qca_debug.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
  3. * Copyright (c) 2014, I2SE GmbH
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software
  6. * for any purpose with or without fee is hereby granted, provided
  7. * that the above copyright notice and this permission notice appear
  8. * in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  13. * THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
  14. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  15. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  16. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  17. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /* This file contains debugging routines for use in the QCA7K driver.
  20. */
  21. #include <linux/debugfs.h>
  22. #include <linux/ethtool.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/types.h>
  25. #include "qca_7k.h"
  26. #include "qca_debug.h"
  27. #define QCASPI_MAX_REGS 0x20
  28. static const u16 qcaspi_spi_regs[] = {
  29. SPI_REG_BFR_SIZE,
  30. SPI_REG_WRBUF_SPC_AVA,
  31. SPI_REG_RDBUF_BYTE_AVA,
  32. SPI_REG_SPI_CONFIG,
  33. SPI_REG_SPI_STATUS,
  34. SPI_REG_INTR_CAUSE,
  35. SPI_REG_INTR_ENABLE,
  36. SPI_REG_RDBUF_WATERMARK,
  37. SPI_REG_WRBUF_WATERMARK,
  38. SPI_REG_SIGNATURE,
  39. SPI_REG_ACTION_CTRL
  40. };
  41. /* The order of these strings must match the order of the fields in
  42. * struct qcaspi_stats
  43. * See qca_spi.h
  44. */
  45. static const char qcaspi_gstrings_stats[][ETH_GSTRING_LEN] = {
  46. "Triggered resets",
  47. "Device resets",
  48. "Reset timeouts",
  49. "Read errors",
  50. "Write errors",
  51. "Read buffer errors",
  52. "Write buffer errors",
  53. "Out of memory",
  54. "Write buffer misses",
  55. "Transmit ring full",
  56. "SPI errors",
  57. "Write verify errors",
  58. "Buffer available errors",
  59. "Bad signature",
  60. };
  61. #ifdef CONFIG_DEBUG_FS
  62. static int
  63. qcaspi_info_show(struct seq_file *s, void *what)
  64. {
  65. struct qcaspi *qca = s->private;
  66. seq_printf(s, "RX buffer size : %lu\n",
  67. (unsigned long)qca->buffer_size);
  68. seq_puts(s, "TX ring state : ");
  69. if (qca->txr.skb[qca->txr.head] == NULL)
  70. seq_puts(s, "empty");
  71. else if (qca->txr.skb[qca->txr.tail])
  72. seq_puts(s, "full");
  73. else
  74. seq_puts(s, "in use");
  75. seq_puts(s, "\n");
  76. seq_printf(s, "TX ring size : %u\n",
  77. qca->txr.size);
  78. seq_printf(s, "Sync state : %u (",
  79. (unsigned int)qca->sync);
  80. switch (qca->sync) {
  81. case QCASPI_SYNC_UNKNOWN:
  82. seq_puts(s, "QCASPI_SYNC_UNKNOWN");
  83. break;
  84. case QCASPI_SYNC_RESET:
  85. seq_puts(s, "QCASPI_SYNC_RESET");
  86. break;
  87. case QCASPI_SYNC_READY:
  88. seq_puts(s, "QCASPI_SYNC_READY");
  89. break;
  90. default:
  91. seq_puts(s, "INVALID");
  92. break;
  93. }
  94. seq_puts(s, ")\n");
  95. seq_printf(s, "IRQ : %d\n",
  96. qca->spi_dev->irq);
  97. seq_printf(s, "INTR REQ : %u\n",
  98. qca->intr_req);
  99. seq_printf(s, "INTR SVC : %u\n",
  100. qca->intr_svc);
  101. seq_printf(s, "SPI max speed : %lu\n",
  102. (unsigned long)qca->spi_dev->max_speed_hz);
  103. seq_printf(s, "SPI mode : %x\n",
  104. qca->spi_dev->mode);
  105. seq_printf(s, "SPI chip select : %u\n",
  106. (unsigned int)qca->spi_dev->chip_select);
  107. seq_printf(s, "SPI legacy mode : %u\n",
  108. (unsigned int)qca->legacy_mode);
  109. seq_printf(s, "SPI burst length : %u\n",
  110. (unsigned int)qca->burst_len);
  111. return 0;
  112. }
  113. DEFINE_SHOW_ATTRIBUTE(qcaspi_info);
  114. void
  115. qcaspi_init_device_debugfs(struct qcaspi *qca)
  116. {
  117. qca->device_root = debugfs_create_dir(dev_name(&qca->net_dev->dev),
  118. NULL);
  119. debugfs_create_file("info", S_IFREG | 0444, qca->device_root, qca,
  120. &qcaspi_info_fops);
  121. }
  122. void
  123. qcaspi_remove_device_debugfs(struct qcaspi *qca)
  124. {
  125. debugfs_remove_recursive(qca->device_root);
  126. }
  127. #else /* CONFIG_DEBUG_FS */
  128. void
  129. qcaspi_init_device_debugfs(struct qcaspi *qca)
  130. {
  131. }
  132. void
  133. qcaspi_remove_device_debugfs(struct qcaspi *qca)
  134. {
  135. }
  136. #endif
  137. static void
  138. qcaspi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *p)
  139. {
  140. struct qcaspi *qca = netdev_priv(dev);
  141. strscpy(p->driver, QCASPI_DRV_NAME, sizeof(p->driver));
  142. strscpy(p->version, QCASPI_DRV_VERSION, sizeof(p->version));
  143. strscpy(p->fw_version, "QCA7000", sizeof(p->fw_version));
  144. strscpy(p->bus_info, dev_name(&qca->spi_dev->dev),
  145. sizeof(p->bus_info));
  146. }
  147. static int
  148. qcaspi_get_link_ksettings(struct net_device *dev,
  149. struct ethtool_link_ksettings *cmd)
  150. {
  151. ethtool_link_ksettings_zero_link_mode(cmd, supported);
  152. ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
  153. cmd->base.speed = SPEED_10;
  154. cmd->base.duplex = DUPLEX_HALF;
  155. cmd->base.port = PORT_OTHER;
  156. cmd->base.autoneg = AUTONEG_DISABLE;
  157. return 0;
  158. }
  159. static void
  160. qcaspi_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *data)
  161. {
  162. struct qcaspi *qca = netdev_priv(dev);
  163. struct qcaspi_stats *st = &qca->stats;
  164. memcpy(data, st, ARRAY_SIZE(qcaspi_gstrings_stats) * sizeof(u64));
  165. }
  166. static void
  167. qcaspi_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  168. {
  169. switch (stringset) {
  170. case ETH_SS_STATS:
  171. memcpy(buf, &qcaspi_gstrings_stats,
  172. sizeof(qcaspi_gstrings_stats));
  173. break;
  174. default:
  175. WARN_ON(1);
  176. break;
  177. }
  178. }
  179. static int
  180. qcaspi_get_sset_count(struct net_device *dev, int sset)
  181. {
  182. switch (sset) {
  183. case ETH_SS_STATS:
  184. return ARRAY_SIZE(qcaspi_gstrings_stats);
  185. default:
  186. return -EINVAL;
  187. }
  188. }
  189. static int
  190. qcaspi_get_regs_len(struct net_device *dev)
  191. {
  192. return sizeof(u32) * QCASPI_MAX_REGS;
  193. }
  194. static void
  195. qcaspi_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
  196. {
  197. struct qcaspi *qca = netdev_priv(dev);
  198. u32 *regs_buff = p;
  199. unsigned int i;
  200. regs->version = 1;
  201. memset(regs_buff, 0, sizeof(u32) * QCASPI_MAX_REGS);
  202. for (i = 0; i < ARRAY_SIZE(qcaspi_spi_regs); i++) {
  203. u16 offset, value;
  204. qcaspi_read_register(qca, qcaspi_spi_regs[i], &value);
  205. offset = qcaspi_spi_regs[i] >> 8;
  206. regs_buff[offset] = value;
  207. }
  208. }
  209. static void
  210. qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
  211. struct kernel_ethtool_ringparam *kernel_ring,
  212. struct netlink_ext_ack *extack)
  213. {
  214. struct qcaspi *qca = netdev_priv(dev);
  215. ring->rx_max_pending = 4;
  216. ring->tx_max_pending = TX_RING_MAX_LEN;
  217. ring->rx_pending = 4;
  218. ring->tx_pending = qca->txr.count;
  219. }
  220. static int
  221. qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
  222. struct kernel_ethtool_ringparam *kernel_ring,
  223. struct netlink_ext_ack *extack)
  224. {
  225. const struct net_device_ops *ops = dev->netdev_ops;
  226. struct qcaspi *qca = netdev_priv(dev);
  227. if ((ring->rx_pending) ||
  228. (ring->rx_mini_pending) ||
  229. (ring->rx_jumbo_pending))
  230. return -EINVAL;
  231. if (netif_running(dev))
  232. ops->ndo_stop(dev);
  233. qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
  234. qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
  235. if (netif_running(dev))
  236. ops->ndo_open(dev);
  237. return 0;
  238. }
  239. static const struct ethtool_ops qcaspi_ethtool_ops = {
  240. .get_drvinfo = qcaspi_get_drvinfo,
  241. .get_link = ethtool_op_get_link,
  242. .get_ethtool_stats = qcaspi_get_ethtool_stats,
  243. .get_strings = qcaspi_get_strings,
  244. .get_sset_count = qcaspi_get_sset_count,
  245. .get_regs_len = qcaspi_get_regs_len,
  246. .get_regs = qcaspi_get_regs,
  247. .get_ringparam = qcaspi_get_ringparam,
  248. .set_ringparam = qcaspi_set_ringparam,
  249. .get_link_ksettings = qcaspi_get_link_ksettings,
  250. };
  251. void qcaspi_set_ethtool_ops(struct net_device *dev)
  252. {
  253. dev->ethtool_ops = &qcaspi_ethtool_ops;
  254. }