From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, Jingjing Wu <jingjing.wu@intel.com>
Subject: [PATCH] net/iavf: simplify mailbox message generation for mac
Date: Tue, 1 Oct 2024 11:15:07 +0200 [thread overview]
Message-ID: <20241001091507.98785-1-david.marchand@redhat.com> (raw)
Caught by code review.
The mailbox message maximum size is larger than the biggest message
to update mac addresses.
Remove the double loop and add some build / assert checks.
This cleanup also fixes a (never hit) issue where multiple mac addresses
would be marked as VIRTCHNL_ETHER_ADDR_PRIMARY if multiple messages had
been effectively sent.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/net/iavf/iavf_vchnl.c | 86 ++++++++++++++---------------------
1 file changed, 34 insertions(+), 52 deletions(-)
diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c
index 065ab3594c..e5113605ac 100644
--- a/drivers/net/iavf/iavf_vchnl.c
+++ b/drivers/net/iavf/iavf_vchnl.c
@@ -1397,62 +1397,44 @@ void
iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
{
struct virtchnl_ether_addr_list *list;
+ char buf[sizeof(*list) + sizeof(struct virtchnl_ether_addr) * IAVF_NUM_MACADDR_MAX];
struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
- struct rte_ether_addr *addr;
struct iavf_cmd_info args;
- int len, err, i, j;
- int next_begin = 0;
- int begin = 0;
-
- do {
- j = 0;
- len = sizeof(struct virtchnl_ether_addr_list);
- for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
- addr = &adapter->dev_data->mac_addrs[i];
- if (rte_is_zero_ether_addr(addr))
- continue;
- len += sizeof(struct virtchnl_ether_addr);
- if (len >= IAVF_AQ_BUF_SZ) {
- next_begin = i + 1;
- break;
- }
- }
+ int len, i;
- list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
- if (!list) {
- PMD_DRV_LOG(ERR, "fail to allocate memory");
- return;
- }
+ RTE_BUILD_BUG_ON(sizeof(buf) > IAVF_AQ_BUF_SZ);
+ list = (struct virtchnl_ether_addr_list *)buf;
- for (i = begin; i < next_begin; i++) {
- addr = &adapter->dev_data->mac_addrs[i];
- if (rte_is_zero_ether_addr(addr))
- continue;
- rte_memcpy(list->list[j].addr, addr->addr_bytes,
- sizeof(addr->addr_bytes));
- list->list[j].type = (j == 0 ?
- VIRTCHNL_ETHER_ADDR_PRIMARY :
- VIRTCHNL_ETHER_ADDR_EXTRA);
- PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
- RTE_ETHER_ADDR_BYTES(addr));
- j++;
- }
- list->vsi_id = vf->vsi_res->vsi_id;
- list->num_elements = j;
- args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
- VIRTCHNL_OP_DEL_ETH_ADDR;
- args.in_args = (uint8_t *)list;
- args.in_args_size = len;
- args.out_buffer = vf->aq_resp;
- args.out_size = IAVF_AQ_BUF_SZ;
- err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
- if (err)
- PMD_DRV_LOG(ERR, "fail to execute command %s",
- add ? "OP_ADD_ETHER_ADDRESS" :
- "OP_DEL_ETHER_ADDRESS");
- rte_free(list);
- begin = next_begin;
- } while (begin < IAVF_NUM_MACADDR_MAX);
+ len = sizeof(struct virtchnl_ether_addr_list);
+ for (i = 0; i < IAVF_NUM_MACADDR_MAX; i++) {
+ struct rte_ether_addr *addr;
+
+ addr = &adapter->dev_data->mac_addrs[i];
+ if (rte_is_zero_ether_addr(addr))
+ continue;
+ len += sizeof(struct virtchnl_ether_addr);
+ assert(len <= IAVF_AQ_BUF_SZ);
+
+ rte_memcpy(list->list[i].addr, addr->addr_bytes,
+ sizeof(addr->addr_bytes));
+ list->list[i].type = (i == 0 ?
+ VIRTCHNL_ETHER_ADDR_PRIMARY :
+ VIRTCHNL_ETHER_ADDR_EXTRA);
+ PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
+ RTE_ETHER_ADDR_BYTES(addr));
+ }
+
+ list->vsi_id = vf->vsi_res->vsi_id;
+ list->num_elements = i;
+ args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
+ args.in_args = (uint8_t *)list;
+ args.in_args_size = len;
+ args.out_buffer = vf->aq_resp;
+ args.out_size = IAVF_AQ_BUF_SZ;
+
+ if (iavf_execute_vf_cmd_safe(adapter, &args, 0))
+ PMD_DRV_LOG(ERR, "fail to execute command %s",
+ add ? "OP_ADD_ETHER_ADDRESS" : "OP_DEL_ETHER_ADDRESS");
}
int
--
2.46.2
next reply other threads:[~2024-10-01 9:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 9:15 David Marchand [this message]
2024-10-15 16:22 ` [PATCH] net/iavf: simplify mailbox message generation for mac Bruce Richardson
2024-10-16 10:16 ` David Marchand
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=20241001091507.98785-1-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=jingjing.wu@intel.com \
/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).