DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jiawen Wu <jiawenwu@trustnetic.com>
To: dev@dpdk.org
Cc: Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [PATCH 18/19] net/txgbe: disable LLDP by default
Date: Tue, 18 Jun 2024 15:11:49 +0800	[thread overview]
Message-ID: <20240618071150.21564-19-jiawenwu@trustnetic.com> (raw)
In-Reply-To: <20240618071150.21564-1-jiawenwu@trustnetic.com>

In the new firmware versions, LLDP is enabled by default to implement
new features in other drivers. But it is useless in DPDK. So disable
it in device initialization to prevent it from affecting hardware
default behavior.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 drivers/net/txgbe/base/txgbe_eeprom.h |  3 ++
 drivers/net/txgbe/base/txgbe_hw.c     | 68 ++++++++++++++++++++++++---
 drivers/net/txgbe/base/txgbe_hw.h     |  4 +-
 drivers/net/txgbe/base/txgbe_mng.c    | 46 ++++++++++++++++++
 drivers/net/txgbe/base/txgbe_mng.h    | 13 +++++
 drivers/net/txgbe/base/txgbe_regs.h   |  2 +
 drivers/net/txgbe/base/txgbe_type.h   |  2 +
 drivers/net/txgbe/txgbe_ethdev.c      |  7 +--
 8 files changed, 133 insertions(+), 12 deletions(-)

diff --git a/drivers/net/txgbe/base/txgbe_eeprom.h b/drivers/net/txgbe/base/txgbe_eeprom.h
index 0d89ca9ebf..c10ad45ec8 100644
--- a/drivers/net/txgbe/base/txgbe_eeprom.h
+++ b/drivers/net/txgbe/base/txgbe_eeprom.h
@@ -12,6 +12,9 @@
 
 #define TXGBE_FW_VER_LEN	32
 #define TXGBE_FW_N_TXEQ		0x0002000A
+#define TXGBE_FW_SUPPORT_LLDP	0x0F
+#define TXGBE_FW_GET_LLDP	0x11
+#define TXGBE_FW_MASK		0xFF
 
 #define TXGBE_FW_PTR			0x0F
 #define TXGBE_PBANUM0_PTR		0x05
diff --git a/drivers/net/txgbe/base/txgbe_hw.c b/drivers/net/txgbe/base/txgbe_hw.c
index 7094551fee..dd5d3ea1fe 100644
--- a/drivers/net/txgbe/base/txgbe_hw.c
+++ b/drivers/net/txgbe/base/txgbe_hw.c
@@ -27,6 +27,56 @@ static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr);
 static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
 					 u16 *san_mac_offset);
 
+static s32 txgbe_is_lldp(struct txgbe_hw *hw)
+{
+	u32 tmp = 0, lldp_flash_data = 0, i;
+	s32 err = 0;
+
+	if ((hw->fw_version & TXGBE_FW_MASK) >= TXGBE_FW_GET_LLDP) {
+		err = txgbe_hic_get_lldp(hw);
+		if (err == 0)
+			return 0;
+	}
+
+	for (i = 0; i < 1024; i++) {
+		err = txgbe_flash_read_dword(hw, TXGBE_LLDP_REG + i * 4, &tmp);
+		if (err)
+			return err;
+
+		if (tmp == BIT_MASK32)
+			break;
+		lldp_flash_data = tmp;
+	}
+
+	if (lldp_flash_data & MS(hw->bus.lan_id, 1))
+		hw->lldp_enabled = true;
+	else
+		hw->lldp_enabled = false;
+
+	return 0;
+}
+
+static void txgbe_disable_lldp(struct txgbe_hw *hw)
+{
+	s32 status = 0;
+
+	if ((hw->fw_version & TXGBE_FW_MASK) < TXGBE_FW_SUPPORT_LLDP)
+		return;
+
+	status = txgbe_is_lldp(hw);
+	if (status) {
+		PMD_INIT_LOG(INFO, "Can not get LLDP status.");
+	} else if (hw->lldp_enabled) {
+		status = txgbe_hic_set_lldp(hw, false);
+		if (!status)
+			PMD_INIT_LOG(INFO,
+				"LLDP detected on port %d, turn it off by default.",
+				hw->port_id);
+		else
+			PMD_INIT_LOG(INFO, "Can not set LLDP status.");
+	}
+}
+
 /**
  * txgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
  * of flow control
@@ -272,6 +322,8 @@ s32 txgbe_init_hw(struct txgbe_hw *hw)
 	/* Get firmware version */
 	hw->phy.get_fw_version(hw, &hw->fw_version);
 
