qdio.h 10.4 KB
Newer Older
J
Jan Glauber 已提交
1 2 3 4 5 6 7
/*
 * linux/drivers/s390/cio/qdio.h
 *
 * Copyright 2000,2008 IBM Corp.
 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
 *	      Jan Glauber <jang@linux.vnet.ibm.com>
 */
L
Linus Torvalds 已提交
8 9 10
#ifndef _CIO_QDIO_H
#define _CIO_QDIO_H

11
#include <asm/page.h>
12
#include <asm/schid.h>
J
Jan Glauber 已提交
13
#include "chsc.h"
14

J
Jan Glauber 已提交
15 16 17
#define QDIO_BUSY_BIT_PATIENCE		100	/* 100 microseconds */
#define QDIO_BUSY_BIT_GIVE_UP		2000000	/* 2 seconds = eternity */
#define QDIO_INPUT_THRESHOLD		500	/* 500 microseconds */
L
Linus Torvalds 已提交
18 19 20 21 22 23 24 25 26 27 28

enum qdio_irq_states {
	QDIO_IRQ_STATE_INACTIVE,
	QDIO_IRQ_STATE_ESTABLISHED,
	QDIO_IRQ_STATE_ACTIVE,
	QDIO_IRQ_STATE_STOPPED,
	QDIO_IRQ_STATE_CLEANUP,
	QDIO_IRQ_STATE_ERR,
	NR_QDIO_IRQ_STATES,
};

J
Jan Glauber 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* used as intparm in do_IO */
#define QDIO_DOING_ESTABLISH	1
#define QDIO_DOING_ACTIVATE	2
#define QDIO_DOING_CLEANUP	3

#define SLSB_STATE_NOT_INIT	0x0
#define SLSB_STATE_EMPTY	0x1
#define SLSB_STATE_PRIMED	0x2
#define SLSB_STATE_HALTED	0xe
#define SLSB_STATE_ERROR	0xf
#define SLSB_TYPE_INPUT		0x0
#define SLSB_TYPE_OUTPUT	0x20
#define SLSB_OWNER_PROG		0x80
#define SLSB_OWNER_CU		0x40

#define SLSB_P_INPUT_NOT_INIT	\
	(SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_NOT_INIT)  /* 0x80 */
#define SLSB_P_INPUT_ACK	\
	(SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY)	   /* 0x81 */
#define SLSB_CU_INPUT_EMPTY	\
	(SLSB_OWNER_CU | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY)	   /* 0x41 */
#define SLSB_P_INPUT_PRIMED	\
	(SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_PRIMED)	   /* 0x82 */
#define SLSB_P_INPUT_HALTED	\
	(SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_HALTED)	   /* 0x8e */
#define SLSB_P_INPUT_ERROR	\
	(SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_ERROR)	   /* 0x8f */
#define SLSB_P_OUTPUT_NOT_INIT	\
	(SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_NOT_INIT) /* 0xa0 */
#define SLSB_P_OUTPUT_EMPTY	\
	(SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_EMPTY)	   /* 0xa1 */
#define SLSB_CU_OUTPUT_PRIMED	\
	(SLSB_OWNER_CU | SLSB_TYPE_OUTPUT | SLSB_STATE_PRIMED)	   /* 0x62 */
#define SLSB_P_OUTPUT_HALTED	\
	(SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_HALTED)   /* 0xae */
#define SLSB_P_OUTPUT_ERROR	\
	(SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_ERROR)	   /* 0xaf */

#define SLSB_ERROR_DURING_LOOKUP  0xff

/* additional CIWs returned by extended Sense-ID */
#define CIW_TYPE_EQUEUE			0x3 /* establish QDIO queues */
#define CIW_TYPE_AQUEUE			0x4 /* activate QDIO queues */
L
Linus Torvalds 已提交
72

J
Jan Glauber 已提交
73 74 75 76 77 78 79 80 81 82 83 84
/* flags for st qdio sch data */
#define CHSC_FLAG_QDIO_CAPABILITY	0x80
#define CHSC_FLAG_VALIDITY		0x40

