Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux driver for VMware's vmxnet3 ethernet NIC. |
| 3 | * |
Shrikrishna Khare | 190af10 | 2016-06-16 10:51:53 -0700 | [diff] [blame] | 4 | * Copyright (C) 2008-2016, VMware, Inc. All Rights Reserved. |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 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 | * |
Shrikrishna Khare | 190af10 | 2016-06-16 10:51:53 -0700 | [diff] [blame] | 23 | * Maintained by: pv-drivers@vmware.com |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 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 | |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 36 | /* per tq stats maintained by the device */ |
| 37 | static const struct vmxnet3_stat_desc |
| 38 | vmxnet3_tq_dev_stats[] = { |
| 39 | /* description, offset */ |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 40 | { "Tx Queue#", 0 }, |
| 41 | { " TSO pkts tx", offsetof(struct UPT1_TxStats, TSOPktsTxOK) }, |
| 42 | { " TSO bytes tx", offsetof(struct UPT1_TxStats, TSOBytesTxOK) }, |
| 43 | { " ucast pkts tx", offsetof(struct UPT1_TxStats, ucastPktsTxOK) }, |
| 44 | { " ucast bytes tx", offsetof(struct UPT1_TxStats, ucastBytesTxOK) }, |
| 45 | { " mcast pkts tx", offsetof(struct UPT1_TxStats, mcastPktsTxOK) }, |
| 46 | { " mcast bytes tx", offsetof(struct UPT1_TxStats, mcastBytesTxOK) }, |
| 47 | { " bcast pkts tx", offsetof(struct UPT1_TxStats, bcastPktsTxOK) }, |
| 48 | { " bcast bytes tx", offsetof(struct UPT1_TxStats, bcastBytesTxOK) }, |
| 49 | { " pkts tx err", offsetof(struct UPT1_TxStats, pktsTxError) }, |
| 50 | { " pkts tx discard", offsetof(struct UPT1_TxStats, pktsTxDiscard) }, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /* per tq stats maintained by the driver */ |
| 54 | static const struct vmxnet3_stat_desc |
| 55 | vmxnet3_tq_driver_stats[] = { |
| 56 | /* description, offset */ |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 57 | {" drv dropped tx total", offsetof(struct vmxnet3_tq_driver_stats, |
| 58 | drop_total) }, |
| 59 | { " too many frags", offsetof(struct vmxnet3_tq_driver_stats, |
| 60 | drop_too_many_frags) }, |
| 61 | { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats, |
| 62 | drop_oversized_hdr) }, |
| 63 | { " hdr err", offsetof(struct vmxnet3_tq_driver_stats, |
| 64 | drop_hdr_inspect_err) }, |
| 65 | { " tso", offsetof(struct vmxnet3_tq_driver_stats, |
| 66 | drop_tso) }, |
| 67 | { " ring full", offsetof(struct vmxnet3_tq_driver_stats, |
| 68 | tx_ring_full) }, |
| 69 | { " pkts linearized", offsetof(struct vmxnet3_tq_driver_stats, |
| 70 | linearized) }, |
| 71 | { " hdr cloned", offsetof(struct vmxnet3_tq_driver_stats, |
| 72 | copy_skb_header) }, |
| 73 | { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats, |
| 74 | oversized_hdr) }, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* per rq stats maintained by the device */ |
| 78 | static const struct vmxnet3_stat_desc |
| 79 | vmxnet3_rq_dev_stats[] = { |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 80 | { "Rx Queue#", 0 }, |
| 81 | { " LRO pkts rx", offsetof(struct UPT1_RxStats, LROPktsRxOK) }, |
| 82 | { " LRO byte rx", offsetof(struct UPT1_RxStats, LROBytesRxOK) }, |
| 83 | { " ucast pkts rx", offsetof(struct UPT1_RxStats, ucastPktsRxOK) }, |
| 84 | { " ucast bytes rx", offsetof(struct UPT1_RxStats, ucastBytesRxOK) }, |
| 85 | { " mcast pkts rx", offsetof(struct UPT1_RxStats, mcastPktsRxOK) }, |
| 86 | { " mcast bytes rx", offsetof(struct UPT1_RxStats, mcastBytesRxOK) }, |
| 87 | { " bcast pkts rx", offsetof(struct UPT1_RxStats, bcastPktsRxOK) }, |
| 88 | { " bcast bytes rx", offsetof(struct UPT1_RxStats, bcastBytesRxOK) }, |
| 89 | { " pkts rx OOB", offsetof(struct UPT1_RxStats, pktsRxOutOfBuf) }, |
| 90 | { " pkts rx err", offsetof(struct UPT1_RxStats, pktsRxError) }, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /* per rq stats maintained by the driver */ |
| 94 | static const struct vmxnet3_stat_desc |
| 95 | vmxnet3_rq_driver_stats[] = { |
| 96 | /* description, offset */ |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 97 | { " drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats, |
| 98 | drop_total) }, |
| 99 | { " err", offsetof(struct vmxnet3_rq_driver_stats, |
| 100 | drop_err) }, |
| 101 | { " fcs", offsetof(struct vmxnet3_rq_driver_stats, |
| 102 | drop_fcs) }, |
| 103 | { " rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats, |
| 104 | rx_buf_alloc_failure) }, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
stephen hemminger | 7887456 | 2015-04-01 15:33:08 -0700 | [diff] [blame] | 107 | /* global stats maintained by the driver */ |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 108 | static const struct vmxnet3_stat_desc |
| 109 | vmxnet3_global_stats[] = { |
| 110 | /* description, offset */ |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 111 | { "tx timeout count", offsetof(struct vmxnet3_adapter, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 112 | tx_timeout_count) } |
| 113 | }; |
| 114 | |
| 115 | |
stephen hemminger | 95305f6 | 2011-06-08 14:53:57 +0000 | [diff] [blame] | 116 | struct rtnl_link_stats64 * |
| 117 | vmxnet3_get_stats64(struct net_device *netdev, |
| 118 | struct rtnl_link_stats64 *stats) |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 119 | { |
| 120 | struct vmxnet3_adapter *adapter; |
| 121 | struct vmxnet3_tq_driver_stats *drvTxStats; |
| 122 | struct vmxnet3_rq_driver_stats *drvRxStats; |
| 123 | struct UPT1_TxStats *devTxStats; |
| 124 | struct UPT1_RxStats *devRxStats; |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 125 | unsigned long flags; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 126 | int i; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 127 | |
| 128 | adapter = netdev_priv(netdev); |
| 129 | |
| 130 | /* Collect the dev stats into the shared area */ |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 131 | spin_lock_irqsave(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 132 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS); |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 133 | spin_unlock_irqrestore(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 134 | |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 135 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 136 | devTxStats = &adapter->tqd_start[i].stats; |
| 137 | drvTxStats = &adapter->tx_queue[i].stats; |
stephen hemminger | 95305f6 | 2011-06-08 14:53:57 +0000 | [diff] [blame] | 138 | stats->tx_packets += devTxStats->ucastPktsTxOK + |
| 139 | devTxStats->mcastPktsTxOK + |
| 140 | devTxStats->bcastPktsTxOK; |
| 141 | stats->tx_bytes += devTxStats->ucastBytesTxOK + |
| 142 | devTxStats->mcastBytesTxOK + |
| 143 | devTxStats->bcastBytesTxOK; |
| 144 | stats->tx_errors += devTxStats->pktsTxError; |
| 145 | stats->tx_dropped += drvTxStats->drop_total; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 146 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 147 | |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 148 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 149 | devRxStats = &adapter->rqd_start[i].stats; |
| 150 | drvRxStats = &adapter->rx_queue[i].stats; |
stephen hemminger | 95305f6 | 2011-06-08 14:53:57 +0000 | [diff] [blame] | 151 | stats->rx_packets += devRxStats->ucastPktsRxOK + |
| 152 | devRxStats->mcastPktsRxOK + |
| 153 | devRxStats->bcastPktsRxOK; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 154 | |
stephen hemminger | 95305f6 | 2011-06-08 14:53:57 +0000 | [diff] [blame] | 155 | stats->rx_bytes += devRxStats->ucastBytesRxOK + |
| 156 | devRxStats->mcastBytesRxOK + |
| 157 | devRxStats->bcastBytesRxOK; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 158 | |
stephen hemminger | 95305f6 | 2011-06-08 14:53:57 +0000 | [diff] [blame] | 159 | stats->rx_errors += devRxStats->pktsRxError; |
| 160 | stats->rx_dropped += drvRxStats->drop_total; |
| 161 | stats->multicast += devRxStats->mcastPktsRxOK; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 162 | } |
stephen hemminger | 95305f6 | 2011-06-08 14:53:57 +0000 | [diff] [blame] | 163 | |
| 164 | return stats; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static int |
| 168 | vmxnet3_get_sset_count(struct net_device *netdev, int sset) |
| 169 | { |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 170 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 171 | switch (sset) { |
| 172 | case ETH_SS_STATS: |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 173 | return (ARRAY_SIZE(vmxnet3_tq_dev_stats) + |
| 174 | ARRAY_SIZE(vmxnet3_tq_driver_stats)) * |
| 175 | adapter->num_tx_queues + |
| 176 | (ARRAY_SIZE(vmxnet3_rq_dev_stats) + |
| 177 | ARRAY_SIZE(vmxnet3_rq_driver_stats)) * |
| 178 | adapter->num_rx_queues + |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 179 | ARRAY_SIZE(vmxnet3_global_stats); |
| 180 | default: |
| 181 | return -EOPNOTSUPP; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 186 | /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with |
| 187 | * the version 2 of the vmxnet3 support for ethtool(8) --register-dump. |
| 188 | * Therefore, if any registers are added, removed or modified, then a version |
| 189 | * bump and a corresponding change in the vmxnet3 support for ethtool(8) |
| 190 | * --register-dump would be required. |
| 191 | */ |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 192 | static int |
| 193 | vmxnet3_get_regs_len(struct net_device *netdev) |
| 194 | { |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 195 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 196 | |
| 197 | return ((9 /* BAR1 registers */ + |
| 198 | (1 + adapter->intr.num_intrs) + |
| 199 | (1 + adapter->num_tx_queues * 17 /* Tx queue registers */) + |
| 200 | (1 + adapter->num_rx_queues * 23 /* Rx queue registers */)) * |
| 201 | sizeof(u32)); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | static void |
| 206 | vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) |
| 207 | { |
| 208 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 209 | |
| 210 | strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver)); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 211 | |
| 212 | strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT, |
| 213 | sizeof(drvinfo->version)); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 214 | |
| 215 | strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 216 | sizeof(drvinfo->bus_info)); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | static void |
| 221 | vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf) |
| 222 | { |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 223 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 224 | if (stringset == ETH_SS_STATS) { |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 225 | int i, j; |
| 226 | for (j = 0; j < adapter->num_tx_queues; j++) { |
| 227 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) { |
| 228 | memcpy(buf, vmxnet3_tq_dev_stats[i].desc, |
| 229 | ETH_GSTRING_LEN); |
| 230 | buf += ETH_GSTRING_LEN; |
| 231 | } |
| 232 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); |
| 233 | i++) { |
| 234 | memcpy(buf, vmxnet3_tq_driver_stats[i].desc, |
| 235 | ETH_GSTRING_LEN); |
| 236 | buf += ETH_GSTRING_LEN; |
| 237 | } |
| 238 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 239 | |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 240 | for (j = 0; j < adapter->num_rx_queues; j++) { |
| 241 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) { |
| 242 | memcpy(buf, vmxnet3_rq_dev_stats[i].desc, |
| 243 | ETH_GSTRING_LEN); |
| 244 | buf += ETH_GSTRING_LEN; |
| 245 | } |
| 246 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); |
| 247 | i++) { |
| 248 | memcpy(buf, vmxnet3_rq_driver_stats[i].desc, |
| 249 | ETH_GSTRING_LEN); |
| 250 | buf += ETH_GSTRING_LEN; |
| 251 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 252 | } |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 253 | |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 254 | for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) { |
| 255 | memcpy(buf, vmxnet3_global_stats[i].desc, |
| 256 | ETH_GSTRING_LEN); |
| 257 | buf += ETH_GSTRING_LEN; |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 262 | int vmxnet3_set_features(struct net_device *netdev, netdev_features_t features) |
Stanislaw Gruszka | d92be4b | 2010-06-27 23:29:42 +0000 | [diff] [blame] | 263 | { |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 264 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 265 | unsigned long flags; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 266 | netdev_features_t changed = features ^ netdev->features; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 267 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 268 | if (changed & (NETIF_F_RXCSUM | NETIF_F_LRO | |
| 269 | NETIF_F_HW_VLAN_CTAG_RX)) { |
Michał Mirosław | a0d2730 | 2011-04-18 13:31:21 +0000 | [diff] [blame] | 270 | if (features & NETIF_F_RXCSUM) |
| 271 | adapter->shared->devRead.misc.uptFeatures |= |
| 272 | UPT1_F_RXCSUM; |
| 273 | else |
| 274 | adapter->shared->devRead.misc.uptFeatures &= |
| 275 | ~UPT1_F_RXCSUM; |
Stanislaw Gruszka | d92be4b | 2010-06-27 23:29:42 +0000 | [diff] [blame] | 276 | |
stephen hemminger | 7887456 | 2015-04-01 15:33:08 -0700 | [diff] [blame] | 277 | /* update hardware LRO capability accordingly */ |
Michał Mirosław | a0d2730 | 2011-04-18 13:31:21 +0000 | [diff] [blame] | 278 | if (features & NETIF_F_LRO) |
Shreyas Bhatewara | ca80244 | 2010-07-15 22:17:29 -0700 | [diff] [blame] | 279 | adapter->shared->devRead.misc.uptFeatures |= |
Harvey Harrison | 3843e51 | 2010-10-21 18:05:32 +0000 | [diff] [blame] | 280 | UPT1_F_LRO; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 281 | else |
| 282 | adapter->shared->devRead.misc.uptFeatures &= |
Harvey Harrison | 3843e51 | 2010-10-21 18:05:32 +0000 | [diff] [blame] | 283 | ~UPT1_F_LRO; |
Michał Mirosław | a0d2730 | 2011-04-18 13:31:21 +0000 | [diff] [blame] | 284 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 285 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | 72e85c4 | 2011-06-23 13:04:39 +0000 | [diff] [blame] | 286 | adapter->shared->devRead.misc.uptFeatures |= |
| 287 | UPT1_F_RXVLAN; |
| 288 | else |
| 289 | adapter->shared->devRead.misc.uptFeatures &= |
| 290 | ~UPT1_F_RXVLAN; |
| 291 | |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 292 | spin_lock_irqsave(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 293 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, |
| 294 | VMXNET3_CMD_UPDATE_FEATURE); |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 295 | spin_unlock_irqrestore(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 296 | } |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static void |
| 301 | vmxnet3_get_ethtool_stats(struct net_device *netdev, |
| 302 | struct ethtool_stats *stats, u64 *buf) |
| 303 | { |
| 304 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 305 | unsigned long flags; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 306 | u8 *base; |
| 307 | int i; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 308 | int j = 0; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 309 | |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 310 | spin_lock_irqsave(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 311 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS); |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 312 | spin_unlock_irqrestore(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 313 | |
| 314 | /* this does assume each counter is 64-bit wide */ |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 315 | for (j = 0; j < adapter->num_tx_queues; j++) { |
| 316 | base = (u8 *)&adapter->tqd_start[j].stats; |
| 317 | *buf++ = (u64)j; |
| 318 | for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) |
| 319 | *buf++ = *(u64 *)(base + |
| 320 | vmxnet3_tq_dev_stats[i].offset); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 321 | |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 322 | base = (u8 *)&adapter->tx_queue[j].stats; |
| 323 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++) |
| 324 | *buf++ = *(u64 *)(base + |
| 325 | vmxnet3_tq_driver_stats[i].offset); |
| 326 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 327 | |
Shrikrishna Khare | 331b9ab | 2015-01-15 11:54:30 -0800 | [diff] [blame] | 328 | for (j = 0; j < adapter->num_rx_queues; j++) { |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 329 | base = (u8 *)&adapter->rqd_start[j].stats; |
| 330 | *buf++ = (u64) j; |
| 331 | for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) |
| 332 | *buf++ = *(u64 *)(base + |
| 333 | vmxnet3_rq_dev_stats[i].offset); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 334 | |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 335 | base = (u8 *)&adapter->rx_queue[j].stats; |
| 336 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++) |
| 337 | *buf++ = *(u64 *)(base + |
| 338 | vmxnet3_rq_driver_stats[i].offset); |
| 339 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 340 | |
| 341 | base = (u8 *)adapter; |
| 342 | for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) |
| 343 | *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset); |
| 344 | } |
| 345 | |
| 346 | |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 347 | /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with |
| 348 | * the version 2 of the vmxnet3 support for ethtool(8) --register-dump. |
| 349 | * Therefore, if any registers are added, removed or modified, then a version |
| 350 | * bump and a corresponding change in the vmxnet3 support for ethtool(8) |
| 351 | * --register-dump would be required. |
| 352 | */ |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 353 | static void |
| 354 | vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) |
| 355 | { |
| 356 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 357 | u32 *buf = p; |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 358 | int i = 0, j = 0; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 359 | |
| 360 | memset(p, 0, vmxnet3_get_regs_len(netdev)); |
| 361 | |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 362 | regs->version = 2; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 363 | |
| 364 | /* Update vmxnet3_get_regs_len if we want to dump more registers */ |
| 365 | |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 366 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_VRRS); |
| 367 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_UVRS); |
| 368 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAL); |
| 369 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAH); |
| 370 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD); |
| 371 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACL); |
| 372 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACH); |
| 373 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ICR); |
| 374 | buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ECR); |
| 375 | |
| 376 | buf[j++] = adapter->intr.num_intrs; |
| 377 | for (i = 0; i < adapter->intr.num_intrs; i++) { |
| 378 | buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_IMR |
| 379 | + i * VMXNET3_REG_ALIGN); |
| 380 | } |
| 381 | |
| 382 | buf[j++] = adapter->num_tx_queues; |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 383 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 384 | struct vmxnet3_tx_queue *tq = &adapter->tx_queue[i]; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 385 | |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 386 | buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_TXPROD + |
| 387 | i * VMXNET3_REG_ALIGN); |
| 388 | |
| 389 | buf[j++] = VMXNET3_GET_ADDR_LO(tq->tx_ring.basePA); |
| 390 | buf[j++] = VMXNET3_GET_ADDR_HI(tq->tx_ring.basePA); |
| 391 | buf[j++] = tq->tx_ring.size; |
| 392 | buf[j++] = tq->tx_ring.next2fill; |
| 393 | buf[j++] = tq->tx_ring.next2comp; |
| 394 | buf[j++] = tq->tx_ring.gen; |
| 395 | |
| 396 | buf[j++] = VMXNET3_GET_ADDR_LO(tq->data_ring.basePA); |
| 397 | buf[j++] = VMXNET3_GET_ADDR_HI(tq->data_ring.basePA); |
| 398 | buf[j++] = tq->data_ring.size; |
Shrikrishna Khare | 3c8b3ef | 2016-06-16 10:51:55 -0700 | [diff] [blame] | 399 | buf[j++] = tq->txdata_desc_size; |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 400 | |
| 401 | buf[j++] = VMXNET3_GET_ADDR_LO(tq->comp_ring.basePA); |
| 402 | buf[j++] = VMXNET3_GET_ADDR_HI(tq->comp_ring.basePA); |
| 403 | buf[j++] = tq->comp_ring.size; |
| 404 | buf[j++] = tq->comp_ring.next2proc; |
| 405 | buf[j++] = tq->comp_ring.gen; |
| 406 | |
| 407 | buf[j++] = tq->stopped; |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 408 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 409 | |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 410 | buf[j++] = adapter->num_rx_queues; |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 411 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 412 | struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i]; |
| 413 | |
| 414 | buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD + |
| 415 | i * VMXNET3_REG_ALIGN); |
| 416 | buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD2 + |
| 417 | i * VMXNET3_REG_ALIGN); |
| 418 | |
| 419 | buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[0].basePA); |
| 420 | buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[0].basePA); |
| 421 | buf[j++] = rq->rx_ring[0].size; |
| 422 | buf[j++] = rq->rx_ring[0].next2fill; |
| 423 | buf[j++] = rq->rx_ring[0].next2comp; |
| 424 | buf[j++] = rq->rx_ring[0].gen; |
| 425 | |
| 426 | buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[1].basePA); |
| 427 | buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[1].basePA); |
| 428 | buf[j++] = rq->rx_ring[1].size; |
| 429 | buf[j++] = rq->rx_ring[1].next2fill; |
| 430 | buf[j++] = rq->rx_ring[1].next2comp; |
| 431 | buf[j++] = rq->rx_ring[1].gen; |
| 432 | |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 433 | buf[j++] = VMXNET3_GET_ADDR_LO(rq->data_ring.basePA); |
| 434 | buf[j++] = VMXNET3_GET_ADDR_HI(rq->data_ring.basePA); |
| 435 | buf[j++] = rq->rx_ring[0].size; |
| 436 | buf[j++] = rq->data_ring.desc_size; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 437 | |
Shrikrishna Khare | b6bd9b5 | 2015-09-21 20:01:29 -0700 | [diff] [blame] | 438 | buf[j++] = VMXNET3_GET_ADDR_LO(rq->comp_ring.basePA); |
| 439 | buf[j++] = VMXNET3_GET_ADDR_HI(rq->comp_ring.basePA); |
| 440 | buf[j++] = rq->comp_ring.size; |
| 441 | buf[j++] = rq->comp_ring.next2proc; |
| 442 | buf[j++] = rq->comp_ring.gen; |
Shreyas Bhatewara | 76d39da | 2011-01-14 14:59:47 +0000 | [diff] [blame] | 443 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | |
| 447 | static void |
| 448 | vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 449 | { |
| 450 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 451 | |
| 452 | wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC; |
| 453 | wol->wolopts = adapter->wol; |
| 454 | } |
| 455 | |
| 456 | |
| 457 | static int |
| 458 | vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 459 | { |
| 460 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 461 | |
| 462 | if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST | |
| 463 | WAKE_MAGICSECURE)) { |
| 464 | return -EOPNOTSUPP; |
| 465 | } |
| 466 | |
| 467 | adapter->wol = wol->wolopts; |
| 468 | |
| 469 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | |
| 475 | static int |
| 476 | vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 477 | { |
| 478 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 479 | |
| 480 | ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full | |
| 481 | SUPPORTED_TP; |
| 482 | ecmd->advertising = ADVERTISED_TP; |
| 483 | ecmd->port = PORT_TP; |
| 484 | ecmd->transceiver = XCVR_INTERNAL; |
| 485 | |
| 486 | if (adapter->link_speed) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 487 | ethtool_cmd_speed_set(ecmd, adapter->link_speed); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 488 | ecmd->duplex = DUPLEX_FULL; |
| 489 | } else { |
Jiri Pirko | 537fae0 | 2014-06-06 14:17:00 +0200 | [diff] [blame] | 490 | ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); |
| 491 | ecmd->duplex = DUPLEX_UNKNOWN; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 492 | } |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | |
| 497 | static void |
| 498 | vmxnet3_get_ringparam(struct net_device *netdev, |
| 499 | struct ethtool_ringparam *param) |
| 500 | { |
| 501 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 502 | |
| 503 | param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE; |
| 504 | param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE; |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 505 | param->rx_mini_max_pending = VMXNET3_VERSION_GE_3(adapter) ? |
| 506 | VMXNET3_RXDATA_DESC_MAX_SIZE : 0; |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 507 | param->rx_jumbo_max_pending = VMXNET3_RX_RING2_MAX_SIZE; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 508 | |
Neil Horman | f00e2b0 | 2014-06-13 10:03:21 -0400 | [diff] [blame] | 509 | param->rx_pending = adapter->rx_ring_size; |
| 510 | param->tx_pending = adapter->tx_ring_size; |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 511 | param->rx_mini_pending = VMXNET3_VERSION_GE_3(adapter) ? |
| 512 | adapter->rxdata_desc_size : 0; |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 513 | param->rx_jumbo_pending = adapter->rx_ring2_size; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | |
| 517 | static int |
| 518 | vmxnet3_set_ringparam(struct net_device *netdev, |
| 519 | struct ethtool_ringparam *param) |
| 520 | { |
| 521 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 522 | u32 new_tx_ring_size, new_rx_ring_size, new_rx_ring2_size; |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 523 | u16 new_rxdata_desc_size; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 524 | u32 sz; |
| 525 | int err = 0; |
| 526 | |
| 527 | if (param->tx_pending == 0 || param->tx_pending > |
| 528 | VMXNET3_TX_RING_MAX_SIZE) |
| 529 | return -EINVAL; |
| 530 | |
| 531 | if (param->rx_pending == 0 || param->rx_pending > |
| 532 | VMXNET3_RX_RING_MAX_SIZE) |
| 533 | return -EINVAL; |
| 534 | |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 535 | if (param->rx_jumbo_pending == 0 || |
| 536 | param->rx_jumbo_pending > VMXNET3_RX_RING2_MAX_SIZE) |
| 537 | return -EINVAL; |
| 538 | |
Bhavesh Davda | e4fabf2 | 2013-03-06 12:04:53 +0000 | [diff] [blame] | 539 | /* if adapter not yet initialized, do nothing */ |
| 540 | if (adapter->rx_buf_per_pkt == 0) { |
| 541 | netdev_err(netdev, "adapter not completely initialized, " |
| 542 | "ring size cannot be changed yet\n"); |
| 543 | return -EOPNOTSUPP; |
| 544 | } |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 545 | |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 546 | if (VMXNET3_VERSION_GE_3(adapter)) { |
| 547 | if (param->rx_mini_pending < 0 || |
| 548 | param->rx_mini_pending > VMXNET3_RXDATA_DESC_MAX_SIZE) { |
| 549 | return -EINVAL; |
| 550 | } |
| 551 | } else if (param->rx_mini_pending != 0) { |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 555 | /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */ |
| 556 | new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) & |
| 557 | ~VMXNET3_RING_SIZE_MASK; |
| 558 | new_tx_ring_size = min_t(u32, new_tx_ring_size, |
| 559 | VMXNET3_TX_RING_MAX_SIZE); |
| 560 | if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size % |
| 561 | VMXNET3_RING_SIZE_ALIGN) != 0) |
| 562 | return -EINVAL; |
| 563 | |
| 564 | /* ring0 has to be a multiple of |
| 565 | * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN |
| 566 | */ |
| 567 | sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN; |
| 568 | new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz; |
| 569 | new_rx_ring_size = min_t(u32, new_rx_ring_size, |
| 570 | VMXNET3_RX_RING_MAX_SIZE / sz * sz); |
| 571 | if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size % |
| 572 | sz) != 0) |
| 573 | return -EINVAL; |
| 574 | |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 575 | /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */ |
| 576 | new_rx_ring2_size = (param->rx_jumbo_pending + VMXNET3_RING_SIZE_MASK) & |
| 577 | ~VMXNET3_RING_SIZE_MASK; |
| 578 | new_rx_ring2_size = min_t(u32, new_rx_ring2_size, |
| 579 | VMXNET3_RX_RING2_MAX_SIZE); |
| 580 | |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 581 | /* rx data ring buffer size has to be a multiple of |
| 582 | * VMXNET3_RXDATA_DESC_SIZE_ALIGN |
| 583 | */ |
| 584 | new_rxdata_desc_size = |
| 585 | (param->rx_mini_pending + VMXNET3_RXDATA_DESC_SIZE_MASK) & |
| 586 | ~VMXNET3_RXDATA_DESC_SIZE_MASK; |
| 587 | new_rxdata_desc_size = min_t(u16, new_rxdata_desc_size, |
| 588 | VMXNET3_RXDATA_DESC_MAX_SIZE); |
| 589 | |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 590 | if (new_tx_ring_size == adapter->tx_ring_size && |
| 591 | new_rx_ring_size == adapter->rx_ring_size && |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 592 | new_rx_ring2_size == adapter->rx_ring2_size && |
| 593 | new_rxdata_desc_size == adapter->rxdata_desc_size) { |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * Reset_work may be in the middle of resetting the device, wait for its |
| 599 | * completion. |
| 600 | */ |
| 601 | while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state)) |
| 602 | msleep(1); |
| 603 | |
| 604 | if (netif_running(netdev)) { |
| 605 | vmxnet3_quiesce_dev(adapter); |
| 606 | vmxnet3_reset_dev(adapter); |
| 607 | |
| 608 | /* recreate the rx queue and the tx queue based on the |
| 609 | * new sizes */ |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 610 | vmxnet3_tq_destroy_all(adapter); |
| 611 | vmxnet3_rq_destroy_all(adapter); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 612 | |
| 613 | err = vmxnet3_create_queues(adapter, new_tx_ring_size, |
Shrikrishna Khare | 3c8b3ef | 2016-06-16 10:51:55 -0700 | [diff] [blame] | 614 | new_rx_ring_size, new_rx_ring2_size, |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 615 | adapter->txdata_desc_size, |
| 616 | new_rxdata_desc_size); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 617 | if (err) { |
| 618 | /* failed, most likely because of OOM, try default |
| 619 | * size */ |
Stephen Hemminger | 204a6e6 | 2013-01-15 07:28:30 +0000 | [diff] [blame] | 620 | netdev_err(netdev, "failed to apply new sizes, " |
| 621 | "try the default ones\n"); |
Neil Horman | f00e2b0 | 2014-06-13 10:03:21 -0400 | [diff] [blame] | 622 | new_rx_ring_size = VMXNET3_DEF_RX_RING_SIZE; |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 623 | new_rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE; |
Neil Horman | f00e2b0 | 2014-06-13 10:03:21 -0400 | [diff] [blame] | 624 | new_tx_ring_size = VMXNET3_DEF_TX_RING_SIZE; |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 625 | new_rxdata_desc_size = VMXNET3_VERSION_GE_3(adapter) ? |
| 626 | VMXNET3_DEF_RXDATA_DESC_SIZE : 0; |
| 627 | |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 628 | err = vmxnet3_create_queues(adapter, |
Neil Horman | f00e2b0 | 2014-06-13 10:03:21 -0400 | [diff] [blame] | 629 | new_tx_ring_size, |
| 630 | new_rx_ring_size, |
Shrikrishna Khare | 3c8b3ef | 2016-06-16 10:51:55 -0700 | [diff] [blame] | 631 | new_rx_ring2_size, |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 632 | adapter->txdata_desc_size, |
| 633 | new_rxdata_desc_size); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 634 | if (err) { |
Stephen Hemminger | 204a6e6 | 2013-01-15 07:28:30 +0000 | [diff] [blame] | 635 | netdev_err(netdev, "failed to create queues " |
| 636 | "with default sizes. Closing it\n"); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 637 | goto out; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | err = vmxnet3_activate_dev(adapter); |
| 642 | if (err) |
Stephen Hemminger | 204a6e6 | 2013-01-15 07:28:30 +0000 | [diff] [blame] | 643 | netdev_err(netdev, "failed to re-activate, error %d." |
| 644 | " Closing it\n", err); |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 645 | } |
Neil Horman | f00e2b0 | 2014-06-13 10:03:21 -0400 | [diff] [blame] | 646 | adapter->tx_ring_size = new_tx_ring_size; |
| 647 | adapter->rx_ring_size = new_rx_ring_size; |
Shrikrishna Khare | 53831aa | 2015-01-06 09:20:15 -0800 | [diff] [blame] | 648 | adapter->rx_ring2_size = new_rx_ring2_size; |
Shrikrishna Khare | 50a5ce3 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 649 | adapter->rxdata_desc_size = new_rxdata_desc_size; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 650 | |
| 651 | out: |
| 652 | clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state); |
| 653 | if (err) |
| 654 | vmxnet3_force_close(adapter); |
| 655 | |
| 656 | return err; |
| 657 | } |
| 658 | |
| 659 | |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 660 | static int |
| 661 | vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info, |
Ben Hutchings | 815c7db | 2011-09-06 13:49:12 +0000 | [diff] [blame] | 662 | u32 *rules) |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 663 | { |
| 664 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 665 | switch (info->cmd) { |
| 666 | case ETHTOOL_GRXRINGS: |
| 667 | info->data = adapter->num_rx_queues; |
| 668 | return 0; |
| 669 | } |
| 670 | return -EOPNOTSUPP; |
| 671 | } |
| 672 | |
Scott J. Goldman | e9248fb | 2010-11-27 10:33:55 +0000 | [diff] [blame] | 673 | #ifdef VMXNET3_RSS |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 674 | static u32 |
| 675 | vmxnet3_get_rss_indir_size(struct net_device *netdev) |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 676 | { |
| 677 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 678 | struct UPT1_RSSConf *rssConf = adapter->rss_conf; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 679 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 680 | return rssConf->indTableSize; |
| 681 | } |
| 682 | |
| 683 | static int |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 684 | vmxnet3_get_rss(struct net_device *netdev, u32 *p, u8 *key, u8 *hfunc) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 685 | { |
| 686 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 687 | struct UPT1_RSSConf *rssConf = adapter->rss_conf; |
| 688 | unsigned int n = rssConf->indTableSize; |
| 689 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 690 | if (hfunc) |
| 691 | *hfunc = ETH_RSS_HASH_TOP; |
| 692 | if (!p) |
| 693 | return 0; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 694 | while (n--) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 695 | p[n] = rssConf->indTable[n]; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 696 | return 0; |
| 697 | |
| 698 | } |
| 699 | |
| 700 | static int |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 701 | vmxnet3_set_rss(struct net_device *netdev, const u32 *p, const u8 *key, |
| 702 | const u8 hfunc) |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 703 | { |
| 704 | unsigned int i; |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 705 | unsigned long flags; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 706 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 707 | struct UPT1_RSSConf *rssConf = adapter->rss_conf; |
| 708 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 709 | /* We do not allow change in unsupported parameters */ |
| 710 | if (key || |
| 711 | (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)) |
| 712 | return -EOPNOTSUPP; |
| 713 | if (!p) |
| 714 | return 0; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 715 | for (i = 0; i < rssConf->indTableSize; i++) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 716 | rssConf->indTable[i] = p[i]; |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 717 | |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 718 | spin_lock_irqsave(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 719 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, |
| 720 | VMXNET3_CMD_UPDATE_RSSIDT); |
Shreyas Bhatewara | 83d0fef | 2011-01-14 14:59:57 +0000 | [diff] [blame] | 721 | spin_unlock_irqrestore(&adapter->cmd_lock, flags); |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 722 | |
| 723 | return 0; |
| 724 | |
| 725 | } |
Scott J. Goldman | e9248fb | 2010-11-27 10:33:55 +0000 | [diff] [blame] | 726 | #endif |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 727 | |
Shrikrishna Khare | 4edef40e | 2016-06-16 10:51:57 -0700 | [diff] [blame^] | 728 | static int |
| 729 | vmxnet3_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec) |
| 730 | { |
| 731 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 732 | |
| 733 | if (!VMXNET3_VERSION_GE_3(adapter)) |
| 734 | return -EOPNOTSUPP; |
| 735 | |
| 736 | switch (adapter->coal_conf->coalMode) { |
| 737 | case VMXNET3_COALESCE_DISABLED: |
| 738 | /* struct ethtool_coalesce is already initialized to 0 */ |
| 739 | break; |
| 740 | case VMXNET3_COALESCE_ADAPT: |
| 741 | ec->use_adaptive_rx_coalesce = true; |
| 742 | break; |
| 743 | case VMXNET3_COALESCE_STATIC: |
| 744 | ec->tx_max_coalesced_frames = |
| 745 | adapter->coal_conf->coalPara.coalStatic.tx_comp_depth; |
| 746 | ec->rx_max_coalesced_frames = |
| 747 | adapter->coal_conf->coalPara.coalStatic.rx_depth; |
| 748 | break; |
| 749 | case VMXNET3_COALESCE_RBC: { |
| 750 | u32 rbc_rate; |
| 751 | |
| 752 | rbc_rate = adapter->coal_conf->coalPara.coalRbc.rbc_rate; |
| 753 | ec->rx_coalesce_usecs = VMXNET3_COAL_RBC_USECS(rbc_rate); |
| 754 | } |
| 755 | break; |
| 756 | default: |
| 757 | return -EOPNOTSUPP; |
| 758 | } |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | static int |
| 764 | vmxnet3_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec) |
| 765 | { |
| 766 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); |
| 767 | struct Vmxnet3_DriverShared *shared = adapter->shared; |
| 768 | union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo; |
| 769 | unsigned long flags; |
| 770 | |
| 771 | if (!VMXNET3_VERSION_GE_3(adapter)) |
| 772 | return -EOPNOTSUPP; |
| 773 | |
| 774 | if (ec->rx_coalesce_usecs_irq || |
| 775 | ec->rx_max_coalesced_frames_irq || |
| 776 | ec->tx_coalesce_usecs || |
| 777 | ec->tx_coalesce_usecs_irq || |
| 778 | ec->tx_max_coalesced_frames_irq || |
| 779 | ec->stats_block_coalesce_usecs || |
| 780 | ec->use_adaptive_tx_coalesce || |
| 781 | ec->pkt_rate_low || |
| 782 | ec->rx_coalesce_usecs_low || |
| 783 | ec->rx_max_coalesced_frames_low || |
| 784 | ec->tx_coalesce_usecs_low || |
| 785 | ec->tx_max_coalesced_frames_low || |
| 786 | ec->pkt_rate_high || |
| 787 | ec->rx_coalesce_usecs_high || |
| 788 | ec->rx_max_coalesced_frames_high || |
| 789 | ec->tx_coalesce_usecs_high || |
| 790 | ec->tx_max_coalesced_frames_high || |
| 791 | ec->rate_sample_interval) { |
| 792 | return -EINVAL; |
| 793 | } |
| 794 | |
| 795 | if ((ec->rx_coalesce_usecs == 0) && |
| 796 | (ec->use_adaptive_rx_coalesce == 0) && |
| 797 | (ec->tx_max_coalesced_frames == 0) && |
| 798 | (ec->rx_max_coalesced_frames == 0)) { |
| 799 | memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf)); |
| 800 | adapter->coal_conf->coalMode = VMXNET3_COALESCE_DISABLED; |
| 801 | goto done; |
| 802 | } |
| 803 | |
| 804 | if (ec->rx_coalesce_usecs != 0) { |
| 805 | u32 rbc_rate; |
| 806 | |
| 807 | if ((ec->use_adaptive_rx_coalesce != 0) || |
| 808 | (ec->tx_max_coalesced_frames != 0) || |
| 809 | (ec->rx_max_coalesced_frames != 0)) { |
| 810 | return -EINVAL; |
| 811 | } |
| 812 | |
| 813 | rbc_rate = VMXNET3_COAL_RBC_RATE(ec->rx_coalesce_usecs); |
| 814 | if (rbc_rate < VMXNET3_COAL_RBC_MIN_RATE || |
| 815 | rbc_rate > VMXNET3_COAL_RBC_MAX_RATE) { |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | |
| 819 | memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf)); |
| 820 | adapter->coal_conf->coalMode = VMXNET3_COALESCE_RBC; |
| 821 | adapter->coal_conf->coalPara.coalRbc.rbc_rate = rbc_rate; |
| 822 | goto done; |
| 823 | } |
| 824 | |
| 825 | if (ec->use_adaptive_rx_coalesce != 0) { |
| 826 | if ((ec->rx_coalesce_usecs != 0) || |
| 827 | (ec->tx_max_coalesced_frames != 0) || |
| 828 | (ec->rx_max_coalesced_frames != 0)) { |
| 829 | return -EINVAL; |
| 830 | } |
| 831 | memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf)); |
| 832 | adapter->coal_conf->coalMode = VMXNET3_COALESCE_ADAPT; |
| 833 | goto done; |
| 834 | } |
| 835 | |
| 836 | if ((ec->tx_max_coalesced_frames != 0) || |
| 837 | (ec->rx_max_coalesced_frames != 0)) { |
| 838 | if ((ec->rx_coalesce_usecs != 0) || |
| 839 | (ec->use_adaptive_rx_coalesce != 0)) { |
| 840 | return -EINVAL; |
| 841 | } |
| 842 | |
| 843 | if ((ec->tx_max_coalesced_frames > |
| 844 | VMXNET3_COAL_STATIC_MAX_DEPTH) || |
| 845 | (ec->rx_max_coalesced_frames > |
| 846 | VMXNET3_COAL_STATIC_MAX_DEPTH)) { |
| 847 | return -EINVAL; |
| 848 | } |
| 849 | |
| 850 | memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf)); |
| 851 | adapter->coal_conf->coalMode = VMXNET3_COALESCE_STATIC; |
| 852 | |
| 853 | adapter->coal_conf->coalPara.coalStatic.tx_comp_depth = |
| 854 | (ec->tx_max_coalesced_frames ? |
| 855 | ec->tx_max_coalesced_frames : |
| 856 | VMXNET3_COAL_STATIC_DEFAULT_DEPTH); |
| 857 | |
| 858 | adapter->coal_conf->coalPara.coalStatic.rx_depth = |
| 859 | (ec->rx_max_coalesced_frames ? |
| 860 | ec->rx_max_coalesced_frames : |
| 861 | VMXNET3_COAL_STATIC_DEFAULT_DEPTH); |
| 862 | |
| 863 | adapter->coal_conf->coalPara.coalStatic.tx_depth = |
| 864 | VMXNET3_COAL_STATIC_DEFAULT_DEPTH; |
| 865 | goto done; |
| 866 | } |
| 867 | |
| 868 | done: |
| 869 | adapter->default_coal_mode = false; |
| 870 | if (netif_running(netdev)) { |
| 871 | spin_lock_irqsave(&adapter->cmd_lock, flags); |
| 872 | cmdInfo->varConf.confVer = 1; |
| 873 | cmdInfo->varConf.confLen = |
| 874 | cpu_to_le32(sizeof(*adapter->coal_conf)); |
| 875 | cmdInfo->varConf.confPA = cpu_to_le64(adapter->coal_conf_pa); |
| 876 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, |
| 877 | VMXNET3_CMD_SET_COALESCE); |
| 878 | spin_unlock_irqrestore(&adapter->cmd_lock, flags); |
| 879 | } |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
stephen hemminger | c8b88ef | 2012-01-04 11:58:13 +0000 | [diff] [blame] | 884 | static const struct ethtool_ops vmxnet3_ethtool_ops = { |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 885 | .get_settings = vmxnet3_get_settings, |
| 886 | .get_drvinfo = vmxnet3_get_drvinfo, |
| 887 | .get_regs_len = vmxnet3_get_regs_len, |
| 888 | .get_regs = vmxnet3_get_regs, |
| 889 | .get_wol = vmxnet3_get_wol, |
| 890 | .set_wol = vmxnet3_set_wol, |
| 891 | .get_link = ethtool_op_get_link, |
Shrikrishna Khare | 4edef40e | 2016-06-16 10:51:57 -0700 | [diff] [blame^] | 892 | .get_coalesce = vmxnet3_get_coalesce, |
| 893 | .set_coalesce = vmxnet3_set_coalesce, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 894 | .get_strings = vmxnet3_get_strings, |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 895 | .get_sset_count = vmxnet3_get_sset_count, |
| 896 | .get_ethtool_stats = vmxnet3_get_ethtool_stats, |
| 897 | .get_ringparam = vmxnet3_get_ringparam, |
| 898 | .set_ringparam = vmxnet3_set_ringparam, |
Shreyas Bhatewara | 09c5088 | 2010-11-19 10:55:24 +0000 | [diff] [blame] | 899 | .get_rxnfc = vmxnet3_get_rxnfc, |
Scott J. Goldman | e9248fb | 2010-11-27 10:33:55 +0000 | [diff] [blame] | 900 | #ifdef VMXNET3_RSS |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 901 | .get_rxfh_indir_size = vmxnet3_get_rss_indir_size, |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 902 | .get_rxfh = vmxnet3_get_rss, |
| 903 | .set_rxfh = vmxnet3_set_rss, |
Scott J. Goldman | e9248fb | 2010-11-27 10:33:55 +0000 | [diff] [blame] | 904 | #endif |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 905 | }; |
| 906 | |
| 907 | void vmxnet3_set_ethtool_ops(struct net_device *netdev) |
| 908 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 909 | netdev->ethtool_ops = &vmxnet3_ethtool_ops; |
Shreyas Bhatewara | d1a890fa | 2009-10-13 00:15:51 -0700 | [diff] [blame] | 910 | } |