yaffs Added more tests to direct/timothy_tests/mirror_tests
[yaffs2.git] / yaffs_tagscompat.c
index 3a9a157e7e2470c44252cb338363347db7b04569..7578075d9ac10a26dca7ff93a9e4d6735795c8a2 100644 (file)
 
 static void yaffs_handle_rd_data_error(struct yaffs_dev *dev, int nand_chunk);
 
-static const char yaffs_count_bits_table[256] = {
-       0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
-       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-       4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
-};
-
-int yaffs_count_bits(u8 x)
-{
-       int ret_val;
-       ret_val = yaffs_count_bits_table[x];
-       return ret_val;
-}
 
 /********** Tags ECC calculations  *********/
 
@@ -157,9 +132,9 @@ static int yaffs_wr_nand(struct yaffs_dev *dev,
                         struct yaffs_spare *spare)
 {
        if (nand_chunk < dev->param.start_block * dev->param.chunks_per_block) {
-               T(YAFFS_TRACE_ERROR,
-                 (TSTR("**>> yaffs chunk %d is not valid" TENDSTR),
-                  nand_chunk));
+               yaffs_trace(YAFFS_TRACE_ERROR,
+                       "**>> yaffs chunk %d is not valid",
+                       nand_chunk);
                return YAFFS_FAIL;
        }
 
@@ -200,30 +175,26 @@ static int yaffs_rd_chunk_nand(struct yaffs_dev *dev,
                                              calc_ecc);
 
                        if (ecc_result1 > 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>yaffs ecc error fix performed on chunk %d:0"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>yaffs ecc error fix performed on chunk %d:0",
+                                       nand_chunk);
                                dev->n_ecc_fixed++;
                        } else if (ecc_result1 < 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>yaffs ecc error unfixed on chunk %d:0"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>yaffs ecc error unfixed on chunk %d:0",
+                                       nand_chunk);
                                dev->n_ecc_unfixed++;
                        }
 
                        if (ecc_result2 > 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>yaffs ecc error fix performed on chunk %d:1"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>yaffs ecc error fix performed on chunk %d:1",
+                                       nand_chunk);
                                dev->n_ecc_fixed++;
                        } else if (ecc_result2 < 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>yaffs ecc error unfixed on chunk %d:1"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>yaffs ecc error unfixed on chunk %d:1",
+                                       nand_chunk);
                                dev->n_ecc_unfixed++;
                        }
 
@@ -252,27 +223,23 @@ static int yaffs_rd_chunk_nand(struct yaffs_dev *dev,
                memcpy(spare, &nspare, sizeof(struct yaffs_spare));
                if (data && correct_errors) {
                        if (nspare.eccres1 > 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>mtd ecc error fix performed on chunk %d:0"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>mtd ecc error fix performed on chunk %d:0",
+                                       nand_chunk);
                        } else if (nspare.eccres1 < 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>mtd ecc error unfixed on chunk %d:0"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>mtd ecc error unfixed on chunk %d:0",
+                                       nand_chunk);
                        }
 
                        if (nspare.eccres2 > 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>mtd ecc error fix performed on chunk %d:1"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>mtd ecc error fix performed on chunk %d:1",
+                                       nand_chunk);
                        } else if (nspare.eccres2 < 0) {
-                               T(YAFFS_TRACE_ERROR,
-                                 (TSTR
-                                  ("**>>mtd ecc error unfixed on chunk %d:1"
-                                   TENDSTR), nand_chunk));
+                               yaffs_trace(YAFFS_TRACE_ERROR,
+                                       "**>>mtd ecc error unfixed on chunk %d:1",
+                                       nand_chunk);
                        }
 
                        if (nspare.eccres1 || nspare.eccres2) {
@@ -304,8 +271,9 @@ static void yaffs_handle_rd_data_error(struct yaffs_dev *dev, int nand_chunk)
        yaffs_get_block_info(dev,
                             flash_block + dev->block_offset)->needs_retiring =
            1;
-       T(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS,
-         (TSTR("**>>Block %d marked for retirement" TENDSTR), flash_block));
+       yaffs_trace(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS,
+               "**>>Block %d marked for retirement",
+               flash_block);
 
        /* TODO:
         * Just do a garbage collection on the affected block
@@ -370,7 +338,7 @@ int yaffs_tags_compat_rd(struct yaffs_dev *dev,
                if (ext_tags) {
 
                        int deleted =
-                           (yaffs_count_bits(spare.page_status) < 7) ? 1 : 0;
+                           (hweight8(spare.page_status) < 7) ? 1 : 0;
 
                        ext_tags->is_deleted = deleted;
                        ext_tags->ecc_result = ecc_result;
@@ -443,7 +411,7 @@ int yaffs_tags_compat_query_block(struct yaffs_dev *dev,
        yaffs_rd_chunk_nand(dev, block_no * dev->param.chunks_per_block + 1,
                            NULL, &spare1, &dummy, 1);
 
-       if (yaffs_count_bits(spare0.block_status & spare1.block_status) < 7)
+       if (hweight8(spare0.block_status & spare1.block_status) < 7)
                *state = YAFFS_BLOCK_STATE_DEAD;
        else if (memcmp(&spare_ff, &spare0, sizeof(spare_ff)) == 0)
                *state = YAFFS_BLOCK_STATE_EMPTY;