From patchwork Tue Nov 21 09:09:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 10067763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 06E536038F for ; Tue, 21 Nov 2017 09:09:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E72A5287EB for ; Tue, 21 Nov 2017 09:09:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC11828FE3; Tue, 21 Nov 2017 09:09:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B212287EB for ; Tue, 21 Nov 2017 09:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751185AbdKUJJM (ORCPT ); Tue, 21 Nov 2017 04:09:12 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:46802 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750794AbdKUJJJ (ORCPT ); Tue, 21 Nov 2017 04:09:09 -0500 Received: by mail-lf0-f65.google.com with SMTP id g35so13193560lfi.13 for ; Tue, 21 Nov 2017 01:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ijN/eViynbhGMaFulwTxViTKSHYX17RBCl5i8990L48=; b=sOthv4S5jVs+lOUBu1vDWrx2b7qiYQjgtLjfasfEE0/3e4haleRoCqxV/VxM7JTRf4 Yycuc2BfCov5CJi9T6dOPmj+9u3rBIajxAei7qGbC5UsMdfPBHnE4U+uKGWep8DU1buN KbkJ6PPwKV93t4JOr+J+QyBrhdXoPYnPcWlg/QRa2F9nPp+uqDbC8geUPz+LDLVYlLig cod9IfATq7COY1r/gKmYl+q86EW5LeDvZ3YuP1QskgrX+WRJ5UibYBnfFmNJiko8c2yU Nh7WS+bJnnB83ebHVAFIDD3TOFzwkdAWxKVvy0kOX3FpCBZ+rkkEatlk4jIyb1fMXHcd KHzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ijN/eViynbhGMaFulwTxViTKSHYX17RBCl5i8990L48=; b=sCfTRy/Z+cnSqoMfRq5m2NhwB8NZWS68wW+54ZW9SD2Fhd81xvdrvDIyl+w7KH8WrM Pn51uArROcO8KUQT2QPJUtZ7kYE0sONXapT7B6wtE6ss/3fnObF8Zh+ZeGc2mEMCzJ3J BXQsoBBunurGudBwaRp6lT7Jjg9wHylQyuF536u2SjDO12J8QMrHeNWhylNDaIok0zFU NgOLPb4f9rrsaGdbbCRBSk+s9r9TWfwwC1HwF9FOLbWMnQwIurgJtoaU+A9cEBoa3UGC ZYldEqVhmOQuNySc2OwwNtUVptf4FvBNu5FW7+uTgFp1GyKx2fCHHnGwe+Z/2K2Kh2Gs 8sSg== X-Gm-Message-State: AJaThX5ko95S6Da3UeepHCVQrLKw8tiUojEoJyw3SvsJpVbOTpwgeEma 01O9Pa+NrXKSLZImmWe4BEE8Yxzq X-Google-Smtp-Source: AGs4zMYTfSFVgHD/GW1zR1JPbf7onan8W+TQqsRMpdfHcdjYf9Htwcd7TRZEHD9tVqARLCXgT6tNfQ== X-Received: by 10.46.65.66 with SMTP id o63mr5550879lja.172.1511255347520; Tue, 21 Nov 2017 01:09:07 -0800 (PST) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id x20sm2997214ljd.88.2017.11.21.01.09.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 01:09:05 -0800 (PST) From: Ricardo Ribalda Delgado To: linux-spi@vger.kernel.org Cc: Ricardo Ribalda Delgado , Mark Brown , Lars-Peter Clausen Subject: [PATCH 1/3] spi: xilinx: Detect stall with Unknown commands Date: Tue, 21 Nov 2017 10:09:02 +0100 Message-Id: <20171121090904.6901-1-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.15.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the core is configured in C_SPI_MODE > 0, it integrates a lookup table that automatically configures the core in dual or quad mode based on the command (first byte on the tx fifo). Unfortunately, that list mode_?_memoy_*.mif does not contain all the supported commands by the flash. Since 4.14 spi-nor automatically tries to probe the flash using SFDP (command 0x5a), and that command is not part of the list_mode table. Whit the right combination of C_SPI_MODE and C_SPI_MEMORY this leads into a stall that can only be recovered with a soft rest. This patch detects this kind of stall and returns -EIO to the caller on those commands. spi-nor can handle this error properly: m25p80 spi0.0: Detected stall. Check C_SPI_MODE and C_SPI_MEMORY. 0x21 0x2404 m25p80 spi0.0: SPI transfer failed: -5 spi_master spi0: failed to transfer one message from queue m25p80 spi0.0: s25sl064p (8192 Kbytes) Cc: Mark Brown Cc: Lars-Peter Clausen Signed-off-by: Ricardo Ribalda Delgado --- drivers/spi/spi-xilinx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c index bc7100b93dfc..e0b9fe1d0e37 100644 --- a/drivers/spi/spi-xilinx.c +++ b/drivers/spi/spi-xilinx.c @@ -271,6 +271,7 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) while (remaining_words) { int n_words, tx_words, rx_words; u32 sr; + int stalled; n_words = min(remaining_words, xspi->buffer_size); @@ -299,7 +300,17 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) /* Read out all the data from the Rx FIFO */ rx_words = n_words; + stalled = 10; while (rx_words) { + if (rx_words == n_words && !(stalled--) && + !(sr & XSPI_SR_TX_EMPTY_MASK) && + (sr & XSPI_SR_RX_EMPTY_MASK)) { + dev_err(&spi->dev, + "Detected stall. Check C_SPI_MODE and C_SPI_MEMORY\n"); + xspi_init_hw(xspi); + return -EIO; + } + if ((sr & XSPI_SR_TX_EMPTY_MASK) && (rx_words > 1)) { xilinx_spi_rx(xspi); rx_words--;