Skip to contentSkip to conversation

bnxt_en: Updates for net-next.

PATCH In review Michael Chan 10 participants 38 messages Jul 24, 2017 – Jul 28, 2017

Subsystems (8)
lore
Share & tools
lore

Michael Chan

author maintainer
#0 lore raw

cover bnxt_en: Updates for net-next.

This series includes updating the firmware interface, adding methods to get and set VEPA/VEB bridge modes, some minor DCBX and ETS refinements, and 3 patches from Sathya Perla to implement initial VF representors for SRIOV switching.

Michael Chan (7):
bnxt_en: Update firmware interface spec to 1.8.0.
bnxt_en: Retrieve the hardware bridge mode from the firmware.
bnxt_en: Implement ndo_bridge_{get|set}link methods.
bnxt_en: Add bnxt_get_num_stats() to centrally get the number of
ethtool stats.
bnxt_en: Allow the user to set ethtool stats-block-usecs to 0.
bnxt_en: Report firmware DCBX agent.
bnxt_en: Set ETS min_bw parameter for older firmware.

Sathya Perla (3):
bnxt_en: add support to enable VF-representors
bnxt_en: add vf-rep RX/TX and netdev implementation
bnxt_en: add support for port_attr_get and and get_phys_port_name

 drivers/net/ethernet/broadcom/Kconfig             |   1 +
 drivers/net/ethernet/broadcom/bnxt/Makefile       |   2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c         | 237 +++++++++--
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  54 ++-
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c     |  17 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.h     |   1 +
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c |  33 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h     | 322 ++++++++++++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c   |  15 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c     | 489 ++++++++++++++++++++++
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h     |  42 ++
 11 files changed, 1134 insertions(+), 79 deletions(-)
 create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c
 create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h
Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw

PATCH 1/10 bnxt_en: Update firmware interface spec to 1.8.0.

VF representors and PTP are added features in the new firmware spec.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c       |   8 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.h       |   8 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h   | 322 +++++++++++++++++++++---
 drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c |   9 +-
 4 files changed, 308 insertions(+), 39 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5 -3
index e7c8539..2103f14 100644
@@ -5646,7 +5646,7 @@ static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
 	if (rc)
 		goto hwrm_phy_qcaps_exit;
 
-	if (resp->eee_supported & PORT_PHY_QCAPS_RESP_EEE_SUPPORTED) {
+	if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) {
 		struct ethtool_eee *eee = &bp->eee;
 		u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
 
@@ -5686,13 +5686,15 @@ static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
 
 	memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
 	link_info->phy_link_status = resp->link;
-	link_info->duplex =  resp->duplex;
+	link_info->duplex = resp->duplex_cfg;
+	if (bp->hwrm_spec_code >= 0x10800)
+		link_info->duplex = resp->duplex_state;
 	link_info->pause = resp->pause;
 	link_info->auto_mode = resp->auto_mode;
 	link_info->auto_pause_setting = resp->auto_pause;
 	link_info->lp_pause = resp->link_partner_adv_pause;
 	link_info->force_pause_setting = resp->force_pause;
-	link_info->duplex_setting = resp->duplex;
+	link_info->duplex_setting = resp->duplex_cfg;
 	if (link_info->phy_link_status == BNXT_LINK_LINK)
 		link_info->link_speed = le16_to_cpu(resp->link_speed);
 	else
drivers/net/ethernet/broadcom/bnxt/bnxt.h +4 -4
index f34691f..505691a 100644
@@ -12,10 +12,10 @@
 #define BNXT_H
 
 #define DRV_MODULE_NAME		"bnxt_en"
-#define DRV_MODULE_VERSION	"1.7.0"
+#define DRV_MODULE_VERSION	"1.8.0"
 
 #define DRV_VER_MAJ	1
-#define DRV_VER_MIN	7
+#define DRV_VER_MIN	8
 #define DRV_VER_UPD	0
 
 #include <linux/interrupt.h>
@@ -825,8 +825,8 @@ struct bnxt_link_info {
 	u8			loop_back;
 	u8			link_up;
 	u8			duplex;
-#define BNXT_LINK_DUPLEX_HALF	PORT_PHY_QCFG_RESP_DUPLEX_HALF
-#define BNXT_LINK_DUPLEX_FULL	PORT_PHY_QCFG_RESP_DUPLEX_FULL
+#define BNXT_LINK_DUPLEX_HALF	PORT_PHY_QCFG_RESP_DUPLEX_STATE_HALF
+#define BNXT_LINK_DUPLEX_FULL	PORT_PHY_QCFG_RESP_DUPLEX_STATE_FULL
 	u8			pause;
 #define BNXT_LINK_PAUSE_TX	PORT_PHY_QCFG_RESP_PAUSE_TX
 #define BNXT_LINK_PAUSE_RX	PORT_PHY_QCFG_RESP_PAUSE_RX
drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h +293 -29

490 lines not on this page · raw message

drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c +6 -3
index b8e7248..fde7256 100644
@@ -794,8 +794,10 @@ static int bnxt_vf_set_link(struct bnxt *bp, struct bnxt_vf_info *vf)
 					PORT_PHY_QCFG_RESP_LINK_LINK;
 				phy_qcfg_resp.link_speed = cpu_to_le16(
 					PORT_PHY_QCFG_RESP_LINK_SPEED_10GB);
-				phy_qcfg_resp.duplex =
-					PORT_PHY_QCFG_RESP_DUPLEX_FULL;
+				phy_qcfg_resp.duplex_cfg =
+					PORT_PHY_QCFG_RESP_DUPLEX_CFG_FULL;
+				phy_qcfg_resp.duplex_state =
+					PORT_PHY_QCFG_RESP_DUPLEX_STATE_FULL;
 				phy_qcfg_resp.pause =
 					(PORT_PHY_QCFG_RESP_PAUSE_TX |
 					 PORT_PHY_QCFG_RESP_PAUSE_RX);
@@ -804,7 +806,8 @@ static int bnxt_vf_set_link(struct bnxt *bp, struct bnxt_vf_info *vf)
 			/* force link down */
 			phy_qcfg_resp.link = PORT_PHY_QCFG_RESP_LINK_NO_LINK;
 			phy_qcfg_resp.link_speed = 0;
-			phy_qcfg_resp.duplex = PORT_PHY_QCFG_RESP_DUPLEX_HALF;
+			phy_qcfg_resp.duplex_state =
+				PORT_PHY_QCFG_RESP_DUPLEX_STATE_HALF;
 			phy_qcfg_resp.pause = 0;
 		}
 		rc = bnxt_hwrm_fwd_resp(bp, vf, &phy_qcfg_resp,
Signature · 1 line
1.8.3.1
author maintainer
#2 lore raw

PATCH 2/10 bnxt_en: Retrieve the hardware bridge mode from the firmware.

In reply to Michael Chan

Retrieve and store the hardware bridge mode, so that we can implement ndo_bridge_{get|set)link methods in the next patch.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 8 ++++++++
 drivers/net/ethernet/broadcom/bnxt/bnxt.h | 1 +
 2 files changed, 9 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -0
index 2103f14..ec8a195 100644
@@ -33,6 +33,7 @@
 #include <linux/mii.h>
 #include <linux/if.h>
 #include <linux/if_vlan.h>
+#include <linux/if_bridge.h>
 #include <linux/rtc.h>
 #include <linux/bpf.h>
 #include <net/ip.h>
@@ -4610,6 +4611,13 @@ static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
 		bp->port_partition_type = resp->port_partition_type;
 		break;
 	}
+	if (bp->hwrm_spec_code < 0x10707 ||
+	    resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB)
+		bp->br_mode = BRIDGE_MODE_VEB;
+	else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA)
+		bp->br_mode = BRIDGE_MODE_VEPA;
+	else
+		bp->br_mode = BRIDGE_MODE_UNDEF;
 
 func_qcfg_exit:
 	mutex_unlock(&bp->hwrm_cmd_lock);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -0
index 505691a..15d5a10 100644
@@ -1164,6 +1164,7 @@ struct bnxt {
 	u8			nge_port_cnt;
 	__le16			nge_fw_dst_port_id;
 	u8			port_partition_type;
+	u16			br_mode;
 
 	u16			rx_coal_ticks;
 	u16			rx_coal_ticks_irq;
Signature · 1 line
1.8.3.1
author maintainer
#3 lore raw

PATCH 3/10 bnxt_en: Implement ndo_bridge_{get|set}link methods.

In reply to Michael Chan

To allow users to set the hardware bridging mode to VEB or VEPA. Only single function PF can change the bridging mode.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 67 +++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +67 -0
index ec8a195..4acaeaf 100644
@@ -4919,6 +4919,26 @@ static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
 	}
 }
 
