fm10k_ethtool.c 32 KB

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