2 * Copyright IBM Corp. 2000, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
4 * Cornelia Huck <cornelia.huck@de.ibm.com>
5 * Jan Glauber <jang@linux.vnet.ibm.com>
8 #include <linux/slab.h>
9 #include <linux/kernel_stat.h>
10 #include <linux/atomic.h>
11 #include <asm/debug.h>
19 #include "qdio_debug.h"
22 * Restriction: only 63 iqdio subchannels would have its own indicator,
23 * after that, subsequent subchannels share one indicator
25 #define TIQDIO_NR_NONSHARED_IND 63
26 #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
27 #define TIQDIO_SHARED_IND 63
29 /* device state change indicators */
31 u32 ind; /* u32 because of compare-and-swap performance */
32 atomic_t count; /* use count, 0 or 1 for non-shared indicators */
35 /* list of thin interrupt input queues */
36 static LIST_HEAD(tiq_list);
37 static DEFINE_MUTEX(tiq_list_lock);
39 /* adapter local summary indicator */
40 static u8 *tiqdio_alsi;
42 static struct indicator_t *q_indicators;
46 /* returns addr for the device state change indicator */
47 static u32 *get_indicator(void)
51 for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
52 if (!atomic_read(&q_indicators[i].count)) {
53 atomic_set(&q_indicators[i].count, 1);
54 return &q_indicators[i].ind;
57 /* use the shared indicator */
58 atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
59 return &q_indicators[TIQDIO_SHARED_IND].ind;
62 static void put_indicator(u32 *addr)
68 i = ((unsigned long)addr - (unsigned long)q_indicators) /
69 sizeof(struct indicator_t);
70 atomic_dec(&q_indicators[i].count);
73 void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
75 mutex_lock(&tiq_list_lock);
76 list_add_rcu(&irq_ptr->input_qs[0]->entry, &tiq_list);
77 mutex_unlock(&tiq_list_lock);
78 xchg(irq_ptr->dsci, 1 << 7);
81 void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
85 q = irq_ptr->input_qs[0];
86 /* if establish triggered an error */
87 if (!q || !q->entry.prev || !q->entry.next)
90 mutex_lock(&tiq_list_lock);
91 list_del_rcu(&q->entry);
92 mutex_unlock(&tiq_list_lock);
96 static inline int has_multiple_inq_on_dsci(struct qdio_irq *irq_ptr)
98 return irq_ptr->nr_input_qs > 1;
101 static inline int references_shared_dsci(struct qdio_irq *irq_ptr)
103 return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
106 static inline int shared_ind(struct qdio_irq *irq_ptr)
108 return references_shared_dsci(irq_ptr) ||
109 has_multiple_inq_on_dsci(irq_ptr);
112 void clear_nonshared_ind(struct qdio_irq *irq_ptr)
114 if (!is_thinint_irq(irq_ptr))
116 if (shared_ind(irq_ptr))
118 xchg(irq_ptr->dsci, 0);
121 int test_nonshared_ind(struct qdio_irq *irq_ptr)
123 if (!is_thinint_irq(irq_ptr))
125 if (shared_ind(irq_ptr))
133 static inline u32 clear_shared_ind(void)
135 if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count))
137 return xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
140 static inline void tiqdio_call_inq_handlers(struct qdio_irq *irq)
145 for_each_input_queue(irq, q, i) {
146 if (!references_shared_dsci(irq) &&
147 has_multiple_inq_on_dsci(irq))
148 xchg(q->irq_ptr->dsci, 0);
150 if (q->u.in.queue_start_poll) {
151 /* skip if polling is enabled or already in work */
152 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
153 &q->u.in.queue_irq_state)) {
154 qperf_inc(q, int_discarded);
158 /* avoid dsci clear here, done after processing */
159 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
160 q->irq_ptr->int_parm);
162 if (!shared_ind(q->irq_ptr))
163 xchg(q->irq_ptr->dsci, 0);
166 * Call inbound processing but not directly
167 * since that could starve other thinint queues.
169 tasklet_schedule(&q->tasklet);
175 * tiqdio_thinint_handler - thin interrupt handler for qdio
176 * @alsi: pointer to adapter local summary indicator
179 static void tiqdio_thinint_handler(void *alsi, void *data)
181 u32 si_used = clear_shared_ind();
184 last_ai_time = S390_lowcore.int_clock;
185 kstat_cpu(smp_processor_id()).irqs[IOINT_QAI]++;
187 /* protect tiq_list entries, only changed in activate or shutdown */
190 /* check for work on all inbound thinint queues */
191 list_for_each_entry_rcu(q, &tiq_list, entry) {
192 struct qdio_irq *irq;
194 /* only process queues from changed sets */
196 if (unlikely(references_shared_dsci(irq))) {
199 } else if (!*irq->dsci)
202 tiqdio_call_inq_handlers(irq);
204 qperf_inc(q, adapter_int);
209 static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
211 struct scssc_area *scssc_area;
214 scssc_area = (struct scssc_area *)irq_ptr->chsc_page;
215 memset(scssc_area, 0, PAGE_SIZE);
218 scssc_area->summary_indicator_addr = 0;
219 scssc_area->subchannel_indicator_addr = 0;
221 scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi);
222 scssc_area->subchannel_indicator_addr =
223 virt_to_phys(irq_ptr->dsci);
226 scssc_area->request = (struct chsc_header) {
230 scssc_area->operation_code = 0;
231 scssc_area->ks = PAGE_DEFAULT_KEY >> 4;
232 scssc_area->kc = PAGE_DEFAULT_KEY >> 4;
233 scssc_area->isc = QDIO_AIRQ_ISC;
234 scssc_area->schid = irq_ptr->schid;
236 /* enable the time delay disablement facility */
237 if (css_general_characteristics.aif_tdd)
238 scssc_area->word_with_d_bit = 0x10000000;
240 rc = chsc(scssc_area);
244 rc = chsc_error_from_response(scssc_area->response.code);
246 DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
247 scssc_area->response.code);
248 DBF_ERROR_HEX(&scssc_area->response, sizeof(void *));
252 DBF_EVENT("setscind");
253 DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long));
254 DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long));
258 /* allocate non-shared indicators and shared indicator */
259 int __init tiqdio_allocate_memory(void)
261 q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
268 void tiqdio_free_memory(void)
273 int __init tiqdio_register_thinints(void)
275 isc_register(QDIO_AIRQ_ISC);
276 tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
277 NULL, QDIO_AIRQ_ISC);
278 if (IS_ERR(tiqdio_alsi)) {
279 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
281 isc_unregister(QDIO_AIRQ_ISC);
287 int qdio_establish_thinint(struct qdio_irq *irq_ptr)
289 if (!is_thinint_irq(irq_ptr))
291 return set_subchannel_ind(irq_ptr, 0);
294 void qdio_setup_thinint(struct qdio_irq *irq_ptr)
296 if (!is_thinint_irq(irq_ptr))
298 irq_ptr->dsci = get_indicator();
299 DBF_HEX(&irq_ptr->dsci, sizeof(void *));
302 void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
304 if (!is_thinint_irq(irq_ptr))
307 /* reset adapter interrupt indicators */
308 set_subchannel_ind(irq_ptr, 1);
309 put_indicator(irq_ptr->dsci);
312 void __exit tiqdio_unregister_thinints(void)
314 WARN_ON(!list_empty(&tiq_list));
317 s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
318 isc_unregister(QDIO_AIRQ_ISC);