+static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
+{
+	struct hwrm_func_cfg_input req = {0};
+	int rc;
+
+	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
+	req.fid = cpu_to_le16(0xffff);
+	req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE);
+	if (br_mode == BRIDGE_MODE_VEB)
+		req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB;
+	else if (br_mode == BRIDGE_MODE_VEPA)
+		req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA;
+	else
+		return -EINVAL;
+	rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
+	if (rc)
+		rc = -EIO;
+	return rc;
+}
+
 static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
 {
 	struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
@@ -7432,6 +7452,51 @@ static void bnxt_udp_tunnel_del(struct net_device *dev,
 	schedule_work(&bp->sp_task);
 }
 
+static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
+			       struct net_device *dev, u32 filter_mask,
+			       int nlflags)
+{
+	struct bnxt *bp = netdev_priv(dev);
+
+	return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0,
+				       nlflags, filter_mask, NULL);
+}
+
+static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
+			       u16 flags)
+{
+	struct bnxt *bp = netdev_priv(dev);
+	struct nlattr *attr, *br_spec;
+	int rem, rc = 0;
+
+	if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp))
+		return -EOPNOTSUPP;
+
+	br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
+	if (!br_spec)
+		return -EINVAL;
+
+	nla_for_each_nested(attr, br_spec, rem) {
+		u16 mode;
+
+		if (nla_type(attr) != IFLA_BRIDGE_MODE)
+			continue;
+
+		if (nla_len(attr) < sizeof(mode))
+			return -EINVAL;
+
+		mode = nla_get_u16(attr);
+		if (mode == bp->br_mode)
+			break;
+
+		rc = bnxt_hwrm_set_br_mode(bp, mode);
+		if (!rc)
+			bp->br_mode = mode;
+		break;
+	}
+	return rc;
+}
+
 static const struct net_device_ops bnxt_netdev_ops = {
 	.ndo_open		= bnxt_open,
 	.ndo_start_xmit		= bnxt_start_xmit,
@@ -7463,6 +7528,8 @@ static void bnxt_udp_tunnel_del(struct net_device *dev,
 	.ndo_udp_tunnel_add	= bnxt_udp_tunnel_add,
 	.ndo_udp_tunnel_del	= bnxt_udp_tunnel_del,
 	.ndo_xdp		= bnxt_xdp,
+	.ndo_bridge_getlink	= bnxt_bridge_getlink,
+	.ndo_bridge_setlink	= bnxt_bridge_setlink,
 };
 
 static void bnxt_remove_one(struct pci_dev *pdev)
Signature · 1 line
1.8.3.1
author maintainer
#4 lore raw

PATCH 4/10 bnxt_en: Add bnxt_get_num_stats() to centrally get the number of ethtool stats.

In reply to Michael Chan

Instead of duplicating the logic multiple times. Also, it is unnecessary to zero the buffer in .get_ethtool_stats() because it is already zeroed by the caller.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 25 ++++++++++++-----------
 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +13 -12
index be6acad..4661b11 100644
@@ -198,19 +198,23 @@ static int bnxt_set_coalesce(struct net_device *dev,
 
 #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
 
+static int bnxt_get_num_stats(struct bnxt *bp)
+{
+	int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
+
+	if (bp->flags & BNXT_FLAG_PORT_STATS)
+		num_stats += BNXT_NUM_PORT_STATS;
+
+	return num_stats;
+}
+
 static int bnxt_get_sset_count(struct net_device *dev, int sset)
 {
 	struct bnxt *bp = netdev_priv(dev);
 
 	switch (sset) {
-	case ETH_SS_STATS: {
-		int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
-
-		if (bp->flags & BNXT_FLAG_PORT_STATS)
-			num_stats += BNXT_NUM_PORT_STATS;
-
-		return num_stats;
-	}
+	case ETH_SS_STATS:
+		return bnxt_get_num_stats(bp);
 	case ETH_SS_TEST:
 		if (!bp->num_tests)
 			return -EOPNOTSUPP;
@@ -225,11 +229,8 @@ static void bnxt_get_ethtool_stats(struct net_device *dev,
 {
 	u32 i, j = 0;
 	struct bnxt *bp = netdev_priv(dev);
-	u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings;
 	u32 stat_fields = sizeof(struct ctx_hw_stats) / 8;
 
-	memset(buf, 0, buf_size);
-
 	if (!bp->bnapi)
 		return;
 
@@ -835,7 +836,7 @@ static void bnxt_get_drvinfo(struct net_device *dev,
 		strlcpy(info->fw_version, bp->fw_ver_str,
 			sizeof(info->fw_version));
 	strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
-	info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
+	info->n_stats = bnxt_get_num_stats(bp);
 	info->testinfo_len = bp->num_tests;
 	/* TODO CHIMP_FW: eeprom dump details */
 	info->eedump_len = 0;
Signature · 1 line
1.8.3.1
author maintainer
#5 lore raw

PATCH 5/10 bnxt_en: Allow the user to set ethtool stats-block-usecs to 0.

In reply to Michael Chan

For debugging purpose, it is sometimes useful to disable periodic port statistics updates, so that the firmware logs will not be filled with statistics update messages.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c         | 3 ++-
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
index 4acaeaf..5df9670 100644
@@ -6843,7 +6843,8 @@ static void bnxt_timer(unsigned long data)
 	if (atomic_read(&bp->intr_sem) != 0)
 		goto bnxt_restart_timer;
 
-	if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS)) {
+	if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) &&
+	    bp->stats_coal_ticks) {
 		set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
 		schedule_work(&bp->sp_task);
 	}
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +5 -3
index 4661b11..140e769 100644
@@ -86,9 +86,11 @@ static int bnxt_set_coalesce(struct net_device *dev,
 	if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
 		u32 stats_ticks = coal->stats_block_coalesce_usecs;
 
-		stats_ticks = clamp_t(u32, stats_ticks,
-				      BNXT_MIN_STATS_COAL_TICKS,
-				      BNXT_MAX_STATS_COAL_TICKS);
+		/* Allow 0, which means disable. */
+		if (stats_ticks)
+			stats_ticks = clamp_t(u32, stats_ticks,
+					      BNXT_MIN_STATS_COAL_TICKS,
+					      BNXT_MAX_STATS_COAL_TICKS);
 		stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS);
 		bp->stats_coal_ticks = stats_ticks;
 		update_stats = true;
Signature · 1 line
1.8.3.1
author maintainer
#6 lore raw

PATCH 6/10 bnxt_en: Report firmware DCBX agent.

In reply to Michael Chan

Report DCB_CAP_DCBX_LLD_MANAGED only if the firmware DCBX agent is enabled and running for PF or VF. Otherwise, if both LLDP and DCBX agents are disabled in firmware, we report DCB_CAP_DCBX_LLD_HOST and allow host IEEE DCB settings. This patch refines the current logic in the driver.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 19 ++++++++++---------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  1 +
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c | 11 ++++++++---
 3 files changed, 19 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -9
index 5df9670..95fea26 100644
@@ -4578,6 +4578,7 @@ static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
 {
 	struct hwrm_func_qcfg_input req = {0};
 	struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
+	u16 flags;
 	int rc;
 
 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
@@ -4594,15 +4595,15 @@ static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
 		vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
 	}
 #endif
-	if (BNXT_PF(bp)) {
-		u16 flags = le16_to_cpu(resp->flags);
-
-		if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
-			     FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED))
-			bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
-		if (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)
-			bp->flags |= BNXT_FLAG_MULTI_HOST;
-	}
+	flags = le16_to_cpu(resp->flags);
+	if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
+		     FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) {
+		bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
+		if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED)
+			bp->flags |= BNXT_FLAG_FW_DCBX_AGENT;
+	}
+	if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
+		bp->flags |= BNXT_FLAG_MULTI_HOST;
 
 	switch (resp->port_partition_type) {
 	case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -0
index 15d5a10..6b781be 100644
@@ -1027,6 +1027,7 @@ struct bnxt {
 	#define BNXT_FLAG_MULTI_HOST	0x100000
 	#define BNXT_FLAG_SHORT_CMD	0x200000
 	#define BNXT_FLAG_DOUBLE_DB	0x400000
+	#define BNXT_FLAG_FW_DCBX_AGENT	0x800000
 	#define BNXT_FLAG_CHIP_NITRO_A0	0x1000000
 
 	#define BNXT_FLAG_ALL_CONFIG_FEATS (BNXT_FLAG_TPA |		\
drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c +8 -3
index 5c6dd0c..c014589 100644
@@ -549,13 +549,18 @@ static u8 bnxt_dcbnl_setdcbx(struct net_device *dev, u8 mode)
 {
 	struct bnxt *bp = netdev_priv(dev);
 
-	/* only support IEEE */
-	if ((mode & DCB_CAP_DCBX_VER_CEE) || !(mode & DCB_CAP_DCBX_VER_IEEE))
+	/* All firmware DCBX settings are set in NVRAM */
+	if (bp->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED)
 		return 1;
 
 	if (mode & DCB_CAP_DCBX_HOST) {
 		if (BNXT_VF(bp) || (bp->flags & BNXT_FLAG_FW_LLDP_AGENT))
 			return 1;
+
+		/* only support IEEE */
+		if ((mode & DCB_CAP_DCBX_VER_CEE) ||
+		    !(mode & DCB_CAP_DCBX_VER_IEEE))
+			return 1;
 	}
 
 	if (mode == bp->dcbx_cap)
@@ -584,7 +589,7 @@ void bnxt_dcb_init(struct bnxt *bp)
 	bp->dcbx_cap = DCB_CAP_DCBX_VER_IEEE;
 	if (BNXT_PF(bp) && !(bp->flags & BNXT_FLAG_FW_LLDP_AGENT))
 		bp->dcbx_cap |= DCB_CAP_DCBX_HOST;
-	else
+	else if (bp->flags & BNXT_FLAG_FW_DCBX_AGENT)
 		bp->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED;
 	bp->dev->dcbnl_ops = &dcbnl_ops;
 }
Signature · 1 line
1.8.3.1
author maintainer
#7 lore raw

PATCH 7/10 bnxt_en: Set ETS min_bw parameter for older firmware.

In reply to Michael Chan

In addition to the ETS weight, older firmware also requires the min_bw parameter to be set for it to work properly.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c | 6 ++++++
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.h | 1 +
 2 files changed, 7 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c +6 -0
index c014589..aa1f3a2 100644
@@ -93,6 +93,12 @@ static int bnxt_hwrm_queue_cos2bw_cfg(struct bnxt *bp, struct ieee_ets *ets,
 			cos2bw.tsa =
 				QUEUE_COS2BW_QCFG_RESP_QUEUE_ID0_TSA_ASSIGN_ETS;
 			cos2bw.bw_weight = ets->tc_tx_bw[i];
+			/* older firmware requires min_bw to be set to the
+			 * same weight value in percent.
+			 */
+			cos2bw.min_bw =
+				cpu_to_le32((ets->tc_tx_bw[i] * 100) |
+					    BW_VALUE_UNIT_PERCENT1_100);
 		}
 		memcpy(data, &cos2bw.queue_id, sizeof(cos2bw) - 4);
 		if (i == 0) {
drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.h +1 -0
index ecd0a5e..d2e0af9 100644
@@ -26,6 +26,7 @@ struct bnxt_cos2bw_cfg {
 	u8			queue_id;
 	__le32			min_bw;
 	__le32			max_bw;
+#define BW_VALUE_UNIT_PERCENT1_100		(0x1UL << 29)
 	u8			tsa;
 	u8			pri_lvl;
 	u8			bw_weight;
Signature · 1 line
1.8.3.1
author maintainer
#8 lore raw

PATCH 8/10 bnxt_en: add support to enable VF-representors

In reply to Michael Chan

From: Sathya Perla <[email protected]>

This patch is a part of a patch-set that introduces support for VF-reps in the bnxt_en driver. The driver registers eswitch mode get/set methods with the devlink interface that allow a user to enable SRIOV switchdev mode. When enabled, the driver registers a VF-rep netdev object for each VF with the stack. This can essentially bring the VFs unders the management perview of the hypervisor and applications such as OVS.

The next patch in the series, adds the RX/TX routines and a slim netdev implementation for the VF-reps.

---
 drivers/net/ethernet/broadcom/Kconfig           |   1 +
 drivers/net/ethernet/broadcom/bnxt/Makefile     |   2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c       |   9 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.h       |  32 ++++
 drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c |   6 +
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c   | 244 ++++++++++++++++++++++++
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h   |  38 ++++
 7 files changed, 330 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c
 create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h
drivers/net/ethernet/broadcom/Kconfig +1 -0
index 9641380..285f8bc 100644
@@ -193,6 +193,7 @@ config SYSTEMPORT
 config BNXT
 	tristate "Broadcom NetXtreme-C/E support"
 	depends on PCI
+	depends on MAY_USE_DEVLINK
 	select FW_LOADER
 	select LIBCRC32C
 	---help---
drivers/net/ethernet/broadcom/bnxt/Makefile +1 -1
index a7ca45b..d141a22 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_BNXT) += bnxt_en.o
 
-bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o
+bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o bnxt_vfr.o
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -1
index 95fea26..ebdeeb4 100644
@@ -57,6 +57,7 @@
 #include "bnxt_ethtool.h"
 #include "bnxt_dcb.h"
 #include "bnxt_xdp.h"
+#include "bnxt_vfr.h"
 
 #define BNXT_TX_TIMEOUT		(5 * HZ)
 
@@ -7539,8 +7540,10 @@ static void bnxt_remove_one(struct pci_dev *pdev)
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct bnxt *bp = netdev_priv(dev);
 
-	if (BNXT_PF(bp))
+	if (BNXT_PF(bp)) {
 		bnxt_sriov_disable(bp);
+		bnxt_dl_unregister(bp);
+	}
 
 	pci_disable_pcie_error_reporting(pdev);
 	unregister_netdev(dev);
@@ -7843,6 +7846,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 #ifdef CONFIG_BNXT_SRIOV
 	init_waitqueue_head(&bp->sriov_cfg_wait);
+	mutex_init(&bp->sriov_lock);
 #endif
 	bp->gro_func = bnxt_gro_func_5730x;
 	if (BNXT_CHIP_P4_PLUS(bp))
@@ -7934,6 +7938,9 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		goto init_err_clr_int;
 
+	if (BNXT_PF(bp))
+		bnxt_dl_register(bp);
+
 	netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
 		    board_info[ent->driver_data].name,
 		    (long)pci_resource_start(pdev, 0), dev->dev_addr);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +32 -0
index 6b781be..a7d5f42 100644
@@ -19,6 +19,7 @@
 #define DRV_VER_UPD	0
 
 #include <linux/interrupt.h>
+#include <net/devlink.h>
 
 struct tx_bd {
 	__le32 tx_bd_len_flags_type;
@@ -618,6 +619,8 @@ struct bnxt_tpa_info {
 
 #define BNXT_TPA_OUTER_L3_OFF(hdr_info)	\
 	((hdr_info) & 0x1ff)
+
+	u16			cfa_code; /* cfa_code in TPA start compl */
 };
 
 struct bnxt_rx_ring_info {
@@ -928,6 +931,23 @@ struct bnxt_test_info {
 #define BNXT_CAG_REG_LEGACY_INT_STATUS	0x4014
 #define BNXT_CAG_REG_BASE		0x300000
 
+struct bnxt_vf_rep_stats {
+	u64			packets;
+	u64			bytes;
+	u64			dropped;
+};
+
+struct bnxt_vf_rep {
+	struct bnxt			*bp;
+	struct net_device		*dev;
+	u16				vf_idx;
+	u16				tx_cfa_action;
+	u16				rx_cfa_code;
+
+	struct bnxt_vf_rep_stats	rx_stats;
+	struct bnxt_vf_rep_stats	tx_stats;
+};
+
 struct bnxt {
 	void __iomem		*bar0;
 	void __iomem		*bar1;
@@ -1208,6 +1228,12 @@ struct bnxt {
 	wait_queue_head_t	sriov_cfg_wait;
 	bool			sriov_cfg;
 #define BNXT_SRIOV_CFG_WAIT_TMO	msecs_to_jiffies(10000)
+
+	/* lock to protect VF-rep creation/cleanup via
+	 * multiple paths such as ->sriov_configure() and
+	 * devlink ->eswitch_mode_set()
+	 */
+	struct mutex		sriov_lock;
 #endif
 
 #define BNXT_NTP_FLTR_MAX_FLTR	4096
@@ -1234,6 +1260,12 @@ struct bnxt {
 	struct bnxt_led_info	leds[BNXT_MAX_LED];
 
 	struct bpf_prog		*xdp_prog;
+
+	/* devlink interface and vf-rep structs */
+	struct devlink		*dl;
+	enum devlink_eswitch_mode eswitch_mode;
+	struct bnxt_vf_rep	**vf_reps; /* array of vf-rep ptrs */
+	u16			*cfa_code_map; /* cfa_code -> vf_idx map */
 };
 
 #define BNXT_RX_STATS_OFFSET(counter)			\
drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c +6 -0
index fde7256..d37925a 100644
@@ -18,6 +18,7 @@
 #include "bnxt.h"
 #include "bnxt_ulp.h"
 #include "bnxt_sriov.h"
+#include "bnxt_vfr.h"
 #include "bnxt_ethtool.h"
 
 #ifdef CONFIG_BNXT_SRIOV
@@ -587,6 +588,10 @@ void bnxt_sriov_disable(struct bnxt *bp)
 	if (!num_vfs)
 		return;
 
+	/* synchronize VF and VF-rep create and destroy */
+	mutex_lock(&bp->sriov_lock);
+	bnxt_vf_reps_destroy(bp);
+
 	if (pci_vfs_assigned(bp->pdev)) {
 		bnxt_hwrm_fwd_async_event_cmpl(
 			bp, NULL, ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD);
@@ -597,6 +602,7 @@ void bnxt_sriov_disable(struct bnxt *bp)
 		/* Free the HW resources reserved for various VF's */
 		bnxt_hwrm_func_vf_resource_free(bp, num_vfs);
 	}
+	mutex_unlock(&bp->sriov_lock);
 
 	bnxt_free_vf_resources(bp);
 
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c new file +244 -0

244 lines not on this page · raw message

drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h new file +38 -0
new file mode 100644
index 0000000..310c9c5
@@ -0,0 +1,38 @@
+/* Broadcom NetXtreme-C/E network driver.
+ *
+ * Copyright (c) 2016-2017 Broadcom Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef BNXT_VFR_H
+#define BNXT_VFR_H
+
+#define	MAX_CFA_CODE			65536
+
+/* Struct to hold housekeeping info needed by devlink interface */
+struct bnxt_dl {
+	struct bnxt *bp;	/* back ptr to the controlling dev */
+};
+
+static inline struct bnxt *bnxt_get_bp_from_dl(struct devlink *dl)
+{
+	return ((struct bnxt_dl *)devlink_priv(dl))->bp;
+}
+
+static inline void bnxt_link_bp_to_dl(struct devlink *dl, struct bnxt *bp)
+{
+	struct bnxt_dl *bp_dl = devlink_priv(dl);
+
+	bp_dl->bp = bp;
+	if (bp)
+		bp->dl = dl;
+}
+
+int bnxt_dl_register(struct bnxt *bp);
+void bnxt_dl_unregister(struct bnxt *bp);
+void bnxt_vf_reps_destroy(struct bnxt *bp);
+
+#endif /* BNXT_VFR_H */
Signature · 1 line
1.8.3.1
author maintainer
#10 lore raw

PATCH 9/10 bnxt_en: add vf-rep RX/TX and netdev implementation

In reply to Michael Chan

From: Sathya Perla <[email protected]>

This patch introduces the RX/TX and a simple netdev implementation for VF-reps. The VF-reps use the RX/TX rings of the PF. For each VF-rep the PF driver issues a VFR_ALLOC FW cmd that returns "cfa_code" and "cfa_action" values. The FW sets up the filter tables in such a way that VF traffic by default (in absence of other rules) gets punted to the parent PF. The cfa_code value in the RX-compl informs the driver of the source VF. For traffic being transmitted from the VF-rep, the TX BD is tagged with a cfa_action value that informs the HW to punt it to the corresponding VF.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     |  68 ++++++--
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  10 ++
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c | 218 +++++++++++++++++++++++++-
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h |   4 +
 4 files changed, 288 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +57 -11
index ebdeeb4..f262fe6 100644
@@ -245,6 +245,16 @@ static bool bnxt_vf_pciid(enum board_idx idx)
 	TX_BD_FLAGS_LHINT_2048_AND_LARGER,
 };
 
+static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb)
+{
+	struct metadata_dst *md_dst = skb_metadata_dst(skb);
+
+	if (!md_dst || md_dst->type != METADATA_HW_PORT_MUX)
+		return 0;
+
+	return md_dst->u.port_info.port_id;
+}
+
 static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct bnxt *bp = netdev_priv(dev);
@@ -289,7 +299,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	tx_buf->nr_frags = last_frag;
 
 	vlan_tag_flags = 0;
-	cfa_action = 0;
+	cfa_action = bnxt_xmit_get_cfa_action(skb);
 	if (skb_vlan_tag_present(skb)) {
 		vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
 				 skb_vlan_tag_get(skb);
@@ -324,7 +334,8 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
 			tx_push1->tx_bd_hsize_lflags = 0;
 
 		tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
-		tx_push1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
+		tx_push1->tx_bd_cfa_action =
+			cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
 
 		end = pdata + length;
 		end = PTR_ALIGN(end, 8) - 1;
@@ -429,7 +440,8 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
 
 	txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
-	txbd1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
+	txbd1->tx_bd_cfa_action =
+			cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
 	for (i = 0; i < last_frag; i++) {
 		skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
 
@@ -1034,7 +1046,10 @@ static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
 		bnxt_sched_reset(bp, rxr);
 		return;
 	}
-
+	/* Store cfa_code in tpa_info to use in tpa_end
+	 * completion processing.
+	 */
+	tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1);
 	prod_rx_buf->data = tpa_info->data;
 	prod_rx_buf->data_ptr = tpa_info->data_ptr;
 
@@ -1269,6 +1284,17 @@ static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
 	return skb;
 }
 
+/* Given the cfa_code of a received packet determine which
+ * netdev (vf-rep or PF) the packet is destined to.
+ */
+static struct net_device *bnxt_get_pkt_dev(struct bnxt *bp, u16 cfa_code)
+{
+	struct net_device *dev = bnxt_get_vf_rep(bp, cfa_code);
+
+	/* if vf-rep dev is NULL, the must belongs to the PF */
+	return dev ? dev : bp->dev;
+}
+
 static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
 					   struct bnxt_napi *bnapi,
 					   u32 *raw_cons,
@@ -1362,7 +1388,9 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
 			return NULL;
 		}
 	}
-	skb->protocol = eth_type_trans(skb, bp->dev);
+
+	skb->protocol =
+		eth_type_trans(skb, bnxt_get_pkt_dev(bp, tpa_info->cfa_code));
 
 	if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
 		skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
@@ -1389,6 +1417,18 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
 	return skb;
 }
 
+static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi,
+			     struct sk_buff *skb)
+{
+	if (skb->dev != bp->dev) {
+		/* this packet belongs to a vf-rep */
+		bnxt_vf_rep_rx(bp, skb);
+		return;
+	}
+	skb_record_rx_queue(skb, bnapi->index);
+	napi_gro_receive(&bnapi->napi, skb);
+}
+
 /* returns the following:
  * 1       - 1 packet successfully received
  * 0       - successful TPA_START, packet not completed yet
@@ -1405,7 +1445,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
 	struct rx_cmp *rxcmp;
 	struct rx_cmp_ext *rxcmp1;
 	u32 tmp_raw_cons = *raw_cons;
-	u16 cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
+	u16 cfa_code, cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
 	struct bnxt_sw_rx_bd *rx_buf;
 	unsigned int len;
 	u8 *data_ptr, agg_bufs, cmp_type;
@@ -1447,8 +1487,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
 
 		rc = -ENOMEM;
 		if (likely(skb)) {
-			skb_record_rx_queue(skb, bnapi->index);
-			napi_gro_receive(&bnapi->napi, skb);
+			bnxt_deliver_skb(bp, bnapi, skb);
 			rc = 1;
 		}
 		*event |= BNXT_RX_EVENT;
@@ -1537,7 +1576,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
 		skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
 	}
 
-	skb->protocol = eth_type_trans(skb, dev);
+	cfa_code = RX_CMP_CFA_CODE(rxcmp1);
+	skb->protocol = eth_type_trans(skb, bnxt_get_pkt_dev(bp, cfa_code));
 
 	if ((rxcmp1->rx_cmp_flags2 &
 	     cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
@@ -1562,8 +1602,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
 		}
 	}
 
-	skb_record_rx_queue(skb, bnapi->index);
-	napi_gro_receive(&bnapi->napi, skb);
+	bnxt_deliver_skb(bp, bnapi, skb);
 	rc = 1;
 
 next_rx:
@@ -6246,6 +6285,9 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
 	/* Poll link status and check for SFP+ module status */
 	bnxt_get_port_module_status(bp);
 
