i40e_ethtool.c 123 KB

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