Skip to contentSkip to conversation

misc updates for hns3 PMD driver

PATCH In review Wei Hu (Xavier) 2 participants 9 messages Mar 17, 2020 – Mar 19, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

cover misc updates for hns3 PMD driver

This series are updates and fixes for hns3 PMD driver.

Chengchang Tang (2):
net/hns3: remove redundant MAC addr check when setting MAC net/hns3: modify inappropriate names

Chengwen Feng (3):
net/hns3: fix packets's offload features flags in Rx net/hns3: fix default error code of command interface net/hns3: fix crash when flushing RSS flow rules with FLR

Min Hu (Connor) (1):
net/hns3: fix configuring illeagl VLAN pvid

Wei Hu (Xavier) (1):
net/hns3: fix abnormal status after reset occurs repeatedly

 drivers/net/hns3/hns3_cmd.c       | 24 +++++++++++----
 drivers/net/hns3/hns3_ethdev.c    | 51 +++++++++++++------------------
 drivers/net/hns3/hns3_ethdev_vf.c | 28 +++++------------
 drivers/net/hns3/hns3_flow.c      |  5 ++-
 drivers/net/hns3/hns3_rxtx.c      |  5 +--
 5 files changed, 55 insertions(+), 58 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/7 net/hns3: remove redundant MAC addr check when setting MAC

From: Chengchang Tang <[email protected]>

This patch removes unnecessary MAC address validity check operation in the .mac_addr_set ops implementation function named hns3_set_default_mac_addr and hns3vf_set_default_mac_addr, because it has been guaranteed that input parameter named mac_addr is valid address in the rte layer of DPDK framework.

---
 drivers/net/hns3/hns3_ethdev.c    | 13 ++++---------
 drivers/net/hns3/hns3_ethdev_vf.c | 12 ++++--------
 2 files changed, 8 insertions(+), 17 deletions(-)
drivers/net/hns3/hns3_ethdev.c +4 -9
index 26366013f..614a42466 100644
@@ -1487,15 +1487,10 @@ hns3_set_default_mac_addr(struct rte_eth_dev *dev,
 	bool rm_succes = false;
 	int ret, ret_val;
 
-	/* check if mac addr is valid */
-	if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
-		rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-				      mac_addr);
-		hns3_err(hw, "Failed to set mac addr, addr(%s) invalid",
-			 mac_str);
-		return -EINVAL;
-	}
-
+	/*
+	 * It has been guaranteed that input parameter named mac_addr is valid
+	 * address in the rte layer of DPDK framework.
+	 */
 	oaddr = (struct rte_ether_addr *)hw->mac.mac_addr;
 	default_addr_setted = hw->mac.default_addr_setted;
 	if (default_addr_setted && !!rte_is_same_ether_addr(mac_addr, oaddr))
drivers/net/hns3/hns3_ethdev_vf.c +4 -8
index 16b7f015f..1c508f06a 100644
@@ -192,14 +192,10 @@ hns3vf_set_default_mac_addr(struct rte_eth_dev *dev,
 	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
 	int ret;
 
-	if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
-		rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-				      mac_addr);
-		hns3_err(hw, "Failed to set mac addr, addr(%s) invalid.",
-			 mac_str);
-		return -EINVAL;
-	}
-
+	/*
+	 * It has been guaranteed that input parameter named mac_addr is valid
+	 * address in the rte layer of DPDK framework.
+	 */
 	old_addr = (struct rte_ether_addr *)hw->mac.mac_addr;
 	rte_spinlock_lock(&hw->lock);
 	memcpy(addr_bytes, mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN);
Signature · 1 line
2.23.0
#2 lore raw

PATCH 2/7 net/hns3: modify inappropriate names

In reply to Wei Hu (Xavier)

From: Chengchang Tang <[email protected]>

This patch modifies the name of some macro and local variable to avoid devil number and increase code readability in the internal interface function named hns3_set_port_vlan_filter.

---
 drivers/net/hns3/hns3_ethdev.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/hns3/hns3_ethdev.c +8 -6
