From patchwork Thu Oct 15 02:02:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinan Sun X-Patchwork-Id: 80816 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 393D6A04DB; Thu, 15 Oct 2020 04:43:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 90EF51DBBC; Thu, 15 Oct 2020 04:43:10 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 4BFDA1DA5E for ; Thu, 15 Oct 2020 04:43:07 +0200 (CEST) IronPort-SDR: hfAuvRuvmK+bCbboD+WYlrW8q1iiRPvufUQLepEJDqEdjY1bdyQOnOrZZDKDYLT32pRhxSwZrC eEgC1AB2Ho6w== X-IronPort-AV: E=McAfee;i="6000,8403,9774"; a="162776819" X-IronPort-AV: E=Sophos;i="5.77,377,1596524400"; d="scan'208";a="162776819" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2020 19:43:06 -0700 IronPort-SDR: 6m7YM13YQykF/4e+Ha+do7EEz4mMFjFrDa2ZJlwZ70RSzwTH0rjN3DG7wkxxjyzM+d+vTF1VEH YFk6jqkl7QIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,377,1596524400"; d="scan'208";a="357563735" Received: from qat_cpm20_vlan01.sh.intel.com ([10.67.97.38]) by orsmga007.jf.intel.com with ESMTP; 14 Oct 2020 19:43:04 -0700 From: Guinan Sun To: dev@dpdk.org Cc: Beilei Xing , Jingjing Wu , Qi Zhang , Guinan Sun Date: Thu, 15 Oct 2020 10:02:04 +0800 Message-Id: <20201015020204.12658-1-guinanx.sun@intel.com> X-Mailer: git-send-email 2.13.6 Subject: [dpdk-dev] [PATCH] net/iavf: fix adding multicast MAC address X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When the multicast address is added, it will flush previous addresses first, and then add new ones. So when adding an address that exceeds the upper limit causes a failure, you need to add the previous address list back. This patch fixes the issue. Fixes: 05e4c3aff35f ("net/iavf: support multicast configuration") Signed-off-by: Guinan Sun Signed-off-by: Guinan Sun --- drivers/net/iavf/iavf_ethdev.c | 30 ++++++++++++++++++++++-------- drivers/net/iavf/iavf_vchnl.c | 3 --- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c index e68e3bc71..042edadd9 100644 --- a/drivers/net/iavf/iavf_ethdev.c +++ b/drivers/net/iavf/iavf_ethdev.c @@ -164,7 +164,14 @@ iavf_set_mc_addr_list(struct rte_eth_dev *dev, struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private); struct iavf_adapter *adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private); - int err; + int err, temp_err; + + if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) { + PMD_DRV_LOG(ERR, + "can't add more than a limited number (%u) of addresses.", + (uint32_t)IAVF_NUM_MACADDR_MAX); + return -EINVAL; + } /* flush previous addresses */ err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num, @@ -172,17 +179,24 @@ iavf_set_mc_addr_list(struct rte_eth_dev *dev, if (err) return err; - vf->mc_addrs_num = 0; - /* add new ones */ err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true); - if (err) - return err; - vf->mc_addrs_num = mc_addrs_num; - memcpy(vf->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs)); + if (err) { + /* When adding new addresses fail, need to add the + * previous addresses back. + */ + temp_err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, + vf->mc_addrs_num, true); + if (temp_err) + return temp_err; + } else { + vf->mc_addrs_num = mc_addrs_num; + memcpy(vf->mc_addrs, + mc_addrs, mc_addrs_num * sizeof(*mc_addrs)); + } - return 0; + return err; } static int diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index db0b76876..a2295f879 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -1107,9 +1107,6 @@ iavf_add_del_mc_addr_list(struct iavf_adapter *adapter, if (mc_addrs == NULL || mc_addrs_num == 0) return 0; - if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) - return -EINVAL; - list = (struct virtchnl_ether_addr_list *)cmd_buffer; list->vsi_id = vf->vsi_res->vsi_id; list->num_elements = mc_addrs_num;