+	/* VF-reps may need to be re-opened after the PF is re-opened */
+	if (BNXT_PF(bp))
+		bnxt_vf_reps_open(bp);
 	return 0;
 
 open_err:
@@ -6334,6 +6376,10 @@ int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
 		if (rc)
 			netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
 	}
+
+	/* Close the VF-reps before closing PF */
+	if (BNXT_PF(bp))
+		bnxt_vf_reps_close(bp);
 #endif
 	/* Change device state to avoid TX queue wake up's */
 	bnxt_tx_disable(bp);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +10 -0
index a7d5f42..63756f0 100644
@@ -20,6 +20,7 @@
 
 #include <linux/interrupt.h>
 #include <net/devlink.h>
+#include <net/dst_metadata.h>
 
 struct tx_bd {
 	__le32 tx_bd_len_flags_type;
@@ -243,6 +244,10 @@ struct rx_cmp_ext {
 	    ((le32_to_cpu((rxcmp1)->rx_cmp_flags2) &			\
 	     RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3)
 
+#define RX_CMP_CFA_CODE(rxcmpl1)					\
+	((le32_to_cpu((rxcmpl1)->rx_cmp_cfa_code_errors_v2) &		\
+	  RX_CMPL_CFA_CODE_MASK) >> RX_CMPL_CFA_CODE_SFT)
+
 struct rx_agg_cmp {
 	__le32 rx_agg_cmp_len_flags_type;
 	#define RX_AGG_CMP_TYPE					(0x3f << 0)
@@ -312,6 +317,10 @@ struct rx_tpa_start_cmp_ext {
 	__le32 rx_tpa_start_cmp_hdr_info;
 };
 
+#define TPA_START_CFA_CODE(rx_tpa_start)				\
+	((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_cfa_code_v2) &	\
+	 RX_TPA_START_CMP_CFA_CODE) >> RX_TPA_START_CMPL_CFA_CODE_SHIFT)
+
 struct rx_tpa_end_cmp {
 	__le32 rx_tpa_end_cmp_len_flags_type;
 	#define RX_TPA_END_CMP_TYPE				(0x3f << 0)
@@ -940,6 +949,7 @@ struct bnxt_vf_rep_stats {
 struct bnxt_vf_rep {
 	struct bnxt			*bp;
 	struct net_device		*dev;
+	struct metadata_dst		*dst;
 	u16				vf_idx;
 	u16				tx_cfa_action;
 	u16				rx_cfa_code;
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c +217 -1

271 lines not on this page · raw message

drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h +4 -0
index 310c9c5..c6cd55a 100644
@@ -34,5 +34,9 @@ static inline void bnxt_link_bp_to_dl(struct devlink *dl, struct bnxt *bp)
 int bnxt_dl_register(struct bnxt *bp);
 void bnxt_dl_unregister(struct bnxt *bp);
 void bnxt_vf_reps_destroy(struct bnxt *bp);
+void bnxt_vf_reps_close(struct bnxt *bp);
+void bnxt_vf_reps_open(struct bnxt *bp);
+void bnxt_vf_rep_rx(struct bnxt *bp, struct sk_buff *skb);
+struct net_device *bnxt_get_vf_rep(struct bnxt *bp, u16 cfa_code);
 
 #endif /* BNXT_VFR_H */
Signature · 1 line
1.8.3.1
author maintainer
#11 lore raw

PATCH 10/10 bnxt_en: add support for port_attr_get and and get_phys_port_name

In reply to Michael Chan

From: Sathya Perla <[email protected]>

This patch adds support for the switchdev_port_attr_get() and ndo_get_phys_port_name() methods for the PF and the VF-reps. Using this support a user application can deduce that the PF (when in the ESWITCH_SWDEV mode) and it's VF-reps form a switch.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 57 +++++++++++++++++++++++++++
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  2 +
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c | 31 ++++++++++++++-
 3 files changed, 89 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +57 -0
index f262fe6..82cbe18 100644
@@ -7546,6 +7546,61 @@ static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
 	return rc;
 }
 
+static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
+				   size_t len)
+{
+	struct bnxt *bp = netdev_priv(dev);
+	int rc;
+
+	/* The PF and it's VF-reps only support the switchdev framework */
+	if (!BNXT_PF(bp))
+		return -EOPNOTSUPP;
+
+	/* The switch-id that the pf belongs to is exported by
+	 * the switchdev ndo. This name is just to distinguish from the
+	 * vf-rep ports.
+	 */
+	rc = snprintf(buf, len, "pf%d", bp->pf.port_id);
+
+	if (rc >= len)
+		return -EOPNOTSUPP;
+	return 0;
+}
+
+int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr)
+{
+	if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
+		return -EOPNOTSUPP;
+
+	/* The PF and it's VF-reps only support the switchdev framework */
+	if (!BNXT_PF(bp))
+		return -EOPNOTSUPP;
+
+	switch (attr->id) {
+	case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
+		/* In SRIOV each PF-pool (PF + child VFs) serves as a
+		 * switching domain, the PF's perm mac-addr can be used
+		 * as the unique parent-id
+		 */
+		attr->u.ppid.id_len = ETH_ALEN;
+		ether_addr_copy(attr->u.ppid.id, bp->pf.mac_addr);
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+	return 0;
+}
+
+static int bnxt_swdev_port_attr_get(struct net_device *dev,
+				    struct switchdev_attr *attr)
+{
+	return bnxt_port_attr_get(netdev_priv(dev), attr);
+}
+
+static const struct switchdev_ops bnxt_switchdev_ops = {
+	.switchdev_port_attr_get	= bnxt_swdev_port_attr_get
+};
+
 static const struct net_device_ops bnxt_netdev_ops = {
 	.ndo_open		= bnxt_open,
 	.ndo_start_xmit		= bnxt_start_xmit,
@@ -7579,6 +7634,7 @@ static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
 	.ndo_xdp		= bnxt_xdp,
 	.ndo_bridge_getlink	= bnxt_bridge_getlink,
 	.ndo_bridge_setlink	= bnxt_bridge_setlink,
+	.ndo_get_phys_port_name = bnxt_get_phys_port_name
 };
 
 static void bnxt_remove_one(struct pci_dev *pdev)
@@ -7838,6 +7894,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	dev->netdev_ops = &bnxt_netdev_ops;
 	dev->watchdog_timeo = BNXT_TX_TIMEOUT;
 	dev->ethtool_ops = &bnxt_ethtool_ops;
+	dev->switchdev_ops = &bnxt_switchdev_ops;
 	pci_set_drvdata(pdev, dev);
 
 	rc = bnxt_alloc_hwrm_resources(bp);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +2 -0
index 63756f0..2d84d57 100644
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <net/devlink.h>
 #include <net/dst_metadata.h>
+#include <net/switchdev.h>
 
 struct tx_bd {
 	__le32 tx_bd_len_flags_type;
@@ -1350,4 +1351,5 @@ int bnxt_reserve_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
 int bnxt_setup_mq_tc(struct net_device *dev, u8 tc);
 int bnxt_get_max_rings(struct bnxt *, int *, int *, bool);
 void bnxt_restore_pf_fw_resources(struct bnxt *bp);
+int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr);
 #endif
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c +30 -1
index 60bdb181..83478e9 100644
@@ -135,6 +135,18 @@ void bnxt_vf_rep_rx(struct bnxt *bp, struct sk_buff *skb)
 	netif_receive_skb(skb);
 }
 
+static int bnxt_vf_rep_get_phys_port_name(struct net_device *dev, char *buf,
+					  size_t len)
+{
+	struct bnxt_vf_rep *vf_rep = netdev_priv(dev);
+	int rc;
+
+	rc = snprintf(buf, len, "vfr%d", vf_rep->vf_idx);
+	if (rc >= len)
+		return -EOPNOTSUPP;
+	return 0;
+}
+
 static void bnxt_vf_rep_get_drvinfo(struct net_device *dev,
 				    struct ethtool_drvinfo *info)
 {
@@ -142,6 +154,21 @@ static void bnxt_vf_rep_get_drvinfo(struct net_device *dev,
 	strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
 }
 
+static int bnxt_vf_rep_port_attr_get(struct net_device *dev,
+				     struct switchdev_attr *attr)
+{
+	struct bnxt_vf_rep *vf_rep = netdev_priv(dev);
+
+	/* as only PORT_PARENT_ID is supported currently use common code
+	 * between PF and VF-rep for now.
+	 */
+	return bnxt_port_attr_get(vf_rep->bp, attr);
+}
+
+static const struct switchdev_ops bnxt_vf_rep_switchdev_ops = {
+	.switchdev_port_attr_get	= bnxt_vf_rep_port_attr_get
+};
+
 static const struct ethtool_ops bnxt_vf_rep_ethtool_ops = {
 	.get_drvinfo		= bnxt_vf_rep_get_drvinfo
 };
@@ -150,7 +177,8 @@ static void bnxt_vf_rep_get_drvinfo(struct net_device *dev,
 	.ndo_open		= bnxt_vf_rep_open,
 	.ndo_stop		= bnxt_vf_rep_close,
 	.ndo_start_xmit		= bnxt_vf_rep_xmit,
-	.ndo_get_stats64	= bnxt_vf_rep_get_stats64
+	.ndo_get_stats64	= bnxt_vf_rep_get_stats64,
+	.ndo_get_phys_port_name = bnxt_vf_rep_get_phys_port_name
 };
 
 /* Called when the parent PF interface is closed:
@@ -274,6 +302,7 @@ static void bnxt_vf_rep_netdev_init(struct bnxt *bp, struct bnxt_vf_rep *vf_rep,
 
 	dev->netdev_ops = &bnxt_vf_rep_netdev_ops;
 	dev->ethtool_ops = &bnxt_vf_rep_ethtool_ops;
+	dev->switchdev_ops = &bnxt_vf_rep_switchdev_ops;
 	/* Just inherit all the featues of the parent PF as the VF-R
 	 * uses the RX/TX rings of the parent PF
 	 */
Signature · 1 line
1.8.3.1
maintainer
#37 lore raw
In reply to Michael Chan

From: Michael Chan <[email protected]>
Date: Mon, 24 Jul 2017 12:34:19 -0400

Quoted 4 lines

This series includes updating the firmware interface, adding methods to get and set VEPA/VEB bridge modes, some minor DCBX and ETS refinements, and 3 patches from Sathya Perla to implement initial VF representors for SRIOV switching.

Series applied, thank you.

#9 lore raw

Re: [PATCH net-next 08/10] bnxt_en: add support to enable VF-representors

In reply to Michael Chan
url: https://github.com/0day-ci/linux/commits/Michael-Chan/bnxt_en-Update-firmware-interface-spec-to-1-8-0/20170725-094835 config: x86_64-randconfig-x016-201730 (attached as .config) compiler: gcc-6…

Hi Sathya,

[auto build test ERROR on net-next/master]

url: https://github.com/0day-ci/linux/commits/Michael-Chan/bnxt_en-Update-firmware-interface-spec-to-1-8-0/20170725-094835
config: x86_64-randconfig-x016-201730 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

In file included from include/linux/kernfs.h:13:0,
from include/linux/sysfs.h:15,
from include/linux/kobject.h:21,
from include/linux/pci.h:28,
from drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c:9:
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c: In function 'bnxt_dl_eswitch_mode_set':

>> drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c:165:16: error: 'struct bnxt' has no member named 'sriov_lock'
     mutex_lock(&bp->sriov_lock);
                   ^
   include/linux/mutex.h:164:44: note: in definition of macro 'mutex_lock'
    #define mutex_lock(lock) mutex_lock_nested(lock, 0)
                                               ^~~~
   drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c:194:18: error: 'struct bnxt' has no member named 'sriov_lock'
     mutex_unlock(&bp->sriov_lock);
                     ^~

vim +165 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c

   > 9	#include <linux/pci.h>
    10	#include <linux/netdevice.h>
    11	#include <linux/etherdevice.h>
    12	#include <linux/rtnetlink.h>
    13	#include <linux/jhash.h>
    14	
    15	#include "bnxt_hsi.h"
    16	#include "bnxt.h"
    17	#include "bnxt_vfr.h"
    18	
    19	#define CFA_HANDLE_INVALID		0xffff
    20	
    21	static void __bnxt_vf_reps_destroy(struct bnxt *bp)
    22	{
    23		u16 num_vfs = pci_num_vf(bp->pdev);
    24		struct bnxt_vf_rep *vf_rep;
    25		int i;
    26	
    27		for (i = 0; i < num_vfs; i++) {
    28			vf_rep = bp->vf_reps[i];
    29			if (vf_rep) {
    30				if (vf_rep->dev) {
    31					/* if register_netdev failed, then netdev_ops
    32					 * would have been set to NULL
    33					 */
    34					if (vf_rep->dev->netdev_ops)
    35						unregister_netdev(vf_rep->dev);
    36					free_netdev(vf_rep->dev);
    37				}
    38			}
    39		}
    40	
    41		kfree(bp->vf_reps);
    42		bp->vf_reps = NULL;
    43	}
    44	
    45	void bnxt_vf_reps_destroy(struct bnxt *bp)
    46	{
    47		bool closed = false;
    48	
    49		if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
    50			return;
    51	
    52		if (!bp->vf_reps)
    53			return;
    54	
    55		/* Ensure that parent PF's and VF-reps' RX/TX has been quiesced
    56		 * before proceeding with VF-rep cleanup.
    57		 */
    58		rtnl_lock();
    59		if (netif_running(bp->dev)) {
    60			bnxt_close_nic(bp, false, false);
    61			closed = true;
    62		}
    63		bp->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY;
    64	
    65		if (closed)
    66			bnxt_open_nic(bp, false, false);
    67		rtnl_unlock();
    68	
    69		/* Need to call vf_reps_destroy() outside of rntl_lock
    70		 * as unregister_netdev takes rtnl_lock
    71		 */
    72		__bnxt_vf_reps_destroy(bp);
    73	}
    74	
    75	/* Use the OUI of the PF's perm addr and report the same mac addr
    76	 * for the same VF-rep each time
    77	 */
    78	static void bnxt_vf_rep_eth_addr_gen(u8 *src_mac, u16 vf_idx, u8 *mac)
    79	{
    80		u32 addr;
    81	
    82		ether_addr_copy(mac, src_mac);
    83	
    84		addr = jhash(src_mac, ETH_ALEN, 0) + vf_idx;
    85		mac[3] = (u8)(addr & 0xFF);
    86		mac[4] = (u8)((addr >> 8) & 0xFF);
    87		mac[5] = (u8)((addr >> 16) & 0xFF);
    88	}
    89	
    90	static void bnxt_vf_rep_netdev_init(struct bnxt *bp, struct bnxt_vf_rep *vf_rep,
    91					    struct net_device *dev)
    92	{
    93		struct net_device *pf_dev = bp->dev;
    94	
    95		/* Just inherit all the featues of the parent PF as the VF-R
    96		 * uses the RX/TX rings of the parent PF
    97		 */
    98		dev->hw_features = pf_dev->hw_features;
    99		dev->gso_partial_features = pf_dev->gso_partial_features;
   100		dev->vlan_features = pf_dev->vlan_features;
   101		dev->hw_enc_features = pf_dev->hw_enc_features;
   102		dev->features |= pf_dev->features;
   103		bnxt_vf_rep_eth_addr_gen(bp->pf.mac_addr, vf_rep->vf_idx,
   104					 dev->perm_addr);
   105		ether_addr_copy(dev->dev_addr, dev->perm_addr);
   106	}
   107	
   108	static int bnxt_vf_reps_create(struct bnxt *bp)
   109	{
   110		u16 num_vfs = pci_num_vf(bp->pdev);
   111		struct bnxt_vf_rep *vf_rep;
   112		struct net_device *dev;
   113		int rc, i;
   114	
   115		bp->vf_reps = kcalloc(num_vfs, sizeof(vf_rep), GFP_KERNEL);
   116		if (!bp->vf_reps)
   117			return -ENOMEM;
   118	
   119		for (i = 0; i < num_vfs; i++) {
   120			dev = alloc_etherdev(sizeof(*vf_rep));
   121			if (!dev) {
   122				rc = -ENOMEM;
   123				goto err;
   124			}
   125	
   126			vf_rep = netdev_priv(dev);
   127			bp->vf_reps[i] = vf_rep;
   128			vf_rep->dev = dev;
   129			vf_rep->bp = bp;
   130			vf_rep->vf_idx = i;
   131			vf_rep->tx_cfa_action = CFA_HANDLE_INVALID;
   132	
   133			bnxt_vf_rep_netdev_init(bp, vf_rep, dev);
   134			rc = register_netdev(dev);
   135			if (rc) {
   136				/* no need for unregister_netdev in cleanup */
   137				dev->netdev_ops = NULL;
   138				goto err;
   139			}
   140		}
   141	
   142		bp->eswitch_mode = DEVLINK_ESWITCH_MODE_SWITCHDEV;
   143		return 0;
   144	
   145	err:
   146		netdev_info(bp->dev, "%s error=%d", __func__, rc);
   147		__bnxt_vf_reps_destroy(bp);
   148		return rc;
   149	}
   150	
   151	/* Devlink related routines */
   152	static int bnxt_dl_eswitch_mode_get(struct devlink *devlink, u16 *mode)
   153	{
   154		struct bnxt *bp = bnxt_get_bp_from_dl(devlink);
   155	
   156		*mode = bp->eswitch_mode;
   157		return 0;
   158	}
   159	
   160	static int bnxt_dl_eswitch_mode_set(struct devlink *devlink, u16 mode)
   161	{
   162		struct bnxt *bp = bnxt_get_bp_from_dl(devlink);
   163		int rc = 0;
   164	
 > 165		mutex_lock(&bp->sriov_lock);

166 if (bp->eswitch_mode == mode) {
167 netdev_info(bp->dev, "already in %s eswitch mode",
168 mode == DEVLINK_ESWITCH_MODE_LEGACY ?
169 "legacy" : "switchdev");
170 rc = -EINVAL;
171 goto done;
172 }
173
174 switch (mode) {
175 case DEVLINK_ESWITCH_MODE_LEGACY:
176 bnxt_vf_reps_destroy(bp);
177 break;
178
179 case DEVLINK_ESWITCH_MODE_SWITCHDEV:
180 if (pci_num_vf(bp->pdev) == 0) {
181 netdev_info(bp->dev,
182 "Enable VFs before setting swtichdev mode");
183 rc = -EPERM;
184 goto done;
185 }
186 rc = bnxt_vf_reps_create(bp);
187 break;
188
189 default:
190 rc = -EINVAL;
191 goto done;
192 }
193 done:
194 mutex_unlock(&bp->sriov_lock);
195 return rc;
196 }
197

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#12 lore raw

Re: [PATCH net-next 10/10] bnxt_en: add support for port_attr_get and and get_phys_port_name

In reply to Michael Chan
url: https://github.com/0day-ci/linux/commits/Michael-Chan/bnxt_en-Update-firmware-interface-spec-to-1-8-0/20170725-094835 config: x86_64-randconfig-x016-201730 (attached as .config) compiler: gcc-6…

Hi Sathya,

[auto build test ERROR on net-next/master]

url: https://github.com/0day-ci/linux/commits/Michael-Chan/bnxt_en-Update-firmware-interface-spec-to-1-8-0/20170725-094835
config: x86_64-randconfig-x016-201730 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

drivers/net/ethernet/broadcom/bnxt/bnxt.c: In function 'bnxt_init_one':

>> drivers/net/ethernet/broadcom/bnxt/bnxt.c:7897:5: error: 'struct net_device' has no member named 'switchdev_ops'; did you mean 'netdev_ops'?
     dev->switchdev_ops = &bnxt_switchdev_ops;
        ^~
--
   drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c: In function 'bnxt_vf_rep_netdev_init':
>> drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c:305:5: error: 'struct net_device' has no member named 'switchdev_ops'; did you mean 'netdev_ops'?
     dev->switchdev_ops = &bnxt_vf_rep_switchdev_ops;
        ^~
   In file included from include/linux/kernfs.h:13:0,
                    from include/linux/sysfs.h:15,
                    from include/linux/kobject.h:21,
                    from include/linux/pci.h:28,
                    from drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c:9:
   drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c: In function 'bnxt_dl_eswitch_mode_set':
   drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c:410:16: error: 'struct bnxt' has no member named 'sriov_lock'
     mutex_lock(&bp->sriov_lock);
                   ^
   include/linux/mutex.h:164:44: note: in definition of macro 'mutex_lock'
    #define mutex_lock(lock) mutex_lock_nested(lock, 0)
                                               ^~~~
   drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c:439:18: error: 'struct bnxt' has no member named 'sriov_lock'
     mutex_unlock(&bp->sriov_lock);
                     ^~

vim +7897 drivers/net/ethernet/broadcom/bnxt/bnxt.c

7863
7864 static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7865 {
7866 static int version_printed;
7867 struct net_device *dev;
7868 struct bnxt *bp;
7869 int rc, max_irqs;
7870
7871 if (pci_is_bridge(pdev))
7872 return -ENODEV;
7873
7874 if (version_printed++ == 0)
7875 pr_info("%s", version);
7876
7877 max_irqs = bnxt_get_max_irq(pdev);
7878 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
7879 if (!dev)
7880 return -ENOMEM;
7881
7882 bp = netdev_priv(dev);
7883
7884 if (bnxt_vf_pciid(ent->driver_data))
7885 bp->flags |= BNXT_FLAG_VF;
7886
7887 if (pdev->msix_cap)
7888 bp->flags |= BNXT_FLAG_MSIX_CAP;
7889
7890 rc = bnxt_init_board(pdev, dev);
7891 if (rc < 0)
7892 goto init_err_free;
7893
7894 dev->netdev_ops = &bnxt_netdev_ops;
7895 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
7896 dev->ethtool_ops = &bnxt_ethtool_ops;

> 7897		dev->switchdev_ops = &bnxt_switchdev_ops;
  7898		pci_set_drvdata(pdev, dev);
  7899	
  7900		rc = bnxt_alloc_hwrm_resources(bp);
  7901		if (rc)
  7902			goto init_err_pci_clean;
  7903	
  7904		mutex_init(&bp->hwrm_cmd_lock);
  7905		rc = bnxt_hwrm_ver_get(bp);
  7906		if (rc)
  7907			goto init_err_pci_clean;
  7908	
  7909		if (bp->flags & BNXT_FLAG_SHORT_CMD) {
  7910			rc = bnxt_alloc_hwrm_short_cmd_req(bp);
  7911			if (rc)
  7912				goto init_err_pci_clean;
  7913		}
  7914	
  7915		rc = bnxt_hwrm_func_reset(bp);
  7916		if (rc)
  7917			goto init_err_pci_clean;
  7918	
  7919		bnxt_hwrm_fw_set_time(bp);
  7920	
  7921		dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  7922				   NETIF_F_TSO | NETIF_F_TSO6 |
  7923				   NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
  7924				   NETIF_F_GSO_IPXIP4 |
  7925				   NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
  7926				   NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
  7927				   NETIF_F_RXCSUM | NETIF_F_GRO;

7928
7929 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
7930 dev->hw_features |= NETIF_F_LRO;
7931
7932 dev->hw_enc_features =
7933 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
7934 NETIF_F_TSO | NETIF_F_TSO6 |
7935 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
7936 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
7937 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
7938 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
7939 NETIF_F_GSO_GRE_CSUM;
7940 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
7941 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
7942 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
7943 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
7944 dev->priv_flags |= IFF_UNICAST_FLT;
7945
7946 /* MTU range: 60 - 9500 */
7947 dev->min_mtu = ETH_ZLEN;
7948 dev->max_mtu = BNXT_MAX_MTU;
7949

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#13 lore raw

Re: [PATCH net-next 10/10] bnxt_en: add support for port_attr_get and and get_phys_port_name

Quoted 4 lines · kbuild test robot

drivers/net/ethernet/broadcom/bnxt/bnxt.c: In function 'bnxt_init_one':

Quoted 1 line
Quoted 1 line

drivers/net/ethernet/broadcom/bnxt/bnxt.c:7897:5: error: 'struct net_device' has no member named 'switchdev_ops'; did you mean 'netdev_ops'?

     dev->switchdev_ops = &bnxt_switchdev_ops;
        ^~

Check out SWITCHDEV_SET_OPS() from commit d643a75ac2bc ("net: switchdev:
add SET_SWITCHDEV_OPS helper").

maintainer
#14 lore raw

Re: [PATCH net-next 10/10] bnxt_en: add support for port_attr_get and and get_phys_port_name

From: Jakub Kicinski <[email protected]>
Date: Mon, 24 Jul 2017 21:06:17 -0700

Quoted 8 lines · kbuild test robot
Quoted 4 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c: In function 'bnxt_init_one':

Quoted 1 line
Quoted 1 line

drivers/net/ethernet/broadcom/bnxt/bnxt.c:7897:5: error: 'struct net_device' has no member named 'switchdev_ops'; did you mean 'netdev_ops'?

     dev->switchdev_ops = &bnxt_switchdev_ops;
        ^~

Check out SWITCHDEV_SET_OPS() from commit d643a75ac2bc ("net: switchdev:
add SET_SWITCHDEV_OPS helper").

This was easy enough so I just pushed out:

====================

Quoted 1 line

From bc88055ab72c0eaa080926c888628b77d2055513 Mon Sep 17 00:00:00 2001

From: "David S. Miller" <[email protected]>
Date: Mon, 24 Jul 2017 21:20:16 -0700
Subject: [PATCH] bnxt_en: Use SWITCHDEV_SET_OPS().

Suggested by Jakub Kicinski.

Fixes c124a62ff2dd ("bnxt_en: add support for port_attr_get and and get_phys_port_name")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
index 82cbe1804821..badbc3550338 100644
@@ -7894,7 +7894,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	dev->netdev_ops = &bnxt_netdev_ops;
 	dev->watchdog_timeo = BNXT_TX_TIMEOUT;
 	dev->ethtool_ops = &bnxt_ethtool_ops;
-	dev->switchdev_ops = &bnxt_switchdev_ops;
+	SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops);
 	pci_set_drvdata(pdev, dev);
 
 	rc = bnxt_alloc_hwrm_resources(bp);
Signature · 1 line
2.13.3
#15 lore raw

Re: [PATCH net-next 10/10] bnxt_en: add support for port_attr_get and and get_phys_port_name

In reply to Michael Chan
Quoted 28 lines · Michael Chan

From: Sathya Perla <[email protected]>

This patch adds support for the switchdev_port_attr_get() and ndo_get_phys_port_name() methods for the PF and the VF-reps. Using this support a user application can deduce that the PF (when in the ESWITCH_SWDEV mode) and it's VF-reps form a switch.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 57 +++++++++++++++++++++++++++
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  2 +
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c | 31 ++++++++++++++-
 3 files changed, 89 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5 -0
index f262fe6..82cbe18 100644
@@ -7546,6 +7546,61 @@ static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
 	return rc;
 }
 
+static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
+				   size_t len)
+{
+	struct bnxt *bp = netdev_priv(dev);
+	int rc;

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, · line 7563

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -0
+
+	/* The PF and it's VF-reps only support the switchdev framework */
+	if (!BNXT_PF(bp))
+		return -EOPNOTSUPP;
+
+	/* The switch-id that the pf belongs to is exported by
+	 * the switchdev ndo. This name is just to distinguish from the
+	 * vf-rep ports.
+	 */
+	rc = snprintf(buf, len, "pf%d", bp->pf.port_id);

This is worrisome. What do you mean by PF? In my experience, since for years PFs had one-to-one association with physical ports people use the terms interchangeably. This causes a lot of headaches in proper eswitch modelling.

I'm not sure whether this is a HW limitation or engineers trying to make things "easy for users" but most VF-representor patchsets we've seen on netdev don't include PF representors. NICs have 3 types of ports - PFs, VFs and external ports/MACs. For some reason there is a tendency to keep pretending PF and physical port is the same entity, which among other things makes it impossible to install VF->PF rules (as in from VF to the host, not to the network).

Most high performance NIC vendors also have multi-PF NICs, even though those are not deployed by wider public. If we keep pretending PF is the external port, those will get very awkward to model. This is a bit of a pet peeve of mine :)

If this bnxt_get_phys_port_name() relates to the external port, please change your implementation to comply with Documentation/networking/switchdev.txt, in particular:

Quoted 3 lines

Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y is the port name or ID, and Z is the sub-port name or ID. For example, sw1p1s0 would be sub-port 0 on port 1 on switch 1.

So for physical ports the convention is p<port_id>, and in case of breakout p<port_id>s<subport_id>.

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +7 -0
+static int bnxt_vf_rep_get_phys_port_name(struct net_device *dev, char *buf,
+					  size_t len)
+{
+	struct bnxt_vf_rep *vf_rep = netdev_priv(dev);
+	int rc;
+
+	rc = snprintf(buf, len, "vfr%d", vf_rep->vf_idx);

This is even worse. We already have two naming conventions in the kernel, mlx5 uses "%d" for legacy reasons. nfp uses pf%dvf%d for vfs, which is better for two reasons: (a) it works with multi-PF devices;
(b) naming something representor from switchdev perspective is pointless, you're not calling the external port netdev a physical port representor, even though it has the exact same relation to the port as with VFs (i.e. egressing traffic on the netdev will cause the switch to send to the given port).

#16 lore raw

RFC 1/1 switchdev: clarify ndo_get_phys_port_name() formats

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

---
 Documentation/networking/switchdev.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +11 -3
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).
+Where A is the port name or ID; B is the sub-port name or ID; C is PCIe
+Physical Function name or ID and D is PCIe Virtual Function name or ID.
+
+Suggested naming convention for switches is "swX", where X is the switch name
+or ID, plus the port name.  For example, sw1p1s0 would be sub-port 0 on port 1
+on switch 1.
 
 Port Features
 ^^^^^^^^^^^^^
Signature · 1 line
2.11.0
#34 lore raw

Re: [PATCH net-next 10/10] bnxt_en: add support for port_attr_get and and get_phys_port_name

In reply to Jakub Kicinski

On Tue, Jul 25, 2017 at 10:15 AM, Jakub Kicinski <[email protected]> wrote:
...

Quoted 29 lines
Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5 -0
+static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
+                                size_t len)
+{
+     struct bnxt *bp = netdev_priv(dev);
+     int rc;

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, · line 7563

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -0
+
+     /* The PF and it's VF-reps only support the switchdev framework */
+     if (!BNXT_PF(bp))
+             return -EOPNOTSUPP;
+
+     /* The switch-id that the pf belongs to is exported by
+      * the switchdev ndo. This name is just to distinguish from the
+      * vf-rep ports.
+      */
+     rc = snprintf(buf, len, "pf%d", bp->pf.port_id);

This is worrisome. What do you mean by PF? In my experience, since for years PFs had one-to-one association with physical ports people use the terms interchangeably. This causes a lot of headaches in proper eswitch modelling.

I'm not sure whether this is a HW limitation or engineers trying to make things "easy for users" but most VF-representor patchsets we've seen on netdev don't include PF representors. NICs have 3 types of ports - PFs, VFs and external ports/MACs. For some reason there is a tendency to keep pretending PF and physical port is the same entity, which among other things makes it impossible to install VF->PF rules (as in from VF to the host, not to the network).

Quoted 4 lines

Most high performance NIC vendors also have multi-PF NICs, even though those are not deployed by wider public. If we keep pretending PF is the external port, those will get very awkward to model. This is a bit of a pet peeve of mine :)

Jakub, we'll consider implementing a PF-rep as an add-on feature...

Quoted 11 lines

If this bnxt_get_phys_port_name() relates to the external port, please change your implementation to comply with Documentation/networking/switchdev.txt, in particular:

Quoted 3 lines

Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y is the port name or ID, and Z is the sub-port name or ID. For example, sw1p1s0 would be sub-port 0 on port 1 on switch 1.

So for physical ports the convention is p<port_id>, and in case of breakout p<port_id>s<subport_id>.

I'm sending a follow-up patch that fixes the naming for both the external port and the VF-reps as proposed in your RFC ( switchdev:
clarify ndo_get_phys_port_name() formats)

thanks,
-Sathya

#17 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

In reply to Jakub Kicinski
Quoted 7 lines · Jakub Kicinski

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

This is a nice addition and I suspect there could be even more done to update this file to cover the VF rep usage.

Quoted 10 lines
---
 Documentation/networking/switchdev.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +0 -0
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \

Documentation/networking/switchdev.txt into 4 10G ports, resulting in 4 port netdevs, the device can give a unique · line 126

Quoted 10 lines
Documentation/networking/switchdev.txt +5 -3
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).

I hate to clutter this up, but might be also need to add:

- pfCsB for split PF ports (so called PF representors);
- pfCsBvfD for split VF ports (so called VF representors).

or are we comfortable that these additions to the name for split ports are implied?

Quoted 9 lines
Documentation/networking/switchdev.txt +6 -0
+Where A is the port name or ID; B is the sub-port name or ID; C is PCIe
+Physical Function name or ID and D is PCIe Virtual Function name or ID.
+
+Suggested naming convention for switches is "swX", where X is the switch name
+or ID, plus the port name.  For example, sw1p1s0 would be sub-port 0 on port 1
+on switch 1.
 
 Port Features
 ^^^^^^^^^^^^^
#18 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

Quoted 35 lines · Andy Gospodarek
Quoted 7 lines · Jakub Kicinski

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

This is a nice addition and I suspect there could be even more done to update this file to cover the VF rep usage.

Quoted 10 lines
---
 Documentation/networking/switchdev.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +0 -0
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \

Documentation/networking/switchdev.txt into 4 10G ports, resulting in 4 port netdevs, the device can give a unique · line 126

Quoted 10 lines
Documentation/networking/switchdev.txt +5 -3
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).  

