ibm_emac_debug.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * drivers/net/ibm_emac/ibm_emac_debug.c
  3. *
  4. * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines.
  5. *
  6. * Copyright (c) 2004, 2005 Zultys Technologies
  7. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/sysrq.h>
  20. #include <asm/io.h>
  21. #include "ibm_emac_core.h"
  22. static void emac_desc_dump(int idx, struct ocp_enet_private *p)
  23. {
  24. int i;
  25. printk("** EMAC%d TX BDs **\n"
  26. " tx_cnt = %d tx_slot = %d ack_slot = %d\n",
  27. idx, p->tx_cnt, p->tx_slot, p->ack_slot);
  28. for (i = 0; i < NUM_TX_BUFF / 2; ++i)
  29. printk
  30. ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n",
  31. i, p->tx_desc[i].data_ptr, p->tx_skb[i] ? 'V' : ' ',
  32. p->tx_desc[i].ctrl, p->tx_desc[i].data_len,
  33. NUM_TX_BUFF / 2 + i,
  34. p->tx_desc[NUM_TX_BUFF / 2 + i].data_ptr,
  35. p->tx_skb[NUM_TX_BUFF / 2 + i] ? 'V' : ' ',
  36. p->tx_desc[NUM_TX_BUFF / 2 + i].ctrl,
  37. p->tx_desc[NUM_TX_BUFF / 2 + i].data_len);
  38. printk("** EMAC%d RX BDs **\n"
  39. " rx_slot = %d rx_stopped = %d rx_skb_size = %d rx_sync_size = %d\n"
  40. " rx_sg_skb = 0x%p\n",
  41. idx, p->rx_slot, p->commac.rx_stopped, p->rx_skb_size,
  42. p->rx_sync_size, p->rx_sg_skb);
  43. for (i = 0; i < NUM_RX_BUFF / 2; ++i)
  44. printk
  45. ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n",
  46. i, p->rx_desc[i].data_ptr, p->rx_skb[i] ? 'V' : ' ',
  47. p->rx_desc[i].ctrl, p->rx_desc[i].data_len,
  48. NUM_RX_BUFF / 2 + i,
  49. p->rx_desc[NUM_RX_BUFF / 2 + i].data_ptr,
  50. p->rx_skb[NUM_RX_BUFF / 2 + i] ? 'V' : ' ',
  51. p->rx_desc[NUM_RX_BUFF / 2 + i].ctrl,
  52. p->rx_desc[NUM_RX_BUFF / 2 + i].data_len);
  53. }
  54. static void emac_mac_dump(int idx, struct ocp_enet_private *dev)
  55. {
  56. struct emac_regs __iomem *p = dev->emacp;
  57. printk("** EMAC%d registers **\n"
  58. "MR0 = 0x%08x MR1 = 0x%08x TMR0 = 0x%08x TMR1 = 0x%08x\n"
  59. "RMR = 0x%08x ISR = 0x%08x ISER = 0x%08x\n"
  60. "IAR = %04x%08x VTPID = 0x%04x VTCI = 0x%04x\n"
  61. "IAHT: 0x%04x 0x%04x 0x%04x 0x%04x "
  62. "GAHT: 0x%04x 0x%04x 0x%04x 0x%04x\n"
  63. "LSA = %04x%08x IPGVR = 0x%04x\n"
  64. "STACR = 0x%08x TRTR = 0x%08x RWMR = 0x%08x\n"
  65. "OCTX = 0x%08x OCRX = 0x%08x IPCR = 0x%08x\n",
  66. idx, in_be32(&p->mr0), in_be32(&p->mr1),
  67. in_be32(&p->tmr0), in_be32(&p->tmr1),
  68. in_be32(&p->rmr), in_be32(&p->isr), in_be32(&p->iser),
  69. in_be32(&p->iahr), in_be32(&p->ialr), in_be32(&p->vtpid),
  70. in_be32(&p->vtci),
  71. in_be32(&p->iaht1), in_be32(&p->iaht2), in_be32(&p->iaht3),
  72. in_be32(&p->iaht4),
  73. in_be32(&p->gaht1), in_be32(&p->gaht2), in_be32(&p->gaht3),
  74. in_be32(&p->gaht4),
  75. in_be32(&p->lsah), in_be32(&p->lsal), in_be32(&p->ipgvr),
  76. in_be32(&p->stacr), in_be32(&p->trtr), in_be32(&p->rwmr),
  77. in_be32(&p->octx), in_be32(&p->ocrx), in_be32(&p->ipcr)
  78. );
  79. emac_desc_dump(idx, dev);
  80. }
  81. static void emac_mal_dump(struct ibm_ocp_mal *mal)
  82. {
  83. struct ocp_func_mal_data *maldata = mal->def->additions;
  84. int i;
  85. printk("** MAL%d Registers **\n"
  86. "CFG = 0x%08x ESR = 0x%08x IER = 0x%08x\n"
  87. "TX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n"
  88. "RX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n",
  89. mal->def->index,
  90. get_mal_dcrn(mal, MAL_CFG), get_mal_dcrn(mal, MAL_ESR),
  91. get_mal_dcrn(mal, MAL_IER),
  92. get_mal_dcrn(mal, MAL_TXCASR), get_mal_dcrn(mal, MAL_TXCARR),
  93. get_mal_dcrn(mal, MAL_TXEOBISR), get_mal_dcrn(mal, MAL_TXDEIR),
  94. get_mal_dcrn(mal, MAL_RXCASR), get_mal_dcrn(mal, MAL_RXCARR),
  95. get_mal_dcrn(mal, MAL_RXEOBISR), get_mal_dcrn(mal, MAL_RXDEIR)
  96. );
  97. printk("TX|");
  98. for (i = 0; i < maldata->num_tx_chans; ++i) {
  99. if (i && !(i % 4))
  100. printk("\n ");
  101. printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_TXCTPR(i)));
  102. }
  103. printk("\nRX|");
  104. for (i = 0; i < maldata->num_rx_chans; ++i) {
  105. if (i && !(i % 4))
  106. printk("\n ");
  107. printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_RXCTPR(i)));
  108. }
  109. printk("\n ");
  110. for (i = 0; i < maldata->num_rx_chans; ++i) {
  111. u32 r = get_mal_dcrn(mal, MAL_RCBS(i));
  112. if (i && !(i % 3))
  113. printk("\n ");
  114. printk("RCBS%d = 0x%08x (%d) ", i, r, r * 16);
  115. }
  116. printk("\n");
  117. }
  118. static struct ocp_enet_private *__emacs[4];
  119. static struct ibm_ocp_mal *__mals[1];
  120. void emac_dbg_register(int idx, struct ocp_enet_private *dev)
  121. {
  122. unsigned long flags;
  123. if (idx >= ARRAY_SIZE(__emacs)) {
  124. printk(KERN_WARNING
  125. "invalid index %d when registering EMAC for debugging\n",
  126. idx);
  127. return;
  128. }
  129. local_irq_save(flags);
  130. __emacs[idx] = dev;
  131. local_irq_restore(flags);
  132. }
  133. void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
  134. {
  135. unsigned long flags;
  136. if (idx >= ARRAY_SIZE(__mals)) {
  137. printk(KERN_WARNING
  138. "invalid index %d when registering MAL for debugging\n",
  139. idx);
  140. return;
  141. }
  142. local_irq_save(flags);
  143. __mals[idx] = mal;
  144. local_irq_restore(flags);
  145. }
  146. void emac_dbg_dump_all(void)
  147. {
  148. unsigned int i;
  149. unsigned long flags;
  150. local_irq_save(flags);
  151. for (i = 0; i < ARRAY_SIZE(__mals); ++i)
  152. if (__mals[i])
  153. emac_mal_dump(__mals[i]);
  154. for (i = 0; i < ARRAY_SIZE(__emacs); ++i)
  155. if (__emacs[i])
  156. emac_mac_dump(i, __emacs[i]);
  157. local_irq_restore(flags);
  158. }
  159. #if defined(CONFIG_MAGIC_SYSRQ)
  160. static void emac_sysrq_handler(int key, struct tty_struct *tty)
  161. {
  162. emac_dbg_dump_all();
  163. }
  164. static struct sysrq_key_op emac_sysrq_op = {
  165. .handler = emac_sysrq_handler,
  166. .help_msg = "emaC",
  167. .action_msg = "Show EMAC(s) status",
  168. };
  169. int __init emac_init_debug(void)
  170. {
  171. return register_sysrq_key('c', &emac_sysrq_op);
  172. }
  173. void __exit emac_fini_debug(void)
  174. {
  175. unregister_sysrq_key('c', &emac_sysrq_op);
  176. }
  177. #else
  178. int __init emac_init_debug(void)
  179. {
  180. return 0;
  181. }
  182. void __exit emac_fini_debug(void)
  183. {
  184. }
  185. #endif /* CONFIG_MAGIC_SYSRQ */