fm10k_ethtool.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. /* Intel Ethernet Switch Host Interface Driver
  2. * Copyright(c) 2013 - 2015 Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. * Contact Information:
  17. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. */
  20. #include <linux/vmalloc.h>
  21. #include "fm10k.h"
  22. struct fm10k_stats {
  23. char stat_string[ETH_GSTRING_LEN];
  24. int sizeof_stat;
  25. int stat_offset;
  26. };
  27. #define FM10K_NETDEV_STAT(_net_stat) { \
  28. .stat_string = #_net_stat, \
  29. .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
  30. .stat_offset = offsetof(struct net_device_stats, _net_stat) \
  31. }
  32. static const struct fm10k_stats fm10k_gstrings_net_stats[] = {
  33. FM10K_NETDEV_STAT(tx_packets),
  34. FM10K_NETDEV_STAT(tx_bytes),
  35. FM10K_NETDEV_STAT(tx_errors),
  36. FM10K_NETDEV_STAT(rx_packets),
  37. FM10K_NETDEV_STAT(rx_bytes),
  38. FM10K_NETDEV_STAT(rx_errors),
  39. FM10K_NETDEV_STAT(rx_dropped),
  40. /* detailed Rx errors */
  41. FM10K_NETDEV_STAT(rx_length_errors),
  42. FM10K_NETDEV_STAT(rx_crc_errors),
  43. FM10K_NETDEV_STAT(rx_fifo_errors),
  44. };
  45. #define FM10K_NETDEV_STATS_LEN ARRAY_SIZE(fm10k_gstrings_net_stats)
  46. #define FM10K_STAT(_name, _stat) { \
  47. .stat_string = _name, \
  48. .sizeof_stat = FIELD_SIZEOF(struct fm10k_intfc, _stat), \
  49. .stat_offset = offsetof(struct fm10k_intfc, _stat) \
  50. }
  51. static const struct fm10k_stats fm10k_gstrings_global_stats[] = {
  52. FM10K_STAT("tx_restart_queue", restart_queue),
  53. FM10K_STAT("tx_busy", tx_busy),
  54. FM10K_STAT("tx_csum_errors", tx_csum_errors),
  55. FM10K_STAT("rx_alloc_failed", alloc_failed),
  56. FM10K_STAT("rx_csum_errors", rx_csum_errors),
  57. FM10K_STAT("tx_packets_nic", tx_packets_nic),
  58. FM10K_STAT("tx_bytes_nic", tx_bytes_nic),
  59. FM10K_STAT("rx_packets_nic", rx_packets_nic),
  60. FM10K_STAT("rx_bytes_nic", rx_bytes_nic),
  61. FM10K_STAT("rx_drops_nic", rx_drops_nic),
  62. FM10K_STAT("rx_overrun_pf", rx_overrun_pf),
  63. FM10K_STAT("rx_overrun_vf", rx_overrun_vf),
  64. FM10K_STAT("swapi_status", hw.swapi.status),
  65. FM10K_STAT("mac_rules_used", hw.swapi.mac.used),
  66. FM10K_STAT("mac_rules_avail", hw.swapi.mac.avail),
  67. FM10K_STAT("mbx_tx_busy", hw.mbx.tx_busy),
  68. FM10K_STAT("mbx_tx_oversized", hw.mbx.tx_dropped),
  69. FM10K_STAT("mbx_tx_messages", hw.mbx.tx_messages),
  70. FM10K_STAT("mbx_tx_dwords", hw.mbx.tx_dwords),
  71. FM10K_STAT("mbx_rx_messages", hw.mbx.rx_messages),
  72. FM10K_STAT("mbx_rx_dwords", hw.mbx.rx_dwords),
  73. FM10K_STAT("mbx_rx_parse_err", hw.mbx.rx_parse_err),
  74. FM10K_STAT("tx_hang_count", tx_timeout_count),
  75. FM10K_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
  76. };
  77. static const struct fm10k_stats fm10k_gstrings_pf_stats[] = {
  78. FM10K_STAT("timeout", stats.timeout.count),
  79. FM10K_STAT("ur", stats.ur.count),
  80. FM10K_STAT("ca", stats.ca.count),
  81. FM10K_STAT("um", stats.um.count),
  82. FM10K_STAT("xec", stats.xec.count),
  83. FM10K_STAT("vlan_drop", stats.vlan_drop.count),
  84. FM10K_STAT("loopback_drop", stats.loopback_drop.count),
  85. FM10K_STAT("nodesc_drop", stats.nodesc_drop.count),
  86. };
  87. #define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
  88. #define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
  89. #define FM10K_QUEUE_STATS_LEN(_n) \
  90. ( (_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
  91. #define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
  92. FM10K_NETDEV_STATS_LEN)
  93. static const char fm10k_gstrings_test[][ETH_GSTRING_LEN] = {
  94. "Mailbox test (on/offline)"
  95. };
  96. #define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
  97. enum fm10k_self_test_types {
  98. FM10K_TEST_MBX,
  99. FM10K_TEST_MAX = FM10K_TEST_LEN
  100. };
  101. static void fm10k_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  102. {
  103. struct fm10k_intfc *interface = netdev_priv(dev);
  104. char *p = (char *)data;
  105. int i;
  106. switch (stringset) {
  107. case ETH_SS_TEST:
  108. memcpy(data, *fm10k_gstrings_test,
  109. FM10K_TEST_LEN * ETH_GSTRING_LEN);
  110. break;
  111. case ETH_SS_STATS:
  112. for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
  113. memcpy(p, fm10k_gstrings_net_stats[i].stat_string,
  114. ETH_GSTRING_LEN);
  115. p += ETH_GSTRING_LEN;
  116. }
  117. for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
  118. memcpy(p, fm10k_gstrings_global_stats[i].stat_string,
  119. ETH_GSTRING_LEN);
  120. p += ETH_GSTRING_LEN;
  121. }
  122. if (interface->hw.mac.type != fm10k_mac_vf)
  123. for (i = 0; i < FM10K_PF_STATS_LEN; i++) {
  124. memcpy(p, fm10k_gstrings_pf_stats[i].stat_string,
  125. ETH_GSTRING_LEN);
  126. p += ETH_GSTRING_LEN;
  127. }
  128. for (i = 0; i < interface->hw.mac.max_queues; i++) {
  129. sprintf(p, "tx_queue_%u_packets", i);
  130. p += ETH_GSTRING_LEN;
  131. sprintf(p, "tx_queue_%u_bytes", i);
  132. p += ETH_GSTRING_LEN;
  133. sprintf(p, "rx_queue_%u_packets", i);
  134. p += ETH_GSTRING_LEN;
  135. sprintf(p, "rx_queue_%u_bytes", i);
  136. p += ETH_GSTRING_LEN;
  137. }
  138. break;
  139. }
  140. }
  141. static int fm10k_get_sset_count(struct net_device *dev, int sset)
  142. {
  143. struct fm10k_intfc *interface = netdev_priv(dev);
  144. struct fm10k_hw *hw = &interface->hw;
  145. int stats_len = FM10K_STATIC_STATS_LEN;
  146. switch (sset) {
  147. case ETH_SS_TEST:
  148. return FM10K_TEST_LEN;
  149. case ETH_SS_STATS:
  150. stats_len += FM10K_QUEUE_STATS_LEN(hw->mac.max_queues);
  151. if (hw->mac.type != fm10k_mac_vf)
  152. stats_len += FM10K_PF_STATS_LEN;
  153. return stats_len;
  154. default:
  155. return -EOPNOTSUPP;
  156. }
  157. }
  158. static void fm10k_get_ethtool_stats(struct net_device *netdev,
  159. struct ethtool_stats __always_unused *stats,
  160. u64 *data)
  161. {
  162. const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64);
  163. struct fm10k_intfc *interface = netdev_priv(netdev);
  164. struct net_device_stats *net_stats = &netdev->stats;
  165. char *p;
  166. int i, j;
  167. fm10k_update_stats(interface);
  168. for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
  169. p = (char *)net_stats + fm10k_gstrings_net_stats[i].stat_offset;
  170. *(data++) = (fm10k_gstrings_net_stats[i].sizeof_stat ==
  171. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  172. }
  173. for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
  174. p = (char *)interface +
  175. fm10k_gstrings_global_stats[i].stat_offset;
  176. *(data++) = (fm10k_gstrings_global_stats[i].sizeof_stat ==
  177. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  178. }
  179. if (interface->hw.mac.type != fm10k_mac_vf)
  180. for (i = 0; i < FM10K_PF_STATS_LEN; i++) {
  181. p = (char *)interface +
  182. fm10k_gstrings_pf_stats[i].stat_offset;
  183. *(data++) = (fm10k_gstrings_pf_stats[i].sizeof_stat ==
  184. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  185. }
  186. for (i = 0; i < interface->hw.mac.max_queues; i++) {
  187. struct fm10k_ring *ring;
  188. u64 *queue_stat;
  189. ring = interface->tx_ring[i];
  190. if (ring)
  191. queue_stat = (u64 *)&ring->stats;
  192. for (j = 0; j < stat_count; j++)
  193. *(data++) = ring ? queue_stat[j] : 0;
  194. ring = interface->rx_ring[i];
  195. if (ring)
  196. queue_stat = (u64 *)&ring->stats;
  197. for (j = 0; j < stat_count; j++)
  198. *(data++) = ring ? queue_stat[j] : 0;
  199. }
  200. }
  201. /* If function below adds more registers this define needs to be updated */
  202. #define FM10K_REGS_LEN_Q 29
  203. static void fm10k_get_reg_q(struct fm10k_hw *hw, u32 *buff, int i)
  204. {
  205. int idx = 0;
  206. buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAL(i));
  207. buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAH(i));
  208. buff[idx++] = fm10k_read_reg(hw, FM10K_RDLEN(i));
  209. buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_RXCTRL(i));
  210. buff[idx++] = fm10k_read_reg(hw, FM10K_RDH(i));
  211. buff[idx++] = fm10k_read_reg(hw, FM10K_RDT(i));
  212. buff[idx++] = fm10k_read_reg(hw, FM10K_RXQCTL(i));
  213. buff[idx++] = fm10k_read_reg(hw, FM10K_RXDCTL(i));
  214. buff[idx++] = fm10k_read_reg(hw, FM10K_RXINT(i));
  215. buff[idx++] = fm10k_read_reg(hw, FM10K_SRRCTL(i));
  216. buff[idx++] = fm10k_read_reg(hw, FM10K_QPRC(i));
  217. buff[idx++] = fm10k_read_reg(hw, FM10K_QPRDC(i));
  218. buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_L(i));
  219. buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_H(i));
  220. buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAL(i));
  221. buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAH(i));
  222. buff[idx++] = fm10k_read_reg(hw, FM10K_TDLEN(i));
  223. buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_TXCTRL(i));
  224. buff[idx++] = fm10k_read_reg(hw, FM10K_TDH(i));
  225. buff[idx++] = fm10k_read_reg(hw, FM10K_TDT(i));
  226. buff[idx++] = fm10k_read_reg(hw, FM10K_TXDCTL(i));
  227. buff[idx++] = fm10k_read_reg(hw, FM10K_TXQCTL(i));
  228. buff[idx++] = fm10k_read_reg(hw, FM10K_TXINT(i));
  229. buff[idx++] = fm10k_read_reg(hw, FM10K_QPTC(i));
  230. buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_L(i));
  231. buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_H(i));
  232. buff[idx++] = fm10k_read_reg(hw, FM10K_TQDLOC(i));
  233. buff[idx++] = fm10k_read_reg(hw, FM10K_TX_SGLORT(i));
  234. buff[idx++] = fm10k_read_reg(hw, FM10K_PFVTCTL(i));
  235. BUG_ON(idx != FM10K_REGS_LEN_Q);
  236. }
  237. /* If function above adds more registers this define needs to be updated */
  238. #define FM10K_REGS_LEN_VSI 43
  239. static void fm10k_get_reg_vsi(struct fm10k_hw *hw, u32 *buff, int i)
  240. {
  241. int idx = 0, j;
  242. buff[idx++] = fm10k_read_reg(hw, FM10K_MRQC(i));
  243. for (j = 0; j < 10; j++)
  244. buff[idx++] = fm10k_read_reg(hw, FM10K_RSSRK(i, j));
  245. for (j = 0; j < 32; j++)
  246. buff[idx++] = fm10k_read_reg(hw, FM10K_RETA(i, j));
  247. BUG_ON(idx != FM10K_REGS_LEN_VSI);
  248. }
  249. static void fm10k_get_regs(struct net_device *netdev,
  250. struct ethtool_regs *regs, void *p)
  251. {
  252. struct fm10k_intfc *interface = netdev_priv(netdev);
  253. struct fm10k_hw *hw = &interface->hw;
  254. u32 *buff = p;
  255. u16 i;
  256. regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
  257. switch (hw->mac.type) {
  258. case fm10k_mac_pf:
  259. /* General PF Registers */
  260. *(buff++) = fm10k_read_reg(hw, FM10K_CTRL);
  261. *(buff++) = fm10k_read_reg(hw, FM10K_CTRL_EXT);
  262. *(buff++) = fm10k_read_reg(hw, FM10K_GCR);
  263. *(buff++) = fm10k_read_reg(hw, FM10K_GCR_EXT);
  264. for (i = 0; i < 8; i++) {
  265. *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTMAP(i));
  266. *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTDEC(i));
  267. }
  268. for (i = 0; i < 65; i++) {
  269. fm10k_get_reg_vsi(hw, buff, i);
  270. buff += FM10K_REGS_LEN_VSI;
  271. }
  272. *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL);
  273. *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
  274. for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) {
  275. fm10k_get_reg_q(hw, buff, i);
  276. buff += FM10K_REGS_LEN_Q;
  277. }
  278. *(buff++) = fm10k_read_reg(hw, FM10K_TPH_CTRL);
  279. for (i = 0; i < 8; i++)
  280. *(buff++) = fm10k_read_reg(hw, FM10K_INT_MAP(i));
  281. /* Interrupt Throttling Registers */
  282. for (i = 0; i < 130; i++)
  283. *(buff++) = fm10k_read_reg(hw, FM10K_ITR(i));
  284. break;
  285. case fm10k_mac_vf:
  286. /* General VF registers */
  287. *(buff++) = fm10k_read_reg(hw, FM10K_VFCTRL);
  288. *(buff++) = fm10k_read_reg(hw, FM10K_VFINT_MAP);
  289. *(buff++) = fm10k_read_reg(hw, FM10K_VFSYSTIME);
  290. /* Interrupt Throttling Registers */
  291. for (i = 0; i < 8; i++)
  292. *(buff++) = fm10k_read_reg(hw, FM10K_VFITR(i));
  293. fm10k_get_reg_vsi(hw, buff, 0);
  294. buff += FM10K_REGS_LEN_VSI;
  295. for (i = 0; i < FM10K_MAX_QUEUES_POOL; i++) {
  296. if (i < hw->mac.max_queues)
  297. fm10k_get_reg_q(hw, buff, i);
  298. else
  299. memset(buff, 0, sizeof(u32) * FM10K_REGS_LEN_Q);
  300. buff += FM10K_REGS_LEN_Q;
  301. }
  302. break;
  303. default:
  304. return;
  305. }
  306. }
  307. /* If function above adds more registers these define need to be updated */
  308. #define FM10K_REGS_LEN_PF \
  309. (162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
  310. #define FM10K_REGS_LEN_VF \
  311. (11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
  312. static int fm10k_get_regs_len(struct net_device *netdev)
  313. {
  314. struct fm10k_intfc *interface = netdev_priv(netdev);
  315. struct fm10k_hw *hw = &interface->hw;
  316. switch (hw->mac.type) {
  317. case fm10k_mac_pf:
  318. return FM10K_REGS_LEN_PF * sizeof(u32);
  319. case fm10k_mac_vf:
  320. return FM10K_REGS_LEN_VF * sizeof(u32);
  321. default:
  322. return 0;
  323. }
  324. }
  325. static void fm10k_get_drvinfo(struct net_device *dev,
  326. struct ethtool_drvinfo *info)
  327. {
  328. struct fm10k_intfc *interface = netdev_priv(dev);
  329. strncpy(info->driver, fm10k_driver_name,
  330. sizeof(info->driver) - 1);
  331. strncpy(info->version, fm10k_driver_version,
  332. sizeof(info->version) - 1);
  333. strncpy(info->bus_info, pci_name(interface->pdev),
  334. sizeof(info->bus_info) - 1);
  335. info->n_stats = fm10k_get_sset_count(dev, ETH_SS_STATS);
  336. info->regdump_len = fm10k_get_regs_len(dev);
  337. }
  338. static void fm10k_get_pauseparam(struct net_device *dev,
  339. struct ethtool_pauseparam *pause)
  340. {
  341. struct fm10k_intfc *interface = netdev_priv(dev);
  342. /* record fixed values for autoneg and tx pause */
  343. pause->autoneg = 0;
  344. pause->tx_pause = 1;
  345. pause->rx_pause = interface->rx_pause ? 1 : 0;
  346. }
  347. static int fm10k_set_pauseparam(struct net_device *dev,
  348. struct ethtool_pauseparam *pause)
  349. {
  350. struct fm10k_intfc *interface = netdev_priv(dev);
  351. struct fm10k_hw *hw = &interface->hw;
  352. if (pause->autoneg || !pause->tx_pause)
  353. return -EINVAL;
  354. /* we can only support pause on the PF to avoid head-of-line blocking */
  355. if (hw->mac.type == fm10k_mac_pf)
  356. interface->rx_pause = pause->rx_pause ? ~0 : 0;
  357. else if (pause->rx_pause)
  358. return -EINVAL;
  359. if (netif_running(dev))
  360. fm10k_update_rx_drop_en(interface);
  361. return 0;
  362. }
  363. static u32 fm10k_get_msglevel(struct net_device *netdev)
  364. {
  365. struct fm10k_intfc *interface = netdev_priv(netdev);
  366. return interface->msg_enable;
  367. }
  368. static void fm10k_set_msglevel(struct net_device *netdev, u32 data)
  369. {
  370. struct fm10k_intfc *interface = netdev_priv(netdev);
  371. interface->msg_enable = data;
  372. }
  373. static void fm10k_get_ringparam(struct net_device *netdev,
  374. struct ethtool_ringparam *ring)
  375. {
  376. struct fm10k_intfc *interface = netdev_priv(netdev);
  377. ring->rx_max_pending = FM10K_MAX_RXD;
  378. ring->tx_max_pending = FM10K_MAX_TXD;
  379. ring->rx_mini_max_pending = 0;
  380. ring->rx_jumbo_max_pending = 0;
  381. ring->rx_pending = interface->rx_ring_count;
  382. ring->tx_pending = interface->tx_ring_count;
  383. ring->rx_mini_pending = 0;
  384. ring->rx_jumbo_pending = 0;
  385. }
  386. static int fm10k_set_ringparam(struct net_device *netdev,
  387. struct ethtool_ringparam *ring)
  388. {
  389. struct fm10k_intfc *interface = netdev_priv(netdev);
  390. struct fm10k_ring *temp_ring;
  391. int i, err = 0;
  392. u32 new_rx_count, new_tx_count;
  393. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  394. return -EINVAL;
  395. new_tx_count = clamp_t(u32, ring->tx_pending,
  396. FM10K_MIN_TXD, FM10K_MAX_TXD);
  397. new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE);
  398. new_rx_count = clamp_t(u32, ring->rx_pending,
  399. FM10K_MIN_RXD, FM10K_MAX_RXD);
  400. new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE);
  401. if ((new_tx_count == interface->tx_ring_count) &&
  402. (new_rx_count == interface->rx_ring_count)) {
  403. /* nothing to do */
  404. return 0;
  405. }
  406. while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
  407. usleep_range(1000, 2000);
  408. if (!netif_running(interface->netdev)) {
  409. for (i = 0; i < interface->num_tx_queues; i++)
  410. interface->tx_ring[i]->count = new_tx_count;
  411. for (i = 0; i < interface->num_rx_queues; i++)
  412. interface->rx_ring[i]->count = new_rx_count;
  413. interface->tx_ring_count = new_tx_count;
  414. interface->rx_ring_count = new_rx_count;
  415. goto clear_reset;
  416. }
  417. /* allocate temporary buffer to store rings in */
  418. i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
  419. temp_ring = vmalloc(i * sizeof(struct fm10k_ring));
  420. if (!temp_ring) {
  421. err = -ENOMEM;
  422. goto clear_reset;
  423. }
  424. fm10k_down(interface);
  425. /* Setup new Tx resources and free the old Tx resources in that order.
  426. * We can then assign the new resources to the rings via a memcpy.
  427. * The advantage to this approach is that we are guaranteed to still
  428. * have resources even in the case of an allocation failure.
  429. */
  430. if (new_tx_count != interface->tx_ring_count) {
  431. for (i = 0; i < interface->num_tx_queues; i++) {
  432. memcpy(&temp_ring[i], interface->tx_ring[i],
  433. sizeof(struct fm10k_ring));
  434. temp_ring[i].count = new_tx_count;
  435. err = fm10k_setup_tx_resources(&temp_ring[i]);
  436. if (err) {
  437. while (i) {
  438. i--;
  439. fm10k_free_tx_resources(&temp_ring[i]);
  440. }
  441. goto err_setup;
  442. }
  443. }
  444. for (i = 0; i < interface->num_tx_queues; i++) {
  445. fm10k_free_tx_resources(interface->tx_ring[i]);
  446. memcpy(interface->tx_ring[i], &temp_ring[i],
  447. sizeof(struct fm10k_ring));
  448. }
  449. interface->tx_ring_count = new_tx_count;
  450. }
  451. /* Repeat the process for the Rx rings if needed */
  452. if (new_rx_count != interface->rx_ring_count) {
  453. for (i = 0; i < interface->num_rx_queues; i++) {
  454. memcpy(&temp_ring[i], interface->rx_ring[i],
  455. sizeof(struct fm10k_ring));
  456. temp_ring[i].count = new_rx_count;
  457. err = fm10k_setup_rx_resources(&temp_ring[i]);
  458. if (err) {
  459. while (i) {
  460. i--;
  461. fm10k_free_rx_resources(&temp_ring[i]);
  462. }
  463. goto err_setup;
  464. }
  465. }
  466. for (i = 0; i < interface->num_rx_queues; i++) {
  467. fm10k_free_rx_resources(interface->rx_ring[i]);
  468. memcpy(interface->rx_ring[i], &temp_ring[i],
  469. sizeof(struct fm10k_ring));
  470. }
  471. interface->rx_ring_count = new_rx_count;
  472. }
  473. err_setup:
  474. fm10k_up(interface);
  475. vfree(temp_ring);
  476. clear_reset:
  477. clear_bit(__FM10K_RESETTING, &interface->state);
  478. return err;
  479. }
  480. static int fm10k_get_coalesce(struct net_device *dev,
  481. struct ethtool_coalesce *ec)
  482. {
  483. struct fm10k_intfc *interface = netdev_priv(dev);
  484. ec->use_adaptive_tx_coalesce =
  485. !!(interface->tx_itr & FM10K_ITR_ADAPTIVE);
  486. ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE;
  487. ec->use_adaptive_rx_coalesce =
  488. !!(interface->rx_itr & FM10K_ITR_ADAPTIVE);
  489. ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE;
  490. return 0;
  491. }
  492. static int fm10k_set_coalesce(struct net_device *dev,
  493. struct ethtool_coalesce *ec)
  494. {
  495. struct fm10k_intfc *interface = netdev_priv(dev);
  496. struct fm10k_q_vector *qv;
  497. u16 tx_itr, rx_itr;
  498. int i;
  499. /* verify limits */
  500. if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) ||
  501. (ec->tx_coalesce_usecs > FM10K_ITR_MAX))
  502. return -EINVAL;
  503. /* record settings */
  504. tx_itr = ec->tx_coalesce_usecs;
  505. rx_itr = ec->rx_coalesce_usecs;
  506. /* set initial values for adaptive ITR */
  507. if (ec->use_adaptive_tx_coalesce)
  508. tx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_10K;
  509. if (ec->use_adaptive_rx_coalesce)
  510. rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
  511. /* update interface */
  512. interface->tx_itr = tx_itr;
  513. interface->rx_itr = rx_itr;
  514. /* update q_vectors */
  515. for (i = 0; i < interface->num_q_vectors; i++) {
  516. qv = interface->q_vector[i];
  517. qv->tx.itr = tx_itr;
  518. qv->rx.itr = rx_itr;
  519. }
  520. return 0;
  521. }
  522. static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface,
  523. struct ethtool_rxnfc *cmd)
  524. {
  525. cmd->data = 0;
  526. /* Report default options for RSS on fm10k */
  527. switch (cmd->flow_type) {
  528. case TCP_V4_FLOW:
  529. case TCP_V6_FLOW:
  530. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  531. /* fall through */
  532. case UDP_V4_FLOW:
  533. if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
  534. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  535. /* fall through */
  536. case SCTP_V4_FLOW:
  537. case SCTP_V6_FLOW:
  538. case AH_ESP_V4_FLOW:
  539. case AH_ESP_V6_FLOW:
  540. case AH_V4_FLOW:
  541. case AH_V6_FLOW:
  542. case ESP_V4_FLOW:
  543. case ESP_V6_FLOW:
  544. case IPV4_FLOW:
  545. case IPV6_FLOW:
  546. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  547. break;
  548. case UDP_V6_FLOW:
  549. if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
  550. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  551. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  552. break;
  553. default:
  554. return -EINVAL;
  555. }
  556. return 0;
  557. }
  558. static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  559. u32 __always_unused *rule_locs)
  560. {
  561. struct fm10k_intfc *interface = netdev_priv(dev);
  562. int ret = -EOPNOTSUPP;
  563. switch (cmd->cmd) {
  564. case ETHTOOL_GRXRINGS:
  565. cmd->data = interface->num_rx_queues;
  566. ret = 0;
  567. break;
  568. case ETHTOOL_GRXFH:
  569. ret = fm10k_get_rss_hash_opts(interface, cmd);
  570. break;
  571. default:
  572. break;
  573. }
  574. return ret;
  575. }
  576. #define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
  577. FM10K_FLAG_RSS_FIELD_IPV6_UDP)
  578. static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface,
  579. struct ethtool_rxnfc *nfc)
  580. {
  581. u32 flags = interface->flags;
  582. /* RSS does not support anything other than hashing
  583. * to queues on src and dst IPs and ports
  584. */
  585. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  586. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  587. return -EINVAL;
  588. switch (nfc->flow_type) {
  589. case TCP_V4_FLOW:
  590. case TCP_V6_FLOW:
  591. if (!(nfc->data & RXH_IP_SRC) ||
  592. !(nfc->data & RXH_IP_DST) ||
  593. !(nfc->data & RXH_L4_B_0_1) ||
  594. !(nfc->data & RXH_L4_B_2_3))
  595. return -EINVAL;
  596. break;
  597. case UDP_V4_FLOW:
  598. if (!(nfc->data & RXH_IP_SRC) ||
  599. !(nfc->data & RXH_IP_DST))
  600. return -EINVAL;
  601. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  602. case 0:
  603. flags &= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP;
  604. break;
  605. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  606. flags |= FM10K_FLAG_RSS_FIELD_IPV4_UDP;
  607. break;
  608. default:
  609. return -EINVAL;
  610. }
  611. break;
  612. case UDP_V6_FLOW:
  613. if (!(nfc->data & RXH_IP_SRC) ||
  614. !(nfc->data & RXH_IP_DST))
  615. return -EINVAL;
  616. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  617. case 0:
  618. flags &= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP;
  619. break;
  620. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  621. flags |= FM10K_FLAG_RSS_FIELD_IPV6_UDP;
  622. break;
  623. default:
  624. return -EINVAL;
  625. }
  626. break;
  627. case AH_ESP_V4_FLOW:
  628. case AH_V4_FLOW:
  629. case ESP_V4_FLOW:
  630. case SCTP_V4_FLOW:
  631. case AH_ESP_V6_FLOW:
  632. case AH_V6_FLOW:
  633. case ESP_V6_FLOW:
  634. case SCTP_V6_FLOW:
  635. if (!(nfc->data & RXH_IP_SRC) ||
  636. !(nfc->data & RXH_IP_DST) ||
  637. (nfc->data & RXH_L4_B_0_1) ||
  638. (nfc->data & RXH_L4_B_2_3))
  639. return -EINVAL;
  640. break;
  641. default:
  642. return -EINVAL;
  643. }
  644. /* if we changed something we need to update flags */
  645. if (flags != interface->flags) {
  646. struct fm10k_hw *hw = &interface->hw;
  647. u32 mrqc;
  648. if ((flags & UDP_RSS_FLAGS) &&
  649. !(interface->flags & UDP_RSS_FLAGS))
  650. netif_warn(interface, drv, interface->netdev,
  651. "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
  652. interface->flags = flags;
  653. /* Perform hash on these packet types */
  654. mrqc = FM10K_MRQC_IPV4 |
  655. FM10K_MRQC_TCP_IPV4 |
  656. FM10K_MRQC_IPV6 |
  657. FM10K_MRQC_TCP_IPV6;
  658. if (flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
  659. mrqc |= FM10K_MRQC_UDP_IPV4;
  660. if (flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
  661. mrqc |= FM10K_MRQC_UDP_IPV6;
  662. fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
  663. }
  664. return 0;
  665. }
  666. static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  667. {
  668. struct fm10k_intfc *interface = netdev_priv(dev);
  669. int ret = -EOPNOTSUPP;
  670. switch (cmd->cmd) {
  671. case ETHTOOL_SRXFH:
  672. ret = fm10k_set_rss_hash_opt(interface, cmd);
  673. break;
  674. default:
  675. break;
  676. }
  677. return ret;
  678. }
  679. static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data)
  680. {
  681. struct fm10k_hw *hw = &interface->hw;
  682. struct fm10k_mbx_info *mbx = &hw->mbx;
  683. u32 attr_flag, test_msg[6];
  684. unsigned long timeout;
  685. int err;
  686. /* For now this is a VF only feature */
  687. if (hw->mac.type != fm10k_mac_vf)
  688. return 0;
  689. /* loop through both nested and unnested attribute types */
  690. for (attr_flag = (1 << FM10K_TEST_MSG_UNSET);
  691. attr_flag < (1 << (2 * FM10K_TEST_MSG_NESTED));
  692. attr_flag += attr_flag) {
  693. /* generate message to be tested */
  694. fm10k_tlv_msg_test_create(test_msg, attr_flag);
  695. fm10k_mbx_lock(interface);
  696. mbx->test_result = FM10K_NOT_IMPLEMENTED;
  697. err = mbx->ops.enqueue_tx(hw, mbx, test_msg);
  698. fm10k_mbx_unlock(interface);
  699. /* wait up to 1 second for response */
  700. timeout = jiffies + HZ;
  701. do {
  702. if (err < 0)
  703. goto err_out;
  704. usleep_range(500, 1000);
  705. fm10k_mbx_lock(interface);
  706. mbx->ops.process(hw, mbx);
  707. fm10k_mbx_unlock(interface);
  708. err = mbx->test_result;
  709. if (!err)
  710. break;
  711. } while (time_is_after_jiffies(timeout));
  712. /* reporting errors */
  713. if (err)
  714. goto err_out;
  715. }
  716. err_out:
  717. *data = err < 0 ? (attr_flag) : (err > 0);
  718. return err;
  719. }
  720. static void fm10k_self_test(struct net_device *dev,
  721. struct ethtool_test *eth_test, u64 *data)
  722. {
  723. struct fm10k_intfc *interface = netdev_priv(dev);
  724. struct fm10k_hw *hw = &interface->hw;
  725. memset(data, 0, sizeof(*data) * FM10K_TEST_LEN);
  726. if (FM10K_REMOVED(hw)) {
  727. netif_err(interface, drv, dev,
  728. "Interface removed - test blocked\n");
  729. eth_test->flags |= ETH_TEST_FL_FAILED;
  730. return;
  731. }
  732. if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX]))
  733. eth_test->flags |= ETH_TEST_FL_FAILED;
  734. }
  735. static u32 fm10k_get_reta_size(struct net_device __always_unused *netdev)
  736. {
  737. return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG;
  738. }
  739. static int fm10k_get_reta(struct net_device *netdev, u32 *indir)
  740. {
  741. struct fm10k_intfc *interface = netdev_priv(netdev);
  742. int i;
  743. if (!indir)
  744. return 0;
  745. for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
  746. u32 reta = interface->reta[i];
  747. indir[0] = (reta << 24) >> 24;
  748. indir[1] = (reta << 16) >> 24;
  749. indir[2] = (reta << 8) >> 24;
  750. indir[3] = (reta) >> 24;
  751. }
  752. return 0;
  753. }
  754. static int fm10k_set_reta(struct net_device *netdev, const u32 *indir)
  755. {
  756. struct fm10k_intfc *interface = netdev_priv(netdev);
  757. struct fm10k_hw *hw = &interface->hw;
  758. int i;
  759. u16 rss_i;
  760. if (!indir)
  761. return 0;
  762. /* Verify user input. */
  763. rss_i = interface->ring_feature[RING_F_RSS].indices;
  764. for (i = fm10k_get_reta_size(netdev); i--;) {
  765. if (indir[i] < rss_i)
  766. continue;
  767. return -EINVAL;
  768. }
  769. /* record entries to reta table */
  770. for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
  771. u32 reta = indir[0] |
  772. (indir[1] << 8) |
  773. (indir[2] << 16) |
  774. (indir[3] << 24);
  775. if (interface->reta[i] == reta)
  776. continue;
  777. interface->reta[i] = reta;
  778. fm10k_write_reg(hw, FM10K_RETA(0, i), reta);
  779. }
  780. return 0;
  781. }
  782. static u32 fm10k_get_rssrk_size(struct net_device __always_unused *netdev)
  783. {
  784. return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG;
  785. }
  786. static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key,
  787. u8 *hfunc)
  788. {
  789. struct fm10k_intfc *interface = netdev_priv(netdev);
  790. int i, err;
  791. if (hfunc)
  792. *hfunc = ETH_RSS_HASH_TOP;
  793. err = fm10k_get_reta(netdev, indir);
  794. if (err || !key)
  795. return err;
  796. for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4)
  797. *(__le32 *)key = cpu_to_le32(interface->rssrk[i]);
  798. return 0;
  799. }
  800. static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir,
  801. const u8 *key, const u8 hfunc)
  802. {
  803. struct fm10k_intfc *interface = netdev_priv(netdev);
  804. struct fm10k_hw *hw = &interface->hw;
  805. int i, err;
  806. /* We do not allow change in unsupported parameters */
  807. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  808. return -EOPNOTSUPP;
  809. err = fm10k_set_reta(netdev, indir);
  810. if (err || !key)
  811. return err;
  812. for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) {
  813. u32 rssrk = le32_to_cpu(*(__le32 *)key);
  814. if (interface->rssrk[i] == rssrk)
  815. continue;
  816. interface->rssrk[i] = rssrk;
  817. fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk);
  818. }
  819. return 0;
  820. }
  821. static unsigned int fm10k_max_channels(struct net_device *dev)
  822. {
  823. struct fm10k_intfc *interface = netdev_priv(dev);
  824. unsigned int max_combined = interface->hw.mac.max_queues;
  825. u8 tcs = netdev_get_num_tc(dev);
  826. /* For QoS report channels per traffic class */
  827. if (tcs > 1)
  828. max_combined = 1 << (fls(max_combined / tcs) - 1);
  829. return max_combined;
  830. }
  831. static void fm10k_get_channels(struct net_device *dev,
  832. struct ethtool_channels *ch)
  833. {
  834. struct fm10k_intfc *interface = netdev_priv(dev);
  835. struct fm10k_hw *hw = &interface->hw;
  836. /* report maximum channels */
  837. ch->max_combined = fm10k_max_channels(dev);
  838. /* report info for other vector */
  839. ch->max_other = NON_Q_VECTORS(hw);
  840. ch->other_count = ch->max_other;
  841. /* record RSS queues */
  842. ch->combined_count = interface->ring_feature[RING_F_RSS].indices;
  843. }
  844. static int fm10k_set_channels(struct net_device *dev,
  845. struct ethtool_channels *ch)
  846. {
  847. struct fm10k_intfc *interface = netdev_priv(dev);
  848. unsigned int count = ch->combined_count;
  849. struct fm10k_hw *hw = &interface->hw;
  850. /* verify they are not requesting separate vectors */
  851. if (!count || ch->rx_count || ch->tx_count)
  852. return -EINVAL;
  853. /* verify other_count has not changed */
  854. if (ch->other_count != NON_Q_VECTORS(hw))
  855. return -EINVAL;
  856. /* verify the number of channels does not exceed hardware limits */
  857. if (count > fm10k_max_channels(dev))
  858. return -EINVAL;
  859. interface->ring_feature[RING_F_RSS].limit = count;
  860. /* use setup TC to update any traffic class queue mapping */
  861. return fm10k_setup_tc(dev, netdev_get_num_tc(dev));
  862. }
  863. static int fm10k_get_ts_info(struct net_device *dev,
  864. struct ethtool_ts_info *info)
  865. {
  866. struct fm10k_intfc *interface = netdev_priv(dev);
  867. info->so_timestamping =
  868. SOF_TIMESTAMPING_TX_SOFTWARE |
  869. SOF_TIMESTAMPING_RX_SOFTWARE |
  870. SOF_TIMESTAMPING_SOFTWARE |
  871. SOF_TIMESTAMPING_TX_HARDWARE |
  872. SOF_TIMESTAMPING_RX_HARDWARE |
  873. SOF_TIMESTAMPING_RAW_HARDWARE;
  874. if (interface->ptp_clock)
  875. info->phc_index = ptp_clock_index(interface->ptp_clock);
  876. else
  877. info->phc_index = -1;
  878. info->tx_types = (1 << HWTSTAMP_TX_OFF) |
  879. (1 << HWTSTAMP_TX_ON);
  880. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  881. (1 << HWTSTAMP_FILTER_ALL);
  882. return 0;
  883. }
  884. static const struct ethtool_ops fm10k_ethtool_ops = {
  885. .get_strings = fm10k_get_strings,
  886. .get_sset_count = fm10k_get_sset_count,
  887. .get_ethtool_stats = fm10k_get_ethtool_stats,
  888. .get_drvinfo = fm10k_get_drvinfo,
  889. .get_link = ethtool_op_get_link,
  890. .get_pauseparam = fm10k_get_pauseparam,
  891. .set_pauseparam = fm10k_set_pauseparam,
  892. .get_msglevel = fm10k_get_msglevel,
  893. .set_msglevel = fm10k_set_msglevel,
  894. .get_ringparam = fm10k_get_ringparam,
  895. .set_ringparam = fm10k_set_ringparam,
  896. .get_coalesce = fm10k_get_coalesce,
  897. .set_coalesce = fm10k_set_coalesce,
  898. .get_rxnfc = fm10k_get_rxnfc,
  899. .set_rxnfc = fm10k_set_rxnfc,
  900. .get_regs = fm10k_get_regs,
  901. .get_regs_len = fm10k_get_regs_len,
  902. .self_test = fm10k_self_test,
  903. .get_rxfh_indir_size = fm10k_get_reta_size,
  904. .get_rxfh_key_size = fm10k_get_rssrk_size,
  905. .get_rxfh = fm10k_get_rssh,
  906. .set_rxfh = fm10k_set_rssh,
  907. .get_channels = fm10k_get_channels,
  908. .set_channels = fm10k_set_channels,
  909. .get_ts_info = fm10k_get_ts_info,
  910. };
  911. void fm10k_set_ethtool_ops(struct net_device *dev)
  912. {
  913. dev->ethtool_ops = &fm10k_ethtool_ops;
  914. }