Skip to contentSkip to conversation

liquidio: switchdev support for LiquidIO NIC

PATCH In review Felix Manlunas 5 participants 8 messages Oct 31, 2017 – Nov 1, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 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 hypervisor. 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

Patchset Change Log:
V2 -> V3:
* Use mac address as the physical switchID.
* Check for eswitch_mode before returning switchID

V1 -> V2:
* Name the representors "pfXvfY".
* Drop patch3 (ethtool support for switchdev ports) that was in V1 because it's not necessary.

Vijaya Mohan Guvva (2):
liquidio: switchdev support for LiquidIO NIC
liquidio: Configure switchdev with devlink

 drivers/net/ethernet/cavium/Kconfig                |   1 +
 drivers/net/ethernet/cavium/liquidio/Makefile      |   2 +-
 drivers/net/ethernet/cavium/liquidio/lio_main.c    | 118 ++++
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c  | 627 +++++++++++++++++++++
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.h  |  47 ++
 .../net/ethernet/cavium/liquidio/liquidio_common.h |  50 ++
 .../net/ethernet/cavium/liquidio/octeon_device.h   |  14 +
 7 files changed, 858 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 v3 1/2 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    |  25 +
 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, 750 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 +25 -0
index 8ea24d6..8078412 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,29 @@ 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);
+
+	switch (attr->id) {
+	case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
+		attr->u.ppid.id_len = ETH_ALEN;
+		ether_addr_copy(attr->u.ppid.id,
+				(void *)&lio->linfo.hw_addr + 2);
+		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 +3607,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
#5 lore raw

PATCH v3 2/2 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    | 93 ++++++++++++++++++++++
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c  |  6 ++
 .../net/ethernet/cavium/liquidio/liquidio_common.h |  1 +
 .../net/ethernet/cavium/liquidio/octeon_device.h   |  7 ++
 5 files changed, 108 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 +93 -0

144 lines not on this page · raw message

drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c +6 -0
index 67ff7a1..de0c80d 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 +1 -0
index 3aceb78..441cc78 100644
@@ -114,6 +114,7 @@ enum octeon_tag_type {
 
 /* App specific capabilities from firmware to pf driver */
 #define LIQUIDIO_TIME_SYNC_CAP 0x1
+#define LIQUIDIO_SWITCHDEV_CAP 0x2
 
 static inline u32 incr_index(u32 index, u32 count, u32 max)
 {
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
#6 lore raw
In reply to Felix Manlunas
Quoted 8 lines · Felix Manlunas

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 hypervisor. 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 6 lines

patch2 adds support for switchdev enable/disable from devlink

Patchset Change Log:
V2 -> V3:
* Use mac address as the physical switchID.
* Check for eswitch_mode before returning switchID

Looks better, thanks!

maintainer
#7 lore raw
In reply to Felix Manlunas

From: Felix Manlunas <[email protected]>
Date: Tue, 31 Oct 2017 16:04:20 -0700

Quoted 15 lines

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 hypervisor. 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

Patchset Change Log:
V2 -> V3:
* Use mac address as the physical switchID.
* Check for eswitch_mode before returning switchID

Quoted 4 lines

V1 -> V2:
* Name the representors "pfXvfY".
* Drop patch3 (ethtool support for switchdev ports) that was in V1 because it's not necessary.

Series applied, thanks.

#2 lore raw
In reply to Felix Manlunas

drivers/net/ethernet/cavium/liquidio/lio_main.c static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx, · line 3322

Quoted 10 lines
drivers/net/ethernet/cavium/liquidio/lio_main.c +10 -0
+static int
+lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr)
+{
+	struct lio *lio = GET_LIO(dev);
+
+	switch (attr->id) {
+	case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
+		attr->u.ppid.id_len = ETH_ALEN;
+		ether_addr_copy(attr->u.ppid.id,
+				(void *)&lio->linfo.hw_addr + 2);

The + 2 seems odd. Please could you explain why it is there?

Quoted 9 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +9 -0
+static int lio_vf_rep_open(struct net_device *ndev);
+static int lio_vf_rep_stop(struct net_device *ndev);
+static int lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev);
+static void lio_vf_rep_tx_timeout(struct net_device *netdev);
+static int lio_vf_rep_phys_port_name(struct net_device *dev,
+				     char *buf, size_t len);
+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);

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

Quoted 10 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +10 -0
+
+static const struct net_device_ops lio_vf_rep_ndev_ops = {
+	.ndo_open = lio_vf_rep_open,
+	.ndo_stop = lio_vf_rep_stop,
+	.ndo_start_xmit = lio_vf_rep_pkt_xmit,
+	.ndo_tx_timeout = lio_vf_rep_tx_timeout,
+	.ndo_get_phys_port_name = lio_vf_rep_phys_port_name,
+	.ndo_get_stats64 = lio_vf_rep_get_stats64,
+	.ndo_change_mtu = lio_vf_rep_change_mtu,
+};

Please don't use forward references. Change the order of the code and put this structure towards the end of the file.

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

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

EOPNOTSUPP seems an odd return code for too short a buffer?

Andrew

#3 lore raw
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
drivers/net/ethernet/cavium/liquidio/lio_main.c +4 -0
+static int
+lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr)
+{
+	struct lio *lio = GET_LIO(dev);
Quoted 8 lines

drivers/net/ethernet/cavium/liquidio/lio_main.c static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx, · line 3322

Quoted 6 lines
drivers/net/ethernet/cavium/liquidio/lio_main.c +6 -0
+
+	switch (attr->id) {
+	case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
+		attr->u.ppid.id_len = ETH_ALEN;
+		ether_addr_copy(attr->u.ppid.id,
+				(void *)&lio->linfo.hw_addr + 2);

The + 2 seems odd. Please could you explain why it is there?

The "+ 2" is the byte offset of the start of the mac address. In a future patch, we will replace "(void *)&lio->linfo.hw_addr + 2" with "dev->dev_addr" which is an elegant equivalent.

Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +14 -0
+static int lio_vf_rep_open(struct net_device *ndev);
+static int lio_vf_rep_stop(struct net_device *ndev);
+static int lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev);
+static void lio_vf_rep_tx_timeout(struct net_device *netdev);
+static int lio_vf_rep_phys_port_name(struct net_device *dev,
+				     char *buf, size_t len);
+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 struct net_device_ops lio_vf_rep_ndev_ops = {
+	.ndo_open = lio_vf_rep_open,
+	.ndo_stop = lio_vf_rep_stop,
+	.ndo_start_xmit = lio_vf_rep_pkt_xmit,
Quoted 8 lines

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

Quoted 5 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +5 -0
+	.ndo_tx_timeout = lio_vf_rep_tx_timeout,
+	.ndo_get_phys_port_name = lio_vf_rep_phys_port_name,
+	.ndo_get_stats64 = lio_vf_rep_get_stats64,
+	.ndo_change_mtu = lio_vf_rep_change_mtu,
+};

Please don't use forward references. Change the order of the code and put this structure towards the end of the file.

We will fix this in a future patch.

Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +5 -0
+lio_vf_rep_phys_port_name(struct net_device *dev,
+			  char *buf, size_t len)
+{
+	struct lio_vf_rep_desc *vf_rep = netdev_priv(dev);
+	struct octeon_device *oct = vf_rep->oct;
Quoted 8 lines

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

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

EOPNOTSUPP seems an odd return code for too short a buffer?

We will replace that with ENOBUFS in a future patch.

#4 lore raw
Quoted 14 lines · Felix Manlunas
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c new file +5 -0
+lio_vf_rep_phys_port_name(struct net_device *dev,
+			  char *buf, size_t len)
+{
+	struct lio_vf_rep_desc *vf_rep = netdev_priv(dev);
+	struct octeon_device *oct = vf_rep->oct;
Quoted 8 lines

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

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

EOPNOTSUPP seems an odd return code for too short a buffer?

Quoted 1 line

We will replace that with ENOBUFS in a future patch.

Strangely enough mlx5 and bnxt also use EOPNOTSUPP if string doesn't fit. Others use EINVAL, IMHO that's more appropriate.