[dpdk-stable] patch 'net/hns3: fix Rx buffer size' has been queued to stable release 19.11.4

luca.boccassi at gmail.com luca.boccassi at gmail.com
Fri Jul 24 13:59:10 CEST 2020


Hi,

FYI, your patch has been queued to stable release 19.11.4

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 07/26/20. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Thanks.

Luca Boccassi

---
>From 479064d41e9cbd7654abe1689043e4045e206bbd Mon Sep 17 00:00:00 2001
From: "Wei Hu (Xavier)" <xavier.huwei at huawei.com>
Date: Wed, 1 Jul 2020 19:54:40 +0800
Subject: [PATCH] net/hns3: fix Rx buffer size

[ upstream commit dfac40d93edf7dbac8ef41f775daba4e54a39263 ]

Currently, rx_buf_size of hns3 PMD driver is fixed on, and it's value
depends on the firmware which will decrease the flexibility of PMD.

The receive side mbufs was allocated from the mempool given by upper
application calling rte_eth_rx_queue_setup API function. So the memory
chunk used for net device DMA is depend on the data room size of the
objects in this mempool. Hns3 PMD driver should set the rx_buf_len
smaller than the data room size of mempool and our hardware only support
the following four specifications: 512, 1024, 2148 and 4096.

Fixes: bba636698316 ("net/hns3: support Rx/Tx and related operations")

Signed-off-by: Chengchang Tang <tangchengchang at huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei at huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c    |  3 +-
 drivers/net/hns3/hns3_ethdev.h    |  1 -
 drivers/net/hns3/hns3_ethdev_vf.c |  5 +--
 drivers/net/hns3/hns3_rxtx.c      | 56 +++++++++++++++++++++++++++++--
 drivers/net/hns3/hns3_rxtx.h      |  8 +++++
 5 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 4a1bb174c..4922e1bde 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2362,7 +2362,7 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
 	info->max_rx_queues = queue_num;
 	info->max_tx_queues = hw->tqps_num;
 	info->max_rx_pktlen = HNS3_MAX_FRAME_LEN; /* CRC included */
-	info->min_rx_bufsize = hw->rx_buf_len;
+	info->min_rx_bufsize = HNS3_MIN_BD_BUF_SIZE;
 	info->max_mac_addrs = HNS3_UC_MACADDR_NUM;
 	info->max_mtu = info->max_rx_pktlen - HNS3_ETH_OVERHEAD;
 	info->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
@@ -2709,7 +2709,6 @@ hns3_get_board_configuration(struct hns3_hw *hw)
 	hw->mac.media_type = cfg.media_type;
 	hw->rss_size_max = cfg.rss_size_max;
 	hw->rss_dis_flag = false;
-	hw->rx_buf_len = cfg.rx_buf_len;
 	memcpy(hw->mac.mac_addr, cfg.mac_addr, RTE_ETHER_ADDR_LEN);
 	hw->mac.phy_addr = cfg.phy_addr;
 	hw->mac.default_addr_setted = false;
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index e7d9fe0e0..155099e99 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -363,7 +363,6 @@ struct hns3_hw {
 	uint16_t tqps_num;          /* num task queue pairs of this function */
 	uint16_t intr_tqps_num;     /* num queue pairs mapping interrupt */
 	uint16_t rss_size_max;      /* HW defined max RSS task queue */
-	uint16_t rx_buf_len;
 	uint16_t num_tx_desc;       /* desc num of per tx queue */
 	uint16_t num_rx_desc;       /* desc num of per rx queue */
 
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 22cd9eb33..a2867f8ec 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -652,7 +652,7 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
 	info->max_rx_queues = q_num;
 	info->max_tx_queues = hw->tqps_num;
 	info->max_rx_pktlen = HNS3_MAX_FRAME_LEN; /* CRC included */
-	info->min_rx_bufsize = hw->rx_buf_len;
+	info->min_rx_bufsize = HNS3_MIN_BD_BUF_SIZE;
 	info->max_mac_addrs = HNS3_VF_UC_MACADDR_NUM;
 	info->max_mtu = info->max_rx_pktlen - HNS3_ETH_OVERHEAD;
 
@@ -816,8 +816,6 @@ hns3vf_check_tqp_info(struct hns3_hw *hw)
 		return -EINVAL;
 	}
 
-	if (hw->rx_buf_len == 0)
-		hw->rx_buf_len = HNS3_DEFAULT_RX_BUF_LEN;
 	hw->alloc_rss_size = RTE_MIN(hw->rss_size_max, hw->tqps_num);
 
 	return 0;