I hate to clutter this up, but might be also need to add:

Quoted 5 lines

- pfCsB for split PF ports (so called PF representors);
- pfCsBvfD for split VF ports (so called VF representors).

or are we comfortable that these additions to the name for split ports are implied?

Hm.. What is a split PF port? Splits happen on the physical port - see my rant on the thread this is a reply to ;) PFs are PCIe functions, on the opposite side of the eswitch from the wires.

#35 lore raw

Re: [PATCH net-next 10/10] bnxt_en: add support for port_attr_get and and get_phys_port_name

In reply to Sathya Perla
Quoted 10 lines · Sathya Perla
Quoted 6 lines
Quoted 3 lines

Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y is the port name or ID, and Z is the sub-port name or ID. For example, sw1p1s0 would be sub-port 0 on port 1 on switch 1.

So for physical ports the convention is p<port_id>, and in case of breakout p<port_id>s<subport_id>.

I'm sending a follow-up patch that fixes the naming for both the external port and the VF-reps as proposed in your RFC ( switchdev:
clarify ndo_get_phys_port_name() formats)

Thanks!

#19 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

In reply to Jakub Kicinski
Quoted 39 lines · Jakub Kicinski
Quoted 38 lines · Andy Gospodarek
Quoted 7 lines · Jakub Kicinski

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

