dma-mapping: remove p2p support from SG mapping routine

After commit 94ce55046c36 ("nvme-pci: convert metadata mapping to dma iter"),
there are no in-kernel users who perform DMA mapping over SG to enable p2p
transfer.

In order to make sure that future p2p implementation will use proper
interface e.g. dma_iova_link().., let's remove p2p checks from SG.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index ea2ef53..b169824 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1383,7 +1383,6 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 	struct iova_domain *iovad = &cookie->iovad;
 	struct scatterlist *s, *prev = NULL;
 	int prot = dma_info_to_prot(dir, dev_is_dma_coherent(dev), attrs);
-	struct pci_p2pdma_map_state p2pdma_state = {};
 	dma_addr_t iova;
 	size_t iova_len = 0;
 	unsigned long mask = dma_get_seg_boundary(dev);
@@ -1413,28 +1412,12 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 		size_t s_length = s->length;
 		size_t pad_len = (mask - iova_len + 1) & mask;
 
-		switch (pci_p2pdma_state(&p2pdma_state, dev, sg_page(s))) {
-		case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
+		if (IS_ENABLED(CONFIG_PCI_P2PDMA) &&
+		    is_pci_p2pdma_page(sg_page(s))) {
 			/*
-			 * Mapping through host bridge should be mapped with
-			 * regular IOVAs, thus we do nothing here and continue
-			 * below.
+			 * Mapping of p2p pages is peformed through
+			 * dma_iova_link() interface and not SG lists.
 			 */
-			break;
-		case PCI_P2PDMA_MAP_NONE:
-			break;
-		case PCI_P2PDMA_MAP_BUS_ADDR:
-			/*
-			 * iommu_map_sg() will skip this segment as it is marked
-			 * as a bus address, __finalise_sg() will copy the dma
-			 * address into the output segment.
-			 */
-			s->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state,
-						sg_phys(s));
-			sg_dma_len(s) = sg->length;
-			sg_dma_mark_bus_address(s);
-			continue;
-		default:
 			ret = -EREMOTEIO;
 			goto out_restore_sg;
 		}
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 24c359d..f834a8a 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -462,36 +462,26 @@ void dma_direct_unmap_sg(struct device *dev, struct scatterlist *sgl,
 int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
 		enum dma_data_direction dir, unsigned long attrs)
 {
-	struct pci_p2pdma_map_state p2pdma_state = {};
 	struct scatterlist *sg;
 	int i, ret;
 
 	for_each_sg(sgl, sg, nents, i) {
-		switch (pci_p2pdma_state(&p2pdma_state, dev, sg_page(sg))) {
-		case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
+		if (IS_ENABLED(CONFIG_PCI_P2PDMA) &&
+		    is_pci_p2pdma_page(sg_page(sg))) {
 			/*
-			 * Any P2P mapping that traverses the PCI host bridge
-			 * must be mapped with CPU physical address and not PCI
-			 * bus addresses.
+			 * Mapping of p2p pages is peformed through
+			 * dma_iova_link() interface and not SG lists.
 			 */
-			break;
-		case PCI_P2PDMA_MAP_NONE:
-			sg->dma_address = dma_direct_map_page(dev, sg_page(sg),
-					sg->offset, sg->length, dir, attrs);
-			if (sg->dma_address == DMA_MAPPING_ERROR) {
-				ret = -EIO;
-				goto out_unmap;
-			}
-			break;
-		case PCI_P2PDMA_MAP_BUS_ADDR:
-			sg->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state,
-					sg_phys(sg));
-			sg_dma_mark_bus_address(sg);
-			continue;
-		default:
 			ret = -EREMOTEIO;
 			goto out_unmap;
 		}
+
+		sg->dma_address = dma_direct_map_page(
+			dev, sg_page(sg), sg->offset, sg->length, dir, attrs);
+		if (sg->dma_address == DMA_MAPPING_ERROR) {
+			ret = -EIO;
+			goto out_unmap;
+		}
 		sg_dma_len(sg) = sg->length;
 	}