i40e_common.c 147 KB

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