/* A CRC Error causes this condition; retry */ sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | 
/* A CRC Error causes this condition; retry */ sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | 
mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr){	struct scsi_cmnd	*sc;	MPT_SCSI_HOST	*hd;	SCSIIORequest_t	*pScsiReq;	SCSIIOReply_t	*pScsiReply;	u16		 req_idx;	hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;	req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);	sc = hd->ScsiLookup[req_idx];	if (sc == NULL) {		MPIHeader_t *hdr = (MPIHeader_t *)mf;		/* Remark: writeSDP1 will use the ScsiDoneCtx		 * If a SCSI I/O cmd, device disabled by OS and		 * completion done. Cannot touch sc struct. Just free mem.		 */		if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)			printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",			ioc->name);		mptscsih_freeChainBuffers(ioc, req_idx);		return 1;	}	dmfprintk((MYIOC_s_INFO_FMT		"ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",		ioc->name, mf, mr, sc, req_idx));	sc->result = DID_OK << 16;		/* Set default reply as OK */	pScsiReq = (SCSIIORequest_t *) mf;	pScsiReply = (SCSIIOReply_t *) mr;	if (pScsiReply == NULL) {		/* special context reply handling */		;	} else {		u32	 xfer_cnt;		u16	 status;		u8	 scsi_state, scsi_status;		status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;		scsi_state = pScsiReply->SCSIState;		scsi_status = pScsiReply->SCSIStatus;		xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);		sc->resid = sc->request_bufflen - xfer_cnt;		dreplyprintk((KERN_NOTICE "Reply ha=%d id=%d lun=%d:\n"			"IOCStatus=%04xh SCSIState=%02xh SCSIStatus=%02xh\n"			"resid=%d bufflen=%d xfer_cnt=%d\n",			ioc->id, pScsiReq->TargetID, pScsiReq->LUN[1],			status, scsi_state, scsi_status, sc->resid, 			sc->request_bufflen, xfer_cnt));		if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)			mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);		/*		 *  Look for + dump FCP ResponseInfo[]!		 */		if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID) {			printk(KERN_NOTICE "  FCP_ResponseInfo=%08xh\n",			le32_to_cpu(pScsiReply->ResponseInfo));		}		switch(status) {		case MPI_IOCSTATUS_BUSY:			/* 0x0002 */			/* CHECKME!			 * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)			 * But not: DID_BUS_BUSY lest one risk			 * killing interrupt handler:-(			 */			sc->result = SAM_STAT_BUSY;			break;		case MPI_IOCSTATUS_SCSI_INVALID_BUS:		/* 0x0041 */		case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:	/* 0x0042 */			sc->result = DID_BAD_TARGET << 16;			break;		case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:	/* 0x0043 */			/* Spoof to SCSI Selection Timeout! */			sc->result = DID_NO_CONNECT << 16;			if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)				hd->sel_timeout[pScsiReq->TargetID]++;			break;		case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:	/* 0x0048 */		case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:		/* 0x004B */		case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:		/* 0x004C */			/* Linux handles an unsolicited DID_RESET better			 * than an unsolicited DID_ABORT.			 */			sc->result = DID_RESET << 16;			/* GEM Workaround. */			if (ioc->bus_type == SCSI)				mptscsih_no_negotiate(hd, sc->device->id);			break;		case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:	/* 0x0049 */			if ( xfer_cnt >= sc->underflow ) {				/* Sufficient data transfer occurred */				sc->result = (DID_OK << 16) | scsi_status;			} else if ( xfer_cnt == 0 ) {				/* A CRC Error causes this condition; retry */ 				sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | 					(CHECK_CONDITION << 1);				sc->sense_buffer[0] = 0x70;				sc->sense_buffer[2] = NO_SENSE;				sc->sense_buffer[12] = 0;				sc->sense_buffer[13] = 0;			} else {				sc->result = DID_SOFT_ERROR << 16;			}			dreplyprintk((KERN_NOTICE "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->target));			break;		case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:		/* 0x0045 */			/*			 *  Do upfront check for valid SenseData and give it			 *  precedence!			 */			sc->result = (DID_OK << 16) | scsi_status;			if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {				/* Have already saved the status and sense data				 */				;			} else {				if (xfer_cnt < sc->underflow) {					sc->result = DID_SOFT_ERROR << 16;				}				if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {					/* What to do?				 	*/					sc->result = DID_SOFT_ERROR << 16;				}				else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {					/*  Not real sure here either...  */					sc->result = DID_RESET << 16;				}			}			dreplyprintk((KERN_NOTICE "  sc->underflow={report ERR if < %02xh bytes xfer'd}\n",					sc->underflow));			dreplyprintk((KERN_NOTICE "  ActBytesXferd=%02xh\n", xfer_cnt));			/* Report Queue Full			 */			if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)				mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);			break;		case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR:	/* 0x0040 */		case MPI_IOCSTATUS_SUCCESS:			/* 0x0000 */			scsi_status = pScsiReply->SCSIStatus;			sc->result = (DID_OK << 16) | scsi_status;			if (scsi_state == 0) {				;			} else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {				/*				 * If running against circa 200003dd 909 MPT f/w,				 * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL				 * (QUEUE_FULL) returned from device! --> get 0x0000?128				 * and with SenseBytes set to 0.				 */				if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)					mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);			}			else if (scsi_state &			         (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)			   ) {				/*				 * What to do?				 */				sc->result = DID_SOFT_ERROR << 16;			}			else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {				/*  Not real sure here either...  */				sc->result = DID_RESET << 16;			}			else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {				/* Device Inq. data indicates that it supports				 * QTags, but rejects QTag messages.				 * This command completed OK.				 *				 * Not real sure here either so do nothing...  */			}			if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)				mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);			/* Add handling of:			 * Reservation Conflict, Busy,			 * Command Terminated, CHECK			 */			break;		case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:		/* 0x0047 */			sc->result = DID_SOFT_ERROR << 16;			break;		case MPI_IOCSTATUS_INVALID_FUNCTION:		/* 0x0001 */		case MPI_IOCSTATUS_INVALID_SGL:			/* 0x0003 */		case MPI_IOCSTATUS_INTERNAL_ERROR:		/* 0x0004 */		case MPI_IOCSTATUS_RESERVED:			/* 0x0005 */		case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:	/* 0x0006 */		case MPI_IOCSTATUS_INVALID_FIELD:		/* 0x0007 */		case MPI_IOCSTATUS_INVALID_STATE:		/* 0x0008 */		case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:		/* 0x0044 */		case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:		/* 0x0046 */		case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:	/* 0x004A */		default:			/*			 * What to do?			 */			sc->result = DID_SOFT_ERROR << 16;			break;		}	/* switch(status) */		dreplyprintk((KERN_NOTICE "  sc->result is %08xh\n", sc->result));	} /* end of address reply case */	/* Unmap the DMA buffers, if any. */	if (sc->use_sg) {		pci_unmap_sg(ioc->pcidev, (struct scatterlist *) sc->request_buffer,			    sc->use_sg, sc->sc_data_direction);	} else if (sc->request_bufflen) {		pci_unmap_single(ioc->pcidev, sc->SCp.dma_handle,				sc->request_bufflen, sc->sc_data_direction);	}	hd->ScsiLookup[req_idx] = NULL;	sc->scsi_done(sc);		/* Issue the command callback */	/* Free Chain buffers */	mptscsih_freeChainBuffers(ioc, req_idx);	return 1;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/c6678e0cfb41b029c3600c54b5bb65954de1230a/mptscsih.c/buggy/drivers/message/fusion/mptscsih.c