Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 2 | * Support for adapter interruptions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999, 2007 |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 5 | * Author(s): Ingo Adlung <adlung@de.ibm.com> |
| 6 | * Cornelia Huck <cornelia.huck@de.ibm.com> |
| 7 | * Arnd Bergmann <arndb@de.ibm.com> |
| 8 | * Peter Oberparleiter <peter.oberparleiter@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/init.h> |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 12 | #include <linux/irq.h> |
| 13 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 15 | #include <linux/mutex.h> |
| 16 | #include <linux/rculist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 19 | #include <asm/airq.h> |
Cornelia Huck | da7c5af | 2008-07-14 09:58:59 +0200 | [diff] [blame] | 20 | #include <asm/isc.h> |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 21 | |
| 22 | #include "cio.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "cio_debug.h" |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 24 | #include "ioasm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 26 | static DEFINE_SPINLOCK(airq_lists_lock); |
| 27 | static struct hlist_head airq_lists[MAX_ISC+1]; |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 28 | |
| 29 | /** |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 30 | * register_adapter_interrupt() - register adapter interrupt handler |
| 31 | * @airq: pointer to adapter interrupt descriptor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 33 | * Returns 0 on success, or -EINVAL. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | */ |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 35 | int register_adapter_interrupt(struct airq_struct *airq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 37 | char dbf_txt[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 47 | if (!airq->lsi_mask) |
| 48 | airq->lsi_mask = 0xff; |
| 49 | snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%p", airq); |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 50 | CIO_TRACE_EVENT(4, dbf_txt); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 57 | EXPORT_SYMBOL(register_adapter_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 59 | /** |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 60 | * unregister_adapter_interrupt - unregister adapter interrupt handler |
| 61 | * @airq: pointer to adapter interrupt descriptor |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 62 | */ |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 63 | void unregister_adapter_interrupt(struct airq_struct *airq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 65 | char dbf_txt[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 67 | if (hlist_unhashed(&airq->list)) |
| 68 | return; |
| 69 | snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%p", airq); |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 70 | CIO_TRACE_EVENT(4, dbf_txt); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 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 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 82 | EXPORT_SYMBOL(unregister_adapter_interrupt); |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 83 | |
Cornelia Huck | da7c5af | 2008-07-14 09:58:59 +0200 | [diff] [blame] | 84 | void do_adapter_IO(u8 isc) |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 85 | { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 86 | struct airq_struct *airq; |
| 87 | struct hlist_head *head; |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 88 | |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 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(); |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 95 | } |