Skip to contentSkip to conversation

ntb/plx: Add support for PLX hardware

RFC In review Jeff Kirsher 3 participants 7 messages May 20, 2021 – May 21, 2021 NTB driver core

lore
Share & tools
lore
#0 lore raw

RFC 1/1 ntb/plx: Add support for PLX hardware

Added initial support for PLX Non-Transparent Bridge driver.

Cc Alexander Motin <[email protected]>
---
 drivers/ntb/hw/Kconfig          |    1 +
 drivers/ntb/hw/Makefile         |    1 +
 drivers/ntb/hw/plx/Kconfig      |    8 +
 drivers/ntb/hw/plx/Makefile     |    2 +
 drivers/ntb/hw/plx/ntb_hw_plx.c | 1088 +++++++++++++++++++++++++++++++
 drivers/ntb/hw/plx/ntb_hw_plx.h |  152 +++++
 drivers/ntb/ntb_transport.c     |    8 +-
 7 files changed, 1258 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ntb/hw/plx/Kconfig
 create mode 100644 drivers/ntb/hw/plx/Makefile
 create mode 100644 drivers/ntb/hw/plx/ntb_hw_plx.c
 create mode 100644 drivers/ntb/hw/plx/ntb_hw_plx.h
drivers/ntb/hw/Kconfig +1 -0
index e77c587060ff..326a95af9659 100644
@@ -3,3 +3,4 @@ source "drivers/ntb/hw/amd/Kconfig"
 source "drivers/ntb/hw/idt/Kconfig"
 source "drivers/ntb/hw/intel/Kconfig"
 source "drivers/ntb/hw/mscc/Kconfig"
+source "drivers/ntb/hw/plx/Kconfig"
drivers/ntb/hw/Makefile +1 -0
index 4714d6238845..358c67242dd5 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_NTB_AMD)	+= amd/
 obj-$(CONFIG_NTB_IDT)	+= idt/
 obj-$(CONFIG_NTB_INTEL)	+= intel/
 obj-$(CONFIG_NTB_SWITCHTEC) += mscc/
+obj-$(CONFIG_NTB_PLX)	+= plx/
drivers/ntb/hw/plx/Kconfig new file +8 -0
new file mode 100644
index 000000000000..7a2c694c60b8
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config NTB_PLX
+	tristate "PLX Non-Transparent Bridge support"
+	depends on X86_64
+	help
+	 This driver supports PLX NTB on capable hardware.
+
+	 If unsure, say N.
drivers/ntb/hw/plx/Makefile new file +2 -0
new file mode 100644
index 000000000000..206a0202b7c4
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_NTB_PLX) += ntb_hw_plx.o
drivers/ntb/hw/plx/ntb_hw_plx.c new file +1088 -0

1,088 lines not on this page · raw message

drivers/ntb/hw/plx/ntb_hw_plx.h new file +152 -0

152 lines not on this page · raw message

drivers/ntb/ntb_transport.c +6 -2
index 4a02561cfb96..ee39c5e9f274 100644
@@ -873,6 +873,11 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
 	xlat_size = round_up(size, xlat_align_size);
 	buff_size = round_up(size, xlat_align);
 
+	/* DEBUG code */
+	dev_info(&pdev->dev, "xlat_size is %lu\n", xlat_size);
+	dev_info(&pdev->dev, "buff_size is %lu\n", buff_size);
+	dev_info(&pdev->dev, "size is %llu\n", size);
+
 	/* No need to re-setup */
 	if (mw->xlat_size == xlat_size)
 		return 0;
@@ -1204,7 +1209,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt,
 	tx_size -= sizeof(struct ntb_rx_info);
 	qp->rx_info = qp->tx_mw + tx_size;
 
-	/* Due to housekeeping, there must be atleast 2 buffs */
+	/* Due to housekeeping, there must be at least 2 buffs */
 	qp->tx_max_frame = min(transport_mtu, tx_size / 2);
 	qp->tx_max_entry = tx_size / qp->tx_max_frame;
 
@@ -1289,7 +1294,6 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
 	spad_count = ntb_spad_count(ndev);
 
 	/* Limit the MW's based on the availability of scratchpads */
