fm10k_ethtool.c 29 KB

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