vmxnet3_ethtool.c 19 KB

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