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
22 * You can also choose to distribute this program under the terms of
23 * the Unmodified Binary Distribution Licence (as given in the file
24 * COPYING.UBDL), provided that you have satisfied its requirements.
27 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
39 #include <ipxe/pcibackup.h>
40 #include <ipxe/malloc.h>
41 #include <ipxe/umalloc.h>
42 #include <ipxe/iobuf.h>
43 #include <ipxe/netdevice.h>
44 #include <ipxe/infiniband.h>
45 #include <ipxe/ib_smc.h>
51 * Mellanox Arbel Infiniband HCA
55 /***************************************************************************
57 * Queue number allocation
59 ***************************************************************************
63 * Allocate offset within usage bitmask
65 * @v bits Usage bitmask
66 * @v bits_len Length of usage bitmask
67 * @ret bit First free bit within bitmask, or negative error
69 static int arbel_bitmask_alloc ( arbel_bitmask_t *bits,
70 unsigned int bits_len ) {
72 arbel_bitmask_t mask = 1;
74 while ( bit < bits_len ) {
75 if ( ( mask & *bits ) == 0 ) {
80 mask = ( mask << 1 ) | ( mask >> ( 8 * sizeof ( mask ) - 1 ) );
88 * Free offset within usage bitmask
90 * @v bits Usage bitmask
91 * @v bit Bit within bitmask
93 static void arbel_bitmask_free ( arbel_bitmask_t *bits, int bit ) {
96 mask = ( 1 << ( bit % ( 8 * sizeof ( mask ) ) ) );
97 bits += ( bit / ( 8 * sizeof ( mask ) ) );
101 /***************************************************************************
105 ***************************************************************************
109 * Wait for Arbel command completion
111 * @v arbel Arbel device
112 * @ret rc Return status code
114 static int arbel_cmd_wait ( struct arbel *arbel,
115 struct arbelprm_hca_command_register *hcr ) {
118 for ( wait = ARBEL_HCR_MAX_WAIT_MS ; wait ; wait-- ) {
120 readl ( arbel->config + ARBEL_HCR_REG ( 6 ) );
121 if ( MLX_GET ( hcr, go ) == 0 )
131 * @v arbel Arbel device
132 * @v command Command opcode, flags and input/output lengths
133 * @v op_mod Opcode modifier (0 if no modifier applicable)
134 * @v in Input parameters
135 * @v in_mod Input modifier (0 if no modifier applicable)
136 * @v out Output parameters
137 * @ret rc Return status code
139 static int arbel_cmd ( struct arbel *arbel, unsigned long command,
140 unsigned int op_mod, const void *in,
141 unsigned int in_mod, void *out ) {
142 struct arbelprm_hca_command_register hcr;
143 unsigned int opcode = ARBEL_HCR_OPCODE ( command );
144 size_t in_len = ARBEL_HCR_IN_LEN ( command );
145 size_t out_len = ARBEL_HCR_OUT_LEN ( command );
152 assert ( in_len <= ARBEL_MBOX_SIZE );
153 assert ( out_len <= ARBEL_MBOX_SIZE );
155 DBGC2 ( arbel, "Arbel %p command %02x in %zx%s out %zx%s\n",
156 arbel, opcode, in_len,
157 ( ( command & ARBEL_HCR_IN_MBOX ) ? "(mbox)" : "" ), out_len,
158 ( ( command & ARBEL_HCR_OUT_MBOX ) ? "(mbox)" : "" ) );
160 /* Check that HCR is free */
161 if ( ( rc = arbel_cmd_wait ( arbel, &hcr ) ) != 0 ) {
162 DBGC ( arbel, "Arbel %p command interface locked\n", arbel );
167 memset ( &hcr, 0, sizeof ( hcr ) );
168 in_buffer = &hcr.u.dwords[0];
169 if ( in_len && ( command & ARBEL_HCR_IN_MBOX ) ) {
170 in_buffer = arbel->mailbox_in;
171 MLX_FILL_H ( &hcr, 0, in_param_h, virt_to_bus ( in_buffer ) );
172 MLX_FILL_1 ( &hcr, 1, in_param_l, virt_to_bus ( in_buffer ) );
174 memcpy ( in_buffer, in, in_len );
175 MLX_FILL_1 ( &hcr, 2, input_modifier, in_mod );
176 out_buffer = &hcr.u.dwords[3];
177 if ( out_len && ( command & ARBEL_HCR_OUT_MBOX ) ) {
178 out_buffer = arbel->mailbox_out;
179 MLX_FILL_H ( &hcr, 3, out_param_h,
180 virt_to_bus ( out_buffer ) );
181 MLX_FILL_1 ( &hcr, 4, out_param_l,
182 virt_to_bus ( out_buffer ) );
184 MLX_FILL_3 ( &hcr, 6,
186 opcode_modifier, op_mod,
188 DBGC ( arbel, "Arbel %p issuing command %04x\n", arbel, opcode );
189 DBGC2_HDA ( arbel, virt_to_phys ( arbel->config + ARBEL_HCR_BASE ),
190 &hcr, sizeof ( hcr ) );
191 if ( in_len && ( command & ARBEL_HCR_IN_MBOX ) ) {
192 DBGC2 ( arbel, "Input mailbox:\n" );
193 DBGC2_HDA ( arbel, virt_to_phys ( in_buffer ), in_buffer,
194 ( ( in_len < 512 ) ? in_len : 512 ) );
198 for ( i = 0 ; i < ( sizeof ( hcr ) / sizeof ( hcr.u.dwords[0] ) ) ;
200 writel ( hcr.u.dwords[i],
201 arbel->config + ARBEL_HCR_REG ( i ) );
205 /* Wait for command completion */
206 if ( ( rc = arbel_cmd_wait ( arbel, &hcr ) ) != 0 ) {
207 DBGC ( arbel, "Arbel %p timed out waiting for command:\n",
209 DBGC_HD ( arbel, &hcr, sizeof ( hcr ) );
213 /* Check command status */
214 status = MLX_GET ( &hcr, status );
216 DBGC ( arbel, "Arbel %p command failed with status %02x:\n",
218 DBGC_HD ( arbel, &hcr, sizeof ( hcr ) );
222 /* Read output parameters, if any */
223 hcr.u.dwords[3] = readl ( arbel->config + ARBEL_HCR_REG ( 3 ) );
224 hcr.u.dwords[4] = readl ( arbel->config + ARBEL_HCR_REG ( 4 ) );
225 memcpy ( out, out_buffer, out_len );
227 DBGC2 ( arbel, "Output%s:\n",
228 ( command & ARBEL_HCR_OUT_MBOX ) ? " mailbox" : "" );
229 DBGC2_HDA ( arbel, virt_to_phys ( out_buffer ), out_buffer,
230 ( ( out_len < 512 ) ? out_len : 512 ) );
237 arbel_cmd_query_dev_lim ( struct arbel *arbel,
238 struct arbelprm_query_dev_lim *dev_lim ) {
239 return arbel_cmd ( arbel,
240 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_DEV_LIM,
241 1, sizeof ( *dev_lim ) ),
242 0, NULL, 0, dev_lim );
246 arbel_cmd_query_fw ( struct arbel *arbel, struct arbelprm_query_fw *fw ) {
247 return arbel_cmd ( arbel,
248 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_FW,
254 arbel_cmd_init_hca ( struct arbel *arbel,
255 const struct arbelprm_init_hca *init_hca ) {
256 return arbel_cmd ( arbel,
257 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT_HCA,
258 1, sizeof ( *init_hca ) ),
259 0, init_hca, 0, NULL );
263 arbel_cmd_close_hca ( struct arbel *arbel ) {
264 return arbel_cmd ( arbel,
265 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CLOSE_HCA ),
270 arbel_cmd_init_ib ( struct arbel *arbel, unsigned int port,
271 const struct arbelprm_init_ib *init_ib ) {
272 return arbel_cmd ( arbel,
273 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT_IB,
274 1, sizeof ( *init_ib ) ),
275 0, init_ib, port, NULL );
279 arbel_cmd_close_ib ( struct arbel *arbel, unsigned int port ) {
280 return arbel_cmd ( arbel,
281 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CLOSE_IB ),
282 0, NULL, port, NULL );
286 arbel_cmd_sw2hw_mpt ( struct arbel *arbel, unsigned int index,
287 const struct arbelprm_mpt *mpt ) {
288 return arbel_cmd ( arbel,
289 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_MPT,
290 1, sizeof ( *mpt ) ),
291 0, mpt, index, NULL );
295 arbel_cmd_map_eq ( struct arbel *arbel, unsigned long index_map,
296 const struct arbelprm_event_mask *mask ) {
297 return arbel_cmd ( arbel,
298 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_EQ,
299 0, sizeof ( *mask ) ),
300 0, mask, index_map, NULL );
304 arbel_cmd_sw2hw_eq ( struct arbel *arbel, unsigned int index,
305 const struct arbelprm_eqc *eqctx ) {
306 return arbel_cmd ( arbel,
307 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_EQ,
308 1, sizeof ( *eqctx ) ),
309 0, eqctx, index, NULL );
313 arbel_cmd_hw2sw_eq ( struct arbel *arbel, unsigned int index,
314 struct arbelprm_eqc *eqctx ) {
315 return arbel_cmd ( arbel,
316 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_HW2SW_EQ,
317 1, sizeof ( *eqctx ) ),
318 1, NULL, index, eqctx );
322 arbel_cmd_sw2hw_cq ( struct arbel *arbel, unsigned long cqn,
323 const struct arbelprm_completion_queue_context *cqctx ) {
324 return arbel_cmd ( arbel,
325 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_CQ,
326 1, sizeof ( *cqctx ) ),
327 0, cqctx, cqn, NULL );
331 arbel_cmd_hw2sw_cq ( struct arbel *arbel, unsigned long cqn,
332 struct arbelprm_completion_queue_context *cqctx) {
333 return arbel_cmd ( arbel,
334 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_HW2SW_CQ,
335 1, sizeof ( *cqctx ) ),
336 0, NULL, cqn, cqctx );
340 arbel_cmd_query_cq ( struct arbel *arbel, unsigned long cqn,
341 struct arbelprm_completion_queue_context *cqctx ) {
342 return arbel_cmd ( arbel,
343 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_CQ,
344 1, sizeof ( *cqctx ) ),
345 0, NULL, cqn, cqctx );
349 arbel_cmd_rst2init_qpee ( struct arbel *arbel, unsigned long qpn,
350 const struct arbelprm_qp_ee_state_transitions *ctx ){
351 return arbel_cmd ( arbel,
352 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RST2INIT_QPEE,
353 1, sizeof ( *ctx ) ),
358 arbel_cmd_init2rtr_qpee ( struct arbel *arbel, unsigned long qpn,
359 const struct arbelprm_qp_ee_state_transitions *ctx ){
360 return arbel_cmd ( arbel,
361 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT2RTR_QPEE,
362 1, sizeof ( *ctx ) ),
367 arbel_cmd_rtr2rts_qpee ( struct arbel *arbel, unsigned long qpn,
368 const struct arbelprm_qp_ee_state_transitions *ctx ) {
369 return arbel_cmd ( arbel,
370 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RTR2RTS_QPEE,
371 1, sizeof ( *ctx ) ),
376 arbel_cmd_rts2rts_qpee ( struct arbel *arbel, unsigned long qpn,
377 const struct arbelprm_qp_ee_state_transitions *ctx ) {
378 return arbel_cmd ( arbel,
379 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RTS2RTS_QPEE,
380 1, sizeof ( *ctx ) ),
385 arbel_cmd_2rst_qpee ( struct arbel *arbel, unsigned long qpn ) {
386 return arbel_cmd ( arbel,
387 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_2RST_QPEE ),
388 0x03, NULL, qpn, NULL );
392 arbel_cmd_query_qpee ( struct arbel *arbel, unsigned long qpn,
393 struct arbelprm_qp_ee_state_transitions *ctx ) {
394 return arbel_cmd ( arbel,
395 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_QPEE,
396 1, sizeof ( *ctx ) ),
401 arbel_cmd_conf_special_qp ( struct arbel *arbel, unsigned int qp_type,
402 unsigned long base_qpn ) {
403 return arbel_cmd ( arbel,
404 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CONF_SPECIAL_QP ),
405 qp_type, NULL, base_qpn, NULL );
409 arbel_cmd_mad_ifc ( struct arbel *arbel, unsigned int port,
410 union arbelprm_mad *mad ) {
411 return arbel_cmd ( arbel,
412 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_MAD_IFC,
414 1, sizeof ( *mad ) ),
415 0x03, mad, port, mad );
419 arbel_cmd_read_mgm ( struct arbel *arbel, unsigned int index,
420 struct arbelprm_mgm_entry *mgm ) {
421 return arbel_cmd ( arbel,
422 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_READ_MGM,
423 1, sizeof ( *mgm ) ),
424 0, NULL, index, mgm );
428 arbel_cmd_write_mgm ( struct arbel *arbel, unsigned int index,
429 const struct arbelprm_mgm_entry *mgm ) {
430 return arbel_cmd ( arbel,
431 ARBEL_HCR_IN_CMD ( ARBEL_HCR_WRITE_MGM,
432 1, sizeof ( *mgm ) ),
433 0, mgm, index, NULL );
437 arbel_cmd_mgid_hash ( struct arbel *arbel, const union ib_gid *gid,
438 struct arbelprm_mgm_hash *hash ) {
439 return arbel_cmd ( arbel,
440 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_MGID_HASH,
442 0, sizeof ( *hash ) ),
447 arbel_cmd_run_fw ( struct arbel *arbel ) {
448 return arbel_cmd ( arbel,
449 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_RUN_FW ),
454 arbel_cmd_disable_lam ( struct arbel *arbel ) {
455 return arbel_cmd ( arbel,
456 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_DISABLE_LAM ),
461 arbel_cmd_enable_lam ( struct arbel *arbel, struct arbelprm_access_lam *lam ) {
462 return arbel_cmd ( arbel,
463 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_ENABLE_LAM,
464 1, sizeof ( *lam ) ),
469 arbel_cmd_unmap_icm ( struct arbel *arbel, unsigned int page_count,
470 const struct arbelprm_scalar_parameter *offset ) {
471 return arbel_cmd ( arbel,
472 ARBEL_HCR_IN_CMD ( ARBEL_HCR_UNMAP_ICM, 0,
473 sizeof ( *offset ) ),
474 0, offset, page_count, NULL );
478 arbel_cmd_map_icm ( struct arbel *arbel,
479 const struct arbelprm_virtual_physical_mapping *map ) {
480 return arbel_cmd ( arbel,
481 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_ICM,
482 1, sizeof ( *map ) ),
487 arbel_cmd_unmap_icm_aux ( struct arbel *arbel ) {
488 return arbel_cmd ( arbel,
489 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_UNMAP_ICM_AUX ),
494 arbel_cmd_map_icm_aux ( struct arbel *arbel,
495 const struct arbelprm_virtual_physical_mapping *map ) {
496 return arbel_cmd ( arbel,
497 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_ICM_AUX,
498 1, sizeof ( *map ) ),
503 arbel_cmd_set_icm_size ( struct arbel *arbel,
504 const struct arbelprm_scalar_parameter *icm_size,
505 struct arbelprm_scalar_parameter *icm_aux_size ) {
506 return arbel_cmd ( arbel,
507 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_SET_ICM_SIZE,
508 0, sizeof ( *icm_size ),
509 0, sizeof ( *icm_aux_size ) ),
510 0, icm_size, 0, icm_aux_size );
514 arbel_cmd_unmap_fa ( struct arbel *arbel ) {
515 return arbel_cmd ( arbel,
516 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_UNMAP_FA ),
521 arbel_cmd_map_fa ( struct arbel *arbel,
522 const struct arbelprm_virtual_physical_mapping *map ) {
523 return arbel_cmd ( arbel,
524 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_FA,
525 1, sizeof ( *map ) ),
529 /***************************************************************************
533 ***************************************************************************
537 * Issue management datagram
539 * @v ibdev Infiniband device
540 * @v mad Management datagram
541 * @ret rc Return status code
543 static int arbel_mad ( struct ib_device *ibdev, union ib_mad *mad ) {
544 struct arbel *arbel = ib_get_drvdata ( ibdev );
545 union arbelprm_mad mad_ifc;
548 linker_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ),
551 /* Copy in request packet */
552 memcpy ( &mad_ifc.mad, mad, sizeof ( mad_ifc.mad ) );
555 if ( ( rc = arbel_cmd_mad_ifc ( arbel, ibdev->port,
556 &mad_ifc ) ) != 0 ) {
557 DBGC ( arbel, "Arbel %p port %d could not issue MAD IFC: %s\n",
558 arbel, ibdev->port, strerror ( rc ) );
562 /* Copy out reply packet */
563 memcpy ( mad, &mad_ifc.mad, sizeof ( *mad ) );
565 if ( mad->hdr.status != 0 ) {
566 DBGC ( arbel, "Arbel %p port %d MAD IFC status %04x\n",
567 arbel, ibdev->port, ntohs ( mad->hdr.status ) );
573 /***************************************************************************
575 * Completion queue operations
577 ***************************************************************************
581 * Dump completion queue context (for debugging only)
583 * @v arbel Arbel device
584 * @v cq Completion queue
585 * @ret rc Return status code
587 static __attribute__ (( unused )) int
588 arbel_dump_cqctx ( struct arbel *arbel, struct ib_completion_queue *cq ) {
589 struct arbelprm_completion_queue_context cqctx;
592 memset ( &cqctx, 0, sizeof ( cqctx ) );
593 if ( ( rc = arbel_cmd_query_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
594 DBGC ( arbel, "Arbel %p CQN %#lx QUERY_CQ failed: %s\n",
595 arbel, cq->cqn, strerror ( rc ) );
598 DBGC ( arbel, "Arbel %p CQN %#lx context:\n", arbel, cq->cqn );
599 DBGC_HDA ( arbel, 0, &cqctx, sizeof ( cqctx ) );
605 * Create completion queue
607 * @v ibdev Infiniband device
608 * @v cq Completion queue
609 * @ret rc Return status code
611 static int arbel_create_cq ( struct ib_device *ibdev,
612 struct ib_completion_queue *cq ) {
613 struct arbel *arbel = ib_get_drvdata ( ibdev );
614 struct arbel_completion_queue *arbel_cq;
615 struct arbelprm_completion_queue_context cqctx;
616 struct arbelprm_cq_ci_db_record *ci_db_rec;
617 struct arbelprm_cq_arm_db_record *arm_db_rec;
622 /* Find a free completion queue number */
623 cqn_offset = arbel_bitmask_alloc ( arbel->cq_inuse, ARBEL_MAX_CQS );
624 if ( cqn_offset < 0 ) {
625 DBGC ( arbel, "Arbel %p out of completion queues\n", arbel );
629 cq->cqn = ( arbel->limits.reserved_cqs + cqn_offset );
631 /* Allocate control structures */
632 arbel_cq = zalloc ( sizeof ( *arbel_cq ) );
637 arbel_cq->ci_doorbell_idx = arbel_cq_ci_doorbell_idx ( arbel, cq );
638 arbel_cq->arm_doorbell_idx = arbel_cq_arm_doorbell_idx ( arbel, cq );
640 /* Allocate completion queue itself */
641 arbel_cq->cqe_size = ( cq->num_cqes * sizeof ( arbel_cq->cqe[0] ) );
642 arbel_cq->cqe = malloc_dma ( arbel_cq->cqe_size,
643 sizeof ( arbel_cq->cqe[0] ) );
644 if ( ! arbel_cq->cqe ) {
648 memset ( arbel_cq->cqe, 0, arbel_cq->cqe_size );
649 for ( i = 0 ; i < cq->num_cqes ; i++ ) {
650 MLX_FILL_1 ( &arbel_cq->cqe[i].normal, 7, owner, 1 );
654 /* Initialise doorbell records */
655 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
656 MLX_FILL_1 ( ci_db_rec, 0, counter, 0 );
657 MLX_FILL_2 ( ci_db_rec, 1,
658 res, ARBEL_UAR_RES_CQ_CI,
659 cq_number, cq->cqn );
660 arm_db_rec = &arbel->db_rec[arbel_cq->arm_doorbell_idx].cq_arm;
661 MLX_FILL_1 ( arm_db_rec, 0, counter, 0 );
662 MLX_FILL_2 ( arm_db_rec, 1,
663 res, ARBEL_UAR_RES_CQ_ARM,
664 cq_number, cq->cqn );
666 /* Hand queue over to hardware */
667 memset ( &cqctx, 0, sizeof ( cqctx ) );
668 MLX_FILL_1 ( &cqctx, 0, st, 0xa /* "Event fired" */ );
669 MLX_FILL_H ( &cqctx, 1, start_address_h,
670 virt_to_bus ( arbel_cq->cqe ) );
671 MLX_FILL_1 ( &cqctx, 2, start_address_l,
672 virt_to_bus ( arbel_cq->cqe ) );
673 MLX_FILL_2 ( &cqctx, 3,
674 usr_page, arbel->limits.reserved_uars,
675 log_cq_size, fls ( cq->num_cqes - 1 ) );
676 MLX_FILL_1 ( &cqctx, 5, c_eqn, arbel->eq.eqn );
677 MLX_FILL_1 ( &cqctx, 6, pd, ARBEL_GLOBAL_PD );
678 MLX_FILL_1 ( &cqctx, 7, l_key, arbel->lkey );
679 MLX_FILL_1 ( &cqctx, 12, cqn, cq->cqn );
680 MLX_FILL_1 ( &cqctx, 13,
681 cq_ci_db_record, arbel_cq->ci_doorbell_idx );
682 MLX_FILL_1 ( &cqctx, 14,
683 cq_state_db_record, arbel_cq->arm_doorbell_idx );
684 if ( ( rc = arbel_cmd_sw2hw_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
685 DBGC ( arbel, "Arbel %p CQN %#lx SW2HW_CQ failed: %s\n",
686 arbel, cq->cqn, strerror ( rc ) );
690 DBGC ( arbel, "Arbel %p CQN %#lx ring [%08lx,%08lx), doorbell %08lx\n",
691 arbel, cq->cqn, virt_to_phys ( arbel_cq->cqe ),
692 ( virt_to_phys ( arbel_cq->cqe ) + arbel_cq->cqe_size ),
693 virt_to_phys ( ci_db_rec ) );
694 ib_cq_set_drvdata ( cq, arbel_cq );
698 MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
699 MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
700 free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
704 arbel_bitmask_free ( arbel->cq_inuse, cqn_offset );
710 * Destroy completion queue
712 * @v ibdev Infiniband device
713 * @v cq Completion queue
715 static void arbel_destroy_cq ( struct ib_device *ibdev,
716 struct ib_completion_queue *cq ) {
717 struct arbel *arbel = ib_get_drvdata ( ibdev );
718 struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
719 struct arbelprm_completion_queue_context cqctx;
720 struct arbelprm_cq_ci_db_record *ci_db_rec;
721 struct arbelprm_cq_arm_db_record *arm_db_rec;
725 /* Take ownership back from hardware */
726 if ( ( rc = arbel_cmd_hw2sw_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
727 DBGC ( arbel, "Arbel %p CQN %#lx FATAL HW2SW_CQ failed: "
728 "%s\n", arbel, cq->cqn, strerror ( rc ) );
729 /* Leak memory and return; at least we avoid corruption */
733 /* Clear doorbell records */
734 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
735 arm_db_rec = &arbel->db_rec[arbel_cq->arm_doorbell_idx].cq_arm;
736 MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
737 MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
740 free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
743 /* Mark queue number as free */
744 cqn_offset = ( cq->cqn - arbel->limits.reserved_cqs );
745 arbel_bitmask_free ( arbel->cq_inuse, cqn_offset );
747 ib_cq_set_drvdata ( cq, NULL );
750 /***************************************************************************
752 * Queue pair operations
754 ***************************************************************************
758 * Assign queue pair number
760 * @v ibdev Infiniband device
762 * @ret rc Return status code
764 static int arbel_alloc_qpn ( struct ib_device *ibdev,
765 struct ib_queue_pair *qp ) {
766 struct arbel *arbel = ib_get_drvdata ( ibdev );
767 unsigned int port_offset;
770 /* Calculate queue pair number */
771 port_offset = ( ibdev->port - ARBEL_PORT_BASE );
773 switch ( qp->type ) {
775 qp->qpn = ( arbel->special_qpn_base + port_offset );
778 qp->qpn = ( arbel->special_qpn_base + 2 + port_offset );
782 /* Find a free queue pair number */
783 qpn_offset = arbel_bitmask_alloc ( arbel->qp_inuse,
785 if ( qpn_offset < 0 ) {
786 DBGC ( arbel, "Arbel %p out of queue pairs\n",
790 qp->qpn = ( ( random() & ARBEL_QPN_RANDOM_MASK ) |
791 ( arbel->qpn_base + qpn_offset ) );
794 DBGC ( arbel, "Arbel %p unsupported QP type %d\n",
801 * Free queue pair number
803 * @v ibdev Infiniband device
806 static void arbel_free_qpn ( struct ib_device *ibdev,
807 struct ib_queue_pair *qp ) {
808 struct arbel *arbel = ib_get_drvdata ( ibdev );
811 qpn_offset = ( ( qp->qpn & ~ARBEL_QPN_RANDOM_MASK ) - arbel->qpn_base );
812 if ( qpn_offset >= 0 )
813 arbel_bitmask_free ( arbel->qp_inuse, qpn_offset );
817 * Calculate transmission rate
819 * @v av Address vector
820 * @ret arbel_rate Arbel rate
822 static unsigned int arbel_rate ( struct ib_address_vector *av ) {
823 return ( ( ( av->rate >= IB_RATE_2_5 ) && ( av->rate <= IB_RATE_120 ) )
824 ? ( av->rate + 5 ) : 0 );
827 /** Queue pair transport service type map */
828 static uint8_t arbel_qp_st[] = {
829 [IB_QPT_SMI] = ARBEL_ST_MLX,
830 [IB_QPT_GSI] = ARBEL_ST_MLX,
831 [IB_QPT_UD] = ARBEL_ST_UD,
832 [IB_QPT_RC] = ARBEL_ST_RC,
836 * Dump queue pair context (for debugging only)
838 * @v arbel Arbel device
840 * @ret rc Return status code
842 static __attribute__ (( unused )) int
843 arbel_dump_qpctx ( struct arbel *arbel, struct ib_queue_pair *qp ) {
844 struct arbelprm_qp_ee_state_transitions qpctx;
847 memset ( &qpctx, 0, sizeof ( qpctx ) );
848 if ( ( rc = arbel_cmd_query_qpee ( arbel, qp->qpn, &qpctx ) ) != 0 ) {
849 DBGC ( arbel, "Arbel %p QPN %#lx QUERY_QPEE failed: %s\n",
850 arbel, qp->qpn, strerror ( rc ) );
853 DBGC ( arbel, "Arbel %p QPN %#lx context:\n", arbel, qp->qpn );
854 DBGC_HDA ( arbel, 0, &qpctx.u.dwords[2], ( sizeof ( qpctx ) - 8 ) );
860 * Create send work queue
862 * @v arbel_send_wq Send work queue
863 * @v num_wqes Number of work queue entries
864 * @ret rc Return status code
866 static int arbel_create_send_wq ( struct arbel_send_work_queue *arbel_send_wq,
867 unsigned int num_wqes ) {
868 union arbel_send_wqe *wqe;
869 union arbel_send_wqe *next_wqe;
870 unsigned int wqe_idx_mask;
873 /* Allocate work queue */
874 arbel_send_wq->wqe_size = ( num_wqes *
875 sizeof ( arbel_send_wq->wqe[0] ) );
876 arbel_send_wq->wqe = malloc_dma ( arbel_send_wq->wqe_size,
877 sizeof ( arbel_send_wq->wqe[0] ) );
878 if ( ! arbel_send_wq->wqe )
880 memset ( arbel_send_wq->wqe, 0, arbel_send_wq->wqe_size );
882 /* Link work queue entries */
883 wqe_idx_mask = ( num_wqes - 1 );
884 for ( i = 0 ; i < num_wqes ; i++ ) {
885 wqe = &arbel_send_wq->wqe[i];
886 next_wqe = &arbel_send_wq->wqe[ ( i + 1 ) & wqe_idx_mask ];
887 MLX_FILL_1 ( &wqe->next, 0, nda_31_6,
888 ( virt_to_bus ( next_wqe ) >> 6 ) );
889 MLX_FILL_1 ( &wqe->next, 1, always1, 1 );
896 * Create receive work queue
898 * @v arbel_recv_wq Receive work queue
899 * @v num_wqes Number of work queue entries
900 * @ret rc Return status code
902 static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
903 unsigned int num_wqes ) {
904 struct arbelprm_recv_wqe *wqe;
905 struct arbelprm_recv_wqe *next_wqe;
906 unsigned int wqe_idx_mask;
911 /* Allocate work queue */
912 arbel_recv_wq->wqe_size = ( num_wqes *
913 sizeof ( arbel_recv_wq->wqe[0] ) );
914 arbel_recv_wq->wqe = malloc_dma ( arbel_recv_wq->wqe_size,
915 sizeof ( arbel_recv_wq->wqe[0] ) );
916 if ( ! arbel_recv_wq->wqe )
918 memset ( arbel_recv_wq->wqe, 0, arbel_recv_wq->wqe_size );
920 /* Link work queue entries */
921 wqe_idx_mask = ( num_wqes - 1 );
922 nds = ( ( offsetof ( typeof ( *wqe ), data ) +
923 sizeof ( wqe->data[0] ) ) >> 4 );
924 for ( i = 0 ; i < num_wqes ; i++ ) {
925 wqe = &arbel_recv_wq->wqe[i].recv;
926 next_wqe = &arbel_recv_wq->wqe[( i + 1 ) & wqe_idx_mask].recv;
927 MLX_FILL_1 ( &wqe->next, 0, nda_31_6,
928 ( virt_to_bus ( next_wqe ) >> 6 ) );
929 MLX_FILL_1 ( &wqe->next, 1, nds, nds );
930 for ( j = 0 ; ( ( ( void * ) &wqe->data[j] ) <
931 ( ( void * ) ( wqe + 1 ) ) ) ; j++ ) {
932 MLX_FILL_1 ( &wqe->data[j], 1,
933 l_key, ARBEL_INVALID_LKEY );
943 * @v ibdev Infiniband device
945 * @ret rc Return status code
947 static int arbel_create_qp ( struct ib_device *ibdev,
948 struct ib_queue_pair *qp ) {
949 struct arbel *arbel = ib_get_drvdata ( ibdev );
950 struct arbel_queue_pair *arbel_qp;
951 struct arbelprm_qp_ee_state_transitions qpctx;
952 struct arbelprm_qp_db_record *send_db_rec;
953 struct arbelprm_qp_db_record *recv_db_rec;
954 physaddr_t send_wqe_base_adr;
955 physaddr_t recv_wqe_base_adr;
956 physaddr_t wqe_base_adr;
959 /* Warn about dysfunctional code
961 * Arbel seems to crash the system as soon as the first send
962 * WQE completes on an RC queue pair. (NOPs complete
963 * successfully, so this is a problem specific to the work
964 * queue rather than the completion queue.) The cause of this
965 * problem has remained unknown for over a year. Patches to
966 * fix this are welcome.
968 if ( qp->type == IB_QPT_RC )
969 DBG ( "*** WARNING: Arbel RC support is non-functional ***\n" );
971 /* Calculate queue pair number */
972 if ( ( rc = arbel_alloc_qpn ( ibdev, qp ) ) != 0 )
975 /* Allocate control structures */
976 arbel_qp = zalloc ( sizeof ( *arbel_qp ) );
981 arbel_qp->send.doorbell_idx = arbel_send_doorbell_idx ( arbel, qp );
982 arbel_qp->recv.doorbell_idx = arbel_recv_doorbell_idx ( arbel, qp );
984 /* Create send and receive work queues */
985 if ( ( rc = arbel_create_send_wq ( &arbel_qp->send,
986 qp->send.num_wqes ) ) != 0 )
987 goto err_create_send_wq;
988 if ( ( rc = arbel_create_recv_wq ( &arbel_qp->recv,
989 qp->recv.num_wqes ) ) != 0 )
990 goto err_create_recv_wq;
992 /* Send and receive work queue entries must be within the same 4GB */
993 send_wqe_base_adr = virt_to_bus ( arbel_qp->send.wqe );
994 recv_wqe_base_adr = virt_to_bus ( arbel_qp->recv.wqe );
995 if ( ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) &&
996 ( ( ( ( uint64_t ) send_wqe_base_adr ) >> 32 ) !=
997 ( ( ( uint64_t ) recv_wqe_base_adr ) >> 32 ) ) ) {
998 DBGC ( arbel, "Arbel %p QPN %#lx cannot support send %08lx "
999 "recv %08lx\n", arbel, qp->qpn,
1000 send_wqe_base_adr, recv_wqe_base_adr );
1002 goto err_unsupported_address_split;
1004 wqe_base_adr = send_wqe_base_adr;
1006 /* Initialise doorbell records */
1007 send_db_rec = &arbel->db_rec[arbel_qp->send.doorbell_idx].qp;
1008 MLX_FILL_1 ( send_db_rec, 0, counter, 0 );
1009 MLX_FILL_2 ( send_db_rec, 1,
1010 res, ARBEL_UAR_RES_SQ,
1011 qp_number, qp->qpn );
1012 recv_db_rec = &arbel->db_rec[arbel_qp->recv.doorbell_idx].qp;
1013 MLX_FILL_1 ( recv_db_rec, 0, counter, 0 );
1014 MLX_FILL_2 ( recv_db_rec, 1,
1015 res, ARBEL_UAR_RES_RQ,
1016 qp_number, qp->qpn );
1018 /* Transition queue to INIT state */
1019 memset ( &qpctx, 0, sizeof ( qpctx ) );
1020 MLX_FILL_3 ( &qpctx, 2,
1022 qpc_eec_data.pm_state, ARBEL_PM_STATE_MIGRATED,
1023 qpc_eec_data.st, arbel_qp_st[qp->type] );
1024 MLX_FILL_4 ( &qpctx, 4,
1025 qpc_eec_data.log_rq_size, fls ( qp->recv.num_wqes - 1 ),
1026 qpc_eec_data.log_rq_stride,
1027 ( fls ( sizeof ( arbel_qp->recv.wqe[0] ) - 1 ) - 4 ),
1028 qpc_eec_data.log_sq_size, fls ( qp->send.num_wqes - 1 ),
1029 qpc_eec_data.log_sq_stride,
1030 ( fls ( sizeof ( arbel_qp->send.wqe[0] ) - 1 ) - 4 ) );
1031 MLX_FILL_1 ( &qpctx, 5,
1032 qpc_eec_data.usr_page, arbel->limits.reserved_uars );
1033 MLX_FILL_1 ( &qpctx, 10, qpc_eec_data.primary_address_path.port_number,
1035 MLX_FILL_1 ( &qpctx, 27, qpc_eec_data.pd, ARBEL_GLOBAL_PD );
1036 MLX_FILL_H ( &qpctx, 28, qpc_eec_data.wqe_base_adr_h, wqe_base_adr );
1037 MLX_FILL_1 ( &qpctx, 29, qpc_eec_data.wqe_lkey, arbel->lkey );
1038 MLX_FILL_1 ( &qpctx, 30, qpc_eec_data.ssc, 1 );
1039 MLX_FILL_1 ( &qpctx, 33, qpc_eec_data.cqn_snd, qp->send.cq->cqn );
1040 MLX_FILL_1 ( &qpctx, 34, qpc_eec_data.snd_wqe_base_adr_l,
1041 ( send_wqe_base_adr >> 6 ) );
1042 MLX_FILL_1 ( &qpctx, 35, qpc_eec_data.snd_db_record_index,
1043 arbel_qp->send.doorbell_idx );
1044 MLX_FILL_4 ( &qpctx, 38,
1045 qpc_eec_data.rre, 1,
1046 qpc_eec_data.rwe, 1,
1047 qpc_eec_data.rae, 1,
1048 qpc_eec_data.rsc, 1 );
1049 MLX_FILL_1 ( &qpctx, 41, qpc_eec_data.cqn_rcv, qp->recv.cq->cqn );
1050 MLX_FILL_1 ( &qpctx, 42, qpc_eec_data.rcv_wqe_base_adr_l,
1051 ( recv_wqe_base_adr >> 6 ) );
1052 MLX_FILL_1 ( &qpctx, 43, qpc_eec_data.rcv_db_record_index,
1053 arbel_qp->recv.doorbell_idx );
1054 if ( ( rc = arbel_cmd_rst2init_qpee ( arbel, qp->qpn, &qpctx )) != 0 ){
1055 DBGC ( arbel, "Arbel %p QPN %#lx RST2INIT_QPEE failed: %s\n",
1056 arbel, qp->qpn, strerror ( rc ) );
1057 goto err_rst2init_qpee;
1059 arbel_qp->state = ARBEL_QP_ST_INIT;
1061 DBGC ( arbel, "Arbel %p QPN %#lx send ring [%08lx,%08lx), doorbell "
1062 "%08lx\n", arbel, qp->qpn, virt_to_phys ( arbel_qp->send.wqe ),
1063 ( virt_to_phys ( arbel_qp->send.wqe ) +
1064 arbel_qp->send.wqe_size ),
1065 virt_to_phys ( send_db_rec ) );
1066 DBGC ( arbel, "Arbel %p QPN %#lx receive ring [%08lx,%08lx), doorbell "
1067 "%08lx\n", arbel, qp->qpn, virt_to_phys ( arbel_qp->recv.wqe ),
1068 ( virt_to_phys ( arbel_qp->recv.wqe ) +
1069 arbel_qp->recv.wqe_size ),
1070 virt_to_phys ( recv_db_rec ) );
1071 DBGC ( arbel, "Arbel %p QPN %#lx send CQN %#lx receive CQN %#lx\n",
1072 arbel, qp->qpn, qp->send.cq->cqn, qp->recv.cq->cqn );
1073 ib_qp_set_drvdata ( qp, arbel_qp );
1076 arbel_cmd_2rst_qpee ( arbel, qp->qpn );
1078 MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1079 MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1080 err_unsupported_address_split:
1081 free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
1083 free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
1087 arbel_free_qpn ( ibdev, qp );
1095 * @v ibdev Infiniband device
1097 * @ret rc Return status code
1099 static int arbel_modify_qp ( struct ib_device *ibdev,
1100 struct ib_queue_pair *qp ) {
1101 struct arbel *arbel = ib_get_drvdata ( ibdev );
1102 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1103 struct arbelprm_qp_ee_state_transitions qpctx;
1106 /* Transition queue to RTR state, if applicable */
1107 if ( arbel_qp->state < ARBEL_QP_ST_RTR ) {
1108 memset ( &qpctx, 0, sizeof ( qpctx ) );
1109 MLX_FILL_2 ( &qpctx, 4,
1110 qpc_eec_data.mtu, ARBEL_MTU_2048,
1111 qpc_eec_data.msg_max, 31 );
1112 MLX_FILL_1 ( &qpctx, 7,
1113 qpc_eec_data.remote_qpn_een, qp->av.qpn );
1114 MLX_FILL_2 ( &qpctx, 11,
1115 qpc_eec_data.primary_address_path.rnr_retry,
1117 qpc_eec_data.primary_address_path.rlid,
1119 MLX_FILL_2 ( &qpctx, 12,
1120 qpc_eec_data.primary_address_path.ack_timeout,
1121 14 /* 4.096us * 2^(14) = 67ms */,
1122 qpc_eec_data.primary_address_path.max_stat_rate,
1123 arbel_rate ( &qp->av ) );
1124 memcpy ( &qpctx.u.dwords[14], &qp->av.gid,
1125 sizeof ( qp->av.gid ) );
1126 MLX_FILL_1 ( &qpctx, 30,
1127 qpc_eec_data.retry_count, ARBEL_RETRY_MAX );
1128 MLX_FILL_1 ( &qpctx, 39,
1129 qpc_eec_data.next_rcv_psn, qp->recv.psn );
1130 MLX_FILL_1 ( &qpctx, 40,
1131 qpc_eec_data.ra_buff_indx,
1132 ( arbel->limits.reserved_rdbs +
1133 ( ( qp->qpn & ~ARBEL_QPN_RANDOM_MASK ) -
1134 arbel->special_qpn_base ) ) );
1135 if ( ( rc = arbel_cmd_init2rtr_qpee ( arbel, qp->qpn,
1137 DBGC ( arbel, "Arbel %p QPN %#lx INIT2RTR_QPEE failed:"
1138 " %s\n", arbel, qp->qpn, strerror ( rc ) );
1141 arbel_qp->state = ARBEL_QP_ST_RTR;
1144 /* Transition queue to RTS state, if applicable */
1145 if ( arbel_qp->state < ARBEL_QP_ST_RTS ) {
1146 memset ( &qpctx, 0, sizeof ( qpctx ) );
1147 MLX_FILL_1 ( &qpctx, 11,
1148 qpc_eec_data.primary_address_path.rnr_retry,
1150 MLX_FILL_1 ( &qpctx, 12,
1151 qpc_eec_data.primary_address_path.ack_timeout,
1152 14 /* 4.096us * 2^(14) = 67ms */ );
1153 MLX_FILL_2 ( &qpctx, 30,
1154 qpc_eec_data.retry_count, ARBEL_RETRY_MAX,
1155 qpc_eec_data.sic, 1 );
1156 MLX_FILL_1 ( &qpctx, 32,
1157 qpc_eec_data.next_send_psn, qp->send.psn );
1158 if ( ( rc = arbel_cmd_rtr2rts_qpee ( arbel, qp->qpn,
1160 DBGC ( arbel, "Arbel %p QPN %#lx RTR2RTS_QPEE failed: "
1161 "%s\n", arbel, qp->qpn, strerror ( rc ) );
1164 arbel_qp->state = ARBEL_QP_ST_RTS;
1167 /* Update parameters in RTS state */
1168 memset ( &qpctx, 0, sizeof ( qpctx ) );
1169 MLX_FILL_1 ( &qpctx, 0, opt_param_mask, ARBEL_QPEE_OPT_PARAM_QKEY );
1170 MLX_FILL_1 ( &qpctx, 44, qpc_eec_data.q_key, qp->qkey );
1171 if ( ( rc = arbel_cmd_rts2rts_qpee ( arbel, qp->qpn, &qpctx ) ) != 0 ){
1172 DBGC ( arbel, "Arbel %p QPN %#lx RTS2RTS_QPEE failed: %s\n",
1173 arbel, qp->qpn, strerror ( rc ) );
1181 * Destroy queue pair
1183 * @v ibdev Infiniband device
1186 static void arbel_destroy_qp ( struct ib_device *ibdev,
1187 struct ib_queue_pair *qp ) {
1188 struct arbel *arbel = ib_get_drvdata ( ibdev );
1189 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1190 struct arbelprm_qp_db_record *send_db_rec;
1191 struct arbelprm_qp_db_record *recv_db_rec;
1194 /* Take ownership back from hardware */
1195 if ( ( rc = arbel_cmd_2rst_qpee ( arbel, qp->qpn ) ) != 0 ) {
1196 DBGC ( arbel, "Arbel %p QPN %#lx FATAL 2RST_QPEE failed: "
1197 "%s\n", arbel, qp->qpn, strerror ( rc ) );
1198 /* Leak memory and return; at least we avoid corruption */
1202 /* Clear doorbell records */
1203 send_db_rec = &arbel->db_rec[arbel_qp->send.doorbell_idx].qp;
1204 recv_db_rec = &arbel->db_rec[arbel_qp->recv.doorbell_idx].qp;
1205 MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1206 MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
1209 free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
1210 free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
1213 /* Mark queue number as free */
1214 arbel_free_qpn ( ibdev, qp );
1216 ib_qp_set_drvdata ( qp, NULL );
1219 /***************************************************************************
1221 * Work request operations
1223 ***************************************************************************
1227 * Ring doorbell register in UAR
1229 * @v arbel Arbel device
1230 * @v db_reg Doorbell register structure
1231 * @v offset Address of doorbell
1233 static void arbel_ring_doorbell ( struct arbel *arbel,
1234 union arbelprm_doorbell_register *db_reg,
1235 unsigned int offset ) {
1237 DBGC2 ( arbel, "Arbel %p ringing doorbell %08x:%08x at %lx\n",
1238 arbel, ntohl ( db_reg->dword[0] ), ntohl ( db_reg->dword[1] ),
1239 virt_to_phys ( arbel->uar + offset ) );
1242 writel ( db_reg->dword[0], ( arbel->uar + offset + 0 ) );
1244 writel ( db_reg->dword[1], ( arbel->uar + offset + 4 ) );
1247 /** GID used for GID-less send work queue entries */
1248 static const union ib_gid arbel_no_gid = {
1249 .bytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0 },
1253 * Construct UD send work queue entry
1255 * @v ibdev Infiniband device
1257 * @v dest Destination address vector
1258 * @v iobuf I/O buffer
1259 * @v wqe Send work queue entry
1260 * @ret nds Work queue entry size
1262 static size_t arbel_fill_ud_send_wqe ( struct ib_device *ibdev,
1263 struct ib_queue_pair *qp __unused,
1264 struct ib_address_vector *dest,
1265 struct io_buffer *iobuf,
1266 union arbel_send_wqe *wqe ) {
1267 struct arbel *arbel = ib_get_drvdata ( ibdev );
1268 const union ib_gid *gid;
1270 /* Construct this work queue entry */
1271 MLX_FILL_1 ( &wqe->ud.ctrl, 0, always1, 1 );
1272 MLX_FILL_2 ( &wqe->ud.ud, 0,
1273 ud_address_vector.pd, ARBEL_GLOBAL_PD,
1274 ud_address_vector.port_number, ibdev->port );
1275 MLX_FILL_2 ( &wqe->ud.ud, 1,
1276 ud_address_vector.rlid, dest->lid,
1277 ud_address_vector.g, dest->gid_present );
1278 MLX_FILL_2 ( &wqe->ud.ud, 2,
1279 ud_address_vector.max_stat_rate, arbel_rate ( dest ),
1280 ud_address_vector.msg, 3 );
1281 MLX_FILL_1 ( &wqe->ud.ud, 3, ud_address_vector.sl, dest->sl );
1282 gid = ( dest->gid_present ? &dest->gid : &arbel_no_gid );
1283 memcpy ( &wqe->ud.ud.u.dwords[4], gid, sizeof ( *gid ) );
1284 MLX_FILL_1 ( &wqe->ud.ud, 8, destination_qp, dest->qpn );
1285 MLX_FILL_1 ( &wqe->ud.ud, 9, q_key, dest->qkey );
1286 MLX_FILL_1 ( &wqe->ud.data[0], 0, byte_count, iob_len ( iobuf ) );
1287 MLX_FILL_1 ( &wqe->ud.data[0], 1, l_key, arbel->lkey );
1288 MLX_FILL_H ( &wqe->ud.data[0], 2,
1289 local_address_h, virt_to_bus ( iobuf->data ) );
1290 MLX_FILL_1 ( &wqe->ud.data[0], 3,
1291 local_address_l, virt_to_bus ( iobuf->data ) );
1293 return ( offsetof ( typeof ( wqe->ud ), data[1] ) >> 4 );
1297 * Construct MLX send work queue entry
1299 * @v ibdev Infiniband device
1301 * @v dest Destination address vector
1302 * @v iobuf I/O buffer
1303 * @v wqe Send work queue entry
1304 * @ret nds Work queue entry size
1306 static size_t arbel_fill_mlx_send_wqe ( struct ib_device *ibdev,
1307 struct ib_queue_pair *qp,
1308 struct ib_address_vector *dest,
1309 struct io_buffer *iobuf,
1310 union arbel_send_wqe *wqe ) {
1311 struct arbel *arbel = ib_get_drvdata ( ibdev );
1312 struct io_buffer headers;
1314 /* Construct IB headers */
1315 iob_populate ( &headers, &wqe->mlx.headers, 0,
1316 sizeof ( wqe->mlx.headers ) );
1317 iob_reserve ( &headers, sizeof ( wqe->mlx.headers ) );
1318 ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), dest );
1320 /* Construct this work queue entry */
1321 MLX_FILL_5 ( &wqe->mlx.ctrl, 0,
1322 c, 1 /* generate completion */,
1323 icrc, 0 /* generate ICRC */,
1324 max_statrate, arbel_rate ( dest ),
1326 v15, ( ( qp->ext_qpn == IB_QPN_SMI ) ? 1 : 0 ) );
1327 MLX_FILL_1 ( &wqe->mlx.ctrl, 1, rlid, dest->lid );
1328 MLX_FILL_1 ( &wqe->mlx.data[0], 0,
1329 byte_count, iob_len ( &headers ) );
1330 MLX_FILL_1 ( &wqe->mlx.data[0], 1, l_key, arbel->lkey );
1331 MLX_FILL_H ( &wqe->mlx.data[0], 2,
1332 local_address_h, virt_to_bus ( headers.data ) );
1333 MLX_FILL_1 ( &wqe->mlx.data[0], 3,
1334 local_address_l, virt_to_bus ( headers.data ) );
1335 MLX_FILL_1 ( &wqe->mlx.data[1], 0,
1336 byte_count, ( iob_len ( iobuf ) + 4 /* ICRC */ ) );
1337 MLX_FILL_1 ( &wqe->mlx.data[1], 1, l_key, arbel->lkey );
1338 MLX_FILL_H ( &wqe->mlx.data[1], 2,
1339 local_address_h, virt_to_bus ( iobuf->data ) );
1340 MLX_FILL_1 ( &wqe->mlx.data[1], 3,
1341 local_address_l, virt_to_bus ( iobuf->data ) );
1343 return ( offsetof ( typeof ( wqe->mlx ), data[2] ) >> 4 );
1347 * Construct RC send work queue entry
1349 * @v ibdev Infiniband device
1351 * @v dest Destination address vector
1352 * @v iobuf I/O buffer
1353 * @v wqe Send work queue entry
1354 * @ret nds Work queue entry size
1356 static size_t arbel_fill_rc_send_wqe ( struct ib_device *ibdev,
1357 struct ib_queue_pair *qp __unused,
1358 struct ib_address_vector *dest __unused,
1359 struct io_buffer *iobuf,
1360 union arbel_send_wqe *wqe ) {
1361 struct arbel *arbel = ib_get_drvdata ( ibdev );
1363 /* Construct this work queue entry */
1364 MLX_FILL_1 ( &wqe->rc.ctrl, 0, always1, 1 );
1365 MLX_FILL_1 ( &wqe->rc.data[0], 0, byte_count, iob_len ( iobuf ) );
1366 MLX_FILL_1 ( &wqe->rc.data[0], 1, l_key, arbel->lkey );
1367 MLX_FILL_H ( &wqe->rc.data[0], 2,
1368 local_address_h, virt_to_bus ( iobuf->data ) );
1369 MLX_FILL_1 ( &wqe->rc.data[0], 3,
1370 local_address_l, virt_to_bus ( iobuf->data ) );
1372 return ( offsetof ( typeof ( wqe->rc ), data[1] ) >> 4 );
1375 /** Work queue entry constructors */
1377 ( * arbel_fill_send_wqe[] ) ( struct ib_device *ibdev,
1378 struct ib_queue_pair *qp,
1379 struct ib_address_vector *dest,
1380 struct io_buffer *iobuf,
1381 union arbel_send_wqe *wqe ) = {
1382 [IB_QPT_SMI] = arbel_fill_mlx_send_wqe,
1383 [IB_QPT_GSI] = arbel_fill_mlx_send_wqe,
1384 [IB_QPT_UD] = arbel_fill_ud_send_wqe,
1385 [IB_QPT_RC] = arbel_fill_rc_send_wqe,
1389 * Post send work queue entry
1391 * @v ibdev Infiniband device
1393 * @v dest Destination address vector
1394 * @v iobuf I/O buffer
1395 * @ret rc Return status code
1397 static int arbel_post_send ( struct ib_device *ibdev,
1398 struct ib_queue_pair *qp,
1399 struct ib_address_vector *dest,
1400 struct io_buffer *iobuf ) {
1401 struct arbel *arbel = ib_get_drvdata ( ibdev );
1402 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1403 struct ib_work_queue *wq = &qp->send;
1404 struct arbel_send_work_queue *arbel_send_wq = &arbel_qp->send;
1405 union arbel_send_wqe *prev_wqe;
1406 union arbel_send_wqe *wqe;
1407 struct arbelprm_qp_db_record *qp_db_rec;
1408 union arbelprm_doorbell_register db_reg;
1409 unsigned long wqe_idx_mask;
1412 /* Allocate work queue entry */
1413 wqe_idx_mask = ( wq->num_wqes - 1 );
1414 if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
1415 DBGC ( arbel, "Arbel %p QPN %#lx send queue full",
1419 wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
1420 prev_wqe = &arbel_send_wq->wqe[(wq->next_idx - 1) & wqe_idx_mask];
1421 wqe = &arbel_send_wq->wqe[wq->next_idx & wqe_idx_mask];
1423 /* Construct work queue entry */
1424 memset ( ( ( ( void * ) wqe ) + sizeof ( wqe->next ) ), 0,
1425 ( sizeof ( *wqe ) - sizeof ( wqe->next ) ) );
1426 assert ( qp->type < ( sizeof ( arbel_fill_send_wqe ) /
1427 sizeof ( arbel_fill_send_wqe[0] ) ) );
1428 assert ( arbel_fill_send_wqe[qp->type] != NULL );
1429 nds = arbel_fill_send_wqe[qp->type] ( ibdev, qp, dest, iobuf, wqe );
1430 DBGCP ( arbel, "Arbel %p QPN %#lx posting send WQE %#lx:\n",
1431 arbel, qp->qpn, ( wq->next_idx & wqe_idx_mask ) );
1432 DBGCP_HDA ( arbel, virt_to_phys ( wqe ), wqe, sizeof ( *wqe ) );
1434 /* Update previous work queue entry's "next" field */
1435 MLX_SET ( &prev_wqe->next, nopcode, ARBEL_OPCODE_SEND );
1436 MLX_FILL_3 ( &prev_wqe->next, 1,
1441 /* Update doorbell record */
1443 qp_db_rec = &arbel->db_rec[arbel_send_wq->doorbell_idx].qp;
1444 MLX_FILL_1 ( qp_db_rec, 0,
1445 counter, ( ( wq->next_idx + 1 ) & 0xffff ) );
1447 /* Ring doorbell register */
1448 MLX_FILL_4 ( &db_reg.send, 0,
1449 nopcode, ARBEL_OPCODE_SEND,
1451 wqe_counter, ( wq->next_idx & 0xffff ),
1453 MLX_FILL_2 ( &db_reg.send, 1,
1456 arbel_ring_doorbell ( arbel, &db_reg, ARBEL_DB_POST_SND_OFFSET );
1458 /* Update work queue's index */
1465 * Post receive work queue entry
1467 * @v ibdev Infiniband device
1469 * @v iobuf I/O buffer
1470 * @ret rc Return status code
1472 static int arbel_post_recv ( struct ib_device *ibdev,
1473 struct ib_queue_pair *qp,
1474 struct io_buffer *iobuf ) {
1475 struct arbel *arbel = ib_get_drvdata ( ibdev );
1476 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1477 struct ib_work_queue *wq = &qp->recv;
1478 struct arbel_recv_work_queue *arbel_recv_wq = &arbel_qp->recv;
1479 struct arbelprm_recv_wqe *wqe;
1480 union arbelprm_doorbell_record *db_rec;
1481 unsigned int wqe_idx_mask;
1483 /* Allocate work queue entry */
1484 wqe_idx_mask = ( wq->num_wqes - 1 );
1485 if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
1486 DBGC ( arbel, "Arbel %p QPN %#lx receive queue full\n",
1490 wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
1491 wqe = &arbel_recv_wq->wqe[wq->next_idx & wqe_idx_mask].recv;
1493 /* Construct work queue entry */
1494 MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_tailroom ( iobuf ) );
1495 MLX_FILL_1 ( &wqe->data[0], 1, l_key, arbel->lkey );
1496 MLX_FILL_H ( &wqe->data[0], 2,
1497 local_address_h, virt_to_bus ( iobuf->data ) );
1498 MLX_FILL_1 ( &wqe->data[0], 3,
1499 local_address_l, virt_to_bus ( iobuf->data ) );
1501 /* Update doorbell record */
1503 db_rec = &arbel->db_rec[arbel_recv_wq->doorbell_idx];
1504 MLX_FILL_1 ( &db_rec->qp, 0,
1505 counter, ( ( wq->next_idx + 1 ) & 0xffff ) );
1507 /* Update work queue's index */
1516 * @v ibdev Infiniband device
1517 * @v cq Completion queue
1518 * @v cqe Hardware completion queue entry
1519 * @ret rc Return status code
1521 static int arbel_complete ( struct ib_device *ibdev,
1522 struct ib_completion_queue *cq,
1523 union arbelprm_completion_entry *cqe ) {
1524 struct arbel *arbel = ib_get_drvdata ( ibdev );
1525 struct ib_work_queue *wq;
1526 struct ib_queue_pair *qp;
1527 struct arbel_queue_pair *arbel_qp;
1528 struct arbel_send_work_queue *arbel_send_wq;
1529 struct arbel_recv_work_queue *arbel_recv_wq;
1530 struct arbelprm_recv_wqe *recv_wqe;
1531 struct io_buffer *iobuf;
1532 struct ib_address_vector recv_dest;
1533 struct ib_address_vector recv_source;
1534 struct ib_global_route_header *grh;
1535 struct ib_address_vector *source;
1536 unsigned int opcode;
1539 unsigned long wqe_adr;
1540 unsigned long wqe_idx;
1544 /* Parse completion */
1545 qpn = MLX_GET ( &cqe->normal, my_qpn );
1546 is_send = MLX_GET ( &cqe->normal, s );
1547 wqe_adr = ( MLX_GET ( &cqe->normal, wqe_adr ) << 6 );
1548 opcode = MLX_GET ( &cqe->normal, opcode );
1549 if ( opcode >= ARBEL_OPCODE_RECV_ERROR ) {
1550 /* "s" field is not valid for error opcodes */
1551 is_send = ( opcode == ARBEL_OPCODE_SEND_ERROR );
1552 DBGC ( arbel, "Arbel %p CQN %#lx %s QPN %#lx syndrome %#x "
1553 "vendor %#x\n", arbel, cq->cqn,
1554 ( is_send ? "send" : "recv" ), qpn,
1555 MLX_GET ( &cqe->error, syndrome ),
1556 MLX_GET ( &cqe->error, vendor_code ) );
1557 DBGC_HDA ( arbel, virt_to_phys ( cqe ), cqe, sizeof ( *cqe ) );
1559 /* Don't return immediately; propagate error to completer */
1562 /* Identify work queue */
1563 wq = ib_find_wq ( cq, qpn, is_send );
1565 DBGC ( arbel, "Arbel %p CQN %#lx unknown %s QPN %#lx\n",
1566 arbel, cq->cqn, ( is_send ? "send" : "recv" ), qpn );
1570 arbel_qp = ib_qp_get_drvdata ( qp );
1571 arbel_send_wq = &arbel_qp->send;
1572 arbel_recv_wq = &arbel_qp->recv;
1574 /* Identify work queue entry index */
1576 wqe_idx = ( ( wqe_adr - virt_to_bus ( arbel_send_wq->wqe ) ) /
1577 sizeof ( arbel_send_wq->wqe[0] ) );
1578 assert ( wqe_idx < qp->send.num_wqes );
1580 wqe_idx = ( ( wqe_adr - virt_to_bus ( arbel_recv_wq->wqe ) ) /
1581 sizeof ( arbel_recv_wq->wqe[0] ) );
1582 assert ( wqe_idx < qp->recv.num_wqes );
1585 DBGCP ( arbel, "Arbel %p CQN %#lx QPN %#lx %s WQE %#lx completed:\n",
1586 arbel, cq->cqn, qp->qpn, ( is_send ? "send" : "recv" ),
1588 DBGCP_HDA ( arbel, virt_to_phys ( cqe ), cqe, sizeof ( *cqe ) );
1590 /* Identify I/O buffer */
1591 iobuf = wq->iobufs[wqe_idx];
1593 DBGC ( arbel, "Arbel %p CQN %#lx QPN %#lx empty %s WQE %#lx\n",
1594 arbel, cq->cqn, qp->qpn, ( is_send ? "send" : "recv" ),
1598 wq->iobufs[wqe_idx] = NULL;
1601 /* Hand off to completion handler */
1602 ib_complete_send ( ibdev, qp, iobuf, rc );
1604 /* Set received length */
1605 len = MLX_GET ( &cqe->normal, byte_cnt );
1606 recv_wqe = &arbel_recv_wq->wqe[wqe_idx].recv;
1607 assert ( MLX_GET ( &recv_wqe->data[0], local_address_l ) ==
1608 virt_to_bus ( iobuf->data ) );
1609 assert ( MLX_GET ( &recv_wqe->data[0], byte_count ) ==
1610 iob_tailroom ( iobuf ) );
1611 MLX_FILL_1 ( &recv_wqe->data[0], 0, byte_count, 0 );
1612 MLX_FILL_1 ( &recv_wqe->data[0], 1,
1613 l_key, ARBEL_INVALID_LKEY );
1614 assert ( len <= iob_tailroom ( iobuf ) );
1615 iob_put ( iobuf, len );
1616 memset ( &recv_dest, 0, sizeof ( recv_dest ) );
1617 recv_dest.qpn = qpn;
1618 switch ( qp->type ) {
1622 assert ( iob_len ( iobuf ) >= sizeof ( *grh ) );
1624 iob_pull ( iobuf, sizeof ( *grh ) );
1625 /* Construct address vector */
1626 source = &recv_source;
1627 memset ( source, 0, sizeof ( *source ) );
1628 source->qpn = MLX_GET ( &cqe->normal, rqpn );
1629 source->lid = MLX_GET ( &cqe->normal, rlid );
1630 source->sl = MLX_GET ( &cqe->normal, sl );
1631 recv_dest.gid_present = source->gid_present =
1632 MLX_GET ( &cqe->normal, g );
1633 memcpy ( &recv_dest.gid, &grh->dgid,
1634 sizeof ( recv_dest.gid ) );
1635 memcpy ( &source->gid, &grh->sgid,
1636 sizeof ( source->gid ) );
1645 /* Hand off to completion handler */
1646 ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc );
1653 * Poll completion queue
1655 * @v ibdev Infiniband device
1656 * @v cq Completion queue
1658 static void arbel_poll_cq ( struct ib_device *ibdev,
1659 struct ib_completion_queue *cq ) {
1660 struct arbel *arbel = ib_get_drvdata ( ibdev );
1661 struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
1662 struct arbelprm_cq_ci_db_record *ci_db_rec;
1663 union arbelprm_completion_entry *cqe;
1664 unsigned int cqe_idx_mask;
1668 /* Look for completion entry */
1669 cqe_idx_mask = ( cq->num_cqes - 1 );
1670 cqe = &arbel_cq->cqe[cq->next_idx & cqe_idx_mask];
1671 if ( MLX_GET ( &cqe->normal, owner ) != 0 ) {
1672 /* Entry still owned by hardware; end of poll */
1676 /* Handle completion */
1677 if ( ( rc = arbel_complete ( ibdev, cq, cqe ) ) != 0 ) {
1678 DBGC ( arbel, "Arbel %p CQN %#lx failed to complete: "
1679 "%s\n", arbel, cq->cqn, strerror ( rc ) );
1680 DBGC_HD ( arbel, cqe, sizeof ( *cqe ) );
1683 /* Return ownership to hardware */
1684 MLX_FILL_1 ( &cqe->normal, 7, owner, 1 );
1686 /* Update completion queue's index */
1688 /* Update doorbell record */
1689 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
1690 MLX_FILL_1 ( ci_db_rec, 0,
1691 counter, ( cq->next_idx & 0xffffffffUL ) );
1695 /***************************************************************************
1699 ***************************************************************************
1703 * Create event queue
1705 * @v arbel Arbel device
1706 * @ret rc Return status code
1708 static int arbel_create_eq ( struct arbel *arbel ) {
1709 struct arbel_event_queue *arbel_eq = &arbel->eq;
1710 struct arbelprm_eqc eqctx;
1711 struct arbelprm_event_mask mask;
1715 /* Select event queue number */
1716 arbel_eq->eqn = arbel->limits.reserved_eqs;
1718 /* Calculate doorbell address */
1719 arbel_eq->doorbell = ( arbel->eq_ci_doorbells +
1720 ARBEL_DB_EQ_OFFSET ( arbel_eq->eqn ) );
1722 /* Allocate event queue itself */
1723 arbel_eq->eqe_size =
1724 ( ARBEL_NUM_EQES * sizeof ( arbel_eq->eqe[0] ) );
1725 arbel_eq->eqe = malloc_dma ( arbel_eq->eqe_size,
1726 sizeof ( arbel_eq->eqe[0] ) );
1727 if ( ! arbel_eq->eqe ) {
1731 memset ( arbel_eq->eqe, 0, arbel_eq->eqe_size );
1732 for ( i = 0 ; i < ARBEL_NUM_EQES ; i++ ) {
1733 MLX_FILL_1 ( &arbel_eq->eqe[i].generic, 7, owner, 1 );
1737 /* Hand queue over to hardware */
1738 memset ( &eqctx, 0, sizeof ( eqctx ) );
1739 MLX_FILL_1 ( &eqctx, 0, st, 0xa /* "Fired" */ );
1740 MLX_FILL_H ( &eqctx, 1,
1741 start_address_h, virt_to_phys ( arbel_eq->eqe ) );
1742 MLX_FILL_1 ( &eqctx, 2,
1743 start_address_l, virt_to_phys ( arbel_eq->eqe ) );
1744 MLX_FILL_1 ( &eqctx, 3, log_eq_size, fls ( ARBEL_NUM_EQES - 1 ) );
1745 MLX_FILL_1 ( &eqctx, 6, pd, ARBEL_GLOBAL_PD );
1746 MLX_FILL_1 ( &eqctx, 7, lkey, arbel->lkey );
1747 if ( ( rc = arbel_cmd_sw2hw_eq ( arbel, arbel_eq->eqn,
1749 DBGC ( arbel, "Arbel %p EQN %#lx SW2HW_EQ failed: %s\n",
1750 arbel, arbel_eq->eqn, strerror ( rc ) );
1754 /* Map events to this event queue */
1755 memset ( &mask, 0xff, sizeof ( mask ) );
1756 if ( ( rc = arbel_cmd_map_eq ( arbel,
1757 ( ARBEL_MAP_EQ | arbel_eq->eqn ),
1759 DBGC ( arbel, "Arbel %p EQN %#lx MAP_EQ failed: %s\n",
1760 arbel, arbel_eq->eqn, strerror ( rc ) );
1764 DBGC ( arbel, "Arbel %p EQN %#lx ring [%08lx,%08lx), doorbell %08lx\n",
1765 arbel, arbel_eq->eqn, virt_to_phys ( arbel_eq->eqe ),
1766 ( virt_to_phys ( arbel_eq->eqe ) + arbel_eq->eqe_size ),
1767 virt_to_phys ( arbel_eq->doorbell ) );
1771 arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn, &eqctx );
1773 free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
1775 memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
1780 * Destroy event queue
1782 * @v arbel Arbel device
1784 static void arbel_destroy_eq ( struct arbel *arbel ) {
1785 struct arbel_event_queue *arbel_eq = &arbel->eq;
1786 struct arbelprm_eqc eqctx;
1787 struct arbelprm_event_mask mask;
1790 /* Unmap events from event queue */
1791 memset ( &mask, 0, sizeof ( mask ) );
1792 MLX_FILL_1 ( &mask, 1, port_state_change, 1 );
1793 if ( ( rc = arbel_cmd_map_eq ( arbel,
1794 ( ARBEL_UNMAP_EQ | arbel_eq->eqn ),
1796 DBGC ( arbel, "Arbel %p EQN %#lx FATAL MAP_EQ failed to "
1797 "unmap: %s\n", arbel, arbel_eq->eqn, strerror ( rc ) );
1798 /* Continue; HCA may die but system should survive */
1801 /* Take ownership back from hardware */
1802 if ( ( rc = arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn,
1804 DBGC ( arbel, "Arbel %p EQN %#lx FATAL HW2SW_EQ failed: %s\n",
1805 arbel, arbel_eq->eqn, strerror ( rc ) );
1806 /* Leak memory and return; at least we avoid corruption */
1811 free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
1812 memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
1816 * Handle port state event
1818 * @v arbel Arbel device
1819 * @v eqe Port state change event queue entry
1821 static void arbel_event_port_state_change ( struct arbel *arbel,
1822 union arbelprm_event_entry *eqe){
1826 /* Get port and link status */
1827 port = ( MLX_GET ( &eqe->port_state_change, data.p ) - 1 );
1828 link_up = ( MLX_GET ( &eqe->generic, event_sub_type ) & 0x04 );
1829 DBGC ( arbel, "Arbel %p port %d link %s\n", arbel, ( port + 1 ),
1830 ( link_up ? "up" : "down" ) );
1833 if ( port >= ARBEL_NUM_PORTS ) {
1834 DBGC ( arbel, "Arbel %p port %d does not exist!\n",
1835 arbel, ( port + 1 ) );
1839 /* Update MAD parameters */
1840 ib_smc_update ( arbel->ibdev[port], arbel_mad );
1846 * @v ibdev Infiniband device
1848 static void arbel_poll_eq ( struct ib_device *ibdev ) {
1849 struct arbel *arbel = ib_get_drvdata ( ibdev );
1850 struct arbel_event_queue *arbel_eq = &arbel->eq;
1851 union arbelprm_event_entry *eqe;
1852 union arbelprm_eq_doorbell_register db_reg;
1853 unsigned int eqe_idx_mask;
1854 unsigned int event_type;
1856 /* No event is generated upon reaching INIT, so we must poll
1857 * separately for link state changes while we remain DOWN.
1859 if ( ib_is_open ( ibdev ) &&
1860 ( ibdev->port_state == IB_PORT_STATE_DOWN ) ) {
1861 ib_smc_update ( ibdev, arbel_mad );
1864 /* Poll event queue */
1866 /* Look for event entry */
1867 eqe_idx_mask = ( ARBEL_NUM_EQES - 1 );
1868 eqe = &arbel_eq->eqe[arbel_eq->next_idx & eqe_idx_mask];
1869 if ( MLX_GET ( &eqe->generic, owner ) != 0 ) {
1870 /* Entry still owned by hardware; end of poll */
1873 DBGCP ( arbel, "Arbel %p EQN %#lx event:\n",
1874 arbel, arbel_eq->eqn );
1875 DBGCP_HDA ( arbel, virt_to_phys ( eqe ),
1876 eqe, sizeof ( *eqe ) );
1879 event_type = MLX_GET ( &eqe->generic, event_type );
1880 switch ( event_type ) {
1881 case ARBEL_EV_PORT_STATE_CHANGE:
1882 arbel_event_port_state_change ( arbel, eqe );
1885 DBGC ( arbel, "Arbel %p EQN %#lx unrecognised event "
1887 arbel, arbel_eq->eqn, event_type );
1888 DBGC_HDA ( arbel, virt_to_phys ( eqe ),
1889 eqe, sizeof ( *eqe ) );
1893 /* Return ownership to hardware */
1894 MLX_FILL_1 ( &eqe->generic, 7, owner, 1 );
1897 /* Update event queue's index */
1898 arbel_eq->next_idx++;
1901 MLX_FILL_1 ( &db_reg.ci, 0, ci, arbel_eq->next_idx );
1902 writel ( db_reg.dword[0], arbel_eq->doorbell );
1906 /***************************************************************************
1910 ***************************************************************************
1914 * Map virtual to physical address for firmware usage
1916 * @v arbel Arbel device
1917 * @v map Mapping function
1918 * @v va Virtual address
1919 * @v pa Physical address
1920 * @v len Length of region
1921 * @ret rc Return status code
1923 static int arbel_map_vpm ( struct arbel *arbel,
1924 int ( *map ) ( struct arbel *arbel,
1925 const struct arbelprm_virtual_physical_mapping* ),
1926 uint64_t va, physaddr_t pa, size_t len ) {
1927 struct arbelprm_virtual_physical_mapping mapping;
1936 assert ( ( va & ( ARBEL_PAGE_SIZE - 1 ) ) == 0 );
1937 assert ( ( pa & ( ARBEL_PAGE_SIZE - 1 ) ) == 0 );
1938 assert ( ( len & ( ARBEL_PAGE_SIZE - 1 ) ) == 0 );
1940 /* Calculate starting points */
1942 end = ( start + len );
1943 size = ( 1UL << ( fls ( start ^ end ) - 1 ) );
1944 low = high = ( end & ~( size - 1 ) );
1945 assert ( start < low );
1946 assert ( high <= end );
1948 /* These mappings tend to generate huge volumes of
1949 * uninteresting debug data, which basically makes it
1950 * impossible to use debugging otherwise.
1952 DBG_DISABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
1954 /* Map blocks in descending order of size */
1955 while ( size >= ARBEL_PAGE_SIZE ) {
1957 /* Find the next candidate block */
1958 if ( ( low - size ) >= start ) {
1961 } else if ( ( high + size ) <= end ) {
1968 assert ( ( va & ( size - 1 ) ) == 0 );
1969 assert ( ( pa & ( size - 1 ) ) == 0 );
1971 /* Map this block */
1972 memset ( &mapping, 0, sizeof ( mapping ) );
1973 MLX_FILL_1 ( &mapping, 0, va_h, ( va >> 32 ) );
1974 MLX_FILL_1 ( &mapping, 1, va_l, ( va >> 12 ) );
1975 MLX_FILL_H ( &mapping, 2, pa_h, pa );
1976 MLX_FILL_2 ( &mapping, 3,
1977 log2size, ( ( fls ( size ) - 1 ) - 12 ),
1978 pa_l, ( pa >> 12 ) );
1979 if ( ( rc = map ( arbel, &mapping ) ) != 0 ) {
1980 DBG_ENABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
1981 DBGC ( arbel, "Arbel %p could not map %08llx+%zx to "
1983 arbel, va, size, pa, strerror ( rc ) );
1988 assert ( low == start );
1989 assert ( high == end );
1991 DBG_ENABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
1996 * Start firmware running
1998 * @v arbel Arbel device
1999 * @ret rc Return status code
2001 static int arbel_start_firmware ( struct arbel *arbel ) {
2002 struct arbelprm_query_fw fw;
2003 struct arbelprm_access_lam lam;
2004 unsigned int fw_pages;
2007 uint64_t eq_set_ci_base_addr;
2010 /* Get firmware parameters */
2011 if ( ( rc = arbel_cmd_query_fw ( arbel, &fw ) ) != 0 ) {
2012 DBGC ( arbel, "Arbel %p could not query firmware: %s\n",
2013 arbel, strerror ( rc ) );
2016 DBGC ( arbel, "Arbel %p firmware version %d.%d.%d\n", arbel,
2017 MLX_GET ( &fw, fw_rev_major ), MLX_GET ( &fw, fw_rev_minor ),
2018 MLX_GET ( &fw, fw_rev_subminor ) );
2019 fw_pages = MLX_GET ( &fw, fw_pages );
2020 DBGC ( arbel, "Arbel %p requires %d kB for firmware\n",
2021 arbel, ( fw_pages * 4 ) );
2022 eq_set_ci_base_addr =
2023 ( ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_h ) << 32 ) |
2024 ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_l ) ) );
2025 arbel->eq_ci_doorbells = ioremap ( eq_set_ci_base_addr, 0x200 );
2027 /* Enable locally-attached memory. Ignore failure; there may
2028 * be no attached memory.
2030 arbel_cmd_enable_lam ( arbel, &lam );
2032 /* Allocate firmware pages and map firmware area */
2033 fw_len = ( fw_pages * ARBEL_PAGE_SIZE );
2034 if ( ! arbel->firmware_area ) {
2035 arbel->firmware_len = fw_len;
2036 arbel->firmware_area = umalloc ( arbel->firmware_len );
2037 if ( ! arbel->firmware_area ) {
2042 assert ( arbel->firmware_len == fw_len );
2044 fw_base = user_to_phys ( arbel->firmware_area, 0 );
2045 DBGC ( arbel, "Arbel %p firmware area at [%08lx,%08lx)\n",
2046 arbel, fw_base, ( fw_base + fw_len ) );
2047 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_fa,
2048 0, fw_base, fw_len ) ) != 0 ) {
2049 DBGC ( arbel, "Arbel %p could not map firmware: %s\n",
2050 arbel, strerror ( rc ) );
2054 /* Start firmware */
2055 if ( ( rc = arbel_cmd_run_fw ( arbel ) ) != 0 ) {
2056 DBGC ( arbel, "Arbel %p could not run firmware: %s\n",
2057 arbel, strerror ( rc ) );
2061 DBGC ( arbel, "Arbel %p firmware started\n", arbel );
2065 arbel_cmd_unmap_fa ( arbel );
2073 * Stop firmware running
2075 * @v arbel Arbel device
2077 static void arbel_stop_firmware ( struct arbel *arbel ) {
2080 if ( ( rc = arbel_cmd_unmap_fa ( arbel ) ) != 0 ) {
2081 DBGC ( arbel, "Arbel %p FATAL could not stop firmware: %s\n",
2082 arbel, strerror ( rc ) );
2083 /* Leak memory and return; at least we avoid corruption */
2084 arbel->firmware_area = UNULL;
2089 /***************************************************************************
2091 * Infinihost Context Memory management
2093 ***************************************************************************
2099 * @v arbel Arbel device
2100 * @ret rc Return status code
2102 static int arbel_get_limits ( struct arbel *arbel ) {
2103 struct arbelprm_query_dev_lim dev_lim;
2106 if ( ( rc = arbel_cmd_query_dev_lim ( arbel, &dev_lim ) ) != 0 ) {
2107 DBGC ( arbel, "Arbel %p could not get device limits: %s\n",
2108 arbel, strerror ( rc ) );
2112 arbel->limits.reserved_qps =
2113 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_qps ) );
2114 arbel->limits.qpc_entry_size = MLX_GET ( &dev_lim, qpc_entry_sz );
2115 arbel->limits.eqpc_entry_size = MLX_GET ( &dev_lim, eqpc_entry_sz );
2116 arbel->limits.reserved_srqs =
2117 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_srqs ) );
2118 arbel->limits.srqc_entry_size = MLX_GET ( &dev_lim, srq_entry_sz );
2119 arbel->limits.reserved_ees =
2120 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_ees ) );
2121 arbel->limits.eec_entry_size = MLX_GET ( &dev_lim, eec_entry_sz );
2122 arbel->limits.eeec_entry_size = MLX_GET ( &dev_lim, eeec_entry_sz );
2123 arbel->limits.reserved_cqs =
2124 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_cqs ) );
2125 arbel->limits.cqc_entry_size = MLX_GET ( &dev_lim, cqc_entry_sz );
2126 arbel->limits.reserved_mtts =
2127 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_mtts ) );
2128 arbel->limits.mtt_entry_size = MLX_GET ( &dev_lim, mtt_entry_sz );
2129 arbel->limits.reserved_mrws =
2130 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_mrws ) );
2131 arbel->limits.mpt_entry_size = MLX_GET ( &dev_lim, mpt_entry_sz );
2132 arbel->limits.reserved_rdbs =
2133 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_rdbs ) );
2134 arbel->limits.reserved_eqs = MLX_GET ( &dev_lim, num_rsvd_eqs );
2135 arbel->limits.eqc_entry_size = MLX_GET ( &dev_lim, eqc_entry_sz );
2136 arbel->limits.reserved_uars = MLX_GET ( &dev_lim, num_rsvd_uars );
2137 arbel->limits.uar_scratch_entry_size =
2138 MLX_GET ( &dev_lim, uar_scratch_entry_sz );
2140 DBGC ( arbel, "Arbel %p reserves %d x %#zx QPC, %d x %#zx EQPC, "
2141 "%d x %#zx SRQC\n", arbel,
2142 arbel->limits.reserved_qps, arbel->limits.qpc_entry_size,
2143 arbel->limits.reserved_qps, arbel->limits.eqpc_entry_size,
2144 arbel->limits.reserved_srqs, arbel->limits.srqc_entry_size );
2145 DBGC ( arbel, "Arbel %p reserves %d x %#zx EEC, %d x %#zx EEEC, "
2146 "%d x %#zx CQC\n", arbel,
2147 arbel->limits.reserved_ees, arbel->limits.eec_entry_size,
2148 arbel->limits.reserved_ees, arbel->limits.eeec_entry_size,
2149 arbel->limits.reserved_cqs, arbel->limits.cqc_entry_size );
2150 DBGC ( arbel, "Arbel %p reserves %d x %#zx EQC, %d x %#zx MTT, "
2151 "%d x %#zx MPT\n", arbel,
2152 arbel->limits.reserved_eqs, arbel->limits.eqc_entry_size,
2153 arbel->limits.reserved_mtts, arbel->limits.mtt_entry_size,
2154 arbel->limits.reserved_mrws, arbel->limits.mpt_entry_size );
2155 DBGC ( arbel, "Arbel %p reserves %d x %#zx RDB, %d x %#zx UAR, "
2156 "%d x %#zx UAR scratchpad\n", arbel,
2157 arbel->limits.reserved_rdbs, ARBEL_RDB_ENTRY_SIZE,
2158 arbel->limits.reserved_uars, ARBEL_PAGE_SIZE,
2159 arbel->limits.reserved_uars,
2160 arbel->limits.uar_scratch_entry_size );
2168 * @v icm_offset Current ICM offset
2169 * @v len ICM table length
2170 * @ret icm_offset ICM offset
2172 static size_t icm_align ( size_t icm_offset, size_t len ) {
2174 /* Round up to a multiple of the table size */
2175 assert ( len == ( 1UL << ( fls ( len ) - 1 ) ) );
2176 return ( ( icm_offset + len - 1 ) & ~( len - 1 ) );
2182 * @v arbel Arbel device
2183 * @v init_hca INIT_HCA structure to fill in
2184 * @ret rc Return status code
2186 static int arbel_alloc_icm ( struct arbel *arbel,
2187 struct arbelprm_init_hca *init_hca ) {
2188 struct arbelprm_scalar_parameter icm_size;
2189 struct arbelprm_scalar_parameter icm_aux_size;
2190 struct arbelprm_scalar_parameter unmap_icm;
2191 union arbelprm_doorbell_record *db_rec;
2192 size_t icm_offset = 0;
2193 unsigned int log_num_uars, log_num_qps, log_num_srqs, log_num_ees;
2194 unsigned int log_num_cqs, log_num_mtts, log_num_mpts, log_num_rdbs;
2195 unsigned int log_num_eqs, log_num_mcs;
2196 size_t icm_len, icm_aux_len;
2198 physaddr_t icm_phys;
2201 /* Calculate number of each object type within ICM */
2202 log_num_qps = fls ( arbel->limits.reserved_qps +
2203 ARBEL_RSVD_SPECIAL_QPS + ARBEL_MAX_QPS - 1 );
2204 log_num_srqs = fls ( arbel->limits.reserved_srqs - 1 );
2205 log_num_ees = fls ( arbel->limits.reserved_ees - 1 );
2206 log_num_cqs = fls ( arbel->limits.reserved_cqs + ARBEL_MAX_CQS - 1 );
2207 log_num_eqs = fls ( arbel->limits.reserved_eqs + ARBEL_MAX_EQS - 1 );
2208 log_num_mtts = fls ( arbel->limits.reserved_mtts - 1 );
2209 log_num_mpts = fls ( arbel->limits.reserved_mrws + 1 - 1 );
2210 log_num_rdbs = fls ( arbel->limits.reserved_rdbs +
2211 ARBEL_RSVD_SPECIAL_QPS + ARBEL_MAX_QPS - 1 );
2212 log_num_uars = fls ( arbel->limits.reserved_uars +
2213 1 /* single UAR used */ - 1 );
2214 log_num_mcs = ARBEL_LOG_MULTICAST_HASH_SIZE;
2216 /* Queue pair contexts */
2217 len = ( ( 1 << log_num_qps ) * arbel->limits.qpc_entry_size );
2218 icm_offset = icm_align ( icm_offset, len );
2219 MLX_FILL_2 ( init_hca, 13,
2220 qpc_eec_cqc_eqc_rdb_parameters.qpc_base_addr_l,
2221 ( icm_offset >> 7 ),
2222 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_qp,
2224 DBGC ( arbel, "Arbel %p ICM QPC is %d x %#zx at [%zx,%zx)\n",
2225 arbel, ( 1 << log_num_qps ), arbel->limits.qpc_entry_size,
2226 icm_offset, ( icm_offset + len ) );
2229 /* Extended queue pair contexts */
2230 len = ( ( 1 << log_num_qps ) * arbel->limits.eqpc_entry_size );
2231 icm_offset = icm_align ( icm_offset, len );
2232 MLX_FILL_1 ( init_hca, 25,
2233 qpc_eec_cqc_eqc_rdb_parameters.eqpc_base_addr_l,
2235 DBGC ( arbel, "Arbel %p ICM EQPC is %d x %#zx at [%zx,%zx)\n",
2236 arbel, ( 1 << log_num_qps ), arbel->limits.eqpc_entry_size,
2237 icm_offset, ( icm_offset + len ) );
2240 /* Completion queue contexts */
2241 len = ( ( 1 << log_num_cqs ) * arbel->limits.cqc_entry_size );
2242 icm_offset = icm_align ( icm_offset, len );
2243 MLX_FILL_2 ( init_hca, 21,
2244 qpc_eec_cqc_eqc_rdb_parameters.cqc_base_addr_l,
2245 ( icm_offset >> 6 ),
2246 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_cq,
2248 DBGC ( arbel, "Arbel %p ICM CQC is %d x %#zx at [%zx,%zx)\n",
2249 arbel, ( 1 << log_num_cqs ), arbel->limits.cqc_entry_size,
2250 icm_offset, ( icm_offset + len ) );
2253 /* Event queue contexts */
2254 len = ( ( 1 << log_num_eqs ) * arbel->limits.eqc_entry_size );
2255 icm_offset = icm_align ( icm_offset, len );
2256 MLX_FILL_2 ( init_hca, 33,
2257 qpc_eec_cqc_eqc_rdb_parameters.eqc_base_addr_l,
2258 ( icm_offset >> 6 ),
2259 qpc_eec_cqc_eqc_rdb_parameters.log_num_eq,
2261 DBGC ( arbel, "Arbel %p ICM EQC is %d x %#zx at [%zx,%zx)\n",
2262 arbel, ( 1 << log_num_eqs ), arbel->limits.eqc_entry_size,
2263 icm_offset, ( icm_offset + len ) );
2266 /* End-to-end contexts */
2267 len = ( ( 1 << log_num_ees ) * arbel->limits.eec_entry_size );
2268 icm_offset = icm_align ( icm_offset, len );
2269 MLX_FILL_2 ( init_hca, 17,
2270 qpc_eec_cqc_eqc_rdb_parameters.eec_base_addr_l,
2271 ( icm_offset >> 7 ),
2272 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_ee,
2274 DBGC ( arbel, "Arbel %p ICM EEC is %d x %#zx at [%zx,%zx)\n",
2275 arbel, ( 1 << log_num_ees ), arbel->limits.eec_entry_size,
2276 icm_offset, ( icm_offset + len ) );
2279 /* Shared receive queue contexts */
2280 len = ( ( 1 << log_num_srqs ) * arbel->limits.srqc_entry_size );
2281 icm_offset = icm_align ( icm_offset, len );
2282 MLX_FILL_2 ( init_hca, 19,
2283 qpc_eec_cqc_eqc_rdb_parameters.srqc_base_addr_l,
2284 ( icm_offset >> 5 ),
2285 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_srq,
2287 DBGC ( arbel, "Arbel %p ICM SRQC is %d x %#zx at [%zx,%zx)\n",
2288 arbel, ( 1 << log_num_srqs ), arbel->limits.srqc_entry_size,
2289 icm_offset, ( icm_offset + len ) );
2292 /* Memory protection table */
2293 len = ( ( 1 << log_num_mpts ) * arbel->limits.mpt_entry_size );
2294 icm_offset = icm_align ( icm_offset, len );
2295 MLX_FILL_1 ( init_hca, 61,
2296 tpt_parameters.mpt_base_adr_l, icm_offset );
2297 MLX_FILL_1 ( init_hca, 62,
2298 tpt_parameters.log_mpt_sz, log_num_mpts );
2299 DBGC ( arbel, "Arbel %p ICM MPT is %d x %#zx at [%zx,%zx)\n",
2300 arbel, ( 1 << log_num_mpts ), arbel->limits.mpt_entry_size,
2301 icm_offset, ( icm_offset + len ) );
2304 /* Remote read data base table */
2305 len = ( ( 1 << log_num_rdbs ) * ARBEL_RDB_ENTRY_SIZE );
2306 icm_offset = icm_align ( icm_offset, len );
2307 MLX_FILL_1 ( init_hca, 37,
2308 qpc_eec_cqc_eqc_rdb_parameters.rdb_base_addr_l,
2310 DBGC ( arbel, "Arbel %p ICM RDB is %d x %#zx at [%zx,%zx)\n",
2311 arbel, ( 1 << log_num_rdbs ), ARBEL_RDB_ENTRY_SIZE,
2312 icm_offset, ( icm_offset + len ) );
2315 /* Extended end-to-end contexts */
2316 len = ( ( 1 << log_num_ees ) * arbel->limits.eeec_entry_size );
2317 icm_offset = icm_align ( icm_offset, len );
2318 MLX_FILL_1 ( init_hca, 29,
2319 qpc_eec_cqc_eqc_rdb_parameters.eeec_base_addr_l,
2321 DBGC ( arbel, "Arbel %p ICM EEEC is %d x %#zx at [%zx,%zx)\n",
2322 arbel, ( 1 << log_num_ees ), arbel->limits.eeec_entry_size,
2323 icm_offset, ( icm_offset + len ) );
2326 /* Multicast table */
2327 len = ( ( 1 << log_num_mcs ) * sizeof ( struct arbelprm_mgm_entry ) );
2328 icm_offset = icm_align ( icm_offset, len );
2329 MLX_FILL_1 ( init_hca, 49,
2330 multicast_parameters.mc_base_addr_l, icm_offset );
2331 MLX_FILL_1 ( init_hca, 52,
2332 multicast_parameters.log_mc_table_entry_sz,
2333 fls ( sizeof ( struct arbelprm_mgm_entry ) - 1 ) );
2334 MLX_FILL_1 ( init_hca, 53,
2335 multicast_parameters.mc_table_hash_sz,
2336 ( 1 << log_num_mcs ) );
2337 MLX_FILL_1 ( init_hca, 54,
2338 multicast_parameters.log_mc_table_sz,
2339 log_num_mcs /* Only one entry per hash */ );
2340 DBGC ( arbel, "Arbel %p ICM MC is %d x %#zx at [%zx,%zx)\n", arbel,
2341 ( 1 << log_num_mcs ), sizeof ( struct arbelprm_mgm_entry ),
2342 icm_offset, ( icm_offset + len ) );
2345 /* Memory translation table */
2346 len = ( ( 1 << log_num_mtts ) * arbel->limits.mtt_entry_size );
2347 icm_offset = icm_align ( icm_offset, len );
2348 MLX_FILL_1 ( init_hca, 65,
2349 tpt_parameters.mtt_base_addr_l, icm_offset );
2350 DBGC ( arbel, "Arbel %p ICM MTT is %d x %#zx at [%zx,%zx)\n",
2351 arbel, ( 1 << log_num_mtts ), arbel->limits.mtt_entry_size,
2352 icm_offset, ( icm_offset + len ) );
2355 /* User access region scratchpads */
2356 len = ( ( 1 << log_num_uars ) * arbel->limits.uar_scratch_entry_size );
2357 icm_offset = icm_align ( icm_offset, len );
2358 MLX_FILL_1 ( init_hca, 77,
2359 uar_parameters.uar_scratch_base_addr_l, icm_offset );
2360 DBGC ( arbel, "Arbel %p UAR scratchpad is %d x %#zx at [%zx,%zx)\n",
2361 arbel, ( 1 << log_num_uars ),
2362 arbel->limits.uar_scratch_entry_size,
2363 icm_offset, ( icm_offset + len ) );
2366 /* Record amount of ICM to be allocated */
2367 icm_offset = icm_align ( icm_offset, ARBEL_PAGE_SIZE );
2368 icm_len = icm_offset;
2370 /* User access region contexts
2372 * The reserved UAR(s) do not need to be backed by physical
2373 * memory, and our UAR is allocated separately; neither are
2374 * part of the umalloc()ed ICM block, but both contribute to
2375 * the total length of ICM virtual address space.
2377 len = ( ( 1 << log_num_uars ) * ARBEL_PAGE_SIZE );
2378 icm_offset = icm_align ( icm_offset, len );
2379 MLX_FILL_1 ( init_hca, 74, uar_parameters.log_max_uars, log_num_uars );
2380 MLX_FILL_1 ( init_hca, 79,
2381 uar_parameters.uar_context_base_addr_l, icm_offset );
2382 arbel->db_rec_offset =
2384 ( arbel->limits.reserved_uars * ARBEL_PAGE_SIZE ) );
2385 DBGC ( arbel, "Arbel %p UAR is %d x %#zx at [%zx,%zx), doorbells "
2386 "[%zx,%zx)\n", arbel, ( 1 << log_num_uars ), ARBEL_PAGE_SIZE,
2387 icm_offset, ( icm_offset + len ), arbel->db_rec_offset,
2388 ( arbel->db_rec_offset + ARBEL_PAGE_SIZE ) );
2391 /* Get ICM auxiliary area size */
2392 memset ( &icm_size, 0, sizeof ( icm_size ) );
2393 MLX_FILL_1 ( &icm_size, 1, value, icm_len );
2394 if ( ( rc = arbel_cmd_set_icm_size ( arbel, &icm_size,
2395 &icm_aux_size ) ) != 0 ) {
2396 DBGC ( arbel, "Arbel %p could not set ICM size: %s\n",
2397 arbel, strerror ( rc ) );
2398 goto err_set_icm_size;
2400 icm_aux_len = ( MLX_GET ( &icm_aux_size, value ) * ARBEL_PAGE_SIZE );
2402 /* Allocate ICM data and auxiliary area */
2403 DBGC ( arbel, "Arbel %p requires %zd kB ICM and %zd kB AUX ICM\n",
2404 arbel, ( icm_len / 1024 ), ( icm_aux_len / 1024 ) );
2405 if ( ! arbel->icm ) {
2406 arbel->icm_len = icm_len;
2407 arbel->icm_aux_len = icm_aux_len;
2408 arbel->icm = umalloc ( arbel->icm_len + arbel->icm_aux_len );
2409 if ( ! arbel->icm ) {
2414 assert ( arbel->icm_len == icm_len );
2415 assert ( arbel->icm_aux_len == icm_aux_len );
2417 icm_phys = user_to_phys ( arbel->icm, 0 );
2419 /* Allocate doorbell UAR */
2420 arbel->db_rec = malloc_dma ( ARBEL_PAGE_SIZE, ARBEL_PAGE_SIZE );
2421 if ( ! arbel->db_rec ) {
2423 goto err_alloc_doorbell;
2426 /* Map ICM auxiliary area */
2427 DBGC ( arbel, "Arbel %p ICM AUX at [%08lx,%08lx)\n",
2428 arbel, icm_phys, ( icm_phys + arbel->icm_aux_len ) );
2429 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_icm_aux,
2430 0, icm_phys, arbel->icm_aux_len ) ) != 0 ){
2431 DBGC ( arbel, "Arbel %p could not map AUX ICM: %s\n",
2432 arbel, strerror ( rc ) );
2433 goto err_map_icm_aux;
2435 icm_phys += arbel->icm_aux_len;
2438 DBGC ( arbel, "Arbel %p ICM at [%08lx,%08lx)\n",
2439 arbel, icm_phys, ( icm_phys + arbel->icm_len ) );
2440 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_icm,
2441 0, icm_phys, arbel->icm_len ) ) != 0 ) {
2442 DBGC ( arbel, "Arbel %p could not map ICM: %s\n",
2443 arbel, strerror ( rc ) );
2446 icm_phys += arbel->icm_len;
2448 /* Map doorbell UAR */
2449 DBGC ( arbel, "Arbel %p UAR at [%08lx,%08lx)\n",
2450 arbel, virt_to_phys ( arbel->db_rec ),
2451 ( virt_to_phys ( arbel->db_rec ) + ARBEL_PAGE_SIZE ) );
2452 if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_icm,
2453 arbel->db_rec_offset,
2454 virt_to_phys ( arbel->db_rec ),
2455 ARBEL_PAGE_SIZE ) ) != 0 ) {
2456 DBGC ( arbel, "Arbel %p could not map doorbell UAR: %s\n",
2457 arbel, strerror ( rc ) );
2458 goto err_map_doorbell;
2461 /* Initialise doorbell records */
2462 memset ( arbel->db_rec, 0, ARBEL_PAGE_SIZE );
2463 db_rec = &arbel->db_rec[ARBEL_GROUP_SEPARATOR_DOORBELL];
2464 MLX_FILL_1 ( &db_rec->qp, 1, res, ARBEL_UAR_RES_GROUP_SEP );
2468 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2469 MLX_FILL_1 ( &unmap_icm, 1, value, arbel->db_rec_offset );
2470 arbel_cmd_unmap_icm ( arbel, 1, &unmap_icm );
2472 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2473 arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / ARBEL_PAGE_SIZE ),
2476 arbel_cmd_unmap_icm_aux ( arbel );
2478 free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
2479 arbel->db_rec= NULL;
2489 * @v arbel Arbel device
2491 static void arbel_free_icm ( struct arbel *arbel ) {
2492 struct arbelprm_scalar_parameter unmap_icm;
2494 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2495 MLX_FILL_1 ( &unmap_icm, 1, value, arbel->db_rec_offset );
2496 arbel_cmd_unmap_icm ( arbel, 1, &unmap_icm );
2497 memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2498 arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / ARBEL_PAGE_SIZE ),
2500 arbel_cmd_unmap_icm_aux ( arbel );
2501 free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
2502 arbel->db_rec = NULL;
2505 /***************************************************************************
2507 * Initialisation and teardown
2509 ***************************************************************************
2515 * @v arbel Arbel device
2517 static void arbel_reset ( struct arbel *arbel ) {
2518 struct pci_device *pci = arbel->pci;
2519 struct pci_config_backup backup;
2520 static const uint8_t backup_exclude[] =
2521 PCI_CONFIG_BACKUP_EXCLUDE ( 0x58, 0x5c );
2525 /* Perform device reset and preserve PCI configuration */
2526 pci_backup ( pci, &backup, backup_exclude );
2527 writel ( ARBEL_RESET_MAGIC,
2528 ( arbel->config + ARBEL_RESET_OFFSET ) );
2529 for ( i = 0 ; i < ARBEL_RESET_WAIT_TIME_MS ; i++ ) {
2531 pci_read_config_word ( pci, PCI_VENDOR_ID, &vendor );
2532 if ( vendor != 0xffff )
2535 pci_restore ( pci, &backup, backup_exclude );
2539 * Set up memory protection table
2541 * @v arbel Arbel device
2542 * @ret rc Return status code
2544 static int arbel_setup_mpt ( struct arbel *arbel ) {
2545 struct arbelprm_mpt mpt;
2550 key = ( arbel->limits.reserved_mrws | ARBEL_MKEY_PREFIX );
2551 arbel->lkey = ( ( key << 8 ) | ( key >> 24 ) );
2553 /* Initialise memory protection table */
2554 memset ( &mpt, 0, sizeof ( mpt ) );
2555 MLX_FILL_7 ( &mpt, 0,
2563 MLX_FILL_1 ( &mpt, 2, mem_key, key );
2564 MLX_FILL_2 ( &mpt, 3,
2565 pd, ARBEL_GLOBAL_PD,
2567 MLX_FILL_1 ( &mpt, 6, reg_wnd_len_h, 0xffffffffUL );
2568 MLX_FILL_1 ( &mpt, 7, reg_wnd_len_l, 0xffffffffUL );
2569 if ( ( rc = arbel_cmd_sw2hw_mpt ( arbel, arbel->limits.reserved_mrws,
2571 DBGC ( arbel, "Arbel %p could not set up MPT: %s\n",
2572 arbel, strerror ( rc ) );
2580 * Configure special queue pairs
2582 * @v arbel Arbel device
2583 * @ret rc Return status code
2585 static int arbel_configure_special_qps ( struct arbel *arbel ) {
2586 unsigned int smi_qpn_base;
2587 unsigned int gsi_qpn_base;
2590 /* Special QP block must be aligned on an even number */
2591 arbel->special_qpn_base = ( ( arbel->limits.reserved_qps + 1 ) & ~1 );
2592 arbel->qpn_base = ( arbel->special_qpn_base +
2593 ARBEL_NUM_SPECIAL_QPS );
2594 DBGC ( arbel, "Arbel %p special QPs at [%lx,%lx]\n", arbel,
2595 arbel->special_qpn_base, ( arbel->qpn_base - 1 ) );
2596 smi_qpn_base = arbel->special_qpn_base;
2597 gsi_qpn_base = ( smi_qpn_base + 2 );
2599 /* Issue commands to configure special QPs */
2600 if ( ( rc = arbel_cmd_conf_special_qp ( arbel, 0,
2601 smi_qpn_base ) ) != 0 ) {
2602 DBGC ( arbel, "Arbel %p could not configure SMI QPs: %s\n",
2603 arbel, strerror ( rc ) );
2606 if ( ( rc = arbel_cmd_conf_special_qp ( arbel, 1,
2607 gsi_qpn_base ) ) != 0 ) {
2608 DBGC ( arbel, "Arbel %p could not configure GSI QPs: %s\n",
2609 arbel, strerror ( rc ) );
2617 * Start Arbel device
2619 * @v arbel Arbel device
2620 * @v running Firmware is already running
2621 * @ret rc Return status code
2623 static int arbel_start ( struct arbel *arbel, int running ) {
2624 struct arbelprm_init_hca init_hca;
2628 /* Start firmware if not already running */
2630 if ( ( rc = arbel_start_firmware ( arbel ) ) != 0 )
2631 goto err_start_firmware;
2635 memset ( &init_hca, 0, sizeof ( init_hca ) );
2636 if ( ( rc = arbel_alloc_icm ( arbel, &init_hca ) ) != 0 )
2639 /* Initialise HCA */
2640 if ( ( rc = arbel_cmd_init_hca ( arbel, &init_hca ) ) != 0 ) {
2641 DBGC ( arbel, "Arbel %p could not initialise HCA: %s\n",
2642 arbel, strerror ( rc ) );
2646 /* Set up memory protection */
2647 if ( ( rc = arbel_setup_mpt ( arbel ) ) != 0 )
2649 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ )
2650 arbel->ibdev[i]->rdma_key = arbel->lkey;
2652 /* Set up event queue */
2653 if ( ( rc = arbel_create_eq ( arbel ) ) != 0 )
2656 /* Configure special QPs */
2657 if ( ( rc = arbel_configure_special_qps ( arbel ) ) != 0 )
2658 goto err_conf_special_qps;
2662 err_conf_special_qps:
2663 arbel_destroy_eq ( arbel );
2666 arbel_cmd_close_hca ( arbel );
2668 arbel_free_icm ( arbel );
2670 arbel_stop_firmware ( arbel );
2678 * @v arbel Arbel device
2680 static void arbel_stop ( struct arbel *arbel ) {
2681 arbel_destroy_eq ( arbel );
2682 arbel_cmd_close_hca ( arbel );
2683 arbel_free_icm ( arbel );
2684 arbel_stop_firmware ( arbel );
2685 arbel_reset ( arbel );
2691 * @v arbel Arbel device
2692 * @ret rc Return status code
2694 static int arbel_open ( struct arbel *arbel ) {
2697 /* Start device if applicable */
2698 if ( arbel->open_count == 0 ) {
2699 if ( ( rc = arbel_start ( arbel, 0 ) ) != 0 )
2703 /* Increment open counter */
2704 arbel->open_count++;
2710 * Close Arbel device
2712 * @v arbel Arbel device
2714 static void arbel_close ( struct arbel *arbel ) {
2716 /* Decrement open counter */
2717 assert ( arbel->open_count != 0 );
2718 arbel->open_count--;
2720 /* Stop device if applicable */
2721 if ( arbel->open_count == 0 )
2722 arbel_stop ( arbel );
2725 /***************************************************************************
2727 * Infiniband link-layer operations
2729 ***************************************************************************
2733 * Initialise Infiniband link
2735 * @v ibdev Infiniband device
2736 * @ret rc Return status code
2738 static int arbel_ib_open ( struct ib_device *ibdev ) {
2739 struct arbel *arbel = ib_get_drvdata ( ibdev );
2740 struct arbelprm_init_ib init_ib;
2744 if ( ( rc = arbel_open ( arbel ) ) != 0 )
2748 memset ( &init_ib, 0, sizeof ( init_ib ) );
2749 MLX_FILL_3 ( &init_ib, 0,
2750 mtu_cap, ARBEL_MTU_2048,
2753 MLX_FILL_1 ( &init_ib, 1, max_gid, 1 );
2754 MLX_FILL_1 ( &init_ib, 2, max_pkey, 64 );
2755 if ( ( rc = arbel_cmd_init_ib ( arbel, ibdev->port,
2756 &init_ib ) ) != 0 ) {
2757 DBGC ( arbel, "Arbel %p port %d could not intialise IB: %s\n",
2758 arbel, ibdev->port, strerror ( rc ) );
2762 /* Update MAD parameters */
2763 ib_smc_update ( ibdev, arbel_mad );
2768 arbel_close ( arbel );
2774 * Close Infiniband link
2776 * @v ibdev Infiniband device
2778 static void arbel_ib_close ( struct ib_device *ibdev ) {
2779 struct arbel *arbel = ib_get_drvdata ( ibdev );
2783 if ( ( rc = arbel_cmd_close_ib ( arbel, ibdev->port ) ) != 0 ) {
2784 DBGC ( arbel, "Arbel %p port %d could not close IB: %s\n",
2785 arbel, ibdev->port, strerror ( rc ) );
2786 /* Nothing we can do about this */
2789 /* Close hardware */
2790 arbel_close ( arbel );
2794 * Inform embedded subnet management agent of a received MAD
2796 * @v ibdev Infiniband device
2798 * @ret rc Return status code
2800 static int arbel_inform_sma ( struct ib_device *ibdev, union ib_mad *mad ) {
2803 /* Send the MAD to the embedded SMA */
2804 if ( ( rc = arbel_mad ( ibdev, mad ) ) != 0 )
2807 /* Update parameters held in software */
2808 ib_smc_update ( ibdev, arbel_mad );
2813 /***************************************************************************
2815 * Multicast group operations
2817 ***************************************************************************
2821 * Attach to multicast group
2823 * @v ibdev Infiniband device
2825 * @v gid Multicast GID
2826 * @ret rc Return status code
2828 static int arbel_mcast_attach ( struct ib_device *ibdev,
2829 struct ib_queue_pair *qp,
2830 union ib_gid *gid ) {
2831 struct arbel *arbel = ib_get_drvdata ( ibdev );
2832 struct arbelprm_mgm_hash hash;
2833 struct arbelprm_mgm_entry mgm;
2837 /* Generate hash table index */
2838 if ( ( rc = arbel_cmd_mgid_hash ( arbel, gid, &hash ) ) != 0 ) {
2839 DBGC ( arbel, "Arbel %p could not hash GID: %s\n",
2840 arbel, strerror ( rc ) );
2843 index = MLX_GET ( &hash, hash );
2845 /* Check for existing hash table entry */
2846 if ( ( rc = arbel_cmd_read_mgm ( arbel, index, &mgm ) ) != 0 ) {
2847 DBGC ( arbel, "Arbel %p could not read MGM %#x: %s\n",
2848 arbel, index, strerror ( rc ) );
2851 if ( MLX_GET ( &mgm, mgmqp_0.qi ) != 0 ) {
2852 /* FIXME: this implementation allows only a single QP
2853 * per multicast group, and doesn't handle hash
2854 * collisions. Sufficient for IPoIB but may need to
2855 * be extended in future.
2857 DBGC ( arbel, "Arbel %p MGID index %#x already in use\n",
2862 /* Update hash table entry */
2863 MLX_FILL_2 ( &mgm, 8,
2864 mgmqp_0.qpn_i, qp->qpn,
2866 memcpy ( &mgm.u.dwords[4], gid, sizeof ( *gid ) );
2867 if ( ( rc = arbel_cmd_write_mgm ( arbel, index, &mgm ) ) != 0 ) {
2868 DBGC ( arbel, "Arbel %p could not write MGM %#x: %s\n",
2869 arbel, index, strerror ( rc ) );
2877 * Detach from multicast group
2879 * @v ibdev Infiniband device
2881 * @v gid Multicast GID
2883 static void arbel_mcast_detach ( struct ib_device *ibdev,
2884 struct ib_queue_pair *qp __unused,
2885 union ib_gid *gid ) {
2886 struct arbel *arbel = ib_get_drvdata ( ibdev );
2887 struct arbelprm_mgm_hash hash;
2888 struct arbelprm_mgm_entry mgm;
2892 /* Generate hash table index */
2893 if ( ( rc = arbel_cmd_mgid_hash ( arbel, gid, &hash ) ) != 0 ) {
2894 DBGC ( arbel, "Arbel %p could not hash GID: %s\n",
2895 arbel, strerror ( rc ) );
2898 index = MLX_GET ( &hash, hash );
2900 /* Clear hash table entry */
2901 memset ( &mgm, 0, sizeof ( mgm ) );
2902 if ( ( rc = arbel_cmd_write_mgm ( arbel, index, &mgm ) ) != 0 ) {
2903 DBGC ( arbel, "Arbel %p could not write MGM %#x: %s\n",
2904 arbel, index, strerror ( rc ) );
2909 /** Arbel Infiniband operations */
2910 static struct ib_device_operations arbel_ib_operations = {
2911 .create_cq = arbel_create_cq,
2912 .destroy_cq = arbel_destroy_cq,
2913 .create_qp = arbel_create_qp,
2914 .modify_qp = arbel_modify_qp,
2915 .destroy_qp = arbel_destroy_qp,
2916 .post_send = arbel_post_send,
2917 .post_recv = arbel_post_recv,
2918 .poll_cq = arbel_poll_cq,
2919 .poll_eq = arbel_poll_eq,
2920 .open = arbel_ib_open,
2921 .close = arbel_ib_close,
2922 .mcast_attach = arbel_mcast_attach,
2923 .mcast_detach = arbel_mcast_detach,
2924 .set_port_info = arbel_inform_sma,
2925 .set_pkey_table = arbel_inform_sma,
2928 /***************************************************************************
2932 ***************************************************************************
2936 * Allocate Arbel device
2938 * @ret arbel Arbel device
2940 static struct arbel * arbel_alloc ( void ) {
2941 struct arbel *arbel;
2943 /* Allocate Arbel device */
2944 arbel = zalloc ( sizeof ( *arbel ) );
2948 /* Allocate space for mailboxes */
2949 arbel->mailbox_in = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
2950 if ( ! arbel->mailbox_in )
2951 goto err_mailbox_in;
2952 arbel->mailbox_out = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
2953 if ( ! arbel->mailbox_out )
2954 goto err_mailbox_out;
2958 free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
2960 free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
2970 * @v arbel Arbel device
2972 static void arbel_free ( struct arbel *arbel ) {
2974 ufree ( arbel->icm );
2975 ufree ( arbel->firmware_area );
2976 free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
2977 free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
2986 * @ret rc Return status code
2988 static int arbel_probe ( struct pci_device *pci ) {
2989 struct arbel *arbel;
2990 struct ib_device *ibdev;
2994 /* Allocate Arbel device */
2995 arbel = arbel_alloc();
3000 pci_set_drvdata ( pci, arbel );
3003 /* Allocate Infiniband devices */
3004 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
3005 ibdev = alloc_ibdev ( 0 );
3008 goto err_alloc_ibdev;
3010 arbel->ibdev[i] = ibdev;
3011 ibdev->op = &arbel_ib_operations;
3012 ibdev->dev = &pci->dev;
3013 ibdev->port = ( ARBEL_PORT_BASE + i );
3014 ib_set_drvdata ( ibdev, arbel );
3017 /* Fix up PCI device */
3018 adjust_pci_device ( pci );
3021 arbel->config = ioremap ( pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR ),
3022 ARBEL_PCI_CONFIG_BAR_SIZE );
3023 arbel->uar = ioremap ( ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) +
3024 ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE ),
3025 ARBEL_PCI_UAR_SIZE );
3028 arbel_reset ( arbel );
3030 /* Start firmware */
3031 if ( ( rc = arbel_start_firmware ( arbel ) ) != 0 )
3032 goto err_start_firmware;
3034 /* Get device limits */
3035 if ( ( rc = arbel_get_limits ( arbel ) ) != 0 )
3036 goto err_get_limits;
3039 if ( ( rc = arbel_start ( arbel, 1 ) ) != 0 )
3042 /* Initialise parameters using SMC */
3043 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ )
3044 ib_smc_init ( arbel->ibdev[i], arbel_mad );
3046 /* Register Infiniband devices */
3047 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
3048 if ( ( rc = register_ibdev ( arbel->ibdev[i] ) ) != 0 ) {
3049 DBGC ( arbel, "Arbel %p port %d could not register IB "
3050 "device: %s\n", arbel,
3051 arbel->ibdev[i]->port, strerror ( rc ) );
3052 goto err_register_ibdev;
3056 /* Leave device quiescent until opened */
3057 if ( arbel->open_count == 0 )
3058 arbel_stop ( arbel );
3062 i = ARBEL_NUM_PORTS;
3064 for ( i-- ; i >= 0 ; i-- )
3065 unregister_ibdev ( arbel->ibdev[i] );
3066 arbel_stop ( arbel );
3069 arbel_stop_firmware ( arbel );
3071 i = ARBEL_NUM_PORTS;
3073 for ( i-- ; i >= 0 ; i-- )
3074 ibdev_put ( arbel->ibdev[i] );
3075 arbel_free ( arbel );
3085 static void arbel_remove ( struct pci_device *pci ) {
3086 struct arbel *arbel = pci_get_drvdata ( pci );
3089 for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
3090 unregister_ibdev ( arbel->ibdev[i] );
3091 for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
3092 ibdev_put ( arbel->ibdev[i] );
3093 arbel_free ( arbel );
3096 static struct pci_device_id arbel_nics[] = {
3097 PCI_ROM ( 0x15b3, 0x6282, "mt25218", "MT25218 HCA driver", 0 ),
3098 PCI_ROM ( 0x15b3, 0x6274, "mt25204", "MT25204 HCA driver", 0 ),
3101 struct pci_driver arbel_driver __pci_driver = {
3103 .id_count = ( sizeof ( arbel_nics ) / sizeof ( arbel_nics[0] ) ),
3104 .probe = arbel_probe,
3105 .remove = arbel_remove,