From nobody Thu Oct 2 16:57:26 2025 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 B6BC723BF96 for ; Sun, 14 Sep 2025 02:21:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757816508; cv=none; b=WYFpbwsYErE8G8e10D+c99CKgwqdoeChq8LeXzzLk5mjAmX3KDwJzMl1bNBXR2f45Pgo/MBzgPNgeJ5FTJkrqPFgt6j6lXZhXZbMvc+Ec9hq4b4aYtKYjkVYGhqVyovs6mI13gEVw9qqfad0IWCWYSGOuhwuPTIq7Fgg/DGnl7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757816508; c=relaxed/simple; bh=kS8JHpcfhYM5CdW9CB6tUor9f9vwCDwkONQoLHpHv6s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=P04YUNOW971SZGjx4H8rq3KPdX7tMtP9RfI2rn7xZsfuOAwG3HjwhFko3HGCG/K4yeS68own7Puvln+5VhT+fyzrI5SzGs8amiFWe5wRZ0hNV8mnR0sS9OKjPfOojyUzaFDOoE/EQL7cIaY4GUHTLfUkhPDnP4ZZVp6Y0E6Lkww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nXNQOL9l; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nXNQOL9l" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-b4f9d61e7deso1936724a12.2 for ; Sat, 13 Sep 2025 19:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757816506; x=1758421306; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MqdYb43+ykEUj742mo0iH3T4ooAsVFSgAqPeQX3wifY=; b=nXNQOL9lJIyPmLivfpjw89AdGKte0lgQ27JkFImHvIckSTUzDB+glOuS6UaPclGGC2 ERhHHEYsTIcnZF7upX03AuGF4DFkCZG9rHPczcy6BvVWAE/dg2Qsi19G1yaS+xm0D28t xail3/NNkVQQQpnOUutyr7Esq9RQx2uQrKTj6gZHN9wL6vZw+08zYRzGGaiyH7Mkisu8 XBXRa7WcGgW00JQ78xwPxE9yMaIx17rCPiQyMpxb3wdx7gwy5vJgW3Kj14wPXeA7rpv5 2H5+4yCD6dYB5DA+XcfvFdZs5o9DGXJeYeV4OeEEyxWpWiOhLWBB2asi3AuiuYAVku9G srnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757816506; x=1758421306; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MqdYb43+ykEUj742mo0iH3T4ooAsVFSgAqPeQX3wifY=; b=uWrmLfDNSntyGQbS7EzjP9pA03tJM3oIgOkC/1u92EhM/h8WinnwAnVutTZTQeK5yO JkXsYwQHs1wXhALveXKDzYpm5v0+1yVpF2g/bgjQ61m6DyM5qOY2KXcAYwBW/dzJIGcG vES7q3qpBzfY59416pLIZdltgqA1sQjnN1O2AHlW0ab+bXbngt051893ojQn5B8gGKtE t4vxMeYxOyYdaiwEFhyb5WvtzxYHbjFI7uxG+9x+U1JQBUQbbJyiodEisbQtzf2LUtUY 53QsckFErOJXE3ZBzvicAZSTp+fDBsZcGfVtdWH8UrTNeuGF3gjkrymsZ5EEut9+ydFU ZJ1g== X-Forwarded-Encrypted: i=1; AJvYcCXl5oAsxptuP1RAyrhQ3NDG7R1dl88Dyy9iZNLVfSyyp7xMpOhfV6g16f3qcHlOLh5E1Z74Uc5DnxHt/Vc=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9orf6I0P8edsnc7x1RTdr+7+RMcH5YKm8JRuYcIN7Nwq0vWu2 oQhCVy08zAuO6nYQt/WIE/ajQBcXszUyweVy6o++krrhgnUnHQn1cf/d X-Gm-Gg: ASbGnctD1gG1j0sL7jT3iGj6AtetfSwnawI7NcPP+pMFl7UQ7BH3w5NBW0ILGIoXkJg TGFrTI3sg+eHPhoq909P2nmK8//ctfR/SvPXP2oRV3LQ7jGeYWhufTA7PI5RsSGr3Z3reaXyG28 Gh9GMEZtrEIPhZpQVZPadRET5sRe9pP1/8Uo64wPlHeMAXNl6Sgg0swzPSOowobby6J9PYlGmxc o9dKGeSwUDFVcIiUwoJAOfL9tOFtK7qZMFIBMiMWyvEAMxUdEiQARQTyfQo3JA/VeWYmdSQCEvS 3tK9YmmpmtWqip9VYKjbEyHB6e+cR71O4zMvd6asDrkWe63GIhKPtTiO1zCgTWBhq+Og8vZ/VRt cGAHHRbovku62am7o58VagMueLjl/AjUdlA== X-Google-Smtp-Source: AGHT+IFoR2P5g3/f0mGeIuy3+0+zAJUbfdsUl2n3PtZNSOt3j4dOvKJKtvTfVzY7igk5GaUMCr6Mew== X-Received: by 2002:a17:903:1b4c:b0:24c:b2a4:7089 with SMTP id d9443c01a7336-25d26077175mr98369385ad.31.1757816505822; Sat, 13 Sep 2025 19:21:45 -0700 (PDT) Received: from fedora ([172.59.162.206]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-261d3dd0285sm27968685ad.8.2025.09.13.19.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Sep 2025 19:21:45 -0700 (PDT) From: Alex Tran To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Tran Subject: [PATCH v1] spi: spi-omap2-mcspi: fallback to PIO when DMA transfer fails Date: Sat, 13 Sep 2025 19:21:32 -0700 Message-ID: <20250914022132.319227-1-alex.t.tran@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add fallback to PIO mode when DMA preparation fails. Allows SPI transfers to complete successfully, even on a DMA preparation failure. Signed-off-by: Alex Tran --- drivers/spi/spi-omap2-mcspi.c | 46 +++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 6dc58a308..0b3b7ff0c 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -414,9 +414,8 @@ static void omap2_mcspi_tx_callback(void *data) complete(&mcspi_dma->dma_tx_completion); } =20 -static void omap2_mcspi_tx_dma(struct spi_device *spi, - struct spi_transfer *xfer, - struct dma_slave_config cfg) +static int omap2_mcspi_tx_dma(struct spi_device *spi, struct spi_transfer = *xfer, + struct dma_slave_config cfg) { struct omap2_mcspi *mcspi; struct omap2_mcspi_dma *mcspi_dma; @@ -436,13 +435,15 @@ static void omap2_mcspi_tx_dma(struct spi_device *spi, tx->callback_param =3D spi; dmaengine_submit(tx); } else { - /* FIXME: fall back to PIO? */ + dev_warn(mcspi->dev, "%s: failed to prepare DMA engine\n", __func__); + return -EINVAL; } dma_async_issue_pending(mcspi_dma->dma_tx); omap2_mcspi_set_dma_req(spi, 0, 1); + return 0; } =20 -static unsigned +static int omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, struct dma_slave_config cfg, unsigned es) @@ -522,7 +523,8 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_t= ransfer *xfer, tx->callback_param =3D spi; dmaengine_submit(tx); } else { - /* FIXME: fall back to PIO? */ + dev_warn(mcspi->dev, "%s: failed to prepare DMA engine\n", __func__); + return -EINVAL; } =20 dma_async_issue_pending(mcspi_dma->dma_rx); @@ -589,13 +591,13 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi= _transfer *xfer, return count; } =20 -static unsigned -omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) +static int omap2_mcspi_txrx_dma(struct spi_device *spi, + struct spi_transfer *xfer) { struct omap2_mcspi *mcspi; struct omap2_mcspi_cs *cs =3D spi->controller_state; struct omap2_mcspi_dma *mcspi_dma; - unsigned int count; + int count; u8 *rx; const u8 *tx; struct dma_slave_config cfg; @@ -642,13 +644,19 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct s= pi_transfer *xfer) mcspi_write_reg(spi->controller, OMAP2_MCSPI_IRQENABLE, OMAP2_MCSPI_IRQSTATUS_EOW); - omap2_mcspi_tx_dma(spi, xfer, cfg); + if (omap2_mcspi_tx_dma(spi, xfer, cfg) < 0) { + count =3D -EINVAL; + goto pio_fallback; + } } =20 - if (rx !=3D NULL) + if (rx) { count =3D omap2_mcspi_rx_dma(spi, xfer, cfg, es); + if (count < 0) + goto pio_fallback; + } =20 - if (tx !=3D NULL) { + if (tx) { int ret; =20 ret =3D mcspi_wait_for_completion(mcspi, &mcspi_dma->dma_tx_completion); @@ -695,6 +703,8 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi= _transfer *xfer) dev_err(&spi->dev, "EOT timed out\n"); } } + +pio_fallback: return count; } =20 @@ -1206,7 +1216,7 @@ static int omap2_mcspi_transfer_one(struct spi_contro= ller *ctlr, mcspi_write_chconf0(spi, chconf); =20 if (t->len) { - unsigned count; + int count; =20 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && spi_xfer_is_dma_mapped(ctlr, spi, t)) @@ -1220,10 +1230,16 @@ static int omap2_mcspi_transfer_one(struct spi_cont= roller *ctlr, + OMAP2_MCSPI_TX0); =20 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && - spi_xfer_is_dma_mapped(ctlr, spi, t)) + spi_xfer_is_dma_mapped(ctlr, spi, t)) { count =3D omap2_mcspi_txrx_dma(spi, t); - else + if (count < 0) { + dev_warn(mcspi->dev, + "%s: falling back to PIO\n", __func__); + count =3D omap2_mcspi_txrx_pio(spi, t); + } + } else { count =3D omap2_mcspi_txrx_pio(spi, t); + } =20 if (count !=3D t->len) { status =3D -EIO; --=20 2.51.0