Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux driver for VMware's vmxnet3 ethernet NIC. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; version 2 of the License and no later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 13 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 14 | * details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | * The full GNU General Public License is included in this distribution in |
| 21 | * the file called "COPYING". |
| 22 | * |
| 23 | * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com> |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | #include "vmxnet3_int.h" |
| 29 | |
| 30 | struct vmxnet3_stat_desc { |
| 31 | char desc[ETH_GSTRING_LEN]; |
| 32 | int offset; |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | static u32 |
| 37 | vmxnet3_get_rx_csum(struct net_device *netdev) |
| 38 | { |
| 39 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 40 | return adapter->rxcsum; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | static int |
| 45 | vmxnet3_set_rx_csum(struct net_device *netdev, u32 val) |
| 46 | { |
| 47 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 48 | |
| 49 | if (adapter->rxcsum != val) { |
| 50 | adapter->rxcsum = val; |
| 51 | if (netif_running(netdev)) { |
| 52 | if (val) |
Harvey Harrison | 3843e51 | 2010-10-21 18:05:32 +0000 | [diff] [blame] | 53 | adapter->shared->devRead.misc.uptFeatures |= |
| 54 | UPT1_F_RXCSUM; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 55 | else |
Harvey Harrison | 3843e51 | 2010-10-21 18:05:32 +0000 | [diff] [blame] | 56 | adapter->shared->devRead.misc.uptFeatures &= |
| 57 | ~UPT1_F_RXCSUM; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 58 | |
| 59 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, |
| 60 | VMXNET3_CMD_UPDATE_FEATURE); |
| 61 | } |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /* per tq stats maintained by the device */ |
| 68 | static const struct vmxnet3_stat_desc |
| 69 | vmxnet3_tq_dev_stats[] = { |
| 70 | /* description, offset */ |
| 71 | { "TSO pkts tx", offsetof(struct UPT1_TxStats, TSOPktsTxOK) }, |
| 72 | { "TSO bytes tx", offsetof(struct UPT1_TxStats, TSOBytesTxOK) }, |
| 73 | { "ucast pkts tx", offsetof(struct UPT1_TxStats, ucastPktsTxOK) }, |
| 74 | { "ucast bytes tx", offsetof(struct UPT1_TxStats, ucastBytesTxOK) }, |
| 75 | { "mcast pkts tx", offsetof(struct UPT1_TxStats, mcastPktsTxOK) }, |
| 76 | { "mcast bytes tx", offsetof(struct UPT1_TxStats, mcastBytesTxOK) }, |
| 77 | { "bcast pkts tx", offsetof(struct UPT1_TxStats, bcastPktsTxOK) }, |
| 78 | { "bcast bytes tx", offsetof(struct UPT1_TxStats, bcastBytesTxOK) }, |
| 79 | { "pkts tx err", offsetof(struct UPT1_TxStats, pktsTxError) }, |
| 80 | { "pkts tx discard", offsetof(struct UPT1_TxStats, pktsTxDiscard) }, |
| 81 | }; |
| 82 | |
| 83 | /* per tq stats maintained by the driver */ |
| 84 | static const struct vmxnet3_stat_desc |
| 85 | vmxnet3_tq_driver_stats[] = { |
| 86 | /* description, offset */ |
| 87 | {"drv dropped tx total", offsetof(struct vmxnet3_tq_driver_stats, |
| 88 | drop_total) }, |
| 89 | { " too many frags", offsetof(struct vmxnet3_tq_driver_stats, |
| 90 | drop_too_many_frags) }, |
| 91 | { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats, |
| 92 | drop_oversized_hdr) }, |
| 93 | { " hdr err", offsetof(struct vmxnet3_tq_driver_stats, |
| 94 | drop_hdr_inspect_err) }, |
| 95 | { " tso", offsetof(struct vmxnet3_tq_driver_stats, |
| 96 | drop_tso) }, |
| 97 | { "ring full", offsetof(struct vmxnet3_tq_driver_stats, |
| 98 | tx_ring_full) }, |
| 99 | { "pkts linearized", offsetof(struct vmxnet3_tq_driver_stats, |
| 100 | linearized) }, |
| 101 | { "hdr cloned", offsetof(struct vmxnet3_tq_driver_stats, |
| 102 | copy_skb_header) }, |
| 103 | { "giant hdr", offsetof(struct vmxnet3_tq_driver_stats, |
| 104 | oversized_hdr) }, |
| 105 | }; |
| 106 | |
| 107 | /* per rq stats maintained by the device */ |
| 108 | static const struct vmxnet3_stat_desc |
| 109 | vmxnet3_rq_dev_stats[] = { |
| 110 | { "LRO pkts rx", offsetof(struct UPT1_RxStats, LROPktsRxOK) }, |
| 111 | { "LRO byte rx", offsetof(struct UPT1_RxStats, LROBytesRxOK) }, |
| 112 | { "ucast pkts rx", offsetof(struct UPT1_RxStats, ucastPktsRxOK) }, |
| 113 | { "ucast bytes rx", offsetof(struct UPT1_RxStats, ucastBytesRxOK) }, |
| 114 | { "mcast pkts rx", offsetof(struct UPT1_RxStats, mcastPktsRxOK) }, |
| 115 | { "mcast bytes rx", offsetof(struct UPT1_RxStats, mcastBytesRxOK) }, |
| 116 | { "bcast pkts rx", offsetof(struct UPT1_RxStats, bcastPktsRxOK) }, |
| 117 | { "bcast bytes rx", offsetof(struct UPT1_RxStats, bcastBytesRxOK) }, |
| 118 | { "pkts rx out of buf", offsetof(struct UPT1_RxStats, pktsRxOutOfBuf) }, |
| 119 | { "pkts rx err", offsetof(struct UPT1_RxStats, pktsRxError) }, |
| 120 | }; |
| 121 | |
| 122 | /* per rq stats maintained by the driver */ |
| 123 | static const struct vmxnet3_stat_desc |
| 124 | vmxnet3_rq_driver_stats[] = { |
| 125 | /* description, offset */ |
| 126 | { "drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats, |
| 127 | drop_total) }, |
| 128 | { " err", offsetof(struct vmxnet3_rq_driver_stats, |
| 129 | drop_err) }, |
| 130 | { " fcs", offsetof(struct vmxnet3_rq_driver_stats, |
| 131 | drop_fcs) }, |
| 132 | { "rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats, |
| 133 | rx_buf_alloc_failure) }, |
| 134 | }; |
| 135 | |
| 136 | /* gloabl stats maintained by the driver */ |
| 137 | static const struct vmxnet3_stat_desc |
| 138 | vmxnet3_global_stats[] = { |
| 139 | /* description, offset */ |
| 140 | { "tx timeout count", offsetof(struct vmxnet3_adapter, |
| 141 | tx_timeout_count) } |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | struct net_device_stats * |
| 146 | vmxnet3_get_stats(struct net_device *netdev) |
| 147 | { |
| 148 | struct vmxnet3_adapter *adapter; |
| 149 | struct vmxnet3_tq_driver_stats *drvTxStats; |
| 150 | struct vmxnet3_rq_driver_stats *drvRxStats; |
| 151 | struct UPT1_TxStats *devTxStats; |
| 152 | struct UPT1_RxStats *devRxStats; |
| 153 | struct net_device_stats *net_stats = &netdev->stats; |
| 154 | |
| 155 | adapter = netdev_priv(netdev); |
| 156 | |
| 157 | /* Collect the dev stats into the shared area */ |
| 158 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS); |
| 159 | |
| 160 | /* Assuming that we have a single queue device */ |
| 161 | devTxStats = &adapter->tqd_start->stats; |
| 162 | devRxStats = &adapter->rqd_start->stats; |
| 163 | |
| 164 | /* Get access to the driver stats per queue */ |
| 165 | drvTxStats = &adapter->tx_queue.stats; |
| 166 | drvRxStats = &adapter->rx_queue.stats; |
| 167 | |
| 168 | memset(net_stats, 0, sizeof(*net_stats)); |
| 169 | |
| 170 | net_stats->rx_packets = devRxStats->ucastPktsRxOK + |
| 171 | devRxStats->mcastPktsRxOK + |
| 172 | devRxStats->bcastPktsRxOK; |
| 173 | |
| 174 | net_stats->tx_packets = devTxStats->ucastPktsTxOK + |
| 175 | devTxStats->mcastPktsTxOK + |
| 176 | devTxStats->bcastPktsTxOK; |
| 177 | |
| 178 | net_stats->rx_bytes = devRxStats->ucastBytesRxOK + |
| 179 | devRxStats->mcastBytesRxOK + |
| 180 | devRxStats->bcastBytesRxOK; |
| 181 | |
| 182 | net_stats->tx_bytes = devTxStats->ucastBytesTxOK + |
| 183 | devTxStats->mcastBytesTxOK + |
| 184 | devTxStats->bcastBytesTxOK; |
| 185 | |
| 186 | net_stats->rx_errors = devRxStats->pktsRxError; |
| 187 | net_stats->tx_errors = devTxStats->pktsTxError; |
| 188 | net_stats->rx_dropped = drvRxStats->drop_total; |
| 189 | net_stats->tx_dropped = drvTxStats->drop_total; |
| 190 | net_stats->multicast = devRxStats->mcastPktsRxOK; |
| 191 | |
| 192 | return net_stats; |
| 193 | } |
| 194 | |
| 195 | static int |
| 196 | vmxnet3_get_sset_count(struct net_device *netdev, int sset) |
| 197 | { |
| 198 | switch (sset) { |
| 199 | case ETH_SS_STATS: |
| 200 | return ARRAY_SIZE(vmxnet3_tq_dev_stats) + |
| 201 | ARRAY_SIZE(vmxnet3_tq_driver_stats) + |
| 202 | ARRAY_SIZE(vmxnet3_rq_dev_stats) + |
| 203 | ARRAY_SIZE(vmxnet3_rq_driver_stats) + |
| 204 | ARRAY_SIZE(vmxnet3_global_stats); |
| 205 | default: |
| 206 | return -EOPNOTSUPP; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | |
| 211 | static int |
| 212 | vmxnet3_get_regs_len(struct net_device *netdev) |
| 213 | { |
| 214 | return 20 * sizeof(u32); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | static void |
| 219 | vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) |
| 220 | { |
| 221 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 222 | |
| 223 | strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver)); |
| 224 | drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0'; |
| 225 | |
| 226 | strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT, |
| 227 | sizeof(drvinfo->version)); |
| 228 | drvinfo->driver[sizeof(drvinfo->version) - 1] = '\0'; |
| 229 | |
| 230 | strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); |
| 231 | drvinfo->fw_version[sizeof(drvinfo->fw_version) - 1] = '\0'; |
| 232 | |
| 233 | strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), |
| 234 | ETHTOOL_BUSINFO_LEN); |
| 235 | drvinfo->n_stats = vmxnet3_get_sset_count(netdev, ETH_SS_STATS); |
| 236 | drvinfo->testinfo_len = 0; |
| 237 | drvinfo->eedump_len = 0; |
| 238 | drvinfo->regdump_len = vmxnet3_get_regs_len(netdev); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | static void |
| 243 | vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf) |
| 244 | { |
| 245 | if (stringset == ETH_SS_STATS) { |
| 246 | int i; |
| 247 | |
| 248 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) { |
| 249 | memcpy(buf, vmxnet3_tq_dev_stats[i].desc, |
| 250 | ETH_GSTRING_LEN); |
| 251 | buf += ETH_GSTRING_LEN; |
| 252 | } |
| 253 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++) { |
| 254 | memcpy(buf, vmxnet3_tq_driver_stats[i].desc, |
| 255 | ETH_GSTRING_LEN); |
| 256 | buf += ETH_GSTRING_LEN; |
| 257 | } |
| 258 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) { |
| 259 | memcpy(buf, vmxnet3_rq_dev_stats[i].desc, |
| 260 | ETH_GSTRING_LEN); |
| 261 | buf += ETH_GSTRING_LEN; |
| 262 | } |
| 263 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++) { |
| 264 | memcpy(buf, vmxnet3_rq_driver_stats[i].desc, |
| 265 | ETH_GSTRING_LEN); |
| 266 | buf += ETH_GSTRING_LEN; |
| 267 | } |
| 268 | for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) { |
| 269 | memcpy(buf, vmxnet3_global_stats[i].desc, |
| 270 | ETH_GSTRING_LEN); |
| 271 | buf += ETH_GSTRING_LEN; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 276 | static int |
Stanislaw Gruszka | d92be4b | 2010-06-27 23:29:42 +0000 | [diff] [blame] | 277 | vmxnet3_set_flags(struct net_device *netdev, u32 data) |
| 278 | { |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 279 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 280 | u8 lro_requested = (data & ETH_FLAG_LRO) == 0 ? 0 : 1; |
| 281 | u8 lro_present = (netdev->features & NETIF_F_LRO) == 0 ? 0 : 1; |
| 282 | |
Stanislaw Gruszka | d92be4b | 2010-06-27 23:29:42 +0000 | [diff] [blame] | 283 | if (data & ~ETH_FLAG_LRO) |
| 284 | return -EOPNOTSUPP; |
| 285 | |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 286 | if (lro_requested ^ lro_present) { |
| 287 | /* toggle the LRO feature*/ |
| 288 | netdev->features ^= NETIF_F_LRO; |
| 289 | |
| 290 | /* update harware LRO capability accordingly */ |
| 291 | if (lro_requested) |
Shreyas Bhatewara | ca80244 | 2010-07-15 22:17:29 -0700 | [diff] [blame] | 292 | adapter->shared->devRead.misc.uptFeatures |= |
Harvey Harrison | 3843e51 | 2010-10-21 18:05:32 +0000 | [diff] [blame] | 293 | UPT1_F_LRO; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 294 | else |
| 295 | adapter->shared->devRead.misc.uptFeatures &= |
Harvey Harrison | 3843e51 | 2010-10-21 18:05:32 +0000 | [diff] [blame] | 296 | ~UPT1_F_LRO; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 297 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, |
| 298 | VMXNET3_CMD_UPDATE_FEATURE); |
| 299 | } |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static void |
| 304 | vmxnet3_get_ethtool_stats(struct net_device *netdev, |
| 305 | struct ethtool_stats *stats, u64 *buf) |
| 306 | { |
| 307 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 308 | u8 *base; |
| 309 | int i; |
| 310 | |
| 311 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS); |
| 312 | |
| 313 | /* this does assume each counter is 64-bit wide */ |
| 314 | |
| 315 | base = (u8 *)&adapter->tqd_start->stats; |
| 316 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) |
| 317 | *buf++ = *(u64 *)(base + vmxnet3_tq_dev_stats[i].offset); |
| 318 | |
| 319 | base = (u8 *)&adapter->tx_queue.stats; |
| 320 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++) |
| 321 | *buf++ = *(u64 *)(base + vmxnet3_tq_driver_stats[i].offset); |
| 322 | |
| 323 | base = (u8 *)&adapter->rqd_start->stats; |
| 324 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) |
| 325 | *buf++ = *(u64 *)(base + vmxnet3_rq_dev_stats[i].offset); |
| 326 | |
| 327 | base = (u8 *)&adapter->rx_queue.stats; |
| 328 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++) |
| 329 | *buf++ = *(u64 *)(base + vmxnet3_rq_driver_stats[i].offset); |
| 330 | |
| 331 | base = (u8 *)adapter; |
| 332 | for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) |
| 333 | *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset); |
| 334 | } |
| 335 | |
| 336 | |
| 337 | static void |
| 338 | vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) |
| 339 | { |
| 340 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 341 | u32 *buf = p; |
| 342 | |
| 343 | memset(p, 0, vmxnet3_get_regs_len(netdev)); |
| 344 | |
| 345 | regs->version = 1; |
| 346 | |
| 347 | /* Update vmxnet3_get_regs_len if we want to dump more registers */ |
| 348 | |
| 349 | /* make each ring use multiple of 16 bytes */ |
| 350 | buf[0] = adapter->tx_queue.tx_ring.next2fill; |
| 351 | buf[1] = adapter->tx_queue.tx_ring.next2comp; |
| 352 | buf[2] = adapter->tx_queue.tx_ring.gen; |
| 353 | buf[3] = 0; |
| 354 | |
| 355 | buf[4] = adapter->tx_queue.comp_ring.next2proc; |
| 356 | buf[5] = adapter->tx_queue.comp_ring.gen; |
| 357 | buf[6] = adapter->tx_queue.stopped; |
| 358 | buf[7] = 0; |
| 359 | |
| 360 | buf[8] = adapter->rx_queue.rx_ring[0].next2fill; |
| 361 | buf[9] = adapter->rx_queue.rx_ring[0].next2comp; |
| 362 | buf[10] = adapter->rx_queue.rx_ring[0].gen; |
| 363 | buf[11] = 0; |
| 364 | |
| 365 | buf[12] = adapter->rx_queue.rx_ring[1].next2fill; |
| 366 | buf[13] = adapter->rx_queue.rx_ring[1].next2comp; |
| 367 | buf[14] = adapter->rx_queue.rx_ring[1].gen; |
| 368 | buf[15] = 0; |
| 369 | |
| 370 | buf[16] = adapter->rx_queue.comp_ring.next2proc; |
| 371 | buf[17] = adapter->rx_queue.comp_ring.gen; |
| 372 | buf[18] = 0; |
| 373 | buf[19] = 0; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | static void |
| 378 | vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 379 | { |
| 380 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 381 | |
| 382 | wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC; |
| 383 | wol->wolopts = adapter->wol; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | static int |
| 388 | vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 389 | { |
| 390 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 391 | |
| 392 | if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST | |
| 393 | WAKE_MAGICSECURE)) { |
| 394 | return -EOPNOTSUPP; |
| 395 | } |
| 396 | |
| 397 | adapter->wol = wol->wolopts; |
| 398 | |
| 399 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | static int |
| 406 | vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 407 | { |
| 408 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 409 | |
| 410 | ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full | |
| 411 | SUPPORTED_TP; |
| 412 | ecmd->advertising = ADVERTISED_TP; |
| 413 | ecmd->port = PORT_TP; |
| 414 | ecmd->transceiver = XCVR_INTERNAL; |
| 415 | |
| 416 | if (adapter->link_speed) { |
| 417 | ecmd->speed = adapter->link_speed; |
| 418 | ecmd->duplex = DUPLEX_FULL; |
| 419 | } else { |
| 420 | ecmd->speed = -1; |
| 421 | ecmd->duplex = -1; |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | static void |
| 428 | vmxnet3_get_ringparam(struct net_device *netdev, |
| 429 | struct ethtool_ringparam *param) |
| 430 | { |
| 431 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 432 | |
| 433 | param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE; |
| 434 | param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE; |
| 435 | param->rx_mini_max_pending = 0; |
| 436 | param->rx_jumbo_max_pending = 0; |
| 437 | |
| 438 | param->rx_pending = adapter->rx_queue.rx_ring[0].size; |
| 439 | param->tx_pending = adapter->tx_queue.tx_ring.size; |
| 440 | param->rx_mini_pending = 0; |
| 441 | param->rx_jumbo_pending = 0; |
| 442 | } |
| 443 | |
| 444 | |
| 445 | static int |
| 446 | vmxnet3_set_ringparam(struct net_device *netdev, |
| 447 | struct ethtool_ringparam *param) |
| 448 | { |
| 449 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 450 | u32 new_tx_ring_size, new_rx_ring_size; |
| 451 | u32 sz; |
| 452 | int err = 0; |
| 453 | |
| 454 | if (param->tx_pending == 0 || param->tx_pending > |
| 455 | VMXNET3_TX_RING_MAX_SIZE) |
| 456 | return -EINVAL; |
| 457 | |
| 458 | if (param->rx_pending == 0 || param->rx_pending > |
| 459 | VMXNET3_RX_RING_MAX_SIZE) |
| 460 | return -EINVAL; |
| 461 | |
| 462 | |
| 463 | /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */ |
| 464 | new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) & |
| 465 | ~VMXNET3_RING_SIZE_MASK; |
| 466 | new_tx_ring_size = min_t(u32, new_tx_ring_size, |
| 467 | VMXNET3_TX_RING_MAX_SIZE); |
| 468 | if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size % |
| 469 | VMXNET3_RING_SIZE_ALIGN) != 0) |
| 470 | return -EINVAL; |
| 471 | |
| 472 | /* ring0 has to be a multiple of |
| 473 | * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN |
| 474 | */ |
| 475 | sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN; |
| 476 | new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz; |
| 477 | new_rx_ring_size = min_t(u32, new_rx_ring_size, |
| 478 | VMXNET3_RX_RING_MAX_SIZE / sz * sz); |
| 479 | if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size % |
| 480 | sz) != 0) |
| 481 | return -EINVAL; |
| 482 | |
| 483 | if (new_tx_ring_size == adapter->tx_queue.tx_ring.size && |
| 484 | new_rx_ring_size == adapter->rx_queue.rx_ring[0].size) { |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | * Reset_work may be in the middle of resetting the device, wait for its |
| 490 | * completion. |
| 491 | */ |
| 492 | while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state)) |
| 493 | msleep(1); |
| 494 | |
| 495 | if (netif_running(netdev)) { |
| 496 | vmxnet3_quiesce_dev(adapter); |
| 497 | vmxnet3_reset_dev(adapter); |
| 498 | |
| 499 | /* recreate the rx queue and the tx queue based on the |
| 500 | * new sizes */ |
| 501 | vmxnet3_tq_destroy(&adapter->tx_queue, adapter); |
| 502 | vmxnet3_rq_destroy(&adapter->rx_queue, adapter); |
| 503 | |
| 504 | err = vmxnet3_create_queues(adapter, new_tx_ring_size, |
| 505 | new_rx_ring_size, VMXNET3_DEF_RX_RING_SIZE); |
| 506 | if (err) { |
| 507 | /* failed, most likely because of OOM, try default |
| 508 | * size */ |
| 509 | printk(KERN_ERR "%s: failed to apply new sizes, try the" |
| 510 | " default ones\n", netdev->name); |
| 511 | err = vmxnet3_create_queues(adapter, |
| 512 | VMXNET3_DEF_TX_RING_SIZE, |
| 513 | VMXNET3_DEF_RX_RING_SIZE, |
| 514 | VMXNET3_DEF_RX_RING_SIZE); |
| 515 | if (err) { |
| 516 | printk(KERN_ERR "%s: failed to create queues " |
| 517 | "with default sizes. Closing it\n", |
| 518 | netdev->name); |
| 519 | goto out; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | err = vmxnet3_activate_dev(adapter); |
| 524 | if (err) |
| 525 | printk(KERN_ERR "%s: failed to re-activate, error %d." |
| 526 | " Closing it\n", netdev->name, err); |
| 527 | } |
| 528 | |
| 529 | out: |
| 530 | clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state); |
| 531 | if (err) |
| 532 | vmxnet3_force_close(adapter); |
| 533 | |
| 534 | return err; |
| 535 | } |
| 536 | |
| 537 | |
| 538 | static struct ethtool_ops vmxnet3_ethtool_ops = { |
| 539 | .get_settings = vmxnet3_get_settings, |
| 540 | .get_drvinfo = vmxnet3_get_drvinfo, |
| 541 | .get_regs_len = vmxnet3_get_regs_len, |
| 542 | .get_regs = vmxnet3_get_regs, |
| 543 | .get_wol = vmxnet3_get_wol, |
| 544 | .set_wol = vmxnet3_set_wol, |
| 545 | .get_link = ethtool_op_get_link, |
| 546 | .get_rx_csum = vmxnet3_get_rx_csum, |
| 547 | .set_rx_csum = vmxnet3_set_rx_csum, |
| 548 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 549 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
| 550 | .get_sg = ethtool_op_get_sg, |
| 551 | .set_sg = ethtool_op_set_sg, |
| 552 | .get_tso = ethtool_op_get_tso, |
| 553 | .set_tso = ethtool_op_set_tso, |
| 554 | .get_strings = vmxnet3_get_strings, |
Ben Hutchings | cbf2d60 | 2010-06-30 02:47:40 +0000 | [diff] [blame] | 555 | .get_flags = ethtool_op_get_flags, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 556 | .set_flags = vmxnet3_set_flags, |
| 557 | .get_sset_count = vmxnet3_get_sset_count, |
| 558 | .get_ethtool_stats = vmxnet3_get_ethtool_stats, |
| 559 | .get_ringparam = vmxnet3_get_ringparam, |
| 560 | .set_ringparam = vmxnet3_set_ringparam, |
| 561 | }; |
| 562 | |
| 563 | void vmxnet3_set_ethtool_ops(struct net_device *netdev) |
| 564 | { |
| 565 | SET_ETHTOOL_OPS(netdev, &vmxnet3_ethtool_ops); |
| 566 | } |