From 85289f2efa108d1586a86d0c426ffc9d641bbdc2 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sat, 26 May 2007 02:41:54 +0900 Subject: [SCSI] tmscsim: convert to use the data buffer accessors - remove the unnecessary map_single path. - convert to use the new accessors for the sg lists and the parameters. Signed-off-by: FUJITA Tomonori Signed-off-by: Guennadi Liakhovetski Signed-off-by: James Bottomley --- drivers/scsi/tmscsim.c | 59 +++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'drivers/scsi/tmscsim.c') diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c index e7b85e832eb5..73c5ca082e65 100644 --- a/drivers/scsi/tmscsim.c +++ b/drivers/scsi/tmscsim.c @@ -457,28 +457,21 @@ static int dc390_pci_map (struct dc390_srb* pSRB) error = 1; DEBUG1(printk("%s(): Mapped sense buffer %p at %x\n", __FUNCTION__, pcmd->sense_buffer, cmdp->saved_dma_handle)); /* Map SG list */ - } else if (pcmd->use_sg) { - pSRB->pSegmentList = (struct scatterlist *) pcmd->request_buffer; - pSRB->SGcount = pci_map_sg(pdev, pSRB->pSegmentList, pcmd->use_sg, - pcmd->sc_data_direction); + } else if (scsi_sg_count(pcmd)) { + int nseg; + + nseg = scsi_dma_map(pcmd); + + pSRB->pSegmentList = scsi_sglist(pcmd); + pSRB->SGcount = nseg; + /* TODO: error handling */ - if (!pSRB->SGcount) + if (nseg < 0) error = 1; DEBUG1(printk("%s(): Mapped SG %p with %d (%d) elements\n",\ - __FUNCTION__, pcmd->request_buffer, pSRB->SGcount, pcmd->use_sg)); + __FUNCTION__, scsi_sglist(pcmd), nseg, scsi_sg_count(pcmd))); /* Map single segment */ - } else if (pcmd->request_buffer && pcmd->request_bufflen) { - pSRB->pSegmentList = dc390_sg_build_single(&pSRB->Segmentx, pcmd->request_buffer, pcmd->request_bufflen); - pSRB->SGcount = pci_map_sg(pdev, pSRB->pSegmentList, 1, - pcmd->sc_data_direction); - cmdp->saved_dma_handle = sg_dma_address(pSRB->pSegmentList); - - /* TODO: error handling */ - 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 + } else pSRB->SGcount = 0; return error; @@ -494,12 +487,10 @@ static void dc390_pci_unmap (struct dc390_srb* pSRB) if (pSRB->SRBFlag) { 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, 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_sg(pdev, &pSRB->Segmentx, 1, pcmd->sc_data_direction); - DEBUG1(printk("%s(): Unmapped request buffer at %x\n", __FUNCTION__, cmdp->saved_dma_handle)); + } else { + scsi_dma_unmap(pcmd); + DEBUG1(printk("%s(): Unmapped SG at %p with %d elements\n", + __FUNCTION__, scsi_sglist(pcmd), scsi_sg_count(pcmd))); } } @@ -1153,9 +1144,9 @@ dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB) struct scatterlist *psgl; pSRB->TotalXferredLen = 0; pSRB->SGIndex = 0; - if (pcmd->use_sg) { + if (scsi_sg_count(pcmd)) { size_t saved; - pSRB->pSegmentList = (struct scatterlist *)pcmd->request_buffer; + pSRB->pSegmentList = scsi_sglist(pcmd); psgl = pSRB->pSegmentList; //dc390_pci_sync(pSRB); @@ -1179,12 +1170,6 @@ dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB) printk (KERN_INFO "DC390: Pointer restored. Segment %i, Total %li, Bus %08lx\n", pSRB->SGIndex, pSRB->Saved_Ptr, pSRB->SGBusAddr); - } else if(pcmd->request_buffer) { - //dc390_pci_sync(pSRB); - - sg_dma_len(&pSRB->Segmentx) = pcmd->request_bufflen - pSRB->Saved_Ptr; - pSRB->SGcount = 1; - pSRB->pSegmentList = (struct scatterlist *) &pSRB->Segmentx; } else { pSRB->SGcount = 0; printk (KERN_INFO "DC390: RESTORE_PTR message for Transfer without Scatter-Gather ??\n"); @@ -1612,7 +1597,7 @@ dc390_Reselect( struct dc390_acb* pACB ) if( !( pACB->scan_devices ) ) { struct scsi_cmnd *pcmd = pSRB->pcmd; - pcmd->resid = pcmd->request_bufflen; + scsi_set_resid(pcmd, scsi_bufflen(pcmd)); SET_RES_DID(pcmd->result, DID_SOFT_ERROR); dc390_Going_remove(pDCB, pSRB); dc390_Free_insert(pACB, pSRB); @@ -1695,7 +1680,7 @@ dc390_RequestSense(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_ pcmd->cmnd[0], pDCB->TargetID, pDCB->TargetLUN)); pSRB->SRBFlag |= AUTO_REQSENSE; - pSRB->SavedSGCount = pcmd->use_sg; + pSRB->SavedSGCount = scsi_sg_count(pcmd); pSRB->SavedTotXLen = pSRB->TotalXferredLen; pSRB->AdaptStatus = 0; pSRB->TargetStatus = 0; /* CHECK_CONDITION<<1; */ @@ -1743,7 +1728,7 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* (u32) pcmd->result, (u32) pSRB->TotalXferredLen)); } else { SET_RES_DRV(pcmd->result, DRIVER_SENSE); - pcmd->use_sg = pSRB->SavedSGCount; + scsi_sg_count(pcmd) = pSRB->SavedSGCount; //pSRB->ScsiCmdLen = (u8) (pSRB->Segment1[0] >> 8); DEBUG0 (printk ("DC390: RETRY pid %li (%02x), target %02i-%02i\n", pcmd->pid, pcmd->cmnd[0], pcmd->device->id, pcmd->device->lun)); pSRB->TotalXferredLen = 0; @@ -1765,7 +1750,7 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* else if( status_byte(status) == QUEUE_FULL ) { scsi_track_queue_full(pcmd->device, pDCB->GoingSRBCnt - 1); - pcmd->use_sg = pSRB->SavedSGCount; + scsi_sg_count(pcmd) = pSRB->SavedSGCount; DEBUG0 (printk ("DC390: RETRY pid %li (%02x), target %02i-%02i\n", pcmd->pid, pcmd->cmnd[0], pcmd->device->id, pcmd->device->lun)); pSRB->TotalXferredLen = 0; SET_RES_DID(pcmd->result, DID_SOFT_ERROR); @@ -1816,7 +1801,7 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* } cmd_done: - pcmd->resid = pcmd->request_bufflen - pSRB->TotalXferredLen; + scsi_set_resid(pcmd, scsi_bufflen(pcmd) - pSRB->TotalXferredLen); dc390_Going_remove (pDCB, pSRB); /* Add to free list */ -- cgit v1.2.3 From 4a904a65fab83bcdd6b00470ac6c4aa80518e6a9 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Sun, 17 Jun 2007 20:32:27 +0200 Subject: [SCSI] tmscsim: clean-up status codes Remove redundant defines from the header, replace all occurances in the code with standard SAM_STAT_ macros. Also fix what seems to be a typo in testing for (status == H_OVER_UNDER_RUN)... Signed-off-by: G. Liakhovetski Signed-off-by: James Bottomley --- drivers/scsi/tmscsim.c | 29 ++++++++++++++--------------- drivers/scsi/tmscsim.h | 9 +-------- 2 files changed, 15 insertions(+), 23 deletions(-) (limited to 'drivers/scsi/tmscsim.c') diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c index 73c5ca082e65..e8260f2dba0f 100644 --- a/drivers/scsi/tmscsim.c +++ b/drivers/scsi/tmscsim.c @@ -1564,7 +1564,8 @@ dc390_Disconnect( struct dc390_acb* pACB ) if( (pSRB->SRBState & (SRB_START_+SRB_MSGOUT)) || !(pSRB->SRBState & (SRB_DISCONNECT+SRB_COMPLETED)) ) { /* Selection time out */ - pSRB->TargetStatus = SCSI_STAT_SEL_TIMEOUT; + pSRB->AdaptStatus = H_SEL_TIMEOUT; + pSRB->TargetStatus = 0; goto disc1; } else if (!(pSRB->SRBState & SRB_DISCONNECT) && (pSRB->SRBState & SRB_COMPLETED)) @@ -1713,17 +1714,17 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* { /* Last command was a Request Sense */ pSRB->SRBFlag &= ~AUTO_REQSENSE; pSRB->AdaptStatus = 0; - pSRB->TargetStatus = CHECK_CONDITION << 1; + pSRB->TargetStatus = SAM_STAT_CHECK_CONDITION; //pcmd->result = MK_RES(DRIVER_SENSE,DID_OK,0,status); - if (status == (CHECK_CONDITION << 1)) + if (status == SAM_STAT_CHECK_CONDITION) pcmd->result = MK_RES_LNX(0, DID_BAD_TARGET, 0, /*CHECK_CONDITION*/0); else /* Retry */ { if( pSRB->pcmd->cmnd[0] == TEST_UNIT_READY /* || pSRB->pcmd->cmnd[0] == START_STOP */) { /* Don't retry on TEST_UNIT_READY */ - pcmd->result = MK_RES_LNX(DRIVER_SENSE,DID_OK,0,CHECK_CONDITION); + pcmd->result = MK_RES_LNX(DRIVER_SENSE, DID_OK, 0, SAM_STAT_CHECK_CONDITION); REMOVABLEDEBUG(printk(KERN_INFO "Cmd=%02x, Result=%08x, XferL=%08x\n",pSRB->pcmd->cmnd[0],\ (u32) pcmd->result, (u32) pSRB->TotalXferredLen)); } else { @@ -1739,7 +1740,7 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* } if( status ) { - if( status_byte(status) == CHECK_CONDITION ) + if (status == SAM_STAT_CHECK_CONDITION) { if (dc390_RequestSense(pACB, pDCB, pSRB)) { SET_RES_DID(pcmd->result, DID_ERROR); @@ -1747,7 +1748,7 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* } return; } - else if( status_byte(status) == QUEUE_FULL ) + else if (status == SAM_STAT_TASK_SET_FULL) { scsi_track_queue_full(pcmd->device, pDCB->GoingSRBCnt - 1); scsi_sg_count(pcmd) = pSRB->SavedSGCount; @@ -1755,14 +1756,7 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB->TotalXferredLen = 0; SET_RES_DID(pcmd->result, DID_SOFT_ERROR); } - else if(status == SCSI_STAT_SEL_TIMEOUT) - { - pSRB->AdaptStatus = H_SEL_TIMEOUT; - pSRB->TargetStatus = 0; - pcmd->result = MK_RES(0,DID_NO_CONNECT,0,0); - /* Devices are removed below ... */ - } - else if (status_byte(status) == BUSY && + else if (status == SAM_STAT_BUSY && (pcmd->cmnd[0] == TEST_UNIT_READY || pcmd->cmnd[0] == INQUIRY) && pACB->scan_devices) { @@ -1780,12 +1774,17 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* else { /* Target status == 0 */ status = pSRB->AdaptStatus; - if(status & H_OVER_UNDER_RUN) + if (status == H_OVER_UNDER_RUN) { pSRB->TargetStatus = 0; SET_RES_DID(pcmd->result,DID_OK); SET_RES_MSG(pcmd->result,pSRB->EndMessage); } + else if (status == H_SEL_TIMEOUT) + { + pcmd->result = MK_RES(0, DID_NO_CONNECT, 0, 0); + /* Devices are removed below ... */ + } else if( pSRB->SRBStatus & PARITY_ERROR) { //pcmd->result = MK_RES(0,DID_PARITY,pSRB->EndMessage,0); diff --git a/drivers/scsi/tmscsim.h b/drivers/scsi/tmscsim.h index c3d8c80cfb38..c74c72aadb08 100644 --- a/drivers/scsi/tmscsim.h +++ b/drivers/scsi/tmscsim.h @@ -258,13 +258,6 @@ struct dc390_srb SRB_array[MAX_SRB_CNT]; /* 50 SRBs */ #define H_BAD_CCB_OR_SG 0x1A #define H_ABORT 0x0FF -/*; SCSI Status byte codes*/ -/* The values defined in include/scsi/scsi.h, to be shifted << 1 */ - -#define SCSI_STAT_UNEXP_BUS_F 0xFD /*; Unexpect Bus Free */ -#define SCSI_STAT_BUS_RST_DETECT 0xFE /*; Scsi Bus Reset detected */ -#define SCSI_STAT_SEL_TIMEOUT 0xFF /*; Selection Time out */ - /* cmd->result */ #define RES_TARGET 0x000000FF /* Target State */ #define RES_TARGET_LNX STATUS_MASK /* Only official ... */ @@ -273,7 +266,7 @@ struct dc390_srb SRB_array[MAX_SRB_CNT]; /* 50 SRBs */ #define RES_DRV 0xFF000000 /* DRIVER_ codes */ #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)) -#define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)<<1) +#define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)) #define SET_RES_TARGET(who, tgt) do { who &= ~RES_TARGET; who |= (int)(tgt); } while (0) #define SET_RES_TARGET_LNX(who, tgt) do { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; } while (0) -- cgit v1.2.3 From 0ab179bcf31fd54c7b34b4191ea8591267641e92 Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Wed, 4 Jul 2007 21:18:55 +0300 Subject: [SCSI] tmscsim: Further clean-up of the driver - The saved sg_count was a leftover from the time the driver was doing dma mapping by himself. But now that scsi-ml is called for the mapping it is not the drivers responsibility. Signed-off-by: Boaz Harrosh Acked-by: G. Liakhovetski Signed-off-by: James Bottomley --- drivers/scsi/tmscsim.c | 3 --- drivers/scsi/tmscsim.h | 1 - 2 files changed, 4 deletions(-) (limited to 'drivers/scsi/tmscsim.c') diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c index e8260f2dba0f..14cba1ca38b3 100644 --- a/drivers/scsi/tmscsim.c +++ b/drivers/scsi/tmscsim.c @@ -1681,7 +1681,6 @@ dc390_RequestSense(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_ pcmd->cmnd[0], pDCB->TargetID, pDCB->TargetLUN)); pSRB->SRBFlag |= AUTO_REQSENSE; - pSRB->SavedSGCount = scsi_sg_count(pcmd); pSRB->SavedTotXLen = pSRB->TotalXferredLen; pSRB->AdaptStatus = 0; pSRB->TargetStatus = 0; /* CHECK_CONDITION<<1; */ @@ -1729,7 +1728,6 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* (u32) pcmd->result, (u32) pSRB->TotalXferredLen)); } else { SET_RES_DRV(pcmd->result, DRIVER_SENSE); - scsi_sg_count(pcmd) = pSRB->SavedSGCount; //pSRB->ScsiCmdLen = (u8) (pSRB->Segment1[0] >> 8); DEBUG0 (printk ("DC390: RETRY pid %li (%02x), target %02i-%02i\n", pcmd->pid, pcmd->cmnd[0], pcmd->device->id, pcmd->device->lun)); pSRB->TotalXferredLen = 0; @@ -1751,7 +1749,6 @@ dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* else if (status == SAM_STAT_TASK_SET_FULL) { scsi_track_queue_full(pcmd->device, pDCB->GoingSRBCnt - 1); - scsi_sg_count(pcmd) = pSRB->SavedSGCount; DEBUG0 (printk ("DC390: RETRY pid %li (%02x), target %02i-%02i\n", pcmd->pid, pcmd->cmnd[0], pcmd->device->id, pcmd->device->lun)); pSRB->TotalXferredLen = 0; SET_RES_DID(pcmd->result, DID_SOFT_ERROR); diff --git a/drivers/scsi/tmscsim.h b/drivers/scsi/tmscsim.h index c74c72aadb08..77adc54dbd16 100644 --- a/drivers/scsi/tmscsim.h +++ b/drivers/scsi/tmscsim.h @@ -57,7 +57,6 @@ u8 SGcount; u8 MsgCnt; u8 EndMessage; -u8 SavedSGCount; u8 MsgInBuf[6]; u8 MsgOutBuf[6]; -- cgit v1.2.3