Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7323785yba; Thu, 2 May 2019 08:03:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAzTYYx9Nl9SBtF2MuOfmc58FqK6OR7aM5EXbqio7bZ745QKjTzQYKE2QByRYhzTfb/so/ X-Received: by 2002:a17:902:6ac6:: with SMTP id i6mr4252924plt.313.1556809401999; Thu, 02 May 2019 08:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556809401; cv=none; d=google.com; s=arc-20160816; b=snZMHyaZCVPG2E8+7vToSOYELG7U/fvqhmK07NtNK8ykl3yulKnPfuM2YnGBCPGzQJ 6b+yzQXSXhGzItzMfYtxvCSXCvUFW0OCwOYz9D4uj0Kkwac9t+q7e9RdXe4QdMY+EtEC Fy46Y1llHKuk8VsHGMmcULOwRC6bNMdqPznrUylgaOntnShgJdGmvnMd6jHqdVPiobPB Z212vmilqPwv9L3vCJn6m9iocn+6TawIgvQ5tx6Psn32rL3JRoU9WKGzdU0hme0ptjli sdoPv/WUgBlNxQAcp73Jyhw8h0jSRMLsz8cbIr7UxyitfooSeRzvbcTZiMC+a05H7O4Z xl/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=UuMFcOk4PKj91APfBr8006g4N2giQ/z6xm9K7QOYvPU=; b=ibrA/J19dzWgM0sEgfX+EmnOeYWAYI+wg572T3U4kQz4O8wPhTVzruMzFw9PXFkZa1 Ij1P5cw2ChITYfFQ8I/W8x2GFsaVRcE0pvH1vD3zg8iE8V0aFdbm/0QAV57A+PHtN1zK PIr8p4lfZsLwnsNLt4NXz+/FsvXY8jpPuzkWH+ovStfRLVHdH3iO4Oq4GOfIDKZy4CFW N0RHi0FTXxxFbLYhOXIHwt6cD+GJZgKQd0NCz+DpLznFOgrhBj3nQoh4akEZj7xJ0dca WVEkDhennxn0C3qHpauotuLpgkcoVY+Ywxzvu+ZbZbbhUj6ckrQIFMJAXWmTI1Xc+aGR JzSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RyhiUhGM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o186si1588778pgo.423.2019.05.02.08.03.03; Thu, 02 May 2019 08:03:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RyhiUhGM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726450AbfEBPB3 (ORCPT + 99 others); Thu, 2 May 2019 11:01:29 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41699 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbfEBPB0 (ORCPT ); Thu, 2 May 2019 11:01:26 -0400 Received: by mail-pg1-f195.google.com with SMTP id f6so1182657pgs.8 for ; Thu, 02 May 2019 08:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=UuMFcOk4PKj91APfBr8006g4N2giQ/z6xm9K7QOYvPU=; b=RyhiUhGMu/07Fiptheef7l3Im7ZUgKwPpMGS171+3DfjyFghriz8AOvRTi8Me4ogUb 5CDP5WtPupbfM5B0sODlecbeWn0+sDne5D+oprjQzCmrQwCx3oZHRp9+bKcQCBxlOyuK mT49R5DO+VPww+b/sKHXtQL8oDw/pvjKN8zcuitbVaLHAIGPfEv7mVB3lY3bpFfJq+Mq v9h9NoX2vL5P+ugHDTfKE5/6Fi/Undu5B1Dmq0AJ4FNV12IzcZaTIB9dhe2E4KCV+Bg7 PDJJeYJAWaSL9/rdUNI7JYv8UcjtwGMqXUHaA61fFxQlkNwMnKC5k/iUotEXsQSOTTKj g37Q== 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=UuMFcOk4PKj91APfBr8006g4N2giQ/z6xm9K7QOYvPU=; b=tYhdDvbLnpOZt9+W0fq474yBN3CvEtM3/rhmg9OhdwrYRgpEXiSEjoOHMtSdXg+msb SpSrpV8J4yQVmD46JaU8VWc047dbwH6A56Wrq2ypHe/+Vi1Uw6/NZxJkcrLkT5o4cp0t 0Vny4NDleQs1YhF4WYIF3jeR11pGi+QBuKTbLnyAeG/xDlgr8DNWQTvvfk5USBV23Rp3 rI2+GDJNloU3TwwSQl+hnachK28893C7V4eCETkXCaJonF9OFUXx3kwxIyyu1oMAKgOv mTO7jRAZG4ROJY2s1lZzHnBCjDHIDQ3n0GtFihXTZeGzmUt2oaoFublTZWDVac32gBfX V32A== X-Gm-Message-State: APjAAAXJFTb0UCWfS8Esvv5luFIT4OchDHwPjbEb3Drri+Zmv0Uyg3E1 dUmfKokmnkBsRdyBtCmvW14= X-Received: by 2002:a63:9214:: with SMTP id o20mr4452130pgd.203.1556809285953; Thu, 02 May 2019 08:01:25 -0700 (PDT) Received: from mail.broadcom.com ([192.19.231.250]) by smtp.gmail.com with ESMTPSA id o15sm21581450pgb.85.2019.05.02.08.01.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 May 2019 08:01:25 -0700 (PDT) From: Kamal Dasu To: linux-mtd@lists.infradead.org Cc: bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, Kamal Dasu , Brian Norris , Boris Brezillon , Miquel Raynal , Richard Weinberger , David Woodhouse , Marek Vasut Subject: [PATCH v2] mtd: nand: raw: brcmnand: When oops in progress use pio and interrupt polling Date: Thu, 2 May 2019 11:01:01 -0400 Message-Id: <1556809273-40009-1-git-send-email-kdasu.kdev@gmail.com> X-Mailer: git-send-email 1.9.0.138.g2de3478 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If mtd_oops is in progress, switch to polling during NAND command completion instead of relying on DMA/interrupts so that the mtd_oops buffer can be completely written in the assigned NAND partition. This is needed in cases where and there is only one online CPU and the panic is not on cpu0 as all IRQs are wired to cpu0. Signed-off-by: Kamal Dasu --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 55 ++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 482c6f0..128a806 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -823,6 +823,12 @@ static inline bool has_flash_dma(struct brcmnand_controller *ctrl) return ctrl->flash_dma_base; } +static inline void disable_flash_dma_xfer(struct brcmnand_controller *ctrl) +{ + if (has_flash_dma(ctrl)) + ctrl->flash_dma_base = 0; +} + static inline bool flash_dma_buf_ok(const void *buf) { return buf && !is_vmalloc_addr(buf) && @@ -1237,15 +1243,58 @@ static void brcmnand_cmd_ctrl(struct nand_chip *chip, int dat, /* intentionally left blank */ } +static bool is_mtd_oops_in_progress(void) +{ + int i = 0; + +#ifdef CONFIG_MTD_OOPS + if (oops_in_progress && smp_processor_id()) { + int cpu = 0; + + for_each_online_cpu(cpu) + ++i; + } +#endif + return (i == 1); +} + +static bool brcmstb_nand_wait_for_completion(struct nand_chip *chip) +{ + struct brcmnand_host *host = nand_get_controller_data(chip); + struct brcmnand_controller *ctrl = host->ctrl; + bool err = false; + int sts; + + if (is_mtd_oops_in_progress()) { + /* Switch to interrupt polling and PIO mode */ + disable_flash_dma_xfer(ctrl); + sts = bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY | + NAND_STATUS_READY, + NAND_CTRL_RDY | + NAND_STATUS_READY, 0); + err = (sts < 0) ? true : false; + } else { + unsigned long timeo = msecs_to_jiffies( + NAND_POLL_STATUS_TIMEOUT_MS); + /* wait for completion interrupt */ + sts = wait_for_completion_timeout(&ctrl->done, timeo); + err = (sts <= 0) ? true : false; + } + + return err; +} + static int brcmnand_waitfunc(struct nand_chip *chip) { struct brcmnand_host *host = nand_get_controller_data(chip); struct brcmnand_controller *ctrl = host->ctrl; - unsigned long timeo = msecs_to_jiffies(100); + bool err = false; dev_dbg(ctrl->dev, "wait on native cmd %d\n", ctrl->cmd_pending); - if (ctrl->cmd_pending && - wait_for_completion_timeout(&ctrl->done, timeo) <= 0) { + if (ctrl->cmd_pending) + err = brcmstb_nand_wait_for_completion(chip); + + if (err) { u32 cmd = brcmnand_read_reg(ctrl, BRCMNAND_CMD_START) >> brcmnand_cmd_shift(ctrl); -- 1.9.0.138.g2de3478