[ofa-general] [PATCH 2 of 2] mlx4: deal with ownership bit wraparound when cleaning cq

Jack Morgenstein jackm at dev.mellanox.co.il
Tue Jun 12 22:36:24 PDT 2007


When compacting the cqe's, need to preserve the
proper ownership value of the cqe in case of wraparound.

Found by Ronni Zimmerman of Mellanox.

Signed-off-by: Jack Morgenstein <jackm at dev.mellanox.co.il>

diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
index 048c527..ced854d 100644
--- a/drivers/infiniband/hw/mlx4/cq.c
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -496,14 +496,24 @@ void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq)
 	 * that match our QP by copying older entries on top of them.
 	 */
 	while ((int) --prod_index - (int) cq->mcq.cons_index >= 0) {
+		struct mlx4_cqe *q;
+		u8 own;
 		cqe = get_cqe(cq, prod_index & cq->ibcq.cqe);
 		if ((be32_to_cpu(cqe->my_qpn) & 0xffffff) == qpn) {
 			if (srq && !(cqe->owner_sr_opcode & MLX4_CQE_IS_SEND_MASK))
 				mlx4_ib_free_srq_wqe(srq, be16_to_cpu(cqe->wqe_index));
 			++nfreed;
-		} else if (nfreed)
-			memcpy(get_cqe(cq, (prod_index + nfreed) & cq->ibcq.cqe),
-			       cqe, sizeof *cqe);
+		} else if (nfreed) {
+			/*
+			 * preserve proper ownership bit value in case of
+			 * wraparound.
+			 */
+			q = get_cqe(cq, (prod_index + nfreed) & cq->ibcq.cqe);
+			own = q->owner_sr_opcode & MLX4_CQE_OWNER_MASK;
+			memcpy(q, cqe, sizeof *cqe);
+			q->owner_sr_opcode =
+				(q->owner_sr_opcode & ~MLX4_CQE_OWNER_MASK) | own;
+		}
 	}
 
 	if (nfreed) {



More information about the general mailing list