From cddc43e416deeb875982f371d27c4fb074d5970e Mon Sep 17 00:00:00 2001
From: Seokmann Ju <seokmann.ju@qlogic.com>
Date: Tue, 3 Jul 2007 11:53:34 -0700
Subject: [PATCH] add data buffer accessor with device structure.

- in addition to scsi_dma_map(), scsi_dma_map_with_device() has added.
- this addition is for not fully instantiated host, like virtual hosts on
  NPIV based implementation.

Signed-off-by: Seokmann Ju <seokmann.ju@qlogic.com>
---
 drivers/scsi/scsi_lib.c  |   22 ++++++++++++++++++++++
 include/scsi/scsi_cmnd.h |    1 +
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 70454b4..90601ed 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2315,6 +2315,28 @@ int scsi_dma_map(struct scsi_cmnd *cmd)
 EXPORT_SYMBOL(scsi_dma_map);
 
 /**
+ * scsi_dma_map_with_device - perform DMA mapping against command's sg lists
+ * @dev:	device structure
+ * @cmd:	scsi command
+ *
+ * Returns the number of sg lists actually used, zero if the sg lists
+ * is NULL, or -ENOMEM if the mapping failed.
+ */
+int scsi_dma_map_with_device(struct device *dev, struct scsi_cmnd *cmd)
+{
+	int nseg = 0;
+
+	if (scsi_sg_count(cmd)) {
+		nseg = dma_map_sg(dev, scsi_sglist(cmd), scsi_sg_count(cmd),
+				  cmd->sc_data_direction);
+		if (unlikely(!nseg))
+			return -ENOMEM;
+	}
+	return nseg;
+}
+EXPORT_SYMBOL(scsi_dma_map_with_device);
+
+/**
  * scsi_dma_unmap - unmap command's sg lists mapped by scsi_dma_map
  * @cmd:	scsi command
  */
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 53e1705..a223331 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -136,6 +136,7 @@ extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t);
 extern void scsi_free_sgtable(struct scatterlist *, int);
 
 extern int scsi_dma_map(struct scsi_cmnd *cmd);
+extern int scsi_dma_map_with_device(struct device *dev, struct scsi_cmnd *cmd);
 extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
 
 #define scsi_sg_count(cmd) ((cmd)->use_sg)
-- 
1.5.2.2.603.g7c851

