Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp555023pxy; Fri, 30 Apr 2021 10:54:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzVtQxtJpkW+Resa1Ah+4SoB52rFA7vERWwZNdvlQrXro3lClAn4qLSH/4S1YXg/3sx9E6 X-Received: by 2002:a05:6402:2753:: with SMTP id z19mr7360026edd.158.1619805279696; Fri, 30 Apr 2021 10:54:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619805279; cv=none; d=google.com; s=arc-20160816; b=xMWAUNRAY5kB2VqcAcB31t1j2peaS9mClaXTyQjhFUjXZdFgFAbZBKEeRUe02UFfk+ 9vPRPkZvIQ3CBGFiYqiDKE0QxLwqkdlz/zTfT+txGv80W3LrlqEb9U0DQBLH8IlekOB4 +3EIl0RaY4ymdvOht/RhHpZuhpRm++a7rzYyZTyr6tfq6ivA9dIM3pOwc727T28TLDBy WZHV+Kwwlkr0kAueVW1uYrrMr8USpDcU6065hQmlMNTBCacM1EQqVsffKYm/PwUUgSWe niyX5si1sdeVkpxwhfapkccjxacOhYxtI/7tqxOChzY8OQbB+C/7HOOViWTEbFF5f77c prXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HMzsaqTGZDxXnCna6bQLV0e80DntjnVjS74hsO2j+28=; b=cdHaKQmUCmYY50MkM4rQuXPVnCFTN5G4VhsHHkGiXFQXUX5LK9E3omk8EjN+cNKxlB vbBrsUC3eb1h9tA1CMMyiAmg+z3wDoLRiKw5r7QRQAs9MZ0LhJNSjSaHmcO2KpxR4XrF gUxDYuXfO6VJ3zrXHncJad0LK5oyG8bra9gD+leDm+3bU4AYryKWuixGDasKeQMlhWHK srm7T22X8AguZjYdR+zt17dGBSPI1+jGk1n5nMkmf55VPLxakUF9K1jrZoIpdU6Iu9EW wghVbx1p3Rvv7YJvqp8PQoaOYlfRJWyTACKC2MnHGAOeXL7+kw8rCnX9z5r5d8hOEyM2 rqaA== 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz20si4672632ejc.70.2021.04.30.10.54.15; Fri, 30 Apr 2021 10:54:39 -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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231503AbhD3Rvo (ORCPT + 99 others); Fri, 30 Apr 2021 13:51:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbhD3Rvh (ORCPT ); Fri, 30 Apr 2021 13:51:37 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97BAFC06138B; Fri, 30 Apr 2021 10:50:48 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 21C1E1F43C65 Received: by jupiter.universe (Postfix, from userid 1000) id F35124800C3; Fri, 30 Apr 2021 19:50:44 +0200 (CEST) From: Sebastian Reichel To: Greg Kroah-Hartman , Rob Herring Cc: Jiri Slaby , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Sebastian Reichel , Ian Ray , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, kernel@collabora.com Subject: [PATCHv5 1/2] serial: imx: Add DMA buffer configuration via DT Date: Fri, 30 Apr 2021 19:50:37 +0200 Message-Id: <20210430175038.103226-2-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210430175038.103226-1-sebastian.reichel@collabora.com> References: <20210430175038.103226-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fabien Lahoudere In order to optimize serial communication (performance/throughput VS latency), we may need to tweak DMA period number and size. This adds DT properties to configure those values before initialising DMA. The defaults will stay the same as before. Signed-off-by: Fabien Lahoudere [update documentation and commit message, rebase to current master, switch back to DT instead of sysfs] Signed-off-by: Sebastian Reichel --- .../bindings/serial/fsl-imx-uart.yaml | 12 +++++++++ drivers/tty/serial/imx.c | 25 +++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/serial/fsl-imx-uart.yaml b/Documentation/devicetree/bindings/serial/fsl-imx-uart.yaml index 2b06c6ce4a75..9d949296a142 100644 --- a/Documentation/devicetree/bindings/serial/fsl-imx-uart.yaml +++ b/Documentation/devicetree/bindings/serial/fsl-imx-uart.yaml @@ -71,6 +71,18 @@ properties: received, and that the peripheral should invert its input using the INVR registers. + fsl,dma-info: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + description: | + First cell contains the size of DMA buffer chunks, second cell contains + the amount of chunks used for the device. Multiplying both numbers is + the total size of memory used for receiving data. + When not being configured the system will use default settings, which + are sensible for most use cases. If you need low latency processing on + slow connections this needs to be configured appropriately. + uart-has-rtscts: true rs485-rts-delay: true diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 7d5a8dfa3e91..9e72e382a867 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -225,6 +225,8 @@ struct imx_port { struct scatterlist rx_sgl, tx_sgl[2]; void *rx_buf; struct circ_buf rx_ring; + unsigned int rx_buf_size; + unsigned int rx_period_length; unsigned int rx_periods; dma_cookie_t rx_cookie; unsigned int tx_bytes; @@ -1183,10 +1185,6 @@ static void imx_uart_dma_rx_callback(void *data) } } -/* RX DMA buffer periods */ -#define RX_DMA_PERIODS 16 -#define RX_BUF_SIZE (RX_DMA_PERIODS * PAGE_SIZE / 4) - static int imx_uart_start_rx_dma(struct imx_port *sport) { struct scatterlist *sgl = &sport->rx_sgl; @@ -1197,9 +1195,8 @@ static int imx_uart_start_rx_dma(struct imx_port *sport) sport->rx_ring.head = 0; sport->rx_ring.tail = 0; - sport->rx_periods = RX_DMA_PERIODS; - sg_init_one(sgl, sport->rx_buf, RX_BUF_SIZE); + sg_init_one(sgl, sport->rx_buf, sport->rx_buf_size); ret = dma_map_sg(dev, sgl, 1, DMA_FROM_DEVICE); if (ret == 0) { dev_err(dev, "DMA mapping error for RX.\n"); @@ -1316,7 +1313,8 @@ static int imx_uart_dma_init(struct imx_port *sport) goto err; } - sport->rx_buf = kzalloc(RX_BUF_SIZE, GFP_KERNEL); + sport->rx_buf_size = sport->rx_period_length * sport->rx_periods; + sport->rx_buf = kzalloc(sport->rx_buf_size, GFP_KERNEL); if (!sport->rx_buf) { ret = -ENOMEM; goto err; @@ -2179,11 +2177,16 @@ static enum hrtimer_restart imx_trigger_stop_tx(struct hrtimer *t) return HRTIMER_NORESTART; } +/* Default RX DMA buffer configuration */ +#define RX_DMA_PERIODS 16 +#define RX_DMA_PERIOD_LEN (PAGE_SIZE / 4) + static int imx_uart_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct imx_port *sport; void __iomem *base; + u32 dma_buf_conf[2]; int ret = 0; u32 ucr1; struct resource *res; @@ -2218,6 +2221,14 @@ static int imx_uart_probe(struct platform_device *pdev) if (of_get_property(np, "fsl,inverted-rx", NULL)) sport->inverted_rx = 1; + if (!of_property_read_u32_array(np, "fsl,dma-info", dma_buf_conf, 2)) { + sport->rx_period_length = dma_buf_conf[0]; + sport->rx_periods = dma_buf_conf[1]; + } else { + sport->rx_period_length = RX_DMA_PERIOD_LEN; + sport->rx_periods = RX_DMA_PERIODS; + } + if (sport->port.line >= ARRAY_SIZE(imx_uart_ports)) { dev_err(&pdev->dev, "serial%d out of range\n", sport->port.line); -- 2.30.2