i40e_common.c 147 KB

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