qdio.h 11.2 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
J
Jan Glauber 已提交
2
/*
3
 * Copyright IBM Corp. 2000, 2009
J
Jan Glauber 已提交
4 5 6
 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
 *	      Jan Glauber <jang@linux.vnet.ibm.com>
 */
L
Linus Torvalds 已提交
7 8 9
#ifndef _CIO_QDIO_H
#define _CIO_QDIO_H

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

15
#define QDIO_BUSY_BIT_PATIENCE		(100 << 12)	/* 100 microseconds */
16 17
#define QDIO_BUSY_BIT_RETRY_DELAY	10		/* 10 milliseconds */
#define QDIO_BUSY_BIT_RETRIES		1000		/* = 10s retry time */
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
/* 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
37
#define SLSB_STATE_PENDING	0x3
J
Jan Glauber 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#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 */
61 62
#define SLSB_P_OUTPUT_PENDING \
	(SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_PENDING)  /* 0xa3 */
J
Jan Glauber 已提交
63 64 65 66 67 68 69 70 71 72 73 74
#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 已提交
75

J
Jan Glauber 已提交
76 77 78 79
/* flags for st qdio sch data */
#define CHSC_FLAG_QDIO_CAPABILITY	0x80
#define CHSC_FLAG_VALIDITY		0x40

80 81 82 83
/* SIGA flags */
#define QDIO_SIGA_WRITE		0x00
#define QDIO_SIGA_READ		0x01
#define QDIO_SIGA_SYNC		0x02
84
#define QDIO_SIGA_WRITEM	0x03
85
#define QDIO_SIGA_WRITEQ	0x04
86 87
#define QDIO_SIGA_QEBSM_FLAG	0x80

J
Jan Glauber 已提交
88 89 90 91 92 93
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 已提交
94

J
Jan Glauber 已提交
95 96 97 98 99 100 101
	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;
102

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

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

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

	return (_ccq >> 32) & 0xff;
L
Linus Torvalds 已提交
124 125
}

J
Jan Glauber 已提交
126
struct qdio_irq;
L
Linus Torvalds 已提交
127

J
Jan Glauber 已提交
128 129 130 131
struct siga_flag {
	u8 input:1;
	u8 output:1;
	u8 sync:1;
J
Jan Glauber 已提交
132 133 134
	u8 sync_after_ai:1;
	u8 sync_out_after_pci:1;
	u8:3;
J
Jan Glauber 已提交
135
} __attribute__ ((packed));
L
Linus Torvalds 已提交
136

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
struct qdio_dev_perf_stat {
	unsigned int adapter_int;
	unsigned int qdio_int;
	unsigned int pci_request_int;

	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;
154
	unsigned int outbound_queue_full;
155 156 157 158 159 160
	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 已提交
161
	unsigned int int_discarded;
162
} ____cacheline_aligned;
163

164
struct qdio_queue_perf_stat {
165
	/* Sorted into order-2 buckets: 1, 2-3, 4-7, ... 64-127, 128. */
166 167 168 169 170 171
	unsigned int nr_sbals[8];
	unsigned int nr_sbal_error;
	unsigned int nr_sbal_nop;
	unsigned int nr_sbal_total;
};

172 173
enum qdio_irq_poll_states {
	QDIO_IRQ_DISABLED,
J
Jan Glauber 已提交
174 175
};

J
Jan Glauber 已提交
176
struct qdio_input_q {
177 178 179
	/* Batch of SBALs that we processed while polling the queue: */
	unsigned int batch_start;
	unsigned int batch_count;
L
Linus Torvalds 已提交
180 181
};

J
Jan Glauber 已提交
182 183 184
struct qdio_output_q {
	/* PCIs are enabled for the queue */
	int pci_out_enabled;
185 186 187 188 189 190
	/* cq: use asynchronous output buffers */
	int use_cq;
	/* cq: aobs used for particual SBAL */
	struct qaob **aobs;
	/* cq: sbal state related to asynchronous operation */
	struct qdio_outbuf_state *sbal_state;
J
Jan Glauber 已提交
191 192
	/* timer to check for more outbound work */
	struct timer_list timer;
193 194
	/* tasklet to check for completions */
	struct tasklet_struct tasklet;
J
Jan Glauber 已提交
195
};
L
Linus Torvalds 已提交
196

197 198 199 200
/*
 * 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 已提交
201
struct qdio_q {
J
Jan Glauber 已提交
202
	struct slsb slsb;
203

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

J
Jan Glauber 已提交
209 210
	/*
	 * inbound: next buffer the program should check for
211
	 * outbound: next buffer to check if adapter processed it
J
Jan Glauber 已提交
212 213
	 */
	int first_to_check;
L
Linus Torvalds 已提交
214

J
Jan Glauber 已提交
215 216
	/* number of buffers in use by the adapter */
	atomic_t nr_buf_used;
L
Linus Torvalds 已提交
217

J
Jan Glauber 已提交
218
	/* error condition during a data transfer */
L
Linus Torvalds 已提交
219 220
	unsigned int qdio_error;

221 222 223
	/* last scan of the queue */
	u64 timestamp;

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
	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;

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

240 241
	struct qdio_irq *irq_ptr;
	struct sl *sl;
J
Jan Glauber 已提交
242
	/*
J
Jan Glauber 已提交
243 244
	 * 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 已提交
245 246
	 */
	struct slib *slib;
L
Linus Torvalds 已提交
247 248 249
} __attribute__ ((aligned(256)));

