Skip to content

Commit 8a241ef

Browse files
shinas-marvellkuba-moo
authored andcommitted
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. Signed-off-by: Shinas Rasheed <srasheed@marvell.com> Link: https://patch.msgid.link/20241206064135.2331790-1-srasheed@marvell.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e58b477 commit 8a241ef

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

drivers/net/ethernet/marvell/octeon_ep/octep_main.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,43 @@ static int octep_set_features(struct net_device *dev, netdev_features_t features
11371137
return err;
11381138
}
11391139

1140+
static int octep_get_vf_config(struct net_device *dev, int vf,
1141+
struct ifla_vf_info *ivi)
1142+
{
1143+
struct octep_device *oct = netdev_priv(dev);
1144+
1145+
ivi->vf = vf;
1146+
ether_addr_copy(ivi->mac, oct->vf_info[vf].mac_addr);
1147+
ivi->spoofchk = true;
1148+
ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
1149+
ivi->trusted = false;
1150+
1151+
return 0;
1152+
}
1153+
1154+
static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
1155+
{
1156+
struct octep_device *oct = netdev_priv(dev);
1157+
int err;
1158+
1159+
if (!is_valid_ether_addr(mac)) {
1160+
dev_err(&oct->pdev->dev, "Invalid MAC Address %pM\n", mac);
1161+
return -EADDRNOTAVAIL;
1162+
}
1163+
1164+
dev_dbg(&oct->pdev->dev, "set vf-%d mac to %pM\n", vf, mac);
1165+
ether_addr_copy(oct->vf_info[vf].mac_addr, mac);
1166+
oct->vf_info[vf].flags |= OCTEON_PFVF_FLAG_MAC_SET_BY_PF;
1167+
1168+
err = octep_ctrl_net_set_mac_addr(oct, vf, mac, true);
1169+
if (err)
1170+
dev_err(&oct->pdev->dev,
1171+
"Set VF%d MAC address failed via host control Mbox\n",
1172+
vf);
1173+
1174+
return err;
1175+
}
1176+
11401177
static const struct net_device_ops octep_netdev_ops = {
11411178
.ndo_open = octep_open,
11421179
.ndo_stop = octep_stop,
@@ -1146,6 +1183,8 @@ static const struct net_device_ops octep_netdev_ops = {
11461183
.ndo_set_mac_address = octep_set_mac,
11471184
.ndo_change_mtu = octep_change_mtu,
11481185
.ndo_set_features = octep_set_features,
1186+
.ndo_get_vf_config = octep_get_vf_config,
1187+
.ndo_set_vf_mac = octep_set_vf_mac
11491188
};
11501189

11511190
/**

drivers/net/ethernet/marvell/octeon_ep/octep_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct octep_iface_link_info {
220220
/* The Octeon VF device specific info data structure.*/
221221
struct octep_pfvf_info {
222222
u8 mac_addr[ETH_ALEN];
223+
u32 flags;
223224
u32 mbox_version;
224225
};
225226

drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,23 @@ static void octep_pfvf_set_mac_addr(struct octep_device *oct, u32 vf_id,
156156
{
157157
int err;
158158

159+
if (oct->vf_info[vf_id].flags & OCTEON_PFVF_FLAG_MAC_SET_BY_PF) {
160+
dev_err(&oct->pdev->dev,
161+
"VF%d attempted to override administrative set MAC address\n",
162+
vf_id);
163+
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
164+
return;
165+
}
166+
159167
err = octep_ctrl_net_set_mac_addr(oct, vf_id, cmd.s_set_mac.mac_addr, true);
160168
if (err) {
161169
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
162-
dev_err(&oct->pdev->dev, "Set VF MAC address failed via host control Mbox\n");
170+
dev_err(&oct->pdev->dev, "Set VF%d MAC address failed via host control Mbox\n",
171+
vf_id);
163172
return;
164173
}
174+
175+
ether_addr_copy(oct->vf_info[vf_id].mac_addr, cmd.s_set_mac.mac_addr);
165176
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
166177
}
167178

@@ -171,10 +182,18 @@ static void octep_pfvf_get_mac_addr(struct octep_device *oct, u32 vf_id,
171182
{
172183
int err;
173184

185+
if (oct->vf_info[vf_id].flags & OCTEON_PFVF_FLAG_MAC_SET_BY_PF) {
186+
dev_dbg(&oct->pdev->dev, "VF%d MAC address set by PF\n", vf_id);
187+
ether_addr_copy(rsp->s_set_mac.mac_addr,
188+
oct->vf_info[vf_id].mac_addr);
189+
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
190+
return;
191+
}
174192
err = octep_ctrl_net_get_mac_addr(oct, vf_id, rsp->s_set_mac.mac_addr);
175193
if (err) {
176194
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
177-
dev_err(&oct->pdev->dev, "Get VF MAC address failed via host control Mbox\n");
195+
dev_err(&oct->pdev->dev, "Get VF%d MAC address failed via host control Mbox\n",
196+
vf_id);
178197
return;
179198
}
180199
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#ifndef _OCTEP_PFVF_MBOX_H_
99
#define _OCTEP_PFVF_MBOX_H_
1010

11-
/* VF flags */
12-
#define OCTEON_PFVF_FLAG_MAC_SET_BY_PF BIT_ULL(0) /* PF has set VF MAC address */
1311
#define OCTEON_SDP_16K_HW_FRS 16380UL
1412
#define OCTEON_SDP_64K_HW_FRS 65531UL
1513

@@ -23,6 +21,10 @@ enum octep_pfvf_mbox_version {
2321

2422
#define OCTEP_PFVF_MBOX_VERSION_CURRENT OCTEP_PFVF_MBOX_VERSION_V2
2523

24+
/* VF flags */
25+
/* PF has set VF MAC address */
26+
#define OCTEON_PFVF_FLAG_MAC_SET_BY_PF BIT(0)
27+
2628
enum octep_pfvf_mbox_opcode {
2729
OCTEP_PFVF_MBOX_CMD_VERSION,
2830
OCTEP_PFVF_MBOX_CMD_SET_MTU,

0 commit comments

Comments
 (0)