i40e_common.c 141 KB

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