2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * Based in part upon the original driver by Mellanox Technologies
5 * Ltd. Portions may be Copyright (c) Mellanox Technologies Ltd.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 FILE_LICENCE ( GPL2_OR_LATER );
35 #include <ipxe/pcibackup.h>
36 #include <ipxe/malloc.h>
37 #include <ipxe/umalloc.h>
38 #include <ipxe/iobuf.h>
39 #include <ipxe/netdevice.h>
40 #include <ipxe/infiniband.h>
41 #include <ipxe/ib_smc.h>
47 * Mellanox Arbel Infiniband HCA
51 /***************************************************************************
53 * Queue number allocation
55 ***************************************************************************
59 * Allocate offset within usage bitmask
61 * @v bits Usage bitmask
62 * @v bits_len Length of usage bitmask
63 * @ret bit First free bit within bitmask, or negative error
65 static int arbel_bitmask_alloc ( arbel_bitmask_t *bits,
66 unsigned int bits_len ) {
68 arbel_bitmask_t mask = 1;
70 while ( bit < bits_len ) {
71 if ( ( mask & *bits ) == 0 ) {
76 mask = ( mask << 1 ) | ( mask >> ( 8 * sizeof ( mask ) - 1 ) );
84 * Free offset within usage bitmask
86 * @v bits Usage bitmask
87 * @v bit Bit within bitmask
89 static void arbel_bitmask_free ( arbel_bitmask_t *bits, int bit ) {
92 mask = ( 1 << ( bit % ( 8 * sizeof ( mask ) ) ) );
93 bits += ( bit / ( 8 * sizeof ( mask ) ) );
97 /***************************************************************************
101 ***************************************************************************
105 * Wait for Arbel command completion
107 * @v arbel Arbel device
108 * @ret rc Return status code
110 static int arbel_cmd_wait ( struct arbel *arbel,
111 struct arbelprm_hca_command_register *hcr ) {
114 for ( wait = ARBEL_HCR_MAX_WAIT_MS ; wait ; wait-- ) {
116 readl ( arbel->config + ARBEL_HCR_REG ( 6 ) );
117 if ( MLX_GET ( hcr, go ) == 0 )
127 * @v arbel Arbel device
128 * @v command Command opcode, flags and input/output lengths
129 * @v op_mod Opcode modifier (0 if no modifier applicable)
130 * @v in Input parameters
131 * @v in_mod Input modifier (0 if no modifier applicable)
132 * @v out Output parameters
133 * @ret rc Return status code
135 static int arbel_cmd ( struct arbel *arbel, unsigned long command,
136 unsigned int op_mod, const void *in,
137 unsigned int in_mod, void *out ) {
138 struct arbelprm_hca_command_register hcr;
139 unsigned int opcode = ARBEL_HCR_OPCODE ( command );
140 size_t in_len = ARBEL_HCR_IN_LEN ( command );
141 size_t out_len = ARBEL_HCR_OUT_LEN ( command );
148 assert ( in_len <= ARBEL_MBOX_SIZE );
149 assert ( out_len <= ARBEL_MBOX_SIZE );
151 DBGC2 ( arbel, "Arbel %p command %02x in %zx%s out %zx%s\n",
152 arbel, opcode, in_len,
153 ( ( command & ARBEL_HCR_IN_MBOX ) ? "(mbox)" : "" ), out_len,
154 ( ( command & ARBEL_HCR_OUT_MBOX ) ? "(mbox)" : "" ) );
156 /* Check that HCR is free */
157 if ( ( rc = arbel_cmd_wait ( arbel, &hcr ) ) != 0 ) {
158 DBGC ( arbel, "Arbel %p command interface locked\n", arbel );
163 memset ( &hcr, 0, sizeof ( hcr ) );
164 in_buffer = &hcr.u.dwords[0];
165 if ( in_len && ( command & ARBEL_HCR_IN_MBOX ) ) {
166 in_buffer = arbel->mailbox_in;
167 MLX_FILL_H ( &hcr, 0, in_param_h, virt_to_bus ( in_buffer ) );
168 MLX_FILL_1 ( &hcr, 1, in_param_l, virt_to_bus ( in_buffer ) );
170 memcpy ( in_buffer, in, in_len );
171 MLX_FILL_1 ( &hcr, 2, input_modifier, in_mod );
172 out_buffer = &hcr.u.dwords[3];
173 if ( out_len && ( command & ARBEL_HCR_OUT_MBOX ) ) {
174 out_buffer = arbel->mailbox_out;
175 MLX_FILL_H ( &hcr, 3, out_param_h,
176 virt_to_bus ( out_buffer ) );
177 MLX_FILL_1 ( &hcr, 4, out_param_l,
178 virt_to_bus ( out_buffer ) );
180 MLX_FILL_3 ( &hcr, 6,
182 opcode_modifier, op_mod,
184 DBGC ( arbel, "Arbel %p issuing command %04x\n", arbel, opcode );
185 DBGC2_HDA ( arbel, virt_to_phys ( arbel->config + ARBEL_HCR_BASE ),
186 &hcr, sizeof ( hcr ) );
187 if ( in_len && ( command & ARBEL_HCR_IN_MBOX ) ) {
188 DBGC2 ( arbel, "Input mailbox:\n" );
189 DBGC2_HDA ( arbel, virt_to_phys ( in_buffer ), in_buffer,
190 ( ( in_len < 512 ) ? in_len : 512 ) );
194 for ( i = 0 ; i < ( sizeof ( hcr ) / sizeof ( hcr.u.dwords[0] ) ) ;
196 writel ( hcr.u.dwords[i],
197 arbel->config + ARBEL_HCR_REG ( i ) );
201 /* Wait for command completion */
202 if ( ( rc = arbel_cmd_wait ( arbel, &hcr ) ) != 0 ) {
203 DBGC ( arbel, "Arbel %p timed out waiting for command:\n",
205 DBGC_HD ( arbel, &hcr, sizeof ( hcr ) );
209 /* Check command status */
210 status = MLX_GET ( &hcr, status );
212 DBGC ( arbel, "Arbel %p command failed with status %02x:\n",
214 DBGC_HD ( arbel, &hcr, sizeof ( hcr ) );
218 /* Read output parameters, if any */
219 hcr.u.dwords[3] = readl ( arbel->config + ARBEL_HCR_REG ( 3 ) );
220 hcr.u.dwords[4] = readl ( arbel->config + ARBEL_HCR_REG ( 4 ) );
221 memcpy ( out, out_buffer, out_len );
223 DBGC2 ( arbel, "Output%s:\n",
224 ( command & ARBEL_HCR_OUT_MBOX ) ? " mailbox" : "" );
225 DBGC2_HDA ( arbel, virt_to_phys ( out_buffer ), out_buffer,
226 ( ( out_len < 512 ) ? out_len : 512 ) );
233 arbel_cmd_query_dev_lim ( struct arbel *arbel,
234 struct arbelprm_query_dev_lim *dev_lim ) {
235 return arbel_cmd ( arbel,
236 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_DEV_LIM,
237 1, sizeof ( *dev_lim ) ),
238 0, NULL, 0, dev_lim );
242 arbel_cmd_query_fw ( struct arbel *arbel, struct arbelprm_query_fw *fw ) {
243 return arbel_cmd ( arbel,
244 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_FW,
250 arbel_cmd_init_hca ( struct arbel *arbel,
251 const struct arbelprm_init_hca *init_hca ) {
252 return arbel_cmd ( arbel,
253 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT_HCA,
254 1, sizeof ( *init_hca ) ),
255 0, init_hca, 0, NULL );
259 arbel_cmd_close_hca ( struct arbel *arbel ) {
260 return arbel_cmd ( arbel,
261 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CLOSE_HCA ),
266 arbel_cmd_init_ib ( struct arbel *arbel, unsigned int port,
267 const struct arbelprm_init_ib *init_ib ) {
268 return arbel_cmd ( arbel,
269 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT_IB,
270 1, sizeof ( *init_ib ) ),
271 0, init_ib, port, NULL );
275 arbel_cmd_close_ib ( struct arbel *arbel, unsigned int port ) {
276 return arbel_cmd ( arbel,
277 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CLOSE_IB ),
278 0, NULL, port, NULL );
282 arbel_cmd_sw2hw_mpt ( struct arbel *arbel, unsigned int index,
283 const struct arbelprm_mpt *mpt ) {
284 return arbel_cmd ( arbel,
285 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_MPT,
286 1, sizeof ( *mpt ) ),
287 0, mpt, index, NULL );
291 arbel_cmd_map_eq ( struct arbel *arbel, unsigned long index_map,
292 const struct arbelprm_event_mask *mask ) {
293 return arbel_cmd ( arbel,
294 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_EQ,
295 0, sizeof ( *mask ) ),
296 0, mask, index_map, NULL );
300 arbel_cmd_sw2hw_eq ( struct arbel *arbel, unsigned int index,
301 const struct arbelprm_eqc *eqctx ) {
302 return arbel_cmd ( arbel,
303 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_EQ,
304 1, sizeof ( *eqctx ) ),
305 0, eqctx, index, NULL );
309 arbel_cmd_hw2sw_eq ( struct arbel *arbel, unsigned int index,
310 struct arbelprm_eqc *eqctx ) {
311 return arbel_cmd ( arbel,
312 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_HW2SW_EQ,
313 1, sizeof ( *eqctx ) ),
314 1, NULL, index, eqctx );
318 arbel_cmd_sw2hw_cq ( struct arbel *arbel, unsigned long cqn,
319 const struct arbelprm_completion_queue_context *cqctx ) {
320 return arbel_cmd ( arbel,
321 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_CQ,
322 1, sizeof ( *cqctx ) ),
323 0, cqctx, cqn, NULL );
327 arbel_cmd_hw2sw_cq ( struct arbel *arbel, unsigned long cqn,
328 struct arbelprm_completion_queue_context *cqctx) {
329 return arbel_cmd ( arbel,
330 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_HW2SW_CQ,
331 1, sizeof ( *cqctx ) ),
332 0, NULL, cqn, cqctx );
336 arbel_cmd_query_cq ( struct arbel *arbel, unsigned long cqn,
337 struct arbelprm_completion_queue_context *cqctx ) {
338 return arbel_cmd ( arbel,
339 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_CQ,
340 1, sizeof ( *cqctx ) ),
341 0, NULL, cqn, cqctx );
345 arbel_cmd_rst2init_qpee ( struct arbel *arbel, unsigned long qpn,
346 const struct arbelprm_qp_ee_state_transitions *ctx ){
347 return arbel_cmd ( arbel,
348 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RST2INIT_QPEE,
349 1, sizeof ( *ctx ) ),
354 arbel_cmd_init2rtr_qpee ( struct arbel *arbel, unsigned long qpn,
355 const struct arbelprm_qp_ee_state_transitions *ctx ){
356 return arbel_cmd ( arbel,
357 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT2RTR_QPEE,
358 1, sizeof ( *ctx ) ),
363 arbel_cmd_rtr2rts_qpee ( struct arbel *arbel, unsigned long qpn,
364 const struct arbelprm_qp_ee_state_transitions *ctx ) {
365 return arbel_cmd ( arbel,
366 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RTR2RTS_QPEE,
367 1, sizeof ( *ctx ) ),
372 arbel_cmd_rts2rts_qpee ( struct arbel *arbel, unsigned long qpn,
373 const struct arbelprm_qp_ee_state_transitions *ctx ) {
374 return arbel_cmd ( arbel,
375 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RTS2RTS_QPEE,
376 1, sizeof ( *ctx ) ),
381 arbel_cmd_2rst_qpee ( struct arbel *arbel, unsigned long qpn ) {
382 return arbel_cmd ( arbel,
383 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_2RST_QPEE ),
384 0x03, NULL, qpn, NULL );
388 arbel_cmd_query_qpee ( struct arbel *arbel, unsigned long qpn,
389 struct arbelprm_qp_ee_state_transitions *ctx ) {
390 return arbel_cmd ( arbel,
391 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_QPEE,
392 1, sizeof ( *ctx ) ),
397 arbel_cmd_conf_special_qp ( struct arbel *arbel, unsigned int qp_type,
398 unsigned long base_qpn ) {
399 return arbel_cmd ( arbel,
400 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CONF_SPECIAL_QP ),
401 qp_type, NULL, base_qpn, NULL );
405 arbel_cmd_mad_ifc ( struct arbel *arbel, unsigned int port,
406 union arbelprm_mad *mad ) {
407 return arbel_cmd ( arbel,
408 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_MAD_IFC,
410 1, sizeof ( *mad ) ),
411 0x03, mad, port, mad );
415 arbel_cmd_read_mgm ( struct arbel *arbel, unsigned int index,
416 struct arbelprm_mgm_entry *mgm ) {
417 return arbel_cmd ( arbel,
418 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_READ_MGM,
419 1, sizeof ( *mgm ) ),
420 0, NULL, index, mgm );
424 arbel_cmd_write_mgm ( struct arbel *arbel, unsigned int index,
425 const struct arbelprm_mgm_entry *mgm ) {
426 return arbel_cmd ( arbel,
427 ARBEL_HCR_IN_CMD ( ARBEL_HCR_WRITE_MGM,
428 1, sizeof ( *mgm ) ),
429 0, mgm, index, NULL );
433 arbel_cmd_mgid_hash ( struct arbel *arbel, const union ib_gid *gid,
434 struct arbelprm_mgm_hash *hash ) {
435 return arbel_cmd ( arbel,
436 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_MGID_HASH,
438 0, sizeof ( *hash ) ),
443 arbel_cmd_run_fw ( struct arbel *arbel ) {
444 return arbel_cmd ( arbel,
445 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_RUN_FW ),
450 arbel_cmd_disable_lam ( struct arbel *arbel ) {
451 return arbel_cmd ( arbel,
452 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_DISABLE_LAM ),
457 arbel_cmd_enable_lam ( struct arbel *arbel, struct arbelprm_access_lam *lam ) {
458 return arbel_cmd ( arbel,
459 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_ENABLE_LAM,
460 1, sizeof ( *lam ) ),
465 arbel_cmd_unmap_icm ( struct arbel *arbel, unsigned int page_count,
466 const struct arbelprm_scalar_parameter *offset ) {
467 return arbel_cmd ( arbel,
468 ARBEL_HCR_IN_CMD ( ARBEL_HCR_UNMAP_ICM, 0,
469 sizeof ( *offset ) ),
470 0, offset, page_count, NULL );
474 arbel_cmd_map_icm ( struct arbel *arbel,
475 const struct arbelprm_virtual_physical_mapping *map ) {
476 return arbel_cmd ( arbel,
477 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_ICM,
478 1, sizeof ( *map ) ),
483 arbel_cmd_unmap_icm_aux ( struct arbel *arbel ) {
484 return arbel_cmd ( arbel,
485 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_UNMAP_ICM_AUX ),
490 arbel_cmd_map_icm_aux ( struct arbel *arbel,
491 const struct arbelprm_virtual_physical_mapping *map ) {
492 return arbel_cmd ( arbel,
493 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_ICM_AUX,
494 1, sizeof ( *map ) ),
499 arbel_cmd_set_icm_size ( struct arbel *arbel,
500 const struct arbelprm_scalar_parameter *icm_size,
501 struct arbelprm_scalar_parameter *icm_aux_size ) {
502 return arbel_cmd ( arbel,
503 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_SET_ICM_SIZE,
504 0, sizeof ( *icm_size ),
505 0, sizeof ( *icm_aux_size ) ),
506 0, icm_size, 0, icm_aux_size );
510 arbel_cmd_unmap_fa ( struct arbel *arbel ) {
511 return arbel_cmd ( arbel,
512 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_UNMAP_FA ),
517 arbel_cmd_map_fa ( struct arbel *arbel,
518 const struct arbelprm_virtual_physical_mapping *map ) {
519 return arbel_cmd ( arbel,
520 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_FA,
521 1, sizeof ( *map ) ),
525 /***************************************************************************
529 ***************************************************************************
533 * Issue management datagram
535 * @v ibdev Infiniband device
536 * @v mad Management datagram
537 * @ret rc Return status code
539 static int arbel_mad ( struct ib_device *ibdev, union ib_mad *mad ) {
540 struct arbel *arbel = ib_get_drvdata ( ibdev );
541 union arbelprm_mad mad_ifc;
544 linker_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ),
547 /* Copy in request packet */
548 memcpy ( &mad_ifc.mad, mad, sizeof ( mad_ifc.mad ) );
551 if ( ( rc = arbel_cmd_mad_ifc ( arbel, ibdev->port,
552 &mad_ifc ) ) != 0 ) {
553 DBGC ( arbel, "Arbel %p port %d could not issue MAD IFC: %s\n",
554 arbel, ibdev->port, strerror ( rc ) );
558 /* Copy out reply packet */
559 memcpy ( mad, &mad_ifc.mad, sizeof ( *mad ) );
561 if ( mad->hdr.status != 0 ) {
562 DBGC ( arbel, "Arbel %p port %d MAD IFC status %04x\n",
563 arbel, ibdev->port, ntohs ( mad->hdr.status ) );
569 /***************************************************************************
571 * Completion queue operations
573 ***************************************************************************
577 * Dump completion queue context (for debugging only)
579 * @v arbel Arbel device
580 * @v cq Completion queue
581 * @ret rc Return status code
583 static __attribute__ (( unused )) int
584 arbel_dump_cqctx ( struct arbel *arbel, struct ib_completion_queue *cq ) {
585 struct arbelprm_completion_queue_context cqctx;
588 memset ( &cqctx, 0, sizeof ( cqctx ) );
589 if ( ( rc = arbel_cmd_query_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
590 DBGC ( arbel, "Arbel %p CQN %#lx QUERY_CQ failed: %s\n",
591 arbel, cq->cqn, strerror ( rc ) );
594 DBGC ( arbel, "Arbel %p CQN %#lx context:\n", arbel, cq->cqn );
595 DBGC_HDA ( arbel, 0, &cqctx, sizeof ( cqctx ) );
601 * Create completion queue
603 * @v ibdev Infiniband device
604 * @v cq Completion queue
605 * @ret rc Return status code
607 static int arbel_create_cq ( struct ib_device *ibdev,
608 struct ib_completion_queue *cq ) {
609 struct arbel *arbel = ib_get_drvdata ( ibdev );
610 struct arbel_completion_queue *arbel_cq;
611 struct arbelprm_completion_queue_context cqctx;
612 struct arbelprm_cq_ci_db_record *ci_db_rec;
613 struct arbelprm_cq_arm_db_record *arm_db_rec;
618 /* Find a free completion queue number */
619 cqn_offset = arbel_bitmask_alloc ( arbel->cq_inuse, ARBEL_MAX_CQS );
620 if ( cqn_offset < 0 ) {
621 DBGC ( arbel, "Arbel %p out of completion queues\n", arbel );
625 cq->cqn = ( arbel->limits.reserved_cqs + cqn_offset );
627 /* Allocate control structures */
628 arbel_cq = zalloc ( sizeof ( *arbel_cq ) );
633 arbel_cq->ci_doorbell_idx = arbel_cq_ci_doorbell_idx ( arbel, cq );
634 arbel_cq->arm_doorbell_idx = arbel_cq_arm_doorbell_idx ( arbel, cq );
636 /* Allocate completion queue itself */
637 arbel_cq->cqe_size = ( cq->num_cqes * sizeof ( arbel_cq->cqe[0] ) );
638 arbel_cq->cqe = malloc_dma ( arbel_cq->cqe_size,
639 sizeof ( arbel_cq->cqe[0] ) );
640 if ( ! arbel_cq->cqe ) {
644 memset ( arbel_cq->cqe, 0, arbel_cq->cqe_size );
645 for ( i = 0 ; i < cq->num_cqes ; i++ ) {
646 MLX_FILL_1 ( &arbel_cq->cqe[i].normal, 7, owner, 1 );
650 /* Initialise doorbell records */
651 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
652 MLX_FILL_1 ( ci_db_rec, 0, counter, 0 );
653 MLX_FILL_2 ( ci_db_rec, 1,
654 res, ARBEL_UAR_RES_CQ_CI,
655 cq_number, cq->cqn );
656 arm_db_rec = &arbel->db_rec[arbel_cq->arm_doorbell_idx].cq_arm;
657 MLX_FILL_1 ( arm_db_rec, 0, counter, 0 );
658 MLX_FILL_2 ( arm_db_rec, 1,
659 res, ARBEL_UAR_RES_CQ_ARM,
660 cq_number, cq->cqn );
662 /* Hand queue over to hardware */
663 memset ( &cqctx, 0, sizeof ( cqctx ) );
664 MLX_FILL_1 ( &cqctx, 0, st, 0xa /* "Event fired" */ );
665 MLX_FILL_H ( &cqctx, 1, start_address_h,
666 virt_to_bus ( arbel_cq->cqe ) );
667 MLX_FILL_1 ( &cqctx, 2, start_address_l,
668 virt_to_bus ( arbel_cq->cqe ) );
669 MLX_FILL_2 ( &cqctx, 3,
670 usr_page, arbel->limits.reserved_uars,
671 log_cq_size, fls ( cq->num_cqes - 1 ) );
672 MLX_FILL_1 ( &cqctx, 5, c_eqn, arbel->eq.eqn );
673 MLX_FILL_1 ( &cqctx, 6, pd, ARBEL_GLOBAL_PD );
674 MLX_FILL_1 ( &cqctx, 7, l_key, arbel->lkey );
675 MLX_FILL_1 ( &cqctx, 12, cqn, cq->cqn );
676 MLX_FILL_1 ( &cqctx, 13,
677 cq_ci_db_record, arbel_cq->ci_doorbell_idx );
678 MLX_FILL_1 ( &cqctx, 14,
679 cq_state_db_record, arbel_cq->arm_doorbell_idx );
680 if ( ( rc = arbel_cmd_sw2hw_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
681 DBGC ( arbel, "Arbel %p CQN %#lx SW2HW_CQ failed: %s\n",
682 arbel, cq->cqn, strerror ( rc ) );
686 DBGC ( arbel, "Arbel %p CQN %#lx ring [%08lx,%08lx), doorbell %08lx\n",
687 arbel, cq->cqn, virt_to_phys ( arbel_cq->cqe ),
688 ( virt_to_phys ( arbel_cq->cqe ) + arbel_cq->cqe_size ),
689 virt_to_phys ( ci_db_rec ) );
690 ib_cq_set_drvdata ( cq, arbel_cq );
694 MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
695 MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
696 free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
700 arbel_bitmask_free ( arbel->cq_inuse, cqn_offset );
706 * Destroy completion queue
708 * @v ibdev Infiniband device
709 * @v cq Completion queue
711 static void arbel_destroy_cq ( struct ib_device *ibdev,
712 struct ib_completion_queue *cq ) {
713 struct arbel *arbel = ib_get_drvdata ( ibdev );
714 struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
715 struct arbelprm_completion_queue_context cqctx;
716 struct arbelprm_cq_ci_db_record *ci_db_rec;
717 struct arbelprm_cq_arm_db_record *arm_db_rec;
721 /* Take ownership back from hardware */
722 if ( ( rc = arbel_cmd_hw2sw_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
723 DBGC ( arbel, "Arbel %p CQN %#lx FATAL HW2SW_CQ failed: "
724 "%s\n", arbel, cq->cqn, strerror ( rc ) );
725 /* Leak memory and return; at least we avoid corruption */
729 /* Clear doorbell records */
730 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
731 arm_db_rec = &arbel->db_rec[arbel_cq->arm_doorbell_idx].cq_arm;
732 MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
733 MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
736 free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
739 /* Mark queue number as free */
740 cqn_offset = ( cq->cqn - arbel->limits.reserved_cqs );
741 arbel_bitmask_free ( arbel->cq_inuse, cqn_offset );
743 ib_cq_set_drvdata ( cq, NULL );
746 /***************************************************************************
748 * Queue pair operations
750 ***************************************************************************
754 * Assign queue pair number
756 * @v ibdev Infiniband device
758 * @ret rc Return status code
760 static int arbel_alloc_qpn ( struct ib_device *ibdev,
761 struct ib_queue_pair *qp ) {
762 struct arbel *arbel = ib_get_drvdata ( ibdev );
763 unsigned int port_offset;
766 /* Calculate queue pair number */
767 port_offset = ( ibdev->port - ARBEL_PORT_BASE );
769 switch ( qp->type ) {
771 qp->qpn = ( arbel->special_qpn_base + port_offset );
774 qp->qpn = ( arbel->special_qpn_base + 2 + port_offset );
778 /* Find a free queue pair number */
779 qpn_offset = arbel_bitmask_alloc ( arbel->qp_inuse,
781 if ( qpn_offset < 0 ) {
782 DBGC ( arbel, "Arbel %p out of queue pairs\n",
786 qp->qpn = ( ( random() & ARBEL_QPN_RANDOM_MASK ) |
787 ( arbel->qpn_base + qpn_offset ) );
790 DBGC ( arbel, "Arbel %p unsupported QP type %d\n",
797 * Free queue pair number
799 * @v ibdev Infiniband device
802 static void arbel_free_qpn ( struct ib_device *ibdev,
803 struct ib_queue_pair *qp ) {
804 struct arbel *arbel = ib_get_drvdata ( ibdev );
807 qpn_offset = ( ( qp->qpn & ~ARBEL_QPN_RANDOM_MASK ) - arbel->qpn_base );
808 if ( qpn_offset >= 0 )
809 arbel_bitmask_free ( arbel->qp_inuse, qpn_offset );
813 * Calculate transmission rate
815 * @v av Address vector
816 * @ret arbel_rate Arbel rate
818 static unsigned int arbel_rate ( struct ib_address_vector *av ) {
819 return ( ( ( av->rate >= IB_RATE_2_5 ) && ( av->rate <= IB_RATE_120 ) )
820 ? ( av->rate + 5 ) : 0 );
823 /** Queue pair transport service type map */
824 static uint8_t arbel_qp_st[] = {
825 [IB_QPT_SMI] = ARBEL_ST_MLX,
826 [IB_QPT_GSI] = ARBEL_ST_MLX,
827 [IB_QPT_UD] = ARBEL_ST_UD,
828 [IB_QPT_RC] = ARBEL_ST_RC,
832 * Dump queue pair context (for debugging only)
834 * @v arbel Arbel device
836 * @ret rc Return status code
838 static __attribute__ (( unused )) int
839 arbel_dump_qpctx ( struct arbel *arbel, struct ib_queue_pair *qp ) {
840 struct arbelprm_qp_ee_state_transitions qpctx;
843 memset ( &qpctx, 0, sizeof ( qpctx ) );
844 if ( ( rc = arbel_cmd_query_qpee ( arbel, qp->qpn, &qpctx ) ) != 0 ) {
845 DBGC ( arbel, "Arbel %p QPN %#lx QUERY_QPEE failed: %s\n",
846 arbel, qp->qpn, strerror ( rc ) );
849 DBGC ( arbel, "Arbel %p QPN %#lx context:\n", arbel, qp->qpn );
850 DBGC_HDA ( arbel, 0, &qpctx.u.dwords[2], ( sizeof ( qpctx ) - 8 ) );
856 * Create send work queue
858 * @v arbel_send_wq Send work queue
859 * @v num_wqes Number of work queue entries
860 * @ret rc Return status code
862 static int arbel_create_send_wq ( struct arbel_send_work_queue *arbel_send_wq,
863 unsigned int num_wqes ) {
864 union arbel_send_wqe *wqe;
865 union arbel_send_wqe *next_wqe;
866 unsigned int wqe_idx_mask;
869 /* Allocate work queue */
870 arbel_send_wq->wqe_size = ( num_wqes *
871 sizeof ( arbel_send_wq->wqe[0] ) );
872 arbel_send_wq->wqe = malloc_dma ( arbel_send_wq->wqe_size,
873 sizeof ( arbel_send_wq->wqe[0] ) );
874 if ( ! arbel_send_wq->wqe )
876 memset ( arbel_send_wq->wqe, 0, arbel_send_wq->wqe_size );
878 /* Link work queue entries */
879 wqe_idx_mask = ( num_wqes - 1 );
880 for ( i = 0 ; i < num_wqes ; i++ ) {
881 wqe = &arbel_send_wq->wqe[i];
882 next_wqe = &arbel_send_wq->wqe[ ( i + 1 ) & wqe_idx_mask ];
883 MLX_FILL_1 ( &wqe->next, 0, nda_31_6,
884 ( virt_to_bus ( next_wqe ) >> 6 ) );
885 MLX_FILL_1 ( &wqe->next, 1, always1, 1 );
892 * Create receive work queue
894 * @v arbel_recv_wq Receive work queue
895 * @v num_wqes Number of work queue entries
896 * @ret rc Return status code
898 static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
899 unsigned int num_wqes ) {
900 struct arbelprm_recv_wqe *wqe;
901 struct arbelprm_recv_wqe *next_wqe;
902 unsigned int wqe_idx_mask;
907 /* Allocate work queue */
908 arbel_recv_wq->wqe_size = ( num_wqes *
909 sizeof ( arbel_recv_wq->wqe[0] ) );
910 arbel_recv_wq->wqe = malloc_dma ( arbel_recv_wq->wqe_size,
911 sizeof ( arbel_recv_wq->wqe[0] ) );
912 if ( ! arbel_recv_wq->wqe )
914 memset ( arbel_recv_wq->wqe, 0, arbel_recv_wq->wqe_size );
916 /* Link work queue entries */
917 wqe_idx_mask = ( num_wqes - 1 );
918 nds = ( ( offsetof ( typeof ( *wqe ), data ) +
919 sizeof ( wqe->data[0] ) ) >> 4 );
920 for ( i = 0 ; i < num_wqes ; i++ ) {
921 wqe = &arbel_recv_wq->wqe[i].recv;
922 next_wqe = &arbel_recv_wq->wqe[( i + 1 ) & wqe_idx_mask].recv;
923 MLX_FILL_1 ( &wqe->next, 0, nda_31_6,
924 ( virt_to_bus ( next_wqe ) >> 6 ) );
925 MLX_FILL_1 ( &wqe->next, 1, nds, nds );
926 for ( j = 0 ; ( ( ( void * ) &wqe->data[j] ) <
927 ( ( void * ) ( wqe + 1 ) ) ) ; j++ ) {
928 MLX_FILL_1 ( &wqe->data[j], 1,
929 l_key, ARBEL_INVALID_LKEY );
939 * @v ibdev Infiniband device
941 * @ret rc Return status code
943 static int arbel_create_qp ( struct ib_device *ibdev,
944 struct ib_queue_pair *qp ) {
945 struct arbel *arbel = ib_get_drvdata ( ibdev );
946 struct arbel_queue_pair *arbel_qp;
947 struct arbelprm_qp_ee_state_transitions qpctx;
948 struct arbelprm_qp_db_record *send_db_rec;
949 struct arbelprm_qp_db_record *recv_db_rec;
950 physaddr_t send_wqe_base_adr;
951 physaddr_t recv_wqe_base_adr;
952 physaddr_t wqe_base_adr;
955 /* Warn about dysfunctional code
957 * Arbel seems to crash the system as soon as the first send
958 * WQE completes on an RC queue pair. (NOPs complete
959 * successfully, so this is a problem specific to the work
960 * queue rather than the completion queue.) The cause of this
961 * problem has remained unknown for over a year. Patches to
962 * fix this are welcome.
964 if ( qp->type == IB_QPT_RC )
965 DBG ( "*** WARNING: Arbel RC support is non-functional ***\n" );
967 /* Calculate queue pair number */
968 if ( ( rc = arbel_alloc_qpn ( ibdev, qp ) ) != 0 )
971 /* Allocate control structures */
972 arbel_qp = zalloc ( sizeof ( *arbel_qp ) );
977 arbel_qp->send.doorbell_idx = arbel_send_doorbell_idx ( arbel, qp );
978 arbel_qp->recv.doorbell_idx = arbel_recv_doorbell_idx ( arbel, qp );
980 /* Create send and receive work queues */
981 if ( ( rc = arbel_create_send_wq ( &arbel_qp->send,
982 qp->send.num_wqes ) ) != 0 )
983 goto err_create_send_wq;
984 if ( ( rc = arbel_create_recv_wq ( &arbel_qp->recv,
985 qp->recv.num_wqes ) ) != 0 )
986 goto err_create_recv_wq;
988 /* Send and receive work queue entries must be within the same 4GB */
989 send_wqe_base_adr = virt_to_bus ( arbel_qp->send.wqe );
990 recv_wqe_base_adr = virt_to_bus ( arbel_qp->recv.wqe );
991 if ( ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) &&
992 ( ( ( ( uint64_t ) send_wqe_base_adr ) >> 32 ) !=
993 ( ( ( uint64_t ) recv_wqe_base_adr ) >> 32 ) ) ) {
994 DBGC ( arbel, "Arbel %p QPN %#lx cannot support send %08lx "
995 "recv %08lx\n", arbel, qp->qpn,
996 send_wqe_base_adr, recv_wqe_base_adr );
998 goto err_unsupported_address_split;
1000 wqe_base_adr = send_wqe_base_adr;
1002 /* Initialise doorbell records */
1003 send_db_rec = &arbel->db_rec[arbel_qp->send.doorbell_idx].qp;
1004 MLX_FILL_1 ( send_db_rec, 0, counter, 0 );
1005 MLX_FILL_2 ( send_db_rec, 1,
1006 res, ARBEL_UAR_RES_SQ,
1007 qp_number, qp->qpn );
1008 recv_db_rec = &arbel->db_rec[arbel_qp->recv.doorbell_idx].qp;
1009 MLX_FILL_1 ( recv_db_rec, 0, counter, 0 );
1010 MLX_FILL_2 ( recv_db_rec, 1,
1011 res, ARBEL_UAR_RES_RQ,
1012 qp_number, qp->qpn );
1014 /* Transition queue to INIT state */
1015 memset ( &qpctx, 0, sizeof ( qpctx ) );
1016 MLX_FILL_3 ( &qpctx, 2,
1018 qpc_eec_data.pm_state, ARBEL_PM_STATE_MIGRATED,
1019 qpc_eec_data.st, arbel_qp_st[qp->type] );
1020 MLX_FILL_4 ( &qpctx, 4,
1021 qpc_eec_data.log_rq_size, fls ( qp->recv.num_wqes - 1 ),
1022 qpc_eec_data.log_rq_stride,
1023 ( fls ( sizeof ( arbel_qp->recv.wqe[0] ) - 1 ) - 4 ),
1024 qpc_eec_data.log_sq_size, fls ( qp->send.num_wqes - 1 ),
1025 qpc_eec_data.log_sq_stride,
1026 ( fls ( sizeof ( arbel_qp->send.wqe[0] ) - 1 ) - 4 ) );
1027 MLX_FILL_1 ( &qpctx, 5,
1028 qpc_eec_data.usr_page, arbel->limits.reserved_uars );
1029 MLX_FILL_1 ( &qpctx, 10, qpc_eec_data.primary_address_path.port_number,
1031 MLX_FILL_1 ( &qpctx, 27, qpc_eec_data.pd, ARBEL_GLOBAL_PD );
1032 MLX_FILL_H ( &qpctx, 28, qpc_eec_data.wqe_base_adr_h, wqe_base_adr );
1033 MLX_FILL_1 ( &qpctx, 29, qpc_eec_data.wqe_lkey, arbel->lkey );
1034 MLX_FILL_1 ( &qpctx, 30, qpc_eec_data.ssc, 1 );
1035 MLX_FILL_1 ( &qpctx, 33, qpc_eec_data.cqn_snd, qp->send.cq->cqn );
1036 MLX_FILL_1 ( &qpctx, 34, qpc_eec_data.snd_wqe_base_adr_l,
1037 ( send_wqe_base_adr >> 6 ) );
1038 MLX_FILL_1 ( &qpctx, 35, qpc_eec_data.snd_db_record_index,
1039 arbel_qp->send.doorbell_idx );
1040 MLX_FILL_4 ( &qpctx, 38,
1041 qpc_eec_data.rre, 1,
1042 qpc_eec_data.rwe, 1,
1043 qpc_eec_data.rae, 1,
1044 qpc_eec_data.rsc, 1 );
1045 MLX_FILL_1 ( &qpctx, 41, qpc_eec_data.cqn_rcv, qp->recv.cq->cqn );
1046 MLX_FILL_1 ( &qpctx, 42, qpc_eec_data.rcv_wqe_base_adr_l,
1047 ( recv_wqe_base_adr >> 6 ) );
1048 MLX_FILL_1 ( &qpctx, 43, qpc_eec_data.rcv_db_record_index,
1049 arbel_qp->recv.doorbell_idx );
1050 if ( ( rc = arbel_cmd_rst2init_qpee ( arbel, qp->qpn, &qpctx )) != 0 ){
1051 DBGC ( arbel, "Arbel %p QPN %#lx RST2INIT_QPEE failed: %s\n",
1052 arbel, qp->qpn, strerror ( rc ) );
1053 goto err_rst2init_qpee;
1055 arbel_qp->state = ARBEL_QP_ST_INIT;
1057 DBGC ( arbel, "Arbel %p QPN %#lx send ring [%08lx,%08lx), doorbell "
1058 "%08lx\n", arbel, qp->qpn, virt_to_phys ( arbel_qp->send.wqe ),
1059 ( virt_to_phys ( arbel_qp->send.wqe ) +
1060 arbel_qp->send.wqe_size ),
1061 virt_to_phys ( send_db_rec ) );
1062 DBGC ( arbel, "Arbel %p QPN %#lx receive ring [%08lx,%08lx), doorbell "
1063 "%08lx\n", arbel, qp->qpn, virt_to_phys ( arbel_qp->recv.wqe ),
1064 ( virt_to_phys ( arbel_qp->recv.wqe ) +
1065 arbel_qp->recv.wqe_size ),
1066 virt_to_phys ( recv_db_rec ) );
1067 DBGC ( arbel, "Arbel %p QPN %#lx send CQN %#lx receive CQN %#lx\n",
1068 arbel, qp->qpn, qp->send.cq->cqn, qp->recv.cq->cqn );
1069 ib_qp_set_drvdata ( qp, arbel_qp );
1072 arbel_cmd_2rst_qpee ( arbel, qp->qpn );
1074 MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1075 MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1076 err_unsupported_address_split:
1077 free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
1079 free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
1083 arbel_free_qpn ( ibdev, qp );
1091 * @v ibdev Infiniband device
1093 * @ret rc Return status code
1095 static int arbel_modify_qp ( struct ib_device *ibdev,
1096 struct ib_queue_pair *qp ) {
1097 struct arbel *arbel = ib_get_drvdata ( ibdev );
1098 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1099 struct arbelprm_qp_ee_state_transitions qpctx;
1102 /* Transition queue to RTR state, if applicable */
1103 if ( arbel_qp->state < ARBEL_QP_ST_RTR ) {
1104 memset ( &qpctx, 0, sizeof ( qpctx ) );
1105 MLX_FILL_2 ( &qpctx, 4,
1106 qpc_eec_data.mtu, ARBEL_MTU_2048,
1107 qpc_eec_data.msg_max, 31 );
1108 MLX_FILL_1 ( &qpctx, 7,
1109 qpc_eec_data.remote_qpn_een, qp->av.qpn );
1110 MLX_FILL_2 ( &qpctx, 11,
1111 qpc_eec_data.primary_address_path.rnr_retry,
1113 qpc_eec_data.primary_address_path.rlid,
1115 MLX_FILL_2 ( &qpctx, 12,
1116 qpc_eec_data.primary_address_path.ack_timeout,
1117 14 /* 4.096us * 2^(14) = 67ms */,
1118 qpc_eec_data.primary_address_path.max_stat_rate,
1119 arbel_rate ( &qp->av ) );
1120 memcpy ( &qpctx.u.dwords[14], &qp->av.gid,
1121 sizeof ( qp->av.gid ) );
1122 MLX_FILL_1 ( &qpctx, 30,
1123 qpc_eec_data.retry_count, ARBEL_RETRY_MAX );
1124 MLX_FILL_1 ( &qpctx, 39,
1125 qpc_eec_data.next_rcv_psn, qp->recv.psn );
1126 MLX_FILL_1 ( &qpctx, 40,
1127 qpc_eec_data.ra_buff_indx,
1128 ( arbel->limits.reserved_rdbs +
1129 ( ( qp->qpn & ~ARBEL_QPN_RANDOM_MASK ) -
1130 arbel->special_qpn_base ) ) );
1131 if ( ( rc = arbel_cmd_init2rtr_qpee ( arbel, qp->qpn,
1133 DBGC ( arbel, "Arbel %p QPN %#lx INIT2RTR_QPEE failed:"
1134 " %s\n", arbel, qp->qpn, strerror ( rc ) );
1137 arbel_qp->state = ARBEL_QP_ST_RTR;
1140 /* Transition queue to RTS state, if applicable */
1141 if ( arbel_qp->state < ARBEL_QP_ST_RTS ) {
1142 memset ( &qpctx, 0, sizeof ( qpctx ) );
1143 MLX_FILL_1 ( &qpctx, 11,
1144 qpc_eec_data.primary_address_path.rnr_retry,
1146 MLX_FILL_1 ( &qpctx, 12,
1147 qpc_eec_data.primary_address_path.ack_timeout,
1148 14 /* 4.096us * 2^(14) = 67ms */ );
1149 MLX_FILL_2 ( &qpctx, 30,
1150 qpc_eec_data.retry_count, ARBEL_RETRY_MAX,
1151 qpc_eec_data.sic, 1 );
1152 MLX_FILL_1 ( &qpctx, 32,
1153 qpc_eec_data.next_send_psn, qp->send.psn );
1154 if ( ( rc = arbel_cmd_rtr2rts_qpee ( arbel, qp->qpn,
1156 DBGC ( arbel, "Arbel %p QPN %#lx RTR2RTS_QPEE failed: "
1157 "%s\n", arbel, qp->qpn, strerror ( rc ) );
1160 arbel_qp->state = ARBEL_QP_ST_RTS;
1163 /* Update parameters in RTS state */
1164 memset ( &qpctx, 0, sizeof ( qpctx ) );
1165 MLX_FILL_1 ( &qpctx, 0, opt_param_mask, ARBEL_QPEE_OPT_PARAM_QKEY );
1166 MLX_FILL_1 ( &qpctx, 44, qpc_eec_data.q_key, qp->qkey );
1167 if ( ( rc = arbel_cmd_rts2rts_qpee ( arbel, qp->qpn, &qpctx ) ) != 0 ){
1168 DBGC ( arbel, "Arbel %p QPN %#lx RTS2RTS_QPEE failed: %s\n",
1169 arbel, qp->qpn, strerror ( rc ) );
1177 * Destroy queue pair
1179 * @v ibdev Infiniband device
1182 static void arbel_destroy_qp ( struct ib_device *ibdev,
1183 struct ib_queue_pair *qp ) {
1184 struct arbel *arbel = ib_get_drvdata ( ibdev );
1185 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1186 struct arbelprm_qp_db_record *send_db_rec;
1187 struct arbelprm_qp_db_record *recv_db_rec;
1190 /* Take ownership back from hardware */
1191 if ( ( rc = arbel_cmd_2rst_qpee ( arbel, qp->qpn ) ) != 0 ) {
1192 DBGC ( arbel, "Arbel %p QPN %#lx FATAL 2RST_QPEE failed: "
1193 "%s\n", arbel, qp->qpn, strerror ( rc ) );
1194 /* Leak memory and return; at least we avoid corruption */
1198 /* Clear doorbell records */
1199 send_db_rec = &arbel->db_rec[arbel_qp->send.doorbell_idx].qp;
1200 recv_db_rec = &arbel->db_rec[arbel_qp->recv.doorbell_idx].qp;
1201 MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1202 MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1205 free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
1206 free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
1209 /* Mark queue number as free */
1210 arbel_free_qpn ( ibdev, qp );
1212 ib_qp_set_drvdata ( qp, NULL );
1215 /***************************************************************************
1217 * Work request operations
1219 ***************************************************************************
1223 * Ring doorbell register in UAR
1225 * @v arbel Arbel device
1226 * @v db_reg Doorbell register structure
1227 * @v offset Address of doorbell
1229 static void arbel_ring_doorbell ( struct arbel *arbel,
1230 union arbelprm_doorbell_register *db_reg,
1231 unsigned int offset ) {
1233 DBGC2 ( arbel, "Arbel %p ringing doorbell %08x:%08x at %lx\n",
1234 arbel, ntohl ( db_reg->dword[0] ), ntohl ( db_reg->dword[1] ),
1235 virt_to_phys ( arbel->uar + offset ) );
1238 writel ( db_reg->dword[0], ( arbel->uar + offset + 0 ) );
1240 writel ( db_reg->dword[1], ( arbel->uar + offset + 4 ) );
1243 /** GID used for GID-less send work queue entries */
1244 static const union ib_gid arbel_no_gid = {
1245 .bytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0 },
1249 * Construct UD send work queue entry
1251 * @v ibdev Infiniband device
1253 * @v dest Destination address vector
1254 * @v iobuf I/O buffer
1255 * @v wqe Send work queue entry
1256 * @ret nds Work queue entry size
1258 static size_t arbel_fill_ud_send_wqe ( struct ib_device *ibdev,
1259 struct ib_queue_pair *qp __unused,
1260 struct ib_address_vector *dest,
1261 struct io_buffer *iobuf,
1262 union arbel_send_wqe *wqe ) {
1263 struct arbel *arbel = ib_get_drvdata ( ibdev );
1264 const union ib_gid *gid;
1266 /* Construct this work queue entry */
1267 MLX_FILL_1 ( &wqe->ud.ctrl, 0, always1, 1 );
1268 MLX_FILL_2 ( &wqe->ud.ud, 0,
1269 ud_address_vector.pd, ARBEL_GLOBAL_PD,
1270 ud_address_vector.port_number, ibdev->port );
1271 MLX_FILL_2 ( &wqe->ud.ud, 1,
1272 ud_address_vector.rlid, dest->lid,
1273 ud_address_vector.g, dest->gid_present );
1274 MLX_FILL_2 ( &wqe->ud.ud, 2,
1275 ud_address_vector.max_stat_rate, arbel_rate ( dest ),
1276 ud_address_vector.msg, 3 );
1277 MLX_FILL_1 ( &wqe->ud.ud, 3, ud_address_vector.sl, dest->sl );
1278 gid = ( dest->gid_present ? &dest->gid : &arbel_no_gid );
1279 memcpy ( &wqe->ud.ud.u.dwords[4], gid, sizeof ( *gid ) );
1280 MLX_FILL_1 ( &wqe->ud.ud, 8, destination_qp, dest->qpn );
1281 MLX_FILL_1 ( &wqe->ud.ud, 9, q_key, dest->qkey );
1282 MLX_FILL_1 ( &wqe->ud.data[0], 0, byte_count, iob_len ( iobuf ) );
1283 MLX_FILL_1 ( &wqe->ud.data[0], 1, l_key, arbel->lkey );
1284 MLX_FILL_H ( &wqe->ud.data[0], 2,
1285 local_address_h, virt_to_bus ( iobuf->data ) );
1286 MLX_FILL_1 ( &wqe->ud.data[0], 3,
1287 local_address_l, virt_to_bus ( iobuf->data ) );
1289 return ( offsetof ( typeof ( wqe->ud ), data[1] ) >> 4 );
1293 * Construct MLX send work queue entry
1295 * @v ibdev Infiniband device
1297 * @v dest Destination address vector
1298 * @v iobuf I/O buffer
1299 * @v wqe Send work queue entry
1300 * @ret nds Work queue entry size
1302 static size_t arbel_fill_mlx_send_wqe ( struct ib_device *ibdev,
1303 struct ib_queue_pair *qp,
1304 struct ib_address_vector *dest,
1305 struct io_buffer *iobuf,
1306 union arbel_send_wqe *wqe ) {
1307 struct arbel *arbel = ib_get_drvdata ( ibdev );
1308 struct io_buffer headers;
1310 /* Construct IB headers */
1311 iob_populate ( &headers, &wqe->mlx.headers, 0,
1312 sizeof ( wqe->mlx.headers ) );
1313 iob_reserve ( &headers, sizeof ( wqe->mlx.headers ) );
1314 ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), dest );
1316 /* Construct this work queue entry */
1317 MLX_FILL_5 ( &wqe->mlx.ctrl, 0,
1318 c, 1 /* generate completion */,
1319 icrc, 0 /* generate ICRC */,
1320 max_statrate, arbel_rate ( dest ),
1322 v15, ( ( qp->ext_qpn == IB_QPN_SMI ) ? 1 : 0 ) );
1323 MLX_FILL_1 ( &wqe->mlx.ctrl, 1, rlid, dest->lid );
1324 MLX_FILL_1 ( &wqe->mlx.data[0], 0,
1325 byte_count, iob_len ( &headers ) );
1326 MLX_FILL_1 ( &wqe->mlx.data[0], 1, l_key, arbel->lkey );
1327 MLX_FILL_H ( &wqe->mlx.data[0], 2,
1328 local_address_h, virt_to_bus ( headers.data ) );
1329 MLX_FILL_1 ( &wqe->mlx.data[0], 3,
1330 local_address_l, virt_to_bus ( headers.data ) );
1331 MLX_FILL_1 ( &wqe->mlx.data[1], 0,
1332 byte_count, ( iob_len ( iobuf ) + 4 /* ICRC */ ) );
1333 MLX_FILL_1 ( &wqe->mlx.data[1], 1, l_key, arbel->lkey );
1334 MLX_FILL_H ( &wqe->mlx.data[1], 2,
1335 local_address_h, virt_to_bus ( iobuf->data ) );
1336 MLX_FILL_1 ( &wqe->mlx.data[1], 3,
1337 local_address_l, virt_to_bus ( iobuf->data ) );
1339 return ( offsetof ( typeof ( wqe->mlx ), data[2] ) >> 4 );
1343 * Construct RC send work queue entry
1345 * @v ibdev Infiniband device
1347 * @v dest Destination address vector
1348 * @v iobuf I/O buffer
1349 * @v wqe Send work queue entry
1350 * @ret nds Work queue entry size
1352 static size_t arbel_fill_rc_send_wqe ( struct ib_device *ibdev,
1353 struct ib_queue_pair *qp __unused,
1354 struct ib_address_vector *dest __unused,
1355 struct io_buffer *iobuf,
1356 union arbel_send_wqe *wqe ) {
1357 struct arbel *arbel = ib_get_drvdata ( ibdev );
1359 /* Construct this work queue entry */
1360 MLX_FILL_1 ( &wqe->rc.ctrl, 0, always1, 1 );
1361 MLX_FILL_1 ( &wqe->rc.data[0], 0, byte_count, iob_len ( iobuf ) );
1362 MLX_FILL_1 ( &wqe->rc.data[0], 1, l_key, arbel->lkey );
1363 MLX_FILL_H ( &wqe->rc.data[0], 2,
1364 local_address_h, virt_to_bus ( iobuf->data ) );
1365 MLX_FILL_1 ( &wqe->rc.data[0], 3,
1366 local_address_l, virt_to_bus ( iobuf->data ) );
1368 return ( offsetof ( typeof ( wqe->rc ), data[1] ) >> 4 );
1371 /** Work queue entry constructors */
1373 ( * arbel_fill_send_wqe[] ) ( struct ib_device *ibdev,
1374 struct ib_queue_pair *qp,
1375 struct ib_address_vector *dest,
1376 struct io_buffer *iobuf,
1377 union arbel_send_wqe *wqe ) = {
1378 [IB_QPT_SMI] = arbel_fill_mlx_send_wqe,
1379 [IB_QPT_GSI] = arbel_fill_mlx_send_wqe,
1380 [IB_QPT_UD] = arbel_fill_ud_send_wqe,
1381 [IB_QPT_RC] = arbel_fill_rc_send_wqe,
1385 * Post send work queue entry
1387 * @v ibdev Infiniband device
1389 * @v dest Destination address vector
1390 * @v iobuf I/O buffer
1391 * @ret rc Return status code
1393 static int arbel_post_send ( struct ib_device *ibdev,
1394 struct ib_queue_pair *qp,
1395 struct ib_address_vector *dest,
1396 struct io_buffer *iobuf ) {
1397 struct arbel *arbel = ib_get_drvdata ( ibdev );
1398 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1399 struct ib_work_queue *wq = &qp->send;
1400 struct arbel_send_work_queue *arbel_send_wq = &arbel_qp->send;
1401 union arbel_send_wqe *prev_wqe;
1402 union arbel_send_wqe *wqe;
1403 struct arbelprm_qp_db_record *qp_db_rec;
1404 union arbelprm_doorbell_register db_reg;
1405 unsigned long wqe_idx_mask;
1408 /* Allocate work queue entry */
1409 wqe_idx_mask = ( wq->num_wqes - 1 );
1410 if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
1411 DBGC ( arbel, "Arbel %p QPN %#lx send queue full",
1415 wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
1416 prev_wqe = &arbel_send_wq->wqe[(wq->next_idx - 1) & wqe_idx_mask];
1417 wqe = &arbel_send_wq->wqe[wq->next_idx & wqe_idx_mask];
1419 /* Construct work queue entry */
1420 memset ( ( ( ( void * ) wqe ) + sizeof ( wqe->next ) ), 0,
1421 ( sizeof ( *wqe ) - sizeof ( wqe->next ) ) );
1422 assert ( qp->type < ( sizeof ( arbel_fill_send_wqe ) /
1423 sizeof ( arbel_fill_send_wqe[0] ) ) );
1424 assert ( arbel_fill_send_wqe[qp->type] != NULL );
1425 nds = arbel_fill_send_wqe[qp->type] ( ibdev, qp, dest, iobuf, wqe );
1426 DBGCP ( arbel, "Arbel %p QPN %#lx posting send WQE %#lx:\n",
1427 arbel, qp->qpn, ( wq->next_idx & wqe_idx_mask ) );
1428 DBGCP_HDA ( arbel, virt_to_phys ( wqe ), wqe, sizeof ( *wqe ) );
1430 /* Update previous work queue entry's "next" field */
1431 MLX_SET ( &prev_wqe->next, nopcode, ARBEL_OPCODE_SEND );
1432 MLX_FILL_3 ( &prev_wqe->next, 1,
1437 /* Update doorbell record */
1439 qp_db_rec = &arbel->db_rec[arbel_send_wq->doorbell_idx].qp;
1440 MLX_FILL_1 ( qp_db_rec, 0,
1441 counter, ( ( wq->next_idx + 1 ) & 0xffff ) );
1443 /* Ring doorbell register */
1444 MLX_FILL_4 ( &db_reg.send, 0,
1445 nopcode, ARBEL_OPCODE_SEND,
1447 wqe_counter, ( wq->next_idx & 0xffff ),
1449 MLX_FILL_2 ( &db_reg.send, 1,
1452 arbel_ring_doorbell ( arbel, &db_reg, ARBEL_DB_POST_SND_OFFSET );
1454 /* Update work queue's index */
1461 * Post receive work queue entry
1463 * @v ibdev Infiniband device
1465 * @v iobuf I/O buffer
1466 * @ret rc Return status code
1468 static int arbel_post_recv ( struct ib_device *ibdev,
1469 struct ib_queue_pair *qp,
1470 struct io_buffer *iobuf ) {
1471 struct arbel *arbel = ib_get_drvdata ( ibdev );
1472 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1473 struct ib_work_queue *wq = &qp->recv;
1474 struct arbel_recv_work_queue *arbel_recv_wq = &arbel_qp->recv;
1475 struct arbelprm_recv_wqe *wqe;
1476 union arbelprm_doorbell_record *db_rec;
1477 unsigned int wqe_idx_mask;
1479 /* Allocate work queue entry */
1480 wqe_idx_mask = ( wq->num_wqes - 1 );
1481 if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
1482 DBGC ( arbel, "Arbel %p QPN %#lx receive queue full\n",
1486 wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
1487 wqe = &arbel_recv_wq->wqe[wq->next_idx & wqe_idx_mask].recv;
1489 /* Construct work queue entry */
1490 MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_tailroom ( iobuf ) );
1491 MLX_FILL_1 ( &wqe->data[0], 1, l_key, arbel->lkey );
1492 MLX_FILL_H ( &wqe->data[0], 2,
1493 local_address_h, virt_to_bus ( iobuf->data ) );
1494 MLX_FILL_1 ( &wqe->data[0], 3,
1495 local_address_l, virt_to_bus ( iobuf->data ) );
1497 /* Update doorbell record */
1499 db_rec = &arbel->db_rec[arbel_recv_wq->doorbell_idx];
1500 MLX_FILL_1 ( &db_rec->qp, 0,
1501 counter, ( ( wq->next_idx + 1 ) & 0xffff ) );
1503 /* Update work queue's index */
1512 * @v ibdev Infiniband device
1513 * @v cq Completion queue
1514 * @v cqe Hardware completion queue entry
1515 * @ret rc Return status code
1517 static int arbel_complete ( struct ib_device *ibdev,
1518 struct ib_completion_queue *cq,
1519 union arbelprm_completion_entry *cqe ) {
1520 struct arbel *arbel = ib_get_drvdata ( ibdev );
1521 struct ib_work_queue *wq;
1522 struct ib_queue_pair *qp;
1523 struct arbel_queue_pair *arbel_qp;
1524 struct arbel_send_work_queue *arbel_send_wq;
1525 struct arbel_recv_work_queue *arbel_recv_wq;
1526 struct arbelprm_recv_wqe *recv_wqe;
1527 struct io_buffer *iobuf;
1528 struct ib_address_vector recv_dest;
1529 struct ib_address_vector recv_source;
1530 struct ib_global_route_header *grh;
1531 struct ib_address_vector *source;
1532 unsigned int opcode;
1535 unsigned long wqe_adr;
1536 unsigned long wqe_idx;
1540 /* Parse completion */
1541 qpn = MLX_GET ( &cqe->normal, my_qpn );
1542 is_send = MLX_GET ( &cqe->normal, s );
1543 wqe_adr = ( MLX_GET ( &cqe->normal, wqe_adr ) << 6 );
1544 opcode = MLX_GET ( &cqe->normal, opcode );
1545 if ( opcode >= ARBEL_OPCODE_RECV_ERROR ) {
1546 /* "s" field is not valid for error opcodes */
1547 is_send = ( opcode == ARBEL_OPCODE_SEND_ERROR );
1548 DBGC ( arbel, "Arbel %p CQN %#lx %s QPN %#lx syndrome %#x "
1549 "vendor %#x\n", arbel, cq->cqn,
1550 ( is_send ? "send" : "recv" ), qpn,
1551 MLX_GET ( &cqe->error, syndrome ),
1552 MLX_GET ( &cqe->error, vendor_code ) );
1553 DBGC_HDA ( arbel, virt_to_phys ( cqe ), cqe, sizeof ( *cqe ) );
1555 /* Don't return immediately; propagate error to completer */
1558 /* Identify work queue */
1559 wq = ib_find_wq ( cq, qpn, is_send );
1561 DBGC ( arbel, "Arbel %p CQN %#lx unknown %s QPN %#lx\n",
1562 arbel, cq->cqn, ( is_send ? "send" : "recv" ), qpn );
1566 arbel_qp = ib_qp_get_drvdata ( qp );
1567 arbel_send_wq = &arbel_qp->send;
1568 arbel_recv_wq = &arbel_qp->recv;
1570 /* Identify work queue entry index */
1572 wqe_idx = ( ( wqe_adr - virt_to_bus ( arbel_send_wq->wqe ) ) /
1573 sizeof ( arbel_send_wq->wqe[0] ) );
1574 assert ( wqe_idx < qp->send.num_wqes );
1576 wqe_idx = ( ( wqe_adr - virt_to_bus ( arbel_recv_wq->wqe ) ) /
1577 sizeof ( arbel_recv_wq->wqe[0] ) );
1578 assert ( wqe_idx < qp->recv.num_wqes );
1581 DBGCP ( arbel, "Arbel %p CQN %#lx QPN %#lx %s WQE %#lx completed:\n",
1582 arbel, cq->cqn, qp->qpn, ( is_send ? "send" : "recv" ),
1584 DBGCP_HDA ( arbel, virt_to_phys ( cqe ), cqe, sizeof ( *cqe ) );
1586 /* Identify I/O buffer */
1587 iobuf = wq->iobufs[wqe_idx];
1589 DBGC ( arbel, "Arbel %p CQN %#lx QPN %#lx empty %s WQE %#lx\n",
1590 arbel, cq->cqn, qp->qpn, ( is_send ? "send" : "recv" ),
1594 wq->iobufs[wqe_idx] = NULL;
1597 /* Hand off to completion handler */
1598 ib_complete_send ( ibdev, qp, iobuf, rc );
1600 /* Set received length */
1601 len = MLX_GET ( &cqe->normal, byte_cnt );
1602 recv_wqe = &arbel_recv_wq->wqe[wqe_idx].recv;
1603 assert ( MLX_GET ( &recv_wqe->data[0], local_address_l ) ==
1604 virt_to_bus ( iobuf->data ) );
1605 assert ( MLX_GET ( &recv_wqe->data[0], byte_count ) ==
1606 iob_tailroom ( iobuf ) );
1607 MLX_FILL_1 ( &recv_wqe->data[0], 0, byte_count, 0 );
1608 MLX_FILL_1 ( &recv_wqe->data[0], 1,
1609 l_key, ARBEL_INVALID_LKEY );
1610 assert ( len <= iob_tailroom ( iobuf ) );
1611 iob_put ( iobuf, len );
1612 memset ( &recv_dest, 0, sizeof ( recv_dest ) );
1613 recv_dest.qpn = qpn;
1614 switch ( qp->type ) {
1618 assert ( iob_len ( iobuf ) >= sizeof ( *grh ) );
1620 iob_pull ( iobuf, sizeof ( *grh ) );
1621 /* Construct address vector */
1622 source = &recv_source;
1623 memset ( source, 0, sizeof ( *source ) );
1624 source->qpn = MLX_GET ( &cqe->normal, rqpn );
1625 source->lid = MLX_GET ( &cqe->normal, rlid );
1626 source->sl = MLX_GET ( &cqe->normal, sl );
1627 recv_dest.gid_present = source->gid_present =
1628 MLX_GET ( &cqe->normal, g );
1629 memcpy ( &recv_dest.gid, &grh->dgid,
1630 sizeof ( recv_dest.gid ) );
1631 memcpy ( &source->gid, &grh->sgid,
1632 sizeof ( source->gid ) );
1641 /* Hand off to completion handler */
1642 ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc );
1649 * Poll completion queue
1651 * @v ibdev Infiniband device
1652 * @v cq Completion queue
1654 static void arbel_poll_cq ( struct ib_device *ibdev,
1655 struct ib_completion_queue *cq ) {
1656 struct arbel *arbel = ib_get_drvdata ( ibdev );
1657 struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
1658 struct arbelprm_cq_ci_db_record *ci_db_rec;
1659 union arbelprm_completion_entry *cqe;
1660 unsigned int cqe_idx_mask;
1664 /* Look for completion entry */
1665 cqe_idx_mask = ( cq->num_cqes - 1 );
1666 cqe = &arbel_cq->cqe[cq->next_idx & cqe_idx_mask];
1667 if ( MLX_GET ( &cqe->normal, owner ) != 0 ) {
1668 /* Entry still owned by hardware; end of poll */
1672 /* Handle completion */
1673 if ( ( rc = arbel_complete ( ibdev, cq, cqe ) ) != 0 ) {
1674 DBGC ( arbel, "Arbel %p CQN %#lx failed to complete: "
1675 "%s\n", arbel, cq->cqn, strerror ( rc ) );
1676 DBGC_HD ( arbel, cqe, sizeof ( *cqe ) );
1679 /* Return ownership to hardware */
1680 MLX_FILL_1 ( &cqe->normal, 7, owner, 1 );
1682 /* Update completion queue's index */
1684 /* Update doorbell record */
1685 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
1686 MLX_FILL_1 ( ci_db_rec, 0,
1687 counter, ( cq->next_idx & 0xffffffffUL ) );
1691 /***************************************************************************
1695 ***************************************************************************
1699 * Create event queue
1701 * @v arbel Arbel device
1702 * @ret rc Return status code
1704 static int arbel_create_eq ( struct arbel *arbel ) {
1705 struct arbel_event_queue *arbel_eq = &arbel->eq;
1706 struct arbelprm_eqc eqctx;
1707 struct arbelprm_event_mask mask;
1711 /* Select event queue number */
1712 arbel_eq->eqn = arbel->limits.reserved_eqs;
1714 /* Calculate doorbell address */
1715 arbel_eq->doorbell = ( arbel->eq_ci_doorbells +
1716 ARBEL_DB_EQ_OFFSET ( arbel_eq->eqn ) );
1718 /* Allocate event queue itself */
1719 arbel_eq->eqe_size =
1720 ( ARBEL_NUM_EQES * sizeof ( arbel_eq->eqe[0] ) );
1721 arbel_eq->eqe = malloc_dma ( arbel_eq->eqe_size,
1722 sizeof ( arbel_eq->eqe[0] ) );
1723 if ( ! arbel_eq->eqe ) {
1727 memset ( arbel_eq->eqe, 0, arbel_eq->eqe_size );
1728 for ( i = 0 ; i < ARBEL_NUM_EQES ; i++ ) {
1729 MLX_FILL_1 ( &arbel_eq->eqe[i].generic, 7, owner, 1 );
1733 /* Hand queue over to hardware */
1734 memset ( &eqctx, 0, sizeof ( eqctx ) );
1735 MLX_FILL_1 ( &eqctx, 0, st, 0xa /* "Fired" */ );
1736 MLX_FILL_H ( &eqctx, 1,
1737 start_address_h, virt_to_phys ( arbel_eq->eqe ) );
1738 MLX_FILL_1 ( &eqctx, 2,
1739 start_address_l, virt_to_phys ( arbel_eq->eqe ) );
1740 MLX_FILL_1 ( &eqctx, 3, log_eq_size, fls ( ARBEL_NUM_EQES - 1 ) );
1741 MLX_FILL_1 ( &eqctx, 6, pd, ARBEL_GLOBAL_PD );
1742 MLX_FILL_1 ( &eqctx, 7, lkey, arbel->lkey );
1743 if ( ( rc = arbel_cmd_sw2hw_eq ( arbel, arbel_eq->eqn,
1745 DBGC ( arbel, "Arbel %p EQN %#lx SW2HW_EQ failed: %s\n",
1746 arbel, arbel_eq->eqn, strerror ( rc ) );
1750 /* Map events to this event queue */
1751 memset ( &mask, 0xff, sizeof ( mask ) );
1752 if ( ( rc = arbel_cmd_map_eq ( arbel,
1753 ( ARBEL_MAP_EQ | arbel_eq->eqn ),
1755 DBGC ( arbel, "Arbel %p EQN %#lx MAP_EQ failed: %s\n",
1756 arbel, arbel_eq->eqn, strerror ( rc ) );
1760 DBGC ( arbel, "Arbel %p EQN %#lx ring [%08lx,%08lx), doorbell %08lx\n",
1761 arbel, arbel_eq->eqn, virt_to_phys ( arbel_eq->eqe ),
1762 ( virt_to_phys ( arbel_eq->eqe ) + arbel_eq->eqe_size ),
1763 virt_to_phys ( arbel_eq->doorbell ) );
1767 arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn, &eqctx );
1769 free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
1771 memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
1776 * Destroy event queue
1778 * @v arbel Arbel device
1780 static void arbel_destroy_eq ( struct arbel *arbel ) {
1781 struct arbel_event_queue *arbel_eq = &arbel->eq;
1782 struct arbelprm_eqc eqctx;
1783 struct arbelprm_event_mask mask;
1786 /* Unmap events from event queue */
1787 memset ( &mask, 0, sizeof ( mask ) );
1788 MLX_FILL_1 ( &mask, 1, port_state_change, 1 );
1789 if ( ( rc = arbel_cmd_map_eq ( arbel,
1790 ( ARBEL_UNMAP_EQ | arbel_eq->eqn ),
1792 DBGC ( arbel, "Arbel %p EQN %#lx FATAL MAP_EQ failed to "
1793 "unmap: %s\n", arbel, arbel_eq->eqn, strerror ( rc ) );
1794 /* Continue; HCA may die but system should survive */
1797 /* Take ownership back from hardware */
1798 if ( ( rc = arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn,
1800 DBGC ( arbel, "Arbel %p EQN %#lx FATAL HW2SW_EQ failed: %s\n",
1801 arbel, arbel_eq->eqn, strerror ( rc ) );
1802 /* Leak memory and return; at least we avoid corruption */
1807 free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
1808 memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
1812 * Handle port state event
1814 * @v arbel Arbel device
1815 * @v eqe Port state change event queue entry
1817 static void arbel_event_port_state_change ( struct arbel *arbel,
1818 union arbelprm_event_entry *eqe){
1822 /* Get port and link status */
1823 port = ( MLX_GET ( &eqe->port_state_change, data.p ) - 1 );
1824 link_up = ( MLX_GET ( &eqe->generic, event_sub_type ) & 0x04 );
1825 DBGC ( arbel, "Arbel %p port %d link %s\n", arbel, ( port + 1 ),
1826 ( link_up ? "up" : "down" ) );
1829 if ( port >= ARBEL_NUM_PORTS ) {
1830 DBGC ( arbel, "Arbel %p port %d does not exist!\n",
1831 arbel, ( port + 1 ) );
1835 /* Update MAD parameters */
1836 ib_smc_update ( arbel->ibdev[port], arbel_mad );
1842 * @v ibdev Infiniband device
1844 static void arbel_poll_eq ( struct ib_device *ibdev ) {
1845 struct arbel *arbel = ib_get_drvdata ( ibdev );
1846 struct arbel_event_queue *arbel_eq = &arbel->eq;
1847 union arbelprm_event_entry *eqe;
1848 union arbelprm_eq_doorbell_register db_reg;
1849 unsigned int eqe_idx_mask;
1850 unsigned int event_type;
1852 /* No event is generated upon reaching INIT, so we must poll
1853 * separately for link state changes while we remain DOWN.
1855 if ( ib_is_open ( ibdev ) &&
1856 ( ibdev->port_state == IB_PORT_STATE_DOWN ) ) {
1857 ib_smc_update ( ibdev, arbel_mad );
1860 /* Poll event queue */
1862 /* Look for event entry */
1863 eqe_idx_mask = ( ARBEL_NUM_EQES - 1 );
1864 eqe = &arbel_eq->eqe[arbel_eq->next_idx & eqe_idx_mask];
1865 if ( MLX_GET ( &eqe->generic, owner ) != 0 ) {
1866 /* Entry still owned by hardware; end of poll */
1869 DBGCP ( arbel, "Arbel %p EQN %#lx event:\n",
1870 arbel, arbel_eq->eqn );
1871 DBGCP_HDA ( arbel, virt_to_phys ( eqe ),
1872 eqe, sizeof ( *eqe ) );
1875 event_type = MLX_GET ( &eqe->generic, event_type );
1876 switch ( event_type ) {
1877 case ARBEL_EV_PORT_STATE_CHANGE:
1878 arbel_event_port_state_change ( arbel, eqe );
1881 DBGC ( arbel, "Arbel %p EQN %#lx unrecognised event "
1883 arbel, arbel_eq->eqn, event_type );
1884 DBGC_HDA ( arbel, virt_to_phys ( eqe ),
1885 eqe, sizeof ( *eqe ) );
1889 /* Return ownership to hardware */
1890 MLX_FILL_1 ( &eqe->generic, 7, owner, 1 );
1893 /* Update event queue's index */
1894 arbel_eq->next_idx++;
1897 MLX_FILL_1 ( &db_reg.ci, 0, ci, arbel_eq->next_idx );
1898 writel ( db_reg.dword[0], arbel_eq->doorbell );
1902 /***************************************************************************
1906 ***************************************************************************
1910 * Map virtual to physical address for firmware usage
1912 * @v arbel Arbel device
1913 * @v map Mapping function
1914 * @v va Virtual address
1915 * @v pa Physical address
1916 * @v len Length of region
1917 * @ret rc Return status code
1919 static int arbel_map_vpm ( struct arbel *arbel,
1920 int ( *map ) ( struct arbel *arbel,
1921 const struct arbelprm_virtual_physical_mapping* ),
1922 uint64_t va, physaddr_t pa, size_t len ) {
1923 struct arbelprm_virtual_physical_mapping mapping;
1932 assert ( ( va & ( ARBEL_PAGE_SIZE - 1 ) ) == 0 );
1933 assert ( ( pa & ( ARBEL_PAGE_SIZE - 1 ) ) == 0 );
1934 assert ( ( len & ( ARBEL_PAGE_SIZE - 1 ) ) == 0 );
1936 /* Calculate starting points */
1938 end = ( start + len );
1939 size = ( 1UL << ( fls ( start ^ end ) - 1 ) );
1940 low = high = ( end & ~( size - 1 ) );
1941 assert ( start < low );
1942 assert ( high <= end );
1944 /* These mappings tend to generate huge volumes of
1945 * uninteresting debug data, which basically makes it
1946 * impossible to use debugging otherwise.
1948 DBG_DISABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
1950 /* Map blocks in descending order of size */
1951 while ( size >= ARBEL_PAGE_SIZE ) {
1953 /* Find the next candidate block */
1954 if ( ( low - size ) >= start ) {
1957 } else if ( ( high + size ) <= end ) {
1964 assert ( ( va & ( size - 1 ) ) == 0 );
1965 assert ( ( pa & ( size - 1 ) ) == 0 );
1967 /* Map this block */
1968 memset ( &mapping, 0, sizeof ( mapping ) );
1969 MLX_FILL_1 ( &mapping, 0, va_h, ( va >> 32 ) );
1970 MLX_FILL_1 ( &mapping, 1, va_l, ( va >> 12 ) );
1971 MLX_FILL_H ( &mapping, 2, pa_h, pa );
1972 MLX_FILL_2 ( &mapping, 3,
1973 log2size, ( ( fls ( size ) - 1 ) - 12 ),
1974 pa_l, ( pa >> 12 ) );
1975 if ( ( rc = map ( arbel, &mapping ) ) != 0 ) {
1976 DBG_ENABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
1977 DBGC ( arbel, "Arbel %p could not map %08llx+%zx to "
1979 arbel, va, size, pa, strerror ( rc ) );
1984 assert ( low == start );
1985 assert ( high == end );
1987 DBG_ENABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
1992 * Start firmware running
1994 * @v arbel Arbel device
1995 * @ret rc Return status code
1997 static int arbel_start_firmware ( struct arbel *arbel ) {
1998 struct arbelprm_query_fw fw;
1999 struct arbelprm_access_lam lam;
2000 unsigned int fw_pages;
2003 uint64_t eq_set_ci_base_addr;
2006 /* Get firmware parameters */
2007 if ( ( rc = arbel_cmd_query_fw ( arbel, &fw ) ) != 0 ) {
2008 DBGC ( arbel, "Arbel %p could not query firmware: %s\n",
2009 arbel, strerror ( rc ) );
2012 DBGC ( arbel, "Arbel %p firmware version %d.%d.%d\n", arbel,
2013 MLX_GET ( &fw, fw_rev_major ), MLX_GET ( &fw, fw_rev_minor ),
2014 MLX_GET ( &fw, fw_rev_subminor ) );
2015 fw_pages = MLX_GET ( &fw, fw_pages );
2016 DBGC ( arbel, "Arbel %p requires %d kB for firmware\n",
2017 arbel, ( fw_pages * 4 ) );
2018 eq_set_ci_base_addr =
2019 ( ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_h ) << 32 ) |
2020 ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_l ) ) );
2021 arbel->eq_ci_doorbells = ioremap ( eq_set_ci_base_addr, 0x200 );
2023 /* Enable locally-attached memory. Ignore failure; there may
2024 * be no attached memory.
2026 arbel_cmd_enable_lam ( arbel, &lam );
2028 /* Allocate firmware pages and map firmware area */
2029 fw_len = ( fw_pages * ARBEL_PAGE_SIZE );
2030 if ( ! arbel->firmware_area ) {
2031 arbel->firmware_len = fw_len;
2032 arbel->firmware_area = umalloc ( arbel->firmware_len );
2033 if ( ! arbel->firmware_area ) {
2038 assert ( arbel->firmware_len == fw_len );
2040 fw_base = user_to_phys ( arbel->firmware_area, 0 );
2041 DBGC ( arbel, "Arbel %p firmware area at [%08lx,%08lx)\n",
2042 arbel, fw_base, ( fw_base + fw_len ) );
2043 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_fa,
2044 0, fw_base, fw_len ) ) != 0 ) {
2045 DBGC ( arbel, "Arbel %p could not map firmware: %s\n",
2046 arbel, strerror ( rc ) );
2050 /* Start firmware */
2051 if ( ( rc = arbel_cmd_run_fw ( arbel ) ) != 0 ) {
2052 DBGC ( arbel, "Arbel %p could not run firmware: %s\n",
2053 arbel, strerror ( rc ) );
2057 DBGC ( arbel, "Arbel %p firmware started\n", arbel );
2061 arbel_cmd_unmap_fa ( arbel );
2069 * Stop firmware running
2071 * @v arbel Arbel device
2073 static void arbel_stop_firmware ( struct arbel *arbel ) {
2076 if ( ( rc = arbel_cmd_unmap_fa ( arbel ) ) != 0 ) {
2077 DBGC ( arbel, "Arbel %p FATAL could not stop firmware: %s\n",
2078 arbel, strerror ( rc ) );
2079 /* Leak memory and return; at least we avoid corruption */
2080 arbel->firmware_area = UNULL;
2085 /***************************************************************************
2087 * Infinihost Context Memory management
2089 ***************************************************************************
2095 * @v arbel Arbel device
2096 * @ret rc Return status code
2098 static int arbel_get_limits ( struct arbel *arbel ) {
2099 struct arbelprm_query_dev_lim dev_lim;
2102 if ( ( rc = arbel_cmd_query_dev_lim ( arbel, &dev_lim ) ) != 0 ) {
2103 DBGC ( arbel, "Arbel %p could not get device limits: %s\n",
2104 arbel, strerror ( rc ) );
2108 arbel->limits.reserved_qps =
2109 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_qps ) );
2110 arbel->limits.qpc_entry_size = MLX_GET ( &dev_lim, qpc_entry_sz );
2111 arbel->limits.eqpc_entry_size = MLX_GET ( &dev_lim, eqpc_entry_sz );
2112 arbel->limits.reserved_srqs =
2113 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_srqs ) );
2114 arbel->limits.srqc_entry_size = MLX_GET ( &dev_lim, srq_entry_sz );
2115 arbel->limits.reserved_ees =
2116 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_ees ) );
2117 arbel->limits.eec_entry_size = MLX_GET ( &dev_lim, eec_entry_sz );
2118 arbel->limits.eeec_entry_size = MLX_GET ( &dev_lim, eeec_entry_sz );
2119 arbel->limits.reserved_cqs =
2120 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_cqs ) );
2121 arbel->limits.cqc_entry_size = MLX_GET ( &dev_lim, cqc_entry_sz );
2122 arbel->limits.reserved_mtts =
2123 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_mtts ) );
2124 arbel->limits.mtt_entry_size = MLX_GET ( &dev_lim, mtt_entry_sz );
2125 arbel->limits.reserved_mrws =
2126 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_mrws ) );
2127 arbel->limits.mpt_entry_size = MLX_GET ( &dev_lim, mpt_entry_sz );
2128 arbel->limits.reserved_rdbs =
2129 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_rdbs ) );
2130 arbel->limits.reserved_eqs = MLX_GET ( &dev_lim, num_rsvd_eqs );
2131 arbel->limits.eqc_entry_size = MLX_GET ( &dev_lim, eqc_entry_sz );
2132 arbel->limits.reserved_uars = MLX_GET ( &dev_lim, num_rsvd_uars );
2133 arbel->limits.uar_scratch_entry_size =
2134 MLX_GET ( &dev_lim, uar_scratch_entry_sz );
2136 DBGC ( arbel, "Arbel %p reserves %d x %#zx QPC, %d x %#zx EQPC, "
2137 "%d x %#zx SRQC\n", arbel,
2138 arbel->limits.reserved_qps, arbel->limits.qpc_entry_size,
2139 arbel->limits.reserved_qps, arbel->limits.eqpc_entry_size,
2140 arbel->limits.reserved_srqs, arbel->limits.srqc_entry_size );
2141 DBGC ( arbel, "Arbel %p reserves %d x %#zx EEC, %d x %#zx EEEC, "
2142 "%d x %#zx CQC\n", arbel,
2143 arbel->limits.reserved_ees, arbel->limits.eec_entry_size,
2144 arbel->limits.reserved_ees, arbel->limits.eeec_entry_size,
2145 arbel->limits.reserved_cqs, arbel->limits.cqc_entry_size );
2146 DBGC ( arbel, "Arbel %p reserves %d x %#zx EQC, %d x %#zx MTT, "
2147 "%d x %#zx MPT\n", arbel,
2148 arbel->limits.reserved_eqs, arbel->limits.eqc_entry_size,
2149 arbel->limits.reserved_mtts, arbel->limits.mtt_entry_size,
2150 arbel->limits.reserved_mrws, arbel->limits.mpt_entry_size );
2151 DBGC ( arbel, "Arbel %p reserves %d x %#zx RDB, %d x %#zx UAR, "
2152 "%d x %#zx UAR scratchpad\n", arbel,
2153 arbel->limits.reserved_rdbs, ARBEL_RDB_ENTRY_SIZE,
2154 arbel->limits.reserved_uars, ARBEL_PAGE_SIZE,
2155 arbel->limits.reserved_uars,
2156 arbel->limits.uar_scratch_entry_size );
2164 * @v icm_offset Current ICM offset
2165 * @v len ICM table length
2166 * @ret icm_offset ICM offset
2168 static size_t icm_align ( size_t icm_offset, size_t len ) {
2170 /* Round up to a multiple of the table size */
2171 assert ( len == ( 1UL << ( fls ( len ) - 1 ) ) );
2172 return ( ( icm_offset + len - 1 ) & ~( len - 1 ) );
2178 * @v arbel Arbel device
2179 * @v init_hca INIT_HCA structure to fill in
2180 * @ret rc Return status code
2182 static int arbel_alloc_icm ( struct arbel *arbel,
2183 struct arbelprm_init_hca *init_hca ) {
2184 struct arbelprm_scalar_parameter icm_size;
2185 struct arbelprm_scalar_parameter icm_aux_size;
2186 struct arbelprm_scalar_parameter unmap_icm;
2187 union arbelprm_doorbell_record *db_rec;
2188 size_t icm_offset = 0;
2189 unsigned int log_num_uars, log_num_qps, log_num_srqs, log_num_ees;
2190 unsigned int log_num_cqs, log_num_mtts, log_num_mpts, log_num_rdbs;
2191 unsigned int log_num_eqs, log_num_mcs;
2192 size_t icm_len, icm_aux_len;
2194 physaddr_t icm_phys;
2197 /* Calculate number of each object type within ICM */
2198 log_num_qps = fls ( arbel->limits.reserved_qps +
2199 ARBEL_RSVD_SPECIAL_QPS + ARBEL_MAX_QPS - 1 );
2200 log_num_srqs = fls ( arbel->limits.reserved_srqs - 1 );
2201 log_num_ees = fls ( arbel->limits.reserved_ees - 1 );
2202 log_num_cqs = fls ( arbel->limits.reserved_cqs + ARBEL_MAX_CQS - 1 );
2203 log_num_eqs = fls ( arbel->limits.reserved_eqs + ARBEL_MAX_EQS - 1 );
2204 log_num_mtts = fls ( arbel->limits.reserved_mtts - 1 );
2205 log_num_mpts = fls ( arbel->limits.reserved_mrws + 1 - 1 );
2206 log_num_rdbs = fls ( arbel->limits.reserved_rdbs +
2207 ARBEL_RSVD_SPECIAL_QPS + ARBEL_MAX_QPS - 1 );
2208 log_num_uars = fls ( arbel->limits.reserved_uars +
2209 1 /* single UAR used */ - 1 );
2210 log_num_mcs = ARBEL_LOG_MULTICAST_HASH_SIZE;
2212 /* Queue pair contexts */
2213 len = ( ( 1 << log_num_qps ) * arbel->limits.qpc_entry_size );
2214 icm_offset = icm_align ( icm_offset, len );
2215 MLX_FILL_2 ( init_hca, 13,
2216 qpc_eec_cqc_eqc_rdb_parameters.qpc_base_addr_l,
2217 ( icm_offset >> 7 ),
2218 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_qp,
2220 DBGC ( arbel, "Arbel %p ICM QPC is %d x %#zx at [%zx,%zx)\n",
2221 arbel, ( 1 << log_num_qps ), arbel->limits.qpc_entry_size,
2222 icm_offset, ( icm_offset + len ) );
2225 /* Extended queue pair contexts */
2226 len = ( ( 1 << log_num_qps ) * arbel->limits.eqpc_entry_size );
2227 icm_offset = icm_align ( icm_offset, len );
2228 MLX_FILL_1 ( init_hca, 25,
2229 qpc_eec_cqc_eqc_rdb_parameters.eqpc_base_addr_l,
2231 DBGC ( arbel, "Arbel %p ICM EQPC is %d x %#zx at [%zx,%zx)\n",
2232 arbel, ( 1 << log_num_qps ), arbel->limits.eqpc_entry_size,
2233 icm_offset, ( icm_offset + len ) );
2236 /* Completion queue contexts */
2237 len = ( ( 1 << log_num_cqs ) * arbel->limits.cqc_entry_size );
2238 icm_offset = icm_align ( icm_offset, len );
2239 MLX_FILL_2 ( init_hca, 21,
2240 qpc_eec_cqc_eqc_rdb_parameters.cqc_base_addr_l,
2241 ( icm_offset >> 6 ),
2242 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_cq,
2244 DBGC ( arbel, "Arbel %p ICM CQC is %d x %#zx at [%zx,%zx)\n",
2245 arbel, ( 1 << log_num_cqs ), arbel->limits.cqc_entry_size,
2246 icm_offset, ( icm_offset + len ) );
2249 /* Event queue contexts */
2250 len = ( ( 1 << log_num_eqs ) * arbel->limits.eqc_entry_size );
2251 icm_offset = icm_align ( icm_offset, len );
2252 MLX_FILL_2 ( init_hca, 33,
2253 qpc_eec_cqc_eqc_rdb_parameters.eqc_base_addr_l,
2254 ( icm_offset >> 6 ),
2255 qpc_eec_cqc_eqc_rdb_parameters.log_num_eq,
2257 DBGC ( arbel, "Arbel %p ICM EQC is %d x %#zx at [%zx,%zx)\n",
2258 arbel, ( 1 << log_num_eqs ), arbel->limits.eqc_entry_size,
2259 icm_offset, ( icm_offset + len ) );
2262 /* End-to-end contexts */
2263 len = ( ( 1 << log_num_ees ) * arbel->limits.eec_entry_size );
2264 icm_offset = icm_align ( icm_offset, len );
2265 MLX_FILL_2 ( init_hca, 17,
2266 qpc_eec_cqc_eqc_rdb_parameters.eec_base_addr_l,
2267 ( icm_offset >> 7 ),
2268 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_ee,
2270 DBGC ( arbel, "Arbel %p ICM EEC is %d x %#zx at [%zx,%zx)\n",
2271 arbel, ( 1 << log_num_ees ), arbel->limits.eec_entry_size,
2272 icm_offset, ( icm_offset + len ) );
2275 /* Shared receive queue contexts */
2276 len = ( ( 1 << log_num_srqs ) * arbel->limits.srqc_entry_size );
2277 icm_offset = icm_align ( icm_offset, len );
2278 MLX_FILL_2 ( init_hca, 19,
2279 qpc_eec_cqc_eqc_rdb_parameters.srqc_base_addr_l,
2280 ( icm_offset >> 5 ),
2281 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_srq,
2283 DBGC ( arbel, "Arbel %p ICM SRQC is %d x %#zx at [%zx,%zx)\n",
2284 arbel, ( 1 << log_num_srqs ), arbel->limits.srqc_entry_size,
2285 icm_offset, ( icm_offset + len ) );
2288 /* Memory protection table */
2289 len = ( ( 1 << log_num_mpts ) * arbel->limits.mpt_entry_size );
2290 icm_offset = icm_align ( icm_offset, len );
2291 MLX_FILL_1 ( init_hca, 61,
2292 tpt_parameters.mpt_base_adr_l, icm_offset );
2293 MLX_FILL_1 ( init_hca, 62,
2294 tpt_parameters.log_mpt_sz, log_num_mpts );
2295 DBGC ( arbel, "Arbel %p ICM MPT is %d x %#zx at [%zx,%zx)\n",
2296 arbel, ( 1 << log_num_mpts ), arbel->limits.mpt_entry_size,
2297 icm_offset, ( icm_offset + len ) );
2300 /* Remote read data base table */
2301 len = ( ( 1 << log_num_rdbs ) * ARBEL_RDB_ENTRY_SIZE );
2302 icm_offset = icm_align ( icm_offset, len );
2303 MLX_FILL_1 ( init_hca, 37,
2304 qpc_eec_cqc_eqc_rdb_parameters.rdb_base_addr_l,
2306 DBGC ( arbel, "Arbel %p ICM RDB is %d x %#zx at [%zx,%zx)\n",
2307 arbel, ( 1 << log_num_rdbs ), ARBEL_RDB_ENTRY_SIZE,
2308 icm_offset, ( icm_offset + len ) );
2311 /* Extended end-to-end contexts */
2312 len = ( ( 1 << log_num_ees ) * arbel->limits.eeec_entry_size );
2313 icm_offset = icm_align ( icm_offset, len );
2314 MLX_FILL_1 ( init_hca, 29,
2315 qpc_eec_cqc_eqc_rdb_parameters.eeec_base_addr_l,
2317 DBGC ( arbel, "Arbel %p ICM EEEC is %d x %#zx at [%zx,%zx)\n",
2318 arbel, ( 1 << log_num_ees ), arbel->limits.eeec_entry_size,
2319 icm_offset, ( icm_offset + len ) );
2322 /* Multicast table */
2323 len = ( ( 1 << log_num_mcs ) * sizeof ( struct arbelprm_mgm_entry ) );
2324 icm_offset = icm_align ( icm_offset, len );
2325 MLX_FILL_1 ( init_hca, 49,
2326 multicast_parameters.mc_base_addr_l, icm_offset );
2327 MLX_FILL_1 ( init_hca, 52,
2328 multicast_parameters.log_mc_table_entry_sz,
2329 fls ( sizeof ( struct arbelprm_mgm_entry ) - 1 ) );
2330 MLX_FILL_1 ( init_hca, 53,
2331 multicast_parameters.mc_table_hash_sz,
2332 ( 1 << log_num_mcs ) );
2333 MLX_FILL_1 ( init_hca, 54,
2334 multicast_parameters.log_mc_table_sz,
2335 log_num_mcs /* Only one entry per hash */ );
2336 DBGC ( arbel, "Arbel %p ICM MC is %d x %#zx at [%zx,%zx)\n", arbel,
2337 ( 1 << log_num_mcs ), sizeof ( struct arbelprm_mgm_entry ),
2338 icm_offset, ( icm_offset + len ) );
2341 /* Memory translation table */
2342 len = ( ( 1 << log_num_mtts ) * arbel->limits.mtt_entry_size );
2343 icm_offset = icm_align ( icm_offset, len );
2344 MLX_FILL_1 ( init_hca, 65,
2345 tpt_parameters.mtt_base_addr_l, icm_offset );
2346 DBGC ( arbel, "Arbel %p ICM MTT is %d x %#zx at [%zx,%zx)\n",
2347 arbel, ( 1 << log_num_mtts ), arbel->limits.mtt_entry_size,
2348 icm_offset, ( icm_offset + len ) );
2351 /* User access region scratchpads */
2352 len = ( ( 1 << log_num_uars ) * arbel->limits.uar_scratch_entry_size );
2353 icm_offset = icm_align ( icm_offset, len );
2354 MLX_FILL_1 ( init_hca, 77,
2355 uar_parameters.uar_scratch_base_addr_l, icm_offset );
2356 DBGC ( arbel, "Arbel %p UAR scratchpad is %d x %#zx at [%zx,%zx)\n",
2357 arbel, ( 1 << log_num_uars ),
2358 arbel->limits.uar_scratch_entry_size,
2359 icm_offset, ( icm_offset + len ) );
2362 /* Record amount of ICM to be allocated */
2363 icm_offset = icm_align ( icm_offset, ARBEL_PAGE_SIZE );
2364 icm_len = icm_offset;
2366 /* User access region contexts
2368 * The reserved UAR(s) do not need to be backed by physical
2369 * memory, and our UAR is allocated separately; neither are
2370 * part of the umalloc()ed ICM block, but both contribute to
2371 * the total length of ICM virtual address space.
2373 len = ( ( 1 << log_num_uars ) * ARBEL_PAGE_SIZE );
2374 icm_offset = icm_align ( icm_offset, len );
2375 MLX_FILL_1 ( init_hca, 74, uar_parameters.log_max_uars, log_num_uars );
2376 MLX_FILL_1 ( init_hca, 79,
2377 uar_parameters.uar_context_base_addr_l, icm_offset );
2378 arbel->db_rec_offset =
2380 ( arbel->limits.reserved_uars * ARBEL_PAGE_SIZE ) );
2381 DBGC ( arbel, "Arbel %p UAR is %d x %#zx at [%zx,%zx), doorbells "
2382 "[%zx,%zx)\n", arbel, ( 1 << log_num_uars ), ARBEL_PAGE_SIZE,
2383 icm_offset, ( icm_offset + len ), arbel->db_rec_offset,
2384 ( arbel->db_rec_offset + ARBEL_PAGE_SIZE ) );
2387 /* Get ICM auxiliary area size */
2388 memset ( &icm_size, 0, sizeof ( icm_size ) );
2389 MLX_FILL_1 ( &icm_size, 1, value, icm_len );
2390 if ( ( rc = arbel_cmd_set_icm_size ( arbel, &icm_size,
2391 &icm_aux_size ) ) != 0 ) {
2392 DBGC ( arbel, "Arbel %p could not set ICM size: %s\n",
2393 arbel, strerror ( rc ) );
2394 goto err_set_icm_size;
2396 icm_aux_len = ( MLX_GET ( &icm_aux_size, value ) * ARBEL_PAGE_SIZE );
2398 /* Allocate ICM data and auxiliary area */
2399 DBGC ( arbel, "Arbel %p requires %zd kB ICM and %zd kB AUX ICM\n",
2400 arbel, ( icm_len / 1024 ), ( icm_aux_len / 1024 ) );
2401 if ( ! arbel->icm ) {
2402 arbel->icm_len = icm_len;
2403 arbel->icm_aux_len = icm_aux_len;
2404 arbel->icm = umalloc ( arbel->icm_len + arbel->icm_aux_len );
2405 if ( ! arbel->icm ) {
2410 assert ( arbel->icm_len == icm_len );
2411 assert ( arbel->icm_aux_len == icm_aux_len );
2413 icm_phys = user_to_phys ( arbel->icm, 0 );
2415 /* Allocate doorbell UAR */
2416 arbel->db_rec = malloc_dma ( ARBEL_PAGE_SIZE, ARBEL_PAGE_SIZE );
2417 if ( ! arbel->db_rec ) {
2419 goto err_alloc_doorbell;
2422 /* Map ICM auxiliary area */
2423 DBGC ( arbel, "Arbel %p ICM AUX at [%08lx,%08lx)\n",
2424 arbel, icm_phys, ( icm_phys + arbel->icm_aux_len ) );
2425 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_icm_aux,
2426 0, icm_phys, arbel->icm_aux_len ) ) != 0 ){
2427 DBGC ( arbel, "Arbel %p could not map AUX ICM: %s\n",
2428 arbel, strerror ( rc ) );
2429 goto err_map_icm_aux;
2431 icm_phys += arbel->icm_aux_len;
2434 DBGC ( arbel, "Arbel %p ICM at [%08lx,%08lx)\n",
2435 arbel, icm_phys, ( icm_phys + arbel->icm_len ) );
2436 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_icm,
2437 0, icm_phys, arbel->icm_len ) ) != 0 ) {
2438 DBGC ( arbel, "Arbel %p could not map ICM: %s\n",
2439 arbel, strerror ( rc ) );
2442 icm_phys += arbel->icm_len;
2444 /* Map doorbell UAR */
2445 DBGC ( arbel, "Arbel %p UAR at [%08lx,%08lx)\n",
2446 arbel, virt_to_phys ( arbel->db_rec ),
2447 ( virt_to_phys ( arbel->db_rec ) + ARBEL_PAGE_SIZE ) );
2448 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_icm,
2449 arbel->db_rec_offset,
2450 virt_to_phys ( arbel->db_rec ),
2451 ARBEL_PAGE_SIZE ) ) != 0 ) {
2452 DBGC ( arbel, "Arbel %p could not map doorbell UAR: %s\n",
2453 arbel, strerror ( rc ) );
2454 goto err_map_doorbell;
2457 /* Initialise doorbell records */
2458 memset ( arbel->db_rec, 0, ARBEL_PAGE_SIZE );
2459 db_rec = &arbel->db_rec[ARBEL_GROUP_SEPARATOR_DOORBELL];
2460 MLX_FILL_1 ( &db_rec->qp, 1, res, ARBEL_UAR_RES_GROUP_SEP );
2464 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2465 MLX_FILL_1 ( &unmap_icm, 1, value, arbel->db_rec_offset );
2466 arbel_cmd_unmap_icm ( arbel, 1, &unmap_icm );
2468 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2469 arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / ARBEL_PAGE_SIZE ),
2472 arbel_cmd_unmap_icm_aux ( arbel );
2474 free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
2475 arbel->db_rec= NULL;
2485 * @v arbel Arbel device
2487 static void arbel_free_icm ( struct arbel *arbel ) {
2488 struct arbelprm_scalar_parameter unmap_icm;
2490 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2491 MLX_FILL_1 ( &unmap_icm, 1, value, arbel->db_rec_offset );
2492 arbel_cmd_unmap_icm ( arbel, 1, &unmap_icm );
2493 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2494 arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / ARBEL_PAGE_SIZE ),
2496 arbel_cmd_unmap_icm_aux ( arbel );
2497 free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
2498 arbel->db_rec = NULL;
2501 /***************************************************************************
2503 * Initialisation and teardown
2505 ***************************************************************************
2511 * @v arbel Arbel device
2513 static void arbel_reset ( struct arbel *arbel ) {
2514 struct pci_device *pci = arbel->pci;
2515 struct pci_config_backup backup;
2516 static const uint8_t backup_exclude[] =
2517 PCI_CONFIG_BACKUP_EXCLUDE ( 0x58, 0x5c );
2521 /* Perform device reset and preserve PCI configuration */
2522 pci_backup ( pci, &backup, backup_exclude );
2523 writel ( ARBEL_RESET_MAGIC,
2524 ( arbel->config + ARBEL_RESET_OFFSET ) );
2525 for ( i = 0 ; i < ARBEL_RESET_WAIT_TIME_MS ; i++ ) {
2527 pci_read_config_word ( pci, PCI_VENDOR_ID, &vendor );
2528 if ( vendor != 0xffff )
2531 pci_restore ( pci, &backup, backup_exclude );
2535 * Set up memory protection table
2537 * @v arbel Arbel device
2538 * @ret rc Return status code
2540 static int arbel_setup_mpt ( struct arbel *arbel ) {
2541 struct arbelprm_mpt mpt;
2546 key = ( arbel->limits.reserved_mrws | ARBEL_MKEY_PREFIX );
2547 arbel->lkey = ( ( key << 8 ) | ( key >> 24 ) );
2549 /* Initialise memory protection table */
2550 memset ( &mpt, 0, sizeof ( mpt ) );
2551 MLX_FILL_7 ( &mpt, 0,
2559 MLX_FILL_1 ( &mpt, 2, mem_key, key );
2560 MLX_FILL_2 ( &mpt, 3,
2561 pd, ARBEL_GLOBAL_PD,
2563 MLX_FILL_1 ( &mpt, 6, reg_wnd_len_h, 0xffffffffUL );
2564 MLX_FILL_1 ( &mpt, 7, reg_wnd_len_l, 0xffffffffUL );
2565 if ( ( rc = arbel_cmd_sw2hw_mpt ( arbel, arbel->limits.reserved_mrws,
2567 DBGC ( arbel, "Arbel %p could not set up MPT: %s\n",
2568 arbel, strerror ( rc ) );
2576 * Configure special queue pairs
2578 * @v arbel Arbel device
2579 * @ret rc Return status code
2581 static int arbel_configure_special_qps ( struct arbel *arbel ) {
2582 unsigned int smi_qpn_base;
2583 unsigned int gsi_qpn_base;
2586 /* Special QP block must be aligned on an even number */
2587 arbel->special_qpn_base = ( ( arbel->limits.reserved_qps + 1 ) & ~1 );
2588 arbel->qpn_base = ( arbel->special_qpn_base +
2589 ARBEL_NUM_SPECIAL_QPS );
2590 DBGC ( arbel, "Arbel %p special QPs at [%lx,%lx]\n", arbel,
2591 arbel->special_qpn_base, ( arbel->qpn_base - 1 ) );
2592 smi_qpn_base = arbel->special_qpn_base;
2593 gsi_qpn_base = ( smi_qpn_base + 2 );
2595 /* Issue commands to configure special QPs */
2596 if ( ( rc = arbel_cmd_conf_special_qp ( arbel, 0,
2597 smi_qpn_base ) ) != 0 ) {
2598 DBGC ( arbel, "Arbel %p could not configure SMI QPs: %s\n",
2599 arbel, strerror ( rc ) );
2602 if ( ( rc = arbel_cmd_conf_special_qp ( arbel, 1,
2603 gsi_qpn_base ) ) != 0 ) {
2604 DBGC ( arbel, "Arbel %p could not configure GSI QPs: %s\n",
2605 arbel, strerror ( rc ) );
2613 * Start Arbel device
2615 * @v arbel Arbel device
2616 * @v running Firmware is already running
2617 * @ret rc Return status code
2619 static int arbel_start ( struct arbel *arbel, int running ) {
2620 struct arbelprm_init_hca init_hca;
2624 /* Start firmware if not already running */
2626 if ( ( rc = arbel_start_firmware ( arbel ) ) != 0 )
2627 goto err_start_firmware;
2631 memset ( &init_hca, 0, sizeof ( init_hca ) );
2632 if ( ( rc = arbel_alloc_icm ( arbel, &init_hca ) ) != 0 )
2635 /* Initialise HCA */
2636 if ( ( rc = arbel_cmd_init_hca ( arbel, &init_hca ) ) != 0 ) {
2637 DBGC ( arbel, "Arbel %p could not initialise HCA: %s\n",
2638 arbel, strerror ( rc ) );
2642 /* Set up memory protection */
2643 if ( ( rc = arbel_setup_mpt ( arbel ) ) != 0 )
2645 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ )
2646 arbel->ibdev[i]->rdma_key = arbel->lkey;
2648 /* Set up event queue */
2649 if ( ( rc = arbel_create_eq ( arbel ) ) != 0 )
2652 /* Configure special QPs */
2653 if ( ( rc = arbel_configure_special_qps ( arbel ) ) != 0 )
2654 goto err_conf_special_qps;
2658 err_conf_special_qps:
2659 arbel_destroy_eq ( arbel );
2662 arbel_cmd_close_hca ( arbel );
2664 arbel_free_icm ( arbel );
2666 arbel_stop_firmware ( arbel );
2674 * @v arbel Arbel device
2676 static void arbel_stop ( struct arbel *arbel ) {
2677 arbel_destroy_eq ( arbel );
2678 arbel_cmd_close_hca ( arbel );
2679 arbel_free_icm ( arbel );
2680 arbel_stop_firmware ( arbel );
2681 arbel_reset ( arbel );
2687 * @v arbel Arbel device
2688 * @ret rc Return status code
2690 static int arbel_open ( struct arbel *arbel ) {
2693 /* Start device if applicable */
2694 if ( arbel->open_count == 0 ) {
2695 if ( ( rc = arbel_start ( arbel, 0 ) ) != 0 )
2699 /* Increment open counter */
2700 arbel->open_count++;
2706 * Close Arbel device
2708 * @v arbel Arbel device
2710 static void arbel_close ( struct arbel *arbel ) {
2712 /* Decrement open counter */
2713 assert ( arbel->open_count != 0 );
2714 arbel->open_count--;
2716 /* Stop device if applicable */
2717 if ( arbel->open_count == 0 )
2718 arbel_stop ( arbel );
2721 /***************************************************************************
2723 * Infiniband link-layer operations
2725 ***************************************************************************
2729 * Initialise Infiniband link
2731 * @v ibdev Infiniband device
2732 * @ret rc Return status code
2734 static int arbel_ib_open ( struct ib_device *ibdev ) {
2735 struct arbel *arbel = ib_get_drvdata ( ibdev );
2736 struct arbelprm_init_ib init_ib;
2740 if ( ( rc = arbel_open ( arbel ) ) != 0 )
2744 memset ( &init_ib, 0, sizeof ( init_ib ) );
2745 MLX_FILL_3 ( &init_ib, 0,
2746 mtu_cap, ARBEL_MTU_2048,
2749 MLX_FILL_1 ( &init_ib, 1, max_gid, 1 );
2750 MLX_FILL_1 ( &init_ib, 2, max_pkey, 64 );
2751 if ( ( rc = arbel_cmd_init_ib ( arbel, ibdev->port,
2752 &init_ib ) ) != 0 ) {
2753 DBGC ( arbel, "Arbel %p port %d could not intialise IB: %s\n",
2754 arbel, ibdev->port, strerror ( rc ) );
2758 /* Update MAD parameters */
2759 ib_smc_update ( ibdev, arbel_mad );
2764 arbel_close ( arbel );
2770 * Close Infiniband link
2772 * @v ibdev Infiniband device
2774 static void arbel_ib_close ( struct ib_device *ibdev ) {
2775 struct arbel *arbel = ib_get_drvdata ( ibdev );
2779 if ( ( rc = arbel_cmd_close_ib ( arbel, ibdev->port ) ) != 0 ) {
2780 DBGC ( arbel, "Arbel %p port %d could not close IB: %s\n",
2781 arbel, ibdev->port, strerror ( rc ) );
2782 /* Nothing we can do about this */
2785 /* Close hardware */
2786 arbel_close ( arbel );
2790 * Inform embedded subnet management agent of a received MAD
2792 * @v ibdev Infiniband device
2794 * @ret rc Return status code
2796 static int arbel_inform_sma ( struct ib_device *ibdev, union ib_mad *mad ) {
2799 /* Send the MAD to the embedded SMA */
2800 if ( ( rc = arbel_mad ( ibdev, mad ) ) != 0 )
2803 /* Update parameters held in software */
2804 ib_smc_update ( ibdev, arbel_mad );
2809 /***************************************************************************
2811 * Multicast group operations
2813 ***************************************************************************
2817 * Attach to multicast group
2819 * @v ibdev Infiniband device
2821 * @v gid Multicast GID
2822 * @ret rc Return status code
2824 static int arbel_mcast_attach ( struct ib_device *ibdev,
2825 struct ib_queue_pair *qp,
2826 union ib_gid *gid ) {
2827 struct arbel *arbel = ib_get_drvdata ( ibdev );
2828 struct arbelprm_mgm_hash hash;
2829 struct arbelprm_mgm_entry mgm;
2833 /* Generate hash table index */
2834 if ( ( rc = arbel_cmd_mgid_hash ( arbel, gid, &hash ) ) != 0 ) {
2835 DBGC ( arbel, "Arbel %p could not hash GID: %s\n",
2836 arbel, strerror ( rc ) );
2839 index = MLX_GET ( &hash, hash );
2841 /* Check for existing hash table entry */
2842 if ( ( rc = arbel_cmd_read_mgm ( arbel, index, &mgm ) ) != 0 ) {
2843 DBGC ( arbel, "Arbel %p could not read MGM %#x: %s\n",
2844 arbel, index, strerror ( rc ) );
2847 if ( MLX_GET ( &mgm, mgmqp_0.qi ) != 0 ) {
2848 /* FIXME: this implementation allows only a single QP
2849 * per multicast group, and doesn't handle hash
2850 * collisions. Sufficient for IPoIB but may need to
2851 * be extended in future.
2853 DBGC ( arbel, "Arbel %p MGID index %#x already in use\n",
2858 /* Update hash table entry */
2859 MLX_FILL_2 ( &mgm, 8,
2860 mgmqp_0.qpn_i, qp->qpn,
2862 memcpy ( &mgm.u.dwords[4], gid, sizeof ( *gid ) );
2863 if ( ( rc = arbel_cmd_write_mgm ( arbel, index, &mgm ) ) != 0 ) {
2864 DBGC ( arbel, "Arbel %p could not write MGM %#x: %s\n",
2865 arbel, index, strerror ( rc ) );
2873 * Detach from multicast group
2875 * @v ibdev Infiniband device
2877 * @v gid Multicast GID
2879 static void arbel_mcast_detach ( struct ib_device *ibdev,
2880 struct ib_queue_pair *qp __unused,
2881 union ib_gid *gid ) {
2882 struct arbel *arbel = ib_get_drvdata ( ibdev );
2883 struct arbelprm_mgm_hash hash;
2884 struct arbelprm_mgm_entry mgm;
2888 /* Generate hash table index */
2889 if ( ( rc = arbel_cmd_mgid_hash ( arbel, gid, &hash ) ) != 0 ) {
2890 DBGC ( arbel, "Arbel %p could not hash GID: %s\n",
2891 arbel, strerror ( rc ) );
2894 index = MLX_GET ( &hash, hash );
2896 /* Clear hash table entry */
2897 memset ( &mgm, 0, sizeof ( mgm ) );
2898 if ( ( rc = arbel_cmd_write_mgm ( arbel, index, &mgm ) ) != 0 ) {
2899 DBGC ( arbel, "Arbel %p could not write MGM %#x: %s\n",
2900 arbel, index, strerror ( rc ) );
2905 /** Arbel Infiniband operations */
2906 static struct ib_device_operations arbel_ib_operations = {
2907 .create_cq = arbel_create_cq,
2908 .destroy_cq = arbel_destroy_cq,
2909 .create_qp = arbel_create_qp,
2910 .modify_qp = arbel_modify_qp,
2911 .destroy_qp = arbel_destroy_qp,
2912 .post_send = arbel_post_send,
2913 .post_recv = arbel_post_recv,
2914 .poll_cq = arbel_poll_cq,
2915 .poll_eq = arbel_poll_eq,
2916 .open = arbel_ib_open,
2917 .close = arbel_ib_close,
2918 .mcast_attach = arbel_mcast_attach,
2919 .mcast_detach = arbel_mcast_detach,
2920 .set_port_info = arbel_inform_sma,
2921 .set_pkey_table = arbel_inform_sma,
2924 /***************************************************************************
2928 ***************************************************************************
2932 * Allocate Arbel device
2934 * @ret arbel Arbel device
2936 static struct arbel * arbel_alloc ( void ) {
2937 struct arbel *arbel;
2939 /* Allocate Arbel device */
2940 arbel = zalloc ( sizeof ( *arbel ) );
2944 /* Allocate space for mailboxes */
2945 arbel->mailbox_in = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
2946 if ( ! arbel->mailbox_in )
2947 goto err_mailbox_in;
2948 arbel->mailbox_out = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
2949 if ( ! arbel->mailbox_out )
2950 goto err_mailbox_out;
2954 free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
2956 free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
2966 * @v arbel Arbel device
2968 static void arbel_free ( struct arbel *arbel ) {
2970 ufree ( arbel->icm );
2971 ufree ( arbel->firmware_area );
2972 free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
2973 free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
2982 * @ret rc Return status code
2984 static int arbel_probe ( struct pci_device *pci ) {
2985 struct arbel *arbel;
2986 struct ib_device *ibdev;
2990 /* Allocate Arbel device */
2991 arbel = arbel_alloc();
2996 pci_set_drvdata ( pci, arbel );
2999 /* Allocate Infiniband devices */
3000 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
3001 ibdev = alloc_ibdev ( 0 );
3004 goto err_alloc_ibdev;
3006 arbel->ibdev[i] = ibdev;
3007 ibdev->op = &arbel_ib_operations;
3008 ibdev->dev = &pci->dev;
3009 ibdev->port = ( ARBEL_PORT_BASE + i );
3010 ib_set_drvdata ( ibdev, arbel );
3013 /* Fix up PCI device */
3014 adjust_pci_device ( pci );
3017 arbel->config = ioremap ( pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR ),
3018 ARBEL_PCI_CONFIG_BAR_SIZE );
3019 arbel->uar = ioremap ( ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) +
3020 ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE ),
3021 ARBEL_PCI_UAR_SIZE );
3024 arbel_reset ( arbel );
3026 /* Start firmware */
3027 if ( ( rc = arbel_start_firmware ( arbel ) ) != 0 )
3028 goto err_start_firmware;
3030 /* Get device limits */
3031 if ( ( rc = arbel_get_limits ( arbel ) ) != 0 )
3032 goto err_get_limits;
3035 if ( ( rc = arbel_start ( arbel, 1 ) ) != 0 )
3038 /* Initialise parameters using SMC */
3039 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ )
3040 ib_smc_init ( arbel->ibdev[i], arbel_mad );
3042 /* Register Infiniband devices */
3043 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
3044 if ( ( rc = register_ibdev ( arbel->ibdev[i] ) ) != 0 ) {
3045 DBGC ( arbel, "Arbel %p port %d could not register IB "
3046 "device: %s\n", arbel,
3047 arbel->ibdev[i]->port, strerror ( rc ) );
3048 goto err_register_ibdev;
3052 /* Leave device quiescent until opened */
3053 if ( arbel->open_count == 0 )
3054 arbel_stop ( arbel );
3058 i = ARBEL_NUM_PORTS;
3060 for ( i-- ; i >= 0 ; i-- )
3061 unregister_ibdev ( arbel->ibdev[i] );
3062 arbel_stop ( arbel );
3065 arbel_stop_firmware ( arbel );
3067 i = ARBEL_NUM_PORTS;
3069 for ( i-- ; i >= 0 ; i-- )
3070 ibdev_put ( arbel->ibdev[i] );
3071 arbel_free ( arbel );
3081 static void arbel_remove ( struct pci_device *pci ) {
3082 struct arbel *arbel = pci_get_drvdata ( pci );
3085 for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
3086 unregister_ibdev ( arbel->ibdev[i] );
3087 for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
3088 ibdev_put ( arbel->ibdev[i] );
3089 arbel_free ( arbel );
3092 static struct pci_device_id arbel_nics[] = {
3093 PCI_ROM ( 0x15b3, 0x6282, "mt25218", "MT25218 HCA driver", 0 ),
3094 PCI_ROM ( 0x15b3, 0x6274, "mt25204", "MT25204 HCA driver", 0 ),
3097 struct pci_driver arbel_driver __pci_driver = {
3099 .id_count = ( sizeof ( arbel_nics ) / sizeof ( arbel_nics[0] ) ),
3100 .probe = arbel_probe,
3101 .remove = arbel_remove,