qca_debug.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. };
  58. #ifdef CONFIG_DEBUG_FS
  59. static int
  60. qcaspi_info_show(struct seq_file *s, void *what)
  61. {
  62. struct qcaspi *qca = s->private;
  63. seq_printf(s, "RX buffer size : %lu\n",
  64. (unsigned long)qca->buffer_size);
  65. seq_puts(s, "TX ring state : ");
  66. if (qca->txr.skb[qca->txr.head] == NULL)
  67. seq_puts(s, "empty");
  68. else if (qca->txr.skb[qca->txr.tail])
  69. seq_puts(s, "full");
  70. else
  71. seq_puts(s, "in use");
  72. seq_puts(s, "\n");
  73. seq_printf(s, "TX ring size : %u\n",
  74. qca->txr.size);
  75. seq_printf(s, "Sync state : %u (",
  76. (unsigned int)qca->sync);
  77. switch (qca->sync) {
  78. case QCASPI_SYNC_UNKNOWN:
  79. seq_puts(s, "QCASPI_SYNC_UNKNOWN");
  80. break;
  81. case QCASPI_SYNC_RESET:
  82. seq_puts(s, "QCASPI_SYNC_RESET");
  83. break;
  84. case QCASPI_SYNC_READY:
  85. seq_puts(s, "QCASPI_SYNC_READY");
  86. break;
  87. default:
  88. seq_puts(s, "INVALID");
  89. break;
  90. }
  91. seq_puts(s, ")\n");
  92. seq_printf(s, "IRQ : %d\n",
  93. qca->spi_dev->irq);
  94. seq_printf(s, "INTR REQ : %u\n",
  95. qca->intr_req);
  96. seq_printf(s, "INTR SVC : %u\n",
  97. qca->intr_svc);
  98. seq_printf(s, "SPI max speed : %lu\n",
  99. (unsigned long)qca->spi_dev->max_speed_hz);
  100. seq_printf(s, "SPI mode : %x\n",
  101. qca->spi_dev->mode);
  102. seq_printf(s, "SPI chip select : %u\n",
  103. (unsigned int)qca->spi_dev->chip_select);
  104. seq_printf(s, "SPI legacy mode : %u\n",
  105. (unsigned int)qca->legacy_mode);
  106. seq_printf(s, "SPI burst length : %u\n",
  107. (unsigned int)qca->burst_len);
  108. return 0;
  109. }
  110. static int
  111. qcaspi_info_open(struct inode *inode, struct file *file)
  112. {
  113. return single_open(file, qcaspi_info_show, inode->i_private);
  114. }
  115. static const struct file_operations qcaspi_info_ops = {
  116. .open = qcaspi_info_open,
  117. .read = seq_read,
  118. .llseek = seq_lseek,
  119. .release = single_release,
  120. };
  121. void
  122. qcaspi_init_device_debugfs(struct qcaspi *qca)
  123. {
  124. struct dentry *device_root;
  125. device_root = debugfs_create_dir(dev_name(&qca->net_dev->dev), NULL);
  126. qca->device_root = device_root;
  127. if (IS_ERR(device_root) || !device_root) {
  128. pr_warn("failed to create debugfs directory for %s\n",
  129. dev_name(&qca->net_dev->dev));
  130. return;
  131. }
  132. debugfs_create_file("info", S_IFREG | S_IRUGO, device_root, qca,
  133. &qcaspi_info_ops);
  134. }
  135. void
  136. qcaspi_remove_device_debugfs(struct qcaspi *qca)
  137. {
  138. debugfs_remove_recursive(qca->device_root);
  139. }
  140. #else /* CONFIG_DEBUG_FS */
  141. void
  142. qcaspi_init_device_debugfs(struct qcaspi *qca)
  143. {
  144. }
  145. void
  146. qcaspi_remove_device_debugfs(struct qcaspi *qca)
  147. {
  148. }
  149. #endif
  150. static void
  151. qcaspi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *p)
  152. {
  153. struct qcaspi *qca = netdev_priv(dev);
  154. strlcpy(p->driver, QCASPI_DRV_NAME, sizeof(p->driver));
  155. strlcpy(p->version, QCASPI_DRV_VERSION, sizeof(p->version));
  156. strlcpy(p->fw_version, "QCA7000", sizeof(p->fw_version));
  157. strlcpy(p->bus_info, dev_name(&qca->spi_dev->dev),
  158. sizeof(p->bus_info));
  159. }
  160. static int
  161. qcaspi_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  162. {
  163. cmd->transceiver = XCVR_INTERNAL;
  164. cmd->supported = SUPPORTED_10baseT_Half;
  165. ethtool_cmd_speed_set(cmd, SPEED_10);
  166. cmd->duplex = DUPLEX_HALF;
  167. cmd->port = PORT_OTHER;
  168. cmd->autoneg = AUTONEG_DISABLE;
  169. return 0;
  170. }
  171. static void
  172. qcaspi_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *data)
  173. {
  174. struct qcaspi *qca = netdev_priv(dev);
  175. struct qcaspi_stats *st = &qca->stats;
  176. memcpy(data, st, ARRAY_SIZE(qcaspi_gstrings_stats) * sizeof(u64));
  177. }
  178. static void
  179. qcaspi_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  180. {
  181. switch (stringset) {
  182. case ETH_SS_STATS:
  183. memcpy(buf, &qcaspi_gstrings_stats,
  184. sizeof(qcaspi_gstrings_stats));
  185. break;
  186. default:
  187. WARN_ON(1);
  188. break;
  189. }
  190. }
  191. static int
  192. qcaspi_get_sset_count(struct net_device *dev, int sset)
  193. {
  194. switch (sset) {
  195. case ETH_SS_STATS:
  196. return ARRAY_SIZE(qcaspi_gstrings_stats);
  197. default:
  198. return -EINVAL;
  199. }
  200. }
  201. static int
  202. qcaspi_get_regs_len(struct net_device *dev)
  203. {
  204. return sizeof(u32) * QCASPI_MAX_REGS;
  205. }
  206. static void
  207. qcaspi_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
  208. {
  209. struct qcaspi *qca = netdev_priv(dev);
  210. u32 *regs_buff = p;
  211. unsigned int i;
  212. regs->version = 1;
  213. memset(regs_buff, 0, sizeof(u32) * QCASPI_MAX_REGS);
  214. for (i = 0; i < ARRAY_SIZE(qcaspi_spi_regs); i++) {
  215. u16 offset, value;
  216. qcaspi_read_register(qca, qcaspi_spi_regs[i], &value);
  217. offset = qcaspi_spi_regs[i] >> 8;
  218. regs_buff[offset] = value;
  219. }
  220. }
  221. static void
  222. qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
  223. {
  224. struct qcaspi *qca = netdev_priv(dev);
  225. ring->rx_max_pending = 4;
  226. ring->tx_max_pending = TX_RING_MAX_LEN;
  227. ring->rx_pending = 4;
  228. ring->tx_pending = qca->txr.count;
  229. }
  230. static int
  231. qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
  232. {
  233. struct qcaspi *qca = netdev_priv(dev);
  234. if ((ring->rx_pending) ||
  235. (ring->rx_mini_pending) ||
  236. (ring->rx_jumbo_pending))
  237. return -EINVAL;
  238. if (netif_running(dev))
  239. qcaspi_netdev_close(dev);
  240. qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
  241. qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
  242. if (netif_running(dev))
  243. qcaspi_netdev_open(dev);
  244. return 0;
  245. }
  246. static const struct ethtool_ops qcaspi_ethtool_ops = {
  247. .get_drvinfo = qcaspi_get_drvinfo,
  248. .get_link = ethtool_op_get_link,
  249. .get_settings = qcaspi_get_settings,
  250. .get_ethtool_stats = qcaspi_get_ethtool_stats,
  251. .get_strings = qcaspi_get_strings,
  252. .get_sset_count = qcaspi_get_sset_count,
  253. .get_regs_len = qcaspi_get_regs_len,
  254. .get_regs = qcaspi_get_regs,
  255. .get_ringparam = qcaspi_get_ringparam,
  256. .set_ringparam = qcaspi_set_ringparam,
  257. };
  258. void qcaspi_set_ethtool_ops(struct net_device *dev)
  259. {
  260. dev->ethtool_ops = &qcaspi_ethtool_ops;
  261. }