From patchwork Fri Apr 5 06:08:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13618571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BECCCD1284 for ; Fri, 5 Apr 2024 06:09:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Fm1+27qk6iJ/EgDc8P7d/bmpIQ/pOhBlNACyDKL6jX0=; b=ENV1pcdv1XWZRJ rUdUs5WekxXIjXd/QQxByEetOf1KgjbseY1W0sGWx0n4D0ZnbV8nr7uQvDVYulQEpyhA7qUcNjkgd yZ+SOGqqsV+nNz+dUJe9aEJM0ag5VGrH8Xq4LYd7dcn6mVQuZYTDXsUhhCjFwu6+Tsn6mZZ2FdKch kZxZYoL/OtI3Us+HqwnNFkoYZ0OIpNwzIg/GDXWVUsfdPSE9cGOCLlEkkvDsY1MGvTCWpLLFzR2uD aVGAZT5K7cEY/R4LhjASXfeVj1Mfmka8p0L+WmIAv9N21gUBayZ/1S26lAYPerwl/eW/WXWJUpDbf IoH1kmK5CHmBYmy52nvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsclI-00000005Oix-0wOU; Fri, 05 Apr 2024 06:09:16 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsclF-00000005Ohr-1k00 for linux-arm-kernel@lists.infradead.org; Fri, 05 Apr 2024 06:09:15 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D264761448; Fri, 5 Apr 2024 06:09:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABEA9C43601; Fri, 5 Apr 2024 06:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712297352; bh=KVsipsYsYMv/yG54CaStidUVpSv0BOqzJ7Q6MUmF5/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ekMXKAldDk5A0/hhar1jOHHOX2Q5+uattPl9QYCAt6X9v1wnsFeNGA1JosAZ/es0X Tiv9Q7/ymF1zFeZK9G2HdhWRr/TJV+uklFxWM84Wfg7IhH7YNmqv6izFsp7pLjCcaS Rs2fYi35XmLWrR1l31E9Q+PVEjdJxhqzlrYUjIhJywMzefdHXaGf188SisQHImiei7 1amEhnFN4i+aa5BPaH5qv4CFUSnoJtveexr2aIp1C/ugP6OBhcgDT8WjJLJcBNVQRM 36p6EhJNL1HkZOoKC5fkGjeH4CVtZY3jbuW3dHjT+F4rCvlZ3j8F4+LyXnd088JGIW eOUjnglwhNl3A== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Subject: [PATCH 13/15] tty: atmel_serial: use single DMA mapping for TX Date: Fri, 5 Apr 2024 08:08:24 +0200 Message-ID: <20240405060826.2521-14-jirislaby@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405060826.2521-1-jirislaby@kernel.org> References: <20240405060826.2521-1-jirislaby@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_230913_571912_B0105D69 X-CRM114-Status: GOOD ( 13.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Richard Genoud , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Claudiu Beznea , "Jiri Slaby \(SUSE\)" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org dma_map_single() provides much easier interface for simple mappings as used for TX in atmel_serial. So switch to that, removing all the s-g unnecessary handling. Note that it is not easy (maybe impossible) to use kfifo_dma_* API for atmel's serial purposes. It handles DMA very specially. Signed-off-by: Jiri Slaby (SUSE) Cc: Richard Genoud Cc: Nicolas Ferre Cc: Alexandre Belloni Cc: Claudiu Beznea Cc: linux-arm-kernel@lists.infradead.org --- drivers/tty/serial/atmel_serial.c | 35 +++++++++++++------------------ 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 5bb5e4303754..69ec80ffc97b 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -132,7 +132,7 @@ struct atmel_uart_port { struct dma_async_tx_descriptor *desc_rx; dma_cookie_t cookie_tx; dma_cookie_t cookie_rx; - struct scatterlist sg_tx; + dma_addr_t tx_phys; struct scatterlist sg_rx; struct tasklet_struct tasklet_rx; struct tasklet_struct tasklet_tx; @@ -904,8 +904,8 @@ static void atmel_release_tx_dma(struct uart_port *port) if (chan) { dmaengine_terminate_all(chan); dma_release_channel(chan); - dma_unmap_sg(port->dev, &atmel_port->sg_tx, 1, - DMA_TO_DEVICE); + dma_unmap_single(port->dev, atmel_port->tx_phys, + UART_XMIT_SIZE, DMA_TO_DEVICE); } atmel_port->desc_tx = NULL; @@ -922,7 +922,7 @@ static void atmel_tx_dma(struct uart_port *port) struct tty_port *tport = &port->state->port; struct dma_chan *chan = atmel_port->chan_tx; struct dma_async_tx_descriptor *desc; - struct scatterlist sgl[2], *sg, *sg_tx = &atmel_port->sg_tx; + struct scatterlist sgl[2], *sg; unsigned int tx_len, tail, part1_len, part2_len, sg_len; dma_addr_t phys_addr; @@ -955,7 +955,7 @@ static void atmel_tx_dma(struct uart_port *port) sg_init_table(sgl, 2); sg_len = 0; - phys_addr = sg_dma_address(sg_tx) + tail; + phys_addr = atmel_port->tx_phys + tail; if (part1_len) { sg = &sgl[sg_len++]; sg_dma_address(sg) = phys_addr; @@ -987,7 +987,8 @@ static void atmel_tx_dma(struct uart_port *port) return; } - dma_sync_sg_for_device(port->dev, sg_tx, 1, DMA_TO_DEVICE); + dma_sync_single_for_device(port->dev, atmel_port->tx_phys, + UART_XMIT_SIZE, DMA_TO_DEVICE); atmel_port->desc_tx = desc; desc->callback = atmel_complete_tx_dma; @@ -1014,7 +1015,7 @@ static int atmel_prepare_tx_dma(struct uart_port *port) dma_cap_mask_t mask; struct dma_slave_config config; struct dma_chan *chan; - int ret, nent; + int ret; dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); @@ -1029,26 +1030,18 @@ static int atmel_prepare_tx_dma(struct uart_port *port) dma_chan_name(atmel_port->chan_tx)); spin_lock_init(&atmel_port->lock_tx); - sg_init_table(&atmel_port->sg_tx, 1); /* UART circular tx buffer is an aligned page. */ BUG_ON(!PAGE_ALIGNED(tport->xmit_buf)); - sg_set_page(&atmel_port->sg_tx, - virt_to_page(tport->xmit_buf), - UART_XMIT_SIZE, - offset_in_page(tport->xmit_buf)); - nent = dma_map_sg(port->dev, - &atmel_port->sg_tx, - 1, - DMA_TO_DEVICE); + atmel_port->tx_phys = dma_map_single(port->dev, tport->xmit_buf, + UART_XMIT_SIZE, DMA_TO_DEVICE); - if (!nent) { + if (dma_mapping_error(port->dev, atmel_port->tx_phys)) { dev_dbg(port->dev, "need to release resource of dma\n"); goto chan_err; } else { - dev_dbg(port->dev, "%s: mapped %d@%p to %pad\n", __func__, - sg_dma_len(&atmel_port->sg_tx), - tport->xmit_buf, - &sg_dma_address(&atmel_port->sg_tx)); + dev_dbg(port->dev, "%s: mapped %lu@%p to %pad\n", __func__, + UART_XMIT_SIZE, tport->xmit_buf, + &atmel_port->tx_phys); } /* Configure the slave DMA */ From patchwork Fri Apr 5 06:08:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13618569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14A7ACD11C2 for ; Fri, 5 Apr 2024 06:09:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sBjhEiInXqHgEyqH7c9aOVYlIYtte1O1EpjlJo0QnNE=; b=POaciL2O+q0+GV HAFHcd+kPBn2K1L4mBw9tzWHc1SeTK5cPGNNYZ8H1c/YjLjJRAC3tMrbO/UxJCNWmBvIKX95Jt2Z5 E1F1dHW4RNF7X5YSeSS5eY9mmBES0KP7CftFrvekzjBJcsHArdyWM8c3ue/bf6pX2U+UHk8VBtk5p cYZl73YrXr609H+ILunHadm2OVGHDxHSGAd54y6r9yUPYbsaXXTOYfWFY+tCw9dIbS3MskFKinQHY 99xRA70foCfkxqc5pw1fLfe74gp4rm48Gm3YbqlYcfL1GXEdZQCm2bRWuqLtP8UVBkwpd6w36YFKF 9qJLzwem1PW+JfPxnKVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsclM-00000005OlE-0EPz; Fri, 05 Apr 2024 06:09:20 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsclJ-00000005Oiw-1ykY for linux-arm-kernel@lists.infradead.org; Fri, 05 Apr 2024 06:09:19 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 72B74CE360E; Fri, 5 Apr 2024 06:09:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 202EDC433F1; Fri, 5 Apr 2024 06:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712297355; bh=5+bhGaEEsgnXQkvvlI11yrFLziNuirM9WUE4o2kU49s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SR5IkoVWCThIz/IBG4dzQ2NMBOZgCa6oO3mHsRDzKtpnJI73i/leg0yhmXB/ELmoo k4tJVUb5AYY5fzBvjdbtoGwC7z571VIunje+PC3+0xHmQUzw1S6C2e1HyoVJpEGRR/ GNdgND2effh9za7S8E1C7Ho5IKLUTJyHiRL8kaa9hlKzm05fpge3Gyi4OWord4zqVo hF7fwsJ+JIfygO36D2ObOsvpI8Nb8t5wTYEyhZIsd+9e++sd170qbM9glC/WnukVk6 NvpxDyXWqS5ONegWMu11GvD322p2uJ6xULNYpFWk9xYyaDnPE17xrmxCMyAdOrAPeC 9+F2fxqtatrpg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Subject: [PATCH 14/15] tty: atmel_serial: define macro for RX size Date: Fri, 5 Apr 2024 08:08:25 +0200 Message-ID: <20240405060826.2521-15-jirislaby@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405060826.2521-1-jirislaby@kernel.org> References: <20240405060826.2521-1-jirislaby@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_230917_722826_C09A2790 X-CRM114-Status: GOOD ( 13.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Richard Genoud , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Claudiu Beznea , "Jiri Slaby \(SUSE\)" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It is repeated in the code and there is also a big warning by ATMEL_SERIAL_RINGSIZE. So define ATMEL_SERIAL_RX_SIZE and use it appropriatelly. The macro uses array_size() and kmalloc_array() is switched to kmalloc(). Signed-off-by: Jiri Slaby (SUSE) Cc: Richard Genoud Cc: Nicolas Ferre Cc: Alexandre Belloni Cc: Claudiu Beznea Cc: linux-arm-kernel@lists.infradead.org --- drivers/tty/serial/atmel_serial.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 69ec80ffc97b..5cde5077c429 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -96,7 +96,9 @@ struct atmel_uart_char { * can contain up to 1024 characters in PIO mode and up to 4096 characters in * DMA mode. */ -#define ATMEL_SERIAL_RINGSIZE 1024 +#define ATMEL_SERIAL_RINGSIZE 1024 +#define ATMEL_SERIAL_RX_SIZE array_size(sizeof(struct atmel_uart_char), \ + ATMEL_SERIAL_RINGSIZE) /* * at91: 6 USARTs and one DBGU port (SAM9260) @@ -1208,7 +1210,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port) BUG_ON(!PAGE_ALIGNED(ring->buf)); sg_set_page(&atmel_port->sg_rx, virt_to_page(ring->buf), - sizeof(struct atmel_uart_char) * ATMEL_SERIAL_RINGSIZE, + ATMEL_SERIAL_RX_SIZE, offset_in_page(ring->buf)); nent = dma_map_sg(port->dev, &atmel_port->sg_rx, @@ -2947,9 +2949,7 @@ static int atmel_serial_probe(struct platform_device *pdev) if (!atmel_use_pdc_rx(&atmel_port->uart)) { ret = -ENOMEM; - data = kmalloc_array(ATMEL_SERIAL_RINGSIZE, - sizeof(struct atmel_uart_char), - GFP_KERNEL); + data = kmalloc(ATMEL_SERIAL_RX_SIZE, GFP_KERNEL); if (!data) goto err_clk_disable_unprepare; atmel_port->rx_ring.buf = data; From patchwork Fri Apr 5 06:08:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13618570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71596CD1296 for ; Fri, 5 Apr 2024 06:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=K0uTq6ful/Rja0rY1rF9ftZZBqkVPVsOq0FQn50gRTs=; b=AwAN9fWqv2UV25 u0LZuo+rNktgLaDykBxfd2PxSx4Om6+osgRN5cuByoAUlSvcoNf42jZZVdVwsf8uodChV9zT6pN5j IwJSKgosdBOhwySmNfwDO8n6h6c7hUTlHKSshdMFqv7kVefUQdUkwSAuI2AByGP4T8K7AiRgzcXUE BT0fkiCbHoYWHaOox6bhKFZvSTgs9sot+yd85g1KnRGoufbqfYHlH6X2sOlPw/GeTWv+zufLr1HQg 84QNqnKH6piqBwvB2hsvyN9e9QZoDhPZrydL+DG3TXPHKFVrLe3NtnedLtruA3WFP325KPjKEIx3b wCos6/jM+UrdLvOPvexw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsclQ-00000005Onk-0a2Z; Fri, 05 Apr 2024 06:09:24 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsclK-00000005Ojt-1fVi for linux-arm-kernel@lists.infradead.org; Fri, 05 Apr 2024 06:09:19 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AF81661799; Fri, 5 Apr 2024 06:09:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89087C43399; Fri, 5 Apr 2024 06:09:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712297357; bh=/FjnStB/yZtMO26TOxQ+YsIrQb3A2biwdW2z1LAyxHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ptB122ndmL1qOaMN542Suz/jgypKSfUMNgqcdTXrsSn8apL2DaRjXXfT+dKuf0e8U SknJ8928wFdXrmjaj2C3cPBnAxiUTRaNNlQPfKysbWnfkZ7D6hnXJOr32nok4IO9it DmHPD8j2GOHHP4ApHNCKCL4Pvw6zQzn7BXR2gCrlfcXKGTSuzANT09FYhDS/fEglOc Qn0+77Zr8CZo0rvKjRvNOlB1k5QMmpp8z6PWXkqwLHMyE2KIdaen7UihL634guJEqU 3UIoABuJy0/Ov20Q9qUEqUmVauGtkJkSnlYiS9WKGEeMVspbtd9uNhewpMEOWpPqnc 81aQ4aUasR7NA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Subject: [PATCH 15/15] tty: atmel_serial: use single DMA mapping for RX Date: Fri, 5 Apr 2024 08:08:26 +0200 Message-ID: <20240405060826.2521-16-jirislaby@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405060826.2521-1-jirislaby@kernel.org> References: <20240405060826.2521-1-jirislaby@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_230918_579823_48CD1125 X-CRM114-Status: GOOD ( 16.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Richard Genoud , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Claudiu Beznea , "Jiri Slaby \(SUSE\)" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org dma_map_single() provides much easier interface for simple mappings as used for RX in atmel_serial. So switch to that, removing all the s-g unnecessary handling. Signed-off-by: Jiri Slaby (SUSE) Cc: Richard Genoud Cc: Nicolas Ferre Cc: Alexandre Belloni Cc: Claudiu Beznea Cc: linux-arm-kernel@lists.infradead.org --- drivers/tty/serial/atmel_serial.c | 56 ++++++++++++------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 5cde5077c429..0a90964d6d10 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -135,7 +135,7 @@ struct atmel_uart_port { dma_cookie_t cookie_tx; dma_cookie_t cookie_rx; dma_addr_t tx_phys; - struct scatterlist sg_rx; + dma_addr_t rx_phys; struct tasklet_struct tasklet_rx; struct tasklet_struct tasklet_tx; atomic_t tasklet_shutdown; @@ -1088,8 +1088,8 @@ static void atmel_release_rx_dma(struct uart_port *port) if (chan) { dmaengine_terminate_all(chan); dma_release_channel(chan); - dma_unmap_sg(port->dev, &atmel_port->sg_rx, 1, - DMA_FROM_DEVICE); + dma_unmap_single(port->dev, atmel_port->rx_phys, + ATMEL_SERIAL_RX_SIZE, DMA_FROM_DEVICE); } atmel_port->desc_rx = NULL; @@ -1122,10 +1122,8 @@ static void atmel_rx_from_dma(struct uart_port *port) } /* CPU claims ownership of RX DMA buffer */ - dma_sync_sg_for_cpu(port->dev, - &atmel_port->sg_rx, - 1, - DMA_FROM_DEVICE); + dma_sync_single_for_cpu(port->dev, atmel_port->rx_phys, + ATMEL_SERIAL_RX_SIZE, DMA_FROM_DEVICE); /* * ring->head points to the end of data already written by the DMA. @@ -1134,8 +1132,8 @@ static void atmel_rx_from_dma(struct uart_port *port) * The current transfer size should not be larger than the dma buffer * length. */ - ring->head = sg_dma_len(&atmel_port->sg_rx) - state.residue; - BUG_ON(ring->head > sg_dma_len(&atmel_port->sg_rx)); + ring->head = ATMEL_SERIAL_RX_SIZE - state.residue; + BUG_ON(ring->head > ATMEL_SERIAL_RX_SIZE); /* * At this point ring->head may point to the first byte right after the * last byte of the dma buffer: @@ -1149,7 +1147,7 @@ static void atmel_rx_from_dma(struct uart_port *port) * tail to the end of the buffer then reset tail. */ if (ring->head < ring->tail) { - count = sg_dma_len(&atmel_port->sg_rx) - ring->tail; + count = ATMEL_SERIAL_RX_SIZE - ring->tail; tty_insert_flip_string(tport, ring->buf + ring->tail, count); ring->tail = 0; @@ -1162,17 +1160,15 @@ static void atmel_rx_from_dma(struct uart_port *port) tty_insert_flip_string(tport, ring->buf + ring->tail, count); /* Wrap ring->head if needed */ - if (ring->head >= sg_dma_len(&atmel_port->sg_rx)) + if (ring->head >= ATMEL_SERIAL_RX_SIZE) ring->head = 0; ring->tail = ring->head; port->icount.rx += count; } /* USART retreives ownership of RX DMA buffer */ - dma_sync_sg_for_device(port->dev, - &atmel_port->sg_rx, - 1, - DMA_FROM_DEVICE); + dma_sync_single_for_device(port->dev, atmel_port->rx_phys, + ATMEL_SERIAL_RX_SIZE, DMA_FROM_DEVICE); tty_flip_buffer_push(tport); @@ -1188,7 +1184,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port) struct dma_slave_config config; struct circ_buf *ring; struct dma_chan *chan; - int ret, nent; + int ret; ring = &atmel_port->rx_ring; @@ -1205,26 +1201,18 @@ static int atmel_prepare_rx_dma(struct uart_port *port) dma_chan_name(atmel_port->chan_rx)); spin_lock_init(&atmel_port->lock_rx); - sg_init_table(&atmel_port->sg_rx, 1); /* UART circular rx buffer is an aligned page. */ BUG_ON(!PAGE_ALIGNED(ring->buf)); - sg_set_page(&atmel_port->sg_rx, - virt_to_page(ring->buf), - ATMEL_SERIAL_RX_SIZE, - offset_in_page(ring->buf)); - nent = dma_map_sg(port->dev, - &atmel_port->sg_rx, - 1, - DMA_FROM_DEVICE); - - if (!nent) { + atmel_port->rx_phys = dma_map_single(port->dev, ring->buf, + ATMEL_SERIAL_RX_SIZE, + DMA_FROM_DEVICE); + + if (dma_mapping_error(port->dev, atmel_port->rx_phys)) { dev_dbg(port->dev, "need to release resource of dma\n"); goto chan_err; } else { - dev_dbg(port->dev, "%s: mapped %d@%p to %pad\n", __func__, - sg_dma_len(&atmel_port->sg_rx), - ring->buf, - &sg_dma_address(&atmel_port->sg_rx)); + dev_dbg(port->dev, "%s: mapped %zu@%p to %pad\n", __func__, + ATMEL_SERIAL_RX_SIZE, ring->buf, &atmel_port->rx_phys); } /* Configure the slave DMA */ @@ -1245,9 +1233,9 @@ static int atmel_prepare_rx_dma(struct uart_port *port) * each one is half ring buffer size */ desc = dmaengine_prep_dma_cyclic(atmel_port->chan_rx, - sg_dma_address(&atmel_port->sg_rx), - sg_dma_len(&atmel_port->sg_rx), - sg_dma_len(&atmel_port->sg_rx)/2, + atmel_port->rx_phys, + ATMEL_SERIAL_RX_SIZE, + ATMEL_SERIAL_RX_SIZE / 2, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); if (!desc) {