From: "Michael S. Tsirkin" Clean up CQ code so that we only calculate the address of a CQ entry once when using it. Signed-off-by: Michael S. Tsirkin Signed-off-by: Roland Dreier Signed-off-by: Andrew Morton --- 25-akpm/drivers/infiniband/hw/mthca/mthca_cq.c | 26 ++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-) diff -puN drivers/infiniband/hw/mthca/mthca_cq.c~ib-mthca-cq-minor-tweaks drivers/infiniband/hw/mthca/mthca_cq.c --- 25/drivers/infiniband/hw/mthca/mthca_cq.c~ib-mthca-cq-minor-tweaks 2005-03-03 17:39:52.000000000 -0800 +++ 25-akpm/drivers/infiniband/hw/mthca/mthca_cq.c 2005-03-03 17:39:52.000000000 -0800 @@ -147,20 +147,21 @@ static inline struct mthca_cqe *get_cqe( + (entry * MTHCA_CQ_ENTRY_SIZE) % PAGE_SIZE; } -static inline int cqe_sw(struct mthca_cq *cq, int i) +static inline struct mthca_cqe *cqe_sw(struct mthca_cq *cq, int i) { - return !(MTHCA_CQ_ENTRY_OWNER_HW & - get_cqe(cq, i)->owner); + struct mthca_cqe *cqe; + cqe = get_cqe(cq, i); + return (MTHCA_CQ_ENTRY_OWNER_HW & cqe->owner) ? NULL : cqe; } -static inline int next_cqe_sw(struct mthca_cq *cq) +static inline struct mthca_cqe *next_cqe_sw(struct mthca_cq *cq) { return cqe_sw(cq, cq->cons_index); } -static inline void set_cqe_hw(struct mthca_cq *cq, int entry) +static inline void set_cqe_hw(struct mthca_cqe *cqe) { - get_cqe(cq, entry)->owner = MTHCA_CQ_ENTRY_OWNER_HW; + cqe->owner = MTHCA_CQ_ENTRY_OWNER_HW; } static inline void inc_cons_index(struct mthca_dev *dev, struct mthca_cq *cq, @@ -388,7 +389,8 @@ static inline int mthca_poll_one(struct int free_cqe = 1; int err = 0; - if (!next_cqe_sw(cq)) + cqe = next_cqe_sw(cq); + if (!cqe) return -EAGAIN; /* @@ -397,8 +399,6 @@ static inline int mthca_poll_one(struct */ rmb(); - cqe = get_cqe(cq, cq->cons_index); - if (0) { mthca_dbg(dev, "%x/%d: CQE -> QPN %06x, WQE @ %08x\n", cq->cqn, cq->cons_index, be32_to_cpu(cqe->my_qpn), @@ -509,8 +509,8 @@ static inline int mthca_poll_one(struct entry->status = IB_WC_SUCCESS; out: - if (free_cqe) { - set_cqe_hw(cq, cq->cons_index); + if (likely(free_cqe)) { + set_cqe_hw(cqe); ++(*freed); cq->cons_index = (cq->cons_index + 1) & cq->ibcq.cqe; } @@ -655,7 +655,7 @@ int mthca_init_cq(struct mthca_dev *dev, } for (i = 0; i < nent; ++i) - set_cqe_hw(cq, i); + set_cqe_hw(get_cqe(cq, i)); cq->cqn = mthca_alloc(&dev->cq_table.alloc); if (cq->cqn == -1) @@ -773,7 +773,7 @@ void mthca_free_cq(struct mthca_dev *dev int j; printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n", - cq->cqn, cq->cons_index, next_cqe_sw(cq)); + cq->cqn, cq->cons_index, !!next_cqe_sw(cq)); for (j = 0; j < 16; ++j) printk(KERN_ERR "[%2x] %08x\n", j * 4, be32_to_cpu(ctx[j])); } _