cmd.h 41 KB

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