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