fm10k_ethtool.c 31 KB

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