From patchwork Tue Nov 29 11:00:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 629214 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEB0C4167B for ; Tue, 29 Nov 2022 11:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232597AbiK2LAv (ORCPT ); Tue, 29 Nov 2022 06:00:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232559AbiK2LA3 (ORCPT ); Tue, 29 Nov 2022 06:00:29 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E6260E9C for ; Tue, 29 Nov 2022 03:00:25 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id ja4-20020a05600c556400b003cf6e77f89cso789417wmb.0 for ; Tue, 29 Nov 2022 03:00:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UCx51yC9FU1yXWOh1yw/MuoHVQ7pzTJCbQJJlG1PhVk=; b=fg/ELnn3dT2bcQp3NIsvGvAOU4IIfMZG7ttb8g21jmYpRlMWMygqPh6xHOp87tY7p1 yaEc/eMl02eyBI04DF+CFr9KsOVEFG+N7r+BLdaPQLVtF54wlSfc7YcZpkal/k3zGsWg nD+HEkPmENlhGytkXDIbO0TLrjIJl3lPnVcSL1RqGVeKPjQrAnxZtMGAWWuKuJ9eJz+o TRPMuSq8a6uVrYDfO/jyddUfd6iT2ItfcEJji9G+/6TePWUfizyi1mneFNTVC3AcGoOb n91WZsy8rlNs/Z5jiUrzLzIBv9clb8pzVX0Zec+vdA0M96YJaXEY1enbT9zWaJkAdlip Ttfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UCx51yC9FU1yXWOh1yw/MuoHVQ7pzTJCbQJJlG1PhVk=; b=qpAcPoeKj6olsmr0OQyV0lWZvqC9Ooqu8cwep33R9jkOGoaXUaH94nqmLm5nQ2MM3J Uu4rYmoUCpoaLciBL1uFsl1Bd2HBLAmt5D13PEp/QjzFlN/dre92ab/6P9l5nD5hkolK 8rxwf8RpAuf72U5Fsqxg13ufmroDlrgC9VAfEKWrIvavN0jrOKj+K6TmEGIUhcJT/aDS zvd+4L+yYXFbgAfhZWEvClDHr/7IG+w/pUJ3rJWrVTmSDRjGZ0VcHiLIrkFh2FXDMAqm /zNYJsU5XCNgGJW7GmUbqaoFdVAYhD3S46/4soS9y6CF7yjIXaU1UWZu4O3vTZspWT7l oiXA== X-Gm-Message-State: ANoB5pkqcWQgx2n67weUZy+8y/bPor4pgHsWi+gL4jGyYwNrGS0cH2rE WsgAUaWnr/jvn+6+L8B7ltAarw== X-Google-Smtp-Source: AA0mqf4A8+jlrMOET9sawxjDQfpCcherYi21OVJ+m7bOPfzZf0RJvzBAFf3zIRN40FNPqQJr5SiKDw== X-Received: by 2002:a05:600c:2193:b0:3cf:a323:bfe6 with SMTP id e19-20020a05600c219300b003cfa323bfe6mr33940371wme.86.1669719625514; Tue, 29 Nov 2022 03:00:25 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6b19:1d8e:fbca:fd02]) by smtp.gmail.com with ESMTPSA id q19-20020a1cf313000000b003a3170a7af9sm1617658wmq.4.2022.11.29.03.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 03:00:25 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , Srinivas Kandagatla , Vinod Koul , Alex Elder , =?utf-8?q?Ilp?= =?utf-8?q?o_J=C3=A4rvinen?= Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 08/13] tty: serial: qcom-geni-serial: refactor qcom_geni_serial_handle_tx() Date: Tue, 29 Nov 2022 12:00:07 +0100 Message-Id: <20221129110012.224685-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221129110012.224685-1-brgl@bgdev.pl> References: <20221129110012.224685-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski qcom_geni_serial_handle_tx() is pretty big, let's move the code that handles the actual writing of data to a separate function which makes sense in preparation for introducing a dma variant of handle_tx(). Let's also shuffle the code a bit, drop unneeded variables and use uart_xmit_advance() instead of handling tail->xmit manually. Signed-off-by: Bartosz Golaszewski --- drivers/tty/serial/qcom_geni_serial.c | 55 +++++++++++++-------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index 68a1402fbe58..ece5b4d543fc 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -93,7 +93,7 @@ #define IO_MACRO_IO2_IO3_SWAP 0x4640 /* We always configure 4 bytes per FIFO word */ -#define BYTES_PER_FIFO_WORD 4 +#define BYTES_PER_FIFO_WORD 4U struct qcom_geni_private_data { /* NOTE: earlycon port will have NULL here */ @@ -704,19 +704,41 @@ static void qcom_geni_serial_start_rx(struct uart_port *uport) writel(irq_en, uport->membase + SE_GENI_M_IRQ_EN); } +static void qcom_geni_serial_send_chunk_fifo(struct uart_port *uport, + unsigned int chunk) +{ + struct qcom_geni_serial_port *port = to_dev_port(uport); + struct circ_buf *xmit = &uport->state->xmit; + unsigned int tx_bytes, remaining = chunk; + u8 buf[BYTES_PER_FIFO_WORD]; + int c; + + while (remaining) { + memset(buf, 0, sizeof(buf)); + tx_bytes = min(remaining, BYTES_PER_FIFO_WORD); + + for (c = 0; c < tx_bytes ; c++) { + buf[c] = xmit->buf[xmit->tail]; + uart_xmit_advance(uport, 1); + } + + iowrite32_rep(uport->membase + SE_GENI_TX_FIFOn, buf, 1); + + remaining -= tx_bytes; + port->tx_remaining -= tx_bytes; + } +} + static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done, bool active) { struct qcom_geni_serial_port *port = to_dev_port(uport); struct circ_buf *xmit = &uport->state->xmit; size_t avail; - size_t remaining; size_t pending; - int i; u32 status; u32 irq_en; unsigned int chunk; - int tail; status = readl(uport->membase + SE_GENI_TX_FIFO_STATUS); @@ -735,7 +757,6 @@ static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done, avail = port->tx_fifo_depth - (status & TX_FIFO_WC); avail *= BYTES_PER_FIFO_WORD; - tail = xmit->tail; chunk = min(avail, pending); if (!chunk) goto out_write_wakeup; @@ -750,29 +771,7 @@ static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done, uport->membase + SE_GENI_M_IRQ_EN); } - remaining = chunk; - for (i = 0; i < chunk; ) { - unsigned int tx_bytes; - u8 buf[sizeof(u32)]; - int c; - - memset(buf, 0, sizeof(buf)); - tx_bytes = min_t(size_t, remaining, BYTES_PER_FIFO_WORD); - - for (c = 0; c < tx_bytes ; c++) { - buf[c] = xmit->buf[tail++]; - tail &= UART_XMIT_SIZE - 1; - } - - iowrite32_rep(uport->membase + SE_GENI_TX_FIFOn, buf, 1); - - i += tx_bytes; - uport->icount.tx += tx_bytes; - remaining -= tx_bytes; - port->tx_remaining -= tx_bytes; - } - - xmit->tail = tail; + qcom_geni_serial_send_chunk_fifo(uport, chunk); /* * The tx fifo watermark is level triggered and latched. Though we had