i40e_common.c 164 KB

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