summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2008-03-25 11:35:49 +1100
committerStephen Rothwell <sfr@canb.auug.org.au>2008-03-25 11:35:49 +1100
commitba04dff62fcb6668b691b9fc952773bb19a5734f (patch)
tree9b7b9735ce1d6e6610e58d644f952fd4ac6377cd
parentcab5ea0ec3db13d3239f4297ffc9cf182082cde3 (diff)
parent030cd6634ba3399186b637fa637bfb7604d22822 (diff)
Merge commit 'scsi/master'
-rw-r--r--Documentation/scsi/st.txt12
-rw-r--r--arch/ia64/hp/sim/simscsi.c23
-rw-r--r--drivers/base/transport_class.c2
-rw-r--r--drivers/message/fusion/mptbase.c27
-rw-r--r--drivers/message/fusion/mptbase.h4
-rw-r--r--drivers/message/fusion/mptscsih.c8
-rw-r--r--drivers/s390/scsi/zfcp_def.h1
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c7
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c64
-rw-r--r--drivers/scsi/3w-9xxx.c21
-rw-r--r--drivers/scsi/3w-xxxx.c12
-rw-r--r--drivers/scsi/BusLogic.c5
-rw-r--r--drivers/scsi/BusLogic.h21
-rw-r--r--drivers/scsi/FlashPoint.c6
-rw-r--r--drivers/scsi/Kconfig14
-rw-r--r--drivers/scsi/aacraid/aachba.c67
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c7
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c10
-rw-r--r--drivers/scsi/aic94xx/aic94xx.h16
-rw-r--r--drivers/scsi/aic94xx/aic94xx_hwi.c20
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c2
-rw-r--r--drivers/scsi/arm/acornscsi.c1
-rw-r--r--drivers/scsi/arm/cumana_1.c1
-rw-r--r--drivers/scsi/dc395x.c1
-rw-r--r--drivers/scsi/eata_pio.c2
-rw-r--r--drivers/scsi/gdth.c320
-rw-r--r--drivers/scsi/gdth.h2
-rw-r--r--drivers/scsi/hptiop.c1
-rw-r--r--drivers/scsi/ips.c49
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c41
-rw-r--r--drivers/scsi/mac_scsi.c1
-rw-r--r--drivers/scsi/ps3rom.c94
-rw-r--r--drivers/scsi/qla4xxx/ql4_fw.h1
-rw-r--r--drivers/scsi/qla4xxx/ql4_glbl.h2
-rw-r--r--drivers/scsi/qla4xxx/ql4_mbx.c39
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c82
-rw-r--r--drivers/scsi/raid_class.c2
-rw-r--r--drivers/scsi/scsi.c227
-rw-r--r--drivers/scsi/scsi_debug.c755
-rw-r--r--drivers/scsi/scsi_debug.h24
-rw-r--r--drivers/scsi/scsi_error.c122
-rw-r--r--drivers/scsi/st.c83
-rw-r--r--drivers/scsi/st.h3
-rw-r--r--drivers/scsi/st_options.h6
-rw-r--r--drivers/scsi/stex.c66
-rw-r--r--include/linux/attribute_container.h2
-rw-r--r--include/linux/mtio.h1
-rw-r--r--include/linux/scatterlist.h5
-rw-r--r--include/linux/transport_class.h4
-rw-r--r--include/scsi/libsas.h2
-rw-r--r--include/scsi/scsi_cmnd.h17
-rw-r--r--include/scsi/scsi_eh.h1
-rw-r--r--include/scsi/scsi_host.h1
-rw-r--r--lib/scatterlist.c102
54 files changed, 1259 insertions, 1150 deletions
diff --git a/Documentation/scsi/st.txt b/Documentation/scsi/st.txt
index b7be95b5bd24..40752602c050 100644
--- a/Documentation/scsi/st.txt
+++ b/Documentation/scsi/st.txt
@@ -2,7 +2,7 @@ This file contains brief information about the SCSI tape driver.
The driver is currently maintained by Kai Mäkisara (email
Kai.Makisara@kolumbus.fi)
-Last modified: Mon Mar 7 21:14:44 2005 by kai.makisara
+Last modified: Sun Feb 24 21:59:07 2008 by kai.makisara
BASICS
@@ -133,6 +133,11 @@ the defaults set by the user. The value -1 means the default is not set. The
file 'dev' contains the device numbers corresponding to this device. The links
'device' and 'driver' point to the SCSI device and driver entries.
+Each directory also contains the entry 'options' which shows the currently
+enabled driver and mode options. The value in the file is a bit mask where the
+bit definitions are the same as those used with MTSETDRVBUFFER in setting the
+options.
+
A link named 'tape' is made from the SCSI device directory to the class
directory corresponding to the mode 0 auto-rewind device (e.g., st0).
@@ -372,6 +377,11 @@ MTSETDRVBUFFER
MT_ST_SYSV sets the SYSV semantics (mode)
MT_ST_NOWAIT enables immediate mode (i.e., don't wait for
the command to finish) for some commands (e.g., rewind)
+ MT_ST_SILI enables setting the SILI bit in SCSI commands when
+ reading in variable block mode to enhance performance when
+ reading blocks shorter than the byte count; set this only
+ if you are sure that the drive supports SILI and the HBA
+ correctly returns transfer residuals
MT_ST_DEBUGGING debugging (global; debugging must be
compiled into the driver)
MT_ST_SETBOOLEANS
diff --git a/arch/ia64/hp/sim/simscsi.c b/arch/ia64/hp/sim/simscsi.c
index 7661bb065fa5..3a078ad3aa44 100644
--- a/arch/ia64/hp/sim/simscsi.c
+++ b/arch/ia64/hp/sim/simscsi.c
@@ -201,22 +201,6 @@ simscsi_readwrite10 (struct scsi_cmnd *sc, int mode)
simscsi_sg_readwrite(sc, mode, offset);
}
-static void simscsi_fillresult(struct scsi_cmnd *sc, char *buf, unsigned len)
-{
-
- int i;
- unsigned thislen;
- struct scatterlist *slp;
-
- scsi_for_each_sg(sc, slp, scsi_sg_count(sc), i) {
- if (!len)
- break;
- thislen = min(len, slp->length);
- memcpy(sg_virt(slp), buf, thislen);
- len -= thislen;
- }
-}
-
static int
simscsi_queuecommand (struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
{
@@ -258,7 +242,7 @@ simscsi_queuecommand (struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
buf[6] = 0; /* reserved */
buf[7] = 0; /* various flags */
memcpy(buf + 8, "HP SIMULATED DISK 0.00", 28);
- simscsi_fillresult(sc, buf, 36);
+ scsi_sg_copy_from_buffer(sc, buf, 36);
sc->result = GOOD;
break;
@@ -306,14 +290,15 @@ simscsi_queuecommand (struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
buf[5] = 0;
buf[6] = 2;
buf[7] = 0;
- simscsi_fillresult(sc, buf, 8);
+ scsi_sg_copy_from_buffer(sc, buf, 8);
sc->result = GOOD;
break;
case MODE_SENSE:
case MODE_SENSE_10:
/* sd.c uses this to determine whether disk does write-caching. */
- simscsi_fillresult(sc, (char *)empty_zero_page, scsi_bufflen(sc));
+ scsi_sg_copy_from_buffer(sc, (char *)empty_zero_page,
+ PAGE_SIZE);
sc->result = GOOD;
break;
diff --git a/drivers/base/transport_class.c b/drivers/base/transport_class.c
index 72cf4629a7f5..cb08f1c13996 100644
--- a/drivers/base/transport_class.c
+++ b/drivers/base/transport_class.c
@@ -108,7 +108,7 @@ EXPORT_SYMBOL_GPL(anon_transport_class_register);
*/
void anon_transport_class_unregister(struct anon_transport_class *atc)
{
- attribute_container_unregister(&atc->container);
+ BUG_ON(attribute_container_unregister(&atc->container));
}
EXPORT_SYMBOL_GPL(anon_transport_class_unregister);
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index c6be6eba7dc3..a34ddc7bce80 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -79,7 +79,7 @@ MODULE_VERSION(my_VERSION);
/*
* cmd line parameters
*/
-static int mpt_msi_enable;
+static int mpt_msi_enable = -1;
module_param(mpt_msi_enable, int, 0);
MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)");
@@ -1686,6 +1686,11 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
ioc->bus_type = SAS;
}
+ if (ioc->bus_type == SAS && mpt_msi_enable == -1)
+ ioc->msi_enable = 1;
+ else
+ ioc->msi_enable = mpt_msi_enable;
+
if (ioc->errata_flag_1064)
pci_disable_io_access(pdev);
@@ -2057,15 +2062,17 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
ioc->pci_irq = -1;
if (ioc->pcidev->irq) {
- if (mpt_msi_enable && !pci_enable_msi(ioc->pcidev))
+ if (ioc->msi_enable && !pci_enable_msi(ioc->pcidev))
printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
ioc->name);
+ else
+ ioc->msi_enable = 0;
rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
IRQF_SHARED, ioc->name, ioc);
if (rc < 0) {
printk(MYIOC_s_ERR_FMT "Unable to allocate "
"interrupt %d!\n", ioc->name, ioc->pcidev->irq);
- if (mpt_msi_enable)
+ if (ioc->msi_enable)
pci_disable_msi(ioc->pcidev);
return -EBUSY;
}
@@ -2173,7 +2180,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
/*
* Initalize link list for inactive raid volumes.
*/
- init_MUTEX(&ioc->raid_data.inactive_list_mutex);
+ mutex_init(&ioc->raid_data.inactive_list_mutex);
INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
if (ioc->bus_type == SAS) {
@@ -2261,7 +2268,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
out:
if ((ret != 0) && irq_allocated) {
free_irq(ioc->pci_irq, ioc);
- if (mpt_msi_enable)
+ if (ioc->msi_enable)
pci_disable_msi(ioc->pcidev);
}
return ret;
@@ -2443,7 +2450,7 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
if (ioc->pci_irq != -1) {
free_irq(ioc->pci_irq, ioc);
- if (mpt_msi_enable)
+ if (ioc->msi_enable)
pci_disable_msi(ioc->pcidev);
ioc->pci_irq = -1;
}
@@ -5159,13 +5166,13 @@ mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
if (list_empty(&ioc->raid_data.inactive_list))
return;
- down(&ioc->raid_data.inactive_list_mutex);
+ mutex_lock(&ioc->raid_data.inactive_list_mutex);
list_for_each_entry_safe(component_info, pNext,
&ioc->raid_data.inactive_list, list) {
list_del(&component_info->list);
kfree(component_info);
}
- up(&ioc->raid_data.inactive_list_mutex);
+ mutex_unlock(&ioc->raid_data.inactive_list_mutex);
}
/**
@@ -5224,7 +5231,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
if (!handle_inactive_volumes)
goto out;
- down(&ioc->raid_data.inactive_list_mutex);
+ mutex_lock(&ioc->raid_data.inactive_list_mutex);
for (i = 0; i < buffer->NumPhysDisks; i++) {
if(mpt_raid_phys_disk_pg0(ioc,
buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
@@ -5244,7 +5251,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
list_add_tail(&component_info->list,
&ioc->raid_data.inactive_list);
}
- up(&ioc->raid_data.inactive_list_mutex);
+ mutex_unlock(&ioc->raid_data.inactive_list_mutex);
out:
if (buffer)
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index caadc68c3000..0041ab3e5e80 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -51,6 +51,7 @@
#include <linux/kernel.h>
#include <linux/pci.h>
+#include <linux/mutex.h>
#include "lsi/mpi_type.h"
#include "lsi/mpi.h" /* Fusion MPI(nterface) basic defs */
@@ -531,7 +532,7 @@ struct inactive_raid_component_info {
typedef struct _RaidCfgData {
IOCPage2_t *pIocPg2; /* table of Raid Volumes */
IOCPage3_t *pIocPg3; /* table of physical disks */
- struct semaphore inactive_list_mutex;
+ struct mutex inactive_list_mutex;
struct list_head inactive_list; /* link list for physical
disk that belong in
inactive volumes */
@@ -630,6 +631,7 @@ typedef struct _MPT_ADAPTER
int mtrr_reg;
struct pci_dev *pcidev; /* struct pci_dev pointer */
int bars; /* bitmask of BAR's that must be configured */
+ int msi_enable;
u8 __iomem *memmap; /* mmap address */
struct Scsi_Host *sh; /* Scsi Host pointer */
SpiCfgData spi_data; /* Scsi config. data */
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index f06d9da5385a..b109bd8a4d19 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -2304,14 +2304,14 @@ mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
if (list_empty(&ioc->raid_data.inactive_list))
goto out;
- down(&ioc->raid_data.inactive_list_mutex);
+ mutex_lock(&ioc->raid_data.inactive_list_mutex);
list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
list) {
if ((component_info->d.PhysDiskID == id) &&
(component_info->d.PhysDiskBus == channel))
rc = 1;
}
- up(&ioc->raid_data.inactive_list_mutex);
+ mutex_unlock(&ioc->raid_data.inactive_list_mutex);
out:
return rc;
@@ -2341,14 +2341,14 @@ mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
if (list_empty(&ioc->raid_data.inactive_list))
goto out;
- down(&ioc->raid_data.inactive_list_mutex);
+ mutex_lock(&ioc->raid_data.inactive_list_mutex);
list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
list) {
if ((component_info->d.PhysDiskID == id) &&
(component_info->d.PhysDiskBus == channel))
rc = component_info->d.PhysDiskNum;
}
- up(&ioc->raid_data.inactive_list_mutex);
+ mutex_unlock(&ioc->raid_data.inactive_list_mutex);
out:
return rc;
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index 9e9f6c1e4e5d..662c70f537ec 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -634,7 +634,6 @@ do { \
ZFCP_STATUS_PORT_NO_SCSI_ID)
/* logical unit status */
-#define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
#define ZFCP_STATUS_UNIT_SHARED 0x00000004
#define ZFCP_STATUS_UNIT_READONLY 0x00000008
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 0dff05840ee2..2ed3c7b48882 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -2968,6 +2968,13 @@ zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
zfcp_erp_port_boxed(port);
fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
ZFCP_STATUS_FSFREQ_RETRY;
+
+ /* can't use generic zfcp_erp_modify_port_status because
+ * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
+ atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
+ list_for_each_entry(unit, &port->unit_list_head, list)
+ atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
+ &unit->status);
break;
case FSF_ADAPTER_STATUS_AVAILABLE:
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index b9daf5c05862..ff97a61ad964 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -31,6 +31,7 @@ static int zfcp_scsi_queuecommand(struct scsi_cmnd *,
void (*done) (struct scsi_cmnd *));
static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *);
static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *);
+static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *);
static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *);
static int zfcp_task_management_function(struct zfcp_unit *, u8,
struct scsi_cmnd *);
@@ -51,6 +52,7 @@ struct zfcp_data zfcp_data = {
.queuecommand = zfcp_scsi_queuecommand,
.eh_abort_handler = zfcp_scsi_eh_abort_handler,
.eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
+ .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
.eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
.can_queue = 4096,
.this_id = -1,
@@ -442,58 +444,32 @@ static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
return retval;
}
-static int
-zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
+static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
{
int retval;
- struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
+ struct zfcp_unit *unit = scpnt->device->hostdata;
if (!unit) {
- ZFCP_LOG_NORMAL("bug: Tried reset for nonexistent unit\n");
- retval = SUCCESS;
- goto out;
+ WARN_ON(1);
+ return SUCCESS;
}
- ZFCP_LOG_NORMAL("resetting unit 0x%016Lx on port 0x%016Lx, adapter %s\n",
- unit->fcp_lun, unit->port->wwpn,
- zfcp_get_busid_by_adapter(unit->port->adapter));
+ retval = zfcp_task_management_function(unit,
+ FCP_LOGICAL_UNIT_RESET,
+ scpnt);
+ return retval ? FAILED : SUCCESS;
+}
- /*
- * If we do not know whether the unit supports 'logical unit reset'
- * then try 'logical unit reset' and proceed with 'target reset'
- * if 'logical unit reset' fails.
- * If the unit is known not to support 'logical unit reset' then
- * skip 'logical unit reset' and try 'target reset' immediately.
- */
- if (!atomic_test_mask(ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
- &unit->status)) {
- retval = zfcp_task_management_function(unit,
- FCP_LOGICAL_UNIT_RESET,
- scpnt);
- if (retval) {
- ZFCP_LOG_DEBUG("unit reset failed (unit=%p)\n", unit);
- if (retval == -ENOTSUPP)
- atomic_set_mask
- (ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
- &unit->status);
- /* fall through and try 'target reset' next */
- } else {
- ZFCP_LOG_DEBUG("unit reset succeeded (unit=%p)\n",
- unit);
- /* avoid 'target reset' */
- retval = SUCCESS;
- goto out;
- }
+static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
+{
+ int retval;
+ struct zfcp_unit *unit = scpnt->device->hostdata;
+
+ if (!unit) {
+ WARN_ON(1);
+ return SUCCESS;
}
retval = zfcp_task_management_function(unit, FCP_TARGET_RESET, scpnt);
- if (retval) {
- ZFCP_LOG_DEBUG("target reset failed (unit=%p)\n", unit);
- retval = FAILED;
- } else {
- ZFCP_LOG_DEBUG("target reset succeeded (unit=%p)\n", unit);
- retval = SUCCESS;
- }
- out:
- return retval;
+ return retval ? FAILED : SUCCESS;
}
static int
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 9572fd8d8c3e..e6ec0a4e693e 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1839,12 +1839,11 @@ static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
if (scsi_sg_count(srb)) {
if ((scsi_sg_count(srb) == 1) &&
(scsi_bufflen(srb) < TW_MIN_SGL_LENGTH)) {
- if (srb->sc_data_direction == DMA_TO_DEVICE || srb->sc_data_direction == DMA_BIDIRECTIONAL) {
- struct scatterlist *sg = scsi_sglist(srb);
- char *buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
- memcpy(tw_dev->generic_buffer_virt[request_id], buf, sg->length);
- kunmap_atomic(buf - sg->offset, KM_IRQ0);
- }
+ if (srb->sc_data_direction == DMA_TO_DEVICE ||
+ srb->sc_data_direction == DMA_BIDIRECTIONAL)
+ scsi_sg_copy_to_buffer(srb,
+ tw_dev->generic_buffer_virt[request_id],
+ TW_SECTOR_SIZE);
command_packet->sg_list[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
command_packet->sg_list[0].length = cpu_to_le32(TW_MIN_SGL_LENGTH);
} else {
@@ -1916,13 +1915,11 @@ static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int re
(cmd->sc_data_direction == DMA_FROM_DEVICE ||
cmd->sc_data_direction == DMA_BIDIRECTIONAL)) {
if (scsi_sg_count(cmd) == 1) {
- struct scatterlist *sg = scsi_sglist(tw_dev->srb[request_id]);
- char *buf;
- unsigned long flags = 0;
+ unsigned long flags;
+ void *buf = tw_dev->generic_buffer_virt[request_id];
+
local_irq_save(flags);
- buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
- memcpy(buf, tw_dev->generic_buffer_virt[request_id], sg->length);
- kunmap_atomic(buf - sg->offset, KM_IRQ0);
+ scsi_sg_copy_from_buffer(cmd, buf, TW_SECTOR_SIZE);
local_irq_restore(flags);
}
}
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index f4be1e748fc1..4d0cbb5db0a5 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1464,18 +1464,10 @@ static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
void *data, unsigned int len)
{
struct scsi_cmnd *cmd = tw_dev->srb[request_id];
- void *buf;
- unsigned int transfer_len;
- unsigned long flags = 0;
- struct scatterlist *sg = scsi_sglist(cmd);
+ unsigned long flags;
local_irq_save(flags);
- buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
- transfer_len = min(sg->length, len);
-
- memcpy(buf, data, transfer_len);
-
- kunmap_atomic(buf - sg->offset, KM_IRQ0);
+ scsi_sg_copy_from_buffer(cmd, data, len);
local_irq_restore(flags);
}
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 4d3ebb1af490..2d689af24664 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -896,7 +896,7 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
IRQ_Channel = PCI_Device->irq;
IO_Address = BaseAddress0 = pci_resource_start(PCI_Device, 0);
PCI_Address = BaseAddress1 = pci_resource_start(PCI_Device, 1);
-#ifndef CONFIG_SCSI_OMIT_FLASHPOINT
+#ifdef CONFIG_SCSI_FLASHPOINT
if (pci_resource_flags(PCI_Device, 0) & IORESOURCE_MEM) {
BusLogic_Error("BusLogic: Base Address0 0x%X not I/O for " "FlashPoint Host Adapter\n", NULL, BaseAddress0);
BusLogic_Error("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, Bus, Device, IO_Address);
@@ -1006,6 +1006,9 @@ static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
}
+#else
+#define BusLogic_InitializeProbeInfoList(adapter) \
+ BusLogic_InitializeProbeInfoListISA(adapter)
#endif /* CONFIG_PCI */
diff --git a/drivers/scsi/BusLogic.h b/drivers/scsi/BusLogic.h
index bfbfb5c3a8f6..73f237a1ed94 100644
--- a/drivers/scsi/BusLogic.h
+++ b/drivers/scsi/BusLogic.h
@@ -34,23 +34,6 @@
#endif
/*
- FlashPoint support is only available for the Intel x86 Architecture with
- CONFIG_PCI set.
-*/
-
-#ifndef __i386__
-#undef CONFIG_SCSI_OMIT_FLASHPOINT
-#define CONFIG_SCSI_OMIT_FLASHPOINT
-#endif
-
-#ifndef CONFIG_PCI
-#undef CONFIG_SCSI_OMIT_FLASHPOINT
-#define CONFIG_SCSI_OMIT_FLASHPOINT
-#define BusLogic_InitializeProbeInfoListISA BusLogic_InitializeProbeInfoList
-#endif
-
-
-/*
Define the maximum number of BusLogic Host Adapters supported by this driver.
*/
@@ -178,7 +161,7 @@ static int BusLogic_HostAdapterAddressCount[3] = { 0, BusLogic_MultiMasterAddres
Define macros for testing the Host Adapter Type.
*/
-#ifndef CONFIG_SCSI_OMIT_FLASHPOINT
+#ifdef CONFIG_SCSI_FLASHPOINT
#define BusLogic_MultiMasterHostAdapterP(HostAdapter) \
(HostAdapter->HostAdapterType == BusLogic_MultiMaster)
@@ -871,7 +854,7 @@ struct BusLogic_CCB {
void (*CallbackFunction) (struct BusLogic_CCB *); /* Bytes 40-43 */
u32 BaseAddress; /* Bytes 44-47 */
enum BusLogic_CompletionCode CompletionCode; /* Byte 48 */
-#ifndef CONFIG_SCSI_OMIT_FLASHPOINT
+#ifdef CONFIG_SCSI_FLASHPOINT
unsigned char:8; /* Byte 49 */
unsigned short OS_Flags; /* Bytes 50-51 */
unsigned char Private[48]; /* Bytes 52-99 */
diff --git a/drivers/scsi/FlashPoint.c b/drivers/scsi/FlashPoint.c
index 1c9078191d9e..b374e457e5e2 100644
--- a/drivers/scsi/FlashPoint.c
+++ b/drivers/scsi/FlashPoint.c
@@ -16,7 +16,7 @@
*/
-#ifndef CONFIG_SCSI_OMIT_FLASHPOINT
+#ifdef CONFIG_SCSI_FLASHPOINT
#define MAX_CARDS 8
#undef BUSTYPE_PCI
@@ -7626,7 +7626,7 @@ FlashPoint__HandleInterrupt(FlashPoint_CardHandle_T CardHandle)
#define FlashPoint_InterruptPending FlashPoint__InterruptPending
#define FlashPoint_HandleInterrupt FlashPoint__HandleInterrupt
-#else /* CONFIG_SCSI_OMIT_FLASHPOINT */
+#else /* !CONFIG_SCSI_FLASHPOINT */
/*
Define prototypes for the FlashPoint SCCB Manager Functions.
@@ -7641,4 +7641,4 @@ extern bool FlashPoint_InterruptPending(FlashPoint_CardHandle_T);
extern int FlashPoint_HandleInterrupt(FlashPoint_CardHandle_T);
extern void FlashPoint_ReleaseHostAdapter(FlashPoint_CardHandle_T);
-#endif /* CONFIG_SCSI_OMIT_FLASHPOINT */
+#endif /* CONFIG_SCSI_FLASHPOINT */
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index b9d374082b65..7f78e3ea517d 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -588,18 +588,20 @@ config SCSI_BUSLOGIC
<http://www.tldp.org/docs.html#howto>, and the files
<file:Documentation/scsi/BusLogic.txt> and
<file:Documentation/scsi/FlashPoint.txt> for more information.
+ Note that support for FlashPoint is only available for 32-bit
+ x86 configurations.
To compile this driver as a module, choose M here: the
module will be called BusLogic.
-config SCSI_OMIT_FLASHPOINT
- bool "Omit FlashPoint support"
- depends on SCSI_BUSLOGIC
+config SCSI_FLASHPOINT
+ bool "FlashPoint support"
+ depends on SCSI_BUSLOGIC && PCI && X86_32
help
- This option allows you to omit the FlashPoint support from the
+ This option allows you to add FlashPoint support to the
BusLogic SCSI driver. The FlashPoint SCCB Manager code is
- substantial, so users of MultiMaster Host Adapters may wish to omit
- it.
+ substantial, so users of MultiMaster Host Adapters may not
+ wish to include it.
config SCSI_DMX3191D
tristate "DMX3191D SCSI support"
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 6f3e50738043..9840945339c8 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -379,24 +379,6 @@ int aac_get_containers(struct aac_dev *dev)
return status;
}
-static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
-{
- void *buf;
- int transfer_len;
- struct scatterlist *sg = scsi_sglist(scsicmd);
-
- buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
- transfer_len = min(sg->length, len + offset);
-
- transfer_len -= offset;
- if (buf && transfer_len > 0)
- memcpy(buf + offset, data, transfer_len);
-
- flush_kernel_dcache_page(kmap_atomic_to_page(buf - sg->offset));
- kunmap_atomic(buf - sg->offset, KM_IRQ0);
-
-}
-
static void get_container_name_callback(void *context, struct fib * fibptr)
{
struct aac_get_name_resp * get_name_reply;
@@ -419,14 +401,17 @@ static void get_container_name_callback(void *context, struct fib * fibptr)
while (*sp == ' ')
++sp;
if (*sp) {
+ struct inquiry_data inq;
char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
int count = sizeof(d);
char *dp = d;
do {
*dp++ = (*sp) ? *sp++ : ' ';
} while (--count > 0);
- aac_internal_transfer(scsicmd, d,
- offsetof(struct inquiry_data, inqd_pid), sizeof(d));
+
+ scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
+ memcpy(inq.inqd_pid, d, sizeof(d));
+ scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
}
}
@@ -811,7 +796,7 @@ static void get_container_serial_callback(void *context, struct fib * fibptr)
sp[2] = 0;
sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
le32_to_cpu(get_serial_reply->uid));
- aac_internal_transfer(scsicmd, sp, 0, sizeof(sp));
+ scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp));
}
scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
@@ -1986,8 +1971,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
arr[4] = 0x0;
arr[5] = 0x80;
arr[1] = scsicmd->cmnd[2];
- aac_internal_transfer(scsicmd, &inq_data, 0,
- sizeof(inq_data));
+ scsi_sg_copy_from_buffer(scsicmd, &inq_data,
+ sizeof(inq_data));
scsicmd->result = DID_OK << 16 |
COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
} else if (scsicmd->cmnd[2] == 0x80) {
@@ -1995,8 +1980,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
arr[3] = setinqserial(dev, &arr[4],
scmd_id(scsicmd));
arr[1] = scsicmd->cmnd[2];
- aac_internal_transfer(scsicmd, &inq_data, 0,
- sizeof(inq_data));
+ scsi_sg_copy_from_buffer(scsicmd, &inq_data,
+ sizeof(inq_data));
return aac_get_container_serial(scsicmd);
} else {
/* vpd page not implemented */
@@ -2027,7 +2012,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
if (cid == host->this_id) {
setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
- aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
+ scsi_sg_copy_from_buffer(scsicmd, &inq_data,
+ sizeof(inq_data));
scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
scsicmd->scsi_done(scsicmd);
return 0;
@@ -2036,7 +2022,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
return -1;
setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
- aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
+ scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
return aac_get_container_name(scsicmd);
}
case SERVICE_ACTION_IN:
@@ -2047,6 +2033,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
{
u64 capacity;
char cp[13];
+ unsigned int alloc_len;
dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
capacity = fsa_dev_ptr[cid].size - 1;
@@ -2063,18 +2050,16 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
cp[10] = 2;
cp[11] = 0;
cp[12] = 0;
- aac_internal_transfer(scsicmd, cp, 0,
- min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
- if (sizeof(cp) < scsicmd->cmnd[13]) {
- unsigned int len, offset = sizeof(cp);
- memset(cp, 0, offset);
- do {
- len = min_t(size_t, scsicmd->cmnd[13] - offset,
- sizeof(cp));
- aac_internal_transfer(scsicmd, cp, offset, len);
- } while ((offset += len) < scsicmd->cmnd[13]);
- }
+ alloc_len = ((scsicmd->cmnd[10] << 24)
+ + (scsicmd->cmnd[11] << 16)
+ + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
+
+ alloc_len = min_t(size_t, alloc_len, sizeof(cp));
+ scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
+ if (alloc_len < scsi_bufflen(scsicmd))
+ scsi_set_resid(scsicmd,
+ scsi_bufflen(scsicmd) - alloc_len);
/* Do not cache partition table for arrays */
scsicmd->device->removable = 1;
@@ -2104,7 +2089,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
cp[5] = 0;
cp[6] = 2;
cp[7] = 0;
- aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
+ scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
/* Do not cache partition table for arrays */
scsicmd->device->removable = 1;
@@ -2139,7 +2124,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
if (mode_buf_length > scsicmd->cmnd[4])
mode_buf_length = scsicmd->cmnd[4];
}
- aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
+ scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
scsicmd->scsi_done(scsicmd);
@@ -2174,7 +2159,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
if (mode_buf_length > scsicmd->cmnd[8])
mode_buf_length = scsicmd->cmnd[8];
}
- aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
+ scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
scsicmd->scsi_done(scsicmd);
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 72fccd9f40df..0081aa357c8b 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1413,6 +1413,10 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
unsigned long flags;
int nseg;
+ nseg = scsi_dma_map(cmd);
+ if (nseg < 0)
+ return SCSI_MLQUEUE_HOST_BUSY;
+
ahd_lock(ahd, &flags);
/*
@@ -1430,6 +1434,7 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
ahd->flags |= AHD_RESOURCE_SHORTAGE;
ahd_unlock(ahd, &flags);
+ scsi_dma_unmap(cmd);
return SCSI_MLQUEUE_HOST_BUSY;
}
@@ -1485,8 +1490,6 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
ahd_set_sense_residual(scb, 0);
scb->sg_count = 0;
- nseg = scsi_dma_map(cmd);
- BUG_ON(nseg < 0);
if (nseg > 0) {
void *sg = scb->sg_list;
struct scatterlist *cur_seg;
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index 282aff6f852e..42ad48e09f02 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1398,12 +1398,18 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
return SCSI_MLQUEUE_DEVICE_BUSY;
}
+ nseg = scsi_dma_map(cmd);
+ if (nseg < 0)
+ return SCSI_MLQUEUE_HOST_BUSY;
+
/*
* Get an scb to use.
*/
scb = ahc_get_scb(ahc);
- if (!scb)
+ if (!scb) {
+ scsi_dma_unmap(cmd);
return SCSI_MLQUEUE_HOST_BUSY;
+ }
scb->io_ctx = cmd;
scb->platform_data->dev = dev;
@@ -1464,8 +1470,6 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
ahc_set_sense_residual(scb, 0);
scb->sg_count = 0;
- nseg = scsi_dma_map(cmd);
- BUG_ON(nseg < 0);
if (nseg > 0) {
struct ahc_dma_seg *sg;
struct scatterlist *cur_seg;
diff --git a/drivers/scsi/aic94xx/aic94xx.h b/drivers/scsi/aic94xx/aic94xx.h
index eb8efdcefe48..2ef459e9cda1 100644
--- a/drivers/scsi/aic94xx/aic94xx.h
+++ b/drivers/scsi/aic94xx/aic94xx.h
@@ -58,7 +58,6 @@
extern struct kmem_cache *asd_dma_token_cache;
extern struct kmem_cache *asd_ascb_cache;
-extern char sas_addr_str[2*SAS_ADDR_SIZE + 1];
static inline void asd_stringify_sas_addr(char *p, const u8 *sas_addr)
{
@@ -68,21 +67,6 @@ static inline void asd_stringify_sas_addr(char *p, const u8 *sas_addr)
*p = '\0';
}
-static inline void asd_destringify_sas_addr(u8 *sas_addr, const char *p)
-{
- int i;
- for (i = 0; i < SAS_ADDR_SIZE; i++) {
- u8 h, l;
- if (!*p)
- break;
- h = isdigit(*p) ? *p-'0' : *p-'A'+10;
- p++;
- l = isdigit(*p) ? *p-'0' : *p-'A'+10;
- p++;
- sas_addr[i] = (h<<4) | l;
- }
-}
-
struct asd_ha_struct;
struct asd_ascb;
diff --git a/drivers/scsi/aic94xx/aic94xx_hwi.c b/drivers/scsi/aic94xx/aic94xx_hwi.c
index 098b5f39cd31..940a207a42fb 100644
--- a/drivers/scsi/aic94xx/aic94xx_hwi.c
+++ b/drivers/scsi/aic94xx/aic94xx_hwi.c
@@ -27,6 +27,7 @@
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/module.h>
+#include <linux/firmware.h>
#include "aic94xx.h"
#include "aic94xx_reg.h"
@@ -38,16 +39,14 @@ u32 MBAR0_SWB_SIZE;
/* ---------- Initialization ---------- */
-static void asd_get_user_sas_addr(struct asd_ha_struct *asd_ha)
+static int asd_get_user_sas_addr(struct asd_ha_struct *asd_ha)
{
- extern char sas_addr_str[];
- /* If the user has specified a WWN it overrides other settings
- */
- if (sas_addr_str[0] != '\0')
- asd_destringify_sas_addr(asd_ha->hw_prof.sas_addr,
- sas_addr_str);
- else if (asd_ha->hw_prof.sas_addr[0] != 0)
- asd_stringify_sas_addr(sas_addr_str, asd_ha->hw_prof.sas_addr);
+ /* adapter came with a sas address */
+ if (asd_ha->hw_prof.sas_addr[0])
+ return 0;
+
+ return sas_request_addr(asd_ha->sas_ha.core.shost,
+ asd_ha->hw_prof.sas_addr);
}
static void asd_propagate_sas_addr(struct asd_ha_struct *asd_ha)
@@ -657,8 +656,7 @@ int asd_init_hw(struct asd_ha_struct *asd_ha)
asd_init_ctxmem(asd_ha);
- asd_get_user_sas_addr(asd_ha);
- if (!asd_ha->hw_prof.sas_addr[0]) {
+ if (asd_get_user_sas_addr(asd_ha)) {
asd_printk("No SAS Address provided for %s\n",
pci_name(asd_ha->pcidev));
err = -ENODEV;
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index 88d1e731b65e..806fa4d9a648 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -56,8 +56,6 @@ MODULE_PARM_DESC(collector, "\n"
"\tThe aic94xx SAS LLDD supports both modes.\n"
"\tDefault: 0 (Direct Mode).\n");
-char sas_addr_str[2*SAS_ADDR_SIZE + 1] = "";
-
static struct scsi_transport_template *aic94xx_transport_template;
static int asd_scan_finished(struct Scsi_Host *, unsigned long);
static void asd_scan_start(struct Scsi_Host *);
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index 3bedf2466bd1..8e53f02cc311 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -2983,7 +2983,6 @@ static struct scsi_host_template acornscsi_template = {
.this_id = 7,
.sg_tablesize = SG_ALL,
.cmd_per_lun = 2,
- .unchecked_isa_dma = 0,
.use_clustering = DISABLE_CLUSTERING,
.proc_name = "acornscsi",
};
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index 49d838e90a24..a3398fe70a9c 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -222,7 +222,6 @@ static struct scsi_host_template cumanascsi_template = {
.this_id = 7,
.sg_tablesize = SG_ALL,
.cmd_per_lun = 2,
- .unchecked_isa_dma = 0,
.use_clustering = DISABLE_CLUSTERING,
.proc_name = "CumanaSCSI-1",
};
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index e351db6c0077..075e2397273c 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -4761,7 +4761,6 @@ static struct scsi_host_template dc395x_driver_template = {
.cmd_per_lun = DC395x_MAX_CMD_PER_LUN,
.eh_abort_handler = dc395x_eh_abort,
.eh_bus_reset_handler = dc395x_eh_bus_reset,
- .unchecked_isa_dma = 0,
.use_clustering = DISABLE_CLUSTERING,
};
diff --git a/drivers/scsi/eata_pio.c b/drivers/scsi/eata_pio.c
index b5a60926e556..952505c006df 100644
--- a/drivers/scsi/eata_pio.c
+++ b/drivers/scsi/eata_pio.c
@@ -815,8 +815,6 @@ static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev
else
hd->primary = 1;
- sh->unchecked_isa_dma = 0; /* We can only do PIO */
-
hd->next = NULL; /* build a linked list of all HBAs */
hd->prev = last_HBA;
if (hd->prev != NULL)
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 0b2080d33575..c6d6e7c6559a 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -85,10 +85,10 @@
/* The meaning of the Scsi_Pointer members in this driver is as follows:
* ptr: Chaining
- * this_residual: gdth_bufflen
- * buffer: gdth_sglist
+ * this_residual: unused
+ * buffer: unused
* dma_handle: unused
- * buffers_residual: gdth_sg_count
+ * buffers_residual: unused
* Status: unused
* Message: unused
* have_data_in: unused
@@ -372,47 +372,6 @@ static const struct file_operations gdth_fops = {
.release = gdth_close,
};
-/*
- * gdth scsi_command access wrappers.
- * below 6 functions are used throughout the driver to access scsi_command's
- * io parameters. The reason we do not use the regular accessors from
- * scsi_cmnd.h is because of gdth_execute(). Since it is unrecommended for
- * llds to directly set scsi_cmnd's IO members. This driver will use SCp
- * members for IO parameters, and will copy scsi_cmnd's members to Scp
- * members in queuecommand. For internal commands through gdth_execute()
- * SCp's members will be set directly.
- */
-static inline unsigned gdth_bufflen(struct scsi_cmnd *cmd)
-{
- return (unsigned)cmd->SCp.this_residual;
-}
-
-static inline void gdth_set_bufflen(struct scsi_cmnd *cmd, unsigned bufflen)
-{
- cmd->SCp.this_residual = bufflen;
-}
-
-static inline unsigned gdth_sg_count(struct scsi_cmnd *cmd)
-{
- return (unsigned)cmd->SCp.buffers_residual;
-}
-
-static inline void gdth_set_sg_count(struct scsi_cmnd *cmd, unsigned sg_count)
-{
- cmd->SCp.buffers_residual = sg_count;
-}
-
-static inline struct scatterlist *gdth_sglist(struct scsi_cmnd *cmd)
-{
- return cmd->SCp.buffer;
-}
-
-static inline void gdth_set_sglist(struct scsi_cmnd *cmd,
- struct scatterlist *sglist)
-{
- cmd->SCp.buffer = sglist;
-}
-
#include "gdth_proc.h"
#include "gdth_proc.c"
@@ -591,125 +550,111 @@ static int __init gdth_search_isa(ulong32 bios_adr)
#endif /* CONFIG_ISA */
#ifdef CONFIG_PCI
-static void gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
- ushort vendor, ushort dev);
+static bool gdth_pci_registered;
-static int __init gdth_search_pci(gdth_pci_str *pcistr)
+static bool gdth_search_vortex(ushort device)
{
- ushort device, cnt;
-
- TRACE(("gdth_search_pci()\n"));
-
- cnt = 0;
- for (device = 0; device <= PCI_DEVICE_ID_VORTEX_GDT6555; ++device)
- gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
- for (device = PCI_DEVICE_ID_VORTEX_GDT6x17RP;
- device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP; ++device)
- gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
- gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
- PCI_DEVICE_ID_VORTEX_GDTNEWRX);
- gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
- PCI_DEVICE_ID_VORTEX_GDTNEWRX2);
- gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
- PCI_DEVICE_ID_INTEL_SRC);
- gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
- PCI_DEVICE_ID_INTEL_SRC_XSCALE);
- return cnt;
+ if (device <= PCI_DEVICE_ID_VORTEX_GDT6555)
+ return true;
+ if (device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP &&
+ device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP)
+ return true;
+ if (device == PCI_DEVICE_ID_VORTEX_GDTNEWRX ||
+ device == PCI_DEVICE_ID_VORTEX_GDTNEWRX2)
+ return true;
+ return false;
}
+static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out);
+static int gdth_pci_init_one(struct pci_dev *pdev,
+ const struct pci_device_id *ent);
+static void gdth_pci_remove_one(struct pci_dev *pdev);
+static void gdth_remove_one(gdth_ha_str *ha);
+
/* Vortex only makes RAID controllers.
* We do not really want to specify all 550 ids here, so wildcard match.
*/
-static struct pci_device_id gdthtable[] __maybe_unused = {
- {PCI_VENDOR_ID_VORTEX,PCI_ANY_ID,PCI_ANY_ID, PCI_ANY_ID},
- {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC,PCI_ANY_ID,PCI_ANY_ID},
- {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC_XSCALE,PCI_ANY_ID,PCI_ANY_ID},
- {0}
+static const struct pci_device_id gdthtable[] = {
+ { PCI_VDEVICE(VORTEX, PCI_ANY_ID) },
+ { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC) },
+ { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC_XSCALE) },
+ { } /* terminate list */
+};
+MODULE_DEVICE_TABLE(pci, gdthtable);
+
+static struct pci_driver gdth_pci_driver = {
+ .name = "gdth",
+ .id_table = gdthtable,
+ .probe = gdth_pci_init_one,
+ .remove = gdth_pci_remove_one,
};
-MODULE_DEVICE_TABLE(pci,gdthtable);
-static void __init gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
- ushort vendor, ushort device)
+static void gdth_pci_remove_one(struct pci_dev *pdev)
{
- ulong base0, base1, base2;
- struct pci_dev *pdev;
+ gdth_ha_str *ha = pci_get_drvdata(pdev);
+
+ pci_set_drvdata(pdev, NULL);
+
+ list_del(&ha->list);
+ gdth_remove_one(ha);
+
+ pci_disable_device(pdev);
+}
+
+static int gdth_pci_init_one(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ ushort vendor = pdev->vendor;
+ ushort device = pdev->device;
+ ulong base0, base1, base2;
+ int rc;
+ gdth_pci_str gdth_pcistr;
+ gdth_ha_str *ha = NULL;
- TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
- *cnt, vendor, device));
+ TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
+ gdth_ctr_count, vendor, device));
- pdev = NULL;
- while ((pdev = pci_get_device(vendor, device, pdev))
- != NULL) {
- if (pci_enable_device(pdev))
- continue;
- if (*cnt >= MAXHA) {
- pci_dev_put(pdev);
- return;
- }
+ memset(&gdth_pcistr, 0, sizeof(gdth_pcistr));
+
+ if (vendor == PCI_VENDOR_ID_VORTEX && !gdth_search_vortex(device))
+ return -ENODEV;
+
+ rc = pci_enable_device(pdev);
+ if (rc)
+ return rc;
+
+ if (gdth_ctr_count >= MAXHA)
+ return -EBUSY;
/* GDT PCI controller found, resources are already in pdev */
- pcistr[*cnt].pdev = pdev;
- pcistr[*cnt].irq = pdev->irq;
+ gdth_pcistr.pdev = pdev;
base0 = pci_resource_flags(pdev, 0);
base1 = pci_resource_flags(pdev, 1);
base2 = pci_resource_flags(pdev, 2);
if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
if (!(base0 & IORESOURCE_MEM))
- continue;
- pcistr[*cnt].dpmem = pci_resource_start(pdev, 0);
+ return -ENODEV;
+ gdth_pcistr.dpmem = pci_resource_start(pdev, 0);
} else { /* GDT6110, GDT6120, .. */
if (!(base0 & IORESOURCE_MEM) ||
!(base2 & IORESOURCE_MEM) ||
!(base1 & IORESOURCE_IO))
- continue;
- pcistr[*cnt].dpmem = pci_resource_start(pdev, 2);
- pcistr[*cnt].io_mm = pci_resource_start(pdev, 0);
- pcistr[*cnt].io = pci_resource_start(pdev, 1);
+ return -ENODEV;
+ gdth_pcistr.dpmem = pci_resource_start(pdev, 2);
+ gdth_pcistr.io = pci_resource_start(pdev, 1);
}
TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
- pcistr[*cnt].pdev->bus->number,
- PCI_SLOT(pcistr[*cnt].pdev->devfn),
- pcistr[*cnt].irq, pcistr[*cnt].dpmem));
- (*cnt)++;
- }
-}
+ gdth_pcistr.pdev->bus->number,
+ PCI_SLOT(gdth_pcistr.pdev->devfn),
+ gdth_pcistr.irq,
+ gdth_pcistr.dpmem));
-static void __init gdth_sort_pci(gdth_pci_str *pcistr, int cnt)
-{
- gdth_pci_str temp;
- int i, changed;
-
- TRACE(("gdth_sort_pci() cnt %d\n",cnt));
- if (cnt == 0)
- return;
+ rc = gdth_pci_probe_one(&gdth_pcistr, &ha);
+ if (rc)
+ return rc;
- do {
- changed = FALSE;
- for (i = 0; i < cnt-1; ++i) {
- if (!reverse_scan) {
- if ((pcistr[i].pdev->bus->number > pcistr[i+1].pdev->bus->number) ||
- (pcistr[i].pdev->bus->number == pcistr[i+1].pdev->bus->number &&
- PCI_SLOT(pcistr[i].pdev->devfn) >
- PCI_SLOT(pcistr[i+1].pdev->devfn))) {
- temp = pcistr[i];
- pcistr[i] = pcistr[i+1];
- pcistr[i+1] = temp;
- changed = TRUE;
- }
- } else {
- if ((pcistr[i].pdev->bus->number < pcistr[i+1].pdev->bus->number) ||
- (pcistr[i].pdev->bus->number == pcistr[i+1].pdev->bus->number &&
- PCI_SLOT(pcistr[i].pdev->devfn) <
- PCI_SLOT(pcistr[i+1].pdev->devfn))) {
- temp = pcistr[i];
- pcistr[i] = pcistr[i+1];
- pcistr[i+1] = temp;
- changed = TRUE;
- }
- }
- }
- } while (changed);
+ return 0;
}
#endif /* CONFIG_PCI */
@@ -909,7 +854,8 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
#endif /* CONFIG_ISA */
#ifdef CONFIG_PCI
-static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
+static int gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
+ gdth_ha_str *ha)
{
register gdt6_dpram_str __iomem *dp6_ptr;
register gdt6c_dpram_str __iomem *dp6c_ptr;
@@ -921,14 +867,14 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
TRACE(("gdth_init_pci()\n"));
- if (pcistr->pdev->vendor == PCI_VENDOR_ID_INTEL)
+ if (pdev->vendor == PCI_VENDOR_ID_INTEL)
ha->oem_id = OEM_ID_INTEL;
else
ha->oem_id = OEM_ID_ICP;
- ha->brd_phys = (pcistr->pdev->bus->number << 8) | (pcistr->pdev->devfn & 0xf8);
- ha->stype = (ulong32)pcistr->pdev->device;
- ha->irq = pcistr->irq;
- ha->pdev = pcistr->pdev;
+ ha->brd_phys = (pdev->bus->number << 8) | (pdev->devfn & 0xf8);
+ ha->stype = (ulong32)pdev->device;
+ ha->irq = pdev->irq;
+ ha->pdev = pdev;
if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
@@ -956,8 +902,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
continue;
}
iounmap(ha->brd);
- pci_write_config_dword(pcistr->pdev,
- PCI_BASE_ADDRESS_0, i);
+ pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i);
ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
if (ha->brd == NULL) {
printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
@@ -1066,8 +1011,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
continue;
}
iounmap(ha->brd);
- pci_write_config_dword(pcistr->pdev,
- PCI_BASE_ADDRESS_2, i);
+ pci_write_config_dword(pdev, PCI_BASE_ADDRESS_2, i);
ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
if (ha->brd == NULL) {
printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
@@ -1159,16 +1103,16 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
}
/* manipulate config. space to enable DPMEM, start RP controller */
- pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
+ pci_read_config_word(pdev, PCI_COMMAND, &command);
command |= 6;
- pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
- if (pci_resource_start(pcistr->pdev, 8) == 1UL)
- pci_resource_start(pcistr->pdev, 8) = 0UL;
+ pci_write_config_word(pdev, PCI_COMMAND, command);
+ if (pci_resource_start(pdev, 8) == 1UL)
+ pci_resource_start(pdev, 8) = 0UL;
i = 0xFEFF0001UL;
- pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
+ pci_write_config_dword(pdev, PCI_ROM_ADDRESS, i);
gdth_delay(1);
- pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
- pci_resource_start(pcistr->pdev, 8));
+ pci_write_config_dword(pdev, PCI_ROM_ADDRESS,
+ pci_resource_start(pdev, 8));
dp6m_ptr = ha->brd;
@@ -1195,8 +1139,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
continue;
}
iounmap(ha->brd);
- pci_write_config_dword(pcistr->pdev,
- PCI_BASE_ADDRESS_0, i);
+ pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i);
ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
if (ha->brd == NULL) {
printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
@@ -2353,12 +2296,12 @@ static void gdth_next(gdth_ha_str *ha)
static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
char *buffer, ushort count)
{
- ushort cpcount,i, max_sg = gdth_sg_count(scp);
+ ushort cpcount,i, max_sg = scsi_sg_count(scp);
ushort cpsum,cpnow;
struct scatterlist *sl;
char *address;
- cpcount = min_t(ushort, count, gdth_bufflen(scp));
+ cpcount = min_t(ushort, count, scsi_bufflen(scp));
if (cpcount) {
cpsum=0;
@@ -2366,7 +2309,7 @@ static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
unsigned long flags;
cpnow = (ushort)sl->length;
TRACE(("copy_internal() now %d sum %d count %d %d\n",
- cpnow, cpsum, cpcount, gdth_bufflen(scp)));
+ cpnow, cpsum, cpcount, scsi_bufflen(scp)));
if (cpsum+cpnow > cpcount)
cpnow = cpcount - cpsum;
cpsum += cpnow;
@@ -2589,10 +2532,10 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
cmdp->u.cache.BlockCnt = blockcnt;
}
- if (gdth_bufflen(scp)) {
+ if (scsi_bufflen(scp)) {
cmndinfo->dma_dir = (read_write == 1 ?
PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
- sgcnt = pci_map_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
+ sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
cmndinfo->dma_dir);
if (mode64) {
struct scatterlist *sl;
@@ -2739,7 +2682,7 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
cmdp->u.raw64.lun = l;
cmdp->u.raw64.bus = b;
cmdp->u.raw64.priority = 0;
- cmdp->u.raw64.sdlen = gdth_bufflen(scp);
+ cmdp->u.raw64.sdlen = scsi_bufflen(scp);
cmdp->u.raw64.sense_len = 16;
cmdp->u.raw64.sense_data = sense_paddr;
cmdp->u.raw64.direction =
@@ -2756,7 +2699,7 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
cmdp->u.raw.bus = b;
cmdp->u.raw.priority = 0;
cmdp->u.raw.link_p = 0;
- cmdp->u.raw.sdlen = gdth_bufflen(scp);
+ cmdp->u.raw.sdlen = scsi_bufflen(scp);
cmdp->u.raw.sense_len = 16;
cmdp->u.raw.sense_data = sense_paddr;
cmdp->u.raw.direction =
@@ -2765,9 +2708,9 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
cmdp->u.raw.sg_ranz = 0;
}
- if (gdth_bufflen(scp)) {
+ if (scsi_bufflen(scp)) {
cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL;
- sgcnt = pci_map_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
+ sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
cmndinfo->dma_dir);
if (mode64) {
struct scatterlist *sl;
@@ -3388,8 +3331,8 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
/* retry */
return 2;
}
- if (gdth_bufflen(scp))
- pci_unmap_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
+ if (scsi_bufflen(scp))
+ pci_unmap_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
cmndinfo->dma_dir);
if (cmndinfo->sense_paddr)
@@ -4031,10 +3974,6 @@ static int gdth_queuecommand(struct scsi_cmnd *scp,
gdth_update_timeout(scp, scp->timeout_per_command * 6);
cmndinfo->priority = DEFAULT_PRI;
- gdth_set_bufflen(scp, scsi_bufflen(scp));
- gdth_set_sg_count(scp, scsi_sg_count(scp));
- gdth_set_sglist(scp, scsi_sglist(scp));
-
return __gdth_queuecommand(ha, scp, cmndinfo);
}
@@ -4955,12 +4894,16 @@ static int __init gdth_eisa_probe_one(ushort eisa_slot)
#endif /* CONFIG_EISA */
#ifdef CONFIG_PCI
-static int __init gdth_pci_probe_one(gdth_pci_str *pcistr, int ctr)
+static int gdth_pci_probe_one(gdth_pci_str *pcistr,
+ gdth_ha_str **ha_out)
{
struct Scsi_Host *shp;
gdth_ha_str *ha;
dma_addr_t scratch_dma_handle = 0;
int error, i;
+ struct pci_dev *pdev = pcistr->pdev;
+
+ *ha_out = NULL;
shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str));
if (!shp)
@@ -4968,13 +4911,13 @@ static int __init gdth_pci_probe_one(gdth_pci_str *pcistr, int ctr)
ha = shost_priv(shp);
error = -ENODEV;
- if (!gdth_init_pci(&pcistr[ctr],ha))
+ if (!gdth_init_pci(pdev, pcistr, ha))
goto out_host_put;
/* controller found and initialized */
printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
- pcistr[ctr].pdev->bus->number,
- PCI_SLOT(pcistr[ctr].pdev->devfn),
+ pdev->bus->number,
+ PCI_SLOT(pdev->devfn),
ha->irq);
error = request_irq(ha->irq, gdth_interrupt,
@@ -5019,7 +4962,7 @@ static int __init gdth_pci_probe_one(gdth_pci_str *pcistr, int ctr)
ha->scratch_busy = FALSE;
ha->req_first = NULL;
- ha->tid_cnt = pcistr[ctr].pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
+ ha->tid_cnt = pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
if (max_ids > 0 && max_ids < ha->tid_cnt)
ha->tid_cnt = max_ids;
for (i = 0; i < GDTH_MAXCMDS; ++i)
@@ -5039,16 +4982,16 @@ static int __init gdth_pci_probe_one(gdth_pci_str *pcistr, int ctr)
/* 64-bit DMA only supported from FW >= x.43 */
if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) ||
!ha->dma64_support) {
- if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
+ if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
printk(KERN_WARNING "GDT-PCI %d: "
"Unable to set 32-bit DMA\n", ha->hanum);
goto out_free_coal_stat;
}
} else {
shp->max_cmd_len = 16;
- if (!pci_set_dma_mask(pcistr[ctr].pdev, DMA_64BIT_MASK)) {
+ if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
printk("GDT-PCI %d: 64-bit DMA enabled\n", ha->hanum);
- } else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
+ } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
printk(KERN_WARNING "GDT-PCI %d: "
"Unable to set 64/32-bit DMA\n", ha->hanum);
goto out_free_coal_stat;
@@ -5062,13 +5005,17 @@ static int __init gdth_pci_probe_one(gdth_pci_str *pcistr, int ctr)
spin_lock_init(&ha->smp_lock);
gdth_enable_int(ha);
- error = scsi_add_host(shp, &pcistr[ctr].pdev->dev);
+ error = scsi_add_host(shp, &pdev->dev);
if (error)
goto out_free_coal_stat;
list_add_tail(&ha->list, &gdth_instances);
+ pci_set_drvdata(ha->pdev, ha);
+
scsi_scan_host(shp);
+ *ha_out = ha;
+
return 0;
out_free_coal_stat:
@@ -5185,16 +5132,8 @@ static int __init gdth_init(void)
#ifdef CONFIG_PCI
/* scanning for PCI controllers */
- {
- gdth_pci_str pcistr[MAXHA];
- int cnt,ctr;
-
- cnt = gdth_search_pci(pcistr);
- printk("GDT-HA: Found %d PCI Storage RAID Controllers\n", cnt);
- gdth_sort_pci(pcistr,cnt);
- for (ctr = 0; ctr < cnt; ++ctr)
- gdth_pci_probe_one(pcistr, ctr);
- }
+ if (pci_register_driver(&gdth_pci_driver) == 0)
+ gdth_pci_registered = true;
#endif /* CONFIG_PCI */
TRACE2(("gdth_detect() %d controller detected\n", gdth_ctr_count));
@@ -5227,6 +5166,11 @@ static void __exit gdth_exit(void)
del_timer_sync(&gdth_timer);
#endif
+#ifdef CONFIG_PCI
+ if (gdth_pci_registered)
+ pci_unregister_driver(&gdth_pci_driver);
+#endif
+
list_for_each_entry(ha, &gdth_instances, list)
gdth_remove_one(ha);
}
diff --git a/drivers/scsi/gdth.h b/drivers/scsi/gdth.h
index 26e4e92515e0..ca92476727cf 100644
--- a/drivers/scsi/gdth.h
+++ b/drivers/scsi/gdth.h
@@ -839,8 +839,6 @@ typedef struct {
struct pci_dev *pdev;
ulong dpmem; /* DPRAM address */
ulong io; /* IO address */
- ulong io_mm; /* IO address mem. mapped */
- unchar irq; /* IRQ */
} gdth_pci_str;
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index 9617f424ab31..58adfc408793 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -905,7 +905,6 @@ static struct scsi_host_template driver_template = {
.eh_device_reset_handler = hptiop_reset,
.eh_bus_reset_handler = hptiop_reset,
.info = hptiop_info,
- .unchecked_isa_dma = 0,
.emulated = 0,
.use_clustering = ENABLE_CLUSTERING,
.proc_name = driver_name,
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index 7ed568f180ae..cc4f44fcabb6 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -3502,27 +3502,11 @@ ips_send_wait(ips_ha_t * ha, ips_scb_t * scb, int timeout, int intr)
static void
ips_scmd_buf_write(struct scsi_cmnd *scmd, void *data, unsigned int count)
{
- int i;
- unsigned int min_cnt, xfer_cnt;
- char *cdata = (char *) data;
- unsigned char *buffer;
- unsigned long flags;
- struct scatterlist *sg = scsi_sglist(scmd);
-
- for (i = 0, xfer_cnt = 0;
- (i < scsi_sg_count(scmd)) && (xfer_cnt < count); i++) {
- min_cnt = min(count - xfer_cnt, sg[i].length);
-
- /* kmap_atomic() ensures addressability of the data buffer.*/
- /* local_irq_save() protects the KM_IRQ0 address slot. */
- local_irq_save(flags);
- buffer = kmap_atomic(sg_page(&sg[i]), KM_IRQ0) + sg[i].offset;
- memcpy(buffer, &cdata[xfer_cnt], min_cnt);
- kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
- local_irq_restore(flags);
+ unsigned long flags;
- xfer_cnt += min_cnt;
- }
+ local_irq_save(flags);
+ scsi_sg_copy_from_buffer(scmd, data, count);
+ local_irq_restore(flags);
}
/****************************************************************************/
@@ -3535,27 +3519,11 @@ ips_scmd_buf_write(struct scsi_cmnd *scmd, void *data, unsigned int count)
static void
ips_scmd_buf_read(struct scsi_cmnd *scmd, void *data, unsigned int count)
{
- int i;
- unsigned int min_cnt, xfer_cnt;
- char *cdata = (char *) data;
- unsigned char *buffer;
- unsigned long flags;
- struct scatterlist *sg = scsi_sglist(scmd);
-
- for (i = 0, xfer_cnt = 0;
- (i < scsi_sg_count(scmd)) && (xfer_cnt < count); i++) {
- min_cnt = min(count - xfer_cnt, sg[i].length);
-
- /* kmap_atomic() ensures addressability of the data buffer.*/
- /* local_irq_save() protects the KM_IRQ0 address slot. */
- local_irq_save(flags);
- buffer = kmap_atomic(sg_page(&sg[i]), KM_IRQ0) + sg[i].offset;
- memcpy(&cdata[xfer_cnt], buffer, min_cnt);
- kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
- local_irq_restore(flags);
+ unsigned long flags;
- xfer_cnt += min_cnt;
- }
+ local_irq_save(flags);
+ scsi_sg_copy_to_buffer(scmd, data, count);
+ local_irq_restore(flags);
}
/****************************************************************************/
@@ -6842,7 +6810,6 @@ ips_register_scsi(int index)
sh->sg_tablesize = sh->hostt->sg_tablesize;
sh->can_queue = sh->hostt->can_queue;
sh->cmd_per_lun = sh->hostt->cmd_per_lun;
- sh->unchecked_isa_dma = sh->hostt->unchecked_isa_dma;
sh->use_clustering = sh->hostt->use_clustering;
sh->max_sectors = 128;
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 1f8241563c6c..601ec5b6a7f6 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -24,6 +24,8 @@
*/
#include <linux/kthread.h>
+#include <linux/firmware.h>
+#include <linux/ctype.h>
#include "sas_internal.h"
@@ -1064,6 +1066,45 @@ void sas_target_destroy(struct scsi_target *starget)
return;
}
+static void sas_parse_addr(u8 *sas_addr, const char *p)
+{
+ int i;
+ for (i = 0; i < SAS_ADDR_SIZE; i++) {
+ u8 h, l;
+ if (!*p)
+ break;
+ h = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10;
+ p++;
+ l = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10;
+ p++;
+ sas_addr[i] = (h<<4) | l;
+ }
+}
+
+#define SAS_STRING_ADDR_SIZE 16
+
+int sas_request_addr(struct Scsi_Host *shost, u8 *addr)
+{
+ int res;
+ const struct firmware *fw;
+
+ res = request_firmware(&fw, "sas_addr", &shost->shost_gendev);
+ if (res)
+ return res;
+
+ if (fw->size < SAS_STRING_ADDR_SIZE) {
+ res = -ENODEV;
+ goto out;
+ }
+
+ sas_parse_addr(addr, fw->data);
+
+out:
+ release_firmware(fw);
+ return res;
+}
+EXPORT_SYMBOL_GPL(sas_request_addr);
+
EXPORT_SYMBOL_GPL(sas_queuecommand);
EXPORT_SYMBOL_GPL(sas_target_alloc);
EXPORT_SYMBOL_GPL(sas_slave_configure);
diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c
index 3b09ab21d701..0248919bc2df 100644
--- a/drivers/scsi/mac_scsi.c
+++ b/drivers/scsi/mac_scsi.c
@@ -592,7 +592,6 @@ static struct scsi_host_template driver_template = {
.this_id = 7,
.sg_tablesize = SG_ALL,
.cmd_per_lun = CMD_PER_LUN,
- .unchecked_isa_dma = 0,
.use_clustering = DISABLE_CLUSTERING
};
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index fad6cb5cba28..d1e7845e11c7 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -90,78 +90,6 @@ static int ps3rom_slave_configure(struct scsi_device *scsi_dev)
return 0;
}
-/*
- * copy data from device into scatter/gather buffer
- */
-static int fill_from_dev_buffer(struct scsi_cmnd *cmd, const void *buf)
-{
- int k, req_len, act_len, len, active;
- void *kaddr;
- struct scatterlist *sgpnt;
- unsigned int buflen;
-
- buflen = scsi_bufflen(cmd);
- if (!buflen)
- return 0;
-
- if (!scsi_sglist(cmd))
- return -1;
-
- active = 1;
- req_len = act_len = 0;
- scsi_for_each_sg(cmd, sgpnt, scsi_sg_count(cmd), k) {
- if (active) {
- kaddr = kmap_atomic(sg_page(sgpnt), KM_IRQ0);
- len = sgpnt->length;
- if ((req_len + len) > buflen) {
- active = 0;
- len = buflen - req_len;
- }
- memcpy(kaddr + sgpnt->offset, buf + req_len, len);
- flush_kernel_dcache_page(sg_page(sgpnt));
- kunmap_atomic(kaddr, KM_IRQ0);
- act_len += len;
- }
- req_len += sgpnt->length;
- }
- scsi_set_resid(cmd, buflen - act_len);
- return 0;
-}
-
-/*
- * copy data from scatter/gather into device's buffer
- */
-static int fetch_to_dev_buffer(struct scsi_cmnd *cmd, void *buf)
-{
- int k, req_len, len, fin;
- void *kaddr;
- struct scatterlist *sgpnt;
- unsigned int buflen;
-
- buflen = scsi_bufflen(cmd);
- if (!buflen)
- return 0;
-
- if (!scsi_sglist(cmd))
- return -1;
-
- req_len = fin = 0;
- scsi_for_each_sg(cmd, sgpnt, scsi_sg_count(cmd), k) {
- kaddr = kmap_atomic(sg_page(sgpnt), KM_IRQ0);
- len = sgpnt->length;
- if ((req_len + len) > buflen) {
- len = buflen - req_len;
- fin = 1;
- }
- memcpy(buf + req_len, kaddr + sgpnt->offset, len);
- kunmap_atomic(kaddr, KM_IRQ0);
- if (fin)
- return req_len + len;
- req_len += sgpnt->length;
- }
- return req_len;
-}
-
static int ps3rom_atapi_request(struct ps3_storage_device *dev,
struct scsi_cmnd *cmd)
{
@@ -195,9 +123,7 @@ static int ps3rom_atapi_request(struct ps3_storage_device *dev,
else
atapi_cmnd.proto = PIO_DATA_OUT_PROTO;
atapi_cmnd.in_out = DIR_WRITE;
- res = fetch_to_dev_buffer(cmd, dev->bounce_buf);
- if (res < 0)
- return DID_ERROR << 16;
+ scsi_sg_copy_to_buffer(cmd, dev->bounce_buf, dev->bounce_size);
break;
default:
@@ -269,9 +195,7 @@ static int ps3rom_write_request(struct ps3_storage_device *dev,
dev_dbg(&dev->sbd.core, "%s:%u: write %u sectors starting at %u\n",
__func__, __LINE__, sectors, start_sector);
- res = fetch_to_dev_buffer(cmd, dev->bounce_buf);
- if (res < 0)
- return DID_ERROR << 16;
+ scsi_sg_copy_to_buffer(cmd, dev->bounce_buf, dev->bounce_size);
res = lv1_storage_write(dev->sbd.dev_id,
dev->regions[dev->region_idx].id, start_sector,
@@ -381,11 +305,13 @@ static irqreturn_t ps3rom_interrupt(int irq, void *data)
if (!status) {
/* OK, completed */
if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
- res = fill_from_dev_buffer(cmd, dev->bounce_buf);
- if (res) {
- cmd->result = DID_ERROR << 16;
- goto done;
- }
+ int len;
+
+ len = scsi_sg_copy_from_buffer(cmd,
+ dev->bounce_buf,
+ dev->bounce_size);
+
+ scsi_set_resid(cmd, scsi_bufflen(cmd) - len);
}
cmd->result = DID_OK << 16;
goto done;
@@ -427,7 +353,7 @@ static struct scsi_host_template ps3rom_host_template = {
.cmd_per_lun = 1,
.emulated = 1, /* only sg driver uses this */
.max_sectors = PS3ROM_MAX_SECTORS,
- .use_clustering = DISABLE_CLUSTERING,
+ .use_clustering = ENABLE_CLUSTERING,
.module = THIS_MODULE,
};
diff --git a/drivers/scsi/qla4xxx/ql4_fw.h b/drivers/scsi/qla4xxx/ql4_fw.h
index fe415ec85655..ed8ee66a7da5 100644
--- a/drivers/scsi/qla4xxx/ql4_fw.h
+++ b/drivers/scsi/qla4xxx/ql4_fw.h
@@ -216,6 +216,7 @@ union external_hw_config_reg {
#define MBOX_CMD_ABOUT_FW 0x0009
#define MBOX_CMD_PING 0x000B
#define MBOX_CMD_LUN_RESET 0x0016
+#define MBOX_CMD_TARGET_WARM_RESET 0x0017
#define MBOX_CMD_GET_MANAGEMENT_DATA 0x001E
#define MBOX_CMD_GET_FW_STATUS 0x001F
#define MBOX_CMD_SET_ISNS_SERVICE 0x0021
diff --git a/drivers/scsi/qla4xxx/ql4_glbl.h b/drivers/scsi/qla4xxx/ql4_glbl.h
index a3608e028bf6..b403a17106c5 100644
--- a/drivers/scsi/qla4xxx/ql4_glbl.h
+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
@@ -27,6 +27,8 @@ int qla4xxx_relogin_device(struct scsi_qla_host * ha,
struct ddb_entry * ddb_entry);
int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
int lun);
+int qla4xxx_reset_target(struct scsi_qla_host * ha,
+ struct ddb_entry * ddb_entry);
int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
uint32_t offset, uint32_t len);
int qla4xxx_get_firmware_status(struct scsi_qla_host * ha);
diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c b/drivers/scsi/qla4xxx/ql4_mbx.c
index 35cd73c72a68..c577d79bd7e8 100644
--- a/drivers/scsi/qla4xxx/ql4_mbx.c
+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
@@ -713,6 +713,45 @@ int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
return status;
}
+/**
+ * qla4xxx_reset_target - issues target Reset
+ * @ha: Pointer to host adapter structure.
+ * @db_entry: Pointer to device database entry
+ * @un_entry: Pointer to lun entry structure
+ *
+ * This routine performs a TARGET RESET on the specified target.
+ * The caller must ensure that the ddb_entry pointers
+ * are valid before calling this routine.
+ **/
+int qla4xxx_reset_target(struct scsi_qla_host *ha,
+ struct ddb_entry *ddb_entry)
+{
+ uint32_t mbox_cmd[MBOX_REG_COUNT];
+ uint32_t mbox_sts[MBOX_REG_COUNT];
+ int status = QLA_SUCCESS;
+
+ DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
+ ddb_entry->os_target_id));
+
+ /*
+ * Send target reset command to ISP, so that the ISP will return all
+ * outstanding requests with RESET status
+ */
+ memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+ memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+ mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
+ mbox_cmd[1] = ddb_entry->fw_ddb_index;
+ mbox_cmd[5] = 0x01; /* Immediate Command Enable */
+
+ qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
+ &mbox_sts[0]);
+ if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
+ mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
+ status = QLA_ERROR;
+
+ return status;
+}
int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
uint32_t offset, uint32_t len)
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 8b92f348f02c..31e605caf0f1 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -71,6 +71,7 @@ static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
void (*done) (struct scsi_cmnd *));
static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
+static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
static int qla4xxx_slave_alloc(struct scsi_device *device);
static int qla4xxx_slave_configure(struct scsi_device *device);
@@ -84,6 +85,7 @@ static struct scsi_host_template qla4xxx_driver_template = {
.queuecommand = qla4xxx_queuecommand,
.eh_device_reset_handler = qla4xxx_eh_device_reset,
+ .eh_target_reset_handler = qla4xxx_eh_target_reset,
.eh_host_reset_handler = qla4xxx_eh_host_reset,
.slave_configure = qla4xxx_slave_configure,
@@ -1482,7 +1484,7 @@ static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
}
/**
- * qla4xxx_eh_wait_for_active_target_commands - wait for active cmds to finish.
+ * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
* @ha: pointer to to HBA
* @t: target id
* @l: lun id
@@ -1490,20 +1492,22 @@ static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
* This function waits for all outstanding commands to a lun to complete. It
* returns 0 if all pending commands are returned and 1 otherwise.
**/
-static int qla4xxx_eh_wait_for_active_target_commands(struct scsi_qla_host *ha,
- int t, int l)
+static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
+ struct scsi_target *stgt,
+ struct scsi_device *sdev)
{
int cnt;
int status = 0;
struct scsi_cmnd *cmd;
/*
- * Waiting for all commands for the designated target in the active
- * array
+ * Waiting for all commands for the designated target or dev
+ * in the active array
*/
for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
cmd = scsi_host_find_tag(ha->host, cnt);
- if (cmd && cmd->device->id == t && cmd->device->lun == l) {
+ if (cmd && stgt == scsi_target(cmd->device) &&
+ (!sdev || sdev == cmd->device)) {
if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
status++;
break;
@@ -1551,19 +1555,12 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
/* Send marker. */
ha->marker_needed = 1;
- /*
- * If we are coming down the EH path, wait for all commands to complete
- * for the device.
- */
- if (cmd->device->host->shost_state == SHOST_RECOVERY) {
- if (qla4xxx_eh_wait_for_active_target_commands(ha,
- cmd->device->id,
- cmd->device->lun)){
- dev_info(&ha->pdev->dev,
- "DEVICE RESET FAILED - waiting for "
- "commands.\n");
- goto eh_dev_reset_done;
- }
+ if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
+ cmd->device)) {
+ dev_info(&ha->pdev->dev,
+ "DEVICE RESET FAILED - waiting for "
+ "commands.\n");
+ goto eh_dev_reset_done;
}
dev_info(&ha->pdev->dev,
@@ -1579,6 +1576,53 @@ eh_dev_reset_done:
}
/**
+ * qla4xxx_eh_target_reset - callback for target reset.
+ * @cmd: Pointer to Linux's SCSI command structure
+ *
+ * This routine is called by the Linux OS to reset the target.
+ **/
+static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
+{
+ struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
+ struct ddb_entry *ddb_entry = cmd->device->hostdata;
+ int stat;
+
+ if (!ddb_entry)
+ return FAILED;
+
+ starget_printk(KERN_INFO, scsi_target(cmd->device),
+ "WARM TARGET RESET ISSUED.\n");
+
+ DEBUG2(printk(KERN_INFO
+ "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
+ "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
+ ha->host_no, cmd, jiffies, cmd->timeout_per_command / HZ,
+ ha->dpc_flags, cmd->result, cmd->allowed));
+
+ stat = qla4xxx_reset_target(ha, ddb_entry);
+ if (stat != QLA_SUCCESS) {
+ starget_printk(KERN_INFO, scsi_target(cmd->device),
+ "WARM TARGET RESET FAILED.\n");
+ return FAILED;
+ }
+
+ /* Send marker. */
+ ha->marker_needed = 1;
+
+ if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
+ NULL)) {
+ starget_printk(KERN_INFO, scsi_target(cmd->device),
+ "WARM TARGET DEVICE RESET FAILED - "
+ "waiting for commands.\n");
+ return FAILED;
+ }
+
+ starget_printk(KERN_INFO, scsi_target(cmd->device),
+ "WARM TARGET RESET SUCCEEDED.\n");
+ return SUCCESS;
+}
+
+/**
* qla4xxx_eh_host_reset - kernel callback
* @cmd: Pointer to Linux's SCSI command structure
*
diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c
index 52ca4d507c3c..913a931176ef 100644
--- a/drivers/scsi/raid_class.c
+++ b/drivers/scsi/raid_class.c
@@ -290,7 +290,7 @@ raid_class_release(struct raid_template *r)
{
struct raid_internal *i = to_raid_internal(r);
- attribute_container_unregister(&i->r.raid_attrs.ac);
+ BUG_ON(attribute_container_unregister(&i->r.raid_attrs.ac));
kfree(i);
}
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index e5c6f6af8765..f6980bd9d8f9 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -166,6 +166,51 @@ static struct scsi_host_cmd_pool scsi_cmd_dma_pool = {
static DEFINE_MUTEX(host_cmd_pool_mutex);
/**
+ * scsi_pool_alloc_command - internal function to get a fully allocated command
+ * @pool: slab pool to allocate the command from
+ * @gfp_mask: mask for the allocation
+ *
+ * Returns a fully allocated command (with the allied sense buffer) or
+ * NULL on failure
+ */
+static struct scsi_cmnd *
+scsi_pool_alloc_command(struct scsi_host_cmd_pool *pool, gfp_t gfp_mask)
+{
+ struct scsi_cmnd *cmd;
+
+ cmd = kmem_cache_alloc(pool->cmd_slab, gfp_mask | pool->gfp_mask);
+ if (!cmd)
+ return NULL;
+
+ memset(cmd, 0, sizeof(*cmd));
+
+ cmd->sense_buffer = kmem_cache_alloc(pool->sense_slab,
+ gfp_mask | pool->gfp_mask);
+ if (!cmd->sense_buffer) {
+ kmem_cache_free(pool->cmd_slab, cmd);
+ return NULL;
+ }
+
+ return cmd;
+}
+
+/**
+ * scsi_pool_free_command - internal function to release a command
+ * @pool: slab pool to allocate the command from
+ * @cmd: command to release
+ *
+ * the command must previously have been allocated by
+ * scsi_pool_alloc_command.
+ */
+static void
+scsi_pool_free_command(struct scsi_host_cmd_pool *pool,
+ struct scsi_cmnd *cmd)
+{
+ kmem_cache_free(pool->sense_slab, cmd->sense_buffer);
+ kmem_cache_free(pool->cmd_slab, cmd);
+}
+
+/**
* __scsi_get_command - Allocate a struct scsi_cmnd
* @shost: host to transmit command
* @gfp_mask: allocation mask
@@ -178,8 +223,7 @@ struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask)
struct scsi_cmnd *cmd;
unsigned char *buf;
- cmd = kmem_cache_alloc(shost->cmd_pool->cmd_slab,
- gfp_mask | shost->cmd_pool->gfp_mask);
+ cmd = scsi_pool_alloc_command(shost->cmd_pool, gfp_mask);
if (unlikely(!cmd)) {
unsigned long flags;
@@ -197,16 +241,6 @@ struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask)
memset(cmd, 0, sizeof(*cmd));
cmd->sense_buffer = buf;
}
- } else {
- buf = kmem_cache_alloc(shost->cmd_pool->sense_slab,
- gfp_mask | shost->cmd_pool->gfp_mask);
- if (likely(buf)) {
- memset(cmd, 0, sizeof(*cmd));
- cmd->sense_buffer = buf;
- } else {
- kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
- cmd = NULL;
- }
}
return cmd;
@@ -266,11 +300,8 @@ void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd,
}
spin_unlock_irqrestore(&shost->free_list_lock, flags);
- if (likely(cmd != NULL)) {
- kmem_cache_free(shost->cmd_pool->sense_slab,
- cmd->sense_buffer);
- kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
- }
+ if (likely(cmd != NULL))
+ scsi_pool_free_command(shost->cmd_pool, cmd);
put_device(dev);
}
@@ -299,30 +330,16 @@ void scsi_put_command(struct scsi_cmnd *cmd)
}
EXPORT_SYMBOL(scsi_put_command);
-/**
- * scsi_setup_command_freelist - Setup the command freelist for a scsi host.
- * @shost: host to allocate the freelist for.
- *
- * Description: The command freelist protects against system-wide out of memory
- * deadlock by preallocating one SCSI command structure for each host, so the
- * system can always write to a swap file on a device associated with that host.
- *
- * Returns: Nothing.
- */
-int scsi_setup_command_freelist(struct Scsi_Host *shost)
+static struct scsi_host_cmd_pool *scsi_get_host_cmd_pool(gfp_t gfp_mask)
{
- struct scsi_host_cmd_pool *pool;
- struct scsi_cmnd *cmd;
-
- spin_lock_init(&shost->free_list_lock);
- INIT_LIST_HEAD(&shost->free_list);
-
+ struct scsi_host_cmd_pool *retval = NULL, *pool;
/*
* Select a command slab for this host and create it if not
* yet existent.
*/
mutex_lock(&host_cmd_pool_mutex);
- pool = (shost->unchecked_isa_dma ? &scsi_cmd_dma_pool : &scsi_cmd_pool);
+ pool = (gfp_mask & __GFP_DMA) ? &scsi_cmd_dma_pool :
+ &scsi_cmd_pool;
if (!pool->users) {
pool->cmd_slab = kmem_cache_create(pool->cmd_name,
sizeof(struct scsi_cmnd), 0,
@@ -340,37 +357,122 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost)
}
pool->users++;
- shost->cmd_pool = pool;
+ retval = pool;
+ fail:
mutex_unlock(&host_cmd_pool_mutex);
+ return retval;
+}
+
+static void scsi_put_host_cmd_pool(gfp_t gfp_mask)
+{
+ struct scsi_host_cmd_pool *pool;
+ mutex_lock(&host_cmd_pool_mutex);
+ pool = (gfp_mask & __GFP_DMA) ? &scsi_cmd_dma_pool :
+ &scsi_cmd_pool;
/*
- * Get one backup command for this host.
+ * This may happen if a driver has a mismatched get and put
+ * of the command pool; the driver should be implicated in
+ * the stack trace
*/
- cmd = kmem_cache_alloc(shost->cmd_pool->cmd_slab,
- GFP_KERNEL | shost->cmd_pool->gfp_mask);
- if (!cmd)
- goto fail2;
-
- cmd->sense_buffer = kmem_cache_alloc(shost->cmd_pool->sense_slab,
- GFP_KERNEL |
- shost->cmd_pool->gfp_mask);
- if (!cmd->sense_buffer)
- goto fail2;
-
- list_add(&cmd->list, &shost->free_list);
- return 0;
+ BUG_ON(pool->users == 0);
- fail2:
- if (cmd)
- kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
- mutex_lock(&host_cmd_pool_mutex);
if (!--pool->users) {
kmem_cache_destroy(pool->cmd_slab);
kmem_cache_destroy(pool->sense_slab);
}
- fail:
mutex_unlock(&host_cmd_pool_mutex);
- return -ENOMEM;
+}
+
+/**
+ * scsi_allocate_command - get a fully allocated SCSI command
+ * @gfp_mask: allocation mask
+ *
+ * This function is for use outside of the normal host based pools.
+ * It allocates the relevant command and takes an additional reference
+ * on the pool it used. This function *must* be paired with
+ * scsi_free_command which also has the identical mask, otherwise the
+ * free pool counts will eventually go wrong and you'll trigger a bug.
+ *
+ * This function should *only* be used by drivers that need a static
+ * command allocation at start of day for internal functions.
+ */
+struct scsi_cmnd *scsi_allocate_command(gfp_t gfp_mask)
+{
+ struct scsi_host_cmd_pool *pool = scsi_get_host_cmd_pool(gfp_mask);
+
+ if (!pool)
+ return NULL;
+
+ return scsi_pool_alloc_command(pool, gfp_mask);
+}
+EXPORT_SYMBOL(scsi_allocate_command);
+
+/**
+ * scsi_free_command - free a command allocated by scsi_allocate_command
+ * @gfp_mask: mask used in the original allocation
+ * @cmd: command to free
+ *
+ * Note: using the original allocation mask is vital because that's
+ * what determines which command pool we use to free the command. Any
+ * mismatch will cause the system to BUG eventually.
+ */
+void scsi_free_command(gfp_t gfp_mask, struct scsi_cmnd *cmd)
+{
+ struct scsi_host_cmd_pool *pool = scsi_get_host_cmd_pool(gfp_mask);
+
+ /*
+ * this could trigger if the mask to scsi_allocate_command
+ * doesn't match this mask. Otherwise we're guaranteed that this
+ * succeeds because scsi_allocate_command must have taken a reference
+ * on the pool
+ */
+ BUG_ON(!pool);
+
+ scsi_pool_free_command(pool, cmd);
+ /*
+ * scsi_put_host_cmd_pool is called twice; once to release the
+ * reference we took above, and once to release the reference
+ * originally taken by scsi_allocate_command
+ */
+ scsi_put_host_cmd_pool(gfp_mask);
+ scsi_put_host_cmd_pool(gfp_mask);
+}
+EXPORT_SYMBOL(scsi_free_command);
+
+/**
+ * scsi_setup_command_freelist - Setup the command freelist for a scsi host.
+ * @shost: host to allocate the freelist for.
+ *
+ * Description: The command freelist protects against system-wide out of memory
+ * deadlock by preallocating one SCSI command structure for each host, so the
+ * system can always write to a swap file on a device associated with that host.
+ *
+ * Returns: Nothing.
+ */
+int scsi_setup_command_freelist(struct Scsi_Host *shost)
+{
+ struct scsi_cmnd *cmd;
+ const gfp_t gfp_mask = shost->unchecked_isa_dma ? GFP_DMA : GFP_KERNEL;
+
+ spin_lock_init(&shost->free_list_lock);
+ INIT_LIST_HEAD(&shost->free_list);
+
+ shost->cmd_pool = scsi_get_host_cmd_pool(gfp_mask);
+
+ if (!shost->cmd_pool)
+ return -ENOMEM;
+
+ /*
+ * Get one backup command for this host.
+ */
+ cmd = scsi_pool_alloc_command(shost->cmd_pool, gfp_mask);
+ if (!cmd) {
+ scsi_put_host_cmd_pool(gfp_mask);
+ return -ENOMEM;
+ }
+ list_add(&cmd->list, &shost->free_list);
+ return 0;
}
/**
@@ -384,17 +486,10 @@ void scsi_destroy_command_freelist(struct Scsi_Host *shost)
cmd = list_entry(shost->free_list.next, struct scsi_cmnd, list);
list_del_init(&cmd->list);
- kmem_cache_free(shost->cmd_pool->sense_slab,
- cmd->sense_buffer);
- kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
+ scsi_pool_free_command(shost->cmd_pool, cmd);
}
-
- mutex_lock(&host_cmd_pool_mutex);
- if (!--shost->cmd_pool->users) {
- kmem_cache_destroy(shost->cmd_pool->cmd_slab);
- kmem_cache_destroy(shost->cmd_pool->sense_slab);
- }
- mutex_unlock(&host_cmd_pool_mutex);
+ shost->cmd_pool = NULL;
+ scsi_put_host_cmd_pool(shost->unchecked_isa_dma ? GFP_DMA : GFP_KERNEL);
}
#ifdef CONFIG_SCSI_LOGGING
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index d1777a9a9625..4f4c5b7bdef5 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -39,16 +39,17 @@
#include <linux/vmalloc.h>
#include <linux/moduleparam.h>
#include <linux/scatterlist.h>
-
#include <linux/blkdev.h>
-#include "scsi.h"
+
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>
#include <scsi/scsicam.h>
#include <linux/stat.h>
#include "scsi_logging.h"
-#include "scsi_debug.h"
#define SCSI_DEBUG_VERSION "1.81"
static const char * scsi_debug_version_date = "20070104";
@@ -165,6 +166,9 @@ static int sdebug_sectors_per; /* sectors per cylinder */
#define SDEBUG_SENSE_LEN 32
+#define SCSI_DEBUG_CANQUEUE 255
+#define SCSI_DEBUG_MAX_CMD_LEN 16
+
struct sdebug_dev_info {
struct list_head dev_list;
unsigned char sense_buff[SDEBUG_SENSE_LEN]; /* weak nexus */
@@ -202,30 +206,6 @@ struct sdebug_queued_cmd {
};
static struct sdebug_queued_cmd queued_arr[SCSI_DEBUG_CANQUEUE];
-static struct scsi_host_template sdebug_driver_template = {
- .proc_info = scsi_debug_proc_info,
- .name = "SCSI DEBUG",
- .info = scsi_debug_info,
- .slave_alloc = scsi_debug_slave_alloc,
- .slave_configure = scsi_debug_slave_configure,
- .slave_destroy = scsi_debug_slave_destroy,
- .ioctl = scsi_debug_ioctl,
- .queuecommand = scsi_debug_queuecommand,
- .eh_abort_handler = scsi_debug_abort,
- .eh_bus_reset_handler = scsi_debug_bus_reset,
- .eh_device_reset_handler = scsi_debug_device_reset,
- .eh_host_reset_handler = scsi_debug_host_reset,
- .bios_param = scsi_debug_biosparam,
- .can_queue = SCSI_DEBUG_CANQUEUE,
- .this_id = 7,
- .sg_tablesize = 256,
- .cmd_per_lun = 16,
- .max_sectors = 0xffff,
- .unchecked_isa_dma = 0,
- .use_clustering = DISABLE_CLUSTERING,
- .module = THIS_MODULE,
-};
-
static unsigned char * fake_storep; /* ramdisk storage */
static int num_aborts = 0;
@@ -255,56 +235,11 @@ static unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0,
static unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
0, 0, 0x0, 0x0};
-/* function declarations */
-static int resp_inquiry(struct scsi_cmnd * SCpnt, int target,
- struct sdebug_dev_info * devip);
-static int resp_requests(struct scsi_cmnd * SCpnt,
- struct sdebug_dev_info * devip);
-static int resp_start_stop(struct scsi_cmnd * scp,
- struct sdebug_dev_info * devip);
-static int resp_report_tgtpgs(struct scsi_cmnd * scp,
- struct sdebug_dev_info * devip);
-static int resp_readcap(struct scsi_cmnd * SCpnt,
- struct sdebug_dev_info * devip);
-static int resp_readcap16(struct scsi_cmnd * SCpnt,
- struct sdebug_dev_info * devip);
-static int resp_mode_sense(struct scsi_cmnd * scp, int target,
- struct sdebug_dev_info * devip);
-static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
- struct sdebug_dev_info * devip);
-static int resp_log_sense(struct scsi_cmnd * scp,
- struct sdebug_dev_info * devip);
-static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba,
- unsigned int num, struct sdebug_dev_info * devip);
-static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba,
- unsigned int num, struct sdebug_dev_info * devip);
-static int resp_report_luns(struct scsi_cmnd * SCpnt,
- struct sdebug_dev_info * devip);
-static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
- unsigned int num, struct sdebug_dev_info *devip);
-static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
- int arr_len);
-static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
- int max_arr_len);
-static void timer_intr_handler(unsigned long);
static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev);
static void mk_sense_buffer(struct sdebug_dev_info * devip, int key,
int asc, int asq);
-static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only,
- struct sdebug_dev_info * devip);
-static int schedule_resp(struct scsi_cmnd * cmnd,
- struct sdebug_dev_info * devip,
- done_funct_t done, int scsi_result, int delta_jiff);
-static void __init sdebug_build_parts(unsigned char * ramp);
-static void __init init_all_queued(void);
static void stop_all_queued(void);
static int stop_queued_cmnd(struct scsi_cmnd * cmnd);
-static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
- int target_dev_id, int dev_id_num,
- const char * dev_id_str, int dev_id_str_len);
-static int inquiry_evpd_88(unsigned char * arr, int target_dev_id);
-static int do_create_driverfs_files(void);
-static void do_remove_driverfs_files(void);
static int sdebug_add_adapter(void);
static void sdebug_remove_adapter(void);
@@ -350,237 +285,6 @@ static void get_data_transfer_info(unsigned char *cmd,
}
}
-static
-int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
-{
- unsigned char *cmd = (unsigned char *) SCpnt->cmnd;
- int len, k;
- unsigned int num;
- unsigned long long lba;
- int errsts = 0;
- int target = SCpnt->device->id;
- struct sdebug_dev_info * devip = NULL;
- int inj_recovered = 0;
- int inj_transport = 0;
- int delay_override = 0;
-
- if (done == NULL)
- return 0; /* assume mid level reprocessing command */
-
- scsi_set_resid(SCpnt, 0);
- if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) {
- printk(KERN_INFO "scsi_debug: cmd ");
- for (k = 0, len = SCpnt->cmd_len; k < len; ++k)
- printk("%02x ", (int)cmd[k]);
- printk("\n");
- }
- if(target == sdebug_driver_template.this_id) {
- printk(KERN_INFO "scsi_debug: initiator's id used as "
- "target!\n");
- return schedule_resp(SCpnt, NULL, done,
- DID_NO_CONNECT << 16, 0);
- }
-
- if ((SCpnt->device->lun >= scsi_debug_max_luns) &&
- (SCpnt->device->lun != SAM2_WLUN_REPORT_LUNS))
- return schedule_resp(SCpnt, NULL, done,
- DID_NO_CONNECT << 16, 0);
- devip = devInfoReg(SCpnt->device);
- if (NULL == devip)
- return schedule_resp(SCpnt, NULL, done,
- DID_NO_CONNECT << 16, 0);
-
- if ((scsi_debug_every_nth != 0) &&
- (++scsi_debug_cmnd_count >= abs(scsi_debug_every_nth))) {
- scsi_debug_cmnd_count = 0;
- if (scsi_debug_every_nth < -1)
- scsi_debug_every_nth = -1;
- if (SCSI_DEBUG_OPT_TIMEOUT & scsi_debug_opts)
- return 0; /* ignore command causing timeout */
- else if (SCSI_DEBUG_OPT_RECOVERED_ERR & scsi_debug_opts)
- inj_recovered = 1; /* to reads and writes below */
- else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & scsi_debug_opts)
- inj_transport = 1; /* to reads and writes below */
- }
-
- if (devip->wlun) {
- switch (*cmd) {
- case INQUIRY:
- case REQUEST_SENSE:
- case TEST_UNIT_READY:
- case REPORT_LUNS:
- break; /* only allowable wlun commands */
- default:
- if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: Opcode: 0x%x "
- "not supported for wlun\n", *cmd);
- mk_sense_buffer(devip, ILLEGAL_REQUEST,
- INVALID_OPCODE, 0);
- errsts = check_condition_result;
- return schedule_resp(SCpnt, devip, done, errsts,
- 0);
- }
- }
-
- switch (*cmd) {
- case INQUIRY: /* mandatory, ignore unit attention */
- delay_override = 1;
- errsts = resp_inquiry(SCpnt, target, devip);
- break;
- case REQUEST_SENSE: /* mandatory, ignore unit attention */
- delay_override = 1;
- errsts = resp_requests(SCpnt, devip);
- break;
- case REZERO_UNIT: /* actually this is REWIND for SSC */
- case START_STOP:
- errsts = resp_start_stop(SCpnt, devip);
- break;
- case ALLOW_MEDIUM_REMOVAL:
- if ((errsts = check_readiness(SCpnt, 1, devip)))
- break;
- if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: Medium removal %s\n",
- cmd[4] ? "inhibited" : "enabled");
- break;
- case SEND_DIAGNOSTIC: /* mandatory */
- errsts = check_readiness(SCpnt, 1, devip);
- break;
- case TEST_UNIT_READY: /* mandatory */
- delay_override = 1;
- errsts = check_readiness(SCpnt, 0, devip);
- break;
- case RESERVE:
- errsts = check_readiness(SCpnt, 1, devip);
- break;
- case RESERVE_10:
- errsts = check_readiness(SCpnt, 1, devip);
- break;
- case RELEASE:
- errsts = check_readiness(SCpnt, 1, devip);
- break;
- case RELEASE_10:
- errsts = check_readiness(SCpnt, 1, devip);
- break;
- case READ_CAPACITY:
- errsts = resp_readcap(SCpnt, devip);
- break;
- case SERVICE_ACTION_IN:
- if (SAI_READ_CAPACITY_16 != cmd[1]) {
- mk_sense_buffer(devip, ILLEGAL_REQUEST,
- INVALID_OPCODE, 0);
- errsts = check_condition_result;
- break;
- }
- errsts = resp_readcap16(SCpnt, devip);
- break;
- case MAINTENANCE_IN:
- if (MI_REPORT_TARGET_PGS != cmd[1]) {
- mk_sense_buffer(devip, ILLEGAL_REQUEST,
- INVALID_OPCODE, 0);
- errsts = check_condition_result;
- break;
- }
- errsts = resp_report_tgtpgs(SCpnt, devip);
- break;
- case READ_16:
- case READ_12:
- case READ_10:
- case READ_6:
- if ((errsts = check_readiness(SCpnt, 0, devip)))
- break;
- if (scsi_debug_fake_rw)
- break;
- get_data_transfer_info(cmd, &lba, &num);
- errsts = resp_read(SCpnt, lba, num, devip);
- if (inj_recovered && (0 == errsts)) {
- mk_sense_buffer(devip, RECOVERED_ERROR,
- THRESHOLD_EXCEEDED, 0);
- errsts = check_condition_result;
- } else if (inj_transport && (0 == errsts)) {
- mk_sense_buffer(devip, ABORTED_COMMAND,
- TRANSPORT_PROBLEM, ACK_NAK_TO);
- errsts = check_condition_result;
- }
- break;
- case REPORT_LUNS: /* mandatory, ignore unit attention */
- delay_override = 1;
- errsts = resp_report_luns(SCpnt, devip);
- break;
- case VERIFY: /* 10 byte SBC-2 command */
- errsts = check_readiness(SCpnt, 0, devip);
- break;
- case WRITE_16:
- case WRITE_12:
- case WRITE_10:
- case WRITE_6:
- if ((errsts = check_readiness(SCpnt, 0, devip)))
- break;
- if (scsi_debug_fake_rw)
- break;
- get_data_transfer_info(cmd, &lba, &num);
- errsts = resp_write(SCpnt, lba, num, devip);
- if (inj_recovered && (0 == errsts)) {
- mk_sense_buffer(devip, RECOVERED_ERROR,
- THRESHOLD_EXCEEDED, 0);
- errsts = check_condition_result;
- }
- break;
- case MODE_SENSE:
- case MODE_SENSE_10:
- errsts = resp_mode_sense(SCpnt, target, devip);
- break;
- case MODE_SELECT:
- errsts = resp_mode_select(SCpnt, 1, devip);
- break;
- case MODE_SELECT_10:
- errsts = resp_mode_select(SCpnt, 0, devip);
- break;
- case LOG_SENSE:
- errsts = resp_log_sense(SCpnt, devip);
- break;
- case SYNCHRONIZE_CACHE:
- delay_override = 1;
- errsts = check_readiness(SCpnt, 0, devip);
- break;
- case WRITE_BUFFER:
- errsts = check_readiness(SCpnt, 1, devip);
- break;
- case XDWRITEREAD_10:
- if (!scsi_bidi_cmnd(SCpnt)) {
- mk_sense_buffer(devip, ILLEGAL_REQUEST,
- INVALID_FIELD_IN_CDB, 0);
- errsts = check_condition_result;
- break;
- }
-
- errsts = check_readiness(SCpnt, 0, devip);
- if (errsts)
- break;
- if (scsi_debug_fake_rw)
- break;
- get_data_transfer_info(cmd, &lba, &num);
- errsts = resp_read(SCpnt, lba, num, devip);
- if (errsts)
- break;
- errsts = resp_write(SCpnt, lba, num, devip);
- if (errsts)
- break;
- errsts = resp_xdwriteread(SCpnt, lba, num, devip);
- break;
- default:
- if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: Opcode: 0x%x not "
- "supported\n", *cmd);
- if ((errsts = check_readiness(SCpnt, 1, devip)))
- break; /* Unit attention takes precedence */
- mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0);
- errsts = check_condition_result;
- break;
- }
- return schedule_resp(SCpnt, devip, done, errsts,
- (delay_override ? 0 : scsi_debug_delay));
-}
-
static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
{
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) {
@@ -613,81 +317,37 @@ static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only,
}
/* Returns 0 if ok else (DID_ERROR << 16). Sets scp->resid . */
-static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
+static int fill_from_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
int arr_len)
{
- int k, req_len, act_len, len, active;
- void * kaddr;
- void * kaddr_off;
- struct scatterlist *sg;
+ int act_len;
struct scsi_data_buffer *sdb = scsi_in(scp);
if (!sdb->length)
return 0;
- if (!sdb->table.sgl)
- return (DID_ERROR << 16);
if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_FROM_DEVICE))
return (DID_ERROR << 16);
- active = 1;
- req_len = act_len = 0;
- for_each_sg(sdb->table.sgl, sg, sdb->table.nents, k) {
- if (active) {
- kaddr = (unsigned char *)
- kmap_atomic(sg_page(sg), KM_USER0);
- if (NULL == kaddr)
- return (DID_ERROR << 16);
- kaddr_off = (unsigned char *)kaddr + sg->offset;
- len = sg->length;
- if ((req_len + len) > arr_len) {
- active = 0;
- len = arr_len - req_len;
- }
- memcpy(kaddr_off, arr + req_len, len);
- kunmap_atomic(kaddr, KM_USER0);
- act_len += len;
- }
- req_len += sg->length;
- }
+
+ act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents,
+ arr, arr_len);
if (sdb->resid)
sdb->resid -= act_len;
else
- sdb->resid = req_len - act_len;
+ sdb->resid = scsi_bufflen(scp) - act_len;
+
return 0;
}
/* Returns number of bytes fetched into 'arr' or -1 if error. */
-static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
- int max_arr_len)
+static int fetch_to_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
+ int arr_len)
{
- int k, req_len, len, fin;
- void * kaddr;
- void * kaddr_off;
- struct scatterlist * sg;
-
- if (0 == scsi_bufflen(scp))
+ if (!scsi_bufflen(scp))
return 0;
- if (NULL == scsi_sglist(scp))
- return -1;
if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_TO_DEVICE))
return -1;
- req_len = fin = 0;
- scsi_for_each_sg(scp, sg, scsi_sg_count(scp), k) {
- kaddr = (unsigned char *)kmap_atomic(sg_page(sg), KM_USER0);
- if (NULL == kaddr)
- return -1;
- kaddr_off = (unsigned char *)kaddr + sg->offset;
- len = sg->length;
- if ((req_len + len) > max_arr_len) {
- len = max_arr_len - req_len;
- fin = 1;
- }
- memcpy(arr + req_len, kaddr_off, len);
- kunmap_atomic(kaddr, KM_USER0);
- if (fin)
- return req_len + len;
- req_len += sg->length;
- }
- return req_len;
+
+ return scsi_sg_copy_to_buffer(scp, arr, arr_len);
}
@@ -1987,16 +1647,7 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
if (!buf)
return ret;
- offset = 0;
- scsi_for_each_sg(scp, sg, scsi_sg_count(scp), i) {
- kaddr = (unsigned char *)kmap_atomic(sg_page(sg), KM_USER0);
- if (!kaddr)
- goto out;
-
- memcpy(buf + offset, kaddr + sg->offset, sg->length);
- offset += sg->length;
- kunmap_atomic(kaddr, KM_USER0);
- }
+ scsi_sg_copy_to_buffer(scp, buf, scsi_bufflen(scp));
offset = 0;
for_each_sg(sdb->table.sgl, sg, sdb->table.nents, i) {
@@ -2089,6 +1740,19 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp)
}
}
+struct sdebug_dev_info *sdebug_device_create(struct sdebug_host_info *sdbg_host,
+ gfp_t flags)
+{
+ struct sdebug_dev_info *devip;
+
+ devip = kzalloc(sizeof(*devip), flags);
+ if (devip) {
+ devip->sdbg_host = sdbg_host;
+ list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list);
+ }
+ return devip;
+}
+
static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
{
struct sdebug_host_info * sdbg_host;
@@ -2098,8 +1762,8 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
if (devip)
return devip;
- sdbg_host = *(struct sdebug_host_info **) sdev->host->hostdata;
- if(! sdbg_host) {
+ sdbg_host = *(struct sdebug_host_info **)shost_priv(sdev->host);
+ if (!sdbg_host) {
printk(KERN_ERR "Host info NULL\n");
return NULL;
}
@@ -2113,36 +1777,32 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
open_devip = devip;
}
}
- if (NULL == open_devip) { /* try and make a new one */
- open_devip = kzalloc(sizeof(*open_devip),GFP_ATOMIC);
- if (NULL == open_devip) {
+ if (!open_devip) { /* try and make a new one */
+ open_devip = sdebug_device_create(sdbg_host, GFP_ATOMIC);
+ if (!open_devip) {
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
return NULL;
}
- open_devip->sdbg_host = sdbg_host;
- list_add_tail(&open_devip->dev_list,
- &sdbg_host->dev_info_list);
- }
- if (open_devip) {
- open_devip->channel = sdev->channel;
- open_devip->target = sdev->id;
- open_devip->lun = sdev->lun;
- open_devip->sdbg_host = sdbg_host;
- open_devip->reset = 1;
- open_devip->used = 1;
- memset(open_devip->sense_buff, 0, SDEBUG_SENSE_LEN);
- if (scsi_debug_dsense)
- open_devip->sense_buff[0] = 0x72;
- else {
- open_devip->sense_buff[0] = 0x70;
- open_devip->sense_buff[7] = 0xa;
- }
- if (sdev->lun == SAM2_WLUN_REPORT_LUNS)
- open_devip->wlun = SAM2_WLUN_REPORT_LUNS & 0xff;
- return open_devip;
- }
- return NULL;
+ }
+
+ open_devip->channel = sdev->channel;
+ open_devip->target = sdev->id;
+ open_devip->lun = sdev->lun;
+ open_devip->sdbg_host = sdbg_host;
+ open_devip->reset = 1;
+ open_devip->used = 1;
+ memset(open_devip->sense_buff, 0, SDEBUG_SENSE_LEN);
+ if (scsi_debug_dsense)
+ open_devip->sense_buff[0] = 0x72;
+ else {
+ open_devip->sense_buff[0] = 0x70;
+ open_devip->sense_buff[7] = 0xa;
+ }
+ if (sdev->lun == SAM2_WLUN_REPORT_LUNS)
+ open_devip->wlun = SAM2_WLUN_REPORT_LUNS & 0xff;
+
+ return open_devip;
}
static void mk_sense_buffer(struct sdebug_dev_info * devip, int key,
@@ -2226,7 +1886,7 @@ static int scsi_debug_bus_reset(struct scsi_cmnd * SCpnt)
printk(KERN_INFO "scsi_debug: bus_reset\n");
++num_bus_resets;
if (SCpnt && ((sdp = SCpnt->device)) && ((hp = sdp->host))) {
- sdbg_host = *(struct sdebug_host_info **) hp->hostdata;
+ sdbg_host = *(struct sdebug_host_info **)shost_priv(hp);
if (sdbg_host) {
list_for_each_entry(dev_info,
&sdbg_host->dev_info_list,
@@ -2756,21 +2416,10 @@ static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf)
static ssize_t sdebug_add_host_store(struct device_driver * ddp,
const char * buf, size_t count)
{
- int delta_hosts;
- char work[20];
+ int delta_hosts;
- if (1 != sscanf(buf, "%10s", work))
+ if (sscanf(buf, "%d", &delta_hosts) != 1)
return -EINVAL;
- { /* temporary hack around sscanf() problem with -ve nums */
- int neg = 0;
-
- if ('-' == *work)
- neg = 1;
- if (1 != sscanf(work + neg, "%d", &delta_hosts))
- return -EINVAL;
- if (neg)
- delta_hosts = -delta_hosts;
- }
if (delta_hosts > 0) {
do {
sdebug_add_adapter();
@@ -2782,7 +2431,7 @@ static ssize_t sdebug_add_host_store(struct device_driver * ddp,
}
return count;
}
-DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show,
+DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show,
sdebug_add_host_store);
static ssize_t sdebug_vpd_use_hostno_show(struct device_driver * ddp,
@@ -2922,8 +2571,6 @@ static int __init scsi_debug_init(void)
init_all_queued();
- sdebug_driver_template.proc_name = sdebug_proc_name;
-
host_to_add = scsi_debug_add_host;
scsi_debug_add_host = 0;
@@ -3009,8 +2656,7 @@ static int sdebug_add_adapter(void)
int k, devs_per_host;
int error = 0;
struct sdebug_host_info *sdbg_host;
- struct sdebug_dev_info *sdbg_devinfo;
- struct list_head *lh, *lh_sf;
+ struct sdebug_dev_info *sdbg_devinfo, *tmp;
sdbg_host = kzalloc(sizeof(*sdbg_host),GFP_KERNEL);
if (NULL == sdbg_host) {
@@ -3023,16 +2669,13 @@ static int sdebug_add_adapter(void)
devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns;
for (k = 0; k < devs_per_host; k++) {
- sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo),GFP_KERNEL);
- if (NULL == sdbg_devinfo) {
+ sdbg_devinfo = sdebug_device_create(sdbg_host, GFP_KERNEL);
+ if (!sdbg_devinfo) {
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
error = -ENOMEM;
goto clean;
}
- sdbg_devinfo->sdbg_host = sdbg_host;
- list_add_tail(&sdbg_devinfo->dev_list,
- &sdbg_host->dev_info_list);
}
spin_lock(&sdebug_host_list_lock);
@@ -3053,9 +2696,8 @@ static int sdebug_add_adapter(void)
return error;
clean:
- list_for_each_safe(lh, lh_sf, &sdbg_host->dev_info_list) {
- sdbg_devinfo = list_entry(lh, struct sdebug_dev_info,
- dev_list);
+ list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list,
+ dev_list) {
list_del(&sdbg_devinfo->dev_list);
kfree(sdbg_devinfo);
}
@@ -3083,6 +2725,263 @@ static void sdebug_remove_adapter(void)
--scsi_debug_add_host;
}
+static
+int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done)
+{
+ unsigned char *cmd = (unsigned char *) SCpnt->cmnd;
+ int len, k;
+ unsigned int num;
+ unsigned long long lba;
+ int errsts = 0;
+ int target = SCpnt->device->id;
+ struct sdebug_dev_info *devip = NULL;
+ int inj_recovered = 0;
+ int inj_transport = 0;
+ int delay_override = 0;
+
+ scsi_set_resid(SCpnt, 0);
+ if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) {
+ printk(KERN_INFO "scsi_debug: cmd ");
+ for (k = 0, len = SCpnt->cmd_len; k < len; ++k)
+ printk("%02x ", (int)cmd[k]);
+ printk("\n");
+ }
+
+ if (target == SCpnt->device->host->hostt->this_id) {
+ printk(KERN_INFO "scsi_debug: initiator's id used as "
+ "target!\n");
+ return schedule_resp(SCpnt, NULL, done,
+ DID_NO_CONNECT << 16, 0);
+ }
+
+ if ((SCpnt->device->lun >= scsi_debug_max_luns) &&
+ (SCpnt->device->lun != SAM2_WLUN_REPORT_LUNS))
+ return schedule_resp(SCpnt, NULL, done,
+ DID_NO_CONNECT << 16, 0);
+ devip = devInfoReg(SCpnt->device);
+ if (NULL == devip)
+ return schedule_resp(SCpnt, NULL, done,
+ DID_NO_CONNECT << 16, 0);
+
+ if ((scsi_debug_every_nth != 0) &&
+ (++scsi_debug_cmnd_count >= abs(scsi_debug_every_nth))) {
+ scsi_debug_cmnd_count = 0;
+ if (scsi_debug_every_nth < -1)
+ scsi_debug_every_nth = -1;
+ if (SCSI_DEBUG_OPT_TIMEOUT & scsi_debug_opts)
+ return 0; /* ignore command causing timeout */
+ else if (SCSI_DEBUG_OPT_RECOVERED_ERR & scsi_debug_opts)
+ inj_recovered = 1; /* to reads and writes below */
+ else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & scsi_debug_opts)
+ inj_transport = 1; /* to reads and writes below */
+ }
+
+ if (devip->wlun) {
+ switch (*cmd) {
+ case INQUIRY:
+ case REQUEST_SENSE:
+ case TEST_UNIT_READY:
+ case REPORT_LUNS:
+ break; /* only allowable wlun commands */
+ default:
+ if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
+ printk(KERN_INFO "scsi_debug: Opcode: 0x%x "
+ "not supported for wlun\n", *cmd);
+ mk_sense_buffer(devip, ILLEGAL_REQUEST,
+ INVALID_OPCODE, 0);
+ errsts = check_condition_result;
+ return schedule_resp(SCpnt, devip, done, errsts,
+ 0);
+ }
+ }
+
+ switch (*cmd) {
+ case INQUIRY: /* mandatory, ignore unit attention */
+ delay_override = 1;
+ errsts = resp_inquiry(SCpnt, target, devip);
+ break;
+ case REQUEST_SENSE: /* mandatory, ignore unit attention */
+ delay_override = 1;
+ errsts = resp_requests(SCpnt, devip);
+ break;
+ case REZERO_UNIT: /* actually this is REWIND for SSC */
+ case START_STOP:
+ errsts = resp_start_stop(SCpnt, devip);
+ break;
+ case ALLOW_MEDIUM_REMOVAL:
+ errsts = check_readiness(SCpnt, 1, devip);
+ if (errsts)
+ break;
+ if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
+ printk(KERN_INFO "scsi_debug: Medium removal %s\n",
+ cmd[4] ? "inhibited" : "enabled");
+ break;
+ case SEND_DIAGNOSTIC: /* mandatory */
+ errsts = check_readiness(SCpnt, 1, devip);
+ break;
+ case TEST_UNIT_READY: /* mandatory */
+ delay_override = 1;
+ errsts = check_readiness(SCpnt, 0, devip);
+ break;
+ case RESERVE:
+ errsts = check_readiness(SCpnt, 1, devip);
+ break;
+ case RESERVE_10:
+ errsts = check_readiness(SCpnt, 1, devip);
+ break;
+ case RELEASE:
+ errsts = check_readiness(SCpnt, 1, devip);
+ break;
+ case RELEASE_10:
+ errsts = check_readiness(SCpnt, 1, devip);
+ break;
+ case READ_CAPACITY:
+ errsts = resp_readcap(SCpnt, devip);
+ break;
+ case SERVICE_ACTION_IN:
+ if (SAI_READ_CAPACITY_16 != cmd[1]) {
+ mk_sense_buffer(devip, ILLEGAL_REQUEST,
+ INVALID_OPCODE, 0);
+ errsts = check_condition_result;
+ break;
+ }
+ errsts = resp_readcap16(SCpnt, devip);
+ break;
+ case MAINTENANCE_IN:
+ if (MI_REPORT_TARGET_PGS != cmd[1]) {
+ mk_sense_buffer(devip, ILLEGAL_REQUEST,
+ INVALID_OPCODE, 0);
+ errsts = check_condition_result;
+ break;
+ }
+ errsts = resp_report_tgtpgs(SCpnt, devip);
+ break;
+ case READ_16:
+ case READ_12:
+ case READ_10:
+ case READ_6:
+ errsts = check_readiness(SCpnt, 0, devip);
+ if (errsts)
+ break;
+ if (scsi_debug_fake_rw)
+ break;
+ get_data_transfer_info(cmd, &lba, &num);
+ errsts = resp_read(SCpnt, lba, num, devip);
+ if (inj_recovered && (0 == errsts)) {
+ mk_sense_buffer(devip, RECOVERED_ERROR,
+ THRESHOLD_EXCEEDED, 0);
+ errsts = check_condition_result;
+ } else if (inj_transport && (0 == errsts)) {
+ mk_sense_buffer(devip, ABORTED_COMMAND,
+ TRANSPORT_PROBLEM, ACK_NAK_TO);
+ errsts = check_condition_result;
+ }
+ break;
+ case REPORT_LUNS: /* mandatory, ignore unit attention */
+ delay_override = 1;
+ errsts = resp_report_luns(SCpnt, devip);
+ break;
+ case VERIFY: /* 10 byte SBC-2 command */
+ errsts = check_readiness(SCpnt, 0, devip);
+ break;
+ case WRITE_16:
+ case WRITE_12:
+ case WRITE_10:
+ case WRITE_6:
+ errsts = check_readiness(SCpnt, 0, devip);
+ if (errsts)
+ break;
+ if (scsi_debug_fake_rw)
+ break;
+ get_data_transfer_info(cmd, &lba, &num);
+ errsts = resp_write(SCpnt, lba, num, devip);
+ if (inj_recovered && (0 == errsts)) {
+ mk_sense_buffer(devip, RECOVERED_ERROR,
+ THRESHOLD_EXCEEDED, 0);
+ errsts = check_condition_result;
+ }
+ break;
+ case MODE_SENSE:
+ case MODE_SENSE_10:
+ errsts = resp_mode_sense(SCpnt, target, devip);
+ break;
+ case MODE_SELECT:
+ errsts = resp_mode_select(SCpnt, 1, devip);
+ break;
+ case MODE_SELECT_10:
+ errsts = resp_mode_select(SCpnt, 0, devip);
+ break;
+ case LOG_SENSE:
+ errsts = resp_log_sense(SCpnt, devip);
+ break;
+ case SYNCHRONIZE_CACHE:
+ delay_override = 1;
+ errsts = check_readiness(SCpnt, 0, devip);
+ break;
+ case WRITE_BUFFER:
+ errsts = check_readiness(SCpnt, 1, devip);
+ break;
+ case XDWRITEREAD_10:
+ if (!scsi_bidi_cmnd(SCpnt)) {
+ mk_sense_buffer(devip, ILLEGAL_REQUEST,
+ INVALID_FIELD_IN_CDB, 0);
+ errsts = check_condition_result;
+ break;
+ }
+
+ errsts = check_readiness(SCpnt, 0, devip);
+ if (errsts)
+ break;
+ if (scsi_debug_fake_rw)
+ break;
+ get_data_transfer_info(cmd, &lba, &num);
+ errsts = resp_read(SCpnt, lba, num, devip);
+ if (errsts)
+ break;
+ errsts = resp_write(SCpnt, lba, num, devip);
+ if (errsts)
+ break;
+ errsts = resp_xdwriteread(SCpnt, lba, num, devip);
+ break;
+ default:
+ if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
+ printk(KERN_INFO "scsi_debug: Opcode: 0x%x not "
+ "supported\n", *cmd);
+ errsts = check_readiness(SCpnt, 1, devip);
+ if (errsts)
+ break; /* Unit attention takes precedence */
+ mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0);
+ errsts = check_condition_result;
+ break;
+ }
+ return schedule_resp(SCpnt, devip, done, errsts,
+ (delay_override ? 0 : scsi_debug_delay));
+}
+
+static struct scsi_host_template sdebug_driver_template = {
+ .proc_info = scsi_debug_proc_info,
+ .proc_name = sdebug_proc_name,
+ .name = "SCSI DEBUG",
+ .info = scsi_debug_info,
+ .slave_alloc = scsi_debug_slave_alloc,
+ .slave_configure = scsi_debug_slave_configure,
+ .slave_destroy = scsi_debug_slave_destroy,
+ .ioctl = scsi_debug_ioctl,
+ .queuecommand = scsi_debug_queuecommand,
+ .eh_abort_handler = scsi_debug_abort,
+ .eh_bus_reset_handler = scsi_debug_bus_reset,
+ .eh_device_reset_handler = scsi_debug_device_reset,
+ .eh_host_reset_handler = scsi_debug_host_reset,
+ .bios_param = scsi_debug_biosparam,
+ .can_queue = SCSI_DEBUG_CANQUEUE,
+ .this_id = 7,
+ .sg_tablesize = 256,
+ .cmd_per_lun = 16,
+ .max_sectors = 0xffff,
+ .use_clustering = DISABLE_CLUSTERING,
+ .module = THIS_MODULE,
+};
+
static int sdebug_driver_probe(struct device * dev)
{
int error = 0;
@@ -3120,9 +3019,8 @@ static int sdebug_driver_probe(struct device * dev)
static int sdebug_driver_remove(struct device * dev)
{
- struct list_head *lh, *lh_sf;
struct sdebug_host_info *sdbg_host;
- struct sdebug_dev_info *sdbg_devinfo;
+ struct sdebug_dev_info *sdbg_devinfo, *tmp;
sdbg_host = to_sdebug_host(dev);
@@ -3134,9 +3032,8 @@ static int sdebug_driver_remove(struct device * dev)
scsi_remove_host(sdbg_host->shost);
- list_for_each_safe(lh, lh_sf, &sdbg_host->dev_info_list) {
- sdbg_devinfo = list_entry(lh, struct sdebug_dev_info,
- dev_list);
+ list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list,
+ dev_list) {
list_del(&sdbg_devinfo->dev_list);
kfree(sdbg_devinfo);
}
diff --git a/drivers/scsi/scsi_debug.h b/drivers/scsi/scsi_debug.h
deleted file mode 100644
index 965dd5e760c1..000000000000
--- a/drivers/scsi/scsi_debug.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef _SCSI_DEBUG_H
-
-#include <linux/types.h>
-
-static int scsi_debug_slave_alloc(struct scsi_device *);
-static int scsi_debug_slave_configure(struct scsi_device *);
-static void scsi_debug_slave_destroy(struct scsi_device *);
-static int scsi_debug_queuecommand(struct scsi_cmnd *,
- void (*done) (struct scsi_cmnd *));
-static int scsi_debug_ioctl(struct scsi_device *, int, void __user *);
-static int scsi_debug_biosparam(struct scsi_device *, struct block_device *,
- sector_t, int[]);
-static int scsi_debug_abort(struct scsi_cmnd *);
-static int scsi_debug_bus_reset(struct scsi_cmnd *);
-static int scsi_debug_device_reset(struct scsi_cmnd *);
-static int scsi_debug_host_reset(struct scsi_cmnd *);
-static int scsi_debug_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
-static const char * scsi_debug_info(struct Scsi_Host *);
-
-#define SCSI_DEBUG_CANQUEUE 255 /* needs to be >= 1 */
-
-#define SCSI_DEBUG_MAX_CMD_LEN 16
-
-#endif
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 045a0868fc7b..1221d2ca0c64 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -524,6 +524,41 @@ static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
return rtn;
}
+static void __scsi_report_device_reset(struct scsi_device *sdev, void *data)
+{
+ sdev->was_reset = 1;
+ sdev->expecting_cc_ua = 1;
+}
+
+/**
+ * scsi_try_target_reset - Ask host to perform a target reset
+ * @scmd: SCSI cmd used to send a target reset
+ *
+ * Notes:
+ * There is no timeout for this operation. if this operation is
+ * unreliable for a given host, then the host itself needs to put a
+ * timer on it, and set the host back to a consistent state prior to
+ * returning.
+ */
+static int scsi_try_target_reset(struct scsi_cmnd *scmd)
+{
+ unsigned long flags;
+ int rtn;
+
+ if (!scmd->device->host->hostt->eh_target_reset_handler)
+ return FAILED;
+
+ rtn = scmd->device->host->hostt->eh_target_reset_handler(scmd);
+ if (rtn == SUCCESS) {
+ spin_lock_irqsave(scmd->device->host->host_lock, flags);
+ __starget_for_each_device(scsi_target(scmd->device), NULL,
+ __scsi_report_device_reset);
+ spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
+ }
+
+ return rtn;
+}
+
/**
* scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
* @scmd: SCSI cmd used to send BDR
@@ -542,11 +577,8 @@ static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
return FAILED;
rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
- if (rtn == SUCCESS) {
- scmd->device->was_reset = 1;
- scmd->device->expecting_cc_ua = 1;
- }
-
+ if (rtn == SUCCESS)
+ __scsi_report_device_reset(scmd->device, NULL);
return rtn;
}
@@ -584,8 +616,9 @@ static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
{
if (__scsi_try_to_abort_cmd(scmd) != SUCCESS)
if (scsi_try_bus_device_reset(scmd) != SUCCESS)
- if (scsi_try_bus_reset(scmd) != SUCCESS)
- scsi_try_host_reset(scmd);
+ if (scsi_try_target_reset(scmd) != SUCCESS)
+ if (scsi_try_bus_reset(scmd) != SUCCESS)
+ scsi_try_host_reset(scmd);
}
/**
@@ -1060,6 +1093,56 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
}
/**
+ * scsi_eh_target_reset - send target reset if needed
+ * @shost: scsi host being recovered.
+ * @work_q: &list_head for pending commands.
+ * @done_q: &list_head for processed commands.
+ *
+ * Notes:
+ * Try a target reset.
+ */
+static int scsi_eh_target_reset(struct Scsi_Host *shost,
+ struct list_head *work_q,
+ struct list_head *done_q)
+{
+ struct scsi_cmnd *scmd, *tgtr_scmd, *next;
+ unsigned int id;
+ int rtn;
+
+ for (id = 0; id <= shost->max_id; id++) {
+ tgtr_scmd = NULL;
+ list_for_each_entry(scmd, work_q, eh_entry) {
+ if (id == scmd_id(scmd)) {
+ tgtr_scmd = scmd;
+ break;
+ }
+ }
+ if (!tgtr_scmd)
+ continue;
+
+ SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending target reset "
+ "to target %d\n",
+ current->comm, id));
+ rtn = scsi_try_target_reset(tgtr_scmd);
+ if (rtn == SUCCESS) {
+ list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
+ if (id == scmd_id(scmd))
+ if (!scsi_device_online(scmd->device) ||
+ !scsi_eh_tur(tgtr_scmd))
+ scsi_eh_finish_cmd(scmd,
+ done_q);
+ }
+ } else
+ SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Target reset"
+ " failed target: "
+ "%d\n",
+ current->comm, id));
+ }
+
+ return list_empty(work_q);
+}
+
+/**
* scsi_eh_bus_reset - send a bus reset
* @shost: &scsi host being recovered.
* @work_q: &list_head for pending commands.
@@ -1447,9 +1530,11 @@ void scsi_eh_ready_devs(struct Scsi_Host *shost,
{
if (!scsi_eh_stu(shost, work_q, done_q))
if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
- if (!scsi_eh_bus_reset(shost, work_q, done_q))
- if (!scsi_eh_host_reset(work_q, done_q))
- scsi_eh_offline_sdevs(work_q, done_q);
+ if (!scsi_eh_target_reset(shost, work_q, done_q))
+ if (!scsi_eh_bus_reset(shost, work_q, done_q))
+ if (!scsi_eh_host_reset(work_q, done_q))
+ scsi_eh_offline_sdevs(work_q,
+ done_q);
}
EXPORT_SYMBOL_GPL(scsi_eh_ready_devs);
@@ -1619,10 +1704,8 @@ void scsi_report_bus_reset(struct Scsi_Host *shost, int channel)
struct scsi_device *sdev;
__shost_for_each_device(sdev, shost) {
- if (channel == sdev_channel(sdev)) {
- sdev->was_reset = 1;
- sdev->expecting_cc_ua = 1;
- }
+ if (channel == sdev_channel(sdev))
+ __scsi_report_device_reset(sdev, NULL);
}
}
EXPORT_SYMBOL(scsi_report_bus_reset);
@@ -1655,10 +1738,8 @@ void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
__shost_for_each_device(sdev, shost) {
if (channel == sdev_channel(sdev) &&
- target == sdev_id(sdev)) {
- sdev->was_reset = 1;
- sdev->expecting_cc_ua = 1;
- }
+ target == sdev_id(sdev))
+ __scsi_report_device_reset(sdev, NULL);
}
}
EXPORT_SYMBOL(scsi_report_device_reset);
@@ -1714,6 +1795,11 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
if (rtn == SUCCESS)
break;
/* FALLTHROUGH */
+ case SCSI_TRY_RESET_TARGET:
+ rtn = scsi_try_target_reset(scmd);
+ if (rtn == SUCCESS)
+ break;
+ /* FALLTHROUGH */
case SCSI_TRY_RESET_BUS:
rtn = scsi_try_bus_reset(scmd);
if (rtn == SUCCESS)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index e29400d7ee3b..eb47dcb3d63c 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -17,7 +17,7 @@
Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
*/
-static const char *verstr = "20080221";
+static const char *verstr = "20080224";
#include <linux/module.h>
@@ -183,6 +183,7 @@ static int modes_defined;
static struct st_buffer *new_tape_buffer(int, int, int);
static int enlarge_buffer(struct st_buffer *, int, int);
+static void clear_buffer(struct st_buffer *);
static void normalize_buffer(struct st_buffer *);
static int append_to_buffer(const char __user *, struct st_buffer *, int);
static int from_buffer(struct st_buffer *, char __user *, int);
@@ -442,6 +443,7 @@ static void st_sleep_done(void *data, char *sense, int result, int resid)
memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE);
(STp->buffer)->cmdstat.midlevel_result = SRpnt->result = result;
+ (STp->buffer)->cmdstat.residual = resid;
DEB( STp->write_pending = 0; )
if (SRpnt->waiting)
@@ -1159,6 +1161,7 @@ static int st_open(struct inode *inode, struct file *filp)
goto err_out;
}
+ (STp->buffer)->cleared = 0;
(STp->buffer)->writing = 0;
(STp->buffer)->syscall_result = 0;
@@ -1432,8 +1435,14 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
if (STp->block_size)
bufsize = STp->block_size > st_fixed_buffer_size ?
STp->block_size : st_fixed_buffer_size;
- else
+ else {
bufsize = count;
+ /* Make sure that data from previous user is not leaked even if
+ HBA does not return correct residual */
+ if (is_read && STp->sili && !STbp->cleared)
+ clear_buffer(STbp);
+ }
+
if (bufsize > STbp->buffer_size &&
!enlarge_buffer(STbp, bufsize, STp->restr_dma)) {
printk(KERN_WARNING "%s: Can't allocate %d byte tape buffer.\n",
@@ -1783,6 +1792,8 @@ static long read_tape(struct scsi_tape *STp, long count,
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = READ_6;
cmd[1] = (STp->block_size != 0);
+ if (!cmd[1] && STp->sili)
+ cmd[1] |= 2;
cmd[2] = blks >> 16;
cmd[3] = blks >> 8;
cmd[4] = blks;
@@ -1911,8 +1922,11 @@ static long read_tape(struct scsi_tape *STp, long count,
}
/* End of error handling */
- else /* Read successful */
+ else { /* Read successful */
STbp->buffer_bytes = bytes;
+ if (STp->sili) /* In fixed block mode residual is always zero here */
+ STbp->buffer_bytes -= STp->buffer->cmdstat.residual;
+ }
if (STps->drv_block >= 0) {
if (STp->block_size == 0)
@@ -2090,7 +2104,8 @@ static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm, char
name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions,
STp->scsi2_logical);
printk(KERN_INFO
- "%s: sysv: %d nowait: %d\n", name, STm->sysv, STp->immediate);
+ "%s: sysv: %d nowait: %d sili: %d\n", name, STm->sysv, STp->immediate,
+ STp->sili);
printk(KERN_INFO "%s: debugging: %d\n",
name, debugging);
}
@@ -2133,6 +2148,7 @@ static int st_set_options(struct scsi_tape *STp, long options)
STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
STp->immediate = (options & MT_ST_NOWAIT) != 0;
STm->sysv = (options & MT_ST_SYSV) != 0;
+ STp->sili = (options & MT_ST_SILI) != 0;
DEB( debugging = (options & MT_ST_DEBUGGING) != 0;
st_log_options(STp, STm, name); )
} else if (code == MT_ST_SETBOOLEANS || code == MT_ST_CLEARBOOLEANS) {
@@ -2164,6 +2180,8 @@ static int st_set_options(struct scsi_tape *STp, long options)
STp->immediate = value;
if ((options & MT_ST_SYSV) != 0)
STm->sysv = value;
+ if ((options & MT_ST_SILI) != 0)
+ STp->sili = value;
DEB(
if ((options & MT_ST_DEBUGGING) != 0)
debugging = value;
@@ -3655,6 +3673,8 @@ static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dm
STbuffer->frp_segs += 1;
got += b_size;
STbuffer->buffer_size = got;
+ if (STbuffer->cleared)
+ memset(page_address(STbuffer->frp[segs].page), 0, b_size);
segs++;
}
STbuffer->b_data = page_address(STbuffer->frp[0].page);
@@ -3663,6 +3683,17 @@ static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dm
}
+/* Make sure that no data from previous user is in the internal buffer */
+static void clear_buffer(struct st_buffer * st_bp)
+{
+ int i;
+
+ for (i=0; i < st_bp->frp_segs; i++)
+ memset(page_address(st_bp->frp[i].page), 0, st_bp->frp[i].length);
+ st_bp->cleared = 1;
+}
+
+
/* Release the extra buffer */
static void normalize_buffer(struct st_buffer * STbuffer)
{
@@ -3987,6 +4018,7 @@ static int st_probe(struct device *dev)
tpnt->two_fm = ST_TWO_FM;
tpnt->fast_mteom = ST_FAST_MTEOM;
tpnt->scsi2_logical = ST_SCSI2LOGICAL;
+ tpnt->sili = ST_SILI;
tpnt->immediate = ST_NOWAIT;
tpnt->default_drvbuffer = 0xff; /* No forced buffering */
tpnt->partition = 0;
@@ -4338,6 +4370,46 @@ st_defcompression_show(struct device *dev, struct device_attribute *attr,
DEVICE_ATTR(default_compression, S_IRUGO, st_defcompression_show, NULL);
+static ssize_t st_options_show(struct class_device *class_dev, char *buf)
+{
+ struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev);
+ struct scsi_tape *STp;
+ int i, j, options;
+ ssize_t l = 0;
+
+ for (i=0; i < st_dev_max; i++) {
+ for (j=0; j < ST_NBR_MODES; j++)
+ if (&scsi_tapes[i]->modes[j] == STm)
+ break;
+ if (j < ST_NBR_MODES)
+ break;
+ }
+ if (i == st_dev_max)
+ return 0; /* should never happen */
+
+ STp = scsi_tapes[i];
+
+ options = STm->do_buffer_writes ? MT_ST_BUFFER_WRITES : 0;
+ options |= STm->do_async_writes ? MT_ST_ASYNC_WRITES : 0;
+ options |= STm->do_read_ahead ? MT_ST_READ_AHEAD : 0;
+ DEB( options |= debugging ? MT_ST_DEBUGGING : 0 );
+ options |= STp->two_fm ? MT_ST_TWO_FM : 0;
+ options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0;
+ options |= STm->defaults_for_writes ? MT_ST_DEF_WRITES : 0;
+ options |= STp->can_bsr ? MT_ST_CAN_BSR : 0;
+ options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0;
+ options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0;
+ options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0;
+ options |= STm->sysv ? MT_ST_SYSV : 0;
+ options |= STp->immediate ? MT_ST_NOWAIT : 0;
+ options |= STp->sili ? MT_ST_SILI : 0;
+
+ l = snprintf(buf, PAGE_SIZE, "0x%08x\n", options);
+ return l;
+}
+
+CLASS_DEVICE_ATTR(options, S_IRUGO, st_options_show, NULL);
+
static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode)
{
int i, rew, error;
@@ -4375,6 +4447,9 @@ static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode)
error = device_create_file(st_class_member,
&dev_attr_default_compression);
if (error) goto out;
+ error = class_device_create_file(st_class_member,
+ &class_device_attr_options);
+ if (error) goto out;
if (mode == 0 && rew == 0) {
error = sysfs_create_link(&STp->device->sdev_gendev.kobj,
diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h
index 5931726fcf93..b92712f95931 100644
--- a/drivers/scsi/st.h
+++ b/drivers/scsi/st.h
@@ -12,6 +12,7 @@ struct st_cmdstatus {
int midlevel_result;
struct scsi_sense_hdr sense_hdr;
int have_sense;
+ int residual;
u64 uremainder64;
u8 flags;
u8 remainder_valid;
@@ -34,6 +35,7 @@ struct st_request {
struct st_buffer {
unsigned char dma; /* DMA-able buffer */
unsigned char do_dio; /* direct i/o set up? */
+ unsigned char cleared; /* internal buffer cleared after open? */
int buffer_size;
int buffer_blocks;
int buffer_bytes;
@@ -122,6 +124,7 @@ struct scsi_tape {
unsigned char try_dio_now; /* try direct i/o before next close? */
unsigned char c_algo; /* compression algorithm */
unsigned char pos_unknown; /* after reset position unknown */
+ unsigned char sili; /* use SILI when reading in variable b mode */
int tape_type;
int long_timeout; /* timeout for commands known to take long time */
diff --git a/drivers/scsi/st_options.h b/drivers/scsi/st_options.h
index b6b5c9c37677..d2f947935554 100644
--- a/drivers/scsi/st_options.h
+++ b/drivers/scsi/st_options.h
@@ -3,7 +3,7 @@
Copyright 1995-2003 Kai Makisara.
- Last modified: Mon Apr 7 22:49:18 2003 by makisara
+ Last modified: Thu Feb 21 21:47:07 2008 by kai.makisara
*/
#ifndef _ST_OPTIONS_H
@@ -94,6 +94,10 @@
The default is BSD semantics. */
#define ST_SYSV 0
+/* If ST_SILI is non-zero, the SILI bit is set when reading in variable block
+ mode and the block size is determined using the residual returned by the HBA. */
+#define ST_SILI 0
+
/* Time to wait for the drive to become ready if blocking open */
#define ST_BLOCK_SECONDS 120
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 654430edf74d..8c7b1830d9e8 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -426,49 +426,13 @@ static int stex_map_sg(struct st_hba *hba,
return 0;
}
-static void stex_internal_copy(struct scsi_cmnd *cmd,
- const void *src, size_t *count, int sg_count, int direction)
-{
- size_t lcount;
- size_t len;
- void *s, *d, *base = NULL;
- size_t offset;
-
- if (*count > scsi_bufflen(cmd))
- *count = scsi_bufflen(cmd);
- lcount = *count;
- while (lcount) {
- len = lcount;
- s = (void *)src;
-
- offset = *count - lcount;
- s += offset;
- base = scsi_kmap_atomic_sg(scsi_sglist(cmd),
- sg_count, &offset, &len);
- if (!base) {
- *count -= lcount;
- return;
- }
- d = base + offset;
-
- if (direction == ST_TO_CMD)
- memcpy(d, s, len);
- else
- memcpy(s, d, len);
-
- lcount -= len;
- scsi_kunmap_atomic_sg(base);
- }
-}
-
static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb)
{
struct st_frame *p;
size_t count = sizeof(struct st_frame);
p = hba->copy_buffer;
- stex_internal_copy(ccb->cmd, p, &count, scsi_sg_count(ccb->cmd),
- ST_FROM_CMD);
+ count = scsi_sg_copy_to_buffer(ccb->cmd, p, count);
memset(p->base, 0, sizeof(u32)*6);
*(unsigned long *)(p->base) = pci_resource_start(hba->pdev, 0);
p->rom_addr = 0;
@@ -486,8 +450,7 @@ static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb)
p->subid =
hba->pdev->subsystem_vendor << 16 | hba->pdev->subsystem_device;
- stex_internal_copy(ccb->cmd, p, &count, scsi_sg_count(ccb->cmd),
- ST_TO_CMD);
+ count = scsi_sg_copy_from_buffer(ccb->cmd, p, count);
}
static void
@@ -554,10 +517,8 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
unsigned char page;
page = cmd->cmnd[2] & 0x3f;
if (page == 0x8 || page == 0x3f) {
- size_t cp_len = sizeof(ms10_caching_page);
- stex_internal_copy(cmd, ms10_caching_page,
- &cp_len, scsi_sg_count(cmd),
- ST_TO_CMD);
+ scsi_sg_copy_from_buffer(cmd, ms10_caching_page,
+ sizeof(ms10_caching_page));
cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
done(cmd);
} else
@@ -586,10 +547,8 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
if (id != host->max_id - 1)
break;
if (lun == 0 && (cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
- size_t cp_len = sizeof(console_inq_page);
- stex_internal_copy(cmd, console_inq_page,
- &cp_len, scsi_sg_count(cmd),
- ST_TO_CMD);
+ scsi_sg_copy_from_buffer(cmd, (void *)console_inq_page,
+ sizeof(console_inq_page));
cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
done(cmd);
} else
@@ -606,8 +565,7 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
ver.signature[0] = PASSTHRU_SIGNATURE;
ver.console_id = host->max_id - 1;
ver.host_no = hba->host->host_no;
- stex_internal_copy(cmd, &ver, &cp_len,
- scsi_sg_count(cmd), ST_TO_CMD);
+ cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
cmd->result = sizeof(ver) == cp_len ?
DID_OK << 16 | COMMAND_COMPLETE << 8 :
DID_ERROR << 16 | COMMAND_COMPLETE << 8;
@@ -700,15 +658,12 @@ static void stex_copy_data(struct st_ccb *ccb,
if (ccb->cmd == NULL)
return;
- stex_internal_copy(ccb->cmd,
- resp->variable, &count, scsi_sg_count(ccb->cmd), ST_TO_CMD);
+ count = scsi_sg_copy_from_buffer(ccb->cmd, resp->variable, count);
}
static void stex_ys_commands(struct st_hba *hba,
struct st_ccb *ccb, struct status_msg *resp)
{
- size_t count;
-
if (ccb->cmd->cmnd[0] == MGT_CMD &&
resp->scsi_status != SAM_STAT_CHECK_CONDITION) {
scsi_set_resid(ccb->cmd, scsi_bufflen(ccb->cmd) -
@@ -724,9 +679,8 @@ static void stex_ys_commands(struct st_hba *hba,
resp->scsi_status == SAM_STAT_GOOD) {
ST_INQ *inq_data;
- count = STEX_EXTRA_SIZE;
- stex_internal_copy(ccb->cmd, hba->copy_buffer,
- &count, scsi_sg_count(ccb->cmd), ST_FROM_CMD);
+ scsi_sg_copy_to_buffer(ccb->cmd, hba->copy_buffer,
+ STEX_EXTRA_SIZE);
inq_data = (ST_INQ *)hba->copy_buffer;
if (inq_data->DeviceTypeQualifier != 0)
ccb->srb_status = SRB_STATUS_SELECTION_TIMEOUT;
diff --git a/include/linux/attribute_container.h b/include/linux/attribute_container.h
index 05af181d4c77..794ad74b1d61 100644
--- a/include/linux/attribute_container.h
+++ b/include/linux/attribute_container.h
@@ -37,7 +37,7 @@ attribute_container_set_no_classdevs(struct attribute_container *atc)
}
int attribute_container_register(struct attribute_container *cont);
-int attribute_container_unregister(struct attribute_container *cont);
+int __must_check attribute_container_unregister(struct attribute_container *cont);
void attribute_container_create_device(struct device *dev,
int (*fn)(struct attribute_container *,
struct device *,
diff --git a/include/linux/mtio.h b/include/linux/mtio.h
index 6f8d2d45a8fb..ef01d6aa5934 100644
--- a/include/linux/mtio.h
+++ b/include/linux/mtio.h
@@ -192,6 +192,7 @@ struct mtpos {
#define MT_ST_SCSI2LOGICAL 0x800
#define MT_ST_SYSV 0x1000
#define MT_ST_NOWAIT 0x2000
+#define MT_ST_SILI 0x4000
/* The mode parameters to be controlled. Parameter chosen with bits 20-28 */
#define MT_ST_CLEAR_DEFAULT 0xfffff
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index a3d567a974e8..71fc81360048 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -213,6 +213,11 @@ int __sg_alloc_table(struct sg_table *, unsigned int, unsigned int, gfp_t,
sg_alloc_fn *);
int sg_alloc_table(struct sg_table *, unsigned int, gfp_t);
+size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents,
+ void *buf, size_t buflen);
+size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
+ void *buf, size_t buflen);
+
/*
* Maximum number of entries that will be allocated in one piece, if
* a list larger than this is required then chaining will be utilized.
diff --git a/include/linux/transport_class.h b/include/linux/transport_class.h
index 9d049d1602c5..890d1073f72e 100644
--- a/include/linux/transport_class.h
+++ b/include/linux/transport_class.h
@@ -86,9 +86,9 @@ static inline int transport_container_register(struct transport_container *tc)
return attribute_container_register(&tc->ac);
}
-static inline int transport_container_unregister(struct transport_container *tc)
+static inline void transport_container_unregister(struct transport_container *tc)
{
- return attribute_container_unregister(&tc->ac);
+ BUG_ON(attribute_container_unregister(&tc->ac));
}
int transport_class_register(struct transport_class *);
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index 39e1cac24bb7..98724ba65a79 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -677,4 +677,6 @@ extern void sas_ssp_task_response(struct device *dev, struct sas_task *task,
struct ssp_response_iu *iu);
struct sas_phy *sas_find_local_phy(struct domain_device *dev);
+int sas_request_addr(struct Scsi_Host *shost, u8 *addr);
+
#endif /* _SASLIB_H_ */
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index de28aab820b0..8d20e60a94b7 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -130,6 +130,9 @@ extern void scsi_release_buffers(struct scsi_cmnd *cmd);
extern int scsi_dma_map(struct scsi_cmnd *cmd);
extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
+struct scsi_cmnd *scsi_allocate_command(gfp_t gfp_mask);
+void scsi_free_command(gfp_t gfp_mask, struct scsi_cmnd *cmd);
+
static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd)
{
return cmd->sdb.table.nents;
@@ -175,4 +178,18 @@ static inline struct scsi_data_buffer *scsi_out(struct scsi_cmnd *cmd)
return &cmd->sdb;
}
+static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd,
+ void *buf, int buflen)
+{
+ return sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
+ buf, buflen);
+}
+
+static inline int scsi_sg_copy_to_buffer(struct scsi_cmnd *cmd,
+ void *buf, int buflen)
+{
+ return sg_copy_to_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
+ buf, buflen);
+}
+
#endif /* _SCSI_SCSI_CMND_H */
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index 25071d5d9bf8..37a7614f62f4 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -64,6 +64,7 @@ extern int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len,
#define SCSI_TRY_RESET_DEVICE 1
#define SCSI_TRY_RESET_BUS 2
#define SCSI_TRY_RESET_HOST 3
+#define SCSI_TRY_RESET_TARGET 4
extern int scsi_reset_provider(struct scsi_device *, int);
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 99a1383e8768..d967d6dc7a28 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -172,6 +172,7 @@ struct scsi_host_template {
*/
int (* eh_abort_handler)(struct scsi_cmnd *);
int (* eh_device_reset_handler)(struct scsi_cmnd *);
+ int (* eh_target_reset_handler)(struct scsi_cmnd *);
int (* eh_bus_reset_handler)(struct scsi_cmnd *);
int (* eh_host_reset_handler)(struct scsi_cmnd *);
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index acca4901046c..b80c21100d78 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -8,6 +8,7 @@
*/
#include <linux/module.h>
#include <linux/scatterlist.h>
+#include <linux/highmem.h>
/**
* sg_next - return the next scatterlist entry in a list
@@ -292,3 +293,104 @@ int sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask)
return ret;
}
EXPORT_SYMBOL(sg_alloc_table);
+
+/**
+ * sg_copy_buffer - Copy data between a linear buffer and an SG list
+ * @sgl: The SG list
+ * @nents: Number of SG entries
+ * @buf: Where to copy from
+ * @buflen: The number of bytes to copy
+ * @to_buffer: transfer direction (non zero == from an sg list to a
+ * buffer, 0 == from a buffer to an sg list
+ *
+ * Returns the number of copied bytes.
+ *
+ **/
+static size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents,
+ void *buf, size_t buflen, int to_buffer)
+{
+ struct scatterlist *sg;
+ size_t buf_off = 0;
+ int i;
+
+ WARN_ON(!irqs_disabled());
+
+ for_each_sg(sgl, sg, nents, i) {
+ struct page *page;
+ int n = 0;
+ unsigned int sg_off = sg->offset;
+ unsigned int sg_copy = sg->length;
+
+ if (sg_copy > buflen)
+ sg_copy = buflen;
+ buflen -= sg_copy;
+
+ while (sg_copy > 0) {
+ unsigned int page_copy;
+ void *p;
+
+ page_copy = PAGE_SIZE - sg_off;
+ if (page_copy > sg_copy)
+ page_copy = sg_copy;
+
+ page = nth_page(sg_page(sg), n);
+ p = kmap_atomic(page, KM_BIO_SRC_IRQ);
+
+ if (to_buffer)
+ memcpy(buf + buf_off, p + sg_off, page_copy);
+ else {
+ memcpy(p + sg_off, buf + buf_off, page_copy);
+ flush_kernel_dcache_page(page);
+ }
+
+ kunmap_atomic(p, KM_BIO_SRC_IRQ);
+
+ buf_off += page_copy;
+ sg_off += page_copy;
+ if (sg_off == PAGE_SIZE) {
+ sg_off = 0;
+ n++;
+ }
+ sg_copy -= page_copy;
+ }
+
+ if (!buflen)
+ break;
+ }
+
+ return buf_off;
+}
+
+/**
+ * sg_copy_from_buffer - Copy from a linear buffer to an SG list
+ * @sgl: The SG list
+ * @nents: Number of SG entries
+ * @buf: Where to copy from
+ * @buflen: The number of bytes to copy
+ *
+ * Returns the number of copied bytes.
+ *
+ **/
+size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents,
+ void *buf, size_t buflen)
+{
+ return sg_copy_buffer(sgl, nents, buf, buflen, 0);
+}
+EXPORT_SYMBOL(sg_copy_from_buffer);
+
+/**
+ * sg_copy_to_buffer - Copy from an SG list to a linear buffer
+ * @sgl: The SG list
+ * @nents: Number of SG entries
+ * @buf: Where to copy to
+ * @buflen: The number of bytes to copy
+ *
+ * Returns the number of copied bytes.
+ *
+ **/
+size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
+ void *buf, size_t buflen)
+{
+ return sg_copy_buffer(sgl, nents, buf, buflen, 1);
+}
+EXPORT_SYMBOL(sg_copy_to_buffer);