|
@@ -56,11 +56,11 @@ static int send_cold_reset_protection_cmd(struct nfc_dev *nfc_dev,
|
|
|
|
|
|
*cmd++ = NCI_PROP_MSG_CMD;
|
|
*cmd++ = NCI_PROP_MSG_CMD;
|
|
|
|
|
|
- if (requestType) { /* reset protection */
|
|
|
|
|
|
+ if (requestType) { /* reset protection */
|
|
*cmd++ = RST_PROT_OID;
|
|
*cmd++ = RST_PROT_OID;
|
|
*cmd++ = RST_PROT_PAYLOAD_SIZE;
|
|
*cmd++ = RST_PROT_PAYLOAD_SIZE;
|
|
*cmd++ = (!cold_reset->reset_protection) ? 1 : 0;
|
|
*cmd++ = (!cold_reset->reset_protection) ? 1 : 0;
|
|
- } else { /* cold reset */
|
|
|
|
|
|
+ } else { /* cold reset */
|
|
*cmd++ = CLD_RST_OID;
|
|
*cmd++ = CLD_RST_OID;
|
|
*cmd++ = CLD_RST_PAYLOAD_SIZE;
|
|
*cmd++ = CLD_RST_PAYLOAD_SIZE;
|
|
}
|
|
}
|
|
@@ -149,6 +149,7 @@ static int perform_cold_reset_protection(struct nfc_dev *nfc_dev,
|
|
{
|
|
{
|
|
int ret = 0;
|
|
int ret = 0;
|
|
int timeout = 0;
|
|
int timeout = 0;
|
|
|
|
+ int retry_cnt = 0;
|
|
char *rsp = nfc_dev->read_kbuf;
|
|
char *rsp = nfc_dev->read_kbuf;
|
|
struct cold_reset *cold_reset = &nfc_dev->cold_reset;
|
|
struct cold_reset *cold_reset = &nfc_dev->cold_reset;
|
|
|
|
|
|
@@ -203,41 +204,50 @@ static int perform_cold_reset_protection(struct nfc_dev *nfc_dev,
|
|
}
|
|
}
|
|
|
|
|
|
timeout = NCI_CMD_RSP_TIMEOUT_MS;
|
|
timeout = NCI_CMD_RSP_TIMEOUT_MS;
|
|
|
|
+ mutex_lock(&nfc_dev->dev_ref_mutex);
|
|
do {
|
|
do {
|
|
- /* call read api directly if reader thread is not blocked */
|
|
|
|
- if (mutex_trylock(&nfc_dev->read_mutex)) {
|
|
|
|
- pr_debug("%s: reader thread not pending\n", __func__);
|
|
|
|
- ret = nfc_dev->nfc_read(nfc_dev, rsp, 3,
|
|
|
|
- timeout);
|
|
|
|
- mutex_unlock(&nfc_dev->read_mutex);
|
|
|
|
|
|
+ if (nfc_dev->cold_reset.is_nfc_read_pending) {
|
|
|
|
+ if (!wait_event_interruptible_timeout
|
|
|
|
+ (cold_reset->read_wq,
|
|
|
|
+ cold_reset->rsp_pending == false,
|
|
|
|
+ msecs_to_jiffies(timeout))) {
|
|
|
|
+ pr_err("%s: cold reset/prot response timeout\n",
|
|
|
|
+ __func__);
|
|
|
|
+ if (retry_cnt <= 1) {
|
|
|
|
+ retry_cnt = retry_cnt + 1;
|
|
|
|
+ ret = -EAGAIN;
|
|
|
|
+ } else {
|
|
|
|
+ pr_debug("%s: Maximum retry reached",
|
|
|
|
+ __func__);
|
|
|
|
+ ret = -ETIMEDOUT;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ret = nfc_dev->nfc_read(nfc_dev, rsp, 3, timeout);
|
|
if (!ret)
|
|
if (!ret)
|
|
break;
|
|
break;
|
|
usleep_range(READ_RETRY_WAIT_TIME_US,
|
|
usleep_range(READ_RETRY_WAIT_TIME_US,
|
|
- READ_RETRY_WAIT_TIME_US + 500);
|
|
|
|
- /* Read pending response form the HAL service */
|
|
|
|
- } else if (!wait_event_interruptible_timeout(
|
|
|
|
- cold_reset->read_wq,
|
|
|
|
- cold_reset->rsp_pending == false,
|
|
|
|
- msecs_to_jiffies(timeout))) {
|
|
|
|
- pr_err("%s: cold reset/prot response timeout\n", __func__);
|
|
|
|
- ret = -EAGAIN;
|
|
|
|
|
|
+ READ_RETRY_WAIT_TIME_US + 500);
|
|
}
|
|
}
|
|
- } while (ret == -ERESTARTSYS || ret == -EFAULT);
|
|
|
|
|
|
+ } while (ret == -ERESTARTSYS || ret == -EFAULT || ret == -EAGAIN);
|
|
|
|
+ mutex_unlock(&nfc_dev->dev_ref_mutex);
|
|
mutex_unlock(&nfc_dev->write_mutex);
|
|
mutex_unlock(&nfc_dev->write_mutex);
|
|
|
|
|
|
timeout = ESE_CLD_RST_REBOOT_GUARD_TIME_MS;
|
|
timeout = ESE_CLD_RST_REBOOT_GUARD_TIME_MS;
|
|
- if (ret == 0) { /* success case */
|
|
|
|
|
|
+ if (ret == 0) { /* success case */
|
|
ret = cold_reset->status;
|
|
ret = cold_reset->status;
|
|
if (IS_RST_PROT_REQ(arg)) {
|
|
if (IS_RST_PROT_REQ(arg)) {
|
|
cold_reset->reset_protection = IS_RST_PROT_EN_REQ(arg);
|
|
cold_reset->reset_protection = IS_RST_PROT_EN_REQ(arg);
|
|
cold_reset->rst_prot_src = IS_RST_PROT_EN_REQ(arg) ?
|
|
cold_reset->rst_prot_src = IS_RST_PROT_EN_REQ(arg) ?
|
|
- GET_SRC(arg) :
|
|
|
|
- SRC_NONE;
|
|
|
|
|
|
+ GET_SRC(arg) : SRC_NONE;
|
|
/* wait for reboot guard timer */
|
|
/* wait for reboot guard timer */
|
|
- } else if (wait_event_interruptible_timeout(
|
|
|
|
- cold_reset->read_wq, true,
|
|
|
|
- msecs_to_jiffies(timeout)) == 0) {
|
|
|
|
- pr_info("%s: reboot guard timer timeout\n", __func__);
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if (wait_event_interruptible_timeout
|
|
|
|
+ (cold_reset->read_wq, true,
|
|
|
|
+ msecs_to_jiffies(timeout)) == 0) {
|
|
|
|
+ pr_info("%s: reboot guard timer timeout\n",
|
|
|
|
+ __func__);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
err:
|
|
err:
|