IB/mlx4: Consolidate code to get an entry from a struct mlx4_buf
We use struct mlx4_buf for kernel QP, CQ and SRQ buffers, and the code to look up an entry is duplicated in get_cqe_from_buf() and the QP and SRQ versions of get_wqe(). Factor this out into mlx4_buf_offset(). This will also make it easier to switch over to using vmap() for buffers. Signed-off-by: Roland Dreier <rolandd@cisco.com>
This commit is contained in:
Родитель
21511abd0a
Коммит
1c69fc2a90
|
@ -64,13 +64,7 @@ static void mlx4_ib_cq_event(struct mlx4_cq *cq, enum mlx4_event type)
|
||||||
|
|
||||||
static void *get_cqe_from_buf(struct mlx4_ib_cq_buf *buf, int n)
|
static void *get_cqe_from_buf(struct mlx4_ib_cq_buf *buf, int n)
|
||||||
{
|
{
|
||||||
int offset = n * sizeof (struct mlx4_cqe);
|
return mlx4_buf_offset(&buf->buf, n * sizeof (struct mlx4_cqe));
|
||||||
|
|
||||||
if (buf->buf.nbufs == 1)
|
|
||||||
return buf->buf.u.direct.buf + offset;
|
|
||||||
else
|
|
||||||
return buf->buf.u.page_list[offset >> PAGE_SHIFT].buf +
|
|
||||||
(offset & (PAGE_SIZE - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *get_cqe(struct mlx4_ib_cq *cq, int n)
|
static void *get_cqe(struct mlx4_ib_cq *cq, int n)
|
||||||
|
|
|
@ -96,11 +96,7 @@ static int is_qp0(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp)
|
||||||
|
|
||||||
static void *get_wqe(struct mlx4_ib_qp *qp, int offset)
|
static void *get_wqe(struct mlx4_ib_qp *qp, int offset)
|
||||||
{
|
{
|
||||||
if (qp->buf.nbufs == 1)
|
return mlx4_buf_offset(&qp->buf, offset);
|
||||||
return qp->buf.u.direct.buf + offset;
|
|
||||||
else
|
|
||||||
return qp->buf.u.page_list[offset >> PAGE_SHIFT].buf +
|
|
||||||
(offset & (PAGE_SIZE - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *get_recv_wqe(struct mlx4_ib_qp *qp, int n)
|
static void *get_recv_wqe(struct mlx4_ib_qp *qp, int n)
|
||||||
|
|
|
@ -38,13 +38,7 @@
|
||||||
|
|
||||||
static void *get_wqe(struct mlx4_ib_srq *srq, int n)
|
static void *get_wqe(struct mlx4_ib_srq *srq, int n)
|
||||||
{
|
{
|
||||||
int offset = n << srq->msrq.wqe_shift;
|
return mlx4_buf_offset(&srq->buf, n << srq->msrq.wqe_shift);
|
||||||
|
|
||||||
if (srq->buf.nbufs == 1)
|
|
||||||
return srq->buf.u.direct.buf + offset;
|
|
||||||
else
|
|
||||||
return srq->buf.u.page_list[offset >> PAGE_SHIFT].buf +
|
|
||||||
(offset & (PAGE_SIZE - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mlx4_ib_srq_event(struct mlx4_srq *srq, enum mlx4_event type)
|
static void mlx4_ib_srq_event(struct mlx4_srq *srq, enum mlx4_event type)
|
||||||
|
|
|
@ -308,6 +308,14 @@ struct mlx4_init_port_param {
|
||||||
int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
|
int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
|
||||||
struct mlx4_buf *buf);
|
struct mlx4_buf *buf);
|
||||||
void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf);
|
void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf);
|
||||||
|
static inline void *mlx4_buf_offset(struct mlx4_buf *buf, int offset)
|
||||||
|
{
|
||||||
|
if (buf->nbufs == 1)
|
||||||
|
return buf->u.direct.buf + offset;
|
||||||
|
else
|
||||||
|
return buf->u.page_list[offset >> PAGE_SHIFT].buf +
|
||||||
|
(offset & (PAGE_SIZE - 1));
|
||||||
|
}
|
||||||
|
|
||||||
int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn);
|
int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn);
|
||||||
void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn);
|
void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче