i40e_common.c 166 KB

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