Skip to content

Commit

Permalink
Merge pull request #1439 from Kamalheib/qedr_pr
Browse files Browse the repository at this point in the history
providers/qedr: Use the generic logging API
  • Loading branch information
rleon committed Apr 1, 2024
2 parents b51ef55 + cb0f880 commit 0fb80a4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 189 deletions.
58 changes: 0 additions & 58 deletions providers/qedr/qelr.h
Expand Up @@ -50,64 +50,6 @@
#include "qelr_hsi.h"
#include "qelr_chain.h"

#define qelr_err(format, arg...) printf(format, ##arg)

extern uint32_t qelr_dp_level;
extern uint32_t qelr_dp_module;

enum DP_MODULE {
QELR_MSG_CQ = 0x10000,
QELR_MSG_RQ = 0x20000,
QELR_MSG_SQ = 0x40000,
QELR_MSG_QP = (QELR_MSG_SQ | QELR_MSG_RQ),
QELR_MSG_MR = 0x80000,
QELR_MSG_INIT = 0x100000,
QELR_MSG_SRQ = 0x200000,
/* to be added...up to 0x8000000 */
};

enum DP_LEVEL {
QELR_LEVEL_VERBOSE = 0x0,
QELR_LEVEL_INFO = 0x1,
QELR_LEVEL_NOTICE = 0x2,
QELR_LEVEL_ERR = 0x3,
};

#define DP_ERR(fd, fmt, ...) \
do { \
fprintf(fd, "[%s:%d]" fmt, \
__func__, __LINE__, \
##__VA_ARGS__); \
fflush(fd); \
} while (0)

#define DP_NOTICE(fd, fmt, ...) \
do { \
if (qelr_dp_level <= QELR_LEVEL_NOTICE) {\
fprintf(fd, "[%s:%d]" fmt, \
__func__, __LINE__, \
##__VA_ARGS__); \
fflush(fd); } \
} while (0)

#define DP_INFO(fd, fmt, ...) \
do { \
if (qelr_dp_level <= QELR_LEVEL_INFO) { \
fprintf(fd, "[%s:%d]" fmt, \
__func__, __LINE__, \
##__VA_ARGS__); fflush(fd); \
} \
} while (0)

#define DP_VERBOSE(fd, module, fmt, ...) \
do { \
if ((qelr_dp_level <= QELR_LEVEL_VERBOSE) && \
(qelr_dp_module & (module))) { \
fprintf(fd, "[%s:%d]" fmt, \
__func__, __LINE__, \
##__VA_ARGS__); fflush(fd); } \
} while (0)

struct qelr_buf {
void *addr;
size_t len; /* a 64 uint is used as s preparation
Expand Down
61 changes: 3 additions & 58 deletions providers/qedr/qelr_main.c
Expand Up @@ -64,9 +64,6 @@ static void qelr_free_context(struct ibv_context *ibctx);
#define PCI_DEVICE_ID_QLOGIC_AHP (0x8170)
#define PCI_DEVICE_ID_QLOGIC_AHP_IOV (0x8190)

uint32_t qelr_dp_level;
uint32_t qelr_dp_module;

#define QHCA(d) \
VERBS_PCI_MATCH(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_##d, NULL)
static const struct verbs_match_ent hca_table[] = {
Expand Down Expand Up @@ -128,53 +125,6 @@ static void qelr_uninit_device(struct verbs_device *verbs_device)
free(dev);
}

static void qelr_open_debug_file(struct qelr_devctx *ctx)
{
char *env;

env = getenv("QELR_DEBUG_FILE");
if (!env) {
ctx->dbg_fp = stderr;
DP_VERBOSE(ctx->dbg_fp, QELR_MSG_INIT,
"Debug file opened: stderr\n");
return;
}

ctx->dbg_fp = fopen(env, "aw+");
if (!ctx->dbg_fp) {
fprintf(stderr, "Failed opening debug file %s, using stderr\n",
env);
ctx->dbg_fp = stderr;
DP_VERBOSE(ctx->dbg_fp, QELR_MSG_INIT,
"Debug file opened: stderr\n");
return;
}

DP_VERBOSE(ctx->dbg_fp, QELR_MSG_INIT, "Debug file opened: %s\n", env);
}

static void qelr_close_debug_file(struct qelr_devctx *ctx)
{
if (ctx->dbg_fp && ctx->dbg_fp != stderr)
fclose(ctx->dbg_fp);
}

static void qelr_set_debug_mask(void)
{
char *env;

qelr_dp_level = QELR_LEVEL_NOTICE;
qelr_dp_module = 0;

env = getenv("QELR_DP_LEVEL");
if (env)
qelr_dp_level = atoi(env);

env = getenv("QELR_DP_MODULE");
if (env)
qelr_dp_module = atoi(env);
}

static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,
int cmd_fd,
void *private_data)
Expand All @@ -190,9 +140,6 @@ static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,

memset(&resp, 0, sizeof(resp));

qelr_open_debug_file(ctx);
qelr_set_debug_mask();

cmd.context_flags = QEDR_ALLOC_UCTX_DB_REC | QEDR_SUPPORT_DPM_SIZES;
cmd.context_flags |= QEDR_ALLOC_UCTX_EDPM_MODE;
if (ibv_cmd_get_context(&ctx->ibv_ctx, &cmd.ibv_cmd, sizeof(cmd),
Expand All @@ -205,7 +152,7 @@ static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,

ctx->srq_table = calloc(QELR_MAX_SRQ_ID, sizeof(*ctx->srq_table));
if (!ctx->srq_table) {
DP_ERR(ctx->dbg_fp, "failed to allocate srq_table\n");
verbs_err(&ctx->ibv_ctx, "failed to allocate srq_table\n");
goto cmd_err;
}

Expand Down Expand Up @@ -254,7 +201,7 @@ static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,
if (ctx->db_addr == MAP_FAILED) {
int errsv = errno;

DP_ERR(ctx->dbg_fp,
verbs_err(&ctx->ibv_ctx,
"alloc context: doorbell mapping failed resp.db_pa = %llx resp.db_size=%d context->cmd_fd=%d errno=%d\n",
resp.db_pa, resp.db_size, cmd_fd, errsv);
goto free_srq_tbl;
Expand All @@ -266,8 +213,7 @@ static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,
free(ctx->srq_table);

cmd_err:
qelr_err("%s: Failed to allocate context for device.\n", __func__);
qelr_close_debug_file(ctx);
verbs_err(&ctx->ibv_ctx, "Failed to allocate context for device.\n");
verbs_uninit_context(&ctx->ibv_ctx);
free(ctx);
return NULL;
Expand All @@ -281,7 +227,6 @@ static void qelr_free_context(struct ibv_context *ibctx)
munmap(ctx->db_addr, ctx->db_size);

free(ctx->srq_table);
qelr_close_debug_file(ctx);
verbs_uninit_context(&ctx->ibv_ctx);
free(ctx);
}
Expand Down

0 comments on commit 0fb80a4

Please sign in to comment.