This is a nice addition and I suspect there could be even more done to update this file to cover the VF rep usage.

Quoted 10 lines
---
 Documentation/networking/switchdev.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +0 -0
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \

Documentation/networking/switchdev.txt into 4 10G ports, resulting in 4 port netdevs, the device can give a unique · line 126

Quoted 10 lines
Documentation/networking/switchdev.txt +5 -3
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).  

I hate to clutter this up, but might be also need to add:

- pfCsB for split PF ports (so called PF representors);
- pfCsBvfD for split VF ports (so called VF representors).

Quoted 6 lines
Quoted 2 lines

or are we comfortable that these additions to the name for split ports are implied?

Hm.. What is a split PF port? Splits happen on the physical port - see my rant on the thread this is a reply to ;) PFs are PCIe functions, on the opposite side of the eswitch from the wires.

I'm with you that I think there is value in separate netdevs to represent "PFs, VFs and external ports/MACs" -- particularly for the use-case you to create rules to control PF<->VF traffic.

So while I'm not saying it is a _great_ idea to support such a thing as port-splitting of PFs, I suggested this addition as I'm not willing to restrict such a design/implementation if a vendor or customer desired. It seemed useful to provde some guidance on how to name them -- even if we do not like them. :-)

#20 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

Quoted 51 lines · Andy Gospodarek
Quoted 39 lines · Jakub Kicinski
Quoted 38 lines · Andy Gospodarek
Quoted 7 lines · Jakub Kicinski

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

