Skip to content

Commit f4eae94

Browse files
author
Martin Schwidefsky
committed
s390/airq: simplify adapter interrupt code
There are three users of adapter interrupts: AP, QDIO and PCI. Each registers a single adapter interrupt with independent ISCs. Define a "struct airq" with the interrupt handler, a pointer and a mask for the local summary indicator and the ISC for the adapter interrupt source. Convert the indicator array with its fixed number of adapter interrupt sources per ISE to an array of hlists. This removes the limitation to 32 adapter interrupts per ISC and allows for arbitrary memory locations for the local summary indicator. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 386aa05 commit f4eae94

5 files changed

Lines changed: 132 additions & 170 deletions

File tree

‎arch/s390/include/asm/airq.h‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@
99
#ifndef _ASM_S390_AIRQ_H
1010
#define _ASM_S390_AIRQ_H
1111

12-
typedef void (*adapter_int_handler_t)(void *, void *);
12+
struct airq_struct {
13+
struct hlist_node list; /* Handler queueing. */
14+
void (*handler)(struct airq_struct *); /* Thin-interrupt handler */
15+
u8 *lsi_ptr; /* Local-Summary-Indicator pointer */
16+
u8 lsi_mask; /* Local-Summary-Indicator mask */
17+
u8 isc; /* Interrupt-subclass */
18+
u8 flags;
19+
};
1320

14-
void *s390_register_adapter_interrupt(adapter_int_handler_t, void *, u8);
15-
void s390_unregister_adapter_interrupt(void *, u8);
21+
#define AIRQ_PTR_ALLOCATED 0x01
22+
23+
int register_adapter_interrupt(struct airq_struct *airq);
24+
void unregister_adapter_interrupt(struct airq_struct *airq);
1625

1726
#endif /* _ASM_S390_AIRQ_H */

