fm10k_ethtool.c 33 KB

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