Exemple #1
0
/*****************************************************************************
*Name         :
*Description  :
*Parameter    :
*Return       :
*Note         :
*****************************************************************************/
int add_nand_for_test(struct _nand_phy_partition* phy_partition)
{
	int i;
    __u32 cur_offset = 0;
    struct _nftl_blk *nftl_blk;
    struct _nand_dev *nand_dev;
	struct _nand_disk* disk;
	struct _nand_disk* head_disk;
	struct nand_kobject* nand_kobj;
	uint16 PartitionNO;

    PartitionNO = get_partitionNO(phy_partition);

    nftl_blk = kmalloc(sizeof(struct _nftl_blk), GFP_KERNEL);
    if (!nftl_blk)
	{
	    printk("nftl_blk kmalloc fail!\n");
		return 1;
	}
    nftl_blk->nand = build_nand_partition(phy_partition);

    if (nftl_initialize(nftl_blk,PartitionNO))
	{
        printk("nftl_initialize failed\n");
        return 1;
    }

    nftl_blk->blk_lock = kmalloc(sizeof(struct mutex), GFP_KERNEL);
    if (!nftl_blk->blk_lock)
	{
	    printk("blk_lock kmalloc fail!\n");
		return 1;
	}
    mutex_init(nftl_blk->blk_lock);

	nftl_blk->nftl_thread = kthread_run(nftl_test_thread, nftl_blk, "%sd", "nftl");
    if (IS_ERR(nftl_blk->nftl_thread))
    {
        printk("nftl_thread kthread_run fail!\n");
        return 1;
    }

    add_nftl_blk_list(&nftl_blk_head,nftl_blk);

    nand_kobj = kzalloc(sizeof(struct nand_kobject), GFP_KERNEL);
    if (!nand_kobj)
	{
	    printk("nand_kobj kzalloc fail!\n");
		return 1;
	}
	nand_kobj->nftl_blk = nftl_blk;
    if(kobject_init_and_add(&nand_kobj->kobj,&ktype,NULL,"nand_driver%d",PartitionNO) != 0 ) {
	printk("init nand sysfs fail!\n");
		return 1;
	}

    return 0;
}
/*****************************************************************************
*Name         :
*Description  :
*Parameter    :
*Return       :
*Note         :
*****************************************************************************/
int add_nand(struct nand_blk_ops *tr, struct _nand_phy_partition* phy_partition)
{
	int i;
    __u32 cur_offset = 0;
    struct _nftl_blk *nftl_blk;
    struct _nand_dev *nand_dev;
	struct _nand_disk* disk;
	struct _nand_disk* head_disk;
	struct nand_kobject* nand_kobj;
	uint16 PartitionNO;

    PartitionNO = get_partitionNO(phy_partition);

    nftl_blk = kmalloc(sizeof(struct _nftl_blk), GFP_KERNEL);
    if (!nftl_blk)
	{
	    nand_dbg_err("init kmalloc fail 3!\n");
		return 1;
	}
    nftl_blk->nand = build_nand_partition(phy_partition);

    if (nftl_initialize(nftl_blk,PartitionNO))
	{
        nand_dbg_err("nftl_initialize failed\n");
        return 1;
    }

    nftl_blk->blk_lock = kmalloc(sizeof(struct mutex), GFP_KERNEL);
    if (!nftl_blk->blk_lock)
	{
	    nand_dbg_err("init kmalloc fail 2!\n");
		return 1;
	}
    mutex_init(nftl_blk->blk_lock);

	nftl_blk->nftl_thread = kthread_run(nftl_thread, nftl_blk, "%sd", "nftl");
    if (IS_ERR(nftl_blk->nftl_thread))
    {
        nand_dbg_err("init kthread_run fail!\n");
        return 1;
    }

    add_nftl_blk_list(&tr->nftl_blk_head,nftl_blk);

    nand_kobj = kzalloc(sizeof(struct nand_kobject), GFP_KERNEL);
    if (!nand_kobj)
	{
	    nand_dbg_err("init kmalloc fail 1!\n");
		return 1;
	}
	nand_kobj->nftl_blk = nftl_blk;
    if(kobject_init_and_add(&nand_kobj->kobj,&ktype,NULL,"nand_driver%d",PartitionNO) != 0 ) {
    	nand_dbg_err("init nand sysfs fail!\n");
	  	return 1;
	}

	disk = get_disk_from_phy_partition(phy_partition);
	for(i=0;i<MAX_PART_COUNT_PER_FTL;i++)
    {
        //nand_dbg_err("disk->name %s\n",(char *)(disk->name));
        //nand_dbg_err("disk->type %x\n",disk[i].type);
        //nand_dbg_err("disk->size %x\n",disk[i].size);
    }

    head_disk = get_disk_from_phy_partition(phy_partition);
	for(i=0;i<MAX_PART_COUNT_PER_FTL;i++)
	{
		disk = head_disk + i;
		if(disk->type == 0xffffffff)
		{
		    break;
		}

        nand_dev = kmalloc(sizeof(struct _nand_dev), GFP_KERNEL);
        if (!nand_dev)
		{
		    nand_dbg_err("init kmalloc fail!\n");
            return 1;
		}

		add_nand_dev_list(&tr->nand_dev_head,nand_dev);

        nand_dev->nbd.nandr = &mytr;

        if(dev_initialize(nand_dev,nftl_blk,cur_offset,disk->size) != 0)
		{
            //nand_dbg_err("dev_initialize failed\n");
            return 1;
        }

        nand_dev->nbd.size = (unsigned int)nand_dev->size;
        nand_dev->nbd.priv = (void*)nand_dev;

        //memcpy(nand_dev->nbd.name,disk->name,strlen(disk->name)+1);

        if((PartitionNO == 0) && (i==0))
        {
            dev_num = -1;
        }
        else
        {
            dev_num++;
            nand_dev->nbd.devnum = dev_num;
            if (add_nand_blktrans_dev(&nand_dev->nbd))
		    {
                nand_dbg_err("nftl add blk disk dev failed\n");
                return 1;
            }
        }

		cur_offset += disk->size;
	}
    return 0;
}