pci.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * drivers/net/ethernet/mellanox/mlxsw/pci.h
  3. * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the names of the copyright holders nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * Alternatively, this software may be distributed under the terms of the
  19. * GNU General Public License ("GPL") version 2 as published by the Free
  20. * Software Foundation.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _MLXSW_PCI_H
  35. #define _MLXSW_PCI_H
  36. #include <linux/bitops.h>
  37. #include "item.h"
  38. #define PCI_DEVICE_ID_MELLANOX_SWITCHX2 0xc738
  39. #define PCI_DEVICE_ID_MELLANOX_SPECTRUM 0xcb84
  40. #define MLXSW_PCI_BAR0_SIZE (1024 * 1024) /* 1MB */
  41. #define MLXSW_PCI_PAGE_SIZE 4096
  42. #define MLXSW_PCI_CIR_BASE 0x71000
  43. #define MLXSW_PCI_CIR_IN_PARAM_HI MLXSW_PCI_CIR_BASE
  44. #define MLXSW_PCI_CIR_IN_PARAM_LO (MLXSW_PCI_CIR_BASE + 0x04)
  45. #define MLXSW_PCI_CIR_IN_MODIFIER (MLXSW_PCI_CIR_BASE + 0x08)
  46. #define MLXSW_PCI_CIR_OUT_PARAM_HI (MLXSW_PCI_CIR_BASE + 0x0C)
  47. #define MLXSW_PCI_CIR_OUT_PARAM_LO (MLXSW_PCI_CIR_BASE + 0x10)
  48. #define MLXSW_PCI_CIR_TOKEN (MLXSW_PCI_CIR_BASE + 0x14)
  49. #define MLXSW_PCI_CIR_CTRL (MLXSW_PCI_CIR_BASE + 0x18)
  50. #define MLXSW_PCI_CIR_CTRL_GO_BIT BIT(23)
  51. #define MLXSW_PCI_CIR_CTRL_EVREQ_BIT BIT(22)
  52. #define MLXSW_PCI_CIR_CTRL_OPCODE_MOD_SHIFT 12
  53. #define MLXSW_PCI_CIR_CTRL_STATUS_SHIFT 24
  54. #define MLXSW_PCI_CIR_TIMEOUT_MSECS 1000
  55. #define MLXSW_PCI_SW_RESET 0xF0010
  56. #define MLXSW_PCI_SW_RESET_RST_BIT BIT(0)
  57. #define MLXSW_PCI_SW_RESET_TIMEOUT_MSECS 5000
  58. #define MLXSW_PCI_FW_READY 0xA1844
  59. #define MLXSW_PCI_FW_READY_MASK 0xFF
  60. #define MLXSW_PCI_FW_READY_MAGIC 0x5E
  61. #define MLXSW_PCI_DOORBELL_SDQ_OFFSET 0x000
  62. #define MLXSW_PCI_DOORBELL_RDQ_OFFSET 0x200
  63. #define MLXSW_PCI_DOORBELL_CQ_OFFSET 0x400
  64. #define MLXSW_PCI_DOORBELL_EQ_OFFSET 0x600
  65. #define MLXSW_PCI_DOORBELL_ARM_CQ_OFFSET 0x800
  66. #define MLXSW_PCI_DOORBELL_ARM_EQ_OFFSET 0xA00
  67. #define MLXSW_PCI_DOORBELL(offset, type_offset, num) \
  68. ((offset) + (type_offset) + (num) * 4)
  69. #define MLXSW_PCI_CQS_MAX 96
  70. #define MLXSW_PCI_EQS_COUNT 2
  71. #define MLXSW_PCI_EQ_ASYNC_NUM 0
  72. #define MLXSW_PCI_EQ_COMP_NUM 1
  73. #define MLXSW_PCI_AQ_PAGES 8
  74. #define MLXSW_PCI_AQ_SIZE (MLXSW_PCI_PAGE_SIZE * MLXSW_PCI_AQ_PAGES)
  75. #define MLXSW_PCI_WQE_SIZE 32 /* 32 bytes per element */
  76. #define MLXSW_PCI_CQE_SIZE 16 /* 16 bytes per element */
  77. #define MLXSW_PCI_EQE_SIZE 16 /* 16 bytes per element */
  78. #define MLXSW_PCI_WQE_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_WQE_SIZE)
  79. #define MLXSW_PCI_CQE_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_CQE_SIZE)
  80. #define MLXSW_PCI_EQE_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_EQE_SIZE)
  81. #define MLXSW_PCI_EQE_UPDATE_COUNT 0x80
  82. #define MLXSW_PCI_WQE_SG_ENTRIES 3
  83. #define MLXSW_PCI_WQE_TYPE_ETHERNET 0xA
  84. /* pci_wqe_c
  85. * If set it indicates that a completion should be reported upon
  86. * execution of this descriptor.
  87. */
  88. MLXSW_ITEM32(pci, wqe, c, 0x00, 31, 1);
  89. /* pci_wqe_lp
  90. * Local Processing, set if packet should be processed by the local
  91. * switch hardware:
  92. * For Ethernet EMAD (Direct Route and non Direct Route) -
  93. * must be set if packet destination is local device
  94. * For InfiniBand CTL - must be set if packet destination is local device
  95. * Otherwise it must be clear
  96. * Local Process packets must not exceed the size of 2K (including payload
  97. * and headers).
  98. */
  99. MLXSW_ITEM32(pci, wqe, lp, 0x00, 30, 1);
  100. /* pci_wqe_type
  101. * Packet type.
  102. */
  103. MLXSW_ITEM32(pci, wqe, type, 0x00, 23, 4);
  104. /* pci_wqe_byte_count
  105. * Size of i-th scatter/gather entry, 0 if entry is unused.
  106. */
  107. MLXSW_ITEM16_INDEXED(pci, wqe, byte_count, 0x02, 0, 14, 0x02, 0x00, false);
  108. /* pci_wqe_address
  109. * Physical address of i-th scatter/gather entry.
  110. * Gather Entries must be 2Byte aligned.
  111. */
  112. MLXSW_ITEM64_INDEXED(pci, wqe, address, 0x08, 0, 64, 0x8, 0x0, false);
  113. /* pci_cqe_lag
  114. * Packet arrives from a port which is a LAG
  115. */
  116. MLXSW_ITEM32(pci, cqe, lag, 0x00, 23, 1);
  117. /* pci_cqe_system_port/lag_id
  118. * When lag=0: System port on which the packet was received
  119. * When lag=1:
  120. * bits [15:4] LAG ID on which the packet was received
  121. * bits [3:0] sub_port on which the packet was received
  122. */
  123. MLXSW_ITEM32(pci, cqe, system_port, 0x00, 0, 16);
  124. MLXSW_ITEM32(pci, cqe, lag_id, 0x00, 4, 12);
  125. MLXSW_ITEM32(pci, cqe, lag_port_index, 0x00, 0, 4);
  126. /* pci_cqe_wqe_counter
  127. * WQE count of the WQEs completed on the associated dqn
  128. */
  129. MLXSW_ITEM32(pci, cqe, wqe_counter, 0x04, 16, 16);
  130. /* pci_cqe_byte_count
  131. * Byte count of received packets including additional two
  132. * Reserved Bytes that are append to the end of the frame.
  133. * Reserved for Send CQE.
  134. */
  135. MLXSW_ITEM32(pci, cqe, byte_count, 0x04, 0, 14);
  136. /* pci_cqe_trap_id
  137. * Trap ID that captured the packet.
  138. */
  139. MLXSW_ITEM32(pci, cqe, trap_id, 0x08, 0, 8);
  140. /* pci_cqe_crc
  141. * Length include CRC. Indicates the length field includes
  142. * the packet's CRC.
  143. */
  144. MLXSW_ITEM32(pci, cqe, crc, 0x0C, 8, 1);
  145. /* pci_cqe_e
  146. * CQE with Error.
  147. */
  148. MLXSW_ITEM32(pci, cqe, e, 0x0C, 7, 1);
  149. /* pci_cqe_sr
  150. * 1 - Send Queue
  151. * 0 - Receive Queue
  152. */
  153. MLXSW_ITEM32(pci, cqe, sr, 0x0C, 6, 1);
  154. /* pci_cqe_dqn
  155. * Descriptor Queue (DQ) Number.
  156. */
  157. MLXSW_ITEM32(pci, cqe, dqn, 0x0C, 1, 5);
  158. /* pci_cqe_owner
  159. * Ownership bit.
  160. */
  161. MLXSW_ITEM32(pci, cqe, owner, 0x0C, 0, 1);
  162. /* pci_eqe_event_type
  163. * Event type.
  164. */
  165. MLXSW_ITEM32(pci, eqe, event_type, 0x0C, 24, 8);
  166. #define MLXSW_PCI_EQE_EVENT_TYPE_COMP 0x00
  167. #define MLXSW_PCI_EQE_EVENT_TYPE_CMD 0x0A
  168. /* pci_eqe_event_sub_type
  169. * Event type.
  170. */
  171. MLXSW_ITEM32(pci, eqe, event_sub_type, 0x0C, 16, 8);
  172. /* pci_eqe_cqn
  173. * Completion Queue that triggeret this EQE.
  174. */
  175. MLXSW_ITEM32(pci, eqe, cqn, 0x0C, 8, 7);
  176. /* pci_eqe_owner
  177. * Ownership bit.
  178. */
  179. MLXSW_ITEM32(pci, eqe, owner, 0x0C, 0, 1);
  180. /* pci_eqe_cmd_token
  181. * Command completion event - token
  182. */
  183. MLXSW_ITEM32(pci, eqe, cmd_token, 0x00, 16, 16);
  184. /* pci_eqe_cmd_status
  185. * Command completion event - status
  186. */
  187. MLXSW_ITEM32(pci, eqe, cmd_status, 0x00, 0, 8);
  188. /* pci_eqe_cmd_out_param_h
  189. * Command completion event - output parameter - higher part
  190. */
  191. MLXSW_ITEM32(pci, eqe, cmd_out_param_h, 0x04, 0, 32);
  192. /* pci_eqe_cmd_out_param_l
  193. * Command completion event - output parameter - lower part
  194. */
  195. MLXSW_ITEM32(pci, eqe, cmd_out_param_l, 0x08, 0, 32);
  196. #endif