xref: /NextBSD/sys/ofed/drivers/infiniband/hw/mlx4/mlx4_exp.c (revision 287e3b14e9552995def1802ec9c5034f4adf28ec)
1 /*
2  * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3  * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
4  *
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:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      - Redistributions of source code must retain the above
16  *        copyright notice, this list of conditions and the following
17  *        disclaimer.
18  *
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.
23  *
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
31  * SOFTWARE.
32  */
33 
34 #include "mlx4_ib.h"
35 #include "mlx4_exp.h"
36 #include <linux/mlx4/qp.h>
37 
mlx4_ib_exp_query_device(struct ib_device * ibdev,struct ib_exp_device_attr * props)38 int mlx4_ib_exp_query_device(struct ib_device *ibdev,
39 			     struct ib_exp_device_attr *props)
40 {
41 	struct ib_device_attr *base = &props->base;
42 	struct mlx4_ib_dev *dev = to_mdev(ibdev);
43 	int ret = mlx4_ib_query_device(ibdev, &props->base);
44 
45 	props->exp_comp_mask = IB_EXP_DEVICE_ATTR_INLINE_RECV_SZ;
46 	props->inline_recv_sz = dev->dev->caps.max_rq_sg * sizeof(struct mlx4_wqe_data_seg);
47 	props->device_cap_flags2 = 0;
48 
49 	/* move RSS device cap from device_cap to device_cap_flags2 */
50 	if (base->device_cap_flags & IB_DEVICE_QPG) {
51 		props->device_cap_flags2 |= IB_EXP_DEVICE_QPG;
52 		if (base->device_cap_flags & IB_DEVICE_UD_RSS)
53 			props->device_cap_flags2 |= IB_EXP_DEVICE_UD_RSS;
54 	}
55 	base->device_cap_flags &= ~(IB_DEVICE_QPG |
56 				    IB_DEVICE_UD_RSS |
57 				    IB_DEVICE_UD_TSS);
58 
59 	if (base->max_rss_tbl_sz > 0) {
60 		props->max_rss_tbl_sz = base->max_rss_tbl_sz;
61 		props->exp_comp_mask |= IB_EXP_DEVICE_ATTR_RSS_TBL_SZ;
62 	} else {
63 		props->max_rss_tbl_sz = 0;
64 		props->exp_comp_mask &= ~IB_EXP_DEVICE_ATTR_RSS_TBL_SZ;
65 	}
66 
67 	if (props->device_cap_flags2)
68 		props->exp_comp_mask |= IB_EXP_DEVICE_ATTR_CAP_FLAGS2;
69 
70 	return ret;
71 }
72 
73 /*
74  * Experimental functions
75  */
mlx4_ib_exp_create_qp(struct ib_pd * pd,struct ib_exp_qp_init_attr * init_attr,struct ib_udata * udata)76 struct ib_qp *mlx4_ib_exp_create_qp(struct ib_pd *pd,
77 				    struct ib_exp_qp_init_attr *init_attr,
78 				    struct ib_udata *udata)
79 {
80 	int rwqe_size;
81 	struct ib_qp *qp;
82 	struct mlx4_ib_qp *mqp;
83 	int use_inlr;
84 	struct mlx4_ib_dev *dev;
85 
86 	if (init_attr->max_inl_recv && !udata)
87 		return ERR_PTR(-EINVAL);
88 
89 	use_inlr = mlx4_ib_qp_has_rq((struct ib_qp_init_attr *)init_attr) &&
90 		   init_attr->max_inl_recv && pd;
91 	if (use_inlr) {
92 		rwqe_size = roundup_pow_of_two(max(1U, init_attr->cap.max_recv_sge)) *
93 					       sizeof(struct mlx4_wqe_data_seg);
94 		if (rwqe_size < init_attr->max_inl_recv) {
95 			dev = to_mdev(pd->device);
96 			init_attr->max_inl_recv = min(init_attr->max_inl_recv,
97 						      (u32)(dev->dev->caps.max_rq_sg *
98 						      sizeof(struct mlx4_wqe_data_seg)));
99 			init_attr->cap.max_recv_sge = roundup_pow_of_two(init_attr->max_inl_recv) /
100 						      sizeof(struct mlx4_wqe_data_seg);
101 		}
102 	} else {
103 		init_attr->max_inl_recv = 0;
104 	}
105 	qp = mlx4_ib_create_qp(pd, (struct ib_qp_init_attr *)init_attr, udata);
106 	if (IS_ERR(qp))
107 		return qp;
108 
109 	if (use_inlr) {
110 		mqp = to_mqp(qp);
111 		mqp->max_inlr_data = 1 << mqp->rq.wqe_shift;
112 		init_attr->max_inl_recv = mqp->max_inlr_data;
113 	}
114 
115 	return qp;
116 }
117