Lines Matching refs:btt
256 static void btt_debugfs_init(struct btt *btt) in btt_debugfs_init() argument
261 btt->debugfs_dir = debugfs_create_dir(dev_name(&btt->nd_btt->dev), in btt_debugfs_init()
263 if (IS_ERR_OR_NULL(btt->debugfs_dir)) in btt_debugfs_init()
266 list_for_each_entry(arena, &btt->arena_list, list) { in btt_debugfs_init()
267 arena_debugfs_init(arena, btt->debugfs_dir, i); in btt_debugfs_init()
746 static struct arena_info *alloc_arena(struct btt *btt, size_t size, in alloc_arena() argument
756 arena->nd_btt = btt->nd_btt; in alloc_arena()
757 arena->sector_size = btt->sector_size; in alloc_arena()
765 arena->external_lbasize = btt->lbasize; in alloc_arena()
769 arena->version_major = btt->nd_btt->version_major; in alloc_arena()
770 arena->version_minor = btt->nd_btt->version_minor; in alloc_arena()
803 static void free_arenas(struct btt *btt) in free_arenas() argument
807 list_for_each_entry_safe(arena, next, &btt->arena_list, list) { in free_arenas()
847 static int discover_arenas(struct btt *btt) in discover_arenas() argument
852 size_t remaining = btt->rawsize; in discover_arenas()
863 arena = alloc_arena(btt, 0, 0, 0); in discover_arenas()
874 if (!nd_btt_arena_is_valid(btt->nd_btt, super)) { in discover_arenas()
875 if (remaining == btt->rawsize) { in discover_arenas()
876 btt->init_state = INIT_NOTFOUND; in discover_arenas()
909 list_add_tail(&arena->list, &btt->arena_list); in discover_arenas()
919 btt->num_arenas = num_arenas; in discover_arenas()
920 btt->nlba = cur_nlba; in discover_arenas()
921 btt->init_state = INIT_READY; in discover_arenas()
928 free_arenas(btt); in discover_arenas()
934 static int create_arenas(struct btt *btt) in create_arenas() argument
936 size_t remaining = btt->rawsize; in create_arenas()
947 arena = alloc_arena(btt, arena_size, btt->nlba, cur_off); in create_arenas()
949 free_arenas(btt); in create_arenas()
952 btt->nlba += arena->external_nlba; in create_arenas()
958 list_add_tail(&arena->list, &btt->arena_list); in create_arenas()
1026 static int btt_meta_init(struct btt *btt) in btt_meta_init() argument
1031 mutex_lock(&btt->init_lock); in btt_meta_init()
1032 list_for_each_entry(arena, &btt->arena_list, list) { in btt_meta_init()
1050 btt->init_state = INIT_READY; in btt_meta_init()
1053 mutex_unlock(&btt->init_lock); in btt_meta_init()
1057 static u32 btt_meta_size(struct btt *btt) in btt_meta_size() argument
1059 return btt->lbasize - btt->sector_size; in btt_meta_size()
1069 static int lba_to_arena(struct btt *btt, sector_t sector, __u32 *premap, in lba_to_arena() argument
1073 __u64 lba = div_u64(sector << SECTOR_SHIFT, btt->sector_size); in lba_to_arena()
1075 list_for_each_entry(arena_list, &btt->arena_list, list) { in lba_to_arena()
1142 static int btt_rw_integrity(struct btt *btt, struct bio_integrity_payload *bip, in btt_rw_integrity() argument
1145 unsigned int len = btt_meta_size(btt); in btt_rw_integrity()
1152 meta_nsoff = to_namespace_offset(arena, postmap) + btt->sector_size; in btt_rw_integrity()
1191 static int btt_rw_integrity(struct btt *btt, struct bio_integrity_payload *bip, in btt_rw_integrity() argument
1198 static int btt_read_pg(struct btt *btt, struct bio_integrity_payload *bip, in btt_read_pg() argument
1210 lane = nd_region_acquire_lane(btt->nd_region); in btt_read_pg()
1212 ret = lba_to_arena(btt, sector, &premap, &arena); in btt_read_pg()
1216 cur_len = min(btt->sector_size, len); in btt_read_pg()
1274 ret = btt_rw_integrity(btt, bip, arena, postmap, READ); in btt_read_pg()
1280 nd_region_release_lane(btt->nd_region, lane); in btt_read_pg()
1284 sector += btt->sector_size >> SECTOR_SHIFT; in btt_read_pg()
1292 nd_region_release_lane(btt->nd_region, lane); in btt_read_pg()
1301 static bool btt_is_badblock(struct btt *btt, struct arena_info *arena, in btt_is_badblock() argument
1308 return is_bad_pmem(btt->phys_bb, phys_sector, arena->internal_lbasize); in btt_is_badblock()
1311 static int btt_write_pg(struct btt *btt, struct bio_integrity_payload *bip, in btt_write_pg() argument
1326 lane = nd_region_acquire_lane(btt->nd_region); in btt_write_pg()
1328 ret = lba_to_arena(btt, sector, &premap, &arena); in btt_write_pg()
1331 cur_len = min(btt->sector_size, len); in btt_write_pg()
1338 if (btt_is_badblock(btt, arena, arena->freelist[lane].block)) in btt_write_pg()
1343 nd_region_release_lane(btt->nd_region, lane); in btt_write_pg()
1371 ret = btt_rw_integrity(btt, bip, arena, new_postmap, in btt_write_pg()
1404 nd_region_release_lane(btt->nd_region, lane); in btt_write_pg()
1414 sector += btt->sector_size >> SECTOR_SHIFT; in btt_write_pg()
1422 nd_region_release_lane(btt->nd_region, lane); in btt_write_pg()
1426 static int btt_do_bvec(struct btt *btt, struct bio_integrity_payload *bip, in btt_do_bvec() argument
1433 ret = btt_read_pg(btt, bip, page, off, sector, len); in btt_do_bvec()
1437 ret = btt_write_pg(btt, bip, sector, page, off, len); in btt_do_bvec()
1446 struct btt *btt = bio->bi_bdev->bd_disk->private_data; in btt_submit_bio() local
1462 if (len > PAGE_SIZE || len < btt->sector_size || in btt_submit_bio()
1463 len % btt->sector_size) { in btt_submit_bio()
1464 dev_err_ratelimited(&btt->nd_btt->dev, in btt_submit_bio()
1470 err = btt_do_bvec(btt, bip, bvec.bv_page, len, bvec.bv_offset, in btt_submit_bio()
1473 dev_err(&btt->nd_btt->dev, in btt_submit_bio()
1492 struct btt *btt = bdev->bd_disk->private_data; in btt_rw_page() local
1495 rc = btt_do_bvec(btt, NULL, page, thp_size(page), 0, op, sector); in btt_rw_page()
1519 static int btt_blk_init(struct btt *btt) in btt_blk_init() argument
1521 struct nd_btt *nd_btt = btt->nd_btt; in btt_blk_init()
1524 btt->btt_disk = blk_alloc_disk(NUMA_NO_NODE); in btt_blk_init()
1525 if (!btt->btt_disk) in btt_blk_init()
1528 nvdimm_namespace_disk_name(ndns, btt->btt_disk->disk_name); in btt_blk_init()
1529 btt->btt_disk->first_minor = 0; in btt_blk_init()
1530 btt->btt_disk->fops = &btt_fops; in btt_blk_init()
1531 btt->btt_disk->private_data = btt; in btt_blk_init()
1533 blk_queue_logical_block_size(btt->btt_disk->queue, btt->sector_size); in btt_blk_init()
1534 blk_queue_max_hw_sectors(btt->btt_disk->queue, UINT_MAX); in btt_blk_init()
1535 blk_queue_flag_set(QUEUE_FLAG_NONROT, btt->btt_disk->queue); in btt_blk_init()
1537 if (btt_meta_size(btt)) { in btt_blk_init()
1538 int rc = nd_integrity_init(btt->btt_disk, btt_meta_size(btt)); in btt_blk_init()
1541 blk_cleanup_disk(btt->btt_disk); in btt_blk_init()
1545 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9); in btt_blk_init()
1546 device_add_disk(&btt->nd_btt->dev, btt->btt_disk, NULL); in btt_blk_init()
1547 btt->nd_btt->size = btt->nlba * (u64)btt->sector_size; in btt_blk_init()
1548 nvdimm_check_and_set_ro(btt->btt_disk); in btt_blk_init()
1553 static void btt_blk_cleanup(struct btt *btt) in btt_blk_cleanup() argument
1555 del_gendisk(btt->btt_disk); in btt_blk_cleanup()
1556 blk_cleanup_disk(btt->btt_disk); in btt_blk_cleanup()
1576 static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize, in btt_init()
1580 struct btt *btt; in btt_init() local
1584 btt = devm_kzalloc(dev, sizeof(struct btt), GFP_KERNEL); in btt_init()
1585 if (!btt) in btt_init()
1588 btt->nd_btt = nd_btt; in btt_init()
1589 btt->rawsize = rawsize; in btt_init()
1590 btt->lbasize = lbasize; in btt_init()
1591 btt->sector_size = ((lbasize >= 4096) ? 4096 : 512); in btt_init()
1592 INIT_LIST_HEAD(&btt->arena_list); in btt_init()
1593 mutex_init(&btt->init_lock); in btt_init()
1594 btt->nd_region = nd_region; in btt_init()
1596 btt->phys_bb = &nsio->bb; in btt_init()
1598 ret = discover_arenas(btt); in btt_init()
1604 if (btt->init_state != INIT_READY && nd_region->ro) { in btt_init()
1608 } else if (btt->init_state != INIT_READY) { in btt_init()
1609 btt->num_arenas = (rawsize / ARENA_MAX_SIZE) + in btt_init()
1612 btt->num_arenas, rawsize); in btt_init()
1614 ret = create_arenas(btt); in btt_init()
1620 ret = btt_meta_init(btt); in btt_init()
1627 ret = btt_blk_init(btt); in btt_init()
1633 btt_debugfs_init(btt); in btt_init()
1635 return btt; in btt_init()
1647 static void btt_fini(struct btt *btt) in btt_fini() argument
1649 if (btt) { in btt_fini()
1650 btt_blk_cleanup(btt); in btt_fini()
1651 free_arenas(btt); in btt_fini()
1652 debugfs_remove_recursive(btt->debugfs_dir); in btt_fini()
1661 struct btt *btt; in nvdimm_namespace_attach_btt() local
1695 btt = btt_init(nd_btt, rawsize, nd_btt->lbasize, nd_btt->uuid, in nvdimm_namespace_attach_btt()
1697 if (!btt) in nvdimm_namespace_attach_btt()
1699 nd_btt->btt = btt; in nvdimm_namespace_attach_btt()
1707 struct btt *btt = nd_btt->btt; in nvdimm_namespace_detach_btt() local
1709 btt_fini(btt); in nvdimm_namespace_detach_btt()
1710 nd_btt->btt = NULL; in nvdimm_namespace_detach_btt()