1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 /*
3  * Copyright(c) 2018 Intel Corporation.
4  *
5  */
6 
7 #include "hfi.h"
8 #include "verbs.h"
9 #include "tid_rdma.h"
10 
11 /**
12  * qp_to_rcd - determine the receive context used by a qp
13  * @qp - the qp
14  *
15  * This routine returns the receive context associated
16  * with a a qp's qpn.
17  *
18  * Returns the context.
19  */
20 static struct hfi1_ctxtdata *qp_to_rcd(struct rvt_dev_info *rdi,
21 				       struct rvt_qp *qp)
22 {
23 	struct hfi1_ibdev *verbs_dev = container_of(rdi,
24 						    struct hfi1_ibdev,
25 						    rdi);
26 	struct hfi1_devdata *dd = container_of(verbs_dev,
27 					       struct hfi1_devdata,
28 					       verbs_dev);
29 	unsigned int ctxt;
30 
31 	if (qp->ibqp.qp_num == 0)
32 		ctxt = 0;
33 	else
34 		ctxt = ((qp->ibqp.qp_num >> dd->qos_shift) %
35 			(dd->n_krcv_queues - 1)) + 1;
36 
37 	return dd->rcd[ctxt];
38 }
39 
40 int hfi1_qp_priv_init(struct rvt_dev_info *rdi, struct rvt_qp *qp,
41 		      struct ib_qp_init_attr *init_attr)
42 {
43 	struct hfi1_qp_priv *qpriv = qp->priv;
44 
45 	qpriv->rcd = qp_to_rcd(rdi, qp);
46 
47 	return 0;
48 }
49