vmxnet3_ethtool.c 20 KB

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