diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c index 6657390de95621a53a7a2bbce16f10eb66d16982..88de3aa9c5b0205952299a7823ad0bfc071d3a5d 100644 --- a/drivers/infiniband/hw/cxgb4/cq.c +++ b/drivers/infiniband/hw/cxgb4/cq.c @@ -611,9 +611,12 @@ static int poll_cq(struct t4_wq *wq, struct t4_cq *cq, struct t4_cqe *cqe, * to the first unsignaled one, and idx points to the * signaled one. So adjust in_use based on this delta. * if this is not completing any unsigned wrs, then the - * delta will be 0. + * delta will be 0. Handle wrapping also! */ - wq->sq.in_use -= idx - wq->sq.cidx; + if (idx < wq->sq.cidx) + wq->sq.in_use -= wq->sq.size + idx - wq->sq.cidx; + else + wq->sq.in_use -= idx - wq->sq.cidx; BUG_ON(wq->sq.in_use < 0 && wq->sq.in_use < wq->sq.size); wq->sq.cidx = (uint16_t)idx;