Signed-off-by: Jianpeng Ma <majianp...@gmail.com>
---
 drivers/scsi/scsi-mq.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi-mq.c b/drivers/scsi/scsi-mq.c
index 78b05c1..7b8137b 100644
--- a/drivers/scsi/scsi-mq.c
+++ b/drivers/scsi/scsi-mq.c
@@ -154,6 +154,7 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct 
scsi_device *sdev)
        struct request *rq;
        struct scsi_cmnd *sc;
        int i, j;
+       int sgl_size;
 
        sdev->sdev_mq_reg.ops = &scsi_mq_ops;
        sdev->sdev_mq_reg.queue_depth = min((short)sh->hostt->can_queue,
@@ -186,13 +187,20 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct 
scsi_device *sdev)
         * Set existing Scsi_Host based hardware limits from scsi_lib.c
         */
        scsi_init_request_queue(q, sh);
+
+       if (sh->hostt->sg_tablesize > SCSI_MQ_MAX_SG_SEGMENTS) {
+               printk(KERN_ERR"Host%d sg_tablesize too larger than %d\n",
+                       sh->host_no, SCSI_MQ_MAX_SG_SEGMENTS);
+               sh->hostt->sg_tablesize = SCSI_MQ_MAX_SG_SEGMENTS;
+       }
+       sgl_size = sh->hostt->sg_tablesize * sizeof(struct scatterlist);
+
        /*
         * Do remaining setup of pre-allocated scsi_cmnd descriptor map for
         * each scsi-mq hctx
         */
 //FIXME: Do cmd->prot_sdb setup for DIF from scsi_host_alloc_command
        queue_for_each_hw_ctx(q, hctx, i) {
-
                printk("Performing sc map setup on q: %p hctx: %p i: %d\n", q, 
hctx, i);
 
                for (j = 0; j < hctx->queue_depth; j++) {
@@ -201,8 +209,7 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct 
scsi_device *sdev)
                        sc->device = sdev;
                        sc->ll_list.next = NULL;
 
-//FIXME: Pre-allocation of sg tables based upon max_sectors
-                       sc->mq_sgl = kzalloc_node(SCSI_MQ_SGL_SIZE,
+                       sc->mq_sgl = kzalloc_node(sgl_size,
                                        GFP_KERNEL, 
sdev->sdev_mq_reg.numa_node);
                        if (!sc->mq_sgl) {
                                pr_err("Unable to pre-allocate sc->sdb\n");
-- 
1.7.10.4

Reply via email to