Skip to content

Commit

Permalink
[SCSI] - fusion - mptfc bug fix's to prevent deadlock situations
Browse files Browse the repository at this point in the history
mptbase.h

	bump version number to 3.03.09

	remove unneeded flags
	define workq and remove old fc specific locks

mptbase.c

	initialize new lock and don't initialize two removed locks

mptscsih.c

	when firmware reports target is no longer there, return
        DID_REQUEUE for fc hosts so that i/o doesn't get killed until
        the transport has an opportunity to manage the loss via its
        dev loss timer

	when the "eh_abort" routine is called, check to see if the
        driver has the command or not before looking to see if a reset
        is pending.  James Smart and I talked about this and believe
        that the API for this routine is: if driver doesn't have
        command, return SUCCESS.  This change helps prevent a target
        from being taken offline.  SUCCESS is returned because it's
        likely that the command completed after error recovery timed
        it out but before it could be aborted.

	provide a routine to queue work to newly created workq, and
        use it.

	remove "ioc" from mptscsih_abort() it was only used one time.
	the other references were via hd->ioc, so I just moved it....
	net change in references to ioc via hd->ioc is zero

	move hd->resetPending test and hd->timeouts increment to after
	the test for whether the command to be aborted remains known
	to the driver

	Make certain that the workq exists before queuing work to it.

mptfc.c

	no longer need to lock rport data structures as I was able to
	single thread the code!  I fixed up the debug code to
	eliminate compilation messages due to type mismatch in the
	printk.  Got rid of some no longer needed rport flags.
	Initialize and destroy the workq used for the rescan work.

	simplify the logic regarding the increment of
        fc_rescan_work_count.  use post increment and test for zero
        vs. pre increment and test for one; eliminate work_count
        variable: queue_work can be called with the work_lock held as
        it doesn't sleep

Signed-off-by: Michael Reed <mdr@sgi.com>
Signed-off-by: Eric Moore <Eric.Moore@lsil.com>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
  • Loading branch information
Moore, Eric authored and James Bottomley committed Apr 25, 2006
1 parent bd23e94 commit 65207fe
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 77 deletions.
1 change: 0 additions & 1 deletion drivers/message/fusion/mptbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,6 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
ioc->diagPending = 0;
spin_lock_init(&ioc->diagLock);
spin_lock_init(&ioc->fc_rescan_work_lock);
spin_lock_init(&ioc->fc_rport_lock);
spin_lock_init(&ioc->initializing_hba_lock);

/* Initialize the event logging.
Expand Down
10 changes: 4 additions & 6 deletions drivers/message/fusion/mptbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
#define COPYRIGHT "Copyright (c) 1999-2005 " MODULEAUTHOR
#endif

#define MPT_LINUX_VERSION_COMMON "3.03.08"
#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.03.08"
#define MPT_LINUX_VERSION_COMMON "3.03.09"
#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.03.09"
#define WHAT_MAGIC_STRING "@" "(" "#" ")"

#define show_mptmod_ver(s,ver) \
Expand Down Expand Up @@ -489,7 +489,6 @@ typedef struct _RaidCfgData {

#define MPT_RPORT_INFO_FLAGS_REGISTERED 0x01 /* rport registered */
#define MPT_RPORT_INFO_FLAGS_MISSING 0x02 /* missing from DevPage0 scan */
#define MPT_RPORT_INFO_FLAGS_MAPPED_VDEV 0x04 /* target mapped in vdev */

/*
* data allocated for each fc rport device
Expand All @@ -501,7 +500,6 @@ struct mptfc_rport_info
struct scsi_target *starget;
FCDevicePage0_t pg0;
u8 flags;
u8 remap_needed;
};

/*
Expand Down Expand Up @@ -628,11 +626,11 @@ typedef struct _MPT_ADAPTER
struct work_struct mptscsih_persistTask;

struct list_head fc_rports;
spinlock_t fc_rport_lock; /* list and ri flags */
spinlock_t fc_rescan_work_lock;
int fc_rescan_work_count;
struct work_struct fc_rescan_work;

char fc_rescan_work_q_name[KOBJ_NAME_LEN];
struct workqueue_struct *fc_rescan_work_q;
} MPT_ADAPTER;

