public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] some tmscsim consolidation
@ 2004-06-06 12:41 Christoph Hellwig
  2004-06-06 20:22 ` Guennadi Liakhovetski
  2004-06-23 15:59 ` Christoph Hellwig
  0 siblings, 2 replies; 8+ messages in thread
From: Christoph Hellwig @ 2004-06-06 12:41 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: linux-scsi

I've looked through my old tmscsim patch queue and found this one:

 - merge dc390_initDCB into dc390_slave_alloc
 - merge DC390_release and dc390_shutdown into dc390_remove_one,
   use del_timer_sync to make sure the timer is really deleted on
   removal, adjust locking accordingly
 - some tiny related cleanups


--- 1.38/drivers/scsi/tmscsim.c	2004-05-12 17:46:23 +02:00
+++ edited/drivers/scsi/tmscsim.c	2004-06-06 14:22:25 +02:00
@@ -340,11 +340,8 @@
 static irqreturn_t do_DC390_Interrupt( int, void *, struct pt_regs *);
 
 static int    dc390_initAdapter( PSH psh, ULONG io_port, UCHAR Irq, UCHAR index );
-static void   dc390_initDCB( PACB pACB, PDCB *ppDCB, UCHAR id, UCHAR lun);
 static void   dc390_updateDCB (PACB pACB, PDCB pDCB);
 
-static int DC390_release(struct Scsi_Host *host);
-static int dc390_shutdown (struct Scsi_Host *host);
 static int DC390_proc_info (struct Scsi_Host *shpnt, char *buffer, char **start,
 			    off_t offset, int length, int inout);
 
@@ -1527,94 +1524,6 @@
 
 #include "scsiiom.c"
 
