qdio.h 13.2 KB
Newer Older
J
Jan Glauber 已提交
1 2 3
/*
 * linux/drivers/s390/cio/qdio.h
 *
4
 * Copyright 2000,2009 IBM Corp.
J
Jan Glauber 已提交
5 6 7
 * 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>
13
#include <asm/debug.h>
J
Jan Glauber 已提交
14
#include "chsc.h"
15

16 17
#define QDIO_BUSY_BIT_PATIENCE		(100 << 12)	/* 100 microseconds */
#define QDIO_INPUT_THRESHOLD		(500 << 12)	/* 500 microseconds */
L
Linus Torvalds 已提交
18

19 20 21 22 23 24 25 26
/*
 * if an asynchronous HiperSockets queue runs full, the 10 seconds timer wait
 * till next initiative to give transmitted skbs back to the stack is too long.
 * Therefore polling is started in case of multicast queue is filled more
 * than 50 percent.
 */
#define QDIO_IQDIO_POLL_LVL		65	/* HS multicast queue */

L
Linus Torvalds 已提交
27 28 29 30 31 32 33 34 35 36
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 已提交
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 72 73 74 75 76 77 78 79
/* 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 已提交
80

J
Jan Glauber 已提交
81 82 83 84 85 86 87 88 89 90 91 92
/* 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 已提交
93

94 95 96 97 98 99
/* SIGA flags */
#define QDIO_SIGA_WRITE		0x00
#define QDIO_SIGA_READ		0x01
#define QDIO_SIGA_SYNC		0x02
#define QDIO_SIGA_QEBSM_FLAG	0x80

J
Jan Glauber 已提交
100 101 102 103 104 105 106
#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 已提交
107

J
Jan Glauber 已提交
108 109 110 111 112 113 114
	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;
115

J
Jan Glauber 已提交
116
	return (_ccq >> 32) & 0xff;
117 118
}

J
Jan Glauber 已提交
119
static inline int do_eqbs(u64 token, unsigned char *state, int queue,
120
			  int *start, int *count, int ack)
121 122
{
	register unsigned long _ccq asm ("0") = *count;
J
Jan Glauber 已提交
123
	register unsigned long _token asm ("1") = token;
124
	unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
125
	unsigned long _state = (unsigned long)ack << 63;
126

127 128 129
	asm volatile(
		"	.insn	rrf,0xB99c0000,%1,%2,0,0"
		: "+d" (_ccq), "+d" (_queuestart), "+d" (_state)
J
Jan Glauber 已提交
130 131
		: "d" (_token)
		: "memory", "cc");
132 133 134 135 136
	*count = _ccq & 0xff;
	*start = _queuestart & 0xff;
	*state = _state & 0xff;

	return (_ccq >> 32) & 0xff;
L
Linus Torvalds 已提交
137
}
J
Jan Glauber 已提交
138 139 140 141
#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,
142
			  int *start, int *count, int ack) { return 0; }
J
Jan Glauber 已提交
143
#endif /* CONFIG_64BIT */
L
Linus Torvalds 已提交
144

J
Jan Glauber 已提交
145
struct qdio_irq;
L
Linus Torvalds 已提交
146

J
Jan Glauber 已提交
147 148 149 150
struct siga_flag {
	u8 input:1;
	u8 output:1;
	u8 sync:1;
J
Jan Glauber 已提交
151 152 153
	u8 sync_after_ai:1;
	u8 sync_out_after_pci:1;
	u8:3;
J
Jan Glauber 已提交
154
} __attribute__ ((packed));
L
Linus Torvalds 已提交
155

J
Jan Glauber 已提交
156
struct chsc_ssqd_area {
157
	struct chsc_header request;
J
Jan Glauber 已提交
158 159 160
	u16:10;
	u8 ssid:2;
	u8 fmt:4;
161
	u16 first_sch;
J
Jan Glauber 已提交
162
	u16:16;
163
	u16 last_sch;
J
Jan Glauber 已提交
164
	u32:32;
165
	struct chsc_header response;
J
Jan Glauber 已提交
166 167 168
	u32:32;
	struct qdio_ssqd_desc qdio_ssqd;
} __attribute__ ((packed));
169

J
Jan Glauber 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
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));

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
struct qdio_dev_perf_stat {
	unsigned int adapter_int;
	unsigned int qdio_int;
	unsigned int pci_request_int;

	unsigned int tasklet_inbound;
	unsigned int tasklet_inbound_resched;
	unsigned int tasklet_inbound_resched2;
	unsigned int tasklet_outbound;

