1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * qdio queue initialization
4  *
5  * Copyright IBM Corp. 2008
6  * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
7  */
8 #include <linux/kernel.h>
9 #include <linux/slab.h>
10 #include <linux/export.h>
11 #include <linux/io.h>
12 #include <asm/qdio.h>
13 
14 #include "cio.h"
15 #include "css.h"
16 #include "device.h"
17 #include "ioasm.h"
18 #include "chsc.h"
19 #include "qdio.h"
20 #include "qdio_debug.h"
21 
22 #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
23 
24 static struct kmem_cache *qdio_q_cache;
25 static struct kmem_cache *qdio_aob_cache;
26 
qdio_allocate_aob(void)27 struct qaob *qdio_allocate_aob(void)
28 {
29 	return kmem_cache_zalloc(qdio_aob_cache, GFP_ATOMIC);
30 }
31 EXPORT_SYMBOL_GPL(qdio_allocate_aob);
32 
qdio_release_aob(struct qaob * aob)33 void qdio_release_aob(struct qaob *aob)
34 {
35 	kmem_cache_free(qdio_aob_cache, aob);
36 }
37 EXPORT_SYMBOL_GPL(qdio_release_aob);
38 
39 /**
40  * qdio_free_buffers() - free qdio buffers
41  * @buf: array of pointers to qdio buffers
42  * @count: number of qdio buffers to free
43  */
qdio_free_buffers(struct qdio_buffer ** buf,unsigned int count)44 void qdio_free_buffers(struct qdio_buffer **buf, unsigned int count)
45 {
46 	int pos;
47 
48 	for (pos = 0; pos < count; pos += QBUFF_PER_PAGE)
49 		free_page((unsigned long) buf[pos]);
50 }
51 EXPORT_SYMBOL_GPL(qdio_free_buffers);
52 
53 /**
54  * qdio_alloc_buffers() - allocate qdio buffers
55  * @buf: array of pointers to qdio buffers
56  * @count: number of qdio buffers to allocate
57  */
qdio_alloc_buffers(struct qdio_buffer ** buf,unsigned int count)58 int qdio_alloc_buffers(struct qdio_buffer **buf, unsigned int count)
59 {
60 	int pos;
61 
62 	for (pos = 0; pos < count; pos += QBUFF_PER_PAGE) {
63 		buf[pos] = (void *) get_zeroed_page(GFP_KERNEL);
64 		if (!buf[pos]) {
65 			qdio_free_buffers(buf, count);
66 			return -ENOMEM;
67 		}
68 	}
69 	for (pos = 0; pos < count; pos++)
70 		if (pos % QBUFF_PER_PAGE)
71 			buf[pos] = buf[pos - 1] + 1;
72 	return 0;
73 }
74 EXPORT_SYMBOL_GPL(qdio_alloc_buffers);
75 
76 /**
77  * qdio_reset_buffers() - reset qdio buffers
78  * @buf: array of pointers to qdio buffers
79  * @count: number of qdio buffers that will be zeroed
80  */
qdio_reset_buffers(struct qdio_buffer ** buf,unsigned int count)81 void qdio_reset_buffers(struct qdio_buffer **buf, unsigned int count)
82 {
83 	int pos;
84 
85 	for (pos = 0; pos < count; pos++)
86 		memset(buf[pos], 0, sizeof(struct qdio_buffer));
87 }
88 EXPORT_SYMBOL_GPL(qdio_reset_buffers);
89 
90 /*
91  * qebsm is only available under 64bit but the adapter sets the feature
92  * flag anyway, so we manually override it.
93  */
qebsm_possible(void)94 static inline int qebsm_possible(void)
95 {
96 	return css_general_characteristics.qebsm;
97 }
98 
99 /*
100  * qib_param_field: pointer to 128 bytes or NULL, if no param field
101  * nr_input_qs: pointer to nr_queues*128 words of data or NULL
102  */
set_impl_params(struct qdio_irq * irq_ptr,unsigned int qib_param_field_format,unsigned char * qib_param_field,unsigned long * input_slib_elements,unsigned long * output_slib_elements)103 static void set_impl_params(struct qdio_irq *irq_ptr,
104 			    unsigned int qib_param_field_format,
105 			    unsigned char *qib_param_field,
106 			    unsigned long *input_slib_elements,
107 			    unsigned long *output_slib_elements)
108 {
109 	struct qdio_q *q;
110 	int i, j;
111 
112 	if (!irq_ptr)
113 		return;
114 
115 	irq_ptr->qib.pfmt = qib_param_field_format;
116 	if (qib_param_field)
117 		memcpy(irq_ptr->qib.parm, qib_param_field,
118 		       QDIO_MAX_BUFFERS_PER_Q);
119 
120 	if (!input_slib_elements)
121 		goto output;
122 
123 	for_each_input_queue(irq_ptr, q, i) {
124 		for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
125 			q->slib->slibe[j].parms =
126 				input_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j];
127 	}
128 output:
129 	if (!output_slib_elements)
130 		return;
131 
132 	for_each_output_queue(irq_ptr, q, i) {
133 		for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
134 			q->slib->slibe[j].parms =
135 				output_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j];
136 	}
137 }
138 
__qdio_allocate_qs(struct qdio_q ** irq_ptr_qs,int nr_queues)139 static int __qdio_allocate_qs(struct qdio_q **irq_ptr_qs, int nr_queues)
140 {
141 	struct qdio_q *q;
142 	int i;
143 
144 	for (i = 0; i < nr_queues; i++) {
145 		q = kmem_cache_zalloc(qdio_q_cache, GFP_KERNEL);
146 		if (!q)
147 			return -ENOMEM;
148 
149 		q->slib = (struct slib *) __get_free_page(GFP_KERNEL);
150 		if (!q->slib) {
151 			kmem_cache_free(qdio_q_cache, q);
152 			return -ENOMEM;
153 		}
154 		irq_ptr_qs[i] = q;
155 		INIT_LIST_HEAD(&q->entry);
156 	}
157 	return 0;
158 }
159 
qdio_allocate_qs(struct qdio_irq * irq_ptr,int nr_input_qs,int nr_output_qs)160 int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs, int nr_output_qs)
161 {
162 	int rc;
163 
164 	rc = __qdio_allocate_qs(irq_ptr->input_qs, nr_input_qs);
165 	if (rc)
166 		return rc;
167 	rc = __qdio_allocate_qs(irq_ptr->output_qs, nr_output_qs);
168 	return rc;
169 }
170 
setup_queues_misc(struct qdio_q * q,struct qdio_irq * irq_ptr,qdio_handler_t * handler,int i)171 static void setup_queues_misc(struct qdio_q *q, struct qdio_irq *irq_ptr,
172 			      qdio_handler_t *handler, int i)
173 {
174 	struct slib *slib = q->slib;
175 
176 	/* queue must be cleared for qdio_establish */
177 	memset(q, 0, sizeof(*q));
178 	memset(slib, 0, PAGE_SIZE);
179 	q->slib = slib;
180 	q->irq_ptr = irq_ptr;
181 	q->mask = 1 << (31 - i);
182 	q->nr = i;
183 	q->handler = handler;
184 	INIT_LIST_HEAD(&q->entry);
185 }
186 
setup_storage_lists(struct qdio_q * q,struct qdio_irq * irq_ptr,void ** sbals_array,int i)187 static void setup_storage_lists(struct qdio_q *q, struct qdio_irq *irq_ptr,
188 				void **sbals_array, int i)
189 {
190 	struct qdio_q *prev;
191 	int j;
192 
193 	DBF_HEX(&q, sizeof(void *));
194 	q->sl = (struct sl *)((char *)q->slib + PAGE_SIZE / 2);
195 
196 	/* fill in sbal */
197 	for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
198 		q->sbal[j] = *sbals_array++;
199 
200 	/* fill in slib */
201 	if (i > 0) {
202 		prev = (q->is_input_q) ? irq_ptr->input_qs[i - 1]
203 			: irq_ptr->output_qs[i - 1];
204 		prev->slib->nsliba = (unsigned long)q->slib;
205 	}
206 
207 	q->slib->sla = (unsigned long)q->sl;
208 	q->slib->slsba = (unsigned long)&q->slsb.val[0];
209 
210 	/* fill in sl */
211 	for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
212 		q->sl->element[j].sbal = virt_to_phys(q->sbal[j]);
213 }
214 
setup_queues(struct qdio_irq * irq_ptr,struct qdio_initialize * qdio_init)215 static void setup_queues(struct qdio_irq *irq_ptr,
216 			 struct qdio_initialize *qdio_init)
217 {
218 	struct qdio_q *q;
219 	void **input_sbal_array = qdio_init->input_sbal_addr_array;
220 	void **output_sbal_array = qdio_init->output_sbal_addr_array;
221 	struct qdio_outbuf_state *output_sbal_state_array =
222 				  qdio_init->output_sbal_state_array;
223 	int i;
224 
225 	for_each_input_queue(irq_ptr, q, i) {
226 		DBF_EVENT("inq:%1d", i);
227 		setup_queues_misc(q, irq_ptr, qdio_init->input_handler, i);
228 
229 		q->is_input_q = 1;
230 		q->u.in.queue_start_poll = qdio_init->queue_start_poll_array ?
231 				qdio_init->queue_start_poll_array[i] : NULL;
232 
233 		setup_storage_lists(q, irq_ptr, input_sbal_array, i);
234 		input_sbal_array += QDIO_MAX_BUFFERS_PER_Q;
235 
236 		if (is_thinint_irq(irq_ptr)) {
237 			tasklet_init(&q->tasklet, tiqdio_inbound_processing,
238 				     (unsigned long) q);
239 		} else {
240 			tasklet_init(&q->tasklet, qdio_inbound_processing,
241 				     (unsigned long) q);
242 		}
243 	}
244 
245 	for_each_output_queue(irq_ptr, q, i) {
246 		DBF_EVENT("outq:%1d", i);
247 		setup_queues_misc(q, irq_ptr, qdio_init->output_handler, i);
248 
249 		q->u.out.sbal_state = output_sbal_state_array;
250 		output_sbal_state_array += QDIO_MAX_BUFFERS_PER_Q;
251 
252 		q->is_input_q = 0;
253 		q->u.out.scan_threshold = qdio_init->scan_threshold;
254 		setup_storage_lists(q, irq_ptr, output_sbal_array, i);
255 		output_sbal_array += QDIO_MAX_BUFFERS_PER_Q;
256 
257 		tasklet_init(&q->tasklet, qdio_outbound_processing,
258 			     (unsigned long) q);
259 		timer_setup(&q->u.out.timer, qdio_outbound_timer, 0);
260 	}
261 }
262 
process_ac_flags(struct qdio_irq * irq_ptr,unsigned char qdioac)263 static void process_ac_flags(struct qdio_irq *irq_ptr, unsigned char qdioac)
264 {
265 	if (qdioac & AC1_SIGA_INPUT_NEEDED)
266 		irq_ptr->siga_flag.input = 1;
267 	if (qdioac & AC1_SIGA_OUTPUT_NEEDED)
268 		irq_ptr->siga_flag.output = 1;
269 	if (qdioac & AC1_SIGA_SYNC_NEEDED)
270 		irq_ptr->siga_flag.sync = 1;
271 	if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_THININT))
272 		irq_ptr->siga_flag.sync_after_ai = 1;
273 	if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_OUT_PCI))
274 		irq_ptr->siga_flag.sync_out_after_pci = 1;
275 }
276 
check_and_setup_qebsm(struct qdio_irq * irq_ptr,unsigned char qdioac,unsigned long token)277 static void check_and_setup_qebsm(struct qdio_irq *irq_ptr,
278 				  unsigned char qdioac, unsigned long token)
279 {
280 	if (!(irq_ptr->qib.rflags & QIB_RFLAGS_ENABLE_QEBSM))
281 		goto no_qebsm;
282 	if (!(qdioac & AC1_SC_QEBSM_AVAILABLE) ||
283 	    (!(qdioac & AC1_SC_QEBSM_ENABLED)))
284 		goto no_qebsm;
285 
286 	irq_ptr->sch_token = token;
287 
288 	DBF_EVENT("V=V:1");
289 	DBF_EVENT("%8lx", irq_ptr->sch_token);
290 	return;
291 
292 no_qebsm:
293 	irq_ptr->sch_token = 0;
294 	irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
295 	DBF_EVENT("noV=V");
296 }
297 
298 /*
299  * If there is a qdio_irq we use the chsc_page and store the information
300  * in the qdio_irq, otherwise we copy it to the specified structure.
301  */
qdio_setup_get_ssqd(struct qdio_irq * irq_ptr,struct subchannel_id * schid,struct qdio_ssqd_desc * data)302 int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
303 			struct subchannel_id *schid,
304 			struct qdio_ssqd_desc *data)
305 {
306 	struct chsc_ssqd_area *ssqd;
307 	int rc;
308 
309 	DBF_EVENT("getssqd:%4x", schid->sch_no);
310 	if (!irq_ptr) {
311 		ssqd = (struct chsc_ssqd_area *)__get_free_page(GFP_KERNEL);
312 		if (!ssqd)
313 			return -ENOMEM;
314 	} else {
315 		ssqd = (struct chsc_ssqd_area *)irq_ptr->chsc_page;
316 	}
317 
318 	rc = chsc_ssqd(*schid, ssqd);
319 	if (rc)
320 		goto out;
321 
322 	if (!(ssqd->qdio_ssqd.flags & CHSC_FLAG_QDIO_CAPABILITY) ||
323 	    !(ssqd->qdio_ssqd.flags & CHSC_FLAG_VALIDITY) ||
324 	    (ssqd->qdio_ssqd.sch != schid->sch_no))
325 		rc = -EINVAL;
326 
327 	if (!rc)
328 		memcpy(data, &ssqd->qdio_ssqd, sizeof(*data));
329 
330 out:
331 	if (!irq_ptr)
332 		free_page((unsigned long)ssqd);
333 
334 	return rc;
335 }
336 
qdio_setup_ssqd_info(struct qdio_irq * irq_ptr)337 void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr)
338 {
339 	unsigned char qdioac;
340 	int rc;
341 
342 	rc = qdio_setup_get_ssqd(irq_ptr, &irq_ptr->schid, &irq_ptr->ssqd_desc);
343 	if (rc) {
344 		DBF_ERROR("%4x ssqd ERR", irq_ptr->schid.sch_no);
345 		DBF_ERROR("rc:%x", rc);
346 		/* all flags set, worst case */
347 		qdioac = AC1_SIGA_INPUT_NEEDED | AC1_SIGA_OUTPUT_NEEDED |
348 			 AC1_SIGA_SYNC_NEEDED;
349 	} else
350 		qdioac = irq_ptr->ssqd_desc.qdioac1;
351 
352 	check_and_setup_qebsm(irq_ptr, qdioac, irq_ptr->ssqd_desc.sch_token);
353 	process_ac_flags(irq_ptr, qdioac);
354 	DBF_EVENT("ac 1:%2x 2:%4x", qdioac, irq_ptr->ssqd_desc.qdioac2);
355 	DBF_EVENT("3:%4x qib:%4x", irq_ptr->ssqd_desc.qdioac3, irq_ptr->qib.ac);
356 }
357 
qdio_release_memory(struct qdio_irq * irq_ptr)358 void qdio_release_memory(struct qdio_irq *irq_ptr)
359 {
360 	struct qdio_q *q;
361 	int i;
362 
363 	/*
364 	 * Must check queue array manually since irq_ptr->nr_input_queues /
365 	 * irq_ptr->nr_input_queues may not yet be set.
366 	 */
367 	for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
368 		q = irq_ptr->input_qs[i];
369 		if (q) {
370 			free_page((unsigned long) q->slib);
371 			kmem_cache_free(qdio_q_cache, q);
372 		}
373 	}
374 	for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
375 		q = irq_ptr->output_qs[i];
376 		if (q) {
377 			if (q->u.out.use_cq) {
378 				int n;
379 
380 				for (n = 0; n < QDIO_MAX_BUFFERS_PER_Q; ++n) {
381 					struct qaob *aob = q->u.out.aobs[n];
382 					if (aob) {
383 						qdio_release_aob(aob);
384 						q->u.out.aobs[n] = NULL;
385 					}
386 				}
387 
388 				qdio_disable_async_operation(&q->u.out);
389 			}
390 			free_page((unsigned long) q->slib);
391 			kmem_cache_free(qdio_q_cache, q);
392 		}
393 	}
394 	free_page((unsigned long) irq_ptr->qdr);
395 	free_page(irq_ptr->chsc_page);
396 	free_page((unsigned long) irq_ptr);
397 }
398 
__qdio_allocate_fill_qdr(struct qdio_irq * irq_ptr,struct qdio_q ** irq_ptr_qs,int i,int nr)399 static void __qdio_allocate_fill_qdr(struct qdio_irq *irq_ptr,
400 				     struct qdio_q **irq_ptr_qs,
401 				     int i, int nr)
402 {
403 	irq_ptr->qdr->qdf0[i + nr].sliba =
404 		(unsigned long)irq_ptr_qs[i]->slib;
405 
406 	irq_ptr->qdr->qdf0[i + nr].sla =
407 		(unsigned long)irq_ptr_qs[i]->sl;
408 
409 	irq_ptr->qdr->qdf0[i + nr].slsba =
410 		(unsigned long)&irq_ptr_qs[i]->slsb.val[0];
411 
412 	irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY >> 4;
413 	irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY >> 4;
414 	irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY >> 4;
415 	irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY >> 4;
416 }
417 
setup_qdr(struct qdio_irq * irq_ptr,struct qdio_initialize * qdio_init)418 static void setup_qdr(struct qdio_irq *irq_ptr,
419 		      struct qdio_initialize *qdio_init)
420 {
421 	int i;
422 
423 	irq_ptr->qdr->qfmt = qdio_init->q_format;
424 	irq_ptr->qdr->ac = qdio_init->qdr_ac;
425 	irq_ptr->qdr->iqdcnt = qdio_init->no_input_qs;
426 	irq_ptr->qdr->oqdcnt = qdio_init->no_output_qs;
427 	irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */
428 	irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4;
429 	irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib;
430 	irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY >> 4;
431 
432 	for (i = 0; i < qdio_init->no_input_qs; i++)
433 		__qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0);
434 
435 	for (i = 0; i < qdio_init->no_output_qs; i++)
436 		__qdio_allocate_fill_qdr(irq_ptr, irq_ptr->output_qs, i,
437 					 qdio_init->no_input_qs);
438 }
439 
setup_qib(struct qdio_irq * irq_ptr,struct qdio_initialize * init_data)440 static void setup_qib(struct qdio_irq *irq_ptr,
441 		      struct qdio_initialize *init_data)
442 {
443 	if (qebsm_possible())
444 		irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM;
445 
446 	irq_ptr->qib.rflags |= init_data->qib_rflags;
447 
448 	irq_ptr->qib.qfmt = init_data->q_format;
449 	if (init_data->no_input_qs)
450 		irq_ptr->qib.isliba =
451 			(unsigned long)(irq_ptr->input_qs[0]->slib);
452 	if (init_data->no_output_qs)
453 		irq_ptr->qib.osliba =
454 			(unsigned long)(irq_ptr->output_qs[0]->slib);
455 	memcpy(irq_ptr->qib.ebcnam, init_data->adapter_name, 8);
456 }
457 
qdio_setup_irq(struct qdio_initialize * init_data)458 int qdio_setup_irq(struct qdio_initialize *init_data)
459 {
460 	struct ciw *ciw;
461 	struct qdio_irq *irq_ptr = init_data->cdev->private->qdio_data;
462 
463 	memset(&irq_ptr->qib, 0, sizeof(irq_ptr->qib));
464 	memset(&irq_ptr->siga_flag, 0, sizeof(irq_ptr->siga_flag));
465 	memset(&irq_ptr->ccw, 0, sizeof(irq_ptr->ccw));
466 	memset(&irq_ptr->ssqd_desc, 0, sizeof(irq_ptr->ssqd_desc));
467 	memset(&irq_ptr->perf_stat, 0, sizeof(irq_ptr->perf_stat));
468 
469 	irq_ptr->debugfs_dev = irq_ptr->debugfs_perf = NULL;
470 	irq_ptr->sch_token = irq_ptr->state = irq_ptr->perf_stat_enabled = 0;
471 
472 	/* wipes qib.ac, required by ar7063 */
473 	memset(irq_ptr->qdr, 0, sizeof(struct qdr));
474 
475 	irq_ptr->int_parm = init_data->int_parm;
476 	irq_ptr->nr_input_qs = init_data->no_input_qs;
477 	irq_ptr->nr_output_qs = init_data->no_output_qs;
478 	irq_ptr->cdev = init_data->cdev;
479 	ccw_device_get_schid(irq_ptr->cdev, &irq_ptr->schid);
480 	setup_queues(irq_ptr, init_data);
481 
482 	setup_qib(irq_ptr, init_data);
483 	set_impl_params(irq_ptr, init_data->qib_param_field_format,
484 			init_data->qib_param_field,
485 			init_data->input_slib_elements,
486 			init_data->output_slib_elements);
487 
488 	/* fill input and output descriptors */
489 	setup_qdr(irq_ptr, init_data);
490 
491 	/* qdr, qib, sls, slsbs, slibs, sbales are filled now */
492 
493 	/* get qdio commands */
494 	ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
495 	if (!ciw) {
496 		DBF_ERROR("%4x NO EQ", irq_ptr->schid.sch_no);
497 		return -EINVAL;
498 	}
499 	irq_ptr->equeue = *ciw;
500 
501 	ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
502 	if (!ciw) {
503 		DBF_ERROR("%4x NO AQ", irq_ptr->schid.sch_no);
504 		return -EINVAL;
505 	}
506 	irq_ptr->aqueue = *ciw;
507 
508 	/* set new interrupt handler */
509 	spin_lock_irq(get_ccwdev_lock(irq_ptr->cdev));
510 	irq_ptr->orig_handler = init_data->cdev->handler;
511 	init_data->cdev->handler = qdio_int_handler;
512 	spin_unlock_irq(get_ccwdev_lock(irq_ptr->cdev));
513 	return 0;
514 }
515 
qdio_print_subchannel_info(struct qdio_irq * irq_ptr,struct ccw_device * cdev)516 void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
517 				struct ccw_device *cdev)
518 {
519 	char s[80];
520 
521 	snprintf(s, 80, "qdio: %s %s on SC %x using "
522 		 "AI:%d QEBSM:%d PRI:%d TDD:%d SIGA:%s%s%s%s%s\n",
523 		 dev_name(&cdev->dev),
524 		 (irq_ptr->qib.qfmt == QDIO_QETH_QFMT) ? "OSA" :
525 			((irq_ptr->qib.qfmt == QDIO_ZFCP_QFMT) ? "ZFCP" : "HS"),
526 		 irq_ptr->schid.sch_no,
527 		 is_thinint_irq(irq_ptr),
528 		 (irq_ptr->sch_token) ? 1 : 0,
529 		 (irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED) ? 1 : 0,
530 		 css_general_characteristics.aif_tdd,
531 		 (irq_ptr->siga_flag.input) ? "R" : " ",
532 		 (irq_ptr->siga_flag.output) ? "W" : " ",
533 		 (irq_ptr->siga_flag.sync) ? "S" : " ",
534 		 (irq_ptr->siga_flag.sync_after_ai) ? "A" : " ",
535 		 (irq_ptr->siga_flag.sync_out_after_pci) ? "P" : " ");
536 	printk(KERN_INFO "%s", s);
537 }
538 
qdio_enable_async_operation(struct qdio_output_q * outq)539 int qdio_enable_async_operation(struct qdio_output_q *outq)
540 {
541 	outq->aobs = kcalloc(QDIO_MAX_BUFFERS_PER_Q, sizeof(struct qaob *),
542 			     GFP_ATOMIC);
543 	if (!outq->aobs) {
544 		outq->use_cq = 0;
545 		return -ENOMEM;
546 	}
547 	outq->use_cq = 1;
548 	return 0;
549 }
550 
qdio_disable_async_operation(struct qdio_output_q * q)551 void qdio_disable_async_operation(struct qdio_output_q *q)
552 {
553 	kfree(q->aobs);
554 	q->aobs = NULL;
555 	q->use_cq = 0;
556 }
557 
qdio_setup_init(void)558 int __init qdio_setup_init(void)
559 {
560 	int rc;
561 
562 	qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q),
563 					 256, 0, NULL);
564 	if (!qdio_q_cache)
565 		return -ENOMEM;
566 
567 	qdio_aob_cache = kmem_cache_create("qdio_aob",
568 					sizeof(struct qaob),
569 					sizeof(struct qaob),
570 					0,
571 					NULL);
572 	if (!qdio_aob_cache) {
573 		rc = -ENOMEM;
574 		goto free_qdio_q_cache;
575 	}
576 
577 	/* Check for OSA/FCP thin interrupts (bit 67). */
578 	DBF_EVENT("thinint:%1d",
579 		  (css_general_characteristics.aif_osa) ? 1 : 0);
580 
581 	/* Check for QEBSM support in general (bit 58). */
582 	DBF_EVENT("cssQEBSM:%1d", (qebsm_possible()) ? 1 : 0);
583 	rc = 0;
584 out:
585 	return rc;
586 free_qdio_q_cache:
587 	kmem_cache_destroy(qdio_q_cache);
588 	goto out;
589 }
590 
qdio_setup_exit(void)591 void qdio_setup_exit(void)
592 {
593 	kmem_cache_destroy(qdio_aob_cache);
594 	kmem_cache_destroy(qdio_q_cache);
595 }
596