i40e_ethtool.c 148 KB

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