Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4456573pxj; Tue, 22 Jun 2021 00:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8abdZnn9Eg71Sg1higRWJvnKHP34RSnX/0mEJ0yM9LkRqqimlhcotxQQVb2FI9mcSsUVp X-Received: by 2002:a05:6402:2789:: with SMTP id b9mr2964809ede.142.1624345783115; Tue, 22 Jun 2021 00:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624345783; cv=none; d=google.com; s=arc-20160816; b=P/GOqVQahIAgvlLBxENxszqzL+ktJ4AkhbhmPKUnRLLXRLaq3ia0dHqxmdIG7yorPn Cvdb3vlXIsi7CQ+niEGd94z1vJS6PIdvpoNpeKO6V9WafCybW9v7RncvH+FBG4Osrvpk Vt0SRPfh1URW+vAVyiroxbLP9e0ZheFLzBUvFLsVcu7/Ep/Y5LvyYZyTXcsEigRaIBY3 mOWgEcyFjjbsM0f+qeSDI+m5JYaytIbaRkQ09IrCeVTE2q+NsnLU9dxV4bkoqKekwiNC CDxv9S21pzWsG6aC7bMn120whTLHBPFp5iY09Sh+uDp61JGBiO2m4rDwUgooZWlca6s+ hyuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from; bh=lTXjEM62TZsdnqbafkcE1LO7W2CdxUF8uNFzRXMFweE=; b=0PSMLo/OAVOLb/Z5FX9uEwSWThfQvDqXJsbUQSWqYBuJxaVHGcippULpv6nU2dKzsr 80wHkBjnps5XhTRGza1ClC0DVfejNz3U4Pvz2PC68RTGnQJVQSs7d3sSeigy1OcxFUok CpyY16rzx4i69/EZ5numZ5+FQ6iUg6xwdduKPdI3+CuzpQ7qFZNsDUfsRkGGeaTiAHGV VPq6i4ErpPZNpV5B9k7obMInEiFZQG7+Y5Qs2feJ70U27njwcAFJkt8Zj1z49x4OebQc C1XYVdrobHeIO+ig/R55RhboX2SV5uf6xdZ0dndANZkGAlqR1rRETr/jt2YdvB+NMNAj cX7Q== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si13353578ejj.485.2021.06.22.00.09.19; Tue, 22 Jun 2021 00:09:43 -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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbhFVHIf (ORCPT + 99 others); Tue, 22 Jun 2021 03:08:35 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:41386 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbhFVHIf (ORCPT ); Tue, 22 Jun 2021 03:08:35 -0400 Received: from mail-wr1-f69.google.com ([209.85.221.69]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lvaUE-0002qS-6J for linux-kernel@vger.kernel.org; Tue, 22 Jun 2021 07:06:18 +0000 Received: by mail-wr1-f69.google.com with SMTP id l13-20020adfe9cd0000b0290119a0645c8fso9333441wrn.8 for ; Tue, 22 Jun 2021 00:06:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lTXjEM62TZsdnqbafkcE1LO7W2CdxUF8uNFzRXMFweE=; b=jm0bLtbS/777uCPaXuddFeWMyffUttR2szAy+DWSuZqnmqBJazukuxbfxks8PnmTKQ IiCEAtrKx7hI88tk59//+MvFZPcPKH0jFby2zozYUSPWSVKUXBVy4Du0XEu8nF41egTk wiQxRgQiUPrjzSemlFv1/wPOviZ0YkTCtaP9EM22QWYjJ3rgvU3ugs4U5v4HGAPkxyhw GkE5ptQZB5IxkTgJOTU4VxLYhYnYlq+iy3in6zLhWGjeIKGur+M7yx9BRBRaSTYsq1Lv Lh+ZzoCuHL0nvN9Q/OekqwjX9SMHqTMKKH7Y5+pv++UIAa9IUWg9Vyfkg/GGoM/KGdTZ 9Irw== X-Gm-Message-State: AOAM530e8NA5BcTOf92KOFpu+Hh7g2lKIfBA/Ny+37eXYprYoj60LBHI z7MPcJddUD10K/iG0Lujgk3ysGAJBnaSBIVO/ELJDYxeUuUX4hGidU7WZF5WJBdGplAyUkO15Fd 0DHJ/6C0QmIte2i82W0NtxoU3w1kIjvEr0QmSYuBuxw== X-Received: by 2002:a05:6000:2:: with SMTP id h2mr2790441wrx.347.1624345577934; Tue, 22 Jun 2021 00:06:17 -0700 (PDT) X-Received: by 2002:a05:6000:2:: with SMTP id h2mr2790422wrx.347.1624345577744; Tue, 22 Jun 2021 00:06:17 -0700 (PDT) Received: from [192.168.1.115] (xdsl-188-155-177-222.adslplus.ch. [188.155.177.222]) by smtp.gmail.com with ESMTPSA id 11sm1321777wmf.20.2021.06.22.00.06.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 00:06:17 -0700 (PDT) From: Krzysztof Kozlowski Subject: Re: [PATCH] serial: samsung: use dma_ops of DMA if attached To: M Tamseel Shams , kgene@kernel.org, gregkh@linuxfoundation.org, jslaby@suse.com Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, alim.akhtar@samsung.com, ajaykumar.rs@samsung.com References: <20210621044916.41564-1-m.shams@samsung.com> <8935a448-04b7-91ce-203a-9f0d7e377052@canonical.com> <004f01d766a0$567b9860$0372c920$@samsung.com> Message-ID: <4b2576c1-c986-a4d8-d6cf-661ca056ecee@canonical.com> Date: Tue, 22 Jun 2021 09:06:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <004f01d766a0$567b9860$0372c920$@samsung.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/06/2021 15:21, M Tamseel Shams wrote: > Hi, > >> >> Hi, >> >> Thanks for the patch. >> >> On 21/06/2021 06:49, Tamseel Shams wrote: >>> When DMA is used for TX and RX by serial driver, it should pass the >>> DMA device pointer to DMA API instead of UART device pointer. >> >> Hmmm, but why DMA device pointer should be used? >> >>> >>> This patch is necessary to fix the SMMU page faults which is observed >>> when a DMA(with SMMU enabled) is attached to UART for transfer. >>> >>> Signed-off-by: Tamseel Shams >>> Signed-off-by: Ajay Kumar >>> --- >>> drivers/tty/serial/samsung_tty.c | 60 >>> +++++++++++++++++++++++++------- >>> 1 file changed, 48 insertions(+), 12 deletions(-) >>> >>> diff --git a/drivers/tty/serial/samsung_tty.c >>> b/drivers/tty/serial/samsung_tty.c >>> index b923683e6a25..5bdc7dd2a5e2 100644 >>> --- a/drivers/tty/serial/samsung_tty.c >>> +++ b/drivers/tty/serial/samsung_tty.c >>> @@ -284,8 +284,13 @@ static void s3c24xx_serial_stop_tx(struct uart_port >> *port) >>> struct s3c24xx_uart_dma *dma = ourport->dma; >>> struct circ_buf *xmit = &port->state->xmit; >>> struct dma_tx_state state; >>> + struct device *dma_map_ops_dev = ourport->port.dev; >>> int count; >>> >>> + /* Pick dma_ops of DMA device if DMA device is attached */ >> >> You mention here and further comments "dma_ops". I don't see you changing >> the DMA ops, but the device. It's quite confusing. I think you meant a DMA >> device shall be passed to DMA API? >> > Yes, DMA device should be used for DMA API because only the DMA device is aware of > how the device connects to the memory. There might be an extra level of address translation > due to a SMMU attached to the DMA device. When serial device pointer device is used > for DMA API, the DMA API will have no clue of the SMMU attached to the DMA device. Thanks, this should be in commit msg. > >> Second question: you write that DMA devices should be used if DMA is attached >> and in the code you follow such pattern a lot: >> >>> + if (dma && dma->tx_chan) >>> + dma_map_ops_dev = dma->tx_chan->device->dev; >>> + >> >> Are you trying to say that if DMA is not attached, UART device should be used? If >> DMA is not attached, how are the DMA operations used then? >> > If DMA is not attached, this part of code related to dma_engine or DMA API do not > get called. There will not be any DMA operations at all. Now I get it. The "When" in your description followed by multiple comments "if DMA device is attached" confused me that you expect to use UART device for DMA operations if DMA is not attached... > >>> if (!ourport->tx_enabled) >>> return; >>> >>> @@ -298,7 +303,7 @@ static void s3c24xx_serial_stop_tx(struct uart_port >> *port) >>> dmaengine_pause(dma->tx_chan); >>> dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state); >>> dmaengine_terminate_all(dma->tx_chan); >>> - dma_sync_single_for_cpu(ourport->port.dev, >>> + dma_sync_single_for_cpu(dma_map_ops_dev, >>> dma->tx_transfer_addr, dma->tx_size, >> DMA_TO_DEVICE); >>> async_tx_ack(dma->tx_desc); >>> count = dma->tx_bytes_requested - state.residue; @@ -324,15 >> +329,19 >>> @@ static void s3c24xx_serial_tx_dma_complete(void *args) >>> struct circ_buf *xmit = &port->state->xmit; >>> struct s3c24xx_uart_dma *dma = ourport->dma; >>> struct dma_tx_state state; >>> + struct device *dma_map_ops_dev = ourport->port.dev; >>> unsigned long flags; >>> int count; >>> >>> + /* Pick dma_ops of DMA device if DMA device is attached */ >>> + if (dma && dma->tx_chan) >>> + dma_map_ops_dev = dma->tx_chan->device->dev; Example is this one - you use here "if" suggesting there is "else". So what is the else condition? There is none... >>> >>> dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state); >>> count = dma->tx_bytes_requested - state.residue; >>> async_tx_ack(dma->tx_desc); >>> >>> - dma_sync_single_for_cpu(ourport->port.dev, dma->tx_transfer_addr, >>> + dma_sync_single_for_cpu(dma_map_ops_dev, dma->tx_transfer_addr, >>> dma->tx_size, DMA_TO_DEVICE); >>> >>> spin_lock_irqsave(&port->lock, flags); @@ -408,7 +417,11 @@ static >>> int s3c24xx_serial_start_tx_dma(struct s3c24xx_uart_port *ourport, >>> struct uart_port *port = &ourport->port; >>> struct circ_buf *xmit = &port->state->xmit; >>> struct s3c24xx_uart_dma *dma = ourport->dma; >>> + struct device *dma_map_ops_dev = ourport->port.dev; >>> >>> + /* Pick dma_ops of DMA device if DMA device is attached */ >>> + if (dma && dma->tx_chan) >>> + dma_map_ops_dev = dma->tx_chan->device->dev; >>> >>> if (ourport->tx_mode != S3C24XX_TX_DMA) >>> enable_tx_dma(ourport); >>> @@ -416,7 +429,7 @@ static int s3c24xx_serial_start_tx_dma(struct >> s3c24xx_uart_port *ourport, >>> dma->tx_size = count & ~(dma_get_cache_alignment() - 1); >>> dma->tx_transfer_addr = dma->tx_addr + xmit->tail; >>> >>> - dma_sync_single_for_device(ourport->port.dev, dma- >>> tx_transfer_addr, >>> + dma_sync_single_for_device(dma_map_ops_dev, dma- >>> tx_transfer_addr, >>> dma->tx_size, DMA_TO_DEVICE); >>> >>> dma->tx_desc = dmaengine_prep_slave_single(dma->tx_chan, >>> @@ -483,12 +496,17 @@ static void s3c24xx_uart_copy_rx_to_tty(struct >> s3c24xx_uart_port *ourport, >>> struct tty_port *tty, int count) >>> { >>> struct s3c24xx_uart_dma *dma = ourport->dma; >>> + struct device *dma_map_ops_dev = ourport->port.dev; >>> int copied; >>> >>> + /* Pick dma_ops of DMA device if DMA device is attached */ >>> + if (dma && dma->rx_chan) >>> + dma_map_ops_dev = dma->rx_chan->device->dev; >>> + >>> if (!count) >>> return; >>> >>> - dma_sync_single_for_cpu(ourport->port.dev, dma->rx_addr, >>> + dma_sync_single_for_cpu(dma_map_ops_dev, dma->rx_addr, >>> dma->rx_size, DMA_FROM_DEVICE); >>> >>> ourport->port.icount.rx += count; >>> @@ -600,8 +618,13 @@ static void s3c24xx_serial_rx_dma_complete(void >>> *args) static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port >>> *ourport) { >>> struct s3c24xx_uart_dma *dma = ourport->dma; >>> + struct device *dma_map_ops_dev = ourport->port.dev; >>> >>> - dma_sync_single_for_device(ourport->port.dev, dma->rx_addr, >>> + /* Pick dma_ops of DMA device if DMA device is attached */ >>> + if (dma && dma->rx_chan) >>> + dma_map_ops_dev = dma->rx_chan->device->dev; >>> + >>> + dma_sync_single_for_device(dma_map_ops_dev, dma->rx_addr, >>> dma->rx_size, DMA_FROM_DEVICE); >>> >>> dma->rx_desc = dmaengine_prep_slave_single(dma->rx_chan, >>> @@ -983,6 +1006,7 @@ static int s3c24xx_serial_request_dma(struct >>> s3c24xx_uart_port *p) >> >> Offset of hunks looks here significantly different than mainline. The patch should >> be based and tested mainline tree. Which one did you choose as base? >> >> Using my email address not from get_maintainers.pl also suggests that you >> don't use anything recent as a base. >> > I used "master" branch of main linux-next tree as the base. > I will rebase on "tty-next" branch of TTY tree and post again. > > Thanks & Regards, > Tamseel Shams > Best regards, Krzysztof