Skip to contentSkip to conversation

liquidio: Switchdev support for LiquidIO NIC

PATCH Superseded Felix Manlunas 3 participants 7 messages Oct 26, 2017

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover liquidio: Switchdev support for LiquidIO NIC

From: Vijaya Mohan Guvva <[email protected]>

patch1 of this patch set adds switchdev support for SRIOV capable LiquidIO NIC, so that for every SRIOV VF on LiquidIO, a representor netdev is created on hyperviser. It also has changes to send representor interface configurations like admin state and MTU to LiquidIO firmware and to retrieve HW counted VF stats for VF representor.

patch2 adds support for switchdev enable/disable from devlink

patch3 adds ethtool support for vf representor interface to return VF representor port stats and driver info.

Vijaya Mohan Guvva (3):
liquidio: switchdev support for LiquidIO NIC
liquidio: Configure switchdev with devlink
liquidio: ethtool support for switchdev ports

 drivers/net/ethernet/cavium/Kconfig                |   1 +
 drivers/net/ethernet/cavium/liquidio/Makefile      |   2 +-
 drivers/net/ethernet/cavium/liquidio/lio_main.c    | 117 ++++
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c  | 714 +++++++++++++++++++++
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.h  |  47 ++
 .../net/ethernet/cavium/liquidio/liquidio_common.h |  51 ++
 .../net/ethernet/cavium/liquidio/octeon_device.h   |  14 +
 7 files changed, 945 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c
 create mode 100644 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.h
Signature · 1 line
2.9.0
#1 lore raw

PATCH 1/3 liquidio: switchdev support for LiquidIO NIC

From: Vijaya Mohan Guvva <[email protected]>

Enable switchdev for SRIOV capable LiquidIO NIC. It registers a representor netdev (with switchdev_ops) for each SRIOV VF created. It also has changes to send representor interface configurations like admin state and MTU to LiquidIO firmware and to retrieve HW counted VF stats for VF representor.

---
 drivers/net/ethernet/cavium/liquidio/Makefile      |   2 +-
 drivers/net/ethernet/cavium/liquidio/lio_main.c    |  28 +
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c  | 621 +++++++++++++++++++++
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.h  |  47 ++
 .../net/ethernet/cavium/liquidio/liquidio_common.h |  49 ++
 .../net/ethernet/cavium/liquidio/octeon_device.h   |   7 +
 6 files changed, 753 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c
 create mode 100644 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.h
drivers/net/ethernet/cavium/liquidio/Makefile +1 -1
index c4d411d..cad4fe1 100644
@@ -17,7 +17,7 @@ liquidio-$(CONFIG_LIQUIDIO) += lio_ethtool.o \
 			octeon_droq.o      \
 			octeon_nic.o
 
-liquidio-objs := lio_main.o octeon_console.o $(liquidio-y)
+liquidio-objs := lio_main.o octeon_console.o lio_vf_rep.o $(liquidio-y)
 
 obj-$(CONFIG_LIQUIDIO_VF) += liquidio_vf.o
 
drivers/net/ethernet/cavium/liquidio/lio_main.c +28 -0
index b4f753c..a946996 100644
@@ -21,6 +21,7 @@
 #include <linux/firmware.h>
 #include <net/vxlan.h>
 #include <linux/kthread.h>
+#include <net/switchdev.h>
 #include "liquidio_common.h"
 #include "octeon_droq.h"
 #include "octeon_iq.h"
@@ -3309,6 +3310,32 @@ static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx,
 	return 0;
 }
 