‎arch/s390/pci/pci.c‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ struct intr_bucket {
8282

8383
static struct intr_bucket *bucket;
8484

85-
/* Adapter local summary indicator */
86-
static u8 *zpci_irq_si;
85+
/* Adapter interrupt definitions */
86+
static void zpci_irq_handler(struct airq_struct *airq);
87+
88+
static struct airq_struct zpci_airq = {
89+
.handler = zpci_irq_handler,
90+
.isc = PCI_ISC,
91+
};
8792

8893
/* I/O Map */
8994
static DEFINE_SPINLOCK(zpci_iomap_lock);
@@ -402,7 +407,7 @@ static struct pci_ops pci_root_ops = {
402407
/* store the last handled bit to implement fair scheduling of devices */
403408
static DEFINE_PER_CPU(unsigned long, next_sbit);
404409

405-
static void zpci_irq_handler(void *dont, void *need)
410+
static void zpci_irq_handler(struct airq_struct *airq)
406411
{
407412
unsigned long sbit, mbit, last = 0, start = __get_cpu_var(next_sbit);
408413
int rescan = 0, max = aisb_max;
@@ -712,25 +717,20 @@ static int __init zpci_irq_init(void)
712717
goto out_alloc;
713718
}
714719

715-
isc_register(PCI_ISC);
716-
zpci_irq_si = s390_register_adapter_interrupt(&zpci_irq_handler, NULL, PCI_ISC);
717-
if (IS_ERR(zpci_irq_si)) {
718-
rc = PTR_ERR(zpci_irq_si);
719-
zpci_irq_si = NULL;
720+
rc = register_adapter_interrupt(&zpci_airq);
721+
if (rc)
720722
goto out_ai;
721-
}
723+
/* Set summary to 1 to be called every time for the ISC. */
724+
*zpci_airq.lsi_ptr = 1;
722725

723726
for_each_online_cpu(cpu)
724727
per_cpu(next_sbit, cpu) = 0;
725728

726729
spin_lock_init(&bucket->lock);
727-
/* set summary to 1 to be called every time for the ISC */
728-
*zpci_irq_si = 1;
729730
set_irq_ctrl(SIC_IRQ_MODE_SINGLE, NULL, PCI_ISC);
730731
return 0;
731732

732733
out_ai:
733-
isc_unregister(PCI_ISC);
734734
free_page((unsigned long) bucket->alloc);
735735
out_alloc:
736736
free_page((unsigned long) bucket->aisb);
@@ -743,8 +743,7 @@ static void zpci_irq_exit(void)
743743
{
744744
free_page((unsigned long) bucket->alloc);
745745
free_page((unsigned long) bucket->aisb);
746-
s390_unregister_adapter_interrupt(zpci_irq_si, PCI_ISC);
747-
isc_unregister(PCI_ISC);
746+
unregister_adapter_interrupt(&zpci_airq);
748747
kfree(bucket);
749748
}
750749

‎drivers/s390/cio/airq.c‎

Lines changed: 56 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -9,142 +9,87 @@
99
*/
1010

1111
#include <linux/init.h>
12+
#include <linux/irq.h>
13+
#include <linux/kernel_stat.h>
1214
#include <linux/module.h>
15+
#include <linux/mutex.h>
16+
#include <linux/rculist.h>
1317
#include <linux/slab.h>
14-
#include <linux/rcupdate.h>
1518

1619
#include <asm/airq.h>
1720
#include <asm/isc.h>
1821

1922
#include "cio.h"
2023
#include "cio_debug.h"
24+
#include "ioasm.h"
2125

22-
#define NR_AIRQS 32
23-
#define NR_AIRQS_PER_WORD sizeof(unsigned long)
24-
#define NR_AIRQ_WORDS (NR_AIRQS / NR_AIRQS_PER_WORD)
25-
26-
union indicator_t {
27-
unsigned long word[NR_AIRQ_WORDS];
28-
unsigned char byte[NR_AIRQS];
29-
} __attribute__((packed));
30-
31-
struct airq_t {
32-
adapter_int_handler_t handler;
33-
void *drv_data;
34-
};
35-
36-
static union indicator_t indicators[MAX_ISC+1];
37-
static struct airq_t *airqs[MAX_ISC+1][NR_AIRQS];
38-
39-
static int register_airq(struct airq_t *airq, u8 isc)
40-
{
41-
int i;
42-
43-
for (i = 0; i < NR_AIRQS; i++)
44-
if (!cmpxchg(&airqs[isc][i], NULL, airq))
45-
return i;
46-
return -ENOMEM;
47-
}
26+
static DEFINE_SPINLOCK(airq_lists_lock);
27+
static struct hlist_head airq_lists[MAX_ISC+1];
4828

4929
/**
50-
* s390_register_adapter_interrupt() - register adapter interrupt handler
51-
* @handler: adapter handler to be registered
52-
* @drv_data: driver data passed with each call to the handler
53-
* @isc: isc for which the handler should be called
30+
* register_adapter_interrupt() - register adapter interrupt handler
31+
* @airq: pointer to adapter interrupt descriptor
5432
*
55-
* Returns:
56-
* Pointer to the indicator to be used on success
57-
* ERR_PTR() if registration failed
33+
* Returns 0 on success, or -EINVAL.
5834
*/
59-
void *s390_register_adapter_interrupt(adapter_int_handler_t handler,
60-
void *drv_data, u8 isc)
35+
int register_adapter_interrupt(struct airq_struct *airq)
6136
{
62-
struct airq_t *airq;
63-
char dbf_txt[16];
64-
int ret;
65-
66-
if (isc > MAX_ISC)
67-
return ERR_PTR(-EINVAL);
68-
airq = kmalloc(sizeof(struct airq_t), GFP_KERNEL);
69-
if (!airq) {
70-
ret = -ENOMEM;
71-
goto out;
37+
char dbf_txt[32];
38+
39+
if (!airq->handler || airq->isc > MAX_ISC)
40+
return -EINVAL;
41+
if (!airq->lsi_ptr) {
42+
airq->lsi_ptr = kzalloc(1, GFP_KERNEL);
43+
if (!airq->lsi_ptr)
44+
return -ENOMEM;
45+
airq->flags |= AIRQ_PTR_ALLOCATED;
7246
}
73-
airq->handler = handler;
74-
airq->drv_data = drv_data;
75-
76-
ret = register_airq(airq, isc);
77-
out:
78-
snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%d", ret);
47+
if (!airq->lsi_mask)
48+
airq->lsi_mask = 0xff;
49+
snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%p", airq);
7950
CIO_TRACE_EVENT(4, dbf_txt);
80-
if (ret < 0) {
81-
kfree(airq);
82-
return ERR_PTR(ret);
83-
} else
84-
return &indicators[isc].byte[ret];
51+
isc_register(airq->isc);
52+
spin_lock(&airq_lists_lock);
53+
hlist_add_head_rcu(&airq->list, &airq_lists[airq->isc]);
54+
spin_unlock(&airq_lists_lock);
55+
return 0;
8556
}
86-
EXPORT_SYMBOL(s390_register_adapter_interrupt);
57+
EXPORT_SYMBOL(register_adapter_interrupt);
8758

8859
/**
89-
* s390_unregister_adapter_interrupt - unregister adapter interrupt handler
90-
* @ind: indicator for which the handler is to be unregistered
91-
* @isc: interruption subclass
60+
* unregister_adapter_interrupt - unregister adapter interrupt handler
61+
* @airq: pointer to adapter interrupt descriptor
9262
*/
93-
void s390_unregister_adapter_interrupt(void *ind, u8 isc)
63+
void unregister_adapter_interrupt(struct airq_struct *airq)
9464
{
95-
struct airq_t *airq;
96-
char dbf_txt[16];
97-
int i;
65+
char dbf_txt[32];
9866

99-
i = (int) ((addr_t) ind) - ((addr_t) &indicators[isc].byte[0]);
100-
snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%d", i);
67+
if (hlist_unhashed(&airq->list))
68+
return;
69+
snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%p", airq);
10170
CIO_TRACE_EVENT(4, dbf_txt);
102-
indicators[isc].byte[i] = 0;
103-
airq = xchg(&airqs[isc][i], NULL);
104-
/*
105-
* Allow interrupts to complete. This will ensure that the airq handle
106-
* is no longer referenced by any interrupt handler.
107-
*/
108-
synchronize_sched();
109-
kfree(airq);
71+
spin_lock(&airq_lists_lock);
72+
hlist_del_rcu(&airq->list);
73+
spin_unlock(&airq_lists_lock);
74+
synchronize_rcu();
75+
isc_unregister(airq->isc);
76+
if (airq->flags & AIRQ_PTR_ALLOCATED) {
77+
kfree(airq->lsi_ptr);
78+
airq->lsi_ptr = NULL;
79+
airq->flags &= ~AIRQ_PTR_ALLOCATED;
80+
}
11081
}
111-
EXPORT_SYMBOL(s390_unregister_adapter_interrupt);
112-
113-
#define INDICATOR_MASK (0xffUL << ((NR_AIRQS_PER_WORD - 1) * 8))
82+
EXPORT_SYMBOL(unregister_adapter_interrupt);
11483

11584
void do_adapter_IO(u8 isc)
11685
{
117-
int w;
118-
int i;
119-
unsigned long word;
120-
struct airq_t *airq;
121-
122-
/*
123-
* Access indicator array in word-sized chunks to minimize storage
124-
* fetch operations.
125-
*/
126-
for (w = 0; w < NR_AIRQ_WORDS; w++) {
127-
word = indicators[isc].word[w];
128-
i = w * NR_AIRQS_PER_WORD;
129-
/*
130-
* Check bytes within word for active indicators.
131-
*/
132-
while (word) {
133-
if (word & INDICATOR_MASK) {
134-
airq = airqs[isc][i];
135-
/* Make sure gcc reads from airqs only once. */
136-
barrier();
137-
if (likely(airq))
138-
airq->handler(&indicators[isc].byte[i],
139-
airq->drv_data);
140-
else
141-
/*
142-
* Reset ill-behaved indicator.
143-
*/
144-
indicators[isc].byte[i] = 0;
145-
}
146-
word <<= 8;
147-
i++;
148-
}
149-
}
86+
struct airq_struct *airq;
87+
struct hlist_head *head;
88+
89+
head = &airq_lists[isc];
90+
rcu_read_lock();
91+
hlist_for_each_entry_rcu(airq, head, list)
92+
if ((*airq->lsi_ptr & airq->lsi_mask) != 0)
93+
airq->handler(airq);
94+
rcu_read_unlock();
15095
}

‎drivers/s390/cio/qdio_thinint.c‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ struct indicator_t {
3636
static LIST_HEAD(tiq_list);
3737
static DEFINE_MUTEX(tiq_list_lock);
3838

39-
/* adapter local summary indicator */
40-
static u8 *tiqdio_alsi;
39+
/* Adapter interrupt definitions */
40+
static void tiqdio_thinint_handler(struct airq_struct *airq);
41+
42+
static struct airq_struct tiqdio_airq = {
43+
.handler = tiqdio_thinint_handler,
44+
.isc = QDIO_AIRQ_ISC,
45+
};
4146

4247
static struct indicator_t *q_indicators;
4348

@@ -176,7 +181,7 @@ static inline void tiqdio_call_inq_handlers(struct qdio_irq *irq)
176181
* @alsi: pointer to adapter local summary indicator
177182
* @data: NULL
178183
*/
179-
static void tiqdio_thinint_handler(void *alsi, void *data)
184+
static void tiqdio_thinint_handler(struct airq_struct *airq)
180185
{
181186
u32 si_used = clear_shared_ind();
182187
struct qdio_q *q;
@@ -216,7 +221,7 @@ static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
216221
summary_indicator_addr = 0;
217222
subchannel_indicator_addr = 0;
218223
} else {
219-
summary_indicator_addr = virt_to_phys(tiqdio_alsi);
224+
summary_indicator_addr = virt_to_phys(tiqdio_airq.lsi_ptr);
220225
subchannel_indicator_addr = virt_to_phys(irq_ptr->dsci);
221226
}
222227

@@ -252,14 +257,12 @@ void tiqdio_free_memory(void)
252257

253258
int __init tiqdio_register_thinints(void)
254259
{
255-
isc_register(QDIO_AIRQ_ISC);
256-
tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
257-
NULL, QDIO_AIRQ_ISC);
258-
if (IS_ERR(tiqdio_alsi)) {
259-
DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
260-
tiqdio_alsi = NULL;
261-
isc_unregister(QDIO_AIRQ_ISC);
262-
return -ENOMEM;
260+
int rc;
261+
262+
rc = register_adapter_interrupt(&tiqdio_airq);
263+
if (rc) {
264+
DBF_EVENT("RTI:%x", rc);
265+
return rc;
263266
}
264267
return 0;
265268
}
@@ -292,9 +295,5 @@ void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
292295
void __exit tiqdio_unregister_thinints(void)
293296
{
294297
WARN_ON(!list_empty(&tiq_list));
295-
296-
if (tiqdio_alsi) {
297-
s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
298-
isc_unregister(QDIO_AIRQ_ISC);
299-
}
298+
unregister_adapter_interrupt(&tiqdio_airq);
300299
}

0 commit comments

Comments
 (0)