Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
0003  *   Copyright (c) 2014, I2SE GmbH
0004  *
0005  *   Permission to use, copy, modify, and/or distribute this software
0006  *   for any purpose with or without fee is hereby granted, provided
0007  *   that the above copyright notice and this permission notice appear
0008  *   in all copies.
0009  *
0010  *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
0011  *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
0012  *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
0013  *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
0014  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
0015  *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
0016  *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
0017  *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0018  */
0019 
0020 /*   This file contains debugging routines for use in the QCA7K driver.
0021  */
0022 
0023 #include <linux/debugfs.h>
0024 #include <linux/ethtool.h>
0025 #include <linux/seq_file.h>
0026 #include <linux/types.h>
0027 
0028 #include "qca_7k.h"
0029 #include "qca_debug.h"
0030 
0031 #define QCASPI_MAX_REGS 0x20
0032 
0033 static const u16 qcaspi_spi_regs[] = {
0034     SPI_REG_BFR_SIZE,
0035     SPI_REG_WRBUF_SPC_AVA,
0036     SPI_REG_RDBUF_BYTE_AVA,
0037     SPI_REG_SPI_CONFIG,
0038     SPI_REG_SPI_STATUS,
0039     SPI_REG_INTR_CAUSE,
0040     SPI_REG_INTR_ENABLE,
0041     SPI_REG_RDBUF_WATERMARK,
0042     SPI_REG_WRBUF_WATERMARK,
0043     SPI_REG_SIGNATURE,
0044     SPI_REG_ACTION_CTRL
0045 };
0046 
0047 /* The order of these strings must match the order of the fields in
0048  * struct qcaspi_stats
0049  * See qca_spi.h
0050  */
0051 static const char qcaspi_gstrings_stats[][ETH_GSTRING_LEN] = {
0052     "Triggered resets",
0053     "Device resets",
0054     "Reset timeouts",
0055     "Read errors",
0056     "Write errors",
0057     "Read buffer errors",
0058     "Write buffer errors",
0059     "Out of memory",
0060     "Write buffer misses",
0061     "Transmit ring full",
0062     "SPI errors",
0063     "Write verify errors",
0064     "Buffer available errors",
0065     "Bad signature",
0066 };
0067 
0068 #ifdef CONFIG_DEBUG_FS
0069 
0070 static int
0071 qcaspi_info_show(struct seq_file *s, void *what)
0072 {
0073     struct qcaspi *qca = s->private;
0074 
0075     seq_printf(s, "RX buffer size   : %lu\n",
0076            (unsigned long)qca->buffer_size);
0077 
0078     seq_puts(s, "TX ring state    : ");
0079 
0080     if (qca->txr.skb[qca->txr.head] == NULL)
0081         seq_puts(s, "empty");
0082     else if (qca->txr.skb[qca->txr.tail])
0083         seq_puts(s, "full");
0084     else
0085         seq_puts(s, "in use");
0086 
0087     seq_puts(s, "\n");
0088 
0089     seq_printf(s, "TX ring size     : %u\n",
0090            qca->txr.size);
0091 
0092     seq_printf(s, "Sync state       : %u (",
0093            (unsigned int)qca->sync);
0094     switch (qca->sync) {
0095     case QCASPI_SYNC_UNKNOWN:
0096         seq_puts(s, "QCASPI_SYNC_UNKNOWN");
0097         break;
0098     case QCASPI_SYNC_RESET:
0099         seq_puts(s, "QCASPI_SYNC_RESET");
0100         break;
0101     case QCASPI_SYNC_READY:
0102         seq_puts(s, "QCASPI_SYNC_READY");
0103         break;
0104     default:
0105         seq_puts(s, "INVALID");
0106         break;
0107     }
0108     seq_puts(s, ")\n");
0109 
0110     seq_printf(s, "IRQ              : %d\n",
0111            qca->spi_dev->irq);
0112     seq_printf(s, "INTR REQ         : %u\n",
0113            qca->intr_req);
0114     seq_printf(s, "INTR SVC         : %u\n",
0115            qca->intr_svc);
0116 
0117     seq_printf(s, "SPI max speed    : %lu\n",
0118            (unsigned long)qca->spi_dev->max_speed_hz);
0119     seq_printf(s, "SPI mode         : %x\n",
0120            qca->spi_dev->mode);
0121     seq_printf(s, "SPI chip select  : %u\n",
0122            (unsigned int)qca->spi_dev->chip_select);
0123     seq_printf(s, "SPI legacy mode  : %u\n",
0124            (unsigned int)qca->legacy_mode);
0125     seq_printf(s, "SPI burst length : %u\n",
0126            (unsigned int)qca->burst_len);
0127 
0128     return 0;
0129 }
0130 DEFINE_SHOW_ATTRIBUTE(qcaspi_info);
0131 
0132 void
0133 qcaspi_init_device_debugfs(struct qcaspi *qca)
0134 {
0135     qca->device_root = debugfs_create_dir(dev_name(&qca->net_dev->dev),
0136                           NULL);
0137 
0138     debugfs_create_file("info", S_IFREG | 0444, qca->device_root, qca,
0139                 &qcaspi_info_fops);
0140 }
0141 
0142 void
0143 qcaspi_remove_device_debugfs(struct qcaspi *qca)
0144 {
0145     debugfs_remove_recursive(qca->device_root);
0146 }
0147 
0148 #else /* CONFIG_DEBUG_FS */
0149 
0150 void
0151 qcaspi_init_device_debugfs(struct qcaspi *qca)
0152 {
0153 }
0154 
0155 void
0156 qcaspi_remove_device_debugfs(struct qcaspi *qca)
0157 {
0158 }
0159 
0160 #endif
0161 
0162 static void
0163 qcaspi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *p)
0164 {
0165     struct qcaspi *qca = netdev_priv(dev);
0166 
0167     strlcpy(p->driver, QCASPI_DRV_NAME, sizeof(p->driver));
0168     strlcpy(p->version, QCASPI_DRV_VERSION, sizeof(p->version));
0169     strlcpy(p->fw_version, "QCA7000", sizeof(p->fw_version));
0170     strlcpy(p->bus_info, dev_name(&qca->spi_dev->dev),
0171         sizeof(p->bus_info));
0172 }
0173 
0174 static int
0175 qcaspi_get_link_ksettings(struct net_device *dev,
0176               struct ethtool_link_ksettings *cmd)
0177 {
0178     ethtool_link_ksettings_zero_link_mode(cmd, supported);
0179     ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
0180 
0181     cmd->base.speed = SPEED_10;
0182     cmd->base.duplex = DUPLEX_HALF;
0183     cmd->base.port = PORT_OTHER;
0184     cmd->base.autoneg = AUTONEG_DISABLE;
0185 
0186     return 0;
0187 }
0188 
0189 static void
0190 qcaspi_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *data)
0191 {
0192     struct qcaspi *qca = netdev_priv(dev);
0193     struct qcaspi_stats *st = &qca->stats;
0194 
0195     memcpy(data, st, ARRAY_SIZE(qcaspi_gstrings_stats) * sizeof(u64));
0196 }
0197 
0198 static void
0199 qcaspi_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
0200 {
0201     switch (stringset) {
0202     case ETH_SS_STATS:
0203         memcpy(buf, &qcaspi_gstrings_stats,
0204                sizeof(qcaspi_gstrings_stats));
0205         break;
0206     default:
0207         WARN_ON(1);
0208         break;
0209     }
0210 }
0211 
0212 static int
0213 qcaspi_get_sset_count(struct net_device *dev, int sset)
0214 {
0215     switch (sset) {
0216     case ETH_SS_STATS:
0217         return ARRAY_SIZE(qcaspi_gstrings_stats);
0218     default:
0219         return -EINVAL;
0220     }
0221 }
0222 
0223 static int
0224 qcaspi_get_regs_len(struct net_device *dev)
0225 {
0226     return sizeof(u32) * QCASPI_MAX_REGS;
0227 }
0228 
0229 static void
0230 qcaspi_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
0231 {
0232     struct qcaspi *qca = netdev_priv(dev);
0233     u32 *regs_buff = p;
0234     unsigned int i;
0235 
0236     regs->version = 1;
0237     memset(regs_buff, 0, sizeof(u32) * QCASPI_MAX_REGS);
0238 
0239     for (i = 0; i < ARRAY_SIZE(qcaspi_spi_regs); i++) {
0240         u16 offset, value;
0241 
0242         qcaspi_read_register(qca, qcaspi_spi_regs[i], &value);
0243         offset = qcaspi_spi_regs[i] >> 8;
0244         regs_buff[offset] = value;
0245     }
0246 }
0247 
0248 static void
0249 qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
0250              struct kernel_ethtool_ringparam *kernel_ring,
0251              struct netlink_ext_ack *extack)
0252 {
0253     struct qcaspi *qca = netdev_priv(dev);
0254 
0255     ring->rx_max_pending = 4;
0256     ring->tx_max_pending = TX_RING_MAX_LEN;
0257     ring->rx_pending = 4;
0258     ring->tx_pending = qca->txr.count;
0259 }
0260 
0261 static int
0262 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
0263              struct kernel_ethtool_ringparam *kernel_ring,
0264              struct netlink_ext_ack *extack)
0265 {
0266     const struct net_device_ops *ops = dev->netdev_ops;
0267     struct qcaspi *qca = netdev_priv(dev);
0268 
0269     if ((ring->rx_pending) ||
0270         (ring->rx_mini_pending) ||
0271         (ring->rx_jumbo_pending))
0272         return -EINVAL;
0273 
0274     if (netif_running(dev))
0275         ops->ndo_stop(dev);
0276 
0277     qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
0278     qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
0279 
0280     if (netif_running(dev))
0281         ops->ndo_open(dev);
0282 
0283     return 0;
0284 }
0285 
0286 static const struct ethtool_ops qcaspi_ethtool_ops = {
0287     .get_drvinfo = qcaspi_get_drvinfo,
0288     .get_link = ethtool_op_get_link,
0289     .get_ethtool_stats = qcaspi_get_ethtool_stats,
0290     .get_strings = qcaspi_get_strings,
0291     .get_sset_count = qcaspi_get_sset_count,
0292     .get_regs_len = qcaspi_get_regs_len,
0293     .get_regs = qcaspi_get_regs,
0294     .get_ringparam = qcaspi_get_ringparam,
0295     .set_ringparam = qcaspi_set_ringparam,
0296     .get_link_ksettings = qcaspi_get_link_ksettings,
0297 };
0298 
0299 void qcaspi_set_ethtool_ops(struct net_device *dev)
0300 {
0301     dev->ethtool_ops = &qcaspi_ethtool_ops;
0302 }