rdma: add support for promiscuous mode
[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, ERROR, "error") \
26   _(1, ADMIN_UP, "admin-up") \
27   _(2, LINK_UP, "link-up") \
28   _(3, PROMISC, "promiscuous")
29
30 enum
31 {
32 #define _(a, b, c) RDMA_DEVICE_F_##b = (1 << a),
33   foreach_rdma_device_flags
34 #undef _
35 };
36
37 typedef struct
38 {
39   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
40   u32 size;
41   u32 n_enq;
42   struct ibv_cq *cq;
43   struct ibv_wq *wq;
44 } rdma_rxq_t;
45
46 typedef struct
47 {
48   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
49   u32 size;
50   u32 n_enq;
51   struct ibv_cq *cq;
52   struct ibv_qp *qp;
53   clib_spinlock_t lock;
54 } rdma_txq_t;
55
56 typedef struct
57 {
58   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
59   u32 flags;
60   u32 per_interface_next_index;
61
62   u32 dev_instance;
63   u32 sw_if_index;
64   u32 hw_if_index;
65
66   u32 async_event_clib_file_index;
67
68   rdma_rxq_t *rxqs;
69   rdma_txq_t *txqs;
70
71   u8 *name;
72   mac_address_t hwaddr;
73   vlib_pci_addr_t pci_addr;
74
75   struct ibv_context *ctx;
76   struct ibv_pd *pd;
77   struct ibv_mr *mr;
78   struct ibv_qp *rx_qp;
79   struct ibv_rwq_ind_table *rx_rwq_ind_tbl;
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   u8 *name;
99   u32 rxq_size;
100   u32 txq_size;
101   u32 rxq_num;
102
103   /* return */
104   int rv;
105   u32 sw_if_index;
106   clib_error_t *error;
107 } rdma_create_if_args_t;
108
109 void rdma_create_if (vlib_main_t * vm, rdma_create_if_args_t * args);
110 void rdma_delete_if (vlib_main_t * vm, rdma_device_t * rd);
111
112 extern vlib_node_registration_t rdma_input_node;
113 extern vnet_device_class_t rdma_device_class;
114
115 /* format.c */
116 format_function_t format_rdma_device;
117 format_function_t format_rdma_device_name;
118 format_function_t format_rdma_input_trace;
119
120 typedef struct
121 {
122   u32 next_index;
123   u32 hw_if_index;
124 } rdma_input_trace_t;
125
126 #define foreach_rdma_tx_func_error             \
127 _(NO_FREE_SLOTS, "no free tx slots")
128
129 typedef enum
130 {
131 #define _(f,s) RDMA_TX_ERROR_##f,
132   foreach_rdma_tx_func_error
133 #undef _
134     RDMA_TX_N_ERROR,
135 } rdma_tx_func_error_t;
136
137 #endif /* AVF_H */
138
139 /*
140  * fd.io coding-style-patch-verification: ON
141  *
142  * Local Variables:
143  * eval: (c-set-style "gnu")
144  * End:
145  */