110-mtd-move-nand_ecc_ctrl-init.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From 3282055a7d0a304d541dbdbe2e32167e1a2f117c Mon Sep 17 00:00:00 2001
  2. From: Boris BREZILLON <boris.brezillon@free-electrons.com>
  3. Date: Mon, 28 Jul 2014 14:20:54 +0200
  4. Subject: [PATCH] mtd: nand: Take nand_ecc_ctrl initialization out of
  5. nand_scan_tail
  6. Take ECC initialization code portion out of nand_scan_tail so that we can
  7. re-use this implementation.
  8. This commit only moves some code around and makes no functional changes.
  9. Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
  10. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  11. ---
  12. drivers/mtd/nand/nand_base.c | 91 +++++++++++++++++++++++++++-----------------
  13. 1 file changed, 56 insertions(+), 35 deletions(-)
  14. --- a/drivers/mtd/nand/nand_base.c
  15. +++ b/drivers/mtd/nand/nand_base.c
  16. @@ -3892,42 +3892,15 @@ static bool nand_ecc_strength_good(struc
  17. return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds;
  18. }
  19. -/**
  20. - * nand_scan_tail - [NAND Interface] Scan for the NAND device
  21. - * @mtd: MTD device structure
  22. - *
  23. - * This is the second phase of the normal nand_scan() function. It fills out
  24. - * all the uninitialized function pointers with the defaults and scans for a
  25. - * bad block table if appropriate.
  26. +/*
  27. + * Initialize ECC struct:
  28. + * - fill ECC struct with default function/values when these ones are undefined
  29. + * - fill ECC infos based on MTD device
  30. */
  31. -int nand_scan_tail(struct mtd_info *mtd)
  32. +static int nand_ecc_ctrl_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc)
  33. {
  34. int i;
  35. - struct nand_chip *chip = mtd->priv;
  36. - struct nand_ecc_ctrl *ecc = &chip->ecc;
  37. - struct nand_buffers *nbuf;
  38. - /* New bad blocks should be marked in OOB, flash-based BBT, or both */
  39. - BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
  40. - !(chip->bbt_options & NAND_BBT_USE_FLASH));
  41. -
  42. - if (!(chip->options & NAND_OWN_BUFFERS)) {
  43. - nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
  44. - + mtd->oobsize * 3, GFP_KERNEL);
  45. - if (!nbuf)
  46. - return -ENOMEM;
  47. - nbuf->ecccalc = (uint8_t *)(nbuf + 1);
  48. - nbuf->ecccode = nbuf->ecccalc + mtd->oobsize;
  49. - nbuf->databuf = nbuf->ecccode + mtd->oobsize;
  50. -
  51. - chip->buffers = nbuf;
  52. - } else {
  53. - if (!chip->buffers)
  54. - return -ENOMEM;
  55. - }
  56. -
  57. - /* Set the internal oob buffer location, just after the page data */
  58. - chip->oob_poi = chip->buffers->databuf + mtd->writesize;
  59. /*
  60. * If no default placement scheme is given, select an appropriate one.
  61. @@ -3953,9 +3926,6 @@ int nand_scan_tail(struct mtd_info *mtd)
  62. }
  63. }
  64. - if (!chip->write_page)
  65. - chip->write_page = nand_write_page;
  66. -
  67. /*
  68. * Check ECC mode, default to software if 3byte/512byte hardware ECC is
  69. * selected and we have 256 byte pagesize fallback to software ECC
  70. @@ -4125,6 +4095,57 @@ int nand_scan_tail(struct mtd_info *mtd)
  71. }
  72. ecc->total = ecc->steps * ecc->bytes;
  73. + return 0;
  74. +}
  75. +
  76. +/**
  77. + * nand_scan_tail - [NAND Interface] Scan for the NAND device
  78. + * @mtd: MTD device structure
  79. + *
  80. + * This is the second phase of the normal nand_scan() function. It fills out
  81. + * all the uninitialized function pointers with the defaults and scans for a
  82. + * bad block table if appropriate.
  83. + */
  84. +int nand_scan_tail(struct mtd_info *mtd)
  85. +{
  86. + int ret;
  87. + struct nand_chip *chip = mtd->priv;
  88. + struct nand_ecc_ctrl *ecc = &chip->ecc;
  89. + struct nand_buffers *nbuf;
  90. +
  91. + /* New bad blocks should be marked in OOB, flash-based BBT, or both */
  92. + BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
  93. + !(chip->bbt_options & NAND_BBT_USE_FLASH));
  94. +
  95. + if (!(chip->options & NAND_OWN_BUFFERS)) {
  96. + nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
  97. + + mtd->oobsize * 3, GFP_KERNEL);
  98. + if (!nbuf)
  99. + return -ENOMEM;
  100. + nbuf->ecccalc = (uint8_t *)(nbuf + 1);
  101. + nbuf->ecccode = nbuf->ecccalc + mtd->oobsize;
  102. + nbuf->databuf = nbuf->ecccode + mtd->oobsize;
  103. + chip->buffers = nbuf;
  104. + } else {
  105. + if (!chip->buffers)
  106. + return -ENOMEM;
  107. + }
  108. +
  109. + /* Set the internal oob buffer location, just after the page data */
  110. + chip->oob_poi = chip->buffers->databuf + mtd->writesize;
  111. +
  112. + if (!chip->write_page)
  113. + chip->write_page = nand_write_page;
  114. +
  115. + /* Initialize ECC struct */
  116. + ret = nand_ecc_ctrl_init(mtd, ecc);
  117. + if (ret) {
  118. + if (!(chip->options & NAND_OWN_BUFFERS))
  119. + kfree(chip->buffers);
  120. +
  121. + return ret;
  122. + }
  123. +
  124. /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
  125. if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) {
  126. switch (ecc->steps) {