@@ -839,7 +837,6 @@ hns3vf_get_queue_info(struct hns3_hw *hw)
 
 	memcpy(&hw->tqps_num, &resp_msg[0], sizeof(uint16_t));
 	memcpy(&hw->rss_size_max, &resp_msg[2], sizeof(uint16_t));
-	memcpy(&hw->rx_buf_len, &resp_msg[4], sizeof(uint16_t));
 
 	return hns3vf_check_tqp_info(hw);
 }
diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c
index 3251515fe..c1ffa136b 100644
--- a/drivers/net/hns3/hns3_rxtx.c
+++ b/drivers/net/hns3/hns3_rxtx.c
@@ -884,7 +884,7 @@ hns3_fake_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
 	nb_rx_q = dev->data->nb_rx_queues;
 	rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
 				(nb_rx_q + idx) * HNS3_TQP_REG_SIZE);
-	rxq->rx_buf_len = hw->rx_buf_len;
+	rxq->rx_buf_len = HNS3_MIN_BD_BUF_SIZE;
 
 	rte_spinlock_lock(&hw->lock);
 	hw->fkq_data.rx_queues[idx] = rxq;
@@ -1160,6 +1160,48 @@ hns3_dev_release_mbufs(struct hns3_adapter *hns)
 		}
 }
 
+static int
+hns3_rx_buf_len_calc(struct rte_mempool *mp, uint16_t *rx_buf_len)
+{
+	uint16_t vld_buf_size;
+	uint16_t num_hw_specs;
+	uint16_t i;
+
+	/*
+	 * hns3 network engine only support to set 4 typical specification, and
+	 * different buffer size will affect the max packet_len and the max
+	 * number of segmentation when hw gro is turned on in receive side. The
+	 * relationship between them is as follows:
+	 *      rx_buf_size     |  max_gro_pkt_len  |  max_gro_nb_seg
+	 * ---------------------|-------------------|----------------
+	 * HNS3_4K_BD_BUF_SIZE  |        60KB       |       15
+	 * HNS3_2K_BD_BUF_SIZE  |        62KB       |       31
+	 * HNS3_1K_BD_BUF_SIZE  |        63KB       |       63
+	 * HNS3_512_BD_BUF_SIZE |      31.5KB       |       63
+	 */
+	static const uint16_t hw_rx_buf_size[] = {
+		HNS3_4K_BD_BUF_SIZE,
+		HNS3_2K_BD_BUF_SIZE,
+		HNS3_1K_BD_BUF_SIZE,
+		HNS3_512_BD_BUF_SIZE
+	};
+
+	vld_buf_size = (uint16_t)(rte_pktmbuf_data_room_size(mp) -
+			RTE_PKTMBUF_HEADROOM);
+
+	if (vld_buf_size < HNS3_MIN_BD_BUF_SIZE)
+		return -EINVAL;
+
+	num_hw_specs = RTE_DIM(hw_rx_buf_size);
+	for (i = 0; i < num_hw_specs; i++) {
+		if (vld_buf_size >= hw_rx_buf_size[i]) {
+			*rx_buf_len = hw_rx_buf_size[i];
+			break;
+		}
+	}
+	return 0;
+}
+
 int
 hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
 		    unsigned int socket_id, const struct rte_eth_rxconf *conf,
@@ -1169,6 +1211,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
 	struct hns3_hw *hw = &hns->hw;
 	struct hns3_queue_info q_info;
 	struct hns3_rx_queue *rxq;