/* qdio adapter-characteristics-1 flag */
#define AC1_SIGA_INPUT_NEEDED		0x40	/* process input queues */
#define AC1_SIGA_OUTPUT_NEEDED		0x20	/* process output queues */
#define AC1_SIGA_SYNC_NEEDED		0x10	/* ask hypervisor to sync */
#define AC1_AUTOMATIC_SYNC_ON_THININT	0x08	/* set by hypervisor */
#define AC1_AUTOMATIC_SYNC_ON_OUT_PCI	0x04	/* set by hypervisor */
#define AC1_SC_QEBSM_AVAILABLE		0x02	/* available for subchannel */
#define AC1_SC_QEBSM_ENABLED		0x01	/* enabled for subchannel */
L
Linus Torvalds 已提交
85

J
Jan Glauber 已提交
86 87 88 89 90 91 92
#ifdef CONFIG_64BIT
static inline int do_sqbs(u64 token, unsigned char state, int queue,
			  int *start, int *count)
{
	register unsigned long _ccq asm ("0") = *count;
	register unsigned long _token asm ("1") = token;
	unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
L
Linus Torvalds 已提交
93

J
Jan Glauber 已提交
94 95 96 97 98 99 100
	asm volatile(
		"	.insn	rsy,0xeb000000008A,%1,0,0(%2)"
		: "+d" (_ccq), "+d" (_queuestart)
		: "d" ((unsigned long)state), "d" (_token)
		: "memory", "cc");
	*count = _ccq & 0xff;
	*start = _queuestart & 0xff;
101

J
Jan Glauber 已提交
102
	return (_ccq >> 32) & 0xff;
103 104
}

J
Jan Glauber 已提交
105 106
static inline int do_eqbs(u64 token, unsigned char *state, int queue,
			  int *start, int *count)
107 108
{
	register unsigned long _ccq asm ("0") = *count;
J
Jan Glauber 已提交
109
	register unsigned long _token asm ("1") = token;
110 111 112
	unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
	unsigned long _state = 0;

113 114 115
	asm volatile(
		"	.insn	rrf,0xB99c0000,%1,%2,0,0"
		: "+d" (_ccq), "+d" (_queuestart), "+d" (_state)
J
Jan Glauber 已提交
116 117
		: "d" (_token)
		: "memory", "cc");
118 119 120 121 122
	*count = _ccq & 0xff;
	*start = _queuestart & 0xff;
	*state = _state & 0xff;

	return (_ccq >> 32) & 0xff;
L
Linus Torvalds 已提交
123
}
J
Jan Glauber 已提交
124 125 126 127 128 129
#else
static inline int do_sqbs(u64 token, unsigned char state, int queue,
			  int *start, int *count) { return 0; }
static inline int do_eqbs(u64 token, unsigned char *state, int queue,
			  int *start, int *count) { return 0; }
#endif /* CONFIG_64BIT */
L
Linus Torvalds 已提交
130

J
Jan Glauber 已提交
131
struct qdio_irq;
L
Linus Torvalds 已提交
132

J
Jan Glauber 已提交
133 134 135 136 137 138 139 140 141
struct siga_flag {
	u8 input:1;
	u8 output:1;
	u8 sync:1;
	u8 no_sync_ti:1;
	u8 no_sync_out_ti:1;
	u8 no_sync_out_pci:1;
	u8:2;
} __attribute__ ((packed));
L
Linus Torvalds 已提交
142

J
Jan Glauber 已提交
143
struct chsc_ssqd_area {
144
	struct chsc_header request;
J
Jan Glauber 已提交
145 146 147
	u16:10;
	u8 ssid:2;
	u8 fmt:4;
148
	u16 first_sch;
J
Jan Glauber 已提交
149
	u16:16;
150
	u16 last_sch;
J
Jan Glauber 已提交
151
	u32:32;
152
	struct chsc_header response;
J
Jan Glauber 已提交
153 154 155
	u32:32;
	struct qdio_ssqd_desc qdio_ssqd;
} __attribute__ ((packed));
156

J
Jan Glauber 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
struct scssc_area {
	struct chsc_header request;
	u16 operation_code;
	u16:16;
	u32:32;
	u32:32;
	u64 summary_indicator_addr;
	u64 subchannel_indicator_addr;
	u32 ks:4;
	u32 kc:4;
	u32:21;
	u32 isc:3;
	u32 word_with_d_bit;
	u32:32;
	struct subchannel_id schid;
	u32 reserved[1004];
	struct chsc_header response;
	u32:32;
} __attribute__ ((packed));

struct qdio_input_q {
	/* input buffer acknowledgement flag */
	int polling;

