rdma: implement striding rq for multiseg rx
[vpp.git] / src / plugins / rdma / rdma_mlx5dv.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2020 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_MLX5DV_H_
19 #define _RDMA_MLX5DV_H_
20
21 #undef always_inline
22 #include <infiniband/mlx5dv.h>
23 #define always_inline static_always_inline
24 #include <vppinfra/types.h>
25 #include <vppinfra/error.h>
26 /* CQE flags - bits 16-31 of qword at offset 0x1c */
27 #define CQE_FLAG_L4_OK                  10
28 #define CQE_FLAG_L3_OK                  9
29 #define CQE_FLAG_L2_OK                  8
30 #define CQE_FLAG_IP_FRAG                7
31 #define CQE_FLAG_L4_HDR_TYPE(f)         (((f) >> 4) & 7)
32 #define CQE_FLAG_L3_HDR_TYPE_SHIFT      (2)
33 #define CQE_FLAG_L3_HDR_TYPE_MASK       (3 << CQE_FLAG_L3_HDR_TYPE_SHIFT)
34 #define CQE_FLAG_L3_HDR_TYPE(f)         (((f) & CQE_FLAG_L3_HDR_TYPE_MASK)  >> CQE_FLAG_L3_HDR_TYPE_SHIFT)
35 #define CQE_FLAG_L3_HDR_TYPE_IP4        1
36 #define CQE_FLAG_L3_HDR_TYPE_IP6        2
37 #define CQE_FLAG_IP_EXT_OPTS            1
38
39 /* CQE byte count (Striding RQ) */
40 #define CQE_BC_FILLER_MASK (1 << 31)
41 #define CQE_BC_CONSUMED_STRIDES_SHIFT (16)
42 #define CQE_BC_CONSUMED_STRIDES_MASK (0x3fff << CQE_BC_CONSUMED_STRIDES_SHIFT)
43 #define CQE_BC_BYTE_COUNT_MASK (0xffff)
44 typedef struct
45 {
46   struct
47   {
48     u8 pad1[28];
49     u16 flags;
50     u8 pad2[14];
51     union
52     {
53       u32 byte_cnt;
54       u32 mini_cqe_num;
55     };
56     u8 pad3[12];
57     u16 wqe_counter;
58     u8 signature;
59     u8 opcode_cqefmt_se_owner;
60   };
61 } mlx5dv_cqe_t;
62
63 STATIC_ASSERT_SIZEOF (mlx5dv_cqe_t, 64);
64
65 typedef struct
66 {
67   union
68   {
69     u32 checksum;
70     u32 rx_hash_result;
71   };
72   u32 byte_count;
73 } mlx5dv_mini_cqe_t;
74
75 typedef struct
76 {
77   u64 dsz_and_lkey;
78   u64 addr;
79 } mlx5dv_wqe_ds_t;              /* a WQE data segment */
80
81 typedef struct
82 {
83   u8 rsvd0[2];
84   u16 next_wqe_index;
85   u8 signature;
86   u8 rsvd1[11];
87 } mlx5dv_wqe_srq_next_t;
88
89 #define foreach_cqe_rx_field \
90   _(0x1c, 26, 26, l4_ok)        \
91   _(0x1c, 25, 25, l3_ok)        \
92   _(0x1c, 24, 24, l2_ok)        \
93   _(0x1c, 23, 23, ip_frag)      \
94   _(0x1c, 22, 20, l4_hdr_type)  \
95   _(0x1c, 19, 18, l3_hdr_type)  \
96   _(0x1c, 17, 17, ip_ext_opts)  \
97   _(0x1c, 16, 16, cv)   \
98   _(0x2c, 31,  0, byte_cnt)     \
99   _(0x30, 63,  0, timestamp)    \
100   _(0x38, 31, 24, rx_drop_counter)      \
101   _(0x38, 23,  0, flow_tag)     \
102   _(0x3c, 31, 16, wqe_counter)  \
103   _(0x3c, 15,  8, signature)    \
104   _(0x3c,  7,  4, opcode)       \
105   _(0x3c,  3,  2, cqe_format)   \
106   _(0x3c,  1,  1, sc)   \
107   _(0x3c,  0,  0, owner)
108
109
110 /* inline functions */
111
112 static inline u32
113 mlx5_get_u32 (void *start, int offset)
114 {
115   return clib_net_to_host_u32 (*(u32 *) (((u8 *) start) + offset));
116 }
117
118 static inline u64
119 mlx5_get_u64 (void *start, int offset)
120 {
121   return clib_net_to_host_u64 (*(u64 *) (((u8 *) start) + offset));
122 }
123
124 static inline void
125 mlx5_set_u32 (void *start, int offset, u32 value)
126 {
127   (*(u32 *) (((u8 *) start) + offset)) = clib_host_to_net_u32 (value);
128 }
129
130 static inline void
131 mlx5_set_u64 (void *start, int offset, u64 value)
132 {
133   (*(u64 *) (((u8 *) start) + offset)) = clib_host_to_net_u64 (value);
134 }
135
136 static inline void
137 mlx5_set_bits (void *start, int offset, int first, int last, u32 value)
138 {
139   u32 mask = (1 << (first - last + 1)) - 1;
140   u32 old = mlx5_get_u32 (start, offset);
141   if ((last == 0) && (first == 31))
142     {
143       mlx5_set_u32 (start, offset, value);
144       return;
145     }
146   ASSERT (value == (value & mask));
147   value &= mask;
148   old &= ~(mask << last);
149   mlx5_set_u32 (start, offset, old | value << last);
150 }
151
152 static inline u32
153 mlx5_get_bits (void *start, int offset, int first, int last)
154 {
155   u32 value = mlx5_get_u32 (start, offset);
156   if ((last == 0) && (first == 31))
157     return value;
158   value >>= last;
159   value &= (1 << (first - last + 1)) - 1;
160   return value;
161 }
162
163
164 #endif /* RDMA_MLX5DV_H */
165
166 /*
167  * fd.io coding-style-patch-verification: ON
168  *
169  * Local Variables:
170  * eval: (c-set-style "gnu")
171  * End:
172  */