i40e_ethtool.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 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 rtnl_link_stats64, #_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. I40E_VSI_STAT("tx_linearize", tx_linearize),
  83. I40E_VSI_STAT("tx_force_wb", tx_force_wb),
  84. I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
  85. I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
  86. I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
  87. };
  88. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  89. * but they are separate. This device supports Virtualization, and
  90. * as such might have several netdevs supporting VMDq and FCoE going
  91. * through a single port. The NETDEV_STATs are for individual netdevs
  92. * seen at the top of the stack, and the PF_STATs are for the physical
  93. * function at the bottom of the stack hosting those netdevs.
  94. *
  95. * The PF_STATs are appended to the netdev stats only when ethtool -S
  96. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  97. */
  98. static struct i40e_stats i40e_gstrings_stats[] = {
  99. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  100. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  101. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  102. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  103. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  104. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  105. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  106. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  107. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  108. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  109. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  110. I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
  111. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  112. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  113. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  114. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  115. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  116. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  117. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  118. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  119. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  120. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  121. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  122. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  123. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  124. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  125. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  126. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  127. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  128. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  129. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  130. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  131. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  132. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  133. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  134. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  135. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  136. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  137. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  138. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  139. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  140. I40E_PF_STAT("arq_overflows", arq_overflows),
  141. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  142. I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
  143. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  144. I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
  145. I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
  146. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  147. I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
  148. /* LPI stats */
  149. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  150. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  151. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  152. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  153. };
  154. #ifdef I40E_FCOE
  155. static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
  156. I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
  157. I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
  158. I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
  159. I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
  160. I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
  161. I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
  162. I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
  163. I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
  164. };
  165. #endif /* I40E_FCOE */
  166. #define I40E_QUEUE_STATS_LEN(n) \
  167. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  168. * 2 /* Tx and Rx together */ \
  169. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  170. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  171. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  172. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  173. #ifdef I40E_FCOE
  174. #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
  175. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  176. I40E_FCOE_STATS_LEN + \
  177. I40E_MISC_STATS_LEN + \
  178. I40E_QUEUE_STATS_LEN((n)))
  179. #else
  180. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  181. I40E_MISC_STATS_LEN + \
  182. I40E_QUEUE_STATS_LEN((n)))
  183. #endif /* I40E_FCOE */
  184. #define I40E_PFC_STATS_LEN ( \
  185. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  186. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  187. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  188. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  189. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  190. / sizeof(u64))
  191. #define I40E_VEB_TC_STATS_LEN ( \
  192. (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
  193. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
  194. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
  195. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
  196. / sizeof(u64))
  197. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  198. #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
  199. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  200. I40E_PFC_STATS_LEN + \
  201. I40E_VSI_STATS_LEN((n)))
  202. enum i40e_ethtool_test_id {
  203. I40E_ETH_TEST_REG = 0,
  204. I40E_ETH_TEST_EEPROM,
  205. I40E_ETH_TEST_INTR,
  206. I40E_ETH_TEST_LOOPBACK,
  207. I40E_ETH_TEST_LINK,
  208. };
  209. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  210. "Register test (offline)",
  211. "Eeprom test (offline)",
  212. "Interrupt test (offline)",
  213. "Loopback test (offline)",
  214. "Link test (on/offline)"
  215. };
  216. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  217. static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
  218. "NPAR",
  219. "LinkPolling",
  220. "flow-director-atr",
  221. "veb-stats",
  222. "packet-split",
  223. "hw-atr-eviction",
  224. };
  225. #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
  226. /**
  227. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  228. * @pf: the PF struct
  229. **/
  230. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  231. {
  232. dev_info(&pf->pdev->dev,
  233. "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
  234. }
  235. /**
  236. * i40e_get_settings_link_up - Get the Link settings for when link is up
  237. * @hw: hw structure
  238. * @ecmd: ethtool command to fill in
  239. * @netdev: network interface device structure
  240. *
  241. **/
  242. static void i40e_get_settings_link_up(struct i40e_hw *hw,
  243. struct ethtool_cmd *ecmd,
  244. struct net_device *netdev,
  245. struct i40e_pf *pf)
  246. {
  247. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  248. u32 link_speed = hw_link_info->link_speed;
  249. /* Initialize supported and advertised settings based on phy settings */
  250. switch (hw_link_info->phy_type) {
  251. case I40E_PHY_TYPE_40GBASE_CR4:
  252. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  253. ecmd->supported = SUPPORTED_Autoneg |
  254. SUPPORTED_40000baseCR4_Full;
  255. ecmd->advertising = ADVERTISED_Autoneg |
  256. ADVERTISED_40000baseCR4_Full;
  257. break;
  258. case I40E_PHY_TYPE_XLAUI:
  259. case I40E_PHY_TYPE_XLPPI:
  260. case I40E_PHY_TYPE_40GBASE_AOC:
  261. ecmd->supported = SUPPORTED_40000baseCR4_Full;
  262. break;
  263. case I40E_PHY_TYPE_40GBASE_SR4:
  264. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  265. break;
  266. case I40E_PHY_TYPE_40GBASE_LR4:
  267. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  268. break;
  269. case I40E_PHY_TYPE_10GBASE_SR:
  270. case I40E_PHY_TYPE_10GBASE_LR:
  271. case I40E_PHY_TYPE_1000BASE_SX:
  272. case I40E_PHY_TYPE_1000BASE_LX:
  273. ecmd->supported = SUPPORTED_10000baseT_Full;
  274. if (hw_link_info->module_type[2] &
  275. I40E_MODULE_TYPE_1000BASE_SX ||
  276. hw_link_info->module_type[2] &
  277. I40E_MODULE_TYPE_1000BASE_LX) {
  278. ecmd->supported |= SUPPORTED_1000baseT_Full;
  279. if (hw_link_info->requested_speeds &
  280. I40E_LINK_SPEED_1GB)
  281. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  282. }
  283. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  284. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  285. break;
  286. case I40E_PHY_TYPE_10GBASE_T:
  287. case I40E_PHY_TYPE_1000BASE_T:
  288. ecmd->supported = SUPPORTED_Autoneg |
  289. SUPPORTED_10000baseT_Full |
  290. SUPPORTED_1000baseT_Full;
  291. ecmd->advertising = ADVERTISED_Autoneg;
  292. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  293. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  294. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  295. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  296. break;
  297. case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
  298. ecmd->supported = SUPPORTED_Autoneg |
  299. SUPPORTED_1000baseT_Full;
  300. ecmd->advertising = ADVERTISED_Autoneg |
  301. ADVERTISED_1000baseT_Full;
  302. break;
  303. case I40E_PHY_TYPE_100BASE_TX:
  304. ecmd->supported = SUPPORTED_Autoneg |
  305. SUPPORTED_100baseT_Full;
  306. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  307. ecmd->advertising |= ADVERTISED_100baseT_Full;
  308. break;
  309. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  310. case I40E_PHY_TYPE_10GBASE_CR1:
  311. ecmd->supported = SUPPORTED_Autoneg |
  312. SUPPORTED_10000baseT_Full;
  313. ecmd->advertising = ADVERTISED_Autoneg |
  314. ADVERTISED_10000baseT_Full;
  315. break;
  316. case I40E_PHY_TYPE_XAUI:
  317. case I40E_PHY_TYPE_XFI:
  318. case I40E_PHY_TYPE_SFI:
  319. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  320. case I40E_PHY_TYPE_10GBASE_AOC:
  321. ecmd->supported = SUPPORTED_10000baseT_Full;
  322. break;
  323. case I40E_PHY_TYPE_SGMII:
  324. ecmd->supported = SUPPORTED_Autoneg |
  325. SUPPORTED_1000baseT_Full;
  326. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  327. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  328. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  329. ecmd->supported |= SUPPORTED_100baseT_Full;
  330. if (hw_link_info->requested_speeds &
  331. I40E_LINK_SPEED_100MB)
  332. ecmd->advertising |= ADVERTISED_100baseT_Full;
  333. }
  334. break;
  335. /* Backplane is set based on supported phy types in get_settings
  336. * so don't set anything here but don't warn either
  337. */
  338. case I40E_PHY_TYPE_40GBASE_KR4:
  339. case I40E_PHY_TYPE_20GBASE_KR2:
  340. case I40E_PHY_TYPE_10GBASE_KR:
  341. case I40E_PHY_TYPE_10GBASE_KX4:
  342. case I40E_PHY_TYPE_1000BASE_KX:
  343. break;
  344. default:
  345. /* if we got here and link is up something bad is afoot */
  346. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  347. hw_link_info->phy_type);
  348. }
  349. /* Set speed and duplex */
  350. switch (link_speed) {
  351. case I40E_LINK_SPEED_40GB:
  352. ethtool_cmd_speed_set(ecmd, SPEED_40000);
  353. break;
  354. case I40E_LINK_SPEED_20GB:
  355. ethtool_cmd_speed_set(ecmd, SPEED_20000);
  356. break;
  357. case I40E_LINK_SPEED_10GB:
  358. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  359. break;
  360. case I40E_LINK_SPEED_1GB:
  361. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  362. break;
  363. case I40E_LINK_SPEED_100MB:
  364. ethtool_cmd_speed_set(ecmd, SPEED_100);
  365. break;
  366. default:
  367. break;
  368. }
  369. ecmd->duplex = DUPLEX_FULL;
  370. }
  371. /**
  372. * i40e_get_settings_link_down - Get the Link settings for when link is down
  373. * @hw: hw structure
  374. * @ecmd: ethtool command to fill in
  375. *
  376. * Reports link settings that can be determined when link is down
  377. **/
  378. static void i40e_get_settings_link_down(struct i40e_hw *hw,
  379. struct ethtool_cmd *ecmd,
  380. struct i40e_pf *pf)
  381. {
  382. enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
  383. /* link is down and the driver needs to fall back on
  384. * supported phy types to figure out what info to display
  385. */
  386. ecmd->supported = 0x0;
  387. ecmd->advertising = 0x0;
  388. if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
  389. ecmd->supported |= SUPPORTED_Autoneg |
  390. SUPPORTED_1000baseT_Full;
  391. ecmd->advertising |= ADVERTISED_Autoneg |
  392. ADVERTISED_1000baseT_Full;
  393. if (pf->hw.mac.type == I40E_MAC_X722) {
  394. ecmd->supported |= SUPPORTED_100baseT_Full;
  395. ecmd->advertising |= ADVERTISED_100baseT_Full;
  396. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  397. ecmd->supported |= SUPPORTED_100baseT_Full;
  398. ecmd->advertising |= ADVERTISED_100baseT_Full;
  399. }
  400. }
  401. }
  402. if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
  403. phy_types & I40E_CAP_PHY_TYPE_XFI ||
  404. phy_types & I40E_CAP_PHY_TYPE_SFI ||
  405. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
  406. phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
  407. ecmd->supported |= SUPPORTED_10000baseT_Full;
  408. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
  409. phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
  410. phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
  411. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
  412. phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
  413. ecmd->supported |= SUPPORTED_Autoneg |
  414. SUPPORTED_10000baseT_Full;
  415. ecmd->advertising |= ADVERTISED_Autoneg |
  416. ADVERTISED_10000baseT_Full;
  417. }
  418. if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
  419. phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
  420. phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
  421. ecmd->supported |= SUPPORTED_40000baseCR4_Full;
  422. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
  423. phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
  424. ecmd->supported |= SUPPORTED_Autoneg |
  425. SUPPORTED_40000baseCR4_Full;
  426. ecmd->advertising |= ADVERTISED_Autoneg |
  427. ADVERTISED_40000baseCR4_Full;
  428. }
  429. if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
  430. !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
  431. ecmd->supported |= SUPPORTED_Autoneg |
  432. SUPPORTED_100baseT_Full;
  433. ecmd->advertising |= ADVERTISED_Autoneg |
  434. ADVERTISED_100baseT_Full;
  435. }
  436. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
  437. phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
  438. phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
  439. phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
  440. ecmd->supported |= SUPPORTED_Autoneg |
  441. SUPPORTED_1000baseT_Full;
  442. ecmd->advertising |= ADVERTISED_Autoneg |
  443. ADVERTISED_1000baseT_Full;
  444. }
  445. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
  446. ecmd->supported |= SUPPORTED_40000baseSR4_Full;
  447. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
  448. ecmd->supported |= SUPPORTED_40000baseLR4_Full;
  449. /* With no link speed and duplex are unknown */
  450. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  451. ecmd->duplex = DUPLEX_UNKNOWN;
  452. }
  453. /**
  454. * i40e_get_settings - Get Link Speed and Duplex settings
  455. * @netdev: network interface device structure
  456. * @ecmd: ethtool command
  457. *
  458. * Reports speed/duplex settings based on media_type
  459. **/
  460. static int i40e_get_settings(struct net_device *netdev,
  461. struct ethtool_cmd *ecmd)
  462. {
  463. struct i40e_netdev_priv *np = netdev_priv(netdev);
  464. struct i40e_pf *pf = np->vsi->back;
  465. struct i40e_hw *hw = &pf->hw;
  466. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  467. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  468. if (link_up)
  469. i40e_get_settings_link_up(hw, ecmd, netdev, pf);
  470. else
  471. i40e_get_settings_link_down(hw, ecmd, pf);
  472. /* Now set the settings that don't rely on link being up/down */
  473. /* For backplane, supported and advertised are only reliant on the
  474. * phy types the NVM specifies are supported.
  475. */
  476. if (hw->device_id == I40E_DEV_ID_KX_B ||
  477. hw->device_id == I40E_DEV_ID_KX_C ||
  478. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  479. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  480. ecmd->supported = SUPPORTED_Autoneg;
  481. ecmd->advertising = ADVERTISED_Autoneg;
  482. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
  483. ecmd->supported |= SUPPORTED_40000baseKR4_Full;
  484. ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
  485. }
  486. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
  487. ecmd->supported |= SUPPORTED_20000baseKR2_Full;
  488. ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
  489. }
  490. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
  491. ecmd->supported |= SUPPORTED_10000baseKR_Full;
  492. ecmd->advertising |= ADVERTISED_10000baseKR_Full;
  493. }
  494. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
  495. ecmd->supported |= SUPPORTED_10000baseKX4_Full;
  496. ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
  497. }
  498. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
  499. ecmd->supported |= SUPPORTED_1000baseKX_Full;
  500. ecmd->advertising |= ADVERTISED_1000baseKX_Full;
  501. }
  502. }
  503. /* Set autoneg settings */
  504. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  505. AUTONEG_ENABLE : AUTONEG_DISABLE);
  506. switch (hw->phy.media_type) {
  507. case I40E_MEDIA_TYPE_BACKPLANE:
  508. ecmd->supported |= SUPPORTED_Autoneg |
  509. SUPPORTED_Backplane;
  510. ecmd->advertising |= ADVERTISED_Autoneg |
  511. ADVERTISED_Backplane;
  512. ecmd->port = PORT_NONE;
  513. break;
  514. case I40E_MEDIA_TYPE_BASET:
  515. ecmd->supported |= SUPPORTED_TP;
  516. ecmd->advertising |= ADVERTISED_TP;
  517. ecmd->port = PORT_TP;
  518. break;
  519. case I40E_MEDIA_TYPE_DA:
  520. case I40E_MEDIA_TYPE_CX4:
  521. ecmd->supported |= SUPPORTED_FIBRE;
  522. ecmd->advertising |= ADVERTISED_FIBRE;
  523. ecmd->port = PORT_DA;
  524. break;
  525. case I40E_MEDIA_TYPE_FIBER:
  526. ecmd->supported |= SUPPORTED_FIBRE;
  527. ecmd->port = PORT_FIBRE;
  528. break;
  529. case I40E_MEDIA_TYPE_UNKNOWN:
  530. default:
  531. ecmd->port = PORT_OTHER;
  532. break;
  533. }
  534. /* Set transceiver */
  535. ecmd->transceiver = XCVR_EXTERNAL;
  536. /* Set flow control settings */
  537. ecmd->supported |= SUPPORTED_Pause;
  538. switch (hw->fc.requested_mode) {
  539. case I40E_FC_FULL:
  540. ecmd->advertising |= ADVERTISED_Pause;
  541. break;
  542. case I40E_FC_TX_PAUSE:
  543. ecmd->advertising |= ADVERTISED_Asym_Pause;
  544. break;
  545. case I40E_FC_RX_PAUSE:
  546. ecmd->advertising |= (ADVERTISED_Pause |
  547. ADVERTISED_Asym_Pause);
  548. break;
  549. default:
  550. ecmd->advertising &= ~(ADVERTISED_Pause |
  551. ADVERTISED_Asym_Pause);
  552. break;
  553. }
  554. return 0;
  555. }
  556. /**
  557. * i40e_set_settings - Set Speed and Duplex
  558. * @netdev: network interface device structure
  559. * @ecmd: ethtool command
  560. *
  561. * Set speed/duplex per media_types advertised/forced
  562. **/
  563. static int i40e_set_settings(struct net_device *netdev,
  564. struct ethtool_cmd *ecmd)
  565. {
  566. struct i40e_netdev_priv *np = netdev_priv(netdev);
  567. struct i40e_aq_get_phy_abilities_resp abilities;
  568. struct i40e_aq_set_phy_config config;
  569. struct i40e_pf *pf = np->vsi->back;
  570. struct i40e_vsi *vsi = np->vsi;
  571. struct i40e_hw *hw = &pf->hw;
  572. struct ethtool_cmd safe_ecmd;
  573. i40e_status status = 0;
  574. bool change = false;
  575. int err = 0;
  576. u8 autoneg;
  577. u32 advertise;
  578. /* Changing port settings is not supported if this isn't the
  579. * port's controlling PF
  580. */
  581. if (hw->partition_id != 1) {
  582. i40e_partition_setting_complaint(pf);
  583. return -EOPNOTSUPP;
  584. }
  585. if (vsi != pf->vsi[pf->lan_vsi])
  586. return -EOPNOTSUPP;
  587. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  588. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  589. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  590. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  591. return -EOPNOTSUPP;
  592. if (hw->device_id == I40E_DEV_ID_KX_B ||
  593. hw->device_id == I40E_DEV_ID_KX_C ||
  594. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  595. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  596. netdev_info(netdev, "Changing settings is not supported on backplane.\n");
  597. return -EOPNOTSUPP;
  598. }
  599. /* get our own copy of the bits to check against */
  600. memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
  601. i40e_get_settings(netdev, &safe_ecmd);
  602. /* save autoneg and speed out of ecmd */
  603. autoneg = ecmd->autoneg;
  604. advertise = ecmd->advertising;
  605. /* set autoneg and speed back to what they currently are */
  606. ecmd->autoneg = safe_ecmd.autoneg;
  607. ecmd->advertising = safe_ecmd.advertising;
  608. ecmd->cmd = safe_ecmd.cmd;
  609. /* If ecmd and safe_ecmd are not the same now, then they are
  610. * trying to set something that we do not support
  611. */
  612. if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
  613. return -EOPNOTSUPP;
  614. while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
  615. usleep_range(1000, 2000);
  616. /* Get the current phy config */
  617. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  618. NULL);
  619. if (status)
  620. return -EAGAIN;
  621. /* Copy abilities to config in case autoneg is not
  622. * set below
  623. */
  624. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  625. config.abilities = abilities.abilities;
  626. /* Check autoneg */
  627. if (autoneg == AUTONEG_ENABLE) {
  628. /* If autoneg was not already enabled */
  629. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  630. /* If autoneg is not supported, return error */
  631. if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
  632. netdev_info(netdev, "Autoneg not supported on this phy\n");
  633. return -EINVAL;
  634. }
  635. /* Autoneg is allowed to change */
  636. config.abilities = abilities.abilities |
  637. I40E_AQ_PHY_ENABLE_AN;
  638. change = true;
  639. }
  640. } else {
  641. /* If autoneg is currently enabled */
  642. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  643. /* If autoneg is supported 10GBASE_T is the only PHY
  644. * that can disable it, so otherwise return error
  645. */
  646. if (safe_ecmd.supported & SUPPORTED_Autoneg &&
  647. hw->phy.link_info.phy_type !=
  648. I40E_PHY_TYPE_10GBASE_T) {
  649. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  650. return -EINVAL;
  651. }
  652. /* Autoneg is allowed to change */
  653. config.abilities = abilities.abilities &
  654. ~I40E_AQ_PHY_ENABLE_AN;
  655. change = true;
  656. }
  657. }
  658. if (advertise & ~safe_ecmd.supported)
  659. return -EINVAL;
  660. if (advertise & ADVERTISED_100baseT_Full)
  661. config.link_speed |= I40E_LINK_SPEED_100MB;
  662. if (advertise & ADVERTISED_1000baseT_Full ||
  663. advertise & ADVERTISED_1000baseKX_Full)
  664. config.link_speed |= I40E_LINK_SPEED_1GB;
  665. if (advertise & ADVERTISED_10000baseT_Full ||
  666. advertise & ADVERTISED_10000baseKX4_Full ||
  667. advertise & ADVERTISED_10000baseKR_Full)
  668. config.link_speed |= I40E_LINK_SPEED_10GB;
  669. if (advertise & ADVERTISED_20000baseKR2_Full)
  670. config.link_speed |= I40E_LINK_SPEED_20GB;
  671. if (advertise & ADVERTISED_40000baseKR4_Full ||
  672. advertise & ADVERTISED_40000baseCR4_Full ||
  673. advertise & ADVERTISED_40000baseSR4_Full ||
  674. advertise & ADVERTISED_40000baseLR4_Full)
  675. config.link_speed |= I40E_LINK_SPEED_40GB;
  676. /* If speed didn't get set, set it to what it currently is.
  677. * This is needed because if advertise is 0 (as it is when autoneg
  678. * is disabled) then speed won't get set.
  679. */
  680. if (!config.link_speed)
  681. config.link_speed = abilities.link_speed;
  682. if (change || (abilities.link_speed != config.link_speed)) {
  683. /* copy over the rest of the abilities */
  684. config.phy_type = abilities.phy_type;
  685. config.eee_capability = abilities.eee_capability;
  686. config.eeer = abilities.eeer_val;
  687. config.low_power_ctrl = abilities.d3_lpan;
  688. /* save the requested speeds */
  689. hw->phy.link_info.requested_speeds = config.link_speed;
  690. /* set link and auto negotiation so changes take effect */
  691. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  692. /* If link is up put link down */
  693. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  694. /* Tell the OS link is going down, the link will go
  695. * back up when fw says it is ready asynchronously
  696. */
  697. i40e_print_link_message(vsi, false);
  698. netif_carrier_off(netdev);
  699. netif_tx_stop_all_queues(netdev);
  700. }
  701. /* make the aq call */
  702. status = i40e_aq_set_phy_config(hw, &config, NULL);
  703. if (status) {
  704. netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
  705. i40e_stat_str(hw, status),
  706. i40e_aq_str(hw, hw->aq.asq_last_status));
  707. return -EAGAIN;
  708. }
  709. status = i40e_update_link_info(hw);
  710. if (status)
  711. netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
  712. i40e_stat_str(hw, status),
  713. i40e_aq_str(hw, hw->aq.asq_last_status));
  714. } else {
  715. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  716. }
  717. return err;
  718. }
  719. static int i40e_nway_reset(struct net_device *netdev)
  720. {
  721. /* restart autonegotiation */
  722. struct i40e_netdev_priv *np = netdev_priv(netdev);
  723. struct i40e_pf *pf = np->vsi->back;
  724. struct i40e_hw *hw = &pf->hw;
  725. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  726. i40e_status ret = 0;
  727. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  728. if (ret) {
  729. netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
  730. i40e_stat_str(hw, ret),
  731. i40e_aq_str(hw, hw->aq.asq_last_status));
  732. return -EIO;
  733. }
  734. return 0;
  735. }
  736. /**
  737. * i40e_get_pauseparam - Get Flow Control status
  738. * Return tx/rx-pause status
  739. **/
  740. static void i40e_get_pauseparam(struct net_device *netdev,
  741. struct ethtool_pauseparam *pause)
  742. {
  743. struct i40e_netdev_priv *np = netdev_priv(netdev);
  744. struct i40e_pf *pf = np->vsi->back;
  745. struct i40e_hw *hw = &pf->hw;
  746. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  747. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  748. pause->autoneg =
  749. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  750. AUTONEG_ENABLE : AUTONEG_DISABLE);
  751. /* PFC enabled so report LFC as off */
  752. if (dcbx_cfg->pfc.pfcenable) {
  753. pause->rx_pause = 0;
  754. pause->tx_pause = 0;
  755. return;
  756. }
  757. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  758. pause->rx_pause = 1;
  759. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  760. pause->tx_pause = 1;
  761. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  762. pause->rx_pause = 1;
  763. pause->tx_pause = 1;
  764. }
  765. }
  766. /**
  767. * i40e_set_pauseparam - Set Flow Control parameter
  768. * @netdev: network interface device structure
  769. * @pause: return tx/rx flow control status
  770. **/
  771. static int i40e_set_pauseparam(struct net_device *netdev,
  772. struct ethtool_pauseparam *pause)
  773. {
  774. struct i40e_netdev_priv *np = netdev_priv(netdev);
  775. struct i40e_pf *pf = np->vsi->back;
  776. struct i40e_vsi *vsi = np->vsi;
  777. struct i40e_hw *hw = &pf->hw;
  778. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  779. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  780. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  781. i40e_status status;
  782. u8 aq_failures;
  783. int err = 0;
  784. /* Changing the port's flow control is not supported if this isn't the
  785. * port's controlling PF
  786. */
  787. if (hw->partition_id != 1) {
  788. i40e_partition_setting_complaint(pf);
  789. return -EOPNOTSUPP;
  790. }
  791. if (vsi != pf->vsi[pf->lan_vsi])
  792. return -EOPNOTSUPP;
  793. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  794. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  795. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  796. return -EOPNOTSUPP;
  797. }
  798. /* If we have link and don't have autoneg */
  799. if (!test_bit(__I40E_DOWN, &pf->state) &&
  800. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  801. /* Send message that it might not necessarily work*/
  802. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  803. }
  804. if (dcbx_cfg->pfc.pfcenable) {
  805. netdev_info(netdev,
  806. "Priority flow control enabled. Cannot set link flow control.\n");
  807. return -EOPNOTSUPP;
  808. }
  809. if (pause->rx_pause && pause->tx_pause)
  810. hw->fc.requested_mode = I40E_FC_FULL;
  811. else if (pause->rx_pause && !pause->tx_pause)
  812. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  813. else if (!pause->rx_pause && pause->tx_pause)
  814. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  815. else if (!pause->rx_pause && !pause->tx_pause)
  816. hw->fc.requested_mode = I40E_FC_NONE;
  817. else
  818. return -EINVAL;
  819. /* Tell the OS link is going down, the link will go back up when fw
  820. * says it is ready asynchronously
  821. */
  822. i40e_print_link_message(vsi, false);
  823. netif_carrier_off(netdev);
  824. netif_tx_stop_all_queues(netdev);
  825. /* Set the fc mode and only restart an if link is up*/
  826. status = i40e_set_fc(hw, &aq_failures, link_up);
  827. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  828. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
  829. i40e_stat_str(hw, status),
  830. i40e_aq_str(hw, hw->aq.asq_last_status));
  831. err = -EAGAIN;
  832. }
  833. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  834. netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
  835. i40e_stat_str(hw, status),
  836. i40e_aq_str(hw, hw->aq.asq_last_status));
  837. err = -EAGAIN;
  838. }
  839. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  840. netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
  841. i40e_stat_str(hw, status),
  842. i40e_aq_str(hw, hw->aq.asq_last_status));
  843. err = -EAGAIN;
  844. }
  845. if (!test_bit(__I40E_DOWN, &pf->state)) {
  846. /* Give it a little more time to try to come back */
  847. msleep(75);
  848. if (!test_bit(__I40E_DOWN, &pf->state))
  849. return i40e_nway_reset(netdev);
  850. }
  851. return err;
  852. }
  853. static u32 i40e_get_msglevel(struct net_device *netdev)
  854. {
  855. struct i40e_netdev_priv *np = netdev_priv(netdev);
  856. struct i40e_pf *pf = np->vsi->back;
  857. return pf->msg_enable;
  858. }
  859. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  860. {
  861. struct i40e_netdev_priv *np = netdev_priv(netdev);
  862. struct i40e_pf *pf = np->vsi->back;
  863. if (I40E_DEBUG_USER & data)
  864. pf->hw.debug_mask = data;
  865. pf->msg_enable = data;
  866. }
  867. static int i40e_get_regs_len(struct net_device *netdev)
  868. {
  869. int reg_count = 0;
  870. int i;
  871. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  872. reg_count += i40e_reg_list[i].elements;
  873. return reg_count * sizeof(u32);
  874. }
  875. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  876. void *p)
  877. {
  878. struct i40e_netdev_priv *np = netdev_priv(netdev);
  879. struct i40e_pf *pf = np->vsi->back;
  880. struct i40e_hw *hw = &pf->hw;
  881. u32 *reg_buf = p;
  882. int i, j, ri;
  883. u32 reg;
  884. /* Tell ethtool which driver-version-specific regs output we have.
  885. *
  886. * At some point, if we have ethtool doing special formatting of
  887. * this data, it will rely on this version number to know how to
  888. * interpret things. Hence, this needs to be updated if/when the
  889. * diags register table is changed.
  890. */
  891. regs->version = 1;
  892. /* loop through the diags reg table for what to print */
  893. ri = 0;
  894. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  895. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  896. reg = i40e_reg_list[i].offset
  897. + (j * i40e_reg_list[i].stride);
  898. reg_buf[ri++] = rd32(hw, reg);
  899. }
  900. }
  901. }
  902. static int i40e_get_eeprom(struct net_device *netdev,
  903. struct ethtool_eeprom *eeprom, u8 *bytes)
  904. {
  905. struct i40e_netdev_priv *np = netdev_priv(netdev);
  906. struct i40e_hw *hw = &np->vsi->back->hw;
  907. struct i40e_pf *pf = np->vsi->back;
  908. int ret_val = 0, len, offset;
  909. u8 *eeprom_buff;
  910. u16 i, sectors;
  911. bool last;
  912. u32 magic;
  913. #define I40E_NVM_SECTOR_SIZE 4096
  914. if (eeprom->len == 0)
  915. return -EINVAL;
  916. /* check for NVMUpdate access method */
  917. magic = hw->vendor_id | (hw->device_id << 16);
  918. if (eeprom->magic && eeprom->magic != magic) {
  919. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  920. int errno = 0;
  921. /* make sure it is the right magic for NVMUpdate */
  922. if ((eeprom->magic >> 16) != hw->device_id)
  923. errno = -EINVAL;
  924. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  925. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  926. errno = -EBUSY;
  927. else
  928. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  929. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  930. dev_info(&pf->pdev->dev,
  931. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  932. ret_val, hw->aq.asq_last_status, errno,
  933. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  934. cmd->offset, cmd->data_size);
  935. return errno;
  936. }
  937. /* normal ethtool get_eeprom support */
  938. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  939. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  940. if (!eeprom_buff)
  941. return -ENOMEM;
  942. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  943. if (ret_val) {
  944. dev_info(&pf->pdev->dev,
  945. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  946. ret_val, hw->aq.asq_last_status);
  947. goto free_buff;
  948. }
  949. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  950. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  951. len = I40E_NVM_SECTOR_SIZE;
  952. last = false;
  953. for (i = 0; i < sectors; i++) {
  954. if (i == (sectors - 1)) {
  955. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  956. last = true;
  957. }
  958. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  959. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  960. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  961. last, NULL);
  962. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  963. dev_info(&pf->pdev->dev,
  964. "read NVM failed, invalid offset 0x%x\n",
  965. offset);
  966. break;
  967. } else if (ret_val &&
  968. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  969. dev_info(&pf->pdev->dev,
  970. "read NVM failed, access, offset 0x%x\n",
  971. offset);
  972. break;
  973. } else if (ret_val) {
  974. dev_info(&pf->pdev->dev,
  975. "read NVM failed offset %d err=%d status=0x%x\n",
  976. offset, ret_val, hw->aq.asq_last_status);
  977. break;
  978. }
  979. }
  980. i40e_release_nvm(hw);
  981. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  982. free_buff:
  983. kfree(eeprom_buff);
  984. return ret_val;
  985. }
  986. static int i40e_get_eeprom_len(struct net_device *netdev)
  987. {
  988. struct i40e_netdev_priv *np = netdev_priv(netdev);
  989. struct i40e_hw *hw = &np->vsi->back->hw;
  990. u32 val;
  991. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  992. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  993. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  994. /* register returns value in power of 2, 64Kbyte chunks. */
  995. val = (64 * 1024) * BIT(val);
  996. return val;
  997. }
  998. static int i40e_set_eeprom(struct net_device *netdev,
  999. struct ethtool_eeprom *eeprom, u8 *bytes)
  1000. {
  1001. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1002. struct i40e_hw *hw = &np->vsi->back->hw;
  1003. struct i40e_pf *pf = np->vsi->back;
  1004. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1005. int ret_val = 0;
  1006. int errno = 0;
  1007. u32 magic;
  1008. /* normal ethtool set_eeprom is not supported */
  1009. magic = hw->vendor_id | (hw->device_id << 16);
  1010. if (eeprom->magic == magic)
  1011. errno = -EOPNOTSUPP;
  1012. /* check for NVMUpdate access method */
  1013. else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  1014. errno = -EINVAL;
  1015. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1016. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1017. errno = -EBUSY;
  1018. else
  1019. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1020. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1021. dev_info(&pf->pdev->dev,
  1022. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1023. ret_val, hw->aq.asq_last_status, errno,
  1024. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1025. cmd->offset, cmd->data_size);
  1026. return errno;
  1027. }
  1028. static void i40e_get_drvinfo(struct net_device *netdev,
  1029. struct ethtool_drvinfo *drvinfo)
  1030. {
  1031. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1032. struct i40e_vsi *vsi = np->vsi;
  1033. struct i40e_pf *pf = vsi->back;
  1034. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  1035. strlcpy(drvinfo->version, i40e_driver_version_str,
  1036. sizeof(drvinfo->version));
  1037. strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
  1038. sizeof(drvinfo->fw_version));
  1039. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  1040. sizeof(drvinfo->bus_info));
  1041. }
  1042. static void i40e_get_ringparam(struct net_device *netdev,
  1043. struct ethtool_ringparam *ring)
  1044. {
  1045. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1046. struct i40e_pf *pf = np->vsi->back;
  1047. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1048. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1049. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1050. ring->rx_mini_max_pending = 0;
  1051. ring->rx_jumbo_max_pending = 0;
  1052. ring->rx_pending = vsi->rx_rings[0]->count;
  1053. ring->tx_pending = vsi->tx_rings[0]->count;
  1054. ring->rx_mini_pending = 0;
  1055. ring->rx_jumbo_pending = 0;
  1056. }
  1057. static int i40e_set_ringparam(struct net_device *netdev,
  1058. struct ethtool_ringparam *ring)
  1059. {
  1060. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  1061. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1062. struct i40e_vsi *vsi = np->vsi;
  1063. struct i40e_pf *pf = vsi->back;
  1064. u32 new_rx_count, new_tx_count;
  1065. int i, err = 0;
  1066. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1067. return -EINVAL;
  1068. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1069. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  1070. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1071. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  1072. netdev_info(netdev,
  1073. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  1074. ring->tx_pending, ring->rx_pending,
  1075. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  1076. return -EINVAL;
  1077. }
  1078. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1079. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1080. /* if nothing to do return success */
  1081. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1082. (new_rx_count == vsi->rx_rings[0]->count))
  1083. return 0;
  1084. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  1085. usleep_range(1000, 2000);
  1086. if (!netif_running(vsi->netdev)) {
  1087. /* simple case - set for the next time the netdev is started */
  1088. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1089. vsi->tx_rings[i]->count = new_tx_count;
  1090. vsi->rx_rings[i]->count = new_rx_count;
  1091. }
  1092. goto done;
  1093. }
  1094. /* We can't just free everything and then setup again,
  1095. * because the ISRs in MSI-X mode get passed pointers
  1096. * to the Tx and Rx ring structs.
  1097. */
  1098. /* alloc updated Tx resources */
  1099. if (new_tx_count != vsi->tx_rings[0]->count) {
  1100. netdev_info(netdev,
  1101. "Changing Tx descriptor count from %d to %d.\n",
  1102. vsi->tx_rings[0]->count, new_tx_count);
  1103. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  1104. sizeof(struct i40e_ring), GFP_KERNEL);
  1105. if (!tx_rings) {
  1106. err = -ENOMEM;
  1107. goto done;
  1108. }
  1109. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1110. /* clone ring and setup updated count */
  1111. tx_rings[i] = *vsi->tx_rings[i];
  1112. tx_rings[i].count = new_tx_count;
  1113. /* the desc and bi pointers will be reallocated in the
  1114. * setup call
  1115. */
  1116. tx_rings[i].desc = NULL;
  1117. tx_rings[i].rx_bi = NULL;
  1118. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1119. if (err) {
  1120. while (i) {
  1121. i--;
  1122. i40e_free_tx_resources(&tx_rings[i]);
  1123. }
  1124. kfree(tx_rings);
  1125. tx_rings = NULL;
  1126. goto done;
  1127. }
  1128. }
  1129. }
  1130. /* alloc updated Rx resources */
  1131. if (new_rx_count != vsi->rx_rings[0]->count) {
  1132. netdev_info(netdev,
  1133. "Changing Rx descriptor count from %d to %d\n",
  1134. vsi->rx_rings[0]->count, new_rx_count);
  1135. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1136. sizeof(struct i40e_ring), GFP_KERNEL);
  1137. if (!rx_rings) {
  1138. err = -ENOMEM;
  1139. goto free_tx;
  1140. }
  1141. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1142. /* clone ring and setup updated count */
  1143. rx_rings[i] = *vsi->rx_rings[i];
  1144. rx_rings[i].count = new_rx_count;
  1145. /* the desc and bi pointers will be reallocated in the
  1146. * setup call
  1147. */
  1148. rx_rings[i].desc = NULL;
  1149. rx_rings[i].rx_bi = NULL;
  1150. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1151. if (err) {
  1152. while (i) {
  1153. i--;
  1154. i40e_free_rx_resources(&rx_rings[i]);
  1155. }
  1156. kfree(rx_rings);
  1157. rx_rings = NULL;
  1158. goto free_tx;
  1159. }
  1160. }
  1161. }
  1162. /* Bring interface down, copy in the new ring info,
  1163. * then restore the interface
  1164. */
  1165. i40e_down(vsi);
  1166. if (tx_rings) {
  1167. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1168. i40e_free_tx_resources(vsi->tx_rings[i]);
  1169. *vsi->tx_rings[i] = tx_rings[i];
  1170. }
  1171. kfree(tx_rings);
  1172. tx_rings = NULL;
  1173. }
  1174. if (rx_rings) {
  1175. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1176. i40e_free_rx_resources(vsi->rx_rings[i]);
  1177. *vsi->rx_rings[i] = rx_rings[i];
  1178. }
  1179. kfree(rx_rings);
  1180. rx_rings = NULL;
  1181. }
  1182. i40e_up(vsi);
  1183. free_tx:
  1184. /* error cleanup if the Rx allocations failed after getting Tx */
  1185. if (tx_rings) {
  1186. for (i = 0; i < vsi->num_queue_pairs; i++)
  1187. i40e_free_tx_resources(&tx_rings[i]);
  1188. kfree(tx_rings);
  1189. tx_rings = NULL;
  1190. }
  1191. done:
  1192. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1193. return err;
  1194. }
  1195. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1196. {
  1197. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1198. struct i40e_vsi *vsi = np->vsi;
  1199. struct i40e_pf *pf = vsi->back;
  1200. switch (sset) {
  1201. case ETH_SS_TEST:
  1202. return I40E_TEST_LEN;
  1203. case ETH_SS_STATS:
  1204. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1205. int len = I40E_PF_STATS_LEN(netdev);
  1206. if ((pf->lan_veb != I40E_NO_VEB) &&
  1207. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
  1208. len += I40E_VEB_STATS_TOTAL;
  1209. return len;
  1210. } else {
  1211. return I40E_VSI_STATS_LEN(netdev);
  1212. }
  1213. case ETH_SS_PRIV_FLAGS:
  1214. return I40E_PRIV_FLAGS_STR_LEN;
  1215. default:
  1216. return -EOPNOTSUPP;
  1217. }
  1218. }
  1219. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1220. struct ethtool_stats *stats, u64 *data)
  1221. {
  1222. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1223. struct i40e_ring *tx_ring, *rx_ring;
  1224. struct i40e_vsi *vsi = np->vsi;
  1225. struct i40e_pf *pf = vsi->back;
  1226. int i = 0;
  1227. char *p;
  1228. int j;
  1229. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1230. unsigned int start;
  1231. i40e_update_stats(vsi);
  1232. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1233. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1234. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1235. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1236. }
  1237. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1238. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1239. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1240. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1241. }
  1242. #ifdef I40E_FCOE
  1243. for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
  1244. p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
  1245. data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
  1246. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1247. }
  1248. #endif
  1249. rcu_read_lock();
  1250. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1251. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1252. if (!tx_ring)
  1253. continue;
  1254. /* process Tx ring statistics */
  1255. do {
  1256. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1257. data[i] = tx_ring->stats.packets;
  1258. data[i + 1] = tx_ring->stats.bytes;
  1259. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1260. i += 2;
  1261. /* Rx ring is the 2nd half of the queue pair */
  1262. rx_ring = &tx_ring[1];
  1263. do {
  1264. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1265. data[i] = rx_ring->stats.packets;
  1266. data[i + 1] = rx_ring->stats.bytes;
  1267. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1268. i += 2;
  1269. }
  1270. rcu_read_unlock();
  1271. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1272. return;
  1273. if ((pf->lan_veb != I40E_NO_VEB) &&
  1274. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1275. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1276. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1277. p = (char *)veb;
  1278. p += i40e_gstrings_veb_stats[j].stat_offset;
  1279. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1280. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1281. }
  1282. for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
  1283. data[i++] = veb->tc_stats.tc_tx_packets[j];
  1284. data[i++] = veb->tc_stats.tc_tx_bytes[j];
  1285. data[i++] = veb->tc_stats.tc_rx_packets[j];
  1286. data[i++] = veb->tc_stats.tc_rx_bytes[j];
  1287. }
  1288. }
  1289. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1290. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1291. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1292. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1293. }
  1294. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1295. data[i++] = pf->stats.priority_xon_tx[j];
  1296. data[i++] = pf->stats.priority_xoff_tx[j];
  1297. }
  1298. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1299. data[i++] = pf->stats.priority_xon_rx[j];
  1300. data[i++] = pf->stats.priority_xoff_rx[j];
  1301. }
  1302. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1303. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1304. }
  1305. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1306. u8 *data)
  1307. {
  1308. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1309. struct i40e_vsi *vsi = np->vsi;
  1310. struct i40e_pf *pf = vsi->back;
  1311. char *p = (char *)data;
  1312. int i;
  1313. switch (stringset) {
  1314. case ETH_SS_TEST:
  1315. for (i = 0; i < I40E_TEST_LEN; i++) {
  1316. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  1317. data += ETH_GSTRING_LEN;
  1318. }
  1319. break;
  1320. case ETH_SS_STATS:
  1321. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1322. snprintf(p, ETH_GSTRING_LEN, "%s",
  1323. i40e_gstrings_net_stats[i].stat_string);
  1324. p += ETH_GSTRING_LEN;
  1325. }
  1326. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1327. snprintf(p, ETH_GSTRING_LEN, "%s",
  1328. i40e_gstrings_misc_stats[i].stat_string);
  1329. p += ETH_GSTRING_LEN;
  1330. }
  1331. #ifdef I40E_FCOE
  1332. for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
  1333. snprintf(p, ETH_GSTRING_LEN, "%s",
  1334. i40e_gstrings_fcoe_stats[i].stat_string);
  1335. p += ETH_GSTRING_LEN;
  1336. }
  1337. #endif
  1338. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1339. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  1340. p += ETH_GSTRING_LEN;
  1341. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  1342. p += ETH_GSTRING_LEN;
  1343. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  1344. p += ETH_GSTRING_LEN;
  1345. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  1346. p += ETH_GSTRING_LEN;
  1347. }
  1348. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1349. return;
  1350. if ((pf->lan_veb != I40E_NO_VEB) &&
  1351. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1352. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1353. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1354. i40e_gstrings_veb_stats[i].stat_string);
  1355. p += ETH_GSTRING_LEN;
  1356. }
  1357. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1358. snprintf(p, ETH_GSTRING_LEN,
  1359. "veb.tc_%u_tx_packets", i);
  1360. p += ETH_GSTRING_LEN;
  1361. snprintf(p, ETH_GSTRING_LEN,
  1362. "veb.tc_%u_tx_bytes", i);
  1363. p += ETH_GSTRING_LEN;
  1364. snprintf(p, ETH_GSTRING_LEN,
  1365. "veb.tc_%u_rx_packets", i);
  1366. p += ETH_GSTRING_LEN;
  1367. snprintf(p, ETH_GSTRING_LEN,
  1368. "veb.tc_%u_rx_bytes", i);
  1369. p += ETH_GSTRING_LEN;
  1370. }
  1371. }
  1372. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1373. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1374. i40e_gstrings_stats[i].stat_string);
  1375. p += ETH_GSTRING_LEN;
  1376. }
  1377. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1378. snprintf(p, ETH_GSTRING_LEN,
  1379. "port.tx_priority_%u_xon", i);
  1380. p += ETH_GSTRING_LEN;
  1381. snprintf(p, ETH_GSTRING_LEN,
  1382. "port.tx_priority_%u_xoff", i);
  1383. p += ETH_GSTRING_LEN;
  1384. }
  1385. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1386. snprintf(p, ETH_GSTRING_LEN,
  1387. "port.rx_priority_%u_xon", i);
  1388. p += ETH_GSTRING_LEN;
  1389. snprintf(p, ETH_GSTRING_LEN,
  1390. "port.rx_priority_%u_xoff", i);
  1391. p += ETH_GSTRING_LEN;
  1392. }
  1393. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1394. snprintf(p, ETH_GSTRING_LEN,
  1395. "port.rx_priority_%u_xon_2_xoff", i);
  1396. p += ETH_GSTRING_LEN;
  1397. }
  1398. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1399. break;
  1400. case ETH_SS_PRIV_FLAGS:
  1401. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  1402. memcpy(data, i40e_priv_flags_strings[i],
  1403. ETH_GSTRING_LEN);
  1404. data += ETH_GSTRING_LEN;
  1405. }
  1406. break;
  1407. default:
  1408. break;
  1409. }
  1410. }
  1411. static int i40e_get_ts_info(struct net_device *dev,
  1412. struct ethtool_ts_info *info)
  1413. {
  1414. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1415. /* only report HW timestamping if PTP is enabled */
  1416. if (!(pf->flags & I40E_FLAG_PTP))
  1417. return ethtool_op_get_ts_info(dev, info);
  1418. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1419. SOF_TIMESTAMPING_RX_SOFTWARE |
  1420. SOF_TIMESTAMPING_SOFTWARE |
  1421. SOF_TIMESTAMPING_TX_HARDWARE |
  1422. SOF_TIMESTAMPING_RX_HARDWARE |
  1423. SOF_TIMESTAMPING_RAW_HARDWARE;
  1424. if (pf->ptp_clock)
  1425. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1426. else
  1427. info->phc_index = -1;
  1428. info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
  1429. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  1430. BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  1431. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
  1432. return 0;
  1433. }
  1434. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1435. {
  1436. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1437. struct i40e_pf *pf = np->vsi->back;
  1438. i40e_status status;
  1439. bool link_up = false;
  1440. netif_info(pf, hw, netdev, "link test\n");
  1441. status = i40e_get_link_status(&pf->hw, &link_up);
  1442. if (status) {
  1443. netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
  1444. *data = 1;
  1445. return *data;
  1446. }
  1447. if (link_up)
  1448. *data = 0;
  1449. else
  1450. *data = 1;
  1451. return *data;
  1452. }
  1453. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1454. {
  1455. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1456. struct i40e_pf *pf = np->vsi->back;
  1457. netif_info(pf, hw, netdev, "register test\n");
  1458. *data = i40e_diag_reg_test(&pf->hw);
  1459. return *data;
  1460. }
  1461. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1462. {
  1463. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1464. struct i40e_pf *pf = np->vsi->back;
  1465. netif_info(pf, hw, netdev, "eeprom test\n");
  1466. *data = i40e_diag_eeprom_test(&pf->hw);
  1467. /* forcebly clear the NVM Update state machine */
  1468. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1469. return *data;
  1470. }
  1471. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1472. {
  1473. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1474. struct i40e_pf *pf = np->vsi->back;
  1475. u16 swc_old = pf->sw_int_count;
  1476. netif_info(pf, hw, netdev, "interrupt test\n");
  1477. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1478. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1479. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1480. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1481. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1482. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1483. usleep_range(1000, 2000);
  1484. *data = (swc_old == pf->sw_int_count);
  1485. return *data;
  1486. }
  1487. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  1488. {
  1489. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1490. struct i40e_pf *pf = np->vsi->back;
  1491. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  1492. *data = 0;
  1493. return *data;
  1494. }
  1495. static inline bool i40e_active_vfs(struct i40e_pf *pf)
  1496. {
  1497. struct i40e_vf *vfs = pf->vf;
  1498. int i;
  1499. for (i = 0; i < pf->num_alloc_vfs; i++)
  1500. if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
  1501. return true;
  1502. return false;
  1503. }
  1504. static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
  1505. {
  1506. struct i40e_vsi **vsi = pf->vsi;
  1507. int i;
  1508. for (i = 0; i < pf->num_alloc_vsi; i++) {
  1509. if (!vsi[i])
  1510. continue;
  1511. if (vsi[i]->type == I40E_VSI_VMDQ2)
  1512. return true;
  1513. }
  1514. return false;
  1515. }
  1516. static void i40e_diag_test(struct net_device *netdev,
  1517. struct ethtool_test *eth_test, u64 *data)
  1518. {
  1519. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1520. bool if_running = netif_running(netdev);
  1521. struct i40e_pf *pf = np->vsi->back;
  1522. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1523. /* Offline tests */
  1524. netif_info(pf, drv, netdev, "offline testing starting\n");
  1525. set_bit(__I40E_TESTING, &pf->state);
  1526. if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
  1527. dev_warn(&pf->pdev->dev,
  1528. "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
  1529. data[I40E_ETH_TEST_REG] = 1;
  1530. data[I40E_ETH_TEST_EEPROM] = 1;
  1531. data[I40E_ETH_TEST_INTR] = 1;
  1532. data[I40E_ETH_TEST_LOOPBACK] = 1;
  1533. data[I40E_ETH_TEST_LINK] = 1;
  1534. eth_test->flags |= ETH_TEST_FL_FAILED;
  1535. clear_bit(__I40E_TESTING, &pf->state);
  1536. goto skip_ol_tests;
  1537. }
  1538. /* If the device is online then take it offline */
  1539. if (if_running)
  1540. /* indicate we're in test mode */
  1541. dev_close(netdev);
  1542. else
  1543. /* This reset does not affect link - if it is
  1544. * changed to a type of reset that does affect
  1545. * link then the following link test would have
  1546. * to be moved to before the reset
  1547. */
  1548. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1549. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1550. eth_test->flags |= ETH_TEST_FL_FAILED;
  1551. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1552. eth_test->flags |= ETH_TEST_FL_FAILED;
  1553. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1554. eth_test->flags |= ETH_TEST_FL_FAILED;
  1555. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  1556. eth_test->flags |= ETH_TEST_FL_FAILED;
  1557. /* run reg test last, a reset is required after it */
  1558. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1559. eth_test->flags |= ETH_TEST_FL_FAILED;
  1560. clear_bit(__I40E_TESTING, &pf->state);
  1561. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1562. if (if_running)
  1563. dev_open(netdev);
  1564. } else {
  1565. /* Online tests */
  1566. netif_info(pf, drv, netdev, "online testing starting\n");
  1567. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1568. eth_test->flags |= ETH_TEST_FL_FAILED;
  1569. /* Offline only tests, not run in online; pass by default */
  1570. data[I40E_ETH_TEST_REG] = 0;
  1571. data[I40E_ETH_TEST_EEPROM] = 0;
  1572. data[I40E_ETH_TEST_INTR] = 0;
  1573. data[I40E_ETH_TEST_LOOPBACK] = 0;
  1574. }
  1575. skip_ol_tests:
  1576. netif_info(pf, drv, netdev, "testing finished\n");
  1577. }
  1578. static void i40e_get_wol(struct net_device *netdev,
  1579. struct ethtool_wolinfo *wol)
  1580. {
  1581. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1582. struct i40e_pf *pf = np->vsi->back;
  1583. struct i40e_hw *hw = &pf->hw;
  1584. u16 wol_nvm_bits;
  1585. /* NVM bit on means WoL disabled for the port */
  1586. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1587. if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
  1588. wol->supported = 0;
  1589. wol->wolopts = 0;
  1590. } else {
  1591. wol->supported = WAKE_MAGIC;
  1592. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1593. }
  1594. }
  1595. /**
  1596. * i40e_set_wol - set the WakeOnLAN configuration
  1597. * @netdev: the netdev in question
  1598. * @wol: the ethtool WoL setting data
  1599. **/
  1600. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1601. {
  1602. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1603. struct i40e_pf *pf = np->vsi->back;
  1604. struct i40e_vsi *vsi = np->vsi;
  1605. struct i40e_hw *hw = &pf->hw;
  1606. u16 wol_nvm_bits;
  1607. /* WoL not supported if this isn't the controlling PF on the port */
  1608. if (hw->partition_id != 1) {
  1609. i40e_partition_setting_complaint(pf);
  1610. return -EOPNOTSUPP;
  1611. }
  1612. if (vsi != pf->vsi[pf->lan_vsi])
  1613. return -EOPNOTSUPP;
  1614. /* NVM bit on means WoL disabled for the port */
  1615. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1616. if (BIT(hw->port) & wol_nvm_bits)
  1617. return -EOPNOTSUPP;
  1618. /* only magic packet is supported */
  1619. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1620. return -EOPNOTSUPP;
  1621. /* is this a new value? */
  1622. if (pf->wol_en != !!wol->wolopts) {
  1623. pf->wol_en = !!wol->wolopts;
  1624. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1625. }
  1626. return 0;
  1627. }
  1628. static int i40e_set_phys_id(struct net_device *netdev,
  1629. enum ethtool_phys_id_state state)
  1630. {
  1631. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1632. i40e_status ret = 0;
  1633. struct i40e_pf *pf = np->vsi->back;
  1634. struct i40e_hw *hw = &pf->hw;
  1635. int blink_freq = 2;
  1636. u16 temp_status;
  1637. switch (state) {
  1638. case ETHTOOL_ID_ACTIVE:
  1639. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1640. pf->led_status = i40e_led_get(hw);
  1641. } else {
  1642. i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_PORT, NULL);
  1643. ret = i40e_led_get_phy(hw, &temp_status,
  1644. &pf->phy_led_val);
  1645. pf->led_status = temp_status;
  1646. }
  1647. return blink_freq;
  1648. case ETHTOOL_ID_ON:
  1649. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1650. i40e_led_set(hw, 0xf, false);
  1651. else
  1652. ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
  1653. break;
  1654. case ETHTOOL_ID_OFF:
  1655. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1656. i40e_led_set(hw, 0x0, false);
  1657. else
  1658. ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
  1659. break;
  1660. case ETHTOOL_ID_INACTIVE:
  1661. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1662. i40e_led_set(hw, false, pf->led_status);
  1663. } else {
  1664. ret = i40e_led_set_phy(hw, false, pf->led_status,
  1665. (pf->phy_led_val |
  1666. I40E_PHY_LED_MODE_ORIG));
  1667. i40e_aq_set_phy_debug(hw, 0, NULL);
  1668. }
  1669. break;
  1670. default:
  1671. break;
  1672. }
  1673. if (ret)
  1674. return -ENOENT;
  1675. else
  1676. return 0;
  1677. }
  1678. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1679. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1680. * 125us (8000 interrupts per second) == ITR(62)
  1681. */
  1682. static int __i40e_get_coalesce(struct net_device *netdev,
  1683. struct ethtool_coalesce *ec,
  1684. int queue)
  1685. {
  1686. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1687. struct i40e_vsi *vsi = np->vsi;
  1688. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1689. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1690. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1691. * return queue 0's value to represent.
  1692. */
  1693. if (queue < 0) {
  1694. queue = 0;
  1695. } else if (queue >= vsi->num_queue_pairs) {
  1696. return -EINVAL;
  1697. }
  1698. if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting))
  1699. ec->use_adaptive_rx_coalesce = 1;
  1700. if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting))
  1701. ec->use_adaptive_tx_coalesce = 1;
  1702. ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1703. ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1704. /* we use the _usecs_high to store/set the interrupt rate limit
  1705. * that the hardware supports, that almost but not quite
  1706. * fits the original intent of the ethtool variable,
  1707. * the rx_coalesce_usecs_high limits total interrupts
  1708. * per second from both tx/rx sources.
  1709. */
  1710. ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
  1711. ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
  1712. return 0;
  1713. }
  1714. static int i40e_get_coalesce(struct net_device *netdev,
  1715. struct ethtool_coalesce *ec)
  1716. {
  1717. return __i40e_get_coalesce(netdev, ec, -1);
  1718. }
  1719. static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1720. struct ethtool_coalesce *ec)
  1721. {
  1722. return __i40e_get_coalesce(netdev, ec, queue);
  1723. }
  1724. static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
  1725. struct ethtool_coalesce *ec,
  1726. int queue)
  1727. {
  1728. struct i40e_pf *pf = vsi->back;
  1729. struct i40e_hw *hw = &pf->hw;
  1730. struct i40e_q_vector *q_vector;
  1731. u16 vector, intrl;
  1732. intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
  1733. vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
  1734. vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
  1735. if (ec->use_adaptive_rx_coalesce)
  1736. vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1737. else
  1738. vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1739. if (ec->use_adaptive_tx_coalesce)
  1740. vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1741. else
  1742. vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1743. q_vector = vsi->rx_rings[queue]->q_vector;
  1744. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
  1745. vector = vsi->base_vector + q_vector->v_idx;
  1746. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  1747. q_vector = vsi->tx_rings[queue]->q_vector;
  1748. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
  1749. vector = vsi->base_vector + q_vector->v_idx;
  1750. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  1751. wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
  1752. i40e_flush(hw);
  1753. }
  1754. static int __i40e_set_coalesce(struct net_device *netdev,
  1755. struct ethtool_coalesce *ec,
  1756. int queue)
  1757. {
  1758. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1759. struct i40e_vsi *vsi = np->vsi;
  1760. struct i40e_pf *pf = vsi->back;
  1761. int i;
  1762. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1763. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1764. /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
  1765. if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
  1766. netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
  1767. return -EINVAL;
  1768. }
  1769. if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
  1770. netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
  1771. return -EINVAL;
  1772. }
  1773. if (ec->rx_coalesce_usecs == 0) {
  1774. if (ec->use_adaptive_rx_coalesce)
  1775. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1776. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1777. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1778. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1779. return -EINVAL;
  1780. }
  1781. vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
  1782. if (ec->tx_coalesce_usecs == 0) {
  1783. if (ec->use_adaptive_tx_coalesce)
  1784. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1785. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1786. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1787. netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  1788. return -EINVAL;
  1789. }
  1790. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1791. * apply to all queues.
  1792. */
  1793. if (queue < 0) {
  1794. for (i = 0; i < vsi->num_queue_pairs; i++)
  1795. i40e_set_itr_per_queue(vsi, ec, i);
  1796. } else if (queue < vsi->num_queue_pairs) {
  1797. i40e_set_itr_per_queue(vsi, ec, queue);
  1798. } else {
  1799. netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  1800. vsi->num_queue_pairs - 1);
  1801. return -EINVAL;
  1802. }
  1803. return 0;
  1804. }
  1805. static int i40e_set_coalesce(struct net_device *netdev,
  1806. struct ethtool_coalesce *ec)
  1807. {
  1808. return __i40e_set_coalesce(netdev, ec, -1);
  1809. }
  1810. static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1811. struct ethtool_coalesce *ec)
  1812. {
  1813. return __i40e_set_coalesce(netdev, ec, queue);
  1814. }
  1815. /**
  1816. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1817. * @pf: pointer to the physical function struct
  1818. * @cmd: ethtool rxnfc command
  1819. *
  1820. * Returns Success if the flow is supported, else Invalid Input.
  1821. **/
  1822. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1823. {
  1824. cmd->data = 0;
  1825. if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
  1826. cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
  1827. cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
  1828. return 0;
  1829. }
  1830. /* Report default options for RSS on i40e */
  1831. switch (cmd->flow_type) {
  1832. case TCP_V4_FLOW:
  1833. case UDP_V4_FLOW:
  1834. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1835. /* fall through to add IP fields */
  1836. case SCTP_V4_FLOW:
  1837. case AH_ESP_V4_FLOW:
  1838. case AH_V4_FLOW:
  1839. case ESP_V4_FLOW:
  1840. case IPV4_FLOW:
  1841. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1842. break;
  1843. case TCP_V6_FLOW:
  1844. case UDP_V6_FLOW:
  1845. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1846. /* fall through to add IP fields */
  1847. case SCTP_V6_FLOW:
  1848. case AH_ESP_V6_FLOW:
  1849. case AH_V6_FLOW:
  1850. case ESP_V6_FLOW:
  1851. case IPV6_FLOW:
  1852. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1853. break;
  1854. default:
  1855. return -EINVAL;
  1856. }
  1857. return 0;
  1858. }
  1859. /**
  1860. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  1861. * @pf: Pointer to the physical function struct
  1862. * @cmd: The command to get or set Rx flow classification rules
  1863. * @rule_locs: Array of used rule locations
  1864. *
  1865. * This function populates both the total and actual rule count of
  1866. * the ethtool flow classification command
  1867. *
  1868. * Returns 0 on success or -EMSGSIZE if entry not found
  1869. **/
  1870. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  1871. struct ethtool_rxnfc *cmd,
  1872. u32 *rule_locs)
  1873. {
  1874. struct i40e_fdir_filter *rule;
  1875. struct hlist_node *node2;
  1876. int cnt = 0;
  1877. /* report total rule count */
  1878. cmd->data = i40e_get_fd_cnt_all(pf);
  1879. hlist_for_each_entry_safe(rule, node2,
  1880. &pf->fdir_filter_list, fdir_node) {
  1881. if (cnt == cmd->rule_cnt)
  1882. return -EMSGSIZE;
  1883. rule_locs[cnt] = rule->fd_id;
  1884. cnt++;
  1885. }
  1886. cmd->rule_cnt = cnt;
  1887. return 0;
  1888. }
  1889. /**
  1890. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  1891. * @pf: Pointer to the physical function struct
  1892. * @cmd: The command to get or set Rx flow classification rules
  1893. *
  1894. * This function looks up a filter based on the Rx flow classification
  1895. * command and fills the flow spec info for it if found
  1896. *
  1897. * Returns 0 on success or -EINVAL if filter not found
  1898. **/
  1899. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  1900. struct ethtool_rxnfc *cmd)
  1901. {
  1902. struct ethtool_rx_flow_spec *fsp =
  1903. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1904. struct i40e_fdir_filter *rule = NULL;
  1905. struct hlist_node *node2;
  1906. hlist_for_each_entry_safe(rule, node2,
  1907. &pf->fdir_filter_list, fdir_node) {
  1908. if (fsp->location <= rule->fd_id)
  1909. break;
  1910. }
  1911. if (!rule || fsp->location != rule->fd_id)
  1912. return -EINVAL;
  1913. fsp->flow_type = rule->flow_type;
  1914. if (fsp->flow_type == IP_USER_FLOW) {
  1915. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  1916. fsp->h_u.usr_ip4_spec.proto = 0;
  1917. fsp->m_u.usr_ip4_spec.proto = 0;
  1918. }
  1919. /* Reverse the src and dest notion, since the HW views them from
  1920. * Tx perspective where as the user expects it from Rx filter view.
  1921. */
  1922. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  1923. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  1924. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  1925. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  1926. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  1927. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  1928. else
  1929. fsp->ring_cookie = rule->q_index;
  1930. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  1931. struct i40e_vsi *vsi;
  1932. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  1933. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  1934. fsp->h_ext.data[1] = htonl(vsi->vf_id);
  1935. fsp->m_ext.data[1] = htonl(0x1);
  1936. }
  1937. }
  1938. return 0;
  1939. }
  1940. /**
  1941. * i40e_get_rxnfc - command to get RX flow classification rules
  1942. * @netdev: network interface device structure
  1943. * @cmd: ethtool rxnfc command
  1944. *
  1945. * Returns Success if the command is supported.
  1946. **/
  1947. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  1948. u32 *rule_locs)
  1949. {
  1950. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1951. struct i40e_vsi *vsi = np->vsi;
  1952. struct i40e_pf *pf = vsi->back;
  1953. int ret = -EOPNOTSUPP;
  1954. switch (cmd->cmd) {
  1955. case ETHTOOL_GRXRINGS:
  1956. cmd->data = vsi->num_queue_pairs;
  1957. ret = 0;
  1958. break;
  1959. case ETHTOOL_GRXFH:
  1960. ret = i40e_get_rss_hash_opts(pf, cmd);
  1961. break;
  1962. case ETHTOOL_GRXCLSRLCNT:
  1963. cmd->rule_cnt = pf->fdir_pf_active_filters;
  1964. /* report total rule count */
  1965. cmd->data = i40e_get_fd_cnt_all(pf);
  1966. ret = 0;
  1967. break;
  1968. case ETHTOOL_GRXCLSRULE:
  1969. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  1970. break;
  1971. case ETHTOOL_GRXCLSRLALL:
  1972. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  1973. break;
  1974. default:
  1975. break;
  1976. }
  1977. return ret;
  1978. }
  1979. /**
  1980. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  1981. * @pf: pointer to the physical function struct
  1982. * @cmd: ethtool rxnfc command
  1983. *
  1984. * Returns Success if the flow input set is supported.
  1985. **/
  1986. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  1987. {
  1988. struct i40e_hw *hw = &pf->hw;
  1989. u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  1990. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  1991. /* RSS does not support anything other than hashing
  1992. * to queues on src and dst IPs and ports
  1993. */
  1994. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  1995. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  1996. return -EINVAL;
  1997. /* We need at least the IP SRC and DEST fields for hashing */
  1998. if (!(nfc->data & RXH_IP_SRC) ||
  1999. !(nfc->data & RXH_IP_DST))
  2000. return -EINVAL;
  2001. switch (nfc->flow_type) {
  2002. case TCP_V4_FLOW:
  2003. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2004. case 0:
  2005. return -EINVAL;
  2006. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2007. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2008. hena |=
  2009. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2010. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  2011. break;
  2012. default:
  2013. return -EINVAL;
  2014. }
  2015. break;
  2016. case TCP_V6_FLOW:
  2017. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2018. case 0:
  2019. return -EINVAL;
  2020. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2021. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2022. hena |=
  2023. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  2024. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  2025. break;
  2026. default:
  2027. return -EINVAL;
  2028. }
  2029. break;
  2030. case UDP_V4_FLOW:
  2031. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2032. case 0:
  2033. return -EINVAL;
  2034. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2035. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2036. hena |=
  2037. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  2038. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  2039. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  2040. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
  2041. break;
  2042. default:
  2043. return -EINVAL;
  2044. }
  2045. break;
  2046. case UDP_V6_FLOW:
  2047. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2048. case 0:
  2049. return -EINVAL;
  2050. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2051. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2052. hena |=
  2053. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  2054. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  2055. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  2056. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
  2057. break;
  2058. default:
  2059. return -EINVAL;
  2060. }
  2061. break;
  2062. case AH_ESP_V4_FLOW:
  2063. case AH_V4_FLOW:
  2064. case ESP_V4_FLOW:
  2065. case SCTP_V4_FLOW:
  2066. if ((nfc->data & RXH_L4_B_0_1) ||
  2067. (nfc->data & RXH_L4_B_2_3))
  2068. return -EINVAL;
  2069. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  2070. break;
  2071. case AH_ESP_V6_FLOW:
  2072. case AH_V6_FLOW:
  2073. case ESP_V6_FLOW:
  2074. case SCTP_V6_FLOW:
  2075. if ((nfc->data & RXH_L4_B_0_1) ||
  2076. (nfc->data & RXH_L4_B_2_3))
  2077. return -EINVAL;
  2078. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  2079. break;
  2080. case IPV4_FLOW:
  2081. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  2082. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2083. break;
  2084. case IPV6_FLOW:
  2085. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  2086. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2087. break;
  2088. default:
  2089. return -EINVAL;
  2090. }
  2091. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  2092. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  2093. i40e_flush(hw);
  2094. /* Save setting for future output/update */
  2095. pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
  2096. return 0;
  2097. }
  2098. /**
  2099. * i40e_match_fdir_input_set - Match a new filter against an existing one
  2100. * @rule: The filter already added
  2101. * @input: The new filter to comapre against
  2102. *
  2103. * Returns true if the two input set match
  2104. **/
  2105. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  2106. struct i40e_fdir_filter *input)
  2107. {
  2108. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  2109. (rule->src_ip[0] != input->src_ip[0]) ||
  2110. (rule->dst_port != input->dst_port) ||
  2111. (rule->src_port != input->src_port))
  2112. return false;
  2113. return true;
  2114. }
  2115. /**
  2116. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  2117. * @vsi: Pointer to the targeted VSI
  2118. * @input: The filter to update or NULL to indicate deletion
  2119. * @sw_idx: Software index to the filter
  2120. * @cmd: The command to get or set Rx flow classification rules
  2121. *
  2122. * This function updates (or deletes) a Flow Director entry from
  2123. * the hlist of the corresponding PF
  2124. *
  2125. * Returns 0 on success
  2126. **/
  2127. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  2128. struct i40e_fdir_filter *input,
  2129. u16 sw_idx,
  2130. struct ethtool_rxnfc *cmd)
  2131. {
  2132. struct i40e_fdir_filter *rule, *parent;
  2133. struct i40e_pf *pf = vsi->back;
  2134. struct hlist_node *node2;
  2135. int err = -EINVAL;
  2136. parent = NULL;
  2137. rule = NULL;
  2138. hlist_for_each_entry_safe(rule, node2,
  2139. &pf->fdir_filter_list, fdir_node) {
  2140. /* hash found, or no matching entry */
  2141. if (rule->fd_id >= sw_idx)
  2142. break;
  2143. parent = rule;
  2144. }
  2145. /* if there is an old rule occupying our place remove it */
  2146. if (rule && (rule->fd_id == sw_idx)) {
  2147. if (input && !i40e_match_fdir_input_set(rule, input))
  2148. err = i40e_add_del_fdir(vsi, rule, false);
  2149. else if (!input)
  2150. err = i40e_add_del_fdir(vsi, rule, false);
  2151. hlist_del(&rule->fdir_node);
  2152. kfree(rule);
  2153. pf->fdir_pf_active_filters--;
  2154. }
  2155. /* If no input this was a delete, err should be 0 if a rule was
  2156. * successfully found and removed from the list else -EINVAL
  2157. */
  2158. if (!input)
  2159. return err;
  2160. /* initialize node and set software index */
  2161. INIT_HLIST_NODE(&input->fdir_node);
  2162. /* add filter to the list */
  2163. if (parent)
  2164. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  2165. else
  2166. hlist_add_head(&input->fdir_node,
  2167. &pf->fdir_filter_list);
  2168. /* update counts */
  2169. pf->fdir_pf_active_filters++;
  2170. return 0;
  2171. }
  2172. /**
  2173. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  2174. * @vsi: Pointer to the targeted VSI
  2175. * @cmd: The command to get or set Rx flow classification rules
  2176. *
  2177. * The function removes a Flow Director filter entry from the
  2178. * hlist of the corresponding PF
  2179. *
  2180. * Returns 0 on success
  2181. */
  2182. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  2183. struct ethtool_rxnfc *cmd)
  2184. {
  2185. struct ethtool_rx_flow_spec *fsp =
  2186. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2187. struct i40e_pf *pf = vsi->back;
  2188. int ret = 0;
  2189. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2190. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2191. return -EBUSY;
  2192. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2193. return -EBUSY;
  2194. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  2195. i40e_fdir_check_and_reenable(pf);
  2196. return ret;
  2197. }
  2198. /**
  2199. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  2200. * @vsi: pointer to the targeted VSI
  2201. * @cmd: command to get or set RX flow classification rules
  2202. *
  2203. * Add Flow Director filters for a specific flow spec based on their
  2204. * protocol. Returns 0 if the filters were successfully added.
  2205. **/
  2206. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  2207. struct ethtool_rxnfc *cmd)
  2208. {
  2209. struct ethtool_rx_flow_spec *fsp;
  2210. struct i40e_fdir_filter *input;
  2211. struct i40e_pf *pf;
  2212. int ret = -EINVAL;
  2213. u16 vf_id;
  2214. if (!vsi)
  2215. return -EINVAL;
  2216. pf = vsi->back;
  2217. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2218. return -EOPNOTSUPP;
  2219. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  2220. return -ENOSPC;
  2221. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2222. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2223. return -EBUSY;
  2224. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2225. return -EBUSY;
  2226. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  2227. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  2228. pf->hw.func_caps.fd_filters_guaranteed)) {
  2229. return -EINVAL;
  2230. }
  2231. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  2232. (fsp->ring_cookie >= vsi->num_queue_pairs))
  2233. return -EINVAL;
  2234. input = kzalloc(sizeof(*input), GFP_KERNEL);
  2235. if (!input)
  2236. return -ENOMEM;
  2237. input->fd_id = fsp->location;
  2238. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  2239. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2240. else
  2241. input->dest_ctl =
  2242. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  2243. input->q_index = fsp->ring_cookie;
  2244. input->flex_off = 0;
  2245. input->pctype = 0;
  2246. input->dest_vsi = vsi->id;
  2247. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  2248. input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  2249. input->flow_type = fsp->flow_type;
  2250. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  2251. /* Reverse the src and dest notion, since the HW expects them to be from
  2252. * Tx perspective where as the input from user is from Rx filter view.
  2253. */
  2254. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  2255. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  2256. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  2257. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  2258. if (ntohl(fsp->m_ext.data[1])) {
  2259. if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
  2260. netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
  2261. goto free_input;
  2262. }
  2263. vf_id = ntohl(fsp->h_ext.data[1]);
  2264. /* Find vsi id from vf id and override dest vsi */
  2265. input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
  2266. if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
  2267. netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
  2268. goto free_input;
  2269. }
  2270. }
  2271. ret = i40e_add_del_fdir(vsi, input, true);
  2272. free_input:
  2273. if (ret)
  2274. kfree(input);
  2275. else
  2276. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  2277. return ret;
  2278. }
  2279. /**
  2280. * i40e_set_rxnfc - command to set RX flow classification rules
  2281. * @netdev: network interface device structure
  2282. * @cmd: ethtool rxnfc command
  2283. *
  2284. * Returns Success if the command is supported.
  2285. **/
  2286. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  2287. {
  2288. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2289. struct i40e_vsi *vsi = np->vsi;
  2290. struct i40e_pf *pf = vsi->back;
  2291. int ret = -EOPNOTSUPP;
  2292. switch (cmd->cmd) {
  2293. case ETHTOOL_SRXFH:
  2294. ret = i40e_set_rss_hash_opt(pf, cmd);
  2295. break;
  2296. case ETHTOOL_SRXCLSRLINS:
  2297. ret = i40e_add_fdir_ethtool(vsi, cmd);
  2298. break;
  2299. case ETHTOOL_SRXCLSRLDEL:
  2300. ret = i40e_del_fdir_entry(vsi, cmd);
  2301. break;
  2302. default:
  2303. break;
  2304. }
  2305. return ret;
  2306. }
  2307. /**
  2308. * i40e_max_channels - get Max number of combined channels supported
  2309. * @vsi: vsi pointer
  2310. **/
  2311. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  2312. {
  2313. /* TODO: This code assumes DCB and FD is disabled for now. */
  2314. return vsi->alloc_queue_pairs;
  2315. }
  2316. /**
  2317. * i40e_get_channels - Get the current channels enabled and max supported etc.
  2318. * @netdev: network interface device structure
  2319. * @ch: ethtool channels structure
  2320. *
  2321. * We don't support separate tx and rx queues as channels. The other count
  2322. * represents how many queues are being used for control. max_combined counts
  2323. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  2324. * q_vectors since we support a lot more queue pairs than q_vectors.
  2325. **/
  2326. static void i40e_get_channels(struct net_device *dev,
  2327. struct ethtool_channels *ch)
  2328. {
  2329. struct i40e_netdev_priv *np = netdev_priv(dev);
  2330. struct i40e_vsi *vsi = np->vsi;
  2331. struct i40e_pf *pf = vsi->back;
  2332. /* report maximum channels */
  2333. ch->max_combined = i40e_max_channels(vsi);
  2334. /* report info for other vector */
  2335. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  2336. ch->max_other = ch->other_count;
  2337. /* Note: This code assumes DCB is disabled for now. */
  2338. ch->combined_count = vsi->num_queue_pairs;
  2339. }
  2340. /**
  2341. * i40e_set_channels - Set the new channels count.
  2342. * @netdev: network interface device structure
  2343. * @ch: ethtool channels structure
  2344. *
  2345. * The new channels count may not be the same as requested by the user
  2346. * since it gets rounded down to a power of 2 value.
  2347. **/
  2348. static int i40e_set_channels(struct net_device *dev,
  2349. struct ethtool_channels *ch)
  2350. {
  2351. struct i40e_netdev_priv *np = netdev_priv(dev);
  2352. unsigned int count = ch->combined_count;
  2353. struct i40e_vsi *vsi = np->vsi;
  2354. struct i40e_pf *pf = vsi->back;
  2355. int new_count;
  2356. /* We do not support setting channels for any other VSI at present */
  2357. if (vsi->type != I40E_VSI_MAIN)
  2358. return -EINVAL;
  2359. /* verify they are not requesting separate vectors */
  2360. if (!count || ch->rx_count || ch->tx_count)
  2361. return -EINVAL;
  2362. /* verify other_count has not changed */
  2363. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  2364. return -EINVAL;
  2365. /* verify the number of channels does not exceed hardware limits */
  2366. if (count > i40e_max_channels(vsi))
  2367. return -EINVAL;
  2368. /* update feature limits from largest to smallest supported values */
  2369. /* TODO: Flow director limit, DCB etc */
  2370. /* use rss_reconfig to rebuild with new queue count and update traffic
  2371. * class queue mapping
  2372. */
  2373. new_count = i40e_reconfig_rss_queues(pf, count);
  2374. if (new_count > 0)
  2375. return 0;
  2376. else
  2377. return -EINVAL;
  2378. }
  2379. /**
  2380. * i40e_get_rxfh_key_size - get the RSS hash key size
  2381. * @netdev: network interface device structure
  2382. *
  2383. * Returns the table size.
  2384. **/
  2385. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  2386. {
  2387. return I40E_HKEY_ARRAY_SIZE;
  2388. }
  2389. /**
  2390. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  2391. * @netdev: network interface device structure
  2392. *
  2393. * Returns the table size.
  2394. **/
  2395. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  2396. {
  2397. return I40E_HLUT_ARRAY_SIZE;
  2398. }
  2399. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  2400. u8 *hfunc)
  2401. {
  2402. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2403. struct i40e_vsi *vsi = np->vsi;
  2404. u8 *lut, *seed = NULL;
  2405. int ret;
  2406. u16 i;
  2407. if (hfunc)
  2408. *hfunc = ETH_RSS_HASH_TOP;
  2409. if (!indir)
  2410. return 0;
  2411. seed = key;
  2412. lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2413. if (!lut)
  2414. return -ENOMEM;
  2415. ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
  2416. if (ret)
  2417. goto out;
  2418. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2419. indir[i] = (u32)(lut[i]);
  2420. out:
  2421. kfree(lut);
  2422. return ret;
  2423. }
  2424. /**
  2425. * i40e_set_rxfh - set the rx flow hash indirection table
  2426. * @netdev: network interface device structure
  2427. * @indir: indirection table
  2428. * @key: hash key
  2429. *
  2430. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  2431. * returns 0 after programming the table.
  2432. **/
  2433. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  2434. const u8 *key, const u8 hfunc)
  2435. {
  2436. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2437. struct i40e_vsi *vsi = np->vsi;
  2438. u8 *seed = NULL;
  2439. u16 i;
  2440. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  2441. return -EOPNOTSUPP;
  2442. if (!indir)
  2443. return 0;
  2444. if (key) {
  2445. if (!vsi->rss_hkey_user) {
  2446. vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
  2447. GFP_KERNEL);
  2448. if (!vsi->rss_hkey_user)
  2449. return -ENOMEM;
  2450. }
  2451. memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
  2452. seed = vsi->rss_hkey_user;
  2453. }
  2454. if (!vsi->rss_lut_user) {
  2455. vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2456. if (!vsi->rss_lut_user)
  2457. return -ENOMEM;
  2458. }
  2459. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  2460. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2461. vsi->rss_lut_user[i] = (u8)(indir[i]);
  2462. return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
  2463. I40E_HLUT_ARRAY_SIZE);
  2464. }
  2465. /**
  2466. * i40e_get_priv_flags - report device private flags
  2467. * @dev: network interface device structure
  2468. *
  2469. * The get string set count and the string set should be matched for each
  2470. * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
  2471. * array.
  2472. *
  2473. * Returns a u32 bitmap of flags.
  2474. **/
  2475. static u32 i40e_get_priv_flags(struct net_device *dev)
  2476. {
  2477. struct i40e_netdev_priv *np = netdev_priv(dev);
  2478. struct i40e_vsi *vsi = np->vsi;
  2479. struct i40e_pf *pf = vsi->back;
  2480. u32 ret_flags = 0;
  2481. ret_flags |= pf->hw.func_caps.npar_enable ?
  2482. I40E_PRIV_FLAGS_NPAR_FLAG : 0;
  2483. ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
  2484. I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
  2485. ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
  2486. I40E_PRIV_FLAGS_FD_ATR : 0;
  2487. ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
  2488. I40E_PRIV_FLAGS_VEB_STATS : 0;
  2489. ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
  2490. I40E_PRIV_FLAGS_PS : 0;
  2491. ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
  2492. 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
  2493. return ret_flags;
  2494. }
  2495. /**
  2496. * i40e_set_priv_flags - set private flags
  2497. * @dev: network interface device structure
  2498. * @flags: bit flags to be set
  2499. **/
  2500. static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
  2501. {
  2502. struct i40e_netdev_priv *np = netdev_priv(dev);
  2503. struct i40e_vsi *vsi = np->vsi;
  2504. struct i40e_pf *pf = vsi->back;
  2505. bool reset_required = false;
  2506. /* NOTE: MFP is not settable */
  2507. /* allow the user to control the method of receive
  2508. * buffer DMA, whether the packet is split at header
  2509. * boundaries into two separate buffers. In some cases
  2510. * one routine or the other will perform better.
  2511. */
  2512. if ((flags & I40E_PRIV_FLAGS_PS) &&
  2513. !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
  2514. pf->flags |= I40E_FLAG_RX_PS_ENABLED;
  2515. pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
  2516. reset_required = true;
  2517. } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
  2518. (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
  2519. pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
  2520. pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
  2521. reset_required = true;
  2522. }
  2523. if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
  2524. pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
  2525. else
  2526. pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
  2527. /* allow the user to control the state of the Flow
  2528. * Director ATR (Application Targeted Routing) feature
  2529. * of the driver
  2530. */
  2531. if (flags & I40E_PRIV_FLAGS_FD_ATR) {
  2532. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  2533. } else {
  2534. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  2535. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  2536. }
  2537. if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2538. !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2539. pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
  2540. reset_required = true;
  2541. } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2542. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2543. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  2544. reset_required = true;
  2545. }
  2546. if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
  2547. (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
  2548. pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2549. else
  2550. pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2551. /* if needed, issue reset to cause things to take effect */
  2552. if (reset_required)
  2553. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  2554. return 0;
  2555. }
  2556. static const struct ethtool_ops i40e_ethtool_ops = {
  2557. .get_settings = i40e_get_settings,
  2558. .set_settings = i40e_set_settings,
  2559. .get_drvinfo = i40e_get_drvinfo,
  2560. .get_regs_len = i40e_get_regs_len,
  2561. .get_regs = i40e_get_regs,
  2562. .nway_reset = i40e_nway_reset,
  2563. .get_link = ethtool_op_get_link,
  2564. .get_wol = i40e_get_wol,
  2565. .set_wol = i40e_set_wol,
  2566. .set_eeprom = i40e_set_eeprom,
  2567. .get_eeprom_len = i40e_get_eeprom_len,
  2568. .get_eeprom = i40e_get_eeprom,
  2569. .get_ringparam = i40e_get_ringparam,
  2570. .set_ringparam = i40e_set_ringparam,
  2571. .get_pauseparam = i40e_get_pauseparam,
  2572. .set_pauseparam = i40e_set_pauseparam,
  2573. .get_msglevel = i40e_get_msglevel,
  2574. .set_msglevel = i40e_set_msglevel,
  2575. .get_rxnfc = i40e_get_rxnfc,
  2576. .set_rxnfc = i40e_set_rxnfc,
  2577. .self_test = i40e_diag_test,
  2578. .get_strings = i40e_get_strings,
  2579. .set_phys_id = i40e_set_phys_id,
  2580. .get_sset_count = i40e_get_sset_count,
  2581. .get_ethtool_stats = i40e_get_ethtool_stats,
  2582. .get_coalesce = i40e_get_coalesce,
  2583. .set_coalesce = i40e_set_coalesce,
  2584. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  2585. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  2586. .get_rxfh = i40e_get_rxfh,
  2587. .set_rxfh = i40e_set_rxfh,
  2588. .get_channels = i40e_get_channels,
  2589. .set_channels = i40e_set_channels,
  2590. .get_ts_info = i40e_get_ts_info,
  2591. .get_priv_flags = i40e_get_priv_flags,
  2592. .set_priv_flags = i40e_set_priv_flags,
  2593. .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
  2594. .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
  2595. };
  2596. void i40e_set_ethtool_ops(struct net_device *netdev)
  2597. {
  2598. netdev->ethtool_ops = &i40e_ethtool_ops;
  2599. }