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 #define QCASPI_RX_MAX_FRAMES 4
35 static const u16 qcaspi_spi_regs[] = {
37 SPI_REG_WRBUF_SPC_AVA,
38 SPI_REG_RDBUF_BYTE_AVA,
43 SPI_REG_RDBUF_WATERMARK,
44 SPI_REG_WRBUF_WATERMARK,
49 /* The order of these strings must match the order of the fields in
53 static const char qcaspi_gstrings_stats[][ETH_GSTRING_LEN] = {
60 "Write buffer errors",
62 "Write buffer misses",
65 "Write verify errors",
66 "Buffer available errors",
69 #ifdef CONFIG_DEBUG_FS
72 qcaspi_info_show(struct seq_file *s, void *what)
74 struct qcaspi *qca = s->private;
76 seq_printf(s, "RX buffer size : %lu\n",
77 (unsigned long)qca->buffer_size);
79 seq_puts(s, "TX ring state : ");
81 if (qca->txr.skb[qca->txr.head] == NULL)
83 else if (qca->txr.skb[qca->txr.tail])
86 seq_puts(s, "in use");
90 seq_printf(s, "TX ring size : %u\n",
93 seq_printf(s, "Sync state : %u (",
94 (unsigned int)qca->sync);
96 case QCASPI_SYNC_UNKNOWN:
97 seq_puts(s, "QCASPI_SYNC_UNKNOWN");
99 case QCASPI_SYNC_RESET:
100 seq_puts(s, "QCASPI_SYNC_RESET");
102 case QCASPI_SYNC_READY:
103 seq_puts(s, "QCASPI_SYNC_READY");
106 seq_puts(s, "INVALID");
111 seq_printf(s, "IRQ : %d\n",
113 seq_printf(s, "INTR REQ : %u\n",
115 seq_printf(s, "INTR SVC : %u\n",
118 seq_printf(s, "SPI max speed : %lu\n",
119 (unsigned long)qca->spi_dev->max_speed_hz);
120 seq_printf(s, "SPI mode : %x\n",
122 seq_printf(s, "SPI chip select : %u\n",
123 (unsigned int)qca->spi_dev->chip_select);
124 seq_printf(s, "SPI legacy mode : %u\n",
125 (unsigned int)qca->legacy_mode);
126 seq_printf(s, "SPI burst length : %u\n",
127 (unsigned int)qca->burst_len);
131 DEFINE_SHOW_ATTRIBUTE(qcaspi_info);
134 qcaspi_init_device_debugfs(struct qcaspi *qca)
136 qca->device_root = debugfs_create_dir(dev_name(&qca->net_dev->dev),
139 debugfs_create_file("info", S_IFREG | 0444, qca->device_root, qca,
144 qcaspi_remove_device_debugfs(struct qcaspi *qca)
146 debugfs_remove_recursive(qca->device_root);
149 #else /* CONFIG_DEBUG_FS */
152 qcaspi_init_device_debugfs(struct qcaspi *qca)
157 qcaspi_remove_device_debugfs(struct qcaspi *qca)
164 qcaspi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *p)
166 struct qcaspi *qca = netdev_priv(dev);
168 strlcpy(p->driver, QCASPI_DRV_NAME, sizeof(p->driver));
169 strlcpy(p->version, QCASPI_DRV_VERSION, sizeof(p->version));
170 strlcpy(p->fw_version, "QCA7000", sizeof(p->fw_version));
171 strlcpy(p->bus_info, dev_name(&qca->spi_dev->dev),
172 sizeof(p->bus_info));
176 qcaspi_get_link_ksettings(struct net_device *dev,
177 struct ethtool_link_ksettings *cmd)
179 ethtool_link_ksettings_zero_link_mode(cmd, supported);
180 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
182 cmd->base.speed = SPEED_10;
183 cmd->base.duplex = DUPLEX_HALF;
184 cmd->base.port = PORT_OTHER;
185 cmd->base.autoneg = AUTONEG_DISABLE;
191 qcaspi_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *data)
193 struct qcaspi *qca = netdev_priv(dev);
194 struct qcaspi_stats *st = &qca->stats;
196 memcpy(data, st, ARRAY_SIZE(qcaspi_gstrings_stats) * sizeof(u64));
200 qcaspi_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
204 memcpy(buf, &qcaspi_gstrings_stats,
205 sizeof(qcaspi_gstrings_stats));
214 qcaspi_get_sset_count(struct net_device *dev, int sset)
218 return ARRAY_SIZE(qcaspi_gstrings_stats);
225 qcaspi_get_regs_len(struct net_device *dev)
227 return sizeof(u32) * QCASPI_MAX_REGS;
231 qcaspi_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
233 struct qcaspi *qca = netdev_priv(dev);
238 memset(regs_buff, 0, sizeof(u32) * QCASPI_MAX_REGS);
240 for (i = 0; i < ARRAY_SIZE(qcaspi_spi_regs); i++) {
243 qcaspi_read_register(qca, qcaspi_spi_regs[i], &value);
244 offset = qcaspi_spi_regs[i] >> 8;
245 regs_buff[offset] = value;
250 qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
252 struct qcaspi *qca = netdev_priv(dev);
254 ring->rx_max_pending = QCASPI_RX_MAX_FRAMES;
255 ring->tx_max_pending = TX_RING_MAX_LEN;
256 ring->rx_pending = QCASPI_RX_MAX_FRAMES;
257 ring->tx_pending = qca->txr.count;
261 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
263 struct qcaspi *qca = netdev_priv(dev);
265 if (ring->rx_pending != QCASPI_RX_MAX_FRAMES ||
266 (ring->rx_mini_pending) ||
267 (ring->rx_jumbo_pending))
271 kthread_park(qca->spi_thread);
273 qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
274 qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
277 kthread_unpark(qca->spi_thread);
282 static const struct ethtool_ops qcaspi_ethtool_ops = {
283 .get_drvinfo = qcaspi_get_drvinfo,
284 .get_link = ethtool_op_get_link,
285 .get_ethtool_stats = qcaspi_get_ethtool_stats,
286 .get_strings = qcaspi_get_strings,
287 .get_sset_count = qcaspi_get_sset_count,
288 .get_regs_len = qcaspi_get_regs_len,
289 .get_regs = qcaspi_get_regs,
290 .get_ringparam = qcaspi_get_ringparam,
291 .set_ringparam = qcaspi_set_ringparam,
292 .get_link_ksettings = qcaspi_get_link_ksettings,
295 void qcaspi_set_ethtool_ops(struct net_device *dev)
297 dev->ethtool_ops = &qcaspi_ethtool_ops;