aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Van Assche <bart.vanassche@wdc.com>2018-02-12 11:58:19 -0500
committerMartin K. Petersen <martin.petersen@oracle.com>2018-02-13 21:49:15 -0500
commited4414cef2ad0ad0afb3d77a6fdde425d7f7ec4d (patch)
treed76cd830f86a373d7f3c23391d04af20725accfd
parentf5594686f5f06637bea144159dfe147dae3040d2 (diff)
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>
-rw-r--r--drivers/scsi/Kconfig1
-rw-r--r--drivers/scsi/pmcraid.c43
-rw-r--r--drivers/scsi/pmcraid.h2
3 files changed, 6 insertions, 40 deletions
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 7e3f6e37fb66..8647ca9199b3 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1577,6 +1577,7 @@ config ZFCP
1577config SCSI_PMCRAID 1577config SCSI_PMCRAID
1578 tristate "PMC SIERRA Linux MaxRAID adapter support" 1578 tristate "PMC SIERRA Linux MaxRAID adapter support"
1579 depends on PCI && SCSI && NET 1579 depends on PCI && SCSI && NET
1580 select SGL_ALLOC
1580 ---help--- 1581 ---help---
1581 This driver supports the PMC SIERRA MaxRAID adapters. 1582 This driver supports the PMC SIERRA MaxRAID adapters.
1582 1583
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 9330cc5ba34d..95530393872d 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -3225,12 +3225,7 @@ static int pmcraid_build_ioadl(
3225 */ 3225 */
3226static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) 3226static void pmcraid_free_sglist(struct pmcraid_sglist *sglist)
3227{ 3227{
3228 int i; 3228 sgl_free_order(sglist->scatterlist, sglist->order);
3229
3230 for (i = 0; i < sglist->num_sg; i++)
3231 __free_pages(sg_page(&(sglist->scatterlist[i])),
3232 sglist->order);
3233
3234 kfree(sglist); 3229 kfree(sglist);
3235} 3230}
3236 3231
@@ -3247,50 +3242,20 @@ static void pmcraid_free_sglist(struct pmcraid_sglist *sglist)
3247static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen) 3242static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen)
3248{ 3243{
3249 struct pmcraid_sglist *sglist; 3244 struct pmcraid_sglist *sglist;
3250 struct scatterlist *scatterlist;
3251 struct page *page;
3252 int num_elem, i, j;
3253 int sg_size; 3245 int sg_size;
3254 int order; 3246 int order;
3255 int bsize_elem;
3256 3247
3257 sg_size = buflen / (PMCRAID_MAX_IOADLS - 1); 3248 sg_size = buflen / (PMCRAID_MAX_IOADLS - 1);
3258 order = (sg_size > 0) ? get_order(sg_size) : 0; 3249 order = (sg_size > 0) ? get_order(sg_size) : 0;
3259 bsize_elem = PAGE_SIZE * (1 << order);
3260
3261 /* Determine the actual number of sg entries needed */
3262 if (buflen % bsize_elem)
3263 num_elem = (buflen / bsize_elem) + 1;
3264 else
3265 num_elem = buflen / bsize_elem;
3266 3250
3267 /* Allocate a scatter/gather list for the DMA */ 3251 /* Allocate a scatter/gather list for the DMA */
3268 sglist = kzalloc(sizeof(struct pmcraid_sglist) + 3252 sglist = kzalloc(sizeof(struct pmcraid_sglist), GFP_KERNEL);
3269 (sizeof(struct scatterlist) * (num_elem - 1)),
3270 GFP_KERNEL);
3271
3272 if (sglist == NULL) 3253 if (sglist == NULL)
3273 return NULL; 3254 return NULL;
3274 3255
3275 scatterlist = sglist->scatterlist;
3276 sg_init_table(scatterlist, num_elem);
3277 sglist->order = order; 3256 sglist->order = order;
3278 sglist->num_sg = num_elem; 3257 sgl_alloc_order(buflen, order, false,
3279 sg_size = buflen; 3258 GFP_KERNEL | GFP_DMA | __GFP_ZERO, &sglist->num_sg);
3280
3281 for (i = 0; i < num_elem; i++) {
3282 page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order);
3283 if (!page) {
3284 for (j = i - 1; j >= 0; j--)
3285 __free_pages(sg_page(&scatterlist[j]), order);
3286 kfree(sglist);
3287 return NULL;
3288 }
3289
3290 sg_set_page(&scatterlist[i], page,
3291 sg_size < bsize_elem ? sg_size : bsize_elem, 0);
3292 sg_size -= bsize_elem;
3293 }
3294 3259
3295 return sglist; 3260 return sglist;
3296} 3261}
diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
index 44da91712115..754ef30927e2 100644
--- a/drivers/scsi/pmcraid.h
+++ b/drivers/scsi/pmcraid.h
@@ -542,7 +542,7 @@ struct pmcraid_sglist {
542 u32 order; 542 u32 order;
543 u32 num_sg; 543 u32 num_sg;
544 u32 num_dma_sg; 544 u32 num_dma_sg;
545 struct scatterlist scatterlist[1]; 545 struct scatterlist *scatterlist;
546}; 546};
547 547
548/* page D0 inquiry data of focal point resource */ 548/* page D0 inquiry data of focal point resource */