2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-10-24 16:30:34 +08:00
|
|
|
* Disk Array driver for HP Smart Array controllers, SCSI Tape module.
|
|
|
|
* (C) Copyright 2001, 2007 Hewlett-Packard Development Company, L.P.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* 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
|
2007-10-24 16:30:34 +08:00
|
|
|
* the Free Software Foundation; version 2 of the License.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-24 16:30:34 +08:00
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2007-10-24 16:30:34 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 300, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Questions/Comments/Bugfixes to iss_storagedev@hp.com
|
|
|
|
*
|
|
|
|
* Author: Stephen M. Cameron
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_CISS_SCSI_TAPE
|
|
|
|
|
|
|
|
/* Here we have code to present the driver as a scsi driver
|
|
|
|
as it is simultaneously presented as a block driver. The
|
|
|
|
reason for doing this is to allow access to SCSI tape drives
|
|
|
|
through the array controller. Note in particular, neither
|
|
|
|
physical nor logical disks are presented through the scsi layer. */
|
|
|
|
|
2005-10-31 07:03:48 +08:00
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2005-10-31 07:03:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
|
|
|
|
#include "cciss_scsi.h"
|
|
|
|
|
2005-11-05 02:30:37 +08:00
|
|
|
#define CCISS_ABORT_MSG 0x00
|
|
|
|
#define CCISS_RESET_MSG 0x01
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
static int fill_cmd(ctlr_info_t *h, CommandList_struct *c, __u8 cmd, void *buff,
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
size_t size,
|
2009-06-09 05:02:17 +08:00
|
|
|
__u8 page_code, unsigned char *scsi3addr,
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
int cmd_type);
|
|
|
|
|
2010-07-20 02:46:43 +08:00
|
|
|
static CommandList_struct *cmd_alloc(ctlr_info_t *h);
|
|
|
|
static CommandList_struct *cmd_special_alloc(ctlr_info_t *h);
|
|
|
|
static void cmd_free(ctlr_info_t *h, CommandList_struct *c);
|
|
|
|
static void cmd_special_free(ctlr_info_t *h, CommandList_struct *c);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int cciss_scsi_proc_info(
|
|
|
|
struct Scsi_Host *sh,
|
|
|
|
char *buffer, /* data buffer */
|
|
|
|
char **start, /* where data in buffer starts */
|
|
|
|
off_t offset, /* offset from start of imaginary file */
|
|
|
|
int length, /* length of data in buffer */
|
|
|
|
int func); /* 0 == read, 1 == write */
|
|
|
|
|
2010-11-16 15:10:29 +08:00
|
|
|
static int cciss_scsi_queue_command (struct Scsi_Host *h,
|
|
|
|
struct scsi_cmnd *cmd);
|
2005-11-05 02:30:37 +08:00
|
|
|
static int cciss_eh_device_reset_handler(struct scsi_cmnd *);
|
|
|
|
static int cciss_eh_abort_handler(struct scsi_cmnd *);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct cciss_scsi_hba_t ccissscsi[MAX_CTLR] = {
|
|
|
|
{ .name = "cciss0", .ndevices = 0 },
|
|
|
|
{ .name = "cciss1", .ndevices = 0 },
|
|
|
|
{ .name = "cciss2", .ndevices = 0 },
|
|
|
|
{ .name = "cciss3", .ndevices = 0 },
|
|
|
|
{ .name = "cciss4", .ndevices = 0 },
|
|
|
|
{ .name = "cciss5", .ndevices = 0 },
|
|
|
|
{ .name = "cciss6", .ndevices = 0 },
|
|
|
|
{ .name = "cciss7", .ndevices = 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct scsi_host_template cciss_driver_template = {
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.name = "cciss",
|
|
|
|
.proc_name = "cciss",
|
|
|
|
.proc_info = cciss_scsi_proc_info,
|
|
|
|
.queuecommand = cciss_scsi_queue_command,
|
|
|
|
.this_id = 7,
|
|
|
|
.cmd_per_lun = 1,
|
|
|
|
.use_clustering = DISABLE_CLUSTERING,
|
2005-11-05 02:30:37 +08:00
|
|
|
/* Can't have eh_bus_reset_handler or eh_host_reset_handler for cciss */
|
|
|
|
.eh_device_reset_handler= cciss_eh_device_reset_handler,
|
|
|
|
.eh_abort_handler = cciss_eh_abort_handler,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(1)
|
2010-02-27 06:01:17 +08:00
|
|
|
|
2010-06-03 03:58:06 +08:00
|
|
|
#define SCSI_PAD_32 8
|
|
|
|
#define SCSI_PAD_64 8
|
2010-02-27 06:01:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cciss_scsi_cmd_stack_elem_t {
|
|
|
|
CommandList_struct cmd;
|
|
|
|
ErrorInfo_struct Err;
|
|
|
|
__u32 busaddr;
|
2010-02-27 06:01:53 +08:00
|
|
|
int cmdindex;
|
2010-02-27 06:01:17 +08:00
|
|
|
u8 pad[IS_32_BIT * SCSI_PAD_32 + IS_64_BIT * SCSI_PAD_64];
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
#pragma pack(1)
|
|
|
|
struct cciss_scsi_cmd_stack_t {
|
|
|
|
struct cciss_scsi_cmd_stack_elem_t *pool;
|
2011-05-04 03:54:12 +08:00
|
|
|
struct cciss_scsi_cmd_stack_elem_t **elem;
|
2005-04-17 06:20:36 +08:00
|
|
|
dma_addr_t cmd_pool_handle;
|
|
|
|
int top;
|
2011-05-04 03:54:12 +08:00
|
|
|
int nelems;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
struct cciss_scsi_adapter_data_t {
|
|
|
|
struct Scsi_Host *scsi_host;
|
|
|
|
struct cciss_scsi_cmd_stack_t cmd_stack;
|
2010-02-27 06:01:53 +08:00
|
|
|
SGDescriptor_struct **cmd_sg_list;
|
2005-04-17 06:20:36 +08:00
|
|
|
int registered;
|
|
|
|
spinlock_t lock; // to protect ccissscsi[ctlr];
|
|
|
|
};
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
#define CPQ_TAPE_LOCK(h, flags) spin_lock_irqsave( \
|
|
|
|
&h->scsi_ctlr->lock, flags);
|
|
|
|
#define CPQ_TAPE_UNLOCK(h, flags) spin_unlock_irqrestore( \
|
|
|
|
&h->scsi_ctlr->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static CommandList_struct *
|
|
|
|
scsi_cmd_alloc(ctlr_info_t *h)
|
|
|
|
{
|
|
|
|
/* assume only one process in here at a time, locking done by caller. */
|
2010-07-20 02:46:38 +08:00
|
|
|
/* use h->lock */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* might be better to rewrite how we allocate scsi commands in a way that */
|
|
|
|
/* needs no locking at all. */
|
|
|
|
|
|
|
|
/* take the top memory chunk off the stack and return it, if any. */
|
|
|
|
struct cciss_scsi_cmd_stack_elem_t *c;
|
|
|
|
struct cciss_scsi_adapter_data_t *sa;
|
|
|
|
struct cciss_scsi_cmd_stack_t *stk;
|
|
|
|
u64bit temp64;
|
|
|
|
|
2010-02-27 06:01:42 +08:00
|
|
|
sa = h->scsi_ctlr;
|
2005-04-17 06:20:36 +08:00
|
|
|
stk = &sa->cmd_stack;
|
|
|
|
|
|
|
|
if (stk->top < 0)
|
|
|
|
return NULL;
|
|
|
|
c = stk->elem[stk->top];
|
|
|
|
/* memset(c, 0, sizeof(*c)); */
|
|
|
|
memset(&c->cmd, 0, sizeof(c->cmd));
|
|
|
|
memset(&c->Err, 0, sizeof(c->Err));
|
|
|
|
/* set physical addr of cmd and addr of scsi parameters */
|
|
|
|
c->cmd.busaddr = c->busaddr;
|
2010-02-27 06:01:53 +08:00
|
|
|
c->cmd.cmdindex = c->cmdindex;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* (__u32) (stk->cmd_pool_handle +
|
|
|
|
(sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top)); */
|
|
|
|
|
|
|
|
temp64.val = (__u64) (c->busaddr + sizeof(CommandList_struct));
|
|
|
|
/* (__u64) (stk->cmd_pool_handle +
|
|
|
|
(sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top) +
|
|
|
|
sizeof(CommandList_struct)); */
|
|
|
|
stk->top--;
|
|
|
|
c->cmd.ErrDesc.Addr.lower = temp64.val32.lower;
|
|
|
|
c->cmd.ErrDesc.Addr.upper = temp64.val32.upper;
|
|
|
|
c->cmd.ErrDesc.Len = sizeof(ErrorInfo_struct);
|
|
|
|
|
|
|
|
c->cmd.ctlr = h->ctlr;
|
|
|
|
c->cmd.err_info = &c->Err;
|
|
|
|
|
|
|
|
return (CommandList_struct *) c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-20 02:46:38 +08:00
|
|
|
scsi_cmd_free(ctlr_info_t *h, CommandList_struct *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* assume only one process in here at a time, locking done by caller. */
|
2010-07-20 02:46:38 +08:00
|
|
|
/* use h->lock */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* drop the free memory chunk on top of the stack. */
|
|
|
|
|
|
|
|
struct cciss_scsi_adapter_data_t *sa;
|
|
|
|
struct cciss_scsi_cmd_stack_t *stk;
|
|
|
|
|
2010-02-27 06:01:42 +08:00
|
|
|
sa = h->scsi_ctlr;
|
2005-04-17 06:20:36 +08:00
|
|
|
stk = &sa->cmd_stack;
|
2010-06-01 18:17:48 +08:00
|
|
|
stk->top++;
|
2011-05-04 03:54:12 +08:00
|
|
|
if (stk->top >= stk->nelems) {
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_err(&h->pdev->dev,
|
|
|
|
"scsi_cmd_free called too many times.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
BUG();
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
stk->elem[stk->top] = (struct cciss_scsi_cmd_stack_elem_t *) c;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
scsi_cmd_stack_setup(ctlr_info_t *h, struct cciss_scsi_adapter_data_t *sa)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct cciss_scsi_cmd_stack_t *stk;
|
|
|
|
size_t size;
|
|
|
|
|
2011-05-04 03:54:12 +08:00
|
|
|
stk = &sa->cmd_stack;
|
|
|
|
stk->nelems = cciss_tape_cmds + 2;
|
2010-07-20 02:46:38 +08:00
|
|
|
sa->cmd_sg_list = cciss_allocate_sg_chain_blocks(h,
|
2011-05-04 03:54:12 +08:00
|
|
|
h->chainsize, stk->nelems);
|
2010-07-20 02:46:38 +08:00
|
|
|
if (!sa->cmd_sg_list && h->chainsize > 0)
|
2010-02-27 06:01:53 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-05-04 03:54:12 +08:00
|
|
|
size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * stk->nelems;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-27 06:01:17 +08:00
|
|
|
/* Check alignment, see cciss_cmd.h near CommandList_struct def. */
|
|
|
|
BUILD_BUG_ON((sizeof(*stk->pool) % COMMANDLIST_ALIGNMENT) != 0);
|
|
|
|
/* pci_alloc_consistent guarantees 32-bit DMA address will be used */
|
2005-04-17 06:20:36 +08:00
|
|
|
stk->pool = (struct cciss_scsi_cmd_stack_elem_t *)
|
2010-07-20 02:46:38 +08:00
|
|
|
pci_alloc_consistent(h->pdev, size, &stk->cmd_pool_handle);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (stk->pool == NULL) {
|
2011-05-04 03:54:12 +08:00
|
|
|
cciss_free_sg_chain_blocks(sa->cmd_sg_list, stk->nelems);
|
2010-02-27 06:01:53 +08:00
|
|
|
sa->cmd_sg_list = NULL;
|
|
|
|
return -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-05-04 03:54:12 +08:00
|
|
|
stk->elem = kmalloc(sizeof(stk->elem[0]) * stk->nelems, GFP_KERNEL);
|
|
|
|
if (!stk->elem) {
|
|
|
|
pci_free_consistent(h->pdev, size, stk->pool,
|
|
|
|
stk->cmd_pool_handle);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < stk->nelems; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
stk->elem[i] = &stk->pool[i];
|
|
|
|
stk->elem[i]->busaddr = (__u32) (stk->cmd_pool_handle +
|
|
|
|
(sizeof(struct cciss_scsi_cmd_stack_elem_t) * i));
|
2010-02-27 06:01:53 +08:00
|
|
|
stk->elem[i]->cmdindex = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-05-04 03:54:12 +08:00
|
|
|
stk->top = stk->nelems-1;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-20 02:46:38 +08:00
|
|
|
scsi_cmd_stack_free(ctlr_info_t *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct cciss_scsi_adapter_data_t *sa;
|
|
|
|
struct cciss_scsi_cmd_stack_t *stk;
|
|
|
|
size_t size;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
sa = h->scsi_ctlr;
|
2005-04-17 06:20:36 +08:00
|
|
|
stk = &sa->cmd_stack;
|
2011-05-04 03:54:12 +08:00
|
|
|
if (stk->top != stk->nelems-1) {
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"bug: %d scsi commands are still outstanding.\n",
|
2011-05-04 03:54:12 +08:00
|
|
|
stk->nelems - stk->top);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-05-04 03:54:12 +08:00
|
|
|
size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * stk->nelems;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
pci_free_consistent(h->pdev, size, stk->pool, stk->cmd_pool_handle);
|
2005-04-17 06:20:36 +08:00
|
|
|
stk->pool = NULL;
|
2011-05-04 03:54:12 +08:00
|
|
|
cciss_free_sg_chain_blocks(sa->cmd_sg_list, stk->nelems);
|
|
|
|
kfree(stk->elem);
|
|
|
|
stk->elem = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-15 16:09:20 +08:00
|
|
|
#if 0
|
2005-04-17 06:20:36 +08:00
|
|
|
static int xmargin=8;
|
|
|
|
static int amargin=60;
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_bytes (unsigned char *c, int len, int hex, int ascii)
|
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
unsigned char *x;
|
|
|
|
|
|
|
|
if (hex)
|
|
|
|
{
|
|
|
|
x = c;
|
|
|
|
for (i=0;i<len;i++)
|
|
|
|
{
|
|
|
|
if ((i % xmargin) == 0 && i>0) printk("\n");
|
|
|
|
if ((i % xmargin) == 0) printk("0x%04x:", i);
|
|
|
|
printk(" %02x", *x);
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
if (ascii)
|
|
|
|
{
|
|
|
|
x = c;
|
|
|
|
for (i=0;i<len;i++)
|
|
|
|
{
|
|
|
|
if ((i % amargin) == 0 && i>0) printk("\n");
|
|
|
|
if ((i % amargin) == 0) printk("0x%04x:", i);
|
|
|
|
if (*x > 26 && *x < 128) printk("%c", *x);
|
|
|
|
else printk(".");
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_cmd(CommandList_struct *cp)
|
|
|
|
{
|
|
|
|
printk("queue:%d\n", cp->Header.ReplyQueue);
|
|
|
|
printk("sglist:%d\n", cp->Header.SGList);
|
|
|
|
printk("sgtot:%d\n", cp->Header.SGTotal);
|
|
|
|
printk("Tag:0x%08x/0x%08x\n", cp->Header.Tag.upper,
|
|
|
|
cp->Header.Tag.lower);
|
|
|
|
printk("LUN:0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
|
|
|
|
cp->Header.LUN.LunAddrBytes[0],
|
|
|
|
cp->Header.LUN.LunAddrBytes[1],
|
|
|
|
cp->Header.LUN.LunAddrBytes[2],
|
|
|
|
cp->Header.LUN.LunAddrBytes[3],
|
|
|
|
cp->Header.LUN.LunAddrBytes[4],
|
|
|
|
cp->Header.LUN.LunAddrBytes[5],
|
|
|
|
cp->Header.LUN.LunAddrBytes[6],
|
|
|
|
cp->Header.LUN.LunAddrBytes[7]);
|
|
|
|
printk("CDBLen:%d\n", cp->Request.CDBLen);
|
|
|
|
printk("Type:%d\n",cp->Request.Type.Type);
|
|
|
|
printk("Attr:%d\n",cp->Request.Type.Attribute);
|
|
|
|
printk(" Dir:%d\n",cp->Request.Type.Direction);
|
|
|
|
printk("Timeout:%d\n",cp->Request.Timeout);
|
|
|
|
printk( "CDB: %02x %02x %02x %02x %02x %02x %02x %02x"
|
|
|
|
" %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
|
|
|
cp->Request.CDB[0], cp->Request.CDB[1],
|
|
|
|
cp->Request.CDB[2], cp->Request.CDB[3],
|
|
|
|
cp->Request.CDB[4], cp->Request.CDB[5],
|
|
|
|
cp->Request.CDB[6], cp->Request.CDB[7],
|
|
|
|
cp->Request.CDB[8], cp->Request.CDB[9],
|
|
|
|
cp->Request.CDB[10], cp->Request.CDB[11],
|
|
|
|
cp->Request.CDB[12], cp->Request.CDB[13],
|
|
|
|
cp->Request.CDB[14], cp->Request.CDB[15]),
|
|
|
|
printk("edesc.Addr: 0x%08x/0%08x, Len = %d\n",
|
|
|
|
cp->ErrDesc.Addr.upper, cp->ErrDesc.Addr.lower,
|
|
|
|
cp->ErrDesc.Len);
|
|
|
|
printk("sgs..........Errorinfo:\n");
|
|
|
|
printk("scsistatus:%d\n", cp->err_info->ScsiStatus);
|
|
|
|
printk("senselen:%d\n", cp->err_info->SenseLen);
|
|
|
|
printk("cmd status:%d\n", cp->err_info->CommandStatus);
|
|
|
|
printk("resid cnt:%d\n", cp->err_info->ResidualCnt);
|
|
|
|
printk("offense size:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_size);
|
|
|
|
printk("offense byte:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_num);
|
|
|
|
printk("offense value:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
find_bus_target_lun(ctlr_info_t *h, int *bus, int *target, int *lun)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* finds an unused bus, target, lun for a new device */
|
2010-07-20 02:46:38 +08:00
|
|
|
/* assumes h->scsi_ctlr->lock is held */
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, found=0;
|
|
|
|
unsigned char target_taken[CCISS_MAX_SCSI_DEVS_PER_HBA];
|
|
|
|
|
|
|
|
memset(&target_taken[0], 0, CCISS_MAX_SCSI_DEVS_PER_HBA);
|
|
|
|
|
|
|
|
target_taken[SELF_SCSI_ID] = 1;
|
2010-07-20 02:46:38 +08:00
|
|
|
for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++)
|
|
|
|
target_taken[ccissscsi[h->ctlr].dev[i].target] = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
for (i = 0; i < CCISS_MAX_SCSI_DEVS_PER_HBA; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!target_taken[i]) {
|
|
|
|
*bus = 0; *target=i; *lun = 0; found=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (!found);
|
|
|
|
}
|
2008-08-04 17:54:53 +08:00
|
|
|
struct scsi2map {
|
|
|
|
char scsi3addr[8];
|
|
|
|
int bus, target, lun;
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_add_entry(ctlr_info_t *h, int hostno,
|
2008-09-20 09:27:47 +08:00
|
|
|
struct cciss_scsi_dev_t *device,
|
2008-08-04 17:54:53 +08:00
|
|
|
struct scsi2map *added, int *nadded)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-07-20 02:46:38 +08:00
|
|
|
/* assumes h->scsi_ctlr->lock is held */
|
|
|
|
int n = ccissscsi[h->ctlr].ndevices;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cciss_scsi_dev_t *sd;
|
2008-08-04 17:54:54 +08:00
|
|
|
int i, bus, target, lun;
|
|
|
|
unsigned char addr1[8], addr2[8];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (n >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "Too many devices, "
|
|
|
|
"some will be inaccessible.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2008-08-04 17:54:53 +08:00
|
|
|
|
2008-08-04 17:54:54 +08:00
|
|
|
bus = target = -1;
|
|
|
|
lun = 0;
|
|
|
|
/* Is this device a non-zero lun of a multi-lun device */
|
|
|
|
/* byte 4 of the 8-byte LUN addr will contain the logical unit no. */
|
2008-09-20 09:27:47 +08:00
|
|
|
if (device->scsi3addr[4] != 0) {
|
2008-08-04 17:54:54 +08:00
|
|
|
/* Search through our list and find the device which */
|
|
|
|
/* has the same 8 byte LUN address, excepting byte 4. */
|
|
|
|
/* Assign the same bus and target for this new LUN. */
|
|
|
|
/* Use the logical unit number from the firmware. */
|
2008-09-20 09:27:47 +08:00
|
|
|
memcpy(addr1, device->scsi3addr, 8);
|
2008-08-04 17:54:54 +08:00
|
|
|
addr1[4] = 0;
|
|
|
|
for (i = 0; i < n; i++) {
|
2010-07-20 02:46:38 +08:00
|
|
|
sd = &ccissscsi[h->ctlr].dev[i];
|
2008-08-04 17:54:54 +08:00
|
|
|
memcpy(addr2, sd->scsi3addr, 8);
|
|
|
|
addr2[4] = 0;
|
|
|
|
/* differ only in byte 4? */
|
|
|
|
if (memcmp(addr1, addr2, 8) == 0) {
|
|
|
|
bus = sd->bus;
|
|
|
|
target = sd->target;
|
2008-09-20 09:27:47 +08:00
|
|
|
lun = device->scsi3addr[4];
|
2008-08-04 17:54:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
sd = &ccissscsi[h->ctlr].dev[n];
|
2008-08-04 17:54:54 +08:00
|
|
|
if (lun == 0) {
|
2010-07-20 02:46:38 +08:00
|
|
|
if (find_bus_target_lun(h,
|
2008-08-04 17:54:54 +08:00
|
|
|
&sd->bus, &sd->target, &sd->lun) != 0)
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
sd->bus = bus;
|
|
|
|
sd->target = target;
|
|
|
|
sd->lun = lun;
|
|
|
|
}
|
2008-08-04 17:54:53 +08:00
|
|
|
added[*nadded].bus = sd->bus;
|
|
|
|
added[*nadded].target = sd->target;
|
|
|
|
added[*nadded].lun = sd->lun;
|
|
|
|
(*nadded)++;
|
|
|
|
|
2008-09-20 09:27:47 +08:00
|
|
|
memcpy(sd->scsi3addr, device->scsi3addr, 8);
|
|
|
|
memcpy(sd->vendor, device->vendor, sizeof(sd->vendor));
|
|
|
|
memcpy(sd->revision, device->revision, sizeof(sd->revision));
|
|
|
|
memcpy(sd->device_id, device->device_id, sizeof(sd->device_id));
|
|
|
|
sd->devtype = device->devtype;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
ccissscsi[h->ctlr].ndevices++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* initially, (before registering with scsi layer) we don't
|
|
|
|
know our hostno and we don't want to print anything first
|
|
|
|
time anyway (the scsi layer's inquiries will show that info) */
|
|
|
|
if (hostno != -1)
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d added.\n",
|
|
|
|
scsi_device_type(sd->devtype), hostno,
|
2005-04-17 06:20:36 +08:00
|
|
|
sd->bus, sd->target, sd->lun);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_remove_entry(ctlr_info_t *h, int hostno, int entry,
|
2008-08-04 17:54:53 +08:00
|
|
|
struct scsi2map *removed, int *nremoved)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-07-20 02:46:38 +08:00
|
|
|
/* assumes h->ctlr]->scsi_ctlr->lock is held */
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
struct cciss_scsi_dev_t sd;
|
|
|
|
|
|
|
|
if (entry < 0 || entry >= CCISS_MAX_SCSI_DEVS_PER_HBA) return;
|
2010-07-20 02:46:38 +08:00
|
|
|
sd = ccissscsi[h->ctlr].dev[entry];
|
2008-08-04 17:54:53 +08:00
|
|
|
removed[*nremoved].bus = sd.bus;
|
|
|
|
removed[*nremoved].target = sd.target;
|
|
|
|
removed[*nremoved].lun = sd.lun;
|
|
|
|
(*nremoved)++;
|
2010-07-20 02:46:38 +08:00
|
|
|
for (i = entry; i < ccissscsi[h->ctlr].ndevices-1; i++)
|
|
|
|
ccissscsi[h->ctlr].dev[i] = ccissscsi[h->ctlr].dev[i+1];
|
|
|
|
ccissscsi[h->ctlr].ndevices--;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d removed.\n",
|
|
|
|
scsi_device_type(sd.devtype), hostno,
|
2005-04-17 06:20:36 +08:00
|
|
|
sd.bus, sd.target, sd.lun);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define SCSI3ADDR_EQ(a,b) ( \
|
|
|
|
(a)[7] == (b)[7] && \
|
|
|
|
(a)[6] == (b)[6] && \
|
|
|
|
(a)[5] == (b)[5] && \
|
|
|
|
(a)[4] == (b)[4] && \
|
|
|
|
(a)[3] == (b)[3] && \
|
|
|
|
(a)[2] == (b)[2] && \
|
|
|
|
(a)[1] == (b)[1] && \
|
|
|
|
(a)[0] == (b)[0])
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
static void fixup_botched_add(ctlr_info_t *h, char *scsi3addr)
|
2008-08-04 17:54:53 +08:00
|
|
|
{
|
|
|
|
/* called when scsi_add_device fails in order to re-adjust */
|
|
|
|
/* ccissscsi[] to match the mid layer's view. */
|
|
|
|
unsigned long flags;
|
|
|
|
int i, j;
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_LOCK(h, flags);
|
|
|
|
for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
|
2008-08-04 17:54:53 +08:00
|
|
|
if (memcmp(scsi3addr,
|
2010-07-20 02:46:38 +08:00
|
|
|
ccissscsi[h->ctlr].dev[i].scsi3addr, 8) == 0) {
|
|
|
|
for (j = i; j < ccissscsi[h->ctlr].ndevices-1; j++)
|
|
|
|
ccissscsi[h->ctlr].dev[j] =
|
|
|
|
ccissscsi[h->ctlr].dev[j+1];
|
|
|
|
ccissscsi[h->ctlr].ndevices--;
|
2008-08-04 17:54:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_UNLOCK(h, flags);
|
2008-08-04 17:54:53 +08:00
|
|
|
}
|
|
|
|
|
2008-09-20 09:27:47 +08:00
|
|
|
static int device_is_the_same(struct cciss_scsi_dev_t *dev1,
|
|
|
|
struct cciss_scsi_dev_t *dev2)
|
|
|
|
{
|
|
|
|
return dev1->devtype == dev2->devtype &&
|
|
|
|
memcmp(dev1->scsi3addr, dev2->scsi3addr,
|
|
|
|
sizeof(dev1->scsi3addr)) == 0 &&
|
|
|
|
memcmp(dev1->device_id, dev2->device_id,
|
|
|
|
sizeof(dev1->device_id)) == 0 &&
|
|
|
|
memcmp(dev1->vendor, dev2->vendor,
|
|
|
|
sizeof(dev1->vendor)) == 0 &&
|
|
|
|
memcmp(dev1->model, dev2->model,
|
|
|
|
sizeof(dev1->model)) == 0 &&
|
|
|
|
memcmp(dev1->revision, dev2->revision,
|
|
|
|
sizeof(dev1->revision)) == 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
adjust_cciss_scsi_table(ctlr_info_t *h, int hostno,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cciss_scsi_dev_t sd[], int nsds)
|
|
|
|
{
|
|
|
|
/* sd contains scsi3 addresses and devtypes, but
|
|
|
|
bus target and lun are not filled in. This funciton
|
|
|
|
takes what's in sd to be the current and adjusts
|
|
|
|
ccissscsi[] to be in line with what's in sd. */
|
|
|
|
|
|
|
|
int i,j, found, changes=0;
|
|
|
|
struct cciss_scsi_dev_t *csd;
|
|
|
|
unsigned long flags;
|
2008-08-04 17:54:53 +08:00
|
|
|
struct scsi2map *added, *removed;
|
|
|
|
int nadded, nremoved;
|
|
|
|
struct Scsi_Host *sh = NULL;
|
|
|
|
|
|
|
|
added = kzalloc(sizeof(*added) * CCISS_MAX_SCSI_DEVS_PER_HBA,
|
|
|
|
GFP_KERNEL);
|
|
|
|
removed = kzalloc(sizeof(*removed) * CCISS_MAX_SCSI_DEVS_PER_HBA,
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!added || !removed) {
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"Out of memory in adjust_cciss_scsi_table\n");
|
2008-08-04 17:54:53 +08:00
|
|
|
goto free_and_out;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_LOCK(h, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-04 17:54:53 +08:00
|
|
|
if (hostno != -1) /* if it's not the first time... */
|
2010-07-20 02:46:38 +08:00
|
|
|
sh = h->scsi_ctlr->scsi_host;
|
2008-08-04 17:54:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* find any devices in ccissscsi[] that are not in
|
|
|
|
sd[] and remove them from ccissscsi[] */
|
|
|
|
|
|
|
|
i = 0;
|
2008-08-04 17:54:53 +08:00
|
|
|
nremoved = 0;
|
|
|
|
nadded = 0;
|
2010-07-20 02:46:38 +08:00
|
|
|
while (i < ccissscsi[h->ctlr].ndevices) {
|
|
|
|
csd = &ccissscsi[h->ctlr].dev[i];
|
2005-04-17 06:20:36 +08:00
|
|
|
found=0;
|
|
|
|
for (j=0;j<nsds;j++) {
|
|
|
|
if (SCSI3ADDR_EQ(sd[j].scsi3addr,
|
|
|
|
csd->scsi3addr)) {
|
2008-09-20 09:27:47 +08:00
|
|
|
if (device_is_the_same(&sd[j], csd))
|
2005-04-17 06:20:36 +08:00
|
|
|
found=2;
|
|
|
|
else
|
|
|
|
found=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == 0) { /* device no longer present. */
|
|
|
|
changes++;
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_remove_entry(h, hostno, i,
|
2008-08-04 17:54:53 +08:00
|
|
|
removed, &nremoved);
|
|
|
|
/* remove ^^^, hence i not incremented */
|
2008-09-20 09:27:47 +08:00
|
|
|
} else if (found == 1) { /* device is different in some way */
|
2005-04-17 06:20:36 +08:00
|
|
|
changes++;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_info(&h->pdev->dev,
|
|
|
|
"device c%db%dt%dl%d has changed.\n",
|
|
|
|
hostno, csd->bus, csd->target, csd->lun);
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_remove_entry(h, hostno, i,
|
2008-08-04 17:54:53 +08:00
|
|
|
removed, &nremoved);
|
|
|
|
/* remove ^^^, hence i not incremented */
|
2010-07-20 02:46:38 +08:00
|
|
|
if (cciss_scsi_add_entry(h, hostno, &sd[j],
|
2008-08-04 17:54:53 +08:00
|
|
|
added, &nadded) != 0)
|
|
|
|
/* we just removed one, so add can't fail. */
|
|
|
|
BUG();
|
2005-04-17 06:20:36 +08:00
|
|
|
csd->devtype = sd[j].devtype;
|
2008-09-20 09:27:47 +08:00
|
|
|
memcpy(csd->device_id, sd[j].device_id,
|
|
|
|
sizeof(csd->device_id));
|
|
|
|
memcpy(csd->vendor, sd[j].vendor,
|
|
|
|
sizeof(csd->vendor));
|
|
|
|
memcpy(csd->model, sd[j].model,
|
|
|
|
sizeof(csd->model));
|
|
|
|
memcpy(csd->revision, sd[j].revision,
|
|
|
|
sizeof(csd->revision));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else /* device is same as it ever was, */
|
|
|
|
i++; /* so just move along. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, make sure every device listed in sd[] is also
|
|
|
|
listed in ccissscsi[], adding them if they aren't found */
|
|
|
|
|
|
|
|
for (i=0;i<nsds;i++) {
|
|
|
|
found=0;
|
2010-07-20 02:46:38 +08:00
|
|
|
for (j = 0; j < ccissscsi[h->ctlr].ndevices; j++) {
|
|
|
|
csd = &ccissscsi[h->ctlr].dev[j];
|
2005-04-17 06:20:36 +08:00
|
|
|
if (SCSI3ADDR_EQ(sd[i].scsi3addr,
|
|
|
|
csd->scsi3addr)) {
|
2008-09-20 09:27:47 +08:00
|
|
|
if (device_is_the_same(&sd[i], csd))
|
2005-04-17 06:20:36 +08:00
|
|
|
found=2; /* found device */
|
|
|
|
else
|
|
|
|
found=1; /* found a bug. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
changes++;
|
2010-07-20 02:46:38 +08:00
|
|
|
if (cciss_scsi_add_entry(h, hostno, &sd[i],
|
2008-08-04 17:54:53 +08:00
|
|
|
added, &nadded) != 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
} else if (found == 1) {
|
|
|
|
/* should never happen... */
|
|
|
|
changes++;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"device unexpectedly changed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
/* but if it does happen, we just ignore that device */
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_UNLOCK(h, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-04 17:54:53 +08:00
|
|
|
/* Don't notify scsi mid layer of any changes the first time through */
|
|
|
|
/* (or if there are no changes) scsi_scan_host will do it later the */
|
|
|
|
/* first time through. */
|
|
|
|
if (hostno == -1 || !changes)
|
|
|
|
goto free_and_out;
|
|
|
|
|
|
|
|
/* Notify scsi mid layer of any removed devices */
|
|
|
|
for (i = 0; i < nremoved; i++) {
|
|
|
|
struct scsi_device *sdev =
|
|
|
|
scsi_device_lookup(sh, removed[i].bus,
|
|
|
|
removed[i].target, removed[i].lun);
|
|
|
|
if (sdev != NULL) {
|
|
|
|
scsi_remove_device(sdev);
|
|
|
|
scsi_device_put(sdev);
|
|
|
|
} else {
|
|
|
|
/* We don't expect to get here. */
|
|
|
|
/* future cmds to this device will get selection */
|
|
|
|
/* timeout as if the device was gone. */
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "didn't find "
|
2008-08-04 17:54:53 +08:00
|
|
|
"c%db%dt%dl%d\n for removal.",
|
2010-07-20 02:46:48 +08:00
|
|
|
hostno, removed[i].bus,
|
2008-08-04 17:54:53 +08:00
|
|
|
removed[i].target, removed[i].lun);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify scsi mid layer of any added devices */
|
|
|
|
for (i = 0; i < nadded; i++) {
|
|
|
|
int rc;
|
|
|
|
rc = scsi_add_device(sh, added[i].bus,
|
|
|
|
added[i].target, added[i].lun);
|
|
|
|
if (rc == 0)
|
|
|
|
continue;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "scsi_add_device "
|
2008-08-04 17:54:53 +08:00
|
|
|
"c%db%dt%dl%d failed, device not added.\n",
|
2010-07-20 02:46:48 +08:00
|
|
|
hostno, added[i].bus, added[i].target, added[i].lun);
|
2008-08-04 17:54:53 +08:00
|
|
|
/* now we have to remove it from ccissscsi, */
|
|
|
|
/* since it didn't get added to scsi mid layer */
|
2010-07-20 02:46:38 +08:00
|
|
|
fixup_botched_add(h, added[i].scsi3addr);
|
2008-08-04 17:54:53 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-04 17:54:53 +08:00
|
|
|
free_and_out:
|
|
|
|
kfree(added);
|
|
|
|
kfree(removed);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
lookup_scsi3addr(ctlr_info_t *h, int bus, int target, int lun, char *scsi3addr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct cciss_scsi_dev_t *sd;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_LOCK(h, flags);
|
|
|
|
for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
|
|
|
|
sd = &ccissscsi[h->ctlr].dev[i];
|
2005-04-17 06:20:36 +08:00
|
|
|
if (sd->bus == bus &&
|
|
|
|
sd->target == target &&
|
|
|
|
sd->lun == lun) {
|
|
|
|
memcpy(scsi3addr, &sd->scsi3addr[0], 8);
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_UNLOCK(h, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_UNLOCK(h, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_setup(ctlr_info_t *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct cciss_scsi_adapter_data_t * shba;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
ccissscsi[h->ctlr].ndevices = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
shba = (struct cciss_scsi_adapter_data_t *)
|
|
|
|
kmalloc(sizeof(*shba), GFP_KERNEL);
|
|
|
|
if (shba == NULL)
|
|
|
|
return;
|
|
|
|
shba->scsi_host = NULL;
|
|
|
|
spin_lock_init(&shba->lock);
|
|
|
|
shba->registered = 0;
|
2010-07-20 02:46:38 +08:00
|
|
|
if (scsi_cmd_stack_setup(h, shba) != 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(shba);
|
|
|
|
shba = NULL;
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
h->scsi_ctlr = shba;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
static void complete_scsi_command(CommandList_struct *c, int timeout,
|
|
|
|
__u32 tag)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct scsi_cmnd *cmd;
|
2010-07-20 02:46:38 +08:00
|
|
|
ctlr_info_t *h;
|
2005-04-17 06:20:36 +08:00
|
|
|
ErrorInfo_struct *ei;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
ei = c->err_info;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* First, see if it was a message rather than a command */
|
2010-07-20 02:46:38 +08:00
|
|
|
if (c->Request.Type.Type == TYPE_MSG) {
|
|
|
|
c->cmd_type = CMD_MSG_DONE;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
cmd = (struct scsi_cmnd *) c->scsi_cmd;
|
|
|
|
h = hba[c->ctlr];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-26 01:45:17 +08:00
|
|
|
scsi_dma_unmap(cmd);
|
2010-07-20 02:46:38 +08:00
|
|
|
if (c->Header.SGTotal > h->max_cmd_sgentries)
|
|
|
|
cciss_unmap_sg_chain_block(h, c);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cmd->result = (DID_OK << 16); /* host byte */
|
|
|
|
cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */
|
|
|
|
/* cmd->result |= (GOOD < 1); */ /* status byte */
|
|
|
|
|
|
|
|
cmd->result |= (ei->ScsiStatus);
|
|
|
|
/* printk("Scsistatus is 0x%02x\n", ei->ScsiStatus); */
|
|
|
|
|
|
|
|
/* copy the sense data whether we need to or not. */
|
|
|
|
|
|
|
|
memcpy(cmd->sense_buffer, ei->SenseInfo,
|
|
|
|
ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
|
|
|
|
SCSI_SENSE_BUFFERSIZE :
|
|
|
|
ei->SenseLen);
|
2007-05-26 01:45:17 +08:00
|
|
|
scsi_set_resid(cmd, ei->ResidualCnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if(ei->CommandStatus != 0)
|
|
|
|
{ /* an error has occurred */
|
|
|
|
switch(ei->CommandStatus)
|
|
|
|
{
|
|
|
|
case CMD_TARGET_STATUS:
|
|
|
|
/* Pass it up to the upper layers... */
|
|
|
|
if( ei->ScsiStatus)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
printk(KERN_WARNING "cciss: cmd %p "
|
2010-07-20 02:46:38 +08:00
|
|
|
"has SCSI Status = %x\n",
|
|
|
|
c, ei->ScsiStatus);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2009-11-13 02:49:45 +08:00
|
|
|
cmd->result |= (ei->ScsiStatus << 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
else { /* scsi status is zero??? How??? */
|
|
|
|
|
|
|
|
/* Ordinarily, this case should never happen, but there is a bug
|
|
|
|
in some released firmware revisions that allows it to happen
|
|
|
|
if, for example, a 4100 backplane loses power and the tape
|
|
|
|
drive is in it. We assume that it's a fatal error of some
|
|
|
|
kind because we can't show that it wasn't. We will make it
|
|
|
|
look like selection timeout since that is the most common
|
|
|
|
reason for this to occur, and it's severe enough. */
|
|
|
|
|
|
|
|
cmd->result = DID_NO_CONNECT << 16;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
|
|
|
|
break;
|
|
|
|
case CMD_DATA_OVERRUN:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p has"
|
2005-04-17 06:20:36 +08:00
|
|
|
" completed with data overrun "
|
2010-07-20 02:46:38 +08:00
|
|
|
"reported\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_INVALID: {
|
2010-07-20 02:46:38 +08:00
|
|
|
/* print_bytes(c, sizeof(*c), 1, 0);
|
|
|
|
print_cmd(c); */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* We get CMD_INVALID if you address a non-existent tape drive instead
|
|
|
|
of a selection timeout (no response). You will see this if you yank
|
|
|
|
out a tape drive, then try to access it. This is kind of a shame
|
|
|
|
because it means that any other CMD_INVALID (e.g. driver bug) will
|
|
|
|
get interpreted as a missing target. */
|
|
|
|
cmd->result = DID_NO_CONNECT << 16;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CMD_PROTOCOL_ERR:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p has protocol error\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_HARDWARE_ERR:
|
|
|
|
cmd->result = DID_ERROR << 16;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p had hardware error\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_CONNECTION_LOST:
|
|
|
|
cmd->result = DID_ERROR << 16;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p had connection lost\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_ABORTED:
|
|
|
|
cmd->result = DID_ABORT << 16;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p was aborted\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_ABORT_FAILED:
|
|
|
|
cmd->result = DID_ERROR << 16;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p reports abort failed\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_UNSOLICITED_ABORT:
|
|
|
|
cmd->result = DID_ABORT << 16;
|
2011-03-12 17:02:30 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p aborted due to an "
|
2010-07-20 02:46:48 +08:00
|
|
|
"unsolicited abort\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_TIMEOUT:
|
|
|
|
cmd->result = DID_TIME_OUT << 16;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p timedout\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2011-03-12 17:02:30 +08:00
|
|
|
case CMD_UNABORTABLE:
|
|
|
|
cmd->result = DID_ERROR << 16;
|
|
|
|
dev_warn(&h->pdev->dev, "c %p command "
|
|
|
|
"unabortable\n", c);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
cmd->result = DID_ERROR << 16;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p returned unknown status %x\n", c,
|
2005-04-17 06:20:36 +08:00
|
|
|
ei->CommandStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd->scsi_done(cmd);
|
2010-07-20 02:46:38 +08:00
|
|
|
scsi_cmd_free(h, c);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_detect(ctlr_info_t *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct Scsi_Host *sh;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sh = scsi_host_alloc(&cciss_driver_template, sizeof(struct ctlr_info *));
|
|
|
|
if (sh == NULL)
|
|
|
|
goto fail;
|
|
|
|
sh->io_port = 0; // good enough? FIXME,
|
|
|
|
sh->n_io_port = 0; // I don't think we use these two...
|
|
|
|
sh->this_id = SELF_SCSI_ID;
|
2011-05-04 03:54:12 +08:00
|
|
|
sh->can_queue = cciss_tape_cmds;
|
2010-07-20 02:46:38 +08:00
|
|
|
sh->sg_tablesize = h->maxsgentries;
|
2010-06-15 14:12:34 +08:00
|
|
|
sh->max_cmd_len = MAX_COMMAND_SIZE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
((struct cciss_scsi_adapter_data_t *)
|
2010-07-20 02:46:38 +08:00
|
|
|
h->scsi_ctlr)->scsi_host = sh;
|
|
|
|
sh->hostdata[0] = (unsigned long) h;
|
|
|
|
sh->irq = h->intr[SIMPLE_MODE_INT];
|
2005-04-17 06:20:36 +08:00
|
|
|
sh->unique_id = sh->irq;
|
2010-07-20 02:46:38 +08:00
|
|
|
error = scsi_add_host(sh, &h->pdev->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (error)
|
|
|
|
goto fail_host_put;
|
|
|
|
scsi_scan_host(sh);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
fail_host_put:
|
|
|
|
scsi_host_put(sh);
|
|
|
|
fail:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cciss_unmap_one(struct pci_dev *pdev,
|
2010-07-20 02:46:38 +08:00
|
|
|
CommandList_struct *c,
|
2005-04-17 06:20:36 +08:00
|
|
|
size_t buflen,
|
|
|
|
int data_direction)
|
|
|
|
{
|
|
|
|
u64bit addr64;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
addr64.val32.lower = c->SG[0].Addr.lower;
|
|
|
|
addr64.val32.upper = c->SG[0].Addr.upper;
|
2005-04-17 06:20:36 +08:00
|
|
|
pci_unmap_single(pdev, (dma_addr_t) addr64.val, buflen, data_direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cciss_map_one(struct pci_dev *pdev,
|
2010-07-20 02:46:38 +08:00
|
|
|
CommandList_struct *c,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char *buf,
|
|
|
|
size_t buflen,
|
|
|
|
int data_direction)
|
|
|
|
{
|
|
|
|
__u64 addr64;
|
|
|
|
|
|
|
|
addr64 = (__u64) pci_map_single(pdev, buf, buflen, data_direction);
|
2010-07-20 02:46:38 +08:00
|
|
|
c->SG[0].Addr.lower =
|
2005-04-17 06:20:36 +08:00
|
|
|
(__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
|
2010-07-20 02:46:38 +08:00
|
|
|
c->SG[0].Addr.upper =
|
2005-04-17 06:20:36 +08:00
|
|
|
(__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
|
2010-07-20 02:46:38 +08:00
|
|
|
c->SG[0].Len = buflen;
|
|
|
|
c->Header.SGList = (__u8) 1; /* no. SGs contig in this cmd */
|
|
|
|
c->Header.SGTotal = (__u16) 1; /* total sgs in this cmd list */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_do_simple_cmd(ctlr_info_t *h,
|
|
|
|
CommandList_struct *c,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char *scsi3addr,
|
|
|
|
unsigned char *cdb,
|
|
|
|
unsigned char cdblen,
|
|
|
|
unsigned char *buf, int bufsize,
|
|
|
|
int direction)
|
|
|
|
{
|
2006-10-01 14:28:10 +08:00
|
|
|
DECLARE_COMPLETION_ONSTACK(wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
c->cmd_type = CMD_IOCTL_PEND; /* treat this like an ioctl */
|
|
|
|
c->scsi_cmd = NULL;
|
|
|
|
c->Header.ReplyQueue = 0; /* unused in simple mode */
|
|
|
|
memcpy(&c->Header.LUN, scsi3addr, sizeof(c->Header.LUN));
|
|
|
|
c->Header.Tag.lower = c->busaddr; /* Use k. address of cmd as tag */
|
2005-04-17 06:20:36 +08:00
|
|
|
// Fill in the request block...
|
|
|
|
|
|
|
|
/* printk("Using scsi3addr 0x%02x%0x2%0x2%0x2%0x2%0x2%0x2%0x2\n",
|
|
|
|
scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3],
|
|
|
|
scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); */
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
memset(c->Request.CDB, 0, sizeof(c->Request.CDB));
|
|
|
|
memcpy(c->Request.CDB, cdb, cdblen);
|
|
|
|
c->Request.Timeout = 0;
|
|
|
|
c->Request.CDBLen = cdblen;
|
|
|
|
c->Request.Type.Type = TYPE_CMD;
|
|
|
|
c->Request.Type.Attribute = ATTR_SIMPLE;
|
|
|
|
c->Request.Type.Direction = direction;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Fill in the SG list and do dma mapping */
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_map_one(h->pdev, c, (unsigned char *) buf,
|
2005-04-17 06:20:36 +08:00
|
|
|
bufsize, DMA_FROM_DEVICE);
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
c->waiting = &wait;
|
|
|
|
enqueue_cmd_and_start_io(h, c);
|
2005-04-17 06:20:36 +08:00
|
|
|
wait_for_completion(&wait);
|
|
|
|
|
|
|
|
/* undo the dma mapping */
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_unmap_one(h->pdev, c, bufsize, DMA_FROM_DEVICE);
|
2005-04-17 06:20:36 +08:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-20 02:46:48 +08:00
|
|
|
cciss_scsi_interpret_error(ctlr_info_t *h, CommandList_struct *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
ErrorInfo_struct *ei;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
ei = c->err_info;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch(ei->CommandStatus)
|
|
|
|
{
|
|
|
|
case CMD_TARGET_STATUS:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"cmd %p has completed with errors\n", c);
|
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"cmd %p has SCSI Status = %x\n",
|
|
|
|
c, ei->ScsiStatus);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ei->ScsiStatus == 0)
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"SCSI status is abnormally zero. "
|
2005-04-17 06:20:36 +08:00
|
|
|
"(probably indicates selection timeout "
|
|
|
|
"reported incorrectly due to a known "
|
|
|
|
"firmware bug, circa July, 2001.)\n");
|
|
|
|
break;
|
|
|
|
case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_info(&h->pdev->dev, "UNDERRUN\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_DATA_OVERRUN:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p has"
|
2005-04-17 06:20:36 +08:00
|
|
|
" completed with data overrun "
|
2010-07-20 02:46:38 +08:00
|
|
|
"reported\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_INVALID: {
|
|
|
|
/* controller unfortunately reports SCSI passthru's */
|
|
|
|
/* to non-existent targets as invalid commands. */
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p is reported invalid (probably means "
|
2010-07-20 02:46:38 +08:00
|
|
|
"target device no longer present)\n", c);
|
|
|
|
/* print_bytes((unsigned char *) c, sizeof(*c), 1, 0);
|
|
|
|
print_cmd(c); */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CMD_PROTOCOL_ERR:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p has protocol error\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_HARDWARE_ERR:
|
|
|
|
/* cmd->result = DID_ERROR << 16; */
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p had hardware error\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_CONNECTION_LOST:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p had connection lost\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_ABORTED:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p was aborted\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_ABORT_FAILED:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p reports abort failed\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_UNSOLICITED_ABORT:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
2011-03-12 17:02:30 +08:00
|
|
|
"%p aborted due to an unsolicited abort\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CMD_TIMEOUT:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "%p timedout\n", c);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2011-03-12 17:02:30 +08:00
|
|
|
case CMD_UNABORTABLE:
|
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p unabortable\n", c);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev,
|
|
|
|
"%p returned unknown status %x\n",
|
|
|
|
c, ei->CommandStatus);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_do_inquiry(ctlr_info_t *h, unsigned char *scsi3addr,
|
2008-09-20 09:27:47 +08:00
|
|
|
unsigned char page, unsigned char *buf,
|
|
|
|
unsigned char bufsize)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc;
|
2010-07-20 02:46:38 +08:00
|
|
|
CommandList_struct *c;
|
2005-04-17 06:20:36 +08:00
|
|
|
char cdb[6];
|
|
|
|
ErrorInfo_struct *ei;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
c = scsi_cmd_alloc(h);
|
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
if (c == NULL) { /* trouble... */
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("cmd_alloc returned NULL!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
ei = c->err_info;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cdb[0] = CISS_INQUIRY;
|
2008-09-20 09:27:47 +08:00
|
|
|
cdb[1] = (page != 0);
|
|
|
|
cdb[2] = page;
|
2005-04-17 06:20:36 +08:00
|
|
|
cdb[3] = 0;
|
2005-09-13 16:25:25 +08:00
|
|
|
cdb[4] = bufsize;
|
2005-04-17 06:20:36 +08:00
|
|
|
cdb[5] = 0;
|
2010-07-20 02:46:38 +08:00
|
|
|
rc = cciss_scsi_do_simple_cmd(h, c, scsi3addr, cdb,
|
2005-09-13 16:25:25 +08:00
|
|
|
6, buf, bufsize, XFER_READ);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (rc != 0) return rc; /* something went wrong */
|
|
|
|
|
|
|
|
if (ei->CommandStatus != 0 &&
|
|
|
|
ei->CommandStatus != CMD_DATA_UNDERRUN) {
|
2010-07-20 02:46:48 +08:00
|
|
|
cciss_scsi_interpret_error(h, c);
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = -1;
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
scsi_cmd_free(h, c);
|
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-09-20 09:27:47 +08:00
|
|
|
/* Get the device id from inquiry page 0x83 */
|
2010-07-20 02:46:38 +08:00
|
|
|
static int cciss_scsi_get_device_id(ctlr_info_t *h, unsigned char *scsi3addr,
|
2008-09-20 09:27:47 +08:00
|
|
|
unsigned char *device_id, int buflen)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
unsigned char *buf;
|
|
|
|
|
|
|
|
if (buflen > 16)
|
|
|
|
buflen = 16;
|
|
|
|
buf = kzalloc(64, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -1;
|
2010-07-20 02:46:38 +08:00
|
|
|
rc = cciss_scsi_do_inquiry(h, scsi3addr, 0x83, buf, 64);
|
2008-09-20 09:27:47 +08:00
|
|
|
if (rc == 0)
|
|
|
|
memcpy(device_id, &buf[8], buflen);
|
|
|
|
kfree(buf);
|
|
|
|
return rc != 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_do_report_phys_luns(ctlr_info_t *h,
|
2005-04-17 06:20:36 +08:00
|
|
|
ReportLunData_struct *buf, int bufsize)
|
|
|
|
{
|
|
|
|
int rc;
|
2010-07-20 02:46:38 +08:00
|
|
|
CommandList_struct *c;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char cdb[12];
|
|
|
|
unsigned char scsi3addr[8];
|
|
|
|
ErrorInfo_struct *ei;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
c = scsi_cmd_alloc(h);
|
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
|
|
|
if (c == NULL) { /* trouble... */
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("cmd_alloc returned NULL!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&scsi3addr[0], 0, 8); /* address the controller */
|
|
|
|
cdb[0] = CISS_REPORT_PHYS;
|
|
|
|
cdb[1] = 0;
|
|
|
|
cdb[2] = 0;
|
|
|
|
cdb[3] = 0;
|
|
|
|
cdb[4] = 0;
|
|
|
|
cdb[5] = 0;
|
|
|
|
cdb[6] = (bufsize >> 24) & 0xFF; //MSB
|
|
|
|
cdb[7] = (bufsize >> 16) & 0xFF;
|
|
|
|
cdb[8] = (bufsize >> 8) & 0xFF;
|
|
|
|
cdb[9] = bufsize & 0xFF;
|
|
|
|
cdb[10] = 0;
|
|
|
|
cdb[11] = 0;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
rc = cciss_scsi_do_simple_cmd(h, c, scsi3addr,
|
2005-04-17 06:20:36 +08:00
|
|
|
cdb, 12,
|
|
|
|
(unsigned char *) buf,
|
|
|
|
bufsize, XFER_READ);
|
|
|
|
|
|
|
|
if (rc != 0) return rc; /* something went wrong */
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
ei = c->err_info;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ei->CommandStatus != 0 &&
|
|
|
|
ei->CommandStatus != CMD_DATA_UNDERRUN) {
|
2010-07-20 02:46:48 +08:00
|
|
|
cciss_scsi_interpret_error(h, c);
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = -1;
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
scsi_cmd_free(h, c);
|
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_update_non_disk_devices(ctlr_info_t *h, int hostno)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* the idea here is we could get notified from /proc
|
|
|
|
that some devices have changed, so we do a report
|
|
|
|
physical luns cmd, and adjust our list of devices
|
|
|
|
accordingly. (We can't rely on the scsi-mid layer just
|
|
|
|
doing inquiries, because the "busses" that the scsi
|
|
|
|
mid-layer probes are totally fabricated by this driver,
|
|
|
|
so new devices wouldn't show up.
|
|
|
|
|
|
|
|
the scsi3addr's of devices won't change so long as the
|
|
|
|
adapter is not reset. That means we can rescan and
|
|
|
|
tell which devices we already know about, vs. new
|
|
|
|
devices, vs. disappearing devices.
|
|
|
|
|
|
|
|
Also, if you yank out a tape drive, then put in a disk
|
|
|
|
in it's place, (say, a configured volume from another
|
|
|
|
array controller for instance) _don't_ poke this driver
|
|
|
|
(so it thinks it's still a tape, but _do_ poke the scsi
|
|
|
|
mid layer, so it does an inquiry... the scsi mid layer
|
|
|
|
will see the physical disk. This would be bad. Need to
|
|
|
|
think about how to prevent that. One idea would be to
|
|
|
|
snoop all scsi responses and if an inquiry repsonse comes
|
|
|
|
back that reports a disk, chuck it an return selection
|
|
|
|
timeout instead and adjust our table... Not sure i like
|
|
|
|
that though.
|
|
|
|
|
|
|
|
*/
|
2005-09-13 16:25:25 +08:00
|
|
|
#define OBDR_TAPE_INQ_SIZE 49
|
|
|
|
#define OBDR_TAPE_SIG "$DR-10"
|
2005-04-17 06:20:36 +08:00
|
|
|
ReportLunData_struct *ld_buff;
|
2005-09-13 16:25:25 +08:00
|
|
|
unsigned char *inq_buff;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char scsi3addr[8];
|
|
|
|
__u32 num_luns=0;
|
|
|
|
unsigned char *ch;
|
2008-09-20 09:27:47 +08:00
|
|
|
struct cciss_scsi_dev_t *currentsd, *this_device;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ncurrent=0;
|
|
|
|
int reportlunsize = sizeof(*ld_buff) + CISS_MAX_PHYS_LUN * 8;
|
|
|
|
int i;
|
|
|
|
|
2006-03-08 18:21:52 +08:00
|
|
|
ld_buff = kzalloc(reportlunsize, GFP_KERNEL);
|
2005-09-13 16:25:25 +08:00
|
|
|
inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL);
|
2008-09-20 09:27:47 +08:00
|
|
|
currentsd = kzalloc(sizeof(*currentsd) *
|
|
|
|
(CCISS_MAX_SCSI_DEVS_PER_HBA+1), GFP_KERNEL);
|
|
|
|
if (ld_buff == NULL || inq_buff == NULL || currentsd == NULL) {
|
|
|
|
printk(KERN_ERR "cciss: out of memory\n");
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-09-20 09:27:47 +08:00
|
|
|
this_device = ¤tsd[CCISS_MAX_SCSI_DEVS_PER_HBA];
|
2010-07-20 02:46:38 +08:00
|
|
|
if (cciss_scsi_do_report_phys_luns(h, ld_buff, reportlunsize) == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ch = &ld_buff->LUNListLength[0];
|
|
|
|
num_luns = ((ch[0]<<24) | (ch[1]<<16) | (ch[2]<<8) | ch[3]) / 8;
|
|
|
|
if (num_luns > CISS_MAX_PHYS_LUN) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"cciss: Maximum physical LUNs (%d) exceeded. "
|
|
|
|
"%d LUNs ignored.\n", CISS_MAX_PHYS_LUN,
|
|
|
|
num_luns - CISS_MAX_PHYS_LUN);
|
|
|
|
num_luns = CISS_MAX_PHYS_LUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printk(KERN_ERR "cciss: Report physical LUNs failed.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* adjust our table of devices */
|
2008-09-20 09:27:47 +08:00
|
|
|
for (i = 0; i < num_luns; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* for each physical lun, do an inquiry */
|
|
|
|
if (ld_buff->LUN[i][3] & 0xC0) continue;
|
2005-09-13 16:25:25 +08:00
|
|
|
memset(inq_buff, 0, OBDR_TAPE_INQ_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(&scsi3addr[0], &ld_buff->LUN[i][0], 8);
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
if (cciss_scsi_do_inquiry(h, scsi3addr, 0, inq_buff,
|
2008-09-20 09:27:47 +08:00
|
|
|
(unsigned char) OBDR_TAPE_INQ_SIZE) != 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Inquiry failed (msg printed already) */
|
2008-09-20 09:27:47 +08:00
|
|
|
continue; /* so we will skip this device. */
|
|
|
|
|
|
|
|
this_device->devtype = (inq_buff[0] & 0x1f);
|
|
|
|
this_device->bus = -1;
|
|
|
|
this_device->target = -1;
|
|
|
|
this_device->lun = -1;
|
|
|
|
memcpy(this_device->scsi3addr, scsi3addr, 8);
|
|
|
|
memcpy(this_device->vendor, &inq_buff[8],
|
|
|
|
sizeof(this_device->vendor));
|
|
|
|
memcpy(this_device->model, &inq_buff[16],
|
|
|
|
sizeof(this_device->model));
|
|
|
|
memcpy(this_device->revision, &inq_buff[32],
|
|
|
|
sizeof(this_device->revision));
|
|
|
|
memset(this_device->device_id, 0,
|
|
|
|
sizeof(this_device->device_id));
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_get_device_id(h, scsi3addr,
|
2008-09-20 09:27:47 +08:00
|
|
|
this_device->device_id, sizeof(this_device->device_id));
|
|
|
|
|
|
|
|
switch (this_device->devtype)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-13 16:25:25 +08:00
|
|
|
case 0x05: /* CD-ROM */ {
|
|
|
|
|
|
|
|
/* We don't *really* support actual CD-ROM devices,
|
|
|
|
* just this "One Button Disaster Recovery" tape drive
|
|
|
|
* which temporarily pretends to be a CD-ROM drive.
|
|
|
|
* So we check that the device is really an OBDR tape
|
|
|
|
* device by checking for "$DR-10" in bytes 43-48 of
|
|
|
|
* the inquiry data.
|
|
|
|
*/
|
|
|
|
char obdr_sig[7];
|
|
|
|
|
|
|
|
strncpy(obdr_sig, &inq_buff[43], 6);
|
|
|
|
obdr_sig[6] = '\0';
|
|
|
|
if (strncmp(obdr_sig, OBDR_TAPE_SIG, 6) != 0)
|
|
|
|
/* Not OBDR device, ignore it. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through . . . */
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0x01: /* sequential access, (tape) */
|
|
|
|
case 0x08: /* medium changer */
|
|
|
|
if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
|
|
|
|
printk(KERN_INFO "cciss%d: %s ignored, "
|
2010-07-20 02:46:38 +08:00
|
|
|
"too many devices.\n", h->ctlr,
|
2008-09-20 09:27:47 +08:00
|
|
|
scsi_device_type(this_device->devtype));
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-09-20 09:27:47 +08:00
|
|
|
currentsd[ncurrent] = *this_device;
|
2005-04-17 06:20:36 +08:00
|
|
|
ncurrent++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
adjust_cciss_scsi_table(h, hostno, currentsd, ncurrent);
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
|
|
|
kfree(inq_buff);
|
|
|
|
kfree(ld_buff);
|
2008-09-20 09:27:47 +08:00
|
|
|
kfree(currentsd);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_keyword(char *ptr, int len, char *verb) // Thanks to ncr53c8xx.c
|
|
|
|
{
|
|
|
|
int verb_len = strlen(verb);
|
|
|
|
if (len >= verb_len && !memcmp(verb,ptr,verb_len))
|
|
|
|
return verb_len;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scsi_user_command(ctlr_info_t *h, int hostno, char *buffer, int length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int arg_len;
|
|
|
|
|
|
|
|
if ((arg_len = is_keyword(buffer, length, "rescan")) != 0)
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_update_non_disk_devices(h, hostno);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cciss_scsi_proc_info(struct Scsi_Host *sh,
|
|
|
|
char *buffer, /* data buffer */
|
|
|
|
char **start, /* where data in buffer starts */
|
|
|
|
off_t offset, /* offset from start of imaginary file */
|
|
|
|
int length, /* length of data in buffer */
|
|
|
|
int func) /* 0 == read, 1 == write */
|
|
|
|
{
|
|
|
|
|
|
|
|
int buflen, datalen;
|
2010-07-20 02:46:38 +08:00
|
|
|
ctlr_info_t *h;
|
2005-09-13 16:25:26 +08:00
|
|
|
int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
h = (ctlr_info_t *) sh->hostdata[0];
|
|
|
|
if (h == NULL) /* This really shouldn't ever happen. */
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (func == 0) { /* User is reading from /proc/scsi/ciss*?/?* */
|
2005-09-13 16:25:26 +08:00
|
|
|
buflen = sprintf(buffer, "cciss%d: SCSI host: %d\n",
|
2010-07-20 02:46:38 +08:00
|
|
|
h->ctlr, sh->host_no);
|
2005-09-13 16:25:26 +08:00
|
|
|
|
|
|
|
/* this information is needed by apps to know which cciss
|
|
|
|
device corresponds to which scsi host number without
|
|
|
|
having to open a scsi target device node. The device
|
|
|
|
information is not a duplicate of /proc/scsi/scsi because
|
|
|
|
the two may be out of sync due to scsi hotplug, rather
|
|
|
|
this info is for an app to be able to use to know how to
|
|
|
|
get them back in sync. */
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
|
|
|
|
struct cciss_scsi_dev_t *sd =
|
|
|
|
&ccissscsi[h->ctlr].dev[i];
|
2005-09-13 16:25:26 +08:00
|
|
|
buflen += sprintf(&buffer[buflen], "c%db%dt%dl%d %02d "
|
|
|
|
"0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
|
|
|
|
sh->host_no, sd->bus, sd->target, sd->lun,
|
|
|
|
sd->devtype,
|
|
|
|
sd->scsi3addr[0], sd->scsi3addr[1],
|
|
|
|
sd->scsi3addr[2], sd->scsi3addr[3],
|
|
|
|
sd->scsi3addr[4], sd->scsi3addr[5],
|
|
|
|
sd->scsi3addr[6], sd->scsi3addr[7]);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
datalen = buflen - offset;
|
|
|
|
if (datalen < 0) { /* they're reading past EOF. */
|
|
|
|
datalen = 0;
|
|
|
|
*start = buffer+buflen;
|
|
|
|
} else
|
|
|
|
*start = buffer + offset;
|
|
|
|
return(datalen);
|
|
|
|
} else /* User is writing to /proc/scsi/cciss*?/?* ... */
|
2010-07-20 02:46:38 +08:00
|
|
|
return cciss_scsi_user_command(h, sh->host_no,
|
2005-04-17 06:20:36 +08:00
|
|
|
buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cciss_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci
|
|
|
|
dma mapping and fills in the scatter gather entries of the
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss command, c. */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *c,
|
2010-02-27 06:01:53 +08:00
|
|
|
struct scsi_cmnd *cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-05-26 01:45:17 +08:00
|
|
|
unsigned int len;
|
|
|
|
struct scatterlist *sg;
|
2005-04-17 06:20:36 +08:00
|
|
|
__u64 addr64;
|
2010-02-27 06:01:53 +08:00
|
|
|
int request_nsgs, i, chained, sg_index;
|
|
|
|
struct cciss_scsi_adapter_data_t *sa = h->scsi_ctlr;
|
|
|
|
SGDescriptor_struct *curr_sg;
|
|
|
|
|
|
|
|
BUG_ON(scsi_sg_count(cmd) > h->maxsgentries);
|
|
|
|
|
|
|
|
chained = 0;
|
|
|
|
sg_index = 0;
|
2010-07-20 02:46:38 +08:00
|
|
|
curr_sg = c->SG;
|
2010-02-27 06:01:53 +08:00
|
|
|
request_nsgs = scsi_dma_map(cmd);
|
|
|
|
if (request_nsgs) {
|
|
|
|
scsi_for_each_sg(cmd, sg, request_nsgs, i) {
|
|
|
|
if (sg_index + 1 == h->max_cmd_sgentries &&
|
|
|
|
!chained && request_nsgs - i > 1) {
|
|
|
|
chained = 1;
|
|
|
|
sg_index = 0;
|
2010-07-20 02:46:38 +08:00
|
|
|
curr_sg = sa->cmd_sg_list[c->cmdindex];
|
2010-02-27 06:01:53 +08:00
|
|
|
}
|
2007-05-26 01:45:17 +08:00
|
|
|
addr64 = (__u64) sg_dma_address(sg);
|
|
|
|
len = sg_dma_len(sg);
|
2010-02-27 06:01:53 +08:00
|
|
|
curr_sg[sg_index].Addr.lower =
|
|
|
|
(__u32) (addr64 & 0x0FFFFFFFFULL);
|
|
|
|
curr_sg[sg_index].Addr.upper =
|
|
|
|
(__u32) ((addr64 >> 32) & 0x0FFFFFFFFULL);
|
|
|
|
curr_sg[sg_index].Len = len;
|
|
|
|
curr_sg[sg_index].Ext = 0;
|
|
|
|
++sg_index;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-27 06:01:53 +08:00
|
|
|
if (chained)
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_map_sg_chain_block(h, c,
|
|
|
|
sa->cmd_sg_list[c->cmdindex],
|
2010-02-27 06:01:53 +08:00
|
|
|
(request_nsgs - (h->max_cmd_sgentries - 1)) *
|
|
|
|
sizeof(SGDescriptor_struct));
|
2007-05-26 01:45:17 +08:00
|
|
|
}
|
2010-02-27 06:01:53 +08:00
|
|
|
/* track how many SG entries we are using */
|
|
|
|
if (request_nsgs > h->maxSG)
|
|
|
|
h->maxSG = request_nsgs;
|
2010-07-20 02:46:38 +08:00
|
|
|
c->Header.SGTotal = (__u8) request_nsgs + chained;
|
2010-02-27 06:01:53 +08:00
|
|
|
if (request_nsgs > h->max_cmd_sgentries)
|
2010-07-20 02:46:38 +08:00
|
|
|
c->Header.SGList = h->max_cmd_sgentries;
|
2010-02-27 06:01:53 +08:00
|
|
|
else
|
2010-07-20 02:46:38 +08:00
|
|
|
c->Header.SGList = c->Header.SGTotal;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-11-16 15:10:29 +08:00
|
|
|
cciss_scsi_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-07-20 02:46:38 +08:00
|
|
|
ctlr_info_t *h;
|
|
|
|
int rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char scsi3addr[8];
|
2010-07-20 02:46:38 +08:00
|
|
|
CommandList_struct *c;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
// Get the ptr to our adapter structure (hba[i]) out of cmd->host.
|
|
|
|
// We violate cmd->host privacy here. (Is there another way?)
|
2010-07-20 02:46:38 +08:00
|
|
|
h = (ctlr_info_t *) cmd->device->host->hostdata[0];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
rc = lookup_scsi3addr(h, cmd->device->channel, cmd->device->id,
|
2005-04-17 06:20:36 +08:00
|
|
|
cmd->device->lun, scsi3addr);
|
|
|
|
if (rc != 0) {
|
|
|
|
/* the scsi nexus does not match any that we presented... */
|
|
|
|
/* pretend to mid layer that we got selection timeout */
|
|
|
|
cmd->result = DID_NO_CONNECT << 16;
|
|
|
|
done(cmd);
|
|
|
|
/* we might want to think about registering controller itself
|
|
|
|
as a processor device on the bus so sg binds to it. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ok, we have a reasonable scsi nexus, so send the cmd down, and
|
|
|
|
see what the device thinks of it. */
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
c = scsi_cmd_alloc(h);
|
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
|
|
|
if (c == NULL) { /* trouble... */
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "scsi_cmd_alloc returned NULL!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
/* FIXME: next 3 lines are -> BAD! <- */
|
|
|
|
cmd->result = DID_NO_CONNECT << 16;
|
|
|
|
done(cmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill in the command list header
|
|
|
|
|
|
|
|
cmd->scsi_done = done; // save this for use by completion code
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
/* save c in case we have to abort it */
|
|
|
|
cmd->host_scribble = (unsigned char *) c;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
c->cmd_type = CMD_SCSI;
|
|
|
|
c->scsi_cmd = cmd;
|
|
|
|
c->Header.ReplyQueue = 0; /* unused in simple mode */
|
|
|
|
memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
|
|
|
|
c->Header.Tag.lower = c->busaddr; /* Use k. address of cmd as tag */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
// Fill in the request block...
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
c->Request.Timeout = 0;
|
|
|
|
memset(c->Request.CDB, 0, sizeof(c->Request.CDB));
|
|
|
|
BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB));
|
|
|
|
c->Request.CDBLen = cmd->cmd_len;
|
|
|
|
memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len);
|
|
|
|
c->Request.Type.Type = TYPE_CMD;
|
|
|
|
c->Request.Type.Attribute = ATTR_SIMPLE;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch(cmd->sc_data_direction)
|
|
|
|
{
|
2010-07-20 02:46:38 +08:00
|
|
|
case DMA_TO_DEVICE:
|
|
|
|
c->Request.Type.Direction = XFER_WRITE;
|
|
|
|
break;
|
|
|
|
case DMA_FROM_DEVICE:
|
|
|
|
c->Request.Type.Direction = XFER_READ;
|
|
|
|
break;
|
|
|
|
case DMA_NONE:
|
|
|
|
c->Request.Type.Direction = XFER_NONE;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
case DMA_BIDIRECTIONAL:
|
|
|
|
// This can happen if a buggy application does a scsi passthru
|
|
|
|
// and sets both inlen and outlen to non-zero. ( see
|
|
|
|
// ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
c->Request.Type.Direction = XFER_RSVD;
|
2005-04-17 06:20:36 +08:00
|
|
|
// This is technically wrong, and cciss controllers should
|
|
|
|
// reject it with CMD_INVALID, which is the most correct
|
|
|
|
// response, but non-fibre backends appear to let it
|
|
|
|
// slide by, and give the same results as if this field
|
|
|
|
// were set correctly. Either way is acceptable for
|
|
|
|
// our purposes here.
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "unknown data direction: %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
cmd->sc_data_direction);
|
|
|
|
BUG();
|
|
|
|
break;
|
|
|
|
}
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_scatter_gather(h, c, cmd);
|
|
|
|
enqueue_cmd_and_start_io(h, c);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* the cmd'll come back via intr handler in complete_scsi_command() */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-16 15:10:29 +08:00
|
|
|
static DEF_SCSI_QCMD(cciss_scsi_queue_command)
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
static void cciss_unregister_scsi(ctlr_info_t *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct cciss_scsi_adapter_data_t *sa;
|
|
|
|
struct cciss_scsi_cmd_stack_t *stk;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* we are being forcibly unloaded, and may not refuse. */
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
sa = h->scsi_ctlr;
|
2005-04-17 06:20:36 +08:00
|
|
|
stk = &sa->cmd_stack;
|
|
|
|
|
|
|
|
/* if we weren't ever actually registered, don't unregister */
|
|
|
|
if (sa->registered) {
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_remove_host(sa->scsi_host);
|
|
|
|
scsi_host_put(sa->scsi_host);
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set scsi_host to NULL so our detect routine will
|
|
|
|
find us on register */
|
|
|
|
sa->scsi_host = NULL;
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
|
|
|
scsi_cmd_stack_free(h);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(sa);
|
|
|
|
}
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
static int cciss_engage_scsi(ctlr_info_t *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct cciss_scsi_adapter_data_t *sa;
|
|
|
|
struct cciss_scsi_cmd_stack_t *stk;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
sa = h->scsi_ctlr;
|
2005-04-17 06:20:36 +08:00
|
|
|
stk = &sa->cmd_stack;
|
|
|
|
|
2008-08-04 17:54:53 +08:00
|
|
|
if (sa->registered) {
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_info(&h->pdev->dev, "SCSI subsystem already engaged.\n");
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
2009-11-13 02:50:06 +08:00
|
|
|
return -ENXIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-08-04 17:54:53 +08:00
|
|
|
sa->registered = 1;
|
2010-07-20 02:46:38 +08:00
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
|
|
|
cciss_update_non_disk_devices(h, -1);
|
|
|
|
cciss_scsi_detect(h);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-20 02:46:38 +08:00
|
|
|
cciss_seq_tape_report(struct seq_file *seq, ctlr_info_t *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-07-20 02:46:38 +08:00
|
|
|
CPQ_TAPE_LOCK(h, flags);
|
2008-02-21 15:54:03 +08:00
|
|
|
seq_printf(seq,
|
2005-09-13 16:25:26 +08:00
|
|
|
"Sequential access devices: %d\n\n",
|
2010-07-20 02:46:38 +08:00
|
|
|
ccissscsi[h->ctlr].ndevices);
|
|
|
|
CPQ_TAPE_UNLOCK(h, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
static int wait_for_device_to_become_ready(ctlr_info_t *h,
|
|
|
|
unsigned char lunaddr[])
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int count = 0;
|
|
|
|
int waittime = HZ;
|
|
|
|
CommandList_struct *c;
|
|
|
|
|
2010-07-20 02:46:43 +08:00
|
|
|
c = cmd_alloc(h);
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
if (!c) {
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "out of memory in "
|
|
|
|
"wait_for_device_to_become_ready.\n");
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
return IO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send test unit ready until device ready, or give up. */
|
|
|
|
while (count < 20) {
|
|
|
|
|
|
|
|
/* Wait for a bit. do this first, because if we send
|
|
|
|
* the TUR right away, the reset will just abort it.
|
|
|
|
*/
|
2009-06-09 04:59:38 +08:00
|
|
|
schedule_timeout_uninterruptible(waittime);
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
count++;
|
|
|
|
|
|
|
|
/* Increase wait time with each try, up to a point. */
|
|
|
|
if (waittime < (HZ * 30))
|
|
|
|
waittime = waittime * 2;
|
|
|
|
|
|
|
|
/* Send the Test Unit Ready */
|
2010-07-20 02:46:38 +08:00
|
|
|
rc = fill_cmd(h, c, TEST_UNIT_READY, NULL, 0, 0,
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
lunaddr, TYPE_CMD);
|
2009-06-09 05:07:45 +08:00
|
|
|
if (rc == 0)
|
|
|
|
rc = sendcmd_withirq_core(h, c, 0);
|
|
|
|
|
|
|
|
(void) process_sendcmd_error(h, c);
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
|
2009-06-09 05:10:57 +08:00
|
|
|
if (rc != 0)
|
|
|
|
goto retry_tur;
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
|
2009-06-09 05:10:57 +08:00
|
|
|
if (c->err_info->CommandStatus == CMD_SUCCESS)
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
break;
|
|
|
|
|
2009-06-09 05:10:57 +08:00
|
|
|
if (c->err_info->CommandStatus == CMD_TARGET_STATUS &&
|
|
|
|
c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
|
|
|
|
if (c->err_info->SenseInfo[2] == NO_SENSE)
|
|
|
|
break;
|
|
|
|
if (c->err_info->SenseInfo[2] == UNIT_ATTENTION) {
|
|
|
|
unsigned char asc;
|
|
|
|
asc = c->err_info->SenseInfo[12];
|
|
|
|
check_for_unit_attention(h, c);
|
|
|
|
if (asc == POWER_OR_RESET)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retry_tur:
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "Waiting %d secs "
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
"for device to become ready.\n",
|
2010-07-20 02:46:48 +08:00
|
|
|
waittime / HZ);
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
rc = 1; /* device not ready. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc)
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "giving up on device.\n");
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
else
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "device is ready.\n");
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
|
2010-07-20 02:46:43 +08:00
|
|
|
cmd_free(h, c);
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2008-02-21 15:54:03 +08:00
|
|
|
|
2005-11-05 02:30:37 +08:00
|
|
|
/* Need at least one of these error handlers to keep ../scsi/hosts.c from
|
|
|
|
* complaining. Doing a host- or bus-reset can't do anything good here.
|
|
|
|
* Despite what it might say in scsi_error.c, there may well be commands
|
|
|
|
* on the controller, as the cciss driver registers twice, once as a block
|
|
|
|
* device for the logical drives, and once as a scsi device, for any tape
|
|
|
|
* drives. So we know there are no commands out on the tape drives, but we
|
|
|
|
* don't know there are no commands on the controller, and it is likely
|
|
|
|
* that there probably are, as the cciss block device is most commonly used
|
|
|
|
* as a boot device (embedded controller on HP/Compaq systems.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
CommandList_struct *cmd_in_trouble;
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
unsigned char lunaddr[8];
|
2010-07-20 02:46:38 +08:00
|
|
|
ctlr_info_t *h;
|
2005-11-05 02:30:37 +08:00
|
|
|
|
|
|
|
/* find the controller to which the command to be aborted was sent */
|
2010-07-20 02:46:38 +08:00
|
|
|
h = (ctlr_info_t *) scsicmd->device->host->hostdata[0];
|
|
|
|
if (h == NULL) /* paranoia */
|
2005-11-05 02:30:37 +08:00
|
|
|
return FAILED;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "resetting tape drive or medium changer.\n");
|
2005-11-05 02:30:37 +08:00
|
|
|
/* find the command that's giving us trouble */
|
|
|
|
cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble;
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
if (cmd_in_trouble == NULL) /* paranoia */
|
2005-11-05 02:30:37 +08:00
|
|
|
return FAILED;
|
cciss: fix SCSI device reset handler
Fix the SCSI reset error handler to send a working, properly addressed
reset message to the target device and add code to wait for the target
device to become ready by polling it with Test Unit Ready.
The existing reset code was broken in that it didn't bother to set the
8-byte LUN address to anything besides zero, so the command was addressed
to the controller, which pretended to the driver that the command
succeeded, while doing nothing. Ages ago I tested this code, but
unbeknownst to me, my test was flawed, and what I thought was a tape drive
getting reset was actually nothing of the sort. Unfortunately, there is
still lots of Smartarray firmware that doesn't handle doing target resets
right, and this code won't help in those cases, but it also shouldn't make
things worse in those cases than they already are.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Cc: Mike Miller <mikem@beardog.cca.cpqcorp.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-06-02 20:48:11 +08:00
|
|
|
memcpy(lunaddr, &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 8);
|
2005-11-05 02:30:37 +08:00
|
|
|
/* send a reset to the SCSI LUN which the command was sent to */
|
2010-07-20 02:46:38 +08:00
|
|
|
rc = sendcmd_withirq(h, CCISS_RESET_MSG, NULL, 0, 0, lunaddr,
|
2005-11-05 02:30:37 +08:00
|
|
|
TYPE_MSG);
|
2010-07-20 02:46:38 +08:00
|
|
|
if (rc == 0 && wait_for_device_to_become_ready(h, lunaddr) == 0)
|
2005-11-05 02:30:37 +08:00
|
|
|
return SUCCESS;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "resetting device failed.\n");
|
2005-11-05 02:30:37 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
CommandList_struct *cmd_to_abort;
|
2009-06-09 05:07:45 +08:00
|
|
|
unsigned char lunaddr[8];
|
2010-07-20 02:46:38 +08:00
|
|
|
ctlr_info_t *h;
|
2005-11-05 02:30:37 +08:00
|
|
|
|
|
|
|
/* find the controller to which the command to be aborted was sent */
|
2010-07-20 02:46:38 +08:00
|
|
|
h = (ctlr_info_t *) scsicmd->device->host->hostdata[0];
|
|
|
|
if (h == NULL) /* paranoia */
|
2005-11-05 02:30:37 +08:00
|
|
|
return FAILED;
|
2010-07-20 02:46:48 +08:00
|
|
|
dev_warn(&h->pdev->dev, "aborting tardy SCSI cmd\n");
|
2005-11-05 02:30:37 +08:00
|
|
|
|
|
|
|
/* find the command to be aborted */
|
|
|
|
cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble;
|
|
|
|
if (cmd_to_abort == NULL) /* paranoia */
|
|
|
|
return FAILED;
|
2009-06-09 05:07:45 +08:00
|
|
|
memcpy(lunaddr, &cmd_to_abort->Header.LUN.LunAddrBytes[0], 8);
|
2010-07-20 02:46:38 +08:00
|
|
|
rc = sendcmd_withirq(h, CCISS_ABORT_MSG, &cmd_to_abort->Header.Tag,
|
2009-06-09 05:07:45 +08:00
|
|
|
0, 0, lunaddr, TYPE_MSG);
|
2005-11-05 02:30:37 +08:00
|
|
|
if (rc == 0)
|
|
|
|
return SUCCESS;
|
|
|
|
return FAILED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#else /* no CONFIG_CISS_SCSI_TAPE */
|
|
|
|
|
|
|
|
/* If no tape support, then these become defined out of existence */
|
|
|
|
|
|
|
|
#define cciss_scsi_setup(cntl_num)
|
cciss: auto engage SCSI mid layer at driver load time
A long time ago, probably in 2002, one of the distros, or maybe more than
one, loaded block drivers prior to loading the SCSI mid layer. This meant
that the cciss driver, being a block driver, could not engage the SCSI mid
layer at init time without panicking, and relied on being poked by a
userland program after the system was up (and the SCSI mid layer was
therefore present) to engage the SCSI mid layer.
This is no longer the case, and cciss can safely rely on the SCSI mid
layer being present at init time and engage the SCSI mid layer straight
away. This means that users will see their tape drives and medium
changers at driver load time without need for a script in /etc/rc.d that
does this:
for x in /proc/driver/cciss/cciss*
do
echo "engage scsi" > $x
done
However, if no tape drives or medium changers are detected, the SCSI mid
layer will not be engaged. If a tape drive or medium change is later
hot-added to the system it will then be necessary to use the above script
or similar for the device(s) to be acceesible.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2011-11-16 16:21:49 +08:00
|
|
|
#define cciss_engage_scsi(h)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* CONFIG_CISS_SCSI_TAPE */
|