2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef _LINUX_PRINTK_H_
32 #define _LINUX_PRINTK_H_
34 #include <linux/kernel.h>
36 /* GID printing macros */
37 #define GID_PRINT_FMT "%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x"
38 #define GID_PRINT_ARGS(gid_raw) htons(((u16 *)gid_raw)[0]), htons(((u16 *)gid_raw)[1]),\
39 htons(((u16 *)gid_raw)[2]), htons(((u16 *)gid_raw)[3]),\
40 htons(((u16 *)gid_raw)[4]), htons(((u16 *)gid_raw)[5]),\
41 htons(((u16 *)gid_raw)[6]), htons(((u16 *)gid_raw)[7])
50 print_hex_dump(const char *level, const char *prefix_str,
51 const int prefix_type, const int rowsize, const int groupsize,
52 const void *buf, size_t len, const bool ascii)
54 typedef const struct { long long value; } __packed *print_64p_t;
55 typedef const struct { uint32_t value; } __packed *print_32p_t;
56 typedef const struct { uint16_t value; } __packed *print_16p_t;
57 const void *buf_old = buf;
63 if (prefix_str != NULL)
64 printf("%s ", prefix_str);
66 switch (prefix_type) {
67 case DUMP_PREFIX_ADDRESS:
70 case DUMP_PREFIX_OFFSET:
71 printf("[%p] ", (const char *)((const char *)buf -
72 (const char *)buf_old));
77 for (row = 0; row != rowsize; row++) {
78 if (groupsize == 8 && len > 7) {
79 printf("%016llx ", ((print_64p_t)buf)->value);
80 buf = (const uint8_t *)buf + 8;
82 } else if (groupsize == 4 && len > 3) {
83 printf("%08x ", ((print_32p_t)buf)->value);
84 buf = (const uint8_t *)buf + 4;
86 } else if (groupsize == 2 && len > 1) {
87 printf("%04x ", ((print_16p_t)buf)->value);
88 buf = (const uint8_t *)buf + 2;
91 printf("%02x ", *(const uint8_t *)buf);
92 buf = (const uint8_t *)buf + 1;
103 print_hex_dump_bytes(const char *prefix_str, const int prefix_type,
104 const void *buf, size_t len)
106 print_hex_dump(NULL, prefix_str, prefix_type, 16, 1, buf, len, 0);
109 #define printk_ratelimit() ({ \
110 static linux_ratelimit_t __ratelimited; \
111 linux_ratelimited(&__ratelimited); \
114 #define printk_ratelimited(...) ({ \
115 bool __retval = printk_ratelimit(); \
117 printk(__VA_ARGS__); \
121 #define pr_err_ratelimited(fmt, ...) \
122 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
124 #endif /* _LINUX_PRINTK_H_ */