Skip to content

Commit 292b335

Browse files
larrchjgunthorpe
authored andcommitted
RDMA/hns: Adjust fields and variables about CMDQ tail/head
The register 0x07014 is actually the head pointer of CMDQ, and 0x07010 means tail pointer. Current definitions are confusing, so rename them and related variables. The next_to_use of structure hns_roce_v2_cmq_ring has the same semantics as head, merge them into one member. The next_to_clean of structure hns_roce_v2_cmq_ring has the same semantics as tail. After deleting next_to_clean, tail should also be deleted. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lang Cheng <[email protected]> Signed-off-by: Weihang Li <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 563aeb2 commit 292b335

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

drivers/infiniband/hw/hns/hns_roce_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@
364364
#define ROCEE_TX_CMQ_BASEADDR_L_REG 0x07000
365365
#define ROCEE_TX_CMQ_BASEADDR_H_REG 0x07004
366366
#define ROCEE_TX_CMQ_DEPTH_REG 0x07008
367-
#define ROCEE_TX_CMQ_TAIL_REG 0x07010
368-
#define ROCEE_TX_CMQ_HEAD_REG 0x07014
367+
#define ROCEE_TX_CMQ_HEAD_REG 0x07010
368+
#define ROCEE_TX_CMQ_TAIL_REG 0x07014
369369

370370
#define ROCEE_RX_CMQ_BASEADDR_L_REG 0x07018
371371
#define ROCEE_RX_CMQ_BASEADDR_H_REG 0x0701c

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ static int hns_roce_init_cmq_ring(struct hns_roce_dev *hr_dev, bool ring_type)
11691169
&priv->cmq.csq : &priv->cmq.crq;
11701170

11711171
ring->flag = ring_type;
1172-
ring->next_to_use = 0;
1172+
ring->head = 0;
11731173

11741174
return hns_roce_alloc_cmq_desc(hr_dev, ring);
11751175
}
@@ -1268,10 +1268,10 @@ static void hns_roce_cmq_setup_basic_desc(struct hns_roce_cmq_desc *desc,
12681268

12691269
static int hns_roce_cmq_csq_done(struct hns_roce_dev *hr_dev)
12701270
{
1271-
u32 head = roce_read(hr_dev, ROCEE_TX_CMQ_HEAD_REG);
1271+
u32 tail = roce_read(hr_dev, ROCEE_TX_CMQ_TAIL_REG);
12721272
struct hns_roce_v2_priv *priv = hr_dev->priv;
12731273

1274-
return head == priv->cmq.csq.next_to_use;
1274+
return tail == priv->cmq.csq.head;
12751275
}
12761276

12771277
static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev,
@@ -1283,25 +1283,25 @@ static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev,
12831283
u32 timeout = 0;
12841284
int handle = 0;
12851285
u16 desc_ret;
1286+
u32 tail;
12861287
int ret;
1287-
int ntc;
12881288

12891289
spin_lock_bh(&csq->lock);
12901290

1291-
ntc = csq->next_to_use;
1291+
tail = csq->head;
12921292

12931293
while (handle < num) {
1294-
desc_to_use = &csq->desc[csq->next_to_use];
1294+
desc_to_use = &csq->desc[csq->head];
12951295
*desc_to_use = desc[handle];
12961296
dev_dbg(hr_dev->dev, "set cmq desc:\n");
1297-
csq->next_to_use++;
1298-
if (csq->next_to_use == csq->desc_num)
1299-
csq->next_to_use = 0;
1297+
csq->head++;
1298+
if (csq->head == csq->desc_num)
1299+
csq->head = 0;
13001300
handle++;
13011301
}
13021302

13031303
/* Write to hardware */
1304-
roce_write(hr_dev, ROCEE_TX_CMQ_TAIL_REG, csq->next_to_use);
1304+
roce_write(hr_dev, ROCEE_TX_CMQ_HEAD_REG, csq->head);
13051305

13061306
/*
13071307
* If the command is sync, wait for the firmware to write back,
@@ -1321,24 +1321,25 @@ static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev,
13211321
ret = 0;
13221322
while (handle < num) {
13231323
/* get the result of hardware write back */
1324-
desc_to_use = &csq->desc[ntc];
1324+
desc_to_use = &csq->desc[tail];
13251325
desc[handle] = *desc_to_use;
13261326
dev_dbg(hr_dev->dev, "Get cmq desc:\n");
13271327
desc_ret = le16_to_cpu(desc[handle].retval);
13281328
if (unlikely(desc_ret != CMD_EXEC_SUCCESS))
13291329
ret = -EIO;
13301330

1331-
ntc++;
1331+
tail++;
13321332
handle++;
1333-
if (ntc == csq->desc_num)
1334-
ntc = 0;
1333+
if (tail == csq->desc_num)
1334+
tail = 0;
13351335
}
13361336
} else {
13371337
/* FW/HW reset or incorrect number of desc */
1338-
ntc = roce_read(hr_dev, ROCEE_TX_CMQ_HEAD_REG);
1339-
dev_warn(hr_dev->dev, "CMDQ move head from %d to %d\n",
1340-
csq->next_to_use, ntc);
1341-
csq->next_to_use = ntc;
1338+
tail = roce_read(hr_dev, ROCEE_TX_CMQ_TAIL_REG);
1339+
dev_warn(hr_dev->dev, "CMDQ move tail from %d to %d\n",
1340+
csq->head, tail);
1341+
csq->head = tail;
1342+
13421343
ret = -EAGAIN;
13431344
}
13441345

drivers/infiniband/hw/hns/hns_roce_hw_v2.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,11 +1876,8 @@ struct hns_roce_v2_cmq_ring {
18761876
dma_addr_t desc_dma_addr;
18771877
struct hns_roce_cmq_desc *desc;
18781878
u32 head;
1879-
u32 tail;
1880-
18811879
u16 buf_size;
18821880
u16 desc_num;
1883-
int next_to_use;
18841881
u8 flag;
18851882
spinlock_t lock; /* command queue lock */
18861883
};

0 commit comments

Comments
 (0)