i40e_ethtool.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* ethtool support for i40e */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. struct i40e_stats {
  30. char stat_string[ETH_GSTRING_LEN];
  31. int sizeof_stat;
  32. int stat_offset;
  33. };
  34. #define I40E_STAT(_type, _name, _stat) { \
  35. .stat_string = _name, \
  36. .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
  37. .stat_offset = offsetof(_type, _stat) \
  38. }
  39. #define I40E_NETDEV_STAT(_net_stat) \
  40. I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
  41. #define I40E_PF_STAT(_name, _stat) \
  42. I40E_STAT(struct i40e_pf, _name, _stat)
  43. #define I40E_VSI_STAT(_name, _stat) \
  44. I40E_STAT(struct i40e_vsi, _name, _stat)
  45. #define I40E_VEB_STAT(_name, _stat) \
  46. I40E_STAT(struct i40e_veb, _name, _stat)
  47. static const struct i40e_stats i40e_gstrings_net_stats[] = {
  48. I40E_NETDEV_STAT(rx_packets),
  49. I40E_NETDEV_STAT(tx_packets),
  50. I40E_NETDEV_STAT(rx_bytes),
  51. I40E_NETDEV_STAT(tx_bytes),
  52. I40E_NETDEV_STAT(rx_errors),
  53. I40E_NETDEV_STAT(tx_errors),
  54. I40E_NETDEV_STAT(rx_dropped),
  55. I40E_NETDEV_STAT(tx_dropped),
  56. I40E_NETDEV_STAT(collisions),
  57. I40E_NETDEV_STAT(rx_length_errors),
  58. I40E_NETDEV_STAT(rx_crc_errors),
  59. };
  60. static const struct i40e_stats i40e_gstrings_veb_stats[] = {
  61. I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
  62. I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
  63. I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
  64. I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
  65. I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
  66. I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
  67. I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
  68. I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
  69. I40E_VEB_STAT("rx_discards", stats.rx_discards),
  70. I40E_VEB_STAT("tx_discards", stats.tx_discards),
  71. I40E_VEB_STAT("tx_errors", stats.tx_errors),
  72. I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
  73. };
  74. static const struct i40e_stats i40e_gstrings_misc_stats[] = {
  75. I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
  76. I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
  77. I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
  78. I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
  79. I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
  80. I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
  81. I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
  82. };
  83. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  84. struct ethtool_rxnfc *cmd);
  85. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  86. * but they are separate. This device supports Virtualization, and
  87. * as such might have several netdevs supporting VMDq and FCoE going
  88. * through a single port. The NETDEV_STATs are for individual netdevs
  89. * seen at the top of the stack, and the PF_STATs are for the physical
  90. * function at the bottom of the stack hosting those netdevs.
  91. *
  92. * The PF_STATs are appended to the netdev stats only when ethtool -S
  93. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  94. */
  95. static struct i40e_stats i40e_gstrings_stats[] = {
  96. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  97. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  98. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  99. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  100. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  101. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  102. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  103. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  104. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  105. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  106. I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
  107. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  108. I40E_PF_STAT("crc_errors", stats.crc_errors),
  109. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  110. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  111. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  112. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  113. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  114. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  115. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  116. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  117. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  118. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  119. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  120. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  121. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  122. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  123. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  124. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  125. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  126. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  127. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  128. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  129. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  130. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  131. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  132. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  133. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  134. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  135. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  136. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  137. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  138. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  139. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  140. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  141. /* LPI stats */
  142. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  143. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  144. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  145. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  146. };
  147. #define I40E_QUEUE_STATS_LEN(n) \
  148. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  149. * 2 /* Tx and Rx together */ \
  150. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  151. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  152. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  153. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  154. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  155. I40E_MISC_STATS_LEN + \
  156. I40E_QUEUE_STATS_LEN((n)))
  157. #define I40E_PFC_STATS_LEN ( \
  158. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  159. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  160. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  161. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  162. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  163. / sizeof(u64))
  164. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  165. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  166. I40E_PFC_STATS_LEN + \
  167. I40E_VSI_STATS_LEN((n)))
  168. enum i40e_ethtool_test_id {
  169. I40E_ETH_TEST_REG = 0,
  170. I40E_ETH_TEST_EEPROM,
  171. I40E_ETH_TEST_INTR,
  172. I40E_ETH_TEST_LOOPBACK,
  173. I40E_ETH_TEST_LINK,
  174. };
  175. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  176. "Register test (offline)",
  177. "Eeprom test (offline)",
  178. "Interrupt test (offline)",
  179. "Loopback test (offline)",
  180. "Link test (on/offline)"
  181. };
  182. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  183. /**
  184. * i40e_get_settings - Get Link Speed and Duplex settings
  185. * @netdev: network interface device structure
  186. * @ecmd: ethtool command
  187. *
  188. * Reports speed/duplex settings based on media_type
  189. **/
  190. static int i40e_get_settings(struct net_device *netdev,
  191. struct ethtool_cmd *ecmd)
  192. {
  193. struct i40e_netdev_priv *np = netdev_priv(netdev);
  194. struct i40e_pf *pf = np->vsi->back;
  195. struct i40e_hw *hw = &pf->hw;
  196. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  197. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  198. u32 link_speed = hw_link_info->link_speed;
  199. /* hardware is either in 40G mode or 10G mode
  200. * NOTE: this section initializes supported and advertising
  201. */
  202. if (!link_up) {
  203. /* link is down and the driver needs to fall back on
  204. * device ID to determine what kinds of info to display,
  205. * it's mostly a guess that may change when link is up
  206. */
  207. switch (hw->device_id) {
  208. case I40E_DEV_ID_QSFP_A:
  209. case I40E_DEV_ID_QSFP_B:
  210. case I40E_DEV_ID_QSFP_C:
  211. /* pluggable QSFP */
  212. ecmd->supported = SUPPORTED_40000baseSR4_Full |
  213. SUPPORTED_40000baseCR4_Full |
  214. SUPPORTED_40000baseLR4_Full;
  215. ecmd->advertising = ADVERTISED_40000baseSR4_Full |
  216. ADVERTISED_40000baseCR4_Full |
  217. ADVERTISED_40000baseLR4_Full;
  218. break;
  219. case I40E_DEV_ID_KX_B:
  220. /* backplane 40G */
  221. ecmd->supported = SUPPORTED_40000baseKR4_Full;
  222. ecmd->advertising = ADVERTISED_40000baseKR4_Full;
  223. break;
  224. case I40E_DEV_ID_KX_C:
  225. /* backplane 10G */
  226. ecmd->supported = SUPPORTED_10000baseKR_Full;
  227. ecmd->advertising = ADVERTISED_10000baseKR_Full;
  228. break;
  229. default:
  230. /* all the rest are 10G/1G */
  231. ecmd->supported = SUPPORTED_10000baseT_Full |
  232. SUPPORTED_1000baseT_Full;
  233. ecmd->advertising = ADVERTISED_10000baseT_Full |
  234. ADVERTISED_1000baseT_Full;
  235. break;
  236. }
  237. /* skip phy_type use as it is zero when link is down */
  238. goto no_valid_phy_type;
  239. }
  240. switch (hw_link_info->phy_type) {
  241. case I40E_PHY_TYPE_40GBASE_CR4:
  242. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  243. ecmd->supported = SUPPORTED_Autoneg |
  244. SUPPORTED_40000baseCR4_Full;
  245. ecmd->advertising = ADVERTISED_Autoneg |
  246. ADVERTISED_40000baseCR4_Full;
  247. break;
  248. case I40E_PHY_TYPE_40GBASE_KR4:
  249. ecmd->supported = SUPPORTED_Autoneg |
  250. SUPPORTED_40000baseKR4_Full;
  251. ecmd->advertising = ADVERTISED_Autoneg |
  252. ADVERTISED_40000baseKR4_Full;
  253. break;
  254. case I40E_PHY_TYPE_40GBASE_SR4:
  255. case I40E_PHY_TYPE_XLPPI:
  256. case I40E_PHY_TYPE_XLAUI:
  257. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  258. break;
  259. case I40E_PHY_TYPE_40GBASE_LR4:
  260. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  261. break;
  262. case I40E_PHY_TYPE_10GBASE_KX4:
  263. ecmd->supported = SUPPORTED_Autoneg |
  264. SUPPORTED_10000baseKX4_Full;
  265. ecmd->advertising = ADVERTISED_Autoneg |
  266. ADVERTISED_10000baseKX4_Full;
  267. break;
  268. case I40E_PHY_TYPE_10GBASE_KR:
  269. ecmd->supported = SUPPORTED_Autoneg |
  270. SUPPORTED_10000baseKR_Full;
  271. ecmd->advertising = ADVERTISED_Autoneg |
  272. ADVERTISED_10000baseKR_Full;
  273. break;
  274. case I40E_PHY_TYPE_10GBASE_SR:
  275. case I40E_PHY_TYPE_10GBASE_LR:
  276. ecmd->supported = SUPPORTED_10000baseT_Full;
  277. break;
  278. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  279. case I40E_PHY_TYPE_10GBASE_CR1:
  280. case I40E_PHY_TYPE_10GBASE_T:
  281. ecmd->supported = SUPPORTED_Autoneg |
  282. SUPPORTED_10000baseT_Full;
  283. ecmd->advertising = ADVERTISED_Autoneg |
  284. ADVERTISED_10000baseT_Full;
  285. break;
  286. case I40E_PHY_TYPE_XAUI:
  287. case I40E_PHY_TYPE_XFI:
  288. case I40E_PHY_TYPE_SFI:
  289. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  290. ecmd->supported = SUPPORTED_10000baseT_Full;
  291. break;
  292. case I40E_PHY_TYPE_1000BASE_KX:
  293. case I40E_PHY_TYPE_1000BASE_T:
  294. ecmd->supported = SUPPORTED_Autoneg |
  295. SUPPORTED_1000baseT_Full;
  296. ecmd->advertising = ADVERTISED_Autoneg |
  297. ADVERTISED_1000baseT_Full;
  298. break;
  299. case I40E_PHY_TYPE_100BASE_TX:
  300. ecmd->supported = SUPPORTED_Autoneg |
  301. SUPPORTED_100baseT_Full;
  302. ecmd->advertising = ADVERTISED_Autoneg |
  303. ADVERTISED_100baseT_Full;
  304. break;
  305. case I40E_PHY_TYPE_SGMII:
  306. ecmd->supported = SUPPORTED_Autoneg |
  307. SUPPORTED_1000baseT_Full |
  308. SUPPORTED_100baseT_Full;
  309. ecmd->advertising = ADVERTISED_Autoneg |
  310. ADVERTISED_1000baseT_Full |
  311. ADVERTISED_100baseT_Full;
  312. break;
  313. default:
  314. /* if we got here and link is up something bad is afoot */
  315. WARN_ON(link_up);
  316. }
  317. no_valid_phy_type:
  318. /* this is if autoneg is enabled or disabled */
  319. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  320. AUTONEG_ENABLE : AUTONEG_DISABLE);
  321. switch (hw->phy.media_type) {
  322. case I40E_MEDIA_TYPE_BACKPLANE:
  323. ecmd->supported |= SUPPORTED_Autoneg |
  324. SUPPORTED_Backplane;
  325. ecmd->advertising |= ADVERTISED_Autoneg |
  326. ADVERTISED_Backplane;
  327. ecmd->port = PORT_NONE;
  328. break;
  329. case I40E_MEDIA_TYPE_BASET:
  330. ecmd->supported |= SUPPORTED_TP;
  331. ecmd->advertising |= ADVERTISED_TP;
  332. ecmd->port = PORT_TP;
  333. break;
  334. case I40E_MEDIA_TYPE_DA:
  335. case I40E_MEDIA_TYPE_CX4:
  336. ecmd->supported |= SUPPORTED_FIBRE;
  337. ecmd->advertising |= ADVERTISED_FIBRE;
  338. ecmd->port = PORT_DA;
  339. break;
  340. case I40E_MEDIA_TYPE_FIBER:
  341. ecmd->supported |= SUPPORTED_FIBRE;
  342. ecmd->port = PORT_FIBRE;
  343. break;
  344. case I40E_MEDIA_TYPE_UNKNOWN:
  345. default:
  346. ecmd->port = PORT_OTHER;
  347. break;
  348. }
  349. ecmd->transceiver = XCVR_EXTERNAL;
  350. ecmd->supported |= SUPPORTED_Pause;
  351. switch (hw->fc.current_mode) {
  352. case I40E_FC_FULL:
  353. ecmd->advertising |= ADVERTISED_Pause;
  354. break;
  355. case I40E_FC_TX_PAUSE:
  356. ecmd->advertising |= ADVERTISED_Asym_Pause;
  357. break;
  358. case I40E_FC_RX_PAUSE:
  359. ecmd->advertising |= (ADVERTISED_Pause |
  360. ADVERTISED_Asym_Pause);
  361. break;
  362. default:
  363. ecmd->advertising &= ~(ADVERTISED_Pause |
  364. ADVERTISED_Asym_Pause);
  365. break;
  366. }
  367. if (link_up) {
  368. switch (link_speed) {
  369. case I40E_LINK_SPEED_40GB:
  370. /* need a SPEED_40000 in ethtool.h */
  371. ethtool_cmd_speed_set(ecmd, 40000);
  372. break;
  373. case I40E_LINK_SPEED_10GB:
  374. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  375. break;
  376. case I40E_LINK_SPEED_1GB:
  377. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  378. break;
  379. default:
  380. break;
  381. }
  382. ecmd->duplex = DUPLEX_FULL;
  383. } else {
  384. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  385. ecmd->duplex = DUPLEX_UNKNOWN;
  386. }
  387. return 0;
  388. }
  389. static int i40e_nway_reset(struct net_device *netdev)
  390. {
  391. /* restart autonegotiation */
  392. struct i40e_netdev_priv *np = netdev_priv(netdev);
  393. struct i40e_pf *pf = np->vsi->back;
  394. struct i40e_hw *hw = &pf->hw;
  395. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  396. i40e_status ret = 0;
  397. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  398. if (ret) {
  399. netdev_info(netdev, "link restart failed, aq_err=%d\n",
  400. pf->hw.aq.asq_last_status);
  401. return -EIO;
  402. }
  403. return 0;
  404. }
  405. /**
  406. * i40e_get_pauseparam - Get Flow Control status
  407. * Return tx/rx-pause status
  408. **/
  409. static void i40e_get_pauseparam(struct net_device *netdev,
  410. struct ethtool_pauseparam *pause)
  411. {
  412. struct i40e_netdev_priv *np = netdev_priv(netdev);
  413. struct i40e_pf *pf = np->vsi->back;
  414. struct i40e_hw *hw = &pf->hw;
  415. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  416. pause->autoneg =
  417. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  418. AUTONEG_ENABLE : AUTONEG_DISABLE);
  419. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  420. pause->rx_pause = 1;
  421. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  422. pause->tx_pause = 1;
  423. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  424. pause->rx_pause = 1;
  425. pause->tx_pause = 1;
  426. }
  427. }
  428. /**
  429. * i40e_set_pauseparam - Set Flow Control parameter
  430. * @netdev: network interface device structure
  431. * @pause: return tx/rx flow control status
  432. **/
  433. static int i40e_set_pauseparam(struct net_device *netdev,
  434. struct ethtool_pauseparam *pause)
  435. {
  436. struct i40e_netdev_priv *np = netdev_priv(netdev);
  437. struct i40e_pf *pf = np->vsi->back;
  438. struct i40e_vsi *vsi = np->vsi;
  439. struct i40e_hw *hw = &pf->hw;
  440. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  441. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  442. i40e_status status;
  443. u8 aq_failures;
  444. int err;
  445. if (vsi != pf->vsi[pf->lan_vsi])
  446. return -EOPNOTSUPP;
  447. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  448. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  449. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  450. return -EOPNOTSUPP;
  451. }
  452. /* If we have link and don't have autoneg */
  453. if (!test_bit(__I40E_DOWN, &pf->state) &&
  454. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  455. /* Send message that it might not necessarily work*/
  456. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  457. }
  458. if (hw->fc.current_mode == I40E_FC_PFC) {
  459. netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
  460. return -EOPNOTSUPP;
  461. }
  462. if (pause->rx_pause && pause->tx_pause)
  463. hw->fc.requested_mode = I40E_FC_FULL;
  464. else if (pause->rx_pause && !pause->tx_pause)
  465. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  466. else if (!pause->rx_pause && pause->tx_pause)
  467. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  468. else if (!pause->rx_pause && !pause->tx_pause)
  469. hw->fc.requested_mode = I40E_FC_NONE;
  470. else
  471. return -EINVAL;
  472. /* Set the fc mode and only restart an if link is up*/
  473. status = i40e_set_fc(hw, &aq_failures, link_up);
  474. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  475. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
  476. status, hw->aq.asq_last_status);
  477. err = -EAGAIN;
  478. }
  479. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  480. netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
  481. status, hw->aq.asq_last_status);
  482. err = -EAGAIN;
  483. }
  484. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  485. netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
  486. status, hw->aq.asq_last_status);
  487. err = -EAGAIN;
  488. }
  489. if (!test_bit(__I40E_DOWN, &pf->state))
  490. return i40e_nway_reset(netdev);
  491. return err;
  492. }
  493. static u32 i40e_get_msglevel(struct net_device *netdev)
  494. {
  495. struct i40e_netdev_priv *np = netdev_priv(netdev);
  496. struct i40e_pf *pf = np->vsi->back;
  497. return pf->msg_enable;
  498. }
  499. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  500. {
  501. struct i40e_netdev_priv *np = netdev_priv(netdev);
  502. struct i40e_pf *pf = np->vsi->back;
  503. if (I40E_DEBUG_USER & data)
  504. pf->hw.debug_mask = data;
  505. pf->msg_enable = data;
  506. }
  507. static int i40e_get_regs_len(struct net_device *netdev)
  508. {
  509. int reg_count = 0;
  510. int i;
  511. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  512. reg_count += i40e_reg_list[i].elements;
  513. return reg_count * sizeof(u32);
  514. }
  515. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  516. void *p)
  517. {
  518. struct i40e_netdev_priv *np = netdev_priv(netdev);
  519. struct i40e_pf *pf = np->vsi->back;
  520. struct i40e_hw *hw = &pf->hw;
  521. u32 *reg_buf = p;
  522. int i, j, ri;
  523. u32 reg;
  524. /* Tell ethtool which driver-version-specific regs output we have.
  525. *
  526. * At some point, if we have ethtool doing special formatting of
  527. * this data, it will rely on this version number to know how to
  528. * interpret things. Hence, this needs to be updated if/when the
  529. * diags register table is changed.
  530. */
  531. regs->version = 1;
  532. /* loop through the diags reg table for what to print */
  533. ri = 0;
  534. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  535. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  536. reg = i40e_reg_list[i].offset
  537. + (j * i40e_reg_list[i].stride);
  538. reg_buf[ri++] = rd32(hw, reg);
  539. }
  540. }
  541. }
  542. static int i40e_get_eeprom(struct net_device *netdev,
  543. struct ethtool_eeprom *eeprom, u8 *bytes)
  544. {
  545. struct i40e_netdev_priv *np = netdev_priv(netdev);
  546. struct i40e_hw *hw = &np->vsi->back->hw;
  547. struct i40e_pf *pf = np->vsi->back;
  548. int ret_val = 0, len;
  549. u8 *eeprom_buff;
  550. u16 i, sectors;
  551. bool last;
  552. #define I40E_NVM_SECTOR_SIZE 4096
  553. if (eeprom->len == 0)
  554. return -EINVAL;
  555. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  556. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  557. if (!eeprom_buff)
  558. return -ENOMEM;
  559. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  560. if (ret_val) {
  561. dev_info(&pf->pdev->dev,
  562. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  563. ret_val, hw->aq.asq_last_status);
  564. goto free_buff;
  565. }
  566. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  567. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  568. len = I40E_NVM_SECTOR_SIZE;
  569. last = false;
  570. for (i = 0; i < sectors; i++) {
  571. if (i == (sectors - 1)) {
  572. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  573. last = true;
  574. }
  575. ret_val = i40e_aq_read_nvm(hw, 0x0,
  576. eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  577. len,
  578. eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  579. last, NULL);
  580. if (ret_val) {
  581. dev_info(&pf->pdev->dev,
  582. "read NVM failed err=%d status=0x%x\n",
  583. ret_val, hw->aq.asq_last_status);
  584. goto release_nvm;
  585. }
  586. }
  587. release_nvm:
  588. i40e_release_nvm(hw);
  589. memcpy(bytes, eeprom_buff, eeprom->len);
  590. free_buff:
  591. kfree(eeprom_buff);
  592. return ret_val;
  593. }
  594. static int i40e_get_eeprom_len(struct net_device *netdev)
  595. {
  596. struct i40e_netdev_priv *np = netdev_priv(netdev);
  597. struct i40e_hw *hw = &np->vsi->back->hw;
  598. u32 val;
  599. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  600. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  601. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  602. /* register returns value in power of 2, 64Kbyte chunks. */
  603. val = (64 * 1024) * (1 << val);
  604. return val;
  605. }
  606. static void i40e_get_drvinfo(struct net_device *netdev,
  607. struct ethtool_drvinfo *drvinfo)
  608. {
  609. struct i40e_netdev_priv *np = netdev_priv(netdev);
  610. struct i40e_vsi *vsi = np->vsi;
  611. struct i40e_pf *pf = vsi->back;
  612. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  613. strlcpy(drvinfo->version, i40e_driver_version_str,
  614. sizeof(drvinfo->version));
  615. strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
  616. sizeof(drvinfo->fw_version));
  617. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  618. sizeof(drvinfo->bus_info));
  619. }
  620. static void i40e_get_ringparam(struct net_device *netdev,
  621. struct ethtool_ringparam *ring)
  622. {
  623. struct i40e_netdev_priv *np = netdev_priv(netdev);
  624. struct i40e_pf *pf = np->vsi->back;
  625. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  626. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  627. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  628. ring->rx_mini_max_pending = 0;
  629. ring->rx_jumbo_max_pending = 0;
  630. ring->rx_pending = vsi->rx_rings[0]->count;
  631. ring->tx_pending = vsi->tx_rings[0]->count;
  632. ring->rx_mini_pending = 0;
  633. ring->rx_jumbo_pending = 0;
  634. }
  635. static int i40e_set_ringparam(struct net_device *netdev,
  636. struct ethtool_ringparam *ring)
  637. {
  638. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  639. struct i40e_netdev_priv *np = netdev_priv(netdev);
  640. struct i40e_vsi *vsi = np->vsi;
  641. struct i40e_pf *pf = vsi->back;
  642. u32 new_rx_count, new_tx_count;
  643. int i, err = 0;
  644. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  645. return -EINVAL;
  646. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  647. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  648. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  649. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  650. netdev_info(netdev,
  651. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  652. ring->tx_pending, ring->rx_pending,
  653. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  654. return -EINVAL;
  655. }
  656. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  657. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  658. /* if nothing to do return success */
  659. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  660. (new_rx_count == vsi->rx_rings[0]->count))
  661. return 0;
  662. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  663. usleep_range(1000, 2000);
  664. if (!netif_running(vsi->netdev)) {
  665. /* simple case - set for the next time the netdev is started */
  666. for (i = 0; i < vsi->num_queue_pairs; i++) {
  667. vsi->tx_rings[i]->count = new_tx_count;
  668. vsi->rx_rings[i]->count = new_rx_count;
  669. }
  670. goto done;
  671. }
  672. /* We can't just free everything and then setup again,
  673. * because the ISRs in MSI-X mode get passed pointers
  674. * to the Tx and Rx ring structs.
  675. */
  676. /* alloc updated Tx resources */
  677. if (new_tx_count != vsi->tx_rings[0]->count) {
  678. netdev_info(netdev,
  679. "Changing Tx descriptor count from %d to %d.\n",
  680. vsi->tx_rings[0]->count, new_tx_count);
  681. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  682. sizeof(struct i40e_ring), GFP_KERNEL);
  683. if (!tx_rings) {
  684. err = -ENOMEM;
  685. goto done;
  686. }
  687. for (i = 0; i < vsi->num_queue_pairs; i++) {
  688. /* clone ring and setup updated count */
  689. tx_rings[i] = *vsi->tx_rings[i];
  690. tx_rings[i].count = new_tx_count;
  691. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  692. if (err) {
  693. while (i) {
  694. i--;
  695. i40e_free_tx_resources(&tx_rings[i]);
  696. }
  697. kfree(tx_rings);
  698. tx_rings = NULL;
  699. goto done;
  700. }
  701. }
  702. }
  703. /* alloc updated Rx resources */
  704. if (new_rx_count != vsi->rx_rings[0]->count) {
  705. netdev_info(netdev,
  706. "Changing Rx descriptor count from %d to %d\n",
  707. vsi->rx_rings[0]->count, new_rx_count);
  708. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  709. sizeof(struct i40e_ring), GFP_KERNEL);
  710. if (!rx_rings) {
  711. err = -ENOMEM;
  712. goto free_tx;
  713. }
  714. for (i = 0; i < vsi->num_queue_pairs; i++) {
  715. /* clone ring and setup updated count */
  716. rx_rings[i] = *vsi->rx_rings[i];
  717. rx_rings[i].count = new_rx_count;
  718. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  719. if (err) {
  720. while (i) {
  721. i--;
  722. i40e_free_rx_resources(&rx_rings[i]);
  723. }
  724. kfree(rx_rings);
  725. rx_rings = NULL;
  726. goto free_tx;
  727. }
  728. }
  729. }
  730. /* Bring interface down, copy in the new ring info,
  731. * then restore the interface
  732. */
  733. i40e_down(vsi);
  734. if (tx_rings) {
  735. for (i = 0; i < vsi->num_queue_pairs; i++) {
  736. i40e_free_tx_resources(vsi->tx_rings[i]);
  737. *vsi->tx_rings[i] = tx_rings[i];
  738. }
  739. kfree(tx_rings);
  740. tx_rings = NULL;
  741. }
  742. if (rx_rings) {
  743. for (i = 0; i < vsi->num_queue_pairs; i++) {
  744. i40e_free_rx_resources(vsi->rx_rings[i]);
  745. *vsi->rx_rings[i] = rx_rings[i];
  746. }
  747. kfree(rx_rings);
  748. rx_rings = NULL;
  749. }
  750. i40e_up(vsi);
  751. free_tx:
  752. /* error cleanup if the Rx allocations failed after getting Tx */
  753. if (tx_rings) {
  754. for (i = 0; i < vsi->num_queue_pairs; i++)
  755. i40e_free_tx_resources(&tx_rings[i]);
  756. kfree(tx_rings);
  757. tx_rings = NULL;
  758. }
  759. done:
  760. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  761. return err;
  762. }
  763. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  764. {
  765. struct i40e_netdev_priv *np = netdev_priv(netdev);
  766. struct i40e_vsi *vsi = np->vsi;
  767. struct i40e_pf *pf = vsi->back;
  768. switch (sset) {
  769. case ETH_SS_TEST:
  770. return I40E_TEST_LEN;
  771. case ETH_SS_STATS:
  772. if (vsi == pf->vsi[pf->lan_vsi]) {
  773. int len = I40E_PF_STATS_LEN(netdev);
  774. if (pf->lan_veb != I40E_NO_VEB)
  775. len += I40E_VEB_STATS_LEN;
  776. return len;
  777. } else {
  778. return I40E_VSI_STATS_LEN(netdev);
  779. }
  780. default:
  781. return -EOPNOTSUPP;
  782. }
  783. }
  784. static void i40e_get_ethtool_stats(struct net_device *netdev,
  785. struct ethtool_stats *stats, u64 *data)
  786. {
  787. struct i40e_netdev_priv *np = netdev_priv(netdev);
  788. struct i40e_ring *tx_ring, *rx_ring;
  789. struct i40e_vsi *vsi = np->vsi;
  790. struct i40e_pf *pf = vsi->back;
  791. int i = 0;
  792. char *p;
  793. int j;
  794. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  795. unsigned int start;
  796. i40e_update_stats(vsi);
  797. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  798. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  799. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  800. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  801. }
  802. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  803. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  804. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  805. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  806. }
  807. rcu_read_lock();
  808. for (j = 0; j < vsi->num_queue_pairs; j++) {
  809. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  810. if (!tx_ring)
  811. continue;
  812. /* process Tx ring statistics */
  813. do {
  814. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  815. data[i] = tx_ring->stats.packets;
  816. data[i + 1] = tx_ring->stats.bytes;
  817. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  818. i += 2;
  819. /* Rx ring is the 2nd half of the queue pair */
  820. rx_ring = &tx_ring[1];
  821. do {
  822. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  823. data[i] = rx_ring->stats.packets;
  824. data[i + 1] = rx_ring->stats.bytes;
  825. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  826. i += 2;
  827. }
  828. rcu_read_unlock();
  829. if (vsi != pf->vsi[pf->lan_vsi])
  830. return;
  831. if (pf->lan_veb != I40E_NO_VEB) {
  832. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  833. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  834. p = (char *)veb;
  835. p += i40e_gstrings_veb_stats[j].stat_offset;
  836. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  837. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  838. }
  839. }
  840. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  841. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  842. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  843. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  844. }
  845. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  846. data[i++] = pf->stats.priority_xon_tx[j];
  847. data[i++] = pf->stats.priority_xoff_tx[j];
  848. }
  849. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  850. data[i++] = pf->stats.priority_xon_rx[j];
  851. data[i++] = pf->stats.priority_xoff_rx[j];
  852. }
  853. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  854. data[i++] = pf->stats.priority_xon_2_xoff[j];
  855. }
  856. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  857. u8 *data)
  858. {
  859. struct i40e_netdev_priv *np = netdev_priv(netdev);
  860. struct i40e_vsi *vsi = np->vsi;
  861. struct i40e_pf *pf = vsi->back;
  862. char *p = (char *)data;
  863. int i;
  864. switch (stringset) {
  865. case ETH_SS_TEST:
  866. for (i = 0; i < I40E_TEST_LEN; i++) {
  867. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  868. data += ETH_GSTRING_LEN;
  869. }
  870. break;
  871. case ETH_SS_STATS:
  872. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  873. snprintf(p, ETH_GSTRING_LEN, "%s",
  874. i40e_gstrings_net_stats[i].stat_string);
  875. p += ETH_GSTRING_LEN;
  876. }
  877. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  878. snprintf(p, ETH_GSTRING_LEN, "%s",
  879. i40e_gstrings_misc_stats[i].stat_string);
  880. p += ETH_GSTRING_LEN;
  881. }
  882. for (i = 0; i < vsi->num_queue_pairs; i++) {
  883. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  884. p += ETH_GSTRING_LEN;
  885. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  886. p += ETH_GSTRING_LEN;
  887. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  888. p += ETH_GSTRING_LEN;
  889. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  890. p += ETH_GSTRING_LEN;
  891. }
  892. if (vsi != pf->vsi[pf->lan_vsi])
  893. return;
  894. if (pf->lan_veb != I40E_NO_VEB) {
  895. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  896. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  897. i40e_gstrings_veb_stats[i].stat_string);
  898. p += ETH_GSTRING_LEN;
  899. }
  900. }
  901. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  902. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  903. i40e_gstrings_stats[i].stat_string);
  904. p += ETH_GSTRING_LEN;
  905. }
  906. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  907. snprintf(p, ETH_GSTRING_LEN,
  908. "port.tx_priority_%u_xon", i);
  909. p += ETH_GSTRING_LEN;
  910. snprintf(p, ETH_GSTRING_LEN,
  911. "port.tx_priority_%u_xoff", i);
  912. p += ETH_GSTRING_LEN;
  913. }
  914. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  915. snprintf(p, ETH_GSTRING_LEN,
  916. "port.rx_priority_%u_xon", i);
  917. p += ETH_GSTRING_LEN;
  918. snprintf(p, ETH_GSTRING_LEN,
  919. "port.rx_priority_%u_xoff", i);
  920. p += ETH_GSTRING_LEN;
  921. }
  922. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  923. snprintf(p, ETH_GSTRING_LEN,
  924. "port.rx_priority_%u_xon_2_xoff", i);
  925. p += ETH_GSTRING_LEN;
  926. }
  927. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  928. break;
  929. }
  930. }
  931. static int i40e_get_ts_info(struct net_device *dev,
  932. struct ethtool_ts_info *info)
  933. {
  934. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  935. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  936. SOF_TIMESTAMPING_RX_SOFTWARE |
  937. SOF_TIMESTAMPING_SOFTWARE |
  938. SOF_TIMESTAMPING_TX_HARDWARE |
  939. SOF_TIMESTAMPING_RX_HARDWARE |
  940. SOF_TIMESTAMPING_RAW_HARDWARE;
  941. if (pf->ptp_clock)
  942. info->phc_index = ptp_clock_index(pf->ptp_clock);
  943. else
  944. info->phc_index = -1;
  945. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  946. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  947. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  948. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  949. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  950. (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  951. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  952. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  953. (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  954. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  955. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  956. (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
  957. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  958. return 0;
  959. }
  960. static int i40e_link_test(struct net_device *netdev, u64 *data)
  961. {
  962. struct i40e_netdev_priv *np = netdev_priv(netdev);
  963. struct i40e_pf *pf = np->vsi->back;
  964. netif_info(pf, hw, netdev, "link test\n");
  965. if (i40e_get_link_status(&pf->hw))
  966. *data = 0;
  967. else
  968. *data = 1;
  969. return *data;
  970. }
  971. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  972. {
  973. struct i40e_netdev_priv *np = netdev_priv(netdev);
  974. struct i40e_pf *pf = np->vsi->back;
  975. netif_info(pf, hw, netdev, "register test\n");
  976. *data = i40e_diag_reg_test(&pf->hw);
  977. return *data;
  978. }
  979. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  980. {
  981. struct i40e_netdev_priv *np = netdev_priv(netdev);
  982. struct i40e_pf *pf = np->vsi->back;
  983. netif_info(pf, hw, netdev, "eeprom test\n");
  984. *data = i40e_diag_eeprom_test(&pf->hw);
  985. return *data;
  986. }
  987. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  988. {
  989. struct i40e_netdev_priv *np = netdev_priv(netdev);
  990. struct i40e_pf *pf = np->vsi->back;
  991. u16 swc_old = pf->sw_int_count;
  992. netif_info(pf, hw, netdev, "interrupt test\n");
  993. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  994. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  995. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
  996. usleep_range(1000, 2000);
  997. *data = (swc_old == pf->sw_int_count);
  998. return *data;
  999. }
  1000. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  1001. {
  1002. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1003. struct i40e_pf *pf = np->vsi->back;
  1004. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  1005. *data = 0;
  1006. return *data;
  1007. }
  1008. static void i40e_diag_test(struct net_device *netdev,
  1009. struct ethtool_test *eth_test, u64 *data)
  1010. {
  1011. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1012. struct i40e_pf *pf = np->vsi->back;
  1013. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1014. /* Offline tests */
  1015. netif_info(pf, drv, netdev, "offline testing starting\n");
  1016. set_bit(__I40E_TESTING, &pf->state);
  1017. /* Link test performed before hardware reset
  1018. * so autoneg doesn't interfere with test result
  1019. */
  1020. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1021. eth_test->flags |= ETH_TEST_FL_FAILED;
  1022. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1023. eth_test->flags |= ETH_TEST_FL_FAILED;
  1024. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1025. eth_test->flags |= ETH_TEST_FL_FAILED;
  1026. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  1027. eth_test->flags |= ETH_TEST_FL_FAILED;
  1028. /* run reg test last, a reset is required after it */
  1029. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1030. eth_test->flags |= ETH_TEST_FL_FAILED;
  1031. clear_bit(__I40E_TESTING, &pf->state);
  1032. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  1033. } else {
  1034. /* Online tests */
  1035. netif_info(pf, drv, netdev, "online testing starting\n");
  1036. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1037. eth_test->flags |= ETH_TEST_FL_FAILED;
  1038. /* Offline only tests, not run in online; pass by default */
  1039. data[I40E_ETH_TEST_REG] = 0;
  1040. data[I40E_ETH_TEST_EEPROM] = 0;
  1041. data[I40E_ETH_TEST_INTR] = 0;
  1042. data[I40E_ETH_TEST_LOOPBACK] = 0;
  1043. }
  1044. netif_info(pf, drv, netdev, "testing finished\n");
  1045. }
  1046. static void i40e_get_wol(struct net_device *netdev,
  1047. struct ethtool_wolinfo *wol)
  1048. {
  1049. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1050. struct i40e_pf *pf = np->vsi->back;
  1051. struct i40e_hw *hw = &pf->hw;
  1052. u16 wol_nvm_bits;
  1053. /* NVM bit on means WoL disabled for the port */
  1054. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1055. if ((1 << hw->port) & wol_nvm_bits) {
  1056. wol->supported = 0;
  1057. wol->wolopts = 0;
  1058. } else {
  1059. wol->supported = WAKE_MAGIC;
  1060. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1061. }
  1062. }
  1063. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1064. {
  1065. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1066. struct i40e_pf *pf = np->vsi->back;
  1067. struct i40e_hw *hw = &pf->hw;
  1068. u16 wol_nvm_bits;
  1069. /* NVM bit on means WoL disabled for the port */
  1070. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1071. if (((1 << hw->port) & wol_nvm_bits))
  1072. return -EOPNOTSUPP;
  1073. /* only magic packet is supported */
  1074. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1075. return -EOPNOTSUPP;
  1076. /* is this a new value? */
  1077. if (pf->wol_en != !!wol->wolopts) {
  1078. pf->wol_en = !!wol->wolopts;
  1079. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1080. }
  1081. return 0;
  1082. }
  1083. static int i40e_set_phys_id(struct net_device *netdev,
  1084. enum ethtool_phys_id_state state)
  1085. {
  1086. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1087. struct i40e_pf *pf = np->vsi->back;
  1088. struct i40e_hw *hw = &pf->hw;
  1089. int blink_freq = 2;
  1090. switch (state) {
  1091. case ETHTOOL_ID_ACTIVE:
  1092. pf->led_status = i40e_led_get(hw);
  1093. return blink_freq;
  1094. case ETHTOOL_ID_ON:
  1095. i40e_led_set(hw, 0xF, false);
  1096. break;
  1097. case ETHTOOL_ID_OFF:
  1098. i40e_led_set(hw, 0x0, false);
  1099. break;
  1100. case ETHTOOL_ID_INACTIVE:
  1101. i40e_led_set(hw, pf->led_status, false);
  1102. break;
  1103. }
  1104. return 0;
  1105. }
  1106. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1107. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1108. * 125us (8000 interrupts per second) == ITR(62)
  1109. */
  1110. static int i40e_get_coalesce(struct net_device *netdev,
  1111. struct ethtool_coalesce *ec)
  1112. {
  1113. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1114. struct i40e_vsi *vsi = np->vsi;
  1115. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1116. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1117. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  1118. ec->use_adaptive_rx_coalesce = 1;
  1119. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  1120. ec->use_adaptive_tx_coalesce = 1;
  1121. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1122. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1123. return 0;
  1124. }
  1125. static int i40e_set_coalesce(struct net_device *netdev,
  1126. struct ethtool_coalesce *ec)
  1127. {
  1128. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1129. struct i40e_q_vector *q_vector;
  1130. struct i40e_vsi *vsi = np->vsi;
  1131. struct i40e_pf *pf = vsi->back;
  1132. struct i40e_hw *hw = &pf->hw;
  1133. u16 vector;
  1134. int i;
  1135. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1136. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1137. vector = vsi->base_vector;
  1138. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  1139. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
  1140. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  1141. } else if (ec->rx_coalesce_usecs == 0) {
  1142. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  1143. i40e_irq_dynamic_disable(vsi, vector);
  1144. if (ec->use_adaptive_rx_coalesce)
  1145. netif_info(pf, drv, netdev,
  1146. "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
  1147. } else {
  1148. netif_info(pf, drv, netdev,
  1149. "Invalid value, Rx-usecs range is 0, 8-8160\n");
  1150. return -EINVAL;
  1151. }
  1152. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  1153. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
  1154. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  1155. } else if (ec->tx_coalesce_usecs == 0) {
  1156. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  1157. i40e_irq_dynamic_disable(vsi, vector);
  1158. if (ec->use_adaptive_tx_coalesce)
  1159. netif_info(pf, drv, netdev,
  1160. "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
  1161. } else {
  1162. netif_info(pf, drv, netdev,
  1163. "Invalid value, Tx-usecs range is 0, 8-8160\n");
  1164. return -EINVAL;
  1165. }
  1166. if (ec->use_adaptive_rx_coalesce)
  1167. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1168. else
  1169. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1170. if (ec->use_adaptive_tx_coalesce)
  1171. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1172. else
  1173. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1174. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  1175. q_vector = vsi->q_vectors[i];
  1176. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  1177. wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
  1178. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  1179. wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
  1180. i40e_flush(hw);
  1181. }
  1182. return 0;
  1183. }
  1184. /**
  1185. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1186. * @pf: pointer to the physical function struct
  1187. * @cmd: ethtool rxnfc command
  1188. *
  1189. * Returns Success if the flow is supported, else Invalid Input.
  1190. **/
  1191. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1192. {
  1193. cmd->data = 0;
  1194. /* Report default options for RSS on i40e */
  1195. switch (cmd->flow_type) {
  1196. case TCP_V4_FLOW:
  1197. case UDP_V4_FLOW:
  1198. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1199. /* fall through to add IP fields */
  1200. case SCTP_V4_FLOW:
  1201. case AH_ESP_V4_FLOW:
  1202. case AH_V4_FLOW:
  1203. case ESP_V4_FLOW:
  1204. case IPV4_FLOW:
  1205. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1206. break;
  1207. case TCP_V6_FLOW:
  1208. case UDP_V6_FLOW:
  1209. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1210. /* fall through to add IP fields */
  1211. case SCTP_V6_FLOW:
  1212. case AH_ESP_V6_FLOW:
  1213. case AH_V6_FLOW:
  1214. case ESP_V6_FLOW:
  1215. case IPV6_FLOW:
  1216. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1217. break;
  1218. default:
  1219. return -EINVAL;
  1220. }
  1221. return 0;
  1222. }
  1223. /**
  1224. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  1225. * @pf: Pointer to the physical function struct
  1226. * @cmd: The command to get or set Rx flow classification rules
  1227. * @rule_locs: Array of used rule locations
  1228. *
  1229. * This function populates both the total and actual rule count of
  1230. * the ethtool flow classification command
  1231. *
  1232. * Returns 0 on success or -EMSGSIZE if entry not found
  1233. **/
  1234. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  1235. struct ethtool_rxnfc *cmd,
  1236. u32 *rule_locs)
  1237. {
  1238. struct i40e_fdir_filter *rule;
  1239. struct hlist_node *node2;
  1240. int cnt = 0;
  1241. /* report total rule count */
  1242. cmd->data = i40e_get_fd_cnt_all(pf);
  1243. hlist_for_each_entry_safe(rule, node2,
  1244. &pf->fdir_filter_list, fdir_node) {
  1245. if (cnt == cmd->rule_cnt)
  1246. return -EMSGSIZE;
  1247. rule_locs[cnt] = rule->fd_id;
  1248. cnt++;
  1249. }
  1250. cmd->rule_cnt = cnt;
  1251. return 0;
  1252. }
  1253. /**
  1254. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  1255. * @pf: Pointer to the physical function struct
  1256. * @cmd: The command to get or set Rx flow classification rules
  1257. *
  1258. * This function looks up a filter based on the Rx flow classification
  1259. * command and fills the flow spec info for it if found
  1260. *
  1261. * Returns 0 on success or -EINVAL if filter not found
  1262. **/
  1263. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  1264. struct ethtool_rxnfc *cmd)
  1265. {
  1266. struct ethtool_rx_flow_spec *fsp =
  1267. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1268. struct i40e_fdir_filter *rule = NULL;
  1269. struct hlist_node *node2;
  1270. hlist_for_each_entry_safe(rule, node2,
  1271. &pf->fdir_filter_list, fdir_node) {
  1272. if (fsp->location <= rule->fd_id)
  1273. break;
  1274. }
  1275. if (!rule || fsp->location != rule->fd_id)
  1276. return -EINVAL;
  1277. fsp->flow_type = rule->flow_type;
  1278. if (fsp->flow_type == IP_USER_FLOW) {
  1279. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  1280. fsp->h_u.usr_ip4_spec.proto = 0;
  1281. fsp->m_u.usr_ip4_spec.proto = 0;
  1282. }
  1283. /* Reverse the src and dest notion, since the HW views them from
  1284. * Tx perspective where as the user expects it from Rx filter view.
  1285. */
  1286. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  1287. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  1288. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  1289. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  1290. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  1291. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  1292. else
  1293. fsp->ring_cookie = rule->q_index;
  1294. return 0;
  1295. }
  1296. /**
  1297. * i40e_get_rxnfc - command to get RX flow classification rules
  1298. * @netdev: network interface device structure
  1299. * @cmd: ethtool rxnfc command
  1300. *
  1301. * Returns Success if the command is supported.
  1302. **/
  1303. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  1304. u32 *rule_locs)
  1305. {
  1306. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1307. struct i40e_vsi *vsi = np->vsi;
  1308. struct i40e_pf *pf = vsi->back;
  1309. int ret = -EOPNOTSUPP;
  1310. switch (cmd->cmd) {
  1311. case ETHTOOL_GRXRINGS:
  1312. cmd->data = vsi->alloc_queue_pairs;
  1313. ret = 0;
  1314. break;
  1315. case ETHTOOL_GRXFH:
  1316. ret = i40e_get_rss_hash_opts(pf, cmd);
  1317. break;
  1318. case ETHTOOL_GRXCLSRLCNT:
  1319. cmd->rule_cnt = pf->fdir_pf_active_filters;
  1320. /* report total rule count */
  1321. cmd->data = i40e_get_fd_cnt_all(pf);
  1322. ret = 0;
  1323. break;
  1324. case ETHTOOL_GRXCLSRULE:
  1325. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  1326. break;
  1327. case ETHTOOL_GRXCLSRLALL:
  1328. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  1329. break;
  1330. default:
  1331. break;
  1332. }
  1333. return ret;
  1334. }
  1335. /**
  1336. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  1337. * @pf: pointer to the physical function struct
  1338. * @cmd: ethtool rxnfc command
  1339. *
  1340. * Returns Success if the flow input set is supported.
  1341. **/
  1342. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  1343. {
  1344. struct i40e_hw *hw = &pf->hw;
  1345. u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  1346. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  1347. /* RSS does not support anything other than hashing
  1348. * to queues on src and dst IPs and ports
  1349. */
  1350. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  1351. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  1352. return -EINVAL;
  1353. /* We need at least the IP SRC and DEST fields for hashing */
  1354. if (!(nfc->data & RXH_IP_SRC) ||
  1355. !(nfc->data & RXH_IP_DST))
  1356. return -EINVAL;
  1357. switch (nfc->flow_type) {
  1358. case TCP_V4_FLOW:
  1359. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1360. case 0:
  1361. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1362. break;
  1363. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1364. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1365. break;
  1366. default:
  1367. return -EINVAL;
  1368. }
  1369. break;
  1370. case TCP_V6_FLOW:
  1371. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1372. case 0:
  1373. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1374. break;
  1375. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1376. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1377. break;
  1378. default:
  1379. return -EINVAL;
  1380. }
  1381. break;
  1382. case UDP_V4_FLOW:
  1383. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1384. case 0:
  1385. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1386. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1387. break;
  1388. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1389. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1390. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1391. break;
  1392. default:
  1393. return -EINVAL;
  1394. }
  1395. break;
  1396. case UDP_V6_FLOW:
  1397. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1398. case 0:
  1399. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1400. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1401. break;
  1402. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1403. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1404. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1405. break;
  1406. default:
  1407. return -EINVAL;
  1408. }
  1409. break;
  1410. case AH_ESP_V4_FLOW:
  1411. case AH_V4_FLOW:
  1412. case ESP_V4_FLOW:
  1413. case SCTP_V4_FLOW:
  1414. if ((nfc->data & RXH_L4_B_0_1) ||
  1415. (nfc->data & RXH_L4_B_2_3))
  1416. return -EINVAL;
  1417. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  1418. break;
  1419. case AH_ESP_V6_FLOW:
  1420. case AH_V6_FLOW:
  1421. case ESP_V6_FLOW:
  1422. case SCTP_V6_FLOW:
  1423. if ((nfc->data & RXH_L4_B_0_1) ||
  1424. (nfc->data & RXH_L4_B_2_3))
  1425. return -EINVAL;
  1426. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  1427. break;
  1428. case IPV4_FLOW:
  1429. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  1430. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  1431. break;
  1432. case IPV6_FLOW:
  1433. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  1434. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  1435. break;
  1436. default:
  1437. return -EINVAL;
  1438. }
  1439. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  1440. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  1441. i40e_flush(hw);
  1442. return 0;
  1443. }
  1444. /**
  1445. * i40e_match_fdir_input_set - Match a new filter against an existing one
  1446. * @rule: The filter already added
  1447. * @input: The new filter to comapre against
  1448. *
  1449. * Returns true if the two input set match
  1450. **/
  1451. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  1452. struct i40e_fdir_filter *input)
  1453. {
  1454. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  1455. (rule->src_ip[0] != input->src_ip[0]) ||
  1456. (rule->dst_port != input->dst_port) ||
  1457. (rule->src_port != input->src_port))
  1458. return false;
  1459. return true;
  1460. }
  1461. /**
  1462. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  1463. * @vsi: Pointer to the targeted VSI
  1464. * @input: The filter to update or NULL to indicate deletion
  1465. * @sw_idx: Software index to the filter
  1466. * @cmd: The command to get or set Rx flow classification rules
  1467. *
  1468. * This function updates (or deletes) a Flow Director entry from
  1469. * the hlist of the corresponding PF
  1470. *
  1471. * Returns 0 on success
  1472. **/
  1473. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  1474. struct i40e_fdir_filter *input,
  1475. u16 sw_idx,
  1476. struct ethtool_rxnfc *cmd)
  1477. {
  1478. struct i40e_fdir_filter *rule, *parent;
  1479. struct i40e_pf *pf = vsi->back;
  1480. struct hlist_node *node2;
  1481. int err = -EINVAL;
  1482. parent = NULL;
  1483. rule = NULL;
  1484. hlist_for_each_entry_safe(rule, node2,
  1485. &pf->fdir_filter_list, fdir_node) {
  1486. /* hash found, or no matching entry */
  1487. if (rule->fd_id >= sw_idx)
  1488. break;
  1489. parent = rule;
  1490. }
  1491. /* if there is an old rule occupying our place remove it */
  1492. if (rule && (rule->fd_id == sw_idx)) {
  1493. if (input && !i40e_match_fdir_input_set(rule, input))
  1494. err = i40e_add_del_fdir(vsi, rule, false);
  1495. else if (!input)
  1496. err = i40e_add_del_fdir(vsi, rule, false);
  1497. hlist_del(&rule->fdir_node);
  1498. kfree(rule);
  1499. pf->fdir_pf_active_filters--;
  1500. }
  1501. /* If no input this was a delete, err should be 0 if a rule was
  1502. * successfully found and removed from the list else -EINVAL
  1503. */
  1504. if (!input)
  1505. return err;
  1506. /* initialize node and set software index */
  1507. INIT_HLIST_NODE(&input->fdir_node);
  1508. /* add filter to the list */
  1509. if (parent)
  1510. hlist_add_after(&parent->fdir_node, &input->fdir_node);
  1511. else
  1512. hlist_add_head(&input->fdir_node,
  1513. &pf->fdir_filter_list);
  1514. /* update counts */
  1515. pf->fdir_pf_active_filters++;
  1516. return 0;
  1517. }
  1518. /**
  1519. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  1520. * @vsi: Pointer to the targeted VSI
  1521. * @cmd: The command to get or set Rx flow classification rules
  1522. *
  1523. * The function removes a Flow Director filter entry from the
  1524. * hlist of the corresponding PF
  1525. *
  1526. * Returns 0 on success
  1527. */
  1528. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  1529. struct ethtool_rxnfc *cmd)
  1530. {
  1531. struct ethtool_rx_flow_spec *fsp =
  1532. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1533. struct i40e_pf *pf = vsi->back;
  1534. int ret = 0;
  1535. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  1536. i40e_fdir_check_and_reenable(pf);
  1537. return ret;
  1538. }
  1539. /**
  1540. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  1541. * @vsi: pointer to the targeted VSI
  1542. * @cmd: command to get or set RX flow classification rules
  1543. *
  1544. * Add Flow Director filters for a specific flow spec based on their
  1545. * protocol. Returns 0 if the filters were successfully added.
  1546. **/
  1547. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  1548. struct ethtool_rxnfc *cmd)
  1549. {
  1550. struct ethtool_rx_flow_spec *fsp;
  1551. struct i40e_fdir_filter *input;
  1552. struct i40e_pf *pf;
  1553. int ret = -EINVAL;
  1554. if (!vsi)
  1555. return -EINVAL;
  1556. pf = vsi->back;
  1557. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  1558. return -EOPNOTSUPP;
  1559. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  1560. return -ENOSPC;
  1561. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  1562. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  1563. pf->hw.func_caps.fd_filters_guaranteed)) {
  1564. return -EINVAL;
  1565. }
  1566. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  1567. (fsp->ring_cookie >= vsi->num_queue_pairs))
  1568. return -EINVAL;
  1569. input = kzalloc(sizeof(*input), GFP_KERNEL);
  1570. if (!input)
  1571. return -ENOMEM;
  1572. input->fd_id = fsp->location;
  1573. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  1574. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  1575. else
  1576. input->dest_ctl =
  1577. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  1578. input->q_index = fsp->ring_cookie;
  1579. input->flex_off = 0;
  1580. input->pctype = 0;
  1581. input->dest_vsi = vsi->id;
  1582. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  1583. input->cnt_index = pf->fd_sb_cnt_idx;
  1584. input->flow_type = fsp->flow_type;
  1585. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  1586. /* Reverse the src and dest notion, since the HW expects them to be from
  1587. * Tx perspective where as the input from user is from Rx filter view.
  1588. */
  1589. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  1590. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  1591. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  1592. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  1593. ret = i40e_add_del_fdir(vsi, input, true);
  1594. if (ret)
  1595. kfree(input);
  1596. else
  1597. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  1598. return ret;
  1599. }
  1600. /**
  1601. * i40e_set_rxnfc - command to set RX flow classification rules
  1602. * @netdev: network interface device structure
  1603. * @cmd: ethtool rxnfc command
  1604. *
  1605. * Returns Success if the command is supported.
  1606. **/
  1607. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  1608. {
  1609. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1610. struct i40e_vsi *vsi = np->vsi;
  1611. struct i40e_pf *pf = vsi->back;
  1612. int ret = -EOPNOTSUPP;
  1613. switch (cmd->cmd) {
  1614. case ETHTOOL_SRXFH:
  1615. ret = i40e_set_rss_hash_opt(pf, cmd);
  1616. break;
  1617. case ETHTOOL_SRXCLSRLINS:
  1618. ret = i40e_add_fdir_ethtool(vsi, cmd);
  1619. break;
  1620. case ETHTOOL_SRXCLSRLDEL:
  1621. ret = i40e_del_fdir_entry(vsi, cmd);
  1622. break;
  1623. default:
  1624. break;
  1625. }
  1626. return ret;
  1627. }
  1628. /**
  1629. * i40e_max_channels - get Max number of combined channels supported
  1630. * @vsi: vsi pointer
  1631. **/
  1632. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  1633. {
  1634. /* TODO: This code assumes DCB and FD is disabled for now. */
  1635. return vsi->alloc_queue_pairs;
  1636. }
  1637. /**
  1638. * i40e_get_channels - Get the current channels enabled and max supported etc.
  1639. * @netdev: network interface device structure
  1640. * @ch: ethtool channels structure
  1641. *
  1642. * We don't support separate tx and rx queues as channels. The other count
  1643. * represents how many queues are being used for control. max_combined counts
  1644. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  1645. * q_vectors since we support a lot more queue pairs than q_vectors.
  1646. **/
  1647. static void i40e_get_channels(struct net_device *dev,
  1648. struct ethtool_channels *ch)
  1649. {
  1650. struct i40e_netdev_priv *np = netdev_priv(dev);
  1651. struct i40e_vsi *vsi = np->vsi;
  1652. struct i40e_pf *pf = vsi->back;
  1653. /* report maximum channels */
  1654. ch->max_combined = i40e_max_channels(vsi);
  1655. /* report info for other vector */
  1656. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  1657. ch->max_other = ch->other_count;
  1658. /* Note: This code assumes DCB is disabled for now. */
  1659. ch->combined_count = vsi->num_queue_pairs;
  1660. }
  1661. /**
  1662. * i40e_set_channels - Set the new channels count.
  1663. * @netdev: network interface device structure
  1664. * @ch: ethtool channels structure
  1665. *
  1666. * The new channels count may not be the same as requested by the user
  1667. * since it gets rounded down to a power of 2 value.
  1668. **/
  1669. static int i40e_set_channels(struct net_device *dev,
  1670. struct ethtool_channels *ch)
  1671. {
  1672. struct i40e_netdev_priv *np = netdev_priv(dev);
  1673. unsigned int count = ch->combined_count;
  1674. struct i40e_vsi *vsi = np->vsi;
  1675. struct i40e_pf *pf = vsi->back;
  1676. int new_count;
  1677. /* We do not support setting channels for any other VSI at present */
  1678. if (vsi->type != I40E_VSI_MAIN)
  1679. return -EINVAL;
  1680. /* verify they are not requesting separate vectors */
  1681. if (!count || ch->rx_count || ch->tx_count)
  1682. return -EINVAL;
  1683. /* verify other_count has not changed */
  1684. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  1685. return -EINVAL;
  1686. /* verify the number of channels does not exceed hardware limits */
  1687. if (count > i40e_max_channels(vsi))
  1688. return -EINVAL;
  1689. /* update feature limits from largest to smallest supported values */
  1690. /* TODO: Flow director limit, DCB etc */
  1691. /* cap RSS limit */
  1692. if (count > pf->rss_size_max)
  1693. count = pf->rss_size_max;
  1694. /* use rss_reconfig to rebuild with new queue count and update traffic
  1695. * class queue mapping
  1696. */
  1697. new_count = i40e_reconfig_rss_queues(pf, count);
  1698. if (new_count > 0)
  1699. return 0;
  1700. else
  1701. return -EINVAL;
  1702. }
  1703. static const struct ethtool_ops i40e_ethtool_ops = {
  1704. .get_settings = i40e_get_settings,
  1705. .get_drvinfo = i40e_get_drvinfo,
  1706. .get_regs_len = i40e_get_regs_len,
  1707. .get_regs = i40e_get_regs,
  1708. .nway_reset = i40e_nway_reset,
  1709. .get_link = ethtool_op_get_link,
  1710. .get_wol = i40e_get_wol,
  1711. .set_wol = i40e_set_wol,
  1712. .get_eeprom_len = i40e_get_eeprom_len,
  1713. .get_eeprom = i40e_get_eeprom,
  1714. .get_ringparam = i40e_get_ringparam,
  1715. .set_ringparam = i40e_set_ringparam,
  1716. .get_pauseparam = i40e_get_pauseparam,
  1717. .set_pauseparam = i40e_set_pauseparam,
  1718. .get_msglevel = i40e_get_msglevel,
  1719. .set_msglevel = i40e_set_msglevel,
  1720. .get_rxnfc = i40e_get_rxnfc,
  1721. .set_rxnfc = i40e_set_rxnfc,
  1722. .self_test = i40e_diag_test,
  1723. .get_strings = i40e_get_strings,
  1724. .set_phys_id = i40e_set_phys_id,
  1725. .get_sset_count = i40e_get_sset_count,
  1726. .get_ethtool_stats = i40e_get_ethtool_stats,
  1727. .get_coalesce = i40e_get_coalesce,
  1728. .set_coalesce = i40e_set_coalesce,
  1729. .get_channels = i40e_get_channels,
  1730. .set_channels = i40e_set_channels,
  1731. .get_ts_info = i40e_get_ts_info,
  1732. };
  1733. void i40e_set_ethtool_ops(struct net_device *netdev)
  1734. {
  1735. netdev->ethtool_ops = &i40e_ethtool_ops;
  1736. }