Merge branch 'akpm'
[linux-2.6/next.git] / drivers / s390 / cio / qdio_thinint.c
bloba3e3949d7b692d36c4aec1260b1aab74fd6b6e74
1 /*
2 * linux/drivers/s390/cio/thinint_qdio.c
4 * Copyright 2000,2009 IBM Corp.
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
6 * Cornelia Huck <cornelia.huck@de.ibm.com>
7 * Jan Glauber <jang@linux.vnet.ibm.com>
8 */
9 #include <linux/io.h>
10 #include <linux/slab.h>
11 #include <linux/kernel_stat.h>
12 #include <linux/atomic.h>
13 #include <asm/debug.h>
14 #include <asm/qdio.h>
15 #include <asm/airq.h>
16 #include <asm/isc.h>
18 #include "cio.h"
19 #include "ioasm.h"
20 #include "qdio.h"
21 #include "qdio_debug.h"
24 * Restriction: only 63 iqdio subchannels would have its own indicator,
25 * after that, subsequent subchannels share one indicator
27 #define TIQDIO_NR_NONSHARED_IND 63
28 #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
30 /* list of thin interrupt input queues */
31 static LIST_HEAD(tiq_list);
32 DEFINE_MUTEX(tiq_list_lock);
34 /* adapter local summary indicator */
35 static u8 *tiqdio_alsi;
37 struct indicator_t *q_indicators;
39 static u64 last_ai_time;
41 /* returns addr for the device state change indicator */
42 static u32 *get_indicator(void)
44 int i;
46 for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
47 if (!atomic_read(&q_indicators[i].count)) {
48 atomic_set(&q_indicators[i].count, 1);
49 return &q_indicators[i].ind;
52 /* use the shared indicator */
53 atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
54 return &q_indicators[TIQDIO_SHARED_IND].ind;
57 static void put_indicator(u32 *addr)
59 int i;
61 if (!addr)
62 return;
63 i = ((unsigned long)addr - (unsigned long)q_indicators) /
64 sizeof(struct indicator_t);
65 atomic_dec(&q_indicators[i].count);
68 void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
70 mutex_lock(&tiq_list_lock);
71 BUG_ON(irq_ptr->nr_input_qs < 1);
72 list_add_rcu(&irq_ptr->input_qs[0]->entry, &tiq_list);
73 mutex_unlock(&tiq_list_lock);
74 xchg(irq_ptr->dsci, 1 << 7);
77 void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
79 struct qdio_q *q;
81 BUG_ON(irq_ptr->nr_input_qs < 1);
82 q = irq_ptr->input_qs[0];
83 /* if establish triggered an error */
84 if (!q || !q->entry.prev || !q->entry.next)
85 return;
87 mutex_lock(&tiq_list_lock);
88 list_del_rcu(&q->entry);
89 mutex_unlock(&tiq_list_lock);
90 synchronize_rcu();
93 static inline u32 clear_shared_ind(void)
95 if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count))
96 return 0;
97 return xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
100 static inline void tiqdio_call_inq_handlers(struct qdio_irq *irq)
102 struct qdio_q *q;
103 int i;
105 for_each_input_queue(irq, q, i) {
106 if (!references_shared_dsci(irq) &&
107 has_multiple_inq_on_dsci(irq))
108 xchg(q->irq_ptr->dsci, 0);
110 if (q->u.in.queue_start_poll) {
111 /* skip if polling is enabled or already in work */
112 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
113 &q->u.in.queue_irq_state)) {
114 qperf_inc(q, int_discarded);
115 continue;
118 /* avoid dsci clear here, done after processing */
119 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
120 q->irq_ptr->int_parm);
121 } else {
122 if (!shared_ind(q))
123 xchg(q->irq_ptr->dsci, 0);
126 * Call inbound processing but not directly
127 * since that could starve other thinint queues.
129 tasklet_schedule(&q->tasklet);
135 * tiqdio_thinint_handler - thin interrupt handler for qdio
136 * @alsi: pointer to adapter local summary indicator
137 * @data: NULL
139 static void tiqdio_thinint_handler(void *alsi, void *data)
141 u32 si_used = clear_shared_ind();
142 struct qdio_q *q;
144 last_ai_time = S390_lowcore.int_clock;
145 kstat_cpu(smp_processor_id()).irqs[IOINT_QAI]++;
147 /* protect tiq_list entries, only changed in activate or shutdown */
148 rcu_read_lock();
150 /* check for work on all inbound thinint queues */
151 list_for_each_entry_rcu(q, &tiq_list, entry) {
152 struct qdio_irq *irq;
154 /* only process queues from changed sets */
155 irq = q->irq_ptr;
156 if (unlikely(references_shared_dsci(irq))) {
157 if (!si_used)
158 continue;
159 } else if (!*irq->dsci)
160 continue;
162 tiqdio_call_inq_handlers(irq);
164 qperf_inc(q, adapter_int);
166 rcu_read_unlock();
169 static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
171 struct scssc_area *scssc_area;
172 int rc;
174 scssc_area = (struct scssc_area *)irq_ptr->chsc_page;
175 memset(scssc_area, 0, PAGE_SIZE);
177 if (reset) {
178 scssc_area->summary_indicator_addr = 0;
179 scssc_area->subchannel_indicator_addr = 0;
180 } else {
181 scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi);
182 scssc_area->subchannel_indicator_addr =
183 virt_to_phys(irq_ptr->dsci);
186 scssc_area->request = (struct chsc_header) {
187 .length = 0x0fe0,
188 .code = 0x0021,
190 scssc_area->operation_code = 0;
191 scssc_area->ks = PAGE_DEFAULT_KEY >> 4;
192 scssc_area->kc = PAGE_DEFAULT_KEY >> 4;
193 scssc_area->isc = QDIO_AIRQ_ISC;
194 scssc_area->schid = irq_ptr->schid;
196 /* enable the time delay disablement facility */
197 if (css_general_characteristics.aif_tdd)
198 scssc_area->word_with_d_bit = 0x10000000;
200 rc = chsc(scssc_area);
201 if (rc)
202 return -EIO;
204 rc = chsc_error_from_response(scssc_area->response.code);
205 if (rc) {
206 DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
207 scssc_area->response.code);
208 DBF_ERROR_HEX(&scssc_area->response, sizeof(void *));
209 return rc;
212 DBF_EVENT("setscind");
213 DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long));
214 DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long));
215 return 0;
218 /* allocate non-shared indicators and shared indicator */
219 int __init tiqdio_allocate_memory(void)
221 q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
222 GFP_KERNEL);
223 if (!q_indicators)
224 return -ENOMEM;
225 return 0;
228 void tiqdio_free_memory(void)
230 kfree(q_indicators);
233 int __init tiqdio_register_thinints(void)
235 isc_register(QDIO_AIRQ_ISC);
236 tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
237 NULL, QDIO_AIRQ_ISC);
238 if (IS_ERR(tiqdio_alsi)) {
239 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
240 tiqdio_alsi = NULL;
241 isc_unregister(QDIO_AIRQ_ISC);
242 return -ENOMEM;
244 return 0;
247 int qdio_establish_thinint(struct qdio_irq *irq_ptr)
249 if (!is_thinint_irq(irq_ptr))
250 return 0;
251 return set_subchannel_ind(irq_ptr, 0);
254 void qdio_setup_thinint(struct qdio_irq *irq_ptr)
256 if (!is_thinint_irq(irq_ptr))
257 return;
258 irq_ptr->dsci = get_indicator();
259 DBF_HEX(&irq_ptr->dsci, sizeof(void *));
262 void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
264 if (!is_thinint_irq(irq_ptr))
265 return;
267 /* reset adapter interrupt indicators */
268 set_subchannel_ind(irq_ptr, 1);
269 put_indicator(irq_ptr->dsci);
272 void __exit tiqdio_unregister_thinints(void)
274 WARN_ON(!list_empty(&tiq_list));
276 if (tiqdio_alsi) {
277 s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
278 isc_unregister(QDIO_AIRQ_ISC);