vmxnet3_ethtool.c 27 KB

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