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