Commit bc95de84 authored by James Bottomley's avatar James Bottomley

mptfusion: streamline slave_alloc

From: 	Moore, Eric Dean <Eric.Moore@lsil.com>

This cleans up slave_xxx functions. 
This patch previously submitted by hch@.
Signed-off-by: default avatarEric Moore <Eric.Moore@lsil.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent 207d3f95
...@@ -1341,11 +1341,11 @@ mptscsih_remove(struct pci_dev *pdev) ...@@ -1341,11 +1341,11 @@ mptscsih_remove(struct pci_dev *pdev)
hd = (MPT_SCSI_HOST *)host->hostdata; hd = (MPT_SCSI_HOST *)host->hostdata;
if (hd != NULL) { if (hd != NULL) {
int sz1, sz3, sztarget=0; int sz1;
mptscsih_shutdown(&pdev->dev); mptscsih_shutdown(&pdev->dev);
sz1 = sz3 = 0; sz1=0;
if (hd->ScsiLookup != NULL) { if (hd->ScsiLookup != NULL) {
sz1 = hd->ioc->req_depth * sizeof(void *); sz1 = hd->ioc->req_depth * sizeof(void *);
...@@ -1354,36 +1354,16 @@ mptscsih_remove(struct pci_dev *pdev) ...@@ -1354,36 +1354,16 @@ mptscsih_remove(struct pci_dev *pdev)
} }
if (hd->Targets != NULL) { if (hd->Targets != NULL) {
int max, ii;
/*
* Free any target structures that were allocated.
*/
if (hd->is_spi) {
max = MPT_MAX_SCSI_DEVICES;
} else {
max = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
}
for (ii=0; ii < max; ii++) {
if (hd->Targets[ii]) {
kfree(hd->Targets[ii]);
hd->Targets[ii] = NULL;
sztarget += sizeof(VirtDevice);
}
}
/* /*
* Free pointer array. * Free pointer array.
*/ */
sz3 = max * sizeof(void *);
kfree(hd->Targets); kfree(hd->Targets);
hd->Targets = NULL; hd->Targets = NULL;
} }
dprintk((MYIOC_s_INFO_FMT dprintk((MYIOC_s_INFO_FMT
"Free'd ScsiLookup (%d) Target (%d+%d) memory\n", "Free'd ScsiLookup (%d) memory\n",
hd->ioc->name, sz1, sz3, sztarget)); hd->ioc->name, sz1));
dprintk(("Free'd done and free Q (%d) memory\n", szQ));
/* NULL the Scsi_Host pointer /* NULL the Scsi_Host pointer
*/ */
...@@ -2595,39 +2575,56 @@ static int ...@@ -2595,39 +2575,56 @@ static int
mptscsih_slave_alloc(struct scsi_device *device) mptscsih_slave_alloc(struct scsi_device *device)
{ {
struct Scsi_Host *host = device->host; struct Scsi_Host *host = device->host;
MPT_SCSI_HOST *hd; MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
VirtDevice *vdev; VirtDevice *vdev;
uint target = device->id;
hd = (MPT_SCSI_HOST *)host->hostdata;
if (hd == NULL) if (hd == NULL)
return -ENODEV; return -ENODEV;
if ((vdev = hd->Targets[device->id]) == NULL) { if ((vdev = hd->Targets[target]) != NULL)
if ((vdev = kmalloc(sizeof(VirtDevice), GFP_ATOMIC)) == NULL) { goto out;
printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%d) FAILED!\n",
hd->ioc->name, (int)sizeof(VirtDevice)); vdev = kmalloc(sizeof(VirtDevice), GFP_KERNEL);
return -ENOMEM; if (!vdev) {
} else { printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
memset(vdev, 0, sizeof(VirtDevice)); hd->ioc->name, sizeof(VirtDevice));
vdev->tflags = MPT_TARGET_FLAGS_Q_YES; return -ENOMEM;
vdev->ioc_id = hd->ioc->id; }
vdev->target_id = device->id;
vdev->bus_id = device->channel; memset(vdev, 0, sizeof(VirtDevice));
vdev->raidVolume = 0; vdev->tflags = MPT_TARGET_FLAGS_Q_YES;
hd->Targets[device->id] = vdev; vdev->ioc_id = hd->ioc->id;
if (hd->is_spi) { vdev->target_id = device->id;
if (hd->ioc->spi_data.isRaid & (1 << device->id)) { vdev->bus_id = device->channel;
vdev->raidVolume = 1; vdev->raidVolume = 0;
ddvtprintk((KERN_INFO hd->Targets[device->id] = vdev;
"RAID Volume @ id %d\n", device->id)); if (hd->is_spi) {
} if (hd->ioc->spi_data.isRaid & (1 << device->id)) {
} else { vdev->raidVolume = 1;
vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY; ddvtprintk((KERN_INFO
} "RAID Volume @ id %d\n", device->id));
} }
} else {
vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
} }
out:
vdev->num_luns++; vdev->num_luns++;
return 0;
}
static int mptscsih_is_raid_volume(MPT_SCSI_HOST *hd, uint id)
{
int i;
if (!hd->ioc->spi_data.isRaid || !hd->ioc->spi_data.pIocPg3)
return 0;
for (i = 0; i < hd->ioc->spi_data.pIocPg3->NumPhysDisks; i++) {
if (id == hd->ioc->spi_data.pIocPg3->PhysDisk[i].PhysDiskID)
return 1;
}
return 0; return 0;
} }
...@@ -2640,59 +2637,37 @@ static void ...@@ -2640,59 +2637,37 @@ static void
mptscsih_slave_destroy(struct scsi_device *device) mptscsih_slave_destroy(struct scsi_device *device)
{ {
struct Scsi_Host *host = device->host; struct Scsi_Host *host = device->host;
MPT_SCSI_HOST *hd; MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
VirtDevice *vdev; VirtDevice *vdev;
int raid_volume=0; uint target = device->id;
uint lun = device->lun;
hd = (MPT_SCSI_HOST *)host->hostdata;
if (hd == NULL) if (hd == NULL)
return; return;
mptscsih_search_running_cmds(hd, device->id, device->lun); mptscsih_search_running_cmds(hd, target, lun);
/* Free memory and reset all flags for this target
*/
if ((vdev = hd->Targets[device->id]) != NULL) {
vdev->num_luns--;
if (vdev->luns[0] & (1 << device->lun))
vdev->luns[0] &= ~(1 << device->lun);
/* Free device structure only if number of luns is 0.
*/
if (vdev->num_luns == 0) {
kfree(hd->Targets[device->id]);
hd->Targets[device->id] = NULL;
if (!hd->is_spi)
return;
if((hd->ioc->spi_data.isRaid) && (hd->ioc->spi_data.pIocPg3)) {
int i;
for(i=0;i<hd->ioc->spi_data.pIocPg3->NumPhysDisks &&
raid_volume==0;i++)
if(device->id == vdev = hd->Targets[target];
hd->ioc->spi_data.pIocPg3->PhysDisk[i].PhysDiskID) { vdev->luns[0] &= ~(1 << lun);
raid_volume=1; if (--vdev->num_luns)
hd->ioc->spi_data.forceDv |= return;
MPT_SCSICFG_RELOAD_IOC_PG3;
}
}
if(!raid_volume){ kfree(hd->Targets[target]);
hd->ioc->spi_data.dvStatus[device->id] = hd->Targets[target] = NULL;
if (hd->is_spi) {
if (mptscsih_is_raid_volume(hd, target)) {
hd->ioc->spi_data.forceDv |= MPT_SCSICFG_RELOAD_IOC_PG3;
} else {
hd->ioc->spi_data.dvStatus[target] =
MPT_SCSICFG_NEGOTIATE; MPT_SCSICFG_NEGOTIATE;
if (hd->negoNvram == 0) if (!hd->negoNvram) {
hd->ioc->spi_data.dvStatus[device->id] hd->ioc->spi_data.dvStatus[target] |=
|= MPT_SCSICFG_DV_NOT_DONE; MPT_SCSICFG_DV_NOT_DONE;
} }
} }
} }
return;
} }
static void static void
...@@ -2702,7 +2677,7 @@ mptscsih_set_queue_depth(struct scsi_device *device, MPT_SCSI_HOST *hd, ...@@ -2702,7 +2677,7 @@ mptscsih_set_queue_depth(struct scsi_device *device, MPT_SCSI_HOST *hd,
int max_depth; int max_depth;
int tagged; int tagged;
if ( hd->is_spi ) { if (hd->is_spi) {
if (pTarget->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY) { if (pTarget->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY) {
if (!(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)) if (!(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES))
max_depth = 1; max_depth = 1;
...@@ -2817,7 +2792,6 @@ mptscsih_store_queue_depth(struct device *dev, const char *buf, size_t count) ...@@ -2817,7 +2792,6 @@ mptscsih_store_queue_depth(struct device *dev, const char *buf, size_t count)
return count; return count;
} }
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/* /*
* Private routines... * Private routines...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment