1*7689e82eSCornelia Huck /* 2*7689e82eSCornelia Huck * SCSI library functions depending on DMA 3*7689e82eSCornelia Huck */ 4*7689e82eSCornelia Huck 5*7689e82eSCornelia Huck #include <linux/blkdev.h> 6*7689e82eSCornelia Huck #include <linux/device.h> 7*7689e82eSCornelia Huck #include <linux/kernel.h> 8*7689e82eSCornelia Huck 9*7689e82eSCornelia Huck #include <scsi/scsi.h> 10*7689e82eSCornelia Huck #include <scsi/scsi_cmnd.h> 11*7689e82eSCornelia Huck #include <scsi/scsi_device.h> 12*7689e82eSCornelia Huck #include <scsi/scsi_host.h> 13*7689e82eSCornelia Huck 14*7689e82eSCornelia Huck /** 15*7689e82eSCornelia Huck * scsi_dma_map - perform DMA mapping against command's sg lists 16*7689e82eSCornelia Huck * @cmd: scsi command 17*7689e82eSCornelia Huck * 18*7689e82eSCornelia Huck * Returns the number of sg lists actually used, zero if the sg lists 19*7689e82eSCornelia Huck * is NULL, or -ENOMEM if the mapping failed. 20*7689e82eSCornelia Huck */ 21*7689e82eSCornelia Huck int scsi_dma_map(struct scsi_cmnd *cmd) 22*7689e82eSCornelia Huck { 23*7689e82eSCornelia Huck int nseg = 0; 24*7689e82eSCornelia Huck 25*7689e82eSCornelia Huck if (scsi_sg_count(cmd)) { 26*7689e82eSCornelia Huck struct device *dev = cmd->device->host->shost_gendev.parent; 27*7689e82eSCornelia Huck 28*7689e82eSCornelia Huck nseg = dma_map_sg(dev, scsi_sglist(cmd), scsi_sg_count(cmd), 29*7689e82eSCornelia Huck cmd->sc_data_direction); 30*7689e82eSCornelia Huck if (unlikely(!nseg)) 31*7689e82eSCornelia Huck return -ENOMEM; 32*7689e82eSCornelia Huck } 33*7689e82eSCornelia Huck return nseg; 34*7689e82eSCornelia Huck } 35*7689e82eSCornelia Huck EXPORT_SYMBOL(scsi_dma_map); 36*7689e82eSCornelia Huck 37*7689e82eSCornelia Huck /** 38*7689e82eSCornelia Huck * scsi_dma_unmap - unmap command's sg lists mapped by scsi_dma_map 39*7689e82eSCornelia Huck * @cmd: scsi command 40*7689e82eSCornelia Huck */ 41*7689e82eSCornelia Huck void scsi_dma_unmap(struct scsi_cmnd *cmd) 42*7689e82eSCornelia Huck { 43*7689e82eSCornelia Huck if (scsi_sg_count(cmd)) { 44*7689e82eSCornelia Huck struct device *dev = cmd->device->host->shost_gendev.parent; 45*7689e82eSCornelia Huck 46*7689e82eSCornelia Huck dma_unmap_sg(dev, scsi_sglist(cmd), scsi_sg_count(cmd), 47*7689e82eSCornelia Huck cmd->sc_data_direction); 48*7689e82eSCornelia Huck } 49*7689e82eSCornelia Huck } 50*7689e82eSCornelia Huck EXPORT_SYMBOL(scsi_dma_unmap); 51