fm10k_ethtool.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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. snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_packets", i);
  177. p += ETH_GSTRING_LEN;
  178. snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
  179. p += ETH_GSTRING_LEN;
  180. snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_packets", i);
  181. p += ETH_GSTRING_LEN;
  182. snprintf(p, ETH_GSTRING_LEN, "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. }
  437. static void fm10k_get_pauseparam(struct net_device *dev,
  438. struct ethtool_pauseparam *pause)
  439. {
  440. struct fm10k_intfc *interface = netdev_priv(dev);
  441. /* record fixed values for autoneg and tx pause */
  442. pause->autoneg = 0;
  443. pause->tx_pause = 1;
  444. pause->rx_pause = interface->rx_pause ? 1 : 0;
  445. }
  446. static int fm10k_set_pauseparam(struct net_device *dev,
  447. struct ethtool_pauseparam *pause)
  448. {
  449. struct fm10k_intfc *interface = netdev_priv(dev);
  450. struct fm10k_hw *hw = &interface->hw;
  451. if (pause->autoneg || !pause->tx_pause)
  452. return -EINVAL;
  453. /* we can only support pause on the PF to avoid head-of-line blocking */
  454. if (hw->mac.type == fm10k_mac_pf)
  455. interface->rx_pause = pause->rx_pause ? ~0 : 0;
  456. else if (pause->rx_pause)
  457. return -EINVAL;
  458. if (netif_running(dev))
  459. fm10k_update_rx_drop_en(interface);
  460. return 0;
  461. }
  462. static u32 fm10k_get_msglevel(struct net_device *netdev)
  463. {
  464. struct fm10k_intfc *interface = netdev_priv(netdev);
  465. return interface->msg_enable;
  466. }
  467. static void fm10k_set_msglevel(struct net_device *netdev, u32 data)
  468. {
  469. struct fm10k_intfc *interface = netdev_priv(netdev);
  470. interface->msg_enable = data;
  471. }
  472. static void fm10k_get_ringparam(struct net_device *netdev,
  473. struct ethtool_ringparam *ring)
  474. {
  475. struct fm10k_intfc *interface = netdev_priv(netdev);
  476. ring->rx_max_pending = FM10K_MAX_RXD;
  477. ring->tx_max_pending = FM10K_MAX_TXD;
  478. ring->rx_mini_max_pending = 0;
  479. ring->rx_jumbo_max_pending = 0;
  480. ring->rx_pending = interface->rx_ring_count;
  481. ring->tx_pending = interface->tx_ring_count;
  482. ring->rx_mini_pending = 0;
  483. ring->rx_jumbo_pending = 0;
  484. }
  485. static int fm10k_set_ringparam(struct net_device *netdev,
  486. struct ethtool_ringparam *ring)
  487. {
  488. struct fm10k_intfc *interface = netdev_priv(netdev);
  489. struct fm10k_ring *temp_ring;
  490. int i, err = 0;
  491. u32 new_rx_count, new_tx_count;
  492. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  493. return -EINVAL;
  494. new_tx_count = clamp_t(u32, ring->tx_pending,
  495. FM10K_MIN_TXD, FM10K_MAX_TXD);
  496. new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE);
  497. new_rx_count = clamp_t(u32, ring->rx_pending,
  498. FM10K_MIN_RXD, FM10K_MAX_RXD);
  499. new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE);
  500. if ((new_tx_count == interface->tx_ring_count) &&
  501. (new_rx_count == interface->rx_ring_count)) {
  502. /* nothing to do */
  503. return 0;
  504. }
  505. while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
  506. usleep_range(1000, 2000);
  507. if (!netif_running(interface->netdev)) {
  508. for (i = 0; i < interface->num_tx_queues; i++)
  509. interface->tx_ring[i]->count = new_tx_count;
  510. for (i = 0; i < interface->num_rx_queues; i++)
  511. interface->rx_ring[i]->count = new_rx_count;
  512. interface->tx_ring_count = new_tx_count;
  513. interface->rx_ring_count = new_rx_count;
  514. goto clear_reset;
  515. }
  516. /* allocate temporary buffer to store rings in */
  517. i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
  518. temp_ring = vmalloc(i * sizeof(struct fm10k_ring));
  519. if (!temp_ring) {
  520. err = -ENOMEM;
  521. goto clear_reset;
  522. }
  523. fm10k_down(interface);
  524. /* Setup new Tx resources and free the old Tx resources in that order.
  525. * We can then assign the new resources to the rings via a memcpy.
  526. * The advantage to this approach is that we are guaranteed to still
  527. * have resources even in the case of an allocation failure.
  528. */
  529. if (new_tx_count != interface->tx_ring_count) {
  530. for (i = 0; i < interface->num_tx_queues; i++) {
  531. memcpy(&temp_ring[i], interface->tx_ring[i],
  532. sizeof(struct fm10k_ring));
  533. temp_ring[i].count = new_tx_count;
  534. err = fm10k_setup_tx_resources(&temp_ring[i]);
  535. if (err) {
  536. while (i) {
  537. i--;
  538. fm10k_free_tx_resources(&temp_ring[i]);
  539. }
  540. goto err_setup;
  541. }
  542. }
  543. for (i = 0; i < interface->num_tx_queues; i++) {
  544. fm10k_free_tx_resources(interface->tx_ring[i]);
  545. memcpy(interface->tx_ring[i], &temp_ring[i],
  546. sizeof(struct fm10k_ring));
  547. }
  548. interface->tx_ring_count = new_tx_count;
  549. }
  550. /* Repeat the process for the Rx rings if needed */
  551. if (new_rx_count != interface->rx_ring_count) {
  552. for (i = 0; i < interface->num_rx_queues; i++) {
  553. memcpy(&temp_ring[i], interface->rx_ring[i],
  554. sizeof(struct fm10k_ring));
  555. temp_ring[i].count = new_rx_count;
  556. err = fm10k_setup_rx_resources(&temp_ring[i]);
  557. if (err) {
  558. while (i) {
  559. i--;
  560. fm10k_free_rx_resources(&temp_ring[i]);
  561. }
  562. goto err_setup;
  563. }
  564. }
  565. for (i = 0; i < interface->num_rx_queues; i++) {
  566. fm10k_free_rx_resources(interface->rx_ring[i]);
  567. memcpy(interface->rx_ring[i], &temp_ring[i],
  568. sizeof(struct fm10k_ring));
  569. }
  570. interface->rx_ring_count = new_rx_count;
  571. }
  572. err_setup:
  573. fm10k_up(interface);
  574. vfree(temp_ring);
  575. clear_reset:
  576. clear_bit(__FM10K_RESETTING, &interface->state);
  577. return err;
  578. }
  579. static int fm10k_get_coalesce(struct net_device *dev,
  580. struct ethtool_coalesce *ec)
  581. {
  582. struct fm10k_intfc *interface = netdev_priv(dev);
  583. ec->use_adaptive_tx_coalesce =
  584. !!(interface->tx_itr & FM10K_ITR_ADAPTIVE);
  585. ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE;
  586. ec->use_adaptive_rx_coalesce =
  587. !!(interface->rx_itr & FM10K_ITR_ADAPTIVE);
  588. ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE;
  589. return 0;
  590. }
  591. static int fm10k_set_coalesce(struct net_device *dev,
  592. struct ethtool_coalesce *ec)
  593. {
  594. struct fm10k_intfc *interface = netdev_priv(dev);
  595. struct fm10k_q_vector *qv;
  596. u16 tx_itr, rx_itr;
  597. int i;
  598. /* verify limits */
  599. if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) ||
  600. (ec->tx_coalesce_usecs > FM10K_ITR_MAX))
  601. return -EINVAL;
  602. /* record settings */
  603. tx_itr = ec->tx_coalesce_usecs;
  604. rx_itr = ec->rx_coalesce_usecs;
  605. /* set initial values for adaptive ITR */
  606. if (ec->use_adaptive_tx_coalesce)
  607. tx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_10K;
  608. if (ec->use_adaptive_rx_coalesce)
  609. rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
  610. /* update interface */
  611. interface->tx_itr = tx_itr;
  612. interface->rx_itr = rx_itr;
  613. /* update q_vectors */
  614. for (i = 0; i < interface->num_q_vectors; i++) {
  615. qv = interface->q_vector[i];
  616. qv->tx.itr = tx_itr;
  617. qv->rx.itr = rx_itr;
  618. }
  619. return 0;
  620. }
  621. static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface,
  622. struct ethtool_rxnfc *cmd)
  623. {
  624. cmd->data = 0;
  625. /* Report default options for RSS on fm10k */
  626. switch (cmd->flow_type) {
  627. case TCP_V4_FLOW:
  628. case TCP_V6_FLOW:
  629. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  630. /* fall through */
  631. case UDP_V4_FLOW:
  632. if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
  633. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  634. /* fall through */
  635. case SCTP_V4_FLOW:
  636. case SCTP_V6_FLOW:
  637. case AH_ESP_V4_FLOW:
  638. case AH_ESP_V6_FLOW:
  639. case AH_V4_FLOW:
  640. case AH_V6_FLOW:
  641. case ESP_V4_FLOW:
  642. case ESP_V6_FLOW:
  643. case IPV4_FLOW:
  644. case IPV6_FLOW:
  645. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  646. break;
  647. case UDP_V6_FLOW:
  648. if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
  649. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  650. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  651. break;
  652. default:
  653. return -EINVAL;
  654. }
  655. return 0;
  656. }
  657. static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  658. u32 __always_unused *rule_locs)
  659. {
  660. struct fm10k_intfc *interface = netdev_priv(dev);
  661. int ret = -EOPNOTSUPP;
  662. switch (cmd->cmd) {
  663. case ETHTOOL_GRXRINGS:
  664. cmd->data = interface->num_rx_queues;
  665. ret = 0;
  666. break;
  667. case ETHTOOL_GRXFH:
  668. ret = fm10k_get_rss_hash_opts(interface, cmd);
  669. break;
  670. default:
  671. break;
  672. }
  673. return ret;
  674. }
  675. #define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
  676. FM10K_FLAG_RSS_FIELD_IPV6_UDP)
  677. static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface,
  678. struct ethtool_rxnfc *nfc)
  679. {
  680. u32 flags = interface->flags;
  681. /* RSS does not support anything other than hashing
  682. * to queues on src and dst IPs and ports
  683. */
  684. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  685. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  686. return -EINVAL;
  687. switch (nfc->flow_type) {
  688. case TCP_V4_FLOW:
  689. case TCP_V6_FLOW:
  690. if (!(nfc->data & RXH_IP_SRC) ||
  691. !(nfc->data & RXH_IP_DST) ||
  692. !(nfc->data & RXH_L4_B_0_1) ||
  693. !(nfc->data & RXH_L4_B_2_3))
  694. return -EINVAL;
  695. break;
  696. case UDP_V4_FLOW:
  697. if (!(nfc->data & RXH_IP_SRC) ||
  698. !(nfc->data & RXH_IP_DST))
  699. return -EINVAL;
  700. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  701. case 0:
  702. flags &= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP;
  703. break;
  704. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  705. flags |= FM10K_FLAG_RSS_FIELD_IPV4_UDP;
  706. break;
  707. default:
  708. return -EINVAL;
  709. }
  710. break;
  711. case UDP_V6_FLOW:
  712. if (!(nfc->data & RXH_IP_SRC) ||
  713. !(nfc->data & RXH_IP_DST))
  714. return -EINVAL;
  715. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  716. case 0:
  717. flags &= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP;
  718. break;
  719. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  720. flags |= FM10K_FLAG_RSS_FIELD_IPV6_UDP;
  721. break;
  722. default:
  723. return -EINVAL;
  724. }
  725. break;
  726. case AH_ESP_V4_FLOW:
  727. case AH_V4_FLOW:
  728. case ESP_V4_FLOW:
  729. case SCTP_V4_FLOW:
  730. case AH_ESP_V6_FLOW:
  731. case AH_V6_FLOW:
  732. case ESP_V6_FLOW:
  733. case SCTP_V6_FLOW:
  734. if (!(nfc->data & RXH_IP_SRC) ||
  735. !(nfc->data & RXH_IP_DST) ||
  736. (nfc->data & RXH_L4_B_0_1) ||
  737. (nfc->data & RXH_L4_B_2_3))
  738. return -EINVAL;
  739. break;
  740. default:
  741. return -EINVAL;
  742. }
  743. /* if we changed something we need to update flags */
  744. if (flags != interface->flags) {
  745. struct fm10k_hw *hw = &interface->hw;
  746. u32 mrqc;
  747. if ((flags & UDP_RSS_FLAGS) &&
  748. !(interface->flags & UDP_RSS_FLAGS))
  749. netif_warn(interface, drv, interface->netdev,
  750. "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
  751. interface->flags = flags;
  752. /* Perform hash on these packet types */
  753. mrqc = FM10K_MRQC_IPV4 |
  754. FM10K_MRQC_TCP_IPV4 |
  755. FM10K_MRQC_IPV6 |
  756. FM10K_MRQC_TCP_IPV6;
  757. if (flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
  758. mrqc |= FM10K_MRQC_UDP_IPV4;
  759. if (flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
  760. mrqc |= FM10K_MRQC_UDP_IPV6;
  761. fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
  762. }
  763. return 0;
  764. }
  765. static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  766. {
  767. struct fm10k_intfc *interface = netdev_priv(dev);
  768. int ret = -EOPNOTSUPP;
  769. switch (cmd->cmd) {
  770. case ETHTOOL_SRXFH:
  771. ret = fm10k_set_rss_hash_opt(interface, cmd);
  772. break;
  773. default:
  774. break;
  775. }
  776. return ret;
  777. }
  778. static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data)
  779. {
  780. struct fm10k_hw *hw = &interface->hw;
  781. struct fm10k_mbx_info *mbx = &hw->mbx;
  782. u32 attr_flag, test_msg[6];
  783. unsigned long timeout;
  784. int err;
  785. /* For now this is a VF only feature */
  786. if (hw->mac.type != fm10k_mac_vf)
  787. return 0;
  788. /* loop through both nested and unnested attribute types */
  789. for (attr_flag = (1 << FM10K_TEST_MSG_UNSET);
  790. attr_flag < (1 << (2 * FM10K_TEST_MSG_NESTED));
  791. attr_flag += attr_flag) {
  792. /* generate message to be tested */
  793. fm10k_tlv_msg_test_create(test_msg, attr_flag);
  794. fm10k_mbx_lock(interface);
  795. mbx->test_result = FM10K_NOT_IMPLEMENTED;
  796. err = mbx->ops.enqueue_tx(hw, mbx, test_msg);
  797. fm10k_mbx_unlock(interface);
  798. /* wait up to 1 second for response */
  799. timeout = jiffies + HZ;
  800. do {
  801. if (err < 0)
  802. goto err_out;
  803. usleep_range(500, 1000);
  804. fm10k_mbx_lock(interface);
  805. mbx->ops.process(hw, mbx);
  806. fm10k_mbx_unlock(interface);
  807. err = mbx->test_result;
  808. if (!err)
  809. break;
  810. } while (time_is_after_jiffies(timeout));
  811. /* reporting errors */
  812. if (err)
  813. goto err_out;
  814. }
  815. err_out:
  816. *data = err < 0 ? (attr_flag) : (err > 0);
  817. return err;
  818. }
  819. static void fm10k_self_test(struct net_device *dev,
  820. struct ethtool_test *eth_test, u64 *data)
  821. {
  822. struct fm10k_intfc *interface = netdev_priv(dev);
  823. struct fm10k_hw *hw = &interface->hw;
  824. memset(data, 0, sizeof(*data) * FM10K_TEST_LEN);
  825. if (FM10K_REMOVED(hw->hw_addr)) {
  826. netif_err(interface, drv, dev,
  827. "Interface removed - test blocked\n");
  828. eth_test->flags |= ETH_TEST_FL_FAILED;
  829. return;
  830. }
  831. if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX]))
  832. eth_test->flags |= ETH_TEST_FL_FAILED;
  833. }
  834. static u32 fm10k_get_priv_flags(struct net_device *netdev)
  835. {
  836. struct fm10k_intfc *interface = netdev_priv(netdev);
  837. u32 priv_flags = 0;
  838. if (interface->flags & FM10K_FLAG_DEBUG_STATS)
  839. priv_flags |= 1 << FM10K_PRV_FLAG_DEBUG_STATS;
  840. return priv_flags;
  841. }
  842. static int fm10k_set_priv_flags(struct net_device *netdev, u32 priv_flags)
  843. {
  844. struct fm10k_intfc *interface = netdev_priv(netdev);
  845. if (priv_flags >= (1 << FM10K_PRV_FLAG_LEN))
  846. return -EINVAL;
  847. if (priv_flags & (1 << FM10K_PRV_FLAG_DEBUG_STATS))
  848. interface->flags |= FM10K_FLAG_DEBUG_STATS;
  849. else
  850. interface->flags &= ~FM10K_FLAG_DEBUG_STATS;
  851. return 0;
  852. }
  853. static u32 fm10k_get_reta_size(struct net_device __always_unused *netdev)
  854. {
  855. return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG;
  856. }
  857. static int fm10k_get_reta(struct net_device *netdev, u32 *indir)
  858. {
  859. struct fm10k_intfc *interface = netdev_priv(netdev);
  860. int i;
  861. if (!indir)
  862. return 0;
  863. for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
  864. u32 reta = interface->reta[i];
  865. indir[0] = (reta << 24) >> 24;
  866. indir[1] = (reta << 16) >> 24;
  867. indir[2] = (reta << 8) >> 24;
  868. indir[3] = (reta) >> 24;
  869. }
  870. return 0;
  871. }
  872. static int fm10k_set_reta(struct net_device *netdev, const u32 *indir)
  873. {
  874. struct fm10k_intfc *interface = netdev_priv(netdev);
  875. struct fm10k_hw *hw = &interface->hw;
  876. int i;
  877. u16 rss_i;
  878. if (!indir)
  879. return 0;
  880. /* Verify user input. */
  881. rss_i = interface->ring_feature[RING_F_RSS].indices;
  882. for (i = fm10k_get_reta_size(netdev); i--;) {
  883. if (indir[i] < rss_i)
  884. continue;
  885. return -EINVAL;
  886. }
  887. /* record entries to reta table */
  888. for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
  889. u32 reta = indir[0] |
  890. (indir[1] << 8) |
  891. (indir[2] << 16) |
  892. (indir[3] << 24);
  893. if (interface->reta[i] == reta)
  894. continue;
  895. interface->reta[i] = reta;
  896. fm10k_write_reg(hw, FM10K_RETA(0, i), reta);
  897. }
  898. return 0;
  899. }
  900. static u32 fm10k_get_rssrk_size(struct net_device __always_unused *netdev)
  901. {
  902. return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG;
  903. }
  904. static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key,
  905. u8 *hfunc)
  906. {
  907. struct fm10k_intfc *interface = netdev_priv(netdev);
  908. int i, err;
  909. if (hfunc)
  910. *hfunc = ETH_RSS_HASH_TOP;
  911. err = fm10k_get_reta(netdev, indir);
  912. if (err || !key)
  913. return err;
  914. for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4)
  915. *(__le32 *)key = cpu_to_le32(interface->rssrk[i]);
  916. return 0;
  917. }
  918. static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir,
  919. const u8 *key, const u8 hfunc)
  920. {
  921. struct fm10k_intfc *interface = netdev_priv(netdev);
  922. struct fm10k_hw *hw = &interface->hw;
  923. int i, err;
  924. /* We do not allow change in unsupported parameters */
  925. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  926. return -EOPNOTSUPP;
  927. err = fm10k_set_reta(netdev, indir);
  928. if (err || !key)
  929. return err;
  930. for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) {
  931. u32 rssrk = le32_to_cpu(*(__le32 *)key);
  932. if (interface->rssrk[i] == rssrk)
  933. continue;
  934. interface->rssrk[i] = rssrk;
  935. fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk);
  936. }
  937. return 0;
  938. }
  939. static unsigned int fm10k_max_channels(struct net_device *dev)
  940. {
  941. struct fm10k_intfc *interface = netdev_priv(dev);
  942. unsigned int max_combined = interface->hw.mac.max_queues;
  943. u8 tcs = netdev_get_num_tc(dev);
  944. /* For QoS report channels per traffic class */
  945. if (tcs > 1)
  946. max_combined = 1 << (fls(max_combined / tcs) - 1);
  947. return max_combined;
  948. }
  949. static void fm10k_get_channels(struct net_device *dev,
  950. struct ethtool_channels *ch)
  951. {
  952. struct fm10k_intfc *interface = netdev_priv(dev);
  953. struct fm10k_hw *hw = &interface->hw;
  954. /* report maximum channels */
  955. ch->max_combined = fm10k_max_channels(dev);
  956. /* report info for other vector */
  957. ch->max_other = NON_Q_VECTORS(hw);
  958. ch->other_count = ch->max_other;
  959. /* record RSS queues */
  960. ch->combined_count = interface->ring_feature[RING_F_RSS].indices;
  961. }
  962. static int fm10k_set_channels(struct net_device *dev,
  963. struct ethtool_channels *ch)
  964. {
  965. struct fm10k_intfc *interface = netdev_priv(dev);
  966. unsigned int count = ch->combined_count;
  967. struct fm10k_hw *hw = &interface->hw;
  968. /* verify they are not requesting separate vectors */
  969. if (!count || ch->rx_count || ch->tx_count)
  970. return -EINVAL;
  971. /* verify other_count has not changed */
  972. if (ch->other_count != NON_Q_VECTORS(hw))
  973. return -EINVAL;
  974. /* verify the number of channels does not exceed hardware limits */
  975. if (count > fm10k_max_channels(dev))
  976. return -EINVAL;
  977. interface->ring_feature[RING_F_RSS].limit = count;
  978. /* use setup TC to update any traffic class queue mapping */
  979. return fm10k_setup_tc(dev, netdev_get_num_tc(dev));
  980. }
  981. static int fm10k_get_ts_info(struct net_device *dev,
  982. struct ethtool_ts_info *info)
  983. {
  984. struct fm10k_intfc *interface = netdev_priv(dev);
  985. info->so_timestamping =
  986. SOF_TIMESTAMPING_TX_SOFTWARE |
  987. SOF_TIMESTAMPING_RX_SOFTWARE |
  988. SOF_TIMESTAMPING_SOFTWARE |
  989. SOF_TIMESTAMPING_TX_HARDWARE |
  990. SOF_TIMESTAMPING_RX_HARDWARE |
  991. SOF_TIMESTAMPING_RAW_HARDWARE;
  992. if (interface->ptp_clock)
  993. info->phc_index = ptp_clock_index(interface->ptp_clock);
  994. else
  995. info->phc_index = -1;
  996. info->tx_types = (1 << HWTSTAMP_TX_OFF) |
  997. (1 << HWTSTAMP_TX_ON);
  998. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  999. (1 << HWTSTAMP_FILTER_ALL);
  1000. return 0;
  1001. }
  1002. static const struct ethtool_ops fm10k_ethtool_ops = {
  1003. .get_strings = fm10k_get_strings,
  1004. .get_sset_count = fm10k_get_sset_count,
  1005. .get_ethtool_stats = fm10k_get_ethtool_stats,
  1006. .get_drvinfo = fm10k_get_drvinfo,
  1007. .get_link = ethtool_op_get_link,
  1008. .get_pauseparam = fm10k_get_pauseparam,
  1009. .set_pauseparam = fm10k_set_pauseparam,
  1010. .get_msglevel = fm10k_get_msglevel,
  1011. .set_msglevel = fm10k_set_msglevel,
  1012. .get_ringparam = fm10k_get_ringparam,
  1013. .set_ringparam = fm10k_set_ringparam,
  1014. .get_coalesce = fm10k_get_coalesce,
  1015. .set_coalesce = fm10k_set_coalesce,
  1016. .get_rxnfc = fm10k_get_rxnfc,
  1017. .set_rxnfc = fm10k_set_rxnfc,
  1018. .get_regs = fm10k_get_regs,
  1019. .get_regs_len = fm10k_get_regs_len,
  1020. .self_test = fm10k_self_test,
  1021. .get_priv_flags = fm10k_get_priv_flags,
  1022. .set_priv_flags = fm10k_set_priv_flags,
  1023. .get_rxfh_indir_size = fm10k_get_reta_size,
  1024. .get_rxfh_key_size = fm10k_get_rssrk_size,
  1025. .get_rxfh = fm10k_get_rssh,
  1026. .set_rxfh = fm10k_set_rssh,
  1027. .get_channels = fm10k_get_channels,
  1028. .set_channels = fm10k_set_channels,
  1029. .get_ts_info = fm10k_get_ts_info,
  1030. };
  1031. void fm10k_set_ethtool_ops(struct net_device *dev)
  1032. {
  1033. dev->ethtool_ops = &fm10k_ethtool_ops;
  1034. }