rdma: add rdma API
[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   rdma_device_t *devices;
99   vlib_log_class_t log_class;
100   u16 msg_id_base;
101 } rdma_main_t;
102
103 extern rdma_main_t rdma_main;
104
105 typedef struct
106 {
107   u8 *ifname;
108   u8 *name;
109   u32 rxq_size;
110   u32 txq_size;
111   u32 rxq_num;
112
113   /* return */
114   int rv;
115   u32 sw_if_index;
116   clib_error_t *error;
117 } rdma_create_if_args_t;
118
119 void rdma_create_if (vlib_main_t * vm, rdma_create_if_args_t * args);
120 void rdma_delete_if (vlib_main_t * vm, rdma_device_t * rd);
121
122 extern vlib_node_registration_t rdma_input_node;
123 extern vnet_device_class_t rdma_device_class;
124
125 format_function_t format_rdma_device;
126 format_function_t format_rdma_device_name;
127 format_function_t format_rdma_input_trace;
128 unformat_function_t unformat_rdma_create_if_args;
129
130 typedef struct
131 {
132   u32 next_index;
133   u32 hw_if_index;
134 } rdma_input_trace_t;
135
136 #define foreach_rdma_tx_func_error             \
137 _(NO_FREE_SLOTS, "no free tx slots")
138
139 typedef enum
140 {
141 #define _(f,s) RDMA_TX_ERROR_##f,
142   foreach_rdma_tx_func_error
143 #undef _
144     RDMA_TX_N_ERROR,
145 } rdma_tx_func_error_t;
146
147 #endif /* AVF_H */
148
149 /*
150  * fd.io coding-style-patch-verification: ON
151  *
152  * Local Variables:
153  * eval: (c-set-style "gnu")
154  * End:
155  */