/drivers/net/vmxnet3/vmxnet3_ethtool.c

http://github.com/mirrors/linux · C · 901 lines · 696 code · 135 blank · 70 comment · 101 complexity · 61d6ce344e6ca9bb73dc22ac312b31c7 MD5 · raw file

  1. /*
  2. * Linux driver for VMware's vmxnet3 ethernet NIC.
  3. *
  4. * Copyright (C) 2008-2016, 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: 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. void
  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. }
  147. static int
  148. vmxnet3_get_sset_count(struct net_device *netdev, int sset)
  149. {
  150. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  151. switch (sset) {
  152. case ETH_SS_STATS:
  153. return (ARRAY_SIZE(vmxnet3_tq_dev_stats) +
  154. ARRAY_SIZE(vmxnet3_tq_driver_stats)) *
  155. adapter->num_tx_queues +
  156. (ARRAY_SIZE(vmxnet3_rq_dev_stats) +
  157. ARRAY_SIZE(vmxnet3_rq_driver_stats)) *
  158. adapter->num_rx_queues +
  159. ARRAY_SIZE(vmxnet3_global_stats);
  160. default:
  161. return -EOPNOTSUPP;
  162. }
  163. }
  164. /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
  165. * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
  166. * Therefore, if any registers are added, removed or modified, then a version
  167. * bump and a corresponding change in the vmxnet3 support for ethtool(8)
  168. * --register-dump would be required.
  169. */
  170. static int
  171. vmxnet3_get_regs_len(struct net_device *netdev)
  172. {
  173. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  174. return ((9 /* BAR1 registers */ +
  175. (1 + adapter->intr.num_intrs) +
  176. (1 + adapter->num_tx_queues * 17 /* Tx queue registers */) +
  177. (1 + adapter->num_rx_queues * 23 /* Rx queue registers */)) *
  178. sizeof(u32));
  179. }
  180. static void
  181. vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  182. {
  183. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  184. strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver));
  185. strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
  186. sizeof(drvinfo->version));
  187. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  188. sizeof(drvinfo->bus_info));
  189. }
  190. static void
  191. vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
  192. {
  193. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  194. if (stringset == ETH_SS_STATS) {
  195. int i, j;
  196. for (j = 0; j < adapter->num_tx_queues; j++) {
  197. for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
  198. memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
  199. ETH_GSTRING_LEN);
  200. buf += ETH_GSTRING_LEN;
  201. }
  202. for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats);
  203. i++) {
  204. memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
  205. ETH_GSTRING_LEN);
  206. buf += ETH_GSTRING_LEN;
  207. }
  208. }
  209. for (j = 0; j < adapter->num_rx_queues; j++) {
  210. for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
  211. memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
  212. ETH_GSTRING_LEN);
  213. buf += ETH_GSTRING_LEN;
  214. }
  215. for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats);
  216. i++) {
  217. memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
  218. ETH_GSTRING_LEN);
  219. buf += ETH_GSTRING_LEN;
  220. }
  221. }
  222. for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
  223. memcpy(buf, vmxnet3_global_stats[i].desc,
  224. ETH_GSTRING_LEN);
  225. buf += ETH_GSTRING_LEN;
  226. }
  227. }
  228. }
  229. netdev_features_t vmxnet3_fix_features(struct net_device *netdev,
  230. netdev_features_t features)
  231. {
  232. /* If Rx checksum is disabled, then LRO should also be disabled */
  233. if (!(features & NETIF_F_RXCSUM))
  234. features &= ~NETIF_F_LRO;
  235. return features;
  236. }
  237. int vmxnet3_set_features(struct net_device *netdev, netdev_features_t features)
  238. {
  239. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  240. unsigned long flags;
  241. netdev_features_t changed = features ^ netdev->features;
  242. if (changed & (NETIF_F_RXCSUM | NETIF_F_LRO |
  243. NETIF_F_HW_VLAN_CTAG_RX)) {
  244. if (features & NETIF_F_RXCSUM)
  245. adapter->shared->devRead.misc.uptFeatures |=
  246. UPT1_F_RXCSUM;
  247. else
  248. adapter->shared->devRead.misc.uptFeatures &=
  249. ~UPT1_F_RXCSUM;
  250. /* update hardware LRO capability accordingly */
  251. if (features & NETIF_F_LRO)
  252. adapter->shared->devRead.misc.uptFeatures |=
  253. UPT1_F_LRO;
  254. else
  255. adapter->shared->devRead.misc.uptFeatures &=
  256. ~UPT1_F_LRO;
  257. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  258. adapter->shared->devRead.misc.uptFeatures |=
  259. UPT1_F_RXVLAN;
  260. else
  261. adapter->shared->devRead.misc.uptFeatures &=
  262. ~UPT1_F_RXVLAN;
  263. spin_lock_irqsave(&adapter->cmd_lock, flags);
  264. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  265. VMXNET3_CMD_UPDATE_FEATURE);
  266. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  267. }
  268. return 0;
  269. }
  270. static void
  271. vmxnet3_get_ethtool_stats(struct net_device *netdev,
  272. struct ethtool_stats *stats, u64 *buf)
  273. {
  274. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  275. unsigned long flags;
  276. u8 *base;
  277. int i;
  278. int j = 0;
  279. spin_lock_irqsave(&adapter->cmd_lock, flags);
  280. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
  281. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  282. /* this does assume each counter is 64-bit wide */
  283. for (j = 0; j < adapter->num_tx_queues; j++) {
  284. base = (u8 *)&adapter->tqd_start[j].stats;
  285. *buf++ = (u64)j;
  286. for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
  287. *buf++ = *(u64 *)(base +
  288. vmxnet3_tq_dev_stats[i].offset);
  289. base = (u8 *)&adapter->tx_queue[j].stats;
  290. for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
  291. *buf++ = *(u64 *)(base +
  292. vmxnet3_tq_driver_stats[i].offset);
  293. }
  294. for (j = 0; j < adapter->num_rx_queues; j++) {
  295. base = (u8 *)&adapter->rqd_start[j].stats;
  296. *buf++ = (u64) j;
  297. for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
  298. *buf++ = *(u64 *)(base +
  299. vmxnet3_rq_dev_stats[i].offset);
  300. base = (u8 *)&adapter->rx_queue[j].stats;
  301. for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
  302. *buf++ = *(u64 *)(base +
  303. vmxnet3_rq_driver_stats[i].offset);
  304. }
  305. base = (u8 *)adapter;
  306. for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
  307. *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
  308. }
  309. /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
  310. * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
  311. * Therefore, if any registers are added, removed or modified, then a version
  312. * bump and a corresponding change in the vmxnet3 support for ethtool(8)
  313. * --register-dump would be required.
  314. */
  315. static void
  316. vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
  317. {
  318. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  319. u32 *buf = p;
  320. int i = 0, j = 0;
  321. memset(p, 0, vmxnet3_get_regs_len(netdev));
  322. regs->version = 2;
  323. /* Update vmxnet3_get_regs_len if we want to dump more registers */
  324. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_VRRS);
  325. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_UVRS);
  326. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAL);
  327. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAH);
  328. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
  329. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACL);
  330. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACH);
  331. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ICR);
  332. buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ECR);
  333. buf[j++] = adapter->intr.num_intrs;
  334. for (i = 0; i < adapter->intr.num_intrs; i++) {
  335. buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_IMR
  336. + i * VMXNET3_REG_ALIGN);
  337. }
  338. buf[j++] = adapter->num_tx_queues;
  339. for (i = 0; i < adapter->num_tx_queues; i++) {
  340. struct vmxnet3_tx_queue *tq = &adapter->tx_queue[i];
  341. buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_TXPROD +
  342. i * VMXNET3_REG_ALIGN);
  343. buf[j++] = VMXNET3_GET_ADDR_LO(tq->tx_ring.basePA);
  344. buf[j++] = VMXNET3_GET_ADDR_HI(tq->tx_ring.basePA);
  345. buf[j++] = tq->tx_ring.size;
  346. buf[j++] = tq->tx_ring.next2fill;
  347. buf[j++] = tq->tx_ring.next2comp;
  348. buf[j++] = tq->tx_ring.gen;
  349. buf[j++] = VMXNET3_GET_ADDR_LO(tq->data_ring.basePA);
  350. buf[j++] = VMXNET3_GET_ADDR_HI(tq->data_ring.basePA);
  351. buf[j++] = tq->data_ring.size;
  352. buf[j++] = tq->txdata_desc_size;
  353. buf[j++] = VMXNET3_GET_ADDR_LO(tq->comp_ring.basePA);
  354. buf[j++] = VMXNET3_GET_ADDR_HI(tq->comp_ring.basePA);
  355. buf[j++] = tq->comp_ring.size;
  356. buf[j++] = tq->comp_ring.next2proc;
  357. buf[j++] = tq->comp_ring.gen;
  358. buf[j++] = tq->stopped;
  359. }
  360. buf[j++] = adapter->num_rx_queues;
  361. for (i = 0; i < adapter->num_rx_queues; i++) {
  362. struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i];
  363. buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD +
  364. i * VMXNET3_REG_ALIGN);
  365. buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD2 +
  366. i * VMXNET3_REG_ALIGN);
  367. buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[0].basePA);
  368. buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[0].basePA);
  369. buf[j++] = rq->rx_ring[0].size;
  370. buf[j++] = rq->rx_ring[0].next2fill;
  371. buf[j++] = rq->rx_ring[0].next2comp;
  372. buf[j++] = rq->rx_ring[0].gen;
  373. buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[1].basePA);
  374. buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[1].basePA);
  375. buf[j++] = rq->rx_ring[1].size;
  376. buf[j++] = rq->rx_ring[1].next2fill;
  377. buf[j++] = rq->rx_ring[1].next2comp;
  378. buf[j++] = rq->rx_ring[1].gen;
  379. buf[j++] = VMXNET3_GET_ADDR_LO(rq->data_ring.basePA);
  380. buf[j++] = VMXNET3_GET_ADDR_HI(rq->data_ring.basePA);
  381. buf[j++] = rq->rx_ring[0].size;
  382. buf[j++] = rq->data_ring.desc_size;
  383. buf[j++] = VMXNET3_GET_ADDR_LO(rq->comp_ring.basePA);
  384. buf[j++] = VMXNET3_GET_ADDR_HI(rq->comp_ring.basePA);
  385. buf[j++] = rq->comp_ring.size;
  386. buf[j++] = rq->comp_ring.next2proc;
  387. buf[j++] = rq->comp_ring.gen;
  388. }
  389. }
  390. static void
  391. vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  392. {
  393. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  394. wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
  395. wol->wolopts = adapter->wol;
  396. }
  397. static int
  398. vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  399. {
  400. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  401. if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
  402. WAKE_MAGICSECURE)) {
  403. return -EOPNOTSUPP;
  404. }
  405. adapter->wol = wol->wolopts;
  406. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  407. return 0;
  408. }
  409. static int
  410. vmxnet3_get_link_ksettings(struct net_device *netdev,
  411. struct ethtool_link_ksettings *ecmd)
  412. {
  413. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  414. ethtool_link_ksettings_zero_link_mode(ecmd, supported);
  415. ethtool_link_ksettings_add_link_mode(ecmd, supported, 10000baseT_Full);
  416. ethtool_link_ksettings_add_link_mode(ecmd, supported, 1000baseT_Full);
  417. ethtool_link_ksettings_add_link_mode(ecmd, supported, TP);
  418. ethtool_link_ksettings_zero_link_mode(ecmd, advertising);
  419. ethtool_link_ksettings_add_link_mode(ecmd, advertising, TP);
  420. ecmd->base.port = PORT_TP;
  421. if (adapter->link_speed) {
  422. ecmd->base.speed = adapter->link_speed;
  423. ecmd->base.duplex = DUPLEX_FULL;
  424. } else {
  425. ecmd->base.speed = SPEED_UNKNOWN;
  426. ecmd->base.duplex = DUPLEX_UNKNOWN;
  427. }
  428. return 0;
  429. }
  430. static void
  431. vmxnet3_get_ringparam(struct net_device *netdev,
  432. struct ethtool_ringparam *param)
  433. {
  434. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  435. param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
  436. param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
  437. param->rx_mini_max_pending = VMXNET3_VERSION_GE_3(adapter) ?
  438. VMXNET3_RXDATA_DESC_MAX_SIZE : 0;
  439. param->rx_jumbo_max_pending = VMXNET3_RX_RING2_MAX_SIZE;
  440. param->rx_pending = adapter->rx_ring_size;
  441. param->tx_pending = adapter->tx_ring_size;
  442. param->rx_mini_pending = VMXNET3_VERSION_GE_3(adapter) ?
  443. adapter->rxdata_desc_size : 0;
  444. param->rx_jumbo_pending = adapter->rx_ring2_size;
  445. }
  446. static int
  447. vmxnet3_set_ringparam(struct net_device *netdev,
  448. struct ethtool_ringparam *param)
  449. {
  450. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  451. u32 new_tx_ring_size, new_rx_ring_size, new_rx_ring2_size;
  452. u16 new_rxdata_desc_size;
  453. u32 sz;
  454. int err = 0;
  455. if (param->tx_pending == 0 || param->tx_pending >
  456. VMXNET3_TX_RING_MAX_SIZE)
  457. return -EINVAL;
  458. if (param->rx_pending == 0 || param->rx_pending >
  459. VMXNET3_RX_RING_MAX_SIZE)
  460. return -EINVAL;
  461. if (param->rx_jumbo_pending == 0 ||
  462. param->rx_jumbo_pending > VMXNET3_RX_RING2_MAX_SIZE)
  463. return -EINVAL;
  464. /* if adapter not yet initialized, do nothing */
  465. if (adapter->rx_buf_per_pkt == 0) {
  466. netdev_err(netdev, "adapter not completely initialized, "
  467. "ring size cannot be changed yet\n");
  468. return -EOPNOTSUPP;
  469. }
  470. if (VMXNET3_VERSION_GE_3(adapter)) {
  471. if (param->rx_mini_pending > VMXNET3_RXDATA_DESC_MAX_SIZE)
  472. return -EINVAL;
  473. } else if (param->rx_mini_pending != 0) {
  474. return -EINVAL;
  475. }
  476. /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
  477. new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
  478. ~VMXNET3_RING_SIZE_MASK;
  479. new_tx_ring_size = min_t(u32, new_tx_ring_size,
  480. VMXNET3_TX_RING_MAX_SIZE);
  481. if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
  482. VMXNET3_RING_SIZE_ALIGN) != 0)
  483. return -EINVAL;
  484. /* ring0 has to be a multiple of
  485. * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
  486. */
  487. sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
  488. new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
  489. new_rx_ring_size = min_t(u32, new_rx_ring_size,
  490. VMXNET3_RX_RING_MAX_SIZE / sz * sz);
  491. if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
  492. sz) != 0)
  493. return -EINVAL;
  494. /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
  495. new_rx_ring2_size = (param->rx_jumbo_pending + VMXNET3_RING_SIZE_MASK) &
  496. ~VMXNET3_RING_SIZE_MASK;
  497. new_rx_ring2_size = min_t(u32, new_rx_ring2_size,
  498. VMXNET3_RX_RING2_MAX_SIZE);
  499. /* rx data ring buffer size has to be a multiple of
  500. * VMXNET3_RXDATA_DESC_SIZE_ALIGN
  501. */
  502. new_rxdata_desc_size =
  503. (param->rx_mini_pending + VMXNET3_RXDATA_DESC_SIZE_MASK) &
  504. ~VMXNET3_RXDATA_DESC_SIZE_MASK;
  505. new_rxdata_desc_size = min_t(u16, new_rxdata_desc_size,
  506. VMXNET3_RXDATA_DESC_MAX_SIZE);
  507. if (new_tx_ring_size == adapter->tx_ring_size &&
  508. new_rx_ring_size == adapter->rx_ring_size &&
  509. new_rx_ring2_size == adapter->rx_ring2_size &&
  510. new_rxdata_desc_size == adapter->rxdata_desc_size) {
  511. return 0;
  512. }
  513. /*
  514. * Reset_work may be in the middle of resetting the device, wait for its
  515. * completion.
  516. */
  517. while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
  518. usleep_range(1000, 2000);
  519. if (netif_running(netdev)) {
  520. vmxnet3_quiesce_dev(adapter);
  521. vmxnet3_reset_dev(adapter);
  522. /* recreate the rx queue and the tx queue based on the
  523. * new sizes */
  524. vmxnet3_tq_destroy_all(adapter);
  525. vmxnet3_rq_destroy_all(adapter);
  526. err = vmxnet3_create_queues(adapter, new_tx_ring_size,
  527. new_rx_ring_size, new_rx_ring2_size,
  528. adapter->txdata_desc_size,
  529. new_rxdata_desc_size);
  530. if (err) {
  531. /* failed, most likely because of OOM, try default
  532. * size */
  533. netdev_err(netdev, "failed to apply new sizes, "
  534. "try the default ones\n");
  535. new_rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;
  536. new_rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;
  537. new_tx_ring_size = VMXNET3_DEF_TX_RING_SIZE;
  538. new_rxdata_desc_size = VMXNET3_VERSION_GE_3(adapter) ?
  539. VMXNET3_DEF_RXDATA_DESC_SIZE : 0;
  540. err = vmxnet3_create_queues(adapter,
  541. new_tx_ring_size,
  542. new_rx_ring_size,
  543. new_rx_ring2_size,
  544. adapter->txdata_desc_size,
  545. new_rxdata_desc_size);
  546. if (err) {
  547. netdev_err(netdev, "failed to create queues "
  548. "with default sizes. Closing it\n");
  549. goto out;
  550. }
  551. }
  552. err = vmxnet3_activate_dev(adapter);
  553. if (err)
  554. netdev_err(netdev, "failed to re-activate, error %d."
  555. " Closing it\n", err);
  556. }
  557. adapter->tx_ring_size = new_tx_ring_size;
  558. adapter->rx_ring_size = new_rx_ring_size;
  559. adapter->rx_ring2_size = new_rx_ring2_size;
  560. adapter->rxdata_desc_size = new_rxdata_desc_size;
  561. out:
  562. clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
  563. if (err)
  564. vmxnet3_force_close(adapter);
  565. return err;
  566. }
  567. static int
  568. vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
  569. u32 *rules)
  570. {
  571. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  572. switch (info->cmd) {
  573. case ETHTOOL_GRXRINGS:
  574. info->data = adapter->num_rx_queues;
  575. return 0;
  576. }
  577. return -EOPNOTSUPP;
  578. }
  579. #ifdef VMXNET3_RSS
  580. static u32
  581. vmxnet3_get_rss_indir_size(struct net_device *netdev)
  582. {
  583. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  584. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  585. return rssConf->indTableSize;
  586. }
  587. static int
  588. vmxnet3_get_rss(struct net_device *netdev, u32 *p, u8 *key, u8 *hfunc)
  589. {
  590. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  591. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  592. unsigned int n = rssConf->indTableSize;
  593. if (hfunc)
  594. *hfunc = ETH_RSS_HASH_TOP;
  595. if (!p)
  596. return 0;
  597. while (n--)
  598. p[n] = rssConf->indTable[n];
  599. return 0;
  600. }
  601. static int
  602. vmxnet3_set_rss(struct net_device *netdev, const u32 *p, const u8 *key,
  603. const u8 hfunc)
  604. {
  605. unsigned int i;
  606. unsigned long flags;
  607. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  608. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  609. /* We do not allow change in unsupported parameters */
  610. if (key ||
  611. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  612. return -EOPNOTSUPP;
  613. if (!p)
  614. return 0;
  615. for (i = 0; i < rssConf->indTableSize; i++)
  616. rssConf->indTable[i] = p[i];
  617. spin_lock_irqsave(&adapter->cmd_lock, flags);
  618. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  619. VMXNET3_CMD_UPDATE_RSSIDT);
  620. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  621. return 0;
  622. }
  623. #endif
  624. static int
  625. vmxnet3_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
  626. {
  627. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  628. if (!VMXNET3_VERSION_GE_3(adapter))
  629. return -EOPNOTSUPP;
  630. switch (adapter->coal_conf->coalMode) {
  631. case VMXNET3_COALESCE_DISABLED:
  632. /* struct ethtool_coalesce is already initialized to 0 */
  633. break;
  634. case VMXNET3_COALESCE_ADAPT:
  635. ec->use_adaptive_rx_coalesce = true;
  636. break;
  637. case VMXNET3_COALESCE_STATIC:
  638. ec->tx_max_coalesced_frames =
  639. adapter->coal_conf->coalPara.coalStatic.tx_comp_depth;
  640. ec->rx_max_coalesced_frames =
  641. adapter->coal_conf->coalPara.coalStatic.rx_depth;
  642. break;
  643. case VMXNET3_COALESCE_RBC: {
  644. u32 rbc_rate;
  645. rbc_rate = adapter->coal_conf->coalPara.coalRbc.rbc_rate;
  646. ec->rx_coalesce_usecs = VMXNET3_COAL_RBC_USECS(rbc_rate);
  647. }
  648. break;
  649. default:
  650. return -EOPNOTSUPP;
  651. }
  652. return 0;
  653. }
  654. static int
  655. vmxnet3_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
  656. {
  657. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  658. struct Vmxnet3_DriverShared *shared = adapter->shared;
  659. union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo;
  660. unsigned long flags;
  661. if (!VMXNET3_VERSION_GE_3(adapter))
  662. return -EOPNOTSUPP;
  663. if ((ec->rx_coalesce_usecs == 0) &&
  664. (ec->use_adaptive_rx_coalesce == 0) &&
  665. (ec->tx_max_coalesced_frames == 0) &&
  666. (ec->rx_max_coalesced_frames == 0)) {
  667. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  668. adapter->coal_conf->coalMode = VMXNET3_COALESCE_DISABLED;
  669. goto done;
  670. }
  671. if (ec->rx_coalesce_usecs != 0) {
  672. u32 rbc_rate;
  673. if ((ec->use_adaptive_rx_coalesce != 0) ||
  674. (ec->tx_max_coalesced_frames != 0) ||
  675. (ec->rx_max_coalesced_frames != 0)) {
  676. return -EINVAL;
  677. }
  678. rbc_rate = VMXNET3_COAL_RBC_RATE(ec->rx_coalesce_usecs);
  679. if (rbc_rate < VMXNET3_COAL_RBC_MIN_RATE ||
  680. rbc_rate > VMXNET3_COAL_RBC_MAX_RATE) {
  681. return -EINVAL;
  682. }
  683. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  684. adapter->coal_conf->coalMode = VMXNET3_COALESCE_RBC;
  685. adapter->coal_conf->coalPara.coalRbc.rbc_rate = rbc_rate;
  686. goto done;
  687. }
  688. if (ec->use_adaptive_rx_coalesce != 0) {
  689. if ((ec->rx_coalesce_usecs != 0) ||
  690. (ec->tx_max_coalesced_frames != 0) ||
  691. (ec->rx_max_coalesced_frames != 0)) {
  692. return -EINVAL;
  693. }
  694. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  695. adapter->coal_conf->coalMode = VMXNET3_COALESCE_ADAPT;
  696. goto done;
  697. }
  698. if ((ec->tx_max_coalesced_frames != 0) ||
  699. (ec->rx_max_coalesced_frames != 0)) {
  700. if ((ec->rx_coalesce_usecs != 0) ||
  701. (ec->use_adaptive_rx_coalesce != 0)) {
  702. return -EINVAL;
  703. }
  704. if ((ec->tx_max_coalesced_frames >
  705. VMXNET3_COAL_STATIC_MAX_DEPTH) ||
  706. (ec->rx_max_coalesced_frames >
  707. VMXNET3_COAL_STATIC_MAX_DEPTH)) {
  708. return -EINVAL;
  709. }
  710. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  711. adapter->coal_conf->coalMode = VMXNET3_COALESCE_STATIC;
  712. adapter->coal_conf->coalPara.coalStatic.tx_comp_depth =
  713. (ec->tx_max_coalesced_frames ?
  714. ec->tx_max_coalesced_frames :
  715. VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
  716. adapter->coal_conf->coalPara.coalStatic.rx_depth =
  717. (ec->rx_max_coalesced_frames ?
  718. ec->rx_max_coalesced_frames :
  719. VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
  720. adapter->coal_conf->coalPara.coalStatic.tx_depth =
  721. VMXNET3_COAL_STATIC_DEFAULT_DEPTH;
  722. goto done;
  723. }
  724. done:
  725. adapter->default_coal_mode = false;
  726. if (netif_running(netdev)) {
  727. spin_lock_irqsave(&adapter->cmd_lock, flags);
  728. cmdInfo->varConf.confVer = 1;
  729. cmdInfo->varConf.confLen =
  730. cpu_to_le32(sizeof(*adapter->coal_conf));
  731. cmdInfo->varConf.confPA = cpu_to_le64(adapter->coal_conf_pa);
  732. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  733. VMXNET3_CMD_SET_COALESCE);
  734. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  735. }
  736. return 0;
  737. }
  738. static const struct ethtool_ops vmxnet3_ethtool_ops = {
  739. .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
  740. ETHTOOL_COALESCE_MAX_FRAMES |
  741. ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
  742. .get_drvinfo = vmxnet3_get_drvinfo,
  743. .get_regs_len = vmxnet3_get_regs_len,
  744. .get_regs = vmxnet3_get_regs,
  745. .get_wol = vmxnet3_get_wol,
  746. .set_wol = vmxnet3_set_wol,
  747. .get_link = ethtool_op_get_link,
  748. .get_coalesce = vmxnet3_get_coalesce,
  749. .set_coalesce = vmxnet3_set_coalesce,
  750. .get_strings = vmxnet3_get_strings,
  751. .get_sset_count = vmxnet3_get_sset_count,
  752. .get_ethtool_stats = vmxnet3_get_ethtool_stats,
  753. .get_ringparam = vmxnet3_get_ringparam,
  754. .set_ringparam = vmxnet3_set_ringparam,
  755. .get_rxnfc = vmxnet3_get_rxnfc,
  756. #ifdef VMXNET3_RSS
  757. .get_rxfh_indir_size = vmxnet3_get_rss_indir_size,
  758. .get_rxfh = vmxnet3_get_rss,
  759. .set_rxfh = vmxnet3_set_rss,
  760. #endif
  761. .get_link_ksettings = vmxnet3_get_link_ksettings,
  762. };
  763. void vmxnet3_set_ethtool_ops(struct net_device *netdev)
  764. {
  765. netdev->ethtool_ops = &vmxnet3_ethtool_ops;
  766. }