From: Junlong Wang <wang.junlong1@zte.com.cn>
To: stephen@networkplumber.org
Cc: dev@dpdk.org, Junlong Wang <wang.junlong1@zte.com.cn>
Subject: [PATCH v2 2/5] net/zxdh: modify some MAC config issues
Date: Tue, 17 Jun 2025 10:05:00 +0800 [thread overview]
Message-ID: <20250617020503.3554511-2-wang.junlong1@zte.com.cn> (raw)
In-Reply-To: <20250617020503.3554511-1-wang.junlong1@zte.com.cn>
[-- Attachment #1.1.1: Type: text/plain, Size: 14067 bytes --]
modify some mac config issues,
which were discovered during the testing process.
Fixes: 1c8f68b64cfc ("net/zxdh: optimize MAC operations")
Signed-off-by: Junlong Wang <wang.junlong1@zte.com.cn>
---
drivers/net/zxdh/zxdh_ethdev.c | 16 ++++++++++++
drivers/net/zxdh/zxdh_ethdev_ops.c | 34 +++++++++++++++++++-----
drivers/net/zxdh/zxdh_msg.c | 10 +++----
drivers/net/zxdh/zxdh_tables.c | 42 ++++++++++++++++--------------
4 files changed, 70 insertions(+), 32 deletions(-)
diff --git a/drivers/net/zxdh/zxdh_ethdev.c b/drivers/net/zxdh/zxdh_ethdev.c
index 80053678cb..74018821d1 100644
--- a/drivers/net/zxdh/zxdh_ethdev.c
+++ b/drivers/net/zxdh/zxdh_ethdev.c
@@ -1265,6 +1265,7 @@ static int
zxdh_mac_config(struct rte_eth_dev *eth_dev)
{
struct zxdh_hw *hw = eth_dev->data->dev_private;
+ struct zxdh_msg_info msg_info = {0};
int ret = 0;
if (hw->is_pf) {
@@ -1274,7 +1275,22 @@ zxdh_mac_config(struct rte_eth_dev *eth_dev)
PMD_DRV_LOG(ERR, "Failed to add mac: port 0x%x", hw->vport.vport);
return ret;
}
+ hw->uc_num++;
+ } else {
+ struct zxdh_mac_filter *mac_filter = &msg_info.data.mac_filter_msg;
+
+ mac_filter->filter_flag = 0xff;
+ memcpy(&mac_filter->mac, ð_dev->data->mac_addrs[0],
+ sizeof(eth_dev->data->mac_addrs[0]));
+ zxdh_msg_head_build(hw, ZXDH_MAC_ADD, &msg_info);
+ ret = zxdh_vf_send_msg_to_pf(eth_dev, &msg_info, sizeof(msg_info), NULL, 0);
+ if (ret) {
+ PMD_DRV_LOG(ERR, "Failed to send msg: msg type %d", ZXDH_MAC_ADD);
+ return ret;
+ }
+ hw->uc_num++;
}
+
return ret;
}
diff --git a/drivers/net/zxdh/zxdh_ethdev_ops.c b/drivers/net/zxdh/zxdh_ethdev_ops.c
index f8e8d26c50..c7a9dc7854 100644
--- a/drivers/net/zxdh/zxdh_ethdev_ops.c
+++ b/drivers/net/zxdh/zxdh_ethdev_ops.c
@@ -413,7 +413,10 @@ zxdh_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
struct zxdh_hw *hw = (struct zxdh_hw *)dev->data->dev_private;
struct rte_ether_addr *old_addr = &dev->data->mac_addrs[0];
struct zxdh_msg_info msg_info = {0};
- uint16_t ret = 0;
+ uint8_t zxdh_msg_reply_info[ZXDH_ST_SZ_BYTES(msg_reply_info)] = {0};
+ void *reply_body_addr = ZXDH_ADDR_OF(msg_reply_info, zxdh_msg_reply_info, reply_body);
+ void *mac_reply_msg_addr = ZXDH_ADDR_OF(msg_reply_body, reply_body_addr, mac_reply_msg);
+ int ret = 0;
if (!rte_is_valid_assigned_ether_addr(addr)) {
PMD_DRV_LOG(ERR, "mac address is invalid!");
@@ -425,7 +428,7 @@ zxdh_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
if (hw->is_pf) {
ret = zxdh_add_mac_table(hw, hw->vport.vport, addr, hw->hash_search_index, 0, 0);
if (ret) {
- if (ret == ZXDH_EEXIST_MAC_FLAG) {
+ if (ret == -EADDRINUSE) {
PMD_DRV_LOG(ERR, "pf mac add failed! mac is in used, code:%d", ret);
return -EADDRINUSE;
}
@@ -446,9 +449,11 @@ zxdh_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
mac_filter->filter_flag = ZXDH_MAC_UNFILTER;
memcpy(&mac_filter->mac, addr, sizeof(struct rte_ether_addr));
zxdh_msg_head_build(hw, ZXDH_MAC_ADD, &msg_info);
- ret = zxdh_vf_send_msg_to_pf(dev, &msg_info, sizeof(msg_info), NULL, 0);
+ ret = zxdh_vf_send_msg_to_pf(dev, &msg_info, sizeof(msg_info),
+ zxdh_msg_reply_info, ZXDH_ST_SZ_BYTES(msg_reply_info));
if (ret) {
- if (ret == ZXDH_EEXIST_MAC_FLAG) {
+ uint8_t flag = ZXDH_GET(mac_reply_msg, mac_reply_msg_addr, mac_flag);
+ if (flag == ZXDH_EEXIST_MAC_FLAG) {
PMD_DRV_LOG(ERR, "pf mac add failed! mac is in used, code:%d", ret);
return -EADDRINUSE;
}
@@ -482,7 +487,11 @@ zxdh_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
{
struct zxdh_hw *hw = dev->data->dev_private;
struct zxdh_msg_info msg_info = {0};
- uint16_t i, ret;
+ uint8_t zxdh_msg_reply_info[ZXDH_ST_SZ_BYTES(msg_reply_info)] = {0};
+ void *reply_body_addr = ZXDH_ADDR_OF(msg_reply_info, zxdh_msg_reply_info, reply_body);
+ void *mac_reply_msg_addr = ZXDH_ADDR_OF(msg_reply_body, reply_body_addr, mac_reply_msg);
+ uint16_t i;
+ int ret;
if (index >= ZXDH_MAX_MAC_ADDRS) {
PMD_DRV_LOG(ERR, "Add mac index (%u) is out of range", index);
@@ -503,6 +512,10 @@ zxdh_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
ret = zxdh_add_mac_table(hw, hw->vport.vport,
mac_addr, hw->hash_search_index, 0, 0);
if (ret) {
+ if (ret == -EADDRINUSE) {
+ PMD_DRV_LOG(ERR, "pf mac add failed mac is in used");
+ return -EADDRINUSE;
+ }
PMD_DRV_LOG(ERR, "mac_addr_add failed, code:%d", ret);
return ret;
}
@@ -536,9 +549,16 @@ zxdh_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
zxdh_msg_head_build(hw, ZXDH_MAC_ADD, &msg_info);
if (rte_is_unicast_ether_addr(mac_addr)) {
if (hw->uc_num < ZXDH_MAX_UC_MAC_ADDRS) {
- ret = zxdh_vf_send_msg_to_pf(dev, &msg_info,
- sizeof(msg_info), NULL, 0);
+ ret = zxdh_vf_send_msg_to_pf(dev, &msg_info, sizeof(msg_info),
+ zxdh_msg_reply_info,
+ ZXDH_ST_SZ_BYTES(msg_reply_info));
if (ret) {
+ flag = ZXDH_GET(mac_reply_msg,
+ mac_reply_msg_addr, mac_flag);
+ if (flag == ZXDH_EEXIST_MAC_FLAG) {
+ PMD_DRV_LOG(ERR, "pf mac add failed mac is in used");
+ return -EADDRINUSE;
+ }
PMD_DRV_LOG(ERR, "Failed to send msg: port 0x%x msg type %d",
hw->vport.vport, ZXDH_MAC_ADD);
return ret;
diff --git a/drivers/net/zxdh/zxdh_msg.c b/drivers/net/zxdh/zxdh_msg.c
index 02ecd93b12..452c7ab2e3 100644
--- a/drivers/net/zxdh/zxdh_msg.c
+++ b/drivers/net/zxdh/zxdh_msg.c
@@ -1349,11 +1349,11 @@ zxdh_add_vf_mac_table(struct zxdh_hw *hw, uint16_t vport, void *cfg_data,
union zxdh_virport_num port = {0};
struct zxdh_mac_filter *mac_filter = (struct zxdh_mac_filter *)cfg_data;
struct rte_ether_addr *addr = &mac_filter->mac;
- int i = 0, ret = 0;
- uint16_t vf_id = port.vfid;
- port.vport = vport;
void *reply_data_addr = ZXDH_ADDR_OF(msg_reply_body, reply_body, reply_data);
void *mac_reply_msg_addr = ZXDH_ADDR_OF(msg_reply_body, reply_body, mac_reply_msg);
+ port.vport = vport;
+ uint16_t vf_id = port.vfid;
+ int i = 0, ret = 0;
for (i = 0; i < ZXDH_MAX_MAC_ADDRS; i++)
if (rte_is_same_ether_addr(&hw->vfinfo[vf_id].vf_mac[i], addr))
@@ -1396,12 +1396,12 @@ static int
zxdh_del_vf_mac_table(struct zxdh_hw *hw, uint16_t vport, void *cfg_data,
void *res_info, uint16_t *res_len)
{
- int ret, i = 0;
struct zxdh_mac_filter *mac_filter = (struct zxdh_mac_filter *)cfg_data;
union zxdh_virport_num port = (union zxdh_virport_num)vport;
char str[ZXDH_MSG_REPLY_BODY_MAX_LEN] = "del mac";
- uint16_t vf_id = port.vfid;
void *reply_data_addr = ZXDH_ADDR_OF(msg_reply_body, res_info, reply_data);
+ uint16_t vf_id = port.vfid;
+ int ret, i = 0;
PMD_DRV_LOG(DEBUG, "[PF GET MSG FROM VF]--vf mac to del.");
ret = zxdh_del_mac_table(hw, vport, &mac_filter->mac, hw->hash_search_index, 0, 0);
diff --git a/drivers/net/zxdh/zxdh_tables.c b/drivers/net/zxdh/zxdh_tables.c
index 29741e53ed..33f161c4cd 100644
--- a/drivers/net/zxdh/zxdh_tables.c
+++ b/drivers/net/zxdh/zxdh_tables.c
@@ -8,8 +8,8 @@
#include "zxdh_tables.h"
#include "zxdh_logs.h"
-#define ZXDH_UNIMAC_HASH_INDEX(index) (ZXDH_SDT_L2_ENTRY_TABLE0 + (index))
-#define ZXDH_MULTIMAC_HASH_INDEX(index) (ZXDH_SDT_MC_TABLE0 + (index))
+#define ZXDH_UNICAST_MAC_HASH_INDEX(index) (ZXDH_SDT_L2_ENTRY_TABLE0 + (index))
+#define ZXDH_MULTICAST_MAC_HASH_INDEX(index) (ZXDH_SDT_MC_TABLE0 + (index))
#define ZXDH_MC_GROUP_NUM 4
#define ZXDH_BASE_VFID 1152
#define ZXDH_TABLE_HIT_FLAG 128
@@ -244,8 +244,8 @@ zxdh_add_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
struct zxdh_mac_multicast_table multicast_table = {0};
union zxdh_virport_num vport_num = (union zxdh_virport_num)vport;
uint16_t vfid = zxdh_vport_to_vfid(vport_num);
- uint32_t ret;
uint16_t group_id = 0;
+ int16_t ret;
if (rte_is_unicast_ether_addr(addr)) {
rte_memcpy(unicast_table.key.dmac_addr, addr, sizeof(struct rte_ether_addr));
@@ -257,7 +257,7 @@ zxdh_add_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
.p_rst = (uint8_t *)&unicast_table.entry
};
ZXDH_DTB_USER_ENTRY_T entry_get = {
- .sdt_no = ZXDH_UNIMAC_HASH_INDEX(hash_search_idx),
+ .sdt_no = ZXDH_UNICAST_MAC_HASH_INDEX(hash_search_idx),
.p_entry_data = (void *)&dtb_hash_entry
};
@@ -294,19 +294,20 @@ zxdh_add_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
};
ZXDH_DTB_USER_ENTRY_T entry_get = {
- .sdt_no = ZXDH_MULTIMAC_HASH_INDEX(hash_search_idx),
+ .sdt_no = ZXDH_MULTICAST_MAC_HASH_INDEX(hash_search_idx),
.p_entry_data = (void *)&dtb_hash_entry
};
ret = zxdh_np_dtb_table_entry_get(hw->slot_id, hw->dev_sd->dtb_sd.queueid,
&entry_get, 1);
uint8_t index = (vport_num.vfid % 64) / 32;
+ uint8_t value = (vport_num.vfid % 64) % 32;
if (ret == 0) {
if (vport_num.vf_flag) {
if (group_id == vport_num.vfid / 64)
multicast_table.entry.mc_bitmap[index] |=
rte_cpu_to_be_32(UINT32_C(1) <<
- (31 - index));
+ (31 - value));
} else {
if (group_id == vport_num.vfid / 64)
multicast_table.entry.mc_pf_enable =
@@ -317,7 +318,7 @@ zxdh_add_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
if (group_id == vport_num.vfid / 64)
multicast_table.entry.mc_bitmap[index] |=
rte_cpu_to_be_32(UINT32_C(1) <<
- (31 - index));
+ (31 - value));
else
multicast_table.entry.mc_bitmap[index] =
false;
@@ -347,10 +348,9 @@ zxdh_del_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
struct zxdh_mac_unicast_table unicast_table = {0};
struct zxdh_mac_multicast_table multicast_table = {0};
union zxdh_virport_num vport_num = (union zxdh_virport_num)vport;
- union zxdh_virport_num port = (union zxdh_virport_num)vport;
- uint16_t vfid = zxdh_vport_to_vfid(port);
- uint32_t ret, del_flag = 0;
- uint16_t group_id = 0;
+ uint16_t vfid = zxdh_vport_to_vfid(vport_num);
+ uint16_t del_flag, group_id = 0;
+ int32_t ret = 0;
if (rte_is_unicast_ether_addr(addr)) {
rte_memcpy(unicast_table.key.dmac_addr, addr, sizeof(struct rte_ether_addr));
@@ -365,7 +365,7 @@ zxdh_del_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
};
ZXDH_DTB_USER_ENTRY_T entry_get = {
- .sdt_no = ZXDH_UNIMAC_HASH_INDEX(hash_search_idx),
+ .sdt_no = ZXDH_UNICAST_MAC_HASH_INDEX(hash_search_idx),
.p_entry_data = (void *)&dtb_hash_entry
};
ret = zxdh_np_dtb_table_entry_get(hw->slot_id, hw->dev_sd->dtb_sd.queueid,
@@ -393,16 +393,17 @@ zxdh_del_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
};
ZXDH_DTB_USER_ENTRY_T entry_get = {
- .sdt_no = ZXDH_MULTIMAC_HASH_INDEX(hash_search_idx),
+ .sdt_no = ZXDH_MULTICAST_MAC_HASH_INDEX(hash_search_idx),
.p_entry_data = (void *)&dtb_hash_entry
};
ret = zxdh_np_dtb_table_entry_get(hw->slot_id, hw->dev_sd->dtb_sd.queueid,
&entry_get, 1);
uint8_t index = (vport_num.vfid % 64) / 32;
+ uint8_t value = (vport_num.vfid % 64) % 32;
if (vport_num.vf_flag)
multicast_table.entry.mc_bitmap[index] &=
- ~(rte_cpu_to_be_32(UINT32_C(1) << (31 - index)));
+ ~(rte_cpu_to_be_32(UINT32_C(1) << (31 - value)));
else
multicast_table.entry.mc_pf_enable = 0;
@@ -422,7 +423,7 @@ zxdh_del_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
.p_rst = (uint8_t *)&multicast_table.entry
};
ZXDH_DTB_USER_ENTRY_T entry_get = {
- .sdt_no = ZXDH_MULTIMAC_HASH_INDEX(hash_search_idx),
+ .sdt_no = ZXDH_MULTICAST_MAC_HASH_INDEX(hash_search_idx),
.p_entry_data = (void *)&dtb_hash_entry
};
@@ -447,7 +448,7 @@ zxdh_del_mac_table(struct zxdh_hw *hw, uint16_t vport, struct rte_ether_addr *ad
.p_rst = (uint8_t *)&multicast_table.entry
};
ZXDH_DTB_USER_ENTRY_T entry_get = {
- .sdt_no = ZXDH_MULTIMAC_HASH_INDEX(hash_search_idx),
+ .sdt_no = ZXDH_MULTICAST_MAC_HASH_INDEX(hash_search_idx),
.p_entry_data = (void *)&dtb_hash_entry
};
@@ -604,6 +605,7 @@ zxdh_dev_unicast_table_set(struct zxdh_hw *hw, uint16_t vport, bool enable)
struct zxdh_unitcast_table uc_table = {0};
struct zxdh_port_attr_table port_attr = {0};
union zxdh_virport_num vport_num = (union zxdh_virport_num)vport;
+ uint16_t vfid = zxdh_vport_to_vfid(vport_num);
int16_t ret = 0;
ZXDH_DTB_ERAM_ENTRY_INFO_T uc_table_entry = {
@@ -617,7 +619,7 @@ zxdh_dev_unicast_table_set(struct zxdh_hw *hw, uint16_t vport, bool enable)
ret = zxdh_np_dtb_table_entry_get(hw->slot_id, dtb_data->queueid, &entry, 1);
if (ret) {
- PMD_DRV_LOG(ERR, "unicast_table_get_failed:%d", hw->vfid);
+ PMD_DRV_LOG(ERR, "unicast_table_get_failed:%d", vfid);
return -ret;
}
@@ -634,20 +636,20 @@ zxdh_dev_unicast_table_set(struct zxdh_hw *hw, uint16_t vport, bool enable)
ret = zxdh_np_dtb_table_entry_write(hw->slot_id, dtb_data->queueid, 1, &entry);
if (ret) {
- PMD_DRV_LOG(ERR, "unicast_table_set_failed:%d", hw->vfid);
+ PMD_DRV_LOG(ERR, "unicast_table_set_failed:%d", vfid);
return -ret;
}
ret = zxdh_get_port_attr(hw, vport, &port_attr);
if (ret) {
- PMD_DRV_LOG(ERR, "port_attr_table_get_failed:%d", hw->vfid);
+ PMD_DRV_LOG(ERR, "port_attr_table_get_failed:%d", vfid);
return -ret;
}
port_attr.promisc_enable = enable;
ret = zxdh_set_port_attr(hw, vport, &port_attr);
if (ret) {
- PMD_DRV_LOG(ERR, "port_attr_table_set_failed:%d", hw->vfid);
+ PMD_DRV_LOG(ERR, "port_attr_table_set_failed:%d", vfid);
return -ret;
}
--
2.27.0
[-- Attachment #1.1.2: Type: text/html , Size: 36658 bytes --]
next prev parent reply other threads:[~2025-06-17 2:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-07 2:30 [PATCH v1 1/3] " Junlong Wang
2025-06-07 2:30 ` [PATCH v1 2/3] net/zxdh: modify some VLAN related issues Junlong Wang
2025-06-16 16:20 ` Stephen Hemminger
2025-06-07 2:30 ` [PATCH v1 3/3] net/zxdh: modify RSS " Junlong Wang
2025-06-16 16:22 ` Stephen Hemminger
2025-06-12 0:14 ` [PATCH v1 1/3] net/zxdh: modify some MAC config issues Thomas Monjalon
2025-06-12 1:18 ` Junlong Wang
2025-06-16 16:16 ` Stephen Hemminger
2025-06-17 2:04 ` [PATCH v2 1/5] net/zxdh: fix meson.build issus in compilation Junlong Wang
2025-06-17 2:05 ` Junlong Wang [this message]
2025-06-17 2:05 ` [PATCH v2 3/5] net/zxdh: modify some VLAN related issues Junlong Wang
2025-06-17 2:05 ` [PATCH v2 4/5] net/zxdh: modify RSS " Junlong Wang
2025-06-17 2:05 ` [PATCH v2 5/5] net/zxdh: add support VLAN TPID set ops Junlong Wang
2025-06-17 3:32 ` zhoumin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250617020503.3554511-2-wang.junlong1@zte.com.cn \
--to=wang.junlong1@zte.com.cn \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).