Commit 12ff5fc4 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Christoph Hellwig

[PATCH] tmscsim: convert to slave_...

On Wed, 26 May 2004, Christoph Hellwig wrote:
> Looks like a way to go.  I'm not sure what scan_device is supposed to
> do as I already wrote, but from looking at when it's set/cleared I'm
> pretty sure it tries to indicate whethere we're currently scanning for
> devices.  And useing slave_alloc/slave_configure is a much safer way to
> find that out then guessing from the commands sent.

Attached is a patch, that moves scan_device to
slave_alloc/_configure/_destroy, as you suggested (to be precise, as I
understood your suggestion:-))
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent 9ff83977
......@@ -14,12 +14,9 @@
#define DC390_H
#include <linux/version.h>
#ifndef KERNEL_VERSION
# define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif
#define DC390_BANNER "Tekram DC390/AM53C974"
#define DC390_VERSION "2.1c 2004-05-23"
#define DC390_VERSION "2.1d 2004-05-27"
/* We don't have eh_abort_handler, eh_device_reset_handler,
* eh_bus_reset_handler, eh_host_reset_handler yet!
......@@ -32,13 +29,4 @@
# define NEW_EH use_new_eh_code: 1,
# define USE_NEW_EH
#endif
static int DC390_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *));
static int DC390_abort(Scsi_Cmnd *cmd);
static int DC390_reset(Scsi_Cmnd *cmd);
static int DC390_bios_param(struct scsi_device *sdev, struct block_device *dev,
sector_t capacity, int geom[]);
static int DC390_release(struct Scsi_Host *);
#endif /* DC390_H */
......@@ -12,7 +12,7 @@ dc390_freetag (PDCB pDCB, PSRB pSRB)
pDCB->TagMask &= ~(1 << pSRB->TagNumber); /* free tag mask */
pSRB->TagNumber = 255;
}
};
}
static UCHAR
......@@ -75,7 +75,7 @@ dc390_StartSCSI( PACB pACB, PDCB pDCB, PSRB pSRB )
printk (KERN_WARNING "DC390: Out of tags for Dev. %02x %02x\n", pDCB->TargetID, pDCB->TargetLUN);
return 1;
//goto no_tag;
};
}
DC390_write8 (ScsiFifo, SIMPLE_QUEUE_TAG);
pDCB->TagMask |= (1 << tag_no); pSRB->TagNumber = tag_no;
DC390_write8 (ScsiFifo, tag_no);
......@@ -86,7 +86,7 @@ dc390_StartSCSI( PACB pACB, PDCB pDCB, PSRB pSRB )
{
// no_tag:
DEBUG1(printk (KERN_DEBUG "DC390: Select w%s/DisCn for Cmd %li (SRB %p), No TagQ\n", (disc_allowed?"":"o"), pSRB->pcmd->pid, pSRB));
};
}
pSRB->SRBState = SRB_START_;
......@@ -104,7 +104,7 @@ dc390_StartSCSI( PACB pACB, PDCB pDCB, PSRB pSRB )
//pSRB->SRBState = SRB_MSGOUT_;
pSRB->SRBState |= DO_SYNC_NEGO;
cmd = SEL_W_ATN_STOP;
};
}
/* Command is written in CommandPhase, if SEL_W_ATN_STOP ... */
if (cmd != SEL_W_ATN_STOP)
......@@ -125,7 +125,7 @@ dc390_StartSCSI( PACB pACB, PDCB pDCB, PSRB pSRB )
ptr = (PUCHAR) pSRB->pcmd->cmnd;
for (i=0; i<pSRB->pcmd->cmd_len; i++)
DC390_write8 (ScsiFifo, *(ptr++));
};
}
}
DEBUG0(if (pACB->pActiveDCB) \
printk (KERN_WARNING "DC390: ActiveDCB != 0\n"));
......@@ -141,7 +141,7 @@ dc390_StartSCSI( PACB pACB, PDCB pDCB, PSRB pSRB )
//DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
pACB->SelLost++;
return 1;
};
}
DC390_write8 (ScsiCmd, cmd);
pACB->pActiveDCB = pDCB; pDCB->pActiveSRB = pSRB;
pACB->Connected = 1;
......@@ -176,7 +176,7 @@ dc390_dma_intr (PACB pACB)
{
printk (KERN_ERR "DC390: DMA error (%02x)!\n", dstate);
return dstate;
};
}
if (dstate & DMA_XFER_DONE)
{
UINT residual, xferCnt; int ctr = 6000000;
......@@ -253,7 +253,7 @@ DC390_Interrupt( int irq, void *dev_id, struct pt_regs *regs)
{
DEBUG0(printk (KERN_WARNING "DC390 Int w/o SCSI actions (only DMA?)\n"));
return IRQ_NONE;
};
}
#else
//DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT);
//dstatus = DC390_read8 (DMA_Status);
......@@ -313,7 +313,7 @@ DC390_Interrupt( int irq, void *dev_id, struct pt_regs *regs)
{
printk (KERN_ERR "DC390: Suc. op/ Serv. req: pActiveDCB = 0!\n");
goto unlock;
};
}
pSRB = pDCB->pActiveSRB;
if( pDCB->DCBFlag & ABORT_DEV_ )
dc390_EnableMsgOut_Abort (pACB, pSRB);
......@@ -549,7 +549,7 @@ dc390_reprog (PACB pACB, PDCB pDCB)
DC390_write8 (CtrlReg3, pDCB->CtrlR3);
DC390_write8 (CtrlReg4, pDCB->CtrlR4);
dc390_SetXferRate (pACB, pDCB);
};
}
#ifdef DC390_DEBUG0
......@@ -561,7 +561,7 @@ dc390_printMsg (UCHAR *MsgBuf, UCHAR len)
for (i = 1; i < len; i++)
printk (" %02x", MsgBuf[i]);
printk ("\n");
};
}
#endif
#define DC390_ENABLE_MSGOUT DC390_write8 (ScsiCmd, SET_ATN_CMD)
......@@ -671,11 +671,11 @@ dc390_MsgIn_set_sync (PACB pACB, PSRB pSRB)
{
printk (KERN_INFO "DC390: Set sync nego period to %ins\n", pDCB->NegoPeriod << 2);
pSRB->MsgInBuf[3] = pDCB->NegoPeriod;
};
}
memcpy (pSRB->MsgOutBuf, pSRB->MsgInBuf, 5);
pSRB->MsgCnt = 5;
DC390_ENABLE_MSGOUT;
};
}
pSRB->SRBState &= ~DO_SYNC_NEGO;
pDCB->SyncMode |= SYNC_ENABLE+SYNC_NEGO_DONE;
......@@ -713,7 +713,7 @@ dc390_MsgIn_set_sync (PACB pACB, PSRB pSRB)
}
dc390_reprog (pACB, pDCB);
};
}
/* handle RESTORE_PTR */
......@@ -761,7 +761,7 @@ dc390_restore_ptr (PACB pACB, PSRB pSRB)
}
pSRB->TotalXferredLen = pSRB->Saved_Ptr;
};
}
/* According to the docs, the AM53C974 reads the message and
......@@ -832,7 +832,7 @@ dc390_MsgIn_0( PACB pACB, PSRB pSRB, PUCHAR psstatus)
dc390_MsgIn_set_async (pACB, pSRB);
else
dc390_MsgIn_set_sync (pACB, pSRB);
};
}
// nothing has to be done
case COMMAND_COMPLETE: break;
......@@ -1276,7 +1276,7 @@ dc390_remove_dev (PACB pACB, PDCB pDCB)
DCBDEBUG(printk (KERN_INFO "DC390: Driver won't free DCB (ID %i, LUN %i): 0x%08x because of SRBCnt %i\n",\
pDCB->TargetID, pDCB->TargetLUN, (int)pDCB, pDCB->GoingSRBCnt));
return;
};
}
pACB->DCBmap[pDCB->TargetID] &= ~(1 << pDCB->TargetLUN);
// The first one
......@@ -1302,7 +1302,7 @@ dc390_remove_dev (PACB pACB, PDCB pDCB)
if (pDCB == pACB->pDCBRunRobin) pACB->pDCBRunRobin = pDCB->pNextDCB;
kfree (pDCB);
pACB->DCBCnt--;
};
}
static UCHAR __inline__
......@@ -1313,7 +1313,7 @@ dc390_tagq_blacklist (char* name)
if (memcmp (name, dc390_baddevname1[i], 28) == 0)
return 1;
return 0;
};
}
static void
......@@ -1335,7 +1335,7 @@ dc390_disc_tagq_set (PDCB pDCB, PSCSI_INQDATA ptr)
else
pDCB->MaxCommand = 1;
}
};
}
static void
......@@ -1345,7 +1345,7 @@ dc390_add_dev (PACB pACB, PDCB pDCB, PSCSI_INQDATA ptr)
pDCB->DevType = bval1;
/* if (bval1 == TYPE_DISK || bval1 == TYPE_MOD) */
dc390_disc_tagq_set (pDCB, ptr);
};
}
static void
......@@ -1562,23 +1562,6 @@ dc390_SRBdone( PACB pACB, PDCB pDCB, PSRB pSRB )
pcmd->sense_buffer[2], pcmd->sense_buffer[3]);
else printk ("\n");
#endif
if( (host_byte(pcmd->result) != DID_OK && !(status_byte(pcmd->result) & CHECK_CONDITION) && !(status_byte(pcmd->result) & BUSY)) ||
((driver_byte(pcmd->result) & DRIVER_SENSE) && (pcmd->sense_buffer[0] & 0x70) == 0x70 &&
(pcmd->sense_buffer[2] & 0xf) == ILLEGAL_REQUEST) || host_byte(pcmd->result) & DID_ERROR )
{
/* device not present: remove */
if( (pcmd->device->id == pACB->pScsiHost->max_id - 1) &&
((pcmd->device->lun == 0) || (pcmd->device->lun == pACB->pScsiHost->max_lun - 1)) )
pACB->scan_devices = 0;
}
else
{
/* device present: add */
if( (pcmd->device->id == pACB->pScsiHost->max_id - 1) &&
(pcmd->device->lun == pACB->pScsiHost->max_lun - 1) )
pACB->scan_devices = END_SCAN ;
}
}
}
......@@ -1590,9 +1573,6 @@ dc390_SRBdone( PACB pACB, PDCB pDCB, PSRB pSRB )
/* device found: add */
dc390_add_dev (pACB, pDCB, ptr);
}
if( (pcmd->device->id == pACB->pScsiHost->max_id - 1) &&
(pcmd->device->lun == pACB->pScsiHost->max_lun - 1) )
pACB->scan_devices = 0;
}
pcmd->resid = pcmd->request_bufflen - pSRB->TotalXferredLen;
......
......@@ -174,6 +174,9 @@
* 2.1b2 04/02/01 CH (applied 05.04) Fix error-handling *
* 2.1c 04/05/23 GL Update to use the new pci_driver API, *
* some scsi EH updates, more cleanup. *
* 2.1d 04/05/27 GL Moved setting of scan_devices to *
* slave_alloc/_configure/_destroy, as *
* suggested by CH. *
***********************************************************************/
/* Uncomment SA_INTERRUPT, if the driver refuses to share its IRQ with other devices */
......@@ -1031,7 +1034,7 @@ static void dc390_BuildSRB (Scsi_Cmnd* pcmd, PDCB pDCB, PSRB pSRB)
* 2.0.x: always return 0
* 2.1.x: old model: (use_new_eh_code == 0): like 2.0.x
* TO BE DONE:
* new model: return 0 if successful
* new model: return 0 if successful, or must not be re-queued
* return 1 if command cannot be queued (queue full)
* command will be inserted in midlevel queue then ...
*
......@@ -1050,16 +1053,7 @@ static int DC390_queue_command (Scsi_Cmnd *cmd, void (* done)(Scsi_Cmnd *))
/* TODO: Change the policy: Always accept TEST_UNIT_READY or INQUIRY
* commands and alloc a DCB for the device if not yet there. DCB will
* be removed in dc390_SRBdone if SEL_TIMEOUT */
if (((pACB->scan_devices == END_SCAN) && (cmd->cmnd[0] != INQUIRY)) ||
((pACB->scan_devices) && (cmd->cmnd[0] == READ_6)))
pACB->scan_devices = 0;
if ((pACB->scan_devices || cmd->cmnd[0] == TEST_UNIT_READY || cmd->cmnd[0] == INQUIRY) &&
!(pACB->DCBmap[cmd->device->id] & (1 << cmd->device->lun))) {
pACB->scan_devices = 1;
DCBDEBUG(printk("Scanning target %02x lun %02x\n", cmd->device->id, cmd->device->lun));
} else if (!(pACB->scan_devices) && !(pACB->DCBmap[cmd->device->id] & (1 << cmd->device->lun))) {
if (!(pACB->scan_devices) && !(pACB->DCBmap[cmd->device->id] & (1 << cmd->device->lun))) {
printk(KERN_INFO "DC390: Ignore target %02x lun %02x\n",
cmd->device->id, cmd->device->lun);
goto fail;
......@@ -1914,8 +1908,10 @@ static int dc390_slave_alloc(struct scsi_device *scsi_device)
PDCB pDCB;
PACB pACB = (PACB) scsi_device->host->hostdata;
dc390_initDCB(pACB, &pDCB, scsi_device->id, scsi_device->lun);
if (pDCB != NULL)
if (pDCB != NULL) {
pACB->scan_devices = 1;
return 0;
}
return -ENOMEM;
}
......@@ -1929,18 +1925,27 @@ static void dc390_slave_destroy(struct scsi_device *scsi_device)
{
PACB pACB = (PACB) scsi_device->host->hostdata;
PDCB pDCB = dc390_findDCB (pACB, scsi_device->id, scsi_device->lun);;
pACB->scan_devices = 0;
if (pDCB != NULL)
dc390_remove_dev(pACB, pDCB);
else
printk(KERN_ERR"%s() called for non-existing device!\n", __FUNCTION__);
}
static int dc390_slave_configure(struct scsi_device *scsi_device)
{
PACB pACB = (PACB) scsi_device->host->hostdata;
pACB->scan_devices = 0;
return 0;
}
static Scsi_Host_Template driver_template = {
.module = THIS_MODULE,
.proc_name = "tmscsim",
.proc_info = DC390_proc_info,
.name = DC390_BANNER " V" DC390_VERSION,
.slave_alloc = dc390_slave_alloc,
.slave_configure = dc390_slave_configure,
.slave_destroy = dc390_slave_destroy,
.queuecommand = DC390_queue_command,
.eh_abort_handler = DC390_abort,
......
......@@ -22,8 +22,6 @@
#define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */
#define END_SCAN 2
#define pci_dma_lo32(a) (a & 0xffffffff)
typedef u8 UCHAR; /* 8 bits */
......
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