+	txgbe_disable_lldp(hw);
+
 	/* Reset the hardware */
 	status = hw->mac.reset_hw(hw);
 	if (status == 0 || status == TXGBE_ERR_SFP_NOT_PRESENT) {
@@ -2668,9 +2720,9 @@ s32 txgbe_prot_autoc_write_raptor(struct txgbe_hw *hw, bool locked, u64 autoc)
  * 1. to be sector address, when implemented erase sector command
  * 2. to be flash address when implemented read, write flash address
  *
- * Return 0 on success, return 1 on failure.
+ * Return 0 on success, return TXGBE_ERR_TIMEOUT on failure.
  */
-u32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr)
+s32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr)
 {
 	u32 cmd_val, i;
 
@@ -2685,22 +2737,24 @@ u32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr)
 	}
 
 	if (i == TXGBE_SPI_TIMEOUT)
-		return 1;
+		return TXGBE_ERR_TIMEOUT;
 
 	return 0;
 }
 
-u32 txgbe_flash_read_dword(struct txgbe_hw *hw, u32 addr)
+s32 txgbe_flash_read_dword(struct txgbe_hw *hw, u32 addr, u32 *data)
 {
-	u32 status;
+	s32 status;
 
 	status = txgbe_fmgr_cmd_op(hw, 1, addr);
-	if (status == 0x1) {
+	if (status < 0) {
 		DEBUGOUT("Read flash timeout.");
 		return status;
 	}
 
-	return rd32(hw, TXGBE_SPIDAT);
+	*data = rd32(hw, TXGBE_SPIDAT);
+
+	return 0;
 }
 
 /**
diff --git a/drivers/net/txgbe/base/txgbe_hw.h b/drivers/net/txgbe/base/txgbe_hw.h
index 4bf9da2d4c..1ed2892f61 100644
--- a/drivers/net/txgbe/base/txgbe_hw.h
+++ b/drivers/net/txgbe/base/txgbe_hw.h
@@ -112,6 +112,6 @@ s32 txgbe_prot_autoc_read_raptor(struct txgbe_hw *hw, bool *locked, u64 *value);
 s32 txgbe_prot_autoc_write_raptor(struct txgbe_hw *hw, bool locked, u64 value);
 s32 txgbe_reinit_fdir_tables(struct txgbe_hw *hw);
 bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw);
-u32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr);
-u32 txgbe_flash_read_dword(struct txgbe_hw *hw, u32 addr);
+s32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr);
+s32 txgbe_flash_read_dword(struct txgbe_hw *hw, u32 addr, u32 *data);
 #endif /* _TXGBE_HW_H_ */
diff --git a/drivers/net/txgbe/base/txgbe_mng.c b/drivers/net/txgbe/base/txgbe_mng.c
index 029a0a1fe1..20db982891 100644
--- a/drivers/net/txgbe/base/txgbe_mng.c
+++ b/drivers/net/txgbe/base/txgbe_mng.c
@@ -439,3 +439,49 @@ txgbe_mng_enabled(struct txgbe_hw *hw)
 	/* firmware does not control laser */
 	return false;
 }
