PCI-Express Non-Transparent Bridge Support
Subsystems (4)
cover PCI-Express Non-Transparent Bridge Support
I am submitting version 4 of the PCI-Express Non-Transparent Bridge patches for inclusion in 3.7. All outstanding issues from the RFC process 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
Thanks,
Jon
PATCH 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 | 1167 +++++++++++++++++++++++++++++++++++ drivers/ntb/ntb_hw.h | 195 ++++++ drivers/ntb/ntb_regs.h | 139 +++++ drivers/ntb/ntb_transport.c | 1401 +++++++++++++++++++++++++++++++++++++++++++ include/linux/ntb.h | 81 +++ 10 files changed, 3008 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
@@ -4851,6 +4851,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
@@ -152,4 +152,6 @@ source "drivers/vme/Kconfig" source "drivers/pwm/Kconfig" +source "drivers/ntb/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -139,3 +139,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
@@ -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
@@ -0,0 +1,3 @@ +obj-$(CONFIG_NTB) += ntb.o + +ntb-objs := ntb_hw.o ntb_transport.o
drivers/ntb/ntb_hw.c new file +1167 -0
1,167 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 +1401 -0
1,401 lines not on this page · raw message
include/linux/ntb.h new file +81 -0
60 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
Part of the diff is not shown here. View the raw message.
PATCH 2/2 net: Add support for NTB virtual ethernet device
In reply to Jon MasonA virtual ethernet device that uses the NTB transport API to send/receive data.
--- drivers/net/Kconfig | 4 + drivers/net/Makefile | 1 + drivers/net/ntb_netdev.c | 407 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 412 insertions(+) create mode 100644 drivers/net/ntb_netdev.c
drivers/net/Kconfig +4 -0
@@ -178,6 +178,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
@@ -69,3 +69,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 +407 -0
407 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Quoted 10 lines · Jon Mason
I am submitting version 4 of the PCI-Express Non-Transparent Bridge patches for inclusion in 3.7. All outstanding issues from the RFC process have been addressed.
version 1
http://thread.gmane.org/gmane.linux.kernel.pci/16443Version 2 incorporates numerous clean-ups
http://thread.gmane.org/gmane.linux.kernel.pci/16696
Quoted 8 lines
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/17808Version 4 removes the transport transmit tasklet (per Dave Miller's request).
http://thread.gmane.org/gmane.linux.network/244491
Hi Jon,
I'm really excited to see this series merged for v3.7-rc code.
Please feel free to add my:
to the two individual patches for an initial merge. I'm not sure which tree that your intending to take this code upstream via, but also feel free to add my:
of your maintainer-ship of /drivers/ntb/ subsystem code.
Very nice work on this series Jon !
--nab
Hi,
it's good to see some NTB code getting into mainline! I have a few comments though.
On Tue, 02 Oct 2012 21:26:16 -0000, Jon Mason <[email protected]> wrote:
[...]
Quoted 11 lines
+/**
+ *ntb_write_local_spad()- write to the secondary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to the scratchpad register, 0 based
+ * @val: the data value to put into the register
+ *
+ * This function allows writing of a 32bit value to the indexed scratchpad
+ * register. The register resides on the secondary (external) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */
[...]
Quoted 11 lines
+/**
+ *ntb_write_remote_spad()- write to the secondary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to the scratchpad register, 0 based
+ * @val: the data value to put into the register
+ *
+ * This function allows writing of a 32bit value to the indexed scratchpad
+ * register. The register resides on the secondary (external) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */
Those comments look suspiciously similar. I think one of the functions does write to primary scratchpad?
[...]
Quoted 11 lines
+/**
+ *ntb_read_local_spad()- read from the primary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to scratchpad register, 0 based
+ * @val: pointer to 32bit integer for storing the register value
+ *
+ * This function allows reading of the 32bit scratchpad register on
+ * the primary (internal) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */
[...]
Quoted 11 lines
+/**
+ *ntb_read_remote_spad()- read from the primary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to scratchpad register, 0 based
+ * @val: pointer to 32bit integer for storing the register value
+ *
+ * This function allows reading of the 32bit scratchpad register on
+ * the primary (internal) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */
Same here.
[...]
Quoted 28 lines
drivers/ntb/ntb_hw.c new file +28
-0+static int ntb_setup_msix (struct ntb_device *ndev) +{ +struct pci_dev *pdev = ndev->pdev; +struct msix_entry *msix; +int msix_entries; +int rc, i, pos; +u16 val; + + pos =pci_find_capability (pdev,PCI_CAP_ID_MSIX ); +if (!pos) { + rc = -EIO ; + goto err; + } + + rc =pci_read_config_word (pdev, pos +PCI_MSIX_FLAGS , &val); +if (rc) + goto err; + + msix_entries =msix_table_size (val); +if (msix_entries > ndev->limits.msix_cnt) { + rc = -EINVAL ; + goto err; + } + + ndev->msix_entries =kmalloc (sizeof (struct msix_entry ) * msix_entries, +GFP_KERNEL ); +if (!ndev->msix_entries) { + rc = -ENOMEM ;
drivers/ntb/ntb_hw.c line 802
Quoted 10 lines
drivers/ntb/ntb_hw.c new file +10
-0+ goto err; + } + +for (i =0 ; i < msix_entries; i++) + ndev->msix_entries[i].entry = i; + + rc =pci_enable_msix (pdev, ndev->msix_entries, msix_entries); +if (rc <0 ) + goto err1; +if (rc >0 ) {
rc > 0 doesn't mean that vectors were allocated. Have a look at the example in Documentation/PCI/MSI-HOWTO.txt.
drivers/ntb/ntb_hw.c line 809
Quoted 7 lines
drivers/ntb/ntb_hw.c new file +7
-0+/* On SNB, the link interrupt is always tied to 4th vector. If +* we can't get all 4, then we can't use MSI-X. +*/ +if (ndev->hw_type !=BWD_HW ) { + rc = -EIO ; + goto err1; + }
This looks fragile, what if msix_table_size(val) was < 4?
Quoted 49 lines
drivers/ntb/ntb_hw.c new file +49
-0+ +dev_warn (&pdev->dev, +"Only %d MSI-X vectors. Limiting the number of queues to that number.\n" , + rc); + msix_entries = rc; + } + +for (i =0 ; i < msix_entries; i++) { + msix = &ndev->msix_entries[i]; +WARN_ON (!msix->vector); + +/* Use the last MSI-X vector for Link status */ +if (ndev->hw_type ==BWD_HW ) { + rc =request_irq (msix->vector, bwd_callback_msix_irq,0 , +"ntb-callback-msix" , &ndev->db_cb[i]); +if (rc) + goto err2; + }else { +if (i == msix_entries -1 ) { + rc =request_irq (msix->vector, + xeon_event_msix_irq,0 , +"ntb-event-msix" , ndev); +if (rc) + goto err2; + }else { + rc =request_irq (msix->vector, + xeon_callback_msix_irq,0 , +"ntb-callback-msix" , + &ndev->db_cb[i]); +if (rc) + goto err2; + } + } + } + + ndev->num_msix = msix_entries; +if (ndev->hw_type ==BWD_HW ) + ndev->max_cbs = msix_entries; +else + ndev->max_cbs = msix_entries -1 ; + +return 0 ; + +err2: +while (--i >=0 ) { + msix = &ndev->msix_entries[i]; +if (ndev->hw_type !=BWD_HW && i == ndev->num_msix -1 ) +free_irq (msix->vector, ndev); +else
drivers/ntb/ntb_hw.c line 868
Quoted 10 lines
drivers/ntb/ntb_hw.c new file +10
-0+free_irq (msix->vector, &ndev->db_cb[i]); + } +pci_disable_msix (pdev); +err1: +kfree (ndev->msix_entries); +dev_err (&pdev->dev,"Error allocating MSI-X interrupt\n" ); +err: + ndev->num_msix =0 ; +return rc; +}
Thanks for your work,
-- Kuba
Quoted 33 lines · Jakub Kicinski
Hi,
it's good to see some NTB code getting into mainline! I have a few comments though.
On Tue, 02 Oct 2012 21:26:16 -0000, Jon Mason <[email protected]> wrote:
[...]
Quoted 11 lines
+/**
+ *ntb_write_local_spad()- write to the secondary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to the scratchpad register, 0 based
+ * @val: the data value to put into the register
+ *
+ * This function allows writing of a 32bit value to the indexed scratchpad
+ * register. The register resides on the secondary (external) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */[...]
Quoted 11 lines
+/**
+ *ntb_write_remote_spad()- write to the secondary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to the scratchpad register, 0 based
+ * @val: the data value to put into the register
+ *
+ * This function allows writing of a 32bit value to the indexed scratchpad
+ * register. The register resides on the secondary (external) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */
Quoted 2 lines
Those comments look suspiciously similar. I think one of the functions does write to primary scratchpad?
Yes, the comments can be improved.
Quoted 62 lines
[...]
Quoted 11 lines
+/**
+ *ntb_read_local_spad()- read from the primary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to scratchpad register, 0 based
+ * @val: pointer to 32bit integer for storing the register value
+ *
+ * This function allows reading of the 32bit scratchpad register on
+ * the primary (internal) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */[...]
Quoted 11 lines
+/**
+ *ntb_read_remote_spad()- read from the primary scratchpad register
+ * @ndev: pointer tontb_deviceinstance
+ * @idx: index to scratchpad register, 0 based
+ * @val: pointer to 32bit integer for storing the register value
+ *
+ * This function allows reading of the 32bit scratchpad register on
+ * the primary (internal) side.
+ *
+ * RETURNS: An appropriate-ERRNOerror value on error, or zero for success.
+ */Same here.
[...]
Quoted 33 lines
drivers/ntb/ntb_hw.c new file +33
-0+static int ntb_setup_msix (struct ntb_device *ndev) +{ +struct pci_dev *pdev = ndev->pdev; +struct msix_entry *msix; +int msix_entries; +int rc, i, pos; +u16 val; + + pos =pci_find_capability (pdev,PCI_CAP_ID_MSIX ); +if (!pos) { + rc = -EIO ; + goto err; + } + + rc =pci_read_config_word (pdev, pos +PCI_MSIX_FLAGS , &val); +if (rc) + goto err; + + msix_entries =msix_table_size (val); +if (msix_entries > ndev->limits.msix_cnt) { + rc = -EINVAL ; + goto err; + } + + ndev->msix_entries =kmalloc (sizeof (struct msix_entry ) * msix_entries, +GFP_KERNEL ); +if (!ndev->msix_entries) { + rc = -ENOMEM ; + goto err; + } + +for (i =0 ; i < msix_entries; i++) + ndev->msix_entries[i].entry = i;
Quoted 8 lines
drivers/ntb/ntb_hw.c line 802
Quoted 5 lines
drivers/ntb/ntb_hw.c new file +5
-0+ + rc =pci_enable_msix (pdev, ndev->msix_entries, msix_entries); +if (rc <0 ) + goto err1; +if (rc >0 ) {rc > 0 doesn't mean that vectors were allocated. Have a look at the example in
Documentation/PCI/MSI-HOWTO.txt.
Thank you, I will correct this.
Quoted 10 lines
drivers/ntb/ntb_hw.c line 809
Quoted 8 lines
drivers/ntb/ntb_hw.c new file +7
-0+/* On SNB, the link interrupt is always tied to 4th vector. If +* we can't get all 4, then we can't use MSI-X. +*/ +if (ndev->hw_type !=BWD_HW ) { + rc = -EIO ; + goto err1; + }This looks fragile, what if
msix_table_size(val)was < 4?
If there are not at least 4 vectors, then we shouldn't use MSI-X.
Quoted 54 lines
Quoted 54 lines
drivers/ntb/ntb_hw.c new file +53
-0+ +dev_warn (&pdev->dev, +"Only %d MSI-X vectors. Limiting the number of queues to that number.\n" , + rc); + msix_entries = rc; + } + +for (i =0 ; i < msix_entries; i++) { + msix = &ndev->msix_entries[i]; +WARN_ON (!msix->vector); + +/* Use the last MSI-X vector for Link status */ +if (ndev->hw_type ==BWD_HW ) { + rc =request_irq (msix->vector, bwd_callback_msix_irq,0 , +"ntb-callback-msix" , &ndev->db_cb[i]); +if (rc) + goto err2; + }else { +if (i == msix_entries -1 ) { + rc =request_irq (msix->vector, + xeon_event_msix_irq,0 , +"ntb-event-msix" , ndev); +if (rc) + goto err2; + }else { + rc =request_irq (msix->vector, + xeon_callback_msix_irq,0 , +"ntb-callback-msix" , + &ndev->db_cb[i]); +if (rc) + goto err2; + } + } + } + + ndev->num_msix = msix_entries; +if (ndev->hw_type ==BWD_HW ) + ndev->max_cbs = msix_entries; +else + ndev->max_cbs = msix_entries -1 ; + +return 0 ; + +err2: +while (--i >=0 ) { + msix = &ndev->msix_entries[i]; +if (ndev->hw_type !=BWD_HW && i == ndev->num_msix -1 ) +free_irq (msix->vector, ndev); +else +free_irq (msix->vector, &ndev->db_cb[i]); + } +pci_disable_msix (pdev); +err1:
Quoted 8 lines
drivers/ntb/ntb_hw.c line 868
Quoted 6 lines
drivers/ntb/ntb_hw.c new file +6
-0+kfree (ndev->msix_entries); +dev_err (&pdev->dev,"Error allocating MSI-X interrupt\n" ); +err: + ndev->num_msix =0 ; +return rc; +}Thanks for your work,
Thanks for the review.
Quoted 2 lines
-- Kuba
Hi Jon & Co,
Quoted 10 lines · Jon Mason
I am submitting version 4 of the PCI-Express Non-Transparent Bridge patches for inclusion in 3.7. All outstanding issues from the RFC process have been addressed.
version 1
http://thread.gmane.org/gmane.linux.kernel.pci/16443Version 2 incorporates numerous clean-ups
http://thread.gmane.org/gmane.linux.kernel.pci/16696
Quoted 8 lines
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/17808Version 4 removes the transport transmit tasklet (per Dave Miller's request).
http://thread.gmane.org/gmane.linux.network/244491
I'm very happy with the current state of the new NTB subsystem code for an initial merge.
As we are t-minus ~5 days until the v3.7 merge window closes, you'll want to (very soon) be sending a PULL request to Linus for drivers/ntb/ with the appropriate Reviewed-By's + Acked-By's in place.
--nab