vmxnet3_ethtool.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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. if (features & NETIF_F_LRO)
  246. adapter->shared->devRead.misc.uptFeatures |=
  247. UPT1_F_LRO;
  248. else
  249. adapter->shared->devRead.misc.uptFeatures &=
  250. ~UPT1_F_LRO;
  251. spin_lock_irqsave(&adapter->cmd_lock, flags);
  252. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  253. VMXNET3_CMD_UPDATE_FEATURE);
  254. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  255. }
  256. return 0;
  257. }
  258. static void
  259. vmxnet3_get_ethtool_stats(struct net_device *netdev,
  260. struct ethtool_stats *stats, u64 *buf)
  261. {
  262. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  263. unsigned long flags;
  264. u8 *base;
  265. int i;
  266. int j = 0;
  267. spin_lock_irqsave(&adapter->cmd_lock, flags);
  268. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
  269. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  270. /* this does assume each counter is 64-bit wide */
  271. for (j = 0; j < adapter->num_tx_queues; j++) {
  272. base = (u8 *)&adapter->tqd_start[j].stats;
  273. *buf++ = (u64)j;
  274. for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
  275. *buf++ = *(u64 *)(base +
  276. vmxnet3_tq_dev_stats[i].offset);
  277. base = (u8 *)&adapter->tx_queue[j].stats;
  278. for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
  279. *buf++ = *(u64 *)(base +
  280. vmxnet3_tq_driver_stats[i].offset);
  281. }
  282. for (j = 0; j < adapter->num_tx_queues; j++) {
  283. base = (u8 *)&adapter->rqd_start[j].stats;
  284. *buf++ = (u64) j;
  285. for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
  286. *buf++ = *(u64 *)(base +
  287. vmxnet3_rq_dev_stats[i].offset);
  288. base = (u8 *)&adapter->rx_queue[j].stats;
  289. for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
  290. *buf++ = *(u64 *)(base +
  291. vmxnet3_rq_driver_stats[i].offset);
  292. }
  293. base = (u8 *)adapter;
  294. for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
  295. *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
  296. }
  297. static void
  298. vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
  299. {
  300. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  301. u32 *buf = p;
  302. int i = 0, j = 0;
  303. memset(p, 0, vmxnet3_get_regs_len(netdev));
  304. regs->version = 1;
  305. /* Update vmxnet3_get_regs_len if we want to dump more registers */
  306. /* make each ring use multiple of 16 bytes */
  307. for (i = 0; i < adapter->num_tx_queues; i++) {
  308. buf[j++] = adapter->tx_queue[i].tx_ring.next2fill;
  309. buf[j++] = adapter->tx_queue[i].tx_ring.next2comp;
  310. buf[j++] = adapter->tx_queue[i].tx_ring.gen;
  311. buf[j++] = 0;
  312. buf[j++] = adapter->tx_queue[i].comp_ring.next2proc;
  313. buf[j++] = adapter->tx_queue[i].comp_ring.gen;
  314. buf[j++] = adapter->tx_queue[i].stopped;
  315. buf[j++] = 0;
  316. }
  317. for (i = 0; i < adapter->num_rx_queues; i++) {
  318. buf[j++] = adapter->rx_queue[i].rx_ring[0].next2fill;
  319. buf[j++] = adapter->rx_queue[i].rx_ring[0].next2comp;
  320. buf[j++] = adapter->rx_queue[i].rx_ring[0].gen;
  321. buf[j++] = 0;
  322. buf[j++] = adapter->rx_queue[i].rx_ring[1].next2fill;
  323. buf[j++] = adapter->rx_queue[i].rx_ring[1].next2comp;
  324. buf[j++] = adapter->rx_queue[i].rx_ring[1].gen;
  325. buf[j++] = 0;
  326. buf[j++] = adapter->rx_queue[i].comp_ring.next2proc;
  327. buf[j++] = adapter->rx_queue[i].comp_ring.gen;
  328. buf[j++] = 0;
  329. buf[j++] = 0;
  330. }
  331. }
  332. static void
  333. vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  334. {
  335. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  336. wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
  337. wol->wolopts = adapter->wol;
  338. }
  339. static int
  340. vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  341. {
  342. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  343. if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
  344. WAKE_MAGICSECURE)) {
  345. return -EOPNOTSUPP;
  346. }
  347. adapter->wol = wol->wolopts;
  348. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  349. return 0;
  350. }
  351. static int
  352. vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  353. {
  354. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  355. ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full |
  356. SUPPORTED_TP;
  357. ecmd->advertising = ADVERTISED_TP;
  358. ecmd->port = PORT_TP;
  359. ecmd->transceiver = XCVR_INTERNAL;
  360. if (adapter->link_speed) {
  361. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  362. ecmd->duplex = DUPLEX_FULL;
  363. } else {
  364. ethtool_cmd_speed_set(ecmd, -1);
  365. ecmd->duplex = -1;
  366. }
  367. return 0;
  368. }
  369. static void
  370. vmxnet3_get_ringparam(struct net_device *netdev,
  371. struct ethtool_ringparam *param)
  372. {
  373. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  374. param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
  375. param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
  376. param->rx_mini_max_pending = 0;
  377. param->rx_jumbo_max_pending = 0;
  378. param->rx_pending = adapter->rx_queue[0].rx_ring[0].size *
  379. adapter->num_rx_queues;
  380. param->tx_pending = adapter->tx_queue[0].tx_ring.size *
  381. adapter->num_tx_queues;
  382. param->rx_mini_pending = 0;
  383. param->rx_jumbo_pending = 0;
  384. }
  385. static int
  386. vmxnet3_set_ringparam(struct net_device *netdev,
  387. struct ethtool_ringparam *param)
  388. {
  389. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  390. u32 new_tx_ring_size, new_rx_ring_size;
  391. u32 sz;
  392. int err = 0;
  393. if (param->tx_pending == 0 || param->tx_pending >
  394. VMXNET3_TX_RING_MAX_SIZE)
  395. return -EINVAL;
  396. if (param->rx_pending == 0 || param->rx_pending >
  397. VMXNET3_RX_RING_MAX_SIZE)
  398. return -EINVAL;
  399. /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
  400. new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
  401. ~VMXNET3_RING_SIZE_MASK;
  402. new_tx_ring_size = min_t(u32, new_tx_ring_size,
  403. VMXNET3_TX_RING_MAX_SIZE);
  404. if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
  405. VMXNET3_RING_SIZE_ALIGN) != 0)
  406. return -EINVAL;
  407. /* ring0 has to be a multiple of
  408. * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
  409. */
  410. sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
  411. new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
  412. new_rx_ring_size = min_t(u32, new_rx_ring_size,
  413. VMXNET3_RX_RING_MAX_SIZE / sz * sz);
  414. if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
  415. sz) != 0)
  416. return -EINVAL;
  417. if (new_tx_ring_size == adapter->tx_queue[0].tx_ring.size &&
  418. new_rx_ring_size == adapter->rx_queue[0].rx_ring[0].size) {
  419. return 0;
  420. }
  421. /*
  422. * Reset_work may be in the middle of resetting the device, wait for its
  423. * completion.
  424. */
  425. while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
  426. msleep(1);
  427. if (netif_running(netdev)) {
  428. vmxnet3_quiesce_dev(adapter);
  429. vmxnet3_reset_dev(adapter);
  430. /* recreate the rx queue and the tx queue based on the
  431. * new sizes */
  432. vmxnet3_tq_destroy_all(adapter);
  433. vmxnet3_rq_destroy_all(adapter);
  434. err = vmxnet3_create_queues(adapter, new_tx_ring_size,
  435. new_rx_ring_size, VMXNET3_DEF_RX_RING_SIZE);
  436. if (err) {
  437. /* failed, most likely because of OOM, try default
  438. * size */
  439. printk(KERN_ERR "%s: failed to apply new sizes, try the"
  440. " default ones\n", netdev->name);
  441. err = vmxnet3_create_queues(adapter,
  442. VMXNET3_DEF_TX_RING_SIZE,
  443. VMXNET3_DEF_RX_RING_SIZE,
  444. VMXNET3_DEF_RX_RING_SIZE);
  445. if (err) {
  446. printk(KERN_ERR "%s: failed to create queues "
  447. "with default sizes. Closing it\n",
  448. netdev->name);
  449. goto out;
  450. }
  451. }
  452. err = vmxnet3_activate_dev(adapter);
  453. if (err)
  454. printk(KERN_ERR "%s: failed to re-activate, error %d."
  455. " Closing it\n", netdev->name, err);
  456. }
  457. out:
  458. clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
  459. if (err)
  460. vmxnet3_force_close(adapter);
  461. return err;
  462. }
  463. static int
  464. vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
  465. void *rules)
  466. {
  467. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  468. switch (info->cmd) {
  469. case ETHTOOL_GRXRINGS:
  470. info->data = adapter->num_rx_queues;
  471. return 0;
  472. }
  473. return -EOPNOTSUPP;
  474. }
  475. #ifdef VMXNET3_RSS
  476. static int
  477. vmxnet3_get_rss_indir(struct net_device *netdev,
  478. struct ethtool_rxfh_indir *p)
  479. {
  480. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  481. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  482. unsigned int n = min_t(unsigned int, p->size, rssConf->indTableSize);
  483. p->size = rssConf->indTableSize;
  484. while (n--)
  485. p->ring_index[n] = rssConf->indTable[n];
  486. return 0;
  487. }
  488. static int
  489. vmxnet3_set_rss_indir(struct net_device *netdev,
  490. const struct ethtool_rxfh_indir *p)
  491. {
  492. unsigned int i;
  493. unsigned long flags;
  494. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  495. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  496. if (p->size != rssConf->indTableSize)
  497. return -EINVAL;
  498. for (i = 0; i < rssConf->indTableSize; i++) {
  499. /*
  500. * Return with error code if any of the queue indices
  501. * is out of range
  502. */
  503. if (p->ring_index[i] < 0 ||
  504. p->ring_index[i] >= adapter->num_rx_queues)
  505. return -EINVAL;
  506. }
  507. for (i = 0; i < rssConf->indTableSize; i++)
  508. rssConf->indTable[i] = p->ring_index[i];
  509. spin_lock_irqsave(&adapter->cmd_lock, flags);
  510. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  511. VMXNET3_CMD_UPDATE_RSSIDT);
  512. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  513. return 0;
  514. }
  515. #endif
  516. static struct ethtool_ops vmxnet3_ethtool_ops = {
  517. .get_settings = vmxnet3_get_settings,
  518. .get_drvinfo = vmxnet3_get_drvinfo,
  519. .get_regs_len = vmxnet3_get_regs_len,
  520. .get_regs = vmxnet3_get_regs,
  521. .get_wol = vmxnet3_get_wol,
  522. .set_wol = vmxnet3_set_wol,
  523. .get_link = ethtool_op_get_link,
  524. .get_strings = vmxnet3_get_strings,
  525. .get_sset_count = vmxnet3_get_sset_count,
  526. .get_ethtool_stats = vmxnet3_get_ethtool_stats,
  527. .get_ringparam = vmxnet3_get_ringparam,
  528. .set_ringparam = vmxnet3_set_ringparam,
  529. .get_rxnfc = vmxnet3_get_rxnfc,
  530. #ifdef VMXNET3_RSS
  531. .get_rxfh_indir = vmxnet3_get_rss_indir,
  532. .set_rxfh_indir = vmxnet3_set_rss_indir,
  533. #endif
  534. };
  535. void vmxnet3_set_ethtool_ops(struct net_device *netdev)
  536. {
  537. SET_ETHTOOL_OPS(netdev, &vmxnet3_ethtool_ops);
  538. }