vmxnet3_ethtool.c 19 KB

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