blob: 8daf1b99f15391a27f41e48e0407b1eefa01647c [file] [log] [blame]
Jan Glauber779e6e12008-07-17 17:16:48 +02001/*
2 * linux/drivers/s390/cio/thinint_qdio.c
3 *
Jan Glauber6486cda2010-01-04 09:05:42 +01004 * Copyright 2000,2009 IBM Corp.
Jan Glauber779e6e12008-07-17 17:16:48 +02005 * 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Jan Glauber779e6e12008-07-17 17:16:48 +020011#include <asm/atomic.h>
12#include <asm/debug.h>
13#include <asm/qdio.h>
14#include <asm/airq.h>
15#include <asm/isc.h>
16
17#include "cio.h"
18#include "ioasm.h"
19#include "qdio.h"
20#include "qdio_debug.h"
Jan Glauber779e6e12008-07-17 17:16:48 +020021
22/*
23 * Restriction: only 63 iqdio subchannels would have its own indicator,
24 * after that, subsequent subchannels share one indicator
25 */
26#define TIQDIO_NR_NONSHARED_IND 63
27#define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
28#define TIQDIO_SHARED_IND 63
29
30/* list of thin interrupt input queues */
31static LIST_HEAD(tiq_list);
Jan Glauberb4547402009-03-26 15:24:24 +010032DEFINE_MUTEX(tiq_list_lock);
Jan Glauber779e6e12008-07-17 17:16:48 +020033
34/* adapter local summary indicator */
35static unsigned char *tiqdio_alsi;
36
37/* device state change indicators */
38struct indicator_t {
39 u32 ind; /* u32 because of compare-and-swap performance */
40 atomic_t count; /* use count, 0 or 1 for non-shared indicators */
41};
42static struct indicator_t *q_indicators;
43
Jan Glauber779e6e12008-07-17 17:16:48 +020044static int css_qdio_omit_svs;
45
46static inline unsigned long do_clear_global_summary(void)
47{
48 register unsigned long __fn asm("1") = 3;
49 register unsigned long __tmp asm("2");
50 register unsigned long __time asm("3");
51
52 asm volatile(
53 " .insn rre,0xb2650000,2,0"
54 : "+d" (__fn), "=d" (__tmp), "=d" (__time));
55 return __time;
56}
57
58/* returns addr for the device state change indicator */
59static u32 *get_indicator(void)
60{
61 int i;
62
63 for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
64 if (!atomic_read(&q_indicators[i].count)) {
65 atomic_set(&q_indicators[i].count, 1);
66 return &q_indicators[i].ind;
67 }
68
69 /* use the shared indicator */
70 atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
71 return &q_indicators[TIQDIO_SHARED_IND].ind;
72}
73
74static void put_indicator(u32 *addr)
75{
76 int i;
77
78 if (!addr)
79 return;
80 i = ((unsigned long)addr - (unsigned long)q_indicators) /
81 sizeof(struct indicator_t);
82 atomic_dec(&q_indicators[i].count);
83}
84
85void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
86{
87 struct qdio_q *q;
88 int i;
89
90 /* No TDD facility? If we must use SIGA-s we can also omit SVS. */
91 if (!css_qdio_omit_svs && irq_ptr->siga_flag.sync)
92 css_qdio_omit_svs = 1;
93
Jan Glauberb4547402009-03-26 15:24:24 +010094 mutex_lock(&tiq_list_lock);
95 for_each_input_queue(irq_ptr, q, i)
Jan Glauber779e6e12008-07-17 17:16:48 +020096 list_add_rcu(&q->entry, &tiq_list);
Jan Glauberb4547402009-03-26 15:24:24 +010097 mutex_unlock(&tiq_list_lock);
Jan Glauberd0c9d4a2010-05-17 10:00:18 +020098 xchg(irq_ptr->dsci, 1 << 7);
Jan Glauber779e6e12008-07-17 17:16:48 +020099}
100
Jan Glauber779e6e12008-07-17 17:16:48 +0200101void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
102{
103 struct qdio_q *q;
104 int i;
105
Jan Glauber53b41ba2008-08-21 19:46:33 +0200106 for (i = 0; i < irq_ptr->nr_input_qs; i++) {
107 q = irq_ptr->input_qs[i];
108 /* if establish triggered an error */
109 if (!q || !q->entry.prev || !q->entry.next)
110 continue;
Jan Glauberb4547402009-03-26 15:24:24 +0100111
112 mutex_lock(&tiq_list_lock);
Jan Glauber779e6e12008-07-17 17:16:48 +0200113 list_del_rcu(&q->entry);
Jan Glauberb4547402009-03-26 15:24:24 +0100114 mutex_unlock(&tiq_list_lock);
Jan Glauber779e6e12008-07-17 17:16:48 +0200115 synchronize_rcu();
116 }
117}
118
Jan Glauber779e6e12008-07-17 17:16:48 +0200119static inline int shared_ind(struct qdio_irq *irq_ptr)
120{
121 return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
122}
123
Jan Glaubercf9a0312009-06-22 12:08:13 +0200124/**
125 * tiqdio_thinint_handler - thin interrupt handler for qdio
126 * @ind: pointer to adapter local summary indicator
127 * @drv_data: NULL
128 */
129static void tiqdio_thinint_handler(void *ind, void *drv_data)
Jan Glauber779e6e12008-07-17 17:16:48 +0200130{
131 struct qdio_q *q;
132
Jan Glaubercf9a0312009-06-22 12:08:13 +0200133 /*
134 * SVS only when needed: issue SVS to benefit from iqdio interrupt
135 * avoidance (SVS clears adapter interrupt suppression overwrite)
136 */
137 if (!css_qdio_omit_svs)
138 do_clear_global_summary();
139
140 /*
141 * reset local summary indicator (tiqdio_alsi) to stop adapter
142 * interrupts for now
143 */
144 xchg((u8 *)ind, 0);
Jan Glauber779e6e12008-07-17 17:16:48 +0200145
146 /* protect tiq_list entries, only changed in activate or shutdown */
147 rcu_read_lock();
148
Jan Glaubercf9a0312009-06-22 12:08:13 +0200149 /* check for work on all inbound thinint queues */
Jan Glauber779e6e12008-07-17 17:16:48 +0200150 list_for_each_entry_rcu(q, &tiq_list, entry)
151 /* only process queues from changed sets */
152 if (*q->irq_ptr->dsci) {
Jan Glauber6486cda2010-01-04 09:05:42 +0100153 qperf_inc(q, adapter_int);
Jan Glauber779e6e12008-07-17 17:16:48 +0200154
155 /* only clear it if the indicator is non-shared */
156 if (!shared_ind(q->irq_ptr))
157 xchg(q->irq_ptr->dsci, 0);
158 /*
159 * don't call inbound processing directly since
160 * that could starve other thinint queues
161 */
162 tasklet_schedule(&q->tasklet);
163 }
164
165 rcu_read_unlock();
166
167 /*
168 * if we used the shared indicator clear it now after all queues
169 * were processed
170 */
171 if (atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) {
172 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
173
174 /* prevent racing */
175 if (*tiqdio_alsi)
Jan Glauberd0c9d4a2010-05-17 10:00:18 +0200176 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1 << 7);
Jan Glauber779e6e12008-07-17 17:16:48 +0200177 }
Jan Glauber779e6e12008-07-17 17:16:48 +0200178}
179
180static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
181{
182 struct scssc_area *scssc_area;
Jan Glauber779e6e12008-07-17 17:16:48 +0200183 int rc;
184
185 scssc_area = (struct scssc_area *)irq_ptr->chsc_page;
186 memset(scssc_area, 0, PAGE_SIZE);
187
188 if (reset) {
189 scssc_area->summary_indicator_addr = 0;
190 scssc_area->subchannel_indicator_addr = 0;
191 } else {
192 scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi);
193 scssc_area->subchannel_indicator_addr =
194 virt_to_phys(irq_ptr->dsci);
195 }
196
197 scssc_area->request = (struct chsc_header) {
198 .length = 0x0fe0,
199 .code = 0x0021,
200 };
201 scssc_area->operation_code = 0;
Heiko Carstensd1bf8592010-02-26 22:37:30 +0100202 scssc_area->ks = PAGE_DEFAULT_KEY >> 4;
203 scssc_area->kc = PAGE_DEFAULT_KEY >> 4;
Jan Glauber779e6e12008-07-17 17:16:48 +0200204 scssc_area->isc = QDIO_AIRQ_ISC;
205 scssc_area->schid = irq_ptr->schid;
206
207 /* enable the time delay disablement facility */
208 if (css_general_characteristics.aif_tdd)
209 scssc_area->word_with_d_bit = 0x10000000;
210
211 rc = chsc(scssc_area);
212 if (rc)
213 return -EIO;
214
215 rc = chsc_error_from_response(scssc_area->response.code);
216 if (rc) {
Jan Glauber22f99342008-12-25 13:38:46 +0100217 DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
218 scssc_area->response.code);
219 DBF_ERROR_HEX(&scssc_area->response, sizeof(void *));
Jan Glauber779e6e12008-07-17 17:16:48 +0200220 return rc;
221 }
222
Jan Glauber22f99342008-12-25 13:38:46 +0100223 DBF_EVENT("setscind");
224 DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long));
225 DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long));
Jan Glauber779e6e12008-07-17 17:16:48 +0200226 return 0;
227}
228
229/* allocate non-shared indicators and shared indicator */
230int __init tiqdio_allocate_memory(void)
231{
232 q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
233 GFP_KERNEL);
234 if (!q_indicators)
235 return -ENOMEM;
236 return 0;
237}
238
239void tiqdio_free_memory(void)
240{
241 kfree(q_indicators);
242}
243
244int __init tiqdio_register_thinints(void)
245{
Jan Glauber779e6e12008-07-17 17:16:48 +0200246 isc_register(QDIO_AIRQ_ISC);
247 tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
248 NULL, QDIO_AIRQ_ISC);
249 if (IS_ERR(tiqdio_alsi)) {
Jan Glauber22f99342008-12-25 13:38:46 +0100250 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
Jan Glauber779e6e12008-07-17 17:16:48 +0200251 tiqdio_alsi = NULL;
252 isc_unregister(QDIO_AIRQ_ISC);
253 return -ENOMEM;
254 }
255 return 0;
256}
257
258int qdio_establish_thinint(struct qdio_irq *irq_ptr)
259{
260 if (!is_thinint_irq(irq_ptr))
261 return 0;
262
263 /* Check for aif time delay disablement. If installed,
264 * omit SVS even under LPAR
265 */
266 if (css_general_characteristics.aif_tdd)
267 css_qdio_omit_svs = 1;
268 return set_subchannel_ind(irq_ptr, 0);
269}
270
271void qdio_setup_thinint(struct qdio_irq *irq_ptr)
272{
273 if (!is_thinint_irq(irq_ptr))
274 return;
275 irq_ptr->dsci = get_indicator();
Jan Glauber22f99342008-12-25 13:38:46 +0100276 DBF_HEX(&irq_ptr->dsci, sizeof(void *));
Jan Glauber779e6e12008-07-17 17:16:48 +0200277}
278
279void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
280{
281 if (!is_thinint_irq(irq_ptr))
282 return;
283
284 /* reset adapter interrupt indicators */
285 put_indicator(irq_ptr->dsci);
286 set_subchannel_ind(irq_ptr, 1);
287}
288
289void __exit tiqdio_unregister_thinints(void)
290{
Jan Glauber9e890ad2009-03-26 15:24:30 +0100291 WARN_ON(!list_empty(&tiq_list));
Jan Glauber779e6e12008-07-17 17:16:48 +0200292
293 if (tiqdio_alsi) {
294 s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
295 isc_unregister(QDIO_AIRQ_ISC);
296 }
Jan Glauber779e6e12008-07-17 17:16:48 +0200297}