blob: 64303eb3a5fc66ccdbe535f3f955be94c3bb6315 [file] [log] [blame]
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -07001/*
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
30struct vmxnet3_stat_desc {
31 char desc[ETH_GSTRING_LEN];
32 int offset;
33};
34
35
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -070036/* per tq stats maintained by the device */
37static const struct vmxnet3_stat_desc
38vmxnet3_tq_dev_stats[] = {
39 /* description, offset */
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +000040 { "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 Bhatewarad1a890fa2009-10-13 00:15:51 -070051};
52
53/* per tq stats maintained by the driver */
54static const struct vmxnet3_stat_desc
55vmxnet3_tq_driver_stats[] = {
56 /* description, offset */
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +000057 {" 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 Bhatewarad1a890fa2009-10-13 00:15:51 -070075};
76
77/* per rq stats maintained by the device */
78static const struct vmxnet3_stat_desc
79vmxnet3_rq_dev_stats[] = {
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +000080 { "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 Bhatewarad1a890fa2009-10-13 00:15:51 -070091};
92
93/* per rq stats maintained by the driver */
94static const struct vmxnet3_stat_desc
95vmxnet3_rq_driver_stats[] = {
96 /* description, offset */
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +000097 { " 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 Bhatewarad1a890fa2009-10-13 00:15:51 -0700105};
106
107/* gloabl stats maintained by the driver */
108static const struct vmxnet3_stat_desc
109vmxnet3_global_stats[] = {
110 /* description, offset */
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000111 { "tx timeout count", offsetof(struct vmxnet3_adapter,
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700112 tx_timeout_count) }
113};
114
115
116struct net_device_stats *
117vmxnet3_get_stats(struct net_device *netdev)
118{
119 struct vmxnet3_adapter *adapter;
120 struct vmxnet3_tq_driver_stats *drvTxStats;
121 struct vmxnet3_rq_driver_stats *drvRxStats;
122 struct UPT1_TxStats *devTxStats;
123 struct UPT1_RxStats *devRxStats;
124 struct net_device_stats *net_stats = &netdev->stats;
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000125 unsigned long flags;
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000126 int i;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700127
128 adapter = netdev_priv(netdev);
129
130 /* Collect the dev stats into the shared area */
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000131 spin_lock_irqsave(&adapter->cmd_lock, flags);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700132 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000133 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700134
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700135 memset(net_stats, 0, sizeof(*net_stats));
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000136 for (i = 0; i < adapter->num_tx_queues; i++) {
137 devTxStats = &adapter->tqd_start[i].stats;
138 drvTxStats = &adapter->tx_queue[i].stats;
139 net_stats->tx_packets += devTxStats->ucastPktsTxOK +
140 devTxStats->mcastPktsTxOK +
141 devTxStats->bcastPktsTxOK;
142 net_stats->tx_bytes += devTxStats->ucastBytesTxOK +
143 devTxStats->mcastBytesTxOK +
144 devTxStats->bcastBytesTxOK;
145 net_stats->tx_errors += devTxStats->pktsTxError;
146 net_stats->tx_dropped += drvTxStats->drop_total;
147 }
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700148
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000149 for (i = 0; i < adapter->num_rx_queues; i++) {
150 devRxStats = &adapter->rqd_start[i].stats;
151 drvRxStats = &adapter->rx_queue[i].stats;
152 net_stats->rx_packets += devRxStats->ucastPktsRxOK +
153 devRxStats->mcastPktsRxOK +
154 devRxStats->bcastPktsRxOK;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700155
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000156 net_stats->rx_bytes += devRxStats->ucastBytesRxOK +
157 devRxStats->mcastBytesRxOK +
158 devRxStats->bcastBytesRxOK;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700159
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000160 net_stats->rx_errors += devRxStats->pktsRxError;
161 net_stats->rx_dropped += drvRxStats->drop_total;
162 net_stats->multicast += devRxStats->mcastPktsRxOK;
163 }
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700164 return net_stats;
165}
166
167static int
168vmxnet3_get_sset_count(struct net_device *netdev, int sset)
169{
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000170 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700171 switch (sset) {
172 case ETH_SS_STATS:
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000173 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 Bhatewarad1a890fa2009-10-13 00:15:51 -0700179 ARRAY_SIZE(vmxnet3_global_stats);
180 default:
181 return -EOPNOTSUPP;
182 }
183}
184
185
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000186/* Should be multiple of 4 */
187#define NUM_TX_REGS 8
188#define NUM_RX_REGS 12
189
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700190static int
191vmxnet3_get_regs_len(struct net_device *netdev)
192{
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000193 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
194 return (adapter->num_tx_queues * NUM_TX_REGS * sizeof(u32) +
195 adapter->num_rx_queues * NUM_RX_REGS * sizeof(u32));
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700196}
197
198
199static void
200vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
201{
202 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
203
204 strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver));
205 drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
206
207 strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
208 sizeof(drvinfo->version));
209 drvinfo->driver[sizeof(drvinfo->version) - 1] = '\0';
210
211 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
212 drvinfo->fw_version[sizeof(drvinfo->fw_version) - 1] = '\0';
213
214 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
215 ETHTOOL_BUSINFO_LEN);
216 drvinfo->n_stats = vmxnet3_get_sset_count(netdev, ETH_SS_STATS);
217 drvinfo->testinfo_len = 0;
218 drvinfo->eedump_len = 0;
219 drvinfo->regdump_len = vmxnet3_get_regs_len(netdev);
220}
221
222
223static void
224vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
225{
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000226 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700227 if (stringset == ETH_SS_STATS) {
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000228 int i, j;
229 for (j = 0; j < adapter->num_tx_queues; j++) {
230 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
231 memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
232 ETH_GSTRING_LEN);
233 buf += ETH_GSTRING_LEN;
234 }
235 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats);
236 i++) {
237 memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
238 ETH_GSTRING_LEN);
239 buf += ETH_GSTRING_LEN;
240 }
241 }
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700242
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000243 for (j = 0; j < adapter->num_rx_queues; j++) {
244 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
245 memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
246 ETH_GSTRING_LEN);
247 buf += ETH_GSTRING_LEN;
248 }
249 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats);
250 i++) {
251 memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
252 ETH_GSTRING_LEN);
253 buf += ETH_GSTRING_LEN;
254 }
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700255 }
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000256
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700257 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
258 memcpy(buf, vmxnet3_global_stats[i].desc,
259 ETH_GSTRING_LEN);
260 buf += ETH_GSTRING_LEN;
261 }
262 }
263}
264
Michał Mirosława0d27302011-04-18 13:31:21 +0000265int vmxnet3_set_features(struct net_device *netdev, u32 features)
Stanislaw Gruszkad92be4b2010-06-27 23:29:42 +0000266{
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700267 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000268 unsigned long flags;
Michał Mirosława0d27302011-04-18 13:31:21 +0000269 u32 changed = features ^ netdev->features;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700270
Michał Mirosława0d27302011-04-18 13:31:21 +0000271 if (changed & (NETIF_F_RXCSUM|NETIF_F_LRO)) {
272 if (features & NETIF_F_RXCSUM)
273 adapter->shared->devRead.misc.uptFeatures |=
274 UPT1_F_RXCSUM;
275 else
276 adapter->shared->devRead.misc.uptFeatures &=
277 ~UPT1_F_RXCSUM;
Stanislaw Gruszkad92be4b2010-06-27 23:29:42 +0000278
Michał Mirosława0d27302011-04-18 13:31:21 +0000279 if (features & NETIF_F_LRO)
Shreyas Bhatewaraca802442010-07-15 22:17:29 -0700280 adapter->shared->devRead.misc.uptFeatures |=
Harvey Harrison3843e512010-10-21 18:05:32 +0000281 UPT1_F_LRO;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700282 else
283 adapter->shared->devRead.misc.uptFeatures &=
Harvey Harrison3843e512010-10-21 18:05:32 +0000284 ~UPT1_F_LRO;
Michał Mirosława0d27302011-04-18 13:31:21 +0000285
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000286 spin_lock_irqsave(&adapter->cmd_lock, flags);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700287 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
288 VMXNET3_CMD_UPDATE_FEATURE);
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000289 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700290 }
291 return 0;
292}
293
294static void
295vmxnet3_get_ethtool_stats(struct net_device *netdev,
296 struct ethtool_stats *stats, u64 *buf)
297{
298 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000299 unsigned long flags;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700300 u8 *base;
301 int i;
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000302 int j = 0;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700303
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000304 spin_lock_irqsave(&adapter->cmd_lock, flags);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700305 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000306 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700307
308 /* this does assume each counter is 64-bit wide */
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000309 for (j = 0; j < adapter->num_tx_queues; j++) {
310 base = (u8 *)&adapter->tqd_start[j].stats;
311 *buf++ = (u64)j;
312 for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
313 *buf++ = *(u64 *)(base +
314 vmxnet3_tq_dev_stats[i].offset);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700315
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000316 base = (u8 *)&adapter->tx_queue[j].stats;
317 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
318 *buf++ = *(u64 *)(base +
319 vmxnet3_tq_driver_stats[i].offset);
320 }
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700321
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000322 for (j = 0; j < adapter->num_tx_queues; j++) {
323 base = (u8 *)&adapter->rqd_start[j].stats;
324 *buf++ = (u64) j;
325 for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
326 *buf++ = *(u64 *)(base +
327 vmxnet3_rq_dev_stats[i].offset);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700328
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000329 base = (u8 *)&adapter->rx_queue[j].stats;
330 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
331 *buf++ = *(u64 *)(base +
332 vmxnet3_rq_driver_stats[i].offset);
333 }
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700334
335 base = (u8 *)adapter;
336 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
337 *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
338}
339
340
341static void
342vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
343{
344 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
345 u32 *buf = p;
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000346 int i = 0, j = 0;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700347
348 memset(p, 0, vmxnet3_get_regs_len(netdev));
349
350 regs->version = 1;
351
352 /* Update vmxnet3_get_regs_len if we want to dump more registers */
353
354 /* make each ring use multiple of 16 bytes */
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000355 for (i = 0; i < adapter->num_tx_queues; i++) {
356 buf[j++] = adapter->tx_queue[i].tx_ring.next2fill;
357 buf[j++] = adapter->tx_queue[i].tx_ring.next2comp;
358 buf[j++] = adapter->tx_queue[i].tx_ring.gen;
359 buf[j++] = 0;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700360
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000361 buf[j++] = adapter->tx_queue[i].comp_ring.next2proc;
362 buf[j++] = adapter->tx_queue[i].comp_ring.gen;
363 buf[j++] = adapter->tx_queue[i].stopped;
364 buf[j++] = 0;
365 }
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700366
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000367 for (i = 0; i < adapter->num_rx_queues; i++) {
368 buf[j++] = adapter->rx_queue[i].rx_ring[0].next2fill;
369 buf[j++] = adapter->rx_queue[i].rx_ring[0].next2comp;
370 buf[j++] = adapter->rx_queue[i].rx_ring[0].gen;
371 buf[j++] = 0;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700372
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000373 buf[j++] = adapter->rx_queue[i].rx_ring[1].next2fill;
374 buf[j++] = adapter->rx_queue[i].rx_ring[1].next2comp;
375 buf[j++] = adapter->rx_queue[i].rx_ring[1].gen;
376 buf[j++] = 0;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700377
Shreyas Bhatewara76d39da2011-01-14 14:59:47 +0000378 buf[j++] = adapter->rx_queue[i].comp_ring.next2proc;
379 buf[j++] = adapter->rx_queue[i].comp_ring.gen;
380 buf[j++] = 0;
381 buf[j++] = 0;
382 }
383
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700384}
385
386
387static void
388vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
389{
390 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
391
392 wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
393 wol->wolopts = adapter->wol;
394}
395
396
397static int
398vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
399{
400 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
401
402 if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
403 WAKE_MAGICSECURE)) {
404 return -EOPNOTSUPP;
405 }
406
407 adapter->wol = wol->wolopts;
408
409 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
410
411 return 0;
412}
413
414
415static int
416vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
417{
418 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
419
420 ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full |
421 SUPPORTED_TP;
422 ecmd->advertising = ADVERTISED_TP;
423 ecmd->port = PORT_TP;
424 ecmd->transceiver = XCVR_INTERNAL;
425
426 if (adapter->link_speed) {
David Decotigny70739492011-04-27 18:32:40 +0000427 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700428 ecmd->duplex = DUPLEX_FULL;
429 } else {
David Decotigny70739492011-04-27 18:32:40 +0000430 ethtool_cmd_speed_set(ecmd, -1);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700431 ecmd->duplex = -1;
432 }
433 return 0;
434}
435
436
437static void
438vmxnet3_get_ringparam(struct net_device *netdev,
439 struct ethtool_ringparam *param)
440{
441 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
442
443 param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
444 param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
445 param->rx_mini_max_pending = 0;
446 param->rx_jumbo_max_pending = 0;
447
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000448 param->rx_pending = adapter->rx_queue[0].rx_ring[0].size *
449 adapter->num_rx_queues;
450 param->tx_pending = adapter->tx_queue[0].tx_ring.size *
451 adapter->num_tx_queues;
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700452 param->rx_mini_pending = 0;
453 param->rx_jumbo_pending = 0;
454}
455
456
457static int
458vmxnet3_set_ringparam(struct net_device *netdev,
459 struct ethtool_ringparam *param)
460{
461 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
462 u32 new_tx_ring_size, new_rx_ring_size;
463 u32 sz;
464 int err = 0;
465
466 if (param->tx_pending == 0 || param->tx_pending >
467 VMXNET3_TX_RING_MAX_SIZE)
468 return -EINVAL;
469
470 if (param->rx_pending == 0 || param->rx_pending >
471 VMXNET3_RX_RING_MAX_SIZE)
472 return -EINVAL;
473
474
475 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
476 new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
477 ~VMXNET3_RING_SIZE_MASK;
478 new_tx_ring_size = min_t(u32, new_tx_ring_size,
479 VMXNET3_TX_RING_MAX_SIZE);
480 if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
481 VMXNET3_RING_SIZE_ALIGN) != 0)
482 return -EINVAL;
483
484 /* ring0 has to be a multiple of
485 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
486 */
487 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
488 new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
489 new_rx_ring_size = min_t(u32, new_rx_ring_size,
490 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
491 if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
492 sz) != 0)
493 return -EINVAL;
494
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000495 if (new_tx_ring_size == adapter->tx_queue[0].tx_ring.size &&
496 new_rx_ring_size == adapter->rx_queue[0].rx_ring[0].size) {
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700497 return 0;
498 }
499
500 /*
501 * Reset_work may be in the middle of resetting the device, wait for its
502 * completion.
503 */
504 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
505 msleep(1);
506
507 if (netif_running(netdev)) {
508 vmxnet3_quiesce_dev(adapter);
509 vmxnet3_reset_dev(adapter);
510
511 /* recreate the rx queue and the tx queue based on the
512 * new sizes */
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000513 vmxnet3_tq_destroy_all(adapter);
514 vmxnet3_rq_destroy_all(adapter);
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700515
516 err = vmxnet3_create_queues(adapter, new_tx_ring_size,
517 new_rx_ring_size, VMXNET3_DEF_RX_RING_SIZE);
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000518
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700519 if (err) {
520 /* failed, most likely because of OOM, try default
521 * size */
522 printk(KERN_ERR "%s: failed to apply new sizes, try the"
523 " default ones\n", netdev->name);
524 err = vmxnet3_create_queues(adapter,
525 VMXNET3_DEF_TX_RING_SIZE,
526 VMXNET3_DEF_RX_RING_SIZE,
527 VMXNET3_DEF_RX_RING_SIZE);
528 if (err) {
529 printk(KERN_ERR "%s: failed to create queues "
530 "with default sizes. Closing it\n",
531 netdev->name);
532 goto out;
533 }
534 }
535
536 err = vmxnet3_activate_dev(adapter);
537 if (err)
538 printk(KERN_ERR "%s: failed to re-activate, error %d."
539 " Closing it\n", netdev->name, err);
540 }
541
542out:
543 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
544 if (err)
545 vmxnet3_force_close(adapter);
546
547 return err;
548}
549
550
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000551static int
552vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
553 void *rules)
554{
555 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
556 switch (info->cmd) {
557 case ETHTOOL_GRXRINGS:
558 info->data = adapter->num_rx_queues;
559 return 0;
560 }
561 return -EOPNOTSUPP;
562}
563
Scott J. Goldmane9248fb2010-11-27 10:33:55 +0000564#ifdef VMXNET3_RSS
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000565static int
566vmxnet3_get_rss_indir(struct net_device *netdev,
567 struct ethtool_rxfh_indir *p)
568{
569 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
570 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
571 unsigned int n = min_t(unsigned int, p->size, rssConf->indTableSize);
572
573 p->size = rssConf->indTableSize;
574 while (n--)
575 p->ring_index[n] = rssConf->indTable[n];
576 return 0;
577
578}
579
580static int
581vmxnet3_set_rss_indir(struct net_device *netdev,
582 const struct ethtool_rxfh_indir *p)
583{
584 unsigned int i;
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000585 unsigned long flags;
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000586 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
587 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
588
589 if (p->size != rssConf->indTableSize)
590 return -EINVAL;
591 for (i = 0; i < rssConf->indTableSize; i++) {
592 /*
593 * Return with error code if any of the queue indices
594 * is out of range
595 */
596 if (p->ring_index[i] < 0 ||
597 p->ring_index[i] >= adapter->num_rx_queues)
598 return -EINVAL;
599 }
600
601 for (i = 0; i < rssConf->indTableSize; i++)
602 rssConf->indTable[i] = p->ring_index[i];
603
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000604 spin_lock_irqsave(&adapter->cmd_lock, flags);
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000605 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
606 VMXNET3_CMD_UPDATE_RSSIDT);
Shreyas Bhatewara83d0fef2011-01-14 14:59:57 +0000607 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000608
609 return 0;
610
611}
Scott J. Goldmane9248fb2010-11-27 10:33:55 +0000612#endif
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000613
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700614static struct ethtool_ops vmxnet3_ethtool_ops = {
615 .get_settings = vmxnet3_get_settings,
616 .get_drvinfo = vmxnet3_get_drvinfo,
617 .get_regs_len = vmxnet3_get_regs_len,
618 .get_regs = vmxnet3_get_regs,
619 .get_wol = vmxnet3_get_wol,
620 .set_wol = vmxnet3_set_wol,
621 .get_link = ethtool_op_get_link,
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700622 .get_strings = vmxnet3_get_strings,
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700623 .get_sset_count = vmxnet3_get_sset_count,
624 .get_ethtool_stats = vmxnet3_get_ethtool_stats,
625 .get_ringparam = vmxnet3_get_ringparam,
626 .set_ringparam = vmxnet3_set_ringparam,
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000627 .get_rxnfc = vmxnet3_get_rxnfc,
Scott J. Goldmane9248fb2010-11-27 10:33:55 +0000628#ifdef VMXNET3_RSS
Shreyas Bhatewara09c50882010-11-19 10:55:24 +0000629 .get_rxfh_indir = vmxnet3_get_rss_indir,
630 .set_rxfh_indir = vmxnet3_set_rss_indir,
Scott J. Goldmane9248fb2010-11-27 10:33:55 +0000631#endif
Shreyas Bhatewarad1a890fa2009-10-13 00:15:51 -0700632};
633
634void vmxnet3_set_ethtool_ops(struct net_device *netdev)
635{
636 SET_ETHTOOL_OPS(netdev, &vmxnet3_ethtool_ops);
637}