+static int
+lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr)
+{
+	struct lio *lio = GET_LIO(dev);
+	struct octeon_device *oct = lio->oct_dev;
+	char phy_switch_id[] = {0x17, 0x7d, 0x97, 0x02, 0x00};
+	int len = sizeof(phy_switch_id);
+
+	switch (attr->id) {
+	case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
+		phy_switch_id[len - 1] = oct->pf_num;
+		attr->u.ppid.id_len = len;
+		memcpy(attr->u.ppid.id, phy_switch_id, len);
+		break;
+
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static const struct switchdev_ops lio_pf_switchdev_ops = {
+	.switchdev_port_attr_get = lio_pf_switchdev_attr_get,
+};
+
 static const struct net_device_ops lionetdevops = {
 	.ndo_open		= liquidio_open,
 	.ndo_stop		= liquidio_stop,
@@ -3583,6 +3610,7 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
 		 * netdev tasks.
 		 */
 		netdev->netdev_ops = &lionetdevops;
+		SWITCHDEV_SET_OPS(netdev, &lio_pf_switchdev_ops);
 
 		lio = GET_LIO(netdev);
 
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +621 -0

621 lines not on this page · raw message

drivers/net/ethernet/cavium/liquidio/lio_vf_rep.h new file +47 -0

47 lines not on this page · raw message

drivers/net/ethernet/cavium/liquidio/liquidio_common.h +49 -0

59 lines not on this page · raw message

drivers/net/ethernet/cavium/liquidio/octeon_device.h +7 -0
index 33d19c4..c97e067 100644
@@ -391,6 +391,11 @@ struct octeon_ioq_vector {
 	u32			ioq_num;
 };
 
+struct lio_vf_rep_list {
+	int num_vfs;
+	struct net_device *ndev[CN23XX_MAX_VFS_PER_PF];
+};
+
 /** The Octeon device.
  *  Each Octeon device has this structure to represent all its
  *  components.
@@ -568,6 +573,8 @@ struct octeon_device {
 	atomic_t *adapter_fw_state; /* per-adapter, lio_fw_state */
 
 	bool ptp_enable;
+
+	struct lio_vf_rep_list vf_rep_list;
 };
 
 #define  OCT_DRV_ONLINE 1
Signature · 1 line
2.9.0
#3 lore raw

PATCH 2/3 liquidio: Configure switchdev with devlink

In reply to Felix Manlunas

From: Vijaya Mohan Guvva <[email protected]>

Enable and disable switchdev on SRIOV capable LiquidIO NIC with devlink. Create representor netdev for each SRIOV VF function on SRIOV enable and and do the cleanup on SRIOV disable.

---
 drivers/net/ethernet/cavium/Kconfig                |  1 +
 drivers/net/ethernet/cavium/liquidio/lio_main.c    | 89 ++++++++++++++++++++++
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c  |  6 ++
 .../net/ethernet/cavium/liquidio/liquidio_common.h |  2 +
 .../net/ethernet/cavium/liquidio/octeon_device.h   |  7 ++
 5 files changed, 105 insertions(+)
drivers/net/ethernet/cavium/Kconfig +1 -0
index dcbce6c..63be75e 100644
@@ -53,6 +53,7 @@ config	THUNDER_NIC_RGX
 config LIQUIDIO
 	tristate "Cavium LiquidIO support"
 	depends on 64BIT
+	depends on MAY_USE_DEVLINK
 	imply PTP_1588_CLOCK
 	select FW_LOADER
 	select LIBCRC32C
drivers/net/ethernet/cavium/liquidio/lio_main.c +89 -0

137 lines not on this page · raw message

drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c +6 -0
index 760893c..2207956 100644
@@ -515,6 +515,9 @@ lio_vf_rep_create(struct octeon_device *oct)
 	struct net_device *ndev;
 	int i, num_vfs;
 
+	if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
+		return 0;
+
 	if (!oct->sriov_info.sriov_enabled)
 		return 0;
 
@@ -599,6 +602,9 @@ lio_vf_rep_destroy(struct octeon_device *oct)
 	struct net_device *ndev;
 	int i;
 
+	if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
+		return;
+
 	if (!oct->sriov_info.sriov_enabled)
 		return;
 
drivers/net/ethernet/cavium/liquidio/liquidio_common.h +2 -0
index 3aceb78..1226ba5 100644
@@ -110,6 +110,8 @@ enum octeon_tag_type {
 #define MAX_IOQ_INTERRUPTS_PER_PF   (64 * 2)
 #define MAX_IOQ_INTERRUPTS_PER_VF   (8 * 2)
 
+#define LIQUIDIO_SWITCHDEV_CAP 0x2
+
 #define SCR2_BIT_FW_LOADED	    63
 
 /* App specific capabilities from firmware to pf driver */
drivers/net/ethernet/cavium/liquidio/octeon_device.h +7 -0
index c97e067..63b0c75 100644
@@ -23,6 +23,7 @@
 #define  _OCTEON_DEVICE_H_
 
 #include <linux/interrupt.h>
+#include <net/devlink.h>
 
 /** PCI VendorId Device Id */
 #define  OCTEON_CN68XX_PCIID          0x91177d
@@ -396,6 +397,10 @@ struct lio_vf_rep_list {
 	struct net_device *ndev[CN23XX_MAX_VFS_PER_PF];
 };
 
+struct lio_devlink_priv {
+	struct octeon_device *oct;
+};
+
 /** The Octeon device.
  *  Each Octeon device has this structure to represent all its
  *  components.
@@ -575,6 +580,8 @@ struct octeon_device {
 	bool ptp_enable;
 
 	struct lio_vf_rep_list vf_rep_list;
+	struct devlink *devlink;
+	enum devlink_eswitch_mode eswitch_mode;
 };
 
 #define  OCT_DRV_ONLINE 1
Signature · 1 line
2.9.0
#4 lore raw

PATCH 3/3 liquidio: ethtool support for switchdev ports

In reply to Felix Manlunas

From: Vijaya Mohan Guvva <[email protected]>

Added ethtool support for vf representor ports to return port stats and driver info.

---
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c | 87 +++++++++++++++++++++++
 1 file changed, 87 insertions(+)
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c +87 -0
index 2207956..92dcf54 100644
@@ -26,6 +26,7 @@
 #include "octeon_main.h"
 #include "octeon_network.h"
 #include <net/switchdev.h>
+#include <linux/ethtool.h>
 #include "lio_vf_rep.h"
 #include "octeon_network.h"
 
@@ -39,6 +40,91 @@ static void lio_vf_rep_get_stats64(struct net_device *dev,
 				   struct rtnl_link_stats64 *stats64);
 static int lio_vf_rep_change_mtu(struct net_device *ndev, int new_mtu);
 
+static const char lio_vf_rep_stats_strings[][ETH_GSTRING_LEN] = {
+	"rx_packets",
+	"tx_packets",
+	"rx_bytes",
+	"tx_bytes",
+	"rx_dropped",
+	"tx_dropped",
+};
+
+static void
+lio_vf_rep_get_drvinfo(struct net_device *ndev,
+		       struct ethtool_drvinfo *drvinfo)
+{
+	struct lio_vf_rep_desc *vf_rep = netdev_priv(ndev);
+	struct octeon_device *oct;
+
+	oct = vf_rep->oct;
+
+	memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
+	strcpy(drvinfo->driver, "liquidio");
+	strcpy(drvinfo->version, LIQUIDIO_VERSION);
+	strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
+		ETHTOOL_FWVERS_LEN);
+}
+
+static void
+lio_vf_rep_get_ethtool_stats(struct net_device *ndev,
+			     struct ethtool_stats *stats,
+			     u64 *data)
+{
+	struct rtnl_link_stats64 *stats_ptr, net_stats;
+	int i = 0;
+
+	stats_ptr = dev_get_stats(ndev, &net_stats);
+
+	data[i++] = stats_ptr->rx_packets;
+	data[i++] = stats_ptr->tx_packets;
+	data[i++] = stats_ptr->rx_bytes;
+	data[i++] = stats_ptr->tx_bytes;
+	data[i++] = stats_ptr->rx_dropped;
+	data[i++] = stats_ptr->tx_dropped;
+}
+
+static int
+lio_vf_rep_get_sset_count(struct net_device *ndev, int sset)
+{
+	switch (sset) {
+	case ETH_SS_STATS:
+		return ARRAY_SIZE(lio_vf_rep_stats_strings);
+
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static void
+lio_vf_rep_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
+{
+	struct lio_vf_rep_desc *vf_rep = netdev_priv(ndev);
+	struct octeon_device *oct = vf_rep->oct;
+	int i, num_stats;
+
+	switch (stringset) {
+	case ETH_SS_STATS:
+		num_stats = ARRAY_SIZE(lio_vf_rep_stats_strings);
+		for (i = 0; i < num_stats; i++) {
+			sprintf(data, "%s", lio_vf_rep_stats_strings[i]);
+			data += ETH_GSTRING_LEN;
+		}
+		break;
+
+	default:
+		dev_err(&oct->pci_dev->dev, "Unknown Stringset !!\n");
+		break;
+	}
+}
+
+static const struct ethtool_ops lio_vf_rep_ethtool_ops = {
+	.get_drvinfo	= lio_vf_rep_get_drvinfo,
+	.get_link	= ethtool_op_get_link,
+	.get_strings	= lio_vf_rep_get_strings,
+	.get_sset_count	= lio_vf_rep_get_sset_count,
+	.get_ethtool_stats = lio_vf_rep_get_ethtool_stats,
+};
+
 static const struct net_device_ops lio_vf_rep_ndev_ops = {
 	.ndo_open = lio_vf_rep_open,
 	.ndo_stop = lio_vf_rep_stop,
@@ -537,6 +623,7 @@ lio_vf_rep_create(struct octeon_device *oct)
 		ndev->max_mtu = LIO_MAX_MTU_SIZE;
 		ndev->netdev_ops = &lio_vf_rep_ndev_ops;
 		SWITCHDEV_SET_OPS(ndev, &lio_vf_rep_switchdev_ops);
+		ndev->ethtool_ops = &lio_vf_rep_ethtool_ops;
 
 		vf_rep = netdev_priv(ndev);
 		memset(vf_rep, 0, sizeof(*vf_rep));
Signature · 1 line
2.9.0
#6 lore raw
In reply to Felix Manlunas
Quoted 8 lines · Thu, Oct 26, 2017 at 07:36:41AM CEST, [email protected] wrote:

From: Vijaya Mohan Guvva <[email protected]>

patch1 of this patch set adds switchdev support for SRIOV capable LiquidIO NIC, so that for every SRIOV VF on LiquidIO, a representor netdev is created on hyperviser. It also has changes to send representor interface configurations like admin state and MTU to LiquidIO firmware and to retrieve HW counted VF stats for VF representor.

Quoted 4 lines

patch2 adds support for switchdev enable/disable from devlink

patch3 adds ethtool support for vf representor interface to return VF representor port stats and driver info.

Looks fine to me.

#2 lore raw

Re: [PATCH net-next 1/3] liquidio: switchdev support for LiquidIO NIC

In reply to Felix Manlunas
Quoted 4 lines · Felix Manlunas
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +4 -0
+static int
+lio_vf_rep_phys_port_name(struct net_device *dev,
+			  char *buf, size_t len)
+{

drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c line 254

Quoted 10 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +10 -0
+	struct lio_vf_rep_desc *vf_rep = netdev_priv(dev);
+	struct octeon_device *oct = vf_rep->oct;
+	int ret;
+
+	ret = snprintf(buf, len, "%d", vf_rep->ifidx - oct->pf_num * 64 - 1);
+	if (ret >= len)
+		return -EOPNOTSUPP;
+
+	return 0;
+}

If you have multiple PFs please name the representors "pfXvfY".

#5 lore raw

Re: [PATCH net-next 3/3] liquidio: ethtool support for switchdev ports

In reply to Felix Manlunas
Quoted 18 lines · Felix Manlunas
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c +17 -0
+static const char lio_vf_rep_stats_strings[][ETH_GSTRING_LEN] = {
+	"rx_packets",
+	"tx_packets",
+	"rx_bytes",
+	"tx_bytes",
+	"rx_dropped",
+	"tx_dropped",
+};
+
[...]
+
+static void
+lio_vf_rep_get_ethtool_stats(struct net_device *ndev,
+			     struct ethtool_stats *stats,
+			     u64 *data)
+{
+	struct rtnl_link_stats64 *stats_ptr, net_stats;
+	int i = 0;

drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c static void lio_vf_rep_get_stats64(struct net_device *dev, · line 84

Quoted 10 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c +10 -0
+
+	stats_ptr = dev_get_stats(ndev, &net_stats);
+
+	data[i++] = stats_ptr->rx_packets;
+	data[i++] = stats_ptr->tx_packets;
+	data[i++] = stats_ptr->rx_bytes;
+	data[i++] = stats_ptr->tx_bytes;
+	data[i++] = stats_ptr->rx_dropped;
+	data[i++] = stats_ptr->tx_dropped;
+}

Duplicating basic netdev stats in ethtool is discouraged these days.