i40e_common.c 167 KB

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