Commit | Line | Data |
---|---|---|
d1a890fa SB |
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) | |
115924b6 SB |
53 | set_flag_le64( |
54 | &adapter->shared->devRead.misc.uptFeatures, | |
55 | UPT1_F_RXCSUM); | |
d1a890fa | 56 | else |
115924b6 SB |
57 | reset_flag_le64( |
58 | &adapter->shared->devRead.misc.uptFeatures, | |
59 | UPT1_F_RXCSUM); | |
d1a890fa SB |
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 | ||
d1a890fa | 278 | static int |
d92be4b1 SG |
279 | vmxnet3_set_flags(struct net_device *netdev, u32 data) |
280 | { | |
d1a890fa SB |
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 | ||
d92be4b1 SG |
285 | if (data & ~ETH_FLAG_LRO) |
286 | return -EOPNOTSUPP; | |
287 | ||
d1a890fa SB |
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) | |
294 | adapter->shared->devRead.misc.uptFeatures &= UPT1_F_LRO; | |
295 | else | |
296 | adapter->shared->devRead.misc.uptFeatures &= | |
297 | ~UPT1_F_LRO; | |
298 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, | |
299 | VMXNET3_CMD_UPDATE_FEATURE); | |
300 | } | |
301 | return 0; | |
302 | } | |
303 | ||
304 | static void | |
305 | vmxnet3_get_ethtool_stats(struct net_device *netdev, | |
306 | struct ethtool_stats *stats, u64 *buf) | |
307 | { | |
308 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); | |
309 | u8 *base; | |
310 | int i; | |
311 | ||
312 | VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS); | |
313 | ||
314 | /* this does assume each counter is 64-bit wide */ | |
315 | ||
316 | base = (u8 *)&adapter->tqd_start->stats; | |
317 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) | |
318 | *buf++ = *(u64 *)(base + vmxnet3_tq_dev_stats[i].offset); | |
319 | ||
320 | base = (u8 *)&adapter->tx_queue.stats; | |
321 | for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++) | |
322 | *buf++ = *(u64 *)(base + vmxnet3_tq_driver_stats[i].offset); | |
323 | ||
324 | base = (u8 *)&adapter->rqd_start->stats; | |
325 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) | |
326 | *buf++ = *(u64 *)(base + vmxnet3_rq_dev_stats[i].offset); | |
327 | ||
328 | base = (u8 *)&adapter->rx_queue.stats; | |
329 | for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++) | |
330 | *buf++ = *(u64 *)(base + vmxnet3_rq_driver_stats[i].offset); | |
331 | ||
332 | base = (u8 *)adapter; | |
333 | for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) | |
334 | *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset); | |
335 | } | |
336 | ||
337 | ||
338 | static void | |
339 | vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) | |
340 | { | |
341 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); | |
342 | u32 *buf = p; | |
343 | ||
344 | memset(p, 0, vmxnet3_get_regs_len(netdev)); | |
345 | ||
346 | regs->version = 1; | |
347 | ||
348 | /* Update vmxnet3_get_regs_len if we want to dump more registers */ | |
349 | ||
350 | /* make each ring use multiple of 16 bytes */ | |
351 | buf[0] = adapter->tx_queue.tx_ring.next2fill; | |
352 | buf[1] = adapter->tx_queue.tx_ring.next2comp; | |
353 | buf[2] = adapter->tx_queue.tx_ring.gen; | |
354 | buf[3] = 0; | |
355 | ||
356 | buf[4] = adapter->tx_queue.comp_ring.next2proc; | |
357 | buf[5] = adapter->tx_queue.comp_ring.gen; | |
358 | buf[6] = adapter->tx_queue.stopped; | |
359 | buf[7] = 0; | |
360 | ||
361 | buf[8] = adapter->rx_queue.rx_ring[0].next2fill; | |
362 | buf[9] = adapter->rx_queue.rx_ring[0].next2comp; | |
363 | buf[10] = adapter->rx_queue.rx_ring[0].gen; | |
364 | buf[11] = 0; | |
365 | ||
366 | buf[12] = adapter->rx_queue.rx_ring[1].next2fill; | |
367 | buf[13] = adapter->rx_queue.rx_ring[1].next2comp; | |
368 | buf[14] = adapter->rx_queue.rx_ring[1].gen; | |
369 | buf[15] = 0; | |
370 | ||
371 | buf[16] = adapter->rx_queue.comp_ring.next2proc; | |
372 | buf[17] = adapter->rx_queue.comp_ring.gen; | |
373 | buf[18] = 0; | |
374 | buf[19] = 0; | |
375 | } | |
376 | ||
377 | ||
378 | static void | |
379 | vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) | |
380 | { | |
381 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); | |
382 | ||
383 | wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC; | |
384 | wol->wolopts = adapter->wol; | |
385 | } | |
386 | ||
387 | ||
388 | static int | |
389 | vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) | |
390 | { | |
391 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); | |
392 | ||
393 | if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST | | |
394 | WAKE_MAGICSECURE)) { | |
395 | return -EOPNOTSUPP; | |
396 | } | |
397 | ||
398 | adapter->wol = wol->wolopts; | |
399 | ||
400 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); | |
401 | ||
402 | return 0; | |
403 | } | |
404 | ||
405 | ||
406 | static int | |
407 | vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) | |
408 | { | |
409 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); | |
410 | ||
411 | ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full | | |
412 | SUPPORTED_TP; | |
413 | ecmd->advertising = ADVERTISED_TP; | |
414 | ecmd->port = PORT_TP; | |
415 | ecmd->transceiver = XCVR_INTERNAL; | |
416 | ||
417 | if (adapter->link_speed) { | |
418 | ecmd->speed = adapter->link_speed; | |
419 | ecmd->duplex = DUPLEX_FULL; | |
420 | } else { | |
421 | ecmd->speed = -1; | |
422 | ecmd->duplex = -1; | |
423 | } | |
424 | return 0; | |
425 | } | |
426 | ||
427 | ||
428 | static void | |
429 | vmxnet3_get_ringparam(struct net_device *netdev, | |
430 | struct ethtool_ringparam *param) | |
431 | { | |
432 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); | |
433 | ||
434 | param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE; | |
435 | param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE; | |
436 | param->rx_mini_max_pending = 0; | |
437 | param->rx_jumbo_max_pending = 0; | |
438 | ||
439 | param->rx_pending = adapter->rx_queue.rx_ring[0].size; | |
440 | param->tx_pending = adapter->tx_queue.tx_ring.size; | |
441 | param->rx_mini_pending = 0; | |
442 | param->rx_jumbo_pending = 0; | |
443 | } | |
444 | ||
445 | ||
446 | static int | |
447 | vmxnet3_set_ringparam(struct net_device *netdev, | |
448 | struct ethtool_ringparam *param) | |
449 | { | |
450 | struct vmxnet3_adapter *adapter = netdev_priv(netdev); | |
451 | u32 new_tx_ring_size, new_rx_ring_size; | |
452 | u32 sz; | |
453 | int err = 0; | |
454 | ||
455 | if (param->tx_pending == 0 || param->tx_pending > | |
456 | VMXNET3_TX_RING_MAX_SIZE) | |
457 | return -EINVAL; | |
458 | ||
459 | if (param->rx_pending == 0 || param->rx_pending > | |
460 | VMXNET3_RX_RING_MAX_SIZE) | |
461 | return -EINVAL; | |
462 | ||
463 | ||
464 | /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */ | |
465 | new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) & | |
466 | ~VMXNET3_RING_SIZE_MASK; | |
467 | new_tx_ring_size = min_t(u32, new_tx_ring_size, | |
468 | VMXNET3_TX_RING_MAX_SIZE); | |
469 | if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size % | |
470 | VMXNET3_RING_SIZE_ALIGN) != 0) | |
471 | return -EINVAL; | |
472 | ||
473 | /* ring0 has to be a multiple of | |
474 | * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN | |
475 | */ | |
476 | sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN; | |
477 | new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz; | |
478 | new_rx_ring_size = min_t(u32, new_rx_ring_size, | |
479 | VMXNET3_RX_RING_MAX_SIZE / sz * sz); | |
480 | if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size % | |
481 | sz) != 0) | |
482 | return -EINVAL; | |
483 | ||
484 | if (new_tx_ring_size == adapter->tx_queue.tx_ring.size && | |
485 | new_rx_ring_size == adapter->rx_queue.rx_ring[0].size) { | |
486 | return 0; | |
487 | } | |
488 | ||
489 | /* | |
490 | * Reset_work may be in the middle of resetting the device, wait for its | |
491 | * completion. | |
492 | */ | |
493 | while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state)) | |
494 | msleep(1); | |
495 | ||
496 | if (netif_running(netdev)) { | |
497 | vmxnet3_quiesce_dev(adapter); | |
498 | vmxnet3_reset_dev(adapter); | |
499 | ||
500 | /* recreate the rx queue and the tx queue based on the | |
501 | * new sizes */ | |
502 | vmxnet3_tq_destroy(&adapter->tx_queue, adapter); | |
503 | vmxnet3_rq_destroy(&adapter->rx_queue, adapter); | |
504 | ||
505 | err = vmxnet3_create_queues(adapter, new_tx_ring_size, | |
506 | new_rx_ring_size, VMXNET3_DEF_RX_RING_SIZE); | |
507 | if (err) { | |
508 | /* failed, most likely because of OOM, try default | |
509 | * size */ | |
510 | printk(KERN_ERR "%s: failed to apply new sizes, try the" | |
511 | " default ones\n", netdev->name); | |
512 | err = vmxnet3_create_queues(adapter, | |
513 | VMXNET3_DEF_TX_RING_SIZE, | |
514 | VMXNET3_DEF_RX_RING_SIZE, | |
515 | VMXNET3_DEF_RX_RING_SIZE); | |
516 | if (err) { | |
517 | printk(KERN_ERR "%s: failed to create queues " | |
518 | "with default sizes. Closing it\n", | |
519 | netdev->name); | |
520 | goto out; | |
521 | } | |
522 | } | |
523 | ||
524 | err = vmxnet3_activate_dev(adapter); | |
525 | if (err) | |
526 | printk(KERN_ERR "%s: failed to re-activate, error %d." | |
527 | " Closing it\n", netdev->name, err); | |
528 | } | |
529 | ||
530 | out: | |
531 | clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state); | |
532 | if (err) | |
533 | vmxnet3_force_close(adapter); | |
534 | ||
535 | return err; | |
536 | } | |
537 | ||
538 | ||
539 | static struct ethtool_ops vmxnet3_ethtool_ops = { | |
540 | .get_settings = vmxnet3_get_settings, | |
541 | .get_drvinfo = vmxnet3_get_drvinfo, | |
542 | .get_regs_len = vmxnet3_get_regs_len, | |
543 | .get_regs = vmxnet3_get_regs, | |
544 | .get_wol = vmxnet3_get_wol, | |
545 | .set_wol = vmxnet3_set_wol, | |
546 | .get_link = ethtool_op_get_link, | |
547 | .get_rx_csum = vmxnet3_get_rx_csum, | |
548 | .set_rx_csum = vmxnet3_set_rx_csum, | |
549 | .get_tx_csum = ethtool_op_get_tx_csum, | |
550 | .set_tx_csum = ethtool_op_set_tx_hw_csum, | |
551 | .get_sg = ethtool_op_get_sg, | |
552 | .set_sg = ethtool_op_set_sg, | |
553 | .get_tso = ethtool_op_get_tso, | |
554 | .set_tso = ethtool_op_set_tso, | |
555 | .get_strings = vmxnet3_get_strings, | |
cbf2d604 | 556 | .get_flags = ethtool_op_get_flags, |
d1a890fa SB |
557 | .set_flags = vmxnet3_set_flags, |
558 | .get_sset_count = vmxnet3_get_sset_count, | |
559 | .get_ethtool_stats = vmxnet3_get_ethtool_stats, | |
560 | .get_ringparam = vmxnet3_get_ringparam, | |
561 | .set_ringparam = vmxnet3_set_ringparam, | |
562 | }; | |
563 | ||
564 | void vmxnet3_set_ethtool_ops(struct net_device *netdev) | |
565 | { | |
566 | SET_ETHTOOL_OPS(netdev, &vmxnet3_ethtool_ops); | |
567 | } |