2005-04-17 00:20:36 +02:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* rpa_vscsi.c
|
|
|
|
* (C) Copyright IBM Corporation 1994, 2003
|
|
|
|
* Authors: Colin DeVilbiss (devilbis@us.ibm.com)
|
|
|
|
* Santiago Leon (santil@us.ibm.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* RPA-specific functions of the SCSI host adapter for Virtual I/O devices
|
|
|
|
*
|
|
|
|
* This driver allows the Linux SCSI peripheral drivers to directly
|
|
|
|
* access devices in the hosting partition, either on an iSeries
|
|
|
|
* hypervisor system or a converged hypervisor system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/vio.h>
|
2005-08-17 08:41:44 +02:00
|
|
|
#include <asm/prom.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/iommu.h>
|
|
|
|
#include <asm/hvcall.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include "ibmvscsi.h"
|
2005-06-28 00:01:48 +02:00
|
|
|
|
|
|
|
static char partition_name[97] = "UNKNOWN";
|
|
|
|
static unsigned int partition_number = -1;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* Routines for managing the command/response queue
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* ibmvscsi_handle_event: - Interrupt handler for crq events
|
|
|
|
* @irq: number of irq to handle, not used
|
|
|
|
* @dev_instance: ibmvscsi_host_data of host that received interrupt
|
|
|
|
*
|
|
|
|
* Disables interrupts and schedules srp_task
|
|
|
|
* Always returns IRQ_HANDLED
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 15:55:46 +02:00
|
|
|
static irqreturn_t ibmvscsi_handle_event(int irq, void *dev_instance)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata =
|
|
|
|
(struct ibmvscsi_host_data *)dev_instance;
|
|
|
|
vio_disable_interrupts(to_vio_dev(hostdata->dev));
|
|
|
|
tasklet_schedule(&hostdata->srp_task);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* release_crq_queue: - Deallocates data and unregisters CRQ
|
|
|
|
* @queue: crq_queue to initialize and register
|
|
|
|
* @host_data: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
* Frees irq, deallocates a page for messages, unmaps dma, and unregisters
|
|
|
|
* the crq with the hypervisor.
|
|
|
|
*/
|
|
|
|
void ibmvscsi_release_crq_queue(struct crq_queue *queue,
|
|
|
|
struct ibmvscsi_host_data *hostdata,
|
|
|
|
int max_requests)
|
|
|
|
{
|
|
|
|
long rc;
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
free_irq(vdev->irq, (void *)hostdata);
|
|
|
|
tasklet_kill(&hostdata->srp_task);
|
|
|
|
do {
|
|
|
|
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
|
2006-03-30 14:49:40 +02:00
|
|
|
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
2005-04-17 00:20:36 +02:00
|
|
|
dma_unmap_single(hostdata->dev,
|
|
|
|
queue->msg_token,
|
|
|
|
queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
|
|
|
|
free_page((unsigned long)queue->msgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* crq_queue_next_crq: - Returns the next entry in message queue
|
|
|
|
* @queue: crq_queue to use
|
|
|
|
*
|
|
|
|
* Returns pointer to next entry in queue, or NULL if there are no new
|
|
|
|
* entried in the CRQ.
|
|
|
|
*/
|
|
|
|
static struct viosrp_crq *crq_queue_next_crq(struct crq_queue *queue)
|
|
|
|
{
|
|
|
|
struct viosrp_crq *crq;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&queue->lock, flags);
|
|
|
|
crq = &queue->msgs[queue->cur];
|
|
|
|
if (crq->valid & 0x80) {
|
|
|
|
if (++queue->cur == queue->size)
|
|
|
|
queue->cur = 0;
|
|
|
|
} else
|
|
|
|
crq = NULL;
|
|
|
|
spin_unlock_irqrestore(&queue->lock, flags);
|
|
|
|
|
|
|
|
return crq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_send_crq: - Send a CRQ
|
|
|
|
* @hostdata: the adapter
|
|
|
|
* @word1: the first 64 bits of the data
|
|
|
|
* @word2: the second 64 bits of the data
|
|
|
|
*/
|
|
|
|
int ibmvscsi_send_crq(struct ibmvscsi_host_data *hostdata, u64 word1, u64 word2)
|
|
|
|
{
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
|
|
|
|
return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, word1, word2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_task: - Process srps asynchronously
|
|
|
|
* @data: ibmvscsi_host_data of host
|
|
|
|
*/
|
|
|
|
static void ibmvscsi_task(void *data)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = (struct ibmvscsi_host_data *)data;
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
struct viosrp_crq *crq;
|
|
|
|
int done = 0;
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
/* Pull all the valid messages off the CRQ */
|
|
|
|
while ((crq = crq_queue_next_crq(&hostdata->queue)) != NULL) {
|
|
|
|
ibmvscsi_handle_crq(crq, hostdata);
|
|
|
|
crq->valid = 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
vio_enable_interrupts(vdev);
|
|
|
|
if ((crq = crq_queue_next_crq(&hostdata->queue)) != NULL) {
|
|
|
|
vio_disable_interrupts(vdev);
|
|
|
|
ibmvscsi_handle_crq(crq, hostdata);
|
|
|
|
crq->valid = 0x00;
|
|
|
|
} else {
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-28 00:01:48 +02:00
|
|
|
static void gather_partition_info(void)
|
|
|
|
{
|
|
|
|
struct device_node *rootdn;
|
|
|
|
|
2006-07-12 07:40:51 +02:00
|
|
|
const char *ppartition_name;
|
|
|
|
const unsigned int *p_number_ptr;
|
2005-06-28 00:01:48 +02:00
|
|
|
|
|
|
|
/* Retrieve information about this partition */
|
2007-04-24 05:50:55 +02:00
|
|
|
rootdn = of_find_node_by_path("/");
|
2005-06-28 00:01:48 +02:00
|
|
|
if (!rootdn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-01 05:54:02 +02:00
|
|
|
ppartition_name = of_get_property(rootdn, "ibm,partition-name", NULL);
|
2005-06-28 00:01:48 +02:00
|
|
|
if (ppartition_name)
|
|
|
|
strncpy(partition_name, ppartition_name,
|
|
|
|
sizeof(partition_name));
|
2007-05-01 05:54:02 +02:00
|
|
|
p_number_ptr = of_get_property(rootdn, "ibm,partition-no", NULL);
|
2005-06-28 00:01:48 +02:00
|
|
|
if (p_number_ptr)
|
|
|
|
partition_number = *p_number_ptr;
|
2007-04-24 05:50:55 +02:00
|
|
|
of_node_put(rootdn);
|
2005-06-28 00:01:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_adapter_info(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
memset(&hostdata->madapter_info, 0x00,
|
|
|
|
sizeof(hostdata->madapter_info));
|
|
|
|
|
|
|
|
printk(KERN_INFO "rpa_vscsi: SPR_VERSION: %s\n", SRP_VERSION);
|
|
|
|
strcpy(hostdata->madapter_info.srp_version, SRP_VERSION);
|
|
|
|
|
|
|
|
strncpy(hostdata->madapter_info.partition_name, partition_name,
|
|
|
|
sizeof(hostdata->madapter_info.partition_name));
|
|
|
|
|
|
|
|
hostdata->madapter_info.partition_number = partition_number;
|
|
|
|
|
|
|
|
hostdata->madapter_info.mad_version = 1;
|
|
|
|
hostdata->madapter_info.os_type = 2;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/**
|
|
|
|
* initialize_crq_queue: - Initializes and registers CRQ with hypervisor
|
|
|
|
* @queue: crq_queue to initialize and register
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
* Allocates a page for messages, maps it for dma, and registers
|
|
|
|
* the crq with the hypervisor.
|
|
|
|
* Returns zero on success.
|
|
|
|
*/
|
|
|
|
int ibmvscsi_init_crq_queue(struct crq_queue *queue,
|
|
|
|
struct ibmvscsi_host_data *hostdata,
|
|
|
|
int max_requests)
|
|
|
|
{
|
|
|
|
int rc;
|
2006-06-13 04:22:51 +02:00
|
|
|
int retrc;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
|
|
|
|
queue->msgs = (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!queue->msgs)
|
|
|
|
goto malloc_failed;
|
|
|
|
queue->size = PAGE_SIZE / sizeof(*queue->msgs);
|
|
|
|
|
|
|
|
queue->msg_token = dma_map_single(hostdata->dev, queue->msgs,
|
|
|
|
queue->size * sizeof(*queue->msgs),
|
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
|
|
|
|
if (dma_mapping_error(queue->msg_token))
|
|
|
|
goto map_failed;
|
|
|
|
|
2005-06-28 00:01:48 +02:00
|
|
|
gather_partition_info();
|
|
|
|
set_adapter_info(hostdata);
|
|
|
|
|
2006-06-13 04:22:51 +02:00
|
|
|
retrc = rc = plpar_hcall_norets(H_REG_CRQ,
|
2005-04-17 00:20:36 +02:00
|
|
|
vdev->unit_address,
|
|
|
|
queue->msg_token, PAGE_SIZE);
|
2006-03-30 14:49:40 +02:00
|
|
|
if (rc == H_RESOURCE)
|
2005-11-15 16:53:00 +01:00
|
|
|
/* maybe kexecing and resource is busy. try a reset */
|
|
|
|
rc = ibmvscsi_reset_crq_queue(queue,
|
|
|
|
hostdata);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (rc == 2) {
|
|
|
|
/* Adapter is good, but other end is not ready */
|
|
|
|
printk(KERN_WARNING "ibmvscsi: Partner adapter not ready\n");
|
2006-07-07 05:08:49 +02:00
|
|
|
retrc = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
} else if (rc != 0) {
|
|
|
|
printk(KERN_WARNING "ibmvscsi: Error %d opening adapter\n", rc);
|
|
|
|
goto reg_crq_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request_irq(vdev->irq,
|
|
|
|
ibmvscsi_handle_event,
|
|
|
|
0, "ibmvscsi", (void *)hostdata) != 0) {
|
|
|
|
printk(KERN_ERR "ibmvscsi: couldn't register irq 0x%x\n",
|
|
|
|
vdev->irq);
|
|
|
|
goto req_irq_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = vio_enable_interrupts(vdev);
|
|
|
|
if (rc != 0) {
|
|
|
|
printk(KERN_ERR "ibmvscsi: Error %d enabling interrupts!!!\n",
|
|
|
|
rc);
|
|
|
|
goto req_irq_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue->cur = 0;
|
|
|
|
spin_lock_init(&queue->lock);
|
|
|
|
|
|
|
|
tasklet_init(&hostdata->srp_task, (void *)ibmvscsi_task,
|
|
|
|
(unsigned long)hostdata);
|
|
|
|
|
2006-06-13 04:22:51 +02:00
|
|
|
return retrc;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
req_irq_failed:
|
|
|
|
do {
|
|
|
|
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
|
2006-03-30 14:49:40 +02:00
|
|
|
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
2005-04-17 00:20:36 +02:00
|
|
|
reg_crq_failed:
|
|
|
|
dma_unmap_single(hostdata->dev,
|
|
|
|
queue->msg_token,
|
|
|
|
queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
|
|
|
|
map_failed:
|
|
|
|
free_page((unsigned long)queue->msgs);
|
|
|
|
malloc_failed:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-01-19 20:34:44 +01:00
|
|
|
/**
|
|
|
|
* reenable_crq_queue: - reenables a crq after
|
|
|
|
* @queue: crq_queue to initialize and register
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int ibmvscsi_reenable_crq_queue(struct crq_queue *queue,
|
|
|
|
struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
|
|
|
|
/* Re-enable the CRQ */
|
|
|
|
do {
|
|
|
|
rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
|
2006-03-30 14:49:40 +02:00
|
|
|
} while ((rc == H_IN_PROGRESS) || (rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
2006-01-19 20:34:44 +01:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
printk(KERN_ERR "ibmvscsi: Error %d enabling adapter\n", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/**
|
|
|
|
* reset_crq_queue: - resets a crq after a failure
|
|
|
|
* @queue: crq_queue to initialize and register
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
*/
|
2005-11-15 16:53:00 +01:00
|
|
|
int ibmvscsi_reset_crq_queue(struct crq_queue *queue,
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
|
|
|
|
/* Close the CRQ */
|
|
|
|
do {
|
|
|
|
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
|
2006-03-30 14:49:40 +02:00
|
|
|
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Clean out the queue */
|
|
|
|
memset(queue->msgs, 0x00, PAGE_SIZE);
|
|
|
|
queue->cur = 0;
|
|
|
|
|
2005-06-28 00:01:48 +02:00
|
|
|
set_adapter_info(hostdata);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* And re-open it again */
|
|
|
|
rc = plpar_hcall_norets(H_REG_CRQ,
|
|
|
|
vdev->unit_address,
|
|
|
|
queue->msg_token, PAGE_SIZE);
|
|
|
|
if (rc == 2) {
|
|
|
|
/* Adapter is good, but other end is not ready */
|
|
|
|
printk(KERN_WARNING "ibmvscsi: Partner adapter not ready\n");
|
|
|
|
} else if (rc != 0) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"ibmvscsi: couldn't register crq--rc 0x%x\n", rc);
|
|
|
|
}
|
2005-11-15 16:53:00 +01:00
|
|
|
return rc;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|