i40e_ethtool.c 143 KB

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