6 * Mellanox Arbel Infiniband HCA driver
15 /* UAR context table (UCE) resource types */
16 #define ARBEL_UAR_RES_NONE 0x00
17 #define ARBEL_UAR_RES_CQ_CI 0x01
18 #define ARBEL_UAR_RES_CQ_ARM 0x02
19 #define ARBEL_UAR_RES_SQ 0x03
20 #define ARBEL_UAR_RES_RQ 0x04
21 #define ARBEL_UAR_RES_GROUP_SEP 0x07
23 /* Work queue entry and completion queue entry opcodes */
24 #define ARBEL_OPCODE_SEND 0x0a
25 #define ARBEL_OPCODE_RECV_ERROR 0xfe
26 #define ARBEL_OPCODE_SEND_ERROR 0xff
28 /* HCA command register opcodes */
29 #define ARBEL_HCR_QUERY_DEV_LIM 0x0003
30 #define ARBEL_HCR_SW2HW_CQ 0x0016
31 #define ARBEL_HCR_HW2SW_CQ 0x0017
32 #define ARBEL_HCR_RST2INIT_QPEE 0x0019
33 #define ARBEL_HCR_INIT2RTR_QPEE 0x001a
34 #define ARBEL_HCR_RTR2RTS_QPEE 0x001b
35 #define ARBEL_HCR_2RST_QPEE 0x0021
38 * Wrapper structures for hardware datatypes
42 struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_context );
43 struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_entry );
44 struct MLX_DECLARE_STRUCT ( arbelprm_completion_with_error );
45 struct MLX_DECLARE_STRUCT ( arbelprm_cq_arm_db_record );
46 struct MLX_DECLARE_STRUCT ( arbelprm_cq_ci_db_record );
47 struct MLX_DECLARE_STRUCT ( arbelprm_hca_command_register );
48 struct MLX_DECLARE_STRUCT ( arbelprm_qp_db_record );
49 struct MLX_DECLARE_STRUCT ( arbelprm_query_dev_lim );
50 struct MLX_DECLARE_STRUCT ( arbelprm_queue_pair_ee_context_entry );
51 struct MLX_DECLARE_STRUCT ( arbelprm_recv_wqe_segment_next );
52 struct MLX_DECLARE_STRUCT ( arbelprm_send_doorbell );
53 struct MLX_DECLARE_STRUCT ( arbelprm_ud_address_vector );
54 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ctrl_send );
55 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_data_ptr );
56 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_next );
57 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ud );
60 * Composite hardware datatypes
64 #define ARBEL_MAX_GATHER 1
66 struct arbelprm_ud_send_wqe {
67 struct arbelprm_wqe_segment_next next;
68 struct arbelprm_wqe_segment_ctrl_send ctrl;
69 struct arbelprm_wqe_segment_ud ud;
70 struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_GATHER];
71 } __attribute__ (( packed ));
73 #define ARBEL_MAX_SCATTER 1
75 struct arbelprm_recv_wqe {
76 /* The autogenerated header is inconsistent between send and
77 * receive WQEs. The "ctrl" structure for receive WQEs is
78 * defined to include the "next" structure. Since the "ctrl"
79 * part of the "ctrl" structure contains only "reserved, must
80 * be zero" bits, we ignore its definition and provide
81 * something more usable.
83 struct arbelprm_recv_wqe_segment_next next;
84 uint32_t ctrl[2]; /* All "reserved, must be zero" */
85 struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_SCATTER];
86 } __attribute__ (( packed ));
88 union arbelprm_completion_entry {
89 struct arbelprm_completion_queue_entry normal;
90 struct arbelprm_completion_with_error error;
91 } __attribute__ (( packed ));
93 union arbelprm_doorbell_record {
94 struct arbelprm_cq_arm_db_record cq_arm;
95 struct arbelprm_cq_ci_db_record cq_ci;
96 struct arbelprm_qp_db_record qp;
97 } __attribute__ (( packed ));
99 union arbelprm_doorbell_register {
100 struct arbelprm_send_doorbell send;
102 } __attribute__ (( packed ));
105 * gPXE-specific definitions
109 /** Arbel device limits */
110 struct arbel_dev_limits {
111 /** Number of reserver UARs */
112 unsigned long reserved_uars;
113 /** Number of reserved CQs */
114 unsigned long reserved_cqs;
115 /** Number of reserved QPs */
116 unsigned long reserved_qps;
119 /** Alignment of Arbel send work queue entries */
120 #define ARBEL_SEND_WQE_ALIGN 128
122 /** An Arbel send work queue entry */
123 union arbel_send_wqe {
124 struct arbelprm_ud_send_wqe ud;
125 uint8_t force_align[ARBEL_SEND_WQE_ALIGN];
126 } __attribute__ (( packed ));
128 /** An Arbel send work queue */
129 struct arbel_send_work_queue {
130 /** Doorbell record number */
131 unsigned int doorbell_idx;
132 /** Work queue entries */
133 union arbel_send_wqe *wqe;
134 /** Size of work queue */
138 /** Alignment of Arbel receive work queue entries */
139 #define ARBEL_RECV_WQE_ALIGN 64
141 /** An Arbel receive work queue entry */
142 union arbel_recv_wqe {
143 struct arbelprm_recv_wqe recv;
144 uint8_t force_align[ARBEL_RECV_WQE_ALIGN];
145 } __attribute__ (( packed ));
147 /** An Arbel receive work queue */
148 struct arbel_recv_work_queue {
149 /** Doorbell record number */
150 unsigned int doorbell_idx;
151 /** Work queue entries */
152 union arbel_recv_wqe *wqe;
153 /** Size of work queue */
157 /** Maximum number of allocatable queue pairs
159 * This is a policy decision, not a device limit.
161 #define ARBEL_MAX_QPS 8
163 /** Base queue pair number */
164 #define ARBEL_QPN_BASE 0x550000
166 /** An Arbel queue pair */
167 struct arbel_queue_pair {
168 /** Send work queue */
169 struct arbel_send_work_queue send;
170 /** Receive work queue */
171 struct arbel_recv_work_queue recv;
174 /** Maximum number of allocatable completion queues
176 * This is a policy decision, not a device limit.
178 #define ARBEL_MAX_CQS 8
180 /** An Arbel completion queue */
181 struct arbel_completion_queue {
182 /** Consumer counter doorbell record number */
183 unsigned int ci_doorbell_idx;
184 /** Arm queue doorbell record number */
185 unsigned int arm_doorbell_idx;
186 /** Completion queue entries */
187 union arbelprm_completion_entry *cqe;
188 /** Size of completion queue */
192 /** An Arbel resource bitmask */
193 typedef uint32_t arbel_bitmask_t;
195 /** Size of an Arbel resource bitmask */
196 #define ARBEL_BITMASK_SIZE(max_entries) \
197 ( ( (max_entries) + ( 8 * sizeof ( arbel_bitmask_t ) ) - 1 ) / \
198 ( 8 * sizeof ( arbel_bitmask_t ) ) )
200 /** An Arbel device */
202 /** Configuration registers */
204 /** Command input mailbox */
206 /** Command output mailbox */
209 /** User Access Region */
211 /** Doorbell records */
212 union arbelprm_doorbell_record *db_rec;
215 * Used to get unrestricted memory access.
217 unsigned long reserved_lkey;
218 /** Event queue number */
221 /** Completion queue in-use bitmask */
222 arbel_bitmask_t cq_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_CQS ) ];
223 /** Queue pair in-use bitmask */
224 arbel_bitmask_t qp_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_QPS ) ];
227 struct arbel_dev_limits limits;
230 /** Global protection domain */
231 #define ARBEL_GLOBAL_PD 0x123456
238 #define ARBEL_HCR_BASE 0x80680
239 #define ARBEL_HCR_REG(x) ( ARBEL_HCR_BASE + 4 * (x) )
240 #define ARBEL_HCR_MAX_WAIT_MS 2000
242 /* HCA command is split into
245 * bit 12 Input uses mailbox
246 * bit 13 Output uses mailbox
247 * bits 22:14 Input parameter length (in dwords)
248 * bits 31:23 Output parameter length (in dwords)
250 * Encoding the information in this way allows us to cut out several
251 * parameters to the arbel_command() call.
253 #define ARBEL_HCR_IN_MBOX 0x00001000UL
254 #define ARBEL_HCR_OUT_MBOX 0x00002000UL
255 #define ARBEL_HCR_OPCODE( _command ) ( (_command) & 0xfff )
256 #define ARBEL_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
257 #define ARBEL_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
259 /** Build HCR command from component parts */
260 #define ARBEL_HCR_CMD( _opcode, _in_mbox, _in_len, _out_mbox, _out_len ) \
262 ( (_in_mbox) ? ARBEL_HCR_IN_MBOX : 0 ) | \
263 ( ( (_in_len) / 4 ) << 14 ) | \
264 ( (_out_mbox) ? ARBEL_HCR_OUT_MBOX : 0 ) | \
265 ( ( (_out_len) / 4 ) << 23 ) )
267 #define ARBEL_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
268 ARBEL_HCR_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
270 #define ARBEL_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
271 ARBEL_HCR_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
273 #define ARBEL_HCR_VOID_CMD( _opcode ) \
274 ARBEL_HCR_CMD ( _opcode, 0, 0, 0, 0 )
277 * Doorbell record allocation
279 * The doorbell record map looks like:
281 * ARBEL_MAX_CQS * Arm completion queue doorbell
282 * ARBEL_MAX_QPS * Send work request doorbell
284 * ...(empty space)...
285 * ARBEL_MAX_QPS * Receive work request doorbell
286 * ARBEL_MAX_CQS * Completion queue consumer counter update doorbell
289 #define ARBEL_MAX_DOORBELL_RECORDS 512
290 #define ARBEL_GROUP_SEPARATOR_DOORBELL ( ARBEL_MAX_CQS + ARBEL_MAX_QPS )
293 * Get arm completion queue doorbell index
295 * @v cqn_offset Completion queue number offset
296 * @ret doorbell_idx Doorbell index
298 static inline unsigned int
299 arbel_cq_arm_doorbell_idx ( unsigned int cqn_offset ) {
304 * Get send work request doorbell index
306 * @v qpn_offset Queue pair number offset
307 * @ret doorbell_idx Doorbell index
309 static inline unsigned int
310 arbel_send_doorbell_idx ( unsigned int qpn_offset ) {
311 return ( ARBEL_MAX_CQS + qpn_offset );
315 * Get receive work request doorbell index
317 * @v qpn_offset Queue pair number offset
318 * @ret doorbell_idx Doorbell index
320 static inline unsigned int
321 arbel_recv_doorbell_idx ( unsigned int qpn_offset ) {
322 return ( ARBEL_MAX_DOORBELL_RECORDS - ARBEL_MAX_CQS - qpn_offset - 1 );
326 * Get completion queue consumer counter doorbell index
328 * @v cqn_offset Completion queue number offset
329 * @ret doorbell_idx Doorbell index
331 static inline unsigned int
332 arbel_cq_ci_doorbell_idx ( unsigned int cqn_offset ) {
333 return ( ARBEL_MAX_DOORBELL_RECORDS - cqn_offset - 1 );
336 #endif /* _ARBEL_H */