-
-/***********************************************************************
- * Function : static void dc390_initDCB()
- *
- * Purpose :  initialize the internal structures for a DCB (to be malloced)
- *
- * Inputs : SCSI id and lun
- ***********************************************************************/
-
-static void dc390_initDCB( PACB pACB, PDCB *ppDCB, UCHAR id, UCHAR lun )
-{
-    PEEprom	prom;
-    UCHAR	index;
-    PDCB pDCB, pDCB2;
-
-    pDCB = kmalloc (sizeof(DC390_DCB), GFP_ATOMIC);
-    DCBDEBUG(printk (KERN_INFO "DC390: alloc mem for DCB (ID %i, LUN %i): %p\n",	\
-		     id, lun, pDCB));
- 
-    *ppDCB = pDCB;
-    if (!pDCB) return;
-    pDCB2 = 0;
-    if( pACB->DCBCnt == 0 )
-    {
-	pACB->pLinkDCB = pDCB;
-	pACB->pDCBRunRobin = pDCB;
-    }
-    else
-    {
-	pACB->pLastDCB->pNextDCB = pDCB;
-    }
-   
-    pACB->DCBCnt++;
-   
-    pDCB->pNextDCB = pACB->pLinkDCB;
-    pACB->pLastDCB = pDCB;
-
-    pDCB->pDCBACB = pACB;
-    pDCB->TargetID = id;
-    pDCB->TargetLUN = lun;
-    pDCB->pWaitingSRB = NULL;
-    pDCB->pGoingSRB = NULL;
-    pDCB->GoingSRBCnt = 0;
-    pDCB->WaitSRBCnt = 0;
-    pDCB->pActiveSRB = NULL;
-    pDCB->TagMask = 0;
-    pDCB->MaxCommand = 1;
-    index = pACB->AdapterIndex;
-    pDCB->DCBFlag = 0;
-
-    /* Is there a corresp. LUN==0 device ? */
-    if (lun != 0)
-	pDCB2 = dc390_findDCB (pACB, id, 0);
-    prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
-    /* Some values are for all LUNs: Copy them */
-    /* In a clean way: We would have an own structure for a SCSI-ID */
-    if (pDCB2)
-    {
-      pDCB->DevMode = pDCB2->DevMode;
-      pDCB->SyncMode = pDCB2->SyncMode;
-      pDCB->SyncPeriod = pDCB2->SyncPeriod;
-      pDCB->SyncOffset = pDCB2->SyncOffset;
-      pDCB->NegoPeriod = pDCB2->NegoPeriod;
-      
-      pDCB->CtrlR3 = pDCB2->CtrlR3;
-      pDCB->CtrlR4 = pDCB2->CtrlR4;
-      pDCB->Inquiry7 = pDCB2->Inquiry7;
-    }
-    else
-    {		
-      pDCB->DevMode = prom->EE_MODE1;
-      pDCB->SyncMode = 0;
-      pDCB->SyncPeriod = 0;
-      pDCB->SyncOffset = 0;
-      pDCB->NegoPeriod = (dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
-            
-      pDCB->CtrlR3 = FAST_CLK;
-      
-      pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
-      if( dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
-	pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
-      pDCB->Inquiry7 = 0;
-    }
-
-    pACB->DCBmap[id] |= (1 << lun);
-    dc390_updateDCB(pACB, pDCB);
-}
-
 /***********************************************************************
  * Function : static void dc390_updateDCB()
  *
@@ -1900,34 +1809,84 @@
  *
  * @scsi_device: The new scsi device that we need to handle.
  */
-static int dc390_slave_alloc(struct scsi_device *scsi_device)
+static int dc390_slave_alloc(struct scsi_device *sdev)
 {
-	PDCB pDCB;
-	PACB pACB = (PACB) scsi_device->host->hostdata;
-	dc390_initDCB(pACB, &pDCB, scsi_device->id, scsi_device->lun);
-	if (pDCB != NULL) {
-		scsi_device->hostdata = pDCB;
-		pACB->scan_devices = 1;
-		return 0;
+	PACB pACB = (PACB) sdev->host->hostdata;
+	PDCB pDCB, pDCB2 = NULL;
+	uint id =  sdev->id;
+	uint lun = sdev->lun;
+
+	pDCB = kmalloc(sizeof(DC390_DCB), GFP_KERNEL);
+	if (!pDCB)
+		return -ENOMEM;
+	memset(pDCB, 0, sizeof(*pDCB));
+
+	if (!pACB->DCBCnt++) {
+		pACB->pLinkDCB = pDCB;
+		pACB->pDCBRunRobin = pDCB;
+	} else {
+		pACB->pLastDCB->pNextDCB = pDCB;
+	}
+   
+	pDCB->pNextDCB = pACB->pLinkDCB;
+	pACB->pLastDCB = pDCB;
+
+	pDCB->pDCBACB = pACB;
+	pDCB->TargetID = id;
+	pDCB->TargetLUN = lun;
+	pDCB->MaxCommand = 1;
+	
+	/*
+	 * Some values are for all LUNs: Copy them 
+	 * In a clean way: We would have an own structure for a SCSI-ID 
+	 */
+	if (lun && (pDCB2 = dc390_findDCB(pACB, id, 0))) {
+		pDCB->DevMode = pDCB2->DevMode;
+		pDCB->SyncMode = pDCB2->SyncMode;
+		pDCB->SyncPeriod = pDCB2->SyncPeriod;
+		pDCB->SyncOffset = pDCB2->SyncOffset;
+		pDCB->NegoPeriod = pDCB2->NegoPeriod;
+      
+		pDCB->CtrlR3 = pDCB2->CtrlR3;
+		pDCB->CtrlR4 = pDCB2->CtrlR4;
+		pDCB->Inquiry7 = pDCB2->Inquiry7;
+	} else {		
+		u8 index = pACB->AdapterIndex;
+		PEEprom	prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
+
+		pDCB->DevMode = prom->EE_MODE1;
+		pDCB->NegoPeriod =
+			(dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
+ 
+		pDCB->CtrlR3 = FAST_CLK;
+		pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
+		
+		if (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
+			pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
 	}
-	return -ENOMEM;
+
+	pACB->DCBmap[id] |= (1 << lun);
+	dc390_updateDCB(pACB, pDCB);
+
+	pACB->scan_devices = 1;
+
+	sdev->hostdata = pDCB;
+	return 0;
 }
 
 /**
  * dc390_slave_destroy - Called by the scsi mid layer to tell us about a
  * device that is going away.
  *
- * @scsi_device: The scsi device that we need to remove.
+ * @sdev: The scsi device that we need to remove.
  */
-static void dc390_slave_destroy(struct scsi_device *scsi_device)
+static void dc390_slave_destroy(struct scsi_device *sdev)
 {
-	PACB pACB = (PACB) scsi_device->host->hostdata;
-	PDCB pDCB = (PDCB) scsi_device->hostdata;
+	PACB pACB = (PACB) sdev->host->hostdata;
+	PDCB pDCB = (PDCB) sdev->hostdata;
+
 	pACB->scan_devices = 0;
-	if (pDCB != NULL)
-		dc390_remove_dev(pACB, pDCB);
-	else
-		printk(KERN_ERR"%s() called for non-existing device!\n", __FUNCTION__);
+	dc390_remove_dev(pACB, pDCB);
 }
 
 static int dc390_slave_configure(struct scsi_device *scsi_device)
@@ -2010,15 +1969,32 @@
  *
  * @dev: The PCI device to remove.
  */
-static void __devexit dc390_remove_one(struct pci_dev *dev)
+static void __devexit dc390_remove_one(struct pci_dev *pdev)
 {
-	struct Scsi_Host *scsi_host = pci_get_drvdata(dev);
+	struct Scsi_Host *shost = pci_get_drvdata(pdev);
+	PACB pACB = (PACB) shost->hostdata;
+	u8 bval;
+	DC390_IFLAGS;
 
-	scsi_remove_host(scsi_host);
-	DC390_release(scsi_host);
-	pci_disable_device(dev);
-	scsi_host_put(scsi_host);
-	pci_set_drvdata(dev, NULL);
+	scsi_remove_host(shost);
+
+	DC390_LOCK_IO(shost);
+	pACB->ACBFlag = RESET_DEV;
+	bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST;
+	DC390_write8(CtrlReg1, bval);	/* disable interrupt */
+	if (pACB->Gmode2 & RST_SCSI_BUS)
+		dc390_ResetSCSIBus(pACB);
+	DC390_UNLOCK_IO(shost);
+
+	del_timer_sync(&pACB->Waiting_Timer);
+
+	free_irq(pdev->irq, pACB);
+	release_region(shost->io_port, shost->n_io_port);
+
+	scsi_host_put(shost);
+
+	pci_disable_device(pdev);
+	pci_set_drvdata(pdev, NULL);
 }
 
 /********************************************************************
@@ -2166,75 +2142,6 @@
 
 #undef YESNO
 #undef SPRINTF
-
-/***********************************************************************
- * Function : static int dc390_shutdown (struct Scsi_Host *host)
- *
- * Purpose : does a clean (we hope) shutdown of the SCSI chip.
- *	     Use prior to dumping core, unloading the driver, etc.
- *
- * Returns : 0 on success
- ***********************************************************************/
-static int dc390_shutdown (struct Scsi_Host *host)
-{
-    UCHAR    bval;
-    PACB pACB = (PACB) host->hostdata;
-   
-/*  pACB->soft_reset(host); */
-
-    printk(KERN_INFO "DC390: shutdown\n");
-
-    pACB->ACBFlag = RESET_DEV;
-    bval = DC390_read8 (CtrlReg1);
-    bval |= DIS_INT_ON_SCSI_RST;
-    DC390_write8 (CtrlReg1, bval);	/* disable interrupt */
-    if (pACB->Gmode2 & RST_SCSI_BUS)
-		dc390_ResetSCSIBus (pACB);
-
-    if (timer_pending (&pACB->Waiting_Timer)) del_timer (&pACB->Waiting_Timer);
-    return( 0 );
-}
-
-static void dc390_freeDCBs (struct Scsi_Host *host)
-{
-    PDCB pDCB, nDCB;
-    PACB pACB = (PACB) host->hostdata;
-    
-    pDCB = pACB->pLinkDCB;
-    if (!pDCB) return;
-    do
-    {
-	nDCB = pDCB->pNextDCB;
-	DCBDEBUG(printk (KERN_INFO "DC390: Free DCB (ID %i, LUN %i): %p\n",\
-			 pDCB->TargetID, pDCB->TargetLUN, pDCB));
-	//kfree (pDCB);
-	dc390_remove_dev (pACB, pDCB);
-	pDCB = nDCB;
-    } while (pDCB && pACB->pLinkDCB);
-
-}
-
-static int DC390_release (struct Scsi_Host *host)
-{
-    DC390_IFLAGS;
-    PACB pACB = (PACB) host->hostdata;
-
-    DC390_LOCK_IO(host);
-
-    /* TO DO: We should check for outstanding commands first. */
-    dc390_shutdown (host);
-
-    if (host->irq != SCSI_IRQ_NONE)
-    {
-	DEBUG0(printk(KERN_INFO "DC390: Free IRQ %i\n",host->irq));
-	free_irq (host->irq, pACB);
-    }
-
-    release_region(host->io_port,host->n_io_port);
-    dc390_freeDCBs (host);
-    DC390_UNLOCK_IO(host);
-    return( 1 );
-}
 
 static struct pci_driver dc390_driver = {
 	.name           = "tmscsim",

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] some tmscsim consolidation
  2004-06-06 12:41 [PATCH] some tmscsim consolidation Christoph Hellwig
@ 2004-06-06 20:22 ` Guennadi Liakhovetski
  2004-06-06 20:33   ` Christoph Hellwig
  2004-06-23 15:59 ` Christoph Hellwig
  1 sibling, 1 reply; 8+ messages in thread
From: Guennadi Liakhovetski @ 2004-06-06 20:22 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-scsi

On Sun, 6 Jun 2004, Christoph Hellwig wrote:

> I've looked through my old tmscsim patch queue and found this one:
>
>  - merge dc390_initDCB into dc390_slave_alloc
>  - merge DC390_release and dc390_shutdown into dc390_remove_one,
>    use del_timer_sync to make sure the timer is really deleted on
>    removal, adjust locking accordingly
>  - some tiny related cleanups

Thanks for the patch, Christoph. As you might have seen, I've already
submitted a patch, which merges _some_ of the functions above, following
your request:-). Is your patch based on something like vanilla 2.6.6, or
some bkX / preY? I'll try to find a version, to which it cleanly applies
and then re-diff with the current state.

Since you didn't sing-off for the patch, I guess, it's not yet
compulsory:-)

Thanks
Guennadi
---
Guennadi Liakhovetski



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] some tmscsim consolidation
  2004-06-06 20:22 ` Guennadi Liakhovetski
@ 2004-06-06 20:33   ` Christoph Hellwig
  2004-06-07 20:37     ` Guennadi Liakhovetski
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2004-06-06 20:33 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: linux-scsi

On Sun, Jun 06, 2004 at 10:22:41PM +0200, Guennadi Liakhovetski wrote:
> On Sun, 6 Jun 2004, Christoph Hellwig wrote:
> 
> > I've looked through my old tmscsim patch queue and found this one:
> >
> >  - merge dc390_initDCB into dc390_slave_alloc
> >  - merge DC390_release and dc390_shutdown into dc390_remove_one,
> >    use del_timer_sync to make sure the timer is really deleted on
> >    removal, adjust locking accordingly
> >  - some tiny related cleanups
> 
> Thanks for the patch, Christoph. As you might have seen, I've already
> submitted a patch, which merges _some_ of the functions above, following
> your request:-). Is your patch based on something like vanilla 2.6.6, or
> some bkX / preY? I'll try to find a version, to which it cleanly applies
> and then re-diff with the current state.

Ah sorry.  It's against James' scsi-misc-2.6 tree from a day or two ago.
I'll keep my eyes open and when I see your patch going in somewhere I'll
resend what's left if anything.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] some tmscsim consolidation
  2004-06-06 20:33   ` Christoph Hellwig
@ 2004-06-07 20:37     ` Guennadi Liakhovetski
  2004-06-20 16:21       ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Guennadi Liakhovetski @ 2004-06-07 20:37 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-scsi

On Sun, 6 Jun 2004, Christoph Hellwig wrote:

> On Sun, Jun 06, 2004 at 10:22:41PM +0200, Guennadi Liakhovetski wrote:
> > On Sun, 6 Jun 2004, Christoph Hellwig wrote:
> >
> > > I've looked through my old tmscsim patch queue and found this one:
> > >
> > >  - merge dc390_initDCB into dc390_slave_alloc
> > >  - merge DC390_release and dc390_shutdown into dc390_remove_one,
> > >    use del_timer_sync to make sure the timer is really deleted on
> > >    removal, adjust locking accordingly
> > >  - some tiny related cleanups
> >
> > Thanks for the patch, Christoph. As you might have seen, I've already
> > submitted a patch, which merges _some_ of the functions above, following
>
> Ah sorry.  It's against James' scsi-misc-2.6 tree from a day or two ago.
> I'll keep my eyes open and when I see your patch going in somewhere I'll
> resend what's left if anything.

Thanks again! That would, certainly, be a lot easier for me. But don't
worry - there'll be enough left for you:-) I think, the only thing I've
done from the above, is merging dc390_initDCB into dc390_slave_alloc and
DC390_release into dc390_remove_one, following your suggestion of 23 May.

Thanks
Guennadi
---
Guennadi Liakhovetski




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] some tmscsim consolidation
  2004-06-07 20:37     ` Guennadi Liakhovetski
@ 2004-06-20 16:21       ` Christoph Hellwig
  2004-06-20 20:26         ` Guennadi Liakhovetski
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2004-06-20 16:21 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: linux-scsi

On Mon, Jun 07, 2004 at 10:37:24PM +0200, Guennadi Liakhovetski wrote:
> On Sun, 6 Jun 2004, Christoph Hellwig wrote:
> 
> > On Sun, Jun 06, 2004 at 10:22:41PM +0200, Guennadi Liakhovetski wrote:
> > > On Sun, 6 Jun 2004, Christoph Hellwig wrote:
> > >
> > > > I've looked through my old tmscsim patch queue and found this one:
> > > >
> > > >  - merge dc390_initDCB into dc390_slave_alloc
> > > >  - merge DC390_release and dc390_shutdown into dc390_remove_one,
> > > >    use del_timer_sync to make sure the timer is really deleted on
> > > >    removal, adjust locking accordingly
> > > >  - some tiny related cleanups
> > >
> > > Thanks for the patch, Christoph. As you might have seen, I've already
> > > submitted a patch, which merges _some_ of the functions above, following
> >
> > Ah sorry.  It's against James' scsi-misc-2.6 tree from a day or two ago.
> > I'll keep my eyes open and when I see your patch going in somewhere I'll
> > resend what's left if anything.
> 
> Thanks again! That would, certainly, be a lot easier for me. But don't
> worry - there'll be enough left for you:-) I think, the only thing I've
> done from the above, is merging dc390_initDCB into dc390_slave_alloc and
> DC390_release into dc390_remove_one, following your suggestion of 23 May.

Your patch doesn't seem to be merged yet.  Maybe you need to resend it?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] some tmscsim consolidation
  2004-06-20 16:21       ` Christoph Hellwig
@ 2004-06-20 20:26         ` Guennadi Liakhovetski
  0 siblings, 0 replies; 8+ messages in thread
From: Guennadi Liakhovetski @ 2004-06-20 20:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-scsi

On Sun, 20 Jun 2004, Christoph Hellwig wrote:

> On Mon, Jun 07, 2004 at 10:37:24PM +0200, Guennadi Liakhovetski wrote:
>> On Sun, 6 Jun 2004, Christoph Hellwig wrote:
>>
>>> On Sun, Jun 06, 2004 at 10:22:41PM +0200, Guennadi Liakhovetski wrote:
>>>> On Sun, 6 Jun 2004, Christoph Hellwig wrote:
>>>>
>>>>> I've looked through my old tmscsim patch queue and found this one:
>>>>>
>>>>>  - merge dc390_initDCB into dc390_slave_alloc
>>>>>  - merge DC390_release and dc390_shutdown into dc390_remove_one,
>>>>>    use del_timer_sync to make sure the timer is really deleted on
>>>>>    removal, adjust locking accordingly
>>>>>  - some tiny related cleanups
>>>>
>>>> Thanks for the patch, Christoph. As you might have seen, I've already
>>>> submitted a patch, which merges _some_ of the functions above, following
>>>
>>> Ah sorry.  It's against James' scsi-misc-2.6 tree from a day or two ago.
>>> I'll keep my eyes open and when I see your patch going in somewhere I'll
>>> resend what's left if anything.
>>
>> Thanks again! That would, certainly, be a lot easier for me. But don't
>> worry - there'll be enough left for you:-) I think, the only thing I've
>> done from the above, is merging dc390_initDCB into dc390_slave_alloc and
>> DC390_release into dc390_remove_one, following your suggestion of 23 May.
>
> Your patch doesn't seem to be merged yet.  Maybe you need to resend it?

Please, see my other email, sent simultaneously with this one.

Thanks
Guennadi
---
Guennadi Liakhovetski


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] some tmscsim consolidation
  2004-06-06 12:41 [PATCH] some tmscsim consolidation Christoph Hellwig
  2004-06-06 20:22 ` Guennadi Liakhovetski
@ 2004-06-23 15:59 ` Christoph Hellwig
  2004-06-23 22:16   ` Guennadi Liakhovetski
  1 sibling, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2004-06-23 15:59 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: linux-scsi

On Sun, Jun 06, 2004 at 02:41:56PM +0200, Christoph Hellwig wrote:
> I've looked through my old tmscsim patch queue and found this one:
> 
>  - merge dc390_initDCB into dc390_slave_alloc
>  - merge DC390_release and dc390_shutdown into dc390_remove_one,
>    use del_timer_sync to make sure the timer is really deleted on
>    removal, adjust locking accordingly
>  - some tiny related cleanups

Okay, here's a resend vs current scsi-misc-2.6 that has your three
outstanding merged.  Additionally I've also killed dc390_freeDCBs()
as all dcbs are removed in ->slave_destroy.


--- 1.14/drivers/scsi/scsiiom.c	2004-06-19 01:03:38 +02:00
+++ edited/drivers/scsi/scsiiom.c	2004-06-23 16:40:08 +02:00
@@ -1283,46 +1283,6 @@
     DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD);	/* ;to release the /ACK signal */
 }
 
-
-static void 
-dc390_remove_dev (PACB pACB, PDCB pDCB)
-{
-   PDCB pPrevDCB = pACB->pLinkDCB;
-
-   if (pDCB->GoingSRBCnt > 1)
-     {
-	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
-   if (pDCB == pACB->pLinkDCB) 
-   {
-	// The last one
-	if (pACB->pLastDCB == pDCB) {
-		pDCB->pNextDCB = 0; pACB->pLastDCB = 0;
-	}
-	pACB->pLinkDCB = pDCB->pNextDCB;
-   }
-   else
-   {
-	while (pPrevDCB->pNextDCB != pDCB) pPrevDCB = pPrevDCB->pNextDCB;
-	pPrevDCB->pNextDCB = pDCB->pNextDCB;
-	if (pDCB == pACB->pLastDCB) pACB->pLastDCB = pPrevDCB;
-   }
-
-   DCBDEBUG(printk (KERN_INFO "DC390: Driver about to free DCB (ID %i, LUN %i): %p\n",\
-	   pDCB->TargetID, pDCB->TargetLUN, pDCB));
-   if (pDCB == pACB->pActiveDCB) pACB->pActiveDCB = 0;
-   if (pDCB == pACB->pLinkDCB) pACB->pLinkDCB = pDCB->pNextDCB;
-   if (pDCB == pACB->pDCBRunRobin) pACB->pDCBRunRobin = pDCB->pNextDCB;
-   kfree (pDCB); 
-   pACB->DCBCnt--;
-}
-
-
 static UCHAR __inline__
 dc390_tagq_blacklist (char* name)
 {
--- 1.41/drivers/scsi/tmscsim.c	2004-06-19 01:02:20 +02:00
+++ edited/drivers/scsi/tmscsim.c	2004-06-23 17:48:00 +02:00
@@ -326,11 +326,9 @@
 static void __inline__ dc390_RequestSense( PACB pACB, PDCB pDCB, PSRB pSRB );
 static void __inline__ dc390_InvalidCmd( PACB pACB );
 static void __inline__ dc390_EnableMsgOut_Abort (PACB, PSRB);
-static void dc390_remove_dev (PACB pACB, PDCB pDCB);
 static irqreturn_t do_DC390_Interrupt( int, void *, struct pt_regs *);
 
 static int    dc390_initAdapter( PSH psh, ULONG io_port, UCHAR Irq, UCHAR index );
-static void   dc390_initDCB( PACB pACB, PDCB *ppDCB, UCHAR id, UCHAR lun);
 static void   dc390_updateDCB (PACB pACB, PDCB pDCB);
 
 static int DC390_proc_info (struct Scsi_Host *shpnt, char *buffer, char **start,
@@ -1522,95 +1520,6 @@
 
 #include "scsiiom.c"
 
-
-/***********************************************************************
- * Function : static void dc390_initDCB()
- *
- * Purpose :  initialize the internal structures for a DCB (to be malloced)
- *
- * Inputs : SCSI id and lun
- ***********************************************************************/
-
-static void dc390_initDCB( PACB pACB, PDCB *ppDCB, UCHAR id, UCHAR lun )
-{
-    PEEprom	prom;
-    UCHAR	index;
-    PDCB	pDCB, pDCB2 = 0;
-
-    pDCB = kmalloc (sizeof(DC390_DCB), GFP_ATOMIC);
-    DCBDEBUG(printk (KERN_INFO "DC390: alloc mem for DCB (ID %i, LUN %i): %p\n",	\
-		     id, lun, pDCB));
-
-    *ppDCB = pDCB;
-    if (!pDCB)
-	return;
-
-    if( pACB->DCBCnt == 0 )
-    {
-	pACB->pLinkDCB = pDCB;
-	pACB->pDCBRunRobin = pDCB;
-    }
-    else
-    {
-	pACB->pLastDCB->pNextDCB = pDCB;
-    }
-   
-    pACB->DCBCnt++;
-   
-    pDCB->pNextDCB = pACB->pLinkDCB;
-    pACB->pLastDCB = pDCB;
-
-    pDCB->pDCBACB = pACB;
-    pDCB->TargetID = id;
-    pDCB->TargetLUN = lun;
-    pDCB->pWaitingSRB = NULL;
-    pDCB->pGoingSRB = NULL;
-    pDCB->GoingSRBCnt = 0;
-    pDCB->WaitSRBCnt = 0;
-    pDCB->pActiveSRB = NULL;
-    pDCB->TagMask = 0;
-    pDCB->MaxCommand = 1;
-    index = pACB->AdapterIndex;
-    pDCB->DCBFlag = 0;
-
-    /* Is there a corresp. LUN==0 device ? */
-    if (lun != 0)
-	pDCB2 = dc390_findDCB (pACB, id, 0);
-    prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
-    /* Some values are for all LUNs: Copy them */
-    /* In a clean way: We would have an own structure for a SCSI-ID */
-    if (pDCB2)
-    {
-      pDCB->DevMode = pDCB2->DevMode;
-      pDCB->SyncMode = pDCB2->SyncMode;
-      pDCB->SyncPeriod = pDCB2->SyncPeriod;
-      pDCB->SyncOffset = pDCB2->SyncOffset;
-      pDCB->NegoPeriod = pDCB2->NegoPeriod;
-      
-      pDCB->CtrlR3 = pDCB2->CtrlR3;
-      pDCB->CtrlR4 = pDCB2->CtrlR4;
-      pDCB->Inquiry7 = pDCB2->Inquiry7;
-    }
-    else
-    {		
-      pDCB->DevMode = prom->EE_MODE1;
-      pDCB->SyncMode = 0;
-      pDCB->SyncPeriod = 0;
-      pDCB->SyncOffset = 0;
-      pDCB->NegoPeriod = (dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
-            
-      pDCB->CtrlR3 = FAST_CLK;
-      
-      pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
-      if( dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
-	pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
-      pDCB->Inquiry7 = 0;
-    }
-
-    pACB->DCBmap[id] |= (1 << lun);
-    dc390_updateDCB(pACB, pDCB);
-}
-
 /***********************************************************************
  * Function : static void dc390_updateDCB()
  *
@@ -1839,15 +1748,64 @@
  */
 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) {
-		scsi_device->hostdata = pDCB;
-		pACB->scan_devices = 1;
-		return 0;
+	PDCB pDCB, pDCB2 = 0;
+	uint id = scsi_device->id;
+	uint lun = scsi_device->lun;
+
+	pDCB = kmalloc(sizeof(DC390_DCB), GFP_KERNEL);
+	if (!pDCB)
+		return -ENOMEM;
+	memset(pDCB, 0, sizeof(DC390_DCB));
+
+	if (!pACB->DCBCnt++) {
+		pACB->pLinkDCB = pDCB;
+		pACB->pDCBRunRobin = pDCB;
+	} else {
+		pACB->pLastDCB->pNextDCB = pDCB;
+	}
+   
+	pDCB->pNextDCB = pACB->pLinkDCB;
+	pACB->pLastDCB = pDCB;
+
+	pDCB->pDCBACB = pACB;
+	pDCB->TargetID = id;
+	pDCB->TargetLUN = lun;
+	pDCB->MaxCommand = 1;
+
+	/*
+	 * Some values are for all LUNs: Copy them 
+	 * In a clean way: We would have an own structure for a SCSI-ID 
+	 */
+	if (lun && (pDCB2 = dc390_findDCB(pACB, id, 0))) {
+		pDCB->DevMode = pDCB2->DevMode;
+		pDCB->SyncMode = pDCB2->SyncMode;
+		pDCB->SyncPeriod = pDCB2->SyncPeriod;
+		pDCB->SyncOffset = pDCB2->SyncOffset;
+		pDCB->NegoPeriod = pDCB2->NegoPeriod;
+      
+		pDCB->CtrlR3 = pDCB2->CtrlR3;
+		pDCB->CtrlR4 = pDCB2->CtrlR4;
+		pDCB->Inquiry7 = pDCB2->Inquiry7;
+	} else {
+		u8 index = pACB->AdapterIndex;
+		PEEprom prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
+
+		pDCB->DevMode = prom->EE_MODE1;
+		pDCB->NegoPeriod =
+			(dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
+		pDCB->CtrlR3 = FAST_CLK;
+		pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
+		if (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
+			pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
 	}
-	return -ENOMEM;
+
+	pACB->DCBmap[id] |= (1 << lun);
+	dc390_updateDCB(pACB, pDCB);
+
+	pACB->scan_devices = 1;
+	scsi_device->hostdata = pDCB;
+	return 0;
 }
 
 /**
@@ -1860,11 +1818,37 @@
 {
 	PACB pACB = (PACB) scsi_device->host->hostdata;
 	PDCB pDCB = (PDCB) scsi_device->hostdata;
+	PDCB pPrevDCB = pACB->pLinkDCB;
+
 	pACB->scan_devices = 0;
-	if (pDCB != NULL)
-		dc390_remove_dev(pACB, pDCB);
-	else
-		printk(KERN_ERR"%s() called for non-existing device!\n", __FUNCTION__);
+
+	BUG_ON(pDCB->GoingSRBCnt > 1);
+	
+	pACB->DCBmap[pDCB->TargetID] &= ~(1 << pDCB->TargetLUN);
+   
+	if (pDCB == pACB->pLinkDCB) {
+		if (pACB->pLastDCB == pDCB) {
+			pDCB->pNextDCB = NULL;
+			pACB->pLastDCB = NULL;
+		}
+		pACB->pLinkDCB = pDCB->pNextDCB;
+	} else {
+		while (pPrevDCB->pNextDCB != pDCB)
+			pPrevDCB = pPrevDCB->pNextDCB;
+		pPrevDCB->pNextDCB = pDCB->pNextDCB;
+		if (pDCB == pACB->pLastDCB)
+			pACB->pLastDCB = pPrevDCB;
+	}
+
+	if (pDCB == pACB->pActiveDCB)
+		pACB->pActiveDCB = NULL;
+	if (pDCB == pACB->pLinkDCB)
+		pACB->pLinkDCB = pDCB->pNextDCB;
+	if (pDCB == pACB->pDCBRunRobin)
+		pACB->pDCBRunRobin = pDCB->pNextDCB;
+	kfree(pDCB); 
+	
+	pACB->DCBCnt--;
 }
 
 static int dc390_slave_configure(struct scsi_device *scsi_device)
@@ -1966,52 +1950,6 @@
 	return ret;
 }
 
-static void __devexit dc390_freeDCBs (struct Scsi_Host *host)
-{
-    PDCB pDCB, nDCB;
-    PACB pACB = (PACB) host->hostdata;
-    
-    pDCB = pACB->pLinkDCB;
-    if (!pDCB) return;
-    do
-    {
-	nDCB = pDCB->pNextDCB;
-	DCBDEBUG(printk (KERN_INFO "DC390: Free DCB (ID %i, LUN %i): %p\n",\
-			 pDCB->TargetID, pDCB->TargetLUN, pDCB));
-	//kfree (pDCB);
-	dc390_remove_dev (pACB, pDCB);
-	pDCB = nDCB;
-    } while (pDCB && pACB->pLinkDCB);
-}
-
-/***********************************************************************
- * Function : static int dc390_shutdown (struct Scsi_Host *host)
- *
- * Purpose : does a clean (we hope) shutdown of the SCSI chip.
- *	     Use prior to dumping core, unloading the driver, etc.
- *
- * Returns : 0 on success
- ***********************************************************************/
-static int __devexit dc390_shutdown (struct Scsi_Host *host)
-{
-    UCHAR    bval;
-    PACB pACB = (PACB) host->hostdata;
-   
-/*  pACB->soft_reset(host); */
-
-    printk(KERN_INFO "DC390: shutdown\n");
-
-    pACB->ACBFlag = RESET_DEV;
-    bval = DC390_read8 (CtrlReg1);
-    bval |= DIS_INT_ON_SCSI_RST;
-    DC390_write8 (CtrlReg1, bval);	/* disable interrupt */
-    if (pACB->Gmode2 & RST_SCSI_BUS)
-		dc390_ResetSCSIBus (pACB);
-
-    if (timer_pending (&pACB->Waiting_Timer)) del_timer (&pACB->Waiting_Timer);
-    return( 0 );
-}
-
 /**
  * dc390_remove_one - Called to remove a single instance of the adapter.
  *
@@ -2022,22 +1960,22 @@
 	struct Scsi_Host *scsi_host = pci_get_drvdata(dev);
 	unsigned long iflags;
 	PACB pACB = (PACB) scsi_host->hostdata;
+	u8 bval;
 
 	scsi_remove_host(scsi_host);
 
 	spin_lock_irqsave(scsi_host->host_lock, iflags);
+	pACB->ACBFlag = RESET_DEV;
+	bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST;
+	DC390_write8 (CtrlReg1, bval);	/* disable interrupt */
+	if (pACB->Gmode2 & RST_SCSI_BUS)
+		dc390_ResetSCSIBus(pACB);
+	spin_unlock_irqrestore(scsi_host->host_lock, iflags);
 
-	/* TO DO: We should check for outstanding commands first. */
-	dc390_shutdown(scsi_host);
-
-	if (scsi_host->irq != SCSI_IRQ_NONE) {
-		DEBUG0(printk(KERN_INFO "DC390: Free IRQ %i\n", scsi_host->irq));
-		free_irq(scsi_host->irq, pACB);
-	}
+	del_timer_sync(&pACB->Waiting_Timer);
 
+	free_irq(scsi_host->irq, pACB);
 	release_region(scsi_host->io_port, scsi_host->n_io_port);
-	dc390_freeDCBs(scsi_host);
-	spin_unlock_irqrestore(scsi_host->host_lock, iflags);
 
 	pci_disable_device(dev);
 	scsi_host_put(scsi_host);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] some tmscsim consolidation
  2004-06-23 15:59 ` Christoph Hellwig
@ 2004-06-23 22:16   ` Guennadi Liakhovetski
  0 siblings, 0 replies; 8+ messages in thread
From: Guennadi Liakhovetski @ 2004-06-23 22:16 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-scsi, James Bottomley

Hi

On Wed, 23 Jun 2004, Christoph Hellwig wrote:

> On Sun, Jun 06, 2004 at 02:41:56PM +0200, Christoph Hellwig wrote:
>> I've looked through my old tmscsim patch queue and found this one:
>>
>>  - merge dc390_initDCB into dc390_slave_alloc
>>  - merge DC390_release and dc390_shutdown into dc390_remove_one,
>>    use del_timer_sync to make sure the timer is really deleted on
>>    removal, adjust locking accordingly
>>  - some tiny related cleanups
>
> Okay, here's a resend vs current scsi-misc-2.6 that has your three
> outstanding merged.  Additionally I've also killed dc390_freeDCBs()
> as all dcbs are removed in ->slave_destroy.

Thanks, Christoph!

James, I need not to say - no objections, please, apply.

Thanks
Guennadi

>
>
> --- 1.14/drivers/scsi/scsiiom.c	2004-06-19 01:03:38 +02:00
> +++ edited/drivers/scsi/scsiiom.c	2004-06-23 16:40:08 +02:00
> @@ -1283,46 +1283,6 @@
>     DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD);	/* ;to release the /ACK signal */
> }
>
> -
> -static void
> -dc390_remove_dev (PACB pACB, PDCB pDCB)
> -{
> -   PDCB pPrevDCB = pACB->pLinkDCB;
> -
> -   if (pDCB->GoingSRBCnt > 1)
> -     {
> -	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
> -   if (pDCB == pACB->pLinkDCB)
> -   {
> -	// The last one
> -	if (pACB->pLastDCB == pDCB) {
> -		pDCB->pNextDCB = 0; pACB->pLastDCB = 0;
> -	}
> -	pACB->pLinkDCB = pDCB->pNextDCB;
> -   }
> -   else
> -   {
> -	while (pPrevDCB->pNextDCB != pDCB) pPrevDCB = pPrevDCB->pNextDCB;
> -	pPrevDCB->pNextDCB = pDCB->pNextDCB;
> -	if (pDCB == pACB->pLastDCB) pACB->pLastDCB = pPrevDCB;
> -   }
> -
> -   DCBDEBUG(printk (KERN_INFO "DC390: Driver about to free DCB (ID %i, LUN %i): %p\n",\
> -	   pDCB->TargetID, pDCB->TargetLUN, pDCB));
> -   if (pDCB == pACB->pActiveDCB) pACB->pActiveDCB = 0;
> -   if (pDCB == pACB->pLinkDCB) pACB->pLinkDCB = pDCB->pNextDCB;
> -   if (pDCB == pACB->pDCBRunRobin) pACB->pDCBRunRobin = pDCB->pNextDCB;
> -   kfree (pDCB);
> -   pACB->DCBCnt--;
> -}
> -
> -
> static UCHAR __inline__
> dc390_tagq_blacklist (char* name)
> {
> --- 1.41/drivers/scsi/tmscsim.c	2004-06-19 01:02:20 +02:00
> +++ edited/drivers/scsi/tmscsim.c	2004-06-23 17:48:00 +02:00
> @@ -326,11 +326,9 @@
> static void __inline__ dc390_RequestSense( PACB pACB, PDCB pDCB, PSRB pSRB );
> static void __inline__ dc390_InvalidCmd( PACB pACB );
> static void __inline__ dc390_EnableMsgOut_Abort (PACB, PSRB);
> -static void dc390_remove_dev (PACB pACB, PDCB pDCB);
> static irqreturn_t do_DC390_Interrupt( int, void *, struct pt_regs *);
>
> static int    dc390_initAdapter( PSH psh, ULONG io_port, UCHAR Irq, UCHAR index );
> -static void   dc390_initDCB( PACB pACB, PDCB *ppDCB, UCHAR id, UCHAR lun);
> static void   dc390_updateDCB (PACB pACB, PDCB pDCB);
>
> static int DC390_proc_info (struct Scsi_Host *shpnt, char *buffer, char **start,
> @@ -1522,95 +1520,6 @@
>
> #include "scsiiom.c"
>
> -
> -/***********************************************************************
> - * Function : static void dc390_initDCB()
> - *
> - * Purpose :  initialize the internal structures for a DCB (to be malloced)
> - *
> - * Inputs : SCSI id and lun
> - ***********************************************************************/
> -
> -static void dc390_initDCB( PACB pACB, PDCB *ppDCB, UCHAR id, UCHAR lun )
> -{
> -    PEEprom	prom;
> -    UCHAR	index;
> -    PDCB	pDCB, pDCB2 = 0;
> -
> -    pDCB = kmalloc (sizeof(DC390_DCB), GFP_ATOMIC);
> -    DCBDEBUG(printk (KERN_INFO "DC390: alloc mem for DCB (ID %i, LUN %i): %p\n",	\
> -		     id, lun, pDCB));
> -
> -    *ppDCB = pDCB;
> -    if (!pDCB)
> -	return;
> -
> -    if( pACB->DCBCnt == 0 )
> -    {
> -	pACB->pLinkDCB = pDCB;
> -	pACB->pDCBRunRobin = pDCB;
> -    }
> -    else
> -    {
> -	pACB->pLastDCB->pNextDCB = pDCB;
> -    }
> -
> -    pACB->DCBCnt++;
> -
> -    pDCB->pNextDCB = pACB->pLinkDCB;
> -    pACB->pLastDCB = pDCB;
> -
> -    pDCB->pDCBACB = pACB;
> -    pDCB->TargetID = id;
> -    pDCB->TargetLUN = lun;
> -    pDCB->pWaitingSRB = NULL;
> -    pDCB->pGoingSRB = NULL;
> -    pDCB->GoingSRBCnt = 0;
> -    pDCB->WaitSRBCnt = 0;
> -    pDCB->pActiveSRB = NULL;
> -    pDCB->TagMask = 0;
> -    pDCB->MaxCommand = 1;
> -    index = pACB->AdapterIndex;
> -    pDCB->DCBFlag = 0;
> -
> -    /* Is there a corresp. LUN==0 device ? */
> -    if (lun != 0)
> -	pDCB2 = dc390_findDCB (pACB, id, 0);
> -    prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
> -    /* Some values are for all LUNs: Copy them */
> -    /* In a clean way: We would have an own structure for a SCSI-ID */
> -    if (pDCB2)
> -    {
> -      pDCB->DevMode = pDCB2->DevMode;
> -      pDCB->SyncMode = pDCB2->SyncMode;
> -      pDCB->SyncPeriod = pDCB2->SyncPeriod;
> -      pDCB->SyncOffset = pDCB2->SyncOffset;
> -      pDCB->NegoPeriod = pDCB2->NegoPeriod;
> -
> -      pDCB->CtrlR3 = pDCB2->CtrlR3;
> -      pDCB->CtrlR4 = pDCB2->CtrlR4;
> -      pDCB->Inquiry7 = pDCB2->Inquiry7;
> -    }
> -    else
> -    {
> -      pDCB->DevMode = prom->EE_MODE1;
> -      pDCB->SyncMode = 0;
> -      pDCB->SyncPeriod = 0;
> -      pDCB->SyncOffset = 0;
> -      pDCB->NegoPeriod = (dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
> -
> -      pDCB->CtrlR3 = FAST_CLK;
> -
> -      pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
> -      if( dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
> -	pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
> -      pDCB->Inquiry7 = 0;
> -    }
> -
> -    pACB->DCBmap[id] |= (1 << lun);
> -    dc390_updateDCB(pACB, pDCB);
> -}
> -
> /***********************************************************************
>  * Function : static void dc390_updateDCB()
>  *
> @@ -1839,15 +1748,64 @@
>  */
> 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) {
> -		scsi_device->hostdata = pDCB;
> -		pACB->scan_devices = 1;
> -		return 0;
> +	PDCB pDCB, pDCB2 = 0;
> +	uint id = scsi_device->id;
> +	uint lun = scsi_device->lun;
> +
> +	pDCB = kmalloc(sizeof(DC390_DCB), GFP_KERNEL);
> +	if (!pDCB)
> +		return -ENOMEM;
> +	memset(pDCB, 0, sizeof(DC390_DCB));
> +
> +	if (!pACB->DCBCnt++) {
> +		pACB->pLinkDCB = pDCB;
> +		pACB->pDCBRunRobin = pDCB;
> +	} else {
> +		pACB->pLastDCB->pNextDCB = pDCB;
> +	}
> +
> +	pDCB->pNextDCB = pACB->pLinkDCB;
> +	pACB->pLastDCB = pDCB;
> +
> +	pDCB->pDCBACB = pACB;
> +	pDCB->TargetID = id;
> +	pDCB->TargetLUN = lun;
> +	pDCB->MaxCommand = 1;
> +
> +	/*
> +	 * Some values are for all LUNs: Copy them
> +	 * In a clean way: We would have an own structure for a SCSI-ID
> +	 */
> +	if (lun && (pDCB2 = dc390_findDCB(pACB, id, 0))) {
> +		pDCB->DevMode = pDCB2->DevMode;
> +		pDCB->SyncMode = pDCB2->SyncMode;
> +		pDCB->SyncPeriod = pDCB2->SyncPeriod;
> +		pDCB->SyncOffset = pDCB2->SyncOffset;
> +		pDCB->NegoPeriod = pDCB2->NegoPeriod;
> +
> +		pDCB->CtrlR3 = pDCB2->CtrlR3;
> +		pDCB->CtrlR4 = pDCB2->CtrlR4;
> +		pDCB->Inquiry7 = pDCB2->Inquiry7;
> +	} else {
> +		u8 index = pACB->AdapterIndex;
> +		PEEprom prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
> +
> +		pDCB->DevMode = prom->EE_MODE1;
> +		pDCB->NegoPeriod =
> +			(dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
> +		pDCB->CtrlR3 = FAST_CLK;
> +		pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
> +		if (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
> +			pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
> 	}
> -	return -ENOMEM;
> +
> +	pACB->DCBmap[id] |= (1 << lun);
> +	dc390_updateDCB(pACB, pDCB);
> +
> +	pACB->scan_devices = 1;
> +	scsi_device->hostdata = pDCB;
> +	return 0;
> }
>
> /**
> @@ -1860,11 +1818,37 @@
> {
> 	PACB pACB = (PACB) scsi_device->host->hostdata;
> 	PDCB pDCB = (PDCB) scsi_device->hostdata;
> +	PDCB pPrevDCB = pACB->pLinkDCB;
> +
> 	pACB->scan_devices = 0;
> -	if (pDCB != NULL)
> -		dc390_remove_dev(pACB, pDCB);
> -	else
> -		printk(KERN_ERR"%s() called for non-existing device!\n", __FUNCTION__);
> +
> +	BUG_ON(pDCB->GoingSRBCnt > 1);
> +
> +	pACB->DCBmap[pDCB->TargetID] &= ~(1 << pDCB->TargetLUN);
> +
> +	if (pDCB == pACB->pLinkDCB) {
> +		if (pACB->pLastDCB == pDCB) {
> +			pDCB->pNextDCB = NULL;
> +			pACB->pLastDCB = NULL;
> +		}
> +		pACB->pLinkDCB = pDCB->pNextDCB;
> +	} else {
> +		while (pPrevDCB->pNextDCB != pDCB)
> +			pPrevDCB = pPrevDCB->pNextDCB;
> +		pPrevDCB->pNextDCB = pDCB->pNextDCB;
> +		if (pDCB == pACB->pLastDCB)
> +			pACB->pLastDCB = pPrevDCB;
> +	}
> +
> +	if (pDCB == pACB->pActiveDCB)
> +		pACB->pActiveDCB = NULL;
> +	if (pDCB == pACB->pLinkDCB)
> +		pACB->pLinkDCB = pDCB->pNextDCB;
> +	if (pDCB == pACB->pDCBRunRobin)
> +		pACB->pDCBRunRobin = pDCB->pNextDCB;
> +	kfree(pDCB);
> +
> +	pACB->DCBCnt--;
> }
>
> static int dc390_slave_configure(struct scsi_device *scsi_device)
> @@ -1966,52 +1950,6 @@
> 	return ret;
> }
>
> -static void __devexit dc390_freeDCBs (struct Scsi_Host *host)
> -{
> -    PDCB pDCB, nDCB;
> -    PACB pACB = (PACB) host->hostdata;
> -
> -    pDCB = pACB->pLinkDCB;
> -    if (!pDCB) return;
> -    do
> -    {
> -	nDCB = pDCB->pNextDCB;
> -	DCBDEBUG(printk (KERN_INFO "DC390: Free DCB (ID %i, LUN %i): %p\n",\
> -			 pDCB->TargetID, pDCB->TargetLUN, pDCB));
> -	//kfree (pDCB);
> -	dc390_remove_dev (pACB, pDCB);
> -	pDCB = nDCB;
> -    } while (pDCB && pACB->pLinkDCB);
> -}
> -
> -/***********************************************************************
> - * Function : static int dc390_shutdown (struct Scsi_Host *host)
> - *
> - * Purpose : does a clean (we hope) shutdown of the SCSI chip.
> - *	     Use prior to dumping core, unloading the driver, etc.
> - *
> - * Returns : 0 on success
> - ***********************************************************************/
> -static int __devexit dc390_shutdown (struct Scsi_Host *host)
> -{
> -    UCHAR    bval;
> -    PACB pACB = (PACB) host->hostdata;
> -
> -/*  pACB->soft_reset(host); */
> -
> -    printk(KERN_INFO "DC390: shutdown\n");
> -
> -    pACB->ACBFlag = RESET_DEV;
> -    bval = DC390_read8 (CtrlReg1);
> -    bval |= DIS_INT_ON_SCSI_RST;
> -    DC390_write8 (CtrlReg1, bval);	/* disable interrupt */
> -    if (pACB->Gmode2 & RST_SCSI_BUS)
> -		dc390_ResetSCSIBus (pACB);
> -
> -    if (timer_pending (&pACB->Waiting_Timer)) del_timer (&pACB->Waiting_Timer);
> -    return( 0 );
> -}
> -
> /**
>  * dc390_remove_one - Called to remove a single instance of the adapter.
>  *
> @@ -2022,22 +1960,22 @@
> 	struct Scsi_Host *scsi_host = pci_get_drvdata(dev);
> 	unsigned long iflags;
> 	PACB pACB = (PACB) scsi_host->hostdata;
> +	u8 bval;
>
> 	scsi_remove_host(scsi_host);
>
> 	spin_lock_irqsave(scsi_host->host_lock, iflags);
> +	pACB->ACBFlag = RESET_DEV;
> +	bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST;
> +	DC390_write8 (CtrlReg1, bval);	/* disable interrupt */
> +	if (pACB->Gmode2 & RST_SCSI_BUS)
> +		dc390_ResetSCSIBus(pACB);
> +	spin_unlock_irqrestore(scsi_host->host_lock, iflags);
>
> -	/* TO DO: We should check for outstanding commands first. */
> -	dc390_shutdown(scsi_host);
> -
> -	if (scsi_host->irq != SCSI_IRQ_NONE) {
> -		DEBUG0(printk(KERN_INFO "DC390: Free IRQ %i\n", scsi_host->irq));
> -		free_irq(scsi_host->irq, pACB);
> -	}
> +	del_timer_sync(&pACB->Waiting_Timer);
>
> +	free_irq(scsi_host->irq, pACB);
> 	release_region(scsi_host->io_port, scsi_host->n_io_port);
> -	dc390_freeDCBs(scsi_host);
> -	spin_unlock_irqrestore(scsi_host->host_lock, iflags);
>
> 	pci_disable_device(dev);
> 	scsi_host_put(scsi_host);
>
>

---
Guennadi Liakhovetski


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-06-23 22:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-06 12:41 [PATCH] some tmscsim consolidation Christoph Hellwig
2004-06-06 20:22 ` Guennadi Liakhovetski
2004-06-06 20:33   ` Christoph Hellwig
2004-06-07 20:37     ` Guennadi Liakhovetski
2004-06-20 16:21       ` Christoph Hellwig
2004-06-20 20:26         ` Guennadi Liakhovetski
2004-06-23 15:59 ` Christoph Hellwig
2004-06-23 22:16   ` Guennadi Liakhovetski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox