vmxnet3_ethtool.c 27 KB

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