2 * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/mlx5/driver.h>
35 #include "mlx5_core.h"
37 u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq)
39 return (u32)wq->fbc.sz_m1 + 1;
42 u32 mlx5_wq_cyc_get_frag_size(struct mlx5_wq_cyc *wq)
44 return (u32)wq->fbc.frag_sz_m1 + 1;
47 u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq)
49 return wq->fbc.sz_m1 + 1;
52 u32 mlx5_wq_ll_get_size(struct mlx5_wq_ll *wq)
54 return (u32)wq->fbc.sz_m1 + 1;
57 static u32 mlx5_wq_cyc_get_byte_size(struct mlx5_wq_cyc *wq)
59 return mlx5_wq_cyc_get_size(wq) << wq->fbc.log_stride;
62 static u32 mlx5_wq_qp_get_byte_size(struct mlx5_wq_qp *wq)
64 return mlx5_wq_cyc_get_byte_size(&wq->rq) +
65 mlx5_wq_cyc_get_byte_size(&wq->sq);
68 static u32 mlx5_cqwq_get_byte_size(struct mlx5_cqwq *wq)
70 return mlx5_cqwq_get_size(wq) << wq->fbc.log_stride;
73 static u32 mlx5_wq_ll_get_byte_size(struct mlx5_wq_ll *wq)
75 return mlx5_wq_ll_get_size(wq) << wq->fbc.log_stride;
78 int mlx5_wq_cyc_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
79 void *wqc, struct mlx5_wq_cyc *wq,
80 struct mlx5_wq_ctrl *wq_ctrl)
82 struct mlx5_frag_buf_ctrl *fbc = &wq->fbc;
85 mlx5_fill_fbc(MLX5_GET(wq, wqc, log_wq_stride),
86 MLX5_GET(wq, wqc, log_wq_sz),
89 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
91 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
95 err = mlx5_frag_buf_alloc_node(mdev, mlx5_wq_cyc_get_byte_size(wq),
96 &wq_ctrl->buf, param->buf_numa_node);
98 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n", err);
102 fbc->frag_buf = wq_ctrl->buf;
103 wq->db = wq_ctrl->db.db;
105 wq_ctrl->mdev = mdev;
110 mlx5_db_free(mdev, &wq_ctrl->db);
115 static void mlx5e_qp_set_frag_buf(struct mlx5_frag_buf *buf,
116 struct mlx5_wq_qp *qp)
118 struct mlx5_frag_buf *rqb, *sqb;
120 rqb = &qp->rq.fbc.frag_buf;
122 rqb->size = mlx5_wq_cyc_get_byte_size(&qp->rq);
123 rqb->npages = 1 << get_order(rqb->size);
125 sqb = &qp->sq.fbc.frag_buf;
127 sqb->size = mlx5_wq_cyc_get_byte_size(&qp->rq);
128 sqb->npages = 1 << get_order(sqb->size);
129 sqb->frags += rqb->npages; /* first part is for the rq */
132 int mlx5_wq_qp_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
133 void *qpc, struct mlx5_wq_qp *wq,
134 struct mlx5_wq_ctrl *wq_ctrl)
138 mlx5_fill_fbc(MLX5_GET(qpc, qpc, log_rq_stride) + 4,
139 MLX5_GET(qpc, qpc, log_rq_size),
141 mlx5_fill_fbc(ilog2(MLX5_SEND_WQE_BB),
142 MLX5_GET(qpc, qpc, log_sq_size),
145 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
147 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
151 err = mlx5_frag_buf_alloc_node(mdev, mlx5_wq_qp_get_byte_size(wq),
152 &wq_ctrl->buf, param->buf_numa_node);
154 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n", err);
158 mlx5e_qp_set_frag_buf(&wq_ctrl->buf, wq);
160 wq->rq.db = &wq_ctrl->db.db[MLX5_RCV_DBR];
161 wq->sq.db = &wq_ctrl->db.db[MLX5_SND_DBR];
163 wq_ctrl->mdev = mdev;
168 mlx5_db_free(mdev, &wq_ctrl->db);
173 int mlx5_cqwq_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
174 void *cqc, struct mlx5_cqwq *wq,
175 struct mlx5_wq_ctrl *wq_ctrl)
179 mlx5_core_init_cq_frag_buf(&wq->fbc, cqc);
181 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
183 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
187 err = mlx5_frag_buf_alloc_node(mdev, mlx5_cqwq_get_byte_size(wq),
189 param->buf_numa_node);
191 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n",
196 wq->fbc.frag_buf = wq_ctrl->buf;
197 wq->db = wq_ctrl->db.db;
199 wq_ctrl->mdev = mdev;
204 mlx5_db_free(mdev, &wq_ctrl->db);
209 int mlx5_wq_ll_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
210 void *wqc, struct mlx5_wq_ll *wq,
211 struct mlx5_wq_ctrl *wq_ctrl)
213 struct mlx5_frag_buf_ctrl *fbc = &wq->fbc;
214 struct mlx5_wqe_srq_next_seg *next_seg;
218 mlx5_fill_fbc(MLX5_GET(wq, wqc, log_wq_stride),
219 MLX5_GET(wq, wqc, log_wq_sz),
222 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
224 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
228 err = mlx5_frag_buf_alloc_node(mdev, mlx5_wq_ll_get_byte_size(wq),
229 &wq_ctrl->buf, param->buf_numa_node);
231 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n", err);
235 wq->fbc.frag_buf = wq_ctrl->buf;
236 wq->db = wq_ctrl->db.db;
238 for (i = 0; i < fbc->sz_m1; i++) {
239 next_seg = mlx5_wq_ll_get_wqe(wq, i);
240 next_seg->next_wqe_index = cpu_to_be16(i + 1);
242 next_seg = mlx5_wq_ll_get_wqe(wq, i);
243 wq->tail_next = &next_seg->next_wqe_index;
245 wq_ctrl->mdev = mdev;
250 mlx5_db_free(mdev, &wq_ctrl->db);
255 void mlx5_wq_destroy(struct mlx5_wq_ctrl *wq_ctrl)
257 mlx5_frag_buf_free(wq_ctrl->mdev, &wq_ctrl->buf);
258 mlx5_db_free(wq_ctrl->mdev, &wq_ctrl->db);