USB: ftdi_sio: re-implement read processing
[linux-2.6/mini2440.git] / drivers / s390 / cio / qdio_thinint.c
blob981a77ea7ee24871c3f4d72db130c014238ebbde
1 /*
2 * linux/drivers/s390/cio/thinint_qdio.c
4 * thin interrupt support for qdio
6 * Copyright 2000-2008 IBM Corp.
7 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
8 * Cornelia Huck <cornelia.huck@de.ibm.com>
9 * Jan Glauber <jang@linux.vnet.ibm.com>
11 #include <linux/io.h>
12 #include <asm/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"
22 #include "qdio_perf.h"
25 * Restriction: only 63 iqdio subchannels would have its own indicator,
26 * after that, subsequent subchannels share one indicator
28 #define TIQDIO_NR_NONSHARED_IND 63
29 #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
30 #define TIQDIO_SHARED_IND 63
32 /* list of thin interrupt input queues */
33 static LIST_HEAD(tiq_list);
34 DEFINE_MUTEX(tiq_list_lock);
36 /* adapter local summary indicator */
37 static unsigned char *tiqdio_alsi;
39 /* device state change indicators */
40 struct indicator_t {
41 u32 ind; /* u32 because of compare-and-swap performance */
42 atomic_t count; /* use count, 0 or 1 for non-shared indicators */
44 static struct indicator_t *q_indicators;
46 static int css_qdio_omit_svs;
48 static inline unsigned long do_clear_global_summary(void)
50 register unsigned long __fn asm("1") = 3;
51 register unsigned long __tmp asm("2");
52 register unsigned long __time asm("3");
54 asm volatile(
55 " .insn rre,0xb2650000,2,0"
56 : "+d" (__fn), "=d" (__tmp), "=d" (__time));
57 return __time;
60 /* returns addr for the device state change indicator */
61 static u32 *get_indicator(void)
63 int i;
65 for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
66 if (!atomic_read(&q_indicators[i].count)) {
67 atomic_set(&q_indicators[i].count, 1);
68 return &q_indicators[i].ind;
71 /* use the shared indicator */
72 atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
73 return &q_indicators[TIQDIO_SHARED_IND].ind;
76 static void put_indicator(u32 *addr)
78 int i;
80 if (!addr)
81 return;
82 i = ((unsigned long)addr - (unsigned long)q_indicators) /
83 sizeof(struct indicator_t);
84 atomic_dec(&q_indicators[i].count);
87 void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
89 struct qdio_q *q;
90 int i;
92 /* No TDD facility? If we must use SIGA-s we can also omit SVS. */
93 if (!css_qdio_omit_svs && irq_ptr->siga_flag.sync)
94 css_qdio_omit_svs = 1;
96 mutex_lock(&tiq_list_lock);
97 for_each_input_queue(irq_ptr, q, i)
98 list_add_rcu(&q->entry, &tiq_list);
99 mutex_unlock(&tiq_list_lock);
100 xchg(irq_ptr->dsci, 1);
103 void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
105 struct qdio_q *q;
106 int i;
108 for (i = 0; i < irq_ptr->nr_input_qs; i++) {
109 q = irq_ptr->input_qs[i];
110 /* if establish triggered an error */
111 if (!q || !q->entry.prev || !q->entry.next)
112 continue;
114 mutex_lock(&tiq_list_lock);
115 list_del_rcu(&q->entry);
116 mutex_unlock(&tiq_list_lock);
117 synchronize_rcu();
121 static inline int shared_ind(struct qdio_irq *irq_ptr)
123 return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
127 * tiqdio_thinint_handler - thin interrupt handler for qdio
128 * @ind: pointer to adapter local summary indicator
129 * @drv_data: NULL
131 static void tiqdio_thinint_handler(void *ind, void *drv_data)
133 struct qdio_q *q;
135 qdio_perf_stat_inc(&perf_stats.thin_int);
138 * SVS only when needed: issue SVS to benefit from iqdio interrupt
139 * avoidance (SVS clears adapter interrupt suppression overwrite)
141 if (!css_qdio_omit_svs)
142 do_clear_global_summary();
145 * reset local summary indicator (tiqdio_alsi) to stop adapter
146 * interrupts for now
148 xchg((u8 *)ind, 0);
150 /* protect tiq_list entries, only changed in activate or shutdown */
151 rcu_read_lock();
153 /* check for work on all inbound thinint queues */
154 list_for_each_entry_rcu(q, &tiq_list, entry)
155 /* only process queues from changed sets */
156 if (*q->irq_ptr->dsci) {
158 /* only clear it if the indicator is non-shared */
159 if (!shared_ind(q->irq_ptr))
160 xchg(q->irq_ptr->dsci, 0);
162 * don't call inbound processing directly since
163 * that could starve other thinint queues
165 tasklet_schedule(&q->tasklet);
168 rcu_read_unlock();
171 * if we used the shared indicator clear it now after all queues
172 * were processed
174 if (atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) {
175 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
177 /* prevent racing */
178 if (*tiqdio_alsi)
179 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1);
183 static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
185 struct scssc_area *scssc_area;
186 int rc;
188 scssc_area = (struct scssc_area *)irq_ptr->chsc_page;
189 memset(scssc_area, 0, PAGE_SIZE);
191 if (reset) {
192 scssc_area->summary_indicator_addr = 0;
193 scssc_area->subchannel_indicator_addr = 0;
194 } else {
195 scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi);
196 scssc_area->subchannel_indicator_addr =
197 virt_to_phys(irq_ptr->dsci);
200 scssc_area->request = (struct chsc_header) {
201 .length = 0x0fe0,
202 .code = 0x0021,
204 scssc_area->operation_code = 0;
205 scssc_area->ks = PAGE_DEFAULT_KEY;
206 scssc_area->kc = PAGE_DEFAULT_KEY;
207 scssc_area->isc = QDIO_AIRQ_ISC;
208 scssc_area->schid = irq_ptr->schid;
210 /* enable the time delay disablement facility */
211 if (css_general_characteristics.aif_tdd)
212 scssc_area->word_with_d_bit = 0x10000000;
214 rc = chsc(scssc_area);
215 if (rc)
216 return -EIO;
218 rc = chsc_error_from_response(scssc_area->response.code);
219 if (rc) {
220 DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
221 scssc_area->response.code);
222 DBF_ERROR_HEX(&scssc_area->response, sizeof(void *));
223 return rc;
226 DBF_EVENT("setscind");
227 DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long));
228 DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long));
229 return 0;
232 /* allocate non-shared indicators and shared indicator */
233 int __init tiqdio_allocate_memory(void)
235 q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
236 GFP_KERNEL);
237 if (!q_indicators)
238 return -ENOMEM;
239 return 0;
242 void tiqdio_free_memory(void)
244 kfree(q_indicators);
247 int __init tiqdio_register_thinints(void)
249 isc_register(QDIO_AIRQ_ISC);
250 tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
251 NULL, QDIO_AIRQ_ISC);
252 if (IS_ERR(tiqdio_alsi)) {
253 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
254 tiqdio_alsi = NULL;
255 isc_unregister(QDIO_AIRQ_ISC);
256 return -ENOMEM;
258 return 0;
261 int qdio_establish_thinint(struct qdio_irq *irq_ptr)
263 if (!is_thinint_irq(irq_ptr))
264 return 0;
266 /* Check for aif time delay disablement. If installed,
267 * omit SVS even under LPAR
269 if (css_general_characteristics.aif_tdd)
270 css_qdio_omit_svs = 1;
271 return set_subchannel_ind(irq_ptr, 0);
274 void qdio_setup_thinint(struct qdio_irq *irq_ptr)
276 if (!is_thinint_irq(irq_ptr))
277 return;
278 irq_ptr->dsci = get_indicator();
279 DBF_HEX(&irq_ptr->dsci, sizeof(void *));
282 void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
284 if (!is_thinint_irq(irq_ptr))
285 return;
287 /* reset adapter interrupt indicators */
288 put_indicator(irq_ptr->dsci);
289 set_subchannel_ind(irq_ptr, 1);
292 void __exit tiqdio_unregister_thinints(void)
294 WARN_ON(!list_empty(&tiq_list));
296 if (tiqdio_alsi) {
297 s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
298 isc_unregister(QDIO_AIRQ_ISC);