[v5,05/24] net/ngbe: add log type and error type

Message ID 20210602094108.1575640-6-jiawenwu@trustnetic.com (mailing list archive)
State Changes Requested, archived
Delegated to: Andrew Rybchenko
Headers
Series net: ngbe PMD |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Jiawen Wu June 2, 2021, 9:40 a.m. UTC
  Add log type and error type to trace functions.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 doc/guides/nics/ngbe.rst            |  20 +++++
 drivers/net/ngbe/base/ngbe_status.h | 125 ++++++++++++++++++++++++++++
 drivers/net/ngbe/base/ngbe_type.h   |   1 +
 drivers/net/ngbe/ngbe_ethdev.c      |  16 ++++
 drivers/net/ngbe/ngbe_logs.h        |  46 ++++++++++
 5 files changed, 208 insertions(+)
 create mode 100644 drivers/net/ngbe/base/ngbe_status.h
 create mode 100644 drivers/net/ngbe/ngbe_logs.h
  

Comments

Andrew Rybchenko June 14, 2021, 5:54 p.m. UTC | #1
On 6/2/21 12:40 PM, Jiawen Wu wrote:
> Add log type and error type to trace functions.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> ---
>   doc/guides/nics/ngbe.rst            |  20 +++++
>   drivers/net/ngbe/base/ngbe_status.h | 125 ++++++++++++++++++++++++++++
>   drivers/net/ngbe/base/ngbe_type.h   |   1 +
>   drivers/net/ngbe/ngbe_ethdev.c      |  16 ++++
>   drivers/net/ngbe/ngbe_logs.h        |  46 ++++++++++
>   5 files changed, 208 insertions(+)
>   create mode 100644 drivers/net/ngbe/base/ngbe_status.h
>   create mode 100644 drivers/net/ngbe/ngbe_logs.h
> 
> diff --git a/doc/guides/nics/ngbe.rst b/doc/guides/nics/ngbe.rst
> index 4ec2623a05..c274a15aab 100644
> --- a/doc/guides/nics/ngbe.rst
> +++ b/doc/guides/nics/ngbe.rst
> @@ -15,6 +15,26 @@ Prerequisites
>   
>   - Follow the DPDK :ref:`Getting Started Guide for Linux <linux_gsg>` to setup the basic DPDK environment.
>   

It should be two empty lines before section start.

> +Pre-Installation Configuration
> +------------------------------
> +
> +Dynamic Logging Parameters
> +~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +One may leverage EAL option "--log-level" to change default levels
> +for the log types supported by the driver. The option is used with
> +an argument typically consisting of two parts separated by a colon.
> +
> +NGBE PMD provides the following log types available for control:
> +
> +- ``pmd.net.ngbe.driver`` (default level is **notice**)
> +
> +  Affects driver-wide messages unrelated to any particular devices.
> +
> +- ``pmd.net.ngbe.init`` (default level is **notice**)
> +
> +  Extra logging of the messages during PMD initialization.
> +

Same here.

