From patchwork Tue Apr 23 12:08:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13639935 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E43B080028 for ; Tue, 23 Apr 2024 12:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713874112; cv=none; b=W+ToOCpsVkxp8wUjDa3e4FTMOS8zX+qmEKLxmnugp5CLXI7599tDVqyH2KYN/TWIPdNQYdJRFlrgvwS8uwEvHvk2fwikBAQd1X88nGTOLcpENTT7LdASi3JqN6GUBy/SV4OqendzEm/nAfZyAji/sp4Ms7gx6yjeGIWewyUP2kI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713874112; c=relaxed/simple; bh=vj4jIeVW+7PoiExoJwbgChfdoJtJx7c2amXeCx4ELO4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type: References; b=ifhU4Kn2VgsHPQ+0culibYTG7dOgy9Hyi0aiSHpCne+c0D8WMM1It8ZVniNohz8zQodM2Yh4X4Kt8/unTHFVpeNqmx42P4bUPZb44br+kIALJC7jkGExq6FXTA8ImtLp/89jUqT2z3FgNmdRtOloysUvSkFCIB+Sf/dcH1jcP2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=W7gPOmEF; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="W7gPOmEF" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240423120821euoutp011962d7deddb5ae70b8d8f06811d4ad83~I52o5cP6Z2629626296euoutp01_ for ; Tue, 23 Apr 2024 12:08:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240423120821euoutp011962d7deddb5ae70b8d8f06811d4ad83~I52o5cP6Z2629626296euoutp01_ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1713874101; bh=KaZelo7BQ9JGVPOzVxxV1W4fwjbZsq3J/OFVmVnpm9k=; h=From:To:Cc:Subject:Date:References:From; b=W7gPOmEF2kK/qHHg9TIXeVed0D9Hro82YaULrfQAW1stQiAgSR+PJyPPhfE5iFObJ xT5H3AUGhJmAJBxBte3MNjzUSlXUg5wD22PlaVpqlK4XXLPb8p2sKY6OMtDnOsb5t5 1sNTPIo6SjFH46IAPwHdz3NPZzn4aKYRx0yoZtp4= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240423120821eucas1p1410aa3756655cdcced13f4c8659c1176~I52om1mvW0783007830eucas1p1H; Tue, 23 Apr 2024 12:08:21 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 2F.55.09875.5B4A7266; Tue, 23 Apr 2024 13:08:21 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240423120821eucas1p2e8eb7aa059e00ee2bc6272cda24d1457~I52oW-4Ld2518225182eucas1p2j; Tue, 23 Apr 2024 12:08:21 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240423120821eusmtrp2850376a33c96a629508291b343b75ea9~I52oWhC1b2998329983eusmtrp2C; Tue, 23 Apr 2024 12:08:21 +0000 (GMT) X-AuditID: cbfec7f4-11bff70000002693-ee-6627a4b55f32 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 50.48.08810.4B4A7266; Tue, 23 Apr 2024 13:08:20 +0100 (BST) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240423120820eusmtip1af1830231cd9012b1b728fa02817a4a7~I52n8ANzn0744407444eusmtip1a; Tue, 23 Apr 2024 12:08:20 +0000 (GMT) From: Marek Szyprowski To: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH] serial: msm: Unify TX and RX DMA paths Date: Tue, 23 Apr 2024 14:08:08 +0200 Message-Id: <20240423120809.2678030-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkleLIzCtJLcpLzFFi42LZduznOd2tS9TTDNas4LdoXryezeLdXBmL ifvPsltc3jWHzWLtkbvsDqwem1Z1snnsn7uG3aNvyypGj8+b5AJYorhsUlJzMstSi/TtErgy Jux+x1ww3bpiR+NK9gbGtQZdjJwcEgImEpOvLmUHsYUEVjBKnN/A0sXIBWR/YZSY8PwgM4Tz mVFi3fMrQA4HWMeJWeEQ8eWMElfbPiB0LHz6mAVkFJuAoUTX2y42EFtEwF7izrybTCBFzAKt jBIvNp5gBEkIC5hLrGx7xgYylUVAVeLFyTCQMC9Qfc/0S6wQ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z1nIBGIzC7QzSlyY4gRiCwuYS6xse8YGsoxFQFXixckwkDCvgL1E z/RLUPPlJfYfPMsMEReUODnzCQvEGHmJ5q2zmScw8s1CkpqFJLWAkWkVo0hqaXFuem6xoV5x Ym5xaV66XnJ+7iZGYABvO/Zz8w7Gea8+6h1iZOJgPMQowcGsJML7649KmhBvSmJlVWpRfnxR aU5q8SFGU6DzJjJLiSbnA2MoryTe0MzA1NDEzNLA1NLMWEmc17OgI1FIID2xJDU7NbUgtQim j4mDU6qB6YReHLPVLvlZOYx/ThRFbODdsH9LdsluFa33xx58r2Hc+7L17Zx5G+3fifgycMY4 sIjzPA9z3H+28qfcarUL3l7fjNca+678VTrnYOuv3BPM0nUHTt9MUtaX05qz6aLo61v64te2 1kV3ZwiH7Ht9cVlGlknP5nltl/gCOlu/LJzJdu+U9oRKO9l3ZjMXGVlzPpdY1HD0wt77177x 7FuUonOPldlZo/VA6ULeWy2G73YuEJi56+CxW8F6/Ncl/G/Pd/CPe214bSFjQMjL/Zl//wm9 7P3kcKiPe/u3/i6nFYL3J8px3mI9K7HnSWvGVTnnmkPrp8/uN39b9KvaO0b3GL/bhVmq8kzX jATnb8v5I6PEUpyRaKjFXFScCAAtcphT6QIAAA== X-CMS-MailID: 20240423120821eucas1p2e8eb7aa059e00ee2bc6272cda24d1457 X-Msg-Generator: CA X-RootMTR: 20240423120821eucas1p2e8eb7aa059e00ee2bc6272cda24d1457 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240423120821eucas1p2e8eb7aa059e00ee2bc6272cda24d1457 References: Use scatterlist-based API also for RX mode to unify TX and RX DMA paths as well as simplify the whole driver code a bit. Signed-off-by: Marek Szyprowski --- drivers/tty/serial/msm_serial.c | 86 +++++++++++++-------------------- 1 file changed, 34 insertions(+), 52 deletions(-) diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c index 0a9c5219df88..d5e00e613f73 100644 --- a/drivers/tty/serial/msm_serial.c +++ b/drivers/tty/serial/msm_serial.c @@ -161,14 +161,8 @@ enum { struct msm_dma { struct dma_chan *chan; enum dma_data_direction dir; - union { - struct { - dma_addr_t phys; - unsigned char *virt; - unsigned int count; - } rx; - struct scatterlist tx_sg; - }; + unsigned char *virt; + struct scatterlist sg; dma_cookie_t cookie; u32 enable_bit; struct dma_async_tx_descriptor *desc; @@ -254,13 +248,7 @@ static void msm_stop_dma(struct uart_port *port, struct msm_dma *dma) unsigned int mapped; u32 val; - if (dma->dir == DMA_TO_DEVICE) { - mapped = sg_dma_len(&dma->tx_sg); - } else { - mapped = dma->rx.count; - dma->rx.count = 0; - } - + mapped = sg_dma_len(&dma->sg); dmaengine_terminate_all(dma->chan); /* @@ -275,11 +263,8 @@ static void msm_stop_dma(struct uart_port *port, struct msm_dma *dma) msm_write(port, val, UARTDM_DMEN); if (mapped) { - if (dma->dir == DMA_TO_DEVICE) { - dma_unmap_sg(dev, &dma->tx_sg, 1, dma->dir); - sg_init_table(&dma->tx_sg, 1); - } else - dma_unmap_single(dev, dma->rx.phys, mapped, dma->dir); + dma_unmap_sg(dev, &dma->sg, 1, dma->dir); + sg_init_table(&dma->sg, 1); } } @@ -299,7 +284,7 @@ static void msm_release_dma(struct msm_port *msm_port) if (dma->chan) { msm_stop_dma(&msm_port->uart, dma); dma_release_channel(dma->chan); - kfree(dma->rx.virt); + kfree(dma->virt); } memset(dma, 0, sizeof(*dma)); @@ -371,8 +356,8 @@ static void msm_request_rx_dma(struct msm_port *msm_port, resource_size_t base) of_property_read_u32(dev->of_node, "qcom,rx-crci", &crci); - dma->rx.virt = kzalloc(UARTDM_RX_SIZE, GFP_KERNEL); - if (!dma->rx.virt) + dma->virt = kzalloc(UARTDM_RX_SIZE, GFP_KERNEL); + if (!dma->virt) goto rel_rx; memset(&conf, 0, sizeof(conf)); @@ -399,7 +384,7 @@ static void msm_request_rx_dma(struct msm_port *msm_port, resource_size_t base) return; err: - kfree(dma->rx.virt); + kfree(dma->virt); rel_rx: dma_release_channel(dma->chan); no_rx: @@ -434,7 +419,7 @@ static void msm_start_tx(struct uart_port *port) struct msm_dma *dma = &msm_port->tx_dma; /* Already started in DMA mode */ - if (sg_dma_len(&dma->tx_sg)) + if (sg_dma_len(&dma->sg)) return; msm_port->imr |= MSM_UART_IMR_TXLEV; @@ -462,12 +447,12 @@ static void msm_complete_tx_dma(void *args) uart_port_lock_irqsave(port, &flags); /* Already stopped */ - if (!sg_dma_len(&dma->tx_sg)) + if (!sg_dma_len(&dma->sg)) goto done; dmaengine_tx_status(dma->chan, dma->cookie, &state); - dma_unmap_sg(port->dev, &dma->tx_sg, 1, dma->dir); + dma_unmap_sg(port->dev, &dma->sg, 1, dma->dir); val = msm_read(port, UARTDM_DMEN); val &= ~dma->enable_bit; @@ -478,9 +463,9 @@ static void msm_complete_tx_dma(void *args) msm_write(port, MSM_UART_CR_TX_ENABLE, MSM_UART_CR); } - count = sg_dma_len(&dma->tx_sg) - state.residue; + count = sg_dma_len(&dma->sg) - state.residue; uart_xmit_advance(port, count); - sg_init_table(&dma->tx_sg, 1); + sg_init_table(&dma->sg, 1); /* Restore "Tx FIFO below watermark" interrupt */ msm_port->imr |= MSM_UART_IMR_TXLEV; @@ -503,16 +488,16 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count) int ret; u32 val; - sg_init_table(&dma->tx_sg, 1); - kfifo_dma_out_prepare(&tport->xmit_fifo, &dma->tx_sg, 1, count); + sg_init_table(&dma->sg, 1); + kfifo_dma_out_prepare(&tport->xmit_fifo, &dma->sg, 1, count); - mapped = dma_map_sg(port->dev, &dma->tx_sg, 1, dma->dir); + mapped = dma_map_sg(port->dev, &dma->sg, 1, dma->dir); if (!mapped) { ret = -EIO; goto zero_sg; } - dma->desc = dmaengine_prep_slave_sg(dma->chan, &dma->tx_sg, 1, + dma->desc = dmaengine_prep_slave_sg(dma->chan, &dma->sg, 1, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_PREP_FENCE); @@ -550,9 +535,9 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count) dma_async_issue_pending(dma->chan); return 0; unmap: - dma_unmap_sg(port->dev, &dma->tx_sg, 1, dma->dir); + dma_unmap_sg(port->dev, &dma->sg, 1, dma->dir); zero_sg: - sg_init_table(&dma->tx_sg, 1); + sg_init_table(&dma->sg, 1); return ret; } @@ -569,7 +554,7 @@ static void msm_complete_rx_dma(void *args) uart_port_lock_irqsave(port, &flags); /* Already stopped */ - if (!dma->rx.count) + if (!sg_dma_len(&dma->sg)) goto done; val = msm_read(port, UARTDM_DMEN); @@ -586,14 +571,13 @@ static void msm_complete_rx_dma(void *args) port->icount.rx += count; - dma->rx.count = 0; - - dma_unmap_single(port->dev, dma->rx.phys, UARTDM_RX_SIZE, dma->dir); + dma_unmap_sg(port->dev, &dma->sg, 1, dma->dir); + sg_init_table(&dma->sg, 1); for (i = 0; i < count; i++) { char flag = TTY_NORMAL; - if (msm_port->break_detected && dma->rx.virt[i] == 0) { + if (msm_port->break_detected && dma->virt[i] == 0) { port->icount.brk++; flag = TTY_BREAK; msm_port->break_detected = false; @@ -604,9 +588,9 @@ static void msm_complete_rx_dma(void *args) if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK)) flag = TTY_NORMAL; - sysrq = uart_prepare_sysrq_char(port, dma->rx.virt[i]); + sysrq = uart_prepare_sysrq_char(port, dma->virt[i]); if (!sysrq) - tty_insert_flip_char(tport, dma->rx.virt[i], flag); + tty_insert_flip_char(tport, dma->virt[i], flag); } msm_start_rx_dma(msm_port); @@ -630,14 +614,13 @@ static void msm_start_rx_dma(struct msm_port *msm_port) if (!dma->chan) return; - dma->rx.phys = dma_map_single(uart->dev, dma->rx.virt, - UARTDM_RX_SIZE, dma->dir); - ret = dma_mapping_error(uart->dev, dma->rx.phys); - if (ret) + sg_init_one(&dma->sg, dma->virt, UARTDM_RX_SIZE); + ret = dma_map_sg(uart->dev, &dma->sg, 1, dma->dir); + if (!ret) goto sw_mode; - dma->desc = dmaengine_prep_slave_single(dma->chan, dma->rx.phys, - UARTDM_RX_SIZE, DMA_DEV_TO_MEM, + dma->desc = dmaengine_prep_slave_sg(dma->chan, &dma->sg, 1, + DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); if (!dma->desc) goto unmap; @@ -664,8 +647,6 @@ static void msm_start_rx_dma(struct msm_port *msm_port) msm_write(uart, msm_port->imr, MSM_UART_IMR); - dma->rx.count = UARTDM_RX_SIZE; - dma_async_issue_pending(dma->chan); msm_write(uart, MSM_UART_CR_CMD_RESET_STALE_INT, MSM_UART_CR); @@ -684,7 +665,8 @@ static void msm_start_rx_dma(struct msm_port *msm_port) return; unmap: - dma_unmap_single(uart->dev, dma->rx.phys, UARTDM_RX_SIZE, dma->dir); + dma_unmap_sg(uart->dev, &dma->sg, 1, dma->dir); + sg_init_table(&dma->sg, 1); sw_mode: /* @@ -967,7 +949,7 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) } if (misr & (MSM_UART_IMR_RXLEV | MSM_UART_IMR_RXSTALE)) { - if (dma->rx.count) { + if (sg_dma_len(&dma->sg)) { val = MSM_UART_CR_CMD_STALE_EVENT_DISABLE; msm_write(port, val, MSM_UART_CR); val = MSM_UART_CR_CMD_RESET_STALE_INT;