i40e_common.c 125 KB

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