vmxnet3_ethtool.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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 < 0 ||
  472. param->rx_mini_pending > VMXNET3_RXDATA_DESC_MAX_SIZE) {
  473. return -EINVAL;
  474. }
  475. } else if (param->rx_mini_pending != 0) {
  476. return -EINVAL;
  477. }
  478. /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
  479. new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
  480. ~VMXNET3_RING_SIZE_MASK;
  481. new_tx_ring_size = min_t(u32, new_tx_ring_size,
  482. VMXNET3_TX_RING_MAX_SIZE);
  483. if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
  484. VMXNET3_RING_SIZE_ALIGN) != 0)
  485. return -EINVAL;
  486. /* ring0 has to be a multiple of
  487. * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
  488. */
  489. sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
  490. new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
  491. new_rx_ring_size = min_t(u32, new_rx_ring_size,
  492. VMXNET3_RX_RING_MAX_SIZE / sz * sz);
  493. if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
  494. sz) != 0)
  495. return -EINVAL;
  496. /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
  497. new_rx_ring2_size = (param->rx_jumbo_pending + VMXNET3_RING_SIZE_MASK) &
  498. ~VMXNET3_RING_SIZE_MASK;
  499. new_rx_ring2_size = min_t(u32, new_rx_ring2_size,
  500. VMXNET3_RX_RING2_MAX_SIZE);
  501. /* rx data ring buffer size has to be a multiple of
  502. * VMXNET3_RXDATA_DESC_SIZE_ALIGN
  503. */
  504. new_rxdata_desc_size =
  505. (param->rx_mini_pending + VMXNET3_RXDATA_DESC_SIZE_MASK) &
  506. ~VMXNET3_RXDATA_DESC_SIZE_MASK;
  507. new_rxdata_desc_size = min_t(u16, new_rxdata_desc_size,
  508. VMXNET3_RXDATA_DESC_MAX_SIZE);
  509. if (new_tx_ring_size == adapter->tx_ring_size &&
  510. new_rx_ring_size == adapter->rx_ring_size &&
  511. new_rx_ring2_size == adapter->rx_ring2_size &&
  512. new_rxdata_desc_size == adapter->rxdata_desc_size) {
  513. return 0;
  514. }
  515. /*
  516. * Reset_work may be in the middle of resetting the device, wait for its
  517. * completion.
  518. */
  519. while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
  520. usleep_range(1000, 2000);
  521. if (netif_running(netdev)) {
  522. vmxnet3_quiesce_dev(adapter);
  523. vmxnet3_reset_dev(adapter);
  524. /* recreate the rx queue and the tx queue based on the
  525. * new sizes */
  526. vmxnet3_tq_destroy_all(adapter);
  527. vmxnet3_rq_destroy_all(adapter);
  528. err = vmxnet3_create_queues(adapter, new_tx_ring_size,
  529. new_rx_ring_size, new_rx_ring2_size,
  530. adapter->txdata_desc_size,
  531. new_rxdata_desc_size);
  532. if (err) {
  533. /* failed, most likely because of OOM, try default
  534. * size */
  535. netdev_err(netdev, "failed to apply new sizes, "
  536. "try the default ones\n");
  537. new_rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;
  538. new_rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;
  539. new_tx_ring_size = VMXNET3_DEF_TX_RING_SIZE;
  540. new_rxdata_desc_size = VMXNET3_VERSION_GE_3(adapter) ?
  541. VMXNET3_DEF_RXDATA_DESC_SIZE : 0;
  542. err = vmxnet3_create_queues(adapter,
  543. new_tx_ring_size,
  544. new_rx_ring_size,
  545. new_rx_ring2_size,
  546. adapter->txdata_desc_size,
  547. new_rxdata_desc_size);
  548. if (err) {
  549. netdev_err(netdev, "failed to create queues "
  550. "with default sizes. Closing it\n");
  551. goto out;
  552. }
  553. }
  554. err = vmxnet3_activate_dev(adapter);
  555. if (err)
  556. netdev_err(netdev, "failed to re-activate, error %d."
  557. " Closing it\n", err);
  558. }
  559. adapter->tx_ring_size = new_tx_ring_size;
  560. adapter->rx_ring_size = new_rx_ring_size;
  561. adapter->rx_ring2_size = new_rx_ring2_size;
  562. adapter->rxdata_desc_size = new_rxdata_desc_size;
  563. out:
  564. clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
  565. if (err)
  566. vmxnet3_force_close(adapter);
  567. return err;
  568. }
  569. static int
  570. vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
  571. u32 *rules)
  572. {
  573. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  574. switch (info->cmd) {
  575. case ETHTOOL_GRXRINGS:
  576. info->data = adapter->num_rx_queues;
  577. return 0;
  578. }
  579. return -EOPNOTSUPP;
  580. }
  581. #ifdef VMXNET3_RSS
  582. static u32
  583. vmxnet3_get_rss_indir_size(struct net_device *netdev)
  584. {
  585. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  586. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  587. return rssConf->indTableSize;
  588. }
  589. static int
  590. vmxnet3_get_rss(struct net_device *netdev, u32 *p, u8 *key, u8 *hfunc)
  591. {
  592. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  593. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  594. unsigned int n = rssConf->indTableSize;
  595. if (hfunc)
  596. *hfunc = ETH_RSS_HASH_TOP;
  597. if (!p)
  598. return 0;
  599. if (n > UPT1_RSS_MAX_IND_TABLE_SIZE)
  600. return 0;
  601. while (n--)
  602. p[n] = rssConf->indTable[n];
  603. return 0;
  604. }
  605. static int
  606. vmxnet3_set_rss(struct net_device *netdev, const u32 *p, const u8 *key,
  607. const u8 hfunc)
  608. {
  609. unsigned int i;
  610. unsigned long flags;
  611. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  612. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  613. /* We do not allow change in unsupported parameters */
  614. if (key ||
  615. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  616. return -EOPNOTSUPP;
  617. if (!p)
  618. return 0;
  619. for (i = 0; i < rssConf->indTableSize; i++)
  620. rssConf->indTable[i] = p[i];
  621. spin_lock_irqsave(&adapter->cmd_lock, flags);
  622. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  623. VMXNET3_CMD_UPDATE_RSSIDT);
  624. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  625. return 0;
  626. }
  627. #endif
  628. static int
  629. vmxnet3_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
  630. {
  631. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  632. if (!VMXNET3_VERSION_GE_3(adapter))
  633. return -EOPNOTSUPP;
  634. switch (adapter->coal_conf->coalMode) {
  635. case VMXNET3_COALESCE_DISABLED:
  636. /* struct ethtool_coalesce is already initialized to 0 */
  637. break;
  638. case VMXNET3_COALESCE_ADAPT:
  639. ec->use_adaptive_rx_coalesce = true;
  640. break;
  641. case VMXNET3_COALESCE_STATIC:
  642. ec->tx_max_coalesced_frames =
  643. adapter->coal_conf->coalPara.coalStatic.tx_comp_depth;
  644. ec->rx_max_coalesced_frames =
  645. adapter->coal_conf->coalPara.coalStatic.rx_depth;
  646. break;
  647. case VMXNET3_COALESCE_RBC: {
  648. u32 rbc_rate;
  649. rbc_rate = adapter->coal_conf->coalPara.coalRbc.rbc_rate;
  650. ec->rx_coalesce_usecs = VMXNET3_COAL_RBC_USECS(rbc_rate);
  651. }
  652. break;
  653. default:
  654. return -EOPNOTSUPP;
  655. }
  656. return 0;
  657. }
  658. static int
  659. vmxnet3_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
  660. {
  661. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  662. struct Vmxnet3_DriverShared *shared = adapter->shared;
  663. union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo;
  664. unsigned long flags;
  665. if (!VMXNET3_VERSION_GE_3(adapter))
  666. return -EOPNOTSUPP;
  667. if (ec->rx_coalesce_usecs_irq ||
  668. ec->rx_max_coalesced_frames_irq ||
  669. ec->tx_coalesce_usecs ||
  670. ec->tx_coalesce_usecs_irq ||
  671. ec->tx_max_coalesced_frames_irq ||
  672. ec->stats_block_coalesce_usecs ||
  673. ec->use_adaptive_tx_coalesce ||
  674. ec->pkt_rate_low ||
  675. ec->rx_coalesce_usecs_low ||
  676. ec->rx_max_coalesced_frames_low ||
  677. ec->tx_coalesce_usecs_low ||
  678. ec->tx_max_coalesced_frames_low ||
  679. ec->pkt_rate_high ||
  680. ec->rx_coalesce_usecs_high ||
  681. ec->rx_max_coalesced_frames_high ||
  682. ec->tx_coalesce_usecs_high ||
  683. ec->tx_max_coalesced_frames_high ||
  684. ec->rate_sample_interval) {
  685. return -EINVAL;
  686. }
  687. if ((ec->rx_coalesce_usecs == 0) &&
  688. (ec->use_adaptive_rx_coalesce == 0) &&
  689. (ec->tx_max_coalesced_frames == 0) &&
  690. (ec->rx_max_coalesced_frames == 0)) {
  691. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  692. adapter->coal_conf->coalMode = VMXNET3_COALESCE_DISABLED;
  693. goto done;
  694. }
  695. if (ec->rx_coalesce_usecs != 0) {
  696. u32 rbc_rate;
  697. if ((ec->use_adaptive_rx_coalesce != 0) ||
  698. (ec->tx_max_coalesced_frames != 0) ||
  699. (ec->rx_max_coalesced_frames != 0)) {
  700. return -EINVAL;
  701. }
  702. rbc_rate = VMXNET3_COAL_RBC_RATE(ec->rx_coalesce_usecs);
  703. if (rbc_rate < VMXNET3_COAL_RBC_MIN_RATE ||
  704. rbc_rate > VMXNET3_COAL_RBC_MAX_RATE) {
  705. return -EINVAL;
  706. }
  707. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  708. adapter->coal_conf->coalMode = VMXNET3_COALESCE_RBC;
  709. adapter->coal_conf->coalPara.coalRbc.rbc_rate = rbc_rate;
  710. goto done;
  711. }
  712. if (ec->use_adaptive_rx_coalesce != 0) {
  713. if ((ec->rx_coalesce_usecs != 0) ||
  714. (ec->tx_max_coalesced_frames != 0) ||
  715. (ec->rx_max_coalesced_frames != 0)) {
  716. return -EINVAL;
  717. }
  718. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  719. adapter->coal_conf->coalMode = VMXNET3_COALESCE_ADAPT;
  720. goto done;
  721. }
  722. if ((ec->tx_max_coalesced_frames != 0) ||
  723. (ec->rx_max_coalesced_frames != 0)) {
  724. if ((ec->rx_coalesce_usecs != 0) ||
  725. (ec->use_adaptive_rx_coalesce != 0)) {
  726. return -EINVAL;
  727. }
  728. if ((ec->tx_max_coalesced_frames >
  729. VMXNET3_COAL_STATIC_MAX_DEPTH) ||
  730. (ec->rx_max_coalesced_frames >
  731. VMXNET3_COAL_STATIC_MAX_DEPTH)) {
  732. return -EINVAL;
  733. }
  734. memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
  735. adapter->coal_conf->coalMode = VMXNET3_COALESCE_STATIC;
  736. adapter->coal_conf->coalPara.coalStatic.tx_comp_depth =
  737. (ec->tx_max_coalesced_frames ?
  738. ec->tx_max_coalesced_frames :
  739. VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
  740. adapter->coal_conf->coalPara.coalStatic.rx_depth =
  741. (ec->rx_max_coalesced_frames ?
  742. ec->rx_max_coalesced_frames :
  743. VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
  744. adapter->coal_conf->coalPara.coalStatic.tx_depth =
  745. VMXNET3_COAL_STATIC_DEFAULT_DEPTH;
  746. goto done;
  747. }
  748. done:
  749. adapter->default_coal_mode = false;
  750. if (netif_running(netdev)) {
  751. spin_lock_irqsave(&adapter->cmd_lock, flags);
  752. cmdInfo->varConf.confVer = 1;
  753. cmdInfo->varConf.confLen =
  754. cpu_to_le32(sizeof(*adapter->coal_conf));
  755. cmdInfo->varConf.confPA = cpu_to_le64(adapter->coal_conf_pa);
  756. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  757. VMXNET3_CMD_SET_COALESCE);
  758. spin_unlock_irqrestore(&adapter->cmd_lock, flags);
  759. }
  760. return 0;
  761. }
  762. static const struct ethtool_ops vmxnet3_ethtool_ops = {
  763. .get_drvinfo = vmxnet3_get_drvinfo,
  764. .get_regs_len = vmxnet3_get_regs_len,
  765. .get_regs = vmxnet3_get_regs,
  766. .get_wol = vmxnet3_get_wol,
  767. .set_wol = vmxnet3_set_wol,
  768. .get_link = ethtool_op_get_link,
  769. .get_coalesce = vmxnet3_get_coalesce,
  770. .set_coalesce = vmxnet3_set_coalesce,
  771. .get_strings = vmxnet3_get_strings,
  772. .get_sset_count = vmxnet3_get_sset_count,
  773. .get_ethtool_stats = vmxnet3_get_ethtool_stats,
  774. .get_ringparam = vmxnet3_get_ringparam,
  775. .set_ringparam = vmxnet3_set_ringparam,
  776. .get_rxnfc = vmxnet3_get_rxnfc,
  777. #ifdef VMXNET3_RSS
  778. .get_rxfh_indir_size = vmxnet3_get_rss_indir_size,
  779. .get_rxfh = vmxnet3_get_rss,
  780. .set_rxfh = vmxnet3_set_rss,
  781. #endif
  782. .get_link_ksettings = vmxnet3_get_link_ksettings,
  783. };
  784. void vmxnet3_set_ethtool_ops(struct net_device *netdev)
  785. {
  786. netdev->ethtool_ops = &vmxnet3_ethtool_ops;
  787. }