	/* last time of noticing incoming data */
	u64 timestamp;

	/* lock for clearing the acknowledgement */
	spinlock_t lock;
L
Linus Torvalds 已提交
186 187
};

J
Jan Glauber 已提交
188 189 190
struct qdio_output_q {
	/* failed siga-w attempts*/
	atomic_t busy_siga_counter;
L
Linus Torvalds 已提交
191

J
Jan Glauber 已提交
192 193
	/* start time of busy condition */
	u64 timestamp;
L
Linus Torvalds 已提交
194

J
Jan Glauber 已提交
195 196
	/* PCIs are enabled for the queue */
	int pci_out_enabled;
L
Linus Torvalds 已提交
197

J
Jan Glauber 已提交
198 199 200
	/* timer to check for more outbound work */
	struct timer_list timer;
};
L
Linus Torvalds 已提交
201 202

struct qdio_q {
J
Jan Glauber 已提交
203 204 205 206 207
	struct slsb slsb;
	union {
		struct qdio_input_q in;
		struct qdio_output_q out;
	} u;
L
Linus Torvalds 已提交
208

J
Jan Glauber 已提交
209 210
	/* queue number */
	int nr;
L
Linus Torvalds 已提交
211

J
Jan Glauber 已提交
212 213
	/* bitmask of queue number */
	int mask;
L
Linus Torvalds 已提交
214

J
Jan Glauber 已提交
215
	/* input or output queue */
L
Linus Torvalds 已提交
216 217
	int is_input_q;

J
Jan Glauber 已提交
218 219
	/* list of thinint input queues */
	struct list_head entry;
L
Linus Torvalds 已提交
220

J
Jan Glauber 已提交
221
	/* upper-layer program handler */
L
Linus Torvalds 已提交
222 223
	qdio_handler_t (*handler);

J
Jan Glauber 已提交
224 225 226 227 228 229
	/*
	 * inbound: next buffer the program should check for
	 * outbound: next buffer to check for having been processed
	 * by the card
	 */
	int first_to_check;
L
Linus Torvalds 已提交
230

J
Jan Glauber 已提交
231 232
	/* first_to_check of the last time */
	int last_move_ftc;
L
Linus Torvalds 已提交
233

J
Jan Glauber 已提交
234 235
	/* beginning position for calling the program */
	int first_to_kick;
L
Linus Torvalds 已提交
236

J
Jan Glauber 已提交
237 238
	/* number of buffers in use by the adapter */
	atomic_t nr_buf_used;
L
Linus Torvalds 已提交
239

J
Jan Glauber 已提交
240
	struct qdio_irq *irq_ptr;
L
Linus Torvalds 已提交
241 242
	struct tasklet_struct tasklet;

J
Jan Glauber 已提交
243
	/* error condition during a data transfer */
L
Linus Torvalds 已提交
244 245 246
	unsigned int qdio_error;

	struct sl *sl;
J
Jan Glauber 已提交
247 248 249 250 251 252 253 254 255
	struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];

	/*
	 * Warning: Leave this member at the end so it won't be cleared in
	 * qdio_fill_qs. A page is allocated under this pointer and used for
	 * slib and sl. slib is 2048 bytes big and sl points to offset
	 * PAGE_SIZE / 2.
	 */
	struct slib *slib;
L
Linus Torvalds 已提交
256 257 258
} __attribute__ ((aligned(256)));

struct qdio_irq {
J
Jan Glauber 已提交
259 260 261
	struct qib qib;
	u32 *dsci;		/* address of device state change indicator */
	struct ccw_device *cdev;
L
Linus Torvalds 已提交
262 263

	unsigned long int_parm;
264
	struct subchannel_id schid;
J
Jan Glauber 已提交
265
	unsigned long sch_token;	/* QEBSM facility */
266

L
Linus Torvalds 已提交
267 268
	enum qdio_irq_states state;

J
Jan Glauber 已提交
269
	struct siga_flag siga_flag;	/* siga sync information from qdioac */
L
Linus Torvalds 已提交
270

J
Jan Glauber 已提交
271 272
	int nr_input_qs;
	int nr_output_qs;
L
Linus Torvalds 已提交
273 274 275 276 277

	struct ccw1 ccw;
	struct ciw equeue;
	struct ciw aqueue;

J
Jan Glauber 已提交
278 279 280
	struct qdio_ssqd_desc ssqd_desc;

