i40e_common.c 106 KB

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