Skip to content

Commit ff980e3

Browse files
committed
w1: masters: w1-uart: Cap consecutive HDQ timeouts on guarded variants
Follow up on transient HDQ timeout retries by faulting a guarded (`hdq_fail_stop`) link after 5 consecutive completely exhausted reads (15 consecutive timed-out cycles with no successful response), so a permanently dead HDQ line stops retrying instead of spinning forever. Any successful transfer resets the counter. Assisted-by: LLM Signed-off-by: Grier Johnson <grier@scooterfarm.com>
1 parent 182354d commit ff980e3

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎drivers/w1/masters/w1-uart.c‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
/* A transaction takes a few ms; do not hold the bus for long on a miss. */
3636
#define W1_UART_HDQ_TIMEOUT msecs_to_jiffies(100)
3737
#define W1_UART_HDQ_TRIES 3
38+
/* Consecutive exhausted reads before faulting a guarded HDQ link. */
39+
#define W1_UART_HDQ_MAX_TIMEOUTS 5
3840
#define W1_UART_HDQ_BREAK_MIN_US 250
3941
#define W1_UART_HDQ_BREAK_MAX_US 500
4042
#define W1_UART_HDQ_RECOVERY_MIN_US 150
@@ -98,6 +100,7 @@ struct w1_uart_config {
98100
struct w1_uart_device {
99101
bool hdq_faulted;
100102
bool hdq_fail_stop;
103+
unsigned int hdq_consecutive_timeouts;
101104
const u8 *hdq_read_regs;
102105
size_t hdq_num_read_regs;
103106
unsigned long hdq_deadline;
@@ -536,12 +539,22 @@ static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command,
536539
}
537540

538541
if (ret == -ETIMEDOUT) {
539-
if (w1dev->hdq_fail_stop)
540-
dev_warn_ratelimited(&w1dev->serdev->dev,
541-
"HDQ read %02x timed out after %u %s\n",
542-
command, tries,
543-
tries == 1 ? "try" : "tries");
542+
if (w1dev->hdq_fail_stop) {
543+
w1dev->hdq_consecutive_timeouts++;
544+
if (w1dev->hdq_consecutive_timeouts >=
545+
W1_UART_HDQ_MAX_TIMEOUTS)
546+
w1_uart_hdq_stop_on_error(w1dev, "read", ret);
547+
else
548+
dev_warn_ratelimited(&w1dev->serdev->dev,
549+
"HDQ read %02x timed out after %u %s (%u/%u)\n",
550+
command, tries,
551+
tries == 1 ? "try" : "tries",
552+
w1dev->hdq_consecutive_timeouts,
553+
W1_UART_HDQ_MAX_TIMEOUTS);
554+
}
544555
} else {
556+
if (!ret)
557+
w1dev->hdq_consecutive_timeouts = 0;
545558
w1_uart_hdq_stop_on_error(w1dev, "read", ret);
546559
}
547560
return ret;

0 commit comments

Comments
 (0)