Skip to contentSkip to conversation

PCI-Express Non-Transparent Bridge Support

PATCH Superseded Jon Mason 2 participants 10 messages Nov 6, 2012 – Nov 16, 2012

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

v5 cover PCI-Express Non-Transparent Bridge Support

I am submitting version 5 of the PCI-Express Non-Transparent Bridge patches for inclusion in 3.8 via Greg KH's char-misc-next tree. All outstanding issues have been addressed.

Version 1
http://thread.gmane.org/gmane.linux.kernel.pci/16443

Version 2 incorporates numerous clean-ups
http://thread.gmane.org/gmane.linux.kernel.pci/16696

Version 3 incorporates changes to conform NTB and client devices to the Linux device model (per Greg KH's request).
http://thread.gmane.org/gmane.linux.kernel.pci/17808

Version 4 removes the transport transmit tasklet (per Dave Miller's request)
http://thread.gmane.org/gmane.linux.network/244491

Version 5 corrects a MSI-X bug and cleans up some comments
http://thread.gmane.org/gmane.linux.kernel.pci/18030

Thanks,
Jon

author
#1 lore raw

PATCH v5 1/2 PCI-Express Non-Transparent Bridge Support

A PCI-Express non-transparent bridge (NTB) is a point-to-point PCIe bus connecting 2 systems, providing electrical isolation between the two subsystems. A non-transparent bridge is functionally similar to a transparent bridge except that both sides of the bridge have their own independent address domains. The host on one side of the bridge will not have the visibility of the complete memory or I/O space on the other side of the bridge. To communicate across the non-transparent bridge, each NTB endpoint has one (or more) apertures exposed to the local system. Writes to these apertures are mirrored to memory on the remote system. Communications can also occur through the use of doorbell registers that initiate interrupts to the alternate domain, and scratch-pad registers accessible from both sides.

The NTB device driver is needed to configure these memory windows, doorbell, and scratch-pad registers as well as use them in such a way as they can be turned into a viable communication channel to the remote system. ntb_hw.[ch] determines the usage model (NTB to NTB or NTB to Root Port) and abstracts away the underlying hardware to provide access and a common interface to the doorbell registers, scratch pads, and memory windows. These hardware interfaces are exported so that other, non-mainlined kernel drivers can access these. ntb_transport.[ch] also uses the exported interfaces in ntb_hw.[ch] to setup a communication channel(s) and provide a reliable way of transferring data from one side to the other, which it then exports so that "client" drivers can access them. These client drivers are used to provide a standard kernel interface (i.e., Ethernet device) to NTB, such that Linux can transfer data from one system to the other in a standard way.

---
 MAINTAINERS                 |    6 +
 drivers/Kconfig             |    2 +
 drivers/Makefile            |    1 +
 drivers/ntb/Kconfig         |   13 +
 drivers/ntb/Makefile        |    3 +
 drivers/ntb/ntb_hw.c        | 1172 +++++++++++++++++++++++++++++++++++++
 drivers/ntb/ntb_hw.h        |  195 +++++++
 drivers/ntb/ntb_regs.h      |  139 +++++
 drivers/ntb/ntb_transport.c | 1354 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/ntb.h         |   81 +++
 10 files changed, 2966 insertions(+)
 create mode 100644 drivers/ntb/Kconfig
 create mode 100644 drivers/ntb/Makefile
 create mode 100644 drivers/ntb/ntb_hw.c
 create mode 100644 drivers/ntb/ntb_hw.h
 create mode 100644 drivers/ntb/ntb_regs.h
 create mode 100644 drivers/ntb/ntb_transport.c
 create mode 100644 include/linux/ntb.h
MAINTAINERS +6 -0
index 59203e7..e0fc24a 100644
@@ -5144,6 +5144,12 @@ S:	Maintained
 F:	Documentation/scsi/NinjaSCSI.txt
 F:	drivers/scsi/nsp32*
 
+NTB DRIVER
+M:	Jon Mason <[email protected]>
+S:	Supported
+F:	drivers/ntb/
+F:	include/linux/ntb.h
+
 NTFS FILESYSTEM
 M:	Anton Altaparmakov <[email protected]>
 L:	[email protected]
drivers/Kconfig +2 -0
index dbdefa3..7992e69 100644
@@ -150,6 +150,8 @@ source "drivers/memory/Kconfig"
 
 source "drivers/iio/Kconfig"
 
+source "drivers/ntb/Kconfig"
+
 source "drivers/vme/Kconfig"
 
 source "drivers/pwm/Kconfig"
drivers/Makefile +1 -0
index a16a8d0..fdafa34 100644
@@ -145,3 +145,4 @@ obj-$(CONFIG_EXTCON)		+= extcon/
 obj-$(CONFIG_MEMORY)		+= memory/
 obj-$(CONFIG_IIO)		+= iio/
 obj-$(CONFIG_VME_BUS)		+= vme/
+obj-$(CONFIG_NTB)		+= ntb/
drivers/ntb/Kconfig new file +13 -0
new file mode 100644
index 0000000..f69df793
@@ -0,0 +1,13 @@
+config NTB
+       tristate "Intel Non-Transparent Bridge support"
+       depends on PCI
+       depends on X86
+       help
+        The PCI-E Non-transparent bridge hardware is a point-to-point PCI-E bus
+        connecting 2 systems.  When configured, writes to the device's PCI
+        mapped memory will be mirrored to a buffer on the remote system.  The
+        ntb Linux driver uses this point-to-point communication as a method to
+        transfer data from one system to the other.
+
+        If unsure, say N.
+
drivers/ntb/Makefile new file +3 -0
new file mode 100644
index 0000000..15cb59f
@@ -0,0 +1,3 @@
+obj-$(CONFIG_NTB) += ntb.o
+
+ntb-objs := ntb_hw.o ntb_transport.o
drivers/ntb/ntb_hw.c new file +1172 -0

1,172 lines not on this page · raw message

drivers/ntb/ntb_hw.h new file +195 -0

195 lines not on this page · raw message

drivers/ntb/ntb_regs.h new file +139 -0

139 lines not on this page · raw message

drivers/ntb/ntb_transport.c new file +1354 -0

1,354 lines not on this page · raw message

include/linux/ntb.h new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw
Quoted 110 lines · Jon Mason
drivers/ntb/ntb_hw.h new file +107 -0
@@ -0,0 +1,195 @@
+/*
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ *   redistributing this file, you may do so under either license.
+ *
+ *   GPL LICENSE SUMMARY
+ *
+ *   Copyright(c) 2012 Intel Corporation. All rights reserved.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ *
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2012 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copy
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Intel PCIe NTB Linux driver
+ *
+ * Contact Information:
+ * Jon Mason <[email protected]>
+ */
+
+#define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF		0x3725
+#define PCI_DEVICE_ID_INTEL_NTB_CLASSIC_JSF	0x3726
+#define PCI_DEVICE_ID_INTEL_NTB_RP_JSF		0x3727
+#define PCI_DEVICE_ID_INTEL_NTB_RP_SNB		0x3C08
+#define PCI_DEVICE_ID_INTEL_NTB_B2B_SNB		0x3C0D
+#define PCI_DEVICE_ID_INTEL_NTB_CLASSIC_SNB	0x3C0E
+#define PCI_DEVICE_ID_INTEL_NTB_2ND_SNB		0x3C0F
+#define PCI_DEVICE_ID_INTEL_NTB_B2B_BWD		0x0C4E
+
+#define msix_table_size(control)	((control & PCI_MSIX_FLAGS_QSIZE)+1)
+
+#define NTB_BAR_MMIO		0
+#define NTB_BAR_23		2
+#define NTB_BAR_45		4
+#define NTB_BAR_MASK		((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
+				 (1 << NTB_BAR_45))
+
+#define NTB_LINK_DOWN		0
+#define NTB_LINK_UP		1
+
+#define NTB_HB_TIMEOUT		msecs_to_jiffies(1000)
+
+#define NTB_NUM_MW		2
+
+enum ntb_hw_event {
+	NTB_EVENT_SW_EVENT0 = 0,
+	NTB_EVENT_SW_EVENT1,
+	NTB_EVENT_SW_EVENT2,
+	NTB_EVENT_HW_ERROR,
+	NTB_EVENT_HW_LINK_UP,
+	NTB_EVENT_HW_LINK_DOWN,
+};
+
+struct ntb_mw {
+	dma_addr_t phys_addr;
+	void __iomem *vbase;
+	resource_size_t bar_sz;
+};
+
+struct ntb_db_cb {
+	void (*callback) (void *data, int db_num);
+	unsigned int db_num;
+	void *data;
+	struct ntb_device *ndev;
+};
+
+struct ntb_device {
+	struct pci_dev *pdev;
+	struct msix_entry *msix_entries;
+	void __iomem *reg_base;
+	struct ntb_mw mw[NTB_NUM_MW];
+	struct {
+		unsigned int max_spads;
+		unsigned int max_db_bits;
+		unsigned int msix_cnt;
+	} limits;
+	struct {
+		void __iomem *pdb;
+		void __iomem *pdb_mask;

drivers/ntb/ntb_hw.h line 117

Quoted 10 lines
drivers/ntb/ntb_hw.h new file +10 -0
+		void __iomem *sdb;
+		void __iomem *sbar2_xlat;
+		void __iomem *sbar4_xlat;
+		void __iomem *spad_write;
+		void __iomem *spad_read;
+		void __iomem *lnk_cntl;
+		void __iomem *lnk_stat;
+		void __iomem *spci_cmd;
+	} reg_ofs;
+	void *ntb_transport;

Use the real type here please. No void *.

drivers/ntb/ntb_hw.h line 130

Quoted 13 lines
drivers/ntb/ntb_hw.h new file +13 -0
+	void (*event_cb)(void *handle, enum ntb_hw_event event);
+
+	struct ntb_db_cb *db_cb;
+	unsigned char hw_type;
+	unsigned char conn_type;
+	unsigned char dev_type;
+	unsigned char num_msix;
+	unsigned char bits_per_vector;
+	unsigned char max_cbs;
+	unsigned char link_status;
+	struct delayed_work hb_timer;
+	unsigned long last_ts;
+};

Shouldn't this have a 'struct device' embedded it in somewhere?

Quoted 29 lines
drivers/ntb/ntb_hw.h new file +29 -0
+/**
+ * ntb_hw_link_status() - return the hardware link status
+ * @ndev: pointer to ntb_device instance
+ *
+ * Returns true if the hardware is connected to the remote system
+ *
+ * RETURNS: true or false based on the hardware link state
+ */
+static inline bool ntb_hw_link_status(struct ntb_device *ndev)
+{
+	return ndev->link_status == NTB_LINK_UP;
+}
+
+/**
+ * ntb_query_pdev() - return the pci_dev pointer
+ * @ndev: pointer to ntb_device instance
+ *
+ * Given the ntb pointer return the pci_dev pointerfor the NTB hardware device
+ *
+ * RETURNS: a pointer to the ntb pci_dev
+ */
+static inline struct pci_dev *ntb_query_pdev(struct ntb_device *ndev)
+{
+	return ndev->pdev;
+}
+
+/**
+ * ntb_query_max_cbs() - return the maximum number of callback tuples
+ * @ndev: pointer to ntb_device instance

drivers/ntb/ntb_hw.h line 170

Quoted 10 lines
drivers/ntb/ntb_hw.h new file +10 -0
+ *
+ * The number of callbacks can vary depending on the platform and MSI-X/MSI
+ * enablement
+ *
+ * RETURNS: the maximum number of callback tuples (3, 15, or 33)
+ */
+static inline unsigned int ntb_query_max_cbs(struct ntb_device *ndev)
+{
+	return ndev->max_cbs;
+}

It is shorter, and simpler, to just write the '->variable' version out for this, than to make the function call here. Why are these needed? Especially when I see the driver code not using them. Please remove.

drivers/ntb/ntb_hw.h line 172

Quoted 3 lines
drivers/ntb/ntb_hw.h new file +3 -0
+static void ntb_client_release(struct device *dev)
+{
+}

Ah, how sweet. Now, according to the in-kernel documentation, I get to publicly mock you for trying to be smarter than the kernel. Nice try.

Think back to when you wrote this function. Did you really think it was the correct thing to do? If not, why did you do this?

Sorry, no.

Quoted 4 lines
drivers/ntb/ntb_hw.h new file +4 -0
+struct bus_type ntb_bus_type = {
+	.name = "ntb_bus",
+	.match = ntb_match_bus,
+	.probe = ntb_client_probe,

drivers/ntb/ntb_hw.h line 186

Quoted 10 lines
drivers/ntb/ntb_hw.h new file +10 -0
+	.remove = ntb_client_remove,
+};
+
+static atomic_t ntb_bus_use = ATOMIC_INIT(0);
+
+static int __devinit ntb_bus_init(void)
+{
+	int rc;
+
+	if (atomic_inc_return(&ntb_bus_use) == 1) {

That's the wierdest way of using an atomic variable I have ever seen. How could this ever be anything but 0? If you need a lock, use a lock.

drivers/ntb/ntb_hw.h line 189

Quoted 3 lines
drivers/ntb/ntb_hw.h new file +3 -0
+static int __devinit ntb_dev_init(struct ntb_transport *nt)
+{
+	struct device *dev = &nt->netdev;

Ah, there's the struct device. Don't call it a 'netdev', that's just really really confusing to anyone who has looked at a network driver. As this isn't a netdev, it's a 'device'.

drivers/ntb/ntb_hw.h

Quoted 8 lines
drivers/ntb/ntb_hw.h new file +8 -0
+	int rc;
+
+	rc = ntb_bus_init();
+	if (rc)
+		goto err;
+
+	/* setup and register client devices */
+	dev_set_name(dev, "ntb_netdev");

All devices get the same name? That's a recipe for confusion.

Quoted 21 lines
drivers/ntb/ntb_hw.h new file +21 -0
+static void ntb_transport_setup_qp_mw(struct ntb_transport *nt,
+				      unsigned int qp_num)
+{
+	struct ntb_transport_qp *qp = &nt->qps[qp_num];
+	u8 mw_num = QP_TO_MW(qp_num);
+	unsigned int size, num_qps_mw;
+
+	WARN_ON(nt->mw[mw_num].virt_addr == 0);
+
+	if (nt->max_qps % NTB_NUM_MW && !mw_num)
+		num_qps_mw = nt->max_qps / NTB_NUM_MW +
+			     (nt->max_qps % NTB_NUM_MW - mw_num);
+	else
+		num_qps_mw = nt->max_qps / NTB_NUM_MW;
+
+	size = nt->mw[mw_num].size / num_qps_mw;
+	pr_debug("orig size = %d, num qps = %d, size = %d\n",
+		 (int) nt->mw[mw_num].size, nt->max_qps, size);
+
+	qp->rx_buff_begin = nt->mw[mw_num].virt_addr +
+			    (qp_num / NTB_NUM_MW * size);

drivers/ntb/ntb_hw.h

Quoted 10 lines
drivers/ntb/ntb_hw.h new file +10 -0
+	qp->rx_buff_end = qp->rx_buff_begin + size;
+	pr_info("QP %d - RX Buff start %p end %p\n", qp->qp_num,
+		qp->rx_buff_begin, qp->rx_buff_end);
+	qp->rx_offset = qp->rx_buff_begin;
+
+	qp->tx_mw_begin = ntb_get_mw_vbase(nt->ndev, mw_num) +
+			  (qp_num / NTB_NUM_MW * size);
+	qp->tx_mw_end = qp->tx_mw_begin + size;
+	pr_info("QP %d - TX MW start %p end %p\n", qp->qp_num, qp->tx_mw_begin,
+		qp->tx_mw_end);

That's some debugging information spamming the kernel log, please remove.

Also, you have a 'struct device', so use dev_dbg() and friends, not pr_* calls. This should be fixed in lots of places here.

thanks,

greg k-h

author
#3 lore raw
Quoted 176 lines · Greg KH
Quoted 110 lines · Jon Mason
drivers/ntb/ntb_hw.h new file +107 -0
@@ -0,0 +1,195 @@
+/*
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ *   redistributing this file, you may do so under either license.
+ *
+ *   GPL LICENSE SUMMARY
+ *
+ *   Copyright(c) 2012 Intel Corporation. All rights reserved.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ *
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2012 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copy
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Intel PCIe NTB Linux driver
+ *
+ * Contact Information:
+ * Jon Mason <[email protected]>
+ */
+
+#define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF		0x3725
+#define PCI_DEVICE_ID_INTEL_NTB_CLASSIC_JSF	0x3726
+#define PCI_DEVICE_ID_INTEL_NTB_RP_JSF		0x3727
+#define PCI_DEVICE_ID_INTEL_NTB_RP_SNB		0x3C08
+#define PCI_DEVICE_ID_INTEL_NTB_B2B_SNB		0x3C0D
+#define PCI_DEVICE_ID_INTEL_NTB_CLASSIC_SNB	0x3C0E
+#define PCI_DEVICE_ID_INTEL_NTB_2ND_SNB		0x3C0F
+#define PCI_DEVICE_ID_INTEL_NTB_B2B_BWD		0x0C4E
+
+#define msix_table_size(control)	((control & PCI_MSIX_FLAGS_QSIZE)+1)
+
+#define NTB_BAR_MMIO		0
+#define NTB_BAR_23		2
+#define NTB_BAR_45		4
+#define NTB_BAR_MASK		((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
+				 (1 << NTB_BAR_45))
+
+#define NTB_LINK_DOWN		0
+#define NTB_LINK_UP		1
+
+#define NTB_HB_TIMEOUT		msecs_to_jiffies(1000)
+
+#define NTB_NUM_MW		2
+
+enum ntb_hw_event {
+	NTB_EVENT_SW_EVENT0 = 0,
+	NTB_EVENT_SW_EVENT1,
+	NTB_EVENT_SW_EVENT2,
+	NTB_EVENT_HW_ERROR,
+	NTB_EVENT_HW_LINK_UP,
+	NTB_EVENT_HW_LINK_DOWN,
+};
+
+struct ntb_mw {
+	dma_addr_t phys_addr;
+	void __iomem *vbase;
+	resource_size_t bar_sz;
+};
+
+struct ntb_db_cb {
+	void (*callback) (void *data, int db_num);
+	unsigned int db_num;
+	void *data;
+	struct ntb_device *ndev;
+};
+
+struct ntb_device {
+	struct pci_dev *pdev;
+	struct msix_entry *msix_entries;
+	void __iomem *reg_base;
+	struct ntb_mw mw[NTB_NUM_MW];
+	struct {
+		unsigned int max_spads;
+		unsigned int max_db_bits;
+		unsigned int msix_cnt;
+	} limits;
+	struct {
+		void __iomem *pdb;
+		void __iomem *pdb_mask;

drivers/ntb/ntb_hw.h line 117

Quoted 10 lines
drivers/ntb/ntb_hw.h new file +10 -0
+		void __iomem *sdb;
+		void __iomem *sbar2_xlat;
+		void __iomem *sbar4_xlat;
+		void __iomem *spad_write;
+		void __iomem *spad_read;
+		void __iomem *lnk_cntl;
+		void __iomem *lnk_stat;
+		void __iomem *spci_cmd;
+	} reg_ofs;
+	void *ntb_transport;

Use the real type here please. No void *.

drivers/ntb/ntb_hw.h line 130

Quoted 13 lines
drivers/ntb/ntb_hw.h new file +13 -0
+	void (*event_cb)(void *handle, enum ntb_hw_event event);
+
+	struct ntb_db_cb *db_cb;
+	unsigned char hw_type;
+	unsigned char conn_type;
+	unsigned char dev_type;
+	unsigned char num_msix;
+	unsigned char bits_per_vector;
+	unsigned char max_cbs;
+	unsigned char link_status;
+	struct delayed_work hb_timer;
+	unsigned long last_ts;
+};

Shouldn't this have a 'struct device' embedded it in somewhere?

Quoted 35 lines
drivers/ntb/ntb_hw.h new file +35 -0
+/**
+ * ntb_hw_link_status() - return the hardware link status
+ * @ndev: pointer to ntb_device instance
+ *
+ * Returns true if the hardware is connected to the remote system
+ *
+ * RETURNS: true or false based on the hardware link state
+ */
+static inline bool ntb_hw_link_status(struct ntb_device *ndev)
+{
+	return ndev->link_status == NTB_LINK_UP;
+}
+
+/**
+ * ntb_query_pdev() - return the pci_dev pointer
+ * @ndev: pointer to ntb_device instance
+ *
+ * Given the ntb pointer return the pci_dev pointerfor the NTB hardware device
+ *
+ * RETURNS: a pointer to the ntb pci_dev
+ */
+static inline struct pci_dev *ntb_query_pdev(struct ntb_device *ndev)
+{
+	return ndev->pdev;
+}
+
+/**
+ * ntb_query_max_cbs() - return the maximum number of callback tuples
+ * @ndev: pointer to ntb_device instance
+ *
+ * The number of callbacks can vary depending on the platform and MSI-X/MSI
+ * enablement
+ *
+ * RETURNS: the maximum number of callback tuples (3, 15, or 33)
+ */
Quoted 8 lines

drivers/ntb/ntb_hw.h line 170

Quoted 4 lines
drivers/ntb/ntb_hw.h new file +4 -0
+static inline unsigned int ntb_query_max_cbs(struct ntb_device *ndev)
+{
+	return ndev->max_cbs;
+}

It is shorter, and simpler, to just write the '->variable' version out for this, than to make the function call here. Why are these needed? Especially when I see the driver code not using them. Please remove.

This is used in ntb_transport.c. It is used to show how many interrupts, and there-by clients, the transport layer can have. I can make it a macro and/or put it in a header file, if that suits you better.

Quoted 6 lines

drivers/ntb/ntb_hw.h line 172

Quoted 3 lines
drivers/ntb/ntb_hw.h new file +3 -0
+static void ntb_client_release(struct device *dev)
+{
+}

Ah, how sweet. Now, according to the in-kernel documentation, I get to publicly mock you for trying to be smarter than the kernel. Nice try.

Consider me sufficiently shamed

Quoted 3 lines

Think back to when you wrote this function. Did you really think it was the correct thing to do? If not, why did you do this?

Quick and dirty hack until I had more than one client driver, but I'll implement it properly now.

Quoted 14 lines

Sorry, no.

Quoted 9 lines
drivers/ntb/ntb_hw.h new file +9 -0
+struct bus_type ntb_bus_type = {
+	.name = "ntb_bus",
+	.match = ntb_match_bus,
+	.probe = ntb_client_probe,
+	.remove = ntb_client_remove,
+};
+
+static atomic_t ntb_bus_use = ATOMIC_INIT(0);
+
Quoted 8 lines

drivers/ntb/ntb_hw.h line 186

Quoted 5 lines
drivers/ntb/ntb_hw.h new file +5 -0
+static int __devinit ntb_bus_init(void)
+{
+	int rc;
+
+	if (atomic_inc_return(&ntb_bus_use) == 1) {

That's the wierdest way of using an atomic variable I have ever seen. How could this ever be anything but 0? If you need a lock, use a lock.

The driver is calling ntb_bus_init for every NTB device, but the bus only needs to be done once.

Quoted 8 lines

drivers/ntb/ntb_hw.h line 189

Quoted 4 lines
drivers/ntb/ntb_hw.h new file +3 -0
+static int __devinit ntb_dev_init(struct ntb_transport *nt)
+{
+	struct device *dev = &nt->netdev;

Ah, there's the struct device. Don't call it a 'netdev', that's just really really confusing to anyone who has looked at a network driver. As this isn't a netdev, it's a 'device'.

There currently is only 1 client, which is a virtual networking device. However, I'll correct it to be more generic (per my comment above).

Quoted 47 lines

drivers/ntb/ntb_hw.h

Quoted 9 lines
drivers/ntb/ntb_hw.h new file +8 -0
+	int rc;
+
+	rc = ntb_bus_init();
+	if (rc)
+		goto err;
+
+	/* setup and register client devices */
+	dev_set_name(dev, "ntb_netdev");

All devices get the same name? That's a recipe for confusion.

Quoted 21 lines
drivers/ntb/ntb_hw.h new file +21 -0
+static void ntb_transport_setup_qp_mw(struct ntb_transport *nt,
+				      unsigned int qp_num)
+{
+	struct ntb_transport_qp *qp = &nt->qps[qp_num];
+	u8 mw_num = QP_TO_MW(qp_num);
+	unsigned int size, num_qps_mw;
+
+	WARN_ON(nt->mw[mw_num].virt_addr == 0);
+
+	if (nt->max_qps % NTB_NUM_MW && !mw_num)
+		num_qps_mw = nt->max_qps / NTB_NUM_MW +
+			     (nt->max_qps % NTB_NUM_MW - mw_num);
+	else
+		num_qps_mw = nt->max_qps / NTB_NUM_MW;
+
+	size = nt->mw[mw_num].size / num_qps_mw;
+	pr_debug("orig size = %d, num qps = %d, size = %d\n",
+		 (int) nt->mw[mw_num].size, nt->max_qps, size);
+
+	qp->rx_buff_begin = nt->mw[mw_num].virt_addr +
+			    (qp_num / NTB_NUM_MW * size);

drivers/ntb/ntb_hw.h

Quoted 10 lines
drivers/ntb/ntb_hw.h new file +10 -0
+	qp->rx_buff_end = qp->rx_buff_begin + size;
+	pr_info("QP %d - RX Buff start %p end %p\n", qp->qp_num,
+		qp->rx_buff_begin, qp->rx_buff_end);
+	qp->rx_offset = qp->rx_buff_begin;
+
+	qp->tx_mw_begin = ntb_get_mw_vbase(nt->ndev, mw_num) +
+			  (qp_num / NTB_NUM_MW * size);
+	qp->tx_mw_end = qp->tx_mw_begin + size;
+	pr_info("QP %d - TX MW start %p end %p\n", qp->qp_num, qp->tx_mw_begin,
+		qp->tx_mw_end);

That's some debugging information spamming the kernel log, please remove.

Quoted 2 lines

Also, you have a 'struct device', so use dev_dbg() and friends, not pr_* calls. This should be fixed in lots of places here.

Will do, thanks for taking the time to review.

Thanks,
Jon

Quoted 4 lines

thanks,

greg k-h

#4 lore raw
Quoted 9 lines · Jon Mason
Quoted 8 lines

drivers/ntb/ntb_hw.h line 170

Quoted 4 lines
drivers/ntb/ntb_hw.h new file +4 -0
+static inline unsigned int ntb_query_max_cbs(struct ntb_device *ndev)
+{
+	return ndev->max_cbs;
+}

It is shorter, and simpler, to just write the '->variable' version out for this, than to make the function call here. Why are these needed? Especially when I see the driver code not using them. Please remove.

Quoted 4 lines

This is used in ntb_transport.c. It is used to show how many interrupts, and there-by clients, the transport layer can have. I can make it a macro and/or put it in a header file, if that suits you better.

No, just reference the field of the structure directly, no need for a function or a macro.

thanks,

greg k-h

#5 lore raw
In reply to Jon Mason

drivers/ntb/ntb_hw.c line 1160

Quoted 3 lines · Jon Mason
drivers/ntb/ntb_hw.c new file +3 -0
+static int __init ntb_init_module(void)
+{
+	pr_info("%s: %s, version %s\n", KBUILD_MODNAME, NTB_NAME, NTB_VER);

No need to be noisy.

drivers/ntb/ntb_hw.c line 1170

Quoted 10 lines
drivers/ntb/ntb_hw.c new file +10 -0
+
+	return pci_register_driver(&ntb_pci_driver);
+}
+module_init(ntb_init_module);
+
+static void __exit ntb_exit_module(void)
+{
+	pci_unregister_driver(&ntb_pci_driver);
+
+	pr_info("%s: Driver removed\n", KBUILD_MODNAME);

Same here, don't print out needless things.

drivers/ntb/ntb_hw.c line 1172

Quoted 2 lines
drivers/ntb/ntb_hw.c new file +2 -0
+}
+module_exit(ntb_exit_module);

This all can be wrapped up using the pci_module() macro instead.

thanks,

greg k-h

author
#6 lore raw

PATCH v5 2/2 net: Add support for NTB virtual ethernet device

In reply to Jon Mason

A virtual ethernet device that uses the NTB transport API to send/receive data.

---
 MAINTAINERS              |    1 +
 drivers/net/Kconfig      |    4 +
 drivers/net/Makefile     |    1 +
 drivers/net/ntb_netdev.c |  415 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 421 insertions(+)
 create mode 100644 drivers/net/ntb_netdev.c
MAINTAINERS +1 -0
index e0fc24a..5c3059f 100644
@@ -5148,6 +5148,7 @@ NTB DRIVER
 M:	Jon Mason <[email protected]>
 S:	Supported
 F:	drivers/ntb/
+F:	drivers/net/ntb_netdev.c
 F:	include/linux/ntb.h
 
 NTFS FILESYSTEM
drivers/net/Kconfig +4 -0
index 6a70184..5db9acb 100644
@@ -189,6 +189,10 @@ config NETPOLL_TRAP
 config NET_POLL_CONTROLLER
 	def_bool NETPOLL
 
+config NTB_NETDEV
+	tristate "Virtual Ethernet over NTB"
+	depends on NTB
+
 config RIONET
 	tristate "RapidIO Ethernet over messaging driver support"
 	depends on RAPIDIO
drivers/net/Makefile +1 -0
index 335db78..ef3d090 100644
@@ -71,3 +71,4 @@ obj-$(CONFIG_USB_IPHETH)        += usb/
 obj-$(CONFIG_USB_CDC_PHONET)   += usb/
 
 obj-$(CONFIG_HYPERV_NET) += hyperv/
+obj-$(CONFIG_NTB_NETDEV) += ntb_netdev.o
drivers/net/ntb_netdev.c new file +415 -0

415 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v5 2/2] net: Add support for NTB virtual ethernet device

Quoted 10 lines · Jon Mason

A virtual ethernet device that uses the NTB transport API to send/receive data.

---
 MAINTAINERS              |    1 +
 drivers/net/Kconfig      |    4 +
 drivers/net/Makefile     |    1 +
 drivers/net/ntb_netdev.c |  415 ++++++++++++++++++++++++++++++++++++++++++++++

As I haven't taken the core yet, I can't take this. But even then, I would need an ack from the network maintainers before I could.

And are you sure this is in the correct location in the tree?

thanks,

greg k-h

author
#8 lore raw

Re: [PATCH v5 2/2] net: Add support for NTB virtual ethernet device

Quoted 12 lines · Greg KH
Quoted 10 lines · Jon Mason

A virtual ethernet device that uses the NTB transport API to send/receive data.

---
 MAINTAINERS              |    1 +
 drivers/net/Kconfig      |    4 +
 drivers/net/Makefile     |    1 +
 drivers/net/ntb_netdev.c |  415 ++++++++++++++++++++++++++++++++++++++++++++++
Quoted 2 lines

As I haven't taken the core yet, I can't take this. But even then, I would need an ack from the network maintainers before I could.

I have been Cc'ing netdev on these patches and gotten many good comments, but I can cc Dave Miller explicitly on my next version (as there will obviously need to be one based on your comments on the previous patch).

Quoted 2 lines

And are you sure this is in the correct location in the tree?

I assumed that the virtual network client that uses NTB as a transport would best fit in the network drivers. Is this a bad assumption?

Thanks,
Jon

Quoted 4 lines

thanks,

greg k-h

#9 lore raw

Re: [PATCH v5 2/2] net: Add support for NTB virtual ethernet device

Quoted 13 lines · Jon Mason
Quoted 12 lines · Greg KH
Quoted 10 lines · Jon Mason

A virtual ethernet device that uses the NTB transport API to send/receive data.

---
 MAINTAINERS              |    1 +
 drivers/net/Kconfig      |    4 +
 drivers/net/Makefile     |    1 +
 drivers/net/ntb_netdev.c |  415 ++++++++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
Quoted 2 lines

As I haven't taken the core yet, I can't take this. But even then, I would need an ack from the network maintainers before I could.

I have been Cc'ing netdev on these patches and gotten many good comments, but I can cc Dave Miller explicitly on my next version (as there will obviously need to be one based on your comments on the previous patch).

Don't cc: David, that's not the way to do it :)

Quoted 4 lines
Quoted 1 line

And are you sure this is in the correct location in the tree?

I assumed that the virtual network client that uses NTB as a transport would best fit in the network drivers. Is this a bad assumption?

No, but if you look, drivers/net/ has been cleaned up a bunch, so perhaps a subdirectory under there is best. I'll leave that up to the netdev developers to discuss.

thanks,

greg k-h