	void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
L
Linus Torvalds 已提交
281

J
Jan Glauber 已提交
282 283 284 285
	/*
	 * Warning: Leave these members together at the end so they won't be
	 * cleared in qdio_setup_irq.
	 */
L
Linus Torvalds 已提交
286
	struct qdr *qdr;
J
Jan Glauber 已提交
287 288
	unsigned long chsc_page;

L
Linus Torvalds 已提交
289 290
	struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
	struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
J
Jan Glauber 已提交
291 292

	struct mutex setup_mutex;
L
Linus Torvalds 已提交
293
};
J
Jan Glauber 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377

/* helper functions */
#define queue_type(q)	q->irq_ptr->qib.qfmt

#define is_thinint_irq(irq) \
	(irq->qib.qfmt == QDIO_IQDIO_QFMT || \
	 css_general_characteristics.aif_osa)

/* the highest iqdio queue is used for multicast */
static inline int multicast_outbound(struct qdio_q *q)
{
	return (q->irq_ptr->nr_output_qs > 1) &&
	       (q->nr == q->irq_ptr->nr_output_qs - 1);
}

static inline unsigned long long get_usecs(void)
{
	return monotonic_clock() >> 12;
}

#define pci_out_supported(q) \
	(q->irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
#define is_qebsm(q)			(q->irq_ptr->sch_token != 0)

#define need_siga_sync_thinint(q)	(!q->irq_ptr->siga_flag.no_sync_ti)
#define need_siga_sync_out_thinint(q)	(!q->irq_ptr->siga_flag.no_sync_out_ti)
#define need_siga_in(q)			(q->irq_ptr->siga_flag.input)
#define need_siga_out(q)		(q->irq_ptr->siga_flag.output)
#define need_siga_sync(q)		(q->irq_ptr->siga_flag.sync)
#define siga_syncs_out_pci(q)		(q->irq_ptr->siga_flag.no_sync_out_pci)

#define for_each_input_queue(irq_ptr, q, i)	\
	for (i = 0, q = irq_ptr->input_qs[0];	\
		i < irq_ptr->nr_input_qs;	\
		q = irq_ptr->input_qs[++i])
#define for_each_output_queue(irq_ptr, q, i)	\
	for (i = 0, q = irq_ptr->output_qs[0];	\
		i < irq_ptr->nr_output_qs;	\
		q = irq_ptr->output_qs[++i])

#define prev_buf(bufnr)	\
	((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK)
#define next_buf(bufnr)	\
	((bufnr + 1) & QDIO_MAX_BUFFERS_MASK)
#define add_buf(bufnr, inc) \
	((bufnr + inc) & QDIO_MAX_BUFFERS_MASK)

/* prototypes for thin interrupt */
void qdio_sync_after_thinint(struct qdio_q *q);
int get_buf_state(struct qdio_q *q, unsigned int bufnr, unsigned char *state);
void qdio_check_outbound_after_thinint(struct qdio_q *q);
int qdio_inbound_q_moved(struct qdio_q *q);
void qdio_kick_inbound_handler(struct qdio_q *q);
void qdio_stop_polling(struct qdio_q *q);
int qdio_siga_sync_q(struct qdio_q *q);

void qdio_setup_thinint(struct qdio_irq *irq_ptr);
int qdio_establish_thinint(struct qdio_irq *irq_ptr);
void qdio_shutdown_thinint(struct qdio_irq *irq_ptr);
void tiqdio_add_input_queues(struct qdio_irq *irq_ptr);
void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr);
void tiqdio_inbound_processing(unsigned long q);
int tiqdio_allocate_memory(void);
void tiqdio_free_memory(void);
int tiqdio_register_thinints(void);
void tiqdio_unregister_thinints(void);

/* prototypes for setup */
void qdio_inbound_processing(unsigned long data);
void qdio_outbound_processing(unsigned long data);
void qdio_outbound_timer(unsigned long data);
void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
		      struct irb *irb);
int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs,
		     int nr_output_qs);
void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr);
int qdio_setup_irq(struct qdio_initialize *init_data);
void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
				struct ccw_device *cdev);
void qdio_release_memory(struct qdio_irq *irq_ptr);
int qdio_setup_init(void);
void qdio_setup_exit(void);

#endif /* _CIO_QDIO_H */