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 | 60063497 | 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 | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 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 */ |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 35 | static u8 *tiqdio_alsi; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 36 | |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 37 | struct indicator_t *q_indicators; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 38 | |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 39 | static u64 last_ai_time; |
| 40 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 41 | /* returns addr for the device state change indicator */ |
| 42 | static u32 *get_indicator(void) |
| 43 | { |
| 44 | int i; |
| 45 | |
| 46 | for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++) |
| 47 | if (!atomic_read(&q_indicators[i].count)) { |
| 48 | atomic_set(&q_indicators[i].count, 1); |
| 49 | return &q_indicators[i].ind; |
| 50 | } |
| 51 | |
| 52 | /* use the shared indicator */ |
| 53 | atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count); |
| 54 | return &q_indicators[TIQDIO_SHARED_IND].ind; |
| 55 | } |
| 56 | |
| 57 | static void put_indicator(u32 *addr) |
| 58 | { |
| 59 | int i; |
| 60 | |
| 61 | if (!addr) |
| 62 | return; |
| 63 | i = ((unsigned long)addr - (unsigned long)q_indicators) / |
| 64 | sizeof(struct indicator_t); |
| 65 | atomic_dec(&q_indicators[i].count); |
| 66 | } |
| 67 | |
| 68 | void tiqdio_add_input_queues(struct qdio_irq *irq_ptr) |
| 69 | { |
| 70 | struct qdio_q *q; |
| 71 | int i; |
| 72 | |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 73 | mutex_lock(&tiq_list_lock); |
| 74 | for_each_input_queue(irq_ptr, q, i) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 75 | list_add_rcu(&q->entry, &tiq_list); |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 76 | mutex_unlock(&tiq_list_lock); |
Jan Glauber | d0c9d4a | 2010-05-17 10:00:18 +0200 | [diff] [blame] | 77 | xchg(irq_ptr->dsci, 1 << 7); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 78 | } |
| 79 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 80 | void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr) |
| 81 | { |
| 82 | struct qdio_q *q; |
| 83 | int i; |
| 84 | |
Jan Glauber | 53b41ba | 2008-08-21 19:46:33 +0200 | [diff] [blame] | 85 | for (i = 0; i < irq_ptr->nr_input_qs; i++) { |
| 86 | q = irq_ptr->input_qs[i]; |
| 87 | /* if establish triggered an error */ |
| 88 | if (!q || !q->entry.prev || !q->entry.next) |
| 89 | continue; |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 90 | |
| 91 | mutex_lock(&tiq_list_lock); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 92 | list_del_rcu(&q->entry); |
Jan Glauber | b454740 | 2009-03-26 15:24:24 +0100 | [diff] [blame] | 93 | mutex_unlock(&tiq_list_lock); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 94 | synchronize_rcu(); |
| 95 | } |
| 96 | } |
| 97 | |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 98 | static inline u32 clear_shared_ind(void) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 99 | { |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 100 | if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) |
| 101 | return 0; |
| 102 | return xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 103 | } |
| 104 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 105 | /** |
| 106 | * tiqdio_thinint_handler - thin interrupt handler for qdio |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 107 | * @alsi: pointer to adapter local summary indicator |
| 108 | * @data: NULL |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 109 | */ |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 110 | static void tiqdio_thinint_handler(void *alsi, void *data) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 111 | { |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 112 | u32 si_used = clear_shared_ind(); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 113 | struct qdio_q *q; |
| 114 | |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 115 | last_ai_time = S390_lowcore.int_clock; |
Jan Glauber | 30d77c3 | 2011-01-05 12:47:29 +0100 | [diff] [blame] | 116 | kstat_cpu(smp_processor_id()).irqs[IOINT_QAI]++; |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 117 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 118 | /* protect tiq_list entries, only changed in activate or shutdown */ |
| 119 | rcu_read_lock(); |
| 120 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 121 | /* check for work on all inbound thinint queues */ |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 122 | list_for_each_entry_rcu(q, &tiq_list, entry) { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 123 | |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 124 | /* only process queues from changed sets */ |
Jan Glauber | 4f32518 | 2011-01-05 12:47:49 +0100 | [diff] [blame] | 125 | if (unlikely(shared_ind(q->irq_ptr->dsci))) { |
| 126 | if (!si_used) |
| 127 | continue; |
| 128 | } else if (!*q->irq_ptr->dsci) |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 129 | continue; |
| 130 | |
| 131 | if (q->u.in.queue_start_poll) { |
| 132 | /* skip if polling is enabled or already in work */ |
| 133 | if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED, |
| 134 | &q->u.in.queue_irq_state)) { |
| 135 | qperf_inc(q, int_discarded); |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | /* avoid dsci clear here, done after processing */ |
| 140 | q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr, |
| 141 | q->irq_ptr->int_parm); |
| 142 | } else { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 143 | /* only clear it if the indicator is non-shared */ |
Jan Glauber | 4f32518 | 2011-01-05 12:47:49 +0100 | [diff] [blame] | 144 | if (!shared_ind(q->irq_ptr->dsci)) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 145 | xchg(q->irq_ptr->dsci, 0); |
| 146 | /* |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 147 | * Call inbound processing but not directly |
| 148 | * since that could starve other thinint queues. |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 149 | */ |
| 150 | tasklet_schedule(&q->tasklet); |
| 151 | } |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 152 | qperf_inc(q, adapter_int); |
| 153 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 154 | rcu_read_unlock(); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset) |
| 158 | { |
| 159 | struct scssc_area *scssc_area; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 160 | int rc; |
| 161 | |
| 162 | scssc_area = (struct scssc_area *)irq_ptr->chsc_page; |
| 163 | memset(scssc_area, 0, PAGE_SIZE); |
| 164 | |
| 165 | if (reset) { |
| 166 | scssc_area->summary_indicator_addr = 0; |
| 167 | scssc_area->subchannel_indicator_addr = 0; |
| 168 | } else { |
| 169 | scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi); |
| 170 | scssc_area->subchannel_indicator_addr = |
| 171 | virt_to_phys(irq_ptr->dsci); |
| 172 | } |
| 173 | |
| 174 | scssc_area->request = (struct chsc_header) { |
| 175 | .length = 0x0fe0, |
| 176 | .code = 0x0021, |
| 177 | }; |
| 178 | scssc_area->operation_code = 0; |
Heiko Carstens | d1bf859 | 2010-02-26 22:37:30 +0100 | [diff] [blame] | 179 | scssc_area->ks = PAGE_DEFAULT_KEY >> 4; |
| 180 | scssc_area->kc = PAGE_DEFAULT_KEY >> 4; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 181 | scssc_area->isc = QDIO_AIRQ_ISC; |
| 182 | scssc_area->schid = irq_ptr->schid; |
| 183 | |
| 184 | /* enable the time delay disablement facility */ |
| 185 | if (css_general_characteristics.aif_tdd) |
| 186 | scssc_area->word_with_d_bit = 0x10000000; |
| 187 | |
| 188 | rc = chsc(scssc_area); |
| 189 | if (rc) |
| 190 | return -EIO; |
| 191 | |
| 192 | rc = chsc_error_from_response(scssc_area->response.code); |
| 193 | if (rc) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 194 | DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no, |
| 195 | scssc_area->response.code); |
| 196 | DBF_ERROR_HEX(&scssc_area->response, sizeof(void *)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 197 | return rc; |
| 198 | } |
| 199 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 200 | DBF_EVENT("setscind"); |
| 201 | DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long)); |
| 202 | DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | /* allocate non-shared indicators and shared indicator */ |
| 207 | int __init tiqdio_allocate_memory(void) |
| 208 | { |
| 209 | q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS, |
| 210 | GFP_KERNEL); |
| 211 | if (!q_indicators) |
| 212 | return -ENOMEM; |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | void tiqdio_free_memory(void) |
| 217 | { |
| 218 | kfree(q_indicators); |
| 219 | } |
| 220 | |
| 221 | int __init tiqdio_register_thinints(void) |
| 222 | { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 223 | isc_register(QDIO_AIRQ_ISC); |
| 224 | tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler, |
| 225 | NULL, QDIO_AIRQ_ISC); |
| 226 | if (IS_ERR(tiqdio_alsi)) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 227 | DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 228 | tiqdio_alsi = NULL; |
| 229 | isc_unregister(QDIO_AIRQ_ISC); |
| 230 | return -ENOMEM; |
| 231 | } |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | int qdio_establish_thinint(struct qdio_irq *irq_ptr) |
| 236 | { |
| 237 | if (!is_thinint_irq(irq_ptr)) |
| 238 | return 0; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 239 | return set_subchannel_ind(irq_ptr, 0); |
| 240 | } |
| 241 | |
| 242 | void qdio_setup_thinint(struct qdio_irq *irq_ptr) |
| 243 | { |
| 244 | if (!is_thinint_irq(irq_ptr)) |
| 245 | return; |
| 246 | irq_ptr->dsci = get_indicator(); |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 247 | DBF_HEX(&irq_ptr->dsci, sizeof(void *)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void qdio_shutdown_thinint(struct qdio_irq *irq_ptr) |
| 251 | { |
| 252 | if (!is_thinint_irq(irq_ptr)) |
| 253 | return; |
| 254 | |
| 255 | /* reset adapter interrupt indicators */ |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 256 | set_subchannel_ind(irq_ptr, 1); |
Jan Glauber | 4814a2b | 2010-11-25 09:52:46 +0100 | [diff] [blame] | 257 | put_indicator(irq_ptr->dsci); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void __exit tiqdio_unregister_thinints(void) |
| 261 | { |
Jan Glauber | 9e890ad | 2009-03-26 15:24:30 +0100 | [diff] [blame] | 262 | WARN_ON(!list_empty(&tiq_list)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 263 | |
| 264 | if (tiqdio_alsi) { |
| 265 | s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC); |
| 266 | isc_unregister(QDIO_AIRQ_ISC); |
| 267 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 268 | } |