i40e_common.c 83 KB

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