1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
3 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
10 #include <linux/interrupt.h>
11 #include <linux/workqueue.h>
12 #include <rdma/rdma_user_rxe.h>
15 #include "rxe_hw_counters.h"
17 static inline int pkey_match(u16 key1
, u16 key2
)
19 return (((key1
& 0x7fff) != 0) &&
20 ((key1
& 0x7fff) == (key2
& 0x7fff)) &&
21 ((key1
& 0x8000) || (key2
& 0x8000))) ? 1 : 0;
24 /* Return >0 if psn_a > psn_b
28 static inline int psn_compare(u32 psn_a
, u32 psn_b
)
32 diff
= (psn_a
- psn_b
) << 8;
37 struct ib_ucontext ibuc
;
38 struct rxe_pool_entry pelem
;
43 struct rxe_pool_entry pelem
;
48 struct rxe_pool_entry pelem
;
56 struct ib_uverbs_wc uibwc
;
62 struct rxe_pool_entry pelem
;
63 struct rxe_queue
*queue
;
68 struct tasklet_struct comp_task
;
83 spinlock_t sq_lock
; /* guard queue */
84 struct rxe_queue
*queue
;
90 spinlock_t producer_lock
; /* guard queue producer */
91 spinlock_t consumer_lock
; /* guard queue consumer */
92 struct rxe_queue
*queue
;
97 struct rxe_pool_entry pelem
;
110 QP_STATE_DRAIN
, /* req only */
111 QP_STATE_DRAINED
, /* req only */
115 struct rxe_req_info
{
116 enum rxe_qp_state state
;
126 struct rxe_task task
;
129 struct rxe_comp_info
{
137 struct rxe_task task
;
140 enum rdatm_res_state
{
141 rdatm_res_state_next
,
143 rdatm_res_state_replay
,
152 enum rdatm_res_state state
;
169 struct rxe_resp_info
{
170 enum rxe_qp_state state
;
178 enum ib_wc_status status
;
182 struct rxe_recv_wqe
*wqe
;
184 /* RDMA read / atomic only */
194 struct rxe_recv_wqe wqe
;
195 struct ib_sge sge
[RXE_MAX_SGE
];
198 /* Responder resources. It's a circular list where the oldest
199 * resource is dropped first.
201 struct resp_res
*resources
;
202 unsigned int res_head
;
203 unsigned int res_tail
;
204 struct resp_res
*res
;
205 struct rxe_task task
;
209 struct rxe_pool_entry pelem
;
211 struct ib_qp_attr attr
;
221 enum ib_sig_type sq_sig_type
;
230 struct rxe_av pri_av
;
231 struct rxe_av alt_av
;
233 /* list of mcast groups qp has joined (for cleanup) */
234 struct list_head grp_list
;
235 spinlock_t grp_lock
; /* guard grp_list */
237 struct sk_buff_head req_pkts
;
238 struct sk_buff_head resp_pkts
;
239 struct sk_buff_head send_pkts
;
241 struct rxe_req_info req
;
242 struct rxe_comp_info comp
;
243 struct rxe_resp_info resp
;
249 /* Timer for retranmitting packet when ACKs have been lost. RC
250 * only. The requester sets it when it is not already
251 * started. The responder resets it whenever an ack is
254 struct timer_list retrans_timer
;
255 u64 qp_timeout_jiffies
;
257 /* Timer for handling RNR NAKS. */
258 struct timer_list rnr_nak_timer
;
260 spinlock_t state_lock
; /* guard requester and completer */
262 struct execute_work cleanup_work
;
266 RXE_MEM_STATE_ZOMBIE
,
267 RXE_MEM_STATE_INVALID
,
279 #define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf))
281 struct rxe_phys_buf
{
287 struct rxe_phys_buf buf
[RXE_BUF_PER_MAP
];
291 struct rxe_pool_entry pelem
;
297 struct ib_umem
*umem
;
299 enum rxe_mem_state state
;
300 enum rxe_mem_type type
;
318 struct rxe_map
**map
;
322 struct rxe_pool_entry pelem
;
323 spinlock_t mcg_lock
; /* guard group */
325 struct list_head qp_list
;
333 struct rxe_pool_entry pelem
;
334 struct list_head qp_list
;
335 struct list_head grp_list
;
337 struct rxe_mc_grp
*grp
;
341 struct ib_port_attr attr
;
343 __be64 subnet_prefix
;
344 spinlock_t port_lock
; /* guard port */
345 unsigned int mtu_cap
;
352 struct ib_device ib_dev
;
353 struct ib_device_attr attr
;
356 struct mutex usdev_lock
;
358 struct net_device
*ndev
;
362 struct rxe_pool uc_pool
;
363 struct rxe_pool pd_pool
;
364 struct rxe_pool ah_pool
;
365 struct rxe_pool srq_pool
;
366 struct rxe_pool qp_pool
;
367 struct rxe_pool cq_pool
;
368 struct rxe_pool mr_pool
;
369 struct rxe_pool mw_pool
;
370 struct rxe_pool mc_grp_pool
;
371 struct rxe_pool mc_elem_pool
;
373 spinlock_t pending_lock
; /* guard pending_mmaps */
374 struct list_head pending_mmaps
;
376 spinlock_t mmap_offset_lock
; /* guard mmap_offset */
379 atomic64_t stats_counters
[RXE_NUM_OF_COUNTERS
];
381 struct rxe_port port
;
382 struct crypto_shash
*tfm
;
385 static inline void rxe_counter_inc(struct rxe_dev
*rxe
, enum rxe_counters index
)
387 atomic64_inc(&rxe
->stats_counters
[index
]);
390 static inline struct rxe_dev
*to_rdev(struct ib_device
*dev
)
392 return dev
? container_of(dev
, struct rxe_dev
, ib_dev
) : NULL
;
395 static inline struct rxe_ucontext
*to_ruc(struct ib_ucontext
*uc
)
397 return uc
? container_of(uc
, struct rxe_ucontext
, ibuc
) : NULL
;
400 static inline struct rxe_pd
*to_rpd(struct ib_pd
*pd
)
402 return pd
? container_of(pd
, struct rxe_pd
, ibpd
) : NULL
;
405 static inline struct rxe_ah
*to_rah(struct ib_ah
*ah
)
407 return ah
? container_of(ah
, struct rxe_ah
, ibah
) : NULL
;
410 static inline struct rxe_srq
*to_rsrq(struct ib_srq
*srq
)
412 return srq
? container_of(srq
, struct rxe_srq
, ibsrq
) : NULL
;
415 static inline struct rxe_qp
*to_rqp(struct ib_qp
*qp
)
417 return qp
? container_of(qp
, struct rxe_qp
, ibqp
) : NULL
;
420 static inline struct rxe_cq
*to_rcq(struct ib_cq
*cq
)
422 return cq
? container_of(cq
, struct rxe_cq
, ibcq
) : NULL
;
425 static inline struct rxe_mem
*to_rmr(struct ib_mr
*mr
)
427 return mr
? container_of(mr
, struct rxe_mem
, ibmr
) : NULL
;
430 static inline struct rxe_mem
*to_rmw(struct ib_mw
*mw
)
432 return mw
? container_of(mw
, struct rxe_mem
, ibmw
) : NULL
;
435 static inline struct rxe_pd
*mr_pd(struct rxe_mem
*mr
)
437 return to_rpd(mr
->ibmr
.pd
);
440 static inline u32
mr_lkey(struct rxe_mem
*mr
)
442 return mr
->ibmr
.lkey
;
445 static inline u32
mr_rkey(struct rxe_mem
*mr
)
447 return mr
->ibmr
.rkey
;
450 int rxe_register_device(struct rxe_dev
*rxe
, const char *ibdev_name
);
452 void rxe_mc_cleanup(struct rxe_pool_entry
*arg
);
454 #endif /* RXE_VERBS_H */