pci_hw.h 7.3 KB

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