From patchwork Wed Nov 23 11:07:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 628406 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 7E566C4332F for ; Wed, 23 Nov 2022 11:09:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237309AbiKWLJh (ORCPT ); Wed, 23 Nov 2022 06:09:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237621AbiKWLId (ORCPT ); Wed, 23 Nov 2022 06:08:33 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C870F9BA1B for ; Wed, 23 Nov 2022 03:08:13 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id x17so15389660wrn.6 for ; Wed, 23 Nov 2022 03:08:13 -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=kzY04K9GyuBHm3usH7zJK0sqLLvwAU6csJcimfdY1bo=; b=SxiA56FEPn1tTlUbvznsd9HsII5+1ZsnUYrfPdthATClaXeuh1+DSatCx06H9IKbrv 7/bWd6pe0VRT0Jau2lKEnpkt6iYiYC51ali/LiNmmatnIrZdhm83XyiG4MaR9P9H1UWE Kh4e9kBKrNhNRnWU8jdtmiIkjWNVqH4Ld7wqO4C1n2RFKLfXcml/OGJ6jMYkCvEum7DL jodgRO1kQoDRtln/s2aUNthOQM2Ftcil/KpixJs8ZK0prPq1R3iJOiY3KS55WzFN3T9G eZ9IbE+jN5H6S/6OY9+cHF5jV14dOOZeqc+APeugwZifOT9Hqp4LU4jryhmZtuHCW0Jr tzvw== 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=kzY04K9GyuBHm3usH7zJK0sqLLvwAU6csJcimfdY1bo=; b=JWd+SGQOQKiInhbWDwhXsKF1Q7cnfArTtPmHkacjMU5wgJvZQTBPa3FiIAhBPbtZcB tYP14KQIqdp8832tm9AeS3+isSKqFWKzAPbr9DnOQqZq+kUepDI9NrHFIWcIRwhVCCbb CURNcjpF7OWsN5381pVMJVkzDz08/abCamIXk5Ic0IhTp/nIdbh51XlUopMUf6bmGnJW 5/1soUh83gUzMW6tW4dhXHgYYnSfTY+hdwzzhhH+OO5Hn36xveX0chBf9Gc3d9tRtczb JG2dBeE1PIPFqG3XJuI6Cx8dkC+GkP/WgpZcvnrJNS3CbhmbaUCbZ7lFYSRXbPNbgKJP I0qg== X-Gm-Message-State: ANoB5pkklMQyM8f21VSHPHOLuXy6GGRuTzd5k08p05XXb58Ygu75y4Ww zubcwhBgPUlsDn9EhifQ0/2EdQ== X-Google-Smtp-Source: AA0mqf6JZaxLA6+i2yDWj1lFtnlxnO2S5fLvX9YGI8ysDpwpWSst9x/t1Nl3BbMIfPGK+7BounysRw== X-Received: by 2002:adf:dfc6:0:b0:236:cfcf:8e36 with SMTP id q6-20020adfdfc6000000b00236cfcf8e36mr17163483wrn.323.1669201692287; Wed, 23 Nov 2022 03:08:12 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae74:d94f:4677:3378]) by smtp.gmail.com with ESMTPSA id f13-20020a05600c4e8d00b003c6c182bef9sm2560406wmq.36.2022.11.23.03.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 03:08:11 -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 v3 08/13] tty: serial: qcom-geni-serial: refactor qcom_geni_serial_handle_tx() Date: Wed, 23 Nov 2022 12:07:54 +0100 Message-Id: <20221123110759.1836666-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221123110759.1836666-1-brgl@bgdev.pl> References: <20221123110759.1836666-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 | 54 +++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index 68a1402fbe58..658b6d596f58 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -704,19 +704,42 @@ 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; + u8 buf[BYTES_PER_FIFO_WORD]; + size_t remaining = chunk; + unsigned int tx_bytes; + int c; + + while (remaining) { + 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[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 +758,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 +772,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