index 614a42466..15ef03cfe 100644
@@ -232,23 +232,25 @@ hns3_interrupt_handler(void *param)
 static int
 hns3_set_port_vlan_filter(struct hns3_adapter *hns, uint16_t vlan_id, int on)
 {
-#define HNS3_VLAN_OFFSET_160		160
+#define HNS3_VLAN_ID_OFFSET_STEP	160
+#define HNS3_VLAN_BYTE_SIZE		8
 	struct hns3_vlan_filter_pf_cfg_cmd *req;
 	struct hns3_hw *hw = &hns->hw;
 	uint8_t vlan_offset_byte_val;
 	struct hns3_cmd_desc desc;
 	uint8_t vlan_offset_byte;
-	uint8_t vlan_offset_160;
+	uint8_t vlan_offset_base;
 	int ret;
 
 	hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_FILTER_PF_CFG, false);
 
-	vlan_offset_160 = vlan_id / HNS3_VLAN_OFFSET_160;
-	vlan_offset_byte = (vlan_id % HNS3_VLAN_OFFSET_160) / 8;
-	vlan_offset_byte_val = 1 << (vlan_id % 8);
+	vlan_offset_base = vlan_id / HNS3_VLAN_ID_OFFSET_STEP;
+	vlan_offset_byte = (vlan_id % HNS3_VLAN_ID_OFFSET_STEP) /
+			   HNS3_VLAN_BYTE_SIZE;
+	vlan_offset_byte_val = 1 << (vlan_id % HNS3_VLAN_BYTE_SIZE);
 
 	req = (struct hns3_vlan_filter_pf_cfg_cmd *)desc.data;
-	req->vlan_offset = vlan_offset_160;
+	req->vlan_offset = vlan_offset_base;
 	req->vlan_cfg = on ? 0 : 1;
 	req->vlan_offset_bitmap[vlan_offset_byte] = vlan_offset_byte_val;
 
Signature · 1 line
2.23.0
#3 lore raw

PATCH 3/7 net/hns3: fix packets's offload features flags in Rx

In reply to Wei Hu (Xavier)

From: Chengwen Feng <[email protected]>

Currently there is a certain probability of the unexpected ol_flag of the Rx packets's rte_mbuf when receiving packets.

The root cause as below:
1. The member variable named ol_flag of the structure named rte_mbuf is not properly initialized to zero in the '.rx_pkt_burst' ops implementation function named hns3_recv_pkts.
2. When multi-segment rte_mbufs are needed for long packet in Rx operation, the driver should assign value to the ol_flag of the first segment, not to the ol_flag of the last segment.

This patch fixes it with the following modification in the '.rx_pkt_burst' ops implementation function named hns3_recv_pkts.
1. Where the first write operation in the '.rx_pkt_burst' ops implementation function, assign PKT_RX_RSS_HASH to ol_flags directly using '=' operation instead of '|=' operation.
2. In the static function named hns3_rx_set_cksum_flag, the last rte_mbuf's ol_flags should be assigned when processing multi-segment. We fix it by passing first_seg variable to the function instead of rxm(the last segment's address).

Fixes bba636698316 ("net/hns3: support Rx/Tx and related operations")
Fixes ad7cf94823e8 ("net/hns3: fix offload flag for RSS hash")
---
 drivers/net/hns3/hns3_rxtx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/hns3/hns3_rxtx.c +3 -2
index ec6d19f58..0c965b1b8 100644
@@ -1582,7 +1582,7 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 		first_seg->pkt_len = pkt_len;
 		first_seg->port = rxq->port_id;
 		first_seg->hash.rss = rte_le_to_cpu_32(rxd.rx.rss_hash);
-		first_seg->ol_flags |= PKT_RX_RSS_HASH;
+		first_seg->ol_flags = PKT_RX_RSS_HASH;
 		if (unlikely(hns3_get_bit(bd_base_info, HNS3_RXD_LUM_B))) {
 			first_seg->hash.fdir.hi =
 				rte_le_to_cpu_32(rxd.rx.fd_id);
@@ -1599,7 +1599,8 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 								  ol_info);
 
 		if (bd_base_info & BIT(HNS3_RXD_L3L4P_B))
