Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Common debugging macros for use with the hisax driver |
| 3 | * |
| 4 | * Author Frode Isaksen |
| 5 | * Copyright 2001 by Frode Isaksen <fisaksen@bewan.com> |
| 6 | * 2001 by Kai Germaschewski <kai.germaschewski@gmx.de> |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This software may be used and distributed according to the terms |
| 9 | * of the GNU General Public License, incorporated herein by reference. |
| 10 | * |
| 11 | * How to use: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Before including this file, you need to |
| 14 | * #define __debug_variable my_debug |
| 15 | * where my_debug is a variable in your code which |
| 16 | * determines the debug bitmask. |
| 17 | * |
| 18 | * If CONFIG_HISAX_DEBUG is not set, all macros evaluate to nothing |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #ifndef __HISAX_DEBUG_H__ |
| 23 | #define __HISAX_DEBUG_H__ |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #ifdef CONFIG_HISAX_DEBUG |
| 27 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 28 | #define DBG(level, format, arg...) do { \ |
| 29 | if (level & __debug_variable) \ |
| 30 | printk(KERN_DEBUG "%s: " format "\n" , __func__ , ## arg); \ |
| 31 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 33 | #define DBG_PACKET(level, data, count) \ |
| 34 | if (level & __debug_variable) dump_packet(__func__, data, count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 36 | #define DBG_SKB(level, skb) \ |
| 37 | if ((level & __debug_variable) && skb) dump_packet(__func__, skb->data, skb->len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | |
| 40 | static void __attribute__((unused)) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 41 | dump_packet(const char *name, const u_char *data, int pkt_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
| 43 | #define DUMP_HDR_SIZE 20 |
| 44 | #define DUMP_TLR_SIZE 8 |
| 45 | if (pkt_len) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 46 | int i, len1, len2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 48 | printk(KERN_DEBUG "%s: length=%d,data=", name, pkt_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 50 | if (pkt_len > DUMP_HDR_SIZE + DUMP_TLR_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | len1 = DUMP_HDR_SIZE; |
| 52 | len2 = DUMP_TLR_SIZE; |
| 53 | } else { |
| 54 | len1 = pkt_len > DUMP_HDR_SIZE ? DUMP_HDR_SIZE : pkt_len; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 55 | len2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | for (i = 0; i < len1; ++i) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 58 | printk("%.2x", data[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | if (len2) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 61 | printk(".."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | for (i = pkt_len-DUMP_TLR_SIZE; i < pkt_len; ++i) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 63 | printk("%.2x", data[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 66 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | #undef DUMP_HDR_SIZE |
| 69 | #undef DUMP_TLR_SIZE |
| 70 | } |
| 71 | |
| 72 | #else |
| 73 | |
| 74 | #define DBG(level, format, arg...) do {} while (0) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 75 | #define DBG_PACKET(level, data, count) do {} while (0) |
| 76 | #define DBG_SKB(level, skb) do {} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | #endif |
| 79 | |
| 80 | #endif |