Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * SCSI library functions depending on DMA
0004  */
0005 
0006 #include <linux/blkdev.h>
0007 #include <linux/device.h>
0008 #include <linux/export.h>
0009 #include <linux/kernel.h>
0010 
0011 #include <scsi/scsi.h>
0012 #include <scsi/scsi_cmnd.h>
0013 #include <scsi/scsi_device.h>
0014 #include <scsi/scsi_host.h>
0015 
0016 /**
0017  * scsi_dma_map - perform DMA mapping against command's sg lists
0018  * @cmd:    scsi command
0019  *
0020  * Returns the number of sg lists actually used, zero if the sg lists
0021  * is NULL, or -ENOMEM if the mapping failed.
0022  */
0023 int scsi_dma_map(struct scsi_cmnd *cmd)
0024 {
0025     int nseg = 0;
0026 
0027     if (scsi_sg_count(cmd)) {
0028         struct device *dev = cmd->device->host->dma_dev;
0029 
0030         nseg = dma_map_sg(dev, scsi_sglist(cmd), scsi_sg_count(cmd),
0031                   cmd->sc_data_direction);
0032         if (unlikely(!nseg))
0033             return -ENOMEM;
0034     }
0035     return nseg;
0036 }
0037 EXPORT_SYMBOL(scsi_dma_map);
0038 
0039 /**
0040  * scsi_dma_unmap - unmap command's sg lists mapped by scsi_dma_map
0041  * @cmd:    scsi command
0042  */
0043 void scsi_dma_unmap(struct scsi_cmnd *cmd)
0044 {
0045     if (scsi_sg_count(cmd)) {
0046         struct device *dev = cmd->device->host->dma_dev;
0047 
0048         dma_unmap_sg(dev, scsi_sglist(cmd), scsi_sg_count(cmd),
0049                  cmd->sc_data_direction);
0050     }
0051 }
0052 EXPORT_SYMBOL(scsi_dma_unmap);