Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3838486pxj; Tue, 11 May 2021 13:03:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwuqbvcrSTkotWyLbaXIwYCDNqL3acHDrEwR6vBSE9aveSHvKAJVthOLTkXG6D4WEJj/XL X-Received: by 2002:a05:6402:2218:: with SMTP id cq24mr21309025edb.213.1620763425257; Tue, 11 May 2021 13:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620763425; cv=none; d=google.com; s=arc-20160816; b=v+0xhIxKtfzm9u6F6vNq0HKSEluFZmGFXinMNXWsoXl5kCgO2abLgItYThYokrzNKR KOypWPk+EMKLWP6bjni9TrP3QvWktFwP5AVG0nYb3+jrWkBpOeodF8f3XVkniEUD+m2h gLB/0INBaBAQ0bQHZ8Vfx6+EGyXiUKL0JZOiERwVS3TcrtrnY9BTiuE3OnRqcS+HGU75 X9D1ID2HwMKRFZDelgVlKqBYcMSg/1stRpJyca3ju9ZR8BlWpCXgvYEHeaLvXgTVU7Gi kvKSLJbCXG9gjyuVJT5Sd5P/RNKnlRXgPFPKzMLdYgRUvP55iMlR9tynzOJnVuB1Zln9 80wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cyDiQUyNgBgGc+H3cFQoAm5Uka2UF4lgSKM+qeTxRAQ=; b=mqy5oA9z24F8uLmfnH8YX5ZbXV3ytcEocS0BKQWUDqc6d7/NtWuCx/ijum8iinFHZ0 C0wrJ3okqOFR7wXVhVJ5D/JL5KNSkQnpw3wK+PhE/rjeWf88kQ4CcXJYxs6pB2KxK0CX JGnZ7Hs3A9rfqKeork3SM79ScU/QUa4soQX0l3GJ0jWhS49GzJytLWmtKeOta9yv9Tg1 ry3Hybh+pfkoN1HrcUnLR6etxkbbMPh90txhBKi3v0e4dY+aDnrzHxr8HPEHMoBT8hIZ dv0u9q6juahzKzBo8yv7PdvyCcapnxTGAGLyM6emLmGzLC8ruEf3EFkdccTRxjYWmHCD XKtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=Noju+nZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si2483749ejj.204.2021.05.11.13.03.21; Tue, 11 May 2021 13:03:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=Noju+nZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230198AbhEKUDT (ORCPT + 99 others); Tue, 11 May 2021 16:03:19 -0400 Received: from ssl.serverraum.org ([176.9.125.105]:43473 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbhEKUDL (ORCPT ); Tue, 11 May 2021 16:03:11 -0400 Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id AA0892226E; Tue, 11 May 2021 22:02:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1620763323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cyDiQUyNgBgGc+H3cFQoAm5Uka2UF4lgSKM+qeTxRAQ=; b=Noju+nZmmG1XjrgW2szmzE17vTeHwZ2/HjvcNiRDNY1bapLnPkBEgqVtaB/byTiAweaC8V Sb/qDZE9zUl97RgvgVkrxHpZjawUmwI3G7EUGjy285H+tczQ7jtkXVArJyEOby+QRn4Qkm fNCARjZI14zXEsxNoPaW4KpCwZqId34= From: Michael Walle To: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Angelo Dureghello , Fugang Duan , Philippe Schenker , Michael Walle Subject: [PATCH 4/8] serial: fsl_lpuart: handle break and make sysrq work Date: Tue, 11 May 2021 22:01:44 +0200 Message-Id: <20210511200148.11934-5-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210511200148.11934-1-michael@walle.cc> References: <20210511200148.11934-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Although there is already (broken) sysrq characters handling, a break condition was never detected. There is also a possible deadlock because we might call handle_sysrq() while still holding the port lock. Add support for break detection and use the proper uart_unlock_and_check_sysrq() to defer calling handle_sysrq(). Signed-off-by: Michael Walle --- drivers/tty/serial/fsl_lpuart.c | 36 ++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index 37e02d992c0b..0a578ad31a19 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -910,6 +910,7 @@ static void lpuart32_rxint(struct lpuart_port *sport) unsigned int flg, ignored = 0; struct tty_port *port = &sport->port.state->port; unsigned long rx, sr; + bool is_break; spin_lock(&sport->port.lock); @@ -924,14 +925,27 @@ static void lpuart32_rxint(struct lpuart_port *sport) rx = lpuart32_read(&sport->port, UARTDATA); rx &= UARTDATA_MASK; - if (uart_handle_sysrq_char(&sport->port, rx)) + /* + * The LPUART can't distinguish between a break and a framing error, + * thus we assume it is a break if the received data is zero. + */ + is_break = sr & UARTSTAT_FE && !rx; + + if (is_break && uart_handle_break(&sport->port)) + continue; + + if (uart_prepare_sysrq_char(&sport->port, rx)) continue; if (sr & (UARTSTAT_PE | UARTSTAT_OR | UARTSTAT_FE)) { - if (sr & UARTSTAT_PE) - sport->port.icount.parity++; - else if (sr & UARTSTAT_FE) + if (sr & UARTSTAT_PE) { + if (is_break) + sport->port.icount.brk++; + else + sport->port.icount.parity++; + } else if (sr & UARTSTAT_FE) { sport->port.icount.frame++; + } if (sr & UARTSTAT_OR) sport->port.icount.overrun++; @@ -944,22 +958,24 @@ static void lpuart32_rxint(struct lpuart_port *sport) sr &= sport->port.read_status_mask; - if (sr & UARTSTAT_PE) - flg = TTY_PARITY; - else if (sr & UARTSTAT_FE) + if (sr & UARTSTAT_PE) { + if (is_break) + flg = TTY_BREAK; + else + flg = TTY_PARITY; + } else if (sr & UARTSTAT_FE) { flg = TTY_FRAME; + } if (sr & UARTSTAT_OR) flg = TTY_OVERRUN; - - sport->port.sysrq = 0; } tty_insert_flip_char(port, rx, flg); } out: - spin_unlock(&sport->port.lock); + uart_unlock_and_check_sysrq(&sport->port); tty_flip_buffer_push(port); } -- 2.20.1