pci_hw.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
  2. /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
  3. #ifndef _MLXSW_PCI_HW_H
  4. #define _MLXSW_PCI_HW_H
  5. #include <linux/bitops.h>
  6. #include "item.h"
  7. #define MLXSW_PCI_BAR0_SIZE (1024 * 1024) /* 1MB */
  8. #define MLXSW_PCI_PAGE_SIZE 4096
  9. #define MLXSW_PCI_CIR_BASE 0x71000
  10. #define MLXSW_PCI_CIR_IN_PARAM_HI MLXSW_PCI_CIR_BASE
  11. #define MLXSW_PCI_CIR_IN_PARAM_LO (MLXSW_PCI_CIR_BASE + 0x04)
  12. #define MLXSW_PCI_CIR_IN_MODIFIER (MLXSW_PCI_CIR_BASE + 0x08)
  13. #define MLXSW_PCI_CIR_OUT_PARAM_HI (MLXSW_PCI_CIR_BASE + 0x0C)
  14. #define MLXSW_PCI_CIR_OUT_PARAM_LO (MLXSW_PCI_CIR_BASE + 0x10)
  15. #define MLXSW_PCI_CIR_TOKEN (MLXSW_PCI_CIR_BASE + 0x14)
  16. #define MLXSW_PCI_CIR_CTRL (MLXSW_PCI_CIR_BASE + 0x18)
  17. #define MLXSW_PCI_CIR_CTRL_GO_BIT BIT(23)
  18. #define MLXSW_PCI_CIR_CTRL_EVREQ_BIT BIT(22)
  19. #define MLXSW_PCI_CIR_CTRL_OPCODE_MOD_SHIFT 12
  20. #define MLXSW_PCI_CIR_CTRL_STATUS_SHIFT 24
  21. #define MLXSW_PCI_CIR_TIMEOUT_MSECS 1000
  22. #define MLXSW_PCI_SW_RESET 0xF0010
  23. #define MLXSW_PCI_SW_RESET_RST_BIT BIT(0)
  24. #define MLXSW_PCI_SW_RESET_TIMEOUT_MSECS 20000
  25. #define MLXSW_PCI_SW_RESET_WAIT_MSECS 100
  26. #define MLXSW_PCI_FW_READY 0xA1844
  27. #define MLXSW_PCI_FW_READY_MASK 0xFFFF
  28. #define MLXSW_PCI_FW_READY_MAGIC 0x5E
  29. #define MLXSW_PCI_DOORBELL_SDQ_OFFSET 0x000
  30. #define MLXSW_PCI_DOORBELL_RDQ_OFFSET 0x200
  31. #define MLXSW_PCI_DOORBELL_CQ_OFFSET 0x400
  32. #define MLXSW_PCI_DOORBELL_EQ_OFFSET 0x600
  33. #define MLXSW_PCI_DOORBELL_ARM_CQ_OFFSET 0x800
  34. #define MLXSW_PCI_DOORBELL_ARM_EQ_OFFSET 0xA00
  35. #define MLXSW_PCI_DOORBELL(offset, type_offset, num) \
  36. ((offset) + (type_offset) + (num) * 4)
  37. #define MLXSW_PCI_CQS_MAX 96
  38. #define MLXSW_PCI_EQS_COUNT 2
  39. #define MLXSW_PCI_EQ_ASYNC_NUM 0
  40. #define MLXSW_PCI_EQ_COMP_NUM 1
  41. #define MLXSW_PCI_AQ_PAGES 8
  42. #define MLXSW_PCI_AQ_SIZE (MLXSW_PCI_PAGE_SIZE * MLXSW_PCI_AQ_PAGES)
  43. #define MLXSW_PCI_WQE_SIZE 32 /* 32 bytes per element */
  44. #define MLXSW_PCI_CQE01_SIZE 16 /* 16 bytes per element */
  45. #define MLXSW_PCI_CQE2_SIZE 32 /* 32 bytes per element */
  46. #define MLXSW_PCI_CQE_SIZE_MAX MLXSW_PCI_CQE2_SIZE
  47. #define MLXSW_PCI_EQE_SIZE 16 /* 16 bytes per element */
  48. #define MLXSW_PCI_WQE_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_WQE_SIZE)
  49. #define MLXSW_PCI_CQE01_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_CQE01_SIZE)
  50. #define MLXSW_PCI_CQE2_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_CQE2_SIZE)
  51. #define MLXSW_PCI_EQE_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_EQE_SIZE)
  52. #define MLXSW_PCI_EQE_UPDATE_COUNT 0x80
  53. #define MLXSW_PCI_WQE_SG_ENTRIES 3
  54. #define MLXSW_PCI_WQE_TYPE_ETHERNET 0xA
  55. /* pci_wqe_c
  56. * If set it indicates that a completion should be reported upon
  57. * execution of this descriptor.
  58. */
  59. MLXSW_ITEM32(pci, wqe, c, 0x00, 31, 1);
  60. /* pci_wqe_lp
  61. * Local Processing, set if packet should be processed by the local
  62. * switch hardware:
  63. * For Ethernet EMAD (Direct Route and non Direct Route) -
  64. * must be set if packet destination is local device
  65. * For InfiniBand CTL - must be set if packet destination is local device
  66. * Otherwise it must be clear
  67. * Local Process packets must not exceed the size of 2K (including payload
  68. * and headers).
  69. */
  70. MLXSW_ITEM32(pci, wqe, lp, 0x00, 30, 1);
  71. /* pci_wqe_type
  72. * Packet type.
  73. */
  74. MLXSW_ITEM32(pci, wqe, type, 0x00, 23, 4);
  75. /* pci_wqe_byte_count
  76. * Size of i-th scatter/gather entry, 0 if entry is unused.
  77. */
  78. MLXSW_ITEM16_INDEXED(pci, wqe, byte_count, 0x02, 0, 14, 0x02, 0x00, false);
  79. /* pci_wqe_address
  80. * Physical address of i-th scatter/gather entry.
  81. * Gather Entries must be 2Byte aligned.
  82. */
  83. MLXSW_ITEM64_INDEXED(pci, wqe, address, 0x08, 0, 64, 0x8, 0x0, false);
  84. enum mlxsw_pci_cqe_v {
  85. MLXSW_PCI_CQE_V0,
  86. MLXSW_PCI_CQE_V1,
  87. MLXSW_PCI_CQE_V2,
  88. };
  89. #define mlxsw_pci_cqe_item_helpers(name, v0, v1, v2) \
  90. static inline u32 mlxsw_pci_cqe_##name##_get(enum mlxsw_pci_cqe_v v, char *cqe) \
  91. { \
  92. switch (v) { \
  93. default: \
  94. case MLXSW_PCI_CQE_V0: \
  95. return mlxsw_pci_cqe##v0##_##name##_get(cqe); \
  96. case MLXSW_PCI_CQE_V1: \
  97. return mlxsw_pci_cqe##v1##_##name##_get(cqe); \
  98. case MLXSW_PCI_CQE_V2: \
  99. return mlxsw_pci_cqe##v2##_##name##_get(cqe); \
  100. } \
  101. } \
  102. static inline void mlxsw_pci_cqe_##name##_set(enum mlxsw_pci_cqe_v v, \
  103. char *cqe, u32 val) \
  104. { \
  105. switch (v) { \
  106. default: \
  107. case MLXSW_PCI_CQE_V0: \
  108. mlxsw_pci_cqe##v0##_##name##_set(cqe, val); \
  109. break; \
  110. case MLXSW_PCI_CQE_V1: \
  111. mlxsw_pci_cqe##v1##_##name##_set(cqe, val); \
  112. break; \
  113. case MLXSW_PCI_CQE_V2: \
  114. mlxsw_pci_cqe##v2##_##name##_set(cqe, val); \
  115. break; \
  116. } \
  117. }
  118. /* pci_cqe_lag
  119. * Packet arrives from a port which is a LAG
  120. */
  121. MLXSW_ITEM32(pci, cqe0, lag, 0x00, 23, 1);
  122. MLXSW_ITEM32(pci, cqe12, lag, 0x00, 24, 1);
  123. mlxsw_pci_cqe_item_helpers(lag, 0, 12, 12);
  124. /* pci_cqe_system_port/lag_id
  125. * When lag=0: System port on which the packet was received
  126. * When lag=1:
  127. * bits [15:4] LAG ID on which the packet was received
  128. * bits [3:0] sub_port on which the packet was received
  129. */
  130. MLXSW_ITEM32(pci, cqe, system_port, 0x00, 0, 16);
  131. MLXSW_ITEM32(pci, cqe0, lag_id, 0x00, 4, 12);
  132. MLXSW_ITEM32(pci, cqe12, lag_id, 0x00, 0, 16);
  133. mlxsw_pci_cqe_item_helpers(lag_id, 0, 12, 12);
  134. MLXSW_ITEM32(pci, cqe0, lag_subport, 0x00, 0, 4);
  135. MLXSW_ITEM32(pci, cqe12, lag_subport, 0x00, 16, 8);
  136. mlxsw_pci_cqe_item_helpers(lag_subport, 0, 12, 12);
  137. /* pci_cqe_wqe_counter
  138. * WQE count of the WQEs completed on the associated dqn
  139. */
  140. MLXSW_ITEM32(pci, cqe, wqe_counter, 0x04, 16, 16);
  141. /* pci_cqe_byte_count
  142. * Byte count of received packets including additional two
  143. * Reserved Bytes that are append to the end of the frame.
  144. * Reserved for Send CQE.
  145. */
  146. MLXSW_ITEM32(pci, cqe, byte_count, 0x04, 0, 14);
  147. /* pci_cqe_trap_id
  148. * Trap ID that captured the packet.
  149. */
  150. MLXSW_ITEM32(pci, cqe, trap_id, 0x08, 0, 9);
  151. /* pci_cqe_crc
  152. * Length include CRC. Indicates the length field includes
  153. * the packet's CRC.
  154. */
  155. MLXSW_ITEM32(pci, cqe0, crc, 0x0C, 8, 1);
  156. MLXSW_ITEM32(pci, cqe12, crc, 0x0C, 9, 1);
  157. mlxsw_pci_cqe_item_helpers(crc, 0, 12, 12);
  158. /* pci_cqe_e
  159. * CQE with Error.
  160. */
  161. MLXSW_ITEM32(pci, cqe0, e, 0x0C, 7, 1);
  162. MLXSW_ITEM32(pci, cqe12, e, 0x00, 27, 1);
  163. mlxsw_pci_cqe_item_helpers(e, 0, 12, 12);
  164. /* pci_cqe_sr
  165. * 1 - Send Queue
  166. * 0 - Receive Queue
  167. */
  168. MLXSW_ITEM32(pci, cqe0, sr, 0x0C, 6, 1);
  169. MLXSW_ITEM32(pci, cqe12, sr, 0x00, 26, 1);
  170. mlxsw_pci_cqe_item_helpers(sr, 0, 12, 12);
  171. /* pci_cqe_dqn
  172. * Descriptor Queue (DQ) Number.
  173. */
  174. MLXSW_ITEM32(pci, cqe0, dqn, 0x0C, 1, 5);
  175. MLXSW_ITEM32(pci, cqe12, dqn, 0x0C, 1, 6);
  176. mlxsw_pci_cqe_item_helpers(dqn, 0, 12, 12);
  177. /* pci_cqe_owner
  178. * Ownership bit.
  179. */
  180. MLXSW_ITEM32(pci, cqe01, owner, 0x0C, 0, 1);
  181. MLXSW_ITEM32(pci, cqe2, owner, 0x1C, 0, 1);
  182. mlxsw_pci_cqe_item_helpers(owner, 01, 01, 2);
  183. /* pci_eqe_event_type
  184. * Event type.
  185. */
  186. MLXSW_ITEM32(pci, eqe, event_type, 0x0C, 24, 8);
  187. #define MLXSW_PCI_EQE_EVENT_TYPE_COMP 0x00
  188. #define MLXSW_PCI_EQE_EVENT_TYPE_CMD 0x0A
  189. /* pci_eqe_event_sub_type
  190. * Event type.
  191. */
  192. MLXSW_ITEM32(pci, eqe, event_sub_type, 0x0C, 16, 8);
  193. /* pci_eqe_cqn
  194. * Completion Queue that triggeret this EQE.
  195. */
  196. MLXSW_ITEM32(pci, eqe, cqn, 0x0C, 8, 7);
  197. /* pci_eqe_owner
  198. * Ownership bit.
  199. */
  200. MLXSW_ITEM32(pci, eqe, owner, 0x0C, 0, 1);
  201. /* pci_eqe_cmd_token
  202. * Command completion event - token
  203. */
  204. MLXSW_ITEM32(pci, eqe, cmd_token, 0x00, 16, 16);
  205. /* pci_eqe_cmd_status
  206. * Command completion event - status
  207. */
  208. MLXSW_ITEM32(pci, eqe, cmd_status, 0x00, 0, 8);
  209. /* pci_eqe_cmd_out_param_h
  210. * Command completion event - output parameter - higher part
  211. */
  212. MLXSW_ITEM32(pci, eqe, cmd_out_param_h, 0x04, 0, 32);
  213. /* pci_eqe_cmd_out_param_l
  214. * Command completion event - output parameter - lower part
  215. */
  216. MLXSW_ITEM32(pci, eqe, cmd_out_param_l, 0x08, 0, 32);
  217. #endif