net/mlx5: Ethernet Datapath files
[deliverable/linux.git] / drivers / net / ethernet / mellanox / mlx5 / core / wq.c
CommitLineData
e586b3b0
AV
1/*
2 * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
3 *
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:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
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.
22 *
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
30 * SOFTWARE.
31 */
32
33#include <linux/mlx5/driver.h>
34#include "wq.h"
35#include "mlx5_core.h"
36
37u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq)
38{
39 return (u32)wq->sz_m1 + 1;
40}
41
42u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq)
43{
44 return wq->sz_m1 + 1;
45}
46
47u32 mlx5_wq_ll_get_size(struct mlx5_wq_ll *wq)
48{
49 return (u32)wq->sz_m1 + 1;
50}
51
52static u32 mlx5_wq_cyc_get_byte_size(struct mlx5_wq_cyc *wq)
53{
54 return mlx5_wq_cyc_get_size(wq) << wq->log_stride;
55}
56
57static u32 mlx5_cqwq_get_byte_size(struct mlx5_cqwq *wq)
58{
59 return mlx5_cqwq_get_size(wq) << wq->log_stride;
60}
61
62static u32 mlx5_wq_ll_get_byte_size(struct mlx5_wq_ll *wq)
63{
64 return mlx5_wq_ll_get_size(wq) << wq->log_stride;
65}
66
67int mlx5_wq_cyc_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
68 void *wqc, struct mlx5_wq_cyc *wq,
69 struct mlx5_wq_ctrl *wq_ctrl)
70{
71 int err;
72
73 wq->log_stride = MLX5_GET(wq, wqc, log_wq_stride);
74 wq->sz_m1 = (1 << MLX5_GET(wq, wqc, log_wq_sz)) - 1;
75
76 err = mlx5_db_alloc(mdev, &wq_ctrl->db);
77 if (err) {
78 mlx5_core_warn(mdev, "mlx5_db_alloc() failed, %d\n", err);
79 return err;
80 }
81
82 err = mlx5_buf_alloc(mdev, mlx5_wq_cyc_get_byte_size(wq), &wq_ctrl->buf);
83 if (err) {
84 mlx5_core_warn(mdev, "mlx5_buf_alloc() failed, %d\n", err);
85 goto err_db_free;
86 }
87
88 wq->buf = wq_ctrl->buf.direct.buf;
89 wq->db = wq_ctrl->db.db;
90
91 wq_ctrl->mdev = mdev;
92
93 return 0;
94
95err_db_free:
96 mlx5_db_free(mdev, &wq_ctrl->db);
97
98 return err;
99}
100
101int mlx5_cqwq_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
102 void *cqc, struct mlx5_cqwq *wq,
103 struct mlx5_wq_ctrl *wq_ctrl)
104{
105 int err;
106
107 wq->log_stride = 6 + MLX5_GET(cqc, cqc, cqe_sz);
108 wq->log_sz = MLX5_GET(cqc, cqc, log_cq_size);
109 wq->sz_m1 = (1 << wq->log_sz) - 1;
110
111 err = mlx5_db_alloc(mdev, &wq_ctrl->db);
112 if (err) {
113 mlx5_core_warn(mdev, "mlx5_db_alloc() failed, %d\n", err);
114 return err;
115 }
116
117 err = mlx5_buf_alloc(mdev, mlx5_cqwq_get_byte_size(wq), &wq_ctrl->buf);
118 if (err) {
119 mlx5_core_warn(mdev, "mlx5_buf_alloc() failed, %d\n", err);
120 goto err_db_free;
121 }
122
123 wq->buf = wq_ctrl->buf.direct.buf;
124 wq->db = wq_ctrl->db.db;
125
126 wq_ctrl->mdev = mdev;
127
128 return 0;
129
130err_db_free:
131 mlx5_db_free(mdev, &wq_ctrl->db);
132
133 return err;
134}
135
136int mlx5_wq_ll_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
137 void *wqc, struct mlx5_wq_ll *wq,
138 struct mlx5_wq_ctrl *wq_ctrl)
139{
140 struct mlx5_wqe_srq_next_seg *next_seg;
141 int err;
142 int i;
143
144 wq->log_stride = MLX5_GET(wq, wqc, log_wq_stride);
145 wq->sz_m1 = (1 << MLX5_GET(wq, wqc, log_wq_sz)) - 1;
146
147 err = mlx5_db_alloc(mdev, &wq_ctrl->db);
148 if (err) {
149 mlx5_core_warn(mdev, "mlx5_db_alloc() failed, %d\n", err);
150 return err;
151 }
152
153 err = mlx5_buf_alloc(mdev, mlx5_wq_ll_get_byte_size(wq), &wq_ctrl->buf);
154 if (err) {
155 mlx5_core_warn(mdev, "mlx5_buf_alloc() failed, %d\n", err);
156 goto err_db_free;
157 }
158
159 wq->buf = wq_ctrl->buf.direct.buf;
160 wq->db = wq_ctrl->db.db;
161
162 for (i = 0; i < wq->sz_m1; i++) {
163 next_seg = mlx5_wq_ll_get_wqe(wq, i);
164 next_seg->next_wqe_index = cpu_to_be16(i + 1);
165 }
166 next_seg = mlx5_wq_ll_get_wqe(wq, i);
167 wq->tail_next = &next_seg->next_wqe_index;
168
169 wq_ctrl->mdev = mdev;
170
171 return 0;
172
173err_db_free:
174 mlx5_db_free(mdev, &wq_ctrl->db);
175
176 return err;
177}
178
179void mlx5_wq_destroy(struct mlx5_wq_ctrl *wq_ctrl)
180{
181 mlx5_buf_free(wq_ctrl->mdev, &wq_ctrl->buf);
182 mlx5_db_free(wq_ctrl->mdev, &wq_ctrl->db);
183}
This page took 0.030266 seconds and 5 git commands to generate.