patches for DPDK stable branches
 help / color / mirror / Atom feed
From: "Min Hu (Connor)" <humin29@huawei.com>
To: <stable@dpdk.org>
Cc: <christian.ehrhardt@canonical.com>
Subject: [dpdk-stable] [PATCH 19.11.9 1/3] net/hns3: fix HW buffer size on MTU update
Date: Sat, 22 May 2021 14:47:22 +0800	[thread overview]
Message-ID: <1621666044-39902-1-git-send-email-humin29@huawei.com> (raw)

From: Chengchang Tang <tangchengchang@huawei.com>

[ upstream commit 25fb790f7868f8eee96f7f051a834dec01b8a369 ]

After MTU changed, the buffer used to store packets in HW should be
reallocated. And buffer size is allocated based on the maximum frame
size in the PF struct. However, the value of maximum frame size  is
not updated in time when MTU is changed. This would lead to a packet
loss for not enough buffer.

This patch update the maximum frame size before reallocating the HW
buffer. And a rollback operation is added to avoid the side effects
of buffer reallocation failures.

Fixes: 1f5ca0b460cd ("net/hns3: support some device operations")
Fixes: d51867db65c1 ("net/hns3: add initialization")
Cc: stable@dpdk.org

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 3a799ed..952538d 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2418,21 +2418,35 @@ hns3_set_mac_mtu(struct hns3_hw *hw, uint16_t new_mps)
 static int
 hns3_config_mtu(struct hns3_hw *hw, uint16_t mps)
 {
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+	uint16_t original_mps = hns->pf.mps;
+	int err;
 	int ret;
 
 	ret = hns3_set_mac_mtu(hw, mps);
 	if (ret) {
-		hns3_err(hw, "Failed to set mtu, ret = %d", ret);
+		hns3_err(hw, "failed to set mtu, ret = %d", ret);
 		return ret;
 	}
 
+	hns->pf.mps = mps;
 	ret = hns3_buffer_alloc(hw);
 	if (ret) {
-		hns3_err(hw, "Failed to allocate buffer, ret = %d", ret);
-		return ret;
+		hns3_err(hw, "failed to allocate buffer, ret = %d", ret);
+		goto rollback;
 	}
 
 	return 0;
+
+rollback:
+	err = hns3_set_mac_mtu(hw, original_mps);
+	if (err) {
+		hns3_err(hw, "fail to rollback MTU, err = %d", err);
+		return ret;
+	}
+	hns->pf.mps = original_mps;
+
+	return ret;
 }
 
 static int
@@ -2465,7 +2479,7 @@ hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 			 dev->data->port_id, mtu, ret);
 		return ret;
 	}
-	hns->pf.mps = (uint16_t)frame_size;
+
 	if (is_jumbo_frame)
 		dev->data->dev_conf.rxmode.offloads |=
 						DEV_RX_OFFLOAD_JUMBO_FRAME;
-- 
2.7.4


             reply	other threads:[~2021-05-22  6:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-22  6:47 Min Hu (Connor) [this message]
2021-05-22  6:47 ` [dpdk-stable] [PATCH 19.11.9 2/3] net/hns3: fix processing Tx offload flags Min Hu (Connor)
2021-05-22  6:47 ` [dpdk-stable] [PATCH 19.11.9 3/3] net/hns3: fix handling link update Min Hu (Connor)
2021-05-31  8:41 ` [dpdk-stable] [PATCH 19.11.9 1/3] net/hns3: fix HW buffer size on MTU update Christian Ehrhardt

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=1621666044-39902-1-git-send-email-humin29@huawei.com \
    --to=humin29@huawei.com \
    --cc=christian.ehrhardt@canonical.com \
    --cc=stable@dpdk.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).