Skip to content

Commit 923abb9

Browse files
gal-pressmandledford
authored andcommitted
RDMA/core: Introduce RDMA subsystem ibdev_* print functions
Similarly to dev/netdev/etc printk helpers, add standard printk helpers for the RDMA subsystem. Example output: efa 0000:00:06.0 efa_0: Hello World! efa_0: Hello World! (no parent device set) (NULL ib_device): Hello World! (ibdev is NULL) Cc: Jason Baron <jbaron@akamai.com> Suggested-by: Jason Gunthorpe <jgg@ziepe.ca> Suggested-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Gal Pressman <galpress@amazon.com> Reviewed-by: Leon Romanovsky <leonro@mellanox.com> Reviewed-by: Shiraz Saleem <shiraz.saleem@intel.com> Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent b9b0f34 commit 923abb9

4 files changed

Lines changed: 138 additions & 0 deletions

File tree

‎drivers/infiniband/core/device.c‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,66 @@ static int ib_security_change(struct notifier_block *nb, unsigned long event,
197197
static void ib_policy_change_task(struct work_struct *work);
198198
static DECLARE_WORK(ib_policy_change_work, ib_policy_change_task);
199199

200+
static void __ibdev_printk(const char *level, const struct ib_device *ibdev,
201+
struct va_format *vaf)
202+
{
203+
if (ibdev && ibdev->dev.parent)
204+
dev_printk_emit(level[1] - '0',
205+
ibdev->dev.parent,
206+
"%s %s %s: %pV",
207+
dev_driver_string(ibdev->dev.parent),
208+
dev_name(ibdev->dev.parent),
209+
dev_name(&ibdev->dev),
210+
vaf);
211+
else if (ibdev)
212+
printk("%s%s: %pV",
213+
level, dev_name(&ibdev->dev), vaf);
214+
else
215+
printk("%s(NULL ib_device): %pV", level, vaf);
216+
}
217+
218+
void ibdev_printk(const char *level, const struct ib_device *ibdev,
219+
const char *format, ...)
220+
{
221+
struct va_format vaf;
222+
va_list args;
223+
224+
va_start(args, format);
225+
226+
vaf.fmt = format;
227+
vaf.va = &args;
228+
229+
__ibdev_printk(level, ibdev, &vaf);
230+
231+
va_end(args);
232+
}
233+
EXPORT_SYMBOL(ibdev_printk);
234+
235+
#define define_ibdev_printk_level(func, level) \
236+
void func(const struct ib_device *ibdev, const char *fmt, ...) \
237+
{ \
238+
struct va_format vaf; \
239+
va_list args; \
240+
\
241+
va_start(args, fmt); \
242+
\
243+
vaf.fmt = fmt; \
244+
vaf.va = &args; \
245+
\
246+
__ibdev_printk(level, ibdev, &vaf); \
247+
\
248+
va_end(args); \
249+
} \
250+
EXPORT_SYMBOL(func);
251+
252+
define_ibdev_printk_level(ibdev_emerg, KERN_EMERG);
253+
define_ibdev_printk_level(ibdev_alert, KERN_ALERT);
254+
define_ibdev_printk_level(ibdev_crit, KERN_CRIT);
255+
define_ibdev_printk_level(ibdev_err, KERN_ERR);
256+
define_ibdev_printk_level(ibdev_warn, KERN_WARNING);
257+
define_ibdev_printk_level(ibdev_notice, KERN_NOTICE);
258+
define_ibdev_printk_level(ibdev_info, KERN_INFO);
259+
200260
static struct notifier_block ibdev_lsm_nb = {
201261
.notifier_call = ib_security_change,
202262
};

‎include/linux/dynamic_debug.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,
7171
const struct net_device *dev,
7272
const char *fmt, ...);
7373

