1 /*-
2 * SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
3 *
4 * Copyright (c) 2021 - 2022 Intel Corporation
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenFabrics.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34 /*$FreeBSD$*/
35
36 #ifndef FBSD_KCOMPAT_H
37 #define FBSD_KCOMPAT_H
38 #include "ice_rdma.h"
39
40 #define TASKLET_DATA_TYPE unsigned long
41 #define TASKLET_FUNC_TYPE void (*)(TASKLET_DATA_TYPE)
42
43 #define tasklet_setup(tasklet, callback) \
44 tasklet_init((tasklet), (TASKLET_FUNC_TYPE)(callback), \
45 (TASKLET_DATA_TYPE)(tasklet))
46
47 #ifndef from_tasklet
48 #define from_tasklet(var, callback_tasklet, tasklet_fieldname) \
49 container_of(callback_tasklet, typeof(*var), tasklet_fieldname)
50 #endif
51
52 #define IRDMA_SET_RDMA_OBJ_SIZE(ib_struct, drv_struct, member) \
53 (sizeof(struct drv_struct) + \
54 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) + \
55 BUILD_BUG_ON_ZERO( \
56 !__same_type(((struct drv_struct *)NULL)->member, \
57 struct ib_struct)))
58
59 #define set_ibdev_dma_device(ibdev, dev) \
60 ibdev.dma_device = (dev)
61 #define set_max_sge(props, rf) \
62 ((props)->max_sge = (rf)->sc_dev.hw_attrs.uk_attrs.max_hw_wq_frags)
63 #define kc_set_props_ip_gid_caps(props) \
64 ((props)->port_cap_flags |= IB_PORT_IP_BASED_GIDS)
65 #define rdma_query_gid(ibdev, port, index, gid) \
66 ib_get_cached_gid(ibdev, port, index, gid, NULL)
67 #define kmap(pg) page_address(pg)
68 #define kmap_local_page(pg) page_address(pg)
69 #define kunmap(pg)
70 #define kunmap_local(pg)
71 #define kc_free_lsmm_dereg_mr(iwdev, iwqp) \
72 ((iwdev)->ibdev.dereg_mr((iwqp)->lsmm_mr, NULL))
73
74 #define IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION IB_CQ_FLAGS_TIMESTAMP_COMPLETION
75 #define kc_irdma_destroy_qp(ibqp, udata) irdma_destroy_qp(ibqp, udata)
76 #ifndef IB_QP_ATTR_STANDARD_BITS
77 #define IB_QP_ATTR_STANDARD_BITS GENMASK(20, 0)
78 #endif
79
80 #define IRDMA_QOS_MODE_VLAN 0x0
81 #define IRDMA_QOS_MODE_DSCP 0x1
82
83 #define IRDMA_VER_LEN 24
84
85 void kc_set_roce_uverbs_cmd_mask(struct irdma_device *iwdev);
86 void kc_set_rdma_uverbs_cmd_mask(struct irdma_device *iwdev);
87
88 struct irdma_tunable_info {
89 struct sysctl_ctx_list irdma_sysctl_ctx;
90 struct sysctl_oid *irdma_sysctl_tree;
91 char drv_ver[IRDMA_VER_LEN];
92 u8 roce_ena;
93 };
94
95 static inline int irdma_iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
96 u16 *pkey)
97 {
98 *pkey = 0;
99 return 0;
100 }
101
102 static inline int cq_validate_flags(u32 flags, u8 hw_rev)
103 {
104 /* GEN1 does not support CQ create flags */
105 if (hw_rev == IRDMA_GEN_1)
106 return flags ? -EOPNOTSUPP : 0;
107
108 return flags & ~IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION ? -EOPNOTSUPP : 0;
109 }
110 static inline u64 *irdma_next_pbl_addr(u64 *pbl, struct irdma_pble_info **pinfo,
111 u32 *idx)
112 {
113 *idx += 1;
114 if (!(*pinfo) || *idx != (*pinfo)->cnt)
115 return ++pbl;
116 *idx = 0;
117 (*pinfo)++;
118
119 return (*pinfo)->addr;
120 }
121 int irdma_create_cq(struct ib_cq *ibcq,
122 const struct ib_cq_init_attr *attr,
123 struct ib_udata *udata);
124 struct ib_qp *irdma_create_qp(struct ib_pd *ibpd,
125 struct ib_qp_init_attr *init_attr,
126 struct ib_udata *udata);
127 int irdma_create_ah(struct ib_ah *ib_ah,
128 struct ib_ah_attr *attr, u32 flags,
129 struct ib_udata *udata);
130 int irdma_create_ah_stub(struct ib_ah *ib_ah,
131 struct ib_ah_attr *attr, u32 flags,
132 struct ib_udata *udata);
133 void irdma_ether_copy(u8 *dmac, struct ib_ah_attr *attr);
134
135 void irdma_destroy_ah(struct ib_ah *ibah, u32 flags);
136 void irdma_destroy_ah_stub(struct ib_ah *ibah, u32 flags);
137 int irdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
138 int irdma_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata);
139 void irdma_get_eth_speed_and_width(u32 link_speed, u8 *active_speed,
140 u8 *active_width);
141 enum rdma_link_layer irdma_get_link_layer(struct ib_device *ibdev,
142 u8 port_num);
143 int irdma_roce_port_immutable(struct ib_device *ibdev, u8 port_num,
144 struct ib_port_immutable *immutable);
145 int irdma_iw_port_immutable(struct ib_device *ibdev, u8 port_num,
146 struct ib_port_immutable *immutable);
147 int irdma_query_gid(struct ib_device *ibdev, u8 port, int index,
148 union ib_gid *gid);
149 int irdma_query_gid_roce(struct ib_device *ibdev, u8 port, int index,
150 union ib_gid *gid);
151 int irdma_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
152 u16 *pkey);
153 int irdma_query_port(struct ib_device *ibdev, u8 port,
154 struct ib_port_attr *props);
155 struct rdma_hw_stats *irdma_alloc_hw_stats(struct ib_device *ibdev, u8 port_num);
156 int irdma_get_hw_stats(struct ib_device *ibdev,
157 struct rdma_hw_stats *stats, u8 port_num,
158 int index);
159
160 int irdma_register_qset(struct irdma_sc_vsi *vsi,
161 struct irdma_ws_node *tc_node);
162 void irdma_unregister_qset(struct irdma_sc_vsi *vsi,
163 struct irdma_ws_node *tc_node);
164 void ib_unregister_device(struct ib_device *ibdev);
165 void irdma_disassociate_ucontext(struct ib_ucontext *context);
166 int kc_irdma_set_roce_cm_info(struct irdma_qp *iwqp,
167 struct ib_qp_attr *attr,
168 u16 *vlan_id);
169 struct irdma_device *kc_irdma_get_device(struct ifnet *netdev);
170 void kc_irdma_put_device(struct irdma_device *iwdev);
171
172 void kc_set_loc_seq_num_mss(struct irdma_cm_node *cm_node);
173 u16 kc_rdma_get_udp_sport(u32 fl, u32 lqpn, u32 rqpn);
174
175 void irdma_get_dev_fw_str(struct ib_device *dev, char *str, size_t str_len);
176
177 int irdma_modify_port(struct ib_device *ibdev, u8 port, int mask,
178 struct ib_port_modify *props);
179 int irdma_get_dst_mac(struct irdma_cm_node *cm_node, struct sockaddr *dst_sin,
180 u8 *dst_mac);
181 int irdma_resolve_neigh_lpb_chk(struct irdma_device *iwdev, struct irdma_cm_node *cm_node,
182 struct irdma_cm_info *cm_info);
183 int irdma_addr_resolve_neigh(struct irdma_cm_node *cm_node, u32 dst_ip,
184 int arpindex);
185 int irdma_addr_resolve_neigh_ipv6(struct irdma_cm_node *cm_node, u32 *dest,
186 int arpindex);
187 void irdma_dcqcn_tunables_init(struct irdma_pci_f *rf);
188 u32 irdma_create_stag(struct irdma_device *iwdev);
189 void irdma_free_stag(struct irdma_device *iwdev, u32 stag);
190
191 int irdma_hwdereg_mr(struct ib_mr *ib_mr);
192 int irdma_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start, u64 len,
193 u64 virt, int new_access, struct ib_pd *new_pd,
194 struct ib_udata *udata);
195 struct irdma_mr;
196 struct irdma_cq;
197 struct irdma_cq_buf;
198 struct ib_mr *irdma_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
199 u32 max_num_sg, struct ib_udata *udata);
200 int irdma_hwreg_mr(struct irdma_device *iwdev, struct irdma_mr *iwmr,
201 u16 access);
202 struct ib_mr *irdma_rereg_mr_trans(struct irdma_mr *iwmr, u64 start, u64 len,
203 u64 virt, struct ib_udata *udata);
204 int irdma_hw_alloc_mw(struct irdma_device *iwdev, struct irdma_mr *iwmr);
205 struct ib_mw *irdma_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
206 struct ib_udata *udata);
207 int irdma_hw_alloc_stag(struct irdma_device *iwdev, struct irdma_mr *iwmr);
208 void irdma_cq_free_rsrc(struct irdma_pci_f *rf, struct irdma_cq *iwcq);
209 int irdma_validate_qp_attrs(struct ib_qp_init_attr *init_attr,
210 struct irdma_device *iwdev);
211 void irdma_setup_virt_qp(struct irdma_device *iwdev,
212 struct irdma_qp *iwqp,
213 struct irdma_qp_init_info *init_info);
214 int irdma_setup_kmode_qp(struct irdma_device *iwdev,
215 struct irdma_qp *iwqp,
216 struct irdma_qp_init_info *info,
217 struct ib_qp_init_attr *init_attr);
218 int irdma_setup_umode_qp(struct ib_udata *udata,
219 struct irdma_device *iwdev,
220 struct irdma_qp *iwqp,
221 struct irdma_qp_init_info *info,
222 struct ib_qp_init_attr *init_attr);
223 void irdma_roce_fill_and_set_qpctx_info(struct irdma_qp *iwqp,
224 struct irdma_qp_host_ctx_info *ctx_info);
225 void irdma_iw_fill_and_set_qpctx_info(struct irdma_qp *iwqp,
226 struct irdma_qp_host_ctx_info *ctx_info);
227 int irdma_cqp_create_qp_cmd(struct irdma_qp *iwqp);
228 void irdma_dealloc_push_page(struct irdma_pci_f *rf,
229 struct irdma_sc_qp *qp);
230 int irdma_process_resize_list(struct irdma_cq *iwcq, struct irdma_device *iwdev,
231 struct irdma_cq_buf *lcqe_buf);
232 void irdma_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata);
233 int irdma_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata);
234 void irdma_dealloc_ucontext(struct ib_ucontext *context);
235 int irdma_alloc_pd(struct ib_pd *pd, struct ib_udata *udata);
236 void irdma_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
237 int irdma_add_gid(struct ib_device *, u8, unsigned int, const union ib_gid *,
238 const struct ib_gid_attr *, void **);
239 int irdma_del_gid(struct ib_device *, u8, unsigned int, void **);
240 struct ib_device *ib_device_get_by_netdev(struct ifnet *ndev, int driver_id);
241 void ib_device_put(struct ib_device *device);
242 void ib_unregister_device_put(struct ib_device *device);
243 enum ib_mtu ib_mtu_int_to_enum(int mtu);
244 struct irdma_pbl *irdma_get_pbl(unsigned long va, struct list_head *pbl_list);
245 void irdma_clean_cqes(struct irdma_qp *iwqp, struct irdma_cq *iwcq);
246 void irdma_remove_push_mmap_entries(struct irdma_qp *iwqp);
247
248 struct irdma_ucontext;
249 void irdma_del_memlist(struct irdma_mr *iwmr, struct irdma_ucontext *ucontext);
250 void irdma_copy_user_pgaddrs(struct irdma_mr *iwmr, u64 *pbl,
251 enum irdma_pble_level level);
252 void irdma_reg_ipaddr_event_cb(struct irdma_pci_f *rf);
253 void irdma_dereg_ipaddr_event_cb(struct irdma_pci_f *rf);
254
255 /* Introduced in this series https://lore.kernel.org/linux-rdma/0-v2-270386b7e60b+28f4-umem_1_jgg@nvidia.com/
256 * An irdma version helper doing same for older functions with difference that iova is passed in
257 * as opposed to derived from umem->iova.
258 */
259 static inline size_t irdma_ib_umem_num_dma_blocks(struct ib_umem *umem, unsigned long pgsz, u64 iova)
260 {
261 /* some older OFED distros do not have ALIGN_DOWN */
262 #ifndef ALIGN_DOWN
263 #define ALIGN_DOWN(x, a) ALIGN((x) - ((a) - 1), (a))
264 #endif
265
266 return (size_t)((ALIGN(iova + umem->length, pgsz) -
267 ALIGN_DOWN(iova, pgsz))) / pgsz;
268 }
269
270 #endif /* FBSD_KCOMPAT_H */
Cache object: 6966cf11743fa24aa160c675ef771c5c
|