aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-eh.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-06-22 23:46:10 -0400
committerJeff Garzik <jeff@garzik.org>2006-06-22 23:46:10 -0400
commitba6a13083c1b720a47c05bee7bedbb6ef06c4611 (patch)
tree26f9d8d37145fac426744f96ecf006ec0a481e31 /drivers/scsi/libata-eh.c
parent47005f255ed126a4b48a1a2f63164fb1d83bcb0a (diff)
[libata] Add host lock to struct ata_port
Prepare for changes required to support SATA devices attached to SAS HBAs. For these devices we don't want to use host_set at all, since libata will not be the owner of struct scsi_host. Signed-off-by: Brian King <brking@us.ibm.com> (with slight merge modifications made by...) Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/scsi/libata-eh.c')
-rw-r--r--drivers/scsi/libata-eh.c65
1 files changed, 32 insertions, 33 deletions
diff --git a/drivers/scsi/libata-eh.c b/drivers/scsi/libata-eh.c
index 70b623988a9f..823385981a7a 100644
--- a/drivers/scsi/libata-eh.c
+++ b/drivers/scsi/libata-eh.c
@@ -128,7 +128,7 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
128 } 128 }
129 129
130 ret = EH_HANDLED; 130 ret = EH_HANDLED;
131 spin_lock_irqsave(&ap->host_set->lock, flags); 131 spin_lock_irqsave(ap->lock, flags);
132 qc = ata_qc_from_tag(ap, ap->active_tag); 132 qc = ata_qc_from_tag(ap, ap->active_tag);
133 if (qc) { 133 if (qc) {
134 WARN_ON(qc->scsicmd != cmd); 134 WARN_ON(qc->scsicmd != cmd);
@@ -136,7 +136,7 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
136 qc->err_mask |= AC_ERR_TIMEOUT; 136 qc->err_mask |= AC_ERR_TIMEOUT;
137 ret = EH_NOT_HANDLED; 137 ret = EH_NOT_HANDLED;
138 } 138 }
139 spin_unlock_irqrestore(&ap->host_set->lock, flags); 139 spin_unlock_irqrestore(ap->lock, flags);
140 140
141 out: 141 out:
142 DPRINTK("EXIT, ret=%d\n", ret); 142 DPRINTK("EXIT, ret=%d\n", ret);
@@ -158,7 +158,7 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
158void ata_scsi_error(struct Scsi_Host *host) 158void ata_scsi_error(struct Scsi_Host *host)
159{ 159{
160 struct ata_port *ap = ata_shost_to_port(host); 160 struct ata_port *ap = ata_shost_to_port(host);
161 spinlock_t *hs_lock = &ap->host_set->lock; 161 spinlock_t *ap_lock = ap->lock;
162 int i, repeat_cnt = ATA_EH_MAX_REPEAT; 162 int i, repeat_cnt = ATA_EH_MAX_REPEAT;
163 unsigned long flags; 163 unsigned long flags;
164 164
@@ -185,7 +185,7 @@ void ata_scsi_error(struct Scsi_Host *host)
185 struct scsi_cmnd *scmd, *tmp; 185 struct scsi_cmnd *scmd, *tmp;
186 int nr_timedout = 0; 186 int nr_timedout = 0;
187 187
188 spin_lock_irqsave(hs_lock, flags); 188 spin_lock_irqsave(ap_lock, flags);
189 189
190 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { 190 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
191 struct ata_queued_cmd *qc; 191 struct ata_queued_cmd *qc;
@@ -224,15 +224,15 @@ void ata_scsi_error(struct Scsi_Host *host)
224 if (nr_timedout) 224 if (nr_timedout)
225 __ata_port_freeze(ap); 225 __ata_port_freeze(ap);
226 226
227 spin_unlock_irqrestore(hs_lock, flags); 227 spin_unlock_irqrestore(ap_lock, flags);
228 } else 228 } else
229 spin_unlock_wait(hs_lock); 229 spin_unlock_wait(ap_lock);
230 230
231 repeat: 231 repeat:
232 /* invoke error handler */ 232 /* invoke error handler */
233 if (ap->ops->error_handler) { 233 if (ap->ops->error_handler) {
234 /* fetch & clear EH info */ 234 /* fetch & clear EH info */
235 spin_lock_irqsave(hs_lock, flags); 235 spin_lock_irqsave(ap_lock, flags);
236 236
237 memset(&ap->eh_context, 0, sizeof(ap->eh_context)); 237 memset(&ap->eh_context, 0, sizeof(ap->eh_context));
238 ap->eh_context.i = ap->eh_info; 238 ap->eh_context.i = ap->eh_info;
@@ -241,7 +241,7 @@ void ata_scsi_error(struct Scsi_Host *host)
241 ap->flags |= ATA_FLAG_EH_IN_PROGRESS; 241 ap->flags |= ATA_FLAG_EH_IN_PROGRESS;
242 ap->flags &= ~ATA_FLAG_EH_PENDING; 242 ap->flags &= ~ATA_FLAG_EH_PENDING;
243 243
244 spin_unlock_irqrestore(hs_lock, flags); 244 spin_unlock_irqrestore(ap_lock, flags);
245 245
246 /* invoke EH. if unloading, just finish failed qcs */ 246 /* invoke EH. if unloading, just finish failed qcs */
247 if (!(ap->flags & ATA_FLAG_UNLOADING)) 247 if (!(ap->flags & ATA_FLAG_UNLOADING))
@@ -253,14 +253,14 @@ void ata_scsi_error(struct Scsi_Host *host)
253 * recovered the port but before this point. Repeat 253 * recovered the port but before this point. Repeat
254 * EH in such case. 254 * EH in such case.
255 */ 255 */
256 spin_lock_irqsave(hs_lock, flags); 256 spin_lock_irqsave(ap_lock, flags);
257 257
258 if (ap->flags & ATA_FLAG_EH_PENDING) { 258 if (ap->flags & ATA_FLAG_EH_PENDING) {
259 if (--repeat_cnt) { 259 if (--repeat_cnt) {
260 ata_port_printk(ap, KERN_INFO, 260 ata_port_printk(ap, KERN_INFO,
261 "EH pending after completion, " 261 "EH pending after completion, "
262 "repeating EH (cnt=%d)\n", repeat_cnt); 262 "repeating EH (cnt=%d)\n", repeat_cnt);
263 spin_unlock_irqrestore(hs_lock, flags); 263 spin_unlock_irqrestore(ap_lock, flags);
264 goto repeat; 264 goto repeat;
265 } 265 }
266 ata_port_printk(ap, KERN_ERR, "EH pending after %d " 266 ata_port_printk(ap, KERN_ERR, "EH pending after %d "
@@ -270,14 +270,14 @@ void ata_scsi_error(struct Scsi_Host *host)
270 /* this run is complete, make sure EH info is clear */ 270 /* this run is complete, make sure EH info is clear */
271 memset(&ap->eh_info, 0, sizeof(ap->eh_info)); 271 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
272 272
273 /* Clear host_eh_scheduled while holding hs_lock such 273 /* Clear host_eh_scheduled while holding ap_lock such
274 * that if exception occurs after this point but 274 * that if exception occurs after this point but
275 * before EH completion, SCSI midlayer will 275 * before EH completion, SCSI midlayer will
276 * re-initiate EH. 276 * re-initiate EH.
277 */ 277 */
278 host->host_eh_scheduled = 0; 278 host->host_eh_scheduled = 0;
279 279
280 spin_unlock_irqrestore(hs_lock, flags); 280 spin_unlock_irqrestore(ap_lock, flags);
281 } else { 281 } else {
282 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL); 282 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
283 ap->ops->eng_timeout(ap); 283 ap->ops->eng_timeout(ap);
@@ -289,7 +289,7 @@ void ata_scsi_error(struct Scsi_Host *host)
289 scsi_eh_flush_done_q(&ap->eh_done_q); 289 scsi_eh_flush_done_q(&ap->eh_done_q);
290 290
291 /* clean up */ 291 /* clean up */
292 spin_lock_irqsave(hs_lock, flags); 292 spin_lock_irqsave(ap_lock, flags);
293 293
294 if (ap->flags & ATA_FLAG_LOADING) { 294 if (ap->flags & ATA_FLAG_LOADING) {
295 ap->flags &= ~ATA_FLAG_LOADING; 295 ap->flags &= ~ATA_FLAG_LOADING;
@@ -306,7 +306,7 @@ void ata_scsi_error(struct Scsi_Host *host)
306 ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS; 306 ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS;
307 wake_up_all(&ap->eh_wait_q); 307 wake_up_all(&ap->eh_wait_q);
308 308
309 spin_unlock_irqrestore(hs_lock, flags); 309 spin_unlock_irqrestore(ap_lock, flags);
310 310
311 DPRINTK("EXIT\n"); 311 DPRINTK("EXIT\n");
312} 312}
@@ -326,17 +326,17 @@ void ata_port_wait_eh(struct ata_port *ap)
326 DEFINE_WAIT(wait); 326 DEFINE_WAIT(wait);
327 327
328 retry: 328 retry:
329 spin_lock_irqsave(&ap->host_set->lock, flags); 329 spin_lock_irqsave(ap->lock, flags);
330 330
331 while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) { 331 while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) {
332 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); 332 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
333 spin_unlock_irqrestore(&ap->host_set->lock, flags); 333 spin_unlock_irqrestore(ap->lock, flags);
334 schedule(); 334 schedule();
335 spin_lock_irqsave(&ap->host_set->lock, flags); 335 spin_lock_irqsave(ap->lock, flags);
336 } 336 }
337 finish_wait(&ap->eh_wait_q, &wait); 337 finish_wait(&ap->eh_wait_q, &wait);
338 338
339 spin_unlock_irqrestore(&ap->host_set->lock, flags); 339 spin_unlock_irqrestore(ap->lock, flags);
340 340
341 /* make sure SCSI EH is complete */ 341 /* make sure SCSI EH is complete */
342 if (scsi_host_in_recovery(ap->host)) { 342 if (scsi_host_in_recovery(ap->host)) {
@@ -368,7 +368,6 @@ void ata_port_wait_eh(struct ata_port *ap)
368static void ata_qc_timeout(struct ata_queued_cmd *qc) 368static void ata_qc_timeout(struct ata_queued_cmd *qc)
369{ 369{
370 struct ata_port *ap = qc->ap; 370 struct ata_port *ap = qc->ap;
371 struct ata_host_set *host_set = ap->host_set;
372 u8 host_stat = 0, drv_stat; 371 u8 host_stat = 0, drv_stat;
373 unsigned long flags; 372 unsigned long flags;
374 373
@@ -376,7 +375,7 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
376 375
377 ap->hsm_task_state = HSM_ST_IDLE; 376 ap->hsm_task_state = HSM_ST_IDLE;
378 377
379 spin_lock_irqsave(&host_set->lock, flags); 378 spin_lock_irqsave(ap->lock, flags);
380 379
381 switch (qc->tf.protocol) { 380 switch (qc->tf.protocol) {
382 381
@@ -405,7 +404,7 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
405 break; 404 break;
406 } 405 }
407 406
408 spin_unlock_irqrestore(&host_set->lock, flags); 407 spin_unlock_irqrestore(ap->lock, flags);
409 408
410 ata_eh_qc_complete(qc); 409 ata_eh_qc_complete(qc);
411 410
@@ -592,9 +591,9 @@ void ata_eh_freeze_port(struct ata_port *ap)
592 if (!ap->ops->error_handler) 591 if (!ap->ops->error_handler)
593 return; 592 return;
594 593
595 spin_lock_irqsave(&ap->host_set->lock, flags); 594 spin_lock_irqsave(ap->lock, flags);
596 __ata_port_freeze(ap); 595 __ata_port_freeze(ap);
597 spin_unlock_irqrestore(&ap->host_set->lock, flags); 596 spin_unlock_irqrestore(ap->lock, flags);
598} 597}
599 598
600/** 599/**
@@ -613,14 +612,14 @@ void ata_eh_thaw_port(struct ata_port *ap)
613 if (!ap->ops->error_handler) 612 if (!ap->ops->error_handler)
614 return; 613 return;
615 614
616 spin_lock_irqsave(&ap->host_set->lock, flags); 615 spin_lock_irqsave(ap->lock, flags);
617 616
618 ap->flags &= ~ATA_FLAG_FROZEN; 617 ap->flags &= ~ATA_FLAG_FROZEN;
619 618
620 if (ap->ops->thaw) 619 if (ap->ops->thaw)
621 ap->ops->thaw(ap); 620 ap->ops->thaw(ap);
622 621
623 spin_unlock_irqrestore(&ap->host_set->lock, flags); 622 spin_unlock_irqrestore(ap->lock, flags);
624 623
625 DPRINTK("ata%u port thawed\n", ap->id); 624 DPRINTK("ata%u port thawed\n", ap->id);
626} 625}
@@ -636,11 +635,11 @@ static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
636 struct scsi_cmnd *scmd = qc->scsicmd; 635 struct scsi_cmnd *scmd = qc->scsicmd;
637 unsigned long flags; 636 unsigned long flags;
638 637
639 spin_lock_irqsave(&ap->host_set->lock, flags); 638 spin_lock_irqsave(ap->lock, flags);
640 qc->scsidone = ata_eh_scsidone; 639 qc->scsidone = ata_eh_scsidone;
641 __ata_qc_complete(qc); 640 __ata_qc_complete(qc);
642 WARN_ON(ata_tag_valid(qc->tag)); 641 WARN_ON(ata_tag_valid(qc->tag));
643 spin_unlock_irqrestore(&ap->host_set->lock, flags); 642 spin_unlock_irqrestore(ap->lock, flags);
644 643
645 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); 644 scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
646} 645}
@@ -694,7 +693,7 @@ static void ata_eh_detach_dev(struct ata_device *dev)
694 693
695 ata_dev_disable(dev); 694 ata_dev_disable(dev);
696 695
697 spin_lock_irqsave(&ap->host_set->lock, flags); 696 spin_lock_irqsave(ap->lock, flags);
698 697
699 dev->flags &= ~ATA_DFLAG_DETACH; 698 dev->flags &= ~ATA_DFLAG_DETACH;
700 699
@@ -703,7 +702,7 @@ static void ata_eh_detach_dev(struct ata_device *dev)
703 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 702 ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
704 } 703 }
705 704
706 spin_unlock_irqrestore(&ap->host_set->lock, flags); 705 spin_unlock_irqrestore(ap->lock, flags);
707} 706}
708 707
709static void ata_eh_clear_action(struct ata_device *dev, 708static void ata_eh_clear_action(struct ata_device *dev,
@@ -749,10 +748,10 @@ static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev,
749{ 748{
750 unsigned long flags; 749 unsigned long flags;
751 750
752 spin_lock_irqsave(&ap->host_set->lock, flags); 751 spin_lock_irqsave(ap->lock, flags);
753 ata_eh_clear_action(dev, &ap->eh_info, action); 752 ata_eh_clear_action(dev, &ap->eh_info, action);
754 ap->flags |= ATA_FLAG_RECOVERED; 753 ap->flags |= ATA_FLAG_RECOVERED;
755 spin_unlock_irqrestore(&ap->host_set->lock, flags); 754 spin_unlock_irqrestore(ap->lock, flags);
756} 755}
757 756
758/** 757/**
@@ -1625,9 +1624,9 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1625 break; 1624 break;
1626 } 1625 }
1627 1626
1628 spin_lock_irqsave(&ap->host_set->lock, flags); 1627 spin_lock_irqsave(ap->lock, flags);
1629 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 1628 ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
1630 spin_unlock_irqrestore(&ap->host_set->lock, flags); 1629 spin_unlock_irqrestore(ap->lock, flags);
1631 } 1630 }
1632 } 1631 }
1633 1632