>   Driver compilation and testing
>   ------------------------------
>   
> diff --git a/drivers/net/ngbe/base/ngbe_status.h b/drivers/net/ngbe/base/ngbe_status.h
> new file mode 100644
> index 0000000000..b1836c6479
> --- /dev/null
> +++ b/drivers/net/ngbe/base/ngbe_status.h
> @@ -0,0 +1,125 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018-2020 Beijing WangXun Technology Co., Ltd.
> + * Copyright(c) 2010-2017 Intel Corporation
> + */
> +
> +#ifndef _NGBE_STATUS_H_
> +#define _NGBE_STATUS_H_
> +
> +/* Error Codes:
> + * common error
> + * module error(simple)
> + * module error(detailed)
> + *
> + * (-256, 256): reserved for non-ngbe defined error code
> + */
> +#define TERR_BASE (0x100)
> +enum ngbe_error {
> +	TERR_NULL = TERR_BASE,
> +	TERR_ANY,
> +	TERR_NOSUPP,
> +	TERR_NOIMPL,
> +	TERR_NOMEM,
> +	TERR_NOSPACE,
> +	TERR_NOENTRY,
> +	TERR_CONFIG,
> +	TERR_ARGS,
> +	TERR_PARAM,
> +	TERR_INVALID,
> +	TERR_TIMEOUT,
> +	TERR_VERSION,
> +	TERR_REGISTER,
> +	TERR_FEATURE,
> +	TERR_RESET,
> +	TERR_AUTONEG,
> +	TERR_MBX,
> +	TERR_I2C,
> +	TERR_FC,
> +	TERR_FLASH,
> +	TERR_DEVICE,
> +	TERR_HOSTIF,
> +	TERR_SRAM,
> +	TERR_EEPROM,
> +	TERR_EEPROM_CHECKSUM,
> +	TERR_EEPROM_PROTECT,
> +	TERR_EEPROM_VERSION,
> +	TERR_MAC,
> +	TERR_MAC_ADDR,
> +	TERR_SFP,
> +	TERR_SFP_INITSEQ,
> +	TERR_SFP_PRESENT,
> +	TERR_SFP_SUPPORT,
> +	TERR_SFP_SETUP,
> +	TERR_PHY,
> +	TERR_PHY_ADDR,
> +	TERR_PHY_INIT,
> +	TERR_FDIR_CMD,
> +	TERR_FDIR_REINIT,
> +	TERR_SWFW_SYNC,
> +	TERR_SWFW_COMMAND,
> +	TERR_FC_CFG,
> +	TERR_FC_NEGO,
> +	TERR_LINK_SETUP,
> +	TERR_PCIE_PENDING,
> +	TERR_PBA_SECTION,
> +	TERR_OVERTEMP,
> +	TERR_UNDERTEMP,
> +	TERR_XPCS_POWERUP,
> +};
> +
> +/* WARNING: just for legacy compatibility */
> +#define NGBE_NOT_IMPLEMENTED 0x7FFFFFFF
> +#define NGBE_ERR_OPS_DUMMY   0x3FFFFFFF
> +
> +/* Error Codes */
> +#define NGBE_ERR_EEPROM				-(TERR_BASE + 1)
> +#define NGBE_ERR_EEPROM_CHECKSUM		-(TERR_BASE + 2)
> +#define NGBE_ERR_PHY				-(TERR_BASE + 3)
> +#define NGBE_ERR_CONFIG				-(TERR_BASE + 4)
> +#define NGBE_ERR_PARAM				-(TERR_BASE + 5)
> +#define NGBE_ERR_MAC_TYPE			-(TERR_BASE + 6)
> +#define NGBE_ERR_UNKNOWN_PHY			-(TERR_BASE + 7)
> +#define NGBE_ERR_LINK_SETUP			-(TERR_BASE + 8)
> +#define NGBE_ERR_ADAPTER_STOPPED		-(TERR_BASE + 9)
> +#define NGBE_ERR_INVALID_MAC_ADDR		-(TERR_BASE + 10)
> +#define NGBE_ERR_DEVICE_NOT_SUPPORTED		-(TERR_BASE + 11)
> +#define NGBE_ERR_MASTER_REQUESTS_PENDING	-(TERR_BASE + 12)
> +#define NGBE_ERR_INVALID_LINK_SETTINGS		-(TERR_BASE + 13)
> +#define NGBE_ERR_AUTONEG_NOT_COMPLETE		-(TERR_BASE + 14)
> +#define NGBE_ERR_RESET_FAILED			-(TERR_BASE + 15)
> +#define NGBE_ERR_SWFW_SYNC			-(TERR_BASE + 16)
> +#define NGBE_ERR_PHY_ADDR_INVALID		-(TERR_BASE + 17)
> +#define NGBE_ERR_I2C				-(TERR_BASE + 18)
> +#define NGBE_ERR_SFP_NOT_SUPPORTED		-(TERR_BASE + 19)
> +#define NGBE_ERR_SFP_NOT_PRESENT		-(TERR_BASE + 20)
> +#define NGBE_ERR_SFP_NO_INIT_SEQ_PRESENT	-(TERR_BASE + 21)
> +#define NGBE_ERR_NO_SAN_ADDR_PTR		-(TERR_BASE + 22)
> +#define NGBE_ERR_FDIR_REINIT_FAILED		-(TERR_BASE + 23)
> +#define NGBE_ERR_EEPROM_VERSION			-(TERR_BASE + 24)
> +#define NGBE_ERR_NO_SPACE			-(TERR_BASE + 25)
> +#define NGBE_ERR_OVERTEMP			-(TERR_BASE + 26)
> +#define NGBE_ERR_FC_NOT_NEGOTIATED		-(TERR_BASE + 27)
> +#define NGBE_ERR_FC_NOT_SUPPORTED		-(TERR_BASE + 28)
> +#define NGBE_ERR_SFP_SETUP_NOT_COMPLETE		-(TERR_BASE + 30)
> +#define NGBE_ERR_PBA_SECTION			-(TERR_BASE + 31)
> +#define NGBE_ERR_INVALID_ARGUMENT		-(TERR_BASE + 32)
> +#define NGBE_ERR_HOST_INTERFACE_COMMAND		-(TERR_BASE + 33)
> +#define NGBE_ERR_OUT_OF_MEM			-(TERR_BASE + 34)
> +#define NGBE_ERR_FEATURE_NOT_SUPPORTED		-(TERR_BASE + 36)
> +#define NGBE_ERR_EEPROM_PROTECTED_REGION	-(TERR_BASE + 37)
> +#define NGBE_ERR_FDIR_CMD_INCOMPLETE		-(TERR_BASE + 38)
> +#define NGBE_ERR_FW_RESP_INVALID		-(TERR_BASE + 39)
> +#define NGBE_ERR_TOKEN_RETRY			-(TERR_BASE + 40)
> +#define NGBE_ERR_FLASH_LOADING_FAILED		-(TERR_BASE + 41)
> +
> +#define NGBE_ERR_NOSUPP                        -(TERR_BASE + 42)
> +#define NGBE_ERR_UNDERTEMP                     -(TERR_BASE + 43)
> +#define NGBE_ERR_XPCS_POWER_UP_FAILED          -(TERR_BASE + 44)
> +#define NGBE_ERR_PHY_INIT_NOT_DONE             -(TERR_BASE + 45)
> +#define NGBE_ERR_TIMEOUT                       -(TERR_BASE + 46)
> +#define NGBE_ERR_REGISTER                      -(TERR_BASE + 47)
> +#define NGBE_ERR_MNG_ACCESS_FAILED             -(TERR_BASE + 49)
> +#define NGBE_ERR_PHY_TYPE                      -(TERR_BASE + 50)
> +#define NGBE_ERR_PHY_TIMEOUT                   -(TERR_BASE + 51)

