SCSI updates for 2.6.6
Quoted 13 lines · Kurt Garloff
Quoted 12 lines · James Bottomley
Quoted 2 lines · Guennadi Liakhovetski
I hoped the tmscsim 64-bit bugfix would somehow find its way into the mainstream after 2.6. Does it still have a chance?
The DC390 is a maintained driver:
DC390/AM53C974 SCSI driver
P: Kurt Garloff
M: [email protected]
W: http://www.garloff.de/kurt/linux/dc390/
S: Maintained
Quoted 7 lines
Quoted 1 line
You need to get the maintainer to approve acceptance.
Granted ;-)
Actually, I had discussed the patch before with Guennadi and agreed to it. As I don't really have much time any more for it, I would suggest that Guennadi takes over, if he wants to.
Well, Kurt, thanks for the offer. I am prepared and willing to do the work on supporting the driver, but I am, perhaps, not skilled enough to be a maintainer of a SCSI LDD. My knowledge of the SCSI protocol and the SCSI Linux subsystem is pretty limited. On one hand, the driver is little used, so, even if I badly break something it is not likely to cause major problems. On the other hand, I would feel more comfortable if, at least at the beginning, somebody would review my patches. Besides, it would be a good opportunity for me to really learn a bit more about SCSI, SCSI Linux driver, BIO,... oh well...
Thanks
Guennadi
---
Guennadi Liakhovetski
Quoted 9 lines · Guennadi Liakhovetski
Well, Kurt, thanks for the offer. I am prepared and willing to do the work on supporting the driver, but I am, perhaps, not skilled enough to be a maintainer of a SCSI LDD. My knowledge of the SCSI protocol and the SCSI Linux subsystem is pretty limited. On one hand, the driver is little used, so, even if I badly break something it is not likely to cause major problems. On the other hand, I would feel more comfortable if, at least at the beginning, somebody would review my patches. Besides, it would be a good opportunity for me to really learn a bit more about SCSI, SCSI Linux driver, BIO,... oh well...
OK, roll up for me what you'd currently like applied to the driver; anything that's less than solid, I'd rather mature in the -mm tree for a while.
James
Quoted 9 lines · Guennadi Liakhovetski
Well, Kurt, thanks for the offer. I am prepared and willing to do the work on supporting the driver, but I am, perhaps, not skilled enough to be a maintainer of a SCSI LDD. My knowledge of the SCSI protocol and the SCSI Linux subsystem is pretty limited. On one hand, the driver is little used, so, even if I badly break something it is not likely to cause major problems. On the other hand, I would feel more comfortable if, at least at the beginning, somebody would review my patches. Besides, it would be a good opportunity for me to really learn a bit more about SCSI, SCSI Linux driver, BIO,... oh well...
Don't worry about it. You'll learn these things in time ...
If Kurt's willing to review your patches when you send them, that'd be best (but don't necessarily wait for Kurt's ack before applying).
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
PATCH 1/1 tmscsim: 64-bit cleanup
In reply to James BottomleyQuoted 3 lines · James Bottomley
OK, roll up for me what you'd currently like applied to the driver; anything that's less than solid, I'd rather mature in the -mm tree for a while.
Ok, here comes the first one. I chose this one because it fixes an actual bug in the driver. This bug was (partially) introduced by myself when porting to 2.6. Partly the reason was that I disliked using function-like macros as lvalues:
sg_dma_address(x) = ...sg_dma_len(x) = ...
[OT] wouldn't it be better to introduce some macros like set_sg_dma_{address|len}(x, y)?
A part of the original patch has already been merged (s/UINT/ULONG/), so, the actual version is re-diffed against 2.6.6-bk6 and re-tested (on a plain Pentium).
Also updates the driver-version, printed on startup.
Please, apply.
Christoph, next I would like to see your patches applied. Do you want to re-submit them yourself, or should I do it for you?
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/tmscsim.c +11 -7
@@ -168,6 +168,7 @@* 2.1a 03/11/29 GL, KG Initial fixing for 2.6. Convert to * * use the current PCI-mapping API, update * * command-queuing. * +* 2.1b 04/04/13 GL Fix for 64-bit platforms * ***********************************************************************/ /* Uncomment SA_INTERRUPT, if the driver refuses to share its IRQ with other devices */
@@ -1022,7 +1023,7 @@pci_map_page (pdev,virt_to_page (pcmd->sense_buffer), (unsigned long )pcmd->sense_buffer & ~PAGE_MASK ,sizeof (pcmd->sense_buffer),DMA_FROM_DEVICE ); - pSRB->Segmentx.length =sizeof (pcmd->sense_buffer); +sg_dma_len (&pSRB->Segmentx) =sizeof (pcmd->sense_buffer); pSRB->SGcount =1 ; pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx;DEBUG1 (printk ("%s(): Mapped sense buffer %p at %x\n" , __FUNCTION__, pcmd->sense_buffer, cmdp->saved_dma_handle));
@@ -1043,7 +1044,7 @@ (unsigned long )pcmd->request_buffer & ~PAGE_MASK , pcmd->request_bufflen, scsi_to_pci_dma_dir(pcmd->sc_data_direction));/* TODO: error handling */ - pSRB->Segmentx.length = pcmd->request_bufflen; +sg_dma_len (&pSRB->Segmentx) = pcmd->request_bufflen; pSRB->SGcount =1 ; pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx;DEBUG1 (printk ("%s(): Mapped request buffer %p at %x\n" , __FUNCTION__, pcmd->request_buffer, cmdp->saved_dma_handle));
@@ -1131,7 +1132,7 @@if (!pcmd) {dc390_Free_insert (pACB, pSRB);return ; }/* should not happen */ pDCB =dc390_findDCB (pACB, pcmd->device->id, pcmd->device->lun);if (!pDCB) - { + {dc390_Free_insert (pACB, pSRB);printk (KERN_ERR "DC390: Command in queue to non-existing device!\n" ); pcmd->result =MK_RES (DRIVER_ERROR ,DID_ERROR ,0 ,0 );
@@ -1180,7 +1181,7 @@/* Assume BAD_TARGET; will be cleared later */ cmd->result =DID_BAD_TARGET <<16 ; -/* TODO: Change the policy: Alway accept TEST_UNIT_READY or INQUIRY +/* 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 */
@@ -1767,7 +1768,7 @@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" \ +DCBDEBUG (printk (KERN_INFO "DC390: alloc mem for DCB (ID %i, LUN %i): %p\n" , \ id, lun, pDCB)); *ppDCB = pDCB;
@@ -2229,10 +2230,13 @@if (PCI_PRESENT )while (PCI_FIND_DEVICE (PCI_VENDOR_ID_AMD ,PCI_DEVICE_ID_AMD53C974 )) { -#if LINUX_VERSION_CODE >KERNEL_VERSION (2 ,3 ,30 )if (pci_enable_device (pdev))continue ; -#endif + +if (pci_set_dma_mask (pdev,0xffffffff )) { +printk (KERN_ERR "DC390(%i): No suitable DMA available.\n" , dc390_adapterCnt); +continue ; + }PCI_GET_IO_AND_IRQ ;DEBUG0 (printk (KERN_INFO "DC390(%i): IO_PORT=%04x,IRQ=%x\n" , dc390_adapterCnt, (UINT ) io_port, irq));
drivers/scsi/scsiiom.c +7 -5
@@ -521,7 +521,7 @@ {DC390_write8 (ScsiCmd,CLEAR_FIFO_CMD );DC390_write8 (DMA_Cmd,READ_DIRECTION +DMA_IDLE_CMD );/* | DMA_INT */ - } + } } static void
@@ -740,9 +740,9 @@ psgl = pSRB->pSegmentList;//dc390_pci_sync(pSRB); -while (pSRB->TotalXferredLen + (ULONG ) psgl->length < pSRB->Saved_Ptr) +while (pSRB->TotalXferredLen + (ULONG )sg_dma_len (psgl) < pSRB->Saved_Ptr) { - pSRB->TotalXferredLen += (ULONG ) psgl->length; + pSRB->TotalXferredLen += (ULONG )sg_dma_len (psgl); pSRB->SGIndex++;if ( pSRB->SGIndex < pSRB->SGcount ) {
@@ -762,7 +762,7 @@ }else if (pcmd->request_buffer) {//dc390_pci_sync(pSRB); - pSRB->Segmentx.length = pcmd->request_bufflen - pSRB->Saved_Ptr; +sg_dma_len (&pSRB->Segmentx) = pcmd->request_bufflen - pSRB->Saved_Ptr; pSRB->SGcount =1 ; pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx; }else {
@@ -885,6 +885,8 @@if (pDCB)printk (KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (%02i-%i)\n" , pDCB->TargetID, pDCB->TargetLUN);else printk (KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (DCB 0!)\n" ); + + pSRB->pSRBDCB = pDCB;dc390_EnableMsgOut_Abort (pACB, pSRB);if (pDCB) pDCB->DCBFlag |=ABORT_DEV ;return ;
@@ -1466,7 +1468,7 @@ ptr2 = pSRB->pSegmentList;for ( i=pSRB->SGIndex; i < bval; i++) { - swlval += ptr2->length; + swlval +=sg_dma_len (ptr2); ptr2++; } REMOVABLEDEBUG(printk(KERN_INFO "XferredLen=%08x,NotXferLen=%08x\n",\
drivers/scsi/dc390.h +1 -1
@@ -19,7 +19,7 @@#endif #define DC390_BANNER "Tekram DC390/AM53C974" -#define DC390_VERSION "2.0f 2000-12-20" +#define DC390_VERSION "2.1b 2004-04-13"/* We don't have eh_abort_handler, eh_device_reset_handler, * eh_bus_reset_handler, eh_host_reset_handler yet!
Re: [PATCH] tmscsim: no internal queue
Here comes the 2nd one. I wanted to get Christoph's patches now in, but already the first his patch comes on the top of this one: remove internal command queuing in the driver. And, in fact, it fixes some bugs in it. So, they should go in together. Here's the original comment from Christoph's email of 1 Feb 2004:
<start quote>
Patch looks mostly good for me. But there's some fishyness in queuecommand, mostly from before you patch:
- many failure cases return one with the new EH code although we wouldn't want to requeue the midlayer in that case. I removed the ifdef and added a failed goto to handle them.
- we need to set cmd->result onlyh if we have an error instead of always an overriding it - else it will leak to the midlayer in the return 1 case.
- the check for ids out of range are superflous (this was one of the errors above, I decided to remove it instead of fixing it).
- you don't do DC390_UNLOCK_ACB when failing. While it's a noop I think it's bad to have locking macros in place and don't balance them. You should probably remove it completly in one of the next patches.
- the pDCB->pWaitingSRB looks a bit strange. By unifying the the codepathes it becomes much more readable.
<end quote>
Please, apply.
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/scsiiom.c +0 -3
@@ -1152,7 +1152,6 @@ pSRB = psrb; } pDCB->pGoingSRB =0 ; -dc390_Query_to_Waiting (pACB);dc390_Waiting_process (pACB); }else
@@ -1634,7 +1633,6 @@ pcmd->scsi_done (pcmd);DC390_LOCK_ACB_NI ; -dc390_Query_to_Waiting (pACB);dc390_Waiting_process (pACB);return ; }
@@ -1681,7 +1679,6 @@ pdcb->TagMask =0 ; pdcb = pdcb->pNextDCB; }while ( pdcb != pDCB ); -dc390_Query_to_Waiting (pACB); }
drivers/scsi/tmscsim.c +6 -95
159 lines not on this page · raw message
drivers/scsi/tmscsim.h +6 -17
@@ -214,16 +214,12 @@PSRB pTmpSRB;/* 0x2c: */ -ULONG QueryCnt; -struct list_head cmdq; - -/* 0x38: */ UCHAR msgin123[4 ];UCHAR DCBmap[MAX_SCSI_ID ];UCHAR Connected;UCHAR pad; -/* 0x3c: */ +/* 0x30: */ #if defined(USE_SPINLOCKS ) &&USE_SPINLOCKS >1 && (defined(CONFIG_SMP ) ||DEBUG_SPINLOCKS >0 )spinlock_t lock;#endif
@@ -234,20 +230,20 @@UCHAR Ignore_IRQ;/* Not used */ PDEVDECL1 ;/* Pointer to PCI cfg. space */ -/* 0x4c/0x48: */ +/* 0x40/0x3c: */ ULONG Cmds;UINT SelLost;UINT SelConn;UINT CmdInQ;UINT CmdOutOfSRB; -/* 0x60/0x5c: */ +/* 0x54/0x50: */ struct timer_list Waiting_Timer; -/* 0x74/0x70: */ +/* 0x68/0x64: */ DC390_SRB TmpSRB; -/* 0xd8/0xd4: */ +/* 0xcc/0xc8: */ DC390_SRB SRB_array[MAX_SRB_CNT ];/* 50 SRBs */ -/* 0xfb0/0xfac: */ +/* 0xfa4/0xfa0: */ };typedef struct _ACB DC390_ACB , *PACB ;
@@ -406,15 +402,8 @@* SISC query queue */ typedef struct { -struct list_head list;dma_addr_t saved_dma_handle; }dc390_cmd_scp_t ; - -struct scsi_cmnd_list -{ -char dummy[offsetof(struct scsi_cmnd , SCp)]; -dc390_cmd_scp_t scp; -};/* ** Inquiry Data format
drivers/scsi/tmscsim.c +25 -63
134 lines not on this page · raw message
Well this may be a little off topic.
But I would like to thank Kurt for supporting DC390 back in 1997 (or 1996? I know it was before the France World Cup soccer games) when I was contemplating of moving to Solaris or linux from OS/2.
Without his support to fix some problems (module usage, etc.), I would not have moved to linux at all.
The DC390 is still working in my PC box to connect HP DAT2 tape drive and CD/PD combo while faster SCSI disks are connected on other boards.
Thank you again, Garloff-san !
PS: This trusty AMD chip board may be still alive in many PC boxes around the world...
Quoted 20 lines · James Bottomley
Quoted 9 lines · Guennadi Liakhovetski
Well, Kurt, thanks for the offer. I am prepared and willing to do the work on supporting the driver, but I am, perhaps, not skilled enough to be a maintainer of a SCSI LDD. My knowledge of the SCSI protocol and the SCSI Linux subsystem is pretty limited. On one hand, the driver is little used, so, even if I badly break something it is not likely to cause major problems. On the other hand, I would feel more comfortable if, at least at the beginning, somebody would review my patches. Besides, it would be a good opportunity for me to really learn a bit more about SCSI, SCSI Linux driver, BIO,... oh well...
OK, roll up for me what you'd currently like applied to the driver; anything that's less than solid, I'd rather mature in the -mm tree for a while.
James
Signature · 5 lines
int main(void){int j=2003;/*(c)2003 cishikawa. */
char t[] ="<CI> @abcdefghijklmnopqrstuvwxyz.,\n\"";
char *i ="g>qtCIuqivb,gCwe\[email protected]\"tqkvv is>dnamz";
while(*i)((j+=strchr(t,*i++)-(int)t),(j%=sizeof t-1),
(putchar(t[j])));return 0;}/* under GPL */Re: [PATCH] tmscsim: 64-bit cleanup
In reply to Guennadi LiakhovetskiQuoted 10 lines · Guennadi Liakhovetski
Ok, here comes the first one. I chose this one because it fixes an actual bug in the driver. This bug was (partially) introduced by myself when porting to 2.6. Partly the reason was that I disliked using function-like macros as lvalues:
sg_dma_address(x)= ...sg_dma_len(x)= ...[OT] wouldn't it be better to introduce some macros like set_sg_dma_{address|len}(x, y)?
Actually, no. struct scatterlist is for the OS platform to use to characterise DMA; it's actually a private structure entirely within the gift of the architecture to define. It usually contains bits of extraneous data that the driver never sees. The driver should convert struct scatterlist into its own version of the scatterlist that needs feeding to the hardware rather than try and use struct scatterlist.
You'll find that lvalue use of sg_dma_len() fails on some platforms that actually compute it from page/offset values in the scatterlist.
Could you (eventually) update tmscsim not to use it?
Thanks,
James
Re: [PATCH] tmscsim: 64-bit cleanup
Quoted 4 lines · James Bottomley
You'll find that lvalue use of
sg_dma_len()fails on some platforms that actually compute it from page/offset values in the scatterlist.Could you (eventually) update tmscsim not to use it?
Ok, thanks for the comments, I'll do that.
Here comes the next (trivial) patch. I just want to get it out of the way to make the next (scary) patch smaller and simpler. This one doesn't modify the object code either. Actually, well, it does - it makes a few objects, that were previously declared extern static. And removes a couple more defines.
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/tmscsim.c +45 -55
@@ -283,14 +283,8 @@#define USE_SPINLOCKS 1#define DC390_IFLAGS unsigned long iflags -#define DC390_DFLAGS unsigned long dflags -spinlock_t dc390_drvlock =SPIN_LOCK_UNLOCKED ;#define DC390_LOCK_IO (dev) spin_lock_irqsave (((struct Scsi_Host *)dev)->host_lock, iflags)#define DC390_UNLOCK_IO (dev) spin_unlock_irqrestore (((struct Scsi_Host *)dev)->host_lock, iflags) -#define DC390_LOCK_DRV spin_lock_irqsave (&dc390_drvlock, dflags) -#define DC390_UNLOCK_DRV spin_unlock_irqrestore (&dc390_drvlock, dflags) -#define DC390_LOCK_DRV_NI spin_lock (&dc390_drvlock) -#define DC390_UNLOCK_DRV_NI spin_unlock (&dc390_drvlock)/* These macros are used for uniform access to 2.0.x and 2.1.x PCI config space*/
@@ -304,10 +298,7 @@#define PCI_READ_CONFIG_BYTE (pd, rv, bv) pci_read_config_byte (pd, rv, bv)#define PCI_WRITE_CONFIG_WORD (pd, rv, bv) pci_write_config_word (pd, rv, bv)#define PCI_READ_CONFIG_WORD (pd, rv, bv) pci_read_config_word (pd, rv, bv) -#define PCI_BUS_DEV pdev->bus->number, pdev->devfn#define PCI_PRESENT (1) -#define PCI_SET_MASTER pci_set_master (pdev) -#define PCI_FIND_DEVICE (vend, id) (pdev = pci_find_device (vend, id, pdev))#define PCI_GET_IO_AND_IRQ do{io_port = pci_resource_start (pdev, 0); irq = pdev->irq;} while(0)#include "tmscsim.h"
@@ -316,38 +307,38 @@# define __init#endif -UCHAR dc390_StartSCSI (PACB pACB,PDCB pDCB,PSRB pSRB ); -void dc390_DataOut_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus); -void dc390_DataIn_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus); +static UCHAR dc390_StartSCSI (PACB pACB,PDCB pDCB,PSRB pSRB ); +static void dc390_DataOut_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus); +static void dc390_DataIn_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_Command_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_Status_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_MsgOut_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus); -void dc390_MsgIn_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus); +static void dc390_MsgIn_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_DataOutPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_DataInPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus); -void dc390_CommandPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus); +static void dc390_CommandPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_StatusPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus); -void dc390_MsgOutPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus); +static void dc390_MsgOutPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_MsgInPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_Nop_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_Nop_1 (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_SetXferRate (PACB pACB,PDCB pDCB ); -void dc390_Disconnect (PACB pACB ); -void dc390_Reselect (PACB pACB ); -void dc390_SRBdone (PACB pACB,PDCB pDCB,PSRB pSRB ); -void dc390_DoingSRB_Done (PACB pACB,PSCSICMD cmd ); +static void dc390_Disconnect (PACB pACB ); +static void dc390_Reselect (PACB pACB ); +static void dc390_SRBdone (PACB pACB,PDCB pDCB,PSRB pSRB ); +static void dc390_DoingSRB_Done (PACB pACB,PSCSICMD cmd );static void dc390_ScsiRstDetect (PACB pACB );static void dc390_ResetSCSIBus (PACB pACB );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); -irqreturn_t do_DC390_Interrupt (int ,void *,struct pt_regs *); +static irqreturn_t do_DC390_Interrupt (int ,void *,struct pt_regs *); -int dc390_initAdapter (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index ); -void dc390_initDCB (PACB pACB,PDCB *ppDCB,UCHAR id,UCHAR lun); -void dc390_updateDCB (PACB pACB,PDCB pDCB); +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);
@@ -359,7 +350,7 @@static UCHAR dc390_adapterCnt =0 ;/* Startup values, to be overriden on the commandline */ -int tmscsim[] = {-2 ,-2 ,-2 ,-2 ,-2 ,-2 }; +static int tmscsim[] = {-2 ,-2 ,-2 ,-2 ,-2 ,-2 };#if defined(MODULE )MODULE_PARM (tmscsim,"1-6i" );
@@ -422,15 +413,15 @@#endif /* Devices erroneously pretending to be able to do TagQ */ -UCHAR dc390_baddevname1[2 ][28 ] ={ +static UCHAR dc390_baddevname1[2 ][28 ] ={"SEAGATE ST3390N 9546" ,"HP C3323-300 4269" };#define BADDEVCNT 2static char * dc390_adapname ="DC390" ; -UCHAR dc390_eepromBuf[MAX_ADAPTER_NUM ][EE_LEN ]; -UCHAR dc390_clock_period1[] = {4 ,5 ,6 ,7 ,8 ,10 ,13 ,20 }; -UCHAR dc390_clock_speed[] = {100 ,80 ,67 ,57 ,50 ,40 ,31 ,20 }; +static UCHAR dc390_eepromBuf[MAX_ADAPTER_NUM ][EE_LEN ]; +static UCHAR dc390_clock_period1[] = {4 ,5 ,6 ,7 ,8 ,10 ,13 ,20 }; +static UCHAR dc390_clock_speed[] = {100 ,80 ,67 ,57 ,50 ,40 ,31 ,20 };/*********************************************************************** * Functions for access to DC390 EEPROM
@@ -495,7 +486,7 @@ } -int __initdata tmscsim_def[] = {7 ,0 /* 10MHz */ , +static int __initdata tmscsim_def[] = {7 ,0 /* 10MHz */ ,PARITY_CHK_ |SEND_START_ |EN_DISCONNECT_ |SYNC_NEGO_ |TAG_QUEUEING_ ,MORE2_DRV |GREATER_1G |RST_SCSI_BUS |ACTIVE_NEGATION
@@ -526,7 +517,7 @@/* Override defaults on cmdline: * tmscsim: AdaptID, MaxSpeed (Index), DevMode (Bitmapped), AdaptMode (Bitmapped) */ -int __init dc390_setup (char *str) +static int __init dc390_setup (char *str) {int ints[8 ];int i, im;
@@ -818,7 +809,7 @@dc390_Going_append (pDCB, pSRB); } -void DC390_waiting_timed_out (unsigned long ptr); +static void DC390_waiting_timed_out (unsigned long ptr);/* Sets the timer to wake us up */ static void dc390_waiting_timer (PACB pACB,unsigned long to) {
@@ -871,7 +862,7 @@ }/* Wake up waiting queue */ -void DC390_waiting_timed_out (unsigned long ptr) +static void DC390_waiting_timed_out (unsigned long ptr) {PACB pACB = (PACB )ptr;DC390_IFLAGS ;
@@ -1046,7 +1037,7 @@* ***********************************************************************/ -int DC390_queue_command (Scsi_Cmnd *cmd,void (* done)(Scsi_Cmnd *)) +static int DC390_queue_command (Scsi_Cmnd *cmd,void (* done)(Scsi_Cmnd *)) {PDCB pDCB;PSRB pSRB;
@@ -1213,8 +1204,8 @@* Note: * In contrary to other externally callable funcs (DC390_), we don't lock ***********************************************************************/ -int DC390_bios_param (struct scsi_device *sdev,struct block_device *bdev, -sector_t capacity,int geom[]) +static int DC390_bios_param (struct scsi_device *sdev,struct block_device *bdev, +sector_t capacity,int geom[]) {int heads, sectors, cylinders;PACB pACB = (PACB ) sdev->host->hostdata;
@@ -1250,15 +1241,14 @@ return (0); }#else -int DC390_bios_param (struct scsi_device *sdev,struct block_device *bdev, -sector_t capacity,int geom[]) +static int DC390_bios_param (struct scsi_device *sdev,struct block_device *bdev, +sector_t capacity,int geom[]) {return scsicam_bios_param (bdev, capacity, geom); }#endif - -void dc390_dumpinfo (PACB pACB,PDCB pDCB,PSRB pSRB) +static void dc390_dumpinfo (PACB pACB,PDCB pDCB,PSRB pSRB) {USHORT pstat;PDEVDECL1 ;if (!pDCB) pDCB = pACB->pActiveDCB;
@@ -1312,7 +1302,7 @@* Status: Buggy ! ***********************************************************************/ -int DC390_abort (Scsi_Cmnd *cmd) +static int DC390_abort (Scsi_Cmnd *cmd) {PDCB pDCB;PSRB pSRB, psrb;
@@ -1518,7 +1508,7 @@* Returns : 0 on success. ***********************************************************************/ -int DC390_reset (Scsi_Cmnd *cmd) +static int DC390_reset (Scsi_Cmnd *cmd) {UCHAR bval;PACB pACB = (PACB ) cmd->device->host->hostdata;
@@ -1567,7 +1557,7 @@* Inputs : SCSI id and lun ***********************************************************************/ -void dc390_initDCB (PACB pACB,PDCB *ppDCB,UCHAR id,UCHAR lun ) +static void dc390_initDCB (PACB pACB,PDCB *ppDCB,UCHAR id,UCHAR lun ) {PEEprom prom;UCHAR index;
@@ -1652,7 +1642,7 @@* Purpose : Set the configuration dependent DCB parameters ***********************************************************************/ -void dc390_updateDCB (PACB pACB,PDCB pDCB) +static void dc390_updateDCB (PACB pACB,PDCB pDCB) { pDCB->SyncMode &=EN_TAG_QUEUEING |SYNC_NEGO_DONE /*| EN_ATN_STOP*/ ;if (pDCB->DevMode &TAG_QUEUEING_ ) {
@@ -1690,7 +1680,7 @@ } -void dc390_linkSRB (PACB pACB ) +static void dc390_linkSRB (PACB pACB ) {UINT count, i;
@@ -1715,7 +1705,7 @@* io_port, Irq, index: Resources and adapter index ***********************************************************************/ -void __init dc390_initACB (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) +static void __init dc390_initACB (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) {PACB pACB;UCHAR i;
@@ -1788,7 +1778,7 @@* Outputs: 0 on success, -1 on error ***********************************************************************/ -int __init dc390_initAdapter (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) +static int __init dc390_initAdapter (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) {PACB pACB, pACB2;UCHAR dstate;
@@ -1867,7 +1857,7 @@* Inputs : host - pointer to this host adapter's structure * io_port - IO ports mapped to this adapter * Irq - IRQ assigned to this adpater -* PDEVDECL - PCI access handle +* struct pci_dev - PCI access handle * index - Adapter index * * Outputs: 0 on success, -1 on error
@@ -1876,7 +1866,7 @@* not in DC390_detect, called from outside ***********************************************************************/ -static int __init DC390_init (PSHT psht,ULONG io_port,UCHAR Irq,PDEVDECL ,UCHAR index) +static int __init DC390_init (PSHT psht,ULONG io_port,UCHAR Irq,struct pci_dev *pdev,UCHAR index) {PSH psh;PACB pACB;
@@ -1939,14 +1929,14 @@int __init DC390_detect (Scsi_Host_Template *psht) { -PDEVDECL0 ; +struct pci_dev *pdev =NULL ;UCHAR irq;ULONG io_port; dc390_pACB_start =NULL ;if (PCI_PRESENT ) -while (PCI_FIND_DEVICE (PCI_VENDOR_ID_AMD ,PCI_DEVICE_ID_AMD53C974 )) +while ((pdev =pci_find_device (PCI_VENDOR_ID_AMD ,PCI_DEVICE_ID_AMD53C974 , pdev))) {if (pci_enable_device (pdev))continue ;
@@ -1960,7 +1950,7 @@if ( !DC390_init (psht, io_port, irq,PDEV , dc390_adapterCnt)) { -PCI_SET_MASTER ; +pci_set_master (pdev);dc390_set_pci_cfg (PDEV ); dc390_adapterCnt++; }
@@ -2002,8 +1992,8 @@ else SPRINTF(" No ") -int DC390_proc_info (struct Scsi_Host *shpnt,char *buffer,char **start, -off_t offset,int length,int inout) +static int DC390_proc_info (struct Scsi_Host *shpnt,char *buffer,char **start, +off_t offset,int length,int inout) {int dev, spd, spd1;char *pos = buffer;
@@ -2149,7 +2139,7 @@return (0 ); } -void dc390_freeDCBs (struct Scsi_Host *host) +static void dc390_freeDCBs (struct Scsi_Host *host) {PDCB pDCB, nDCB;PACB pACB = (PACB )(host->hostdata);
@@ -2168,7 +2158,7 @@ } -int DC390_release (struct Scsi_Host *host) +static int DC390_release (struct Scsi_Host *host) {DC390_IFLAGS ;PACB pACB = (PACB )(host->hostdata);
drivers/scsi/dc390.h +5 -5
@@ -33,11 +33,11 @@# define USE_NEW_EH #endif -extern int DC390_detect (Scsi_Host_Template *psht); -extern int DC390_queue_command (Scsi_Cmnd *cmd,void (*done)(Scsi_Cmnd *)); -extern int DC390_abort (Scsi_Cmnd *cmd); -extern int DC390_reset (Scsi_Cmnd *cmd); -extern int DC390_bios_param (struct scsi_device *sdev,struct block_device *dev, +static int DC390_detect (Scsi_Host_Template *psht); +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 *);
drivers/scsi/scsiiom.c +5 -5
@@ -15,7 +15,7 @@ }; -UCHAR +static UCHAR dc390_StartSCSI (PACB pACB,PDCB pDCB,PSRB pSRB ) {UCHAR cmd;UCHAR disc_allowed, try_sync_nego;
@@ -336,7 +336,7 @@return IRQ_HANDLED ; } -irqreturn_t do_DC390_Interrupt (int irq,void *dev_id,struct pt_regs *regs) +static irqreturn_t do_DC390_Interrupt (int irq,void *dev_id,struct pt_regs *regs) {irqreturn_t ret;DEBUG1 (printk (KERN_INFO "DC390: Irq (%i) caught: " , irq));
@@ -346,7 +346,7 @@return ret; } -void +static void dc390_DataOut_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus) {UCHAR sstatus;
@@ -400,7 +400,7 @@ } } -void +static void dc390_DataIn_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus) {UCHAR sstatus, residual, bval;
@@ -863,7 +863,7 @@ } -void +static void dc390_DataIO_Comm (PACB pACB,PSRB pSRB,UCHAR ioDir) {PSGL psgl;
Re: [PATCH] tmscsim: 64-bit cleanup
In reply to James BottomleyHi James, Guennadi,
Quoted 7 lines · James Bottomley
On Wed, 2004-05-19 at 14:50, Guennadi Liakhovetski wrote:
Actually, no. struct scatterlist is for the OS platform to use to characterise DMA; it's actually a private structure entirely within the gift of the architecture to define. It usually contains bits of extraneous data that the driver never sees. The driver should convert struct scatterlist into its own version of the scatterlist that needs feeding to the hardware rather than try and use struct scatterlist.
The AM53C974 hardware does not have hardware support for scatter-gather. (Yes, this is sad, you get an IRQ after every segment ...)
Quoted 4 lines
You'll find that lvalue use of
sg_dma_len()fails on some platforms that actually compute it from page/offset values in the scatterlist.Could you (eventually) update tmscsim not to use it?
We could just define our own format, make a copy and then use that one.
Regards,
Signature · 2 lines
Kurt Garloff <[email protected]> Cologne, DE SUSE LINUX AG / Novell, Nuernberg, DE Director SUSE Labs
Re: [PATCH] tmscsim: 64-bit cleanup
Quoted 11 lines · Kurt Garloff
Quoted 7 lines · James Bottomley
On Wed, 2004-05-19 at 14:50, Guennadi Liakhovetski wrote:
Actually, no. struct scatterlist is for the OS platform to use to characterise DMA; it's actually a private structure entirely within the gift of the architecture to define. It usually contains bits of extraneous data that the driver never sees. The driver should convert struct scatterlist into its own version of the scatterlist that needs feeding to the hardware rather than try and use struct scatterlist.The AM53C974 hardware does not have hardware support for scatter-gather. (Yes, this is sad, you get an IRQ after every segment ...)
But then you should set sg_tablesize to one. There's little point the elevator wasting time to coalesce if you can't process the request in a single go. Doing that would also allow for a simpler driver design, because now you know you can complete individual requests since they only yield a single sg element. You no longer have to track multiple card completions to the request completion.
Quoted 6 lines
Quoted 4 lines
You'll find that lvalue use of
sg_dma_len()fails on some platforms that actually compute it from page/offset values in the scatterlist.Could you (eventually) update tmscsim not to use it?
We could just define our own format, make a copy and then use that one.
Sure, that would be fine. Whatever the registers take.
James
Re: [PATCH] tmscsim: 64-bit cleanup
Quoted 10 lines · James Bottomley
Quoted 2 lines · Kurt Garloff
The AM53C974 hardware does not have hardware support for scatter-gather. (Yes, this is sad, you get an IRQ after every segment ...)
But then you should set
sg_tablesizeto one. There's little point the elevator wasting time to coalesce if you can't process the request in a single go. Doing that would also allow for a simpler driver design, because now you know you can complete individual requests since they only yield a single sg element. You no longer have to track multiple card completions to the request completion.
It's still cheaper to send down one command for a large transfer, let the card interrupt the CPU to get a new DMA address every segment. (When we're lucky, we might even have segments with contiguous bus
addresses -- this is certainly the case if there's a IOMMU in the system)
The per-command overhead in SCSI is significant, so I would hate to restrict the driver to process 4k commands.
Regards,
Signature · 2 lines
Kurt Garloff <[email protected]> Cologne, DE SUSE LINUX AG / Novell, Nuernberg, DE Director SUSE Labs
Re: [PATCH] tmscsim: 64-bit cleanup
In reply to James BottomleyQuoted 4 lines · James Bottomley
Quoted 1 line · Kurt Garloff
We could just define our own format, make a copy and then use that one.
Sure, that would be fine. Whatever the registers take.
Thanks for clarifications and ideas, Kurt, James. As usual - any help is highly appreciated.
Regards
Guennadi
---
Guennadi Liakhovetski
Re: [PATCH] tmscsim: new interfaces
In reply to James BottomleyOk, here comes the risky (and, so far, the last) one. It updates the driver to use the "new" pci, scsi, and module interfaces. It is risky, because it changes quite a bit, and I, unfortunatly, can only test it in one configuration - compiled in (not as a module), and I don't have any devices, that support tagged command queues, and it is just an onboard AM53C974 chip without EEPROM.
So, any amount of reviewing and testing would be appreciated.
With a bit of work I could, perhaps, organise to boot from another media and so test a modular build, but not immediately.
Thanks
Guennadi
---
Guennadi Liakhovetski
linux-2.6.6-bk6-tmscsim/drivers/scsi/dc390.h renamed from drivers/scsi/dc390.h +0 -1
@@ -33,7 +33,6 @@# define USE_NEW_EH #endif -static int DC390_detect (Scsi_Host_Template *psht);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);
linux-2.6.6-bk6-tmscsim/drivers/scsi/scsiiom.c renamed from drivers/scsi/scsiiom.c +11 -59
141 lines not on this page · raw message
linux-2.6.6-bk6-tmscsim/drivers/scsi/tmscsim.c renamed from drivers/scsi/tmscsim.c +142 -98
328 lines not on this page · raw message
Re: [PATCH] tmscsim: new interfaces
Quoted 6 lines · Guennadi Liakhovetski
Ok, here comes the risky (and, so far, the last) one. It updates the driver to use the "new" pci, scsi, and module interfaces. It is risky, because it changes quite a bit, and I, unfortunatly, can only test it in one configuration - compiled in (not as a module), and I don't have any devices, that support tagged command queues, and it is just an onboard AM53C974 chip without EEPROM.
Looks mostly goo to me, one thing I worry about is the complete removal of the scan_device flag, I don't fully understand what it's supposed to do, but we should be able to always set in ->slave_alloc and then clear it in ->slave_configure when we know probing is over for this device.
The other thing is that most calls to dc390_findDCB could probably be replaced with stroing the pDCB in scsi_device->hostdata on slave_alloc, but that could aswell be done in an incremental patch.
In dc390_init_one you don't call pci_disable_device on failure, best switch to goto for a single shared error path to avoid all these leaks. Maybe also merge dc390_init and dc390_init_one?
Similarly I think DC390_release should be merged into dc390_remove_one.
Re: [PATCH] tmscsim: new interfaces
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Guennadi Liakhovetski
Ok, here comes the risky (and, so far, the last) one. It updates the driver to use the "new" pci, scsi, and module interfaces. It is risky, because it changes quite a bit, and I, unfortunatly, can only test it in one configuration - compiled in (not as a module), and I don't have any devices, that support tagged command queues, and it is just an onboard AM53C974 chip without EEPROM.
Quoted 5 lines
Looks mostly goo to me, one thing I worry about is the complete removal of the
scan_deviceflag, I don't fully understand what it's supposed to do, but we should be able to always set in ->slave_alloc and then clear it in ->slave_configure when we know probing is over for this device.
Right, thanks. I didn't understand at all what scan_devices was doing there, so, I tried to preserve its semantics in the driver, and "just" overlooked its setting in dc390_SRBdone:-( But, wouldn't it be safer to just restore the relevant parts there, rather than moving it in slave_alloc / configure? Because... emn, well, I wanted to write "because it is tested later on in dc390_SRBdone:
if (pACB->scan_devices) pACB->DeviceCnt++;
", but then I checked, where else this DeviceCnt is used, and found only initialisation to 0, the increment above, no decrement, and a proc-output:
SPRINTF("Nr of attached devices: %i, Nr of DCBs: %i\n", pACB->DeviceCnt, pACB->DCBCnt);Whereas, DCBCnt is incremented on slave_alloc, decremented on slave_destroy and used in a couple more places. So, is it safe to assume that DeviceCnt is redundant and remove it in a next patch?... Then it might be already safe to move scan_devices as you suggest?
Quoted 3 lines
The other thing is that most calls to
dc390_findDCBcould probably be replaced with stroing the pDCB inscsi_device->hostdataonslave_alloc, but that could aswell be done in an incremental patch.
Ok, one more item for the todo list, when I start it...
Quoted 3 lines
In
dc390_init_oneyou don't callpci_disable_deviceon failure, best switch to goto for a single shared error path to avoid all these leaks.
Done. Actually, I copied this (and other) new function(s) from dc395x, so, they have this bug too... And, I asume, it has to be done in remove_one too, right?
Quoted 3 lines
Maybe also merge
dc390_initanddc390_init_one?Similarly I think
DC390_releaseshould be merged intodc390_remove_one.
Ok, 2 more items...
So, attached is version 2 of the patch.
Besides, there's a tiny trivial (and, hopefully, correct) patch to scsi_host.h, fixing the comment.
Thanks
Guennadi
---
Guennadi Liakhovetski
Index: include/scsi/scsi_host.h
===================================================================
RCS file: /usr/src/cvs/linux-2_6/include/scsi/scsi_host.h,v retrieving revision 1.1.1.3
scsi/scsi_host.h +2 -2
@@ -151,7 +151,7 @@* here then you will get a call to slave_configure(), then the * device will be used for however long it is kept around, then when * the device is removed from the system (or * possibly at reboot -* time), you will then get a call to slave_detach(). This is +* time), you will then get a call to slave_destroy(). This is * assuming you implement slave_configure and slave_destroy. * However, if you allocate memory and hang it off the device struct, * then you must implement the slave_destroy() routine at a minimum
@@ -185,7 +185,7 @@* specific setup basis... * 6. Return 0 on success, non-0 on error. The device will be marked * as offline on error so that no access will occur. If you return -* non-0, your slave_detach routine will never get called for this +* non-0, your slave_destroy routine will never get called for this * device, so don't leave any loose memory hanging around, clean * up after yourself before returning non-0 *
drivers/scsi/dc390.h renamed from linux-2.6.6/drivers/scsi/dc390.h +0 -1
@@ -33,7 +33,6 @@# define USE_NEW_EH #endif -static int DC390_detect (Scsi_Host_Template *psht);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);
drivers/scsi/scsiiom.c renamed from linux-2.6.6/drivers/scsi/scsiiom.c +12 -26
@@ -789,7 +789,7 @@/* read and eval received messages */ -void +static void dc390_MsgIn_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus) {PDCB pDCB = pACB->pActiveDCB;
@@ -948,7 +948,7 @@dc390_DataIO_Comm (pACB, pSRB,READ_DIRECTION ); } -void +static void dc390_CommandPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus) {PDCB pDCB;
@@ -989,7 +989,7 @@//DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); } -void +static void dc390_MsgOutPhase (PACB pACB,PSRB pSRB,PUCHAR psstatus) {UCHAR bval, i, cnt;
@@ -1097,7 +1097,7 @@ } -void +static void dc390_Disconnect (PACB pACB ) {PDCB pDCB;
@@ -1179,7 +1179,7 @@ } -void +static void dc390_Reselect (PACB pACB ) {PDCB pDCB;
@@ -1349,10 +1349,10 @@ }; -void +static void dc390_SRBdone (PACB pACB,PDCB pDCB,PSRB pSRB ) { -UCHAR bval, status, i, DCB_removed; +UCHAR bval, status, i;PSCSICMD pcmd;PSCSI_INQDATA ptr;PSGL ptr2;
@@ -1362,7 +1362,6 @@/* KG: Moved pci_unmap here */ dc390_pci_unmap (pSRB); - DCB_removed =0 ; status = pSRB->TargetStatus; ptr = (PSCSI_INQDATA ) (pcmd->request_buffer);if ( pcmd->use_sg )
@@ -1569,8 +1568,6 @@ (pcmd->sense_buffer[2] & 0xf) == ILLEGAL_REQUEST) || host_byte(pcmd->result) & DID_ERROR ) {/* device not present: remove */ -//dc390_Going_remove (pDCB, pSRB); -dc390_remove_dev (pACB, pDCB); DCB_removed =1 ;if ( (pcmd->device->id == pACB->pScsiHost->max_id -1 ) && ((pcmd->device->lun ==0 ) || (pcmd->device->lun == pACB->pScsiHost->max_lun -1 )) )
@@ -1582,24 +1579,14 @@if ( (pcmd->device->id == pACB->pScsiHost->max_id -1 ) && (pcmd->device->lun == pACB->pScsiHost->max_lun -1 ) ) pACB->scan_devices =END_SCAN ; -/* pACB->DeviceCnt++; */ /* Dev is added on INQUIRY */ } } } - -//if( pSRB->pcmd->cmnd[0] == INQUIRY && -// (host_byte(pcmd->result) == DID_OK || status_byte(pcmd->result) & CHECK_CONDITION) ) +if ( pcmd->cmnd[0 ] ==INQUIRY && (pcmd->result == (DID_OK <<16 ) ||status_byte (pcmd->result) &CHECK_CONDITION ) ) { -if ((ptr->DevType &SCSI_DEVTYPE ) ==TYPE_NODEV && !DCB_removed) - { -//printk ("DC390: Type = nodev! (%02i-%i)\n", pcmd->target, pcmd->lun); -/* device not present: remove */ -//dc390_Going_remove (pDCB, pSRB); -dc390_remove_dev (pACB, pDCB); DCB_removed =1 ; - } -else +if ((ptr->DevType &SCSI_DEVTYPE ) !=TYPE_NODEV ) {/* device found: add */ dc390_add_dev (pACB, pDCB, ptr);
@@ -1608,11 +1595,11 @@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; -if (!DCB_removed)dc390_Going_remove (pDCB, pSRB); +dc390_Going_remove (pDCB, pSRB);/* Add to free list */ dc390_Free_insert (pACB, pSRB);
@@ -1625,7 +1612,7 @@/* Remove all SRBs from Going list and inform midlevel */ -void +static void dc390_DoingSRB_Done (PACB pACB,PSCSICMD cmd ) {PDCB pDCB, pdcb;
@@ -1760,4 +1747,3 @@if ( pACB->pActiveDCB->pActiveSRB->SRBState & (SRB_START_ +SRB_MSGOUT ) )DC390_write8 (ScsiCmd,CLEAR_FIFO_CMD ); } -
drivers/scsi/tmscsim.c renamed from linux-2.6.6/drivers/scsi/tmscsim.c +151 -98
337 lines not on this page · raw message
Re: [PATCH] tmscsim: new interfaces
Quoted 16 lines · Guennadi Liakhovetski
Quoted 5 lines
Looks mostly goo to me, one thing I worry about is the complete removal of the
scan_deviceflag, I don't fully understand what it's supposed to do, but we should be able to always set in ->slave_alloc and then clear it in ->slave_configure when we know probing is over for this device.Right, thanks. I didn't understand at all what
scan_deviceswas doing there, so, I tried to preserve its semantics in the driver, and "just" overlooked its setting in dc390_SRBdone:-( But, wouldn't it be safer to just restore the relevant parts there, rather than moving it inslave_alloc/ configure? Because... emn, well, I wanted to write "because it is tested later on indc390_SRBdone:if (pACB->scan_devices) pACB->DeviceCnt++;", but then I checked, where else this DeviceCnt is used, and found only initialisation to 0, the increment above, no decrement, and a proc-output:
Quoted 6 lines
SPRINTF("Nr of attached devices: %i, Nr of DCBs: %i\n", pACB->DeviceCnt, pACB->DCBCnt);Whereas, DCBCnt is incremented on
slave_alloc, decremented onslave_destroyand used in a couple more places. So, is it safe to assume that DeviceCnt is redundant and remove it in a next patch?... Then it might be already safe to movescan_devicesas you suggest?
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.
Quoted 6 lines
Quoted 3 lines
In
dc390_init_oneyou don't callpci_disable_deviceon failure, best switch to goto for a single shared error path to avoid all these leaks.Done. Actually, I copied this (and other) new function(s) from dc395x, so, they have this bug too...
There's quite a lot drivers missing it, because it's not nessecary on most PCs.
Quoted 1 line
And, I asume, it has to be done in
remove_onetoo, right?
Yes.
Quoted 15 lines
RCS file:
/usr/src/cvs/linux-2_6/include/scsi/scsi_host.h,vretrieving revision 1.1.1.3
diff -u -r1.1.1.3scsi_host.hscsi/scsi_host.h +1
-1@@ -151,7 +151,7 @@* here then you will get a call to slave_configure(), then the * device will be used for however long it is kept around, then when * the device is removed from the system (or * possibly at reboot -* time), you will then get a call to slave_detach(). This is +* time), you will then get a call to slave_destroy(). This is * assuming you implement slave_configure and slave_destroy. * However, if you allocate memory and hang it off the device struct, * then you must implement the slave_destroy() routine at a minimum
scsi/scsi_host.h line 188
Quoted 5 lines
scsi/scsi_host.h +1
-1@@ -185,7 +185,7 @@* specific setup basis... * 6. Return 0 on success, non-0 on error. The device will be marked * as offline on error so that no access will occur. If you return -* non-0, your slave_detach routine will never get called for this +* non-0, your slave_destroy routine will never get called for this
This looks okay, but can you please send it to the list as a separate patch?
Rest of the patch also looks go to go in as-is, the additional items can be fixed in followup-patches.
Re: [PATCH] tmscsim: new interfaces
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Guennadi Liakhovetski
Whereas, DCBCnt is incremented on
slave_alloc, decremented onslave_destroyand used in a couple more places. So, is it safe to assume that DeviceCnt is redundant and remove it in a next patch?... Then it might be already safe to movescan_devicesas you suggest?
Quoted 5 lines
Looks like a way to go. I'm not sure what
scan_deviceis 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.
So, here's the first one - remove DeviceCnt.
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/scsiiom.c +0 -2
@@ -1302,7 +1302,6 @@if (pDCB == pACB->pDCBRunRobin) pACB->pDCBRunRobin = pDCB->pNextDCB;kfree (pDCB); pACB->DCBCnt--; -/* pACB->DeviceCnt--; */ };
@@ -1590,7 +1589,6 @@ {/* device found: add */ dc390_add_dev (pACB, pDCB, ptr); -if (pACB->scan_devices) pACB->DeviceCnt++; }if ( (pcmd->device->id == pACB->pScsiHost->max_id -1 ) && (pcmd->device->lun == pACB->pScsiHost->max_lun -1 ) )
drivers/scsi/tmscsim.c +1 -2
@@ -1734,7 +1734,6 @@ pACB->AdapterIndex = index; pACB->status =0 ; psh->this_id = dc390_eepromBuf[index][EE_ADAPT_SCSI_ID ]; - pACB->DeviceCnt =0 ; pACB->DCBCnt =0 ; pACB->TagMaxNum =2 << dc390_eepromBuf[index][EE_TAG_CMD_NUM ]; pACB->ACBFlag =0 ;
@@ -2089,7 +2088,7 @@SPRINTF (" Lost arbitrations %i, Sel. connected %i, Connected: %s\n" , pACB->SelLost, pACB->SelConn, pACB->Connected?"Yes" :"No" ); -SPRINTF ("Nr of attached devices: %i, Nr of DCBs: %i\n" , pACB->DeviceCnt, pACB->DCBCnt); +SPRINTF ("Nr of DCBs: %i\n" , pACB->DCBCnt);SPRINTF ("Map of attached LUNs: %02x %02x %02x %02x %02x %02x %02x %02x\n" , pACB->DCBmap[0 ], pACB->DCBmap[1 ], pACB->DCBmap[2 ], pACB->DCBmap[3 ], pACB->DCBmap[4 ], pACB->DCBmap[5 ], pACB->DCBmap[6 ], pACB->DCBmap[7 ]);
drivers/scsi/tmscsim.h +2 -9
@@ -196,10 +196,8 @@UCHAR SRBCount;UCHAR AdapterIndex;/*; nth Adapter this driver */ -UCHAR DeviceCnt;UCHAR DCBCnt; -/* 0x10: */ UCHAR TagMaxNum;UCHAR ACBFlag;UCHAR Gmode2;
@@ -213,13 +211,11 @@PSRB pFreeSRB;PSRB pTmpSRB; -/* 0x2c: */ UCHAR msgin123[4 ];UCHAR DCBmap[MAX_SCSI_ID ];UCHAR Connected;UCHAR pad; -/* 0x30: */ #if defined(USE_SPINLOCKS ) &&USE_SPINLOCKS >1 && (defined(CONFIG_SMP ) ||DEBUG_SPINLOCKS >0 )spinlock_t lock;#endif
@@ -230,20 +226,17 @@UCHAR Ignore_IRQ;/* Not used */ PDEVDECL1 ;/* Pointer to PCI cfg. space */ -/* 0x40/0x3c: */ +ULONG Cmds;UINT SelLost;UINT SelConn;UINT CmdInQ;UINT CmdOutOfSRB; -/* 0x54/0x50: */ struct timer_list Waiting_Timer; -/* 0x68/0x64: */ +DC390_SRB TmpSRB; -/* 0xcc/0xc8: */ DC390_SRB SRB_array[MAX_SRB_CNT ];/* 50 SRBs */ -/* 0xfa4/0xfa0: */ };typedef struct _ACB DC390_ACB , *PACB ;
Re: [PATCH] fix comment in scsi_host.h
In reply to Christoph HellwigQuoted 2 lines · Christoph Hellwig
Quoted 1 line · Guennadi Liakhovetski
diff -u -r1.1.1.3
scsi_host.h
...
Quoted 1 line
This looks okay, but can you please send it to the list as a separate patch?
Attached.
Thanks
Guennadi
---
Guennadi Liakhovetski
include/scsi/scsi_host.h +2 -2
@@ -151,7 +151,7 @@* here then you will get a call to slave_configure(), then the * device will be used for however long it is kept around, then when * the device is removed from the system (or * possibly at reboot -* time), you will then get a call to slave_detach(). This is +* time), you will then get a call to slave_destroy(). This is * assuming you implement slave_configure and slave_destroy. * However, if you allocate memory and hang it off the device struct, * then you must implement the slave_destroy() routine at a minimum
@@ -185,7 +185,7 @@* specific setup basis... * 6. Return 0 on success, non-0 on error. The device will be marked * as offline on error so that no access will occur. If you return -* non-0, your slave_detach routine will never get called for this +* non-0, your slave_destroy routine will never get called for this * device, so don't leave any loose memory hanging around, clean * up after yourself before returning non-0 *
Re: [PATCH] tmscsim: new interfaces
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Looks like a way to go. I'm not sure what
scan_deviceis 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:-)). Please consider. The patch also contains some more clean-up. Don't know, if you, James, would prefer it as a separate patch, or left alone altogether. Those minor details are disturbing the eye, but are, perhaps, not important enough to bother you with a separate patch:-) But if you want it separate - no problem, will do that.
As usual, tested on my AM53C974.
Please, consider.
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/dc390.h +1 -13
@@ -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 */
drivers/scsi/scsiiom.c +21 -41
197 lines not on this page · raw message
drivers/scsi/tmscsim.c +19 -14
@@ -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,8 +1034,8 @@* 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 -* return 1 if command cannot be queued (queue full) +* 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 @@/* 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 @@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 @@ {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,
drivers/scsi/tmscsim.h +0 -2
@@ -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 */
Re: [PATCH] tmscsim: new interfaces
Quoted 17 lines · Guennadi Liakhovetski
Quoted 5 lines · Christoph Hellwig
Looks like a way to go. I'm not sure what
scan_deviceis 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_deviceto slave_alloc/_configure/_destroy, as you suggested (to be precise, as I understood your suggestion:-)). Please consider. The patch also contains some more clean-up. Don't know, if you, James, would prefer it as a separate patch, or left alone altogether. Those minor details are disturbing the eye, but are, perhaps, not important enough to bother you with a separate patch:-) But if you want it separate - no problem, will do that.
Quoted 1 line
As usual, tested on my AM53C974.
Looks good to me.
Re: [PATCH] tmscsim: new interfaces
In reply to Guennadi LiakhovetskiQuoted 8 lines · Guennadi Liakhovetski
Attached is a patch, that moves
scan_deviceto slave_alloc/_configure/_destroy, as you suggested (to be precise, as I understood your suggestion:-)). Please consider. The patch also contains some more clean-up. Don't know, if you, James, would prefer it as a separate patch, or left alone altogether. Those minor details are disturbing the eye, but are, perhaps, not important enough to bother you with a separate patch:-) But if you want it separate - no problem, will do that.
Well, I'll leave that up to you. It is nice clearly to separate different updates in different patches ... but I have drivers that go into the tree containing a bunch of different changes with a single comment like "update to version xxx", so I don't insist on this.
James
Re: [PATCH] tmscsim: Store pDCB in device->hostdata
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
The other thing is that most calls to
dc390_findDCBcould probably be replaced with stroing the pDCB inscsi_device->hostdataonslave_alloc, but that could aswell be done in an incremental patch.
Done in the attached patch. Tested as usual and a bit harder.
BTW, just managed to re-organise my test-system to allow modular tmscsim. Tested - works too.
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/tmscsim.c +8 -10
@@ -1042,7 +1042,7 @@static int DC390_queue_command (Scsi_Cmnd *cmd,void (* done)(Scsi_Cmnd *)) { -PDCB pDCB; +PDCB pDCB = (PDCB ) cmd->device->hostdata;PSRB pSRB;PACB pACB = (PACB ) cmd->device->host->hostdata;
@@ -1059,8 +1059,6 @@ goto fail; } - pDCB =dc390_findDCB (pACB, cmd->device->id, cmd->device->lun); -/* Should it be: BUG_ON(!pDCB); ? */ if (!pDCB)
@@ -1286,7 +1284,7 @@static int DC390_abort (Scsi_Cmnd *cmd) { -PDCB pDCB; +PDCB pDCB = (PDCB ) cmd->device->hostdata;PSRB pSRB, psrb;UINT count, i;int status;
@@ -1296,7 +1294,6 @@printk ("DC390: Abort command (pid %li, Device %02i-%02i)\n" , cmd->pid, cmd->device->id, cmd->device->lun); - pDCB =dc390_findDCB (pACB, cmd->device->id, cmd->device->lun);if ( !pDCB ) goto NOT_RUN;/* Added 98/07/02 KG */
@@ -1909,6 +1906,7 @@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 ; }
@@ -1924,7 +1922,7 @@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);; +PDCB pDCB = (PDCB ) scsi_device->hostdata; pACB->scan_devices =0 ;if (pDCB !=NULL )dc390_remove_dev (pACB, pDCB);
@@ -1978,7 +1976,7 @@if (!scsi_host) goto nomem; - pACB = (PACB )scsi_host->hostdata; + pACB = (PACB ) scsi_host->hostdata;if (dc390_init (scsi_host, io_port, irq, dev, dc390_adapterCnt)) { ret = -EBUSY ;
@@ -2180,7 +2178,7 @@static int dc390_shutdown (struct Scsi_Host *host) {UCHAR bval; -PACB pACB = (PACB )(host->hostdata); +PACB pACB = (PACB ) host->hostdata;/* pACB->soft_reset(host); */
@@ -2200,7 +2198,7 @@static void dc390_freeDCBs (struct Scsi_Host *host) {PDCB pDCB, nDCB; -PACB pACB = (PACB )(host->hostdata); +PACB pACB = (PACB ) host->hostdata; pDCB = pACB->pLinkDCB;if (!pDCB)return ;
@@ -2219,7 +2217,7 @@static int DC390_release (struct Scsi_Host *host) {DC390_IFLAGS ; -PACB pACB = (PACB )(host->hostdata); +PACB pACB = (PACB ) host->hostdata;DC390_LOCK_IO (host);
Re: [PATCH] tmscsim: Store pDCB in device->hostdata
Quoted 10 lines · Guennadi Liakhovetski
Quoted 3 lines · Christoph Hellwig
The other thing is that most calls to
dc390_findDCBcould probably be replaced with stroing the pDCB inscsi_device->hostdataonslave_alloc, but that could aswell be done in an incremental patch.Done in the attached patch. Tested as usual and a bit harder.
BTW, just managed to re-organise my test-system to allow modular tmscsim. Tested - works too.
Patch looks good to me.
Re: [PATCH] tmscsim: init / exit cleanup
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
these leaks. Maybe also merge
dc390_initanddc390_init_one?Similarly I think
DC390_releaseshould be merged intodc390_remove_one.
Attached. Also fixed some __init / __devinit and __exit / __devexit attributes. Although, would be good to have something like
#ifdef CONFIG_HOTPLUG_PCI
#define __pcidevinit
#define __pcidevinitdata
#define __pcidevexit
#define __pcidevexitdata
#else
#define __pcidevinit __init
#define __pcidevinitdata __initdata
#define __pcidevexit __exit
#define __pcidevexitdata __exitdata
#endif
I don't think there are any pcmcia / usb / ieee1394 / ... tmscsim adapters out there?
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/tmscsim.c +104 -150
@@ -306,10 +306,6 @@#include "tmscsim.h" -#ifndef __init -# define __init -#endif -static UCHAR dc390_StartSCSI (PACB pACB,PDCB pDCB,PSRB pSRB );static void dc390_DataOut_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus);static void dc390_DataIn_0 (PACB pACB,PSRB pSRB,PUCHAR psstatus);
@@ -343,8 +339,6 @@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);
@@ -433,7 +427,7 @@**********************************************************************/ -static void __init dc390_EnDisableCE (UCHAR mode,PDEVDECL ,PUCHAR regval ) +static void __devinit dc390_EnDisableCE (UCHAR mode,PDEVDECL ,PUCHAR regval ) {UCHAR bval;
@@ -450,7 +444,7 @@/* Override EEprom values with explicitly set values */ -static void __init dc390_EEprom_Override (UCHAR index) +static void __devinit dc390_EEprom_Override (UCHAR index) {PUCHAR ptr;UCHAR id;
@@ -477,7 +471,7 @@ }/* Handle "-1" case */ -static void __init dc390_check_for_safe_settings (void ) +static void __devinit dc390_check_for_safe_settings (void ) {if (tmscsim[0 ] ==-1 || tmscsim[0 ] >15 )/* modules-2.0.0 passes -1 as string */ {
@@ -500,7 +494,7 @@ , 3 /* 16 Tags per LUN */, 1 /* s delay after Reset */ };/* Copy defaults over set values where missing */ -static void __init dc390_fill_with_defaults (void ) +static void __devinit dc390_fill_with_defaults (void ) {int i; PARSEDEBUG(printk(KERN_INFO "DC390: setup %08x %08x %08x %08x %08x %08x\n", tmscsim[0],\
@@ -517,6 +511,7 @@if (tmscsim[5 ] >180 ) tmscsim[5 ] =180 ; } +#ifndef MODULE /* Override defaults on cmdline: * tmscsim: AdaptID, MaxSpeed (Index), DevMode (Bitmapped), AdaptMode (Bitmapped) */
@@ -536,11 +531,11 @@/* dc390_checkparams (); */ return 1; } -#ifndef MODULE +__setup ("tmscsim=" , dc390_setup);#endif -static void __init dc390_EEpromOutDI (PDEVDECL ,PUCHAR regval,UCHAR Carry ) +static void __devinit dc390_EEpromOutDI (PDEVDECL ,PUCHAR regval,UCHAR Carry ) {UCHAR bval;
@@ -561,7 +556,7 @@ } -static UCHAR __init dc390_EEpromInDO (PDEVDECL ) +static UCHAR __devinit dc390_EEpromInDO (PDEVDECL ) {UCHAR bval;
@@ -577,7 +572,7 @@ } -static USHORT __init dc390_EEpromGetData1 (PDEVDECL ) +static USHORT __devinit dc390_EEpromGetData1 (PDEVDECL ) {UCHAR i;UCHAR carryFlag;
@@ -594,7 +589,7 @@ } -static void __init dc390_Prepare (PDEVDECL ,PUCHAR regval,UCHAR EEpromCmd ) +static void __devinit dc390_Prepare (PDEVDECL ,PUCHAR regval,UCHAR EEpromCmd ) {UCHAR i,j;UCHAR carryFlag;
@@ -610,7 +605,7 @@ } -static void __init dc390_ReadEEprom (PDEVDECL ,PUSHORT ptr) +static void __devinit dc390_ReadEEprom (PDEVDECL ,PUSHORT ptr) {UCHAR regval,cmd;UCHAR i;
@@ -626,13 +621,13 @@ } -static void __init dc390_interpret_delay (UCHAR index) +static void __devinit dc390_interpret_delay (UCHAR index) {char interpd [] = {1 ,3 ,5 ,10 ,16 ,30 ,60 ,120 }; dc390_eepromBuf[index][EE_DELAY ] = interpd [dc390_eepromBuf[index][EE_DELAY ]]; } -static UCHAR __init dc390_CheckEEpromCheckSum (PDEVDECL ,UCHAR index ) +static UCHAR __devinit dc390_CheckEEpromCheckSum (PDEVDECL ,UCHAR index ) {UCHAR i;char EEbuf[128 ];
@@ -1684,7 +1679,7 @@* io_port, Irq, index: Resources and adapter index ***********************************************************************/ -static void __init dc390_initACB (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) +static void __devinit dc390_initACB (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) {PACB pACB;UCHAR i;
@@ -1756,7 +1751,7 @@* Outputs: 0 on success, -1 on error ***********************************************************************/ -static int __init dc390_initAdapter (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) +static int __devinit dc390_initAdapter (PSH psh,ULONG io_port,UCHAR Irq,UCHAR index) {PACB pACB, pACB2;UCHAR dstate;
@@ -1827,65 +1822,7 @@ } -/*********************************************************************** -* Function : static int DC390_init (struct Scsi_Host *host, ...) -* -* Purpose : initialize the internal structures for a given SCSI host -* -* Inputs : host - pointer to this host adapter's structure -* io_port - IO ports mapped to this adapter -* irq - IRQ assigned to this adpater -* struct pci_dev - PCI access handle -* index - Adapter index -* -* Outputs: 0 on success, -1 on error -* -* Note: written in capitals, because the locking is only done here, -* not in DC390_detect, called from outside -***********************************************************************/ -static int __init dc390_init (PSH psh,unsigned long io_port,u8 irq,struct pci_dev *pdev,UCHAR index) -{ -PACB pACB; - -if (dc390_CheckEEpromCheckSum (PDEV , index)) - { -int speed; - dc390_adapname ="AM53C974" ; -printk (KERN_INFO "DC390_init: No EEPROM found! Trying default settings ...\n" ); -dc390_check_for_safe_settings (); -dc390_fill_with_defaults (); -dc390_EEprom_Override (index); - speed = dc390_clock_speed[tmscsim[1 ]]; -printk (KERN_INFO "DC390: Used defaults: AdaptID=%i, SpeedIdx=%i (%i.%i MHz)," -" DevMode=0x%02x, AdaptMode=0x%02x, TaggedCmnds=%i (%i), DelayReset=%is\n" , - tmscsim[0 ], tmscsim[1 ], speed/10 , speed%10 , - (UCHAR )tmscsim[2 ], (UCHAR )tmscsim[3 ], tmscsim[4 ],2 << (tmscsim[4 ]), tmscsim[5 ]); - } -else - { -dc390_check_for_safe_settings (); -dc390_EEprom_Override (index); - } - pACB = (PACB ) psh->hostdata; - -DEBUG0 (printk (KERN_INFO "DC390: pSH = %8x, Index %02i\n" , (UINT ) psh, index)); - -dc390_initACB ( psh, io_port, irq, index ); - -PDEVSET ; - -if ( !dc390_initAdapter ( psh, io_port, irq, index ) ) - { -return (0 ); - } -else - { -scsi_unregister ( psh ); -return (-1 ); - } -} - -static void __init dc390_set_pci_cfg (PDEVDECL ) +static void __devinit dc390_set_pci_cfg (PDEVDECL ) {USHORT cmd;PCI_READ_CONFIG_WORD (PDEV ,PCI_COMMAND , &cmd);
@@ -1978,7 +1915,31 @@ pACB = (PACB ) scsi_host->hostdata; -if (dc390_init (scsi_host, io_port, irq, dev, dc390_adapterCnt)) { +if (dc390_CheckEEpromCheckSum (dev, dc390_adapterCnt)) { +int speed; + dc390_adapname ="AM53C974" ; +printk (KERN_INFO "DC390_init: No EEPROM found! Trying default settings ...\n" ); +dc390_check_for_safe_settings (); +dc390_fill_with_defaults (); +dc390_EEprom_Override (dc390_adapterCnt); + speed = dc390_clock_speed[tmscsim[1 ]]; +printk (KERN_INFO "DC390: Used defaults: AdaptID=%i, SpeedIdx=%i (%i.%i MHz)," +" DevMode=0x%02x, AdaptMode=0x%02x, TaggedCmnds=%i (%i), DelayReset=%is\n" , + tmscsim[0 ], tmscsim[1 ], speed/10 , speed%10 , + (UCHAR )tmscsim[2 ], (UCHAR )tmscsim[3 ], tmscsim[4 ],2 << (tmscsim[4 ]), tmscsim[5 ]); + }else { +dc390_check_for_safe_settings (); +dc390_EEprom_Override (dc390_adapterCnt); + } + +DEBUG0 (printk (KERN_INFO "DC390: pSH = %8x, Index %02i\n" , (UINT ) scsi_host, dc390_adapterCnt)); + +dc390_initACB (scsi_host, io_port, irq, dc390_adapterCnt); + + pACB->pdev = dev; + +if (dc390_initAdapter (scsi_host, io_port, irq, dc390_adapterCnt)) { +scsi_unregister (scsi_host); ret = -EBUSY ; goto busy; }
@@ -2005,6 +1966,52 @@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. *
@@ -2013,9 +2020,25 @@ static void __devexit dc390_remove_one(struct pci_dev *dev) {struct Scsi_Host *scsi_host =pci_get_drvdata (dev); +DC390_IFLAGS ; +PACB pACB = (PACB ) scsi_host->hostdata;scsi_remove_host (scsi_host); -DC390_release (scsi_host); + +DC390_LOCK_IO (scsi_host); + +/* 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); + } + +release_region (scsi_host->io_port, scsi_host->n_io_port); +dc390_freeDCBs (scsi_host); +DC390_UNLOCK_IO (scsi_host); +pci_disable_device (dev);scsi_host_put (scsi_host);pci_set_drvdata (dev,NULL );
@@ -2166,75 +2189,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" ,
Re: [PATCH] tmscsim: init / exit cleanup
Quoted 21 lines · Guennadi Liakhovetski
Quoted 3 lines · Christoph Hellwig
these leaks. Maybe also merge
dc390_initanddc390_init_one?Similarly I think
DC390_releaseshould be merged intodc390_remove_one.Attached. Also fixed some
__init/__devinitand__exit/__devexitattributes. Although, would be good to have something like#ifdef
CONFIG_HOTPLUG_PCI
#define__pcidevinit
#define__pcidevinitdata
#define__pcidevexit
#define__pcidevexitdata
#else
#define__pcidevinit__init
#define__pcidevinitdata__initdata
#define__pcidevexit__exit
#define__pcidevexitdata__exitdata
#endif
Quoted 2 lines
I don't think there are any pcmcia / usb / ieee1394 / ... tmscsim adapters out there?
This has been though out a bit but not considered worthwile. And to actually work it would have to be for all the kernel because you could get problems over the module boundary otherwise.
Re: [PATCH] tmscsim: init / exit cleanup
Quoted 14 lines · Christoph Hellwig
Quoted 12 lines · Guennadi Liakhovetski
#ifdef
CONFIG_HOTPLUG_PCI
#define__pcidevinit
#define__pcidevinitdata
#define__pcidevexit
#define__pcidevexitdata
#else
#define__pcidevinit__init
#define__pcidevinitdata__initdata
#define__pcidevexit__exit
#define__pcidevexitdata__exitdata
#endif
Quoted 3 lines
This has been though out a bit but not considered worthwile. And to actually work it would have to be for all the kernel because you could get problems over the module boundary otherwise.
Sorry, do you have a reference or remember at least apporoximatly when and where the discussion took place? I don't quite understand your arguments. We do have __dev{init,exit,...} macros, do they have "problems over the module boundary"? If yes - they want to be solved, right? If not - why would equally defined __pcidev* have problems? You mean using __devinit in a module has probles? The advantages of the above are obvious: there are many more HOTPLUG-enabled systems, than PCI_HOTPLUG-enabled ones. And a reasonable number of drivers, that serve devices only over PCI. How much would it add to "Freeing init memory" in an "average" configuration?
Thanks
Guennadi
---
Guennadi Liakhovetski
Re: [PATCH] tmscsim: 64-bit cleanup
In reply to James BottomleyQuoted 12 lines · James Bottomley
Quoted 10 lines · Guennadi Liakhovetski
Ok, here comes the first one. I chose this one because it fixes an actual bug in the driver. This bug was (partially) introduced by myself when porting to 2.6. Partly the reason was that I disliked using function-like macros as lvalues:
sg_dma_address(x)= ...sg_dma_len(x)= ...[OT] wouldn't it be better to introduce some macros like set_sg_dma_{address|len}(x, y)?
Quoted 6 lines
Actually, no. struct scatterlist is for the OS platform to use to characterise DMA; it's actually a private structure entirely within the gift of the architecture to define. It usually contains bits of extraneous data that the driver never sees. The driver should convert struct scatterlist into its own version of the scatterlist that needs feeding to the hardware rather than try and use struct scatterlist.
Well, I don't quite understand. What about this code in block/ll_rw_blk.c:
sg[nsegs].page = bvec->bv_page; sg[nsegs].length = nbytes; sg[nsegs].offset = bvec->bv_offset;
? So, looks like all architectures should implement these fields in struct scatterlist, and use them in map_sg. So, isn't it safe to use them from drivers in a similar way (see patch attached).
Quoted 2 lines
You'll find that lvalue use of
sg_dma_len()fails on some platforms that actually compute it from page/offset values in the scatterlist.
Actually, I found only 1 platform, where sg_dma_address() cannot be used as an lvalue:
include/asm-sh/pci.h:#define sg_dma_address(sg) (virt_to_bus((sg)->dma_address))
Quoted 1 line
Could you (eventually) update tmscsim not to use it?
Don't know if this is correct, but the most consistent way to do it, I was able to find, was to reproduce the code above for an sg with 1 element and call pci_map_sg() instead of pci_map_page, thus avoiding assignments like
sg_dma_len(sg) = ...;sg_dma_address(sg) = ...;
There's still one use of sg_dma_len() as an lvalue left in scsiiom.c on the RESTORE_PTR path. But (1) at the moment it seems to be safe on all platforms, (2) I am very suspicious about that code any way and would appreciate any advise as to if that code is correct, and, if not, what should be done there.
Emn, ok, in case it is already compalsory, here goes:
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/tmscsim.c +32 -23
@@ -919,18 +919,8 @@Scsi_Cmnd *pcmd = pSRB->pcmd;struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;dc390_cmd_scp_t * cmdp = ((dc390_cmd_scp_t *)(&pcmd->SCp)); -/* Map sense buffer */ -if (pSRB->SRBFlag &AUTO_REQSENSE ) { -sg_dma_address (&pSRB->Segmentx) = cmdp->saved_dma_handle = -pci_map_page (pdev,virt_to_page (pcmd->sense_buffer), - (unsigned long )pcmd->sense_buffer & ~PAGE_MASK ,sizeof (pcmd->sense_buffer), -DMA_FROM_DEVICE ); -sg_dma_len (&pSRB->Segmentx) =sizeof (pcmd->sense_buffer); - pSRB->SGcount =1 ; - pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx; -DEBUG1 (printk ("%s(): Mapped sense buffer %p at %x\n" , __FUNCTION__, pcmd->sense_buffer, cmdp->saved_dma_handle)); -/* Make SG list */ - }else if (pcmd->use_sg) { +/* Map SG list */ +if (pcmd->use_sg) { pSRB->pSegmentList = (PSGL ) pcmd->request_buffer; pSRB->SGcount = pci_map_sg(pdev, pSRB->pSegmentList, pcmd->use_sg,
@@ -938,18 +928,37 @@/* TODO: error handling */ if (!pSRB->SGcount) error =1 ; -DEBUG1 (printk ("%s(): Mapped SG %p with %d (%d) elements\n" , __FUNCTION__, pcmd->request_buffer, pSRB->SGcount, pcmd->use_sg)); -/* Map single segment */ - }else if (pcmd->request_buffer && pcmd->request_bufflen) { -sg_dma_address (&pSRB->Segmentx) = cmdp->saved_dma_handle = -pci_map_page (pdev,virt_to_page (pcmd->request_buffer), - (unsigned long )pcmd->request_buffer & ~PAGE_MASK , - pcmd->request_bufflen,scsi_to_pci_dma_dir (pcmd->sc_data_direction)); +DEBUG1 (printk ("%s(): Mapped SG %p with %d (%d) elements\n" ,\ + __FUNCTION__, pcmd->request_buffer, pSRB->SGcount, pcmd->use_sg)); + }else if ((pSRB->SRBFlag &AUTO_REQSENSE ) || (pcmd->request_buffer && pcmd->request_bufflen)) { +void *addr; +unsigned long length; +int dir; + +if (pSRB->SRBFlag &AUTO_REQSENSE ) { +/* Map sense buffer */ + addr = pcmd->sense_buffer; + length =sizeof (pcmd->sense_buffer); + dir =DMA_FROM_DEVICE ; +DEBUG1 (printk ("%s(): Mapped sense buffer %p" , __FUNCTION__, pcmd->sense_buffer)); + }else { +/* Map single segment */ + addr = pcmd->request_buffer; + length = pcmd->request_bufflen; + dir =scsi_to_pci_dma_dir (pcmd->sc_data_direction); +DEBUG1 (printk ("%s(): Mapped request buffer %p" , __FUNCTION__, pcmd->request_buffer)); + } +memset (&pSRB->Segmentx,0 ,sizeof (struct scatterlist )); + pSRB->Segmentx.page =virt_to_page (addr); + pSRB->Segmentx.length = length; + pSRB->Segmentx.offset = (unsigned long )addr & ~PAGE_MASK ; + pSRB->pSegmentList = &pSRB->Segmentx; + pSRB->SGcount =pci_map_sg (pdev, &pSRB->Segmentx,1 , dir); + cmdp->saved_dma_handle =sg_dma_address (&pSRB->Segmentx); +DEBUG1 (printk (" at %x\n" , cmdp->saved_dma_handle));/* TODO: error handling */ -sg_dma_len (&pSRB->Segmentx) = pcmd->request_bufflen; - pSRB->SGcount =1 ; - pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx; -DEBUG1 (printk ("%s(): Mapped request buffer %p at %x\n" , __FUNCTION__, pcmd->request_buffer, cmdp->saved_dma_handle)); +if (pSRB->SGcount !=1 ) + error =1 ;/* No mapping !? */ }else pSRB->SGcount =0 ;
Re: [PATCH] tmscsim: 64-bit cleanup
Quoted 2 lines · Guennadi Liakhovetski
scatterlist, and use them in
map_sg. So, isn't it safe to use them from drivers in a similar way (see patch attached).
Ooops, forgot to modify the unmapping path. New version attached (I'm looking forward to getting hold of the new version of SubmittingPatches, meanwhile, I guess, I have to sign-off for it again)
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/tmscsim.c +44 -34
@@ -919,18 +919,8 @@Scsi_Cmnd *pcmd = pSRB->pcmd;struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;dc390_cmd_scp_t * cmdp = ((dc390_cmd_scp_t *)(&pcmd->SCp)); -/* Map sense buffer */ -if (pSRB->SRBFlag &AUTO_REQSENSE ) { -sg_dma_address (&pSRB->Segmentx) = cmdp->saved_dma_handle = -pci_map_page (pdev,virt_to_page (pcmd->sense_buffer), - (unsigned long )pcmd->sense_buffer & ~PAGE_MASK ,sizeof (pcmd->sense_buffer), -DMA_FROM_DEVICE ); -sg_dma_len (&pSRB->Segmentx) =sizeof (pcmd->sense_buffer); - pSRB->SGcount =1 ; - pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx; -DEBUG1 (printk ("%s(): Mapped sense buffer %p at %x\n" , __FUNCTION__, pcmd->sense_buffer, cmdp->saved_dma_handle)); -/* Make SG list */ - }else if (pcmd->use_sg) { +/* Map SG list */ +if (pcmd->use_sg) { pSRB->pSegmentList = (PSGL ) pcmd->request_buffer; pSRB->SGcount = pci_map_sg(pdev, pSRB->pSegmentList, pcmd->use_sg,
@@ -938,18 +928,37 @@/* TODO: error handling */ if (!pSRB->SGcount) error =1 ; -DEBUG1 (printk ("%s(): Mapped SG %p with %d (%d) elements\n" , __FUNCTION__, pcmd->request_buffer, pSRB->SGcount, pcmd->use_sg)); -/* Map single segment */ - }else if (pcmd->request_buffer && pcmd->request_bufflen) { -sg_dma_address (&pSRB->Segmentx) = cmdp->saved_dma_handle = -pci_map_page (pdev,virt_to_page (pcmd->request_buffer), - (unsigned long )pcmd->request_buffer & ~PAGE_MASK , - pcmd->request_bufflen,scsi_to_pci_dma_dir (pcmd->sc_data_direction)); +DEBUG1 (printk ("%s(): Mapped SG %p with %d (%d) elements\n" ,\ + __FUNCTION__, pcmd->request_buffer, pSRB->SGcount, pcmd->use_sg)); + }else if ((pSRB->SRBFlag &AUTO_REQSENSE ) || (pcmd->request_buffer && pcmd->request_bufflen)) { +void *addr; +unsigned long length; +int dir; + +if (pSRB->SRBFlag &AUTO_REQSENSE ) { +/* Map sense buffer */ + addr = pcmd->sense_buffer; + length =sizeof (pcmd->sense_buffer); + dir =DMA_FROM_DEVICE ; +DEBUG1 (printk ("%s(): Mapped sense buffer %p" , __FUNCTION__, pcmd->sense_buffer)); + }else { +/* Map single segment */ + addr = pcmd->request_buffer; + length = pcmd->request_bufflen; + dir =scsi_to_pci_dma_dir (pcmd->sc_data_direction); +DEBUG1 (printk ("%s(): Mapped request buffer %p" , __FUNCTION__, pcmd->request_buffer)); + } +memset (&pSRB->Segmentx,0 ,sizeof (struct scatterlist )); + pSRB->Segmentx.page =virt_to_page (addr); + pSRB->Segmentx.length = length; + pSRB->Segmentx.offset = (unsigned long )addr & ~PAGE_MASK ; + pSRB->pSegmentList = &pSRB->Segmentx; + pSRB->SGcount =pci_map_sg (pdev, &pSRB->Segmentx,1 , dir); + cmdp->saved_dma_handle =sg_dma_address (&pSRB->Segmentx); +DEBUG1 (printk (" at %x\n" , cmdp->saved_dma_handle));/* TODO: error handling */ -sg_dma_len (&pSRB->Segmentx) = pcmd->request_bufflen; - pSRB->SGcount =1 ; - pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx; -DEBUG1 (printk ("%s(): Mapped request buffer %p at %x\n" , __FUNCTION__, pcmd->request_buffer, cmdp->saved_dma_handle)); +if (pSRB->SGcount !=1 ) + error =1 ;/* No mapping !? */ }else pSRB->SGcount =0 ;
@@ -963,20 +972,21 @@struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;dc390_cmd_scp_t * cmdp = ((dc390_cmd_scp_t *)(&pcmd->SCp)); -if (pSRB->SRBFlag) { -pci_unmap_page (pdev, cmdp->saved_dma_handle, -sizeof (pcmd->sense_buffer),DMA_FROM_DEVICE ); -DEBUG1 (printk ("%s(): Unmapped sense buffer at %x\n" , __FUNCTION__, cmdp->saved_dma_handle)); - }else if (pcmd->use_sg) { +if (pcmd->use_sg) {pci_unmap_sg (pdev, pcmd->request_buffer, pcmd->use_sg,scsi_to_pci_dma_dir (pcmd->sc_data_direction));DEBUG1 (printk ("%s(): Unmapped SG at %p with %d elements\n" , __FUNCTION__, pcmd->request_buffer, pcmd->use_sg)); - }else if (pcmd->request_buffer && pcmd->request_bufflen) { -pci_unmap_page (pdev, - cmdp->saved_dma_handle, - pcmd->request_bufflen, -scsi_to_pci_dma_dir (pcmd->sc_data_direction)); -DEBUG1 (printk ("%s(): Unmapped request buffer at %x\n" , __FUNCTION__, cmdp->saved_dma_handle)); + }else if (pSRB->SRBFlag || (pcmd->request_buffer && pcmd->request_bufflen)) { +int dir; + +if (pSRB->SRBFlag) { + dir =DMA_FROM_DEVICE ; +DEBUG1 (printk ("%s(): Unmapped sense buffer at %x\n" , __FUNCTION__, cmdp->saved_dma_handle)); + }else { + dir =scsi_to_pci_dma_dir (pcmd->sc_data_direction); +DEBUG1 (printk ("%s(): Unmapped request buffer at %x\n" , __FUNCTION__, cmdp->saved_dma_handle)); + } +pci_unmap_sg (pdev, &pSRB->Segmentx,1 , dir); } }
Re: [PATCH] tmscsim: 64-bit cleanup
In reply to Guennadi LiakhovetskiQuoted 20 lines · Guennadi Liakhovetski
Quoted 12 lines · James Bottomley
Quoted 10 lines · Guennadi Liakhovetski
Ok, here comes the first one. I chose this one because it fixes an actual bug in the driver. This bug was (partially) introduced by myself when porting to 2.6. Partly the reason was that I disliked using function-like macros as lvalues:
sg_dma_address(x)= ...sg_dma_len(x)= ...[OT] wouldn't it be better to introduce some macros like set_sg_dma_{address|len}(x, y)?
Quoted 6 lines
Actually, no. struct scatterlist is for the OS platform to use to characterise DMA; it's actually a private structure entirely within the gift of the architecture to define. It usually contains bits of extraneous data that the driver never sees. The driver should convert struct scatterlist into its own version of the scatterlist that needs feeding to the hardware rather than try and use struct scatterlist.
Quoted 7 lines
Well, I don't quite understand. What about this code in
block/ll_rw_blk.c:sg[nsegs].page = bvec->bv_page; sg[nsegs].length = nbytes; sg[nsegs].offset = bvec->bv_offset;? So, looks like all architectures should implement these fields in struct scatterlist, and use them in
map_sg. So, isn't it safe to use them from drivers in a similar way (see patch attached).
No.
struct scatterlist is defined by the platform in two halves: the block side, which uses the three members you list above, and which, as you say, all architectures are required to provide and the platform side which define extra elements but use the macro accessors sg_dma_len() and sg_dma_address().
However, if you tamper with the block side of this, you'll loose idempotence (the property that dma_map_sg()->dma_unmap_sg()->dma_map_sg() works). Without this none of the retryable error paths will work.
You should simply treat the scatterlist as an information providing opaque structure you examine with the provided accessors. If you try to alter it, you'll get into trouble with the platform layer, the block layer or both.
James
Re: [PATCH] tmscsim: 64-bit cleanup
Quoted 17 lines · James Bottomley
Quoted 7 lines · Guennadi Liakhovetski
Well, I don't quite understand. What about this code in
block/ll_rw_blk.c:sg[nsegs].page = bvec->bv_page; sg[nsegs].length = nbytes; sg[nsegs].offset = bvec->bv_offset;? So, looks like all architectures should implement these fields in struct scatterlist, and use them in
map_sg. So, isn't it safe to use them from drivers in a similar way (see patch attached).No.
struct scatterlist is defined by the platform in two halves: the block side, which uses the three members you list above, and which, as you say, all architectures are required to provide and the platform side which define extra elements but use the macro accessors
sg_dma_len()andsg_dma_address().
Quoted 4 lines
However, if you tamper with the block side of this, you'll loose idempotence (the property that dma_map_sg()->dma_unmap_sg()->dma_map_sg() works). Without this none of the retryable error paths will work.
Thanks for replies and explanations, James! But could you, please, just explain a bit more - what and how do I break with this patch? I just use a driver-private scatterlist struct (SRB.Segmentx) to set up a single-segment sg-list, and call pci_map_sg() on it. If I do it wrong - it could be fixed. But why it is bad in principle? Advantages - no need to check if sg is used for this particular command throughout the code.
But no problem. I'll redo the patch without private sg.
Thanks
Guennadi
---
Guennadi Liakhovetski
Re: [PATCH] tmscsim: 64-bit cleanup
Quoted 8 lines · Guennadi Liakhovetski
Thanks for replies and explanations, James! But could you, please, just explain a bit more - what and how do I break with this patch? I just use a driver-private scatterlist struct (SRB.Segmentx) to set up a single-segment sg-list, and call
pci_map_sg()on it. If I do it wrong - it could be fixed. But why it is bad in principle? Advantages - no need to check if sg is used for this particular command throughout the code.But no problem. I'll redo the patch without private sg.
Actually, I haven't looked at the patch yet. I was just answering the question in the mail which I assumed was "can I alter these three fields?" to which the answer is "no". If the question is "can I read these fields directly" the answer's yes.
James
Re: [PATCH] tmscsim: 64-bit cleanup
Quoted 8 lines · James Bottomley
Quoted 7 lines · Guennadi Liakhovetski
Thanks for replies and explanations, James! But could you, please, just explain a bit more - what and how do I break with this patch? I just use a driver-private scatterlist struct (SRB.Segmentx) to set up a single-segment sg-list, and call
pci_map_sg()on it. If I do it wrong - it could be fixed. But why it is bad in principle? Advantages - no need to check if sg is used for this particular command throughout the code.
Quoted 6 lines
Quoted 1 line
But no problem. I'll redo the patch without private sg.
Actually, I haven't looked at the patch yet. I was just answering the question in the mail which I assumed was "can I alter these three fields?" to which the answer is "no". If the question is "can I read these fields directly" the answer's yes.
Ah, ok. I don't alter those fields in the sg, set up by the block-layer. I just set up a separate sg for cases, when the block layer doesn't do it. That helps to unify the processing. I would prefer to go that way. Although, I think, there's still a glitch there (modified if's order). I'll send a new version, if the approach is approved in principle.
I also prepared a patch without extra sg's, but I am much less confident about it, although it survived some light testing.
Thanks
Guennadi
---
Guennadi Liakhovetski
Re: [PATCH] tmscsim: init / exit cleanup
In reply to Guennadi LiakhovetskiQuoted 2 lines · Guennadi Liakhovetski
Sorry, do you have a reference or remember at least apporoximatly when and where the discussion took place?
Sorry, don't remember anymore. Try searching the lkml archives.
Quoted 3 lines
I don't quite understand your arguments.
We do have __dev{init,exit,...} macros, do they have "problems over the module boundary"? If yes - they want to be solved, right?
currently you can have pointers to __devinitdata functions in structures registered with other modules. Having more different lifetime rules will complicate that enormously and need a audit of the whole kernel first.
Re: [PATCH] tmscsim: init / exit cleanup
In reply to Guennadi LiakhovetskiHi,
Quoted 2 lines · Guennadi Liakhovetski
I don't think there are any pcmcia / usb / ieee1394 / ... tmscsim adapters out there?
Never heard of any.
Regards,
Signature · 2 lines
Kurt Garloff <[email protected]> Cologne, DE SUSE LINUX AG / Novell, Nuernberg, DE Director SUSE Labs
Re: [PATCH] tmscsim: 64-bit cleanup
In reply to Guennadi LiakhovetskiQuoted 2 lines · Guennadi Liakhovetski
Although, I think, there's still a glitch there (modified if's order). I'll send a new version, if the approach is approved in principle.
Ok, attached is version 3:-) It also fixes a definite (although, perhaps, harmless) bug in scsiiom.c. And removes a redundant assignment in tmscsim.c.
Thanks
Guennadi
---
Guennadi Liakhovetski
drivers/scsi/tmscsim.c +40 -34
@@ -911,6 +911,14 @@ } } +static struct scatterlist *dc390_sg_build_single (struct scatterlist *sg,void *addr,unsigned int length) +{ +memset (sg,0 ,sizeof (struct scatterlist )); + sg->page =virt_to_page (addr); + sg->length = length; + sg->offset = (unsigned long )addr & ~PAGE_MASK ; +return sg; +}/* Create pci mapping */ static int dc390_pci_map (PSRB pSRB)
@@ -919,40 +927,43 @@Scsi_Cmnd *pcmd = pSRB->pcmd;struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;dc390_cmd_scp_t * cmdp = ((dc390_cmd_scp_t *)(&pcmd->SCp)); +/* Map sense buffer */ if (pSRB->SRBFlag &AUTO_REQSENSE ) { -sg_dma_address (&pSRB->Segmentx) = cmdp->saved_dma_handle = -pci_map_page (pdev,virt_to_page (pcmd->sense_buffer), - (unsigned long )pcmd->sense_buffer & ~PAGE_MASK ,sizeof (pcmd->sense_buffer), -DMA_FROM_DEVICE ); -sg_dma_len (&pSRB->Segmentx) =sizeof (pcmd->sense_buffer); - pSRB->SGcount =1 ; - pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx; + pSRB->pSegmentList =dc390_sg_build_single (&pSRB->Segmentx, pcmd->sense_buffer,sizeof (pcmd->sense_buffer)); + pSRB->SGcount =pci_map_sg (pdev, pSRB->pSegmentList,1 , +DMA_FROM_DEVICE ); + cmdp->saved_dma_handle =sg_dma_address (pSRB->pSegmentList); + +/* TODO: error handling */ +if (pSRB->SGcount !=1 ) + error =1 ;DEBUG1 (printk ("%s(): Mapped sense buffer %p at %x\n" , __FUNCTION__, pcmd->sense_buffer, cmdp->saved_dma_handle)); -/* Make SG list */ +/* Map SG list */ }else if (pcmd->use_sg) { - pSRB->pSegmentList = (PSGL ) pcmd->request_buffer; - pSRB->SGcount =pci_map_sg (pdev, pSRB->pSegmentList, - pcmd->use_sg, -scsi_to_pci_dma_dir (pcmd->sc_data_direction)); + pSRB->pSegmentList = (PSGL ) pcmd->request_buffer; + pSRB->SGcount =pci_map_sg (pdev, pSRB->pSegmentList, pcmd->use_sg, +scsi_to_pci_dma_dir (pcmd->sc_data_direction));/* TODO: error handling */ if (!pSRB->SGcount) error =1 ; -DEBUG1 (printk ("%s(): Mapped SG %p with %d (%d) elements\n" , __FUNCTION__, pcmd->request_buffer, pSRB->SGcount, pcmd->use_sg)); +DEBUG1 (printk ("%s(): Mapped SG %p with %d (%d) elements\n" ,\ + __FUNCTION__, pcmd->request_buffer, pSRB->SGcount, pcmd->use_sg));/* Map single segment */ }else if (pcmd->request_buffer && pcmd->request_bufflen) { -sg_dma_address (&pSRB->Segmentx) = cmdp->saved_dma_handle = -pci_map_page (pdev,virt_to_page (pcmd->request_buffer), - (unsigned long )pcmd->request_buffer & ~PAGE_MASK , - pcmd->request_bufflen,scsi_to_pci_dma_dir (pcmd->sc_data_direction)); + pSRB->pSegmentList =dc390_sg_build_single (&pSRB->Segmentx, pcmd->request_buffer, pcmd->request_bufflen); + pSRB->SGcount =pci_map_sg (pdev, pSRB->pSegmentList,1 , +scsi_to_pci_dma_dir (pcmd->sc_data_direction)); + cmdp->saved_dma_handle =sg_dma_address (pSRB->pSegmentList); +/* TODO: error handling */ -sg_dma_len (&pSRB->Segmentx) = pcmd->request_bufflen; - pSRB->SGcount =1 ; - pSRB->pSegmentList = (PSGL ) &pSRB->Segmentx; +if (pSRB->SGcount !=1 ) + error =1 ;DEBUG1 (printk ("%s(): Mapped request buffer %p at %x\n" , __FUNCTION__, pcmd->request_buffer, cmdp->saved_dma_handle));/* No mapping !? */ }else pSRB->SGcount =0 ; +return error; }
@@ -961,21 +972,16 @@ {Scsi_Cmnd * pcmd = pSRB->pcmd;struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev; -dc390_cmd_scp_t * cmdp = ((dc390_cmd_scp_t *)(&pcmd->SCp)); +DEBUG1 (dc390_cmd_scp_t* cmdp = ((dc390_cmd_scp_t *)(&pcmd->SCp)));if (pSRB->SRBFlag) { -pci_unmap_page (pdev, cmdp->saved_dma_handle, -sizeof (pcmd->sense_buffer),DMA_FROM_DEVICE ); +pci_unmap_sg (pdev, &pSRB->Segmentx,1 ,DMA_FROM_DEVICE );DEBUG1 (printk ("%s(): Unmapped sense buffer at %x\n" , __FUNCTION__, cmdp->saved_dma_handle)); }else if (pcmd->use_sg) { -pci_unmap_sg (pdev, pcmd->request_buffer, pcmd->use_sg, -scsi_to_pci_dma_dir (pcmd->sc_data_direction)); +pci_unmap_sg (pdev, pcmd->request_buffer, pcmd->use_sg,scsi_to_pci_dma_dir (pcmd->sc_data_direction));DEBUG1 (printk ("%s(): Unmapped SG at %p with %d elements\n" , __FUNCTION__, pcmd->request_buffer, pcmd->use_sg)); }else if (pcmd->request_buffer && pcmd->request_bufflen) { -pci_unmap_page (pdev, - cmdp->saved_dma_handle, - pcmd->request_bufflen, -scsi_to_pci_dma_dir (pcmd->sc_data_direction)); +pci_unmap_sg (pdev, &pSRB->Segmentx,1 ,scsi_to_pci_dma_dir (pcmd->sc_data_direction));DEBUG1 (printk ("%s(): Unmapped request buffer at %x\n" , __FUNCTION__, cmdp->saved_dma_handle)); } }
@@ -1535,15 +1541,16 @@ {PEEprom prom;UCHAR index; -PDCB pDCB, pDCB2; +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 ; - pDCB2 =0 ; +if (!pDCB) +return ; +if ( pACB->DCBCnt ==0 ) { pACB->pLinkDCB = pDCB;
@@ -1719,7 +1726,6 @@ pACB->SRBCount =MAX_SRB_CNT ; pACB->AdapterIndex = index; pACB->status =0 ; - psh->this_id = dc390_eepromBuf[index][EE_ADAPT_SCSI_ID ]; pACB->DCBCnt =0 ; pACB->TagMaxNum =2 << dc390_eepromBuf[index][EE_TAG_CMD_NUM ]; pACB->ACBFlag =0 ;
drivers/scsi/scsiiom.c +1 -1
@@ -1364,7 +1364,7 @@ status = pSRB->TargetStatus; ptr = (PSCSI_INQDATA ) (pcmd->request_buffer);if ( pcmd->use_sg ) - ptr = (PSCSI_INQDATA )sg_dma_address ((PSGL ) ptr); + ptr = (PSCSI_INQDATA ) (page_address (((PSGL ) ptr)->page) + ((PSGL ) ptr)->offset);DEBUG0 (printk (" SRBdone (%02x,%08x), SRB %p, pid %li\n" , status, pcmd->result,\ pSRB, pcmd->pid));