2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
30 #include <ipxe/list.h>
31 #include <ipxe/errortab.h>
32 #include <ipxe/if_arp.h>
33 #include <ipxe/netdevice.h>
34 #include <ipxe/iobuf.h>
35 #include <ipxe/process.h>
36 #include <ipxe/infiniband.h>
37 #include <ipxe/ib_mi.h>
38 #include <ipxe/ib_sma.h>
46 /** List of Infiniband devices */
47 struct list_head ib_devices = LIST_HEAD_INIT ( ib_devices );
49 /** List of open Infiniband devices, in reverse order of opening */
50 static struct list_head open_ib_devices = LIST_HEAD_INIT ( open_ib_devices );
52 /* Disambiguate the various possible EINPROGRESSes */
53 #define EINPROGRESS_INIT __einfo_error ( EINFO_EINPROGRESS_INIT )
54 #define EINFO_EINPROGRESS_INIT __einfo_uniqify \
55 ( EINFO_EINPROGRESS, 0x01, "Initialising" )
56 #define EINPROGRESS_ARMED __einfo_error ( EINFO_EINPROGRESS_ARMED )
57 #define EINFO_EINPROGRESS_ARMED __einfo_uniqify \
58 ( EINFO_EINPROGRESS, 0x02, "Armed" )
60 /** Human-readable message for the link statuses */
61 struct errortab infiniband_errors[] __errortab = {
62 __einfo_errortab ( EINFO_EINPROGRESS_INIT ),
63 __einfo_errortab ( EINFO_EINPROGRESS_ARMED ),
66 /***************************************************************************
70 ***************************************************************************
74 * Create completion queue
76 * @v ibdev Infiniband device
77 * @v num_cqes Number of completion queue entries
78 * @v op Completion queue operations
79 * @ret cq New completion queue
81 struct ib_completion_queue *
82 ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
83 struct ib_completion_queue_operations *op ) {
84 struct ib_completion_queue *cq;
87 DBGC ( ibdev, "IBDEV %p creating completion queue\n", ibdev );
89 /* Allocate and initialise data structure */
90 cq = zalloc ( sizeof ( *cq ) );
94 list_add ( &cq->list, &ibdev->cqs );
95 cq->num_cqes = num_cqes;
96 INIT_LIST_HEAD ( &cq->work_queues );
99 /* Perform device-specific initialisation and get CQN */
100 if ( ( rc = ibdev->op->create_cq ( ibdev, cq ) ) != 0 ) {
101 DBGC ( ibdev, "IBDEV %p could not initialise completion "
102 "queue: %s\n", ibdev, strerror ( rc ) );
103 goto err_dev_create_cq;
106 DBGC ( ibdev, "IBDEV %p created %d-entry completion queue %p (%p) "
107 "with CQN %#lx\n", ibdev, num_cqes, cq,
108 ib_cq_get_drvdata ( cq ), cq->cqn );
111 ibdev->op->destroy_cq ( ibdev, cq );
113 list_del ( &cq->list );
120 * Destroy completion queue
122 * @v ibdev Infiniband device
123 * @v cq Completion queue
125 void ib_destroy_cq ( struct ib_device *ibdev,
126 struct ib_completion_queue *cq ) {
127 DBGC ( ibdev, "IBDEV %p destroying completion queue %#lx\n",
129 assert ( list_empty ( &cq->work_queues ) );
130 ibdev->op->destroy_cq ( ibdev, cq );
131 list_del ( &cq->list );
136 * Poll completion queue
138 * @v ibdev Infiniband device
139 * @v cq Completion queue
141 void ib_poll_cq ( struct ib_device *ibdev,
142 struct ib_completion_queue *cq ) {
143 struct ib_work_queue *wq;
145 /* Poll completion queue */
146 ibdev->op->poll_cq ( ibdev, cq );
148 /* Refill receive work queues */
149 list_for_each_entry ( wq, &cq->work_queues, list ) {
151 ib_refill_recv ( ibdev, wq->qp );
155 /***************************************************************************
159 ***************************************************************************
165 * @v ibdev Infiniband device
166 * @v type Queue pair type
167 * @v num_send_wqes Number of send work queue entries
168 * @v send_cq Send completion queue
169 * @v num_recv_wqes Number of receive work queue entries
170 * @v recv_cq Receive completion queue
171 * @v op Queue pair operations
174 * The queue pair will be left in the INIT state; you must call
175 * ib_modify_qp() before it is ready to use for sending and receiving.
177 struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
178 enum ib_queue_pair_type type,
179 unsigned int num_send_wqes,
180 struct ib_completion_queue *send_cq,
181 unsigned int num_recv_wqes,
182 struct ib_completion_queue *recv_cq,
183 struct ib_queue_pair_operations *op ) {
184 struct ib_queue_pair *qp;
188 DBGC ( ibdev, "IBDEV %p creating queue pair\n", ibdev );
190 /* Allocate and initialise data structure */
191 total_size = ( sizeof ( *qp ) +
192 ( num_send_wqes * sizeof ( qp->send.iobufs[0] ) ) +
193 ( num_recv_wqes * sizeof ( qp->recv.iobufs[0] ) ) );
194 qp = zalloc ( total_size );
198 list_add ( &qp->list, &ibdev->qps );
201 qp->send.is_send = 1;
202 qp->send.cq = send_cq;
203 list_add ( &qp->send.list, &send_cq->work_queues );
204 qp->send.psn = ( random() & 0xffffffUL );
205 qp->send.num_wqes = num_send_wqes;
206 qp->send.iobufs = ( ( ( void * ) qp ) + sizeof ( *qp ) );
208 qp->recv.cq = recv_cq;
209 list_add ( &qp->recv.list, &recv_cq->work_queues );
210 qp->recv.psn = ( random() & 0xffffffUL );
211 qp->recv.num_wqes = num_recv_wqes;
212 qp->recv.iobufs = ( ( ( void * ) qp ) + sizeof ( *qp ) +
213 ( num_send_wqes * sizeof ( qp->send.iobufs[0] ) ));
214 INIT_LIST_HEAD ( &qp->mgids );
217 /* Perform device-specific initialisation and get QPN */
218 if ( ( rc = ibdev->op->create_qp ( ibdev, qp ) ) != 0 ) {
219 DBGC ( ibdev, "IBDEV %p could not initialise queue pair: "
220 "%s\n", ibdev, strerror ( rc ) );
221 goto err_dev_create_qp;
223 DBGC ( ibdev, "IBDEV %p created queue pair %p (%p) with QPN %#lx\n",
224 ibdev, qp, ib_qp_get_drvdata ( qp ), qp->qpn );
225 DBGC ( ibdev, "IBDEV %p QPN %#lx has %d send entries at [%p,%p)\n",
226 ibdev, qp->qpn, num_send_wqes, qp->send.iobufs,
228 DBGC ( ibdev, "IBDEV %p QPN %#lx has %d receive entries at [%p,%p)\n",
229 ibdev, qp->qpn, num_recv_wqes, qp->recv.iobufs,
230 ( ( ( void * ) qp ) + total_size ) );
232 /* Calculate externally-visible QPN */
235 qp->ext_qpn = IB_QPN_SMI;
238 qp->ext_qpn = IB_QPN_GSI;
241 qp->ext_qpn = qp->qpn;
244 if ( qp->ext_qpn != qp->qpn ) {
245 DBGC ( ibdev, "IBDEV %p QPN %#lx has external QPN %#lx\n",
246 ibdev, qp->qpn, qp->ext_qpn );
251 ibdev->op->destroy_qp ( ibdev, qp );
253 list_del ( &qp->send.list );
254 list_del ( &qp->recv.list );
255 list_del ( &qp->list );
264 * @v ibdev Infiniband device
266 * @ret rc Return status code
268 int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp ) {
271 DBGC ( ibdev, "IBDEV %p modifying QPN %#lx\n", ibdev, qp->qpn );
273 if ( ( rc = ibdev->op->modify_qp ( ibdev, qp ) ) != 0 ) {
274 DBGC ( ibdev, "IBDEV %p could not modify QPN %#lx: %s\n",
275 ibdev, qp->qpn, strerror ( rc ) );
285 * @v ibdev Infiniband device
288 void ib_destroy_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp ) {
289 struct io_buffer *iobuf;
292 DBGC ( ibdev, "IBDEV %p destroying QPN %#lx\n",
295 assert ( list_empty ( &qp->mgids ) );
297 /* Perform device-specific destruction */
298 ibdev->op->destroy_qp ( ibdev, qp );
300 /* Complete any remaining I/O buffers with errors */
301 for ( i = 0 ; i < qp->send.num_wqes ; i++ ) {
302 if ( ( iobuf = qp->send.iobufs[i] ) != NULL )
303 ib_complete_send ( ibdev, qp, iobuf, -ECANCELED );
305 for ( i = 0 ; i < qp->recv.num_wqes ; i++ ) {
306 if ( ( iobuf = qp->recv.iobufs[i] ) != NULL ) {
307 ib_complete_recv ( ibdev, qp, NULL, NULL, iobuf,
312 /* Remove work queues from completion queue */
313 list_del ( &qp->send.list );
314 list_del ( &qp->recv.list );
317 list_del ( &qp->list );
322 * Find queue pair by QPN
324 * @v ibdev Infiniband device
325 * @v qpn Queue pair number
326 * @ret qp Queue pair, or NULL
328 struct ib_queue_pair * ib_find_qp_qpn ( struct ib_device *ibdev,
329 unsigned long qpn ) {
330 struct ib_queue_pair *qp;
332 list_for_each_entry ( qp, &ibdev->qps, list ) {
333 if ( ( qpn == qp->qpn ) || ( qpn == qp->ext_qpn ) )
340 * Find queue pair by multicast GID
342 * @v ibdev Infiniband device
343 * @v gid Multicast GID
344 * @ret qp Queue pair, or NULL
346 struct ib_queue_pair * ib_find_qp_mgid ( struct ib_device *ibdev,
347 union ib_gid *gid ) {
348 struct ib_queue_pair *qp;
349 struct ib_multicast_gid *mgid;
351 list_for_each_entry ( qp, &ibdev->qps, list ) {
352 list_for_each_entry ( mgid, &qp->mgids, list ) {
353 if ( memcmp ( &mgid->gid, gid,
354 sizeof ( mgid->gid ) ) == 0 ) {
363 * Find work queue belonging to completion queue
365 * @v cq Completion queue
366 * @v qpn Queue pair number
367 * @v is_send Find send work queue (rather than receive)
368 * @ret wq Work queue, or NULL if not found
370 struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
371 unsigned long qpn, int is_send ) {
372 struct ib_work_queue *wq;
374 list_for_each_entry ( wq, &cq->work_queues, list ) {
375 if ( ( wq->qp->qpn == qpn ) && ( wq->is_send == is_send ) )
382 * Post send work queue entry
384 * @v ibdev Infiniband device
386 * @v dest Destination address vector
387 * @v iobuf I/O buffer
388 * @ret rc Return status code
390 int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
391 struct ib_address_vector *dest,
392 struct io_buffer *iobuf ) {
393 struct ib_address_vector dest_copy;
396 /* Check queue fill level */
397 if ( qp->send.fill >= qp->send.num_wqes ) {
398 DBGC ( ibdev, "IBDEV %p QPN %#lx send queue full\n",
403 /* Use default address vector if none specified */
407 /* Make modifiable copy of address vector */
408 memcpy ( &dest_copy, dest, sizeof ( dest_copy ) );
411 /* Fill in optional parameters in address vector */
413 dest->qkey = qp->qkey;
415 dest->rate = IB_RATE_2_5;
417 /* Post to hardware */
418 if ( ( rc = ibdev->op->post_send ( ibdev, qp, dest, iobuf ) ) != 0 ) {
419 DBGC ( ibdev, "IBDEV %p QPN %#lx could not post send WQE: "
420 "%s\n", ibdev, qp->qpn, strerror ( rc ) );
429 * Post receive work queue entry
431 * @v ibdev Infiniband device
433 * @v iobuf I/O buffer
434 * @ret rc Return status code
436 int ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
437 struct io_buffer *iobuf ) {
440 /* Check packet length */
441 if ( iob_tailroom ( iobuf ) < IB_MAX_PAYLOAD_SIZE ) {
442 DBGC ( ibdev, "IBDEV %p QPN %#lx wrong RX buffer size (%zd)\n",
443 ibdev, qp->qpn, iob_tailroom ( iobuf ) );
447 /* Check queue fill level */
448 if ( qp->recv.fill >= qp->recv.num_wqes ) {
449 DBGC ( ibdev, "IBDEV %p QPN %#lx receive queue full\n",
454 /* Post to hardware */
455 if ( ( rc = ibdev->op->post_recv ( ibdev, qp, iobuf ) ) != 0 ) {
456 DBGC ( ibdev, "IBDEV %p QPN %#lx could not post receive WQE: "
457 "%s\n", ibdev, qp->qpn, strerror ( rc ) );
466 * Complete send work queue entry
468 * @v ibdev Infiniband device
470 * @v iobuf I/O buffer
471 * @v rc Completion status code
473 void ib_complete_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
474 struct io_buffer *iobuf, int rc ) {
476 if ( qp->send.cq->op->complete_send ) {
477 qp->send.cq->op->complete_send ( ibdev, qp, iobuf, rc );
485 * Complete receive work queue entry
487 * @v ibdev Infiniband device
489 * @v dest Destination address vector, or NULL
490 * @v source Source address vector, or NULL
491 * @v iobuf I/O buffer
492 * @v rc Completion status code
494 void ib_complete_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
495 struct ib_address_vector *dest,
496 struct ib_address_vector *source,
497 struct io_buffer *iobuf, int rc ) {
499 if ( qp->recv.cq->op->complete_recv ) {
500 qp->recv.cq->op->complete_recv ( ibdev, qp, dest, source,
509 * Refill receive work queue
511 * @v ibdev Infiniband device
514 void ib_refill_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp ) {
515 struct io_buffer *iobuf;
518 /* Keep filling while unfilled entries remain */
519 while ( qp->recv.fill < qp->recv.num_wqes ) {
521 /* Allocate I/O buffer */
522 iobuf = qp->op->alloc_iob ( IB_MAX_PAYLOAD_SIZE );
524 /* Non-fatal; we will refill on next attempt */
528 /* Post I/O buffer */
529 if ( ( rc = ib_post_recv ( ibdev, qp, iobuf ) ) != 0 ) {
530 DBGC ( ibdev, "IBDEV %p could not refill: %s\n",
531 ibdev, strerror ( rc ) );
539 /***************************************************************************
543 ***************************************************************************
549 * @v ibdev Infiniband device
550 * @ret rc Link status code
552 int ib_link_rc ( struct ib_device *ibdev ) {
553 switch ( ibdev->port_state ) {
554 case IB_PORT_STATE_DOWN: return -ENOTCONN;
555 case IB_PORT_STATE_INIT: return -EINPROGRESS_INIT;
556 case IB_PORT_STATE_ARMED: return -EINPROGRESS_ARMED;
557 case IB_PORT_STATE_ACTIVE: return 0;
558 default: return -EINVAL;
563 * Textual representation of Infiniband link state
565 * @v ibdev Infiniband device
566 * @ret link_text Link state text
568 static const char * ib_link_state_text ( struct ib_device *ibdev ) {
569 switch ( ibdev->port_state ) {
570 case IB_PORT_STATE_DOWN: return "DOWN";
571 case IB_PORT_STATE_INIT: return "INIT";
572 case IB_PORT_STATE_ARMED: return "ARMED";
573 case IB_PORT_STATE_ACTIVE: return "ACTIVE";
574 default: return "UNKNOWN";
579 * Notify drivers of Infiniband device or link state change
581 * @v ibdev Infiniband device
583 static void ib_notify ( struct ib_device *ibdev ) {
584 struct ib_driver *driver;
586 for_each_table_entry ( driver, IB_DRIVERS )
587 driver->notify ( ibdev );
591 * Notify of Infiniband link state change
593 * @v ibdev Infiniband device
595 void ib_link_state_changed ( struct ib_device *ibdev ) {
597 DBGC ( ibdev, "IBDEV %p link state is %s\n",
598 ibdev, ib_link_state_text ( ibdev ) );
600 /* Notify drivers of link state change */
607 * @v ibdev Infiniband device
608 * @ret rc Return status code
610 int ib_open ( struct ib_device *ibdev ) {
613 /* Increment device open request counter */
614 if ( ibdev->open_count++ > 0 ) {
615 /* Device was already open; do nothing */
620 if ( ( rc = ibdev->op->open ( ibdev ) ) != 0 ) {
621 DBGC ( ibdev, "IBDEV %p could not open: %s\n",
622 ibdev, strerror ( rc ) );
626 /* Create subnet management interface */
627 ibdev->smi = ib_create_mi ( ibdev, IB_QPT_SMI );
628 if ( ! ibdev->smi ) {
629 DBGC ( ibdev, "IBDEV %p could not create SMI\n", ibdev );
634 /* Create subnet management agent */
635 if ( ( rc = ib_create_sma ( ibdev, ibdev->smi ) ) != 0 ) {
636 DBGC ( ibdev, "IBDEV %p could not create SMA: %s\n",
637 ibdev, strerror ( rc ) );
641 /* Create general services interface */
642 ibdev->gsi = ib_create_mi ( ibdev, IB_QPT_GSI );
643 if ( ! ibdev->gsi ) {
644 DBGC ( ibdev, "IBDEV %p could not create GSI\n", ibdev );
649 /* Add to head of open devices list */
650 list_add ( &ibdev->open_list, &open_ib_devices );
652 /* Notify drivers of device state change */
655 assert ( ibdev->open_count == 1 );
658 ib_destroy_mi ( ibdev, ibdev->gsi );
660 ib_destroy_sma ( ibdev, ibdev->smi );
662 ib_destroy_mi ( ibdev, ibdev->smi );
664 ibdev->op->close ( ibdev );
666 assert ( ibdev->open_count == 1 );
667 ibdev->open_count = 0;
674 * @v ibdev Infiniband device
676 void ib_close ( struct ib_device *ibdev ) {
678 /* Decrement device open request counter */
681 /* Close device if this was the last remaining requested opening */
682 if ( ibdev->open_count == 0 ) {
684 list_del ( &ibdev->open_list );
685 ib_destroy_mi ( ibdev, ibdev->gsi );
686 ib_destroy_sma ( ibdev, ibdev->smi );
687 ib_destroy_mi ( ibdev, ibdev->smi );
688 ibdev->op->close ( ibdev );
689 ibdev->port_state = IB_PORT_STATE_DOWN;
693 /***************************************************************************
697 ***************************************************************************
701 * Attach to multicast group
703 * @v ibdev Infiniband device
705 * @v gid Multicast GID
706 * @ret rc Return status code
708 * Note that this function handles only the local device's attachment
709 * to the multicast GID; it does not issue the relevant MADs to join
710 * the multicast group on the subnet.
712 int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
713 union ib_gid *gid ) {
714 struct ib_multicast_gid *mgid;
717 /* Add to software multicast GID list */
718 mgid = zalloc ( sizeof ( *mgid ) );
723 memcpy ( &mgid->gid, gid, sizeof ( mgid->gid ) );
724 list_add ( &mgid->list, &qp->mgids );
726 /* Add to hardware multicast GID list */
727 if ( ( rc = ibdev->op->mcast_attach ( ibdev, qp, gid ) ) != 0 )
728 goto err_dev_mcast_attach;
732 err_dev_mcast_attach:
733 list_del ( &mgid->list );
740 * Detach from multicast group
742 * @v ibdev Infiniband device
744 * @v gid Multicast GID
746 void ib_mcast_detach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
747 union ib_gid *gid ) {
748 struct ib_multicast_gid *mgid;
750 /* Remove from hardware multicast GID list */
751 ibdev->op->mcast_detach ( ibdev, qp, gid );
753 /* Remove from software multicast GID list */
754 list_for_each_entry ( mgid, &qp->mgids, list ) {
755 if ( memcmp ( &mgid->gid, gid, sizeof ( mgid->gid ) ) == 0 ) {
756 list_del ( &mgid->list );
763 /***************************************************************************
767 ***************************************************************************
771 * Count Infiniband HCA ports
773 * @v ibdev Infiniband device
774 * @ret num_ports Number of ports
776 int ib_count_ports ( struct ib_device *ibdev ) {
777 struct ib_device *tmp;
780 /* Search for IB devices with the same physical device to
781 * identify port count.
783 for_each_ibdev ( tmp ) {
784 if ( tmp->dev == ibdev->dev )
791 * Set port information
793 * @v ibdev Infiniband device
794 * @v mad Set port information MAD
796 int ib_set_port_info ( struct ib_device *ibdev, union ib_mad *mad ) {
799 /* Adapters with embedded SMAs do not need to support this method */
800 if ( ! ibdev->op->set_port_info ) {
801 DBGC ( ibdev, "IBDEV %p does not support setting port "
802 "information\n", ibdev );
806 if ( ( rc = ibdev->op->set_port_info ( ibdev, mad ) ) != 0 ) {
807 DBGC ( ibdev, "IBDEV %p could not set port information: %s\n",
808 ibdev, strerror ( rc ) );
816 * Set partition key table
818 * @v ibdev Infiniband device
819 * @v mad Set partition key table MAD
821 int ib_set_pkey_table ( struct ib_device *ibdev, union ib_mad *mad ) {
824 /* Adapters with embedded SMAs do not need to support this method */
825 if ( ! ibdev->op->set_pkey_table ) {
826 DBGC ( ibdev, "IBDEV %p does not support setting partition "
827 "key table\n", ibdev );
831 if ( ( rc = ibdev->op->set_pkey_table ( ibdev, mad ) ) != 0 ) {
832 DBGC ( ibdev, "IBDEV %p could not set partition key table: "
833 "%s\n", ibdev, strerror ( rc ) );
840 /***************************************************************************
844 ***************************************************************************
850 * @v ibdev Infiniband device
852 void ib_poll_eq ( struct ib_device *ibdev ) {
853 struct ib_completion_queue *cq;
855 /* Poll device's event queue */
856 ibdev->op->poll_eq ( ibdev );
858 /* Poll all completion queues */
859 list_for_each_entry ( cq, &ibdev->cqs, list )
860 ib_poll_cq ( ibdev, cq );
864 * Single-step the Infiniband event queue
866 * @v process Infiniband event queue process
868 static void ib_step ( struct process *process __unused ) {
869 struct ib_device *ibdev;
871 list_for_each_entry ( ibdev, &open_ib_devices, open_list )
872 ib_poll_eq ( ibdev );
875 /** Infiniband event queue process */
876 PERMANENT_PROCESS ( ib_process, ib_step );
878 /***************************************************************************
880 * Infiniband device creation/destruction
882 ***************************************************************************
886 * Allocate Infiniband device
888 * @v priv_size Size of driver private data area
889 * @ret ibdev Infiniband device, or NULL
891 struct ib_device * alloc_ibdev ( size_t priv_size ) {
892 struct ib_device *ibdev;
896 total_len = ( sizeof ( *ibdev ) + priv_size );
897 ibdev = zalloc ( total_len );
899 drv_priv = ( ( ( void * ) ibdev ) + sizeof ( *ibdev ) );
900 ib_set_drvdata ( ibdev, drv_priv );
901 INIT_LIST_HEAD ( &ibdev->list );
902 INIT_LIST_HEAD ( &ibdev->open_list );
903 INIT_LIST_HEAD ( &ibdev->cqs );
904 INIT_LIST_HEAD ( &ibdev->qps );
905 ibdev->port_state = IB_PORT_STATE_DOWN;
906 ibdev->lid = IB_LID_NONE;
907 ibdev->pkey = IB_PKEY_DEFAULT;
913 * Register Infiniband device
915 * @v ibdev Infiniband device
916 * @ret rc Return status code
918 int register_ibdev ( struct ib_device *ibdev ) {
919 struct ib_driver *driver;
922 /* Add to device list */
924 list_add_tail ( &ibdev->list, &ib_devices );
925 DBGC ( ibdev, "IBDEV %p registered (phys %s)\n", ibdev,
929 for_each_table_entry ( driver, IB_DRIVERS ) {
930 if ( ( rc = driver->probe ( ibdev ) ) != 0 ) {
931 DBGC ( ibdev, "IBDEV %p could not add %s device: %s\n",
932 ibdev, driver->name, strerror ( rc ) );
940 for_each_table_entry_continue_reverse ( driver, IB_DRIVERS )
941 driver->remove ( ibdev );
942 list_del ( &ibdev->list );
948 * Unregister Infiniband device
950 * @v ibdev Infiniband device
952 void unregister_ibdev ( struct ib_device *ibdev ) {
953 struct ib_driver *driver;
956 for_each_table_entry_reverse ( driver, IB_DRIVERS )
957 driver->remove ( ibdev );
959 /* Remove from device list */
960 list_del ( &ibdev->list );
962 DBGC ( ibdev, "IBDEV %p unregistered\n", ibdev );
966 * Find Infiniband device by GID
969 * @ret ibdev Infiniband device, or NULL
971 struct ib_device * find_ibdev ( union ib_gid *gid ) {
972 struct ib_device *ibdev;
974 for_each_ibdev ( ibdev ) {
975 if ( memcmp ( gid, &ibdev->gid, sizeof ( *gid ) ) == 0 )
982 * Get most recently opened Infiniband device
984 * @ret ibdev Most recently opened Infiniband device, or NULL
986 struct ib_device * last_opened_ibdev ( void ) {
987 struct ib_device *ibdev;
989 ibdev = list_first_entry ( &open_ib_devices, struct ib_device,
994 assert ( ibdev->open_count != 0 );
999 REQUIRE_OBJECT ( ipoib );