6 * Mellanox Arbel Infiniband HCA driver
16 #define ARBEL_PCI_CONFIG_BAR PCI_BASE_ADDRESS_0
17 #define ARBEL_PCI_CONFIG_BAR_SIZE 0x100000
18 #define ARBEL_PCI_UAR_BAR PCI_BASE_ADDRESS_2
19 #define ARBEL_PCI_UAR_IDX 1
20 #define ARBEL_PCI_UAR_SIZE 0x1000
22 /* UAR context table (UCE) resource types */
23 #define ARBEL_UAR_RES_NONE 0x00
24 #define ARBEL_UAR_RES_CQ_CI 0x01
25 #define ARBEL_UAR_RES_CQ_ARM 0x02
26 #define ARBEL_UAR_RES_SQ 0x03
27 #define ARBEL_UAR_RES_RQ 0x04
28 #define ARBEL_UAR_RES_GROUP_SEP 0x07
30 /* Work queue entry and completion queue entry opcodes */
31 #define ARBEL_OPCODE_SEND 0x0a
32 #define ARBEL_OPCODE_RECV_ERROR 0xfe
33 #define ARBEL_OPCODE_SEND_ERROR 0xff
35 /* HCA command register opcodes */
36 #define ARBEL_HCR_QUERY_DEV_LIM 0x0003
37 #define ARBEL_HCR_QUERY_FW 0x0004
38 #define ARBEL_HCR_SW2HW_CQ 0x0016
39 #define ARBEL_HCR_HW2SW_CQ 0x0017
40 #define ARBEL_HCR_RST2INIT_QPEE 0x0019
41 #define ARBEL_HCR_INIT2RTR_QPEE 0x001a
42 #define ARBEL_HCR_RTR2RTS_QPEE 0x001b
43 #define ARBEL_HCR_2RST_QPEE 0x0021
44 #define ARBEL_HCR_MAD_IFC 0x0024
45 #define ARBEL_HCR_READ_MGM 0x0025
46 #define ARBEL_HCR_WRITE_MGM 0x0026
47 #define ARBEL_HCR_MGID_HASH 0x0027
50 #define ARBEL_ST_UD 0x03
53 #define ARBEL_MTU_2048 0x04
55 #define ARBEL_INVALID_LKEY 0x00000100UL
58 * Datatypes that seem to be missing from the autogenerated documentation
61 struct arbelprm_mgm_hash_st {
62 pseudo_bit_t reserved0[0x00020];
64 pseudo_bit_t hash[0x00010];
65 pseudo_bit_t reserved1[0x00010];
69 * Wrapper structures for hardware datatypes
73 struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_context );
74 struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_entry );
75 struct MLX_DECLARE_STRUCT ( arbelprm_completion_with_error );
76 struct MLX_DECLARE_STRUCT ( arbelprm_cq_arm_db_record );
77 struct MLX_DECLARE_STRUCT ( arbelprm_cq_ci_db_record );
78 struct MLX_DECLARE_STRUCT ( arbelprm_hca_command_register );
79 struct MLX_DECLARE_STRUCT ( arbelprm_mad_ifc );
80 struct MLX_DECLARE_STRUCT ( arbelprm_mgm_entry );
81 struct MLX_DECLARE_STRUCT ( arbelprm_mgm_hash );
82 struct MLX_DECLARE_STRUCT ( arbelprm_qp_db_record );
83 struct MLX_DECLARE_STRUCT ( arbelprm_qp_ee_state_transitions );
84 struct MLX_DECLARE_STRUCT ( arbelprm_query_dev_lim );
85 struct MLX_DECLARE_STRUCT ( arbelprm_query_fw );
86 struct MLX_DECLARE_STRUCT ( arbelprm_queue_pair_ee_context_entry );
87 struct MLX_DECLARE_STRUCT ( arbelprm_recv_wqe_segment_next );
88 struct MLX_DECLARE_STRUCT ( arbelprm_send_doorbell );
89 struct MLX_DECLARE_STRUCT ( arbelprm_ud_address_vector );
90 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ctrl_send );
91 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_data_ptr );
92 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_next );
93 struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ud );
96 * Composite hardware datatypes
100 #define ARBEL_MAX_GATHER 1
102 struct arbelprm_ud_send_wqe {
103 struct arbelprm_wqe_segment_next next;
104 struct arbelprm_wqe_segment_ctrl_send ctrl;
105 struct arbelprm_wqe_segment_ud ud;
106 struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_GATHER];
107 } __attribute__ (( packed ));
109 #define ARBEL_MAX_SCATTER 1
111 struct arbelprm_recv_wqe {
112 /* The autogenerated header is inconsistent between send and
113 * receive WQEs. The "ctrl" structure for receive WQEs is
114 * defined to include the "next" structure. Since the "ctrl"
115 * part of the "ctrl" structure contains only "reserved, must
116 * be zero" bits, we ignore its definition and provide
117 * something more usable.
119 struct arbelprm_recv_wqe_segment_next next;
120 uint32_t ctrl[2]; /* All "reserved, must be zero" */
121 struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_SCATTER];
122 } __attribute__ (( packed ));
124 union arbelprm_completion_entry {
125 struct arbelprm_completion_queue_entry normal;
126 struct arbelprm_completion_with_error error;
127 } __attribute__ (( packed ));
129 union arbelprm_doorbell_record {
130 struct arbelprm_cq_arm_db_record cq_arm;
131 struct arbelprm_cq_ci_db_record cq_ci;
132 struct arbelprm_qp_db_record qp;
133 } __attribute__ (( packed ));
135 union arbelprm_doorbell_register {
136 struct arbelprm_send_doorbell send;
138 } __attribute__ (( packed ));
141 struct arbelprm_mad_ifc ifc;
143 } __attribute__ (( packed ));
146 * gPXE-specific definitions
150 /** Arbel device limits */
151 struct arbel_dev_limits {
152 /** Number of reserver UARs */
153 unsigned long reserved_uars;
154 /** Number of reserved CQs */
155 unsigned long reserved_cqs;
156 /** Number of reserved QPs */
157 unsigned long reserved_qps;
160 /** Alignment of Arbel send work queue entries */
161 #define ARBEL_SEND_WQE_ALIGN 128
163 /** An Arbel send work queue entry */
164 union arbel_send_wqe {
165 struct arbelprm_ud_send_wqe ud;
166 uint8_t force_align[ARBEL_SEND_WQE_ALIGN];
167 } __attribute__ (( packed ));
169 /** An Arbel send work queue */
170 struct arbel_send_work_queue {
171 /** Doorbell record number */
172 unsigned int doorbell_idx;
173 /** Work queue entries */
174 union arbel_send_wqe *wqe;
175 /** Size of work queue */
179 /** Alignment of Arbel receive work queue entries */
180 #define ARBEL_RECV_WQE_ALIGN 64
182 /** An Arbel receive work queue entry */
183 union arbel_recv_wqe {
184 struct arbelprm_recv_wqe recv;
185 uint8_t force_align[ARBEL_RECV_WQE_ALIGN];
186 } __attribute__ (( packed ));
188 /** An Arbel receive work queue */
189 struct arbel_recv_work_queue {
190 /** Doorbell record number */
191 unsigned int doorbell_idx;
192 /** Work queue entries */
193 union arbel_recv_wqe *wqe;
194 /** Size of work queue */
198 /** Maximum number of allocatable queue pairs
200 * This is a policy decision, not a device limit.
202 #define ARBEL_MAX_QPS 8
204 /** Base queue pair number */
205 #define ARBEL_QPN_BASE 0x550000
207 /** An Arbel queue pair */
208 struct arbel_queue_pair {
209 /** Send work queue */
210 struct arbel_send_work_queue send;
211 /** Receive work queue */
212 struct arbel_recv_work_queue recv;
215 /** Maximum number of allocatable completion queues
217 * This is a policy decision, not a device limit.
219 #define ARBEL_MAX_CQS 8
221 /** An Arbel completion queue */
222 struct arbel_completion_queue {
223 /** Consumer counter doorbell record number */
224 unsigned int ci_doorbell_idx;
225 /** Arm queue doorbell record number */
226 unsigned int arm_doorbell_idx;
227 /** Completion queue entries */
228 union arbelprm_completion_entry *cqe;
229 /** Size of completion queue */
233 /** An Arbel resource bitmask */
234 typedef uint32_t arbel_bitmask_t;
236 /** Size of an Arbel resource bitmask */
237 #define ARBEL_BITMASK_SIZE(max_entries) \
238 ( ( (max_entries) + ( 8 * sizeof ( arbel_bitmask_t ) ) - 1 ) / \
239 ( 8 * sizeof ( arbel_bitmask_t ) ) )
241 /** An Arbel device */
243 /** Configuration registers */
245 /** Command input mailbox */
247 /** Command output mailbox */
250 /** User Access Region */
252 /** Doorbell records */
253 union arbelprm_doorbell_record *db_rec;
256 * Used to get unrestricted memory access.
258 unsigned long reserved_lkey;
259 /** Event queue number */
262 /** Completion queue in-use bitmask */
263 arbel_bitmask_t cq_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_CQS ) ];
264 /** Queue pair in-use bitmask */
265 arbel_bitmask_t qp_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_QPS ) ];
268 struct arbel_dev_limits limits;
271 /** Global protection domain */
272 #define ARBEL_GLOBAL_PD 0x123456
279 #define ARBEL_HCR_BASE 0x80680
280 #define ARBEL_HCR_REG(x) ( ARBEL_HCR_BASE + 4 * (x) )
281 #define ARBEL_HCR_MAX_WAIT_MS 2000
282 #define ARBEL_MBOX_ALIGN 4096
283 #define ARBEL_MBOX_SIZE 512
285 /* HCA command is split into
288 * bit 12 Input uses mailbox
289 * bit 13 Output uses mailbox
290 * bits 22:14 Input parameter length (in dwords)
291 * bits 31:23 Output parameter length (in dwords)
293 * Encoding the information in this way allows us to cut out several
294 * parameters to the arbel_command() call.
296 #define ARBEL_HCR_IN_MBOX 0x00001000UL
297 #define ARBEL_HCR_OUT_MBOX 0x00002000UL
298 #define ARBEL_HCR_OPCODE( _command ) ( (_command) & 0xfff )
299 #define ARBEL_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
300 #define ARBEL_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
302 /** Build HCR command from component parts */
303 #define ARBEL_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len, \
304 _out_mbox, _out_len ) \
306 ( (_in_mbox) ? ARBEL_HCR_IN_MBOX : 0 ) | \
307 ( ( (_in_len) / 4 ) << 14 ) | \
308 ( (_out_mbox) ? ARBEL_HCR_OUT_MBOX : 0 ) | \
309 ( ( (_out_len) / 4 ) << 23 ) )
311 #define ARBEL_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
312 ARBEL_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
314 #define ARBEL_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
315 ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
317 #define ARBEL_HCR_VOID_CMD( _opcode ) \
318 ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
321 * Doorbell record allocation
323 * The doorbell record map looks like:
325 * ARBEL_MAX_CQS * Arm completion queue doorbell
326 * ARBEL_MAX_QPS * Send work request doorbell
328 * ...(empty space)...
329 * ARBEL_MAX_QPS * Receive work request doorbell
330 * ARBEL_MAX_CQS * Completion queue consumer counter update doorbell
333 #define ARBEL_MAX_DOORBELL_RECORDS 512
334 #define ARBEL_GROUP_SEPARATOR_DOORBELL ( ARBEL_MAX_CQS + ARBEL_MAX_QPS )
337 * Get arm completion queue doorbell index
339 * @v cqn_offset Completion queue number offset
340 * @ret doorbell_idx Doorbell index
342 static inline unsigned int
343 arbel_cq_arm_doorbell_idx ( unsigned int cqn_offset ) {
348 * Get send work request doorbell index
350 * @v qpn_offset Queue pair number offset
351 * @ret doorbell_idx Doorbell index
353 static inline unsigned int
354 arbel_send_doorbell_idx ( unsigned int qpn_offset ) {
355 return ( ARBEL_MAX_CQS + qpn_offset );
359 * Get receive work request doorbell index
361 * @v qpn_offset Queue pair number offset
362 * @ret doorbell_idx Doorbell index
364 static inline unsigned int
365 arbel_recv_doorbell_idx ( unsigned int qpn_offset ) {
366 return ( ARBEL_MAX_DOORBELL_RECORDS - ARBEL_MAX_CQS - qpn_offset - 1 );
370 * Get completion queue consumer counter doorbell index
372 * @v cqn_offset Completion queue number offset
373 * @ret doorbell_idx Doorbell index
375 static inline unsigned int
376 arbel_cq_ci_doorbell_idx ( unsigned int cqn_offset ) {
377 return ( ARBEL_MAX_DOORBELL_RECORDS - cqn_offset - 1 );
380 #endif /* _ARBEL_H */