18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky * Copyright (c) 2010 Panasas, Inc.
5c2676069SHans Petter Selasky * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky * All rights reserved.
78d59ecb2SHans Petter Selasky *
88d59ecb2SHans Petter Selasky * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky * are met:
118d59ecb2SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky * notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky * disclaimer.
148d59ecb2SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky * documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky *
188d59ecb2SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky */
29307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_PRINTK_H_
30307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_PRINTK_H_
31c2676069SHans Petter Selasky
32c2676069SHans Petter Selasky #include <linux/kernel.h>
338d59ecb2SHans Petter Selasky
348d59ecb2SHans Petter Selasky /* GID printing macros */
358d59ecb2SHans Petter Selasky #define GID_PRINT_FMT "%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x"
368d59ecb2SHans Petter Selasky #define GID_PRINT_ARGS(gid_raw) htons(((u16 *)gid_raw)[0]), htons(((u16 *)gid_raw)[1]),\
378d59ecb2SHans Petter Selasky htons(((u16 *)gid_raw)[2]), htons(((u16 *)gid_raw)[3]),\
388d59ecb2SHans Petter Selasky htons(((u16 *)gid_raw)[4]), htons(((u16 *)gid_raw)[5]),\
398d59ecb2SHans Petter Selasky htons(((u16 *)gid_raw)[6]), htons(((u16 *)gid_raw)[7])
408d59ecb2SHans Petter Selasky
41c2676069SHans Petter Selasky enum {
42c2676069SHans Petter Selasky DUMP_PREFIX_NONE,
43c2676069SHans Petter Selasky DUMP_PREFIX_ADDRESS,
44c2676069SHans Petter Selasky DUMP_PREFIX_OFFSET
45c2676069SHans Petter Selasky };
46c2676069SHans Petter Selasky
474359672eSBjoern A. Zeeb int __lkpi_hexdump_printf(void *, const char *, ...) __printflike(2, 3);
484359672eSBjoern A. Zeeb
494359672eSBjoern A. Zeeb void lkpi_hex_dump(int(*)(void *, const char *, ...), void *arg1,
504359672eSBjoern A. Zeeb const char *, const char *, const int, const int, const int,
514359672eSBjoern A. Zeeb const void *, size_t, const bool);
524359672eSBjoern A. Zeeb
53c2676069SHans Petter Selasky static inline void
print_hex_dump(const char * level,const char * prefix_str,const int prefix_type,const int rowsize,const int groupsize,const void * buf,size_t len,const bool ascii)54c2676069SHans Petter Selasky print_hex_dump(const char *level, const char *prefix_str,
55c2676069SHans Petter Selasky const int prefix_type, const int rowsize, const int groupsize,
56c2676069SHans Petter Selasky const void *buf, size_t len, const bool ascii)
57c2676069SHans Petter Selasky {
584359672eSBjoern A. Zeeb lkpi_hex_dump(__lkpi_hexdump_printf, NULL, level, prefix_str, prefix_type,
594359672eSBjoern A. Zeeb rowsize, groupsize, buf, len, ascii);
60c2676069SHans Petter Selasky }
61c2676069SHans Petter Selasky
62c2676069SHans Petter Selasky static inline void
print_hex_dump_bytes(const char * prefix_str,const int prefix_type,const void * buf,size_t len)63c2676069SHans Petter Selasky print_hex_dump_bytes(const char *prefix_str, const int prefix_type,
64c2676069SHans Petter Selasky const void *buf, size_t len)
65c2676069SHans Petter Selasky {
66c2676069SHans Petter Selasky print_hex_dump(NULL, prefix_str, prefix_type, 16, 1, buf, len, 0);
67c2676069SHans Petter Selasky }
68c2676069SHans Petter Selasky
6903f8ddedSHans Petter Selasky #define printk_ratelimit() ({ \
70c2676069SHans Petter Selasky static linux_ratelimit_t __ratelimited; \
7103f8ddedSHans Petter Selasky linux_ratelimited(&__ratelimited); \
7203f8ddedSHans Petter Selasky })
7303f8ddedSHans Petter Selasky
7403f8ddedSHans Petter Selasky #define printk_ratelimited(...) ({ \
7503f8ddedSHans Petter Selasky bool __retval = printk_ratelimit(); \
7603f8ddedSHans Petter Selasky if (__retval) \
77c2676069SHans Petter Selasky printk(__VA_ARGS__); \
7803f8ddedSHans Petter Selasky __retval; \
7903f8ddedSHans Petter Selasky })
80c2676069SHans Petter Selasky
81ab7da720SHans Petter Selasky #define pr_err_ratelimited(fmt, ...) \
82ab7da720SHans Petter Selasky printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
83ab7da720SHans Petter Selasky
8434cb771eSHans Petter Selasky #define print_hex_dump_debug(...) \
8534cb771eSHans Petter Selasky print_hex_dump(KERN_DEBUG, ##__VA_ARGS__)
8634cb771eSHans Petter Selasky
87c4698825SHans Petter Selasky #define pr_info_ratelimited(fmt, ...) \
88c4698825SHans Petter Selasky printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
89c4698825SHans Petter Selasky
901847e63dSBjoern A. Zeeb #define no_printk(fmt, ...) \
911847e63dSBjoern A. Zeeb ({ \
921847e63dSBjoern A. Zeeb if (0) \
931847e63dSBjoern A. Zeeb printk(pr_fmt(fmt), ##__VA_ARGS__); \
941847e63dSBjoern A. Zeeb 0; \
951847e63dSBjoern A. Zeeb })
961847e63dSBjoern A. Zeeb
97*621f43ffSJean-Sébastien Pédron #define FW_BUG "[Firmware Bug]: "
98*621f43ffSJean-Sébastien Pédron #define FW_WARN "[Firmware Warn]: "
99*621f43ffSJean-Sébastien Pédron #define FW_INFO "[Firmware Info]: "
100*621f43ffSJean-Sébastien Pédron #define HW_ERR "[Hardware Error]: "
101*621f43ffSJean-Sébastien Pédron #define DEPRECATED "[Deprecated]: "
102*621f43ffSJean-Sébastien Pédron
103307f78f3SVladimir Kondratyev #endif /* _LINUXKPI_LINUX_PRINTK_H_ */
104