diff options
Diffstat (limited to 'drivers/scsi/scsi.c')
| -rw-r--r-- | drivers/scsi/scsi.c | 132 |
1 files changed, 51 insertions, 81 deletions
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 88d46fe6bf98..df3306019a7e 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c | |||
| @@ -72,8 +72,6 @@ | |||
| 72 | #define CREATE_TRACE_POINTS | 72 | #define CREATE_TRACE_POINTS |
| 73 | #include <trace/events/scsi.h> | 73 | #include <trace/events/scsi.h> |
| 74 | 74 | ||
| 75 | static void scsi_done(struct scsi_cmnd *cmd); | ||
| 76 | |||
| 77 | /* | 75 | /* |
| 78 | * Definitions and constants. | 76 | * Definitions and constants. |
| 79 | */ | 77 | */ |
| @@ -124,6 +122,8 @@ static const char *const scsi_device_types[] = { | |||
| 124 | "Bridge controller", | 122 | "Bridge controller", |
| 125 | "Object storage ", | 123 | "Object storage ", |
| 126 | "Automation/Drive ", | 124 | "Automation/Drive ", |
| 125 | "Security Manager ", | ||
| 126 | "Direct-Access-ZBC", | ||
| 127 | }; | 127 | }; |
| 128 | 128 | ||
| 129 | /** | 129 | /** |
| @@ -235,7 +235,8 @@ fail: | |||
| 235 | * Description: allocate a struct scsi_cmd from host's slab, recycling from the | 235 | * Description: allocate a struct scsi_cmd from host's slab, recycling from the |
| 236 | * host's free_list if necessary. | 236 | * host's free_list if necessary. |
| 237 | */ | 237 | */ |
| 238 | struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask) | 238 | static struct scsi_cmnd * |
| 239 | __scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask) | ||
| 239 | { | 240 | { |
| 240 | struct scsi_cmnd *cmd = scsi_host_alloc_command(shost, gfp_mask); | 241 | struct scsi_cmnd *cmd = scsi_host_alloc_command(shost, gfp_mask); |
| 241 | 242 | ||
| @@ -265,7 +266,6 @@ struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask) | |||
| 265 | 266 | ||
| 266 | return cmd; | 267 | return cmd; |
| 267 | } | 268 | } |
| 268 | EXPORT_SYMBOL_GPL(__scsi_get_command); | ||
| 269 | 269 | ||
| 270 | /** | 270 | /** |
| 271 | * scsi_get_command - Allocate and setup a scsi command block | 271 | * scsi_get_command - Allocate and setup a scsi command block |
| @@ -291,14 +291,13 @@ struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, gfp_t gfp_mask) | |||
| 291 | cmd->jiffies_at_alloc = jiffies; | 291 | cmd->jiffies_at_alloc = jiffies; |
| 292 | return cmd; | 292 | return cmd; |
| 293 | } | 293 | } |
| 294 | EXPORT_SYMBOL(scsi_get_command); | ||
| 295 | 294 | ||
| 296 | /** | 295 | /** |
| 297 | * __scsi_put_command - Free a struct scsi_cmnd | 296 | * __scsi_put_command - Free a struct scsi_cmnd |
| 298 | * @shost: dev->host | 297 | * @shost: dev->host |
| 299 | * @cmd: Command to free | 298 | * @cmd: Command to free |
| 300 | */ | 299 | */ |
| 301 | void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd) | 300 | static void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd) |
| 302 | { | 301 | { |
| 303 | unsigned long flags; | 302 | unsigned long flags; |
| 304 | 303 | ||
| @@ -314,7 +313,6 @@ void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd) | |||
| 314 | if (likely(cmd != NULL)) | 313 | if (likely(cmd != NULL)) |
| 315 | scsi_host_free_command(shost, cmd); | 314 | scsi_host_free_command(shost, cmd); |
| 316 | } | 315 | } |
| 317 | EXPORT_SYMBOL(__scsi_put_command); | ||
| 318 | 316 | ||
| 319 | /** | 317 | /** |
| 320 | * scsi_put_command - Free a scsi command block | 318 | * scsi_put_command - Free a scsi command block |
| @@ -334,11 +332,10 @@ void scsi_put_command(struct scsi_cmnd *cmd) | |||
| 334 | list_del_init(&cmd->list); | 332 | list_del_init(&cmd->list); |
| 335 | spin_unlock_irqrestore(&cmd->device->list_lock, flags); | 333 | spin_unlock_irqrestore(&cmd->device->list_lock, flags); |
| 336 | 334 | ||
| 337 | cancel_delayed_work(&cmd->abort_work); | 335 | BUG_ON(delayed_work_pending(&cmd->abort_work)); |
| 338 | 336 | ||
| 339 | __scsi_put_command(cmd->device->host, cmd); | 337 | __scsi_put_command(cmd->device->host, cmd); |
| 340 | } | 338 | } |
| 341 | EXPORT_SYMBOL(scsi_put_command); | ||
| 342 | 339 | ||
| 343 | static struct scsi_host_cmd_pool * | 340 | static struct scsi_host_cmd_pool * |
| 344 | scsi_find_host_cmd_pool(struct Scsi_Host *shost) | 341 | scsi_find_host_cmd_pool(struct Scsi_Host *shost) |
| @@ -368,8 +365,8 @@ scsi_alloc_host_cmd_pool(struct Scsi_Host *shost) | |||
| 368 | if (!pool) | 365 | if (!pool) |
| 369 | return NULL; | 366 | return NULL; |
| 370 | 367 | ||
| 371 | pool->cmd_name = kasprintf(GFP_KERNEL, "%s_cmd", hostt->name); | 368 | pool->cmd_name = kasprintf(GFP_KERNEL, "%s_cmd", hostt->proc_name); |
| 372 | pool->sense_name = kasprintf(GFP_KERNEL, "%s_sense", hostt->name); | 369 | pool->sense_name = kasprintf(GFP_KERNEL, "%s_sense", hostt->proc_name); |
| 373 | if (!pool->cmd_name || !pool->sense_name) { | 370 | if (!pool->cmd_name || !pool->sense_name) { |
| 374 | scsi_free_host_cmd_pool(pool); | 371 | scsi_free_host_cmd_pool(pool); |
| 375 | return NULL; | 372 | return NULL; |
| @@ -605,7 +602,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition) | |||
| 605 | if (level > 3) | 602 | if (level > 3) |
| 606 | scmd_printk(KERN_INFO, cmd, | 603 | scmd_printk(KERN_INFO, cmd, |
| 607 | "scsi host busy %d failed %d\n", | 604 | "scsi host busy %d failed %d\n", |
| 608 | cmd->device->host->host_busy, | 605 | atomic_read(&cmd->device->host->host_busy), |
| 609 | cmd->device->host->host_failed); | 606 | cmd->device->host->host_failed); |
| 610 | } | 607 | } |
| 611 | } | 608 | } |
| @@ -648,33 +645,24 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd) | |||
| 648 | * returns an immediate error upwards, and signals | 645 | * returns an immediate error upwards, and signals |
| 649 | * that the device is no longer present */ | 646 | * that the device is no longer present */ |
| 650 | cmd->result = DID_NO_CONNECT << 16; | 647 | cmd->result = DID_NO_CONNECT << 16; |
| 651 | scsi_done(cmd); | 648 | goto done; |
| 652 | /* return 0 (because the command has been processed) */ | ||
| 653 | goto out; | ||
| 654 | } | 649 | } |
| 655 | 650 | ||
| 656 | /* Check to see if the scsi lld made this device blocked. */ | 651 | /* Check to see if the scsi lld made this device blocked. */ |
| 657 | if (unlikely(scsi_device_blocked(cmd->device))) { | 652 | if (unlikely(scsi_device_blocked(cmd->device))) { |
| 658 | /* | 653 | /* |
| 659 | * in blocked state, the command is just put back on | 654 | * in blocked state, the command is just put back on |
| 660 | * the device queue. The suspend state has already | 655 | * the device queue. The suspend state has already |
| 661 | * blocked the queue so future requests should not | 656 | * blocked the queue so future requests should not |
| 662 | * occur until the device transitions out of the | 657 | * occur until the device transitions out of the |
| 663 | * suspend state. | 658 | * suspend state. |
| 664 | */ | 659 | */ |
| 665 | 660 | SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd, | |
| 666 | scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); | 661 | "queuecommand : device blocked\n")); |
| 667 | 662 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
| 668 | SCSI_LOG_MLQUEUE(3, printk("queuecommand : device blocked \n")); | ||
| 669 | |||
| 670 | /* | ||
| 671 | * NOTE: rtn is still zero here because we don't need the | ||
| 672 | * queue to be plugged on return (it's already stopped) | ||
| 673 | */ | ||
| 674 | goto out; | ||
| 675 | } | 663 | } |
| 676 | 664 | ||
| 677 | /* | 665 | /* |
| 678 | * If SCSI-2 or lower, store the LUN value in cmnd. | 666 | * If SCSI-2 or lower, store the LUN value in cmnd. |
| 679 | */ | 667 | */ |
| 680 | if (cmd->device->scsi_level <= SCSI_2 && | 668 | if (cmd->device->scsi_level <= SCSI_2 && |
| @@ -690,57 +678,36 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd) | |||
| 690 | * length exceeds what the host adapter can handle. | 678 | * length exceeds what the host adapter can handle. |
| 691 | */ | 679 | */ |
| 692 | if (cmd->cmd_len > cmd->device->host->max_cmd_len) { | 680 | if (cmd->cmd_len > cmd->device->host->max_cmd_len) { |
| 693 | SCSI_LOG_MLQUEUE(3, | 681 | SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd, |
| 694 | printk("queuecommand : command too long. " | 682 | "queuecommand : command too long. " |
| 695 | "cdb_size=%d host->max_cmd_len=%d\n", | 683 | "cdb_size=%d host->max_cmd_len=%d\n", |
| 696 | cmd->cmd_len, cmd->device->host->max_cmd_len)); | 684 | cmd->cmd_len, cmd->device->host->max_cmd_len)); |
| 697 | cmd->result = (DID_ABORT << 16); | 685 | cmd->result = (DID_ABORT << 16); |
| 698 | 686 | goto done; | |
| 699 | scsi_done(cmd); | ||
| 700 | goto out; | ||
| 701 | } | 687 | } |
| 702 | 688 | ||
| 703 | if (unlikely(host->shost_state == SHOST_DEL)) { | 689 | if (unlikely(host->shost_state == SHOST_DEL)) { |
| 704 | cmd->result = (DID_NO_CONNECT << 16); | 690 | cmd->result = (DID_NO_CONNECT << 16); |
| 705 | scsi_done(cmd); | 691 | goto done; |
| 706 | } else { | 692 | |
| 707 | trace_scsi_dispatch_cmd_start(cmd); | ||
| 708 | cmd->scsi_done = scsi_done; | ||
| 709 | rtn = host->hostt->queuecommand(host, cmd); | ||
| 710 | } | 693 | } |
| 711 | 694 | ||
| 695 | trace_scsi_dispatch_cmd_start(cmd); | ||
| 696 | rtn = host->hostt->queuecommand(host, cmd); | ||
| 712 | if (rtn) { | 697 | if (rtn) { |
| 713 | trace_scsi_dispatch_cmd_error(cmd, rtn); | 698 | trace_scsi_dispatch_cmd_error(cmd, rtn); |
| 714 | if (rtn != SCSI_MLQUEUE_DEVICE_BUSY && | 699 | if (rtn != SCSI_MLQUEUE_DEVICE_BUSY && |
| 715 | rtn != SCSI_MLQUEUE_TARGET_BUSY) | 700 | rtn != SCSI_MLQUEUE_TARGET_BUSY) |
| 716 | rtn = SCSI_MLQUEUE_HOST_BUSY; | 701 | rtn = SCSI_MLQUEUE_HOST_BUSY; |
| 717 | 702 | ||
| 718 | scsi_queue_insert(cmd, rtn); | 703 | SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd, |
| 719 | 704 | "queuecommand : request rejected\n")); | |
| 720 | SCSI_LOG_MLQUEUE(3, | ||
| 721 | printk("queuecommand : request rejected\n")); | ||
| 722 | } | 705 | } |
| 723 | 706 | ||
| 724 | out: | ||
| 725 | SCSI_LOG_MLQUEUE(3, printk("leaving scsi_dispatch_cmnd()\n")); | ||
| 726 | return rtn; | 707 | return rtn; |
| 727 | } | 708 | done: |
| 728 | 709 | cmd->scsi_done(cmd); | |
| 729 | /** | 710 | return 0; |
| 730 | * scsi_done - Invoke completion on finished SCSI command. | ||
| 731 | * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives | ||
| 732 | * ownership back to SCSI Core -- i.e. the LLDD has finished with it. | ||
| 733 | * | ||
| 734 | * Description: This function is the mid-level's (SCSI Core) interrupt routine, | ||
| 735 | * which regains ownership of the SCSI command (de facto) from a LLDD, and | ||
| 736 | * calls blk_complete_request() for further processing. | ||
| 737 | * | ||
| 738 | * This function is interrupt context safe. | ||
| 739 | */ | ||
| 740 | static void scsi_done(struct scsi_cmnd *cmd) | ||
| 741 | { | ||
| 742 | trace_scsi_dispatch_cmd_done(cmd); | ||
| 743 | blk_complete_request(cmd->request); | ||
| 744 | } | 711 | } |
| 745 | 712 | ||
| 746 | /** | 713 | /** |
| @@ -761,17 +728,16 @@ void scsi_finish_command(struct scsi_cmnd *cmd) | |||
| 761 | 728 | ||
| 762 | scsi_device_unbusy(sdev); | 729 | scsi_device_unbusy(sdev); |
| 763 | 730 | ||
| 764 | /* | 731 | /* |
| 765 | * Clear the flags which say that the device/host is no longer | 732 | * Clear the flags that say that the device/target/host is no longer |
| 766 | * capable of accepting new commands. These are set in scsi_queue.c | 733 | * capable of accepting new commands. |
| 767 | * for both the queue full condition on a device, and for a | 734 | */ |
| 768 | * host full condition on the host. | 735 | if (atomic_read(&shost->host_blocked)) |
| 769 | * | 736 | atomic_set(&shost->host_blocked, 0); |
| 770 | * XXX(hch): What about locking? | 737 | if (atomic_read(&starget->target_blocked)) |
| 771 | */ | 738 | atomic_set(&starget->target_blocked, 0); |
| 772 | shost->host_blocked = 0; | 739 | if (atomic_read(&sdev->device_blocked)) |
| 773 | starget->target_blocked = 0; | 740 | atomic_set(&sdev->device_blocked, 0); |
| 774 | sdev->device_blocked = 0; | ||
| 775 | 741 | ||
| 776 | /* | 742 | /* |
| 777 | * If we have valid sense information, then some kind of recovery | 743 | * If we have valid sense information, then some kind of recovery |
| @@ -801,7 +767,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd) | |||
| 801 | } | 767 | } |
| 802 | scsi_io_completion(cmd, good_bytes); | 768 | scsi_io_completion(cmd, good_bytes); |
| 803 | } | 769 | } |
| 804 | EXPORT_SYMBOL(scsi_finish_command); | ||
| 805 | 770 | ||
| 806 | /** | 771 | /** |
| 807 | * scsi_adjust_queue_depth - Let low level drivers change a device's queue depth | 772 | * scsi_adjust_queue_depth - Let low level drivers change a device's queue depth |
| @@ -842,7 +807,7 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags) | |||
| 842 | * is more IO than the LLD's can_queue (so there are not enuogh | 807 | * is more IO than the LLD's can_queue (so there are not enuogh |
| 843 | * tags) request_fn's host queue ready check will handle it. | 808 | * tags) request_fn's host queue ready check will handle it. |
| 844 | */ | 809 | */ |
| 845 | if (!sdev->host->bqt) { | 810 | if (!shost_use_blk_mq(sdev->host) && !sdev->host->bqt) { |
| 846 | if (blk_queue_tagged(sdev->request_queue) && | 811 | if (blk_queue_tagged(sdev->request_queue) && |
| 847 | blk_queue_resize_tags(sdev->request_queue, tags) != 0) | 812 | blk_queue_resize_tags(sdev->request_queue, tags) != 0) |
| 848 | goto out; | 813 | goto out; |
| @@ -850,6 +815,10 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags) | |||
| 850 | 815 | ||
| 851 | sdev->queue_depth = tags; | 816 | sdev->queue_depth = tags; |
| 852 | switch (tagged) { | 817 | switch (tagged) { |
| 818 | case 0: | ||
| 819 | sdev->ordered_tags = 0; | ||
| 820 | sdev->simple_tags = 0; | ||
| 821 | break; | ||
| 853 | case MSG_ORDERED_TAG: | 822 | case MSG_ORDERED_TAG: |
| 854 | sdev->ordered_tags = 1; | 823 | sdev->ordered_tags = 1; |
| 855 | sdev->simple_tags = 1; | 824 | sdev->simple_tags = 1; |
| @@ -859,13 +828,11 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags) | |||
| 859 | sdev->simple_tags = 1; | 828 | sdev->simple_tags = 1; |
| 860 | break; | 829 | break; |
| 861 | default: | 830 | default: |
| 831 | sdev->ordered_tags = 0; | ||
| 832 | sdev->simple_tags = 0; | ||
| 862 | sdev_printk(KERN_WARNING, sdev, | 833 | sdev_printk(KERN_WARNING, sdev, |
| 863 | "scsi_adjust_queue_depth, bad queue type, " | 834 | "scsi_adjust_queue_depth, bad queue type, " |
| 864 | "disabled\n"); | 835 | "disabled\n"); |
| 865 | case 0: | ||
| 866 | sdev->ordered_tags = sdev->simple_tags = 0; | ||
| 867 | sdev->queue_depth = tags; | ||
| 868 | break; | ||
| 869 | } | 836 | } |
| 870 | out: | 837 | out: |
| 871 | spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); | 838 | spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); |
| @@ -1291,7 +1258,7 @@ EXPORT_SYMBOL(__starget_for_each_device); | |||
| 1291 | * really want to use scsi_device_lookup_by_target instead. | 1258 | * really want to use scsi_device_lookup_by_target instead. |
| 1292 | **/ | 1259 | **/ |
| 1293 | struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *starget, | 1260 | struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *starget, |
| 1294 | uint lun) | 1261 | u64 lun) |
| 1295 | { | 1262 | { |
| 1296 | struct scsi_device *sdev; | 1263 | struct scsi_device *sdev; |
| 1297 | 1264 | ||
| @@ -1316,7 +1283,7 @@ EXPORT_SYMBOL(__scsi_device_lookup_by_target); | |||
| 1316 | * needs to be released with scsi_device_put once you're done with it. | 1283 | * needs to be released with scsi_device_put once you're done with it. |
| 1317 | **/ | 1284 | **/ |
| 1318 | struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *starget, | 1285 | struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *starget, |
| 1319 | uint lun) | 1286 | u64 lun) |
| 1320 | { | 1287 | { |
| 1321 | struct scsi_device *sdev; | 1288 | struct scsi_device *sdev; |
| 1322 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | 1289 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| @@ -1349,7 +1316,7 @@ EXPORT_SYMBOL(scsi_device_lookup_by_target); | |||
| 1349 | * really want to use scsi_device_lookup instead. | 1316 | * really want to use scsi_device_lookup instead. |
| 1350 | **/ | 1317 | **/ |
| 1351 | struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost, | 1318 | struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost, |
| 1352 | uint channel, uint id, uint lun) | 1319 | uint channel, uint id, u64 lun) |
| 1353 | { | 1320 | { |
| 1354 | struct scsi_device *sdev; | 1321 | struct scsi_device *sdev; |
| 1355 | 1322 | ||
| @@ -1375,7 +1342,7 @@ EXPORT_SYMBOL(__scsi_device_lookup); | |||
| 1375 | * needs to be released with scsi_device_put once you're done with it. | 1342 | * needs to be released with scsi_device_put once you're done with it. |
| 1376 | **/ | 1343 | **/ |
| 1377 | struct scsi_device *scsi_device_lookup(struct Scsi_Host *shost, | 1344 | struct scsi_device *scsi_device_lookup(struct Scsi_Host *shost, |
| 1378 | uint channel, uint id, uint lun) | 1345 | uint channel, uint id, u64 lun) |
| 1379 | { | 1346 | { |
| 1380 | struct scsi_device *sdev; | 1347 | struct scsi_device *sdev; |
| 1381 | unsigned long flags; | 1348 | unsigned long flags; |
| @@ -1396,6 +1363,9 @@ MODULE_LICENSE("GPL"); | |||
| 1396 | module_param(scsi_logging_level, int, S_IRUGO|S_IWUSR); | 1363 | module_param(scsi_logging_level, int, S_IRUGO|S_IWUSR); |
| 1397 | MODULE_PARM_DESC(scsi_logging_level, "a bit mask of logging levels"); | 1364 | MODULE_PARM_DESC(scsi_logging_level, "a bit mask of logging levels"); |
| 1398 | 1365 | ||
| 1366 | bool scsi_use_blk_mq = false; | ||
| 1367 | module_param_named(use_blk_mq, scsi_use_blk_mq, bool, S_IWUSR | S_IRUGO); | ||
| 1368 | |||
| 1399 | static int __init init_scsi(void) | 1369 | static int __init init_scsi(void) |
| 1400 | { | 1370 | { |
| 1401 | int error; | 1371 | int error; |
