6 * Mellanox Hermon Infiniband HCA driver
11 #include <gpxe/uaccess.h>
12 #include <gpxe/process.h>
13 #include "mlx_bitops.h"
14 #include "MT25408_PRM.h"
21 /* Ports in existence */
22 #define HERMON_NUM_PORTS 2
23 #define HERMON_PORT_BASE 1
26 #define HERMON_PCI_CONFIG_BAR PCI_BASE_ADDRESS_0
27 #define HERMON_PCI_CONFIG_BAR_SIZE 0x100000
28 #define HERMON_PCI_UAR_BAR PCI_BASE_ADDRESS_2
30 /* Work queue entry and completion queue entry opcodes */
31 #define HERMON_OPCODE_SEND 0x0a
32 #define HERMON_OPCODE_RECV_ERROR 0xfe
33 #define HERMON_OPCODE_SEND_ERROR 0xff
35 /* HCA command register opcodes */
36 #define HERMON_HCR_QUERY_DEV_CAP 0x0003
37 #define HERMON_HCR_QUERY_FW 0x0004
38 #define HERMON_HCR_INIT_HCA 0x0007
39 #define HERMON_HCR_CLOSE_HCA 0x0008
40 #define HERMON_HCR_INIT_PORT 0x0009
41 #define HERMON_HCR_CLOSE_PORT 0x000a
42 #define HERMON_HCR_SW2HW_MPT 0x000d
43 #define HERMON_HCR_WRITE_MTT 0x0011
44 #define HERMON_HCR_MAP_EQ 0x0012
45 #define HERMON_HCR_SW2HW_EQ 0x0013
46 #define HERMON_HCR_HW2SW_EQ 0x0014
47 #define HERMON_HCR_SW2HW_CQ 0x0016
48 #define HERMON_HCR_HW2SW_CQ 0x0017
49 #define HERMON_HCR_RST2INIT_QP 0x0019
50 #define HERMON_HCR_INIT2RTR_QP 0x001a
51 #define HERMON_HCR_RTR2RTS_QP 0x001b
52 #define HERMON_HCR_RTS2RTS_QP 0x001c
53 #define HERMON_HCR_2RST_QP 0x0021
54 #define HERMON_HCR_MAD_IFC 0x0024
55 #define HERMON_HCR_READ_MCG 0x0025
56 #define HERMON_HCR_WRITE_MCG 0x0026
57 #define HERMON_HCR_MGID_HASH 0x0027
58 #define HERMON_HCR_RUN_FW 0x0ff6
59 #define HERMON_HCR_DISABLE_LAM 0x0ff7
60 #define HERMON_HCR_ENABLE_LAM 0x0ff8
61 #define HERMON_HCR_UNMAP_ICM 0x0ff9
62 #define HERMON_HCR_MAP_ICM 0x0ffa
63 #define HERMON_HCR_UNMAP_ICM_AUX 0x0ffb
64 #define HERMON_HCR_MAP_ICM_AUX 0x0ffc
65 #define HERMON_HCR_SET_ICM_SIZE 0x0ffd
66 #define HERMON_HCR_UNMAP_FA 0x0ffe
67 #define HERMON_HCR_MAP_FA 0x0fff
70 #define HERMON_ST_UD 0x03
73 #define HERMON_MTU_2048 0x04
75 #define HERMON_INVALID_LKEY 0x00000100UL
77 #define HERMON_PAGE_SIZE 4096
79 #define HERMON_DB_POST_SND_OFFSET 0x14
80 #define HERMON_DB_EQ0_OFFSET 0x800
82 #define HERMON_QP_OPT_PARAM_QKEY 0x00000020UL
84 #define HERMON_MAP_EQ_MAP ( 0UL << 31 )
85 #define HERMON_MAP_EQ_UNMAP ( 1UL << 31 )
87 #define HERMON_EV_PORT_STATE_CHANGE 0x09
90 * Datatypes that seem to be missing from the autogenerated documentation
93 struct hermonprm_mgm_hash_st {
94 pseudo_bit_t reserved0[0x00020];
96 pseudo_bit_t hash[0x00010];
97 pseudo_bit_t reserved1[0x00010];
98 } __attribute__ (( packed ));
100 struct hermonprm_mcg_entry_st {
101 struct hermonprm_mcg_hdr_st hdr;
102 struct hermonprm_mcg_qp_dw_st qp[8];
103 } __attribute__ (( packed ));
105 struct hermonprm_cq_db_record_st {
106 pseudo_bit_t update_ci[0x00018];
107 pseudo_bit_t reserved0[0x00008];
109 pseudo_bit_t arm_ci[0x00018];
110 pseudo_bit_t cmd[0x00003];
111 pseudo_bit_t reserved1[0x00001];
112 pseudo_bit_t cmd_sn[0x00002];
113 pseudo_bit_t reserved2[0x00002];
114 } __attribute__ (( packed ));
116 struct hermonprm_send_db_register_st {
117 pseudo_bit_t reserved[0x00008];
118 pseudo_bit_t qn[0x00018];
119 } __attribute__ (( packed ));
121 struct hermonprm_event_db_register_st {
122 pseudo_bit_t ci[0x00018];
123 pseudo_bit_t reserver[0x00007];
124 pseudo_bit_t a[0x00001];
125 } __attribute__ (( packed ));
127 struct hermonprm_scalar_parameter_st {
128 pseudo_bit_t value_hi[0x00020];
130 pseudo_bit_t value[0x00020];
131 } __attribute__ (( packed ));
133 struct hermonprm_event_mask_st {
134 pseudo_bit_t reserved0[0x00020];
136 pseudo_bit_t completion[0x00001];
137 pseudo_bit_t reserved1[0x0008];
138 pseudo_bit_t port_state_change[0x00001];
139 pseudo_bit_t reserved2[0x00016];
140 } __attribute__ (( packed ));
142 struct hermonprm_port_state_change_event_st {
143 pseudo_bit_t reserved[0x00020];
144 struct hermonprm_port_state_change_st data;
145 } __attribute__ (( packed ));
148 * Wrapper structures for hardware datatypes
152 struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_context );
153 struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_entry );
154 struct MLX_DECLARE_STRUCT ( hermonprm_completion_with_error );
155 struct MLX_DECLARE_STRUCT ( hermonprm_cq_db_record );
156 struct MLX_DECLARE_STRUCT ( hermonprm_eqc );
157 struct MLX_DECLARE_STRUCT ( hermonprm_event_db_register );
158 struct MLX_DECLARE_STRUCT ( hermonprm_event_mask );
159 struct MLX_DECLARE_STRUCT ( hermonprm_event_queue_entry );
160 struct MLX_DECLARE_STRUCT ( hermonprm_hca_command_register );
161 struct MLX_DECLARE_STRUCT ( hermonprm_init_hca );
162 struct MLX_DECLARE_STRUCT ( hermonprm_init_port );
163 struct MLX_DECLARE_STRUCT ( hermonprm_mad_ifc );
164 struct MLX_DECLARE_STRUCT ( hermonprm_mcg_entry );
165 struct MLX_DECLARE_STRUCT ( hermonprm_mgm_hash );
166 struct MLX_DECLARE_STRUCT ( hermonprm_mpt );
167 struct MLX_DECLARE_STRUCT ( hermonprm_mtt );
168 struct MLX_DECLARE_STRUCT ( hermonprm_port_state_change_event );
169 struct MLX_DECLARE_STRUCT ( hermonprm_qp_db_record );
170 struct MLX_DECLARE_STRUCT ( hermonprm_qp_ee_state_transitions );
171 struct MLX_DECLARE_STRUCT ( hermonprm_query_dev_cap );
172 struct MLX_DECLARE_STRUCT ( hermonprm_query_fw );
173 struct MLX_DECLARE_STRUCT ( hermonprm_queue_pair_ee_context_entry );
174 struct MLX_DECLARE_STRUCT ( hermonprm_scalar_parameter );
175 struct MLX_DECLARE_STRUCT ( hermonprm_send_db_register );
176 struct MLX_DECLARE_STRUCT ( hermonprm_ud_address_vector );
177 struct MLX_DECLARE_STRUCT ( hermonprm_virtual_physical_mapping );
178 struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ctrl_send );
179 struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_data_ptr );
180 struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ud );
183 * Composite hardware datatypes
187 struct hermonprm_write_mtt {
188 struct hermonprm_scalar_parameter mtt_base_addr;
189 struct hermonprm_scalar_parameter reserved;
190 struct hermonprm_mtt mtt;
191 } __attribute__ (( packed ));
193 #define HERMON_MAX_GATHER 1
195 struct hermonprm_ud_send_wqe {
196 struct hermonprm_wqe_segment_ctrl_send ctrl;
197 struct hermonprm_wqe_segment_ud ud;
198 struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
199 } __attribute__ (( packed ));
201 #define HERMON_MAX_SCATTER 1
203 struct hermonprm_recv_wqe {
204 struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_SCATTER];
205 } __attribute__ (( packed ));
207 union hermonprm_completion_entry {
208 struct hermonprm_completion_queue_entry normal;
209 struct hermonprm_completion_with_error error;
210 } __attribute__ (( packed ));
212 union hermonprm_event_entry {
213 struct hermonprm_event_queue_entry generic;
214 struct hermonprm_port_state_change_event port_state_change;
215 } __attribute__ (( packed ));
217 union hermonprm_doorbell_register {
218 struct hermonprm_send_db_register send;
219 struct hermonprm_event_db_register event;
221 } __attribute__ (( packed ));
223 union hermonprm_mad {
224 struct hermonprm_mad_ifc ifc;
226 } __attribute__ (( packed ));
229 * gPXE-specific definitions
233 /** Hermon device capabilitiess */
234 struct hermon_dev_cap {
235 /** CMPT entry size */
236 size_t cmpt_entry_size;
237 /** Number of reserved QPs */
238 unsigned int reserved_qps;
239 /** QP context entry size */
240 size_t qpc_entry_size;
241 /** Alternate path context entry size */
242 size_t altc_entry_size;
243 /** Auxiliary context entry size */
244 size_t auxc_entry_size;
245 /** Number of reserved SRQs */
246 unsigned int reserved_srqs;
247 /** SRQ context entry size */
248 size_t srqc_entry_size;
249 /** Number of reserved CQs */
250 unsigned int reserved_cqs;
251 /** CQ context entry size */
252 size_t cqc_entry_size;
253 /** Number of reserved EQs */
254 unsigned int reserved_eqs;
255 /** EQ context entry size */
256 size_t eqc_entry_size;
257 /** Number of reserved MTTs */
258 unsigned int reserved_mtts;
259 /** MTT entry size */
260 size_t mtt_entry_size;
261 /** Number of reserved MRWs */
262 unsigned int reserved_mrws;
263 /** DMPT entry size */
264 size_t dmpt_entry_size;
265 /** Number of reserved UARs */
266 unsigned int reserved_uars;
269 /** Number of cMPT entries of each type */
270 #define HERMON_CMPT_MAX_ENTRIES ( 1 << 24 )
272 /** Hermon ICM memory map entry */
273 struct hermon_icm_map {
274 /** Offset (virtual address within ICM) */
280 /** Discontiguous regions within Hermon ICM */
281 enum hermon_icm_map_regions {
282 HERMON_ICM_QP_CMPT = 0,
287 HERMON_ICM_NUM_REGIONS
290 /** UAR page for doorbell accesses
292 * Pages 0-127 are reserved for event queue doorbells only, so we use
295 #define HERMON_UAR_PAGE 128
297 /** Maximum number of allocatable MTT entries
299 * This is a policy decision, not a device limit.
301 #define HERMON_MAX_MTTS 64
303 /** A Hermon MTT descriptor */
306 unsigned int mtt_offset;
307 /** Number of pages */
308 unsigned int num_pages;
309 /** MTT base address */
310 unsigned int mtt_base_addr;
311 /** Offset within page */
312 unsigned int page_offset;
315 /** Alignment of Hermon send work queue entries */
316 #define HERMON_SEND_WQE_ALIGN 128
318 /** A Hermon send work queue entry */
319 union hermon_send_wqe {
320 struct hermonprm_ud_send_wqe ud;
321 uint8_t force_align[HERMON_SEND_WQE_ALIGN];
322 } __attribute__ (( packed ));
324 /** A Hermon send work queue */
325 struct hermon_send_work_queue {
326 /** Number of work queue entries, including headroom
328 * Hermon requires us to leave unused space within the send
329 * WQ, so we create a send WQ with more entries than are
330 * requested in the create_qp() call.
332 unsigned int num_wqes;
333 /** Work queue entries */
334 union hermon_send_wqe *wqe;
335 /** Size of work queue */
339 /** Alignment of Hermon receive work queue entries */
340 #define HERMON_RECV_WQE_ALIGN 16
342 /** A Hermon receive work queue entry */
343 union hermon_recv_wqe {
344 struct hermonprm_recv_wqe recv;
345 uint8_t force_align[HERMON_RECV_WQE_ALIGN];
346 } __attribute__ (( packed ));
348 /** A Hermon receive work queue */
349 struct hermon_recv_work_queue {
350 /** Work queue entries */
351 union hermon_recv_wqe *wqe;
352 /** Size of work queue */
355 struct hermonprm_qp_db_record doorbell __attribute__ (( aligned (4) ));
358 /** Maximum number of allocatable queue pairs
360 * This is a policy decision, not a device limit.
362 #define HERMON_MAX_QPS 8
364 /** Base queue pair number */
365 #define HERMON_QPN_BASE 0x550000
367 /** A Hermon queue pair */
368 struct hermon_queue_pair {
369 /** Work queue buffer */
371 /** Size of work queue buffer */
373 /** MTT descriptor */
374 struct hermon_mtt mtt;
375 /** Send work queue */
376 struct hermon_send_work_queue send;
377 /** Receive work queue */
378 struct hermon_recv_work_queue recv;
381 /** Maximum number of allocatable completion queues
383 * This is a policy decision, not a device limit.
385 #define HERMON_MAX_CQS 8
387 /** A Hermon completion queue */
388 struct hermon_completion_queue {
389 /** Completion queue entries */
390 union hermonprm_completion_entry *cqe;
391 /** Size of completion queue */
393 /** MTT descriptor */
394 struct hermon_mtt mtt;
396 struct hermonprm_cq_db_record doorbell __attribute__ (( aligned (8) ));
399 /** Maximum number of allocatable event queues
401 * This is a policy decision, not a device limit.
403 #define HERMON_MAX_EQS 4
405 /** A Hermon event queue */
406 struct hermon_event_queue {
407 /** Event queue entries */
408 union hermonprm_event_entry *eqe;
409 /** Size of event queue */
411 /** MTT descriptor */
412 struct hermon_mtt mtt;
413 /** Next event queue entry index */
414 unsigned long next_idx;
417 /** Number of event queue entries
419 * This is a policy decision.
421 #define HERMON_NUM_EQES 4
423 /** A Hermon resource bitmask */
424 typedef uint32_t hermon_bitmask_t;
426 /** Size of a hermon resource bitmask */
427 #define HERMON_BITMASK_SIZE(max_entries) \
428 ( ( (max_entries) + ( 8 * sizeof ( hermon_bitmask_t ) ) - 1 ) / \
429 ( 8 * sizeof ( hermon_bitmask_t ) ) )
431 /** A Hermon device */
433 /** PCI configuration registers */
435 /** PCI user Access Region */
438 /** Command toggle */
440 /** Command input mailbox */
442 /** Command output mailbox */
445 /** Firmware area in external memory */
446 userptr_t firmware_area;
448 struct hermon_icm_map icm_map[HERMON_ICM_NUM_REGIONS];
454 * Used to get unrestricted memory access.
456 unsigned long reserved_lkey;
459 struct hermon_event_queue eq;
460 /** Event queue process */
461 struct process event_process;
463 /** Completion queue in-use bitmask */
464 hermon_bitmask_t cq_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_CQS ) ];
465 /** Queue pair in-use bitmask */
466 hermon_bitmask_t qp_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_QPS ) ];
467 /** MTT entry in-use bitmask */
468 hermon_bitmask_t mtt_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_MTTS ) ];
470 /** Device capabilities */
471 struct hermon_dev_cap cap;
473 /** Infiniband devices */
474 struct ib_device *ibdev[HERMON_NUM_PORTS];
477 /** Global protection domain */
478 #define HERMON_GLOBAL_PD 0x123456
480 /** Memory key prefix */
481 #define HERMON_MKEY_PREFIX 0x77000000UL
488 #define HERMON_HCR_BASE 0x80680
489 #define HERMON_HCR_REG(x) ( HERMON_HCR_BASE + 4 * (x) )
490 #define HERMON_HCR_MAX_WAIT_MS 2000
491 #define HERMON_MBOX_ALIGN 4096
492 #define HERMON_MBOX_SIZE 512
494 /* HCA command is split into
497 * bit 12 Input uses mailbox
498 * bit 13 Output uses mailbox
499 * bits 22:14 Input parameter length (in dwords)
500 * bits 31:23 Output parameter length (in dwords)
502 * Encoding the information in this way allows us to cut out several
503 * parameters to the hermon_command() call.
505 #define HERMON_HCR_IN_MBOX 0x00001000UL
506 #define HERMON_HCR_OUT_MBOX 0x00002000UL
507 #define HERMON_HCR_OPCODE( _command ) ( (_command) & 0xfff )
508 #define HERMON_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
509 #define HERMON_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
511 /** Build HCR command from component parts */
512 #define HERMON_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len, \
513 _out_mbox, _out_len ) \
515 ( (_in_mbox) ? HERMON_HCR_IN_MBOX : 0 ) | \
516 ( ( (_in_len) / 4 ) << 14 ) | \
517 ( (_out_mbox) ? HERMON_HCR_OUT_MBOX : 0 ) | \
518 ( ( (_out_len) / 4 ) << 23 ) )
520 #define HERMON_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
521 HERMON_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
523 #define HERMON_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
524 HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
526 #define HERMON_HCR_VOID_CMD( _opcode ) \
527 HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
529 #endif /* _HERMON_H */