Not sure that I understand how above define are related to logging.

> +
> +#endif /* _NGBE_STATUS_H_ */
> diff --git a/drivers/net/ngbe/base/ngbe_type.h b/drivers/net/ngbe/base/ngbe_type.h
> index b6bde11dcd..bcc9f74216 100644
> --- a/drivers/net/ngbe/base/ngbe_type.h
> +++ b/drivers/net/ngbe/base/ngbe_type.h
> @@ -8,6 +8,7 @@
>   
>   #define NGBE_ALIGN		128 /* as intel did */
>   
> +#include "ngbe_status.h"
>   #include "ngbe_osdep.h"
>   #include "ngbe_devids.h"
>   
> diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
> index 3431a9a9a7..f24c3e173e 100644
> --- a/drivers/net/ngbe/ngbe_ethdev.c
> +++ b/drivers/net/ngbe/ngbe_ethdev.c
> @@ -6,6 +6,7 @@
>   #include <rte_common.h>
>   #include <ethdev_pci.h>
>   
> +#include "ngbe_logs.h"
>   #include "base/ngbe.h"
>   #include "ngbe_ethdev.h"
>   
> @@ -37,6 +38,8 @@ eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
>   	struct ngbe_hw *hw = NGBE_DEV_HW(eth_dev);
>   	const struct rte_memzone *mz;
>   
> +	PMD_INIT_FUNC_TRACE();
> +
>   	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
>   		return 0;
>   
> @@ -65,6 +68,8 @@ eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
>   static int
>   eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
>   {
> +	PMD_INIT_FUNC_TRACE();
> +
>   	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
>   		return 0;
>   
> @@ -115,6 +120,8 @@ static struct rte_pci_driver rte_ngbe_pmd = {
>   static int
>   ngbe_dev_close(struct rte_eth_dev *dev)
>   {
> +	PMD_INIT_FUNC_TRACE();
> +
>   	RTE_SET_USED(dev);
>   
>   	return 0;
> @@ -124,3 +131,12 @@ RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
>   RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
>   RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");
>   
> +RTE_LOG_REGISTER(ngbe_logtype_init, pmd.net.ngbe.init, NOTICE);
> +RTE_LOG_REGISTER(ngbe_logtype_driver, pmd.net.ngbe.driver, NOTICE);
> +
> +#ifdef RTE_ETHDEV_DEBUG_RX
> +	RTE_LOG_REGISTER(ngbe_logtype_rx, pmd.net.ngbe.rx, DEBUG);
> +#endif
> +#ifdef RTE_ETHDEV_DEBUG_TX
> +	RTE_LOG_REGISTER(ngbe_logtype_tx, pmd.net.ngbe.tx, DEBUG);
> +#endif
> diff --git a/drivers/net/ngbe/ngbe_logs.h b/drivers/net/ngbe/ngbe_logs.h
> new file mode 100644
> index 0000000000..c5d1ab0930
> --- /dev/null
> +++ b/drivers/net/ngbe/ngbe_logs.h
> @@ -0,0 +1,46 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018-2020 Beijing WangXun Technology Co., Ltd.
> + * Copyright(c) 2010-2017 Intel Corporation
> + */
> +
> +#ifndef _NGBE_LOGS_H_
> +#define _NGBE_LOGS_H_
> +
> +/*
> + * PMD_USER_LOG: for user
> + */
> +extern int ngbe_logtype_init;
> +#define PMD_INIT_LOG(level, fmt, args...) \
> +	rte_log(RTE_LOG_ ## level, ngbe_logtype_init, \
> +		"%s(): " fmt "\n", __func__, ##args)
> +
> +extern int ngbe_logtype_driver;
> +#define PMD_DRV_LOG(level, fmt, args...) \
> +	rte_log(RTE_LOG_ ## level, ngbe_logtype_driver, \
> +		"%s(): " fmt "\n", __func__, ##args)
> +
> +#ifdef RTE_ETHDEV_DEBUG_RX
> +extern int ngbe_logtype_rx;
> +#define PMD_RX_LOG(level, fmt, args...) \
> +	rte_log(RTE_LOG_ ## level, ngbe_logtype_rx,	\
> +		"%s(): " fmt "\n", __func__, ##args)
> +#else
> +#define PMD_RX_LOG(level, fmt, args...) do { } while (0)
> +#endif
> +
> +#ifdef RTE_ETHDEV_DEBUG_TX
> +extern int ngbe_logtype_tx;
> +#define PMD_TX_LOG(level, fmt, args...) \
> +	rte_log(RTE_LOG_ ## level, ngbe_logtype_tx,	\
> +		"%s(): " fmt "\n", __func__, ##args)
> +#else
> +#define PMD_TX_LOG(level, fmt, args...) do { } while (0)
> +#endif
> +
> +#define TLOG_DEBUG(fmt, args...)  PMD_DRV_LOG(DEBUG, fmt, ##args)
> +
> +#define DEBUGOUT(fmt, args...)    TLOG_DEBUG(fmt, ##args)
> +#define PMD_INIT_FUNC_TRACE()     TLOG_DEBUG(" >>")
> +#define DEBUGFUNC(fmt)            TLOG_DEBUG(fmt)
> +
> +#endif /* _NGBE_LOGS_H_ */
>
  
Jiawen Wu June 15, 2021, 7:13 a.m. UTC | #2
On Tuesday, June 15, 2021 1:55 AM, Andrew Rybchenko wrote:
> On 6/2/21 12:40 PM, Jiawen Wu wrote:
> > Add log type and error type to trace functions.
> >
> > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> > ---
> >   doc/guides/nics/ngbe.rst            |  20 +++++
> >   drivers/net/ngbe/base/ngbe_status.h | 125
> ++++++++++++++++++++++++++++
> >   drivers/net/ngbe/base/ngbe_type.h   |   1 +
> >   drivers/net/ngbe/ngbe_ethdev.c      |  16 ++++
> >   drivers/net/ngbe/ngbe_logs.h        |  46 ++++++++++
> >   5 files changed, 208 insertions(+)
> >   create mode 100644 drivers/net/ngbe/base/ngbe_status.h
> >   create mode 100644 drivers/net/ngbe/ngbe_logs.h
> >
> > diff --git a/doc/guides/nics/ngbe.rst b/doc/guides/nics/ngbe.rst index
> > 4ec2623a05..c274a15aab 100644
> > --- a/doc/guides/nics/ngbe.rst
> > +++ b/doc/guides/nics/ngbe.rst
> > @@ -15,6 +15,26 @@ Prerequisites
> >
> >   - Follow the DPDK :ref:`Getting Started Guide for Linux <linux_gsg>` to
> setup the basic DPDK environment.
> >
> 
> It should be two empty lines before section start.
> 
> > +Pre-Installation Configuration
> > +------------------------------
> > +
> > +Dynamic Logging Parameters
> > +~~~~~~~~~~~~~~~~~~~~~~~~~~
> > +
> > +One may leverage EAL option "--log-level" to change default levels
> > +for the log types supported by the driver. The option is used with an
> > +argument typically consisting of two parts separated by a colon.
> > +
> > +NGBE PMD provides the following log types available for control:
> > +
> > +- ``pmd.net.ngbe.driver`` (default level is **notice**)
> > +
> > +  Affects driver-wide messages unrelated to any particular devices.
> > +
> > +- ``pmd.net.ngbe.init`` (default level is **notice**)
> > +
> > +  Extra logging of the messages during PMD initialization.
> > +
> 
> Same here.
> 
> >   Driver compilation and testing
> >   ------------------------------
> >
> > diff --git a/drivers/net/ngbe/base/ngbe_status.h
> > b/drivers/net/ngbe/base/ngbe_status.h
> > new file mode 100644
> > index 0000000000..b1836c6479
> > --- /dev/null
> > +++ b/drivers/net/ngbe/base/ngbe_status.h
> > @@ -0,0 +1,125 @@
> > +/* SPDX-License-Identifier: BSD-3-Clause
> > + * Copyright(c) 2018-2020 Beijing WangXun Technology Co., Ltd.
> > + * Copyright(c) 2010-2017 Intel Corporation  */
> > +
> > +#ifndef _NGBE_STATUS_H_
> > +#define _NGBE_STATUS_H_
> > +
> > +/* Error Codes:
> > + * common error
> > + * module error(simple)
> > + * module error(detailed)
> > + *
> > + * (-256, 256): reserved for non-ngbe defined error code  */ #define
> > +TERR_BASE (0x100) enum ngbe_error {
> > +	TERR_NULL = TERR_BASE,
> > +	TERR_ANY,
> > +	TERR_NOSUPP,
> > +	TERR_NOIMPL,
> > +	TERR_NOMEM,
> > +	TERR_NOSPACE,
> > +	TERR_NOENTRY,
> > +	TERR_CONFIG,
> > +	TERR_ARGS,
> > +	TERR_PARAM,
> > +	TERR_INVALID,
> > +	TERR_TIMEOUT,
> > +	TERR_VERSION,
> > +	TERR_REGISTER,
> > +	TERR_FEATURE,
> > +	TERR_RESET,
> > +	TERR_AUTONEG,
> > +	TERR_MBX,
> > +	TERR_I2C,
> > +	TERR_FC,
> > +	TERR_FLASH,
> > +	TERR_DEVICE,
> > +	TERR_HOSTIF,
> > +	TERR_SRAM,
> > +	TERR_EEPROM,
> > +	TERR_EEPROM_CHECKSUM,
> > +	TERR_EEPROM_PROTECT,
> > +	TERR_EEPROM_VERSION,
> > +	TERR_MAC,
> > +	TERR_MAC_ADDR,
> > +	TERR_SFP,
> > +	TERR_SFP_INITSEQ,
> > +	TERR_SFP_PRESENT,
> > +	TERR_SFP_SUPPORT,
> > +	TERR_SFP_SETUP,
> > +	TERR_PHY,
> > +	TERR_PHY_ADDR,
> > +	TERR_PHY_INIT,
> > +	TERR_FDIR_CMD,
> > +	TERR_FDIR_REINIT,
> > +	TERR_SWFW_SYNC,
> > +	TERR_SWFW_COMMAND,
> > +	TERR_FC_CFG,
> > +	TERR_FC_NEGO,
> > +	TERR_LINK_SETUP,
> > +	TERR_PCIE_PENDING,
> > +	TERR_PBA_SECTION,
> > +	TERR_OVERTEMP,
> > +	TERR_UNDERTEMP,
> > +	TERR_XPCS_POWERUP,
> > +};
> > +
> > +/* WARNING: just for legacy compatibility */ #define
> > +NGBE_NOT_IMPLEMENTED 0x7FFFFFFF
> > +#define NGBE_ERR_OPS_DUMMY   0x3FFFFFFF
> > +
> > +/* Error Codes */
> > +#define NGBE_ERR_EEPROM				-(TERR_BASE + 1)
> > +#define NGBE_ERR_EEPROM_CHECKSUM		-(TERR_BASE + 2)
> > +#define NGBE_ERR_PHY				-(TERR_BASE + 3)
> > +#define NGBE_ERR_CONFIG				-(TERR_BASE + 4)
> > +#define NGBE_ERR_PARAM				-(TERR_BASE + 5)
> > +#define NGBE_ERR_MAC_TYPE			-(TERR_BASE + 6)
> > +#define NGBE_ERR_UNKNOWN_PHY			-(TERR_BASE + 7)
> > +#define NGBE_ERR_LINK_SETUP			-(TERR_BASE + 8)
> > +#define NGBE_ERR_ADAPTER_STOPPED		-(TERR_BASE + 9)
> > +#define NGBE_ERR_INVALID_MAC_ADDR		-(TERR_BASE + 10)
> > +#define NGBE_ERR_DEVICE_NOT_SUPPORTED		-(TERR_BASE + 11)
> > +#define NGBE_ERR_MASTER_REQUESTS_PENDING	-(TERR_BASE + 12)
> > +#define NGBE_ERR_INVALID_LINK_SETTINGS		-(TERR_BASE + 13)
> > +#define NGBE_ERR_AUTONEG_NOT_COMPLETE		-(TERR_BASE + 14)
> > +#define NGBE_ERR_RESET_FAILED			-(TERR_BASE + 15)
> > +#define NGBE_ERR_SWFW_SYNC			-(TERR_BASE + 16)
> > +#define NGBE_ERR_PHY_ADDR_INVALID		-(TERR_BASE + 17)
> > +#define NGBE_ERR_I2C				-(TERR_BASE + 18)
> > +#define NGBE_ERR_SFP_NOT_SUPPORTED		-(TERR_BASE + 19)
> > +#define NGBE_ERR_SFP_NOT_PRESENT		-(TERR_BASE + 20)
> > +#define NGBE_ERR_SFP_NO_INIT_SEQ_PRESENT	-(TERR_BASE + 21)
> > +#define NGBE_ERR_NO_SAN_ADDR_PTR		-(TERR_BASE + 22)
> > +#define NGBE_ERR_FDIR_REINIT_FAILED		-(TERR_BASE + 23)
> > +#define NGBE_ERR_EEPROM_VERSION			-(TERR_BASE + 24)
> > +#define NGBE_ERR_NO_SPACE			-(TERR_BASE + 25)
> > +#define NGBE_ERR_OVERTEMP			-(TERR_BASE + 26)
> > +#define NGBE_ERR_FC_NOT_NEGOTIATED		-(TERR_BASE + 27)
> > +#define NGBE_ERR_FC_NOT_SUPPORTED		-(TERR_BASE + 28)
> > +#define NGBE_ERR_SFP_SETUP_NOT_COMPLETE		-(TERR_BASE + 30)
> > +#define NGBE_ERR_PBA_SECTION			-(TERR_BASE + 31)
> > +#define NGBE_ERR_INVALID_ARGUMENT		-(TERR_BASE + 32)
> > +#define NGBE_ERR_HOST_INTERFACE_COMMAND		-(TERR_BASE + 33)
> > +#define NGBE_ERR_OUT_OF_MEM			-(TERR_BASE + 34)
> > +#define NGBE_ERR_FEATURE_NOT_SUPPORTED		-(TERR_BASE + 36)
> > +#define NGBE_ERR_EEPROM_PROTECTED_REGION	-(TERR_BASE + 37)
> > +#define NGBE_ERR_FDIR_CMD_INCOMPLETE		-(TERR_BASE + 38)
> > +#define NGBE_ERR_FW_RESP_INVALID		-(TERR_BASE + 39)
> > +#define NGBE_ERR_TOKEN_RETRY			-(TERR_BASE + 40)
> > +#define NGBE_ERR_FLASH_LOADING_FAILED		-(TERR_BASE + 41)
> > +
> > +#define NGBE_ERR_NOSUPP                        -(TERR_BASE + 42)
> > +#define NGBE_ERR_UNDERTEMP                     -(TERR_BASE + 43)
> > +#define NGBE_ERR_XPCS_POWER_UP_FAILED          -(TERR_BASE + 44)
> > +#define NGBE_ERR_PHY_INIT_NOT_DONE             -(TERR_BASE + 45)
> > +#define NGBE_ERR_TIMEOUT                       -(TERR_BASE + 46)
> > +#define NGBE_ERR_REGISTER                      -(TERR_BASE + 47)
> > +#define NGBE_ERR_MNG_ACCESS_FAILED             -(TERR_BASE + 49)
> > +#define NGBE_ERR_PHY_TYPE                      -(TERR_BASE + 50)
> > +#define NGBE_ERR_PHY_TIMEOUT                   -(TERR_BASE + 51)
> 
> Not sure that I understand how above define are related to logging.

Above redundant code was not handled properly in the early.
I'll remove enum ngbe_error, and use above macro defines to return different errors.
  
David Marchand July 1, 2021, 1:57 p.m. UTC | #3
Hello,

Currently looking at new drivers posted on the ml.


On Wed, Jun 2, 2021 at 11:40 AM Jiawen Wu <jiawenwu@trustnetic.com> wrote:
> @@ -124,3 +131,12 @@ RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
>  RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
>  RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");
>
> +RTE_LOG_REGISTER(ngbe_logtype_init, pmd.net.ngbe.init, NOTICE);
> +RTE_LOG_REGISTER(ngbe_logtype_driver, pmd.net.ngbe.driver, NOTICE);

Please use helpers added recently:
https://git.dpdk.org/dpdk/commit/?id=eeded2044af5bbe88220120b14933536cbb3edb6

Converting this patch should be quick:
RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_init, init, NOTICE)
RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_driver, driver, NOTICE);

etc...

> +
> +#ifdef RTE_ETHDEV_DEBUG_RX
> +       RTE_LOG_REGISTER(ngbe_logtype_rx, pmd.net.ngbe.rx, DEBUG);
> +#endif
> +#ifdef RTE_ETHDEV_DEBUG_TX
> +       RTE_LOG_REGISTER(ngbe_logtype_tx, pmd.net.ngbe.tx, DEBUG);
> +#endif
  
Jiawen Wu July 2, 2021, 2:08 a.m. UTC | #4
On July 1, 2021 9:57 PM, David Marchand wrote:
> Hello,
> 
> Currently looking at new drivers posted on the ml.
> 
> 
> On Wed, Jun 2, 2021 at 11:40 AM Jiawen Wu <jiawenwu@trustnetic.com>
> wrote:
> > @@ -124,3 +131,12 @@ RTE_PMD_REGISTER_PCI(net_ngbe,
> rte_ngbe_pmd);
> > RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
> > RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic |
> > vfio-pci");
> >
> > +RTE_LOG_REGISTER(ngbe_logtype_init, pmd.net.ngbe.init, NOTICE);
> > +RTE_LOG_REGISTER(ngbe_logtype_driver, pmd.net.ngbe.driver, NOTICE);
> 
> Please use helpers added recently:
> https://git.dpdk.org/dpdk/commit/?id=eeded2044af5bbe88220120b14933536c
> bb3edb6
> 
> Converting this patch should be quick:
> RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_init, init, NOTICE)
> RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_driver, driver, NOTICE);
> 
> etc...
> 
> > +
> > +#ifdef RTE_ETHDEV_DEBUG_RX
> > +       RTE_LOG_REGISTER(ngbe_logtype_rx, pmd.net.ngbe.rx, DEBUG);
> > +#endif #ifdef RTE_ETHDEV_DEBUG_TX
> > +       RTE_LOG_REGISTER(ngbe_logtype_tx, pmd.net.ngbe.tx, DEBUG);
> > +#endif
> 
> 
> 
> --
> David Marchand

Thanks David,
I'd like to convert it in the patch set v6. And are there any comments on other patches?
  

Patch

diff --git a/doc/guides/nics/ngbe.rst b/doc/guides/nics/ngbe.rst
index 4ec2623a05..c274a15aab 100644
--- a/doc/guides/nics/ngbe.rst
+++ b/doc/guides/nics/ngbe.rst
@@ -15,6 +15,26 @@  Prerequisites
 
 - Follow the DPDK :ref:`Getting Started Guide for Linux <linux_gsg>` to setup the basic DPDK environment.
 
+Pre-Installation Configuration
+------------------------------
+
+Dynamic Logging Parameters
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+One may leverage EAL option "--log-level" to change default levels
+for the log types supported by the driver. The option is used with
+an argument typically consisting of two parts separated by a colon.
+
+NGBE PMD provides the following log types available for control:
+
+- ``pmd.net.ngbe.driver`` (default level is **notice**)
+
+  Affects driver-wide messages unrelated to any particular devices.
+
+- ``pmd.net.ngbe.init`` (default level is **notice**)
+
+  Extra logging of the messages during PMD initialization.
+
 Driver compilation and testing
 ------------------------------
 
diff --git a/drivers/net/ngbe/base/ngbe_status.h b/drivers/net/ngbe/base/ngbe_status.h
new file mode 100644
index 0000000000..b1836c6479
--- /dev/null
+++ b/drivers/net/ngbe/base/ngbe_status.h
@@ -0,0 +1,125 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018-2020 Beijing WangXun Technology Co., Ltd.
+ * Copyright(c) 2010-2017 Intel Corporation
+ */
+
+#ifndef _NGBE_STATUS_H_
+#define _NGBE_STATUS_H_
+
+/* Error Codes:
+ * common error
+ * module error(simple)
+ * module error(detailed)
+ *
+ * (-256, 256): reserved for non-ngbe defined error code
+ */
+#define TERR_BASE (0x100)
+enum ngbe_error {
+	TERR_NULL = TERR_BASE,
+	TERR_ANY,
+	TERR_NOSUPP,
+	TERR_NOIMPL,
+	TERR_NOMEM,
+	TERR_NOSPACE,
+	TERR_NOENTRY,
+	TERR_CONFIG,
+	TERR_ARGS,
+	TERR_PARAM,
+	TERR_INVALID,
+	TERR_TIMEOUT,
+	TERR_VERSION,
+	TERR_REGISTER,
+	TERR_FEATURE,
+	TERR_RESET,
+	TERR_AUTONEG,
+	TERR_MBX,
+	TERR_I2C,
+	TERR_FC,
+	TERR_FLASH,
+	TERR_DEVICE,
+	TERR_HOSTIF,
+	TERR_SRAM,
+	TERR_EEPROM,
+	TERR_EEPROM_CHECKSUM,
+	TERR_EEPROM_PROTECT,
+	TERR_EEPROM_VERSION,
+	TERR_MAC,
+	TERR_MAC_ADDR,
+	TERR_SFP,
+	TERR_SFP_INITSEQ,
+	TERR_SFP_PRESENT,
+	TERR_SFP_SUPPORT,
+	TERR_SFP_SETUP,
+	TERR_PHY,
+	TERR_PHY_ADDR,
+	TERR_PHY_INIT,
+	TERR_FDIR_CMD,
+	TERR_FDIR_REINIT,
+	TERR_SWFW_SYNC,
+	TERR_SWFW_COMMAND,
+	TERR_FC_CFG,
+	TERR_FC_NEGO,
+	TERR_LINK_SETUP,
+	TERR_PCIE_PENDING,
+	TERR_PBA_SECTION,
+	TERR_OVERTEMP,
+	TERR_UNDERTEMP,
+	TERR_XPCS_POWERUP,
+};
+
+/* WARNING: just for legacy compatibility */
+#define NGBE_NOT_IMPLEMENTED 0x7FFFFFFF
+#define NGBE_ERR_OPS_DUMMY   0x3FFFFFFF
+
+/* Error Codes */
+#define NGBE_ERR_EEPROM				-(TERR_BASE + 1)
+#define NGBE_ERR_EEPROM_CHECKSUM		-(TERR_BASE + 2)
+#define NGBE_ERR_PHY				-(TERR_BASE + 3)
+#define NGBE_ERR_CONFIG				-(TERR_BASE + 4)
+#define NGBE_ERR_PARAM				-(TERR_BASE + 5)
+#define NGBE_ERR_MAC_TYPE			-(TERR_BASE + 6)
+#define NGBE_ERR_UNKNOWN_PHY			-(TERR_BASE + 7)
+#define NGBE_ERR_LINK_SETUP			-(TERR_BASE + 8)
+#define NGBE_ERR_ADAPTER_STOPPED		-(TERR_BASE + 9)
+#define NGBE_ERR_INVALID_MAC_ADDR		-(TERR_BASE + 10)
+#define NGBE_ERR_DEVICE_NOT_SUPPORTED		-(TERR_BASE + 11)
+#define NGBE_ERR_MASTER_REQUESTS_PENDING	-(TERR_BASE + 12)
+#define NGBE_ERR_INVALID_LINK_SETTINGS		-(TERR_BASE + 13)
+#define NGBE_ERR_AUTONEG_NOT_COMPLETE		-(TERR_BASE + 14)
+#define NGBE_ERR_RESET_FAILED			-(TERR_BASE + 15)
+#define NGBE_ERR_SWFW_SYNC			-(TERR_BASE + 16)
+#define NGBE_ERR_PHY_ADDR_INVALID		-(TERR_BASE + 17)
+#define NGBE_ERR_I2C				-(TERR_BASE + 18)
+#define NGBE_ERR_SFP_NOT_SUPPORTED		-(TERR_BASE + 19)
+#define NGBE_ERR_SFP_NOT_PRESENT		-(TERR_BASE + 20)
+#define NGBE_ERR_SFP_NO_INIT_SEQ_PRESENT	-(TERR_BASE + 21)
+#define NGBE_ERR_NO_SAN_ADDR_PTR		-(TERR_BASE + 22)
+#define NGBE_ERR_FDIR_REINIT_FAILED		-(TERR_BASE + 23)
+#define NGBE_ERR_EEPROM_VERSION			-(TERR_BASE + 24)
+#define NGBE_ERR_NO_SPACE			-(TERR_BASE + 25)
+#define NGBE_ERR_OVERTEMP			-(TERR_BASE + 26)
+#define NGBE_ERR_FC_NOT_NEGOTIATED		-(TERR_BASE + 27)
+#define NGBE_ERR_FC_NOT_SUPPORTED		-(TERR_BASE + 28)
+#define NGBE_ERR_SFP_SETUP_NOT_COMPLETE		-(TERR_BASE + 30)
+#define NGBE_ERR_PBA_SECTION			-(TERR_BASE + 31)
+#define NGBE_ERR_INVALID_ARGUMENT		-(TERR_BASE + 32)
+#define NGBE_ERR_HOST_INTERFACE_COMMAND		-(TERR_BASE + 33)
+#define NGBE_ERR_OUT_OF_MEM			-(TERR_BASE + 34)
+#define NGBE_ERR_FEATURE_NOT_SUPPORTED		-(TERR_BASE + 36)
+#define NGBE_ERR_EEPROM_PROTECTED_REGION	-(TERR_BASE + 37)
+#define NGBE_ERR_FDIR_CMD_INCOMPLETE		-(TERR_BASE + 38)
+#define NGBE_ERR_FW_RESP_INVALID		-(TERR_BASE + 39)
+#define NGBE_ERR_TOKEN_RETRY			-(TERR_BASE + 40)
+#define NGBE_ERR_FLASH_LOADING_FAILED		-(TERR_BASE + 41)
+
+#define NGBE_ERR_NOSUPP                        -(TERR_BASE + 42)
+#define NGBE_ERR_UNDERTEMP                     -(TERR_BASE + 43)
+#define NGBE_ERR_XPCS_POWER_UP_FAILED          -(TERR_BASE + 44)
+#define NGBE_ERR_PHY_INIT_NOT_DONE             -(TERR_BASE + 45)
+#define NGBE_ERR_TIMEOUT                       -(TERR_BASE + 46)
+#define NGBE_ERR_REGISTER                      -(TERR_BASE + 47)
+#define NGBE_ERR_MNG_ACCESS_FAILED             -(TERR_BASE + 49)
+#define NGBE_ERR_PHY_TYPE                      -(TERR_BASE + 50)
+#define NGBE_ERR_PHY_TIMEOUT                   -(TERR_BASE + 51)
+
+#endif /* _NGBE_STATUS_H_ */
diff --git a/drivers/net/ngbe/base/ngbe_type.h b/drivers/net/ngbe/base/ngbe_type.h
index b6bde11dcd..bcc9f74216 100644
--- a/drivers/net/ngbe/base/ngbe_type.h
+++ b/drivers/net/ngbe/base/ngbe_type.h
@@ -8,6 +8,7 @@ 
 
 #define NGBE_ALIGN		128 /* as intel did */
 
+#include "ngbe_status.h"
 #include "ngbe_osdep.h"
 #include "ngbe_devids.h"
 
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 3431a9a9a7..f24c3e173e 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -6,6 +6,7 @@ 
 #include <rte_common.h>
 #include <ethdev_pci.h>
 
+#include "ngbe_logs.h"
 #include "base/ngbe.h"
 #include "ngbe_ethdev.h"
 
@@ -37,6 +38,8 @@  eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 	struct ngbe_hw *hw = NGBE_DEV_HW(eth_dev);
 	const struct rte_memzone *mz;
 
+	PMD_INIT_FUNC_TRACE();
+
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
@@ -65,6 +68,8 @@  eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 static int
 eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
 {
+	PMD_INIT_FUNC_TRACE();
+
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
@@ -115,6 +120,8 @@  static struct rte_pci_driver rte_ngbe_pmd = {
 static int
 ngbe_dev_close(struct rte_eth_dev *dev)
 {
+	PMD_INIT_FUNC_TRACE();
+
 	RTE_SET_USED(dev);
 
 	return 0;
@@ -124,3 +131,12 @@  RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");
 
+RTE_LOG_REGISTER(ngbe_logtype_init, pmd.net.ngbe.init, NOTICE);
+RTE_LOG_REGISTER(ngbe_logtype_driver, pmd.net.ngbe.driver, NOTICE);
+
+#ifdef RTE_ETHDEV_DEBUG_RX
+	RTE_LOG_REGISTER(ngbe_logtype_rx, pmd.net.ngbe.rx, DEBUG);
+#endif
+#ifdef RTE_ETHDEV_DEBUG_TX
+	RTE_LOG_REGISTER(ngbe_logtype_tx, pmd.net.ngbe.tx, DEBUG);
+#endif
diff --git a/drivers/net/ngbe/ngbe_logs.h b/drivers/net/ngbe/ngbe_logs.h
new file mode 100644
index 0000000000..c5d1ab0930
--- /dev/null
+++ b/drivers/net/ngbe/ngbe_logs.h
@@ -0,0 +1,46 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018-2020 Beijing WangXun Technology Co., Ltd.
+ * Copyright(c) 2010-2017 Intel Corporation
+ */
+
+#ifndef _NGBE_LOGS_H_
+#define _NGBE_LOGS_H_
+
+/*
+ * PMD_USER_LOG: for user
+ */
+extern int ngbe_logtype_init;
+#define PMD_INIT_LOG(level, fmt, args...) \
+	rte_log(RTE_LOG_ ## level, ngbe_logtype_init, \
+		"%s(): " fmt "\n", __func__, ##args)
+
+extern int ngbe_logtype_driver;
+#define PMD_DRV_LOG(level, fmt, args...) \
+	rte_log(RTE_LOG_ ## level, ngbe_logtype_driver, \
+		"%s(): " fmt "\n", __func__, ##args)
+
+#ifdef RTE_ETHDEV_DEBUG_RX
+extern int ngbe_logtype_rx;
+#define PMD_RX_LOG(level, fmt, args...) \
+	rte_log(RTE_LOG_ ## level, ngbe_logtype_rx,	\
+		"%s(): " fmt "\n", __func__, ##args)
+#else
+#define PMD_RX_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+extern int ngbe_logtype_tx;
+#define PMD_TX_LOG(level, fmt, args...) \
+	rte_log(RTE_LOG_ ## level, ngbe_logtype_tx,	\
+		"%s(): " fmt "\n", __func__, ##args)
+#else
+#define PMD_TX_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+#define TLOG_DEBUG(fmt, args...)  PMD_DRV_LOG(DEBUG, fmt, ##args)
+
+#define DEBUGOUT(fmt, args...)    TLOG_DEBUG(fmt, ##args)
+#define PMD_INIT_FUNC_TRACE()     TLOG_DEBUG(" >>")
+#define DEBUGFUNC(fmt)            TLOG_DEBUG(fmt)
+
+#endif /* _NGBE_LOGS_H_ */