PCI-Express Non-Transparent Bridge Support
Subsystems (4)
RFC 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 | 1283 +++++++++++++++++++++++++++++++++++++++++++ drivers/ntb/ntb_hw.h | 115 ++++ drivers/ntb/ntb_regs.h | 150 +++++ drivers/ntb/ntb_transport.c | 1283 +++++++++++++++++++++++++++++++++++++++++++ include/linux/ntb.h | 78 +++ 10 files changed, 2934 insertions(+), 0 deletions(-) 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
@@ -4818,6 +4818,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
@@ -148,4 +148,6 @@ source "drivers/iio/Kconfig" source "drivers/vme/Kconfig" +source "drivers/ntb/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -137,3 +137,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 +1283 -0
1,283 lines not on this page · raw message
drivers/ntb/ntb_hw.h new file +115 -0
115 lines not on this page · raw message
drivers/ntb/ntb_regs.h new file +150 -0
150 lines not on this page · raw message
drivers/ntb/ntb_transport.c new file +1283 -0
1,283 lines not on this page · raw message
include/linux/ntb.h new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
1.7.5.4
RFC 2/2 net: Add support for NTB virtual ethernet device
A 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 | 411 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 0 deletions(-) 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 +411 -0
411 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [RFC 2/2] net: Add support for NTB virtual ethernet device
Quoted 94 lines · Fri, Jul 13, 2012 at 11:45:00PM CEST, [email protected] wrote:
A virtual ethernet device that uses the NTB transport API to send/receive data.
Signed-off-by Jon Mason <[email protected]>---
drivers/net/Kconfig | 4 + drivers/net/Makefile | 1 + drivers/net/ntb_netdev.c | 411 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 0 deletions(-)create mode 100644
drivers/net/ntb_netdev.cdrivers/net/Kconfig +0
-0@@ -178,6 +178,10 @@ config NETPOLL_TRAPconfig
NET_POLL_CONTROLLER
def_boolNETPOLLdrivers/net/Kconfig +4
-0+config NTB_NETDEV + tristate "Virtual Ethernet over NTB" + depends on NTB +config RIONET
tristate "RapidIO Ethernet over messaging driver support" depends on RAPIDIOdrivers/net/Makefile +0
-0@@ -69,3 +69,4 @@ obj-$(CONFIG_USB_IPHETH) += usb/obj-$(CONFIG_USB_CDC_PHONET) += usb/
obj-$(CONFIG_HYPERV_NET) += hyperv/
drivers/net/Makefile +1
-0+obj-$(CONFIG_NTB_NETDEV) += ntb_netdev.odrivers/net/ntb_netdev.c new file +54
-0@@ -0,0 +1,411 @@ +/* +* 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. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +* The full GNU General Public License is included in this distribution +* in the file called LICENSE.GPL. +* +* 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 Network Linux driver
drivers/net/ntb_netdev.c line 64
Quoted 10 lines
drivers/net/ntb_netdev.c new file +10
-0+* +* Contact Information: +* Jon Mason <[email protected]> +*/ +#include <linux/etherdevice.h> +#include <linux/ethtool.h> +#include <linux/module.h> +#include <linux/ntb.h> + +#define NTB_NETDEV_VER "0.4"
Is it really necessary to provide this in-file versioning? Doesn't kernel version itself do the trick?
Quoted 194 lines
drivers/net/ntb_netdev.c new file +194
-0+ +MODULE_DESCRIPTION (KBUILD_MODNAME ); +MODULE_VERSION (NTB_NETDEV_VER ); +MODULE_LICENSE ("Dual BSD/GPL" ); +MODULE_AUTHOR ("Intel Corporation" ); + +struct ntb_netdev { +struct net_device *ndev; +struct ntb_transport_qp *qp; +}; + +#define NTB_TX_TIMEOUT_MS 1000 +#define NTB_RXQ_SIZE 100 + +static struct net_device *netdev; + +static void ntb_netdev_event_handler (int status) +{ +struct ntb_netdev *dev =netdev_priv (netdev); + +pr_debug ("%s: Event %x, Link %x\n" ,KBUILD_MODNAME , status, +ntb_transport_link_query (dev->qp)); + +/* Currently, only link status event is supported */ +if (status) +netif_carrier_on (netdev); +else +netif_carrier_off (netdev); +} + +static void ntb_netdev_rx_handler (struct ntb_transport_qp *qp) +{ +struct net_device *ndev = netdev; +struct sk_buff *skb; +int len, rc; + +while ((skb =ntb_transport_rx_dequeue (qp, &len))) { +pr_debug ("%s: %d byte payload received\n" , __func__, len); + +skb_put (skb, len); + skb->protocol =eth_type_trans (skb, ndev); + skb->ip_summed =CHECKSUM_NONE ; + +if (netif_rx (skb) ==NET_RX_DROP ) { + ndev->stats.rx_errors++; + ndev->stats.rx_dropped++; + }else { + ndev->stats.rx_packets++; + ndev->stats.rx_bytes += len; + } + + skb =netdev_alloc_skb (ndev, ndev->mtu +ETH_HLEN ); +if (!skb) { + ndev->stats.rx_errors++; + ndev->stats.rx_frame_errors++; +pr_err ("%s: No skb\n" , __func__); +break ; + } + + rc =ntb_transport_rx_enqueue (qp, skb, skb->data, + ndev->mtu +ETH_HLEN ); +if (rc) { + ndev->stats.rx_errors++; + ndev->stats.rx_fifo_errors++; +pr_err ("%s: error re-enqueuing\n" , __func__); +break ; + } + } +} + +static void ntb_netdev_tx_handler (struct ntb_transport_qp *qp) +{ +struct net_device *ndev = netdev; +struct sk_buff *skb; +int len; + +while ((skb =ntb_transport_tx_dequeue (qp, &len))) { + ndev->stats.tx_packets++; + ndev->stats.tx_bytes += skb->len; +dev_kfree_skb (skb); + } + +if (netif_queue_stopped (ndev)) +netif_wake_queue (ndev); +} + +static netdev_tx_t ntb_netdev_start_xmit (struct sk_buff *skb, +struct net_device *ndev) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +int rc; + +pr_debug ("%s: ntb_transport_tx_enqueue\n" ,KBUILD_MODNAME ); + + rc =ntb_transport_tx_enqueue (dev->qp, skb, skb->data, skb->len); +if (rc) + goto err; + +return NETDEV_TX_OK ; + +err: + ndev->stats.tx_dropped++; + ndev->stats.tx_errors++; +netif_stop_queue (ndev); +return NETDEV_TX_BUSY ; +} + +static int ntb_netdev_open (struct net_device *ndev) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +struct sk_buff *skb; +int rc, i, len; + +/* Add some empty rx bufs */ +for (i =0 ; i <NTB_RXQ_SIZE ; i++) { + skb =netdev_alloc_skb (ndev, ndev->mtu +ETH_HLEN ); +if (!skb) { + rc = -ENOMEM ; + goto err; + } + + rc =ntb_transport_rx_enqueue (dev->qp, skb, skb->data, + ndev->mtu +ETH_HLEN ); +if (rc == -EINVAL ) + goto err; + } + +netif_carrier_off (ndev); +ntb_transport_link_up (dev->qp); + +return 0 ; + +err: +while ((skb =ntb_transport_rx_remove (dev->qp, &len))) +kfree (skb); +return rc; +} + +static int ntb_netdev_close (struct net_device *ndev) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +struct sk_buff *skb; +int len; + +ntb_transport_link_down (dev->qp); + +while ((skb =ntb_transport_rx_remove (dev->qp, &len))) +kfree (skb); + +return 0 ; +} + +static int ntb_netdev_change_mtu (struct net_device *ndev,int new_mtu) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +struct sk_buff *skb; +int len, rc; + +if (new_mtu >ntb_transport_max_size (dev->qp) -ETH_HLEN ) +return -EINVAL ; + +if (!netif_running (ndev)) { + ndev->mtu = new_mtu; +return 0 ; + } + +/* Bring down the link and dispose of posted rx entries */ +ntb_transport_link_down (dev->qp); + +if (ndev->mtu < new_mtu) { +int i; + +for (i =0 ; (skb =ntb_transport_rx_remove (dev->qp, &len)); i++) +kfree (skb); + +for (; i; i--) { + skb =netdev_alloc_skb (ndev, new_mtu +ETH_HLEN ); +if (!skb) { + rc = -ENOMEM ; + goto err; + } + + rc =ntb_transport_rx_enqueue (dev->qp, skb, skb->data, + new_mtu +ETH_HLEN ); +if (rc) { +kfree (skb); + goto err; + } + } + } + + ndev->mtu = new_mtu; + +ntb_transport_link_up (dev->qp);
drivers/net/ntb_netdev.c line 268
Quoted 10 lines
drivers/net/ntb_netdev.c new file +10
-0+ +return 0 ; + +err: +ntb_transport_link_down (dev->qp); + +while ((skb =ntb_transport_rx_remove (dev->qp, &len))) +kfree (skb); + +pr_err ("Error changing MTU, device inoperable\n" );
Would be maybe better to use netdev_err here (and on similar other places)
Also, it might be good to provide rollback in case any of netdev_alloc_skb() fails.
Quoted 6 lines
drivers/net/ntb_netdev.c new file +6
-0+return rc; +} + +static void ntb_netdev_tx_timeout (struct net_device *ndev) +{ +if (netif_running (ndev))
drivers/net/ntb_netdev.c line 284
Quoted 10 lines
drivers/net/ntb_netdev.c new file +10
-0+netif_wake_queue (ndev); +} + +static const struct net_device_ops ntb_netdev_ops = { + .ndo_open = ntb_netdev_open, + .ndo_stop = ntb_netdev_close, + .ndo_start_xmit = ntb_netdev_start_xmit, + .ndo_change_mtu = ntb_netdev_change_mtu, + .ndo_tx_timeout = ntb_netdev_tx_timeout, + .ndo_set_mac_address = eth_mac_addr,
Does your device support mac change while it's up and running?
Quoted 65 lines
drivers/net/ntb_netdev.c new file +65
-0+}; + +static void ntb_get_drvinfo (__attribute__((unused))struct net_device *dev, +struct ethtool_drvinfo *info) +{ +strlcpy (info->driver,KBUILD_MODNAME ,sizeof (info->driver)); +strlcpy (info->version,NTB_NETDEV_VER ,sizeof (info->version)); +} + +static const char ntb_nic_stats[][ETH_GSTRING_LEN ] = { +"rx_packets" ,"rx_bytes" ,"rx_errors" ,"rx_dropped" ,"rx_length_errors" , +"rx_frame_errors" ,"rx_fifo_errors" , +"tx_packets" ,"tx_bytes" ,"tx_errors" ,"tx_dropped" , +}; + +static int ntb_get_stats_count (__attribute__((unused))struct net_device *dev) +{ +return ARRAY_SIZE (ntb_nic_stats); +} + +static int ntb_get_sset_count (struct net_device *dev,int sset) +{ +switch (sset) { +case ETH_SS_STATS : +return ntb_get_stats_count (dev); +default : +return -EOPNOTSUPP ; + } +} + +static void ntb_get_strings (__attribute__((unused))struct net_device *dev, +u32 sset,u8 *data) +{ +switch (sset) { +case ETH_SS_STATS : +memcpy (data, *ntb_nic_stats,sizeof (ntb_nic_stats)); + } +} + +static void +ntb_get_ethtool_stats (struct net_device *dev, + __attribute__((unused))struct ethtool_stats *stats, +u64 *data) +{ +int i =0 ; + + data[i++] = dev->stats.rx_packets; + data[i++] = dev->stats.rx_bytes; + data[i++] = dev->stats.rx_errors; + data[i++] = dev->stats.rx_dropped; + data[i++] = dev->stats.rx_length_errors; + data[i++] = dev->stats.rx_frame_errors; + data[i++] = dev->stats.rx_fifo_errors; + data[i++] = dev->stats.tx_packets; + data[i++] = dev->stats.tx_bytes; + data[i++] = dev->stats.tx_errors; + data[i++] = dev->stats.tx_dropped; +} + +static const struct ethtool_ops ntb_ethtool_ops = { + .get_drvinfo = ntb_get_drvinfo, + .get_sset_count = ntb_get_sset_count, + .get_strings = ntb_get_strings, + .get_ethtool_stats = ntb_get_ethtool_stats, + .get_link = ethtool_op_get_link,
drivers/net/ntb_netdev.c line 359
Quoted 10 lines
drivers/net/ntb_netdev.c new file +10
-0+}; + +static int __init ntb_netdev_init_module (void ) +{ +struct ntb_netdev *dev; +int rc; + +pr_info ("%s: Probe\n" ,KBUILD_MODNAME ); + + netdev =alloc_etherdev (sizeof (struct ntb_netdev ));
I might be missing something but this place (module init) does not seems like a good place to do alloc_etherdev(). Do you want to support only one netdevice instance?
Anyway, I think that using "static netdev" should be avoided in any case.
Quoted 59 lines
drivers/net/ntb_netdev.c new file +52
-0+if (!netdev) +return -ENOMEM ; + + dev =netdev_priv (netdev); + dev->ndev = netdev; + netdev->features =NETIF_F_HIGHDMA ; + + netdev->hw_features = netdev->features; + netdev->watchdog_timeo =msecs_to_jiffies (NTB_TX_TIMEOUT_MS ); + +random_ether_addr (netdev->perm_addr); +memcpy (netdev->dev_addr, netdev->perm_addr, netdev->addr_len); + + netdev->netdev_ops = &ntb_netdev_ops; +SET_ETHTOOL_OPS (netdev, &ntb_ethtool_ops); + + dev->qp =ntb_transport_create_queue (ntb_netdev_rx_handler, + ntb_netdev_tx_handler, + ntb_netdev_event_handler); +if (!dev->qp) { + rc = -EIO ; + goto err; + } + + netdev->mtu =ntb_transport_max_size (dev->qp) -ETH_HLEN ; + + rc =register_netdev (netdev); +if (rc) + goto err1; + +pr_info ("%s: %s created\n" ,KBUILD_MODNAME , netdev->name); +return 0 ; + +err1: +ntb_transport_free_queue (dev->qp); +err: +free_netdev (netdev); +return rc; +} +module_init (ntb_netdev_init_module); + +static void __exit ntb_netdev_exit_module(void) +{ +struct ntb_netdev *dev =netdev_priv (netdev); + +unregister_netdev (netdev); +ntb_transport_free_queue (dev->qp); +free_netdev (netdev); + +pr_info ("%s: Driver removed\n" ,KBUILD_MODNAME ); +} +module_exit (ntb_netdev_exit_module);Signature · 6 lines
1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 28 lines · On Fri, 13 Jul 2012 14:44:59 -0700 Jon Mason <[email protected]> wrote:
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.
Signed-off-by Jon Mason <[email protected]>
drivers/ntb/ntb_hw.c line 78
Quoted 4 lines
drivers/ntb/ntb_hw.c new file +4
-0+ +static int max_num_cbs =2 ; +module_param (max_num_cbs, uint,0644 ); +MODULE_PARM_DESC (max_num_cbs,"Maximum number of NTB transport connections" );
Rather than making it a fixed size, could you dynamically set these up with rtnl_link_ops?
Quoted 1 line
+static struct
ntb_device*ntbdev;
What about multiple boards in system?
drivers/ntb/ntb_hw.c line 178
Quoted 13 lines
drivers/ntb/ntb_hw.c new file +13
-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 +*/ +bool ntb_hw_link_status (struct ntb_device *ndev) +{ +return ndev->link_status ==NTB_LINK_UP ; +} +EXPORT_SYMBOL (ntb_hw_link_status);
Why isn't this inline in some header?
Quoted 63 lines
drivers/ntb/ntb_hw.c new file +63
-0+/** +* 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 +*/ +struct pci_dev *ntb_query_pdev (struct ntb_device *ndev) +{ +return ndev->pdev; +} +EXPORT_SYMBOL (ntb_query_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) +*/ +unsigned int ntb_query_max_cbs (struct ntb_device *ndev) +{ +return ndev->max_cbs > max_num_cbs ? max_num_cbs : ndev->max_cbs; +} +EXPORT_SYMBOL (ntb_query_max_cbs); + +/** +* ntb_register_event_callback() - register event callback +* @ndev: pointer to ntb_device instance +* @func: callback function to register +* +* This function registers a callback for any HW driver events such as link +* up/down, power management notices and etc. +* +* RETURNS: An appropriate -ERRNO error value on error, or zero for success. +*/ +int ntb_register_event_callback (struct ntb_device *ndev, +void (*func)(void *handle,unsigned int event)) +{ +if (ndev->event_cb) +return -EINVAL ; + + ndev->event_cb = func; + +return 0 ; +} +EXPORT_SYMBOL (ntb_register_event_callback); + +/** +* ntb_unregister_event_callback() - unregisters the event callback +* @ndev: pointer to ntb_device instance +* +* This function unregisters the existing callback from transport +*/ +void ntb_unregister_event_callback (struct ntb_device *ndev) +{ + ndev->event_cb =NULL ; +} +EXPORT_SYMBOL (ntb_unregister_event_callback); +
Re: [RFC 2/2] net: Add support for NTB virtual ethernet device
In reply to Jon MasonQuoted 57 lines · On Fri, 13 Jul 2012 14:45:00 -0700 Jon Mason <[email protected]> wrote:
A virtual ethernet device that uses the NTB transport API to send/receive data.
Signed-off-by Jon Mason <[email protected]>--- drivers/net/Kconfig | 4 + drivers/net/Makefile | 1 + drivers/net/ntb_netdev.c | 411 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 0 deletions(-) create mode 100644 drivers/net/ntb_netdev.cdrivers/net/ntb_netdev.c new file +46
-0+static void ntb_get_drvinfo (__attribute__((unused))struct net_device *dev, +struct ethtool_drvinfo *info) +{ +strlcpy (info->driver,KBUILD_MODNAME ,sizeof (info->driver)); +strlcpy (info->version,NTB_NETDEV_VER ,sizeof (info->version)); +} + +static const char ntb_nic_stats[][ETH_GSTRING_LEN ] = { +"rx_packets" ,"rx_bytes" ,"rx_errors" ,"rx_dropped" ,"rx_length_errors" , +"rx_frame_errors" ,"rx_fifo_errors" , +"tx_packets" ,"tx_bytes" ,"tx_errors" ,"tx_dropped" , +}; + +static int ntb_get_stats_count (__attribute__((unused))struct net_device *dev) +{ +return ARRAY_SIZE (ntb_nic_stats); +} + +static int ntb_get_sset_count (struct net_device *dev,int sset) +{ +switch (sset) { +case ETH_SS_STATS : +return ntb_get_stats_count (dev); +default : +return -EOPNOTSUPP ; + } +} + +static void ntb_get_strings (__attribute__((unused))struct net_device *dev, +u32 sset,u8 *data) +{ +switch (sset) { +case ETH_SS_STATS : +memcpy (data, *ntb_nic_stats,sizeof (ntb_nic_stats)); + } +} + +static void +ntb_get_ethtool_stats (struct net_device *dev, + __attribute__((unused))struct ethtool_stats *stats, +u64 *data) +{ +int i =0 ; + + data[i++] = dev->stats.rx_packets; + data[i++] = dev->stats.rx_bytes;
drivers/net/ntb_netdev.c line 342
Quoted 10 lines
drivers/net/ntb_netdev.c new file +10
-0+ data[i++] = dev->stats.rx_errors; + data[i++] = dev->stats.rx_dropped; + data[i++] = dev->stats.rx_length_errors; + data[i++] = dev->stats.rx_frame_errors; + data[i++] = dev->stats.rx_fifo_errors; + data[i++] = dev->stats.tx_packets; + data[i++] = dev->stats.tx_bytes; + data[i++] = dev->stats.tx_errors; + data[i++] = dev->stats.tx_dropped; +}
These statistics add no value over existing network stats. Don't implement ethtool stats unless device has something more interesting to say.
drivers/net/ntb_netdev.c line 350
Quoted 7 lines
drivers/net/ntb_netdev.c new file +7
-0+static const struct ethtool_ops ntb_ethtool_ops = { + .get_drvinfo = ntb_get_drvinfo, + .get_sset_count = ntb_get_sset_count, + .get_strings = ntb_get_strings, + .get_ethtool_stats = ntb_get_ethtool_stats, + .get_link = ethtool_op_get_link, +};
If you want to implement bonding or bridging then implementing get_settings would help.
drivers/net/ntb_netdev.c line 357
Quoted 6 lines
drivers/net/ntb_netdev.c new file +6
-0+static int __init ntb_netdev_init_module (void ) +{ +struct ntb_netdev *dev; +int rc; + +pr_info ("%s: Probe\n" ,KBUILD_MODNAME );
Useless message
Quoted 53 lines
drivers/net/ntb_netdev.c new file +53
-0+ netdev =alloc_etherdev (sizeof (struct ntb_netdev )); +if (!netdev) +return -ENOMEM ; + + dev =netdev_priv (netdev); + dev->ndev = netdev; + netdev->features =NETIF_F_HIGHDMA ; + + netdev->hw_features = netdev->features; + netdev->watchdog_timeo =msecs_to_jiffies (NTB_TX_TIMEOUT_MS ); + +random_ether_addr (netdev->perm_addr); +memcpy (netdev->dev_addr, netdev->perm_addr, netdev->addr_len); + + netdev->netdev_ops = &ntb_netdev_ops; +SET_ETHTOOL_OPS (netdev, &ntb_ethtool_ops); + + dev->qp =ntb_transport_create_queue (ntb_netdev_rx_handler, + ntb_netdev_tx_handler, + ntb_netdev_event_handler); +if (!dev->qp) { + rc = -EIO ; + goto err; + } + + netdev->mtu =ntb_transport_max_size (dev->qp) -ETH_HLEN ; + + rc =register_netdev (netdev); +if (rc) + goto err1; + +pr_info ("%s: %s created\n" ,KBUILD_MODNAME , netdev->name); +return 0 ; + +err1: +ntb_transport_free_queue (dev->qp); +err: +free_netdev (netdev); +return rc; +} +module_init (ntb_netdev_init_module); + +static void __exit ntb_netdev_exit_module(void) +{ +struct ntb_netdev *dev =netdev_priv (netdev); + +unregister_netdev (netdev); +ntb_transport_free_queue (dev->qp); +free_netdev (netdev); + +pr_info ("%s: Driver removed\n" ,KBUILD_MODNAME ); +} +module_exit (ntb_netdev_exit_module);
Quoted 26 lines · On Fri, 13 Jul 2012 14:44:59 -0700 Jon Mason <[email protected]> wrote:
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.
Quoted 1 line
Signed-off-by Jon Mason <[email protected]>
This driver does some reimplementing of standard type operations is this because you are trying to use the same code on multiple platforms?
Example:
+
+static void ntb_list_add_head(spinlock_t *lock, struct list_head *entry,
+ struct list_head *list)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(lock, flags);
+ list_add(entry, list);
+ spin_unlock_irqrestore(lock, flags);
+}
+
+static void ntb_list_add_tail(spinlock_t *lock, struct list_head *entry,
+ struct list_head *list)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(lock, flags);
+ list_add_tail(entry, list);
+ spin_unlock_irqrestore(lock, flags);
+}
Which are used on skb's and yet we already have sk_buff_head with locking?
I know you probably are committed to this API, but is there some way to reuse existing shared memory used by virtio-net between two ports?
Re: [RFC 2/2] net: Add support for NTB virtual ethernet device
In reply to Jiri PirkoQuoted 100 lines · Jiri Pirko
Quoted 99 lines · Fri, Jul 13, 2012 at 11:45:00PM CEST, [email protected] wrote:
A virtual ethernet device that uses the NTB transport API to send/receive data.
Signed-off-by Jon Mason <[email protected]>---
drivers/net/Kconfig | 4 + drivers/net/Makefile | 1 + drivers/net/ntb_netdev.c | 411 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 0 deletions(-)create mode 100644
drivers/net/ntb_netdev.cdrivers/net/Kconfig +0
-0@@ -178,6 +178,10 @@ config NETPOLL_TRAPconfig
NET_POLL_CONTROLLER
def_boolNETPOLLdrivers/net/Kconfig +4
-0+config NTB_NETDEV + tristate "Virtual Ethernet over NTB" + depends on NTB +config RIONET
tristate "RapidIO Ethernet over messaging driver support" depends on RAPIDIOdrivers/net/Makefile +0
-0@@ -69,3 +69,4 @@ obj-$(CONFIG_USB_IPHETH) += usb/obj-$(CONFIG_USB_CDC_PHONET) += usb/
obj-$(CONFIG_HYPERV_NET) += hyperv/
drivers/net/Makefile +1
-0+obj-$(CONFIG_NTB_NETDEV) += ntb_netdev.odrivers/net/ntb_netdev.c new file +59
-0@@ -0,0 +1,411 @@ +/* +* 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. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +* The full GNU General Public License is included in this distribution +* in the file called LICENSE.GPL. +* +* 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 Network Linux driver +* +* Contact Information: +* Jon Mason <[email protected]> +*/ +#include <linux/etherdevice.h>
Quoted 8 lines
drivers/net/ntb_netdev.c line 64
Quoted 5 lines
drivers/net/ntb_netdev.c new file +5
-0+#include <linux/ethtool.h> +#include <linux/module.h> +#include <linux/ntb.h> + +#define NTB_NETDEV_VER "0.4"Is it really necessary to provide this in-file versioning? Doesn't kernel version itself do the trick?
Not necessarily. This may be distributed as a package outside of the kernel and the version is useful for debug.
Quoted 200 lines
Quoted 200 lines
drivers/net/ntb_netdev.c new file +199
-0+ +MODULE_DESCRIPTION (KBUILD_MODNAME ); +MODULE_VERSION (NTB_NETDEV_VER ); +MODULE_LICENSE ("Dual BSD/GPL" ); +MODULE_AUTHOR ("Intel Corporation" ); + +struct ntb_netdev { +struct net_device *ndev; +struct ntb_transport_qp *qp; +}; + +#define NTB_TX_TIMEOUT_MS 1000 +#define NTB_RXQ_SIZE 100 + +static struct net_device *netdev; + +static void ntb_netdev_event_handler (int status) +{ +struct ntb_netdev *dev =netdev_priv (netdev); + +pr_debug ("%s: Event %x, Link %x\n" ,KBUILD_MODNAME , status, +ntb_transport_link_query (dev->qp)); + +/* Currently, only link status event is supported */ +if (status) +netif_carrier_on (netdev); +else +netif_carrier_off (netdev); +} + +static void ntb_netdev_rx_handler (struct ntb_transport_qp *qp) +{ +struct net_device *ndev = netdev; +struct sk_buff *skb; +int len, rc; + +while ((skb =ntb_transport_rx_dequeue (qp, &len))) { +pr_debug ("%s: %d byte payload received\n" , __func__, len); + +skb_put (skb, len); + skb->protocol =eth_type_trans (skb, ndev); + skb->ip_summed =CHECKSUM_NONE ; + +if (netif_rx (skb) ==NET_RX_DROP ) { + ndev->stats.rx_errors++; + ndev->stats.rx_dropped++; + }else { + ndev->stats.rx_packets++; + ndev->stats.rx_bytes += len; + } + + skb =netdev_alloc_skb (ndev, ndev->mtu +ETH_HLEN ); +if (!skb) { + ndev->stats.rx_errors++; + ndev->stats.rx_frame_errors++; +pr_err ("%s: No skb\n" , __func__); +break ; + } + + rc =ntb_transport_rx_enqueue (qp, skb, skb->data, + ndev->mtu +ETH_HLEN ); +if (rc) { + ndev->stats.rx_errors++; + ndev->stats.rx_fifo_errors++; +pr_err ("%s: error re-enqueuing\n" , __func__); +break ; + } + } +} + +static void ntb_netdev_tx_handler (struct ntb_transport_qp *qp) +{ +struct net_device *ndev = netdev; +struct sk_buff *skb; +int len; + +while ((skb =ntb_transport_tx_dequeue (qp, &len))) { + ndev->stats.tx_packets++; + ndev->stats.tx_bytes += skb->len; +dev_kfree_skb (skb); + } + +if (netif_queue_stopped (ndev)) +netif_wake_queue (ndev); +} + +static netdev_tx_t ntb_netdev_start_xmit (struct sk_buff *skb, +struct net_device *ndev) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +int rc; + +pr_debug ("%s: ntb_transport_tx_enqueue\n" ,KBUILD_MODNAME ); + + rc =ntb_transport_tx_enqueue (dev->qp, skb, skb->data, skb->len); +if (rc) + goto err; + +return NETDEV_TX_OK ; + +err: + ndev->stats.tx_dropped++; + ndev->stats.tx_errors++; +netif_stop_queue (ndev); +return NETDEV_TX_BUSY ; +} + +static int ntb_netdev_open (struct net_device *ndev) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +struct sk_buff *skb; +int rc, i, len; + +/* Add some empty rx bufs */ +for (i =0 ; i <NTB_RXQ_SIZE ; i++) { + skb =netdev_alloc_skb (ndev, ndev->mtu +ETH_HLEN ); +if (!skb) { + rc = -ENOMEM ; + goto err; + } + + rc =ntb_transport_rx_enqueue (dev->qp, skb, skb->data, + ndev->mtu +ETH_HLEN ); +if (rc == -EINVAL ) + goto err; + } + +netif_carrier_off (ndev); +ntb_transport_link_up (dev->qp); + +return 0 ; + +err: +while ((skb =ntb_transport_rx_remove (dev->qp, &len))) +kfree (skb); +return rc; +} + +static int ntb_netdev_close (struct net_device *ndev) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +struct sk_buff *skb; +int len; + +ntb_transport_link_down (dev->qp); + +while ((skb =ntb_transport_rx_remove (dev->qp, &len))) +kfree (skb); + +return 0 ; +} + +static int ntb_netdev_change_mtu (struct net_device *ndev,int new_mtu) +{ +struct ntb_netdev *dev =netdev_priv (ndev); +struct sk_buff *skb; +int len, rc; + +if (new_mtu >ntb_transport_max_size (dev->qp) -ETH_HLEN ) +return -EINVAL ; + +if (!netif_running (ndev)) { + ndev->mtu = new_mtu; +return 0 ; + } + +/* Bring down the link and dispose of posted rx entries */ +ntb_transport_link_down (dev->qp); + +if (ndev->mtu < new_mtu) { +int i; + +for (i =0 ; (skb =ntb_transport_rx_remove (dev->qp, &len)); i++) +kfree (skb); + +for (; i; i--) { + skb =netdev_alloc_skb (ndev, new_mtu +ETH_HLEN ); +if (!skb) { + rc = -ENOMEM ; + goto err; + } + + rc =ntb_transport_rx_enqueue (dev->qp, skb, skb->data, + new_mtu +ETH_HLEN ); +if (rc) { +kfree (skb); + goto err; + } + } + } + + ndev->mtu = new_mtu; + +ntb_transport_link_up (dev->qp); + +return 0 ; + +err: +ntb_transport_link_down (dev->qp);
Quoted 8 lines
drivers/net/ntb_netdev.c line 268
Quoted 5 lines
drivers/net/ntb_netdev.c new file +5
-0+ +while ((skb =ntb_transport_rx_remove (dev->qp, &len))) +kfree (skb); + +pr_err ("Error changing MTU, device inoperable\n" );Would be maybe better to use
netdev_errhere (and on similar other places)
Good point
Quoted 14 lines
Also, it might be good to provide rollback in case any of
netdev_alloc_skb()fails.Quoted 10 lines
drivers/net/ntb_netdev.c new file +10
-0+return rc; +} + +static void ntb_netdev_tx_timeout (struct net_device *ndev) +{ +if (netif_running (ndev)) +netif_wake_queue (ndev); +} + +static const struct net_device_ops ntb_netdev_ops = {
Quoted 8 lines
drivers/net/ntb_netdev.c line 284
Quoted 6 lines
drivers/net/ntb_netdev.c new file +6
-0+ .ndo_open = ntb_netdev_open, + .ndo_stop = ntb_netdev_close, + .ndo_start_xmit = ntb_netdev_start_xmit, + .ndo_change_mtu = ntb_netdev_change_mtu, + .ndo_tx_timeout = ntb_netdev_tx_timeout, + .ndo_set_mac_address = eth_mac_addr,Does your device support mac change while it's up and running?
It's virtual ethernet, so there is no hardware limitation, only what is acceptable for the remote side to receive.
Quoted 81 lines
Quoted 66 lines
drivers/net/ntb_netdev.c new file +65
-0+}; + +static void ntb_get_drvinfo (__attribute__((unused))struct net_device *dev, +struct ethtool_drvinfo *info) +{ +strlcpy (info->driver,KBUILD_MODNAME ,sizeof (info->driver)); +strlcpy (info->version,NTB_NETDEV_VER ,sizeof (info->version)); +} + +static const char ntb_nic_stats[][ETH_GSTRING_LEN ] = { +"rx_packets" ,"rx_bytes" ,"rx_errors" ,"rx_dropped" ,"rx_length_errors" , +"rx_frame_errors" ,"rx_fifo_errors" , +"tx_packets" ,"tx_bytes" ,"tx_errors" ,"tx_dropped" , +}; + +static int ntb_get_stats_count (__attribute__((unused))struct net_device *dev) +{ +return ARRAY_SIZE (ntb_nic_stats); +} + +static int ntb_get_sset_count (struct net_device *dev,int sset) +{ +switch (sset) { +case ETH_SS_STATS : +return ntb_get_stats_count (dev); +default : +return -EOPNOTSUPP ; + } +} + +static void ntb_get_strings (__attribute__((unused))struct net_device *dev, +u32 sset,u8 *data) +{ +switch (sset) { +case ETH_SS_STATS : +memcpy (data, *ntb_nic_stats,sizeof (ntb_nic_stats)); + } +} + +static void +ntb_get_ethtool_stats (struct net_device *dev, + __attribute__((unused))struct ethtool_stats *stats, +u64 *data) +{ +int i =0 ; + + data[i++] = dev->stats.rx_packets; + data[i++] = dev->stats.rx_bytes; + data[i++] = dev->stats.rx_errors; + data[i++] = dev->stats.rx_dropped; + data[i++] = dev->stats.rx_length_errors; + data[i++] = dev->stats.rx_frame_errors; + data[i++] = dev->stats.rx_fifo_errors; + data[i++] = dev->stats.tx_packets; + data[i++] = dev->stats.tx_bytes; + data[i++] = dev->stats.tx_errors; + data[i++] = dev->stats.tx_dropped; +} + +static const struct ethtool_ops ntb_ethtool_ops = { + .get_drvinfo = ntb_get_drvinfo, + .get_sset_count = ntb_get_sset_count, + .get_strings = ntb_get_strings, + .get_ethtool_stats = ntb_get_ethtool_stats, + .get_link = ethtool_op_get_link,drivers/net/ntb_netdev.c line 359
Quoted 10 lines
drivers/net/ntb_netdev.c new file +10
-0+}; + +static int __init ntb_netdev_init_module (void ) +{ +struct ntb_netdev *dev; +int rc; + +pr_info ("%s: Probe\n" ,KBUILD_MODNAME ); + + netdev =alloc_etherdev (sizeof (struct ntb_netdev ));I might be missing something but this place (module init) does not seems like a good place to do
alloc_etherdev(). Do you want to support only one netdevice instance?
Quoted 2 lines
Anyway, I think that using "static netdev" should be avoided in any case.
It would fail the probe if there is no underlying ntb hardware, but it would make sense to check for that before allocing the etherdev.
Thanks for the comments!
Quoted 59 lines
Quoted 59 lines
drivers/net/ntb_netdev.c new file +52
-0+if (!netdev) +return -ENOMEM ; + + dev =netdev_priv (netdev); + dev->ndev = netdev; + netdev->features =NETIF_F_HIGHDMA ; + + netdev->hw_features = netdev->features; + netdev->watchdog_timeo =msecs_to_jiffies (NTB_TX_TIMEOUT_MS ); + +random_ether_addr (netdev->perm_addr); +memcpy (netdev->dev_addr, netdev->perm_addr, netdev->addr_len); + + netdev->netdev_ops = &ntb_netdev_ops; +SET_ETHTOOL_OPS (netdev, &ntb_ethtool_ops); + + dev->qp =ntb_transport_create_queue (ntb_netdev_rx_handler, + ntb_netdev_tx_handler, + ntb_netdev_event_handler); +if (!dev->qp) { + rc = -EIO ; + goto err; + } + + netdev->mtu =ntb_transport_max_size (dev->qp) -ETH_HLEN ; + + rc =register_netdev (netdev); +if (rc) + goto err1; + +pr_info ("%s: %s created\n" ,KBUILD_MODNAME , netdev->name); +return 0 ; + +err1: +ntb_transport_free_queue (dev->qp); +err: +free_netdev (netdev); +return rc; +} +module_init (ntb_netdev_init_module); + +static void __exit ntb_netdev_exit_module(void) +{ +struct ntb_netdev *dev =netdev_priv (netdev); + +unregister_netdev (netdev); +ntb_transport_free_queue (dev->qp); +free_netdev (netdev); + +pr_info ("%s: Driver removed\n" ,KBUILD_MODNAME ); +} +module_exit (ntb_netdev_exit_module);Signature · 6 lines
1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 2/2] net: Add support for NTB virtual ethernet device
In reply to Stephen HemmingerQuoted 66 lines · Stephen Hemminger
Quoted 63 lines · On Fri, 13 Jul 2012 14:45:00 -0700 Jon Mason <[email protected]> wrote:
A virtual ethernet device that uses the NTB transport API to send/receive data.
Signed-off-by Jon Mason <[email protected]>--- drivers/net/Kconfig | 4 + drivers/net/Makefile | 1 + drivers/net/ntb_netdev.c | 411 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 0 deletions(-) create mode 100644 drivers/net/ntb_netdev.cdrivers/net/ntb_netdev.c new file +52
-0+static void ntb_get_drvinfo (__attribute__((unused))struct net_device *dev, +struct ethtool_drvinfo *info) +{ +strlcpy (info->driver,KBUILD_MODNAME ,sizeof (info->driver)); +strlcpy (info->version,NTB_NETDEV_VER ,sizeof (info->version)); +} + +static const char ntb_nic_stats[][ETH_GSTRING_LEN ] = { +"rx_packets" ,"rx_bytes" ,"rx_errors" ,"rx_dropped" ,"rx_length_errors" , +"rx_frame_errors" ,"rx_fifo_errors" , +"tx_packets" ,"tx_bytes" ,"tx_errors" ,"tx_dropped" , +}; + +static int ntb_get_stats_count (__attribute__((unused))struct net_device *dev) +{ +return ARRAY_SIZE (ntb_nic_stats); +} + +static int ntb_get_sset_count (struct net_device *dev,int sset) +{ +switch (sset) { +case ETH_SS_STATS : +return ntb_get_stats_count (dev); +default : +return -EOPNOTSUPP ; + } +} + +static void ntb_get_strings (__attribute__((unused))struct net_device *dev, +u32 sset,u8 *data) +{ +switch (sset) { +case ETH_SS_STATS : +memcpy (data, *ntb_nic_stats,sizeof (ntb_nic_stats)); + } +} + +static void +ntb_get_ethtool_stats (struct net_device *dev, + __attribute__((unused))struct ethtool_stats *stats, +u64 *data) +{ +int i =0 ; + + data[i++] = dev->stats.rx_packets; + data[i++] = dev->stats.rx_bytes; + data[i++] = dev->stats.rx_errors; + data[i++] = dev->stats.rx_dropped; + data[i++] = dev->stats.rx_length_errors; + data[i++] = dev->stats.rx_frame_errors; + data[i++] = dev->stats.rx_fifo_errors; + data[i++] = dev->stats.tx_packets;
Quoted 8 lines
drivers/net/ntb_netdev.c line 342
Quoted 4 lines
drivers/net/ntb_netdev.c new file +4
-0+ data[i++] = dev->stats.tx_bytes; + data[i++] = dev->stats.tx_errors; + data[i++] = dev->stats.tx_dropped; +}These statistics add no value over existing network stats. Don't implement ethtool stats unless device has something more interesting to say.
Fair enough
Quoted 11 lines
drivers/net/ntb_netdev.c line 350
Quoted 8 lines
drivers/net/ntb_netdev.c new file +7
-0+static const struct ethtool_ops ntb_ethtool_ops = { + .get_drvinfo = ntb_get_drvinfo, + .get_sset_count = ntb_get_sset_count, + .get_strings = ntb_get_strings, + .get_ethtool_stats = ntb_get_ethtool_stats, + .get_link = ethtool_op_get_link, +};If you want to implement bonding or bridging then implementing
get_settingswould help.
Will do.
Quoted 8 lines
drivers/net/ntb_netdev.c line 357
Quoted 6 lines
drivers/net/ntb_netdev.c new file +6
-0+static int __init ntb_netdev_init_module (void ) +{ +struct ntb_netdev *dev; +int rc; + +pr_info ("%s: Probe\n" ,KBUILD_MODNAME );Useless message
True, will remove.
Thanks for the comments!
Quoted 54 lines
Quoted 53 lines
drivers/net/ntb_netdev.c new file +53
-0+ netdev =alloc_etherdev (sizeof (struct ntb_netdev )); +if (!netdev) +return -ENOMEM ; + + dev =netdev_priv (netdev); + dev->ndev = netdev; + netdev->features =NETIF_F_HIGHDMA ; + + netdev->hw_features = netdev->features; + netdev->watchdog_timeo =msecs_to_jiffies (NTB_TX_TIMEOUT_MS ); + +random_ether_addr (netdev->perm_addr); +memcpy (netdev->dev_addr, netdev->perm_addr, netdev->addr_len); + + netdev->netdev_ops = &ntb_netdev_ops; +SET_ETHTOOL_OPS (netdev, &ntb_ethtool_ops); + + dev->qp =ntb_transport_create_queue (ntb_netdev_rx_handler, + ntb_netdev_tx_handler, + ntb_netdev_event_handler); +if (!dev->qp) { + rc = -EIO ; + goto err; + } + + netdev->mtu =ntb_transport_max_size (dev->qp) -ETH_HLEN ; + + rc =register_netdev (netdev); +if (rc) + goto err1; + +pr_info ("%s: %s created\n" ,KBUILD_MODNAME , netdev->name); +return 0 ; + +err1: +ntb_transport_free_queue (dev->qp); +err: +free_netdev (netdev); +return rc; +} +module_init (ntb_netdev_init_module); + +static void __exit ntb_netdev_exit_module(void) +{ +struct ntb_netdev *dev =netdev_priv (netdev); + +unregister_netdev (netdev); +ntb_transport_free_queue (dev->qp); +free_netdev (netdev); + +pr_info ("%s: Driver removed\n" ,KBUILD_MODNAME ); +} +module_exit (ntb_netdev_exit_module);
Quoted 56 lines · Stephen Hemminger
Quoted 26 lines · On Fri, 13 Jul 2012 14:44:59 -0700 Jon Mason <[email protected]> wrote:
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.
Quoted 1 line
Signed-off-by Jon Mason <[email protected]>This driver does some reimplementing of standard type operations is this because you are trying to use the same code on multiple platforms?
Example:
drivers/ntb/ntb_transport.c new file +20
-0+ +static void ntb_list_add_head (spinlock_t *lock,struct list_head *entry, +struct list_head *list) +{ +unsigned long flags; + +spin_lock_irqsave (lock, flags); +list_add (entry, list); +spin_unlock_irqrestore (lock, flags); +} + +static void ntb_list_add_tail (spinlock_t *lock,struct list_head *entry, +struct list_head *list) +{ +unsigned long flags; + +spin_lock_irqsave (lock, flags); +list_add_tail (entry, list); +spin_unlock_irqrestore (lock, flags); +}
Quoted 6 lines
Which are used on skb's and yet we already have
sk_buff_headwith locking?I know you probably are committed to this API, but is there some way to reuse existing shared memory used by virtio-net between two ports?
The intention is to be able to have multiple client drivers/virtual devices that are able to use NTB as the transport to the remote system. This is the reason why a void* is passed into the transport instead of skb*, making all of the extra book keeping necessary. Currently, only the virtual Ethernet has been done, which may be part of the confusion. I'd like to be able to find a way to have the virtio devices use ntb (and save me the work of reinventing the wheel), but step one is getting this code accepted :)
Thanks,
Jon
Re: [RFC 2/2] net: Add support for NTB virtual ethernet device
In reply to Jon MasonQuoted 11 lines · Sat, Jul 14, 2012 at 07:50:35AM CEST, [email protected] wrote:
Quoted 10 lines · Jiri Pirko
Quoted 9 lines · Fri, Jul 13, 2012 at 11:45:00PM CEST, [email protected] wrote:
A virtual ethernet device that uses the NTB transport API to send/receive data.
Signed-off-by Jon Mason <[email protected]>---
drivers/net/Kconfig | 4 + drivers/net/Makefile | 1 + drivers/net/ntb_netdev.c | 411 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 0 deletions(-)create mode 100644
drivers/net/ntb_netdev.c
<snip>
Quoted 11 lines
Quoted 10 lines
drivers/net/ntb_netdev.c line 284
Quoted 8 lines
drivers/net/ntb_netdev.c new file +8
-0+ +static const struct net_device_ops ntb_netdev_ops = { + .ndo_open = ntb_netdev_open, + .ndo_stop = ntb_netdev_close, + .ndo_start_xmit = ntb_netdev_start_xmit, + .ndo_change_mtu = ntb_netdev_change_mtu, + .ndo_tx_timeout = ntb_netdev_tx_timeout, + .ndo_set_mac_address = eth_mac_addr,Does your device support mac change while it's up and running?
Quoted 1 line
It's virtual ethernet, so there is no hardware limitation, only what is acceptable for the remote side to receive.
In that case, it would be good to do:dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
This enables mac change in eth_mac_addr() when iface is running.
<snip>
Quoted 14 lines
Quoted 14 lines
drivers/net/ntb_netdev.c line 359
Quoted 9 lines
drivers/net/ntb_netdev.c new file +9
-0+ +static int __init ntb_netdev_init_module (void ) +{ +struct ntb_netdev *dev; +int rc; + +pr_info ("%s: Probe\n" ,KBUILD_MODNAME ); + + netdev =alloc_etherdev (sizeof (struct ntb_netdev ));I might be missing something but this place (module init) does not seems like a good place to do
alloc_etherdev(). Do you want to support only one netdevice instance?
Quoted 4 lines
Quoted 2 lines
Anyway, I think that using "static netdev" should be avoided in any case.
It would fail the probe if there is no underlying ntb hardware, but it would make sense to check for that before allocing the etherdev.
But isn't there possible to have multiple ntb hardware devices? It would make sense to register ntb device here with ntb core and let the core call probe which would actually create new netdev.
Is there a limitation that one underlying ntb hardware ~ one ntb netdevice?
Thanks,
Jiri
Quoted 7 lines · Jon Mason
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.
Why would you have non-mainlined drivers?
Can you submit the drivers at the same time so we see how you are using these new interfaces?
Quoted 14 lines
+++
b/drivers/ntb/ntb_hw.cdrivers/ntb/ntb_hw.c new file +12
-0@@ -0,0 +1,1283 @@ +/* +* 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. +*
drivers/ntb/ntb_hw.c line 22
Quoted 10 lines
drivers/ntb/ntb_hw.c new file +10
-0+* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +* The full GNU General Public License is included in this distribution +* in the file called LICENSE.GPL.
You really want to track the office movements of the FSF for the next 40 years? You should ask your lawyers if you can remove this paragraph.
drivers/ntb/ntb_hw.c line 178
Quoted 13 lines
drivers/ntb/ntb_hw.c new file +13
-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 +*/ +bool ntb_hw_link_status (struct ntb_device *ndev) +{ +return ndev->link_status ==NTB_LINK_UP ; +} +EXPORT_SYMBOL (ntb_hw_link_status);
EXPORT_SYMBOL_GPL() perhaps, for these, and the other symbols you are creating?
thanks,
greg k-h
drivers/ntb/ntb_hw.c line 82
Quoted 7 lines · Jon Mason
drivers/ntb/ntb_hw.c new file +7
-0+static int max_num_cbs =2 ; +module_param (max_num_cbs, uint,0644 ); +MODULE_PARM_DESC (max_num_cbs,"Maximum number of NTB transport connections" ); + +static bool no_msix; +module_param (no_msix, bool,0644 ); +MODULE_PARM_DESC (no_msix,"Do not allow MSI-X interrupts to be selected" );
How would a user, or a distro, know to set these options? Why are they even options at all?
Quoted 14 lines
drivers/ntb/ntb_hw.c new file +14
-0+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; +void __iomem *sdb;
drivers/ntb/ntb_hw.c line 135
Quoted 10 lines
drivers/ntb/ntb_hw.c new file +10
-0+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; +void (*event_cb)(void *handle,unsigned int event);
Shouldn't the event be an enum?
drivers/ntb/ntb_hw.c line 147
Quoted 11 lines
drivers/ntb/ntb_hw.c new file +11
-0+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; +};
Why isn't this either a 'struct device' itself, or why isn't the 'struct pci_device' embedded within it? What controls the lifetime of this device? Why doesn't it show up in sysfs? Don't you want it to show up in the global device tree?
drivers/ntb/ntb_hw.c line 164
Quoted 13 lines
drivers/ntb/ntb_hw.c new file +13
-0+static DEFINE_PCI_DEVICE_TABLE (ntb_pci_tbl) = { + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_B2B_BWD )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_B2B_JSF )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_CLASSIC_JSF )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_RP_JSF )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_RP_SNB )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_B2B_SNB )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_CLASSIC_SNB )}, + {0 } +}; +MODULE_DEVICE_TABLE (pci, ntb_pci_tbl); + +static struct ntb_device *ntbdev;
You can really only have just one of these in the whole system? Is that wise? Why isn't it dynamic and tied to the pci device itself as a child?
thanks,
greg k-h
Have you looked at any of the work that the PXI group has done on NTB support within PXI?
http://www.ni.com/white-paper/12523/en
I was on that working group, and one of the first capabilities I suggested for it was IP over NTB - I was going to implement this at my employer, but the project took a different turn and this idea got put on the back burner. I am glad somebody else has seen fit to take it up.
Also, a stupid question but one I have to ask: have you taken into account the idea that the CPUs on each side of the NTB might have different endian-ness? I was looking at a case with a PPC on one side of the bridge and an X86 on the other.
Quoted 9 lines · Greg KH
Quoted 7 lines · Jon Mason
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.
Quoted 4 lines
Why would you have non-mainlined drivers?
Can you submit the drivers at the same time so we see how you are using these new interfaces?
There are none at this time. In the near future, the transport will be modified to use IOAT instead of the CPU copy to improve throughput performance, and it may be beneficial to have that separate. If you wish for me to remove the hooks until it is necessary for that, then I can.
Quoted 20 lines
Quoted 20 lines
+++
b/drivers/ntb/ntb_hw.cdrivers/ntb/ntb_hw.c new file +17
-0@@ -0,0 +1,1283 @@ +/* +* 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. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*
Quoted 8 lines
drivers/ntb/ntb_hw.c line 22
Quoted 5 lines
drivers/ntb/ntb_hw.c new file +5
-0+* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +* The full GNU General Public License is included in this distribution +* in the file called LICENSE.GPL. You really want to track the office movements of the FSF for the next 40 years? You should ask your lawyers if you can remove this paragraph.
Standard boilerplate junk, but it never hurts to ask.
Quoted 8 lines
Quoted 8 lines
drivers/ntb/ntb_hw.c new file +8
-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 +*/
Quoted 8 lines
drivers/ntb/ntb_hw.c line 178
Quoted 5 lines
drivers/ntb/ntb_hw.c new file +5
-0+bool ntb_hw_link_status (struct ntb_device *ndev) +{ +return ndev->link_status ==NTB_LINK_UP ; +} +EXPORT_SYMBOL (ntb_hw_link_status);
EXPORT_SYMBOL_GPL()perhaps, for these, and the other symbols you are creating?
Will do.
Quoted 4 lines
thanks,
greg k-h
Quoted 12 lines · Jon Mason
Quoted 11 lines · Greg KH
Quoted 7 lines · Jon Mason
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.
Why would you have non-mainlined drivers?
Quoted 8 lines
Quoted 2 lines
Can you submit the drivers at the same time so we see how you are using these new interfaces?
There are none at this time. In the near future, the transport will be modified to use IOAT instead of the CPU copy to improve throughput performance, and it may be beneficial to have that separate. If you wish for me to remove the hooks until it is necessary for that, then I can.
Yes, please do so, we don't add apis for things that are not in-kernel as they almost always need to change once we actually get a user of them, as you know.
thanks,
greg k-h
Quoted 11 lines · Greg KH
drivers/ntb/ntb_hw.c line 82
Quoted 7 lines · Jon Mason
drivers/ntb/ntb_hw.c new file +7
-0+static int max_num_cbs =2 ; +module_param (max_num_cbs, uint,0644 ); +MODULE_PARM_DESC (max_num_cbs,"Maximum number of NTB transport connections" ); + +static bool no_msix; +module_param (no_msix, bool,0644 ); +MODULE_PARM_DESC (no_msix,"Do not allow MSI-X interrupts to be selected" );How would a user, or a distro, know to set these options? Why are they even options at all?
Good question. There is actually a potential benefit to disabling MSI-X. The NTB device on one of our platforms only has 3 MSI-X vectors. In the current driver design, that would limit them to 3 client/virtual devices. However, there are 15bits in the ISR that can be used for the same purpose. So, if you disable MSI-X, you can have 15 instead of 3.
Quoted 20 lines
Quoted 20 lines
drivers/ntb/ntb_hw.c new file +18
-0+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; +void __iomem *sdb; +void __iomem *sbar2_xlat; +void __iomem *sbar4_xlat; +void __iomem *spad_write; +void __iomem *spad_read;
Quoted 8 lines
drivers/ntb/ntb_hw.c line 135
Quoted 6 lines
drivers/ntb/ntb_hw.c new file +6
-0+void __iomem *lnk_cntl; +void __iomem *lnk_stat; +void __iomem *spci_cmd; + } reg_ofs; +void *ntb_transport; +void (*event_cb)(void *handle,unsigned int event);Shouldn't the event be an enum?
No, that would be too smart.
Quoted 27 lines
drivers/ntb/ntb_hw.c line 147
Quoted 12 lines
drivers/ntb/ntb_hw.c new file +11
-0+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; +};Why isn't this either a 'struct device' itself, or why isn't the 'struct
pci_device' embedded within it? What controls the lifetime of this device? Why doesn't it show up in sysfs? Don't you want it to show up in the global device tree?Quoted 9 lines
drivers/ntb/ntb_hw.c new file +9
-0+static DEFINE_PCI_DEVICE_TABLE (ntb_pci_tbl) = { + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_B2B_BWD )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_B2B_JSF )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_CLASSIC_JSF )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_RP_JSF )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_RP_SNB )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_B2B_SNB )}, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_NTB_CLASSIC_SNB )}, + {0 }
Quoted 8 lines
drivers/ntb/ntb_hw.c line 164
Quoted 4 lines
drivers/ntb/ntb_hw.c new file +4
-0+}; +MODULE_DEVICE_TABLE (pci, ntb_pci_tbl); + +static struct ntb_device *ntbdev;You can really only have just one of these in the whole system? Is that wise? Why isn't it dynamic and tied to the pci device itself as a child?
Good point, I will fix that up.
Thanks for the review!
Quoted 4 lines
thanks,
greg k-h
Quoted 13 lines · Jon Mason
Quoted 11 lines · Greg KH
drivers/ntb/ntb_hw.c line 82
Quoted 7 lines · Jon Mason
drivers/ntb/ntb_hw.c new file +7
-0+static int max_num_cbs =2 ; +module_param (max_num_cbs, uint,0644 ); +MODULE_PARM_DESC (max_num_cbs,"Maximum number of NTB transport connections" ); + +static bool no_msix; +module_param (no_msix, bool,0644 ); +MODULE_PARM_DESC (no_msix,"Do not allow MSI-X interrupts to be selected" );How would a user, or a distro, know to set these options? Why are they even options at all?
Quoted 6 lines
Good question. There is actually a potential benefit to disabling MSI-X. The NTB device on one of our platforms only has 3 MSI-X vectors. In the current driver design, that would limit them to 3 client/virtual devices. However, there are 15bits in the ISR that can be used for the same purpose. So, if you disable MSI-X, you can have 15 instead of 3.
But again, how would a user, or a distro, know to set these? Where is the documentation describing it? Why really have these options at all and not just fix the platform issues (only 3 MSI-X vectors? Really?)
thanks,
greg k-h
Hi Jon,
On Fri, Jul 13, 2012 at 5:44 PM, Jon Mason <[email protected]> wrote:
Just a few minor comments/questions:
....
drivers/ntb/ntb_transport.c line 94
Quoted 9 lines
drivers/ntb/ntb_transport.c new file +9
-0+struct ntb_transport_qp { +struct ntb_device *ndev; + +bool client_ready; +bool qp_link; +u8 qp_num;/* Only 64 QP's are allowed. 0-63 */ + +void (*tx_handler) (struct ntb_transport_qp *qp); +struct tasklet_struct tx_work;
Is it ok to rename the following vars for convenience sake?
Quoted 1 line
+ struct
list_headtxq;
tx_pend_q - (pending_queue) or tx_out_q - (outstanding_queue) - or pick any new string you like - other than a mono-syllable definition
Quoted 1 line
+ struct
list_headtxc;
tx_compl_q - completion queue
Quoted 1 line
+ struct
list_headtxe;
tx_avail_e - available entry queue
drivers/ntb/ntb_transport.c line 100
Quoted 3 lines
drivers/ntb/ntb_transport.c new file +3
-0+spinlock_t txq_lock; +spinlock_t txc_lock; +spinlock_t txe_lock;
then match the variants accordingly.
drivers/ntb/ntb_transport.c line 112
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+struct list_head rxq; +struct list_head rxc; +struct list_head rxe; +spinlock_t rxq_lock; +spinlock_t rxc_lock; +spinlock_t rxe_lock;
similarly the rx-counterpart
..................
Quoted 12 lines
drivers/ntb/ntb_transport.c new file +12
-0+static void ntb_tx_copy_task (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry, +void *offset) +{ +struct ntb_payload_header *hdr = offset; +int rc; + + offset +=sizeof (struct ntb_payload_header ); +memcpy_toio (offset, entry->buf, entry->len); + + hdr->len = entry->len; + hdr->ver = qp->tx_pkts;
drivers/ntb/ntb_transport.c line 777
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +10
-0+ +/* Ensure that the data is fully copied out before setting the flag */ +wmb (); + hdr->flags = entry->flags |DESC_DONE_FLAG ; + + rc =ntb_ring_sdb (qp->ndev, qp->qp_num); +if (rc) +pr_err ("%s: error ringing db %d\n" , __func__, qp->qp_num); + +if (entry->len >0 ) {
how do you interpret this len variable and decide if it's a good/bad completion?
drivers/ntb/ntb_transport.c line 786
Quoted 9 lines
drivers/ntb/ntb_transport.c new file +9
-0+ qp->tx_bytes += entry->len; + +/* Add fully transmitted data to completion queue */ +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp); + }else +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);
I could be wrong but how is the original skb handled if the code path goes in the else clause?
Also, in the else clause, how about a ntb_list_add_head rather than a _tail.
Quoted 22 lines
drivers/ntb/ntb_transport.c new file +22
-0+ +static int ntb_process_tx (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry) +{ +struct ntb_payload_header *hdr; +void *offset; + + offset = qp->tx_offset; + hdr = offset; + +pr_debug ("%lld - offset %p, tx %p, entry len %d flags %x buff %p\n" , + qp->tx_pkts, offset, qp->tx_offset, entry->len, entry->flags, + entry->buf); +if (hdr->flags) { +ntb_list_add_head (&qp->txq_lock, &entry->entry, &qp->txq); + qp->tx_ring_full++; +return -EAGAIN ; + } + +if (entry->len > transport_mtu) { +pr_err ("Trying to send pkt size of %d\n" , entry->len); + entry->flags =HW_ERROR_FLAG ;
drivers/ntb/ntb_transport.c line 819
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +10
-0+ +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp); + +return 0 ; + } + +ntb_tx_copy_task (qp, entry, offset);
what happens when ntb_sdb_ring returns an error? would you still want to increment tx_pkts below?
Quoted 12 lines
drivers/ntb/ntb_transport.c new file +12
-0+ + qp->tx_offset = + (qp->tx_offset + + ((transport_mtu +sizeof (struct ntb_payload_header )) *2 ) >= + qp->tx_mw_end) ? qp->tx_mw_begin : qp->tx_offset + transport_mtu + +sizeof (struct ntb_payload_header ); + + qp->tx_pkts++; + +return 0 ; +} +
........................
Quoted 9 lines
drivers/ntb/ntb_transport.c new file +9
-0+void *ntb_transport_tx_dequeue (struct ntb_transport_qp *qp,unsigned int *len) +{ +struct ntb_queue_entry *entry; +void *buf; + +if (!qp) +return NULL ; + + entry =ntb_list_rm_head (&qp->txc_lock, &qp->txc);
drivers/ntb/ntb_transport.c line 1149
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +10
-0+if (!entry) +return NULL ; + + buf = entry->callback_data; +if (entry->flags !=HW_ERROR_FLAG ) + *len = entry->len; +else + *len = -EIO ; + +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);
how about a ntb_list_add_head?
Chetan Loke
Quoted 21 lines · Greg KH
Quoted 13 lines · Jon Mason
Quoted 11 lines · Greg KH
drivers/ntb/ntb_hw.c line 82
Quoted 7 lines · Jon Mason
drivers/ntb/ntb_hw.c new file +7
-0+static int max_num_cbs =2 ; +module_param (max_num_cbs, uint,0644 ); +MODULE_PARM_DESC (max_num_cbs,"Maximum number of NTB transport connections" ); + +static bool no_msix; +module_param (no_msix, bool,0644 ); +MODULE_PARM_DESC (no_msix,"Do not allow MSI-X interrupts to be selected" );How would a user, or a distro, know to set these options? Why are they even options at all?
Quoted 6 lines
Good question. There is actually a potential benefit to disabling MSI-X. The NTB device on one of our platforms only has 3 MSI-X vectors. In the current driver design, that would limit them to 3 client/virtual devices. However, there are 15bits in the ISR that can be used for the same purpose. So, if you disable MSI-X, you can have 15 instead of 3.
Quoted 3 lines
But again, how would a user, or a distro, know to set these? Where is the documentation describing it? Why really have these options at all and not just fix the platform issues (only 3 MSI-X vectors? Really?)
I believe we'll want multiple clients (or have multiqueue Ethernet). I'm happy to add something to /Documentation to describe it and why it would be useful, or I can remove it and re-introduce it when I add multiqueue Ethernet.
3 MSI-X vectors (plus one for PCI-E link up/down) on Xeon NTB, and 33 for Atom NTB. Yeah, really.
Quoted 4 lines
thanks,
greg k-h
Jon,
On Fri, Jul 13, 2012 at 5:44 PM, Jon Mason <[email protected]> wrote:
..............
Quoted 7 lines
drivers/ntb/ntb_hw.c new file +7
-0+/** +* ntb_ring_sdb() - Set the doorbell on the secondary/external side +* @ndev: pointer to ntb_device instance +* @db: doorbell to ring +* +* This function allows triggering of a doorbell on the secondary/external +* side that will initiate an interrupt on the remote host
drivers/ntb/ntb_hw.c line 536
Quoted 10 lines
drivers/ntb/ntb_hw.c new file +9
-0+* +* RETURNS: An appropriate -ERRNO error value on error, or zero for success. +*/ +int ntb_ring_sdb (struct ntb_device *ndev,unsigned int db) +{ +dev_dbg (&ndev->pdev->dev,"%s: ringing doorbell %d\n" , __func__, db); + +if (db >= ndev->max_cbs) +return -EINVAL ;
How about moving this max_cbs error check in the upper level callers(example in ntb_process_tx)?
That way you won't have to defer handling some negative cases all the way till the end.
So ntb_process_tx could now look like:
.....
error=0;
if (entry->len > transport_mtu) {
...
error=1;
}
else if (qp->qp_num >= qp->ndev->max_cbs) {
...
error=1;
}
if (unlikely(error)) {
ntb_list_add_tail(&qp->txc_lock, &entry->entry, &qp->txc);
if (qp->tx_handler)
qp->tx_handler(qp);
return 0;
}.................
No further comments below
Quoted 34 lines
drivers/ntb/ntb_transport.c new file +34
-0+ +static int ntb_process_tx (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry) +{ +struct ntb_payload_header *hdr; +void *offset; + + offset = qp->tx_offset; + hdr = offset; + +pr_debug ("%lld - offset %p, tx %p, entry len %d flags %x buff %p\n" , + qp->tx_pkts, offset, qp->tx_offset, entry->len, entry->flags, + entry->buf); +if (hdr->flags) { +ntb_list_add_head (&qp->txq_lock, &entry->entry, &qp->txq); + qp->tx_ring_full++; +return -EAGAIN ; + } + +if (entry->len > transport_mtu) { +pr_err ("Trying to send pkt size of %d\n" , entry->len); + entry->flags =HW_ERROR_FLAG ; + +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp); + +return 0 ; + } + +ntb_tx_copy_task (qp, entry, offset); + + qp->tx_offset =
drivers/ntb/ntb_transport.c line 831
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +10
-0+ (qp->tx_offset + + ((transport_mtu +sizeof (struct ntb_payload_header )) *2 ) >= + qp->tx_mw_end) ? qp->tx_mw_begin : qp->tx_offset + transport_mtu + +sizeof (struct ntb_payload_header ); + + qp->tx_pkts++; + +return 0 ; +} +
Chetan Loke
Quoted 22 lines · Jon Mason
Quoted 21 lines · Greg KH
Quoted 19 lines · Jon Mason
Quoted 11 lines · Greg KH
drivers/ntb/ntb_hw.c line 82
Quoted 7 lines · Jon Mason
drivers/ntb/ntb_hw.c new file +7
-0+static int max_num_cbs =2 ; +module_param (max_num_cbs, uint,0644 ); +MODULE_PARM_DESC (max_num_cbs,"Maximum number of NTB transport connections" ); + +static bool no_msix; +module_param (no_msix, bool,0644 ); +MODULE_PARM_DESC (no_msix,"Do not allow MSI-X interrupts to be selected" );How would a user, or a distro, know to set these options? Why are they even options at all?
Good question. There is actually a potential benefit to disabling MSI-X. The NTB device on one of our platforms only has 3 MSI-X vectors. In the current driver design, that would limit them to 3 client/virtual devices. However, there are 15bits in the ISR that can be used for the same purpose. So, if you disable MSI-X, you can have 15 instead of 3.
Quoted 8 lines
Quoted 3 lines
But again, how would a user, or a distro, know to set these? Where is the documentation describing it? Why really have these options at all and not just fix the platform issues (only 3 MSI-X vectors? Really?)
I believe we'll want multiple clients (or have multiqueue Ethernet). I'm happy to add something to /Documentation to describe it and why it would be useful, or I can remove it and re-introduce it when I add multiqueue Ethernet.
I'd suggest waiting and adding it later if really needed (see previous comment about not adding code/features before they are actually needed.)
thanks,
greg k-h
Quoted 37 lines · chetan loke
Hi Jon,
On Fri, Jul 13, 2012 at 5:44 PM, Jon Mason <[email protected]> wrote:
Just a few minor comments/questions:
....
drivers/ntb/ntb_transport.c line 94
Quoted 9 lines
drivers/ntb/ntb_transport.c new file +9
-0+struct ntb_transport_qp { +struct ntb_device *ndev; + +bool client_ready; +bool qp_link; +u8 qp_num;/* Only 64 QP's are allowed. 0-63 */ + +void (*tx_handler) (struct ntb_transport_qp *qp); +struct tasklet_struct tx_work;Is it ok to rename the following vars for convenience sake?
Quoted 1 line
+ struct
list_headtxq;
tx_pend_q- (pending_queue) ortx_out_q- (outstanding_queue) - or pick any new string you like - other than a mono-syllable definitionQuoted 1 line
+ struct
list_headtxc;
tx_compl_q- completion queueQuoted 1 line
+ struct
list_headtxe;
tx_avail_e- available entry queuedrivers/ntb/ntb_transport.c line 100
Quoted 3 lines
drivers/ntb/ntb_transport.c new file +3
-0+spinlock_t txq_lock; +spinlock_t txc_lock; +spinlock_t txe_lock;then match the variants accordingly.
Quoted 8 lines
drivers/ntb/ntb_transport.c line 112
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+struct list_head rxq; +struct list_head rxc; +struct list_head rxe; +spinlock_t rxq_lock; +spinlock_t rxc_lock; +spinlock_t rxe_lock;similarly the rx-counterpart
Are they difficult to understand? I can change them, but it seems rather moot since you seemed to immediately understand the logic behind the names.
Quoted 20 lines
..................
Quoted 16 lines
drivers/ntb/ntb_transport.c new file +16
-0+static void ntb_tx_copy_task (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry, +void *offset) +{ +struct ntb_payload_header *hdr = offset; +int rc; + + offset +=sizeof (struct ntb_payload_header ); +memcpy_toio (offset, entry->buf, entry->len); + + hdr->len = entry->len; + hdr->ver = qp->tx_pkts; + +/* Ensure that the data is fully copied out before setting the flag */ +wmb (); + hdr->flags = entry->flags |DESC_DONE_FLAG ;
Quoted 8 lines
drivers/ntb/ntb_transport.c line 777
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+ + rc =ntb_ring_sdb (qp->ndev, qp->qp_num); +if (rc) +pr_err ("%s: error ringing db %d\n" , __func__, qp->qp_num); + +if (entry->len >0 ) {how do you interpret this len variable and decide if it's a good/bad completion?
The length of 0 is for messages from the remote system, which currently only consists of a "link down" message notifying the local system to no longer send any messages to the remote side.
Quoted 13 lines
drivers/ntb/ntb_transport.c line 786
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +9
-0+ qp->tx_bytes += entry->len; + +/* Add fully transmitted data to completion queue */ +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp); + }else +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);I could be wrong but how is the original skb handled if the code path goes in the else clause?
There is no skb is the length is zero. Since the only client is virtual ethernet, it will always be > 60. However, I should add a sanity check for 0 length in tx_enqueue.
Quoted 1 line
Also, in the else clause, how about a
ntb_list_add_headrather than a_tail.
Why add to the head, it was just used?
Quoted 27 lines
Quoted 27 lines
drivers/ntb/ntb_transport.c new file +27
-0+ +static int ntb_process_tx (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry) +{ +struct ntb_payload_header *hdr; +void *offset; + + offset = qp->tx_offset; + hdr = offset; + +pr_debug ("%lld - offset %p, tx %p, entry len %d flags %x buff %p\n" , + qp->tx_pkts, offset, qp->tx_offset, entry->len, entry->flags, + entry->buf); +if (hdr->flags) { +ntb_list_add_head (&qp->txq_lock, &entry->entry, &qp->txq); + qp->tx_ring_full++; +return -EAGAIN ; + } + +if (entry->len > transport_mtu) { +pr_err ("Trying to send pkt size of %d\n" , entry->len); + entry->flags =HW_ERROR_FLAG ; + +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp);
Quoted 8 lines
drivers/ntb/ntb_transport.c line 819
Quoted 5 lines
drivers/ntb/ntb_transport.c new file +5
-0+ +return 0 ; + } + +ntb_tx_copy_task (qp, entry, offset);what happens when
ntb_sdb_ringreturns an error? would you still want to incrementtx_pktsbelow?
It's not fatal if the remote side isn't notified. It will hurt latency, since the next packet would be the one that triggers the next interrupt. Also, the only way it could ever fail would be if it was an invalid interrupt bit being set, which should never happen.
Quoted 29 lines
Quoted 12 lines
drivers/ntb/ntb_transport.c new file +12
-0+ + qp->tx_offset = + (qp->tx_offset + + ((transport_mtu +sizeof (struct ntb_payload_header )) *2 ) >= + qp->tx_mw_end) ? qp->tx_mw_begin : qp->tx_offset + transport_mtu + +sizeof (struct ntb_payload_header ); + + qp->tx_pkts++; + +return 0 ; +} +........................
Quoted 13 lines
drivers/ntb/ntb_transport.c new file +13
-0+void *ntb_transport_tx_dequeue (struct ntb_transport_qp *qp,unsigned int *len) +{ +struct ntb_queue_entry *entry; +void *buf; + +if (!qp) +return NULL ; + + entry =ntb_list_rm_head (&qp->txc_lock, &qp->txc); +if (!entry) +return NULL ; + + buf = entry->callback_data;
Quoted 8 lines
drivers/ntb/ntb_transport.c line 1149
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+if (entry->flags !=HW_ERROR_FLAG ) + *len = entry->len; +else + *len = -EIO ; + +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);how about a
ntb_list_add_head?
Is there a benefit to adding to the head versus tail? It makes more sense to me to pull from the head and add to the tail.
Quoted 3 lines
Chetan Loke
Quoted 1 line · Jon Mason
On Mon, Jul 16, 2012 at 12:49:39PM -0400, chetan loke wrote:
....
Quoted 26 lines
Quoted 26 lines
Is it ok to rename the following vars for convenience sake?
Quoted 1 line
+ struct
list_headtxq;
tx_pend_q- (pending_queue) ortx_out_q- (outstanding_queue) - or pick any new string you like - other than a mono-syllable definitionQuoted 1 line
+ struct
list_headtxc;
tx_compl_q- completion queueQuoted 1 line
+ struct
list_headtxe;
tx_avail_e- available entry queuedrivers/ntb/ntb_transport.c line 100
Quoted 3 lines
drivers/ntb/ntb_transport.c new file +3
-0+spinlock_t txq_lock; +spinlock_t txc_lock; +spinlock_t txe_lock;then match the variants accordingly.
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+struct list_head rxq; +struct list_head rxc; +struct list_head rxe; +spinlock_t rxq_lock; +spinlock_t rxc_lock; +spinlock_t rxe_lock;
Quoted 4 lines
Quoted 1 line
similarly the rx-counterpart
Are they difficult to understand? I can change them, but it seems rather moot since you seemed to immediately understand the logic behind the names.
Immediately understand? Not at first glance. I had to re-read the functions. Its really is a minor change and variables will then become self-explanatory. I can almost feel that a developer who works on this code for the first time might end up choosing the wrong 'syllable' and locking an entirely different lock.
Infact add a prefix 'ntb' to all the rx/tx locks. That way grep'ing output of lockstat also becomes easier.
It now reads: ntb_tx_pend_lock
Quoted 29 lines
Quoted 20 lines
..................
Quoted 16 lines
drivers/ntb/ntb_transport.c new file +16
-0+static void ntb_tx_copy_task (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry, +void *offset) +{ +struct ntb_payload_header *hdr = offset; +int rc; + + offset +=sizeof (struct ntb_payload_header ); +memcpy_toio (offset, entry->buf, entry->len); + + hdr->len = entry->len; + hdr->ver = qp->tx_pkts; + +/* Ensure that the data is fully copied out before setting the flag */ +wmb (); + hdr->flags = entry->flags |DESC_DONE_FLAG ;Quoted 8 lines
drivers/ntb/ntb_transport.c line 777
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+ + rc =ntb_ring_sdb (qp->ndev, qp->qp_num); +if (rc) +pr_err ("%s: error ringing db %d\n" , __func__, qp->qp_num); + +if (entry->len >0 ) {how do you interpret this len variable and decide if it's a good/bad completion?
Quoted 2 lines
The length of 0 is for messages from the remote system, which currently only consists of a "link down" message notifying the local system to no longer send any messages to the remote side.
May be I didn't read the code properly. Is there a length-comment that explains the above? If not then just by pure code inspection it would seem that a skb was leaked. So add the above comment that way we can save time for other netdev folks too.
Quoted 14 lines
Quoted 13 lines
drivers/ntb/ntb_transport.c line 786
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +9
-0+ qp->tx_bytes += entry->len; + +/* Add fully transmitted data to completion queue */ +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp); + }else +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);I could be wrong but how is the original skb handled if the code path goes in the else clause?
Quoted 5 lines
There is no skb is the length is zero. Since the only client is virtual ethernet, it will always be > 60. However, I should add a sanity check for 0 length in
tx_enqueue.Quoted 1 line
Also, in the else clause, how about a
ntb_list_add_headrather than a_tail.Why add to the head, it was just used?
Yes, just re-use what's hot(best guess).
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
drivers/ntb/ntb_transport.c new file +27
-0+ +static int ntb_process_tx (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry) +{ +struct ntb_payload_header *hdr; +void *offset; + + offset = qp->tx_offset; + hdr = offset; + +pr_debug ("%lld - offset %p, tx %p, entry len %d flags %x buff %p\n" , + qp->tx_pkts, offset, qp->tx_offset, entry->len, entry->flags, + entry->buf); +if (hdr->flags) { +ntb_list_add_head (&qp->txq_lock, &entry->entry, &qp->txq); + qp->tx_ring_full++; +return -EAGAIN ; + } + +if (entry->len > transport_mtu) { +pr_err ("Trying to send pkt size of %d\n" , entry->len); + entry->flags =HW_ERROR_FLAG ; + +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp);Quoted 8 lines
drivers/ntb/ntb_transport.c line 819
Quoted 5 lines
drivers/ntb/ntb_transport.c new file +5
-0+ +return 0 ; + } + +ntb_tx_copy_task (qp, entry, offset);what happens when
ntb_sdb_ringreturns an error? would you still want to incrementtx_pktsbelow?
Quoted 2 lines
It's not fatal if the remote side isn't notified. It will hurt latency, since the next packet would be the one that triggers the next interrupt. Also, the only way it could ever fail would be if it was an invalid interrupt bit being set, which should never happen.
What happens when the 'db >= ndev->max_cbs' check fails? Under what circumstances will that happen? When it does happen how does the remote side then gets notified or should it even get notified?
'which should never happen'? FYI - I have seen and debugged(not this one but doorbells and what not) weirdness while working on CLARiiON + PCie-interconnects. Board bring-up is a PITA. So you get the idea ...
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/ntb/ntb_transport.c new file +13
-0+void *ntb_transport_tx_dequeue (struct ntb_transport_qp *qp,unsigned int *len) +{ +struct ntb_queue_entry *entry; +void *buf; + +if (!qp) +return NULL ; + + entry =ntb_list_rm_head (&qp->txc_lock, &qp->txc); +if (!entry) +return NULL ; + + buf = entry->callback_data;Quoted 8 lines
drivers/ntb/ntb_transport.c line 1149
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+if (entry->flags !=HW_ERROR_FLAG ) + *len = entry->len; +else + *len = -EIO ; + +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);how about a
ntb_list_add_head?
Quoted 2 lines
Is there a benefit to adding to the head versus tail? It makes more sense to me to pull from the head and add to the tail.
Yes, explained above. Today there are 100(..DEF_NUM...) entries. Tomorrow there could be more. So why not re-use what's hot? You could also think of this as yet another way of forcing detection of double-use corruption/bug. I'm not saying that there's a bug here but you get the idea.
Chetan Loke
Quoted 42 lines · chetan loke
Quoted 1 line · Jon Mason
On Mon, Jul 16, 2012 at 12:49:39PM -0400, chetan loke wrote:
....
Quoted 26 lines
Quoted 26 lines
Is it ok to rename the following vars for convenience sake?
Quoted 1 line
+ struct
list_headtxq;
tx_pend_q- (pending_queue) ortx_out_q- (outstanding_queue) - or pick any new string you like - other than a mono-syllable definitionQuoted 1 line
+ struct
list_headtxc;
tx_compl_q- completion queueQuoted 1 line
+ struct
list_headtxe;
tx_avail_e- available entry queuedrivers/ntb/ntb_transport.c line 100
Quoted 3 lines
drivers/ntb/ntb_transport.c new file +3
-0+spinlock_t txq_lock; +spinlock_t txc_lock; +spinlock_t txe_lock;then match the variants accordingly.
Quoted 6 lines
drivers/ntb/ntb_transport.c new file +6
-0+struct list_head rxq; +struct list_head rxc; +struct list_head rxe; +spinlock_t rxq_lock; +spinlock_t rxc_lock; +spinlock_t rxe_lock;Quoted 4 lines
Quoted 1 line
similarly the rx-counterpart
Are they difficult to understand? I can change them, but it seems rather moot since you seemed to immediately understand the logic behind the names.
Immediately understand? Not at first glance. I had to re-read the functions. Its really is a minor change and variables will then become self-explanatory. I can almost feel that a developer who works on this code for the first time might end up choosing the wrong 'syllable' and locking an entirely different lock.
Quoted 4 lines
Infact add a prefix 'ntb' to all the rx/tx locks. That way grep'ing output of lockstat also becomes easier.
It now reads:
ntb_tx_pend_lock
Makes sense
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
..................
Quoted 12 lines
drivers/ntb/ntb_transport.c new file +12
-0+static void ntb_tx_copy_task (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry, +void *offset) +{ +struct ntb_payload_header *hdr = offset; +int rc; + + offset +=sizeof (struct ntb_payload_header ); +memcpy_toio (offset, entry->buf, entry->len); + + hdr->len = entry->len; + hdr->ver = qp->tx_pkts;drivers/ntb/ntb_transport.c line 777
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +10
-0+ +/* Ensure that the data is fully copied out before setting the flag */ +wmb (); + hdr->flags = entry->flags |DESC_DONE_FLAG ; + + rc =ntb_ring_sdb (qp->ndev, qp->qp_num); +if (rc) +pr_err ("%s: error ringing db %d\n" , __func__, qp->qp_num); + +if (entry->len >0 ) {how do you interpret this len variable and decide if it's a good/bad completion?
Quoted 7 lines
Quoted 2 lines
The length of 0 is for messages from the remote system, which currently only consists of a "link down" message notifying the local system to no longer send any messages to the remote side.
May be I didn't read the code properly. Is there a length-comment that explains the above? If not then just by pure code inspection it would seem that a skb was leaked. So add the above comment that way we can save time for other netdev folks too.
I'll add a comment.
Quoted 61 lines
Quoted 16 lines
Quoted 15 lines
drivers/ntb/ntb_transport.c line 786
Quoted 12 lines
drivers/ntb/ntb_transport.c new file +9
-0+ qp->tx_bytes += entry->len; + +/* Add fully transmitted data to completion queue */ +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp); + }else +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);I could be wrong but how is the original skb handled if the code path goes in the else clause?
Quoted 5 lines
There is no skb is the length is zero. Since the only client is virtual ethernet, it will always be > 60. However, I should add a sanity check for 0 length in
tx_enqueue.Quoted 1 line
Also, in the else clause, how about a
ntb_list_add_headrather than a_tail.Why add to the head, it was just used?
Yes, just re-use what's hot(best guess).
Quoted 37 lines
Quoted 36 lines
Quoted 23 lines
drivers/ntb/ntb_transport.c new file +22
-0+ +static int ntb_process_tx (struct ntb_transport_qp *qp, +struct ntb_queue_entry *entry) +{ +struct ntb_payload_header *hdr; +void *offset; + + offset = qp->tx_offset; + hdr = offset; + +pr_debug ("%lld - offset %p, tx %p, entry len %d flags %x buff %p\n" , + qp->tx_pkts, offset, qp->tx_offset, entry->len, entry->flags, + entry->buf); +if (hdr->flags) { +ntb_list_add_head (&qp->txq_lock, &entry->entry, &qp->txq); + qp->tx_ring_full++; +return -EAGAIN ; + } + +if (entry->len > transport_mtu) { +pr_err ("Trying to send pkt size of %d\n" , entry->len); + entry->flags =HW_ERROR_FLAG ;drivers/ntb/ntb_transport.c line 819
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +10
-0+ +ntb_list_add_tail (&qp->txc_lock, &entry->entry, &qp->txc); + +if (qp->tx_handler) + qp->tx_handler (qp); + +return 0 ; + } + +ntb_tx_copy_task (qp, entry, offset);what happens when
ntb_sdb_ringreturns an error? would you still want to incrementtx_pktsbelow?
Quoted 6 lines
Quoted 2 lines
It's not fatal if the remote side isn't notified. It will hurt latency, since the next packet would be the one that triggers the next interrupt. Also, the only way it could ever fail would be if it was an invalid interrupt bit being set, which should never happen.
What happens when the 'db >=
ndev->max_cbs' check fails? Under what circumstances will that happen? When it does happen how does the remote side then gets notified or should it even get notified?
It should never happen, as there are checks when enqueuing that the transport queue is valid. It is more of a sanity check than anything else.
Quoted 3 lines
'which should never happen'? FYI - I have seen and debugged(not this one but doorbells and what not) weirdness while working on CLARiiON + PCie-interconnects. Board bring-up is a PITA. So you get the idea ...
I understand, that is why I had the sanity check code. Paranoia can be a good thing.
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +9
-0+void *ntb_transport_tx_dequeue (struct ntb_transport_qp *qp,unsigned int *len) +{ +struct ntb_queue_entry *entry; +void *buf; + +if (!qp) +return NULL ; + + entry =ntb_list_rm_head (&qp->txc_lock, &qp->txc);drivers/ntb/ntb_transport.c line 1149
Quoted 10 lines
drivers/ntb/ntb_transport.c new file +10
-0+if (!entry) +return NULL ; + + buf = entry->callback_data; +if (entry->flags !=HW_ERROR_FLAG ) + *len = entry->len; +else + *len = -EIO ; + +ntb_list_add_tail (&qp->txe_lock, &entry->entry, &qp->txe);how about a
ntb_list_add_head?
Quoted 8 lines
Quoted 2 lines
Is there a benefit to adding to the head versus tail? It makes more sense to me to pull from the head and add to the tail.
Yes, explained above. Today there are 100(..DEF_NUM...) entries. Tomorrow there could be more. So why not re-use what's hot? You could also think of this as yet another way of forcing detection of double-use corruption/bug. I'm not saying that there's a bug here but you get the idea.
I'm fairly sure the list is suboptimal performance-wise, but it is much easier to use when developing. Perhaps I should use a fixed size array instead.
Thanks for the reviews!
Quoted 2 lines
Chetan Loke