2 * Copyright (c) 2007, 2014 Mellanox Technologies. 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
34 #include <linux/rcupdate.h>
36 #include <dev/mlx4/cq.h>
37 #include <dev/mlx4/qp.h>
38 #include <dev/mlx4/cmd.h>
42 static void mlx4_en_cq_event(struct mlx4_cq *cq, enum mlx4_event event)
47 static void mlx4_en_tx_que(void *arg, int pending)
52 int mlx4_en_create_cq(struct mlx4_en_priv *priv,
53 struct mlx4_en_cq **pcq,
54 int entries, int ring, enum cq_type mode,
57 struct mlx4_en_dev *mdev = priv->mdev;
58 struct mlx4_en_cq *cq;
61 cq = kzalloc_node(sizeof(*cq), GFP_KERNEL, node);
63 cq = kzalloc(sizeof(*cq), GFP_KERNEL);
65 en_err(priv, "Failed to allocate CQ structure\n");
71 cq->buf_size = cq->size * mdev->dev->caps.cqe_size;
73 cq->tq = taskqueue_create_fast("mlx4_en_que", M_NOWAIT,
74 taskqueue_thread_enqueue, &cq->tq);
76 TASK_INIT(&cq->cq_task, 0, mlx4_en_rx_que, cq);
77 taskqueue_start_threads(&cq->tq, 1, PI_NET, "%s rx cq",
81 TASK_INIT(&cq->cq_task, 0, mlx4_en_tx_que, cq);
82 taskqueue_start_threads(&cq->tq, 1, PI_NET, "%s tx cq",
88 cq->vector = mdev->dev->caps.num_comp_vectors;
89 spin_lock_init(&cq->lock);
91 err = mlx4_alloc_hwq_res(mdev->dev, &cq->wqres,
92 cq->buf_size, 2 * PAGE_SIZE);
96 err = mlx4_en_map_buffer(&cq->wqres.buf);
100 cq->buf = (struct mlx4_cqe *)cq->wqres.buf.direct.buf;
106 mlx4_free_hwq_res(mdev->dev, &cq->wqres, cq->buf_size);
113 int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
116 struct mlx4_en_dev *mdev = priv->mdev;
118 int timestamp_en = 0;
119 bool assigned_eq = false;
121 cq->dev = mdev->pndev[priv->port];
122 cq->mcq.set_ci_db = cq->wqres.db.db;
123 cq->mcq.arm_db = cq->wqres.db.db + 1;
124 *cq->mcq.set_ci_db = 0;
126 memset(cq->buf, 0, cq->buf_size);
128 if (cq->is_tx == RX) {
129 if (!mlx4_is_eq_vector_valid(mdev->dev, priv->port,
131 cq->vector = cq_idx % mdev->dev->caps.num_comp_vectors;
133 err = mlx4_assign_eq(mdev->dev, priv->port,
136 mlx4_err(mdev, "Failed assigning an EQ to CQ vector %d\n",
144 struct mlx4_en_cq *rx_cq;
146 * For TX we use the same irq per
147 * ring we assigned for the RX
149 cq_idx = cq_idx % priv->rx_ring_num;
150 rx_cq = priv->rx_cq[cq_idx];
151 cq->vector = rx_cq->vector;
155 cq->size = priv->rx_ring[cq->ring]->actual_size;
157 err = mlx4_cq_alloc(mdev->dev, cq->size, &cq->wqres.mtt,
158 &mdev->priv_uar, cq->wqres.db.dma, &cq->mcq,
159 cq->vector, 0, timestamp_en);
163 cq->mcq.comp = cq->is_tx ? mlx4_en_tx_irq : mlx4_en_rx_irq;
164 cq->mcq.event = mlx4_en_cq_event;
167 init_timer(&cq->timer);
168 cq->timer.function = mlx4_en_poll_tx_cq;
169 cq->timer.data = (unsigned long) cq;
177 mlx4_release_eq(mdev->dev, cq->vector);
178 cq->vector = mdev->dev->caps.num_comp_vectors;
182 void mlx4_en_destroy_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq)
184 struct mlx4_en_dev *mdev = priv->mdev;
185 struct mlx4_en_cq *cq = *pcq;
187 taskqueue_drain(cq->tq, &cq->cq_task);
188 taskqueue_free(cq->tq);
189 mlx4_en_unmap_buffer(&cq->wqres.buf);
190 mlx4_free_hwq_res(mdev->dev, &cq->wqres, cq->buf_size);
191 if (mlx4_is_eq_vector_valid(mdev->dev, priv->port, cq->vector) &&
193 mlx4_release_eq(priv->mdev->dev, cq->vector);
201 void mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq)
203 taskqueue_drain(cq->tq, &cq->cq_task);
207 del_timer_sync(&cq->timer);
210 mlx4_cq_free(priv->mdev->dev, &cq->mcq);
213 /* Set rx cq moderation parameters */
214 int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq)
216 return mlx4_cq_modify(priv->mdev->dev, &cq->mcq,
217 cq->moder_cnt, cq->moder_time);
220 int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq)
222 mlx4_cq_arm(&cq->mcq, MLX4_CQ_DB_REQ_NOT, priv->mdev->uar_map,
223 &priv->mdev->uar_lock);