Skip to content

Commit 548b6b4

Browse files
shinas-marvellNipaLocal
authored and
NipaLocal
committed
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 <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 202e05d commit 548b6b4

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,45 @@ 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 = oct->vf_info[vf].trusted;
1150+
ivi->max_tx_rate = 10000;
1151+
ivi->min_tx_rate = 0;
1152+
1153+
return 0;
1154+
}
1155+
1156+
static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
1157+
{
1158+
struct octep_device *oct = netdev_priv(dev);
1159+
int err;
1160+
1161+
if (!is_valid_ether_addr(mac)) {
1162+
dev_err(&oct->pdev->dev, "Invalid MAC Address %pM\n", mac);
1163+
return -EADDRNOTAVAIL;
1164+
}
1165+
1166+
dev_dbg(&oct->pdev->dev, "set vf-%d mac to %pM\n", vf, mac);
1167+
ether_addr_copy(oct->vf_info[vf].mac_addr, mac);
1168+
oct->vf_info[vf].flags |= OCTEON_PFVF_FLAG_MAC_SET_BY_PF;
1169+
1170+
err = octep_ctrl_net_set_mac_addr(oct, vf, mac, true);
1171+
if (err)
1172+
dev_err(&oct->pdev->dev,
1173+
"Set VF%d MAC address failed via host control Mbox\n",
1174+
vf);
1175+
1176+
return err;
1177+
}
1178+
11401179
static const struct net_device_ops octep_netdev_ops = {
11411180
.ndo_open = octep_open,
11421181
.ndo_stop = octep_stop,
@@ -1146,6 +1185,8 @@ static const struct net_device_ops octep_netdev_ops = {
11461185
.ndo_set_mac_address = octep_set_mac,
11471186
.ndo_change_mtu = octep_change_mtu,
11481187
.ndo_set_features = octep_set_features,
1188+
.ndo_get_vf_config = octep_get_vf_config,
1189+
.ndo_set_vf_mac = octep_set_vf_mac
11491190
};
11501191

11511192
/**
@@ -1560,9 +1601,12 @@ static void octep_remove(struct pci_dev *pdev)
15601601
static int octep_sriov_enable(struct octep_device *oct, int num_vfs)
15611602
{
15621603
struct pci_dev *pdev = oct->pdev;
1563-
int err;
1604+
int i, err;
15641605

15651606
CFG_GET_ACTIVE_VFS(oct->conf) = num_vfs;
1607+
for (i = 0; i < num_vfs; i++)
1608+
oct->vf_info[i].trusted = false;
1609+
15661610
err = pci_enable_sriov(pdev, num_vfs);
15671611
if (err) {
15681612
dev_warn(&pdev->dev, "Failed to enable SRIOV err=%d\n", err);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ 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;
225+
bool trusted;
224226
};
225227

226228
/* The Octeon device specific private data structure.

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,24 @@ 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+
!oct->vf_info[vf_id].trusted) {
161+
dev_err(&oct->pdev->dev,
162+
"VF%d attempted to override administrative set MAC address\n",
163+
vf_id);
164+
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_NACK;
165+
return;
166+
}
167+
159168
err = octep_ctrl_net_set_mac_addr(oct, vf_id, cmd.s_set_mac.mac_addr, true);
160169
if (err) {
161170
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");
171+
dev_err(&oct->pdev->dev, "Set VF%d MAC address failed via host control Mbox\n",
172+
vf_id);
163173
return;
164174
}
175+
176+
ether_addr_copy(oct->vf_info[vf_id].mac_addr, cmd.s_set_mac.mac_addr);
165177
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
166178
}
167179

@@ -171,10 +183,18 @@ static void octep_pfvf_get_mac_addr(struct octep_device *oct, u32 vf_id,
171183
{
172184
int err;
173185

186+
if (oct->vf_info[vf_id].flags & OCTEON_PFVF_FLAG_MAC_SET_BY_PF) {
187+
dev_dbg(&oct->pdev->dev, "VF%d MAC address set by PF\n", vf_id);
188+
ether_addr_copy(rsp->s_set_mac.mac_addr,
189+
oct->vf_info[vf_id].mac_addr);
190+
rsp->s_set_mac.type = OCTEP_PFVF_MBOX_TYPE_RSP_ACK;
191+
return;
192+
}
174193
err = octep_ctrl_net_get_mac_addr(oct, vf_id, rsp->s_set_mac.mac_addr);
175194
if (err) {
176195
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");
196+
dev_err(&oct->pdev->dev, "Get VF%d MAC address failed via host control Mbox\n",
197+
vf_id);
178198
return;
179199
}
180200
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)