Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp753867ybt; Fri, 10 Jul 2020 11:28:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJpifTa94t+Ms8iruv1YmHcHGQBgncEkuZrTJItu5x9RiiWs8Qqg9LlwQGhkd0Mrsoj58k X-Received: by 2002:a17:906:ca0e:: with SMTP id jt14mr61061256ejb.325.1594405722880; Fri, 10 Jul 2020 11:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594405722; cv=none; d=google.com; s=arc-20160816; b=sEEQdUx7PaJrVeP9kQb706qVJ7HKlHN1LIIncYjEyLFKAldC7OS09cvI9QJUMmOJ0R HIxCJRR22iwbyfZhRho+8G+5vgPK7bduuKZDEUuFln0AukkAwO4OXWMXDNpf4hdNt4Df bmptdEiydRI7R/GWoeOUYHfQODnca03YxZt/lrdYi8EkV7gEWGiuiFxpbpg+Wp3OC0ov 8W2Qjc5CCf3hcn+6e62F/MSNlpLiWb6DX3/fHs0kym4I1MEHersqbWh/dqgKSxZ+PDzN m+KQOKYJj226M3/T7H5hDY3D9vM+k7a84ggt8QwQOp8afGcd+4HnQAxPou76kLhEIuGE c/UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tLKh/X0uXeX2LGln8V38XdhqIytFWvmdivttEbfej3A=; b=VTPzUzBpVAjzICuB7QJim70QZo3wGWVlRS5/KULGySEQUXW7llda1e+YunyHVhjGRb 8AFwCNZcMS9U8lCdFHXi06R5rJ4JFjcwxG6YyGK1OgnP0sOST2v9IUf0VATyI0w8Za9x sZPVODcH3/WtjIJmr0v69OlqONXAV3A8x1a9u/gutKfD7KLpU0DNvOBlxXkC5FXDTDA8 ImjNcvONkv2I1R+JabFIprVxhQk8SLrLFe9FqSRF+1osxzFPGKeA+VH1eQ4XCJF9oAwx F2cE/+cdjSHSHNJ8xPoTAcJ67q3fGiK0UQMPhkJeMlA25fUrABeje270n/LsBKU45tw5 SqLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T8gHEm7i; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h28si4599972edj.267.2020.07.10.11.28.19; Fri, 10 Jul 2020 11:28:42 -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; dkim=pass header.i=@chromium.org header.s=google header.b=T8gHEm7i; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727819AbgGJS2I (ORCPT + 99 others); Fri, 10 Jul 2020 14:28:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726872AbgGJS2I (ORCPT ); Fri, 10 Jul 2020 14:28:08 -0400 Received: from mail-ua1-x943.google.com (mail-ua1-x943.google.com [IPv6:2607:f8b0:4864:20::943]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27721C08C5DC for ; Fri, 10 Jul 2020 11:28:08 -0700 (PDT) Received: by mail-ua1-x943.google.com with SMTP id q15so2111344uap.4 for ; Fri, 10 Jul 2020 11:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tLKh/X0uXeX2LGln8V38XdhqIytFWvmdivttEbfej3A=; b=T8gHEm7iKqdyoST5OEcE24mAxhUbWx/ujrm3+39tyFVSnNITZrImdgsKf4o14KEpH6 xFCInhQJCQb11FGriDxPVd45l6X0wbiUg8mSX3FT1IduymyhHIDBYMsQfOfPJzhSZTRu nRe5eVDX9XxoTmNXd+01hakcw5MXFJS70VUPM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tLKh/X0uXeX2LGln8V38XdhqIytFWvmdivttEbfej3A=; b=dFFcWL64HNWn8VjF7IREGb0FSH/7kZqr+v0KSp+j7fF8+RSQplLROgjgdx0IHCTqlT cybFjSFiDboH3sdWhorJXf+LQZdG6zn7Wuh6ZhmolyL68LES1C9fb76PgS0WvQy7p87q S9SutwYxEfuLac4t38y+OBS3hdKcVYMI16SyFG4IQWF7TZNgBP0S0Q2N46qEYQ4a948w i7aeVyQFrSs4y52vp/7DF/oc1QQxUOrPcFYiYmJrOK/caSHc2UCLbfkEjDFOCoR8wkYF oQ8pqILhNzVnp/YqCmNY+zM2aE8SWi0GnMZeC/dNc3ZUzkyStx3PjH1Fq8CVSgwkJxWe Zy7Q== X-Gm-Message-State: AOAM532yOdg8W4dB+2VjvXfEQZrSgXEt8IQ4evHvhW+odwxo2W6y1Gcd XWRjzZACuz7pvadoeguRQkY5wjYlSLk= X-Received: by 2002:ab0:44e5:: with SMTP id n92mr12115131uan.121.1594405686903; Fri, 10 Jul 2020 11:28:06 -0700 (PDT) Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com. [209.85.221.175]) by smtp.gmail.com with ESMTPSA id x201sm826341vsc.27.2020.07.10.11.28.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jul 2020 11:28:05 -0700 (PDT) Received: by mail-vk1-f175.google.com with SMTP id s192so1446825vkh.3 for ; Fri, 10 Jul 2020 11:28:05 -0700 (PDT) X-Received: by 2002:a1f:9d57:: with SMTP id g84mr27397611vke.100.1594405685296; Fri, 10 Jul 2020 11:28:05 -0700 (PDT) MIME-Version: 1.0 References: <20200626200033.1528052-1-dianders@chromium.org> <20200626125844.2.Iabd56347670b9e4e916422773aba5b27943d19ee@changeid> In-Reply-To: From: Doug Anderson Date: Fri, 10 Jul 2020 11:27:53 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] serial: qcom_geni_serial: Always use 4 bytes per TX FIFO word To: Evan Green Cc: Greg Kroah-Hartman , Daniel Thompson , Akash Asthana , Stephen Boyd , kgdb-bugreport@lists.sourceforge.net, linux-arm-msm , Sumit Garg , Vivek Gautam , Andy Gross , Bjorn Andersson , Jiri Slaby , LKML , linux-serial@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Jul 10, 2020 at 10:46 AM Evan Green wrote: > > On Fri, Jun 26, 2020 at 1:01 PM Douglas Anderson wrote: > > > > The geni serial driver had a rule that we'd only use 1 byte per FIFO > > word for the TX FIFO if we were being used for the serial console. > > This is ugly and a bit of a pain. It's not too hard to fix, so fix > > it. > > > > Signed-off-by: Douglas Anderson > > --- > > > > drivers/tty/serial/qcom_geni_serial.c | 57 +++++++++++++++++---------- > > 1 file changed, 37 insertions(+), 20 deletions(-) > > > > diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c > > index 4610e391e886..583d903321b5 100644 > > --- a/drivers/tty/serial/qcom_geni_serial.c > > +++ b/drivers/tty/serial/qcom_geni_serial.c > > @@ -103,12 +103,18 @@ > > #define DEFAULT_IO_MACRO_IO2_IO3_MASK GENMASK(15, 4) > > #define IO_MACRO_IO2_IO3_SWAP 0x4640 > > > > +/* We always configure 4 bytes per FIFO word */ > > +#define BYTES_PER_FIFO_WORD 4 > > + > > struct qcom_geni_private_data { > > /* NOTE: earlycon port will have NULL here */ > > struct uart_driver *drv; > > > > u32 poll_cached_bytes; > > unsigned int poll_cached_bytes_cnt; > > + > > + u32 write_cached_bytes; > > + unsigned int write_cached_bytes_cnt; > > }; > > > > struct qcom_geni_serial_port { > > @@ -121,8 +127,6 @@ struct qcom_geni_serial_port { > > bool setup; > > int (*handle_rx)(struct uart_port *uport, u32 bytes, bool drop); > > unsigned int baud; > > - unsigned int tx_bytes_pw; > > - unsigned int rx_bytes_pw; > > void *rx_fifo; > > u32 loopback; > > bool brk; > > @@ -390,13 +394,25 @@ static void qcom_geni_serial_poll_put_char(struct uart_port *uport, > > #ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE > > static void qcom_geni_serial_wr_char(struct uart_port *uport, int ch) > > { > > - writel(ch, uport->membase + SE_GENI_TX_FIFOn); > > + struct qcom_geni_private_data *private_data = uport->private_data; > > + > > + private_data->write_cached_bytes = > > + (private_data->write_cached_bytes >> 8) | (ch << 24); > > + private_data->write_cached_bytes_cnt++; > > + > > + if (private_data->write_cached_bytes_cnt == BYTES_PER_FIFO_WORD) { > > + writel(private_data->write_cached_bytes, > > + uport->membase + SE_GENI_TX_FIFOn); > > + private_data->write_cached_bytes_cnt = 0; > > + } > > } > > > > static void > > __qcom_geni_serial_console_write(struct uart_port *uport, const char *s, > > unsigned int count) > > { > > + struct qcom_geni_private_data *private_data = uport->private_data; > > + > > int i; > > u32 bytes_to_send = count; > > > > @@ -431,6 +447,15 @@ __qcom_geni_serial_console_write(struct uart_port *uport, const char *s, > > SE_GENI_M_IRQ_CLEAR); > > i += chars_to_write; > > } > > + > > + if (private_data->write_cached_bytes_cnt) { > > + private_data->write_cached_bytes >>= BITS_PER_BYTE * > > + (BYTES_PER_FIFO_WORD - private_data->write_cached_bytes_cnt); > > + writel(private_data->write_cached_bytes, > > + uport->membase + SE_GENI_TX_FIFOn); > > + private_data->write_cached_bytes_cnt = 0; > > + } > > How does this not end up sending stray zeros? In other words, how does > the hardware know which bytes of this word are valid? We told it how many bytes we wanted to send in qcom_geni_serial_setup_tx(). If the total number of bytes being sent is not a multiple of the FIFO word size then it knows that the last word will be a partial and it'll extract just the number of needed bytes out of it. Like receiving, sending bytes out of geni is also packet based. Though the packets work a little differently for sending vs. receiving in both cases you are supposed to fully finish a packet before you send more bytes (you can sorta cancel / start a new packet, but that's not what we're doing here). So ahead of time we told it how many bytes to expect and then we sent them all. NOTE: if we wanted to simplify this function at the expense of efficiency, we could change it to always send 1-byte packets. Then we'd start a packet, send 1 byte, wait for done, start a new packet, send 1 byte, wait for done, etc. In fact, that's how the polling code does it... -Doug