Lines Matching refs:part

151 static int scan_header(partition_t *part)  in scan_header()  argument
157 part->header.FormattedSize = 0; in scan_header()
158 max_offset = (0x100000<part->mbd.mtd->size)?0x100000:part->mbd.mtd->size; in scan_header()
162 offset += part->mbd.mtd->erasesize ? : 0x2000) { in scan_header()
164 err = mtd_read(part->mbd.mtd, offset, sizeof(header), &ret, in scan_header()
183 if ((1 << header.EraseUnitSize) != part->mbd.mtd->erasesize) { in scan_header()
185 1 << header.EraseUnitSize,part->mbd.mtd->erasesize); in scan_header()
188 part->header = header; in scan_header()
192 static int build_maps(partition_t *part) in build_maps() argument
202 part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) - in build_maps()
203 part->header.NumTransferUnits; in build_maps()
204 part->EUNInfo = kmalloc_array(part->DataUnits, sizeof(struct eun_info_t), in build_maps()
206 if (!part->EUNInfo) in build_maps()
208 for (i = 0; i < part->DataUnits; i++) in build_maps()
209 part->EUNInfo[i].Offset = 0xffffffff; in build_maps()
210 part->XferInfo = in build_maps()
211 kmalloc_array(part->header.NumTransferUnits, in build_maps()
214 if (!part->XferInfo) in build_maps()
218 for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) { in build_maps()
219 offset = ((i + le16_to_cpu(part->header.FirstPhysicalEUN)) in build_maps()
220 << part->header.EraseUnitSize); in build_maps()
221 ret = mtd_read(part->mbd.mtd, offset, sizeof(header), &retval, in build_maps()
230 if (hdr_ok && (le16_to_cpu(header.LogicalEUN) < part->DataUnits) && in build_maps()
231 (part->EUNInfo[le16_to_cpu(header.LogicalEUN)].Offset == 0xffffffff)) { in build_maps()
232 part->EUNInfo[le16_to_cpu(header.LogicalEUN)].Offset = offset; in build_maps()
233 part->EUNInfo[le16_to_cpu(header.LogicalEUN)].EraseCount = in build_maps()
237 if (xtrans == part->header.NumTransferUnits) { in build_maps()
243 part->XferInfo[xtrans].state = XFER_PREPARED; in build_maps()
244 part->XferInfo[xtrans].EraseCount = le32_to_cpu(header.EraseCount); in build_maps()
246 part->XferInfo[xtrans].state = XFER_UNKNOWN; in build_maps()
248 part->XferInfo[xtrans].EraseCount = in build_maps()
249 le32_to_cpu(part->header.EraseCount); in build_maps()
251 part->XferInfo[xtrans].Offset = offset; in build_maps()
256 header = part->header; in build_maps()
266 part->VirtualBlockMap = vmalloc(array_size(blocks, sizeof(uint32_t))); in build_maps()
267 if (!part->VirtualBlockMap) in build_maps()
270 memset(part->VirtualBlockMap, 0xff, blocks * sizeof(uint32_t)); in build_maps()
271 part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize; in build_maps()
273 part->bam_cache = kmalloc_array(part->BlocksPerUnit, sizeof(uint32_t), in build_maps()
275 if (!part->bam_cache) in build_maps()
278 part->bam_index = 0xffff; in build_maps()
279 part->FreeTotal = 0; in build_maps()
281 for (i = 0; i < part->DataUnits; i++) { in build_maps()
282 part->EUNInfo[i].Free = 0; in build_maps()
283 part->EUNInfo[i].Deleted = 0; in build_maps()
284 offset = part->EUNInfo[i].Offset + le32_to_cpu(header.BAMOffset); in build_maps()
286 ret = mtd_read(part->mbd.mtd, offset, in build_maps()
287 part->BlocksPerUnit * sizeof(uint32_t), &retval, in build_maps()
288 (unsigned char *)part->bam_cache); in build_maps()
293 for (j = 0; j < part->BlocksPerUnit; j++) { in build_maps()
294 if (BLOCK_FREE(le32_to_cpu(part->bam_cache[j]))) { in build_maps()
295 part->EUNInfo[i].Free++; in build_maps()
296 part->FreeTotal++; in build_maps()
297 } else if ((BLOCK_TYPE(le32_to_cpu(part->bam_cache[j])) == BLOCK_DATA) && in build_maps()
298 (BLOCK_NUMBER(le32_to_cpu(part->bam_cache[j])) < blocks)) in build_maps()
299 part->VirtualBlockMap[BLOCK_NUMBER(le32_to_cpu(part->bam_cache[j]))] = in build_maps()
301 else if (BLOCK_DELETED(le32_to_cpu(part->bam_cache[j]))) in build_maps()
302 part->EUNInfo[i].Deleted++; in build_maps()
310 kfree(part->bam_cache); in build_maps()
312 vfree(part->VirtualBlockMap); in build_maps()
314 kfree(part->XferInfo); in build_maps()
316 kfree(part->EUNInfo); in build_maps()
328 static int erase_xfer(partition_t *part, in erase_xfer() argument
335 xfer = &part->XferInfo[xfernum]; in erase_xfer()
347 erase->len = 1 << part->header.EraseUnitSize; in erase_xfer()
349 ret = mtd_erase(part->mbd.mtd, erase); in erase_xfer()
370 static int prepare_xfer(partition_t *part, int i) in prepare_xfer() argument
379 xfer = &part->XferInfo[i]; in prepare_xfer()
385 header = part->header; in prepare_xfer()
389 ret = mtd_write(part->mbd.mtd, xfer->Offset, sizeof(header), &retlen, in prepare_xfer()
397 nbam = DIV_ROUND_UP(part->BlocksPerUnit * sizeof(uint32_t) + in prepare_xfer()
398 le32_to_cpu(part->header.BAMOffset), SECTOR_SIZE); in prepare_xfer()
400 offset = xfer->Offset + le32_to_cpu(part->header.BAMOffset); in prepare_xfer()
405 ret = mtd_write(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, in prepare_xfer()
428 static int copy_erase_unit(partition_t *part, uint16_t srcunit, in copy_erase_unit() argument
441 eun = &part->EUNInfo[srcunit]; in copy_erase_unit()
442 xfer = &part->XferInfo[xferunit]; in copy_erase_unit()
448 if (part->bam_index != srcunit) { in copy_erase_unit()
450 offset = eun->Offset + le32_to_cpu(part->header.BAMOffset); in copy_erase_unit()
452 ret = mtd_read(part->mbd.mtd, offset, in copy_erase_unit()
453 part->BlocksPerUnit * sizeof(uint32_t), &retlen, in copy_erase_unit()
454 (u_char *)(part->bam_cache)); in copy_erase_unit()
457 part->bam_index = 0xffff; in copy_erase_unit()
470 ret = mtd_write(part->mbd.mtd, offset, sizeof(uint16_t), &retlen, in copy_erase_unit()
483 for (i = 0; i < part->BlocksPerUnit; i++) { in copy_erase_unit()
484 switch (BLOCK_TYPE(le32_to_cpu(part->bam_cache[i]))) { in copy_erase_unit()
490 ret = mtd_read(part->mbd.mtd, src, SECTOR_SIZE, &retlen, in copy_erase_unit()
498 ret = mtd_write(part->mbd.mtd, dest, SECTOR_SIZE, &retlen, in copy_erase_unit()
508 part->bam_cache[i] = cpu_to_le32(0xffffffff); in copy_erase_unit()
517 ret = mtd_write(part->mbd.mtd, in copy_erase_unit()
518 xfer->Offset + le32_to_cpu(part->header.BAMOffset), in copy_erase_unit()
519 part->BlocksPerUnit * sizeof(int32_t), in copy_erase_unit()
521 (u_char *)part->bam_cache); in copy_erase_unit()
529 ret = mtd_write(part->mbd.mtd, xfer->Offset + 20, sizeof(uint16_t), in copy_erase_unit()
541 part->FreeTotal -= eun->Free; in copy_erase_unit()
542 part->FreeTotal += free; in copy_erase_unit()
547 part->bam_index = srcunit; in copy_erase_unit()
568 static int reclaim_block(partition_t *part) in reclaim_block() argument
575 pr_debug("NumTransferUnits == %x\n", part->header.NumTransferUnits); in reclaim_block()
580 for (i = 0; i < part->header.NumTransferUnits; i++) { in reclaim_block()
582 if (part->XferInfo[i].state == XFER_UNKNOWN) { in reclaim_block()
585 erase_xfer(part, i); in reclaim_block()
587 if (part->XferInfo[i].state == XFER_ERASING) { in reclaim_block()
592 else if (part->XferInfo[i].state == XFER_ERASED) { in reclaim_block()
595 prepare_xfer(part, i); in reclaim_block()
597 if (part->XferInfo[i].state == XFER_PREPARED) { in reclaim_block()
600 if (part->XferInfo[i].EraseCount <= best) { in reclaim_block()
601 best = part->XferInfo[i].EraseCount; in reclaim_block()
606 pr_debug("XferInfo[%d].state == %x\n",i, part->XferInfo[i].state); in reclaim_block()
613 mtd_sync(part->mbd.mtd); in reclaim_block()
632 for (i = 0; i < part->DataUnits; i++) in reclaim_block()
633 if (part->EUNInfo[i].EraseCount <= best) { in reclaim_block()
634 best = part->EUNInfo[i].EraseCount; in reclaim_block()
639 for (i = 0; i < part->DataUnits; i++) in reclaim_block()
640 if (part->EUNInfo[i].Deleted >= best) { in reclaim_block()
641 best = part->EUNInfo[i].Deleted; in reclaim_block()
656 ret = copy_erase_unit(part, eun, xfer); in reclaim_block()
658 erase_xfer(part, xfer); in reclaim_block()
675 static void dump_lists(partition_t *part) in dump_lists() argument
678 printk(KERN_DEBUG "ftl_cs: Free total = %d\n", part->FreeTotal); in dump_lists()
679 for (i = 0; i < part->DataUnits; i++) in dump_lists()
682 part->EUNInfo[i].Offset >> part->header.EraseUnitSize, in dump_lists()
683 part->EUNInfo[i].Free, part->EUNInfo[i].Deleted); in dump_lists()
687 static uint32_t find_free(partition_t *part) in find_free() argument
695 stop = (part->bam_index == 0xffff) ? 0 : part->bam_index; in find_free()
698 if (part->EUNInfo[eun].Free != 0) break; in find_free()
700 if (++eun == part->DataUnits) eun = 0; in find_free()
703 if (part->EUNInfo[eun].Free == 0) in find_free()
707 if (eun != part->bam_index) { in find_free()
709 part->bam_index = 0xffff; in find_free()
711 ret = mtd_read(part->mbd.mtd, in find_free()
712 part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset), in find_free()
713 part->BlocksPerUnit * sizeof(uint32_t), in find_free()
715 (u_char *)(part->bam_cache)); in find_free()
721 part->bam_index = eun; in find_free()
725 for (blk = 0; blk < part->BlocksPerUnit; blk++) in find_free()
726 if (BLOCK_FREE(le32_to_cpu(part->bam_cache[blk]))) break; in find_free()
727 if (blk == part->BlocksPerUnit) { in find_free()
731 dump_lists(part); in find_free()
748 static int ftl_read(partition_t *part, caddr_t buffer, in ftl_read() argument
757 part, sector, nblocks); in ftl_read()
758 if (!(part->state & FTL_FORMATTED)) { in ftl_read()
762 bsize = 1 << part->header.EraseUnitSize; in ftl_read()
765 if (((sector+i) * SECTOR_SIZE) >= le32_to_cpu(part->header.FormattedSize)) { in ftl_read()
769 log_addr = part->VirtualBlockMap[sector+i]; in ftl_read()
773 offset = (part->EUNInfo[log_addr / bsize].Offset in ftl_read()
775 ret = mtd_read(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, in ftl_read()
794 static int set_bam_entry(partition_t *part, uint32_t log_addr, in set_bam_entry() argument
806 part, log_addr, virt_addr); in set_bam_entry()
807 bsize = 1 << part->header.EraseUnitSize; in set_bam_entry()
810 offset = (part->EUNInfo[eun].Offset + blk * sizeof(uint32_t) + in set_bam_entry()
811 le32_to_cpu(part->header.BAMOffset)); in set_bam_entry()
814 ret = mtd_read(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, in set_bam_entry()
835 if (part->bam_index == eun) { in set_bam_entry()
837 if (le32_to_cpu(part->bam_cache[blk]) != old_addr) { in set_bam_entry()
844 le32_to_cpu(part->bam_cache[blk]), old_addr); in set_bam_entry()
849 part->bam_cache[blk] = le_virt_addr; in set_bam_entry()
851 ret = mtd_write(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, in set_bam_entry()
862 static int ftl_write(partition_t *part, caddr_t buffer, in ftl_write() argument
871 part, sector, nblocks); in ftl_write()
872 if (!(part->state & FTL_FORMATTED)) { in ftl_write()
877 while (part->FreeTotal < nblocks) { in ftl_write()
878 ret = reclaim_block(part); in ftl_write()
883 bsize = 1 << part->header.EraseUnitSize; in ftl_write()
887 if (virt_addr >= le32_to_cpu(part->header.FormattedSize)) { in ftl_write()
893 blk = find_free(part); in ftl_write()
903 log_addr = part->bam_index * bsize + blk * SECTOR_SIZE; in ftl_write()
904 part->EUNInfo[part->bam_index].Free--; in ftl_write()
905 part->FreeTotal--; in ftl_write()
906 if (set_bam_entry(part, log_addr, 0xfffffffe)) in ftl_write()
908 part->EUNInfo[part->bam_index].Deleted++; in ftl_write()
909 offset = (part->EUNInfo[part->bam_index].Offset + in ftl_write()
911 ret = mtd_write(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, buffer); in ftl_write()
922 old_addr = part->VirtualBlockMap[sector+i]; in ftl_write()
924 part->VirtualBlockMap[sector+i] = 0xffffffff; in ftl_write()
925 part->EUNInfo[old_addr/bsize].Deleted++; in ftl_write()
926 if (set_bam_entry(part, old_addr, 0)) in ftl_write()
931 if (set_bam_entry(part, log_addr, virt_addr)) in ftl_write()
933 part->VirtualBlockMap[sector+i] = log_addr; in ftl_write()
934 part->EUNInfo[part->bam_index].Deleted--; in ftl_write()
944 partition_t *part = container_of(dev, struct partition_t, mbd); in ftl_getgeo() local
948 sect = le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE; in ftl_getgeo()
972 partition_t *part = container_of(dev, struct partition_t, mbd); in ftl_discardsect() local
973 uint32_t bsize = 1 << part->header.EraseUnitSize; in ftl_discardsect()
979 uint32_t old_addr = part->VirtualBlockMap[sector]; in ftl_discardsect()
981 part->VirtualBlockMap[sector] = 0xffffffff; in ftl_discardsect()
982 part->EUNInfo[old_addr/bsize].Deleted++; in ftl_discardsect()
983 if (set_bam_entry(part, old_addr, 0)) in ftl_discardsect()
994 static void ftl_freepart(partition_t *part) in ftl_freepart() argument
996 vfree(part->VirtualBlockMap); in ftl_freepart()
997 part->VirtualBlockMap = NULL; in ftl_freepart()
998 kfree(part->EUNInfo); in ftl_freepart()
999 part->EUNInfo = NULL; in ftl_freepart()
1000 kfree(part->XferInfo); in ftl_freepart()
1001 part->XferInfo = NULL; in ftl_freepart()
1002 kfree(part->bam_cache); in ftl_freepart()
1003 part->bam_cache = NULL; in ftl_freepart()