00001 #ifndef _GPXE_INFINIBAND_H
00002 #define _GPXE_INFINIBAND_H
00003
00004
00005
00006
00007
00008
00009
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011
00012 #include <stdint.h>
00013 #include <gpxe/refcnt.h>
00014 #include <gpxe/device.h>
00015 #include <gpxe/ib_packet.h>
00016 #include <gpxe/ib_mad.h>
00017
00018
00019 #define IB_QPN_SMI 0
00020
00021
00022 #define IB_QKEY_SMI 0
00023
00024
00025 #define IB_QPN_GSI 1
00026
00027
00028 #define IB_QKEY_GSI 0x80010000UL
00029
00030
00031 #define IB_QPN_BROADCAST 0xffffffUL
00032
00033
00034 #define IB_QPN_MASK 0xffffffUL
00035
00036
00037 #define IB_PKEY_DEFAULT 0xffff
00038
00039
00040 #define IB_PKEY_FULL 0x8000
00041
00042
00043
00044
00045
00046
00047
00048 #define IB_MAX_PAYLOAD_SIZE 2048
00049
00050 struct ib_device;
00051 struct ib_queue_pair;
00052 struct ib_address_vector;
00053 struct ib_completion_queue;
00054 struct ib_mad_interface;
00055
00056
00057 enum ib_rate {
00058 IB_RATE_2_5 = 2,
00059 IB_RATE_10 = 3,
00060 IB_RATE_30 = 4,
00061 IB_RATE_5 = 5,
00062 IB_RATE_20 = 6,
00063 IB_RATE_40 = 7,
00064 IB_RATE_60 = 8,
00065 IB_RATE_80 = 9,
00066 IB_RATE_120 = 10,
00067 };
00068
00069
00070 struct ib_address_vector {
00071
00072 unsigned long qpn;
00073
00074
00075
00076
00077 unsigned long qkey;
00078
00079 unsigned int lid;
00080
00081
00082
00083
00084 enum ib_rate rate;
00085
00086 unsigned int sl;
00087
00088 unsigned int gid_present;
00089
00090 struct ib_gid gid;
00091 };
00092
00093
00094 struct ib_work_queue {
00095
00096 struct ib_queue_pair *qp;
00097
00098 int is_send;
00099
00100 struct ib_completion_queue *cq;
00101
00102 struct list_head list;
00103
00104 uint32_t psn;
00105
00106 unsigned int num_wqes;
00107
00108 unsigned int fill;
00109
00110
00111
00112
00113
00114
00115
00116 unsigned long next_idx;
00117
00118 struct io_buffer **iobufs;
00119
00120 void *drv_priv;
00121 };
00122
00123
00124 struct ib_multicast_gid {
00125
00126 struct list_head list;
00127
00128 struct ib_gid gid;
00129 };
00130
00131
00132 enum ib_queue_pair_type {
00133 IB_QPT_SMI,
00134 IB_QPT_GSI,
00135 IB_QPT_UD,
00136 IB_QPT_RC,
00137 };
00138
00139
00140 struct ib_queue_pair {
00141
00142 struct ib_device *ibdev;
00143
00144 struct list_head list;
00145
00146 unsigned long qpn;
00147
00148
00149
00150
00151
00152
00153 unsigned long ext_qpn;
00154
00155 enum ib_queue_pair_type type;
00156
00157 unsigned long qkey;
00158
00159 struct ib_work_queue send;
00160
00161 struct ib_work_queue recv;
00162
00163 struct list_head mgids;
00164
00165 struct ib_address_vector av;
00166
00167 void *drv_priv;
00168
00169 void *owner_priv;
00170 };
00171
00172
00173 struct ib_completion_queue_operations {
00174
00175
00176
00177
00178
00179
00180
00181
00182 void ( * complete_send ) ( struct ib_device *ibdev,
00183 struct ib_queue_pair *qp,
00184 struct io_buffer *iobuf, int rc );
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 void ( * complete_recv ) ( struct ib_device *ibdev,
00195 struct ib_queue_pair *qp,
00196 struct ib_address_vector *av,
00197 struct io_buffer *iobuf, int rc );
00198 };
00199
00200
00201 struct ib_completion_queue {
00202
00203 struct ib_device *ibdev;
00204
00205 struct list_head list;
00206
00207 unsigned long cqn;
00208
00209 unsigned int num_cqes;
00210
00211
00212
00213
00214
00215
00216
00217 unsigned long next_idx;
00218
00219 struct list_head work_queues;
00220
00221 struct ib_completion_queue_operations *op;
00222
00223 void *drv_priv;
00224 };
00225
00226
00227
00228
00229
00230
00231 struct ib_device_operations {
00232
00233
00234
00235
00236
00237
00238 int ( * create_cq ) ( struct ib_device *ibdev,
00239 struct ib_completion_queue *cq );
00240
00241
00242
00243
00244
00245 void ( * destroy_cq ) ( struct ib_device *ibdev,
00246 struct ib_completion_queue *cq );
00247
00248
00249
00250
00251
00252
00253 int ( * create_qp ) ( struct ib_device *ibdev,
00254 struct ib_queue_pair *qp );
00255
00256
00257
00258
00259
00260
00261 int ( * modify_qp ) ( struct ib_device *ibdev,
00262 struct ib_queue_pair *qp );
00263
00264
00265
00266
00267
00268 void ( * destroy_qp ) ( struct ib_device *ibdev,
00269 struct ib_queue_pair *qp );
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 int ( * post_send ) ( struct ib_device *ibdev,
00284 struct ib_queue_pair *qp,
00285 struct ib_address_vector *av,
00286 struct io_buffer *iobuf );
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 int ( * post_recv ) ( struct ib_device *ibdev,
00300 struct ib_queue_pair *qp,
00301 struct io_buffer *iobuf );
00302
00303
00304
00305
00306
00307
00308
00309
00310 void ( * poll_cq ) ( struct ib_device *ibdev,
00311 struct ib_completion_queue *cq );
00312
00313
00314
00315
00316
00317 void ( * poll_eq ) ( struct ib_device *ibdev );
00318
00319
00320
00321
00322
00323
00324 int ( * open ) ( struct ib_device *ibdev );
00325
00326
00327
00328
00329
00330 void ( * close ) ( struct ib_device *ibdev );
00331
00332
00333
00334
00335
00336
00337
00338 int ( * mcast_attach ) ( struct ib_device *ibdev,
00339 struct ib_queue_pair *qp,
00340 struct ib_gid *gid );
00341
00342
00343
00344
00345
00346
00347 void ( * mcast_detach ) ( struct ib_device *ibdev,
00348 struct ib_queue_pair *qp,
00349 struct ib_gid *gid );
00350
00351
00352
00353
00354
00355
00356
00357
00358 int ( * set_port_info ) ( struct ib_device *ibdev, union ib_mad *mad );
00359
00360
00361
00362
00363
00364
00365
00366
00367 int ( * set_pkey_table ) ( struct ib_device *ibdev,
00368 union ib_mad *mad );
00369 };
00370
00371
00372 struct ib_device {
00373
00374 struct refcnt refcnt;
00375
00376 struct list_head list;
00377
00378 struct list_head open_list;
00379
00380 struct device *dev;
00381
00382 struct list_head cqs;
00383
00384 struct list_head qps;
00385
00386 struct ib_device_operations *op;
00387
00388 unsigned int port;
00389
00390 unsigned int open_count;
00391
00392
00393 uint8_t port_state;
00394
00395 uint8_t link_width_supported;
00396
00397 uint8_t link_width_enabled;
00398
00399 uint8_t link_width_active;
00400
00401 uint8_t link_speed_supported;
00402
00403 uint8_t link_speed_enabled;
00404
00405 uint8_t link_speed_active;
00406
00407 struct ib_gid gid;
00408
00409 uint16_t lid;
00410
00411 uint16_t sm_lid;
00412
00413 uint8_t sm_sl;
00414
00415 uint16_t pkey;
00416
00417
00418
00419
00420
00421
00422 uint32_t rdma_key;
00423
00424
00425 struct ib_mad_interface *smi;
00426
00427 struct ib_mad_interface *gsi;
00428
00429
00430 void *drv_priv;
00431
00432 void *owner_priv;
00433 };
00434
00435 extern struct ib_completion_queue *
00436 ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
00437 struct ib_completion_queue_operations *op );
00438 extern void ib_destroy_cq ( struct ib_device *ibdev,
00439 struct ib_completion_queue *cq );
00440 extern void ib_poll_cq ( struct ib_device *ibdev,
00441 struct ib_completion_queue *cq );
00442 extern struct ib_queue_pair *
00443 ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
00444 unsigned int num_send_wqes, struct ib_completion_queue *send_cq,
00445 unsigned int num_recv_wqes,
00446 struct ib_completion_queue *recv_cq );
00447 extern int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp );
00448 extern void ib_destroy_qp ( struct ib_device *ibdev,
00449 struct ib_queue_pair *qp );
00450 extern struct ib_queue_pair * ib_find_qp_qpn ( struct ib_device *ibdev,
00451 unsigned long qpn );
00452 extern struct ib_queue_pair * ib_find_qp_mgid ( struct ib_device *ibdev,
00453 struct ib_gid *gid );
00454 extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
00455 unsigned long qpn, int is_send );
00456 extern int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
00457 struct ib_address_vector *av,
00458 struct io_buffer *iobuf );
00459 extern int ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
00460 struct io_buffer *iobuf );
00461 extern void ib_complete_send ( struct ib_device *ibdev,
00462 struct ib_queue_pair *qp,
00463 struct io_buffer *iobuf, int rc );
00464 extern void ib_complete_recv ( struct ib_device *ibdev,
00465 struct ib_queue_pair *qp,
00466 struct ib_address_vector *av,
00467 struct io_buffer *iobuf, int rc );
00468 extern void ib_refill_recv ( struct ib_device *ibdev,
00469 struct ib_queue_pair *qp );
00470 extern int ib_open ( struct ib_device *ibdev );
00471 extern void ib_close ( struct ib_device *ibdev );
00472 extern int ib_link_rc ( struct ib_device *ibdev );
00473 extern int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
00474 struct ib_gid *gid );
00475 extern void ib_mcast_detach ( struct ib_device *ibdev,
00476 struct ib_queue_pair *qp, struct ib_gid *gid );
00477 extern int ib_get_hca_info ( struct ib_device *ibdev,
00478 struct ib_gid_half *hca_guid );
00479 extern int ib_set_port_info ( struct ib_device *ibdev, union ib_mad *mad );
00480 extern int ib_set_pkey_table ( struct ib_device *ibdev, union ib_mad *mad );
00481 extern struct ib_device * alloc_ibdev ( size_t priv_size );
00482 extern int register_ibdev ( struct ib_device *ibdev );
00483 extern void unregister_ibdev ( struct ib_device *ibdev );
00484 extern struct ib_device * find_ibdev ( struct ib_gid *gid );
00485 extern struct ib_device * last_opened_ibdev ( void );
00486 extern void ib_link_state_changed ( struct ib_device *ibdev );
00487 extern void ib_poll_eq ( struct ib_device *ibdev );
00488 extern struct list_head ib_devices;
00489
00490
00491 #define for_each_ibdev( ibdev ) \
00492 list_for_each_entry ( (ibdev), &ib_devices, list )
00493
00494
00495
00496
00497
00498
00499
00500 static inline __always_inline int
00501 ib_link_ok ( struct ib_device *ibdev ) {
00502 return ( ibdev->port_state == IB_PORT_STATE_ACTIVE );
00503 }
00504
00505
00506
00507
00508
00509
00510
00511 static inline __always_inline struct ib_device *
00512 ibdev_get ( struct ib_device *ibdev ) {
00513 ref_get ( &ibdev->refcnt );
00514 return ibdev;
00515 }
00516
00517
00518
00519
00520
00521
00522 static inline __always_inline void
00523 ibdev_put ( struct ib_device *ibdev ) {
00524 ref_put ( &ibdev->refcnt );
00525 }
00526
00527
00528
00529
00530
00531
00532
00533 static inline __always_inline void
00534 ib_wq_set_drvdata ( struct ib_work_queue *wq, void *priv ) {
00535 wq->drv_priv = priv;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544 static inline __always_inline void *
00545 ib_wq_get_drvdata ( struct ib_work_queue *wq ) {
00546 return wq->drv_priv;
00547 }
00548
00549
00550
00551
00552
00553
00554
00555 static inline __always_inline void
00556 ib_qp_set_drvdata ( struct ib_queue_pair *qp, void *priv ) {
00557 qp->drv_priv = priv;
00558 }
00559
00560
00561
00562
00563
00564
00565
00566 static inline __always_inline void *
00567 ib_qp_get_drvdata ( struct ib_queue_pair *qp ) {
00568 return qp->drv_priv;
00569 }
00570
00571
00572
00573
00574
00575
00576
00577 static inline __always_inline void
00578 ib_qp_set_ownerdata ( struct ib_queue_pair *qp, void *priv ) {
00579 qp->owner_priv = priv;
00580 }
00581
00582
00583
00584
00585
00586
00587
00588 static inline __always_inline void *
00589 ib_qp_get_ownerdata ( struct ib_queue_pair *qp ) {
00590 return qp->owner_priv;
00591 }
00592
00593
00594
00595
00596
00597
00598
00599 static inline __always_inline void
00600 ib_cq_set_drvdata ( struct ib_completion_queue *cq, void *priv ) {
00601 cq->drv_priv = priv;
00602 }
00603
00604
00605
00606
00607
00608
00609
00610 static inline __always_inline void *
00611 ib_cq_get_drvdata ( struct ib_completion_queue *cq ) {
00612 return cq->drv_priv;
00613 }
00614
00615
00616
00617
00618
00619
00620
00621 static inline __always_inline void
00622 ib_set_drvdata ( struct ib_device *ibdev, void *priv ) {
00623 ibdev->drv_priv = priv;
00624 }
00625
00626
00627
00628
00629
00630
00631
00632 static inline __always_inline void *
00633 ib_get_drvdata ( struct ib_device *ibdev ) {
00634 return ibdev->drv_priv;
00635 }
00636
00637
00638
00639
00640
00641
00642
00643 static inline __always_inline void
00644 ib_set_ownerdata ( struct ib_device *ibdev, void *priv ) {
00645 ibdev->owner_priv = priv;
00646 }
00647
00648
00649
00650
00651
00652
00653
00654 static inline __always_inline void *
00655 ib_get_ownerdata ( struct ib_device *ibdev ) {
00656 return ibdev->owner_priv;
00657 }
00658
00659 #endif