cmd.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /*
  2. * drivers/net/ethernet/mellanox/mlxsw/cmd.h
  3. * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
  5. * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the names of the copyright holders nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * Alternatively, this software may be distributed under the terms of the
  20. * GNU General Public License ("GPL") version 2 as published by the Free
  21. * Software Foundation.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef _MLXSW_CMD_H
  36. #define _MLXSW_CMD_H
  37. #include "item.h"
  38. #define MLXSW_CMD_MBOX_SIZE 4096
  39. static inline char *mlxsw_cmd_mbox_alloc(void)
  40. {
  41. return kzalloc(MLXSW_CMD_MBOX_SIZE, GFP_KERNEL);
  42. }
  43. static inline void mlxsw_cmd_mbox_free(char *mbox)
  44. {
  45. kfree(mbox);
  46. }
  47. static inline void mlxsw_cmd_mbox_zero(char *mbox)
  48. {
  49. memset(mbox, 0, MLXSW_CMD_MBOX_SIZE);
  50. }
  51. struct mlxsw_core;
  52. int mlxsw_cmd_exec(struct mlxsw_core *mlxsw_core, u16 opcode, u8 opcode_mod,
  53. u32 in_mod, bool out_mbox_direct,
  54. char *in_mbox, size_t in_mbox_size,
  55. char *out_mbox, size_t out_mbox_size);
  56. static inline int mlxsw_cmd_exec_in(struct mlxsw_core *mlxsw_core, u16 opcode,
  57. u8 opcode_mod, u32 in_mod, char *in_mbox,
  58. size_t in_mbox_size)
  59. {
  60. return mlxsw_cmd_exec(mlxsw_core, opcode, opcode_mod, in_mod, false,
  61. in_mbox, in_mbox_size, NULL, 0);
  62. }
  63. static inline int mlxsw_cmd_exec_out(struct mlxsw_core *mlxsw_core, u16 opcode,
  64. u8 opcode_mod, u32 in_mod,
  65. bool out_mbox_direct,
  66. char *out_mbox, size_t out_mbox_size)
  67. {
  68. return mlxsw_cmd_exec(mlxsw_core, opcode, opcode_mod, in_mod,
  69. out_mbox_direct, NULL, 0,
  70. out_mbox, out_mbox_size);
  71. }
  72. static inline int mlxsw_cmd_exec_none(struct mlxsw_core *mlxsw_core, u16 opcode,
  73. u8 opcode_mod, u32 in_mod)
  74. {
  75. return mlxsw_cmd_exec(mlxsw_core, opcode, opcode_mod, in_mod, false,
  76. NULL, 0, NULL, 0);
  77. }
  78. enum mlxsw_cmd_opcode {
  79. MLXSW_CMD_OPCODE_QUERY_FW = 0x004,
  80. MLXSW_CMD_OPCODE_QUERY_BOARDINFO = 0x006,
  81. MLXSW_CMD_OPCODE_QUERY_AQ_CAP = 0x003,
  82. MLXSW_CMD_OPCODE_MAP_FA = 0xFFF,
  83. MLXSW_CMD_OPCODE_UNMAP_FA = 0xFFE,
  84. MLXSW_CMD_OPCODE_CONFIG_PROFILE = 0x100,
  85. MLXSW_CMD_OPCODE_ACCESS_REG = 0x040,
  86. MLXSW_CMD_OPCODE_SW2HW_DQ = 0x201,
  87. MLXSW_CMD_OPCODE_HW2SW_DQ = 0x202,
  88. MLXSW_CMD_OPCODE_2ERR_DQ = 0x01E,
  89. MLXSW_CMD_OPCODE_QUERY_DQ = 0x022,
  90. MLXSW_CMD_OPCODE_SW2HW_CQ = 0x016,
  91. MLXSW_CMD_OPCODE_HW2SW_CQ = 0x017,
  92. MLXSW_CMD_OPCODE_QUERY_CQ = 0x018,
  93. MLXSW_CMD_OPCODE_SW2HW_EQ = 0x013,
  94. MLXSW_CMD_OPCODE_HW2SW_EQ = 0x014,
  95. MLXSW_CMD_OPCODE_QUERY_EQ = 0x015,
  96. MLXSW_CMD_OPCODE_QUERY_RESOURCES = 0x101,
  97. };
  98. static inline const char *mlxsw_cmd_opcode_str(u16 opcode)
  99. {
  100. switch (opcode) {
  101. case MLXSW_CMD_OPCODE_QUERY_FW:
  102. return "QUERY_FW";
  103. case MLXSW_CMD_OPCODE_QUERY_BOARDINFO:
  104. return "QUERY_BOARDINFO";
  105. case MLXSW_CMD_OPCODE_QUERY_AQ_CAP:
  106. return "QUERY_AQ_CAP";
  107. case MLXSW_CMD_OPCODE_MAP_FA:
  108. return "MAP_FA";
  109. case MLXSW_CMD_OPCODE_UNMAP_FA:
  110. return "UNMAP_FA";
  111. case MLXSW_CMD_OPCODE_CONFIG_PROFILE:
  112. return "CONFIG_PROFILE";
  113. case MLXSW_CMD_OPCODE_ACCESS_REG:
  114. return "ACCESS_REG";
  115. case MLXSW_CMD_OPCODE_SW2HW_DQ:
  116. return "SW2HW_DQ";
  117. case MLXSW_CMD_OPCODE_HW2SW_DQ:
  118. return "HW2SW_DQ";
  119. case MLXSW_CMD_OPCODE_2ERR_DQ:
  120. return "2ERR_DQ";
  121. case MLXSW_CMD_OPCODE_QUERY_DQ:
  122. return "QUERY_DQ";
  123. case MLXSW_CMD_OPCODE_SW2HW_CQ:
  124. return "SW2HW_CQ";
  125. case MLXSW_CMD_OPCODE_HW2SW_CQ:
  126. return "HW2SW_CQ";
  127. case MLXSW_CMD_OPCODE_QUERY_CQ:
  128. return "QUERY_CQ";
  129. case MLXSW_CMD_OPCODE_SW2HW_EQ:
  130. return "SW2HW_EQ";
  131. case MLXSW_CMD_OPCODE_HW2SW_EQ:
  132. return "HW2SW_EQ";
  133. case MLXSW_CMD_OPCODE_QUERY_EQ:
  134. return "QUERY_EQ";
  135. case MLXSW_CMD_OPCODE_QUERY_RESOURCES:
  136. return "QUERY_RESOURCES";
  137. default:
  138. return "*UNKNOWN*";
  139. }
  140. }
  141. enum mlxsw_cmd_status {
  142. /* Command execution succeeded. */
  143. MLXSW_CMD_STATUS_OK = 0x00,
  144. /* Internal error (e.g. bus error) occurred while processing command. */
  145. MLXSW_CMD_STATUS_INTERNAL_ERR = 0x01,
  146. /* Operation/command not supported or opcode modifier not supported. */
  147. MLXSW_CMD_STATUS_BAD_OP = 0x02,
  148. /* Parameter not supported, parameter out of range. */
  149. MLXSW_CMD_STATUS_BAD_PARAM = 0x03,
  150. /* System was not enabled or bad system state. */
  151. MLXSW_CMD_STATUS_BAD_SYS_STATE = 0x04,
  152. /* Attempt to access reserved or unallocated resource, or resource in
  153. * inappropriate ownership.
  154. */
  155. MLXSW_CMD_STATUS_BAD_RESOURCE = 0x05,
  156. /* Requested resource is currently executing a command. */
  157. MLXSW_CMD_STATUS_RESOURCE_BUSY = 0x06,
  158. /* Required capability exceeds device limits. */
  159. MLXSW_CMD_STATUS_EXCEED_LIM = 0x08,
  160. /* Resource is not in the appropriate state or ownership. */
  161. MLXSW_CMD_STATUS_BAD_RES_STATE = 0x09,
  162. /* Index out of range (might be beyond table size or attempt to
  163. * access a reserved resource).
  164. */
  165. MLXSW_CMD_STATUS_BAD_INDEX = 0x0A,
  166. /* NVMEM checksum/CRC failed. */
  167. MLXSW_CMD_STATUS_BAD_NVMEM = 0x0B,
  168. /* Bad management packet (silently discarded). */
  169. MLXSW_CMD_STATUS_BAD_PKT = 0x30,
  170. };
  171. static inline const char *mlxsw_cmd_status_str(u8 status)
  172. {
  173. switch (status) {
  174. case MLXSW_CMD_STATUS_OK:
  175. return "OK";
  176. case MLXSW_CMD_STATUS_INTERNAL_ERR:
  177. return "INTERNAL_ERR";
  178. case MLXSW_CMD_STATUS_BAD_OP:
  179. return "BAD_OP";
  180. case MLXSW_CMD_STATUS_BAD_PARAM:
  181. return "BAD_PARAM";
  182. case MLXSW_CMD_STATUS_BAD_SYS_STATE:
  183. return "BAD_SYS_STATE";
  184. case MLXSW_CMD_STATUS_BAD_RESOURCE:
  185. return "BAD_RESOURCE";
  186. case MLXSW_CMD_STATUS_RESOURCE_BUSY:
  187. return "RESOURCE_BUSY";
  188. case MLXSW_CMD_STATUS_EXCEED_LIM:
  189. return "EXCEED_LIM";
  190. case MLXSW_CMD_STATUS_BAD_RES_STATE:
  191. return "BAD_RES_STATE";
  192. case MLXSW_CMD_STATUS_BAD_INDEX:
  193. return "BAD_INDEX";
  194. case MLXSW_CMD_STATUS_BAD_NVMEM:
  195. return "BAD_NVMEM";
  196. case MLXSW_CMD_STATUS_BAD_PKT:
  197. return "BAD_PKT";
  198. default:
  199. return "*UNKNOWN*";
  200. }
  201. }
  202. /* QUERY_FW - Query Firmware
  203. * -------------------------
  204. * OpMod == 0, INMmod == 0
  205. * -----------------------
  206. * The QUERY_FW command retrieves information related to firmware, command
  207. * interface version and the amount of resources that should be allocated to
  208. * the firmware.
  209. */
  210. static inline int mlxsw_cmd_query_fw(struct mlxsw_core *mlxsw_core,
  211. char *out_mbox)
  212. {
  213. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_FW,
  214. 0, 0, false, out_mbox, MLXSW_CMD_MBOX_SIZE);
  215. }
  216. /* cmd_mbox_query_fw_fw_pages
  217. * Amount of physical memory to be allocatedfor firmware usage in 4KB pages.
  218. */
  219. MLXSW_ITEM32(cmd_mbox, query_fw, fw_pages, 0x00, 16, 16);
  220. /* cmd_mbox_query_fw_fw_rev_major
  221. * Firmware Revision - Major
  222. */
  223. MLXSW_ITEM32(cmd_mbox, query_fw, fw_rev_major, 0x00, 0, 16);
  224. /* cmd_mbox_query_fw_fw_rev_subminor
  225. * Firmware Sub-minor version (Patch level)
  226. */
  227. MLXSW_ITEM32(cmd_mbox, query_fw, fw_rev_subminor, 0x04, 16, 16);
  228. /* cmd_mbox_query_fw_fw_rev_minor
  229. * Firmware Revision - Minor
  230. */
  231. MLXSW_ITEM32(cmd_mbox, query_fw, fw_rev_minor, 0x04, 0, 16);
  232. /* cmd_mbox_query_fw_core_clk
  233. * Internal Clock Frequency (in MHz)
  234. */
  235. MLXSW_ITEM32(cmd_mbox, query_fw, core_clk, 0x08, 16, 16);
  236. /* cmd_mbox_query_fw_cmd_interface_rev
  237. * Command Interface Interpreter Revision ID. This number is bumped up
  238. * every time a non-backward-compatible change is done for the command
  239. * interface. The current cmd_interface_rev is 1.
  240. */
  241. MLXSW_ITEM32(cmd_mbox, query_fw, cmd_interface_rev, 0x08, 0, 16);
  242. /* cmd_mbox_query_fw_dt
  243. * If set, Debug Trace is supported
  244. */
  245. MLXSW_ITEM32(cmd_mbox, query_fw, dt, 0x0C, 31, 1);
  246. /* cmd_mbox_query_fw_api_version
  247. * Indicates the version of the API, to enable software querying
  248. * for compatibility. The current api_version is 1.
  249. */
  250. MLXSW_ITEM32(cmd_mbox, query_fw, api_version, 0x0C, 0, 16);
  251. /* cmd_mbox_query_fw_fw_hour
  252. * Firmware timestamp - hour
  253. */
  254. MLXSW_ITEM32(cmd_mbox, query_fw, fw_hour, 0x10, 24, 8);
  255. /* cmd_mbox_query_fw_fw_minutes
  256. * Firmware timestamp - minutes
  257. */
  258. MLXSW_ITEM32(cmd_mbox, query_fw, fw_minutes, 0x10, 16, 8);
  259. /* cmd_mbox_query_fw_fw_seconds
  260. * Firmware timestamp - seconds
  261. */
  262. MLXSW_ITEM32(cmd_mbox, query_fw, fw_seconds, 0x10, 8, 8);
  263. /* cmd_mbox_query_fw_fw_year
  264. * Firmware timestamp - year
  265. */
  266. MLXSW_ITEM32(cmd_mbox, query_fw, fw_year, 0x14, 16, 16);
  267. /* cmd_mbox_query_fw_fw_month
  268. * Firmware timestamp - month
  269. */
  270. MLXSW_ITEM32(cmd_mbox, query_fw, fw_month, 0x14, 8, 8);
  271. /* cmd_mbox_query_fw_fw_day
  272. * Firmware timestamp - day
  273. */
  274. MLXSW_ITEM32(cmd_mbox, query_fw, fw_day, 0x14, 0, 8);
  275. /* cmd_mbox_query_fw_clr_int_base_offset
  276. * Clear Interrupt register's offset from clr_int_bar register
  277. * in PCI address space.
  278. */
  279. MLXSW_ITEM64(cmd_mbox, query_fw, clr_int_base_offset, 0x20, 0, 64);
  280. /* cmd_mbox_query_fw_clr_int_bar
  281. * PCI base address register (BAR) where clr_int register is located.
  282. * 00 - BAR 0-1 (64 bit BAR)
  283. */
  284. MLXSW_ITEM32(cmd_mbox, query_fw, clr_int_bar, 0x28, 30, 2);
  285. /* cmd_mbox_query_fw_error_buf_offset
  286. * Read Only buffer for internal error reports of offset
  287. * from error_buf_bar register in PCI address space).
  288. */
  289. MLXSW_ITEM64(cmd_mbox, query_fw, error_buf_offset, 0x30, 0, 64);
  290. /* cmd_mbox_query_fw_error_buf_size
  291. * Internal error buffer size in DWORDs
  292. */
  293. MLXSW_ITEM32(cmd_mbox, query_fw, error_buf_size, 0x38, 0, 32);
  294. /* cmd_mbox_query_fw_error_int_bar
  295. * PCI base address register (BAR) where error buffer
  296. * register is located.
  297. * 00 - BAR 0-1 (64 bit BAR)
  298. */
  299. MLXSW_ITEM32(cmd_mbox, query_fw, error_int_bar, 0x3C, 30, 2);
  300. /* cmd_mbox_query_fw_doorbell_page_offset
  301. * Offset of the doorbell page
  302. */
  303. MLXSW_ITEM64(cmd_mbox, query_fw, doorbell_page_offset, 0x40, 0, 64);
  304. /* cmd_mbox_query_fw_doorbell_page_bar
  305. * PCI base address register (BAR) of the doorbell page
  306. * 00 - BAR 0-1 (64 bit BAR)
  307. */
  308. MLXSW_ITEM32(cmd_mbox, query_fw, doorbell_page_bar, 0x48, 30, 2);
  309. /* QUERY_BOARDINFO - Query Board Information
  310. * -----------------------------------------
  311. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  312. * -----------------------------------
  313. * The QUERY_BOARDINFO command retrieves adapter specific parameters.
  314. */
  315. static inline int mlxsw_cmd_boardinfo(struct mlxsw_core *mlxsw_core,
  316. char *out_mbox)
  317. {
  318. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_BOARDINFO,
  319. 0, 0, false, out_mbox, MLXSW_CMD_MBOX_SIZE);
  320. }
  321. /* cmd_mbox_boardinfo_intapin
  322. * When PCIe interrupt messages are being used, this value is used for clearing
  323. * an interrupt. When using MSI-X, this register is not used.
  324. */
  325. MLXSW_ITEM32(cmd_mbox, boardinfo, intapin, 0x10, 24, 8);
  326. /* cmd_mbox_boardinfo_vsd_vendor_id
  327. * PCISIG Vendor ID (www.pcisig.com/membership/vid_search) of the vendor
  328. * specifying/formatting the VSD. The vsd_vendor_id identifies the management
  329. * domain of the VSD/PSID data. Different vendors may choose different VSD/PSID
  330. * format and encoding as long as they use their assigned vsd_vendor_id.
  331. */
  332. MLXSW_ITEM32(cmd_mbox, boardinfo, vsd_vendor_id, 0x1C, 0, 16);
  333. /* cmd_mbox_boardinfo_vsd
  334. * Vendor Specific Data. The VSD string that is burnt to the Flash
  335. * with the firmware.
  336. */
  337. #define MLXSW_CMD_BOARDINFO_VSD_LEN 208
  338. MLXSW_ITEM_BUF(cmd_mbox, boardinfo, vsd, 0x20, MLXSW_CMD_BOARDINFO_VSD_LEN);
  339. /* cmd_mbox_boardinfo_psid
  340. * The PSID field is a 16-ascii (byte) character string which acts as
  341. * the board ID. The PSID format is used in conjunction with
  342. * Mellanox vsd_vendor_id (15B3h).
  343. */
  344. #define MLXSW_CMD_BOARDINFO_PSID_LEN 16
  345. MLXSW_ITEM_BUF(cmd_mbox, boardinfo, psid, 0xF0, MLXSW_CMD_BOARDINFO_PSID_LEN);
  346. /* QUERY_AQ_CAP - Query Asynchronous Queues Capabilities
  347. * -----------------------------------------------------
  348. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  349. * -----------------------------------
  350. * The QUERY_AQ_CAP command returns the device asynchronous queues
  351. * capabilities supported.
  352. */
  353. static inline int mlxsw_cmd_query_aq_cap(struct mlxsw_core *mlxsw_core,
  354. char *out_mbox)
  355. {
  356. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_AQ_CAP,
  357. 0, 0, false, out_mbox, MLXSW_CMD_MBOX_SIZE);
  358. }
  359. /* cmd_mbox_query_aq_cap_log_max_sdq_sz
  360. * Log (base 2) of max WQEs allowed on SDQ.
  361. */
  362. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_sdq_sz, 0x00, 24, 8);
  363. /* cmd_mbox_query_aq_cap_max_num_sdqs
  364. * Maximum number of SDQs.
  365. */
  366. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_sdqs, 0x00, 0, 8);
  367. /* cmd_mbox_query_aq_cap_log_max_rdq_sz
  368. * Log (base 2) of max WQEs allowed on RDQ.
  369. */
  370. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_rdq_sz, 0x04, 24, 8);
  371. /* cmd_mbox_query_aq_cap_max_num_rdqs
  372. * Maximum number of RDQs.
  373. */
  374. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_rdqs, 0x04, 0, 8);
  375. /* cmd_mbox_query_aq_cap_log_max_cq_sz
  376. * Log (base 2) of max CQEs allowed on CQ.
  377. */
  378. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_cq_sz, 0x08, 24, 8);
  379. /* cmd_mbox_query_aq_cap_max_num_cqs
  380. * Maximum number of CQs.
  381. */
  382. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_cqs, 0x08, 0, 8);
  383. /* cmd_mbox_query_aq_cap_log_max_eq_sz
  384. * Log (base 2) of max EQEs allowed on EQ.
  385. */
  386. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_eq_sz, 0x0C, 24, 8);
  387. /* cmd_mbox_query_aq_cap_max_num_eqs
  388. * Maximum number of EQs.
  389. */
  390. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_eqs, 0x0C, 0, 8);
  391. /* cmd_mbox_query_aq_cap_max_sg_sq
  392. * The maximum S/G list elements in an DSQ. DSQ must not contain
  393. * more S/G entries than indicated here.
  394. */
  395. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_sg_sq, 0x10, 8, 8);
  396. /* cmd_mbox_query_aq_cap_
  397. * The maximum S/G list elements in an DRQ. DRQ must not contain
  398. * more S/G entries than indicated here.
  399. */
  400. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_sg_rq, 0x10, 0, 8);
  401. /* MAP_FA - Map Firmware Area
  402. * --------------------------
  403. * OpMod == 0 (N/A), INMmod == Number of VPM entries
  404. * -------------------------------------------------
  405. * The MAP_FA command passes physical pages to the switch. These pages
  406. * are used to store the device firmware. MAP_FA can be executed multiple
  407. * times until all the firmware area is mapped (the size that should be
  408. * mapped is retrieved through the QUERY_FW command). All required pages
  409. * must be mapped to finish the initialization phase. Physical memory
  410. * passed in this command must be pinned.
  411. */
  412. #define MLXSW_CMD_MAP_FA_VPM_ENTRIES_MAX 32
  413. static inline int mlxsw_cmd_map_fa(struct mlxsw_core *mlxsw_core,
  414. char *in_mbox, u32 vpm_entries_count)
  415. {
  416. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_MAP_FA,
  417. 0, vpm_entries_count,
  418. in_mbox, MLXSW_CMD_MBOX_SIZE);
  419. }
  420. /* cmd_mbox_map_fa_pa
  421. * Physical Address.
  422. */
  423. MLXSW_ITEM64_INDEXED(cmd_mbox, map_fa, pa, 0x00, 12, 52, 0x08, 0x00, true);
  424. /* cmd_mbox_map_fa_log2size
  425. * Log (base 2) of the size in 4KB pages of the physical and contiguous memory
  426. * that starts at PA_L/H.
  427. */
  428. MLXSW_ITEM32_INDEXED(cmd_mbox, map_fa, log2size, 0x00, 0, 5, 0x08, 0x04, false);
  429. /* UNMAP_FA - Unmap Firmware Area
  430. * ------------------------------
  431. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  432. * -----------------------------------
  433. * The UNMAP_FA command unload the firmware and unmaps all the
  434. * firmware area. After this command is completed the device will not access
  435. * the pages that were mapped to the firmware area. After executing UNMAP_FA
  436. * command, software reset must be done prior to execution of MAP_FW command.
  437. */
  438. static inline int mlxsw_cmd_unmap_fa(struct mlxsw_core *mlxsw_core)
  439. {
  440. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_UNMAP_FA, 0, 0);
  441. }
  442. /* QUERY_RESOURCES - Query chip resources
  443. * --------------------------------------
  444. * OpMod == 0 (N/A) , INMmod is index
  445. * ----------------------------------
  446. * The QUERY_RESOURCES command retrieves information related to chip resources
  447. * by resource ID. Every command returns 32 entries. INmod is being use as base.
  448. * for example, index 1 will return entries 32-63. When the tables end and there
  449. * are no more sources in the table, will return resource id 0xFFF to indicate
  450. * it.
  451. */
  452. #define MLXSW_CMD_QUERY_RESOURCES_TABLE_END_ID 0xffff
  453. #define MLXSW_CMD_QUERY_RESOURCES_MAX_QUERIES 100
  454. #define MLXSW_CMD_QUERY_RESOURCES_PER_QUERY 32
  455. static inline int mlxsw_cmd_query_resources(struct mlxsw_core *mlxsw_core,
  456. char *out_mbox, int index)
  457. {
  458. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_RESOURCES,
  459. 0, index, false, out_mbox,
  460. MLXSW_CMD_MBOX_SIZE);
  461. }
  462. /* cmd_mbox_query_resource_id
  463. * The resource id. 0xFFFF indicates table's end.
  464. */
  465. MLXSW_ITEM32_INDEXED(cmd_mbox, query_resource, id, 0x00, 16, 16, 0x8, 0, false);
  466. /* cmd_mbox_query_resource_data
  467. * The resource
  468. */
  469. MLXSW_ITEM64_INDEXED(cmd_mbox, query_resource, data,
  470. 0x00, 0, 40, 0x8, 0, false);
  471. /* CONFIG_PROFILE (Set) - Configure Switch Profile
  472. * ------------------------------
  473. * OpMod == 1 (Set), INMmod == 0 (N/A)
  474. * -----------------------------------
  475. * The CONFIG_PROFILE command sets the switch profile. The command can be
  476. * executed on the device only once at startup in order to allocate and
  477. * configure all switch resources and prepare it for operational mode.
  478. * It is not possible to change the device profile after the chip is
  479. * in operational mode.
  480. * Failure of the CONFIG_PROFILE command leaves the hardware in an indeterminate
  481. * state therefore it is required to perform software reset to the device
  482. * following an unsuccessful completion of the command. It is required
  483. * to perform software reset to the device to change an existing profile.
  484. */
  485. static inline int mlxsw_cmd_config_profile_set(struct mlxsw_core *mlxsw_core,
  486. char *in_mbox)
  487. {
  488. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_CONFIG_PROFILE,
  489. 1, 0, in_mbox, MLXSW_CMD_MBOX_SIZE);
  490. }
  491. /* cmd_mbox_config_profile_set_max_vepa_channels
  492. * Capability bit. Setting a bit to 1 configures the profile
  493. * according to the mailbox contents.
  494. */
  495. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_vepa_channels, 0x0C, 0, 1);
  496. /* cmd_mbox_config_profile_set_max_lag
  497. * Capability bit. Setting a bit to 1 configures the profile
  498. * according to the mailbox contents.
  499. */
  500. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_lag, 0x0C, 1, 1);
  501. /* cmd_mbox_config_profile_set_max_port_per_lag
  502. * Capability bit. Setting a bit to 1 configures the profile
  503. * according to the mailbox contents.
  504. */
  505. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_port_per_lag, 0x0C, 2, 1);
  506. /* cmd_mbox_config_profile_set_max_mid
  507. * Capability bit. Setting a bit to 1 configures the profile
  508. * according to the mailbox contents.
  509. */
  510. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_mid, 0x0C, 3, 1);
  511. /* cmd_mbox_config_profile_set_max_pgt
  512. * Capability bit. Setting a bit to 1 configures the profile
  513. * according to the mailbox contents.
  514. */
  515. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_pgt, 0x0C, 4, 1);
  516. /* cmd_mbox_config_profile_set_max_system_port
  517. * Capability bit. Setting a bit to 1 configures the profile
  518. * according to the mailbox contents.
  519. */
  520. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_system_port, 0x0C, 5, 1);
  521. /* cmd_mbox_config_profile_set_max_vlan_groups
  522. * Capability bit. Setting a bit to 1 configures the profile
  523. * according to the mailbox contents.
  524. */
  525. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_vlan_groups, 0x0C, 6, 1);
  526. /* cmd_mbox_config_profile_set_max_regions
  527. * Capability bit. Setting a bit to 1 configures the profile
  528. * according to the mailbox contents.
  529. */
  530. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_regions, 0x0C, 7, 1);
  531. /* cmd_mbox_config_profile_set_flood_mode
  532. * Capability bit. Setting a bit to 1 configures the profile
  533. * according to the mailbox contents.
  534. */
  535. MLXSW_ITEM32(cmd_mbox, config_profile, set_flood_mode, 0x0C, 8, 1);
  536. /* cmd_mbox_config_profile_set_max_flood_tables
  537. * Capability bit. Setting a bit to 1 configures the profile
  538. * according to the mailbox contents.
  539. */
  540. MLXSW_ITEM32(cmd_mbox, config_profile, set_flood_tables, 0x0C, 9, 1);
  541. /* cmd_mbox_config_profile_set_max_ib_mc
  542. * Capability bit. Setting a bit to 1 configures the profile
  543. * according to the mailbox contents.
  544. */
  545. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_ib_mc, 0x0C, 12, 1);
  546. /* cmd_mbox_config_profile_set_max_pkey
  547. * Capability bit. Setting a bit to 1 configures the profile
  548. * according to the mailbox contents.
  549. */
  550. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_pkey, 0x0C, 13, 1);
  551. /* cmd_mbox_config_profile_set_adaptive_routing_group_cap
  552. * Capability bit. Setting a bit to 1 configures the profile
  553. * according to the mailbox contents.
  554. */
  555. MLXSW_ITEM32(cmd_mbox, config_profile,
  556. set_adaptive_routing_group_cap, 0x0C, 14, 1);
  557. /* cmd_mbox_config_profile_set_ar_sec
  558. * Capability bit. Setting a bit to 1 configures the profile
  559. * according to the mailbox contents.
  560. */
  561. MLXSW_ITEM32(cmd_mbox, config_profile, set_ar_sec, 0x0C, 15, 1);
  562. /* cmd_mbox_config_set_kvd_linear_size
  563. * Capability bit. Setting a bit to 1 configures the profile
  564. * according to the mailbox contents.
  565. */
  566. MLXSW_ITEM32(cmd_mbox, config_profile, set_kvd_linear_size, 0x0C, 24, 1);
  567. /* cmd_mbox_config_set_kvd_hash_single_size
  568. * Capability bit. Setting a bit to 1 configures the profile
  569. * according to the mailbox contents.
  570. */
  571. MLXSW_ITEM32(cmd_mbox, config_profile, set_kvd_hash_single_size, 0x0C, 25, 1);
  572. /* cmd_mbox_config_set_kvd_hash_double_size
  573. * Capability bit. Setting a bit to 1 configures the profile
  574. * according to the mailbox contents.
  575. */
  576. MLXSW_ITEM32(cmd_mbox, config_profile, set_kvd_hash_double_size, 0x0C, 26, 1);
  577. /* cmd_mbox_config_profile_max_vepa_channels
  578. * Maximum number of VEPA channels per port (0 through 16)
  579. * 0 - multi-channel VEPA is disabled
  580. */
  581. MLXSW_ITEM32(cmd_mbox, config_profile, max_vepa_channels, 0x10, 0, 8);
  582. /* cmd_mbox_config_profile_max_lag
  583. * Maximum number of LAG IDs requested.
  584. */
  585. MLXSW_ITEM32(cmd_mbox, config_profile, max_lag, 0x14, 0, 16);
  586. /* cmd_mbox_config_profile_max_port_per_lag
  587. * Maximum number of ports per LAG requested.
  588. */
  589. MLXSW_ITEM32(cmd_mbox, config_profile, max_port_per_lag, 0x18, 0, 16);
  590. /* cmd_mbox_config_profile_max_mid
  591. * Maximum Multicast IDs.
  592. * Multicast IDs are allocated from 0 to max_mid-1
  593. */
  594. MLXSW_ITEM32(cmd_mbox, config_profile, max_mid, 0x1C, 0, 16);
  595. /* cmd_mbox_config_profile_max_pgt
  596. * Maximum records in the Port Group Table per Switch Partition.
  597. * Port Group Table indexes are from 0 to max_pgt-1
  598. */
  599. MLXSW_ITEM32(cmd_mbox, config_profile, max_pgt, 0x20, 0, 16);
  600. /* cmd_mbox_config_profile_max_system_port
  601. * The maximum number of system ports that can be allocated.
  602. */
  603. MLXSW_ITEM32(cmd_mbox, config_profile, max_system_port, 0x24, 0, 16);
  604. /* cmd_mbox_config_profile_max_vlan_groups
  605. * Maximum number VLAN Groups for VLAN binding.
  606. */
  607. MLXSW_ITEM32(cmd_mbox, config_profile, max_vlan_groups, 0x28, 0, 12);
  608. /* cmd_mbox_config_profile_max_regions
  609. * Maximum number of TCAM Regions.
  610. */
  611. MLXSW_ITEM32(cmd_mbox, config_profile, max_regions, 0x2C, 0, 16);
  612. /* cmd_mbox_config_profile_max_flood_tables
  613. * Maximum number of single-entry flooding tables. Different flooding tables
  614. * can be associated with different packet types.
  615. */
  616. MLXSW_ITEM32(cmd_mbox, config_profile, max_flood_tables, 0x30, 16, 4);
  617. /* cmd_mbox_config_profile_max_vid_flood_tables
  618. * Maximum number of per-vid flooding tables. Flooding tables are associated
  619. * to the different packet types for the different switch partitions.
  620. * Table size is 4K entries covering all VID space.
  621. */
  622. MLXSW_ITEM32(cmd_mbox, config_profile, max_vid_flood_tables, 0x30, 8, 4);
  623. /* cmd_mbox_config_profile_flood_mode
  624. * Flooding mode to use.
  625. * 0-2 - Backward compatible modes for SwitchX devices.
  626. * 3 - Mixed mode, where:
  627. * max_flood_tables indicates the number of single-entry tables.
  628. * max_vid_flood_tables indicates the number of per-VID tables.
  629. * max_fid_offset_flood_tables indicates the number of FID-offset tables.
  630. * max_fid_flood_tables indicates the number of per-FID tables.
  631. */
  632. MLXSW_ITEM32(cmd_mbox, config_profile, flood_mode, 0x30, 0, 2);
  633. /* cmd_mbox_config_profile_max_fid_offset_flood_tables
  634. * Maximum number of FID-offset flooding tables.
  635. */
  636. MLXSW_ITEM32(cmd_mbox, config_profile,
  637. max_fid_offset_flood_tables, 0x34, 24, 4);
  638. /* cmd_mbox_config_profile_fid_offset_flood_table_size
  639. * The size (number of entries) of each FID-offset flood table.
  640. */
  641. MLXSW_ITEM32(cmd_mbox, config_profile,
  642. fid_offset_flood_table_size, 0x34, 0, 16);
  643. /* cmd_mbox_config_profile_max_fid_flood_tables
  644. * Maximum number of per-FID flooding tables.
  645. *
  646. * Note: This flooding tables cover special FIDs only (vFIDs), starting at
  647. * FID value 4K and higher.
  648. */
  649. MLXSW_ITEM32(cmd_mbox, config_profile, max_fid_flood_tables, 0x38, 24, 4);
  650. /* cmd_mbox_config_profile_fid_flood_table_size
  651. * The size (number of entries) of each per-FID table.
  652. */
  653. MLXSW_ITEM32(cmd_mbox, config_profile, fid_flood_table_size, 0x38, 0, 16);
  654. /* cmd_mbox_config_profile_max_ib_mc
  655. * Maximum number of multicast FDB records for InfiniBand
  656. * FDB (in 512 chunks) per InfiniBand switch partition.
  657. */
  658. MLXSW_ITEM32(cmd_mbox, config_profile, max_ib_mc, 0x40, 0, 15);
  659. /* cmd_mbox_config_profile_max_pkey
  660. * Maximum per port PKEY table size (for PKEY enforcement)
  661. */
  662. MLXSW_ITEM32(cmd_mbox, config_profile, max_pkey, 0x44, 0, 15);
  663. /* cmd_mbox_config_profile_ar_sec
  664. * Primary/secondary capability
  665. * Describes the number of adaptive routing sub-groups
  666. * 0 - disable primary/secondary (single group)
  667. * 1 - enable primary/secondary (2 sub-groups)
  668. * 2 - 3 sub-groups: Not supported in SwitchX, SwitchX-2
  669. * 3 - 4 sub-groups: Not supported in SwitchX, SwitchX-2
  670. */
  671. MLXSW_ITEM32(cmd_mbox, config_profile, ar_sec, 0x4C, 24, 2);
  672. /* cmd_mbox_config_profile_adaptive_routing_group_cap
  673. * Adaptive Routing Group Capability. Indicates the number of AR groups
  674. * supported. Note that when Primary/secondary is enabled, each
  675. * primary/secondary couple consumes 2 adaptive routing entries.
  676. */
  677. MLXSW_ITEM32(cmd_mbox, config_profile, adaptive_routing_group_cap, 0x4C, 0, 16);
  678. /* cmd_mbox_config_profile_arn
  679. * Adaptive Routing Notification Enable
  680. * Not supported in SwitchX, SwitchX-2
  681. */
  682. MLXSW_ITEM32(cmd_mbox, config_profile, arn, 0x50, 31, 1);
  683. /* cmd_mbox_config_kvd_linear_size
  684. * KVD Linear Size
  685. * Valid for Spectrum only
  686. * Allowed values are 128*N where N=0 or higher
  687. */
  688. MLXSW_ITEM32(cmd_mbox, config_profile, kvd_linear_size, 0x54, 0, 24);
  689. /* cmd_mbox_config_kvd_hash_single_size
  690. * KVD Hash single-entries size
  691. * Valid for Spectrum only
  692. * Allowed values are 128*N where N=0 or higher
  693. * Must be greater or equal to cap_min_kvd_hash_single_size
  694. * Must be smaller or equal to cap_kvd_size - kvd_linear_size
  695. */
  696. MLXSW_ITEM32(cmd_mbox, config_profile, kvd_hash_single_size, 0x58, 0, 24);
  697. /* cmd_mbox_config_kvd_hash_double_size
  698. * KVD Hash double-entries size (units of single-size entries)
  699. * Valid for Spectrum only
  700. * Allowed values are 128*N where N=0 or higher
  701. * Must be either 0 or greater or equal to cap_min_kvd_hash_double_size
  702. * Must be smaller or equal to cap_kvd_size - kvd_linear_size
  703. */
  704. MLXSW_ITEM32(cmd_mbox, config_profile, kvd_hash_double_size, 0x5C, 0, 24);
  705. /* cmd_mbox_config_profile_swid_config_mask
  706. * Modify Switch Partition Configuration mask. When set, the configu-
  707. * ration value for the Switch Partition are taken from the mailbox.
  708. * When clear, the current configuration values are used.
  709. * Bit 0 - set type
  710. * Bit 1 - properties
  711. * Other - reserved
  712. */
  713. MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_mask,
  714. 0x60, 24, 8, 0x08, 0x00, false);
  715. /* cmd_mbox_config_profile_swid_config_type
  716. * Switch Partition type.
  717. * 0000 - disabled (Switch Partition does not exist)
  718. * 0001 - InfiniBand
  719. * 0010 - Ethernet
  720. * 1000 - router port (SwitchX-2 only)
  721. * Other - reserved
  722. */
  723. MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_type,
  724. 0x60, 20, 4, 0x08, 0x00, false);
  725. /* cmd_mbox_config_profile_swid_config_properties
  726. * Switch Partition properties.
  727. */
  728. MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_properties,
  729. 0x60, 0, 8, 0x08, 0x00, false);
  730. /* ACCESS_REG - Access EMAD Supported Register
  731. * ----------------------------------
  732. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  733. * -------------------------------------
  734. * The ACCESS_REG command supports accessing device registers. This access
  735. * is mainly used for bootstrapping.
  736. */
  737. static inline int mlxsw_cmd_access_reg(struct mlxsw_core *mlxsw_core,
  738. char *in_mbox, char *out_mbox)
  739. {
  740. return mlxsw_cmd_exec(mlxsw_core, MLXSW_CMD_OPCODE_ACCESS_REG,
  741. 0, 0, false, in_mbox, MLXSW_CMD_MBOX_SIZE,
  742. out_mbox, MLXSW_CMD_MBOX_SIZE);
  743. }
  744. /* SW2HW_DQ - Software to Hardware DQ
  745. * ----------------------------------
  746. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  747. * INMmod == DQ number
  748. * ----------------------------------------------
  749. * The SW2HW_DQ command transitions a descriptor queue from software to
  750. * hardware ownership. The command enables posting WQEs and ringing DoorBells
  751. * on the descriptor queue.
  752. */
  753. static inline int __mlxsw_cmd_sw2hw_dq(struct mlxsw_core *mlxsw_core,
  754. char *in_mbox, u32 dq_number,
  755. u8 opcode_mod)
  756. {
  757. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_SW2HW_DQ,
  758. opcode_mod, dq_number,
  759. in_mbox, MLXSW_CMD_MBOX_SIZE);
  760. }
  761. enum {
  762. MLXSW_CMD_OPCODE_MOD_SDQ = 0,
  763. MLXSW_CMD_OPCODE_MOD_RDQ = 1,
  764. };
  765. static inline int mlxsw_cmd_sw2hw_sdq(struct mlxsw_core *mlxsw_core,
  766. char *in_mbox, u32 dq_number)
  767. {
  768. return __mlxsw_cmd_sw2hw_dq(mlxsw_core, in_mbox, dq_number,
  769. MLXSW_CMD_OPCODE_MOD_SDQ);
  770. }
  771. static inline int mlxsw_cmd_sw2hw_rdq(struct mlxsw_core *mlxsw_core,
  772. char *in_mbox, u32 dq_number)
  773. {
  774. return __mlxsw_cmd_sw2hw_dq(mlxsw_core, in_mbox, dq_number,
  775. MLXSW_CMD_OPCODE_MOD_RDQ);
  776. }
  777. /* cmd_mbox_sw2hw_dq_cq
  778. * Number of the CQ that this Descriptor Queue reports completions to.
  779. */
  780. MLXSW_ITEM32(cmd_mbox, sw2hw_dq, cq, 0x00, 24, 8);
  781. /* cmd_mbox_sw2hw_dq_sdq_tclass
  782. * SDQ: CPU Egress TClass
  783. * RDQ: Reserved
  784. */
  785. MLXSW_ITEM32(cmd_mbox, sw2hw_dq, sdq_tclass, 0x00, 16, 6);
  786. /* cmd_mbox_sw2hw_dq_log2_dq_sz
  787. * Log (base 2) of the Descriptor Queue size in 4KB pages.
  788. */
  789. MLXSW_ITEM32(cmd_mbox, sw2hw_dq, log2_dq_sz, 0x00, 0, 6);
  790. /* cmd_mbox_sw2hw_dq_pa
  791. * Physical Address.
  792. */
  793. MLXSW_ITEM64_INDEXED(cmd_mbox, sw2hw_dq, pa, 0x10, 12, 52, 0x08, 0x00, true);
  794. /* HW2SW_DQ - Hardware to Software DQ
  795. * ----------------------------------
  796. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  797. * INMmod == DQ number
  798. * ----------------------------------------------
  799. * The HW2SW_DQ command transitions a descriptor queue from hardware to
  800. * software ownership. Incoming packets on the DQ are silently discarded,
  801. * SW should not post descriptors on nonoperational DQs.
  802. */
  803. static inline int __mlxsw_cmd_hw2sw_dq(struct mlxsw_core *mlxsw_core,
  804. u32 dq_number, u8 opcode_mod)
  805. {
  806. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_HW2SW_DQ,
  807. opcode_mod, dq_number);
  808. }
  809. static inline int mlxsw_cmd_hw2sw_sdq(struct mlxsw_core *mlxsw_core,
  810. u32 dq_number)
  811. {
  812. return __mlxsw_cmd_hw2sw_dq(mlxsw_core, dq_number,
  813. MLXSW_CMD_OPCODE_MOD_SDQ);
  814. }
  815. static inline int mlxsw_cmd_hw2sw_rdq(struct mlxsw_core *mlxsw_core,
  816. u32 dq_number)
  817. {
  818. return __mlxsw_cmd_hw2sw_dq(mlxsw_core, dq_number,
  819. MLXSW_CMD_OPCODE_MOD_RDQ);
  820. }
  821. /* 2ERR_DQ - To Error DQ
  822. * ---------------------
  823. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  824. * INMmod == DQ number
  825. * ----------------------------------------------
  826. * The 2ERR_DQ command transitions the DQ into the error state from the state
  827. * in which it has been. While the command is executed, some in-process
  828. * descriptors may complete. Once the DQ transitions into the error state,
  829. * if there are posted descriptors on the RDQ/SDQ, the hardware writes
  830. * a completion with error (flushed) for all descriptors posted in the RDQ/SDQ.
  831. * When the command is completed successfully, the DQ is already in
  832. * the error state.
  833. */
  834. static inline int __mlxsw_cmd_2err_dq(struct mlxsw_core *mlxsw_core,
  835. u32 dq_number, u8 opcode_mod)
  836. {
  837. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_2ERR_DQ,
  838. opcode_mod, dq_number);
  839. }
  840. static inline int mlxsw_cmd_2err_sdq(struct mlxsw_core *mlxsw_core,
  841. u32 dq_number)
  842. {
  843. return __mlxsw_cmd_2err_dq(mlxsw_core, dq_number,
  844. MLXSW_CMD_OPCODE_MOD_SDQ);
  845. }
  846. static inline int mlxsw_cmd_2err_rdq(struct mlxsw_core *mlxsw_core,
  847. u32 dq_number)
  848. {
  849. return __mlxsw_cmd_2err_dq(mlxsw_core, dq_number,
  850. MLXSW_CMD_OPCODE_MOD_RDQ);
  851. }
  852. /* QUERY_DQ - Query DQ
  853. * ---------------------
  854. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  855. * INMmod == DQ number
  856. * ----------------------------------------------
  857. * The QUERY_DQ command retrieves a snapshot of DQ parameters from the hardware.
  858. *
  859. * Note: Output mailbox has the same format as SW2HW_DQ.
  860. */
  861. static inline int __mlxsw_cmd_query_dq(struct mlxsw_core *mlxsw_core,
  862. char *out_mbox, u32 dq_number,
  863. u8 opcode_mod)
  864. {
  865. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_2ERR_DQ,
  866. opcode_mod, dq_number, false,
  867. out_mbox, MLXSW_CMD_MBOX_SIZE);
  868. }
  869. static inline int mlxsw_cmd_query_sdq(struct mlxsw_core *mlxsw_core,
  870. char *out_mbox, u32 dq_number)
  871. {
  872. return __mlxsw_cmd_query_dq(mlxsw_core, out_mbox, dq_number,
  873. MLXSW_CMD_OPCODE_MOD_SDQ);
  874. }
  875. static inline int mlxsw_cmd_query_rdq(struct mlxsw_core *mlxsw_core,
  876. char *out_mbox, u32 dq_number)
  877. {
  878. return __mlxsw_cmd_query_dq(mlxsw_core, out_mbox, dq_number,
  879. MLXSW_CMD_OPCODE_MOD_RDQ);
  880. }
  881. /* SW2HW_CQ - Software to Hardware CQ
  882. * ----------------------------------
  883. * OpMod == 0 (N/A), INMmod == CQ number
  884. * -------------------------------------
  885. * The SW2HW_CQ command transfers ownership of a CQ context entry from software
  886. * to hardware. The command takes the CQ context entry from the input mailbox
  887. * and stores it in the CQC in the ownership of the hardware. The command fails
  888. * if the requested CQC entry is already in the ownership of the hardware.
  889. */
  890. static inline int mlxsw_cmd_sw2hw_cq(struct mlxsw_core *mlxsw_core,
  891. char *in_mbox, u32 cq_number)
  892. {
  893. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_SW2HW_CQ,
  894. 0, cq_number, in_mbox, MLXSW_CMD_MBOX_SIZE);
  895. }
  896. /* cmd_mbox_sw2hw_cq_cv
  897. * CQE Version.
  898. * 0 - CQE Version 0, 1 - CQE Version 1
  899. */
  900. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, cv, 0x00, 28, 4);
  901. /* cmd_mbox_sw2hw_cq_c_eqn
  902. * Event Queue this CQ reports completion events to.
  903. */
  904. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, c_eqn, 0x00, 24, 1);
  905. /* cmd_mbox_sw2hw_cq_st
  906. * Event delivery state machine
  907. * 0x0 - FIRED
  908. * 0x1 - ARMED (Request for Notification)
  909. */
  910. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, st, 0x00, 8, 1);
  911. /* cmd_mbox_sw2hw_cq_log_cq_size
  912. * Log (base 2) of the CQ size (in entries).
  913. */
  914. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, log_cq_size, 0x00, 0, 4);
  915. /* cmd_mbox_sw2hw_cq_producer_counter
  916. * Producer Counter. The counter is incremented for each CQE that is
  917. * written by the HW to the CQ.
  918. * Maintained by HW (valid for the QUERY_CQ command only)
  919. */
  920. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, producer_counter, 0x04, 0, 16);
  921. /* cmd_mbox_sw2hw_cq_pa
  922. * Physical Address.
  923. */
  924. MLXSW_ITEM64_INDEXED(cmd_mbox, sw2hw_cq, pa, 0x10, 11, 53, 0x08, 0x00, true);
  925. /* HW2SW_CQ - Hardware to Software CQ
  926. * ----------------------------------
  927. * OpMod == 0 (N/A), INMmod == CQ number
  928. * -------------------------------------
  929. * The HW2SW_CQ command transfers ownership of a CQ context entry from hardware
  930. * to software. The CQC entry is invalidated as a result of this command.
  931. */
  932. static inline int mlxsw_cmd_hw2sw_cq(struct mlxsw_core *mlxsw_core,
  933. u32 cq_number)
  934. {
  935. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_HW2SW_CQ,
  936. 0, cq_number);
  937. }
  938. /* QUERY_CQ - Query CQ
  939. * ----------------------------------
  940. * OpMod == 0 (N/A), INMmod == CQ number
  941. * -------------------------------------
  942. * The QUERY_CQ command retrieves a snapshot of the current CQ context entry.
  943. * The command stores the snapshot in the output mailbox in the software format.
  944. * Note that the CQ context state and values are not affected by the QUERY_CQ
  945. * command. The QUERY_CQ command is for debug purposes only.
  946. *
  947. * Note: Output mailbox has the same format as SW2HW_CQ.
  948. */
  949. static inline int mlxsw_cmd_query_cq(struct mlxsw_core *mlxsw_core,
  950. char *out_mbox, u32 cq_number)
  951. {
  952. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_CQ,
  953. 0, cq_number, false,
  954. out_mbox, MLXSW_CMD_MBOX_SIZE);
  955. }
  956. /* SW2HW_EQ - Software to Hardware EQ
  957. * ----------------------------------
  958. * OpMod == 0 (N/A), INMmod == EQ number
  959. * -------------------------------------
  960. * The SW2HW_EQ command transfers ownership of an EQ context entry from software
  961. * to hardware. The command takes the EQ context entry from the input mailbox
  962. * and stores it in the EQC in the ownership of the hardware. The command fails
  963. * if the requested EQC entry is already in the ownership of the hardware.
  964. */
  965. static inline int mlxsw_cmd_sw2hw_eq(struct mlxsw_core *mlxsw_core,
  966. char *in_mbox, u32 eq_number)
  967. {
  968. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_SW2HW_EQ,
  969. 0, eq_number, in_mbox, MLXSW_CMD_MBOX_SIZE);
  970. }
  971. /* cmd_mbox_sw2hw_eq_int_msix
  972. * When set, MSI-X cycles will be generated by this EQ.
  973. * When cleared, an interrupt will be generated by this EQ.
  974. */
  975. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, int_msix, 0x00, 24, 1);
  976. /* cmd_mbox_sw2hw_eq_st
  977. * Event delivery state machine
  978. * 0x0 - FIRED
  979. * 0x1 - ARMED (Request for Notification)
  980. * 0x11 - Always ARMED
  981. * other - reserved
  982. */
  983. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, st, 0x00, 8, 2);
  984. /* cmd_mbox_sw2hw_eq_log_eq_size
  985. * Log (base 2) of the EQ size (in entries).
  986. */
  987. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, log_eq_size, 0x00, 0, 4);
  988. /* cmd_mbox_sw2hw_eq_producer_counter
  989. * Producer Counter. The counter is incremented for each EQE that is written
  990. * by the HW to the EQ.
  991. * Maintained by HW (valid for the QUERY_EQ command only)
  992. */
  993. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, producer_counter, 0x04, 0, 16);
  994. /* cmd_mbox_sw2hw_eq_pa
  995. * Physical Address.
  996. */
  997. MLXSW_ITEM64_INDEXED(cmd_mbox, sw2hw_eq, pa, 0x10, 11, 53, 0x08, 0x00, true);
  998. /* HW2SW_EQ - Hardware to Software EQ
  999. * ----------------------------------
  1000. * OpMod == 0 (N/A), INMmod == EQ number
  1001. * -------------------------------------
  1002. */
  1003. static inline int mlxsw_cmd_hw2sw_eq(struct mlxsw_core *mlxsw_core,
  1004. u32 eq_number)
  1005. {
  1006. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_HW2SW_EQ,
  1007. 0, eq_number);
  1008. }
  1009. /* QUERY_EQ - Query EQ
  1010. * ----------------------------------
  1011. * OpMod == 0 (N/A), INMmod == EQ number
  1012. * -------------------------------------
  1013. *
  1014. * Note: Output mailbox has the same format as SW2HW_EQ.
  1015. */
  1016. static inline int mlxsw_cmd_query_eq(struct mlxsw_core *mlxsw_core,
  1017. char *out_mbox, u32 eq_number)
  1018. {
  1019. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_EQ,
  1020. 0, eq_number, false,
  1021. out_mbox, MLXSW_CMD_MBOX_SIZE);
  1022. }
  1023. #endif