~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/scsi/scsi_lib.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 
68
68
struct kmem_cache *scsi_sdb_cache;
69
69
 
70
 
static void scsi_run_queue(struct request_queue *q);
 
70
/*
 
71
 * When to reinvoke queueing after a resource shortage. It's 3 msecs to
 
72
 * not change behaviour from the previous unplug mechanism, experimentation
 
73
 * may prove this needs changing.
 
74
 */
 
75
#define SCSI_QUEUE_DELAY        3
71
76
 
72
77
/*
73
78
 * Function:    scsi_unprep_request()
149
154
        /*
150
155
         * Requeue this command.  It will go before all other commands
151
156
         * that are already in the queue.
152
 
         *
153
 
         * NOTE: there is magic here about the way the queue is plugged if
154
 
         * we have no outstanding commands.
155
 
         * 
156
 
         * Although we *don't* plug the queue, we call the request
157
 
         * function.  The SCSI request function detects the blocked condition
158
 
         * and plugs the queue appropriately.
159
 
         */
 
157
         */
160
158
        spin_lock_irqsave(q->queue_lock, flags);
161
159
        blk_requeue_request(q, cmd->request);
162
160
        spin_unlock_irqrestore(q->queue_lock, flags);
163
161
 
164
 
        scsi_run_queue(q);
 
162
        kblockd_schedule_work(q, &device->requeue_work);
165
163
 
166
164
        return 0;
167
165
}
400
398
static void scsi_run_queue(struct request_queue *q)
401
399
{
402
400
        struct scsi_device *sdev = q->queuedata;
403
 
        struct Scsi_Host *shost = sdev->host;
 
401
        struct Scsi_Host *shost;
404
402
        LIST_HEAD(starved_list);
405
403
        unsigned long flags;
406
404
 
 
405
        /* if the device is dead, sdev will be NULL, so no queue to run */
 
406
        if (!sdev)
 
407
                return;
 
408
 
 
409
        shost = sdev->host;
407
410
        if (scsi_target(sdev)->single_lun)
408
411
                scsi_single_lun_run(sdev);
409
412
 
411
414
        list_splice_init(&shost->starved_list, &starved_list);
412
415
 
413
416
        while (!list_empty(&starved_list)) {
414
 
                int flagset;
415
 
 
416
417
                /*
417
418
                 * As long as shost is accepting commands and we have
418
419
                 * starved queues, call blk_run_queue. scsi_request_fn
436
437
                }
437
438
 
438
439
                spin_unlock(shost->host_lock);
439
 
 
440
440
                spin_lock(sdev->request_queue->queue_lock);
441
 
                flagset = test_bit(QUEUE_FLAG_REENTER, &q->queue_flags) &&
442
 
                                !test_bit(QUEUE_FLAG_REENTER,
443
 
                                        &sdev->request_queue->queue_flags);
444
 
                if (flagset)
445
 
                        queue_flag_set(QUEUE_FLAG_REENTER, sdev->request_queue);
446
 
                __blk_run_queue(sdev->request_queue, false);
447
 
                if (flagset)
448
 
                        queue_flag_clear(QUEUE_FLAG_REENTER, sdev->request_queue);
 
441
                __blk_run_queue(sdev->request_queue);
449
442
                spin_unlock(sdev->request_queue->queue_lock);
450
 
 
451
443
                spin_lock(shost->host_lock);
452
444
        }
453
445
        /* put any unprocessed entries back */
457
449
        blk_run_queue(q);
458
450
}
459
451
 
 
452
void scsi_requeue_run_queue(struct work_struct *work)
 
453
{
 
454
        struct scsi_device *sdev;
 
455
        struct request_queue *q;
 
456
 
 
457
        sdev = container_of(work, struct scsi_device, requeue_work);
 
458
        q = sdev->request_queue;
 
459
        scsi_run_queue(q);
 
460
}
 
461
 
460
462
/*
461
463
 * Function:    scsi_requeue_command()
462
464
 *
667
669
}
668
670
EXPORT_SYMBOL(scsi_release_buffers);
669
671
 
 
672
static int __scsi_error_from_host_byte(struct scsi_cmnd *cmd, int result)
 
673
{
 
674
        int error = 0;
 
675
 
 
676
        switch(host_byte(result)) {
 
677
        case DID_TRANSPORT_FAILFAST:
 
678
                error = -ENOLINK;
 
679
                break;
 
680
        case DID_TARGET_FAILURE:
 
681
                cmd->result |= (DID_OK << 16);
 
682
                error = -EREMOTEIO;
 
683
                break;
 
684
        case DID_NEXUS_FAILURE:
 
685
                cmd->result |= (DID_OK << 16);
 
686
                error = -EBADE;
 
687
                break;
 
688
        default:
 
689
                error = -EIO;
 
690
                break;
 
691
        }
 
692
 
 
693
        return error;
 
694
}
 
695
 
670
696
/*
671
697
 * Function:    scsi_io_completion()
672
698
 *
737
763
                                req->sense_len = len;
738
764
                        }
739
765
                        if (!sense_deferred)
740
 
                                error = -EIO;
 
766
                                error = __scsi_error_from_host_byte(cmd, result);
741
767
                }
742
768
 
743
769
                req->resid_len = scsi_get_resid(cmd);
796
822
        if (scsi_end_request(cmd, error, good_bytes, result == 0) == NULL)
797
823
                return;
798
824
 
799
 
        error = -EIO;
 
825
        error = __scsi_error_from_host_byte(cmd, result);
800
826
 
801
827
        if (host_byte(result) == DID_RESET) {
802
828
                /* Third party bus reset or reset for error recovery
843
869
                                description = "Host Data Integrity Failure";
844
870
                                action = ACTION_FAIL;
845
871
                                error = -EILSEQ;
 
872
                        /* INVALID COMMAND OPCODE or INVALID FIELD IN CDB */
 
873
                        } else if ((sshdr.asc == 0x20 || sshdr.asc == 0x24) &&
 
874
                                   (cmd->cmnd[0] == UNMAP ||
 
875
                                    cmd->cmnd[0] == WRITE_SAME_16 ||
 
876
                                    cmd->cmnd[0] == WRITE_SAME)) {
 
877
                                description = "Discard failure";
 
878
                                action = ACTION_FAIL;
846
879
                        } else