struct qdio_irq {
J
Jan Glauber 已提交
250 251 252
	struct qib qib;
	u32 *dsci;		/* address of device state change indicator */
	struct ccw_device *cdev;
253
	struct list_head entry;		/* list of thinint devices */
254
	struct dentry *debugfs_dev;
255
	u64 last_data_irq_time;
L
Linus Torvalds 已提交
256 257

	unsigned long int_parm;
258
	struct subchannel_id schid;
J
Jan Glauber 已提交
259
	unsigned long sch_token;	/* QEBSM facility */
260

L
Linus Torvalds 已提交
261 262
	enum qdio_irq_states state;

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

J
Jan Glauber 已提交
265 266
	int nr_input_qs;
	int nr_output_qs;
L
Linus Torvalds 已提交
267 268 269 270 271

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

J
Jan Glauber 已提交
272 273
	struct qdio_ssqd_desc ssqd_desc;
	void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
L
Linus Torvalds 已提交
274

275
	unsigned int scan_threshold;	/* used SBALs before tasklet schedule */
276
	int perf_stat_enabled;
277

L
Linus Torvalds 已提交
278
	struct qdr *qdr;
J
Jan Glauber 已提交
279 280
	unsigned long chsc_page;

L
Linus Torvalds 已提交
281 282
	struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
	struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
283 284
	unsigned int max_input_qs;
	unsigned int max_output_qs;
J
Jan Glauber 已提交
285

286 287 288
	void (*irq_poll)(struct ccw_device *cdev, unsigned long data);
	unsigned long poll_state;

289
	debug_info_t *debug_area;
J
Jan Glauber 已提交
290
	struct mutex setup_mutex;
291
	struct qdio_dev_perf_stat perf_stat;
L
Linus Torvalds 已提交
292
};
J
Jan Glauber 已提交
293 294 295

/* helper functions */
#define queue_type(q)	q->irq_ptr->qib.qfmt
296
#define SCH_NO(q)	(q->irq_ptr->schid.sch_no)
J
Jan Glauber 已提交
297 298 299 300 301

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

302 303
#define qperf(__qdev, __attr)	((__qdev)->perf_stat.(__attr))

304
#define QDIO_PERF_STAT_INC(__irq, __attr)				\
305
({									\
306
	struct qdio_irq *qdev = __irq;					\
307 308 309 310
	if (qdev->perf_stat_enabled)					\
		(qdev->perf_stat.__attr)++;				\
})

311 312
#define qperf_inc(__q, __attr)	QDIO_PERF_STAT_INC((__q)->irq_ptr, __attr)

313 314 315 316 317
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;
}
318

J
Jan Glauber 已提交
319 320 321 322 323 324 325
/* 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);
}

326 327 328 329 330 331 332 333
static inline void qdio_deliver_irq(struct qdio_irq *irq)
{
	if (!test_and_set_bit(QDIO_IRQ_DISABLED, &irq->poll_state))
		irq->irq_poll(irq->cdev, irq->int_parm);
	else
		QDIO_PERF_STAT_INC(irq, int_discarded);
}

334
#define pci_out_supported(irq) ((irq)->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
J
Jan Glauber 已提交
335 336 337 338
#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 已提交
339 340 341 342 343
#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 已提交
344

345 346 347 348 349 350
#define for_each_input_queue(irq_ptr, q, i)		\
	for (i = 0; i < irq_ptr->nr_input_qs &&		\
		({ q = irq_ptr->input_qs[i]; 1; }); i++)
#define for_each_output_queue(irq_ptr, q, i)		\
	for (i = 0; i < irq_ptr->nr_output_qs &&	\
		({ q = irq_ptr->output_qs[i]; 1; }); i++)
J
Jan Glauber 已提交
351

J
Julian Wiedmann 已提交
352 353 354 355
#define add_buf(bufnr, inc)	QDIO_BUFNR((bufnr) + (inc))
#define next_buf(bufnr)		add_buf(bufnr, 1)
#define sub_buf(bufnr, dec)	QDIO_BUFNR((bufnr) - (dec))
#define prev_buf(bufnr)		sub_buf(bufnr, 1)
J
Jan Glauber 已提交
356

J
Jan Glauber 已提交
357 358 359 360 361
#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)

362 363
extern u64 last_ai_time;

J
Jan Glauber 已提交
364 365 366
/* prototypes for thin interrupt */
int qdio_establish_thinint(struct qdio_irq *irq_ptr);
void qdio_shutdown_thinint(struct qdio_irq *irq_ptr);
367 368
int qdio_thinint_init(void);
void qdio_thinint_exit(void);
369
int test_nonshared_ind(struct qdio_irq *);
370

J
Jan Glauber 已提交
371
/* prototypes for setup */
372
void qdio_outbound_tasklet(struct tasklet_struct *t);
373
void qdio_outbound_timer(struct timer_list *t);
J
Jan Glauber 已提交
374 375 376 377 378
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);
379 380 381
int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
			struct subchannel_id *schid,
			struct qdio_ssqd_desc *data);
382
int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data);
383
void qdio_shutdown_irq(struct qdio_irq *irq);
384
void qdio_print_subchannel_info(struct qdio_irq *irq_ptr);
385
void qdio_free_queues(struct qdio_irq *irq_ptr);
386
void qdio_free_async_data(struct qdio_irq *irq_ptr);
J
Jan Glauber 已提交
387 388
int qdio_setup_init(void);
void qdio_setup_exit(void);
389 390 391
int qdio_enable_async_operation(struct qdio_output_q *q);
void qdio_disable_async_operation(struct qdio_output_q *q);
struct qaob *qdio_allocate_aob(void);
J
Jan Glauber 已提交
392

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