Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp54105ybm; Tue, 21 May 2019 22:26:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAZF0f2qHBDA4c1dFOm0llmndIQVpUrmPHq4Dps0cD40RfsobA8C1GpWk2K6wQtyTSSNsD X-Received: by 2002:a65:6450:: with SMTP id s16mr889530pgv.414.1558502813769; Tue, 21 May 2019 22:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558502813; cv=none; d=google.com; s=arc-20160816; b=E8G+x1QWyEYwyUcmhzmUGoaRQxrsJPdJzKUT2xGUfnDsihpcutOfj006/6U4oNL/LW z+UVR1hJ5nIPO+BiGjbHHw6omnYxfxEUwLsO7FNEWMt3Pwk0w+7DGRUjb1F1WjRtk9Gg SGIwNqEG1FFszcdrz4np60oGo/uZPZFQPKHH6vSiJl0OvaeDikOfmuNoqu/8CmktjQvF fXinr1ZeAqFEqwjemlGeQuGIQq/yITnTKLy9dpQI9MoqhrQXijcnEeZ20xMuL/y1nCRO gFE2GSRnF86B9IxLStGjWw6cg+jdk6wuWomLaztzshjZuZSUPH7mmW/7vqx1vPW1zfzA SAJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=sD1VCnRtwve+KHkswyiTvr/vnE/2rqDzT/tFybnx8+Y=; b=Sn/ca9tLRf4MFvHr71jBA2urgDXjF6yXMeZSoP+yl7hLvGbwyy4iJkOtLZhoFTEhB9 tHl35Zko9K9ccTgFi7pS2ud4x+HjCZ5Jnzta0veX0Mf202GUkKlSDdGs3J6V4MyztVZ2 ljFljYU3GFbhas3d5H/Gbvj/ub+AXCeRFHMze9GNJlilws7fQB05lnjh8oCpU9lJvcM6 f+UiYsuW5pCWFOLC8OfMTbD3U4GFGOF1i+C0D/HxOofG0VA/5i6kCzP/R83gLjrqstTD gTdyODeMbi1vYPBHJwLFrKNs4lbPw1xsudpkfPLTJ+BXwcrUGckSbRGily5A+g/JJUTA 9/hA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v130si27535451pfc.99.2019.05.21.22.26.38; Tue, 21 May 2019 22:26:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727284AbfEVFYb (ORCPT + 99 others); Wed, 22 May 2019 01:24:31 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:53719 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725796AbfEVFYb (ORCPT ); Wed, 22 May 2019 01:24:31 -0400 X-UUID: c79c5609883e4e05bbfd9eabfb832317-20190522 X-UUID: c79c5609883e4e05bbfd9eabfb832317-20190522 Received: from mtkmrs01.mediatek.inc [(172.21.131.159)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1054208324; Wed, 22 May 2019 13:24:25 +0800 Received: from MTKCAS32.mediatek.inc (172.27.4.184) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 22 May 2019 13:24:23 +0800 Received: from [10.17.3.153] (172.27.4.253) by MTKCAS32.mediatek.inc (172.27.4.170) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 22 May 2019 13:24:22 +0800 Message-ID: <1558502662.14150.31.camel@mhfsdcap03> Subject: Re: [PATCH 4/4] serial: 8250-mtk: modify uart DMA rx From: Long Cheng To: Nicolas Boichat CC: Vinod Koul , Randy Dunlap , "Rob Herring" , Mark Rutland , "Ryder Lee" , Sean Wang , "Matthias Brugger" , Dan Williams , Greg Kroah-Hartman , Jiri Slaby , Sean Wang , , , "linux-arm Mailing List" , "moderated list:ARM/Mediatek SoC support" , lkml , , srv_heupstream , Yingjoe Chen , YT Shen , Zhenbao Liu , Long Cheng Date: Wed, 22 May 2019 13:24:22 +0800 In-Reply-To: <1558078602.14150.27.camel@mhfsdcap03> References: <1556336193-15198-1-git-send-email-long.cheng@mediatek.com> <1556336193-15198-5-git-send-email-long.cheng@mediatek.com> <1558078602.14150.27.camel@mhfsdcap03> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-05-17 at 15:36 +0800, Long Cheng wrote: > On Wed, 2019-05-15 at 21:48 +0800, Nicolas Boichat wrote: > > On Sat, Apr 27, 2019 at 11:36 AM Long Cheng wrote: > > > > > > Modify uart rx and complete for DMA. > > > > I don't know much about the DMA framework, but can you please explain > > why you are making the changes in this CL? I see that you are dropping > > dma_sync_single_for_device calls, for example, why? > > > > the rx buffer is create by 'dma_alloc_coherent'. in the function, the > buffer is uncache. We don't need to sync between CPU and DMA. So I > remove it. > > > > > > > Signed-off-by: Long Cheng > > > --- > > > drivers/tty/serial/8250/8250_mtk.c | 53 ++++++++++++++++-------------------- > > > 1 file changed, 23 insertions(+), 30 deletions(-) > > > > > > diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c > > > index c1fdbc0..04081a6 100644 > > > --- a/drivers/tty/serial/8250/8250_mtk.c > > > +++ b/drivers/tty/serial/8250/8250_mtk.c > > > @@ -30,7 +30,6 @@ > > > #define MTK_UART_DMA_EN_TX 0x2 > > > #define MTK_UART_DMA_EN_RX 0x5 > > > > > > -#define MTK_UART_TX_SIZE UART_XMIT_SIZE > > > #define MTK_UART_RX_SIZE 0x8000 > > > #define MTK_UART_TX_TRIGGER 1 > > > #define MTK_UART_RX_TRIGGER MTK_UART_RX_SIZE > > > @@ -64,28 +63,30 @@ static void mtk8250_dma_rx_complete(void *param) > > > struct mtk8250_data *data = up->port.private_data; > > > struct tty_port *tty_port = &up->port.state->port; > > > struct dma_tx_state state; > > > + int copied, cnt, tmp; > > > unsigned char *ptr; > > > - int copied; > > > > > > - dma_sync_single_for_cpu(dma->rxchan->device->dev, dma->rx_addr, > > > - dma->rx_size, DMA_FROM_DEVICE); > > > + if (data->rx_status == DMA_RX_SHUTDOWN) > > > + return; > > > > > > dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); > > > + cnt = dma->rx_size - state.residue; > > > + tmp = cnt; > > > > I ponder, maybe we should rename cnt to left? (like, how many bytes > > are left to transfer, in total) Or maybe "total" > > Then maybe rename tmp to cnt. > > > like better. > > > > > > > - if (data->rx_status == DMA_RX_SHUTDOWN) > > > - return; > > > + if ((data->rx_pos + cnt) > dma->rx_size) > > > + tmp = dma->rx_size - data->rx_pos; > > > > Maybe replace this and the line above: > > tmp = max_t(int, cnt, dma->rx_size - data->rx_pos); > > > Yes. It's better. > can't replace by 'max_t'. So I will keep original code. > > > > > > - if ((data->rx_pos + state.residue) <= dma->rx_size) { > > > - ptr = (unsigned char *)(data->rx_pos + dma->rx_buf); > > > - copied = tty_insert_flip_string(tty_port, ptr, state.residue); > > > - } else { > > > - ptr = (unsigned char *)(data->rx_pos + dma->rx_buf); > > > - copied = tty_insert_flip_string(tty_port, ptr, > > > - dma->rx_size - data->rx_pos); > > > + ptr = (unsigned char *)(data->rx_pos + dma->rx_buf); > > > + copied = tty_insert_flip_string(tty_port, ptr, tmp); > > > + data->rx_pos += tmp; > > > + > > > + if (cnt > tmp) { > > > ptr = (unsigned char *)(dma->rx_buf); > > > - copied += tty_insert_flip_string(tty_port, ptr, > > > - data->rx_pos + state.residue - dma->rx_size); > > > + tmp = cnt - tmp; > > > + copied += tty_insert_flip_string(tty_port, ptr, tmp); > > > + data->rx_pos = tmp; > > > } > > > + > > > up->port.icount.rx += copied; > > > > > > tty_flip_buffer_push(tty_port); > > > @@ -96,9 +97,7 @@ static void mtk8250_dma_rx_complete(void *param) > > > static void mtk8250_rx_dma(struct uart_8250_port *up) > > > { > > > struct uart_8250_dma *dma = up->dma; > > > - struct mtk8250_data *data = up->port.private_data; > > > struct dma_async_tx_descriptor *desc; > > > - struct dma_tx_state state; > > > > > > desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr, > > > dma->rx_size, DMA_DEV_TO_MEM, > > > @@ -113,12 +112,6 @@ static void mtk8250_rx_dma(struct uart_8250_port *up) > > > > > > dma->rx_cookie = dmaengine_submit(desc); > > > > > > - dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); > > > - data->rx_pos = state.residue; > > > - > > > - dma_sync_single_for_device(dma->rxchan->device->dev, dma->rx_addr, > > > - dma->rx_size, DMA_FROM_DEVICE); > > > - > > > dma_async_issue_pending(dma->rxchan); > > > } > > > > > > @@ -131,13 +124,13 @@ static void mtk8250_dma_enable(struct uart_8250_port *up) > > > if (data->rx_status != DMA_RX_START) > > > return; > > > > > > - dma->rxconf.direction = DMA_DEV_TO_MEM; > > > - dma->rxconf.src_addr_width = dma->rx_size / 1024; > > > - dma->rxconf.src_addr = dma->rx_addr; > > > + dma->rxconf.direction = DMA_DEV_TO_MEM; > > > + dma->rxconf.src_port_window_size = dma->rx_size; > > > + dma->rxconf.src_addr = dma->rx_addr; > > > > > > - dma->txconf.direction = DMA_MEM_TO_DEV; > > > - dma->txconf.dst_addr_width = MTK_UART_TX_SIZE / 1024; > > > - dma->txconf.dst_addr = dma->tx_addr; > > > + dma->txconf.direction = DMA_MEM_TO_DEV; > > > + dma->txconf.dst_port_window_size = UART_XMIT_SIZE; > > > + dma->txconf.dst_addr = dma->tx_addr; > > > > > > serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | > > > UART_FCR_CLEAR_XMIT); > > > @@ -217,7 +210,7 @@ static void mtk8250_shutdown(struct uart_port *port) > > > * Mediatek UARTs use an extra highspeed register (UART_MTK_HIGHS) > > > * > > > * We need to recalcualte the quot register, as the claculation depends > > > - * on the vaule in the highspeed register. > > > + * on the value in the highspeed register. > > > > Since you're doing some cosmetic changes here, you might as well fix > > recalcualte => recalculate and claculation => calculation on the line > > above. > > > > I see. > > > But technically, this should belong in another patch... > > > > > * > > > * Some baudrates are not supported by the chip, so we use the next > > > * lower rate supported and update termios c_flag. > > > -- > > > 1.7.9.5 > > > >