-
 	if (spad_count < NTB_TRANSPORT_MIN_SPADS) {
 		nt->mw_count = 0;
 		rc = -EINVAL;
Signature · 1 line
2.31.1
#1 lore raw

Hi Jeff,

I've just done a quick review and found some style issues. Generally the driver looks pretty good but I didn't dig into too many details.

drivers/ntb/hw/plx/ntb_hw_plx.c line 34

Quoted 3 lines · Jeff Kirsher
drivers/ntb/hw/plx/ntb_hw_plx.c new file +3 -0
+static const struct file_operations plx_ntb_debugfs_info;
+static struct dentry *debugfs_dir;
+static int plx_ntb_mw_set_trans_internal(struct ntb_dev *ntb, int idx);

Kernel style tries to avoid forward declarations unless they are needed to avoid a mutual recursion (not here). This means the code will always be in a specific order where we can read the code before it's used and it also generally forces initialization functions on the bottom. This is easier to read.

Quoted 27 lines
drivers/ntb/hw/plx/ntb_hw_plx.c new file +27 -0
+static int plx_ntb_init_pci(struct plx_ntb_dev *ndev, struct pci_dev *pdev)
+{
+	int rc;
+
+	pci_set_drvdata(pdev, ndev);
+
+	rc = pci_enable_device(pdev);
+	if (rc)
+		goto err_pci_enable;
+
+	rc = pci_request_regions(pdev, NTB_NAME);
+	if (rc)
+		goto err_pci_regions;
+
+	pci_set_master(pdev);
+
+	rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
+	if (rc) {
+		rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+		if (rc)
+			goto err_dma_mask;
+		dev_warn(&pdev->dev, "Cannot DMA highmem\n");
+	}
+
+	rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
+	if (rc) {
+		rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));

drivers/ntb/hw/plx/ntb_hw_plx.c line 223

Quoted 10 lines
drivers/ntb/hw/plx/ntb_hw_plx.c new file +10 -0
+		if (rc)
+			goto err_dma_mask;
+		dev_warn(&pdev->dev, "Cannot DMA consistent highmem\n");
+	}
+
+	ndev->self_mmio = pci_iomap(pdev, 0, 0);
+	if (!ndev->self_mmio) {
+		rc = -EIO;
+		goto err_mmio;
+	}

I'd recommend using the device managed variants of all of these. pcim_enable_device(), pcim_iomap(), devm_request_irq(), etc. It really simplifies the code as the cleanup paths are much easier.

drivers/ntb/hw/plx/ntb_hw_plx.h

Quoted 6 lines
drivers/ntb/hw/plx/ntb_hw_plx.c new file +1 -0
+module_exit(plx_ntb_pci_driver_exit);
drivers/ntb/hw/plx/ntb_hw_plx.h new file +0 -0
new file mode 100644
index 000000000000..4f118432e718

We generally do not add header files unless they are shared by multiple C files. All this code can and should be placed at the top of the C file.

Quoted 1 line

+#define ntb_ndev(__ntb) container_of(__ntb, struct plx_ntb_dev, ntb)

