Skip to content

Commit 745d8ae

Browse files
Eugenia Emantayevdavem330
authored andcommitted
net/mlx4: Spoofcheck and zero MAC can't coexist
Spoofcheck can't be enabled if VF MAC is zero. Vice versa, can't zero MAC if spoofcheck is on. Fixes: 8f7ba3c ('net/mlx4: Add set VF mac address support') Signed-off-by: Eugenia Emantayev <eugenia@mellanox.com> Signed-off-by: Tariq Toukan <tariqt@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 423b3ae commit 745d8ae

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

drivers/net/ethernet/mellanox/mlx4/cmd.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/semaphore.h>
4444
#include <rdma/ib_smi.h>
4545
#include <linux/delay.h>
46+
#include <linux/etherdevice.h>
4647

4748
#include <asm/io.h>
4849

@@ -2955,7 +2956,7 @@ static bool mlx4_valid_vf_state_change(struct mlx4_dev *dev, int port,
29552956
return false;
29562957
}
29572958

2958-
int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u64 mac)
2959+
int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u8 *mac)
29592960
{
29602961
struct mlx4_priv *priv = mlx4_priv(dev);
29612962
struct mlx4_vport_state *s_info;
@@ -2964,13 +2965,22 @@ int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u64 mac)
29642965
if (!mlx4_is_master(dev))
29652966
return -EPROTONOSUPPORT;
29662967

2968+
if (is_multicast_ether_addr(mac))
2969+
return -EINVAL;
2970+
29672971
slave = mlx4_get_slave_indx(dev, vf);
29682972
if (slave < 0)
29692973
return -EINVAL;
29702974

29712975
port = mlx4_slaves_closest_port(dev, slave, port);
29722976
s_info = &priv->mfunc.master.vf_admin[slave].vport[port];
2973-
s_info->mac = mac;
2977+
2978+
if (s_info->spoofchk && is_zero_ether_addr(mac)) {
2979+
mlx4_info(dev, "MAC invalidation is not allowed when spoofchk is on\n");
2980+
return -EPERM;
2981+
}
2982+
2983+
s_info->mac = mlx4_mac_to_u64(mac);
29742984
mlx4_info(dev, "default mac on vf %d port %d to %llX will take effect only after vf restart\n",
29752985
vf, port, s_info->mac);
29762986
return 0;
@@ -3143,6 +3153,7 @@ int mlx4_set_vf_spoofchk(struct mlx4_dev *dev, int port, int vf, bool setting)
31433153
struct mlx4_priv *priv = mlx4_priv(dev);
31443154
struct mlx4_vport_state *s_info;
31453155
int slave;
3156+
u8 mac[ETH_ALEN];
31463157

31473158
if ((!mlx4_is_master(dev)) ||
31483159
!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FSM))
@@ -3154,6 +3165,13 @@ int mlx4_set_vf_spoofchk(struct mlx4_dev *dev, int port, int vf, bool setting)
31543165

31553166
port = mlx4_slaves_closest_port(dev, slave, port);
31563167
s_info = &priv->mfunc.master.vf_admin[slave].vport[port];
3168+
3169+
mlx4_u64_to_mac(mac, s_info->mac);
3170+
if (setting && !is_valid_ether_addr(mac)) {
3171+
mlx4_info(dev, "Illegal MAC with spoofchk\n");
3172+
return -EPERM;
3173+
}
3174+
31573175
s_info->spoofchk = setting;
31583176

31593177
return 0;

drivers/net/ethernet/mellanox/mlx4/en_netdev.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,12 +2485,8 @@ static int mlx4_en_set_vf_mac(struct net_device *dev, int queue, u8 *mac)
24852485
{
24862486
struct mlx4_en_priv *en_priv = netdev_priv(dev);
24872487
struct mlx4_en_dev *mdev = en_priv->mdev;
2488-
u64 mac_u64 = mlx4_mac_to_u64(mac);
24892488

2490-
if (is_multicast_ether_addr(mac))
2491-
return -EINVAL;
2492-
2493-
return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac_u64);
2489+
return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac);
24942490
}
24952491

24962492
static int mlx4_en_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos,

include/linux/mlx4/cmd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ int mlx4_get_counter_stats(struct mlx4_dev *dev, int counter_index,
308308
int mlx4_get_vf_stats(struct mlx4_dev *dev, int port, int vf_idx,
309309
struct ifla_vf_stats *vf_stats);
310310
u32 mlx4_comm_get_version(void);
311-
int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u64 mac);
311+
int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u8 *mac);
312312
int mlx4_set_vf_vlan(struct mlx4_dev *dev, int port, int vf, u16 vlan,
313313
u8 qos, __be16 proto);
314314
int mlx4_set_vf_rate(struct mlx4_dev *dev, int port, int vf, int min_tx_rate,

include/linux/mlx4/driver.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,14 @@ static inline u64 mlx4_mac_to_u64(u8 *addr)
104104
return mac;
105105
}
106106

107+
static inline void mlx4_u64_to_mac(u8 *addr, u64 mac)
108+
{
109+
int i;
110+
111+
for (i = ETH_ALEN; i > 0; i--) {
112+
addr[i - 1] = mac && 0xFF;
113+
mac >>= 8;
114+
}
115+
}
116+
107117
#endif /* MLX4_DRIVER_H */

0 commit comments

Comments
 (0)