2005-04-17 06:20:36 +08:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* ibmvscsi.c
|
|
|
|
* (C) Copyright IBM Corporation 1994, 2004
|
|
|
|
* Authors: Colin DeVilbiss (devilbis@us.ibm.com)
|
|
|
|
* Santiago Leon (santil@us.ibm.com)
|
|
|
|
* Dave Boutcher (sleddog@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
|
|
|
|
*
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* Emulation of a SCSI host adapter for Virtual I/O devices
|
|
|
|
*
|
|
|
|
* This driver supports the SCSI adapter implemented by the IBM
|
|
|
|
* Power5 firmware. That SCSI adapter is not a physical adapter,
|
|
|
|
* but allows Linux SCSI peripheral drivers to directly
|
|
|
|
* access devices in another logical partition on the physical system.
|
|
|
|
*
|
|
|
|
* The virtual adapter(s) are present in the open firmware device
|
|
|
|
* tree just like real adapters.
|
|
|
|
*
|
|
|
|
* One of the capabilities provided on these systems is the ability
|
|
|
|
* to DMA between partitions. The architecture states that for VSCSI,
|
|
|
|
* the server side is allowed to DMA to and from the client. The client
|
|
|
|
* is never trusted to DMA to or from the server directly.
|
|
|
|
*
|
|
|
|
* Messages are sent between partitions on a "Command/Response Queue"
|
|
|
|
* (CRQ), which is just a buffer of 16 byte entries in the receiver's
|
|
|
|
* Senders cannot access the buffer directly, but send messages by
|
|
|
|
* making a hypervisor call and passing in the 16 bytes. The hypervisor
|
2009-12-05 03:43:37 +08:00
|
|
|
* puts the message in the next 16 byte space in round-robin fashion,
|
2005-04-17 06:20:36 +08:00
|
|
|
* turns on the high order bit of the message (the valid bit), and
|
|
|
|
* generates an interrupt to the receiver (if interrupts are turned on.)
|
|
|
|
* The receiver just turns off the valid bit when they have copied out
|
|
|
|
* the message.
|
|
|
|
*
|
|
|
|
* The VSCSI client builds a SCSI Remote Protocol (SRP) Information Unit
|
|
|
|
* (IU) (as defined in the T10 standard available at www.t10.org), gets
|
|
|
|
* a DMA address for the message, and sends it to the server as the
|
|
|
|
* payload of a CRQ message. The server DMAs the SRP IU and processes it,
|
|
|
|
* including doing any additional data transfers. When it is done, it
|
|
|
|
* DMAs the SRP response back to the same address as the request came from,
|
|
|
|
* and sends a CRQ message back to inform the client that the request has
|
|
|
|
* completed.
|
|
|
|
*
|
2012-03-08 02:35:38 +08:00
|
|
|
* TODO: This is currently pretty tied to the IBM pSeries hypervisor
|
2005-04-17 06:20:36 +08:00
|
|
|
* interfaces. It would be really nice to abstract this above an RDMA
|
|
|
|
* layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-06-09 05:19:08 +08:00
|
|
|
#include <linux/of.h>
|
2010-02-22 00:37:57 +08:00
|
|
|
#include <linux/pm.h>
|
2010-06-18 02:56:00 +08:00
|
|
|
#include <linux/kthread.h>
|
2007-09-22 06:29:36 +08:00
|
|
|
#include <asm/firmware.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/vio.h>
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
2007-06-27 15:32:50 +08:00
|
|
|
#include <scsi/scsi_transport_srp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "ibmvscsi.h"
|
|
|
|
|
|
|
|
/* The values below are somewhat arbitrary default values, but
|
|
|
|
* OS/400 will use 3 busses (disks, CDs, tapes, I think.)
|
|
|
|
* Note that there are 3 bits of channel value, 6 bits of id, and
|
|
|
|
* 5 bits of LUN.
|
|
|
|
*/
|
|
|
|
static int max_id = 64;
|
|
|
|
static int max_channel = 3;
|
2009-06-09 05:19:03 +08:00
|
|
|
static int init_timeout = 300;
|
|
|
|
static int login_timeout = 60;
|
|
|
|
static int info_timeout = 30;
|
|
|
|
static int abort_timeout = 60;
|
|
|
|
static int reset_timeout = 60;
|
2007-03-29 01:45:46 +08:00
|
|
|
static int max_requests = IBMVSCSI_MAX_REQUESTS_DEFAULT;
|
2008-12-18 07:19:33 +08:00
|
|
|
static int max_events = IBMVSCSI_MAX_REQUESTS_DEFAULT + 2;
|
2009-06-09 05:19:07 +08:00
|
|
|
static int fast_fail = 1;
|
2009-06-09 05:19:08 +08:00
|
|
|
static int client_reserve = 1;
|
2012-07-30 09:32:26 +08:00
|
|
|
static char partition_name[97] = "UNKNOWN";
|
|
|
|
static unsigned int partition_number = -1;
|
2016-12-08 06:04:35 +08:00
|
|
|
static LIST_HEAD(ibmvscsi_head);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-06-27 15:32:50 +08:00
|
|
|
static struct scsi_transport_template *ibmvscsi_transport_template;
|
|
|
|
|
2010-06-18 02:56:04 +08:00
|
|
|
#define IBMVSCSI_VERSION "1.5.9"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("IBM Virtual SCSI");
|
|
|
|
MODULE_AUTHOR("Dave Boutcher");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(IBMVSCSI_VERSION);
|
|
|
|
|
|
|
|
module_param_named(max_id, max_id, int, S_IRUGO | S_IWUSR);
|
2015-11-10 00:49:08 +08:00
|
|
|
MODULE_PARM_DESC(max_id, "Largest ID value for each channel [Default=64]");
|
2005-04-17 06:20:36 +08:00
|
|
|
module_param_named(max_channel, max_channel, int, S_IRUGO | S_IWUSR);
|
2015-11-10 00:49:08 +08:00
|
|
|
MODULE_PARM_DESC(max_channel, "Largest channel value [Default=3]");
|
2005-04-17 06:20:36 +08:00
|
|
|
module_param_named(init_timeout, init_timeout, int, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(init_timeout, "Initialization timeout in seconds");
|
2008-12-09 07:01:47 +08:00
|
|
|
module_param_named(max_requests, max_requests, int, S_IRUGO);
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_PARM_DESC(max_requests, "Maximum requests for this adapter");
|
2009-06-09 05:19:07 +08:00
|
|
|
module_param_named(fast_fail, fast_fail, int, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(fast_fail, "Enable fast fail. [Default=1]");
|
2009-06-09 05:19:08 +08:00
|
|
|
module_param_named(client_reserve, client_reserve, int, S_IRUGO );
|
|
|
|
MODULE_PARM_DESC(client_reserve, "Attempt client managed reserve/release");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-07-30 09:32:26 +08:00
|
|
|
static void ibmvscsi_handle_crq(struct viosrp_crq *crq,
|
|
|
|
struct ibmvscsi_host_data *hostdata);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
static irqreturn_t ibmvscsi_handle_event(int irq, void *dev_instance)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static void ibmvscsi_release_crq_queue(struct crq_queue *queue,
|
|
|
|
struct ibmvscsi_host_data *hostdata,
|
|
|
|
int max_requests)
|
|
|
|
{
|
|
|
|
long rc = 0;
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
free_irq(vdev->irq, (void *)hostdata);
|
|
|
|
tasklet_kill(&hostdata->srp_task);
|
|
|
|
do {
|
|
|
|
if (rc)
|
|
|
|
msleep(100);
|
|
|
|
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
|
|
|
|
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
|
|
|
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];
|
2016-02-11 09:32:23 +08:00
|
|
|
if (crq->valid != VIOSRP_CRQ_FREE) {
|
2012-07-30 09:32:26 +08:00
|
|
|
if (++queue->cur == queue->size)
|
|
|
|
queue->cur = 0;
|
2014-05-23 23:52:11 +08:00
|
|
|
|
|
|
|
/* Ensure the read of the valid bit occurs before reading any
|
|
|
|
* other bits of the CRQ entry
|
|
|
|
*/
|
|
|
|
rmb();
|
2012-07-30 09:32:26 +08:00
|
|
|
} 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
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_send_crq(struct ibmvscsi_host_data *hostdata,
|
|
|
|
u64 word1, u64 word2)
|
|
|
|
{
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
|
2014-05-23 23:52:11 +08:00
|
|
|
/*
|
|
|
|
* Ensure the command buffer is flushed to memory before handing it
|
|
|
|
* over to the VIOS to prevent it from fetching any stale data.
|
|
|
|
*/
|
|
|
|
mb();
|
2012-07-30 09:32:26 +08:00
|
|
|
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);
|
2016-02-11 09:32:23 +08:00
|
|
|
crq->valid = VIOSRP_CRQ_FREE;
|
2016-12-08 07:31:26 +08:00
|
|
|
wmb();
|
2012-07-30 09:32:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
vio_enable_interrupts(vdev);
|
|
|
|
crq = crq_queue_next_crq(&hostdata->queue);
|
|
|
|
if (crq != NULL) {
|
|
|
|
vio_disable_interrupts(vdev);
|
|
|
|
ibmvscsi_handle_crq(crq, hostdata);
|
2016-02-11 09:32:23 +08:00
|
|
|
crq->valid = VIOSRP_CRQ_FREE;
|
2016-12-08 07:31:26 +08:00
|
|
|
wmb();
|
2012-07-30 09:32:26 +08:00
|
|
|
} else {
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gather_partition_info(void)
|
|
|
|
{
|
|
|
|
const char *ppartition_name;
|
2013-09-03 08:04:47 +08:00
|
|
|
const __be32 *p_number_ptr;
|
2012-07-30 09:32:26 +08:00
|
|
|
|
|
|
|
/* Retrieve information about this partition */
|
2016-02-11 09:32:25 +08:00
|
|
|
if (!of_root)
|
2012-07-30 09:32:26 +08:00
|
|
|
return;
|
|
|
|
|
2016-02-11 09:32:25 +08:00
|
|
|
of_node_get(of_root);
|
|
|
|
|
|
|
|
ppartition_name = of_get_property(of_root, "ibm,partition-name", NULL);
|
2012-07-30 09:32:26 +08:00
|
|
|
if (ppartition_name)
|
|
|
|
strncpy(partition_name, ppartition_name,
|
|
|
|
sizeof(partition_name));
|
2016-02-11 09:32:25 +08:00
|
|
|
p_number_ptr = of_get_property(of_root, "ibm,partition-no", NULL);
|
2012-07-30 09:32:26 +08:00
|
|
|
if (p_number_ptr)
|
2013-09-03 08:04:47 +08:00
|
|
|
partition_number = of_read_number(p_number_ptr, 1);
|
2016-02-11 09:32:25 +08:00
|
|
|
of_node_put(of_root);
|
2012-07-30 09:32:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_adapter_info(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
memset(&hostdata->madapter_info, 0x00,
|
|
|
|
sizeof(hostdata->madapter_info));
|
|
|
|
|
|
|
|
dev_info(hostdata->dev, "SRP_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));
|
|
|
|
|
2013-09-03 08:04:47 +08:00
|
|
|
hostdata->madapter_info.partition_number =
|
|
|
|
cpu_to_be32(partition_number);
|
2012-07-30 09:32:26 +08:00
|
|
|
|
2016-02-11 09:32:24 +08:00
|
|
|
hostdata->madapter_info.mad_version = cpu_to_be32(SRP_MAD_VERSION_1);
|
|
|
|
hostdata->madapter_info.os_type = cpu_to_be32(SRP_MAD_OS_LINUX);
|
2012-07-30 09:32:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* reset_crq_queue: - resets a crq after a failure
|
|
|
|
* @queue: crq_queue to initialize and register
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_reset_crq_queue(struct crq_queue *queue,
|
|
|
|
struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
|
|
|
|
/* Close the CRQ */
|
|
|
|
do {
|
|
|
|
if (rc)
|
|
|
|
msleep(100);
|
|
|
|
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
|
|
|
|
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
|
|
|
|
|
|
|
/* Clean out the queue */
|
|
|
|
memset(queue->msgs, 0x00, PAGE_SIZE);
|
|
|
|
queue->cur = 0;
|
|
|
|
|
|
|
|
set_adapter_info(hostdata);
|
|
|
|
|
|
|
|
/* And re-open it again */
|
|
|
|
rc = plpar_hcall_norets(H_REG_CRQ,
|
|
|
|
vdev->unit_address,
|
|
|
|
queue->msg_token, PAGE_SIZE);
|
2016-02-11 09:32:28 +08:00
|
|
|
if (rc == H_CLOSED) {
|
2012-07-30 09:32:26 +08:00
|
|
|
/* Adapter is good, but other end is not ready */
|
|
|
|
dev_warn(hostdata->dev, "Partner adapter not ready\n");
|
|
|
|
} else if (rc != 0) {
|
|
|
|
dev_warn(hostdata->dev, "couldn't register crq--rc 0x%x\n", rc);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_init_crq_queue(struct crq_queue *queue,
|
|
|
|
struct ibmvscsi_host_data *hostdata,
|
|
|
|
int max_requests)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int retrc;
|
|
|
|
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(hostdata->dev, queue->msg_token))
|
|
|
|
goto map_failed;
|
|
|
|
|
|
|
|
gather_partition_info();
|
|
|
|
set_adapter_info(hostdata);
|
|
|
|
|
|
|
|
retrc = rc = plpar_hcall_norets(H_REG_CRQ,
|
|
|
|
vdev->unit_address,
|
|
|
|
queue->msg_token, PAGE_SIZE);
|
|
|
|
if (rc == H_RESOURCE)
|
|
|
|
/* maybe kexecing and resource is busy. try a reset */
|
|
|
|
rc = ibmvscsi_reset_crq_queue(queue,
|
|
|
|
hostdata);
|
|
|
|
|
2016-02-11 09:32:28 +08:00
|
|
|
if (rc == H_CLOSED) {
|
2012-07-30 09:32:26 +08:00
|
|
|
/* Adapter is good, but other end is not ready */
|
|
|
|
dev_warn(hostdata->dev, "Partner adapter not ready\n");
|
|
|
|
retrc = 0;
|
|
|
|
} else if (rc != 0) {
|
|
|
|
dev_warn(hostdata->dev, "Error %d opening adapter\n", rc);
|
|
|
|
goto reg_crq_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue->cur = 0;
|
|
|
|
spin_lock_init(&queue->lock);
|
|
|
|
|
|
|
|
tasklet_init(&hostdata->srp_task, (void *)ibmvscsi_task,
|
|
|
|
(unsigned long)hostdata);
|
|
|
|
|
|
|
|
if (request_irq(vdev->irq,
|
|
|
|
ibmvscsi_handle_event,
|
|
|
|
0, "ibmvscsi", (void *)hostdata) != 0) {
|
|
|
|
dev_err(hostdata->dev, "couldn't register irq 0x%x\n",
|
|
|
|
vdev->irq);
|
|
|
|
goto req_irq_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = vio_enable_interrupts(vdev);
|
|
|
|
if (rc != 0) {
|
|
|
|
dev_err(hostdata->dev, "Error %d enabling interrupts!!!\n", rc);
|
|
|
|
goto req_irq_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retrc;
|
|
|
|
|
|
|
|
req_irq_failed:
|
|
|
|
tasklet_kill(&hostdata->srp_task);
|
|
|
|
rc = 0;
|
|
|
|
do {
|
|
|
|
if (rc)
|
|
|
|
msleep(100);
|
|
|
|
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
|
|
|
|
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* reenable_crq_queue: - reenables a crq after
|
|
|
|
* @queue: crq_queue to initialize and register
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_reenable_crq_queue(struct crq_queue *queue,
|
|
|
|
struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
struct vio_dev *vdev = to_vio_dev(hostdata->dev);
|
|
|
|
|
|
|
|
/* Re-enable the CRQ */
|
|
|
|
do {
|
|
|
|
if (rc)
|
|
|
|
msleep(100);
|
|
|
|
rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
|
|
|
|
} while ((rc == H_IN_PROGRESS) || (rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
dev_err(hostdata->dev, "Error %d enabling adapter\n", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* Routines for the event pool and event structs
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* initialize_event_pool: - Allocates and initializes the event pool for a host
|
|
|
|
* @pool: event_pool to be initialized
|
|
|
|
* @size: Number of events in pool
|
|
|
|
* @hostdata: ibmvscsi_host_data who owns the event pool
|
|
|
|
*
|
|
|
|
* Returns zero on success.
|
|
|
|
*/
|
|
|
|
static int initialize_event_pool(struct event_pool *pool,
|
|
|
|
int size, struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pool->size = size;
|
|
|
|
pool->next = 0;
|
2006-04-07 18:10:03 +08:00
|
|
|
pool->events = kcalloc(pool->size, sizeof(*pool->events), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!pool->events)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pool->iu_storage =
|
|
|
|
dma_alloc_coherent(hostdata->dev,
|
|
|
|
pool->size * sizeof(*pool->iu_storage),
|
|
|
|
&pool->iu_token, 0);
|
|
|
|
if (!pool->iu_storage) {
|
|
|
|
kfree(pool->events);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pool->size; ++i) {
|
|
|
|
struct srp_event_struct *evt = &pool->events[i];
|
|
|
|
memset(&evt->crq, 0x00, sizeof(evt->crq));
|
|
|
|
atomic_set(&evt->free, 1);
|
2016-02-11 09:32:23 +08:00
|
|
|
evt->crq.valid = VIOSRP_CRQ_CMD_RSP;
|
2013-09-03 08:04:47 +08:00
|
|
|
evt->crq.IU_length = cpu_to_be16(sizeof(*evt->xfer_iu));
|
|
|
|
evt->crq.IU_data_ptr = cpu_to_be64(pool->iu_token +
|
|
|
|
sizeof(*evt->xfer_iu) * i);
|
2005-04-17 06:20:36 +08:00
|
|
|
evt->xfer_iu = pool->iu_storage + i;
|
|
|
|
evt->hostdata = hostdata;
|
2005-09-07 06:11:54 +08:00
|
|
|
evt->ext_list = NULL;
|
|
|
|
evt->ext_list_token = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* release_event_pool: - Frees memory of an event pool of a host
|
|
|
|
* @pool: event_pool to be released
|
|
|
|
* @hostdata: ibmvscsi_host_data who owns the even pool
|
|
|
|
*
|
|
|
|
* Returns zero on success.
|
|
|
|
*/
|
|
|
|
static void release_event_pool(struct event_pool *pool,
|
|
|
|
struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int i, in_use = 0;
|
2005-09-07 06:11:54 +08:00
|
|
|
for (i = 0; i < pool->size; ++i) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (atomic_read(&pool->events[i].free) != 1)
|
|
|
|
++in_use;
|
2005-09-07 06:11:54 +08:00
|
|
|
if (pool->events[i].ext_list) {
|
|
|
|
dma_free_coherent(hostdata->dev,
|
2006-03-26 02:57:14 +08:00
|
|
|
SG_ALL * sizeof(struct srp_direct_buf),
|
2005-09-07 06:11:54 +08:00
|
|
|
pool->events[i].ext_list,
|
|
|
|
pool->events[i].ext_list_token);
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
if (in_use)
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_warn(hostdata->dev, "releasing event pool with %d "
|
|
|
|
"events still in use?\n", in_use);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(pool->events);
|
|
|
|
dma_free_coherent(hostdata->dev,
|
|
|
|
pool->size * sizeof(*pool->iu_storage),
|
|
|
|
pool->iu_storage, pool->iu_token);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* valid_event_struct: - Determines if event is valid.
|
|
|
|
* @pool: event_pool that contains the event
|
|
|
|
* @evt: srp_event_struct to be checked for validity
|
|
|
|
*
|
|
|
|
* Returns zero if event is invalid, one otherwise.
|
|
|
|
*/
|
|
|
|
static int valid_event_struct(struct event_pool *pool,
|
|
|
|
struct srp_event_struct *evt)
|
|
|
|
{
|
|
|
|
int index = evt - pool->events;
|
|
|
|
if (index < 0 || index >= pool->size) /* outside of bounds */
|
|
|
|
return 0;
|
|
|
|
if (evt != pool->events + index) /* unaligned */
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_free-event_struct: - Changes status of event to "free"
|
|
|
|
* @pool: event_pool that contains the event
|
|
|
|
* @evt: srp_event_struct to be modified
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void free_event_struct(struct event_pool *pool,
|
|
|
|
struct srp_event_struct *evt)
|
|
|
|
{
|
|
|
|
if (!valid_event_struct(pool, evt)) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(evt->hostdata->dev, "Freeing invalid event_struct %p "
|
|
|
|
"(not in pool %p)\n", evt, pool->events);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (atomic_inc_return(&evt->free) != 1) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(evt->hostdata->dev, "Freeing event_struct %p "
|
|
|
|
"which is not in use!\n", evt);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_evt_struct: - Gets the next free event in pool
|
|
|
|
* @pool: event_pool that contains the events to be searched
|
|
|
|
*
|
|
|
|
* Returns the next event in "free" state, and NULL if none are free.
|
|
|
|
* Note that no synchronization is done here, we assume the host_lock
|
|
|
|
* will syncrhonze things.
|
|
|
|
*/
|
|
|
|
static struct srp_event_struct *get_event_struct(struct event_pool *pool)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int poolsize = pool->size;
|
|
|
|
int offset = pool->next;
|
|
|
|
|
|
|
|
for (i = 0; i < poolsize; i++) {
|
|
|
|
offset = (offset + 1) % poolsize;
|
|
|
|
if (!atomic_dec_if_positive(&pool->events[offset].free)) {
|
|
|
|
pool->next = offset;
|
|
|
|
return &pool->events[offset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_ERR "ibmvscsi: found no event struct in pool!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* init_event_struct: Initialize fields in an event struct that are always
|
|
|
|
* required.
|
|
|
|
* @evt: The event
|
|
|
|
* @done: Routine to call when the event is responded to
|
|
|
|
* @format: SRP or MAD format
|
|
|
|
* @timeout: timeout value set in the CRQ
|
|
|
|
*/
|
|
|
|
static void init_event_struct(struct srp_event_struct *evt_struct,
|
|
|
|
void (*done) (struct srp_event_struct *),
|
|
|
|
u8 format,
|
|
|
|
int timeout)
|
|
|
|
{
|
|
|
|
evt_struct->cmnd = NULL;
|
|
|
|
evt_struct->cmnd_done = NULL;
|
|
|
|
evt_struct->sync_srp = NULL;
|
|
|
|
evt_struct->crq.format = format;
|
2013-09-03 08:04:47 +08:00
|
|
|
evt_struct->crq.timeout = cpu_to_be16(timeout);
|
2005-04-17 06:20:36 +08:00
|
|
|
evt_struct->done = done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* Routines for receiving SCSI responses from the hosting partition
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set_srp_direction: Set the fields in the srp related to data
|
|
|
|
* direction and number of buffers based on the direction in
|
|
|
|
* the scsi_cmnd and the number of buffers
|
|
|
|
*/
|
|
|
|
static void set_srp_direction(struct scsi_cmnd *cmd,
|
|
|
|
struct srp_cmd *srp_cmd,
|
|
|
|
int numbuf)
|
|
|
|
{
|
2006-03-26 02:57:14 +08:00
|
|
|
u8 fmt;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (numbuf == 0)
|
|
|
|
return;
|
|
|
|
|
2006-03-26 02:57:14 +08:00
|
|
|
if (numbuf == 1)
|
|
|
|
fmt = SRP_DATA_DESC_DIRECT;
|
|
|
|
else {
|
|
|
|
fmt = SRP_DATA_DESC_INDIRECT;
|
|
|
|
numbuf = min(numbuf, MAX_INDIRECT_BUFS);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cmd->sc_data_direction == DMA_TO_DEVICE)
|
2006-03-26 02:57:14 +08:00
|
|
|
srp_cmd->data_out_desc_cnt = numbuf;
|
|
|
|
else
|
|
|
|
srp_cmd->data_in_desc_cnt = numbuf;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-03-26 02:57:14 +08:00
|
|
|
|
|
|
|
if (cmd->sc_data_direction == DMA_TO_DEVICE)
|
|
|
|
srp_cmd->buf_fmt = fmt << 4;
|
|
|
|
else
|
|
|
|
srp_cmd->buf_fmt = fmt;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format
|
|
|
|
* @cmd: srp_cmd whose additional_data member will be unmapped
|
|
|
|
* @dev: device for which the memory is mapped
|
|
|
|
*
|
|
|
|
*/
|
2005-09-07 06:11:54 +08:00
|
|
|
static void unmap_cmd_data(struct srp_cmd *cmd,
|
|
|
|
struct srp_event_struct *evt_struct,
|
|
|
|
struct device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-26 02:57:14 +08:00
|
|
|
u8 out_fmt, in_fmt;
|
|
|
|
|
|
|
|
out_fmt = cmd->buf_fmt >> 4;
|
|
|
|
in_fmt = cmd->buf_fmt & ((1U << 4) - 1);
|
|
|
|
|
|
|
|
if (out_fmt == SRP_NO_DATA_DESC && in_fmt == SRP_NO_DATA_DESC)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2005-09-07 06:11:54 +08:00
|
|
|
|
2010-04-02 14:50:24 +08:00
|
|
|
if (evt_struct->cmnd)
|
|
|
|
scsi_dma_unmap(evt_struct->cmnd);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-25 23:32:58 +08:00
|
|
|
static int map_sg_list(struct scsi_cmnd *cmd, int nseg,
|
2006-03-26 02:57:14 +08:00
|
|
|
struct srp_direct_buf *md)
|
2005-09-07 06:11:54 +08:00
|
|
|
{
|
|
|
|
int i;
|
2007-05-25 23:32:58 +08:00
|
|
|
struct scatterlist *sg;
|
2005-09-07 06:11:54 +08:00
|
|
|
u64 total_length = 0;
|
|
|
|
|
2007-05-25 23:32:58 +08:00
|
|
|
scsi_for_each_sg(cmd, sg, nseg, i) {
|
2006-03-26 02:57:14 +08:00
|
|
|
struct srp_direct_buf *descr = md + i;
|
2013-09-03 08:04:47 +08:00
|
|
|
descr->va = cpu_to_be64(sg_dma_address(sg));
|
|
|
|
descr->len = cpu_to_be32(sg_dma_len(sg));
|
2006-03-26 02:57:14 +08:00
|
|
|
descr->key = 0;
|
2007-05-25 23:32:58 +08:00
|
|
|
total_length += sg_dma_len(sg);
|
2005-09-07 06:11:54 +08:00
|
|
|
}
|
|
|
|
return total_length;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* map_sg_data: - Maps dma for a scatterlist and initializes decriptor fields
|
|
|
|
* @cmd: Scsi_Cmnd with the scatterlist
|
|
|
|
* @srp_cmd: srp_cmd that contains the memory descriptor
|
|
|
|
* @dev: device for which to map dma memory
|
|
|
|
*
|
|
|
|
* Called by map_data_for_srp_cmd() when building srp cmd from scsi cmd.
|
|
|
|
* Returns 1 on success.
|
|
|
|
*/
|
|
|
|
static int map_sg_data(struct scsi_cmnd *cmd,
|
2005-09-07 06:11:54 +08:00
|
|
|
struct srp_event_struct *evt_struct,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct srp_cmd *srp_cmd, struct device *dev)
|
|
|
|
{
|
|
|
|
|
2005-09-07 06:11:54 +08:00
|
|
|
int sg_mapped;
|
2005-04-17 06:20:36 +08:00
|
|
|
u64 total_length = 0;
|
2006-03-26 02:57:14 +08:00
|
|
|
struct srp_direct_buf *data =
|
|
|
|
(struct srp_direct_buf *) srp_cmd->add_data;
|
|
|
|
struct srp_indirect_buf *indirect =
|
|
|
|
(struct srp_indirect_buf *) data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-25 23:32:58 +08:00
|
|
|
sg_mapped = scsi_dma_map(cmd);
|
|
|
|
if (!sg_mapped)
|
|
|
|
return 1;
|
|
|
|
else if (sg_mapped < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
set_srp_direction(cmd, srp_cmd, sg_mapped);
|
|
|
|
|
|
|
|
/* special case; we can use a single direct descriptor */
|
|
|
|
if (sg_mapped == 1) {
|
2007-05-25 23:32:58 +08:00
|
|
|
map_sg_list(cmd, sg_mapped, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-26 02:57:14 +08:00
|
|
|
indirect->table_desc.va = 0;
|
2013-09-03 08:04:47 +08:00
|
|
|
indirect->table_desc.len = cpu_to_be32(sg_mapped *
|
|
|
|
sizeof(struct srp_direct_buf));
|
2006-03-26 02:57:14 +08:00
|
|
|
indirect->table_desc.key = 0;
|
2005-09-07 06:11:54 +08:00
|
|
|
|
|
|
|
if (sg_mapped <= MAX_INDIRECT_BUFS) {
|
2007-05-25 23:32:58 +08:00
|
|
|
total_length = map_sg_list(cmd, sg_mapped,
|
2006-03-26 02:57:14 +08:00
|
|
|
&indirect->desc_list[0]);
|
2013-09-03 08:04:47 +08:00
|
|
|
indirect->len = cpu_to_be32(total_length);
|
2005-09-07 06:11:54 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-07 06:11:54 +08:00
|
|
|
/* get indirect table */
|
|
|
|
if (!evt_struct->ext_list) {
|
2006-03-26 02:57:14 +08:00
|
|
|
evt_struct->ext_list = (struct srp_direct_buf *)
|
2007-05-25 23:32:58 +08:00
|
|
|
dma_alloc_coherent(dev,
|
2006-03-26 02:57:14 +08:00
|
|
|
SG_ALL * sizeof(struct srp_direct_buf),
|
|
|
|
&evt_struct->ext_list_token, 0);
|
2005-09-07 06:11:54 +08:00
|
|
|
if (!evt_struct->ext_list) {
|
2008-07-24 02:35:27 +08:00
|
|
|
if (!firmware_has_feature(FW_FEATURE_CMO))
|
|
|
|
sdev_printk(KERN_ERR, cmd->device,
|
|
|
|
"Can't allocate memory "
|
|
|
|
"for indirect table\n");
|
2009-01-23 03:40:09 +08:00
|
|
|
scsi_dma_unmap(cmd);
|
2005-09-07 06:11:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-25 23:32:58 +08:00
|
|
|
total_length = map_sg_list(cmd, sg_mapped, evt_struct->ext_list);
|
2005-09-07 06:11:54 +08:00
|
|
|
|
2013-09-03 08:04:47 +08:00
|
|
|
indirect->len = cpu_to_be32(total_length);
|
|
|
|
indirect->table_desc.va = cpu_to_be64(evt_struct->ext_list_token);
|
|
|
|
indirect->table_desc.len = cpu_to_be32(sg_mapped *
|
|
|
|
sizeof(indirect->desc_list[0]));
|
2006-03-26 02:57:14 +08:00
|
|
|
memcpy(indirect->desc_list, evt_struct->ext_list,
|
|
|
|
MAX_INDIRECT_BUFS * sizeof(struct srp_direct_buf));
|
2005-09-07 06:11:54 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* map_data_for_srp_cmd: - Calls functions to map data for srp cmds
|
|
|
|
* @cmd: struct scsi_cmnd with the memory to be mapped
|
|
|
|
* @srp_cmd: srp_cmd that contains the memory descriptor
|
|
|
|
* @dev: dma device for which to map dma memory
|
|
|
|
*
|
|
|
|
* Called by scsi_cmd_to_srp_cmd() when converting scsi cmds to srp cmds
|
|
|
|
* Returns 1 on success.
|
|
|
|
*/
|
|
|
|
static int map_data_for_srp_cmd(struct scsi_cmnd *cmd,
|
2005-09-07 06:11:54 +08:00
|
|
|
struct srp_event_struct *evt_struct,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct srp_cmd *srp_cmd, struct device *dev)
|
|
|
|
{
|
|
|
|
switch (cmd->sc_data_direction) {
|
|
|
|
case DMA_FROM_DEVICE:
|
|
|
|
case DMA_TO_DEVICE:
|
|
|
|
break;
|
|
|
|
case DMA_NONE:
|
|
|
|
return 1;
|
|
|
|
case DMA_BIDIRECTIONAL:
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_ERR, cmd->device,
|
|
|
|
"Can't map DMA_BIDIRECTIONAL to read/write\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
default:
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_ERR, cmd->device,
|
|
|
|
"Unknown data direction 0x%02x; can't map!\n",
|
|
|
|
cmd->sc_data_direction);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-25 23:32:58 +08:00
|
|
|
return map_sg_data(cmd, evt_struct, srp_cmd, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-06-14 06:12:26 +08:00
|
|
|
/**
|
|
|
|
* purge_requests: Our virtual adapter just shut down. purge any sent requests
|
|
|
|
* @hostdata: the adapter
|
|
|
|
*/
|
|
|
|
static void purge_requests(struct ibmvscsi_host_data *hostdata, int error_code)
|
|
|
|
{
|
2010-06-18 02:56:02 +08:00
|
|
|
struct srp_event_struct *evt;
|
2007-06-14 06:12:26 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
2010-06-18 02:56:02 +08:00
|
|
|
while (!list_empty(&hostdata->sent)) {
|
|
|
|
evt = list_first_entry(&hostdata->sent, struct srp_event_struct, list);
|
|
|
|
list_del(&evt->list);
|
|
|
|
del_timer(&evt->timer);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
if (evt->cmnd) {
|
|
|
|
evt->cmnd->result = (error_code << 16);
|
|
|
|
unmap_cmd_data(&evt->iu.srp.cmd, evt,
|
|
|
|
evt->hostdata->dev);
|
|
|
|
if (evt->cmnd_done)
|
|
|
|
evt->cmnd_done(evt->cmnd);
|
2014-05-23 23:52:10 +08:00
|
|
|
} else if (evt->done && evt->crq.format != VIOSRP_MAD_FORMAT &&
|
|
|
|
evt->iu.srp.login_req.opcode != SRP_LOGIN_REQ)
|
2010-06-18 02:56:02 +08:00
|
|
|
evt->done(evt);
|
|
|
|
free_event_struct(&evt->hostdata->pool, evt);
|
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
2007-06-14 06:12:26 +08:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_reset_host - Reset the connection to the server
|
|
|
|
* @hostdata: struct ibmvscsi_host_data to reset
|
|
|
|
*/
|
|
|
|
static void ibmvscsi_reset_host(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
scsi_block_requests(hostdata->host);
|
|
|
|
atomic_set(&hostdata->request_limit, 0);
|
|
|
|
|
|
|
|
purge_requests(hostdata, DID_ERROR);
|
2010-06-18 02:56:00 +08:00
|
|
|
hostdata->reset_crq = 1;
|
|
|
|
wake_up(&hostdata->work_wait_q);
|
2007-06-14 06:12:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_timeout - Internal command timeout handler
|
|
|
|
* @evt_struct: struct srp_event_struct that timed out
|
|
|
|
*
|
|
|
|
* Called when an internally generated command times out
|
|
|
|
*/
|
|
|
|
static void ibmvscsi_timeout(struct srp_event_struct *evt_struct)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
|
|
|
|
|
|
|
|
dev_err(hostdata->dev, "Command timed out (%x). Resetting connection\n",
|
|
|
|
evt_struct->iu.srp.cmd.opcode);
|
|
|
|
|
|
|
|
ibmvscsi_reset_host(hostdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* Routines for sending and receiving SRPs
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* ibmvscsi_send_srp_event: - Transforms event to u64 array and calls send_crq()
|
|
|
|
* @evt_struct: evt_struct to be sent
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
2007-06-14 06:12:26 +08:00
|
|
|
* @timeout: timeout in seconds - 0 means do not time command
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Returns the value returned from ibmvscsi_send_crq(). (Zero for success)
|
|
|
|
* Note that this routine assumes that host_lock is held for synchronization
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
|
2007-06-14 06:12:26 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata,
|
|
|
|
unsigned long timeout)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-09-03 08:04:47 +08:00
|
|
|
__be64 *crq_as_u64 = (__be64 *)&evt_struct->crq;
|
2007-10-31 00:37:07 +08:00
|
|
|
int request_status = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc;
|
2010-06-18 02:56:03 +08:00
|
|
|
int srp_req = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-03-29 01:45:46 +08:00
|
|
|
/* If we have exhausted our request limit, just fail this request,
|
|
|
|
* unless it is for a reset or abort.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Note that there are rare cases involving driver generated requests
|
|
|
|
* (such as task management requests) that the mid layer may think we
|
|
|
|
* can handle more requests (can_queue) when we actually can't
|
|
|
|
*/
|
2006-06-13 10:22:51 +08:00
|
|
|
if (evt_struct->crq.format == VIOSRP_SRP_FORMAT) {
|
2010-06-18 02:56:03 +08:00
|
|
|
srp_req = 1;
|
2006-06-13 10:22:51 +08:00
|
|
|
request_status =
|
|
|
|
atomic_dec_if_positive(&hostdata->request_limit);
|
|
|
|
/* If request limit was -1 when we started, it is now even
|
|
|
|
* less than that
|
|
|
|
*/
|
|
|
|
if (request_status < -1)
|
|
|
|
goto send_error;
|
2007-03-29 01:45:46 +08:00
|
|
|
/* Otherwise, we may have run out of requests. */
|
2007-10-31 00:37:07 +08:00
|
|
|
/* If request limit was 0 when we started the adapter is in the
|
|
|
|
* process of performing a login with the server adapter, or
|
|
|
|
* we may have run out of requests.
|
|
|
|
*/
|
|
|
|
else if (request_status == -1 &&
|
|
|
|
evt_struct->iu.srp.login_req.opcode != SRP_LOGIN_REQ)
|
|
|
|
goto send_busy;
|
2007-03-29 01:45:46 +08:00
|
|
|
/* Abort and reset calls should make it through.
|
|
|
|
* Nothing except abort and reset should use the last two
|
|
|
|
* slots unless we had two or less to begin with.
|
|
|
|
*/
|
|
|
|
else if (request_status < 2 &&
|
|
|
|
evt_struct->iu.srp.cmd.opcode != SRP_TSK_MGMT) {
|
|
|
|
/* In the case that we have less than two requests
|
|
|
|
* available, check the server limit as a combination
|
|
|
|
* of the request limit and the number of requests
|
|
|
|
* in-flight (the size of the send list). If the
|
|
|
|
* server limit is greater than 2, return busy so
|
|
|
|
* that the last two are reserved for reset and abort.
|
|
|
|
*/
|
|
|
|
int server_limit = request_status;
|
|
|
|
struct srp_event_struct *tmp_evt;
|
|
|
|
|
|
|
|
list_for_each_entry(tmp_evt, &hostdata->sent, list) {
|
|
|
|
server_limit++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (server_limit > 2)
|
|
|
|
goto send_busy;
|
|
|
|
}
|
2006-06-13 10:22:51 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Copy the IU into the transfer area */
|
|
|
|
*evt_struct->xfer_iu = evt_struct->iu;
|
2006-03-26 02:57:14 +08:00
|
|
|
evt_struct->xfer_iu->srp.rsp.tag = (u64)evt_struct;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Add this to the sent list. We need to do this
|
|
|
|
* before we actually send
|
|
|
|
* in case it comes back REALLY fast
|
|
|
|
*/
|
|
|
|
list_add_tail(&evt_struct->list, &hostdata->sent);
|
|
|
|
|
2007-06-14 06:12:26 +08:00
|
|
|
init_timer(&evt_struct->timer);
|
|
|
|
if (timeout) {
|
|
|
|
evt_struct->timer.data = (unsigned long) evt_struct;
|
|
|
|
evt_struct->timer.expires = jiffies + (timeout * HZ);
|
|
|
|
evt_struct->timer.function = (void (*)(unsigned long))ibmvscsi_timeout;
|
|
|
|
add_timer(&evt_struct->timer);
|
|
|
|
}
|
|
|
|
|
2013-09-03 08:04:47 +08:00
|
|
|
rc = ibmvscsi_send_crq(hostdata, be64_to_cpu(crq_as_u64[0]),
|
|
|
|
be64_to_cpu(crq_as_u64[1]));
|
|
|
|
if (rc != 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
list_del(&evt_struct->list);
|
2007-06-14 06:12:26 +08:00
|
|
|
del_timer(&evt_struct->timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
/* If send_crq returns H_CLOSED, return SCSI_MLQUEUE_HOST_BUSY.
|
|
|
|
* Firmware will send a CRQ with a transport event (0xFF) to
|
|
|
|
* tell this client what has happened to the transport. This
|
|
|
|
* will be handled in ibmvscsi_handle_crq()
|
|
|
|
*/
|
|
|
|
if (rc == H_CLOSED) {
|
|
|
|
dev_warn(hostdata->dev, "send warning. "
|
|
|
|
"Receive queue closed, will retry.\n");
|
|
|
|
goto send_busy;
|
|
|
|
}
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "send error %d\n", rc);
|
2010-06-18 02:56:03 +08:00
|
|
|
if (srp_req)
|
|
|
|
atomic_inc(&hostdata->request_limit);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto send_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2006-06-13 10:22:51 +08:00
|
|
|
send_busy:
|
2005-09-07 06:11:54 +08:00
|
|
|
unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
free_event_struct(&hostdata->pool, evt_struct);
|
2010-06-18 02:56:03 +08:00
|
|
|
if (srp_req && request_status != -1)
|
2007-10-31 00:37:07 +08:00
|
|
|
atomic_inc(&hostdata->request_limit);
|
2007-03-29 01:45:46 +08:00
|
|
|
return SCSI_MLQUEUE_HOST_BUSY;
|
2006-06-13 10:22:51 +08:00
|
|
|
|
|
|
|
send_error:
|
|
|
|
unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
|
|
|
|
|
|
|
|
if (evt_struct->cmnd != NULL) {
|
|
|
|
evt_struct->cmnd->result = DID_ERROR << 16;
|
|
|
|
evt_struct->cmnd_done(evt_struct->cmnd);
|
|
|
|
} else if (evt_struct->done)
|
|
|
|
evt_struct->done(evt_struct);
|
|
|
|
|
|
|
|
free_event_struct(&hostdata->pool, evt_struct);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* handle_cmd_rsp: - Handle responses from commands
|
|
|
|
* @evt_struct: srp_event_struct to be handled
|
|
|
|
*
|
|
|
|
* Used as a callback by when sending scsi cmds.
|
|
|
|
* Gets called by ibmvscsi_handle_crq()
|
|
|
|
*/
|
|
|
|
static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
|
|
|
|
{
|
|
|
|
struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp;
|
|
|
|
struct scsi_cmnd *cmnd = evt_struct->cmnd;
|
|
|
|
|
2006-03-26 02:57:14 +08:00
|
|
|
if (unlikely(rsp->opcode != SRP_RSP)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (printk_ratelimit())
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_warn(evt_struct->hostdata->dev,
|
2016-12-08 06:04:36 +08:00
|
|
|
"bad SRP RSP type %#02x\n", rsp->opcode);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cmnd) {
|
2008-04-26 05:58:29 +08:00
|
|
|
cmnd->result |= rsp->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
|
|
|
|
memcpy(cmnd->sense_buffer,
|
2006-03-26 02:57:14 +08:00
|
|
|
rsp->data,
|
2013-09-03 08:04:47 +08:00
|
|
|
be32_to_cpu(rsp->sense_data_len));
|
2005-04-17 06:20:36 +08:00
|
|
|
unmap_cmd_data(&evt_struct->iu.srp.cmd,
|
2005-09-07 06:11:54 +08:00
|
|
|
evt_struct,
|
2005-04-17 06:20:36 +08:00
|
|
|
evt_struct->hostdata->dev);
|
|
|
|
|
2006-03-26 02:57:14 +08:00
|
|
|
if (rsp->flags & SRP_RSP_FLAG_DOOVER)
|
2013-09-03 08:04:47 +08:00
|
|
|
scsi_set_resid(cmnd,
|
|
|
|
be32_to_cpu(rsp->data_out_res_cnt));
|
2006-03-26 02:57:14 +08:00
|
|
|
else if (rsp->flags & SRP_RSP_FLAG_DIOVER)
|
2013-09-03 08:04:47 +08:00
|
|
|
scsi_set_resid(cmnd, be32_to_cpu(rsp->data_in_res_cnt));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (evt_struct->cmnd_done)
|
|
|
|
evt_struct->cmnd_done(cmnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lun_from_dev: - Returns the lun of the scsi device
|
|
|
|
* @dev: struct scsi_device
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static inline u16 lun_from_dev(struct scsi_device *dev)
|
|
|
|
{
|
|
|
|
return (0x2 << 14) | (dev->id << 8) | (dev->channel << 5) | dev->lun;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_queue: - The queuecommand function of the scsi template
|
|
|
|
* @cmd: struct scsi_cmnd to be executed
|
|
|
|
* @done: Callback function to be called when cmd is completed
|
|
|
|
*/
|
2010-11-16 15:10:29 +08:00
|
|
|
static int ibmvscsi_queuecommand_lck(struct scsi_cmnd *cmnd,
|
2005-04-17 06:20:36 +08:00
|
|
|
void (*done) (struct scsi_cmnd *))
|
|
|
|
{
|
|
|
|
struct srp_cmd *srp_cmd;
|
|
|
|
struct srp_event_struct *evt_struct;
|
2006-03-26 02:57:14 +08:00
|
|
|
struct srp_indirect_buf *indirect;
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(cmnd->device->host);
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 lun = lun_from_dev(cmnd->device);
|
2006-03-26 02:57:14 +08:00
|
|
|
u8 out_fmt, in_fmt;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-26 05:58:29 +08:00
|
|
|
cmnd->result = (DID_OK << 16);
|
2005-04-17 06:20:36 +08:00
|
|
|
evt_struct = get_event_struct(&hostdata->pool);
|
|
|
|
if (!evt_struct)
|
|
|
|
return SCSI_MLQUEUE_HOST_BUSY;
|
|
|
|
|
|
|
|
/* Set up the actual SRP IU */
|
|
|
|
srp_cmd = &evt_struct->iu.srp.cmd;
|
2006-03-26 02:57:14 +08:00
|
|
|
memset(srp_cmd, 0x00, SRP_MAX_IU_LEN);
|
|
|
|
srp_cmd->opcode = SRP_CMD;
|
2008-04-30 16:19:47 +08:00
|
|
|
memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(srp_cmd->cdb));
|
2015-05-18 19:27:14 +08:00
|
|
|
int_to_scsilun(lun, &srp_cmd->lun);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-07 06:11:54 +08:00
|
|
|
if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) {
|
2008-07-24 02:35:27 +08:00
|
|
|
if (!firmware_has_feature(FW_FEATURE_CMO))
|
|
|
|
sdev_printk(KERN_ERR, cmnd->device,
|
|
|
|
"couldn't convert cmd to srp_cmd\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
free_event_struct(&hostdata->pool, evt_struct);
|
|
|
|
return SCSI_MLQUEUE_HOST_BUSY;
|
|
|
|
}
|
|
|
|
|
2005-09-07 06:11:54 +08:00
|
|
|
init_event_struct(evt_struct,
|
|
|
|
handle_cmd_rsp,
|
|
|
|
VIOSRP_SRP_FORMAT,
|
2008-09-14 20:55:09 +08:00
|
|
|
cmnd->request->timeout/HZ);
|
2005-09-07 06:11:54 +08:00
|
|
|
|
|
|
|
evt_struct->cmnd = cmnd;
|
|
|
|
evt_struct->cmnd_done = done;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Fix up dma address of the buffer itself */
|
2006-03-26 02:57:14 +08:00
|
|
|
indirect = (struct srp_indirect_buf *) srp_cmd->add_data;
|
|
|
|
out_fmt = srp_cmd->buf_fmt >> 4;
|
|
|
|
in_fmt = srp_cmd->buf_fmt & ((1U << 4) - 1);
|
|
|
|
if ((in_fmt == SRP_DATA_DESC_INDIRECT ||
|
|
|
|
out_fmt == SRP_DATA_DESC_INDIRECT) &&
|
|
|
|
indirect->table_desc.va == 0) {
|
2013-09-03 08:04:47 +08:00
|
|
|
indirect->table_desc.va =
|
|
|
|
cpu_to_be64(be64_to_cpu(evt_struct->crq.IU_data_ptr) +
|
2006-03-26 02:57:14 +08:00
|
|
|
offsetof(struct srp_cmd, add_data) +
|
2013-09-03 08:04:47 +08:00
|
|
|
offsetof(struct srp_indirect_buf, desc_list));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-06-14 06:12:26 +08:00
|
|
|
return ibmvscsi_send_srp_event(evt_struct, hostdata, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-11-16 15:10:29 +08:00
|
|
|
static DEF_SCSI_QCMD(ibmvscsi_queuecommand)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* Routines for driver initialization
|
|
|
|
*/
|
2009-06-09 05:19:04 +08:00
|
|
|
|
2009-06-09 05:19:08 +08:00
|
|
|
/**
|
|
|
|
* map_persist_bufs: - Pre-map persistent data for adapter logins
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
* Map the capabilities and adapter info DMA buffers to avoid runtime failures.
|
|
|
|
* Return 1 on error, 0 on success.
|
|
|
|
*/
|
|
|
|
static int map_persist_bufs(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
|
|
|
|
hostdata->caps_addr = dma_map_single(hostdata->dev, &hostdata->caps,
|
|
|
|
sizeof(hostdata->caps), DMA_BIDIRECTIONAL);
|
|
|
|
|
|
|
|
if (dma_mapping_error(hostdata->dev, hostdata->caps_addr)) {
|
|
|
|
dev_err(hostdata->dev, "Unable to map capabilities buffer!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hostdata->adapter_info_addr = dma_map_single(hostdata->dev,
|
|
|
|
&hostdata->madapter_info,
|
|
|
|
sizeof(hostdata->madapter_info),
|
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
if (dma_mapping_error(hostdata->dev, hostdata->adapter_info_addr)) {
|
|
|
|
dev_err(hostdata->dev, "Unable to map adapter info buffer!\n");
|
|
|
|
dma_unmap_single(hostdata->dev, hostdata->caps_addr,
|
|
|
|
sizeof(hostdata->caps), DMA_BIDIRECTIONAL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unmap_persist_bufs: - Unmap persistent data needed for adapter logins
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
* Unmap the capabilities and adapter info DMA buffers
|
|
|
|
*/
|
|
|
|
static void unmap_persist_bufs(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
dma_unmap_single(hostdata->dev, hostdata->caps_addr,
|
|
|
|
sizeof(hostdata->caps), DMA_BIDIRECTIONAL);
|
|
|
|
|
|
|
|
dma_unmap_single(hostdata->dev, hostdata->adapter_info_addr,
|
|
|
|
sizeof(hostdata->madapter_info), DMA_BIDIRECTIONAL);
|
|
|
|
}
|
|
|
|
|
2009-06-09 05:19:04 +08:00
|
|
|
/**
|
|
|
|
* login_rsp: - Handle response to SRP login request
|
|
|
|
* @evt_struct: srp_event_struct with the response
|
|
|
|
*
|
|
|
|
* Used as a "done" callback by when sending srp_login. Gets called
|
|
|
|
* by ibmvscsi_handle_crq()
|
|
|
|
*/
|
|
|
|
static void login_rsp(struct srp_event_struct *evt_struct)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
|
|
|
|
switch (evt_struct->xfer_iu->srp.login_rsp.opcode) {
|
|
|
|
case SRP_LOGIN_RSP: /* it worked! */
|
|
|
|
break;
|
|
|
|
case SRP_LOGIN_REJ: /* refused! */
|
|
|
|
dev_info(hostdata->dev, "SRP_LOGIN_REJ reason %u\n",
|
|
|
|
evt_struct->xfer_iu->srp.login_rej.reason);
|
|
|
|
/* Login failed. */
|
|
|
|
atomic_set(&hostdata->request_limit, -1);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
dev_err(hostdata->dev, "Invalid login response typecode 0x%02x!\n",
|
|
|
|
evt_struct->xfer_iu->srp.login_rsp.opcode);
|
|
|
|
/* Login failed. */
|
|
|
|
atomic_set(&hostdata->request_limit, -1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(hostdata->dev, "SRP_LOGIN succeeded\n");
|
2009-06-09 05:19:08 +08:00
|
|
|
hostdata->client_migrated = 0;
|
2009-06-09 05:19:04 +08:00
|
|
|
|
|
|
|
/* Now we know what the real request-limit is.
|
|
|
|
* This value is set rather than added to request_limit because
|
|
|
|
* request_limit could have been set to -1 by this client.
|
|
|
|
*/
|
|
|
|
atomic_set(&hostdata->request_limit,
|
2013-09-03 08:04:47 +08:00
|
|
|
be32_to_cpu(evt_struct->xfer_iu->srp.login_rsp.req_lim_delta));
|
2009-06-09 05:19:04 +08:00
|
|
|
|
|
|
|
/* If we had any pending I/Os, kick them */
|
|
|
|
scsi_unblock_requests(hostdata->host);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_srp_login: - Sends the srp login
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
* Returns zero if successful.
|
|
|
|
*/
|
|
|
|
static int send_srp_login(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
unsigned long flags;
|
|
|
|
struct srp_login_req *login;
|
|
|
|
struct srp_event_struct *evt_struct = get_event_struct(&hostdata->pool);
|
|
|
|
|
|
|
|
BUG_ON(!evt_struct);
|
|
|
|
init_event_struct(evt_struct, login_rsp,
|
|
|
|
VIOSRP_SRP_FORMAT, login_timeout);
|
|
|
|
|
|
|
|
login = &evt_struct->iu.srp.login_req;
|
|
|
|
memset(login, 0, sizeof(*login));
|
|
|
|
login->opcode = SRP_LOGIN_REQ;
|
2013-09-03 08:04:47 +08:00
|
|
|
login->req_it_iu_len = cpu_to_be32(sizeof(union srp_iu));
|
|
|
|
login->req_buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT |
|
|
|
|
SRP_BUF_FORMAT_INDIRECT);
|
2009-06-09 05:19:04 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
|
|
|
/* Start out with a request limit of 0, since this is negotiated in
|
|
|
|
* the login request we are just sending and login requests always
|
|
|
|
* get sent by the driver regardless of request_limit.
|
|
|
|
*/
|
|
|
|
atomic_set(&hostdata->request_limit, 0);
|
|
|
|
|
|
|
|
rc = ibmvscsi_send_srp_event(evt_struct, hostdata, login_timeout * 2);
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
dev_info(hostdata->dev, "sent SRP login\n");
|
|
|
|
return rc;
|
|
|
|
};
|
|
|
|
|
2009-06-09 05:19:08 +08:00
|
|
|
/**
|
|
|
|
* capabilities_rsp: - Handle response to MAD adapter capabilities request
|
|
|
|
* @evt_struct: srp_event_struct with the response
|
|
|
|
*
|
|
|
|
* Used as a "done" callback by when sending adapter_info.
|
|
|
|
*/
|
|
|
|
static void capabilities_rsp(struct srp_event_struct *evt_struct)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
|
|
|
|
|
|
|
|
if (evt_struct->xfer_iu->mad.capabilities.common.status) {
|
|
|
|
dev_err(hostdata->dev, "error 0x%X getting capabilities info\n",
|
|
|
|
evt_struct->xfer_iu->mad.capabilities.common.status);
|
|
|
|
} else {
|
2013-09-03 08:04:47 +08:00
|
|
|
if (hostdata->caps.migration.common.server_support !=
|
|
|
|
cpu_to_be16(SERVER_SUPPORTS_CAP))
|
2009-06-09 05:19:08 +08:00
|
|
|
dev_info(hostdata->dev, "Partition migration not supported\n");
|
|
|
|
|
|
|
|
if (client_reserve) {
|
|
|
|
if (hostdata->caps.reserve.common.server_support ==
|
2013-09-03 08:04:47 +08:00
|
|
|
cpu_to_be16(SERVER_SUPPORTS_CAP))
|
2009-06-09 05:19:08 +08:00
|
|
|
dev_info(hostdata->dev, "Client reserve enabled\n");
|
|
|
|
else
|
|
|
|
dev_info(hostdata->dev, "Client reserve not supported\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send_srp_login(hostdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_mad_capabilities: - Sends the mad capabilities request
|
|
|
|
* and stores the result so it can be retrieved with
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*/
|
|
|
|
static void send_mad_capabilities(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
struct viosrp_capabilities *req;
|
|
|
|
struct srp_event_struct *evt_struct;
|
|
|
|
unsigned long flags;
|
2010-04-14 07:12:29 +08:00
|
|
|
struct device_node *of_node = hostdata->dev->of_node;
|
2009-06-09 05:19:08 +08:00
|
|
|
const char *location;
|
|
|
|
|
|
|
|
evt_struct = get_event_struct(&hostdata->pool);
|
|
|
|
BUG_ON(!evt_struct);
|
|
|
|
|
|
|
|
init_event_struct(evt_struct, capabilities_rsp,
|
|
|
|
VIOSRP_MAD_FORMAT, info_timeout);
|
|
|
|
|
|
|
|
req = &evt_struct->iu.mad.capabilities;
|
|
|
|
memset(req, 0, sizeof(*req));
|
|
|
|
|
2013-09-03 08:04:47 +08:00
|
|
|
hostdata->caps.flags = cpu_to_be32(CAP_LIST_SUPPORTED);
|
2009-06-09 05:19:08 +08:00
|
|
|
if (hostdata->client_migrated)
|
2013-09-03 08:04:47 +08:00
|
|
|
hostdata->caps.flags |= cpu_to_be32(CLIENT_MIGRATED);
|
2009-06-09 05:19:08 +08:00
|
|
|
|
|
|
|
strncpy(hostdata->caps.name, dev_name(&hostdata->host->shost_gendev),
|
|
|
|
sizeof(hostdata->caps.name));
|
|
|
|
hostdata->caps.name[sizeof(hostdata->caps.name) - 1] = '\0';
|
|
|
|
|
|
|
|
location = of_get_property(of_node, "ibm,loc-code", NULL);
|
|
|
|
location = location ? location : dev_name(hostdata->dev);
|
|
|
|
strncpy(hostdata->caps.loc, location, sizeof(hostdata->caps.loc));
|
|
|
|
hostdata->caps.loc[sizeof(hostdata->caps.loc) - 1] = '\0';
|
|
|
|
|
2013-09-03 08:04:47 +08:00
|
|
|
req->common.type = cpu_to_be32(VIOSRP_CAPABILITIES_TYPE);
|
|
|
|
req->buffer = cpu_to_be64(hostdata->caps_addr);
|
2009-06-09 05:19:08 +08:00
|
|
|
|
2013-09-03 08:04:47 +08:00
|
|
|
hostdata->caps.migration.common.cap_type =
|
|
|
|
cpu_to_be32(MIGRATION_CAPABILITIES);
|
|
|
|
hostdata->caps.migration.common.length =
|
|
|
|
cpu_to_be16(sizeof(hostdata->caps.migration));
|
|
|
|
hostdata->caps.migration.common.server_support =
|
|
|
|
cpu_to_be16(SERVER_SUPPORTS_CAP);
|
|
|
|
hostdata->caps.migration.ecl = cpu_to_be32(1);
|
2009-06-09 05:19:08 +08:00
|
|
|
|
|
|
|
if (client_reserve) {
|
2013-09-03 08:04:47 +08:00
|
|
|
hostdata->caps.reserve.common.cap_type =
|
|
|
|
cpu_to_be32(RESERVATION_CAPABILITIES);
|
|
|
|
hostdata->caps.reserve.common.length =
|
|
|
|
cpu_to_be16(sizeof(hostdata->caps.reserve));
|
|
|
|
hostdata->caps.reserve.common.server_support =
|
|
|
|
cpu_to_be16(SERVER_SUPPORTS_CAP);
|
|
|
|
hostdata->caps.reserve.type =
|
|
|
|
cpu_to_be32(CLIENT_RESERVE_SCSI_2);
|
|
|
|
req->common.length =
|
|
|
|
cpu_to_be16(sizeof(hostdata->caps));
|
2009-06-09 05:19:08 +08:00
|
|
|
} else
|
2013-09-03 08:04:47 +08:00
|
|
|
req->common.length = cpu_to_be16(sizeof(hostdata->caps) -
|
|
|
|
sizeof(hostdata->caps.reserve));
|
2009-06-09 05:19:08 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
|
|
|
if (ibmvscsi_send_srp_event(evt_struct, hostdata, info_timeout * 2))
|
|
|
|
dev_err(hostdata->dev, "couldn't send CAPABILITIES_REQ!\n");
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
};
|
|
|
|
|
2009-06-09 05:19:07 +08:00
|
|
|
/**
|
|
|
|
* fast_fail_rsp: - Handle response to MAD enable fast fail
|
|
|
|
* @evt_struct: srp_event_struct with the response
|
|
|
|
*
|
|
|
|
* Used as a "done" callback by when sending enable fast fail. Gets called
|
|
|
|
* by ibmvscsi_handle_crq()
|
|
|
|
*/
|
|
|
|
static void fast_fail_rsp(struct srp_event_struct *evt_struct)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
|
2013-09-03 08:04:47 +08:00
|
|
|
u16 status = be16_to_cpu(evt_struct->xfer_iu->mad.fast_fail.common.status);
|
2009-06-09 05:19:07 +08:00
|
|
|
|
|
|
|
if (status == VIOSRP_MAD_NOT_SUPPORTED)
|
|
|
|
dev_err(hostdata->dev, "fast_fail not supported in server\n");
|
|
|
|
else if (status == VIOSRP_MAD_FAILED)
|
|
|
|
dev_err(hostdata->dev, "fast_fail request failed\n");
|
|
|
|
else if (status != VIOSRP_MAD_SUCCESS)
|
|
|
|
dev_err(hostdata->dev, "error 0x%X enabling fast_fail\n", status);
|
|
|
|
|
2009-06-09 05:19:08 +08:00
|
|
|
send_mad_capabilities(hostdata);
|
2009-06-09 05:19:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* init_host - Start host initialization
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
* Returns zero if successful.
|
|
|
|
*/
|
|
|
|
static int enable_fast_fail(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
unsigned long flags;
|
|
|
|
struct viosrp_fast_fail *fast_fail_mad;
|
|
|
|
struct srp_event_struct *evt_struct;
|
|
|
|
|
2009-06-09 05:19:08 +08:00
|
|
|
if (!fast_fail) {
|
|
|
|
send_mad_capabilities(hostdata);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-09 05:19:07 +08:00
|
|
|
|
|
|
|
evt_struct = get_event_struct(&hostdata->pool);
|
|
|
|
BUG_ON(!evt_struct);
|
|
|
|
|
|
|
|
init_event_struct(evt_struct, fast_fail_rsp, VIOSRP_MAD_FORMAT, info_timeout);
|
|
|
|
|
|
|
|
fast_fail_mad = &evt_struct->iu.mad.fast_fail;
|
|
|
|
memset(fast_fail_mad, 0, sizeof(*fast_fail_mad));
|
2013-09-03 08:04:47 +08:00
|
|
|
fast_fail_mad->common.type = cpu_to_be32(VIOSRP_ENABLE_FAST_FAIL);
|
|
|
|
fast_fail_mad->common.length = cpu_to_be16(sizeof(*fast_fail_mad));
|
2009-06-09 05:19:07 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
|
|
|
rc = ibmvscsi_send_srp_event(evt_struct, hostdata, info_timeout * 2);
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* adapter_info_rsp: - Handle response to MAD adapter info request
|
|
|
|
* @evt_struct: srp_event_struct with the response
|
|
|
|
*
|
|
|
|
* Used as a "done" callback by when sending adapter_info. Gets called
|
|
|
|
* by ibmvscsi_handle_crq()
|
|
|
|
*/
|
|
|
|
static void adapter_info_rsp(struct srp_event_struct *evt_struct)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
|
|
|
|
|
|
|
|
if (evt_struct->xfer_iu->mad.adapter_info.common.status) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "error %d getting adapter info\n",
|
|
|
|
evt_struct->xfer_iu->mad.adapter_info.common.status);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_info(hostdata->dev, "host srp version: %s, "
|
|
|
|
"host partition %s (%d), OS %d, max io %u\n",
|
|
|
|
hostdata->madapter_info.srp_version,
|
|
|
|
hostdata->madapter_info.partition_name,
|
2013-09-03 08:04:47 +08:00
|
|
|
be32_to_cpu(hostdata->madapter_info.partition_number),
|
|
|
|
be32_to_cpu(hostdata->madapter_info.os_type),
|
|
|
|
be32_to_cpu(hostdata->madapter_info.port_max_txu[0]));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (hostdata->madapter_info.port_max_txu[0])
|
|
|
|
hostdata->host->max_sectors =
|
2013-09-03 08:04:47 +08:00
|
|
|
be32_to_cpu(hostdata->madapter_info.port_max_txu[0]) >> 9;
|
2005-09-13 23:09:02 +08:00
|
|
|
|
2016-02-11 09:32:24 +08:00
|
|
|
if (be32_to_cpu(hostdata->madapter_info.os_type) == SRP_MAD_OS_AIX &&
|
2005-09-13 23:09:02 +08:00
|
|
|
strcmp(hostdata->madapter_info.srp_version, "1.6a") <= 0) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "host (Ver. %s) doesn't support large transfers\n",
|
|
|
|
hostdata->madapter_info.srp_version);
|
|
|
|
dev_err(hostdata->dev, "limiting scatterlists to %d\n",
|
|
|
|
MAX_INDIRECT_BUFS);
|
2005-09-13 23:09:02 +08:00
|
|
|
hostdata->host->sg_tablesize = MAX_INDIRECT_BUFS;
|
|
|
|
}
|
2009-06-24 06:14:01 +08:00
|
|
|
|
2016-02-11 09:32:24 +08:00
|
|
|
if (be32_to_cpu(hostdata->madapter_info.os_type) == SRP_MAD_OS_AIX) {
|
2009-06-24 06:14:01 +08:00
|
|
|
enable_fast_fail(hostdata);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-06-09 05:19:04 +08:00
|
|
|
|
2009-06-24 06:14:01 +08:00
|
|
|
send_srp_login(hostdata);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_mad_adapter_info: - Sends the mad adapter info request
|
|
|
|
* and stores the result so it can be retrieved with
|
|
|
|
* sysfs. We COULD consider causing a failure if the
|
|
|
|
* returned SRP version doesn't match ours.
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
* Returns zero if successful.
|
|
|
|
*/
|
|
|
|
static void send_mad_adapter_info(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
struct viosrp_adapter_info *req;
|
|
|
|
struct srp_event_struct *evt_struct;
|
2007-06-14 06:12:33 +08:00
|
|
|
unsigned long flags;
|
2006-04-14 12:52:18 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
evt_struct = get_event_struct(&hostdata->pool);
|
2009-06-09 05:19:04 +08:00
|
|
|
BUG_ON(!evt_struct);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
init_event_struct(evt_struct,
|
|
|
|
adapter_info_rsp,
|
|
|
|
VIOSRP_MAD_FORMAT,
|
2009-06-09 05:19:03 +08:00
|
|
|
info_timeout);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
req = &evt_struct->iu.mad.adapter_info;
|
|
|
|
memset(req, 0x00, sizeof(*req));
|
|
|
|
|
2013-09-03 08:04:47 +08:00
|
|
|
req->common.type = cpu_to_be32(VIOSRP_ADAPTER_INFO_TYPE);
|
|
|
|
req->common.length = cpu_to_be16(sizeof(hostdata->madapter_info));
|
|
|
|
req->buffer = cpu_to_be64(hostdata->adapter_info_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-06-14 06:12:33 +08:00
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
2009-06-09 05:19:08 +08:00
|
|
|
if (ibmvscsi_send_srp_event(evt_struct, hostdata, info_timeout * 2))
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "couldn't send ADAPTER_INFO_REQ!\n");
|
2007-06-14 06:12:33 +08:00
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2009-06-09 05:19:04 +08:00
|
|
|
* init_adapter: Start virtual adapter initialization sequence
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2009-06-09 05:19:04 +08:00
|
|
|
*/
|
|
|
|
static void init_adapter(struct ibmvscsi_host_data *hostdata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
send_mad_adapter_info(hostdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sync_completion: Signal that a synchronous command has completed
|
|
|
|
* Note that after returning from this call, the evt_struct is freed.
|
|
|
|
* the caller waiting on this completion shouldn't touch the evt_struct
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
static void sync_completion(struct srp_event_struct *evt_struct)
|
|
|
|
{
|
|
|
|
/* copy the response back */
|
|
|
|
if (evt_struct->sync_srp)
|
|
|
|
*evt_struct->sync_srp = *evt_struct->xfer_iu;
|
|
|
|
|
|
|
|
complete(&evt_struct->comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_abort: Abort a command...from scsi host template
|
|
|
|
* send this over to the server and wait synchronously for the response
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
|
|
|
|
{
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct srp_tsk_mgmt *tsk_mgmt;
|
|
|
|
struct srp_event_struct *evt;
|
|
|
|
struct srp_event_struct *tmp_evt, *found_evt;
|
|
|
|
union viosrp_iu srp_rsp;
|
|
|
|
int rsp_rc;
|
2005-08-16 05:52:58 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 lun = lun_from_dev(cmd->device);
|
2007-11-12 23:00:23 +08:00
|
|
|
unsigned long wait_switch = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* First, find this command in our sent list so we can figure
|
|
|
|
* out the correct tag
|
|
|
|
*/
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
2007-11-12 23:00:23 +08:00
|
|
|
wait_switch = jiffies + (init_timeout * HZ);
|
|
|
|
do {
|
|
|
|
found_evt = NULL;
|
|
|
|
list_for_each_entry(tmp_evt, &hostdata->sent, list) {
|
|
|
|
if (tmp_evt->cmnd == cmd) {
|
|
|
|
found_evt = tmp_evt;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
if (!found_evt) {
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
evt = get_event_struct(&hostdata->pool);
|
|
|
|
if (evt == NULL) {
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
sdev_printk(KERN_ERR, cmd->device,
|
|
|
|
"failed to allocate abort event\n");
|
|
|
|
return FAILED;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
init_event_struct(evt,
|
|
|
|
sync_completion,
|
|
|
|
VIOSRP_SRP_FORMAT,
|
2009-06-09 05:19:03 +08:00
|
|
|
abort_timeout);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
tsk_mgmt = &evt->iu.srp.tsk_mgmt;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
/* Set up an abort SRP command */
|
|
|
|
memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt));
|
|
|
|
tsk_mgmt->opcode = SRP_TSK_MGMT;
|
2015-05-18 19:27:14 +08:00
|
|
|
int_to_scsilun(lun, &tsk_mgmt->lun);
|
2007-11-12 23:00:23 +08:00
|
|
|
tsk_mgmt->tsk_mgmt_func = SRP_TSK_ABORT_TASK;
|
|
|
|
tsk_mgmt->task_tag = (u64) found_evt;
|
|
|
|
|
|
|
|
evt->sync_srp = &srp_rsp;
|
|
|
|
|
|
|
|
init_completion(&evt->comp);
|
2009-06-09 05:19:03 +08:00
|
|
|
rsp_rc = ibmvscsi_send_srp_event(evt, hostdata, abort_timeout * 2);
|
2007-11-12 23:00:23 +08:00
|
|
|
|
|
|
|
if (rsp_rc != SCSI_MLQUEUE_HOST_BUSY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
msleep(10);
|
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
|
|
|
} while (time_before(jiffies, wait_switch));
|
|
|
|
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
2007-11-12 23:00:23 +08:00
|
|
|
|
2005-08-16 05:52:58 +08:00
|
|
|
if (rsp_rc != 0) {
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_ERR, cmd->device,
|
|
|
|
"failed to send abort() event. rc=%d\n", rsp_rc);
|
2005-04-17 06:20:36 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
sdev_printk(KERN_INFO, cmd->device,
|
2009-01-06 22:26:03 +08:00
|
|
|
"aborting command. lun 0x%llx, tag 0x%llx\n",
|
2007-11-12 23:00:23 +08:00
|
|
|
(((u64) lun) << 48), (u64) found_evt);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
wait_for_completion(&evt->comp);
|
|
|
|
|
|
|
|
/* make sure we got a good response */
|
2006-03-26 02:57:14 +08:00
|
|
|
if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (printk_ratelimit())
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_WARNING, cmd->device, "abort bad SRP RSP type %d\n",
|
|
|
|
srp_rsp.srp.rsp.opcode);
|
2005-04-17 06:20:36 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2006-03-26 02:57:14 +08:00
|
|
|
if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID)
|
|
|
|
rsp_rc = *((int *)srp_rsp.srp.rsp.data);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
rsp_rc = srp_rsp.srp.rsp.status;
|
|
|
|
|
|
|
|
if (rsp_rc) {
|
|
|
|
if (printk_ratelimit())
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_WARNING, cmd->device,
|
2009-01-06 22:26:03 +08:00
|
|
|
"abort code %d for task tag 0x%llx\n",
|
2007-06-14 06:12:19 +08:00
|
|
|
rsp_rc, tsk_mgmt->task_tag);
|
2005-04-17 06:20:36 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Because we dropped the spinlock above, it's possible
|
|
|
|
* The event is no longer in our list. Make sure it didn't
|
|
|
|
* complete while we were aborting
|
|
|
|
*/
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
found_evt = NULL;
|
|
|
|
list_for_each_entry(tmp_evt, &hostdata->sent, list) {
|
|
|
|
if (tmp_evt->cmnd == cmd) {
|
|
|
|
found_evt = tmp_evt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_evt == NULL) {
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
2009-01-06 22:26:03 +08:00
|
|
|
sdev_printk(KERN_INFO, cmd->device, "aborted task tag 0x%llx completed\n",
|
2007-06-14 06:12:19 +08:00
|
|
|
tsk_mgmt->task_tag);
|
2005-04-17 06:20:36 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-01-06 22:26:03 +08:00
|
|
|
sdev_printk(KERN_INFO, cmd->device, "successfully aborted task tag 0x%llx\n",
|
2007-06-14 06:12:19 +08:00
|
|
|
tsk_mgmt->task_tag);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cmd->result = (DID_ABORT << 16);
|
|
|
|
list_del(&found_evt->list);
|
2005-09-07 06:11:54 +08:00
|
|
|
unmap_cmd_data(&found_evt->iu.srp.cmd, found_evt,
|
|
|
|
found_evt->hostdata->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
free_event_struct(&found_evt->hostdata->pool, found_evt);
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_inc(&hostdata->request_limit);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_eh_device_reset_handler: Reset a single LUN...from scsi host
|
|
|
|
* template send this over to the server and wait synchronously for the
|
|
|
|
* response
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
|
|
|
|
{
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct srp_tsk_mgmt *tsk_mgmt;
|
|
|
|
struct srp_event_struct *evt;
|
|
|
|
struct srp_event_struct *tmp_evt, *pos;
|
|
|
|
union viosrp_iu srp_rsp;
|
|
|
|
int rsp_rc;
|
2005-08-16 05:52:58 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 lun = lun_from_dev(cmd->device);
|
2007-11-12 23:00:23 +08:00
|
|
|
unsigned long wait_switch = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
2007-11-12 23:00:23 +08:00
|
|
|
wait_switch = jiffies + (init_timeout * HZ);
|
|
|
|
do {
|
|
|
|
evt = get_event_struct(&hostdata->pool);
|
|
|
|
if (evt == NULL) {
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
sdev_printk(KERN_ERR, cmd->device,
|
|
|
|
"failed to allocate reset event\n");
|
|
|
|
return FAILED;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
init_event_struct(evt,
|
|
|
|
sync_completion,
|
|
|
|
VIOSRP_SRP_FORMAT,
|
2009-06-09 05:19:03 +08:00
|
|
|
reset_timeout);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
tsk_mgmt = &evt->iu.srp.tsk_mgmt;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
/* Set up a lun reset SRP command */
|
|
|
|
memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt));
|
|
|
|
tsk_mgmt->opcode = SRP_TSK_MGMT;
|
2015-05-18 19:27:14 +08:00
|
|
|
int_to_scsilun(lun, &tsk_mgmt->lun);
|
2007-11-12 23:00:23 +08:00
|
|
|
tsk_mgmt->tsk_mgmt_func = SRP_TSK_LUN_RESET;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-12 23:00:23 +08:00
|
|
|
evt->sync_srp = &srp_rsp;
|
|
|
|
|
|
|
|
init_completion(&evt->comp);
|
2009-06-09 05:19:03 +08:00
|
|
|
rsp_rc = ibmvscsi_send_srp_event(evt, hostdata, reset_timeout * 2);
|
2007-11-12 23:00:23 +08:00
|
|
|
|
|
|
|
if (rsp_rc != SCSI_MLQUEUE_HOST_BUSY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
|
|
|
msleep(10);
|
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
|
|
|
} while (time_before(jiffies, wait_switch));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
2007-11-12 23:00:23 +08:00
|
|
|
|
2005-08-16 05:52:58 +08:00
|
|
|
if (rsp_rc != 0) {
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_ERR, cmd->device,
|
|
|
|
"failed to send reset event. rc=%d\n", rsp_rc);
|
2005-04-17 06:20:36 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2009-01-06 22:26:03 +08:00
|
|
|
sdev_printk(KERN_INFO, cmd->device, "resetting device. lun 0x%llx\n",
|
2007-11-12 23:00:23 +08:00
|
|
|
(((u64) lun) << 48));
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
wait_for_completion(&evt->comp);
|
|
|
|
|
|
|
|
/* make sure we got a good response */
|
2006-03-26 02:57:14 +08:00
|
|
|
if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (printk_ratelimit())
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_WARNING, cmd->device, "reset bad SRP RSP type %d\n",
|
|
|
|
srp_rsp.srp.rsp.opcode);
|
2005-04-17 06:20:36 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2006-03-26 02:57:14 +08:00
|
|
|
if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID)
|
|
|
|
rsp_rc = *((int *)srp_rsp.srp.rsp.data);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
rsp_rc = srp_rsp.srp.rsp.status;
|
|
|
|
|
|
|
|
if (rsp_rc) {
|
|
|
|
if (printk_ratelimit())
|
2007-06-14 06:12:19 +08:00
|
|
|
sdev_printk(KERN_WARNING, cmd->device,
|
2009-01-06 22:26:03 +08:00
|
|
|
"reset code %d for task tag 0x%llx\n",
|
2007-06-14 06:12:19 +08:00
|
|
|
rsp_rc, tsk_mgmt->task_tag);
|
2005-04-17 06:20:36 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to find all commands for this LUN that have not yet been
|
|
|
|
* responded to, and fail them with DID_RESET
|
|
|
|
*/
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_lock_irqsave(hostdata->host->host_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) {
|
|
|
|
if ((tmp_evt->cmnd) && (tmp_evt->cmnd->device == cmd->device)) {
|
|
|
|
if (tmp_evt->cmnd)
|
|
|
|
tmp_evt->cmnd->result = (DID_RESET << 16);
|
|
|
|
list_del(&tmp_evt->list);
|
2005-09-07 06:11:54 +08:00
|
|
|
unmap_cmd_data(&tmp_evt->iu.srp.cmd, tmp_evt,
|
|
|
|
tmp_evt->hostdata->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
free_event_struct(&tmp_evt->hostdata->pool,
|
|
|
|
tmp_evt);
|
|
|
|
atomic_inc(&hostdata->request_limit);
|
|
|
|
if (tmp_evt->cmnd_done)
|
|
|
|
tmp_evt->cmnd_done(tmp_evt->cmnd);
|
|
|
|
else if (tmp_evt->done)
|
|
|
|
tmp_evt->done(tmp_evt);
|
|
|
|
}
|
|
|
|
}
|
2005-08-16 05:52:58 +08:00
|
|
|
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-14 06:12:26 +08:00
|
|
|
* ibmvscsi_eh_host_reset_handler - Reset the connection to the server
|
|
|
|
* @cmd: struct scsi_cmnd having problems
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_eh_host_reset_handler(struct scsi_cmnd *cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-06-14 06:12:26 +08:00
|
|
|
unsigned long wait_switch = 0;
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-06-14 06:12:26 +08:00
|
|
|
dev_err(hostdata->dev, "Resetting connection due to error recovery\n");
|
|
|
|
|
|
|
|
ibmvscsi_reset_host(hostdata);
|
|
|
|
|
|
|
|
for (wait_switch = jiffies + (init_timeout * HZ);
|
|
|
|
time_before(jiffies, wait_switch) &&
|
|
|
|
atomic_read(&hostdata->request_limit) < 2;) {
|
|
|
|
|
|
|
|
msleep(10);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-06-14 06:12:26 +08:00
|
|
|
|
|
|
|
if (atomic_read(&hostdata->request_limit) <= 0)
|
|
|
|
return FAILED;
|
|
|
|
|
|
|
|
return SUCCESS;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ibmvscsi_handle_crq: - Handles and frees received events in the CRQ
|
|
|
|
* @crq: Command/Response queue
|
|
|
|
* @hostdata: ibmvscsi_host_data of host
|
|
|
|
*
|
|
|
|
*/
|
2012-07-30 09:32:26 +08:00
|
|
|
static void ibmvscsi_handle_crq(struct viosrp_crq *crq,
|
|
|
|
struct ibmvscsi_host_data *hostdata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-06-14 06:12:19 +08:00
|
|
|
long rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
2013-09-03 08:04:47 +08:00
|
|
|
/* The hypervisor copies our tag value here so no byteswapping */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct srp_event_struct *evt_struct =
|
2013-09-03 08:04:47 +08:00
|
|
|
(__force struct srp_event_struct *)crq->IU_data_ptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (crq->valid) {
|
2016-02-11 09:32:23 +08:00
|
|
|
case VIOSRP_CRQ_INIT_RSP: /* initialization */
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (crq->format) {
|
2016-02-11 09:32:23 +08:00
|
|
|
case VIOSRP_CRQ_INIT: /* Initialization message */
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_info(hostdata->dev, "partner initialized\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Send back a response */
|
2012-07-30 09:32:26 +08:00
|
|
|
rc = ibmvscsi_send_crq(hostdata, 0xC002000000000000LL, 0);
|
|
|
|
if (rc == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Now login */
|
2009-06-09 05:19:04 +08:00
|
|
|
init_adapter(hostdata);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "Unable to send init rsp. rc=%ld\n", rc);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2016-02-11 09:32:23 +08:00
|
|
|
case VIOSRP_CRQ_INIT_COMPLETE: /* Initialization response */
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_info(hostdata->dev, "partner initialization complete\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Now login */
|
2009-06-09 05:19:04 +08:00
|
|
|
init_adapter(hostdata);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "unknown crq message type: %d\n", crq->format);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return;
|
2016-02-11 09:32:23 +08:00
|
|
|
case VIOSRP_CRQ_XPORT_EVENT: /* Hypervisor telling us the connection is closed */
|
2006-01-20 03:34:44 +08:00
|
|
|
scsi_block_requests(hostdata->host);
|
2006-06-13 10:22:51 +08:00
|
|
|
atomic_set(&hostdata->request_limit, 0);
|
2006-01-20 03:34:44 +08:00
|
|
|
if (crq->format == 0x06) {
|
|
|
|
/* We need to re-setup the interpartition connection */
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_info(hostdata->dev, "Re-enabling adapter!\n");
|
2009-06-09 05:19:08 +08:00
|
|
|
hostdata->client_migrated = 1;
|
2010-06-18 02:56:00 +08:00
|
|
|
hostdata->reenable_crq = 1;
|
2006-01-20 03:34:44 +08:00
|
|
|
purge_requests(hostdata, DID_REQUEUE);
|
2010-06-18 02:56:00 +08:00
|
|
|
wake_up(&hostdata->work_wait_q);
|
2006-01-20 03:34:44 +08:00
|
|
|
} else {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "Virtual adapter failed rc %d!\n",
|
|
|
|
crq->format);
|
2010-06-18 02:56:00 +08:00
|
|
|
ibmvscsi_reset_host(hostdata);
|
2006-01-20 03:34:44 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2016-02-11 09:32:23 +08:00
|
|
|
case VIOSRP_CRQ_CMD_RSP: /* real payload */
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "got an invalid message type 0x%02x\n",
|
|
|
|
crq->valid);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The only kind of payload CRQs we should get are responses to
|
|
|
|
* things we send. Make sure this response is to something we
|
|
|
|
* actually sent
|
|
|
|
*/
|
|
|
|
if (!valid_event_struct(&hostdata->pool, evt_struct)) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "returned correlation_token 0x%p is invalid!\n",
|
2013-09-03 08:04:47 +08:00
|
|
|
evt_struct);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atomic_read(&evt_struct->free)) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "received duplicate correlation_token 0x%p!\n",
|
2013-09-03 08:04:47 +08:00
|
|
|
evt_struct);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crq->format == VIOSRP_SRP_FORMAT)
|
2013-09-03 08:04:47 +08:00
|
|
|
atomic_add(be32_to_cpu(evt_struct->xfer_iu->srp.rsp.req_lim_delta),
|
2005-04-17 06:20:36 +08:00
|
|
|
&hostdata->request_limit);
|
|
|
|
|
2007-06-14 06:12:26 +08:00
|
|
|
del_timer(&evt_struct->timer);
|
|
|
|
|
2008-05-19 23:27:56 +08:00
|
|
|
if ((crq->status != VIOSRP_OK && crq->status != VIOSRP_OK2) && evt_struct->cmnd)
|
2008-04-26 05:58:29 +08:00
|
|
|
evt_struct->cmnd->result = DID_ERROR << 16;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (evt_struct->done)
|
|
|
|
evt_struct->done(evt_struct);
|
|
|
|
else
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(hostdata->dev, "returned done() is NULL; not running it!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the host_lock before messing with these structures, since we
|
|
|
|
* are running in a task context
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(evt_struct->hostdata->host->host_lock, flags);
|
|
|
|
list_del(&evt_struct->list);
|
|
|
|
free_event_struct(&evt_struct->hostdata->pool, evt_struct);
|
|
|
|
spin_unlock_irqrestore(evt_struct->hostdata->host->host_lock, flags);
|
|
|
|
}
|
|
|
|
|
2007-03-30 01:30:40 +08:00
|
|
|
/**
|
|
|
|
* ibmvscsi_slave_configure: Set the "allow_restart" flag for each disk.
|
|
|
|
* @sdev: struct scsi_device device to configure
|
|
|
|
*
|
|
|
|
* Enable allow_restart for a device if it is a disk. Adjust the
|
|
|
|
* queue_depth here also as is required by the documentation for
|
|
|
|
* struct scsi_host_template.
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_slave_configure(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
struct Scsi_Host *shost = sdev->host;
|
|
|
|
unsigned long lock_flags = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, lock_flags);
|
2007-10-26 05:06:34 +08:00
|
|
|
if (sdev->type == TYPE_DISK) {
|
2007-03-30 01:30:40 +08:00
|
|
|
sdev->allow_restart = 1;
|
2009-06-09 05:19:03 +08:00
|
|
|
blk_queue_rq_timeout(sdev->request_queue, 120 * HZ);
|
2007-10-26 05:06:34 +08:00
|
|
|
}
|
2007-03-30 01:30:40 +08:00
|
|
|
spin_unlock_irqrestore(shost->host_lock, lock_flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-30 04:46:14 +08:00
|
|
|
/**
|
|
|
|
* ibmvscsi_change_queue_depth - Change the device's queue depth
|
|
|
|
* @sdev: scsi device struct
|
|
|
|
* @qdepth: depth to set
|
2009-10-16 08:46:39 +08:00
|
|
|
* @reason: calling context
|
2007-05-30 04:46:14 +08:00
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* actual depth set
|
|
|
|
**/
|
2014-11-13 22:08:42 +08:00
|
|
|
static int ibmvscsi_change_queue_depth(struct scsi_device *sdev, int qdepth)
|
2007-05-30 04:46:14 +08:00
|
|
|
{
|
|
|
|
if (qdepth > IBMVSCSI_MAX_CMDS_PER_LUN)
|
|
|
|
qdepth = IBMVSCSI_MAX_CMDS_PER_LUN;
|
2014-11-13 22:08:42 +08:00
|
|
|
return scsi_change_queue_depth(sdev, qdepth);
|
2007-05-30 04:46:14 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* sysfs attributes
|
|
|
|
*/
|
2009-06-09 05:19:08 +08:00
|
|
|
static ssize_t show_host_vhost_loc(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct Scsi_Host *shost = class_to_shost(dev);
|
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(shost);
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(buf, sizeof(hostdata->caps.loc), "%s\n",
|
|
|
|
hostdata->caps.loc);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_attribute ibmvscsi_host_vhost_loc = {
|
|
|
|
.attr = {
|
|
|
|
.name = "vhost_loc",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.show = show_host_vhost_loc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t show_host_vhost_name(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct Scsi_Host *shost = class_to_shost(dev);
|
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(shost);
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(buf, sizeof(hostdata->caps.name), "%s\n",
|
|
|
|
hostdata->caps.name);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_attribute ibmvscsi_host_vhost_name = {
|
|
|
|
.attr = {
|
|
|
|
.name = "vhost_name",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.show = show_host_vhost_name,
|
|
|
|
};
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static ssize_t show_host_srp_version(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-22 07:13:36 +08:00
|
|
|
struct Scsi_Host *shost = class_to_shost(dev);
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(shost);
|
2005-04-17 06:20:36 +08:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(buf, PAGE_SIZE, "%s\n",
|
|
|
|
hostdata->madapter_info.srp_version);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static struct device_attribute ibmvscsi_host_srp_version = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.attr = {
|
|
|
|
.name = "srp_version",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.show = show_host_srp_version,
|
|
|
|
};
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static ssize_t show_host_partition_name(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2005-04-17 06:20:36 +08:00
|
|
|
char *buf)
|
|
|
|
{
|
2008-02-22 07:13:36 +08:00
|
|
|
struct Scsi_Host *shost = class_to_shost(dev);
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(shost);
|
2005-04-17 06:20:36 +08:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(buf, PAGE_SIZE, "%s\n",
|
|
|
|
hostdata->madapter_info.partition_name);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static struct device_attribute ibmvscsi_host_partition_name = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.attr = {
|
|
|
|
.name = "partition_name",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.show = show_host_partition_name,
|
|
|
|
};
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static ssize_t show_host_partition_number(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2005-04-17 06:20:36 +08:00
|
|
|
char *buf)
|
|
|
|
{
|
2008-02-22 07:13:36 +08:00
|
|
|
struct Scsi_Host *shost = class_to_shost(dev);
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(shost);
|
2005-04-17 06:20:36 +08:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(buf, PAGE_SIZE, "%d\n",
|
2016-02-11 09:32:27 +08:00
|
|
|
be32_to_cpu(hostdata->madapter_info.partition_number));
|
2005-04-17 06:20:36 +08:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static struct device_attribute ibmvscsi_host_partition_number = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.attr = {
|
|
|
|
.name = "partition_number",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.show = show_host_partition_number,
|
|
|
|
};
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static ssize_t show_host_mad_version(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-22 07:13:36 +08:00
|
|
|
struct Scsi_Host *shost = class_to_shost(dev);
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(shost);
|
2005-04-17 06:20:36 +08:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(buf, PAGE_SIZE, "%d\n",
|
2016-02-11 09:32:27 +08:00
|
|
|
be32_to_cpu(hostdata->madapter_info.mad_version));
|
2005-04-17 06:20:36 +08:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static struct device_attribute ibmvscsi_host_mad_version = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.attr = {
|
|
|
|
.name = "mad_version",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.show = show_host_mad_version,
|
|
|
|
};
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static ssize_t show_host_os_type(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-22 07:13:36 +08:00
|
|
|
struct Scsi_Host *shost = class_to_shost(dev);
|
2007-07-23 08:28:40 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = shost_priv(shost);
|
2005-04-17 06:20:36 +08:00
|
|
|
int len;
|
|
|
|
|
2016-02-11 09:32:27 +08:00
|
|
|
len = snprintf(buf, PAGE_SIZE, "%d\n",
|
|
|
|
be32_to_cpu(hostdata->madapter_info.os_type));
|
2005-04-17 06:20:36 +08:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static struct device_attribute ibmvscsi_host_os_type = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.attr = {
|
|
|
|
.name = "os_type",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.show = show_host_os_type,
|
|
|
|
};
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static ssize_t show_host_config(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-02-11 09:32:26 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static struct device_attribute ibmvscsi_host_config = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.attr = {
|
2016-02-11 09:32:26 +08:00
|
|
|
.name = "config",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
.show = show_host_config,
|
|
|
|
};
|
|
|
|
|
2008-02-22 07:13:36 +08:00
|
|
|
static struct device_attribute *ibmvscsi_attrs[] = {
|
2009-06-09 05:19:08 +08:00
|
|
|
&ibmvscsi_host_vhost_loc,
|
|
|
|
&ibmvscsi_host_vhost_name,
|
2005-04-17 06:20:36 +08:00
|
|
|
&ibmvscsi_host_srp_version,
|
|
|
|
&ibmvscsi_host_partition_name,
|
|
|
|
&ibmvscsi_host_partition_number,
|
|
|
|
&ibmvscsi_host_mad_version,
|
|
|
|
&ibmvscsi_host_os_type,
|
|
|
|
&ibmvscsi_host_config,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* SCSI driver registration
|
|
|
|
*/
|
|
|
|
static struct scsi_host_template driver_template = {
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.name = "IBM POWER Virtual SCSI Adapter " IBMVSCSI_VERSION,
|
|
|
|
.proc_name = "ibmvscsi",
|
|
|
|
.queuecommand = ibmvscsi_queuecommand,
|
2017-01-30 20:18:58 +08:00
|
|
|
.eh_timed_out = srp_timed_out,
|
2005-04-17 06:20:36 +08:00
|
|
|
.eh_abort_handler = ibmvscsi_eh_abort_handler,
|
|
|
|
.eh_device_reset_handler = ibmvscsi_eh_device_reset_handler,
|
2007-06-14 06:12:26 +08:00
|
|
|
.eh_host_reset_handler = ibmvscsi_eh_host_reset_handler,
|
2007-03-30 01:30:40 +08:00
|
|
|
.slave_configure = ibmvscsi_slave_configure,
|
2007-05-30 04:46:14 +08:00
|
|
|
.change_queue_depth = ibmvscsi_change_queue_depth,
|
2008-07-24 02:35:27 +08:00
|
|
|
.cmd_per_lun = IBMVSCSI_CMDS_PER_LUN_DEFAULT,
|
2007-03-29 01:45:46 +08:00
|
|
|
.can_queue = IBMVSCSI_MAX_REQUESTS_DEFAULT,
|
2005-04-17 06:20:36 +08:00
|
|
|
.this_id = -1,
|
2005-09-07 06:11:54 +08:00
|
|
|
.sg_tablesize = SG_ALL,
|
2005-04-17 06:20:36 +08:00
|
|
|
.use_clustering = ENABLE_CLUSTERING,
|
|
|
|
.shost_attrs = ibmvscsi_attrs,
|
|
|
|
};
|
|
|
|
|
2008-07-24 02:35:27 +08:00
|
|
|
/**
|
|
|
|
* ibmvscsi_get_desired_dma - Calculate IO memory desired by the driver
|
|
|
|
*
|
|
|
|
* @vdev: struct vio_dev for the device whose desired IO mem is to be returned
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* Number of bytes of IO data the driver will need to perform well.
|
|
|
|
*/
|
|
|
|
static unsigned long ibmvscsi_get_desired_dma(struct vio_dev *vdev)
|
|
|
|
{
|
|
|
|
/* iu_storage data allocated in initialize_event_pool */
|
2008-12-18 07:19:33 +08:00
|
|
|
unsigned long desired_io = max_events * sizeof(union viosrp_iu);
|
2008-07-24 02:35:27 +08:00
|
|
|
|
|
|
|
/* add io space for sg data */
|
2008-08-15 23:48:47 +08:00
|
|
|
desired_io += (IBMVSCSI_MAX_SECTORS_DEFAULT * 512 *
|
2008-07-24 02:35:27 +08:00
|
|
|
IBMVSCSI_CMDS_PER_LUN_DEFAULT);
|
|
|
|
|
|
|
|
return desired_io;
|
|
|
|
}
|
|
|
|
|
2010-06-18 02:56:00 +08:00
|
|
|
static void ibmvscsi_do_work(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
char *action = "reset";
|
|
|
|
|
|
|
|
if (hostdata->reset_crq) {
|
|
|
|
smp_rmb();
|
|
|
|
hostdata->reset_crq = 0;
|
|
|
|
|
2012-07-30 09:32:26 +08:00
|
|
|
rc = ibmvscsi_reset_crq_queue(&hostdata->queue, hostdata);
|
2010-06-18 02:56:00 +08:00
|
|
|
if (!rc)
|
2012-07-30 09:32:26 +08:00
|
|
|
rc = ibmvscsi_send_crq(hostdata, 0xC001000000000000LL, 0);
|
2011-04-27 23:27:08 +08:00
|
|
|
vio_enable_interrupts(to_vio_dev(hostdata->dev));
|
2010-06-18 02:56:00 +08:00
|
|
|
} else if (hostdata->reenable_crq) {
|
|
|
|
smp_rmb();
|
|
|
|
action = "enable";
|
2012-07-30 09:32:26 +08:00
|
|
|
rc = ibmvscsi_reenable_crq_queue(&hostdata->queue, hostdata);
|
2010-06-18 02:56:00 +08:00
|
|
|
hostdata->reenable_crq = 0;
|
|
|
|
if (!rc)
|
2012-07-30 09:32:26 +08:00
|
|
|
rc = ibmvscsi_send_crq(hostdata, 0xC001000000000000LL, 0);
|
2010-06-18 02:56:00 +08:00
|
|
|
} else
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
atomic_set(&hostdata->request_limit, -1);
|
|
|
|
dev_err(hostdata->dev, "error after %s\n", action);
|
|
|
|
}
|
|
|
|
|
|
|
|
scsi_unblock_requests(hostdata->host);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ibmvscsi_work_to_do(struct ibmvscsi_host_data *hostdata)
|
|
|
|
{
|
|
|
|
if (kthread_should_stop())
|
|
|
|
return 1;
|
|
|
|
else if (hostdata->reset_crq) {
|
|
|
|
smp_rmb();
|
|
|
|
return 1;
|
|
|
|
} else if (hostdata->reenable_crq) {
|
|
|
|
smp_rmb();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ibmvscsi_work(void *data)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = data;
|
|
|
|
int rc;
|
|
|
|
|
2014-03-11 18:09:12 +08:00
|
|
|
set_user_nice(current, MIN_NICE);
|
2010-06-18 02:56:00 +08:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
rc = wait_event_interruptible(hostdata->work_wait_q,
|
|
|
|
ibmvscsi_work_to_do(hostdata));
|
|
|
|
|
|
|
|
BUG_ON(rc);
|
|
|
|
|
|
|
|
if (kthread_should_stop())
|
|
|
|
break;
|
|
|
|
|
|
|
|
ibmvscsi_do_work(hostdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* Called by bus code for each adapter
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata;
|
|
|
|
struct Scsi_Host *host;
|
|
|
|
struct device *dev = &vdev->dev;
|
2007-06-27 15:32:50 +08:00
|
|
|
struct srp_rport_identifiers ids;
|
|
|
|
struct srp_rport *rport;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long wait_switch = 0;
|
2006-06-13 10:22:51 +08:00
|
|
|
int rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-05 03:40:54 +08:00
|
|
|
dev_set_drvdata(&vdev->dev, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
host = scsi_host_alloc(&driver_template, sizeof(*hostdata));
|
|
|
|
if (!host) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(&vdev->dev, "couldn't allocate host data\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
goto scsi_host_alloc_failed;
|
|
|
|
}
|
|
|
|
|
2007-06-27 15:32:50 +08:00
|
|
|
host->transportt = ibmvscsi_transport_template;
|
2007-07-23 08:28:40 +08:00
|
|
|
hostdata = shost_priv(host);
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(hostdata, 0x00, sizeof(*hostdata));
|
|
|
|
INIT_LIST_HEAD(&hostdata->sent);
|
2010-06-18 02:56:00 +08:00
|
|
|
init_waitqueue_head(&hostdata->work_wait_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
hostdata->host = host;
|
|
|
|
hostdata->dev = dev;
|
|
|
|
atomic_set(&hostdata->request_limit, -1);
|
2008-07-24 02:35:27 +08:00
|
|
|
hostdata->host->max_sectors = IBMVSCSI_MAX_SECTORS_DEFAULT;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-09 05:19:08 +08:00
|
|
|
if (map_persist_bufs(hostdata)) {
|
|
|
|
dev_err(&vdev->dev, "couldn't map persistent buffers\n");
|
|
|
|
goto persist_bufs_failed;
|
|
|
|
}
|
|
|
|
|
2010-06-18 02:56:00 +08:00
|
|
|
hostdata->work_thread = kthread_run(ibmvscsi_work, hostdata, "%s_%d",
|
|
|
|
"ibmvscsi", host->host_no);
|
|
|
|
|
|
|
|
if (IS_ERR(hostdata->work_thread)) {
|
|
|
|
dev_err(&vdev->dev, "couldn't initialize kthread. rc=%ld\n",
|
|
|
|
PTR_ERR(hostdata->work_thread));
|
|
|
|
goto init_crq_failed;
|
|
|
|
}
|
|
|
|
|
2012-07-30 09:32:26 +08:00
|
|
|
rc = ibmvscsi_init_crq_queue(&hostdata->queue, hostdata, max_events);
|
2006-06-13 10:22:51 +08:00
|
|
|
if (rc != 0 && rc != H_RESOURCE) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(&vdev->dev, "couldn't initialize crq. rc=%d\n", rc);
|
2010-06-18 02:56:00 +08:00
|
|
|
goto kill_kthread;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-12-18 07:19:33 +08:00
|
|
|
if (initialize_event_pool(&hostdata->pool, max_events, hostdata) != 0) {
|
2007-06-14 06:12:19 +08:00
|
|
|
dev_err(&vdev->dev, "couldn't initialize event pool\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
goto init_pool_failed;
|
|
|
|
}
|
|
|
|
|
2015-11-10 00:49:09 +08:00
|
|
|
host->max_lun = IBMVSCSI_MAX_LUN;
|
2005-04-17 06:20:36 +08:00
|
|
|
host->max_id = max_id;
|
|
|
|
host->max_channel = max_channel;
|
2009-06-09 05:19:01 +08:00
|
|
|
host->max_cmd_len = 16;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-11-10 00:49:08 +08:00
|
|
|
dev_info(dev,
|
|
|
|
"Maximum ID: %d Maximum LUN: %llu Maximum Channel: %d\n",
|
|
|
|
host->max_id, host->max_lun, host->max_channel);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (scsi_add_host(hostdata->host, hostdata->dev))
|
|
|
|
goto add_host_failed;
|
|
|
|
|
2007-06-27 15:32:50 +08:00
|
|
|
/* we don't have a proper target_port_id so let's use the fake one */
|
|
|
|
memcpy(ids.port_id, hostdata->madapter_info.partition_name,
|
|
|
|
sizeof(ids.port_id));
|
2007-07-11 14:08:15 +08:00
|
|
|
ids.roles = SRP_RPORT_ROLE_TARGET;
|
2007-06-27 15:32:50 +08:00
|
|
|
rport = srp_rport_add(host, &ids);
|
|
|
|
if (IS_ERR(rport))
|
|
|
|
goto add_srp_port_failed;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Try to send an initialization message. Note that this is allowed
|
|
|
|
* to fail if the other end is not acive. In that case we don't
|
|
|
|
* want to scan
|
|
|
|
*/
|
2012-07-30 09:32:26 +08:00
|
|
|
if (ibmvscsi_send_crq(hostdata, 0xC001000000000000LL, 0) == 0
|
2006-06-13 10:22:51 +08:00
|
|
|
|| rc == H_RESOURCE) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Wait around max init_timeout secs for the adapter to finish
|
|
|
|
* initializing. When we are done initializing, we will have a
|
|
|
|
* valid request_limit. We don't want Linux scanning before
|
|
|
|
* we are ready.
|
|
|
|
*/
|
|
|
|
for (wait_switch = jiffies + (init_timeout * HZ);
|
|
|
|
time_before(jiffies, wait_switch) &&
|
|
|
|
atomic_read(&hostdata->request_limit) < 2;) {
|
|
|
|
|
|
|
|
msleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we now have a valid request_limit, initiate a scan */
|
|
|
|
if (atomic_read(&hostdata->request_limit) > 0)
|
|
|
|
scsi_scan_host(host);
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:40:54 +08:00
|
|
|
dev_set_drvdata(&vdev->dev, hostdata);
|
2016-12-08 06:04:35 +08:00
|
|
|
list_add_tail(&hostdata->host_list, &ibmvscsi_head);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
2007-06-27 15:32:50 +08:00
|
|
|
add_srp_port_failed:
|
|
|
|
scsi_remove_host(hostdata->host);
|
2005-04-17 06:20:36 +08:00
|
|
|
add_host_failed:
|
|
|
|
release_event_pool(&hostdata->pool, hostdata);
|
|
|
|
init_pool_failed:
|
2012-07-30 09:32:26 +08:00
|
|
|
ibmvscsi_release_crq_queue(&hostdata->queue, hostdata, max_events);
|
2010-06-18 02:56:00 +08:00
|
|
|
kill_kthread:
|
|
|
|
kthread_stop(hostdata->work_thread);
|
2005-04-17 06:20:36 +08:00
|
|
|
init_crq_failed:
|
2009-06-09 05:19:08 +08:00
|
|
|
unmap_persist_bufs(hostdata);
|
|
|
|
persist_bufs_failed:
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_host_put(host);
|
|
|
|
scsi_host_alloc_failed:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ibmvscsi_remove(struct vio_dev *vdev)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct ibmvscsi_host_data *hostdata = dev_get_drvdata(&vdev->dev);
|
2016-12-08 06:04:35 +08:00
|
|
|
list_del(&hostdata->host_list);
|
2009-06-09 05:19:08 +08:00
|
|
|
unmap_persist_bufs(hostdata);
|
2005-04-17 06:20:36 +08:00
|
|
|
release_event_pool(&hostdata->pool, hostdata);
|
2012-07-30 09:32:26 +08:00
|
|
|
ibmvscsi_release_crq_queue(&hostdata->queue, hostdata,
|
2008-12-18 07:19:33 +08:00
|
|
|
max_events);
|
2007-06-27 15:32:50 +08:00
|
|
|
|
2010-06-18 02:56:00 +08:00
|
|
|
kthread_stop(hostdata->work_thread);
|
2007-06-27 15:32:50 +08:00
|
|
|
srp_remove_host(hostdata->host);
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_remove_host(hostdata->host);
|
|
|
|
scsi_host_put(hostdata->host);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-22 00:37:57 +08:00
|
|
|
/**
|
|
|
|
* ibmvscsi_resume: Resume from suspend
|
|
|
|
* @dev: device struct
|
|
|
|
*
|
|
|
|
* We may have lost an interrupt across suspend/resume, so kick the
|
|
|
|
* interrupt handler
|
|
|
|
*/
|
|
|
|
static int ibmvscsi_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct ibmvscsi_host_data *hostdata = dev_get_drvdata(dev);
|
2012-07-30 09:32:26 +08:00
|
|
|
vio_disable_interrupts(to_vio_dev(hostdata->dev));
|
|
|
|
tasklet_schedule(&hostdata->srp_task);
|
|
|
|
|
|
|
|
return 0;
|
2010-02-22 00:37:57 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* ibmvscsi_device_table: Used by vio.c to match devices in the device tree we
|
|
|
|
* support.
|
|
|
|
*/
|
2012-12-22 05:08:55 +08:00
|
|
|
static struct vio_device_id ibmvscsi_device_table[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{"vscsi", "IBM,v-scsi"},
|
2005-08-17 14:42:59 +08:00
|
|
|
{ "", "" }
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
|
2005-10-24 13:12:22 +08:00
|
|
|
|
2010-02-22 00:37:57 +08:00
|
|
|
static struct dev_pm_ops ibmvscsi_pm_ops = {
|
|
|
|
.resume = ibmvscsi_resume
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct vio_driver ibmvscsi_driver = {
|
|
|
|
.id_table = ibmvscsi_device_table,
|
|
|
|
.probe = ibmvscsi_probe,
|
2005-10-24 12:53:21 +08:00
|
|
|
.remove = ibmvscsi_remove,
|
2008-07-24 02:35:27 +08:00
|
|
|
.get_desired_dma = ibmvscsi_get_desired_dma,
|
2012-03-27 03:06:30 +08:00
|
|
|
.name = "ibmvscsi",
|
|
|
|
.pm = &ibmvscsi_pm_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-06-27 15:32:50 +08:00
|
|
|
static struct srp_function_template ibmvscsi_transport_functions = {
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int __init ibmvscsi_module_init(void)
|
|
|
|
{
|
2007-06-27 15:32:50 +08:00
|
|
|
int ret;
|
|
|
|
|
2008-12-18 07:19:33 +08:00
|
|
|
/* Ensure we have two requests to do error recovery */
|
|
|
|
driver_template.can_queue = max_requests;
|
|
|
|
max_events = max_requests + 2;
|
|
|
|
|
2012-07-30 09:32:26 +08:00
|
|
|
if (!firmware_has_feature(FW_FEATURE_VIO))
|
2007-09-22 06:29:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2007-06-27 15:32:50 +08:00
|
|
|
ibmvscsi_transport_template =
|
|
|
|
srp_attach_transport(&ibmvscsi_transport_functions);
|
|
|
|
if (!ibmvscsi_transport_template)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = vio_register_driver(&ibmvscsi_driver);
|
|
|
|
if (ret)
|
|
|
|
srp_release_transport(ibmvscsi_transport_template);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __exit ibmvscsi_module_exit(void)
|
|
|
|
{
|
|
|
|
vio_unregister_driver(&ibmvscsi_driver);
|
2007-06-27 15:32:50 +08:00
|
|
|
srp_release_transport(ibmvscsi_transport_template);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ibmvscsi_module_init);
|
|
|
|
module_exit(ibmvscsi_module_exit);
|