[arbel] Fix off-by-one error in the failure path in arbel_probe()
[gpxe/hramrach.git] / src / drivers / infiniband / arbel.c
blob1b55131b86507a028378d3d2cea1f5985a70cf92
1 /*
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <strings.h>
27 #include <unistd.h>
28 #include <errno.h>
29 #include <byteswap.h>
30 #include <gpxe/pci.h>
31 #include <gpxe/malloc.h>
32 #include <gpxe/umalloc.h>
33 #include <gpxe/iobuf.h>
34 #include <gpxe/netdevice.h>
35 #include <gpxe/infiniband.h>
36 #include "arbel.h"
38 /**
39 * @file
41 * Mellanox Arbel Infiniband HCA
45 /***************************************************************************
47 * Queue number allocation
49 ***************************************************************************
52 /**
53 * Allocate queue number
55 * @v q_inuse Queue usage bitmask
56 * @v max_inuse Maximum number of in-use queues
57 * @ret qn_offset Free queue number offset, or negative error
59 static int arbel_alloc_qn_offset ( arbel_bitmask_t *q_inuse,
60 unsigned int max_inuse ) {
61 unsigned int qn_offset = 0;
62 arbel_bitmask_t mask = 1;
64 while ( qn_offset < max_inuse ) {
65 if ( ( mask & *q_inuse ) == 0 ) {
66 *q_inuse |= mask;
67 return qn_offset;
69 qn_offset++;
70 mask <<= 1;
71 if ( ! mask ) {
72 mask = 1;
73 q_inuse++;
76 return -ENFILE;
79 /**
80 * Free queue number
82 * @v q_inuse Queue usage bitmask
83 * @v qn_offset Queue number offset
85 static void arbel_free_qn_offset ( arbel_bitmask_t *q_inuse, int qn_offset ) {
86 arbel_bitmask_t mask;
88 mask = ( 1 << ( qn_offset % ( 8 * sizeof ( mask ) ) ) );
89 q_inuse += ( qn_offset / ( 8 * sizeof ( mask ) ) );
90 *q_inuse &= ~mask;
93 /***************************************************************************
95 * HCA commands
97 ***************************************************************************
101 * Wait for Arbel command completion
103 * @v arbel Arbel device
104 * @ret rc Return status code
106 static int arbel_cmd_wait ( struct arbel *arbel,
107 struct arbelprm_hca_command_register *hcr ) {
108 unsigned int wait;
110 for ( wait = ARBEL_HCR_MAX_WAIT_MS ; wait ; wait-- ) {
111 hcr->u.dwords[6] =
112 readl ( arbel->config + ARBEL_HCR_REG ( 6 ) );
113 if ( MLX_GET ( hcr, go ) == 0 )
114 return 0;
115 mdelay ( 1 );
117 return -EBUSY;
121 * Issue HCA command
123 * @v arbel Arbel device
124 * @v command Command opcode, flags and input/output lengths
125 * @v op_mod Opcode modifier (0 if no modifier applicable)
126 * @v in Input parameters
127 * @v in_mod Input modifier (0 if no modifier applicable)
128 * @v out Output parameters
129 * @ret rc Return status code
131 static int arbel_cmd ( struct arbel *arbel, unsigned long command,
132 unsigned int op_mod, const void *in,
133 unsigned int in_mod, void *out ) {
134 struct arbelprm_hca_command_register hcr;
135 unsigned int opcode = ARBEL_HCR_OPCODE ( command );
136 size_t in_len = ARBEL_HCR_IN_LEN ( command );
137 size_t out_len = ARBEL_HCR_OUT_LEN ( command );
138 void *in_buffer;
139 void *out_buffer;
140 unsigned int status;
141 unsigned int i;
142 int rc;
144 assert ( in_len <= ARBEL_MBOX_SIZE );
145 assert ( out_len <= ARBEL_MBOX_SIZE );
147 DBGC2 ( arbel, "Arbel %p command %02x in %zx%s out %zx%s\n",
148 arbel, opcode, in_len,
149 ( ( command & ARBEL_HCR_IN_MBOX ) ? "(mbox)" : "" ), out_len,
150 ( ( command & ARBEL_HCR_OUT_MBOX ) ? "(mbox)" : "" ) );
152 /* Check that HCR is free */
153 if ( ( rc = arbel_cmd_wait ( arbel, &hcr ) ) != 0 ) {
154 DBGC ( arbel, "Arbel %p command interface locked\n", arbel );
155 return rc;
158 /* Prepare HCR */
159 memset ( &hcr, 0, sizeof ( hcr ) );
160 in_buffer = &hcr.u.dwords[0];
161 if ( in_len && ( command & ARBEL_HCR_IN_MBOX ) ) {
162 in_buffer = arbel->mailbox_in;
163 MLX_FILL_1 ( &hcr, 1, in_param_l, virt_to_bus ( in_buffer ) );
165 memcpy ( in_buffer, in, in_len );
166 MLX_FILL_1 ( &hcr, 2, input_modifier, in_mod );
167 out_buffer = &hcr.u.dwords[3];
168 if ( out_len && ( command & ARBEL_HCR_OUT_MBOX ) ) {
169 out_buffer = arbel->mailbox_out;
170 MLX_FILL_1 ( &hcr, 4, out_param_l,
171 virt_to_bus ( out_buffer ) );
173 MLX_FILL_3 ( &hcr, 6,
174 opcode, opcode,
175 opcode_modifier, op_mod,
176 go, 1 );
177 DBGC2_HD ( arbel, &hcr, sizeof ( hcr ) );
178 if ( in_len ) {
179 DBGC2 ( arbel, "Input:\n" );
180 DBGC2_HD ( arbel, in, ( ( in_len < 512 ) ? in_len : 512 ) );
183 /* Issue command */
184 for ( i = 0 ; i < ( sizeof ( hcr ) / sizeof ( hcr.u.dwords[0] ) ) ;
185 i++ ) {
186 writel ( hcr.u.dwords[i],
187 arbel->config + ARBEL_HCR_REG ( i ) );
188 barrier();
191 /* Wait for command completion */
192 if ( ( rc = arbel_cmd_wait ( arbel, &hcr ) ) != 0 ) {
193 DBGC ( arbel, "Arbel %p timed out waiting for command:\n",
194 arbel );
195 DBGC_HD ( arbel, &hcr, sizeof ( hcr ) );
196 return rc;
199 /* Check command status */
200 status = MLX_GET ( &hcr, status );
201 if ( status != 0 ) {
202 DBGC ( arbel, "Arbel %p command failed with status %02x:\n",
203 arbel, status );
204 DBGC_HD ( arbel, &hcr, sizeof ( hcr ) );
205 return -EIO;
208 /* Read output parameters, if any */
209 hcr.u.dwords[3] = readl ( arbel->config + ARBEL_HCR_REG ( 3 ) );
210 hcr.u.dwords[4] = readl ( arbel->config + ARBEL_HCR_REG ( 4 ) );
211 memcpy ( out, out_buffer, out_len );
212 if ( out_len ) {
213 DBGC2 ( arbel, "Output:\n" );
214 DBGC2_HD ( arbel, out, ( ( out_len < 512 ) ? out_len : 512 ) );
217 return 0;
220 static inline int
221 arbel_cmd_query_dev_lim ( struct arbel *arbel,
222 struct arbelprm_query_dev_lim *dev_lim ) {
223 return arbel_cmd ( arbel,
224 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_DEV_LIM,
225 1, sizeof ( *dev_lim ) ),
226 0, NULL, 0, dev_lim );
229 static inline int
230 arbel_cmd_query_fw ( struct arbel *arbel, struct arbelprm_query_fw *fw ) {
231 return arbel_cmd ( arbel,
232 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_QUERY_FW,
233 1, sizeof ( *fw ) ),
234 0, NULL, 0, fw );
237 static inline int
238 arbel_cmd_init_hca ( struct arbel *arbel,
239 const struct arbelprm_init_hca *init_hca ) {
240 return arbel_cmd ( arbel,
241 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT_HCA,
242 1, sizeof ( *init_hca ) ),
243 0, init_hca, 0, NULL );
246 static inline int
247 arbel_cmd_close_hca ( struct arbel *arbel ) {
248 return arbel_cmd ( arbel,
249 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CLOSE_HCA ),
250 0, NULL, 0, NULL );
253 static inline int
254 arbel_cmd_init_ib ( struct arbel *arbel, unsigned int port,
255 const struct arbelprm_init_ib *init_ib ) {
256 return arbel_cmd ( arbel,
257 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT_IB,
258 1, sizeof ( *init_ib ) ),
259 0, init_ib, port, NULL );
262 static inline int
263 arbel_cmd_close_ib ( struct arbel *arbel, unsigned int port ) {
264 return arbel_cmd ( arbel,
265 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_CLOSE_IB ),
266 0, NULL, port, NULL );
269 static inline int
270 arbel_cmd_sw2hw_mpt ( struct arbel *arbel, unsigned int index,
271 const struct arbelprm_mpt *mpt ) {
272 return arbel_cmd ( arbel,
273 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_MPT,
274 1, sizeof ( *mpt ) ),
275 0, mpt, index, NULL );
278 static inline int
279 arbel_cmd_map_eq ( struct arbel *arbel, unsigned long index_map,
280 const struct arbelprm_event_mask *mask ) {
281 return arbel_cmd ( arbel,
282 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_EQ,
283 0, sizeof ( *mask ) ),
284 0, mask, index_map, NULL );
287 static inline int
288 arbel_cmd_sw2hw_eq ( struct arbel *arbel, unsigned int index,
289 const struct arbelprm_eqc *eqctx ) {
290 return arbel_cmd ( arbel,
291 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_EQ,
292 1, sizeof ( *eqctx ) ),
293 0, eqctx, index, NULL );
296 static inline int
297 arbel_cmd_hw2sw_eq ( struct arbel *arbel, unsigned int index,
298 struct arbelprm_eqc *eqctx ) {
299 return arbel_cmd ( arbel,
300 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_HW2SW_EQ,
301 1, sizeof ( *eqctx ) ),
302 1, NULL, index, eqctx );
305 static inline int
306 arbel_cmd_sw2hw_cq ( struct arbel *arbel, unsigned long cqn,
307 const struct arbelprm_completion_queue_context *cqctx ) {
308 return arbel_cmd ( arbel,
309 ARBEL_HCR_IN_CMD ( ARBEL_HCR_SW2HW_CQ,
310 1, sizeof ( *cqctx ) ),
311 0, cqctx, cqn, NULL );
314 static inline int
315 arbel_cmd_hw2sw_cq ( struct arbel *arbel, unsigned long cqn,
316 struct arbelprm_completion_queue_context *cqctx) {
317 return arbel_cmd ( arbel,
318 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_HW2SW_CQ,
319 1, sizeof ( *cqctx ) ),
320 0, NULL, cqn, cqctx );
323 static inline int
324 arbel_cmd_rst2init_qpee ( struct arbel *arbel, unsigned long qpn,
325 const struct arbelprm_qp_ee_state_transitions *ctx ){
326 return arbel_cmd ( arbel,
327 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RST2INIT_QPEE,
328 1, sizeof ( *ctx ) ),
329 0, ctx, qpn, NULL );
332 static inline int
333 arbel_cmd_init2rtr_qpee ( struct arbel *arbel, unsigned long qpn,
334 const struct arbelprm_qp_ee_state_transitions *ctx ){
335 return arbel_cmd ( arbel,
336 ARBEL_HCR_IN_CMD ( ARBEL_HCR_INIT2RTR_QPEE,
337 1, sizeof ( *ctx ) ),
338 0, ctx, qpn, NULL );
341 static inline int
342 arbel_cmd_rtr2rts_qpee ( struct arbel *arbel, unsigned long qpn,
343 const struct arbelprm_qp_ee_state_transitions *ctx ) {
344 return arbel_cmd ( arbel,
345 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RTR2RTS_QPEE,
346 1, sizeof ( *ctx ) ),
347 0, ctx, qpn, NULL );
350 static inline int
351 arbel_cmd_rts2rts_qp ( struct arbel *arbel, unsigned long qpn,
352 const struct arbelprm_qp_ee_state_transitions *ctx ) {
353 return arbel_cmd ( arbel,
354 ARBEL_HCR_IN_CMD ( ARBEL_HCR_RTS2RTS_QPEE,
355 1, sizeof ( *ctx ) ),
356 0, ctx, qpn, NULL );
359 static inline int
360 arbel_cmd_2rst_qpee ( struct arbel *arbel, unsigned long qpn ) {
361 return arbel_cmd ( arbel,
362 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_2RST_QPEE ),
363 0x03, NULL, qpn, NULL );
366 static inline int
367 arbel_cmd_mad_ifc ( struct arbel *arbel, unsigned int port,
368 union arbelprm_mad *mad ) {
369 return arbel_cmd ( arbel,
370 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_MAD_IFC,
371 1, sizeof ( *mad ),
372 1, sizeof ( *mad ) ),
373 0x03, mad, port, mad );
376 static inline int
377 arbel_cmd_read_mgm ( struct arbel *arbel, unsigned int index,
378 struct arbelprm_mgm_entry *mgm ) {
379 return arbel_cmd ( arbel,
380 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_READ_MGM,
381 1, sizeof ( *mgm ) ),
382 0, NULL, index, mgm );
385 static inline int
386 arbel_cmd_write_mgm ( struct arbel *arbel, unsigned int index,
387 const struct arbelprm_mgm_entry *mgm ) {
388 return arbel_cmd ( arbel,
389 ARBEL_HCR_IN_CMD ( ARBEL_HCR_WRITE_MGM,
390 1, sizeof ( *mgm ) ),
391 0, mgm, index, NULL );
394 static inline int
395 arbel_cmd_mgid_hash ( struct arbel *arbel, const struct ib_gid *gid,
396 struct arbelprm_mgm_hash *hash ) {
397 return arbel_cmd ( arbel,
398 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_MGID_HASH,
399 1, sizeof ( *gid ),
400 0, sizeof ( *hash ) ),
401 0, gid, 0, hash );
404 static inline int
405 arbel_cmd_run_fw ( struct arbel *arbel ) {
406 return arbel_cmd ( arbel,
407 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_RUN_FW ),
408 0, NULL, 0, NULL );
411 static inline int
412 arbel_cmd_disable_lam ( struct arbel *arbel ) {
413 return arbel_cmd ( arbel,
414 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_DISABLE_LAM ),
415 0, NULL, 0, NULL );
418 static inline int
419 arbel_cmd_enable_lam ( struct arbel *arbel, struct arbelprm_access_lam *lam ) {
420 return arbel_cmd ( arbel,
421 ARBEL_HCR_OUT_CMD ( ARBEL_HCR_ENABLE_LAM,
422 1, sizeof ( *lam ) ),
423 1, NULL, 0, lam );
426 static inline int
427 arbel_cmd_unmap_icm ( struct arbel *arbel, unsigned int page_count ) {
428 return arbel_cmd ( arbel,
429 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_UNMAP_ICM ),
430 0, NULL, page_count, NULL );
433 static inline int
434 arbel_cmd_map_icm ( struct arbel *arbel,
435 const struct arbelprm_virtual_physical_mapping *map ) {
436 return arbel_cmd ( arbel,
437 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_ICM,
438 1, sizeof ( *map ) ),
439 0, map, 1, NULL );
442 static inline int
443 arbel_cmd_unmap_icm_aux ( struct arbel *arbel ) {
444 return arbel_cmd ( arbel,
445 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_UNMAP_ICM_AUX ),
446 0, NULL, 0, NULL );
449 static inline int
450 arbel_cmd_map_icm_aux ( struct arbel *arbel,
451 const struct arbelprm_virtual_physical_mapping *map ) {
452 return arbel_cmd ( arbel,
453 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_ICM_AUX,
454 1, sizeof ( *map ) ),
455 0, map, 1, NULL );
458 static inline int
459 arbel_cmd_set_icm_size ( struct arbel *arbel,
460 const struct arbelprm_scalar_parameter *icm_size,
461 struct arbelprm_scalar_parameter *icm_aux_size ) {
462 return arbel_cmd ( arbel,
463 ARBEL_HCR_INOUT_CMD ( ARBEL_HCR_SET_ICM_SIZE,
464 0, sizeof ( *icm_size ),
465 0, sizeof ( *icm_aux_size ) ),
466 0, icm_size, 0, icm_aux_size );
469 static inline int
470 arbel_cmd_unmap_fa ( struct arbel *arbel ) {
471 return arbel_cmd ( arbel,
472 ARBEL_HCR_VOID_CMD ( ARBEL_HCR_UNMAP_FA ),
473 0, NULL, 0, NULL );
476 static inline int
477 arbel_cmd_map_fa ( struct arbel *arbel,
478 const struct arbelprm_virtual_physical_mapping *map ) {
479 return arbel_cmd ( arbel,
480 ARBEL_HCR_IN_CMD ( ARBEL_HCR_MAP_FA,
481 1, sizeof ( *map ) ),
482 0, map, 1, NULL );
485 /***************************************************************************
487 * Completion queue operations
489 ***************************************************************************
493 * Create completion queue
495 * @v ibdev Infiniband device
496 * @v cq Completion queue
497 * @ret rc Return status code
499 static int arbel_create_cq ( struct ib_device *ibdev,
500 struct ib_completion_queue *cq ) {
501 struct arbel *arbel = ib_get_drvdata ( ibdev );
502 struct arbel_completion_queue *arbel_cq;
503 struct arbelprm_completion_queue_context cqctx;
504 struct arbelprm_cq_ci_db_record *ci_db_rec;
505 struct arbelprm_cq_arm_db_record *arm_db_rec;
506 int cqn_offset;
507 unsigned int i;
508 int rc;
510 /* Find a free completion queue number */
511 cqn_offset = arbel_alloc_qn_offset ( arbel->cq_inuse, ARBEL_MAX_CQS );
512 if ( cqn_offset < 0 ) {
513 DBGC ( arbel, "Arbel %p out of completion queues\n", arbel );
514 rc = cqn_offset;
515 goto err_cqn_offset;
517 cq->cqn = ( arbel->limits.reserved_cqs + cqn_offset );
519 /* Allocate control structures */
520 arbel_cq = zalloc ( sizeof ( *arbel_cq ) );
521 if ( ! arbel_cq ) {
522 rc = -ENOMEM;
523 goto err_arbel_cq;
525 arbel_cq->ci_doorbell_idx = arbel_cq_ci_doorbell_idx ( cqn_offset );
526 arbel_cq->arm_doorbell_idx = arbel_cq_arm_doorbell_idx ( cqn_offset );
528 /* Allocate completion queue itself */
529 arbel_cq->cqe_size = ( cq->num_cqes * sizeof ( arbel_cq->cqe[0] ) );
530 arbel_cq->cqe = malloc_dma ( arbel_cq->cqe_size,
531 sizeof ( arbel_cq->cqe[0] ) );
532 if ( ! arbel_cq->cqe ) {
533 rc = -ENOMEM;
534 goto err_cqe;
536 memset ( arbel_cq->cqe, 0, arbel_cq->cqe_size );
537 for ( i = 0 ; i < cq->num_cqes ; i++ ) {
538 MLX_FILL_1 ( &arbel_cq->cqe[i].normal, 7, owner, 1 );
540 barrier();
542 /* Initialise doorbell records */
543 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
544 MLX_FILL_1 ( ci_db_rec, 0, counter, 0 );
545 MLX_FILL_2 ( ci_db_rec, 1,
546 res, ARBEL_UAR_RES_CQ_CI,
547 cq_number, cq->cqn );
548 arm_db_rec = &arbel->db_rec[arbel_cq->arm_doorbell_idx].cq_arm;
549 MLX_FILL_1 ( arm_db_rec, 0, counter, 0 );
550 MLX_FILL_2 ( arm_db_rec, 1,
551 res, ARBEL_UAR_RES_CQ_ARM,
552 cq_number, cq->cqn );
554 /* Hand queue over to hardware */
555 memset ( &cqctx, 0, sizeof ( cqctx ) );
556 MLX_FILL_1 ( &cqctx, 0, st, 0xa /* "Event fired" */ );
557 MLX_FILL_1 ( &cqctx, 2, start_address_l,
558 virt_to_bus ( arbel_cq->cqe ) );
559 MLX_FILL_2 ( &cqctx, 3,
560 usr_page, arbel->limits.reserved_uars,
561 log_cq_size, fls ( cq->num_cqes - 1 ) );
562 MLX_FILL_1 ( &cqctx, 5, c_eqn, ARBEL_NO_EQ );
563 MLX_FILL_1 ( &cqctx, 6, pd, ARBEL_GLOBAL_PD );
564 MLX_FILL_1 ( &cqctx, 7, l_key, arbel->reserved_lkey );
565 MLX_FILL_1 ( &cqctx, 12, cqn, cq->cqn );
566 MLX_FILL_1 ( &cqctx, 13,
567 cq_ci_db_record, arbel_cq->ci_doorbell_idx );
568 MLX_FILL_1 ( &cqctx, 14,
569 cq_state_db_record, arbel_cq->arm_doorbell_idx );
570 if ( ( rc = arbel_cmd_sw2hw_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
571 DBGC ( arbel, "Arbel %p SW2HW_CQ failed: %s\n",
572 arbel, strerror ( rc ) );
573 goto err_sw2hw_cq;
576 DBGC ( arbel, "Arbel %p CQN %#lx ring at [%p,%p)\n",
577 arbel, cq->cqn, arbel_cq->cqe,
578 ( ( ( void * ) arbel_cq->cqe ) + arbel_cq->cqe_size ) );
579 ib_cq_set_drvdata ( cq, arbel_cq );
580 return 0;
582 err_sw2hw_cq:
583 MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
584 MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
585 free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
586 err_cqe:
587 free ( arbel_cq );
588 err_arbel_cq:
589 arbel_free_qn_offset ( arbel->cq_inuse, cqn_offset );
590 err_cqn_offset:
591 return rc;
595 * Destroy completion queue
597 * @v ibdev Infiniband device
598 * @v cq Completion queue
600 static void arbel_destroy_cq ( struct ib_device *ibdev,
601 struct ib_completion_queue *cq ) {
602 struct arbel *arbel = ib_get_drvdata ( ibdev );
603 struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
604 struct arbelprm_completion_queue_context cqctx;
605 struct arbelprm_cq_ci_db_record *ci_db_rec;
606 struct arbelprm_cq_arm_db_record *arm_db_rec;
607 int cqn_offset;
608 int rc;
610 /* Take ownership back from hardware */
611 if ( ( rc = arbel_cmd_hw2sw_cq ( arbel, cq->cqn, &cqctx ) ) != 0 ) {
612 DBGC ( arbel, "Arbel %p FATAL HW2SW_CQ failed on CQN %#lx: "
613 "%s\n", arbel, cq->cqn, strerror ( rc ) );
614 /* Leak memory and return; at least we avoid corruption */
615 return;
618 /* Clear doorbell records */
619 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
620 arm_db_rec = &arbel->db_rec[arbel_cq->arm_doorbell_idx].cq_arm;
621 MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
622 MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
624 /* Free memory */
625 free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
626 free ( arbel_cq );
628 /* Mark queue number as free */
629 cqn_offset = ( cq->cqn - arbel->limits.reserved_cqs );
630 arbel_free_qn_offset ( arbel->cq_inuse, cqn_offset );
632 ib_cq_set_drvdata ( cq, NULL );
635 /***************************************************************************
637 * Queue pair operations
639 ***************************************************************************
643 * Create send work queue
645 * @v arbel_send_wq Send work queue
646 * @v num_wqes Number of work queue entries
647 * @ret rc Return status code
649 static int arbel_create_send_wq ( struct arbel_send_work_queue *arbel_send_wq,
650 unsigned int num_wqes ) {
651 struct arbelprm_ud_send_wqe *wqe;
652 struct arbelprm_ud_send_wqe *next_wqe;
653 unsigned int wqe_idx_mask;
654 unsigned int i;
656 /* Allocate work queue */
657 arbel_send_wq->wqe_size = ( num_wqes *
658 sizeof ( arbel_send_wq->wqe[0] ) );
659 arbel_send_wq->wqe = malloc_dma ( arbel_send_wq->wqe_size,
660 sizeof ( arbel_send_wq->wqe[0] ) );
661 if ( ! arbel_send_wq->wqe )
662 return -ENOMEM;
663 memset ( arbel_send_wq->wqe, 0, arbel_send_wq->wqe_size );
665 /* Link work queue entries */
666 wqe_idx_mask = ( num_wqes - 1 );
667 for ( i = 0 ; i < num_wqes ; i++ ) {
668 wqe = &arbel_send_wq->wqe[i].ud;
669 next_wqe = &arbel_send_wq->wqe[ ( i + 1 ) & wqe_idx_mask ].ud;
670 MLX_FILL_1 ( &wqe->next, 0, nda_31_6,
671 ( virt_to_bus ( next_wqe ) >> 6 ) );
674 return 0;
678 * Create receive work queue
680 * @v arbel_recv_wq Receive work queue
681 * @v num_wqes Number of work queue entries
682 * @ret rc Return status code
684 static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
685 unsigned int num_wqes ) {
686 struct arbelprm_recv_wqe *wqe;
687 struct arbelprm_recv_wqe *next_wqe;
688 unsigned int wqe_idx_mask;
689 size_t nds;
690 unsigned int i;
691 unsigned int j;
693 /* Allocate work queue */
694 arbel_recv_wq->wqe_size = ( num_wqes *
695 sizeof ( arbel_recv_wq->wqe[0] ) );
696 arbel_recv_wq->wqe = malloc_dma ( arbel_recv_wq->wqe_size,
697 sizeof ( arbel_recv_wq->wqe[0] ) );
698 if ( ! arbel_recv_wq->wqe )
699 return -ENOMEM;
700 memset ( arbel_recv_wq->wqe, 0, arbel_recv_wq->wqe_size );
702 /* Link work queue entries */
703 wqe_idx_mask = ( num_wqes - 1 );
704 nds = ( ( offsetof ( typeof ( *wqe ), data ) +
705 sizeof ( wqe->data[0] ) ) >> 4 );
706 for ( i = 0 ; i < num_wqes ; i++ ) {
707 wqe = &arbel_recv_wq->wqe[i].recv;
708 next_wqe = &arbel_recv_wq->wqe[( i + 1 ) & wqe_idx_mask].recv;
709 MLX_FILL_1 ( &wqe->next, 0, nda_31_6,
710 ( virt_to_bus ( next_wqe ) >> 6 ) );
711 MLX_FILL_1 ( &wqe->next, 1, nds, ( sizeof ( *wqe ) / 16 ) );
712 for ( j = 0 ; ( ( ( void * ) &wqe->data[j] ) <
713 ( ( void * ) ( wqe + 1 ) ) ) ; j++ ) {
714 MLX_FILL_1 ( &wqe->data[j], 1,
715 l_key, ARBEL_INVALID_LKEY );
719 return 0;
723 * Create queue pair
725 * @v ibdev Infiniband device
726 * @v qp Queue pair
727 * @ret rc Return status code
729 static int arbel_create_qp ( struct ib_device *ibdev,
730 struct ib_queue_pair *qp ) {
731 struct arbel *arbel = ib_get_drvdata ( ibdev );
732 struct arbel_queue_pair *arbel_qp;
733 struct arbelprm_qp_ee_state_transitions qpctx;
734 struct arbelprm_qp_db_record *send_db_rec;
735 struct arbelprm_qp_db_record *recv_db_rec;
736 int qpn_offset;
737 int rc;
739 /* Find a free queue pair number */
740 qpn_offset = arbel_alloc_qn_offset ( arbel->qp_inuse, ARBEL_MAX_QPS );
741 if ( qpn_offset < 0 ) {
742 DBGC ( arbel, "Arbel %p out of queue pairs\n", arbel );
743 rc = qpn_offset;
744 goto err_qpn_offset;
746 qp->qpn = ( ARBEL_QPN_BASE + arbel->limits.reserved_qps + qpn_offset );
748 /* Allocate control structures */
749 arbel_qp = zalloc ( sizeof ( *arbel_qp ) );
750 if ( ! arbel_qp ) {
751 rc = -ENOMEM;
752 goto err_arbel_qp;
754 arbel_qp->send.doorbell_idx = arbel_send_doorbell_idx ( qpn_offset );
755 arbel_qp->recv.doorbell_idx = arbel_recv_doorbell_idx ( qpn_offset );
757 /* Create send and receive work queues */
758 if ( ( rc = arbel_create_send_wq ( &arbel_qp->send,
759 qp->send.num_wqes ) ) != 0 )
760 goto err_create_send_wq;
761 if ( ( rc = arbel_create_recv_wq ( &arbel_qp->recv,
762 qp->recv.num_wqes ) ) != 0 )
763 goto err_create_recv_wq;
765 /* Initialise doorbell records */
766 send_db_rec = &arbel->db_rec[arbel_qp->send.doorbell_idx].qp;
767 MLX_FILL_1 ( send_db_rec, 0, counter, 0 );
768 MLX_FILL_2 ( send_db_rec, 1,
769 res, ARBEL_UAR_RES_SQ,
770 qp_number, qp->qpn );
771 recv_db_rec = &arbel->db_rec[arbel_qp->recv.doorbell_idx].qp;
772 MLX_FILL_1 ( recv_db_rec, 0, counter, 0 );
773 MLX_FILL_2 ( recv_db_rec, 1,
774 res, ARBEL_UAR_RES_RQ,
775 qp_number, qp->qpn );
777 /* Hand queue over to hardware */
778 memset ( &qpctx, 0, sizeof ( qpctx ) );
779 MLX_FILL_3 ( &qpctx, 2,
780 qpc_eec_data.de, 1,
781 qpc_eec_data.pm_state, 0x03 /* Always 0x03 for UD */,
782 qpc_eec_data.st, ARBEL_ST_UD );
783 MLX_FILL_6 ( &qpctx, 4,
784 qpc_eec_data.mtu, ARBEL_MTU_2048,
785 qpc_eec_data.msg_max, 11 /* 2^11 = 2048 */,
786 qpc_eec_data.log_rq_size, fls ( qp->recv.num_wqes - 1 ),
787 qpc_eec_data.log_rq_stride,
788 ( fls ( sizeof ( arbel_qp->recv.wqe[0] ) - 1 ) - 4 ),
789 qpc_eec_data.log_sq_size, fls ( qp->send.num_wqes - 1 ),
790 qpc_eec_data.log_sq_stride,
791 ( fls ( sizeof ( arbel_qp->send.wqe[0] ) - 1 ) - 4 ) );
792 MLX_FILL_1 ( &qpctx, 5,
793 qpc_eec_data.usr_page, arbel->limits.reserved_uars );
794 MLX_FILL_1 ( &qpctx, 10, qpc_eec_data.primary_address_path.port_number,
795 ibdev->port );
796 MLX_FILL_1 ( &qpctx, 27, qpc_eec_data.pd, ARBEL_GLOBAL_PD );
797 MLX_FILL_1 ( &qpctx, 29, qpc_eec_data.wqe_lkey, arbel->reserved_lkey );
798 MLX_FILL_1 ( &qpctx, 30, qpc_eec_data.ssc, 1 );
799 MLX_FILL_1 ( &qpctx, 33, qpc_eec_data.cqn_snd, qp->send.cq->cqn );
800 MLX_FILL_1 ( &qpctx, 34, qpc_eec_data.snd_wqe_base_adr_l,
801 ( virt_to_bus ( arbel_qp->send.wqe ) >> 6 ) );
802 MLX_FILL_1 ( &qpctx, 35, qpc_eec_data.snd_db_record_index,
803 arbel_qp->send.doorbell_idx );
804 MLX_FILL_1 ( &qpctx, 38, qpc_eec_data.rsc, 1 );
805 MLX_FILL_1 ( &qpctx, 41, qpc_eec_data.cqn_rcv, qp->recv.cq->cqn );
806 MLX_FILL_1 ( &qpctx, 42, qpc_eec_data.rcv_wqe_base_adr_l,
807 ( virt_to_bus ( arbel_qp->recv.wqe ) >> 6 ) );
808 MLX_FILL_1 ( &qpctx, 43, qpc_eec_data.rcv_db_record_index,
809 arbel_qp->recv.doorbell_idx );
810 MLX_FILL_1 ( &qpctx, 44, qpc_eec_data.q_key, qp->qkey );
811 if ( ( rc = arbel_cmd_rst2init_qpee ( arbel, qp->qpn, &qpctx )) != 0 ){
812 DBGC ( arbel, "Arbel %p RST2INIT_QPEE failed: %s\n",
813 arbel, strerror ( rc ) );
814 goto err_rst2init_qpee;
816 memset ( &qpctx, 0, sizeof ( qpctx ) );
817 MLX_FILL_2 ( &qpctx, 4,
818 qpc_eec_data.mtu, ARBEL_MTU_2048,
819 qpc_eec_data.msg_max, 11 /* 2^11 = 2048 */ );
820 if ( ( rc = arbel_cmd_init2rtr_qpee ( arbel, qp->qpn, &qpctx )) != 0 ){
821 DBGC ( arbel, "Arbel %p INIT2RTR_QPEE failed: %s\n",
822 arbel, strerror ( rc ) );
823 goto err_init2rtr_qpee;
825 memset ( &qpctx, 0, sizeof ( qpctx ) );
826 if ( ( rc = arbel_cmd_rtr2rts_qpee ( arbel, qp->qpn, &qpctx ) ) != 0 ){
827 DBGC ( arbel, "Arbel %p RTR2RTS_QPEE failed: %s\n",
828 arbel, strerror ( rc ) );
829 goto err_rtr2rts_qpee;
832 DBGC ( arbel, "Arbel %p QPN %#lx send ring at [%p,%p)\n",
833 arbel, qp->qpn, arbel_qp->send.wqe,
834 ( ( (void *) arbel_qp->send.wqe ) + arbel_qp->send.wqe_size ) );
835 DBGC ( arbel, "Arbel %p QPN %#lx receive ring at [%p,%p)\n",
836 arbel, qp->qpn, arbel_qp->recv.wqe,
837 ( ( (void *) arbel_qp->recv.wqe ) + arbel_qp->recv.wqe_size ) );
838 ib_qp_set_drvdata ( qp, arbel_qp );
839 return 0;
841 err_rtr2rts_qpee:
842 err_init2rtr_qpee:
843 arbel_cmd_2rst_qpee ( arbel, qp->qpn );
844 err_rst2init_qpee:
845 MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE );
846 MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
847 free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
848 err_create_recv_wq:
849 free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
850 err_create_send_wq:
851 free ( arbel_qp );
852 err_arbel_qp:
853 arbel_free_qn_offset ( arbel->qp_inuse, qpn_offset );
854 err_qpn_offset:
855 return rc;
859 * Modify queue pair
861 * @v ibdev Infiniband device
862 * @v qp Queue pair
863 * @v mod_list Modification list
864 * @ret rc Return status code
866 static int arbel_modify_qp ( struct ib_device *ibdev,
867 struct ib_queue_pair *qp,
868 unsigned long mod_list ) {
869 struct arbel *arbel = ib_get_drvdata ( ibdev );
870 struct arbelprm_qp_ee_state_transitions qpctx;
871 unsigned long optparammask = 0;
872 int rc;
874 /* Construct optparammask */
875 if ( mod_list & IB_MODIFY_QKEY )
876 optparammask |= ARBEL_QPEE_OPT_PARAM_QKEY;
878 /* Issue RTS2RTS_QP */
879 memset ( &qpctx, 0, sizeof ( qpctx ) );
880 MLX_FILL_1 ( &qpctx, 0, opt_param_mask, optparammask );
881 MLX_FILL_1 ( &qpctx, 44, qpc_eec_data.q_key, qp->qkey );
882 if ( ( rc = arbel_cmd_rts2rts_qp ( arbel, qp->qpn, &qpctx ) ) != 0 ){
883 DBGC ( arbel, "Arbel %p RTS2RTS_QP failed: %s\n",
884 arbel, strerror ( rc ) );
885 return rc;
888 return 0;
892 * Destroy queue pair
894 * @v ibdev Infiniband device
895 * @v qp Queue pair
897 static void arbel_destroy_qp ( struct ib_device *ibdev,
898 struct ib_queue_pair *qp ) {
899 struct arbel *arbel = ib_get_drvdata ( ibdev );
900 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
901 struct arbelprm_qp_db_record *send_db_rec;
902 struct arbelprm_qp_db_record *recv_db_rec;
903 int qpn_offset;
904 int rc;
906 /* Take ownership back from hardware */
907 if ( ( rc = arbel_cmd_2rst_qpee ( arbel, qp->qpn ) ) != 0 ) {
908 DBGC ( arbel, "Arbel %p FATAL 2RST_QPEE failed on QPN %#lx: "
909 "%s\n", arbel, qp->qpn, strerror ( rc ) );
910 /* Leak memory and return; at least we avoid corruption */
911 return;
914 /* Clear doorbell records */
915 send_db_rec = &arbel->db_rec[arbel_qp->send.doorbell_idx].qp;
916 recv_db_rec = &arbel->db_rec[arbel_qp->recv.doorbell_idx].qp;
917 MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE );
918 MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
920 /* Free memory */
921 free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
922 free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
923 free ( arbel_qp );
925 /* Mark queue number as free */
926 qpn_offset = ( qp->qpn - ARBEL_QPN_BASE - arbel->limits.reserved_qps );
927 arbel_free_qn_offset ( arbel->qp_inuse, qpn_offset );
929 ib_qp_set_drvdata ( qp, NULL );
932 /***************************************************************************
934 * Work request operations
936 ***************************************************************************
940 * Ring doorbell register in UAR
942 * @v arbel Arbel device
943 * @v db_reg Doorbell register structure
944 * @v offset Address of doorbell
946 static void arbel_ring_doorbell ( struct arbel *arbel,
947 union arbelprm_doorbell_register *db_reg,
948 unsigned int offset ) {
950 DBGC2 ( arbel, "Arbel %p ringing doorbell %08lx:%08lx at %lx\n",
951 arbel, db_reg->dword[0], db_reg->dword[1],
952 virt_to_phys ( arbel->uar + offset ) );
954 barrier();
955 writel ( db_reg->dword[0], ( arbel->uar + offset + 0 ) );
956 barrier();
957 writel ( db_reg->dword[1], ( arbel->uar + offset + 4 ) );
960 /** GID used for GID-less send work queue entries */
961 static const struct ib_gid arbel_no_gid = {
962 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0 } }
966 * Post send work queue entry
968 * @v ibdev Infiniband device
969 * @v qp Queue pair
970 * @v av Address vector
971 * @v iobuf I/O buffer
972 * @ret rc Return status code
974 static int arbel_post_send ( struct ib_device *ibdev,
975 struct ib_queue_pair *qp,
976 struct ib_address_vector *av,
977 struct io_buffer *iobuf ) {
978 struct arbel *arbel = ib_get_drvdata ( ibdev );
979 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
980 struct ib_work_queue *wq = &qp->send;
981 struct arbel_send_work_queue *arbel_send_wq = &arbel_qp->send;
982 struct arbelprm_ud_send_wqe *prev_wqe;
983 struct arbelprm_ud_send_wqe *wqe;
984 struct arbelprm_qp_db_record *qp_db_rec;
985 union arbelprm_doorbell_register db_reg;
986 const struct ib_gid *gid;
987 unsigned int wqe_idx_mask;
988 size_t nds;
990 /* Allocate work queue entry */
991 wqe_idx_mask = ( wq->num_wqes - 1 );
992 if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
993 DBGC ( arbel, "Arbel %p send queue full", arbel );
994 return -ENOBUFS;
996 wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
997 prev_wqe = &arbel_send_wq->wqe[(wq->next_idx - 1) & wqe_idx_mask].ud;
998 wqe = &arbel_send_wq->wqe[wq->next_idx & wqe_idx_mask].ud;
1000 /* Construct work queue entry */
1001 MLX_FILL_1 ( &wqe->next, 1, always1, 1 );
1002 memset ( &wqe->ctrl, 0, sizeof ( wqe->ctrl ) );
1003 MLX_FILL_1 ( &wqe->ctrl, 0, always1, 1 );
1004 memset ( &wqe->ud, 0, sizeof ( wqe->ud ) );
1005 MLX_FILL_2 ( &wqe->ud, 0,
1006 ud_address_vector.pd, ARBEL_GLOBAL_PD,
1007 ud_address_vector.port_number, ibdev->port );
1008 MLX_FILL_2 ( &wqe->ud, 1,
1009 ud_address_vector.rlid, av->dlid,
1010 ud_address_vector.g, av->gid_present );
1011 MLX_FILL_2 ( &wqe->ud, 2,
1012 ud_address_vector.max_stat_rate,
1013 ( ( av->rate >= 3 ) ? 0 : 1 ),
1014 ud_address_vector.msg, 3 );
1015 MLX_FILL_1 ( &wqe->ud, 3, ud_address_vector.sl, av->sl );
1016 gid = ( av->gid_present ? &av->gid : &arbel_no_gid );
1017 memcpy ( &wqe->ud.u.dwords[4], gid, sizeof ( *gid ) );
1018 MLX_FILL_1 ( &wqe->ud, 8, destination_qp, av->dest_qp );
1019 MLX_FILL_1 ( &wqe->ud, 9, q_key, av->qkey );
1020 MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_len ( iobuf ) );
1021 MLX_FILL_1 ( &wqe->data[0], 1, l_key, arbel->reserved_lkey );
1022 MLX_FILL_1 ( &wqe->data[0], 3,
1023 local_address_l, virt_to_bus ( iobuf->data ) );
1025 /* Update previous work queue entry's "next" field */
1026 nds = ( ( offsetof ( typeof ( *wqe ), data ) +
1027 sizeof ( wqe->data[0] ) ) >> 4 );
1028 MLX_SET ( &prev_wqe->next, nopcode, ARBEL_OPCODE_SEND );
1029 MLX_FILL_3 ( &prev_wqe->next, 1,
1030 nds, nds,
1031 f, 1,
1032 always1, 1 );
1034 /* Update doorbell record */
1035 barrier();
1036 qp_db_rec = &arbel->db_rec[arbel_send_wq->doorbell_idx].qp;
1037 MLX_FILL_1 ( qp_db_rec, 0,
1038 counter, ( ( wq->next_idx + 1 ) & 0xffff ) );
1040 /* Ring doorbell register */
1041 MLX_FILL_4 ( &db_reg.send, 0,
1042 nopcode, ARBEL_OPCODE_SEND,
1043 f, 1,
1044 wqe_counter, ( wq->next_idx & 0xffff ),
1045 wqe_cnt, 1 );
1046 MLX_FILL_2 ( &db_reg.send, 1,
1047 nds, nds,
1048 qpn, qp->qpn );
1049 arbel_ring_doorbell ( arbel, &db_reg, ARBEL_DB_POST_SND_OFFSET );
1051 /* Update work queue's index */
1052 wq->next_idx++;
1054 return 0;
1058 * Post receive work queue entry
1060 * @v ibdev Infiniband device
1061 * @v qp Queue pair
1062 * @v iobuf I/O buffer
1063 * @ret rc Return status code
1065 static int arbel_post_recv ( struct ib_device *ibdev,
1066 struct ib_queue_pair *qp,
1067 struct io_buffer *iobuf ) {
1068 struct arbel *arbel = ib_get_drvdata ( ibdev );
1069 struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1070 struct ib_work_queue *wq = &qp->recv;
1071 struct arbel_recv_work_queue *arbel_recv_wq = &arbel_qp->recv;
1072 struct arbelprm_recv_wqe *wqe;
1073 union arbelprm_doorbell_record *db_rec;
1074 unsigned int wqe_idx_mask;
1076 /* Allocate work queue entry */
1077 wqe_idx_mask = ( wq->num_wqes - 1 );
1078 if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
1079 DBGC ( arbel, "Arbel %p receive queue full", arbel );
1080 return -ENOBUFS;
1082 wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
1083 wqe = &arbel_recv_wq->wqe[wq->next_idx & wqe_idx_mask].recv;
1085 /* Construct work queue entry */
1086 MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_tailroom ( iobuf ) );
1087 MLX_FILL_1 ( &wqe->data[0], 1, l_key, arbel->reserved_lkey );
1088 MLX_FILL_1 ( &wqe->data[0], 3,
1089 local_address_l, virt_to_bus ( iobuf->data ) );
1091 /* Update doorbell record */
1092 barrier();
1093 db_rec = &arbel->db_rec[arbel_recv_wq->doorbell_idx];
1094 MLX_FILL_1 ( &db_rec->qp, 0,
1095 counter, ( ( wq->next_idx + 1 ) & 0xffff ) );
1097 /* Update work queue's index */
1098 wq->next_idx++;
1100 return 0;
1104 * Handle completion
1106 * @v ibdev Infiniband device
1107 * @v cq Completion queue
1108 * @v cqe Hardware completion queue entry
1109 * @v complete_send Send completion handler
1110 * @v complete_recv Receive completion handler
1111 * @ret rc Return status code
1113 static int arbel_complete ( struct ib_device *ibdev,
1114 struct ib_completion_queue *cq,
1115 union arbelprm_completion_entry *cqe,
1116 ib_completer_t complete_send,
1117 ib_completer_t complete_recv ) {
1118 struct arbel *arbel = ib_get_drvdata ( ibdev );
1119 struct ib_completion completion;
1120 struct ib_work_queue *wq;
1121 struct ib_queue_pair *qp;
1122 struct arbel_queue_pair *arbel_qp;
1123 struct arbel_send_work_queue *arbel_send_wq;
1124 struct arbel_recv_work_queue *arbel_recv_wq;
1125 struct arbelprm_recv_wqe *recv_wqe;
1126 struct io_buffer *iobuf;
1127 ib_completer_t complete;
1128 unsigned int opcode;
1129 unsigned long qpn;
1130 int is_send;
1131 unsigned long wqe_adr;
1132 unsigned int wqe_idx;
1133 int rc = 0;
1135 /* Parse completion */
1136 memset ( &completion, 0, sizeof ( completion ) );
1137 qpn = MLX_GET ( &cqe->normal, my_qpn );
1138 is_send = MLX_GET ( &cqe->normal, s );
1139 wqe_adr = ( MLX_GET ( &cqe->normal, wqe_adr ) << 6 );
1140 opcode = MLX_GET ( &cqe->normal, opcode );
1141 if ( opcode >= ARBEL_OPCODE_RECV_ERROR ) {
1142 /* "s" field is not valid for error opcodes */
1143 is_send = ( opcode == ARBEL_OPCODE_SEND_ERROR );
1144 completion.syndrome = MLX_GET ( &cqe->error, syndrome );
1145 DBGC ( arbel, "Arbel %p CPN %lx syndrome %x vendor %lx\n",
1146 arbel, cq->cqn, completion.syndrome,
1147 MLX_GET ( &cqe->error, vendor_code ) );
1148 rc = -EIO;
1149 /* Don't return immediately; propagate error to completer */
1152 /* Identify work queue */
1153 wq = ib_find_wq ( cq, qpn, is_send );
1154 if ( ! wq ) {
1155 DBGC ( arbel, "Arbel %p CQN %lx unknown %s QPN %lx\n",
1156 arbel, cq->cqn, ( is_send ? "send" : "recv" ), qpn );
1157 return -EIO;
1159 qp = wq->qp;
1160 arbel_qp = ib_qp_get_drvdata ( qp );
1161 arbel_send_wq = &arbel_qp->send;
1162 arbel_recv_wq = &arbel_qp->recv;
1164 /* Identify work queue entry index */
1165 if ( is_send ) {
1166 wqe_idx = ( ( wqe_adr - virt_to_bus ( arbel_send_wq->wqe ) ) /
1167 sizeof ( arbel_send_wq->wqe[0] ) );
1168 assert ( wqe_idx < qp->send.num_wqes );
1169 } else {
1170 wqe_idx = ( ( wqe_adr - virt_to_bus ( arbel_recv_wq->wqe ) ) /
1171 sizeof ( arbel_recv_wq->wqe[0] ) );
1172 assert ( wqe_idx < qp->recv.num_wqes );
1175 /* Identify I/O buffer */
1176 iobuf = wq->iobufs[wqe_idx];
1177 if ( ! iobuf ) {
1178 DBGC ( arbel, "Arbel %p CQN %lx QPN %lx empty WQE %x\n",
1179 arbel, cq->cqn, qpn, wqe_idx );
1180 return -EIO;
1182 wq->iobufs[wqe_idx] = NULL;
1184 /* Fill in length for received packets */
1185 if ( ! is_send ) {
1186 completion.len = MLX_GET ( &cqe->normal, byte_cnt );
1187 recv_wqe = &arbel_recv_wq->wqe[wqe_idx].recv;
1188 assert ( MLX_GET ( &recv_wqe->data[0], local_address_l ) ==
1189 virt_to_bus ( iobuf->data ) );
1190 assert ( MLX_GET ( &recv_wqe->data[0], byte_count ) ==
1191 iob_tailroom ( iobuf ) );
1192 MLX_FILL_1 ( &recv_wqe->data[0], 0, byte_count, 0 );
1193 MLX_FILL_1 ( &recv_wqe->data[0], 1,
1194 l_key, ARBEL_INVALID_LKEY );
1195 if ( completion.len > iob_tailroom ( iobuf ) ) {
1196 DBGC ( arbel, "Arbel %p CQN %lx QPN %lx IDX %x "
1197 "overlength received packet length %zd\n",
1198 arbel, cq->cqn, qpn, wqe_idx, completion.len );
1199 return -EIO;
1203 /* Pass off to caller's completion handler */
1204 complete = ( is_send ? complete_send : complete_recv );
1205 complete ( ibdev, qp, &completion, iobuf );
1207 return rc;
1211 * Poll completion queue
1213 * @v ibdev Infiniband device
1214 * @v cq Completion queue
1215 * @v complete_send Send completion handler
1216 * @v complete_recv Receive completion handler
1218 static void arbel_poll_cq ( struct ib_device *ibdev,
1219 struct ib_completion_queue *cq,
1220 ib_completer_t complete_send,
1221 ib_completer_t complete_recv ) {
1222 struct arbel *arbel = ib_get_drvdata ( ibdev );
1223 struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
1224 struct arbelprm_cq_ci_db_record *ci_db_rec;
1225 union arbelprm_completion_entry *cqe;
1226 unsigned int cqe_idx_mask;
1227 int rc;
1229 while ( 1 ) {
1230 /* Look for completion entry */
1231 cqe_idx_mask = ( cq->num_cqes - 1 );
1232 cqe = &arbel_cq->cqe[cq->next_idx & cqe_idx_mask];
1233 if ( MLX_GET ( &cqe->normal, owner ) != 0 ) {
1234 /* Entry still owned by hardware; end of poll */
1235 break;
1238 /* Handle completion */
1239 if ( ( rc = arbel_complete ( ibdev, cq, cqe, complete_send,
1240 complete_recv ) ) != 0 ) {
1241 DBGC ( arbel, "Arbel %p failed to complete: %s\n",
1242 arbel, strerror ( rc ) );
1243 DBGC_HD ( arbel, cqe, sizeof ( *cqe ) );
1246 /* Return ownership to hardware */
1247 MLX_FILL_1 ( &cqe->normal, 7, owner, 1 );
1248 barrier();
1249 /* Update completion queue's index */
1250 cq->next_idx++;
1251 /* Update doorbell record */
1252 ci_db_rec = &arbel->db_rec[arbel_cq->ci_doorbell_idx].cq_ci;
1253 MLX_FILL_1 ( ci_db_rec, 0,
1254 counter, ( cq->next_idx & 0xffffffffUL ) );
1258 /***************************************************************************
1260 * Event queues
1262 ***************************************************************************
1266 * Create event queue
1268 * @v arbel Arbel device
1269 * @ret rc Return status code
1271 static int arbel_create_eq ( struct arbel *arbel ) {
1272 struct arbel_event_queue *arbel_eq = &arbel->eq;
1273 struct arbelprm_eqc eqctx;
1274 struct arbelprm_event_mask mask;
1275 unsigned int i;
1276 int rc;
1278 /* Select event queue number */
1279 arbel_eq->eqn = arbel->limits.reserved_eqs;
1281 /* Calculate doorbell address */
1282 arbel_eq->doorbell = ( arbel->eq_ci_doorbells +
1283 ARBEL_DB_EQ_OFFSET ( arbel_eq->eqn ) );
1285 /* Allocate event queue itself */
1286 arbel_eq->eqe_size =
1287 ( ARBEL_NUM_EQES * sizeof ( arbel_eq->eqe[0] ) );
1288 arbel_eq->eqe = malloc_dma ( arbel_eq->eqe_size,
1289 sizeof ( arbel_eq->eqe[0] ) );
1290 if ( ! arbel_eq->eqe ) {
1291 rc = -ENOMEM;
1292 goto err_eqe;
1294 memset ( arbel_eq->eqe, 0, arbel_eq->eqe_size );
1295 for ( i = 0 ; i < ARBEL_NUM_EQES ; i++ ) {
1296 MLX_FILL_1 ( &arbel_eq->eqe[i].generic, 7, owner, 1 );
1298 barrier();
1300 /* Hand queue over to hardware */
1301 memset ( &eqctx, 0, sizeof ( eqctx ) );
1302 MLX_FILL_1 ( &eqctx, 0, st, 0xa /* "Fired" */ );
1303 MLX_FILL_1 ( &eqctx, 2,
1304 start_address_l, virt_to_phys ( arbel_eq->eqe ) );
1305 MLX_FILL_1 ( &eqctx, 3, log_eq_size, fls ( ARBEL_NUM_EQES - 1 ) );
1306 MLX_FILL_1 ( &eqctx, 6, pd, ARBEL_GLOBAL_PD );
1307 MLX_FILL_1 ( &eqctx, 7, lkey, arbel->reserved_lkey );
1308 if ( ( rc = arbel_cmd_sw2hw_eq ( arbel, arbel_eq->eqn,
1309 &eqctx ) ) != 0 ) {
1310 DBGC ( arbel, "Arbel %p SW2HW_EQ failed: %s\n",
1311 arbel, strerror ( rc ) );
1312 goto err_sw2hw_eq;
1315 /* Map events to this event queue */
1316 memset ( &mask, 0, sizeof ( mask ) );
1317 MLX_FILL_1 ( &mask, 1, port_state_change, 1 );
1318 if ( ( rc = arbel_cmd_map_eq ( arbel,
1319 ( ARBEL_MAP_EQ | arbel_eq->eqn ),
1320 &mask ) ) != 0 ) {
1321 DBGC ( arbel, "Arbel %p MAP_EQ failed: %s\n",
1322 arbel, strerror ( rc ) );
1323 goto err_map_eq;
1326 DBGC ( arbel, "Arbel %p EQN %#lx ring at [%p,%p])\n",
1327 arbel, arbel_eq->eqn, arbel_eq->eqe,
1328 ( ( ( void * ) arbel_eq->eqe ) + arbel_eq->eqe_size ) );
1329 return 0;
1331 err_map_eq:
1332 arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn, &eqctx );
1333 err_sw2hw_eq:
1334 free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
1335 err_eqe:
1336 memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
1337 return rc;
1341 * Destroy event queue
1343 * @v arbel Arbel device
1345 static void arbel_destroy_eq ( struct arbel *arbel ) {
1346 struct arbel_event_queue *arbel_eq = &arbel->eq;
1347 struct arbelprm_eqc eqctx;
1348 struct arbelprm_event_mask mask;
1349 int rc;
1351 /* Unmap events from event queue */
1352 memset ( &mask, 0, sizeof ( mask ) );
1353 MLX_FILL_1 ( &mask, 1, port_state_change, 1 );
1354 if ( ( rc = arbel_cmd_map_eq ( arbel,
1355 ( ARBEL_UNMAP_EQ | arbel_eq->eqn ),
1356 &mask ) ) != 0 ) {
1357 DBGC ( arbel, "Arbel %p FATAL MAP_EQ failed to unmap: %s\n",
1358 arbel, strerror ( rc ) );
1359 /* Continue; HCA may die but system should survive */
1362 /* Take ownership back from hardware */
1363 if ( ( rc = arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn,
1364 &eqctx ) ) != 0 ) {
1365 DBGC ( arbel, "Arbel %p FATAL HW2SW_EQ failed: %s\n",
1366 arbel, strerror ( rc ) );
1367 /* Leak memory and return; at least we avoid corruption */
1368 return;
1371 /* Free memory */
1372 free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
1373 memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
1377 * Handle port state event
1379 * @v arbel Arbel device
1380 * @v eqe Port state change event queue entry
1382 static void arbel_event_port_state_change ( struct arbel *arbel,
1383 union arbelprm_event_entry *eqe){
1384 unsigned int port;
1385 int link_up;
1387 /* Get port and link status */
1388 port = ( MLX_GET ( &eqe->port_state_change, data.p ) - 1 );
1389 link_up = ( MLX_GET ( &eqe->generic, event_sub_type ) & 0x04 );
1390 DBGC ( arbel, "Arbel %p port %d link %s\n", arbel, ( port + 1 ),
1391 ( link_up ? "up" : "down" ) );
1393 /* Sanity check */
1394 if ( port >= ARBEL_NUM_PORTS ) {
1395 DBGC ( arbel, "Arbel %p port %d does not exist!\n",
1396 arbel, ( port + 1 ) );
1397 return;
1400 /* Notify Infiniband core of link state change */
1401 ib_link_state_changed ( arbel->ibdev[port] );
1405 * Poll event queue
1407 * @v ibdev Infiniband device
1409 static void arbel_poll_eq ( struct ib_device *ibdev ) {
1410 struct arbel *arbel = ib_get_drvdata ( ibdev );
1411 struct arbel_event_queue *arbel_eq = &arbel->eq;
1412 union arbelprm_event_entry *eqe;
1413 union arbelprm_eq_doorbell_register db_reg;
1414 unsigned int eqe_idx_mask;
1415 unsigned int event_type;
1417 while ( 1 ) {
1418 /* Look for event entry */
1419 eqe_idx_mask = ( ARBEL_NUM_EQES - 1 );
1420 eqe = &arbel_eq->eqe[arbel_eq->next_idx & eqe_idx_mask];
1421 if ( MLX_GET ( &eqe->generic, owner ) != 0 ) {
1422 /* Entry still owned by hardware; end of poll */
1423 break;
1425 DBGCP ( arbel, "Arbel %p event:\n", arbel );
1426 DBGCP_HD ( arbel, eqe, sizeof ( *eqe ) );
1428 /* Handle event */
1429 event_type = MLX_GET ( &eqe->generic, event_type );
1430 switch ( event_type ) {
1431 case ARBEL_EV_PORT_STATE_CHANGE:
1432 arbel_event_port_state_change ( arbel, eqe );
1433 break;
1434 default:
1435 DBGC ( arbel, "Arbel %p unrecognised event type "
1436 "%#x:\n", arbel, event_type );
1437 DBGC_HD ( arbel, eqe, sizeof ( *eqe ) );
1438 break;
1441 /* Return ownership to hardware */
1442 MLX_FILL_1 ( &eqe->generic, 7, owner, 1 );
1443 barrier();
1445 /* Update event queue's index */
1446 arbel_eq->next_idx++;
1448 /* Ring doorbell */
1449 MLX_FILL_1 ( &db_reg.ci, 0, ci, arbel_eq->next_idx );
1450 DBGCP ( arbel, "Ringing doorbell %08lx with %08lx\n",
1451 virt_to_phys ( arbel_eq->doorbell ),
1452 db_reg.dword[0] );
1453 writel ( db_reg.dword[0], arbel_eq->doorbell );
1457 /***************************************************************************
1459 * Infiniband link-layer operations
1461 ***************************************************************************
1465 * Initialise Infiniband link
1467 * @v ibdev Infiniband device
1468 * @ret rc Return status code
1470 static int arbel_open ( struct ib_device *ibdev ) {
1471 struct arbel *arbel = ib_get_drvdata ( ibdev );
1472 struct arbelprm_init_ib init_ib;
1473 int rc;
1475 memset ( &init_ib, 0, sizeof ( init_ib ) );
1476 MLX_FILL_3 ( &init_ib, 0,
1477 mtu_cap, ARBEL_MTU_2048,
1478 port_width_cap, 3,
1479 vl_cap, 1 );
1480 MLX_FILL_1 ( &init_ib, 1, max_gid, 1 );
1481 MLX_FILL_1 ( &init_ib, 2, max_pkey, 64 );
1482 if ( ( rc = arbel_cmd_init_ib ( arbel, ibdev->port,
1483 &init_ib ) ) != 0 ) {
1484 DBGC ( arbel, "Arbel %p could not intialise IB: %s\n",
1485 arbel, strerror ( rc ) );
1486 return rc;
1489 return 0;
1493 * Close Infiniband link
1495 * @v ibdev Infiniband device
1497 static void arbel_close ( struct ib_device *ibdev ) {
1498 struct arbel *arbel = ib_get_drvdata ( ibdev );
1499 int rc;
1501 if ( ( rc = arbel_cmd_close_ib ( arbel, ibdev->port ) ) != 0 ) {
1502 DBGC ( arbel, "Arbel %p could not close IB: %s\n",
1503 arbel, strerror ( rc ) );
1504 /* Nothing we can do about this */
1508 /***************************************************************************
1510 * Multicast group operations
1512 ***************************************************************************
1516 * Attach to multicast group
1518 * @v ibdev Infiniband device
1519 * @v qp Queue pair
1520 * @v gid Multicast GID
1521 * @ret rc Return status code
1523 static int arbel_mcast_attach ( struct ib_device *ibdev,
1524 struct ib_queue_pair *qp,
1525 struct ib_gid *gid ) {
1526 struct arbel *arbel = ib_get_drvdata ( ibdev );
1527 struct arbelprm_mgm_hash hash;
1528 struct arbelprm_mgm_entry mgm;
1529 unsigned int index;
1530 int rc;
1532 /* Generate hash table index */
1533 if ( ( rc = arbel_cmd_mgid_hash ( arbel, gid, &hash ) ) != 0 ) {
1534 DBGC ( arbel, "Arbel %p could not hash GID: %s\n",
1535 arbel, strerror ( rc ) );
1536 return rc;
1538 index = MLX_GET ( &hash, hash );
1540 /* Check for existing hash table entry */
1541 if ( ( rc = arbel_cmd_read_mgm ( arbel, index, &mgm ) ) != 0 ) {
1542 DBGC ( arbel, "Arbel %p could not read MGM %#x: %s\n",
1543 arbel, index, strerror ( rc ) );
1544 return rc;
1546 if ( MLX_GET ( &mgm, mgmqp_0.qi ) != 0 ) {
1547 /* FIXME: this implementation allows only a single QP
1548 * per multicast group, and doesn't handle hash
1549 * collisions. Sufficient for IPoIB but may need to
1550 * be extended in future.
1552 DBGC ( arbel, "Arbel %p MGID index %#x already in use\n",
1553 arbel, index );
1554 return -EBUSY;
1557 /* Update hash table entry */
1558 MLX_FILL_2 ( &mgm, 8,
1559 mgmqp_0.qpn_i, qp->qpn,
1560 mgmqp_0.qi, 1 );
1561 memcpy ( &mgm.u.dwords[4], gid, sizeof ( *gid ) );
1562 if ( ( rc = arbel_cmd_write_mgm ( arbel, index, &mgm ) ) != 0 ) {
1563 DBGC ( arbel, "Arbel %p could not write MGM %#x: %s\n",
1564 arbel, index, strerror ( rc ) );
1565 return rc;
1568 return 0;
1572 * Detach from multicast group
1574 * @v ibdev Infiniband device
1575 * @v qp Queue pair
1576 * @v gid Multicast GID
1578 static void arbel_mcast_detach ( struct ib_device *ibdev,
1579 struct ib_queue_pair *qp __unused,
1580 struct ib_gid *gid ) {
1581 struct arbel *arbel = ib_get_drvdata ( ibdev );
1582 struct arbelprm_mgm_hash hash;
1583 struct arbelprm_mgm_entry mgm;
1584 unsigned int index;
1585 int rc;
1587 /* Generate hash table index */
1588 if ( ( rc = arbel_cmd_mgid_hash ( arbel, gid, &hash ) ) != 0 ) {
1589 DBGC ( arbel, "Arbel %p could not hash GID: %s\n",
1590 arbel, strerror ( rc ) );
1591 return;
1593 index = MLX_GET ( &hash, hash );
1595 /* Clear hash table entry */
1596 memset ( &mgm, 0, sizeof ( mgm ) );
1597 if ( ( rc = arbel_cmd_write_mgm ( arbel, index, &mgm ) ) != 0 ) {
1598 DBGC ( arbel, "Arbel %p could not write MGM %#x: %s\n",
1599 arbel, index, strerror ( rc ) );
1600 return;
1604 /***************************************************************************
1606 * MAD operations
1608 ***************************************************************************
1612 * Issue management datagram
1614 * @v ibdev Infiniband device
1615 * @v mad Management datagram
1616 * @v len Length of management datagram
1617 * @ret rc Return status code
1619 static int arbel_mad ( struct ib_device *ibdev, struct ib_mad_hdr *mad,
1620 size_t len ) {
1621 struct arbel *arbel = ib_get_drvdata ( ibdev );
1622 union arbelprm_mad mad_ifc;
1623 int rc;
1625 /* Copy in request packet */
1626 memset ( &mad_ifc, 0, sizeof ( mad_ifc ) );
1627 assert ( len <= sizeof ( mad_ifc.mad ) );
1628 memcpy ( &mad_ifc.mad, mad, len );
1630 /* Issue MAD */
1631 if ( ( rc = arbel_cmd_mad_ifc ( arbel, ibdev->port,
1632 &mad_ifc ) ) != 0 ) {
1633 DBGC ( arbel, "Arbel %p could not issue MAD IFC: %s\n",
1634 arbel, strerror ( rc ) );
1635 return rc;
1638 /* Copy out reply packet */
1639 memcpy ( mad, &mad_ifc.mad, len );
1641 if ( mad->status != 0 ) {
1642 DBGC ( arbel, "Arbel %p MAD IFC status %04x\n",
1643 arbel, ntohs ( mad->status ) );
1644 return -EIO;
1646 return 0;
1649 /** Arbel Infiniband operations */
1650 static struct ib_device_operations arbel_ib_operations = {
1651 .create_cq = arbel_create_cq,
1652 .destroy_cq = arbel_destroy_cq,
1653 .create_qp = arbel_create_qp,
1654 .modify_qp = arbel_modify_qp,
1655 .destroy_qp = arbel_destroy_qp,
1656 .post_send = arbel_post_send,
1657 .post_recv = arbel_post_recv,
1658 .poll_cq = arbel_poll_cq,
1659 .poll_eq = arbel_poll_eq,
1660 .open = arbel_open,
1661 .close = arbel_close,
1662 .mcast_attach = arbel_mcast_attach,
1663 .mcast_detach = arbel_mcast_detach,
1664 .mad = arbel_mad,
1667 /***************************************************************************
1669 * Firmware control
1671 ***************************************************************************
1675 * Start firmware running
1677 * @v arbel Arbel device
1678 * @ret rc Return status code
1680 static int arbel_start_firmware ( struct arbel *arbel ) {
1681 struct arbelprm_query_fw fw;
1682 struct arbelprm_access_lam lam;
1683 struct arbelprm_virtual_physical_mapping map_fa;
1684 unsigned int fw_pages;
1685 unsigned int log2_fw_pages;
1686 size_t fw_size;
1687 physaddr_t fw_base;
1688 uint64_t eq_set_ci_base_addr;
1689 int rc;
1691 /* Get firmware parameters */
1692 if ( ( rc = arbel_cmd_query_fw ( arbel, &fw ) ) != 0 ) {
1693 DBGC ( arbel, "Arbel %p could not query firmware: %s\n",
1694 arbel, strerror ( rc ) );
1695 goto err_query_fw;
1697 DBGC ( arbel, "Arbel %p firmware version %ld.%ld.%ld\n", arbel,
1698 MLX_GET ( &fw, fw_rev_major ), MLX_GET ( &fw, fw_rev_minor ),
1699 MLX_GET ( &fw, fw_rev_subminor ) );
1700 fw_pages = MLX_GET ( &fw, fw_pages );
1701 log2_fw_pages = fls ( fw_pages - 1 );
1702 fw_pages = ( 1 << log2_fw_pages );
1703 DBGC ( arbel, "Arbel %p requires %d kB for firmware\n",
1704 arbel, ( fw_pages * 4 ) );
1705 eq_set_ci_base_addr =
1706 ( ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_h ) << 32 ) |
1707 ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_l ) ) );
1708 arbel->eq_ci_doorbells = ioremap ( eq_set_ci_base_addr, 0x200 );
1710 /* Enable locally-attached memory. Ignore failure; there may
1711 * be no attached memory.
1713 arbel_cmd_enable_lam ( arbel, &lam );
1715 /* Allocate firmware pages and map firmware area */
1716 fw_size = ( fw_pages * 4096 );
1717 arbel->firmware_area = umalloc ( fw_size * 2 );
1718 if ( ! arbel->firmware_area ) {
1719 rc = -ENOMEM;
1720 goto err_alloc_fa;
1722 fw_base = ( user_to_phys ( arbel->firmware_area, fw_size ) &
1723 ~( fw_size - 1 ) );
1724 DBGC ( arbel, "Arbel %p firmware area at physical [%lx,%lx)\n",
1725 arbel, fw_base, ( fw_base + fw_size ) );
1726 memset ( &map_fa, 0, sizeof ( map_fa ) );
1727 MLX_FILL_2 ( &map_fa, 3,
1728 log2size, log2_fw_pages,
1729 pa_l, ( fw_base >> 12 ) );
1730 if ( ( rc = arbel_cmd_map_fa ( arbel, &map_fa ) ) != 0 ) {
1731 DBGC ( arbel, "Arbel %p could not map firmware: %s\n",
1732 arbel, strerror ( rc ) );
1733 goto err_map_fa;
1736 /* Start firmware */
1737 if ( ( rc = arbel_cmd_run_fw ( arbel ) ) != 0 ) {
1738 DBGC ( arbel, "Arbel %p could not run firmware: %s\n",
1739 arbel, strerror ( rc ) );
1740 goto err_run_fw;
1743 DBGC ( arbel, "Arbel %p firmware started\n", arbel );
1744 return 0;
1746 err_run_fw:
1747 arbel_cmd_unmap_fa ( arbel );
1748 err_map_fa:
1749 ufree ( arbel->firmware_area );
1750 arbel->firmware_area = UNULL;
1751 err_alloc_fa:
1752 err_query_fw:
1753 return rc;
1757 * Stop firmware running
1759 * @v arbel Arbel device
1761 static void arbel_stop_firmware ( struct arbel *arbel ) {
1762 int rc;
1764 if ( ( rc = arbel_cmd_unmap_fa ( arbel ) ) != 0 ) {
1765 DBGC ( arbel, "Arbel %p FATAL could not stop firmware: %s\n",
1766 arbel, strerror ( rc ) );
1767 /* Leak memory and return; at least we avoid corruption */
1768 return;
1770 ufree ( arbel->firmware_area );
1771 arbel->firmware_area = UNULL;
1774 /***************************************************************************
1776 * Infinihost Context Memory management
1778 ***************************************************************************
1782 * Get device limits
1784 * @v arbel Arbel device
1785 * @ret rc Return status code
1787 static int arbel_get_limits ( struct arbel *arbel ) {
1788 struct arbelprm_query_dev_lim dev_lim;
1789 int rc;
1791 if ( ( rc = arbel_cmd_query_dev_lim ( arbel, &dev_lim ) ) != 0 ) {
1792 DBGC ( arbel, "Arbel %p could not get device limits: %s\n",
1793 arbel, strerror ( rc ) );
1794 return rc;
1797 arbel->limits.reserved_qps =
1798 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_qps ) );
1799 arbel->limits.qpc_entry_size = MLX_GET ( &dev_lim, qpc_entry_sz );
1800 arbel->limits.eqpc_entry_size = MLX_GET ( &dev_lim, eqpc_entry_sz );
1801 arbel->limits.reserved_srqs =
1802 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_srqs ) );
1803 arbel->limits.srqc_entry_size = MLX_GET ( &dev_lim, srq_entry_sz );
1804 arbel->limits.reserved_ees =
1805 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_ees ) );
1806 arbel->limits.eec_entry_size = MLX_GET ( &dev_lim, eec_entry_sz );
1807 arbel->limits.eeec_entry_size = MLX_GET ( &dev_lim, eeec_entry_sz );
1808 arbel->limits.reserved_cqs =
1809 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_cqs ) );
1810 arbel->limits.cqc_entry_size = MLX_GET ( &dev_lim, cqc_entry_sz );
1811 arbel->limits.reserved_eqs = MLX_GET ( &dev_lim, num_rsvd_eqs );
1812 arbel->limits.reserved_mtts =
1813 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_mtts ) );
1814 arbel->limits.mtt_entry_size = MLX_GET ( &dev_lim, mtt_entry_sz );
1815 arbel->limits.reserved_mrws =
1816 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_mrws ) );
1817 arbel->limits.mpt_entry_size = MLX_GET ( &dev_lim, mpt_entry_sz );
1818 arbel->limits.reserved_rdbs =
1819 ( 1 << MLX_GET ( &dev_lim, log2_rsvd_rdbs ) );
1820 arbel->limits.eqc_entry_size = MLX_GET ( &dev_lim, eqc_entry_sz );
1821 arbel->limits.reserved_uars = MLX_GET ( &dev_lim, num_rsvd_uars );
1823 return 0;
1827 * Get ICM usage
1829 * @v log_num_entries Log2 of the number of entries
1830 * @v entry_size Entry size
1831 * @ret usage Usage size in ICM
1833 static size_t icm_usage ( unsigned int log_num_entries, size_t entry_size ) {
1834 size_t usage;
1836 usage = ( ( 1 << log_num_entries ) * entry_size );
1837 usage = ( ( usage + 4095 ) & ~4095 );
1838 return usage;
1842 * Allocate ICM
1844 * @v arbel Arbel device
1845 * @v init_hca INIT_HCA structure to fill in
1846 * @ret rc Return status code
1848 static int arbel_alloc_icm ( struct arbel *arbel,
1849 struct arbelprm_init_hca *init_hca ) {
1850 struct arbelprm_scalar_parameter icm_size;
1851 struct arbelprm_scalar_parameter icm_aux_size;
1852 struct arbelprm_virtual_physical_mapping map_icm_aux;
1853 struct arbelprm_virtual_physical_mapping map_icm;
1854 union arbelprm_doorbell_record *db_rec;
1855 size_t icm_offset = 0;
1856 unsigned int log_num_qps, log_num_srqs, log_num_ees, log_num_cqs;
1857 unsigned int log_num_mtts, log_num_mpts, log_num_rdbs, log_num_eqs;
1858 int rc;
1860 icm_offset = ( ( arbel->limits.reserved_uars + 1 ) << 12 );
1862 /* Queue pair contexts */
1863 log_num_qps = fls ( arbel->limits.reserved_qps + ARBEL_MAX_QPS - 1 );
1864 MLX_FILL_2 ( init_hca, 13,
1865 qpc_eec_cqc_eqc_rdb_parameters.qpc_base_addr_l,
1866 ( icm_offset >> 7 ),
1867 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_qp,
1868 log_num_qps );
1869 DBGC ( arbel, "Arbel %p ICM QPC base = %zx\n", arbel, icm_offset );
1870 icm_offset += icm_usage ( log_num_qps, arbel->limits.qpc_entry_size );
1872 /* Extended queue pair contexts */
1873 MLX_FILL_1 ( init_hca, 25,
1874 qpc_eec_cqc_eqc_rdb_parameters.eqpc_base_addr_l,
1875 icm_offset );
1876 DBGC ( arbel, "Arbel %p ICM EQPC base = %zx\n", arbel, icm_offset );
1877 // icm_offset += icm_usage ( log_num_qps, arbel->limits.eqpc_entry_size );
1878 icm_offset += icm_usage ( log_num_qps, arbel->limits.qpc_entry_size );
1880 /* Shared receive queue contexts */
1881 log_num_srqs = fls ( arbel->limits.reserved_srqs - 1 );
1882 MLX_FILL_2 ( init_hca, 19,
1883 qpc_eec_cqc_eqc_rdb_parameters.srqc_base_addr_l,
1884 ( icm_offset >> 5 ),
1885 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_srq,
1886 log_num_srqs );
1887 DBGC ( arbel, "Arbel %p ICM SRQC base = %zx\n", arbel, icm_offset );
1888 icm_offset += icm_usage ( log_num_srqs, arbel->limits.srqc_entry_size );
1890 /* End-to-end contexts */
1891 log_num_ees = fls ( arbel->limits.reserved_ees - 1 );
1892 MLX_FILL_2 ( init_hca, 17,
1893 qpc_eec_cqc_eqc_rdb_parameters.eec_base_addr_l,
1894 ( icm_offset >> 7 ),
1895 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_ee,
1896 log_num_ees );
1897 DBGC ( arbel, "Arbel %p ICM EEC base = %zx\n", arbel, icm_offset );
1898 icm_offset += icm_usage ( log_num_ees, arbel->limits.eec_entry_size );
1900 /* Extended end-to-end contexts */
1901 MLX_FILL_1 ( init_hca, 29,
1902 qpc_eec_cqc_eqc_rdb_parameters.eeec_base_addr_l,
1903 icm_offset );
1904 DBGC ( arbel, "Arbel %p ICM EEEC base = %zx\n", arbel, icm_offset );
1905 icm_offset += icm_usage ( log_num_ees, arbel->limits.eeec_entry_size );
1907 /* Completion queue contexts */
1908 log_num_cqs = fls ( arbel->limits.reserved_cqs + ARBEL_MAX_CQS - 1 );
1909 MLX_FILL_2 ( init_hca, 21,
1910 qpc_eec_cqc_eqc_rdb_parameters.cqc_base_addr_l,
1911 ( icm_offset >> 6 ),
1912 qpc_eec_cqc_eqc_rdb_parameters.log_num_of_cq,
1913 log_num_cqs );
1914 DBGC ( arbel, "Arbel %p ICM CQC base = %zx\n", arbel, icm_offset );
1915 icm_offset += icm_usage ( log_num_cqs, arbel->limits.cqc_entry_size );
1917 /* Memory translation table */
1918 log_num_mtts = fls ( arbel->limits.reserved_mtts - 1 );
1919 MLX_FILL_1 ( init_hca, 65,
1920 tpt_parameters.mtt_base_addr_l, icm_offset );
1921 DBGC ( arbel, "Arbel %p ICM MTT base = %zx\n", arbel, icm_offset );
1922 icm_offset += icm_usage ( log_num_mtts, arbel->limits.mtt_entry_size );
1924 /* Memory protection table */
1925 log_num_mpts = fls ( arbel->limits.reserved_mrws + 1 - 1 );
1926 MLX_FILL_1 ( init_hca, 61,
1927 tpt_parameters.mpt_base_adr_l, icm_offset );
1928 MLX_FILL_1 ( init_hca, 62,
1929 tpt_parameters.log_mpt_sz, log_num_mpts );
1930 DBGC ( arbel, "Arbel %p ICM MTT base = %zx\n", arbel, icm_offset );
1931 icm_offset += icm_usage ( log_num_mpts, arbel->limits.mpt_entry_size );
1933 /* RDMA something or other */
1934 log_num_rdbs = fls ( arbel->limits.reserved_rdbs - 1 );
1935 MLX_FILL_1 ( init_hca, 37,
1936 qpc_eec_cqc_eqc_rdb_parameters.rdb_base_addr_l,
1937 icm_offset );
1938 DBGC ( arbel, "Arbel %p ICM RDB base = %zx\n", arbel, icm_offset );
1939 icm_offset += icm_usage ( log_num_rdbs, 32 );
1941 /* Event queue contexts */
1942 log_num_eqs = fls ( arbel->limits.reserved_eqs + ARBEL_MAX_EQS - 1 );
1943 MLX_FILL_2 ( init_hca, 33,
1944 qpc_eec_cqc_eqc_rdb_parameters.eqc_base_addr_l,
1945 ( icm_offset >> 6 ),
1946 qpc_eec_cqc_eqc_rdb_parameters.log_num_eq,
1947 log_num_eqs );
1948 DBGC ( arbel, "Arbel %p ICM EQ base = %zx\n", arbel, icm_offset );
1949 icm_offset += ( ( 1 << log_num_eqs ) * arbel->limits.eqc_entry_size );
1951 /* Multicast table */
1952 MLX_FILL_1 ( init_hca, 49,
1953 multicast_parameters.mc_base_addr_l, icm_offset );
1954 MLX_FILL_1 ( init_hca, 52,
1955 multicast_parameters.log_mc_table_entry_sz,
1956 fls ( sizeof ( struct arbelprm_mgm_entry ) - 1 ) );
1957 MLX_FILL_1 ( init_hca, 53,
1958 multicast_parameters.mc_table_hash_sz, 8 );
1959 MLX_FILL_1 ( init_hca, 54,
1960 multicast_parameters.log_mc_table_sz, 3 );
1961 DBGC ( arbel, "Arbel %p ICM MC base = %zx\n", arbel, icm_offset );
1962 icm_offset += ( 8 * sizeof ( struct arbelprm_mgm_entry ) );
1964 arbel->icm_len = icm_offset;
1965 arbel->icm_len = ( ( arbel->icm_len + 4095 ) & ~4095 );
1967 /* Get ICM auxiliary area size */
1968 memset ( &icm_size, 0, sizeof ( icm_size ) );
1969 MLX_FILL_1 ( &icm_size, 1, value, arbel->icm_len );
1970 if ( ( rc = arbel_cmd_set_icm_size ( arbel, &icm_size,
1971 &icm_aux_size ) ) != 0 ) {
1972 DBGC ( arbel, "Arbel %p could not set ICM size: %s\n",
1973 arbel, strerror ( rc ) );
1974 goto err_set_icm_size;
1976 arbel->icm_aux_len = ( MLX_GET ( &icm_aux_size, value ) * 4096 );
1978 /* Allocate ICM data and auxiliary area */
1979 DBGC ( arbel, "Arbel %p requires %zd kB ICM and %zd kB AUX ICM\n",
1980 arbel, ( arbel->icm_len / 1024 ),
1981 ( arbel->icm_aux_len / 1024 ) );
1982 arbel->icm = umalloc ( arbel->icm_len + arbel->icm_aux_len );
1983 if ( ! arbel->icm ) {
1984 rc = -ENOMEM;
1985 goto err_alloc;
1988 /* Map ICM auxiliary area */
1989 memset ( &map_icm_aux, 0, sizeof ( map_icm_aux ) );
1990 MLX_FILL_2 ( &map_icm_aux, 3,
1991 log2size, fls ( ( arbel->icm_aux_len / 4096 ) - 1 ),
1992 pa_l,
1993 ( user_to_phys ( arbel->icm, arbel->icm_len ) >> 12 ) );
1994 if ( ( rc = arbel_cmd_map_icm_aux ( arbel, &map_icm_aux ) ) != 0 ) {
1995 DBGC ( arbel, "Arbel %p could not map AUX ICM: %s\n",
1996 arbel, strerror ( rc ) );
1997 goto err_map_icm_aux;
2000 /* MAP ICM area */
2001 memset ( &map_icm, 0, sizeof ( map_icm ) );
2002 MLX_FILL_2 ( &map_icm, 3,
2003 log2size, fls ( ( arbel->icm_len / 4096 ) - 1 ),
2004 pa_l, ( user_to_phys ( arbel->icm, 0 ) >> 12 ) );
2005 if ( ( rc = arbel_cmd_map_icm ( arbel, &map_icm ) ) != 0 ) {
2006 DBGC ( arbel, "Arbel %p could not map ICM: %s\n",
2007 arbel, strerror ( rc ) );
2008 goto err_map_icm;
2011 /* Initialise UAR context */
2012 arbel->db_rec = phys_to_virt ( user_to_phys ( arbel->icm, 0 ) +
2013 ( arbel->limits.reserved_uars *
2014 ARBEL_PAGE_SIZE ) );
2015 memset ( arbel->db_rec, 0, ARBEL_PAGE_SIZE );
2016 db_rec = &arbel->db_rec[ARBEL_GROUP_SEPARATOR_DOORBELL];
2017 MLX_FILL_1 ( &db_rec->qp, 1, res, ARBEL_UAR_RES_GROUP_SEP );
2019 return 0;
2021 arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / 4096 ) );
2022 err_map_icm:
2023 arbel_cmd_unmap_icm_aux ( arbel );
2024 err_map_icm_aux:
2025 ufree ( arbel->icm );
2026 arbel->icm = UNULL;
2027 err_alloc:
2028 err_set_icm_size:
2029 return rc;
2033 * Free ICM
2035 * @v arbel Arbel device
2037 static void arbel_free_icm ( struct arbel *arbel ) {
2038 arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / 4096 ) );
2039 arbel_cmd_unmap_icm_aux ( arbel );
2040 ufree ( arbel->icm );
2041 arbel->icm = UNULL;
2044 /***************************************************************************
2046 * PCI interface
2048 ***************************************************************************
2052 * Set up memory protection table
2054 * @v arbel Arbel device
2055 * @ret rc Return status code
2057 static int arbel_setup_mpt ( struct arbel *arbel ) {
2058 struct arbelprm_mpt mpt;
2059 uint32_t key;
2060 int rc;
2062 /* Derive key */
2063 key = ( arbel->limits.reserved_mrws | ARBEL_MKEY_PREFIX );
2064 arbel->reserved_lkey = ( ( key << 8 ) | ( key >> 24 ) );
2066 /* Initialise memory protection table */
2067 memset ( &mpt, 0, sizeof ( mpt ) );
2068 MLX_FILL_4 ( &mpt, 0,
2069 r_w, 1,
2070 pa, 1,
2071 lr, 1,
2072 lw, 1 );
2073 MLX_FILL_1 ( &mpt, 2, mem_key, key );
2074 MLX_FILL_1 ( &mpt, 3, pd, ARBEL_GLOBAL_PD );
2075 MLX_FILL_1 ( &mpt, 6, reg_wnd_len_h, 0xffffffffUL );
2076 MLX_FILL_1 ( &mpt, 7, reg_wnd_len_l, 0xffffffffUL );
2077 if ( ( rc = arbel_cmd_sw2hw_mpt ( arbel, arbel->limits.reserved_mrws,
2078 &mpt ) ) != 0 ) {
2079 DBGC ( arbel, "Arbel %p could not set up MPT: %s\n",
2080 arbel, strerror ( rc ) );
2081 return rc;
2084 return 0;
2088 * Probe PCI device
2090 * @v pci PCI device
2091 * @v id PCI ID
2092 * @ret rc Return status code
2094 static int arbel_probe ( struct pci_device *pci,
2095 const struct pci_device_id *id __unused ) {
2096 struct arbel *arbel;
2097 struct ib_device *ibdev;
2098 struct arbelprm_init_hca init_hca;
2099 int i;
2100 int rc;
2102 /* Allocate Arbel device */
2103 arbel = zalloc ( sizeof ( *arbel ) );
2104 if ( ! arbel ) {
2105 rc = -ENOMEM;
2106 goto err_alloc_arbel;
2108 pci_set_drvdata ( pci, arbel );
2110 /* Allocate Infiniband devices */
2111 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
2112 ibdev = alloc_ibdev ( 0 );
2113 if ( ! ibdev ) {
2114 rc = -ENOMEM;
2115 goto err_alloc_ibdev;
2117 arbel->ibdev[i] = ibdev;
2118 ibdev->op = &arbel_ib_operations;
2119 ibdev->dev = &pci->dev;
2120 ibdev->port = ( ARBEL_PORT_BASE + i );
2121 ib_set_drvdata ( ibdev, arbel );
2124 /* Fix up PCI device */
2125 adjust_pci_device ( pci );
2127 /* Get PCI BARs */
2128 arbel->config = ioremap ( pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR ),
2129 ARBEL_PCI_CONFIG_BAR_SIZE );
2130 arbel->uar = ioremap ( ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) +
2131 ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE ),
2132 ARBEL_PCI_UAR_SIZE );
2134 /* Allocate space for mailboxes */
2135 arbel->mailbox_in = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
2136 if ( ! arbel->mailbox_in ) {
2137 rc = -ENOMEM;
2138 goto err_mailbox_in;
2140 arbel->mailbox_out = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
2141 if ( ! arbel->mailbox_out ) {
2142 rc = -ENOMEM;
2143 goto err_mailbox_out;
2146 /* Start firmware */
2147 if ( ( rc = arbel_start_firmware ( arbel ) ) != 0 )
2148 goto err_start_firmware;
2150 /* Get device limits */
2151 if ( ( rc = arbel_get_limits ( arbel ) ) != 0 )
2152 goto err_get_limits;
2154 /* Allocate ICM */
2155 memset ( &init_hca, 0, sizeof ( init_hca ) );
2156 if ( ( rc = arbel_alloc_icm ( arbel, &init_hca ) ) != 0 )
2157 goto err_alloc_icm;
2159 /* Initialise HCA */
2160 MLX_FILL_1 ( &init_hca, 74, uar_parameters.log_max_uars, 1 );
2161 if ( ( rc = arbel_cmd_init_hca ( arbel, &init_hca ) ) != 0 ) {
2162 DBGC ( arbel, "Arbel %p could not initialise HCA: %s\n",
2163 arbel, strerror ( rc ) );
2164 goto err_init_hca;
2167 /* Set up memory protection */
2168 if ( ( rc = arbel_setup_mpt ( arbel ) ) != 0 )
2169 goto err_setup_mpt;
2171 /* Set up event queue */
2172 if ( ( rc = arbel_create_eq ( arbel ) ) != 0 )
2173 goto err_create_eq;
2175 /* Register Infiniband devices */
2176 for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
2177 if ( ( rc = register_ibdev ( arbel->ibdev[i] ) ) != 0 ) {
2178 DBGC ( arbel, "Arbel %p could not register IB "
2179 "device: %s\n", arbel, strerror ( rc ) );
2180 goto err_register_ibdev;
2184 return 0;
2186 i = ARBEL_NUM_PORTS;
2187 err_register_ibdev:
2188 for ( i-- ; i >= 0 ; i-- )
2189 unregister_ibdev ( arbel->ibdev[i] );
2190 arbel_destroy_eq ( arbel );
2191 err_create_eq:
2192 err_setup_mpt:
2193 arbel_cmd_close_hca ( arbel );
2194 err_init_hca:
2195 arbel_free_icm ( arbel );
2196 err_alloc_icm:
2197 err_get_limits:
2198 arbel_stop_firmware ( arbel );
2199 err_start_firmware:
2200 free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
2201 err_mailbox_out:
2202 free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
2203 err_mailbox_in:
2204 i = ARBEL_NUM_PORTS;
2205 err_alloc_ibdev:
2206 for ( i-- ; i >= 0 ; i-- )
2207 ibdev_put ( arbel->ibdev[i] );
2208 free ( arbel );
2209 err_alloc_arbel:
2210 return rc;
2214 * Remove PCI device
2216 * @v pci PCI device
2218 static void arbel_remove ( struct pci_device *pci ) {
2219 struct arbel *arbel = pci_get_drvdata ( pci );
2220 int i;
2222 for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
2223 unregister_ibdev ( arbel->ibdev[i] );
2224 arbel_destroy_eq ( arbel );
2225 arbel_cmd_close_hca ( arbel );
2226 arbel_free_icm ( arbel );
2227 arbel_stop_firmware ( arbel );
2228 arbel_stop_firmware ( arbel );
2229 free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
2230 free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
2231 for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
2232 ibdev_put ( arbel->ibdev[i] );
2233 free ( arbel );
2236 static struct pci_device_id arbel_nics[] = {
2237 PCI_ROM ( 0x15b3, 0x6282, "mt25218", "MT25218 HCA driver" ),
2238 PCI_ROM ( 0x15b3, 0x6274, "mt25204", "MT25204 HCA driver" ),
2241 struct pci_driver arbel_driver __pci_driver = {
2242 .ids = arbel_nics,
2243 .id_count = ( sizeof ( arbel_nics ) / sizeof ( arbel_nics[0] ) ),
2244 .probe = arbel_probe,
2245 .remove = arbel_remove,