74+
struct ib_device;
75+
76+
extern __printf(3, 4)
77+
void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
78+
const struct ib_device *ibdev,
79+
const char *fmt, ...);
80+
7481
#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
7582
static struct _ddebug __aligned(8) \
7683
__attribute__((section("__verbose"))) name = { \
@@ -154,6 +161,10 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,
154161
_dynamic_func_call(fmt, __dynamic_netdev_dbg, \
155162
dev, fmt, ##__VA_ARGS__)
156163

164+
#define dynamic_ibdev_dbg(dev, fmt, ...) \
165+
_dynamic_func_call(fmt, __dynamic_ibdev_dbg, \
166+
dev, fmt, ##__VA_ARGS__)
167+
157168
#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
158169
groupsize, buf, len, ascii) \
159170
_dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \

‎include/rdma/ib_verbs.h‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,36 @@ extern struct workqueue_struct *ib_wq;
7474
extern struct workqueue_struct *ib_comp_wq;
7575
extern struct workqueue_struct *ib_comp_unbound_wq;
7676

77+
__printf(3, 4) __cold
78+
void ibdev_printk(const char *level, const struct ib_device *ibdev,
79+
const char *format, ...);
80+
__printf(2, 3) __cold
81+
void ibdev_emerg(const struct ib_device *ibdev, const char *format, ...);
82+
__printf(2, 3) __cold
83+
void ibdev_alert(const struct ib_device *ibdev, const char *format, ...);
84+
__printf(2, 3) __cold
85+
void ibdev_crit(const struct ib_device *ibdev, const char *format, ...);
86+
__printf(2, 3) __cold
87+
void ibdev_err(const struct ib_device *ibdev, const char *format, ...);
88+
__printf(2, 3) __cold
89+
void ibdev_warn(const struct ib_device *ibdev, const char *format, ...);
90+
__printf(2, 3) __cold
91+
void ibdev_notice(const struct ib_device *ibdev, const char *format, ...);
92+
__printf(2, 3) __cold
93+
void ibdev_info(const struct ib_device *ibdev, const char *format, ...);
94+
95+
#if defined(CONFIG_DYNAMIC_DEBUG)
96+
#define ibdev_dbg(__dev, format, args...) \
97+
dynamic_ibdev_dbg(__dev, format, ##args)
98+
#elif defined(DEBUG)
99+
#define ibdev_dbg(__dev, format, args...) \
100+
ibdev_printk(KERN_DEBUG, __dev, format, ##args)
101+
#else
102+
__printf(2, 3) __cold
103+
static inline
104+
void ibdev_dbg(const struct ib_device *ibdev, const char *format, ...) {}
105+
#endif
106+
77107
union ib_gid {
78108
u8 raw[16];
79109
struct {

‎lib/dynamic_debug.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include <linux/device.h>
3838
#include <linux/netdevice.h>
3939

40+
#include <rdma/ib_verbs.h>
41+
4042
extern struct _ddebug __start___verbose[];
4143
extern struct _ddebug __stop___verbose[];
4244

@@ -636,6 +638,41 @@ EXPORT_SYMBOL(__dynamic_netdev_dbg);
636638

637639
#endif
638640

641+
#if IS_ENABLED(CONFIG_INFINIBAND)
642+
643+
void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
644+
const struct ib_device *ibdev, const char *fmt, ...)
645+
{
646+
struct va_format vaf;
647+
va_list args;
648+
649+
va_start(args, fmt);
650+
651+
vaf.fmt = fmt;
652+
vaf.va = &args;
653+
654+
if (ibdev && ibdev->dev.parent) {
655+
char buf[PREFIX_SIZE];
656+
657+
dev_printk_emit(LOGLEVEL_DEBUG, ibdev->dev.parent,
658+
"%s%s %s %s: %pV",
659+
dynamic_emit_prefix(descriptor, buf),
660+
dev_driver_string(ibdev->dev.parent),
661+
dev_name(ibdev->dev.parent),
662+
dev_name(&ibdev->dev),
663+
&vaf);
664+
} else if (ibdev) {
665+
printk(KERN_DEBUG "%s: %pV", dev_name(&ibdev->dev), &vaf);
666+
} else {
667+
printk(KERN_DEBUG "(NULL ib_device): %pV", &vaf);
668+
}
669+
670+
va_end(args);
671+
}
672+
EXPORT_SYMBOL(__dynamic_ibdev_dbg);
673+
674+
#endif
675+
639676
#define DDEBUG_STRING_SIZE 1024
640677
static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE];
641678

0 commit comments

Comments
 (0)