@@ -10,4 +10,5 @@ endif
deps += ['bus_pci', 'mbuf']
sources += files(
'zsda_device.c',
+ 'zsda_logs.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;
}
new file mode 100644
@@ -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);
new file mode 100644
@@ -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_ */