2020-08-27 07:54:40 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
|
2016-06-16 06:45:23 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
|
|
|
|
*/
|
2018-09-29 22:57:42 -07:00
|
|
|
#include <linux/vmalloc.h>
|
2016-06-16 06:45:23 -07:00
|
|
|
#include "rxe.h"
|
|
|
|
#include "rxe_loc.h"
|
|
|
|
#include "rxe_queue.h"
|
|
|
|
|
|
|
|
int rxe_cq_chk_attr(struct rxe_dev *rxe, struct rxe_cq *cq,
|
2018-03-13 15:33:17 -07:00
|
|
|
int cqe, int comp_vector)
|
2016-06-16 06:45:23 -07:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (cqe <= 0) {
|
2023-03-03 15:16:22 -07:00
|
|
|
rxe_dbg_dev(rxe, "cqe(%d) <= 0\n", cqe);
|
2016-06-16 06:45:23 -07:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cqe > rxe->attr.max_cqe) {
|
2023-03-03 15:16:22 -07:00
|
|
|
rxe_dbg_dev(rxe, "cqe(%d) > max_cqe(%d)\n",
|
2022-06-30 12:04:19 -07:00
|
|
|
cqe, rxe->attr.max_cqe);
|
2016-06-16 06:45:23 -07:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cq) {
|
2021-09-14 09:42:03 -07:00
|
|
|
count = queue_count(cq->queue, QUEUE_TYPE_TO_CLIENT);
|
2016-06-16 06:45:23 -07:00
|
|
|
if (cqe < count) {
|
2024-01-09 01:32:52 -07:00
|
|
|
rxe_dbg_cq(cq, "cqe(%d) < current # elements in queue (%d)\n",
|
2022-06-30 12:04:19 -07:00
|
|
|
cqe, count);
|
2016-06-16 06:45:23 -07:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err1:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rxe_cq_from_init(struct rxe_dev *rxe, struct rxe_cq *cq, int cqe,
|
2019-03-31 09:10:07 -07:00
|
|
|
int comp_vector, struct ib_udata *udata,
|
2018-03-13 15:33:18 -07:00
|
|
|
struct rxe_create_cq_resp __user *uresp)
|
2016-06-16 06:45:23 -07:00
|
|
|
{
|
|
|
|
int err;
|
2021-05-27 12:47:46 -07:00
|
|
|
enum queue_type type;
|
2016-06-16 06:45:23 -07:00
|
|
|
|
2021-09-14 09:42:03 -07:00
|
|
|
type = QUEUE_TYPE_TO_CLIENT;
|
2016-06-16 06:45:23 -07:00
|
|
|
cq->queue = rxe_queue_init(rxe, &cqe,
|
2021-05-27 12:47:46 -07:00
|
|
|
sizeof(struct rxe_cqe), type);
|
2016-06-16 06:45:23 -07:00
|
|
|
if (!cq->queue) {
|
2023-03-03 15:16:22 -07:00
|
|
|
rxe_dbg_dev(rxe, "unable to create cq\n");
|
2016-06-16 06:45:23 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-03-31 09:10:07 -07:00
|
|
|
err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, udata,
|
2018-03-13 15:33:18 -07:00
|
|
|
cq->queue->buf, cq->queue->buf_size, &cq->queue->ip);
|
2016-06-16 06:45:23 -07:00
|
|
|
if (err) {
|
2018-09-29 22:57:42 -07:00
|
|
|
vfree(cq->queue->buf);
|
2016-06-16 06:45:23 -07:00
|
|
|
kfree(cq->queue);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-09-30 02:48:11 -07:00
|
|
|
cq->is_user = uresp;
|
2016-06-16 06:45:23 -07:00
|
|
|
|
|
|
|
spin_lock_init(&cq->cq_lock);
|
|
|
|
cq->ibcq.cqe = cqe;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-13 15:33:18 -07:00
|
|
|
int rxe_cq_resize_queue(struct rxe_cq *cq, int cqe,
|
2019-03-31 09:10:07 -07:00
|
|
|
struct rxe_resize_cq_resp __user *uresp,
|
|
|
|
struct ib_udata *udata)
|
2016-06-16 06:45:23 -07:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = rxe_queue_resize(cq->queue, (unsigned int *)&cqe,
|
2019-03-31 09:10:07 -07:00
|
|
|
sizeof(struct rxe_cqe), udata,
|
2018-03-13 15:33:18 -07:00
|
|
|
uresp ? &uresp->mi : NULL, NULL, &cq->cq_lock);
|
2016-06-16 06:45:23 -07:00
|
|
|
if (!err)
|
|
|
|
cq->ibcq.cqe = cqe;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-03-27 14:56:44 -07:00
|
|
|
/* caller holds reference to cq */
|
2016-06-16 06:45:23 -07:00
|
|
|
int rxe_cq_post(struct rxe_cq *cq, struct rxe_cqe *cqe, int solicited)
|
|
|
|
{
|
|
|
|
struct ib_event ev;
|
2021-05-27 12:47:48 -07:00
|
|
|
int full;
|
|
|
|
void *addr;
|
2022-02-15 12:44:49 -07:00
|
|
|
unsigned long flags;
|
2016-06-16 06:45:23 -07:00
|
|
|
|
2022-02-15 12:44:49 -07:00
|
|
|
spin_lock_irqsave(&cq->cq_lock, flags);
|
2016-06-16 06:45:23 -07:00
|
|
|
|
2021-09-14 09:42:03 -07:00
|
|
|
full = queue_full(cq->queue, QUEUE_TYPE_TO_CLIENT);
|
2021-05-27 12:47:48 -07:00
|
|
|
if (unlikely(full)) {
|
2024-01-09 01:32:52 -07:00
|
|
|
rxe_err_cq(cq, "queue full\n");
|
2022-02-15 12:44:49 -07:00
|
|
|
spin_unlock_irqrestore(&cq->cq_lock, flags);
|
2016-06-16 06:45:23 -07:00
|
|
|
if (cq->ibcq.event_handler) {
|
|
|
|
ev.device = cq->ibcq.device;
|
|
|
|
ev.element.cq = &cq->ibcq;
|
|
|
|
ev.event = IB_EVENT_CQ_ERR;
|
|
|
|
cq->ibcq.event_handler(&ev, cq->ibcq.cq_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2021-09-14 09:42:03 -07:00
|
|
|
addr = queue_producer_addr(cq->queue, QUEUE_TYPE_TO_CLIENT);
|
2021-05-27 12:47:48 -07:00
|
|
|
memcpy(addr, cqe, sizeof(*cqe));
|
|
|
|
|
2021-09-14 09:42:03 -07:00
|
|
|
queue_advance_producer(cq->queue, QUEUE_TYPE_TO_CLIENT);
|
2016-06-16 06:45:23 -07:00
|
|
|
|
2023-06-12 09:22:45 -07:00
|
|
|
if ((cq->notify & IB_CQ_NEXT_COMP) ||
|
|
|
|
(cq->notify & IB_CQ_SOLICITED && solicited)) {
|
2016-06-16 06:45:23 -07:00
|
|
|
cq->notify = 0;
|
2023-03-27 14:56:44 -07:00
|
|
|
cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);
|
2016-06-16 06:45:23 -07:00
|
|
|
}
|
|
|
|
|
2023-06-12 08:50:33 -07:00
|
|
|
spin_unlock_irqrestore(&cq->cq_lock, flags);
|
|
|
|
|
2016-06-16 06:45:23 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-02 22:02:31 -07:00
|
|
|
void rxe_cq_cleanup(struct rxe_pool_elem *elem)
|
2016-06-16 06:45:23 -07:00
|
|
|
{
|
2021-11-02 22:02:31 -07:00
|
|
|
struct rxe_cq *cq = container_of(elem, typeof(*cq), elem);
|
2016-06-16 06:45:23 -07:00
|
|
|
|
|
|
|
if (cq->queue)
|
|
|
|
rxe_queue_cleanup(cq->queue);
|
|
|
|
}
|