2 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #include <linux/interrupt.h>
38 #include <rdma/rdma_user_rxe.h>
42 static inline int pkey_match(u16 key1, u16 key2)
44 return (((key1 & 0x7fff) != 0) &&
45 ((key1 & 0x7fff) == (key2 & 0x7fff)) &&
46 ((key1 & 0x8000) || (key2 & 0x8000))) ? 1 : 0;
49 /* Return >0 if psn_a > psn_b
53 static inline int psn_compare(u32 psn_a, u32 psn_b)
57 diff = (psn_a - psn_b) << 8;
62 struct rxe_pool_entry pelem;
63 struct ib_ucontext ibuc;
67 struct rxe_pool_entry pelem;
72 struct rxe_pool_entry pelem;
81 struct ib_uverbs_wc uibwc;
86 struct rxe_pool_entry pelem;
88 struct rxe_queue *queue;
92 struct tasklet_struct comp_task;
107 spinlock_t sq_lock; /* guard queue */
108 struct rxe_queue *queue;
114 spinlock_t producer_lock; /* guard queue producer */
115 spinlock_t consumer_lock; /* guard queue consumer */
116 struct rxe_queue *queue;
120 struct rxe_pool_entry pelem;
134 QP_STATE_DRAIN, /* req only */
135 QP_STATE_DRAINED, /* req only */
139 extern char *rxe_qp_state_name[];
141 struct rxe_req_info {
142 enum rxe_qp_state state;
152 struct rxe_task task;
155 struct rxe_comp_info {
162 struct rxe_task task;
165 enum rdatm_res_state {
166 rdatm_res_state_next,
168 rdatm_res_state_replay,
176 enum rdatm_res_state state;
193 struct rxe_resp_info {
194 enum rxe_qp_state state;
201 enum ib_wc_status status;
205 struct rxe_recv_wqe *wqe;
207 /* RDMA read / atomic only */
216 struct rxe_recv_wqe wqe;
217 struct ib_sge sge[RXE_MAX_SGE];
220 /* Responder resources. It's a circular list where the oldest
221 * resource is dropped first.
223 struct resp_res *resources;
224 unsigned int res_head;
225 unsigned int res_tail;
226 struct resp_res *res;
227 struct rxe_task task;
231 struct rxe_pool_entry pelem;
233 struct ib_qp_attr attr;
243 enum ib_sig_type sq_sig_type;
250 struct rxe_av pri_av;
251 struct rxe_av alt_av;
253 /* list of mcast groups qp has joined (for cleanup) */
254 struct list_head grp_list;
255 spinlock_t grp_lock; /* guard grp_list */
257 struct sk_buff_head req_pkts;
258 struct sk_buff_head resp_pkts;
259 struct sk_buff_head send_pkts;
261 struct rxe_req_info req;
262 struct rxe_comp_info comp;
263 struct rxe_resp_info resp;
269 /* Timer for retranmitting packet when ACKs have been lost. RC
270 * only. The requester sets it when it is not already
271 * started. The responder resets it whenever an ack is
274 struct timer_list retrans_timer;
275 u64 qp_timeout_jiffies;
277 /* Timer for handling RNR NAKS. */
278 struct timer_list rnr_nak_timer;
280 spinlock_t state_lock; /* guard requester and completer */
284 RXE_MEM_STATE_ZOMBIE,
285 RXE_MEM_STATE_INVALID,
298 #define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf))
300 struct rxe_phys_buf {
306 struct rxe_phys_buf buf[RXE_BUF_PER_MAP];
310 struct rxe_pool_entry pelem;
317 struct ib_umem *umem;
322 enum rxe_mem_state state;
323 enum rxe_mem_type type;
341 struct rxe_map **map;
345 struct rxe_pool_entry pelem;
346 spinlock_t mcg_lock; /* guard group */
348 struct list_head qp_list;
356 struct rxe_pool_entry pelem;
357 struct list_head qp_list;
358 struct list_head grp_list;
360 struct rxe_mc_grp *grp;
364 struct ib_port_attr attr;
367 __be64 subnet_prefix;
368 spinlock_t port_lock; /* guard port */
369 unsigned int mtu_cap;
376 struct ib_device ib_dev;
377 struct ib_device_attr attr;
381 struct mutex usdev_lock;
383 struct net_device *ndev;
387 struct rxe_pool uc_pool;
388 struct rxe_pool pd_pool;
389 struct rxe_pool ah_pool;
390 struct rxe_pool srq_pool;
391 struct rxe_pool qp_pool;
392 struct rxe_pool cq_pool;
393 struct rxe_pool mr_pool;
394 struct rxe_pool mw_pool;
395 struct rxe_pool mc_grp_pool;
396 struct rxe_pool mc_elem_pool;
398 spinlock_t pending_lock; /* guard pending_mmaps */
399 struct list_head pending_mmaps;
401 spinlock_t mmap_offset_lock; /* guard mmap_offset */
404 struct rxe_port port;
405 struct list_head list;
408 static inline struct rxe_dev *to_rdev(struct ib_device *dev)
410 return dev ? container_of(dev, struct rxe_dev, ib_dev) : NULL;
413 static inline struct rxe_ucontext *to_ruc(struct ib_ucontext *uc)
415 return uc ? container_of(uc, struct rxe_ucontext, ibuc) : NULL;
418 static inline struct rxe_pd *to_rpd(struct ib_pd *pd)
420 return pd ? container_of(pd, struct rxe_pd, ibpd) : NULL;
423 static inline struct rxe_ah *to_rah(struct ib_ah *ah)
425 return ah ? container_of(ah, struct rxe_ah, ibah) : NULL;
428 static inline struct rxe_srq *to_rsrq(struct ib_srq *srq)
430 return srq ? container_of(srq, struct rxe_srq, ibsrq) : NULL;
433 static inline struct rxe_qp *to_rqp(struct ib_qp *qp)
435 return qp ? container_of(qp, struct rxe_qp, ibqp) : NULL;
438 static inline struct rxe_cq *to_rcq(struct ib_cq *cq)
440 return cq ? container_of(cq, struct rxe_cq, ibcq) : NULL;
443 static inline struct rxe_mem *to_rmr(struct ib_mr *mr)
445 return mr ? container_of(mr, struct rxe_mem, ibmr) : NULL;
448 static inline struct rxe_mem *to_rmw(struct ib_mw *mw)
450 return mw ? container_of(mw, struct rxe_mem, ibmw) : NULL;
453 int rxe_register_device(struct rxe_dev *rxe);
454 int rxe_unregister_device(struct rxe_dev *rxe);
456 void rxe_mc_cleanup(struct rxe_pool_entry *arg);
458 #endif /* RXE_VERBS_H */