i40e_common.c 167 KB

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