Skip to content

Commit

Permalink
raw/cnxk_gpio: switch to dynamic logging
Browse files Browse the repository at this point in the history
Dynamically allocated log type is a standard approach among all drivers.
Switch to it.

Signed-off-by: Tomasz Duszynski <[email protected]>
  • Loading branch information
Tomasz Duszynski authored and jerinjacobk committed Dec 5, 2023
1 parent a526461 commit 87d934b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
22 changes: 12 additions & 10 deletions drivers/raw/cnxk_gpio/cnxk_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <rte_eal.h>
#include <rte_kvargs.h>
#include <rte_lcore.h>
#include <rte_log.h>
#include <rte_rawdev_pmd.h>

#include <roc_api.h>
Expand Down Expand Up @@ -215,13 +216,13 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
errno = 0;
val = strtol(token, NULL, 10);
if (errno) {
RTE_LOG(ERR, PMD, "failed to parse %s\n", token);
CNXK_GPIO_LOG(ERR, "failed to parse %s", token);
ret = -errno;
goto out;
}

if (val < 0 || val >= gpiochip->num_gpios) {
RTE_LOG(ERR, PMD, "gpio%d out of 0-%d range\n", val,
CNXK_GPIO_LOG(ERR, "gpio%d out of 0-%d range", val,
gpiochip->num_gpios - 1);
ret = -EINVAL;
goto out;
Expand All @@ -231,7 +232,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
if (list[i] != val)
continue;

RTE_LOG(WARNING, PMD, "gpio%d already allowed\n", val);
CNXK_GPIO_LOG(WARNING, "gpio%d already allowed", val);
break;
}
if (i == queue)
Expand Down Expand Up @@ -398,7 +399,7 @@ cnxk_gpio_queue_setup(struct rte_rawdev *dev, uint16_t queue_id,
return ret;
}
} else {
RTE_LOG(WARNING, PMD, "using existing gpio%d\n", gpio->num);
CNXK_GPIO_LOG(WARNING, "using existing gpio%d", gpio->num);
}

gpiochip->gpios[num] = gpio;
Expand Down Expand Up @@ -647,7 +648,7 @@ cnxk_gpio_process_buf(struct cnxk_gpio *gpio, struct rte_rawdev_buf *rbuf)

/* get rid of last response if any */
if (gpio->rsp) {
RTE_LOG(WARNING, PMD, "previous response got overwritten\n");
CNXK_GPIO_LOG(WARNING, "previous response got overwritten");
rte_free(gpio->rsp);
}
gpio->rsp = rsp;
Expand Down Expand Up @@ -741,7 +742,7 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
cnxk_gpio_format_name(name, sizeof(name));
rawdev = rte_rawdev_pmd_allocate(name, sizeof(*gpiochip), rte_socket_id());
if (!rawdev) {
RTE_LOG(ERR, PMD, "failed to allocate %s rawdev\n", name);
CNXK_GPIO_LOG(ERR, "failed to allocate %s rawdev", name);
return -ENOMEM;
}

Expand Down Expand Up @@ -770,28 +771,28 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
snprintf(buf, sizeof(buf), "%s/gpiochip%d/base", CNXK_GPIO_CLASS_PATH, gpiochip->num);
ret = cnxk_gpio_read_attr_int(buf, &gpiochip->base);
if (ret) {
RTE_LOG(ERR, PMD, "failed to read %s\n", buf);
CNXK_GPIO_LOG(ERR, "failed to read %s", buf);
goto out;
}

/* read number of available gpios */
snprintf(buf, sizeof(buf), "%s/gpiochip%d/ngpio", CNXK_GPIO_CLASS_PATH, gpiochip->num);
ret = cnxk_gpio_read_attr_int(buf, &gpiochip->num_gpios);
if (ret) {
RTE_LOG(ERR, PMD, "failed to read %s\n", buf);
CNXK_GPIO_LOG(ERR, "failed to read %s", buf);
goto out;
}
gpiochip->num_queues = gpiochip->num_gpios;

ret = cnxk_gpio_parse_allowlist(gpiochip, params->allowlist);
if (ret) {
RTE_LOG(ERR, PMD, "failed to parse allowed gpios\n");
CNXK_GPIO_LOG(ERR, "failed to parse allowed gpios");
goto out;
}

