vmxnet3_ethtool.c 19 KB

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