scsi: pmcraid: Use sgl_alloc_order() and sgl_free_order()

Use the sgl_alloc_order() and sgl_free_order() functions instead of open
coding these functions.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Cc: Anil Ravindranath <anil_ravindranath@pmc-sierra.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Bart Van Assche 2018-02-12 08:58:19 -08:00 committed by Martin K. Petersen
parent f5594686f5
commit ed4414cef2
3 changed files with 6 additions and 40 deletions

View File

@ -1577,6 +1577,7 @@ config ZFCP
config SCSI_PMCRAID config SCSI_PMCRAID
tristate "PMC SIERRA Linux MaxRAID adapter support" tristate "PMC SIERRA Linux MaxRAID adapter support"
depends on PCI && SCSI && NET depends on PCI && SCSI && NET
select SGL_ALLOC
---help--- ---help---
This driver supports the PMC SIERRA MaxRAID adapters. This driver supports the PMC SIERRA MaxRAID adapters.

View File

@ -3225,12 +3225,7 @@ static int pmcraid_build_ioadl(
*/ */
static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) static void pmcraid_free_sglist(struct pmcraid_sglist *sglist)
{ {
int i; sgl_free_order(sglist->scatterlist, sglist->order);
for (i = 0; i < sglist->num_sg; i++)
__free_pages(sg_page(&(sglist->scatterlist[i])),
sglist->order);
kfree(sglist); kfree(sglist);
} }
@ -3247,50 +3242,20 @@ static void pmcraid_free_sglist(struct pmcraid_sglist *sglist)
static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen) static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen)
{ {
struct pmcraid_sglist *sglist; struct pmcraid_sglist *sglist;
struct scatterlist *scatterlist;
struct page *page;
int num_elem, i, j;
int sg_size; int sg_size;
int order; int order;
int bsize_elem;
sg_size = buflen / (PMCRAID_MAX_IOADLS - 1); sg_size = buflen / (PMCRAID_MAX_IOADLS - 1);
order = (sg_size > 0) ? get_order(sg_size) : 0; order = (sg_size > 0) ? get_order(sg_size) : 0;
bsize_elem = PAGE_SIZE * (1 << order);
/* Determine the actual number of sg entries needed */
if (buflen % bsize_elem)
num_elem = (buflen / bsize_elem) + 1;
else
num_elem = buflen / bsize_elem;
/* Allocate a scatter/gather list for the DMA */ /* Allocate a scatter/gather list for the DMA */
sglist = kzalloc(sizeof(struct pmcraid_sglist) + sglist = kzalloc(sizeof(struct pmcraid_sglist), GFP_KERNEL);
(sizeof(struct scatterlist) * (num_elem - 1)),
GFP_KERNEL);
if (sglist == NULL) if (sglist == NULL)
return NULL; return NULL;
scatterlist = sglist->scatterlist;
sg_init_table(scatterlist, num_elem);
sglist->order = order; sglist->order = order;
sglist->num_sg = num_elem; sgl_alloc_order(buflen, order, false,
sg_size = buflen; GFP_KERNEL | GFP_DMA | __GFP_ZERO, &sglist->num_sg);
for (i = 0; i < num_elem; i++) {
page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order);
if (!page) {
for (j = i - 1; j >= 0; j--)
__free_pages(sg_page(&scatterlist[j]), order);
kfree(sglist);
return NULL;
}
sg_set_page(&scatterlist[i], page,
sg_size < bsize_elem ? sg_size : bsize_elem, 0);
sg_size -= bsize_elem;
}
return sglist; return sglist;
} }

View File

@ -542,7 +542,7 @@ struct pmcraid_sglist {
u32 order; u32 order;
u32 num_sg; u32 num_sg;
u32 num_dma_sg; u32 num_dma_sg;
struct scatterlist scatterlist[1]; struct scatterlist *scatterlist;
}; };
/* page D0 inquiry data of focal point resource */ /* page D0 inquiry data of focal point resource */