	unsigned int siga_read;
	unsigned int siga_write;
	unsigned int siga_sync;

	unsigned int inbound_call;
	unsigned int inbound_handler;
	unsigned int stop_polling;
	unsigned int inbound_queue_full;
	unsigned int outbound_call;
	unsigned int outbound_handler;
210
	unsigned int outbound_queue_full;
211 212 213 214 215 216
	unsigned int fast_requeue;
	unsigned int target_full;
	unsigned int eqbs;
	unsigned int eqbs_partial;
	unsigned int sqbs;
	unsigned int sqbs_partial;
J
Jan Glauber 已提交
217
	unsigned int int_discarded;
218
} ____cacheline_aligned;
219

220 221 222 223 224 225 226 227 228 229 230 231
struct qdio_queue_perf_stat {
	/*
	 * Sorted into order-2 buckets: 1, 2-3, 4-7, ... 64-127, 128.
	 * Since max. 127 SBALs are scanned reuse entry for 128 as queue full
	 * aka 127 SBALs found.
	 */
	unsigned int nr_sbals[8];
	unsigned int nr_sbal_error;
	unsigned int nr_sbal_nop;
	unsigned int nr_sbal_total;
};

J
Jan Glauber 已提交
232 233 234 235
enum qdio_queue_irq_states {
	QDIO_QUEUE_IRQS_DISABLED,
};

J
Jan Glauber 已提交
236 237 238
struct qdio_input_q {
	/* input buffer acknowledgement flag */
	int polling;
239 240
	/* first ACK'ed buffer */
	int ack_start;
241 242
	/* how much sbals are acknowledged with qebsm */
	int ack_count;
J
Jan Glauber 已提交
243 244
	/* last time of noticing incoming data */
	u64 timestamp;
J
Jan Glauber 已提交
245 246 247 248
	/* upper-layer polling flag */
	unsigned long queue_irq_state;
	/* callback to start upper-layer polling */
	void (*queue_start_poll) (struct ccw_device *, int, unsigned long);
L
Linus Torvalds 已提交
249 250
};

J
Jan Glauber 已提交
251 252 253 254 255
struct qdio_output_q {
	/* PCIs are enabled for the queue */
	int pci_out_enabled;
	/* timer to check for more outbound work */
	struct timer_list timer;
256 257
	/* used SBALs before tasklet schedule */
	int scan_threshold;
J
Jan Glauber 已提交
258
};
L
Linus Torvalds 已提交
259

260 261 262 263
/*
 * Note on cache alignment: grouped slsb and write mostly data at the beginning
 * sbal[] is read-only and starts on a new cacheline followed by read mostly.
 */
L
Linus Torvalds 已提交
264
struct qdio_q {
J
Jan Glauber 已提交
265
	struct slsb slsb;
266

J
Jan Glauber 已提交
267 268 269 270
	union {
		struct qdio_input_q in;
		struct qdio_output_q out;
	} u;
L
Linus Torvalds 已提交
271

J
Jan Glauber 已提交
272 273
	/*
	 * inbound: next buffer the program should check for
274
	 * outbound: next buffer to check if adapter processed it
J
Jan Glauber 已提交
275 276
	 */
	int first_to_check;
L
Linus Torvalds 已提交
277

J
Jan Glauber 已提交
278
	/* first_to_check of the last time */
279
	int last_move;
L
Linus Torvalds 已提交
280

J
Jan Glauber 已提交
281 282
	/* beginning position for calling the program */
	int first_to_kick;
L
Linus Torvalds 已提交
283

J
Jan Glauber 已提交
284 285
	/* number of buffers in use by the adapter */
	atomic_t nr_buf_used;
L
Linus Torvalds 已提交
286

J
Jan Glauber 已提交
287
	/* error condition during a data transfer */
L
Linus Torvalds 已提交
288 289
	unsigned int qdio_error;

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
	struct tasklet_struct tasklet;
	struct qdio_queue_perf_stat q_stats;

	struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q] ____cacheline_aligned;

	/* queue number */
	int nr;

	/* bitmask of queue number */
	int mask;

	/* input or output queue */
	int is_input_q;

	/* list of thinint input queues */
	struct list_head entry;

	/* upper-layer program handler */
	qdio_handler_t (*handler);
J
Jan Glauber 已提交
309

310 311 312
	struct dentry *debugfs_q;
	struct qdio_irq *irq_ptr;
	struct sl *sl;
J
Jan Glauber 已提交
313
	/*
J
Jan Glauber 已提交
314 315
	 * 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.
J
Jan Glauber 已提交
316 317
	 */
	struct slib *slib;
