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