i40e_common.c 120 KB

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