Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2000, 2009 |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 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> |
| 6 | */ |
| 7 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
Jan Glauber | 30d77c3 | 2011-01-05 12:47:29 +0100 | [diff] [blame] | 9 | #include <linux/kernel_stat.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 10 | #include <linux/atomic.h> |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 11 | #include <asm/debug.h> |
| 12 | #include <asm/qdio.h> |
| 13 | #include <asm/airq.h> |
| 14 | #include <asm/isc.h> |
| 15 | |
| 16 | #include "cio.h" |
| 17 | #include "ioasm.h" |
| 18 | #include "qdio.h" |
| 19 | #include "qdio_debug.h" |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Restriction: only 63 iqdio subchannels would have its own indicator, |
| 23 | * after that, subsequent subchannels share one indicator |
| 24 | */ |
| 25 | #define TIQDIO_NR_NONSHARED_IND 63 |
| 26 | #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1) |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 27 | #define TIQDIO_SHARED_IND 63 |
| 28 | |
| 29 | /* device state change indicators */ |
| 30 | struct indicator_t { |
| 31 | u32 ind; /* u32 because of compare-and-swap performance */ |
| 32 | atomic_t count; /* use count, 0 or 1 for non-shared indicators */ |
| 33 | }; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 34 | |
| 35 | /* list of thin interrupt input queues */ |
| 36 | static LIST_HEAD(tiq_list); |
Martin Schwidefsky | c4736d9 | 2011-10-30 15:17:11 +0100 | [diff] [blame] | 37 | static DEFINE_MUTEX(tiq_list_lock); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 38 | |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 39 | /* Adapter interrupt definitions */ |
| 40 | static void tiqdio_thinint_handler(struct airq_struct *airq); |
| 41 | |
| 42 | static struct airq_struct tiqdio_airq = { |
| 43 | .handler = tiqdio_thinint_handler, |
| 44 | .isc = QDIO_AIRQ_ISC, |
| 45 | }; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 46 | |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 47 | static struct indicator_t *q_indicators; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 48 | |
Jan Glauber | a2b8601 | 2011-10-30 15:17:05 +0100 | [diff] [blame] | 49 | u64 last_ai_time; |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 50 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 51 | /* returns addr for the device state change indicator */ |
| 52 | static u32 *get_indicator(void) |
| 53 | { |
| 54 | int i; |
| 55 | |
| 56 | for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++) |
| 57 | if (!atomic_read(&q_indicators[i].count)) { |
| 58 | atomic_set(&q_indicators[i].count, 1); |
| 59 | return &q_indicators[i].ind; |
| 60 | } |
| 61 | |
| 62 | /* use the shared indicator */ |
| 63 | atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count); |
| 64 | return &q_indicators[TIQDIO_SHARED_IND].ind; |
| 65 | } |
| 66 | |
| 67 | static void put_indicator(u32 *addr) |
| 68 | { |
| 69 | int i; |
| 70 | |
| 71 | if (!addr) |
| 72 | return; |
| 73 | i = ((unsigned long)addr - (unsigned long)q_indicators) / |
| 74 | sizeof(struct indicator_t); |
| 75 | atomic_dec(&q_indicators[i].count); |
| 76 | } |
| 77 | |
| 78 | void tiqdio_add_input_queues(struct qdio_irq *irq_ptr) |
| 79 | { |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 80 | mutex_lock(&tiq_list_lock); |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 81 | list_add_rcu(&irq_ptr->input_qs[0]->entry, &tiq_list); |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 82 | mutex_unlock(&tiq_list_lock); |
Jan Glauber | d0c9d4a | 2010-05-17 10:00:18 +0200 | [diff] [blame] | 83 | xchg(irq_ptr->dsci, 1 << 7); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 86 | void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr) |
| 87 | { |
| 88 | struct qdio_q *q; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 89 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 90 | q = irq_ptr->input_qs[0]; |
| 91 | /* if establish triggered an error */ |
| 92 | if (!q || !q->entry.prev || !q->entry.next) |
| 93 | return; |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 94 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 95 | mutex_lock(&tiq_list_lock); |
| 96 | list_del_rcu(&q->entry); |
| 97 | mutex_unlock(&tiq_list_lock); |
| 98 | synchronize_rcu(); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 101 | static inline int has_multiple_inq_on_dsci(struct qdio_irq *irq_ptr) |
| 102 | { |
| 103 | return irq_ptr->nr_input_qs > 1; |
| 104 | } |
| 105 | |
| 106 | static inline int references_shared_dsci(struct qdio_irq *irq_ptr) |
| 107 | { |
| 108 | return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind; |
| 109 | } |
| 110 | |
| 111 | static inline int shared_ind(struct qdio_irq *irq_ptr) |
| 112 | { |
| 113 | return references_shared_dsci(irq_ptr) || |
| 114 | has_multiple_inq_on_dsci(irq_ptr); |
| 115 | } |
| 116 | |
| 117 | void clear_nonshared_ind(struct qdio_irq *irq_ptr) |
| 118 | { |
| 119 | if (!is_thinint_irq(irq_ptr)) |
| 120 | return; |
| 121 | if (shared_ind(irq_ptr)) |
| 122 | return; |
| 123 | xchg(irq_ptr->dsci, 0); |
| 124 | } |
| 125 | |
| 126 | int test_nonshared_ind(struct qdio_irq *irq_ptr) |
| 127 | { |
| 128 | if (!is_thinint_irq(irq_ptr)) |
| 129 | return 0; |
| 130 | if (shared_ind(irq_ptr)) |
| 131 | return 0; |
| 132 | if (*irq_ptr->dsci) |
| 133 | return 1; |
| 134 | else |
| 135 | return 0; |
| 136 | } |
| 137 | |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 138 | static inline u32 clear_shared_ind(void) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 139 | { |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 140 | if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) |
| 141 | return 0; |
| 142 | return xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 143 | } |
| 144 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 145 | static inline void tiqdio_call_inq_handlers(struct qdio_irq *irq) |
| 146 | { |
| 147 | struct qdio_q *q; |
| 148 | int i; |
| 149 | |
| 150 | for_each_input_queue(irq, q, i) { |
| 151 | if (!references_shared_dsci(irq) && |
| 152 | has_multiple_inq_on_dsci(irq)) |
| 153 | xchg(q->irq_ptr->dsci, 0); |
| 154 | |
| 155 | if (q->u.in.queue_start_poll) { |
| 156 | /* skip if polling is enabled or already in work */ |
| 157 | if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED, |
| 158 | &q->u.in.queue_irq_state)) { |
| 159 | qperf_inc(q, int_discarded); |
| 160 | continue; |
| 161 | } |
| 162 | |
| 163 | /* avoid dsci clear here, done after processing */ |
| 164 | q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr, |
| 165 | q->irq_ptr->int_parm); |
| 166 | } else { |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 167 | if (!shared_ind(q->irq_ptr)) |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 168 | xchg(q->irq_ptr->dsci, 0); |
| 169 | |
| 170 | /* |
| 171 | * Call inbound processing but not directly |
| 172 | * since that could starve other thinint queues. |
| 173 | */ |
| 174 | tasklet_schedule(&q->tasklet); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 179 | /** |
| 180 | * tiqdio_thinint_handler - thin interrupt handler for qdio |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 181 | * @alsi: pointer to adapter local summary indicator |
| 182 | * @data: NULL |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 183 | */ |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 184 | static void tiqdio_thinint_handler(struct airq_struct *airq) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 185 | { |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 186 | u32 si_used = clear_shared_ind(); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 187 | struct qdio_q *q; |
| 188 | |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 189 | last_ai_time = S390_lowcore.int_clock; |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 190 | inc_irq_stat(IRQIO_QAI); |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 191 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 192 | /* protect tiq_list entries, only changed in activate or shutdown */ |
| 193 | rcu_read_lock(); |
| 194 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 195 | /* check for work on all inbound thinint queues */ |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 196 | list_for_each_entry_rcu(q, &tiq_list, entry) { |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 197 | struct qdio_irq *irq; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 198 | |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 199 | /* only process queues from changed sets */ |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 200 | irq = q->irq_ptr; |
| 201 | if (unlikely(references_shared_dsci(irq))) { |
Jan Glauber | 4f32518 | 2011-01-05 12:47:49 +0100 | [diff] [blame] | 202 | if (!si_used) |
| 203 | continue; |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 204 | } else if (!*irq->dsci) |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 205 | continue; |
| 206 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 207 | tiqdio_call_inq_handlers(irq); |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 208 | |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 209 | qperf_inc(q, adapter_int); |
| 210 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 211 | rcu_read_unlock(); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset) |
| 215 | { |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 216 | struct chsc_scssc_area *scssc = (void *)irq_ptr->chsc_page; |
| 217 | u64 summary_indicator_addr, subchannel_indicator_addr; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 218 | int rc; |
| 219 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 220 | if (reset) { |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 221 | summary_indicator_addr = 0; |
| 222 | subchannel_indicator_addr = 0; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 223 | } else { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 224 | summary_indicator_addr = virt_to_phys(tiqdio_airq.lsi_ptr); |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 225 | subchannel_indicator_addr = virt_to_phys(irq_ptr->dsci); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 228 | rc = chsc_sadc(irq_ptr->schid, scssc, summary_indicator_addr, |
| 229 | subchannel_indicator_addr); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 230 | if (rc) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 231 | DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no, |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 232 | scssc->response.code); |
| 233 | goto out; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 234 | } |
| 235 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 236 | DBF_EVENT("setscind"); |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 237 | DBF_HEX(&summary_indicator_addr, sizeof(summary_indicator_addr)); |
| 238 | DBF_HEX(&subchannel_indicator_addr, sizeof(subchannel_indicator_addr)); |
| 239 | out: |
| 240 | return rc; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* allocate non-shared indicators and shared indicator */ |
| 244 | int __init tiqdio_allocate_memory(void) |
| 245 | { |
| 246 | q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS, |
| 247 | GFP_KERNEL); |
| 248 | if (!q_indicators) |
| 249 | return -ENOMEM; |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | void tiqdio_free_memory(void) |
| 254 | { |
| 255 | kfree(q_indicators); |
| 256 | } |
| 257 | |
| 258 | int __init tiqdio_register_thinints(void) |
| 259 | { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 260 | int rc; |
| 261 | |
| 262 | rc = register_adapter_interrupt(&tiqdio_airq); |
| 263 | if (rc) { |
| 264 | DBF_EVENT("RTI:%x", rc); |
| 265 | return rc; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 266 | } |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | int qdio_establish_thinint(struct qdio_irq *irq_ptr) |
| 271 | { |
| 272 | if (!is_thinint_irq(irq_ptr)) |
| 273 | return 0; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 274 | return set_subchannel_ind(irq_ptr, 0); |
| 275 | } |
| 276 | |
| 277 | void qdio_setup_thinint(struct qdio_irq *irq_ptr) |
| 278 | { |
| 279 | if (!is_thinint_irq(irq_ptr)) |
| 280 | return; |
| 281 | irq_ptr->dsci = get_indicator(); |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 282 | DBF_HEX(&irq_ptr->dsci, sizeof(void *)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void qdio_shutdown_thinint(struct qdio_irq *irq_ptr) |
| 286 | { |
| 287 | if (!is_thinint_irq(irq_ptr)) |
| 288 | return; |
| 289 | |
| 290 | /* reset adapter interrupt indicators */ |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 291 | set_subchannel_ind(irq_ptr, 1); |
Jan Glauber | 4814a2b | 2010-11-25 09:52:46 +0100 | [diff] [blame] | 292 | put_indicator(irq_ptr->dsci); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | void __exit tiqdio_unregister_thinints(void) |
| 296 | { |
Jan Glauber | 9e890ad | 2009-03-26 15:24:30 +0100 | [diff] [blame] | 297 | WARN_ON(!list_empty(&tiq_list)); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 298 | unregister_adapter_interrupt(&tiqdio_airq); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 299 | } |