gpiochip->gpios = rte_calloc(NULL, gpiochip->num_gpios, sizeof(struct cnxk_gpio *), 0);
if (!gpiochip->gpios) {
RTE_LOG(ERR, PMD, "failed to allocate gpios memory\n");
CNXK_GPIO_LOG(ERR, "failed to allocate gpios memory");
ret = -ENOMEM;
goto out;
}
Expand Down Expand Up @@ -851,3 +852,4 @@ RTE_PMD_REGISTER_VDEV(cnxk_gpio, cnxk_gpio_drv);
RTE_PMD_REGISTER_PARAM_STRING(cnxk_gpio,
"gpiochip=<int> "
"allowlist=<list>");
RTE_LOG_REGISTER_DEFAULT(cnxk_gpio_rawdev_logtype, WARNING);
7 changes: 7 additions & 0 deletions drivers/raw/cnxk_gpio/cnxk_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#ifndef _CNXK_GPIO_H_
#define _CNXK_GPIO_H_

#include <rte_log.h>

extern int cnxk_gpio_rawdev_logtype;

#define CNXK_GPIO_LOG(level, fmt, args...) \
rte_log(RTE_LOG_ ## level, cnxk_gpio_rawdev_logtype, "%s(): " fmt "\n", __func__, ##args)

struct cnxk_gpiochip;

struct cnxk_gpio {
Expand Down
19 changes: 8 additions & 11 deletions drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cnxk_gpio_read_attr(char *attr, char *val)

#define CNXK_GPIO_ERR_STR(err, str, ...) do { \
if (err) { \
RTE_LOG(ERR, PMD, "%s:%d: " str " (%d)\n", __func__, __LINE__, \
CNXK_GPIO_LOG(ERR, "%s:%d: " str " (%d)", __func__, __LINE__, \
##__VA_ARGS__, err); \
goto out; \
} \
Expand Down Expand Up @@ -330,30 +330,28 @@ cnxk_gpio_selftest(uint16_t dev_id)
for (i = 0; i < queues; i++) {
ret = rte_rawdev_queue_conf_get(dev_id, i, &conf, sizeof(conf));
if (ret) {
RTE_LOG(ERR, PMD,
"failed to read queue configuration (%d)\n",
ret);
CNXK_GPIO_LOG(ERR, "failed to read queue configuration (%d)", ret);
goto out;
}

RTE_LOG(INFO, PMD, "testing queue%d (gpio%d)\n", i, conf.gpio);
CNXK_GPIO_LOG(INFO, "testing queue%d (gpio%d)", i, conf.gpio);

if (conf.size != 1) {
RTE_LOG(ERR, PMD, "wrong queue size received\n");
CNXK_GPIO_LOG(ERR, "wrong queue size received\n");
ret = -EIO;
goto out;
}

ret = rte_rawdev_queue_setup(dev_id, i, NULL, 0);
if (ret) {
RTE_LOG(ERR, PMD, "failed to setup queue (%d)\n", ret);
CNXK_GPIO_LOG(ERR, "failed to setup queue (%d)", ret);
goto out;
}

gpio = gpiochip->gpios[conf.gpio];
snprintf(buf, sizeof(buf), CNXK_GPIO_PATH_FMT, gpio->num);
if (!cnxk_gpio_attr_exists(buf)) {
RTE_LOG(ERR, PMD, "%s does not exist\n", buf);
CNXK_GPIO_LOG(ERR, "%s does not exist", buf);
ret = -ENOENT;
goto release;
}
Expand All @@ -371,13 +369,12 @@ cnxk_gpio_selftest(uint16_t dev_id)
ret2 = ret;
ret = rte_rawdev_queue_release(dev_id, i);
if (ret) {
RTE_LOG(ERR, PMD, "failed to release queue (%d)\n",
ret);
CNXK_GPIO_LOG(ERR, "failed to release queue (%d)", ret);
break;
}

if (cnxk_gpio_attr_exists(buf)) {
RTE_LOG(ERR, PMD, "%s still exists\n", buf);
CNXK_GPIO_LOG(ERR, "%s still exists", buf);
ret = -EIO;
break;
}
Expand Down

0 comments on commit 87d934b

Please sign in to comment.