blob: 91edbd7ee80640d7d624280722843cbfb69093a8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +01002 * Support for adapter interruptions
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2007
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +01005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
11#include <linux/init.h>
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020012#include <linux/irq.h>
13#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020015#include <linux/mutex.h>
16#include <linux/rculist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010019#include <asm/airq.h>
Cornelia Huckda7c5af2008-07-14 09:58:59 +020020#include <asm/isc.h>
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010021
22#include "cio.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "cio_debug.h"
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020024#include "ioasm.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020026static DEFINE_SPINLOCK(airq_lists_lock);
27static struct hlist_head airq_lists[MAX_ISC+1];
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010028
29/**
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020030 * register_adapter_interrupt() - register adapter interrupt handler
31 * @airq: pointer to adapter interrupt descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 *
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020033 * Returns 0 on success, or -EINVAL.
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020035int register_adapter_interrupt(struct airq_struct *airq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020037 char dbf_txt[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020039 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 Torvalds1da177e2005-04-16 15:20:36 -070046 }
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020047 if (!airq->lsi_mask)
48 airq->lsi_mask = 0xff;
49 snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%p", airq);
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010050 CIO_TRACE_EVENT(4, dbf_txt);
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020051 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 Torvalds1da177e2005-04-16 15:20:36 -070056}
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020057EXPORT_SYMBOL(register_adapter_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010059/**
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020060 * unregister_adapter_interrupt - unregister adapter interrupt handler
61 * @airq: pointer to adapter interrupt descriptor
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010062 */
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020063void unregister_adapter_interrupt(struct airq_struct *airq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020065 char dbf_txt[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020067 if (hlist_unhashed(&airq->list))
68 return;
69 snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%p", airq);
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010070 CIO_TRACE_EVENT(4, dbf_txt);
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020071 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 Torvalds1da177e2005-04-16 15:20:36 -070081}
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020082EXPORT_SYMBOL(unregister_adapter_interrupt);
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010083
Cornelia Huckda7c5af2008-07-14 09:58:59 +020084void do_adapter_IO(u8 isc)
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010085{
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020086 struct airq_struct *airq;
87 struct hlist_head *head;
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010088
Martin Schwidefskyf4eae942013-06-24 10:30:41 +020089 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 Oberparleiter4e8e56c2008-01-26 14:10:44 +010095}