1 /*- 2 * SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB 3 * 4 * Copyright (c) 2015 - 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 IRDMA_VERBS_H 37 #define IRDMA_VERBS_H 38 39 #define IRDMA_MAX_SAVED_PHY_PGADDR 4 40 #define IRDMA_FLUSH_DELAY_MS 20 41 42 #define IRDMA_PKEY_TBL_SZ 1 43 #define IRDMA_DEFAULT_PKEY 0xFFFF 44 45 #define iwdev_to_idev(iwdev) (&(iwdev)->rf->sc_dev) 46 47 struct irdma_ucontext { 48 struct ib_ucontext ibucontext; 49 struct irdma_device *iwdev; 50 #if __FreeBSD_version >= 1400026 51 struct rdma_user_mmap_entry *db_mmap_entry; 52 #else 53 struct irdma_user_mmap_entry *db_mmap_entry; 54 DECLARE_HASHTABLE(mmap_hash_tbl, 6); 55 spinlock_t mmap_tbl_lock; /* protect mmap hash table entries */ 56 #endif 57 struct list_head cq_reg_mem_list; 58 spinlock_t cq_reg_mem_list_lock; /* protect CQ memory list */ 59 struct list_head qp_reg_mem_list; 60 spinlock_t qp_reg_mem_list_lock; /* protect QP memory list */ 61 /* FIXME: Move to kcompat ideally. Used < 4.20.0 for old diassasscoaite flow */ 62 struct list_head vma_list; 63 struct mutex vma_list_mutex; /* protect the vma_list */ 64 int abi_ver; 65 bool legacy_mode:1; 66 bool use_raw_attrs:1; 67 }; 68 69 struct irdma_pd { 70 struct ib_pd ibpd; 71 struct irdma_sc_pd sc_pd; 72 struct list_head udqp_list; 73 spinlock_t udqp_list_lock; 74 }; 75 76 struct irdma_av { 77 u8 macaddr[16]; 78 struct ib_ah_attr attrs; 79 union { 80 struct sockaddr saddr; 81 struct sockaddr_in saddr_in; 82 struct sockaddr_in6 saddr_in6; 83 } sgid_addr, dgid_addr; 84 u8 net_type; 85 }; 86 87 struct irdma_ah { 88 struct ib_ah ibah; 89 struct irdma_sc_ah sc_ah; 90 struct irdma_pd *pd; 91 struct irdma_av av; 92 u8 sgid_index; 93 union ib_gid dgid; 94 }; 95 96 struct irdma_hmc_pble { 97 union { 98 u32 idx; 99 dma_addr_t addr; 100 }; 101 }; 102 103 struct irdma_cq_mr { 104 struct irdma_hmc_pble cq_pbl; 105 dma_addr_t shadow; 106 bool split; 107 }; 108 109 struct irdma_qp_mr { 110 struct irdma_hmc_pble sq_pbl; 111 struct irdma_hmc_pble rq_pbl; 112 dma_addr_t shadow; 113 struct page *sq_page; 114 }; 115 116 struct irdma_cq_buf { 117 struct irdma_dma_mem kmem_buf; 118 struct irdma_cq_uk cq_uk; 119 struct irdma_hw *hw; 120 struct list_head list; 121 struct work_struct work; 122 }; 123 124 struct irdma_pbl { 125 struct list_head list; 126 union { 127 struct irdma_qp_mr qp_mr; 128 struct irdma_cq_mr cq_mr; 129 }; 130 131 bool pbl_allocated:1; 132 bool on_list:1; 133 u64 user_base; 134 struct irdma_pble_alloc pble_alloc; 135 struct irdma_mr *iwmr; 136 }; 137 138 struct irdma_mr { 139 union { 140 struct ib_mr ibmr; 141 struct ib_mw ibmw; 142 }; 143 struct ib_umem *region; 144 int access; 145 u8 is_hwreg; 146 u16 type; 147 u32 page_cnt; 148 u64 page_size; 149 u64 page_msk; 150 u32 npages; 151 u32 stag; 152 u64 len; 153 u64 pgaddrmem[IRDMA_MAX_SAVED_PHY_PGADDR]; 154 struct irdma_pbl iwpbl; 155 }; 156 157 struct irdma_cq { 158 struct ib_cq ibcq; 159 struct irdma_sc_cq sc_cq; 160 u16 cq_head; 161 u16 cq_size; 162 u16 cq_num; 163 bool user_mode; 164 atomic_t armed; 165 enum irdma_cmpl_notify last_notify; 166 u32 polled_cmpls; 167 u32 cq_mem_size; 168 struct irdma_dma_mem kmem; 169 struct irdma_dma_mem kmem_shadow; 170 struct completion free_cq; 171 atomic_t refcnt; 172 spinlock_t lock; /* for poll cq */ 173 struct irdma_pbl *iwpbl; 174 struct irdma_pbl *iwpbl_shadow; 175 struct list_head resize_list; 176 struct irdma_cq_poll_info cur_cqe; 177 struct list_head cmpl_generated; 178 }; 179 180 struct irdma_cmpl_gen { 181 struct list_head list; 182 struct irdma_cq_poll_info cpi; 183 }; 184 185 struct disconn_work { 186 struct work_struct work; 187 struct irdma_qp *iwqp; 188 }; 189 190 struct if_notify_work { 191 struct work_struct work; 192 struct irdma_device *iwdev; 193 u32 ipaddr[4]; 194 u16 vlan_id; 195 bool ipv4:1; 196 bool ifup:1; 197 }; 198 199 struct iw_cm_id; 200 201 struct irdma_qp_kmode { 202 struct irdma_dma_mem dma_mem; 203 u32 *sig_trk_mem; 204 struct irdma_sq_uk_wr_trk_info *sq_wrid_mem; 205 u64 *rq_wrid_mem; 206 }; 207 208 struct irdma_qp { 209 struct ib_qp ibqp; 210 struct irdma_sc_qp sc_qp; 211 struct irdma_device *iwdev; 212 struct irdma_cq *iwscq; 213 struct irdma_cq *iwrcq; 214 struct irdma_pd *iwpd; 215 #if __FreeBSD_version >= 1400026 216 struct rdma_user_mmap_entry *push_wqe_mmap_entry; 217 struct rdma_user_mmap_entry *push_db_mmap_entry; 218 #else 219 struct irdma_user_mmap_entry *push_wqe_mmap_entry; 220 struct irdma_user_mmap_entry *push_db_mmap_entry; 221 #endif 222 struct irdma_qp_host_ctx_info ctx_info; 223 union { 224 struct irdma_iwarp_offload_info iwarp_info; 225 struct irdma_roce_offload_info roce_info; 226 }; 227 228 union { 229 struct irdma_tcp_offload_info tcp_info; 230 struct irdma_udp_offload_info udp_info; 231 }; 232 233 struct irdma_ah roce_ah; 234 struct list_head teardown_entry; 235 struct list_head ud_list_elem; 236 atomic_t refcnt; 237 struct iw_cm_id *cm_id; 238 struct irdma_cm_node *cm_node; 239 struct delayed_work dwork_flush; 240 struct ib_mr *lsmm_mr; 241 atomic_t hw_mod_qp_pend; 242 enum ib_qp_state ibqp_state; 243 u32 qp_mem_size; 244 u32 last_aeq; 245 int max_send_wr; 246 int max_recv_wr; 247 atomic_t close_timer_started; 248 spinlock_t lock; /* serialize posting WRs to SQ/RQ */ 249 struct irdma_qp_context *iwqp_context; 250 void *pbl_vbase; 251 dma_addr_t pbl_pbase; 252 struct page *page; 253 u8 iwarp_state; 254 u16 term_sq_flush_code; 255 u16 term_rq_flush_code; 256 u8 hw_iwarp_state; 257 u8 hw_tcp_state; 258 struct irdma_qp_kmode kqp; 259 struct irdma_dma_mem host_ctx; 260 struct timer_list terminate_timer; 261 struct irdma_pbl *iwpbl; 262 struct irdma_sge *sg_list; 263 struct irdma_dma_mem q2_ctx_mem; 264 struct irdma_dma_mem ietf_mem; 265 struct completion free_qp; 266 wait_queue_head_t waitq; 267 wait_queue_head_t mod_qp_waitq; 268 u8 rts_ae_rcvd; 269 u8 active_conn : 1; 270 u8 user_mode : 1; 271 u8 hte_added : 1; 272 u8 flush_issued : 1; 273 u8 sig_all : 1; 274 u8 pau_mode : 1; 275 }; 276 277 struct irdma_udqs_work { 278 struct work_struct work; 279 struct irdma_qp *iwqp; 280 u8 user_prio; 281 bool qs_change:1; 282 }; 283 284 enum irdma_mmap_flag { 285 IRDMA_MMAP_IO_NC, 286 IRDMA_MMAP_IO_WC, 287 }; 288 289 struct irdma_user_mmap_entry { 290 #if __FreeBSD_version >= 1400026 291 struct rdma_user_mmap_entry rdma_entry; 292 #else 293 struct irdma_ucontext *ucontext; 294 struct hlist_node hlist; 295 u64 pgoff_key; /* Used to compute offset (in bytes) returned to user libc's mmap */ 296 #endif 297 u64 bar_offset; 298 u8 mmap_flag; 299 }; 300 301 static inline u16 irdma_fw_major_ver(struct irdma_sc_dev *dev) 302 { 303 return (u16)FIELD_GET(IRDMA_FW_VER_MAJOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]); 304 } 305 306 static inline u16 irdma_fw_minor_ver(struct irdma_sc_dev *dev) 307 { 308 return (u16)FIELD_GET(IRDMA_FW_VER_MINOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]); 309 } 310 311 /** 312 * irdma_mcast_mac_v4 - Get the multicast MAC for an IP address 313 * @ip_addr: IPv4 address 314 * @mac: pointer to result MAC address 315 * 316 */ 317 static inline void irdma_mcast_mac_v4(u32 *ip_addr, u8 *mac) 318 { 319 u8 *ip = (u8 *)ip_addr; 320 unsigned char mac4[ETH_ALEN] = {0x01, 0x00, 0x5E, ip[2] & 0x7F, ip[1], 321 ip[0]}; 322 323 ether_addr_copy(mac, mac4); 324 } 325 326 /** 327 * irdma_mcast_mac_v6 - Get the multicast MAC for an IP address 328 * @ip_addr: IPv6 address 329 * @mac: pointer to result MAC address 330 * 331 */ 332 static inline void irdma_mcast_mac_v6(u32 *ip_addr, u8 *mac) 333 { 334 u8 *ip = (u8 *)ip_addr; 335 unsigned char mac6[ETH_ALEN] = {0x33, 0x33, ip[3], ip[2], ip[1], ip[0]}; 336 337 ether_addr_copy(mac, mac6); 338 } 339 340 #if __FreeBSD_version >= 1400026 341 struct rdma_user_mmap_entry* 342 irdma_user_mmap_entry_insert(struct irdma_ucontext *ucontext, u64 bar_offset, 343 enum irdma_mmap_flag mmap_flag, u64 *mmap_offset); 344 #else 345 struct irdma_user_mmap_entry * 346 irdma_user_mmap_entry_add_hash(struct irdma_ucontext *ucontext, u64 bar_offset, 347 enum irdma_mmap_flag mmap_flag, u64 *mmap_offset); 348 void irdma_user_mmap_entry_del_hash(struct irdma_user_mmap_entry *entry); 349 #endif 350 int irdma_ib_register_device(struct irdma_device *iwdev); 351 void irdma_ib_unregister_device(struct irdma_device *iwdev); 352 void irdma_ib_qp_event(struct irdma_qp *iwqp, enum irdma_qp_event_type event); 353 void irdma_generate_flush_completions(struct irdma_qp *iwqp); 354 void irdma_remove_cmpls_list(struct irdma_cq *iwcq); 355 int irdma_generated_cmpls(struct irdma_cq *iwcq, struct irdma_cq_poll_info *cq_poll_info); 356 void irdma_sched_qp_flush_work(struct irdma_qp *iwqp); 357 void irdma_flush_worker(struct work_struct *work); 358 #endif /* IRDMA_VERBS_H */ 359