1 // SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
3 * Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
4 * Copyright (c) 2014, I2SE GmbH
7 /* This file contains debugging routines for use in the QCA7K driver.
10 #include <linux/debugfs.h>
11 #include <linux/ethtool.h>
12 #include <linux/seq_file.h>
13 #include <linux/types.h>
16 #include "qca_debug.h"
18 #define QCASPI_MAX_REGS 0x20
20 #define QCASPI_RX_MAX_FRAMES 4
22 static const u16 qcaspi_spi_regs[] = {
24 SPI_REG_WRBUF_SPC_AVA,
25 SPI_REG_RDBUF_BYTE_AVA,
30 SPI_REG_RDBUF_WATERMARK,
31 SPI_REG_WRBUF_WATERMARK,
36 /* The order of these strings must match the order of the fields in
40 static const char qcaspi_gstrings_stats[][ETH_GSTRING_LEN] = {
47 "Write buffer errors",
49 "Write buffer misses",
52 "Write verify errors",
53 "Buffer available errors",
57 #ifdef CONFIG_DEBUG_FS
60 qcaspi_info_show(struct seq_file *s, void *what)
62 struct qcaspi *qca = s->private;
64 seq_printf(s, "RX buffer size : %lu\n",
65 (unsigned long)qca->buffer_size);
67 seq_puts(s, "TX ring state : ");
69 if (qca->txr.skb[qca->txr.head] == NULL)
71 else if (qca->txr.skb[qca->txr.tail])
74 seq_puts(s, "in use");
78 seq_printf(s, "TX ring size : %u\n",
81 seq_printf(s, "Sync state : %u (",
82 (unsigned int)qca->sync);
84 case QCASPI_SYNC_UNKNOWN:
85 seq_puts(s, "QCASPI_SYNC_UNKNOWN");
87 case QCASPI_SYNC_RESET:
88 seq_puts(s, "QCASPI_SYNC_RESET");
90 case QCASPI_SYNC_READY:
91 seq_puts(s, "QCASPI_SYNC_READY");
94 seq_puts(s, "INVALID");
99 seq_printf(s, "IRQ : %d\n",
101 seq_printf(s, "INTR REQ : %u\n",
103 seq_printf(s, "INTR SVC : %u\n",
106 seq_printf(s, "SPI max speed : %lu\n",
107 (unsigned long)qca->spi_dev->max_speed_hz);
108 seq_printf(s, "SPI mode : %x\n",
110 seq_printf(s, "SPI chip select : %u\n",
111 (unsigned int)spi_get_chipselect(qca->spi_dev, 0));
112 seq_printf(s, "SPI legacy mode : %u\n",
113 (unsigned int)qca->legacy_mode);
114 seq_printf(s, "SPI burst length : %u\n",
115 (unsigned int)qca->burst_len);
119 DEFINE_SHOW_ATTRIBUTE(qcaspi_info);
122 qcaspi_init_device_debugfs(struct qcaspi *qca)
124 qca->device_root = debugfs_create_dir(dev_name(&qca->net_dev->dev),
127 debugfs_create_file("info", S_IFREG | 0444, qca->device_root, qca,
132 qcaspi_remove_device_debugfs(struct qcaspi *qca)
134 debugfs_remove_recursive(qca->device_root);
137 #else /* CONFIG_DEBUG_FS */
140 qcaspi_init_device_debugfs(struct qcaspi *qca)
145 qcaspi_remove_device_debugfs(struct qcaspi *qca)
152 qcaspi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *p)
154 struct qcaspi *qca = netdev_priv(dev);
156 strscpy(p->driver, QCASPI_DRV_NAME, sizeof(p->driver));
157 strscpy(p->version, QCASPI_DRV_VERSION, sizeof(p->version));
158 strscpy(p->fw_version, "QCA7000", sizeof(p->fw_version));
159 strscpy(p->bus_info, dev_name(&qca->spi_dev->dev),
160 sizeof(p->bus_info));
164 qcaspi_get_link_ksettings(struct net_device *dev,
165 struct ethtool_link_ksettings *cmd)
167 ethtool_link_ksettings_zero_link_mode(cmd, supported);
168 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
170 cmd->base.speed = SPEED_10;
171 cmd->base.duplex = DUPLEX_HALF;
172 cmd->base.port = PORT_OTHER;
173 cmd->base.autoneg = AUTONEG_DISABLE;
179 qcaspi_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *data)
181 struct qcaspi *qca = netdev_priv(dev);
182 struct qcaspi_stats *st = &qca->stats;
184 memcpy(data, st, ARRAY_SIZE(qcaspi_gstrings_stats) * sizeof(u64));
188 qcaspi_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
192 memcpy(buf, &qcaspi_gstrings_stats,
193 sizeof(qcaspi_gstrings_stats));
202 qcaspi_get_sset_count(struct net_device *dev, int sset)
206 return ARRAY_SIZE(qcaspi_gstrings_stats);
213 qcaspi_get_regs_len(struct net_device *dev)
215 return sizeof(u32) * QCASPI_MAX_REGS;
219 qcaspi_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
221 struct qcaspi *qca = netdev_priv(dev);
226 memset(regs_buff, 0, sizeof(u32) * QCASPI_MAX_REGS);
228 for (i = 0; i < ARRAY_SIZE(qcaspi_spi_regs); i++) {
231 qcaspi_read_register(qca, qcaspi_spi_regs[i], &value);
232 offset = qcaspi_spi_regs[i] >> 8;
233 regs_buff[offset] = value;
238 qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
239 struct kernel_ethtool_ringparam *kernel_ring,
240 struct netlink_ext_ack *extack)
242 struct qcaspi *qca = netdev_priv(dev);
244 ring->rx_max_pending = QCASPI_RX_MAX_FRAMES;
245 ring->tx_max_pending = QCASPI_TX_RING_MAX_LEN;
246 ring->rx_pending = QCASPI_RX_MAX_FRAMES;
247 ring->tx_pending = qca->txr.count;
251 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
252 struct kernel_ethtool_ringparam *kernel_ring,
253 struct netlink_ext_ack *extack)
255 struct qcaspi *qca = netdev_priv(dev);
257 if (ring->rx_pending != QCASPI_RX_MAX_FRAMES ||
258 (ring->rx_mini_pending) ||
259 (ring->rx_jumbo_pending))
263 kthread_park(qca->spi_thread);
265 qca->txr.count = max_t(u32, ring->tx_pending, QCASPI_TX_RING_MIN_LEN);
266 qca->txr.count = min_t(u16, qca->txr.count, QCASPI_TX_RING_MAX_LEN);
269 kthread_unpark(qca->spi_thread);
274 static const struct ethtool_ops qcaspi_ethtool_ops = {
275 .get_drvinfo = qcaspi_get_drvinfo,
276 .get_link = ethtool_op_get_link,
277 .get_ethtool_stats = qcaspi_get_ethtool_stats,
278 .get_strings = qcaspi_get_strings,
279 .get_sset_count = qcaspi_get_sset_count,
280 .get_regs_len = qcaspi_get_regs_len,
281 .get_regs = qcaspi_get_regs,
282 .get_ringparam = qcaspi_get_ringparam,
283 .set_ringparam = qcaspi_set_ringparam,
284 .get_link_ksettings = qcaspi_get_link_ksettings,
287 void qcaspi_set_ethtool_ops(struct net_device *dev)
289 dev->ethtool_ops = &qcaspi_ethtool_ops;