Although you see this a lot (and I've added my fair share) many kernel devs prefer these to be open coded. It's much clearer. Also, though, why the double underscore on ntb?

Quoted 13 lines
drivers/ntb/hw/plx/ntb_hw_plx.h new file +13 -0
+/* Bases of NTx our/peer interface registers */
+#define PLX_NTX_OUR_BASE(sc)				\
+	(PLX_NTX_BASE(sc) + ((sc)->link ? PLX_NTX_LNK_OFFSET : 0))
+#define PLX_NTX_PEER_BASE(sc)				\
+	(PLX_NTX_BASE(sc) + ((sc)->link ? 0 : PLX_NTX_LNK_OFFSET))
+
+/* Read/write NTx our interface registers */
+#define NTX_READ(sc, reg)				\
+	readl((sc)->self_mmio + PLX_NTX_OUR_BASE(sc) + (reg))
+#define NTX_WRITE(val, sc, reg)				\
+	writel((val), (sc)->self_mmio + PLX_NTX_OUR_BASE(sc) + (reg))>
+/* Read/write NTx peer interface registers */
+#define PNTX_READ(sc, reg)				\

drivers/ntb/hw/plx/ntb_hw_plx.h line 138

Quoted 10 lines
drivers/ntb/hw/plx/ntb_hw_plx.h new file +10 -0
+	readl((sc)->self_mmio + PLX_NTX_PEER_BASE(sc) + (reg))
+#define PNTX_WRITE(val, sc, reg)			\
+	writel((val), (sc)->self_mmio + PLX_NTX_PEER_BASE(sc) + (reg))
+
+/* Read/write B2B NTx registers */
+#define BNTX_READ(sc, reg)				\
+	readl((sc)->mw_info[(sc)->b2b_mw].mw_res,	\
+	PLX_NTX_BASE(sc) + (reg))
+#define BNTX_WRITE(val, sc, reg)			\
+	writel((val), (sc)->mw_info[(sc)->b2b_mw].mw_res + PLX_NTX_BASE(sc) + (reg))

This is quite nasty. I was expecting to just say to open code the writel's and not define your own. But they apparently hide a giant mess. There's got to be a better way than nesting all this hidden logic behind macros. It'd probably be better to pre-calcualate and store a lot of these base pointers. Then just open code the writel and readls.

drivers/ntb/ntb_transport.c static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, · line 879

Quoted 12 lines
drivers/ntb/ntb_transport.c +4 -0
index 4a02561cfb96..ee39c5e9f274 100644
@@ -873,6 +873,11 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
 	xlat_size = round_up(size, xlat_align_size);
 	buff_size = round_up(size, xlat_align);
 
+	/* DEBUG code */
+	dev_info(&pdev->dev, "xlat_size is %lu\n", xlat_size);
+	dev_info(&pdev->dev, "buff_size is %lu\n", buff_size);
+	dev_info(&pdev->dev, "size is %llu\n", size);

Please don't add noisy extra debug prints to every ntb-transport user. If we want to add some dev_dbg() calls that might be acceptable, but please do it in another patch.

drivers/ntb/ntb_transport.c static int ntb_transport_init_queue(struct ntb_transport_ctx *nt, · line 1212

Quoted 9 lines
drivers/ntb/ntb_transport.c +1 -1
 	/* No need to re-setup */
 	if (mw->xlat_size == xlat_size)
 		return 0;
@@ -1204,7 +1209,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt,
 	tx_size -= sizeof(struct ntb_rx_info);
 	qp->rx_info = qp->tx_mw + tx_size;
 
-	/* Due to housekeeping, there must be atleast 2 buffs */
+	/* Due to housekeeping, there must be at least 2 buffs */

Please send in separate patch if you want to cleanup other random code bits. It shouldn't be hidden within a large new driver patch.

Thanks,

Logan

#2 lore raw
Quoted 61 lines · Logan Gunthorpe

Hi Jeff,

I've just done a quick review and found some style issues. Generally the
driver looks pretty good but I didn't dig into too many details.

Quoted 4 lines · Jeff Kirsher
drivers/ntb/hw/plx/ntb_hw_plx.c new file +3 -0
+static const struct file_operations plx_ntb_debugfs_info;
+static struct dentry *debugfs_dir;
+static int plx_ntb_mw_set_trans_internal(struct ntb_dev *ntb, int

idx);

Kernel style tries to avoid forward declarations unless they are needed
to avoid a mutual recursion (not here). This means the code will always
be in a specific order where we can read the code before it's used and
it also generally forces initialization functions on the bottom. This is
easier to read.

Quoted 37 lines

+static int plx_ntb_init_pci(struct plx_ntb_dev *ndev, struct pci_dev *pdev)

drivers/ntb/hw/plx/ntb_hw_plx.c new file +26 -0
+{
+       int rc;
+
+       pci_set_drvdata(pdev, ndev);
+
+       rc = pci_enable_device(pdev);
+       if (rc)
+               goto err_pci_enable;
+
+       rc = pci_request_regions(pdev, NTB_NAME);
+       if (rc)
+               goto err_pci_regions;
+
+       pci_set_master(pdev);
+
+       rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
+       if (rc) {
+               rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+               if (rc)
+                       goto err_dma_mask;
+               dev_warn(&pdev->dev, "Cannot DMA highmem\n");
+       }
+
+       rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
+       if (rc) {
+               rc = pci_set_consistent_dma_mask(pdev,

DMA_BIT_MASK(32));
+               if (rc)
+                       goto err_dma_mask;
+               dev_warn(&pdev->dev, "Cannot DMA consistent highmem\n");
+       }
+
+       ndev->self_mmio = pci_iomap(pdev, 0, 0);
+       if (!ndev->self_mmio) {

Quoted 8 lines
Quoted 3 lines

+               rc = -EIO;
+               goto err_mmio;
+       }

I'd recommend using the device managed variants of all of these. pcim_enable_device(), pcim_iomap(), devm_request_irq(), etc. It really
simplifies the code as the cleanup paths are much easier.

Is this something new that all NTB drivers are expected to adopt? Just asking because I used the Intel and AMD drivers as examples and they are still using pci_iomap(), etc...

Quoted 14 lines

drivers/ntb/hw/plx/ntb_hw_plx.h

Quoted 9 lines
drivers/ntb/hw/plx/ntb_hw_plx.c new file +1 -0
+module_exit(plx_ntb_pci_driver_exit);
drivers/ntb/hw/plx/ntb_hw_plx.h new file +0 -0
new file mode 100644
index 000000000000..4f118432e718

We generally do not add header files unless they are shared by multiple
C files. All this code can and should be placed at the top of the C file.

Which I can easily do, if necessary.

Quoted 54 lines
Quoted 2 lines

+#define ntb_ndev(__ntb) container_of(__ntb, struct plx_ntb_dev, ntb)

Although you see this a lot (and I've added my fair share) many kernel
devs prefer these to be open coded. It's much clearer. Also, though, why
the double underscore on ntb?

Quoted 25 lines
drivers/ntb/hw/plx/ntb_hw_plx.h new file +11 -0
+/* Bases of NTx our/peer interface registers */
+#define PLX_NTX_OUR_BASE(sc)                           \
+       (PLX_NTX_BASE(sc) + ((sc)->link ? PLX_NTX_LNK_OFFSET : 0))
+#define PLX_NTX_PEER_BASE(sc)                          \
+       (PLX_NTX_BASE(sc) + ((sc)->link ? 0 : PLX_NTX_LNK_OFFSET))
+
+/* Read/write NTx our interface registers */
+#define NTX_READ(sc, reg)                              \
+       readl((sc)->self_mmio + PLX_NTX_OUR_BASE(sc) + (reg))
+#define NTX_WRITE(val, sc, reg)                                \
+       writel((val), (sc)->self_mmio + PLX_NTX_OUR_BASE(sc) +

(reg))>

drivers/ntb/hw/plx/ntb_hw_plx.h new file +5 -0
+/* Read/write NTx peer interface registers */
+#define PNTX_READ(sc, reg)                             \
+       readl((sc)->self_mmio + PLX_NTX_PEER_BASE(sc) + (reg))
+#define PNTX_WRITE(val, sc, reg)                       \
+       writel((val), (sc)->self_mmio + PLX_NTX_PEER_BASE(sc) +

(reg))

drivers/ntb/hw/plx/ntb_hw_plx.h new file +7 -0
+
+/* Read/write B2B NTx registers */
+#define BNTX_READ(sc, reg)                             \
+       readl((sc)->mw_info[(sc)->b2b_mw].mw_res,       \
+       PLX_NTX_BASE(sc) + (reg))
+#define BNTX_WRITE(val, sc, reg)                       \
+       writel((val), (sc)->mw_info[(sc)->b2b_mw].mw_res +
Quoted 1 line

PLX_NTX_BASE(sc) + (reg))

This is quite nasty. I was expecting to just say to open code the writel's and not define your own. But they apparently hide a giant mess.
There's got to be a better way than nesting all this hidden logic behind
macros. It'd probably be better to pre-calcualate and store a lot of these base pointers. Then just open code the writel and readls.

Quoted 11 lines
drivers/ntb/ntb_transport.c +0 -0
index 4a02561cfb96..ee39c5e9f274 100644
@@ -873,6 +873,11 @@ static int ntb_set_mw(struct ntb_transport_ctx
 *nt, int num_mw,
         xlat_size = round_up(size, xlat_align_size);
         buff_size = round_up(size, xlat_align);


+       /* DEBUG code */

Quoted 8 lines
Quoted 3 lines

+       dev_info(&pdev->dev, "xlat_size is %lu\n", xlat_size); +       dev_info(&pdev->dev, "buff_size is %lu\n", buff_size); +       dev_info(&pdev->dev, "size is %llu\n", size);

Please don't add noisy extra debug prints to every ntb-transport user.
If we want to add some dev_dbg() calls that might be acceptable, but please do it in another patch.

Sorry this was just added to do some debugging on what ntb_trasnport was unable to alloc MW buffers, so this was not meant to be in this patch. This will be removed.

Quoted 15 lines
Quoted 11 lines

        /* No need to re-setup */
        if (mw->xlat_size == xlat_size)
                return 0;

drivers/ntb/ntb_transport.c +0 -0
@@ -1204,7 +1209,7 @@ static int ntb_transport_init_queue(struct
 ntb_transport_ctx *nt,
         tx_size -= sizeof(struct ntb_rx_info);
         qp->rx_info = qp->tx_mw + tx_size;


-       /* Due to housekeeping, there must be atleast 2 buffs */ +       /* Due to housekeeping, there must be at least 2 buffs */

Please send in separate patch if you want to cleanup other random code
bits. It shouldn't be hidden within a large new driver patch.

Your correct, I did not mean to have this in the patch, it was just a cleanup I saw when I was reviewing the ntb_transport code to determine dma_alloc_coherent() failures. This will be a separate patch for sure.

Quoted 5 lines

Thanks,

Logan

#3 lore raw
Quoted 4 lines · Jeff Kirsher

Is this something new that all NTB drivers are expected to adopt? Just asking because I used the Intel and AMD drivers as examples and they are still using pci_iomap(), etc...

I can't speak to expectations, I'm not the gatekeeper, only a previewer passing by.

I believe they are newer than the AMD and Intel drivers and there are new ones added here and there. I think generally, kernel wide, they're a better choice. You'll find your code will be a lot cleaner, smaller and easier to understand if you adopt them.

Logan

#4 lore raw
Quoted 15 lines · Logan Gunthorpe
Quoted 6 lines · Jeff Kirsher

Is this something new that all NTB drivers are expected to adopt? Just
asking because I used the Intel and AMD drivers as examples and they
are still using pci_iomap(), etc...

I can't speak to expectations, I'm not the gatekeeper, only a previewer
passing by.

Quoted 8 lines

I believe they are newer than the AMD and Intel drivers and there are new ones added here and there. I think generally, kernel wide, they're a
better choice. You'll find your code will be a lot cleaner, smaller and
easier to understand if you adopt them.

Logan

Thanks, I can make those changes.

maintainer
#5 lore raw
In reply to Logan Gunthorpe
Quoted 6 lines · Logan Gunthorpe
Quoted 3 lines · Jeff Kirsher

Is this something new that all NTB drivers are expected to adopt? Just asking because I used the Intel and AMD drivers as examples and they are still using pci_iomap(), etc...

Quoted 7 lines

I can't speak to expectations, I'm not the gatekeeper, only a previewer passing by.

I believe they are newer than the AMD and Intel drivers and there are new ones added here and there. I think generally, kernel wide, they're a better choice. You'll find your code will be a lot cleaner, smaller and easier to understand if you adopt them.

The Intel driver is pre devm allocators. Maybe one of these days when I have time I'll clean that up and covert it. But I agree with Logan that things will be cleaner and smaller with devm_ calls.

Quoted 1 line

Logan

#6 lore raw
In reply to Logan Gunthorpe
Quoted 12 lines · Logan Gunthorpe

drivers/ntb/hw/plx/ntb_hw_plx.h

Quoted 7 lines
drivers/ntb/hw/plx/ntb_hw_plx.c new file +1 -0
+module_exit(plx_ntb_pci_driver_exit);
drivers/ntb/hw/plx/ntb_hw_plx.h new file +0 -0
new file mode 100644
index 000000000000..4f118432e718

We generally do not add header files unless they are shared by multiple
C files. All this code can and should be placed at the top of the C file.

Quoted 8 lines
Quoted 2 lines

+#define ntb_ndev(__ntb) container_of(__ntb, struct plx_ntb_dev, ntb)

Although you see this a lot (and I've added my fair share) many kernel
devs prefer these to be open coded. It's much clearer. Also, though, why
the double underscore on ntb?

I realize I did not answer your question, I did the double underscore to align with how other NTB drivers defined their own versions of the same macro.