-			hns3_rx_set_cksum_flag(rxm, first_seg->packet_type,
+			hns3_rx_set_cksum_flag(first_seg,
+					       first_seg->packet_type,
 					       cksum_err);
 
 		first_seg->vlan_tci = rte_le_to_cpu_16(rxd.rx.vlan_tag);
Signature · 1 line
2.23.0
#4 lore raw

PATCH 4/7 net/hns3: fix default error code of command interface

In reply to Wei Hu (Xavier)

From: Chengwen Feng <[email protected]>

Currently, the hns3 PMD driver can interact with firmware through command to complete hardware configuration. The driver calls internal interface function named hns3_cmd_send to issues command to the firmware, and check the execution result of the command through desc_ret returned by firmware to driver.

As the design of error code, when device is resetting hns3_cmd_send will only return -EBUSY or -EIO. But we found that if desc_ret is in [12,65535], for example the item doesn't exist when issuing the command to query some table item, hns3_cmd_send also return -EIO. This phenomenon will affect the processing logic for the return value.

The root cause as below:
When desc_ret is in [12,65535], in the static functin named hns3_cmd_convert_err_code called by hns3_cmd_send, matches the default case and return -EIO. And then hns3_cmd_send return -EIO.

This patch fixes it with the following modification.
1. Change the return value of the default case in the static function named hns3_cmd_convert_err_code from -EIO to -EREMOTEIO.
2. Modify the comment add errcode description of the internal interface function named hns3_cmd_send.

Fixes 737f30e1c3ab ("net/hns3: support command interface with firmware")
---
 drivers/net/hns3/hns3_cmd.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/net/hns3/hns3_cmd.c +17 -5
index 5ec3dfe01..c85168b31 100644
@@ -289,7 +289,7 @@ hns3_cmd_convert_err_code(uint16_t desc_ret)
 	case HNS3_CMD_INVALID:
 		return -EBADR;
 	default:
-		return -EIO;
+		return -EREMOTEIO;
 	}
 }
 
@@ -349,11 +349,23 @@ static int hns3_cmd_poll_reply(struct hns3_hw *hw)
 
 /*
  * hns3_cmd_send - send command to command queue
- * @hw: pointer to the hw struct
- * @desc: prefilled descriptor for describing the command
- * @num : the number of descriptors to be sent
  *
- * This is the main send command for command queue, it
+ * @param hw
+ *   pointer to the hw struct
+ * @param desc
+ *   prefilled descriptor for describing the command
+ * @param num
+ *   the number of descriptors to be sent
+ * @return
+ *   - -EBUSY if detect device is in resetting
+ *   - -EIO   if detect cmd csq corrupted (due to reset) or
+ *            there is reset pending
+ *   - -ENOMEM/-ETIME/...(Non-Zero) if other error case
+ *   - Zero   if operation completed successfully
+ *
+ * Note -BUSY/-EIO only used in reset case
+ *
+ * Note this is the main send command for command queue, it
  * sends the queue, cleans the queue, etc
  */
 int
Signature · 1 line
2.23.0
#5 lore raw

PATCH 5/7 net/hns3: fix crash when flushing RSS flow rules with FLR

In reply to Wei Hu (Xavier)

From: Chengwen Feng <[email protected]>

Currently, we encoutner segmentation fault when performing the following test case:
1. Run testpmd application, config the flow filter rules then flush them repeatedly.
2. Inject FLR concurrently every 5 second.
The calltrace info:

