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