i40e_common.c 120 KB

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