i40e_common.c 119 KB

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