[3/3] net/nfp: fix the reconfigure logic of set mac address
Checks
Commit Message
If the reconfigure API exit abnormally, the value in the config bar
will not same with the value stored in the data structure.
Fix this by add a local variable to hold the temporary value and the
logic of store it when no error happen.
Fixes: 2fe669f4bcd2 ("net/nfp: support MAC address change")
Cc: stable@dpdk.org
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
drivers/net/nfp/nfp_net_common.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
@@ -362,8 +362,8 @@ int
nfp_net_set_mac_addr(struct rte_eth_dev *dev,
struct rte_ether_addr *mac_addr)
{
- uint32_t ctrl;
uint32_t update;
+ uint32_t new_ctrl;
struct nfp_hw *hw;
struct nfp_net_hw *net_hw;
@@ -379,17 +379,19 @@ nfp_net_set_mac_addr(struct rte_eth_dev *dev,
nfp_write_mac(hw, (uint8_t *)mac_addr);
update = NFP_NET_CFG_UPDATE_MACADDR;
- ctrl = hw->ctrl;
+ new_ctrl = hw->ctrl;
if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) != 0 &&
(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR) != 0)
- ctrl |= NFP_NET_CFG_CTRL_LIVE_ADDR;
+ new_ctrl |= NFP_NET_CFG_CTRL_LIVE_ADDR;
/* Signal the NIC about the change */
- if (nfp_reconfig(hw, ctrl, update) != 0) {
+ if (nfp_reconfig(hw, new_ctrl, update) != 0) {
PMD_DRV_LOG(ERR, "MAC address update failed");
return -EIO;
}
+ hw->ctrl = new_ctrl;
+
return 0;
}