i40e_common.c 153 KB

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