i40e_ethtool.c 138 KB

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