blob: 8e09bf3a2fcdf6a058084ac786238f8966c826f0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jan Glauber779e6e12008-07-17 17:16:48 +02002/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02003 * Copyright IBM Corp. 2000, 2009
Jan Glauber779e6e12008-07-17 17:16:48 +02004 * 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 Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Jan Glauber30d77c32011-01-05 12:47:29 +010010#include <linux/kernel_stat.h>
Arun Sharma600634972011-07-26 16:09:06 -070011#include <linux/atomic.h>
Ingo Molnarb2d09102017-02-04 01:27:20 +010012#include <linux/rculist.h>
13
Jan Glauber779e6e12008-07-17 17:16:48 +020014#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 Glauber779e6e12008-07-17 17:16:48 +020023
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 Glauber5f4026f2011-10-30 15:17:20 +010030#define TIQDIO_SHARED_IND 63
31
32/* device state change indicators */
33struct 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 Glauber779e6e12008-07-17 17:16:48 +020037
38/* list of thin interrupt input queues */
39static LIST_HEAD(tiq_list);
Martin Schwidefskyc4736d92011-10-30 15:17:11 +010040static DEFINE_MUTEX(tiq_list_lock);
Jan Glauber779e6e12008-07-17 17:16:48 +020041
Jan Glauber5f4026f2011-10-30 15:17:20 +010042static struct indicator_t *q_indicators;
Jan Glauber779e6e12008-07-17 17:16:48 +020043
Jan Glaubera2b86012011-10-30 15:17:05 +010044u64 last_ai_time;
Jan Glauberd36deae2010-09-07 21:14:39 +000045
Jan Glauber779e6e12008-07-17 17:16:48 +020046/* returns addr for the device state change indicator */
47static u32 *get_indicator(void)
48{
49 int i;
50
51 for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
Sebastian Ott648a6f42017-10-26 16:36:45 +020052 if (!atomic_cmpxchg(&q_indicators[i].count, 0, 1))
Jan Glauber779e6e12008-07-17 17:16:48 +020053 return &q_indicators[i].ind;
Jan Glauber779e6e12008-07-17 17:16:48 +020054
55 /* use the shared indicator */
56 atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
57 return &q_indicators[TIQDIO_SHARED_IND].ind;
58}
59
60static void put_indicator(u32 *addr)
61{
Sebastian Ott30e8eb862017-10-26 16:47:25 +020062 struct indicator_t *ind = container_of(addr, struct indicator_t, ind);
Jan Glauber779e6e12008-07-17 17:16:48 +020063
64 if (!addr)
65 return;
Sebastian Ott30e8eb862017-10-26 16:47:25 +020066 atomic_dec(&ind->count);
Jan Glauber779e6e12008-07-17 17:16:48 +020067}
68
Jan Glauber5f4026f2011-10-30 15:17:20 +010069static 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 Glauber5f4026f2011-10-30 15:17:20 +010074int test_nonshared_ind(struct qdio_irq *irq_ptr)
75{
76 if (!is_thinint_irq(irq_ptr))
77 return 0;
Julian Wiedmann9c159bb2020-03-20 14:00:00 +010078 if (references_shared_dsci(irq_ptr))
Jan Glauber5f4026f2011-10-30 15:17:20 +010079 return 0;
80 if (*irq_ptr->dsci)
81 return 1;
82 else
83 return 0;
84}
85
Jan Glauberb02f0c22011-07-24 10:48:00 +020086static inline u32 clear_shared_ind(void)
Jan Glauber779e6e12008-07-17 17:16:48 +020087{
Jan Glauberb02f0c22011-07-24 10:48:00 +020088 if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count))
89 return 0;
90 return xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
Jan Glauber779e6e12008-07-17 17:16:48 +020091}
92
Jan Glaubercf9a0312009-06-22 12:08:13 +020093/**
94 * tiqdio_thinint_handler - thin interrupt handler for qdio
Julian Wiedmann72a01d02016-11-21 11:19:57 +010095 * @airq: pointer to adapter interrupt descriptor
Sebastian Ott34c636a2019-06-04 13:51:36 +020096 * @floating: flag to recognize floating vs. directed interrupts (unused)
Jan Glaubercf9a0312009-06-22 12:08:13 +020097 */
Sebastian Ott30e63ef2018-10-28 11:51:56 +010098static void tiqdio_thinint_handler(struct airq_struct *airq, bool floating)
Jan Glauber779e6e12008-07-17 17:16:48 +020099{
Julian Wiedmannbd839172020-09-15 10:04:39 +0300100 u64 irq_time = S390_lowcore.int_clock;
Jan Glauberb02f0c22011-07-24 10:48:00 +0200101 u32 si_used = clear_shared_ind();
Julian Wiedmann94c43bd2019-07-23 11:55:27 +0200102 struct qdio_irq *irq;
Jan Glauber779e6e12008-07-17 17:16:48 +0200103
Julian Wiedmannbd839172020-09-15 10:04:39 +0300104 last_ai_time = irq_time;
Heiko Carstens420f42e2013-01-02 15:18:18 +0100105 inc_irq_stat(IRQIO_QAI);
Jan Glauberd36deae2010-09-07 21:14:39 +0000106
Jan Glauber779e6e12008-07-17 17:16:48 +0200107 /* protect tiq_list entries, only changed in activate or shutdown */
108 rcu_read_lock();
109
Julian Wiedmann94c43bd2019-07-23 11:55:27 +0200110 list_for_each_entry_rcu(irq, &tiq_list, entry) {
Jan Glauberd36deae2010-09-07 21:14:39 +0000111 /* only process queues from changed sets */
frank.blaschka@de.ibm.com104ea552011-08-08 01:33:55 +0000112 if (unlikely(references_shared_dsci(irq))) {
Jan Glauber4f325182011-01-05 12:47:49 +0100113 if (!si_used)
114 continue;
Julian Wiedmann1ecbcfd2020-06-02 14:09:10 +0200115 } else {
116 if (!*irq->dsci)
117 continue;
Jan Glauberd36deae2010-09-07 21:14:39 +0000118
Julian Wiedmann1ecbcfd2020-06-02 14:09:10 +0200119 xchg(irq->dsci, 0);
120 }
121
122 qdio_deliver_irq(irq);
Julian Wiedmannbd839172020-09-15 10:04:39 +0300123 irq->last_data_irq_time = irq_time;
Jan Glauberd36deae2010-09-07 21:14:39 +0000124
Julian Wiedmann46112812019-09-30 15:42:35 +0200125 QDIO_PERF_STAT_INC(irq, adapter_int);
Jan Glauberd36deae2010-09-07 21:14:39 +0000126 }
Jan Glauber779e6e12008-07-17 17:16:48 +0200127 rcu_read_unlock();
Jan Glauber779e6e12008-07-17 17:16:48 +0200128}
129
Julian Wiedmannd86f71f2019-07-23 10:23:32 +0200130static struct airq_struct tiqdio_airq = {
131 .handler = tiqdio_thinint_handler,
132 .isc = QDIO_AIRQ_ISC,
133};
134
Jan Glauber779e6e12008-07-17 17:16:48 +0200135static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
136{
Sebastian Ottca4ba152013-06-05 18:59:22 +0200137 struct chsc_scssc_area *scssc = (void *)irq_ptr->chsc_page;
138 u64 summary_indicator_addr, subchannel_indicator_addr;
Jan Glauber779e6e12008-07-17 17:16:48 +0200139 int rc;
140
Jan Glauber779e6e12008-07-17 17:16:48 +0200141 if (reset) {
Sebastian Ottca4ba152013-06-05 18:59:22 +0200142 summary_indicator_addr = 0;
143 subchannel_indicator_addr = 0;
Jan Glauber779e6e12008-07-17 17:16:48 +0200144 } else {
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200145 summary_indicator_addr = virt_to_phys(tiqdio_airq.lsi_ptr);
Sebastian Ottca4ba152013-06-05 18:59:22 +0200146 subchannel_indicator_addr = virt_to_phys(irq_ptr->dsci);
Jan Glauber779e6e12008-07-17 17:16:48 +0200147 }
148
Sebastian Ottca4ba152013-06-05 18:59:22 +0200149 rc = chsc_sadc(irq_ptr->schid, scssc, summary_indicator_addr,
Julian Wiedmann92892242020-03-16 09:20:38 +0100150 subchannel_indicator_addr, tiqdio_airq.isc);
Jan Glauber779e6e12008-07-17 17:16:48 +0200151 if (rc) {
Jan Glauber22f99342008-12-25 13:38:46 +0100152 DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
Sebastian Ottca4ba152013-06-05 18:59:22 +0200153 scssc->response.code);
154 goto out;
Jan Glauber779e6e12008-07-17 17:16:48 +0200155 }
156
Jan Glauber22f99342008-12-25 13:38:46 +0100157 DBF_EVENT("setscind");
Sebastian Ottca4ba152013-06-05 18:59:22 +0200158 DBF_HEX(&summary_indicator_addr, sizeof(summary_indicator_addr));
159 DBF_HEX(&subchannel_indicator_addr, sizeof(subchannel_indicator_addr));
160out:
161 return rc;
Jan Glauber779e6e12008-07-17 17:16:48 +0200162}
163
Jan Glauber779e6e12008-07-17 17:16:48 +0200164int qdio_establish_thinint(struct qdio_irq *irq_ptr)
165{
Julian Wiedmann75e82be2020-04-09 09:59:39 +0200166 int rc;
167
Jan Glauber779e6e12008-07-17 17:16:48 +0200168 if (!is_thinint_irq(irq_ptr))
169 return 0;
Jan Glauber779e6e12008-07-17 17:16:48 +0200170
Jan Glauber779e6e12008-07-17 17:16:48 +0200171 irq_ptr->dsci = get_indicator();
Jan Glauber22f99342008-12-25 13:38:46 +0100172 DBF_HEX(&irq_ptr->dsci, sizeof(void *));
Julian Wiedmann75e82be2020-04-09 09:59:39 +0200173
174 rc = set_subchannel_ind(irq_ptr, 0);
Julian Wiedmann954d6232020-09-30 10:09:07 +0200175 if (rc) {
Julian Wiedmann75e82be2020-04-09 09:59:39 +0200176 put_indicator(irq_ptr->dsci);
Julian Wiedmann954d6232020-09-30 10:09:07 +0200177 return rc;
178 }
Julian Wiedmann75e82be2020-04-09 09:59:39 +0200179
Julian Wiedmann954d6232020-09-30 10:09:07 +0200180 mutex_lock(&tiq_list_lock);
181 list_add_rcu(&irq_ptr->entry, &tiq_list);
182 mutex_unlock(&tiq_list_lock);
183 return 0;
Jan Glauber779e6e12008-07-17 17:16:48 +0200184}
185
186void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
187{
188 if (!is_thinint_irq(irq_ptr))
189 return;
190
Julian Wiedmann954d6232020-09-30 10:09:07 +0200191 mutex_lock(&tiq_list_lock);
192 list_del_rcu(&irq_ptr->entry);
193 mutex_unlock(&tiq_list_lock);
194 synchronize_rcu();
195
Jan Glauber779e6e12008-07-17 17:16:48 +0200196 /* reset adapter interrupt indicators */
Jan Glauber779e6e12008-07-17 17:16:48 +0200197 set_subchannel_ind(irq_ptr, 1);
Jan Glauber4814a2b2010-11-25 09:52:46 +0100198 put_indicator(irq_ptr->dsci);
Jan Glauber779e6e12008-07-17 17:16:48 +0200199}
200
Julian Wiedmann3050f022020-04-02 11:37:50 +0200201int __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
219void __exit qdio_thinint_exit(void)
Jan Glauber779e6e12008-07-17 17:16:48 +0200220{
Jan Glauber9e890ad2009-03-26 15:24:30 +0100221 WARN_ON(!list_empty(&tiq_list));
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200222 unregister_adapter_interrupt(&tiqdio_airq);
Julian Wiedmann3050f022020-04-02 11:37:50 +0200223 kfree(q_indicators);
Jan Glauber779e6e12008-07-17 17:16:48 +0200224}