i40e_common.c 164 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include "i40e_type.h"
  27. #include "i40e_adminq.h"
  28. #include "i40e_prototype.h"
  29. #include <linux/avf/virtchnl.h>
  30. /**
  31. * i40e_set_mac_type - Sets MAC type
  32. * @hw: pointer to the HW structure
  33. *
  34. * This function sets the mac type of the adapter based on the
  35. * vendor ID and device ID stored in the hw structure.
  36. **/
  37. static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
  38. {
  39. i40e_status status = 0;
  40. if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
  41. switch (hw->device_id) {
  42. case I40E_DEV_ID_SFP_XL710:
  43. case I40E_DEV_ID_QEMU:
  44. case I40E_DEV_ID_KX_B:
  45. case I40E_DEV_ID_KX_C:
  46. case I40E_DEV_ID_QSFP_A:
  47. case I40E_DEV_ID_QSFP_B:
  48. case I40E_DEV_ID_QSFP_C:
  49. case I40E_DEV_ID_10G_BASE_T:
  50. case I40E_DEV_ID_10G_BASE_T4:
  51. case I40E_DEV_ID_20G_KR2:
  52. case I40E_DEV_ID_20G_KR2_A:
  53. case I40E_DEV_ID_25G_B:
  54. case I40E_DEV_ID_25G_SFP28:
  55. hw->mac.type = I40E_MAC_XL710;
  56. break;
  57. case I40E_DEV_ID_KX_X722:
  58. case I40E_DEV_ID_QSFP_X722:
  59. case I40E_DEV_ID_SFP_X722:
  60. case I40E_DEV_ID_1G_BASE_T_X722:
  61. case I40E_DEV_ID_10G_BASE_T_X722:
  62. case I40E_DEV_ID_SFP_I_X722:
  63. hw->mac.type = I40E_MAC_X722;
  64. break;
  65. default:
  66. hw->mac.type = I40E_MAC_GENERIC;
  67. break;
  68. }
  69. } else {
  70. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  71. }
  72. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  73. hw->mac.type, status);
  74. return status;
  75. }
  76. /**
  77. * i40e_aq_str - convert AQ err code to a string
  78. * @hw: pointer to the HW structure
  79. * @aq_err: the AQ error code to convert
  80. **/
  81. const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
  82. {
  83. switch (aq_err) {
  84. case I40E_AQ_RC_OK:
  85. return "OK";
  86. case I40E_AQ_RC_EPERM:
  87. return "I40E_AQ_RC_EPERM";
  88. case I40E_AQ_RC_ENOENT:
  89. return "I40E_AQ_RC_ENOENT";
  90. case I40E_AQ_RC_ESRCH:
  91. return "I40E_AQ_RC_ESRCH";
  92. case I40E_AQ_RC_EINTR:
  93. return "I40E_AQ_RC_EINTR";
  94. case I40E_AQ_RC_EIO:
  95. return "I40E_AQ_RC_EIO";
  96. case I40E_AQ_RC_ENXIO:
  97. return "I40E_AQ_RC_ENXIO";
  98. case I40E_AQ_RC_E2BIG:
  99. return "I40E_AQ_RC_E2BIG";
  100. case I40E_AQ_RC_EAGAIN:
  101. return "I40E_AQ_RC_EAGAIN";
  102. case I40E_AQ_RC_ENOMEM:
  103. return "I40E_AQ_RC_ENOMEM";
  104. case I40E_AQ_RC_EACCES:
  105. return "I40E_AQ_RC_EACCES";
  106. case I40E_AQ_RC_EFAULT:
  107. return "I40E_AQ_RC_EFAULT";
  108. case I40E_AQ_RC_EBUSY:
  109. return "I40E_AQ_RC_EBUSY";
  110. case I40E_AQ_RC_EEXIST:
  111. return "I40E_AQ_RC_EEXIST";
  112. case I40E_AQ_RC_EINVAL:
  113. return "I40E_AQ_RC_EINVAL";
  114. case I40E_AQ_RC_ENOTTY:
  115. return "I40E_AQ_RC_ENOTTY";
  116. case I40E_AQ_RC_ENOSPC:
  117. return "I40E_AQ_RC_ENOSPC";
  118. case I40E_AQ_RC_ENOSYS:
  119. return "I40E_AQ_RC_ENOSYS";
  120. case I40E_AQ_RC_ERANGE:
  121. return "I40E_AQ_RC_ERANGE";
  122. case I40E_AQ_RC_EFLUSHED:
  123. return "I40E_AQ_RC_EFLUSHED";
  124. case I40E_AQ_RC_BAD_ADDR:
  125. return "I40E_AQ_RC_BAD_ADDR";
  126. case I40E_AQ_RC_EMODE:
  127. return "I40E_AQ_RC_EMODE";
  128. case I40E_AQ_RC_EFBIG:
  129. return "I40E_AQ_RC_EFBIG";
  130. }
  131. snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
  132. return hw->err_str;
  133. }
  134. /**
  135. * i40e_stat_str - convert status err code to a string
  136. * @hw: pointer to the HW structure
  137. * @stat_err: the status error code to convert
  138. **/
  139. const char *i40e_stat_str(struct i40e_hw *hw, i40e_status stat_err)
  140. {
  141. switch (stat_err) {
  142. case 0:
  143. return "OK";
  144. case I40E_ERR_NVM:
  145. return "I40E_ERR_NVM";
  146. case I40E_ERR_NVM_CHECKSUM:
  147. return "I40E_ERR_NVM_CHECKSUM";
  148. case I40E_ERR_PHY:
  149. return "I40E_ERR_PHY";
  150. case I40E_ERR_CONFIG:
  151. return "I40E_ERR_CONFIG";
  152. case I40E_ERR_PARAM:
  153. return "I40E_ERR_PARAM";
  154. case I40E_ERR_MAC_TYPE:
  155. return "I40E_ERR_MAC_TYPE";
  156. case I40E_ERR_UNKNOWN_PHY:
  157. return "I40E_ERR_UNKNOWN_PHY";
  158. case I40E_ERR_LINK_SETUP:
  159. return "I40E_ERR_LINK_SETUP";
  160. case I40E_ERR_ADAPTER_STOPPED:
  161. return "I40E_ERR_ADAPTER_STOPPED";
  162. case I40E_ERR_INVALID_MAC_ADDR:
  163. return "I40E_ERR_INVALID_MAC_ADDR";
  164. case I40E_ERR_DEVICE_NOT_SUPPORTED:
  165. return "I40E_ERR_DEVICE_NOT_SUPPORTED";
  166. case I40E_ERR_MASTER_REQUESTS_PENDING:
  167. return "I40E_ERR_MASTER_REQUESTS_PENDING";
  168. case I40E_ERR_INVALID_LINK_SETTINGS:
  169. return "I40E_ERR_INVALID_LINK_SETTINGS";
  170. case I40E_ERR_AUTONEG_NOT_COMPLETE:
  171. return "I40E_ERR_AUTONEG_NOT_COMPLETE";
  172. case I40E_ERR_RESET_FAILED:
  173. return "I40E_ERR_RESET_FAILED";
  174. case I40E_ERR_SWFW_SYNC:
  175. return "I40E_ERR_SWFW_SYNC";
  176. case I40E_ERR_NO_AVAILABLE_VSI:
  177. return "I40E_ERR_NO_AVAILABLE_VSI";
  178. case I40E_ERR_NO_MEMORY:
  179. return "I40E_ERR_NO_MEMORY";
  180. case I40E_ERR_BAD_PTR:
  181. return "I40E_ERR_BAD_PTR";
  182. case I40E_ERR_RING_FULL:
  183. return "I40E_ERR_RING_FULL";
  184. case I40E_ERR_INVALID_PD_ID:
  185. return "I40E_ERR_INVALID_PD_ID";
  186. case I40E_ERR_INVALID_QP_ID:
  187. return "I40E_ERR_INVALID_QP_ID";
  188. case I40E_ERR_INVALID_CQ_ID:
  189. return "I40E_ERR_INVALID_CQ_ID";
  190. case I40E_ERR_INVALID_CEQ_ID:
  191. return "I40E_ERR_INVALID_CEQ_ID";
  192. case I40E_ERR_INVALID_AEQ_ID:
  193. return "I40E_ERR_INVALID_AEQ_ID";
  194. case I40E_ERR_INVALID_SIZE:
  195. return "I40E_ERR_INVALID_SIZE";
  196. case I40E_ERR_INVALID_ARP_INDEX:
  197. return "I40E_ERR_INVALID_ARP_INDEX";
  198. case I40E_ERR_INVALID_FPM_FUNC_ID:
  199. return "I40E_ERR_INVALID_FPM_FUNC_ID";
  200. case I40E_ERR_QP_INVALID_MSG_SIZE:
  201. return "I40E_ERR_QP_INVALID_MSG_SIZE";
  202. case I40E_ERR_QP_TOOMANY_WRS_POSTED:
  203. return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
  204. case I40E_ERR_INVALID_FRAG_COUNT:
  205. return "I40E_ERR_INVALID_FRAG_COUNT";
  206. case I40E_ERR_QUEUE_EMPTY:
  207. return "I40E_ERR_QUEUE_EMPTY";
  208. case I40E_ERR_INVALID_ALIGNMENT:
  209. return "I40E_ERR_INVALID_ALIGNMENT";
  210. case I40E_ERR_FLUSHED_QUEUE:
  211. return "I40E_ERR_FLUSHED_QUEUE";
  212. case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
  213. return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
  214. case I40E_ERR_INVALID_IMM_DATA_SIZE:
  215. return "I40E_ERR_INVALID_IMM_DATA_SIZE";
  216. case I40E_ERR_TIMEOUT:
  217. return "I40E_ERR_TIMEOUT";
  218. case I40E_ERR_OPCODE_MISMATCH:
  219. return "I40E_ERR_OPCODE_MISMATCH";
  220. case I40E_ERR_CQP_COMPL_ERROR:
  221. return "I40E_ERR_CQP_COMPL_ERROR";
  222. case I40E_ERR_INVALID_VF_ID:
  223. return "I40E_ERR_INVALID_VF_ID";
  224. case I40E_ERR_INVALID_HMCFN_ID:
  225. return "I40E_ERR_INVALID_HMCFN_ID";
  226. case I40E_ERR_BACKING_PAGE_ERROR:
  227. return "I40E_ERR_BACKING_PAGE_ERROR";
  228. case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
  229. return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
  230. case I40E_ERR_INVALID_PBLE_INDEX:
  231. return "I40E_ERR_INVALID_PBLE_INDEX";
  232. case I40E_ERR_INVALID_SD_INDEX:
  233. return "I40E_ERR_INVALID_SD_INDEX";
  234. case I40E_ERR_INVALID_PAGE_DESC_INDEX:
  235. return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
  236. case I40E_ERR_INVALID_SD_TYPE:
  237. return "I40E_ERR_INVALID_SD_TYPE";
  238. case I40E_ERR_MEMCPY_FAILED:
  239. return "I40E_ERR_MEMCPY_FAILED";
  240. case I40E_ERR_INVALID_HMC_OBJ_INDEX:
  241. return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
  242. case I40E_ERR_INVALID_HMC_OBJ_COUNT:
  243. return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
  244. case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
  245. return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
  246. case I40E_ERR_SRQ_ENABLED:
  247. return "I40E_ERR_SRQ_ENABLED";
  248. case I40E_ERR_ADMIN_QUEUE_ERROR:
  249. return "I40E_ERR_ADMIN_QUEUE_ERROR";
  250. case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
  251. return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
  252. case I40E_ERR_BUF_TOO_SHORT:
  253. return "I40E_ERR_BUF_TOO_SHORT";
  254. case I40E_ERR_ADMIN_QUEUE_FULL:
  255. return "I40E_ERR_ADMIN_QUEUE_FULL";
  256. case I40E_ERR_ADMIN_QUEUE_NO_WORK:
  257. return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
  258. case I40E_ERR_BAD_IWARP_CQE:
  259. return "I40E_ERR_BAD_IWARP_CQE";
  260. case I40E_ERR_NVM_BLANK_MODE:
  261. return "I40E_ERR_NVM_BLANK_MODE";
  262. case I40E_ERR_NOT_IMPLEMENTED:
  263. return "I40E_ERR_NOT_IMPLEMENTED";
  264. case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
  265. return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
  266. case I40E_ERR_DIAG_TEST_FAILED:
  267. return "I40E_ERR_DIAG_TEST_FAILED";
  268. case I40E_ERR_NOT_READY:
  269. return "I40E_ERR_NOT_READY";
  270. case I40E_NOT_SUPPORTED:
  271. return "I40E_NOT_SUPPORTED";
  272. case I40E_ERR_FIRMWARE_API_VERSION:
  273. return "I40E_ERR_FIRMWARE_API_VERSION";
  274. }
  275. snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
  276. return hw->err_str;
  277. }
  278. /**
  279. * i40e_debug_aq
  280. * @hw: debug mask related to admin queue
  281. * @mask: debug mask
  282. * @desc: pointer to admin queue descriptor
  283. * @buffer: pointer to command buffer
  284. * @buf_len: max length of buffer
  285. *
  286. * Dumps debug log about adminq command with descriptor contents.
  287. **/
  288. void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  289. void *buffer, u16 buf_len)
  290. {
  291. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  292. u16 len;
  293. u8 *buf = (u8 *)buffer;
  294. if ((!(mask & hw->debug_mask)) || (desc == NULL))
  295. return;
  296. len = le16_to_cpu(aq_desc->datalen);
  297. i40e_debug(hw, mask,
  298. "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  299. le16_to_cpu(aq_desc->opcode),
  300. le16_to_cpu(aq_desc->flags),
  301. le16_to_cpu(aq_desc->datalen),
  302. le16_to_cpu(aq_desc->retval));
  303. i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  304. le32_to_cpu(aq_desc->cookie_high),
  305. le32_to_cpu(aq_desc->cookie_low));
  306. i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  307. le32_to_cpu(aq_desc->params.internal.param0),
  308. le32_to_cpu(aq_desc->params.internal.param1));
  309. i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  310. le32_to_cpu(aq_desc->params.external.addr_high),
  311. le32_to_cpu(aq_desc->params.external.addr_low));
  312. if ((buffer != NULL) && (aq_desc->datalen != 0)) {
  313. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  314. if (buf_len < len)
  315. len = buf_len;
  316. /* write the full 16-byte chunks */
  317. if (hw->debug_mask & mask) {
  318. char prefix[27];
  319. snprintf(prefix, sizeof(prefix),
  320. "i40e %02x:%02x.%x: \t0x",
  321. hw->bus.bus_id,
  322. hw->bus.device,
  323. hw->bus.func);
  324. print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
  325. 16, 1, buf, len, false);
  326. }
  327. }
  328. }
  329. /**
  330. * i40e_check_asq_alive
  331. * @hw: pointer to the hw struct
  332. *
  333. * Returns true if Queue is enabled else false.
  334. **/
  335. bool i40e_check_asq_alive(struct i40e_hw *hw)
  336. {
  337. if (hw->aq.asq.len)
  338. return !!(rd32(hw, hw->aq.asq.len) &
  339. I40E_PF_ATQLEN_ATQENABLE_MASK);
  340. else
  341. return false;
  342. }
  343. /**
  344. * i40e_aq_queue_shutdown
  345. * @hw: pointer to the hw struct
  346. * @unloading: is the driver unloading itself
  347. *
  348. * Tell the Firmware that we're shutting down the AdminQ and whether
  349. * or not the driver is unloading as well.
  350. **/
  351. i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
  352. bool unloading)
  353. {
  354. struct i40e_aq_desc desc;
  355. struct i40e_aqc_queue_shutdown *cmd =
  356. (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
  357. i40e_status status;
  358. i40e_fill_default_direct_cmd_desc(&desc,
  359. i40e_aqc_opc_queue_shutdown);
  360. if (unloading)
  361. cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
  362. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  363. return status;
  364. }
  365. /**
  366. * i40e_aq_get_set_rss_lut
  367. * @hw: pointer to the hardware structure
  368. * @vsi_id: vsi fw index
  369. * @pf_lut: for PF table set true, for VSI table set false
  370. * @lut: pointer to the lut buffer provided by the caller
  371. * @lut_size: size of the lut buffer
  372. * @set: set true to set the table, false to get the table
  373. *
  374. * Internal function to get or set RSS look up table
  375. **/
  376. static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
  377. u16 vsi_id, bool pf_lut,
  378. u8 *lut, u16 lut_size,
  379. bool set)
  380. {
  381. i40e_status status;
  382. struct i40e_aq_desc desc;
  383. struct i40e_aqc_get_set_rss_lut *cmd_resp =
  384. (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
  385. if (set)
  386. i40e_fill_default_direct_cmd_desc(&desc,
  387. i40e_aqc_opc_set_rss_lut);
  388. else
  389. i40e_fill_default_direct_cmd_desc(&desc,
  390. i40e_aqc_opc_get_rss_lut);
  391. /* Indirect command */
  392. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  393. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  394. cmd_resp->vsi_id =
  395. cpu_to_le16((u16)((vsi_id <<
  396. I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
  397. I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
  398. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
  399. if (pf_lut)
  400. cmd_resp->flags |= cpu_to_le16((u16)
  401. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
  402. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  403. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  404. else
  405. cmd_resp->flags |= cpu_to_le16((u16)
  406. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
  407. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  408. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  409. status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
  410. return status;
  411. }
  412. /**
  413. * i40e_aq_get_rss_lut
  414. * @hw: pointer to the hardware structure
  415. * @vsi_id: vsi fw index
  416. * @pf_lut: for PF table set true, for VSI table set false
  417. * @lut: pointer to the lut buffer provided by the caller
  418. * @lut_size: size of the lut buffer
  419. *
  420. * get the RSS lookup table, PF or VSI type
  421. **/
  422. i40e_status i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
  423. bool pf_lut, u8 *lut, u16 lut_size)
  424. {
  425. return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
  426. false);
  427. }
  428. /**
  429. * i40e_aq_set_rss_lut
  430. * @hw: pointer to the hardware structure
  431. * @vsi_id: vsi fw index
  432. * @pf_lut: for PF table set true, for VSI table set false
  433. * @lut: pointer to the lut buffer provided by the caller
  434. * @lut_size: size of the lut buffer
  435. *
  436. * set the RSS lookup table, PF or VSI type
  437. **/
  438. i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
  439. bool pf_lut, u8 *lut, u16 lut_size)
  440. {
  441. return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
  442. }
  443. /**
  444. * i40e_aq_get_set_rss_key
  445. * @hw: pointer to the hw struct
  446. * @vsi_id: vsi fw index
  447. * @key: pointer to key info struct
  448. * @set: set true to set the key, false to get the key
  449. *
  450. * get the RSS key per VSI
  451. **/
  452. static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
  453. u16 vsi_id,
  454. struct i40e_aqc_get_set_rss_key_data *key,
  455. bool set)
  456. {
  457. i40e_status status;
  458. struct i40e_aq_desc desc;
  459. struct i40e_aqc_get_set_rss_key *cmd_resp =
  460. (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
  461. u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
  462. if (set)
  463. i40e_fill_default_direct_cmd_desc(&desc,
  464. i40e_aqc_opc_set_rss_key);
  465. else
  466. i40e_fill_default_direct_cmd_desc(&desc,
  467. i40e_aqc_opc_get_rss_key);
  468. /* Indirect command */
  469. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  470. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  471. cmd_resp->vsi_id =
  472. cpu_to_le16((u16)((vsi_id <<
  473. I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
  474. I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
  475. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
  476. status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
  477. return status;
  478. }
  479. /**
  480. * i40e_aq_get_rss_key
  481. * @hw: pointer to the hw struct
  482. * @vsi_id: vsi fw index
  483. * @key: pointer to key info struct
  484. *
  485. **/
  486. i40e_status i40e_aq_get_rss_key(struct i40e_hw *hw,
  487. u16 vsi_id,
  488. struct i40e_aqc_get_set_rss_key_data *key)
  489. {
  490. return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
  491. }
  492. /**
  493. * i40e_aq_set_rss_key
  494. * @hw: pointer to the hw struct
  495. * @vsi_id: vsi fw index
  496. * @key: pointer to key info struct
  497. *
  498. * set the RSS key per VSI
  499. **/
  500. i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
  501. u16 vsi_id,
  502. struct i40e_aqc_get_set_rss_key_data *key)
  503. {
  504. return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
  505. }
  506. /* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
  507. * hardware to a bit-field that can be used by SW to more easily determine the
  508. * packet type.
  509. *
  510. * Macros are used to shorten the table lines and make this table human
  511. * readable.
  512. *
  513. * We store the PTYPE in the top byte of the bit field - this is just so that
  514. * we can check that the table doesn't have a row missing, as the index into
  515. * the table should be the PTYPE.
  516. *
  517. * Typical work flow:
  518. *
  519. * IF NOT i40e_ptype_lookup[ptype].known
  520. * THEN
  521. * Packet is unknown
  522. * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
  523. * Use the rest of the fields to look at the tunnels, inner protocols, etc
  524. * ELSE
  525. * Use the enum i40e_rx_l2_ptype to decode the packet type
  526. * ENDIF
  527. */
  528. /* macro to make the table lines short */
  529. #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
  530. { PTYPE, \
  531. 1, \
  532. I40E_RX_PTYPE_OUTER_##OUTER_IP, \
  533. I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
  534. I40E_RX_PTYPE_##OUTER_FRAG, \
  535. I40E_RX_PTYPE_TUNNEL_##T, \
  536. I40E_RX_PTYPE_TUNNEL_END_##TE, \
  537. I40E_RX_PTYPE_##TEF, \
  538. I40E_RX_PTYPE_INNER_PROT_##I, \
  539. I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
  540. #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
  541. { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  542. /* shorter macros makes the table fit but are terse */
  543. #define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
  544. #define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
  545. #define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
  546. /* Lookup table mapping the HW PTYPE to the bit field for decoding */
  547. struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
  548. /* L2 Packet types */
  549. I40E_PTT_UNUSED_ENTRY(0),
  550. I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  551. I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
  552. I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  553. I40E_PTT_UNUSED_ENTRY(4),
  554. I40E_PTT_UNUSED_ENTRY(5),
  555. I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  556. I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  557. I40E_PTT_UNUSED_ENTRY(8),
  558. I40E_PTT_UNUSED_ENTRY(9),
  559. I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  560. I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
  561. I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  562. I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  563. I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  564. I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  565. I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  566. I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  567. I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  568. I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  569. I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  570. I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  571. /* Non Tunneled IPv4 */
  572. I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
  573. I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
  574. I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
  575. I40E_PTT_UNUSED_ENTRY(25),
  576. I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
  577. I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
  578. I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
  579. /* IPv4 --> IPv4 */
  580. I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  581. I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  582. I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  583. I40E_PTT_UNUSED_ENTRY(32),
  584. I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  585. I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  586. I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  587. /* IPv4 --> IPv6 */
  588. I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  589. I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  590. I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  591. I40E_PTT_UNUSED_ENTRY(39),
  592. I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  593. I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  594. I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  595. /* IPv4 --> GRE/NAT */
  596. I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  597. /* IPv4 --> GRE/NAT --> IPv4 */
  598. I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  599. I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  600. I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  601. I40E_PTT_UNUSED_ENTRY(47),
  602. I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  603. I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  604. I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  605. /* IPv4 --> GRE/NAT --> IPv6 */
  606. I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  607. I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  608. I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  609. I40E_PTT_UNUSED_ENTRY(54),
  610. I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  611. I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  612. I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  613. /* IPv4 --> GRE/NAT --> MAC */
  614. I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  615. /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
  616. I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  617. I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  618. I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  619. I40E_PTT_UNUSED_ENTRY(62),
  620. I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  621. I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  622. I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  623. /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
  624. I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  625. I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  626. I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  627. I40E_PTT_UNUSED_ENTRY(69),
  628. I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  629. I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  630. I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  631. /* IPv4 --> GRE/NAT --> MAC/VLAN */
  632. I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  633. /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
  634. I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  635. I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  636. I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  637. I40E_PTT_UNUSED_ENTRY(77),
  638. I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  639. I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  640. I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  641. /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
  642. I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  643. I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  644. I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  645. I40E_PTT_UNUSED_ENTRY(84),
  646. I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  647. I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  648. I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  649. /* Non Tunneled IPv6 */
  650. I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
  651. I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
  652. I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY4),
  653. I40E_PTT_UNUSED_ENTRY(91),
  654. I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
  655. I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
  656. I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
  657. /* IPv6 --> IPv4 */
  658. I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  659. I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  660. I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  661. I40E_PTT_UNUSED_ENTRY(98),
  662. I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  663. I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  664. I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  665. /* IPv6 --> IPv6 */
  666. I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  667. I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  668. I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  669. I40E_PTT_UNUSED_ENTRY(105),
  670. I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  671. I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  672. I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  673. /* IPv6 --> GRE/NAT */
  674. I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  675. /* IPv6 --> GRE/NAT -> IPv4 */
  676. I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  677. I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  678. I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  679. I40E_PTT_UNUSED_ENTRY(113),
  680. I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  681. I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  682. I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  683. /* IPv6 --> GRE/NAT -> IPv6 */
  684. I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  685. I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  686. I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  687. I40E_PTT_UNUSED_ENTRY(120),
  688. I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  689. I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  690. I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  691. /* IPv6 --> GRE/NAT -> MAC */
  692. I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  693. /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
  694. I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  695. I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  696. I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  697. I40E_PTT_UNUSED_ENTRY(128),
  698. I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  699. I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  700. I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  701. /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
  702. I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  703. I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  704. I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  705. I40E_PTT_UNUSED_ENTRY(135),
  706. I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  707. I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  708. I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  709. /* IPv6 --> GRE/NAT -> MAC/VLAN */
  710. I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  711. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
  712. I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  713. I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  714. I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  715. I40E_PTT_UNUSED_ENTRY(143),
  716. I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  717. I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  718. I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  719. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
  720. I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  721. I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  722. I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  723. I40E_PTT_UNUSED_ENTRY(150),
  724. I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  725. I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  726. I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  727. /* unused entries */
  728. I40E_PTT_UNUSED_ENTRY(154),
  729. I40E_PTT_UNUSED_ENTRY(155),
  730. I40E_PTT_UNUSED_ENTRY(156),
  731. I40E_PTT_UNUSED_ENTRY(157),
  732. I40E_PTT_UNUSED_ENTRY(158),
  733. I40E_PTT_UNUSED_ENTRY(159),
  734. I40E_PTT_UNUSED_ENTRY(160),
  735. I40E_PTT_UNUSED_ENTRY(161),
  736. I40E_PTT_UNUSED_ENTRY(162),
  737. I40E_PTT_UNUSED_ENTRY(163),
  738. I40E_PTT_UNUSED_ENTRY(164),
  739. I40E_PTT_UNUSED_ENTRY(165),
  740. I40E_PTT_UNUSED_ENTRY(166),
  741. I40E_PTT_UNUSED_ENTRY(167),
  742. I40E_PTT_UNUSED_ENTRY(168),
  743. I40E_PTT_UNUSED_ENTRY(169),
  744. I40E_PTT_UNUSED_ENTRY(170),
  745. I40E_PTT_UNUSED_ENTRY(171),
  746. I40E_PTT_UNUSED_ENTRY(172),
  747. I40E_PTT_UNUSED_ENTRY(173),
  748. I40E_PTT_UNUSED_ENTRY(174),
  749. I40E_PTT_UNUSED_ENTRY(175),
  750. I40E_PTT_UNUSED_ENTRY(176),
  751. I40E_PTT_UNUSED_ENTRY(177),
  752. I40E_PTT_UNUSED_ENTRY(178),
  753. I40E_PTT_UNUSED_ENTRY(179),
  754. I40E_PTT_UNUSED_ENTRY(180),
  755. I40E_PTT_UNUSED_ENTRY(181),
  756. I40E_PTT_UNUSED_ENTRY(182),
  757. I40E_PTT_UNUSED_ENTRY(183),
  758. I40E_PTT_UNUSED_ENTRY(184),
  759. I40E_PTT_UNUSED_ENTRY(185),
  760. I40E_PTT_UNUSED_ENTRY(186),
  761. I40E_PTT_UNUSED_ENTRY(187),
  762. I40E_PTT_UNUSED_ENTRY(188),
  763. I40E_PTT_UNUSED_ENTRY(189),
  764. I40E_PTT_UNUSED_ENTRY(190),
  765. I40E_PTT_UNUSED_ENTRY(191),
  766. I40E_PTT_UNUSED_ENTRY(192),
  767. I40E_PTT_UNUSED_ENTRY(193),
  768. I40E_PTT_UNUSED_ENTRY(194),
  769. I40E_PTT_UNUSED_ENTRY(195),
  770. I40E_PTT_UNUSED_ENTRY(196),
  771. I40E_PTT_UNUSED_ENTRY(197),
  772. I40E_PTT_UNUSED_ENTRY(198),
  773. I40E_PTT_UNUSED_ENTRY(199),
  774. I40E_PTT_UNUSED_ENTRY(200),
  775. I40E_PTT_UNUSED_ENTRY(201),
  776. I40E_PTT_UNUSED_ENTRY(202),
  777. I40E_PTT_UNUSED_ENTRY(203),
  778. I40E_PTT_UNUSED_ENTRY(204),
  779. I40E_PTT_UNUSED_ENTRY(205),
  780. I40E_PTT_UNUSED_ENTRY(206),
  781. I40E_PTT_UNUSED_ENTRY(207),
  782. I40E_PTT_UNUSED_ENTRY(208),
  783. I40E_PTT_UNUSED_ENTRY(209),
  784. I40E_PTT_UNUSED_ENTRY(210),
  785. I40E_PTT_UNUSED_ENTRY(211),
  786. I40E_PTT_UNUSED_ENTRY(212),
  787. I40E_PTT_UNUSED_ENTRY(213),
  788. I40E_PTT_UNUSED_ENTRY(214),
  789. I40E_PTT_UNUSED_ENTRY(215),
  790. I40E_PTT_UNUSED_ENTRY(216),
  791. I40E_PTT_UNUSED_ENTRY(217),
  792. I40E_PTT_UNUSED_ENTRY(218),
  793. I40E_PTT_UNUSED_ENTRY(219),
  794. I40E_PTT_UNUSED_ENTRY(220),
  795. I40E_PTT_UNUSED_ENTRY(221),
  796. I40E_PTT_UNUSED_ENTRY(222),
  797. I40E_PTT_UNUSED_ENTRY(223),
  798. I40E_PTT_UNUSED_ENTRY(224),
  799. I40E_PTT_UNUSED_ENTRY(225),
  800. I40E_PTT_UNUSED_ENTRY(226),
  801. I40E_PTT_UNUSED_ENTRY(227),
  802. I40E_PTT_UNUSED_ENTRY(228),
  803. I40E_PTT_UNUSED_ENTRY(229),
  804. I40E_PTT_UNUSED_ENTRY(230),
  805. I40E_PTT_UNUSED_ENTRY(231),
  806. I40E_PTT_UNUSED_ENTRY(232),
  807. I40E_PTT_UNUSED_ENTRY(233),
  808. I40E_PTT_UNUSED_ENTRY(234),
  809. I40E_PTT_UNUSED_ENTRY(235),
  810. I40E_PTT_UNUSED_ENTRY(236),
  811. I40E_PTT_UNUSED_ENTRY(237),
  812. I40E_PTT_UNUSED_ENTRY(238),
  813. I40E_PTT_UNUSED_ENTRY(239),
  814. I40E_PTT_UNUSED_ENTRY(240),
  815. I40E_PTT_UNUSED_ENTRY(241),
  816. I40E_PTT_UNUSED_ENTRY(242),
  817. I40E_PTT_UNUSED_ENTRY(243),
  818. I40E_PTT_UNUSED_ENTRY(244),
  819. I40E_PTT_UNUSED_ENTRY(245),
  820. I40E_PTT_UNUSED_ENTRY(246),
  821. I40E_PTT_UNUSED_ENTRY(247),
  822. I40E_PTT_UNUSED_ENTRY(248),
  823. I40E_PTT_UNUSED_ENTRY(249),
  824. I40E_PTT_UNUSED_ENTRY(250),
  825. I40E_PTT_UNUSED_ENTRY(251),
  826. I40E_PTT_UNUSED_ENTRY(252),
  827. I40E_PTT_UNUSED_ENTRY(253),
  828. I40E_PTT_UNUSED_ENTRY(254),
  829. I40E_PTT_UNUSED_ENTRY(255)
  830. };
  831. /**
  832. * i40e_init_shared_code - Initialize the shared code
  833. * @hw: pointer to hardware structure
  834. *
  835. * This assigns the MAC type and PHY code and inits the NVM.
  836. * Does not touch the hardware. This function must be called prior to any
  837. * other function in the shared code. The i40e_hw structure should be
  838. * memset to 0 prior to calling this function. The following fields in
  839. * hw structure should be filled in prior to calling this function:
  840. * hw_addr, back, device_id, vendor_id, subsystem_device_id,
  841. * subsystem_vendor_id, and revision_id
  842. **/
  843. i40e_status i40e_init_shared_code(struct i40e_hw *hw)
  844. {
  845. i40e_status status = 0;
  846. u32 port, ari, func_rid;
  847. i40e_set_mac_type(hw);
  848. switch (hw->mac.type) {
  849. case I40E_MAC_XL710:
  850. case I40E_MAC_X722:
  851. break;
  852. default:
  853. return I40E_ERR_DEVICE_NOT_SUPPORTED;
  854. }
  855. hw->phy.get_link_info = true;
  856. /* Determine port number and PF number*/
  857. port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
  858. >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
  859. hw->port = (u8)port;
  860. ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
  861. I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
  862. func_rid = rd32(hw, I40E_PF_FUNC_RID);
  863. if (ari)
  864. hw->pf_id = (u8)(func_rid & 0xff);
  865. else
  866. hw->pf_id = (u8)(func_rid & 0x7);
  867. if (hw->mac.type == I40E_MAC_X722)
  868. hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
  869. I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
  870. status = i40e_init_nvm(hw);
  871. return status;
  872. }
  873. /**
  874. * i40e_aq_mac_address_read - Retrieve the MAC addresses
  875. * @hw: pointer to the hw struct
  876. * @flags: a return indicator of what addresses were added to the addr store
  877. * @addrs: the requestor's mac addr store
  878. * @cmd_details: pointer to command details structure or NULL
  879. **/
  880. static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
  881. u16 *flags,
  882. struct i40e_aqc_mac_address_read_data *addrs,
  883. struct i40e_asq_cmd_details *cmd_details)
  884. {
  885. struct i40e_aq_desc desc;
  886. struct i40e_aqc_mac_address_read *cmd_data =
  887. (struct i40e_aqc_mac_address_read *)&desc.params.raw;
  888. i40e_status status;
  889. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
  890. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
  891. status = i40e_asq_send_command(hw, &desc, addrs,
  892. sizeof(*addrs), cmd_details);
  893. *flags = le16_to_cpu(cmd_data->command_flags);
  894. return status;
  895. }
  896. /**
  897. * i40e_aq_mac_address_write - Change the MAC addresses
  898. * @hw: pointer to the hw struct
  899. * @flags: indicates which MAC to be written
  900. * @mac_addr: address to write
  901. * @cmd_details: pointer to command details structure or NULL
  902. **/
  903. i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
  904. u16 flags, u8 *mac_addr,
  905. struct i40e_asq_cmd_details *cmd_details)
  906. {
  907. struct i40e_aq_desc desc;
  908. struct i40e_aqc_mac_address_write *cmd_data =
  909. (struct i40e_aqc_mac_address_write *)&desc.params.raw;
  910. i40e_status status;
  911. i40e_fill_default_direct_cmd_desc(&desc,
  912. i40e_aqc_opc_mac_address_write);
  913. cmd_data->command_flags = cpu_to_le16(flags);
  914. cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
  915. cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
  916. ((u32)mac_addr[3] << 16) |
  917. ((u32)mac_addr[4] << 8) |
  918. mac_addr[5]);
  919. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  920. return status;
  921. }
  922. /**
  923. * i40e_get_mac_addr - get MAC address
  924. * @hw: pointer to the HW structure
  925. * @mac_addr: pointer to MAC address
  926. *
  927. * Reads the adapter's MAC address from register
  928. **/
  929. i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  930. {
  931. struct i40e_aqc_mac_address_read_data addrs;
  932. i40e_status status;
  933. u16 flags = 0;
  934. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  935. if (flags & I40E_AQC_LAN_ADDR_VALID)
  936. ether_addr_copy(mac_addr, addrs.pf_lan_mac);
  937. return status;
  938. }
  939. /**
  940. * i40e_get_port_mac_addr - get Port MAC address
  941. * @hw: pointer to the HW structure
  942. * @mac_addr: pointer to Port MAC address
  943. *
  944. * Reads the adapter's Port MAC address
  945. **/
  946. i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  947. {
  948. struct i40e_aqc_mac_address_read_data addrs;
  949. i40e_status status;
  950. u16 flags = 0;
  951. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  952. if (status)
  953. return status;
  954. if (flags & I40E_AQC_PORT_ADDR_VALID)
  955. ether_addr_copy(mac_addr, addrs.port_mac);
  956. else
  957. status = I40E_ERR_INVALID_MAC_ADDR;
  958. return status;
  959. }
  960. /**
  961. * i40e_pre_tx_queue_cfg - pre tx queue configure
  962. * @hw: pointer to the HW structure
  963. * @queue: target PF queue index
  964. * @enable: state change request
  965. *
  966. * Handles hw requirement to indicate intention to enable
  967. * or disable target queue.
  968. **/
  969. void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
  970. {
  971. u32 abs_queue_idx = hw->func_caps.base_queue + queue;
  972. u32 reg_block = 0;
  973. u32 reg_val;
  974. if (abs_queue_idx >= 128) {
  975. reg_block = abs_queue_idx / 128;
  976. abs_queue_idx %= 128;
  977. }
  978. reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
  979. reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
  980. reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
  981. if (enable)
  982. reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
  983. else
  984. reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
  985. wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
  986. }
  987. /**
  988. * i40e_read_pba_string - Reads part number string from EEPROM
  989. * @hw: pointer to hardware structure
  990. * @pba_num: stores the part number string from the EEPROM
  991. * @pba_num_size: part number string buffer length
  992. *
  993. * Reads the part number string from the EEPROM.
  994. **/
  995. i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
  996. u32 pba_num_size)
  997. {
  998. i40e_status status = 0;
  999. u16 pba_word = 0;
  1000. u16 pba_size = 0;
  1001. u16 pba_ptr = 0;
  1002. u16 i = 0;
  1003. status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
  1004. if (status || (pba_word != 0xFAFA)) {
  1005. hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
  1006. return status;
  1007. }
  1008. status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
  1009. if (status) {
  1010. hw_dbg(hw, "Failed to read PBA Block pointer.\n");
  1011. return status;
  1012. }
  1013. status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
  1014. if (status) {
  1015. hw_dbg(hw, "Failed to read PBA Block size.\n");
  1016. return status;
  1017. }
  1018. /* Subtract one to get PBA word count (PBA Size word is included in
  1019. * total size)
  1020. */
  1021. pba_size--;
  1022. if (pba_num_size < (((u32)pba_size * 2) + 1)) {
  1023. hw_dbg(hw, "Buffer to small for PBA data.\n");
  1024. return I40E_ERR_PARAM;
  1025. }
  1026. for (i = 0; i < pba_size; i++) {
  1027. status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
  1028. if (status) {
  1029. hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
  1030. return status;
  1031. }
  1032. pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
  1033. pba_num[(i * 2) + 1] = pba_word & 0xFF;
  1034. }
  1035. pba_num[(pba_size * 2)] = '\0';
  1036. return status;
  1037. }
  1038. /**
  1039. * i40e_get_media_type - Gets media type
  1040. * @hw: pointer to the hardware structure
  1041. **/
  1042. static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
  1043. {
  1044. enum i40e_media_type media;
  1045. switch (hw->phy.link_info.phy_type) {
  1046. case I40E_PHY_TYPE_10GBASE_SR:
  1047. case I40E_PHY_TYPE_10GBASE_LR:
  1048. case I40E_PHY_TYPE_1000BASE_SX:
  1049. case I40E_PHY_TYPE_1000BASE_LX:
  1050. case I40E_PHY_TYPE_40GBASE_SR4:
  1051. case I40E_PHY_TYPE_40GBASE_LR4:
  1052. case I40E_PHY_TYPE_25GBASE_LR:
  1053. case I40E_PHY_TYPE_25GBASE_SR:
  1054. media = I40E_MEDIA_TYPE_FIBER;
  1055. break;
  1056. case I40E_PHY_TYPE_100BASE_TX:
  1057. case I40E_PHY_TYPE_1000BASE_T:
  1058. case I40E_PHY_TYPE_10GBASE_T:
  1059. media = I40E_MEDIA_TYPE_BASET;
  1060. break;
  1061. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  1062. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  1063. case I40E_PHY_TYPE_10GBASE_CR1:
  1064. case I40E_PHY_TYPE_40GBASE_CR4:
  1065. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  1066. case I40E_PHY_TYPE_40GBASE_AOC:
  1067. case I40E_PHY_TYPE_10GBASE_AOC:
  1068. case I40E_PHY_TYPE_25GBASE_CR:
  1069. case I40E_PHY_TYPE_25GBASE_AOC:
  1070. case I40E_PHY_TYPE_25GBASE_ACC:
  1071. media = I40E_MEDIA_TYPE_DA;
  1072. break;
  1073. case I40E_PHY_TYPE_1000BASE_KX:
  1074. case I40E_PHY_TYPE_10GBASE_KX4:
  1075. case I40E_PHY_TYPE_10GBASE_KR:
  1076. case I40E_PHY_TYPE_40GBASE_KR4:
  1077. case I40E_PHY_TYPE_20GBASE_KR2:
  1078. case I40E_PHY_TYPE_25GBASE_KR:
  1079. media = I40E_MEDIA_TYPE_BACKPLANE;
  1080. break;
  1081. case I40E_PHY_TYPE_SGMII:
  1082. case I40E_PHY_TYPE_XAUI:
  1083. case I40E_PHY_TYPE_XFI:
  1084. case I40E_PHY_TYPE_XLAUI:
  1085. case I40E_PHY_TYPE_XLPPI:
  1086. default:
  1087. media = I40E_MEDIA_TYPE_UNKNOWN;
  1088. break;
  1089. }
  1090. return media;
  1091. }
  1092. #define I40E_PF_RESET_WAIT_COUNT_A0 200
  1093. #define I40E_PF_RESET_WAIT_COUNT 200
  1094. /**
  1095. * i40e_pf_reset - Reset the PF
  1096. * @hw: pointer to the hardware structure
  1097. *
  1098. * Assuming someone else has triggered a global reset,
  1099. * assure the global reset is complete and then reset the PF
  1100. **/
  1101. i40e_status i40e_pf_reset(struct i40e_hw *hw)
  1102. {
  1103. u32 cnt = 0;
  1104. u32 cnt1 = 0;
  1105. u32 reg = 0;
  1106. u32 grst_del;
  1107. /* Poll for Global Reset steady state in case of recent GRST.
  1108. * The grst delay value is in 100ms units, and we'll wait a
  1109. * couple counts longer to be sure we don't just miss the end.
  1110. */
  1111. grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
  1112. I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
  1113. I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
  1114. /* It can take upto 15 secs for GRST steady state.
  1115. * Bump it to 16 secs max to be safe.
  1116. */
  1117. grst_del = grst_del * 20;
  1118. for (cnt = 0; cnt < grst_del; cnt++) {
  1119. reg = rd32(hw, I40E_GLGEN_RSTAT);
  1120. if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
  1121. break;
  1122. msleep(100);
  1123. }
  1124. if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
  1125. hw_dbg(hw, "Global reset polling failed to complete.\n");
  1126. return I40E_ERR_RESET_FAILED;
  1127. }
  1128. /* Now Wait for the FW to be ready */
  1129. for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
  1130. reg = rd32(hw, I40E_GLNVM_ULD);
  1131. reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  1132. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
  1133. if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  1134. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
  1135. hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
  1136. break;
  1137. }
  1138. usleep_range(10000, 20000);
  1139. }
  1140. if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  1141. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
  1142. hw_dbg(hw, "wait for FW Reset complete timedout\n");
  1143. hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
  1144. return I40E_ERR_RESET_FAILED;
  1145. }
  1146. /* If there was a Global Reset in progress when we got here,
  1147. * we don't need to do the PF Reset
  1148. */
  1149. if (!cnt) {
  1150. u32 reg2 = 0;
  1151. if (hw->revision_id == 0)
  1152. cnt = I40E_PF_RESET_WAIT_COUNT_A0;
  1153. else
  1154. cnt = I40E_PF_RESET_WAIT_COUNT;
  1155. reg = rd32(hw, I40E_PFGEN_CTRL);
  1156. wr32(hw, I40E_PFGEN_CTRL,
  1157. (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  1158. for (; cnt; cnt--) {
  1159. reg = rd32(hw, I40E_PFGEN_CTRL);
  1160. if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
  1161. break;
  1162. reg2 = rd32(hw, I40E_GLGEN_RSTAT);
  1163. if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
  1164. hw_dbg(hw, "Core reset upcoming. Skipping PF reset request.\n");
  1165. hw_dbg(hw, "I40E_GLGEN_RSTAT = 0x%x\n", reg2);
  1166. return I40E_ERR_NOT_READY;
  1167. }
  1168. usleep_range(1000, 2000);
  1169. }
  1170. if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
  1171. hw_dbg(hw, "PF reset polling failed to complete.\n");
  1172. return I40E_ERR_RESET_FAILED;
  1173. }
  1174. }
  1175. i40e_clear_pxe_mode(hw);
  1176. return 0;
  1177. }
  1178. /**
  1179. * i40e_clear_hw - clear out any left over hw state
  1180. * @hw: pointer to the hw struct
  1181. *
  1182. * Clear queues and interrupts, typically called at init time,
  1183. * but after the capabilities have been found so we know how many
  1184. * queues and msix vectors have been allocated.
  1185. **/
  1186. void i40e_clear_hw(struct i40e_hw *hw)
  1187. {
  1188. u32 num_queues, base_queue;
  1189. u32 num_pf_int;
  1190. u32 num_vf_int;
  1191. u32 num_vfs;
  1192. u32 i, j;
  1193. u32 val;
  1194. u32 eol = 0x7ff;
  1195. /* get number of interrupts, queues, and VFs */
  1196. val = rd32(hw, I40E_GLPCI_CNF2);
  1197. num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
  1198. I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
  1199. num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
  1200. I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
  1201. val = rd32(hw, I40E_PFLAN_QALLOC);
  1202. base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
  1203. I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
  1204. j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
  1205. I40E_PFLAN_QALLOC_LASTQ_SHIFT;
  1206. if (val & I40E_PFLAN_QALLOC_VALID_MASK)
  1207. num_queues = (j - base_queue) + 1;
  1208. else
  1209. num_queues = 0;
  1210. val = rd32(hw, I40E_PF_VT_PFALLOC);
  1211. i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
  1212. I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
  1213. j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
  1214. I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
  1215. if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
  1216. num_vfs = (j - i) + 1;
  1217. else
  1218. num_vfs = 0;
  1219. /* stop all the interrupts */
  1220. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  1221. val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
  1222. for (i = 0; i < num_pf_int - 2; i++)
  1223. wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
  1224. /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
  1225. val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  1226. wr32(hw, I40E_PFINT_LNKLST0, val);
  1227. for (i = 0; i < num_pf_int - 2; i++)
  1228. wr32(hw, I40E_PFINT_LNKLSTN(i), val);
  1229. val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  1230. for (i = 0; i < num_vfs; i++)
  1231. wr32(hw, I40E_VPINT_LNKLST0(i), val);
  1232. for (i = 0; i < num_vf_int - 2; i++)
  1233. wr32(hw, I40E_VPINT_LNKLSTN(i), val);
  1234. /* warn the HW of the coming Tx disables */
  1235. for (i = 0; i < num_queues; i++) {
  1236. u32 abs_queue_idx = base_queue + i;
  1237. u32 reg_block = 0;
  1238. if (abs_queue_idx >= 128) {
  1239. reg_block = abs_queue_idx / 128;
  1240. abs_queue_idx %= 128;
  1241. }
  1242. val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
  1243. val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
  1244. val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
  1245. val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
  1246. wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
  1247. }
  1248. udelay(400);
  1249. /* stop all the queues */
  1250. for (i = 0; i < num_queues; i++) {
  1251. wr32(hw, I40E_QINT_TQCTL(i), 0);
  1252. wr32(hw, I40E_QTX_ENA(i), 0);
  1253. wr32(hw, I40E_QINT_RQCTL(i), 0);
  1254. wr32(hw, I40E_QRX_ENA(i), 0);
  1255. }
  1256. /* short wait for all queue disables to settle */
  1257. udelay(50);
  1258. }
  1259. /**
  1260. * i40e_clear_pxe_mode - clear pxe operations mode
  1261. * @hw: pointer to the hw struct
  1262. *
  1263. * Make sure all PXE mode settings are cleared, including things
  1264. * like descriptor fetch/write-back mode.
  1265. **/
  1266. void i40e_clear_pxe_mode(struct i40e_hw *hw)
  1267. {
  1268. u32 reg;
  1269. if (i40e_check_asq_alive(hw))
  1270. i40e_aq_clear_pxe_mode(hw, NULL);
  1271. /* Clear single descriptor fetch/write-back mode */
  1272. reg = rd32(hw, I40E_GLLAN_RCTL_0);
  1273. if (hw->revision_id == 0) {
  1274. /* As a work around clear PXE_MODE instead of setting it */
  1275. wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
  1276. } else {
  1277. wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
  1278. }
  1279. }
  1280. /**
  1281. * i40e_led_is_mine - helper to find matching led
  1282. * @hw: pointer to the hw struct
  1283. * @idx: index into GPIO registers
  1284. *
  1285. * returns: 0 if no match, otherwise the value of the GPIO_CTL register
  1286. */
  1287. static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
  1288. {
  1289. u32 gpio_val = 0;
  1290. u32 port;
  1291. if (!hw->func_caps.led[idx])
  1292. return 0;
  1293. gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
  1294. port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
  1295. I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
  1296. /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
  1297. * if it is not our port then ignore
  1298. */
  1299. if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
  1300. (port != hw->port))
  1301. return 0;
  1302. return gpio_val;
  1303. }
  1304. #define I40E_COMBINED_ACTIVITY 0xA
  1305. #define I40E_FILTER_ACTIVITY 0xE
  1306. #define I40E_LINK_ACTIVITY 0xC
  1307. #define I40E_MAC_ACTIVITY 0xD
  1308. #define I40E_LED0 22
  1309. /**
  1310. * i40e_led_get - return current on/off mode
  1311. * @hw: pointer to the hw struct
  1312. *
  1313. * The value returned is the 'mode' field as defined in the
  1314. * GPIO register definitions: 0x0 = off, 0xf = on, and other
  1315. * values are variations of possible behaviors relating to
  1316. * blink, link, and wire.
  1317. **/
  1318. u32 i40e_led_get(struct i40e_hw *hw)
  1319. {
  1320. u32 current_mode = 0;
  1321. u32 mode = 0;
  1322. int i;
  1323. /* as per the documentation GPIO 22-29 are the LED
  1324. * GPIO pins named LED0..LED7
  1325. */
  1326. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  1327. u32 gpio_val = i40e_led_is_mine(hw, i);
  1328. if (!gpio_val)
  1329. continue;
  1330. /* ignore gpio LED src mode entries related to the activity
  1331. * LEDs
  1332. */
  1333. current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
  1334. >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
  1335. switch (current_mode) {
  1336. case I40E_COMBINED_ACTIVITY:
  1337. case I40E_FILTER_ACTIVITY:
  1338. case I40E_MAC_ACTIVITY:
  1339. continue;
  1340. default:
  1341. break;
  1342. }
  1343. mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
  1344. I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
  1345. break;
  1346. }
  1347. return mode;
  1348. }
  1349. /**
  1350. * i40e_led_set - set new on/off mode
  1351. * @hw: pointer to the hw struct
  1352. * @mode: 0=off, 0xf=on (else see manual for mode details)
  1353. * @blink: true if the LED should blink when on, false if steady
  1354. *
  1355. * if this function is used to turn on the blink it should
  1356. * be used to disable the blink when restoring the original state.
  1357. **/
  1358. void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
  1359. {
  1360. u32 current_mode = 0;
  1361. int i;
  1362. if (mode & 0xfffffff0)
  1363. hw_dbg(hw, "invalid mode passed in %X\n", mode);
  1364. /* as per the documentation GPIO 22-29 are the LED
  1365. * GPIO pins named LED0..LED7
  1366. */
  1367. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  1368. u32 gpio_val = i40e_led_is_mine(hw, i);
  1369. if (!gpio_val)
  1370. continue;
  1371. /* ignore gpio LED src mode entries related to the activity
  1372. * LEDs
  1373. */
  1374. current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
  1375. >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
  1376. switch (current_mode) {
  1377. case I40E_COMBINED_ACTIVITY:
  1378. case I40E_FILTER_ACTIVITY:
  1379. case I40E_MAC_ACTIVITY:
  1380. continue;
  1381. default:
  1382. break;
  1383. }
  1384. gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
  1385. /* this & is a bit of paranoia, but serves as a range check */
  1386. gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
  1387. I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
  1388. if (mode == I40E_LINK_ACTIVITY)
  1389. blink = false;
  1390. if (blink)
  1391. gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1392. else
  1393. gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1394. wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
  1395. break;
  1396. }
  1397. }
  1398. /* Admin command wrappers */
  1399. /**
  1400. * i40e_aq_get_phy_capabilities
  1401. * @hw: pointer to the hw struct
  1402. * @abilities: structure for PHY capabilities to be filled
  1403. * @qualified_modules: report Qualified Modules
  1404. * @report_init: report init capabilities (active are default)
  1405. * @cmd_details: pointer to command details structure or NULL
  1406. *
  1407. * Returns the various PHY abilities supported on the Port.
  1408. **/
  1409. i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
  1410. bool qualified_modules, bool report_init,
  1411. struct i40e_aq_get_phy_abilities_resp *abilities,
  1412. struct i40e_asq_cmd_details *cmd_details)
  1413. {
  1414. struct i40e_aq_desc desc;
  1415. i40e_status status;
  1416. u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
  1417. u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
  1418. if (!abilities)
  1419. return I40E_ERR_PARAM;
  1420. do {
  1421. i40e_fill_default_direct_cmd_desc(&desc,
  1422. i40e_aqc_opc_get_phy_abilities);
  1423. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1424. if (abilities_size > I40E_AQ_LARGE_BUF)
  1425. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1426. if (qualified_modules)
  1427. desc.params.external.param0 |=
  1428. cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
  1429. if (report_init)
  1430. desc.params.external.param0 |=
  1431. cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
  1432. status = i40e_asq_send_command(hw, &desc, abilities,
  1433. abilities_size, cmd_details);
  1434. if (status)
  1435. break;
  1436. if (hw->aq.asq_last_status == I40E_AQ_RC_EIO) {
  1437. status = I40E_ERR_UNKNOWN_PHY;
  1438. break;
  1439. } else if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) {
  1440. usleep_range(1000, 2000);
  1441. total_delay++;
  1442. status = I40E_ERR_TIMEOUT;
  1443. }
  1444. } while ((hw->aq.asq_last_status != I40E_AQ_RC_OK) &&
  1445. (total_delay < max_delay));
  1446. if (status)
  1447. return status;
  1448. if (report_init) {
  1449. if (hw->mac.type == I40E_MAC_XL710 &&
  1450. hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  1451. hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
  1452. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1453. } else {
  1454. hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
  1455. hw->phy.phy_types |=
  1456. ((u64)abilities->phy_type_ext << 32);
  1457. }
  1458. }
  1459. return status;
  1460. }
  1461. /**
  1462. * i40e_aq_set_phy_config
  1463. * @hw: pointer to the hw struct
  1464. * @config: structure with PHY configuration to be set
  1465. * @cmd_details: pointer to command details structure or NULL
  1466. *
  1467. * Set the various PHY configuration parameters
  1468. * supported on the Port.One or more of the Set PHY config parameters may be
  1469. * ignored in an MFP mode as the PF may not have the privilege to set some
  1470. * of the PHY Config parameters. This status will be indicated by the
  1471. * command response.
  1472. **/
  1473. enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
  1474. struct i40e_aq_set_phy_config *config,
  1475. struct i40e_asq_cmd_details *cmd_details)
  1476. {
  1477. struct i40e_aq_desc desc;
  1478. struct i40e_aq_set_phy_config *cmd =
  1479. (struct i40e_aq_set_phy_config *)&desc.params.raw;
  1480. enum i40e_status_code status;
  1481. if (!config)
  1482. return I40E_ERR_PARAM;
  1483. i40e_fill_default_direct_cmd_desc(&desc,
  1484. i40e_aqc_opc_set_phy_config);
  1485. *cmd = *config;
  1486. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1487. return status;
  1488. }
  1489. /**
  1490. * i40e_set_fc
  1491. * @hw: pointer to the hw struct
  1492. *
  1493. * Set the requested flow control mode using set_phy_config.
  1494. **/
  1495. enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
  1496. bool atomic_restart)
  1497. {
  1498. enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
  1499. struct i40e_aq_get_phy_abilities_resp abilities;
  1500. struct i40e_aq_set_phy_config config;
  1501. enum i40e_status_code status;
  1502. u8 pause_mask = 0x0;
  1503. *aq_failures = 0x0;
  1504. switch (fc_mode) {
  1505. case I40E_FC_FULL:
  1506. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1507. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1508. break;
  1509. case I40E_FC_RX_PAUSE:
  1510. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1511. break;
  1512. case I40E_FC_TX_PAUSE:
  1513. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1514. break;
  1515. default:
  1516. break;
  1517. }
  1518. /* Get the current phy config */
  1519. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  1520. NULL);
  1521. if (status) {
  1522. *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
  1523. return status;
  1524. }
  1525. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  1526. /* clear the old pause settings */
  1527. config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
  1528. ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
  1529. /* set the new abilities */
  1530. config.abilities |= pause_mask;
  1531. /* If the abilities have changed, then set the new config */
  1532. if (config.abilities != abilities.abilities) {
  1533. /* Auto restart link so settings take effect */
  1534. if (atomic_restart)
  1535. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  1536. /* Copy over all the old settings */
  1537. config.phy_type = abilities.phy_type;
  1538. config.phy_type_ext = abilities.phy_type_ext;
  1539. config.link_speed = abilities.link_speed;
  1540. config.eee_capability = abilities.eee_capability;
  1541. config.eeer = abilities.eeer_val;
  1542. config.low_power_ctrl = abilities.d3_lpan;
  1543. config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
  1544. I40E_AQ_PHY_FEC_CONFIG_MASK;
  1545. status = i40e_aq_set_phy_config(hw, &config, NULL);
  1546. if (status)
  1547. *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
  1548. }
  1549. /* Update the link info */
  1550. status = i40e_update_link_info(hw);
  1551. if (status) {
  1552. /* Wait a little bit (on 40G cards it sometimes takes a really
  1553. * long time for link to come back from the atomic reset)
  1554. * and try once more
  1555. */
  1556. msleep(1000);
  1557. status = i40e_update_link_info(hw);
  1558. }
  1559. if (status)
  1560. *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
  1561. return status;
  1562. }
  1563. /**
  1564. * i40e_aq_clear_pxe_mode
  1565. * @hw: pointer to the hw struct
  1566. * @cmd_details: pointer to command details structure or NULL
  1567. *
  1568. * Tell the firmware that the driver is taking over from PXE
  1569. **/
  1570. i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
  1571. struct i40e_asq_cmd_details *cmd_details)
  1572. {
  1573. i40e_status status;
  1574. struct i40e_aq_desc desc;
  1575. struct i40e_aqc_clear_pxe *cmd =
  1576. (struct i40e_aqc_clear_pxe *)&desc.params.raw;
  1577. i40e_fill_default_direct_cmd_desc(&desc,
  1578. i40e_aqc_opc_clear_pxe_mode);
  1579. cmd->rx_cnt = 0x2;
  1580. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1581. wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
  1582. return status;
  1583. }
  1584. /**
  1585. * i40e_aq_set_link_restart_an
  1586. * @hw: pointer to the hw struct
  1587. * @enable_link: if true: enable link, if false: disable link
  1588. * @cmd_details: pointer to command details structure or NULL
  1589. *
  1590. * Sets up the link and restarts the Auto-Negotiation over the link.
  1591. **/
  1592. i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
  1593. bool enable_link,
  1594. struct i40e_asq_cmd_details *cmd_details)
  1595. {
  1596. struct i40e_aq_desc desc;
  1597. struct i40e_aqc_set_link_restart_an *cmd =
  1598. (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
  1599. i40e_status status;
  1600. i40e_fill_default_direct_cmd_desc(&desc,
  1601. i40e_aqc_opc_set_link_restart_an);
  1602. cmd->command = I40E_AQ_PHY_RESTART_AN;
  1603. if (enable_link)
  1604. cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
  1605. else
  1606. cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
  1607. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1608. return status;
  1609. }
  1610. /**
  1611. * i40e_aq_get_link_info
  1612. * @hw: pointer to the hw struct
  1613. * @enable_lse: enable/disable LinkStatusEvent reporting
  1614. * @link: pointer to link status structure - optional
  1615. * @cmd_details: pointer to command details structure or NULL
  1616. *
  1617. * Returns the link status of the adapter.
  1618. **/
  1619. i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
  1620. bool enable_lse, struct i40e_link_status *link,
  1621. struct i40e_asq_cmd_details *cmd_details)
  1622. {
  1623. struct i40e_aq_desc desc;
  1624. struct i40e_aqc_get_link_status *resp =
  1625. (struct i40e_aqc_get_link_status *)&desc.params.raw;
  1626. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  1627. i40e_status status;
  1628. bool tx_pause, rx_pause;
  1629. u16 command_flags;
  1630. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
  1631. if (enable_lse)
  1632. command_flags = I40E_AQ_LSE_ENABLE;
  1633. else
  1634. command_flags = I40E_AQ_LSE_DISABLE;
  1635. resp->command_flags = cpu_to_le16(command_flags);
  1636. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1637. if (status)
  1638. goto aq_get_link_info_exit;
  1639. /* save off old link status information */
  1640. hw->phy.link_info_old = *hw_link_info;
  1641. /* update link status */
  1642. hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
  1643. hw->phy.media_type = i40e_get_media_type(hw);
  1644. hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
  1645. hw_link_info->link_info = resp->link_info;
  1646. hw_link_info->an_info = resp->an_info;
  1647. hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
  1648. I40E_AQ_CONFIG_FEC_RS_ENA);
  1649. hw_link_info->ext_info = resp->ext_info;
  1650. hw_link_info->loopback = resp->loopback & I40E_AQ_LOOPBACK_MASK;
  1651. hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
  1652. hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
  1653. /* update fc info */
  1654. tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
  1655. rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
  1656. if (tx_pause & rx_pause)
  1657. hw->fc.current_mode = I40E_FC_FULL;
  1658. else if (tx_pause)
  1659. hw->fc.current_mode = I40E_FC_TX_PAUSE;
  1660. else if (rx_pause)
  1661. hw->fc.current_mode = I40E_FC_RX_PAUSE;
  1662. else
  1663. hw->fc.current_mode = I40E_FC_NONE;
  1664. if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
  1665. hw_link_info->crc_enable = true;
  1666. else
  1667. hw_link_info->crc_enable = false;
  1668. if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_IS_ENABLED))
  1669. hw_link_info->lse_enable = true;
  1670. else
  1671. hw_link_info->lse_enable = false;
  1672. if ((hw->mac.type == I40E_MAC_XL710) &&
  1673. (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
  1674. hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
  1675. hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
  1676. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  1677. hw->aq.api_min_ver >= 7) {
  1678. __le32 tmp;
  1679. memcpy(&tmp, resp->link_type, sizeof(tmp));
  1680. hw->phy.phy_types = le32_to_cpu(tmp);
  1681. hw->phy.phy_types |= ((u64)resp->link_type_ext << 32);
  1682. }
  1683. /* save link status information */
  1684. if (link)
  1685. *link = *hw_link_info;
  1686. /* flag cleared so helper functions don't call AQ again */
  1687. hw->phy.get_link_info = false;
  1688. aq_get_link_info_exit:
  1689. return status;
  1690. }
  1691. /**
  1692. * i40e_aq_set_phy_int_mask
  1693. * @hw: pointer to the hw struct
  1694. * @mask: interrupt mask to be set
  1695. * @cmd_details: pointer to command details structure or NULL
  1696. *
  1697. * Set link interrupt mask.
  1698. **/
  1699. i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
  1700. u16 mask,
  1701. struct i40e_asq_cmd_details *cmd_details)
  1702. {
  1703. struct i40e_aq_desc desc;
  1704. struct i40e_aqc_set_phy_int_mask *cmd =
  1705. (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
  1706. i40e_status status;
  1707. i40e_fill_default_direct_cmd_desc(&desc,
  1708. i40e_aqc_opc_set_phy_int_mask);
  1709. cmd->event_mask = cpu_to_le16(mask);
  1710. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1711. return status;
  1712. }
  1713. /**
  1714. * i40e_aq_set_phy_debug
  1715. * @hw: pointer to the hw struct
  1716. * @cmd_flags: debug command flags
  1717. * @cmd_details: pointer to command details structure or NULL
  1718. *
  1719. * Reset the external PHY.
  1720. **/
  1721. i40e_status i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
  1722. struct i40e_asq_cmd_details *cmd_details)
  1723. {
  1724. struct i40e_aq_desc desc;
  1725. struct i40e_aqc_set_phy_debug *cmd =
  1726. (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
  1727. i40e_status status;
  1728. i40e_fill_default_direct_cmd_desc(&desc,
  1729. i40e_aqc_opc_set_phy_debug);
  1730. cmd->command_flags = cmd_flags;
  1731. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1732. return status;
  1733. }
  1734. /**
  1735. * i40e_aq_add_vsi
  1736. * @hw: pointer to the hw struct
  1737. * @vsi_ctx: pointer to a vsi context struct
  1738. * @cmd_details: pointer to command details structure or NULL
  1739. *
  1740. * Add a VSI context to the hardware.
  1741. **/
  1742. i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
  1743. struct i40e_vsi_context *vsi_ctx,
  1744. struct i40e_asq_cmd_details *cmd_details)
  1745. {
  1746. struct i40e_aq_desc desc;
  1747. struct i40e_aqc_add_get_update_vsi *cmd =
  1748. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1749. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1750. (struct i40e_aqc_add_get_update_vsi_completion *)
  1751. &desc.params.raw;
  1752. i40e_status status;
  1753. i40e_fill_default_direct_cmd_desc(&desc,
  1754. i40e_aqc_opc_add_vsi);
  1755. cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
  1756. cmd->connection_type = vsi_ctx->connection_type;
  1757. cmd->vf_id = vsi_ctx->vf_num;
  1758. cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
  1759. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1760. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1761. sizeof(vsi_ctx->info), cmd_details);
  1762. if (status)
  1763. goto aq_add_vsi_exit;
  1764. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1765. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1766. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1767. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1768. aq_add_vsi_exit:
  1769. return status;
  1770. }
  1771. /**
  1772. * i40e_aq_set_default_vsi
  1773. * @hw: pointer to the hw struct
  1774. * @seid: vsi number
  1775. * @cmd_details: pointer to command details structure or NULL
  1776. **/
  1777. i40e_status i40e_aq_set_default_vsi(struct i40e_hw *hw,
  1778. u16 seid,
  1779. struct i40e_asq_cmd_details *cmd_details)
  1780. {
  1781. struct i40e_aq_desc desc;
  1782. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1783. (struct i40e_aqc_set_vsi_promiscuous_modes *)
  1784. &desc.params.raw;
  1785. i40e_status status;
  1786. i40e_fill_default_direct_cmd_desc(&desc,
  1787. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1788. cmd->promiscuous_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
  1789. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
  1790. cmd->seid = cpu_to_le16(seid);
  1791. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1792. return status;
  1793. }
  1794. /**
  1795. * i40e_aq_clear_default_vsi
  1796. * @hw: pointer to the hw struct
  1797. * @seid: vsi number
  1798. * @cmd_details: pointer to command details structure or NULL
  1799. **/
  1800. i40e_status i40e_aq_clear_default_vsi(struct i40e_hw *hw,
  1801. u16 seid,
  1802. struct i40e_asq_cmd_details *cmd_details)
  1803. {
  1804. struct i40e_aq_desc desc;
  1805. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1806. (struct i40e_aqc_set_vsi_promiscuous_modes *)
  1807. &desc.params.raw;
  1808. i40e_status status;
  1809. i40e_fill_default_direct_cmd_desc(&desc,
  1810. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1811. cmd->promiscuous_flags = cpu_to_le16(0);
  1812. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
  1813. cmd->seid = cpu_to_le16(seid);
  1814. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1815. return status;
  1816. }
  1817. /**
  1818. * i40e_aq_set_vsi_unicast_promiscuous
  1819. * @hw: pointer to the hw struct
  1820. * @seid: vsi number
  1821. * @set: set unicast promiscuous enable/disable
  1822. * @cmd_details: pointer to command details structure or NULL
  1823. * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
  1824. **/
  1825. i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
  1826. u16 seid, bool set,
  1827. struct i40e_asq_cmd_details *cmd_details,
  1828. bool rx_only_promisc)
  1829. {
  1830. struct i40e_aq_desc desc;
  1831. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1832. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1833. i40e_status status;
  1834. u16 flags = 0;
  1835. i40e_fill_default_direct_cmd_desc(&desc,
  1836. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1837. if (set) {
  1838. flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
  1839. if (rx_only_promisc &&
  1840. (((hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver >= 5)) ||
  1841. (hw->aq.api_maj_ver > 1)))
  1842. flags |= I40E_AQC_SET_VSI_PROMISC_TX;
  1843. }
  1844. cmd->promiscuous_flags = cpu_to_le16(flags);
  1845. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
  1846. if (((hw->aq.api_maj_ver >= 1) && (hw->aq.api_min_ver >= 5)) ||
  1847. (hw->aq.api_maj_ver > 1))
  1848. cmd->valid_flags |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_TX);
  1849. cmd->seid = cpu_to_le16(seid);
  1850. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1851. return status;
  1852. }
  1853. /**
  1854. * i40e_aq_set_vsi_multicast_promiscuous
  1855. * @hw: pointer to the hw struct
  1856. * @seid: vsi number
  1857. * @set: set multicast promiscuous enable/disable
  1858. * @cmd_details: pointer to command details structure or NULL
  1859. **/
  1860. i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
  1861. u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
  1862. {
  1863. struct i40e_aq_desc desc;
  1864. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1865. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1866. i40e_status status;
  1867. u16 flags = 0;
  1868. i40e_fill_default_direct_cmd_desc(&desc,
  1869. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1870. if (set)
  1871. flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
  1872. cmd->promiscuous_flags = cpu_to_le16(flags);
  1873. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
  1874. cmd->seid = cpu_to_le16(seid);
  1875. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1876. return status;
  1877. }
  1878. /**
  1879. * i40e_aq_set_vsi_mc_promisc_on_vlan
  1880. * @hw: pointer to the hw struct
  1881. * @seid: vsi number
  1882. * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
  1883. * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
  1884. * @cmd_details: pointer to command details structure or NULL
  1885. **/
  1886. enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
  1887. u16 seid, bool enable,
  1888. u16 vid,
  1889. struct i40e_asq_cmd_details *cmd_details)
  1890. {
  1891. struct i40e_aq_desc desc;
  1892. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1893. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1894. enum i40e_status_code status;
  1895. u16 flags = 0;
  1896. i40e_fill_default_direct_cmd_desc(&desc,
  1897. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1898. if (enable)
  1899. flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
  1900. cmd->promiscuous_flags = cpu_to_le16(flags);
  1901. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
  1902. cmd->seid = cpu_to_le16(seid);
  1903. cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
  1904. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1905. return status;
  1906. }
  1907. /**
  1908. * i40e_aq_set_vsi_uc_promisc_on_vlan
  1909. * @hw: pointer to the hw struct
  1910. * @seid: vsi number
  1911. * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
  1912. * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
  1913. * @cmd_details: pointer to command details structure or NULL
  1914. **/
  1915. enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
  1916. u16 seid, bool enable,
  1917. u16 vid,
  1918. struct i40e_asq_cmd_details *cmd_details)
  1919. {
  1920. struct i40e_aq_desc desc;
  1921. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1922. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1923. enum i40e_status_code status;
  1924. u16 flags = 0;
  1925. i40e_fill_default_direct_cmd_desc(&desc,
  1926. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1927. if (enable)
  1928. flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
  1929. cmd->promiscuous_flags = cpu_to_le16(flags);
  1930. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
  1931. cmd->seid = cpu_to_le16(seid);
  1932. cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
  1933. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1934. return status;
  1935. }
  1936. /**
  1937. * i40e_aq_set_vsi_bc_promisc_on_vlan
  1938. * @hw: pointer to the hw struct
  1939. * @seid: vsi number
  1940. * @enable: set broadcast promiscuous enable/disable for a given VLAN
  1941. * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
  1942. * @cmd_details: pointer to command details structure or NULL
  1943. **/
  1944. i40e_status i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
  1945. u16 seid, bool enable, u16 vid,
  1946. struct i40e_asq_cmd_details *cmd_details)
  1947. {
  1948. struct i40e_aq_desc desc;
  1949. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1950. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1951. i40e_status status;
  1952. u16 flags = 0;
  1953. i40e_fill_default_direct_cmd_desc(&desc,
  1954. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1955. if (enable)
  1956. flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
  1957. cmd->promiscuous_flags = cpu_to_le16(flags);
  1958. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1959. cmd->seid = cpu_to_le16(seid);
  1960. cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
  1961. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1962. return status;
  1963. }
  1964. /**
  1965. * i40e_aq_set_vsi_broadcast
  1966. * @hw: pointer to the hw struct
  1967. * @seid: vsi number
  1968. * @set_filter: true to set filter, false to clear filter
  1969. * @cmd_details: pointer to command details structure or NULL
  1970. *
  1971. * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
  1972. **/
  1973. i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
  1974. u16 seid, bool set_filter,
  1975. struct i40e_asq_cmd_details *cmd_details)
  1976. {
  1977. struct i40e_aq_desc desc;
  1978. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1979. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1980. i40e_status status;
  1981. i40e_fill_default_direct_cmd_desc(&desc,
  1982. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1983. if (set_filter)
  1984. cmd->promiscuous_flags
  1985. |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1986. else
  1987. cmd->promiscuous_flags
  1988. &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1989. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1990. cmd->seid = cpu_to_le16(seid);
  1991. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1992. return status;
  1993. }
  1994. /**
  1995. * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
  1996. * @hw: pointer to the hw struct
  1997. * @seid: vsi number
  1998. * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
  1999. * @cmd_details: pointer to command details structure or NULL
  2000. **/
  2001. i40e_status i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
  2002. u16 seid, bool enable,
  2003. struct i40e_asq_cmd_details *cmd_details)
  2004. {
  2005. struct i40e_aq_desc desc;
  2006. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  2007. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  2008. i40e_status status;
  2009. u16 flags = 0;
  2010. i40e_fill_default_direct_cmd_desc(&desc,
  2011. i40e_aqc_opc_set_vsi_promiscuous_modes);
  2012. if (enable)
  2013. flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
  2014. cmd->promiscuous_flags = cpu_to_le16(flags);
  2015. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
  2016. cmd->seid = cpu_to_le16(seid);
  2017. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2018. return status;
  2019. }
  2020. /**
  2021. * i40e_get_vsi_params - get VSI configuration info
  2022. * @hw: pointer to the hw struct
  2023. * @vsi_ctx: pointer to a vsi context struct
  2024. * @cmd_details: pointer to command details structure or NULL
  2025. **/
  2026. i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
  2027. struct i40e_vsi_context *vsi_ctx,
  2028. struct i40e_asq_cmd_details *cmd_details)
  2029. {
  2030. struct i40e_aq_desc desc;
  2031. struct i40e_aqc_add_get_update_vsi *cmd =
  2032. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  2033. struct i40e_aqc_add_get_update_vsi_completion *resp =
  2034. (struct i40e_aqc_add_get_update_vsi_completion *)
  2035. &desc.params.raw;
  2036. i40e_status status;
  2037. i40e_fill_default_direct_cmd_desc(&desc,
  2038. i40e_aqc_opc_get_vsi_parameters);
  2039. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  2040. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2041. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  2042. sizeof(vsi_ctx->info), NULL);
  2043. if (status)
  2044. goto aq_get_vsi_params_exit;
  2045. vsi_ctx->seid = le16_to_cpu(resp->seid);
  2046. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  2047. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  2048. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  2049. aq_get_vsi_params_exit:
  2050. return status;
  2051. }
  2052. /**
  2053. * i40e_aq_update_vsi_params
  2054. * @hw: pointer to the hw struct
  2055. * @vsi_ctx: pointer to a vsi context struct
  2056. * @cmd_details: pointer to command details structure or NULL
  2057. *
  2058. * Update a VSI context.
  2059. **/
  2060. i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
  2061. struct i40e_vsi_context *vsi_ctx,
  2062. struct i40e_asq_cmd_details *cmd_details)
  2063. {
  2064. struct i40e_aq_desc desc;
  2065. struct i40e_aqc_add_get_update_vsi *cmd =
  2066. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  2067. struct i40e_aqc_add_get_update_vsi_completion *resp =
  2068. (struct i40e_aqc_add_get_update_vsi_completion *)
  2069. &desc.params.raw;
  2070. i40e_status status;
  2071. i40e_fill_default_direct_cmd_desc(&desc,
  2072. i40e_aqc_opc_update_vsi_parameters);
  2073. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  2074. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2075. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  2076. sizeof(vsi_ctx->info), cmd_details);
  2077. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  2078. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  2079. return status;
  2080. }
  2081. /**
  2082. * i40e_aq_get_switch_config
  2083. * @hw: pointer to the hardware structure
  2084. * @buf: pointer to the result buffer
  2085. * @buf_size: length of input buffer
  2086. * @start_seid: seid to start for the report, 0 == beginning
  2087. * @cmd_details: pointer to command details structure or NULL
  2088. *
  2089. * Fill the buf with switch configuration returned from AdminQ command
  2090. **/
  2091. i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
  2092. struct i40e_aqc_get_switch_config_resp *buf,
  2093. u16 buf_size, u16 *start_seid,
  2094. struct i40e_asq_cmd_details *cmd_details)
  2095. {
  2096. struct i40e_aq_desc desc;
  2097. struct i40e_aqc_switch_seid *scfg =
  2098. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  2099. i40e_status status;
  2100. i40e_fill_default_direct_cmd_desc(&desc,
  2101. i40e_aqc_opc_get_switch_config);
  2102. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2103. if (buf_size > I40E_AQ_LARGE_BUF)
  2104. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2105. scfg->seid = cpu_to_le16(*start_seid);
  2106. status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
  2107. *start_seid = le16_to_cpu(scfg->seid);
  2108. return status;
  2109. }
  2110. /**
  2111. * i40e_aq_set_switch_config
  2112. * @hw: pointer to the hardware structure
  2113. * @flags: bit flag values to set
  2114. * @valid_flags: which bit flags to set
  2115. * @mode: cloud filter mode
  2116. * @cmd_details: pointer to command details structure or NULL
  2117. *
  2118. * Set switch configuration bits
  2119. **/
  2120. enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
  2121. u16 flags,
  2122. u16 valid_flags, u8 mode,
  2123. struct i40e_asq_cmd_details *cmd_details)
  2124. {
  2125. struct i40e_aq_desc desc;
  2126. struct i40e_aqc_set_switch_config *scfg =
  2127. (struct i40e_aqc_set_switch_config *)&desc.params.raw;
  2128. enum i40e_status_code status;
  2129. i40e_fill_default_direct_cmd_desc(&desc,
  2130. i40e_aqc_opc_set_switch_config);
  2131. scfg->flags = cpu_to_le16(flags);
  2132. scfg->valid_flags = cpu_to_le16(valid_flags);
  2133. scfg->mode = mode;
  2134. if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
  2135. scfg->switch_tag = cpu_to_le16(hw->switch_tag);
  2136. scfg->first_tag = cpu_to_le16(hw->first_tag);
  2137. scfg->second_tag = cpu_to_le16(hw->second_tag);
  2138. }
  2139. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2140. return status;
  2141. }
  2142. /**
  2143. * i40e_aq_get_firmware_version
  2144. * @hw: pointer to the hw struct
  2145. * @fw_major_version: firmware major version
  2146. * @fw_minor_version: firmware minor version
  2147. * @fw_build: firmware build number
  2148. * @api_major_version: major queue version
  2149. * @api_minor_version: minor queue version
  2150. * @cmd_details: pointer to command details structure or NULL
  2151. *
  2152. * Get the firmware version from the admin queue commands
  2153. **/
  2154. i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
  2155. u16 *fw_major_version, u16 *fw_minor_version,
  2156. u32 *fw_build,
  2157. u16 *api_major_version, u16 *api_minor_version,
  2158. struct i40e_asq_cmd_details *cmd_details)
  2159. {
  2160. struct i40e_aq_desc desc;
  2161. struct i40e_aqc_get_version *resp =
  2162. (struct i40e_aqc_get_version *)&desc.params.raw;
  2163. i40e_status status;
  2164. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
  2165. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2166. if (!status) {
  2167. if (fw_major_version)
  2168. *fw_major_version = le16_to_cpu(resp->fw_major);
  2169. if (fw_minor_version)
  2170. *fw_minor_version = le16_to_cpu(resp->fw_minor);
  2171. if (fw_build)
  2172. *fw_build = le32_to_cpu(resp->fw_build);
  2173. if (api_major_version)
  2174. *api_major_version = le16_to_cpu(resp->api_major);
  2175. if (api_minor_version)
  2176. *api_minor_version = le16_to_cpu(resp->api_minor);
  2177. }
  2178. return status;
  2179. }
  2180. /**
  2181. * i40e_aq_send_driver_version
  2182. * @hw: pointer to the hw struct
  2183. * @dv: driver's major, minor version
  2184. * @cmd_details: pointer to command details structure or NULL
  2185. *
  2186. * Send the driver version to the firmware
  2187. **/
  2188. i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
  2189. struct i40e_driver_version *dv,
  2190. struct i40e_asq_cmd_details *cmd_details)
  2191. {
  2192. struct i40e_aq_desc desc;
  2193. struct i40e_aqc_driver_version *cmd =
  2194. (struct i40e_aqc_driver_version *)&desc.params.raw;
  2195. i40e_status status;
  2196. u16 len;
  2197. if (dv == NULL)
  2198. return I40E_ERR_PARAM;
  2199. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
  2200. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
  2201. cmd->driver_major_ver = dv->major_version;
  2202. cmd->driver_minor_ver = dv->minor_version;
  2203. cmd->driver_build_ver = dv->build_version;
  2204. cmd->driver_subbuild_ver = dv->subbuild_version;
  2205. len = 0;
  2206. while (len < sizeof(dv->driver_string) &&
  2207. (dv->driver_string[len] < 0x80) &&
  2208. dv->driver_string[len])
  2209. len++;
  2210. status = i40e_asq_send_command(hw, &desc, dv->driver_string,
  2211. len, cmd_details);
  2212. return status;
  2213. }
  2214. /**
  2215. * i40e_get_link_status - get status of the HW network link
  2216. * @hw: pointer to the hw struct
  2217. * @link_up: pointer to bool (true/false = linkup/linkdown)
  2218. *
  2219. * Variable link_up true if link is up, false if link is down.
  2220. * The variable link_up is invalid if returned value of status != 0
  2221. *
  2222. * Side effect: LinkStatusEvent reporting becomes enabled
  2223. **/
  2224. i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
  2225. {
  2226. i40e_status status = 0;
  2227. if (hw->phy.get_link_info) {
  2228. status = i40e_update_link_info(hw);
  2229. if (status)
  2230. i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
  2231. status);
  2232. }
  2233. *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  2234. return status;
  2235. }
  2236. /**
  2237. * i40e_updatelink_status - update status of the HW network link
  2238. * @hw: pointer to the hw struct
  2239. **/
  2240. i40e_status i40e_update_link_info(struct i40e_hw *hw)
  2241. {
  2242. struct i40e_aq_get_phy_abilities_resp abilities;
  2243. i40e_status status = 0;
  2244. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  2245. if (status)
  2246. return status;
  2247. /* extra checking needed to ensure link info to user is timely */
  2248. if ((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  2249. ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
  2250. !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) {
  2251. status = i40e_aq_get_phy_capabilities(hw, false, false,
  2252. &abilities, NULL);
  2253. if (status)
  2254. return status;
  2255. hw->phy.link_info.req_fec_info =
  2256. abilities.fec_cfg_curr_mod_ext_info &
  2257. (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS);
  2258. memcpy(hw->phy.link_info.module_type, &abilities.module_type,
  2259. sizeof(hw->phy.link_info.module_type));
  2260. }
  2261. return status;
  2262. }
  2263. /**
  2264. * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
  2265. * @hw: pointer to the hw struct
  2266. * @uplink_seid: the MAC or other gizmo SEID
  2267. * @downlink_seid: the VSI SEID
  2268. * @enabled_tc: bitmap of TCs to be enabled
  2269. * @default_port: true for default port VSI, false for control port
  2270. * @veb_seid: pointer to where to put the resulting VEB SEID
  2271. * @enable_stats: true to turn on VEB stats
  2272. * @cmd_details: pointer to command details structure or NULL
  2273. *
  2274. * This asks the FW to add a VEB between the uplink and downlink
  2275. * elements. If the uplink SEID is 0, this will be a floating VEB.
  2276. **/
  2277. i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
  2278. u16 downlink_seid, u8 enabled_tc,
  2279. bool default_port, u16 *veb_seid,
  2280. bool enable_stats,
  2281. struct i40e_asq_cmd_details *cmd_details)
  2282. {
  2283. struct i40e_aq_desc desc;
  2284. struct i40e_aqc_add_veb *cmd =
  2285. (struct i40e_aqc_add_veb *)&desc.params.raw;
  2286. struct i40e_aqc_add_veb_completion *resp =
  2287. (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
  2288. i40e_status status;
  2289. u16 veb_flags = 0;
  2290. /* SEIDs need to either both be set or both be 0 for floating VEB */
  2291. if (!!uplink_seid != !!downlink_seid)
  2292. return I40E_ERR_PARAM;
  2293. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
  2294. cmd->uplink_seid = cpu_to_le16(uplink_seid);
  2295. cmd->downlink_seid = cpu_to_le16(downlink_seid);
  2296. cmd->enable_tcs = enabled_tc;
  2297. if (!uplink_seid)
  2298. veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
  2299. if (default_port)
  2300. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
  2301. else
  2302. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
  2303. /* reverse logic here: set the bitflag to disable the stats */
  2304. if (!enable_stats)
  2305. veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
  2306. cmd->veb_flags = cpu_to_le16(veb_flags);
  2307. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2308. if (!status && veb_seid)
  2309. *veb_seid = le16_to_cpu(resp->veb_seid);
  2310. return status;
  2311. }
  2312. /**
  2313. * i40e_aq_get_veb_parameters - Retrieve VEB parameters
  2314. * @hw: pointer to the hw struct
  2315. * @veb_seid: the SEID of the VEB to query
  2316. * @switch_id: the uplink switch id
  2317. * @floating: set to true if the VEB is floating
  2318. * @statistic_index: index of the stats counter block for this VEB
  2319. * @vebs_used: number of VEB's used by function
  2320. * @vebs_free: total VEB's not reserved by any function
  2321. * @cmd_details: pointer to command details structure or NULL
  2322. *
  2323. * This retrieves the parameters for a particular VEB, specified by
  2324. * uplink_seid, and returns them to the caller.
  2325. **/
  2326. i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
  2327. u16 veb_seid, u16 *switch_id,
  2328. bool *floating, u16 *statistic_index,
  2329. u16 *vebs_used, u16 *vebs_free,
  2330. struct i40e_asq_cmd_details *cmd_details)
  2331. {
  2332. struct i40e_aq_desc desc;
  2333. struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
  2334. (struct i40e_aqc_get_veb_parameters_completion *)
  2335. &desc.params.raw;
  2336. i40e_status status;
  2337. if (veb_seid == 0)
  2338. return I40E_ERR_PARAM;
  2339. i40e_fill_default_direct_cmd_desc(&desc,
  2340. i40e_aqc_opc_get_veb_parameters);
  2341. cmd_resp->seid = cpu_to_le16(veb_seid);
  2342. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2343. if (status)
  2344. goto get_veb_exit;
  2345. if (switch_id)
  2346. *switch_id = le16_to_cpu(cmd_resp->switch_id);
  2347. if (statistic_index)
  2348. *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
  2349. if (vebs_used)
  2350. *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
  2351. if (vebs_free)
  2352. *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
  2353. if (floating) {
  2354. u16 flags = le16_to_cpu(cmd_resp->veb_flags);
  2355. if (flags & I40E_AQC_ADD_VEB_FLOATING)
  2356. *floating = true;
  2357. else
  2358. *floating = false;
  2359. }
  2360. get_veb_exit:
  2361. return status;
  2362. }
  2363. /**
  2364. * i40e_aq_add_macvlan
  2365. * @hw: pointer to the hw struct
  2366. * @seid: VSI for the mac address
  2367. * @mv_list: list of macvlans to be added
  2368. * @count: length of the list
  2369. * @cmd_details: pointer to command details structure or NULL
  2370. *
  2371. * Add MAC/VLAN addresses to the HW filtering
  2372. **/
  2373. i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
  2374. struct i40e_aqc_add_macvlan_element_data *mv_list,
  2375. u16 count, struct i40e_asq_cmd_details *cmd_details)
  2376. {
  2377. struct i40e_aq_desc desc;
  2378. struct i40e_aqc_macvlan *cmd =
  2379. (struct i40e_aqc_macvlan *)&desc.params.raw;
  2380. i40e_status status;
  2381. u16 buf_size;
  2382. int i;
  2383. if (count == 0 || !mv_list || !hw)
  2384. return I40E_ERR_PARAM;
  2385. buf_size = count * sizeof(*mv_list);
  2386. /* prep the rest of the request */
  2387. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
  2388. cmd->num_addresses = cpu_to_le16(count);
  2389. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  2390. cmd->seid[1] = 0;
  2391. cmd->seid[2] = 0;
  2392. for (i = 0; i < count; i++)
  2393. if (is_multicast_ether_addr(mv_list[i].mac_addr))
  2394. mv_list[i].flags |=
  2395. cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
  2396. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2397. if (buf_size > I40E_AQ_LARGE_BUF)
  2398. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2399. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  2400. cmd_details);
  2401. return status;
  2402. }
  2403. /**
  2404. * i40e_aq_remove_macvlan
  2405. * @hw: pointer to the hw struct
  2406. * @seid: VSI for the mac address
  2407. * @mv_list: list of macvlans to be removed
  2408. * @count: length of the list
  2409. * @cmd_details: pointer to command details structure or NULL
  2410. *
  2411. * Remove MAC/VLAN addresses from the HW filtering
  2412. **/
  2413. i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
  2414. struct i40e_aqc_remove_macvlan_element_data *mv_list,
  2415. u16 count, struct i40e_asq_cmd_details *cmd_details)
  2416. {
  2417. struct i40e_aq_desc desc;
  2418. struct i40e_aqc_macvlan *cmd =
  2419. (struct i40e_aqc_macvlan *)&desc.params.raw;
  2420. i40e_status status;
  2421. u16 buf_size;
  2422. if (count == 0 || !mv_list || !hw)
  2423. return I40E_ERR_PARAM;
  2424. buf_size = count * sizeof(*mv_list);
  2425. /* prep the rest of the request */
  2426. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
  2427. cmd->num_addresses = cpu_to_le16(count);
  2428. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  2429. cmd->seid[1] = 0;
  2430. cmd->seid[2] = 0;
  2431. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2432. if (buf_size > I40E_AQ_LARGE_BUF)
  2433. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2434. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  2435. cmd_details);
  2436. return status;
  2437. }
  2438. /**
  2439. * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
  2440. * @hw: pointer to the hw struct
  2441. * @opcode: AQ opcode for add or delete mirror rule
  2442. * @sw_seid: Switch SEID (to which rule refers)
  2443. * @rule_type: Rule Type (ingress/egress/VLAN)
  2444. * @id: Destination VSI SEID or Rule ID
  2445. * @count: length of the list
  2446. * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
  2447. * @cmd_details: pointer to command details structure or NULL
  2448. * @rule_id: Rule ID returned from FW
  2449. * @rule_used: Number of rules used in internal switch
  2450. * @rule_free: Number of rules free in internal switch
  2451. *
  2452. * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
  2453. * VEBs/VEPA elements only
  2454. **/
  2455. static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
  2456. u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
  2457. u16 count, __le16 *mr_list,
  2458. struct i40e_asq_cmd_details *cmd_details,
  2459. u16 *rule_id, u16 *rules_used, u16 *rules_free)
  2460. {
  2461. struct i40e_aq_desc desc;
  2462. struct i40e_aqc_add_delete_mirror_rule *cmd =
  2463. (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
  2464. struct i40e_aqc_add_delete_mirror_rule_completion *resp =
  2465. (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
  2466. i40e_status status;
  2467. u16 buf_size;
  2468. buf_size = count * sizeof(*mr_list);
  2469. /* prep the rest of the request */
  2470. i40e_fill_default_direct_cmd_desc(&desc, opcode);
  2471. cmd->seid = cpu_to_le16(sw_seid);
  2472. cmd->rule_type = cpu_to_le16(rule_type &
  2473. I40E_AQC_MIRROR_RULE_TYPE_MASK);
  2474. cmd->num_entries = cpu_to_le16(count);
  2475. /* Dest VSI for add, rule_id for delete */
  2476. cmd->destination = cpu_to_le16(id);
  2477. if (mr_list) {
  2478. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
  2479. I40E_AQ_FLAG_RD));
  2480. if (buf_size > I40E_AQ_LARGE_BUF)
  2481. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2482. }
  2483. status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
  2484. cmd_details);
  2485. if (!status ||
  2486. hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
  2487. if (rule_id)
  2488. *rule_id = le16_to_cpu(resp->rule_id);
  2489. if (rules_used)
  2490. *rules_used = le16_to_cpu(resp->mirror_rules_used);
  2491. if (rules_free)
  2492. *rules_free = le16_to_cpu(resp->mirror_rules_free);
  2493. }
  2494. return status;
  2495. }
  2496. /**
  2497. * i40e_aq_add_mirrorrule - add a mirror rule
  2498. * @hw: pointer to the hw struct
  2499. * @sw_seid: Switch SEID (to which rule refers)
  2500. * @rule_type: Rule Type (ingress/egress/VLAN)
  2501. * @dest_vsi: SEID of VSI to which packets will be mirrored
  2502. * @count: length of the list
  2503. * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
  2504. * @cmd_details: pointer to command details structure or NULL
  2505. * @rule_id: Rule ID returned from FW
  2506. * @rule_used: Number of rules used in internal switch
  2507. * @rule_free: Number of rules free in internal switch
  2508. *
  2509. * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
  2510. **/
  2511. i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
  2512. u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
  2513. struct i40e_asq_cmd_details *cmd_details,
  2514. u16 *rule_id, u16 *rules_used, u16 *rules_free)
  2515. {
  2516. if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
  2517. rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
  2518. if (count == 0 || !mr_list)
  2519. return I40E_ERR_PARAM;
  2520. }
  2521. return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
  2522. rule_type, dest_vsi, count, mr_list,
  2523. cmd_details, rule_id, rules_used, rules_free);
  2524. }
  2525. /**
  2526. * i40e_aq_delete_mirrorrule - delete a mirror rule
  2527. * @hw: pointer to the hw struct
  2528. * @sw_seid: Switch SEID (to which rule refers)
  2529. * @rule_type: Rule Type (ingress/egress/VLAN)
  2530. * @count: length of the list
  2531. * @rule_id: Rule ID that is returned in the receive desc as part of
  2532. * add_mirrorrule.
  2533. * @mr_list: list of mirrored VLAN IDs to be removed
  2534. * @cmd_details: pointer to command details structure or NULL
  2535. * @rule_used: Number of rules used in internal switch
  2536. * @rule_free: Number of rules free in internal switch
  2537. *
  2538. * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
  2539. **/
  2540. i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
  2541. u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
  2542. struct i40e_asq_cmd_details *cmd_details,
  2543. u16 *rules_used, u16 *rules_free)
  2544. {
  2545. /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
  2546. if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
  2547. /* count and mr_list shall be valid for rule_type INGRESS VLAN
  2548. * mirroring. For other rule_type, count and rule_type should
  2549. * not matter.
  2550. */
  2551. if (count == 0 || !mr_list)
  2552. return I40E_ERR_PARAM;
  2553. }
  2554. return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
  2555. rule_type, rule_id, count, mr_list,
  2556. cmd_details, NULL, rules_used, rules_free);
  2557. }
  2558. /**
  2559. * i40e_aq_send_msg_to_vf
  2560. * @hw: pointer to the hardware structure
  2561. * @vfid: VF id to send msg
  2562. * @v_opcode: opcodes for VF-PF communication
  2563. * @v_retval: return error code
  2564. * @msg: pointer to the msg buffer
  2565. * @msglen: msg length
  2566. * @cmd_details: pointer to command details
  2567. *
  2568. * send msg to vf
  2569. **/
  2570. i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
  2571. u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
  2572. struct i40e_asq_cmd_details *cmd_details)
  2573. {
  2574. struct i40e_aq_desc desc;
  2575. struct i40e_aqc_pf_vf_message *cmd =
  2576. (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
  2577. i40e_status status;
  2578. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
  2579. cmd->id = cpu_to_le32(vfid);
  2580. desc.cookie_high = cpu_to_le32(v_opcode);
  2581. desc.cookie_low = cpu_to_le32(v_retval);
  2582. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  2583. if (msglen) {
  2584. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
  2585. I40E_AQ_FLAG_RD));
  2586. if (msglen > I40E_AQ_LARGE_BUF)
  2587. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2588. desc.datalen = cpu_to_le16(msglen);
  2589. }
  2590. status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  2591. return status;
  2592. }
  2593. /**
  2594. * i40e_aq_debug_read_register
  2595. * @hw: pointer to the hw struct
  2596. * @reg_addr: register address
  2597. * @reg_val: register value
  2598. * @cmd_details: pointer to command details structure or NULL
  2599. *
  2600. * Read the register using the admin queue commands
  2601. **/
  2602. i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
  2603. u32 reg_addr, u64 *reg_val,
  2604. struct i40e_asq_cmd_details *cmd_details)
  2605. {
  2606. struct i40e_aq_desc desc;
  2607. struct i40e_aqc_debug_reg_read_write *cmd_resp =
  2608. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  2609. i40e_status status;
  2610. if (reg_val == NULL)
  2611. return I40E_ERR_PARAM;
  2612. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
  2613. cmd_resp->address = cpu_to_le32(reg_addr);
  2614. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2615. if (!status) {
  2616. *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
  2617. (u64)le32_to_cpu(cmd_resp->value_low);
  2618. }
  2619. return status;
  2620. }
  2621. /**
  2622. * i40e_aq_debug_write_register
  2623. * @hw: pointer to the hw struct
  2624. * @reg_addr: register address
  2625. * @reg_val: register value
  2626. * @cmd_details: pointer to command details structure or NULL
  2627. *
  2628. * Write to a register using the admin queue commands
  2629. **/
  2630. i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
  2631. u32 reg_addr, u64 reg_val,
  2632. struct i40e_asq_cmd_details *cmd_details)
  2633. {
  2634. struct i40e_aq_desc desc;
  2635. struct i40e_aqc_debug_reg_read_write *cmd =
  2636. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  2637. i40e_status status;
  2638. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
  2639. cmd->address = cpu_to_le32(reg_addr);
  2640. cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
  2641. cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
  2642. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2643. return status;
  2644. }
  2645. /**
  2646. * i40e_aq_request_resource
  2647. * @hw: pointer to the hw struct
  2648. * @resource: resource id
  2649. * @access: access type
  2650. * @sdp_number: resource number
  2651. * @timeout: the maximum time in ms that the driver may hold the resource
  2652. * @cmd_details: pointer to command details structure or NULL
  2653. *
  2654. * requests common resource using the admin queue commands
  2655. **/
  2656. i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
  2657. enum i40e_aq_resources_ids resource,
  2658. enum i40e_aq_resource_access_type access,
  2659. u8 sdp_number, u64 *timeout,
  2660. struct i40e_asq_cmd_details *cmd_details)
  2661. {
  2662. struct i40e_aq_desc desc;
  2663. struct i40e_aqc_request_resource *cmd_resp =
  2664. (struct i40e_aqc_request_resource *)&desc.params.raw;
  2665. i40e_status status;
  2666. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
  2667. cmd_resp->resource_id = cpu_to_le16(resource);
  2668. cmd_resp->access_type = cpu_to_le16(access);
  2669. cmd_resp->resource_number = cpu_to_le32(sdp_number);
  2670. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2671. /* The completion specifies the maximum time in ms that the driver
  2672. * may hold the resource in the Timeout field.
  2673. * If the resource is held by someone else, the command completes with
  2674. * busy return value and the timeout field indicates the maximum time
  2675. * the current owner of the resource has to free it.
  2676. */
  2677. if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
  2678. *timeout = le32_to_cpu(cmd_resp->timeout);
  2679. return status;
  2680. }
  2681. /**
  2682. * i40e_aq_release_resource
  2683. * @hw: pointer to the hw struct
  2684. * @resource: resource id
  2685. * @sdp_number: resource number
  2686. * @cmd_details: pointer to command details structure or NULL
  2687. *
  2688. * release common resource using the admin queue commands
  2689. **/
  2690. i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
  2691. enum i40e_aq_resources_ids resource,
  2692. u8 sdp_number,
  2693. struct i40e_asq_cmd_details *cmd_details)
  2694. {
  2695. struct i40e_aq_desc desc;
  2696. struct i40e_aqc_request_resource *cmd =
  2697. (struct i40e_aqc_request_resource *)&desc.params.raw;
  2698. i40e_status status;
  2699. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
  2700. cmd->resource_id = cpu_to_le16(resource);
  2701. cmd->resource_number = cpu_to_le32(sdp_number);
  2702. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2703. return status;
  2704. }
  2705. /**
  2706. * i40e_aq_read_nvm
  2707. * @hw: pointer to the hw struct
  2708. * @module_pointer: module pointer location in words from the NVM beginning
  2709. * @offset: byte offset from the module beginning
  2710. * @length: length of the section to be read (in bytes from the offset)
  2711. * @data: command buffer (size [bytes] = length)
  2712. * @last_command: tells if this is the last command in a series
  2713. * @cmd_details: pointer to command details structure or NULL
  2714. *
  2715. * Read the NVM using the admin queue commands
  2716. **/
  2717. i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
  2718. u32 offset, u16 length, void *data,
  2719. bool last_command,
  2720. struct i40e_asq_cmd_details *cmd_details)
  2721. {
  2722. struct i40e_aq_desc desc;
  2723. struct i40e_aqc_nvm_update *cmd =
  2724. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2725. i40e_status status;
  2726. /* In offset the highest byte must be zeroed. */
  2727. if (offset & 0xFF000000) {
  2728. status = I40E_ERR_PARAM;
  2729. goto i40e_aq_read_nvm_exit;
  2730. }
  2731. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
  2732. /* If this is the last command in a series, set the proper flag. */
  2733. if (last_command)
  2734. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2735. cmd->module_pointer = module_pointer;
  2736. cmd->offset = cpu_to_le32(offset);
  2737. cmd->length = cpu_to_le16(length);
  2738. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2739. if (length > I40E_AQ_LARGE_BUF)
  2740. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2741. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  2742. i40e_aq_read_nvm_exit:
  2743. return status;
  2744. }
  2745. /**
  2746. * i40e_aq_erase_nvm
  2747. * @hw: pointer to the hw struct
  2748. * @module_pointer: module pointer location in words from the NVM beginning
  2749. * @offset: offset in the module (expressed in 4 KB from module's beginning)
  2750. * @length: length of the section to be erased (expressed in 4 KB)
  2751. * @last_command: tells if this is the last command in a series
  2752. * @cmd_details: pointer to command details structure or NULL
  2753. *
  2754. * Erase the NVM sector using the admin queue commands
  2755. **/
  2756. i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
  2757. u32 offset, u16 length, bool last_command,
  2758. struct i40e_asq_cmd_details *cmd_details)
  2759. {
  2760. struct i40e_aq_desc desc;
  2761. struct i40e_aqc_nvm_update *cmd =
  2762. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2763. i40e_status status;
  2764. /* In offset the highest byte must be zeroed. */
  2765. if (offset & 0xFF000000) {
  2766. status = I40E_ERR_PARAM;
  2767. goto i40e_aq_erase_nvm_exit;
  2768. }
  2769. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
  2770. /* If this is the last command in a series, set the proper flag. */
  2771. if (last_command)
  2772. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2773. cmd->module_pointer = module_pointer;
  2774. cmd->offset = cpu_to_le32(offset);
  2775. cmd->length = cpu_to_le16(length);
  2776. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2777. i40e_aq_erase_nvm_exit:
  2778. return status;
  2779. }
  2780. /**
  2781. * i40e_parse_discover_capabilities
  2782. * @hw: pointer to the hw struct
  2783. * @buff: pointer to a buffer containing device/function capability records
  2784. * @cap_count: number of capability records in the list
  2785. * @list_type_opc: type of capabilities list to parse
  2786. *
  2787. * Parse the device/function capabilities list.
  2788. **/
  2789. static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
  2790. u32 cap_count,
  2791. enum i40e_admin_queue_opc list_type_opc)
  2792. {
  2793. struct i40e_aqc_list_capabilities_element_resp *cap;
  2794. u32 valid_functions, num_functions;
  2795. u32 number, logical_id, phys_id;
  2796. struct i40e_hw_capabilities *p;
  2797. u8 major_rev;
  2798. u32 i = 0;
  2799. u16 id;
  2800. cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
  2801. if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
  2802. p = &hw->dev_caps;
  2803. else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
  2804. p = &hw->func_caps;
  2805. else
  2806. return;
  2807. for (i = 0; i < cap_count; i++, cap++) {
  2808. id = le16_to_cpu(cap->id);
  2809. number = le32_to_cpu(cap->number);
  2810. logical_id = le32_to_cpu(cap->logical_id);
  2811. phys_id = le32_to_cpu(cap->phys_id);
  2812. major_rev = cap->major_rev;
  2813. switch (id) {
  2814. case I40E_AQ_CAP_ID_SWITCH_MODE:
  2815. p->switch_mode = number;
  2816. break;
  2817. case I40E_AQ_CAP_ID_MNG_MODE:
  2818. p->management_mode = number;
  2819. if (major_rev > 1) {
  2820. p->mng_protocols_over_mctp = logical_id;
  2821. i40e_debug(hw, I40E_DEBUG_INIT,
  2822. "HW Capability: Protocols over MCTP = %d\n",
  2823. p->mng_protocols_over_mctp);
  2824. } else {
  2825. p->mng_protocols_over_mctp = 0;
  2826. }
  2827. break;
  2828. case I40E_AQ_CAP_ID_NPAR_ACTIVE:
  2829. p->npar_enable = number;
  2830. break;
  2831. case I40E_AQ_CAP_ID_OS2BMC_CAP:
  2832. p->os2bmc = number;
  2833. break;
  2834. case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
  2835. p->valid_functions = number;
  2836. break;
  2837. case I40E_AQ_CAP_ID_SRIOV:
  2838. if (number == 1)
  2839. p->sr_iov_1_1 = true;
  2840. break;
  2841. case I40E_AQ_CAP_ID_VF:
  2842. p->num_vfs = number;
  2843. p->vf_base_id = logical_id;
  2844. break;
  2845. case I40E_AQ_CAP_ID_VMDQ:
  2846. if (number == 1)
  2847. p->vmdq = true;
  2848. break;
  2849. case I40E_AQ_CAP_ID_8021QBG:
  2850. if (number == 1)
  2851. p->evb_802_1_qbg = true;
  2852. break;
  2853. case I40E_AQ_CAP_ID_8021QBR:
  2854. if (number == 1)
  2855. p->evb_802_1_qbh = true;
  2856. break;
  2857. case I40E_AQ_CAP_ID_VSI:
  2858. p->num_vsis = number;
  2859. break;
  2860. case I40E_AQ_CAP_ID_DCB:
  2861. if (number == 1) {
  2862. p->dcb = true;
  2863. p->enabled_tcmap = logical_id;
  2864. p->maxtc = phys_id;
  2865. }
  2866. break;
  2867. case I40E_AQ_CAP_ID_FCOE:
  2868. if (number == 1)
  2869. p->fcoe = true;
  2870. break;
  2871. case I40E_AQ_CAP_ID_ISCSI:
  2872. if (number == 1)
  2873. p->iscsi = true;
  2874. break;
  2875. case I40E_AQ_CAP_ID_RSS:
  2876. p->rss = true;
  2877. p->rss_table_size = number;
  2878. p->rss_table_entry_width = logical_id;
  2879. break;
  2880. case I40E_AQ_CAP_ID_RXQ:
  2881. p->num_rx_qp = number;
  2882. p->base_queue = phys_id;
  2883. break;
  2884. case I40E_AQ_CAP_ID_TXQ:
  2885. p->num_tx_qp = number;
  2886. p->base_queue = phys_id;
  2887. break;
  2888. case I40E_AQ_CAP_ID_MSIX:
  2889. p->num_msix_vectors = number;
  2890. i40e_debug(hw, I40E_DEBUG_INIT,
  2891. "HW Capability: MSIX vector count = %d\n",
  2892. p->num_msix_vectors);
  2893. break;
  2894. case I40E_AQ_CAP_ID_VF_MSIX:
  2895. p->num_msix_vectors_vf = number;
  2896. break;
  2897. case I40E_AQ_CAP_ID_FLEX10:
  2898. if (major_rev == 1) {
  2899. if (number == 1) {
  2900. p->flex10_enable = true;
  2901. p->flex10_capable = true;
  2902. }
  2903. } else {
  2904. /* Capability revision >= 2 */
  2905. if (number & 1)
  2906. p->flex10_enable = true;
  2907. if (number & 2)
  2908. p->flex10_capable = true;
  2909. }
  2910. p->flex10_mode = logical_id;
  2911. p->flex10_status = phys_id;
  2912. break;
  2913. case I40E_AQ_CAP_ID_CEM:
  2914. if (number == 1)
  2915. p->mgmt_cem = true;
  2916. break;
  2917. case I40E_AQ_CAP_ID_IWARP:
  2918. if (number == 1)
  2919. p->iwarp = true;
  2920. break;
  2921. case I40E_AQ_CAP_ID_LED:
  2922. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2923. p->led[phys_id] = true;
  2924. break;
  2925. case I40E_AQ_CAP_ID_SDP:
  2926. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2927. p->sdp[phys_id] = true;
  2928. break;
  2929. case I40E_AQ_CAP_ID_MDIO:
  2930. if (number == 1) {
  2931. p->mdio_port_num = phys_id;
  2932. p->mdio_port_mode = logical_id;
  2933. }
  2934. break;
  2935. case I40E_AQ_CAP_ID_1588:
  2936. if (number == 1)
  2937. p->ieee_1588 = true;
  2938. break;
  2939. case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
  2940. p->fd = true;
  2941. p->fd_filters_guaranteed = number;
  2942. p->fd_filters_best_effort = logical_id;
  2943. break;
  2944. case I40E_AQ_CAP_ID_WSR_PROT:
  2945. p->wr_csr_prot = (u64)number;
  2946. p->wr_csr_prot |= (u64)logical_id << 32;
  2947. break;
  2948. case I40E_AQ_CAP_ID_NVM_MGMT:
  2949. if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
  2950. p->sec_rev_disabled = true;
  2951. if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
  2952. p->update_disabled = true;
  2953. break;
  2954. default:
  2955. break;
  2956. }
  2957. }
  2958. if (p->fcoe)
  2959. i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
  2960. /* Software override ensuring FCoE is disabled if npar or mfp
  2961. * mode because it is not supported in these modes.
  2962. */
  2963. if (p->npar_enable || p->flex10_enable)
  2964. p->fcoe = false;
  2965. /* count the enabled ports (aka the "not disabled" ports) */
  2966. hw->num_ports = 0;
  2967. for (i = 0; i < 4; i++) {
  2968. u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
  2969. u64 port_cfg = 0;
  2970. /* use AQ read to get the physical register offset instead
  2971. * of the port relative offset
  2972. */
  2973. i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
  2974. if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
  2975. hw->num_ports++;
  2976. }
  2977. valid_functions = p->valid_functions;
  2978. num_functions = 0;
  2979. while (valid_functions) {
  2980. if (valid_functions & 1)
  2981. num_functions++;
  2982. valid_functions >>= 1;
  2983. }
  2984. /* partition id is 1-based, and functions are evenly spread
  2985. * across the ports as partitions
  2986. */
  2987. if (hw->num_ports != 0) {
  2988. hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
  2989. hw->num_partitions = num_functions / hw->num_ports;
  2990. }
  2991. /* additional HW specific goodies that might
  2992. * someday be HW version specific
  2993. */
  2994. p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
  2995. }
  2996. /**
  2997. * i40e_aq_discover_capabilities
  2998. * @hw: pointer to the hw struct
  2999. * @buff: a virtual buffer to hold the capabilities
  3000. * @buff_size: Size of the virtual buffer
  3001. * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
  3002. * @list_type_opc: capabilities type to discover - pass in the command opcode
  3003. * @cmd_details: pointer to command details structure or NULL
  3004. *
  3005. * Get the device capabilities descriptions from the firmware
  3006. **/
  3007. i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
  3008. void *buff, u16 buff_size, u16 *data_size,
  3009. enum i40e_admin_queue_opc list_type_opc,
  3010. struct i40e_asq_cmd_details *cmd_details)
  3011. {
  3012. struct i40e_aqc_list_capabilites *cmd;
  3013. struct i40e_aq_desc desc;
  3014. i40e_status status = 0;
  3015. cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
  3016. if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
  3017. list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
  3018. status = I40E_ERR_PARAM;
  3019. goto exit;
  3020. }
  3021. i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
  3022. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3023. if (buff_size > I40E_AQ_LARGE_BUF)
  3024. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3025. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  3026. *data_size = le16_to_cpu(desc.datalen);
  3027. if (status)
  3028. goto exit;
  3029. i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
  3030. list_type_opc);
  3031. exit:
  3032. return status;
  3033. }
  3034. /**
  3035. * i40e_aq_update_nvm
  3036. * @hw: pointer to the hw struct
  3037. * @module_pointer: module pointer location in words from the NVM beginning
  3038. * @offset: byte offset from the module beginning
  3039. * @length: length of the section to be written (in bytes from the offset)
  3040. * @data: command buffer (size [bytes] = length)
  3041. * @last_command: tells if this is the last command in a series
  3042. * @cmd_details: pointer to command details structure or NULL
  3043. *
  3044. * Update the NVM using the admin queue commands
  3045. **/
  3046. i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
  3047. u32 offset, u16 length, void *data,
  3048. bool last_command,
  3049. struct i40e_asq_cmd_details *cmd_details)
  3050. {
  3051. struct i40e_aq_desc desc;
  3052. struct i40e_aqc_nvm_update *cmd =
  3053. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  3054. i40e_status status;
  3055. /* In offset the highest byte must be zeroed. */
  3056. if (offset & 0xFF000000) {
  3057. status = I40E_ERR_PARAM;
  3058. goto i40e_aq_update_nvm_exit;
  3059. }
  3060. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
  3061. /* If this is the last command in a series, set the proper flag. */
  3062. if (last_command)
  3063. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  3064. cmd->module_pointer = module_pointer;
  3065. cmd->offset = cpu_to_le32(offset);
  3066. cmd->length = cpu_to_le16(length);
  3067. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  3068. if (length > I40E_AQ_LARGE_BUF)
  3069. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3070. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  3071. i40e_aq_update_nvm_exit:
  3072. return status;
  3073. }
  3074. /**
  3075. * i40e_aq_get_lldp_mib
  3076. * @hw: pointer to the hw struct
  3077. * @bridge_type: type of bridge requested
  3078. * @mib_type: Local, Remote or both Local and Remote MIBs
  3079. * @buff: pointer to a user supplied buffer to store the MIB block
  3080. * @buff_size: size of the buffer (in bytes)
  3081. * @local_len : length of the returned Local LLDP MIB
  3082. * @remote_len: length of the returned Remote LLDP MIB
  3083. * @cmd_details: pointer to command details structure or NULL
  3084. *
  3085. * Requests the complete LLDP MIB (entire packet).
  3086. **/
  3087. i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
  3088. u8 mib_type, void *buff, u16 buff_size,
  3089. u16 *local_len, u16 *remote_len,
  3090. struct i40e_asq_cmd_details *cmd_details)
  3091. {
  3092. struct i40e_aq_desc desc;
  3093. struct i40e_aqc_lldp_get_mib *cmd =
  3094. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  3095. struct i40e_aqc_lldp_get_mib *resp =
  3096. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  3097. i40e_status status;
  3098. if (buff_size == 0 || !buff)
  3099. return I40E_ERR_PARAM;
  3100. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
  3101. /* Indirect Command */
  3102. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3103. cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  3104. cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
  3105. I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  3106. desc.datalen = cpu_to_le16(buff_size);
  3107. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3108. if (buff_size > I40E_AQ_LARGE_BUF)
  3109. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3110. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  3111. if (!status) {
  3112. if (local_len != NULL)
  3113. *local_len = le16_to_cpu(resp->local_len);
  3114. if (remote_len != NULL)
  3115. *remote_len = le16_to_cpu(resp->remote_len);
  3116. }
  3117. return status;
  3118. }
  3119. /**
  3120. * i40e_aq_cfg_lldp_mib_change_event
  3121. * @hw: pointer to the hw struct
  3122. * @enable_update: Enable or Disable event posting
  3123. * @cmd_details: pointer to command details structure or NULL
  3124. *
  3125. * Enable or Disable posting of an event on ARQ when LLDP MIB
  3126. * associated with the interface changes
  3127. **/
  3128. i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
  3129. bool enable_update,
  3130. struct i40e_asq_cmd_details *cmd_details)
  3131. {
  3132. struct i40e_aq_desc desc;
  3133. struct i40e_aqc_lldp_update_mib *cmd =
  3134. (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
  3135. i40e_status status;
  3136. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
  3137. if (!enable_update)
  3138. cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
  3139. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3140. return status;
  3141. }
  3142. /**
  3143. * i40e_aq_stop_lldp
  3144. * @hw: pointer to the hw struct
  3145. * @shutdown_agent: True if LLDP Agent needs to be Shutdown
  3146. * @cmd_details: pointer to command details structure or NULL
  3147. *
  3148. * Stop or Shutdown the embedded LLDP Agent
  3149. **/
  3150. i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
  3151. struct i40e_asq_cmd_details *cmd_details)
  3152. {
  3153. struct i40e_aq_desc desc;
  3154. struct i40e_aqc_lldp_stop *cmd =
  3155. (struct i40e_aqc_lldp_stop *)&desc.params.raw;
  3156. i40e_status status;
  3157. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
  3158. if (shutdown_agent)
  3159. cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
  3160. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3161. return status;
  3162. }
  3163. /**
  3164. * i40e_aq_start_lldp
  3165. * @hw: pointer to the hw struct
  3166. * @cmd_details: pointer to command details structure or NULL
  3167. *
  3168. * Start the embedded LLDP Agent on all ports.
  3169. **/
  3170. i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
  3171. struct i40e_asq_cmd_details *cmd_details)
  3172. {
  3173. struct i40e_aq_desc desc;
  3174. struct i40e_aqc_lldp_start *cmd =
  3175. (struct i40e_aqc_lldp_start *)&desc.params.raw;
  3176. i40e_status status;
  3177. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
  3178. cmd->command = I40E_AQ_LLDP_AGENT_START;
  3179. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3180. return status;
  3181. }
  3182. /**
  3183. * i40e_aq_get_cee_dcb_config
  3184. * @hw: pointer to the hw struct
  3185. * @buff: response buffer that stores CEE operational configuration
  3186. * @buff_size: size of the buffer passed
  3187. * @cmd_details: pointer to command details structure or NULL
  3188. *
  3189. * Get CEE DCBX mode operational configuration from firmware
  3190. **/
  3191. i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
  3192. void *buff, u16 buff_size,
  3193. struct i40e_asq_cmd_details *cmd_details)
  3194. {
  3195. struct i40e_aq_desc desc;
  3196. i40e_status status;
  3197. if (buff_size == 0 || !buff)
  3198. return I40E_ERR_PARAM;
  3199. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
  3200. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3201. status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
  3202. cmd_details);
  3203. return status;
  3204. }
  3205. /**
  3206. * i40e_aq_add_udp_tunnel
  3207. * @hw: pointer to the hw struct
  3208. * @udp_port: the UDP port to add in Host byte order
  3209. * @header_len: length of the tunneling header length in DWords
  3210. * @protocol_index: protocol index type
  3211. * @filter_index: pointer to filter index
  3212. * @cmd_details: pointer to command details structure or NULL
  3213. *
  3214. * Note: Firmware expects the udp_port value to be in Little Endian format,
  3215. * and this function will call cpu_to_le16 to convert from Host byte order to
  3216. * Little Endian order.
  3217. **/
  3218. i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
  3219. u16 udp_port, u8 protocol_index,
  3220. u8 *filter_index,
  3221. struct i40e_asq_cmd_details *cmd_details)
  3222. {
  3223. struct i40e_aq_desc desc;
  3224. struct i40e_aqc_add_udp_tunnel *cmd =
  3225. (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
  3226. struct i40e_aqc_del_udp_tunnel_completion *resp =
  3227. (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
  3228. i40e_status status;
  3229. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
  3230. cmd->udp_port = cpu_to_le16(udp_port);
  3231. cmd->protocol_type = protocol_index;
  3232. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3233. if (!status && filter_index)
  3234. *filter_index = resp->index;
  3235. return status;
  3236. }
  3237. /**
  3238. * i40e_aq_del_udp_tunnel
  3239. * @hw: pointer to the hw struct
  3240. * @index: filter index
  3241. * @cmd_details: pointer to command details structure or NULL
  3242. **/
  3243. i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
  3244. struct i40e_asq_cmd_details *cmd_details)
  3245. {
  3246. struct i40e_aq_desc desc;
  3247. struct i40e_aqc_remove_udp_tunnel *cmd =
  3248. (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
  3249. i40e_status status;
  3250. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
  3251. cmd->index = index;
  3252. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3253. return status;
  3254. }
  3255. /**
  3256. * i40e_aq_delete_element - Delete switch element
  3257. * @hw: pointer to the hw struct
  3258. * @seid: the SEID to delete from the switch
  3259. * @cmd_details: pointer to command details structure or NULL
  3260. *
  3261. * This deletes a switch element from the switch.
  3262. **/
  3263. i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
  3264. struct i40e_asq_cmd_details *cmd_details)
  3265. {
  3266. struct i40e_aq_desc desc;
  3267. struct i40e_aqc_switch_seid *cmd =
  3268. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  3269. i40e_status status;
  3270. if (seid == 0)
  3271. return I40E_ERR_PARAM;
  3272. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
  3273. cmd->seid = cpu_to_le16(seid);
  3274. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3275. return status;
  3276. }
  3277. /**
  3278. * i40e_aq_dcb_updated - DCB Updated Command
  3279. * @hw: pointer to the hw struct
  3280. * @cmd_details: pointer to command details structure or NULL
  3281. *
  3282. * EMP will return when the shared RPB settings have been
  3283. * recomputed and modified. The retval field in the descriptor
  3284. * will be set to 0 when RPB is modified.
  3285. **/
  3286. i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
  3287. struct i40e_asq_cmd_details *cmd_details)
  3288. {
  3289. struct i40e_aq_desc desc;
  3290. i40e_status status;
  3291. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
  3292. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3293. return status;
  3294. }
  3295. /**
  3296. * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
  3297. * @hw: pointer to the hw struct
  3298. * @seid: seid for the physical port/switching component/vsi
  3299. * @buff: Indirect buffer to hold data parameters and response
  3300. * @buff_size: Indirect buffer size
  3301. * @opcode: Tx scheduler AQ command opcode
  3302. * @cmd_details: pointer to command details structure or NULL
  3303. *
  3304. * Generic command handler for Tx scheduler AQ commands
  3305. **/
  3306. static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
  3307. void *buff, u16 buff_size,
  3308. enum i40e_admin_queue_opc opcode,
  3309. struct i40e_asq_cmd_details *cmd_details)
  3310. {
  3311. struct i40e_aq_desc desc;
  3312. struct i40e_aqc_tx_sched_ind *cmd =
  3313. (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
  3314. i40e_status status;
  3315. bool cmd_param_flag = false;
  3316. switch (opcode) {
  3317. case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
  3318. case i40e_aqc_opc_configure_vsi_tc_bw:
  3319. case i40e_aqc_opc_enable_switching_comp_ets:
  3320. case i40e_aqc_opc_modify_switching_comp_ets:
  3321. case i40e_aqc_opc_disable_switching_comp_ets:
  3322. case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
  3323. case i40e_aqc_opc_configure_switching_comp_bw_config:
  3324. cmd_param_flag = true;
  3325. break;
  3326. case i40e_aqc_opc_query_vsi_bw_config:
  3327. case i40e_aqc_opc_query_vsi_ets_sla_config:
  3328. case i40e_aqc_opc_query_switching_comp_ets_config:
  3329. case i40e_aqc_opc_query_port_ets_config:
  3330. case i40e_aqc_opc_query_switching_comp_bw_config:
  3331. cmd_param_flag = false;
  3332. break;
  3333. default:
  3334. return I40E_ERR_PARAM;
  3335. }
  3336. i40e_fill_default_direct_cmd_desc(&desc, opcode);
  3337. /* Indirect command */
  3338. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3339. if (cmd_param_flag)
  3340. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  3341. if (buff_size > I40E_AQ_LARGE_BUF)
  3342. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3343. desc.datalen = cpu_to_le16(buff_size);
  3344. cmd->vsi_seid = cpu_to_le16(seid);
  3345. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  3346. return status;
  3347. }
  3348. /**
  3349. * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
  3350. * @hw: pointer to the hw struct
  3351. * @seid: VSI seid
  3352. * @credit: BW limit credits (0 = disabled)
  3353. * @max_credit: Max BW limit credits
  3354. * @cmd_details: pointer to command details structure or NULL
  3355. **/
  3356. i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
  3357. u16 seid, u16 credit, u8 max_credit,
  3358. struct i40e_asq_cmd_details *cmd_details)
  3359. {
  3360. struct i40e_aq_desc desc;
  3361. struct i40e_aqc_configure_vsi_bw_limit *cmd =
  3362. (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
  3363. i40e_status status;
  3364. i40e_fill_default_direct_cmd_desc(&desc,
  3365. i40e_aqc_opc_configure_vsi_bw_limit);
  3366. cmd->vsi_seid = cpu_to_le16(seid);
  3367. cmd->credit = cpu_to_le16(credit);
  3368. cmd->max_credit = max_credit;
  3369. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3370. return status;
  3371. }
  3372. /**
  3373. * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
  3374. * @hw: pointer to the hw struct
  3375. * @seid: VSI seid
  3376. * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
  3377. * @cmd_details: pointer to command details structure or NULL
  3378. **/
  3379. i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
  3380. u16 seid,
  3381. struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
  3382. struct i40e_asq_cmd_details *cmd_details)
  3383. {
  3384. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3385. i40e_aqc_opc_configure_vsi_tc_bw,
  3386. cmd_details);
  3387. }
  3388. /**
  3389. * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
  3390. * @hw: pointer to the hw struct
  3391. * @seid: seid of the switching component connected to Physical Port
  3392. * @ets_data: Buffer holding ETS parameters
  3393. * @cmd_details: pointer to command details structure or NULL
  3394. **/
  3395. i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
  3396. u16 seid,
  3397. struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
  3398. enum i40e_admin_queue_opc opcode,
  3399. struct i40e_asq_cmd_details *cmd_details)
  3400. {
  3401. return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
  3402. sizeof(*ets_data), opcode, cmd_details);
  3403. }
  3404. /**
  3405. * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
  3406. * @hw: pointer to the hw struct
  3407. * @seid: seid of the switching component
  3408. * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
  3409. * @cmd_details: pointer to command details structure or NULL
  3410. **/
  3411. i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
  3412. u16 seid,
  3413. struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
  3414. struct i40e_asq_cmd_details *cmd_details)
  3415. {
  3416. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3417. i40e_aqc_opc_configure_switching_comp_bw_config,
  3418. cmd_details);
  3419. }
  3420. /**
  3421. * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
  3422. * @hw: pointer to the hw struct
  3423. * @seid: seid of the VSI
  3424. * @bw_data: Buffer to hold VSI BW configuration
  3425. * @cmd_details: pointer to command details structure or NULL
  3426. **/
  3427. i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
  3428. u16 seid,
  3429. struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
  3430. struct i40e_asq_cmd_details *cmd_details)
  3431. {
  3432. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3433. i40e_aqc_opc_query_vsi_bw_config,
  3434. cmd_details);
  3435. }
  3436. /**
  3437. * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
  3438. * @hw: pointer to the hw struct
  3439. * @seid: seid of the VSI
  3440. * @bw_data: Buffer to hold VSI BW configuration per TC
  3441. * @cmd_details: pointer to command details structure or NULL
  3442. **/
  3443. i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
  3444. u16 seid,
  3445. struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
  3446. struct i40e_asq_cmd_details *cmd_details)
  3447. {
  3448. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3449. i40e_aqc_opc_query_vsi_ets_sla_config,
  3450. cmd_details);
  3451. }
  3452. /**
  3453. * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
  3454. * @hw: pointer to the hw struct
  3455. * @seid: seid of the switching component
  3456. * @bw_data: Buffer to hold switching component's per TC BW config
  3457. * @cmd_details: pointer to command details structure or NULL
  3458. **/
  3459. i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
  3460. u16 seid,
  3461. struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
  3462. struct i40e_asq_cmd_details *cmd_details)
  3463. {
  3464. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3465. i40e_aqc_opc_query_switching_comp_ets_config,
  3466. cmd_details);
  3467. }
  3468. /**
  3469. * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
  3470. * @hw: pointer to the hw struct
  3471. * @seid: seid of the VSI or switching component connected to Physical Port
  3472. * @bw_data: Buffer to hold current ETS configuration for the Physical Port
  3473. * @cmd_details: pointer to command details structure or NULL
  3474. **/
  3475. i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
  3476. u16 seid,
  3477. struct i40e_aqc_query_port_ets_config_resp *bw_data,
  3478. struct i40e_asq_cmd_details *cmd_details)
  3479. {
  3480. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3481. i40e_aqc_opc_query_port_ets_config,
  3482. cmd_details);
  3483. }
  3484. /**
  3485. * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
  3486. * @hw: pointer to the hw struct
  3487. * @seid: seid of the switching component
  3488. * @bw_data: Buffer to hold switching component's BW configuration
  3489. * @cmd_details: pointer to command details structure or NULL
  3490. **/
  3491. i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
  3492. u16 seid,
  3493. struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
  3494. struct i40e_asq_cmd_details *cmd_details)
  3495. {
  3496. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3497. i40e_aqc_opc_query_switching_comp_bw_config,
  3498. cmd_details);
  3499. }
  3500. /**
  3501. * i40e_validate_filter_settings
  3502. * @hw: pointer to the hardware structure
  3503. * @settings: Filter control settings
  3504. *
  3505. * Check and validate the filter control settings passed.
  3506. * The function checks for the valid filter/context sizes being
  3507. * passed for FCoE and PE.
  3508. *
  3509. * Returns 0 if the values passed are valid and within
  3510. * range else returns an error.
  3511. **/
  3512. static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
  3513. struct i40e_filter_control_settings *settings)
  3514. {
  3515. u32 fcoe_cntx_size, fcoe_filt_size;
  3516. u32 pe_cntx_size, pe_filt_size;
  3517. u32 fcoe_fmax;
  3518. u32 val;
  3519. /* Validate FCoE settings passed */
  3520. switch (settings->fcoe_filt_num) {
  3521. case I40E_HASH_FILTER_SIZE_1K:
  3522. case I40E_HASH_FILTER_SIZE_2K:
  3523. case I40E_HASH_FILTER_SIZE_4K:
  3524. case I40E_HASH_FILTER_SIZE_8K:
  3525. case I40E_HASH_FILTER_SIZE_16K:
  3526. case I40E_HASH_FILTER_SIZE_32K:
  3527. fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  3528. fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
  3529. break;
  3530. default:
  3531. return I40E_ERR_PARAM;
  3532. }
  3533. switch (settings->fcoe_cntx_num) {
  3534. case I40E_DMA_CNTX_SIZE_512:
  3535. case I40E_DMA_CNTX_SIZE_1K:
  3536. case I40E_DMA_CNTX_SIZE_2K:
  3537. case I40E_DMA_CNTX_SIZE_4K:
  3538. fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  3539. fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
  3540. break;
  3541. default:
  3542. return I40E_ERR_PARAM;
  3543. }
  3544. /* Validate PE settings passed */
  3545. switch (settings->pe_filt_num) {
  3546. case I40E_HASH_FILTER_SIZE_1K:
  3547. case I40E_HASH_FILTER_SIZE_2K:
  3548. case I40E_HASH_FILTER_SIZE_4K:
  3549. case I40E_HASH_FILTER_SIZE_8K:
  3550. case I40E_HASH_FILTER_SIZE_16K:
  3551. case I40E_HASH_FILTER_SIZE_32K:
  3552. case I40E_HASH_FILTER_SIZE_64K:
  3553. case I40E_HASH_FILTER_SIZE_128K:
  3554. case I40E_HASH_FILTER_SIZE_256K:
  3555. case I40E_HASH_FILTER_SIZE_512K:
  3556. case I40E_HASH_FILTER_SIZE_1M:
  3557. pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  3558. pe_filt_size <<= (u32)settings->pe_filt_num;
  3559. break;
  3560. default:
  3561. return I40E_ERR_PARAM;
  3562. }
  3563. switch (settings->pe_cntx_num) {
  3564. case I40E_DMA_CNTX_SIZE_512:
  3565. case I40E_DMA_CNTX_SIZE_1K:
  3566. case I40E_DMA_CNTX_SIZE_2K:
  3567. case I40E_DMA_CNTX_SIZE_4K:
  3568. case I40E_DMA_CNTX_SIZE_8K:
  3569. case I40E_DMA_CNTX_SIZE_16K:
  3570. case I40E_DMA_CNTX_SIZE_32K:
  3571. case I40E_DMA_CNTX_SIZE_64K:
  3572. case I40E_DMA_CNTX_SIZE_128K:
  3573. case I40E_DMA_CNTX_SIZE_256K:
  3574. pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  3575. pe_cntx_size <<= (u32)settings->pe_cntx_num;
  3576. break;
  3577. default:
  3578. return I40E_ERR_PARAM;
  3579. }
  3580. /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
  3581. val = rd32(hw, I40E_GLHMC_FCOEFMAX);
  3582. fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
  3583. >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
  3584. if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
  3585. return I40E_ERR_INVALID_SIZE;
  3586. return 0;
  3587. }
  3588. /**
  3589. * i40e_set_filter_control
  3590. * @hw: pointer to the hardware structure
  3591. * @settings: Filter control settings
  3592. *
  3593. * Set the Queue Filters for PE/FCoE and enable filters required
  3594. * for a single PF. It is expected that these settings are programmed
  3595. * at the driver initialization time.
  3596. **/
  3597. i40e_status i40e_set_filter_control(struct i40e_hw *hw,
  3598. struct i40e_filter_control_settings *settings)
  3599. {
  3600. i40e_status ret = 0;
  3601. u32 hash_lut_size = 0;
  3602. u32 val;
  3603. if (!settings)
  3604. return I40E_ERR_PARAM;
  3605. /* Validate the input settings */
  3606. ret = i40e_validate_filter_settings(hw, settings);
  3607. if (ret)
  3608. return ret;
  3609. /* Read the PF Queue Filter control register */
  3610. val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  3611. /* Program required PE hash buckets for the PF */
  3612. val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
  3613. val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
  3614. I40E_PFQF_CTL_0_PEHSIZE_MASK;
  3615. /* Program required PE contexts for the PF */
  3616. val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
  3617. val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
  3618. I40E_PFQF_CTL_0_PEDSIZE_MASK;
  3619. /* Program required FCoE hash buckets for the PF */
  3620. val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  3621. val |= ((u32)settings->fcoe_filt_num <<
  3622. I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
  3623. I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  3624. /* Program required FCoE DDP contexts for the PF */
  3625. val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  3626. val |= ((u32)settings->fcoe_cntx_num <<
  3627. I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
  3628. I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  3629. /* Program Hash LUT size for the PF */
  3630. val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  3631. if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
  3632. hash_lut_size = 1;
  3633. val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
  3634. I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  3635. /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
  3636. if (settings->enable_fdir)
  3637. val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
  3638. if (settings->enable_ethtype)
  3639. val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
  3640. if (settings->enable_macvlan)
  3641. val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
  3642. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
  3643. return 0;
  3644. }
  3645. /**
  3646. * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
  3647. * @hw: pointer to the hw struct
  3648. * @mac_addr: MAC address to use in the filter
  3649. * @ethtype: Ethertype to use in the filter
  3650. * @flags: Flags that needs to be applied to the filter
  3651. * @vsi_seid: seid of the control VSI
  3652. * @queue: VSI queue number to send the packet to
  3653. * @is_add: Add control packet filter if True else remove
  3654. * @stats: Structure to hold information on control filter counts
  3655. * @cmd_details: pointer to command details structure or NULL
  3656. *
  3657. * This command will Add or Remove control packet filter for a control VSI.
  3658. * In return it will update the total number of perfect filter count in
  3659. * the stats member.
  3660. **/
  3661. i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
  3662. u8 *mac_addr, u16 ethtype, u16 flags,
  3663. u16 vsi_seid, u16 queue, bool is_add,
  3664. struct i40e_control_filter_stats *stats,
  3665. struct i40e_asq_cmd_details *cmd_details)
  3666. {
  3667. struct i40e_aq_desc desc;
  3668. struct i40e_aqc_add_remove_control_packet_filter *cmd =
  3669. (struct i40e_aqc_add_remove_control_packet_filter *)
  3670. &desc.params.raw;
  3671. struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
  3672. (struct i40e_aqc_add_remove_control_packet_filter_completion *)
  3673. &desc.params.raw;
  3674. i40e_status status;
  3675. if (vsi_seid == 0)
  3676. return I40E_ERR_PARAM;
  3677. if (is_add) {
  3678. i40e_fill_default_direct_cmd_desc(&desc,
  3679. i40e_aqc_opc_add_control_packet_filter);
  3680. cmd->queue = cpu_to_le16(queue);
  3681. } else {
  3682. i40e_fill_default_direct_cmd_desc(&desc,
  3683. i40e_aqc_opc_remove_control_packet_filter);
  3684. }
  3685. if (mac_addr)
  3686. ether_addr_copy(cmd->mac, mac_addr);
  3687. cmd->etype = cpu_to_le16(ethtype);
  3688. cmd->flags = cpu_to_le16(flags);
  3689. cmd->seid = cpu_to_le16(vsi_seid);
  3690. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3691. if (!status && stats) {
  3692. stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
  3693. stats->etype_used = le16_to_cpu(resp->etype_used);
  3694. stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
  3695. stats->etype_free = le16_to_cpu(resp->etype_free);
  3696. }
  3697. return status;
  3698. }
  3699. /**
  3700. * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
  3701. * @hw: pointer to the hw struct
  3702. * @seid: VSI seid to add ethertype filter from
  3703. **/
  3704. #define I40E_FLOW_CONTROL_ETHTYPE 0x8808
  3705. void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
  3706. u16 seid)
  3707. {
  3708. u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
  3709. I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
  3710. I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
  3711. u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
  3712. i40e_status status;
  3713. status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
  3714. seid, 0, true, NULL,
  3715. NULL);
  3716. if (status)
  3717. hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
  3718. }
  3719. /**
  3720. * i40e_aq_alternate_read
  3721. * @hw: pointer to the hardware structure
  3722. * @reg_addr0: address of first dword to be read
  3723. * @reg_val0: pointer for data read from 'reg_addr0'
  3724. * @reg_addr1: address of second dword to be read
  3725. * @reg_val1: pointer for data read from 'reg_addr1'
  3726. *
  3727. * Read one or two dwords from alternate structure. Fields are indicated
  3728. * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
  3729. * is not passed then only register at 'reg_addr0' is read.
  3730. *
  3731. **/
  3732. static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
  3733. u32 reg_addr0, u32 *reg_val0,
  3734. u32 reg_addr1, u32 *reg_val1)
  3735. {
  3736. struct i40e_aq_desc desc;
  3737. struct i40e_aqc_alternate_write *cmd_resp =
  3738. (struct i40e_aqc_alternate_write *)&desc.params.raw;
  3739. i40e_status status;
  3740. if (!reg_val0)
  3741. return I40E_ERR_PARAM;
  3742. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
  3743. cmd_resp->address0 = cpu_to_le32(reg_addr0);
  3744. cmd_resp->address1 = cpu_to_le32(reg_addr1);
  3745. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  3746. if (!status) {
  3747. *reg_val0 = le32_to_cpu(cmd_resp->data0);
  3748. if (reg_val1)
  3749. *reg_val1 = le32_to_cpu(cmd_resp->data1);
  3750. }
  3751. return status;
  3752. }
  3753. /**
  3754. * i40e_aq_resume_port_tx
  3755. * @hw: pointer to the hardware structure
  3756. * @cmd_details: pointer to command details structure or NULL
  3757. *
  3758. * Resume port's Tx traffic
  3759. **/
  3760. i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
  3761. struct i40e_asq_cmd_details *cmd_details)
  3762. {
  3763. struct i40e_aq_desc desc;
  3764. i40e_status status;
  3765. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
  3766. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3767. return status;
  3768. }
  3769. /**
  3770. * i40e_set_pci_config_data - store PCI bus info
  3771. * @hw: pointer to hardware structure
  3772. * @link_status: the link status word from PCI config space
  3773. *
  3774. * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
  3775. **/
  3776. void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
  3777. {
  3778. hw->bus.type = i40e_bus_type_pci_express;
  3779. switch (link_status & PCI_EXP_LNKSTA_NLW) {
  3780. case PCI_EXP_LNKSTA_NLW_X1:
  3781. hw->bus.width = i40e_bus_width_pcie_x1;
  3782. break;
  3783. case PCI_EXP_LNKSTA_NLW_X2:
  3784. hw->bus.width = i40e_bus_width_pcie_x2;
  3785. break;
  3786. case PCI_EXP_LNKSTA_NLW_X4:
  3787. hw->bus.width = i40e_bus_width_pcie_x4;
  3788. break;
  3789. case PCI_EXP_LNKSTA_NLW_X8:
  3790. hw->bus.width = i40e_bus_width_pcie_x8;
  3791. break;
  3792. default:
  3793. hw->bus.width = i40e_bus_width_unknown;
  3794. break;
  3795. }
  3796. switch (link_status & PCI_EXP_LNKSTA_CLS) {
  3797. case PCI_EXP_LNKSTA_CLS_2_5GB:
  3798. hw->bus.speed = i40e_bus_speed_2500;
  3799. break;
  3800. case PCI_EXP_LNKSTA_CLS_5_0GB:
  3801. hw->bus.speed = i40e_bus_speed_5000;
  3802. break;
  3803. case PCI_EXP_LNKSTA_CLS_8_0GB:
  3804. hw->bus.speed = i40e_bus_speed_8000;
  3805. break;
  3806. default:
  3807. hw->bus.speed = i40e_bus_speed_unknown;
  3808. break;
  3809. }
  3810. }
  3811. /**
  3812. * i40e_aq_debug_dump
  3813. * @hw: pointer to the hardware structure
  3814. * @cluster_id: specific cluster to dump
  3815. * @table_id: table id within cluster
  3816. * @start_index: index of line in the block to read
  3817. * @buff_size: dump buffer size
  3818. * @buff: dump buffer
  3819. * @ret_buff_size: actual buffer size returned
  3820. * @ret_next_table: next block to read
  3821. * @ret_next_index: next index to read
  3822. *
  3823. * Dump internal FW/HW data for debug purposes.
  3824. *
  3825. **/
  3826. i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
  3827. u8 table_id, u32 start_index, u16 buff_size,
  3828. void *buff, u16 *ret_buff_size,
  3829. u8 *ret_next_table, u32 *ret_next_index,
  3830. struct i40e_asq_cmd_details *cmd_details)
  3831. {
  3832. struct i40e_aq_desc desc;
  3833. struct i40e_aqc_debug_dump_internals *cmd =
  3834. (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
  3835. struct i40e_aqc_debug_dump_internals *resp =
  3836. (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
  3837. i40e_status status;
  3838. if (buff_size == 0 || !buff)
  3839. return I40E_ERR_PARAM;
  3840. i40e_fill_default_direct_cmd_desc(&desc,
  3841. i40e_aqc_opc_debug_dump_internals);
  3842. /* Indirect Command */
  3843. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3844. if (buff_size > I40E_AQ_LARGE_BUF)
  3845. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3846. cmd->cluster_id = cluster_id;
  3847. cmd->table_id = table_id;
  3848. cmd->idx = cpu_to_le32(start_index);
  3849. desc.datalen = cpu_to_le16(buff_size);
  3850. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  3851. if (!status) {
  3852. if (ret_buff_size)
  3853. *ret_buff_size = le16_to_cpu(desc.datalen);
  3854. if (ret_next_table)
  3855. *ret_next_table = resp->table_id;
  3856. if (ret_next_index)
  3857. *ret_next_index = le32_to_cpu(resp->idx);
  3858. }
  3859. return status;
  3860. }
  3861. /**
  3862. * i40e_read_bw_from_alt_ram
  3863. * @hw: pointer to the hardware structure
  3864. * @max_bw: pointer for max_bw read
  3865. * @min_bw: pointer for min_bw read
  3866. * @min_valid: pointer for bool that is true if min_bw is a valid value
  3867. * @max_valid: pointer for bool that is true if max_bw is a valid value
  3868. *
  3869. * Read bw from the alternate ram for the given pf
  3870. **/
  3871. i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
  3872. u32 *max_bw, u32 *min_bw,
  3873. bool *min_valid, bool *max_valid)
  3874. {
  3875. i40e_status status;
  3876. u32 max_bw_addr, min_bw_addr;
  3877. /* Calculate the address of the min/max bw registers */
  3878. max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3879. I40E_ALT_STRUCT_MAX_BW_OFFSET +
  3880. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3881. min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3882. I40E_ALT_STRUCT_MIN_BW_OFFSET +
  3883. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3884. /* Read the bandwidths from alt ram */
  3885. status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
  3886. min_bw_addr, min_bw);
  3887. if (*min_bw & I40E_ALT_BW_VALID_MASK)
  3888. *min_valid = true;
  3889. else
  3890. *min_valid = false;
  3891. if (*max_bw & I40E_ALT_BW_VALID_MASK)
  3892. *max_valid = true;
  3893. else
  3894. *max_valid = false;
  3895. return status;
  3896. }
  3897. /**
  3898. * i40e_aq_configure_partition_bw
  3899. * @hw: pointer to the hardware structure
  3900. * @bw_data: Buffer holding valid pfs and bw limits
  3901. * @cmd_details: pointer to command details
  3902. *
  3903. * Configure partitions guaranteed/max bw
  3904. **/
  3905. i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
  3906. struct i40e_aqc_configure_partition_bw_data *bw_data,
  3907. struct i40e_asq_cmd_details *cmd_details)
  3908. {
  3909. i40e_status status;
  3910. struct i40e_aq_desc desc;
  3911. u16 bwd_size = sizeof(*bw_data);
  3912. i40e_fill_default_direct_cmd_desc(&desc,
  3913. i40e_aqc_opc_configure_partition_bw);
  3914. /* Indirect command */
  3915. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3916. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  3917. if (bwd_size > I40E_AQ_LARGE_BUF)
  3918. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3919. desc.datalen = cpu_to_le16(bwd_size);
  3920. status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
  3921. cmd_details);
  3922. return status;
  3923. }
  3924. /**
  3925. * i40e_read_phy_register_clause22
  3926. * @hw: pointer to the HW structure
  3927. * @reg: register address in the page
  3928. * @phy_adr: PHY address on MDIO interface
  3929. * @value: PHY register value
  3930. *
  3931. * Reads specified PHY register value
  3932. **/
  3933. i40e_status i40e_read_phy_register_clause22(struct i40e_hw *hw,
  3934. u16 reg, u8 phy_addr, u16 *value)
  3935. {
  3936. i40e_status status = I40E_ERR_TIMEOUT;
  3937. u8 port_num = (u8)hw->func_caps.mdio_port_num;
  3938. u32 command = 0;
  3939. u16 retry = 1000;
  3940. command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
  3941. (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
  3942. (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
  3943. (I40E_MDIO_CLAUSE22_STCODE_MASK) |
  3944. (I40E_GLGEN_MSCA_MDICMD_MASK);
  3945. wr32(hw, I40E_GLGEN_MSCA(port_num), command);
  3946. do {
  3947. command = rd32(hw, I40E_GLGEN_MSCA(port_num));
  3948. if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
  3949. status = 0;
  3950. break;
  3951. }
  3952. udelay(10);
  3953. retry--;
  3954. } while (retry);
  3955. if (status) {
  3956. i40e_debug(hw, I40E_DEBUG_PHY,
  3957. "PHY: Can't write command to external PHY.\n");
  3958. } else {
  3959. command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
  3960. *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
  3961. I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
  3962. }
  3963. return status;
  3964. }
  3965. /**
  3966. * i40e_write_phy_register_clause22
  3967. * @hw: pointer to the HW structure
  3968. * @reg: register address in the page
  3969. * @phy_adr: PHY address on MDIO interface
  3970. * @value: PHY register value
  3971. *
  3972. * Writes specified PHY register value
  3973. **/
  3974. i40e_status i40e_write_phy_register_clause22(struct i40e_hw *hw,
  3975. u16 reg, u8 phy_addr, u16 value)
  3976. {
  3977. i40e_status status = I40E_ERR_TIMEOUT;
  3978. u8 port_num = (u8)hw->func_caps.mdio_port_num;
  3979. u32 command = 0;
  3980. u16 retry = 1000;
  3981. command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
  3982. wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
  3983. command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
  3984. (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
  3985. (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
  3986. (I40E_MDIO_CLAUSE22_STCODE_MASK) |
  3987. (I40E_GLGEN_MSCA_MDICMD_MASK);
  3988. wr32(hw, I40E_GLGEN_MSCA(port_num), command);
  3989. do {
  3990. command = rd32(hw, I40E_GLGEN_MSCA(port_num));
  3991. if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
  3992. status = 0;
  3993. break;
  3994. }
  3995. udelay(10);
  3996. retry--;
  3997. } while (retry);
  3998. return status;
  3999. }
  4000. /**
  4001. * i40e_read_phy_register_clause45
  4002. * @hw: pointer to the HW structure
  4003. * @page: registers page number
  4004. * @reg: register address in the page
  4005. * @phy_adr: PHY address on MDIO interface
  4006. * @value: PHY register value
  4007. *
  4008. * Reads specified PHY register value
  4009. **/
  4010. i40e_status i40e_read_phy_register_clause45(struct i40e_hw *hw,
  4011. u8 page, u16 reg, u8 phy_addr, u16 *value)
  4012. {
  4013. i40e_status status = I40E_ERR_TIMEOUT;
  4014. u32 command = 0;
  4015. u16 retry = 1000;
  4016. u8 port_num = hw->func_caps.mdio_port_num;
  4017. command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
  4018. (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
  4019. (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
  4020. (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
  4021. (I40E_MDIO_CLAUSE45_STCODE_MASK) |
  4022. (I40E_GLGEN_MSCA_MDICMD_MASK) |
  4023. (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
  4024. wr32(hw, I40E_GLGEN_MSCA(port_num), command);
  4025. do {
  4026. command = rd32(hw, I40E_GLGEN_MSCA(port_num));
  4027. if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
  4028. status = 0;
  4029. break;
  4030. }
  4031. usleep_range(10, 20);
  4032. retry--;
  4033. } while (retry);
  4034. if (status) {
  4035. i40e_debug(hw, I40E_DEBUG_PHY,
  4036. "PHY: Can't write command to external PHY.\n");
  4037. goto phy_read_end;
  4038. }
  4039. command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
  4040. (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
  4041. (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
  4042. (I40E_MDIO_CLAUSE45_STCODE_MASK) |
  4043. (I40E_GLGEN_MSCA_MDICMD_MASK) |
  4044. (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
  4045. status = I40E_ERR_TIMEOUT;
  4046. retry = 1000;
  4047. wr32(hw, I40E_GLGEN_MSCA(port_num), command);
  4048. do {
  4049. command = rd32(hw, I40E_GLGEN_MSCA(port_num));
  4050. if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
  4051. status = 0;
  4052. break;
  4053. }
  4054. usleep_range(10, 20);
  4055. retry--;
  4056. } while (retry);
  4057. if (!status) {
  4058. command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
  4059. *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
  4060. I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
  4061. } else {
  4062. i40e_debug(hw, I40E_DEBUG_PHY,
  4063. "PHY: Can't read register value from external PHY.\n");
  4064. }
  4065. phy_read_end:
  4066. return status;
  4067. }
  4068. /**
  4069. * i40e_write_phy_register_clause45
  4070. * @hw: pointer to the HW structure
  4071. * @page: registers page number
  4072. * @reg: register address in the page
  4073. * @phy_adr: PHY address on MDIO interface
  4074. * @value: PHY register value
  4075. *
  4076. * Writes value to specified PHY register
  4077. **/
  4078. i40e_status i40e_write_phy_register_clause45(struct i40e_hw *hw,
  4079. u8 page, u16 reg, u8 phy_addr, u16 value)
  4080. {
  4081. i40e_status status = I40E_ERR_TIMEOUT;
  4082. u32 command = 0;
  4083. u16 retry = 1000;
  4084. u8 port_num = hw->func_caps.mdio_port_num;
  4085. command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
  4086. (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
  4087. (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
  4088. (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
  4089. (I40E_MDIO_CLAUSE45_STCODE_MASK) |
  4090. (I40E_GLGEN_MSCA_MDICMD_MASK) |
  4091. (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
  4092. wr32(hw, I40E_GLGEN_MSCA(port_num), command);
  4093. do {
  4094. command = rd32(hw, I40E_GLGEN_MSCA(port_num));
  4095. if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
  4096. status = 0;
  4097. break;
  4098. }
  4099. usleep_range(10, 20);
  4100. retry--;
  4101. } while (retry);
  4102. if (status) {
  4103. i40e_debug(hw, I40E_DEBUG_PHY,
  4104. "PHY: Can't write command to external PHY.\n");
  4105. goto phy_write_end;
  4106. }
  4107. command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
  4108. wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
  4109. command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
  4110. (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
  4111. (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
  4112. (I40E_MDIO_CLAUSE45_STCODE_MASK) |
  4113. (I40E_GLGEN_MSCA_MDICMD_MASK) |
  4114. (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
  4115. status = I40E_ERR_TIMEOUT;
  4116. retry = 1000;
  4117. wr32(hw, I40E_GLGEN_MSCA(port_num), command);
  4118. do {
  4119. command = rd32(hw, I40E_GLGEN_MSCA(port_num));
  4120. if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
  4121. status = 0;
  4122. break;
  4123. }
  4124. usleep_range(10, 20);
  4125. retry--;
  4126. } while (retry);
  4127. phy_write_end:
  4128. return status;
  4129. }
  4130. /**
  4131. * i40e_write_phy_register
  4132. * @hw: pointer to the HW structure
  4133. * @page: registers page number
  4134. * @reg: register address in the page
  4135. * @phy_adr: PHY address on MDIO interface
  4136. * @value: PHY register value
  4137. *
  4138. * Writes value to specified PHY register
  4139. **/
  4140. i40e_status i40e_write_phy_register(struct i40e_hw *hw,
  4141. u8 page, u16 reg, u8 phy_addr, u16 value)
  4142. {
  4143. i40e_status status;
  4144. switch (hw->device_id) {
  4145. case I40E_DEV_ID_1G_BASE_T_X722:
  4146. status = i40e_write_phy_register_clause22(hw, reg, phy_addr,
  4147. value);
  4148. break;
  4149. case I40E_DEV_ID_10G_BASE_T:
  4150. case I40E_DEV_ID_10G_BASE_T4:
  4151. case I40E_DEV_ID_10G_BASE_T_X722:
  4152. case I40E_DEV_ID_25G_B:
  4153. case I40E_DEV_ID_25G_SFP28:
  4154. status = i40e_write_phy_register_clause45(hw, page, reg,
  4155. phy_addr, value);
  4156. break;
  4157. default:
  4158. status = I40E_ERR_UNKNOWN_PHY;
  4159. break;
  4160. }
  4161. return status;
  4162. }
  4163. /**
  4164. * i40e_read_phy_register
  4165. * @hw: pointer to the HW structure
  4166. * @page: registers page number
  4167. * @reg: register address in the page
  4168. * @phy_adr: PHY address on MDIO interface
  4169. * @value: PHY register value
  4170. *
  4171. * Reads specified PHY register value
  4172. **/
  4173. i40e_status i40e_read_phy_register(struct i40e_hw *hw,
  4174. u8 page, u16 reg, u8 phy_addr, u16 *value)
  4175. {
  4176. i40e_status status;
  4177. switch (hw->device_id) {
  4178. case I40E_DEV_ID_1G_BASE_T_X722:
  4179. status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
  4180. value);
  4181. break;
  4182. case I40E_DEV_ID_10G_BASE_T:
  4183. case I40E_DEV_ID_10G_BASE_T4:
  4184. case I40E_DEV_ID_10G_BASE_T_X722:
  4185. case I40E_DEV_ID_25G_B:
  4186. case I40E_DEV_ID_25G_SFP28:
  4187. status = i40e_read_phy_register_clause45(hw, page, reg,
  4188. phy_addr, value);
  4189. break;
  4190. default:
  4191. status = I40E_ERR_UNKNOWN_PHY;
  4192. break;
  4193. }
  4194. return status;
  4195. }
  4196. /**
  4197. * i40e_get_phy_address
  4198. * @hw: pointer to the HW structure
  4199. * @dev_num: PHY port num that address we want
  4200. * @phy_addr: Returned PHY address
  4201. *
  4202. * Gets PHY address for current port
  4203. **/
  4204. u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
  4205. {
  4206. u8 port_num = hw->func_caps.mdio_port_num;
  4207. u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
  4208. return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
  4209. }
  4210. /**
  4211. * i40e_blink_phy_led
  4212. * @hw: pointer to the HW structure
  4213. * @time: time how long led will blinks in secs
  4214. * @interval: gap between LED on and off in msecs
  4215. *
  4216. * Blinks PHY link LED
  4217. **/
  4218. i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
  4219. u32 time, u32 interval)
  4220. {
  4221. i40e_status status = 0;
  4222. u32 i;
  4223. u16 led_ctl;
  4224. u16 gpio_led_port;
  4225. u16 led_reg;
  4226. u16 led_addr = I40E_PHY_LED_PROV_REG_1;
  4227. u8 phy_addr = 0;
  4228. u8 port_num;
  4229. i = rd32(hw, I40E_PFGEN_PORTNUM);
  4230. port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
  4231. phy_addr = i40e_get_phy_address(hw, port_num);
  4232. for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
  4233. led_addr++) {
  4234. status = i40e_read_phy_register_clause45(hw,
  4235. I40E_PHY_COM_REG_PAGE,
  4236. led_addr, phy_addr,
  4237. &led_reg);
  4238. if (status)
  4239. goto phy_blinking_end;
  4240. led_ctl = led_reg;
  4241. if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
  4242. led_reg = 0;
  4243. status = i40e_write_phy_register_clause45(hw,
  4244. I40E_PHY_COM_REG_PAGE,
  4245. led_addr, phy_addr,
  4246. led_reg);
  4247. if (status)
  4248. goto phy_blinking_end;
  4249. break;
  4250. }
  4251. }
  4252. if (time > 0 && interval > 0) {
  4253. for (i = 0; i < time * 1000; i += interval) {
  4254. status = i40e_read_phy_register_clause45(hw,
  4255. I40E_PHY_COM_REG_PAGE,
  4256. led_addr, phy_addr, &led_reg);
  4257. if (status)
  4258. goto restore_config;
  4259. if (led_reg & I40E_PHY_LED_MANUAL_ON)
  4260. led_reg = 0;
  4261. else
  4262. led_reg = I40E_PHY_LED_MANUAL_ON;
  4263. status = i40e_write_phy_register_clause45(hw,
  4264. I40E_PHY_COM_REG_PAGE,
  4265. led_addr, phy_addr, led_reg);
  4266. if (status)
  4267. goto restore_config;
  4268. msleep(interval);
  4269. }
  4270. }
  4271. restore_config:
  4272. status = i40e_write_phy_register_clause45(hw,
  4273. I40E_PHY_COM_REG_PAGE,
  4274. led_addr, phy_addr, led_ctl);
  4275. phy_blinking_end:
  4276. return status;
  4277. }
  4278. /**
  4279. * i40e_led_get_reg - read LED register
  4280. * @hw: pointer to the HW structure
  4281. * @led_addr: LED register address
  4282. * @reg_val: read register value
  4283. **/
  4284. static enum i40e_status_code i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
  4285. u32 *reg_val)
  4286. {
  4287. enum i40e_status_code status;
  4288. u8 phy_addr = 0;
  4289. u8 port_num;
  4290. u32 i;
  4291. *reg_val = 0;
  4292. if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
  4293. status =
  4294. i40e_aq_get_phy_register(hw,
  4295. I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
  4296. I40E_PHY_COM_REG_PAGE,
  4297. I40E_PHY_LED_PROV_REG_1,
  4298. reg_val, NULL);
  4299. } else {
  4300. i = rd32(hw, I40E_PFGEN_PORTNUM);
  4301. port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
  4302. phy_addr = i40e_get_phy_address(hw, port_num);
  4303. status = i40e_read_phy_register_clause45(hw,
  4304. I40E_PHY_COM_REG_PAGE,
  4305. led_addr, phy_addr,
  4306. (u16 *)reg_val);
  4307. }
  4308. return status;
  4309. }
  4310. /**
  4311. * i40e_led_set_reg - write LED register
  4312. * @hw: pointer to the HW structure
  4313. * @led_addr: LED register address
  4314. * @reg_val: register value to write
  4315. **/
  4316. static enum i40e_status_code i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
  4317. u32 reg_val)
  4318. {
  4319. enum i40e_status_code status;
  4320. u8 phy_addr = 0;
  4321. u8 port_num;
  4322. u32 i;
  4323. if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
  4324. status =
  4325. i40e_aq_set_phy_register(hw,
  4326. I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
  4327. I40E_PHY_COM_REG_PAGE,
  4328. I40E_PHY_LED_PROV_REG_1,
  4329. reg_val, NULL);
  4330. } else {
  4331. i = rd32(hw, I40E_PFGEN_PORTNUM);
  4332. port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
  4333. phy_addr = i40e_get_phy_address(hw, port_num);
  4334. status = i40e_write_phy_register_clause45(hw,
  4335. I40E_PHY_COM_REG_PAGE,
  4336. led_addr, phy_addr,
  4337. (u16)reg_val);
  4338. }
  4339. return status;
  4340. }
  4341. /**
  4342. * i40e_led_get_phy - return current on/off mode
  4343. * @hw: pointer to the hw struct
  4344. * @led_addr: address of led register to use
  4345. * @val: original value of register to use
  4346. *
  4347. **/
  4348. i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
  4349. u16 *val)
  4350. {
  4351. i40e_status status = 0;
  4352. u16 gpio_led_port;
  4353. u8 phy_addr = 0;
  4354. u16 reg_val;
  4355. u16 temp_addr;
  4356. u8 port_num;
  4357. u32 i;
  4358. u32 reg_val_aq;
  4359. if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
  4360. status =
  4361. i40e_aq_get_phy_register(hw,
  4362. I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
  4363. I40E_PHY_COM_REG_PAGE,
  4364. I40E_PHY_LED_PROV_REG_1,
  4365. &reg_val_aq, NULL);
  4366. if (status == I40E_SUCCESS)
  4367. *val = (u16)reg_val_aq;
  4368. return status;
  4369. }
  4370. temp_addr = I40E_PHY_LED_PROV_REG_1;
  4371. i = rd32(hw, I40E_PFGEN_PORTNUM);
  4372. port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
  4373. phy_addr = i40e_get_phy_address(hw, port_num);
  4374. for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
  4375. temp_addr++) {
  4376. status = i40e_read_phy_register_clause45(hw,
  4377. I40E_PHY_COM_REG_PAGE,
  4378. temp_addr, phy_addr,
  4379. &reg_val);
  4380. if (status)
  4381. return status;
  4382. *val = reg_val;
  4383. if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
  4384. *led_addr = temp_addr;
  4385. break;
  4386. }
  4387. }
  4388. return status;
  4389. }
  4390. /**
  4391. * i40e_led_set_phy
  4392. * @hw: pointer to the HW structure
  4393. * @on: true or false
  4394. * @mode: original val plus bit for set or ignore
  4395. * Set led's on or off when controlled by the PHY
  4396. *
  4397. **/
  4398. i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
  4399. u16 led_addr, u32 mode)
  4400. {
  4401. i40e_status status = 0;
  4402. u32 led_ctl = 0;
  4403. u32 led_reg = 0;
  4404. status = i40e_led_get_reg(hw, led_addr, &led_reg);
  4405. if (status)
  4406. return status;
  4407. led_ctl = led_reg;
  4408. if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
  4409. led_reg = 0;
  4410. status = i40e_led_set_reg(hw, led_addr, led_reg);
  4411. if (status)
  4412. return status;
  4413. }
  4414. status = i40e_led_get_reg(hw, led_addr, &led_reg);
  4415. if (status)
  4416. goto restore_config;
  4417. if (on)
  4418. led_reg = I40E_PHY_LED_MANUAL_ON;
  4419. else
  4420. led_reg = 0;
  4421. status = i40e_led_set_reg(hw, led_addr, led_reg);
  4422. if (status)
  4423. goto restore_config;
  4424. if (mode & I40E_PHY_LED_MODE_ORIG) {
  4425. led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
  4426. status = i40e_led_set_reg(hw, led_addr, led_ctl);
  4427. }
  4428. return status;
  4429. restore_config:
  4430. status = i40e_led_set_reg(hw, led_addr, led_ctl);
  4431. return status;
  4432. }
  4433. /**
  4434. * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
  4435. * @hw: pointer to the hw struct
  4436. * @reg_addr: register address
  4437. * @reg_val: ptr to register value
  4438. * @cmd_details: pointer to command details structure or NULL
  4439. *
  4440. * Use the firmware to read the Rx control register,
  4441. * especially useful if the Rx unit is under heavy pressure
  4442. **/
  4443. i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
  4444. u32 reg_addr, u32 *reg_val,
  4445. struct i40e_asq_cmd_details *cmd_details)
  4446. {
  4447. struct i40e_aq_desc desc;
  4448. struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
  4449. (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
  4450. i40e_status status;
  4451. if (!reg_val)
  4452. return I40E_ERR_PARAM;
  4453. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
  4454. cmd_resp->address = cpu_to_le32(reg_addr);
  4455. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  4456. if (status == 0)
  4457. *reg_val = le32_to_cpu(cmd_resp->value);
  4458. return status;
  4459. }
  4460. /**
  4461. * i40e_read_rx_ctl - read from an Rx control register
  4462. * @hw: pointer to the hw struct
  4463. * @reg_addr: register address
  4464. **/
  4465. u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
  4466. {
  4467. i40e_status status = 0;
  4468. bool use_register;
  4469. int retry = 5;
  4470. u32 val = 0;
  4471. use_register = (((hw->aq.api_maj_ver == 1) &&
  4472. (hw->aq.api_min_ver < 5)) ||
  4473. (hw->mac.type == I40E_MAC_X722));
  4474. if (!use_register) {
  4475. do_retry:
  4476. status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
  4477. if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
  4478. usleep_range(1000, 2000);
  4479. retry--;
  4480. goto do_retry;
  4481. }
  4482. }
  4483. /* if the AQ access failed, try the old-fashioned way */
  4484. if (status || use_register)
  4485. val = rd32(hw, reg_addr);
  4486. return val;
  4487. }
  4488. /**
  4489. * i40e_aq_rx_ctl_write_register
  4490. * @hw: pointer to the hw struct
  4491. * @reg_addr: register address
  4492. * @reg_val: register value
  4493. * @cmd_details: pointer to command details structure or NULL
  4494. *
  4495. * Use the firmware to write to an Rx control register,
  4496. * especially useful if the Rx unit is under heavy pressure
  4497. **/
  4498. i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
  4499. u32 reg_addr, u32 reg_val,
  4500. struct i40e_asq_cmd_details *cmd_details)
  4501. {
  4502. struct i40e_aq_desc desc;
  4503. struct i40e_aqc_rx_ctl_reg_read_write *cmd =
  4504. (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
  4505. i40e_status status;
  4506. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
  4507. cmd->address = cpu_to_le32(reg_addr);
  4508. cmd->value = cpu_to_le32(reg_val);
  4509. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  4510. return status;
  4511. }
  4512. /**
  4513. * i40e_write_rx_ctl - write to an Rx control register
  4514. * @hw: pointer to the hw struct
  4515. * @reg_addr: register address
  4516. * @reg_val: register value
  4517. **/
  4518. void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
  4519. {
  4520. i40e_status status = 0;
  4521. bool use_register;
  4522. int retry = 5;
  4523. use_register = (((hw->aq.api_maj_ver == 1) &&
  4524. (hw->aq.api_min_ver < 5)) ||
  4525. (hw->mac.type == I40E_MAC_X722));
  4526. if (!use_register) {
  4527. do_retry:
  4528. status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
  4529. reg_val, NULL);
  4530. if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
  4531. usleep_range(1000, 2000);
  4532. retry--;
  4533. goto do_retry;
  4534. }
  4535. }
  4536. /* if the AQ access failed, try the old-fashioned way */
  4537. if (status || use_register)
  4538. wr32(hw, reg_addr, reg_val);
  4539. }
  4540. /**
  4541. * i40e_aq_set_phy_register
  4542. * @hw: pointer to the hw struct
  4543. * @phy_select: select which phy should be accessed
  4544. * @dev_addr: PHY device address
  4545. * @reg_addr: PHY register address
  4546. * @reg_val: new register value
  4547. * @cmd_details: pointer to command details structure or NULL
  4548. *
  4549. * Write the external PHY register.
  4550. **/
  4551. i40e_status i40e_aq_set_phy_register(struct i40e_hw *hw,
  4552. u8 phy_select, u8 dev_addr,
  4553. u32 reg_addr, u32 reg_val,
  4554. struct i40e_asq_cmd_details *cmd_details)
  4555. {
  4556. struct i40e_aq_desc desc;
  4557. struct i40e_aqc_phy_register_access *cmd =
  4558. (struct i40e_aqc_phy_register_access *)&desc.params.raw;
  4559. i40e_status status;
  4560. i40e_fill_default_direct_cmd_desc(&desc,
  4561. i40e_aqc_opc_set_phy_register);
  4562. cmd->phy_interface = phy_select;
  4563. cmd->dev_address = dev_addr;
  4564. cmd->reg_address = cpu_to_le32(reg_addr);
  4565. cmd->reg_value = cpu_to_le32(reg_val);
  4566. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  4567. return status;
  4568. }
  4569. /**
  4570. * i40e_aq_get_phy_register
  4571. * @hw: pointer to the hw struct
  4572. * @phy_select: select which phy should be accessed
  4573. * @dev_addr: PHY device address
  4574. * @reg_addr: PHY register address
  4575. * @reg_val: read register value
  4576. * @cmd_details: pointer to command details structure or NULL
  4577. *
  4578. * Read the external PHY register.
  4579. **/
  4580. i40e_status i40e_aq_get_phy_register(struct i40e_hw *hw,
  4581. u8 phy_select, u8 dev_addr,
  4582. u32 reg_addr, u32 *reg_val,
  4583. struct i40e_asq_cmd_details *cmd_details)
  4584. {
  4585. struct i40e_aq_desc desc;
  4586. struct i40e_aqc_phy_register_access *cmd =
  4587. (struct i40e_aqc_phy_register_access *)&desc.params.raw;
  4588. i40e_status status;
  4589. i40e_fill_default_direct_cmd_desc(&desc,
  4590. i40e_aqc_opc_get_phy_register);
  4591. cmd->phy_interface = phy_select;
  4592. cmd->dev_address = dev_addr;
  4593. cmd->reg_address = cpu_to_le32(reg_addr);
  4594. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  4595. if (!status)
  4596. *reg_val = le32_to_cpu(cmd->reg_value);
  4597. return status;
  4598. }
  4599. /**
  4600. * i40e_aq_write_ppp - Write pipeline personalization profile (ppp)
  4601. * @hw: pointer to the hw struct
  4602. * @buff: command buffer (size in bytes = buff_size)
  4603. * @buff_size: buffer size in bytes
  4604. * @track_id: package tracking id
  4605. * @error_offset: returns error offset
  4606. * @error_info: returns error information
  4607. * @cmd_details: pointer to command details structure or NULL
  4608. **/
  4609. enum
  4610. i40e_status_code i40e_aq_write_ppp(struct i40e_hw *hw, void *buff,
  4611. u16 buff_size, u32 track_id,
  4612. u32 *error_offset, u32 *error_info,
  4613. struct i40e_asq_cmd_details *cmd_details)
  4614. {
  4615. struct i40e_aq_desc desc;
  4616. struct i40e_aqc_write_personalization_profile *cmd =
  4617. (struct i40e_aqc_write_personalization_profile *)
  4618. &desc.params.raw;
  4619. struct i40e_aqc_write_ppp_resp *resp;
  4620. i40e_status status;
  4621. i40e_fill_default_direct_cmd_desc(&desc,
  4622. i40e_aqc_opc_write_personalization_profile);
  4623. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
  4624. if (buff_size > I40E_AQ_LARGE_BUF)
  4625. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  4626. desc.datalen = cpu_to_le16(buff_size);
  4627. cmd->profile_track_id = cpu_to_le32(track_id);
  4628. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  4629. if (!status) {
  4630. resp = (struct i40e_aqc_write_ppp_resp *)&desc.params.raw;
  4631. if (error_offset)
  4632. *error_offset = le32_to_cpu(resp->error_offset);
  4633. if (error_info)
  4634. *error_info = le32_to_cpu(resp->error_info);
  4635. }
  4636. return status;
  4637. }
  4638. /**
  4639. * i40e_aq_get_ppp_list - Read pipeline personalization profile (ppp)
  4640. * @hw: pointer to the hw struct
  4641. * @buff: command buffer (size in bytes = buff_size)
  4642. * @buff_size: buffer size in bytes
  4643. * @cmd_details: pointer to command details structure or NULL
  4644. **/
  4645. enum
  4646. i40e_status_code i40e_aq_get_ppp_list(struct i40e_hw *hw, void *buff,
  4647. u16 buff_size, u8 flags,
  4648. struct i40e_asq_cmd_details *cmd_details)
  4649. {
  4650. struct i40e_aq_desc desc;
  4651. struct i40e_aqc_get_applied_profiles *cmd =
  4652. (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
  4653. i40e_status status;
  4654. i40e_fill_default_direct_cmd_desc(&desc,
  4655. i40e_aqc_opc_get_personalization_profile_list);
  4656. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  4657. if (buff_size > I40E_AQ_LARGE_BUF)
  4658. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  4659. desc.datalen = cpu_to_le16(buff_size);
  4660. cmd->flags = flags;
  4661. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  4662. return status;
  4663. }
  4664. /**
  4665. * i40e_find_segment_in_package
  4666. * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
  4667. * @pkg_hdr: pointer to the package header to be searched
  4668. *
  4669. * This function searches a package file for a particular segment type. On
  4670. * success it returns a pointer to the segment header, otherwise it will
  4671. * return NULL.
  4672. **/
  4673. struct i40e_generic_seg_header *
  4674. i40e_find_segment_in_package(u32 segment_type,
  4675. struct i40e_package_header *pkg_hdr)
  4676. {
  4677. struct i40e_generic_seg_header *segment;
  4678. u32 i;
  4679. /* Search all package segments for the requested segment type */
  4680. for (i = 0; i < pkg_hdr->segment_count; i++) {
  4681. segment =
  4682. (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
  4683. pkg_hdr->segment_offset[i]);
  4684. if (segment->type == segment_type)
  4685. return segment;
  4686. }
  4687. return NULL;
  4688. }
  4689. /**
  4690. * i40e_write_profile
  4691. * @hw: pointer to the hardware structure
  4692. * @profile: pointer to the profile segment of the package to be downloaded
  4693. * @track_id: package tracking id
  4694. *
  4695. * Handles the download of a complete package.
  4696. */
  4697. enum i40e_status_code
  4698. i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
  4699. u32 track_id)
  4700. {
  4701. i40e_status status = 0;
  4702. struct i40e_section_table *sec_tbl;
  4703. struct i40e_profile_section_header *sec = NULL;
  4704. u32 dev_cnt;
  4705. u32 vendor_dev_id;
  4706. u32 *nvm;
  4707. u32 section_size = 0;
  4708. u32 offset = 0, info = 0;
  4709. u32 i;
  4710. if (!track_id) {
  4711. i40e_debug(hw, I40E_DEBUG_PACKAGE, "Track_id can't be 0.");
  4712. return I40E_NOT_SUPPORTED;
  4713. }
  4714. dev_cnt = profile->device_table_count;
  4715. for (i = 0; i < dev_cnt; i++) {
  4716. vendor_dev_id = profile->device_table[i].vendor_dev_id;
  4717. if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
  4718. if (hw->device_id == (vendor_dev_id & 0xFFFF))
  4719. break;
  4720. }
  4721. if (i == dev_cnt) {
  4722. i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support PPP");
  4723. return I40E_ERR_DEVICE_NOT_SUPPORTED;
  4724. }
  4725. nvm = (u32 *)&profile->device_table[dev_cnt];
  4726. sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
  4727. for (i = 0; i < sec_tbl->section_count; i++) {
  4728. sec = (struct i40e_profile_section_header *)((u8 *)profile +
  4729. sec_tbl->section_offset[i]);
  4730. /* Skip 'AQ', 'note' and 'name' sections */
  4731. if (sec->section.type != SECTION_TYPE_MMIO)
  4732. continue;
  4733. section_size = sec->section.size +
  4734. sizeof(struct i40e_profile_section_header);
  4735. /* Write profile */
  4736. status = i40e_aq_write_ppp(hw, (void *)sec, (u16)section_size,
  4737. track_id, &offset, &info, NULL);
  4738. if (status) {
  4739. i40e_debug(hw, I40E_DEBUG_PACKAGE,
  4740. "Failed to write profile: offset %d, info %d",
  4741. offset, info);
  4742. break;
  4743. }
  4744. }
  4745. return status;
  4746. }
  4747. /**
  4748. * i40e_add_pinfo_to_list
  4749. * @hw: pointer to the hardware structure
  4750. * @profile: pointer to the profile segment of the package
  4751. * @profile_info_sec: buffer for information section
  4752. * @track_id: package tracking id
  4753. *
  4754. * Register a profile to the list of loaded profiles.
  4755. */
  4756. enum i40e_status_code
  4757. i40e_add_pinfo_to_list(struct i40e_hw *hw,
  4758. struct i40e_profile_segment *profile,
  4759. u8 *profile_info_sec, u32 track_id)
  4760. {
  4761. i40e_status status = 0;
  4762. struct i40e_profile_section_header *sec = NULL;
  4763. struct i40e_profile_info *pinfo;
  4764. u32 offset = 0, info = 0;
  4765. sec = (struct i40e_profile_section_header *)profile_info_sec;
  4766. sec->tbl_size = 1;
  4767. sec->data_end = sizeof(struct i40e_profile_section_header) +
  4768. sizeof(struct i40e_profile_info);
  4769. sec->section.type = SECTION_TYPE_INFO;
  4770. sec->section.offset = sizeof(struct i40e_profile_section_header);
  4771. sec->section.size = sizeof(struct i40e_profile_info);
  4772. pinfo = (struct i40e_profile_info *)(profile_info_sec +
  4773. sec->section.offset);
  4774. pinfo->track_id = track_id;
  4775. pinfo->version = profile->version;
  4776. pinfo->op = I40E_PPP_ADD_TRACKID;
  4777. memcpy(pinfo->name, profile->name, I40E_PPP_NAME_SIZE);
  4778. status = i40e_aq_write_ppp(hw, (void *)sec, sec->data_end,
  4779. track_id, &offset, &info, NULL);
  4780. return status;
  4781. }
  4782. /**
  4783. * i40e_aq_add_cloud_filters
  4784. * @hw: pointer to the hardware structure
  4785. * @seid: VSI seid to add cloud filters from
  4786. * @filters: Buffer which contains the filters to be added
  4787. * @filter_count: number of filters contained in the buffer
  4788. *
  4789. * Set the cloud filters for a given VSI. The contents of the
  4790. * i40e_aqc_cloud_filters_element_data are filled in by the caller
  4791. * of the function.
  4792. *
  4793. **/
  4794. enum i40e_status_code
  4795. i40e_aq_add_cloud_filters(struct i40e_hw *hw, u16 seid,
  4796. struct i40e_aqc_cloud_filters_element_data *filters,
  4797. u8 filter_count)
  4798. {
  4799. struct i40e_aq_desc desc;
  4800. struct i40e_aqc_add_remove_cloud_filters *cmd =
  4801. (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
  4802. enum i40e_status_code status;
  4803. u16 buff_len;
  4804. i40e_fill_default_direct_cmd_desc(&desc,
  4805. i40e_aqc_opc_add_cloud_filters);
  4806. buff_len = filter_count * sizeof(*filters);
  4807. desc.datalen = cpu_to_le16(buff_len);
  4808. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  4809. cmd->num_filters = filter_count;
  4810. cmd->seid = cpu_to_le16(seid);
  4811. status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
  4812. return status;
  4813. }
  4814. /**
  4815. * i40e_aq_add_cloud_filters_bb
  4816. * @hw: pointer to the hardware structure
  4817. * @seid: VSI seid to add cloud filters from
  4818. * @filters: Buffer which contains the filters in big buffer to be added
  4819. * @filter_count: number of filters contained in the buffer
  4820. *
  4821. * Set the big buffer cloud filters for a given VSI. The contents of the
  4822. * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
  4823. * function.
  4824. *
  4825. **/
  4826. i40e_status
  4827. i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
  4828. struct i40e_aqc_cloud_filters_element_bb *filters,
  4829. u8 filter_count)
  4830. {
  4831. struct i40e_aq_desc desc;
  4832. struct i40e_aqc_add_remove_cloud_filters *cmd =
  4833. (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
  4834. i40e_status status;
  4835. u16 buff_len;
  4836. int i;
  4837. i40e_fill_default_direct_cmd_desc(&desc,
  4838. i40e_aqc_opc_add_cloud_filters);
  4839. buff_len = filter_count * sizeof(*filters);
  4840. desc.datalen = cpu_to_le16(buff_len);
  4841. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  4842. cmd->num_filters = filter_count;
  4843. cmd->seid = cpu_to_le16(seid);
  4844. cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
  4845. for (i = 0; i < filter_count; i++) {
  4846. u16 tnl_type;
  4847. u32 ti;
  4848. tnl_type = (le16_to_cpu(filters[i].element.flags) &
  4849. I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
  4850. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
  4851. /* Due to hardware eccentricities, the VNI for Geneve is shifted
  4852. * one more byte further than normally used for Tenant ID in
  4853. * other tunnel types.
  4854. */
  4855. if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
  4856. ti = le32_to_cpu(filters[i].element.tenant_id);
  4857. filters[i].element.tenant_id = cpu_to_le32(ti << 8);
  4858. }
  4859. }
  4860. status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
  4861. return status;
  4862. }
  4863. /**
  4864. * i40e_aq_rem_cloud_filters
  4865. * @hw: pointer to the hardware structure
  4866. * @seid: VSI seid to remove cloud filters from
  4867. * @filters: Buffer which contains the filters to be removed
  4868. * @filter_count: number of filters contained in the buffer
  4869. *
  4870. * Remove the cloud filters for a given VSI. The contents of the
  4871. * i40e_aqc_cloud_filters_element_data are filled in by the caller
  4872. * of the function.
  4873. *
  4874. **/
  4875. enum i40e_status_code
  4876. i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
  4877. struct i40e_aqc_cloud_filters_element_data *filters,
  4878. u8 filter_count)
  4879. {
  4880. struct i40e_aq_desc desc;
  4881. struct i40e_aqc_add_remove_cloud_filters *cmd =
  4882. (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
  4883. enum i40e_status_code status;
  4884. u16 buff_len;
  4885. i40e_fill_default_direct_cmd_desc(&desc,
  4886. i40e_aqc_opc_remove_cloud_filters);
  4887. buff_len = filter_count * sizeof(*filters);
  4888. desc.datalen = cpu_to_le16(buff_len);
  4889. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  4890. cmd->num_filters = filter_count;
  4891. cmd->seid = cpu_to_le16(seid);
  4892. status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
  4893. return status;
  4894. }
  4895. /**
  4896. * i40e_aq_rem_cloud_filters_bb
  4897. * @hw: pointer to the hardware structure
  4898. * @seid: VSI seid to remove cloud filters from
  4899. * @filters: Buffer which contains the filters in big buffer to be removed
  4900. * @filter_count: number of filters contained in the buffer
  4901. *
  4902. * Remove the big buffer cloud filters for a given VSI. The contents of the
  4903. * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
  4904. * function.
  4905. *
  4906. **/
  4907. i40e_status
  4908. i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
  4909. struct i40e_aqc_cloud_filters_element_bb *filters,
  4910. u8 filter_count)
  4911. {
  4912. struct i40e_aq_desc desc;
  4913. struct i40e_aqc_add_remove_cloud_filters *cmd =
  4914. (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
  4915. i40e_status status;
  4916. u16 buff_len;
  4917. int i;
  4918. i40e_fill_default_direct_cmd_desc(&desc,
  4919. i40e_aqc_opc_remove_cloud_filters);
  4920. buff_len = filter_count * sizeof(*filters);
  4921. desc.datalen = cpu_to_le16(buff_len);
  4922. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  4923. cmd->num_filters = filter_count;
  4924. cmd->seid = cpu_to_le16(seid);
  4925. cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
  4926. for (i = 0; i < filter_count; i++) {
  4927. u16 tnl_type;
  4928. u32 ti;
  4929. tnl_type = (le16_to_cpu(filters[i].element.flags) &
  4930. I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
  4931. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
  4932. /* Due to hardware eccentricities, the VNI for Geneve is shifted
  4933. * one more byte further than normally used for Tenant ID in
  4934. * other tunnel types.
  4935. */
  4936. if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
  4937. ti = le32_to_cpu(filters[i].element.tenant_id);
  4938. filters[i].element.tenant_id = cpu_to_le32(ti << 8);
  4939. }
  4940. }
  4941. status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
  4942. return status;
  4943. }