847
880
                                action = ACTION_FAIL;
848
881
                        break;
1038
1071
        cmd->request = req;
1039
1072
 
1040
1073
        cmd->cmnd = req->cmd;
 
1074
        cmd->prot_op = SCSI_PROT_NORMAL;
1041
1075
 
1042
1076
        return cmd;
1043
1077
}
1194
1228
        case BLKPREP_DEFER:
1195
1229
                /*
1196
1230
                 * If we defer, the blk_peek_request() returns NULL, but the
1197
 
                 * queue must be restarted, so we plug here if no returning
1198
 
                 * command will automatically do that.
 
1231
                 * queue must be restarted, so we schedule a callback to happen
 
1232
                 * shortly.
1199
1233
                 */
1200
1234
                if (sdev->device_busy == 0)
1201
 
                        blk_plug_device(q);
 
1235
                        blk_delay_queue(q, SCSI_QUEUE_DELAY);
1202
1236
                break;
1203
1237
        default:
1204
1238
                req->cmd_flags |= REQ_DONTPREP;
1237
1271
                                   sdev_printk(KERN_INFO, sdev,
1238
1272
                                   "unblocking device at zero depth\n"));
1239
1273
                } else {
1240
 
                        blk_plug_device(q);
 
1274
                        blk_delay_queue(q, SCSI_QUEUE_DELAY);
1241
1275
                        return 0;
1242
1276
                }
1243
1277
        }
1467
1501
         * the host is no longer able to accept any more requests.
1468
1502
         */
1469
1503
        shost = sdev->host;
1470
 
        while (!blk_queue_plugged(q)) {
 
1504
        for (;;) {
1471
1505
                int rtn;
1472
1506
                /*
1473
1507
                 * get next queueable request.  We do this early to make sure
1546
1580
                 */
1547
1581
                rtn = scsi_dispatch_cmd(cmd);
1548
1582
                spin_lock_irq(q->queue_lock);
1549
 
                if(rtn) {
1550
 
                        /* we're refusing the command; because of
1551
 
                         * the way locks get dropped, we need to 
1552
 
                         * check here if plugging is required */
1553
 
                        if(sdev->device_busy == 0)
1554
 
                                blk_plug_device(q);
1555
 
 
1556
 
                        break;
1557
 
                }
 
1583
                if (rtn)
 
1584
                        goto out_delay;
1558
1585
        }
1559
1586
 
1560
1587
        goto out;
1573
1600
        spin_lock_irq(q->queue_lock);
1574
1601
        blk_requeue_request(q, req);
1575
1602
        sdev->device_busy--;
1576
 
        if(sdev->device_busy == 0)
1577
 
                blk_plug_device(q);
1578
 
 out:
 
1603
out_delay:
 
1604
        if (sdev->device_busy == 0)
 
1605
                blk_delay_queue(q, SCSI_QUEUE_DELAY);
 
1606
out:
1579
1607
        /* must be careful here...if we trigger the ->remove() function
1580
1608
         * we cannot be holding the q lock */
1581
1609
        spin_unlock_irq(q->queue_lock);