This GDB was configured as "aarch64-linux-gnu".
Reading symbols from ./testpmd...(no debugging symbols found)...done. [New LWP 322]
[New LWP 325]
[New LWP 324]
[New LWP 326]
[New LWP 323]
[New LWP 327]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/ libthread_db.so.1".
Core was generated by `/home/root/app/testpmd -w 0000:00:01.0 -w 0000:00:02.0 -w 0000:00:03.0 -l 0-3 -'.
Program terminated with signal SIGSEGV, Segmentation fault. libc.so.6
[Current thread is 1 (Thread 0xffff8bb35110 (LWP 322))] (gdb) bt
#0 0x0000ffff8b936a90 in strlen () from /lib/aarch64-linux-gnu/ libc.so.6
#1 0x0000ffff8b905ccc in vfprintf () from /lib/aarch64-linux-gnu/ libc.so.6
#2 0x0000ffff8b993d04 in __printf_chk () from /lib/aarch64-linux-gnu/ libc.so.6
#3 0x0000000000754828 in port_flow_flush ()
#4 0x0000000000870f3c in cmdline_parse ()

The root cause as follows:
In the '.flush' ops implementation function named hns3_flow_flush, By the way the '.flush' ops is defined in the struct rte_flow_ops, if failed to call hns3_clear_rss_filter, the out parameter error is not setted, and then the member variable name message in the struct error is invalid(filled with 0x44444444 in port_flow_flush function of the testpmd application), it leads to segmentation fault when format the message.

We fixes it by filling error parameter when failure in calling static function named hns3_clear_rss_filter in the the '.flush' ops implementation function named hns3_flow_flush.

Fixes c37ca66f2b27 ("net/hns3: support RSS")
---
 drivers/net/hns3/hns3_flow.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/hns3/hns3_flow.c +4 -1
index 98affa567..559b9d02b 100644
@@ -1827,8 +1827,11 @@ hns3_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
 	}
 
 	ret = hns3_clear_rss_filter(dev);
-	if (ret)
+	if (ret) {
+		rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE,
+				   NULL, "Failed to flush rss filter");
 		return ret;
+	}
 
 	hns3_filterlist_flush(dev);
 
Signature · 1 line
2.23.0
#6 lore raw

PATCH 6/7 net/hns3: fix configuring illeagl VLAN pvid

In reply to Wei Hu (Xavier)

From: "Min Hu (Connor)" <[email protected]>

The VLAN pvid ranges from 0 to 4095. The hns3 PMD driver does not support this situation that the VLAN pvid is larger than Maximum VLAN ID(4095).

Fixes 411d23b9eafb ("net/hns3: support VLAN")
---
 drivers/net/hns3/hns3_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/hns3/hns3_ethdev.c +6 -0
index 15ef03cfe..0d0f5ebb7 100644
@@ -873,6 +873,12 @@ hns3_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
 	struct hns3_hw *hw = &hns->hw;
 	int ret;
 
+	if (pvid > RTE_ETHER_MAX_VLAN_ID) {
+		hns3_err(hw, "Invalid vlan_id = %u > %d", pvid,
+			 RTE_ETHER_MAX_VLAN_ID);
+		return -EINVAL;
+	}
+
 	rte_spinlock_lock(&hw->lock);
 	ret = hns3_vlan_pvid_configure(hns, pvid, on);
 	rte_spinlock_unlock(&hw->lock);
Signature · 1 line
2.23.0
#7 lore raw

PATCH 7/7 net/hns3: fix abnormal status after reset occurs repeatedly

In reply to Wei Hu (Xavier)

From: "Wei Hu (Xavier)" <[email protected]>

Currently, when performing the following test case:
1. Run testpmd application based on hns3 PF device.
2. Inject reset(global/IMP reset) repeatedly. After the reset, the network port can't link up.

In the RESET_STAGE_DEV_INIT stage of the reset process, the driver will reinitialize the hardware. If global/IMP reset occurs at this time again, the operation of reinitialize the hardware will fail because that firmware don't respond to the configuration commands issued by driver. In current driver, when failed to reinitialize the hardware, rollback operation is done, such as clearing the relevant configuration of the command queue registers.

If firmware detects that the function's command queue register is not configured correctly, it will not complete the reset related hardware configuration for this function, resulting in that driver can't detect that the hardware reset has been completed. And then the reset process of the driver exit abnormally, the hardware can not work normally after reset.

This patch fixes it by avoid clearing the command queue related registers when failed to reinitialize the hardware in the RESET_STAGE_DEV_INIT stage of the reset process.

Fixes 2790c6464725 ("net/hns3: support device reset")
---
 drivers/net/hns3/hns3_cmd.c       |  2 +-
 drivers/net/hns3/hns3_ethdev.c    | 18 ++++--------------
 drivers/net/hns3/hns3_ethdev_vf.c | 16 ++++------------
 3 files changed, 9 insertions(+), 27 deletions(-)
drivers/net/hns3/hns3_cmd.c +1 -1
index c85168b31..c7993634e 100644
@@ -529,7 +529,7 @@ hns3_cmd_init(struct hns3_hw *hw)
 	return 0;
 
 err_cmd_init:
-	hns3_cmd_uninit(hw);
+	rte_atomic16_set(&hw->reset.disable_cmd, 1);
 	return ret;
 }
 
drivers/net/hns3/hns3_ethdev.c +4 -14
index 0d0f5ebb7..1d57de7f9 100644
@@ -4126,13 +4126,10 @@ hns3_init_pf(struct rte_eth_dev *eth_dev)
 	rte_intr_disable(&pci_dev->intr_handle);
 	hns3_intr_unregister(&pci_dev->intr_handle, hns3_interrupt_handler,
 			     eth_dev);
-
 err_intr_callback_register:
-	hns3_cmd_uninit(hw);
-
 err_cmd_init:
+	hns3_cmd_uninit(hw);
 	hns3_cmd_destroy_queue(hw);
-
 err_cmd_init_queue:
 	hw->io_base = NULL;
 
@@ -4610,31 +4607,24 @@ hns3_reinit_dev(struct hns3_adapter *hns)
 	ret = hns3_reset_all_queues(hns);
 	if (ret) {
 		hns3_err(hw, "Failed to reset all queues: %d", ret);
-		goto err_init;
+		return ret;
 	}
 
 	ret = hns3_init_hardware(hns);
 	if (ret) {
 		hns3_err(hw, "Failed to init hardware: %d", ret);
-		goto err_init;
+		return ret;
 	}
 
 	ret = hns3_enable_hw_error_intr(hns, true);
 	if (ret) {
 		hns3_err(hw, "fail to enable hw error interrupts: %d",
 			     ret);
-		goto err_mac_init;
+		return ret;
 	}
 	hns3_info(hw, "Reset done, driver initialization finished.");
 
 	return 0;
-
-err_mac_init:
-	hns3_uninit_umv_space(hw);
-err_init:
-	hns3_cmd_uninit(hw);
-
-	return ret;
 }
 
 static bool
drivers/net/hns3/hns3_ethdev_vf.c +4 -12
index 1c508f06a..2e8acfee3 100644
@@ -1486,11 +1486,9 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev)
 	hns3_intr_unregister(&pci_dev->intr_handle, hns3vf_interrupt_handler,
 			     eth_dev);
 err_intr_callback_register:
-	hns3_cmd_uninit(hw);
-
 err_cmd_init:
+	hns3_cmd_uninit(hw);
 	hns3_cmd_destroy_queue(hw);
-
 err_cmd_init_queue:
 	hw->io_base = NULL;
 
@@ -2104,7 +2102,7 @@ hns3vf_reinit_dev(struct hns3_adapter *hns)
 	ret = hns3_cmd_init(hw);
 	if (ret) {
 		hns3_err(hw, "Failed to init cmd: %d", ret);
-		goto err_cmd_init;
+		return ret;
 	}
 
 	if (hw->reset.level == HNS3_VF_FULL_RESET) {
@@ -2124,22 +2122,16 @@ hns3vf_reinit_dev(struct hns3_adapter *hns)
 	ret = hns3_reset_all_queues(hns);
 	if (ret) {
 		hns3_err(hw, "Failed to reset all queues: %d", ret);
-		goto err_init;
+		return ret;
 	}
 
 	ret = hns3vf_init_hardware(hns);
 	if (ret) {
 		hns3_err(hw, "Failed to init hardware: %d", ret);
-		goto err_init;
+		return ret;
 	}
 
 	return 0;
-
-err_cmd_init:
-	hns3vf_set_bus_master(pci_dev, false);
-err_init:
-	hns3_cmd_uninit(hw);
-	return ret;
 }
 
 static const struct eth_dev_ops hns3vf_eth_dev_ops = {
Signature · 1 line
2.23.0
#8 lore raw
In reply to Wei Hu (Xavier)
Quoted 11 lines · Wei Hu (Xavier)

This series are updates and fixes for hns3 PMD driver.

Chengchang Tang (2):
net/hns3: remove redundant MAC addr check when setting MAC net/hns3: modify inappropriate names

Chengwen Feng (3):
net/hns3: fix packets's offload features flags in Rx net/hns3: fix default error code of command interface net/hns3: fix crash when flushing RSS flow rules with FLR

Quoted 6 lines

Min Hu (Connor) (1):
net/hns3: fix configuring illeagl VLAN pvid

Wei Hu (Xavier) (1):
net/hns3: fix abnormal status after reset occurs repeatedly

Series applied to dpdk-next-net/master, thanks.