[v21,03/13] common/zsda: add logging macros

Message ID 20241111024435.3126308-2-li.hanxiao@zte.com.cn (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series drivers/zsda: introduce zsda drivers |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Hanxiao Li Nov. 11, 2024, 2:44 a.m. UTC
Add zxdh logging implementation.

Signed-off-by: Hanxiao Li <li.hanxiao@zte.com.cn>
---
 drivers/common/zsda/meson.build   |  1 +
 drivers/common/zsda/zsda_device.c | 23 ++++++++++++++++-------
 drivers/common/zsda/zsda_logs.c   | 19 +++++++++++++++++++
 drivers/common/zsda/zsda_logs.h   | 27 +++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 7 deletions(-)
 create mode 100644 drivers/common/zsda/zsda_logs.c
 create mode 100644 drivers/common/zsda/zsda_logs.h

-- 
2.27.0
  

Patch

diff --git a/drivers/common/zsda/meson.build b/drivers/common/zsda/meson.build
index 68bc549c27..342d000c6d 100644
--- a/drivers/common/zsda/meson.build
+++ b/drivers/common/zsda/meson.build
@@ -10,4 +10,5 @@  endif
 deps += ['bus_pci', 'mbuf']
 sources += files(
 		'zsda_device.c',
+		'zsda_logs.c',
 		)
diff --git a/drivers/common/zsda/zsda_device.c b/drivers/common/zsda/zsda_device.c
index 8d691b3bb8..1be3ea8016 100644
--- a/drivers/common/zsda/zsda_device.c
+++ b/drivers/common/zsda/zsda_device.c
@@ -9,6 +9,7 @@ 
 #include <rte_bus_pci.h>
 
 #include "zsda_device.h"
+#include "zsda_logs.h"
 
 /* per-process array of device data */
 struct zsda_device_info zsda_devs[RTE_PMD_ZSDA_MAX_PCI_DEVICES];
@@ -32,9 +33,10 @@  zsda_pci_get_named_dev(const char *name)
 {
 	unsigned int i;
 
-	if (name == NULL)
+	if (name == NULL) {
+		ZSDA_LOG(ERR, "Failed! name is NULL.");
 		return NULL;
-
+	}
 	for (i = 0; i < RTE_PMD_ZSDA_MAX_PCI_DEVICES; i++) {
 		if (zsda_devs[i].mz &&
 		    (strcmp(((struct zsda_pci_device *)zsda_devs[i].mz->addr)
@@ -81,8 +83,10 @@  zsda_pci_device_allocate(struct rte_pci_device *pci_dev)
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
 		const struct rte_memzone *mz = rte_memzone_lookup(name);
 
-		if (mz == NULL)
+		if (mz == NULL) {
+			ZSDA_LOG(ERR, "Secondary can't find %s mz", name);
 			return NULL;
+		}
 		zsda_pci_dev = mz->addr;
 		zsda_devs[zsda_pci_dev->zsda_dev_id].mz = mz;
 		zsda_devs[zsda_pci_dev->zsda_dev_id].pci_dev = pci_dev;
@@ -90,8 +94,10 @@  zsda_pci_device_allocate(struct rte_pci_device *pci_dev)
 		return zsda_pci_dev;
 	}
 
-	if (zsda_pci_get_named_dev(name) != NULL)
+	if (zsda_pci_get_named_dev(name) != NULL) {
+		ZSDA_LOG(ERR, "Failed! config");
 		return NULL;
+	}
 
 	zsda_dev_id = zsda_pci_find_free_device_index();
 
@@ -102,9 +108,10 @@  zsda_pci_device_allocate(struct rte_pci_device *pci_dev)
 		rte_memzone_reserve(name, sizeof(struct zsda_pci_device),
 				    (int)(socket_id & 0xfff), 0);
 
-	if (zsda_devs[zsda_dev_id].mz == NULL)
+	if (zsda_devs[zsda_dev_id].mz == NULL) {
+		ZSDA_LOG(ERR, "Failed! malloc");
 		return NULL;
-
+	}
 	zsda_pci_dev = zsda_devs[zsda_dev_id].mz->addr;
 	memset(zsda_pci_dev, 0, sizeof(*zsda_pci_dev));
 	memcpy(zsda_pci_dev->name, name, ZSDA_DEV_NAME_MAX_LEN);
@@ -158,8 +165,10 @@  zsda_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	struct zsda_pci_device *zsda_pci_dev;
 
 	zsda_pci_dev = zsda_pci_device_allocate(pci_dev);
-	if (zsda_pci_dev == NULL)
+	if (zsda_pci_dev == NULL) {
+		ZSDA_LOG(ERR, "Failed! zsda_pci_dev is NULL");
 		return -ENODEV;
+	}
 
 	return ret;
 }
diff --git a/drivers/common/zsda/zsda_logs.c b/drivers/common/zsda/zsda_logs.c
new file mode 100644
index 0000000000..f76d9d9d0d
--- /dev/null
+++ b/drivers/common/zsda/zsda_logs.c
@@ -0,0 +1,19 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 ZTE Corporation
+ */
+
+#include <rte_hexdump.h>
+
+#include "zsda_logs.h"
+
+int
+zsda_hexdump_log(uint32_t level, uint32_t logtype, const char *title,
+		const void *buf, unsigned int len)
+{
+	if (rte_log_can_log(logtype, level))
+		rte_hexdump(rte_log_get_stream(), title, buf, len);
+
+	return 0;
+}
+
+RTE_LOG_REGISTER_SUFFIX(zsda_logtype_gen, gen, NOTICE);
diff --git a/drivers/common/zsda/zsda_logs.h b/drivers/common/zsda/zsda_logs.h
new file mode 100644
index 0000000000..9d77254773
--- /dev/null
+++ b/drivers/common/zsda/zsda_logs.h
@@ -0,0 +1,27 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 ZTE Corporation
+ */
+
+#ifndef _ZSDA_LOGS_H_
+#define _ZSDA_LOGS_H_
+
+#include <rte_log.h>
+
+extern int zsda_logtype_gen;
+#define RTE_LOGTYPE_ZSDA_GEN zsda_logtype_gen
+
+#define ZSDA_LOG(level, ...)             \
+	RTE_LOG_LINE_PREFIX(level, ZSDA_GEN, "%s(): ", \
+		__func__, __VA_ARGS__)
+
+/**
+ * zsda_hexdump_log - Dump out memory in a special hex dump format.
+ *
+ * Dump out the message buffer in a special hex dump output format with
+ * characters printed for each line of 16 hex values. The message will be sent
+ * to the stream used by the rte_log infrastructure.
+ */
+int zsda_hexdump_log(uint32_t level, uint32_t logtype, const char *title,
+		     const void *buf, unsigned int len);
+
+#endif /* _ZSDA_LOGS_H_ */