Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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