i40e_ethtool.c 145 KB

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