Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 2 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 3 | * Copyright IBM Corp. 2000, 2009 |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 4 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com> |
| 5 | * Cornelia Huck <cornelia.huck@de.ibm.com> |
| 6 | * Jan Glauber <jang@linux.vnet.ibm.com> |
| 7 | */ |
| 8 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Jan Glauber | 30d77c3 | 2011-01-05 12:47:29 +0100 | [diff] [blame] | 10 | #include <linux/kernel_stat.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 11 | #include <linux/atomic.h> |
Ingo Molnar | b2d0910 | 2017-02-04 01:27:20 +0100 | [diff] [blame] | 12 | #include <linux/rculist.h> |
| 13 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 14 | #include <asm/debug.h> |
| 15 | #include <asm/qdio.h> |
| 16 | #include <asm/airq.h> |
| 17 | #include <asm/isc.h> |
| 18 | |
| 19 | #include "cio.h" |
| 20 | #include "ioasm.h" |
| 21 | #include "qdio.h" |
| 22 | #include "qdio_debug.h" |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Restriction: only 63 iqdio subchannels would have its own indicator, |
| 26 | * after that, subsequent subchannels share one indicator |
| 27 | */ |
| 28 | #define TIQDIO_NR_NONSHARED_IND 63 |
| 29 | #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1) |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 30 | #define TIQDIO_SHARED_IND 63 |
| 31 | |
| 32 | /* device state change indicators */ |
| 33 | struct indicator_t { |
| 34 | u32 ind; /* u32 because of compare-and-swap performance */ |
| 35 | atomic_t count; /* use count, 0 or 1 for non-shared indicators */ |
| 36 | }; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 37 | |
| 38 | /* list of thin interrupt input queues */ |
| 39 | static LIST_HEAD(tiq_list); |
Martin Schwidefsky | c4736d9 | 2011-10-30 15:17:11 +0100 | [diff] [blame] | 40 | static DEFINE_MUTEX(tiq_list_lock); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 41 | |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 42 | static struct indicator_t *q_indicators; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 43 | |
Jan Glauber | a2b8601 | 2011-10-30 15:17:05 +0100 | [diff] [blame] | 44 | u64 last_ai_time; |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 45 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 46 | /* returns addr for the device state change indicator */ |
| 47 | static u32 *get_indicator(void) |
| 48 | { |
| 49 | int i; |
| 50 | |
| 51 | for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++) |
Sebastian Ott | 648a6f4 | 2017-10-26 16:36:45 +0200 | [diff] [blame] | 52 | if (!atomic_cmpxchg(&q_indicators[i].count, 0, 1)) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 53 | return &q_indicators[i].ind; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 54 | |
| 55 | /* use the shared indicator */ |
| 56 | atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count); |
| 57 | return &q_indicators[TIQDIO_SHARED_IND].ind; |
| 58 | } |
| 59 | |
| 60 | static void put_indicator(u32 *addr) |
| 61 | { |
Sebastian Ott | 30e8eb86 | 2017-10-26 16:47:25 +0200 | [diff] [blame] | 62 | struct indicator_t *ind = container_of(addr, struct indicator_t, ind); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 63 | |
| 64 | if (!addr) |
| 65 | return; |
Sebastian Ott | 30e8eb86 | 2017-10-26 16:47:25 +0200 | [diff] [blame] | 66 | atomic_dec(&ind->count); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 67 | } |
| 68 | |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 69 | static inline int references_shared_dsci(struct qdio_irq *irq_ptr) |
| 70 | { |
| 71 | return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind; |
| 72 | } |
| 73 | |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 74 | int test_nonshared_ind(struct qdio_irq *irq_ptr) |
| 75 | { |
| 76 | if (!is_thinint_irq(irq_ptr)) |
| 77 | return 0; |
Julian Wiedmann | 9c159bb | 2020-03-20 14:00:00 +0100 | [diff] [blame] | 78 | if (references_shared_dsci(irq_ptr)) |
Jan Glauber | 5f4026f | 2011-10-30 15:17:20 +0100 | [diff] [blame] | 79 | return 0; |
| 80 | if (*irq_ptr->dsci) |
| 81 | return 1; |
| 82 | else |
| 83 | return 0; |
| 84 | } |
| 85 | |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 86 | static inline u32 clear_shared_ind(void) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 87 | { |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 88 | if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) |
| 89 | return 0; |
| 90 | return xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 93 | /** |
| 94 | * tiqdio_thinint_handler - thin interrupt handler for qdio |
Julian Wiedmann | 72a01d0 | 2016-11-21 11:19:57 +0100 | [diff] [blame] | 95 | * @airq: pointer to adapter interrupt descriptor |
Sebastian Ott | 34c636a | 2019-06-04 13:51:36 +0200 | [diff] [blame] | 96 | * @floating: flag to recognize floating vs. directed interrupts (unused) |
Jan Glauber | cf9a031 | 2009-06-22 12:08:13 +0200 | [diff] [blame] | 97 | */ |
Sebastian Ott | 30e63ef | 2018-10-28 11:51:56 +0100 | [diff] [blame] | 98 | static void tiqdio_thinint_handler(struct airq_struct *airq, bool floating) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 99 | { |
Julian Wiedmann | bd83917 | 2020-09-15 10:04:39 +0300 | [diff] [blame] | 100 | u64 irq_time = S390_lowcore.int_clock; |
Jan Glauber | b02f0c2 | 2011-07-24 10:48:00 +0200 | [diff] [blame] | 101 | u32 si_used = clear_shared_ind(); |
Julian Wiedmann | 94c43bd | 2019-07-23 11:55:27 +0200 | [diff] [blame] | 102 | struct qdio_irq *irq; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 103 | |
Julian Wiedmann | bd83917 | 2020-09-15 10:04:39 +0300 | [diff] [blame] | 104 | last_ai_time = irq_time; |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 105 | inc_irq_stat(IRQIO_QAI); |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 106 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 107 | /* protect tiq_list entries, only changed in activate or shutdown */ |
| 108 | rcu_read_lock(); |
| 109 | |
Julian Wiedmann | 94c43bd | 2019-07-23 11:55:27 +0200 | [diff] [blame] | 110 | list_for_each_entry_rcu(irq, &tiq_list, entry) { |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 111 | /* only process queues from changed sets */ |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 112 | if (unlikely(references_shared_dsci(irq))) { |
Jan Glauber | 4f32518 | 2011-01-05 12:47:49 +0100 | [diff] [blame] | 113 | if (!si_used) |
| 114 | continue; |
Julian Wiedmann | 1ecbcfd | 2020-06-02 14:09:10 +0200 | [diff] [blame] | 115 | } else { |
| 116 | if (!*irq->dsci) |
| 117 | continue; |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 118 | |
Julian Wiedmann | 1ecbcfd | 2020-06-02 14:09:10 +0200 | [diff] [blame] | 119 | xchg(irq->dsci, 0); |
| 120 | } |
| 121 | |
| 122 | qdio_deliver_irq(irq); |
Julian Wiedmann | bd83917 | 2020-09-15 10:04:39 +0300 | [diff] [blame] | 123 | irq->last_data_irq_time = irq_time; |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 124 | |
Julian Wiedmann | 4611281 | 2019-09-30 15:42:35 +0200 | [diff] [blame] | 125 | QDIO_PERF_STAT_INC(irq, adapter_int); |
Jan Glauber | d36deae | 2010-09-07 21:14:39 +0000 | [diff] [blame] | 126 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 127 | rcu_read_unlock(); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Julian Wiedmann | d86f71f | 2019-07-23 10:23:32 +0200 | [diff] [blame] | 130 | static struct airq_struct tiqdio_airq = { |
| 131 | .handler = tiqdio_thinint_handler, |
| 132 | .isc = QDIO_AIRQ_ISC, |
| 133 | }; |
| 134 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 135 | static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset) |
| 136 | { |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 137 | struct chsc_scssc_area *scssc = (void *)irq_ptr->chsc_page; |
| 138 | u64 summary_indicator_addr, subchannel_indicator_addr; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 139 | int rc; |
| 140 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 141 | if (reset) { |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 142 | summary_indicator_addr = 0; |
| 143 | subchannel_indicator_addr = 0; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 144 | } else { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 145 | summary_indicator_addr = virt_to_phys(tiqdio_airq.lsi_ptr); |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 146 | subchannel_indicator_addr = virt_to_phys(irq_ptr->dsci); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 147 | } |
| 148 | |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 149 | rc = chsc_sadc(irq_ptr->schid, scssc, summary_indicator_addr, |
Julian Wiedmann | 9289224 | 2020-03-16 09:20:38 +0100 | [diff] [blame] | 150 | subchannel_indicator_addr, tiqdio_airq.isc); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 151 | if (rc) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 152 | DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no, |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 153 | scssc->response.code); |
| 154 | goto out; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 157 | DBF_EVENT("setscind"); |
Sebastian Ott | ca4ba15 | 2013-06-05 18:59:22 +0200 | [diff] [blame] | 158 | DBF_HEX(&summary_indicator_addr, sizeof(summary_indicator_addr)); |
| 159 | DBF_HEX(&subchannel_indicator_addr, sizeof(subchannel_indicator_addr)); |
| 160 | out: |
| 161 | return rc; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 164 | int qdio_establish_thinint(struct qdio_irq *irq_ptr) |
| 165 | { |
Julian Wiedmann | 75e82be | 2020-04-09 09:59:39 +0200 | [diff] [blame] | 166 | int rc; |
| 167 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 168 | if (!is_thinint_irq(irq_ptr)) |
| 169 | return 0; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 170 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 171 | irq_ptr->dsci = get_indicator(); |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 172 | DBF_HEX(&irq_ptr->dsci, sizeof(void *)); |
Julian Wiedmann | 75e82be | 2020-04-09 09:59:39 +0200 | [diff] [blame] | 173 | |
| 174 | rc = set_subchannel_ind(irq_ptr, 0); |
Julian Wiedmann | 954d623 | 2020-09-30 10:09:07 +0200 | [diff] [blame] | 175 | if (rc) { |
Julian Wiedmann | 75e82be | 2020-04-09 09:59:39 +0200 | [diff] [blame] | 176 | put_indicator(irq_ptr->dsci); |
Julian Wiedmann | 954d623 | 2020-09-30 10:09:07 +0200 | [diff] [blame] | 177 | return rc; |
| 178 | } |
Julian Wiedmann | 75e82be | 2020-04-09 09:59:39 +0200 | [diff] [blame] | 179 | |
Julian Wiedmann | 954d623 | 2020-09-30 10:09:07 +0200 | [diff] [blame] | 180 | mutex_lock(&tiq_list_lock); |
| 181 | list_add_rcu(&irq_ptr->entry, &tiq_list); |
| 182 | mutex_unlock(&tiq_list_lock); |
| 183 | return 0; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void qdio_shutdown_thinint(struct qdio_irq *irq_ptr) |
| 187 | { |
| 188 | if (!is_thinint_irq(irq_ptr)) |
| 189 | return; |
| 190 | |
Julian Wiedmann | 954d623 | 2020-09-30 10:09:07 +0200 | [diff] [blame] | 191 | mutex_lock(&tiq_list_lock); |
| 192 | list_del_rcu(&irq_ptr->entry); |
| 193 | mutex_unlock(&tiq_list_lock); |
| 194 | synchronize_rcu(); |
| 195 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 196 | /* reset adapter interrupt indicators */ |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 197 | set_subchannel_ind(irq_ptr, 1); |
Jan Glauber | 4814a2b | 2010-11-25 09:52:46 +0100 | [diff] [blame] | 198 | put_indicator(irq_ptr->dsci); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Julian Wiedmann | 3050f02 | 2020-04-02 11:37:50 +0200 | [diff] [blame] | 201 | int __init qdio_thinint_init(void) |
| 202 | { |
| 203 | int rc; |
| 204 | |
| 205 | q_indicators = kcalloc(TIQDIO_NR_INDICATORS, sizeof(struct indicator_t), |
| 206 | GFP_KERNEL); |
| 207 | if (!q_indicators) |
| 208 | return -ENOMEM; |
| 209 | |
| 210 | rc = register_adapter_interrupt(&tiqdio_airq); |
| 211 | if (rc) { |
| 212 | DBF_EVENT("RTI:%x", rc); |
| 213 | kfree(q_indicators); |
| 214 | return rc; |
| 215 | } |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | void __exit qdio_thinint_exit(void) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 220 | { |
Jan Glauber | 9e890ad | 2009-03-26 15:24:30 +0100 | [diff] [blame] | 221 | WARN_ON(!list_empty(&tiq_list)); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 222 | unregister_adapter_interrupt(&tiqdio_airq); |
Julian Wiedmann | 3050f02 | 2020-04-02 11:37:50 +0200 | [diff] [blame] | 223 | kfree(q_indicators); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 224 | } |