Skip to content

Commit 860c9af

Browse files
kadesai16sbasavapatna
authored andcommitted
bnxt_re/lib: Support debug logging
Introduce a new logging function and new enviornment variables to control it. This will be used in subsequent patches for debug logging. Below environment variables are supported. BNXT_DEBUG_FILE: User can provide absolute file location that will be used for logging the prints from library code. Default path is – “/var/log/messages” BNXT_DEBUG_MASK: Set this value to log direct verbs related information. BNXT_DUMP_DV = 1 Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com> Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com> Reviewed-by: Damodharam Ammepalli <damodharam.ammepalli@broadcom.com> Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
1 parent 0d977c5 commit 860c9af

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

providers/bnxt_re/main.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ static const struct verbs_match_ent cna_table[] = {
9191
{}
9292
};
9393

94+
uint32_t bnxt_debug_mask;
95+
9496
static const struct verbs_context_ops bnxt_re_cntx_ops = {
9597
.query_device_ex = bnxt_re_query_device,
9698
.query_port = bnxt_re_query_port,
@@ -181,6 +183,39 @@ static int bnxt_re_alloc_map_dbr_bar_page(struct ibv_context *ibvctx)
181183
return 0;
182184
}
183185

186+
static void bnxt_open_debug_file(FILE **dbg_fp)
187+
{
188+
FILE *default_dbg_fp = NULL;
189+
const char *env;
190+
191+
env = getenv("BNXT_DEBUG_FILE");
192+
193+
if (!env)
194+
env = "/var/log/messages";
195+
196+
*dbg_fp = fopen(env, "aw+");
197+
if (!*dbg_fp) {
198+
*dbg_fp = default_dbg_fp;
199+
bnxt_err(NULL, "Failed opening debug file %s\n", env);
200+
return;
201+
}
202+
}
203+
204+
static void bnxt_close_debug_file(FILE *dbg_fp)
205+
{
206+
if (dbg_fp && dbg_fp != stderr)
207+
fclose(dbg_fp);
208+
}
209+
210+
static void bnxt_set_debug_mask(void)
211+
{
212+
char *env;
213+
214+
env = getenv("BNXT_DEBUG_MASK");
215+
if (env)
216+
bnxt_debug_mask = strtol(env, NULL, 0);
217+
}
218+
184219
/* Context Init functions */
185220
static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
186221
int cmd_fd,
@@ -261,6 +296,9 @@ static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
261296
if (ret)
262297
goto failed;
263298

299+
bnxt_open_debug_file(&cntx->dbg_fp);
300+
bnxt_set_debug_mask();
301+
264302
return &cntx->ibvctx;
265303

266304
failed:
@@ -274,6 +312,8 @@ static void bnxt_re_free_context(struct ibv_context *ibvctx)
274312
struct bnxt_re_context *cntx = to_bnxt_re_context(ibvctx);
275313
struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibvctx->device);
276314

315+
bnxt_close_debug_file(cntx->dbg_fp);
316+
277317
/* Unmap if anything device specific was mapped in init_context. */
278318
pthread_mutex_destroy(&cntx->shlock);
279319
if (cntx->shpg)

providers/bnxt_re/main.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#include <endian.h>
4646
#include <pthread.h>
4747
#include <sys/param.h>
48+
#include <stdio.h>
49+
#include <stdarg.h>
4850

4951
#include <util/mmio.h>
5052
#include <util/util.h>
@@ -270,6 +272,7 @@ struct bnxt_re_context {
270272
uint32_t wc_handle;
271273
void *dbr_page;
272274
void *bar_map;
275+
FILE *dbg_fp;
273276
};
274277

275278
struct bnxt_re_pacing_data {
@@ -321,6 +324,45 @@ int bnxt_re_get_toggle_mem(struct ibv_context *ibvctx,
321324
struct bnxt_re_mmap_info *minfo,
322325
uint32_t *page_handle);
323326

327+
extern uint32_t bnxt_debug_mask;
328+
enum {
329+
BNXT_DUMP_DV = 1 << 0,
330+
};
331+
332+
#define LEN_50 50
333+
#define bnxt_trace_dv(cntx, fmt, ...) \
334+
{ \
335+
if (bnxt_debug_mask & BNXT_DUMP_DV) \
336+
bnxt_err(cntx, fmt, ##__VA_ARGS__); \
337+
}
338+
339+
static inline void bnxt_err(struct bnxt_re_context *cntx, const char *fmt, ...)
340+
__attribute__((format(printf, 2, 3)));
341+
342+
static inline void bnxt_err(struct bnxt_re_context *cntx, const char *fmt, ...)
343+
{
344+
FILE *fp = cntx ? cntx->dbg_fp : stderr;
345+
char prefix[LEN_50] = {};
346+
char timestamp[LEN_50];
347+
struct tm *timeinfo;
348+
time_t rawtime;
349+
va_list args;
350+
351+
time(&rawtime);
352+
timeinfo = localtime(&rawtime);
353+
354+
strftime(timestamp, LEN_50, "%b %d %X", timeinfo);
355+
sprintf(prefix, " %s: ", "libbnxt_re");
356+
357+
if (!fp)
358+
return;
359+
va_start(args, fmt);
360+
fprintf(fp, "%s", timestamp);
361+
fprintf(fp, "%s", prefix);
362+
vfprintf(fp, fmt, args);
363+
va_end(args);
364+
}
365+
324366
/* pointer conversion functions*/
325367
static inline struct bnxt_re_dev *to_bnxt_re_dev(struct ibv_device *ibvdev)
326368
{

0 commit comments

Comments
 (0)