This is a nice addition and I suspect there could be even more done to update this file to cover the VF rep usage.

Quoted 10 lines
---
 Documentation/networking/switchdev.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +0 -0
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \

Documentation/networking/switchdev.txt into 4 10G ports, resulting in 4 port netdevs, the device can give a unique · line 126

Quoted 10 lines
Documentation/networking/switchdev.txt +5 -3
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).    

I hate to clutter this up, but might be also need to add:

- pfCsB for split PF ports (so called PF representors);
- pfCsBvfD for split VF ports (so called VF representors).

Quoted 6 lines
Quoted 2 lines

or are we comfortable that these additions to the name for split ports are implied?

Hm.. What is a split PF port? Splits happen on the physical port - see my rant on the thread this is a reply to ;) PFs are PCIe functions, on the opposite side of the eswitch from the wires.

I'm with you that I think there is value in separate netdevs to represent "PFs, VFs and external ports/MACs" -- particularly for the use-case you to create rules to control PF<->VF traffic.

Quoted 5 lines

So while I'm not saying it is a _great_ idea to support such a thing as port-splitting of PFs, I suggested this addition as I'm not willing to restrict such a design/implementation if a vendor or customer desired. It seemed useful to provde some guidance on how to name them -- even if we do not like them. :-)

If I understand you correctly split PF would be a situation where device has multiple port instances on the PCIe PF side? IOW switch sees multiple endpoints on the PF side? Let me attempt an ASCII diagram :)

                    HOST A             ||          HOST B                  
                                       ||                                  
        PF A       | V | V | V | V     ||       PF B        | V | V | V               
                   | F | F | F | F ... ||                   | F | F | F ...           
 port A0 | port A1 | 0 | 1 | 2 | 3     || port B0 | port B1 | 0 | 1 | 2            
                                       ||                                  
             PCI Express link          ||        PCI Express link          
        \      \      \  |   |   |          |        |      /   /   /         
         \      \      \ |   |   |          |        |     /   /   /          
          \______\______\'   |   |          |        '____/___/___/
                         /---------------------------\                         
                         |<<==========               |
                         |             ==========>>  |
                         |     SR-IOV e-switch       |                         
                         |<<==========               |                         
                         |             ==========>>  |                          
                         \---------------------------/                     
                              |        |         |                          
                              |        |         |                          
                                 ||         ||                               
                          MAC 0  ||  MAC 1  || MAC 2                   
                                 ||         ||                              

Seems to be a valid configuration, perhaps this would actually be of some use in container workloads, especially if the ports could be instantiated at runtime in high numbers. I would be cautious though with calling the instances splits. The more different PFs look from MACs the better IMHO. Do you actually have that problem today? Is there any HW supported upstream which would benefit from this? Could we decide on naming when we have an example implementation? In theory nothing stops us from splitting VFs the same way.

Another note on PF netdevs, perhaps the most awkward thing about them, is that they result in two netdevs being visible to the host. This is not incorrect, since VFs if unassigned to VMs will end up creating an "actual" netdev and the switchdev port representor too, but it rubs some people the wrong way. Which in turn makes those people try to not spawn separate netdevs, which is incorrect IMHO, and breaks down e.g. when the real netdev gets assigned to a namespace.

I'm not sure if this clarifies my thinking, I have, however, seem to have drawn a moose :)

#22 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

In reply to Jakub Kicinski
Quoted 17 lines · Tue, Jul 25, 2017 at 07:13:44AM CEST, [email protected] wrote:

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

---
Documentation/networking/switchdev.txt | 14 +++++++++++---

1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +0 -0
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \

Documentation/networking/switchdev.txt into 4 10G ports, resulting in 4 port netdevs, the device can give a unique · line 126

Quoted 10 lines
Documentation/networking/switchdev.txt +5 -3
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).

I think it would make sense if the driver would just fill-up a struct in the ndo call and core would generate the string.

Quoted 12 lines
Documentation/networking/switchdev.txt +6 -0
+Where A is the port name or ID; B is the sub-port name or ID; C is PCIe
+Physical Function name or ID and D is PCIe Virtual Function name or ID.
+
+Suggested naming convention for switches is "swX", where X is the switch name
+or ID, plus the port name.  For example, sw1p1s0 would be sub-port 0 on port 1
+on switch 1.
 

Port Features
^^^^^^^^^^^^^

Signature · 1 line
2.11.0
#23 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

Quoted 20 lines · Jiri Pirko
Quoted 19 lines · Tue, Jul 25, 2017 at 07:13:44AM CEST, [email protected] wrote:

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

---
Documentation/networking/switchdev.txt | 14 +++++++++++---

1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +0 -0
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
Quoted 11 lines

Documentation/networking/switchdev.txt into 4 10G ports, resulting in 4 port netdevs, the device can give a unique · line 126

Quoted 8 lines
Documentation/networking/switchdev.txt +5 -3
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).  

I think it would make sense if the driver would just fill-up a struct in the ndo call and core would generate the string.

I do like the idea of core generating the string. I have a temptation to try to involve devlink in this somehow, since port id and split info is already available there. Perhaps that would only overcomplicate things.

The other question is: can we remove the option to generate an arbitrary string completely? I think Or and mlx5 folks may object since it would mean mlx5 VF repr names would change.

#36 lore raw

Re: [PATCH net-next 10/10] bnxt_en: add support for port_attr_get and and get_phys_port_name

In reply to Jakub Kicinski
Quoted 2 lines · Jakub Kicinski

This is even worse. We already have two naming conventions in the kernel, mlx5 uses "%d" for legacy reasons. nfp uses pf%dvf%d for vfs,

To make it clear, in mlx5 this is used only for the offloads/switchdev mode and not for legacy mode, in the latter mode, a VF probed to VM doesn't have host side representation so there's no where to use that.

Or.

Quoted 6 lines

which is better for two reasons: (a) it works with multi-PF devices;
(b) naming something representor from switchdev perspective is pointless, you're not calling the external port netdev a physical port representor, even though it has the exact same relation to the port as with VFs (i.e. egressing traffic on the netdev will cause the switch to send to the given port).

#24 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

In reply to Jakub Kicinski
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · Jiri Pirko

I think it would make sense if the driver would just fill-up a struct in the ndo call and core would generate the string.

Quoted 8 lines

I do like the idea of core generating the string. I have a temptation to try to involve devlink in this somehow, since port id and split info is already available there. Perhaps that would only overcomplicate things.

The other question is: can we remove the option to generate an arbitrary string completely? I think Or and mlx5 folks may object since it would mean mlx5 VF repr names would change.

What we have today is the representor driver instance setting the VF index as the of phys port name and we're telling users to have this sort of udev rule:

SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \ ATTR{phys_port_name}!="", NAME="$PF_NIC$attr{phys_port_name}"

that has affiliation to the PF where this VF belongs. AFAIK this model/assumption is now under push to
higher level (open stack), so lets see if/what we want to change here w.r.t to sriov offloading drivers.

I would opt for an approach where the value returned by the kernel is the minimal possible and
user-space has flexibility to further orchestrate that with udev rules. I wasn't fully clear on Jakub's suggestion
which parts must come from the kernel. Do we have any length limitation for the phys port name?

Or.

#21 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

In reply to Jakub Kicinski
Quoted 93 lines · Jakub Kicinski
Quoted 51 lines · Andy Gospodarek
Quoted 39 lines · Jakub Kicinski
Quoted 38 lines · Andy Gospodarek
Quoted 7 lines · Jakub Kicinski

We are still in position where we can suggest uniform naming convention for ndo_get_phys_port_name(). switchdev.txt file already contained a suggestion of how to name external ports. Since the use of switchdev for SR-IOV NIC's eswitches is growing, establish a format for ports of those devices as well.

This is a nice addition and I suspect there could be even more done to update this file to cover the VF rep usage.

Quoted 10 lines
---
 Documentation/networking/switchdev.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/networking/switchdev.txt +0 -0
index 3e7b946dea27..7c4b6025fb4b 100644
@@ -119,9 +119,17 @@ into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \

Documentation/networking/switchdev.txt into 4 10G ports, resulting in 4 port netdevs, the device can give a unique · line 126

Quoted 10 lines
Documentation/networking/switchdev.txt +5 -3
 	ATTR{phys_port_name}!="", NAME="swX$attr{phys_port_name}"
 
-Suggested naming convention is "swXpYsZ", where X is the switch name or ID, Y
-is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
-would be sub-port 0 on port 1 on switch 1.
+Suggested formats of the port name returned by ndo_get_phys_port_name are:
+ - pA     for external ports;
+ - pAsB   for split external ports;
+ - pfC    for PF ports (so called PF representors);
+ - pfCvfD for VF ports (so called VF representors).    

I hate to clutter this up, but might be also need to add:

- pfCsB for split PF ports (so called PF representors);
- pfCsBvfD for split VF ports (so called VF representors).

Quoted 6 lines
Quoted 2 lines

or are we comfortable that these additions to the name for split ports are implied?

Hm.. What is a split PF port? Splits happen on the physical port - see my rant on the thread this is a reply to ;) PFs are PCIe functions, on the opposite side of the eswitch from the wires.

I'm with you that I think there is value in separate netdevs to represent "PFs, VFs and external ports/MACs" -- particularly for the use-case you to create rules to control PF<->VF traffic.

Quoted 5 lines

So while I'm not saying it is a _great_ idea to support such a thing as port-splitting of PFs, I suggested this addition as I'm not willing to restrict such a design/implementation if a vendor or customer desired. It seemed useful to provde some guidance on how to name them -- even if we do not like them. :-)

If I understand you correctly split PF would be a situation where device has multiple port instances on the PCIe PF side? IOW switch sees multiple endpoints on the PF side? Let me attempt an ASCII diagram :)

                    HOST A             ||          HOST B                  
                                       ||                                  
        PF A       | V | V | V | V     ||       PF B        | V | V | V               
                   | F | F | F | F ... ||                   | F | F | F ...           
 port A0 | port A1 | 0 | 1 | 2 | 3     || port B0 | port B1 | 0 | 1 | 2            
                                       ||                                  
             PCI Express link          ||        PCI Express link          
        \      \      \  |   |   |          |        |      /   /   /         
         \      \      \ |   |   |          |        |     /   /   /          
          \______\______\'   |   |          |        '____/___/___/
                         /---------------------------\                         
                         |<<==========               |
                         |             ==========>>  |
                         |     SR-IOV e-switch       |                         
                         |<<==========               |                         
                         |             ==========>>  |                          
                         \---------------------------/                     
                              |        |         |                          
                              |        |         |                          
                                 ||         ||                               
                          MAC 0  ||  MAC 1  || MAC 2                   
                                 ||         ||                              

Seems to be a valid configuration, perhaps this would actually be of some use in container workloads, especially if the ports could be instantiated at runtime in high numbers. I would be cautious though with calling the instances splits. The more different PFs look from MACs the better IMHO. Do you actually have that problem today?

Quoted 3 lines

Is there any HW supported upstream which would benefit from this? Could we decide on naming when we have an example implementation? In theory nothing stops us from splitting VFs the same way.

Not that I know about right now.

Quoted 7 lines

Another note on PF netdevs, perhaps the most awkward thing about them, is that they result in two netdevs being visible to the host. This is not incorrect, since VFs if unassigned to VMs will end up creating an "actual" netdev and the switchdev port representor too, but it rubs some people the wrong way. Which in turn makes those people try to not spawn separate netdevs, which is incorrect IMHO, and breaks down e.g. when the real netdev gets assigned to a namespace.

For me, the most awkward part of having a separate netdev for the PF and the MAC is that is really not how things were thought about in the nominal switching case (the non e-switch case).

Since idea behind switchdev when it was created was to make sure that each front-panel port on a switch was represented by a netdev in the kernel (and the 'CPU interface' was abstracted away by the driver) I was always a bit uneasy about having a separate netdev allocated for the CPU port when in the switching case it really wasn't necessary.

Quoted 2 lines

I'm not sure if this clarifies my thinking, I have, however, seem to have drawn a moose :)

Which looks great, BTW. The moose may turn out to be one of the major benefits from this thread!

#25 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

In reply to Or Gerlitz
Quoted 15 lines · Or Gerlitz
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · Jiri Pirko

I think it would make sense if the driver would just fill-up a struct in the ndo call and core would generate the string.

Quoted 8 lines

I do like the idea of core generating the string. I have a temptation to try to involve devlink in this somehow, since port id and split info is already available there. Perhaps that would only overcomplicate things.

The other question is: can we remove the option to generate an arbitrary string completely? I think Or and mlx5 folks may object since it would mean mlx5 VF repr names would change.

Quoted 6 lines

What we have today is the representor driver instance setting the VF index as the of phys port name and we're telling users to have this sort of udev rule:

SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \ ATTR{phys_port_name}!="", NAME="$PF_NIC$attr{phys_port_name}"

Example names generated by this rule would be pfnic_0, pfnic_1 for vf representors 0 and 1?

Quoted 11 lines

that has affiliation to the PF where this VF belongs. AFAIK this model/assumption is now under push to
higher level (open stack), so lets see if/what we want to change here w.r.t to sriov offloading drivers.

I would opt for an approach where the value returned by the kernel is the minimal possible and
user-space has flexibility to further orchestrate that with udev rules. I wasn't fully clear on Jakub's suggestion
which parts must come from the kernel. Do we have any length limitation for the phys port name?