L
Linus Torvalds 已提交
318 319 320
} __attribute__ ((aligned(256)));

struct qdio_irq {
J
Jan Glauber 已提交
321 322 323
	struct qib qib;
	u32 *dsci;		/* address of device state change indicator */
	struct ccw_device *cdev;
324
	struct dentry *debugfs_dev;
325
	struct dentry *debugfs_perf;
L
Linus Torvalds 已提交
326 327

	unsigned long int_parm;
328
	struct subchannel_id schid;
J
Jan Glauber 已提交
329
	unsigned long sch_token;	/* QEBSM facility */
330

L
Linus Torvalds 已提交
331 332
	enum qdio_irq_states state;

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

J
Jan Glauber 已提交
335 336
	int nr_input_qs;
	int nr_output_qs;
L
Linus Torvalds 已提交
337 338 339 340 341

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

J
Jan Glauber 已提交
342 343
	struct qdio_ssqd_desc ssqd_desc;
	void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
L
Linus Torvalds 已提交
344

345
	int perf_stat_enabled;
346

L
Linus Torvalds 已提交
347
	struct qdr *qdr;
J
Jan Glauber 已提交
348 349
	unsigned long chsc_page;

L
Linus Torvalds 已提交
350 351
	struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
	struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
J
Jan Glauber 已提交
352

353
	debug_info_t *debug_area;
J
Jan Glauber 已提交
354
	struct mutex setup_mutex;
355
	struct qdio_dev_perf_stat perf_stat;
L
Linus Torvalds 已提交
356
};
J
Jan Glauber 已提交
357 358 359

/* helper functions */
#define queue_type(q)	q->irq_ptr->qib.qfmt
360
#define SCH_NO(q)	(q->irq_ptr->schid.sch_no)
J
Jan Glauber 已提交
361 362 363 364 365

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

366 367 368 369 370 371 372 373 374 375 376 377 378 379
#define qperf(__qdev, __attr)	((__qdev)->perf_stat.(__attr))

#define qperf_inc(__q, __attr)						\
({									\
	struct qdio_irq *qdev = (__q)->irq_ptr;				\
	if (qdev->perf_stat_enabled)					\
		(qdev->perf_stat.__attr)++;				\
})

static inline void account_sbals_error(struct qdio_q *q, int count)
{
	q->q_stats.nr_sbal_error += count;
	q->q_stats.nr_sbal_total += count;
}
380

J
Jan Glauber 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393
/* 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);
}

#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_in(q)			(q->irq_ptr->siga_flag.input)
#define need_siga_out(q)		(q->irq_ptr->siga_flag.output)
J
Jan Glauber 已提交
394 395 396 397 398
#define need_siga_sync(q)		(unlikely(q->irq_ptr->siga_flag.sync))
#define need_siga_sync_after_ai(q)	\
	(unlikely(q->irq_ptr->siga_flag.sync_after_ai))
#define need_siga_sync_out_after_pci(q)	\
	(unlikely(q->irq_ptr->siga_flag.sync_out_after_pci))
J
Jan Glauber 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414

#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)
415 416
#define sub_buf(bufnr, dec) \
	((bufnr - dec) & QDIO_MAX_BUFFERS_MASK)
J
Jan Glauber 已提交
417

J
Jan Glauber 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
#define queue_irqs_enabled(q)			\
	(test_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state) == 0)
#define queue_irqs_disabled(q)			\
	(test_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state) != 0)

#define TIQDIO_SHARED_IND		63

/* device state change indicators */
struct indicator_t {
	u32 ind;	/* u32 because of compare-and-swap performance */
	atomic_t count; /* use count, 0 or 1 for non-shared indicators */
};

extern struct indicator_t *q_indicators;

433
static inline int shared_ind(u32 *dsci)
J
Jan Glauber 已提交
434
{
435
	return dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
J
Jan Glauber 已提交
436 437
}

J
Jan Glauber 已提交
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
/* prototypes for thin interrupt */
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);
459 460 461
int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
			struct subchannel_id *schid,
			struct qdio_ssqd_desc *data);
J
Jan Glauber 已提交
462 463 464 465
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);
466 467
int qdio_setup_create_sysfs(struct ccw_device *cdev);
void qdio_setup_destroy_sysfs(struct ccw_device *cdev);
J
Jan Glauber 已提交
468 469 470
int qdio_setup_init(void);
void qdio_setup_exit(void);

471 472
int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
			unsigned char *state);
J
Jan Glauber 已提交
473
#endif /* _CIO_QDIO_H */