6 * Mellanox Arbel Infiniband HCA driver
11 #include <gpxe/uaccess.h>
19 #define ARBEL_PCI_CONFIG_BAR PCI_BASE_ADDRESS_0
20 #define ARBEL_PCI_CONFIG_BAR_SIZE 0x100000
21 #define ARBEL_PCI_UAR_BAR PCI_BASE_ADDRESS_2
22 #define ARBEL_PCI_UAR_IDX 1
23 #define ARBEL_PCI_UAR_SIZE 0x1000
25 /* UAR context table (UCE) resource types */
26 #define ARBEL_UAR_RES_NONE 0x00
27 #define ARBEL_UAR_RES_CQ_CI 0x01
28 #define ARBEL_UAR_RES_CQ_ARM 0x02
29 #define ARBEL_UAR_RES_SQ 0x03
30 #define ARBEL_UAR_RES_RQ 0x04
31 #define ARBEL_UAR_RES_GROUP_SEP 0x07
33 /* Work queue entry and completion queue entry opcodes */
34 #define ARBEL_OPCODE_SEND 0x0a
35 #define ARBEL_OPCODE_RECV_ERROR 0xfe
36 #define ARBEL_OPCODE_SEND_ERROR 0xff
38 /* HCA command register opcodes */
39 #define ARBEL_HCR_QUERY_DEV_LIM 0x0003
40 #define ARBEL_HCR_QUERY_FW 0x0004
41 #define ARBEL_HCR_SW2HW_CQ 0x0016
42 #define ARBEL_HCR_HW2SW_CQ 0x0017
43 #define ARBEL_HCR_RST2INIT_QPEE 0x0019
44 #define ARBEL_HCR_INIT2RTR_QPEE 0x001a
45 #define ARBEL_HCR_RTR2RTS_QPEE 0x001b
46 #define ARBEL_HCR_2RST_QPEE 0x0021
47 #define ARBEL_HCR_MAD_IFC 0x0024
48 #define ARBEL_HCR_READ_MGM 0x0025
49 #define ARBEL_HCR_WRITE_MGM 0x0026
50 #define ARBEL_HCR_MGID_HASH 0x0027
51 #define ARBEL_HCR_RUN_FW 0x0ff6
52 #define ARBEL_HCR_UNMAP_FA 0x0ffe
53 #define ARBEL_HCR_MAP_FA 0x0fff
56 #define ARBEL_ST_UD 0x03
59 #define ARBEL_MTU_2048 0x04
61 #define ARBEL_INVALID_LKEY 0x00000100UL
64 * Datatypes that seem to be missing from the autogenerated documentation
67 struct arbelprm_mgm_hash_st {
68 pseudo_bit_t reserved0[0x00020];
70 pseudo_bit_t hash[0x00010];
71 pseudo_bit_t reserved1[0x00010];
75 * Wrapper structures for hardware datatypes
79 struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_context );
80 struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_entry );
81 struct MLX_DECLARE_STRUCT ( arbelprm_completion_with_error );
82 struct MLX_DECLARE_STRUCT ( arbelprm_cq_arm_db_record );
83 struct MLX_DECLARE_STRUCT ( arbelprm_cq_ci_db_record );
84 struct MLX_DECLARE_STRUCT ( arbelprm_hca_command_register );
85 struct MLX_DECLARE_STRUCT ( arbelprm_mad_ifc );
86 struct MLX_DECLARE_STRUCT ( arbelprm_mgm_entry );
87 struct MLX_DECLARE_STRUCT ( arbelprm_mgm_hash );
88 struct MLX_DECLARE_STRUCT ( arbelprm_qp_db_record );
89 struct MLX_DECLARE_STRUCT ( arbelprm_qp_ee_state_transitions );
90 struct MLX_DECLARE_STRUCT ( arbelprm_query_dev_lim );
91 struct MLX_DECLARE_STRUCT ( arbelprm_query_fw );
92 struct MLX_DECLARE_STRUCT ( arbelprm_queue_pair_ee_context_entry );
93 struct MLX_DECLARE_STRUCT ( arbelprm_recv_wqe_segment_next );
94 struct MLX_DECLARE_STRUCT ( arbelprm_send_doorbell );
95 struct MLX_DECLARE_STRUCT ( arbelprm_ud_address_vector );
96 struct MLX_DECLARE_STRUCT ( arbelprm_virtual_physical_mapping );
97 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ctrl_send );
98 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_data_ptr );
99 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_next );
100 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ud );
103 * Composite hardware datatypes
107 #define ARBEL_MAX_GATHER 1
109 struct arbelprm_ud_send_wqe {
110 struct arbelprm_wqe_segment_next next;
111 struct arbelprm_wqe_segment_ctrl_send ctrl;
112 struct arbelprm_wqe_segment_ud ud;
113 struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_GATHER];
114 } __attribute__ (( packed ));
116 #define ARBEL_MAX_SCATTER 1
118 struct arbelprm_recv_wqe {
119 /* The autogenerated header is inconsistent between send and
120 * receive WQEs. The "ctrl" structure for receive WQEs is
121 * defined to include the "next" structure. Since the "ctrl"
122 * part of the "ctrl" structure contains only "reserved, must
123 * be zero" bits, we ignore its definition and provide
124 * something more usable.
126 struct arbelprm_recv_wqe_segment_next next;
127 uint32_t ctrl[2]; /* All "reserved, must be zero" */
128 struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_SCATTER];
129 } __attribute__ (( packed ));
131 union arbelprm_completion_entry {
132 struct arbelprm_completion_queue_entry normal;
133 struct arbelprm_completion_with_error error;
134 } __attribute__ (( packed ));
136 union arbelprm_doorbell_record {
137 struct arbelprm_cq_arm_db_record cq_arm;
138 struct arbelprm_cq_ci_db_record cq_ci;
139 struct arbelprm_qp_db_record qp;
140 } __attribute__ (( packed ));
142 union arbelprm_doorbell_register {
143 struct arbelprm_send_doorbell send;
145 } __attribute__ (( packed ));
148 struct arbelprm_mad_ifc ifc;
150 } __attribute__ (( packed ));
153 * gPXE-specific definitions
157 /** Arbel device limits */
158 struct arbel_dev_limits {
159 /** Number of reserved QPs */
160 unsigned int reserved_qps;
161 /** Number of reserved EEs */
162 unsigned int reserved_ees;
163 /** Number of reserved MPTs */
164 unsigned int reserved_mpts;
165 /** Number of reserved MTTs */
166 unsigned int reserved_mtts;
167 /** Number of reserved CQs */
168 unsigned int reserved_cqs;
169 /** Number of reserved SRQs */
170 unsigned int reserved_srqs;
171 /** Number of reserver UARs */
172 unsigned int reserved_uars;
175 /** Alignment of Arbel send work queue entries */
176 #define ARBEL_SEND_WQE_ALIGN 128
178 /** An Arbel send work queue entry */
179 union arbel_send_wqe {
180 struct arbelprm_ud_send_wqe ud;
181 uint8_t force_align[ARBEL_SEND_WQE_ALIGN];
182 } __attribute__ (( packed ));
184 /** An Arbel send work queue */
185 struct arbel_send_work_queue {
186 /** Doorbell record number */
187 unsigned int doorbell_idx;
188 /** Work queue entries */
189 union arbel_send_wqe *wqe;
190 /** Size of work queue */
194 /** Alignment of Arbel receive work queue entries */
195 #define ARBEL_RECV_WQE_ALIGN 64
197 /** An Arbel receive work queue entry */
198 union arbel_recv_wqe {
199 struct arbelprm_recv_wqe recv;
200 uint8_t force_align[ARBEL_RECV_WQE_ALIGN];
201 } __attribute__ (( packed ));
203 /** An Arbel receive work queue */
204 struct arbel_recv_work_queue {
205 /** Doorbell record number */
206 unsigned int doorbell_idx;
207 /** Work queue entries */
208 union arbel_recv_wqe *wqe;
209 /** Size of work queue */
213 /** Maximum number of allocatable queue pairs
215 * This is a policy decision, not a device limit.
217 #define ARBEL_MAX_QPS 8
219 /** Base queue pair number */
220 #define ARBEL_QPN_BASE 0x550000
222 /** An Arbel queue pair */
223 struct arbel_queue_pair {
224 /** Send work queue */
225 struct arbel_send_work_queue send;
226 /** Receive work queue */
227 struct arbel_recv_work_queue recv;
230 /** Maximum number of allocatable completion queues
232 * This is a policy decision, not a device limit.
234 #define ARBEL_MAX_CQS 8
236 /** An Arbel completion queue */
237 struct arbel_completion_queue {
238 /** Consumer counter doorbell record number */
239 unsigned int ci_doorbell_idx;
240 /** Arm queue doorbell record number */
241 unsigned int arm_doorbell_idx;
242 /** Completion queue entries */
243 union arbelprm_completion_entry *cqe;
244 /** Size of completion queue */
248 /** An Arbel resource bitmask */
249 typedef uint32_t arbel_bitmask_t;
251 /** Size of an Arbel resource bitmask */
252 #define ARBEL_BITMASK_SIZE(max_entries) \
253 ( ( (max_entries) + ( 8 * sizeof ( arbel_bitmask_t ) ) - 1 ) / \
254 ( 8 * sizeof ( arbel_bitmask_t ) ) )
256 /** An Arbel device */
258 /** PCI configuration registers */
260 /** PCI user Access Region */
263 /** Command input mailbox */
265 /** Command output mailbox */
268 /** Firmware area in external memory */
269 userptr_t firmware_area;
271 /** Doorbell records */
272 union arbelprm_doorbell_record *db_rec;
275 * Used to get unrestricted memory access.
277 unsigned long reserved_lkey;
278 /** Event queue number */
281 /** Completion queue in-use bitmask */
282 arbel_bitmask_t cq_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_CQS ) ];
283 /** Queue pair in-use bitmask */
284 arbel_bitmask_t qp_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_QPS ) ];
287 struct arbel_dev_limits limits;
290 /** Global protection domain */
291 #define ARBEL_GLOBAL_PD 0x123456
298 #define ARBEL_HCR_BASE 0x80680
299 #define ARBEL_HCR_REG(x) ( ARBEL_HCR_BASE + 4 * (x) )
300 #define ARBEL_HCR_MAX_WAIT_MS 2000
301 #define ARBEL_MBOX_ALIGN 4096
302 #define ARBEL_MBOX_SIZE 512
304 /* HCA command is split into
307 * bit 12 Input uses mailbox
308 * bit 13 Output uses mailbox
309 * bits 22:14 Input parameter length (in dwords)
310 * bits 31:23 Output parameter length (in dwords)
312 * Encoding the information in this way allows us to cut out several
313 * parameters to the arbel_command() call.
315 #define ARBEL_HCR_IN_MBOX 0x00001000UL
316 #define ARBEL_HCR_OUT_MBOX 0x00002000UL
317 #define ARBEL_HCR_OPCODE( _command ) ( (_command) & 0xfff )
318 #define ARBEL_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
319 #define ARBEL_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
321 /** Build HCR command from component parts */
322 #define ARBEL_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len, \
323 _out_mbox, _out_len ) \
325 ( (_in_mbox) ? ARBEL_HCR_IN_MBOX : 0 ) | \
326 ( ( (_in_len) / 4 ) << 14 ) | \
327 ( (_out_mbox) ? ARBEL_HCR_OUT_MBOX : 0 ) | \
328 ( ( (_out_len) / 4 ) << 23 ) )
330 #define ARBEL_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
331 ARBEL_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
333 #define ARBEL_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
334 ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
336 #define ARBEL_HCR_VOID_CMD( _opcode ) \
337 ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
340 * Doorbell record allocation
342 * The doorbell record map looks like:
344 * ARBEL_MAX_CQS * Arm completion queue doorbell
345 * ARBEL_MAX_QPS * Send work request doorbell
347 * ...(empty space)...
348 * ARBEL_MAX_QPS * Receive work request doorbell
349 * ARBEL_MAX_CQS * Completion queue consumer counter update doorbell
352 #define ARBEL_MAX_DOORBELL_RECORDS 512
353 #define ARBEL_GROUP_SEPARATOR_DOORBELL ( ARBEL_MAX_CQS + ARBEL_MAX_QPS )
356 * Get arm completion queue doorbell index
358 * @v cqn_offset Completion queue number offset
359 * @ret doorbell_idx Doorbell index
361 static inline unsigned int
362 arbel_cq_arm_doorbell_idx ( unsigned int cqn_offset ) {
367 * Get send work request doorbell index
369 * @v qpn_offset Queue pair number offset
370 * @ret doorbell_idx Doorbell index
372 static inline unsigned int
373 arbel_send_doorbell_idx ( unsigned int qpn_offset ) {
374 return ( ARBEL_MAX_CQS + qpn_offset );
378 * Get receive work request doorbell index
380 * @v qpn_offset Queue pair number offset
381 * @ret doorbell_idx Doorbell index
383 static inline unsigned int
384 arbel_recv_doorbell_idx ( unsigned int qpn_offset ) {
385 return ( ARBEL_MAX_DOORBELL_RECORDS - ARBEL_MAX_CQS - qpn_offset - 1 );
389 * Get completion queue consumer counter doorbell index
391 * @v cqn_offset Completion queue number offset
392 * @ret doorbell_idx Doorbell index
394 static inline unsigned int
395 arbel_cq_ci_doorbell_idx ( unsigned int cqn_offset ) {
396 return ( ARBEL_MAX_DOORBELL_RECORDS - cqn_offset - 1 );
399 #endif /* _ARBEL_H */