Looks like the limit today is IFNAMSIZ. I'm in favor of leaving the flexibility to the userspace, why I suggested adding the pf%d or pf%dvf%d to the name is that I don't think we have any other way today of telling whether representor is for a physical port, VF or PF.

If I understand mlx5 code, you're not reporting port ids for physical ports so presence of the name already implies it's a VF but in case you want to add port splitting support, for example, reporting the name on physical ports will become more of a necessity.

If we adopt Jiri's suggestion of returning structured data it will be very easy to give user space type and indexes separately, but we should probably still return the string for backwards compatibility.

#26 lore raw

Re: [RFC] switchdev: clarify ndo_get_phys_port_name() formats

Quoted 19 lines · Jakub Kicinski
Quoted 18 lines · Or Gerlitz
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · Jiri Pirko

I think it would make sense if the driver would just fill-up a struct in the ndo call and core would generate the string.

Quoted 8 lines

I do like the idea of core generating the string. I have a temptation to try to involve devlink in this somehow, since port id and split info is already available there. Perhaps that would only overcomplicate things.

The other question is: can we remove the option to generate an arbitrary string completely? I think Or and mlx5 folks may object since it would mean mlx5 VF repr names would change.

What we have today is the representor driver instance setting the VF index as the of phys port name and we're telling users to have this sort of udev rule:

Quoted 6 lines
Quoted 3 lines

SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \ ATTR{phys_port_name}!="", NAME="$PF_NIC$attr{phys_port_name}"

Example names generated by this rule would be pfnic_0, pfnic_1 for vf representors 0 and 1?

YES

Quoted 12 lines
Quoted 11 lines

that has affiliation to the PF where this VF belongs. AFAIK this model/assumption is now under push to
higher level (open stack), so lets see if/what we want to change here w.r.t to sriov offloading drivers.

I would opt for an approach where the value returned by the kernel is the minimal possible and
user-space has flexibility to further orchestrate that with udev rules. I wasn't fully clear on Jakub's suggestion
which parts must come from the kernel. Do we have any length limitation for the phys port name?

Quoted 7 lines

Looks like the limit today is IFNAMSIZ. I'm in favor of leaving the flexibility to the userspace, why I suggested adding the pf%d or pf%dvf%d to the name is that I don't think we have any other way today of telling whether representor is for a physical port, VF or PF.

If I understand mlx5 code, you're not reporting port ids for physical ports so presence of the name already implies it's a VF but in case you

yes, currently in our model the PF serves as the uplink representor when running in offloads mode.

Quoted 6 lines

want to add port splitting support, for example, reporting the name on physical ports will become more of a necessity.

If we adopt Jiri's suggestion of returning structured data it will be very easy to give user space type and indexes separately, but we should probably still return the string for backwards compatibility.

I am not still clear how the structured data would look like

#27 lore raw

RFC 1/1 switchdev: generate phys_port_name in the core

Quoted 8 lines · Or Gerlitz
Quoted 6 lines

want to add port splitting support, for example, reporting the name on physical ports will become more of a necessity.

If we adopt Jiri's suggestion of returning structured data it will be very easy to give user space type and indexes separately, but we should probably still return the string for backwards compatibility.

I am not still clear how the structured data would look like

I decided to just quickly write the code, that should be easier to understand. We can probably leave out the netlink part of the API if there is no need for it right now, but that's what I ment by returning the information in a more structured way.

Tested-by nobody :)
Suggested-by Jiri (if I understood correctly)
---
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c |  8 ++-
 drivers/net/ethernet/mellanox/mlxsw/switchx2.c   | 10 ++--
 drivers/net/ethernet/netronome/nfp/nfp_port.c    | 26 ++++-----
 drivers/net/ethernet/netronome/nfp/nfp_port.h    |  4 +-
 include/linux/netdevice.h                        | 18 ++++++-
 include/uapi/linux/if_link.h                     | 16 ++++++
 net/core/dev.c                                   | 31 +++++++++--
 net/core/rtnetlink.c                             | 69 ++++++++++++++++++++++++
 8 files changed, 153 insertions(+), 29 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +3 -5
index 45e60be9c277..7a71291b8ec3 100644
@@ -637,16 +637,14 @@ static int mlx5e_rep_close(struct net_device *dev)
 }
 
 static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
+					struct netdev_port_info *info)
 {
 	struct mlx5e_priv *priv = netdev_priv(dev);
 	struct mlx5e_rep_priv *rpriv = priv->ppriv;
 	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	int ret;
 
-	ret = snprintf(buf, len, "%d", rep->vport - 1);
-	if (ret >= len)
-		return -EOPNOTSUPP;
+	info->type = NETDEV_PORT_PCI_VF;
+	info->pci.vf_id = rep->vport - 1;
 
 	return 0;
 }
drivers/net/ethernet/mellanox/mlxsw/switchx2.c +4 -6
index 3b0f72455681..383b8b5f41cf 100644
@@ -413,15 +413,13 @@ mlxsw_sx_port_get_stats64(struct net_device *dev,
 	stats->tx_dropped	= tx_dropped;
 }
 
-static int mlxsw_sx_port_get_phys_port_name(struct net_device *dev, char *name,
-					    size_t len)
+static int mlxsw_sx_port_get_phys_port_name(struct net_device *dev,
+					    struct netdev_port_info *info)
 {
 	struct mlxsw_sx_port *mlxsw_sx_port = netdev_priv(dev);
-	int err;
 
-	err = snprintf(name, len, "p%d", mlxsw_sx_port->mapping.module + 1);
-	if (err >= len)
-		return -EINVAL;
+	info->type = NETDEV_PORT_EXTERNAL;
+	info->port.id = mlxsw_sx_port->mapping.module + 1;
 
 	return 0;
 }
drivers/net/ethernet/netronome/nfp/nfp_port.c +14 -12
index d16a7b78ba9b..8f5c37b9a79c 100644
@@ -143,11 +143,11 @@ struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port)
 }
 
 int
-nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len)
+nfp_port_get_phys_port_name(struct net_device *netdev,
+			    struct netdev_port_info *info)
 {
 	struct nfp_eth_table_port *eth_port;
 	struct nfp_port *port;
-	int n;
 
 	port = nfp_port_from_netdev(netdev);
 	if (!port)
@@ -159,25 +159,27 @@ nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len)
 		if (!eth_port)
 			return -EOPNOTSUPP;
 
-		if (!eth_port->is_split)
-			n = snprintf(name, len, "p%d", eth_port->label_port);
-		else
-			n = snprintf(name, len, "p%ds%d", eth_port->label_port,
-				     eth_port->label_subport);
+		info->type = NETDEV_PORT_EXTERNAL;
+		info->external.id = eth_port->label_port;
+
+		if (eth_port->is_split) {
+			info->type = NETDEV_PORT_EXTERNAL_SPLIT;
+			info->external.split_id = eth_port->label_subport;
+		}
 		break;
 	case NFP_PORT_PF_PORT:
-		n = snprintf(name, len, "pf%d", port->pf_id);
+		info->type = NETDEV_PORT_PCI_PF;
+		info->pci.pf_id = port->pf_id;
 		break;
 	case NFP_PORT_VF_PORT:
-		n = snprintf(name, len, "pf%dvf%d", port->pf_id, port->vf_id);
+		info->type = NETDEV_PORT_PCI_VF;
+		info->pci.pf_id = port->pf_id;
+		info->pci.vf_id = port->vf_id;
 		break;
 	default:
 		return -EOPNOTSUPP;
 	}
 
-	if (n >= len)
-		return -EINVAL;
-
 	return 0;
 }
 
drivers/net/ethernet/netronome/nfp/nfp_port.h +2 -2
index 56c76926c82a..03b8746feb29 100644
@@ -118,8 +118,8 @@ nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id);
 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port);
 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port);
 
-int
-nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len);
+int nfp_port_get_phys_port_name(struct net_device *netdev,
+				struct netdev_port_info *info);
 int nfp_port_configure(struct net_device *netdev, bool configed);
 
 struct nfp_port *
include/linux/netdevice.h +17 -1
index 3a3cdc1b1f31..0a055df701ef 100644
@@ -845,6 +845,22 @@ struct xfrmdev_ops {
 };
 #endif
 
+struct netdev_port_info {
+	int type;
+
+	union {
+		struct {
+			u32 id;
+			u32 split_id;
+		} external;
+
+		struct {
+			u32 pf_id;
+			u32 vf_id;
+		} pci;
+	};
+};
+
 /*
  * This structure defines the management hooks for network devices.
  * The following hooks can be defined; unless noted otherwise, they are
@@ -1306,7 +1322,7 @@ struct net_device_ops {
 	int			(*ndo_get_phys_port_id)(struct net_device *dev,
 							struct netdev_phys_item_id *ppid);
 	int			(*ndo_get_phys_port_name)(struct net_device *dev,
-							  char *name, size_t len);
+							  struct netdev_port_info *info);
 	void			(*ndo_udp_tunnel_add)(struct net_device *dev,
 						      struct udp_tunnel_info *ti);
 	void			(*ndo_udp_tunnel_del)(struct net_device *dev,
include/uapi/linux/if_link.h +16 -0
index 8d062c58d5cb..e00ff0333e3f 100644
@@ -158,6 +158,7 @@ enum {
 	IFLA_PAD,
 	IFLA_XDP,
 	IFLA_EVENT,
+	IFLA_PORT_INFO,
 	__IFLA_MAX
 };
 
@@ -927,4 +928,19 @@ enum {
 	IFLA_EVENT_BONDING_OPTIONS,	/* change in bonding options */
 };
 
+enum {
+	NETDEV_PORT_EXTERNAL,
+	NETDEV_PORT_EXTERNAL_SPLIT,
+	NETDEV_PORT_PCI_PF,
+	NETDEV_PORT_PCI_VF,
+};
+
+enum {
+	IFLA_PORT_INFO_TYPE,
+	IFLA_PORT_INFO_EXTERNAL_ID,
+	IFLA_PORT_INFO_EXTERNAL_SPLIT_ID,
+	IFLA_PORT_INFO_PCI_PF_ID,
+	IFLA_PORT_INFO_PCI_VF_ID,
+};
+
 #endif /* _UAPI_LINUX_IF_LINK_H */
net/core/dev.c +28 -3
index 8ea6b4b42611..8fe3f697234e 100644
@@ -6947,14 +6947,39 @@ EXPORT_SYMBOL(dev_get_phys_port_id);
  *
  *	Get device physical port name
  */
-int dev_get_phys_port_name(struct net_device *dev,
-			   char *name, size_t len)
+int dev_get_phys_port_name(struct net_device *dev, char *name, size_t len)
 {
 	const struct net_device_ops *ops = dev->netdev_ops;
+	struct netdev_port_info info = {};
+	int ret;
 
 	if (!ops->ndo_get_phys_port_name)
 		return -EOPNOTSUPP;
-	return ops->ndo_get_phys_port_name(dev, name, len);
+	ret = ops->ndo_get_phys_port_name(dev, &info);
+	if (ret)
+		return ret;
+
+	switch (info.type) {
+	case NETDEV_PORT_EXTERNAL:
+		ret = snprintf(name, len, "p%d", info.external.id);
+		break;
+	case NETDEV_PORT_EXTERNAL_SPLIT:
+		ret = snprintf(name, len, "p%ds%d",
+			       info.external.id, info.external.split_id);
+		break;
+	case NETDEV_PORT_PCI_PF:
+		ret = snprintf(name, len, "pf%d", info.pci.pf_id);
+		break;
+	case NETDEV_PORT_PCI_VF:
+		ret = snprintf(name, len, "pf%dvf%d",
+			       info.pci.pf_id, info.pci.vf_id);
+		break;
+	}
+
+	if (ret > len)
+		return -EINVAL;
+
+	return 0;
 }
 EXPORT_SYMBOL(dev_get_phys_port_name);
 
net/core/rtnetlink.c +69 -0

93 lines not on this page · raw message

Signature · 1 line
2.11.0
#28 lore raw

Re: [RFC] switchdev: generate phys_port_name in the core

net/core/rtnetlink.c static size_t rtnl_xdp_size(void) · line 912

Quoted 3 lines · Jakub Kicinski
net/core/rtnetlink.c +3 -0
+static size_t rtnl_port_info_size(void)
+{
+	size_t port_info_size = nla_total_size(0) + /* nest IFLA_PORT_INFO */
				nla_total_size(4) + /* TYPE */
Quoted 6 lines
net/core/rtnetlink.c +6 -0
+				nla_total_size(4) + /* EXTERNAL_ID or PF_ID */
+				nla_total_size(4);  /* SPLIT_ID or VF_ID*/
+
+	return port_info_size;
+}
+
#29 lore raw

Re: [RFC] switchdev: generate phys_port_name in the core

In reply to Jakub Kicinski
Quoted 10 lines · Fri, Jul 28, 2017 at 04:31:22AM CEST, [email protected] wrote:
Quoted 8 lines · Or Gerlitz
Quoted 6 lines

want to add port splitting support, for example, reporting the name on physical ports will become more of a necessity.

If we adopt Jiri's suggestion of returning structured data it will be very easy to give user space type and indexes separately, but we should probably still return the string for backwards compatibility.

I am not still clear how the structured data would look like

Quoted 7 lines

I decided to just quickly write the code, that should be easier to understand. We can probably leave out the netlink part of the API if there is no need for it right now, but that's what I ment by returning the information in a more structured way.

Tested-by nobody :)
Suggested-by Jiri (if I understood correctly)

Yes, you did :) Couple of nits inlined.

Quoted 16 lines

---

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c |  8 ++-
drivers/net/ethernet/mellanox/mlxsw/switchx2.c   | 10 ++--
drivers/net/ethernet/netronome/nfp/nfp_port.c    | 26 ++++-----
drivers/net/ethernet/netronome/nfp/nfp_port.h    |  4 +-
include/linux/netdevice.h                        | 18 ++++++-
include/uapi/linux/if_link.h                     | 16 ++++++
net/core/dev.c                                   | 31 +++++++++--
net/core/rtnetlink.c                             | 69 ++++++++++++++++++++++++
8 files changed, 153 insertions(+), 29 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +0 -0
index 45e60be9c277..7a71291b8ec3 100644

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c static int mlx5e_rep_close(struct net_device *dev) · line 640

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -1
@@ -637,16 +637,14 @@ static int mlx5e_rep_close(struct net_device *dev)
 }
 
 static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
