Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp245599lqb; Thu, 23 May 2024 17:38:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3qeRLzJry0O5eW9knkzjETN9W9+5VrdWzckrjvgt+awnfN0q3sQPVbxRIm+g4OPdslUsJ7CdDNBUCzUB678gF7QQAvPEPeaj5zhWrWA== X-Google-Smtp-Source: AGHT+IGRbi6jRsiVNcoLb/q6ZqEW+E/DDdwdX8OV6tTR87s8TEyEBmW4OYBY8x9RRLRYi2mZmDHq X-Received: by 2002:a17:903:120c:b0:1f2:f63b:4795 with SMTP id d9443c01a7336-1f4486c65e6mr12296295ad.14.1716511128232; Thu, 23 May 2024 17:38:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716511128; cv=pass; d=google.com; s=arc-20160816; b=BTZTVuDLtx949d4DNKBljrTcV5Y6oeTc7xLWomQhUXipMXIhgs4kQFokXnCtMEnx/q q+5WqK+lixZAXuf7pU638pxgiHOR4o+tIvhm+Hwyfvte87Ng/6Yn6m1WAlNQmNXnvCia uGiwwtO4xABO5B5M4B0wJRDY6Lm4Hm47tAOqj8fPfT8THCxrNuL3YFc4fFc1FPQ1TSP/ XwfumPa/dTt6yDJstyJnPxB0GGoLZAqTdgUwSUuia79k/hyjMTZpQ1haOReMyNE7mziY V4nOnnGxv9DQk8nr5PyJsrxng1lImpgq2gC6+78XX/UvR5e42iVdS9m04Z7Zi4rmUcXc Aipw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:user-agent:from:references :in-reply-to:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:dkim-signature; bh=8oEGXFFhEZ3kKS8HqbZY7sKVJ85+CGR+UK70IUChd0Y=; fh=xC1DEW0UEIbp4qNCpegt8bOV1sbJ3vMqE4FbsShPaJ8=; b=C8gyRd9xHbTYY7qyksUrywK8+vCjdkzv/ddZTPbNfsrwvr6V4R93eb4z2L5vlVJKQZ OqsckBAE2g2Vi8bFXDi1BNXM11xgo4JdlbuqrY4MFDTHS6BCHktICVwiIxwu2sAnRZp8 1YhYgswb2J9Wh5TzC3GU2ktX2V/pLJAgaLITpiadINrnCdJNZn/DXwHFufmj6BjznZZ8 XWGZbnAyGUW5cfj4egMOMkIQNsMbGagoxXaaAB9tsR5VczHzMbJNW/NIjav3yuV8lGdY l1LGYM5DMhZi7MX0762WoVx3dFJC6WWXFg/g6xoBKR1ScMf60PVkIDP87UDb2RXeIicg qAJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ex3GKSZu; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-188183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188183-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c788efcsi2900375ad.67.2024.05.23.17.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 17:38:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ex3GKSZu; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-188183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188183-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D2D022831ED for ; Fri, 24 May 2024 00:38:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8F818493; Fri, 24 May 2024 00:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Ex3GKSZu" Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41150816 for ; Fri, 24 May 2024 00:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716511118; cv=none; b=jdLDixjaIMzLVzpqp6LgDvrz1CtdiKjvB2Q1dpxN9l0KbPbEtAJaxzLgNy3Bhk16rJN04/0lNMuXPyLPISjTGneO5xI2yWO22vMJhSg09F+4xt022qyMV3igPoj3fpVkB4sOvKmSrAaoGowWbXuEWJFRAlE3TvWMHbDELz8c+bI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716511118; c=relaxed/simple; bh=grp2aumzXD04JTUddCKPIYKV3Zd9gabxwz5TJKI3HGw=; h=MIME-Version:In-Reply-To:References:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SAzQR9c7sRC8jUysQrJnwehH5b+wf+zrExpcrol4D2F10ifjmYUr92AX7cuMMS39bMBiQbfLPSi44jGX1pvFbY1LD8ExNMJY0+3WwI4vNJV5eMKoO9Y3lflYtmVUzEBWUSzhVqaUDMtNsbpHImFGE8yHdV8CbU8kZSphZToZkDI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Ex3GKSZu; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3c99e6b8b1fso4348730b6e.1 for ; Thu, 23 May 2024 17:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716511116; x=1717115916; darn=vger.kernel.org; h=cc:to:subject:message-id:date:user-agent:from:references :in-reply-to:mime-version:from:to:cc:subject:date:message-id :reply-to; bh=8oEGXFFhEZ3kKS8HqbZY7sKVJ85+CGR+UK70IUChd0Y=; b=Ex3GKSZuxcxD+i/4WPEcNOxsUhcdOmlkltvZ1BBzr8A0NFRBOQgveZg/VxQ/SrZeq+ y/e30zgGncRfviVjrjqjUKsN1kHKXyMvp7BOkIDyT7tKch6OBqnqVfe2k2lmVzdQvhEM VMIu08MgAP+W4ocCPdyD9Z2cU78O9B/BlcEfQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716511116; x=1717115916; h=cc:to:subject:message-id:date:user-agent:from:references :in-reply-to:mime-version:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8oEGXFFhEZ3kKS8HqbZY7sKVJ85+CGR+UK70IUChd0Y=; b=C8VDA7IHfsoVMuETXwiD8hAc1MUP6z0ikf+iCUK3eYCvgEt2FD3hjmiiwmZ+R07mdM ImOGlSwruzlYAJ1HtDXi1CY906UqGEIqD5fH4RPb0m02C8ucafVmIijKZSVZB5zY6DLq WKdyenJr8jxYYvdDeGl9sRmZWr8/xI4+X7MGGdnt6LOns/NcP6CODwKO3drFQzj0bDLO FRoWT0slBUQMp9bjcgs9Z395m6TOs54Hu0aX8hfHOvBl5nCqmaURcInwdYusSVm5Ktv/ zfM38WuMRQtSRy/F1YwGvs/qf4hBhn0+HdxwmAzDlJ0tXYSSQqb5DmN5z9wrGVT3CV4N MUdw== X-Forwarded-Encrypted: i=1; AJvYcCXh2wjlDxeNpaouA2OlS080UWWrxn1O8y6mWi2bk6n5/HMsjXvYHVu0A4PeULC6Y1wewyHrO2jNLyxnd0mxx9fJWN81QCv+nYAuK4v6 X-Gm-Message-State: AOJu0YxohfW9R7AYb3BlwrlkbsOQKYbYXaMd4b43oDIZp7eJHEfHOUt0 7YavPmQnRKz6FvfER+zpT3WSc2iOmbmLgtMZQnJQO46hHTRilxUkpYkYSGmM8TgNBw7Gqv8M6iA 15WJA8dFMF3CudiAPPYXpm5yg4N/ajVDoRW3c X-Received: by 2002:a05:6808:358:b0:3c7:4fd4:ae76 with SMTP id 5614622812f47-3d1a4fb3c78mr1125728b6e.10.1716511116239; Thu, 23 May 2024 17:38:36 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 23 May 2024 19:38:34 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240523162207.2.I0f81a5baa37d368f291c96ee4830abca337e3c87@changeid> References: <20240523232216.3148367-1-dianders@chromium.org> <20240523162207.2.I0f81a5baa37d368f291c96ee4830abca337e3c87@changeid> From: Stephen Boyd User-Agent: alot/0.10 Date: Thu, 23 May 2024 19:38:34 -0500 Message-ID: Subject: Re: [PATCH 2/2] serial: qcom-geni: Fix qcom_geni_serial_stop_tx_fifo() while xfer To: Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , John Ogness , Tony Lindgren , linux-arm-msm@vger.kernel.org, Johan Hovold , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , Yicong Yang , James Clark , Thomas Gleixner , Vijaya Krishna Nivarthi , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Quoting Douglas Anderson (2024-05-23 16:22:13) > diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c > index 2bd25afe0d92..9110ac4bdbbf 100644 > --- a/drivers/tty/serial/qcom_geni_serial.c > +++ b/drivers/tty/serial/qcom_geni_serial.c > @@ -265,8 +265,8 @@ static bool qcom_geni_serial_secondary_active(struct uart_port *uport) > return readl(uport->membase + SE_GENI_STATUS) & S_GENI_CMD_ACTIVE; > } > > -static bool qcom_geni_serial_poll_bit(struct uart_port *uport, > - int offset, int field, bool set) > +static bool qcom_geni_serial_poll_bitfield(struct uart_port *uport, > + int offset, int field, u32 val) Can these be unsigned offset and field? > { > u32 reg; > struct qcom_geni_serial_port *port; > @@ -295,7 +295,7 @@ static bool qcom_geni_serial_poll_bit(struct uart_port *uport, > timeout_us = DIV_ROUND_UP(timeout_us, 10) * 10; > while (timeout_us) { > reg = readl(uport->membase + offset); > - if ((bool)(reg & field) == set) > + if ((reg & field) == val) > return true; > udelay(10); > timeout_us -= 10; > @@ -303,6 +303,12 @@ static bool qcom_geni_serial_poll_bit(struct uart_port *uport, > return false; > } > > +static bool qcom_geni_serial_poll_bit(struct uart_port *uport, > + int offset, int field, bool set) Can these be unsigned offset and field? > +{ > + return qcom_geni_serial_poll_bitfield(uport, offset, field, set ? field : 0); > +} > + > static void qcom_geni_serial_setup_tx(struct uart_port *uport, u32 xmit_size) > { > u32 m_cmd; > @@ -675,6 +681,31 @@ static void qcom_geni_serial_stop_tx_fifo(struct uart_port *uport) > if (!qcom_geni_serial_main_active(uport)) > return; > > + /* > + * Wait until the FIFO has been drained. We've already taken bytes out > + * of the higher level queue in qcom_geni_serial_send_chunk_fifo() so > + * if we don't drain the FIFO but send the "cancel" below they seem to > + * get lost. > + */ > + qcom_geni_serial_poll_bitfield(uport, SE_GENI_TX_FIFO_STATUS, TX_FIFO_WC, 0); > + > + /* > + * If we send the cancel immediately after the FIFO reports that it's > + * empty then bytes still seem to get lost. From trial and error, it > + * appears that a small delay here keeps bytes from being lost and > + * there is (apparently) no bit that we can poll instead of this. > + * Specifically it can be noted that the sequencer is still "active" > + * if it's waiting for us to send it more bytes from the current > + * transfer. > + */ > + mdelay(1); I wonder if the FIFO is in a different 1kb chunk of device memory and so this needs to be an instruction barrier (isb()) to prevent the cancel from being executed before or in parallel to the FIFO polling. Hopefully someone at qcom can confirm this. It looks like SE_GENI_TX_FIFO_STATUS is 0x800 offset and the cancel is at 0x600 so it looks like it may be this problem. Device memory doesn't save us even if that has ordered accesses :( > + > + /* > + * Cancel the current command. After this the main sequencer will > + * stop reporting that it's active and we'll have to start a new > + * transfer command. If the cancel doesn't take, we'll also send an > + * abort. > + */ > geni_se_cancel_m_cmd(&port->se); > if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS, > M_CMD_CANCEL_EN, true)) {