Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mtd: rawnand: sunxi: Replace hard coded value by a define

The user data length (4) used all over the code hard coded.
And sometimes, it's not that trivial to know that it's the user data
length and not something else.
Moreover, for the H6/H616 this value is no more fixed by hardware, but
could be modified.

Using a define here makes the code more readable.

Suggested-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Richard Genoud <richard.genoud@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

authored by

Richard Genoud and committed by
Miquel Raynal
1be7ac78 deaa77ed

+37 -26
+37 -26
drivers/mtd/nand/raw/sunxi_nand.c
··· 157 157 158 158 #define NFC_MAX_CS 7 159 159 160 + /* 161 + * On A10/A23, this is the size of the NDFC User Data Register, containing the 162 + * mandatory user data bytes following the ECC for each ECC step. 163 + * Thus, for each ECC step, we need the ECC bytes + USER_DATA_SZ. 164 + * Those bits are currently unsused, and kept as default value 0xffffffff. 165 + * 166 + * On H6/H616, this size became configurable, from 0 bytes to 32, via the 167 + * USER_DATA_LEN registers. 168 + */ 169 + #define USER_DATA_SZ 4 170 + 160 171 /** 161 172 * struct sunxi_nand_chip_sel - stores information related to NAND Chip Select 162 173 * ··· 740 729 bool bbm, int page) 741 730 { 742 731 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 743 - u8 user_data[4]; 732 + u8 user_data[USER_DATA_SZ]; 744 733 745 734 /* Randomize the Bad Block Marker. */ 746 735 if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) { ··· 792 781 memset(data, pattern, ecc->size); 793 782 794 783 if (oob) 795 - memset(oob, pattern, ecc->bytes + 4); 784 + memset(oob, pattern, ecc->bytes + USER_DATA_SZ); 796 785 797 786 return 0; 798 787 } ··· 837 826 if (ret) 838 827 return ret; 839 828 840 - *cur_off = oob_off + ecc->bytes + 4; 829 + *cur_off = oob_off + ecc->bytes + USER_DATA_SZ; 841 830 842 831 ret = sunxi_nfc_hw_ecc_correct(nand, data, oob_required ? oob : NULL, 0, 843 832 readl(nfc->regs + NFC_REG_ECC_ST), ··· 857 846 memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, 858 847 ecc->size); 859 848 860 - nand_change_read_column_op(nand, oob_off, oob, ecc->bytes + 4, 861 - false); 849 + nand_change_read_column_op(nand, oob_off, oob, 850 + ecc->bytes + USER_DATA_SZ, false); 862 851 863 - ret = nand_check_erased_ecc_chunk(data, ecc->size, 864 - oob, ecc->bytes + 4, 852 + ret = nand_check_erased_ecc_chunk(data, ecc->size, oob, 853 + ecc->bytes + USER_DATA_SZ, 865 854 NULL, 0, ecc->strength); 866 855 if (ret >= 0) 867 856 raw_mode = 1; ··· 871 860 if (oob_required) { 872 861 nand_change_read_column_op(nand, oob_off, NULL, 0, 873 862 false); 874 - sunxi_nfc_randomizer_read_buf(nand, oob, ecc->bytes + 4, 863 + sunxi_nfc_randomizer_read_buf(nand, oob, ecc->bytes + USER_DATA_SZ, 875 864 true, page); 876 865 877 866 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, 0, ··· 965 954 966 955 for (i = 0; i < nchunks; i++) { 967 956 int data_off = i * ecc->size; 968 - int oob_off = i * (ecc->bytes + 4); 957 + int oob_off = i * (ecc->bytes + USER_DATA_SZ); 969 958 u8 *data = buf + data_off; 970 959 u8 *oob = nand->oob_poi + oob_off; 971 960 bool erased; ··· 982 971 /* TODO: use DMA to retrieve OOB */ 983 972 nand_change_read_column_op(nand, 984 973 mtd->writesize + oob_off, 985 - oob, ecc->bytes + 4, false); 974 + oob, ecc->bytes + USER_DATA_SZ, false); 986 975 987 976 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, i, 988 977 !i, page); ··· 997 986 if (status & NFC_ECC_ERR_MSK) { 998 987 for (i = 0; i < nchunks; i++) { 999 988 int data_off = i * ecc->size; 1000 - int oob_off = i * (ecc->bytes + 4); 989 + int oob_off = i * (ecc->bytes + USER_DATA_SZ); 1001 990 u8 *data = buf + data_off; 1002 991 u8 *oob = nand->oob_poi + oob_off; 1003 992 ··· 1017 1006 /* TODO: use DMA to retrieve OOB */ 1018 1007 nand_change_read_column_op(nand, 1019 1008 mtd->writesize + oob_off, 1020 - oob, ecc->bytes + 4, false); 1009 + oob, ecc->bytes + USER_DATA_SZ, false); 1021 1010 1022 - ret = nand_check_erased_ecc_chunk(data, ecc->size, 1023 - oob, ecc->bytes + 4, 1011 + ret = nand_check_erased_ecc_chunk(data, ecc->size, oob, 1012 + ecc->bytes + USER_DATA_SZ, 1024 1013 NULL, 0, 1025 1014 ecc->strength); 1026 1015 if (ret >= 0) ··· 1073 1062 if (ret) 1074 1063 return ret; 1075 1064 1076 - *cur_off = oob_off + ecc->bytes + 4; 1065 + *cur_off = oob_off + ecc->bytes + USER_DATA_SZ; 1077 1066 1078 1067 return 0; 1079 1068 } ··· 1084 1073 { 1085 1074 struct mtd_info *mtd = nand_to_mtd(nand); 1086 1075 struct nand_ecc_ctrl *ecc = &nand->ecc; 1087 - int offset = ((ecc->bytes + 4) * ecc->steps); 1076 + int offset = ((ecc->bytes + USER_DATA_SZ) * ecc->steps); 1088 1077 int len = mtd->oobsize - offset; 1089 1078 1090 1079 if (len <= 0) ··· 1117 1106 1118 1107 for (i = 0; i < ecc->steps; i++) { 1119 1108 int data_off = i * ecc->size; 1120 - int oob_off = i * (ecc->bytes + 4); 1109 + int oob_off = i * (ecc->bytes + USER_DATA_SZ); 1121 1110 u8 *data = buf + data_off; 1122 1111 u8 *oob = nand->oob_poi + oob_off; 1123 1112 ··· 1176 1165 for (i = data_offs / ecc->size; 1177 1166 i < DIV_ROUND_UP(data_offs + readlen, ecc->size); i++) { 1178 1167 int data_off = i * ecc->size; 1179 - int oob_off = i * (ecc->bytes + 4); 1168 + int oob_off = i * (ecc->bytes + USER_DATA_SZ); 1180 1169 u8 *data = bufpoi + data_off; 1181 1170 u8 *oob = nand->oob_poi + oob_off; 1182 1171 ··· 1230 1219 1231 1220 for (i = 0; i < ecc->steps; i++) { 1232 1221 int data_off = i * ecc->size; 1233 - int oob_off = i * (ecc->bytes + 4); 1222 + int oob_off = i * (ecc->bytes + USER_DATA_SZ); 1234 1223 const u8 *data = buf + data_off; 1235 1224 const u8 *oob = nand->oob_poi + oob_off; 1236 1225 ··· 1268 1257 for (i = data_offs / ecc->size; 1269 1258 i < DIV_ROUND_UP(data_offs + data_len, ecc->size); i++) { 1270 1259 int data_off = i * ecc->size; 1271 - int oob_off = i * (ecc->bytes + 4); 1260 + int oob_off = i * (ecc->bytes + USER_DATA_SZ); 1272 1261 const u8 *data = buf + data_off; 1273 1262 const u8 *oob = nand->oob_poi + oob_off; 1274 1263 ··· 1307 1296 goto pio_fallback; 1308 1297 1309 1298 for (i = 0; i < ecc->steps; i++) { 1310 - const u8 *oob = nand->oob_poi + (i * (ecc->bytes + 4)); 1299 + const u8 *oob = nand->oob_poi + (i * (ecc->bytes + USER_DATA_SZ)); 1311 1300 1312 1301 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, i, !i, page); 1313 1302 } ··· 1577 1566 if (section >= ecc->steps) 1578 1567 return -ERANGE; 1579 1568 1580 - oobregion->offset = section * (ecc->bytes + 4) + 4; 1569 + oobregion->offset = section * (ecc->bytes + USER_DATA_SZ) + 4; 1581 1570 oobregion->length = ecc->bytes; 1582 1571 1583 1572 return 0; ··· 1611 1600 if (section == ecc->steps && ecc->engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) 1612 1601 return -ERANGE; 1613 1602 1614 - oobregion->offset = section * (ecc->bytes + 4); 1603 + oobregion->offset = section * (ecc->bytes + USER_DATA_SZ); 1615 1604 1616 1605 if (section < ecc->steps) 1617 - oobregion->length = 4; 1606 + oobregion->length = USER_DATA_SZ; 1618 1607 else 1619 1608 oobregion->length = mtd->oobsize - oobregion->offset; 1620 1609 ··· 1648 1637 bytes = (mtd->oobsize - 2) / nsectors; 1649 1638 1650 1639 /* 4 non-ECC bytes are added before each ECC bytes section */ 1651 - bytes -= 4; 1640 + bytes -= USER_DATA_SZ; 1652 1641 1653 1642 /* and bytes has to be even. */ 1654 1643 if (bytes % 2) ··· 1701 1690 1702 1691 nsectors = mtd->writesize / ecc->size; 1703 1692 1704 - if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) 1693 + if (mtd->oobsize < ((ecc->bytes + USER_DATA_SZ) * nsectors)) 1705 1694 return -EINVAL; 1706 1695 1707 1696 ecc->read_oob = sunxi_nfc_hw_ecc_read_oob;