Skip to content

Commit 6d0de60

Browse files
Weili Qianherbertx
authored andcommitted
crypto: hisilicon/qm - increase wait time for mailbox
The device requires more time to process queue stop and function stop mailbox commands compared to other mailbox commands . In the current driver, the mailbox processing wait time for queue stop and function stop is less than the device timeout, which may cause the driver to incorrectly assume that the mailbox processing has failed. Therefore, the driver wait time for queue stop and function stop should be set to be greater than the device timeout. And PF and VF communication relies on mailbox, the communication wait time should also be modified. Signed-off-by: Weili Qian <qianweili@huawei.com> Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 3296992 commit 6d0de60

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

  • drivers/crypto/hisilicon

drivers/crypto/hisilicon/qm.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define QM_MB_PING_ALL_VFS 0xffff
3333
#define QM_MB_STATUS_MASK GENMASK(12, 9)
3434
#define QM_MB_BUSY_MASK BIT(13)
35+
#define QM_MB_MAX_WAIT_TIMEOUT USEC_PER_SEC
36+
#define QM_MB_MAX_STOP_TIMEOUT (5 * USEC_PER_SEC)
3537

3638
/* sqc shift */
3739
#define QM_SQ_HOP_NUM_SHIFT 0
@@ -189,8 +191,8 @@
189191
#define QM_IFC_INT_DISABLE BIT(0)
190192
#define QM_IFC_INT_STATUS_MASK BIT(0)
191193
#define QM_IFC_INT_SET_MASK BIT(0)
192-
#define QM_WAIT_DST_ACK 10
193-
#define QM_MAX_PF_WAIT_COUNT 10
194+
#define QM_WAIT_DST_ACK 1000
195+
#define QM_MAX_PF_WAIT_COUNT 20
194196
#define QM_MAX_VF_WAIT_COUNT 40
195197
#define QM_VF_RESET_WAIT_US 20000
196198
#define QM_VF_RESET_WAIT_CNT 3000
@@ -645,14 +647,14 @@ int hisi_qm_wait_mb_ready(struct hisi_qm *qm)
645647
}
646648
EXPORT_SYMBOL_GPL(hisi_qm_wait_mb_ready);
647649

648-
static int qm_wait_mb_finish(struct hisi_qm *qm, struct qm_mailbox *mailbox)
650+
static int qm_wait_mb_finish(struct hisi_qm *qm, struct qm_mailbox *mailbox, u32 wait_timeout)
649651
{
650652
struct device *dev = &qm->pdev->dev;
651653
int ret;
652654

653655
ret = read_poll_timeout(qm_mb_read, *mailbox,
654656
!(le16_to_cpu(mailbox->w0) & QM_MB_BUSY_MASK),
655-
POLL_PERIOD, POLL_TIMEOUT,
657+
POLL_PERIOD, wait_timeout,
656658
true, qm);
657659
if (ret) {
658660
dev_err(dev, "QM mailbox operation timeout!\n");
@@ -667,7 +669,7 @@ static int qm_wait_mb_finish(struct hisi_qm *qm, struct qm_mailbox *mailbox)
667669
return 0;
668670
}
669671

670-
static int qm_mb_nolock(struct hisi_qm *qm, struct qm_mailbox *mailbox)
672+
static int qm_mb_nolock(struct hisi_qm *qm, struct qm_mailbox *mailbox, u32 wait_timeout)
671673
{
672674
int ret;
673675

@@ -677,7 +679,7 @@ static int qm_mb_nolock(struct hisi_qm *qm, struct qm_mailbox *mailbox)
677679

678680
qm_mb_write(qm, mailbox);
679681

680-
ret = qm_wait_mb_finish(qm, mailbox);
682+
ret = qm_wait_mb_finish(qm, mailbox, wait_timeout);
681683
if (ret)
682684
goto mb_err_cnt_increase;
683685

@@ -692,12 +694,24 @@ int hisi_qm_mb(struct hisi_qm *qm, u8 cmd, dma_addr_t dma_addr, u16 queue,
692694
bool op)
693695
{
694696
struct qm_mailbox mailbox;
697+
u32 wait_timeout;
695698
int ret;
696699

700+
if (cmd == QM_MB_CMD_STOP_QP || cmd == QM_MB_CMD_FLUSH_QM)
701+
wait_timeout = QM_MB_MAX_STOP_TIMEOUT;
702+
else
703+
wait_timeout = QM_MB_MAX_WAIT_TIMEOUT;
704+
705+
/* No need to judge if master OOO is blocked. */
706+
if (qm_check_dev_error(qm)) {
707+
dev_err(&qm->pdev->dev, "QM mailbox operation failed since qm is stop!\n");
708+
return -EIO;
709+
}
710+
697711
qm_mb_pre_init(&mailbox, cmd, dma_addr, queue, op);
698712

699713
mutex_lock(&qm->mailbox_lock);
700-
ret = qm_mb_nolock(qm, &mailbox);
714+
ret = qm_mb_nolock(qm, &mailbox, wait_timeout);
701715
mutex_unlock(&qm->mailbox_lock);
702716

703717
return ret;
@@ -711,7 +725,7 @@ int hisi_qm_mb_read(struct hisi_qm *qm, u64 *base, u8 cmd, u16 queue)
711725

712726
qm_mb_pre_init(&mailbox, cmd, 0, queue, 1);
713727
mutex_lock(&qm->mailbox_lock);
714-
ret = qm_mb_nolock(qm, &mailbox);
728+
ret = qm_mb_nolock(qm, &mailbox, QM_MB_MAX_WAIT_TIMEOUT);
715729
mutex_unlock(&qm->mailbox_lock);
716730
if (ret)
717731
return ret;
@@ -769,7 +783,7 @@ int qm_set_and_get_xqc(struct hisi_qm *qm, u8 cmd, void *xqc, u32 qp_id, bool op
769783
memcpy(tmp_xqc, xqc, size);
770784

771785
qm_mb_pre_init(&mailbox, cmd, xqc_dma, qp_id, op);
772-
ret = qm_mb_nolock(qm, &mailbox);
786+
ret = qm_mb_nolock(qm, &mailbox, QM_MB_MAX_WAIT_TIMEOUT);
773787
if (!ret && op)
774788
memcpy(xqc, tmp_xqc, size);
775789

@@ -1897,7 +1911,7 @@ static int qm_set_ifc_begin_v3(struct hisi_qm *qm, enum qm_ifc_cmd cmd, u32 data
18971911

18981912
qm_mb_pre_init(&mailbox, QM_MB_CMD_SRC, msg, fun_num, 0);
18991913
mutex_lock(&qm->mailbox_lock);
1900-
return qm_mb_nolock(qm, &mailbox);
1914+
return qm_mb_nolock(qm, &mailbox, QM_MB_MAX_WAIT_TIMEOUT);
19011915
}
19021916

19031917
static void qm_set_ifc_end_v3(struct hisi_qm *qm)

0 commit comments

Comments
 (0)