Add zxdh logging implementation. Signed-off-by: Junlong Wang --- drivers/net/zxdh/zxdh_ethdev.c | 15 +++++++++++-- drivers/net/zxdh/zxdh_logs.h | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 drivers/net/zxdh/zxdh_logs.h diff --git a/drivers/net/zxdh/zxdh_ethdev.c b/drivers/net/zxdh/zxdh_ethdev.c index 5b6c9ec1bf..c911284423 100644 --- a/drivers/net/zxdh/zxdh_ethdev.c +++ b/drivers/net/zxdh/zxdh_ethdev.c @@ -7,6 +7,7 @@ #include #include "zxdh_ethdev.h" +#include "zxdh_logs.h" static int zxdh_eth_dev_init(struct rte_eth_dev *eth_dev) { @@ -19,13 +20,18 @@ static int zxdh_eth_dev_init(struct rte_eth_dev *eth_dev) /* Allocate memory for storing MAC addresses */ eth_dev->data->mac_addrs = rte_zmalloc("zxdh_mac", ZXDH_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN, 0); - if (eth_dev->data->mac_addrs == NULL) + if (eth_dev->data->mac_addrs == NULL) { + PMD_INIT_LOG(ERR, "Failed to allocate %d bytes store MAC addresses", + ZXDH_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN); return -ENOMEM; + } memset(hw, 0, sizeof(*hw)); hw->bar_addr[0] = (uint64_t)pci_dev->mem_resource[0].addr; - if (hw->bar_addr[0] == 0) + if (hw->bar_addr[0] == 0) { + PMD_INIT_LOG(ERR, "Bad mem resource."); return -EIO; + } hw->device_id = pci_dev->id.device_id; hw->port_id = eth_dev->data->port_id; @@ -90,3 +96,8 @@ static struct rte_pci_driver zxdh_pmd = { RTE_PMD_REGISTER_PCI(net_zxdh, zxdh_pmd); RTE_PMD_REGISTER_PCI_TABLE(net_zxdh, pci_id_zxdh_map); RTE_PMD_REGISTER_KMOD_DEP(net_zxdh, "* vfio-pci"); +RTE_LOG_REGISTER_SUFFIX(zxdh_logtype_init, init, NOTICE); +RTE_LOG_REGISTER_SUFFIX(zxdh_logtype_driver, driver, NOTICE); +RTE_LOG_REGISTER_SUFFIX(zxdh_logtype_rx, rx, NOTICE); +RTE_LOG_REGISTER_SUFFIX(zxdh_logtype_tx, tx, NOTICE); +RTE_LOG_REGISTER_SUFFIX(zxdh_logtype_msg, msg, NOTICE); diff --git a/drivers/net/zxdh/zxdh_logs.h b/drivers/net/zxdh/zxdh_logs.h new file mode 100644 index 0000000000..a8a6a3135b --- /dev/null +++ b/drivers/net/zxdh/zxdh_logs.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 ZTE Corporation + */ + +#ifndef ZXDH_LOGS_H +#define ZXDH_LOGS_H + +#include + +extern int zxdh_logtype_init; +#define RTE_LOGTYPE_ZXDH_INIT zxdh_logtype_init +#define PMD_INIT_LOG(level, ...) \ + RTE_LOG_LINE_PREFIX(level, ZXDH_INIT, "offload_zxdh %s(): ", \ + __func__, __VA_ARGS__) + +extern int zxdh_logtype_driver; +#define RTE_LOGTYPE_ZXDH_DRIVER zxdh_logtype_driver +#define PMD_DRV_LOG(level, ...) \ + RTE_LOG_LINE_PREFIX(level, ZXDH_DRIVER, "offload_zxdh %s(): ", \ + __func__, __VA_ARGS__) + +extern int zxdh_logtype_rx; +#define RTE_LOGTYPE_ZXDH_RX zxdh_logtype_rx +#define PMD_RX_LOG(level, ...) \ + RTE_LOG_LINE_PREFIX(level, ZXDH_RX, "offload_zxdh %s(): ", \ + __func__, __VA_ARGS__) + +extern int zxdh_logtype_tx; +#define RTE_LOGTYPE_ZXDH_TX zxdh_logtype_tx +#define PMD_TX_LOG(level, ...) \ + RTE_LOG_LINE_PREFIX(level, ZXDH_TX, "offload_zxdh %s(): ", \ + __func__, __VA_ARGS__) + +extern int zxdh_logtype_msg; +#define RTE_LOGTYPE_ZXDH_MSG zxdh_logtype_msg +#define PMD_MSG_LOG(level, ...) \ + RTE_LOG_LINE_PREFIX(level, ZXDH_MSG, "offload_zxdh %s(): ", \ + __func__, __VA_ARGS__) + +#endif /* ZXDH_LOGS_H */ -- 2.27.0