From patchwork Tue Nov 22 10:21:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 24250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2118733wrr; Tue, 22 Nov 2022 02:24:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf59k57Thz222WQ2Qx8DrgyM48I47f/aXpblLNMM0qvDMXjEc6429XCpbiR772PkoVn8w/H2 X-Received: by 2002:a17:906:81cd:b0:7ad:beb3:91b6 with SMTP id e13-20020a17090681cd00b007adbeb391b6mr3882611ejx.159.1669112655989; Tue, 22 Nov 2022 02:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669112655; cv=none; d=google.com; s=arc-20160816; b=fkgt9O8Sf6daCxEnPBNGq4YYD+utDXWYsLfUQFroZpua+tN6mjySlvk8XO67twyVgg 9X00wylvE/MyL1iKFds0M6EEiQAfKGzxnrb4/NZA/b6TlwQqREfN5qlePS4Stc05E3kP MyFfEZWHpWTwTE5VMjy5ARz1SGX155s3UwLBA2+GTsF6c6Z0aY1+5ld790zRqfK2wGmb Vu6MZ8SzncZeFPmovP2G2PuKn2U15dsVkfQ3q/ogRcLt/rGomeug0Im+hPT8LQzdwQCJ L2cKAV88jTgQkwWo3mmv2/R2FXtlrDHnrtr/Ez3+uq7Fa/lxw6R6iugVk4psiOi+hqQa uiWA== 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 :dkim-signature; bh=kzY04K9GyuBHm3usH7zJK0sqLLvwAU6csJcimfdY1bo=; b=RYpjFP0TPO+spFUUuUpYpTzt5bZLTD8w3i5aRjIkqpeAuWT7t2bkCNDXI5E46SeRA/ O5QCWdpiDfpVe4gw4ykf0Mywi+bueS2R4E1inZ36HHXHVvepWRfbiE8mJXLSUImQ4UAR JRq4y3JnhVIVqLJapj7b/owaJXs3gYSGdVKg/Yfj/FTLkzoVWZkaaKS7OLK1LqjUFEpZ BeXWQYVxRwNZtafnNGWF7gCsDN3L5MrjOFezkm3ywKHZcjntRyPXLaAn9m9Eu3EVUqJr 4rReuEEpqPtGWiIv6h7XVANbsEzaB8a1GL4nFBx6/XlrNAuTrW3Aihx7CPVaJtUNdkDP +olA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=fG9KF9TC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ae12-20020a17090725cc00b007825337afeesi14699581ejc.273.2022.11.22.02.23.52; Tue, 22 Nov 2022 02:24:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=fG9KF9TC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233572AbiKVKXU (ORCPT + 99 others); Tue, 22 Nov 2022 05:23:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233570AbiKVKWH (ORCPT ); Tue, 22 Nov 2022 05:22:07 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6174D41985 for ; Tue, 22 Nov 2022 02:21:50 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id x5so19908877wrt.7 for ; Tue, 22 Nov 2022 02:21:50 -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=fG9KF9TCboacMHM4Lqbb4TbFZF3dpm25PBc8vtuxLKqjWm2KdBep1qPauzfPaAQoMO mfTspLuptF7SrzxQUD0ssz88qQP+ZLWM8tZEOl+114Sz7P3w3u2fcYEATIm6hLKNfW/X 6lbJamPubM3iNHZTxD8jJG2u5ww1gi736U2gECXWH32Wkib5t+Q0Y2aJ7rvil3jBPS0B Uk3hCb9QMljrmnyrGogyhtGLtZqY/H4MHsHM0FsFUPipFMhONjqBvodWfWdnpFcRmkY3 O/kDhz12jkBIKsvb954rbJpx10BI9iPI2sbR7z02ELm02grGCxrpyNmerPxTOjF9au2X +UhQ== 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=pUbZZDeyi9zYNN11VtMP66t99VSF0BF5uzOYKl5bVXsOJOHlxr4WRb2dRoRfd6jmEJ 0BV5qa3AITwHHGFIGXVsPAJj1n5Zxmav0jDBDgFgQe3wUfBPmrm8n9GrozBfaobJyjhL B6Yh4ChuEyhiIhYxc/0SIQPf6DIfKOGv5Bg1rOD7sw/c7ril4SnOe2RapBwurQwUy5/F VV7NCDQcnwwYjSN5vNEVBcdA/hfswqOoXkQ/KwrYGqQ5Gye96b7h/Mg/lJEtuT05rgOx ytdj3fPiMZ7UMeRXWgFDCQ/LdKNlIwF+LEY5pms6o2HxP8g89tGLzfO7t7wtvS4YvkAr h8OQ== X-Gm-Message-State: ANoB5pllB/wO5TOaW+38vPAz+EuS9rRPumyvv2ffRA1x55EhRDLXkQmK 9ccyOLHJuTuHXz08glWYGbyDRQ== X-Received: by 2002:adf:e8cc:0:b0:236:7a1c:c437 with SMTP id k12-20020adfe8cc000000b002367a1cc437mr13408424wrn.124.1669112508869; Tue, 22 Nov 2022 02:21:48 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:e011:9e81:66f1:3415]) by smtp.gmail.com with ESMTPSA id o3-20020a5d4083000000b002366e8eee11sm13432873wrp.101.2022.11.22.02.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 02:21:48 -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 v2 08/15] tty: serial: qcom-geni-serial: refactor qcom_geni_serial_handle_tx() Date: Tue, 22 Nov 2022 11:21:18 +0100 Message-Id: <20221122102125.142075-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221122102125.142075-1-brgl@bgdev.pl> References: <20221122102125.142075-1-brgl@bgdev.pl> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750191472654574034?= X-GMAIL-MSGID: =?utf-8?q?1750191472654574034?= 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