11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Common debugging macros for use with the hisax driver 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Author Frode Isaksen 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright 2001 by Frode Isaksen <fisaksen@bewan.com> 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2001 by Kai Germaschewski <kai.germaschewski@gmx.de> 7475be4d85a274d0961593db41cf85689db1d583cJoe Perches * 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This software may be used and distributed according to the terms 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of the GNU General Public License, incorporated herein by reference. 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * How to use: 12475be4d85a274d0961593db41cf85689db1d583cJoe Perches * 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Before including this file, you need to 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * #define __debug_variable my_debug 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * where my_debug is a variable in your code which 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * determines the debug bitmask. 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If CONFIG_HISAX_DEBUG is not set, all macros evaluate to nothing 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __HISAX_DEBUG_H__ 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __HISAX_DEBUG_H__ 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_HISAX_DEBUG 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 28475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define DBG(level, format, arg...) do { \ 29475be4d85a274d0961593db41cf85689db1d583cJoe Perches if (level & __debug_variable) \ 30475be4d85a274d0961593db41cf85689db1d583cJoe Perches printk(KERN_DEBUG "%s: " format "\n" , __func__ , ## arg); \ 31475be4d85a274d0961593db41cf85689db1d583cJoe Perches } while (0) 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 33475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define DBG_PACKET(level, data, count) \ 34475be4d85a274d0961593db41cf85689db1d583cJoe Perches if (level & __debug_variable) dump_packet(__func__, data, count) 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 36475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define DBG_SKB(level, skb) \ 37475be4d85a274d0961593db41cf85689db1d583cJoe Perches if ((level & __debug_variable) && skb) dump_packet(__func__, skb->data, skb->len) 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __attribute__((unused)) 41475be4d85a274d0961593db41cf85689db1d583cJoe Perchesdump_packet(const char *name, const u_char *data, int pkt_len) 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DUMP_HDR_SIZE 20 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DUMP_TLR_SIZE 8 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (pkt_len) { 46475be4d85a274d0961593db41cf85689db1d583cJoe Perches int i, len1, len2; 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 48475be4d85a274d0961593db41cf85689db1d583cJoe Perches printk(KERN_DEBUG "%s: length=%d,data=", name, pkt_len); 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 50475be4d85a274d0961593db41cf85689db1d583cJoe Perches if (pkt_len > DUMP_HDR_SIZE + DUMP_TLR_SIZE) { 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len1 = DUMP_HDR_SIZE; 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len2 = DUMP_TLR_SIZE; 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len1 = pkt_len > DUMP_HDR_SIZE ? DUMP_HDR_SIZE : pkt_len; 55475be4d85a274d0961593db41cf85689db1d583cJoe Perches len2 = 0; 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0; i < len1; ++i) { 58475be4d85a274d0961593db41cf85689db1d583cJoe Perches printk("%.2x", data[i]); 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (len2) { 61475be4d85a274d0961593db41cf85689db1d583cJoe Perches printk(".."); 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = pkt_len-DUMP_TLR_SIZE; i < pkt_len; ++i) { 63475be4d85a274d0961593db41cf85689db1d583cJoe Perches printk("%.2x", data[i]); 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 66475be4d85a274d0961593db41cf85689db1d583cJoe Perches printk("\n"); 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef DUMP_HDR_SIZE 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef DUMP_TLR_SIZE 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DBG(level, format, arg...) do {} while (0) 75475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define DBG_PACKET(level, data, count) do {} while (0) 76475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define DBG_SKB(level, skb) do {} while (0) 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 81