hisax_debug.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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>
  7. *
  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:
  12. *
  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. #ifndef __HISAX_DEBUG_H__
  22. #define __HISAX_DEBUG_H__
  23. #include <linux/config.h>
  24. #ifdef CONFIG_HISAX_DEBUG
  25. #define DBG(level, format, arg...) do { \
  26. if (level & __debug_variable) \
  27. printk(KERN_DEBUG "%s: " format "\n" , __FUNCTION__ , ## arg); \
  28. } while (0)
  29. #define DBG_PACKET(level,data,count) \
  30. if (level & __debug_variable) dump_packet(__FUNCTION__,data,count)
  31. #define DBG_SKB(level,skb) \
  32. if ((level & __debug_variable) && skb) dump_packet(__FUNCTION__,skb->data,skb->len)
  33. static void __attribute__((unused))
  34. dump_packet(const char *name,const u_char *data,int pkt_len)
  35. {
  36. #define DUMP_HDR_SIZE 20
  37. #define DUMP_TLR_SIZE 8
  38. if (pkt_len) {
  39. int i,len1,len2;
  40. printk(KERN_DEBUG "%s: length=%d,data=",name,pkt_len);
  41. if (pkt_len > DUMP_HDR_SIZE+ DUMP_TLR_SIZE) {
  42. len1 = DUMP_HDR_SIZE;
  43. len2 = DUMP_TLR_SIZE;
  44. } else {
  45. len1 = pkt_len > DUMP_HDR_SIZE ? DUMP_HDR_SIZE : pkt_len;
  46. len2 = 0;
  47. }
  48. for (i = 0; i < len1; ++i) {
  49. printk ("%.2x", data[i]);
  50. }
  51. if (len2) {
  52. printk ("..");
  53. for (i = pkt_len-DUMP_TLR_SIZE; i < pkt_len; ++i) {
  54. printk ("%.2x", data[i]);
  55. }
  56. }
  57. printk ("\n");
  58. }
  59. #undef DUMP_HDR_SIZE
  60. #undef DUMP_TLR_SIZE
  61. }
  62. #else
  63. #define DBG(level, format, arg...) do {} while (0)
  64. #define DBG_PACKET(level,data,count) do {} while (0)
  65. #define DBG_SKB(level,skb) do {} while (0)
  66. #endif
  67. #endif