+	uint16_t rx_buf_size;
 	int rx_entry_len;
 
 	if (dev->data->dev_started) {
@@ -1193,6 +1236,15 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
 	q_info.nb_desc = nb_desc;
 	q_info.type = "hns3 RX queue";
 	q_info.ring_name = "rx_ring";
+
+	if (hns3_rx_buf_len_calc(mp, &rx_buf_size)) {
+		hns3_err(hw, "rxq mbufs' data room size:%u is not enough! "
+				"minimal data room size:%u.",
+				rte_pktmbuf_data_room_size(mp),
+				HNS3_MIN_BD_BUF_SIZE + RTE_PKTMBUF_HEADROOM);
+		return -EINVAL;
+	}
+
 	rxq = hns3_alloc_rxq_and_dma_zone(dev, &q_info);
 	if (rxq == NULL) {
 		hns3_err(hw,
@@ -1226,7 +1278,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
 	rxq->configured = true;
 	rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
 				idx * HNS3_TQP_REG_SIZE);
-	rxq->rx_buf_len = hw->rx_buf_len;
+	rxq->rx_buf_len = rx_buf_size;
 	rxq->l2_errors = 0;
 	rxq->pkt_len_errors = 0;
 	rxq->l3_csum_erros = 0;
diff --git a/drivers/net/hns3/hns3_rxtx.h b/drivers/net/hns3/hns3_rxtx.h
index 771f3c9be..1fd1afd1d 100644
--- a/drivers/net/hns3/hns3_rxtx.h
+++ b/drivers/net/hns3/hns3_rxtx.h
@@ -11,6 +11,14 @@
 #define	HNS3_ALIGN_RING_DESC	32
 #define HNS3_RING_BASE_ALIGN	128
 
+#define HNS3_512_BD_BUF_SIZE	512
+#define HNS3_1K_BD_BUF_SIZE	1024
+#define HNS3_2K_BD_BUF_SIZE	2048
+#define HNS3_4K_BD_BUF_SIZE	4096
+
+#define HNS3_MIN_BD_BUF_SIZE	HNS3_512_BD_BUF_SIZE
+#define HNS3_MAX_BD_BUF_SIZE	HNS3_4K_BD_BUF_SIZE
+
 #define HNS3_BD_SIZE_512_TYPE			0
 #define HNS3_BD_SIZE_1024_TYPE			1
 #define HNS3_BD_SIZE_2048_TYPE			2
-- 
2.20.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2020-07-24 12:53:52.860342031 +0100
+++ 0112-net-hns3-fix-Rx-buffer-size.patch	2020-07-24 12:53:48.375008099 +0100
@@ -1,8 +1,10 @@
-From dfac40d93edf7dbac8ef41f775daba4e54a39263 Mon Sep 17 00:00:00 2001
+From 479064d41e9cbd7654abe1689043e4045e206bbd Mon Sep 17 00:00:00 2001
 From: "Wei Hu (Xavier)" <xavier.huwei at huawei.com>
 Date: Wed, 1 Jul 2020 19:54:40 +0800
 Subject: [PATCH] net/hns3: fix Rx buffer size
 
+[ upstream commit dfac40d93edf7dbac8ef41f775daba4e54a39263 ]
+
 Currently, rx_buf_size of hns3 PMD driver is fixed on, and it's value
 depends on the firmware which will decrease the flexibility of PMD.
 
@@ -14,7 +16,6 @@
 the following four specifications: 512, 1024, 2148 and 4096.
 
 Fixes: bba636698316 ("net/hns3: support Rx/Tx and related operations")
-Cc: stable at dpdk.org
 
 Signed-off-by: Chengchang Tang <tangchengchang at huawei.com>
 Signed-off-by: Wei Hu (Xavier) <xavier.huwei at huawei.com>
@@ -27,10 +28,10 @@
  5 files changed, 64 insertions(+), 9 deletions(-)
 
 diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
-index b9868de54..13ce32432 100644
+index 4a1bb174c..4922e1bde 100644
 --- a/drivers/net/hns3/hns3_ethdev.c
 +++ b/drivers/net/hns3/hns3_ethdev.c
-@@ -2450,7 +2450,7 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
+@@ -2362,7 +2362,7 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
  	info->max_rx_queues = queue_num;
  	info->max_tx_queues = hw->tqps_num;
  	info->max_rx_pktlen = HNS3_MAX_FRAME_LEN; /* CRC included */
@@ -38,8 +39,8 @@
 +	info->min_rx_bufsize = HNS3_MIN_BD_BUF_SIZE;
  	info->max_mac_addrs = HNS3_UC_MACADDR_NUM;
  	info->max_mtu = info->max_rx_pktlen - HNS3_ETH_OVERHEAD;
- 	info->max_lro_pkt_size = HNS3_MAX_LRO_SIZE;
-@@ -2848,7 +2848,6 @@ hns3_get_board_configuration(struct hns3_hw *hw)
+ 	info->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
+@@ -2709,7 +2709,6 @@ hns3_get_board_configuration(struct hns3_hw *hw)
  	hw->mac.media_type = cfg.media_type;
  	hw->rss_size_max = cfg.rss_size_max;
  	hw->rss_dis_flag = false;
@@ -48,10 +49,10 @@
  	hw->mac.phy_addr = cfg.phy_addr;
  	hw->mac.default_addr_setted = false;
 diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
-index c390263bd..3c991f4ce 100644
+index e7d9fe0e0..155099e99 100644
 --- a/drivers/net/hns3/hns3_ethdev.h
 +++ b/drivers/net/hns3/hns3_ethdev.h
-@@ -375,7 +375,6 @@ struct hns3_hw {
+@@ -363,7 +363,6 @@ struct hns3_hw {
  	uint16_t tqps_num;          /* num task queue pairs of this function */
  	uint16_t intr_tqps_num;     /* num queue pairs mapping interrupt */
  	uint16_t rss_size_max;      /* HW defined max RSS task queue */
@@ -60,10 +61,10 @@
  	uint16_t num_rx_desc;       /* desc num of per rx queue */
  
 diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
-index 9c45ffae2..3c5998abe 100644
+index 22cd9eb33..a2867f8ec 100644
 --- a/drivers/net/hns3/hns3_ethdev_vf.c
 +++ b/drivers/net/hns3/hns3_ethdev_vf.c
-@@ -902,7 +902,7 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
+@@ -652,7 +652,7 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
  	info->max_rx_queues = q_num;
  	info->max_tx_queues = hw->tqps_num;
  	info->max_rx_pktlen = HNS3_MAX_FRAME_LEN; /* CRC included */
@@ -71,8 +72,8 @@
 +	info->min_rx_bufsize = HNS3_MIN_BD_BUF_SIZE;
  	info->max_mac_addrs = HNS3_VF_UC_MACADDR_NUM;
  	info->max_mtu = info->max_rx_pktlen - HNS3_ETH_OVERHEAD;
- 	info->max_lro_pkt_size = HNS3_MAX_LRO_SIZE;
-@@ -1096,8 +1096,6 @@ hns3vf_check_tqp_info(struct hns3_hw *hw)
+ 
+@@ -816,8 +816,6 @@ hns3vf_check_tqp_info(struct hns3_hw *hw)
  		return -EINVAL;
  	}
  
@@ -81,7 +82,7 @@
  	hw->alloc_rss_size = RTE_MIN(hw->rss_size_max, hw->tqps_num);
  
  	return 0;
-@@ -1162,7 +1160,6 @@ hns3vf_get_queue_info(struct hns3_hw *hw)
+@@ -839,7 +837,6 @@ hns3vf_get_queue_info(struct hns3_hw *hw)
  
  	memcpy(&hw->tqps_num, &resp_msg[0], sizeof(uint16_t));
  	memcpy(&hw->rss_size_max, &resp_msg[2], sizeof(uint16_t));
@@ -90,10 +91,10 @@
  	return hns3vf_check_tqp_info(hw);
  }
 diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c
-index 0f9825f74..931d89a1a 100644
+index 3251515fe..c1ffa136b 100644
 --- a/drivers/net/hns3/hns3_rxtx.c
 +++ b/drivers/net/hns3/hns3_rxtx.c
-@@ -909,7 +909,7 @@ hns3_fake_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
+@@ -884,7 +884,7 @@ hns3_fake_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
  	nb_rx_q = dev->data->nb_rx_queues;
  	rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
  				(nb_rx_q + idx) * HNS3_TQP_REG_SIZE);
@@ -102,7 +103,7 @@
  
  	rte_spinlock_lock(&hw->lock);
  	hw->fkq_data.rx_queues[idx] = rxq;
-@@ -1185,6 +1185,48 @@ hns3_dev_release_mbufs(struct hns3_adapter *hns)
+@@ -1160,6 +1160,48 @@ hns3_dev_release_mbufs(struct hns3_adapter *hns)
  		}
  }
  
