i40e_common.c 140 KB

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