@@ -2783,137 +2783,6 @@ int nand_set_features(struct nand_chip *chip, int addr,
27832783 return nand_set_features_op (chip , addr , subfeature_param );
27842784}
27852785
2786- /**
2787- * nand_check_erased_buf - check if a buffer contains (almost) only 0xff data
2788- * @buf: buffer to test
2789- * @len: buffer length
2790- * @bitflips_threshold: maximum number of bitflips
2791- *
2792- * Check if a buffer contains only 0xff, which means the underlying region
2793- * has been erased and is ready to be programmed.
2794- * The bitflips_threshold specify the maximum number of bitflips before
2795- * considering the region is not erased.
2796- * Note: The logic of this function has been extracted from the memweight
2797- * implementation, except that nand_check_erased_buf function exit before
2798- * testing the whole buffer if the number of bitflips exceed the
2799- * bitflips_threshold value.
2800- *
2801- * Returns a positive number of bitflips less than or equal to
2802- * bitflips_threshold, or -ERROR_CODE for bitflips in excess of the
2803- * threshold.
2804- */
2805- static int nand_check_erased_buf (void * buf , int len , int bitflips_threshold )
2806- {
2807- const unsigned char * bitmap = buf ;
2808- int bitflips = 0 ;
2809- int weight ;
2810-
2811- for (; len && ((uintptr_t )bitmap ) % sizeof (long );
2812- len -- , bitmap ++ ) {
2813- weight = hweight8 (* bitmap );
2814- bitflips += BITS_PER_BYTE - weight ;
2815- if (unlikely (bitflips > bitflips_threshold ))
2816- return - EBADMSG ;
2817- }
2818-
2819- for (; len >= sizeof (long );
2820- len -= sizeof (long ), bitmap += sizeof (long )) {
2821- unsigned long d = * ((unsigned long * )bitmap );
2822- if (d == ~0UL )
2823- continue ;
2824- weight = hweight_long (d );
2825- bitflips += BITS_PER_LONG - weight ;
2826- if (unlikely (bitflips > bitflips_threshold ))
2827- return - EBADMSG ;
2828- }
2829-
2830- for (; len > 0 ; len -- , bitmap ++ ) {
2831- weight = hweight8 (* bitmap );
2832- bitflips += BITS_PER_BYTE - weight ;
2833- if (unlikely (bitflips > bitflips_threshold ))
2834- return - EBADMSG ;
2835- }
2836-
2837- return bitflips ;
2838- }
2839-
2840- /**
2841- * nand_check_erased_ecc_chunk - check if an ECC chunk contains (almost) only
2842- * 0xff data
2843- * @data: data buffer to test
2844- * @datalen: data length
2845- * @ecc: ECC buffer
2846- * @ecclen: ECC length
2847- * @extraoob: extra OOB buffer
2848- * @extraooblen: extra OOB length
2849- * @bitflips_threshold: maximum number of bitflips
2850- *
2851- * Check if a data buffer and its associated ECC and OOB data contains only
2852- * 0xff pattern, which means the underlying region has been erased and is
2853- * ready to be programmed.
2854- * The bitflips_threshold specify the maximum number of bitflips before
2855- * considering the region as not erased.
2856- *
2857- * Note:
2858- * 1/ ECC algorithms are working on pre-defined block sizes which are usually
2859- * different from the NAND page size. When fixing bitflips, ECC engines will
2860- * report the number of errors per chunk, and the NAND core infrastructure
2861- * expect you to return the maximum number of bitflips for the whole page.
2862- * This is why you should always use this function on a single chunk and
2863- * not on the whole page. After checking each chunk you should update your
2864- * max_bitflips value accordingly.
2865- * 2/ When checking for bitflips in erased pages you should not only check
2866- * the payload data but also their associated ECC data, because a user might
2867- * have programmed almost all bits to 1 but a few. In this case, we
2868- * shouldn't consider the chunk as erased, and checking ECC bytes prevent
2869- * this case.
2870- * 3/ The extraoob argument is optional, and should be used if some of your OOB
2871- * data are protected by the ECC engine.
2872- * It could also be used if you support subpages and want to attach some
2873- * extra OOB data to an ECC chunk.
2874- *
2875- * Returns a positive number of bitflips less than or equal to
2876- * bitflips_threshold, or -ERROR_CODE for bitflips in excess of the
2877- * threshold. In case of success, the passed buffers are filled with 0xff.
2878- */
2879- int nand_check_erased_ecc_chunk (void * data , int datalen ,
2880- void * ecc , int ecclen ,
2881- void * extraoob , int extraooblen ,
2882- int bitflips_threshold )
2883- {
2884- int data_bitflips = 0 , ecc_bitflips = 0 , extraoob_bitflips = 0 ;
2885-
2886- data_bitflips = nand_check_erased_buf (data , datalen ,
2887- bitflips_threshold );
2888- if (data_bitflips < 0 )
2889- return data_bitflips ;
2890-
2891- bitflips_threshold -= data_bitflips ;
2892-
2893- ecc_bitflips = nand_check_erased_buf (ecc , ecclen , bitflips_threshold );
2894- if (ecc_bitflips < 0 )
2895- return ecc_bitflips ;
2896-
2897- bitflips_threshold -= ecc_bitflips ;
2898-
2899- extraoob_bitflips = nand_check_erased_buf (extraoob , extraooblen ,
2900- bitflips_threshold );
2901- if (extraoob_bitflips < 0 )
2902- return extraoob_bitflips ;
2903-
2904- if (data_bitflips )
2905- memset (data , 0xff , datalen );
2906-
2907- if (ecc_bitflips )
2908- memset (ecc , 0xff , ecclen );
2909-
2910- if (extraoob_bitflips )
2911- memset (extraoob , 0xff , extraooblen );
2912-
2913- return data_bitflips + ecc_bitflips + extraoob_bitflips ;
2914- }
2915- EXPORT_SYMBOL (nand_check_erased_ecc_chunk );
2916-
29172786/**
29182787 * nand_read_page_raw_notsupp - dummy read raw page function
29192788 * @chip: nand chip info structure
0 commit comments