@@ -151,7 +152,7 @@
  int
  hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
  		    unsigned int socket_id, const struct rte_eth_rxconf *conf,
-@@ -1194,6 +1236,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
+@@ -1169,6 +1211,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
  	struct hns3_hw *hw = &hns->hw;
  	struct hns3_queue_info q_info;
  	struct hns3_rx_queue *rxq;
@@ -159,7 +160,7 @@
  	int rx_entry_len;
  
  	if (dev->data->dev_started) {
-@@ -1218,6 +1261,15 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
+@@ -1193,6 +1236,15 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
  	q_info.nb_desc = nb_desc;
  	q_info.type = "hns3 RX queue";
  	q_info.ring_name = "rx_ring";
@@ -175,7 +176,7 @@
  	rxq = hns3_alloc_rxq_and_dma_zone(dev, &q_info);
  	if (rxq == NULL) {
  		hns3_err(hw,
-@@ -1252,7 +1304,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
+@@ -1226,7 +1278,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
  	rxq->configured = true;
  	rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
  				idx * HNS3_TQP_REG_SIZE);
@@ -185,7 +186,7 @@
  	rxq->pkt_len_errors = 0;
  	rxq->l3_csum_erros = 0;
 diff --git a/drivers/net/hns3/hns3_rxtx.h b/drivers/net/hns3/hns3_rxtx.h
-index b85c64f65..ccd508b74 100644
+index 771f3c9be..1fd1afd1d 100644
 --- a/drivers/net/hns3/hns3_rxtx.h
 +++ b/drivers/net/hns3/hns3_rxtx.h
 @@ -11,6 +11,14 @@


More information about the stable mailing list