IB: convert struct class_device to struct device
[safe/jmp/linux-2.6] / drivers / infiniband / hw / mthca / mthca_memfree.c
index 007b381..b224079 100644 (file)
@@ -113,9 +113,7 @@ static int mthca_alloc_icm_pages(struct scatterlist *mem, int order, gfp_t gfp_m
        if (!page)
                return -ENOMEM;
 
-       sg_set_page(mem, page);
-       mem->length = PAGE_SIZE << order;
-       mem->offset = 0;
+       sg_set_page(mem, page, PAGE_SIZE << order, 0);
        return 0;
 }
 
@@ -361,12 +359,14 @@ struct mthca_icm_table *mthca_alloc_icm_table(struct mthca_dev *dev,
                                              int use_lowmem, int use_coherent)
 {
        struct mthca_icm_table *table;
+       int obj_per_chunk;
        int num_icm;
        unsigned chunk_size;
        int i;
        u8 status;
 
-       num_icm = (obj_size * nobj + MTHCA_TABLE_CHUNK_SIZE - 1) / MTHCA_TABLE_CHUNK_SIZE;
+       obj_per_chunk = MTHCA_TABLE_CHUNK_SIZE / obj_size;
+       num_icm = DIV_ROUND_UP(nobj, obj_per_chunk);
 
        table = kmalloc(sizeof *table + num_icm * sizeof *table->icm, GFP_KERNEL);
        if (!table)
@@ -414,7 +414,7 @@ err:
                if (table->icm[i]) {
                        mthca_UNMAP_ICM(dev, virt + i * MTHCA_TABLE_CHUNK_SIZE,
                                        MTHCA_TABLE_CHUNK_SIZE / MTHCA_ICM_PAGE_SIZE,
-                                       &status);
+                                       &status);
                        mthca_free_icm(dev, table->icm[i], table->coherent);
                }
 
@@ -481,9 +481,8 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
        if (ret < 0)
                goto out;
 
-       sg_set_page(&db_tab->page[i].mem, pages[0]);
-       db_tab->page[i].mem.length = MTHCA_ICM_PAGE_SIZE;
-       db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK;
+       sg_set_page(&db_tab->page[i].mem, pages[0], MTHCA_ICM_PAGE_SIZE,
+                       uaddr & ~PAGE_MASK);
 
        ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
        if (ret < 0) {
@@ -545,6 +544,7 @@ struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev)
        for (i = 0; i < npages; ++i) {
                db_tab->page[i].refcount = 0;
                db_tab->page[i].uvirt    = 0;
+               sg_init_table(&db_tab->page[i].mem, 1);
        }
 
        return db_tab;