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 | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 11 | #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 Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 21 | |
| 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 */ |
| 31 | static LIST_HEAD(tiq_list); |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 32 | DEFINE_MUTEX(tiq_list_lock); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 33 | |
| 34 | /* adapter local summary indicator */ |
| 35 | static unsigned char *tiqdio_alsi; |
| 36 | |
| 37 | /* device state change indicators */ |
| 38 | struct 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 | }; |
| 42 | static struct indicator_t *q_indicators; |
| 43 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 44 | static int css_qdio_omit_svs; |
| 45 | |
| 46 | static 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 */ |
| 59 | static 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 | |
| 74 | static 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 | |
| 85 | void 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 Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 94 | mutex_lock(&tiq_list_lock); |
| 95 | for_each_input_queue(irq_ptr, q, i) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 96 | list_add_rcu(&q->entry, &tiq_list); |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 97 | mutex_unlock(&tiq_list_lock); |
Jan Glauber | d0c9d4a | 2010-05-17 10:00:18 +0200 | [diff] [blame^] | 98 | xchg(irq_ptr->dsci, 1 << 7); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 101 | void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr) |
| 102 | { |
| 103 | struct qdio_q *q; |
| 104 | int i; |
| 105 | |
Jan Glauber | 53b41ba | 2008-08-21 19:46:33 +0200 | [diff] [blame] | 106 | 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 Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 111 | |
| 112 | mutex_lock(&tiq_list_lock); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 113 | list_del_rcu(&q->entry); |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 114 | mutex_unlock(&tiq_list_lock); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 115 | synchronize_rcu(); |
| 116 | } |
| 117 | } |
| 118 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 119 | static inline int shared_ind(struct qdio_irq *irq_ptr) |
| 120 | { |
| 121 | return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind; |
| 122 | } |
| 123 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 124 | /** |
| 125 | * tiqdio_thinint_handler - thin interrupt handler for qdio |
| 126 | * @ind: pointer to adapter local summary indicator |
| 127 | * @drv_data: NULL |
| 128 | */ |
| 129 | static void tiqdio_thinint_handler(void *ind, void *drv_data) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 130 | { |
| 131 | struct qdio_q *q; |
| 132 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 133 | /* |
| 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 Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 145 | |
| 146 | /* protect tiq_list entries, only changed in activate or shutdown */ |
| 147 | rcu_read_lock(); |
| 148 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 149 | /* check for work on all inbound thinint queues */ |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 150 | list_for_each_entry_rcu(q, &tiq_list, entry) |
| 151 | /* only process queues from changed sets */ |
| 152 | if (*q->irq_ptr->dsci) { |
Jan Glauber | 6486cda | 2010-01-04 09:05:42 +0100 | [diff] [blame] | 153 | qperf_inc(q, adapter_int); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 154 | |
| 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 Glauber | d0c9d4a | 2010-05-17 10:00:18 +0200 | [diff] [blame^] | 176 | xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1 << 7); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 177 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset) |
| 181 | { |
| 182 | struct scssc_area *scssc_area; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 183 | 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 Carstens | d1bf859 | 2010-02-26 22:37:30 +0100 | [diff] [blame] | 202 | scssc_area->ks = PAGE_DEFAULT_KEY >> 4; |
| 203 | scssc_area->kc = PAGE_DEFAULT_KEY >> 4; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 204 | 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 Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 217 | 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 Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 220 | return rc; |
| 221 | } |
| 222 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 223 | 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 Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /* allocate non-shared indicators and shared indicator */ |
| 230 | int __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 | |
| 239 | void tiqdio_free_memory(void) |
| 240 | { |
| 241 | kfree(q_indicators); |
| 242 | } |
| 243 | |
| 244 | int __init tiqdio_register_thinints(void) |
| 245 | { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 246 | 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 Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 250 | DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 251 | tiqdio_alsi = NULL; |
| 252 | isc_unregister(QDIO_AIRQ_ISC); |
| 253 | return -ENOMEM; |
| 254 | } |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | int 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 | |
| 271 | void 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 Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 276 | DBF_HEX(&irq_ptr->dsci, sizeof(void *)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | void 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 | |
| 289 | void __exit tiqdio_unregister_thinints(void) |
| 290 | { |
Jan Glauber | 9e890ad | 2009-03-26 15:24:30 +0100 | [diff] [blame] | 291 | WARN_ON(!list_empty(&tiq_list)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 292 | |
| 293 | if (tiqdio_alsi) { |
| 294 | s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC); |
| 295 | isc_unregister(QDIO_AIRQ_ISC); |
| 296 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 297 | } |