i40e_ethtool.c 65 KB

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