2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2008-01-26 06:10:44 -07:00
|
|
|
* Support for adapter interruptions
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2012-07-20 03:15:04 -06:00
|
|
|
* Copyright IBM Corp. 1999, 2007
|
2008-01-26 06:10:44 -07:00
|
|
|
* Author(s): Ingo Adlung <adlung@de.ibm.com>
|
|
|
|
* Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
|
|
* Arnd Bergmann <arndb@de.ibm.com>
|
|
|
|
* Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
2013-06-24 02:30:41 -06:00
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/module.h>
|
2013-06-24 02:30:41 -06:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/rculist.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/slab.h>
|
|
|
|
|
2008-01-26 06:10:44 -07:00
|
|
|
#include <asm/airq.h>
|
2008-07-14 01:58:59 -06:00
|
|
|
#include <asm/isc.h>
|
2008-01-26 06:10:44 -07:00
|
|
|
|
|
|
|
#include "cio.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "cio_debug.h"
|
2013-06-24 02:30:41 -06:00
|
|
|
#include "ioasm.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-06-24 02:30:41 -06:00
|
|
|
static DEFINE_SPINLOCK(airq_lists_lock);
|
|
|
|
static struct hlist_head airq_lists[MAX_ISC+1];
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-01-26 06:10:44 -07:00
|
|
|
/**
|
2013-06-24 02:30:41 -06:00
|
|
|
* register_adapter_interrupt() - register adapter interrupt handler
|
|
|
|
* @airq: pointer to adapter interrupt descriptor
|
2008-01-26 06:10:44 -07:00
|
|
|
*
|
2013-06-24 02:30:41 -06:00
|
|
|
* Returns 0 on success, or -EINVAL.
|
2008-01-26 06:10:44 -07:00
|
|
|
*/
|
2013-06-24 02:30:41 -06:00
|
|
|
int register_adapter_interrupt(struct airq_struct *airq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-06-24 02:30:41 -06:00
|
|
|
char dbf_txt[32];
|
|
|
|
|
|
|
|
if (!airq->handler || airq->isc > MAX_ISC)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!airq->lsi_ptr) {
|
|
|
|
airq->lsi_ptr = kzalloc(1, GFP_KERNEL);
|
|
|
|
if (!airq->lsi_ptr)
|
|
|
|
return -ENOMEM;
|
|
|
|
airq->flags |= AIRQ_PTR_ALLOCATED;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2013-06-24 02:30:41 -06:00
|
|
|
if (!airq->lsi_mask)
|
|
|
|
airq->lsi_mask = 0xff;
|
|
|
|
snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%p", airq);
|
2008-01-26 06:10:44 -07:00
|
|
|
CIO_TRACE_EVENT(4, dbf_txt);
|
2013-06-24 02:30:41 -06:00
|
|
|
isc_register(airq->isc);
|
|
|
|
spin_lock(&airq_lists_lock);
|
|
|
|
hlist_add_head_rcu(&airq->list, &airq_lists[airq->isc]);
|
|
|
|
spin_unlock(&airq_lists_lock);
|
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2013-06-24 02:30:41 -06:00
|
|
|
EXPORT_SYMBOL(register_adapter_interrupt);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-01-26 06:10:44 -07:00
|
|
|
/**
|
2013-06-24 02:30:41 -06:00
|
|
|
* unregister_adapter_interrupt - unregister adapter interrupt handler
|
|
|
|
* @airq: pointer to adapter interrupt descriptor
|
2008-01-26 06:10:44 -07:00
|
|
|
*/
|
2013-06-24 02:30:41 -06:00
|
|
|
void unregister_adapter_interrupt(struct airq_struct *airq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-06-24 02:30:41 -06:00
|
|
|
char dbf_txt[32];
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-06-24 02:30:41 -06:00
|
|
|
if (hlist_unhashed(&airq->list))
|
|
|
|
return;
|
|
|
|
snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%p", airq);
|
2008-01-26 06:10:44 -07:00
|
|
|
CIO_TRACE_EVENT(4, dbf_txt);
|
2013-06-24 02:30:41 -06:00
|
|
|
spin_lock(&airq_lists_lock);
|
|
|
|
hlist_del_rcu(&airq->list);
|
|
|
|
spin_unlock(&airq_lists_lock);
|
|
|
|
synchronize_rcu();
|
|
|
|
isc_unregister(airq->isc);
|
|
|
|
if (airq->flags & AIRQ_PTR_ALLOCATED) {
|
|
|
|
kfree(airq->lsi_ptr);
|
|
|
|
airq->lsi_ptr = NULL;
|
|
|
|
airq->flags &= ~AIRQ_PTR_ALLOCATED;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2013-06-24 02:30:41 -06:00
|
|
|
EXPORT_SYMBOL(unregister_adapter_interrupt);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-06-27 01:01:09 -06:00
|
|
|
static irqreturn_t do_airq_interrupt(int irq, void *dummy)
|
2008-01-26 06:10:44 -07:00
|
|
|
{
|
2013-06-27 01:01:09 -06:00
|
|
|
struct tpi_info *tpi_info;
|
2013-06-24 02:30:41 -06:00
|
|
|
struct airq_struct *airq;
|
|
|
|
struct hlist_head *head;
|
|
|
|
|
2013-06-27 01:01:09 -06:00
|
|
|
__this_cpu_write(s390_idle.nohz_delay, 1);
|
|
|
|
tpi_info = (struct tpi_info *) &get_irq_regs()->int_code;
|
|
|
|
head = &airq_lists[tpi_info->isc];
|
2013-06-24 02:30:41 -06:00
|
|
|
rcu_read_lock();
|
|
|
|
hlist_for_each_entry_rcu(airq, head, list)
|
|
|
|
if ((*airq->lsi_ptr & airq->lsi_mask) != 0)
|
|
|
|
airq->handler(airq);
|
|
|
|
rcu_read_unlock();
|
2013-06-27 01:01:09 -06:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irqaction airq_interrupt = {
|
|
|
|
.name = "AIO",
|
|
|
|
.handler = do_airq_interrupt,
|
|
|
|
};
|
|
|
|
|
|
|
|
void __init init_airq_interrupts(void)
|
|
|
|
{
|
|
|
|
irq_set_chip_and_handler(THIN_INTERRUPT,
|
|
|
|
&dummy_irq_chip, handle_percpu_irq);
|
|
|
|
setup_irq(THIN_INTERRUPT, &airq_interrupt);
|
2008-01-26 06:10:44 -07:00
|
|
|
}
|
2013-06-25 06:17:57 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* airq_iv_create - create an interrupt vector
|
|
|
|
* @bits: number of bits in the interrupt vector
|
|
|
|
* @flags: allocation flags
|
|
|
|
*
|
|
|
|
* Returns a pointer to an interrupt vector structure
|
|
|
|
*/
|
|
|
|
struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
|
|
|
|
{
|
|
|
|
struct airq_iv *iv;
|
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
iv = kzalloc(sizeof(*iv), GFP_KERNEL);
|
|
|
|
if (!iv)
|
|
|
|
goto out;
|
|
|
|
iv->bits = bits;
|
|
|
|
size = BITS_TO_LONGS(bits) * sizeof(unsigned long);
|
|
|
|
iv->vector = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!iv->vector)
|
|
|
|
goto out_free;
|
|
|
|
if (flags & AIRQ_IV_ALLOC) {
|
|
|
|
iv->avail = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!iv->avail)
|
|
|
|
goto out_free;
|
|
|
|
memset(iv->avail, 0xff, size);
|
|
|
|
iv->end = 0;
|
|
|
|
} else
|
|
|
|
iv->end = bits;
|
|
|
|
if (flags & AIRQ_IV_BITLOCK) {
|
|
|
|
iv->bitlock = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!iv->bitlock)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (flags & AIRQ_IV_PTR) {
|
|
|
|
size = bits * sizeof(unsigned long);
|
|
|
|
iv->ptr = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!iv->ptr)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (flags & AIRQ_IV_DATA) {
|
|
|
|
size = bits * sizeof(unsigned int);
|
|
|
|
iv->data = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!iv->data)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
spin_lock_init(&iv->lock);
|
|
|
|
return iv;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree(iv->ptr);
|
|
|
|
kfree(iv->bitlock);
|
|
|
|
kfree(iv->avail);
|
|
|
|
kfree(iv->vector);
|
|
|
|
kfree(iv);
|
|
|
|
out:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(airq_iv_create);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* airq_iv_release - release an interrupt vector
|
|
|
|
* @iv: pointer to interrupt vector structure
|
|
|
|
*/
|
|
|
|
void airq_iv_release(struct airq_iv *iv)
|
|
|
|
{
|
|
|
|
kfree(iv->data);
|
|
|
|
kfree(iv->ptr);
|
|
|
|
kfree(iv->bitlock);
|
|
|
|
kfree(iv->vector);
|
|
|
|
kfree(iv->avail);
|
|
|
|
kfree(iv);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(airq_iv_release);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* airq_iv_alloc_bit - allocate an irq bit from an interrupt vector
|
|
|
|
* @iv: pointer to an interrupt vector structure
|
|
|
|
*
|
|
|
|
* Returns the bit number of the allocated irq, or -1UL if no bit
|
|
|
|
* is available or the AIRQ_IV_ALLOC flag has not been specified
|
|
|
|
*/
|
|
|
|
unsigned long airq_iv_alloc_bit(struct airq_iv *iv)
|
|
|
|
{
|
|
|
|
unsigned long bit;
|
|
|
|
|
|
|
|
if (!iv->avail)
|
|
|
|
return -1UL;
|
|
|
|
spin_lock(&iv->lock);
|
2013-09-23 04:01:44 -06:00
|
|
|
bit = find_first_bit_inv(iv->avail, iv->bits);
|
2013-06-25 06:17:57 -06:00
|
|
|
if (bit < iv->bits) {
|
2013-09-23 04:01:44 -06:00
|
|
|
clear_bit_inv(bit, iv->avail);
|
2013-06-25 06:17:57 -06:00
|
|
|
if (bit >= iv->end)
|
|
|
|
iv->end = bit + 1;
|
|
|
|
} else
|
|
|
|
bit = -1UL;
|
|
|
|
spin_unlock(&iv->lock);
|
|
|
|
return bit;
|
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(airq_iv_alloc_bit);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* airq_iv_free_bit - free an irq bit of an interrupt vector
|
|
|
|
* @iv: pointer to interrupt vector structure
|
|
|
|
* @bit: number of the irq bit to free
|
|
|
|
*/
|
|
|
|
void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit)
|
|
|
|
{
|
|
|
|
if (!iv->avail)
|
|
|
|
return;
|
|
|
|
spin_lock(&iv->lock);
|
|
|
|
/* Clear (possibly left over) interrupt bit */
|
2013-09-23 04:01:44 -06:00
|
|
|
clear_bit_inv(bit, iv->vector);
|
2013-06-25 06:17:57 -06:00
|
|
|
/* Make the bit position available again */
|
2013-09-23 04:01:44 -06:00
|
|
|
set_bit_inv(bit, iv->avail);
|
2013-06-25 06:17:57 -06:00
|
|
|
if (bit == iv->end - 1) {
|
|
|
|
/* Find new end of bit-field */
|
|
|
|
while (--iv->end > 0)
|
2013-09-23 04:01:44 -06:00
|
|
|
if (!test_bit_inv(iv->end - 1, iv->avail))
|
2013-06-25 06:17:57 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock(&iv->lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(airq_iv_free_bit);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* airq_iv_scan - scan interrupt vector for non-zero bits
|
|
|
|
* @iv: pointer to interrupt vector structure
|
|
|
|
* @start: bit number to start the search
|
|
|
|
* @end: bit number to end the search
|
|
|
|
*
|
|
|
|
* Returns the bit number of the next non-zero interrupt bit, or
|
|
|
|
* -1UL if the scan completed without finding any more any non-zero bits.
|
|
|
|
*/
|
|
|
|
unsigned long airq_iv_scan(struct airq_iv *iv, unsigned long start,
|
|
|
|
unsigned long end)
|
|
|
|
{
|
|
|
|
unsigned long bit;
|
|
|
|
|
|
|
|
/* Find non-zero bit starting from 'ivs->next'. */
|
2013-09-23 04:01:44 -06:00
|
|
|
bit = find_next_bit_inv(iv->vector, end, start);
|
2013-06-25 06:17:57 -06:00
|
|
|
if (bit >= end)
|
|
|
|
return -1UL;
|
2013-09-23 04:01:44 -06:00
|
|
|
clear_bit_inv(bit, iv->vector);
|
2013-06-25 06:17:57 -06:00
|
|
|
return bit;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(airq_iv_scan);
|