[ofa-general] Re: [RFC/PATCH] mthca: ensure alignment of doorbell writes

Michael S. Tsirkin mst at dev.mellanox.co.il
Wed Jul 25 20:39:46 PDT 2007


> @@ -58,10 +63,10 @@ static inline void mthca_write64_raw(__b
>  	__raw_writeq((__force u64) val, dest);
>  }
>  
> -static inline void mthca_write64(__be32 val[2], void __iomem *dest,
> +static inline void mthca_ring_db(union mthca_doorbell db, void __iomem *dest,
>  				 spinlock_t *doorbell_lock)
>  {
> -	__raw_writeq(*(u64 *) val, dest);
> +	__raw_writeq((u64)db.val64, dest);
>  }
>  
>  static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)
> @@ -87,14 +92,14 @@ static inline void mthca_write64_raw(__b
>  	__raw_writel(((__force u32 *) &val)[1], dest + 4);
>  }
>  
> -static inline void mthca_write64(__be32 val[2], void __iomem *dest,
> +static inline void mthca_ring_db(union mthca_doorbell db, void __iomem *dest,
>  				 spinlock_t *doorbell_lock)
>  {
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(doorbell_lock, flags);
> -	__raw_writel((__force u32) val[0], dest);
> -	__raw_writel((__force u32) val[1], dest + 4);
> +	__raw_writel((__force u32) db.val32[0], dest);
> +	__raw_writel((__force u32) db.val32[1], dest + 4);
>  	spin_unlock_irqrestore(doorbell_lock, flags);
>  }

These should be getting 'union mthca_doorbell *db' I think.

diff -rup ofa_kernel-1.2.orig/drivers/infiniband/hw/mthca/mthca_eq.c ofa_kernel-1.2/drivers/infiniband/hw/mthca/mthca_eq.c
--- ofa_kernel-1.2.orig/drivers/infiniband/hw/mthca/mthca_eq.c	2007-07-20 14:42:52.858494231 -0700
+++ ofa_kernel-1.2/drivers/infiniband/hw/mthca/mthca_eq.c	2007-07-25 17:25:34.397279816 -0700
@@ -173,10 +173,10 @@ static inline u64 async_mask(struct mthc
 
 static inline void tavor_set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)
 {
-	__be32 doorbell[2];
+	union mthca_doorbell db;
 
-	doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_SET_CI | eq->eqn);
-	doorbell[1] = cpu_to_be32(ci & (eq->nent - 1));
+	db.val32[0] = cpu_to_be32(MTHCA_EQ_DB_SET_CI | eq->eqn);
+	db.val32[1] = cpu_to_be32(ci & (eq->nent - 1));
 
 	/*
 	 * This barrier makes sure that all updates to ownership bits
@@ -187,8 +187,7 @@ static inline void tavor_set_eq_ci(struc
 	 * having set_eqe_hw() overwrite the owner field.
 	 */
 	wmb();
-	mthca_write64(doorbell,
-		      dev->kar + MTHCA_EQ_DOORBELL,
+	mthca_ring_db(db, dev->kar + MTHCA_EQ_DOORBELL,
 		      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 }
 
@@ -212,13 +211,11 @@ static inline void set_eq_ci(struct mthc
 
 static inline void tavor_eq_req_not(struct mthca_dev *dev, int eqn)
 {
-	__be32 doorbell[2];
+	union mthca_doorbell db;
 
-	doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_REQ_NOT | eqn);
-	doorbell[1] = 0;
-
-	mthca_write64(doorbell,
-		      dev->kar + MTHCA_EQ_DOORBELL,
+	db.val32[0] = cpu_to_be32(MTHCA_EQ_DB_REQ_NOT | eqn);
+	db.val32[1] = 0;
+	mthca_ring_db(db, dev->kar + MTHCA_EQ_DOORBELL,
 		      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 }
 
@@ -230,13 +227,12 @@ static inline void arbel_eq_req_not(stru
 static inline void disarm_cq(struct mthca_dev *dev, int eqn, int cqn)
 {
 	if (!mthca_is_memfree(dev)) {
-		__be32 doorbell[2];
+		union mthca_doorbell db;
 
-		doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_DISARM_CQ | eqn);
-		doorbell[1] = cpu_to_be32(cqn);
+		db.val32[0] = cpu_to_be32(MTHCA_EQ_DB_DISARM_CQ | eqn);
+		db.val32[1] = cpu_to_be32(cqn);
 
-		mthca_write64(doorbell,
-			      dev->kar + MTHCA_EQ_DOORBELL,
+		mthca_ring_db(db, dev->kar + MTHCA_EQ_DOORBELL,
 			      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 	}
 }
diff -rup ofa_kernel-1.2.orig/drivers/infiniband/hw/mthca/mthca_qp.c ofa_kernel-1.2/drivers/infiniband/hw/mthca/mthca_qp.c
--- ofa_kernel-1.2.orig/drivers/infiniband/hw/mthca/mthca_qp.c	2007-07-20 14:42:52.858494231 -0700
+++ ofa_kernel-1.2/drivers/infiniband/hw/mthca/mthca_qp.c	2007-07-25 17:25:58.057619693 -0700
@@ -1730,16 +1730,15 @@ int mthca_tavor_post_send(struct ib_qp *
 
 out:
 	if (likely(nreq)) {
-		__be32 doorbell[2];
+		union mthca_doorbell db;
 
-		doorbell[0] = cpu_to_be32(((qp->sq.next_ind << qp->sq.wqe_shift) +
+		db.val32[0] = cpu_to_be32(((qp->sq.next_ind << qp->sq.wqe_shift) +
 					   qp->send_wqe_offset) | f0 | op0);
-		doorbell[1] = cpu_to_be32((qp->qpn << 8) | size0);
+		db.val32[1] = cpu_to_be32((qp->qpn << 8) | size0);
 
 		wmb();
 
-		mthca_write64(doorbell,
-			      dev->kar + MTHCA_SEND_DOORBELL,
+		mthca_ring_db(db, dev->kar + MTHCA_SEND_DOORBELL,
 			      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 		/*
 		 * Make sure doorbells don't leak out of SQ spinlock
@@ -1760,7 +1759,7 @@ int mthca_tavor_post_receive(struct ib_q
 {
 	struct mthca_dev *dev = to_mdev(ibqp->device);
 	struct mthca_qp *qp = to_mqp(ibqp);
-	__be32 doorbell[2];
+	union mthca_doorbell db;
 	unsigned long flags;
 	int err = 0;
 	int nreq;
@@ -1836,13 +1835,12 @@ int mthca_tavor_post_receive(struct ib_q
 		if (unlikely(nreq == MTHCA_TAVOR_MAX_WQES_PER_RECV_DB)) {
 			nreq = 0;
 
-			doorbell[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);
-			doorbell[1] = cpu_to_be32(qp->qpn << 8);
+			db.val32[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);
+			db.val32[1] = cpu_to_be32(qp->qpn << 8);
 
 			wmb();
 
-			mthca_write64(doorbell,
-				      dev->kar + MTHCA_RECEIVE_DOORBELL,
+			mthca_ring_db(db, dev->kar + MTHCA_RECEIVE_DOORBELL,
 				      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 
 			qp->rq.head += MTHCA_TAVOR_MAX_WQES_PER_RECV_DB;
@@ -1852,13 +1850,12 @@ int mthca_tavor_post_receive(struct ib_q
 
 out:
 	if (likely(nreq)) {
-		doorbell[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);
-		doorbell[1] = cpu_to_be32((qp->qpn << 8) | nreq);
+		db.val32[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);
+		db.val32[1] = cpu_to_be32((qp->qpn << 8) | nreq);
 
 		wmb();
 
-		mthca_write64(doorbell,
-			      dev->kar + MTHCA_RECEIVE_DOORBELL,
+		mthca_ring_db(db, dev->kar + MTHCA_RECEIVE_DOORBELL,
 			      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 	}
 
@@ -1880,7 +1877,7 @@ int mthca_arbel_post_send(struct ib_qp *
 {
 	struct mthca_dev *dev = to_mdev(ibqp->device);
 	struct mthca_qp *qp = to_mqp(ibqp);
-	__be32 doorbell[2];
+	union mthca_doorbell db;
 	void *wqe;
 	void *prev_wqe;
 	unsigned long flags;
@@ -1903,10 +1900,10 @@ int mthca_arbel_post_send(struct ib_qp *
 		if (unlikely(nreq == MTHCA_ARBEL_MAX_WQES_PER_SEND_DB)) {
 			nreq = 0;
 
-			doorbell[0] = cpu_to_be32((MTHCA_ARBEL_MAX_WQES_PER_SEND_DB << 24) |
+			db.val32[0] = cpu_to_be32((MTHCA_ARBEL_MAX_WQES_PER_SEND_DB << 24) |
 						  ((qp->sq.head & 0xffff) << 8) |
 						  f0 | op0);
-			doorbell[1] = cpu_to_be32((qp->qpn << 8) | size0);
+			db.val32[1] = cpu_to_be32((qp->qpn << 8) | size0);
 
 			qp->sq.head += MTHCA_ARBEL_MAX_WQES_PER_SEND_DB;
 			size0 = 0;
@@ -1923,8 +1920,7 @@ int mthca_arbel_post_send(struct ib_qp *
 			 * write MMIO send doorbell.
 			 */
 			wmb();
-			mthca_write64(doorbell,
-				      dev->kar + MTHCA_SEND_DOORBELL,
+			mthca_ring_db(db, dev->kar + MTHCA_SEND_DOORBELL,
 				      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 		}
 
@@ -2108,10 +2104,10 @@ int mthca_arbel_post_send(struct ib_qp *
 
 out:
 	if (likely(nreq)) {
-		doorbell[0] = cpu_to_be32((nreq << 24)                  |
+		db.val32[0] = cpu_to_be32((nreq << 24)                  |
 					  ((qp->sq.head & 0xffff) << 8) |
 					  f0 | op0);
-		doorbell[1] = cpu_to_be32((qp->qpn << 8) | size0);
+		db.val32[1] = cpu_to_be32((qp->qpn << 8) | size0);
 
 		qp->sq.head += nreq;
 
@@ -2127,8 +2123,7 @@ out:
 		 * write MMIO send doorbell.
 		 */
 		wmb();
-		mthca_write64(doorbell,
-			      dev->kar + MTHCA_SEND_DOORBELL,
+		mthca_ring_db(db, dev->kar + MTHCA_SEND_DOORBELL,
 			      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 	}
 
diff -rup ofa_kernel-1.2.orig/drivers/infiniband/hw/mthca/mthca_srq.c ofa_kernel-1.2/drivers/infiniband/hw/mthca/mthca_srq.c
--- ofa_kernel-1.2.orig/drivers/infiniband/hw/mthca/mthca_srq.c	2007-07-20 14:42:52.862494291 -0700
+++ ofa_kernel-1.2/drivers/infiniband/hw/mthca/mthca_srq.c	2007-07-25 17:26:07.925761483 -0700
@@ -485,7 +485,7 @@ int mthca_tavor_post_srq_recv(struct ib_
 {
 	struct mthca_dev *dev = to_mdev(ibsrq->device);
 	struct mthca_srq *srq = to_msrq(ibsrq);
-	__be32 doorbell[2];
+	union mthca_doorbell db;
 	unsigned long flags;
 	int err = 0;
 	int first_ind;
@@ -565,8 +565,8 @@ int mthca_tavor_post_srq_recv(struct ib_
 		if (unlikely(nreq == MTHCA_TAVOR_MAX_WQES_PER_RECV_DB)) {
 			nreq = 0;
 
-			doorbell[0] = cpu_to_be32(first_ind << srq->wqe_shift);
-			doorbell[1] = cpu_to_be32(srq->srqn << 8);
+			db.val32[0] = cpu_to_be32(first_ind << srq->wqe_shift);
+			db.val32[1] = cpu_to_be32(srq->srqn << 8);
 
 			/*
 			 * Make sure that descriptors are written
@@ -574,8 +574,7 @@ int mthca_tavor_post_srq_recv(struct ib_
 			 */
 			wmb();
 
-			mthca_write64(doorbell,
-				      dev->kar + MTHCA_RECEIVE_DOORBELL,
+			mthca_ring_db(db, dev->kar + MTHCA_RECEIVE_DOORBELL,
 				      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 
 			first_ind = srq->first_free;
@@ -583,8 +582,8 @@ int mthca_tavor_post_srq_recv(struct ib_
 	}
 
 	if (likely(nreq)) {
-		doorbell[0] = cpu_to_be32(first_ind << srq->wqe_shift);
-		doorbell[1] = cpu_to_be32((srq->srqn << 8) | nreq);
+		db.val32[0] = cpu_to_be32(first_ind << srq->wqe_shift);
+		db.val32[1] = cpu_to_be32((srq->srqn << 8) | nreq);
 
 		/*
 		 * Make sure that descriptors are written before
@@ -592,8 +591,7 @@ int mthca_tavor_post_srq_recv(struct ib_
 		 */
 		wmb();
 
-		mthca_write64(doorbell,
-			      dev->kar + MTHCA_RECEIVE_DOORBELL,
+		mthca_ring_db(db, dev->kar + MTHCA_RECEIVE_DOORBELL,
 			      MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
 	}
 
-- 
Arthur

_______________________________________________
general mailing list
general at lists.openfabrics.org
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

-- 
MST



More information about the general mailing list