i40e_common.c 83 KB

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