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