i40e_common.c 147 KB

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