i40e_common.c 102 KB

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