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>

+11 -19
+1 -7
drivers/infiniband/hw/mlx4/cq.c
··· 64 64 65 65 static void *get_cqe_from_buf(struct mlx4_ib_cq_buf *buf, int n) 66 66 { 67 - int offset = n * sizeof (struct mlx4_cqe); 68 - 69 - if (buf->buf.nbufs == 1) 70 - return buf->buf.u.direct.buf + offset; 71 - else 72 - return buf->buf.u.page_list[offset >> PAGE_SHIFT].buf + 73 - (offset & (PAGE_SIZE - 1)); 67 + return mlx4_buf_offset(&buf->buf, n * sizeof (struct mlx4_cqe)); 74 68 } 75 69 76 70 static void *get_cqe(struct mlx4_ib_cq *cq, int n)
+1 -5
drivers/infiniband/hw/mlx4/qp.c
··· 96 96 97 97 static void *get_wqe(struct mlx4_ib_qp *qp, int offset) 98 98 { 99 - if (qp->buf.nbufs == 1) 100 - return qp->buf.u.direct.buf + offset; 101 - else 102 - return qp->buf.u.page_list[offset >> PAGE_SHIFT].buf + 103 - (offset & (PAGE_SIZE - 1)); 99 + return mlx4_buf_offset(&qp->buf, offset); 104 100 } 105 101 106 102 static void *get_recv_wqe(struct mlx4_ib_qp *qp, int n)
+1 -7
drivers/infiniband/hw/mlx4/srq.c
··· 38 38 39 39 static void *get_wqe(struct mlx4_ib_srq *srq, int n) 40 40 { 41 - int offset = n << srq->msrq.wqe_shift; 42 - 43 - if (srq->buf.nbufs == 1) 44 - return srq->buf.u.direct.buf + offset; 45 - else 46 - return srq->buf.u.page_list[offset >> PAGE_SHIFT].buf + 47 - (offset & (PAGE_SIZE - 1)); 41 + return mlx4_buf_offset(&srq->buf, n << srq->msrq.wqe_shift); 48 42 } 49 43 50 44 static void mlx4_ib_srq_event(struct mlx4_srq *srq, enum mlx4_event type)
+8
include/linux/mlx4/device.h
··· 308 308 int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct, 309 309 struct mlx4_buf *buf); 310 310 void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf); 311 + static inline void *mlx4_buf_offset(struct mlx4_buf *buf, int offset) 312 + { 313 + if (buf->nbufs == 1) 314 + return buf->u.direct.buf + offset; 315 + else 316 + return buf->u.page_list[offset >> PAGE_SHIFT].buf + 317 + (offset & (PAGE_SIZE - 1)); 318 + } 311 319 312 320 int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn); 313 321 void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn);