From patchwork Thu May 1 09:56:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29468 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5F7F0203F3 for ; Thu, 1 May 2014 09:58:01 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id vb8sf15322225obc.3 for ; Thu, 01 May 2014 02:58:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=li+fv3MAq+9WDm+itNHB7+O2AKYtWESTI2KNvoSJ9aQ=; b=NBIxlNdTU7fl/6Td/3qKlbF+cQLdIT3HnC6bVQTM86MyfzA+fRx62vxOPzGnuKR6VR +3IPqyvInsRNQxuXyhPbluicuvk7d/ZzL6gjyCFtjQTtID1Y3SRS9/vtn9MV99j437GG CXkLhBrpnbI6HZXuIZsamXoxexyViTxSQvSkreA+ziQdKGnLFdrfIoz2ySGZZHk120Cl NIMCPp5FFOU9iuzO4+LDWniRn/mO3IZQXyYrF1fD1s6lazKMfC/m+VzVzu/2Eaan3TTj t52ytfOM0CFM9Z0Tww2JxjyTl4WtziEFPYb6AzwWABWa2jSnzwxMNnk4JJMdJh+b6cYU ZohQ== X-Gm-Message-State: ALoCoQlw+P2GPs5xYQ3f8+uVjpwoatXcpHUpBw3kTdOG/TVyVcdnr6/stZe5Cgbu8mp7EHNjB6Il X-Received: by 10.182.158.135 with SMTP id wu7mr5169075obb.19.1398938280885; Thu, 01 May 2014 02:58:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.87 with SMTP id v81ls1181197qge.0.gmail; Thu, 01 May 2014 02:58:00 -0700 (PDT) X-Received: by 10.58.31.136 with SMTP id a8mr8423315vei.20.1398938280790; Thu, 01 May 2014 02:58:00 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id tx7si5959017vcb.116.2014.05.01.02.58.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:00 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id im17so3799566vcb.28 for ; Thu, 01 May 2014 02:58:00 -0700 (PDT) X-Received: by 10.52.166.102 with SMTP id zf6mr6834125vdb.2.1398938280723; Thu, 01 May 2014 02:58:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp12941vcb; Thu, 1 May 2014 02:58:00 -0700 (PDT) X-Received: by 10.180.212.107 with SMTP id nj11mr1553233wic.40.1398938279943; Thu, 01 May 2014 02:57:59 -0700 (PDT) Received: from mail-we0-f173.google.com (mail-we0-f173.google.com [74.125.82.173]) by mx.google.com with ESMTPS id yx6si10555558wjc.0.2014.05.01.02.57.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:59 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=74.125.82.173; Received: by mail-we0-f173.google.com with SMTP id w61so2847389wes.18 for ; Thu, 01 May 2014 02:57:59 -0700 (PDT) X-Received: by 10.180.38.107 with SMTP id f11mr1459215wik.31.1398938279342; Thu, 01 May 2014 02:57:59 -0700 (PDT) Received: from lee--X1.home (host109-148-238-223.range109-148.btcentralplus.com. [109.148.238.223]) by mx.google.com with ESMTPSA id bj5sm2696494wib.3.2014.05.01.02.57.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:58 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, linux-mtd@lists.infradead.org, kernel@stlinux.com, Lee Jones Subject: [PATCH 25/47] mtd: nand: stm_nand_bch: provide read functionality (BCH) Date: Thu, 1 May 2014 10:56:32 +0100 Message-Id: <1398938214-17847-26-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> References: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Use DMA to read a single page of data. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 2ff72c9..72c9734 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -512,6 +513,99 @@ static int check_erased_page(uint8_t *data, uint32_t page_size, int max_zeros) return zeros; } +/* Returns the number of ECC errors, or '-1' for uncorrectable error */ +static int bch_read_page(struct nandi_controller *nandi, + loff_t offs, + uint8_t *buf) +{ + struct bch_prog *prog = &bch_prog_read_page; + uint32_t page_size = nandi->info.mtd.writesize; + unsigned long list_phys; + unsigned long buf_phys; + uint32_t ecc_err; + int ret = 0; + + dev_dbg(nandi->dev, "%s: offs = 0x%012llx\n", __func__, offs); + + BUG_ON(offs & (NANDI_BCH_DMA_ALIGNMENT - 1)); + + emiss_nandi_select(STM_NANDI_BCH); + + nandi_enable_interrupts(nandi, NANDBCH_INT_SEQNODESOVER); + reinit_completion(&nandi->seq_completed); + + /* Reset ECC stats */ + writel(CFG_RESET_ECC_ALL | CFG_ENABLE_AFM, + nandi->base + NANDBCH_CONTROLLER_CFG); + writel(CFG_ENABLE_AFM, nandi->base + NANDBCH_CONTROLLER_CFG); + + prog->addr = (uint32_t)((offs >> (nandi->page_shift - 8)) & 0xffffff00); + + buf_phys = dma_map_single(NULL, buf, page_size, DMA_FROM_DEVICE); + + memset(nandi->buf_list, 0x00, NANDI_BCH_BUF_LIST_SIZE); + nandi->buf_list[0] = buf_phys | (nandi->sectors_per_page - 1); + + list_phys = dma_map_single(NULL, nandi->buf_list, + NANDI_BCH_BUF_LIST_SIZE, DMA_TO_DEVICE); + + writel(list_phys, nandi->base + NANDBCH_BUFFER_LIST_PTR); + + bch_load_prog_cpu(nandi, prog); + + bch_wait_seq(nandi); + + nandi_disable_interrupts(nandi, NANDBCH_INT_SEQNODESOVER); + + dma_unmap_single(NULL, list_phys, NANDI_BCH_BUF_LIST_SIZE, + DMA_TO_DEVICE); + dma_unmap_single(NULL, buf_phys, page_size, DMA_FROM_DEVICE); + + /* Use the maximum per-sector ECC count! */ + ecc_err = readl(nandi->base + NANDBCH_ECC_SCORE_REG_A) & 0xff; + if (ecc_err == 0xff) { + /* + * Downgrade uncorrectable ECC error for an erased page, + * tolerating 'bitflip_threshold' bits at zero. + */ + ret = check_erased_page(buf, page_size, + nandi->bitflip_threshold); + if (ret >= 0) + dev_dbg(nandi->dev, + "%s: erased page detected: \n" + " downgrading uncorrectable ECC error.\n", + __func__); + } else { + ret = (int)ecc_err; + } + + return ret; +} + +static int bch_read(struct mtd_info *mtd, struct nand_chip *chip, + uint8_t *buf, int oob_required, int page) +{ + struct nandi_controller *nandi = chip->priv; + uint32_t page_size = mtd->writesize; + loff_t offs = page * page_size; + bool bounce = false; + uint8_t *p; + int ret; + + if (((unsigned int)buf & (NANDI_BCH_DMA_ALIGNMENT - 1)) || + (!virt_addr_valid(buf))) /* vmalloc'd buffer! */ + bounce = true; + + p = bounce ? nandi->page_buf : buf; + + ret = bch_read_page(nandi, offs, p); + + if (bounce) + memcpy(buf, p, page_size); + + return ret; +} + /* * Initialisation */ @@ -590,6 +684,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, mtd->flags = MTD_CAP_NANDFLASH; mtd->ecclayout = &info->ecclayout; mtd->subpage_sft = 0; + + chip->ecc.read_page = bch_read; } /*