1 #ifndef _GPXE_INFINIBAND_H
2 #define _GPXE_INFINIBAND_H
10 FILE_LICENCE ( GPL2_OR_LATER );
13 #include <gpxe/refcnt.h>
14 #include <gpxe/device.h>
15 #include <gpxe/ib_packet.h>
16 #include <gpxe/ib_mad.h>
18 /** Subnet management QPN */
21 /** Subnet management queue key */
24 /** General management QPN */
27 /** General management queue key */
28 #define IB_QKEY_GMA 0x80010000UL
31 #define IB_QPN_BROADCAST 0xffffffUL
33 /** Default Infiniband partition key */
34 #define IB_PKEY_NONE 0xffff
37 * Maximum payload size
39 * This is currently hard-coded in various places (drivers, subnet
40 * management agent, etc.) to 2048.
42 #define IB_MAX_PAYLOAD_SIZE 2048
46 struct ib_address_vector;
47 struct ib_completion_queue;
50 /** An Infiniband Work Queue */
51 struct ib_work_queue {
52 /** Containing queue pair */
53 struct ib_queue_pair *qp;
54 /** "Is a send queue" flag */
56 /** Associated completion queue */
57 struct ib_completion_queue *cq;
58 /** List of work queues on this completion queue */
59 struct list_head list;
60 /** Number of work queue entries */
61 unsigned int num_wqes;
62 /** Number of occupied work queue entries */
64 /** Next work queue entry index
66 * This is the index of the next entry to be filled (i.e. the
67 * first empty entry). This value is not bounded by num_wqes;
68 * users must logical-AND with (num_wqes-1) to generate an
71 unsigned long next_idx;
72 /** I/O buffers assigned to work queue */
73 struct io_buffer **iobufs;
74 /** Driver private data */
78 /** An Infiniband multicast GID */
79 struct ib_multicast_gid {
80 /** List of multicast GIDs on this QP */
81 struct list_head list;
86 /** An Infiniband queue pair type */
87 enum ib_queue_pair_type {
93 /** An Infiniband Queue Pair */
94 struct ib_queue_pair {
95 /** Containing Infiniband device */
96 struct ib_device *ibdev;
97 /** List of queue pairs on this Infiniband device */
98 struct list_head list;
99 /** Queue Pair Number */
101 /** Queue pair type */
102 enum ib_queue_pair_type type;
106 struct ib_work_queue send;
108 struct ib_work_queue recv;
109 /** List of multicast GIDs */
110 struct list_head mgids;
111 /** Driver private data */
113 /** Queue owner private data */
117 /** Infiniband queue pair modification flags */
118 enum ib_queue_pair_mods {
119 IB_MODIFY_QKEY = 0x0001,
122 /** An Infiniband Address Vector */
123 struct ib_address_vector {
124 /** Queue Pair Number */
128 * Not specified for received packets.
135 * Not specified for received packets.
140 /** GID is present */
141 unsigned int gid_present;
142 /** GID, if present */
146 /** Infiniband transmission rates */
159 /** Infiniband completion queue operations */
160 struct ib_completion_queue_operations {
164 * @v ibdev Infiniband device
166 * @v iobuf I/O buffer
167 * @v rc Completion status code
169 void ( * complete_send ) ( struct ib_device *ibdev,
170 struct ib_queue_pair *qp,
171 struct io_buffer *iobuf, int rc );
173 * Complete Receive WQE
175 * @v ibdev Infiniband device
177 * @v av Address vector, or NULL
178 * @v iobuf I/O buffer
179 * @v rc Completion status code
181 void ( * complete_recv ) ( struct ib_device *ibdev,
182 struct ib_queue_pair *qp,
183 struct ib_address_vector *av,
184 struct io_buffer *iobuf, int rc );
187 /** An Infiniband Completion Queue */
188 struct ib_completion_queue {
189 /** Containing Infiniband device */
190 struct ib_device *ibdev;
191 /** List of completion queues on this Infiniband device */
192 struct list_head list;
193 /** Completion queue number */
195 /** Number of completion queue entries */
196 unsigned int num_cqes;
197 /** Next completion queue entry index
199 * This is the index of the next entry to be filled (i.e. the
200 * first empty entry). This value is not bounded by num_wqes;
201 * users must logical-AND with (num_wqes-1) to generate an
204 unsigned long next_idx;
205 /** List of work queues completing to this queue */
206 struct list_head work_queues;
207 /** Completion queue operations */
208 struct ib_completion_queue_operations *op;
209 /** Driver private data */
214 * Infiniband device operations
216 * These represent a subset of the Infiniband Verbs.
218 struct ib_device_operations {
219 /** Create completion queue
221 * @v ibdev Infiniband device
222 * @v cq Completion queue
223 * @ret rc Return status code
225 int ( * create_cq ) ( struct ib_device *ibdev,
226 struct ib_completion_queue *cq );
227 /** Destroy completion queue
229 * @v ibdev Infiniband device
230 * @v cq Completion queue
232 void ( * destroy_cq ) ( struct ib_device *ibdev,
233 struct ib_completion_queue *cq );
234 /** Create queue pair
236 * @v ibdev Infiniband device
238 * @ret rc Return status code
240 int ( * create_qp ) ( struct ib_device *ibdev,
241 struct ib_queue_pair *qp );
242 /** Modify queue pair
244 * @v ibdev Infiniband device
246 * @v mod_list Modification list
247 * @ret rc Return status code
249 int ( * modify_qp ) ( struct ib_device *ibdev,
250 struct ib_queue_pair *qp,
251 unsigned long mod_list );
252 /** Destroy queue pair
254 * @v ibdev Infiniband device
257 void ( * destroy_qp ) ( struct ib_device *ibdev,
258 struct ib_queue_pair *qp );
259 /** Post send work queue entry
261 * @v ibdev Infiniband device
263 * @v av Address vector
264 * @v iobuf I/O buffer
265 * @ret rc Return status code
267 * If this method returns success, the I/O buffer remains
268 * owned by the queue pair. If this method returns failure,
269 * the I/O buffer is immediately released; the failure is
270 * interpreted as "failure to enqueue buffer".
272 int ( * post_send ) ( struct ib_device *ibdev,
273 struct ib_queue_pair *qp,
274 struct ib_address_vector *av,
275 struct io_buffer *iobuf );
276 /** Post receive work queue entry
278 * @v ibdev Infiniband device
280 * @v iobuf I/O buffer
281 * @ret rc Return status code
283 * If this method returns success, the I/O buffer remains
284 * owned by the queue pair. If this method returns failure,
285 * the I/O buffer is immediately released; the failure is
286 * interpreted as "failure to enqueue buffer".
288 int ( * post_recv ) ( struct ib_device *ibdev,
289 struct ib_queue_pair *qp,
290 struct io_buffer *iobuf );
291 /** Poll completion queue
293 * @v ibdev Infiniband device
294 * @v cq Completion queue
296 * The relevant completion handler (specified at completion
297 * queue creation time) takes ownership of the I/O buffer.
299 void ( * poll_cq ) ( struct ib_device *ibdev,
300 struct ib_completion_queue *cq );
304 * @v ibdev Infiniband device
306 void ( * poll_eq ) ( struct ib_device *ibdev );
310 * @v ibdev Infiniband device
311 * @ret rc Return status code
313 int ( * open ) ( struct ib_device *ibdev );
317 * @v ibdev Infiniband device
319 void ( * close ) ( struct ib_device *ibdev );
320 /** Attach to multicast group
322 * @v ibdev Infiniband device
324 * @v gid Multicast GID
325 * @ret rc Return status code
327 int ( * mcast_attach ) ( struct ib_device *ibdev,
328 struct ib_queue_pair *qp,
329 struct ib_gid *gid );
330 /** Detach from multicast group
332 * @v ibdev Infiniband device
334 * @v gid Multicast GID
336 void ( * mcast_detach ) ( struct ib_device *ibdev,
337 struct ib_queue_pair *qp,
338 struct ib_gid *gid );
339 /** Set port information
341 * @v ibdev Infiniband device
342 * @v port_info New port information
344 * This method is required only by adapters that do not have
347 int ( * set_port_info ) ( struct ib_device *ibdev,
348 const struct ib_port_info *port_info );
351 /** An Infiniband device */
353 /** Reference counter */
354 struct refcnt refcnt;
355 /** List of Infiniband devices */
356 struct list_head list;
357 /** Underlying device */
359 /** List of completion queues */
360 struct list_head cqs;
361 /** List of queue pairs */
362 struct list_head qps;
363 /** Infiniband operations */
364 struct ib_device_operations *op;
367 /** Port open request counter */
368 unsigned int open_count;
380 /** Subnet manager LID */
382 /** Subnet manager SL */
387 /** Outbound packet sequence number */
390 /** Subnet management agent */
392 /** General management agent */
395 /** Driver private data */
397 /** Owner private data */
401 extern struct ib_completion_queue *
402 ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
403 struct ib_completion_queue_operations *op );
404 extern void ib_destroy_cq ( struct ib_device *ibdev,
405 struct ib_completion_queue *cq );
406 extern void ib_poll_cq ( struct ib_device *ibdev,
407 struct ib_completion_queue *cq );
408 extern struct ib_queue_pair *
409 ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
410 unsigned int num_send_wqes, struct ib_completion_queue *send_cq,
411 unsigned int num_recv_wqes, struct ib_completion_queue *recv_cq,
412 unsigned long qkey );
413 extern int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp,
414 unsigned long mod_list, unsigned long qkey );
415 extern void ib_destroy_qp ( struct ib_device *ibdev,
416 struct ib_queue_pair *qp );
417 extern struct ib_queue_pair * ib_find_qp_qpn ( struct ib_device *ibdev,
419 extern struct ib_queue_pair * ib_find_qp_mgid ( struct ib_device *ibdev,
420 struct ib_gid *gid );
421 extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
422 unsigned long qpn, int is_send );
423 extern int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
424 struct ib_address_vector *av,
425 struct io_buffer *iobuf );
426 extern int ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
427 struct io_buffer *iobuf );
428 extern void ib_complete_send ( struct ib_device *ibdev,
429 struct ib_queue_pair *qp,
430 struct io_buffer *iobuf, int rc );
431 extern void ib_complete_recv ( struct ib_device *ibdev,
432 struct ib_queue_pair *qp,
433 struct ib_address_vector *av,
434 struct io_buffer *iobuf, int rc );
435 extern void ib_refill_recv ( struct ib_device *ibdev,
436 struct ib_queue_pair *qp );
437 extern int ib_open ( struct ib_device *ibdev );
438 extern void ib_close ( struct ib_device *ibdev );
439 extern int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
440 struct ib_gid *gid );
441 extern void ib_mcast_detach ( struct ib_device *ibdev,
442 struct ib_queue_pair *qp, struct ib_gid *gid );
443 extern int ib_get_hca_info ( struct ib_device *ibdev,
444 struct ib_gid_half *hca_guid );
445 extern int ib_set_port_info ( struct ib_device *ibdev,
446 const struct ib_port_info *port_info );
447 extern struct ib_device * alloc_ibdev ( size_t priv_size );
448 extern int register_ibdev ( struct ib_device *ibdev );
449 extern void unregister_ibdev ( struct ib_device *ibdev );
450 extern void ib_link_state_changed ( struct ib_device *ibdev );
451 extern void ib_poll_eq ( struct ib_device *ibdev );
452 extern struct list_head ib_devices;
454 /** Iterate over all network devices */
455 #define for_each_ibdev( ibdev ) \
456 list_for_each_entry ( (ibdev), &ib_devices, list )
461 * @v ibdev Infiniband device
462 * @ret link_up Link is up
464 static inline __always_inline int
465 ib_link_ok ( struct ib_device *ibdev ) {
466 return ( ibdev->port_state == IB_PORT_STATE_ACTIVE );
470 * Get reference to Infiniband device
472 * @v ibdev Infiniband device
473 * @ret ibdev Infiniband device
475 static inline __always_inline struct ib_device *
476 ibdev_get ( struct ib_device *ibdev ) {
477 ref_get ( &ibdev->refcnt );
482 * Drop reference to Infiniband device
484 * @v ibdev Infiniband device
486 static inline __always_inline void
487 ibdev_put ( struct ib_device *ibdev ) {
488 ref_put ( &ibdev->refcnt );
492 * Set Infiniband work queue driver-private data
495 * @v priv Private data
497 static inline __always_inline void
498 ib_wq_set_drvdata ( struct ib_work_queue *wq, void *priv ) {
503 * Get Infiniband work queue driver-private data
506 * @ret priv Private data
508 static inline __always_inline void *
509 ib_wq_get_drvdata ( struct ib_work_queue *wq ) {
514 * Set Infiniband queue pair driver-private data
517 * @v priv Private data
519 static inline __always_inline void
520 ib_qp_set_drvdata ( struct ib_queue_pair *qp, void *priv ) {
525 * Get Infiniband queue pair driver-private data
528 * @ret priv Private data
530 static inline __always_inline void *
531 ib_qp_get_drvdata ( struct ib_queue_pair *qp ) {
536 * Set Infiniband queue pair owner-private data
539 * @v priv Private data
541 static inline __always_inline void
542 ib_qp_set_ownerdata ( struct ib_queue_pair *qp, void *priv ) {
543 qp->owner_priv = priv;
547 * Get Infiniband queue pair owner-private data
550 * @ret priv Private data
552 static inline __always_inline void *
553 ib_qp_get_ownerdata ( struct ib_queue_pair *qp ) {
554 return qp->owner_priv;
558 * Set Infiniband completion queue driver-private data
560 * @v cq Completion queue
561 * @v priv Private data
563 static inline __always_inline void
564 ib_cq_set_drvdata ( struct ib_completion_queue *cq, void *priv ) {
569 * Get Infiniband completion queue driver-private data
571 * @v cq Completion queue
572 * @ret priv Private data
574 static inline __always_inline void *
575 ib_cq_get_drvdata ( struct ib_completion_queue *cq ) {
580 * Set Infiniband device driver-private data
582 * @v ibdev Infiniband device
583 * @v priv Private data
585 static inline __always_inline void
586 ib_set_drvdata ( struct ib_device *ibdev, void *priv ) {
587 ibdev->drv_priv = priv;
591 * Get Infiniband device driver-private data
593 * @v ibdev Infiniband device
594 * @ret priv Private data
596 static inline __always_inline void *
597 ib_get_drvdata ( struct ib_device *ibdev ) {
598 return ibdev->drv_priv;
602 * Set Infiniband device owner-private data
604 * @v ibdev Infiniband device
605 * @v priv Private data
607 static inline __always_inline void
608 ib_set_ownerdata ( struct ib_device *ibdev, void *priv ) {
609 ibdev->owner_priv = priv;
613 * Get Infiniband device owner-private data
615 * @v ibdev Infiniband device
616 * @ret priv Private data
618 static inline __always_inline void *
619 ib_get_ownerdata ( struct ib_device *ibdev ) {
620 return ibdev->owner_priv;
623 #endif /* _GPXE_INFINIBAND_H */