rdma: add option to specify inteface name
[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   u8 *name;
77
78   struct ibv_context *ctx;
79   struct ibv_pd *pd;
80   struct ibv_mr *mr;
81   struct ibv_flow *flow_ucast;
82   struct ibv_flow *flow_mcast;
83
84   /* error */
85   clib_error_t *error;
86 } rdma_device_t;
87
88 typedef struct
89 {
90   rdma_device_t *devices;
91   vlib_log_class_t log_class;
92 } rdma_main_t;
93
94 extern rdma_main_t rdma_main;
95
96 typedef struct
97 {
98   u8 *ifname;
99   u8 *name;
100
101   /* return */
102   int rv;
103   u32 sw_if_index;
104   clib_error_t *error;
105 } rdma_create_if_args_t;
106
107 void rdma_create_if (vlib_main_t * vm, rdma_create_if_args_t * args);
108 void rdma_delete_if (vlib_main_t * vm, rdma_device_t * rd);
109
110 extern vlib_node_registration_t rdma_input_node;
111 extern vnet_device_class_t rdma_device_class;
112
113 /* format.c */
114 format_function_t format_rdma_device;
115 format_function_t format_rdma_device_name;
116 format_function_t format_rdma_input_trace;
117
118 typedef struct
119 {
120   u32 next_index;
121   u32 hw_if_index;
122 } rdma_input_trace_t;
123
124 #define foreach_rdma_tx_func_error             \
125 _(NO_FREE_SLOTS, "no free tx slots")
126
127 typedef enum
128 {
129 #define _(f,s) RDMA_TX_ERROR_##f,
130   foreach_rdma_tx_func_error
131 #undef _
132     RDMA_TX_N_ERROR,
133 } rdma_tx_func_error_t;
134
135 #endif /* AVF_H */
136
137 /*
138  * fd.io coding-style-patch-verification: ON
139  *
140  * Local Variables:
141  * eval: (c-set-style "gnu")
142  * End:
143  */