i40e_ethtool.c 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151
  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 const 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. #define I40E_QUEUE_STATS_LEN(n) \
  155. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  156. * 2 /* Tx and Rx together */ \
  157. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  158. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  159. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  160. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  161. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  162. I40E_MISC_STATS_LEN + \
  163. I40E_QUEUE_STATS_LEN((n)))
  164. #define I40E_PFC_STATS_LEN ( \
  165. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  166. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  167. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  168. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  169. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  170. / sizeof(u64))
  171. #define I40E_VEB_TC_STATS_LEN ( \
  172. (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
  173. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
  174. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
  175. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
  176. / sizeof(u64))
  177. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  178. #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
  179. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  180. I40E_PFC_STATS_LEN + \
  181. I40E_VSI_STATS_LEN((n)))
  182. enum i40e_ethtool_test_id {
  183. I40E_ETH_TEST_REG = 0,
  184. I40E_ETH_TEST_EEPROM,
  185. I40E_ETH_TEST_INTR,
  186. I40E_ETH_TEST_LINK,
  187. };
  188. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  189. "Register test (offline)",
  190. "Eeprom test (offline)",
  191. "Interrupt test (offline)",
  192. "Link test (on/offline)"
  193. };
  194. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  195. struct i40e_priv_flags {
  196. char flag_string[ETH_GSTRING_LEN];
  197. u64 flag;
  198. bool read_only;
  199. };
  200. #define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
  201. .flag_string = _name, \
  202. .flag = _flag, \
  203. .read_only = _read_only, \
  204. }
  205. static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
  206. /* NOTE: MFP setting cannot be changed */
  207. I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
  208. I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
  209. I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
  210. I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
  211. I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_CAPABLE, 0),
  212. I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
  213. };
  214. #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
  215. /* Private flags with a global effect, restricted to PF 0 */
  216. static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
  217. I40E_PRIV_FLAG("vf-true-promisc-support",
  218. I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
  219. };
  220. #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
  221. /**
  222. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  223. * @pf: the PF struct
  224. **/
  225. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  226. {
  227. dev_info(&pf->pdev->dev,
  228. "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");
  229. }
  230. /**
  231. * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
  232. * @phy_types: PHY types to convert
  233. * @supported: pointer to the ethtool supported variable to fill in
  234. * @advertising: pointer to the ethtool advertising variable to fill in
  235. *
  236. **/
  237. static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
  238. u32 *advertising)
  239. {
  240. struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
  241. u64 phy_types = pf->hw.phy.phy_types;
  242. *supported = 0x0;
  243. *advertising = 0x0;
  244. if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
  245. *supported |= SUPPORTED_Autoneg |
  246. SUPPORTED_1000baseT_Full;
  247. *advertising |= ADVERTISED_Autoneg;
  248. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  249. *advertising |= ADVERTISED_1000baseT_Full;
  250. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  251. *supported |= SUPPORTED_100baseT_Full;
  252. *advertising |= ADVERTISED_100baseT_Full;
  253. }
  254. }
  255. if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
  256. phy_types & I40E_CAP_PHY_TYPE_XFI ||
  257. phy_types & I40E_CAP_PHY_TYPE_SFI ||
  258. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
  259. phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
  260. *supported |= SUPPORTED_10000baseT_Full;
  261. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
  262. phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
  263. phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
  264. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
  265. phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
  266. *supported |= SUPPORTED_Autoneg |
  267. SUPPORTED_10000baseT_Full;
  268. *advertising |= ADVERTISED_Autoneg;
  269. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  270. *advertising |= ADVERTISED_10000baseT_Full;
  271. }
  272. if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
  273. phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
  274. phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
  275. *supported |= SUPPORTED_40000baseCR4_Full;
  276. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
  277. phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
  278. *supported |= SUPPORTED_Autoneg |
  279. SUPPORTED_40000baseCR4_Full;
  280. *advertising |= ADVERTISED_Autoneg;
  281. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
  282. *advertising |= ADVERTISED_40000baseCR4_Full;
  283. }
  284. if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
  285. *supported |= SUPPORTED_Autoneg |
  286. SUPPORTED_100baseT_Full;
  287. *advertising |= ADVERTISED_Autoneg;
  288. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  289. *advertising |= ADVERTISED_100baseT_Full;
  290. }
  291. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
  292. phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
  293. phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
  294. phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
  295. *supported |= SUPPORTED_Autoneg |
  296. SUPPORTED_1000baseT_Full;
  297. *advertising |= ADVERTISED_Autoneg;
  298. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  299. *advertising |= ADVERTISED_1000baseT_Full;
  300. }
  301. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
  302. *supported |= SUPPORTED_40000baseSR4_Full;
  303. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
  304. *supported |= SUPPORTED_40000baseLR4_Full;
  305. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
  306. *supported |= SUPPORTED_40000baseKR4_Full |
  307. SUPPORTED_Autoneg;
  308. *advertising |= ADVERTISED_40000baseKR4_Full |
  309. ADVERTISED_Autoneg;
  310. }
  311. if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
  312. *supported |= SUPPORTED_20000baseKR2_Full |
  313. SUPPORTED_Autoneg;
  314. *advertising |= ADVERTISED_Autoneg;
  315. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
  316. *advertising |= ADVERTISED_20000baseKR2_Full;
  317. }
  318. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
  319. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  320. *supported |= SUPPORTED_10000baseKR_Full |
  321. SUPPORTED_Autoneg;
  322. *advertising |= ADVERTISED_Autoneg;
  323. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  324. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  325. *advertising |= ADVERTISED_10000baseKR_Full;
  326. }
  327. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
  328. *supported |= SUPPORTED_10000baseKX4_Full |
  329. SUPPORTED_Autoneg;
  330. *advertising |= ADVERTISED_Autoneg;
  331. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  332. *advertising |= ADVERTISED_10000baseKX4_Full;
  333. }
  334. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
  335. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  336. *supported |= SUPPORTED_1000baseKX_Full |
  337. SUPPORTED_Autoneg;
  338. *advertising |= ADVERTISED_Autoneg;
  339. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  340. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  341. *advertising |= ADVERTISED_1000baseKX_Full;
  342. }
  343. if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
  344. phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
  345. phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
  346. phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
  347. *supported |= SUPPORTED_Autoneg;
  348. *advertising |= ADVERTISED_Autoneg;
  349. }
  350. }
  351. /**
  352. * i40e_get_settings_link_up - Get the Link settings for when link is up
  353. * @hw: hw structure
  354. * @ecmd: ethtool command to fill in
  355. * @netdev: network interface device structure
  356. *
  357. **/
  358. static void i40e_get_settings_link_up(struct i40e_hw *hw,
  359. struct ethtool_link_ksettings *cmd,
  360. struct net_device *netdev,
  361. struct i40e_pf *pf)
  362. {
  363. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  364. u32 link_speed = hw_link_info->link_speed;
  365. u32 e_advertising = 0x0;
  366. u32 e_supported = 0x0;
  367. u32 supported, advertising;
  368. ethtool_convert_link_mode_to_legacy_u32(&supported,
  369. cmd->link_modes.supported);
  370. ethtool_convert_link_mode_to_legacy_u32(&advertising,
  371. cmd->link_modes.advertising);
  372. /* Initialize supported and advertised settings based on phy settings */
  373. switch (hw_link_info->phy_type) {
  374. case I40E_PHY_TYPE_40GBASE_CR4:
  375. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  376. supported = SUPPORTED_Autoneg |
  377. SUPPORTED_40000baseCR4_Full;
  378. advertising = ADVERTISED_Autoneg |
  379. ADVERTISED_40000baseCR4_Full;
  380. break;
  381. case I40E_PHY_TYPE_XLAUI:
  382. case I40E_PHY_TYPE_XLPPI:
  383. case I40E_PHY_TYPE_40GBASE_AOC:
  384. supported = SUPPORTED_40000baseCR4_Full;
  385. break;
  386. case I40E_PHY_TYPE_40GBASE_SR4:
  387. supported = SUPPORTED_40000baseSR4_Full;
  388. break;
  389. case I40E_PHY_TYPE_40GBASE_LR4:
  390. supported = SUPPORTED_40000baseLR4_Full;
  391. break;
  392. case I40E_PHY_TYPE_10GBASE_SR:
  393. case I40E_PHY_TYPE_10GBASE_LR:
  394. case I40E_PHY_TYPE_1000BASE_SX:
  395. case I40E_PHY_TYPE_1000BASE_LX:
  396. supported = SUPPORTED_10000baseT_Full;
  397. if (hw_link_info->module_type[2] &
  398. I40E_MODULE_TYPE_1000BASE_SX ||
  399. hw_link_info->module_type[2] &
  400. I40E_MODULE_TYPE_1000BASE_LX) {
  401. supported |= SUPPORTED_1000baseT_Full;
  402. if (hw_link_info->requested_speeds &
  403. I40E_LINK_SPEED_1GB)
  404. advertising |= ADVERTISED_1000baseT_Full;
  405. }
  406. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  407. advertising |= ADVERTISED_10000baseT_Full;
  408. break;
  409. case I40E_PHY_TYPE_10GBASE_T:
  410. case I40E_PHY_TYPE_1000BASE_T:
  411. case I40E_PHY_TYPE_100BASE_TX:
  412. supported = SUPPORTED_Autoneg |
  413. SUPPORTED_10000baseT_Full |
  414. SUPPORTED_1000baseT_Full |
  415. SUPPORTED_100baseT_Full;
  416. advertising = ADVERTISED_Autoneg;
  417. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  418. advertising |= ADVERTISED_10000baseT_Full;
  419. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  420. advertising |= ADVERTISED_1000baseT_Full;
  421. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  422. advertising |= ADVERTISED_100baseT_Full;
  423. break;
  424. case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
  425. supported = SUPPORTED_Autoneg |
  426. SUPPORTED_1000baseT_Full;
  427. advertising = ADVERTISED_Autoneg |
  428. ADVERTISED_1000baseT_Full;
  429. break;
  430. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  431. case I40E_PHY_TYPE_10GBASE_CR1:
  432. supported = SUPPORTED_Autoneg |
  433. SUPPORTED_10000baseT_Full;
  434. advertising = ADVERTISED_Autoneg |
  435. ADVERTISED_10000baseT_Full;
  436. break;
  437. case I40E_PHY_TYPE_XAUI:
  438. case I40E_PHY_TYPE_XFI:
  439. case I40E_PHY_TYPE_SFI:
  440. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  441. case I40E_PHY_TYPE_10GBASE_AOC:
  442. supported = SUPPORTED_10000baseT_Full;
  443. advertising = SUPPORTED_10000baseT_Full;
  444. break;
  445. case I40E_PHY_TYPE_SGMII:
  446. supported = SUPPORTED_Autoneg |
  447. SUPPORTED_1000baseT_Full;
  448. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  449. advertising |= ADVERTISED_1000baseT_Full;
  450. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  451. supported |= SUPPORTED_100baseT_Full;
  452. if (hw_link_info->requested_speeds &
  453. I40E_LINK_SPEED_100MB)
  454. advertising |= ADVERTISED_100baseT_Full;
  455. }
  456. break;
  457. case I40E_PHY_TYPE_40GBASE_KR4:
  458. case I40E_PHY_TYPE_20GBASE_KR2:
  459. case I40E_PHY_TYPE_10GBASE_KR:
  460. case I40E_PHY_TYPE_10GBASE_KX4:
  461. case I40E_PHY_TYPE_1000BASE_KX:
  462. supported |= SUPPORTED_40000baseKR4_Full |
  463. SUPPORTED_20000baseKR2_Full |
  464. SUPPORTED_10000baseKR_Full |
  465. SUPPORTED_10000baseKX4_Full |
  466. SUPPORTED_1000baseKX_Full |
  467. SUPPORTED_Autoneg;
  468. advertising |= ADVERTISED_40000baseKR4_Full |
  469. ADVERTISED_20000baseKR2_Full |
  470. ADVERTISED_10000baseKR_Full |
  471. ADVERTISED_10000baseKX4_Full |
  472. ADVERTISED_1000baseKX_Full |
  473. ADVERTISED_Autoneg;
  474. break;
  475. case I40E_PHY_TYPE_25GBASE_KR:
  476. case I40E_PHY_TYPE_25GBASE_CR:
  477. case I40E_PHY_TYPE_25GBASE_SR:
  478. case I40E_PHY_TYPE_25GBASE_LR:
  479. supported = SUPPORTED_Autoneg;
  480. advertising = ADVERTISED_Autoneg;
  481. /* TODO: add speeds when ethtool is ready to support*/
  482. break;
  483. default:
  484. /* if we got here and link is up something bad is afoot */
  485. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  486. hw_link_info->phy_type);
  487. }
  488. /* Now that we've worked out everything that could be supported by the
  489. * current PHY type, get what is supported by the NVM and them to
  490. * get what is truly supported
  491. */
  492. i40e_phy_type_to_ethtool(pf, &e_supported,
  493. &e_advertising);
  494. supported = supported & e_supported;
  495. advertising = advertising & e_advertising;
  496. /* Set speed and duplex */
  497. switch (link_speed) {
  498. case I40E_LINK_SPEED_40GB:
  499. cmd->base.speed = SPEED_40000;
  500. break;
  501. case I40E_LINK_SPEED_25GB:
  502. #ifdef SPEED_25000
  503. cmd->base.speed = SPEED_25000;
  504. #else
  505. netdev_info(netdev,
  506. "Speed is 25G, display not supported by this version of ethtool.\n");
  507. #endif
  508. break;
  509. case I40E_LINK_SPEED_20GB:
  510. cmd->base.speed = SPEED_20000;
  511. break;
  512. case I40E_LINK_SPEED_10GB:
  513. cmd->base.speed = SPEED_10000;
  514. break;
  515. case I40E_LINK_SPEED_1GB:
  516. cmd->base.speed = SPEED_1000;
  517. break;
  518. case I40E_LINK_SPEED_100MB:
  519. cmd->base.speed = SPEED_100;
  520. break;
  521. default:
  522. break;
  523. }
  524. cmd->base.duplex = DUPLEX_FULL;
  525. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  526. supported);
  527. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  528. advertising);
  529. }
  530. /**
  531. * i40e_get_settings_link_down - Get the Link settings for when link is down
  532. * @hw: hw structure
  533. * @ecmd: ethtool command to fill in
  534. *
  535. * Reports link settings that can be determined when link is down
  536. **/
  537. static void i40e_get_settings_link_down(struct i40e_hw *hw,
  538. struct ethtool_link_ksettings *cmd,
  539. struct i40e_pf *pf)
  540. {
  541. u32 supported, advertising;
  542. /* link is down and the driver needs to fall back on
  543. * supported phy types to figure out what info to display
  544. */
  545. i40e_phy_type_to_ethtool(pf, &supported, &advertising);
  546. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  547. supported);
  548. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  549. advertising);
  550. /* With no link speed and duplex are unknown */
  551. cmd->base.speed = SPEED_UNKNOWN;
  552. cmd->base.duplex = DUPLEX_UNKNOWN;
  553. }
  554. /**
  555. * i40e_get_settings - Get Link Speed and Duplex settings
  556. * @netdev: network interface device structure
  557. * @ecmd: ethtool command
  558. *
  559. * Reports speed/duplex settings based on media_type
  560. **/
  561. static int i40e_get_link_ksettings(struct net_device *netdev,
  562. struct ethtool_link_ksettings *cmd)
  563. {
  564. struct i40e_netdev_priv *np = netdev_priv(netdev);
  565. struct i40e_pf *pf = np->vsi->back;
  566. struct i40e_hw *hw = &pf->hw;
  567. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  568. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  569. u32 advertising;
  570. if (link_up)
  571. i40e_get_settings_link_up(hw, cmd, netdev, pf);
  572. else
  573. i40e_get_settings_link_down(hw, cmd, pf);
  574. /* Now set the settings that don't rely on link being up/down */
  575. /* Set autoneg settings */
  576. cmd->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  577. AUTONEG_ENABLE : AUTONEG_DISABLE);
  578. switch (hw->phy.media_type) {
  579. case I40E_MEDIA_TYPE_BACKPLANE:
  580. ethtool_link_ksettings_add_link_mode(cmd, supported,
  581. Autoneg);
  582. ethtool_link_ksettings_add_link_mode(cmd, supported,
  583. Backplane);
  584. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  585. Autoneg);
  586. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  587. Backplane);
  588. cmd->base.port = PORT_NONE;
  589. break;
  590. case I40E_MEDIA_TYPE_BASET:
  591. ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
  592. ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
  593. cmd->base.port = PORT_TP;
  594. break;
  595. case I40E_MEDIA_TYPE_DA:
  596. case I40E_MEDIA_TYPE_CX4:
  597. ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
  598. ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
  599. cmd->base.port = PORT_DA;
  600. break;
  601. case I40E_MEDIA_TYPE_FIBER:
  602. ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
  603. cmd->base.port = PORT_FIBRE;
  604. break;
  605. case I40E_MEDIA_TYPE_UNKNOWN:
  606. default:
  607. cmd->base.port = PORT_OTHER;
  608. break;
  609. }
  610. /* Set flow control settings */
  611. ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
  612. switch (hw->fc.requested_mode) {
  613. case I40E_FC_FULL:
  614. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  615. Pause);
  616. break;
  617. case I40E_FC_TX_PAUSE:
  618. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  619. Asym_Pause);
  620. break;
  621. case I40E_FC_RX_PAUSE:
  622. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  623. Pause);
  624. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  625. Asym_Pause);
  626. break;
  627. default:
  628. ethtool_convert_link_mode_to_legacy_u32(
  629. &advertising, cmd->link_modes.advertising);
  630. advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
  631. ethtool_convert_legacy_u32_to_link_mode(
  632. cmd->link_modes.advertising, advertising);
  633. break;
  634. }
  635. return 0;
  636. }
  637. /**
  638. * i40e_set_settings - Set Speed and Duplex
  639. * @netdev: network interface device structure
  640. * @ecmd: ethtool command
  641. *
  642. * Set speed/duplex per media_types advertised/forced
  643. **/
  644. static int i40e_set_link_ksettings(struct net_device *netdev,
  645. const struct ethtool_link_ksettings *cmd)
  646. {
  647. struct i40e_netdev_priv *np = netdev_priv(netdev);
  648. struct i40e_aq_get_phy_abilities_resp abilities;
  649. struct i40e_aq_set_phy_config config;
  650. struct i40e_pf *pf = np->vsi->back;
  651. struct i40e_vsi *vsi = np->vsi;
  652. struct i40e_hw *hw = &pf->hw;
  653. struct ethtool_link_ksettings safe_cmd;
  654. struct ethtool_link_ksettings copy_cmd;
  655. i40e_status status = 0;
  656. bool change = false;
  657. int err = 0;
  658. u32 autoneg;
  659. u32 advertise;
  660. u32 tmp;
  661. /* Changing port settings is not supported if this isn't the
  662. * port's controlling PF
  663. */
  664. if (hw->partition_id != 1) {
  665. i40e_partition_setting_complaint(pf);
  666. return -EOPNOTSUPP;
  667. }
  668. if (vsi != pf->vsi[pf->lan_vsi])
  669. return -EOPNOTSUPP;
  670. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  671. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  672. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  673. hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
  674. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  675. return -EOPNOTSUPP;
  676. if (hw->device_id == I40E_DEV_ID_KX_B ||
  677. hw->device_id == I40E_DEV_ID_KX_C ||
  678. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  679. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  680. netdev_info(netdev, "Changing settings is not supported on backplane.\n");
  681. return -EOPNOTSUPP;
  682. }
  683. /* copy the cmd to copy_cmd to avoid modifying the origin */
  684. memcpy(&copy_cmd, cmd, sizeof(struct ethtool_link_ksettings));
  685. /* get our own copy of the bits to check against */
  686. memset(&safe_cmd, 0, sizeof(struct ethtool_link_ksettings));
  687. i40e_get_link_ksettings(netdev, &safe_cmd);
  688. /* save autoneg and speed out of cmd */
  689. autoneg = cmd->base.autoneg;
  690. ethtool_convert_link_mode_to_legacy_u32(&advertise,
  691. cmd->link_modes.advertising);
  692. /* set autoneg and speed back to what they currently are */
  693. copy_cmd.base.autoneg = safe_cmd.base.autoneg;
  694. ethtool_convert_link_mode_to_legacy_u32(
  695. &tmp, safe_cmd.link_modes.advertising);
  696. ethtool_convert_legacy_u32_to_link_mode(
  697. copy_cmd.link_modes.advertising, tmp);
  698. copy_cmd.base.cmd = safe_cmd.base.cmd;
  699. /* If copy_cmd and safe_cmd are not the same now, then they are
  700. * trying to set something that we do not support
  701. */
  702. if (memcmp(&copy_cmd, &safe_cmd, sizeof(struct ethtool_link_ksettings)))
  703. return -EOPNOTSUPP;
  704. while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
  705. usleep_range(1000, 2000);
  706. /* Get the current phy config */
  707. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  708. NULL);
  709. if (status)
  710. return -EAGAIN;
  711. /* Copy abilities to config in case autoneg is not
  712. * set below
  713. */
  714. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  715. config.abilities = abilities.abilities;
  716. /* Check autoneg */
  717. if (autoneg == AUTONEG_ENABLE) {
  718. /* If autoneg was not already enabled */
  719. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  720. /* If autoneg is not supported, return error */
  721. if (!ethtool_link_ksettings_test_link_mode(
  722. &safe_cmd, supported, Autoneg)) {
  723. netdev_info(netdev, "Autoneg not supported on this phy\n");
  724. return -EINVAL;
  725. }
  726. /* Autoneg is allowed to change */
  727. config.abilities = abilities.abilities |
  728. I40E_AQ_PHY_ENABLE_AN;
  729. change = true;
  730. }
  731. } else {
  732. /* If autoneg is currently enabled */
  733. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  734. /* If autoneg is supported 10GBASE_T is the only PHY
  735. * that can disable it, so otherwise return error
  736. */
  737. if (ethtool_link_ksettings_test_link_mode(
  738. &safe_cmd, supported, Autoneg) &&
  739. hw->phy.link_info.phy_type !=
  740. I40E_PHY_TYPE_10GBASE_T) {
  741. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  742. return -EINVAL;
  743. }
  744. /* Autoneg is allowed to change */
  745. config.abilities = abilities.abilities &
  746. ~I40E_AQ_PHY_ENABLE_AN;
  747. change = true;
  748. }
  749. }
  750. ethtool_convert_link_mode_to_legacy_u32(&tmp,
  751. safe_cmd.link_modes.supported);
  752. if (advertise & ~tmp)
  753. return -EINVAL;
  754. if (advertise & ADVERTISED_100baseT_Full)
  755. config.link_speed |= I40E_LINK_SPEED_100MB;
  756. if (advertise & ADVERTISED_1000baseT_Full ||
  757. advertise & ADVERTISED_1000baseKX_Full)
  758. config.link_speed |= I40E_LINK_SPEED_1GB;
  759. if (advertise & ADVERTISED_10000baseT_Full ||
  760. advertise & ADVERTISED_10000baseKX4_Full ||
  761. advertise & ADVERTISED_10000baseKR_Full)
  762. config.link_speed |= I40E_LINK_SPEED_10GB;
  763. if (advertise & ADVERTISED_20000baseKR2_Full)
  764. config.link_speed |= I40E_LINK_SPEED_20GB;
  765. if (advertise & ADVERTISED_40000baseKR4_Full ||
  766. advertise & ADVERTISED_40000baseCR4_Full ||
  767. advertise & ADVERTISED_40000baseSR4_Full ||
  768. advertise & ADVERTISED_40000baseLR4_Full)
  769. config.link_speed |= I40E_LINK_SPEED_40GB;
  770. /* If speed didn't get set, set it to what it currently is.
  771. * This is needed because if advertise is 0 (as it is when autoneg
  772. * is disabled) then speed won't get set.
  773. */
  774. if (!config.link_speed)
  775. config.link_speed = abilities.link_speed;
  776. if (change || (abilities.link_speed != config.link_speed)) {
  777. /* copy over the rest of the abilities */
  778. config.phy_type = abilities.phy_type;
  779. config.phy_type_ext = abilities.phy_type_ext;
  780. config.eee_capability = abilities.eee_capability;
  781. config.eeer = abilities.eeer_val;
  782. config.low_power_ctrl = abilities.d3_lpan;
  783. config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
  784. I40E_AQ_PHY_FEC_CONFIG_MASK;
  785. /* save the requested speeds */
  786. hw->phy.link_info.requested_speeds = config.link_speed;
  787. /* set link and auto negotiation so changes take effect */
  788. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  789. /* If link is up put link down */
  790. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  791. /* Tell the OS link is going down, the link will go
  792. * back up when fw says it is ready asynchronously
  793. */
  794. i40e_print_link_message(vsi, false);
  795. netif_carrier_off(netdev);
  796. netif_tx_stop_all_queues(netdev);
  797. }
  798. /* make the aq call */
  799. status = i40e_aq_set_phy_config(hw, &config, NULL);
  800. if (status) {
  801. netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
  802. i40e_stat_str(hw, status),
  803. i40e_aq_str(hw, hw->aq.asq_last_status));
  804. return -EAGAIN;
  805. }
  806. status = i40e_update_link_info(hw);
  807. if (status)
  808. netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
  809. i40e_stat_str(hw, status),
  810. i40e_aq_str(hw, hw->aq.asq_last_status));
  811. } else {
  812. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  813. }
  814. return err;
  815. }
  816. static int i40e_nway_reset(struct net_device *netdev)
  817. {
  818. /* restart autonegotiation */
  819. struct i40e_netdev_priv *np = netdev_priv(netdev);
  820. struct i40e_pf *pf = np->vsi->back;
  821. struct i40e_hw *hw = &pf->hw;
  822. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  823. i40e_status ret = 0;
  824. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  825. if (ret) {
  826. netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
  827. i40e_stat_str(hw, ret),
  828. i40e_aq_str(hw, hw->aq.asq_last_status));
  829. return -EIO;
  830. }
  831. return 0;
  832. }
  833. /**
  834. * i40e_get_pauseparam - Get Flow Control status
  835. * Return tx/rx-pause status
  836. **/
  837. static void i40e_get_pauseparam(struct net_device *netdev,
  838. struct ethtool_pauseparam *pause)
  839. {
  840. struct i40e_netdev_priv *np = netdev_priv(netdev);
  841. struct i40e_pf *pf = np->vsi->back;
  842. struct i40e_hw *hw = &pf->hw;
  843. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  844. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  845. pause->autoneg =
  846. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  847. AUTONEG_ENABLE : AUTONEG_DISABLE);
  848. /* PFC enabled so report LFC as off */
  849. if (dcbx_cfg->pfc.pfcenable) {
  850. pause->rx_pause = 0;
  851. pause->tx_pause = 0;
  852. return;
  853. }
  854. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  855. pause->rx_pause = 1;
  856. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  857. pause->tx_pause = 1;
  858. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  859. pause->rx_pause = 1;
  860. pause->tx_pause = 1;
  861. }
  862. }
  863. /**
  864. * i40e_set_pauseparam - Set Flow Control parameter
  865. * @netdev: network interface device structure
  866. * @pause: return tx/rx flow control status
  867. **/
  868. static int i40e_set_pauseparam(struct net_device *netdev,
  869. struct ethtool_pauseparam *pause)
  870. {
  871. struct i40e_netdev_priv *np = netdev_priv(netdev);
  872. struct i40e_pf *pf = np->vsi->back;
  873. struct i40e_vsi *vsi = np->vsi;
  874. struct i40e_hw *hw = &pf->hw;
  875. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  876. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  877. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  878. i40e_status status;
  879. u8 aq_failures;
  880. int err = 0;
  881. /* Changing the port's flow control is not supported if this isn't the
  882. * port's controlling PF
  883. */
  884. if (hw->partition_id != 1) {
  885. i40e_partition_setting_complaint(pf);
  886. return -EOPNOTSUPP;
  887. }
  888. if (vsi != pf->vsi[pf->lan_vsi])
  889. return -EOPNOTSUPP;
  890. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  891. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  892. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  893. return -EOPNOTSUPP;
  894. }
  895. /* If we have link and don't have autoneg */
  896. if (!test_bit(__I40E_DOWN, &pf->state) &&
  897. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  898. /* Send message that it might not necessarily work*/
  899. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  900. }
  901. if (dcbx_cfg->pfc.pfcenable) {
  902. netdev_info(netdev,
  903. "Priority flow control enabled. Cannot set link flow control.\n");
  904. return -EOPNOTSUPP;
  905. }
  906. if (pause->rx_pause && pause->tx_pause)
  907. hw->fc.requested_mode = I40E_FC_FULL;
  908. else if (pause->rx_pause && !pause->tx_pause)
  909. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  910. else if (!pause->rx_pause && pause->tx_pause)
  911. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  912. else if (!pause->rx_pause && !pause->tx_pause)
  913. hw->fc.requested_mode = I40E_FC_NONE;
  914. else
  915. return -EINVAL;
  916. /* Tell the OS link is going down, the link will go back up when fw
  917. * says it is ready asynchronously
  918. */
  919. i40e_print_link_message(vsi, false);
  920. netif_carrier_off(netdev);
  921. netif_tx_stop_all_queues(netdev);
  922. /* Set the fc mode and only restart an if link is up*/
  923. status = i40e_set_fc(hw, &aq_failures, link_up);
  924. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  925. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
  926. i40e_stat_str(hw, status),
  927. i40e_aq_str(hw, hw->aq.asq_last_status));
  928. err = -EAGAIN;
  929. }
  930. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  931. netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
  932. i40e_stat_str(hw, status),
  933. i40e_aq_str(hw, hw->aq.asq_last_status));
  934. err = -EAGAIN;
  935. }
  936. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  937. netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
  938. i40e_stat_str(hw, status),
  939. i40e_aq_str(hw, hw->aq.asq_last_status));
  940. err = -EAGAIN;
  941. }
  942. if (!test_bit(__I40E_DOWN, &pf->state)) {
  943. /* Give it a little more time to try to come back */
  944. msleep(75);
  945. if (!test_bit(__I40E_DOWN, &pf->state))
  946. return i40e_nway_reset(netdev);
  947. }
  948. return err;
  949. }
  950. static u32 i40e_get_msglevel(struct net_device *netdev)
  951. {
  952. struct i40e_netdev_priv *np = netdev_priv(netdev);
  953. struct i40e_pf *pf = np->vsi->back;
  954. u32 debug_mask = pf->hw.debug_mask;
  955. if (debug_mask)
  956. netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
  957. return pf->msg_enable;
  958. }
  959. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  960. {
  961. struct i40e_netdev_priv *np = netdev_priv(netdev);
  962. struct i40e_pf *pf = np->vsi->back;
  963. if (I40E_DEBUG_USER & data)
  964. pf->hw.debug_mask = data;
  965. else
  966. pf->msg_enable = data;
  967. }
  968. static int i40e_get_regs_len(struct net_device *netdev)
  969. {
  970. int reg_count = 0;
  971. int i;
  972. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  973. reg_count += i40e_reg_list[i].elements;
  974. return reg_count * sizeof(u32);
  975. }
  976. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  977. void *p)
  978. {
  979. struct i40e_netdev_priv *np = netdev_priv(netdev);
  980. struct i40e_pf *pf = np->vsi->back;
  981. struct i40e_hw *hw = &pf->hw;
  982. u32 *reg_buf = p;
  983. int i, j, ri;
  984. u32 reg;
  985. /* Tell ethtool which driver-version-specific regs output we have.
  986. *
  987. * At some point, if we have ethtool doing special formatting of
  988. * this data, it will rely on this version number to know how to
  989. * interpret things. Hence, this needs to be updated if/when the
  990. * diags register table is changed.
  991. */
  992. regs->version = 1;
  993. /* loop through the diags reg table for what to print */
  994. ri = 0;
  995. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  996. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  997. reg = i40e_reg_list[i].offset
  998. + (j * i40e_reg_list[i].stride);
  999. reg_buf[ri++] = rd32(hw, reg);
  1000. }
  1001. }
  1002. }
  1003. static int i40e_get_eeprom(struct net_device *netdev,
  1004. struct ethtool_eeprom *eeprom, u8 *bytes)
  1005. {
  1006. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1007. struct i40e_hw *hw = &np->vsi->back->hw;
  1008. struct i40e_pf *pf = np->vsi->back;
  1009. int ret_val = 0, len, offset;
  1010. u8 *eeprom_buff;
  1011. u16 i, sectors;
  1012. bool last;
  1013. u32 magic;
  1014. #define I40E_NVM_SECTOR_SIZE 4096
  1015. if (eeprom->len == 0)
  1016. return -EINVAL;
  1017. /* check for NVMUpdate access method */
  1018. magic = hw->vendor_id | (hw->device_id << 16);
  1019. if (eeprom->magic && eeprom->magic != magic) {
  1020. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1021. int errno = 0;
  1022. /* make sure it is the right magic for NVMUpdate */
  1023. if ((eeprom->magic >> 16) != hw->device_id)
  1024. errno = -EINVAL;
  1025. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1026. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1027. errno = -EBUSY;
  1028. else
  1029. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1030. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1031. dev_info(&pf->pdev->dev,
  1032. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1033. ret_val, hw->aq.asq_last_status, errno,
  1034. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1035. cmd->offset, cmd->data_size);
  1036. return errno;
  1037. }
  1038. /* normal ethtool get_eeprom support */
  1039. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  1040. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  1041. if (!eeprom_buff)
  1042. return -ENOMEM;
  1043. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  1044. if (ret_val) {
  1045. dev_info(&pf->pdev->dev,
  1046. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  1047. ret_val, hw->aq.asq_last_status);
  1048. goto free_buff;
  1049. }
  1050. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  1051. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  1052. len = I40E_NVM_SECTOR_SIZE;
  1053. last = false;
  1054. for (i = 0; i < sectors; i++) {
  1055. if (i == (sectors - 1)) {
  1056. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  1057. last = true;
  1058. }
  1059. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  1060. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  1061. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  1062. last, NULL);
  1063. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  1064. dev_info(&pf->pdev->dev,
  1065. "read NVM failed, invalid offset 0x%x\n",
  1066. offset);
  1067. break;
  1068. } else if (ret_val &&
  1069. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  1070. dev_info(&pf->pdev->dev,
  1071. "read NVM failed, access, offset 0x%x\n",
  1072. offset);
  1073. break;
  1074. } else if (ret_val) {
  1075. dev_info(&pf->pdev->dev,
  1076. "read NVM failed offset %d err=%d status=0x%x\n",
  1077. offset, ret_val, hw->aq.asq_last_status);
  1078. break;
  1079. }
  1080. }
  1081. i40e_release_nvm(hw);
  1082. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  1083. free_buff:
  1084. kfree(eeprom_buff);
  1085. return ret_val;
  1086. }
  1087. static int i40e_get_eeprom_len(struct net_device *netdev)
  1088. {
  1089. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1090. struct i40e_hw *hw = &np->vsi->back->hw;
  1091. u32 val;
  1092. #define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
  1093. if (hw->mac.type == I40E_MAC_X722) {
  1094. val = X722_EEPROM_SCOPE_LIMIT + 1;
  1095. return val;
  1096. }
  1097. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  1098. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  1099. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  1100. /* register returns value in power of 2, 64Kbyte chunks. */
  1101. val = (64 * 1024) * BIT(val);
  1102. return val;
  1103. }
  1104. static int i40e_set_eeprom(struct net_device *netdev,
  1105. struct ethtool_eeprom *eeprom, u8 *bytes)
  1106. {
  1107. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1108. struct i40e_hw *hw = &np->vsi->back->hw;
  1109. struct i40e_pf *pf = np->vsi->back;
  1110. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1111. int ret_val = 0;
  1112. int errno = 0;
  1113. u32 magic;
  1114. /* normal ethtool set_eeprom is not supported */
  1115. magic = hw->vendor_id | (hw->device_id << 16);
  1116. if (eeprom->magic == magic)
  1117. errno = -EOPNOTSUPP;
  1118. /* check for NVMUpdate access method */
  1119. else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  1120. errno = -EINVAL;
  1121. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1122. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1123. errno = -EBUSY;
  1124. else
  1125. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1126. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1127. dev_info(&pf->pdev->dev,
  1128. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1129. ret_val, hw->aq.asq_last_status, errno,
  1130. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1131. cmd->offset, cmd->data_size);
  1132. return errno;
  1133. }
  1134. static void i40e_get_drvinfo(struct net_device *netdev,
  1135. struct ethtool_drvinfo *drvinfo)
  1136. {
  1137. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1138. struct i40e_vsi *vsi = np->vsi;
  1139. struct i40e_pf *pf = vsi->back;
  1140. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  1141. strlcpy(drvinfo->version, i40e_driver_version_str,
  1142. sizeof(drvinfo->version));
  1143. strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
  1144. sizeof(drvinfo->fw_version));
  1145. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  1146. sizeof(drvinfo->bus_info));
  1147. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
  1148. if (pf->hw.pf_id == 0)
  1149. drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
  1150. }
  1151. static void i40e_get_ringparam(struct net_device *netdev,
  1152. struct ethtool_ringparam *ring)
  1153. {
  1154. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1155. struct i40e_pf *pf = np->vsi->back;
  1156. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1157. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1158. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1159. ring->rx_mini_max_pending = 0;
  1160. ring->rx_jumbo_max_pending = 0;
  1161. ring->rx_pending = vsi->rx_rings[0]->count;
  1162. ring->tx_pending = vsi->tx_rings[0]->count;
  1163. ring->rx_mini_pending = 0;
  1164. ring->rx_jumbo_pending = 0;
  1165. }
  1166. static int i40e_set_ringparam(struct net_device *netdev,
  1167. struct ethtool_ringparam *ring)
  1168. {
  1169. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  1170. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1171. struct i40e_hw *hw = &np->vsi->back->hw;
  1172. struct i40e_vsi *vsi = np->vsi;
  1173. struct i40e_pf *pf = vsi->back;
  1174. u32 new_rx_count, new_tx_count;
  1175. int i, err = 0;
  1176. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1177. return -EINVAL;
  1178. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1179. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  1180. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1181. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  1182. netdev_info(netdev,
  1183. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  1184. ring->tx_pending, ring->rx_pending,
  1185. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  1186. return -EINVAL;
  1187. }
  1188. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1189. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1190. /* if nothing to do return success */
  1191. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1192. (new_rx_count == vsi->rx_rings[0]->count))
  1193. return 0;
  1194. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  1195. usleep_range(1000, 2000);
  1196. if (!netif_running(vsi->netdev)) {
  1197. /* simple case - set for the next time the netdev is started */
  1198. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1199. vsi->tx_rings[i]->count = new_tx_count;
  1200. vsi->rx_rings[i]->count = new_rx_count;
  1201. }
  1202. goto done;
  1203. }
  1204. /* We can't just free everything and then setup again,
  1205. * because the ISRs in MSI-X mode get passed pointers
  1206. * to the Tx and Rx ring structs.
  1207. */
  1208. /* alloc updated Tx resources */
  1209. if (new_tx_count != vsi->tx_rings[0]->count) {
  1210. netdev_info(netdev,
  1211. "Changing Tx descriptor count from %d to %d.\n",
  1212. vsi->tx_rings[0]->count, new_tx_count);
  1213. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  1214. sizeof(struct i40e_ring), GFP_KERNEL);
  1215. if (!tx_rings) {
  1216. err = -ENOMEM;
  1217. goto done;
  1218. }
  1219. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1220. /* clone ring and setup updated count */
  1221. tx_rings[i] = *vsi->tx_rings[i];
  1222. tx_rings[i].count = new_tx_count;
  1223. /* the desc and bi pointers will be reallocated in the
  1224. * setup call
  1225. */
  1226. tx_rings[i].desc = NULL;
  1227. tx_rings[i].rx_bi = NULL;
  1228. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1229. if (err) {
  1230. while (i) {
  1231. i--;
  1232. i40e_free_tx_resources(&tx_rings[i]);
  1233. }
  1234. kfree(tx_rings);
  1235. tx_rings = NULL;
  1236. goto done;
  1237. }
  1238. }
  1239. }
  1240. /* alloc updated Rx resources */
  1241. if (new_rx_count != vsi->rx_rings[0]->count) {
  1242. netdev_info(netdev,
  1243. "Changing Rx descriptor count from %d to %d\n",
  1244. vsi->rx_rings[0]->count, new_rx_count);
  1245. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1246. sizeof(struct i40e_ring), GFP_KERNEL);
  1247. if (!rx_rings) {
  1248. err = -ENOMEM;
  1249. goto free_tx;
  1250. }
  1251. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1252. struct i40e_ring *ring;
  1253. u16 unused;
  1254. /* clone ring and setup updated count */
  1255. rx_rings[i] = *vsi->rx_rings[i];
  1256. rx_rings[i].count = new_rx_count;
  1257. /* the desc and bi pointers will be reallocated in the
  1258. * setup call
  1259. */
  1260. rx_rings[i].desc = NULL;
  1261. rx_rings[i].rx_bi = NULL;
  1262. /* this is to allow wr32 to have something to write to
  1263. * during early allocation of Rx buffers
  1264. */
  1265. rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
  1266. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1267. if (err)
  1268. goto rx_unwind;
  1269. /* now allocate the Rx buffers to make sure the OS
  1270. * has enough memory, any failure here means abort
  1271. */
  1272. ring = &rx_rings[i];
  1273. unused = I40E_DESC_UNUSED(ring);
  1274. err = i40e_alloc_rx_buffers(ring, unused);
  1275. rx_unwind:
  1276. if (err) {
  1277. do {
  1278. i40e_free_rx_resources(&rx_rings[i]);
  1279. } while (i--);
  1280. kfree(rx_rings);
  1281. rx_rings = NULL;
  1282. goto free_tx;
  1283. }
  1284. }
  1285. }
  1286. /* Bring interface down, copy in the new ring info,
  1287. * then restore the interface
  1288. */
  1289. i40e_down(vsi);
  1290. if (tx_rings) {
  1291. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1292. i40e_free_tx_resources(vsi->tx_rings[i]);
  1293. *vsi->tx_rings[i] = tx_rings[i];
  1294. }
  1295. kfree(tx_rings);
  1296. tx_rings = NULL;
  1297. }
  1298. if (rx_rings) {
  1299. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1300. i40e_free_rx_resources(vsi->rx_rings[i]);
  1301. /* get the real tail offset */
  1302. rx_rings[i].tail = vsi->rx_rings[i]->tail;
  1303. /* this is to fake out the allocation routine
  1304. * into thinking it has to realloc everything
  1305. * but the recycling logic will let us re-use
  1306. * the buffers allocated above
  1307. */
  1308. rx_rings[i].next_to_use = 0;
  1309. rx_rings[i].next_to_clean = 0;
  1310. rx_rings[i].next_to_alloc = 0;
  1311. /* do a struct copy */
  1312. *vsi->rx_rings[i] = rx_rings[i];
  1313. }
  1314. kfree(rx_rings);
  1315. rx_rings = NULL;
  1316. }
  1317. i40e_up(vsi);
  1318. free_tx:
  1319. /* error cleanup if the Rx allocations failed after getting Tx */
  1320. if (tx_rings) {
  1321. for (i = 0; i < vsi->num_queue_pairs; i++)
  1322. i40e_free_tx_resources(&tx_rings[i]);
  1323. kfree(tx_rings);
  1324. tx_rings = NULL;
  1325. }
  1326. done:
  1327. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1328. return err;
  1329. }
  1330. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1331. {
  1332. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1333. struct i40e_vsi *vsi = np->vsi;
  1334. struct i40e_pf *pf = vsi->back;
  1335. switch (sset) {
  1336. case ETH_SS_TEST:
  1337. return I40E_TEST_LEN;
  1338. case ETH_SS_STATS:
  1339. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1340. int len = I40E_PF_STATS_LEN(netdev);
  1341. if ((pf->lan_veb != I40E_NO_VEB) &&
  1342. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
  1343. len += I40E_VEB_STATS_TOTAL;
  1344. return len;
  1345. } else {
  1346. return I40E_VSI_STATS_LEN(netdev);
  1347. }
  1348. case ETH_SS_PRIV_FLAGS:
  1349. return I40E_PRIV_FLAGS_STR_LEN +
  1350. (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
  1351. default:
  1352. return -EOPNOTSUPP;
  1353. }
  1354. }
  1355. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1356. struct ethtool_stats *stats, u64 *data)
  1357. {
  1358. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1359. struct i40e_ring *tx_ring, *rx_ring;
  1360. struct i40e_vsi *vsi = np->vsi;
  1361. struct i40e_pf *pf = vsi->back;
  1362. int i = 0;
  1363. char *p;
  1364. int j;
  1365. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1366. unsigned int start;
  1367. i40e_update_stats(vsi);
  1368. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1369. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1370. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1371. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1372. }
  1373. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1374. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1375. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1376. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1377. }
  1378. rcu_read_lock();
  1379. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1380. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1381. if (!tx_ring)
  1382. continue;
  1383. /* process Tx ring statistics */
  1384. do {
  1385. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1386. data[i] = tx_ring->stats.packets;
  1387. data[i + 1] = tx_ring->stats.bytes;
  1388. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1389. i += 2;
  1390. /* Rx ring is the 2nd half of the queue pair */
  1391. rx_ring = &tx_ring[1];
  1392. do {
  1393. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1394. data[i] = rx_ring->stats.packets;
  1395. data[i + 1] = rx_ring->stats.bytes;
  1396. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1397. i += 2;
  1398. }
  1399. rcu_read_unlock();
  1400. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1401. return;
  1402. if ((pf->lan_veb != I40E_NO_VEB) &&
  1403. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1404. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1405. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1406. p = (char *)veb;
  1407. p += i40e_gstrings_veb_stats[j].stat_offset;
  1408. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1409. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1410. }
  1411. for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
  1412. data[i++] = veb->tc_stats.tc_tx_packets[j];
  1413. data[i++] = veb->tc_stats.tc_tx_bytes[j];
  1414. data[i++] = veb->tc_stats.tc_rx_packets[j];
  1415. data[i++] = veb->tc_stats.tc_rx_bytes[j];
  1416. }
  1417. }
  1418. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1419. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1420. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1421. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1422. }
  1423. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1424. data[i++] = pf->stats.priority_xon_tx[j];
  1425. data[i++] = pf->stats.priority_xoff_tx[j];
  1426. }
  1427. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1428. data[i++] = pf->stats.priority_xon_rx[j];
  1429. data[i++] = pf->stats.priority_xoff_rx[j];
  1430. }
  1431. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1432. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1433. }
  1434. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1435. u8 *data)
  1436. {
  1437. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1438. struct i40e_vsi *vsi = np->vsi;
  1439. struct i40e_pf *pf = vsi->back;
  1440. char *p = (char *)data;
  1441. int i;
  1442. switch (stringset) {
  1443. case ETH_SS_TEST:
  1444. memcpy(data, i40e_gstrings_test,
  1445. I40E_TEST_LEN * ETH_GSTRING_LEN);
  1446. break;
  1447. case ETH_SS_STATS:
  1448. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1449. snprintf(p, ETH_GSTRING_LEN, "%s",
  1450. i40e_gstrings_net_stats[i].stat_string);
  1451. p += ETH_GSTRING_LEN;
  1452. }
  1453. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1454. snprintf(p, ETH_GSTRING_LEN, "%s",
  1455. i40e_gstrings_misc_stats[i].stat_string);
  1456. p += ETH_GSTRING_LEN;
  1457. }
  1458. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1459. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
  1460. p += ETH_GSTRING_LEN;
  1461. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
  1462. p += ETH_GSTRING_LEN;
  1463. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
  1464. p += ETH_GSTRING_LEN;
  1465. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
  1466. p += ETH_GSTRING_LEN;
  1467. }
  1468. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1469. return;
  1470. if ((pf->lan_veb != I40E_NO_VEB) &&
  1471. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1472. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1473. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1474. i40e_gstrings_veb_stats[i].stat_string);
  1475. p += ETH_GSTRING_LEN;
  1476. }
  1477. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1478. snprintf(p, ETH_GSTRING_LEN,
  1479. "veb.tc_%d_tx_packets", i);
  1480. p += ETH_GSTRING_LEN;
  1481. snprintf(p, ETH_GSTRING_LEN,
  1482. "veb.tc_%d_tx_bytes", i);
  1483. p += ETH_GSTRING_LEN;
  1484. snprintf(p, ETH_GSTRING_LEN,
  1485. "veb.tc_%d_rx_packets", i);
  1486. p += ETH_GSTRING_LEN;
  1487. snprintf(p, ETH_GSTRING_LEN,
  1488. "veb.tc_%d_rx_bytes", i);
  1489. p += ETH_GSTRING_LEN;
  1490. }
  1491. }
  1492. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1493. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1494. i40e_gstrings_stats[i].stat_string);
  1495. p += ETH_GSTRING_LEN;
  1496. }
  1497. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1498. snprintf(p, ETH_GSTRING_LEN,
  1499. "port.tx_priority_%d_xon", i);
  1500. p += ETH_GSTRING_LEN;
  1501. snprintf(p, ETH_GSTRING_LEN,
  1502. "port.tx_priority_%d_xoff", i);
  1503. p += ETH_GSTRING_LEN;
  1504. }
  1505. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1506. snprintf(p, ETH_GSTRING_LEN,
  1507. "port.rx_priority_%d_xon", i);
  1508. p += ETH_GSTRING_LEN;
  1509. snprintf(p, ETH_GSTRING_LEN,
  1510. "port.rx_priority_%d_xoff", i);
  1511. p += ETH_GSTRING_LEN;
  1512. }
  1513. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1514. snprintf(p, ETH_GSTRING_LEN,
  1515. "port.rx_priority_%d_xon_2_xoff", i);
  1516. p += ETH_GSTRING_LEN;
  1517. }
  1518. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1519. break;
  1520. case ETH_SS_PRIV_FLAGS:
  1521. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  1522. snprintf(p, ETH_GSTRING_LEN, "%s",
  1523. i40e_gstrings_priv_flags[i].flag_string);
  1524. p += ETH_GSTRING_LEN;
  1525. }
  1526. if (pf->hw.pf_id != 0)
  1527. break;
  1528. for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
  1529. snprintf(p, ETH_GSTRING_LEN, "%s",
  1530. i40e_gl_gstrings_priv_flags[i].flag_string);
  1531. p += ETH_GSTRING_LEN;
  1532. }
  1533. break;
  1534. default:
  1535. break;
  1536. }
  1537. }
  1538. static int i40e_get_ts_info(struct net_device *dev,
  1539. struct ethtool_ts_info *info)
  1540. {
  1541. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1542. /* only report HW timestamping if PTP is enabled */
  1543. if (!(pf->flags & I40E_FLAG_PTP))
  1544. return ethtool_op_get_ts_info(dev, info);
  1545. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1546. SOF_TIMESTAMPING_RX_SOFTWARE |
  1547. SOF_TIMESTAMPING_SOFTWARE |
  1548. SOF_TIMESTAMPING_TX_HARDWARE |
  1549. SOF_TIMESTAMPING_RX_HARDWARE |
  1550. SOF_TIMESTAMPING_RAW_HARDWARE;
  1551. if (pf->ptp_clock)
  1552. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1553. else
  1554. info->phc_index = -1;
  1555. info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
  1556. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  1557. BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  1558. BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  1559. BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
  1560. if (pf->flags & I40E_FLAG_PTP_L4_CAPABLE)
  1561. info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1562. BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1563. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
  1564. BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  1565. BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
  1566. BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1567. BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  1568. BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  1569. return 0;
  1570. }
  1571. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1572. {
  1573. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1574. struct i40e_pf *pf = np->vsi->back;
  1575. i40e_status status;
  1576. bool link_up = false;
  1577. netif_info(pf, hw, netdev, "link test\n");
  1578. status = i40e_get_link_status(&pf->hw, &link_up);
  1579. if (status) {
  1580. netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
  1581. *data = 1;
  1582. return *data;
  1583. }
  1584. if (link_up)
  1585. *data = 0;
  1586. else
  1587. *data = 1;
  1588. return *data;
  1589. }
  1590. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1591. {
  1592. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1593. struct i40e_pf *pf = np->vsi->back;
  1594. netif_info(pf, hw, netdev, "register test\n");
  1595. *data = i40e_diag_reg_test(&pf->hw);
  1596. return *data;
  1597. }
  1598. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1599. {
  1600. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1601. struct i40e_pf *pf = np->vsi->back;
  1602. netif_info(pf, hw, netdev, "eeprom test\n");
  1603. *data = i40e_diag_eeprom_test(&pf->hw);
  1604. /* forcebly clear the NVM Update state machine */
  1605. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1606. return *data;
  1607. }
  1608. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1609. {
  1610. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1611. struct i40e_pf *pf = np->vsi->back;
  1612. u16 swc_old = pf->sw_int_count;
  1613. netif_info(pf, hw, netdev, "interrupt test\n");
  1614. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1615. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1616. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1617. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1618. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1619. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1620. usleep_range(1000, 2000);
  1621. *data = (swc_old == pf->sw_int_count);
  1622. return *data;
  1623. }
  1624. static inline bool i40e_active_vfs(struct i40e_pf *pf)
  1625. {
  1626. struct i40e_vf *vfs = pf->vf;
  1627. int i;
  1628. for (i = 0; i < pf->num_alloc_vfs; i++)
  1629. if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
  1630. return true;
  1631. return false;
  1632. }
  1633. static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
  1634. {
  1635. return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
  1636. }
  1637. static void i40e_diag_test(struct net_device *netdev,
  1638. struct ethtool_test *eth_test, u64 *data)
  1639. {
  1640. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1641. bool if_running = netif_running(netdev);
  1642. struct i40e_pf *pf = np->vsi->back;
  1643. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1644. /* Offline tests */
  1645. netif_info(pf, drv, netdev, "offline testing starting\n");
  1646. set_bit(__I40E_TESTING, &pf->state);
  1647. if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
  1648. dev_warn(&pf->pdev->dev,
  1649. "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
  1650. data[I40E_ETH_TEST_REG] = 1;
  1651. data[I40E_ETH_TEST_EEPROM] = 1;
  1652. data[I40E_ETH_TEST_INTR] = 1;
  1653. data[I40E_ETH_TEST_LINK] = 1;
  1654. eth_test->flags |= ETH_TEST_FL_FAILED;
  1655. clear_bit(__I40E_TESTING, &pf->state);
  1656. goto skip_ol_tests;
  1657. }
  1658. /* If the device is online then take it offline */
  1659. if (if_running)
  1660. /* indicate we're in test mode */
  1661. i40e_close(netdev);
  1662. else
  1663. /* This reset does not affect link - if it is
  1664. * changed to a type of reset that does affect
  1665. * link then the following link test would have
  1666. * to be moved to before the reset
  1667. */
  1668. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1669. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1670. eth_test->flags |= ETH_TEST_FL_FAILED;
  1671. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1672. eth_test->flags |= ETH_TEST_FL_FAILED;
  1673. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1674. eth_test->flags |= ETH_TEST_FL_FAILED;
  1675. /* run reg test last, a reset is required after it */
  1676. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1677. eth_test->flags |= ETH_TEST_FL_FAILED;
  1678. clear_bit(__I40E_TESTING, &pf->state);
  1679. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1680. if (if_running)
  1681. i40e_open(netdev);
  1682. } else {
  1683. /* Online tests */
  1684. netif_info(pf, drv, netdev, "online testing starting\n");
  1685. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1686. eth_test->flags |= ETH_TEST_FL_FAILED;
  1687. /* Offline only tests, not run in online; pass by default */
  1688. data[I40E_ETH_TEST_REG] = 0;
  1689. data[I40E_ETH_TEST_EEPROM] = 0;
  1690. data[I40E_ETH_TEST_INTR] = 0;
  1691. }
  1692. skip_ol_tests:
  1693. netif_info(pf, drv, netdev, "testing finished\n");
  1694. }
  1695. static void i40e_get_wol(struct net_device *netdev,
  1696. struct ethtool_wolinfo *wol)
  1697. {
  1698. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1699. struct i40e_pf *pf = np->vsi->back;
  1700. struct i40e_hw *hw = &pf->hw;
  1701. u16 wol_nvm_bits;
  1702. /* NVM bit on means WoL disabled for the port */
  1703. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1704. if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
  1705. wol->supported = 0;
  1706. wol->wolopts = 0;
  1707. } else {
  1708. wol->supported = WAKE_MAGIC;
  1709. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1710. }
  1711. }
  1712. /**
  1713. * i40e_set_wol - set the WakeOnLAN configuration
  1714. * @netdev: the netdev in question
  1715. * @wol: the ethtool WoL setting data
  1716. **/
  1717. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1718. {
  1719. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1720. struct i40e_pf *pf = np->vsi->back;
  1721. struct i40e_vsi *vsi = np->vsi;
  1722. struct i40e_hw *hw = &pf->hw;
  1723. u16 wol_nvm_bits;
  1724. /* WoL not supported if this isn't the controlling PF on the port */
  1725. if (hw->partition_id != 1) {
  1726. i40e_partition_setting_complaint(pf);
  1727. return -EOPNOTSUPP;
  1728. }
  1729. if (vsi != pf->vsi[pf->lan_vsi])
  1730. return -EOPNOTSUPP;
  1731. /* NVM bit on means WoL disabled for the port */
  1732. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1733. if (BIT(hw->port) & wol_nvm_bits)
  1734. return -EOPNOTSUPP;
  1735. /* only magic packet is supported */
  1736. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1737. return -EOPNOTSUPP;
  1738. /* is this a new value? */
  1739. if (pf->wol_en != !!wol->wolopts) {
  1740. pf->wol_en = !!wol->wolopts;
  1741. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1742. }
  1743. return 0;
  1744. }
  1745. static int i40e_set_phys_id(struct net_device *netdev,
  1746. enum ethtool_phys_id_state state)
  1747. {
  1748. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1749. i40e_status ret = 0;
  1750. struct i40e_pf *pf = np->vsi->back;
  1751. struct i40e_hw *hw = &pf->hw;
  1752. int blink_freq = 2;
  1753. u16 temp_status;
  1754. switch (state) {
  1755. case ETHTOOL_ID_ACTIVE:
  1756. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
  1757. pf->led_status = i40e_led_get(hw);
  1758. } else {
  1759. i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
  1760. ret = i40e_led_get_phy(hw, &temp_status,
  1761. &pf->phy_led_val);
  1762. pf->led_status = temp_status;
  1763. }
  1764. return blink_freq;
  1765. case ETHTOOL_ID_ON:
  1766. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
  1767. i40e_led_set(hw, 0xf, false);
  1768. else
  1769. ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
  1770. break;
  1771. case ETHTOOL_ID_OFF:
  1772. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
  1773. i40e_led_set(hw, 0x0, false);
  1774. else
  1775. ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
  1776. break;
  1777. case ETHTOOL_ID_INACTIVE:
  1778. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
  1779. i40e_led_set(hw, pf->led_status, false);
  1780. } else {
  1781. ret = i40e_led_set_phy(hw, false, pf->led_status,
  1782. (pf->phy_led_val |
  1783. I40E_PHY_LED_MODE_ORIG));
  1784. i40e_aq_set_phy_debug(hw, 0, NULL);
  1785. }
  1786. break;
  1787. default:
  1788. break;
  1789. }
  1790. if (ret)
  1791. return -ENOENT;
  1792. else
  1793. return 0;
  1794. }
  1795. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1796. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1797. * 125us (8000 interrupts per second) == ITR(62)
  1798. */
  1799. /**
  1800. * __i40e_get_coalesce - get per-queue coalesce settings
  1801. * @netdev: the netdev to check
  1802. * @ec: ethtool coalesce data structure
  1803. * @queue: which queue to pick
  1804. *
  1805. * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
  1806. * are per queue. If queue is <0 then we default to queue 0 as the
  1807. * representative value.
  1808. **/
  1809. static int __i40e_get_coalesce(struct net_device *netdev,
  1810. struct ethtool_coalesce *ec,
  1811. int queue)
  1812. {
  1813. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1814. struct i40e_ring *rx_ring, *tx_ring;
  1815. struct i40e_vsi *vsi = np->vsi;
  1816. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1817. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1818. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1819. * return queue 0's value to represent.
  1820. */
  1821. if (queue < 0) {
  1822. queue = 0;
  1823. } else if (queue >= vsi->num_queue_pairs) {
  1824. return -EINVAL;
  1825. }
  1826. rx_ring = vsi->rx_rings[queue];
  1827. tx_ring = vsi->tx_rings[queue];
  1828. if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
  1829. ec->use_adaptive_rx_coalesce = 1;
  1830. if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
  1831. ec->use_adaptive_tx_coalesce = 1;
  1832. ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1833. ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1834. /* we use the _usecs_high to store/set the interrupt rate limit
  1835. * that the hardware supports, that almost but not quite
  1836. * fits the original intent of the ethtool variable,
  1837. * the rx_coalesce_usecs_high limits total interrupts
  1838. * per second from both tx/rx sources.
  1839. */
  1840. ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
  1841. ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
  1842. return 0;
  1843. }
  1844. /**
  1845. * i40e_get_coalesce - get a netdev's coalesce settings
  1846. * @netdev: the netdev to check
  1847. * @ec: ethtool coalesce data structure
  1848. *
  1849. * Gets the coalesce settings for a particular netdev. Note that if user has
  1850. * modified per-queue settings, this only guarantees to represent queue 0. See
  1851. * __i40e_get_coalesce for more details.
  1852. **/
  1853. static int i40e_get_coalesce(struct net_device *netdev,
  1854. struct ethtool_coalesce *ec)
  1855. {
  1856. return __i40e_get_coalesce(netdev, ec, -1);
  1857. }
  1858. /**
  1859. * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
  1860. * @netdev: netdev structure
  1861. * @ec: ethtool's coalesce settings
  1862. * @queue: the particular queue to read
  1863. *
  1864. * Will read a specific queue's coalesce settings
  1865. **/
  1866. static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1867. struct ethtool_coalesce *ec)
  1868. {
  1869. return __i40e_get_coalesce(netdev, ec, queue);
  1870. }
  1871. /**
  1872. * i40e_set_itr_per_queue - set ITR values for specific queue
  1873. * @vsi: the VSI to set values for
  1874. * @ec: coalesce settings from ethtool
  1875. * @queue: the queue to modify
  1876. *
  1877. * Change the ITR settings for a specific queue.
  1878. **/
  1879. static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
  1880. struct ethtool_coalesce *ec,
  1881. int queue)
  1882. {
  1883. struct i40e_pf *pf = vsi->back;
  1884. struct i40e_hw *hw = &pf->hw;
  1885. struct i40e_q_vector *q_vector;
  1886. u16 vector, intrl;
  1887. intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
  1888. vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
  1889. vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
  1890. if (ec->use_adaptive_rx_coalesce)
  1891. vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1892. else
  1893. vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1894. if (ec->use_adaptive_tx_coalesce)
  1895. vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1896. else
  1897. vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1898. q_vector = vsi->rx_rings[queue]->q_vector;
  1899. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
  1900. vector = vsi->base_vector + q_vector->v_idx;
  1901. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  1902. q_vector = vsi->tx_rings[queue]->q_vector;
  1903. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
  1904. vector = vsi->base_vector + q_vector->v_idx;
  1905. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  1906. wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
  1907. i40e_flush(hw);
  1908. }
  1909. /**
  1910. * __i40e_set_coalesce - set coalesce settings for particular queue
  1911. * @netdev: the netdev to change
  1912. * @ec: ethtool coalesce settings
  1913. * @queue: the queue to change
  1914. *
  1915. * Sets the coalesce settings for a particular queue.
  1916. **/
  1917. static int __i40e_set_coalesce(struct net_device *netdev,
  1918. struct ethtool_coalesce *ec,
  1919. int queue)
  1920. {
  1921. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1922. struct i40e_vsi *vsi = np->vsi;
  1923. struct i40e_pf *pf = vsi->back;
  1924. u16 intrl_reg;
  1925. int i;
  1926. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1927. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1928. /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
  1929. if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
  1930. netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
  1931. return -EINVAL;
  1932. }
  1933. if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
  1934. netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
  1935. INTRL_REG_TO_USEC(I40E_MAX_INTRL));
  1936. return -EINVAL;
  1937. }
  1938. if (ec->rx_coalesce_usecs == 0) {
  1939. if (ec->use_adaptive_rx_coalesce)
  1940. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1941. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1942. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1943. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1944. return -EINVAL;
  1945. }
  1946. intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
  1947. vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
  1948. if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
  1949. netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
  1950. vsi->int_rate_limit);
  1951. }
  1952. if (ec->tx_coalesce_usecs == 0) {
  1953. if (ec->use_adaptive_tx_coalesce)
  1954. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1955. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1956. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1957. netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  1958. return -EINVAL;
  1959. }
  1960. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1961. * apply to all queues.
  1962. */
  1963. if (queue < 0) {
  1964. for (i = 0; i < vsi->num_queue_pairs; i++)
  1965. i40e_set_itr_per_queue(vsi, ec, i);
  1966. } else if (queue < vsi->num_queue_pairs) {
  1967. i40e_set_itr_per_queue(vsi, ec, queue);
  1968. } else {
  1969. netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  1970. vsi->num_queue_pairs - 1);
  1971. return -EINVAL;
  1972. }
  1973. return 0;
  1974. }
  1975. /**
  1976. * i40e_set_coalesce - set coalesce settings for every queue on the netdev
  1977. * @netdev: the netdev to change
  1978. * @ec: ethtool coalesce settings
  1979. *
  1980. * This will set each queue to the same coalesce settings.
  1981. **/
  1982. static int i40e_set_coalesce(struct net_device *netdev,
  1983. struct ethtool_coalesce *ec)
  1984. {
  1985. return __i40e_set_coalesce(netdev, ec, -1);
  1986. }
  1987. /**
  1988. * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
  1989. * @netdev: the netdev to change
  1990. * @ec: ethtool's coalesce settings
  1991. * @queue: the queue to change
  1992. *
  1993. * Sets the specified queue's coalesce settings.
  1994. **/
  1995. static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1996. struct ethtool_coalesce *ec)
  1997. {
  1998. return __i40e_set_coalesce(netdev, ec, queue);
  1999. }
  2000. /**
  2001. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  2002. * @pf: pointer to the physical function struct
  2003. * @cmd: ethtool rxnfc command
  2004. *
  2005. * Returns Success if the flow is supported, else Invalid Input.
  2006. **/
  2007. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  2008. {
  2009. struct i40e_hw *hw = &pf->hw;
  2010. u8 flow_pctype = 0;
  2011. u64 i_set = 0;
  2012. cmd->data = 0;
  2013. switch (cmd->flow_type) {
  2014. case TCP_V4_FLOW:
  2015. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2016. break;
  2017. case UDP_V4_FLOW:
  2018. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2019. break;
  2020. case TCP_V6_FLOW:
  2021. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  2022. break;
  2023. case UDP_V6_FLOW:
  2024. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  2025. break;
  2026. case SCTP_V4_FLOW:
  2027. case AH_ESP_V4_FLOW:
  2028. case AH_V4_FLOW:
  2029. case ESP_V4_FLOW:
  2030. case IPV4_FLOW:
  2031. case SCTP_V6_FLOW:
  2032. case AH_ESP_V6_FLOW:
  2033. case AH_V6_FLOW:
  2034. case ESP_V6_FLOW:
  2035. case IPV6_FLOW:
  2036. /* Default is src/dest for IP, no matter the L4 hashing */
  2037. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  2038. break;
  2039. default:
  2040. return -EINVAL;
  2041. }
  2042. /* Read flow based hash input set register */
  2043. if (flow_pctype) {
  2044. i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2045. flow_pctype)) |
  2046. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2047. flow_pctype)) << 32);
  2048. }
  2049. /* Process bits of hash input set */
  2050. if (i_set) {
  2051. if (i_set & I40E_L4_SRC_MASK)
  2052. cmd->data |= RXH_L4_B_0_1;
  2053. if (i_set & I40E_L4_DST_MASK)
  2054. cmd->data |= RXH_L4_B_2_3;
  2055. if (cmd->flow_type == TCP_V4_FLOW ||
  2056. cmd->flow_type == UDP_V4_FLOW) {
  2057. if (i_set & I40E_L3_SRC_MASK)
  2058. cmd->data |= RXH_IP_SRC;
  2059. if (i_set & I40E_L3_DST_MASK)
  2060. cmd->data |= RXH_IP_DST;
  2061. } else if (cmd->flow_type == TCP_V6_FLOW ||
  2062. cmd->flow_type == UDP_V6_FLOW) {
  2063. if (i_set & I40E_L3_V6_SRC_MASK)
  2064. cmd->data |= RXH_IP_SRC;
  2065. if (i_set & I40E_L3_V6_DST_MASK)
  2066. cmd->data |= RXH_IP_DST;
  2067. }
  2068. }
  2069. return 0;
  2070. }
  2071. /**
  2072. * i40e_check_mask - Check whether a mask field is set
  2073. * @mask: the full mask value
  2074. * @field; mask of the field to check
  2075. *
  2076. * If the given mask is fully set, return positive value. If the mask for the
  2077. * field is fully unset, return zero. Otherwise return a negative error code.
  2078. **/
  2079. static int i40e_check_mask(u64 mask, u64 field)
  2080. {
  2081. u64 value = mask & field;
  2082. if (value == field)
  2083. return 1;
  2084. else if (!value)
  2085. return 0;
  2086. else
  2087. return -1;
  2088. }
  2089. /**
  2090. * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
  2091. * @fsp: pointer to rx flow specification
  2092. * @data: pointer to userdef data structure for storage
  2093. *
  2094. * Read the user-defined data and deconstruct the value into a structure. No
  2095. * other code should read the user-defined data, so as to ensure that every
  2096. * place consistently reads the value correctly.
  2097. *
  2098. * The user-defined field is a 64bit Big Endian format value, which we
  2099. * deconstruct by reading bits or bit fields from it. Single bit flags shall
  2100. * be defined starting from the highest bits, while small bit field values
  2101. * shall be defined starting from the lowest bits.
  2102. *
  2103. * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
  2104. * and the filter should be rejected. The data structure will always be
  2105. * modified even if FLOW_EXT is not set.
  2106. *
  2107. **/
  2108. static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
  2109. struct i40e_rx_flow_userdef *data)
  2110. {
  2111. u64 value, mask;
  2112. int valid;
  2113. /* Zero memory first so it's always consistent. */
  2114. memset(data, 0, sizeof(*data));
  2115. if (!(fsp->flow_type & FLOW_EXT))
  2116. return 0;
  2117. value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
  2118. mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
  2119. #define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
  2120. #define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
  2121. #define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
  2122. valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
  2123. if (valid < 0) {
  2124. return -EINVAL;
  2125. } else if (valid) {
  2126. data->flex_word = value & I40E_USERDEF_FLEX_WORD;
  2127. data->flex_offset =
  2128. (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
  2129. data->flex_filter = true;
  2130. }
  2131. return 0;
  2132. }
  2133. /**
  2134. * i40e_fill_rx_flow_user_data - Fill in user-defined data field
  2135. * @fsp: pointer to rx_flow specification
  2136. *
  2137. * Reads the userdef data structure and properly fills in the user defined
  2138. * fields of the rx_flow_spec.
  2139. **/
  2140. static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
  2141. struct i40e_rx_flow_userdef *data)
  2142. {
  2143. u64 value = 0, mask = 0;
  2144. if (data->flex_filter) {
  2145. value |= data->flex_word;
  2146. value |= (u64)data->flex_offset << 16;
  2147. mask |= I40E_USERDEF_FLEX_FILTER;
  2148. }
  2149. if (value || mask)
  2150. fsp->flow_type |= FLOW_EXT;
  2151. *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
  2152. *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
  2153. }
  2154. /**
  2155. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  2156. * @pf: Pointer to the physical function struct
  2157. * @cmd: The command to get or set Rx flow classification rules
  2158. * @rule_locs: Array of used rule locations
  2159. *
  2160. * This function populates both the total and actual rule count of
  2161. * the ethtool flow classification command
  2162. *
  2163. * Returns 0 on success or -EMSGSIZE if entry not found
  2164. **/
  2165. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  2166. struct ethtool_rxnfc *cmd,
  2167. u32 *rule_locs)
  2168. {
  2169. struct i40e_fdir_filter *rule;
  2170. struct hlist_node *node2;
  2171. int cnt = 0;
  2172. /* report total rule count */
  2173. cmd->data = i40e_get_fd_cnt_all(pf);
  2174. hlist_for_each_entry_safe(rule, node2,
  2175. &pf->fdir_filter_list, fdir_node) {
  2176. if (cnt == cmd->rule_cnt)
  2177. return -EMSGSIZE;
  2178. rule_locs[cnt] = rule->fd_id;
  2179. cnt++;
  2180. }
  2181. cmd->rule_cnt = cnt;
  2182. return 0;
  2183. }
  2184. /**
  2185. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  2186. * @pf: Pointer to the physical function struct
  2187. * @cmd: The command to get or set Rx flow classification rules
  2188. *
  2189. * This function looks up a filter based on the Rx flow classification
  2190. * command and fills the flow spec info for it if found
  2191. *
  2192. * Returns 0 on success or -EINVAL if filter not found
  2193. **/
  2194. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  2195. struct ethtool_rxnfc *cmd)
  2196. {
  2197. struct ethtool_rx_flow_spec *fsp =
  2198. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2199. struct i40e_rx_flow_userdef userdef = {0};
  2200. struct i40e_fdir_filter *rule = NULL;
  2201. struct hlist_node *node2;
  2202. u64 input_set;
  2203. u16 index;
  2204. hlist_for_each_entry_safe(rule, node2,
  2205. &pf->fdir_filter_list, fdir_node) {
  2206. if (fsp->location <= rule->fd_id)
  2207. break;
  2208. }
  2209. if (!rule || fsp->location != rule->fd_id)
  2210. return -EINVAL;
  2211. fsp->flow_type = rule->flow_type;
  2212. if (fsp->flow_type == IP_USER_FLOW) {
  2213. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  2214. fsp->h_u.usr_ip4_spec.proto = 0;
  2215. fsp->m_u.usr_ip4_spec.proto = 0;
  2216. }
  2217. /* Reverse the src and dest notion, since the HW views them from
  2218. * Tx perspective where as the user expects it from Rx filter view.
  2219. */
  2220. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  2221. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  2222. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
  2223. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
  2224. switch (rule->flow_type) {
  2225. case SCTP_V4_FLOW:
  2226. index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
  2227. break;
  2228. case TCP_V4_FLOW:
  2229. index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2230. break;
  2231. case UDP_V4_FLOW:
  2232. index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2233. break;
  2234. case IP_USER_FLOW:
  2235. index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
  2236. break;
  2237. default:
  2238. /* If we have stored a filter with a flow type not listed here
  2239. * it is almost certainly a driver bug. WARN(), and then
  2240. * assign the input_set as if all fields are enabled to avoid
  2241. * reading unassigned memory.
  2242. */
  2243. WARN(1, "Missing input set index for flow_type %d\n",
  2244. rule->flow_type);
  2245. input_set = 0xFFFFFFFFFFFFFFFFULL;
  2246. goto no_input_set;
  2247. }
  2248. input_set = i40e_read_fd_input_set(pf, index);
  2249. no_input_set:
  2250. if (input_set & I40E_L3_SRC_MASK)
  2251. fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
  2252. if (input_set & I40E_L3_DST_MASK)
  2253. fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
  2254. if (input_set & I40E_L4_SRC_MASK)
  2255. fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
  2256. if (input_set & I40E_L4_DST_MASK)
  2257. fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
  2258. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  2259. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  2260. else
  2261. fsp->ring_cookie = rule->q_index;
  2262. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  2263. struct i40e_vsi *vsi;
  2264. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  2265. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  2266. /* VFs are zero-indexed by the driver, but ethtool
  2267. * expects them to be one-indexed, so add one here
  2268. */
  2269. u64 ring_vf = vsi->vf_id + 1;
  2270. ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
  2271. fsp->ring_cookie |= ring_vf;
  2272. }
  2273. }
  2274. if (rule->flex_filter) {
  2275. userdef.flex_filter = true;
  2276. userdef.flex_word = be16_to_cpu(rule->flex_word);
  2277. userdef.flex_offset = rule->flex_offset;
  2278. }
  2279. i40e_fill_rx_flow_user_data(fsp, &userdef);
  2280. return 0;
  2281. }
  2282. /**
  2283. * i40e_get_rxnfc - command to get RX flow classification rules
  2284. * @netdev: network interface device structure
  2285. * @cmd: ethtool rxnfc command
  2286. *
  2287. * Returns Success if the command is supported.
  2288. **/
  2289. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  2290. u32 *rule_locs)
  2291. {
  2292. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2293. struct i40e_vsi *vsi = np->vsi;
  2294. struct i40e_pf *pf = vsi->back;
  2295. int ret = -EOPNOTSUPP;
  2296. switch (cmd->cmd) {
  2297. case ETHTOOL_GRXRINGS:
  2298. cmd->data = vsi->num_queue_pairs;
  2299. ret = 0;
  2300. break;
  2301. case ETHTOOL_GRXFH:
  2302. ret = i40e_get_rss_hash_opts(pf, cmd);
  2303. break;
  2304. case ETHTOOL_GRXCLSRLCNT:
  2305. cmd->rule_cnt = pf->fdir_pf_active_filters;
  2306. /* report total rule count */
  2307. cmd->data = i40e_get_fd_cnt_all(pf);
  2308. ret = 0;
  2309. break;
  2310. case ETHTOOL_GRXCLSRULE:
  2311. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  2312. break;
  2313. case ETHTOOL_GRXCLSRLALL:
  2314. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  2315. break;
  2316. default:
  2317. break;
  2318. }
  2319. return ret;
  2320. }
  2321. /**
  2322. * i40e_get_rss_hash_bits - Read RSS Hash bits from register
  2323. * @nfc: pointer to user request
  2324. * @i_setc bits currently set
  2325. *
  2326. * Returns value of bits to be set per user request
  2327. **/
  2328. static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
  2329. {
  2330. u64 i_set = i_setc;
  2331. u64 src_l3 = 0, dst_l3 = 0;
  2332. if (nfc->data & RXH_L4_B_0_1)
  2333. i_set |= I40E_L4_SRC_MASK;
  2334. else
  2335. i_set &= ~I40E_L4_SRC_MASK;
  2336. if (nfc->data & RXH_L4_B_2_3)
  2337. i_set |= I40E_L4_DST_MASK;
  2338. else
  2339. i_set &= ~I40E_L4_DST_MASK;
  2340. if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
  2341. src_l3 = I40E_L3_V6_SRC_MASK;
  2342. dst_l3 = I40E_L3_V6_DST_MASK;
  2343. } else if (nfc->flow_type == TCP_V4_FLOW ||
  2344. nfc->flow_type == UDP_V4_FLOW) {
  2345. src_l3 = I40E_L3_SRC_MASK;
  2346. dst_l3 = I40E_L3_DST_MASK;
  2347. } else {
  2348. /* Any other flow type are not supported here */
  2349. return i_set;
  2350. }
  2351. if (nfc->data & RXH_IP_SRC)
  2352. i_set |= src_l3;
  2353. else
  2354. i_set &= ~src_l3;
  2355. if (nfc->data & RXH_IP_DST)
  2356. i_set |= dst_l3;
  2357. else
  2358. i_set &= ~dst_l3;
  2359. return i_set;
  2360. }
  2361. /**
  2362. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  2363. * @pf: pointer to the physical function struct
  2364. * @cmd: ethtool rxnfc command
  2365. *
  2366. * Returns Success if the flow input set is supported.
  2367. **/
  2368. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  2369. {
  2370. struct i40e_hw *hw = &pf->hw;
  2371. u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  2372. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  2373. u8 flow_pctype = 0;
  2374. u64 i_set, i_setc;
  2375. /* RSS does not support anything other than hashing
  2376. * to queues on src and dst IPs and ports
  2377. */
  2378. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  2379. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2380. return -EINVAL;
  2381. switch (nfc->flow_type) {
  2382. case TCP_V4_FLOW:
  2383. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2384. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2385. hena |=
  2386. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2387. break;
  2388. case TCP_V6_FLOW:
  2389. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  2390. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2391. hena |=
  2392. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2393. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2394. hena |=
  2395. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  2396. break;
  2397. case UDP_V4_FLOW:
  2398. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2399. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2400. hena |=
  2401. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  2402. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  2403. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2404. break;
  2405. case UDP_V6_FLOW:
  2406. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  2407. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2408. hena |=
  2409. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  2410. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  2411. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2412. break;
  2413. case AH_ESP_V4_FLOW:
  2414. case AH_V4_FLOW:
  2415. case ESP_V4_FLOW:
  2416. case SCTP_V4_FLOW:
  2417. if ((nfc->data & RXH_L4_B_0_1) ||
  2418. (nfc->data & RXH_L4_B_2_3))
  2419. return -EINVAL;
  2420. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  2421. break;
  2422. case AH_ESP_V6_FLOW:
  2423. case AH_V6_FLOW:
  2424. case ESP_V6_FLOW:
  2425. case SCTP_V6_FLOW:
  2426. if ((nfc->data & RXH_L4_B_0_1) ||
  2427. (nfc->data & RXH_L4_B_2_3))
  2428. return -EINVAL;
  2429. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  2430. break;
  2431. case IPV4_FLOW:
  2432. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  2433. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2434. break;
  2435. case IPV6_FLOW:
  2436. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  2437. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2438. break;
  2439. default:
  2440. return -EINVAL;
  2441. }
  2442. if (flow_pctype) {
  2443. i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2444. flow_pctype)) |
  2445. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2446. flow_pctype)) << 32);
  2447. i_set = i40e_get_rss_hash_bits(nfc, i_setc);
  2448. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
  2449. (u32)i_set);
  2450. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
  2451. (u32)(i_set >> 32));
  2452. hena |= BIT_ULL(flow_pctype);
  2453. }
  2454. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  2455. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  2456. i40e_flush(hw);
  2457. return 0;
  2458. }
  2459. /**
  2460. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  2461. * @vsi: Pointer to the targeted VSI
  2462. * @input: The filter to update or NULL to indicate deletion
  2463. * @sw_idx: Software index to the filter
  2464. * @cmd: The command to get or set Rx flow classification rules
  2465. *
  2466. * This function updates (or deletes) a Flow Director entry from
  2467. * the hlist of the corresponding PF
  2468. *
  2469. * Returns 0 on success
  2470. **/
  2471. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  2472. struct i40e_fdir_filter *input,
  2473. u16 sw_idx,
  2474. struct ethtool_rxnfc *cmd)
  2475. {
  2476. struct i40e_fdir_filter *rule, *parent;
  2477. struct i40e_pf *pf = vsi->back;
  2478. struct hlist_node *node2;
  2479. int err = -EINVAL;
  2480. parent = NULL;
  2481. rule = NULL;
  2482. hlist_for_each_entry_safe(rule, node2,
  2483. &pf->fdir_filter_list, fdir_node) {
  2484. /* hash found, or no matching entry */
  2485. if (rule->fd_id >= sw_idx)
  2486. break;
  2487. parent = rule;
  2488. }
  2489. /* if there is an old rule occupying our place remove it */
  2490. if (rule && (rule->fd_id == sw_idx)) {
  2491. /* Remove this rule, since we're either deleting it, or
  2492. * replacing it.
  2493. */
  2494. err = i40e_add_del_fdir(vsi, rule, false);
  2495. hlist_del(&rule->fdir_node);
  2496. kfree(rule);
  2497. pf->fdir_pf_active_filters--;
  2498. }
  2499. /* If we weren't given an input, this is a delete, so just return the
  2500. * error code indicating if there was an entry at the requested slot
  2501. */
  2502. if (!input)
  2503. return err;
  2504. /* Otherwise, install the new rule as requested */
  2505. INIT_HLIST_NODE(&input->fdir_node);
  2506. /* add filter to the list */
  2507. if (parent)
  2508. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  2509. else
  2510. hlist_add_head(&input->fdir_node,
  2511. &pf->fdir_filter_list);
  2512. /* update counts */
  2513. pf->fdir_pf_active_filters++;
  2514. return 0;
  2515. }
  2516. /**
  2517. * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
  2518. * @pf: pointer to PF structure
  2519. *
  2520. * This function searches the list of filters and determines which FLX_PIT
  2521. * entries are still required. It will prune any entries which are no longer
  2522. * in use after the deletion.
  2523. **/
  2524. static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
  2525. {
  2526. struct i40e_flex_pit *entry, *tmp;
  2527. struct i40e_fdir_filter *rule;
  2528. /* First, we'll check the l3 table */
  2529. list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
  2530. bool found = false;
  2531. hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
  2532. if (rule->flow_type != IP_USER_FLOW)
  2533. continue;
  2534. if (rule->flex_filter &&
  2535. rule->flex_offset == entry->src_offset) {
  2536. found = true;
  2537. break;
  2538. }
  2539. }
  2540. /* If we didn't find the filter, then we can prune this entry
  2541. * from the list.
  2542. */
  2543. if (!found) {
  2544. list_del(&entry->list);
  2545. kfree(entry);
  2546. }
  2547. }
  2548. /* Followed by the L4 table */
  2549. list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
  2550. bool found = false;
  2551. hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
  2552. /* Skip this filter if it's L3, since we already
  2553. * checked those in the above loop
  2554. */
  2555. if (rule->flow_type == IP_USER_FLOW)
  2556. continue;
  2557. if (rule->flex_filter &&
  2558. rule->flex_offset == entry->src_offset) {
  2559. found = true;
  2560. break;
  2561. }
  2562. }
  2563. /* If we didn't find the filter, then we can prune this entry
  2564. * from the list.
  2565. */
  2566. if (!found) {
  2567. list_del(&entry->list);
  2568. kfree(entry);
  2569. }
  2570. }
  2571. }
  2572. /**
  2573. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  2574. * @vsi: Pointer to the targeted VSI
  2575. * @cmd: The command to get or set Rx flow classification rules
  2576. *
  2577. * The function removes a Flow Director filter entry from the
  2578. * hlist of the corresponding PF
  2579. *
  2580. * Returns 0 on success
  2581. */
  2582. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  2583. struct ethtool_rxnfc *cmd)
  2584. {
  2585. struct ethtool_rx_flow_spec *fsp =
  2586. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2587. struct i40e_pf *pf = vsi->back;
  2588. int ret = 0;
  2589. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2590. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2591. return -EBUSY;
  2592. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2593. return -EBUSY;
  2594. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  2595. i40e_prune_flex_pit_list(pf);
  2596. i40e_fdir_check_and_reenable(pf);
  2597. return ret;
  2598. }
  2599. /**
  2600. * i40e_unused_pit_index - Find an unused PIT index for given list
  2601. * @pf: the PF data structure
  2602. *
  2603. * Find the first unused flexible PIT index entry. We search both the L3 and
  2604. * L4 flexible PIT lists so that the returned index is unique and unused by
  2605. * either currently programmed L3 or L4 filters. We use a bit field as storage
  2606. * to track which indexes are already used.
  2607. **/
  2608. static u8 i40e_unused_pit_index(struct i40e_pf *pf)
  2609. {
  2610. unsigned long available_index = 0xFF;
  2611. struct i40e_flex_pit *entry;
  2612. /* We need to make sure that the new index isn't in use by either L3
  2613. * or L4 filters so that IP_USER_FLOW filters can program both L3 and
  2614. * L4 to use the same index.
  2615. */
  2616. list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
  2617. clear_bit(entry->pit_index, &available_index);
  2618. list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
  2619. clear_bit(entry->pit_index, &available_index);
  2620. return find_first_bit(&available_index, 8);
  2621. }
  2622. /**
  2623. * i40e_find_flex_offset - Find an existing flex src_offset
  2624. * @flex_pit_list: L3 or L4 flex PIT list
  2625. * @src_offset: new src_offset to find
  2626. *
  2627. * Searches the flex_pit_list for an existing offset. If no offset is
  2628. * currently programmed, then this will return an ERR_PTR if there is no space
  2629. * to add a new offset, otherwise it returns NULL.
  2630. **/
  2631. static
  2632. struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
  2633. u16 src_offset)
  2634. {
  2635. struct i40e_flex_pit *entry;
  2636. int size = 0;
  2637. /* Search for the src_offset first. If we find a matching entry
  2638. * already programmed, we can simply re-use it.
  2639. */
  2640. list_for_each_entry(entry, flex_pit_list, list) {
  2641. size++;
  2642. if (entry->src_offset == src_offset)
  2643. return entry;
  2644. }
  2645. /* If we haven't found an entry yet, then the provided src offset has
  2646. * not yet been programmed. We will program the src offset later on,
  2647. * but we need to indicate whether there is enough space to do so
  2648. * here. We'll make use of ERR_PTR for this purpose.
  2649. */
  2650. if (size >= I40E_FLEX_PIT_TABLE_SIZE)
  2651. return ERR_PTR(-ENOSPC);
  2652. return NULL;
  2653. }
  2654. /**
  2655. * i40e_add_flex_offset - Add src_offset to flex PIT table list
  2656. * @flex_pit_list: L3 or L4 flex PIT list
  2657. * @src_offset: new src_offset to add
  2658. * @pit_index: the PIT index to program
  2659. *
  2660. * This function programs the new src_offset to the list. It is expected that
  2661. * i40e_find_flex_offset has already been tried and returned NULL, indicating
  2662. * that this offset is not programmed, and that the list has enough space to
  2663. * store another offset.
  2664. *
  2665. * Returns 0 on success, and negative value on error.
  2666. **/
  2667. static int i40e_add_flex_offset(struct list_head *flex_pit_list,
  2668. u16 src_offset,
  2669. u8 pit_index)
  2670. {
  2671. struct i40e_flex_pit *new_pit, *entry;
  2672. new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
  2673. if (!new_pit)
  2674. return -ENOMEM;
  2675. new_pit->src_offset = src_offset;
  2676. new_pit->pit_index = pit_index;
  2677. /* We need to insert this item such that the list is sorted by
  2678. * src_offset in ascending order.
  2679. */
  2680. list_for_each_entry(entry, flex_pit_list, list) {
  2681. if (new_pit->src_offset < entry->src_offset) {
  2682. list_add_tail(&new_pit->list, &entry->list);
  2683. return 0;
  2684. }
  2685. /* If we found an entry with our offset already programmed we
  2686. * can simply return here, after freeing the memory. However,
  2687. * if the pit_index does not match we need to report an error.
  2688. */
  2689. if (new_pit->src_offset == entry->src_offset) {
  2690. int err = 0;
  2691. /* If the PIT index is not the same we can't re-use
  2692. * the entry, so we must report an error.
  2693. */
  2694. if (new_pit->pit_index != entry->pit_index)
  2695. err = -EINVAL;
  2696. kfree(new_pit);
  2697. return err;
  2698. }
  2699. }
  2700. /* If we reached here, then we haven't yet added the item. This means
  2701. * that we should add the item at the end of the list.
  2702. */
  2703. list_add_tail(&new_pit->list, flex_pit_list);
  2704. return 0;
  2705. }
  2706. /**
  2707. * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
  2708. * @pf: Pointer to the PF structure
  2709. * @flex_pit_list: list of flexible src offsets in use
  2710. * #flex_pit_start: index to first entry for this section of the table
  2711. *
  2712. * In order to handle flexible data, the hardware uses a table of values
  2713. * called the FLX_PIT table. This table is used to indicate which sections of
  2714. * the input correspond to what PIT index values. Unfortunately, hardware is
  2715. * very restrictive about programming this table. Entries must be ordered by
  2716. * src_offset in ascending order, without duplicates. Additionally, unused
  2717. * entries must be set to the unused index value, and must have valid size and
  2718. * length according to the src_offset ordering.
  2719. *
  2720. * This function will reprogram the FLX_PIT register from a book-keeping
  2721. * structure that we guarantee is already ordered correctly, and has no more
  2722. * than 3 entries.
  2723. *
  2724. * To make things easier, we only support flexible values of one word length,
  2725. * rather than allowing variable length flexible values.
  2726. **/
  2727. static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
  2728. struct list_head *flex_pit_list,
  2729. int flex_pit_start)
  2730. {
  2731. struct i40e_flex_pit *entry = NULL;
  2732. u16 last_offset = 0;
  2733. int i = 0, j = 0;
  2734. /* First, loop over the list of flex PIT entries, and reprogram the
  2735. * registers.
  2736. */
  2737. list_for_each_entry(entry, flex_pit_list, list) {
  2738. /* We have to be careful when programming values for the
  2739. * largest SRC_OFFSET value. It is possible that adding
  2740. * additional empty values at the end would overflow the space
  2741. * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
  2742. * we check here and add the empty values prior to adding the
  2743. * largest value.
  2744. *
  2745. * To determine this, we will use a loop from i+1 to 3, which
  2746. * will determine whether the unused entries would have valid
  2747. * SRC_OFFSET. Note that there cannot be extra entries past
  2748. * this value, because the only valid values would have been
  2749. * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
  2750. * have been added to the list in the first place.
  2751. */
  2752. for (j = i + 1; j < 3; j++) {
  2753. u16 offset = entry->src_offset + j;
  2754. int index = flex_pit_start + i;
  2755. u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
  2756. 1,
  2757. offset - 3);
  2758. if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
  2759. i40e_write_rx_ctl(&pf->hw,
  2760. I40E_PRTQF_FLX_PIT(index),
  2761. value);
  2762. i++;
  2763. }
  2764. }
  2765. /* Now, we can program the actual value into the table */
  2766. i40e_write_rx_ctl(&pf->hw,
  2767. I40E_PRTQF_FLX_PIT(flex_pit_start + i),
  2768. I40E_FLEX_PREP_VAL(entry->pit_index + 50,
  2769. 1,
  2770. entry->src_offset));
  2771. i++;
  2772. }
  2773. /* In order to program the last entries in the table, we need to
  2774. * determine the valid offset. If the list is empty, we'll just start
  2775. * with 0. Otherwise, we'll start with the last item offset and add 1.
  2776. * This ensures that all entries have valid sizes. If we don't do this
  2777. * correctly, the hardware will disable flexible field parsing.
  2778. */
  2779. if (!list_empty(flex_pit_list))
  2780. last_offset = list_prev_entry(entry, list)->src_offset + 1;
  2781. for (; i < 3; i++, last_offset++) {
  2782. i40e_write_rx_ctl(&pf->hw,
  2783. I40E_PRTQF_FLX_PIT(flex_pit_start + i),
  2784. I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
  2785. 1,
  2786. last_offset));
  2787. }
  2788. }
  2789. /**
  2790. * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
  2791. * @pf: pointer to the PF structure
  2792. *
  2793. * This function reprograms both the L3 and L4 FLX_PIT tables. See the
  2794. * internal helper function for implementation details.
  2795. **/
  2796. static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
  2797. {
  2798. __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
  2799. I40E_FLEX_PIT_IDX_START_L3);
  2800. __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
  2801. I40E_FLEX_PIT_IDX_START_L4);
  2802. /* We also need to program the L3 and L4 GLQF ORT register */
  2803. i40e_write_rx_ctl(&pf->hw,
  2804. I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
  2805. I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
  2806. 3, 1));
  2807. i40e_write_rx_ctl(&pf->hw,
  2808. I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
  2809. I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
  2810. 3, 1));
  2811. }
  2812. /**
  2813. * i40e_flow_str - Converts a flow_type into a human readable string
  2814. * @flow_type: the flow type from a flow specification
  2815. *
  2816. * Currently only flow types we support are included here, and the string
  2817. * value attempts to match what ethtool would use to configure this flow type.
  2818. **/
  2819. static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
  2820. {
  2821. switch (fsp->flow_type & ~FLOW_EXT) {
  2822. case TCP_V4_FLOW:
  2823. return "tcp4";
  2824. case UDP_V4_FLOW:
  2825. return "udp4";
  2826. case SCTP_V4_FLOW:
  2827. return "sctp4";
  2828. case IP_USER_FLOW:
  2829. return "ip4";
  2830. default:
  2831. return "unknown";
  2832. }
  2833. }
  2834. /**
  2835. * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
  2836. * @pit_index: PIT index to convert
  2837. *
  2838. * Returns the mask for a given PIT index. Will return 0 if the pit_index is
  2839. * of range.
  2840. **/
  2841. static u64 i40e_pit_index_to_mask(int pit_index)
  2842. {
  2843. switch (pit_index) {
  2844. case 0:
  2845. return I40E_FLEX_50_MASK;
  2846. case 1:
  2847. return I40E_FLEX_51_MASK;
  2848. case 2:
  2849. return I40E_FLEX_52_MASK;
  2850. case 3:
  2851. return I40E_FLEX_53_MASK;
  2852. case 4:
  2853. return I40E_FLEX_54_MASK;
  2854. case 5:
  2855. return I40E_FLEX_55_MASK;
  2856. case 6:
  2857. return I40E_FLEX_56_MASK;
  2858. case 7:
  2859. return I40E_FLEX_57_MASK;
  2860. default:
  2861. return 0;
  2862. }
  2863. }
  2864. /**
  2865. * i40e_print_input_set - Show changes between two input sets
  2866. * @vsi: the vsi being configured
  2867. * @old: the old input set
  2868. * @new: the new input set
  2869. *
  2870. * Print the difference between old and new input sets by showing which series
  2871. * of words are toggled on or off. Only displays the bits we actually support
  2872. * changing.
  2873. **/
  2874. static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
  2875. {
  2876. struct i40e_pf *pf = vsi->back;
  2877. bool old_value, new_value;
  2878. int i;
  2879. old_value = !!(old & I40E_L3_SRC_MASK);
  2880. new_value = !!(new & I40E_L3_SRC_MASK);
  2881. if (old_value != new_value)
  2882. netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
  2883. old_value ? "ON" : "OFF",
  2884. new_value ? "ON" : "OFF");
  2885. old_value = !!(old & I40E_L3_DST_MASK);
  2886. new_value = !!(new & I40E_L3_DST_MASK);
  2887. if (old_value != new_value)
  2888. netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
  2889. old_value ? "ON" : "OFF",
  2890. new_value ? "ON" : "OFF");
  2891. old_value = !!(old & I40E_L4_SRC_MASK);
  2892. new_value = !!(new & I40E_L4_SRC_MASK);
  2893. if (old_value != new_value)
  2894. netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
  2895. old_value ? "ON" : "OFF",
  2896. new_value ? "ON" : "OFF");
  2897. old_value = !!(old & I40E_L4_DST_MASK);
  2898. new_value = !!(new & I40E_L4_DST_MASK);
  2899. if (old_value != new_value)
  2900. netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
  2901. old_value ? "ON" : "OFF",
  2902. new_value ? "ON" : "OFF");
  2903. old_value = !!(old & I40E_VERIFY_TAG_MASK);
  2904. new_value = !!(new & I40E_VERIFY_TAG_MASK);
  2905. if (old_value != new_value)
  2906. netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
  2907. old_value ? "ON" : "OFF",
  2908. new_value ? "ON" : "OFF");
  2909. /* Show change of flexible filter entries */
  2910. for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
  2911. u64 flex_mask = i40e_pit_index_to_mask(i);
  2912. old_value = !!(old & flex_mask);
  2913. new_value = !!(new & flex_mask);
  2914. if (old_value != new_value)
  2915. netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
  2916. i,
  2917. old_value ? "ON" : "OFF",
  2918. new_value ? "ON" : "OFF");
  2919. }
  2920. netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
  2921. old);
  2922. netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
  2923. new);
  2924. }
  2925. /**
  2926. * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
  2927. * @vsi: pointer to the targeted VSI
  2928. * @fsp: pointer to Rx flow specification
  2929. * @userdef: userdefined data from flow specification
  2930. *
  2931. * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
  2932. * for partial matches exists with a few limitations. First, hardware only
  2933. * supports masking by word boundary (2 bytes) and not per individual bit.
  2934. * Second, hardware is limited to using one mask for a flow type and cannot
  2935. * use a separate mask for each filter.
  2936. *
  2937. * To support these limitations, if we already have a configured filter for
  2938. * the specified type, this function enforces that new filters of the type
  2939. * match the configured input set. Otherwise, if we do not have a filter of
  2940. * the specified type, we allow the input set to be updated to match the
  2941. * desired filter.
  2942. *
  2943. * To help ensure that administrators understand why filters weren't displayed
  2944. * as supported, we print a diagnostic message displaying how the input set
  2945. * would change and warning to delete the preexisting filters if required.
  2946. *
  2947. * Returns 0 on successful input set match, and a negative return code on
  2948. * failure.
  2949. **/
  2950. static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
  2951. struct ethtool_rx_flow_spec *fsp,
  2952. struct i40e_rx_flow_userdef *userdef)
  2953. {
  2954. struct i40e_pf *pf = vsi->back;
  2955. struct ethtool_tcpip4_spec *tcp_ip4_spec;
  2956. struct ethtool_usrip4_spec *usr_ip4_spec;
  2957. u64 current_mask, new_mask;
  2958. bool new_flex_offset = false;
  2959. bool flex_l3 = false;
  2960. u16 *fdir_filter_count;
  2961. u16 index, src_offset = 0;
  2962. u8 pit_index = 0;
  2963. int err;
  2964. switch (fsp->flow_type & ~FLOW_EXT) {
  2965. case SCTP_V4_FLOW:
  2966. index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
  2967. fdir_filter_count = &pf->fd_sctp4_filter_cnt;
  2968. break;
  2969. case TCP_V4_FLOW:
  2970. index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2971. fdir_filter_count = &pf->fd_tcp4_filter_cnt;
  2972. break;
  2973. case UDP_V4_FLOW:
  2974. index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2975. fdir_filter_count = &pf->fd_udp4_filter_cnt;
  2976. break;
  2977. case IP_USER_FLOW:
  2978. index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
  2979. fdir_filter_count = &pf->fd_ip4_filter_cnt;
  2980. flex_l3 = true;
  2981. break;
  2982. default:
  2983. return -EOPNOTSUPP;
  2984. }
  2985. /* Read the current input set from register memory. */
  2986. current_mask = i40e_read_fd_input_set(pf, index);
  2987. new_mask = current_mask;
  2988. /* Determine, if any, the required changes to the input set in order
  2989. * to support the provided mask.
  2990. *
  2991. * Hardware only supports masking at word (2 byte) granularity and does
  2992. * not support full bitwise masking. This implementation simplifies
  2993. * even further and only supports fully enabled or fully disabled
  2994. * masks for each field, even though we could split the ip4src and
  2995. * ip4dst fields.
  2996. */
  2997. switch (fsp->flow_type & ~FLOW_EXT) {
  2998. case SCTP_V4_FLOW:
  2999. new_mask &= ~I40E_VERIFY_TAG_MASK;
  3000. /* Fall through */
  3001. case TCP_V4_FLOW:
  3002. case UDP_V4_FLOW:
  3003. tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
  3004. /* IPv4 source address */
  3005. if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
  3006. new_mask |= I40E_L3_SRC_MASK;
  3007. else if (!tcp_ip4_spec->ip4src)
  3008. new_mask &= ~I40E_L3_SRC_MASK;
  3009. else
  3010. return -EOPNOTSUPP;
  3011. /* IPv4 destination address */
  3012. if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
  3013. new_mask |= I40E_L3_DST_MASK;
  3014. else if (!tcp_ip4_spec->ip4dst)
  3015. new_mask &= ~I40E_L3_DST_MASK;
  3016. else
  3017. return -EOPNOTSUPP;
  3018. /* L4 source port */
  3019. if (tcp_ip4_spec->psrc == htons(0xFFFF))
  3020. new_mask |= I40E_L4_SRC_MASK;
  3021. else if (!tcp_ip4_spec->psrc)
  3022. new_mask &= ~I40E_L4_SRC_MASK;
  3023. else
  3024. return -EOPNOTSUPP;
  3025. /* L4 destination port */
  3026. if (tcp_ip4_spec->pdst == htons(0xFFFF))
  3027. new_mask |= I40E_L4_DST_MASK;
  3028. else if (!tcp_ip4_spec->pdst)
  3029. new_mask &= ~I40E_L4_DST_MASK;
  3030. else
  3031. return -EOPNOTSUPP;
  3032. /* Filtering on Type of Service is not supported. */
  3033. if (tcp_ip4_spec->tos)
  3034. return -EOPNOTSUPP;
  3035. break;
  3036. case IP_USER_FLOW:
  3037. usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
  3038. /* IPv4 source address */
  3039. if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
  3040. new_mask |= I40E_L3_SRC_MASK;
  3041. else if (!usr_ip4_spec->ip4src)
  3042. new_mask &= ~I40E_L3_SRC_MASK;
  3043. else
  3044. return -EOPNOTSUPP;
  3045. /* IPv4 destination address */
  3046. if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
  3047. new_mask |= I40E_L3_DST_MASK;
  3048. else if (!usr_ip4_spec->ip4dst)
  3049. new_mask &= ~I40E_L3_DST_MASK;
  3050. else
  3051. return -EOPNOTSUPP;
  3052. /* First 4 bytes of L4 header */
  3053. if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
  3054. new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
  3055. else if (!usr_ip4_spec->l4_4_bytes)
  3056. new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  3057. else
  3058. return -EOPNOTSUPP;
  3059. /* Filtering on Type of Service is not supported. */
  3060. if (usr_ip4_spec->tos)
  3061. return -EOPNOTSUPP;
  3062. /* Filtering on IP version is not supported */
  3063. if (usr_ip4_spec->ip_ver)
  3064. return -EINVAL;
  3065. /* Filtering on L4 protocol is not supported */
  3066. if (usr_ip4_spec->proto)
  3067. return -EINVAL;
  3068. break;
  3069. default:
  3070. return -EOPNOTSUPP;
  3071. }
  3072. /* First, clear all flexible filter entries */
  3073. new_mask &= ~I40E_FLEX_INPUT_MASK;
  3074. /* If we have a flexible filter, try to add this offset to the correct
  3075. * flexible filter PIT list. Once finished, we can update the mask.
  3076. * If the src_offset changed, we will get a new mask value which will
  3077. * trigger an input set change.
  3078. */
  3079. if (userdef->flex_filter) {
  3080. struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
  3081. /* Flexible offset must be even, since the flexible payload
  3082. * must be aligned on 2-byte boundary.
  3083. */
  3084. if (userdef->flex_offset & 0x1) {
  3085. dev_warn(&pf->pdev->dev,
  3086. "Flexible data offset must be 2-byte aligned\n");
  3087. return -EINVAL;
  3088. }
  3089. src_offset = userdef->flex_offset >> 1;
  3090. /* FLX_PIT source offset value is only so large */
  3091. if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
  3092. dev_warn(&pf->pdev->dev,
  3093. "Flexible data must reside within first 64 bytes of the packet payload\n");
  3094. return -EINVAL;
  3095. }
  3096. /* See if this offset has already been programmed. If we get
  3097. * an ERR_PTR, then the filter is not safe to add. Otherwise,
  3098. * if we get a NULL pointer, this means we will need to add
  3099. * the offset.
  3100. */
  3101. flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
  3102. src_offset);
  3103. if (IS_ERR(flex_pit))
  3104. return PTR_ERR(flex_pit);
  3105. /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
  3106. * packet types, and thus we need to program both L3 and L4
  3107. * flexible values. These must have identical flexible index,
  3108. * as otherwise we can't correctly program the input set. So
  3109. * we'll find both an L3 and L4 index and make sure they are
  3110. * the same.
  3111. */
  3112. if (flex_l3) {
  3113. l3_flex_pit =
  3114. i40e_find_flex_offset(&pf->l3_flex_pit_list,
  3115. src_offset);
  3116. if (IS_ERR(l3_flex_pit))
  3117. return PTR_ERR(l3_flex_pit);
  3118. if (flex_pit) {
  3119. /* If we already had a matching L4 entry, we
  3120. * need to make sure that the L3 entry we
  3121. * obtained uses the same index.
  3122. */
  3123. if (l3_flex_pit) {
  3124. if (l3_flex_pit->pit_index !=
  3125. flex_pit->pit_index) {
  3126. return -EINVAL;
  3127. }
  3128. } else {
  3129. new_flex_offset = true;
  3130. }
  3131. } else {
  3132. flex_pit = l3_flex_pit;
  3133. }
  3134. }
  3135. /* If we didn't find an existing flex offset, we need to
  3136. * program a new one. However, we don't immediately program it
  3137. * here because we will wait to program until after we check
  3138. * that it is safe to change the input set.
  3139. */
  3140. if (!flex_pit) {
  3141. new_flex_offset = true;
  3142. pit_index = i40e_unused_pit_index(pf);
  3143. } else {
  3144. pit_index = flex_pit->pit_index;
  3145. }
  3146. /* Update the mask with the new offset */
  3147. new_mask |= i40e_pit_index_to_mask(pit_index);
  3148. }
  3149. /* If the mask and flexible filter offsets for this filter match the
  3150. * currently programmed values we don't need any input set change, so
  3151. * this filter is safe to install.
  3152. */
  3153. if (new_mask == current_mask && !new_flex_offset)
  3154. return 0;
  3155. netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
  3156. i40e_flow_str(fsp));
  3157. i40e_print_input_set(vsi, current_mask, new_mask);
  3158. if (new_flex_offset) {
  3159. netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
  3160. pit_index, src_offset);
  3161. }
  3162. /* Hardware input sets are global across multiple ports, so even the
  3163. * main port cannot change them when in MFP mode as this would impact
  3164. * any filters on the other ports.
  3165. */
  3166. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3167. netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
  3168. return -EOPNOTSUPP;
  3169. }
  3170. /* This filter requires us to update the input set. However, hardware
  3171. * only supports one input set per flow type, and does not support
  3172. * separate masks for each filter. This means that we can only support
  3173. * a single mask for all filters of a specific type.
  3174. *
  3175. * If we have preexisting filters, they obviously depend on the
  3176. * current programmed input set. Display a diagnostic message in this
  3177. * case explaining why the filter could not be accepted.
  3178. */
  3179. if (*fdir_filter_count) {
  3180. netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
  3181. i40e_flow_str(fsp),
  3182. *fdir_filter_count);
  3183. return -EOPNOTSUPP;
  3184. }
  3185. i40e_write_fd_input_set(pf, index, new_mask);
  3186. /* Add the new offset and update table, if necessary */
  3187. if (new_flex_offset) {
  3188. err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
  3189. pit_index);
  3190. if (err)
  3191. return err;
  3192. if (flex_l3) {
  3193. err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
  3194. src_offset,
  3195. pit_index);
  3196. if (err)
  3197. return err;
  3198. }
  3199. i40e_reprogram_flex_pit(pf);
  3200. }
  3201. return 0;
  3202. }
  3203. /**
  3204. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  3205. * @vsi: pointer to the targeted VSI
  3206. * @cmd: command to get or set RX flow classification rules
  3207. *
  3208. * Add Flow Director filters for a specific flow spec based on their
  3209. * protocol. Returns 0 if the filters were successfully added.
  3210. **/
  3211. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  3212. struct ethtool_rxnfc *cmd)
  3213. {
  3214. struct i40e_rx_flow_userdef userdef;
  3215. struct ethtool_rx_flow_spec *fsp;
  3216. struct i40e_fdir_filter *input;
  3217. u16 dest_vsi = 0, q_index = 0;
  3218. struct i40e_pf *pf;
  3219. int ret = -EINVAL;
  3220. u8 dest_ctl;
  3221. if (!vsi)
  3222. return -EINVAL;
  3223. pf = vsi->back;
  3224. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  3225. return -EOPNOTSUPP;
  3226. if (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)
  3227. return -ENOSPC;
  3228. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  3229. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  3230. return -EBUSY;
  3231. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  3232. return -EBUSY;
  3233. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  3234. /* Parse the user-defined field */
  3235. if (i40e_parse_rx_flow_user_data(fsp, &userdef))
  3236. return -EINVAL;
  3237. /* Extended MAC field is not supported */
  3238. if (fsp->flow_type & FLOW_MAC_EXT)
  3239. return -EINVAL;
  3240. ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
  3241. if (ret)
  3242. return ret;
  3243. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  3244. pf->hw.func_caps.fd_filters_guaranteed)) {
  3245. return -EINVAL;
  3246. }
  3247. /* ring_cookie is either the drop index, or is a mask of the queue
  3248. * index and VF id we wish to target.
  3249. */
  3250. if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
  3251. dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  3252. } else {
  3253. u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
  3254. u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
  3255. if (!vf) {
  3256. if (ring >= vsi->num_queue_pairs)
  3257. return -EINVAL;
  3258. dest_vsi = vsi->id;
  3259. } else {
  3260. /* VFs are zero-indexed, so we subtract one here */
  3261. vf--;
  3262. if (vf >= pf->num_alloc_vfs)
  3263. return -EINVAL;
  3264. if (ring >= pf->vf[vf].num_queue_pairs)
  3265. return -EINVAL;
  3266. dest_vsi = pf->vf[vf].lan_vsi_id;
  3267. }
  3268. dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  3269. q_index = ring;
  3270. }
  3271. input = kzalloc(sizeof(*input), GFP_KERNEL);
  3272. if (!input)
  3273. return -ENOMEM;
  3274. input->fd_id = fsp->location;
  3275. input->q_index = q_index;
  3276. input->dest_vsi = dest_vsi;
  3277. input->dest_ctl = dest_ctl;
  3278. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  3279. input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  3280. input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
  3281. input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
  3282. input->flow_type = fsp->flow_type & ~FLOW_EXT;
  3283. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  3284. /* Reverse the src and dest notion, since the HW expects them to be from
  3285. * Tx perspective where as the input from user is from Rx filter view.
  3286. */
  3287. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  3288. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  3289. input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
  3290. input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
  3291. if (userdef.flex_filter) {
  3292. input->flex_filter = true;
  3293. input->flex_word = cpu_to_be16(userdef.flex_word);
  3294. input->flex_offset = userdef.flex_offset;
  3295. }
  3296. ret = i40e_add_del_fdir(vsi, input, true);
  3297. if (ret)
  3298. goto free_input;
  3299. /* Add the input filter to the fdir_input_list, possibly replacing
  3300. * a previous filter. Do not free the input structure after adding it
  3301. * to the list as this would cause a use-after-free bug.
  3302. */
  3303. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  3304. return 0;
  3305. free_input:
  3306. kfree(input);
  3307. return ret;
  3308. }
  3309. /**
  3310. * i40e_set_rxnfc - command to set RX flow classification rules
  3311. * @netdev: network interface device structure
  3312. * @cmd: ethtool rxnfc command
  3313. *
  3314. * Returns Success if the command is supported.
  3315. **/
  3316. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  3317. {
  3318. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3319. struct i40e_vsi *vsi = np->vsi;
  3320. struct i40e_pf *pf = vsi->back;
  3321. int ret = -EOPNOTSUPP;
  3322. switch (cmd->cmd) {
  3323. case ETHTOOL_SRXFH:
  3324. ret = i40e_set_rss_hash_opt(pf, cmd);
  3325. break;
  3326. case ETHTOOL_SRXCLSRLINS:
  3327. ret = i40e_add_fdir_ethtool(vsi, cmd);
  3328. break;
  3329. case ETHTOOL_SRXCLSRLDEL:
  3330. ret = i40e_del_fdir_entry(vsi, cmd);
  3331. break;
  3332. default:
  3333. break;
  3334. }
  3335. return ret;
  3336. }
  3337. /**
  3338. * i40e_max_channels - get Max number of combined channels supported
  3339. * @vsi: vsi pointer
  3340. **/
  3341. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  3342. {
  3343. /* TODO: This code assumes DCB and FD is disabled for now. */
  3344. return vsi->alloc_queue_pairs;
  3345. }
  3346. /**
  3347. * i40e_get_channels - Get the current channels enabled and max supported etc.
  3348. * @netdev: network interface device structure
  3349. * @ch: ethtool channels structure
  3350. *
  3351. * We don't support separate tx and rx queues as channels. The other count
  3352. * represents how many queues are being used for control. max_combined counts
  3353. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  3354. * q_vectors since we support a lot more queue pairs than q_vectors.
  3355. **/
  3356. static void i40e_get_channels(struct net_device *dev,
  3357. struct ethtool_channels *ch)
  3358. {
  3359. struct i40e_netdev_priv *np = netdev_priv(dev);
  3360. struct i40e_vsi *vsi = np->vsi;
  3361. struct i40e_pf *pf = vsi->back;
  3362. /* report maximum channels */
  3363. ch->max_combined = i40e_max_channels(vsi);
  3364. /* report info for other vector */
  3365. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  3366. ch->max_other = ch->other_count;
  3367. /* Note: This code assumes DCB is disabled for now. */
  3368. ch->combined_count = vsi->num_queue_pairs;
  3369. }
  3370. /**
  3371. * i40e_set_channels - Set the new channels count.
  3372. * @netdev: network interface device structure
  3373. * @ch: ethtool channels structure
  3374. *
  3375. * The new channels count may not be the same as requested by the user
  3376. * since it gets rounded down to a power of 2 value.
  3377. **/
  3378. static int i40e_set_channels(struct net_device *dev,
  3379. struct ethtool_channels *ch)
  3380. {
  3381. const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  3382. struct i40e_netdev_priv *np = netdev_priv(dev);
  3383. unsigned int count = ch->combined_count;
  3384. struct i40e_vsi *vsi = np->vsi;
  3385. struct i40e_pf *pf = vsi->back;
  3386. struct i40e_fdir_filter *rule;
  3387. struct hlist_node *node2;
  3388. int new_count;
  3389. int err = 0;
  3390. /* We do not support setting channels for any other VSI at present */
  3391. if (vsi->type != I40E_VSI_MAIN)
  3392. return -EINVAL;
  3393. /* verify they are not requesting separate vectors */
  3394. if (!count || ch->rx_count || ch->tx_count)
  3395. return -EINVAL;
  3396. /* verify other_count has not changed */
  3397. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  3398. return -EINVAL;
  3399. /* verify the number of channels does not exceed hardware limits */
  3400. if (count > i40e_max_channels(vsi))
  3401. return -EINVAL;
  3402. /* verify that the number of channels does not invalidate any current
  3403. * flow director rules
  3404. */
  3405. hlist_for_each_entry_safe(rule, node2,
  3406. &pf->fdir_filter_list, fdir_node) {
  3407. if (rule->dest_ctl != drop && count <= rule->q_index) {
  3408. dev_warn(&pf->pdev->dev,
  3409. "Existing user defined filter %d assigns flow to queue %d\n",
  3410. rule->fd_id, rule->q_index);
  3411. err = -EINVAL;
  3412. }
  3413. }
  3414. if (err) {
  3415. dev_err(&pf->pdev->dev,
  3416. "Existing filter rules must be deleted to reduce combined channel count to %d\n",
  3417. count);
  3418. return err;
  3419. }
  3420. /* update feature limits from largest to smallest supported values */
  3421. /* TODO: Flow director limit, DCB etc */
  3422. /* use rss_reconfig to rebuild with new queue count and update traffic
  3423. * class queue mapping
  3424. */
  3425. new_count = i40e_reconfig_rss_queues(pf, count);
  3426. if (new_count > 0)
  3427. return 0;
  3428. else
  3429. return -EINVAL;
  3430. }
  3431. /**
  3432. * i40e_get_rxfh_key_size - get the RSS hash key size
  3433. * @netdev: network interface device structure
  3434. *
  3435. * Returns the table size.
  3436. **/
  3437. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  3438. {
  3439. return I40E_HKEY_ARRAY_SIZE;
  3440. }
  3441. /**
  3442. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  3443. * @netdev: network interface device structure
  3444. *
  3445. * Returns the table size.
  3446. **/
  3447. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  3448. {
  3449. return I40E_HLUT_ARRAY_SIZE;
  3450. }
  3451. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  3452. u8 *hfunc)
  3453. {
  3454. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3455. struct i40e_vsi *vsi = np->vsi;
  3456. u8 *lut, *seed = NULL;
  3457. int ret;
  3458. u16 i;
  3459. if (hfunc)
  3460. *hfunc = ETH_RSS_HASH_TOP;
  3461. if (!indir)
  3462. return 0;
  3463. seed = key;
  3464. lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  3465. if (!lut)
  3466. return -ENOMEM;
  3467. ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
  3468. if (ret)
  3469. goto out;
  3470. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  3471. indir[i] = (u32)(lut[i]);
  3472. out:
  3473. kfree(lut);
  3474. return ret;
  3475. }
  3476. /**
  3477. * i40e_set_rxfh - set the rx flow hash indirection table
  3478. * @netdev: network interface device structure
  3479. * @indir: indirection table
  3480. * @key: hash key
  3481. *
  3482. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  3483. * returns 0 after programming the table.
  3484. **/
  3485. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  3486. const u8 *key, const u8 hfunc)
  3487. {
  3488. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3489. struct i40e_vsi *vsi = np->vsi;
  3490. struct i40e_pf *pf = vsi->back;
  3491. u8 *seed = NULL;
  3492. u16 i;
  3493. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  3494. return -EOPNOTSUPP;
  3495. if (key) {
  3496. if (!vsi->rss_hkey_user) {
  3497. vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
  3498. GFP_KERNEL);
  3499. if (!vsi->rss_hkey_user)
  3500. return -ENOMEM;
  3501. }
  3502. memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
  3503. seed = vsi->rss_hkey_user;
  3504. }
  3505. if (!vsi->rss_lut_user) {
  3506. vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  3507. if (!vsi->rss_lut_user)
  3508. return -ENOMEM;
  3509. }
  3510. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  3511. if (indir)
  3512. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  3513. vsi->rss_lut_user[i] = (u8)(indir[i]);
  3514. else
  3515. i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
  3516. vsi->rss_size);
  3517. return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
  3518. I40E_HLUT_ARRAY_SIZE);
  3519. }
  3520. /**
  3521. * i40e_get_priv_flags - report device private flags
  3522. * @dev: network interface device structure
  3523. *
  3524. * The get string set count and the string set should be matched for each
  3525. * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
  3526. * array.
  3527. *
  3528. * Returns a u32 bitmap of flags.
  3529. **/
  3530. static u32 i40e_get_priv_flags(struct net_device *dev)
  3531. {
  3532. struct i40e_netdev_priv *np = netdev_priv(dev);
  3533. struct i40e_vsi *vsi = np->vsi;
  3534. struct i40e_pf *pf = vsi->back;
  3535. u32 i, j, ret_flags = 0;
  3536. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  3537. const struct i40e_priv_flags *priv_flags;
  3538. priv_flags = &i40e_gstrings_priv_flags[i];
  3539. if (priv_flags->flag & pf->flags)
  3540. ret_flags |= BIT(i);
  3541. }
  3542. if (pf->hw.pf_id != 0)
  3543. return ret_flags;
  3544. for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
  3545. const struct i40e_priv_flags *priv_flags;
  3546. priv_flags = &i40e_gl_gstrings_priv_flags[j];
  3547. if (priv_flags->flag & pf->flags)
  3548. ret_flags |= BIT(i + j);
  3549. }
  3550. return ret_flags;
  3551. }
  3552. /**
  3553. * i40e_set_priv_flags - set private flags
  3554. * @dev: network interface device structure
  3555. * @flags: bit flags to be set
  3556. **/
  3557. static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
  3558. {
  3559. struct i40e_netdev_priv *np = netdev_priv(dev);
  3560. struct i40e_vsi *vsi = np->vsi;
  3561. struct i40e_pf *pf = vsi->back;
  3562. u64 changed_flags;
  3563. u32 i, j;
  3564. changed_flags = pf->flags;
  3565. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  3566. const struct i40e_priv_flags *priv_flags;
  3567. priv_flags = &i40e_gstrings_priv_flags[i];
  3568. if (priv_flags->read_only)
  3569. continue;
  3570. if (flags & BIT(i))
  3571. pf->flags |= priv_flags->flag;
  3572. else
  3573. pf->flags &= ~(priv_flags->flag);
  3574. }
  3575. if (pf->hw.pf_id != 0)
  3576. goto flags_complete;
  3577. for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
  3578. const struct i40e_priv_flags *priv_flags;
  3579. priv_flags = &i40e_gl_gstrings_priv_flags[j];
  3580. if (priv_flags->read_only)
  3581. continue;
  3582. if (flags & BIT(i + j))
  3583. pf->flags |= priv_flags->flag;
  3584. else
  3585. pf->flags &= ~(priv_flags->flag);
  3586. }
  3587. flags_complete:
  3588. /* check for flags that changed */
  3589. changed_flags ^= pf->flags;
  3590. /* Process any additional changes needed as a result of flag changes.
  3591. * The changed_flags value reflects the list of bits that were
  3592. * changed in the code above.
  3593. */
  3594. /* Flush current ATR settings if ATR was disabled */
  3595. if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
  3596. !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
  3597. pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED;
  3598. set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  3599. }
  3600. /* Only allow ATR evict on hardware that is capable of handling it */
  3601. if (pf->hw_disabled_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE)
  3602. pf->flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  3603. if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
  3604. u16 sw_flags = 0, valid_flags = 0;
  3605. int ret;
  3606. if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  3607. sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  3608. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  3609. ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
  3610. NULL);
  3611. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  3612. dev_info(&pf->pdev->dev,
  3613. "couldn't set switch config bits, err %s aq_err %s\n",
  3614. i40e_stat_str(&pf->hw, ret),
  3615. i40e_aq_str(&pf->hw,
  3616. pf->hw.aq.asq_last_status));
  3617. /* not a fatal problem, just keep going */
  3618. }
  3619. }
  3620. /* Issue reset to cause things to take effect, as additional bits
  3621. * are added we will need to create a mask of bits requiring reset
  3622. */
  3623. if ((changed_flags & I40E_FLAG_VEB_STATS_ENABLED) ||
  3624. ((changed_flags & I40E_FLAG_LEGACY_RX) && netif_running(dev)))
  3625. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  3626. return 0;
  3627. }
  3628. static const struct ethtool_ops i40e_ethtool_ops = {
  3629. .get_drvinfo = i40e_get_drvinfo,
  3630. .get_regs_len = i40e_get_regs_len,
  3631. .get_regs = i40e_get_regs,
  3632. .nway_reset = i40e_nway_reset,
  3633. .get_link = ethtool_op_get_link,
  3634. .get_wol = i40e_get_wol,
  3635. .set_wol = i40e_set_wol,
  3636. .set_eeprom = i40e_set_eeprom,
  3637. .get_eeprom_len = i40e_get_eeprom_len,
  3638. .get_eeprom = i40e_get_eeprom,
  3639. .get_ringparam = i40e_get_ringparam,
  3640. .set_ringparam = i40e_set_ringparam,
  3641. .get_pauseparam = i40e_get_pauseparam,
  3642. .set_pauseparam = i40e_set_pauseparam,
  3643. .get_msglevel = i40e_get_msglevel,
  3644. .set_msglevel = i40e_set_msglevel,
  3645. .get_rxnfc = i40e_get_rxnfc,
  3646. .set_rxnfc = i40e_set_rxnfc,
  3647. .self_test = i40e_diag_test,
  3648. .get_strings = i40e_get_strings,
  3649. .set_phys_id = i40e_set_phys_id,
  3650. .get_sset_count = i40e_get_sset_count,
  3651. .get_ethtool_stats = i40e_get_ethtool_stats,
  3652. .get_coalesce = i40e_get_coalesce,
  3653. .set_coalesce = i40e_set_coalesce,
  3654. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  3655. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  3656. .get_rxfh = i40e_get_rxfh,
  3657. .set_rxfh = i40e_set_rxfh,
  3658. .get_channels = i40e_get_channels,
  3659. .set_channels = i40e_set_channels,
  3660. .get_ts_info = i40e_get_ts_info,
  3661. .get_priv_flags = i40e_get_priv_flags,
  3662. .set_priv_flags = i40e_set_priv_flags,
  3663. .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
  3664. .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
  3665. .get_link_ksettings = i40e_get_link_ksettings,
  3666. .set_link_ksettings = i40e_set_link_ksettings,
  3667. };
  3668. void i40e_set_ethtool_ops(struct net_device *netdev)
  3669. {
  3670. netdev->ethtool_ops = &i40e_ethtool_ops;
  3671. }