From owner-freebsd-embedded@FreeBSD.ORG Wed Nov 13 22:32:46 2013 Return-Path: Delivered-To: freebsd-embedded@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EA0EF4D6; Wed, 13 Nov 2013 22:32:46 +0000 (UTC) Received: from venus.codepro.be (venus.codepro.be [IPv6:2a01:4f8:162:1127::2]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AD2BB25CD; Wed, 13 Nov 2013 22:32:46 +0000 (UTC) Received: from adrastea.jupiter.sigsegv.be (unknown [IPv6:2a02:1811:2000:701:1b:9fff:fe00:160b]) by venus.codepro.be (Postfix) with ESMTPSA id 5329B9B2F; Wed, 13 Nov 2013 23:32:44 +0100 (CET) Received: from sigsegv.be (unknown [10.0.2.251]) by adrastea.jupiter.sigsegv.be (Postfix) with ESMTP id 3E8A34163; Wed, 13 Nov 2013 23:32:43 +0100 (CET) From: kristof@sigsegv.be To: Ian Lepore Subject: [PATCH 5/5] Rework the routine that returns a pointer to the table of software ECC byte positions within the OOB area to support chips with unusual OOB sizes such as 218 or 224 bytes (the table for 128 byte OOB works for these but it assumes 3 bytes of ECC per 256 byte block, and in the case of an ONFI chip the params page may ask for something different). Date: Wed, 13 Nov 2013 23:32:40 +0100 Message-Id: <1384381960-98851-6-git-send-email-kristof@sigsegv.be> X-Mailer: git-send-email 1.7.10.3 In-Reply-To: <1384381960-98851-1-git-send-email-kristof@sigsegv.be> References: <1383782353.31172.183.camel@revolution.hippie.lan> <1384381960-98851-1-git-send-email-kristof@sigsegv.be> Cc: Grzegorz Bernacki , freebsd-embedded@FreeBSD.org X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Nov 2013 22:32:47 -0000 From: Kristof Provost --- sys/dev/nand/nand.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/sys/dev/nand/nand.c b/sys/dev/nand/nand.c index 902ff79..fb83e67 100644 --- a/sys/dev/nand/nand.c +++ b/sys/dev/nand/nand.c @@ -309,23 +309,22 @@ nand_get_chip_param(struct nand_chip *chip, struct chip_param_io *param) static uint16_t * default_software_ecc_positions(struct nand_chip *chip) { - struct nand_ecc_data *eccd; - - eccd = &chip->nand->ecc; - - if (eccd->eccpositions) - return (eccd->eccpositions); - - switch (chip->chip_geom.oob_size) { - case 16: - return ((uint16_t *)&default_software_ecc_positions_16); - case 64: - return ((uint16_t *)&default_software_ecc_positions_64); - case 128: - return ((uint16_t *)&default_software_ecc_positions_128); - default: - return (NULL); /* No ecc bytes positions defs available */ - } + /* If positions have been set already, use them. */ + if (chip->nand->ecc.eccpositions) + return (chip->nand->ecc.eccpositions); + + /* + * XXX Note that the following logic isn't really sufficient, especially + * in the ONFI case where the number of ECC bytes can be dictated by + * values in the parameters page, and that could lead to needing more + * byte positions than exist within the tables of software-ecc defaults. + */ + if (chip->chip_geom.oob_size >= 128) + return (default_software_ecc_positions_128); + if (chip->chip_geom.oob_size >= 64) + return (default_software_ecc_positions_64); + else if (chip->chip_geom.oob_size >= 16) + return (default_software_ecc_positions_16); return (NULL); } -- 1.7.10.3