[v1,02/18] net/r8169: add logging structure

Message ID 20241015030928.70642-3-howard_wang@realsil.com.cn (mailing list archive)
State Changes Requested
Delegated to: Ferruh Yigit
Headers
Series net/r8169: add r8169 pmd to dpdk |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

王颢 Oct. 15, 2024, 3:09 a.m. UTC
Implement logging macros for debug purposes.

Signed-off-by: Howard Wang <howard_wang@realsil.com.cn>
---
 drivers/net/r8169/r8169_ethdev.c | 40 ++++++++++++++++++++++++
 drivers/net/r8169/r8169_logs.h   | 53 ++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)
 create mode 100644 drivers/net/r8169/r8169_logs.h
  

Patch

diff --git a/drivers/net/r8169/r8169_ethdev.c b/drivers/net/r8169/r8169_ethdev.c
index e5f8857304..09e12fb56d 100644
--- a/drivers/net/r8169/r8169_ethdev.c
+++ b/drivers/net/r8169/r8169_ethdev.c
@@ -177,3 +177,43 @@  RTE_PMD_REGISTER_PCI(net_r8169, rte_r8169_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_r8169, pci_id_r8169_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_r8169, "* igb_uio | uio_pci_generic | vfio-pci");
 
+int r8169_logtype_init;
+int r8169_logtype_driver;
+
+#ifdef RTE_LIBRTE_R8169_DEBUG_RX
+int r8169_logtype_rx;
+#endif
+#ifdef RTE_LIBRTE_R8169_DEBUG_TX
+int r8169_logtype_tx;
+#endif
+#ifdef RTE_LIBRTE_R8169_DEBUG_TX_FREE
+int r8169_logtype_tx_free;
+#endif
+
+RTE_INIT(r8169_init_log)
+{
+	r8169_logtype_init = rte_log_register("pmd.net.r8169.init");
+	if (r8169_logtype_init >= 0)
+		rte_log_set_level(r8169_logtype_init, RTE_LOG_NOTICE);
+	r8169_logtype_driver = rte_log_register("pmd.net.r8169.driver");
+	if (r8169_logtype_driver >= 0)
+		rte_log_set_level(r8169_logtype_driver, RTE_LOG_NOTICE);
+#ifdef RTE_LIBRTE_R8169_DEBUG_RX
+	r8169_logtype_rx = rte_log_register("pmd.net.r8169.rx");
+	if (r8169_logtype_rx >= 0)
+		rte_log_set_level(r8169_logtype_rx, RTE_LOG_DEBUG);
+#endif
+
+#ifdef RTE_LIBRTE_R8169_DEBUG_TX
+	r8169_logtype_tx = rte_log_register("pmd.net.r8169.tx");
+	if (r8169_logtype_tx >= 0)
+		rte_log_set_level(r8169_logtype_tx, RTE_LOG_DEBUG);
+#endif
+
+#ifdef RTE_LIBRTE_R8169_DEBUG_TX_FREE
+	r8169_logtype_tx_free = rte_log_register("pmd.net.r8169.tx_free");
+	if (r8169_logtype_tx_free >= 0)
+		rte_log_set_level(r8169_logtype_tx_free, RTE_LOG_DEBUG);
+#endif
+}
+
diff --git a/drivers/net/r8169/r8169_logs.h b/drivers/net/r8169/r8169_logs.h
new file mode 100644
index 0000000000..6ce5b4b5ac
--- /dev/null
+++ b/drivers/net/r8169/r8169_logs.h
@@ -0,0 +1,53 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 Realtek Corporation. All rights reserved
+ */
+
+#ifndef _R8169_LOGS_H_
+#define _R8169_LOGS_H_
+
+#include <rte_log.h>
+
+extern int r8169_logtype_init;
+#define PMD_INIT_LOG(level, fmt, args...) \
+	rte_log(RTE_LOG_ ## level, r8169_logtype_init, \
+		"%s(): " fmt "\n", __func__, ##args)
+
+#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
+
+#ifdef RTE_LIBRTE_R8169_DEBUG_RX
+extern int r8169_logtype_rx;
+#define PMD_RX_LOG(level, fmt, args...)			\
+	rte_log(RTE_LOG_ ## level, r8169_logtype_rx,	\
+		"%s(): " fmt "\n", __func__, ## args)
+#else
+#define PMD_RX_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+#ifdef RTE_LIBRTE_R8169_DEBUG_TX
+extern int r8169_logtype_tx;
+#define PMD_TX_LOG(level, fmt, args...)			\
+	rte_log(RTE_LOG_ ## level, r8169_logtype_tx,	\
+		"%s(): " fmt "\n", __func__, ## args)
+#else
+#define PMD_TX_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+#ifdef RTE_LIBRTE_R8169_DEBUG_TX_FREE
+extern int r8169_logtype_tx_free;
+#define PMD_TX_FREE_LOG(level, fmt, args...)			\
+	rte_log(RTE_LOG_ ## level, r8169_logtype_tx_free,	\
+		"%s(): " fmt "\n", __func__, ## args)
+#else
+#define PMD_TX_FREE_LOG(level, fmt, args...) do { } while (0)
+#endif
+
+extern int r8169_logtype_driver;
+#define PMD_DRV_LOG_RAW(level, fmt, args...) \
+	rte_log(RTE_LOG_ ## level, r8169_logtype_driver, "%s(): " fmt, \
+		__func__, ## args)
+
+#define PMD_DRV_LOG(level, fmt, args...) \
+	PMD_DRV_LOG_RAW(level, fmt "\n", ## args)
+
+#endif /* _R8169_LOGS_H_ */
+