Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2007 Freescale Semiconductor, Inc. All rights reserved. |
| 3 | * |
| 4 | * Description: QE UCC Gigabit Ethernet Ethtool API Set |
| 5 | * |
| 6 | * Author: Li Yang <leoli@freescale.com> |
| 7 | * |
Jeff Garzik | 7d2e3cb | 2008-05-13 01:41:58 -0400 | [diff] [blame] | 8 | * Limitation: |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 9 | * Can only get/set setttings of the first queue. |
| 10 | * Need to re-open the interface manually after changing some paramters. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/stddef.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/etherdevice.h> |
| 26 | #include <linux/skbuff.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/dma-mapping.h> |
| 31 | #include <linux/fsl_devices.h> |
| 32 | #include <linux/ethtool.h> |
| 33 | #include <linux/mii.h> |
| 34 | #include <linux/phy.h> |
| 35 | |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/irq.h> |
| 38 | #include <asm/uaccess.h> |
| 39 | #include <asm/types.h> |
| 40 | #include <asm/uaccess.h> |
| 41 | |
| 42 | #include "ucc_geth.h" |
| 43 | #include "ucc_geth_mii.h" |
| 44 | |
| 45 | static char hw_stat_gstrings[][ETH_GSTRING_LEN] = { |
| 46 | "tx-64-frames", |
| 47 | "tx-65-127-frames", |
| 48 | "tx-128-255-frames", |
| 49 | "rx-64-frames", |
| 50 | "rx-65-127-frames", |
| 51 | "rx-128-255-frames", |
| 52 | "tx-bytes-ok", |
| 53 | "tx-pause-frames", |
| 54 | "tx-multicast-frames", |
| 55 | "tx-broadcast-frames", |
| 56 | "rx-frames", |
| 57 | "rx-bytes-ok", |
| 58 | "rx-bytes-all", |
| 59 | "rx-multicast-frames", |
| 60 | "rx-broadcast-frames", |
| 61 | "stats-counter-carry", |
| 62 | "stats-counter-mask", |
| 63 | "rx-dropped-frames", |
| 64 | }; |
| 65 | |
| 66 | static char tx_fw_stat_gstrings[][ETH_GSTRING_LEN] = { |
| 67 | "tx-single-collision", |
| 68 | "tx-multiple-collision", |
| 69 | "tx-late-collsion", |
| 70 | "tx-aborted-frames", |
| 71 | "tx-lost-frames", |
| 72 | "tx-carrier-sense-errors", |
| 73 | "tx-frames-ok", |
| 74 | "tx-excessive-differ-frames", |
| 75 | "tx-256-511-frames", |
Li Yang | 08722bc | 2008-05-23 18:11:27 +0800 | [diff] [blame] | 76 | "tx-512-1023-frames", |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 77 | "tx-1024-1518-frames", |
| 78 | "tx-jumbo-frames", |
| 79 | }; |
| 80 | |
| 81 | static char rx_fw_stat_gstrings[][ETH_GSTRING_LEN] = { |
| 82 | "rx-crc-errors", |
| 83 | "rx-alignment-errors", |
| 84 | "rx-in-range-length-errors", |
| 85 | "rx-out-of-range-length-errors", |
| 86 | "rx-too-long-frames", |
| 87 | "rx-runt", |
| 88 | "rx-very-long-event", |
| 89 | "rx-symbol-errors", |
| 90 | "rx-busy-drop-frames", |
| 91 | "reserved", |
| 92 | "reserved", |
| 93 | "rx-mismatch-drop-frames", |
| 94 | "rx-small-than-64", |
| 95 | "rx-256-511-frames", |
| 96 | "rx-512-1023-frames", |
| 97 | "rx-1024-1518-frames", |
| 98 | "rx-jumbo-frames", |
| 99 | "rx-mac-error-loss", |
| 100 | "rx-pause-frames", |
| 101 | "reserved", |
| 102 | "rx-vlan-removed", |
| 103 | "rx-vlan-replaced", |
| 104 | "rx-vlan-inserted", |
| 105 | "rx-ip-checksum-errors", |
| 106 | }; |
| 107 | |
| 108 | #define UEC_HW_STATS_LEN ARRAY_SIZE(hw_stat_gstrings) |
| 109 | #define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings) |
| 110 | #define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings) |
| 111 | |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 112 | static int |
| 113 | uec_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 114 | { |
| 115 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 116 | struct phy_device *phydev = ugeth->phydev; |
| 117 | struct ucc_geth_info *ug_info = ugeth->ug_info; |
| 118 | |
| 119 | if (!phydev) |
| 120 | return -ENODEV; |
| 121 | |
| 122 | ecmd->maxtxpkt = 1; |
| 123 | ecmd->maxrxpkt = ug_info->interruptcoalescingmaxvalue[0]; |
| 124 | |
| 125 | return phy_ethtool_gset(phydev, ecmd); |
| 126 | } |
| 127 | |
| 128 | static int |
| 129 | uec_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 130 | { |
| 131 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 132 | struct phy_device *phydev = ugeth->phydev; |
| 133 | |
| 134 | if (!phydev) |
| 135 | return -ENODEV; |
| 136 | |
| 137 | return phy_ethtool_sset(phydev, ecmd); |
| 138 | } |
| 139 | |
| 140 | static void |
| 141 | uec_get_pauseparam(struct net_device *netdev, |
| 142 | struct ethtool_pauseparam *pause) |
| 143 | { |
| 144 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 145 | |
| 146 | pause->autoneg = ugeth->phydev->autoneg; |
| 147 | |
| 148 | if (ugeth->ug_info->receiveFlowControl) |
| 149 | pause->rx_pause = 1; |
| 150 | if (ugeth->ug_info->transmitFlowControl) |
| 151 | pause->tx_pause = 1; |
| 152 | } |
| 153 | |
| 154 | static int |
| 155 | uec_set_pauseparam(struct net_device *netdev, |
| 156 | struct ethtool_pauseparam *pause) |
| 157 | { |
| 158 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 159 | int ret = 0; |
| 160 | |
| 161 | ugeth->ug_info->receiveFlowControl = pause->rx_pause; |
| 162 | ugeth->ug_info->transmitFlowControl = pause->tx_pause; |
Jeff Garzik | 7d2e3cb | 2008-05-13 01:41:58 -0400 | [diff] [blame] | 163 | |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 164 | if (ugeth->phydev->autoneg) { |
| 165 | if (netif_running(netdev)) { |
| 166 | /* FIXME: automatically restart */ |
| 167 | printk(KERN_INFO |
| 168 | "Please re-open the interface.\n"); |
| 169 | } |
| 170 | } else { |
| 171 | struct ucc_geth_info *ug_info = ugeth->ug_info; |
| 172 | |
| 173 | ret = init_flow_control_params(ug_info->aufc, |
| 174 | ug_info->receiveFlowControl, |
| 175 | ug_info->transmitFlowControl, |
| 176 | ug_info->pausePeriod, |
| 177 | ug_info->extensionField, |
| 178 | &ugeth->uccf->uf_regs->upsmr, |
| 179 | &ugeth->ug_regs->uempr, |
| 180 | &ugeth->ug_regs->maccfg1); |
| 181 | } |
| 182 | |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | static uint32_t |
| 187 | uec_get_msglevel(struct net_device *netdev) |
| 188 | { |
| 189 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 190 | return ugeth->msg_enable; |
| 191 | } |
| 192 | |
| 193 | static void |
| 194 | uec_set_msglevel(struct net_device *netdev, uint32_t data) |
| 195 | { |
| 196 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 197 | ugeth->msg_enable = data; |
| 198 | } |
| 199 | |
| 200 | static int |
| 201 | uec_get_regs_len(struct net_device *netdev) |
| 202 | { |
| 203 | return sizeof(struct ucc_geth); |
| 204 | } |
| 205 | |
| 206 | static void |
| 207 | uec_get_regs(struct net_device *netdev, |
| 208 | struct ethtool_regs *regs, void *p) |
| 209 | { |
| 210 | int i; |
| 211 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 212 | u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs; |
| 213 | u32 *buff = p; |
| 214 | |
| 215 | for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++) |
| 216 | buff[i] = in_be32(&ug_regs[i]); |
| 217 | } |
| 218 | |
| 219 | static void |
| 220 | uec_get_ringparam(struct net_device *netdev, |
| 221 | struct ethtool_ringparam *ring) |
| 222 | { |
| 223 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 224 | struct ucc_geth_info *ug_info = ugeth->ug_info; |
| 225 | int queue = 0; |
| 226 | |
| 227 | ring->rx_max_pending = UCC_GETH_BD_RING_SIZE_MAX; |
| 228 | ring->rx_mini_max_pending = UCC_GETH_BD_RING_SIZE_MAX; |
| 229 | ring->rx_jumbo_max_pending = UCC_GETH_BD_RING_SIZE_MAX; |
| 230 | ring->tx_max_pending = UCC_GETH_BD_RING_SIZE_MAX; |
| 231 | |
| 232 | ring->rx_pending = ug_info->bdRingLenRx[queue]; |
| 233 | ring->rx_mini_pending = ug_info->bdRingLenRx[queue]; |
| 234 | ring->rx_jumbo_pending = ug_info->bdRingLenRx[queue]; |
| 235 | ring->tx_pending = ug_info->bdRingLenTx[queue]; |
| 236 | } |
| 237 | |
| 238 | static int |
| 239 | uec_set_ringparam(struct net_device *netdev, |
| 240 | struct ethtool_ringparam *ring) |
| 241 | { |
| 242 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 243 | struct ucc_geth_info *ug_info = ugeth->ug_info; |
| 244 | int queue = 0, ret = 0; |
| 245 | |
| 246 | if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) { |
| 247 | printk("%s: RxBD ring size must be no smaller than %d.\n", |
| 248 | netdev->name, UCC_GETH_RX_BD_RING_SIZE_MIN); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) { |
| 252 | printk("%s: RxBD ring size must be multiple of %d.\n", |
| 253 | netdev->name, UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT); |
| 254 | return -EINVAL; |
| 255 | } |
| 256 | if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) { |
| 257 | printk("%s: TxBD ring size must be no smaller than %d.\n", |
| 258 | netdev->name, UCC_GETH_TX_BD_RING_SIZE_MIN); |
| 259 | return -EINVAL; |
| 260 | } |
| 261 | |
| 262 | ug_info->bdRingLenRx[queue] = ring->rx_pending; |
| 263 | ug_info->bdRingLenTx[queue] = ring->tx_pending; |
| 264 | |
| 265 | if (netif_running(netdev)) { |
| 266 | /* FIXME: restart automatically */ |
| 267 | printk(KERN_INFO |
| 268 | "Please re-open the interface.\n"); |
| 269 | } |
| 270 | |
| 271 | return ret; |
| 272 | } |
| 273 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 274 | static int uec_get_sset_count(struct net_device *netdev, int sset) |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 275 | { |
| 276 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 277 | u32 stats_mode = ugeth->ug_info->statisticsMode; |
| 278 | int len = 0; |
| 279 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 280 | switch (sset) { |
| 281 | case ETH_SS_STATS: |
| 282 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) |
| 283 | len += UEC_HW_STATS_LEN; |
| 284 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) |
| 285 | len += UEC_TX_FW_STATS_LEN; |
| 286 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) |
| 287 | len += UEC_RX_FW_STATS_LEN; |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 288 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 289 | return len; |
| 290 | |
| 291 | default: |
| 292 | return -EOPNOTSUPP; |
| 293 | } |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf) |
| 297 | { |
| 298 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 299 | u32 stats_mode = ugeth->ug_info->statisticsMode; |
| 300 | |
| 301 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) { |
| 302 | memcpy(buf, hw_stat_gstrings, UEC_HW_STATS_LEN * |
| 303 | ETH_GSTRING_LEN); |
| 304 | buf += UEC_HW_STATS_LEN * ETH_GSTRING_LEN; |
| 305 | } |
| 306 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) { |
| 307 | memcpy(buf, tx_fw_stat_gstrings, UEC_TX_FW_STATS_LEN * |
| 308 | ETH_GSTRING_LEN); |
| 309 | buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN; |
| 310 | } |
| 311 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) |
Joakim Tjernlund | 25f03dc | 2008-05-23 18:11:26 +0800 | [diff] [blame] | 312 | memcpy(buf, rx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN * |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 313 | ETH_GSTRING_LEN); |
| 314 | } |
| 315 | |
| 316 | static void uec_get_ethtool_stats(struct net_device *netdev, |
| 317 | struct ethtool_stats *stats, uint64_t *data) |
| 318 | { |
| 319 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 320 | u32 stats_mode = ugeth->ug_info->statisticsMode; |
| 321 | u32 __iomem *base; |
| 322 | int i, j = 0; |
| 323 | |
| 324 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) { |
| 325 | base = (u32 __iomem *)&ugeth->ug_regs->tx64; |
| 326 | for (i = 0; i < UEC_HW_STATS_LEN; i++) |
| 327 | data[j++] = (u64)in_be32(&base[i]); |
| 328 | } |
| 329 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) { |
| 330 | base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram; |
| 331 | for (i = 0; i < UEC_TX_FW_STATS_LEN; i++) |
| 332 | data[j++] = (u64)in_be32(&base[i]); |
| 333 | } |
| 334 | if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) { |
| 335 | base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram; |
| 336 | for (i = 0; i < UEC_RX_FW_STATS_LEN; i++) |
| 337 | data[j++] = (u64)in_be32(&base[i]); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static int uec_nway_reset(struct net_device *netdev) |
| 342 | { |
| 343 | struct ucc_geth_private *ugeth = netdev_priv(netdev); |
| 344 | |
| 345 | return phy_start_aneg(ugeth->phydev); |
| 346 | } |
| 347 | |
| 348 | /* Report driver information */ |
| 349 | static void |
| 350 | uec_get_drvinfo(struct net_device *netdev, |
| 351 | struct ethtool_drvinfo *drvinfo) |
| 352 | { |
| 353 | strncpy(drvinfo->driver, DRV_NAME, 32); |
| 354 | strncpy(drvinfo->version, DRV_VERSION, 32); |
| 355 | strncpy(drvinfo->fw_version, "N/A", 32); |
| 356 | strncpy(drvinfo->bus_info, "QUICC ENGINE", 32); |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 357 | drvinfo->eedump_len = 0; |
| 358 | drvinfo->regdump_len = uec_get_regs_len(netdev); |
| 359 | } |
| 360 | |
| 361 | static const struct ethtool_ops uec_ethtool_ops = { |
| 362 | .get_settings = uec_get_settings, |
| 363 | .set_settings = uec_set_settings, |
| 364 | .get_drvinfo = uec_get_drvinfo, |
| 365 | .get_regs_len = uec_get_regs_len, |
| 366 | .get_regs = uec_get_regs, |
| 367 | .get_msglevel = uec_get_msglevel, |
| 368 | .set_msglevel = uec_set_msglevel, |
| 369 | .nway_reset = uec_nway_reset, |
| 370 | .get_link = ethtool_op_get_link, |
| 371 | .get_ringparam = uec_get_ringparam, |
| 372 | .set_ringparam = uec_set_ringparam, |
| 373 | .get_pauseparam = uec_get_pauseparam, |
| 374 | .set_pauseparam = uec_set_pauseparam, |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 375 | .set_sg = ethtool_op_set_sg, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 376 | .get_sset_count = uec_get_sset_count, |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 377 | .get_strings = uec_get_strings, |
| 378 | .get_ethtool_stats = uec_get_ethtool_stats, |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | void uec_set_ethtool_ops(struct net_device *netdev) |
| 382 | { |
| 383 | SET_ETHTOOL_OPS(netdev, &uec_ethtool_ops); |
| 384 | } |