2 * Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
3 * Copyright (c) 2014, I2SE GmbH
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
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.
20 /* This file contains debugging routines for use in the QCA7K driver.
23 #include <linux/debugfs.h>
24 #include <linux/ethtool.h>
25 #include <linux/seq_file.h>
26 #include <linux/types.h>
29 #include "qca_debug.h"
31 #define QCASPI_MAX_REGS 0x20
33 static const u16 qcaspi_spi_regs[] = {
35 SPI_REG_WRBUF_SPC_AVA,
36 SPI_REG_RDBUF_BYTE_AVA,
41 SPI_REG_RDBUF_WATERMARK,
42 SPI_REG_WRBUF_WATERMARK,
47 /* The order of these strings must match the order of the fields in
51 static const char qcaspi_gstrings_stats[][ETH_GSTRING_LEN] = {
58 "Write buffer errors",
60 "Write buffer misses",
63 "Write verify errors",
64 "Buffer available errors",
68 #ifdef CONFIG_DEBUG_FS
71 qcaspi_info_show(struct seq_file *s, void *what)
73 struct qcaspi *qca = s->private;
75 seq_printf(s, "RX buffer size : %lu\n",
76 (unsigned long)qca->buffer_size);
78 seq_puts(s, "TX ring state : ");
80 if (qca->txr.skb[qca->txr.head] == NULL)
82 else if (qca->txr.skb[qca->txr.tail])
85 seq_puts(s, "in use");
89 seq_printf(s, "TX ring size : %u\n",
92 seq_printf(s, "Sync state : %u (",
93 (unsigned int)qca->sync);
95 case QCASPI_SYNC_UNKNOWN:
96 seq_puts(s, "QCASPI_SYNC_UNKNOWN");
98 case QCASPI_SYNC_RESET:
99 seq_puts(s, "QCASPI_SYNC_RESET");
101 case QCASPI_SYNC_READY:
102 seq_puts(s, "QCASPI_SYNC_READY");
105 seq_puts(s, "INVALID");
110 seq_printf(s, "IRQ : %d\n",
112 seq_printf(s, "INTR REQ : %u\n",
114 seq_printf(s, "INTR SVC : %u\n",
117 seq_printf(s, "SPI max speed : %lu\n",
118 (unsigned long)qca->spi_dev->max_speed_hz);
119 seq_printf(s, "SPI mode : %x\n",
121 seq_printf(s, "SPI chip select : %u\n",
122 (unsigned int)spi_get_chipselect(qca->spi_dev, 0));
123 seq_printf(s, "SPI legacy mode : %u\n",
124 (unsigned int)qca->legacy_mode);
125 seq_printf(s, "SPI burst length : %u\n",
126 (unsigned int)qca->burst_len);
130 DEFINE_SHOW_ATTRIBUTE(qcaspi_info);
133 qcaspi_init_device_debugfs(struct qcaspi *qca)
135 qca->device_root = debugfs_create_dir(dev_name(&qca->net_dev->dev),
138 debugfs_create_file("info", S_IFREG | 0444, qca->device_root, qca,
143 qcaspi_remove_device_debugfs(struct qcaspi *qca)
145 debugfs_remove_recursive(qca->device_root);
148 #else /* CONFIG_DEBUG_FS */
151 qcaspi_init_device_debugfs(struct qcaspi *qca)
156 qcaspi_remove_device_debugfs(struct qcaspi *qca)
163 qcaspi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *p)
165 struct qcaspi *qca = netdev_priv(dev);
167 strscpy(p->driver, QCASPI_DRV_NAME, sizeof(p->driver));
168 strscpy(p->version, QCASPI_DRV_VERSION, sizeof(p->version));
169 strscpy(p->fw_version, "QCA7000", sizeof(p->fw_version));
170 strscpy(p->bus_info, dev_name(&qca->spi_dev->dev),
171 sizeof(p->bus_info));
175 qcaspi_get_link_ksettings(struct net_device *dev,
176 struct ethtool_link_ksettings *cmd)
178 ethtool_link_ksettings_zero_link_mode(cmd, supported);
179 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
181 cmd->base.speed = SPEED_10;
182 cmd->base.duplex = DUPLEX_HALF;
183 cmd->base.port = PORT_OTHER;
184 cmd->base.autoneg = AUTONEG_DISABLE;
190 qcaspi_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *data)
192 struct qcaspi *qca = netdev_priv(dev);
193 struct qcaspi_stats *st = &qca->stats;
195 memcpy(data, st, ARRAY_SIZE(qcaspi_gstrings_stats) * sizeof(u64));
199 qcaspi_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
203 memcpy(buf, &qcaspi_gstrings_stats,
204 sizeof(qcaspi_gstrings_stats));
213 qcaspi_get_sset_count(struct net_device *dev, int sset)
217 return ARRAY_SIZE(qcaspi_gstrings_stats);
224 qcaspi_get_regs_len(struct net_device *dev)
226 return sizeof(u32) * QCASPI_MAX_REGS;
230 qcaspi_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
232 struct qcaspi *qca = netdev_priv(dev);
237 memset(regs_buff, 0, sizeof(u32) * QCASPI_MAX_REGS);
239 for (i = 0; i < ARRAY_SIZE(qcaspi_spi_regs); i++) {
242 qcaspi_read_register(qca, qcaspi_spi_regs[i], &value);
243 offset = qcaspi_spi_regs[i] >> 8;
244 regs_buff[offset] = value;
249 qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
250 struct kernel_ethtool_ringparam *kernel_ring,
251 struct netlink_ext_ack *extack)
253 struct qcaspi *qca = netdev_priv(dev);
255 ring->rx_max_pending = 4;
256 ring->tx_max_pending = TX_RING_MAX_LEN;
257 ring->rx_pending = 4;
258 ring->tx_pending = qca->txr.count;
262 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
263 struct kernel_ethtool_ringparam *kernel_ring,
264 struct netlink_ext_ack *extack)
266 struct qcaspi *qca = netdev_priv(dev);
268 if ((ring->rx_pending) ||
269 (ring->rx_mini_pending) ||
270 (ring->rx_jumbo_pending))
274 kthread_park(qca->spi_thread);
276 qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
277 qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
280 kthread_unpark(qca->spi_thread);
285 static const struct ethtool_ops qcaspi_ethtool_ops = {
286 .get_drvinfo = qcaspi_get_drvinfo,
287 .get_link = ethtool_op_get_link,
288 .get_ethtool_stats = qcaspi_get_ethtool_stats,
289 .get_strings = qcaspi_get_strings,
290 .get_sset_count = qcaspi_get_sset_count,
291 .get_regs_len = qcaspi_get_regs_len,
292 .get_regs = qcaspi_get_regs,
293 .get_ringparam = qcaspi_get_ringparam,
294 .set_ringparam = qcaspi_set_ringparam,
295 .get_link_ksettings = qcaspi_get_link_ksettings,
298 void qcaspi_set_ethtool_ops(struct net_device *dev)
300 dev->ethtool_ops = &qcaspi_ethtool_ops;