+
+s32 txgbe_hic_get_lldp(struct txgbe_hw *hw)
+{
+	struct txgbe_hic_write_lldp buffer;
+	s32 err = 0;
+
+	buffer.hdr.cmd = FW_LLDP_GET_CMD;
+	buffer.hdr.buf_len = 0x1;
+	buffer.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
+	buffer.hdr.checksum = FW_DEFAULT_CHECKSUM;
+	buffer.func = hw->bus.lan_id;
+
+	err = txgbe_host_interface_command(hw, (u32 *)&buffer, sizeof(buffer),
+					   TXGBE_HI_COMMAND_TIMEOUT, true);
+	if (err)
+		return err;
+
+	if (buffer.hdr.cmd_or_resp.ret_status == FW_CEM_RESP_STATUS_SUCCESS) {
+		/* this field returns the status of LLDP */
+		if (buffer.func)
+			hw->lldp_enabled = true;
+		else
+			hw->lldp_enabled = false;
+	} else {
+		err = TXGBE_ERR_HOST_INTERFACE_COMMAND;
+	}
+
+	return err;
+}
+
+s32 txgbe_hic_set_lldp(struct txgbe_hw *hw, bool on)
+{
+	struct txgbe_hic_write_lldp buffer;
+
+	if (on)
+		buffer.hdr.cmd = FW_LLDP_SET_CMD_ON;
+	else
+		buffer.hdr.cmd = FW_LLDP_SET_CMD_OFF;
+	buffer.hdr.buf_len = 0x1;
+	buffer.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
+	buffer.hdr.checksum = FW_DEFAULT_CHECKSUM;
+	buffer.func = hw->bus.lan_id;
+
+	return txgbe_host_interface_command(hw, (u32 *)&buffer, sizeof(buffer),
+					    TXGBE_HI_COMMAND_TIMEOUT, false);
+}
diff --git a/drivers/net/txgbe/base/txgbe_mng.h b/drivers/net/txgbe/base/txgbe_mng.h
index 24d938fecf..16775862d6 100644
--- a/drivers/net/txgbe/base/txgbe_mng.h
+++ b/drivers/net/txgbe/base/txgbe_mng.h
@@ -53,6 +53,9 @@
 #define FW_PHY_TOKEN_RETRIES ((FW_PHY_TOKEN_WAIT * 1000) / FW_PHY_TOKEN_DELAY)
 #define FW_DW_OPEN_NOTIFY               0xE9
 #define FW_DW_CLOSE_NOTIFY              0xEA
+#define FW_LLDP_GET_CMD                 0xF2
+#define FW_LLDP_SET_CMD_OFF             0xF1
+#define FW_LLDP_SET_CMD_ON              0xF0
 
 #define TXGBE_CHECKSUM_CAP_ST_PASS      0x80658383
 #define TXGBE_CHECKSUM_CAP_ST_FAIL      0x70657376
@@ -171,6 +174,13 @@ struct txgbe_hic_upg_verify {
 	u32 action_flag;
 };
 
+struct txgbe_hic_write_lldp {
+	struct txgbe_hic_hdr hdr;
+	u8 func;
+	u8 pad2;
+	u16 pad3;
+};
+
 s32 txgbe_hic_sr_read(struct txgbe_hw *hw, u32 addr, u8 *buf, int len);
 s32 txgbe_hic_sr_write(struct txgbe_hw *hw, u32 addr, u8 *buf, int len);
 s32 txgbe_close_notify(struct txgbe_hw *hw);
