[v2,2/7] net/txgbe: add device arguments

Message ID 20210316105149.110904-3-jiawenwu@trustnetic.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series txgbe backplane AN training |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jiawen Wu March 16, 2021, 10:51 a.m. UTC
  Add device arguments to support runtime options. These arguments are
only set for backplane NICs.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 doc/guides/nics/txgbe.rst           | 50 +++++++++++++++++++++
 drivers/net/txgbe/base/txgbe_type.h | 36 ++++++++++++++++
 drivers/net/txgbe/txgbe_ethdev.c    | 67 +++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
  

Comments

Ferruh Yigit March 24, 2021, 10:59 a.m. UTC | #1
On 3/16/2021 10:51 AM, Jiawen Wu wrote:
> Add device arguments to support runtime options. These arguments are
> only set for backplane NICs.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>

<...>

> +
> +#define TXGBE_DEVARG_BP_AUTO		"auto"
> +#define TXGBE_DEVARG_KR_POLL		"poll"
> +#define TXGBE_DEVARG_KR_PRESENT		"present"
> +#define TXGBE_DEVARG_KX_SGMII		"sgmii"
> +#define TXGBE_DEVARG_FFE_SET		"ffe_set"
> +#define TXGBE_DEVARG_FFE_MAIN		"ffe_main"
> +#define TXGBE_DEVARG_FFE_PRE		"ffe_pre"
> +#define TXGBE_DEVARG_FFE_POST		"ffe_post"
> +

I just recognized that this patch is adding devargs without using them, and 
later patches are using them. This separates them from the full context.

Can you please add them gradually as they are used, in the same patch they are used?

Meanwhile you can add the release notes update in next version.

Thanks,
ferruh
  
Ferruh Yigit March 24, 2021, 11:01 a.m. UTC | #2
On 3/24/2021 10:59 AM, Ferruh Yigit wrote:
> On 3/16/2021 10:51 AM, Jiawen Wu wrote:
>> Add device arguments to support runtime options. These arguments are
>> only set for backplane NICs.
>>
>> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> 
> <...>
> 
>> +
>> +#define TXGBE_DEVARG_BP_AUTO        "auto"
>> +#define TXGBE_DEVARG_KR_POLL        "poll"
>> +#define TXGBE_DEVARG_KR_PRESENT        "present"
>> +#define TXGBE_DEVARG_KX_SGMII        "sgmii"
>> +#define TXGBE_DEVARG_FFE_SET        "ffe_set"
>> +#define TXGBE_DEVARG_FFE_MAIN        "ffe_main"
>> +#define TXGBE_DEVARG_FFE_PRE        "ffe_pre"
>> +#define TXGBE_DEVARG_FFE_POST        "ffe_post"
>> +
> 
> I just recognized that this patch is adding devargs without using them, and 
> later patches are using them. This separates them from the full context.
> 
> Can you please add them gradually as they are used, in the same patch they are 
> used?
> 
> Meanwhile you can add the release notes update in next version.
> 
> Thanks,
> ferruh

And I think 'auto' can be 'auto_neg', since 'auto' is too generic, but up to you.
  

Patch

diff --git a/doc/guides/nics/txgbe.rst b/doc/guides/nics/txgbe.rst
index e520f13f3..f56993c45 100644
--- a/doc/guides/nics/txgbe.rst
+++ b/doc/guides/nics/txgbe.rst
@@ -84,6 +84,56 @@  TXGBE PMD provides the following log types available for control:
 
   Extra logging of the messages during PMD initialization.
 
+Runtime Options
+~~~~~~~~~~~~~~~
+
+The following ``devargs`` options can be enabled at runtime. They must
+be passed as part of EAL arguments. For example,
+
+.. code-block:: console
+
+   dpdk-testpmd -a 01:00.0,auto=1 -- -i
+
+Please note that following ``devargs`` are only set for backplane NICs.
+
+- ``auto`` (default **1**)
+
+  Toggle behavior to use auto-negotiation mode or force mode to
+  link up backplane NICs.
+
+- ``poll`` (default **0**)
+
+  Toggle behavior to enable/disable polling mode to receive AN interrupt.
+
+- ``present`` (default **1**)
+
+  Toggle behavior to use present mode or init mode.
+
+- ``sgmii`` (default **0**)
+
+  Special treatment for KX SGMII cards.
+
+- ``ffe_set`` (default **0**)
+
+  Use to set PHY link mode and enable FFE parameters for user debugging.
+  If disabled, the FFE parameters will not take effect. Otherwise, set 1
+  for SFI mode, set 2 for KR mode, set 3 for KX4 mode, set 4 for KX mode.
+
+- ``ffe_main`` (default **27**)
+
+  PHY parameter used for user debugging. Setting other values to
+  take effect requires setting the ``ffe_set``.
+
+- ``ffe_pre`` (default **8**)
+
+  PHY parameter used for user debugging. Setting other values to
+  take effect requires setting the ``ffe_set``.
+
+- ``ffe_post`` (default **44**)
+
+  PHY parameter used for user debugging. Setting other values to
+  take effect requires setting the ``ffe_set``.
+
 Driver compilation and testing
 ------------------------------
 
