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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
21 #include <infiniband/verbs.h>
23 #include <vlib/pci/pci.h>
24 #include <vnet/interface.h>
25 #include <vnet/ethernet/mac_address.h>
26 #include <rdma/rdma_mlx5dv.h>
28 #define foreach_rdma_device_flags \
29 _(0, ERROR, "error") \
30 _(1, ADMIN_UP, "admin-up") \
31 _(2, LINK_UP, "link-up") \
32 _(3, PROMISC, "promiscuous") \
33 _(4, MLX5DV, "mlx5dv")
37 #define _(a, b, c) RDMA_DEVICE_F_##b = (1 << a),
38 foreach_rdma_device_flags
42 #ifndef MLX5_ETH_L2_INLINE_HEADER_SIZE
43 #define MLX5_ETH_L2_INLINE_HEADER_SIZE 18
48 CLIB_ALIGN_MARK (align0, MLX5_SEND_WQE_BB);
51 struct mlx5_wqe_ctrl_seg ctrl;
60 struct mlx5_wqe_eth_seg eseg;
61 struct mlx5_wqe_data_seg dseg;
63 #define RDMA_MLX5_WQE_SZ sizeof(rdma_mlx5_wqe_t)
64 #define RDMA_MLX5_WQE_DS (RDMA_MLX5_WQE_SZ/sizeof(struct mlx5_wqe_data_seg))
65 STATIC_ASSERT (RDMA_MLX5_WQE_SZ == MLX5_SEND_WQE_BB &&
66 RDMA_MLX5_WQE_SZ % sizeof (struct mlx5_wqe_data_seg) == 0,
71 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
94 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
96 /* following fields are accessed in datapath */
103 /* ibverb datapath. Cache of cq, sq below */
104 struct ibv_cq *ibv_cq;
105 struct ibv_qp *ibv_qp;
109 /* direct verbs datapath */
110 rdma_mlx5_wqe_t *dv_sq_wqes;
111 volatile u32 *dv_sq_dbrec;
112 volatile u64 *dv_sq_db;
113 struct mlx5_cqe64 *dv_cq_cqes;
114 volatile u32 *dv_cq_dbrec;
118 u32 *bufs; /* vlib_buffer ring buffer */
121 u16 dv_cq_idx; /* monotonic CQE index (valid only for direct verbs) */
122 u8 bufs_log2sz; /* log2 vlib_buffer entries */
123 u8 dv_sq_log2sz:4; /* log2 SQ WQE entries (valid only for direct verbs) */
124 u8 dv_cq_log2sz:4; /* log2 CQ CQE entries (valid only for direct verbs) */
125 STRUCT_MARK (cacheline1);
127 /* WQE template (valid only for direct verbs) */
130 /* end of 2nd 64-bytes cacheline (or 1st 128-bytes cacheline) */
131 STRUCT_MARK (cacheline2);
133 /* fields below are not accessed in datapath */
138 STATIC_ASSERT_OFFSET_OF (rdma_txq_t, cacheline1, 64);
139 STATIC_ASSERT_OFFSET_OF (rdma_txq_t, cacheline2, 128);
141 #define RDMA_TXQ_DV_INVALID_ID 0xffffffff
143 #define RDMA_TXQ_BUF_SZ(txq) (1U << (txq)->bufs_log2sz)
144 #define RDMA_TXQ_DV_SQ_SZ(txq) (1U << (txq)->dv_sq_log2sz)
145 #define RDMA_TXQ_DV_CQ_SZ(txq) (1U << (txq)->dv_cq_log2sz)
147 #define RDMA_TXQ_USED_SZ(head, tail) ((u16)((u16)(tail) - (u16)(head)))
148 #define RDMA_TXQ_AVAIL_SZ(txq, head, tail) ((u16)(RDMA_TXQ_BUF_SZ (txq) - RDMA_TXQ_USED_SZ (head, tail)))
152 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
154 /* following fields are accessed in datapath */
158 u32 per_interface_next_index;
161 u32 lkey; /* cache of mr->lkey */
162 u8 pool; /* buffer pool index */
164 /* fields below are not accessed in datapath */
165 vlib_pci_device_info_t *pci;
168 mac_address_t hwaddr;
169 u32 async_event_clib_file_index;
172 struct ibv_context *ctx;
175 struct ibv_qp *rx_qp;
176 struct ibv_rwq_ind_table *rx_rwq_ind_tbl;
177 struct ibv_flow *flow_ucast;
178 struct ibv_flow *flow_mcast;
185 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
188 u16 cqe_flags[VLIB_FRAME_SIZE];
189 u16x8 cqe_flags8[VLIB_FRAME_SIZE / 8];
190 u16x16 cqe_flags16[VLIB_FRAME_SIZE / 16];
192 vlib_buffer_t buffer_template;
193 } rdma_per_thread_data_t;
197 rdma_per_thread_data_t *per_thread_data;
198 rdma_device_t *devices;
199 vlib_log_class_t log_class;
203 extern rdma_main_t rdma_main;
225 } rdma_create_if_args_t;
227 void rdma_create_if (vlib_main_t * vm, rdma_create_if_args_t * args);
228 void rdma_delete_if (vlib_main_t * vm, rdma_device_t * rd);
230 extern vlib_node_registration_t rdma_input_node;
231 extern vnet_device_class_t rdma_device_class;
233 format_function_t format_rdma_device;
234 format_function_t format_rdma_device_name;
235 format_function_t format_rdma_input_trace;
236 format_function_t format_rdma_rxq;
237 unformat_function_t unformat_rdma_create_if_args;
244 } rdma_input_trace_t;
246 #define foreach_rdma_tx_func_error \
247 _(SEGMENT_SIZE_EXCEEDED, "segment size exceeded") \
248 _(NO_FREE_SLOTS, "no free tx slots") \
249 _(SUBMISSION, "tx submission errors") \
250 _(COMPLETION, "tx completion errors")
254 #define _(f,s) RDMA_TX_ERROR_##f,
255 foreach_rdma_tx_func_error
258 } rdma_tx_func_error_t;
260 #endif /* _RDMA_H_ */
263 * fd.io coding-style-patch-verification: ON
266 * eval: (c-set-style "gnu")