Add RDMA ibverb driver plugin
[vpp.git] / src / plugins / rdma / rdma.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef _RDMA_H_
19 #define _RDMA_H_
20
21 #include <infiniband/verbs.h>
22 #include <vlib/log.h>
23
24 #define foreach_rdma_device_flags \
25   _(0, INITIALIZED, "initialized") \
26   _(1, ERROR, "error") \
27   _(2, ADMIN_UP, "admin-up") \
28   _(3, VA_DMA, "vaddr-dma") \
29   _(4, LINK_UP, "link-up") \
30   _(5, SHARED_TXQ_LOCK, "shared-txq-lock") \
31   _(6, ELOG, "elog") \
32
33 enum
34 {
35 #define _(a, b, c) RDMA_DEVICE_F_##b = (1 << a),
36   foreach_rdma_device_flags
37 #undef _
38 };
39
40 typedef struct
41 {
42   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
43   u32 size;
44   u32 n_enq;
45   struct ibv_cq *cq;
46   struct ibv_qp *qp;
47 } rdma_rxq_t;
48
49 typedef struct
50 {
51   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
52   u32 size;
53   u32 n_enq;
54   struct ibv_cq *cq;
55   struct ibv_qp *qp;
56   clib_spinlock_t lock;
57 } rdma_txq_t;
58
59 typedef struct
60 {
61   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
62   u32 flags;
63   u32 per_interface_next_index;
64
65   u32 dev_instance;
66   u32 sw_if_index;
67   u32 hw_if_index;
68
69   u32 async_event_clib_file_index;
70
71   rdma_rxq_t *rxqs;
72   rdma_txq_t *txqs;
73
74   u8 hwaddr[6];
75   vlib_pci_addr_t pci_addr;
76
77   struct ibv_context *ctx;
78   struct ibv_pd *pd;
79   struct ibv_mr *mr;
80   struct ibv_flow *flow_ucast;
81   struct ibv_flow *flow_mcast;
82
83   /* error */
84   clib_error_t *error;
85 } rdma_device_t;
86
87 typedef struct
88 {
89   rdma_device_t *devices;
90   vlib_log_class_t log_class;
91 } rdma_main_t;
92
93 extern rdma_main_t rdma_main;
94
95 typedef struct
96 {
97   u8 *ifname;
98
99   /* return */
100   int rv;
101   u32 sw_if_index;
102   clib_error_t *error;
103 } rdma_create_if_args_t;
104
105 void rdma_create_if (vlib_main_t * vm, rdma_create_if_args_t * args);
106 void rdma_delete_if (vlib_main_t * vm, rdma_device_t * rd);
107
108 extern vlib_node_registration_t rdma_input_node;
109 extern vnet_device_class_t rdma_device_class;
110
111 /* format.c */
112 format_function_t format_rdma_device;
113 format_function_t format_rdma_device_name;
114 format_function_t format_rdma_input_trace;
115
116 typedef struct
117 {
118   u32 next_index;
119   u32 hw_if_index;
120 } rdma_input_trace_t;
121
122 #define foreach_rdma_tx_func_error             \
123 _(NO_FREE_SLOTS, "no free tx slots")
124
125 typedef enum
126 {
127 #define _(f,s) RDMA_TX_ERROR_##f,
128   foreach_rdma_tx_func_error
129 #undef _
130     RDMA_TX_N_ERROR,
131 } rdma_tx_func_error_t;
132
133 #endif /* AVF_H */
134
135 /*
136  * fd.io coding-style-patch-verification: ON
137  *
138  * Local Variables:
139  * eval: (c-set-style "gnu")
140  * End:
141  */