ice_common.c 172 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018-2023, Intel Corporation. */
  3. #include "ice_common.h"
  4. #include "ice_sched.h"
  5. #include "ice_adminq_cmd.h"
  6. #include "ice_flow.h"
  7. #include "ice_ptp_hw.h"
  8. #define ICE_PF_RESET_WAIT_COUNT 300
  9. #define ICE_MAX_NETLIST_SIZE 10
  10. static const char * const ice_link_mode_str_low[] = {
  11. [0] = "100BASE_TX",
  12. [1] = "100M_SGMII",
  13. [2] = "1000BASE_T",
  14. [3] = "1000BASE_SX",
  15. [4] = "1000BASE_LX",
  16. [5] = "1000BASE_KX",
  17. [6] = "1G_SGMII",
  18. [7] = "2500BASE_T",
  19. [8] = "2500BASE_X",
  20. [9] = "2500BASE_KX",
  21. [10] = "5GBASE_T",
  22. [11] = "5GBASE_KR",
  23. [12] = "10GBASE_T",
  24. [13] = "10G_SFI_DA",
  25. [14] = "10GBASE_SR",
  26. [15] = "10GBASE_LR",
  27. [16] = "10GBASE_KR_CR1",
  28. [17] = "10G_SFI_AOC_ACC",
  29. [18] = "10G_SFI_C2C",
  30. [19] = "25GBASE_T",
  31. [20] = "25GBASE_CR",
  32. [21] = "25GBASE_CR_S",
  33. [22] = "25GBASE_CR1",
  34. [23] = "25GBASE_SR",
  35. [24] = "25GBASE_LR",
  36. [25] = "25GBASE_KR",
  37. [26] = "25GBASE_KR_S",
  38. [27] = "25GBASE_KR1",
  39. [28] = "25G_AUI_AOC_ACC",
  40. [29] = "25G_AUI_C2C",
  41. [30] = "40GBASE_CR4",
  42. [31] = "40GBASE_SR4",
  43. [32] = "40GBASE_LR4",
  44. [33] = "40GBASE_KR4",
  45. [34] = "40G_XLAUI_AOC_ACC",
  46. [35] = "40G_XLAUI",
  47. [36] = "50GBASE_CR2",
  48. [37] = "50GBASE_SR2",
  49. [38] = "50GBASE_LR2",
  50. [39] = "50GBASE_KR2",
  51. [40] = "50G_LAUI2_AOC_ACC",
  52. [41] = "50G_LAUI2",
  53. [42] = "50G_AUI2_AOC_ACC",
  54. [43] = "50G_AUI2",
  55. [44] = "50GBASE_CP",
  56. [45] = "50GBASE_SR",
  57. [46] = "50GBASE_FR",
  58. [47] = "50GBASE_LR",
  59. [48] = "50GBASE_KR_PAM4",
  60. [49] = "50G_AUI1_AOC_ACC",
  61. [50] = "50G_AUI1",
  62. [51] = "100GBASE_CR4",
  63. [52] = "100GBASE_SR4",
  64. [53] = "100GBASE_LR4",
  65. [54] = "100GBASE_KR4",
  66. [55] = "100G_CAUI4_AOC_ACC",
  67. [56] = "100G_CAUI4",
  68. [57] = "100G_AUI4_AOC_ACC",
  69. [58] = "100G_AUI4",
  70. [59] = "100GBASE_CR_PAM4",
  71. [60] = "100GBASE_KR_PAM4",
  72. [61] = "100GBASE_CP2",
  73. [62] = "100GBASE_SR2",
  74. [63] = "100GBASE_DR",
  75. };
  76. static const char * const ice_link_mode_str_high[] = {
  77. [0] = "100GBASE_KR2_PAM4",
  78. [1] = "100G_CAUI2_AOC_ACC",
  79. [2] = "100G_CAUI2",
  80. [3] = "100G_AUI2_AOC_ACC",
  81. [4] = "100G_AUI2",
  82. };
  83. /**
  84. * ice_dump_phy_type - helper function to dump phy_type
  85. * @hw: pointer to the HW structure
  86. * @low: 64 bit value for phy_type_low
  87. * @high: 64 bit value for phy_type_high
  88. * @prefix: prefix string to differentiate multiple dumps
  89. */
  90. static void
  91. ice_dump_phy_type(struct ice_hw *hw, u64 low, u64 high, const char *prefix)
  92. {
  93. ice_debug(hw, ICE_DBG_PHY, "%s: phy_type_low: 0x%016llx\n", prefix, low);
  94. for (u32 i = 0; i < BITS_PER_TYPE(typeof(low)); i++) {
  95. if (low & BIT_ULL(i))
  96. ice_debug(hw, ICE_DBG_PHY, "%s: bit(%d): %s\n",
  97. prefix, i, ice_link_mode_str_low[i]);
  98. }
  99. ice_debug(hw, ICE_DBG_PHY, "%s: phy_type_high: 0x%016llx\n", prefix, high);
  100. for (u32 i = 0; i < BITS_PER_TYPE(typeof(high)); i++) {
  101. if (high & BIT_ULL(i))
  102. ice_debug(hw, ICE_DBG_PHY, "%s: bit(%d): %s\n",
  103. prefix, i, ice_link_mode_str_high[i]);
  104. }
  105. }
  106. /**
  107. * ice_set_mac_type - Sets MAC type
  108. * @hw: pointer to the HW structure
  109. *
  110. * This function sets the MAC type of the adapter based on the
  111. * vendor ID and device ID stored in the HW structure.
  112. */
  113. static int ice_set_mac_type(struct ice_hw *hw)
  114. {
  115. if (hw->vendor_id != PCI_VENDOR_ID_INTEL)
  116. return -ENODEV;
  117. switch (hw->device_id) {
  118. case ICE_DEV_ID_E810C_BACKPLANE:
  119. case ICE_DEV_ID_E810C_QSFP:
  120. case ICE_DEV_ID_E810C_SFP:
  121. case ICE_DEV_ID_E810_XXV_BACKPLANE:
  122. case ICE_DEV_ID_E810_XXV_QSFP:
  123. case ICE_DEV_ID_E810_XXV_SFP:
  124. hw->mac_type = ICE_MAC_E810;
  125. break;
  126. case ICE_DEV_ID_E823C_10G_BASE_T:
  127. case ICE_DEV_ID_E823C_BACKPLANE:
  128. case ICE_DEV_ID_E823C_QSFP:
  129. case ICE_DEV_ID_E823C_SFP:
  130. case ICE_DEV_ID_E823C_SGMII:
  131. case ICE_DEV_ID_E822C_10G_BASE_T:
  132. case ICE_DEV_ID_E822C_BACKPLANE:
  133. case ICE_DEV_ID_E822C_QSFP:
  134. case ICE_DEV_ID_E822C_SFP:
  135. case ICE_DEV_ID_E822C_SGMII:
  136. case ICE_DEV_ID_E822L_10G_BASE_T:
  137. case ICE_DEV_ID_E822L_BACKPLANE:
  138. case ICE_DEV_ID_E822L_SFP:
  139. case ICE_DEV_ID_E822L_SGMII:
  140. case ICE_DEV_ID_E823L_10G_BASE_T:
  141. case ICE_DEV_ID_E823L_1GBE:
  142. case ICE_DEV_ID_E823L_BACKPLANE:
  143. case ICE_DEV_ID_E823L_QSFP:
  144. case ICE_DEV_ID_E823L_SFP:
  145. hw->mac_type = ICE_MAC_GENERIC;
  146. break;
  147. case ICE_DEV_ID_E825C_BACKPLANE:
  148. case ICE_DEV_ID_E825C_QSFP:
  149. case ICE_DEV_ID_E825C_SFP:
  150. case ICE_DEV_ID_E825C_SGMII:
  151. hw->mac_type = ICE_MAC_GENERIC_3K_E825;
  152. break;
  153. case ICE_DEV_ID_E830CC_BACKPLANE:
  154. case ICE_DEV_ID_E830CC_QSFP56:
  155. case ICE_DEV_ID_E830CC_SFP:
  156. case ICE_DEV_ID_E830CC_SFP_DD:
  157. case ICE_DEV_ID_E830C_BACKPLANE:
  158. case ICE_DEV_ID_E830_XXV_BACKPLANE:
  159. case ICE_DEV_ID_E830C_QSFP:
  160. case ICE_DEV_ID_E830_XXV_QSFP:
  161. case ICE_DEV_ID_E830C_SFP:
  162. case ICE_DEV_ID_E830_XXV_SFP:
  163. hw->mac_type = ICE_MAC_E830;
  164. break;
  165. default:
  166. hw->mac_type = ICE_MAC_UNKNOWN;
  167. break;
  168. }
  169. ice_debug(hw, ICE_DBG_INIT, "mac_type: %d\n", hw->mac_type);
  170. return 0;
  171. }
  172. /**
  173. * ice_is_generic_mac - check if device's mac_type is generic
  174. * @hw: pointer to the hardware structure
  175. *
  176. * Return: true if mac_type is generic (with SBQ support), false if not
  177. */
  178. bool ice_is_generic_mac(struct ice_hw *hw)
  179. {
  180. return (hw->mac_type == ICE_MAC_GENERIC ||
  181. hw->mac_type == ICE_MAC_GENERIC_3K_E825);
  182. }
  183. /**
  184. * ice_is_e810
  185. * @hw: pointer to the hardware structure
  186. *
  187. * returns true if the device is E810 based, false if not.
  188. */
  189. bool ice_is_e810(struct ice_hw *hw)
  190. {
  191. return hw->mac_type == ICE_MAC_E810;
  192. }
  193. /**
  194. * ice_is_e810t
  195. * @hw: pointer to the hardware structure
  196. *
  197. * returns true if the device is E810T based, false if not.
  198. */
  199. bool ice_is_e810t(struct ice_hw *hw)
  200. {
  201. switch (hw->device_id) {
  202. case ICE_DEV_ID_E810C_SFP:
  203. switch (hw->subsystem_device_id) {
  204. case ICE_SUBDEV_ID_E810T:
  205. case ICE_SUBDEV_ID_E810T2:
  206. case ICE_SUBDEV_ID_E810T3:
  207. case ICE_SUBDEV_ID_E810T4:
  208. case ICE_SUBDEV_ID_E810T6:
  209. case ICE_SUBDEV_ID_E810T7:
  210. return true;
  211. }
  212. break;
  213. case ICE_DEV_ID_E810C_QSFP:
  214. switch (hw->subsystem_device_id) {
  215. case ICE_SUBDEV_ID_E810T2:
  216. case ICE_SUBDEV_ID_E810T3:
  217. case ICE_SUBDEV_ID_E810T5:
  218. return true;
  219. }
  220. break;
  221. default:
  222. break;
  223. }
  224. return false;
  225. }
  226. /**
  227. * ice_is_e822 - Check if a device is E822 family device
  228. * @hw: pointer to the hardware structure
  229. *
  230. * Return: true if the device is E822 based, false if not.
  231. */
  232. bool ice_is_e822(struct ice_hw *hw)
  233. {
  234. switch (hw->device_id) {
  235. case ICE_DEV_ID_E822C_BACKPLANE:
  236. case ICE_DEV_ID_E822C_QSFP:
  237. case ICE_DEV_ID_E822C_SFP:
  238. case ICE_DEV_ID_E822C_10G_BASE_T:
  239. case ICE_DEV_ID_E822C_SGMII:
  240. case ICE_DEV_ID_E822L_BACKPLANE:
  241. case ICE_DEV_ID_E822L_SFP:
  242. case ICE_DEV_ID_E822L_10G_BASE_T:
  243. case ICE_DEV_ID_E822L_SGMII:
  244. return true;
  245. default:
  246. return false;
  247. }
  248. }
  249. /**
  250. * ice_is_e823
  251. * @hw: pointer to the hardware structure
  252. *
  253. * returns true if the device is E823-L or E823-C based, false if not.
  254. */
  255. bool ice_is_e823(struct ice_hw *hw)
  256. {
  257. switch (hw->device_id) {
  258. case ICE_DEV_ID_E823L_BACKPLANE:
  259. case ICE_DEV_ID_E823L_SFP:
  260. case ICE_DEV_ID_E823L_10G_BASE_T:
  261. case ICE_DEV_ID_E823L_1GBE:
  262. case ICE_DEV_ID_E823L_QSFP:
  263. case ICE_DEV_ID_E823C_BACKPLANE:
  264. case ICE_DEV_ID_E823C_QSFP:
  265. case ICE_DEV_ID_E823C_SFP:
  266. case ICE_DEV_ID_E823C_10G_BASE_T:
  267. case ICE_DEV_ID_E823C_SGMII:
  268. return true;
  269. default:
  270. return false;
  271. }
  272. }
  273. /**
  274. * ice_is_e825c - Check if a device is E825C family device
  275. * @hw: pointer to the hardware structure
  276. *
  277. * Return: true if the device is E825-C based, false if not.
  278. */
  279. bool ice_is_e825c(struct ice_hw *hw)
  280. {
  281. switch (hw->device_id) {
  282. case ICE_DEV_ID_E825C_BACKPLANE:
  283. case ICE_DEV_ID_E825C_QSFP:
  284. case ICE_DEV_ID_E825C_SFP:
  285. case ICE_DEV_ID_E825C_SGMII:
  286. return true;
  287. default:
  288. return false;
  289. }
  290. }
  291. /**
  292. * ice_clear_pf_cfg - Clear PF configuration
  293. * @hw: pointer to the hardware structure
  294. *
  295. * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
  296. * configuration, flow director filters, etc.).
  297. */
  298. int ice_clear_pf_cfg(struct ice_hw *hw)
  299. {
  300. struct ice_aq_desc desc;
  301. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg);
  302. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  303. }
  304. /**
  305. * ice_aq_manage_mac_read - manage MAC address read command
  306. * @hw: pointer to the HW struct
  307. * @buf: a virtual buffer to hold the manage MAC read response
  308. * @buf_size: Size of the virtual buffer
  309. * @cd: pointer to command details structure or NULL
  310. *
  311. * This function is used to return per PF station MAC address (0x0107).
  312. * NOTE: Upon successful completion of this command, MAC address information
  313. * is returned in user specified buffer. Please interpret user specified
  314. * buffer as "manage_mac_read" response.
  315. * Response such as various MAC addresses are stored in HW struct (port.mac)
  316. * ice_discover_dev_caps is expected to be called before this function is
  317. * called.
  318. */
  319. static int
  320. ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
  321. struct ice_sq_cd *cd)
  322. {
  323. struct ice_aqc_manage_mac_read_resp *resp;
  324. struct ice_aqc_manage_mac_read *cmd;
  325. struct ice_aq_desc desc;
  326. int status;
  327. u16 flags;
  328. u8 i;
  329. cmd = &desc.params.mac_read;
  330. if (buf_size < sizeof(*resp))
  331. return -EINVAL;
  332. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read);
  333. status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  334. if (status)
  335. return status;
  336. resp = buf;
  337. flags = le16_to_cpu(cmd->flags) & ICE_AQC_MAN_MAC_READ_M;
  338. if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) {
  339. ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n");
  340. return -EIO;
  341. }
  342. /* A single port can report up to two (LAN and WoL) addresses */
  343. for (i = 0; i < cmd->num_addr; i++)
  344. if (resp[i].addr_type == ICE_AQC_MAN_MAC_ADDR_TYPE_LAN) {
  345. ether_addr_copy(hw->port_info->mac.lan_addr,
  346. resp[i].mac_addr);
  347. ether_addr_copy(hw->port_info->mac.perm_addr,
  348. resp[i].mac_addr);
  349. break;
  350. }
  351. return 0;
  352. }
  353. /**
  354. * ice_aq_get_phy_caps - returns PHY capabilities
  355. * @pi: port information structure
  356. * @qual_mods: report qualified modules
  357. * @report_mode: report mode capabilities
  358. * @pcaps: structure for PHY capabilities to be filled
  359. * @cd: pointer to command details structure or NULL
  360. *
  361. * Returns the various PHY capabilities supported on the Port (0x0600)
  362. */
  363. int
  364. ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
  365. struct ice_aqc_get_phy_caps_data *pcaps,
  366. struct ice_sq_cd *cd)
  367. {
  368. struct ice_aqc_get_phy_caps *cmd;
  369. u16 pcaps_size = sizeof(*pcaps);
  370. struct ice_aq_desc desc;
  371. const char *prefix;
  372. struct ice_hw *hw;
  373. int status;
  374. cmd = &desc.params.get_phy;
  375. if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi)
  376. return -EINVAL;
  377. hw = pi->hw;
  378. if (report_mode == ICE_AQC_REPORT_DFLT_CFG &&
  379. !ice_fw_supports_report_dflt_cfg(hw))
  380. return -EINVAL;
  381. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
  382. if (qual_mods)
  383. cmd->param0 |= cpu_to_le16(ICE_AQC_GET_PHY_RQM);
  384. cmd->param0 |= cpu_to_le16(report_mode);
  385. status = ice_aq_send_cmd(hw, &desc, pcaps, pcaps_size, cd);
  386. ice_debug(hw, ICE_DBG_LINK, "get phy caps dump\n");
  387. switch (report_mode) {
  388. case ICE_AQC_REPORT_TOPO_CAP_MEDIA:
  389. prefix = "phy_caps_media";
  390. break;
  391. case ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA:
  392. prefix = "phy_caps_no_media";
  393. break;
  394. case ICE_AQC_REPORT_ACTIVE_CFG:
  395. prefix = "phy_caps_active";
  396. break;
  397. case ICE_AQC_REPORT_DFLT_CFG:
  398. prefix = "phy_caps_default";
  399. break;
  400. default:
  401. prefix = "phy_caps_invalid";
  402. }
  403. ice_dump_phy_type(hw, le64_to_cpu(pcaps->phy_type_low),
  404. le64_to_cpu(pcaps->phy_type_high), prefix);
  405. ice_debug(hw, ICE_DBG_LINK, "%s: report_mode = 0x%x\n",
  406. prefix, report_mode);
  407. ice_debug(hw, ICE_DBG_LINK, "%s: caps = 0x%x\n", prefix, pcaps->caps);
  408. ice_debug(hw, ICE_DBG_LINK, "%s: low_power_ctrl_an = 0x%x\n", prefix,
  409. pcaps->low_power_ctrl_an);
  410. ice_debug(hw, ICE_DBG_LINK, "%s: eee_cap = 0x%x\n", prefix,
  411. pcaps->eee_cap);
  412. ice_debug(hw, ICE_DBG_LINK, "%s: eeer_value = 0x%x\n", prefix,
  413. pcaps->eeer_value);
  414. ice_debug(hw, ICE_DBG_LINK, "%s: link_fec_options = 0x%x\n", prefix,
  415. pcaps->link_fec_options);
  416. ice_debug(hw, ICE_DBG_LINK, "%s: module_compliance_enforcement = 0x%x\n",
  417. prefix, pcaps->module_compliance_enforcement);
  418. ice_debug(hw, ICE_DBG_LINK, "%s: extended_compliance_code = 0x%x\n",
  419. prefix, pcaps->extended_compliance_code);
  420. ice_debug(hw, ICE_DBG_LINK, "%s: module_type[0] = 0x%x\n", prefix,
  421. pcaps->module_type[0]);
  422. ice_debug(hw, ICE_DBG_LINK, "%s: module_type[1] = 0x%x\n", prefix,
  423. pcaps->module_type[1]);
  424. ice_debug(hw, ICE_DBG_LINK, "%s: module_type[2] = 0x%x\n", prefix,
  425. pcaps->module_type[2]);
  426. if (!status && report_mode == ICE_AQC_REPORT_TOPO_CAP_MEDIA) {
  427. pi->phy.phy_type_low = le64_to_cpu(pcaps->phy_type_low);
  428. pi->phy.phy_type_high = le64_to_cpu(pcaps->phy_type_high);
  429. memcpy(pi->phy.link_info.module_type, &pcaps->module_type,
  430. sizeof(pi->phy.link_info.module_type));
  431. }
  432. return status;
  433. }
  434. /**
  435. * ice_aq_get_link_topo_handle - get link topology node return status
  436. * @pi: port information structure
  437. * @node_type: requested node type
  438. * @cd: pointer to command details structure or NULL
  439. *
  440. * Get link topology node return status for specified node type (0x06E0)
  441. *
  442. * Node type cage can be used to determine if cage is present. If AQC
  443. * returns error (ENOENT), then no cage present. If no cage present, then
  444. * connection type is backplane or BASE-T.
  445. */
  446. static int
  447. ice_aq_get_link_topo_handle(struct ice_port_info *pi, u8 node_type,
  448. struct ice_sq_cd *cd)
  449. {
  450. struct ice_aqc_get_link_topo *cmd;
  451. struct ice_aq_desc desc;
  452. cmd = &desc.params.get_link_topo;
  453. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_topo);
  454. cmd->addr.topo_params.node_type_ctx =
  455. (ICE_AQC_LINK_TOPO_NODE_CTX_PORT <<
  456. ICE_AQC_LINK_TOPO_NODE_CTX_S);
  457. /* set node type */
  458. cmd->addr.topo_params.node_type_ctx |=
  459. (ICE_AQC_LINK_TOPO_NODE_TYPE_M & node_type);
  460. return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
  461. }
  462. /**
  463. * ice_aq_get_netlist_node
  464. * @hw: pointer to the hw struct
  465. * @cmd: get_link_topo AQ structure
  466. * @node_part_number: output node part number if node found
  467. * @node_handle: output node handle parameter if node found
  468. *
  469. * Get netlist node handle.
  470. */
  471. int
  472. ice_aq_get_netlist_node(struct ice_hw *hw, struct ice_aqc_get_link_topo *cmd,
  473. u8 *node_part_number, u16 *node_handle)
  474. {
  475. struct ice_aq_desc desc;
  476. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_topo);
  477. desc.params.get_link_topo = *cmd;
  478. if (ice_aq_send_cmd(hw, &desc, NULL, 0, NULL))
  479. return -EINTR;
  480. if (node_handle)
  481. *node_handle =
  482. le16_to_cpu(desc.params.get_link_topo.addr.handle);
  483. if (node_part_number)
  484. *node_part_number = desc.params.get_link_topo.node_part_num;
  485. return 0;
  486. }
  487. /**
  488. * ice_find_netlist_node
  489. * @hw: pointer to the hw struct
  490. * @node_type: type of netlist node to look for
  491. * @ctx: context of the search
  492. * @node_part_number: node part number to look for
  493. * @node_handle: output parameter if node found - optional
  494. *
  495. * Scan the netlist for a node handle of the given node type and part number.
  496. *
  497. * If node_handle is non-NULL it will be modified on function exit. It is only
  498. * valid if the function returns zero, and should be ignored on any non-zero
  499. * return value.
  500. *
  501. * Return:
  502. * * 0 if the node is found,
  503. * * -ENOENT if no handle was found,
  504. * * negative error code on failure to access the AQ.
  505. */
  506. static int ice_find_netlist_node(struct ice_hw *hw, u8 node_type, u8 ctx,
  507. u8 node_part_number, u16 *node_handle)
  508. {
  509. u8 idx;
  510. for (idx = 0; idx < ICE_MAX_NETLIST_SIZE; idx++) {
  511. struct ice_aqc_get_link_topo cmd = {};
  512. u8 rec_node_part_number;
  513. int status;
  514. cmd.addr.topo_params.node_type_ctx =
  515. FIELD_PREP(ICE_AQC_LINK_TOPO_NODE_TYPE_M, node_type) |
  516. FIELD_PREP(ICE_AQC_LINK_TOPO_NODE_CTX_M, ctx);
  517. cmd.addr.topo_params.index = idx;
  518. status = ice_aq_get_netlist_node(hw, &cmd,
  519. &rec_node_part_number,
  520. node_handle);
  521. if (status)
  522. return status;
  523. if (rec_node_part_number == node_part_number)
  524. return 0;
  525. }
  526. return -ENOENT;
  527. }
  528. /**
  529. * ice_is_media_cage_present
  530. * @pi: port information structure
  531. *
  532. * Returns true if media cage is present, else false. If no cage, then
  533. * media type is backplane or BASE-T.
  534. */
  535. static bool ice_is_media_cage_present(struct ice_port_info *pi)
  536. {
  537. /* Node type cage can be used to determine if cage is present. If AQC
  538. * returns error (ENOENT), then no cage present. If no cage present then
  539. * connection type is backplane or BASE-T.
  540. */
  541. return !ice_aq_get_link_topo_handle(pi,
  542. ICE_AQC_LINK_TOPO_NODE_TYPE_CAGE,
  543. NULL);
  544. }
  545. /**
  546. * ice_get_media_type - Gets media type
  547. * @pi: port information structure
  548. */
  549. static enum ice_media_type ice_get_media_type(struct ice_port_info *pi)
  550. {
  551. struct ice_link_status *hw_link_info;
  552. if (!pi)
  553. return ICE_MEDIA_UNKNOWN;
  554. hw_link_info = &pi->phy.link_info;
  555. if (hw_link_info->phy_type_low && hw_link_info->phy_type_high)
  556. /* If more than one media type is selected, report unknown */
  557. return ICE_MEDIA_UNKNOWN;
  558. if (hw_link_info->phy_type_low) {
  559. /* 1G SGMII is a special case where some DA cable PHYs
  560. * may show this as an option when it really shouldn't
  561. * be since SGMII is meant to be between a MAC and a PHY
  562. * in a backplane. Try to detect this case and handle it
  563. */
  564. if (hw_link_info->phy_type_low == ICE_PHY_TYPE_LOW_1G_SGMII &&
  565. (hw_link_info->module_type[ICE_AQC_MOD_TYPE_IDENT] ==
  566. ICE_AQC_MOD_TYPE_BYTE1_SFP_PLUS_CU_ACTIVE ||
  567. hw_link_info->module_type[ICE_AQC_MOD_TYPE_IDENT] ==
  568. ICE_AQC_MOD_TYPE_BYTE1_SFP_PLUS_CU_PASSIVE))
  569. return ICE_MEDIA_DA;
  570. switch (hw_link_info->phy_type_low) {
  571. case ICE_PHY_TYPE_LOW_1000BASE_SX:
  572. case ICE_PHY_TYPE_LOW_1000BASE_LX:
  573. case ICE_PHY_TYPE_LOW_10GBASE_SR:
  574. case ICE_PHY_TYPE_LOW_10GBASE_LR:
  575. case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
  576. case ICE_PHY_TYPE_LOW_25GBASE_SR:
  577. case ICE_PHY_TYPE_LOW_25GBASE_LR:
  578. case ICE_PHY_TYPE_LOW_40GBASE_SR4:
  579. case ICE_PHY_TYPE_LOW_40GBASE_LR4:
  580. case ICE_PHY_TYPE_LOW_50GBASE_SR2:
  581. case ICE_PHY_TYPE_LOW_50GBASE_LR2:
  582. case ICE_PHY_TYPE_LOW_50GBASE_SR:
  583. case ICE_PHY_TYPE_LOW_50GBASE_FR:
  584. case ICE_PHY_TYPE_LOW_50GBASE_LR:
  585. case ICE_PHY_TYPE_LOW_100GBASE_SR4:
  586. case ICE_PHY_TYPE_LOW_100GBASE_LR4:
  587. case ICE_PHY_TYPE_LOW_100GBASE_SR2:
  588. case ICE_PHY_TYPE_LOW_100GBASE_DR:
  589. case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
  590. case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
  591. case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
  592. case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
  593. case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
  594. case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
  595. case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
  596. case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
  597. return ICE_MEDIA_FIBER;
  598. case ICE_PHY_TYPE_LOW_100BASE_TX:
  599. case ICE_PHY_TYPE_LOW_1000BASE_T:
  600. case ICE_PHY_TYPE_LOW_2500BASE_T:
  601. case ICE_PHY_TYPE_LOW_5GBASE_T:
  602. case ICE_PHY_TYPE_LOW_10GBASE_T:
  603. case ICE_PHY_TYPE_LOW_25GBASE_T:
  604. return ICE_MEDIA_BASET;
  605. case ICE_PHY_TYPE_LOW_10G_SFI_DA:
  606. case ICE_PHY_TYPE_LOW_25GBASE_CR:
  607. case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
  608. case ICE_PHY_TYPE_LOW_25GBASE_CR1:
  609. case ICE_PHY_TYPE_LOW_40GBASE_CR4:
  610. case ICE_PHY_TYPE_LOW_50GBASE_CR2:
  611. case ICE_PHY_TYPE_LOW_50GBASE_CP:
  612. case ICE_PHY_TYPE_LOW_100GBASE_CR4:
  613. case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
  614. case ICE_PHY_TYPE_LOW_100GBASE_CP2:
  615. return ICE_MEDIA_DA;
  616. case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
  617. case ICE_PHY_TYPE_LOW_40G_XLAUI:
  618. case ICE_PHY_TYPE_LOW_50G_LAUI2:
  619. case ICE_PHY_TYPE_LOW_50G_AUI2:
  620. case ICE_PHY_TYPE_LOW_50G_AUI1:
  621. case ICE_PHY_TYPE_LOW_100G_AUI4:
  622. case ICE_PHY_TYPE_LOW_100G_CAUI4:
  623. if (ice_is_media_cage_present(pi))
  624. return ICE_MEDIA_DA;
  625. fallthrough;
  626. case ICE_PHY_TYPE_LOW_1000BASE_KX:
  627. case ICE_PHY_TYPE_LOW_2500BASE_KX:
  628. case ICE_PHY_TYPE_LOW_2500BASE_X:
  629. case ICE_PHY_TYPE_LOW_5GBASE_KR:
  630. case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
  631. case ICE_PHY_TYPE_LOW_25GBASE_KR:
  632. case ICE_PHY_TYPE_LOW_25GBASE_KR1:
  633. case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
  634. case ICE_PHY_TYPE_LOW_40GBASE_KR4:
  635. case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
  636. case ICE_PHY_TYPE_LOW_50GBASE_KR2:
  637. case ICE_PHY_TYPE_LOW_100GBASE_KR4:
  638. case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
  639. return ICE_MEDIA_BACKPLANE;
  640. }
  641. } else {
  642. switch (hw_link_info->phy_type_high) {
  643. case ICE_PHY_TYPE_HIGH_100G_AUI2:
  644. case ICE_PHY_TYPE_HIGH_100G_CAUI2:
  645. if (ice_is_media_cage_present(pi))
  646. return ICE_MEDIA_DA;
  647. fallthrough;
  648. case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
  649. return ICE_MEDIA_BACKPLANE;
  650. case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
  651. case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
  652. return ICE_MEDIA_FIBER;
  653. }
  654. }
  655. return ICE_MEDIA_UNKNOWN;
  656. }
  657. /**
  658. * ice_get_link_status_datalen
  659. * @hw: pointer to the HW struct
  660. *
  661. * Returns datalength for the Get Link Status AQ command, which is bigger for
  662. * newer adapter families handled by ice driver.
  663. */
  664. static u16 ice_get_link_status_datalen(struct ice_hw *hw)
  665. {
  666. switch (hw->mac_type) {
  667. case ICE_MAC_E830:
  668. return ICE_AQC_LS_DATA_SIZE_V2;
  669. case ICE_MAC_E810:
  670. default:
  671. return ICE_AQC_LS_DATA_SIZE_V1;
  672. }
  673. }
  674. /**
  675. * ice_aq_get_link_info
  676. * @pi: port information structure
  677. * @ena_lse: enable/disable LinkStatusEvent reporting
  678. * @link: pointer to link status structure - optional
  679. * @cd: pointer to command details structure or NULL
  680. *
  681. * Get Link Status (0x607). Returns the link status of the adapter.
  682. */
  683. int
  684. ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
  685. struct ice_link_status *link, struct ice_sq_cd *cd)
  686. {
  687. struct ice_aqc_get_link_status_data link_data = { 0 };
  688. struct ice_aqc_get_link_status *resp;
  689. struct ice_link_status *li_old, *li;
  690. enum ice_media_type *hw_media_type;
  691. struct ice_fc_info *hw_fc_info;
  692. bool tx_pause, rx_pause;
  693. struct ice_aq_desc desc;
  694. struct ice_hw *hw;
  695. u16 cmd_flags;
  696. int status;
  697. if (!pi)
  698. return -EINVAL;
  699. hw = pi->hw;
  700. li_old = &pi->phy.link_info_old;
  701. hw_media_type = &pi->phy.media_type;
  702. li = &pi->phy.link_info;
  703. hw_fc_info = &pi->fc;
  704. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_status);
  705. cmd_flags = (ena_lse) ? ICE_AQ_LSE_ENA : ICE_AQ_LSE_DIS;
  706. resp = &desc.params.get_link_status;
  707. resp->cmd_flags = cpu_to_le16(cmd_flags);
  708. resp->lport_num = pi->lport;
  709. status = ice_aq_send_cmd(hw, &desc, &link_data,
  710. ice_get_link_status_datalen(hw), cd);
  711. if (status)
  712. return status;
  713. /* save off old link status information */
  714. *li_old = *li;
  715. /* update current link status information */
  716. li->link_speed = le16_to_cpu(link_data.link_speed);
  717. li->phy_type_low = le64_to_cpu(link_data.phy_type_low);
  718. li->phy_type_high = le64_to_cpu(link_data.phy_type_high);
  719. *hw_media_type = ice_get_media_type(pi);
  720. li->link_info = link_data.link_info;
  721. li->link_cfg_err = link_data.link_cfg_err;
  722. li->an_info = link_data.an_info;
  723. li->ext_info = link_data.ext_info;
  724. li->max_frame_size = le16_to_cpu(link_data.max_frame_size);
  725. li->fec_info = link_data.cfg & ICE_AQ_FEC_MASK;
  726. li->topo_media_conflict = link_data.topo_media_conflict;
  727. li->pacing = link_data.cfg & (ICE_AQ_CFG_PACING_M |
  728. ICE_AQ_CFG_PACING_TYPE_M);
  729. /* update fc info */
  730. tx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_TX);
  731. rx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_RX);
  732. if (tx_pause && rx_pause)
  733. hw_fc_info->current_mode = ICE_FC_FULL;
  734. else if (tx_pause)
  735. hw_fc_info->current_mode = ICE_FC_TX_PAUSE;
  736. else if (rx_pause)
  737. hw_fc_info->current_mode = ICE_FC_RX_PAUSE;
  738. else
  739. hw_fc_info->current_mode = ICE_FC_NONE;
  740. li->lse_ena = !!(resp->cmd_flags & cpu_to_le16(ICE_AQ_LSE_IS_ENABLED));
  741. ice_debug(hw, ICE_DBG_LINK, "get link info\n");
  742. ice_debug(hw, ICE_DBG_LINK, " link_speed = 0x%x\n", li->link_speed);
  743. ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
  744. (unsigned long long)li->phy_type_low);
  745. ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
  746. (unsigned long long)li->phy_type_high);
  747. ice_debug(hw, ICE_DBG_LINK, " media_type = 0x%x\n", *hw_media_type);
  748. ice_debug(hw, ICE_DBG_LINK, " link_info = 0x%x\n", li->link_info);
  749. ice_debug(hw, ICE_DBG_LINK, " link_cfg_err = 0x%x\n", li->link_cfg_err);
  750. ice_debug(hw, ICE_DBG_LINK, " an_info = 0x%x\n", li->an_info);
  751. ice_debug(hw, ICE_DBG_LINK, " ext_info = 0x%x\n", li->ext_info);
  752. ice_debug(hw, ICE_DBG_LINK, " fec_info = 0x%x\n", li->fec_info);
  753. ice_debug(hw, ICE_DBG_LINK, " lse_ena = 0x%x\n", li->lse_ena);
  754. ice_debug(hw, ICE_DBG_LINK, " max_frame = 0x%x\n",
  755. li->max_frame_size);
  756. ice_debug(hw, ICE_DBG_LINK, " pacing = 0x%x\n", li->pacing);
  757. /* save link status information */
  758. if (link)
  759. *link = *li;
  760. /* flag cleared so calling functions don't call AQ again */
  761. pi->phy.get_link_info = false;
  762. return 0;
  763. }
  764. /**
  765. * ice_fill_tx_timer_and_fc_thresh
  766. * @hw: pointer to the HW struct
  767. * @cmd: pointer to MAC cfg structure
  768. *
  769. * Add Tx timer and FC refresh threshold info to Set MAC Config AQ command
  770. * descriptor
  771. */
  772. static void
  773. ice_fill_tx_timer_and_fc_thresh(struct ice_hw *hw,
  774. struct ice_aqc_set_mac_cfg *cmd)
  775. {
  776. u32 val, fc_thres_m;
  777. /* We read back the transmit timer and FC threshold value of
  778. * LFC. Thus, we will use index =
  779. * PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX.
  780. *
  781. * Also, because we are operating on transmit timer and FC
  782. * threshold of LFC, we don't turn on any bit in tx_tmr_priority
  783. */
  784. #define E800_IDX_OF_LFC E800_PRTMAC_HSEC_CTL_TX_PS_QNT_MAX
  785. #define E800_REFRESH_TMR E800_PRTMAC_HSEC_CTL_TX_PS_RFSH_TMR
  786. if (hw->mac_type == ICE_MAC_E830) {
  787. /* Retrieve the transmit timer */
  788. val = rd32(hw, E830_PRTMAC_CL01_PS_QNT);
  789. cmd->tx_tmr_value =
  790. le16_encode_bits(val, E830_PRTMAC_CL01_PS_QNT_CL0_M);
  791. /* Retrieve the fc threshold */
  792. val = rd32(hw, E830_PRTMAC_CL01_QNT_THR);
  793. fc_thres_m = E830_PRTMAC_CL01_QNT_THR_CL0_M;
  794. } else {
  795. /* Retrieve the transmit timer */
  796. val = rd32(hw,
  797. E800_PRTMAC_HSEC_CTL_TX_PS_QNT(E800_IDX_OF_LFC));
  798. cmd->tx_tmr_value =
  799. le16_encode_bits(val,
  800. E800_PRTMAC_HSEC_CTL_TX_PS_QNT_M);
  801. /* Retrieve the fc threshold */
  802. val = rd32(hw,
  803. E800_REFRESH_TMR(E800_IDX_OF_LFC));
  804. fc_thres_m = E800_PRTMAC_HSEC_CTL_TX_PS_RFSH_TMR_M;
  805. }
  806. cmd->fc_refresh_threshold = le16_encode_bits(val, fc_thres_m);
  807. }
  808. /**
  809. * ice_aq_set_mac_cfg
  810. * @hw: pointer to the HW struct
  811. * @max_frame_size: Maximum Frame Size to be supported
  812. * @cd: pointer to command details structure or NULL
  813. *
  814. * Set MAC configuration (0x0603)
  815. */
  816. int
  817. ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
  818. {
  819. struct ice_aqc_set_mac_cfg *cmd;
  820. struct ice_aq_desc desc;
  821. cmd = &desc.params.set_mac_cfg;
  822. if (max_frame_size == 0)
  823. return -EINVAL;
  824. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_cfg);
  825. cmd->max_frame_size = cpu_to_le16(max_frame_size);
  826. ice_fill_tx_timer_and_fc_thresh(hw, cmd);
  827. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  828. }
  829. /**
  830. * ice_init_fltr_mgmt_struct - initializes filter management list and locks
  831. * @hw: pointer to the HW struct
  832. */
  833. static int ice_init_fltr_mgmt_struct(struct ice_hw *hw)
  834. {
  835. struct ice_switch_info *sw;
  836. int status;
  837. hw->switch_info = devm_kzalloc(ice_hw_to_dev(hw),
  838. sizeof(*hw->switch_info), GFP_KERNEL);
  839. sw = hw->switch_info;
  840. if (!sw)
  841. return -ENOMEM;
  842. INIT_LIST_HEAD(&sw->vsi_list_map_head);
  843. sw->prof_res_bm_init = 0;
  844. /* Initialize recipe count with default recipes read from NVM */
  845. sw->recp_cnt = ICE_SW_LKUP_LAST;
  846. status = ice_init_def_sw_recp(hw);
  847. if (status) {
  848. devm_kfree(ice_hw_to_dev(hw), hw->switch_info);
  849. return status;
  850. }
  851. return 0;
  852. }
  853. /**
  854. * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks
  855. * @hw: pointer to the HW struct
  856. */
  857. static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
  858. {
  859. struct ice_switch_info *sw = hw->switch_info;
  860. struct ice_vsi_list_map_info *v_pos_map;
  861. struct ice_vsi_list_map_info *v_tmp_map;
  862. struct ice_sw_recipe *recps;
  863. u8 i;
  864. list_for_each_entry_safe(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,
  865. list_entry) {
  866. list_del(&v_pos_map->list_entry);
  867. devm_kfree(ice_hw_to_dev(hw), v_pos_map);
  868. }
  869. recps = sw->recp_list;
  870. for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
  871. recps[i].root_rid = i;
  872. if (recps[i].adv_rule) {
  873. struct ice_adv_fltr_mgmt_list_entry *tmp_entry;
  874. struct ice_adv_fltr_mgmt_list_entry *lst_itr;
  875. mutex_destroy(&recps[i].filt_rule_lock);
  876. list_for_each_entry_safe(lst_itr, tmp_entry,
  877. &recps[i].filt_rules,
  878. list_entry) {
  879. list_del(&lst_itr->list_entry);
  880. devm_kfree(ice_hw_to_dev(hw), lst_itr->lkups);
  881. devm_kfree(ice_hw_to_dev(hw), lst_itr);
  882. }
  883. } else {
  884. struct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry;
  885. mutex_destroy(&recps[i].filt_rule_lock);
  886. list_for_each_entry_safe(lst_itr, tmp_entry,
  887. &recps[i].filt_rules,
  888. list_entry) {
  889. list_del(&lst_itr->list_entry);
  890. devm_kfree(ice_hw_to_dev(hw), lst_itr);
  891. }
  892. }
  893. }
  894. ice_rm_all_sw_replay_rule_info(hw);
  895. devm_kfree(ice_hw_to_dev(hw), sw->recp_list);
  896. devm_kfree(ice_hw_to_dev(hw), sw);
  897. }
  898. /**
  899. * ice_get_itr_intrl_gran
  900. * @hw: pointer to the HW struct
  901. *
  902. * Determines the ITR/INTRL granularities based on the maximum aggregate
  903. * bandwidth according to the device's configuration during power-on.
  904. */
  905. static void ice_get_itr_intrl_gran(struct ice_hw *hw)
  906. {
  907. u8 max_agg_bw = FIELD_GET(GL_PWR_MODE_CTL_CAR_MAX_BW_M,
  908. rd32(hw, GL_PWR_MODE_CTL));
  909. switch (max_agg_bw) {
  910. case ICE_MAX_AGG_BW_200G:
  911. case ICE_MAX_AGG_BW_100G:
  912. case ICE_MAX_AGG_BW_50G:
  913. hw->itr_gran = ICE_ITR_GRAN_ABOVE_25;
  914. hw->intrl_gran = ICE_INTRL_GRAN_ABOVE_25;
  915. break;
  916. case ICE_MAX_AGG_BW_25G:
  917. hw->itr_gran = ICE_ITR_GRAN_MAX_25;
  918. hw->intrl_gran = ICE_INTRL_GRAN_MAX_25;
  919. break;
  920. }
  921. }
  922. /**
  923. * ice_init_hw - main hardware initialization routine
  924. * @hw: pointer to the hardware structure
  925. */
  926. int ice_init_hw(struct ice_hw *hw)
  927. {
  928. struct ice_aqc_get_phy_caps_data *pcaps __free(kfree) = NULL;
  929. void *mac_buf __free(kfree) = NULL;
  930. u16 mac_buf_len;
  931. int status;
  932. /* Set MAC type based on DeviceID */
  933. status = ice_set_mac_type(hw);
  934. if (status)
  935. return status;
  936. hw->pf_id = FIELD_GET(PF_FUNC_RID_FUNC_NUM_M, rd32(hw, PF_FUNC_RID));
  937. status = ice_reset(hw, ICE_RESET_PFR);
  938. if (status)
  939. return status;
  940. ice_get_itr_intrl_gran(hw);
  941. status = ice_create_all_ctrlq(hw);
  942. if (status)
  943. goto err_unroll_cqinit;
  944. status = ice_fwlog_init(hw);
  945. if (status)
  946. ice_debug(hw, ICE_DBG_FW_LOG, "Error initializing FW logging: %d\n",
  947. status);
  948. status = ice_clear_pf_cfg(hw);
  949. if (status)
  950. goto err_unroll_cqinit;
  951. /* Set bit to enable Flow Director filters */
  952. wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
  953. INIT_LIST_HEAD(&hw->fdir_list_head);
  954. ice_clear_pxe_mode(hw);
  955. status = ice_init_nvm(hw);
  956. if (status)
  957. goto err_unroll_cqinit;
  958. status = ice_get_caps(hw);
  959. if (status)
  960. goto err_unroll_cqinit;
  961. if (!hw->port_info)
  962. hw->port_info = devm_kzalloc(ice_hw_to_dev(hw),
  963. sizeof(*hw->port_info),
  964. GFP_KERNEL);
  965. if (!hw->port_info) {
  966. status = -ENOMEM;
  967. goto err_unroll_cqinit;
  968. }
  969. hw->port_info->local_fwd_mode = ICE_LOCAL_FWD_MODE_ENABLED;
  970. /* set the back pointer to HW */
  971. hw->port_info->hw = hw;
  972. /* Initialize port_info struct with switch configuration data */
  973. status = ice_get_initial_sw_cfg(hw);
  974. if (status)
  975. goto err_unroll_alloc;
  976. hw->evb_veb = true;
  977. /* init xarray for identifying scheduling nodes uniquely */
  978. xa_init_flags(&hw->port_info->sched_node_ids, XA_FLAGS_ALLOC);
  979. /* Query the allocated resources for Tx scheduler */
  980. status = ice_sched_query_res_alloc(hw);
  981. if (status) {
  982. ice_debug(hw, ICE_DBG_SCHED, "Failed to get scheduler allocated resources\n");
  983. goto err_unroll_alloc;
  984. }
  985. ice_sched_get_psm_clk_freq(hw);
  986. /* Initialize port_info struct with scheduler data */
  987. status = ice_sched_init_port(hw->port_info);
  988. if (status)
  989. goto err_unroll_sched;
  990. pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
  991. if (!pcaps) {
  992. status = -ENOMEM;
  993. goto err_unroll_sched;
  994. }
  995. /* Initialize port_info struct with PHY capabilities */
  996. status = ice_aq_get_phy_caps(hw->port_info, false,
  997. ICE_AQC_REPORT_TOPO_CAP_MEDIA, pcaps,
  998. NULL);
  999. if (status)
  1000. dev_warn(ice_hw_to_dev(hw), "Get PHY capabilities failed status = %d, continuing anyway\n",
  1001. status);
  1002. /* Initialize port_info struct with link information */
  1003. status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
  1004. if (status)
  1005. goto err_unroll_sched;
  1006. /* need a valid SW entry point to build a Tx tree */
  1007. if (!hw->sw_entry_point_layer) {
  1008. ice_debug(hw, ICE_DBG_SCHED, "invalid sw entry point\n");
  1009. status = -EIO;
  1010. goto err_unroll_sched;
  1011. }
  1012. INIT_LIST_HEAD(&hw->agg_list);
  1013. /* Initialize max burst size */
  1014. if (!hw->max_burst_size)
  1015. ice_cfg_rl_burst_size(hw, ICE_SCHED_DFLT_BURST_SIZE);
  1016. status = ice_init_fltr_mgmt_struct(hw);
  1017. if (status)
  1018. goto err_unroll_sched;
  1019. /* Get MAC information */
  1020. /* A single port can report up to two (LAN and WoL) addresses */
  1021. mac_buf = kcalloc(2, sizeof(struct ice_aqc_manage_mac_read_resp),
  1022. GFP_KERNEL);
  1023. if (!mac_buf) {
  1024. status = -ENOMEM;
  1025. goto err_unroll_fltr_mgmt_struct;
  1026. }
  1027. mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp);
  1028. status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL);
  1029. if (status)
  1030. goto err_unroll_fltr_mgmt_struct;
  1031. /* enable jumbo frame support at MAC level */
  1032. status = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
  1033. if (status)
  1034. goto err_unroll_fltr_mgmt_struct;
  1035. /* Obtain counter base index which would be used by flow director */
  1036. status = ice_alloc_fd_res_cntr(hw, &hw->fd_ctr_base);
  1037. if (status)
  1038. goto err_unroll_fltr_mgmt_struct;
  1039. status = ice_init_hw_tbls(hw);
  1040. if (status)
  1041. goto err_unroll_fltr_mgmt_struct;
  1042. mutex_init(&hw->tnl_lock);
  1043. ice_init_chk_recipe_reuse_support(hw);
  1044. return 0;
  1045. err_unroll_fltr_mgmt_struct:
  1046. ice_cleanup_fltr_mgmt_struct(hw);
  1047. err_unroll_sched:
  1048. ice_sched_cleanup_all(hw);
  1049. err_unroll_alloc:
  1050. devm_kfree(ice_hw_to_dev(hw), hw->port_info);
  1051. err_unroll_cqinit:
  1052. ice_destroy_all_ctrlq(hw);
  1053. return status;
  1054. }
  1055. /**
  1056. * ice_deinit_hw - unroll initialization operations done by ice_init_hw
  1057. * @hw: pointer to the hardware structure
  1058. *
  1059. * This should be called only during nominal operation, not as a result of
  1060. * ice_init_hw() failing since ice_init_hw() will take care of unrolling
  1061. * applicable initializations if it fails for any reason.
  1062. */
  1063. void ice_deinit_hw(struct ice_hw *hw)
  1064. {
  1065. ice_free_fd_res_cntr(hw, hw->fd_ctr_base);
  1066. ice_cleanup_fltr_mgmt_struct(hw);
  1067. ice_sched_cleanup_all(hw);
  1068. ice_sched_clear_agg(hw);
  1069. ice_free_seg(hw);
  1070. ice_free_hw_tbls(hw);
  1071. mutex_destroy(&hw->tnl_lock);
  1072. ice_fwlog_deinit(hw);
  1073. ice_destroy_all_ctrlq(hw);
  1074. /* Clear VSI contexts if not already cleared */
  1075. ice_clear_all_vsi_ctx(hw);
  1076. }
  1077. /**
  1078. * ice_check_reset - Check to see if a global reset is complete
  1079. * @hw: pointer to the hardware structure
  1080. */
  1081. int ice_check_reset(struct ice_hw *hw)
  1082. {
  1083. u32 cnt, reg = 0, grst_timeout, uld_mask;
  1084. /* Poll for Device Active state in case a recent CORER, GLOBR,
  1085. * or EMPR has occurred. The grst delay value is in 100ms units.
  1086. * Add 1sec for outstanding AQ commands that can take a long time.
  1087. */
  1088. grst_timeout = FIELD_GET(GLGEN_RSTCTL_GRSTDEL_M,
  1089. rd32(hw, GLGEN_RSTCTL)) + 10;
  1090. for (cnt = 0; cnt < grst_timeout; cnt++) {
  1091. mdelay(100);
  1092. reg = rd32(hw, GLGEN_RSTAT);
  1093. if (!(reg & GLGEN_RSTAT_DEVSTATE_M))
  1094. break;
  1095. }
  1096. if (cnt == grst_timeout) {
  1097. ice_debug(hw, ICE_DBG_INIT, "Global reset polling failed to complete.\n");
  1098. return -EIO;
  1099. }
  1100. #define ICE_RESET_DONE_MASK (GLNVM_ULD_PCIER_DONE_M |\
  1101. GLNVM_ULD_PCIER_DONE_1_M |\
  1102. GLNVM_ULD_CORER_DONE_M |\
  1103. GLNVM_ULD_GLOBR_DONE_M |\
  1104. GLNVM_ULD_POR_DONE_M |\
  1105. GLNVM_ULD_POR_DONE_1_M |\
  1106. GLNVM_ULD_PCIER_DONE_2_M)
  1107. uld_mask = ICE_RESET_DONE_MASK | (hw->func_caps.common_cap.rdma ?
  1108. GLNVM_ULD_PE_DONE_M : 0);
  1109. /* Device is Active; check Global Reset processes are done */
  1110. for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
  1111. reg = rd32(hw, GLNVM_ULD) & uld_mask;
  1112. if (reg == uld_mask) {
  1113. ice_debug(hw, ICE_DBG_INIT, "Global reset processes done. %d\n", cnt);
  1114. break;
  1115. }
  1116. mdelay(10);
  1117. }
  1118. if (cnt == ICE_PF_RESET_WAIT_COUNT) {
  1119. ice_debug(hw, ICE_DBG_INIT, "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
  1120. reg);
  1121. return -EIO;
  1122. }
  1123. return 0;
  1124. }
  1125. /**
  1126. * ice_pf_reset - Reset the PF
  1127. * @hw: pointer to the hardware structure
  1128. *
  1129. * If a global reset has been triggered, this function checks
  1130. * for its completion and then issues the PF reset
  1131. */
  1132. static int ice_pf_reset(struct ice_hw *hw)
  1133. {
  1134. u32 cnt, reg;
  1135. /* If at function entry a global reset was already in progress, i.e.
  1136. * state is not 'device active' or any of the reset done bits are not
  1137. * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
  1138. * global reset is done.
  1139. */
  1140. if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) ||
  1141. (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) {
  1142. /* poll on global reset currently in progress until done */
  1143. if (ice_check_reset(hw))
  1144. return -EIO;
  1145. return 0;
  1146. }
  1147. /* Reset the PF */
  1148. reg = rd32(hw, PFGEN_CTRL);
  1149. wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M));
  1150. /* Wait for the PFR to complete. The wait time is the global config lock
  1151. * timeout plus the PFR timeout which will account for a possible reset
  1152. * that is occurring during a download package operation.
  1153. */
  1154. for (cnt = 0; cnt < ICE_GLOBAL_CFG_LOCK_TIMEOUT +
  1155. ICE_PF_RESET_WAIT_COUNT; cnt++) {
  1156. reg = rd32(hw, PFGEN_CTRL);
  1157. if (!(reg & PFGEN_CTRL_PFSWR_M))
  1158. break;
  1159. mdelay(1);
  1160. }
  1161. if (cnt == ICE_PF_RESET_WAIT_COUNT) {
  1162. ice_debug(hw, ICE_DBG_INIT, "PF reset polling failed to complete.\n");
  1163. return -EIO;
  1164. }
  1165. return 0;
  1166. }
  1167. /**
  1168. * ice_reset - Perform different types of reset
  1169. * @hw: pointer to the hardware structure
  1170. * @req: reset request
  1171. *
  1172. * This function triggers a reset as specified by the req parameter.
  1173. *
  1174. * Note:
  1175. * If anything other than a PF reset is triggered, PXE mode is restored.
  1176. * This has to be cleared using ice_clear_pxe_mode again, once the AQ
  1177. * interface has been restored in the rebuild flow.
  1178. */
  1179. int ice_reset(struct ice_hw *hw, enum ice_reset_req req)
  1180. {
  1181. u32 val = 0;
  1182. switch (req) {
  1183. case ICE_RESET_PFR:
  1184. return ice_pf_reset(hw);
  1185. case ICE_RESET_CORER:
  1186. ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n");
  1187. val = GLGEN_RTRIG_CORER_M;
  1188. break;
  1189. case ICE_RESET_GLOBR:
  1190. ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n");
  1191. val = GLGEN_RTRIG_GLOBR_M;
  1192. break;
  1193. default:
  1194. return -EINVAL;
  1195. }
  1196. val |= rd32(hw, GLGEN_RTRIG);
  1197. wr32(hw, GLGEN_RTRIG, val);
  1198. ice_flush(hw);
  1199. /* wait for the FW to be ready */
  1200. return ice_check_reset(hw);
  1201. }
  1202. /**
  1203. * ice_copy_rxq_ctx_to_hw
  1204. * @hw: pointer to the hardware structure
  1205. * @ice_rxq_ctx: pointer to the rxq context
  1206. * @rxq_index: the index of the Rx queue
  1207. *
  1208. * Copies rxq context from dense structure to HW register space
  1209. */
  1210. static int
  1211. ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)
  1212. {
  1213. u8 i;
  1214. if (!ice_rxq_ctx)
  1215. return -EINVAL;
  1216. if (rxq_index > QRX_CTRL_MAX_INDEX)
  1217. return -EINVAL;
  1218. /* Copy each dword separately to HW */
  1219. for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) {
  1220. wr32(hw, QRX_CONTEXT(i, rxq_index),
  1221. *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
  1222. ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i,
  1223. *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
  1224. }
  1225. return 0;
  1226. }
  1227. /* LAN Rx Queue Context */
  1228. static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
  1229. /* Field Width LSB */
  1230. ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0),
  1231. ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13),
  1232. ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32),
  1233. ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89),
  1234. ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102),
  1235. ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109),
  1236. ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114),
  1237. ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116),
  1238. ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117),
  1239. ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119),
  1240. ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120),
  1241. ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124),
  1242. ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127),
  1243. ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174),
  1244. ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193),
  1245. ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194),
  1246. ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195),
  1247. ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196),
  1248. ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198),
  1249. ICE_CTX_STORE(ice_rlan_ctx, prefena, 1, 201),
  1250. { 0 }
  1251. };
  1252. /**
  1253. * ice_write_rxq_ctx
  1254. * @hw: pointer to the hardware structure
  1255. * @rlan_ctx: pointer to the rxq context
  1256. * @rxq_index: the index of the Rx queue
  1257. *
  1258. * Converts rxq context from sparse to dense structure and then writes
  1259. * it to HW register space and enables the hardware to prefetch descriptors
  1260. * instead of only fetching them on demand
  1261. */
  1262. int ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
  1263. u32 rxq_index)
  1264. {
  1265. u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
  1266. if (!rlan_ctx)
  1267. return -EINVAL;
  1268. rlan_ctx->prefena = 1;
  1269. ice_set_ctx(hw, (u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
  1270. return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
  1271. }
  1272. /* LAN Tx Queue Context */
  1273. const struct ice_ctx_ele ice_tlan_ctx_info[] = {
  1274. /* Field Width LSB */
  1275. ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0),
  1276. ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57),
  1277. ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60),
  1278. ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65),
  1279. ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68),
  1280. ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78),
  1281. ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80),
  1282. ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90),
  1283. ICE_CTX_STORE(ice_tlan_ctx, internal_usage_flag, 1, 91),
  1284. ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92),
  1285. ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93),
  1286. ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101),
  1287. ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102),
  1288. ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103),
  1289. ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104),
  1290. ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105),
  1291. ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114),
  1292. ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128),
  1293. ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129),
  1294. ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135),
  1295. ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148),
  1296. ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152),
  1297. ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153),
  1298. ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164),
  1299. ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165),
  1300. ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166),
  1301. ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168),
  1302. ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 122, 171),
  1303. { 0 }
  1304. };
  1305. /* Sideband Queue command wrappers */
  1306. /**
  1307. * ice_sbq_send_cmd - send Sideband Queue command to Sideband Queue
  1308. * @hw: pointer to the HW struct
  1309. * @desc: descriptor describing the command
  1310. * @buf: buffer to use for indirect commands (NULL for direct commands)
  1311. * @buf_size: size of buffer for indirect commands (0 for direct commands)
  1312. * @cd: pointer to command details structure
  1313. */
  1314. static int
  1315. ice_sbq_send_cmd(struct ice_hw *hw, struct ice_sbq_cmd_desc *desc,
  1316. void *buf, u16 buf_size, struct ice_sq_cd *cd)
  1317. {
  1318. return ice_sq_send_cmd(hw, ice_get_sbq(hw),
  1319. (struct ice_aq_desc *)desc, buf, buf_size, cd);
  1320. }
  1321. /**
  1322. * ice_sbq_rw_reg - Fill Sideband Queue command
  1323. * @hw: pointer to the HW struct
  1324. * @in: message info to be filled in descriptor
  1325. * @flags: control queue descriptor flags
  1326. */
  1327. int ice_sbq_rw_reg(struct ice_hw *hw, struct ice_sbq_msg_input *in, u16 flags)
  1328. {
  1329. struct ice_sbq_cmd_desc desc = {0};
  1330. struct ice_sbq_msg_req msg = {0};
  1331. u16 msg_len;
  1332. int status;
  1333. msg_len = sizeof(msg);
  1334. msg.dest_dev = in->dest_dev;
  1335. msg.opcode = in->opcode;
  1336. msg.flags = ICE_SBQ_MSG_FLAGS;
  1337. msg.sbe_fbe = ICE_SBQ_MSG_SBE_FBE;
  1338. msg.msg_addr_low = cpu_to_le16(in->msg_addr_low);
  1339. msg.msg_addr_high = cpu_to_le32(in->msg_addr_high);
  1340. if (in->opcode)
  1341. msg.data = cpu_to_le32(in->data);
  1342. else
  1343. /* data read comes back in completion, so shorten the struct by
  1344. * sizeof(msg.data)
  1345. */
  1346. msg_len -= sizeof(msg.data);
  1347. desc.flags = cpu_to_le16(flags);
  1348. desc.opcode = cpu_to_le16(ice_sbq_opc_neigh_dev_req);
  1349. desc.param0.cmd_len = cpu_to_le16(msg_len);
  1350. status = ice_sbq_send_cmd(hw, &desc, &msg, msg_len, NULL);
  1351. if (!status && !in->opcode)
  1352. in->data = le32_to_cpu
  1353. (((struct ice_sbq_msg_cmpl *)&msg)->data);
  1354. return status;
  1355. }
  1356. /* FW Admin Queue command wrappers */
  1357. /* Software lock/mutex that is meant to be held while the Global Config Lock
  1358. * in firmware is acquired by the software to prevent most (but not all) types
  1359. * of AQ commands from being sent to FW
  1360. */
  1361. DEFINE_MUTEX(ice_global_cfg_lock_sw);
  1362. /**
  1363. * ice_should_retry_sq_send_cmd
  1364. * @opcode: AQ opcode
  1365. *
  1366. * Decide if we should retry the send command routine for the ATQ, depending
  1367. * on the opcode.
  1368. */
  1369. static bool ice_should_retry_sq_send_cmd(u16 opcode)
  1370. {
  1371. switch (opcode) {
  1372. case ice_aqc_opc_get_link_topo:
  1373. case ice_aqc_opc_lldp_stop:
  1374. case ice_aqc_opc_lldp_start:
  1375. case ice_aqc_opc_lldp_filter_ctrl:
  1376. return true;
  1377. }
  1378. return false;
  1379. }
  1380. /**
  1381. * ice_sq_send_cmd_retry - send command to Control Queue (ATQ)
  1382. * @hw: pointer to the HW struct
  1383. * @cq: pointer to the specific Control queue
  1384. * @desc: prefilled descriptor describing the command
  1385. * @buf: buffer to use for indirect commands (or NULL for direct commands)
  1386. * @buf_size: size of buffer for indirect commands (or 0 for direct commands)
  1387. * @cd: pointer to command details structure
  1388. *
  1389. * Retry sending the FW Admin Queue command, multiple times, to the FW Admin
  1390. * Queue if the EBUSY AQ error is returned.
  1391. */
  1392. static int
  1393. ice_sq_send_cmd_retry(struct ice_hw *hw, struct ice_ctl_q_info *cq,
  1394. struct ice_aq_desc *desc, void *buf, u16 buf_size,
  1395. struct ice_sq_cd *cd)
  1396. {
  1397. struct ice_aq_desc desc_cpy;
  1398. bool is_cmd_for_retry;
  1399. u8 idx = 0;
  1400. u16 opcode;
  1401. int status;
  1402. opcode = le16_to_cpu(desc->opcode);
  1403. is_cmd_for_retry = ice_should_retry_sq_send_cmd(opcode);
  1404. memset(&desc_cpy, 0, sizeof(desc_cpy));
  1405. if (is_cmd_for_retry) {
  1406. /* All retryable cmds are direct, without buf. */
  1407. WARN_ON(buf);
  1408. memcpy(&desc_cpy, desc, sizeof(desc_cpy));
  1409. }
  1410. do {
  1411. status = ice_sq_send_cmd(hw, cq, desc, buf, buf_size, cd);
  1412. if (!is_cmd_for_retry || !status ||
  1413. hw->adminq.sq_last_status != ICE_AQ_RC_EBUSY)
  1414. break;
  1415. memcpy(desc, &desc_cpy, sizeof(desc_cpy));
  1416. msleep(ICE_SQ_SEND_DELAY_TIME_MS);
  1417. } while (++idx < ICE_SQ_SEND_MAX_EXECUTE);
  1418. return status;
  1419. }
  1420. /**
  1421. * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
  1422. * @hw: pointer to the HW struct
  1423. * @desc: descriptor describing the command
  1424. * @buf: buffer to use for indirect commands (NULL for direct commands)
  1425. * @buf_size: size of buffer for indirect commands (0 for direct commands)
  1426. * @cd: pointer to command details structure
  1427. *
  1428. * Helper function to send FW Admin Queue commands to the FW Admin Queue.
  1429. */
  1430. int
  1431. ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
  1432. u16 buf_size, struct ice_sq_cd *cd)
  1433. {
  1434. struct ice_aqc_req_res *cmd = &desc->params.res_owner;
  1435. bool lock_acquired = false;
  1436. int status;
  1437. /* When a package download is in process (i.e. when the firmware's
  1438. * Global Configuration Lock resource is held), only the Download
  1439. * Package, Get Version, Get Package Info List, Upload Section,
  1440. * Update Package, Set Port Parameters, Get/Set VLAN Mode Parameters,
  1441. * Add Recipe, Set Recipes to Profile Association, Get Recipe, and Get
  1442. * Recipes to Profile Association, and Release Resource (with resource
  1443. * ID set to Global Config Lock) AdminQ commands are allowed; all others
  1444. * must block until the package download completes and the Global Config
  1445. * Lock is released. See also ice_acquire_global_cfg_lock().
  1446. */
  1447. switch (le16_to_cpu(desc->opcode)) {
  1448. case ice_aqc_opc_download_pkg:
  1449. case ice_aqc_opc_get_pkg_info_list:
  1450. case ice_aqc_opc_get_ver:
  1451. case ice_aqc_opc_upload_section:
  1452. case ice_aqc_opc_update_pkg:
  1453. case ice_aqc_opc_set_port_params:
  1454. case ice_aqc_opc_get_vlan_mode_parameters:
  1455. case ice_aqc_opc_set_vlan_mode_parameters:
  1456. case ice_aqc_opc_set_tx_topo:
  1457. case ice_aqc_opc_get_tx_topo:
  1458. case ice_aqc_opc_add_recipe:
  1459. case ice_aqc_opc_recipe_to_profile:
  1460. case ice_aqc_opc_get_recipe:
  1461. case ice_aqc_opc_get_recipe_to_profile:
  1462. break;
  1463. case ice_aqc_opc_release_res:
  1464. if (le16_to_cpu(cmd->res_id) == ICE_AQC_RES_ID_GLBL_LOCK)
  1465. break;
  1466. fallthrough;
  1467. default:
  1468. mutex_lock(&ice_global_cfg_lock_sw);
  1469. lock_acquired = true;
  1470. break;
  1471. }
  1472. status = ice_sq_send_cmd_retry(hw, &hw->adminq, desc, buf, buf_size, cd);
  1473. if (lock_acquired)
  1474. mutex_unlock(&ice_global_cfg_lock_sw);
  1475. return status;
  1476. }
  1477. /**
  1478. * ice_aq_get_fw_ver
  1479. * @hw: pointer to the HW struct
  1480. * @cd: pointer to command details structure or NULL
  1481. *
  1482. * Get the firmware version (0x0001) from the admin queue commands
  1483. */
  1484. int ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
  1485. {
  1486. struct ice_aqc_get_ver *resp;
  1487. struct ice_aq_desc desc;
  1488. int status;
  1489. resp = &desc.params.get_ver;
  1490. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
  1491. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1492. if (!status) {
  1493. hw->fw_branch = resp->fw_branch;
  1494. hw->fw_maj_ver = resp->fw_major;
  1495. hw->fw_min_ver = resp->fw_minor;
  1496. hw->fw_patch = resp->fw_patch;
  1497. hw->fw_build = le32_to_cpu(resp->fw_build);
  1498. hw->api_branch = resp->api_branch;
  1499. hw->api_maj_ver = resp->api_major;
  1500. hw->api_min_ver = resp->api_minor;
  1501. hw->api_patch = resp->api_patch;
  1502. }
  1503. return status;
  1504. }
  1505. /**
  1506. * ice_aq_send_driver_ver
  1507. * @hw: pointer to the HW struct
  1508. * @dv: driver's major, minor version
  1509. * @cd: pointer to command details structure or NULL
  1510. *
  1511. * Send the driver version (0x0002) to the firmware
  1512. */
  1513. int
  1514. ice_aq_send_driver_ver(struct ice_hw *hw, struct ice_driver_ver *dv,
  1515. struct ice_sq_cd *cd)
  1516. {
  1517. struct ice_aqc_driver_ver *cmd;
  1518. struct ice_aq_desc desc;
  1519. u16 len;
  1520. cmd = &desc.params.driver_ver;
  1521. if (!dv)
  1522. return -EINVAL;
  1523. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_driver_ver);
  1524. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1525. cmd->major_ver = dv->major_ver;
  1526. cmd->minor_ver = dv->minor_ver;
  1527. cmd->build_ver = dv->build_ver;
  1528. cmd->subbuild_ver = dv->subbuild_ver;
  1529. len = 0;
  1530. while (len < sizeof(dv->driver_string) &&
  1531. isascii(dv->driver_string[len]) && dv->driver_string[len])
  1532. len++;
  1533. return ice_aq_send_cmd(hw, &desc, dv->driver_string, len, cd);
  1534. }
  1535. /**
  1536. * ice_aq_q_shutdown
  1537. * @hw: pointer to the HW struct
  1538. * @unloading: is the driver unloading itself
  1539. *
  1540. * Tell the Firmware that we're shutting down the AdminQ and whether
  1541. * or not the driver is unloading as well (0x0003).
  1542. */
  1543. int ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
  1544. {
  1545. struct ice_aqc_q_shutdown *cmd;
  1546. struct ice_aq_desc desc;
  1547. cmd = &desc.params.q_shutdown;
  1548. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
  1549. if (unloading)
  1550. cmd->driver_unloading = ICE_AQC_DRIVER_UNLOADING;
  1551. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  1552. }
  1553. /**
  1554. * ice_aq_req_res
  1555. * @hw: pointer to the HW struct
  1556. * @res: resource ID
  1557. * @access: access type
  1558. * @sdp_number: resource number
  1559. * @timeout: the maximum time in ms that the driver may hold the resource
  1560. * @cd: pointer to command details structure or NULL
  1561. *
  1562. * Requests common resource using the admin queue commands (0x0008).
  1563. * When attempting to acquire the Global Config Lock, the driver can
  1564. * learn of three states:
  1565. * 1) 0 - acquired lock, and can perform download package
  1566. * 2) -EIO - did not get lock, driver should fail to load
  1567. * 3) -EALREADY - did not get lock, but another driver has
  1568. * successfully downloaded the package; the driver does
  1569. * not have to download the package and can continue
  1570. * loading
  1571. *
  1572. * Note that if the caller is in an acquire lock, perform action, release lock
  1573. * phase of operation, it is possible that the FW may detect a timeout and issue
  1574. * a CORER. In this case, the driver will receive a CORER interrupt and will
  1575. * have to determine its cause. The calling thread that is handling this flow
  1576. * will likely get an error propagated back to it indicating the Download
  1577. * Package, Update Package or the Release Resource AQ commands timed out.
  1578. */
  1579. static int
  1580. ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res,
  1581. enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout,
  1582. struct ice_sq_cd *cd)
  1583. {
  1584. struct ice_aqc_req_res *cmd_resp;
  1585. struct ice_aq_desc desc;
  1586. int status;
  1587. cmd_resp = &desc.params.res_owner;
  1588. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res);
  1589. cmd_resp->res_id = cpu_to_le16(res);
  1590. cmd_resp->access_type = cpu_to_le16(access);
  1591. cmd_resp->res_number = cpu_to_le32(sdp_number);
  1592. cmd_resp->timeout = cpu_to_le32(*timeout);
  1593. *timeout = 0;
  1594. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1595. /* The completion specifies the maximum time in ms that the driver
  1596. * may hold the resource in the Timeout field.
  1597. */
  1598. /* Global config lock response utilizes an additional status field.
  1599. *
  1600. * If the Global config lock resource is held by some other driver, the
  1601. * command completes with ICE_AQ_RES_GLBL_IN_PROG in the status field
  1602. * and the timeout field indicates the maximum time the current owner
  1603. * of the resource has to free it.
  1604. */
  1605. if (res == ICE_GLOBAL_CFG_LOCK_RES_ID) {
  1606. if (le16_to_cpu(cmd_resp->status) == ICE_AQ_RES_GLBL_SUCCESS) {
  1607. *timeout = le32_to_cpu(cmd_resp->timeout);
  1608. return 0;
  1609. } else if (le16_to_cpu(cmd_resp->status) ==
  1610. ICE_AQ_RES_GLBL_IN_PROG) {
  1611. *timeout = le32_to_cpu(cmd_resp->timeout);
  1612. return -EIO;
  1613. } else if (le16_to_cpu(cmd_resp->status) ==
  1614. ICE_AQ_RES_GLBL_DONE) {
  1615. return -EALREADY;
  1616. }
  1617. /* invalid FW response, force a timeout immediately */
  1618. *timeout = 0;
  1619. return -EIO;
  1620. }
  1621. /* If the resource is held by some other driver, the command completes
  1622. * with a busy return value and the timeout field indicates the maximum
  1623. * time the current owner of the resource has to free it.
  1624. */
  1625. if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY)
  1626. *timeout = le32_to_cpu(cmd_resp->timeout);
  1627. return status;
  1628. }
  1629. /**
  1630. * ice_aq_release_res
  1631. * @hw: pointer to the HW struct
  1632. * @res: resource ID
  1633. * @sdp_number: resource number
  1634. * @cd: pointer to command details structure or NULL
  1635. *
  1636. * release common resource using the admin queue commands (0x0009)
  1637. */
  1638. static int
  1639. ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number,
  1640. struct ice_sq_cd *cd)
  1641. {
  1642. struct ice_aqc_req_res *cmd;
  1643. struct ice_aq_desc desc;
  1644. cmd = &desc.params.res_owner;
  1645. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res);
  1646. cmd->res_id = cpu_to_le16(res);
  1647. cmd->res_number = cpu_to_le32(sdp_number);
  1648. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1649. }
  1650. /**
  1651. * ice_acquire_res
  1652. * @hw: pointer to the HW structure
  1653. * @res: resource ID
  1654. * @access: access type (read or write)
  1655. * @timeout: timeout in milliseconds
  1656. *
  1657. * This function will attempt to acquire the ownership of a resource.
  1658. */
  1659. int
  1660. ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
  1661. enum ice_aq_res_access_type access, u32 timeout)
  1662. {
  1663. #define ICE_RES_POLLING_DELAY_MS 10
  1664. u32 delay = ICE_RES_POLLING_DELAY_MS;
  1665. u32 time_left = timeout;
  1666. int status;
  1667. status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
  1668. /* A return code of -EALREADY means that another driver has
  1669. * previously acquired the resource and performed any necessary updates;
  1670. * in this case the caller does not obtain the resource and has no
  1671. * further work to do.
  1672. */
  1673. if (status == -EALREADY)
  1674. goto ice_acquire_res_exit;
  1675. if (status)
  1676. ice_debug(hw, ICE_DBG_RES, "resource %d acquire type %d failed.\n", res, access);
  1677. /* If necessary, poll until the current lock owner timeouts */
  1678. timeout = time_left;
  1679. while (status && timeout && time_left) {
  1680. mdelay(delay);
  1681. timeout = (timeout > delay) ? timeout - delay : 0;
  1682. status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
  1683. if (status == -EALREADY)
  1684. /* lock free, but no work to do */
  1685. break;
  1686. if (!status)
  1687. /* lock acquired */
  1688. break;
  1689. }
  1690. if (status && status != -EALREADY)
  1691. ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n");
  1692. ice_acquire_res_exit:
  1693. if (status == -EALREADY) {
  1694. if (access == ICE_RES_WRITE)
  1695. ice_debug(hw, ICE_DBG_RES, "resource indicates no work to do.\n");
  1696. else
  1697. ice_debug(hw, ICE_DBG_RES, "Warning: -EALREADY not expected\n");
  1698. }
  1699. return status;
  1700. }
  1701. /**
  1702. * ice_release_res
  1703. * @hw: pointer to the HW structure
  1704. * @res: resource ID
  1705. *
  1706. * This function will release a resource using the proper Admin Command.
  1707. */
  1708. void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
  1709. {
  1710. unsigned long timeout;
  1711. int status;
  1712. /* there are some rare cases when trying to release the resource
  1713. * results in an admin queue timeout, so handle them correctly
  1714. */
  1715. timeout = jiffies + 10 * ICE_CTL_Q_SQ_CMD_TIMEOUT;
  1716. do {
  1717. status = ice_aq_release_res(hw, res, 0, NULL);
  1718. if (status != -EIO)
  1719. break;
  1720. usleep_range(1000, 2000);
  1721. } while (time_before(jiffies, timeout));
  1722. }
  1723. /**
  1724. * ice_aq_alloc_free_res - command to allocate/free resources
  1725. * @hw: pointer to the HW struct
  1726. * @buf: Indirect buffer to hold data parameters and response
  1727. * @buf_size: size of buffer for indirect commands
  1728. * @opc: pass in the command opcode
  1729. *
  1730. * Helper function to allocate/free resources using the admin queue commands
  1731. */
  1732. int ice_aq_alloc_free_res(struct ice_hw *hw,
  1733. struct ice_aqc_alloc_free_res_elem *buf, u16 buf_size,
  1734. enum ice_adminq_opc opc)
  1735. {
  1736. struct ice_aqc_alloc_free_res_cmd *cmd;
  1737. struct ice_aq_desc desc;
  1738. cmd = &desc.params.sw_res_ctrl;
  1739. if (!buf || buf_size < flex_array_size(buf, elem, 1))
  1740. return -EINVAL;
  1741. ice_fill_dflt_direct_cmd_desc(&desc, opc);
  1742. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1743. cmd->num_entries = cpu_to_le16(1);
  1744. return ice_aq_send_cmd(hw, &desc, buf, buf_size, NULL);
  1745. }
  1746. /**
  1747. * ice_alloc_hw_res - allocate resource
  1748. * @hw: pointer to the HW struct
  1749. * @type: type of resource
  1750. * @num: number of resources to allocate
  1751. * @btm: allocate from bottom
  1752. * @res: pointer to array that will receive the resources
  1753. */
  1754. int
  1755. ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res)
  1756. {
  1757. struct ice_aqc_alloc_free_res_elem *buf;
  1758. u16 buf_len;
  1759. int status;
  1760. buf_len = struct_size(buf, elem, num);
  1761. buf = kzalloc(buf_len, GFP_KERNEL);
  1762. if (!buf)
  1763. return -ENOMEM;
  1764. /* Prepare buffer to allocate resource. */
  1765. buf->num_elems = cpu_to_le16(num);
  1766. buf->res_type = cpu_to_le16(type | ICE_AQC_RES_TYPE_FLAG_DEDICATED |
  1767. ICE_AQC_RES_TYPE_FLAG_IGNORE_INDEX);
  1768. if (btm)
  1769. buf->res_type |= cpu_to_le16(ICE_AQC_RES_TYPE_FLAG_SCAN_BOTTOM);
  1770. status = ice_aq_alloc_free_res(hw, buf, buf_len, ice_aqc_opc_alloc_res);
  1771. if (status)
  1772. goto ice_alloc_res_exit;
  1773. memcpy(res, buf->elem, sizeof(*buf->elem) * num);
  1774. ice_alloc_res_exit:
  1775. kfree(buf);
  1776. return status;
  1777. }
  1778. /**
  1779. * ice_free_hw_res - free allocated HW resource
  1780. * @hw: pointer to the HW struct
  1781. * @type: type of resource to free
  1782. * @num: number of resources
  1783. * @res: pointer to array that contains the resources to free
  1784. */
  1785. int ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res)
  1786. {
  1787. struct ice_aqc_alloc_free_res_elem *buf;
  1788. u16 buf_len;
  1789. int status;
  1790. buf_len = struct_size(buf, elem, num);
  1791. buf = kzalloc(buf_len, GFP_KERNEL);
  1792. if (!buf)
  1793. return -ENOMEM;
  1794. /* Prepare buffer to free resource. */
  1795. buf->num_elems = cpu_to_le16(num);
  1796. buf->res_type = cpu_to_le16(type);
  1797. memcpy(buf->elem, res, sizeof(*buf->elem) * num);
  1798. status = ice_aq_alloc_free_res(hw, buf, buf_len, ice_aqc_opc_free_res);
  1799. if (status)
  1800. ice_debug(hw, ICE_DBG_SW, "CQ CMD Buffer:\n");
  1801. kfree(buf);
  1802. return status;
  1803. }
  1804. /**
  1805. * ice_get_num_per_func - determine number of resources per PF
  1806. * @hw: pointer to the HW structure
  1807. * @max: value to be evenly split between each PF
  1808. *
  1809. * Determine the number of valid functions by going through the bitmap returned
  1810. * from parsing capabilities and use this to calculate the number of resources
  1811. * per PF based on the max value passed in.
  1812. */
  1813. static u32 ice_get_num_per_func(struct ice_hw *hw, u32 max)
  1814. {
  1815. u8 funcs;
  1816. #define ICE_CAPS_VALID_FUNCS_M 0xFF
  1817. funcs = hweight8(hw->dev_caps.common_cap.valid_functions &
  1818. ICE_CAPS_VALID_FUNCS_M);
  1819. if (!funcs)
  1820. return 0;
  1821. return max / funcs;
  1822. }
  1823. /**
  1824. * ice_parse_common_caps - parse common device/function capabilities
  1825. * @hw: pointer to the HW struct
  1826. * @caps: pointer to common capabilities structure
  1827. * @elem: the capability element to parse
  1828. * @prefix: message prefix for tracing capabilities
  1829. *
  1830. * Given a capability element, extract relevant details into the common
  1831. * capability structure.
  1832. *
  1833. * Returns: true if the capability matches one of the common capability ids,
  1834. * false otherwise.
  1835. */
  1836. static bool
  1837. ice_parse_common_caps(struct ice_hw *hw, struct ice_hw_common_caps *caps,
  1838. struct ice_aqc_list_caps_elem *elem, const char *prefix)
  1839. {
  1840. u32 logical_id = le32_to_cpu(elem->logical_id);
  1841. u32 phys_id = le32_to_cpu(elem->phys_id);
  1842. u32 number = le32_to_cpu(elem->number);
  1843. u16 cap = le16_to_cpu(elem->cap);
  1844. bool found = true;
  1845. switch (cap) {
  1846. case ICE_AQC_CAPS_VALID_FUNCTIONS:
  1847. caps->valid_functions = number;
  1848. ice_debug(hw, ICE_DBG_INIT, "%s: valid_functions (bitmap) = %d\n", prefix,
  1849. caps->valid_functions);
  1850. break;
  1851. case ICE_AQC_CAPS_SRIOV:
  1852. caps->sr_iov_1_1 = (number == 1);
  1853. ice_debug(hw, ICE_DBG_INIT, "%s: sr_iov_1_1 = %d\n", prefix,
  1854. caps->sr_iov_1_1);
  1855. break;
  1856. case ICE_AQC_CAPS_DCB:
  1857. caps->dcb = (number == 1);
  1858. caps->active_tc_bitmap = logical_id;
  1859. caps->maxtc = phys_id;
  1860. ice_debug(hw, ICE_DBG_INIT, "%s: dcb = %d\n", prefix, caps->dcb);
  1861. ice_debug(hw, ICE_DBG_INIT, "%s: active_tc_bitmap = %d\n", prefix,
  1862. caps->active_tc_bitmap);
  1863. ice_debug(hw, ICE_DBG_INIT, "%s: maxtc = %d\n", prefix, caps->maxtc);
  1864. break;
  1865. case ICE_AQC_CAPS_RSS:
  1866. caps->rss_table_size = number;
  1867. caps->rss_table_entry_width = logical_id;
  1868. ice_debug(hw, ICE_DBG_INIT, "%s: rss_table_size = %d\n", prefix,
  1869. caps->rss_table_size);
  1870. ice_debug(hw, ICE_DBG_INIT, "%s: rss_table_entry_width = %d\n", prefix,
  1871. caps->rss_table_entry_width);
  1872. break;
  1873. case ICE_AQC_CAPS_RXQS:
  1874. caps->num_rxq = number;
  1875. caps->rxq_first_id = phys_id;
  1876. ice_debug(hw, ICE_DBG_INIT, "%s: num_rxq = %d\n", prefix,
  1877. caps->num_rxq);
  1878. ice_debug(hw, ICE_DBG_INIT, "%s: rxq_first_id = %d\n", prefix,
  1879. caps->rxq_first_id);
  1880. break;
  1881. case ICE_AQC_CAPS_TXQS:
  1882. caps->num_txq = number;
  1883. caps->txq_first_id = phys_id;
  1884. ice_debug(hw, ICE_DBG_INIT, "%s: num_txq = %d\n", prefix,
  1885. caps->num_txq);
  1886. ice_debug(hw, ICE_DBG_INIT, "%s: txq_first_id = %d\n", prefix,
  1887. caps->txq_first_id);
  1888. break;
  1889. case ICE_AQC_CAPS_MSIX:
  1890. caps->num_msix_vectors = number;
  1891. caps->msix_vector_first_id = phys_id;
  1892. ice_debug(hw, ICE_DBG_INIT, "%s: num_msix_vectors = %d\n", prefix,
  1893. caps->num_msix_vectors);
  1894. ice_debug(hw, ICE_DBG_INIT, "%s: msix_vector_first_id = %d\n", prefix,
  1895. caps->msix_vector_first_id);
  1896. break;
  1897. case ICE_AQC_CAPS_PENDING_NVM_VER:
  1898. caps->nvm_update_pending_nvm = true;
  1899. ice_debug(hw, ICE_DBG_INIT, "%s: update_pending_nvm\n", prefix);
  1900. break;
  1901. case ICE_AQC_CAPS_PENDING_OROM_VER:
  1902. caps->nvm_update_pending_orom = true;
  1903. ice_debug(hw, ICE_DBG_INIT, "%s: update_pending_orom\n", prefix);
  1904. break;
  1905. case ICE_AQC_CAPS_PENDING_NET_VER:
  1906. caps->nvm_update_pending_netlist = true;
  1907. ice_debug(hw, ICE_DBG_INIT, "%s: update_pending_netlist\n", prefix);
  1908. break;
  1909. case ICE_AQC_CAPS_NVM_MGMT:
  1910. caps->nvm_unified_update =
  1911. (number & ICE_NVM_MGMT_UNIFIED_UPD_SUPPORT) ?
  1912. true : false;
  1913. ice_debug(hw, ICE_DBG_INIT, "%s: nvm_unified_update = %d\n", prefix,
  1914. caps->nvm_unified_update);
  1915. break;
  1916. case ICE_AQC_CAPS_RDMA:
  1917. caps->rdma = (number == 1);
  1918. ice_debug(hw, ICE_DBG_INIT, "%s: rdma = %d\n", prefix, caps->rdma);
  1919. break;
  1920. case ICE_AQC_CAPS_MAX_MTU:
  1921. caps->max_mtu = number;
  1922. ice_debug(hw, ICE_DBG_INIT, "%s: max_mtu = %d\n",
  1923. prefix, caps->max_mtu);
  1924. break;
  1925. case ICE_AQC_CAPS_PCIE_RESET_AVOIDANCE:
  1926. caps->pcie_reset_avoidance = (number > 0);
  1927. ice_debug(hw, ICE_DBG_INIT,
  1928. "%s: pcie_reset_avoidance = %d\n", prefix,
  1929. caps->pcie_reset_avoidance);
  1930. break;
  1931. case ICE_AQC_CAPS_POST_UPDATE_RESET_RESTRICT:
  1932. caps->reset_restrict_support = (number == 1);
  1933. ice_debug(hw, ICE_DBG_INIT,
  1934. "%s: reset_restrict_support = %d\n", prefix,
  1935. caps->reset_restrict_support);
  1936. break;
  1937. case ICE_AQC_CAPS_FW_LAG_SUPPORT:
  1938. caps->roce_lag = !!(number & ICE_AQC_BIT_ROCEV2_LAG);
  1939. ice_debug(hw, ICE_DBG_INIT, "%s: roce_lag = %u\n",
  1940. prefix, caps->roce_lag);
  1941. caps->sriov_lag = !!(number & ICE_AQC_BIT_SRIOV_LAG);
  1942. ice_debug(hw, ICE_DBG_INIT, "%s: sriov_lag = %u\n",
  1943. prefix, caps->sriov_lag);
  1944. break;
  1945. case ICE_AQC_CAPS_TX_SCHED_TOPO_COMP_MODE:
  1946. caps->tx_sched_topo_comp_mode_en = (number == 1);
  1947. break;
  1948. default:
  1949. /* Not one of the recognized common capabilities */
  1950. found = false;
  1951. }
  1952. return found;
  1953. }
  1954. /**
  1955. * ice_recalc_port_limited_caps - Recalculate port limited capabilities
  1956. * @hw: pointer to the HW structure
  1957. * @caps: pointer to capabilities structure to fix
  1958. *
  1959. * Re-calculate the capabilities that are dependent on the number of physical
  1960. * ports; i.e. some features are not supported or function differently on
  1961. * devices with more than 4 ports.
  1962. */
  1963. static void
  1964. ice_recalc_port_limited_caps(struct ice_hw *hw, struct ice_hw_common_caps *caps)
  1965. {
  1966. /* This assumes device capabilities are always scanned before function
  1967. * capabilities during the initialization flow.
  1968. */
  1969. if (hw->dev_caps.num_funcs > 4) {
  1970. /* Max 4 TCs per port */
  1971. caps->maxtc = 4;
  1972. ice_debug(hw, ICE_DBG_INIT, "reducing maxtc to %d (based on #ports)\n",
  1973. caps->maxtc);
  1974. if (caps->rdma) {
  1975. ice_debug(hw, ICE_DBG_INIT, "forcing RDMA off\n");
  1976. caps->rdma = 0;
  1977. }
  1978. /* print message only when processing device capabilities
  1979. * during initialization.
  1980. */
  1981. if (caps == &hw->dev_caps.common_cap)
  1982. dev_info(ice_hw_to_dev(hw), "RDMA functionality is not available with the current device configuration.\n");
  1983. }
  1984. }
  1985. /**
  1986. * ice_parse_vf_func_caps - Parse ICE_AQC_CAPS_VF function caps
  1987. * @hw: pointer to the HW struct
  1988. * @func_p: pointer to function capabilities structure
  1989. * @cap: pointer to the capability element to parse
  1990. *
  1991. * Extract function capabilities for ICE_AQC_CAPS_VF.
  1992. */
  1993. static void
  1994. ice_parse_vf_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
  1995. struct ice_aqc_list_caps_elem *cap)
  1996. {
  1997. u32 logical_id = le32_to_cpu(cap->logical_id);
  1998. u32 number = le32_to_cpu(cap->number);
  1999. func_p->num_allocd_vfs = number;
  2000. func_p->vf_base_id = logical_id;
  2001. ice_debug(hw, ICE_DBG_INIT, "func caps: num_allocd_vfs = %d\n",
  2002. func_p->num_allocd_vfs);
  2003. ice_debug(hw, ICE_DBG_INIT, "func caps: vf_base_id = %d\n",
  2004. func_p->vf_base_id);
  2005. }
  2006. /**
  2007. * ice_parse_vsi_func_caps - Parse ICE_AQC_CAPS_VSI function caps
  2008. * @hw: pointer to the HW struct
  2009. * @func_p: pointer to function capabilities structure
  2010. * @cap: pointer to the capability element to parse
  2011. *
  2012. * Extract function capabilities for ICE_AQC_CAPS_VSI.
  2013. */
  2014. static void
  2015. ice_parse_vsi_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
  2016. struct ice_aqc_list_caps_elem *cap)
  2017. {
  2018. func_p->guar_num_vsi = ice_get_num_per_func(hw, ICE_MAX_VSI);
  2019. ice_debug(hw, ICE_DBG_INIT, "func caps: guar_num_vsi (fw) = %d\n",
  2020. le32_to_cpu(cap->number));
  2021. ice_debug(hw, ICE_DBG_INIT, "func caps: guar_num_vsi = %d\n",
  2022. func_p->guar_num_vsi);
  2023. }
  2024. /**
  2025. * ice_parse_1588_func_caps - Parse ICE_AQC_CAPS_1588 function caps
  2026. * @hw: pointer to the HW struct
  2027. * @func_p: pointer to function capabilities structure
  2028. * @cap: pointer to the capability element to parse
  2029. *
  2030. * Extract function capabilities for ICE_AQC_CAPS_1588.
  2031. */
  2032. static void
  2033. ice_parse_1588_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
  2034. struct ice_aqc_list_caps_elem *cap)
  2035. {
  2036. struct ice_ts_func_info *info = &func_p->ts_func_info;
  2037. u32 number = le32_to_cpu(cap->number);
  2038. info->ena = ((number & ICE_TS_FUNC_ENA_M) != 0);
  2039. func_p->common_cap.ieee_1588 = info->ena;
  2040. info->src_tmr_owned = ((number & ICE_TS_SRC_TMR_OWND_M) != 0);
  2041. info->tmr_ena = ((number & ICE_TS_TMR_ENA_M) != 0);
  2042. info->tmr_index_owned = ((number & ICE_TS_TMR_IDX_OWND_M) != 0);
  2043. info->tmr_index_assoc = ((number & ICE_TS_TMR_IDX_ASSOC_M) != 0);
  2044. if (!ice_is_e825c(hw)) {
  2045. info->clk_freq = FIELD_GET(ICE_TS_CLK_FREQ_M, number);
  2046. info->clk_src = ((number & ICE_TS_CLK_SRC_M) != 0);
  2047. } else {
  2048. info->clk_freq = ICE_TIME_REF_FREQ_156_250;
  2049. info->clk_src = ICE_CLK_SRC_TCXO;
  2050. }
  2051. if (info->clk_freq < NUM_ICE_TIME_REF_FREQ) {
  2052. info->time_ref = (enum ice_time_ref_freq)info->clk_freq;
  2053. } else {
  2054. /* Unknown clock frequency, so assume a (probably incorrect)
  2055. * default to avoid out-of-bounds look ups of frequency
  2056. * related information.
  2057. */
  2058. ice_debug(hw, ICE_DBG_INIT, "1588 func caps: unknown clock frequency %u\n",
  2059. info->clk_freq);
  2060. info->time_ref = ICE_TIME_REF_FREQ_25_000;
  2061. }
  2062. ice_debug(hw, ICE_DBG_INIT, "func caps: ieee_1588 = %u\n",
  2063. func_p->common_cap.ieee_1588);
  2064. ice_debug(hw, ICE_DBG_INIT, "func caps: src_tmr_owned = %u\n",
  2065. info->src_tmr_owned);
  2066. ice_debug(hw, ICE_DBG_INIT, "func caps: tmr_ena = %u\n",
  2067. info->tmr_ena);
  2068. ice_debug(hw, ICE_DBG_INIT, "func caps: tmr_index_owned = %u\n",
  2069. info->tmr_index_owned);
  2070. ice_debug(hw, ICE_DBG_INIT, "func caps: tmr_index_assoc = %u\n",
  2071. info->tmr_index_assoc);
  2072. ice_debug(hw, ICE_DBG_INIT, "func caps: clk_freq = %u\n",
  2073. info->clk_freq);
  2074. ice_debug(hw, ICE_DBG_INIT, "func caps: clk_src = %u\n",
  2075. info->clk_src);
  2076. }
  2077. /**
  2078. * ice_parse_fdir_func_caps - Parse ICE_AQC_CAPS_FD function caps
  2079. * @hw: pointer to the HW struct
  2080. * @func_p: pointer to function capabilities structure
  2081. *
  2082. * Extract function capabilities for ICE_AQC_CAPS_FD.
  2083. */
  2084. static void
  2085. ice_parse_fdir_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p)
  2086. {
  2087. u32 reg_val, gsize, bsize;
  2088. reg_val = rd32(hw, GLQF_FD_SIZE);
  2089. switch (hw->mac_type) {
  2090. case ICE_MAC_E830:
  2091. gsize = FIELD_GET(E830_GLQF_FD_SIZE_FD_GSIZE_M, reg_val);
  2092. bsize = FIELD_GET(E830_GLQF_FD_SIZE_FD_BSIZE_M, reg_val);
  2093. break;
  2094. case ICE_MAC_E810:
  2095. default:
  2096. gsize = FIELD_GET(E800_GLQF_FD_SIZE_FD_GSIZE_M, reg_val);
  2097. bsize = FIELD_GET(E800_GLQF_FD_SIZE_FD_BSIZE_M, reg_val);
  2098. }
  2099. func_p->fd_fltr_guar = ice_get_num_per_func(hw, gsize);
  2100. func_p->fd_fltr_best_effort = bsize;
  2101. ice_debug(hw, ICE_DBG_INIT, "func caps: fd_fltr_guar = %d\n",
  2102. func_p->fd_fltr_guar);
  2103. ice_debug(hw, ICE_DBG_INIT, "func caps: fd_fltr_best_effort = %d\n",
  2104. func_p->fd_fltr_best_effort);
  2105. }
  2106. /**
  2107. * ice_parse_func_caps - Parse function capabilities
  2108. * @hw: pointer to the HW struct
  2109. * @func_p: pointer to function capabilities structure
  2110. * @buf: buffer containing the function capability records
  2111. * @cap_count: the number of capabilities
  2112. *
  2113. * Helper function to parse function (0x000A) capabilities list. For
  2114. * capabilities shared between device and function, this relies on
  2115. * ice_parse_common_caps.
  2116. *
  2117. * Loop through the list of provided capabilities and extract the relevant
  2118. * data into the function capabilities structured.
  2119. */
  2120. static void
  2121. ice_parse_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
  2122. void *buf, u32 cap_count)
  2123. {
  2124. struct ice_aqc_list_caps_elem *cap_resp;
  2125. u32 i;
  2126. cap_resp = buf;
  2127. memset(func_p, 0, sizeof(*func_p));
  2128. for (i = 0; i < cap_count; i++) {
  2129. u16 cap = le16_to_cpu(cap_resp[i].cap);
  2130. bool found;
  2131. found = ice_parse_common_caps(hw, &func_p->common_cap,
  2132. &cap_resp[i], "func caps");
  2133. switch (cap) {
  2134. case ICE_AQC_CAPS_VF:
  2135. ice_parse_vf_func_caps(hw, func_p, &cap_resp[i]);
  2136. break;
  2137. case ICE_AQC_CAPS_VSI:
  2138. ice_parse_vsi_func_caps(hw, func_p, &cap_resp[i]);
  2139. break;
  2140. case ICE_AQC_CAPS_1588:
  2141. ice_parse_1588_func_caps(hw, func_p, &cap_resp[i]);
  2142. break;
  2143. case ICE_AQC_CAPS_FD:
  2144. ice_parse_fdir_func_caps(hw, func_p);
  2145. break;
  2146. default:
  2147. /* Don't list common capabilities as unknown */
  2148. if (!found)
  2149. ice_debug(hw, ICE_DBG_INIT, "func caps: unknown capability[%d]: 0x%x\n",
  2150. i, cap);
  2151. break;
  2152. }
  2153. }
  2154. ice_recalc_port_limited_caps(hw, &func_p->common_cap);
  2155. }
  2156. /**
  2157. * ice_parse_valid_functions_cap - Parse ICE_AQC_CAPS_VALID_FUNCTIONS caps
  2158. * @hw: pointer to the HW struct
  2159. * @dev_p: pointer to device capabilities structure
  2160. * @cap: capability element to parse
  2161. *
  2162. * Parse ICE_AQC_CAPS_VALID_FUNCTIONS for device capabilities.
  2163. */
  2164. static void
  2165. ice_parse_valid_functions_cap(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
  2166. struct ice_aqc_list_caps_elem *cap)
  2167. {
  2168. u32 number = le32_to_cpu(cap->number);
  2169. dev_p->num_funcs = hweight32(number);
  2170. ice_debug(hw, ICE_DBG_INIT, "dev caps: num_funcs = %d\n",
  2171. dev_p->num_funcs);
  2172. }
  2173. /**
  2174. * ice_parse_vf_dev_caps - Parse ICE_AQC_CAPS_VF device caps
  2175. * @hw: pointer to the HW struct
  2176. * @dev_p: pointer to device capabilities structure
  2177. * @cap: capability element to parse
  2178. *
  2179. * Parse ICE_AQC_CAPS_VF for device capabilities.
  2180. */
  2181. static void
  2182. ice_parse_vf_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
  2183. struct ice_aqc_list_caps_elem *cap)
  2184. {
  2185. u32 number = le32_to_cpu(cap->number);
  2186. dev_p->num_vfs_exposed = number;
  2187. ice_debug(hw, ICE_DBG_INIT, "dev_caps: num_vfs_exposed = %d\n",
  2188. dev_p->num_vfs_exposed);
  2189. }
  2190. /**
  2191. * ice_parse_vsi_dev_caps - Parse ICE_AQC_CAPS_VSI device caps
  2192. * @hw: pointer to the HW struct
  2193. * @dev_p: pointer to device capabilities structure
  2194. * @cap: capability element to parse
  2195. *
  2196. * Parse ICE_AQC_CAPS_VSI for device capabilities.
  2197. */
  2198. static void
  2199. ice_parse_vsi_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
  2200. struct ice_aqc_list_caps_elem *cap)
  2201. {
  2202. u32 number = le32_to_cpu(cap->number);
  2203. dev_p->num_vsi_allocd_to_host = number;
  2204. ice_debug(hw, ICE_DBG_INIT, "dev caps: num_vsi_allocd_to_host = %d\n",
  2205. dev_p->num_vsi_allocd_to_host);
  2206. }
  2207. /**
  2208. * ice_parse_1588_dev_caps - Parse ICE_AQC_CAPS_1588 device caps
  2209. * @hw: pointer to the HW struct
  2210. * @dev_p: pointer to device capabilities structure
  2211. * @cap: capability element to parse
  2212. *
  2213. * Parse ICE_AQC_CAPS_1588 for device capabilities.
  2214. */
  2215. static void
  2216. ice_parse_1588_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
  2217. struct ice_aqc_list_caps_elem *cap)
  2218. {
  2219. struct ice_ts_dev_info *info = &dev_p->ts_dev_info;
  2220. u32 logical_id = le32_to_cpu(cap->logical_id);
  2221. u32 phys_id = le32_to_cpu(cap->phys_id);
  2222. u32 number = le32_to_cpu(cap->number);
  2223. info->ena = ((number & ICE_TS_DEV_ENA_M) != 0);
  2224. dev_p->common_cap.ieee_1588 = info->ena;
  2225. info->tmr0_owner = number & ICE_TS_TMR0_OWNR_M;
  2226. info->tmr0_owned = ((number & ICE_TS_TMR0_OWND_M) != 0);
  2227. info->tmr0_ena = ((number & ICE_TS_TMR0_ENA_M) != 0);
  2228. info->tmr1_owner = FIELD_GET(ICE_TS_TMR1_OWNR_M, number);
  2229. info->tmr1_owned = ((number & ICE_TS_TMR1_OWND_M) != 0);
  2230. info->tmr1_ena = ((number & ICE_TS_TMR1_ENA_M) != 0);
  2231. info->ts_ll_read = ((number & ICE_TS_LL_TX_TS_READ_M) != 0);
  2232. info->ts_ll_int_read = ((number & ICE_TS_LL_TX_TS_INT_READ_M) != 0);
  2233. info->ena_ports = logical_id;
  2234. info->tmr_own_map = phys_id;
  2235. ice_debug(hw, ICE_DBG_INIT, "dev caps: ieee_1588 = %u\n",
  2236. dev_p->common_cap.ieee_1588);
  2237. ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr0_owner = %u\n",
  2238. info->tmr0_owner);
  2239. ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr0_owned = %u\n",
  2240. info->tmr0_owned);
  2241. ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr0_ena = %u\n",
  2242. info->tmr0_ena);
  2243. ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr1_owner = %u\n",
  2244. info->tmr1_owner);
  2245. ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr1_owned = %u\n",
  2246. info->tmr1_owned);
  2247. ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr1_ena = %u\n",
  2248. info->tmr1_ena);
  2249. ice_debug(hw, ICE_DBG_INIT, "dev caps: ts_ll_read = %u\n",
  2250. info->ts_ll_read);
  2251. ice_debug(hw, ICE_DBG_INIT, "dev caps: ts_ll_int_read = %u\n",
  2252. info->ts_ll_int_read);
  2253. ice_debug(hw, ICE_DBG_INIT, "dev caps: ieee_1588 ena_ports = %u\n",
  2254. info->ena_ports);
  2255. ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr_own_map = %u\n",
  2256. info->tmr_own_map);
  2257. }
  2258. /**
  2259. * ice_parse_fdir_dev_caps - Parse ICE_AQC_CAPS_FD device caps
  2260. * @hw: pointer to the HW struct
  2261. * @dev_p: pointer to device capabilities structure
  2262. * @cap: capability element to parse
  2263. *
  2264. * Parse ICE_AQC_CAPS_FD for device capabilities.
  2265. */
  2266. static void
  2267. ice_parse_fdir_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
  2268. struct ice_aqc_list_caps_elem *cap)
  2269. {
  2270. u32 number = le32_to_cpu(cap->number);
  2271. dev_p->num_flow_director_fltr = number;
  2272. ice_debug(hw, ICE_DBG_INIT, "dev caps: num_flow_director_fltr = %d\n",
  2273. dev_p->num_flow_director_fltr);
  2274. }
  2275. /**
  2276. * ice_parse_sensor_reading_cap - Parse ICE_AQC_CAPS_SENSOR_READING cap
  2277. * @hw: pointer to the HW struct
  2278. * @dev_p: pointer to device capabilities structure
  2279. * @cap: capability element to parse
  2280. *
  2281. * Parse ICE_AQC_CAPS_SENSOR_READING for device capability for reading
  2282. * enabled sensors.
  2283. */
  2284. static void
  2285. ice_parse_sensor_reading_cap(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
  2286. struct ice_aqc_list_caps_elem *cap)
  2287. {
  2288. dev_p->supported_sensors = le32_to_cpu(cap->number);
  2289. ice_debug(hw, ICE_DBG_INIT,
  2290. "dev caps: supported sensors (bitmap) = 0x%x\n",
  2291. dev_p->supported_sensors);
  2292. }
  2293. /**
  2294. * ice_parse_nac_topo_dev_caps - Parse ICE_AQC_CAPS_NAC_TOPOLOGY cap
  2295. * @hw: pointer to the HW struct
  2296. * @dev_p: pointer to device capabilities structure
  2297. * @cap: capability element to parse
  2298. *
  2299. * Parse ICE_AQC_CAPS_NAC_TOPOLOGY for device capabilities.
  2300. */
  2301. static void ice_parse_nac_topo_dev_caps(struct ice_hw *hw,
  2302. struct ice_hw_dev_caps *dev_p,
  2303. struct ice_aqc_list_caps_elem *cap)
  2304. {
  2305. dev_p->nac_topo.mode = le32_to_cpu(cap->number);
  2306. dev_p->nac_topo.id = le32_to_cpu(cap->phys_id) & ICE_NAC_TOPO_ID_M;
  2307. dev_info(ice_hw_to_dev(hw),
  2308. "PF is configured in %s mode with IP instance ID %d\n",
  2309. (dev_p->nac_topo.mode & ICE_NAC_TOPO_PRIMARY_M) ?
  2310. "primary" : "secondary", dev_p->nac_topo.id);
  2311. ice_debug(hw, ICE_DBG_INIT, "dev caps: nac topology is_primary = %d\n",
  2312. !!(dev_p->nac_topo.mode & ICE_NAC_TOPO_PRIMARY_M));
  2313. ice_debug(hw, ICE_DBG_INIT, "dev caps: nac topology is_dual = %d\n",
  2314. !!(dev_p->nac_topo.mode & ICE_NAC_TOPO_DUAL_M));
  2315. ice_debug(hw, ICE_DBG_INIT, "dev caps: nac topology id = %d\n",
  2316. dev_p->nac_topo.id);
  2317. }
  2318. /**
  2319. * ice_parse_dev_caps - Parse device capabilities
  2320. * @hw: pointer to the HW struct
  2321. * @dev_p: pointer to device capabilities structure
  2322. * @buf: buffer containing the device capability records
  2323. * @cap_count: the number of capabilities
  2324. *
  2325. * Helper device to parse device (0x000B) capabilities list. For
  2326. * capabilities shared between device and function, this relies on
  2327. * ice_parse_common_caps.
  2328. *
  2329. * Loop through the list of provided capabilities and extract the relevant
  2330. * data into the device capabilities structured.
  2331. */
  2332. static void
  2333. ice_parse_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
  2334. void *buf, u32 cap_count)
  2335. {
  2336. struct ice_aqc_list_caps_elem *cap_resp;
  2337. u32 i;
  2338. cap_resp = buf;
  2339. memset(dev_p, 0, sizeof(*dev_p));
  2340. for (i = 0; i < cap_count; i++) {
  2341. u16 cap = le16_to_cpu(cap_resp[i].cap);
  2342. bool found;
  2343. found = ice_parse_common_caps(hw, &dev_p->common_cap,
  2344. &cap_resp[i], "dev caps");
  2345. switch (cap) {
  2346. case ICE_AQC_CAPS_VALID_FUNCTIONS:
  2347. ice_parse_valid_functions_cap(hw, dev_p, &cap_resp[i]);
  2348. break;
  2349. case ICE_AQC_CAPS_VF:
  2350. ice_parse_vf_dev_caps(hw, dev_p, &cap_resp[i]);
  2351. break;
  2352. case ICE_AQC_CAPS_VSI:
  2353. ice_parse_vsi_dev_caps(hw, dev_p, &cap_resp[i]);
  2354. break;
  2355. case ICE_AQC_CAPS_1588:
  2356. ice_parse_1588_dev_caps(hw, dev_p, &cap_resp[i]);
  2357. break;
  2358. case ICE_AQC_CAPS_FD:
  2359. ice_parse_fdir_dev_caps(hw, dev_p, &cap_resp[i]);
  2360. break;
  2361. case ICE_AQC_CAPS_SENSOR_READING:
  2362. ice_parse_sensor_reading_cap(hw, dev_p, &cap_resp[i]);
  2363. break;
  2364. case ICE_AQC_CAPS_NAC_TOPOLOGY:
  2365. ice_parse_nac_topo_dev_caps(hw, dev_p, &cap_resp[i]);
  2366. break;
  2367. default:
  2368. /* Don't list common capabilities as unknown */
  2369. if (!found)
  2370. ice_debug(hw, ICE_DBG_INIT, "dev caps: unknown capability[%d]: 0x%x\n",
  2371. i, cap);
  2372. break;
  2373. }
  2374. }
  2375. ice_recalc_port_limited_caps(hw, &dev_p->common_cap);
  2376. }
  2377. /**
  2378. * ice_is_pf_c827 - check if pf contains c827 phy
  2379. * @hw: pointer to the hw struct
  2380. */
  2381. bool ice_is_pf_c827(struct ice_hw *hw)
  2382. {
  2383. struct ice_aqc_get_link_topo cmd = {};
  2384. u8 node_part_number;
  2385. u16 node_handle;
  2386. int status;
  2387. if (hw->mac_type != ICE_MAC_E810)
  2388. return false;
  2389. if (hw->device_id != ICE_DEV_ID_E810C_QSFP)
  2390. return true;
  2391. cmd.addr.topo_params.node_type_ctx =
  2392. FIELD_PREP(ICE_AQC_LINK_TOPO_NODE_TYPE_M, ICE_AQC_LINK_TOPO_NODE_TYPE_PHY) |
  2393. FIELD_PREP(ICE_AQC_LINK_TOPO_NODE_CTX_M, ICE_AQC_LINK_TOPO_NODE_CTX_PORT);
  2394. cmd.addr.topo_params.index = 0;
  2395. status = ice_aq_get_netlist_node(hw, &cmd, &node_part_number,
  2396. &node_handle);
  2397. if (status || node_part_number != ICE_AQC_GET_LINK_TOPO_NODE_NR_C827)
  2398. return false;
  2399. if (node_handle == E810C_QSFP_C827_0_HANDLE || node_handle == E810C_QSFP_C827_1_HANDLE)
  2400. return true;
  2401. return false;
  2402. }
  2403. /**
  2404. * ice_is_phy_rclk_in_netlist
  2405. * @hw: pointer to the hw struct
  2406. *
  2407. * Check if the PHY Recovered Clock device is present in the netlist
  2408. */
  2409. bool ice_is_phy_rclk_in_netlist(struct ice_hw *hw)
  2410. {
  2411. if (ice_find_netlist_node(hw, ICE_AQC_LINK_TOPO_NODE_TYPE_PHY,
  2412. ICE_AQC_LINK_TOPO_NODE_CTX_PORT,
  2413. ICE_AQC_GET_LINK_TOPO_NODE_NR_C827, NULL) &&
  2414. ice_find_netlist_node(hw, ICE_AQC_LINK_TOPO_NODE_TYPE_PHY,
  2415. ICE_AQC_LINK_TOPO_NODE_CTX_PORT,
  2416. ICE_AQC_GET_LINK_TOPO_NODE_NR_E822_PHY, NULL))
  2417. return false;
  2418. return true;
  2419. }
  2420. /**
  2421. * ice_is_clock_mux_in_netlist
  2422. * @hw: pointer to the hw struct
  2423. *
  2424. * Check if the Clock Multiplexer device is present in the netlist
  2425. */
  2426. bool ice_is_clock_mux_in_netlist(struct ice_hw *hw)
  2427. {
  2428. if (ice_find_netlist_node(hw, ICE_AQC_LINK_TOPO_NODE_TYPE_CLK_MUX,
  2429. ICE_AQC_LINK_TOPO_NODE_CTX_GLOBAL,
  2430. ICE_AQC_GET_LINK_TOPO_NODE_NR_GEN_CLK_MUX,
  2431. NULL))
  2432. return false;
  2433. return true;
  2434. }
  2435. /**
  2436. * ice_is_cgu_in_netlist - check for CGU presence
  2437. * @hw: pointer to the hw struct
  2438. *
  2439. * Check if the Clock Generation Unit (CGU) device is present in the netlist.
  2440. * Save the CGU part number in the hw structure for later use.
  2441. * Return:
  2442. * * true - cgu is present
  2443. * * false - cgu is not present
  2444. */
  2445. bool ice_is_cgu_in_netlist(struct ice_hw *hw)
  2446. {
  2447. if (!ice_find_netlist_node(hw, ICE_AQC_LINK_TOPO_NODE_TYPE_CLK_CTRL,
  2448. ICE_AQC_LINK_TOPO_NODE_CTX_GLOBAL,
  2449. ICE_AQC_GET_LINK_TOPO_NODE_NR_ZL30632_80032,
  2450. NULL)) {
  2451. hw->cgu_part_number = ICE_AQC_GET_LINK_TOPO_NODE_NR_ZL30632_80032;
  2452. return true;
  2453. } else if (!ice_find_netlist_node(hw,
  2454. ICE_AQC_LINK_TOPO_NODE_TYPE_CLK_CTRL,
  2455. ICE_AQC_LINK_TOPO_NODE_CTX_GLOBAL,
  2456. ICE_AQC_GET_LINK_TOPO_NODE_NR_SI5383_5384,
  2457. NULL)) {
  2458. hw->cgu_part_number = ICE_AQC_GET_LINK_TOPO_NODE_NR_SI5383_5384;
  2459. return true;
  2460. }
  2461. return false;
  2462. }
  2463. /**
  2464. * ice_is_gps_in_netlist
  2465. * @hw: pointer to the hw struct
  2466. *
  2467. * Check if the GPS generic device is present in the netlist
  2468. */
  2469. bool ice_is_gps_in_netlist(struct ice_hw *hw)
  2470. {
  2471. if (ice_find_netlist_node(hw, ICE_AQC_LINK_TOPO_NODE_TYPE_GPS,
  2472. ICE_AQC_LINK_TOPO_NODE_CTX_GLOBAL,
  2473. ICE_AQC_GET_LINK_TOPO_NODE_NR_GEN_GPS, NULL))
  2474. return false;
  2475. return true;
  2476. }
  2477. /**
  2478. * ice_aq_list_caps - query function/device capabilities
  2479. * @hw: pointer to the HW struct
  2480. * @buf: a buffer to hold the capabilities
  2481. * @buf_size: size of the buffer
  2482. * @cap_count: if not NULL, set to the number of capabilities reported
  2483. * @opc: capabilities type to discover, device or function
  2484. * @cd: pointer to command details structure or NULL
  2485. *
  2486. * Get the function (0x000A) or device (0x000B) capabilities description from
  2487. * firmware and store it in the buffer.
  2488. *
  2489. * If the cap_count pointer is not NULL, then it is set to the number of
  2490. * capabilities firmware will report. Note that if the buffer size is too
  2491. * small, it is possible the command will return ICE_AQ_ERR_ENOMEM. The
  2492. * cap_count will still be updated in this case. It is recommended that the
  2493. * buffer size be set to ICE_AQ_MAX_BUF_LEN (the largest possible buffer that
  2494. * firmware could return) to avoid this.
  2495. */
  2496. int
  2497. ice_aq_list_caps(struct ice_hw *hw, void *buf, u16 buf_size, u32 *cap_count,
  2498. enum ice_adminq_opc opc, struct ice_sq_cd *cd)
  2499. {
  2500. struct ice_aqc_list_caps *cmd;
  2501. struct ice_aq_desc desc;
  2502. int status;
  2503. cmd = &desc.params.get_cap;
  2504. if (opc != ice_aqc_opc_list_func_caps &&
  2505. opc != ice_aqc_opc_list_dev_caps)
  2506. return -EINVAL;
  2507. ice_fill_dflt_direct_cmd_desc(&desc, opc);
  2508. status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  2509. if (cap_count)
  2510. *cap_count = le32_to_cpu(cmd->count);
  2511. return status;
  2512. }
  2513. /**
  2514. * ice_discover_dev_caps - Read and extract device capabilities
  2515. * @hw: pointer to the hardware structure
  2516. * @dev_caps: pointer to device capabilities structure
  2517. *
  2518. * Read the device capabilities and extract them into the dev_caps structure
  2519. * for later use.
  2520. */
  2521. int
  2522. ice_discover_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_caps)
  2523. {
  2524. u32 cap_count = 0;
  2525. void *cbuf;
  2526. int status;
  2527. cbuf = kzalloc(ICE_AQ_MAX_BUF_LEN, GFP_KERNEL);
  2528. if (!cbuf)
  2529. return -ENOMEM;
  2530. /* Although the driver doesn't know the number of capabilities the
  2531. * device will return, we can simply send a 4KB buffer, the maximum
  2532. * possible size that firmware can return.
  2533. */
  2534. cap_count = ICE_AQ_MAX_BUF_LEN / sizeof(struct ice_aqc_list_caps_elem);
  2535. status = ice_aq_list_caps(hw, cbuf, ICE_AQ_MAX_BUF_LEN, &cap_count,
  2536. ice_aqc_opc_list_dev_caps, NULL);
  2537. if (!status)
  2538. ice_parse_dev_caps(hw, dev_caps, cbuf, cap_count);
  2539. kfree(cbuf);
  2540. return status;
  2541. }
  2542. /**
  2543. * ice_discover_func_caps - Read and extract function capabilities
  2544. * @hw: pointer to the hardware structure
  2545. * @func_caps: pointer to function capabilities structure
  2546. *
  2547. * Read the function capabilities and extract them into the func_caps structure
  2548. * for later use.
  2549. */
  2550. static int
  2551. ice_discover_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_caps)
  2552. {
  2553. u32 cap_count = 0;
  2554. void *cbuf;
  2555. int status;
  2556. cbuf = kzalloc(ICE_AQ_MAX_BUF_LEN, GFP_KERNEL);
  2557. if (!cbuf)
  2558. return -ENOMEM;
  2559. /* Although the driver doesn't know the number of capabilities the
  2560. * device will return, we can simply send a 4KB buffer, the maximum
  2561. * possible size that firmware can return.
  2562. */
  2563. cap_count = ICE_AQ_MAX_BUF_LEN / sizeof(struct ice_aqc_list_caps_elem);
  2564. status = ice_aq_list_caps(hw, cbuf, ICE_AQ_MAX_BUF_LEN, &cap_count,
  2565. ice_aqc_opc_list_func_caps, NULL);
  2566. if (!status)
  2567. ice_parse_func_caps(hw, func_caps, cbuf, cap_count);
  2568. kfree(cbuf);
  2569. return status;
  2570. }
  2571. /**
  2572. * ice_set_safe_mode_caps - Override dev/func capabilities when in safe mode
  2573. * @hw: pointer to the hardware structure
  2574. */
  2575. void ice_set_safe_mode_caps(struct ice_hw *hw)
  2576. {
  2577. struct ice_hw_func_caps *func_caps = &hw->func_caps;
  2578. struct ice_hw_dev_caps *dev_caps = &hw->dev_caps;
  2579. struct ice_hw_common_caps cached_caps;
  2580. u32 num_funcs;
  2581. /* cache some func_caps values that should be restored after memset */
  2582. cached_caps = func_caps->common_cap;
  2583. /* unset func capabilities */
  2584. memset(func_caps, 0, sizeof(*func_caps));
  2585. #define ICE_RESTORE_FUNC_CAP(name) \
  2586. func_caps->common_cap.name = cached_caps.name
  2587. /* restore cached values */
  2588. ICE_RESTORE_FUNC_CAP(valid_functions);
  2589. ICE_RESTORE_FUNC_CAP(txq_first_id);
  2590. ICE_RESTORE_FUNC_CAP(rxq_first_id);
  2591. ICE_RESTORE_FUNC_CAP(msix_vector_first_id);
  2592. ICE_RESTORE_FUNC_CAP(max_mtu);
  2593. ICE_RESTORE_FUNC_CAP(nvm_unified_update);
  2594. ICE_RESTORE_FUNC_CAP(nvm_update_pending_nvm);
  2595. ICE_RESTORE_FUNC_CAP(nvm_update_pending_orom);
  2596. ICE_RESTORE_FUNC_CAP(nvm_update_pending_netlist);
  2597. /* one Tx and one Rx queue in safe mode */
  2598. func_caps->common_cap.num_rxq = 1;
  2599. func_caps->common_cap.num_txq = 1;
  2600. /* two MSIX vectors, one for traffic and one for misc causes */
  2601. func_caps->common_cap.num_msix_vectors = 2;
  2602. func_caps->guar_num_vsi = 1;
  2603. /* cache some dev_caps values that should be restored after memset */
  2604. cached_caps = dev_caps->common_cap;
  2605. num_funcs = dev_caps->num_funcs;
  2606. /* unset dev capabilities */
  2607. memset(dev_caps, 0, sizeof(*dev_caps));
  2608. #define ICE_RESTORE_DEV_CAP(name) \
  2609. dev_caps->common_cap.name = cached_caps.name
  2610. /* restore cached values */
  2611. ICE_RESTORE_DEV_CAP(valid_functions);
  2612. ICE_RESTORE_DEV_CAP(txq_first_id);
  2613. ICE_RESTORE_DEV_CAP(rxq_first_id);
  2614. ICE_RESTORE_DEV_CAP(msix_vector_first_id);
  2615. ICE_RESTORE_DEV_CAP(max_mtu);
  2616. ICE_RESTORE_DEV_CAP(nvm_unified_update);
  2617. ICE_RESTORE_DEV_CAP(nvm_update_pending_nvm);
  2618. ICE_RESTORE_DEV_CAP(nvm_update_pending_orom);
  2619. ICE_RESTORE_DEV_CAP(nvm_update_pending_netlist);
  2620. dev_caps->num_funcs = num_funcs;
  2621. /* one Tx and one Rx queue per function in safe mode */
  2622. dev_caps->common_cap.num_rxq = num_funcs;
  2623. dev_caps->common_cap.num_txq = num_funcs;
  2624. /* two MSIX vectors per function */
  2625. dev_caps->common_cap.num_msix_vectors = 2 * num_funcs;
  2626. }
  2627. /**
  2628. * ice_get_caps - get info about the HW
  2629. * @hw: pointer to the hardware structure
  2630. */
  2631. int ice_get_caps(struct ice_hw *hw)
  2632. {
  2633. int status;
  2634. status = ice_discover_dev_caps(hw, &hw->dev_caps);
  2635. if (status)
  2636. return status;
  2637. return ice_discover_func_caps(hw, &hw->func_caps);
  2638. }
  2639. /**
  2640. * ice_aq_manage_mac_write - manage MAC address write command
  2641. * @hw: pointer to the HW struct
  2642. * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
  2643. * @flags: flags to control write behavior
  2644. * @cd: pointer to command details structure or NULL
  2645. *
  2646. * This function is used to write MAC address to the NVM (0x0108).
  2647. */
  2648. int
  2649. ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags,
  2650. struct ice_sq_cd *cd)
  2651. {
  2652. struct ice_aqc_manage_mac_write *cmd;
  2653. struct ice_aq_desc desc;
  2654. cmd = &desc.params.mac_write;
  2655. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
  2656. cmd->flags = flags;
  2657. ether_addr_copy(cmd->mac_addr, mac_addr);
  2658. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  2659. }
  2660. /**
  2661. * ice_aq_clear_pxe_mode
  2662. * @hw: pointer to the HW struct
  2663. *
  2664. * Tell the firmware that the driver is taking over from PXE (0x0110).
  2665. */
  2666. static int ice_aq_clear_pxe_mode(struct ice_hw *hw)
  2667. {
  2668. struct ice_aq_desc desc;
  2669. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode);
  2670. desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT;
  2671. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  2672. }
  2673. /**
  2674. * ice_clear_pxe_mode - clear pxe operations mode
  2675. * @hw: pointer to the HW struct
  2676. *
  2677. * Make sure all PXE mode settings are cleared, including things
  2678. * like descriptor fetch/write-back mode.
  2679. */
  2680. void ice_clear_pxe_mode(struct ice_hw *hw)
  2681. {
  2682. if (ice_check_sq_alive(hw, &hw->adminq))
  2683. ice_aq_clear_pxe_mode(hw);
  2684. }
  2685. /**
  2686. * ice_aq_set_port_params - set physical port parameters.
  2687. * @pi: pointer to the port info struct
  2688. * @double_vlan: if set double VLAN is enabled
  2689. * @cd: pointer to command details structure or NULL
  2690. *
  2691. * Set Physical port parameters (0x0203)
  2692. */
  2693. int
  2694. ice_aq_set_port_params(struct ice_port_info *pi, bool double_vlan,
  2695. struct ice_sq_cd *cd)
  2696. {
  2697. struct ice_aqc_set_port_params *cmd;
  2698. struct ice_hw *hw = pi->hw;
  2699. struct ice_aq_desc desc;
  2700. u16 cmd_flags = 0;
  2701. cmd = &desc.params.set_port_params;
  2702. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_params);
  2703. if (double_vlan)
  2704. cmd_flags |= ICE_AQC_SET_P_PARAMS_DOUBLE_VLAN_ENA;
  2705. cmd->cmd_flags = cpu_to_le16(cmd_flags);
  2706. cmd->local_fwd_mode = pi->local_fwd_mode |
  2707. ICE_AQC_SET_P_PARAMS_LOCAL_FWD_MODE_VALID;
  2708. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  2709. }
  2710. /**
  2711. * ice_is_100m_speed_supported
  2712. * @hw: pointer to the HW struct
  2713. *
  2714. * returns true if 100M speeds are supported by the device,
  2715. * false otherwise.
  2716. */
  2717. bool ice_is_100m_speed_supported(struct ice_hw *hw)
  2718. {
  2719. switch (hw->device_id) {
  2720. case ICE_DEV_ID_E822C_SGMII:
  2721. case ICE_DEV_ID_E822L_SGMII:
  2722. case ICE_DEV_ID_E823L_1GBE:
  2723. case ICE_DEV_ID_E823C_SGMII:
  2724. return true;
  2725. default:
  2726. return false;
  2727. }
  2728. }
  2729. /**
  2730. * ice_get_link_speed_based_on_phy_type - returns link speed
  2731. * @phy_type_low: lower part of phy_type
  2732. * @phy_type_high: higher part of phy_type
  2733. *
  2734. * This helper function will convert an entry in PHY type structure
  2735. * [phy_type_low, phy_type_high] to its corresponding link speed.
  2736. * Note: In the structure of [phy_type_low, phy_type_high], there should
  2737. * be one bit set, as this function will convert one PHY type to its
  2738. * speed.
  2739. *
  2740. * Return:
  2741. * * PHY speed for recognized PHY type
  2742. * * If no bit gets set, ICE_AQ_LINK_SPEED_UNKNOWN will be returned
  2743. * * If more than one bit gets set, ICE_AQ_LINK_SPEED_UNKNOWN will be returned
  2744. */
  2745. u16 ice_get_link_speed_based_on_phy_type(u64 phy_type_low, u64 phy_type_high)
  2746. {
  2747. u16 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
  2748. u16 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
  2749. switch (phy_type_low) {
  2750. case ICE_PHY_TYPE_LOW_100BASE_TX:
  2751. case ICE_PHY_TYPE_LOW_100M_SGMII:
  2752. speed_phy_type_low = ICE_AQ_LINK_SPEED_100MB;
  2753. break;
  2754. case ICE_PHY_TYPE_LOW_1000BASE_T:
  2755. case ICE_PHY_TYPE_LOW_1000BASE_SX:
  2756. case ICE_PHY_TYPE_LOW_1000BASE_LX:
  2757. case ICE_PHY_TYPE_LOW_1000BASE_KX:
  2758. case ICE_PHY_TYPE_LOW_1G_SGMII:
  2759. speed_phy_type_low = ICE_AQ_LINK_SPEED_1000MB;
  2760. break;
  2761. case ICE_PHY_TYPE_LOW_2500BASE_T:
  2762. case ICE_PHY_TYPE_LOW_2500BASE_X:
  2763. case ICE_PHY_TYPE_LOW_2500BASE_KX:
  2764. speed_phy_type_low = ICE_AQ_LINK_SPEED_2500MB;
  2765. break;
  2766. case ICE_PHY_TYPE_LOW_5GBASE_T:
  2767. case ICE_PHY_TYPE_LOW_5GBASE_KR:
  2768. speed_phy_type_low = ICE_AQ_LINK_SPEED_5GB;
  2769. break;
  2770. case ICE_PHY_TYPE_LOW_10GBASE_T:
  2771. case ICE_PHY_TYPE_LOW_10G_SFI_DA:
  2772. case ICE_PHY_TYPE_LOW_10GBASE_SR:
  2773. case ICE_PHY_TYPE_LOW_10GBASE_LR:
  2774. case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
  2775. case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
  2776. case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
  2777. speed_phy_type_low = ICE_AQ_LINK_SPEED_10GB;
  2778. break;
  2779. case ICE_PHY_TYPE_LOW_25GBASE_T:
  2780. case ICE_PHY_TYPE_LOW_25GBASE_CR:
  2781. case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
  2782. case ICE_PHY_TYPE_LOW_25GBASE_CR1:
  2783. case ICE_PHY_TYPE_LOW_25GBASE_SR:
  2784. case ICE_PHY_TYPE_LOW_25GBASE_LR:
  2785. case ICE_PHY_TYPE_LOW_25GBASE_KR:
  2786. case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
  2787. case ICE_PHY_TYPE_LOW_25GBASE_KR1:
  2788. case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
  2789. case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
  2790. speed_phy_type_low = ICE_AQ_LINK_SPEED_25GB;
  2791. break;
  2792. case ICE_PHY_TYPE_LOW_40GBASE_CR4:
  2793. case ICE_PHY_TYPE_LOW_40GBASE_SR4:
  2794. case ICE_PHY_TYPE_LOW_40GBASE_LR4:
  2795. case ICE_PHY_TYPE_LOW_40GBASE_KR4:
  2796. case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
  2797. case ICE_PHY_TYPE_LOW_40G_XLAUI:
  2798. speed_phy_type_low = ICE_AQ_LINK_SPEED_40GB;
  2799. break;
  2800. case ICE_PHY_TYPE_LOW_50GBASE_CR2:
  2801. case ICE_PHY_TYPE_LOW_50GBASE_SR2:
  2802. case ICE_PHY_TYPE_LOW_50GBASE_LR2:
  2803. case ICE_PHY_TYPE_LOW_50GBASE_KR2:
  2804. case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
  2805. case ICE_PHY_TYPE_LOW_50G_LAUI2:
  2806. case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
  2807. case ICE_PHY_TYPE_LOW_50G_AUI2:
  2808. case ICE_PHY_TYPE_LOW_50GBASE_CP:
  2809. case ICE_PHY_TYPE_LOW_50GBASE_SR:
  2810. case ICE_PHY_TYPE_LOW_50GBASE_FR:
  2811. case ICE_PHY_TYPE_LOW_50GBASE_LR:
  2812. case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
  2813. case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
  2814. case ICE_PHY_TYPE_LOW_50G_AUI1:
  2815. speed_phy_type_low = ICE_AQ_LINK_SPEED_50GB;
  2816. break;
  2817. case ICE_PHY_TYPE_LOW_100GBASE_CR4:
  2818. case ICE_PHY_TYPE_LOW_100GBASE_SR4:
  2819. case ICE_PHY_TYPE_LOW_100GBASE_LR4:
  2820. case ICE_PHY_TYPE_LOW_100GBASE_KR4:
  2821. case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
  2822. case ICE_PHY_TYPE_LOW_100G_CAUI4:
  2823. case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
  2824. case ICE_PHY_TYPE_LOW_100G_AUI4:
  2825. case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
  2826. case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
  2827. case ICE_PHY_TYPE_LOW_100GBASE_CP2:
  2828. case ICE_PHY_TYPE_LOW_100GBASE_SR2:
  2829. case ICE_PHY_TYPE_LOW_100GBASE_DR:
  2830. speed_phy_type_low = ICE_AQ_LINK_SPEED_100GB;
  2831. break;
  2832. default:
  2833. speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
  2834. break;
  2835. }
  2836. switch (phy_type_high) {
  2837. case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
  2838. case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
  2839. case ICE_PHY_TYPE_HIGH_100G_CAUI2:
  2840. case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
  2841. case ICE_PHY_TYPE_HIGH_100G_AUI2:
  2842. speed_phy_type_high = ICE_AQ_LINK_SPEED_100GB;
  2843. break;
  2844. case ICE_PHY_TYPE_HIGH_200G_CR4_PAM4:
  2845. case ICE_PHY_TYPE_HIGH_200G_SR4:
  2846. case ICE_PHY_TYPE_HIGH_200G_FR4:
  2847. case ICE_PHY_TYPE_HIGH_200G_LR4:
  2848. case ICE_PHY_TYPE_HIGH_200G_DR4:
  2849. case ICE_PHY_TYPE_HIGH_200G_KR4_PAM4:
  2850. case ICE_PHY_TYPE_HIGH_200G_AUI4_AOC_ACC:
  2851. case ICE_PHY_TYPE_HIGH_200G_AUI4:
  2852. speed_phy_type_high = ICE_AQ_LINK_SPEED_200GB;
  2853. break;
  2854. default:
  2855. speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
  2856. break;
  2857. }
  2858. if (speed_phy_type_low == ICE_AQ_LINK_SPEED_UNKNOWN &&
  2859. speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
  2860. return ICE_AQ_LINK_SPEED_UNKNOWN;
  2861. else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
  2862. speed_phy_type_high != ICE_AQ_LINK_SPEED_UNKNOWN)
  2863. return ICE_AQ_LINK_SPEED_UNKNOWN;
  2864. else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
  2865. speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
  2866. return speed_phy_type_low;
  2867. else
  2868. return speed_phy_type_high;
  2869. }
  2870. /**
  2871. * ice_update_phy_type
  2872. * @phy_type_low: pointer to the lower part of phy_type
  2873. * @phy_type_high: pointer to the higher part of phy_type
  2874. * @link_speeds_bitmap: targeted link speeds bitmap
  2875. *
  2876. * Note: For the link_speeds_bitmap structure, you can check it at
  2877. * [ice_aqc_get_link_status->link_speed]. Caller can pass in
  2878. * link_speeds_bitmap include multiple speeds.
  2879. *
  2880. * Each entry in this [phy_type_low, phy_type_high] structure will
  2881. * present a certain link speed. This helper function will turn on bits
  2882. * in [phy_type_low, phy_type_high] structure based on the value of
  2883. * link_speeds_bitmap input parameter.
  2884. */
  2885. void
  2886. ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high,
  2887. u16 link_speeds_bitmap)
  2888. {
  2889. u64 pt_high;
  2890. u64 pt_low;
  2891. int index;
  2892. u16 speed;
  2893. /* We first check with low part of phy_type */
  2894. for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) {
  2895. pt_low = BIT_ULL(index);
  2896. speed = ice_get_link_speed_based_on_phy_type(pt_low, 0);
  2897. if (link_speeds_bitmap & speed)
  2898. *phy_type_low |= BIT_ULL(index);
  2899. }
  2900. /* We then check with high part of phy_type */
  2901. for (index = 0; index <= ICE_PHY_TYPE_HIGH_MAX_INDEX; index++) {
  2902. pt_high = BIT_ULL(index);
  2903. speed = ice_get_link_speed_based_on_phy_type(0, pt_high);
  2904. if (link_speeds_bitmap & speed)
  2905. *phy_type_high |= BIT_ULL(index);
  2906. }
  2907. }
  2908. /**
  2909. * ice_aq_set_phy_cfg
  2910. * @hw: pointer to the HW struct
  2911. * @pi: port info structure of the interested logical port
  2912. * @cfg: structure with PHY configuration data to be set
  2913. * @cd: pointer to command details structure or NULL
  2914. *
  2915. * Set the various PHY configuration parameters supported on the Port.
  2916. * One or more of the Set PHY config parameters may be ignored in an MFP
  2917. * mode as the PF may not have the privilege to set some of the PHY Config
  2918. * parameters. This status will be indicated by the command response (0x0601).
  2919. */
  2920. int
  2921. ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
  2922. struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
  2923. {
  2924. struct ice_aq_desc desc;
  2925. int status;
  2926. if (!cfg)
  2927. return -EINVAL;
  2928. /* Ensure that only valid bits of cfg->caps can be turned on. */
  2929. if (cfg->caps & ~ICE_AQ_PHY_ENA_VALID_MASK) {
  2930. ice_debug(hw, ICE_DBG_PHY, "Invalid bit is set in ice_aqc_set_phy_cfg_data->caps : 0x%x\n",
  2931. cfg->caps);
  2932. cfg->caps &= ICE_AQ_PHY_ENA_VALID_MASK;
  2933. }
  2934. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
  2935. desc.params.set_phy.lport_num = pi->lport;
  2936. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  2937. ice_debug(hw, ICE_DBG_LINK, "set phy cfg\n");
  2938. ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
  2939. (unsigned long long)le64_to_cpu(cfg->phy_type_low));
  2940. ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
  2941. (unsigned long long)le64_to_cpu(cfg->phy_type_high));
  2942. ice_debug(hw, ICE_DBG_LINK, " caps = 0x%x\n", cfg->caps);
  2943. ice_debug(hw, ICE_DBG_LINK, " low_power_ctrl_an = 0x%x\n",
  2944. cfg->low_power_ctrl_an);
  2945. ice_debug(hw, ICE_DBG_LINK, " eee_cap = 0x%x\n", cfg->eee_cap);
  2946. ice_debug(hw, ICE_DBG_LINK, " eeer_value = 0x%x\n", cfg->eeer_value);
  2947. ice_debug(hw, ICE_DBG_LINK, " link_fec_opt = 0x%x\n",
  2948. cfg->link_fec_opt);
  2949. status = ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
  2950. if (hw->adminq.sq_last_status == ICE_AQ_RC_EMODE)
  2951. status = 0;
  2952. if (!status)
  2953. pi->phy.curr_user_phy_cfg = *cfg;
  2954. return status;
  2955. }
  2956. /**
  2957. * ice_update_link_info - update status of the HW network link
  2958. * @pi: port info structure of the interested logical port
  2959. */
  2960. int ice_update_link_info(struct ice_port_info *pi)
  2961. {
  2962. struct ice_link_status *li;
  2963. int status;
  2964. if (!pi)
  2965. return -EINVAL;
  2966. li = &pi->phy.link_info;
  2967. status = ice_aq_get_link_info(pi, true, NULL, NULL);
  2968. if (status)
  2969. return status;
  2970. if (li->link_info & ICE_AQ_MEDIA_AVAILABLE) {
  2971. struct ice_aqc_get_phy_caps_data *pcaps __free(kfree) = NULL;
  2972. pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
  2973. if (!pcaps)
  2974. return -ENOMEM;
  2975. status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
  2976. pcaps, NULL);
  2977. }
  2978. return status;
  2979. }
  2980. /**
  2981. * ice_aq_get_phy_equalization - function to read serdes equaliser
  2982. * value from firmware using admin queue command.
  2983. * @hw: pointer to the HW struct
  2984. * @data_in: represents the serdes equalization parameter requested
  2985. * @op_code: represents the serdes number and flag to represent tx or rx
  2986. * @serdes_num: represents the serdes number
  2987. * @output: pointer to the caller-supplied buffer to return serdes equaliser
  2988. *
  2989. * Return: non-zero status on error and 0 on success.
  2990. */
  2991. int ice_aq_get_phy_equalization(struct ice_hw *hw, u16 data_in, u16 op_code,
  2992. u8 serdes_num, int *output)
  2993. {
  2994. struct ice_aqc_dnl_call_command *cmd;
  2995. struct ice_aqc_dnl_call buf = {};
  2996. struct ice_aq_desc desc;
  2997. int err;
  2998. buf.sto.txrx_equa_reqs.data_in = cpu_to_le16(data_in);
  2999. buf.sto.txrx_equa_reqs.op_code_serdes_sel =
  3000. cpu_to_le16(op_code | (serdes_num & 0xF));
  3001. cmd = &desc.params.dnl_call;
  3002. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dnl_call);
  3003. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_BUF |
  3004. ICE_AQ_FLAG_RD |
  3005. ICE_AQ_FLAG_SI);
  3006. desc.datalen = cpu_to_le16(sizeof(struct ice_aqc_dnl_call));
  3007. cmd->activity_id = cpu_to_le16(ICE_AQC_ACT_ID_DNL);
  3008. err = ice_aq_send_cmd(hw, &desc, &buf, sizeof(struct ice_aqc_dnl_call),
  3009. NULL);
  3010. *output = err ? 0 : buf.sto.txrx_equa_resp.val;
  3011. return err;
  3012. }
  3013. #define FEC_REG_PORT(port) { \
  3014. FEC_CORR_LOW_REG_PORT##port, \
  3015. FEC_CORR_HIGH_REG_PORT##port, \
  3016. FEC_UNCORR_LOW_REG_PORT##port, \
  3017. FEC_UNCORR_HIGH_REG_PORT##port, \
  3018. }
  3019. static const u32 fec_reg[][ICE_FEC_MAX] = {
  3020. FEC_REG_PORT(0),
  3021. FEC_REG_PORT(1),
  3022. FEC_REG_PORT(2),
  3023. FEC_REG_PORT(3)
  3024. };
  3025. /**
  3026. * ice_aq_get_fec_stats - reads fec stats from phy
  3027. * @hw: pointer to the HW struct
  3028. * @pcs_quad: represents pcsquad of user input serdes
  3029. * @pcs_port: represents the pcs port number part of above pcs quad
  3030. * @fec_type: represents FEC stats type
  3031. * @output: pointer to the caller-supplied buffer to return requested fec stats
  3032. *
  3033. * Return: non-zero status on error and 0 on success.
  3034. */
  3035. int ice_aq_get_fec_stats(struct ice_hw *hw, u16 pcs_quad, u16 pcs_port,
  3036. enum ice_fec_stats_types fec_type, u32 *output)
  3037. {
  3038. u16 flag = (ICE_AQ_FLAG_RD | ICE_AQ_FLAG_BUF | ICE_AQ_FLAG_SI);
  3039. struct ice_sbq_msg_input msg = {};
  3040. u32 receiver_id, reg_offset;
  3041. int err;
  3042. if (pcs_port > 3)
  3043. return -EINVAL;
  3044. reg_offset = fec_reg[pcs_port][fec_type];
  3045. if (pcs_quad == 0)
  3046. receiver_id = FEC_RECEIVER_ID_PCS0;
  3047. else if (pcs_quad == 1)
  3048. receiver_id = FEC_RECEIVER_ID_PCS1;
  3049. else
  3050. return -EINVAL;
  3051. msg.msg_addr_low = lower_16_bits(reg_offset);
  3052. msg.msg_addr_high = receiver_id;
  3053. msg.opcode = ice_sbq_msg_rd;
  3054. msg.dest_dev = rmn_0;
  3055. err = ice_sbq_rw_reg(hw, &msg, flag);
  3056. if (err)
  3057. return err;
  3058. *output = msg.data;
  3059. return 0;
  3060. }
  3061. /**
  3062. * ice_cache_phy_user_req
  3063. * @pi: port information structure
  3064. * @cache_data: PHY logging data
  3065. * @cache_mode: PHY logging mode
  3066. *
  3067. * Log the user request on (FC, FEC, SPEED) for later use.
  3068. */
  3069. static void
  3070. ice_cache_phy_user_req(struct ice_port_info *pi,
  3071. struct ice_phy_cache_mode_data cache_data,
  3072. enum ice_phy_cache_mode cache_mode)
  3073. {
  3074. if (!pi)
  3075. return;
  3076. switch (cache_mode) {
  3077. case ICE_FC_MODE:
  3078. pi->phy.curr_user_fc_req = cache_data.data.curr_user_fc_req;
  3079. break;
  3080. case ICE_SPEED_MODE:
  3081. pi->phy.curr_user_speed_req =
  3082. cache_data.data.curr_user_speed_req;
  3083. break;
  3084. case ICE_FEC_MODE:
  3085. pi->phy.curr_user_fec_req = cache_data.data.curr_user_fec_req;
  3086. break;
  3087. default:
  3088. break;
  3089. }
  3090. }
  3091. /**
  3092. * ice_caps_to_fc_mode
  3093. * @caps: PHY capabilities
  3094. *
  3095. * Convert PHY FC capabilities to ice FC mode
  3096. */
  3097. enum ice_fc_mode ice_caps_to_fc_mode(u8 caps)
  3098. {
  3099. if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE &&
  3100. caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
  3101. return ICE_FC_FULL;
  3102. if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
  3103. return ICE_FC_TX_PAUSE;
  3104. if (caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
  3105. return ICE_FC_RX_PAUSE;
  3106. return ICE_FC_NONE;
  3107. }
  3108. /**
  3109. * ice_caps_to_fec_mode
  3110. * @caps: PHY capabilities
  3111. * @fec_options: Link FEC options
  3112. *
  3113. * Convert PHY FEC capabilities to ice FEC mode
  3114. */
  3115. enum ice_fec_mode ice_caps_to_fec_mode(u8 caps, u8 fec_options)
  3116. {
  3117. if (caps & ICE_AQC_PHY_EN_AUTO_FEC)
  3118. return ICE_FEC_AUTO;
  3119. if (fec_options & (ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
  3120. ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
  3121. ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
  3122. ICE_AQC_PHY_FEC_25G_KR_REQ))
  3123. return ICE_FEC_BASER;
  3124. if (fec_options & (ICE_AQC_PHY_FEC_25G_RS_528_REQ |
  3125. ICE_AQC_PHY_FEC_25G_RS_544_REQ |
  3126. ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN))
  3127. return ICE_FEC_RS;
  3128. return ICE_FEC_NONE;
  3129. }
  3130. /**
  3131. * ice_cfg_phy_fc - Configure PHY FC data based on FC mode
  3132. * @pi: port information structure
  3133. * @cfg: PHY configuration data to set FC mode
  3134. * @req_mode: FC mode to configure
  3135. */
  3136. int
  3137. ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
  3138. enum ice_fc_mode req_mode)
  3139. {
  3140. struct ice_phy_cache_mode_data cache_data;
  3141. u8 pause_mask = 0x0;
  3142. if (!pi || !cfg)
  3143. return -EINVAL;
  3144. switch (req_mode) {
  3145. case ICE_FC_FULL:
  3146. pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
  3147. pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
  3148. break;
  3149. case ICE_FC_RX_PAUSE:
  3150. pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
  3151. break;
  3152. case ICE_FC_TX_PAUSE:
  3153. pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
  3154. break;
  3155. default:
  3156. break;
  3157. }
  3158. /* clear the old pause settings */
  3159. cfg->caps &= ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
  3160. ICE_AQC_PHY_EN_RX_LINK_PAUSE);
  3161. /* set the new capabilities */
  3162. cfg->caps |= pause_mask;
  3163. /* Cache user FC request */
  3164. cache_data.data.curr_user_fc_req = req_mode;
  3165. ice_cache_phy_user_req(pi, cache_data, ICE_FC_MODE);
  3166. return 0;
  3167. }
  3168. /**
  3169. * ice_set_fc
  3170. * @pi: port information structure
  3171. * @aq_failures: pointer to status code, specific to ice_set_fc routine
  3172. * @ena_auto_link_update: enable automatic link update
  3173. *
  3174. * Set the requested flow control mode.
  3175. */
  3176. int
  3177. ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
  3178. {
  3179. struct ice_aqc_get_phy_caps_data *pcaps __free(kfree) = NULL;
  3180. struct ice_aqc_set_phy_cfg_data cfg = { 0 };
  3181. struct ice_hw *hw;
  3182. int status;
  3183. if (!pi || !aq_failures)
  3184. return -EINVAL;
  3185. *aq_failures = 0;
  3186. hw = pi->hw;
  3187. pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
  3188. if (!pcaps)
  3189. return -ENOMEM;
  3190. /* Get the current PHY config */
  3191. status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG,
  3192. pcaps, NULL);
  3193. if (status) {
  3194. *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
  3195. goto out;
  3196. }
  3197. ice_copy_phy_caps_to_cfg(pi, pcaps, &cfg);
  3198. /* Configure the set PHY data */
  3199. status = ice_cfg_phy_fc(pi, &cfg, pi->fc.req_mode);
  3200. if (status)
  3201. goto out;
  3202. /* If the capabilities have changed, then set the new config */
  3203. if (cfg.caps != pcaps->caps) {
  3204. int retry_count, retry_max = 10;
  3205. /* Auto restart link so settings take effect */
  3206. if (ena_auto_link_update)
  3207. cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
  3208. status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
  3209. if (status) {
  3210. *aq_failures = ICE_SET_FC_AQ_FAIL_SET;
  3211. goto out;
  3212. }
  3213. /* Update the link info
  3214. * It sometimes takes a really long time for link to
  3215. * come back from the atomic reset. Thus, we wait a
  3216. * little bit.
  3217. */
  3218. for (retry_count = 0; retry_count < retry_max; retry_count++) {
  3219. status = ice_update_link_info(pi);
  3220. if (!status)
  3221. break;
  3222. mdelay(100);
  3223. }
  3224. if (status)
  3225. *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
  3226. }
  3227. out:
  3228. return status;
  3229. }
  3230. /**
  3231. * ice_phy_caps_equals_cfg
  3232. * @phy_caps: PHY capabilities
  3233. * @phy_cfg: PHY configuration
  3234. *
  3235. * Helper function to determine if PHY capabilities matches PHY
  3236. * configuration
  3237. */
  3238. bool
  3239. ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data *phy_caps,
  3240. struct ice_aqc_set_phy_cfg_data *phy_cfg)
  3241. {
  3242. u8 caps_mask, cfg_mask;
  3243. if (!phy_caps || !phy_cfg)
  3244. return false;
  3245. /* These bits are not common between capabilities and configuration.
  3246. * Do not use them to determine equality.
  3247. */
  3248. caps_mask = ICE_AQC_PHY_CAPS_MASK & ~(ICE_AQC_PHY_AN_MODE |
  3249. ICE_AQC_GET_PHY_EN_MOD_QUAL);
  3250. cfg_mask = ICE_AQ_PHY_ENA_VALID_MASK & ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
  3251. if (phy_caps->phy_type_low != phy_cfg->phy_type_low ||
  3252. phy_caps->phy_type_high != phy_cfg->phy_type_high ||
  3253. ((phy_caps->caps & caps_mask) != (phy_cfg->caps & cfg_mask)) ||
  3254. phy_caps->low_power_ctrl_an != phy_cfg->low_power_ctrl_an ||
  3255. phy_caps->eee_cap != phy_cfg->eee_cap ||
  3256. phy_caps->eeer_value != phy_cfg->eeer_value ||
  3257. phy_caps->link_fec_options != phy_cfg->link_fec_opt)
  3258. return false;
  3259. return true;
  3260. }
  3261. /**
  3262. * ice_copy_phy_caps_to_cfg - Copy PHY ability data to configuration data
  3263. * @pi: port information structure
  3264. * @caps: PHY ability structure to copy date from
  3265. * @cfg: PHY configuration structure to copy data to
  3266. *
  3267. * Helper function to copy AQC PHY get ability data to PHY set configuration
  3268. * data structure
  3269. */
  3270. void
  3271. ice_copy_phy_caps_to_cfg(struct ice_port_info *pi,
  3272. struct ice_aqc_get_phy_caps_data *caps,
  3273. struct ice_aqc_set_phy_cfg_data *cfg)
  3274. {
  3275. if (!pi || !caps || !cfg)
  3276. return;
  3277. memset(cfg, 0, sizeof(*cfg));
  3278. cfg->phy_type_low = caps->phy_type_low;
  3279. cfg->phy_type_high = caps->phy_type_high;
  3280. cfg->caps = caps->caps;
  3281. cfg->low_power_ctrl_an = caps->low_power_ctrl_an;
  3282. cfg->eee_cap = caps->eee_cap;
  3283. cfg->eeer_value = caps->eeer_value;
  3284. cfg->link_fec_opt = caps->link_fec_options;
  3285. cfg->module_compliance_enforcement =
  3286. caps->module_compliance_enforcement;
  3287. }
  3288. /**
  3289. * ice_cfg_phy_fec - Configure PHY FEC data based on FEC mode
  3290. * @pi: port information structure
  3291. * @cfg: PHY configuration data to set FEC mode
  3292. * @fec: FEC mode to configure
  3293. */
  3294. int
  3295. ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
  3296. enum ice_fec_mode fec)
  3297. {
  3298. struct ice_aqc_get_phy_caps_data *pcaps __free(kfree) = NULL;
  3299. struct ice_hw *hw;
  3300. int status;
  3301. if (!pi || !cfg)
  3302. return -EINVAL;
  3303. hw = pi->hw;
  3304. pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
  3305. if (!pcaps)
  3306. return -ENOMEM;
  3307. status = ice_aq_get_phy_caps(pi, false,
  3308. (ice_fw_supports_report_dflt_cfg(hw) ?
  3309. ICE_AQC_REPORT_DFLT_CFG :
  3310. ICE_AQC_REPORT_TOPO_CAP_MEDIA), pcaps, NULL);
  3311. if (status)
  3312. goto out;
  3313. cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC;
  3314. cfg->link_fec_opt = pcaps->link_fec_options;
  3315. switch (fec) {
  3316. case ICE_FEC_BASER:
  3317. /* Clear RS bits, and AND BASE-R ability
  3318. * bits and OR request bits.
  3319. */
  3320. cfg->link_fec_opt &= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
  3321. ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN;
  3322. cfg->link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
  3323. ICE_AQC_PHY_FEC_25G_KR_REQ;
  3324. break;
  3325. case ICE_FEC_RS:
  3326. /* Clear BASE-R bits, and AND RS ability
  3327. * bits and OR request bits.
  3328. */
  3329. cfg->link_fec_opt &= ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN;
  3330. cfg->link_fec_opt |= ICE_AQC_PHY_FEC_25G_RS_528_REQ |
  3331. ICE_AQC_PHY_FEC_25G_RS_544_REQ;
  3332. break;
  3333. case ICE_FEC_NONE:
  3334. /* Clear all FEC option bits. */
  3335. cfg->link_fec_opt &= ~ICE_AQC_PHY_FEC_MASK;
  3336. break;
  3337. case ICE_FEC_AUTO:
  3338. /* AND auto FEC bit, and all caps bits. */
  3339. cfg->caps &= ICE_AQC_PHY_CAPS_MASK;
  3340. cfg->link_fec_opt |= pcaps->link_fec_options;
  3341. break;
  3342. default:
  3343. status = -EINVAL;
  3344. break;
  3345. }
  3346. if (fec == ICE_FEC_AUTO && ice_fw_supports_link_override(hw) &&
  3347. !ice_fw_supports_report_dflt_cfg(hw)) {
  3348. struct ice_link_default_override_tlv tlv = { 0 };
  3349. status = ice_get_link_default_override(&tlv, pi);
  3350. if (status)
  3351. goto out;
  3352. if (!(tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE) &&
  3353. (tlv.options & ICE_LINK_OVERRIDE_EN))
  3354. cfg->link_fec_opt = tlv.fec_options;
  3355. }
  3356. out:
  3357. return status;
  3358. }
  3359. /**
  3360. * ice_get_link_status - get status of the HW network link
  3361. * @pi: port information structure
  3362. * @link_up: pointer to bool (true/false = linkup/linkdown)
  3363. *
  3364. * Variable link_up is true if link is up, false if link is down.
  3365. * The variable link_up is invalid if status is non zero. As a
  3366. * result of this call, link status reporting becomes enabled
  3367. */
  3368. int ice_get_link_status(struct ice_port_info *pi, bool *link_up)
  3369. {
  3370. struct ice_phy_info *phy_info;
  3371. int status = 0;
  3372. if (!pi || !link_up)
  3373. return -EINVAL;
  3374. phy_info = &pi->phy;
  3375. if (phy_info->get_link_info) {
  3376. status = ice_update_link_info(pi);
  3377. if (status)
  3378. ice_debug(pi->hw, ICE_DBG_LINK, "get link status error, status = %d\n",
  3379. status);
  3380. }
  3381. *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
  3382. return status;
  3383. }
  3384. /**
  3385. * ice_aq_set_link_restart_an
  3386. * @pi: pointer to the port information structure
  3387. * @ena_link: if true: enable link, if false: disable link
  3388. * @cd: pointer to command details structure or NULL
  3389. *
  3390. * Sets up the link and restarts the Auto-Negotiation over the link.
  3391. */
  3392. int
  3393. ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
  3394. struct ice_sq_cd *cd)
  3395. {
  3396. struct ice_aqc_restart_an *cmd;
  3397. struct ice_aq_desc desc;
  3398. cmd = &desc.params.restart_an;
  3399. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
  3400. cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
  3401. cmd->lport_num = pi->lport;
  3402. if (ena_link)
  3403. cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
  3404. else
  3405. cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
  3406. return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
  3407. }
  3408. /**
  3409. * ice_aq_set_event_mask
  3410. * @hw: pointer to the HW struct
  3411. * @port_num: port number of the physical function
  3412. * @mask: event mask to be set
  3413. * @cd: pointer to command details structure or NULL
  3414. *
  3415. * Set event mask (0x0613)
  3416. */
  3417. int
  3418. ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask,
  3419. struct ice_sq_cd *cd)
  3420. {
  3421. struct ice_aqc_set_event_mask *cmd;
  3422. struct ice_aq_desc desc;
  3423. cmd = &desc.params.set_event_mask;
  3424. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_event_mask);
  3425. cmd->lport_num = port_num;
  3426. cmd->event_mask = cpu_to_le16(mask);
  3427. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  3428. }
  3429. /**
  3430. * ice_aq_set_mac_loopback
  3431. * @hw: pointer to the HW struct
  3432. * @ena_lpbk: Enable or Disable loopback
  3433. * @cd: pointer to command details structure or NULL
  3434. *
  3435. * Enable/disable loopback on a given port
  3436. */
  3437. int
  3438. ice_aq_set_mac_loopback(struct ice_hw *hw, bool ena_lpbk, struct ice_sq_cd *cd)
  3439. {
  3440. struct ice_aqc_set_mac_lb *cmd;
  3441. struct ice_aq_desc desc;
  3442. cmd = &desc.params.set_mac_lb;
  3443. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_lb);
  3444. if (ena_lpbk)
  3445. cmd->lb_mode = ICE_AQ_MAC_LB_EN;
  3446. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  3447. }
  3448. /**
  3449. * ice_aq_set_port_id_led
  3450. * @pi: pointer to the port information
  3451. * @is_orig_mode: is this LED set to original mode (by the net-list)
  3452. * @cd: pointer to command details structure or NULL
  3453. *
  3454. * Set LED value for the given port (0x06e9)
  3455. */
  3456. int
  3457. ice_aq_set_port_id_led(struct ice_port_info *pi, bool is_orig_mode,
  3458. struct ice_sq_cd *cd)
  3459. {
  3460. struct ice_aqc_set_port_id_led *cmd;
  3461. struct ice_hw *hw = pi->hw;
  3462. struct ice_aq_desc desc;
  3463. cmd = &desc.params.set_port_id_led;
  3464. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_id_led);
  3465. if (is_orig_mode)
  3466. cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_ORIG;
  3467. else
  3468. cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_BLINK;
  3469. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  3470. }
  3471. /**
  3472. * ice_aq_get_port_options
  3473. * @hw: pointer to the HW struct
  3474. * @options: buffer for the resultant port options
  3475. * @option_count: input - size of the buffer in port options structures,
  3476. * output - number of returned port options
  3477. * @lport: logical port to call the command with (optional)
  3478. * @lport_valid: when false, FW uses port owned by the PF instead of lport,
  3479. * when PF owns more than 1 port it must be true
  3480. * @active_option_idx: index of active port option in returned buffer
  3481. * @active_option_valid: active option in returned buffer is valid
  3482. * @pending_option_idx: index of pending port option in returned buffer
  3483. * @pending_option_valid: pending option in returned buffer is valid
  3484. *
  3485. * Calls Get Port Options AQC (0x06ea) and verifies result.
  3486. */
  3487. int
  3488. ice_aq_get_port_options(struct ice_hw *hw,
  3489. struct ice_aqc_get_port_options_elem *options,
  3490. u8 *option_count, u8 lport, bool lport_valid,
  3491. u8 *active_option_idx, bool *active_option_valid,
  3492. u8 *pending_option_idx, bool *pending_option_valid)
  3493. {
  3494. struct ice_aqc_get_port_options *cmd;
  3495. struct ice_aq_desc desc;
  3496. int status;
  3497. u8 i;
  3498. /* options buffer shall be able to hold max returned options */
  3499. if (*option_count < ICE_AQC_PORT_OPT_COUNT_M)
  3500. return -EINVAL;
  3501. cmd = &desc.params.get_port_options;
  3502. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_port_options);
  3503. if (lport_valid)
  3504. cmd->lport_num = lport;
  3505. cmd->lport_num_valid = lport_valid;
  3506. status = ice_aq_send_cmd(hw, &desc, options,
  3507. *option_count * sizeof(*options), NULL);
  3508. if (status)
  3509. return status;
  3510. /* verify direct FW response & set output parameters */
  3511. *option_count = FIELD_GET(ICE_AQC_PORT_OPT_COUNT_M,
  3512. cmd->port_options_count);
  3513. ice_debug(hw, ICE_DBG_PHY, "options: %x\n", *option_count);
  3514. *active_option_valid = FIELD_GET(ICE_AQC_PORT_OPT_VALID,
  3515. cmd->port_options);
  3516. if (*active_option_valid) {
  3517. *active_option_idx = FIELD_GET(ICE_AQC_PORT_OPT_ACTIVE_M,
  3518. cmd->port_options);
  3519. if (*active_option_idx > (*option_count - 1))
  3520. return -EIO;
  3521. ice_debug(hw, ICE_DBG_PHY, "active idx: %x\n",
  3522. *active_option_idx);
  3523. }
  3524. *pending_option_valid = FIELD_GET(ICE_AQC_PENDING_PORT_OPT_VALID,
  3525. cmd->pending_port_option_status);
  3526. if (*pending_option_valid) {
  3527. *pending_option_idx = FIELD_GET(ICE_AQC_PENDING_PORT_OPT_IDX_M,
  3528. cmd->pending_port_option_status);
  3529. if (*pending_option_idx > (*option_count - 1))
  3530. return -EIO;
  3531. ice_debug(hw, ICE_DBG_PHY, "pending idx: %x\n",
  3532. *pending_option_idx);
  3533. }
  3534. /* mask output options fields */
  3535. for (i = 0; i < *option_count; i++) {
  3536. options[i].pmd = FIELD_GET(ICE_AQC_PORT_OPT_PMD_COUNT_M,
  3537. options[i].pmd);
  3538. options[i].max_lane_speed = FIELD_GET(ICE_AQC_PORT_OPT_MAX_LANE_M,
  3539. options[i].max_lane_speed);
  3540. ice_debug(hw, ICE_DBG_PHY, "pmds: %x max speed: %x\n",
  3541. options[i].pmd, options[i].max_lane_speed);
  3542. }
  3543. return 0;
  3544. }
  3545. /**
  3546. * ice_aq_set_port_option
  3547. * @hw: pointer to the HW struct
  3548. * @lport: logical port to call the command with
  3549. * @lport_valid: when false, FW uses port owned by the PF instead of lport,
  3550. * when PF owns more than 1 port it must be true
  3551. * @new_option: new port option to be written
  3552. *
  3553. * Calls Set Port Options AQC (0x06eb).
  3554. */
  3555. int
  3556. ice_aq_set_port_option(struct ice_hw *hw, u8 lport, u8 lport_valid,
  3557. u8 new_option)
  3558. {
  3559. struct ice_aqc_set_port_option *cmd;
  3560. struct ice_aq_desc desc;
  3561. if (new_option > ICE_AQC_PORT_OPT_COUNT_M)
  3562. return -EINVAL;
  3563. cmd = &desc.params.set_port_option;
  3564. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_option);
  3565. if (lport_valid)
  3566. cmd->lport_num = lport;
  3567. cmd->lport_num_valid = lport_valid;
  3568. cmd->selected_port_option = new_option;
  3569. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  3570. }
  3571. /**
  3572. * ice_get_phy_lane_number - Get PHY lane number for current adapter
  3573. * @hw: pointer to the hw struct
  3574. *
  3575. * Return: PHY lane number on success, negative error code otherwise.
  3576. */
  3577. int ice_get_phy_lane_number(struct ice_hw *hw)
  3578. {
  3579. struct ice_aqc_get_port_options_elem *options;
  3580. unsigned int lport = 0;
  3581. unsigned int lane;
  3582. int err;
  3583. options = kcalloc(ICE_AQC_PORT_OPT_MAX, sizeof(*options), GFP_KERNEL);
  3584. if (!options)
  3585. return -ENOMEM;
  3586. for (lane = 0; lane < ICE_MAX_PORT_PER_PCI_DEV; lane++) {
  3587. u8 options_count = ICE_AQC_PORT_OPT_MAX;
  3588. u8 speed, active_idx, pending_idx;
  3589. bool active_valid, pending_valid;
  3590. err = ice_aq_get_port_options(hw, options, &options_count, lane,
  3591. true, &active_idx, &active_valid,
  3592. &pending_idx, &pending_valid);
  3593. if (err)
  3594. goto err;
  3595. if (!active_valid)
  3596. continue;
  3597. speed = options[active_idx].max_lane_speed;
  3598. /* If we don't get speed for this lane, it's unoccupied */
  3599. if (speed > ICE_AQC_PORT_OPT_MAX_LANE_200G)
  3600. continue;
  3601. if (hw->pf_id == lport) {
  3602. kfree(options);
  3603. return lane;
  3604. }
  3605. lport++;
  3606. }
  3607. /* PHY lane not found */
  3608. err = -ENXIO;
  3609. err:
  3610. kfree(options);
  3611. return err;
  3612. }
  3613. /**
  3614. * ice_aq_sff_eeprom
  3615. * @hw: pointer to the HW struct
  3616. * @lport: bits [7:0] = logical port, bit [8] = logical port valid
  3617. * @bus_addr: I2C bus address of the eeprom (typically 0xA0, 0=topo default)
  3618. * @mem_addr: I2C offset. lower 8 bits for address, 8 upper bits zero padding.
  3619. * @page: QSFP page
  3620. * @set_page: set or ignore the page
  3621. * @data: pointer to data buffer to be read/written to the I2C device.
  3622. * @length: 1-16 for read, 1 for write.
  3623. * @write: 0 read, 1 for write.
  3624. * @cd: pointer to command details structure or NULL
  3625. *
  3626. * Read/Write SFF EEPROM (0x06EE)
  3627. */
  3628. int
  3629. ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
  3630. u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
  3631. bool write, struct ice_sq_cd *cd)
  3632. {
  3633. struct ice_aqc_sff_eeprom *cmd;
  3634. struct ice_aq_desc desc;
  3635. u16 i2c_bus_addr;
  3636. int status;
  3637. if (!data || (mem_addr & 0xff00))
  3638. return -EINVAL;
  3639. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_sff_eeprom);
  3640. cmd = &desc.params.read_write_sff_param;
  3641. desc.flags = cpu_to_le16(ICE_AQ_FLAG_RD);
  3642. cmd->lport_num = (u8)(lport & 0xff);
  3643. cmd->lport_num_valid = (u8)((lport >> 8) & 0x01);
  3644. i2c_bus_addr = FIELD_PREP(ICE_AQC_SFF_I2CBUS_7BIT_M, bus_addr >> 1) |
  3645. FIELD_PREP(ICE_AQC_SFF_SET_EEPROM_PAGE_M, set_page);
  3646. if (write)
  3647. i2c_bus_addr |= ICE_AQC_SFF_IS_WRITE;
  3648. cmd->i2c_bus_addr = cpu_to_le16(i2c_bus_addr);
  3649. cmd->i2c_mem_addr = cpu_to_le16(mem_addr & 0xff);
  3650. cmd->eeprom_page = le16_encode_bits(page, ICE_AQC_SFF_EEPROM_PAGE_M);
  3651. status = ice_aq_send_cmd(hw, &desc, data, length, cd);
  3652. return status;
  3653. }
  3654. static enum ice_lut_size ice_lut_type_to_size(enum ice_lut_type type)
  3655. {
  3656. switch (type) {
  3657. case ICE_LUT_VSI:
  3658. return ICE_LUT_VSI_SIZE;
  3659. case ICE_LUT_GLOBAL:
  3660. return ICE_LUT_GLOBAL_SIZE;
  3661. case ICE_LUT_PF:
  3662. return ICE_LUT_PF_SIZE;
  3663. }
  3664. WARN_ONCE(1, "incorrect type passed");
  3665. return ICE_LUT_VSI_SIZE;
  3666. }
  3667. static enum ice_aqc_lut_flags ice_lut_size_to_flag(enum ice_lut_size size)
  3668. {
  3669. switch (size) {
  3670. case ICE_LUT_VSI_SIZE:
  3671. return ICE_AQC_LUT_SIZE_SMALL;
  3672. case ICE_LUT_GLOBAL_SIZE:
  3673. return ICE_AQC_LUT_SIZE_512;
  3674. case ICE_LUT_PF_SIZE:
  3675. return ICE_AQC_LUT_SIZE_2K;
  3676. }
  3677. WARN_ONCE(1, "incorrect size passed");
  3678. return 0;
  3679. }
  3680. /**
  3681. * __ice_aq_get_set_rss_lut
  3682. * @hw: pointer to the hardware structure
  3683. * @params: RSS LUT parameters
  3684. * @set: set true to set the table, false to get the table
  3685. *
  3686. * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
  3687. */
  3688. static int
  3689. __ice_aq_get_set_rss_lut(struct ice_hw *hw,
  3690. struct ice_aq_get_set_rss_lut_params *params, bool set)
  3691. {
  3692. u16 opcode, vsi_id, vsi_handle = params->vsi_handle, glob_lut_idx = 0;
  3693. enum ice_lut_type lut_type = params->lut_type;
  3694. struct ice_aqc_get_set_rss_lut *desc_params;
  3695. enum ice_aqc_lut_flags flags;
  3696. enum ice_lut_size lut_size;
  3697. struct ice_aq_desc desc;
  3698. u8 *lut = params->lut;
  3699. if (!lut || !ice_is_vsi_valid(hw, vsi_handle))
  3700. return -EINVAL;
  3701. lut_size = ice_lut_type_to_size(lut_type);
  3702. if (lut_size > params->lut_size)
  3703. return -EINVAL;
  3704. else if (set && lut_size != params->lut_size)
  3705. return -EINVAL;
  3706. opcode = set ? ice_aqc_opc_set_rss_lut : ice_aqc_opc_get_rss_lut;
  3707. ice_fill_dflt_direct_cmd_desc(&desc, opcode);
  3708. if (set)
  3709. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  3710. desc_params = &desc.params.get_set_rss_lut;
  3711. vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
  3712. desc_params->vsi_id = cpu_to_le16(vsi_id | ICE_AQC_RSS_VSI_VALID);
  3713. if (lut_type == ICE_LUT_GLOBAL)
  3714. glob_lut_idx = FIELD_PREP(ICE_AQC_LUT_GLOBAL_IDX,
  3715. params->global_lut_id);
  3716. flags = lut_type | glob_lut_idx | ice_lut_size_to_flag(lut_size);
  3717. desc_params->flags = cpu_to_le16(flags);
  3718. return ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL);
  3719. }
  3720. /**
  3721. * ice_aq_get_rss_lut
  3722. * @hw: pointer to the hardware structure
  3723. * @get_params: RSS LUT parameters used to specify which RSS LUT to get
  3724. *
  3725. * get the RSS lookup table, PF or VSI type
  3726. */
  3727. int
  3728. ice_aq_get_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *get_params)
  3729. {
  3730. return __ice_aq_get_set_rss_lut(hw, get_params, false);
  3731. }
  3732. /**
  3733. * ice_aq_set_rss_lut
  3734. * @hw: pointer to the hardware structure
  3735. * @set_params: RSS LUT parameters used to specify how to set the RSS LUT
  3736. *
  3737. * set the RSS lookup table, PF or VSI type
  3738. */
  3739. int
  3740. ice_aq_set_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *set_params)
  3741. {
  3742. return __ice_aq_get_set_rss_lut(hw, set_params, true);
  3743. }
  3744. /**
  3745. * __ice_aq_get_set_rss_key
  3746. * @hw: pointer to the HW struct
  3747. * @vsi_id: VSI FW index
  3748. * @key: pointer to key info struct
  3749. * @set: set true to set the key, false to get the key
  3750. *
  3751. * get (0x0B04) or set (0x0B02) the RSS key per VSI
  3752. */
  3753. static int
  3754. __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id,
  3755. struct ice_aqc_get_set_rss_keys *key, bool set)
  3756. {
  3757. struct ice_aqc_get_set_rss_key *desc_params;
  3758. u16 key_size = sizeof(*key);
  3759. struct ice_aq_desc desc;
  3760. if (set) {
  3761. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key);
  3762. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  3763. } else {
  3764. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key);
  3765. }
  3766. desc_params = &desc.params.get_set_rss_key;
  3767. desc_params->vsi_id = cpu_to_le16(vsi_id | ICE_AQC_RSS_VSI_VALID);
  3768. return ice_aq_send_cmd(hw, &desc, key, key_size, NULL);
  3769. }
  3770. /**
  3771. * ice_aq_get_rss_key
  3772. * @hw: pointer to the HW struct
  3773. * @vsi_handle: software VSI handle
  3774. * @key: pointer to key info struct
  3775. *
  3776. * get the RSS key per VSI
  3777. */
  3778. int
  3779. ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle,
  3780. struct ice_aqc_get_set_rss_keys *key)
  3781. {
  3782. if (!ice_is_vsi_valid(hw, vsi_handle) || !key)
  3783. return -EINVAL;
  3784. return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
  3785. key, false);
  3786. }
  3787. /**
  3788. * ice_aq_set_rss_key
  3789. * @hw: pointer to the HW struct
  3790. * @vsi_handle: software VSI handle
  3791. * @keys: pointer to key info struct
  3792. *
  3793. * set the RSS key per VSI
  3794. */
  3795. int
  3796. ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle,
  3797. struct ice_aqc_get_set_rss_keys *keys)
  3798. {
  3799. if (!ice_is_vsi_valid(hw, vsi_handle) || !keys)
  3800. return -EINVAL;
  3801. return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
  3802. keys, true);
  3803. }
  3804. /**
  3805. * ice_aq_add_lan_txq
  3806. * @hw: pointer to the hardware structure
  3807. * @num_qgrps: Number of added queue groups
  3808. * @qg_list: list of queue groups to be added
  3809. * @buf_size: size of buffer for indirect command
  3810. * @cd: pointer to command details structure or NULL
  3811. *
  3812. * Add Tx LAN queue (0x0C30)
  3813. *
  3814. * NOTE:
  3815. * Prior to calling add Tx LAN queue:
  3816. * Initialize the following as part of the Tx queue context:
  3817. * Completion queue ID if the queue uses Completion queue, Quanta profile,
  3818. * Cache profile and Packet shaper profile.
  3819. *
  3820. * After add Tx LAN queue AQ command is completed:
  3821. * Interrupts should be associated with specific queues,
  3822. * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
  3823. * flow.
  3824. */
  3825. static int
  3826. ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps,
  3827. struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size,
  3828. struct ice_sq_cd *cd)
  3829. {
  3830. struct ice_aqc_add_tx_qgrp *list;
  3831. struct ice_aqc_add_txqs *cmd;
  3832. struct ice_aq_desc desc;
  3833. u16 i, sum_size = 0;
  3834. cmd = &desc.params.add_txqs;
  3835. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs);
  3836. if (!qg_list)
  3837. return -EINVAL;
  3838. if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
  3839. return -EINVAL;
  3840. for (i = 0, list = qg_list; i < num_qgrps; i++) {
  3841. sum_size += struct_size(list, txqs, list->num_txqs);
  3842. list = (struct ice_aqc_add_tx_qgrp *)(list->txqs +
  3843. list->num_txqs);
  3844. }
  3845. if (buf_size != sum_size)
  3846. return -EINVAL;
  3847. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  3848. cmd->num_qgrps = num_qgrps;
  3849. return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
  3850. }
  3851. /**
  3852. * ice_aq_dis_lan_txq
  3853. * @hw: pointer to the hardware structure
  3854. * @num_qgrps: number of groups in the list
  3855. * @qg_list: the list of groups to disable
  3856. * @buf_size: the total size of the qg_list buffer in bytes
  3857. * @rst_src: if called due to reset, specifies the reset source
  3858. * @vmvf_num: the relative VM or VF number that is undergoing the reset
  3859. * @cd: pointer to command details structure or NULL
  3860. *
  3861. * Disable LAN Tx queue (0x0C31)
  3862. */
  3863. static int
  3864. ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps,
  3865. struct ice_aqc_dis_txq_item *qg_list, u16 buf_size,
  3866. enum ice_disq_rst_src rst_src, u16 vmvf_num,
  3867. struct ice_sq_cd *cd)
  3868. {
  3869. struct ice_aqc_dis_txq_item *item;
  3870. struct ice_aqc_dis_txqs *cmd;
  3871. struct ice_aq_desc desc;
  3872. u16 vmvf_and_timeout;
  3873. u16 i, sz = 0;
  3874. int status;
  3875. cmd = &desc.params.dis_txqs;
  3876. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs);
  3877. /* qg_list can be NULL only in VM/VF reset flow */
  3878. if (!qg_list && !rst_src)
  3879. return -EINVAL;
  3880. if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
  3881. return -EINVAL;
  3882. cmd->num_entries = num_qgrps;
  3883. vmvf_and_timeout = FIELD_PREP(ICE_AQC_Q_DIS_TIMEOUT_M, 5);
  3884. switch (rst_src) {
  3885. case ICE_VM_RESET:
  3886. cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VM_RESET;
  3887. vmvf_and_timeout |= vmvf_num & ICE_AQC_Q_DIS_VMVF_NUM_M;
  3888. break;
  3889. case ICE_VF_RESET:
  3890. cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VF_RESET;
  3891. /* In this case, FW expects vmvf_num to be absolute VF ID */
  3892. vmvf_and_timeout |= (vmvf_num + hw->func_caps.vf_base_id) &
  3893. ICE_AQC_Q_DIS_VMVF_NUM_M;
  3894. break;
  3895. case ICE_NO_RESET:
  3896. default:
  3897. break;
  3898. }
  3899. cmd->vmvf_and_timeout = cpu_to_le16(vmvf_and_timeout);
  3900. /* flush pipe on time out */
  3901. cmd->cmd_type |= ICE_AQC_Q_DIS_CMD_FLUSH_PIPE;
  3902. /* If no queue group info, we are in a reset flow. Issue the AQ */
  3903. if (!qg_list)
  3904. goto do_aq;
  3905. /* set RD bit to indicate that command buffer is provided by the driver
  3906. * and it needs to be read by the firmware
  3907. */
  3908. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  3909. for (i = 0, item = qg_list; i < num_qgrps; i++) {
  3910. u16 item_size = struct_size(item, q_id, item->num_qs);
  3911. /* If the num of queues is even, add 2 bytes of padding */
  3912. if ((item->num_qs % 2) == 0)
  3913. item_size += 2;
  3914. sz += item_size;
  3915. item = (struct ice_aqc_dis_txq_item *)((u8 *)item + item_size);
  3916. }
  3917. if (buf_size != sz)
  3918. return -EINVAL;
  3919. do_aq:
  3920. status = ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
  3921. if (status) {
  3922. if (!qg_list)
  3923. ice_debug(hw, ICE_DBG_SCHED, "VM%d disable failed %d\n",
  3924. vmvf_num, hw->adminq.sq_last_status);
  3925. else
  3926. ice_debug(hw, ICE_DBG_SCHED, "disable queue %d failed %d\n",
  3927. le16_to_cpu(qg_list[0].q_id[0]),
  3928. hw->adminq.sq_last_status);
  3929. }
  3930. return status;
  3931. }
  3932. /**
  3933. * ice_aq_cfg_lan_txq
  3934. * @hw: pointer to the hardware structure
  3935. * @buf: buffer for command
  3936. * @buf_size: size of buffer in bytes
  3937. * @num_qs: number of queues being configured
  3938. * @oldport: origination lport
  3939. * @newport: destination lport
  3940. * @cd: pointer to command details structure or NULL
  3941. *
  3942. * Move/Configure LAN Tx queue (0x0C32)
  3943. *
  3944. * There is a better AQ command to use for moving nodes, so only coding
  3945. * this one for configuring the node.
  3946. */
  3947. int
  3948. ice_aq_cfg_lan_txq(struct ice_hw *hw, struct ice_aqc_cfg_txqs_buf *buf,
  3949. u16 buf_size, u16 num_qs, u8 oldport, u8 newport,
  3950. struct ice_sq_cd *cd)
  3951. {
  3952. struct ice_aqc_cfg_txqs *cmd;
  3953. struct ice_aq_desc desc;
  3954. int status;
  3955. cmd = &desc.params.cfg_txqs;
  3956. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_cfg_txqs);
  3957. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  3958. if (!buf)
  3959. return -EINVAL;
  3960. cmd->cmd_type = ICE_AQC_Q_CFG_TC_CHNG;
  3961. cmd->num_qs = num_qs;
  3962. cmd->port_num_chng = (oldport & ICE_AQC_Q_CFG_SRC_PRT_M);
  3963. cmd->port_num_chng |= FIELD_PREP(ICE_AQC_Q_CFG_DST_PRT_M, newport);
  3964. cmd->time_out = FIELD_PREP(ICE_AQC_Q_CFG_TIMEOUT_M, 5);
  3965. cmd->blocked_cgds = 0;
  3966. status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  3967. if (status)
  3968. ice_debug(hw, ICE_DBG_SCHED, "Failed to reconfigure nodes %d\n",
  3969. hw->adminq.sq_last_status);
  3970. return status;
  3971. }
  3972. /**
  3973. * ice_aq_add_rdma_qsets
  3974. * @hw: pointer to the hardware structure
  3975. * @num_qset_grps: Number of RDMA Qset groups
  3976. * @qset_list: list of Qset groups to be added
  3977. * @buf_size: size of buffer for indirect command
  3978. * @cd: pointer to command details structure or NULL
  3979. *
  3980. * Add Tx RDMA Qsets (0x0C33)
  3981. */
  3982. static int
  3983. ice_aq_add_rdma_qsets(struct ice_hw *hw, u8 num_qset_grps,
  3984. struct ice_aqc_add_rdma_qset_data *qset_list,
  3985. u16 buf_size, struct ice_sq_cd *cd)
  3986. {
  3987. struct ice_aqc_add_rdma_qset_data *list;
  3988. struct ice_aqc_add_rdma_qset *cmd;
  3989. struct ice_aq_desc desc;
  3990. u16 i, sum_size = 0;
  3991. cmd = &desc.params.add_rdma_qset;
  3992. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_rdma_qset);
  3993. if (num_qset_grps > ICE_LAN_TXQ_MAX_QGRPS)
  3994. return -EINVAL;
  3995. for (i = 0, list = qset_list; i < num_qset_grps; i++) {
  3996. u16 num_qsets = le16_to_cpu(list->num_qsets);
  3997. sum_size += struct_size(list, rdma_qsets, num_qsets);
  3998. list = (struct ice_aqc_add_rdma_qset_data *)(list->rdma_qsets +
  3999. num_qsets);
  4000. }
  4001. if (buf_size != sum_size)
  4002. return -EINVAL;
  4003. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  4004. cmd->num_qset_grps = num_qset_grps;
  4005. return ice_aq_send_cmd(hw, &desc, qset_list, buf_size, cd);
  4006. }
  4007. /* End of FW Admin Queue command wrappers */
  4008. /**
  4009. * ice_pack_ctx_byte - write a byte to a packed context structure
  4010. * @src_ctx: unpacked source context structure
  4011. * @dest_ctx: packed destination context data
  4012. * @ce_info: context element description
  4013. */
  4014. static void ice_pack_ctx_byte(u8 *src_ctx, u8 *dest_ctx,
  4015. const struct ice_ctx_ele *ce_info)
  4016. {
  4017. u8 src_byte, dest_byte, mask;
  4018. u8 *from, *dest;
  4019. u16 shift_width;
  4020. /* copy from the next struct field */
  4021. from = src_ctx + ce_info->offset;
  4022. /* prepare the bits and mask */
  4023. shift_width = ce_info->lsb % 8;
  4024. mask = GENMASK(ce_info->width - 1 + shift_width, shift_width);
  4025. src_byte = *from;
  4026. src_byte <<= shift_width;
  4027. src_byte &= mask;
  4028. /* get the current bits from the target bit string */
  4029. dest = dest_ctx + (ce_info->lsb / 8);
  4030. memcpy(&dest_byte, dest, sizeof(dest_byte));
  4031. dest_byte &= ~mask; /* get the bits not changing */
  4032. dest_byte |= src_byte; /* add in the new bits */
  4033. /* put it all back */
  4034. memcpy(dest, &dest_byte, sizeof(dest_byte));
  4035. }
  4036. /**
  4037. * ice_pack_ctx_word - write a word to a packed context structure
  4038. * @src_ctx: unpacked source context structure
  4039. * @dest_ctx: packed destination context data
  4040. * @ce_info: context element description
  4041. */
  4042. static void ice_pack_ctx_word(u8 *src_ctx, u8 *dest_ctx,
  4043. const struct ice_ctx_ele *ce_info)
  4044. {
  4045. u16 src_word, mask;
  4046. __le16 dest_word;
  4047. u8 *from, *dest;
  4048. u16 shift_width;
  4049. /* copy from the next struct field */
  4050. from = src_ctx + ce_info->offset;
  4051. /* prepare the bits and mask */
  4052. shift_width = ce_info->lsb % 8;
  4053. mask = GENMASK(ce_info->width - 1 + shift_width, shift_width);
  4054. /* don't swizzle the bits until after the mask because the mask bits
  4055. * will be in a different bit position on big endian machines
  4056. */
  4057. src_word = *(u16 *)from;
  4058. src_word <<= shift_width;
  4059. src_word &= mask;
  4060. /* get the current bits from the target bit string */
  4061. dest = dest_ctx + (ce_info->lsb / 8);
  4062. memcpy(&dest_word, dest, sizeof(dest_word));
  4063. dest_word &= ~(cpu_to_le16(mask)); /* get the bits not changing */
  4064. dest_word |= cpu_to_le16(src_word); /* add in the new bits */
  4065. /* put it all back */
  4066. memcpy(dest, &dest_word, sizeof(dest_word));
  4067. }
  4068. /**
  4069. * ice_pack_ctx_dword - write a dword to a packed context structure
  4070. * @src_ctx: unpacked source context structure
  4071. * @dest_ctx: packed destination context data
  4072. * @ce_info: context element description
  4073. */
  4074. static void ice_pack_ctx_dword(u8 *src_ctx, u8 *dest_ctx,
  4075. const struct ice_ctx_ele *ce_info)
  4076. {
  4077. u32 src_dword, mask;
  4078. __le32 dest_dword;
  4079. u8 *from, *dest;
  4080. u16 shift_width;
  4081. /* copy from the next struct field */
  4082. from = src_ctx + ce_info->offset;
  4083. /* prepare the bits and mask */
  4084. shift_width = ce_info->lsb % 8;
  4085. mask = GENMASK(ce_info->width - 1 + shift_width, shift_width);
  4086. /* don't swizzle the bits until after the mask because the mask bits
  4087. * will be in a different bit position on big endian machines
  4088. */
  4089. src_dword = *(u32 *)from;
  4090. src_dword <<= shift_width;
  4091. src_dword &= mask;
  4092. /* get the current bits from the target bit string */
  4093. dest = dest_ctx + (ce_info->lsb / 8);
  4094. memcpy(&dest_dword, dest, sizeof(dest_dword));
  4095. dest_dword &= ~(cpu_to_le32(mask)); /* get the bits not changing */
  4096. dest_dword |= cpu_to_le32(src_dword); /* add in the new bits */
  4097. /* put it all back */
  4098. memcpy(dest, &dest_dword, sizeof(dest_dword));
  4099. }
  4100. /**
  4101. * ice_pack_ctx_qword - write a qword to a packed context structure
  4102. * @src_ctx: unpacked source context structure
  4103. * @dest_ctx: packed destination context data
  4104. * @ce_info: context element description
  4105. */
  4106. static void ice_pack_ctx_qword(u8 *src_ctx, u8 *dest_ctx,
  4107. const struct ice_ctx_ele *ce_info)
  4108. {
  4109. u64 src_qword, mask;
  4110. __le64 dest_qword;
  4111. u8 *from, *dest;
  4112. u16 shift_width;
  4113. /* copy from the next struct field */
  4114. from = src_ctx + ce_info->offset;
  4115. /* prepare the bits and mask */
  4116. shift_width = ce_info->lsb % 8;
  4117. mask = GENMASK_ULL(ce_info->width - 1 + shift_width, shift_width);
  4118. /* don't swizzle the bits until after the mask because the mask bits
  4119. * will be in a different bit position on big endian machines
  4120. */
  4121. src_qword = *(u64 *)from;
  4122. src_qword <<= shift_width;
  4123. src_qword &= mask;
  4124. /* get the current bits from the target bit string */
  4125. dest = dest_ctx + (ce_info->lsb / 8);
  4126. memcpy(&dest_qword, dest, sizeof(dest_qword));
  4127. dest_qword &= ~(cpu_to_le64(mask)); /* get the bits not changing */
  4128. dest_qword |= cpu_to_le64(src_qword); /* add in the new bits */
  4129. /* put it all back */
  4130. memcpy(dest, &dest_qword, sizeof(dest_qword));
  4131. }
  4132. /**
  4133. * ice_set_ctx - set context bits in packed structure
  4134. * @hw: pointer to the hardware structure
  4135. * @src_ctx: pointer to a generic non-packed context structure
  4136. * @dest_ctx: pointer to memory for the packed structure
  4137. * @ce_info: List of Rx context elements
  4138. */
  4139. int ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,
  4140. const struct ice_ctx_ele *ce_info)
  4141. {
  4142. int f;
  4143. for (f = 0; ce_info[f].width; f++) {
  4144. /* We have to deal with each element of the FW response
  4145. * using the correct size so that we are correct regardless
  4146. * of the endianness of the machine.
  4147. */
  4148. if (ce_info[f].width > (ce_info[f].size_of * BITS_PER_BYTE)) {
  4149. ice_debug(hw, ICE_DBG_QCTX, "Field %d width of %d bits larger than size of %d byte(s) ... skipping write\n",
  4150. f, ce_info[f].width, ce_info[f].size_of);
  4151. continue;
  4152. }
  4153. switch (ce_info[f].size_of) {
  4154. case sizeof(u8):
  4155. ice_pack_ctx_byte(src_ctx, dest_ctx, &ce_info[f]);
  4156. break;
  4157. case sizeof(u16):
  4158. ice_pack_ctx_word(src_ctx, dest_ctx, &ce_info[f]);
  4159. break;
  4160. case sizeof(u32):
  4161. ice_pack_ctx_dword(src_ctx, dest_ctx, &ce_info[f]);
  4162. break;
  4163. case sizeof(u64):
  4164. ice_pack_ctx_qword(src_ctx, dest_ctx, &ce_info[f]);
  4165. break;
  4166. default:
  4167. return -EINVAL;
  4168. }
  4169. }
  4170. return 0;
  4171. }
  4172. /**
  4173. * ice_get_lan_q_ctx - get the LAN queue context for the given VSI and TC
  4174. * @hw: pointer to the HW struct
  4175. * @vsi_handle: software VSI handle
  4176. * @tc: TC number
  4177. * @q_handle: software queue handle
  4178. */
  4179. struct ice_q_ctx *
  4180. ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle)
  4181. {
  4182. struct ice_vsi_ctx *vsi;
  4183. struct ice_q_ctx *q_ctx;
  4184. vsi = ice_get_vsi_ctx(hw, vsi_handle);
  4185. if (!vsi)
  4186. return NULL;
  4187. if (q_handle >= vsi->num_lan_q_entries[tc])
  4188. return NULL;
  4189. if (!vsi->lan_q_ctx[tc])
  4190. return NULL;
  4191. q_ctx = vsi->lan_q_ctx[tc];
  4192. return &q_ctx[q_handle];
  4193. }
  4194. /**
  4195. * ice_ena_vsi_txq
  4196. * @pi: port information structure
  4197. * @vsi_handle: software VSI handle
  4198. * @tc: TC number
  4199. * @q_handle: software queue handle
  4200. * @num_qgrps: Number of added queue groups
  4201. * @buf: list of queue groups to be added
  4202. * @buf_size: size of buffer for indirect command
  4203. * @cd: pointer to command details structure or NULL
  4204. *
  4205. * This function adds one LAN queue
  4206. */
  4207. int
  4208. ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 q_handle,
  4209. u8 num_qgrps, struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
  4210. struct ice_sq_cd *cd)
  4211. {
  4212. struct ice_aqc_txsched_elem_data node = { 0 };
  4213. struct ice_sched_node *parent;
  4214. struct ice_q_ctx *q_ctx;
  4215. struct ice_hw *hw;
  4216. int status;
  4217. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  4218. return -EIO;
  4219. if (num_qgrps > 1 || buf->num_txqs > 1)
  4220. return -ENOSPC;
  4221. hw = pi->hw;
  4222. if (!ice_is_vsi_valid(hw, vsi_handle))
  4223. return -EINVAL;
  4224. mutex_lock(&pi->sched_lock);
  4225. q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handle);
  4226. if (!q_ctx) {
  4227. ice_debug(hw, ICE_DBG_SCHED, "Enaq: invalid queue handle %d\n",
  4228. q_handle);
  4229. status = -EINVAL;
  4230. goto ena_txq_exit;
  4231. }
  4232. /* find a parent node */
  4233. parent = ice_sched_get_free_qparent(pi, vsi_handle, tc,
  4234. ICE_SCHED_NODE_OWNER_LAN);
  4235. if (!parent) {
  4236. status = -EINVAL;
  4237. goto ena_txq_exit;
  4238. }
  4239. buf->parent_teid = parent->info.node_teid;
  4240. node.parent_teid = parent->info.node_teid;
  4241. /* Mark that the values in the "generic" section as valid. The default
  4242. * value in the "generic" section is zero. This means that :
  4243. * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
  4244. * - 0 priority among siblings, indicated by Bit 1-3.
  4245. * - WFQ, indicated by Bit 4.
  4246. * - 0 Adjustment value is used in PSM credit update flow, indicated by
  4247. * Bit 5-6.
  4248. * - Bit 7 is reserved.
  4249. * Without setting the generic section as valid in valid_sections, the
  4250. * Admin queue command will fail with error code ICE_AQ_RC_EINVAL.
  4251. */
  4252. buf->txqs[0].info.valid_sections =
  4253. ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
  4254. ICE_AQC_ELEM_VALID_EIR;
  4255. buf->txqs[0].info.generic = 0;
  4256. buf->txqs[0].info.cir_bw.bw_profile_idx =
  4257. cpu_to_le16(ICE_SCHED_DFLT_RL_PROF_ID);
  4258. buf->txqs[0].info.cir_bw.bw_alloc =
  4259. cpu_to_le16(ICE_SCHED_DFLT_BW_WT);
  4260. buf->txqs[0].info.eir_bw.bw_profile_idx =
  4261. cpu_to_le16(ICE_SCHED_DFLT_RL_PROF_ID);
  4262. buf->txqs[0].info.eir_bw.bw_alloc =
  4263. cpu_to_le16(ICE_SCHED_DFLT_BW_WT);
  4264. /* add the LAN queue */
  4265. status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd);
  4266. if (status) {
  4267. ice_debug(hw, ICE_DBG_SCHED, "enable queue %d failed %d\n",
  4268. le16_to_cpu(buf->txqs[0].txq_id),
  4269. hw->adminq.sq_last_status);
  4270. goto ena_txq_exit;
  4271. }
  4272. node.node_teid = buf->txqs[0].q_teid;
  4273. node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
  4274. q_ctx->q_handle = q_handle;
  4275. q_ctx->q_teid = le32_to_cpu(node.node_teid);
  4276. /* add a leaf node into scheduler tree queue layer */
  4277. status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node, NULL);
  4278. if (!status)
  4279. status = ice_sched_replay_q_bw(pi, q_ctx);
  4280. ena_txq_exit:
  4281. mutex_unlock(&pi->sched_lock);
  4282. return status;
  4283. }
  4284. /**
  4285. * ice_dis_vsi_txq
  4286. * @pi: port information structure
  4287. * @vsi_handle: software VSI handle
  4288. * @tc: TC number
  4289. * @num_queues: number of queues
  4290. * @q_handles: pointer to software queue handle array
  4291. * @q_ids: pointer to the q_id array
  4292. * @q_teids: pointer to queue node teids
  4293. * @rst_src: if called due to reset, specifies the reset source
  4294. * @vmvf_num: the relative VM or VF number that is undergoing the reset
  4295. * @cd: pointer to command details structure or NULL
  4296. *
  4297. * This function removes queues and their corresponding nodes in SW DB
  4298. */
  4299. int
  4300. ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
  4301. u16 *q_handles, u16 *q_ids, u32 *q_teids,
  4302. enum ice_disq_rst_src rst_src, u16 vmvf_num,
  4303. struct ice_sq_cd *cd)
  4304. {
  4305. DEFINE_RAW_FLEX(struct ice_aqc_dis_txq_item, qg_list, q_id, 1);
  4306. u16 i, buf_size = __struct_size(qg_list);
  4307. struct ice_q_ctx *q_ctx;
  4308. int status = -ENOENT;
  4309. struct ice_hw *hw;
  4310. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  4311. return -EIO;
  4312. hw = pi->hw;
  4313. if (!num_queues) {
  4314. /* if queue is disabled already yet the disable queue command
  4315. * has to be sent to complete the VF reset, then call
  4316. * ice_aq_dis_lan_txq without any queue information
  4317. */
  4318. if (rst_src)
  4319. return ice_aq_dis_lan_txq(hw, 0, NULL, 0, rst_src,
  4320. vmvf_num, NULL);
  4321. return -EIO;
  4322. }
  4323. mutex_lock(&pi->sched_lock);
  4324. for (i = 0; i < num_queues; i++) {
  4325. struct ice_sched_node *node;
  4326. node = ice_sched_find_node_by_teid(pi->root, q_teids[i]);
  4327. if (!node)
  4328. continue;
  4329. q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handles[i]);
  4330. if (!q_ctx) {
  4331. ice_debug(hw, ICE_DBG_SCHED, "invalid queue handle%d\n",
  4332. q_handles[i]);
  4333. continue;
  4334. }
  4335. if (q_ctx->q_handle != q_handles[i]) {
  4336. ice_debug(hw, ICE_DBG_SCHED, "Err:handles %d %d\n",
  4337. q_ctx->q_handle, q_handles[i]);
  4338. continue;
  4339. }
  4340. qg_list->parent_teid = node->info.parent_teid;
  4341. qg_list->num_qs = 1;
  4342. qg_list->q_id[0] = cpu_to_le16(q_ids[i]);
  4343. status = ice_aq_dis_lan_txq(hw, 1, qg_list, buf_size, rst_src,
  4344. vmvf_num, cd);
  4345. if (status)
  4346. break;
  4347. ice_free_sched_node(pi, node);
  4348. q_ctx->q_handle = ICE_INVAL_Q_HANDLE;
  4349. q_ctx->q_teid = ICE_INVAL_TEID;
  4350. }
  4351. mutex_unlock(&pi->sched_lock);
  4352. return status;
  4353. }
  4354. /**
  4355. * ice_cfg_vsi_qs - configure the new/existing VSI queues
  4356. * @pi: port information structure
  4357. * @vsi_handle: software VSI handle
  4358. * @tc_bitmap: TC bitmap
  4359. * @maxqs: max queues array per TC
  4360. * @owner: LAN or RDMA
  4361. *
  4362. * This function adds/updates the VSI queues per TC.
  4363. */
  4364. static int
  4365. ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_handle, u8 tc_bitmap,
  4366. u16 *maxqs, u8 owner)
  4367. {
  4368. int status = 0;
  4369. u8 i;
  4370. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  4371. return -EIO;
  4372. if (!ice_is_vsi_valid(pi->hw, vsi_handle))
  4373. return -EINVAL;
  4374. mutex_lock(&pi->sched_lock);
  4375. ice_for_each_traffic_class(i) {
  4376. /* configuration is possible only if TC node is present */
  4377. if (!ice_sched_get_tc_node(pi, i))
  4378. continue;
  4379. status = ice_sched_cfg_vsi(pi, vsi_handle, i, maxqs[i], owner,
  4380. ice_is_tc_ena(tc_bitmap, i));
  4381. if (status)
  4382. break;
  4383. }
  4384. mutex_unlock(&pi->sched_lock);
  4385. return status;
  4386. }
  4387. /**
  4388. * ice_cfg_vsi_lan - configure VSI LAN queues
  4389. * @pi: port information structure
  4390. * @vsi_handle: software VSI handle
  4391. * @tc_bitmap: TC bitmap
  4392. * @max_lanqs: max LAN queues array per TC
  4393. *
  4394. * This function adds/updates the VSI LAN queues per TC.
  4395. */
  4396. int
  4397. ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u8 tc_bitmap,
  4398. u16 *max_lanqs)
  4399. {
  4400. return ice_cfg_vsi_qs(pi, vsi_handle, tc_bitmap, max_lanqs,
  4401. ICE_SCHED_NODE_OWNER_LAN);
  4402. }
  4403. /**
  4404. * ice_cfg_vsi_rdma - configure the VSI RDMA queues
  4405. * @pi: port information structure
  4406. * @vsi_handle: software VSI handle
  4407. * @tc_bitmap: TC bitmap
  4408. * @max_rdmaqs: max RDMA queues array per TC
  4409. *
  4410. * This function adds/updates the VSI RDMA queues per TC.
  4411. */
  4412. int
  4413. ice_cfg_vsi_rdma(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
  4414. u16 *max_rdmaqs)
  4415. {
  4416. return ice_cfg_vsi_qs(pi, vsi_handle, tc_bitmap, max_rdmaqs,
  4417. ICE_SCHED_NODE_OWNER_RDMA);
  4418. }
  4419. /**
  4420. * ice_ena_vsi_rdma_qset
  4421. * @pi: port information structure
  4422. * @vsi_handle: software VSI handle
  4423. * @tc: TC number
  4424. * @rdma_qset: pointer to RDMA Qset
  4425. * @num_qsets: number of RDMA Qsets
  4426. * @qset_teid: pointer to Qset node TEIDs
  4427. *
  4428. * This function adds RDMA Qset
  4429. */
  4430. int
  4431. ice_ena_vsi_rdma_qset(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
  4432. u16 *rdma_qset, u16 num_qsets, u32 *qset_teid)
  4433. {
  4434. struct ice_aqc_txsched_elem_data node = { 0 };
  4435. struct ice_aqc_add_rdma_qset_data *buf;
  4436. struct ice_sched_node *parent;
  4437. struct ice_hw *hw;
  4438. u16 i, buf_size;
  4439. int ret;
  4440. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  4441. return -EIO;
  4442. hw = pi->hw;
  4443. if (!ice_is_vsi_valid(hw, vsi_handle))
  4444. return -EINVAL;
  4445. buf_size = struct_size(buf, rdma_qsets, num_qsets);
  4446. buf = kzalloc(buf_size, GFP_KERNEL);
  4447. if (!buf)
  4448. return -ENOMEM;
  4449. mutex_lock(&pi->sched_lock);
  4450. parent = ice_sched_get_free_qparent(pi, vsi_handle, tc,
  4451. ICE_SCHED_NODE_OWNER_RDMA);
  4452. if (!parent) {
  4453. ret = -EINVAL;
  4454. goto rdma_error_exit;
  4455. }
  4456. buf->parent_teid = parent->info.node_teid;
  4457. node.parent_teid = parent->info.node_teid;
  4458. buf->num_qsets = cpu_to_le16(num_qsets);
  4459. for (i = 0; i < num_qsets; i++) {
  4460. buf->rdma_qsets[i].tx_qset_id = cpu_to_le16(rdma_qset[i]);
  4461. buf->rdma_qsets[i].info.valid_sections =
  4462. ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
  4463. ICE_AQC_ELEM_VALID_EIR;
  4464. buf->rdma_qsets[i].info.generic = 0;
  4465. buf->rdma_qsets[i].info.cir_bw.bw_profile_idx =
  4466. cpu_to_le16(ICE_SCHED_DFLT_RL_PROF_ID);
  4467. buf->rdma_qsets[i].info.cir_bw.bw_alloc =
  4468. cpu_to_le16(ICE_SCHED_DFLT_BW_WT);
  4469. buf->rdma_qsets[i].info.eir_bw.bw_profile_idx =
  4470. cpu_to_le16(ICE_SCHED_DFLT_RL_PROF_ID);
  4471. buf->rdma_qsets[i].info.eir_bw.bw_alloc =
  4472. cpu_to_le16(ICE_SCHED_DFLT_BW_WT);
  4473. }
  4474. ret = ice_aq_add_rdma_qsets(hw, 1, buf, buf_size, NULL);
  4475. if (ret) {
  4476. ice_debug(hw, ICE_DBG_RDMA, "add RDMA qset failed\n");
  4477. goto rdma_error_exit;
  4478. }
  4479. node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
  4480. for (i = 0; i < num_qsets; i++) {
  4481. node.node_teid = buf->rdma_qsets[i].qset_teid;
  4482. ret = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1,
  4483. &node, NULL);
  4484. if (ret)
  4485. break;
  4486. qset_teid[i] = le32_to_cpu(node.node_teid);
  4487. }
  4488. rdma_error_exit:
  4489. mutex_unlock(&pi->sched_lock);
  4490. kfree(buf);
  4491. return ret;
  4492. }
  4493. /**
  4494. * ice_dis_vsi_rdma_qset - free RDMA resources
  4495. * @pi: port_info struct
  4496. * @count: number of RDMA Qsets to free
  4497. * @qset_teid: TEID of Qset node
  4498. * @q_id: list of queue IDs being disabled
  4499. */
  4500. int
  4501. ice_dis_vsi_rdma_qset(struct ice_port_info *pi, u16 count, u32 *qset_teid,
  4502. u16 *q_id)
  4503. {
  4504. DEFINE_RAW_FLEX(struct ice_aqc_dis_txq_item, qg_list, q_id, 1);
  4505. u16 qg_size = __struct_size(qg_list);
  4506. struct ice_hw *hw;
  4507. int status = 0;
  4508. int i;
  4509. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  4510. return -EIO;
  4511. hw = pi->hw;
  4512. mutex_lock(&pi->sched_lock);
  4513. for (i = 0; i < count; i++) {
  4514. struct ice_sched_node *node;
  4515. node = ice_sched_find_node_by_teid(pi->root, qset_teid[i]);
  4516. if (!node)
  4517. continue;
  4518. qg_list->parent_teid = node->info.parent_teid;
  4519. qg_list->num_qs = 1;
  4520. qg_list->q_id[0] =
  4521. cpu_to_le16(q_id[i] |
  4522. ICE_AQC_Q_DIS_BUF_ELEM_TYPE_RDMA_QSET);
  4523. status = ice_aq_dis_lan_txq(hw, 1, qg_list, qg_size,
  4524. ICE_NO_RESET, 0, NULL);
  4525. if (status)
  4526. break;
  4527. ice_free_sched_node(pi, node);
  4528. }
  4529. mutex_unlock(&pi->sched_lock);
  4530. return status;
  4531. }
  4532. /**
  4533. * ice_aq_get_cgu_abilities - get cgu abilities
  4534. * @hw: pointer to the HW struct
  4535. * @abilities: CGU abilities
  4536. *
  4537. * Get CGU abilities (0x0C61)
  4538. * Return: 0 on success or negative value on failure.
  4539. */
  4540. int
  4541. ice_aq_get_cgu_abilities(struct ice_hw *hw,
  4542. struct ice_aqc_get_cgu_abilities *abilities)
  4543. {
  4544. struct ice_aq_desc desc;
  4545. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cgu_abilities);
  4546. return ice_aq_send_cmd(hw, &desc, abilities, sizeof(*abilities), NULL);
  4547. }
  4548. /**
  4549. * ice_aq_set_input_pin_cfg - set input pin config
  4550. * @hw: pointer to the HW struct
  4551. * @input_idx: Input index
  4552. * @flags1: Input flags
  4553. * @flags2: Input flags
  4554. * @freq: Frequency in Hz
  4555. * @phase_delay: Delay in ps
  4556. *
  4557. * Set CGU input config (0x0C62)
  4558. * Return: 0 on success or negative value on failure.
  4559. */
  4560. int
  4561. ice_aq_set_input_pin_cfg(struct ice_hw *hw, u8 input_idx, u8 flags1, u8 flags2,
  4562. u32 freq, s32 phase_delay)
  4563. {
  4564. struct ice_aqc_set_cgu_input_config *cmd;
  4565. struct ice_aq_desc desc;
  4566. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_cgu_input_config);
  4567. cmd = &desc.params.set_cgu_input_config;
  4568. cmd->input_idx = input_idx;
  4569. cmd->flags1 = flags1;
  4570. cmd->flags2 = flags2;
  4571. cmd->freq = cpu_to_le32(freq);
  4572. cmd->phase_delay = cpu_to_le32(phase_delay);
  4573. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4574. }
  4575. /**
  4576. * ice_aq_get_input_pin_cfg - get input pin config
  4577. * @hw: pointer to the HW struct
  4578. * @input_idx: Input index
  4579. * @status: Pin status
  4580. * @type: Pin type
  4581. * @flags1: Input flags
  4582. * @flags2: Input flags
  4583. * @freq: Frequency in Hz
  4584. * @phase_delay: Delay in ps
  4585. *
  4586. * Get CGU input config (0x0C63)
  4587. * Return: 0 on success or negative value on failure.
  4588. */
  4589. int
  4590. ice_aq_get_input_pin_cfg(struct ice_hw *hw, u8 input_idx, u8 *status, u8 *type,
  4591. u8 *flags1, u8 *flags2, u32 *freq, s32 *phase_delay)
  4592. {
  4593. struct ice_aqc_get_cgu_input_config *cmd;
  4594. struct ice_aq_desc desc;
  4595. int ret;
  4596. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cgu_input_config);
  4597. cmd = &desc.params.get_cgu_input_config;
  4598. cmd->input_idx = input_idx;
  4599. ret = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4600. if (!ret) {
  4601. if (status)
  4602. *status = cmd->status;
  4603. if (type)
  4604. *type = cmd->type;
  4605. if (flags1)
  4606. *flags1 = cmd->flags1;
  4607. if (flags2)
  4608. *flags2 = cmd->flags2;
  4609. if (freq)
  4610. *freq = le32_to_cpu(cmd->freq);
  4611. if (phase_delay)
  4612. *phase_delay = le32_to_cpu(cmd->phase_delay);
  4613. }
  4614. return ret;
  4615. }
  4616. /**
  4617. * ice_aq_set_output_pin_cfg - set output pin config
  4618. * @hw: pointer to the HW struct
  4619. * @output_idx: Output index
  4620. * @flags: Output flags
  4621. * @src_sel: Index of DPLL block
  4622. * @freq: Output frequency
  4623. * @phase_delay: Output phase compensation
  4624. *
  4625. * Set CGU output config (0x0C64)
  4626. * Return: 0 on success or negative value on failure.
  4627. */
  4628. int
  4629. ice_aq_set_output_pin_cfg(struct ice_hw *hw, u8 output_idx, u8 flags,
  4630. u8 src_sel, u32 freq, s32 phase_delay)
  4631. {
  4632. struct ice_aqc_set_cgu_output_config *cmd;
  4633. struct ice_aq_desc desc;
  4634. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_cgu_output_config);
  4635. cmd = &desc.params.set_cgu_output_config;
  4636. cmd->output_idx = output_idx;
  4637. cmd->flags = flags;
  4638. cmd->src_sel = src_sel;
  4639. cmd->freq = cpu_to_le32(freq);
  4640. cmd->phase_delay = cpu_to_le32(phase_delay);
  4641. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4642. }
  4643. /**
  4644. * ice_aq_get_output_pin_cfg - get output pin config
  4645. * @hw: pointer to the HW struct
  4646. * @output_idx: Output index
  4647. * @flags: Output flags
  4648. * @src_sel: Internal DPLL source
  4649. * @freq: Output frequency
  4650. * @src_freq: Source frequency
  4651. *
  4652. * Get CGU output config (0x0C65)
  4653. * Return: 0 on success or negative value on failure.
  4654. */
  4655. int
  4656. ice_aq_get_output_pin_cfg(struct ice_hw *hw, u8 output_idx, u8 *flags,
  4657. u8 *src_sel, u32 *freq, u32 *src_freq)
  4658. {
  4659. struct ice_aqc_get_cgu_output_config *cmd;
  4660. struct ice_aq_desc desc;
  4661. int ret;
  4662. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cgu_output_config);
  4663. cmd = &desc.params.get_cgu_output_config;
  4664. cmd->output_idx = output_idx;
  4665. ret = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4666. if (!ret) {
  4667. if (flags)
  4668. *flags = cmd->flags;
  4669. if (src_sel)
  4670. *src_sel = cmd->src_sel;
  4671. if (freq)
  4672. *freq = le32_to_cpu(cmd->freq);
  4673. if (src_freq)
  4674. *src_freq = le32_to_cpu(cmd->src_freq);
  4675. }
  4676. return ret;
  4677. }
  4678. /**
  4679. * ice_aq_get_cgu_dpll_status - get dpll status
  4680. * @hw: pointer to the HW struct
  4681. * @dpll_num: DPLL index
  4682. * @ref_state: Reference clock state
  4683. * @config: current DPLL config
  4684. * @dpll_state: current DPLL state
  4685. * @phase_offset: Phase offset in ns
  4686. * @eec_mode: EEC_mode
  4687. *
  4688. * Get CGU DPLL status (0x0C66)
  4689. * Return: 0 on success or negative value on failure.
  4690. */
  4691. int
  4692. ice_aq_get_cgu_dpll_status(struct ice_hw *hw, u8 dpll_num, u8 *ref_state,
  4693. u8 *dpll_state, u8 *config, s64 *phase_offset,
  4694. u8 *eec_mode)
  4695. {
  4696. struct ice_aqc_get_cgu_dpll_status *cmd;
  4697. struct ice_aq_desc desc;
  4698. int status;
  4699. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cgu_dpll_status);
  4700. cmd = &desc.params.get_cgu_dpll_status;
  4701. cmd->dpll_num = dpll_num;
  4702. status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4703. if (!status) {
  4704. *ref_state = cmd->ref_state;
  4705. *dpll_state = cmd->dpll_state;
  4706. *config = cmd->config;
  4707. *phase_offset = le32_to_cpu(cmd->phase_offset_h);
  4708. *phase_offset <<= 32;
  4709. *phase_offset += le32_to_cpu(cmd->phase_offset_l);
  4710. *phase_offset = sign_extend64(*phase_offset, 47);
  4711. *eec_mode = cmd->eec_mode;
  4712. }
  4713. return status;
  4714. }
  4715. /**
  4716. * ice_aq_set_cgu_dpll_config - set dpll config
  4717. * @hw: pointer to the HW struct
  4718. * @dpll_num: DPLL index
  4719. * @ref_state: Reference clock state
  4720. * @config: DPLL config
  4721. * @eec_mode: EEC mode
  4722. *
  4723. * Set CGU DPLL config (0x0C67)
  4724. * Return: 0 on success or negative value on failure.
  4725. */
  4726. int
  4727. ice_aq_set_cgu_dpll_config(struct ice_hw *hw, u8 dpll_num, u8 ref_state,
  4728. u8 config, u8 eec_mode)
  4729. {
  4730. struct ice_aqc_set_cgu_dpll_config *cmd;
  4731. struct ice_aq_desc desc;
  4732. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_cgu_dpll_config);
  4733. cmd = &desc.params.set_cgu_dpll_config;
  4734. cmd->dpll_num = dpll_num;
  4735. cmd->ref_state = ref_state;
  4736. cmd->config = config;
  4737. cmd->eec_mode = eec_mode;
  4738. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4739. }
  4740. /**
  4741. * ice_aq_set_cgu_ref_prio - set input reference priority
  4742. * @hw: pointer to the HW struct
  4743. * @dpll_num: DPLL index
  4744. * @ref_idx: Reference pin index
  4745. * @ref_priority: Reference input priority
  4746. *
  4747. * Set CGU reference priority (0x0C68)
  4748. * Return: 0 on success or negative value on failure.
  4749. */
  4750. int
  4751. ice_aq_set_cgu_ref_prio(struct ice_hw *hw, u8 dpll_num, u8 ref_idx,
  4752. u8 ref_priority)
  4753. {
  4754. struct ice_aqc_set_cgu_ref_prio *cmd;
  4755. struct ice_aq_desc desc;
  4756. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_cgu_ref_prio);
  4757. cmd = &desc.params.set_cgu_ref_prio;
  4758. cmd->dpll_num = dpll_num;
  4759. cmd->ref_idx = ref_idx;
  4760. cmd->ref_priority = ref_priority;
  4761. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4762. }
  4763. /**
  4764. * ice_aq_get_cgu_ref_prio - get input reference priority
  4765. * @hw: pointer to the HW struct
  4766. * @dpll_num: DPLL index
  4767. * @ref_idx: Reference pin index
  4768. * @ref_prio: Reference input priority
  4769. *
  4770. * Get CGU reference priority (0x0C69)
  4771. * Return: 0 on success or negative value on failure.
  4772. */
  4773. int
  4774. ice_aq_get_cgu_ref_prio(struct ice_hw *hw, u8 dpll_num, u8 ref_idx,
  4775. u8 *ref_prio)
  4776. {
  4777. struct ice_aqc_get_cgu_ref_prio *cmd;
  4778. struct ice_aq_desc desc;
  4779. int status;
  4780. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cgu_ref_prio);
  4781. cmd = &desc.params.get_cgu_ref_prio;
  4782. cmd->dpll_num = dpll_num;
  4783. cmd->ref_idx = ref_idx;
  4784. status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4785. if (!status)
  4786. *ref_prio = cmd->ref_priority;
  4787. return status;
  4788. }
  4789. /**
  4790. * ice_aq_get_cgu_info - get cgu info
  4791. * @hw: pointer to the HW struct
  4792. * @cgu_id: CGU ID
  4793. * @cgu_cfg_ver: CGU config version
  4794. * @cgu_fw_ver: CGU firmware version
  4795. *
  4796. * Get CGU info (0x0C6A)
  4797. * Return: 0 on success or negative value on failure.
  4798. */
  4799. int
  4800. ice_aq_get_cgu_info(struct ice_hw *hw, u32 *cgu_id, u32 *cgu_cfg_ver,
  4801. u32 *cgu_fw_ver)
  4802. {
  4803. struct ice_aqc_get_cgu_info *cmd;
  4804. struct ice_aq_desc desc;
  4805. int status;
  4806. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cgu_info);
  4807. cmd = &desc.params.get_cgu_info;
  4808. status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4809. if (!status) {
  4810. *cgu_id = le32_to_cpu(cmd->cgu_id);
  4811. *cgu_cfg_ver = le32_to_cpu(cmd->cgu_cfg_ver);
  4812. *cgu_fw_ver = le32_to_cpu(cmd->cgu_fw_ver);
  4813. }
  4814. return status;
  4815. }
  4816. /**
  4817. * ice_aq_set_phy_rec_clk_out - set RCLK phy out
  4818. * @hw: pointer to the HW struct
  4819. * @phy_output: PHY reference clock output pin
  4820. * @enable: GPIO state to be applied
  4821. * @freq: PHY output frequency
  4822. *
  4823. * Set phy recovered clock as reference (0x0630)
  4824. * Return: 0 on success or negative value on failure.
  4825. */
  4826. int
  4827. ice_aq_set_phy_rec_clk_out(struct ice_hw *hw, u8 phy_output, bool enable,
  4828. u32 *freq)
  4829. {
  4830. struct ice_aqc_set_phy_rec_clk_out *cmd;
  4831. struct ice_aq_desc desc;
  4832. int status;
  4833. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_rec_clk_out);
  4834. cmd = &desc.params.set_phy_rec_clk_out;
  4835. cmd->phy_output = phy_output;
  4836. cmd->port_num = ICE_AQC_SET_PHY_REC_CLK_OUT_CURR_PORT;
  4837. cmd->flags = enable & ICE_AQC_SET_PHY_REC_CLK_OUT_OUT_EN;
  4838. cmd->freq = cpu_to_le32(*freq);
  4839. status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4840. if (!status)
  4841. *freq = le32_to_cpu(cmd->freq);
  4842. return status;
  4843. }
  4844. /**
  4845. * ice_aq_get_phy_rec_clk_out - get phy recovered signal info
  4846. * @hw: pointer to the HW struct
  4847. * @phy_output: PHY reference clock output pin
  4848. * @port_num: Port number
  4849. * @flags: PHY flags
  4850. * @node_handle: PHY output frequency
  4851. *
  4852. * Get PHY recovered clock output info (0x0631)
  4853. * Return: 0 on success or negative value on failure.
  4854. */
  4855. int
  4856. ice_aq_get_phy_rec_clk_out(struct ice_hw *hw, u8 *phy_output, u8 *port_num,
  4857. u8 *flags, u16 *node_handle)
  4858. {
  4859. struct ice_aqc_get_phy_rec_clk_out *cmd;
  4860. struct ice_aq_desc desc;
  4861. int status;
  4862. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_rec_clk_out);
  4863. cmd = &desc.params.get_phy_rec_clk_out;
  4864. cmd->phy_output = *phy_output;
  4865. status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4866. if (!status) {
  4867. *phy_output = cmd->phy_output;
  4868. if (port_num)
  4869. *port_num = cmd->port_num;
  4870. if (flags)
  4871. *flags = cmd->flags;
  4872. if (node_handle)
  4873. *node_handle = le16_to_cpu(cmd->node_handle);
  4874. }
  4875. return status;
  4876. }
  4877. /**
  4878. * ice_aq_get_sensor_reading
  4879. * @hw: pointer to the HW struct
  4880. * @data: pointer to data to be read from the sensor
  4881. *
  4882. * Get sensor reading (0x0632)
  4883. */
  4884. int ice_aq_get_sensor_reading(struct ice_hw *hw,
  4885. struct ice_aqc_get_sensor_reading_resp *data)
  4886. {
  4887. struct ice_aqc_get_sensor_reading *cmd;
  4888. struct ice_aq_desc desc;
  4889. int status;
  4890. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_sensor_reading);
  4891. cmd = &desc.params.get_sensor_reading;
  4892. #define ICE_INTERNAL_TEMP_SENSOR_FORMAT 0
  4893. #define ICE_INTERNAL_TEMP_SENSOR 0
  4894. cmd->sensor = ICE_INTERNAL_TEMP_SENSOR;
  4895. cmd->format = ICE_INTERNAL_TEMP_SENSOR_FORMAT;
  4896. status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  4897. if (!status)
  4898. memcpy(data, &desc.params.get_sensor_reading_resp,
  4899. sizeof(*data));
  4900. return status;
  4901. }
  4902. /**
  4903. * ice_replay_pre_init - replay pre initialization
  4904. * @hw: pointer to the HW struct
  4905. *
  4906. * Initializes required config data for VSI, FD, ACL, and RSS before replay.
  4907. */
  4908. static int ice_replay_pre_init(struct ice_hw *hw)
  4909. {
  4910. struct ice_switch_info *sw = hw->switch_info;
  4911. u8 i;
  4912. /* Delete old entries from replay filter list head if there is any */
  4913. ice_rm_all_sw_replay_rule_info(hw);
  4914. /* In start of replay, move entries into replay_rules list, it
  4915. * will allow adding rules entries back to filt_rules list,
  4916. * which is operational list.
  4917. */
  4918. for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
  4919. list_replace_init(&sw->recp_list[i].filt_rules,
  4920. &sw->recp_list[i].filt_replay_rules);
  4921. ice_sched_replay_agg_vsi_preinit(hw);
  4922. return 0;
  4923. }
  4924. /**
  4925. * ice_replay_vsi - replay VSI configuration
  4926. * @hw: pointer to the HW struct
  4927. * @vsi_handle: driver VSI handle
  4928. *
  4929. * Restore all VSI configuration after reset. It is required to call this
  4930. * function with main VSI first.
  4931. */
  4932. int ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle)
  4933. {
  4934. int status;
  4935. if (!ice_is_vsi_valid(hw, vsi_handle))
  4936. return -EINVAL;
  4937. /* Replay pre-initialization if there is any */
  4938. if (vsi_handle == ICE_MAIN_VSI_HANDLE) {
  4939. status = ice_replay_pre_init(hw);
  4940. if (status)
  4941. return status;
  4942. }
  4943. /* Replay per VSI all RSS configurations */
  4944. status = ice_replay_rss_cfg(hw, vsi_handle);
  4945. if (status)
  4946. return status;
  4947. /* Replay per VSI all filters */
  4948. status = ice_replay_vsi_all_fltr(hw, vsi_handle);
  4949. if (!status)
  4950. status = ice_replay_vsi_agg(hw, vsi_handle);
  4951. return status;
  4952. }
  4953. /**
  4954. * ice_replay_post - post replay configuration cleanup
  4955. * @hw: pointer to the HW struct
  4956. *
  4957. * Post replay cleanup.
  4958. */
  4959. void ice_replay_post(struct ice_hw *hw)
  4960. {
  4961. /* Delete old entries from replay filter list head */
  4962. ice_rm_all_sw_replay_rule_info(hw);
  4963. ice_sched_replay_agg(hw);
  4964. }
  4965. /**
  4966. * ice_stat_update40 - read 40 bit stat from the chip and update stat values
  4967. * @hw: ptr to the hardware info
  4968. * @reg: offset of 64 bit HW register to read from
  4969. * @prev_stat_loaded: bool to specify if previous stats are loaded
  4970. * @prev_stat: ptr to previous loaded stat value
  4971. * @cur_stat: ptr to current stat value
  4972. */
  4973. void
  4974. ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
  4975. u64 *prev_stat, u64 *cur_stat)
  4976. {
  4977. u64 new_data = rd64(hw, reg) & (BIT_ULL(40) - 1);
  4978. /* device stats are not reset at PFR, they likely will not be zeroed
  4979. * when the driver starts. Thus, save the value from the first read
  4980. * without adding to the statistic value so that we report stats which
  4981. * count up from zero.
  4982. */
  4983. if (!prev_stat_loaded) {
  4984. *prev_stat = new_data;
  4985. return;
  4986. }
  4987. /* Calculate the difference between the new and old values, and then
  4988. * add it to the software stat value.
  4989. */
  4990. if (new_data >= *prev_stat)
  4991. *cur_stat += new_data - *prev_stat;
  4992. else
  4993. /* to manage the potential roll-over */
  4994. *cur_stat += (new_data + BIT_ULL(40)) - *prev_stat;
  4995. /* Update the previously stored value to prepare for next read */
  4996. *prev_stat = new_data;
  4997. }
  4998. /**
  4999. * ice_stat_update32 - read 32 bit stat from the chip and update stat values
  5000. * @hw: ptr to the hardware info
  5001. * @reg: offset of HW register to read from
  5002. * @prev_stat_loaded: bool to specify if previous stats are loaded
  5003. * @prev_stat: ptr to previous loaded stat value
  5004. * @cur_stat: ptr to current stat value
  5005. */
  5006. void
  5007. ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
  5008. u64 *prev_stat, u64 *cur_stat)
  5009. {
  5010. u32 new_data;
  5011. new_data = rd32(hw, reg);
  5012. /* device stats are not reset at PFR, they likely will not be zeroed
  5013. * when the driver starts. Thus, save the value from the first read
  5014. * without adding to the statistic value so that we report stats which
  5015. * count up from zero.
  5016. */
  5017. if (!prev_stat_loaded) {
  5018. *prev_stat = new_data;
  5019. return;
  5020. }
  5021. /* Calculate the difference between the new and old values, and then
  5022. * add it to the software stat value.
  5023. */
  5024. if (new_data >= *prev_stat)
  5025. *cur_stat += new_data - *prev_stat;
  5026. else
  5027. /* to manage the potential roll-over */
  5028. *cur_stat += (new_data + BIT_ULL(32)) - *prev_stat;
  5029. /* Update the previously stored value to prepare for next read */
  5030. *prev_stat = new_data;
  5031. }
  5032. /**
  5033. * ice_sched_query_elem - query element information from HW
  5034. * @hw: pointer to the HW struct
  5035. * @node_teid: node TEID to be queried
  5036. * @buf: buffer to element information
  5037. *
  5038. * This function queries HW element information
  5039. */
  5040. int
  5041. ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
  5042. struct ice_aqc_txsched_elem_data *buf)
  5043. {
  5044. u16 buf_size, num_elem_ret = 0;
  5045. int status;
  5046. buf_size = sizeof(*buf);
  5047. memset(buf, 0, buf_size);
  5048. buf->node_teid = cpu_to_le32(node_teid);
  5049. status = ice_aq_query_sched_elems(hw, 1, buf, buf_size, &num_elem_ret,
  5050. NULL);
  5051. if (status || num_elem_ret != 1)
  5052. ice_debug(hw, ICE_DBG_SCHED, "query element failed\n");
  5053. return status;
  5054. }
  5055. /**
  5056. * ice_aq_read_i2c
  5057. * @hw: pointer to the hw struct
  5058. * @topo_addr: topology address for a device to communicate with
  5059. * @bus_addr: 7-bit I2C bus address
  5060. * @addr: I2C memory address (I2C offset) with up to 16 bits
  5061. * @params: I2C parameters: bit [7] - Repeated start,
  5062. * bits [6:5] data offset size,
  5063. * bit [4] - I2C address type,
  5064. * bits [3:0] - data size to read (0-16 bytes)
  5065. * @data: pointer to data (0 to 16 bytes) to be read from the I2C device
  5066. * @cd: pointer to command details structure or NULL
  5067. *
  5068. * Read I2C (0x06E2)
  5069. */
  5070. int
  5071. ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
  5072. u16 bus_addr, __le16 addr, u8 params, u8 *data,
  5073. struct ice_sq_cd *cd)
  5074. {
  5075. struct ice_aq_desc desc = { 0 };
  5076. struct ice_aqc_i2c *cmd;
  5077. u8 data_size;
  5078. int status;
  5079. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_read_i2c);
  5080. cmd = &desc.params.read_write_i2c;
  5081. if (!data)
  5082. return -EINVAL;
  5083. data_size = FIELD_GET(ICE_AQC_I2C_DATA_SIZE_M, params);
  5084. cmd->i2c_bus_addr = cpu_to_le16(bus_addr);
  5085. cmd->topo_addr = topo_addr;
  5086. cmd->i2c_params = params;
  5087. cmd->i2c_addr = addr;
  5088. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  5089. if (!status) {
  5090. struct ice_aqc_read_i2c_resp *resp;
  5091. u8 i;
  5092. resp = &desc.params.read_i2c_resp;
  5093. for (i = 0; i < data_size; i++) {
  5094. *data = resp->i2c_data[i];
  5095. data++;
  5096. }
  5097. }
  5098. return status;
  5099. }
  5100. /**
  5101. * ice_aq_write_i2c
  5102. * @hw: pointer to the hw struct
  5103. * @topo_addr: topology address for a device to communicate with
  5104. * @bus_addr: 7-bit I2C bus address
  5105. * @addr: I2C memory address (I2C offset) with up to 16 bits
  5106. * @params: I2C parameters: bit [4] - I2C address type, bits [3:0] - data size to write (0-7 bytes)
  5107. * @data: pointer to data (0 to 4 bytes) to be written to the I2C device
  5108. * @cd: pointer to command details structure or NULL
  5109. *
  5110. * Write I2C (0x06E3)
  5111. *
  5112. * * Return:
  5113. * * 0 - Successful write to the i2c device
  5114. * * -EINVAL - Data size greater than 4 bytes
  5115. * * -EIO - FW error
  5116. */
  5117. int
  5118. ice_aq_write_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
  5119. u16 bus_addr, __le16 addr, u8 params, const u8 *data,
  5120. struct ice_sq_cd *cd)
  5121. {
  5122. struct ice_aq_desc desc = { 0 };
  5123. struct ice_aqc_i2c *cmd;
  5124. u8 data_size;
  5125. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_write_i2c);
  5126. cmd = &desc.params.read_write_i2c;
  5127. data_size = FIELD_GET(ICE_AQC_I2C_DATA_SIZE_M, params);
  5128. /* data_size limited to 4 */
  5129. if (data_size > 4)
  5130. return -EINVAL;
  5131. cmd->i2c_bus_addr = cpu_to_le16(bus_addr);
  5132. cmd->topo_addr = topo_addr;
  5133. cmd->i2c_params = params;
  5134. cmd->i2c_addr = addr;
  5135. memcpy(cmd->i2c_data, data, data_size);
  5136. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  5137. }
  5138. /**
  5139. * ice_aq_set_gpio
  5140. * @hw: pointer to the hw struct
  5141. * @gpio_ctrl_handle: GPIO controller node handle
  5142. * @pin_idx: IO Number of the GPIO that needs to be set
  5143. * @value: SW provide IO value to set in the LSB
  5144. * @cd: pointer to command details structure or NULL
  5145. *
  5146. * Sends 0x06EC AQ command to set the GPIO pin state that's part of the topology
  5147. */
  5148. int
  5149. ice_aq_set_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx, bool value,
  5150. struct ice_sq_cd *cd)
  5151. {
  5152. struct ice_aqc_gpio *cmd;
  5153. struct ice_aq_desc desc;
  5154. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_gpio);
  5155. cmd = &desc.params.read_write_gpio;
  5156. cmd->gpio_ctrl_handle = cpu_to_le16(gpio_ctrl_handle);
  5157. cmd->gpio_num = pin_idx;
  5158. cmd->gpio_val = value ? 1 : 0;
  5159. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  5160. }
  5161. /**
  5162. * ice_aq_get_gpio
  5163. * @hw: pointer to the hw struct
  5164. * @gpio_ctrl_handle: GPIO controller node handle
  5165. * @pin_idx: IO Number of the GPIO that needs to be set
  5166. * @value: IO value read
  5167. * @cd: pointer to command details structure or NULL
  5168. *
  5169. * Sends 0x06ED AQ command to get the value of a GPIO signal which is part of
  5170. * the topology
  5171. */
  5172. int
  5173. ice_aq_get_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx,
  5174. bool *value, struct ice_sq_cd *cd)
  5175. {
  5176. struct ice_aqc_gpio *cmd;
  5177. struct ice_aq_desc desc;
  5178. int status;
  5179. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_gpio);
  5180. cmd = &desc.params.read_write_gpio;
  5181. cmd->gpio_ctrl_handle = cpu_to_le16(gpio_ctrl_handle);
  5182. cmd->gpio_num = pin_idx;
  5183. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  5184. if (status)
  5185. return status;
  5186. *value = !!cmd->gpio_val;
  5187. return 0;
  5188. }
  5189. /**
  5190. * ice_is_fw_api_min_ver
  5191. * @hw: pointer to the hardware structure
  5192. * @maj: major version
  5193. * @min: minor version
  5194. * @patch: patch version
  5195. *
  5196. * Checks if the firmware API is minimum version
  5197. */
  5198. static bool ice_is_fw_api_min_ver(struct ice_hw *hw, u8 maj, u8 min, u8 patch)
  5199. {
  5200. if (hw->api_maj_ver == maj) {
  5201. if (hw->api_min_ver > min)
  5202. return true;
  5203. if (hw->api_min_ver == min && hw->api_patch >= patch)
  5204. return true;
  5205. } else if (hw->api_maj_ver > maj) {
  5206. return true;
  5207. }
  5208. return false;
  5209. }
  5210. /**
  5211. * ice_fw_supports_link_override
  5212. * @hw: pointer to the hardware structure
  5213. *
  5214. * Checks if the firmware supports link override
  5215. */
  5216. bool ice_fw_supports_link_override(struct ice_hw *hw)
  5217. {
  5218. return ice_is_fw_api_min_ver(hw, ICE_FW_API_LINK_OVERRIDE_MAJ,
  5219. ICE_FW_API_LINK_OVERRIDE_MIN,
  5220. ICE_FW_API_LINK_OVERRIDE_PATCH);
  5221. }
  5222. /**
  5223. * ice_get_link_default_override
  5224. * @ldo: pointer to the link default override struct
  5225. * @pi: pointer to the port info struct
  5226. *
  5227. * Gets the link default override for a port
  5228. */
  5229. int
  5230. ice_get_link_default_override(struct ice_link_default_override_tlv *ldo,
  5231. struct ice_port_info *pi)
  5232. {
  5233. u16 i, tlv, tlv_len, tlv_start, buf, offset;
  5234. struct ice_hw *hw = pi->hw;
  5235. int status;
  5236. status = ice_get_pfa_module_tlv(hw, &tlv, &tlv_len,
  5237. ICE_SR_LINK_DEFAULT_OVERRIDE_PTR);
  5238. if (status) {
  5239. ice_debug(hw, ICE_DBG_INIT, "Failed to read link override TLV.\n");
  5240. return status;
  5241. }
  5242. /* Each port has its own config; calculate for our port */
  5243. tlv_start = tlv + pi->lport * ICE_SR_PFA_LINK_OVERRIDE_WORDS +
  5244. ICE_SR_PFA_LINK_OVERRIDE_OFFSET;
  5245. /* link options first */
  5246. status = ice_read_sr_word(hw, tlv_start, &buf);
  5247. if (status) {
  5248. ice_debug(hw, ICE_DBG_INIT, "Failed to read override link options.\n");
  5249. return status;
  5250. }
  5251. ldo->options = FIELD_GET(ICE_LINK_OVERRIDE_OPT_M, buf);
  5252. ldo->phy_config = (buf & ICE_LINK_OVERRIDE_PHY_CFG_M) >>
  5253. ICE_LINK_OVERRIDE_PHY_CFG_S;
  5254. /* link PHY config */
  5255. offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_FEC_OFFSET;
  5256. status = ice_read_sr_word(hw, offset, &buf);
  5257. if (status) {
  5258. ice_debug(hw, ICE_DBG_INIT, "Failed to read override phy config.\n");
  5259. return status;
  5260. }
  5261. ldo->fec_options = buf & ICE_LINK_OVERRIDE_FEC_OPT_M;
  5262. /* PHY types low */
  5263. offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET;
  5264. for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
  5265. status = ice_read_sr_word(hw, (offset + i), &buf);
  5266. if (status) {
  5267. ice_debug(hw, ICE_DBG_INIT, "Failed to read override link options.\n");
  5268. return status;
  5269. }
  5270. /* shift 16 bits at a time to fill 64 bits */
  5271. ldo->phy_type_low |= ((u64)buf << (i * 16));
  5272. }
  5273. /* PHY types high */
  5274. offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET +
  5275. ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS;
  5276. for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
  5277. status = ice_read_sr_word(hw, (offset + i), &buf);
  5278. if (status) {
  5279. ice_debug(hw, ICE_DBG_INIT, "Failed to read override link options.\n");
  5280. return status;
  5281. }
  5282. /* shift 16 bits at a time to fill 64 bits */
  5283. ldo->phy_type_high |= ((u64)buf << (i * 16));
  5284. }
  5285. return status;
  5286. }
  5287. /**
  5288. * ice_is_phy_caps_an_enabled - check if PHY capabilities autoneg is enabled
  5289. * @caps: get PHY capability data
  5290. */
  5291. bool ice_is_phy_caps_an_enabled(struct ice_aqc_get_phy_caps_data *caps)
  5292. {
  5293. if (caps->caps & ICE_AQC_PHY_AN_MODE ||
  5294. caps->low_power_ctrl_an & (ICE_AQC_PHY_AN_EN_CLAUSE28 |
  5295. ICE_AQC_PHY_AN_EN_CLAUSE73 |
  5296. ICE_AQC_PHY_AN_EN_CLAUSE37))
  5297. return true;
  5298. return false;
  5299. }
  5300. /**
  5301. * ice_aq_set_lldp_mib - Set the LLDP MIB
  5302. * @hw: pointer to the HW struct
  5303. * @mib_type: Local, Remote or both Local and Remote MIBs
  5304. * @buf: pointer to the caller-supplied buffer to store the MIB block
  5305. * @buf_size: size of the buffer (in bytes)
  5306. * @cd: pointer to command details structure or NULL
  5307. *
  5308. * Set the LLDP MIB. (0x0A08)
  5309. */
  5310. int
  5311. ice_aq_set_lldp_mib(struct ice_hw *hw, u8 mib_type, void *buf, u16 buf_size,
  5312. struct ice_sq_cd *cd)
  5313. {
  5314. struct ice_aqc_lldp_set_local_mib *cmd;
  5315. struct ice_aq_desc desc;
  5316. cmd = &desc.params.lldp_set_mib;
  5317. if (buf_size == 0 || !buf)
  5318. return -EINVAL;
  5319. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_set_local_mib);
  5320. desc.flags |= cpu_to_le16((u16)ICE_AQ_FLAG_RD);
  5321. desc.datalen = cpu_to_le16(buf_size);
  5322. cmd->type = mib_type;
  5323. cmd->length = cpu_to_le16(buf_size);
  5324. return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  5325. }
  5326. /**
  5327. * ice_fw_supports_lldp_fltr_ctrl - check NVM version supports lldp_fltr_ctrl
  5328. * @hw: pointer to HW struct
  5329. */
  5330. bool ice_fw_supports_lldp_fltr_ctrl(struct ice_hw *hw)
  5331. {
  5332. if (hw->mac_type != ICE_MAC_E810)
  5333. return false;
  5334. return ice_is_fw_api_min_ver(hw, ICE_FW_API_LLDP_FLTR_MAJ,
  5335. ICE_FW_API_LLDP_FLTR_MIN,
  5336. ICE_FW_API_LLDP_FLTR_PATCH);
  5337. }
  5338. /**
  5339. * ice_lldp_fltr_add_remove - add or remove a LLDP Rx switch filter
  5340. * @hw: pointer to HW struct
  5341. * @vsi_num: absolute HW index for VSI
  5342. * @add: boolean for if adding or removing a filter
  5343. */
  5344. int
  5345. ice_lldp_fltr_add_remove(struct ice_hw *hw, u16 vsi_num, bool add)
  5346. {
  5347. struct ice_aqc_lldp_filter_ctrl *cmd;
  5348. struct ice_aq_desc desc;
  5349. cmd = &desc.params.lldp_filter_ctrl;
  5350. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_filter_ctrl);
  5351. if (add)
  5352. cmd->cmd_flags = ICE_AQC_LLDP_FILTER_ACTION_ADD;
  5353. else
  5354. cmd->cmd_flags = ICE_AQC_LLDP_FILTER_ACTION_DELETE;
  5355. cmd->vsi_num = cpu_to_le16(vsi_num);
  5356. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  5357. }
  5358. /**
  5359. * ice_lldp_execute_pending_mib - execute LLDP pending MIB request
  5360. * @hw: pointer to HW struct
  5361. */
  5362. int ice_lldp_execute_pending_mib(struct ice_hw *hw)
  5363. {
  5364. struct ice_aq_desc desc;
  5365. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_execute_pending_mib);
  5366. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  5367. }
  5368. /**
  5369. * ice_fw_supports_report_dflt_cfg
  5370. * @hw: pointer to the hardware structure
  5371. *
  5372. * Checks if the firmware supports report default configuration
  5373. */
  5374. bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw)
  5375. {
  5376. return ice_is_fw_api_min_ver(hw, ICE_FW_API_REPORT_DFLT_CFG_MAJ,
  5377. ICE_FW_API_REPORT_DFLT_CFG_MIN,
  5378. ICE_FW_API_REPORT_DFLT_CFG_PATCH);
  5379. }
  5380. /* each of the indexes into the following array match the speed of a return
  5381. * value from the list of AQ returned speeds like the range:
  5382. * ICE_AQ_LINK_SPEED_10MB .. ICE_AQ_LINK_SPEED_100GB excluding
  5383. * ICE_AQ_LINK_SPEED_UNKNOWN which is BIT(15) and maps to BIT(14) in this
  5384. * array. The array is defined as 15 elements long because the link_speed
  5385. * returned by the firmware is a 16 bit * value, but is indexed
  5386. * by [fls(speed) - 1]
  5387. */
  5388. static const u32 ice_aq_to_link_speed[] = {
  5389. SPEED_10, /* BIT(0) */
  5390. SPEED_100,
  5391. SPEED_1000,
  5392. SPEED_2500,
  5393. SPEED_5000,
  5394. SPEED_10000,
  5395. SPEED_20000,
  5396. SPEED_25000,
  5397. SPEED_40000,
  5398. SPEED_50000,
  5399. SPEED_100000, /* BIT(10) */
  5400. SPEED_200000,
  5401. };
  5402. /**
  5403. * ice_get_link_speed - get integer speed from table
  5404. * @index: array index from fls(aq speed) - 1
  5405. *
  5406. * Returns: u32 value containing integer speed
  5407. */
  5408. u32 ice_get_link_speed(u16 index)
  5409. {
  5410. if (index >= ARRAY_SIZE(ice_aq_to_link_speed))
  5411. return 0;
  5412. return ice_aq_to_link_speed[index];
  5413. }