Skip to contentSkip to conversation

octeon_ep: add ndo ops for VFs in PF driver

PATCH Superseded Shinas Rasheed 4 participants 5 messages Nov 12, 2024 – Nov 16, 2024

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 octeon_ep: add ndo ops for VFs in PF driver

These APIs are needed to support applications that use netlink to get VF information from a PF driver.

---
V2:
- Corrected typos, and removed not supported ndo_set_vf* hooks

V1: https://lore.kernel.org/all/[email protected]/

 .../ethernet/marvell/octeon_ep/octep_main.c   | 41 +++++++++++++++++++
 .../ethernet/marvell/octeon_ep/octep_main.h   |  1 +
 .../marvell/octeon_ep/octep_pfvf_mbox.c       | 22 +++++++++-
 .../marvell/octeon_ep/octep_pfvf_mbox.h       |  3 ++
 4 files changed, 65 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +41 -0
index 549436efc204..6c1689a98f20 100644
@@ -1137,6 +1137,44 @@ static int octep_set_features(struct net_device *dev, netdev_features_t features
 	return err;
 }
 
+static int octep_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivi)
+{
+	struct octep_device *oct = netdev_priv(dev);
+
+	ivi->vf = vf;
+	ether_addr_copy(ivi->mac, oct->vf_info[vf].mac_addr);
+	ivi->vlan = 0;
+	ivi->qos = 0;
+	ivi->spoofchk = 0;
+	ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
+	ivi->trusted = true;
+	ivi->max_tx_rate = 10000;
+	ivi->min_tx_rate = 0;
+
+	return 0;
+}
+
+static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
+{
+	struct octep_device *oct = netdev_priv(dev);
+	int err;
+
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&oct->pdev->dev, "Invalid  MAC Address %pM\n", mac);
+		return -EADDRNOTAVAIL;
+	}
+
+	dev_dbg(&oct->pdev->dev, "set vf-%d mac to %pM\n", vf, mac);
+	ether_addr_copy(oct->vf_info[vf].mac_addr, mac);
+	oct->vf_info[vf].flags |=  OCTEON_PFVF_FLAG_MAC_SET_BY_PF;
+
+	err = octep_ctrl_net_set_mac_addr(oct, vf, mac, true);
+	if (err)
+		dev_err(&oct->pdev->dev, "Set VF%d MAC address failed via host control Mbox\n", vf);
+
+	return err;
+}
+
 static const struct net_device_ops octep_netdev_ops = {
 	.ndo_open                = octep_open,
 	.ndo_stop                = octep_stop,
@@ -1146,6 +1184,9 @@ static const struct net_device_ops octep_netdev_ops = {
 	.ndo_set_mac_address     = octep_set_mac,
 	.ndo_change_mtu          = octep_change_mtu,
 	.ndo_set_features        = octep_set_features,
+	/* for VFs */
+	.ndo_get_vf_config       = octep_get_vf_config,
+	.ndo_set_vf_mac          = octep_set_vf_mac
 };
 
 /**
drivers/net/ethernet/marvell/octeon_ep/octep_main.h +1 -0
index fee59e0e0138..3b56916af468 100644
@@ -220,6 +220,7 @@ struct octep_iface_link_info {
 /* The Octeon VF device specific info data structure.*/
 struct octep_pfvf_info {
 	u8 mac_addr[ETH_ALEN];
+	u32 flags;
 	u32 mbox_version;
 };
 
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c +20 -2
index e6eb98d70f3c..26db2d34d1c0 100644
@@ -156,12 +156,23 @@ static void octep_pfvf_set_mac_addr(struct octep_device *oct,  u32 vf_id,
 {
 	int err;
 
+	if (oct->vf_info[vf_id].flags & OCTEON_PFVF_FLAG_MAC_SET_BY_PF) {
+		dev_err(&oct->pdev->dev,
+			"VF%d attempted to override administrative set MAC address\n",
+			vf_id);
+		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
+		return;
+	}
+
 	err = octep_ctrl_net_set_mac_addr(oct, vf_id, cmd.s_set_mac.mac_addr, true);
 	if (err) {
 		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
-		dev_err(&oct->pdev->dev, "Set VF MAC address failed via host control Mbox\n");
+		dev_err(&oct->pdev->dev, "Set VF%d MAC address failed via host control Mbox\n",
+			vf_id);
 		return;
 	}
+
+	ether_addr_copy(oct->vf_info[vf_id].mac_addr, cmd.s_set_mac.mac_addr);
 	rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
 }
 
@@ -171,10 +182,17 @@ static void octep_pfvf_get_mac_addr(struct octep_device *oct,  u32 vf_id,
 {
 	int err;
 
+	if (oct->vf_info[vf_id].flags & OCTEON_PFVF_FLAG_MAC_SET_BY_PF) {
+		dev_dbg(&oct->pdev->dev, "VF%d MAC address set by PF\n", vf_id);
+		ether_addr_copy(rsp->s_set_mac.mac_addr, oct->vf_info[vf_id].mac_addr);
+		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
+		return;
+	}
 	err = octep_ctrl_net_get_mac_addr(oct, vf_id, rsp->s_set_mac.mac_addr);
 	if (err) {
 		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
-		dev_err(&oct->pdev->dev, "Get VF MAC address failed via host control Mbox\n");
+		dev_err(&oct->pdev->dev, "Get VF%d MAC address failed via host control Mbox\n",
+			vf_id);
 		return;
 	}
 	rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h +3 -0
index 0dc6eead292a..339977c7131a 100644
@@ -23,6 +23,9 @@ enum octep_pfvf_mbox_version {
 
 #define OCTEP_PFVF_MBOX_VERSION_CURRENT	OCTEP_PFVF_MBOX_VERSION_V2
 
+/* VF flags */
+#define OCTEON_PFVF_FLAG_MAC_SET_BY_PF  BIT_ULL(0) /* PF has set VF MAC address */
+
 enum octep_pfvf_mbox_opcode {
 	OCTEP_PFVF_MBOX_CMD_VERSION,
 	OCTEP_PFVF_MBOX_CMD_SET_MTU,
Signature · 1 line
2.25.1
maintainer
#3 lore raw
In reply to Shinas Rasheed
Quoted 6 lines · On Tue, 12 Nov 2024 10:54:31 -0800 Shinas Rasheed wrote:

These APIs are needed to support applications that use netlink to get VF information from a PF driver.

+static int octep_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivi)

Please don't go over 80 chars for no good reason.
use checkpatch with --strict --max-line-length=80

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1147

Quoted 7 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +7 -0
+{
+	struct octep_device *oct = netdev_priv(dev);
+
+	ivi->vf = vf;
+	ether_addr_copy(ivi->mac, oct->vf_info[vf].mac_addr);
+	ivi->vlan = 0;
+	ivi->qos = 0;

no need to clear these fields

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1150

Quoted 3 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +3 -0
+	ivi->spoofchk = 0;
+	ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
+	ivi->trusted = true;

so you set spoofchk to 0 and trusted to true, indicating no enforcement [1]

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1152

Quoted 2 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -0
+	ivi->max_tx_rate = 10000;
+	ivi->min_tx_rate = 0;

Why are you setting max rate to a fixed value?

Quoted 7 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +7 -0
+
+	return 0;
+}
+
+static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
+{
+	struct octep_device *oct = netdev_priv(dev);

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1169

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +10 -0
+	int err;
+
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&oct->pdev->dev, "Invalid  MAC Address %pM\n", mac);
+		return -EADDRNOTAVAIL;
+	}
+
+	dev_dbg(&oct->pdev->dev, "set vf-%d mac to %pM\n", vf, mac);
+	ether_addr_copy(oct->vf_info[vf].mac_addr, mac);
+	oct->vf_info[vf].flags |=  OCTEON_PFVF_FLAG_MAC_SET_BY_PF;

double space

Quoted 12 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +8 -0
+
+	err = octep_ctrl_net_set_mac_addr(oct, vf, mac, true);
+	if (err)
+		dev_err(&oct->pdev->dev, "Set VF%d MAC address failed via host control Mbox\n", vf);
+
+	return err;
+}
+
 static const struct net_device_ops octep_netdev_ops = {
 	.ndo_open                = octep_open,
 	.ndo_stop                = octep_stop,

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static const struct net_device_ops octep_netdev_ops = { · line 1187

Quoted 4 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
@@ -1146,6 +1184,9 @@ static const struct net_device_ops octep_netdev_ops = {
 	.ndo_set_mac_address     = octep_set_mac,
 	.ndo_change_mtu          = octep_change_mtu,
 	.ndo_set_features        = octep_set_features,
+	/* for VFs */

what does this comment achieve?

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -0
+	.ndo_get_vf_config       = octep_get_vf_config,
+	.ndo_set_vf_mac          = octep_set_vf_mac
 };
 
 /**
drivers/net/ethernet/marvell/octeon_ep/octep_main.h +0 -0
index fee59e0e0138..3b56916af468 100644

drivers/net/ethernet/marvell/octeon_ep/octep_main.h struct octep_iface_link_info { · line 223

Quoted 4 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.h +1 -0
@@ -220,6 +220,7 @@ struct octep_iface_link_info {
 /* The Octeon VF device specific info data structure.*/
 struct octep_pfvf_info {
 	u8 mac_addr[ETH_ALEN];
+	u32 flags;

the flags are u32 [2]

Quoted 8 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.h +0 -0
 	u32 mbox_version;
 };
 
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c +0 -0
index e6eb98d70f3c..26db2d34d1c0 100644

drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c static void octep_pfvf_set_mac_addr(struct octep_device *oct, u32 vf_id, · line 165

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c +7 -0
@@ -156,12 +156,23 @@ static void octep_pfvf_set_mac_addr(struct octep_device *oct,  u32 vf_id,
 {
 	int err;
 
+	if (oct->vf_info[vf_id].flags & OCTEON_PFVF_FLAG_MAC_SET_BY_PF) {
+		dev_err(&oct->pdev->dev,
+			"VF%d attempted to override administrative set MAC address\n",
+			vf_id);
+		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
+		return;
+	}

[1] and yet you reject VF side changes. So is there enforcement or not? :S

Quoted 37 lines
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c +12 -2
 	err = octep_ctrl_net_set_mac_addr(oct, vf_id, cmd.s_set_mac.mac_addr, true);
 	if (err) {
 		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
-		dev_err(&oct->pdev->dev, "Set VF MAC address failed via host control Mbox\n");
+		dev_err(&oct->pdev->dev, "Set VF%d MAC address failed via host control Mbox\n",
+			vf_id);
 		return;
 	}
+
+	ether_addr_copy(oct->vf_info[vf_id].mac_addr, cmd.s_set_mac.mac_addr);
 	rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
 }
 
@@ -171,10 +182,17 @@ static void octep_pfvf_get_mac_addr(struct octep_device *oct,  u32 vf_id,
 {
 	int err;
 
+	if (oct->vf_info[vf_id].flags & OCTEON_PFVF_FLAG_MAC_SET_BY_PF) {
+		dev_dbg(&oct->pdev->dev, "VF%d MAC address set by PF\n", vf_id);
+		ether_addr_copy(rsp->s_set_mac.mac_addr, oct->vf_info[vf_id].mac_addr);
+		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
+		return;
+	}
 	err = octep_ctrl_net_get_mac_addr(oct, vf_id, rsp->s_set_mac.mac_addr);
 	if (err) {
 		rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
-		dev_err(&oct->pdev->dev, "Get VF MAC address failed via host control Mbox\n");
+		dev_err(&oct->pdev->dev, "Get VF%d MAC address failed via host control Mbox\n",
+			vf_id);
 		return;
 	}
 	rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h +0 -0
index 0dc6eead292a..339977c7131a 100644

drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h enum octep_pfvf_mbox_version { · line 27

Quoted 5 lines
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h +2 -0
@@ -23,6 +23,9 @@ enum octep_pfvf_mbox_version {
 
 #define OCTEP_PFVF_MBOX_VERSION_CURRENT	OCTEP_PFVF_MBOX_VERSION_V2
 
+/* VF flags */
+#define OCTEON_PFVF_FLAG_MAC_SET_BY_PF  BIT_ULL(0) /* PF has set VF MAC address */

[2] but the bit definition uses ULL ?

Quoted 3 lines
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h +0 -0
 enum octep_pfvf_mbox_opcode {
 	OCTEP_PFVF_MBOX_CMD_VERSION,
 	OCTEP_PFVF_MBOX_CMD_SET_MTU,
Signature · 1 line
pw-bot: cr
#4 lore raw

Hi Jakub,

Quoted 12 lines · On Tue, 12 Nov 2024 10:54:31 -0800 Shinas Rasheed wrote:
Quoted 6 lines

These APIs are needed to support applications that use netlink to get VF information from a PF driver.

+static int octep_get_vf_config(struct net_device *dev, int vf, struct

ifla_vf_info *ivi)

Please don't go over 80 chars for no good reason.
use checkpatch with --strict --max-line-length=80

ACK

Quoted 10 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1147

Quoted 7 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +7 -0
+{
+	struct octep_device *oct = netdev_priv(dev);
+
+	ivi->vf = vf;
+	ether_addr_copy(ivi->mac, oct->vf_info[vf].mac_addr);
+	ivi->vlan = 0;
+	ivi->qos = 0;

no need to clear these fields

ACK

Quoted 7 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1150

Quoted 3 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +3 -0
+	ivi->spoofchk = 0;
+	ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
+	ivi->trusted = true;

so you set spoofchk to 0 and trusted to true, indicating no enforcement [1]

Will fix this in next patch

Quoted 5 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1152

Quoted 2 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -0
+	ivi->max_tx_rate = 10000;
+	ivi->min_tx_rate = 0;

Why are you setting max rate to a fixed value?

This is the max tx rate we offer for VFs

Quoted 12 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features

Quoted 11 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +11 -0
+
+	return 0;
+}
+
+static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
+{
+	struct octep_device *oct = netdev_priv(dev);
+	int err;
+
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&oct->pdev->dev, "Invalid  MAC Address %pM\n",

mac);

Quoted 9 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1169

Quoted 6 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +6 -0
+		return -EADDRNOTAVAIL;
+	}
+
+	dev_dbg(&oct->pdev->dev, "set vf-%d mac to %pM\n", vf, mac);
+	ether_addr_copy(oct->vf_info[vf].mac_addr, mac);
+	oct->vf_info[vf].flags |=  OCTEON_PFVF_FLAG_MAC_SET_BY_PF;

double space

ACK

Quoted 14 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features

Quoted 4 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +4 -0
+
+	err = octep_ctrl_net_set_mac_addr(oct, vf, mac, true);
+	if (err)
+		dev_err(&oct->pdev->dev, "Set VF%d MAC address failed via

host control Mbox\n", vf);

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static const struct net_device_ops

Quoted 8 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +4 -0
+
+	return err;
+}
+
 static const struct net_device_ops octep_netdev_ops = {
 	.ndo_open                = octep_open,
 	.ndo_stop                = octep_stop,
@@ -1146,6 +1184,9 @@ static const struct net_device_ops

octep_netdev_ops = {

Quoted 7 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static const struct net_device_ops octep_netdev_ops = { · line 1187

Quoted 4 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
 	.ndo_set_mac_address     = octep_set_mac,
 	.ndo_change_mtu          = octep_change_mtu,
 	.ndo_set_features        = octep_set_features,
+	/* for VFs */

what does this comment achieve?

Will remove

Quoted 7 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h

Quoted 5 lines

index 0dc6eead292a..339977c7131a 100644

drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h +0 -0
@@ -23,6 +23,9 @@ enum octep_pfvf_mbox_version {
 
Quoted 9 lines

drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h enum octep_pfvf_mbox_version { · line 24

Quoted 1 line
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h +0 -0
 #define OCTEP_PFVF_MBOX_VERSION_CURRENT

OCTEP_PFVF_MBOX_VERSION_V2

drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h enum octep_pfvf_mbox_version { · line 26

Quoted 3 lines
drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.h +2 -0
+/* VF flags */
+#define OCTEON_PFVF_FLAG_MAC_SET_BY_PF  BIT_ULL(0) /* PF has set VF

MAC address */

[2] but the bit definition uses ULL ?

Will fix in next patch

Thanks for the comments