* scsi_cmnd request_buffer 
* scsi_cmnd request_buffer.  Note that the bdeSize is explicitly * reinitialized since all iocb memory resources are used many times * for transmit, receive, and continuation bpl's. 
lpfc_scsi_prep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd){	struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;	struct scatterlist *sgel = NULL;	struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;	struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;	IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;	dma_addr_t physaddr;	uint32_t i, num_bde = 0;	int datadir = scsi_cmnd->sc_data_direction;	int dma_error;	/*	 * There are three possibilities here - use scatter-gather segment, use	 * the single mapping, or neither.  Start the lpfc command prep by	 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first	 * data bde entry.	 */	bpl += 2;	if (scsi_cmnd->use_sg) {		/*		 * The driver stores the segment count returned from pci_map_sg		 * because this a count of dma-mappings used to map the use_sg		 * pages.  They are not guaranteed to be the same for those		 * architectures that implement an IOMMU.		 */		sgel = (struct scatterlist *)scsi_cmnd->request_buffer;		lpfc_cmd->seg_cnt = dma_map_sg(&phba->pcidev->dev, sgel,						scsi_cmnd->use_sg, datadir);		if (lpfc_cmd->seg_cnt == 0)			return 1;		if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {			printk(KERN_ERR "%s: Too many sg segments from "			       "dma_map_sg.  Config %d, seg_cnt %d",			       __FUNCTION__, phba->cfg_sg_seg_cnt,			       lpfc_cmd->seg_cnt);			dma_unmap_sg(&phba->pcidev->dev, sgel,				     lpfc_cmd->seg_cnt, datadir);			return 1;		}		/*		 * The driver established a maximum scatter-gather segment count		 * during probe that limits the number of sg elements in any		 * single scsi command.  Just run through the seg_cnt and format		 * the bde's.		 */		for (i = 0; i < lpfc_cmd->seg_cnt; i++) {			physaddr = sg_dma_address(sgel);			bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));			bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));			bpl->tus.f.bdeSize = sg_dma_len(sgel);			if (datadir == DMA_TO_DEVICE)				bpl->tus.f.bdeFlags = 0;			else				bpl->tus.f.bdeFlags = BUFF_USE_RCV;			bpl->tus.w = le32_to_cpu(bpl->tus.w);			bpl++;			sgel++;			num_bde++;		}	} else if (scsi_cmnd->request_buffer && scsi_cmnd->request_bufflen) {		physaddr = dma_map_single(&phba->pcidev->dev,					  scsi_cmnd->request_buffer,					  scsi_cmnd->request_bufflen,					  datadir);		dma_error = dma_mapping_error(physaddr);		if (dma_error) {			lpfc_printf_log(phba, KERN_ERR, LOG_FCP,				"%d:0718 Unable to dma_map_single "				"request_buffer: x%x\n",				phba->brd_no, dma_error);			return 1;		}		lpfc_cmd->nonsg_phys = physaddr;		bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));		bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));		bpl->tus.f.bdeSize = scsi_cmnd->request_bufflen;		if (datadir == DMA_TO_DEVICE)			bpl->tus.f.bdeFlags = 0;		bpl->tus.w = le32_to_cpu(bpl->tus.w);		num_bde = 1;		bpl++;	}	/*	 * Finish initializing those IOCB fields that are dependent on the	 * scsi_cmnd request_buffer	 */	iocb_cmd->un.fcpi64.bdl.bdeSize +=		(num_bde * sizeof (struct ulp_bde64));	iocb_cmd->ulpBdeCount = 1;	iocb_cmd->ulpLe = 1;	fcp_cmnd->fcpDl = be32_to_cpu(scsi_cmnd->request_bufflen);	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/483f05f0134e60b724bc3678507c1def860c56d5/lpfc_scsi.c/buggy/drivers/scsi/lpfc/lpfc_scsi.c