/*
Expand Down
125 changes: 77 additions & 48 deletions drivers/message/fusion/mptfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,13 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
struct fc_rport *rport;
struct mptfc_rport_info *ri;
int new_ri = 1;
u64 pn;
unsigned long flags;
u64 pn, nn;
VirtTarget *vtarget;

if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
return;

/* scan list looking for a match */
spin_lock_irqsave(&ioc->fc_rport_lock, flags);
list_for_each_entry(ri, &ioc->fc_rports, list) {
pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
if (pn == rport_ids.port_name) { /* match */
Expand All @@ -373,11 +371,9 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
}
}
if (new_ri) { /* allocate one */
spin_unlock_irqrestore(&ioc->fc_rport_lock, flags);
ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
if (!ri)
return;
spin_lock_irqsave(&ioc->fc_rport_lock, flags);
list_add_tail(&ri->list, &ioc->fc_rports);
}

Expand All @@ -387,14 +383,11 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
/* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
spin_unlock_irqrestore(&ioc->fc_rport_lock, flags);
rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
spin_lock_irqsave(&ioc->fc_rport_lock, flags);
if (rport) {
ri->rport = rport;
if (new_ri) /* may have been reset by user */
rport->dev_loss_tmo = mptfc_dev_loss_tmo;
*((struct mptfc_rport_info **)rport->dd_data) = ri;
/*
* if already mapped, remap here. If not mapped,
* target_alloc will allocate vtarget and map,
Expand All @@ -406,16 +399,20 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
vtarget->target_id = pg0->CurrentTargetID;
vtarget->bus_id = pg0->CurrentBus;
}
ri->remap_needed = 0;
}
/* once dd_data is filled in, commands will issue to hardware */
*((struct mptfc_rport_info **)rport->dd_data) = ri;

pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
dfcprintk ((MYIOC_s_INFO_FMT
"mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
"rport tid %d, tmo %d\n",
ioc->name,
ioc->sh->host_no,
pg0->PortIdentifier,
pg0->WWNN,
pg0->WWPN,
(unsigned long long)nn,
(unsigned long long)pn,
pg0->CurrentTargetID,
ri->rport->scsi_target_id,
ri->rport->dev_loss_tmo));
Expand All @@ -425,8 +422,6 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
ri = NULL;
}
}
spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);

}

