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 <linux/workqueue.h>
39 #include <rdma/rdma_user_rxe.h>
42 #include "rxe_hw_counters.h"
44 static inline int pkey_match(u16 key1
, u16 key2
)
46 return (((key1
& 0x7fff) != 0) &&
47 ((key1
& 0x7fff) == (key2
& 0x7fff)) &&
48 ((key1
& 0x8000) || (key2
& 0x8000))) ? 1 : 0;
51 /* Return >0 if psn_a > psn_b
55 static inline int psn_compare(u32 psn_a
, u32 psn_b
)
59 diff
= (psn_a
- psn_b
) << 8;
64 struct rxe_pool_entry pelem
;
65 struct ib_ucontext ibuc
;
69 struct rxe_pool_entry pelem
;
74 struct rxe_pool_entry pelem
;
83 struct ib_uverbs_wc uibwc
;
88 struct rxe_pool_entry pelem
;
90 struct rxe_queue
*queue
;
95 struct tasklet_struct comp_task
;
100 wqe_state_processing
,
110 spinlock_t sq_lock
; /* guard queue */
111 struct rxe_queue
*queue
;
117 spinlock_t producer_lock
; /* guard queue producer */
118 spinlock_t consumer_lock
; /* guard queue consumer */
119 struct rxe_queue
*queue
;
123 struct rxe_pool_entry pelem
;
137 QP_STATE_DRAIN
, /* req only */
138 QP_STATE_DRAINED
, /* req only */
142 struct rxe_req_info
{
143 enum rxe_qp_state state
;
153 struct rxe_task task
;
156 struct rxe_comp_info
{
164 struct rxe_task task
;
167 enum rdatm_res_state
{
168 rdatm_res_state_next
,
170 rdatm_res_state_replay
,
179 enum rdatm_res_state state
;
196 struct rxe_resp_info
{
197 enum rxe_qp_state state
;
205 enum ib_wc_status status
;
209 struct rxe_recv_wqe
*wqe
;
211 /* RDMA read / atomic only */
221 struct rxe_recv_wqe wqe
;
222 struct ib_sge sge
[RXE_MAX_SGE
];
225 /* Responder resources. It's a circular list where the oldest
226 * resource is dropped first.
228 struct resp_res
*resources
;
229 unsigned int res_head
;
230 unsigned int res_tail
;
231 struct resp_res
*res
;
232 struct rxe_task task
;
236 struct rxe_pool_entry pelem
;
238 struct ib_qp_attr attr
;
248 enum ib_sig_type sq_sig_type
;
256 struct rxe_av pri_av
;
257 struct rxe_av alt_av
;
259 /* list of mcast groups qp has joined (for cleanup) */
260 struct list_head grp_list
;
261 spinlock_t grp_lock
; /* guard grp_list */
263 struct sk_buff_head req_pkts
;
264 struct sk_buff_head resp_pkts
;
265 struct sk_buff_head send_pkts
;
267 struct rxe_req_info req
;
268 struct rxe_comp_info comp
;
269 struct rxe_resp_info resp
;
275 /* Timer for retranmitting packet when ACKs have been lost. RC
276 * only. The requester sets it when it is not already
277 * started. The responder resets it whenever an ack is
280 struct timer_list retrans_timer
;
281 u64 qp_timeout_jiffies
;
283 /* Timer for handling RNR NAKS. */
284 struct timer_list rnr_nak_timer
;
286 spinlock_t state_lock
; /* guard requester and completer */
288 struct execute_work cleanup_work
;
292 RXE_MEM_STATE_ZOMBIE
,
293 RXE_MEM_STATE_INVALID
,
306 #define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf))
308 struct rxe_phys_buf
{
314 struct rxe_phys_buf buf
[RXE_BUF_PER_MAP
];
318 struct rxe_pool_entry pelem
;
325 struct ib_umem
*umem
;
330 enum rxe_mem_state state
;
331 enum rxe_mem_type type
;
349 struct rxe_map
**map
;
353 struct rxe_pool_entry pelem
;
354 spinlock_t mcg_lock
; /* guard group */
356 struct list_head qp_list
;
364 struct rxe_pool_entry pelem
;
365 struct list_head qp_list
;
366 struct list_head grp_list
;
368 struct rxe_mc_grp
*grp
;
372 struct ib_port_attr attr
;
375 __be64 subnet_prefix
;
376 spinlock_t port_lock
; /* guard port */
377 unsigned int mtu_cap
;
384 struct ib_device ib_dev
;
385 struct ib_device_attr attr
;
389 struct mutex usdev_lock
;
391 struct net_device
*ndev
;
395 struct rxe_pool uc_pool
;
396 struct rxe_pool pd_pool
;
397 struct rxe_pool ah_pool
;
398 struct rxe_pool srq_pool
;
399 struct rxe_pool qp_pool
;
400 struct rxe_pool cq_pool
;
401 struct rxe_pool mr_pool
;
402 struct rxe_pool mw_pool
;
403 struct rxe_pool mc_grp_pool
;
404 struct rxe_pool mc_elem_pool
;
406 spinlock_t pending_lock
; /* guard pending_mmaps */
407 struct list_head pending_mmaps
;
409 spinlock_t mmap_offset_lock
; /* guard mmap_offset */
412 atomic64_t stats_counters
[RXE_NUM_OF_COUNTERS
];
414 struct rxe_port port
;
415 struct list_head list
;
416 struct crypto_shash
*tfm
;
419 static inline void rxe_counter_inc(struct rxe_dev
*rxe
, enum rxe_counters index
)
421 atomic64_inc(&rxe
->stats_counters
[index
]);
424 static inline struct rxe_dev
*to_rdev(struct ib_device
*dev
)
426 return dev
? container_of(dev
, struct rxe_dev
, ib_dev
) : NULL
;
429 static inline struct rxe_ucontext
*to_ruc(struct ib_ucontext
*uc
)
431 return uc
? container_of(uc
, struct rxe_ucontext
, ibuc
) : NULL
;
434 static inline struct rxe_pd
*to_rpd(struct ib_pd
*pd
)
436 return pd
? container_of(pd
, struct rxe_pd
, ibpd
) : NULL
;
439 static inline struct rxe_ah
*to_rah(struct ib_ah
*ah
)
441 return ah
? container_of(ah
, struct rxe_ah
, ibah
) : NULL
;
444 static inline struct rxe_srq
*to_rsrq(struct ib_srq
*srq
)
446 return srq
? container_of(srq
, struct rxe_srq
, ibsrq
) : NULL
;
449 static inline struct rxe_qp
*to_rqp(struct ib_qp
*qp
)
451 return qp
? container_of(qp
, struct rxe_qp
, ibqp
) : NULL
;
454 static inline struct rxe_cq
*to_rcq(struct ib_cq
*cq
)
456 return cq
? container_of(cq
, struct rxe_cq
, ibcq
) : NULL
;
459 static inline struct rxe_mem
*to_rmr(struct ib_mr
*mr
)
461 return mr
? container_of(mr
, struct rxe_mem
, ibmr
) : NULL
;
464 static inline struct rxe_mem
*to_rmw(struct ib_mw
*mw
)
466 return mw
? container_of(mw
, struct rxe_mem
, ibmw
) : NULL
;
469 int rxe_register_device(struct rxe_dev
*rxe
);
470 int rxe_unregister_device(struct rxe_dev
*rxe
);
472 void rxe_mc_cleanup(struct rxe_pool_entry
*arg
);
474 #endif /* RXE_VERBS_H */