diff --git a/drivers/net/txgbe/base/txgbe_type.h b/drivers/net/txgbe/base/txgbe_type.h
index 2c8a3866a..008fcb25b 100644
--- a/drivers/net/txgbe/base/txgbe_type.h
+++ b/drivers/net/txgbe/base/txgbe_type.h
@@ -682,6 +682,33 @@  struct txgbe_phy_info {
 	bool qsfp_shared_i2c_bus;
 	u32 nw_mng_if_sel;
 	u32 link_mode;
+
+	/* Some features need tri-state capability */
+	u16 ffe_set;
+	u16 ffe_main;
+	u16 ffe_pre;
+	u16 ffe_post;
+};
+
+#define TXGBE_DEVARG_BP_AUTO		"auto"
+#define TXGBE_DEVARG_KR_POLL		"poll"
+#define TXGBE_DEVARG_KR_PRESENT		"present"
+#define TXGBE_DEVARG_KX_SGMII		"sgmii"
+#define TXGBE_DEVARG_FFE_SET		"ffe_set"
+#define TXGBE_DEVARG_FFE_MAIN		"ffe_main"
+#define TXGBE_DEVARG_FFE_PRE		"ffe_pre"
+#define TXGBE_DEVARG_FFE_POST		"ffe_post"
+
+static const char * const txgbe_valid_arguments[] = {
+	TXGBE_DEVARG_BP_AUTO,
+	TXGBE_DEVARG_KR_POLL,
+	TXGBE_DEVARG_KR_PRESENT,
+	TXGBE_DEVARG_KX_SGMII,
+	TXGBE_DEVARG_FFE_SET,
+	TXGBE_DEVARG_FFE_MAIN,
+	TXGBE_DEVARG_FFE_PRE,
+	TXGBE_DEVARG_FFE_POST,
+	NULL
 };
 
 struct txgbe_mbx_stats {
@@ -720,6 +747,14 @@  enum txgbe_isb_idx {
 	TXGBE_ISB_MAX
 };
 
+struct txgbe_devargs {
+	u16 bp_log;
+	u16 auto_neg;
+	u16 poll;
+	u16 present;
+	u16 sgmii;
+};
+
 struct txgbe_hw {
 	void IOMEM *hw_addr;
 	void *back;
@@ -741,6 +776,7 @@  struct txgbe_hw {
 	int api_version;
 	bool allow_unsupported_sfp;
 	bool need_crosstalk_fix;
+	struct txgbe_devargs devarg;
 
 	uint64_t isb_dma;
 	void IOMEM *isb_mem;
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index e3c0c5d42..cc7270a1c 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -16,6 +16,7 @@ 
 #include <rte_memory.h>
 #include <rte_eal.h>
 #include <rte_alarm.h>
+#include <rte_kvargs.h>
 
 #include "txgbe_logs.h"
 #include "base/txgbe.h"
@@ -469,6 +470,71 @@  txgbe_swfw_lock_reset(struct txgbe_hw *hw)
 	hw->mac.release_swfw_sync(hw, mask);
 }
 
+static int
+txgbe_handle_devarg(__rte_unused const char *key, const char *value,
+		  void *extra_args)
+{
+	uint16_t *n = extra_args;
+
+	if (value == NULL || extra_args == NULL)
+		return -EINVAL;
+
+	*n = (uint16_t)strtoul(value, NULL, 10);
+	if (*n == USHRT_MAX && errno == ERANGE)
+		return -1;
+
+	return 0;
+}
+
+static void
+txgbe_parse_devargs(struct txgbe_hw *hw, struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvlist;
+	u16 auto_neg = 1;
+	u16 poll = 0;
+	u16 present = 1;
+	u16 sgmii = 0;
+	u16 ffe_set = 0;
+	u16 ffe_main = 27;
+	u16 ffe_pre = 8;
+	u16 ffe_post = 44;
+
+	if (devargs == NULL)
+		goto null;
+
+	kvlist = rte_kvargs_parse(devargs->args, txgbe_valid_arguments);
+	if (kvlist == NULL)
+		goto null;
+
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_BP_AUTO,
+			   &txgbe_handle_devarg, &auto_neg);
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_KR_POLL,
+			   &txgbe_handle_devarg, &poll);
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_KR_PRESENT,
+			   &txgbe_handle_devarg, &present);
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_KX_SGMII,
+			   &txgbe_handle_devarg, &sgmii);
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_FFE_SET,
+			   &txgbe_handle_devarg, &ffe_set);
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_FFE_MAIN,
+			   &txgbe_handle_devarg, &ffe_main);
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_FFE_PRE,
+			   &txgbe_handle_devarg, &ffe_pre);
+	rte_kvargs_process(kvlist, TXGBE_DEVARG_FFE_POST,
+			   &txgbe_handle_devarg, &ffe_post);
+	rte_kvargs_free(kvlist);
+
+null:
+	hw->devarg.auto_neg = auto_neg;
+	hw->devarg.poll = poll;
+	hw->devarg.present = present;
+	hw->devarg.sgmii = sgmii;
+	hw->phy.ffe_set = ffe_set;
+	hw->phy.ffe_main = ffe_main;
+	hw->phy.ffe_pre = ffe_pre;
+	hw->phy.ffe_post = ffe_post;
+}
+
 static int
 eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 {
@@ -537,6 +603,7 @@  eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 	hw->isb_dma = TMZ_PADDR(mz);
 	hw->isb_mem = TMZ_VADDR(mz);
 
+	txgbe_parse_devargs(hw, pci_dev->device.devargs);
 	/* Initialize the shared code (base driver) */
 	err = txgbe_init_shared_code(hw);
 	if (err != 0) {