302d2383cfe834ba206b759119db5bd5ece213e1
[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 #include <vlib/pci/pci.h>
24 #include <vnet/interface.h>
25 #include <vnet/ethernet/mac_address.h>
26
27 #define foreach_rdma_device_flags \
28   _(0, ERROR, "error") \
29   _(1, ADMIN_UP, "admin-up") \
30   _(2, LINK_UP, "link-up") \
31   _(3, PROMISC, "promiscuous")
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   struct ibv_cq *cq;
44   struct ibv_wq *wq;
45   u32 *bufs;
46   u32 size;
47   u32 head;
48   u32 tail;
49 } rdma_rxq_t;
50
51 typedef struct
52 {
53   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
54   clib_spinlock_t lock;
55   struct ibv_cq *cq;
56   struct ibv_qp *qp;
57   u32 *bufs;
58   u32 size;
59   u32 head;
60   u32 tail;
61 } rdma_txq_t;
62
63 typedef struct
64 {
65   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
66
67   /* following fields are accessed in datapath */
68   rdma_rxq_t *rxqs;
69   rdma_txq_t *txqs;
70   u32 flags;
71   u32 per_interface_next_index;
72   u32 sw_if_index;
73   u32 hw_if_index;
74   u32 lkey;                     /* cache of mr->lkey */
75   u8 pool;                      /* buffer pool index */
76
77   /* fields below are not accessed in datapath */
78   vlib_pci_device_info_t *pci;
79   u8 *name;
80   u8 *linux_ifname;
81   mac_address_t hwaddr;
82   u32 async_event_clib_file_index;
83   u32 dev_instance;
84
85   struct ibv_context *ctx;
86   struct ibv_pd *pd;
87   struct ibv_mr *mr;
88   struct ibv_qp *rx_qp;
89   struct ibv_rwq_ind_table *rx_rwq_ind_tbl;
90   struct ibv_flow *flow_ucast;
91   struct ibv_flow *flow_mcast;
92
93   clib_error_t *error;
94 } rdma_device_t;
95
96 typedef struct
97 {
98   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
99   vlib_buffer_t buffer_template;
100 } rdma_per_thread_data_t;
101
102 typedef struct
103 {
104   rdma_per_thread_data_t *per_thread_data;
105   rdma_device_t *devices;
106   vlib_log_class_t log_class;
107   u16 msg_id_base;
108 } rdma_main_t;
109
110 extern rdma_main_t rdma_main;
111
112 typedef enum
113 {
114   RDMA_MODE_AUTO = 0,
115   RDMA_MODE_IBV,
116   RDMA_MODE_DV,
117 } rdma_mode_t;
118
119 typedef struct
120 {
121   u8 *ifname;
122   u8 *name;
123   u32 rxq_size;
124   u32 txq_size;
125   u32 rxq_num;
126   rdma_mode_t mode;
127
128   /* return */
129   int rv;
130   u32 sw_if_index;
131   clib_error_t *error;
132 } rdma_create_if_args_t;
133
134 void rdma_create_if (vlib_main_t * vm, rdma_create_if_args_t * args);
135 void rdma_delete_if (vlib_main_t * vm, rdma_device_t * rd);
136
137 extern vlib_node_registration_t rdma_input_node;
138 extern vnet_device_class_t rdma_device_class;
139
140 format_function_t format_rdma_device;
141 format_function_t format_rdma_device_name;
142 format_function_t format_rdma_input_trace;
143 unformat_function_t unformat_rdma_create_if_args;
144
145 typedef struct
146 {
147   u32 next_index;
148   u32 hw_if_index;
149 } rdma_input_trace_t;
150
151 #define foreach_rdma_tx_func_error             \
152 _(NO_FREE_SLOTS, "no free tx slots")
153
154 typedef enum
155 {
156 #define _(f,s) RDMA_TX_ERROR_##f,
157   foreach_rdma_tx_func_error
158 #undef _
159     RDMA_TX_N_ERROR,
160 } rdma_tx_func_error_t;
161
162 #endif /* AVF_H */
163
164 /*
165  * fd.io coding-style-patch-verification: ON
166  *
167  * Local Variables:
168  * eval: (c-set-style "gnu")
169  * End:
170  */