vmxnet3_ethtool.c 28 KB

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