@@ -181,4 +191,7 @@ s32 txgbe_hic_set_drv_ver(struct txgbe_hw *hw, u8 maj, u8 min, u8 build,
 s32 txgbe_hic_reset(struct txgbe_hw *hw);
 bool txgbe_mng_present(struct txgbe_hw *hw);
 bool txgbe_mng_enabled(struct txgbe_hw *hw);
+s32 txgbe_hic_get_lldp(struct txgbe_hw *hw);
+s32 txgbe_hic_set_lldp(struct txgbe_hw *hw, bool on);
+
 #endif /* _TXGBE_MNG_H_ */
diff --git a/drivers/net/txgbe/base/txgbe_regs.h b/drivers/net/txgbe/base/txgbe_regs.h
index a2984f1106..4ea4a2e3d8 100644
--- a/drivers/net/txgbe/base/txgbe_regs.h
+++ b/drivers/net/txgbe/base/txgbe_regs.h
@@ -1684,6 +1684,8 @@ enum txgbe_5tuple_protocol {
 #define TXGBE_ISBADDRL                  0x000160
 #define TXGBE_ISBADDRH                  0x000164
 
+#define TXGBE_LLDP_REG                  0x0F1000
+
 #define NVM_OROM_OFFSET		0x17
 #define NVM_OROM_BLK_LOW	0x83
 #define NVM_OROM_BLK_HI		0x84
diff --git a/drivers/net/txgbe/base/txgbe_type.h b/drivers/net/txgbe/base/txgbe_type.h
index f52736cae9..4371876649 100644
--- a/drivers/net/txgbe/base/txgbe_type.h
+++ b/drivers/net/txgbe/base/txgbe_type.h
@@ -778,10 +778,12 @@ struct txgbe_hw {
 	u16 vendor_id;
 	u16 subsystem_device_id;
 	u16 subsystem_vendor_id;
+	u8 port_id;
 	u8 revision_id;
 	bool adapter_stopped;
 	int api_version;
 	bool allow_unsupported_sfp;
+	bool lldp_enabled;
 	bool need_crosstalk_fix;
 	bool dev_start;
 	bool autoneg;
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index 700be8f83c..2fabb9fc4e 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -602,15 +602,16 @@ eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 
 	/* Vendor and Device ID need to be set before init of shared code */
 	hw->back = pci_dev;
+	hw->port_id = eth_dev->data->port_id;
 	hw->device_id = pci_dev->id.device_id;
 	hw->vendor_id = pci_dev->id.vendor_id;
 	if (pci_dev->id.subsystem_vendor_id == PCI_VENDOR_ID_WANGXUN) {
 		hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
 	} else {
-		u32 ssid;
+		u32 ssid = 0;
 
-		ssid = txgbe_flash_read_dword(hw, 0xFFFDC);
-		if (ssid == 0x1) {
+		err = txgbe_flash_read_dword(hw, 0xFFFDC, &ssid);
+		if (err) {
 			PMD_INIT_LOG(ERR,
 				"Read of internal subsystem device id failed\n");
 			return -ENODEV;
-- 
2.27.0



  parent reply	other threads:[~2024-06-18  7:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18  7:11 [PATCH 00/19] Wangxun fixes and supports Jiawen Wu
2024-06-18  7:11 ` [PATCH 01/19] net/txgbe: fix to parse tunnel packets Jiawen Wu
2024-06-18  7:11 ` [PATCH 02/19] net/txgbe: fix flow filters in VT mode Jiawen Wu
2024-06-18  7:11 ` [PATCH 03/19] net/txgbe: fix Tx hang on queue disable Jiawen Wu
2024-06-18  7:11 ` [PATCH 04/19] net/txgbe: restrict the configuration of VLAN strip offload Jiawen Wu
2024-06-18  7:11 ` [PATCH 05/19] net/txgbe: reconfigure more MAC Rx registers Jiawen Wu
2024-06-18  7:11 ` [PATCH 06/19] net/txgbe: fix VF promiscuous and allmulticast Jiawen Wu
2024-06-18  7:11 ` [PATCH 07/19] net/ngbe: special config for YT8531SH-CA PHY Jiawen Wu
2024-06-18  7:11 ` [PATCH 08/19] net/ngbe: keep PHY power down while device probing Jiawen Wu
2024-06-18  7:11 ` [PATCH 09/19] net/ngbe: add WOL and NCSI capability Jiawen Wu
2024-06-18  7:11 ` [PATCH 10/19] net/txgbe: fix hotplug remove Jiawen Wu
2024-06-18  7:11 ` [PATCH 11/19] net/ngbe: " Jiawen Wu
2024-06-18  7:11 ` [PATCH 12/19] net/txgbe: correct valid MTU range Jiawen Wu
2024-06-18  7:11 ` [PATCH 13/19] net/ngbe: " Jiawen Wu
2024-06-18  7:11 ` [PATCH 14/19] net/txgbe: fix memory leak Jiawen Wu
2024-06-18  7:11 ` [PATCH 15/19] net/ngbe: " Jiawen Wu
2024-06-18  7:11 ` [PATCH 16/19] net/txgbe: fix Rx interrupt Jiawen Wu
2024-06-18  7:11 ` [PATCH 17/19] net/ngbe: support " Jiawen Wu
2024-06-18  7:11 ` Jiawen Wu [this message]
2024-06-18  7:11 ` [PATCH 19/19] net/ngbe: disable LLDP by default Jiawen Wu
2024-06-25  1:51 ` [PATCH 00/19] Wangxun fixes and supports Jiawen Wu

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=20240618071150.21564-19-jiawenwu@trustnetic.com \
    --to=jiawenwu@trustnetic.com \
    --cc=dev@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).