]> git.karo-electronics.de Git - linux-beck.git/commitdiff
[SCSI] libsas: add mutex for SMP task execution
authorJeff Skirvin <jeffrey.d.skirvin@intel.com>
Wed, 16 Nov 2011 09:44:13 +0000 (09:44 +0000)
committerJames Bottomley <JBottomley@Parallels.com>
Sun, 19 Feb 2012 20:22:49 +0000 (14:22 -0600)
SAS does not tag SMP requests, and at least one lldd (isci) does not permit
more than one in-flight request at a time.

[jejb: fix sas_init_dev tab issues while we're at it]
Signed-off-by: Jeff Skirvin <jeffrey.d.skirvin@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/libsas/sas_discover.c
drivers/scsi/libsas/sas_expander.c
include/scsi/libsas.h

index bad5eba4a92b67455bf7b8faa5b3f0c774525975..c56cc64008190f5231eb3a59b851be75c13eb0f7 100644 (file)
 
 void sas_init_dev(struct domain_device *dev)
 {
-        switch (dev->dev_type) {
-        case SAS_END_DEV:
-                break;
-        case EDGE_DEV:
-        case FANOUT_DEV:
-                INIT_LIST_HEAD(&dev->ex_dev.children);
-                break;
-        case SATA_DEV:
-        case SATA_PM:
-        case SATA_PM_PORT:
-                INIT_LIST_HEAD(&dev->sata_dev.children);
-                break;
-        default:
-                break;
-        }
+       switch (dev->dev_type) {
+       case SAS_END_DEV:
+               break;
+       case EDGE_DEV:
+       case FANOUT_DEV:
+               INIT_LIST_HEAD(&dev->ex_dev.children);
+               mutex_init(&dev->ex_dev.cmd_mutex);
+               break;
+       case SATA_DEV:
+       case SATA_PM:
+       case SATA_PM_PORT:
+               INIT_LIST_HEAD(&dev->sata_dev.children);
+               break;
+       default:
+               break;
+       }
 }
 
 /* ---------- Domain device discovery ---------- */
index d3c1a29b8a2aaba4b5cad835890554f97b4f136e..7c59f97c02872d127a6e8ba0ad7e705bceec8b00 100644 (file)
@@ -72,11 +72,13 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
        struct sas_internal *i =
                to_sas_internal(dev->port->ha->core.shost->transportt);
 
+       mutex_lock(&dev->ex_dev.cmd_mutex);
        for (retry = 0; retry < 3; retry++) {
                task = sas_alloc_task(GFP_KERNEL);
-               if (!task)
-                       return -ENOMEM;
-
+               if (!task) {
+                       res = -ENOMEM;
+                       break;
+               }
                task->dev = dev;
                task->task_proto = dev->tproto;
                sg_init_one(&task->smp_task.smp_req, req, req_size);
@@ -94,7 +96,7 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
                if (res) {
                        del_timer(&task->timer);
                        SAS_DPRINTK("executing SMP task failed:%d\n", res);
-                       goto ex_err;
+                       break;
                }
 
                wait_for_completion(&task->completion);
@@ -104,21 +106,23 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
                        i->dft->lldd_abort_task(task);
                        if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
                                SAS_DPRINTK("SMP task aborted and not done\n");
-                               goto ex_err;
+                               break;
                        }
                }
                if (task->task_status.resp == SAS_TASK_COMPLETE &&
                    task->task_status.stat == SAM_STAT_GOOD) {
                        res = 0;
                        break;
-               } if (task->task_status.resp == SAS_TASK_COMPLETE &&
-                     task->task_status.stat == SAS_DATA_UNDERRUN) {
+               }
+               if (task->task_status.resp == SAS_TASK_COMPLETE &&
+                   task->task_status.stat == SAS_DATA_UNDERRUN) {
                        /* no error, but return the number of bytes of
                         * underrun */
                        res = task->task_status.residual;
                        break;
-               } if (task->task_status.resp == SAS_TASK_COMPLETE &&
-                     task->task_status.stat == SAS_DATA_OVERRUN) {
+               }
+               if (task->task_status.resp == SAS_TASK_COMPLETE &&
+                   task->task_status.stat == SAS_DATA_OVERRUN) {
                        res = -EMSGSIZE;
                        break;
                } else {
@@ -131,11 +135,10 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
                        task = NULL;
                }
        }
-ex_err:
+       mutex_unlock(&dev->ex_dev.cmd_mutex);
+
        BUG_ON(retry == 3 && task != NULL);
-       if (task != NULL) {
-               sas_free_task(task);
-       }
+       sas_free_task(task);
        return res;
 }
 
index f388ba53612871cd8a7fb52239f962157c19e02c..18704a2e4f071a538924eccf6ff87ab3bfcd4430 100644 (file)
@@ -153,6 +153,8 @@ struct expander_device {
 
        struct ex_phy *ex_phy;
        struct sas_port *parent_port;
+
+       struct mutex cmd_mutex;
 };
 
 /* ---------- SATA device ---------- */