scsi_lib_dma.c 1.1 KB

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