/*
Expand Down Expand Up @@ -476,7 +471,6 @@ mptfc_target_alloc(struct scsi_target *starget)
vtarget->target_id = ri->pg0.CurrentTargetID;
vtarget->bus_id = ri->pg0.CurrentBus;
ri->starget = starget;
ri->remap_needed = 0;
rc = 0;
}
}
Expand All @@ -502,10 +496,10 @@ mptfc_slave_alloc(struct scsi_device *sdev)
VirtDevice *vdev;
struct scsi_target *starget;
struct fc_rport *rport;
unsigned long flags;


rport = starget_to_rport(scsi_target(sdev));
starget = scsi_target(sdev);
rport = starget_to_rport(starget);

if (!rport || fc_remote_port_chkready(rport))
return -ENXIO;
Expand All @@ -519,10 +513,8 @@ mptfc_slave_alloc(struct scsi_device *sdev)
return -ENOMEM;
}

spin_lock_irqsave(&hd->ioc->fc_rport_lock,flags);

sdev->hostdata = vdev;
starget = scsi_target(sdev);
vtarget = starget->hostdata;

if (vtarget->num_luns == 0) {
Expand All @@ -535,22 +527,26 @@ mptfc_slave_alloc(struct scsi_device *sdev)
vdev->vtarget = vtarget;
vdev->lun = sdev->lun;

spin_unlock_irqrestore(&hd->ioc->fc_rport_lock,flags);

vtarget->num_luns++;


#ifdef DMPT_DEBUG_FC
{
{
u64 nn, pn;
struct mptfc_rport_info *ri;
ri = *((struct mptfc_rport_info **)rport->dd_data);
pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
dfcprintk ((MYIOC_s_INFO_FMT
"mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
"CurrentTargetID %d, %x %llx %llx\n",
hd->ioc->name,
sdev->host->host_no,
vtarget->num_luns,
sdev->id, ri->pg0.CurrentTargetID,
ri->pg0.PortIdentifier, ri->pg0.WWPN, ri->pg0.WWNN));
ri->pg0.PortIdentifier,
(unsigned long long)pn,
(unsigned long long)nn));
}
#endif

Expand All @@ -570,11 +566,31 @@ mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
done(SCpnt);
return 0;
}

/* dd_data is null until finished adding target */
ri = *((struct mptfc_rport_info **)rport->dd_data);
if (unlikely(ri->remap_needed))
return SCSI_MLQUEUE_HOST_BUSY;
if (unlikely(!ri)) {
dfcprintk ((MYIOC_s_INFO_FMT
"mptfc_qcmd.%d: %d:%d, dd_data is null.\n",
((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
SCpnt->device->id,SCpnt->device->lun));
SCpnt->result = DID_IMM_RETRY << 16;
done(SCpnt);
return 0;
}

return mptscsih_qcmd(SCpnt,done);
err = mptscsih_qcmd(SCpnt,done);
#ifdef DMPT_DEBUG_FC
if (unlikely(err)) {
dfcprintk ((MYIOC_s_INFO_FMT
"mptfc_qcmd.%d: %d:%d, mptscsih_qcmd returns non-zero.\n",
((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
SCpnt->device->id,SCpnt->device->lun));
}
#endif
return err;
}

static void
Expand Down Expand Up @@ -615,18 +631,17 @@ mptfc_rescan_devices(void *arg)
MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
int ii;
int work_to_do;
u64 pn;
unsigned long flags;
struct mptfc_rport_info *ri;

do {
/* start by tagging all ports as missing */
spin_lock_irqsave(&ioc->fc_rport_lock,flags);
list_for_each_entry(ri, &ioc->fc_rports, list) {
if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
}
}
spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);

/*
* now rescan devices known to adapter,
Expand All @@ -639,33 +654,24 @@ mptfc_rescan_devices(void *arg)
}

/* delete devices still missing */
spin_lock_irqsave(&ioc->fc_rport_lock, flags);
list_for_each_entry(ri, &ioc->fc_rports, list) {
/* if newly missing, delete it */
if ((ri->flags & (MPT_RPORT_INFO_FLAGS_REGISTERED |
MPT_RPORT_INFO_FLAGS_MISSING))
== (MPT_RPORT_INFO_FLAGS_REGISTERED |
MPT_RPORT_INFO_FLAGS_MISSING)) {
if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {

ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
MPT_RPORT_INFO_FLAGS_MISSING);
ri->remap_needed = 1;
fc_remote_port_delete(ri->rport);
/*
* remote port not really deleted 'cause
* binding is by WWPN and driver only
* registers FCP_TARGETs but cannot trust
* data structures.
*/
fc_remote_port_delete(ri->rport); /* won't sleep */
ri->rport = NULL;

pn = (u64)ri->pg0.WWPN.High << 32 |
(u64)ri->pg0.WWPN.Low;
dfcprintk ((MYIOC_s_INFO_FMT
"mptfc_rescan.%d: %llx deleted\n",
ioc->name,
ioc->sh->host_no,
ri->pg0.WWPN));
(unsigned long long)pn));
}
}
spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);

/*
* allow multiple passes as target state
Expand Down Expand Up @@ -870,10 +876,23 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto out_mptfc_probe;
}

for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
mptfc_init_host_attr(ioc,ii);
mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
}
/* initialize workqueue */

snprintf(ioc->fc_rescan_work_q_name, KOBJ_NAME_LEN, "mptfc_wq_%d",
sh->host_no);
ioc->fc_rescan_work_q =
create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
if (!ioc->fc_rescan_work_q)
goto out_mptfc_probe;

/*
* scan for rports -
* by doing it via the workqueue, some locking is eliminated
*/

ioc->fc_rescan_work_count = 1;
queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
flush_workqueue(ioc->fc_rescan_work_q);

return 0;

Expand Down Expand Up @@ -949,8 +968,18 @@ mptfc_init(void)
static void __devexit
mptfc_remove(struct pci_dev *pdev)
{
MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
struct mptfc_rport_info *p, *n;
MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
struct mptfc_rport_info *p, *n;
struct workqueue_struct *work_q;
unsigned long flags;

/* destroy workqueue */
if ((work_q=ioc->fc_rescan_work_q)) {
spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
ioc->fc_rescan_work_q = NULL;
spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
destroy_workqueue(work_q);
}

fc_remove_host(ioc->sh);

Expand Down
Loading

0 comments on commit 65207fe

Please sign in to comment.