+					struct netdev_port_info *info)

Either we rename ndo to something like ndo_get_port_info or you rename the struct to netdev_port_name_info. These 2 should be in sync

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c static int mlx5e_rep_close(struct net_device *dev) · line 646

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -4
 {
 	struct mlx5e_priv *priv = netdev_priv(dev);
 	struct mlx5e_rep_priv *rpriv = priv->ppriv;
 	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	int ret;
 
-	ret = snprintf(buf, len, "%d", rep->vport - 1);
-	if (ret >= len)
-		return -EOPNOTSUPP;
+	info->type = NETDEV_PORT_PCI_VF;

NETDEV_PORT_TYPE_PCI_VF
or
NETDEV_PORT_NAME_TYPE_PCI_VF
depends on the option you chose above.

Quoted 104 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -0
+	info->pci.vf_id = rep->vport - 1;
 
 	return 0;
 }
drivers/net/ethernet/mellanox/mlxsw/switchx2.c +4 -6
index 3b0f72455681..383b8b5f41cf 100644
@@ -413,15 +413,13 @@ mlxsw_sx_port_get_stats64(struct net_device *dev,
 	stats->tx_dropped	= tx_dropped;
 }
 
-static int mlxsw_sx_port_get_phys_port_name(struct net_device *dev, char *name,
-					    size_t len)
+static int mlxsw_sx_port_get_phys_port_name(struct net_device *dev,
+					    struct netdev_port_info *info)
 {
 	struct mlxsw_sx_port *mlxsw_sx_port = netdev_priv(dev);
-	int err;
 
-	err = snprintf(name, len, "p%d", mlxsw_sx_port->mapping.module + 1);
-	if (err >= len)
-		return -EINVAL;
+	info->type = NETDEV_PORT_EXTERNAL;
+	info->port.id = mlxsw_sx_port->mapping.module + 1;
 
 	return 0;
 }
drivers/net/ethernet/netronome/nfp/nfp_port.c +0 -0
index d16a7b78ba9b..8f5c37b9a79c 100644
@@ -143,11 +143,11 @@ struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port)
 }
 

int

drivers/net/ethernet/netronome/nfp/nfp_port.c +2 -1
-nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len)
+nfp_port_get_phys_port_name(struct net_device *netdev,
+			    struct netdev_port_info *info)
{
	struct nfp_eth_table_port *eth_port;
	struct nfp_port *port;
drivers/net/ethernet/netronome/nfp/nfp_port.c +0 -1
-	int n;
	port = nfp_port_from_netdev(netdev);
	if (!port)
drivers/net/ethernet/netronome/nfp/nfp_port.c +12 -10
@@ -159,25 +159,27 @@ nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len)
 		if (!eth_port)
 			return -EOPNOTSUPP;
 
-		if (!eth_port->is_split)
-			n = snprintf(name, len, "p%d", eth_port->label_port);
-		else
-			n = snprintf(name, len, "p%ds%d", eth_port->label_port,
-				     eth_port->label_subport);
+		info->type = NETDEV_PORT_EXTERNAL;
+		info->external.id = eth_port->label_port;
+
+		if (eth_port->is_split) {
+			info->type = NETDEV_PORT_EXTERNAL_SPLIT;
+			info->external.split_id = eth_port->label_subport;
+		}
 		break;
 	case NFP_PORT_PF_PORT:
-		n = snprintf(name, len, "pf%d", port->pf_id);
+		info->type = NETDEV_PORT_PCI_PF;
+		info->pci.pf_id = port->pf_id;
 		break;
 	case NFP_PORT_VF_PORT:
-		n = snprintf(name, len, "pf%dvf%d", port->pf_id, port->vf_id);
+		info->type = NETDEV_PORT_PCI_VF;
+		info->pci.pf_id = port->pf_id;
+		info->pci.vf_id = port->vf_id;
 		break;
 	default:
 		return -EOPNOTSUPP;
 	}
 
-	if (n >= len)
-		return -EINVAL;
-
 	return 0;
 }
 
drivers/net/ethernet/netronome/nfp/nfp_port.h +2 -2
index 56c76926c82a..03b8746feb29 100644
@@ -118,8 +118,8 @@ nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id);
 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port);
 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port);
 
-int
-nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len);
+int nfp_port_get_phys_port_name(struct net_device *netdev,
+				struct netdev_port_info *info);
 int nfp_port_configure(struct net_device *netdev, bool configed);
 

struct nfp_port *

include/linux/netdevice.h +0 -0
index 3a3cdc1b1f31..0a055df701ef 100644

include/linux/netdevice.h struct xfrmdev_ops { · line 849

Quoted 5 lines
include/linux/netdevice.h +2 -0
@@ -845,6 +845,22 @@ struct xfrmdev_ops {
 };
 #endif
 
+struct netdev_port_info {
+	int type;

enum please

Quoted 39 lines
include/linux/netdevice.h +15 -1
+
+	union {
+		struct {
+			u32 id;
+			u32 split_id;
+		} external;
+
+		struct {
+			u32 pf_id;
+			u32 vf_id;
+		} pci;
+	};
+};
+
 /*
 * This structure defines the management hooks for network devices.
 * The following hooks can be defined; unless noted otherwise, they are
@@ -1306,7 +1322,7 @@ struct net_device_ops {
 	int			(*ndo_get_phys_port_id)(struct net_device *dev,
 							struct netdev_phys_item_id *ppid);
 	int			(*ndo_get_phys_port_name)(struct net_device *dev,
-							  char *name, size_t len);
+							  struct netdev_port_info *info);
 	void			(*ndo_udp_tunnel_add)(struct net_device *dev,
 						      struct udp_tunnel_info *ti);
 	void			(*ndo_udp_tunnel_del)(struct net_device *dev,
include/uapi/linux/if_link.h +1 -0
index 8d062c58d5cb..e00ff0333e3f 100644
@@ -158,6 +158,7 @@ enum {
 	IFLA_PAD,
 	IFLA_XDP,
 	IFLA_EVENT,
+	IFLA_PORT_INFO,
 	__IFLA_MAX
 };
 

include/uapi/linux/if_link.h enum { · line 934

Quoted 7 lines
include/uapi/linux/if_link.h +4 -0
@@ -927,4 +928,19 @@ enum {
 	IFLA_EVENT_BONDING_OPTIONS,	/* change in bonding options */
 };
 
+enum {
+	NETDEV_PORT_EXTERNAL,
+	NETDEV_PORT_EXTERNAL_SPLIT,
+	NETDEV_PORT_PCI_PF,

Isn't PF also EXTERNAL? Cant VF be split? What I'm getting at, shoudn't these be flags?

Quoted 3 lines
include/uapi/linux/if_link.h +3 -0
+	NETDEV_PORT_PCI_VF,
+};
+
#30 lore raw

Re: [RFC] switchdev: generate phys_port_name in the core

Quoted 40 lines · Fri, Jul 28, 2017 at 07:35:07AM CEST, [email protected] wrote:
Quoted 10 lines · Fri, Jul 28, 2017 at 04:31:22AM CEST, [email protected] wrote:
Quoted 8 lines · Or Gerlitz
Quoted 6 lines

want to add port splitting support, for example, reporting the name on physical ports will become more of a necessity.

If we adopt Jiri's suggestion of returning structured data it will be very easy to give user space type and indexes separately, but we should probably still return the string for backwards compatibility.

I am not still clear how the structured data would look like

Quoted 7 lines

I decided to just quickly write the code, that should be easier to understand. We can probably leave out the netlink part of the API if there is no need for it right now, but that's what I ment by returning the information in a more structured way.

Tested-by nobody :)
Suggested-by Jiri (if I understood correctly)

Yes, you did :) Couple of nits inlined.

Quoted 18 lines

---

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c |  8 ++-
drivers/net/ethernet/mellanox/mlxsw/switchx2.c   | 10 ++--
drivers/net/ethernet/netronome/nfp/nfp_port.c    | 26 ++++-----
drivers/net/ethernet/netronome/nfp/nfp_port.h    |  4 +-
include/linux/netdevice.h                        | 18 ++++++-
include/uapi/linux/if_link.h                     | 16 ++++++
net/core/dev.c                                   | 31 +++++++++--
net/core/rtnetlink.c                             | 69 ++++++++++++++++++++++++
8 files changed, 153 insertions(+), 29 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +0 -0
index 45e60be9c277..7a71291b8ec3 100644
@@ -637,16 +637,14 @@ static int mlx5e_rep_close(struct net_device *dev)
 }
 
Quoted 6 lines

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c static int mlx5e_rep_close(struct net_device *dev) · line 640

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -1
 static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
+					struct netdev_port_info *info)

Either we rename ndo to something like ndo_get_port_info or you rename the struct to netdev_port_name_info. These 2 should be in sync

As this is strictly related to port name, I think it should be:
struct netdev_phys_port_name_info

And the rest named in-sync with this

#32 lore raw

Re: [RFC] switchdev: generate phys_port_name in the core

In reply to Jiri Pirko
Quoted 7 lines · Jiri Pirko

include/uapi/linux/if_link.h enum { · line 934

Quoted 4 lines
include/uapi/linux/if_link.h +4 -0
+enum {
+	NETDEV_PORT_EXTERNAL,
+	NETDEV_PORT_EXTERNAL_SPLIT,
+	NETDEV_PORT_PCI_PF,  

Isn't PF also EXTERNAL? Cant VF be split? What I'm getting at, shoudn't these be flags?

By external PF do you mean not connected to the current host? Yes we could make a flag like that. Right now I have picked "external" to avoid too specific names like MAC/PHY/Ethernet... There could be a MAC-to-MAC connection for instance, so no PHY involved. Should we go with NETDEV_PORT_ETH?

I will make SPLIT into a flag.

#31 lore raw

Re: [RFC] switchdev: generate phys_port_name in the core

In reply to Jiri Pirko
Quoted 48 lines · Jiri Pirko
Quoted 40 lines · Fri, Jul 28, 2017 at 07:35:07AM CEST, [email protected] wrote:
Quoted 10 lines · Fri, Jul 28, 2017 at 04:31:22AM CEST, [email protected] wrote:
Quoted 8 lines · Or Gerlitz
Quoted 6 lines

want to add port splitting support, for example, reporting the name on physical ports will become more of a necessity.

If we adopt Jiri's suggestion of returning structured data it will be very easy to give user space type and indexes separately, but we should probably still return the string for backwards compatibility.

I am not still clear how the structured data would look like

Quoted 7 lines

I decided to just quickly write the code, that should be easier to understand. We can probably leave out the netlink part of the API if there is no need for it right now, but that's what I ment by returning the information in a more structured way.

Tested-by nobody :)
Suggested-by Jiri (if I understood correctly)

Yes, you did :) Couple of nits inlined.

Quoted 18 lines

---

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c |  8 ++-
drivers/net/ethernet/mellanox/mlxsw/switchx2.c   | 10 ++--
drivers/net/ethernet/netronome/nfp/nfp_port.c    | 26 ++++-----
drivers/net/ethernet/netronome/nfp/nfp_port.h    |  4 +-
include/linux/netdevice.h                        | 18 ++++++-
include/uapi/linux/if_link.h                     | 16 ++++++
net/core/dev.c                                   | 31 +++++++++--
net/core/rtnetlink.c                             | 69 ++++++++++++++++++++++++
8 files changed, 153 insertions(+), 29 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +0 -0
index 45e60be9c277..7a71291b8ec3 100644
@@ -637,16 +637,14 @@ static int mlx5e_rep_close(struct net_device *dev)
 }
 
Quoted 6 lines

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c static int mlx5e_rep_close(struct net_device *dev) · line 640

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -1
 static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
+					struct netdev_port_info *info)  

Either we rename ndo to something like ndo_get_port_info or you rename the struct to netdev_port_name_info. These 2 should be in sync

Quoted 4 lines

As this is strictly related to port name, I think it should be:
struct netdev_phys_port_name_info

And the rest named in-sync with this

Hm.. Since we would return the type and IDs via netlink, I was actually leaning towards ndo_get_port_info. "Name" somehow implies a string in my mind. Perhaps the "info" part is where I went wrong, could we go with netdev_port_label? Or netdev_port_ident? I would also prefer to avoid the phys in name, since it doesn't sit well with PFs vs VFs.

Ah, naming things...

#33 lore raw

Re: [RFC] switchdev: generate phys_port_name in the core

In reply to Jakub Kicinski
Quoted 17 lines · Jakub Kicinski
Quoted 8 lines · Or Gerlitz
Quoted 6 lines

want to add port splitting support, for example, reporting the name on physical ports will become more of a necessity.

If we adopt Jiri's suggestion of returning structured data it will be very easy to give user space type and indexes separately, but we should probably still return the string for backwards compatibility.

I am not still clear how the structured data would look like

I decided to just quickly write the code, that should be easier to understand. We can probably leave out the netlink part of the API if there is no need for it right now, but that's what I ment by returning the information in a more structured way.

Tested-by nobody :)
Suggested-by Jiri (if I understood correctly)
Quoted 9 lines
---
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c |  8 ++-
 drivers/net/ethernet/mellanox/mlxsw/switchx2.c   | 10 ++--
 drivers/net/ethernet/netronome/nfp/nfp_port.c    | 26 ++++-----
 drivers/net/ethernet/netronome/nfp/nfp_port.h    |  4 +-
 include/linux/netdevice.h                        | 18 ++++++-
 include/uapi/linux/if_link.h                     | 16 ++++++
 net/core/dev.c                                   | 31 +++++++++--
 net/core/rtnetlink.c                             | 69 ++++++++++++++++++++++++

Hi Jakub

Don't forget net/dsa/slave.c when you go from RFC to a real patch for submission.

Andrew