Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5927797pxv; Thu, 29 Jul 2021 01:49:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfnh0AvaYca/+QooZhXa393pMOmfxKeuunph/RZuhOXoK3eygmQARocAA+4mrxtQ25NY/F X-Received: by 2002:a17:906:350c:: with SMTP id r12mr3705777eja.44.1627548574081; Thu, 29 Jul 2021 01:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627548574; cv=none; d=google.com; s=arc-20160816; b=kHNry+KsvsR8pYfC9t9JUkmqP74+diLdLJmzrPH8vep6kmADBzs7VMO4VSpPTmZlp3 +r6q/bLNpk8ZsH3Heea0e59dZO4IEb9fDaziAFLcF3c8dM7FlDoduHYvEc0E7hBITxcJ 2635rheqeLLMzfmuO8UuifcCS86aZcIp6fOf2KFkDk84sqnkUHR7m8JYoJj+Rq8JIKBQ aFH+YGW9a+DBrvrCfJxsOjvrkoWRfmA5Zyksn2eFDnb0B0bOKfL1EBkUJ5/l+0TPpJjh pouVUpbB3jpNEpZ7UQDd0BFdOjqiobswBu1T8gp8IgHP52RK+UPn8RjUs5/PaL5MQiBY M59g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=jEFz74JaonEoDbkIZve09S140inwXiyCwoE+MTFaVME=; b=iNvF94Dmfkut3ukRR9FqFT8YjQGkcaYLUEYMCTAy72nCQk+VIOUUDWEEXLT4xhoipv ofrAUp6lDlL0RTc0AyH05Wi2nJVMSdQGVXjldONy4ZVPtYpljQ8UWPgU9IqnehURcFci vrJOS1uOPNZiEV4jMOCJhk+ikcZmX5njP+ZNRQQw3/NlDCFjqAhx4tpf1mKF2hTfAYXb It0km0wJ3aVj9xXj2hchzRxe3Lv+SUOV8vxO3CzVwJUdjQIo8zZpswpCT/slLyrJQWJg CxLyfKZbh4E51pKaKRwyOfqN1q+3O6LoL4LEazsZhnVtHkGQ5bP9QRoy+0bI8hGrDYso bA7Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s11si2286417edh.506.2021.07.29.01.49.11; Thu, 29 Jul 2021 01:49:34 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235181AbhG2IrV (ORCPT + 99 others); Thu, 29 Jul 2021 04:47:21 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:47186 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S234878AbhG2IrU (ORCPT ); Thu, 29 Jul 2021 04:47:20 -0400 X-UUID: 1be3e42e7bef43cba7867ad3766c9ec9-20210729 X-UUID: 1be3e42e7bef43cba7867ad3766c9ec9-20210729 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1199891843; Thu, 29 Jul 2021 16:47:15 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 29 Jul 2021 16:47:14 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 29 Jul 2021 16:47:13 +0800 From: Zhiyong Tao To: , , , , CC: , , , , , , , , , , , Subject: [PATCH v2 1/1] serial: 8250_mtk: fix uart corruption issue when rx power off Date: Thu, 29 Jul 2021 16:46:40 +0800 Message-ID: <20210729084640.17613-2-zhiyong.tao@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210729084640.17613-1-zhiyong.tao@mediatek.com> References: <20210729084640.17613-1-zhiyong.tao@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix uart corruption issue when rx power off. Add spin lock in mtk8250_dma_rx_complete function in APDMA mode. when uart is used as a communication port with external device(GPS). when external device(GPS) power off, the power of rx pin is also from 1.8v to 0v. Even if there is not any data in rx. But uart rx pin can capture the data "0". If uart don't receive any data in specified cycle, uart will generates BI(Break interrupt) interrupt. If external device(GPS) power off, we found that BI interrupt appeared continuously and very frequently. When uart interrupt type is BI, uart IRQ handler(8250 framwork API:serial8250_handle_irq) will push data to tty buffer. mtk8250_dma_rx_complete is a task of mtk_uart_apdma_rx_handler. mtk8250_dma_rx_complete priority is lower than uart irq handler(serial8250_handle_irq). if we are in process of mtk8250_dma_rx_complete, uart appear BI interrupt:1)serial8250_handle_irq will priority execution.2)it may cause write tty buffer conflict in mtk8250_dma_rx_complete. So the spin lock protect the rx receive data process is not break. Signed-off-by: Zhiyong Tao --- drivers/tty/serial/8250/8250_mtk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c index f7d3023f860f..fb65dc601b23 100644 --- a/drivers/tty/serial/8250/8250_mtk.c +++ b/drivers/tty/serial/8250/8250_mtk.c @@ -93,10 +93,13 @@ static void mtk8250_dma_rx_complete(void *param) struct dma_tx_state state; int copied, total, cnt; unsigned char *ptr; + unsigned long flags; if (data->rx_status == DMA_RX_SHUTDOWN) return; + spin_lock_irqsave(&up->port.lock, flags); + dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); total = dma->rx_size - state.residue; cnt = total; @@ -120,6 +123,8 @@ static void mtk8250_dma_rx_complete(void *param) tty_flip_buffer_push(tty_port); mtk8250_rx_dma(up); + + spin_unlock_irqrestore(&up->port.lock, flags); } static void mtk8250_rx_dma(struct uart_8250_port *up) -- 2.18.0