static int rd_build_device_space(struct rd_dev *rd_dev) { struct rd_dev_sg_table *sg_table; u32 sg_tables, total_sg_needed; u32 max_sg_per_table = (RD_MAX_ALLOCATION_SIZE / sizeof(struct scatterlist)); int rc; if (rd_dev->rd_page_count <= 0) { pr_err("Illegal page count: %u for Ramdisk device\n", rd_dev->rd_page_count); return -EINVAL; } /* Don't need backing pages for NULLIO */ if (rd_dev->rd_flags & RDF_NULLIO) return 0; total_sg_needed = rd_dev->rd_page_count; sg_tables = (total_sg_needed / max_sg_per_table) + 1; sg_table = kzalloc(sg_tables * sizeof(struct rd_dev_sg_table), GFP_KERNEL); if (!sg_table) { pr_err("Unable to allocate memory for Ramdisk" " scatterlist tables\n"); return -ENOMEM; } rd_dev->sg_table_array = sg_table; rd_dev->sg_table_count = sg_tables; rc = rd_allocate_sgl_table(rd_dev, sg_table, total_sg_needed, 0x00); if (rc) return rc; pr_debug("CORE_RD[%u] - Built Ramdisk Device ID: %u space of" " %u pages in %u tables\n", rd_dev->rd_host->rd_host_id, rd_dev->rd_dev_id, rd_dev->rd_page_count, rd_dev->sg_table_count); return 0; }
static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block_size) { struct rd_dev_sg_table *sg_table; u32 total_sg_needed, sg_tables; u32 max_sg_per_table = (RD_MAX_ALLOCATION_SIZE / sizeof(struct scatterlist)); int rc; if (rd_dev->rd_flags & RDF_NULLIO) return 0; /* * prot_length=8byte dif data * tot sg needed = rd_page_count * (PGSZ/block_size) * * (prot_length/block_size) + pad * PGSZ canceled each other. */ total_sg_needed = (rd_dev->rd_page_count * prot_length / block_size) + 1; sg_tables = (total_sg_needed / max_sg_per_table) + 1; sg_table = kzalloc(sg_tables * sizeof(struct rd_dev_sg_table), GFP_KERNEL); if (!sg_table) { pr_err("Unable to allocate memory for Ramdisk protection" " scatterlist tables\n"); return -ENOMEM; } rd_dev->sg_prot_array = sg_table; rd_dev->sg_prot_count = sg_tables; rc = rd_allocate_sgl_table(rd_dev, sg_table, total_sg_needed, 0xff); if (rc) return rc; pr_debug("CORE_RD[%u] - Built Ramdisk Device ID: %u prot space of" " %u pages in %u tables\n", rd_dev->rd_host->rd_host_id, rd_dev->rd_dev_id, total_sg_needed, rd_dev->sg_prot_count); return 0; }