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",
65 #ifdef CONFIG_DEBUG_FS
68 qcaspi_info_show(struct seq_file *s, void *what)
70 struct qcaspi *qca = s->private;
72 seq_printf(s, "RX buffer size : %lu\n",
73 (unsigned long)qca->buffer_size);
75 seq_puts(s, "TX ring state : ");
77 if (qca->txr.skb[qca->txr.head] == NULL)
79 else if (qca->txr.skb[qca->txr.tail])
82 seq_puts(s, "in use");
86 seq_printf(s, "TX ring size : %u\n",
89 seq_printf(s, "Sync state : %u (",
90 (unsigned int)qca->sync);
92 case QCASPI_SYNC_UNKNOWN:
93 seq_puts(s, "QCASPI_SYNC_UNKNOWN");
95 case QCASPI_SYNC_RESET:
96 seq_puts(s, "QCASPI_SYNC_RESET");
98 case QCASPI_SYNC_READY:
99 seq_puts(s, "QCASPI_SYNC_READY");
102 seq_puts(s, "INVALID");
107 seq_printf(s, "IRQ : %d\n",
109 seq_printf(s, "INTR REQ : %u\n",
111 seq_printf(s, "INTR SVC : %u\n",
114 seq_printf(s, "SPI max speed : %lu\n",
115 (unsigned long)qca->spi_dev->max_speed_hz);
116 seq_printf(s, "SPI mode : %x\n",
118 seq_printf(s, "SPI chip select : %u\n",
119 (unsigned int)qca->spi_dev->chip_select);
120 seq_printf(s, "SPI legacy mode : %u\n",
121 (unsigned int)qca->legacy_mode);
122 seq_printf(s, "SPI burst length : %u\n",
123 (unsigned int)qca->burst_len);
129 qcaspi_info_open(struct inode *inode, struct file *file)
131 return single_open(file, qcaspi_info_show, inode->i_private);
134 static const struct file_operations qcaspi_info_ops = {
135 .open = qcaspi_info_open,
138 .release = single_release,
142 qcaspi_init_device_debugfs(struct qcaspi *qca)
144 struct dentry *device_root;
146 device_root = debugfs_create_dir(dev_name(&qca->net_dev->dev), NULL);
147 qca->device_root = device_root;
149 if (IS_ERR(device_root) || !device_root) {
150 pr_warn("failed to create debugfs directory for %s\n",
151 dev_name(&qca->net_dev->dev));
154 debugfs_create_file("info", S_IFREG | S_IRUGO, device_root, qca,
159 qcaspi_remove_device_debugfs(struct qcaspi *qca)
161 debugfs_remove_recursive(qca->device_root);
164 #else /* CONFIG_DEBUG_FS */
167 qcaspi_init_device_debugfs(struct qcaspi *qca)
172 qcaspi_remove_device_debugfs(struct qcaspi *qca)
179 qcaspi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *p)
181 struct qcaspi *qca = netdev_priv(dev);
183 strlcpy(p->driver, QCASPI_DRV_NAME, sizeof(p->driver));
184 strlcpy(p->version, QCASPI_DRV_VERSION, sizeof(p->version));
185 strlcpy(p->fw_version, "QCA7000", sizeof(p->fw_version));
186 strlcpy(p->bus_info, dev_name(&qca->spi_dev->dev),
187 sizeof(p->bus_info));
191 qcaspi_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
193 cmd->transceiver = XCVR_INTERNAL;
194 cmd->supported = SUPPORTED_10baseT_Half;
195 ethtool_cmd_speed_set(cmd, SPEED_10);
196 cmd->duplex = DUPLEX_HALF;
197 cmd->port = PORT_OTHER;
198 cmd->autoneg = AUTONEG_DISABLE;
204 qcaspi_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *data)
206 struct qcaspi *qca = netdev_priv(dev);
207 struct qcaspi_stats *st = &qca->stats;
209 memcpy(data, st, ARRAY_SIZE(qcaspi_gstrings_stats) * sizeof(u64));
213 qcaspi_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
217 memcpy(buf, &qcaspi_gstrings_stats,
218 sizeof(qcaspi_gstrings_stats));
227 qcaspi_get_sset_count(struct net_device *dev, int sset)
231 return ARRAY_SIZE(qcaspi_gstrings_stats);
238 qcaspi_get_regs_len(struct net_device *dev)
240 return sizeof(u32) * QCASPI_MAX_REGS;
244 qcaspi_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
246 struct qcaspi *qca = netdev_priv(dev);
251 memset(regs_buff, 0, sizeof(u32) * QCASPI_MAX_REGS);
253 for (i = 0; i < ARRAY_SIZE(qcaspi_spi_regs); i++) {
256 qcaspi_read_register(qca, qcaspi_spi_regs[i], &value);
257 offset = qcaspi_spi_regs[i] >> 8;
258 regs_buff[offset] = value;
263 qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
265 struct qcaspi *qca = netdev_priv(dev);
267 ring->rx_max_pending = 4;
268 ring->tx_max_pending = TX_RING_MAX_LEN;
269 ring->rx_pending = 4;
270 ring->tx_pending = qca->txr.count;
274 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
276 struct qcaspi *qca = netdev_priv(dev);
278 if ((ring->rx_pending) ||
279 (ring->rx_mini_pending) ||
280 (ring->rx_jumbo_pending))
283 if (netif_running(dev))
284 qcaspi_netdev_close(dev);
286 qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
287 qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
289 if (netif_running(dev))
290 qcaspi_netdev_open(dev);
295 static const struct ethtool_ops qcaspi_ethtool_ops = {
296 .get_drvinfo = qcaspi_get_drvinfo,
297 .get_link = ethtool_op_get_link,
298 .get_settings = qcaspi_get_settings,
299 .get_ethtool_stats = qcaspi_get_ethtool_stats,
300 .get_strings = qcaspi_get_strings,
301 .get_sset_count = qcaspi_get_sset_count,
302 .get_regs_len = qcaspi_get_regs_len,
303 .get_regs = qcaspi_get_regs,
304 .get_ringparam = qcaspi_get_ringparam,
305 .set_ringparam = qcaspi_set_ringparam,
308 void qcaspi_set_ethtool_ops(struct net_device *dev)
310 dev->ethtool_ops = &qcaspi_ethtool_ops;