cmd.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  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_lag_mode_support
  248. * 0: CONFIG_PROFILE.lag_mode is not supported by FW
  249. * 1: CONFIG_PROFILE.lag_mode is supported by FW
  250. */
  251. MLXSW_ITEM32(cmd_mbox, query_fw, lag_mode_support, 0x18, 1, 1);
  252. /* cmd_mbox_query_fw_cff_support
  253. * 0: CONFIG_PROFILE.flood_mode = 5 (CFF) is not supported by FW
  254. * 1: CONFIG_PROFILE.flood_mode = 5 (CFF) is supported by FW
  255. */
  256. MLXSW_ITEM32(cmd_mbox, query_fw, cff_support, 0x18, 2, 1);
  257. /* cmd_mbox_query_fw_clr_int_base_offset
  258. * Clear Interrupt register's offset from clr_int_bar register
  259. * in PCI address space.
  260. */
  261. MLXSW_ITEM64(cmd_mbox, query_fw, clr_int_base_offset, 0x20, 0, 64);
  262. /* cmd_mbox_query_fw_clr_int_bar
  263. * PCI base address register (BAR) where clr_int register is located.
  264. * 00 - BAR 0-1 (64 bit BAR)
  265. */
  266. MLXSW_ITEM32(cmd_mbox, query_fw, clr_int_bar, 0x28, 30, 2);
  267. /* cmd_mbox_query_fw_error_buf_offset
  268. * Read Only buffer for internal error reports of offset
  269. * from error_buf_bar register in PCI address space).
  270. */
  271. MLXSW_ITEM64(cmd_mbox, query_fw, error_buf_offset, 0x30, 0, 64);
  272. /* cmd_mbox_query_fw_error_buf_size
  273. * Internal error buffer size in DWORDs
  274. */
  275. MLXSW_ITEM32(cmd_mbox, query_fw, error_buf_size, 0x38, 0, 32);
  276. /* cmd_mbox_query_fw_error_int_bar
  277. * PCI base address register (BAR) where error buffer
  278. * register is located.
  279. * 00 - BAR 0-1 (64 bit BAR)
  280. */
  281. MLXSW_ITEM32(cmd_mbox, query_fw, error_int_bar, 0x3C, 30, 2);
  282. /* cmd_mbox_query_fw_doorbell_page_offset
  283. * Offset of the doorbell page
  284. */
  285. MLXSW_ITEM64(cmd_mbox, query_fw, doorbell_page_offset, 0x40, 0, 64);
  286. /* cmd_mbox_query_fw_doorbell_page_bar
  287. * PCI base address register (BAR) of the doorbell page
  288. * 00 - BAR 0-1 (64 bit BAR)
  289. */
  290. MLXSW_ITEM32(cmd_mbox, query_fw, doorbell_page_bar, 0x48, 30, 2);
  291. /* cmd_mbox_query_fw_free_running_clock_offset
  292. * The offset of the free running clock page
  293. */
  294. MLXSW_ITEM64(cmd_mbox, query_fw, free_running_clock_offset, 0x50, 0, 64);
  295. /* cmd_mbox_query_fw_fr_rn_clk_bar
  296. * PCI base address register (BAR) of the free running clock page
  297. * 0: BAR 0
  298. * 1: 64 bit BAR
  299. */
  300. MLXSW_ITEM32(cmd_mbox, query_fw, fr_rn_clk_bar, 0x58, 30, 2);
  301. /* cmd_mbox_query_fw_utc_sec_offset
  302. * The offset of the UTC_Sec page
  303. */
  304. MLXSW_ITEM64(cmd_mbox, query_fw, utc_sec_offset, 0x70, 0, 64);
  305. /* cmd_mbox_query_fw_utc_sec_bar
  306. * PCI base address register (BAR) of the UTC_Sec page
  307. * 0: BAR 0
  308. * 1: 64 bit BAR
  309. * Reserved on SwitchX/-2, Switch-IB/2, Spectrum-1
  310. */
  311. MLXSW_ITEM32(cmd_mbox, query_fw, utc_sec_bar, 0x78, 30, 2);
  312. /* cmd_mbox_query_fw_utc_nsec_offset
  313. * The offset of the UTC_nSec page
  314. */
  315. MLXSW_ITEM64(cmd_mbox, query_fw, utc_nsec_offset, 0x80, 0, 64);
  316. /* cmd_mbox_query_fw_utc_nsec_bar
  317. * PCI base address register (BAR) of the UTC_nSec page
  318. * 0: BAR 0
  319. * 1: 64 bit BAR
  320. * Reserved on SwitchX/-2, Switch-IB/2, Spectrum-1
  321. */
  322. MLXSW_ITEM32(cmd_mbox, query_fw, utc_nsec_bar, 0x88, 30, 2);
  323. /* QUERY_BOARDINFO - Query Board Information
  324. * -----------------------------------------
  325. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  326. * -----------------------------------
  327. * The QUERY_BOARDINFO command retrieves adapter specific parameters.
  328. */
  329. static inline int mlxsw_cmd_boardinfo(struct mlxsw_core *mlxsw_core,
  330. char *out_mbox)
  331. {
  332. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_BOARDINFO,
  333. 0, 0, false, out_mbox, MLXSW_CMD_MBOX_SIZE);
  334. }
  335. /* cmd_mbox_boardinfo_intapin
  336. * When PCIe interrupt messages are being used, this value is used for clearing
  337. * an interrupt. When using MSI-X, this register is not used.
  338. */
  339. MLXSW_ITEM32(cmd_mbox, boardinfo, intapin, 0x10, 24, 8);
  340. /* cmd_mbox_boardinfo_vsd_vendor_id
  341. * PCISIG Vendor ID (www.pcisig.com/membership/vid_search) of the vendor
  342. * specifying/formatting the VSD. The vsd_vendor_id identifies the management
  343. * domain of the VSD/PSID data. Different vendors may choose different VSD/PSID
  344. * format and encoding as long as they use their assigned vsd_vendor_id.
  345. */
  346. MLXSW_ITEM32(cmd_mbox, boardinfo, vsd_vendor_id, 0x1C, 0, 16);
  347. /* cmd_mbox_boardinfo_vsd
  348. * Vendor Specific Data. The VSD string that is burnt to the Flash
  349. * with the firmware.
  350. */
  351. #define MLXSW_CMD_BOARDINFO_VSD_LEN 208
  352. MLXSW_ITEM_BUF(cmd_mbox, boardinfo, vsd, 0x20, MLXSW_CMD_BOARDINFO_VSD_LEN);
  353. /* cmd_mbox_boardinfo_psid
  354. * The PSID field is a 16-ascii (byte) character string which acts as
  355. * the board ID. The PSID format is used in conjunction with
  356. * Mellanox vsd_vendor_id (15B3h).
  357. */
  358. #define MLXSW_CMD_BOARDINFO_PSID_LEN 16
  359. MLXSW_ITEM_BUF(cmd_mbox, boardinfo, psid, 0xF0, MLXSW_CMD_BOARDINFO_PSID_LEN);
  360. /* QUERY_AQ_CAP - Query Asynchronous Queues Capabilities
  361. * -----------------------------------------------------
  362. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  363. * -----------------------------------
  364. * The QUERY_AQ_CAP command returns the device asynchronous queues
  365. * capabilities supported.
  366. */
  367. static inline int mlxsw_cmd_query_aq_cap(struct mlxsw_core *mlxsw_core,
  368. char *out_mbox)
  369. {
  370. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_AQ_CAP,
  371. 0, 0, false, out_mbox, MLXSW_CMD_MBOX_SIZE);
  372. }
  373. /* cmd_mbox_query_aq_cap_log_max_sdq_sz
  374. * Log (base 2) of max WQEs allowed on SDQ.
  375. */
  376. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_sdq_sz, 0x00, 24, 8);
  377. /* cmd_mbox_query_aq_cap_max_num_sdqs
  378. * Maximum number of SDQs.
  379. */
  380. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_sdqs, 0x00, 0, 8);
  381. /* cmd_mbox_query_aq_cap_log_max_rdq_sz
  382. * Log (base 2) of max WQEs allowed on RDQ.
  383. */
  384. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_rdq_sz, 0x04, 24, 8);
  385. /* cmd_mbox_query_aq_cap_max_num_rdqs
  386. * Maximum number of RDQs.
  387. */
  388. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_rdqs, 0x04, 0, 8);
  389. /* cmd_mbox_query_aq_cap_log_max_cq_sz
  390. * Log (base 2) of the Maximum CQEs allowed in a CQ for CQEv0 and CQEv1.
  391. */
  392. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_cq_sz, 0x08, 24, 8);
  393. /* cmd_mbox_query_aq_cap_log_max_cqv2_sz
  394. * Log (base 2) of the Maximum CQEs allowed in a CQ for CQEv2.
  395. */
  396. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_cqv2_sz, 0x08, 16, 8);
  397. /* cmd_mbox_query_aq_cap_max_num_cqs
  398. * Maximum number of CQs.
  399. */
  400. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_cqs, 0x08, 0, 8);
  401. /* cmd_mbox_query_aq_cap_log_max_eq_sz
  402. * Log (base 2) of max EQEs allowed on EQ.
  403. */
  404. MLXSW_ITEM32(cmd_mbox, query_aq_cap, log_max_eq_sz, 0x0C, 24, 8);
  405. /* cmd_mbox_query_aq_cap_max_num_eqs
  406. * Maximum number of EQs.
  407. */
  408. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_num_eqs, 0x0C, 0, 8);
  409. /* cmd_mbox_query_aq_cap_max_sg_sq
  410. * The maximum S/G list elements in an DSQ. DSQ must not contain
  411. * more S/G entries than indicated here.
  412. */
  413. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_sg_sq, 0x10, 8, 8);
  414. /* cmd_mbox_query_aq_cap_
  415. * The maximum S/G list elements in an DRQ. DRQ must not contain
  416. * more S/G entries than indicated here.
  417. */
  418. MLXSW_ITEM32(cmd_mbox, query_aq_cap, max_sg_rq, 0x10, 0, 8);
  419. /* MAP_FA - Map Firmware Area
  420. * --------------------------
  421. * OpMod == 0 (N/A), INMmod == Number of VPM entries
  422. * -------------------------------------------------
  423. * The MAP_FA command passes physical pages to the switch. These pages
  424. * are used to store the device firmware. MAP_FA can be executed multiple
  425. * times until all the firmware area is mapped (the size that should be
  426. * mapped is retrieved through the QUERY_FW command). All required pages
  427. * must be mapped to finish the initialization phase. Physical memory
  428. * passed in this command must be pinned.
  429. */
  430. #define MLXSW_CMD_MAP_FA_VPM_ENTRIES_MAX 32
  431. static inline int mlxsw_cmd_map_fa(struct mlxsw_core *mlxsw_core,
  432. char *in_mbox, u32 vpm_entries_count)
  433. {
  434. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_MAP_FA,
  435. 0, vpm_entries_count,
  436. in_mbox, MLXSW_CMD_MBOX_SIZE);
  437. }
  438. /* cmd_mbox_map_fa_pa
  439. * Physical Address.
  440. */
  441. MLXSW_ITEM64_INDEXED(cmd_mbox, map_fa, pa, 0x00, 12, 52, 0x08, 0x00, true);
  442. /* cmd_mbox_map_fa_log2size
  443. * Log (base 2) of the size in 4KB pages of the physical and contiguous memory
  444. * that starts at PA_L/H.
  445. */
  446. MLXSW_ITEM32_INDEXED(cmd_mbox, map_fa, log2size, 0x00, 0, 5, 0x08, 0x04, false);
  447. /* UNMAP_FA - Unmap Firmware Area
  448. * ------------------------------
  449. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  450. * -----------------------------------
  451. * The UNMAP_FA command unload the firmware and unmaps all the
  452. * firmware area. After this command is completed the device will not access
  453. * the pages that were mapped to the firmware area. After executing UNMAP_FA
  454. * command, software reset must be done prior to execution of MAP_FW command.
  455. */
  456. static inline int mlxsw_cmd_unmap_fa(struct mlxsw_core *mlxsw_core)
  457. {
  458. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_UNMAP_FA, 0, 0);
  459. }
  460. /* QUERY_RESOURCES - Query chip resources
  461. * --------------------------------------
  462. * OpMod == 0 (N/A) , INMmod is index
  463. * ----------------------------------
  464. * The QUERY_RESOURCES command retrieves information related to chip resources
  465. * by resource ID. Every command returns 32 entries. INmod is being use as base.
  466. * for example, index 1 will return entries 32-63. When the tables end and there
  467. * are no more sources in the table, will return resource id 0xFFF to indicate
  468. * it.
  469. */
  470. #define MLXSW_CMD_QUERY_RESOURCES_TABLE_END_ID 0xffff
  471. #define MLXSW_CMD_QUERY_RESOURCES_MAX_QUERIES 100
  472. #define MLXSW_CMD_QUERY_RESOURCES_PER_QUERY 32
  473. static inline int mlxsw_cmd_query_resources(struct mlxsw_core *mlxsw_core,
  474. char *out_mbox, int index)
  475. {
  476. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_RESOURCES,
  477. 0, index, false, out_mbox,
  478. MLXSW_CMD_MBOX_SIZE);
  479. }
  480. /* cmd_mbox_query_resource_id
  481. * The resource id. 0xFFFF indicates table's end.
  482. */
  483. MLXSW_ITEM32_INDEXED(cmd_mbox, query_resource, id, 0x00, 16, 16, 0x8, 0, false);
  484. /* cmd_mbox_query_resource_data
  485. * The resource
  486. */
  487. MLXSW_ITEM64_INDEXED(cmd_mbox, query_resource, data,
  488. 0x00, 0, 40, 0x8, 0, false);
  489. /* CONFIG_PROFILE (Set) - Configure Switch Profile
  490. * ------------------------------
  491. * OpMod == 1 (Set), INMmod == 0 (N/A)
  492. * -----------------------------------
  493. * The CONFIG_PROFILE command sets the switch profile. The command can be
  494. * executed on the device only once at startup in order to allocate and
  495. * configure all switch resources and prepare it for operational mode.
  496. * It is not possible to change the device profile after the chip is
  497. * in operational mode.
  498. * Failure of the CONFIG_PROFILE command leaves the hardware in an indeterminate
  499. * state therefore it is required to perform software reset to the device
  500. * following an unsuccessful completion of the command. It is required
  501. * to perform software reset to the device to change an existing profile.
  502. */
  503. static inline int mlxsw_cmd_config_profile_set(struct mlxsw_core *mlxsw_core,
  504. char *in_mbox)
  505. {
  506. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_CONFIG_PROFILE,
  507. 1, 0, in_mbox, MLXSW_CMD_MBOX_SIZE);
  508. }
  509. /* cmd_mbox_config_profile_set_max_vepa_channels
  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_vepa_channels, 0x0C, 0, 1);
  514. /* cmd_mbox_config_profile_set_max_lag
  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_lag, 0x0C, 1, 1);
  519. /* cmd_mbox_config_profile_set_max_port_per_lag
  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_port_per_lag, 0x0C, 2, 1);
  524. /* cmd_mbox_config_profile_set_max_mid
  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_mid, 0x0C, 3, 1);
  529. /* cmd_mbox_config_profile_set_max_pgt
  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_pgt, 0x0C, 4, 1);
  534. /* cmd_mbox_config_profile_set_max_system_port
  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_system_port, 0x0C, 5, 1);
  539. /* cmd_mbox_config_profile_set_max_vlan_groups
  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_max_vlan_groups, 0x0C, 6, 1);
  544. /* cmd_mbox_config_profile_set_max_regions
  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_max_regions, 0x0C, 7, 1);
  549. /* cmd_mbox_config_profile_set_flood_mode
  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_flood_mode, 0x0C, 8, 1);
  554. /* cmd_mbox_config_profile_set_max_flood_tables
  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_flood_tables, 0x0C, 9, 1);
  559. /* cmd_mbox_config_profile_set_max_ib_mc
  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, set_max_ib_mc, 0x0C, 12, 1);
  564. /* cmd_mbox_config_profile_set_max_pkey
  565. * Capability bit. Setting a bit to 1 configures the profile
  566. * according to the mailbox contents.
  567. */
  568. MLXSW_ITEM32(cmd_mbox, config_profile, set_max_pkey, 0x0C, 13, 1);
  569. /* cmd_mbox_config_profile_set_adaptive_routing_group_cap
  570. * Capability bit. Setting a bit to 1 configures the profile
  571. * according to the mailbox contents.
  572. */
  573. MLXSW_ITEM32(cmd_mbox, config_profile,
  574. set_adaptive_routing_group_cap, 0x0C, 14, 1);
  575. /* cmd_mbox_config_profile_set_ar_sec
  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_ar_sec, 0x0C, 15, 1);
  580. /* cmd_mbox_config_profile_set_ubridge
  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_ubridge, 0x0C, 22, 1);
  585. /* cmd_mbox_config_profile_set_kvd_linear_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_linear_size, 0x0C, 24, 1);
  590. /* cmd_mbox_config_profile_set_kvd_hash_single_size
  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_kvd_hash_single_size, 0x0C, 25, 1);
  595. /* cmd_mbox_config_profile_set_kvd_hash_double_size
  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_kvd_hash_double_size, 0x0C, 26, 1);
  600. /* cmd_mbox_config_profile_set_cqe_version
  601. * Capability bit. Setting a bit to 1 configures the profile
  602. * according to the mailbox contents.
  603. */
  604. MLXSW_ITEM32(cmd_mbox, config_profile, set_cqe_version, 0x08, 0, 1);
  605. /* cmd_mbox_config_profile_set_cqe_time_stamp_type
  606. * Capability bit. Setting a bit to 1 configures the profile
  607. * according to the mailbox contents.
  608. */
  609. MLXSW_ITEM32(cmd_mbox, config_profile, set_cqe_time_stamp_type, 0x08, 2, 1);
  610. /* cmd_mbox_config_profile_set_lag_mode
  611. * Capability bit. Setting a bit to 1 configures the lag_mode
  612. * according to the mailbox contents.
  613. */
  614. MLXSW_ITEM32(cmd_mbox, config_profile, set_lag_mode, 0x08, 7, 1);
  615. /* cmd_mbox_config_profile_max_vepa_channels
  616. * Maximum number of VEPA channels per port (0 through 16)
  617. * 0 - multi-channel VEPA is disabled
  618. */
  619. MLXSW_ITEM32(cmd_mbox, config_profile, max_vepa_channels, 0x10, 0, 8);
  620. /* cmd_mbox_config_profile_max_lag
  621. * Maximum number of LAG IDs requested.
  622. * Reserved when Spectrum-1/2/3, supported from Spectrum-4 and above.
  623. * For Spectrum-4, firmware sets 128 for values between 1-128 and 256 for values
  624. * between 129-256.
  625. */
  626. MLXSW_ITEM32(cmd_mbox, config_profile, max_lag, 0x14, 0, 16);
  627. /* cmd_mbox_config_profile_max_port_per_lag
  628. * Maximum number of ports per LAG requested.
  629. */
  630. MLXSW_ITEM32(cmd_mbox, config_profile, max_port_per_lag, 0x18, 0, 16);
  631. /* cmd_mbox_config_profile_max_mid
  632. * Maximum Multicast IDs.
  633. * Multicast IDs are allocated from 0 to max_mid-1
  634. */
  635. MLXSW_ITEM32(cmd_mbox, config_profile, max_mid, 0x1C, 0, 16);
  636. /* cmd_mbox_config_profile_max_pgt
  637. * Maximum records in the Port Group Table per Switch Partition.
  638. * Port Group Table indexes are from 0 to max_pgt-1
  639. */
  640. MLXSW_ITEM32(cmd_mbox, config_profile, max_pgt, 0x20, 0, 16);
  641. /* cmd_mbox_config_profile_max_system_port
  642. * The maximum number of system ports that can be allocated.
  643. */
  644. MLXSW_ITEM32(cmd_mbox, config_profile, max_system_port, 0x24, 0, 16);
  645. /* cmd_mbox_config_profile_max_vlan_groups
  646. * Maximum number VLAN Groups for VLAN binding.
  647. */
  648. MLXSW_ITEM32(cmd_mbox, config_profile, max_vlan_groups, 0x28, 0, 12);
  649. /* cmd_mbox_config_profile_max_regions
  650. * Maximum number of TCAM Regions.
  651. */
  652. MLXSW_ITEM32(cmd_mbox, config_profile, max_regions, 0x2C, 0, 16);
  653. /* cmd_mbox_config_profile_max_flood_tables
  654. * Maximum number of single-entry flooding tables. Different flooding tables
  655. * can be associated with different packet types.
  656. */
  657. MLXSW_ITEM32(cmd_mbox, config_profile, max_flood_tables, 0x30, 16, 4);
  658. /* cmd_mbox_config_profile_max_vid_flood_tables
  659. * Maximum number of per-vid flooding tables. Flooding tables are associated
  660. * to the different packet types for the different switch partitions.
  661. * Table size is 4K entries covering all VID space.
  662. */
  663. MLXSW_ITEM32(cmd_mbox, config_profile, max_vid_flood_tables, 0x30, 8, 4);
  664. enum mlxsw_cmd_mbox_config_profile_flood_mode {
  665. /* Mixed mode, where:
  666. * max_flood_tables indicates the number of single-entry tables.
  667. * max_vid_flood_tables indicates the number of per-VID tables.
  668. * max_fid_offset_flood_tables indicates the number of FID-offset
  669. * tables. max_fid_flood_tables indicates the number of per-FID tables.
  670. * Reserved when unified bridge model is used.
  671. */
  672. MLXSW_CMD_MBOX_CONFIG_PROFILE_FLOOD_MODE_MIXED = 3,
  673. /* Controlled flood tables. Reserved when legacy bridge model is
  674. * used.
  675. */
  676. MLXSW_CMD_MBOX_CONFIG_PROFILE_FLOOD_MODE_CONTROLLED = 4,
  677. /* CFF - Compressed FID Flood (CFF) mode.
  678. * Reserved when legacy bridge model is used.
  679. * Supported only by Spectrum-2+.
  680. */
  681. MLXSW_CMD_MBOX_CONFIG_PROFILE_FLOOD_MODE_CFF = 5,
  682. };
  683. /* cmd_mbox_config_profile_flood_mode
  684. * Flooding mode to use.
  685. */
  686. MLXSW_ITEM32(cmd_mbox, config_profile, flood_mode, 0x30, 0, 3);
  687. /* cmd_mbox_config_profile_max_fid_offset_flood_tables
  688. * Maximum number of FID-offset flooding tables.
  689. */
  690. MLXSW_ITEM32(cmd_mbox, config_profile,
  691. max_fid_offset_flood_tables, 0x34, 24, 4);
  692. /* cmd_mbox_config_profile_fid_offset_flood_table_size
  693. * The size (number of entries) of each FID-offset flood table.
  694. */
  695. MLXSW_ITEM32(cmd_mbox, config_profile,
  696. fid_offset_flood_table_size, 0x34, 0, 16);
  697. /* cmd_mbox_config_profile_max_fid_flood_tables
  698. * Maximum number of per-FID flooding tables.
  699. *
  700. * Note: This flooding tables cover special FIDs only (vFIDs), starting at
  701. * FID value 4K and higher.
  702. */
  703. MLXSW_ITEM32(cmd_mbox, config_profile, max_fid_flood_tables, 0x38, 24, 4);
  704. /* cmd_mbox_config_profile_fid_flood_table_size
  705. * The size (number of entries) of each per-FID table.
  706. */
  707. MLXSW_ITEM32(cmd_mbox, config_profile, fid_flood_table_size, 0x38, 0, 16);
  708. /* cmd_mbox_config_profile_max_ib_mc
  709. * Maximum number of multicast FDB records for InfiniBand
  710. * FDB (in 512 chunks) per InfiniBand switch partition.
  711. */
  712. MLXSW_ITEM32(cmd_mbox, config_profile, max_ib_mc, 0x40, 0, 15);
  713. /* cmd_mbox_config_profile_max_pkey
  714. * Maximum per port PKEY table size (for PKEY enforcement)
  715. */
  716. MLXSW_ITEM32(cmd_mbox, config_profile, max_pkey, 0x44, 0, 15);
  717. /* cmd_mbox_config_profile_ar_sec
  718. * Primary/secondary capability
  719. * Describes the number of adaptive routing sub-groups
  720. * 0 - disable primary/secondary (single group)
  721. * 1 - enable primary/secondary (2 sub-groups)
  722. * 2 - 3 sub-groups: Not supported in SwitchX, SwitchX-2
  723. * 3 - 4 sub-groups: Not supported in SwitchX, SwitchX-2
  724. */
  725. MLXSW_ITEM32(cmd_mbox, config_profile, ar_sec, 0x4C, 24, 2);
  726. /* cmd_mbox_config_profile_adaptive_routing_group_cap
  727. * Adaptive Routing Group Capability. Indicates the number of AR groups
  728. * supported. Note that when Primary/secondary is enabled, each
  729. * primary/secondary couple consumes 2 adaptive routing entries.
  730. */
  731. MLXSW_ITEM32(cmd_mbox, config_profile, adaptive_routing_group_cap, 0x4C, 0, 16);
  732. /* cmd_mbox_config_profile_arn
  733. * Adaptive Routing Notification Enable
  734. * Not supported in SwitchX, SwitchX-2
  735. */
  736. MLXSW_ITEM32(cmd_mbox, config_profile, arn, 0x50, 31, 1);
  737. /* cmd_mbox_config_profile_ubridge
  738. * Unified Bridge
  739. * 0 - non unified bridge
  740. * 1 - unified bridge
  741. */
  742. MLXSW_ITEM32(cmd_mbox, config_profile, ubridge, 0x50, 4, 1);
  743. enum mlxsw_cmd_mbox_config_profile_lag_mode {
  744. /* FW manages PGT LAG table */
  745. MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_FW,
  746. /* SW manages PGT LAG table */
  747. MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_SW,
  748. };
  749. /* cmd_mbox_config_profile_lag_mode
  750. * LAG mode
  751. * Configured if set_lag_mode is set
  752. * Supported from Spectrum-2 and above.
  753. * Supported only when ubridge = 1
  754. */
  755. MLXSW_ITEM32(cmd_mbox, config_profile, lag_mode, 0x50, 3, 1);
  756. /* cmd_mbox_config_kvd_linear_size
  757. * KVD Linear Size
  758. * Valid for Spectrum only
  759. * Allowed values are 128*N where N=0 or higher
  760. */
  761. MLXSW_ITEM32(cmd_mbox, config_profile, kvd_linear_size, 0x54, 0, 24);
  762. /* cmd_mbox_config_profile_kvd_hash_single_size
  763. * KVD Hash single-entries size
  764. * Valid for Spectrum only
  765. * Allowed values are 128*N where N=0 or higher
  766. * Must be greater or equal to cap_min_kvd_hash_single_size
  767. * Must be smaller or equal to cap_kvd_size - kvd_linear_size
  768. */
  769. MLXSW_ITEM32(cmd_mbox, config_profile, kvd_hash_single_size, 0x58, 0, 24);
  770. /* cmd_mbox_config_profile_kvd_hash_double_size
  771. * KVD Hash double-entries size (units of single-size entries)
  772. * Valid for Spectrum only
  773. * Allowed values are 128*N where N=0 or higher
  774. * Must be either 0 or greater or equal to cap_min_kvd_hash_double_size
  775. * Must be smaller or equal to cap_kvd_size - kvd_linear_size
  776. */
  777. MLXSW_ITEM32(cmd_mbox, config_profile, kvd_hash_double_size, 0x5C, 0, 24);
  778. /* cmd_mbox_config_profile_swid_config_mask
  779. * Modify Switch Partition Configuration mask. When set, the configu-
  780. * ration value for the Switch Partition are taken from the mailbox.
  781. * When clear, the current configuration values are used.
  782. * Bit 0 - set type
  783. * Bit 1 - properties
  784. * Other - reserved
  785. */
  786. MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_mask,
  787. 0x60, 24, 8, 0x08, 0x00, false);
  788. /* cmd_mbox_config_profile_swid_config_type
  789. * Switch Partition type.
  790. * 0000 - disabled (Switch Partition does not exist)
  791. * 0001 - InfiniBand
  792. * 0010 - Ethernet
  793. * 1000 - router port (SwitchX-2 only)
  794. * Other - reserved
  795. */
  796. MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_type,
  797. 0x60, 20, 4, 0x08, 0x00, false);
  798. /* cmd_mbox_config_profile_swid_config_properties
  799. * Switch Partition properties.
  800. */
  801. MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_properties,
  802. 0x60, 0, 8, 0x08, 0x00, false);
  803. enum mlxsw_cmd_mbox_config_profile_cqe_time_stamp_type {
  804. /* uSec - 1.024uSec (default). Only bits 15:0 are valid. */
  805. MLXSW_CMD_MBOX_CONFIG_PROFILE_CQE_TIME_STAMP_TYPE_USEC,
  806. /* FRC - Free Running Clock, units of 1nSec.
  807. * Reserved when SwitchX/-2, Switch-IB/2 and Spectrum-1.
  808. */
  809. MLXSW_CMD_MBOX_CONFIG_PROFILE_CQE_TIME_STAMP_TYPE_FRC,
  810. /* UTC. time_stamp[37:30] = Sec, time_stamp[29:0] = nSec.
  811. * Reserved when SwitchX/2, Switch-IB/2 and Spectrum-1.
  812. */
  813. MLXSW_CMD_MBOX_CONFIG_PROFILE_CQE_TIME_STAMP_TYPE_UTC,
  814. };
  815. /* cmd_mbox_config_profile_cqe_time_stamp_type
  816. * CQE time_stamp_type for non-mirror-packets.
  817. * Configured if set_cqe_time_stamp_type is set.
  818. * Reserved when SwitchX/-2, Switch-IB/2 and Spectrum-1.
  819. */
  820. MLXSW_ITEM32(cmd_mbox, config_profile, cqe_time_stamp_type, 0xB0, 8, 2);
  821. /* cmd_mbox_config_profile_cqe_version
  822. * CQE version:
  823. * 0: CQE version is 0
  824. * 1: CQE version is either 1 or 2
  825. * CQE ver 1 or 2 is configured by Completion Queue Context field cqe_ver.
  826. */
  827. MLXSW_ITEM32(cmd_mbox, config_profile, cqe_version, 0xB0, 0, 8);
  828. /* ACCESS_REG - Access EMAD Supported Register
  829. * ----------------------------------
  830. * OpMod == 0 (N/A), INMmod == 0 (N/A)
  831. * -------------------------------------
  832. * The ACCESS_REG command supports accessing device registers. This access
  833. * is mainly used for bootstrapping.
  834. */
  835. static inline int mlxsw_cmd_access_reg(struct mlxsw_core *mlxsw_core,
  836. bool reset_ok,
  837. char *in_mbox, char *out_mbox)
  838. {
  839. return mlxsw_cmd_exec(mlxsw_core, MLXSW_CMD_OPCODE_ACCESS_REG,
  840. 0, 0, false, reset_ok,
  841. in_mbox, MLXSW_CMD_MBOX_SIZE,
  842. out_mbox, MLXSW_CMD_MBOX_SIZE);
  843. }
  844. /* SW2HW_DQ - Software to Hardware DQ
  845. * ----------------------------------
  846. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  847. * INMmod == DQ number
  848. * ----------------------------------------------
  849. * The SW2HW_DQ command transitions a descriptor queue from software to
  850. * hardware ownership. The command enables posting WQEs and ringing DoorBells
  851. * on the descriptor queue.
  852. */
  853. static inline int __mlxsw_cmd_sw2hw_dq(struct mlxsw_core *mlxsw_core,
  854. char *in_mbox, u32 dq_number,
  855. u8 opcode_mod)
  856. {
  857. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_SW2HW_DQ,
  858. opcode_mod, dq_number,
  859. in_mbox, MLXSW_CMD_MBOX_SIZE);
  860. }
  861. enum {
  862. MLXSW_CMD_OPCODE_MOD_SDQ = 0,
  863. MLXSW_CMD_OPCODE_MOD_RDQ = 1,
  864. };
  865. static inline int mlxsw_cmd_sw2hw_sdq(struct mlxsw_core *mlxsw_core,
  866. char *in_mbox, u32 dq_number)
  867. {
  868. return __mlxsw_cmd_sw2hw_dq(mlxsw_core, in_mbox, dq_number,
  869. MLXSW_CMD_OPCODE_MOD_SDQ);
  870. }
  871. static inline int mlxsw_cmd_sw2hw_rdq(struct mlxsw_core *mlxsw_core,
  872. char *in_mbox, u32 dq_number)
  873. {
  874. return __mlxsw_cmd_sw2hw_dq(mlxsw_core, in_mbox, dq_number,
  875. MLXSW_CMD_OPCODE_MOD_RDQ);
  876. }
  877. /* cmd_mbox_sw2hw_dq_cq
  878. * Number of the CQ that this Descriptor Queue reports completions to.
  879. */
  880. MLXSW_ITEM32(cmd_mbox, sw2hw_dq, cq, 0x00, 24, 8);
  881. enum mlxsw_cmd_mbox_sw2hw_dq_sdq_lp {
  882. MLXSW_CMD_MBOX_SW2HW_DQ_SDQ_LP_WQE,
  883. MLXSW_CMD_MBOX_SW2HW_DQ_SDQ_LP_IGNORE_WQE,
  884. };
  885. /* cmd_mbox_sw2hw_dq_sdq_lp
  886. * SDQ local Processing
  887. * 0: local processing by wqe.lp
  888. * 1: local processing (ignoring wqe.lp)
  889. */
  890. MLXSW_ITEM32(cmd_mbox, sw2hw_dq, sdq_lp, 0x00, 23, 1);
  891. /* cmd_mbox_sw2hw_dq_sdq_tclass
  892. * SDQ: CPU Egress TClass
  893. * RDQ: Reserved
  894. */
  895. MLXSW_ITEM32(cmd_mbox, sw2hw_dq, sdq_tclass, 0x00, 16, 6);
  896. /* cmd_mbox_sw2hw_dq_log2_dq_sz
  897. * Log (base 2) of the Descriptor Queue size in 4KB pages.
  898. */
  899. MLXSW_ITEM32(cmd_mbox, sw2hw_dq, log2_dq_sz, 0x00, 0, 6);
  900. /* cmd_mbox_sw2hw_dq_pa
  901. * Physical Address.
  902. */
  903. MLXSW_ITEM64_INDEXED(cmd_mbox, sw2hw_dq, pa, 0x10, 12, 52, 0x08, 0x00, true);
  904. /* HW2SW_DQ - Hardware to Software DQ
  905. * ----------------------------------
  906. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  907. * INMmod == DQ number
  908. * ----------------------------------------------
  909. * The HW2SW_DQ command transitions a descriptor queue from hardware to
  910. * software ownership. Incoming packets on the DQ are silently discarded,
  911. * SW should not post descriptors on nonoperational DQs.
  912. */
  913. static inline int __mlxsw_cmd_hw2sw_dq(struct mlxsw_core *mlxsw_core,
  914. u32 dq_number, u8 opcode_mod)
  915. {
  916. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_HW2SW_DQ,
  917. opcode_mod, dq_number);
  918. }
  919. static inline int mlxsw_cmd_hw2sw_sdq(struct mlxsw_core *mlxsw_core,
  920. u32 dq_number)
  921. {
  922. return __mlxsw_cmd_hw2sw_dq(mlxsw_core, dq_number,
  923. MLXSW_CMD_OPCODE_MOD_SDQ);
  924. }
  925. static inline int mlxsw_cmd_hw2sw_rdq(struct mlxsw_core *mlxsw_core,
  926. u32 dq_number)
  927. {
  928. return __mlxsw_cmd_hw2sw_dq(mlxsw_core, dq_number,
  929. MLXSW_CMD_OPCODE_MOD_RDQ);
  930. }
  931. /* 2ERR_DQ - To Error DQ
  932. * ---------------------
  933. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  934. * INMmod == DQ number
  935. * ----------------------------------------------
  936. * The 2ERR_DQ command transitions the DQ into the error state from the state
  937. * in which it has been. While the command is executed, some in-process
  938. * descriptors may complete. Once the DQ transitions into the error state,
  939. * if there are posted descriptors on the RDQ/SDQ, the hardware writes
  940. * a completion with error (flushed) for all descriptors posted in the RDQ/SDQ.
  941. * When the command is completed successfully, the DQ is already in
  942. * the error state.
  943. */
  944. static inline int __mlxsw_cmd_2err_dq(struct mlxsw_core *mlxsw_core,
  945. u32 dq_number, u8 opcode_mod)
  946. {
  947. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_2ERR_DQ,
  948. opcode_mod, dq_number);
  949. }
  950. static inline int mlxsw_cmd_2err_sdq(struct mlxsw_core *mlxsw_core,
  951. u32 dq_number)
  952. {
  953. return __mlxsw_cmd_2err_dq(mlxsw_core, dq_number,
  954. MLXSW_CMD_OPCODE_MOD_SDQ);
  955. }
  956. static inline int mlxsw_cmd_2err_rdq(struct mlxsw_core *mlxsw_core,
  957. u32 dq_number)
  958. {
  959. return __mlxsw_cmd_2err_dq(mlxsw_core, dq_number,
  960. MLXSW_CMD_OPCODE_MOD_RDQ);
  961. }
  962. /* QUERY_DQ - Query DQ
  963. * ---------------------
  964. * OpMod == 0 (send DQ) / OpMod == 1 (receive DQ)
  965. * INMmod == DQ number
  966. * ----------------------------------------------
  967. * The QUERY_DQ command retrieves a snapshot of DQ parameters from the hardware.
  968. *
  969. * Note: Output mailbox has the same format as SW2HW_DQ.
  970. */
  971. static inline int __mlxsw_cmd_query_dq(struct mlxsw_core *mlxsw_core,
  972. char *out_mbox, u32 dq_number,
  973. u8 opcode_mod)
  974. {
  975. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_2ERR_DQ,
  976. opcode_mod, dq_number, false,
  977. out_mbox, MLXSW_CMD_MBOX_SIZE);
  978. }
  979. static inline int mlxsw_cmd_query_sdq(struct mlxsw_core *mlxsw_core,
  980. char *out_mbox, u32 dq_number)
  981. {
  982. return __mlxsw_cmd_query_dq(mlxsw_core, out_mbox, dq_number,
  983. MLXSW_CMD_OPCODE_MOD_SDQ);
  984. }
  985. static inline int mlxsw_cmd_query_rdq(struct mlxsw_core *mlxsw_core,
  986. char *out_mbox, u32 dq_number)
  987. {
  988. return __mlxsw_cmd_query_dq(mlxsw_core, out_mbox, dq_number,
  989. MLXSW_CMD_OPCODE_MOD_RDQ);
  990. }
  991. /* SW2HW_CQ - Software to Hardware CQ
  992. * ----------------------------------
  993. * OpMod == 0 (N/A), INMmod == CQ number
  994. * -------------------------------------
  995. * The SW2HW_CQ command transfers ownership of a CQ context entry from software
  996. * to hardware. The command takes the CQ context entry from the input mailbox
  997. * and stores it in the CQC in the ownership of the hardware. The command fails
  998. * if the requested CQC entry is already in the ownership of the hardware.
  999. */
  1000. static inline int mlxsw_cmd_sw2hw_cq(struct mlxsw_core *mlxsw_core,
  1001. char *in_mbox, u32 cq_number)
  1002. {
  1003. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_SW2HW_CQ,
  1004. 0, cq_number, in_mbox, MLXSW_CMD_MBOX_SIZE);
  1005. }
  1006. enum mlxsw_cmd_mbox_sw2hw_cq_cqe_ver {
  1007. MLXSW_CMD_MBOX_SW2HW_CQ_CQE_VER_1,
  1008. MLXSW_CMD_MBOX_SW2HW_CQ_CQE_VER_2,
  1009. };
  1010. /* cmd_mbox_sw2hw_cq_cqe_ver
  1011. * CQE Version.
  1012. */
  1013. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, cqe_ver, 0x00, 28, 4);
  1014. /* cmd_mbox_sw2hw_cq_c_eqn
  1015. * Event Queue this CQ reports completion events to.
  1016. */
  1017. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, c_eqn, 0x00, 24, 1);
  1018. /* cmd_mbox_sw2hw_cq_st
  1019. * Event delivery state machine
  1020. * 0x0 - FIRED
  1021. * 0x1 - ARMED (Request for Notification)
  1022. */
  1023. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, st, 0x00, 8, 1);
  1024. /* cmd_mbox_sw2hw_cq_log_cq_size
  1025. * Log (base 2) of the CQ size (in entries).
  1026. */
  1027. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, log_cq_size, 0x00, 0, 4);
  1028. /* cmd_mbox_sw2hw_cq_producer_counter
  1029. * Producer Counter. The counter is incremented for each CQE that is
  1030. * written by the HW to the CQ.
  1031. * Maintained by HW (valid for the QUERY_CQ command only)
  1032. */
  1033. MLXSW_ITEM32(cmd_mbox, sw2hw_cq, producer_counter, 0x04, 0, 16);
  1034. /* cmd_mbox_sw2hw_cq_pa
  1035. * Physical Address.
  1036. */
  1037. MLXSW_ITEM64_INDEXED(cmd_mbox, sw2hw_cq, pa, 0x10, 11, 53, 0x08, 0x00, true);
  1038. /* HW2SW_CQ - Hardware to Software CQ
  1039. * ----------------------------------
  1040. * OpMod == 0 (N/A), INMmod == CQ number
  1041. * -------------------------------------
  1042. * The HW2SW_CQ command transfers ownership of a CQ context entry from hardware
  1043. * to software. The CQC entry is invalidated as a result of this command.
  1044. */
  1045. static inline int mlxsw_cmd_hw2sw_cq(struct mlxsw_core *mlxsw_core,
  1046. u32 cq_number)
  1047. {
  1048. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_HW2SW_CQ,
  1049. 0, cq_number);
  1050. }
  1051. /* QUERY_CQ - Query CQ
  1052. * ----------------------------------
  1053. * OpMod == 0 (N/A), INMmod == CQ number
  1054. * -------------------------------------
  1055. * The QUERY_CQ command retrieves a snapshot of the current CQ context entry.
  1056. * The command stores the snapshot in the output mailbox in the software format.
  1057. * Note that the CQ context state and values are not affected by the QUERY_CQ
  1058. * command. The QUERY_CQ command is for debug purposes only.
  1059. *
  1060. * Note: Output mailbox has the same format as SW2HW_CQ.
  1061. */
  1062. static inline int mlxsw_cmd_query_cq(struct mlxsw_core *mlxsw_core,
  1063. char *out_mbox, u32 cq_number)
  1064. {
  1065. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_CQ,
  1066. 0, cq_number, false,
  1067. out_mbox, MLXSW_CMD_MBOX_SIZE);
  1068. }
  1069. /* SW2HW_EQ - Software to Hardware EQ
  1070. * ----------------------------------
  1071. * OpMod == 0 (N/A), INMmod == EQ number
  1072. * -------------------------------------
  1073. * The SW2HW_EQ command transfers ownership of an EQ context entry from software
  1074. * to hardware. The command takes the EQ context entry from the input mailbox
  1075. * and stores it in the EQC in the ownership of the hardware. The command fails
  1076. * if the requested EQC entry is already in the ownership of the hardware.
  1077. */
  1078. static inline int mlxsw_cmd_sw2hw_eq(struct mlxsw_core *mlxsw_core,
  1079. char *in_mbox, u32 eq_number)
  1080. {
  1081. return mlxsw_cmd_exec_in(mlxsw_core, MLXSW_CMD_OPCODE_SW2HW_EQ,
  1082. 0, eq_number, in_mbox, MLXSW_CMD_MBOX_SIZE);
  1083. }
  1084. /* cmd_mbox_sw2hw_eq_int_msix
  1085. * When set, MSI-X cycles will be generated by this EQ.
  1086. * When cleared, an interrupt will be generated by this EQ.
  1087. */
  1088. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, int_msix, 0x00, 24, 1);
  1089. /* cmd_mbox_sw2hw_eq_st
  1090. * Event delivery state machine
  1091. * 0x0 - FIRED
  1092. * 0x1 - ARMED (Request for Notification)
  1093. * 0x11 - Always ARMED
  1094. * other - reserved
  1095. */
  1096. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, st, 0x00, 8, 2);
  1097. /* cmd_mbox_sw2hw_eq_log_eq_size
  1098. * Log (base 2) of the EQ size (in entries).
  1099. */
  1100. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, log_eq_size, 0x00, 0, 4);
  1101. /* cmd_mbox_sw2hw_eq_producer_counter
  1102. * Producer Counter. The counter is incremented for each EQE that is written
  1103. * by the HW to the EQ.
  1104. * Maintained by HW (valid for the QUERY_EQ command only)
  1105. */
  1106. MLXSW_ITEM32(cmd_mbox, sw2hw_eq, producer_counter, 0x04, 0, 16);
  1107. /* cmd_mbox_sw2hw_eq_pa
  1108. * Physical Address.
  1109. */
  1110. MLXSW_ITEM64_INDEXED(cmd_mbox, sw2hw_eq, pa, 0x10, 11, 53, 0x08, 0x00, true);
  1111. /* HW2SW_EQ - Hardware to Software EQ
  1112. * ----------------------------------
  1113. * OpMod == 0 (N/A), INMmod == EQ number
  1114. * -------------------------------------
  1115. */
  1116. static inline int mlxsw_cmd_hw2sw_eq(struct mlxsw_core *mlxsw_core,
  1117. u32 eq_number)
  1118. {
  1119. return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_HW2SW_EQ,
  1120. 0, eq_number);
  1121. }
  1122. /* QUERY_EQ - Query EQ
  1123. * ----------------------------------
  1124. * OpMod == 0 (N/A), INMmod == EQ number
  1125. * -------------------------------------
  1126. *
  1127. * Note: Output mailbox has the same format as SW2HW_EQ.
  1128. */
  1129. static inline int mlxsw_cmd_query_eq(struct mlxsw_core *mlxsw_core,
  1130. char *out_mbox, u32 eq_number)
  1131. {
  1132. return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_EQ,
  1133. 0, eq_number, false,
  1134. out_mbox, MLXSW_CMD_MBOX_SIZE);
  1135. }
  1136. #endif