Skip to content

Commit 89d3cf6

Browse files
Jeff SkirvinJames Bottomley
Jeff Skirvin
authored and
James Bottomley
committed
[SCSI] libsas: add mutex for SMP task execution
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 <[email protected]> Signed-off-by: Dan Williams <[email protected]> Signed-off-by: James Bottomley <[email protected]>
1 parent 1f4fe89 commit 89d3cf6

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

drivers/scsi/libsas/sas_discover.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,22 @@
3737

3838
void sas_init_dev(struct domain_device *dev)
3939
{
40-
switch (dev->dev_type) {
41-
case SAS_END_DEV:
42-
break;
43-
case EDGE_DEV:
44-
case FANOUT_DEV:
45-
INIT_LIST_HEAD(&dev->ex_dev.children);
46-
break;
47-
case SATA_DEV:
48-
case SATA_PM:
49-
case SATA_PM_PORT:
50-
INIT_LIST_HEAD(&dev->sata_dev.children);
51-
break;
52-
default:
53-
break;
54-
}
40+
switch (dev->dev_type) {
41+
case SAS_END_DEV:
42+
break;
43+
case EDGE_DEV:
44+
case FANOUT_DEV:
45+
INIT_LIST_HEAD(&dev->ex_dev.children);
46+
mutex_init(&dev->ex_dev.cmd_mutex);
47+
break;
48+
case SATA_DEV:
49+
case SATA_PM:
50+
case SATA_PM_PORT:
51+
INIT_LIST_HEAD(&dev->sata_dev.children);
52+
break;
53+
default:
54+
break;
55+
}
5556
}
5657

5758
/* ---------- Domain device discovery ---------- */

drivers/scsi/libsas/sas_expander.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
7272
struct sas_internal *i =
7373
to_sas_internal(dev->port->ha->core.shost->transportt);
7474

75+
mutex_lock(&dev->ex_dev.cmd_mutex);
7576
for (retry = 0; retry < 3; retry++) {
7677
task = sas_alloc_task(GFP_KERNEL);
77-
if (!task)
78-
return -ENOMEM;
79-
78+
if (!task) {
79+
res = -ENOMEM;
80+
break;
81+
}
8082
task->dev = dev;
8183
task->task_proto = dev->tproto;
8284
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,
9496
if (res) {
9597
del_timer(&task->timer);
9698
SAS_DPRINTK("executing SMP task failed:%d\n", res);
97-
goto ex_err;
99+
break;
98100
}
99101

100102
wait_for_completion(&task->completion);
@@ -104,21 +106,23 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
104106
i->dft->lldd_abort_task(task);
105107
if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
106108
SAS_DPRINTK("SMP task aborted and not done\n");
107-
goto ex_err;
109+
break;
108110
}
109111
}
110112
if (task->task_status.resp == SAS_TASK_COMPLETE &&
111113
task->task_status.stat == SAM_STAT_GOOD) {
112114
res = 0;
113115
break;
114-
} if (task->task_status.resp == SAS_TASK_COMPLETE &&
115-
task->task_status.stat == SAS_DATA_UNDERRUN) {
116+
}
117+
if (task->task_status.resp == SAS_TASK_COMPLETE &&
118+
task->task_status.stat == SAS_DATA_UNDERRUN) {
116119
/* no error, but return the number of bytes of
117120
* underrun */
118121
res = task->task_status.residual;
119122
break;
120-
} if (task->task_status.resp == SAS_TASK_COMPLETE &&
121-
task->task_status.stat == SAS_DATA_OVERRUN) {
123+
}
124+
if (task->task_status.resp == SAS_TASK_COMPLETE &&
125+
task->task_status.stat == SAS_DATA_OVERRUN) {
122126
res = -EMSGSIZE;
123127
break;
124128
} else {
@@ -131,11 +135,10 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
131135
task = NULL;
132136
}
133137
}
134-
ex_err:
138+
mutex_unlock(&dev->ex_dev.cmd_mutex);
139+
135140
BUG_ON(retry == 3 && task != NULL);
136-
if (task != NULL) {
137-
sas_free_task(task);
138-
}
141+
sas_free_task(task);
139142
return res;
140143
}
141144

include/scsi/libsas.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ struct expander_device {
153153

154154
struct ex_phy *ex_phy;
155155
struct sas_port *parent_port;
156+
157+
struct mutex cmd_mutex;
156158
};
157159

158160
/* ---------- SATA device ---------- */

0 commit comments

Comments
 (0)