nvme-pci: check DMA ops when indicating support for PCI P2PDMA
authorLogan Gunthorpe <logang@deltatee.com>
Fri, 8 Jul 2022 16:51:00 +0000 (10:51 -0600)
committerChristoph Hellwig <hch@lst.de>
Tue, 26 Jul 2022 11:28:07 +0000 (07:28 -0400)
Introduce a supports_pci_p2pdma() operation in nvme_ctrl_ops to
replace the fixed NVME_F_PCI_P2PDMA flag such that the dma_map_ops
flags can be checked for PCI P2PDMA support.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c

index 3ab2cfd254a448d729498d303787136ded54c56e..4669045a76f852187cd355c75278458cb0c26724 100644 (file)
@@ -3982,7 +3982,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
                blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, ns->queue);
 
        blk_queue_flag_set(QUEUE_FLAG_NONROT, ns->queue);
-       if (ctrl->ops->flags & NVME_F_PCI_P2PDMA)
+       if (ctrl->ops->supports_pci_p2pdma &&
+           ctrl->ops->supports_pci_p2pdma(ctrl))
                blk_queue_flag_set(QUEUE_FLAG_PCI_P2PDMA, ns->queue);
 
        ns->ctrl = ctrl;
index 0da94b233feda837070277ee5a46318328cad1df..544b4ec81b2b35a3c5124bb82ebe35bd1ac1a197 100644 (file)
@@ -495,7 +495,6 @@ struct nvme_ctrl_ops {
        unsigned int flags;
 #define NVME_F_FABRICS                 (1 << 0)
 #define NVME_F_METADATA_SUPPORTED      (1 << 1)
-#define NVME_F_PCI_P2PDMA              (1 << 2)
        int (*reg_read32)(struct nvme_ctrl *ctrl, u32 off, u32 *val);
        int (*reg_write32)(struct nvme_ctrl *ctrl, u32 off, u32 val);
        int (*reg_read64)(struct nvme_ctrl *ctrl, u32 off, u64 *val);
@@ -504,6 +503,7 @@ struct nvme_ctrl_ops {
        void (*delete_ctrl)(struct nvme_ctrl *ctrl);
        int (*get_address)(struct nvme_ctrl *ctrl, char *buf, int size);
        void (*print_device_info)(struct nvme_ctrl *ctrl);
+       bool (*supports_pci_p2pdma)(struct nvme_ctrl *ctrl);
 };
 
 /*
index c7012e85d035d6114792e0066c2a449de3ae42d6..0ca42ae68f584c7f61619c96a2dde0d8a233847a 100644 (file)
@@ -2984,7 +2984,6 @@ static int nvme_pci_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
        return snprintf(buf, size, "%s\n", dev_name(&pdev->dev));
 }
 
-
 static void nvme_pci_print_device_info(struct nvme_ctrl *ctrl)
 {
        struct pci_dev *pdev = to_pci_dev(to_nvme_dev(ctrl)->dev);
@@ -2999,11 +2998,17 @@ static void nvme_pci_print_device_info(struct nvme_ctrl *ctrl)
                subsys->firmware_rev);
 }
 
+static bool nvme_pci_supports_pci_p2pdma(struct nvme_ctrl *ctrl)
+{
+       struct nvme_dev *dev = to_nvme_dev(ctrl);
+
+       return dma_pci_p2pdma_supported(dev->dev);
+}
+
 static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
        .name                   = "pcie",
        .module                 = THIS_MODULE,
-       .flags                  = NVME_F_METADATA_SUPPORTED |
-                                 NVME_F_PCI_P2PDMA,
+       .flags                  = NVME_F_METADATA_SUPPORTED,
        .reg_read32             = nvme_pci_reg_read32,
        .reg_write32            = nvme_pci_reg_write32,
        .reg_read64             = nvme_pci_reg_read64,
@@ -3011,6 +3016,7 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
        .submit_async_event     = nvme_pci_submit_async_event,
        .get_address            = nvme_pci_get_address,
        .print_device_info      = nvme_pci_print_device_info,
+       .supports_pci_p2pdma    = nvme_pci_supports_pci_p2pdma,
 };
 
 static int nvme_dev_map(struct nvme_dev *dev)