i40e_common.c 137 KB

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