aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/block/biodoc.txt4
-rw-r--r--Documentation/scsi/scsi_mid_low_api.txt50
-rw-r--r--Documentation/scsi/st.txt8
-rw-r--r--block/blk-core.c4
-rw-r--r--block/blk-mq-tag.c28
-rw-r--r--block/blk-mq.c2
-rw-r--r--block/scsi_ioctl.c2
-rw-r--r--drivers/ata/libata-scsi.c6
-rw-r--r--drivers/block/nvme-scsi.c4
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c26
-rw-r--r--drivers/message/fusion/mptsas.c1
-rw-r--r--drivers/message/fusion/mptscsih.c12
-rw-r--r--drivers/misc/enclosure.c44
-rw-r--r--drivers/s390/scsi/zfcp_fc.h14
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c8
-rw-r--r--drivers/scsi/3w-9xxx.c2
-rw-r--r--drivers/scsi/3w-sas.c2
-rw-r--r--drivers/scsi/3w-xxxx.c2
-rw-r--r--drivers/scsi/53c700.c42
-rw-r--r--drivers/scsi/BusLogic.c4
-rw-r--r--drivers/scsi/NCR5380.c17
-rw-r--r--drivers/scsi/aacraid/aachba.c4
-rw-r--r--drivers/scsi/aacraid/linit.c10
-rw-r--r--drivers/scsi/advansys.c7
-rw-r--r--drivers/scsi/aha152x.c994
-rw-r--r--drivers/scsi/aha1740.c2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c19
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c23
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c1
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c2
-rw-r--r--drivers/scsi/arm/acornscsi.c12
-rw-r--r--drivers/scsi/arm/fas216.c39
-rw-r--r--drivers/scsi/atari_NCR5380.c5
-rw-r--r--drivers/scsi/bfa/bfad_im.c18
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c3
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c18
-rw-r--r--drivers/scsi/ch.c36
-rw-r--r--drivers/scsi/constants.c599
-rw-r--r--drivers/scsi/csiostor/csio_scsi.c37
-rw-r--r--drivers/scsi/device_handler/scsi_dh.c55
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c82
-rw-r--r--drivers/scsi/device_handler/scsi_dh_emc.c86
-rw-r--r--drivers/scsi/device_handler/scsi_dh_hp_sw.c81
-rw-r--r--drivers/scsi/device_handler/scsi_dh_rdac.c82
-rw-r--r--drivers/scsi/dpt_i2o.c4
-rw-r--r--drivers/scsi/eata.c8
-rw-r--r--drivers/scsi/esas2r/esas2r.h4
-rw-r--r--drivers/scsi/esas2r/esas2r_main.c55
-rw-r--r--drivers/scsi/esp_scsi.c21
-rw-r--r--drivers/scsi/fcoe/fcoe.c3
-rw-r--r--drivers/scsi/fnic/fnic_main.c7
-rw-r--r--drivers/scsi/fnic/fnic_scsi.c11
-rw-r--r--drivers/scsi/gdth.c5
-rw-r--r--drivers/scsi/hosts.c5
-rw-r--r--drivers/scsi/hpsa.c2
-rw-r--r--drivers/scsi/hptiop.c2
-rw-r--r--drivers/scsi/ibmvscsi/ibmvfc.c50
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c3
-rw-r--r--drivers/scsi/ipr.c63
-rw-r--r--drivers/scsi/ips.c2
-rw-r--r--drivers/scsi/isci/init.c1
-rw-r--r--drivers/scsi/libfc/fc_fcp.c31
-rw-r--r--drivers/scsi/libiscsi.c4
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c26
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c49
-rw-r--r--drivers/scsi/megaraid.c8
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c3
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_scsih.c42
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_scsih.c42
-rw-r--r--drivers/scsi/mvsas/mv_init.c1
-rw-r--r--drivers/scsi/ncr53c8xx.c5
-rw-r--r--drivers/scsi/osd/osd_uld.c2
-rw-r--r--drivers/scsi/osst.c29
-rw-r--r--drivers/scsi/pm8001/pm8001_init.c1
-rw-r--r--drivers/scsi/pmcraid.c84
-rw-r--r--drivers/scsi/ps3rom.c4
-rw-r--r--drivers/scsi/qla1280.c5
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c92
-rw-r--r--drivers/scsi/qla2xxx/qla_mr.c13
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c31
-rw-r--r--drivers/scsi/qla4xxx/ql4_iocb.c10
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c19
-rw-r--r--drivers/scsi/scsi.c176
-rw-r--r--drivers/scsi/scsi_debug.c17
-rw-r--r--drivers/scsi/scsi_error.c196
-rw-r--r--drivers/scsi/scsi_ioctl.c74
-rw-r--r--drivers/scsi/scsi_lib.c165
-rw-r--r--drivers/scsi/scsi_logging.h1
-rw-r--r--drivers/scsi/scsi_priv.h2
-rw-r--r--drivers/scsi/scsi_scan.c27
-rw-r--r--drivers/scsi/scsi_sysfs.c13
-rw-r--r--drivers/scsi/scsi_trace.c2
-rw-r--r--drivers/scsi/scsi_transport_spi.c23
-rw-r--r--drivers/scsi/scsicam.c4
-rw-r--r--drivers/scsi/sd.c114
-rw-r--r--drivers/scsi/sd.h6
-rw-r--r--drivers/scsi/ses.c2
-rw-r--r--drivers/scsi/sg.c62
-rw-r--r--drivers/scsi/sr.c19
-rw-r--r--drivers/scsi/sr.h3
-rw-r--r--drivers/scsi/sr_ioctl.c10
-rw-r--r--drivers/scsi/st.c47
-rw-r--r--drivers/scsi/stex.c30
-rw-r--r--drivers/scsi/storvsc_drv.c6
-rw-r--r--drivers/scsi/sun3_NCR5380.c13
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c4
-rw-r--r--drivers/scsi/tmscsim.c22
-rw-r--r--drivers/scsi/u14-34f.c10
-rw-r--r--drivers/scsi/ufs/ufshcd.c18
-rw-r--r--drivers/scsi/virtio_scsi.c4
-rw-r--r--drivers/scsi/vmw_pvscsi.c6
-rw-r--r--drivers/target/loopback/tcm_loop.c51
-rw-r--r--drivers/target/target_core_alua.c2
-rw-r--r--drivers/target/target_core_pr.c2
-rw-r--r--drivers/target/target_core_sbc.c2
-rw-r--r--drivers/usb/gadget/legacy/tcm_usb_gadget.c2
-rw-r--r--drivers/usb/storage/debug.c10
-rw-r--r--drivers/usb/storage/uas.c7
-rw-r--r--drivers/xen/xen-scsiback.c4
-rw-r--r--include/linux/blk-mq.h17
-rw-r--r--include/linux/blkdev.h1
-rw-r--r--include/scsi/libfc.h1
-rw-r--r--include/scsi/scsi.h12
-rw-r--r--include/scsi/scsi_cmnd.h6
-rw-r--r--include/scsi/scsi_dbg.h28
-rw-r--r--include/scsi/scsi_device.h21
-rw-r--r--include/scsi/scsi_driver.h1
-rw-r--r--include/scsi/scsi_eh.h24
-rw-r--r--include/scsi/scsi_host.h24
-rw-r--r--include/scsi/scsi_ioctl.h4
-rw-r--r--include/scsi/scsi_tcq.h87
-rw-r--r--include/scsi/scsi_transport_spi.h1
-rw-r--r--include/scsi/sg.h5
-rw-r--r--include/trace/events/scsi.h2
-rw-r--r--include/trace/events/target.h2
-rw-r--r--tools/lib/traceevent/plugin_scsi.c9
137 files changed, 1562 insertions, 3085 deletions
diff --git a/Documentation/block/biodoc.txt b/Documentation/block/biodoc.txt
index 2101e718670d..6b972b287795 100644
--- a/Documentation/block/biodoc.txt
+++ b/Documentation/block/biodoc.txt
@@ -827,10 +827,6 @@ but in the event of any barrier requests in the tag queue we need to ensure
827that requests are restarted in the order they were queue. This may happen 827that requests are restarted in the order they were queue. This may happen
828if the driver needs to use blk_queue_invalidate_tags(). 828if the driver needs to use blk_queue_invalidate_tags().
829 829
830Tagging also defines a new request flag, REQ_QUEUED. This is set whenever
831a request is currently tagged. You should not use this flag directly,
832blk_rq_tagged(rq) is the portable way to do so.
833
8343.3 I/O Submission 8303.3 I/O Submission
835 831
836The routine submit_bio() is used to submit a single io. Higher level i/o 832The routine submit_bio() is used to submit a single io. Higher level i/o
diff --git a/Documentation/scsi/scsi_mid_low_api.txt b/Documentation/scsi/scsi_mid_low_api.txt
index d6a9bdeee7f2..bee7d86b9dcc 100644
--- a/Documentation/scsi/scsi_mid_low_api.txt
+++ b/Documentation/scsi/scsi_mid_low_api.txt
@@ -271,9 +271,9 @@ init_this_scsi_driver() ----+
271 slave_destroy() *** 271 slave_destroy() ***
272------------------------------------------------------------ 272------------------------------------------------------------
273 273
274The mid level invokes scsi_adjust_queue_depth() with tagged queuing off and 274The mid level invokes scsi_adjust_queue_depth() with "cmd_per_lun" for that
275"cmd_per_lun" for that host as the queue length. These settings can be 275host as the queue length. These settings can be overridden by a
276overridden by a slave_configure() supplied by the LLD. 276slave_configure() supplied by the LLD.
277 277
278*** For scsi devices that the mid level tries to scan but do not 278*** For scsi devices that the mid level tries to scan but do not
279 respond, a slave_alloc(), slave_destroy() pair is called. 279 respond, a slave_alloc(), slave_destroy() pair is called.
@@ -366,13 +366,11 @@ is initialized. The functions below are listed alphabetically and their
366names all start with "scsi_". 366names all start with "scsi_".
367 367
368Summary: 368Summary:
369 scsi_activate_tcq - turn on tag command queueing
370 scsi_add_device - creates new scsi device (lu) instance 369 scsi_add_device - creates new scsi device (lu) instance
371 scsi_add_host - perform sysfs registration and set up transport class 370 scsi_add_host - perform sysfs registration and set up transport class
372 scsi_adjust_queue_depth - change the queue depth on a SCSI device 371 scsi_adjust_queue_depth - change the queue depth on a SCSI device
373 scsi_bios_ptable - return copy of block device's partition table 372 scsi_bios_ptable - return copy of block device's partition table
374 scsi_block_requests - prevent further commands being queued to given host 373 scsi_block_requests - prevent further commands being queued to given host
375 scsi_deactivate_tcq - turn off tag command queueing
376 scsi_host_alloc - return a new scsi_host instance whose refcount==1 374 scsi_host_alloc - return a new scsi_host instance whose refcount==1
377 scsi_host_get - increments Scsi_Host instance's refcount 375 scsi_host_get - increments Scsi_Host instance's refcount
378 scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) 376 scsi_host_put - decrements Scsi_Host instance's refcount (free if 0)
@@ -390,24 +388,6 @@ Summary:
390Details: 388Details:
391 389
392/** 390/**
393 * scsi_activate_tcq - turn on tag command queueing ("ordered" task attribute)
394 * @sdev: device to turn on TCQ for
395 * @depth: queue depth
396 *
397 * Returns nothing
398 *
399 * Might block: no
400 *
401 * Notes: Eventually, it is hoped depth would be the maximum depth
402 * the device could cope with and the real queue depth
403 * would be adjustable from 0 to depth.
404 *
405 * Defined (inline) in: include/scsi/scsi_tcq.h
406 **/
407void scsi_activate_tcq(struct scsi_device *sdev, int depth)
408
409
410/**
411 * scsi_add_device - creates new scsi device (lu) instance 391 * scsi_add_device - creates new scsi device (lu) instance
412 * @shost: pointer to scsi host instance 392 * @shost: pointer to scsi host instance
413 * @channel: channel number (rarely other than 0) 393 * @channel: channel number (rarely other than 0)
@@ -458,9 +438,6 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
458/** 438/**
459 * scsi_adjust_queue_depth - allow LLD to change queue depth on a SCSI device 439 * scsi_adjust_queue_depth - allow LLD to change queue depth on a SCSI device
460 * @sdev: pointer to SCSI device to change queue depth on 440 * @sdev: pointer to SCSI device to change queue depth on
461 * @tagged: 0 - no tagged queuing
462 * MSG_SIMPLE_TAG - simple tagged queuing
463 * MSG_ORDERED_TAG - ordered tagged queuing
464 * @tags Number of tags allowed if tagged queuing enabled, 441 * @tags Number of tags allowed if tagged queuing enabled,
465 * or number of commands the LLD can queue up 442 * or number of commands the LLD can queue up
466 * in non-tagged mode (as per cmd_per_lun). 443 * in non-tagged mode (as per cmd_per_lun).
@@ -471,15 +448,12 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
471 * 448 *
472 * Notes: Can be invoked any time on a SCSI device controlled by this 449 * Notes: Can be invoked any time on a SCSI device controlled by this
473 * LLD. [Specifically during and after slave_configure() and prior to 450 * LLD. [Specifically during and after slave_configure() and prior to
474 * slave_destroy().] Can safely be invoked from interrupt code. Actual 451 * slave_destroy().] Can safely be invoked from interrupt code.
475 * queue depth change may be delayed until the next command is being
476 * processed. See also scsi_activate_tcq() and scsi_deactivate_tcq().
477 * 452 *
478 * Defined in: drivers/scsi/scsi.c [see source code for more notes] 453 * Defined in: drivers/scsi/scsi.c [see source code for more notes]
479 * 454 *
480 **/ 455 **/
481void scsi_adjust_queue_depth(struct scsi_device * sdev, int tagged, 456void scsi_adjust_queue_depth(struct scsi_device *sdev, int tags)
482 int tags)
483 457
484 458
485/** 459/**
@@ -515,20 +489,6 @@ void scsi_block_requests(struct Scsi_Host * shost)
515 489
516 490
517/** 491/**
518 * scsi_deactivate_tcq - turn off tag command queueing
519 * @sdev: device to turn off TCQ for
520 * @depth: queue depth (stored in sdev)
521 *
522 * Returns nothing
523 *
524 * Might block: no
525 *
526 * Defined (inline) in: include/scsi/scsi_tcq.h
527 **/
528void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
529
530
531/**
532 * scsi_host_alloc - create a scsi host adapter instance and perform basic 492 * scsi_host_alloc - create a scsi host adapter instance and perform basic
533 * initialization. 493 * initialization.
534 * @sht: pointer to scsi host template 494 * @sht: pointer to scsi host template
diff --git a/Documentation/scsi/st.txt b/Documentation/scsi/st.txt
index f346abbdd6ff..0d5bdb153d3b 100644
--- a/Documentation/scsi/st.txt
+++ b/Documentation/scsi/st.txt
@@ -506,9 +506,11 @@ user does not request data that far.)
506 506
507DEBUGGING HINTS 507DEBUGGING HINTS
508 508
509To enable debugging messages, edit st.c and #define DEBUG 1. As seen 509Debugging code is now compiled in by default but debugging is turned off
510above, debugging can be switched off with an ioctl if debugging is 510with the kernel module parameter debug_flag defaulting to 0. Debugging
511compiled into the driver. The debugging output is not voluminous. 511can still be switched on and off with an ioctl. To enable debug at
512module load time add debug_flag=1 to the module load options, the
513debugging output is not voluminous.
512 514
513If the tape seems to hang, I would be very interested to hear where 515If the tape seems to hang, I would be very interested to hear where
514the driver is waiting. With the command 'ps -l' you can see the state 516the driver is waiting. With the command 'ps -l' you can see the state
diff --git a/block/blk-core.c b/block/blk-core.c
index 0421b53e6431..2e7424b42947 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1266,7 +1266,7 @@ void blk_requeue_request(struct request_queue *q, struct request *rq)
1266 blk_clear_rq_complete(rq); 1266 blk_clear_rq_complete(rq);
1267 trace_block_rq_requeue(q, rq); 1267 trace_block_rq_requeue(q, rq);
1268 1268
1269 if (blk_rq_tagged(rq)) 1269 if (rq->cmd_flags & REQ_QUEUED)
1270 blk_queue_end_tag(q, rq); 1270 blk_queue_end_tag(q, rq);
1271 1271
1272 BUG_ON(blk_queued_rq(rq)); 1272 BUG_ON(blk_queued_rq(rq));
@@ -2554,7 +2554,7 @@ EXPORT_SYMBOL_GPL(blk_unprep_request);
2554 */ 2554 */
2555void blk_finish_request(struct request *req, int error) 2555void blk_finish_request(struct request *req, int error)
2556{ 2556{
2557 if (blk_rq_tagged(req)) 2557 if (req->cmd_flags & REQ_QUEUED)
2558 blk_queue_end_tag(req->q, req); 2558 blk_queue_end_tag(req->q, req);
2559 2559
2560 BUG_ON(blk_queued_rq(req)); 2560 BUG_ON(blk_queued_rq(req));
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 8317175a3009..728b9a4d5f56 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -584,6 +584,34 @@ int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int tdepth)
584 return 0; 584 return 0;
585} 585}
586 586
587/**
588 * blk_mq_unique_tag() - return a tag that is unique queue-wide
589 * @rq: request for which to compute a unique tag
590 *
591 * The tag field in struct request is unique per hardware queue but not over
592 * all hardware queues. Hence this function that returns a tag with the
593 * hardware context index in the upper bits and the per hardware queue tag in
594 * the lower bits.
595 *
596 * Note: When called for a request that is queued on a non-multiqueue request
597 * queue, the hardware context index is set to zero.
598 */
599u32 blk_mq_unique_tag(struct request *rq)
600{
601 struct request_queue *q = rq->q;
602 struct blk_mq_hw_ctx *hctx;
603 int hwq = 0;
604
605 if (q->mq_ops) {
606 hctx = q->mq_ops->map_queue(q, rq->mq_ctx->cpu);
607 hwq = hctx->queue_num;
608 }
609
610 return (hwq << BLK_MQ_UNIQUE_TAG_BITS) |
611 (rq->tag & BLK_MQ_UNIQUE_TAG_MASK);
612}
613EXPORT_SYMBOL(blk_mq_unique_tag);
614
587ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page) 615ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page)
588{ 616{
589 char *orig_page = page; 617 char *orig_page = page;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 1d016fc9a8b6..92ceef0d2ab9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2049,6 +2049,8 @@ static int blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set)
2049 */ 2049 */
2050int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set) 2050int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
2051{ 2051{
2052 BUILD_BUG_ON(BLK_MQ_MAX_DEPTH > 1 << BLK_MQ_UNIQUE_TAG_BITS);
2053
2052 if (!set->nr_hw_queues) 2054 if (!set->nr_hw_queues)
2053 return -EINVAL; 2055 return -EINVAL;
2054 if (!set->queue_depth) 2056 if (!set->queue_depth)
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index b0c2a616c8f9..28163fad3c5d 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -142,7 +142,7 @@ static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
142 __set_bit(GPCMD_VERIFY_10, filter->read_ok); 142 __set_bit(GPCMD_VERIFY_10, filter->read_ok);
143 __set_bit(VERIFY_16, filter->read_ok); 143 __set_bit(VERIFY_16, filter->read_ok);
144 __set_bit(REPORT_LUNS, filter->read_ok); 144 __set_bit(REPORT_LUNS, filter->read_ok);
145 __set_bit(SERVICE_ACTION_IN, filter->read_ok); 145 __set_bit(SERVICE_ACTION_IN_16, filter->read_ok);
146 __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok); 146 __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok);
147 __set_bit(MAINTENANCE_IN, filter->read_ok); 147 __set_bit(MAINTENANCE_IN, filter->read_ok);
148 __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok); 148 __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok);
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 0586f66d70fa..fc6a60abe518 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1164,7 +1164,7 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
1164 1164
1165 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); 1165 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id));
1166 depth = min(ATA_MAX_QUEUE - 1, depth); 1166 depth = min(ATA_MAX_QUEUE - 1, depth);
1167 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); 1167 scsi_adjust_queue_depth(sdev, depth);
1168 } 1168 }
1169 1169
1170 blk_queue_flush_queueable(q, false); 1170 blk_queue_flush_queueable(q, false);
@@ -1282,7 +1282,7 @@ int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1282 if (sdev->queue_depth == queue_depth) 1282 if (sdev->queue_depth == queue_depth)
1283 return -EINVAL; 1283 return -EINVAL;
1284 1284
1285 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, queue_depth); 1285 scsi_adjust_queue_depth(sdev, queue_depth);
1286 return queue_depth; 1286 return queue_depth;
1287} 1287}
1288 1288
@@ -3570,7 +3570,7 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
3570 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); 3570 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap);
3571 break; 3571 break;
3572 3572
3573 case SERVICE_ACTION_IN: 3573 case SERVICE_ACTION_IN_16:
3574 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16) 3574 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16)
3575 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); 3575 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap);
3576 else 3576 else
diff --git a/drivers/block/nvme-scsi.c b/drivers/block/nvme-scsi.c
index a4cd6d691c63..0b4b2775600e 100644
--- a/drivers/block/nvme-scsi.c
+++ b/drivers/block/nvme-scsi.c
@@ -329,7 +329,7 @@ INQUIRY_EVPD_BIT_MASK) ? 1 : 0)
329(GET_U32_FROM_CDB(cdb, READ_CAP_16_CDB_ALLOC_LENGTH_OFFSET)) 329(GET_U32_FROM_CDB(cdb, READ_CAP_16_CDB_ALLOC_LENGTH_OFFSET))
330 330
331#define IS_READ_CAP_16(cdb) \ 331#define IS_READ_CAP_16(cdb) \
332((cdb[0] == SERVICE_ACTION_IN && cdb[1] == SAI_READ_CAPACITY_16) ? 1 : 0) 332((cdb[0] == SERVICE_ACTION_IN_16 && cdb[1] == SAI_READ_CAPACITY_16) ? 1 : 0)
333 333
334/* Request Sense Helper Macros */ 334/* Request Sense Helper Macros */
335#define GET_REQUEST_SENSE_ALLOC_LENGTH(cdb) \ 335#define GET_REQUEST_SENSE_ALLOC_LENGTH(cdb) \
@@ -2947,7 +2947,7 @@ static int nvme_scsi_translate(struct nvme_ns *ns, struct sg_io_hdr *hdr)
2947 case READ_CAPACITY: 2947 case READ_CAPACITY:
2948 retcode = nvme_trans_read_capacity(ns, hdr, cmd); 2948 retcode = nvme_trans_read_capacity(ns, hdr, cmd);
2949 break; 2949 break;
2950 case SERVICE_ACTION_IN: 2950 case SERVICE_ACTION_IN_16:
2951 if (IS_READ_CAP_16(cmd)) 2951 if (IS_READ_CAP_16(cmd))
2952 retcode = nvme_trans_read_capacity(ns, hdr, cmd); 2952 retcode = nvme_trans_read_capacity(ns, hdr, cmd);
2953 else 2953 else
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 62d2a18e1b41..023a66f5ca14 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -2259,28 +2259,6 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
2259} 2259}
2260 2260
2261/** 2261/**
2262 * srp_change_queue_type - changing device queue tag type
2263 * @sdev: scsi device struct
2264 * @tag_type: requested tag type
2265 *
2266 * Returns queue tag type.
2267 */
2268static int
2269srp_change_queue_type(struct scsi_device *sdev, int tag_type)
2270{
2271 if (sdev->tagged_supported) {
2272 scsi_set_tag_type(sdev, tag_type);
2273 if (tag_type)
2274 scsi_activate_tcq(sdev, sdev->queue_depth);
2275 else
2276 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2277 } else
2278 tag_type = 0;
2279
2280 return tag_type;
2281}
2282
2283/**
2284 * srp_change_queue_depth - setting device queue depth 2262 * srp_change_queue_depth - setting device queue depth
2285 * @sdev: scsi device struct 2263 * @sdev: scsi device struct
2286 * @qdepth: requested queue depth 2264 * @qdepth: requested queue depth
@@ -2300,7 +2278,7 @@ srp_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2300 max_depth = 1; 2278 max_depth = 1;
2301 if (qdepth > max_depth) 2279 if (qdepth > max_depth)
2302 qdepth = max_depth; 2280 qdepth = max_depth;
2303 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 2281 scsi_adjust_queue_depth(sdev, qdepth);
2304 } else if (reason == SCSI_QDEPTH_QFULL) 2282 } else if (reason == SCSI_QDEPTH_QFULL)
2305 scsi_track_queue_full(sdev, qdepth); 2283 scsi_track_queue_full(sdev, qdepth);
2306 else 2284 else
@@ -2600,7 +2578,7 @@ static struct scsi_host_template srp_template = {
2600 .info = srp_target_info, 2578 .info = srp_target_info,
2601 .queuecommand = srp_queuecommand, 2579 .queuecommand = srp_queuecommand,
2602 .change_queue_depth = srp_change_queue_depth, 2580 .change_queue_depth = srp_change_queue_depth,
2603 .change_queue_type = srp_change_queue_type, 2581 .change_queue_type = scsi_change_queue_type,
2604 .eh_abort_handler = srp_abort, 2582 .eh_abort_handler = srp_abort,
2605 .eh_device_reset_handler = srp_reset_device, 2583 .eh_device_reset_handler = srp_reset_device,
2606 .eh_host_reset_handler = srp_reset_host, 2584 .eh_host_reset_handler = srp_reset_host,
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 0707fa2c701b..5bdaae15a742 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1994,6 +1994,7 @@ static struct scsi_host_template mptsas_driver_template = {
1994 .cmd_per_lun = 7, 1994 .cmd_per_lun = 7,
1995 .use_clustering = ENABLE_CLUSTERING, 1995 .use_clustering = ENABLE_CLUSTERING,
1996 .shost_attrs = mptscsih_host_attrs, 1996 .shost_attrs = mptscsih_host_attrs,
1997 .use_blk_tags = 1,
1997}; 1998};
1998 1999
1999static int mptsas_get_linkerrors(struct sas_phy *phy) 2000static int mptsas_get_linkerrors(struct sas_phy *phy)
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index e7dcb2583369..dee06d6f0b68 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -2322,7 +2322,6 @@ mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2322 VirtTarget *vtarget; 2322 VirtTarget *vtarget;
2323 struct scsi_target *starget; 2323 struct scsi_target *starget;
2324 int max_depth; 2324 int max_depth;
2325 int tagged;
2326 MPT_ADAPTER *ioc = hd->ioc; 2325 MPT_ADAPTER *ioc = hd->ioc;
2327 2326
2328 starget = scsi_target(sdev); 2327 starget = scsi_target(sdev);
@@ -2347,12 +2346,8 @@ mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2347 2346
2348 if (qdepth > max_depth) 2347 if (qdepth > max_depth)
2349 qdepth = max_depth; 2348 qdepth = max_depth;
2350 if (qdepth == 1)
2351 tagged = 0;
2352 else
2353 tagged = MSG_SIMPLE_TAG;
2354 2349
2355 scsi_adjust_queue_depth(sdev, tagged, qdepth); 2350 scsi_adjust_queue_depth(sdev, qdepth);
2356 return sdev->queue_depth; 2351 return sdev->queue_depth;
2357} 2352}
2358 2353
@@ -2400,9 +2395,8 @@ mptscsih_slave_configure(struct scsi_device *sdev)
2400 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH, 2395 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH,
2401 SCSI_QDEPTH_DEFAULT); 2396 SCSI_QDEPTH_DEFAULT);
2402 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2397 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2403 "tagged %d, simple %d, ordered %d\n", 2398 "tagged %d, simple %d\n",
2404 ioc->name,sdev->tagged_supported, sdev->simple_tags, 2399 ioc->name,sdev->tagged_supported, sdev->simple_tags));
2405 sdev->ordered_tags));
2406 2400
2407 blk_queue_dma_alignment (sdev->request_queue, 512 - 1); 2401 blk_queue_dma_alignment (sdev->request_queue, 512 - 1);
2408 2402
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 2cf2bbc0b927..180a5442fd4b 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -187,6 +187,7 @@ void enclosure_unregister(struct enclosure_device *edev)
187EXPORT_SYMBOL_GPL(enclosure_unregister); 187EXPORT_SYMBOL_GPL(enclosure_unregister);
188 188
189#define ENCLOSURE_NAME_SIZE 64 189#define ENCLOSURE_NAME_SIZE 64
190#define COMPONENT_NAME_SIZE 64
190 191
191static void enclosure_link_name(struct enclosure_component *cdev, char *name) 192static void enclosure_link_name(struct enclosure_component *cdev, char *name)
192{ 193{
@@ -246,6 +247,29 @@ static void enclosure_component_release(struct device *dev)
246 put_device(dev->parent); 247 put_device(dev->parent);
247} 248}
248 249
250static struct enclosure_component *
251enclosure_component_find_by_name(struct enclosure_device *edev,
252 const char *name)
253{
254 int i;
255 const char *cname;
256 struct enclosure_component *ecomp;
257
258 if (!edev || !name || !name[0])
259 return NULL;
260
261 for (i = 0; i < edev->components; i++) {
262 ecomp = &edev->component[i];
263 cname = dev_name(&ecomp->cdev);
264 if (ecomp->number != -1 &&
265 cname && cname[0] &&
266 !strcmp(cname, name))
267 return ecomp;
268 }
269
270 return NULL;
271}
272
249static const struct attribute_group *enclosure_component_groups[]; 273static const struct attribute_group *enclosure_component_groups[];
250 274
251/** 275/**
@@ -269,7 +293,8 @@ enclosure_component_register(struct enclosure_device *edev,
269{ 293{
270 struct enclosure_component *ecomp; 294 struct enclosure_component *ecomp;
271 struct device *cdev; 295 struct device *cdev;
272 int err; 296 int err, i;
297 char newname[COMPONENT_NAME_SIZE];
273 298
274 if (number >= edev->components) 299 if (number >= edev->components)
275 return ERR_PTR(-EINVAL); 300 return ERR_PTR(-EINVAL);
@@ -283,9 +308,20 @@ enclosure_component_register(struct enclosure_device *edev,
283 ecomp->number = number; 308 ecomp->number = number;
284 cdev = &ecomp->cdev; 309 cdev = &ecomp->cdev;
285 cdev->parent = get_device(&edev->edev); 310 cdev->parent = get_device(&edev->edev);
286 if (name && name[0]) 311
287 dev_set_name(cdev, "%s", name); 312 if (name && name[0]) {
288 else 313 /* Some hardware (e.g. enclosure in RX300 S6) has components
314 * with non unique names. Registering duplicates in sysfs
315 * will lead to warnings during bootup. So make the names
316 * unique by appending consecutive numbers -1, -2, ... */
317 i = 1;
318 snprintf(newname, COMPONENT_NAME_SIZE,
319 "%s", name);
320 while (enclosure_component_find_by_name(edev, newname))
321 snprintf(newname, COMPONENT_NAME_SIZE,
322 "%s-%i", name, i++);
323 dev_set_name(cdev, "%s", newname);
324 } else
289 dev_set_name(cdev, "%u", number); 325 dev_set_name(cdev, "%u", number);
290 326
291 cdev->release = enclosure_component_release; 327 cdev->release = enclosure_component_release;
diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
index b1d2024ed513..df2b541c8287 100644
--- a/drivers/s390/scsi/zfcp_fc.h
+++ b/drivers/s390/scsi/zfcp_fc.h
@@ -212,8 +212,6 @@ static inline
212void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi, 212void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi,
213 u8 tm_flags) 213 u8 tm_flags)
214{ 214{
215 char tag[2];
216
217 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun); 215 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
218 216
219 if (unlikely(tm_flags)) { 217 if (unlikely(tm_flags)) {
@@ -221,17 +219,7 @@ void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi,
221 return; 219 return;
222 } 220 }
223 221
224 if (scsi_populate_tag_msg(scsi, tag)) { 222 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
225 switch (tag[0]) {
226 case MSG_ORDERED_TAG:
227 fcp->fc_pri_ta |= FCP_PTA_ORDERED;
228 break;
229 case MSG_SIMPLE_TAG:
230 fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
231 break;
232 };
233 } else
234 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
235 223
236 if (scsi->sc_data_direction == DMA_FROM_DEVICE) 224 if (scsi->sc_data_direction == DMA_FROM_DEVICE)
237 fcp->fc_flags |= FCP_CFL_RDDATA; 225 fcp->fc_flags |= FCP_CFL_RDDATA;
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 7b353647cb90..b5dfa51f396f 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -37,13 +37,13 @@ static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth,
37{ 37{
38 switch (reason) { 38 switch (reason) {
39 case SCSI_QDEPTH_DEFAULT: 39 case SCSI_QDEPTH_DEFAULT:
40 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 40 scsi_adjust_queue_depth(sdev, depth);
41 break; 41 break;
42 case SCSI_QDEPTH_QFULL: 42 case SCSI_QDEPTH_QFULL:
43 scsi_track_queue_full(sdev, depth); 43 scsi_track_queue_full(sdev, depth);
44 break; 44 break;
45 case SCSI_QDEPTH_RAMP_UP: 45 case SCSI_QDEPTH_RAMP_UP:
46 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 46 scsi_adjust_queue_depth(sdev, depth);
47 break; 47 break;
48 default: 48 default:
49 return -EOPNOTSUPP; 49 return -EOPNOTSUPP;
@@ -66,9 +66,7 @@ static void zfcp_scsi_slave_destroy(struct scsi_device *sdev)
66static int zfcp_scsi_slave_configure(struct scsi_device *sdp) 66static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
67{ 67{
68 if (sdp->tagged_supported) 68 if (sdp->tagged_supported)
69 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, default_depth); 69 scsi_adjust_queue_depth(sdp, default_depth);
70 else
71 scsi_adjust_queue_depth(sdp, 0, 1);
72 return 0; 70 return 0;
73} 71}
74 72
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 0a7325361d29..02021f5ca866 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -198,7 +198,7 @@ static int twa_change_queue_depth(struct scsi_device *sdev, int queue_depth,
198 198
199 if (queue_depth > TW_Q_LENGTH-2) 199 if (queue_depth > TW_Q_LENGTH-2)
200 queue_depth = TW_Q_LENGTH-2; 200 queue_depth = TW_Q_LENGTH-2;
201 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); 201 scsi_adjust_queue_depth(sdev, queue_depth);
202 return queue_depth; 202 return queue_depth;
203} /* End twa_change_queue_depth() */ 203} /* End twa_change_queue_depth() */
204 204
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 6da6cec9a651..ac0c2544a470 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -200,7 +200,7 @@ static int twl_change_queue_depth(struct scsi_device *sdev, int queue_depth,
200 200
201 if (queue_depth > TW_Q_LENGTH-2) 201 if (queue_depth > TW_Q_LENGTH-2)
202 queue_depth = TW_Q_LENGTH-2; 202 queue_depth = TW_Q_LENGTH-2;
203 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); 203 scsi_adjust_queue_depth(sdev, queue_depth);
204 return queue_depth; 204 return queue_depth;
205} /* End twl_change_queue_depth() */ 205} /* End twl_change_queue_depth() */
206 206
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 752624e6bc00..1ec9ad92b6c3 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -532,7 +532,7 @@ static int tw_change_queue_depth(struct scsi_device *sdev, int queue_depth,
532 532
533 if (queue_depth > TW_Q_LENGTH-2) 533 if (queue_depth > TW_Q_LENGTH-2)
534 queue_depth = TW_Q_LENGTH-2; 534 queue_depth = TW_Q_LENGTH-2;
535 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); 535 scsi_adjust_queue_depth(sdev, queue_depth);
536 return queue_depth; 536 return queue_depth;
537} /* End tw_change_queue_depth() */ 537} /* End tw_change_queue_depth() */
538 538
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index fabd4be2c985..d7557b932113 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -327,6 +327,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
327 tpnt->slave_alloc = NCR_700_slave_alloc; 327 tpnt->slave_alloc = NCR_700_slave_alloc;
328 tpnt->change_queue_depth = NCR_700_change_queue_depth; 328 tpnt->change_queue_depth = NCR_700_change_queue_depth;
329 tpnt->change_queue_type = NCR_700_change_queue_type; 329 tpnt->change_queue_type = NCR_700_change_queue_type;
330 tpnt->use_blk_tags = 1;
330 331
331 if(tpnt->name == NULL) 332 if(tpnt->name == NULL)
332 tpnt->name = "53c700"; 333 tpnt->name = "53c700";
@@ -592,19 +593,14 @@ NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
592 hostdata->cmd = NULL; 593 hostdata->cmd = NULL;
593 594
594 if(SCp != NULL) { 595 if(SCp != NULL) {
595 struct NCR_700_command_slot *slot = 596 struct NCR_700_command_slot *slot =
596 (struct NCR_700_command_slot *)SCp->host_scribble; 597 (struct NCR_700_command_slot *)SCp->host_scribble;
597 598
598 dma_unmap_single(hostdata->dev, slot->pCmd, 599 dma_unmap_single(hostdata->dev, slot->pCmd,
599 MAX_COMMAND_SIZE, DMA_TO_DEVICE); 600 MAX_COMMAND_SIZE, DMA_TO_DEVICE);
600 if (slot->flags == NCR_700_FLAG_AUTOSENSE) { 601 if (slot->flags == NCR_700_FLAG_AUTOSENSE) {
601 char *cmnd = NCR_700_get_sense_cmnd(SCp->device); 602 char *cmnd = NCR_700_get_sense_cmnd(SCp->device);
602#ifdef NCR_700_DEBUG
603 printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense is\n",
604 SCp, SCp->cmnd[7], result);
605 scsi_print_sense("53c700", SCp);
606 603
607#endif
608 dma_unmap_single(hostdata->dev, slot->dma_handle, 604 dma_unmap_single(hostdata->dev, slot->dma_handle,
609 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE); 605 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
610 /* restore the old result if the request sense was 606 /* restore the old result if the request sense was
@@ -906,8 +902,10 @@ process_message(struct Scsi_Host *host, struct NCR_700_Host_Parameters *hostdata
906 /* we're done negotiating */ 902 /* we're done negotiating */
907 NCR_700_set_tag_neg_state(SCp->device, NCR_700_FINISHED_TAG_NEGOTIATION); 903 NCR_700_set_tag_neg_state(SCp->device, NCR_700_FINISHED_TAG_NEGOTIATION);
908 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp)); 904 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp));
905
909 SCp->device->tagged_supported = 0; 906 SCp->device->tagged_supported = 0;
910 scsi_deactivate_tcq(SCp->device, host->cmd_per_lun); 907 scsi_adjust_queue_depth(SCp->device, host->cmd_per_lun);
908 scsi_set_tag_type(SCp->device, 0);
911 } else { 909 } else {
912 shost_printk(KERN_WARNING, host, 910 shost_printk(KERN_WARNING, host,
913 "(%d:%d) Unexpected REJECT Message %s\n", 911 "(%d:%d) Unexpected REJECT Message %s\n",
@@ -1432,7 +1430,7 @@ NCR_700_start_command(struct scsi_cmnd *SCp)
1432 if((hostdata->tag_negotiated & (1<<scmd_id(SCp))) 1430 if((hostdata->tag_negotiated & (1<<scmd_id(SCp)))
1433 && (slot->tag != SCSI_NO_TAG && SCp->cmnd[0] != REQUEST_SENSE && 1431 && (slot->tag != SCSI_NO_TAG && SCp->cmnd[0] != REQUEST_SENSE &&
1434 slot->flags != NCR_700_FLAG_AUTOSENSE)) { 1432 slot->flags != NCR_700_FLAG_AUTOSENSE)) {
1435 count += scsi_populate_tag_msg(SCp, &hostdata->msgout[count]); 1433 count += spi_populate_tag_msg(&hostdata->msgout[count], SCp);
1436 } 1434 }
1437 1435
1438 if(hostdata->fast && 1436 if(hostdata->fast &&
@@ -1772,7 +1770,7 @@ NCR_700_queuecommand_lck(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *)
1772 */ 1770 */
1773 if(NCR_700_get_depth(SCp->device) != 0 1771 if(NCR_700_get_depth(SCp->device) != 0
1774 && (!(hostdata->tag_negotiated & (1<<scmd_id(SCp))) 1772 && (!(hostdata->tag_negotiated & (1<<scmd_id(SCp)))
1775 || !blk_rq_tagged(SCp->request))) { 1773 || !(SCp->flags & SCMD_TAGGED))) {
1776 CDEBUG(KERN_ERR, SCp, "has non zero depth %d\n", 1774 CDEBUG(KERN_ERR, SCp, "has non zero depth %d\n",
1777 NCR_700_get_depth(SCp->device)); 1775 NCR_700_get_depth(SCp->device));
1778 return SCSI_MLQUEUE_DEVICE_BUSY; 1776 return SCSI_MLQUEUE_DEVICE_BUSY;
@@ -1800,7 +1798,7 @@ NCR_700_queuecommand_lck(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *)
1800 printk("53c700: scsi%d, command ", SCp->device->host->host_no); 1798 printk("53c700: scsi%d, command ", SCp->device->host->host_no);
1801 scsi_print_command(SCp); 1799 scsi_print_command(SCp);
1802#endif 1800#endif
1803 if(blk_rq_tagged(SCp->request) 1801 if ((SCp->flags & SCMD_TAGGED)
1804 && (hostdata->tag_negotiated &(1<<scmd_id(SCp))) == 0 1802 && (hostdata->tag_negotiated &(1<<scmd_id(SCp))) == 0
1805 && NCR_700_get_tag_neg_state(SCp->device) == NCR_700_START_TAG_NEGOTIATION) { 1803 && NCR_700_get_tag_neg_state(SCp->device) == NCR_700_START_TAG_NEGOTIATION) {
1806 scmd_printk(KERN_ERR, SCp, "Enabling Tag Command Queuing\n"); 1804 scmd_printk(KERN_ERR, SCp, "Enabling Tag Command Queuing\n");
@@ -1814,7 +1812,7 @@ NCR_700_queuecommand_lck(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *)
1814 * 1812 *
1815 * FIXME: This will royally screw up on multiple LUN devices 1813 * FIXME: This will royally screw up on multiple LUN devices
1816 * */ 1814 * */
1817 if(!blk_rq_tagged(SCp->request) 1815 if (!(SCp->flags & SCMD_TAGGED)
1818 && (hostdata->tag_negotiated &(1<<scmd_id(SCp)))) { 1816 && (hostdata->tag_negotiated &(1<<scmd_id(SCp)))) {
1819 scmd_printk(KERN_INFO, SCp, "Disabling Tag Command Queuing\n"); 1817 scmd_printk(KERN_INFO, SCp, "Disabling Tag Command Queuing\n");
1820 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp)); 1818 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp));
@@ -1911,9 +1909,7 @@ NCR_700_abort(struct scsi_cmnd * SCp)
1911{ 1909{
1912 struct NCR_700_command_slot *slot; 1910 struct NCR_700_command_slot *slot;
1913 1911
1914 scmd_printk(KERN_INFO, SCp, 1912 scmd_printk(KERN_INFO, SCp, "abort command\n");
1915 "New error handler wants to abort command\n\t");
1916 scsi_print_command(SCp);
1917 1913
1918 slot = (struct NCR_700_command_slot *)SCp->host_scribble; 1914 slot = (struct NCR_700_command_slot *)SCp->host_scribble;
1919 1915
@@ -2056,13 +2052,10 @@ NCR_700_slave_configure(struct scsi_device *SDp)
2056 2052
2057 /* to do here: allocate memory; build a queue_full list */ 2053 /* to do here: allocate memory; build a queue_full list */
2058 if(SDp->tagged_supported) { 2054 if(SDp->tagged_supported) {
2059 scsi_set_tag_type(SDp, MSG_ORDERED_TAG); 2055 scsi_adjust_queue_depth(SDp, NCR_700_DEFAULT_TAGS);
2060 scsi_activate_tcq(SDp, NCR_700_DEFAULT_TAGS);
2061 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION); 2056 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION);
2062 } else {
2063 /* initialise to default depth */
2064 scsi_adjust_queue_depth(SDp, 0, SDp->host->cmd_per_lun);
2065 } 2057 }
2058
2066 if(hostdata->fast) { 2059 if(hostdata->fast) {
2067 /* Find the correct offset and period via domain validation */ 2060 /* Find the correct offset and period via domain validation */
2068 if (!spi_initial_dv(SDp->sdev_target)) 2061 if (!spi_initial_dv(SDp->sdev_target))
@@ -2090,7 +2083,7 @@ NCR_700_change_queue_depth(struct scsi_device *SDp, int depth, int reason)
2090 if (depth > NCR_700_MAX_TAGS) 2083 if (depth > NCR_700_MAX_TAGS)
2091 depth = NCR_700_MAX_TAGS; 2084 depth = NCR_700_MAX_TAGS;
2092 2085
2093 scsi_adjust_queue_depth(SDp, scsi_get_tag_type(SDp), depth); 2086 scsi_adjust_queue_depth(SDp, depth);
2094 return depth; 2087 return depth;
2095} 2088}
2096 2089
@@ -2101,8 +2094,6 @@ static int NCR_700_change_queue_type(struct scsi_device *SDp, int tag_type)
2101 struct NCR_700_Host_Parameters *hostdata = 2094 struct NCR_700_Host_Parameters *hostdata =
2102 (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0]; 2095 (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0];
2103 2096
2104 scsi_set_tag_type(SDp, tag_type);
2105
2106 /* We have a global (per target) flag to track whether TCQ is 2097 /* We have a global (per target) flag to track whether TCQ is
2107 * enabled, so we'll be turning it off for the entire target here. 2098 * enabled, so we'll be turning it off for the entire target here.
2108 * our tag algorithm will fail if we mix tagged and untagged commands, 2099 * our tag algorithm will fail if we mix tagged and untagged commands,
@@ -2110,15 +2101,16 @@ static int NCR_700_change_queue_type(struct scsi_device *SDp, int tag_type)
2110 if (change_tag) 2101 if (change_tag)
2111 scsi_target_quiesce(SDp->sdev_target); 2102 scsi_target_quiesce(SDp->sdev_target);
2112 2103
2104 scsi_set_tag_type(SDp, tag_type);
2113 if (!tag_type) { 2105 if (!tag_type) {
2114 /* shift back to the default unqueued number of commands 2106 /* shift back to the default unqueued number of commands
2115 * (the user can still raise this) */ 2107 * (the user can still raise this) */
2116 scsi_deactivate_tcq(SDp, SDp->host->cmd_per_lun); 2108 scsi_adjust_queue_depth(SDp, SDp->host->cmd_per_lun);
2117 hostdata->tag_negotiated &= ~(1 << sdev_id(SDp)); 2109 hostdata->tag_negotiated &= ~(1 << sdev_id(SDp));
2118 } else { 2110 } else {
2119 /* Here, we cleared the negotiation flag above, so this 2111 /* Here, we cleared the negotiation flag above, so this
2120 * will force the driver to renegotiate */ 2112 * will force the driver to renegotiate */
2121 scsi_activate_tcq(SDp, SDp->queue_depth); 2113 scsi_adjust_queue_depth(SDp, SDp->queue_depth);
2122 if (change_tag) 2114 if (change_tag)
2123 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION); 2115 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION);
2124 } 2116 }
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 64c75143c89a..5aa476b6b8a8 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -2327,12 +2327,12 @@ static int blogic_slaveconfig(struct scsi_device *dev)
2327 if (qdepth == 0) 2327 if (qdepth == 0)
2328 qdepth = BLOGIC_MAX_AUTO_TAG_DEPTH; 2328 qdepth = BLOGIC_MAX_AUTO_TAG_DEPTH;
2329 adapter->qdepth[tgt_id] = qdepth; 2329 adapter->qdepth[tgt_id] = qdepth;
2330 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, qdepth); 2330 scsi_adjust_queue_depth(dev, qdepth);
2331 } else { 2331 } else {
2332 adapter->tagq_ok &= ~(1 << tgt_id); 2332 adapter->tagq_ok &= ~(1 << tgt_id);
2333 qdepth = adapter->untag_qdepth; 2333 qdepth = adapter->untag_qdepth;
2334 adapter->qdepth[tgt_id] = qdepth; 2334 adapter->qdepth[tgt_id] = qdepth;
2335 scsi_adjust_queue_depth(dev, 0, qdepth); 2335 scsi_adjust_queue_depth(dev, qdepth);
2336 } 2336 }
2337 qdepth = 0; 2337 qdepth = 0;
2338 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2338 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 45da3c823322..296c6f53605a 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -2647,14 +2647,14 @@ static void NCR5380_dma_complete(NCR5380_instance * instance) {
2647 * 2647 *
2648 * Purpose : abort a command 2648 * Purpose : abort a command
2649 * 2649 *
2650 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the 2650 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the
2651 * host byte of the result field to, if zero DID_ABORTED is 2651 * host byte of the result field to, if zero DID_ABORTED is
2652 * used. 2652 * used.
2653 * 2653 *
2654 * Returns : 0 - success, -1 on failure. 2654 * Returns : SUCCESS - success, FAILED on failure.
2655 * 2655 *
2656 * XXX - there is no way to abort the command that is currently 2656 * XXX - there is no way to abort the command that is currently
2657 * connected, you have to wait for it to complete. If this is 2657 * connected, you have to wait for it to complete. If this is
2658 * a problem, we could implement longjmp() / setjmp(), setjmp() 2658 * a problem, we could implement longjmp() / setjmp(), setjmp()
2659 * called where the loop started in NCR5380_main(). 2659 * called where the loop started in NCR5380_main().
2660 * 2660 *
@@ -2666,9 +2666,8 @@ static int NCR5380_abort(Scsi_Cmnd * cmd) {
2666 struct Scsi_Host *instance = cmd->device->host; 2666 struct Scsi_Host *instance = cmd->device->host;
2667 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata; 2667 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata;
2668 Scsi_Cmnd *tmp, **prev; 2668 Scsi_Cmnd *tmp, **prev;
2669 2669
2670 printk(KERN_WARNING "scsi%d : aborting command\n", instance->host_no); 2670 scmd_printk(KERN_WARNING, cmd, "aborting command\n");
2671 scsi_print_command(cmd);
2672 2671
2673 NCR5380_print_status(instance); 2672 NCR5380_print_status(instance);
2674 2673
@@ -2704,7 +2703,7 @@ static int NCR5380_abort(Scsi_Cmnd * cmd) {
2704 * aborted flag and get back into our main loop. 2703 * aborted flag and get back into our main loop.
2705 */ 2704 */
2706 2705
2707 return 0; 2706 return SUCCESS;
2708 } 2707 }
2709#endif 2708#endif
2710 2709
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 681434e2dfe9..b32e77db0c48 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -2181,7 +2181,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2181 (fsa_dev_ptr[cid].sense_data.sense_key == 2181 (fsa_dev_ptr[cid].sense_data.sense_key ==
2182 NOT_READY)) { 2182 NOT_READY)) {
2183 switch (scsicmd->cmnd[0]) { 2183 switch (scsicmd->cmnd[0]) {
2184 case SERVICE_ACTION_IN: 2184 case SERVICE_ACTION_IN_16:
2185 if (!(dev->raw_io_interface) || 2185 if (!(dev->raw_io_interface) ||
2186 !(dev->raw_io_64) || 2186 !(dev->raw_io_64) ||
2187 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 2187 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
@@ -2309,7 +2309,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2309 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data)); 2309 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
2310 return aac_get_container_name(scsicmd); 2310 return aac_get_container_name(scsicmd);
2311 } 2311 }
2312 case SERVICE_ACTION_IN: 2312 case SERVICE_ACTION_IN_16:
2313 if (!(dev->raw_io_interface) || 2313 if (!(dev->raw_io_interface) ||
2314 !(dev->raw_io_64) || 2314 !(dev->raw_io_64) ||
2315 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 2315 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index a759cb2d4b15..4c340d88c33d 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -462,9 +462,9 @@ static int aac_slave_configure(struct scsi_device *sdev)
462 depth = 256; 462 depth = 256;
463 else if (depth < 2) 463 else if (depth < 2)
464 depth = 2; 464 depth = 2;
465 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth); 465 scsi_adjust_queue_depth(sdev, depth);
466 } else 466 } else
467 scsi_adjust_queue_depth(sdev, 0, 1); 467 scsi_adjust_queue_depth(sdev, 1);
468 468
469 return 0; 469 return 0;
470} 470}
@@ -504,9 +504,9 @@ static int aac_change_queue_depth(struct scsi_device *sdev, int depth,
504 depth = 256; 504 depth = 256;
505 else if (depth < 2) 505 else if (depth < 2)
506 depth = 2; 506 depth = 2;
507 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth); 507 scsi_adjust_queue_depth(sdev, depth);
508 } else 508 } else
509 scsi_adjust_queue_depth(sdev, 0, 1); 509 scsi_adjust_queue_depth(sdev, 1);
510 return sdev->queue_depth; 510 return sdev->queue_depth;
511} 511}
512 512
@@ -555,7 +555,7 @@ static int aac_eh_abort(struct scsi_cmnd* cmd)
555 AAC_DRIVERNAME, 555 AAC_DRIVERNAME,
556 host->host_no, sdev_channel(dev), sdev_id(dev), dev->lun); 556 host->host_no, sdev_channel(dev), sdev_id(dev), dev->lun);
557 switch (cmd->cmnd[0]) { 557 switch (cmd->cmnd[0]) {
558 case SERVICE_ACTION_IN: 558 case SERVICE_ACTION_IN_16:
559 if (!(aac->raw_io_interface) || 559 if (!(aac->raw_io_interface) ||
560 !(aac->raw_io_64) || 560 !(aac->raw_io_64) ||
561 ((cmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 561 ((cmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 43761c1c46f0..ae4840e4c1c5 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -7706,7 +7706,7 @@ advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
7706 asc_dvc->cfg->can_tagged_qng |= tid_bit; 7706 asc_dvc->cfg->can_tagged_qng |= tid_bit;
7707 asc_dvc->use_tagged_qng |= tid_bit; 7707 asc_dvc->use_tagged_qng |= tid_bit;
7708 } 7708 }
7709 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, 7709 scsi_adjust_queue_depth(sdev,
7710 asc_dvc->max_dvc_qng[sdev->id]); 7710 asc_dvc->max_dvc_qng[sdev->id]);
7711 } 7711 }
7712 } else { 7712 } else {
@@ -7714,7 +7714,6 @@ advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
7714 asc_dvc->cfg->can_tagged_qng &= ~tid_bit; 7714 asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
7715 asc_dvc->use_tagged_qng &= ~tid_bit; 7715 asc_dvc->use_tagged_qng &= ~tid_bit;
7716 } 7716 }
7717 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
7718 } 7717 }
7719 7718
7720 if ((sdev->lun == 0) && 7719 if ((sdev->lun == 0) &&
@@ -7849,10 +7848,8 @@ advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
7849 } 7848 }
7850 7849
7851 if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) { 7850 if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) {
7852 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, 7851 scsi_adjust_queue_depth(sdev,
7853 adv_dvc->max_dvc_qng); 7852 adv_dvc->max_dvc_qng);
7854 } else {
7855 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
7856 } 7853 }
7857} 7854}
7858 7855
diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index e77b72f78006..2b960b326daf 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -230,7 +230,7 @@
230 * 230 *
231 * 231 *
232 ************************************************************************** 232 **************************************************************************
233 233
234 see Documentation/scsi/aha152x.txt for configuration details 234 see Documentation/scsi/aha152x.txt for configuration details
235 235
236 **************************************************************************/ 236 **************************************************************************/
@@ -279,45 +279,11 @@ static LIST_HEAD(aha152x_host_list);
279#error define AUTOCONF or SETUP0 279#error define AUTOCONF or SETUP0
280#endif 280#endif
281 281
282#if defined(AHA152X_DEBUG)
283#define DEBUG_DEFAULT debug_eh
284
285#define DPRINTK(when,msgs...) \
286 do { if(HOSTDATA(shpnt)->debug & (when)) printk(msgs); } while(0)
287
288#define DO_LOCK(flags) \
289 do { \
290 if(spin_is_locked(&QLOCK)) { \
291 DPRINTK(debug_intr, DEBUG_LEAD "(%s:%d) already locked at %s:%d\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \
292 } \
293 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locking\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
294 spin_lock_irqsave(&QLOCK,flags); \
295 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
296 QLOCKER=__func__; \
297 QLOCKERL=__LINE__; \
298 } while(0)
299
300#define DO_UNLOCK(flags) \
301 do { \
302 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocking (locked at %s:%d)\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \
303 spin_unlock_irqrestore(&QLOCK,flags); \
304 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
305 QLOCKER="(not locked)"; \
306 QLOCKERL=0; \
307 } while(0)
308
309#else
310#define DPRINTK(when,msgs...)
311#define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags) 282#define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
312#define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags) 283#define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
313#endif
314 284
315#define LEAD "(scsi%d:%d:%d) " 285#define LEAD "(scsi%d:%d:%d) "
316#define WARN_LEAD KERN_WARNING LEAD
317#define INFO_LEAD KERN_INFO LEAD 286#define INFO_LEAD KERN_INFO LEAD
318#define NOTE_LEAD KERN_NOTICE LEAD
319#define ERR_LEAD KERN_ERR LEAD
320#define DEBUG_LEAD KERN_DEBUG LEAD
321#define CMDINFO(cmd) \ 287#define CMDINFO(cmd) \
322 (cmd) ? ((cmd)->device->host->host_no) : -1, \ 288 (cmd) ? ((cmd)->device->host->host_no) : -1, \
323 (cmd) ? ((cmd)->device->id & 0x0f) : -1, \ 289 (cmd) ? ((cmd)->device->id & 0x0f) : -1, \
@@ -345,10 +311,10 @@ CMD_INC_RESID(struct scsi_cmnd *cmd, int inc)
345 311
346enum { 312enum {
347 not_issued = 0x0001, /* command not yet issued */ 313 not_issued = 0x0001, /* command not yet issued */
348 selecting = 0x0002, /* target is beeing selected */ 314 selecting = 0x0002, /* target is being selected */
349 identified = 0x0004, /* IDENTIFY was sent */ 315 identified = 0x0004, /* IDENTIFY was sent */
350 disconnected = 0x0008, /* target disconnected */ 316 disconnected = 0x0008, /* target disconnected */
351 completed = 0x0010, /* target sent COMMAND COMPLETE */ 317 completed = 0x0010, /* target sent COMMAND COMPLETE */
352 aborted = 0x0020, /* ABORT was sent */ 318 aborted = 0x0020, /* ABORT was sent */
353 resetted = 0x0040, /* BUS DEVICE RESET was sent */ 319 resetted = 0x0040, /* BUS DEVICE RESET was sent */
354 spiordy = 0x0080, /* waiting for SPIORDY to raise */ 320 spiordy = 0x0080, /* waiting for SPIORDY to raise */
@@ -396,7 +362,6 @@ static int exttrans[] = {0, 0};
396module_param_array(exttrans, int, NULL, 0); 362module_param_array(exttrans, int, NULL, 0);
397MODULE_PARM_DESC(exttrans,"use extended translation"); 363MODULE_PARM_DESC(exttrans,"use extended translation");
398 364
399#if !defined(AHA152X_DEBUG)
400static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; 365static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
401module_param_array(aha152x, int, NULL, 0); 366module_param_array(aha152x, int, NULL, 0);
402MODULE_PARM_DESC(aha152x, "parameters for first controller"); 367MODULE_PARM_DESC(aha152x, "parameters for first controller");
@@ -404,19 +369,6 @@ MODULE_PARM_DESC(aha152x, "parameters for first controller");
404static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; 369static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
405module_param_array(aha152x1, int, NULL, 0); 370module_param_array(aha152x1, int, NULL, 0);
406MODULE_PARM_DESC(aha152x1, "parameters for second controller"); 371MODULE_PARM_DESC(aha152x1, "parameters for second controller");
407#else
408static int debug[] = {DEBUG_DEFAULT, DEBUG_DEFAULT};
409module_param_array(debug, int, NULL, 0);
410MODULE_PARM_DESC(debug, "flags for driver debugging");
411
412static int aha152x[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
413module_param_array(aha152x, int, NULL, 0);
414MODULE_PARM_DESC(aha152x, "parameters for first controller");
415
416static int aha152x1[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
417module_param_array(aha152x1, int, NULL, 0);
418MODULE_PARM_DESC(aha152x1, "parameters for second controller");
419#endif /* !defined(AHA152X_DEBUG) */
420#endif /* MODULE */ 372#endif /* MODULE */
421 373
422#ifdef __ISAPNP__ 374#ifdef __ISAPNP__
@@ -446,7 +398,7 @@ static struct scsi_host_template aha152x_driver_template;
446/* 398/*
447 * internal states of the host 399 * internal states of the host
448 * 400 *
449 */ 401 */
450enum aha152x_state { 402enum aha152x_state {
451 idle=0, 403 idle=0,
452 unknown, 404 unknown,
@@ -485,24 +437,16 @@ struct aha152x_hostdata {
485 spinlock_t lock; 437 spinlock_t lock;
486 /* host lock */ 438 /* host lock */
487 439
488#if defined(AHA152X_DEBUG)
489 const char *locker;
490 /* which function has the lock */
491 int lockerl; /* where did it get it */
492
493 int debug; /* current debugging setting */
494#endif
495
496#if defined(AHA152X_STAT) 440#if defined(AHA152X_STAT)
497 int total_commands; 441 int total_commands;
498 int disconnections; 442 int disconnections;
499 int busfree_without_any_action; 443 int busfree_without_any_action;
500 int busfree_without_old_command; 444 int busfree_without_old_command;
501 int busfree_without_new_command; 445 int busfree_without_new_command;
502 int busfree_without_done_command; 446 int busfree_without_done_command;
503 int busfree_with_check_condition; 447 int busfree_with_check_condition;
504 int count[maxstate]; 448 int count[maxstate];
505 int count_trans[maxstate]; 449 int count_trans[maxstate];
506 unsigned long time[maxstate]; 450 unsigned long time[maxstate];
507#endif 451#endif
508 452
@@ -514,7 +458,7 @@ struct aha152x_hostdata {
514 int delay; /* reset out delay */ 458 int delay; /* reset out delay */
515 int ext_trans; /* extended translation enabled */ 459 int ext_trans; /* extended translation enabled */
516 460
517 int swint; /* software-interrupt was fired during detect() */ 461 int swint; /* software-interrupt was fired during detect() */
518 int service; /* bh needs to be run */ 462 int service; /* bh needs to be run */
519 int in_intr; /* bh is running */ 463 int in_intr; /* bh is running */
520 464
@@ -543,7 +487,7 @@ struct aha152x_hostdata {
543 unsigned char msgi[256]; 487 unsigned char msgi[256];
544 /* received message bytes */ 488 /* received message bytes */
545 489
546 int msgo_i, msgo_len; 490 int msgo_i, msgo_len;
547 /* number of sent bytes and length of current messages */ 491 /* number of sent bytes and length of current messages */
548 unsigned char msgo[256]; 492 unsigned char msgo[256];
549 /* pending messages */ 493 /* pending messages */
@@ -689,7 +633,6 @@ static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
689static void done(struct Scsi_Host *shpnt, int error); 633static void done(struct Scsi_Host *shpnt, int error);
690 634
691/* diagnostics */ 635/* diagnostics */
692static void disp_ports(struct Scsi_Host *shpnt);
693static void show_command(Scsi_Cmnd * ptr); 636static void show_command(Scsi_Cmnd * ptr);
694static void show_queues(struct Scsi_Host *shpnt); 637static void show_queues(struct Scsi_Host *shpnt);
695static void disp_enintr(struct Scsi_Host *shpnt); 638static void disp_enintr(struct Scsi_Host *shpnt);
@@ -812,10 +755,6 @@ struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup)
812 DELAY = setup->delay; 755 DELAY = setup->delay;
813 EXT_TRANS = setup->ext_trans; 756 EXT_TRANS = setup->ext_trans;
814 757
815#if defined(AHA152X_DEBUG)
816 HOSTDATA(shpnt)->debug = setup->debug;
817#endif
818
819 SETPORT(SCSIID, setup->scsiid << 4); 758 SETPORT(SCSIID, setup->scsiid << 4);
820 shpnt->this_id = setup->scsiid; 759 shpnt->this_id = setup->scsiid;
821 760
@@ -941,31 +880,24 @@ void aha152x_release(struct Scsi_Host *shpnt)
941 * setup controller to generate interrupts depending 880 * setup controller to generate interrupts depending
942 * on current state (lock has to be acquired) 881 * on current state (lock has to be acquired)
943 * 882 *
944 */ 883 */
945static int setup_expected_interrupts(struct Scsi_Host *shpnt) 884static int setup_expected_interrupts(struct Scsi_Host *shpnt)
946{ 885{
947 if(CURRENT_SC) { 886 if(CURRENT_SC) {
948 CURRENT_SC->SCp.phase |= 1 << 16; 887 CURRENT_SC->SCp.phase |= 1 << 16;
949 888
950 if(CURRENT_SC->SCp.phase & selecting) { 889 if(CURRENT_SC->SCp.phase & selecting) {
951 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (seldo) (seltimo) (seldi)\n", CMDINFO(CURRENT_SC));
952 SETPORT(SSTAT1, SELTO); 890 SETPORT(SSTAT1, SELTO);
953 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0)); 891 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0));
954 SETPORT(SIMODE1, ENSELTIMO); 892 SETPORT(SIMODE1, ENSELTIMO);
955 } else { 893 } else {
956 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (busfree) %s\n", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.phase & spiordy ? "(spiordy)" : "");
957 SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0); 894 SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0);
958 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); 895 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
959 } 896 }
960 } else if(STATE==seldi) { 897 } else if(STATE==seldi) {
961 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (identify)\n", CMDINFO(CURRENT_SC));
962 SETPORT(SIMODE0, 0); 898 SETPORT(SIMODE0, 0);
963 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); 899 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
964 } else { 900 } else {
965 DPRINTK(debug_intr, DEBUG_LEAD "expecting: %s %s\n",
966 CMDINFO(CURRENT_SC),
967 DISCONNECTED_SC ? "(reselection)" : "",
968 ISSUE_SC ? "(busfree)" : "");
969 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0); 901 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0);
970 SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0)); 902 SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0));
971 } 903 }
@@ -977,7 +909,7 @@ static int setup_expected_interrupts(struct Scsi_Host *shpnt)
977} 909}
978 910
979 911
980/* 912/*
981 * Queue a command and setup interrupts for a free bus. 913 * Queue a command and setup interrupts for a free bus.
982 */ 914 */
983static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete, 915static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
@@ -986,15 +918,6 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
986 struct Scsi_Host *shpnt = SCpnt->device->host; 918 struct Scsi_Host *shpnt = SCpnt->device->host;
987 unsigned long flags; 919 unsigned long flags;
988 920
989#if defined(AHA152X_DEBUG)
990 if (HOSTDATA(shpnt)->debug & debug_queue) {
991 printk(INFO_LEAD "queue: %p; cmd_len=%d pieces=%d size=%u cmnd=",
992 CMDINFO(SCpnt), SCpnt, SCpnt->cmd_len,
993 scsi_sg_count(SCpnt), scsi_bufflen(SCpnt));
994 __scsi_print_command(SCpnt->cmnd);
995 }
996#endif
997
998 SCpnt->scsi_done = done; 921 SCpnt->scsi_done = done;
999 SCpnt->SCp.phase = not_issued | phase; 922 SCpnt->SCp.phase = not_issued | phase;
1000 SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */ 923 SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */
@@ -1004,13 +927,13 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
1004 927
1005 if(SCpnt->SCp.phase & (resetting|check_condition)) { 928 if(SCpnt->SCp.phase & (resetting|check_condition)) {
1006 if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) { 929 if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) {
1007 printk(ERR_LEAD "cannot reuse command\n", CMDINFO(SCpnt)); 930 scmd_printk(KERN_ERR, SCpnt, "cannot reuse command\n");
1008 return FAILED; 931 return FAILED;
1009 } 932 }
1010 } else { 933 } else {
1011 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC); 934 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
1012 if(!SCpnt->host_scribble) { 935 if(!SCpnt->host_scribble) {
1013 printk(ERR_LEAD "allocation failed\n", CMDINFO(SCpnt)); 936 scmd_printk(KERN_ERR, SCpnt, "allocation failed\n");
1014 return FAILED; 937 return FAILED;
1015 } 938 }
1016 } 939 }
@@ -1066,15 +989,6 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
1066 */ 989 */
1067static int aha152x_queue_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) 990static int aha152x_queue_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
1068{ 991{
1069#if 0
1070 if(*SCpnt->cmnd == REQUEST_SENSE) {
1071 SCpnt->result = 0;
1072 done(SCpnt);
1073
1074 return 0;
1075 }
1076#endif
1077
1078 return aha152x_internal_queue(SCpnt, NULL, 0, done); 992 return aha152x_internal_queue(SCpnt, NULL, 0, done);
1079} 993}
1080 994
@@ -1082,15 +996,10 @@ static DEF_SCSI_QCMD(aha152x_queue)
1082 996
1083 997
1084/* 998/*
1085 *
1086 * 999 *
1087 */ 1000 */
1088static void reset_done(Scsi_Cmnd *SCpnt) 1001static void reset_done(Scsi_Cmnd *SCpnt)
1089{ 1002{
1090#if 0
1091 struct Scsi_Host *shpnt = SCpnt->host;
1092 DPRINTK(debug_eh, INFO_LEAD "reset_done called\n", CMDINFO(SCpnt));
1093#endif
1094 if(SCSEM(SCpnt)) { 1003 if(SCSEM(SCpnt)) {
1095 complete(SCSEM(SCpnt)); 1004 complete(SCSEM(SCpnt));
1096 } else { 1005 } else {
@@ -1108,20 +1017,11 @@ static int aha152x_abort(Scsi_Cmnd *SCpnt)
1108 Scsi_Cmnd *ptr; 1017 Scsi_Cmnd *ptr;
1109 unsigned long flags; 1018 unsigned long flags;
1110 1019
1111#if defined(AHA152X_DEBUG)
1112 if(HOSTDATA(shpnt)->debug & debug_eh) {
1113 printk(DEBUG_LEAD "abort(%p)", CMDINFO(SCpnt), SCpnt);
1114 show_queues(shpnt);
1115 }
1116#endif
1117
1118 DO_LOCK(flags); 1020 DO_LOCK(flags);
1119 1021
1120 ptr=remove_SC(&ISSUE_SC, SCpnt); 1022 ptr=remove_SC(&ISSUE_SC, SCpnt);
1121 1023
1122 if(ptr) { 1024 if(ptr) {
1123 DPRINTK(debug_eh, DEBUG_LEAD "not yet issued - SUCCESS\n", CMDINFO(SCpnt));
1124
1125 HOSTDATA(shpnt)->commands--; 1025 HOSTDATA(shpnt)->commands--;
1126 if (!HOSTDATA(shpnt)->commands) 1026 if (!HOSTDATA(shpnt)->commands)
1127 SETPORT(PORTA, 0); 1027 SETPORT(PORTA, 0);
@@ -1131,7 +1031,7 @@ static int aha152x_abort(Scsi_Cmnd *SCpnt)
1131 SCpnt->host_scribble=NULL; 1031 SCpnt->host_scribble=NULL;
1132 1032
1133 return SUCCESS; 1033 return SUCCESS;
1134 } 1034 }
1135 1035
1136 DO_UNLOCK(flags); 1036 DO_UNLOCK(flags);
1137 1037
@@ -1142,7 +1042,8 @@ static int aha152x_abort(Scsi_Cmnd *SCpnt)
1142 * 1042 *
1143 */ 1043 */
1144 1044
1145 printk(ERR_LEAD "cannot abort running or disconnected command\n", CMDINFO(SCpnt)); 1045 scmd_printk(KERN_ERR, SCpnt,
1046 "cannot abort running or disconnected command\n");
1146 1047
1147 return FAILED; 1048 return FAILED;
1148} 1049}
@@ -1160,15 +1061,8 @@ static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1160 unsigned long flags; 1061 unsigned long flags;
1161 unsigned long timeleft; 1062 unsigned long timeleft;
1162 1063
1163#if defined(AHA152X_DEBUG)
1164 if(HOSTDATA(shpnt)->debug & debug_eh) {
1165 printk(INFO_LEAD "aha152x_device_reset(%p)", CMDINFO(SCpnt), SCpnt);
1166 show_queues(shpnt);
1167 }
1168#endif
1169
1170 if(CURRENT_SC==SCpnt) { 1064 if(CURRENT_SC==SCpnt) {
1171 printk(ERR_LEAD "cannot reset current device\n", CMDINFO(SCpnt)); 1065 scmd_printk(KERN_ERR, SCpnt, "cannot reset current device\n");
1172 return FAILED; 1066 return FAILED;
1173 } 1067 }
1174 1068
@@ -1208,7 +1102,7 @@ static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1208 } else if(disconnected) { 1102 } else if(disconnected) {
1209 append_SC(&DISCONNECTED_SC, SCpnt); 1103 append_SC(&DISCONNECTED_SC, SCpnt);
1210 } 1104 }
1211 1105
1212 ret = FAILED; 1106 ret = FAILED;
1213 } 1107 }
1214 1108
@@ -1227,12 +1121,12 @@ static void free_hard_reset_SCs(struct Scsi_Host *shpnt, Scsi_Cmnd **SCs)
1227 if(SCDATA(ptr)) { 1121 if(SCDATA(ptr)) {
1228 next = SCNEXT(ptr); 1122 next = SCNEXT(ptr);
1229 } else { 1123 } else {
1230 printk(DEBUG_LEAD "queue corrupted at %p\n", CMDINFO(ptr), ptr); 1124 scmd_printk(KERN_DEBUG, ptr,
1125 "queue corrupted at %p\n", ptr);
1231 next = NULL; 1126 next = NULL;
1232 } 1127 }
1233 1128
1234 if (!ptr->device->soft_reset) { 1129 if (!ptr->device->soft_reset) {
1235 DPRINTK(debug_eh, DEBUG_LEAD "disconnected command %p removed\n", CMDINFO(ptr), ptr);
1236 remove_SC(SCs, ptr); 1130 remove_SC(SCs, ptr);
1237 HOSTDATA(shpnt)->commands--; 1131 HOSTDATA(shpnt)->commands--;
1238 kfree(ptr->host_scribble); 1132 kfree(ptr->host_scribble);
@@ -1253,25 +1147,14 @@ static int aha152x_bus_reset_host(struct Scsi_Host *shpnt)
1253 1147
1254 DO_LOCK(flags); 1148 DO_LOCK(flags);
1255 1149
1256#if defined(AHA152X_DEBUG)
1257 if(HOSTDATA(shpnt)->debug & debug_eh) {
1258 printk(KERN_DEBUG "scsi%d: bus reset", shpnt->host_no);
1259 show_queues(shpnt);
1260 }
1261#endif
1262
1263 free_hard_reset_SCs(shpnt, &ISSUE_SC); 1150 free_hard_reset_SCs(shpnt, &ISSUE_SC);
1264 free_hard_reset_SCs(shpnt, &DISCONNECTED_SC); 1151 free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
1265 1152
1266 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting bus\n", shpnt->host_no);
1267
1268 SETPORT(SCSISEQ, SCSIRSTO); 1153 SETPORT(SCSISEQ, SCSIRSTO);
1269 mdelay(256); 1154 mdelay(256);
1270 SETPORT(SCSISEQ, 0); 1155 SETPORT(SCSISEQ, 0);
1271 mdelay(DELAY); 1156 mdelay(DELAY);
1272 1157
1273 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: bus resetted\n", shpnt->host_no);
1274
1275 setup_expected_interrupts(shpnt); 1158 setup_expected_interrupts(shpnt);
1276 if(HOSTDATA(shpnt)->commands==0) 1159 if(HOSTDATA(shpnt)->commands==0)
1277 SETPORT(PORTA, 0); 1160 SETPORT(PORTA, 0);
@@ -1333,11 +1216,7 @@ static void reset_ports(struct Scsi_Host *shpnt)
1333 */ 1216 */
1334int aha152x_host_reset_host(struct Scsi_Host *shpnt) 1217int aha152x_host_reset_host(struct Scsi_Host *shpnt)
1335{ 1218{
1336 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: host reset\n", shpnt->host_no);
1337
1338 aha152x_bus_reset_host(shpnt); 1219 aha152x_bus_reset_host(shpnt);
1339
1340 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting ports\n", shpnt->host_no);
1341 reset_ports(shpnt); 1220 reset_ports(shpnt);
1342 1221
1343 return SUCCESS; 1222 return SUCCESS;
@@ -1345,7 +1224,7 @@ int aha152x_host_reset_host(struct Scsi_Host *shpnt)
1345 1224
1346/* 1225/*
1347 * Reset the host (bus and controller) 1226 * Reset the host (bus and controller)
1348 * 1227 *
1349 */ 1228 */
1350static int aha152x_host_reset(Scsi_Cmnd *SCpnt) 1229static int aha152x_host_reset(Scsi_Cmnd *SCpnt)
1351{ 1230{
@@ -1411,7 +1290,9 @@ static void done(struct Scsi_Host *shpnt, int error)
1411{ 1290{
1412 if (CURRENT_SC) { 1291 if (CURRENT_SC) {
1413 if(DONE_SC) 1292 if(DONE_SC)
1414 printk(ERR_LEAD "there's already a completed command %p - will cause abort\n", CMDINFO(CURRENT_SC), DONE_SC); 1293 scmd_printk(KERN_ERR, CURRENT_SC,
1294 "there's already a completed command %p "
1295 "- will cause abort\n", DONE_SC);
1415 1296
1416 DONE_SC = CURRENT_SC; 1297 DONE_SC = CURRENT_SC;
1417 CURRENT_SC = NULL; 1298 CURRENT_SC = NULL;
@@ -1466,7 +1347,7 @@ static irqreturn_t intr(int irqno, void *dev_id)
1466 return IRQ_NONE; 1347 return IRQ_NONE;
1467 1348
1468 if( TESTLO(DMASTAT, INTSTAT) ) 1349 if( TESTLO(DMASTAT, INTSTAT) )
1469 return IRQ_NONE; 1350 return IRQ_NONE;
1470 1351
1471 /* no more interrupts from the controller, while we're busy. 1352 /* no more interrupts from the controller, while we're busy.
1472 INTEN is restored by the BH handler */ 1353 INTEN is restored by the BH handler */
@@ -1501,7 +1382,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
1501 SETPORT(SXFRCTL0, CH1); 1382 SETPORT(SXFRCTL0, CH1);
1502 1383
1503 SETPORT(SSTAT1, CLRBUSFREE); 1384 SETPORT(SSTAT1, CLRBUSFREE);
1504 1385
1505 if(CURRENT_SC) { 1386 if(CURRENT_SC) {
1506#if defined(AHA152X_STAT) 1387#if defined(AHA152X_STAT)
1507 action++; 1388 action++;
@@ -1513,19 +1394,13 @@ static void busfree_run(struct Scsi_Host *shpnt)
1513 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16)); 1394 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16));
1514 1395
1515 } else if(CURRENT_SC->SCp.phase & aborted) { 1396 } else if(CURRENT_SC->SCp.phase & aborted) {
1516 DPRINTK(debug_eh, DEBUG_LEAD "ABORT sent\n", CMDINFO(CURRENT_SC));
1517 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16)); 1397 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16));
1518 1398
1519 } else if(CURRENT_SC->SCp.phase & resetted) { 1399 } else if(CURRENT_SC->SCp.phase & resetted) {
1520 DPRINTK(debug_eh, DEBUG_LEAD "BUS DEVICE RESET sent\n", CMDINFO(CURRENT_SC));
1521 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16)); 1400 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16));
1522 1401
1523 } else if(CURRENT_SC->SCp.phase & disconnected) { 1402 } else if(CURRENT_SC->SCp.phase & disconnected) {
1524 /* target sent DISCONNECT */ 1403 /* target sent DISCONNECT */
1525 DPRINTK(debug_selection, DEBUG_LEAD "target disconnected at %d/%d\n",
1526 CMDINFO(CURRENT_SC),
1527 scsi_get_resid(CURRENT_SC),
1528 scsi_bufflen(CURRENT_SC));
1529#if defined(AHA152X_STAT) 1404#if defined(AHA152X_STAT)
1530 HOSTDATA(shpnt)->disconnections++; 1405 HOSTDATA(shpnt)->disconnections++;
1531#endif 1406#endif
@@ -1553,13 +1428,6 @@ static void busfree_run(struct Scsi_Host *shpnt)
1553 struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC; 1428 struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC;
1554 struct aha152x_scdata *sc = SCDATA(cmd); 1429 struct aha152x_scdata *sc = SCDATA(cmd);
1555 1430
1556#if 0
1557 if(HOSTDATA(shpnt)->debug & debug_eh) {
1558 printk(ERR_LEAD "received sense: ", CMDINFO(DONE_SC));
1559 scsi_print_sense("bh", DONE_SC);
1560 }
1561#endif
1562
1563 scsi_eh_restore_cmnd(cmd, &sc->ses); 1431 scsi_eh_restore_cmnd(cmd, &sc->ses);
1564 1432
1565 cmd->SCp.Status = SAM_STAT_CHECK_CONDITION; 1433 cmd->SCp.Status = SAM_STAT_CHECK_CONDITION;
@@ -1571,17 +1439,11 @@ static void busfree_run(struct Scsi_Host *shpnt)
1571#if defined(AHA152X_STAT) 1439#if defined(AHA152X_STAT)
1572 HOSTDATA(shpnt)->busfree_with_check_condition++; 1440 HOSTDATA(shpnt)->busfree_with_check_condition++;
1573#endif 1441#endif
1574#if 0
1575 DPRINTK(debug_eh, ERR_LEAD "CHECK CONDITION found\n", CMDINFO(DONE_SC));
1576#endif
1577 1442
1578 if(!(DONE_SC->SCp.phase & not_issued)) { 1443 if(!(DONE_SC->SCp.phase & not_issued)) {
1579 struct aha152x_scdata *sc; 1444 struct aha152x_scdata *sc;
1580 Scsi_Cmnd *ptr = DONE_SC; 1445 Scsi_Cmnd *ptr = DONE_SC;
1581 DONE_SC=NULL; 1446 DONE_SC=NULL;
1582#if 0
1583 DPRINTK(debug_eh, ERR_LEAD "requesting sense\n", CMDINFO(ptr));
1584#endif
1585 1447
1586 sc = SCDATA(ptr); 1448 sc = SCDATA(ptr);
1587 /* It was allocated in aha152x_internal_queue? */ 1449 /* It was allocated in aha152x_internal_queue? */
@@ -1591,19 +1453,10 @@ static void busfree_run(struct Scsi_Host *shpnt)
1591 DO_UNLOCK(flags); 1453 DO_UNLOCK(flags);
1592 aha152x_internal_queue(ptr, NULL, check_condition, ptr->scsi_done); 1454 aha152x_internal_queue(ptr, NULL, check_condition, ptr->scsi_done);
1593 DO_LOCK(flags); 1455 DO_LOCK(flags);
1594#if 0
1595 } else {
1596 DPRINTK(debug_eh, ERR_LEAD "command not issued - CHECK CONDITION ignored\n", CMDINFO(DONE_SC));
1597#endif
1598 } 1456 }
1599 } 1457 }
1600 1458
1601 if(DONE_SC && DONE_SC->scsi_done) { 1459 if(DONE_SC && DONE_SC->scsi_done) {
1602#if defined(AHA152X_DEBUG)
1603 int hostno=DONE_SC->device->host->host_no;
1604 int id=DONE_SC->device->id & 0xf;
1605 int lun=((u8)DONE_SC->device->lun) & 0x7;
1606#endif
1607 Scsi_Cmnd *ptr = DONE_SC; 1460 Scsi_Cmnd *ptr = DONE_SC;
1608 DONE_SC=NULL; 1461 DONE_SC=NULL;
1609 1462
@@ -1618,9 +1471,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
1618 } 1471 }
1619 1472
1620 DO_UNLOCK(flags); 1473 DO_UNLOCK(flags);
1621 DPRINTK(debug_done, DEBUG_LEAD "calling scsi_done(%p)\n", hostno, id, lun, ptr); 1474 ptr->scsi_done(ptr);
1622 ptr->scsi_done(ptr);
1623 DPRINTK(debug_done, DEBUG_LEAD "scsi_done(%p) returned\n", hostno, id, lun, ptr);
1624 DO_LOCK(flags); 1475 DO_LOCK(flags);
1625 } 1476 }
1626 1477
@@ -1640,9 +1491,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
1640#if defined(AHA152X_STAT) 1491#if defined(AHA152X_STAT)
1641 action++; 1492 action++;
1642#endif 1493#endif
1643 CURRENT_SC->SCp.phase |= selecting; 1494 CURRENT_SC->SCp.phase |= selecting;
1644
1645 DPRINTK(debug_selection, DEBUG_LEAD "selecting target\n", CMDINFO(CURRENT_SC));
1646 1495
1647 /* clear selection timeout */ 1496 /* clear selection timeout */
1648 SETPORT(SSTAT1, SELTO); 1497 SETPORT(SSTAT1, SELTO);
@@ -1674,18 +1523,19 @@ static void seldo_run(struct Scsi_Host *shpnt)
1674 SETPORT(SSTAT1, CLRBUSFREE); 1523 SETPORT(SSTAT1, CLRBUSFREE);
1675 SETPORT(SSTAT1, CLRPHASECHG); 1524 SETPORT(SSTAT1, CLRPHASECHG);
1676 1525
1677 CURRENT_SC->SCp.phase &= ~(selecting|not_issued); 1526 CURRENT_SC->SCp.phase &= ~(selecting|not_issued);
1678 1527
1679 SETPORT(SCSISEQ, 0); 1528 SETPORT(SCSISEQ, 0);
1680 1529
1681 if (TESTLO(SSTAT0, SELDO)) { 1530 if (TESTLO(SSTAT0, SELDO)) {
1682 printk(ERR_LEAD "aha152x: passing bus free condition\n", CMDINFO(CURRENT_SC)); 1531 scmd_printk(KERN_ERR, CURRENT_SC,
1532 "aha152x: passing bus free condition\n");
1683 done(shpnt, DID_NO_CONNECT << 16); 1533 done(shpnt, DID_NO_CONNECT << 16);
1684 return; 1534 return;
1685 } 1535 }
1686 1536
1687 SETPORT(SSTAT0, CLRSELDO); 1537 SETPORT(SSTAT0, CLRSELDO);
1688 1538
1689 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun)); 1539 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
1690 1540
1691 if (CURRENT_SC->SCp.phase & aborting) { 1541 if (CURRENT_SC->SCp.phase & aborting) {
@@ -1693,7 +1543,7 @@ static void seldo_run(struct Scsi_Host *shpnt)
1693 } else if (CURRENT_SC->SCp.phase & resetting) { 1543 } else if (CURRENT_SC->SCp.phase & resetting) {
1694 ADDMSGO(BUS_DEVICE_RESET); 1544 ADDMSGO(BUS_DEVICE_RESET);
1695 } else if (SYNCNEG==0 && SYNCHRONOUS) { 1545 } else if (SYNCNEG==0 && SYNCHRONOUS) {
1696 CURRENT_SC->SCp.phase |= syncneg; 1546 CURRENT_SC->SCp.phase |= syncneg;
1697 MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8); 1547 MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
1698 SYNCNEG=1; /* negotiation in progress */ 1548 SYNCNEG=1; /* negotiation in progress */
1699 } 1549 }
@@ -1708,29 +1558,21 @@ static void seldo_run(struct Scsi_Host *shpnt)
1708 */ 1558 */
1709static void selto_run(struct Scsi_Host *shpnt) 1559static void selto_run(struct Scsi_Host *shpnt)
1710{ 1560{
1711 SETPORT(SCSISEQ, 0); 1561 SETPORT(SCSISEQ, 0);
1712 SETPORT(SSTAT1, CLRSELTIMO); 1562 SETPORT(SSTAT1, CLRSELTIMO);
1713 1563
1714 DPRINTK(debug_selection, DEBUG_LEAD "selection timeout\n", CMDINFO(CURRENT_SC)); 1564 if (!CURRENT_SC)
1715
1716 if(!CURRENT_SC) {
1717 DPRINTK(debug_selection, DEBUG_LEAD "!CURRENT_SC\n", CMDINFO(CURRENT_SC));
1718 return; 1565 return;
1719 }
1720 1566
1721 CURRENT_SC->SCp.phase &= ~selecting; 1567 CURRENT_SC->SCp.phase &= ~selecting;
1722 1568
1723 if (CURRENT_SC->SCp.phase & aborted) { 1569 if (CURRENT_SC->SCp.phase & aborted)
1724 DPRINTK(debug_selection, DEBUG_LEAD "aborted\n", CMDINFO(CURRENT_SC));
1725 done(shpnt, DID_ABORT << 16); 1570 done(shpnt, DID_ABORT << 16);
1726 } else if (TESTLO(SSTAT0, SELINGO)) { 1571 else if (TESTLO(SSTAT0, SELINGO))
1727 DPRINTK(debug_selection, DEBUG_LEAD "arbitration not won\n", CMDINFO(CURRENT_SC));
1728 done(shpnt, DID_BUS_BUSY << 16); 1572 done(shpnt, DID_BUS_BUSY << 16);
1729 } else { 1573 else
1730 /* ARBITRATION won, but SELECTION failed */ 1574 /* ARBITRATION won, but SELECTION failed */
1731 DPRINTK(debug_selection, DEBUG_LEAD "selection failed\n", CMDINFO(CURRENT_SC));
1732 done(shpnt, DID_NO_CONNECT << 16); 1575 done(shpnt, DID_NO_CONNECT << 16);
1733 }
1734} 1576}
1735 1577
1736/* 1578/*
@@ -1753,9 +1595,8 @@ static void seldi_run(struct Scsi_Host *shpnt)
1753 1595
1754 if(CURRENT_SC) { 1596 if(CURRENT_SC) {
1755 if(!(CURRENT_SC->SCp.phase & not_issued)) 1597 if(!(CURRENT_SC->SCp.phase & not_issued))
1756 printk(ERR_LEAD "command should not have been issued yet\n", CMDINFO(CURRENT_SC)); 1598 scmd_printk(KERN_ERR, CURRENT_SC,
1757 1599 "command should not have been issued yet\n");
1758 DPRINTK(debug_selection, ERR_LEAD "command requeued - reselection\n", CMDINFO(CURRENT_SC));
1759 1600
1760 DO_LOCK(flags); 1601 DO_LOCK(flags);
1761 append_SC(&ISSUE_SC, CURRENT_SC); 1602 append_SC(&ISSUE_SC, CURRENT_SC);
@@ -1764,17 +1605,16 @@ static void seldi_run(struct Scsi_Host *shpnt)
1764 CURRENT_SC = NULL; 1605 CURRENT_SC = NULL;
1765 } 1606 }
1766 1607
1767 if(!DISCONNECTED_SC) { 1608 if (!DISCONNECTED_SC)
1768 DPRINTK(debug_selection, DEBUG_LEAD "unexpected SELDI ", CMDINFO(CURRENT_SC));
1769 return; 1609 return;
1770 }
1771 1610
1772 RECONN_TARGET=-1; 1611 RECONN_TARGET=-1;
1773 1612
1774 selid = GETPORT(SELID) & ~(1 << shpnt->this_id); 1613 selid = GETPORT(SELID) & ~(1 << shpnt->this_id);
1775 1614
1776 if (selid==0) { 1615 if (selid==0) {
1777 printk("aha152x%d: target id unknown (%02x)\n", HOSTNO, selid); 1616 shost_printk(KERN_INFO, shpnt,
1617 "target id unknown (%02x)\n", selid);
1778 return; 1618 return;
1779 } 1619 }
1780 1620
@@ -1782,8 +1622,8 @@ static void seldi_run(struct Scsi_Host *shpnt)
1782 ; 1622 ;
1783 1623
1784 if(selid & ~(1 << target)) { 1624 if(selid & ~(1 << target)) {
1785 printk("aha152x%d: multiple targets reconnected (%02x)\n", 1625 shost_printk(KERN_INFO, shpnt,
1786 HOSTNO, selid); 1626 "multiple targets reconnected (%02x)\n", selid);
1787 } 1627 }
1788 1628
1789 1629
@@ -1793,7 +1633,6 @@ static void seldi_run(struct Scsi_Host *shpnt)
1793 SETRATE(HOSTDATA(shpnt)->syncrate[target]); 1633 SETRATE(HOSTDATA(shpnt)->syncrate[target]);
1794 1634
1795 RECONN_TARGET=target; 1635 RECONN_TARGET=target;
1796 DPRINTK(debug_selection, DEBUG_LEAD "target %d reselected (%02x).\n", CMDINFO(CURRENT_SC), target, selid);
1797} 1636}
1798 1637
1799/* 1638/*
@@ -1817,31 +1656,24 @@ static void msgi_run(struct Scsi_Host *shpnt)
1817 if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT)) 1656 if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT))
1818 return; 1657 return;
1819 1658
1820 if(TESTLO(SSTAT0,SPIORDY)) { 1659 if (TESTLO(SSTAT0, SPIORDY))
1821 DPRINTK(debug_msgi, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
1822 return; 1660 return;
1823 }
1824 1661
1825 ADDMSGI(GETPORT(SCSIDAT)); 1662 ADDMSGI(GETPORT(SCSIDAT));
1826 1663
1827#if defined(AHA152X_DEBUG)
1828 if (HOSTDATA(shpnt)->debug & debug_msgi) {
1829 printk(INFO_LEAD "inbound message %02x ", CMDINFO(CURRENT_SC), MSGI(0));
1830 spi_print_msg(&MSGI(0));
1831 printk("\n");
1832 }
1833#endif
1834
1835 if(!CURRENT_SC) { 1664 if(!CURRENT_SC) {
1836 if(LASTSTATE!=seldi) { 1665 if(LASTSTATE!=seldi) {
1837 printk(KERN_ERR "aha152x%d: message in w/o current command not after reselection\n", HOSTNO); 1666 shost_printk(KERN_ERR, shpnt,
1667 "message in w/o current command"
1668 " not after reselection\n");
1838 } 1669 }
1839 1670
1840 /* 1671 /*
1841 * Handle reselection 1672 * Handle reselection
1842 */ 1673 */
1843 if(!(MSGI(0) & IDENTIFY_BASE)) { 1674 if(!(MSGI(0) & IDENTIFY_BASE)) {
1844 printk(KERN_ERR "aha152x%d: target didn't identify after reselection\n", HOSTNO); 1675 shost_printk(KERN_ERR, shpnt,
1676 "target didn't identify after reselection\n");
1845 continue; 1677 continue;
1846 } 1678 }
1847 1679
@@ -1849,12 +1681,13 @@ static void msgi_run(struct Scsi_Host *shpnt)
1849 1681
1850 if (!CURRENT_SC) { 1682 if (!CURRENT_SC) {
1851 show_queues(shpnt); 1683 show_queues(shpnt);
1852 printk(KERN_ERR "aha152x%d: no disconnected command for target %d/%d\n", HOSTNO, RECONN_TARGET, MSGI(0) & 0x3f); 1684 shost_printk(KERN_ERR, shpnt,
1685 "no disconnected command"
1686 " for target %d/%d\n",
1687 RECONN_TARGET, MSGI(0) & 0x3f);
1853 continue; 1688 continue;
1854 } 1689 }
1855 1690
1856 DPRINTK(debug_msgi, DEBUG_LEAD "target reconnected\n", CMDINFO(CURRENT_SC));
1857
1858 CURRENT_SC->SCp.Message = MSGI(0); 1691 CURRENT_SC->SCp.Message = MSGI(0);
1859 CURRENT_SC->SCp.phase &= ~disconnected; 1692 CURRENT_SC->SCp.phase &= ~disconnected;
1860 1693
@@ -1862,31 +1695,32 @@ static void msgi_run(struct Scsi_Host *shpnt)
1862 1695
1863 /* next message if any */ 1696 /* next message if any */
1864 continue; 1697 continue;
1865 } 1698 }
1866 1699
1867 CURRENT_SC->SCp.Message = MSGI(0); 1700 CURRENT_SC->SCp.Message = MSGI(0);
1868 1701
1869 switch (MSGI(0)) { 1702 switch (MSGI(0)) {
1870 case DISCONNECT: 1703 case DISCONNECT:
1871 if (!RECONNECT) 1704 if (!RECONNECT)
1872 printk(WARN_LEAD "target was not allowed to disconnect\n", CMDINFO(CURRENT_SC)); 1705 scmd_printk(KERN_WARNING, CURRENT_SC,
1706 "target was not allowed to disconnect\n");
1873 1707
1874 CURRENT_SC->SCp.phase |= disconnected; 1708 CURRENT_SC->SCp.phase |= disconnected;
1875 break; 1709 break;
1876 1710
1877 case COMMAND_COMPLETE: 1711 case COMMAND_COMPLETE:
1878 if(CURRENT_SC->SCp.phase & completed)
1879 DPRINTK(debug_msgi, DEBUG_LEAD "again COMMAND COMPLETE\n", CMDINFO(CURRENT_SC));
1880
1881 CURRENT_SC->SCp.phase |= completed; 1712 CURRENT_SC->SCp.phase |= completed;
1882 break; 1713 break;
1883 1714
1884 case MESSAGE_REJECT: 1715 case MESSAGE_REJECT:
1885 if (SYNCNEG==1) { 1716 if (SYNCNEG==1) {
1886 printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC)); 1717 scmd_printk(KERN_INFO, CURRENT_SC,
1718 "Synchronous Data Transfer Request"
1719 " was rejected\n");
1887 SYNCNEG=2; /* negotiation completed */ 1720 SYNCNEG=2; /* negotiation completed */
1888 } else 1721 } else
1889 printk(INFO_LEAD "inbound message (MESSAGE REJECT)\n", CMDINFO(CURRENT_SC)); 1722 scmd_printk(KERN_INFO, CURRENT_SC,
1723 "inbound message (MESSAGE REJECT)\n");
1890 break; 1724 break;
1891 1725
1892 case SAVE_POINTERS: 1726 case SAVE_POINTERS:
@@ -1907,7 +1741,8 @@ static void msgi_run(struct Scsi_Host *shpnt)
1907 long ticks; 1741 long ticks;
1908 1742
1909 if (MSGI(1) != 3) { 1743 if (MSGI(1) != 3) {
1910 printk(ERR_LEAD "SDTR message length!=3\n", CMDINFO(CURRENT_SC)); 1744 scmd_printk(KERN_ERR, CURRENT_SC,
1745 "SDTR message length!=3\n");
1911 break; 1746 break;
1912 } 1747 }
1913 1748
@@ -1924,10 +1759,12 @@ static void msgi_run(struct Scsi_Host *shpnt)
1924 /* negotiation in progress */ 1759 /* negotiation in progress */
1925 if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) { 1760 if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) {
1926 ADDMSGO(MESSAGE_REJECT); 1761 ADDMSGO(MESSAGE_REJECT);
1927 printk(INFO_LEAD "received Synchronous Data Transfer Request invalid - rejected\n", CMDINFO(CURRENT_SC)); 1762 scmd_printk(KERN_INFO,
1763 CURRENT_SC,
1764 "received Synchronous Data Transfer Request invalid - rejected\n");
1928 break; 1765 break;
1929 } 1766 }
1930 1767
1931 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4); 1768 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1932 } else if (ticks <= 9 && MSGI(4) >= 1) { 1769 } else if (ticks <= 9 && MSGI(4) >= 1) {
1933 ADDMSGO(EXTENDED_MESSAGE); 1770 ADDMSGO(EXTENDED_MESSAGE);
@@ -1947,11 +1784,14 @@ static void msgi_run(struct Scsi_Host *shpnt)
1947 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4); 1784 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1948 } else { 1785 } else {
1949 /* requested SDTR is too slow, do it asynchronously */ 1786 /* requested SDTR is too slow, do it asynchronously */
1950 printk(INFO_LEAD "Synchronous Data Transfer Request too slow - Rejecting\n", CMDINFO(CURRENT_SC)); 1787 scmd_printk(KERN_INFO,
1788 CURRENT_SC,
1789 "Synchronous Data Transfer Request too slow - Rejecting\n");
1951 ADDMSGO(MESSAGE_REJECT); 1790 ADDMSGO(MESSAGE_REJECT);
1952 } 1791 }
1953 1792
1954 SYNCNEG=2; /* negotiation completed */ 1793 /* negotiation completed */
1794 SYNCNEG=2;
1955 SETRATE(SYNCRATE); 1795 SETRATE(SYNCRATE);
1956 } 1796 }
1957 break; 1797 break;
@@ -1985,12 +1825,12 @@ static void msgi_run(struct Scsi_Host *shpnt)
1985static void msgi_end(struct Scsi_Host *shpnt) 1825static void msgi_end(struct Scsi_Host *shpnt)
1986{ 1826{
1987 if(MSGILEN>0) 1827 if(MSGILEN>0)
1988 printk(WARN_LEAD "target left before message completed (%d)\n", CMDINFO(CURRENT_SC), MSGILEN); 1828 scmd_printk(KERN_WARNING, CURRENT_SC,
1829 "target left before message completed (%d)\n",
1830 MSGILEN);
1989 1831
1990 if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE)) { 1832 if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE))
1991 DPRINTK(debug_msgi, DEBUG_LEAD "msgo pending\n", CMDINFO(CURRENT_SC));
1992 SETPORT(SCSISIG, P_MSGI | SIG_ATNO); 1833 SETPORT(SCSISIG, P_MSGI | SIG_ATNO);
1993 }
1994} 1834}
1995 1835
1996/* 1836/*
@@ -2003,21 +1843,12 @@ static void msgo_init(struct Scsi_Host *shpnt)
2003 if((CURRENT_SC->SCp.phase & syncneg) && SYNCNEG==2 && SYNCRATE==0) { 1843 if((CURRENT_SC->SCp.phase & syncneg) && SYNCNEG==2 && SYNCRATE==0) {
2004 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun)); 1844 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
2005 } else { 1845 } else {
2006 printk(INFO_LEAD "unexpected MESSAGE OUT phase; rejecting\n", CMDINFO(CURRENT_SC)); 1846 scmd_printk(KERN_INFO, CURRENT_SC,
1847 "unexpected MESSAGE OUT phase; rejecting\n");
2007 ADDMSGO(MESSAGE_REJECT); 1848 ADDMSGO(MESSAGE_REJECT);
2008 } 1849 }
2009 } 1850 }
2010 1851
2011#if defined(AHA152X_DEBUG)
2012 if(HOSTDATA(shpnt)->debug & debug_msgo) {
2013 int i;
2014
2015 printk(DEBUG_LEAD "messages( ", CMDINFO(CURRENT_SC));
2016 for (i=0; i<MSGOLEN; i+=spi_print_msg(&MSGO(i)), printk(" "))
2017 ;
2018 printk(")\n");
2019 }
2020#endif
2021} 1852}
2022 1853
2023/* 1854/*
@@ -2026,16 +1857,9 @@ static void msgo_init(struct Scsi_Host *shpnt)
2026 */ 1857 */
2027static void msgo_run(struct Scsi_Host *shpnt) 1858static void msgo_run(struct Scsi_Host *shpnt)
2028{ 1859{
2029 if(MSGO_I==MSGOLEN)
2030 DPRINTK(debug_msgo, DEBUG_LEAD "messages all sent (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN);
2031
2032 while(MSGO_I<MSGOLEN) { 1860 while(MSGO_I<MSGOLEN) {
2033 DPRINTK(debug_msgo, DEBUG_LEAD "message byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO(MSGO_I), MSGO_I, MSGOLEN); 1861 if (TESTLO(SSTAT0, SPIORDY))
2034
2035 if(TESTLO(SSTAT0, SPIORDY)) {
2036 DPRINTK(debug_msgo, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2037 return; 1862 return;
2038 }
2039 1863
2040 if (MSGO_I==MSGOLEN-1) { 1864 if (MSGO_I==MSGOLEN-1) {
2041 /* Leave MESSAGE OUT after transfer */ 1865 /* Leave MESSAGE OUT after transfer */
@@ -2059,36 +1883,33 @@ static void msgo_run(struct Scsi_Host *shpnt)
2059static void msgo_end(struct Scsi_Host *shpnt) 1883static void msgo_end(struct Scsi_Host *shpnt)
2060{ 1884{
2061 if(MSGO_I<MSGOLEN) { 1885 if(MSGO_I<MSGOLEN) {
2062 printk(ERR_LEAD "message sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN); 1886 scmd_printk(KERN_ERR, CURRENT_SC,
1887 "message sent incompletely (%d/%d)\n",
1888 MSGO_I, MSGOLEN);
2063 if(SYNCNEG==1) { 1889 if(SYNCNEG==1) {
2064 printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC)); 1890 scmd_printk(KERN_INFO, CURRENT_SC,
1891 "Synchronous Data Transfer Request was rejected\n");
2065 SYNCNEG=2; 1892 SYNCNEG=2;
2066 } 1893 }
2067 } 1894 }
2068 1895
2069 MSGO_I = 0; 1896 MSGO_I = 0;
2070 MSGOLEN = 0; 1897 MSGOLEN = 0;
2071} 1898}
2072 1899
2073/* 1900/*
2074 * command phase 1901 * command phase
2075 * 1902 *
2076 */ 1903 */
2077static void cmd_init(struct Scsi_Host *shpnt) 1904static void cmd_init(struct Scsi_Host *shpnt)
2078{ 1905{
2079 if (CURRENT_SC->SCp.sent_command) { 1906 if (CURRENT_SC->SCp.sent_command) {
2080 printk(ERR_LEAD "command already sent\n", CMDINFO(CURRENT_SC)); 1907 scmd_printk(KERN_ERR, CURRENT_SC,
1908 "command already sent\n");
2081 done(shpnt, DID_ERROR << 16); 1909 done(shpnt, DID_ERROR << 16);
2082 return; 1910 return;
2083 } 1911 }
2084 1912
2085#if defined(AHA152X_DEBUG)
2086 if (HOSTDATA(shpnt)->debug & debug_cmd) {
2087 printk(DEBUG_LEAD "cmd_init: ", CMDINFO(CURRENT_SC));
2088 __scsi_print_command(CURRENT_SC->cmnd);
2089 }
2090#endif
2091
2092 CMD_I=0; 1913 CMD_I=0;
2093} 1914}
2094 1915
@@ -2098,18 +1919,9 @@ static void cmd_init(struct Scsi_Host *shpnt)
2098 */ 1919 */
2099static void cmd_run(struct Scsi_Host *shpnt) 1920static void cmd_run(struct Scsi_Host *shpnt)
2100{ 1921{
2101 if(CMD_I==CURRENT_SC->cmd_len) {
2102 DPRINTK(debug_cmd, DEBUG_LEAD "command already completely sent (%d/%d)", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len);
2103 disp_ports(shpnt);
2104 }
2105
2106 while(CMD_I<CURRENT_SC->cmd_len) { 1922 while(CMD_I<CURRENT_SC->cmd_len) {
2107 DPRINTK(debug_cmd, DEBUG_LEAD "command byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), CURRENT_SC->cmnd[CMD_I], CMD_I, CURRENT_SC->cmd_len); 1923 if (TESTLO(SSTAT0, SPIORDY))
2108
2109 if(TESTLO(SSTAT0, SPIORDY)) {
2110 DPRINTK(debug_cmd, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2111 return; 1924 return;
2112 }
2113 1925
2114 SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]); 1926 SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]);
2115 } 1927 }
@@ -2118,7 +1930,9 @@ static void cmd_run(struct Scsi_Host *shpnt)
2118static void cmd_end(struct Scsi_Host *shpnt) 1930static void cmd_end(struct Scsi_Host *shpnt)
2119{ 1931{
2120 if(CMD_I<CURRENT_SC->cmd_len) 1932 if(CMD_I<CURRENT_SC->cmd_len)
2121 printk(ERR_LEAD "command sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len); 1933 scmd_printk(KERN_ERR, CURRENT_SC,
1934 "command sent incompletely (%d/%d)\n",
1935 CMD_I, CURRENT_SC->cmd_len);
2122 else 1936 else
2123 CURRENT_SC->SCp.sent_command++; 1937 CURRENT_SC->SCp.sent_command++;
2124} 1938}
@@ -2129,20 +1943,11 @@ static void cmd_end(struct Scsi_Host *shpnt)
2129 */ 1943 */
2130static void status_run(struct Scsi_Host *shpnt) 1944static void status_run(struct Scsi_Host *shpnt)
2131{ 1945{
2132 if(TESTLO(SSTAT0,SPIORDY)) { 1946 if (TESTLO(SSTAT0, SPIORDY))
2133 DPRINTK(debug_status, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2134 return; 1947 return;
2135 }
2136 1948
2137 CURRENT_SC->SCp.Status = GETPORT(SCSIDAT); 1949 CURRENT_SC->SCp.Status = GETPORT(SCSIDAT);
2138 1950
2139#if defined(AHA152X_DEBUG)
2140 if (HOSTDATA(shpnt)->debug & debug_status) {
2141 printk(DEBUG_LEAD "inbound status %02x ", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.Status);
2142 scsi_print_status(CURRENT_SC->SCp.Status);
2143 printk("\n");
2144 }
2145#endif
2146} 1951}
2147 1952
2148/* 1953/*
@@ -2161,10 +1966,6 @@ static void datai_init(struct Scsi_Host *shpnt)
2161 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE); 1966 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE);
2162 1967
2163 DATA_LEN=0; 1968 DATA_LEN=0;
2164 DPRINTK(debug_datai,
2165 DEBUG_LEAD "datai_init: request_bufflen=%d resid=%d\n",
2166 CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
2167 scsi_get_resid(CURRENT_SC));
2168} 1969}
2169 1970
2170static void datai_run(struct Scsi_Host *shpnt) 1971static void datai_run(struct Scsi_Host *shpnt)
@@ -2186,8 +1987,7 @@ static void datai_run(struct Scsi_Host *shpnt)
2186 barrier(); 1987 barrier();
2187 1988
2188 if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) { 1989 if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) {
2189 printk(ERR_LEAD "datai timeout", CMDINFO(CURRENT_SC)); 1990 scmd_printk(KERN_ERR, CURRENT_SC, "datai timeout\n");
2190 disp_ports(shpnt);
2191 break; 1991 break;
2192 } 1992 }
2193 1993
@@ -2199,8 +1999,8 @@ static void datai_run(struct Scsi_Host *shpnt)
2199 barrier(); 1999 barrier();
2200 2000
2201 if(TESTLO(SSTAT2, SEMPTY)) { 2001 if(TESTLO(SSTAT2, SEMPTY)) {
2202 printk(ERR_LEAD "datai sempty timeout", CMDINFO(CURRENT_SC)); 2002 scmd_printk(KERN_ERR, CURRENT_SC,
2203 disp_ports(shpnt); 2003 "datai sempty timeout");
2204 break; 2004 break;
2205 } 2005 }
2206 2006
@@ -2209,48 +2009,49 @@ static void datai_run(struct Scsi_Host *shpnt)
2209 2009
2210 if(CURRENT_SC->SCp.this_residual>0) { 2010 if(CURRENT_SC->SCp.this_residual>0) {
2211 while(fifodata>0 && CURRENT_SC->SCp.this_residual>0) { 2011 while(fifodata>0 && CURRENT_SC->SCp.this_residual>0) {
2212 data_count = fifodata>CURRENT_SC->SCp.this_residual ? 2012 data_count = fifodata > CURRENT_SC->SCp.this_residual ?
2213 CURRENT_SC->SCp.this_residual : 2013 CURRENT_SC->SCp.this_residual :
2214 fifodata; 2014 fifodata;
2215 fifodata -= data_count; 2015 fifodata -= data_count;
2216 2016
2217 if(data_count & 1) { 2017 if (data_count & 1) {
2218 DPRINTK(debug_datai, DEBUG_LEAD "8bit\n", CMDINFO(CURRENT_SC)); 2018 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2219 SETPORT(DMACNTRL0, ENDMA|_8BIT); 2019 *CURRENT_SC->SCp.ptr++ = GETPORT(DATAPORT);
2220 *CURRENT_SC->SCp.ptr++ = GETPORT(DATAPORT); 2020 CURRENT_SC->SCp.this_residual--;
2221 CURRENT_SC->SCp.this_residual--; 2021 DATA_LEN++;
2222 DATA_LEN++; 2022 SETPORT(DMACNTRL0, ENDMA);
2223 SETPORT(DMACNTRL0, ENDMA); 2023 }
2224 } 2024
2225 2025 if (data_count > 1) {
2226 if(data_count > 1) { 2026 data_count >>= 1;
2227 DPRINTK(debug_datai, DEBUG_LEAD "16bit(%d)\n", CMDINFO(CURRENT_SC), data_count); 2027 insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2228 data_count >>= 1; 2028 CURRENT_SC->SCp.ptr += 2 * data_count;
2229 insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count); 2029 CURRENT_SC->SCp.this_residual -= 2 * data_count;
2230 CURRENT_SC->SCp.ptr += 2 * data_count; 2030 DATA_LEN += 2 * data_count;
2231 CURRENT_SC->SCp.this_residual -= 2 * data_count; 2031 }
2232 DATA_LEN += 2 * data_count; 2032
2233 } 2033 if (CURRENT_SC->SCp.this_residual == 0 &&
2234 2034 CURRENT_SC->SCp.buffers_residual > 0) {
2235 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) { 2035 /* advance to next buffer */
2236 /* advance to next buffer */ 2036 CURRENT_SC->SCp.buffers_residual--;
2237 CURRENT_SC->SCp.buffers_residual--; 2037 CURRENT_SC->SCp.buffer++;
2238 CURRENT_SC->SCp.buffer++; 2038 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
2239 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer); 2039 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2240 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length; 2040 }
2241 } 2041 }
2242 } 2042 } else if (fifodata > 0) {
2243 } else if(fifodata>0) { 2043 scmd_printk(KERN_ERR, CURRENT_SC,
2244 printk(ERR_LEAD "no buffers left for %d(%d) bytes (data overrun!?)\n", CMDINFO(CURRENT_SC), fifodata, GETPORT(FIFOSTAT)); 2044 "no buffers left for %d(%d) bytes"
2245 SETPORT(DMACNTRL0, ENDMA|_8BIT); 2045 " (data overrun!?)\n",
2046 fifodata, GETPORT(FIFOSTAT));
2047 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2246 while(fifodata>0) { 2048 while(fifodata>0) {
2247 int data; 2049 int data;
2248 data=GETPORT(DATAPORT); 2050 data=GETPORT(DATAPORT);
2249 DPRINTK(debug_datai, DEBUG_LEAD "data=%02x\n", CMDINFO(CURRENT_SC), data);
2250 fifodata--; 2051 fifodata--;
2251 DATA_LEN++; 2052 DATA_LEN++;
2252 } 2053 }
2253 SETPORT(DMACNTRL0, ENDMA|_8BIT); 2054 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2254 } 2055 }
2255 } 2056 }
2256 2057
@@ -2258,19 +2059,20 @@ static void datai_run(struct Scsi_Host *shpnt)
2258 TESTLO(DMASTAT, DFIFOEMP) || 2059 TESTLO(DMASTAT, DFIFOEMP) ||
2259 TESTLO(SSTAT2, SEMPTY) || 2060 TESTLO(SSTAT2, SEMPTY) ||
2260 GETPORT(FIFOSTAT)>0) { 2061 GETPORT(FIFOSTAT)>0) {
2261 /* 2062 /*
2262 * something went wrong, if there's something left in the fifos 2063 * something went wrong, if there's something left in the fifos
2263 * or the phase didn't change 2064 * or the phase didn't change
2264 */ 2065 */
2265 printk(ERR_LEAD "fifos should be empty and phase should have changed\n", CMDINFO(CURRENT_SC)); 2066 scmd_printk(KERN_ERR, CURRENT_SC,
2266 disp_ports(shpnt); 2067 "fifos should be empty and phase should have changed\n");
2267 } 2068 }
2268 2069
2269 if(DATA_LEN!=GETSTCNT()) { 2070 if(DATA_LEN!=GETSTCNT()) {
2270 printk(ERR_LEAD 2071 scmd_printk(KERN_ERR, CURRENT_SC,
2271 "manual transfer count differs from automatic (count=%d;stcnt=%d;diff=%d;fifostat=%d)", 2072 "manual transfer count differs from automatic "
2272 CMDINFO(CURRENT_SC), DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN, GETPORT(FIFOSTAT)); 2073 "(count=%d;stcnt=%d;diff=%d;fifostat=%d)",
2273 disp_ports(shpnt); 2074 DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN,
2075 GETPORT(FIFOSTAT));
2274 mdelay(10000); 2076 mdelay(10000);
2275 } 2077 }
2276} 2078}
@@ -2279,11 +2081,6 @@ static void datai_end(struct Scsi_Host *shpnt)
2279{ 2081{
2280 CMD_INC_RESID(CURRENT_SC, -GETSTCNT()); 2082 CMD_INC_RESID(CURRENT_SC, -GETSTCNT());
2281 2083
2282 DPRINTK(debug_datai,
2283 DEBUG_LEAD "datai_end: request_bufflen=%d resid=%d stcnt=%d\n",
2284 CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
2285 scsi_get_resid(CURRENT_SC), GETSTCNT());
2286
2287 SETPORT(SXFRCTL0, CH1|CLRSTCNT); 2084 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2288 SETPORT(DMACNTRL0, 0); 2085 SETPORT(DMACNTRL0, 0);
2289} 2086}
@@ -2304,11 +2101,6 @@ static void datao_init(struct Scsi_Host *shpnt)
2304 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE ); 2101 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE );
2305 2102
2306 DATA_LEN = scsi_get_resid(CURRENT_SC); 2103 DATA_LEN = scsi_get_resid(CURRENT_SC);
2307
2308 DPRINTK(debug_datao,
2309 DEBUG_LEAD "datao_init: request_bufflen=%d; resid=%d\n",
2310 CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
2311 scsi_get_resid(CURRENT_SC));
2312} 2104}
2313 2105
2314static void datao_run(struct Scsi_Host *shpnt) 2106static void datao_run(struct Scsi_Host *shpnt)
@@ -2323,8 +2115,9 @@ static void datao_run(struct Scsi_Host *shpnt)
2323 data_count=CURRENT_SC->SCp.this_residual; 2115 data_count=CURRENT_SC->SCp.this_residual;
2324 2116
2325 if(TESTLO(DMASTAT, DFIFOEMP)) { 2117 if(TESTLO(DMASTAT, DFIFOEMP)) {
2326 printk(ERR_LEAD "datao fifo not empty (%d)", CMDINFO(CURRENT_SC), GETPORT(FIFOSTAT)); 2118 scmd_printk(KERN_ERR, CURRENT_SC,
2327 disp_ports(shpnt); 2119 "datao fifo not empty (%d)",
2120 GETPORT(FIFOSTAT));
2328 break; 2121 break;
2329 } 2122 }
2330 2123
@@ -2342,7 +2135,7 @@ static void datao_run(struct Scsi_Host *shpnt)
2342 CURRENT_SC->SCp.ptr += 2 * data_count; 2135 CURRENT_SC->SCp.ptr += 2 * data_count;
2343 CURRENT_SC->SCp.this_residual -= 2 * data_count; 2136 CURRENT_SC->SCp.this_residual -= 2 * data_count;
2344 CMD_INC_RESID(CURRENT_SC, -2 * data_count); 2137 CMD_INC_RESID(CURRENT_SC, -2 * data_count);
2345 } 2138 }
2346 2139
2347 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) { 2140 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
2348 /* advance to next buffer */ 2141 /* advance to next buffer */
@@ -2357,8 +2150,7 @@ static void datao_run(struct Scsi_Host *shpnt)
2357 barrier(); 2150 barrier();
2358 2151
2359 if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) { 2152 if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) {
2360 printk(ERR_LEAD "dataout timeout", CMDINFO(CURRENT_SC)); 2153 scmd_printk(KERN_ERR, CURRENT_SC, "dataout timeout\n");
2361 disp_ports(shpnt);
2362 break; 2154 break;
2363 } 2155 }
2364 } 2156 }
@@ -2368,35 +2160,23 @@ static void datao_end(struct Scsi_Host *shpnt)
2368{ 2160{
2369 if(TESTLO(DMASTAT, DFIFOEMP)) { 2161 if(TESTLO(DMASTAT, DFIFOEMP)) {
2370 int data_count = (DATA_LEN - scsi_get_resid(CURRENT_SC)) - 2162 int data_count = (DATA_LEN - scsi_get_resid(CURRENT_SC)) -
2371 GETSTCNT(); 2163 GETSTCNT();
2372
2373 DPRINTK(debug_datao, DEBUG_LEAD "datao: %d bytes to resend (%d written, %d transferred)\n",
2374 CMDINFO(CURRENT_SC),
2375 data_count,
2376 DATA_LEN - scsi_get_resid(CURRENT_SC),
2377 GETSTCNT());
2378 2164
2379 CMD_INC_RESID(CURRENT_SC, data_count); 2165 CMD_INC_RESID(CURRENT_SC, data_count);
2380 2166
2381 data_count -= CURRENT_SC->SCp.ptr - 2167 data_count -= CURRENT_SC->SCp.ptr -
2382 SG_ADDRESS(CURRENT_SC->SCp.buffer); 2168 SG_ADDRESS(CURRENT_SC->SCp.buffer);
2383 while(data_count>0) { 2169 while(data_count>0) {
2384 CURRENT_SC->SCp.buffer--; 2170 CURRENT_SC->SCp.buffer--;
2385 CURRENT_SC->SCp.buffers_residual++; 2171 CURRENT_SC->SCp.buffers_residual++;
2386 data_count -= CURRENT_SC->SCp.buffer->length; 2172 data_count -= CURRENT_SC->SCp.buffer->length;
2387 } 2173 }
2388 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) - 2174 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) -
2389 data_count; 2175 data_count;
2390 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length + 2176 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length +
2391 data_count; 2177 data_count;
2392 } 2178 }
2393 2179
2394 DPRINTK(debug_datao, DEBUG_LEAD "datao_end: request_bufflen=%d; resid=%d; stcnt=%d\n",
2395 CMDINFO(CURRENT_SC),
2396 scsi_bufflen(CURRENT_SC),
2397 scsi_get_resid(CURRENT_SC),
2398 GETSTCNT());
2399
2400 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT); 2180 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
2401 SETPORT(SXFRCTL0, CH1); 2181 SETPORT(SXFRCTL0, CH1);
2402 2182
@@ -2420,7 +2200,7 @@ static int update_state(struct Scsi_Host *shpnt)
2420 STATE=rsti; 2200 STATE=rsti;
2421 SETPORT(SCSISEQ,0); 2201 SETPORT(SCSISEQ,0);
2422 SETPORT(SSTAT1,SCSIRSTI); 2202 SETPORT(SSTAT1,SCSIRSTI);
2423 } else if(stat0 & SELDI && PREVSTATE==busfree) { 2203 } else if (stat0 & SELDI && PREVSTATE == busfree) {
2424 STATE=seldi; 2204 STATE=seldi;
2425 } else if(stat0 & SELDO && CURRENT_SC && (CURRENT_SC->SCp.phase & selecting)) { 2205 } else if(stat0 & SELDO && CURRENT_SC && (CURRENT_SC->SCp.phase & selecting)) {
2426 STATE=seldo; 2206 STATE=seldo;
@@ -2445,8 +2225,7 @@ static int update_state(struct Scsi_Host *shpnt)
2445 } 2225 }
2446 2226
2447 if((stat0 & SELDI) && STATE!=seldi && !dataphase) { 2227 if((stat0 & SELDI) && STATE!=seldi && !dataphase) {
2448 printk(INFO_LEAD "reselection missed?", CMDINFO(CURRENT_SC)); 2228 scmd_printk(KERN_INFO, CURRENT_SC, "reselection missed?");
2449 disp_ports(shpnt);
2450 } 2229 }
2451 2230
2452 if(STATE!=PREVSTATE) { 2231 if(STATE!=PREVSTATE) {
@@ -2464,7 +2243,7 @@ static int update_state(struct Scsi_Host *shpnt)
2464 */ 2243 */
2465static void parerr_run(struct Scsi_Host *shpnt) 2244static void parerr_run(struct Scsi_Host *shpnt)
2466{ 2245{
2467 printk(ERR_LEAD "parity error\n", CMDINFO(CURRENT_SC)); 2246 scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n");
2468 done(shpnt, DID_PARITY << 16); 2247 done(shpnt, DID_PARITY << 16);
2469} 2248}
2470 2249
@@ -2476,8 +2255,8 @@ static void rsti_run(struct Scsi_Host *shpnt)
2476{ 2255{
2477 Scsi_Cmnd *ptr; 2256 Scsi_Cmnd *ptr;
2478 2257
2479 printk(KERN_NOTICE "aha152x%d: scsi reset in\n", HOSTNO); 2258 shost_printk(KERN_NOTICE, shpnt, "scsi reset in\n");
2480 2259
2481 ptr=DISCONNECTED_SC; 2260 ptr=DISCONNECTED_SC;
2482 while(ptr) { 2261 while(ptr) {
2483 Scsi_Cmnd *next = SCNEXT(ptr); 2262 Scsi_Cmnd *next = SCNEXT(ptr);
@@ -2539,8 +2318,6 @@ static void is_complete(struct Scsi_Host *shpnt)
2539 2318
2540 dataphase=update_state(shpnt); 2319 dataphase=update_state(shpnt);
2541 2320
2542 DPRINTK(debug_phases, LEAD "start %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
2543
2544 /* 2321 /*
2545 * end previous state 2322 * end previous state
2546 * 2323 *
@@ -2567,9 +2344,9 @@ static void is_complete(struct Scsi_Host *shpnt)
2567 if(dataphase) { 2344 if(dataphase) {
2568 SETPORT(SSTAT0, REQINIT); 2345 SETPORT(SSTAT0, REQINIT);
2569 SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK); 2346 SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK);
2570 SETPORT(SSTAT1, PHASECHG); 2347 SETPORT(SSTAT1, PHASECHG);
2571 } 2348 }
2572 2349
2573 /* 2350 /*
2574 * enable SPIO mode if previous didn't use it 2351 * enable SPIO mode if previous didn't use it
2575 * and this one does 2352 * and this one does
@@ -2581,14 +2358,14 @@ static void is_complete(struct Scsi_Host *shpnt)
2581 if(CURRENT_SC) 2358 if(CURRENT_SC)
2582 CURRENT_SC->SCp.phase |= spiordy; 2359 CURRENT_SC->SCp.phase |= spiordy;
2583 } 2360 }
2584 2361
2585 /* 2362 /*
2586 * initialize for new state 2363 * initialize for new state
2587 * 2364 *
2588 */ 2365 */
2589 if(PREVSTATE!=STATE && states[STATE].init) 2366 if(PREVSTATE!=STATE && states[STATE].init)
2590 states[STATE].init(shpnt); 2367 states[STATE].init(shpnt);
2591 2368
2592 /* 2369 /*
2593 * handle current state 2370 * handle current state
2594 * 2371 *
@@ -2596,8 +2373,9 @@ static void is_complete(struct Scsi_Host *shpnt)
2596 if(states[STATE].run) 2373 if(states[STATE].run)
2597 states[STATE].run(shpnt); 2374 states[STATE].run(shpnt);
2598 else 2375 else
2599 printk(ERR_LEAD "unexpected state (%x)\n", CMDINFO(CURRENT_SC), STATE); 2376 scmd_printk(KERN_ERR, CURRENT_SC,
2600 2377 "unexpected state (%x)\n", STATE);
2378
2601 /* 2379 /*
2602 * setup controller to interrupt on 2380 * setup controller to interrupt on
2603 * the next expected condition and 2381 * the next expected condition and
@@ -2613,7 +2391,6 @@ static void is_complete(struct Scsi_Host *shpnt)
2613 HOSTDATA(shpnt)->time[STATE] += jiffies-start; 2391 HOSTDATA(shpnt)->time[STATE] += jiffies-start;
2614#endif 2392#endif
2615 2393
2616 DPRINTK(debug_phases, LEAD "end %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
2617 } while(pending); 2394 } while(pending);
2618 2395
2619 /* 2396 /*
@@ -2626,289 +2403,42 @@ static void is_complete(struct Scsi_Host *shpnt)
2626} 2403}
2627 2404
2628 2405
2629/* 2406/*
2630 * Dump the current driver status and panic 2407 * Dump the current driver status and panic
2631 */ 2408 */
2632static void aha152x_error(struct Scsi_Host *shpnt, char *msg) 2409static void aha152x_error(struct Scsi_Host *shpnt, char *msg)
2633{ 2410{
2634 printk(KERN_EMERG "\naha152x%d: %s\n", HOSTNO, msg); 2411 shost_printk(KERN_EMERG, shpnt, "%s\n", msg);
2635 show_queues(shpnt); 2412 show_queues(shpnt);
2636 panic("aha152x panic\n"); 2413 panic("aha152x panic\n");
2637} 2414}
2638 2415
2639/* 2416/*
2640 * Display registers of AIC-6260
2641 */
2642static void disp_ports(struct Scsi_Host *shpnt)
2643{
2644#if defined(AHA152X_DEBUG)
2645 int s;
2646
2647 printk("\n%s: %s(%s) ",
2648 CURRENT_SC ? "busy" : "waiting",
2649 states[STATE].name,
2650 states[PREVSTATE].name);
2651
2652 s = GETPORT(SCSISEQ);
2653 printk("SCSISEQ( ");
2654 if (s & TEMODEO)
2655 printk("TARGET MODE ");
2656 if (s & ENSELO)
2657 printk("SELO ");
2658 if (s & ENSELI)
2659 printk("SELI ");
2660 if (s & ENRESELI)
2661 printk("RESELI ");
2662 if (s & ENAUTOATNO)
2663 printk("AUTOATNO ");
2664 if (s & ENAUTOATNI)
2665 printk("AUTOATNI ");
2666 if (s & ENAUTOATNP)
2667 printk("AUTOATNP ");
2668 if (s & SCSIRSTO)
2669 printk("SCSIRSTO ");
2670 printk(");");
2671
2672 printk(" SCSISIG(");
2673 s = GETPORT(SCSISIG);
2674 switch (s & P_MASK) {
2675 case P_DATAO:
2676 printk("DATA OUT");
2677 break;
2678 case P_DATAI:
2679 printk("DATA IN");
2680 break;
2681 case P_CMD:
2682 printk("COMMAND");
2683 break;
2684 case P_STATUS:
2685 printk("STATUS");
2686 break;
2687 case P_MSGO:
2688 printk("MESSAGE OUT");
2689 break;
2690 case P_MSGI:
2691 printk("MESSAGE IN");
2692 break;
2693 default:
2694 printk("*invalid*");
2695 break;
2696 }
2697
2698 printk("); ");
2699
2700 printk("INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
2701
2702 printk("SSTAT( ");
2703 s = GETPORT(SSTAT0);
2704 if (s & TARGET)
2705 printk("TARGET ");
2706 if (s & SELDO)
2707 printk("SELDO ");
2708 if (s & SELDI)
2709 printk("SELDI ");
2710 if (s & SELINGO)
2711 printk("SELINGO ");
2712 if (s & SWRAP)
2713 printk("SWRAP ");
2714 if (s & SDONE)
2715 printk("SDONE ");
2716 if (s & SPIORDY)
2717 printk("SPIORDY ");
2718 if (s & DMADONE)
2719 printk("DMADONE ");
2720
2721 s = GETPORT(SSTAT1);
2722 if (s & SELTO)
2723 printk("SELTO ");
2724 if (s & ATNTARG)
2725 printk("ATNTARG ");
2726 if (s & SCSIRSTI)
2727 printk("SCSIRSTI ");
2728 if (s & PHASEMIS)
2729 printk("PHASEMIS ");
2730 if (s & BUSFREE)
2731 printk("BUSFREE ");
2732 if (s & SCSIPERR)
2733 printk("SCSIPERR ");
2734 if (s & PHASECHG)
2735 printk("PHASECHG ");
2736 if (s & REQINIT)
2737 printk("REQINIT ");
2738 printk("); ");
2739
2740
2741 printk("SSTAT( ");
2742
2743 s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
2744
2745 if (s & TARGET)
2746 printk("TARGET ");
2747 if (s & SELDO)
2748 printk("SELDO ");
2749 if (s & SELDI)
2750 printk("SELDI ");
2751 if (s & SELINGO)
2752 printk("SELINGO ");
2753 if (s & SWRAP)
2754 printk("SWRAP ");
2755 if (s & SDONE)
2756 printk("SDONE ");
2757 if (s & SPIORDY)
2758 printk("SPIORDY ");
2759 if (s & DMADONE)
2760 printk("DMADONE ");
2761
2762 s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
2763
2764 if (s & SELTO)
2765 printk("SELTO ");
2766 if (s & ATNTARG)
2767 printk("ATNTARG ");
2768 if (s & SCSIRSTI)
2769 printk("SCSIRSTI ");
2770 if (s & PHASEMIS)
2771 printk("PHASEMIS ");
2772 if (s & BUSFREE)
2773 printk("BUSFREE ");
2774 if (s & SCSIPERR)
2775 printk("SCSIPERR ");
2776 if (s & PHASECHG)
2777 printk("PHASECHG ");
2778 if (s & REQINIT)
2779 printk("REQINIT ");
2780 printk("); ");
2781
2782 printk("SXFRCTL0( ");
2783
2784 s = GETPORT(SXFRCTL0);
2785 if (s & SCSIEN)
2786 printk("SCSIEN ");
2787 if (s & DMAEN)
2788 printk("DMAEN ");
2789 if (s & CH1)
2790 printk("CH1 ");
2791 if (s & CLRSTCNT)
2792 printk("CLRSTCNT ");
2793 if (s & SPIOEN)
2794 printk("SPIOEN ");
2795 if (s & CLRCH1)
2796 printk("CLRCH1 ");
2797 printk("); ");
2798
2799 printk("SIGNAL( ");
2800
2801 s = GETPORT(SCSISIG);
2802 if (s & SIG_ATNI)
2803 printk("ATNI ");
2804 if (s & SIG_SELI)
2805 printk("SELI ");
2806 if (s & SIG_BSYI)
2807 printk("BSYI ");
2808 if (s & SIG_REQI)
2809 printk("REQI ");
2810 if (s & SIG_ACKI)
2811 printk("ACKI ");
2812 printk("); ");
2813
2814 printk("SELID (%02x), ", GETPORT(SELID));
2815
2816 printk("STCNT (%d), ", GETSTCNT());
2817
2818 printk("SSTAT2( ");
2819
2820 s = GETPORT(SSTAT2);
2821 if (s & SOFFSET)
2822 printk("SOFFSET ");
2823 if (s & SEMPTY)
2824 printk("SEMPTY ");
2825 if (s & SFULL)
2826 printk("SFULL ");
2827 printk("); SFCNT (%d); ", s & (SFULL | SFCNT));
2828
2829 s = GETPORT(SSTAT3);
2830 printk("SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
2831
2832 printk("SSTAT4( ");
2833 s = GETPORT(SSTAT4);
2834 if (s & SYNCERR)
2835 printk("SYNCERR ");
2836 if (s & FWERR)
2837 printk("FWERR ");
2838 if (s & FRERR)
2839 printk("FRERR ");
2840 printk("); ");
2841
2842 printk("DMACNTRL0( ");
2843 s = GETPORT(DMACNTRL0);
2844 printk("%s ", s & _8BIT ? "8BIT" : "16BIT");
2845 printk("%s ", s & DMA ? "DMA" : "PIO");
2846 printk("%s ", s & WRITE_READ ? "WRITE" : "READ");
2847 if (s & ENDMA)
2848 printk("ENDMA ");
2849 if (s & INTEN)
2850 printk("INTEN ");
2851 if (s & RSTFIFO)
2852 printk("RSTFIFO ");
2853 if (s & SWINT)
2854 printk("SWINT ");
2855 printk("); ");
2856
2857 printk("DMASTAT( ");
2858 s = GETPORT(DMASTAT);
2859 if (s & ATDONE)
2860 printk("ATDONE ");
2861 if (s & WORDRDY)
2862 printk("WORDRDY ");
2863 if (s & DFIFOFULL)
2864 printk("DFIFOFULL ");
2865 if (s & DFIFOEMP)
2866 printk("DFIFOEMP ");
2867 printk(")\n");
2868#endif
2869}
2870
2871/*
2872 * display enabled interrupts 2417 * display enabled interrupts
2873 */ 2418 */
2874static void disp_enintr(struct Scsi_Host *shpnt) 2419static void disp_enintr(struct Scsi_Host *shpnt)
2875{ 2420{
2876 int s; 2421 int s0, s1;
2877 2422
2878 printk(KERN_DEBUG "enabled interrupts ( "); 2423 s0 = GETPORT(SIMODE0);
2879 2424 s1 = GETPORT(SIMODE1);
2880 s = GETPORT(SIMODE0); 2425
2881 if (s & ENSELDO) 2426 shost_printk(KERN_DEBUG, shpnt,
2882 printk("ENSELDO "); 2427 "enabled interrupts (%s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n",
2883 if (s & ENSELDI) 2428 (s0 & ENSELDO) ? "ENSELDO " : "",
2884 printk("ENSELDI "); 2429 (s0 & ENSELDI) ? "ENSELDI " : "",
2885 if (s & ENSELINGO) 2430 (s0 & ENSELINGO) ? "ENSELINGO " : "",
2886 printk("ENSELINGO "); 2431 (s0 & ENSWRAP) ? "ENSWRAP " : "",
2887 if (s & ENSWRAP) 2432 (s0 & ENSDONE) ? "ENSDONE " : "",
2888 printk("ENSWRAP "); 2433 (s0 & ENSPIORDY) ? "ENSPIORDY " : "",
2889 if (s & ENSDONE) 2434 (s0 & ENDMADONE) ? "ENDMADONE " : "",
2890 printk("ENSDONE "); 2435 (s1 & ENSELTIMO) ? "ENSELTIMO " : "",
2891 if (s & ENSPIORDY) 2436 (s1 & ENATNTARG) ? "ENATNTARG " : "",
2892 printk("ENSPIORDY "); 2437 (s1 & ENPHASEMIS) ? "ENPHASEMIS " : "",
2893 if (s & ENDMADONE) 2438 (s1 & ENBUSFREE) ? "ENBUSFREE " : "",
2894 printk("ENDMADONE "); 2439 (s1 & ENSCSIPERR) ? "ENSCSIPERR " : "",
2895 2440 (s1 & ENPHASECHG) ? "ENPHASECHG " : "",
2896 s = GETPORT(SIMODE1); 2441 (s1 & ENREQINIT) ? "ENREQINIT " : "");
2897 if (s & ENSELTIMO)
2898 printk("ENSELTIMO ");
2899 if (s & ENATNTARG)
2900 printk("ENATNTARG ");
2901 if (s & ENPHASEMIS)
2902 printk("ENPHASEMIS ");
2903 if (s & ENBUSFREE)
2904 printk("ENBUSFREE ");
2905 if (s & ENSCSIPERR)
2906 printk("ENSCSIPERR ");
2907 if (s & ENPHASECHG)
2908 printk("ENPHASECHG ");
2909 if (s & ENREQINIT)
2910 printk("ENREQINIT ");
2911 printk(")\n");
2912} 2442}
2913 2443
2914/* 2444/*
@@ -2916,36 +2446,21 @@ static void disp_enintr(struct Scsi_Host *shpnt)
2916 */ 2446 */
2917static void show_command(Scsi_Cmnd *ptr) 2447static void show_command(Scsi_Cmnd *ptr)
2918{ 2448{
2919 scmd_printk(KERN_DEBUG, ptr, "%p: cmnd=(", ptr); 2449 scsi_print_command(ptr);
2920 2450 scmd_printk(KERN_DEBUG, ptr,
2921 __scsi_print_command(ptr->cmnd); 2451 "request_bufflen=%d; resid=%d; "
2922 2452 "phase |%s%s%s%s%s%s%s%s%s; next=0x%p",
2923 printk(KERN_DEBUG "); request_bufflen=%d; resid=%d; phase |", 2453 scsi_bufflen(ptr), scsi_get_resid(ptr),
2924 scsi_bufflen(ptr), scsi_get_resid(ptr)); 2454 (ptr->SCp.phase & not_issued) ? "not issued|" : "",
2925 2455 (ptr->SCp.phase & selecting) ? "selecting|" : "",
2926 if (ptr->SCp.phase & not_issued) 2456 (ptr->SCp.phase & identified) ? "identified|" : "",
2927 printk("not issued|"); 2457 (ptr->SCp.phase & disconnected) ? "disconnected|" : "",
2928 if (ptr->SCp.phase & selecting) 2458 (ptr->SCp.phase & completed) ? "completed|" : "",
2929 printk("selecting|"); 2459 (ptr->SCp.phase & spiordy) ? "spiordy|" : "",
2930 if (ptr->SCp.phase & identified) 2460 (ptr->SCp.phase & syncneg) ? "syncneg|" : "",
2931 printk("identified|"); 2461 (ptr->SCp.phase & aborted) ? "aborted|" : "",
2932 if (ptr->SCp.phase & disconnected) 2462 (ptr->SCp.phase & resetted) ? "resetted|" : "",
2933 printk("disconnected|"); 2463 (SCDATA(ptr)) ? SCNEXT(ptr) : NULL);
2934 if (ptr->SCp.phase & completed)
2935 printk("completed|");
2936 if (ptr->SCp.phase & spiordy)
2937 printk("spiordy|");
2938 if (ptr->SCp.phase & syncneg)
2939 printk("syncneg|");
2940 if (ptr->SCp.phase & aborted)
2941 printk("aborted|");
2942 if (ptr->SCp.phase & resetted)
2943 printk("resetted|");
2944 if( SCDATA(ptr) ) {
2945 printk("; next=0x%p\n", SCNEXT(ptr));
2946 } else {
2947 printk("; next=(host scribble NULL)\n");
2948 }
2949} 2464}
2950 2465
2951/* 2466/*
@@ -2972,7 +2487,6 @@ static void show_queues(struct Scsi_Host *shpnt)
2972 for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL) 2487 for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL)
2973 show_command(ptr); 2488 show_command(ptr);
2974 2489
2975 disp_ports(shpnt);
2976 disp_enintr(shpnt); 2490 disp_enintr(shpnt);
2977} 2491}
2978 2492
@@ -3276,15 +2790,6 @@ static int aha152x_set_info(struct Scsi_Host *shpnt, char *buffer, int length)
3276 if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0) 2790 if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0)
3277 return -EINVAL; 2791 return -EINVAL;
3278 2792
3279#if defined(AHA152X_DEBUG)
3280 if(length>14 && strncmp("debug ", buffer+8, 6)==0) {
3281 int debug = HOSTDATA(shpnt)->debug;
3282
3283 HOSTDATA(shpnt)->debug = simple_strtoul(buffer+14, NULL, 0);
3284
3285 printk(KERN_INFO "aha152x%d: debugging options set to 0x%04x (were 0x%04x)\n", HOSTNO, HOSTDATA(shpnt)->debug, debug);
3286 } else
3287#endif
3288#if defined(AHA152X_STAT) 2793#if defined(AHA152X_STAT)
3289 if(length>13 && strncmp("reset", buffer+8, 5)==0) { 2794 if(length>13 && strncmp("reset", buffer+8, 5)==0) {
3290 int i; 2795 int i;
@@ -3302,7 +2807,7 @@ static int aha152x_set_info(struct Scsi_Host *shpnt, char *buffer, int length)
3302 HOSTDATA(shpnt)->time[i]=0; 2807 HOSTDATA(shpnt)->time[i]=0;
3303 } 2808 }
3304 2809
3305 printk(KERN_INFO "aha152x%d: stats reseted.\n", HOSTNO); 2810 shost_printk(KERN_INFO, shpnt, "aha152x: stats reset.\n");
3306 2811
3307 } else 2812 } else
3308#endif 2813#endif
@@ -3343,29 +2848,6 @@ static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
3343 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50, 2848 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50,
3344 HOSTDATA(shpnt)->syncrate[i] & 0x0f); 2849 HOSTDATA(shpnt)->syncrate[i] & 0x0f);
3345 } 2850 }
3346#if defined(AHA152X_DEBUG)
3347#define PDEBUG(flags,txt) \
3348 if(HOSTDATA(shpnt)->debug & flags) SPRINTF("(%s) ", txt);
3349
3350 SPRINTF("enabled debugging options: ");
3351
3352 PDEBUG(debug_procinfo, "procinfo");
3353 PDEBUG(debug_queue, "queue");
3354 PDEBUG(debug_intr, "interrupt");
3355 PDEBUG(debug_selection, "selection");
3356 PDEBUG(debug_msgo, "message out");
3357 PDEBUG(debug_msgi, "message in");
3358 PDEBUG(debug_status, "status");
3359 PDEBUG(debug_cmd, "command");
3360 PDEBUG(debug_datai, "data in");
3361 PDEBUG(debug_datao, "data out");
3362 PDEBUG(debug_eh, "eh");
3363 PDEBUG(debug_locking, "locks");
3364 PDEBUG(debug_phases, "phases");
3365
3366 SPRINTF("\n");
3367#endif
3368
3369 SPRINTF("\nqueue status:\n"); 2851 SPRINTF("\nqueue status:\n");
3370 DO_LOCK(flags); 2852 DO_LOCK(flags);
3371 if (ISSUE_SC) { 2853 if (ISSUE_SC) {
@@ -3393,8 +2875,8 @@ static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
3393 2875
3394#if defined(AHA152X_STAT) 2876#if defined(AHA152X_STAT)
3395 SPRINTF("statistics:\n" 2877 SPRINTF("statistics:\n"
3396 "total commands: %d\n" 2878 "total commands: %d\n"
3397 "disconnections: %d\n" 2879 "disconnections: %d\n"
3398 "busfree with check condition: %d\n" 2880 "busfree with check condition: %d\n"
3399 "busfree without old command: %d\n" 2881 "busfree without old command: %d\n"
3400 "busfree without new command: %d\n" 2882 "busfree without new command: %d\n"
@@ -3413,7 +2895,7 @@ static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
3413 HOSTDATA(shpnt)->busfree_without_any_action); 2895 HOSTDATA(shpnt)->busfree_without_any_action);
3414 for(i=0; i<maxstate; i++) { 2896 for(i=0; i<maxstate; i++) {
3415 SPRINTF("%-10s %-12d %-12d %-12ld\n", 2897 SPRINTF("%-10s %-12d %-12d %-12ld\n",
3416 states[i].name, 2898 states[i].name,
3417 HOSTDATA(shpnt)->count_trans[i], 2899 HOSTDATA(shpnt)->count_trans[i],
3418 HOSTDATA(shpnt)->count[i], 2900 HOSTDATA(shpnt)->count[i],
3419 HOSTDATA(shpnt)->time[i]); 2901 HOSTDATA(shpnt)->time[i]);
@@ -3671,25 +3153,19 @@ static int __init aha152x_init(void)
3671 setup[setup_count].synchronous = aha152x[5]; 3153 setup[setup_count].synchronous = aha152x[5];
3672 setup[setup_count].delay = aha152x[6]; 3154 setup[setup_count].delay = aha152x[6];
3673 setup[setup_count].ext_trans = aha152x[7]; 3155 setup[setup_count].ext_trans = aha152x[7];
3674#if defined(AHA152X_DEBUG) 3156 } else if (io[0] != 0 || irq[0] != 0) {
3675 setup[setup_count].debug = aha152x[8];
3676#endif
3677 } else if(io[0]!=0 || irq[0]!=0) {
3678 if(io[0]!=0) setup[setup_count].io_port = io[0]; 3157 if(io[0]!=0) setup[setup_count].io_port = io[0];
3679 if(irq[0]!=0) setup[setup_count].irq = irq[0]; 3158 if(irq[0]!=0) setup[setup_count].irq = irq[0];
3680 3159
3681 setup[setup_count].scsiid = scsiid[0]; 3160 setup[setup_count].scsiid = scsiid[0];
3682 setup[setup_count].reconnect = reconnect[0]; 3161 setup[setup_count].reconnect = reconnect[0];
3683 setup[setup_count].parity = parity[0]; 3162 setup[setup_count].parity = parity[0];
3684 setup[setup_count].synchronous = sync[0]; 3163 setup[setup_count].synchronous = sync[0];
3685 setup[setup_count].delay = delay[0]; 3164 setup[setup_count].delay = delay[0];
3686 setup[setup_count].ext_trans = exttrans[0]; 3165 setup[setup_count].ext_trans = exttrans[0];
3687#if defined(AHA152X_DEBUG)
3688 setup[setup_count].debug = debug[0];
3689#endif
3690 } 3166 }
3691 3167
3692 if (checksetup(&setup[setup_count])) 3168 if (checksetup(&setup[setup_count]))
3693 setup_count++; 3169 setup_count++;
3694 else 3170 else
3695 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n", 3171 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
@@ -3714,22 +3190,16 @@ static int __init aha152x_init(void)
3714 setup[setup_count].synchronous = aha152x1[5]; 3190 setup[setup_count].synchronous = aha152x1[5];
3715 setup[setup_count].delay = aha152x1[6]; 3191 setup[setup_count].delay = aha152x1[6];
3716 setup[setup_count].ext_trans = aha152x1[7]; 3192 setup[setup_count].ext_trans = aha152x1[7];
3717#if defined(AHA152X_DEBUG) 3193 } else if (io[1] != 0 || irq[1] != 0) {
3718 setup[setup_count].debug = aha152x1[8];
3719#endif
3720 } else if(io[1]!=0 || irq[1]!=0) {
3721 if(io[1]!=0) setup[setup_count].io_port = io[1]; 3194 if(io[1]!=0) setup[setup_count].io_port = io[1];
3722 if(irq[1]!=0) setup[setup_count].irq = irq[1]; 3195 if(irq[1]!=0) setup[setup_count].irq = irq[1];
3723 3196
3724 setup[setup_count].scsiid = scsiid[1]; 3197 setup[setup_count].scsiid = scsiid[1];
3725 setup[setup_count].reconnect = reconnect[1]; 3198 setup[setup_count].reconnect = reconnect[1];
3726 setup[setup_count].parity = parity[1]; 3199 setup[setup_count].parity = parity[1];
3727 setup[setup_count].synchronous = sync[1]; 3200 setup[setup_count].synchronous = sync[1];
3728 setup[setup_count].delay = delay[1]; 3201 setup[setup_count].delay = delay[1];
3729 setup[setup_count].ext_trans = exttrans[1]; 3202 setup[setup_count].ext_trans = exttrans[1];
3730#if defined(AHA152X_DEBUG)
3731 setup[setup_count].debug = debug[1];
3732#endif
3733 } 3203 }
3734 if (checksetup(&setup[setup_count])) 3204 if (checksetup(&setup[setup_count]))
3735 setup_count++; 3205 setup_count++;
@@ -3776,9 +3246,6 @@ static int __init aha152x_init(void)
3776 setup[setup_count].synchronous = 1; 3246 setup[setup_count].synchronous = 1;
3777 setup[setup_count].delay = DELAY_DEFAULT; 3247 setup[setup_count].delay = DELAY_DEFAULT;
3778 setup[setup_count].ext_trans = 0; 3248 setup[setup_count].ext_trans = 0;
3779#if defined(AHA152X_DEBUG)
3780 setup[setup_count].debug = DEBUG_DEFAULT;
3781#endif
3782#if defined(__ISAPNP__) 3249#if defined(__ISAPNP__)
3783 pnpdev[setup_count] = dev; 3250 pnpdev[setup_count] = dev;
3784#endif 3251#endif
@@ -3847,9 +3314,6 @@ static int __init aha152x_init(void)
3847 setup[setup_count].synchronous = conf.cf_syncneg; 3314 setup[setup_count].synchronous = conf.cf_syncneg;
3848 setup[setup_count].delay = DELAY_DEFAULT; 3315 setup[setup_count].delay = DELAY_DEFAULT;
3849 setup[setup_count].ext_trans = 0; 3316 setup[setup_count].ext_trans = 0;
3850#if defined(AHA152X_DEBUG)
3851 setup[setup_count].debug = DEBUG_DEFAULT;
3852#endif
3853 setup_count++; 3317 setup_count++;
3854 3318
3855 } 3319 }
@@ -3903,11 +3367,8 @@ module_exit(aha152x_exit);
3903#if !defined(MODULE) 3367#if !defined(MODULE)
3904static int __init aha152x_setup(char *str) 3368static int __init aha152x_setup(char *str)
3905{ 3369{
3906#if defined(AHA152X_DEBUG)
3907 int ints[11];
3908#else
3909 int ints[10]; 3370 int ints[10];
3910#endif 3371
3911 get_options(str, ARRAY_SIZE(ints), ints); 3372 get_options(str, ARRAY_SIZE(ints), ints);
3912 3373
3913 if(setup_count>=ARRAY_SIZE(setup)) { 3374 if(setup_count>=ARRAY_SIZE(setup)) {
@@ -3924,16 +3385,9 @@ static int __init aha152x_setup(char *str)
3924 setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1; 3385 setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1;
3925 setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT; 3386 setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT;
3926 setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0; 3387 setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0;
3927#if defined(AHA152X_DEBUG)
3928 setup[setup_count].debug = ints[0] >= 9 ? ints[9] : DEBUG_DEFAULT;
3929 if (ints[0] > 9) {
3930 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
3931 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>[,<DEBUG>]]]]]]]]\n");
3932#else
3933 if (ints[0] > 8) { /*}*/ 3388 if (ints[0] > 8) { /*}*/
3934 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>" 3389 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
3935 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n"); 3390 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
3936#endif
3937 } else { 3391 } else {
3938 setup_count++; 3392 setup_count++;
3939 return 0; 3393 return 0;
diff --git a/drivers/scsi/aha1740.c b/drivers/scsi/aha1740.c
index 5f3101797c93..31ace4bef8fe 100644
--- a/drivers/scsi/aha1740.c
+++ b/drivers/scsi/aha1740.c
@@ -531,7 +531,7 @@ static int aha1740_eh_abort_handler (Scsi_Cmnd *dummy)
531 * quiet as possible... 531 * quiet as possible...
532 */ 532 */
533 533
534 return 0; 534 return SUCCESS;
535} 535}
536 536
537static struct scsi_host_template aha1740_template = { 537static struct scsi_host_template aha1740_template = {
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index ed333669a7dc..80cb4fd7caaa 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -925,6 +925,7 @@ struct scsi_host_template aic79xx_driver_template = {
925 .slave_configure = ahd_linux_slave_configure, 925 .slave_configure = ahd_linux_slave_configure,
926 .target_alloc = ahd_linux_target_alloc, 926 .target_alloc = ahd_linux_target_alloc,
927 .target_destroy = ahd_linux_target_destroy, 927 .target_destroy = ahd_linux_target_destroy,
928 .use_blk_tags = 1,
928}; 929};
929 930
930/******************************** Bus DMA *************************************/ 931/******************************** Bus DMA *************************************/
@@ -1468,12 +1469,9 @@ ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
1468 1469
1469 switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) { 1470 switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
1470 case AHD_DEV_Q_BASIC: 1471 case AHD_DEV_Q_BASIC:
1471 scsi_set_tag_type(sdev, MSG_SIMPLE_TASK);
1472 scsi_activate_tcq(sdev, dev->openings + dev->active);
1473 break;
1474 case AHD_DEV_Q_TAGGED: 1472 case AHD_DEV_Q_TAGGED:
1475 scsi_set_tag_type(sdev, MSG_ORDERED_TASK); 1473 scsi_adjust_queue_depth(sdev,
1476 scsi_activate_tcq(sdev, dev->openings + dev->active); 1474 dev->openings + dev->active);
1477 break; 1475 break;
1478 default: 1476 default:
1479 /* 1477 /*
@@ -1482,7 +1480,7 @@ ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
1482 * serially on the controller/device. This should 1480 * serially on the controller/device. This should
1483 * remove some latency. 1481 * remove some latency.
1484 */ 1482 */
1485 scsi_deactivate_tcq(sdev, 1); 1483 scsi_adjust_queue_depth(sdev, 1);
1486 break; 1484 break;
1487 } 1485 }
1488} 1486}
@@ -1619,15 +1617,6 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
1619 } 1617 }
1620 1618
1621 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) { 1619 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
1622 int msg_bytes;
1623 uint8_t tag_msgs[2];
1624
1625 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
1626 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
1627 hscb->control |= tag_msgs[0];
1628 if (tag_msgs[0] == MSG_ORDERED_TASK)
1629 dev->commands_since_idle_or_otag = 0;
1630 } else
1631 if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH 1620 if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
1632 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) { 1621 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
1633 hscb->control |= MSG_ORDERED_TASK; 1622 hscb->control |= MSG_ORDERED_TASK;
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index d2c9bf39033d..a6a27d5398dd 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -812,6 +812,7 @@ struct scsi_host_template aic7xxx_driver_template = {
812 .slave_configure = ahc_linux_slave_configure, 812 .slave_configure = ahc_linux_slave_configure,
813 .target_alloc = ahc_linux_target_alloc, 813 .target_alloc = ahc_linux_target_alloc,
814 .target_destroy = ahc_linux_target_destroy, 814 .target_destroy = ahc_linux_target_destroy,
815 .use_blk_tags = 1,
815}; 816};
816 817
817/**************************** Tasklet Handler *********************************/ 818/**************************** Tasklet Handler *********************************/
@@ -1334,13 +1335,9 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
1334 } 1335 }
1335 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { 1336 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
1336 case AHC_DEV_Q_BASIC: 1337 case AHC_DEV_Q_BASIC:
1337 scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
1338 scsi_activate_tcq(sdev, dev->openings + dev->active);
1339 break;
1340 case AHC_DEV_Q_TAGGED: 1338 case AHC_DEV_Q_TAGGED:
1341 scsi_set_tag_type(sdev, MSG_ORDERED_TAG); 1339 scsi_adjust_queue_depth(sdev,
1342 scsi_activate_tcq(sdev, dev->openings + dev->active); 1340 dev->openings + dev->active);
1343 break;
1344 default: 1341 default:
1345 /* 1342 /*
1346 * We allow the OS to queue 2 untagged transactions to 1343 * We allow the OS to queue 2 untagged transactions to
@@ -1348,7 +1345,7 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
1348 * serially on the controller/device. This should 1345 * serially on the controller/device. This should
1349 * remove some latency. 1346 * remove some latency.
1350 */ 1347 */
1351 scsi_deactivate_tcq(sdev, 2); 1348 scsi_adjust_queue_depth(sdev, 2);
1352 break; 1349 break;
1353 } 1350 }
1354} 1351}
@@ -1447,7 +1444,7 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
1447 * we are storing a full busy target *lun* 1444 * we are storing a full busy target *lun*
1448 * table in SCB space. 1445 * table in SCB space.
1449 */ 1446 */
1450 if (!blk_rq_tagged(cmd->request) 1447 if (!(cmd->flags & SCMD_TAGGED)
1451 && (ahc->features & AHC_SCB_BTT) == 0) { 1448 && (ahc->features & AHC_SCB_BTT) == 0) {
1452 int target_offset; 1449 int target_offset;
1453 1450
@@ -1501,15 +1498,7 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
1501 } 1498 }
1502 1499
1503 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) { 1500 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
1504 int msg_bytes; 1501 if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
1505 uint8_t tag_msgs[2];
1506
1507 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
1508 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
1509 hscb->control |= tag_msgs[0];
1510 if (tag_msgs[0] == MSG_ORDERED_TASK)
1511 dev->commands_since_idle_or_otag = 0;
1512 } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
1513 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) { 1502 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
1514 hscb->control |= MSG_ORDERED_TASK; 1503 hscb->control |= MSG_ORDERED_TASK;
1515 dev->commands_since_idle_or_otag = 0; 1504 dev->commands_since_idle_or_otag = 0;
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index c56741fc4b99..579dc2f460c4 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -83,6 +83,7 @@ static struct scsi_host_template aic94xx_sht = {
83 .eh_bus_reset_handler = sas_eh_bus_reset_handler, 83 .eh_bus_reset_handler = sas_eh_bus_reset_handler,
84 .target_destroy = sas_target_destroy, 84 .target_destroy = sas_target_destroy,
85 .ioctl = sas_ioctl, 85 .ioctl = sas_ioctl,
86 .use_blk_tags = 1,
86}; 87};
87 88
88static int asd_map_memio(struct asd_ha_struct *asd_ha) 89static int asd_map_memio(struct asd_ha_struct *asd_ha)
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 0b44fb5ee485..209f77162d06 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -122,7 +122,7 @@ static int arcmsr_adjust_disk_queue_depth(struct scsi_device *sdev,
122 122
123 if (queue_depth > ARCMSR_MAX_CMD_PERLUN) 123 if (queue_depth > ARCMSR_MAX_CMD_PERLUN)
124 queue_depth = ARCMSR_MAX_CMD_PERLUN; 124 queue_depth = ARCMSR_MAX_CMD_PERLUN;
125 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); 125 scsi_adjust_queue_depth(sdev, queue_depth);
126 return queue_depth; 126 return queue_depth;
127} 127}
128 128
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index d89b9b4deb3c..deaaf84989cd 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -850,13 +850,13 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
850 break; 850 break;
851 851
852 default: 852 default:
853 printk(KERN_ERR "scsi%d.H: incomplete data transfer detected: result=%08X command=", 853 scmd_printk(KERN_ERR, SCpnt,
854 host->host->host_no, SCpnt->result); 854 "incomplete data transfer detected: "
855 __scsi_print_command(SCpnt->cmnd); 855 "result=%08X", SCpnt->result);
856 scsi_print_command(SCpnt);
856 acornscsi_dumpdma(host, "done"); 857 acornscsi_dumpdma(host, "done");
857 acornscsi_dumplog(host, SCpnt->device->id); 858 acornscsi_dumplog(host, SCpnt->device->id);
858 SCpnt->result &= 0xffff; 859 set_host_byte(SCpnt, DID_ERROR);
859 SCpnt->result |= DID_ERROR << 16;
860 } 860 }
861 } 861 }
862 } 862 }
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 71cfb1e504c4..e64c3af7c1a0 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -308,8 +308,7 @@ static void fas216_log_command(FAS216_Info *info, int level,
308 fas216_do_log(info, '0' + SCpnt->device->id, fmt, args); 308 fas216_do_log(info, '0' + SCpnt->device->id, fmt, args);
309 va_end(args); 309 va_end(args);
310 310
311 printk(" CDB: "); 311 scsi_print_command(SCpnt);
312 __scsi_print_command(SCpnt->cmnd);
313} 312}
314 313
315static void 314static void
@@ -2079,14 +2078,12 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
2079 break; 2078 break;
2080 2079
2081 default: 2080 default:
2082 printk(KERN_ERR "scsi%d.%c: incomplete data transfer " 2081 scmd_printk(KERN_ERR, SCpnt,
2083 "detected: res=%08X ptr=%p len=%X CDB: ", 2082 "incomplete data transfer detected: res=%08X ptr=%p len=%X\n",
2084 info->host->host_no, '0' + SCpnt->device->id, 2083 SCpnt->result, info->scsi.SCp.ptr,
2085 SCpnt->result, info->scsi.SCp.ptr, 2084 info->scsi.SCp.this_residual);
2086 info->scsi.SCp.this_residual); 2085 scsi_print_command(SCpnt);
2087 __scsi_print_command(SCpnt->cmnd); 2086 set_host_byte(SCpnt, DID_ERROR);
2088 SCpnt->result &= ~(255 << 16);
2089 SCpnt->result |= DID_BAD_TARGET << 16;
2090 goto request_sense; 2087 goto request_sense;
2091 } 2088 }
2092 } 2089 }
@@ -2158,12 +2155,11 @@ static void fas216_done(FAS216_Info *info, unsigned int result)
2158 * to transfer, we should not have a valid pointer. 2155 * to transfer, we should not have a valid pointer.
2159 */ 2156 */
2160 if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) { 2157 if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) {
2161 printk("scsi%d.%c: zero bytes left to transfer, but " 2158 scmd_printk(KERN_INFO, SCpnt,
2162 "buffer pointer still valid: ptr=%p len=%08x CDB: ", 2159 "zero bytes left to transfer, but buffer pointer still valid: ptr=%p len=%08x\n",
2163 info->host->host_no, '0' + SCpnt->device->id, 2160 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
2164 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
2165 info->scsi.SCp.ptr = NULL; 2161 info->scsi.SCp.ptr = NULL;
2166 __scsi_print_command(SCpnt->cmnd); 2162 scsi_print_command(SCpnt);
2167 } 2163 }
2168 2164
2169 /* 2165 /*
@@ -2427,14 +2423,11 @@ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
2427 2423
2428 info->stats.aborts += 1; 2424 info->stats.aborts += 1;
2429 2425
2430 printk(KERN_WARNING "scsi%d: abort command ", info->host->host_no); 2426 scmd_printk(KERN_WARNING, SCpnt, "abort command\n");
2431 __scsi_print_command(SCpnt->cmnd);
2432 2427
2433 print_debug_list(); 2428 print_debug_list();
2434 fas216_dumpstate(info); 2429 fas216_dumpstate(info);
2435 2430
2436 printk(KERN_WARNING "scsi%d: abort %p ", info->host->host_no, SCpnt);
2437
2438 switch (fas216_find_command(info, SCpnt)) { 2431 switch (fas216_find_command(info, SCpnt)) {
2439 /* 2432 /*
2440 * We found the command, and cleared it out. Either 2433 * We found the command, and cleared it out. Either
@@ -2442,7 +2435,7 @@ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
2442 * target, or the busylun bit is not set. 2435 * target, or the busylun bit is not set.
2443 */ 2436 */
2444 case res_success: 2437 case res_success:
2445 printk("success\n"); 2438 scmd_printk(KERN_WARNING, SCpnt, "abort %p success\n", SCpnt);
2446 result = SUCCESS; 2439 result = SUCCESS;
2447 break; 2440 break;
2448 2441
@@ -2452,14 +2445,13 @@ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
2452 * if the bus is free. 2445 * if the bus is free.
2453 */ 2446 */
2454 case res_hw_abort: 2447 case res_hw_abort:
2455
2456 2448
2457 /* 2449 /*
2458 * We are unable to abort the command for some reason. 2450 * We are unable to abort the command for some reason.
2459 */ 2451 */
2460 default: 2452 default:
2461 case res_failed: 2453 case res_failed:
2462 printk("failed\n"); 2454 scmd_printk(KERN_WARNING, SCpnt, "abort %p failed\n", SCpnt);
2463 break; 2455 break;
2464 } 2456 }
2465 2457
@@ -2664,8 +2656,7 @@ int fas216_eh_host_reset(struct scsi_cmnd *SCpnt)
2664 2656
2665 fas216_checkmagic(info); 2657 fas216_checkmagic(info);
2666 2658
2667 printk("scsi%d.%c: %s: resetting host\n", 2659 fas216_log(info, LOG_ERROR, "resetting host");
2668 info->host->host_no, '0' + SCpnt->device->id, __func__);
2669 2660
2670 /* 2661 /*
2671 * Reset the SCSI chip. 2662 * Reset the SCSI chip.
diff --git a/drivers/scsi/atari_NCR5380.c b/drivers/scsi/atari_NCR5380.c
index 79e6f045c2a9..11e93025b87a 100644
--- a/drivers/scsi/atari_NCR5380.c
+++ b/drivers/scsi/atari_NCR5380.c
@@ -2607,7 +2607,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
2607 * host byte of the result field to, if zero DID_ABORTED is 2607 * host byte of the result field to, if zero DID_ABORTED is
2608 * used. 2608 * used.
2609 * 2609 *
2610 * Returns : 0 - success, -1 on failure. 2610 * Returns : SUCCESS - success, FAILED on failure.
2611 * 2611 *
2612 * XXX - there is no way to abort the command that is currently 2612 * XXX - there is no way to abort the command that is currently
2613 * connected, you have to wait for it to complete. If this is 2613 * connected, you have to wait for it to complete. If this is
@@ -2623,8 +2623,7 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2623 Scsi_Cmnd *tmp, **prev; 2623 Scsi_Cmnd *tmp, **prev;
2624 unsigned long flags; 2624 unsigned long flags;
2625 2625
2626 printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO); 2626 scmd_printk(KERN_NOTICE, cmd, "aborting command\n");
2627 scsi_print_command(cmd);
2628 2627
2629 NCR5380_print_status(instance); 2628 NCR5380_print_status(instance);
2630 2629
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index f067332bf763..87b09cd232cc 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -776,11 +776,7 @@ bfad_thread_workq(struct bfad_s *bfad)
776static int 776static int
777bfad_im_slave_configure(struct scsi_device *sdev) 777bfad_im_slave_configure(struct scsi_device *sdev)
778{ 778{
779 if (sdev->tagged_supported) 779 scsi_adjust_queue_depth(sdev, bfa_lun_queue_depth);
780 scsi_activate_tcq(sdev, bfa_lun_queue_depth);
781 else
782 scsi_deactivate_tcq(sdev, bfa_lun_queue_depth);
783
784 return 0; 780 return 0;
785} 781}
786 782
@@ -804,6 +800,7 @@ struct scsi_host_template bfad_im_scsi_host_template = {
804 .shost_attrs = bfad_im_host_attrs, 800 .shost_attrs = bfad_im_host_attrs,
805 .max_sectors = BFAD_MAX_SECTORS, 801 .max_sectors = BFAD_MAX_SECTORS,
806 .vendor_id = BFA_PCI_VENDOR_ID_BROCADE, 802 .vendor_id = BFA_PCI_VENDOR_ID_BROCADE,
803 .use_blk_tags = 1,
807}; 804};
808 805
809struct scsi_host_template bfad_im_vport_template = { 806struct scsi_host_template bfad_im_vport_template = {
@@ -825,6 +822,7 @@ struct scsi_host_template bfad_im_vport_template = {
825 .use_clustering = ENABLE_CLUSTERING, 822 .use_clustering = ENABLE_CLUSTERING,
826 .shost_attrs = bfad_im_vport_attrs, 823 .shost_attrs = bfad_im_vport_attrs,
827 .max_sectors = BFAD_MAX_SECTORS, 824 .max_sectors = BFAD_MAX_SECTORS,
825 .use_blk_tags = 1,
828}; 826};
829 827
830bfa_status_t 828bfa_status_t
@@ -868,14 +866,8 @@ bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
868 if (bfa_lun_queue_depth > tmp_sdev->queue_depth) { 866 if (bfa_lun_queue_depth > tmp_sdev->queue_depth) {
869 if (tmp_sdev->id != sdev->id) 867 if (tmp_sdev->id != sdev->id)
870 continue; 868 continue;
871 if (tmp_sdev->ordered_tags) 869 scsi_adjust_queue_depth(tmp_sdev,
872 scsi_adjust_queue_depth(tmp_sdev, 870 tmp_sdev->queue_depth + 1);
873 MSG_ORDERED_TAG,
874 tmp_sdev->queue_depth + 1);
875 else
876 scsi_adjust_queue_depth(tmp_sdev,
877 MSG_SIMPLE_TAG,
878 tmp_sdev->queue_depth + 1);
879 871
880 itnim->last_ramp_up_time = jiffies; 872 itnim->last_ramp_up_time = jiffies;
881 } 873 }
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 72533c58c1f3..3c7db3e8aa76 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -2791,12 +2791,13 @@ static struct scsi_host_template bnx2fc_shost_template = {
2791 .eh_host_reset_handler = fc_eh_host_reset, 2791 .eh_host_reset_handler = fc_eh_host_reset,
2792 .slave_alloc = fc_slave_alloc, 2792 .slave_alloc = fc_slave_alloc,
2793 .change_queue_depth = fc_change_queue_depth, 2793 .change_queue_depth = fc_change_queue_depth,
2794 .change_queue_type = fc_change_queue_type, 2794 .change_queue_type = scsi_change_queue_type,
2795 .this_id = -1, 2795 .this_id = -1,
2796 .cmd_per_lun = 3, 2796 .cmd_per_lun = 3,
2797 .use_clustering = ENABLE_CLUSTERING, 2797 .use_clustering = ENABLE_CLUSTERING,
2798 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD, 2798 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2799 .max_sectors = 1024, 2799 .max_sectors = 1024,
2800 .use_blk_tags = 1,
2800}; 2801};
2801 2802
2802static struct libfc_function_template bnx2fc_libfc_fcn_templ = { 2803static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 5b99844ef6bf..4b56858c1df2 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1725,7 +1725,6 @@ void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
1725 struct fcp_cmnd *fcp_cmnd) 1725 struct fcp_cmnd *fcp_cmnd)
1726{ 1726{
1727 struct scsi_cmnd *sc_cmd = io_req->sc_cmd; 1727 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1728 char tag[2];
1729 1728
1730 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); 1729 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
1731 1730
@@ -1739,21 +1738,10 @@ void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
1739 fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags; 1738 fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags;
1740 fcp_cmnd->fc_flags = io_req->io_req_flags; 1739 fcp_cmnd->fc_flags = io_req->io_req_flags;
1741 1740
1742 if (scsi_populate_tag_msg(sc_cmd, tag)) { 1741 if (sc_cmd->flags & SCMD_TAGGED)
1743 switch (tag[0]) { 1742 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
1744 case HEAD_OF_QUEUE_TAG: 1743 else
1745 fcp_cmnd->fc_pri_ta = FCP_PTA_HEADQ;
1746 break;
1747 case ORDERED_QUEUE_TAG:
1748 fcp_cmnd->fc_pri_ta = FCP_PTA_ORDERED;
1749 break;
1750 default:
1751 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
1752 break;
1753 }
1754 } else {
1755 fcp_cmnd->fc_pri_ta = 0; 1744 fcp_cmnd->fc_pri_ta = 0;
1756 }
1757} 1745}
1758 1746
1759static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req, 1747static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index ef5ae0d03616..6bac8a746ee2 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -85,8 +85,7 @@ static const char * vendor_labels[CH_TYPES-4] = {
85// module_param_string_array(vendor_labels, NULL, 0444); 85// module_param_string_array(vendor_labels, NULL, 0444);
86 86
87#define ch_printk(prefix, ch, fmt, a...) \ 87#define ch_printk(prefix, ch, fmt, a...) \
88 sdev_printk(prefix, (ch)->device, "[%s] " fmt, \ 88 sdev_prefix_printk(prefix, (ch)->device, (ch)->name, fmt, ##a)
89 (ch)->name, ##a)
90 89
91#define DPRINTK(fmt, arg...) \ 90#define DPRINTK(fmt, arg...) \
92do { \ 91do { \
@@ -183,7 +182,7 @@ static int ch_find_errno(struct scsi_sense_hdr *sshdr)
183} 182}
184 183
185static int 184static int
186ch_do_scsi(scsi_changer *ch, unsigned char *cmd, 185ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
187 void *buffer, unsigned buflength, 186 void *buffer, unsigned buflength,
188 enum dma_data_direction direction) 187 enum dma_data_direction direction)
189{ 188{
@@ -197,7 +196,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
197 errno = 0; 196 errno = 0;
198 if (debug) { 197 if (debug) {
199 DPRINTK("command: "); 198 DPRINTK("command: ");
200 __scsi_print_command(cmd); 199 __scsi_print_command(cmd, cmd_len);
201 } 200 }
202 201
203 result = scsi_execute_req(ch->device, cmd, direction, buffer, 202 result = scsi_execute_req(ch->device, cmd, direction, buffer,
@@ -207,7 +206,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
207 DPRINTK("result: 0x%x\n",result); 206 DPRINTK("result: 0x%x\n",result);
208 if (driver_byte(result) & DRIVER_SENSE) { 207 if (driver_byte(result) & DRIVER_SENSE) {
209 if (debug) 208 if (debug)
210 scsi_print_sense_hdr(ch->name, &sshdr); 209 scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
211 errno = ch_find_errno(&sshdr); 210 errno = ch_find_errno(&sshdr);
212 211
213 switch(sshdr.sense_key) { 212 switch(sshdr.sense_key) {
@@ -258,7 +257,8 @@ ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
258 cmd[3] = elem & 0xff; 257 cmd[3] = elem & 0xff;
259 cmd[5] = 1; 258 cmd[5] = 1;
260 cmd[9] = 255; 259 cmd[9] = 255;
261 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) { 260 if (0 == (result = ch_do_scsi(ch, cmd, 12,
261 buffer, 256, DMA_FROM_DEVICE))) {
262 if (((buffer[16] << 8) | buffer[17]) != elem) { 262 if (((buffer[16] << 8) | buffer[17]) != elem) {
263 DPRINTK("asked for element 0x%02x, got 0x%02x\n", 263 DPRINTK("asked for element 0x%02x, got 0x%02x\n",
264 elem,(buffer[16] << 8) | buffer[17]); 264 elem,(buffer[16] << 8) | buffer[17]);
@@ -288,7 +288,7 @@ ch_init_elem(scsi_changer *ch)
288 memset(cmd,0,sizeof(cmd)); 288 memset(cmd,0,sizeof(cmd));
289 cmd[0] = INITIALIZE_ELEMENT_STATUS; 289 cmd[0] = INITIALIZE_ELEMENT_STATUS;
290 cmd[1] = (ch->device->lun & 0x7) << 5; 290 cmd[1] = (ch->device->lun & 0x7) << 5;
291 err = ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE); 291 err = ch_do_scsi(ch, cmd, 6, NULL, 0, DMA_NONE);
292 VPRINTK(KERN_INFO, "... finished\n"); 292 VPRINTK(KERN_INFO, "... finished\n");
293 return err; 293 return err;
294} 294}
@@ -310,10 +310,10 @@ ch_readconfig(scsi_changer *ch)
310 cmd[1] = (ch->device->lun & 0x7) << 5; 310 cmd[1] = (ch->device->lun & 0x7) << 5;
311 cmd[2] = 0x1d; 311 cmd[2] = 0x1d;
312 cmd[4] = 255; 312 cmd[4] = 255;
313 result = ch_do_scsi(ch, cmd, buffer, 255, DMA_FROM_DEVICE); 313 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE);
314 if (0 != result) { 314 if (0 != result) {
315 cmd[1] |= (1<<3); 315 cmd[1] |= (1<<3);
316 result = ch_do_scsi(ch, cmd, buffer, 255, DMA_FROM_DEVICE); 316 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE);
317 } 317 }
318 if (0 == result) { 318 if (0 == result) {
319 ch->firsts[CHET_MT] = 319 ch->firsts[CHET_MT] =
@@ -438,7 +438,7 @@ ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate)
438 cmd[4] = (elem >> 8) & 0xff; 438 cmd[4] = (elem >> 8) & 0xff;
439 cmd[5] = elem & 0xff; 439 cmd[5] = elem & 0xff;
440 cmd[8] = rotate ? 1 : 0; 440 cmd[8] = rotate ? 1 : 0;
441 return ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE); 441 return ch_do_scsi(ch, cmd, 10, NULL, 0, DMA_NONE);
442} 442}
443 443
444static int 444static int
@@ -459,7 +459,7 @@ ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate)
459 cmd[6] = (dest >> 8) & 0xff; 459 cmd[6] = (dest >> 8) & 0xff;
460 cmd[7] = dest & 0xff; 460 cmd[7] = dest & 0xff;
461 cmd[10] = rotate ? 1 : 0; 461 cmd[10] = rotate ? 1 : 0;
462 return ch_do_scsi(ch, cmd, NULL,0, DMA_NONE); 462 return ch_do_scsi(ch, cmd, 12, NULL,0, DMA_NONE);
463} 463}
464 464
465static int 465static int
@@ -485,7 +485,7 @@ ch_exchange(scsi_changer *ch, u_int trans, u_int src,
485 cmd[9] = dest2 & 0xff; 485 cmd[9] = dest2 & 0xff;
486 cmd[10] = (rotate1 ? 1 : 0) | (rotate2 ? 2 : 0); 486 cmd[10] = (rotate1 ? 1 : 0) | (rotate2 ? 2 : 0);
487 487
488 return ch_do_scsi(ch, cmd, NULL,0, DMA_NONE); 488 return ch_do_scsi(ch, cmd, 12, NULL, 0, DMA_NONE);
489} 489}
490 490
491static void 491static void
@@ -535,7 +535,7 @@ ch_set_voltag(scsi_changer *ch, u_int elem,
535 memcpy(buffer,tag,32); 535 memcpy(buffer,tag,32);
536 ch_check_voltag(buffer); 536 ch_check_voltag(buffer);
537 537
538 result = ch_do_scsi(ch, cmd, buffer, 256, DMA_TO_DEVICE); 538 result = ch_do_scsi(ch, cmd, 12, buffer, 256, DMA_TO_DEVICE);
539 kfree(buffer); 539 kfree(buffer);
540 return result; 540 return result;
541} 541}
@@ -616,6 +616,11 @@ static long ch_ioctl(struct file *file,
616 int retval; 616 int retval;
617 void __user *argp = (void __user *)arg; 617 void __user *argp = (void __user *)arg;
618 618
619 retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd,
620 file->f_flags & O_NDELAY);
621 if (retval)
622 return retval;
623
619 switch (cmd) { 624 switch (cmd) {
620 case CHIOGPARAMS: 625 case CHIOGPARAMS:
621 { 626 {
@@ -766,7 +771,8 @@ static long ch_ioctl(struct file *file,
766 ch_cmd[5] = 1; 771 ch_cmd[5] = 1;
767 ch_cmd[9] = 255; 772 ch_cmd[9] = 255;
768 773
769 result = ch_do_scsi(ch, ch_cmd, buffer, 256, DMA_FROM_DEVICE); 774 result = ch_do_scsi(ch, ch_cmd, 12,
775 buffer, 256, DMA_FROM_DEVICE);
770 if (!result) { 776 if (!result) {
771 cge.cge_status = buffer[18]; 777 cge.cge_status = buffer[18];
772 cge.cge_flags = 0; 778 cge.cge_flags = 0;
@@ -966,9 +972,9 @@ static int ch_remove(struct device *dev)
966} 972}
967 973
968static struct scsi_driver ch_template = { 974static struct scsi_driver ch_template = {
969 .owner = THIS_MODULE,
970 .gendrv = { 975 .gendrv = {
971 .name = "ch", 976 .name = "ch",
977 .owner = THIS_MODULE,
972 .probe = ch_probe, 978 .probe = ch_probe,
973 .remove = ch_remove, 979 .remove = ch_remove,
974 }, 980 },
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index d35a5d6c8d7c..e2068a2621c4 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -21,15 +21,21 @@
21 21
22 22
23/* Commands with service actions that change the command name */ 23/* Commands with service actions that change the command name */
24#define SERVICE_ACTION_IN_12 0xab
25#define SERVICE_ACTION_OUT_12 0xa9
26#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
27#define SERVICE_ACTION_IN_16 0x9e
28#define SERVICE_ACTION_OUT_16 0x9f
29#define THIRD_PARTY_COPY_OUT 0x83 24#define THIRD_PARTY_COPY_OUT 0x83
30#define THIRD_PARTY_COPY_IN 0x84 25#define THIRD_PARTY_COPY_IN 0x84
31 26
27#define VENDOR_SPECIFIC_CDB 0xc0
32 28
29struct sa_name_list {
30 int opcode;
31 const struct value_name_pair *arr;
32 int arr_sz;
33};
34
35struct value_name_pair {
36 int value;
37 const char * name;
38};
33 39
34#ifdef CONFIG_SCSI_CONSTANTS 40#ifdef CONFIG_SCSI_CONSTANTS
35static const char * cdb_byte0_names[] = { 41static const char * cdb_byte0_names[] = {
@@ -102,11 +108,6 @@ static const char * cdb_byte0_names[] = {
102 "Volume set (out), Send DVD structure", 108 "Volume set (out), Send DVD structure",
103}; 109};
104 110
105struct value_name_pair {
106 int value;
107 const char * name;
108};
109
110static const struct value_name_pair maint_in_arr[] = { 111static const struct value_name_pair maint_in_arr[] = {
111 {0x5, "Report identifying information"}, 112 {0x5, "Report identifying information"},
112 {0xa, "Report target port groups"}, 113 {0xa, "Report target port groups"},
@@ -244,170 +245,119 @@ static const struct value_name_pair variable_length_arr[] = {
244}; 245};
245#define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr) 246#define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr)
246 247
247static const char * get_sa_name(const struct value_name_pair * arr, 248static struct sa_name_list sa_names_arr[] = {
248 int arr_sz, int service_action) 249 {VARIABLE_LENGTH_CMD, variable_length_arr, VARIABLE_LENGTH_SZ},
249{ 250 {MAINTENANCE_IN, maint_in_arr, MAINT_IN_SZ},
250 int k; 251 {MAINTENANCE_OUT, maint_out_arr, MAINT_OUT_SZ},
252 {PERSISTENT_RESERVE_IN, pr_in_arr, PR_IN_SZ},
253 {PERSISTENT_RESERVE_OUT, pr_out_arr, PR_OUT_SZ},
254 {SERVICE_ACTION_IN_12, serv_in12_arr, SERV_IN12_SZ},
255 {SERVICE_ACTION_OUT_12, serv_out12_arr, SERV_OUT12_SZ},
256 {SERVICE_ACTION_BIDIRECTIONAL, serv_bidi_arr, SERV_BIDI_SZ},
257 {SERVICE_ACTION_IN_16, serv_in16_arr, SERV_IN16_SZ},
258 {SERVICE_ACTION_OUT_16, serv_out16_arr, SERV_OUT16_SZ},
259 {THIRD_PARTY_COPY_IN, tpc_in_arr, TPC_IN_SZ},
260 {THIRD_PARTY_COPY_OUT, tpc_out_arr, TPC_OUT_SZ},
261 {0, NULL, 0},
262};
251 263
252 for (k = 0; k < arr_sz; ++k, ++arr) { 264#else /* ifndef CONFIG_SCSI_CONSTANTS */
253 if (service_action == arr->value) 265static const char *cdb_byte0_names[0];
254 break; 266
255 } 267static struct sa_name_list sa_names_arr[] = {
256 return (k < arr_sz) ? arr->name : NULL; 268 {VARIABLE_LENGTH_CMD, NULL, 0},
257} 269 {MAINTENANCE_IN, NULL, 0},
270 {MAINTENANCE_OUT, NULL, 0},
271 {PERSISTENT_RESERVE_IN, NULL, 0},
272 {PERSISTENT_RESERVE_OUT, NULL, 0},
273 {SERVICE_ACTION_IN_12, NULL, 0},
274 {SERVICE_ACTION_OUT_12, NULL, 0},
275 {SERVICE_ACTION_BIDIRECTIONAL, NULL, 0},
276 {SERVICE_ACTION_IN_16, NULL, 0},
277 {SERVICE_ACTION_OUT_16, NULL, 0},
278 {THIRD_PARTY_COPY_IN, NULL, 0},
279 {THIRD_PARTY_COPY_OUT, NULL, 0},
280 {0, NULL, 0},
281};
282#endif /* CONFIG_SCSI_CONSTANTS */
258 283
259/* attempt to guess cdb length if cdb_len==0 . No trailing linefeed. */ 284static bool scsi_opcode_sa_name(int opcode, int service_action,
260static void print_opcode_name(unsigned char * cdbp, int cdb_len) 285 const char **cdb_name, const char **sa_name)
261{ 286{
262 int sa, len, cdb0; 287 struct sa_name_list *sa_name_ptr;
263 int fin_name = 0; 288 const struct value_name_pair *arr = NULL;
264 const char * name; 289 int arr_sz, k;
265 290
266 cdb0 = cdbp[0]; 291 *cdb_name = NULL;
267 switch(cdb0) { 292 if (opcode >= VENDOR_SPECIFIC_CDB)
268 case VARIABLE_LENGTH_CMD: 293 return false;
269 len = scsi_varlen_cdb_length(cdbp);
270 if (len < 10) {
271 printk("short variable length command, "
272 "len=%d ext_len=%d", len, cdb_len);
273 break;
274 }
275 sa = (cdbp[8] << 8) + cdbp[9];
276 name = get_sa_name(variable_length_arr, VARIABLE_LENGTH_SZ,
277 sa);
278 if (name)
279 printk("%s", name);
280 else
281 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
282 294
283 if ((cdb_len > 0) && (len != cdb_len)) 295 if (opcode < ARRAY_SIZE(cdb_byte0_names))
284 printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len); 296 *cdb_name = cdb_byte0_names[opcode];
285 297
286 break; 298 for (sa_name_ptr = sa_names_arr; sa_name_ptr->arr; ++sa_name_ptr) {
287 case MAINTENANCE_IN: 299 if (sa_name_ptr->opcode == opcode) {
288 sa = cdbp[1] & 0x1f; 300 arr = sa_name_ptr->arr;
289 name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa); 301 arr_sz = sa_name_ptr->arr_sz;
290 fin_name = 1; 302 break;
291 break; 303 }
292 case MAINTENANCE_OUT:
293 sa = cdbp[1] & 0x1f;
294 name = get_sa_name(maint_out_arr, MAINT_OUT_SZ, sa);
295 fin_name = 1;
296 break;
297 case PERSISTENT_RESERVE_IN:
298 sa = cdbp[1] & 0x1f;
299 name = get_sa_name(pr_in_arr, PR_IN_SZ, sa);
300 fin_name = 1;
301 break;
302 case PERSISTENT_RESERVE_OUT:
303 sa = cdbp[1] & 0x1f;
304 name = get_sa_name(pr_out_arr, PR_OUT_SZ, sa);
305 fin_name = 1;
306 break;
307 case SERVICE_ACTION_IN_12:
308 sa = cdbp[1] & 0x1f;
309 name = get_sa_name(serv_in12_arr, SERV_IN12_SZ, sa);
310 fin_name = 1;
311 break;
312 case SERVICE_ACTION_OUT_12:
313 sa = cdbp[1] & 0x1f;
314 name = get_sa_name(serv_out12_arr, SERV_OUT12_SZ, sa);
315 fin_name = 1;
316 break;
317 case SERVICE_ACTION_BIDIRECTIONAL:
318 sa = cdbp[1] & 0x1f;
319 name = get_sa_name(serv_bidi_arr, SERV_BIDI_SZ, sa);
320 fin_name = 1;
321 break;
322 case SERVICE_ACTION_IN_16:
323 sa = cdbp[1] & 0x1f;
324 name = get_sa_name(serv_in16_arr, SERV_IN16_SZ, sa);
325 fin_name = 1;
326 break;
327 case SERVICE_ACTION_OUT_16:
328 sa = cdbp[1] & 0x1f;
329 name = get_sa_name(serv_out16_arr, SERV_OUT16_SZ, sa);
330 fin_name = 1;
331 break;
332 case THIRD_PARTY_COPY_IN:
333 sa = cdbp[1] & 0x1f;
334 name = get_sa_name(tpc_in_arr, TPC_IN_SZ, sa);
335 fin_name = 1;
336 break;
337 case THIRD_PARTY_COPY_OUT:
338 sa = cdbp[1] & 0x1f;
339 name = get_sa_name(tpc_out_arr, TPC_OUT_SZ, sa);
340 fin_name = 1;
341 break;
342 default:
343 if (cdb0 < 0xc0) {
344 name = cdb_byte0_names[cdb0];
345 if (name)
346 printk("%s", name);
347 else
348 printk("cdb[0]=0x%x (reserved)", cdb0);
349 } else
350 printk("cdb[0]=0x%x (vendor)", cdb0);
351 break;
352 } 304 }
353 if (fin_name) { 305 if (!arr)
354 if (name) 306 return false;
355 printk("%s", name); 307
356 else 308 for (k = 0; k < arr_sz; ++k, ++arr) {
357 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa); 309 if (service_action == arr->value)
310 break;
358 } 311 }
359} 312 if (k < arr_sz)
313 *sa_name = arr->name;
360 314
361#else /* ifndef CONFIG_SCSI_CONSTANTS */ 315 return true;
316}
362 317
363static void print_opcode_name(unsigned char * cdbp, int cdb_len) 318static void print_opcode_name(const unsigned char *cdbp, size_t cdb_len)
364{ 319{
365 int sa, len, cdb0; 320 int sa, cdb0;
321 const char *cdb_name = NULL, *sa_name = NULL;
366 322
367 cdb0 = cdbp[0]; 323 cdb0 = cdbp[0];
368 switch(cdb0) { 324 if (cdb0 == VARIABLE_LENGTH_CMD) {
369 case VARIABLE_LENGTH_CMD: 325 if (cdb_len < 10) {
370 len = scsi_varlen_cdb_length(cdbp); 326 printk("short variable length command, len=%zu",
371 if (len < 10) { 327 cdb_len);
372 printk("short opcode=0x%x command, len=%d " 328 return;
373 "ext_len=%d", cdb0, len, cdb_len);
374 break;
375 } 329 }
376 sa = (cdbp[8] << 8) + cdbp[9]; 330 sa = (cdbp[8] << 8) + cdbp[9];
377 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa); 331 } else
378 if (len != cdb_len)
379 printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);
380 break;
381 case MAINTENANCE_IN:
382 case MAINTENANCE_OUT:
383 case PERSISTENT_RESERVE_IN:
384 case PERSISTENT_RESERVE_OUT:
385 case SERVICE_ACTION_IN_12:
386 case SERVICE_ACTION_OUT_12:
387 case SERVICE_ACTION_BIDIRECTIONAL:
388 case SERVICE_ACTION_IN_16:
389 case SERVICE_ACTION_OUT_16:
390 case THIRD_PARTY_COPY_IN:
391 case THIRD_PARTY_COPY_OUT:
392 sa = cdbp[1] & 0x1f; 332 sa = cdbp[1] & 0x1f;
393 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa); 333
394 break; 334 if (!scsi_opcode_sa_name(cdb0, sa, &cdb_name, &sa_name)) {
395 default: 335 if (cdb_name)
396 if (cdb0 < 0xc0) 336 printk("%s", cdb_name);
337 else if (cdb0 >= VENDOR_SPECIFIC_CDB)
338 printk("cdb[0]=0x%x (vendor)", cdb0);
339 else if (cdb0 >= 0x60 && cdb0 < 0x7e)
340 printk("cdb[0]=0x%x (reserved)", cdb0);
341 else
397 printk("cdb[0]=0x%x", cdb0); 342 printk("cdb[0]=0x%x", cdb0);
343 } else {
344 if (sa_name)
345 printk("%s", sa_name);
346 else if (cdb_name)
347 printk("%s, sa=0x%x", cdb_name, sa);
398 else 348 else
399 printk("cdb[0]=0x%x (vendor)", cdb0); 349 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
400 break;
401 } 350 }
402} 351}
403#endif
404 352
405void __scsi_print_command(unsigned char *cdb) 353void __scsi_print_command(const unsigned char *cdb, size_t cdb_len)
406{ 354{
407 int k, len; 355 int k, len;
408 356
409 print_opcode_name(cdb, 0); 357 print_opcode_name(cdb, cdb_len);
410 len = scsi_command_size(cdb); 358 len = scsi_command_size(cdb);
359 if (cdb_len < len)
360 len = cdb_len;
411 /* print out all bytes in cdb */ 361 /* print out all bytes in cdb */
412 for (k = 0; k < len; ++k) 362 for (k = 0; k < len; ++k)
413 printk(" %02x", cdb[k]); 363 printk(" %02x", cdb[k]);
@@ -433,41 +383,6 @@ void scsi_print_command(struct scsi_cmnd *cmd)
433} 383}
434EXPORT_SYMBOL(scsi_print_command); 384EXPORT_SYMBOL(scsi_print_command);
435 385
436/**
437 * scsi_print_status - print scsi status description
438 * @scsi_status: scsi status value
439 *
440 * If the status is recognized, the description is printed.
441 * Otherwise "Unknown status" is output. No trailing space.
442 * If CONFIG_SCSI_CONSTANTS is not set, then print status in hex
443 * (e.g. "0x2" for Check Condition).
444 **/
445void
446scsi_print_status(unsigned char scsi_status) {
447#ifdef CONFIG_SCSI_CONSTANTS
448 const char * ccp;
449
450 switch (scsi_status) {
451 case 0: ccp = "Good"; break;
452 case 0x2: ccp = "Check Condition"; break;
453 case 0x4: ccp = "Condition Met"; break;
454 case 0x8: ccp = "Busy"; break;
455 case 0x10: ccp = "Intermediate"; break;
456 case 0x14: ccp = "Intermediate-Condition Met"; break;
457 case 0x18: ccp = "Reservation Conflict"; break;
458 case 0x22: ccp = "Command Terminated"; break; /* obsolete */
459 case 0x28: ccp = "Task set Full"; break; /* was: Queue Full */
460 case 0x30: ccp = "ACA Active"; break;
461 case 0x40: ccp = "Task Aborted"; break;
462 default: ccp = "Unknown status";
463 }
464 printk(KERN_INFO "%s", ccp);
465#else
466 printk(KERN_INFO "0x%0x", scsi_status);
467#endif
468}
469EXPORT_SYMBOL(scsi_print_status);
470
471#ifdef CONFIG_SCSI_CONSTANTS 386#ifdef CONFIG_SCSI_CONSTANTS
472 387
473struct error_info { 388struct error_info {
@@ -1292,18 +1207,19 @@ static const struct error_info additional[] =
1292 1207
1293struct error_info2 { 1208struct error_info2 {
1294 unsigned char code1, code2_min, code2_max; 1209 unsigned char code1, code2_min, code2_max;
1210 const char * str;
1295 const char * fmt; 1211 const char * fmt;
1296}; 1212};
1297 1213
1298static const struct error_info2 additional2[] = 1214static const struct error_info2 additional2[] =
1299{ 1215{
1300 {0x40, 0x00, 0x7f, "Ram failure (%x)"}, 1216 {0x40, 0x00, 0x7f, "Ram failure", ""},
1301 {0x40, 0x80, 0xff, "Diagnostic failure on component (%x)"}, 1217 {0x40, 0x80, 0xff, "Diagnostic failure on component", ""},
1302 {0x41, 0x00, 0xff, "Data path failure (%x)"}, 1218 {0x41, 0x00, 0xff, "Data path failure", ""},
1303 {0x42, 0x00, 0xff, "Power-on or self-test failure (%x)"}, 1219 {0x42, 0x00, 0xff, "Power-on or self-test failure", ""},
1304 {0x4D, 0x00, 0xff, "Tagged overlapped commands (task tag %x)"}, 1220 {0x4D, 0x00, 0xff, "Tagged overlapped commands", "task tag "},
1305 {0x70, 0x00, 0xff, "Decompression exception short algorithm id of %x"}, 1221 {0x70, 0x00, 0xff, "Decompression exception", "short algorithm id of "},
1306 {0, 0, 0, NULL} 1222 {0, 0, 0, NULL, NULL}
1307}; 1223};
1308 1224
1309/* description of the sense key values */ 1225/* description of the sense key values */
@@ -1349,69 +1265,79 @@ EXPORT_SYMBOL(scsi_sense_key_string);
1349 * This string may contain a "%x" and should be printed with ascq as arg. 1265 * This string may contain a "%x" and should be printed with ascq as arg.
1350 */ 1266 */
1351const char * 1267const char *
1352scsi_extd_sense_format(unsigned char asc, unsigned char ascq) { 1268scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
1269{
1353#ifdef CONFIG_SCSI_CONSTANTS 1270#ifdef CONFIG_SCSI_CONSTANTS
1354 int i; 1271 int i;
1355 unsigned short code = ((asc << 8) | ascq); 1272 unsigned short code = ((asc << 8) | ascq);
1356 1273
1274 *fmt = NULL;
1357 for (i = 0; additional[i].text; i++) 1275 for (i = 0; additional[i].text; i++)
1358 if (additional[i].code12 == code) 1276 if (additional[i].code12 == code)
1359 return additional[i].text; 1277 return additional[i].text;
1360 for (i = 0; additional2[i].fmt; i++) { 1278 for (i = 0; additional2[i].fmt; i++) {
1361 if (additional2[i].code1 == asc && 1279 if (additional2[i].code1 == asc &&
1362 ascq >= additional2[i].code2_min && 1280 ascq >= additional2[i].code2_min &&
1363 ascq <= additional2[i].code2_max) 1281 ascq <= additional2[i].code2_max) {
1364 return additional2[i].fmt; 1282 *fmt = additional2[i].fmt;
1283 return additional2[i].str;
1284 }
1365 } 1285 }
1286#else
1287 *fmt = NULL;
1366#endif 1288#endif
1367 return NULL; 1289 return NULL;
1368} 1290}
1369EXPORT_SYMBOL(scsi_extd_sense_format); 1291EXPORT_SYMBOL(scsi_extd_sense_format);
1370 1292
1371void 1293void
1372scsi_show_extd_sense(unsigned char asc, unsigned char ascq) 1294scsi_show_extd_sense(const struct scsi_device *sdev, const char *name,
1295 unsigned char asc, unsigned char ascq)
1373{ 1296{
1374 const char *extd_sense_fmt = scsi_extd_sense_format(asc, ascq); 1297 const char *extd_sense_fmt = NULL;
1375 1298 const char *extd_sense_str = scsi_extd_sense_format(asc, ascq,
1376 if (extd_sense_fmt) { 1299 &extd_sense_fmt);
1377 if (strstr(extd_sense_fmt, "%x")) { 1300
1378 printk("Add. Sense: "); 1301 if (extd_sense_str) {
1379 printk(extd_sense_fmt, ascq); 1302 if (extd_sense_fmt)
1380 } else 1303 sdev_prefix_printk(KERN_INFO, sdev, name,
1381 printk("Add. Sense: %s", extd_sense_fmt); 1304 "Add. Sense: %s (%s%x)",
1382 } else { 1305 extd_sense_str, extd_sense_fmt,
1383 if (asc >= 0x80) 1306 ascq);
1384 printk("<<vendor>> ASC=0x%x ASCQ=0x%x", asc,
1385 ascq);
1386 if (ascq >= 0x80)
1387 printk("ASC=0x%x <<vendor>> ASCQ=0x%x", asc,
1388 ascq);
1389 else 1307 else
1390 printk("ASC=0x%x ASCQ=0x%x", asc, ascq); 1308 sdev_prefix_printk(KERN_INFO, sdev, name,
1391 } 1309 "Add. Sense: %s", extd_sense_str);
1392 1310
1393 printk("\n"); 1311 } else {
1312 sdev_prefix_printk(KERN_INFO, sdev, name,
1313 "%sASC=0x%x %sASCQ=0x%x\n",
1314 asc >= 0x80 ? "<<vendor>> " : "", asc,
1315 ascq >= 0x80 ? "<<vendor>> " : "", ascq);
1316 }
1394} 1317}
1395EXPORT_SYMBOL(scsi_show_extd_sense); 1318EXPORT_SYMBOL(scsi_show_extd_sense);
1396 1319
1397void 1320void
1398scsi_show_sense_hdr(struct scsi_sense_hdr *sshdr) 1321scsi_show_sense_hdr(const struct scsi_device *sdev, const char *name,
1322 const struct scsi_sense_hdr *sshdr)
1399{ 1323{
1400 const char *sense_txt; 1324 const char *sense_txt;
1401 1325
1402 sense_txt = scsi_sense_key_string(sshdr->sense_key); 1326 sense_txt = scsi_sense_key_string(sshdr->sense_key);
1403 if (sense_txt) 1327 if (sense_txt)
1404 printk("Sense Key : %s ", sense_txt); 1328 sdev_prefix_printk(KERN_INFO, sdev, name,
1329 "Sense Key : %s [%s]%s\n", sense_txt,
1330 scsi_sense_is_deferred(sshdr) ?
1331 "deferred" : "current",
1332 sshdr->response_code >= 0x72 ?
1333 " [descriptor]" : "");
1405 else 1334 else
1406 printk("Sense Key : 0x%x ", sshdr->sense_key); 1335 sdev_prefix_printk(KERN_INFO, sdev, name,
1407 1336 "Sense Key : 0x%x [%s]%s", sshdr->sense_key,
1408 printk("%s", scsi_sense_is_deferred(sshdr) ? "[deferred] " : 1337 scsi_sense_is_deferred(sshdr) ?
1409 "[current] "); 1338 "deferred" : "current",
1410 1339 sshdr->response_code >= 0x72 ?
1411 if (sshdr->response_code >= 0x72) 1340 " [descriptor]" : "");
1412 printk("[descriptor]");
1413
1414 printk("\n");
1415} 1341}
1416EXPORT_SYMBOL(scsi_show_sense_hdr); 1342EXPORT_SYMBOL(scsi_show_sense_hdr);
1417 1343
@@ -1419,141 +1345,55 @@ EXPORT_SYMBOL(scsi_show_sense_hdr);
1419 * Print normalized SCSI sense header with a prefix. 1345 * Print normalized SCSI sense header with a prefix.
1420 */ 1346 */
1421void 1347void
1422scsi_print_sense_hdr(const char *name, struct scsi_sense_hdr *sshdr) 1348scsi_print_sense_hdr(const struct scsi_device *sdev, const char *name,
1349 const struct scsi_sense_hdr *sshdr)
1423{ 1350{
1424 printk(KERN_INFO "%s: ", name); 1351 scsi_show_sense_hdr(sdev, name, sshdr);
1425 scsi_show_sense_hdr(sshdr); 1352 scsi_show_extd_sense(sdev, name, sshdr->asc, sshdr->ascq);
1426 printk(KERN_INFO "%s: ", name);
1427 scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1428} 1353}
1429EXPORT_SYMBOL(scsi_print_sense_hdr); 1354EXPORT_SYMBOL(scsi_print_sense_hdr);
1430 1355
1431/*
1432 * Print normalized SCSI sense header with device information and a prefix.
1433 */
1434void
1435scsi_cmd_print_sense_hdr(struct scsi_cmnd *scmd, const char *desc,
1436 struct scsi_sense_hdr *sshdr)
1437{
1438 scmd_printk(KERN_INFO, scmd, "%s: ", desc);
1439 scsi_show_sense_hdr(sshdr);
1440 scmd_printk(KERN_INFO, scmd, "%s: ", desc);
1441 scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1442}
1443EXPORT_SYMBOL(scsi_cmd_print_sense_hdr);
1444
1445static void 1356static void
1446scsi_decode_sense_buffer(const unsigned char *sense_buffer, int sense_len, 1357scsi_dump_sense_buffer(const unsigned char *sense_buffer, int sense_len)
1447 struct scsi_sense_hdr *sshdr)
1448{ 1358{
1449 int k, num, res; 1359 int k, num;
1450 1360
1451 res = scsi_normalize_sense(sense_buffer, sense_len, sshdr); 1361 num = (sense_len < 32) ? sense_len : 32;
1452 if (0 == res) { 1362 printk("Unrecognized sense data (in hex):");
1453 /* this may be SCSI-1 sense data */ 1363 for (k = 0; k < num; ++k) {
1454 num = (sense_len < 32) ? sense_len : 32; 1364 if (0 == (k % 16)) {
1455 printk("Unrecognized sense data (in hex):"); 1365 printk("\n");
1456 for (k = 0; k < num; ++k) { 1366 printk(KERN_INFO " ");
1457 if (0 == (k % 16)) {
1458 printk("\n");
1459 printk(KERN_INFO " ");
1460 }
1461 printk("%02x ", sense_buffer[k]);
1462 } 1367 }
1463 printk("\n"); 1368 printk("%02x ", sense_buffer[k]);
1464 return;
1465 } 1369 }
1466} 1370 printk("\n");
1467 1371 return;
1468static void
1469scsi_decode_sense_extras(const unsigned char *sense_buffer, int sense_len,
1470 struct scsi_sense_hdr *sshdr)
1471{
1472 int k, num, res;
1473
1474 if (sshdr->response_code < 0x72)
1475 {
1476 /* only decode extras for "fixed" format now */
1477 char buff[80];
1478 int blen, fixed_valid;
1479 unsigned int info;
1480
1481 fixed_valid = sense_buffer[0] & 0x80;
1482 info = ((sense_buffer[3] << 24) | (sense_buffer[4] << 16) |
1483 (sense_buffer[5] << 8) | sense_buffer[6]);
1484 res = 0;
1485 memset(buff, 0, sizeof(buff));
1486 blen = sizeof(buff) - 1;
1487 if (fixed_valid)
1488 res += snprintf(buff + res, blen - res,
1489 "Info fld=0x%x", info);
1490 if (sense_buffer[2] & 0x80) {
1491 /* current command has read a filemark */
1492 if (res > 0)
1493 res += snprintf(buff + res, blen - res, ", ");
1494 res += snprintf(buff + res, blen - res, "FMK");
1495 }
1496 if (sense_buffer[2] & 0x40) {
1497 /* end-of-medium condition exists */
1498 if (res > 0)
1499 res += snprintf(buff + res, blen - res, ", ");
1500 res += snprintf(buff + res, blen - res, "EOM");
1501 }
1502 if (sense_buffer[2] & 0x20) {
1503 /* incorrect block length requested */
1504 if (res > 0)
1505 res += snprintf(buff + res, blen - res, ", ");
1506 res += snprintf(buff + res, blen - res, "ILI");
1507 }
1508 if (res > 0)
1509 printk("%s\n", buff);
1510 } else if (sshdr->additional_length > 0) {
1511 /* descriptor format with sense descriptors */
1512 num = 8 + sshdr->additional_length;
1513 num = (sense_len < num) ? sense_len : num;
1514 printk("Descriptor sense data with sense descriptors "
1515 "(in hex):");
1516 for (k = 0; k < num; ++k) {
1517 if (0 == (k % 16)) {
1518 printk("\n");
1519 printk(KERN_INFO " ");
1520 }
1521 printk("%02x ", sense_buffer[k]);
1522 }
1523
1524 printk("\n");
1525 }
1526
1527} 1372}
1528 1373
1529/* Normalize and print sense buffer with name prefix */ 1374/* Normalize and print sense buffer with name prefix */
1530void __scsi_print_sense(const char *name, const unsigned char *sense_buffer, 1375void __scsi_print_sense(const struct scsi_device *sdev, const char *name,
1531 int sense_len) 1376 const unsigned char *sense_buffer, int sense_len)
1532{ 1377{
1533 struct scsi_sense_hdr sshdr; 1378 struct scsi_sense_hdr sshdr;
1534 1379
1535 printk(KERN_INFO "%s: ", name); 1380 if (!scsi_normalize_sense(sense_buffer, sense_len, &sshdr)) {
1536 scsi_decode_sense_buffer(sense_buffer, sense_len, &sshdr); 1381 scsi_dump_sense_buffer(sense_buffer, sense_len);
1537 scsi_show_sense_hdr(&sshdr); 1382 return;
1538 scsi_decode_sense_extras(sense_buffer, sense_len, &sshdr); 1383 }
1539 printk(KERN_INFO "%s: ", name); 1384 scsi_show_sense_hdr(sdev, name, &sshdr);
1540 scsi_show_extd_sense(sshdr.asc, sshdr.ascq); 1385 scsi_show_extd_sense(sdev, name, sshdr.asc, sshdr.ascq);
1541} 1386}
1542EXPORT_SYMBOL(__scsi_print_sense); 1387EXPORT_SYMBOL(__scsi_print_sense);
1543 1388
1544/* Normalize and print sense buffer in SCSI command */ 1389/* Normalize and print sense buffer in SCSI command */
1545void scsi_print_sense(char *name, struct scsi_cmnd *cmd) 1390void scsi_print_sense(const struct scsi_cmnd *cmd)
1546{ 1391{
1547 struct scsi_sense_hdr sshdr; 1392 struct gendisk *disk = cmd->request->rq_disk;
1393 const char *disk_name = disk ? disk->disk_name : NULL;
1548 1394
1549 scmd_printk(KERN_INFO, cmd, " "); 1395 __scsi_print_sense(cmd->device, disk_name, cmd->sense_buffer,
1550 scsi_decode_sense_buffer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, 1396 SCSI_SENSE_BUFFERSIZE);
1551 &sshdr);
1552 scsi_show_sense_hdr(&sshdr);
1553 scsi_decode_sense_extras(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE,
1554 &sshdr);
1555 scmd_printk(KERN_INFO, cmd, " ");
1556 scsi_show_extd_sense(sshdr.asc, sshdr.ascq);
1557} 1397}
1558EXPORT_SYMBOL(scsi_print_sense); 1398EXPORT_SYMBOL(scsi_print_sense);
1559 1399
@@ -1565,38 +1405,87 @@ static const char * const hostbyte_table[]={
1565"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE", 1405"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE",
1566"DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE", 1406"DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE",
1567"DID_NEXUS_FAILURE" }; 1407"DID_NEXUS_FAILURE" };
1568#define NUM_HOSTBYTE_STRS ARRAY_SIZE(hostbyte_table)
1569 1408
1570static const char * const driverbyte_table[]={ 1409static const char * const driverbyte_table[]={
1571"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR", 1410"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR",
1572"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"}; 1411"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
1573#define NUM_DRIVERBYTE_STRS ARRAY_SIZE(driverbyte_table)
1574 1412
1575void scsi_show_result(int result) 1413#endif
1414
1415const char *scsi_hostbyte_string(int result)
1576{ 1416{
1417 const char *hb_string = NULL;
1418#ifdef CONFIG_SCSI_CONSTANTS
1577 int hb = host_byte(result); 1419 int hb = host_byte(result);
1578 int db = driver_byte(result);
1579 1420
1580 printk("Result: hostbyte=%s driverbyte=%s\n", 1421 if (hb < ARRAY_SIZE(hostbyte_table))
1581 (hb < NUM_HOSTBYTE_STRS ? hostbyte_table[hb] : "invalid"), 1422 hb_string = hostbyte_table[hb];
1582 (db < NUM_DRIVERBYTE_STRS ? driverbyte_table[db] : "invalid")); 1423#endif
1424 return hb_string;
1583} 1425}
1426EXPORT_SYMBOL(scsi_hostbyte_string);
1584 1427
1585#else 1428const char *scsi_driverbyte_string(int result)
1586
1587void scsi_show_result(int result)
1588{ 1429{
1589 printk("Result: hostbyte=0x%02x driverbyte=0x%02x\n", 1430 const char *db_string = NULL;
1590 host_byte(result), driver_byte(result)); 1431#ifdef CONFIG_SCSI_CONSTANTS
1432 int db = driver_byte(result);
1433
1434 if (db < ARRAY_SIZE(driverbyte_table))
1435 db_string = driverbyte_table[db];
1436#endif
1437 return db_string;
1591} 1438}
1439EXPORT_SYMBOL(scsi_driverbyte_string);
1592 1440
1441#ifdef CONFIG_SCSI_CONSTANTS
1442#define scsi_mlreturn_name(result) { result, #result }
1443static const struct value_name_pair scsi_mlreturn_arr[] = {
1444 scsi_mlreturn_name(NEEDS_RETRY),
1445 scsi_mlreturn_name(SUCCESS),
1446 scsi_mlreturn_name(FAILED),
1447 scsi_mlreturn_name(QUEUED),
1448 scsi_mlreturn_name(SOFT_ERROR),
1449 scsi_mlreturn_name(ADD_TO_MLQUEUE),
1450 scsi_mlreturn_name(TIMEOUT_ERROR),
1451 scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED),
1452 scsi_mlreturn_name(FAST_IO_FAIL)
1453};
1593#endif 1454#endif
1594EXPORT_SYMBOL(scsi_show_result);
1595 1455
1456const char *scsi_mlreturn_string(int result)
1457{
1458#ifdef CONFIG_SCSI_CONSTANTS
1459 const struct value_name_pair *arr = scsi_mlreturn_arr;
1460 int k;
1596 1461
1597void scsi_print_result(struct scsi_cmnd *cmd) 1462 for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) {
1463 if (result == arr->value)
1464 return arr->name;
1465 }
1466#endif
1467 return NULL;
1468}
1469EXPORT_SYMBOL(scsi_mlreturn_string);
1470
1471void scsi_print_result(struct scsi_cmnd *cmd, const char *msg, int disposition)
1598{ 1472{
1599 scmd_printk(KERN_INFO, cmd, " "); 1473 const char *mlret_string = scsi_mlreturn_string(disposition);
1600 scsi_show_result(cmd->result); 1474 const char *hb_string = scsi_hostbyte_string(cmd->result);
1475 const char *db_string = scsi_driverbyte_string(cmd->result);
1476
1477 if (hb_string || db_string)
1478 scmd_printk(KERN_INFO, cmd,
1479 "%s%s Result: hostbyte=%s driverbyte=%s",
1480 msg ? msg : "",
1481 mlret_string ? mlret_string : "UNKNOWN",
1482 hb_string ? hb_string : "invalid",
1483 db_string ? db_string : "invalid");
1484 else
1485 scmd_printk(KERN_INFO, cmd,
1486 "%s%s Result: hostbyte=0x%02x driverbyte=0x%02x",
1487 msg ? msg : "",
1488 mlret_string ? mlret_string : "UNKNOWN",
1489 host_byte(cmd->result), driver_byte(cmd->result));
1601} 1490}
1602EXPORT_SYMBOL(scsi_print_result); 1491EXPORT_SYMBOL(scsi_print_result);
diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c
index 86103c8475d8..44a8cc51428f 100644
--- a/drivers/scsi/csiostor/csio_scsi.c
+++ b/drivers/scsi/csiostor/csio_scsi.c
@@ -152,28 +152,6 @@ csio_scsi_itnexus_loss_error(uint16_t error)
152 return 0; 152 return 0;
153} 153}
154 154
155static inline void
156csio_scsi_tag(struct scsi_cmnd *scmnd, uint8_t *tag, uint8_t hq,
157 uint8_t oq, uint8_t sq)
158{
159 char stag[2];
160
161 if (scsi_populate_tag_msg(scmnd, stag)) {
162 switch (stag[0]) {
163 case HEAD_OF_QUEUE_TAG:
164 *tag = hq;
165 break;
166 case ORDERED_QUEUE_TAG:
167 *tag = oq;
168 break;
169 default:
170 *tag = sq;
171 break;
172 }
173 } else
174 *tag = 0;
175}
176
177/* 155/*
178 * csio_scsi_fcp_cmnd - Frame the SCSI FCP command paylod. 156 * csio_scsi_fcp_cmnd - Frame the SCSI FCP command paylod.
179 * @req: IO req structure. 157 * @req: IO req structure.
@@ -192,11 +170,12 @@ csio_scsi_fcp_cmnd(struct csio_ioreq *req, void *addr)
192 int_to_scsilun(scmnd->device->lun, &fcp_cmnd->fc_lun); 170 int_to_scsilun(scmnd->device->lun, &fcp_cmnd->fc_lun);
193 fcp_cmnd->fc_tm_flags = 0; 171 fcp_cmnd->fc_tm_flags = 0;
194 fcp_cmnd->fc_cmdref = 0; 172 fcp_cmnd->fc_cmdref = 0;
195 fcp_cmnd->fc_pri_ta = 0;
196 173
197 memcpy(fcp_cmnd->fc_cdb, scmnd->cmnd, 16); 174 memcpy(fcp_cmnd->fc_cdb, scmnd->cmnd, 16);
198 csio_scsi_tag(scmnd, &fcp_cmnd->fc_pri_ta, 175 if (scmnd->flags & SCMD_TAGGED)
199 FCP_PTA_HEADQ, FCP_PTA_ORDERED, FCP_PTA_SIMPLE); 176 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
177 else
178 fcp_cmnd->fc_pri_ta = 0;
200 fcp_cmnd->fc_dl = cpu_to_be32(scsi_bufflen(scmnd)); 179 fcp_cmnd->fc_dl = cpu_to_be32(scsi_bufflen(scmnd));
201 180
202 if (req->nsge) 181 if (req->nsge)
@@ -2262,11 +2241,7 @@ csio_slave_alloc(struct scsi_device *sdev)
2262static int 2241static int
2263csio_slave_configure(struct scsi_device *sdev) 2242csio_slave_configure(struct scsi_device *sdev)
2264{ 2243{
2265 if (sdev->tagged_supported) 2244 scsi_adjust_queue_depth(sdev, csio_lun_qdepth);
2266 scsi_activate_tcq(sdev, csio_lun_qdepth);
2267 else
2268 scsi_deactivate_tcq(sdev, csio_lun_qdepth);
2269
2270 return 0; 2245 return 0;
2271} 2246}
2272 2247
@@ -2311,6 +2286,7 @@ struct scsi_host_template csio_fcoe_shost_template = {
2311 .use_clustering = ENABLE_CLUSTERING, 2286 .use_clustering = ENABLE_CLUSTERING,
2312 .shost_attrs = csio_fcoe_lport_attrs, 2287 .shost_attrs = csio_fcoe_lport_attrs,
2313 .max_sectors = CSIO_MAX_SECTOR_SIZE, 2288 .max_sectors = CSIO_MAX_SECTOR_SIZE,
2289 .use_blk_tags = 1,
2314}; 2290};
2315 2291
2316struct scsi_host_template csio_fcoe_shost_vport_template = { 2292struct scsi_host_template csio_fcoe_shost_vport_template = {
@@ -2330,6 +2306,7 @@ struct scsi_host_template csio_fcoe_shost_vport_template = {
2330 .use_clustering = ENABLE_CLUSTERING, 2306 .use_clustering = ENABLE_CLUSTERING,
2331 .shost_attrs = csio_fcoe_vport_attrs, 2307 .shost_attrs = csio_fcoe_vport_attrs,
2332 .max_sectors = CSIO_MAX_SECTOR_SIZE, 2308 .max_sectors = CSIO_MAX_SECTOR_SIZE,
2309 .use_blk_tags = 1,
2333}; 2310};
2334 2311
2335/* 2312/*
diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index 33e422e75835..1dba62c5cf6a 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -98,27 +98,51 @@ device_handler_match(struct scsi_device_handler *scsi_dh,
98static int scsi_dh_handler_attach(struct scsi_device *sdev, 98static int scsi_dh_handler_attach(struct scsi_device *sdev,
99 struct scsi_device_handler *scsi_dh) 99 struct scsi_device_handler *scsi_dh)
100{ 100{
101 int err = 0; 101 struct scsi_dh_data *d;
102 102
103 if (sdev->scsi_dh_data) { 103 if (sdev->scsi_dh_data) {
104 if (sdev->scsi_dh_data->scsi_dh != scsi_dh) 104 if (sdev->scsi_dh_data->scsi_dh != scsi_dh)
105 err = -EBUSY; 105 return -EBUSY;
106 else 106
107 kref_get(&sdev->scsi_dh_data->kref); 107 kref_get(&sdev->scsi_dh_data->kref);
108 } else if (scsi_dh->attach) { 108 return 0;
109 err = scsi_dh->attach(sdev);
110 if (!err) {
111 kref_init(&sdev->scsi_dh_data->kref);
112 sdev->scsi_dh_data->sdev = sdev;
113 }
114 } 109 }
115 return err; 110
111 if (!try_module_get(scsi_dh->module))
112 return -EINVAL;
113
114 d = scsi_dh->attach(sdev);
115 if (IS_ERR(d)) {
116 sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%ld)\n",
117 scsi_dh->name, PTR_ERR(d));
118 module_put(scsi_dh->module);
119 return PTR_ERR(d);
120 }
121
122 d->scsi_dh = scsi_dh;
123 kref_init(&d->kref);
124 d->sdev = sdev;
125
126 spin_lock_irq(sdev->request_queue->queue_lock);
127 sdev->scsi_dh_data = d;
128 spin_unlock_irq(sdev->request_queue->queue_lock);
129 return 0;
116} 130}
117 131
118static void __detach_handler (struct kref *kref) 132static void __detach_handler (struct kref *kref)
119{ 133{
120 struct scsi_dh_data *scsi_dh_data = container_of(kref, struct scsi_dh_data, kref); 134 struct scsi_dh_data *scsi_dh_data =
121 scsi_dh_data->scsi_dh->detach(scsi_dh_data->sdev); 135 container_of(kref, struct scsi_dh_data, kref);
136 struct scsi_device_handler *scsi_dh = scsi_dh_data->scsi_dh;
137 struct scsi_device *sdev = scsi_dh_data->sdev;
138
139 spin_lock_irq(sdev->request_queue->queue_lock);
140 sdev->scsi_dh_data = NULL;
141 spin_unlock_irq(sdev->request_queue->queue_lock);
142
143 scsi_dh->detach(sdev);
144 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", scsi_dh->name);
145 module_put(scsi_dh->module);
122} 146}
123 147
124/* 148/*
@@ -141,7 +165,7 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev,
141 if (!scsi_dh) 165 if (!scsi_dh)
142 scsi_dh = sdev->scsi_dh_data->scsi_dh; 166 scsi_dh = sdev->scsi_dh_data->scsi_dh;
143 167
144 if (scsi_dh && scsi_dh->detach) 168 if (scsi_dh)
145 kref_put(&sdev->scsi_dh_data->kref, __detach_handler); 169 kref_put(&sdev->scsi_dh_data->kref, __detach_handler);
146} 170}
147 171
@@ -330,6 +354,9 @@ int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)
330 if (get_device_handler(scsi_dh->name)) 354 if (get_device_handler(scsi_dh->name))
331 return -EBUSY; 355 return -EBUSY;
332 356
357 if (!scsi_dh->attach || !scsi_dh->detach)
358 return -EINVAL;
359
333 spin_lock(&list_lock); 360 spin_lock(&list_lock);
334 list_add(&scsi_dh->list, &scsi_dh_list); 361 list_add(&scsi_dh->list, &scsi_dh_list);
335 spin_unlock(&list_lock); 362 spin_unlock(&list_lock);
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index fd78bdc53528..854b568b9931 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -62,6 +62,7 @@
62#define ALUA_OPTIMIZE_STPG 1 62#define ALUA_OPTIMIZE_STPG 1
63 63
64struct alua_dh_data { 64struct alua_dh_data {
65 struct scsi_dh_data dh_data;
65 int group_id; 66 int group_id;
66 int rel_port; 67 int rel_port;
67 int tpgs; 68 int tpgs;
@@ -87,9 +88,7 @@ static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *);
87 88
88static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev) 89static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev)
89{ 90{
90 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 91 return container_of(sdev->scsi_dh_data, struct alua_dh_data, dh_data);
91 BUG_ON(scsi_dh_data == NULL);
92 return ((struct alua_dh_data *) scsi_dh_data->buf);
93} 92}
94 93
95static int realloc_buffer(struct alua_dh_data *h, unsigned len) 94static int realloc_buffer(struct alua_dh_data *h, unsigned len)
@@ -825,42 +824,18 @@ static bool alua_match(struct scsi_device *sdev)
825 return (scsi_device_tpgs(sdev) != 0); 824 return (scsi_device_tpgs(sdev) != 0);
826} 825}
827 826
828static int alua_bus_attach(struct scsi_device *sdev);
829static void alua_bus_detach(struct scsi_device *sdev);
830
831static struct scsi_device_handler alua_dh = {
832 .name = ALUA_DH_NAME,
833 .module = THIS_MODULE,
834 .attach = alua_bus_attach,
835 .detach = alua_bus_detach,
836 .prep_fn = alua_prep_fn,
837 .check_sense = alua_check_sense,
838 .activate = alua_activate,
839 .set_params = alua_set_params,
840 .match = alua_match,
841};
842
843/* 827/*
844 * alua_bus_attach - Attach device handler 828 * alua_bus_attach - Attach device handler
845 * @sdev: device to be attached to 829 * @sdev: device to be attached to
846 */ 830 */
847static int alua_bus_attach(struct scsi_device *sdev) 831static struct scsi_dh_data *alua_bus_attach(struct scsi_device *sdev)
848{ 832{
849 struct scsi_dh_data *scsi_dh_data;
850 struct alua_dh_data *h; 833 struct alua_dh_data *h;
851 unsigned long flags; 834 int err;
852 int err = SCSI_DH_OK;
853
854 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
855 + sizeof(*h) , GFP_KERNEL);
856 if (!scsi_dh_data) {
857 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
858 ALUA_DH_NAME);
859 return -ENOMEM;
860 }
861 835
862 scsi_dh_data->scsi_dh = &alua_dh; 836 h = kzalloc(sizeof(*h) , GFP_KERNEL);
863 h = (struct alua_dh_data *) scsi_dh_data->buf; 837 if (!h)
838 return ERR_PTR(-ENOMEM);
864 h->tpgs = TPGS_MODE_UNINITIALIZED; 839 h->tpgs = TPGS_MODE_UNINITIALIZED;
865 h->state = TPGS_STATE_OPTIMIZED; 840 h->state = TPGS_STATE_OPTIMIZED;
866 h->group_id = -1; 841 h->group_id = -1;
@@ -870,23 +845,14 @@ static int alua_bus_attach(struct scsi_device *sdev)
870 h->sdev = sdev; 845 h->sdev = sdev;
871 846
872 err = alua_initialize(sdev, h); 847 err = alua_initialize(sdev, h);
873 if ((err != SCSI_DH_OK) && (err != SCSI_DH_DEV_OFFLINED)) 848 if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
874 goto failed;
875
876 if (!try_module_get(THIS_MODULE))
877 goto failed; 849 goto failed;
878 850
879 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
880 sdev->scsi_dh_data = scsi_dh_data;
881 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
882 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME); 851 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME);
883 852 return &h->dh_data;
884 return 0;
885
886failed: 853failed:
887 kfree(scsi_dh_data); 854 kfree(h);
888 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", ALUA_DH_NAME); 855 return ERR_PTR(-EINVAL);
889 return -EINVAL;
890} 856}
891 857
892/* 858/*
@@ -895,23 +861,25 @@ failed:
895 */ 861 */
896static void alua_bus_detach(struct scsi_device *sdev) 862static void alua_bus_detach(struct scsi_device *sdev)
897{ 863{
898 struct scsi_dh_data *scsi_dh_data; 864 struct alua_dh_data *h = get_alua_data(sdev);
899 struct alua_dh_data *h;
900 unsigned long flags;
901
902 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
903 scsi_dh_data = sdev->scsi_dh_data;
904 sdev->scsi_dh_data = NULL;
905 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
906 865
907 h = (struct alua_dh_data *) scsi_dh_data->buf;
908 if (h->buff && h->inq != h->buff) 866 if (h->buff && h->inq != h->buff)
909 kfree(h->buff); 867 kfree(h->buff);
910 kfree(scsi_dh_data); 868 kfree(h);
911 module_put(THIS_MODULE);
912 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", ALUA_DH_NAME);
913} 869}
914 870
871static struct scsi_device_handler alua_dh = {
872 .name = ALUA_DH_NAME,
873 .module = THIS_MODULE,
874 .attach = alua_bus_attach,
875 .detach = alua_bus_detach,
876 .prep_fn = alua_prep_fn,
877 .check_sense = alua_check_sense,
878 .activate = alua_activate,
879 .set_params = alua_set_params,
880 .match = alua_match,
881};
882
915static int __init alua_init(void) 883static int __init alua_init(void)
916{ 884{
917 int r; 885 int r;
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c
index 84765384c47c..6ed1caadbc6a 100644
--- a/drivers/scsi/device_handler/scsi_dh_emc.c
+++ b/drivers/scsi/device_handler/scsi_dh_emc.c
@@ -72,6 +72,7 @@ static const char * lun_state[] =
72}; 72};
73 73
74struct clariion_dh_data { 74struct clariion_dh_data {
75 struct scsi_dh_data dh_data;
75 /* 76 /*
76 * Flags: 77 * Flags:
77 * CLARIION_SHORT_TRESPASS 78 * CLARIION_SHORT_TRESPASS
@@ -116,9 +117,8 @@ struct clariion_dh_data {
116static inline struct clariion_dh_data 117static inline struct clariion_dh_data
117 *get_clariion_data(struct scsi_device *sdev) 118 *get_clariion_data(struct scsi_device *sdev)
118{ 119{
119 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 120 return container_of(sdev->scsi_dh_data, struct clariion_dh_data,
120 BUG_ON(scsi_dh_data == NULL); 121 dh_data);
121 return ((struct clariion_dh_data *) scsi_dh_data->buf);
122} 122}
123 123
124/* 124/*
@@ -622,7 +622,10 @@ done:
622 return result; 622 return result;
623} 623}
624 624
625static const struct scsi_dh_devlist clariion_dev_list[] = { 625static const struct {
626 char *vendor;
627 char *model;
628} clariion_dev_list[] = {
626 {"DGC", "RAID"}, 629 {"DGC", "RAID"},
627 {"DGC", "DISK"}, 630 {"DGC", "DISK"},
628 {"DGC", "VRAID"}, 631 {"DGC", "VRAID"},
@@ -647,39 +650,14 @@ static bool clariion_match(struct scsi_device *sdev)
647 return false; 650 return false;
648} 651}
649 652
650static int clariion_bus_attach(struct scsi_device *sdev); 653static struct scsi_dh_data *clariion_bus_attach(struct scsi_device *sdev)
651static void clariion_bus_detach(struct scsi_device *sdev);
652
653static struct scsi_device_handler clariion_dh = {
654 .name = CLARIION_NAME,
655 .module = THIS_MODULE,
656 .devlist = clariion_dev_list,
657 .attach = clariion_bus_attach,
658 .detach = clariion_bus_detach,
659 .check_sense = clariion_check_sense,
660 .activate = clariion_activate,
661 .prep_fn = clariion_prep_fn,
662 .set_params = clariion_set_params,
663 .match = clariion_match,
664};
665
666static int clariion_bus_attach(struct scsi_device *sdev)
667{ 654{
668 struct scsi_dh_data *scsi_dh_data;
669 struct clariion_dh_data *h; 655 struct clariion_dh_data *h;
670 unsigned long flags;
671 int err; 656 int err;
672 657
673 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 658 h = kzalloc(sizeof(*h) , GFP_KERNEL);
674 + sizeof(*h) , GFP_KERNEL); 659 if (!h)
675 if (!scsi_dh_data) { 660 return ERR_PTR(-ENOMEM);
676 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
677 CLARIION_NAME);
678 return -ENOMEM;
679 }
680
681 scsi_dh_data->scsi_dh = &clariion_dh;
682 h = (struct clariion_dh_data *) scsi_dh_data->buf;
683 h->lun_state = CLARIION_LUN_UNINITIALIZED; 661 h->lun_state = CLARIION_LUN_UNINITIALIZED;
684 h->default_sp = CLARIION_UNBOUND_LU; 662 h->default_sp = CLARIION_UNBOUND_LU;
685 h->current_sp = CLARIION_UNBOUND_LU; 663 h->current_sp = CLARIION_UNBOUND_LU;
@@ -692,45 +670,37 @@ static int clariion_bus_attach(struct scsi_device *sdev)
692 if (err != SCSI_DH_OK) 670 if (err != SCSI_DH_OK)
693 goto failed; 671 goto failed;
694 672
695 if (!try_module_get(THIS_MODULE))
696 goto failed;
697
698 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
699 sdev->scsi_dh_data = scsi_dh_data;
700 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
701
702 sdev_printk(KERN_INFO, sdev, 673 sdev_printk(KERN_INFO, sdev,
703 "%s: connected to SP %c Port %d (%s, default SP %c)\n", 674 "%s: connected to SP %c Port %d (%s, default SP %c)\n",
704 CLARIION_NAME, h->current_sp + 'A', 675 CLARIION_NAME, h->current_sp + 'A',
705 h->port, lun_state[h->lun_state], 676 h->port, lun_state[h->lun_state],
706 h->default_sp + 'A'); 677 h->default_sp + 'A');
707 678 return &h->dh_data;
708 return 0;
709 679
710failed: 680failed:
711 kfree(scsi_dh_data); 681 kfree(h);
712 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 682 return ERR_PTR(-EINVAL);
713 CLARIION_NAME);
714 return -EINVAL;
715} 683}
716 684
717static void clariion_bus_detach(struct scsi_device *sdev) 685static void clariion_bus_detach(struct scsi_device *sdev)
718{ 686{
719 struct scsi_dh_data *scsi_dh_data; 687 struct clariion_dh_data *h = get_clariion_data(sdev);
720 unsigned long flags;
721
722 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
723 scsi_dh_data = sdev->scsi_dh_data;
724 sdev->scsi_dh_data = NULL;
725 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
726
727 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n",
728 CLARIION_NAME);
729 688
730 kfree(scsi_dh_data); 689 kfree(h);
731 module_put(THIS_MODULE);
732} 690}
733 691
692static struct scsi_device_handler clariion_dh = {
693 .name = CLARIION_NAME,
694 .module = THIS_MODULE,
695 .attach = clariion_bus_attach,
696 .detach = clariion_bus_detach,
697 .check_sense = clariion_check_sense,
698 .activate = clariion_activate,
699 .prep_fn = clariion_prep_fn,
700 .set_params = clariion_set_params,
701 .match = clariion_match,
702};
703
734static int __init clariion_init(void) 704static int __init clariion_init(void)
735{ 705{
736 int r; 706 int r;
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index 4ee2759f5299..485d99544a15 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -38,6 +38,7 @@
38#define HP_SW_PATH_PASSIVE 1 38#define HP_SW_PATH_PASSIVE 1
39 39
40struct hp_sw_dh_data { 40struct hp_sw_dh_data {
41 struct scsi_dh_data dh_data;
41 unsigned char sense[SCSI_SENSE_BUFFERSIZE]; 42 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
42 int path_state; 43 int path_state;
43 int retries; 44 int retries;
@@ -51,9 +52,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *);
51 52
52static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev) 53static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
53{ 54{
54 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 55 return container_of(sdev->scsi_dh_data, struct hp_sw_dh_data, dh_data);
55 BUG_ON(scsi_dh_data == NULL);
56 return ((struct hp_sw_dh_data *) scsi_dh_data->buf);
57} 56}
58 57
59/* 58/*
@@ -312,7 +311,10 @@ static int hp_sw_activate(struct scsi_device *sdev,
312 return 0; 311 return 0;
313} 312}
314 313
315static const struct scsi_dh_devlist hp_sw_dh_data_list[] = { 314static const struct {
315 char *vendor;
316 char *model;
317} hp_sw_dh_data_list[] = {
316 {"COMPAQ", "MSA1000 VOLUME"}, 318 {"COMPAQ", "MSA1000 VOLUME"},
317 {"COMPAQ", "HSV110"}, 319 {"COMPAQ", "HSV110"},
318 {"HP", "HSV100"}, 320 {"HP", "HSV100"},
@@ -338,37 +340,14 @@ static bool hp_sw_match(struct scsi_device *sdev)
338 return false; 340 return false;
339} 341}
340 342
341static int hp_sw_bus_attach(struct scsi_device *sdev); 343static struct scsi_dh_data *hp_sw_bus_attach(struct scsi_device *sdev)
342static void hp_sw_bus_detach(struct scsi_device *sdev);
343
344static struct scsi_device_handler hp_sw_dh = {
345 .name = HP_SW_NAME,
346 .module = THIS_MODULE,
347 .devlist = hp_sw_dh_data_list,
348 .attach = hp_sw_bus_attach,
349 .detach = hp_sw_bus_detach,
350 .activate = hp_sw_activate,
351 .prep_fn = hp_sw_prep_fn,
352 .match = hp_sw_match,
353};
354
355static int hp_sw_bus_attach(struct scsi_device *sdev)
356{ 344{
357 struct scsi_dh_data *scsi_dh_data;
358 struct hp_sw_dh_data *h; 345 struct hp_sw_dh_data *h;
359 unsigned long flags;
360 int ret; 346 int ret;
361 347
362 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 348 h = kzalloc(sizeof(*h), GFP_KERNEL);
363 + sizeof(*h) , GFP_KERNEL); 349 if (!h)
364 if (!scsi_dh_data) { 350 return ERR_PTR(-ENOMEM);
365 sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n",
366 HP_SW_NAME);
367 return 0;
368 }
369
370 scsi_dh_data->scsi_dh = &hp_sw_dh;
371 h = (struct hp_sw_dh_data *) scsi_dh_data->buf;
372 h->path_state = HP_SW_PATH_UNINITIALIZED; 351 h->path_state = HP_SW_PATH_UNINITIALIZED;
373 h->retries = HP_SW_RETRIES; 352 h->retries = HP_SW_RETRIES;
374 h->sdev = sdev; 353 h->sdev = sdev;
@@ -377,42 +356,32 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
377 if (ret != SCSI_DH_OK || h->path_state == HP_SW_PATH_UNINITIALIZED) 356 if (ret != SCSI_DH_OK || h->path_state == HP_SW_PATH_UNINITIALIZED)
378 goto failed; 357 goto failed;
379 358
380 if (!try_module_get(THIS_MODULE))
381 goto failed;
382
383 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
384 sdev->scsi_dh_data = scsi_dh_data;
385 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
386
387 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n", 359 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n",
388 HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE? 360 HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE?
389 "active":"passive"); 361 "active":"passive");
390 362 return &h->dh_data;
391 return 0;
392
393failed: 363failed:
394 kfree(scsi_dh_data); 364 kfree(h);
395 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 365 return ERR_PTR(-EINVAL);
396 HP_SW_NAME);
397 return -EINVAL;
398} 366}
399 367
400static void hp_sw_bus_detach( struct scsi_device *sdev ) 368static void hp_sw_bus_detach( struct scsi_device *sdev )
401{ 369{
402 struct scsi_dh_data *scsi_dh_data; 370 struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
403 unsigned long flags;
404
405 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
406 scsi_dh_data = sdev->scsi_dh_data;
407 sdev->scsi_dh_data = NULL;
408 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
409 module_put(THIS_MODULE);
410
411 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", HP_SW_NAME);
412 371
413 kfree(scsi_dh_data); 372 kfree(h);
414} 373}
415 374
375static struct scsi_device_handler hp_sw_dh = {
376 .name = HP_SW_NAME,
377 .module = THIS_MODULE,
378 .attach = hp_sw_bus_attach,
379 .detach = hp_sw_bus_detach,
380 .activate = hp_sw_activate,
381 .prep_fn = hp_sw_prep_fn,
382 .match = hp_sw_match,
383};
384
416static int __init hp_sw_init(void) 385static int __init hp_sw_init(void)
417{ 386{
418 return scsi_register_device_handler(&hp_sw_dh); 387 return scsi_register_device_handler(&hp_sw_dh);
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index 1b5bc9293e37..b46ace3d4bf0 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -181,6 +181,7 @@ struct c2_inquiry {
181}; 181};
182 182
183struct rdac_dh_data { 183struct rdac_dh_data {
184 struct scsi_dh_data dh_data;
184 struct rdac_controller *ctlr; 185 struct rdac_controller *ctlr;
185#define UNINITIALIZED_LUN (1 << 8) 186#define UNINITIALIZED_LUN (1 << 8)
186 unsigned lun; 187 unsigned lun;
@@ -261,9 +262,7 @@ do { \
261 262
262static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev) 263static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
263{ 264{
264 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 265 return container_of(sdev->scsi_dh_data, struct rdac_dh_data, dh_data);
265 BUG_ON(scsi_dh_data == NULL);
266 return ((struct rdac_dh_data *) scsi_dh_data->buf);
267} 266}
268 267
269static struct request *get_rdac_req(struct scsi_device *sdev, 268static struct request *get_rdac_req(struct scsi_device *sdev,
@@ -779,7 +778,10 @@ static int rdac_check_sense(struct scsi_device *sdev,
779 return SCSI_RETURN_NOT_HANDLED; 778 return SCSI_RETURN_NOT_HANDLED;
780} 779}
781 780
782static const struct scsi_dh_devlist rdac_dev_list[] = { 781static const struct {
782 char *vendor;
783 char *model;
784} rdac_dev_list[] = {
783 {"IBM", "1722"}, 785 {"IBM", "1722"},
784 {"IBM", "1724"}, 786 {"IBM", "1724"},
785 {"IBM", "1726"}, 787 {"IBM", "1726"},
@@ -825,40 +827,16 @@ static bool rdac_match(struct scsi_device *sdev)
825 return false; 827 return false;
826} 828}
827 829
828static int rdac_bus_attach(struct scsi_device *sdev); 830static struct scsi_dh_data *rdac_bus_attach(struct scsi_device *sdev)
829static void rdac_bus_detach(struct scsi_device *sdev);
830
831static struct scsi_device_handler rdac_dh = {
832 .name = RDAC_NAME,
833 .module = THIS_MODULE,
834 .devlist = rdac_dev_list,
835 .prep_fn = rdac_prep_fn,
836 .check_sense = rdac_check_sense,
837 .attach = rdac_bus_attach,
838 .detach = rdac_bus_detach,
839 .activate = rdac_activate,
840 .match = rdac_match,
841};
842
843static int rdac_bus_attach(struct scsi_device *sdev)
844{ 831{
845 struct scsi_dh_data *scsi_dh_data;
846 struct rdac_dh_data *h; 832 struct rdac_dh_data *h;
847 unsigned long flags;
848 int err; 833 int err;
849 char array_name[ARRAY_LABEL_LEN]; 834 char array_name[ARRAY_LABEL_LEN];
850 char array_id[UNIQUE_ID_LEN]; 835 char array_id[UNIQUE_ID_LEN];
851 836
852 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 837 h = kzalloc(sizeof(*h) , GFP_KERNEL);
853 + sizeof(*h) , GFP_KERNEL); 838 if (!h)
854 if (!scsi_dh_data) { 839 return ERR_PTR(-ENOMEM);
855 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
856 RDAC_NAME);
857 return -ENOMEM;
858 }
859
860 scsi_dh_data->scsi_dh = &rdac_dh;
861 h = (struct rdac_dh_data *) scsi_dh_data->buf;
862 h->lun = UNINITIALIZED_LUN; 840 h->lun = UNINITIALIZED_LUN;
863 h->state = RDAC_STATE_ACTIVE; 841 h->state = RDAC_STATE_ACTIVE;
864 842
@@ -878,19 +856,12 @@ static int rdac_bus_attach(struct scsi_device *sdev)
878 if (err != SCSI_DH_OK) 856 if (err != SCSI_DH_OK)
879 goto clean_ctlr; 857 goto clean_ctlr;
880 858
881 if (!try_module_get(THIS_MODULE))
882 goto clean_ctlr;
883
884 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
885 sdev->scsi_dh_data = scsi_dh_data;
886 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
887
888 sdev_printk(KERN_NOTICE, sdev, 859 sdev_printk(KERN_NOTICE, sdev,
889 "%s: LUN %d (%s) (%s)\n", 860 "%s: LUN %d (%s) (%s)\n",
890 RDAC_NAME, h->lun, mode[(int)h->mode], 861 RDAC_NAME, h->lun, mode[(int)h->mode],
891 lun_state[(int)h->lun_state]); 862 lun_state[(int)h->lun_state]);
892 863
893 return 0; 864 return &h->dh_data;
894 865
895clean_ctlr: 866clean_ctlr:
896 spin_lock(&list_lock); 867 spin_lock(&list_lock);
@@ -898,37 +869,34 @@ clean_ctlr:
898 spin_unlock(&list_lock); 869 spin_unlock(&list_lock);
899 870
900failed: 871failed:
901 kfree(scsi_dh_data); 872 kfree(h);
902 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 873 return ERR_PTR(-EINVAL);
903 RDAC_NAME);
904 return -EINVAL;
905} 874}
906 875
907static void rdac_bus_detach( struct scsi_device *sdev ) 876static void rdac_bus_detach( struct scsi_device *sdev )
908{ 877{
909 struct scsi_dh_data *scsi_dh_data; 878 struct rdac_dh_data *h = get_rdac_data(sdev);
910 struct rdac_dh_data *h;
911 unsigned long flags;
912 879
913 scsi_dh_data = sdev->scsi_dh_data;
914 h = (struct rdac_dh_data *) scsi_dh_data->buf;
915 if (h->ctlr && h->ctlr->ms_queued) 880 if (h->ctlr && h->ctlr->ms_queued)
916 flush_workqueue(kmpath_rdacd); 881 flush_workqueue(kmpath_rdacd);
917 882
918 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
919 sdev->scsi_dh_data = NULL;
920 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
921
922 spin_lock(&list_lock); 883 spin_lock(&list_lock);
923 if (h->ctlr) 884 if (h->ctlr)
924 kref_put(&h->ctlr->kref, release_controller); 885 kref_put(&h->ctlr->kref, release_controller);
925 spin_unlock(&list_lock); 886 spin_unlock(&list_lock);
926 kfree(scsi_dh_data); 887 kfree(h);
927 module_put(THIS_MODULE);
928 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
929} 888}
930 889
931 890static struct scsi_device_handler rdac_dh = {
891 .name = RDAC_NAME,
892 .module = THIS_MODULE,
893 .prep_fn = rdac_prep_fn,
894 .check_sense = rdac_check_sense,
895 .attach = rdac_bus_attach,
896 .detach = rdac_bus_detach,
897 .activate = rdac_activate,
898 .match = rdac_match,
899};
932 900
933static int __init rdac_init(void) 901static int __init rdac_init(void)
934{ 902{
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 072f0ec2851e..1af8d54bcded 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -415,10 +415,8 @@ static int adpt_slave_configure(struct scsi_device * device)
415 pHba = (adpt_hba *) host->hostdata[0]; 415 pHba = (adpt_hba *) host->hostdata[0];
416 416
417 if (host->can_queue && device->tagged_supported) { 417 if (host->can_queue && device->tagged_supported) {
418 scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG, 418 scsi_adjust_queue_depth(device,
419 host->can_queue - 1); 419 host->can_queue - 1);
420 } else {
421 scsi_adjust_queue_depth(device, 0, 1);
422 } 420 }
423 return 0; 421 return 0;
424} 422}
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index 943ad3a19661..bc0f918f1729 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -946,20 +946,18 @@ static int eata2x_slave_configure(struct scsi_device *dev)
946 946
947 if (TLDEV(dev->type) && dev->tagged_supported) { 947 if (TLDEV(dev->type) && dev->tagged_supported) {
948 if (tag_mode == TAG_SIMPLE) { 948 if (tag_mode == TAG_SIMPLE) {
949 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, tqd);
950 tag_suffix = ", simple tags"; 949 tag_suffix = ", simple tags";
951 } else if (tag_mode == TAG_ORDERED) { 950 } else if (tag_mode == TAG_ORDERED) {
952 scsi_adjust_queue_depth(dev, MSG_ORDERED_TAG, tqd);
953 tag_suffix = ", ordered tags"; 951 tag_suffix = ", ordered tags";
954 } else { 952 } else {
955 scsi_adjust_queue_depth(dev, 0, tqd);
956 tag_suffix = ", no tags"; 953 tag_suffix = ", no tags";
957 } 954 }
955 scsi_adjust_queue_depth(dev, tqd);
958 } else if (TLDEV(dev->type) && linked_comm) { 956 } else if (TLDEV(dev->type) && linked_comm) {
959 scsi_adjust_queue_depth(dev, 0, tqd); 957 scsi_adjust_queue_depth(dev, tqd);
960 tag_suffix = ", untagged"; 958 tag_suffix = ", untagged";
961 } else { 959 } else {
962 scsi_adjust_queue_depth(dev, 0, utqd); 960 scsi_adjust_queue_depth(dev, utqd);
963 tag_suffix = ""; 961 tag_suffix = "";
964 } 962 }
965 963
diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index 3fd305d6b67d..1941d837f6f2 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -972,11 +972,7 @@ u8 handle_hba_ioctl(struct esas2r_adapter *a,
972 struct atto_ioctl *ioctl_hba); 972 struct atto_ioctl *ioctl_hba);
973int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd); 973int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd);
974int esas2r_show_info(struct seq_file *m, struct Scsi_Host *sh); 974int esas2r_show_info(struct seq_file *m, struct Scsi_Host *sh);
975int esas2r_slave_alloc(struct scsi_device *dev);
976int esas2r_slave_configure(struct scsi_device *dev);
977void esas2r_slave_destroy(struct scsi_device *dev);
978int esas2r_change_queue_depth(struct scsi_device *dev, int depth, int reason); 975int esas2r_change_queue_depth(struct scsi_device *dev, int depth, int reason);
979int esas2r_change_queue_type(struct scsi_device *dev, int type);
980long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg); 976long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
981 977
982/* SCSI error handler (eh) functions */ 978/* SCSI error handler (eh) functions */
diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c
index 6504a195c874..30fce64faf75 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -254,12 +254,10 @@ static struct scsi_host_template driver_template = {
254 .use_clustering = ENABLE_CLUSTERING, 254 .use_clustering = ENABLE_CLUSTERING,
255 .emulated = 0, 255 .emulated = 0,
256 .proc_name = ESAS2R_DRVR_NAME, 256 .proc_name = ESAS2R_DRVR_NAME,
257 .slave_configure = esas2r_slave_configure,
258 .slave_alloc = esas2r_slave_alloc,
259 .slave_destroy = esas2r_slave_destroy,
260 .change_queue_depth = esas2r_change_queue_depth, 257 .change_queue_depth = esas2r_change_queue_depth,
261 .change_queue_type = esas2r_change_queue_type, 258 .change_queue_type = scsi_change_queue_type,
262 .max_sectors = 0xFFFF, 259 .max_sectors = 0xFFFF,
260 .use_blk_tags = 1,
263}; 261};
264 262
265int sgl_page_size = 512; 263int sgl_page_size = 512;
@@ -1057,7 +1055,7 @@ int esas2r_eh_abort(struct scsi_cmnd *cmd)
1057 1055
1058 cmd->scsi_done(cmd); 1056 cmd->scsi_done(cmd);
1059 1057
1060 return 0; 1058 return SUCCESS;
1061 } 1059 }
1062 1060
1063 spin_lock_irqsave(&a->queue_lock, flags); 1061 spin_lock_irqsave(&a->queue_lock, flags);
@@ -1263,56 +1261,11 @@ int esas2r_change_queue_depth(struct scsi_device *dev, int depth, int reason)
1263{ 1261{
1264 esas2r_log(ESAS2R_LOG_INFO, "change_queue_depth %p, %d", dev, depth); 1262 esas2r_log(ESAS2R_LOG_INFO, "change_queue_depth %p, %d", dev, depth);
1265 1263
1266 scsi_adjust_queue_depth(dev, scsi_get_tag_type(dev), depth); 1264 scsi_adjust_queue_depth(dev, depth);
1267 1265
1268 return dev->queue_depth; 1266 return dev->queue_depth;
1269} 1267}
1270 1268
1271int esas2r_change_queue_type(struct scsi_device *dev, int type)
1272{
1273 esas2r_log(ESAS2R_LOG_INFO, "change_queue_type %p, %d", dev, type);
1274
1275 if (dev->tagged_supported) {
1276 scsi_set_tag_type(dev, type);
1277
1278 if (type)
1279 scsi_activate_tcq(dev, dev->queue_depth);
1280 else
1281 scsi_deactivate_tcq(dev, dev->queue_depth);
1282 } else {
1283 type = 0;
1284 }
1285
1286 return type;
1287}
1288
1289int esas2r_slave_alloc(struct scsi_device *dev)
1290{
1291 return 0;
1292}
1293
1294int esas2r_slave_configure(struct scsi_device *dev)
1295{
1296 esas2r_log_dev(ESAS2R_LOG_INFO, &(dev->sdev_gendev),
1297 "esas2r_slave_configure()");
1298
1299 if (dev->tagged_supported) {
1300 scsi_set_tag_type(dev, MSG_SIMPLE_TAG);
1301 scsi_activate_tcq(dev, cmd_per_lun);
1302 } else {
1303 scsi_set_tag_type(dev, 0);
1304 scsi_deactivate_tcq(dev, cmd_per_lun);
1305 }
1306
1307 return 0;
1308}
1309
1310void esas2r_slave_destroy(struct scsi_device *dev)
1311{
1312 esas2r_log_dev(ESAS2R_LOG_INFO, &(dev->sdev_gendev),
1313 "esas2r_slave_destroy()");
1314}
1315
1316void esas2r_log_request_failure(struct esas2r_adapter *a, 1269void esas2r_log_request_failure(struct esas2r_adapter *a,
1317 struct esas2r_request *rq) 1270 struct esas2r_request *rq)
1318{ 1271{
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 55548dc5cec3..38c23e0b73af 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -663,7 +663,7 @@ static struct esp_cmd_entry *find_and_prep_issuable_command(struct esp *esp)
663 return ent; 663 return ent;
664 } 664 }
665 665
666 if (!scsi_populate_tag_msg(cmd, &ent->tag[0])) { 666 if (!spi_populate_tag_msg(&ent->tag[0], cmd)) {
667 ent->tag[0] = 0; 667 ent->tag[0] = 0;
668 ent->tag[1] = 0; 668 ent->tag[1] = 0;
669 } 669 }
@@ -2402,28 +2402,14 @@ static int esp_slave_configure(struct scsi_device *dev)
2402{ 2402{
2403 struct esp *esp = shost_priv(dev->host); 2403 struct esp *esp = shost_priv(dev->host);
2404 struct esp_target_data *tp = &esp->target[dev->id]; 2404 struct esp_target_data *tp = &esp->target[dev->id];
2405 int goal_tags, queue_depth;
2406
2407 goal_tags = 0;
2408 2405
2409 if (dev->tagged_supported) { 2406 if (dev->tagged_supported) {
2410 /* XXX make this configurable somehow XXX */ 2407 /* XXX make this configurable somehow XXX */
2411 goal_tags = ESP_DEFAULT_TAGS; 2408 int goal_tags = min(ESP_DEFAULT_TAGS, ESP_MAX_TAG);
2412 2409
2413 if (goal_tags > ESP_MAX_TAG) 2410 scsi_adjust_queue_depth(dev, goal_tags);
2414 goal_tags = ESP_MAX_TAG;
2415 } 2411 }
2416 2412
2417 queue_depth = goal_tags;
2418 if (queue_depth < dev->host->cmd_per_lun)
2419 queue_depth = dev->host->cmd_per_lun;
2420
2421 if (goal_tags) {
2422 scsi_set_tag_type(dev, MSG_ORDERED_TAG);
2423 scsi_activate_tcq(dev, queue_depth);
2424 } else {
2425 scsi_deactivate_tcq(dev, queue_depth);
2426 }
2427 tp->flags |= ESP_TGT_DISCONNECT; 2413 tp->flags |= ESP_TGT_DISCONNECT;
2428 2414
2429 if (!spi_initial_dv(dev->sdev_target)) 2415 if (!spi_initial_dv(dev->sdev_target))
@@ -2631,6 +2617,7 @@ struct scsi_host_template scsi_esp_template = {
2631 .use_clustering = ENABLE_CLUSTERING, 2617 .use_clustering = ENABLE_CLUSTERING,
2632 .max_sectors = 0xffff, 2618 .max_sectors = 0xffff,
2633 .skip_settle_delay = 1, 2619 .skip_settle_delay = 1,
2620 .use_blk_tags = 1,
2634}; 2621};
2635EXPORT_SYMBOL(scsi_esp_template); 2622EXPORT_SYMBOL(scsi_esp_template);
2636 2623
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 4a8ac7d8c76b..a3eeb6842499 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -281,13 +281,14 @@ static struct scsi_host_template fcoe_shost_template = {
281 .eh_host_reset_handler = fc_eh_host_reset, 281 .eh_host_reset_handler = fc_eh_host_reset,
282 .slave_alloc = fc_slave_alloc, 282 .slave_alloc = fc_slave_alloc,
283 .change_queue_depth = fc_change_queue_depth, 283 .change_queue_depth = fc_change_queue_depth,
284 .change_queue_type = fc_change_queue_type, 284 .change_queue_type = scsi_change_queue_type,
285 .this_id = -1, 285 .this_id = -1,
286 .cmd_per_lun = 3, 286 .cmd_per_lun = 3,
287 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS, 287 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
288 .use_clustering = ENABLE_CLUSTERING, 288 .use_clustering = ENABLE_CLUSTERING,
289 .sg_tablesize = SG_ALL, 289 .sg_tablesize = SG_ALL,
290 .max_sectors = 0xffff, 290 .max_sectors = 0xffff,
291 .use_blk_tags = 1,
291}; 292};
292 293
293/** 294/**
diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
index 8c56fdc3a456..cf1560c30b7f 100644
--- a/drivers/scsi/fnic/fnic_main.c
+++ b/drivers/scsi/fnic/fnic_main.c
@@ -95,12 +95,10 @@ static int fnic_slave_alloc(struct scsi_device *sdev)
95{ 95{
96 struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); 96 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
97 97
98 sdev->tagged_supported = 1;
99
100 if (!rport || fc_remote_port_chkready(rport)) 98 if (!rport || fc_remote_port_chkready(rport))
101 return -ENXIO; 99 return -ENXIO;
102 100
103 scsi_activate_tcq(sdev, fnic_max_qdepth); 101 scsi_adjust_queue_depth(sdev, fnic_max_qdepth);
104 return 0; 102 return 0;
105} 103}
106 104
@@ -113,7 +111,7 @@ static struct scsi_host_template fnic_host_template = {
113 .eh_host_reset_handler = fnic_host_reset, 111 .eh_host_reset_handler = fnic_host_reset,
114 .slave_alloc = fnic_slave_alloc, 112 .slave_alloc = fnic_slave_alloc,
115 .change_queue_depth = fc_change_queue_depth, 113 .change_queue_depth = fc_change_queue_depth,
116 .change_queue_type = fc_change_queue_type, 114 .change_queue_type = scsi_change_queue_type,
117 .this_id = -1, 115 .this_id = -1,
118 .cmd_per_lun = 3, 116 .cmd_per_lun = 3,
119 .can_queue = FNIC_DFLT_IO_REQ, 117 .can_queue = FNIC_DFLT_IO_REQ,
@@ -121,6 +119,7 @@ static struct scsi_host_template fnic_host_template = {
121 .sg_tablesize = FNIC_MAX_SG_DESC_CNT, 119 .sg_tablesize = FNIC_MAX_SG_DESC_CNT,
122 .max_sectors = 0xffff, 120 .max_sectors = 0xffff,
123 .shost_attrs = fnic_attrs, 121 .shost_attrs = fnic_attrs,
122 .use_blk_tags = 1,
124}; 123};
125 124
126static void 125static void
diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index 961bdf5d31cd..10d5c6bbc9e7 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -325,13 +325,11 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
325 struct fc_rport_libfc_priv *rp = rport->dd_data; 325 struct fc_rport_libfc_priv *rp = rport->dd_data;
326 struct host_sg_desc *desc; 326 struct host_sg_desc *desc;
327 struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; 327 struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats;
328 u8 pri_tag = 0;
329 unsigned int i; 328 unsigned int i;
330 unsigned long intr_flags; 329 unsigned long intr_flags;
331 int flags; 330 int flags;
332 u8 exch_flags; 331 u8 exch_flags;
333 struct scsi_lun fc_lun; 332 struct scsi_lun fc_lun;
334 char msg[2];
335 333
336 if (sg_count) { 334 if (sg_count) {
337 /* For each SGE, create a device desc entry */ 335 /* For each SGE, create a device desc entry */
@@ -357,12 +355,6 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
357 355
358 int_to_scsilun(sc->device->lun, &fc_lun); 356 int_to_scsilun(sc->device->lun, &fc_lun);
359 357
360 pri_tag = FCPIO_ICMND_PTA_SIMPLE;
361 msg[0] = MSG_SIMPLE_TAG;
362 scsi_populate_tag_msg(sc, msg);
363 if (msg[0] == MSG_ORDERED_TAG)
364 pri_tag = FCPIO_ICMND_PTA_ORDERED;
365
366 /* Enqueue the descriptor in the Copy WQ */ 358 /* Enqueue the descriptor in the Copy WQ */
367 spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags); 359 spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags);
368 360
@@ -394,7 +386,8 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
394 io_req->sgl_list_pa, 386 io_req->sgl_list_pa,
395 io_req->sense_buf_pa, 387 io_req->sense_buf_pa,
396 0, /* scsi cmd ref, always 0 */ 388 0, /* scsi cmd ref, always 0 */
397 pri_tag, /* scsi pri and tag */ 389 FCPIO_ICMND_PTA_SIMPLE,
390 /* scsi pri and tag */
398 flags, /* command flags */ 391 flags, /* command flags */
399 sc->cmnd, sc->cmd_len, 392 sc->cmnd, sc->cmd_len,
400 scsi_bufflen(sc), 393 scsi_bufflen(sc),
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 0f1ae13ce7c7..71e138044379 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -2159,7 +2159,7 @@ static void gdth_next(gdth_ha_str *ha)
2159 case VERIFY: 2159 case VERIFY:
2160 case START_STOP: 2160 case START_STOP:
2161 case MODE_SENSE: 2161 case MODE_SENSE:
2162 case SERVICE_ACTION_IN: 2162 case SERVICE_ACTION_IN_16:
2163 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0], 2163 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2164 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], 2164 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2165 nscp->cmnd[4],nscp->cmnd[5])); 2165 nscp->cmnd[4],nscp->cmnd[5]));
@@ -2391,7 +2391,7 @@ static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2391 gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data)); 2391 gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data));
2392 break; 2392 break;
2393 2393
2394 case SERVICE_ACTION_IN: 2394 case SERVICE_ACTION_IN_16:
2395 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 && 2395 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2396 (ha->cache_feat & GDT_64BIT)) { 2396 (ha->cache_feat & GDT_64BIT)) {
2397 gdth_rdcap16_data rdc16; 2397 gdth_rdcap16_data rdc16;
@@ -4661,7 +4661,6 @@ static void gdth_flush(gdth_ha_str *ha)
4661/* configure lun */ 4661/* configure lun */
4662static int gdth_slave_configure(struct scsi_device *sdev) 4662static int gdth_slave_configure(struct scsi_device *sdev)
4663{ 4663{
4664 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4665 sdev->skip_ms_page_3f = 1; 4664 sdev->skip_ms_page_3f = 1;
4666 sdev->skip_ms_page_8 = 1; 4665 sdev->skip_ms_page_8 = 1;
4667 return 0; 4666 return 0;
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 6de80e352871..8bb173e01084 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -418,7 +418,6 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
418 shost->cmd_per_lun = sht->cmd_per_lun; 418 shost->cmd_per_lun = sht->cmd_per_lun;
419 shost->unchecked_isa_dma = sht->unchecked_isa_dma; 419 shost->unchecked_isa_dma = sht->unchecked_isa_dma;
420 shost->use_clustering = sht->use_clustering; 420 shost->use_clustering = sht->use_clustering;
421 shost->ordered_tag = sht->ordered_tag;
422 shost->no_write_same = sht->no_write_same; 421 shost->no_write_same = sht->no_write_same;
423 422
424 if (shost_eh_deadline == -1 || !sht->eh_host_reset_handler) 423 if (shost_eh_deadline == -1 || !sht->eh_host_reset_handler)
@@ -485,8 +484,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
485 WQ_UNBOUND | WQ_MEM_RECLAIM, 484 WQ_UNBOUND | WQ_MEM_RECLAIM,
486 1, shost->host_no); 485 1, shost->host_no);
487 if (!shost->tmf_work_q) { 486 if (!shost->tmf_work_q) {
488 printk(KERN_WARNING "scsi%d: failed to create tmf workq\n", 487 shost_printk(KERN_WARNING, shost,
489 shost->host_no); 488 "failed to create tmf workq\n");
490 goto fail_kthread; 489 goto fail_kthread;
491 } 490 }
492 scsi_proc_hostdir_add(shost->hostt); 491 scsi_proc_hostdir_add(shost->hostt);
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index cef5d49b59cd..18ea2e16e34f 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -4165,7 +4165,7 @@ static int hpsa_change_queue_depth(struct scsi_device *sdev,
4165 else 4165 else
4166 if (qdepth > h->nr_cmds) 4166 if (qdepth > h->nr_cmds)
4167 qdepth = h->nr_cmds; 4167 qdepth = h->nr_cmds;
4168 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 4168 scsi_adjust_queue_depth(sdev, qdepth);
4169 return sdev->queue_depth; 4169 return sdev->queue_depth;
4170} 4170}
4171 4171
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index dedb62c21b29..151893148abd 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -1127,7 +1127,7 @@ static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
1127 1127
1128 if (queue_depth > hba->max_requests) 1128 if (queue_depth > hba->max_requests)
1129 queue_depth = hba->max_requests; 1129 queue_depth = hba->max_requests;
1130 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); 1130 scsi_adjust_queue_depth(sdev, queue_depth);
1131 return queue_depth; 1131 return queue_depth;
1132} 1132}
1133 1133
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 598c42cba5a8..147b80e07b00 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1643,19 +1643,9 @@ static int ibmvfc_queuecommand_lck(struct scsi_cmnd *cmnd,
1643 int_to_scsilun(cmnd->device->lun, &vfc_cmd->iu.lun); 1643 int_to_scsilun(cmnd->device->lun, &vfc_cmd->iu.lun);
1644 memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len); 1644 memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len);
1645 1645
1646 if (scsi_populate_tag_msg(cmnd, tag)) { 1646 if (cmnd->flags & SCMD_TAGGED) {
1647 vfc_cmd->task_tag = cpu_to_be64(tag[1]); 1647 vfc_cmd->task_tag = cpu_to_be64(cmnd->tag);
1648 switch (tag[0]) { 1648 vfc_cmd->iu.pri_task_attr = IBMVFC_SIMPLE_TASK;
1649 case MSG_SIMPLE_TAG:
1650 vfc_cmd->iu.pri_task_attr = IBMVFC_SIMPLE_TASK;
1651 break;
1652 case MSG_HEAD_TAG:
1653 vfc_cmd->iu.pri_task_attr = IBMVFC_HEAD_OF_QUEUE;
1654 break;
1655 case MSG_ORDERED_TAG:
1656 vfc_cmd->iu.pri_task_attr = IBMVFC_ORDERED_TASK;
1657 break;
1658 };
1659 } 1649 }
1660 1650
1661 if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev)))) 1651 if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev))))
@@ -2897,12 +2887,6 @@ static int ibmvfc_slave_configure(struct scsi_device *sdev)
2897 spin_lock_irqsave(shost->host_lock, flags); 2887 spin_lock_irqsave(shost->host_lock, flags);
2898 if (sdev->type == TYPE_DISK) 2888 if (sdev->type == TYPE_DISK)
2899 sdev->allow_restart = 1; 2889 sdev->allow_restart = 1;
2900
2901 if (sdev->tagged_supported) {
2902 scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
2903 scsi_activate_tcq(sdev, sdev->queue_depth);
2904 } else
2905 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2906 spin_unlock_irqrestore(shost->host_lock, flags); 2890 spin_unlock_irqrestore(shost->host_lock, flags);
2907 return 0; 2891 return 0;
2908} 2892}
@@ -2925,33 +2909,10 @@ static int ibmvfc_change_queue_depth(struct scsi_device *sdev, int qdepth,
2925 if (qdepth > IBMVFC_MAX_CMDS_PER_LUN) 2909 if (qdepth > IBMVFC_MAX_CMDS_PER_LUN)
2926 qdepth = IBMVFC_MAX_CMDS_PER_LUN; 2910 qdepth = IBMVFC_MAX_CMDS_PER_LUN;
2927 2911
2928 scsi_adjust_queue_depth(sdev, 0, qdepth); 2912 scsi_adjust_queue_depth(sdev, qdepth);
2929 return sdev->queue_depth; 2913 return sdev->queue_depth;
2930} 2914}
2931 2915
2932/**
2933 * ibmvfc_change_queue_type - Change the device's queue type
2934 * @sdev: scsi device struct
2935 * @tag_type: type of tags to use
2936 *
2937 * Return value:
2938 * actual queue type set
2939 **/
2940static int ibmvfc_change_queue_type(struct scsi_device *sdev, int tag_type)
2941{
2942 if (sdev->tagged_supported) {
2943 scsi_set_tag_type(sdev, tag_type);
2944
2945 if (tag_type)
2946 scsi_activate_tcq(sdev, sdev->queue_depth);
2947 else
2948 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2949 } else
2950 tag_type = 0;
2951
2952 return tag_type;
2953}
2954
2955static ssize_t ibmvfc_show_host_partition_name(struct device *dev, 2916static ssize_t ibmvfc_show_host_partition_name(struct device *dev,
2956 struct device_attribute *attr, char *buf) 2917 struct device_attribute *attr, char *buf)
2957{ 2918{
@@ -3133,7 +3094,7 @@ static struct scsi_host_template driver_template = {
3133 .target_alloc = ibmvfc_target_alloc, 3094 .target_alloc = ibmvfc_target_alloc,
3134 .scan_finished = ibmvfc_scan_finished, 3095 .scan_finished = ibmvfc_scan_finished,
3135 .change_queue_depth = ibmvfc_change_queue_depth, 3096 .change_queue_depth = ibmvfc_change_queue_depth,
3136 .change_queue_type = ibmvfc_change_queue_type, 3097 .change_queue_type = scsi_change_queue_type,
3137 .cmd_per_lun = 16, 3098 .cmd_per_lun = 16,
3138 .can_queue = IBMVFC_MAX_REQUESTS_DEFAULT, 3099 .can_queue = IBMVFC_MAX_REQUESTS_DEFAULT,
3139 .this_id = -1, 3100 .this_id = -1,
@@ -3141,6 +3102,7 @@ static struct scsi_host_template driver_template = {
3141 .max_sectors = IBMVFC_MAX_SECTORS, 3102 .max_sectors = IBMVFC_MAX_SECTORS,
3142 .use_clustering = ENABLE_CLUSTERING, 3103 .use_clustering = ENABLE_CLUSTERING,
3143 .shost_attrs = ibmvfc_attrs, 3104 .shost_attrs = ibmvfc_attrs,
3105 .use_blk_tags = 1,
3144}; 3106};
3145 3107
3146/** 3108/**
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 7b23f21f22f1..e8c3cdf0d03b 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -1929,7 +1929,6 @@ static int ibmvscsi_slave_configure(struct scsi_device *sdev)
1929 blk_queue_rq_timeout(sdev->request_queue, 120 * HZ); 1929 blk_queue_rq_timeout(sdev->request_queue, 120 * HZ);
1930 } 1930 }
1931 spin_unlock_irqrestore(shost->host_lock, lock_flags); 1931 spin_unlock_irqrestore(shost->host_lock, lock_flags);
1932 scsi_adjust_queue_depth(sdev, 0, shost->cmd_per_lun);
1933 return 0; 1932 return 0;
1934} 1933}
1935 1934
@@ -1951,7 +1950,7 @@ static int ibmvscsi_change_queue_depth(struct scsi_device *sdev, int qdepth,
1951 if (qdepth > IBMVSCSI_MAX_CMDS_PER_LUN) 1950 if (qdepth > IBMVSCSI_MAX_CMDS_PER_LUN)
1952 qdepth = IBMVSCSI_MAX_CMDS_PER_LUN; 1951 qdepth = IBMVSCSI_MAX_CMDS_PER_LUN;
1953 1952
1954 scsi_adjust_queue_depth(sdev, 0, qdepth); 1953 scsi_adjust_queue_depth(sdev, qdepth);
1955 return sdev->queue_depth; 1954 return sdev->queue_depth;
1956} 1955}
1957 1956
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 2a9578c116b7..256ef98f5c29 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -4344,7 +4344,7 @@ static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
4344 qdepth = IPR_MAX_CMD_PER_ATA_LUN; 4344 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4345 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 4345 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4346 4346
4347 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 4347 scsi_adjust_queue_depth(sdev, qdepth);
4348 return sdev->queue_depth; 4348 return sdev->queue_depth;
4349} 4349}
4350 4350
@@ -4364,24 +4364,10 @@ static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4364 4364
4365 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 4365 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4366 res = (struct ipr_resource_entry *)sdev->hostdata; 4366 res = (struct ipr_resource_entry *)sdev->hostdata;
4367 4367 if (res && ipr_is_gscsi(res))
4368 if (res) { 4368 tag_type = scsi_change_queue_type(sdev, tag_type);
4369 if (ipr_is_gscsi(res) && sdev->tagged_supported) { 4369 else
4370 /*
4371 * We don't bother quiescing the device here since the
4372 * adapter firmware does it for us.
4373 */
4374 scsi_set_tag_type(sdev, tag_type);
4375
4376 if (tag_type)
4377 scsi_activate_tcq(sdev, sdev->queue_depth);
4378 else
4379 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4380 } else
4381 tag_type = 0;
4382 } else
4383 tag_type = 0; 4370 tag_type = 0;
4384
4385 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 4371 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4386 return tag_type; 4372 return tag_type;
4387} 4373}
@@ -4765,10 +4751,10 @@ static int ipr_slave_configure(struct scsi_device *sdev)
4765 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 4751 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4766 4752
4767 if (ap) { 4753 if (ap) {
4768 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN); 4754 scsi_adjust_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
4769 ata_sas_slave_configure(sdev, ap); 4755 ata_sas_slave_configure(sdev, ap);
4770 } else 4756 }
4771 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 4757
4772 if (ioa_cfg->sis64) 4758 if (ioa_cfg->sis64)
4773 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n", 4759 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4774 ipr_format_res_path(ioa_cfg, 4760 ipr_format_res_path(ioa_cfg,
@@ -5673,35 +5659,6 @@ static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5673} 5659}
5674 5660
5675/** 5661/**
5676 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5677 * @scsi_cmd: scsi command struct
5678 *
5679 * Return value:
5680 * task attributes
5681 **/
5682static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
5683{
5684 u8 tag[2];
5685 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
5686
5687 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
5688 switch (tag[0]) {
5689 case MSG_SIMPLE_TAG:
5690 rc = IPR_FLAGS_LO_SIMPLE_TASK;
5691 break;
5692 case MSG_HEAD_TAG:
5693 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
5694 break;
5695 case MSG_ORDERED_TAG:
5696 rc = IPR_FLAGS_LO_ORDERED_TASK;
5697 break;
5698 };
5699 }
5700
5701 return rc;
5702}
5703
5704/**
5705 * ipr_erp_done - Process completion of ERP for a device 5662 * ipr_erp_done - Process completion of ERP for a device
5706 * @ipr_cmd: ipr command struct 5663 * @ipr_cmd: ipr command struct
5707 * 5664 *
@@ -6236,7 +6193,10 @@ static int ipr_queuecommand(struct Scsi_Host *shost,
6236 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST; 6193 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
6237 } 6194 }
6238 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR; 6195 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
6239 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd); 6196 if (scsi_cmd->flags & SCMD_TAGGED)
6197 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
6198 else
6199 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
6240 } 6200 }
6241 6201
6242 if (scsi_cmd->cmnd[0] >= 0xC0 && 6202 if (scsi_cmd->cmnd[0] >= 0xC0 &&
@@ -6357,6 +6317,7 @@ static struct scsi_host_template driver_template = {
6357 .sdev_attrs = ipr_dev_attrs, 6317 .sdev_attrs = ipr_dev_attrs,
6358 .proc_name = IPR_NAME, 6318 .proc_name = IPR_NAME,
6359 .no_write_same = 1, 6319 .no_write_same = 1,
6320 .use_blk_tags = 1,
6360}; 6321};
6361 6322
6362/** 6323/**
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index e5afc3884d74..454741a8da45 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -1210,7 +1210,7 @@ ips_slave_configure(struct scsi_device * SDptr)
1210 min = ha->max_cmds / 2; 1210 min = ha->max_cmds / 2;
1211 if (ha->enq->ucLogDriveCount <= 2) 1211 if (ha->enq->ucLogDriveCount <= 2)
1212 min = ha->max_cmds - 1; 1212 min = ha->max_cmds - 1;
1213 scsi_adjust_queue_depth(SDptr, MSG_ORDERED_TAG, min); 1213 scsi_adjust_queue_depth(SDptr, min);
1214 } 1214 }
1215 1215
1216 SDptr->skip_ms_page_8 = 1; 1216 SDptr->skip_ms_page_8 = 1;
diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index 2e890b1e2526..897562056018 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -172,6 +172,7 @@ static struct scsi_host_template isci_sht = {
172 .target_destroy = sas_target_destroy, 172 .target_destroy = sas_target_destroy,
173 .ioctl = sas_ioctl, 173 .ioctl = sas_ioctl,
174 .shost_attrs = isci_host_attrs, 174 .shost_attrs = isci_host_attrs,
175 .use_blk_tags = 1,
175}; 176};
176 177
177static struct sas_domain_function_template isci_transport_ops = { 178static struct sas_domain_function_template isci_transport_ops = {
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 1d7e76e8b447..bf954ee050f8 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -2160,12 +2160,7 @@ int fc_slave_alloc(struct scsi_device *sdev)
2160 if (!rport || fc_remote_port_chkready(rport)) 2160 if (!rport || fc_remote_port_chkready(rport))
2161 return -ENXIO; 2161 return -ENXIO;
2162 2162
2163 if (sdev->tagged_supported) 2163 scsi_adjust_queue_depth(sdev, FC_FCP_DFLT_QUEUE_DEPTH);
2164 scsi_activate_tcq(sdev, FC_FCP_DFLT_QUEUE_DEPTH);
2165 else
2166 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev),
2167 FC_FCP_DFLT_QUEUE_DEPTH);
2168
2169 return 0; 2164 return 0;
2170} 2165}
2171EXPORT_SYMBOL(fc_slave_alloc); 2166EXPORT_SYMBOL(fc_slave_alloc);
@@ -2180,13 +2175,13 @@ int fc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2180{ 2175{
2181 switch (reason) { 2176 switch (reason) {
2182 case SCSI_QDEPTH_DEFAULT: 2177 case SCSI_QDEPTH_DEFAULT:
2183 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 2178 scsi_adjust_queue_depth(sdev, qdepth);
2184 break; 2179 break;
2185 case SCSI_QDEPTH_QFULL: 2180 case SCSI_QDEPTH_QFULL:
2186 scsi_track_queue_full(sdev, qdepth); 2181 scsi_track_queue_full(sdev, qdepth);
2187 break; 2182 break;
2188 case SCSI_QDEPTH_RAMP_UP: 2183 case SCSI_QDEPTH_RAMP_UP:
2189 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 2184 scsi_adjust_queue_depth(sdev, qdepth);
2190 break; 2185 break;
2191 default: 2186 default:
2192 return -EOPNOTSUPP; 2187 return -EOPNOTSUPP;
@@ -2196,26 +2191,6 @@ int fc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2196EXPORT_SYMBOL(fc_change_queue_depth); 2191EXPORT_SYMBOL(fc_change_queue_depth);
2197 2192
2198/** 2193/**
2199 * fc_change_queue_type() - Change a device's queue type
2200 * @sdev: The SCSI device whose queue depth is to change
2201 * @tag_type: Identifier for queue type
2202 */
2203int fc_change_queue_type(struct scsi_device *sdev, int tag_type)
2204{
2205 if (sdev->tagged_supported) {
2206 scsi_set_tag_type(sdev, tag_type);
2207 if (tag_type)
2208 scsi_activate_tcq(sdev, sdev->queue_depth);
2209 else
2210 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2211 } else
2212 tag_type = 0;
2213
2214 return tag_type;
2215}
2216EXPORT_SYMBOL(fc_change_queue_type);
2217
2218/**
2219 * fc_fcp_destory() - Tear down the FCP layer for a given local port 2194 * fc_fcp_destory() - Tear down the FCP layer for a given local port
2220 * @lport: The local port that no longer needs the FCP layer 2195 * @lport: The local port that no longer needs the FCP layer
2221 */ 2196 */
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 0d8bc6c66650..d521624dedfb 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1775,13 +1775,13 @@ int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason)
1775{ 1775{
1776 switch (reason) { 1776 switch (reason) {
1777 case SCSI_QDEPTH_DEFAULT: 1777 case SCSI_QDEPTH_DEFAULT:
1778 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 1778 scsi_adjust_queue_depth(sdev, depth);
1779 break; 1779 break;
1780 case SCSI_QDEPTH_QFULL: 1780 case SCSI_QDEPTH_QFULL:
1781 scsi_track_queue_full(sdev, depth); 1781 scsi_track_queue_full(sdev, depth);
1782 break; 1782 break;
1783 case SCSI_QDEPTH_RAMP_UP: 1783 case SCSI_QDEPTH_RAMP_UP:
1784 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 1784 scsi_adjust_queue_depth(sdev, depth);
1785 break; 1785 break;
1786 default: 1786 default:
1787 return -EOPNOTSUPP; 1787 return -EOPNOTSUPP;
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 24e477d2ea70..89e8b687a679 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -940,15 +940,12 @@ int sas_slave_configure(struct scsi_device *scsi_dev)
940 sas_read_port_mode_page(scsi_dev); 940 sas_read_port_mode_page(scsi_dev);
941 941
942 if (scsi_dev->tagged_supported) { 942 if (scsi_dev->tagged_supported) {
943 scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG); 943 scsi_adjust_queue_depth(scsi_dev, SAS_DEF_QD);
944 scsi_activate_tcq(scsi_dev, SAS_DEF_QD);
945 } else { 944 } else {
946 SAS_DPRINTK("device %llx, LUN %llx doesn't support " 945 SAS_DPRINTK("device %llx, LUN %llx doesn't support "
947 "TCQ\n", SAS_ADDR(dev->sas_addr), 946 "TCQ\n", SAS_ADDR(dev->sas_addr),
948 scsi_dev->lun); 947 scsi_dev->lun);
949 scsi_dev->tagged_supported = 0; 948 scsi_adjust_queue_depth(scsi_dev, 1);
950 scsi_set_tag_type(scsi_dev, 0);
951 scsi_deactivate_tcq(scsi_dev, 1);
952 } 949 }
953 950
954 scsi_dev->allow_restart = 1; 951 scsi_dev->allow_restart = 1;
@@ -969,7 +966,7 @@ int sas_change_queue_depth(struct scsi_device *sdev, int depth, int reason)
969 case SCSI_QDEPTH_RAMP_UP: 966 case SCSI_QDEPTH_RAMP_UP:
970 if (!sdev->tagged_supported) 967 if (!sdev->tagged_supported)
971 depth = 1; 968 depth = 1;
972 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 969 scsi_adjust_queue_depth(sdev, depth);
973 break; 970 break;
974 case SCSI_QDEPTH_QFULL: 971 case SCSI_QDEPTH_QFULL:
975 scsi_track_queue_full(sdev, depth); 972 scsi_track_queue_full(sdev, depth);
@@ -981,22 +978,11 @@ int sas_change_queue_depth(struct scsi_device *sdev, int depth, int reason)
981 return depth; 978 return depth;
982} 979}
983 980
984int sas_change_queue_type(struct scsi_device *scsi_dev, int qt) 981int sas_change_queue_type(struct scsi_device *scsi_dev, int type)
985{ 982{
986 struct domain_device *dev = sdev_to_domain_dev(scsi_dev); 983 if (dev_is_sata(sdev_to_domain_dev(scsi_dev)))
987
988 if (dev_is_sata(dev))
989 return -EINVAL; 984 return -EINVAL;
990 985 return scsi_change_queue_type(scsi_dev, type);
991 if (!scsi_dev->tagged_supported)
992 return 0;
993
994 scsi_deactivate_tcq(scsi_dev, 1);
995
996 scsi_set_tag_type(scsi_dev, qt);
997 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
998
999 return qt;
1000} 986}
1001 987
1002int sas_bios_param(struct scsi_device *scsi_dev, 988int sas_bios_param(struct scsi_device *scsi_dev,
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index b99399fe2548..8533ee9b818d 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -320,7 +320,7 @@ lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
320 case SCSI_QDEPTH_DEFAULT: 320 case SCSI_QDEPTH_DEFAULT:
321 /* change request from sysfs, fall through */ 321 /* change request from sysfs, fall through */
322 case SCSI_QDEPTH_RAMP_UP: 322 case SCSI_QDEPTH_RAMP_UP:
323 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 323 scsi_adjust_queue_depth(sdev, qdepth);
324 break; 324 break;
325 case SCSI_QDEPTH_QFULL: 325 case SCSI_QDEPTH_QFULL:
326 if (scsi_track_queue_full(sdev, qdepth) == 0) 326 if (scsi_track_queue_full(sdev, qdepth) == 0)
@@ -345,26 +345,6 @@ lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
345} 345}
346 346
347/** 347/**
348 * lpfc_change_queue_type() - Change a device's scsi tag queuing type
349 * @sdev: Pointer the scsi device whose queue depth is to change
350 * @tag_type: Identifier for queue tag type
351 */
352static int
353lpfc_change_queue_type(struct scsi_device *sdev, int tag_type)
354{
355 if (sdev->tagged_supported) {
356 scsi_set_tag_type(sdev, tag_type);
357 if (tag_type)
358 scsi_activate_tcq(sdev, sdev->queue_depth);
359 else
360 scsi_deactivate_tcq(sdev, sdev->queue_depth);
361 } else
362 tag_type = 0;
363
364 return tag_type;
365}
366
367/**
368 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread 348 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
369 * @phba: The Hba for which this call is being executed. 349 * @phba: The Hba for which this call is being executed.
370 * 350 *
@@ -4286,7 +4266,6 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
4286 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; 4266 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
4287 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); 4267 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
4288 int datadir = scsi_cmnd->sc_data_direction; 4268 int datadir = scsi_cmnd->sc_data_direction;
4289 char tag[2];
4290 uint8_t *ptr; 4269 uint8_t *ptr;
4291 bool sli4; 4270 bool sli4;
4292 uint32_t fcpdl; 4271 uint32_t fcpdl;
@@ -4308,20 +4287,7 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
4308 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); 4287 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
4309 } 4288 }
4310 4289
4311 if (scsi_populate_tag_msg(scsi_cmnd, tag)) { 4290 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4312 switch (tag[0]) {
4313 case HEAD_OF_QUEUE_TAG:
4314 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
4315 break;
4316 case ORDERED_QUEUE_TAG:
4317 fcp_cmnd->fcpCntl1 = ORDERED_Q;
4318 break;
4319 default:
4320 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4321 break;
4322 }
4323 } else
4324 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4325 4291
4326 sli4 = (phba->sli_rev == LPFC_SLI_REV4); 4292 sli4 = (phba->sli_rev == LPFC_SLI_REV4);
4327 piocbq->iocb.un.fcpi.fcpi_XRdy = 0; 4293 piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
@@ -5632,10 +5598,7 @@ lpfc_slave_configure(struct scsi_device *sdev)
5632 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; 5598 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5633 struct lpfc_hba *phba = vport->phba; 5599 struct lpfc_hba *phba = vport->phba;
5634 5600
5635 if (sdev->tagged_supported) 5601 scsi_adjust_queue_depth(sdev, vport->cfg_lun_queue_depth);
5636 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
5637 else
5638 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
5639 5602
5640 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { 5603 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5641 lpfc_sli_handle_fast_ring_event(phba, 5604 lpfc_sli_handle_fast_ring_event(phba,
@@ -6019,7 +5982,8 @@ struct scsi_host_template lpfc_template = {
6019 .max_sectors = 0xFFFF, 5982 .max_sectors = 0xFFFF,
6020 .vendor_id = LPFC_NL_VENDOR_ID, 5983 .vendor_id = LPFC_NL_VENDOR_ID,
6021 .change_queue_depth = lpfc_change_queue_depth, 5984 .change_queue_depth = lpfc_change_queue_depth,
6022 .change_queue_type = lpfc_change_queue_type, 5985 .change_queue_type = scsi_change_queue_type,
5986 .use_blk_tags = 1,
6023}; 5987};
6024 5988
6025struct scsi_host_template lpfc_vport_template = { 5989struct scsi_host_template lpfc_vport_template = {
@@ -6042,5 +6006,6 @@ struct scsi_host_template lpfc_vport_template = {
6042 .shost_attrs = lpfc_vport_attrs, 6006 .shost_attrs = lpfc_vport_attrs,
6043 .max_sectors = 0xFFFF, 6007 .max_sectors = 0xFFFF,
6044 .change_queue_depth = lpfc_change_queue_depth, 6008 .change_queue_depth = lpfc_change_queue_depth,
6045 .change_queue_type = lpfc_change_queue_type, 6009 .change_queue_type = scsi_change_queue_type,
6010 .use_blk_tags = 1,
6046}; 6011};
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index ac5d94cfd52f..2485255f3414 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1945,7 +1945,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1945 cmd->device->id, (u32)cmd->device->lun); 1945 cmd->device->id, (u32)cmd->device->lun);
1946 1946
1947 if(list_empty(&adapter->pending_list)) 1947 if(list_empty(&adapter->pending_list))
1948 return FALSE; 1948 return FAILED;
1949 1949
1950 list_for_each_safe(pos, next, &adapter->pending_list) { 1950 list_for_each_safe(pos, next, &adapter->pending_list) {
1951 1951
@@ -1968,7 +1968,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1968 (aor==SCB_ABORT) ? "ABORTING":"RESET", 1968 (aor==SCB_ABORT) ? "ABORTING":"RESET",
1969 scb->idx); 1969 scb->idx);
1970 1970
1971 return FALSE; 1971 return FAILED;
1972 } 1972 }
1973 else { 1973 else {
1974 1974
@@ -1993,12 +1993,12 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1993 list_add_tail(SCSI_LIST(cmd), 1993 list_add_tail(SCSI_LIST(cmd),
1994 &adapter->completed_list); 1994 &adapter->completed_list);
1995 1995
1996 return TRUE; 1996 return SUCCESS;
1997 } 1997 }
1998 } 1998 }
1999 } 1999 }
2000 2000
2001 return FALSE; 2001 return FAILED;
2002} 2002}
2003 2003
2004static inline int 2004static inline int
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 531dce419c18..6b077d839f2b 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -349,7 +349,7 @@ static int megaraid_change_queue_depth(struct scsi_device *sdev, int qdepth,
349 349
350 if (qdepth > MBOX_MAX_SCSI_CMDS) 350 if (qdepth > MBOX_MAX_SCSI_CMDS)
351 qdepth = MBOX_MAX_SCSI_CMDS; 351 qdepth = MBOX_MAX_SCSI_CMDS;
352 scsi_adjust_queue_depth(sdev, 0, qdepth); 352 scsi_adjust_queue_depth(sdev, qdepth);
353 return sdev->queue_depth; 353 return sdev->queue_depth;
354} 354}
355 355
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 5640ad1c8214..107244cebd22 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -2594,8 +2594,7 @@ static int megasas_change_queue_depth(struct scsi_device *sdev,
2594 2594
2595 if (queue_depth > sdev->host->can_queue) 2595 if (queue_depth > sdev->host->can_queue)
2596 queue_depth = sdev->host->can_queue; 2596 queue_depth = sdev->host->can_queue;
2597 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), 2597 scsi_adjust_queue_depth(sdev, queue_depth);
2598 queue_depth);
2599 2598
2600 return queue_depth; 2599 return queue_depth;
2601} 2600}
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index c80ed0482649..42fef914d441 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -1222,7 +1222,7 @@ _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1222 max_depth = 1; 1222 max_depth = 1;
1223 if (qdepth > max_depth) 1223 if (qdepth > max_depth)
1224 qdepth = max_depth; 1224 qdepth = max_depth;
1225 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 1225 scsi_adjust_queue_depth(sdev, qdepth);
1226} 1226}
1227 1227
1228/** 1228/**
@@ -1246,37 +1246,15 @@ _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1246 1246
1247 if (sdev->inquiry_len > 7) 1247 if (sdev->inquiry_len > 7)
1248 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " 1248 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1249 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", 1249 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
1250 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, 1250 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1251 sdev->ordered_tags, sdev->scsi_level, 1251 sdev->scsi_level,
1252 (sdev->inquiry[7] & 2) >> 1); 1252 (sdev->inquiry[7] & 2) >> 1);
1253 1253
1254 return sdev->queue_depth; 1254 return sdev->queue_depth;
1255} 1255}
1256 1256
1257/** 1257/**
1258 * _scsih_change_queue_type - changing device queue tag type
1259 * @sdev: scsi device struct
1260 * @tag_type: requested tag type
1261 *
1262 * Returns queue tag type.
1263 */
1264static int
1265_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1266{
1267 if (sdev->tagged_supported) {
1268 scsi_set_tag_type(sdev, tag_type);
1269 if (tag_type)
1270 scsi_activate_tcq(sdev, sdev->queue_depth);
1271 else
1272 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1273 } else
1274 tag_type = 0;
1275
1276 return tag_type;
1277}
1278
1279/**
1280 * _scsih_target_alloc - target add routine 1258 * _scsih_target_alloc - target add routine
1281 * @starget: scsi target struct 1259 * @starget: scsi target struct
1282 * 1260 *
@@ -3966,16 +3944,8 @@ _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3966 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; 3944 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3967 3945
3968 /* set tags */ 3946 /* set tags */
3969 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { 3947 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3970 if (scmd->device->tagged_supported) { 3948
3971 if (scmd->device->ordered_tags)
3972 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3973 else
3974 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3975 } else
3976 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3977 } else
3978 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3979 /* Make sure Device is not raid volume. 3949 /* Make sure Device is not raid volume.
3980 * We do not expose raid functionality to upper layer for warpdrive. 3950 * We do not expose raid functionality to upper layer for warpdrive.
3981 */ 3951 */
@@ -7653,7 +7623,7 @@ static struct scsi_host_template scsih_driver_template = {
7653 .scan_finished = _scsih_scan_finished, 7623 .scan_finished = _scsih_scan_finished,
7654 .scan_start = _scsih_scan_start, 7624 .scan_start = _scsih_scan_start,
7655 .change_queue_depth = _scsih_change_queue_depth, 7625 .change_queue_depth = _scsih_change_queue_depth,
7656 .change_queue_type = _scsih_change_queue_type, 7626 .change_queue_type = scsi_change_queue_type,
7657 .eh_abort_handler = _scsih_abort, 7627 .eh_abort_handler = _scsih_abort,
7658 .eh_device_reset_handler = _scsih_dev_reset, 7628 .eh_device_reset_handler = _scsih_dev_reset,
7659 .eh_target_reset_handler = _scsih_target_reset, 7629 .eh_target_reset_handler = _scsih_target_reset,
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 857276b8880f..b23c2e7588e5 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1090,7 +1090,7 @@ _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1090 max_depth = 1; 1090 max_depth = 1;
1091 if (qdepth > max_depth) 1091 if (qdepth > max_depth)
1092 qdepth = max_depth; 1092 qdepth = max_depth;
1093 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 1093 scsi_adjust_queue_depth(sdev, qdepth);
1094} 1094}
1095 1095
1096/** 1096/**
@@ -1114,38 +1114,15 @@ _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1114 1114
1115 if (sdev->inquiry_len > 7) 1115 if (sdev->inquiry_len > 7)
1116 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \ 1116 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \
1117 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", 1117 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
1118 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, 1118 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1119 sdev->ordered_tags, sdev->scsi_level, 1119 sdev->scsi_level,
1120 (sdev->inquiry[7] & 2) >> 1); 1120 (sdev->inquiry[7] & 2) >> 1);
1121 1121
1122 return sdev->queue_depth; 1122 return sdev->queue_depth;
1123} 1123}
1124 1124
1125/** 1125/**
1126 * _scsih_change_queue_type - changing device queue tag type
1127 * @sdev: scsi device struct
1128 * @tag_type: requested tag type
1129 *
1130 * Returns queue tag type.
1131 */
1132static int
1133_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1134{
1135 if (sdev->tagged_supported) {
1136 scsi_set_tag_type(sdev, tag_type);
1137 if (tag_type)
1138 scsi_activate_tcq(sdev, sdev->queue_depth);
1139 else
1140 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1141 } else
1142 tag_type = 0;
1143
1144 return tag_type;
1145}
1146
1147
1148/**
1149 * _scsih_target_alloc - target add routine 1126 * _scsih_target_alloc - target add routine
1150 * @starget: scsi target struct 1127 * @starget: scsi target struct
1151 * 1128 *
@@ -3586,16 +3563,7 @@ _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3586 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; 3563 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3587 3564
3588 /* set tags */ 3565 /* set tags */
3589 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { 3566 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3590 if (scmd->device->tagged_supported) {
3591 if (scmd->device->ordered_tags)
3592 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3593 else
3594 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3595 } else
3596 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3597 } else
3598 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3599 3567
3600 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && 3568 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3601 scmd->cmd_len != 32) 3569 scmd->cmd_len != 32)
@@ -7284,7 +7252,7 @@ static struct scsi_host_template scsih_driver_template = {
7284 .scan_finished = _scsih_scan_finished, 7252 .scan_finished = _scsih_scan_finished,
7285 .scan_start = _scsih_scan_start, 7253 .scan_start = _scsih_scan_start,
7286 .change_queue_depth = _scsih_change_queue_depth, 7254 .change_queue_depth = _scsih_change_queue_depth,
7287 .change_queue_type = _scsih_change_queue_type, 7255 .change_queue_type = scsi_change_queue_type,
7288 .eh_abort_handler = _scsih_abort, 7256 .eh_abort_handler = _scsih_abort,
7289 .eh_device_reset_handler = _scsih_dev_reset, 7257 .eh_device_reset_handler = _scsih_dev_reset,
7290 .eh_target_reset_handler = _scsih_target_reset, 7258 .eh_target_reset_handler = _scsih_target_reset,
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index eacee48a955c..d3c1fa5e76fb 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -76,6 +76,7 @@ static struct scsi_host_template mvs_sht = {
76 .target_destroy = sas_target_destroy, 76 .target_destroy = sas_target_destroy,
77 .ioctl = sas_ioctl, 77 .ioctl = sas_ioctl,
78 .shost_attrs = mvst_host_attrs, 78 .shost_attrs = mvst_host_attrs,
79 .use_blk_tags = 1,
79}; 80};
80 81
81static struct sas_domain_function_template mvs_transport_ops = { 82static struct sas_domain_function_template mvs_transport_ops = {
diff --git a/drivers/scsi/ncr53c8xx.c b/drivers/scsi/ncr53c8xx.c
index a7305ffc359d..9c331b7bfdcd 100644
--- a/drivers/scsi/ncr53c8xx.c
+++ b/drivers/scsi/ncr53c8xx.c
@@ -7997,10 +7997,7 @@ static int ncr53c8xx_slave_configure(struct scsi_device *device)
7997 if (depth_to_use > MAX_TAGS) 7997 if (depth_to_use > MAX_TAGS)
7998 depth_to_use = MAX_TAGS; 7998 depth_to_use = MAX_TAGS;
7999 7999
8000 scsi_adjust_queue_depth(device, 8000 scsi_adjust_queue_depth(device, depth_to_use);
8001 (device->tagged_supported ?
8002 MSG_SIMPLE_TAG : 0),
8003 depth_to_use);
8004 8001
8005 /* 8002 /*
8006 ** Since the queue depth is not tunable under Linux, 8003 ** Since the queue depth is not tunable under Linux,
diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c
index 92cdd4b06526..243eab3d10d0 100644
--- a/drivers/scsi/osd/osd_uld.c
+++ b/drivers/scsi/osd/osd_uld.c
@@ -540,9 +540,9 @@ static int osd_remove(struct device *dev)
540 */ 540 */
541 541
542static struct scsi_driver osd_driver = { 542static struct scsi_driver osd_driver = {
543 .owner = THIS_MODULE,
544 .gendrv = { 543 .gendrv = {
545 .name = osd_name, 544 .name = osd_name,
545 .owner = THIS_MODULE,
546 .probe = osd_probe, 546 .probe = osd_probe,
547 .remove = osd_remove, 547 .remove = osd_remove,
548 } 548 }
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index dff37a250d79..5033223f6287 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -172,9 +172,9 @@ static int osst_probe(struct device *);
172static int osst_remove(struct device *); 172static int osst_remove(struct device *);
173 173
174static struct scsi_driver osst_template = { 174static struct scsi_driver osst_template = {
175 .owner = THIS_MODULE,
176 .gendrv = { 175 .gendrv = {
177 .name = "osst", 176 .name = "osst",
177 .owner = THIS_MODULE,
178 .probe = osst_probe, 178 .probe = osst_probe,
179 .remove = osst_remove, 179 .remove = osst_remove,
180 } 180 }
@@ -259,9 +259,10 @@ static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
259 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], 259 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
260 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); 260 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
261 if (scode) printk(OSST_DEB_MSG "%s:D: Sense: %02x, ASC: %02x, ASCQ: %02x\n", 261 if (scode) printk(OSST_DEB_MSG "%s:D: Sense: %02x, ASC: %02x, ASCQ: %02x\n",
262 name, scode, sense[12], sense[13]); 262 name, scode, sense[12], sense[13]);
263 if (cmdstatp->have_sense) 263 if (cmdstatp->have_sense)
264 __scsi_print_sense("osst ", SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 264 __scsi_print_sense(STp->device, name,
265 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
265 } 266 }
266 else 267 else
267#endif 268#endif
@@ -275,7 +276,8 @@ static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
275 SRpnt->cmd[0] != TEST_UNIT_READY)) { /* Abnormal conditions for tape */ 276 SRpnt->cmd[0] != TEST_UNIT_READY)) { /* Abnormal conditions for tape */
276 if (cmdstatp->have_sense) { 277 if (cmdstatp->have_sense) {
277 printk(KERN_WARNING "%s:W: Command with sense data:\n", name); 278 printk(KERN_WARNING "%s:W: Command with sense data:\n", name);
278 __scsi_print_sense("osst ", SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 279 __scsi_print_sense(STp->device, name,
280 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
279 } 281 }
280 else { 282 else {
281 static int notyetprinted = 1; 283 static int notyetprinted = 1;
@@ -3325,19 +3327,18 @@ static int osst_write_frame(struct osst_tape * STp, struct osst_request ** aSRpn
3325/* Lock or unlock the drive door. Don't use when struct osst_request allocated. */ 3327/* Lock or unlock the drive door. Don't use when struct osst_request allocated. */
3326static int do_door_lock(struct osst_tape * STp, int do_lock) 3328static int do_door_lock(struct osst_tape * STp, int do_lock)
3327{ 3329{
3328 int retval, cmd; 3330 int retval;
3329 3331
3330 cmd = do_lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK;
3331#if DEBUG 3332#if DEBUG
3332 printk(OSST_DEB_MSG "%s:D: %socking drive door.\n", tape_name(STp), do_lock ? "L" : "Unl"); 3333 printk(OSST_DEB_MSG "%s:D: %socking drive door.\n", tape_name(STp), do_lock ? "L" : "Unl");
3333#endif 3334#endif
3334 retval = scsi_ioctl(STp->device, cmd, NULL); 3335
3335 if (!retval) { 3336 retval = scsi_set_medium_removal(STp->device,
3337 do_lock ? SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
3338 if (!retval)
3336 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; 3339 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
3337 } 3340 else
3338 else {
3339 STp->door_locked = ST_LOCK_FAILS; 3341 STp->door_locked = ST_LOCK_FAILS;
3340 }
3341 return retval; 3342 return retval;
3342} 3343}
3343 3344
@@ -4967,10 +4968,10 @@ static long osst_ioctl(struct file * file,
4967 * may try and take the device offline, in which case all further 4968 * may try and take the device offline, in which case all further
4968 * access to the device is prohibited. 4969 * access to the device is prohibited.
4969 */ 4970 */
4970 if( !scsi_block_when_processing_errors(STp->device) ) { 4971 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in,
4971 retval = (-ENXIO); 4972 file->f_flags & O_NDELAY);
4973 if (retval)
4972 goto out; 4974 goto out;
4973 }
4974 4975
4975 cmd_type = _IOC_TYPE(cmd_in); 4976 cmd_type = _IOC_TYPE(cmd_in);
4976 cmd_nr = _IOC_NR(cmd_in); 4977 cmd_nr = _IOC_NR(cmd_in);
diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index 666bf5af06e2..3ff759a3b74d 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -89,6 +89,7 @@ static struct scsi_host_template pm8001_sht = {
89 .target_destroy = sas_target_destroy, 89 .target_destroy = sas_target_destroy,
90 .ioctl = sas_ioctl, 90 .ioctl = sas_ioctl,
91 .shost_attrs = pm8001_host_attrs, 91 .shost_attrs = pm8001_host_attrs,
92 .use_blk_tags = 1,
92}; 93};
93 94
94/** 95/**
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index bcb64eb1387f..d8b9ba251fbd 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -249,15 +249,11 @@ static int pmcraid_slave_configure(struct scsi_device *scsi_dev)
249 PMCRAID_VSET_MAX_SECTORS); 249 PMCRAID_VSET_MAX_SECTORS);
250 } 250 }
251 251
252 if (scsi_dev->tagged_supported && 252 /*
253 (RES_IS_GSCSI(res->cfg_entry) || RES_IS_VSET(res->cfg_entry))) { 253 * We never want to report TCQ support for these types of devices.
254 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth); 254 */
255 scsi_adjust_queue_depth(scsi_dev, MSG_SIMPLE_TAG, 255 if (!RES_IS_GSCSI(res->cfg_entry) && !RES_IS_VSET(res->cfg_entry))
256 scsi_dev->host->cmd_per_lun); 256 scsi_dev->tagged_supported = 0;
257 } else {
258 scsi_adjust_queue_depth(scsi_dev, 0,
259 scsi_dev->host->cmd_per_lun);
260 }
261 257
262 return 0; 258 return 0;
263} 259}
@@ -303,41 +299,12 @@ static int pmcraid_change_queue_depth(struct scsi_device *scsi_dev, int depth,
303 if (depth > PMCRAID_MAX_CMD_PER_LUN) 299 if (depth > PMCRAID_MAX_CMD_PER_LUN)
304 depth = PMCRAID_MAX_CMD_PER_LUN; 300 depth = PMCRAID_MAX_CMD_PER_LUN;
305 301
306 scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev), depth); 302 scsi_adjust_queue_depth(scsi_dev, depth);
307 303
308 return scsi_dev->queue_depth; 304 return scsi_dev->queue_depth;
309} 305}
310 306
311/** 307/**
312 * pmcraid_change_queue_type - Change the device's queue type
313 * @scsi_dev: scsi device struct
314 * @tag: type of tags to use
315 *
316 * Return value:
317 * actual queue type set
318 */
319static int pmcraid_change_queue_type(struct scsi_device *scsi_dev, int tag)
320{
321 struct pmcraid_resource_entry *res;
322
323 res = (struct pmcraid_resource_entry *)scsi_dev->hostdata;
324
325 if ((res) && scsi_dev->tagged_supported &&
326 (RES_IS_GSCSI(res->cfg_entry) || RES_IS_VSET(res->cfg_entry))) {
327 scsi_set_tag_type(scsi_dev, tag);
328
329 if (tag)
330 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
331 else
332 scsi_deactivate_tcq(scsi_dev, scsi_dev->queue_depth);
333 } else
334 tag = 0;
335
336 return tag;
337}
338
339
340/**
341 * pmcraid_init_cmdblk - initializes a command block 308 * pmcraid_init_cmdblk - initializes a command block
342 * 309 *
343 * @cmd: pointer to struct pmcraid_cmd to be initialized 310 * @cmd: pointer to struct pmcraid_cmd to be initialized
@@ -3175,36 +3142,6 @@ static int pmcraid_eh_host_reset_handler(struct scsi_cmnd *scmd)
3175} 3142}
3176 3143
3177/** 3144/**
3178 * pmcraid_task_attributes - Translate SPI Q-Tags to task attributes
3179 * @scsi_cmd: scsi command struct
3180 *
3181 * Return value
3182 * number of tags or 0 if the task is not tagged
3183 */
3184static u8 pmcraid_task_attributes(struct scsi_cmnd *scsi_cmd)
3185{
3186 char tag[2];
3187 u8 rc = 0;
3188
3189 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
3190 switch (tag[0]) {
3191 case MSG_SIMPLE_TAG:
3192 rc = TASK_TAG_SIMPLE;
3193 break;
3194 case MSG_HEAD_TAG:
3195 rc = TASK_TAG_QUEUE_HEAD;
3196 break;
3197 case MSG_ORDERED_TAG:
3198 rc = TASK_TAG_ORDERED;
3199 break;
3200 };
3201 }
3202
3203 return rc;
3204}
3205
3206
3207/**
3208 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB 3145 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB
3209 * @cmd: pmcraid command struct 3146 * @cmd: pmcraid command struct
3210 * @sgcount: count of scatter-gather elements 3147 * @sgcount: count of scatter-gather elements
@@ -3559,7 +3496,9 @@ static int pmcraid_queuecommand_lck(
3559 } 3496 }
3560 3497
3561 ioarcb->request_flags0 |= NO_LINK_DESCS; 3498 ioarcb->request_flags0 |= NO_LINK_DESCS;
3562 ioarcb->request_flags1 |= pmcraid_task_attributes(scsi_cmd); 3499
3500 if (scsi_cmd->flags & SCMD_TAGGED)
3501 ioarcb->request_flags1 |= TASK_TAG_SIMPLE;
3563 3502
3564 if (RES_IS_GSCSI(res->cfg_entry)) 3503 if (RES_IS_GSCSI(res->cfg_entry))
3565 ioarcb->request_flags1 |= DELAY_AFTER_RESET; 3504 ioarcb->request_flags1 |= DELAY_AFTER_RESET;
@@ -4320,7 +4259,7 @@ static struct scsi_host_template pmcraid_host_template = {
4320 .slave_configure = pmcraid_slave_configure, 4259 .slave_configure = pmcraid_slave_configure,
4321 .slave_destroy = pmcraid_slave_destroy, 4260 .slave_destroy = pmcraid_slave_destroy,
4322 .change_queue_depth = pmcraid_change_queue_depth, 4261 .change_queue_depth = pmcraid_change_queue_depth,
4323 .change_queue_type = pmcraid_change_queue_type, 4262 .change_queue_type = scsi_change_queue_type,
4324 .can_queue = PMCRAID_MAX_IO_CMD, 4263 .can_queue = PMCRAID_MAX_IO_CMD,
4325 .this_id = -1, 4264 .this_id = -1,
4326 .sg_tablesize = PMCRAID_MAX_IOADLS, 4265 .sg_tablesize = PMCRAID_MAX_IOADLS,
@@ -4329,7 +4268,8 @@ static struct scsi_host_template pmcraid_host_template = {
4329 .cmd_per_lun = PMCRAID_MAX_CMD_PER_LUN, 4268 .cmd_per_lun = PMCRAID_MAX_CMD_PER_LUN,
4330 .use_clustering = ENABLE_CLUSTERING, 4269 .use_clustering = ENABLE_CLUSTERING,
4331 .shost_attrs = pmcraid_host_attrs, 4270 .shost_attrs = pmcraid_host_attrs,
4332 .proc_name = PMCRAID_DRIVER_NAME 4271 .proc_name = PMCRAID_DRIVER_NAME,
4272 .use_blk_tags = 1,
4333}; 4273};
4334 4274
4335/* 4275/*
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index ef23fabe3924..b3b48b5a984c 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -220,10 +220,6 @@ static int ps3rom_queuecommand_lck(struct scsi_cmnd *cmd,
220 unsigned char opcode; 220 unsigned char opcode;
221 int res; 221 int res;
222 222
223#ifdef DEBUG
224 scsi_print_command(cmd);
225#endif
226
227 priv->curr_cmd = cmd; 223 priv->curr_cmd = cmd;
228 cmd->scsi_done = done; 224 cmd->scsi_done = done;
229 225
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 158020522dfb..adedb6ef8eec 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1224,10 +1224,9 @@ qla1280_slave_configure(struct scsi_device *device)
1224 1224
1225 if (device->tagged_supported && 1225 if (device->tagged_supported &&
1226 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) { 1226 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1227 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, 1227 scsi_adjust_queue_depth(device, ha->bus_settings[bus].hiwat);
1228 ha->bus_settings[bus].hiwat);
1229 } else { 1228 } else {
1230 scsi_adjust_queue_depth(device, 0, default_depth); 1229 scsi_adjust_queue_depth(device, default_depth);
1231 } 1230 }
1232 1231
1233 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr; 1232 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index f0edb07f3198..a1ab25fca874 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -325,7 +325,6 @@ qla2x00_start_scsi(srb_t *sp)
325 struct qla_hw_data *ha; 325 struct qla_hw_data *ha;
326 struct req_que *req; 326 struct req_que *req;
327 struct rsp_que *rsp; 327 struct rsp_que *rsp;
328 char tag[2];
329 328
330 /* Setup device pointers. */ 329 /* Setup device pointers. */
331 ret = 0; 330 ret = 0;
@@ -404,26 +403,7 @@ qla2x00_start_scsi(srb_t *sp)
404 /* Set target ID and LUN number*/ 403 /* Set target ID and LUN number*/
405 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); 404 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id);
406 cmd_pkt->lun = cpu_to_le16(cmd->device->lun); 405 cmd_pkt->lun = cpu_to_le16(cmd->device->lun);
407 406 cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);
408 /* Update tagged queuing modifier */
409 if (scsi_populate_tag_msg(cmd, tag)) {
410 switch (tag[0]) {
411 case HEAD_OF_QUEUE_TAG:
412 cmd_pkt->control_flags =
413 __constant_cpu_to_le16(CF_HEAD_TAG);
414 break;
415 case ORDERED_QUEUE_TAG:
416 cmd_pkt->control_flags =
417 __constant_cpu_to_le16(CF_ORDERED_TAG);
418 break;
419 default:
420 cmd_pkt->control_flags =
421 __constant_cpu_to_le16(CF_SIMPLE_TAG);
422 break;
423 }
424 } else {
425 cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);
426 }
427 407
428 /* Load SCSI command packet. */ 408 /* Load SCSI command packet. */
429 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); 409 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
@@ -1264,7 +1244,6 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1264 uint16_t fcp_cmnd_len; 1244 uint16_t fcp_cmnd_len;
1265 struct fcp_cmnd *fcp_cmnd; 1245 struct fcp_cmnd *fcp_cmnd;
1266 dma_addr_t crc_ctx_dma; 1246 dma_addr_t crc_ctx_dma;
1267 char tag[2];
1268 1247
1269 cmd = GET_CMD_SP(sp); 1248 cmd = GET_CMD_SP(sp);
1270 1249
@@ -1356,25 +1335,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1356 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32( 1335 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32(
1357 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); 1336 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
1358 fcp_cmnd->task_management = 0; 1337 fcp_cmnd->task_management = 0;
1359 1338 fcp_cmnd->task_attribute = TSK_SIMPLE;
1360 /*
1361 * Update tagged queuing modifier if using command tag queuing
1362 */
1363 if (scsi_populate_tag_msg(cmd, tag)) {
1364 switch (tag[0]) {
1365 case HEAD_OF_QUEUE_TAG:
1366 fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE;
1367 break;
1368 case ORDERED_QUEUE_TAG:
1369 fcp_cmnd->task_attribute = TSK_ORDERED;
1370 break;
1371 default:
1372 fcp_cmnd->task_attribute = TSK_SIMPLE;
1373 break;
1374 }
1375 } else {
1376 fcp_cmnd->task_attribute = TSK_SIMPLE;
1377 }
1378 1339
1379 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */ 1340 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */
1380 1341
@@ -1495,7 +1456,6 @@ qla24xx_start_scsi(srb_t *sp)
1495 struct scsi_cmnd *cmd = GET_CMD_SP(sp); 1456 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1496 struct scsi_qla_host *vha = sp->fcport->vha; 1457 struct scsi_qla_host *vha = sp->fcport->vha;
1497 struct qla_hw_data *ha = vha->hw; 1458 struct qla_hw_data *ha = vha->hw;
1498 char tag[2];
1499 1459
1500 /* Setup device pointers. */ 1460 /* Setup device pointers. */
1501 ret = 0; 1461 ret = 0;
@@ -1578,22 +1538,7 @@ qla24xx_start_scsi(srb_t *sp)
1578 int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); 1538 int_to_scsilun(cmd->device->lun, &cmd_pkt->lun);
1579 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); 1539 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
1580 1540
1581 /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */ 1541 cmd_pkt->task = TSK_SIMPLE;
1582 if (scsi_populate_tag_msg(cmd, tag)) {
1583 switch (tag[0]) {
1584 case HEAD_OF_QUEUE_TAG:
1585 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
1586 break;
1587 case ORDERED_QUEUE_TAG:
1588 cmd_pkt->task = TSK_ORDERED;
1589 break;
1590 default:
1591 cmd_pkt->task = TSK_SIMPLE;
1592 break;
1593 }
1594 } else {
1595 cmd_pkt->task = TSK_SIMPLE;
1596 }
1597 1542
1598 /* Load SCSI command packet. */ 1543 /* Load SCSI command packet. */
1599 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); 1544 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
@@ -2310,7 +2255,6 @@ qla82xx_start_scsi(srb_t *sp)
2310 struct qla_hw_data *ha = vha->hw; 2255 struct qla_hw_data *ha = vha->hw;
2311 struct req_que *req = NULL; 2256 struct req_que *req = NULL;
2312 struct rsp_que *rsp = NULL; 2257 struct rsp_que *rsp = NULL;
2313 char tag[2];
2314 2258
2315 /* Setup device pointers. */ 2259 /* Setup device pointers. */
2316 ret = 0; 2260 ret = 0;
@@ -2489,22 +2433,6 @@ sufficient_dsds:
2489 else if (cmd->sc_data_direction == DMA_FROM_DEVICE) 2433 else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
2490 ctx->fcp_cmnd->additional_cdb_len |= 2; 2434 ctx->fcp_cmnd->additional_cdb_len |= 2;
2491 2435
2492 /*
2493 * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
2494 */
2495 if (scsi_populate_tag_msg(cmd, tag)) {
2496 switch (tag[0]) {
2497 case HEAD_OF_QUEUE_TAG:
2498 ctx->fcp_cmnd->task_attribute =
2499 TSK_HEAD_OF_QUEUE;
2500 break;
2501 case ORDERED_QUEUE_TAG:
2502 ctx->fcp_cmnd->task_attribute =
2503 TSK_ORDERED;
2504 break;
2505 }
2506 }
2507
2508 /* Populate the FCP_PRIO. */ 2436 /* Populate the FCP_PRIO. */
2509 if (ha->flags.fcp_prio_enabled) 2437 if (ha->flags.fcp_prio_enabled)
2510 ctx->fcp_cmnd->task_attribute |= 2438 ctx->fcp_cmnd->task_attribute |=
@@ -2565,20 +2493,6 @@ sufficient_dsds:
2565 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, 2493 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun,
2566 sizeof(cmd_pkt->lun)); 2494 sizeof(cmd_pkt->lun));
2567 2495
2568 /*
2569 * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
2570 */
2571 if (scsi_populate_tag_msg(cmd, tag)) {
2572 switch (tag[0]) {
2573 case HEAD_OF_QUEUE_TAG:
2574 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
2575 break;
2576 case ORDERED_QUEUE_TAG:
2577 cmd_pkt->task = TSK_ORDERED;
2578 break;
2579 }
2580 }
2581
2582 /* Populate the FCP_PRIO. */ 2496 /* Populate the FCP_PRIO. */
2583 if (ha->flags.fcp_prio_enabled) 2497 if (ha->flags.fcp_prio_enabled)
2584 cmd_pkt->task |= sp->fcport->fcp_prio << 3; 2498 cmd_pkt->task |= sp->fcport->fcp_prio << 3;
diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index 80867599527d..6d190b4b82a0 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -3086,7 +3086,6 @@ qlafx00_start_scsi(srb_t *sp)
3086 struct cmd_type_7_fx00 *cmd_pkt; 3086 struct cmd_type_7_fx00 *cmd_pkt;
3087 struct cmd_type_7_fx00 lcmd_pkt; 3087 struct cmd_type_7_fx00 lcmd_pkt;
3088 struct scsi_lun llun; 3088 struct scsi_lun llun;
3089 char tag[2];
3090 3089
3091 /* Setup device pointers. */ 3090 /* Setup device pointers. */
3092 ret = 0; 3091 ret = 0;
@@ -3157,18 +3156,6 @@ qlafx00_start_scsi(srb_t *sp)
3157 host_to_adap((uint8_t *)&llun, (uint8_t *)&lcmd_pkt.lun, 3156 host_to_adap((uint8_t *)&llun, (uint8_t *)&lcmd_pkt.lun,
3158 sizeof(lcmd_pkt.lun)); 3157 sizeof(lcmd_pkt.lun));
3159 3158
3160 /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */
3161 if (scsi_populate_tag_msg(cmd, tag)) {
3162 switch (tag[0]) {
3163 case HEAD_OF_QUEUE_TAG:
3164 lcmd_pkt.task = TSK_HEAD_OF_QUEUE;
3165 break;
3166 case ORDERED_QUEUE_TAG:
3167 lcmd_pkt.task = TSK_ORDERED;
3168 break;
3169 }
3170 }
3171
3172 /* Load SCSI command packet. */ 3159 /* Load SCSI command packet. */
3173 host_to_adap(cmd->cmnd, lcmd_pkt.fcp_cdb, sizeof(lcmd_pkt.fcp_cdb)); 3160 host_to_adap(cmd->cmnd, lcmd_pkt.fcp_cdb, sizeof(lcmd_pkt.fcp_cdb));
3174 lcmd_pkt.byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); 3161 lcmd_pkt.byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd999cb6..33166ebec7d8 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -237,7 +237,6 @@ static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
237static int qla2xxx_eh_host_reset(struct scsi_cmnd *); 237static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
238 238
239static int qla2x00_change_queue_depth(struct scsi_device *, int, int); 239static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
240static int qla2x00_change_queue_type(struct scsi_device *, int);
241static void qla2x00_clear_drv_active(struct qla_hw_data *); 240static void qla2x00_clear_drv_active(struct qla_hw_data *);
242static void qla2x00_free_device(scsi_qla_host_t *); 241static void qla2x00_free_device(scsi_qla_host_t *);
243static void qla83xx_disable_laser(scsi_qla_host_t *vha); 242static void qla83xx_disable_laser(scsi_qla_host_t *vha);
@@ -260,7 +259,7 @@ struct scsi_host_template qla2xxx_driver_template = {
260 .scan_finished = qla2xxx_scan_finished, 259 .scan_finished = qla2xxx_scan_finished,
261 .scan_start = qla2xxx_scan_start, 260 .scan_start = qla2xxx_scan_start,
262 .change_queue_depth = qla2x00_change_queue_depth, 261 .change_queue_depth = qla2x00_change_queue_depth,
263 .change_queue_type = qla2x00_change_queue_type, 262 .change_queue_type = scsi_change_queue_type,
264 .this_id = -1, 263 .this_id = -1,
265 .cmd_per_lun = 3, 264 .cmd_per_lun = 3,
266 .use_clustering = ENABLE_CLUSTERING, 265 .use_clustering = ENABLE_CLUSTERING,
@@ -270,6 +269,7 @@ struct scsi_host_template qla2xxx_driver_template = {
270 .shost_attrs = qla2x00_host_attrs, 269 .shost_attrs = qla2x00_host_attrs,
271 270
272 .supported_mode = MODE_INITIATOR, 271 .supported_mode = MODE_INITIATOR,
272 .use_blk_tags = 1,
273}; 273};
274 274
275static struct scsi_transport_template *qla2xxx_transport_template = NULL; 275static struct scsi_transport_template *qla2xxx_transport_template = NULL;
@@ -1405,10 +1405,7 @@ qla2xxx_slave_configure(struct scsi_device *sdev)
1405 if (IS_T10_PI_CAPABLE(vha->hw)) 1405 if (IS_T10_PI_CAPABLE(vha->hw))
1406 blk_queue_update_dma_alignment(sdev->request_queue, 0x7); 1406 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1407 1407
1408 if (sdev->tagged_supported) 1408 scsi_adjust_queue_depth(sdev, req->max_q_depth);
1409 scsi_activate_tcq(sdev, req->max_q_depth);
1410 else
1411 scsi_deactivate_tcq(sdev, req->max_q_depth);
1412 return 0; 1409 return 0;
1413} 1410}
1414 1411
@@ -1443,10 +1440,7 @@ static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1443 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth) 1440 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1444 return; 1441 return;
1445 1442
1446 if (sdev->ordered_tags) 1443 scsi_adjust_queue_depth(sdev, qdepth);
1447 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1448 else
1449 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1450 1444
1451 ql_dbg(ql_dbg_io, vha, 0x302a, 1445 ql_dbg(ql_dbg_io, vha, 0x302a,
1452 "Queue depth adjusted-up to %d for nexus=%ld:%d:%llu.\n", 1446 "Queue depth adjusted-up to %d for nexus=%ld:%d:%llu.\n",
@@ -1458,7 +1452,7 @@ qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1458{ 1452{
1459 switch (reason) { 1453 switch (reason) {
1460 case SCSI_QDEPTH_DEFAULT: 1454 case SCSI_QDEPTH_DEFAULT:
1461 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 1455 scsi_adjust_queue_depth(sdev, qdepth);
1462 break; 1456 break;
1463 case SCSI_QDEPTH_QFULL: 1457 case SCSI_QDEPTH_QFULL:
1464 qla2x00_handle_queue_full(sdev, qdepth); 1458 qla2x00_handle_queue_full(sdev, qdepth);
@@ -1473,21 +1467,6 @@ qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1473 return sdev->queue_depth; 1467 return sdev->queue_depth;
1474} 1468}
1475 1469
1476static int
1477qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1478{
1479 if (sdev->tagged_supported) {
1480 scsi_set_tag_type(sdev, tag_type);
1481 if (tag_type)
1482 scsi_activate_tcq(sdev, sdev->queue_depth);
1483 else
1484 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1485 } else
1486 tag_type = 0;
1487
1488 return tag_type;
1489}
1490
1491/** 1470/**
1492 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. 1471 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1493 * @ha: HA context 1472 * @ha: HA context
diff --git a/drivers/scsi/qla4xxx/ql4_iocb.c b/drivers/scsi/qla4xxx/ql4_iocb.c
index 08ab6dac226d..17222eb49762 100644
--- a/drivers/scsi/qla4xxx/ql4_iocb.c
+++ b/drivers/scsi/qla4xxx/ql4_iocb.c
@@ -280,7 +280,6 @@ int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb)
280 uint16_t req_cnt; 280 uint16_t req_cnt;
281 unsigned long flags; 281 unsigned long flags;
282 uint32_t index; 282 uint32_t index;
283 char tag[2];
284 283
285 /* Get real lun and adapter */ 284 /* Get real lun and adapter */
286 ddb_entry = srb->ddb; 285 ddb_entry = srb->ddb;
@@ -352,15 +351,6 @@ int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb)
352 351
353 /* Set tagged queueing control flags */ 352 /* Set tagged queueing control flags */
354 cmd_entry->control_flags |= CF_SIMPLE_TAG; 353 cmd_entry->control_flags |= CF_SIMPLE_TAG;
355 if (scsi_populate_tag_msg(cmd, tag))
356 switch (tag[0]) {
357 case MSG_HEAD_TAG:
358 cmd_entry->control_flags |= CF_HEAD_TAG;
359 break;
360 case MSG_ORDERED_TAG:
361 cmd_entry->control_flags |= CF_ORDERED_TAG;
362 break;
363 }
364 354
365 qla4xxx_advance_req_ring_ptr(ha); 355 qla4xxx_advance_req_ring_ptr(ha);
366 qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds); 356 qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds);
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 199fcf79a051..f8724f2e0158 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -162,8 +162,6 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
162static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); 162static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
163static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); 163static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
164static int qla4xxx_slave_alloc(struct scsi_device *device); 164static int qla4xxx_slave_alloc(struct scsi_device *device);
165static int qla4xxx_slave_configure(struct scsi_device *device);
166static void qla4xxx_slave_destroy(struct scsi_device *sdev);
167static umode_t qla4_attr_is_visible(int param_type, int param); 165static umode_t qla4_attr_is_visible(int param_type, int param);
168static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type); 166static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
169static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth, 167static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
@@ -204,9 +202,7 @@ static struct scsi_host_template qla4xxx_driver_template = {
204 .eh_host_reset_handler = qla4xxx_eh_host_reset, 202 .eh_host_reset_handler = qla4xxx_eh_host_reset,
205 .eh_timed_out = qla4xxx_eh_cmd_timed_out, 203 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
206 204
207 .slave_configure = qla4xxx_slave_configure,
208 .slave_alloc = qla4xxx_slave_alloc, 205 .slave_alloc = qla4xxx_slave_alloc,
209 .slave_destroy = qla4xxx_slave_destroy,
210 .change_queue_depth = qla4xxx_change_queue_depth, 206 .change_queue_depth = qla4xxx_change_queue_depth,
211 207
212 .this_id = -1, 208 .this_id = -1,
@@ -218,6 +214,7 @@ static struct scsi_host_template qla4xxx_driver_template = {
218 .shost_attrs = qla4xxx_host_attrs, 214 .shost_attrs = qla4xxx_host_attrs,
219 .host_reset = qla4xxx_host_reset, 215 .host_reset = qla4xxx_host_reset,
220 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC, 216 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
217 .use_blk_tags = 1,
221}; 218};
222 219
223static struct iscsi_transport qla4xxx_iscsi_transport = { 220static struct iscsi_transport qla4xxx_iscsi_transport = {
@@ -9060,26 +9057,14 @@ static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9060 ddb = sess->dd_data; 9057 ddb = sess->dd_data;
9061 9058
9062 sdev->hostdata = ddb; 9059 sdev->hostdata = ddb;
9063 sdev->tagged_supported = 1;
9064 9060
9065 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) 9061 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9066 queue_depth = ql4xmaxqdepth; 9062 queue_depth = ql4xmaxqdepth;
9067 9063
9068 scsi_activate_tcq(sdev, queue_depth); 9064 scsi_adjust_queue_depth(sdev, queue_depth);
9069 return 0; 9065 return 0;
9070} 9066}
9071 9067
9072static int qla4xxx_slave_configure(struct scsi_device *sdev)
9073{
9074 sdev->tagged_supported = 1;
9075 return 0;
9076}
9077
9078static void qla4xxx_slave_destroy(struct scsi_device *sdev)
9079{
9080 scsi_deactivate_tcq(sdev, 1);
9081}
9082
9083static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth, 9068static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
9084 int reason) 9069 int reason)
9085{ 9070{
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 79c77b485a67..2d9730432233 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -527,9 +527,9 @@ void scsi_log_send(struct scsi_cmnd *cmd)
527 * 527 *
528 * 1: nothing (match completion) 528 * 1: nothing (match completion)
529 * 529 *
530 * 2: log opcode + command of all commands 530 * 2: log opcode + command of all commands + cmd address
531 * 531 *
532 * 3: same as 2 plus dump cmd address 532 * 3: same as 2
533 * 533 *
534 * 4: same as 3 plus dump extra junk 534 * 4: same as 3 plus dump extra junk
535 */ 535 */
@@ -537,10 +537,8 @@ void scsi_log_send(struct scsi_cmnd *cmd)
537 level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT, 537 level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT,
538 SCSI_LOG_MLQUEUE_BITS); 538 SCSI_LOG_MLQUEUE_BITS);
539 if (level > 1) { 539 if (level > 1) {
540 scmd_printk(KERN_INFO, cmd, "Send: "); 540 scmd_printk(KERN_INFO, cmd,
541 if (level > 2) 541 "Send: scmd 0x%p\n", cmd);
542 printk("0x%p ", cmd);
543 printk("\n");
544 scsi_print_command(cmd); 542 scsi_print_command(cmd);
545 if (level > 3) { 543 if (level > 3) {
546 printk(KERN_INFO "buffer = 0x%p, bufflen = %d," 544 printk(KERN_INFO "buffer = 0x%p, bufflen = %d,"
@@ -565,7 +563,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
565 * 563 *
566 * 2: same as 1 but for all command completions. 564 * 2: same as 1 but for all command completions.
567 * 565 *
568 * 3: same as 2 plus dump cmd address 566 * 3: same as 2
569 * 567 *
570 * 4: same as 3 plus dump extra junk 568 * 4: same as 3 plus dump extra junk
571 */ 569 */
@@ -574,39 +572,10 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
574 SCSI_LOG_MLCOMPLETE_BITS); 572 SCSI_LOG_MLCOMPLETE_BITS);
575 if (((level > 0) && (cmd->result || disposition != SUCCESS)) || 573 if (((level > 0) && (cmd->result || disposition != SUCCESS)) ||
576 (level > 1)) { 574 (level > 1)) {
577 scmd_printk(KERN_INFO, cmd, "Done: "); 575 scsi_print_result(cmd, "Done: ", disposition);
578 if (level > 2)
579 printk("0x%p ", cmd);
580 /*
581 * Dump truncated values, so we usually fit within
582 * 80 chars.
583 */
584 switch (disposition) {
585 case SUCCESS:
586 printk("SUCCESS\n");
587 break;
588 case NEEDS_RETRY:
589 printk("RETRY\n");
590 break;
591 case ADD_TO_MLQUEUE:
592 printk("MLQUEUE\n");
593 break;
594 case FAILED:
595 printk("FAILED\n");
596 break;
597 case TIMEOUT_ERROR:
598 /*
599 * If called via scsi_times_out.
600 */
601 printk("TIMEOUT\n");
602 break;
603 default:
604 printk("UNKNOWN\n");
605 }
606 scsi_print_result(cmd);
607 scsi_print_command(cmd); 576 scsi_print_command(cmd);
608 if (status_byte(cmd->result) & CHECK_CONDITION) 577 if (status_byte(cmd->result) & CHECK_CONDITION)
609 scsi_print_sense("", cmd); 578 scsi_print_sense(cmd);
610 if (level > 3) 579 if (level > 3)
611 scmd_printk(KERN_INFO, cmd, 580 scmd_printk(KERN_INFO, cmd,
612 "scsi host busy %d failed %d\n", 581 "scsi host busy %d failed %d\n",
@@ -634,87 +603,6 @@ void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd *cmd)
634EXPORT_SYMBOL(scsi_cmd_get_serial); 603EXPORT_SYMBOL(scsi_cmd_get_serial);
635 604
636/** 605/**
637 * scsi_dispatch_command - Dispatch a command to the low-level driver.
638 * @cmd: command block we are dispatching.
639 *
640 * Return: nonzero return request was rejected and device's queue needs to be
641 * plugged.
642 */
643int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
644{
645 struct Scsi_Host *host = cmd->device->host;
646 int rtn = 0;
647
648 atomic_inc(&cmd->device->iorequest_cnt);
649
650 /* check if the device is still usable */
651 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
652 /* in SDEV_DEL we error all commands. DID_NO_CONNECT
653 * returns an immediate error upwards, and signals
654 * that the device is no longer present */
655 cmd->result = DID_NO_CONNECT << 16;
656 goto done;
657 }
658
659 /* Check to see if the scsi lld made this device blocked. */
660 if (unlikely(scsi_device_blocked(cmd->device))) {
661 /*
662 * in blocked state, the command is just put back on
663 * the device queue. The suspend state has already
664 * blocked the queue so future requests should not
665 * occur until the device transitions out of the
666 * suspend state.
667 */
668 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
669 "queuecommand : device blocked\n"));
670 return SCSI_MLQUEUE_DEVICE_BUSY;
671 }
672
673 /* Store the LUN value in cmnd, if needed. */
674 if (cmd->device->lun_in_cdb)
675 cmd->cmnd[1] = (cmd->cmnd[1] & 0x1f) |
676 (cmd->device->lun << 5 & 0xe0);
677
678 scsi_log_send(cmd);
679
680 /*
681 * Before we queue this command, check if the command
682 * length exceeds what the host adapter can handle.
683 */
684 if (cmd->cmd_len > cmd->device->host->max_cmd_len) {
685 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
686 "queuecommand : command too long. "
687 "cdb_size=%d host->max_cmd_len=%d\n",
688 cmd->cmd_len, cmd->device->host->max_cmd_len));
689 cmd->result = (DID_ABORT << 16);
690 goto done;
691 }
692
693 if (unlikely(host->shost_state == SHOST_DEL)) {
694 cmd->result = (DID_NO_CONNECT << 16);
695 goto done;
696
697 }
698
699 trace_scsi_dispatch_cmd_start(cmd);
700 rtn = host->hostt->queuecommand(host, cmd);
701 if (rtn) {
702 trace_scsi_dispatch_cmd_error(cmd, rtn);
703 if (rtn != SCSI_MLQUEUE_DEVICE_BUSY &&
704 rtn != SCSI_MLQUEUE_TARGET_BUSY)
705 rtn = SCSI_MLQUEUE_HOST_BUSY;
706
707 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
708 "queuecommand : request rejected\n"));
709 }
710
711 return rtn;
712 done:
713 cmd->scsi_done(cmd);
714 return 0;
715}
716
717/**
718 * scsi_finish_command - cleanup and pass command back to upper layer 606 * scsi_finish_command - cleanup and pass command back to upper layer
719 * @cmd: the command 607 * @cmd: the command
720 * 608 *
@@ -775,8 +663,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
775/** 663/**
776 * scsi_adjust_queue_depth - Let low level drivers change a device's queue depth 664 * scsi_adjust_queue_depth - Let low level drivers change a device's queue depth
777 * @sdev: SCSI Device in question 665 * @sdev: SCSI Device in question
778 * @tagged: Do we use tagged queueing (non-0) or do we treat
779 * this device as an untagged device (0)
780 * @tags: Number of tags allowed if tagged queueing enabled, 666 * @tags: Number of tags allowed if tagged queueing enabled,
781 * or number of commands the low level driver can 667 * or number of commands the low level driver can
782 * queue up in non-tagged mode (as per cmd_per_lun). 668 * queue up in non-tagged mode (as per cmd_per_lun).
@@ -790,7 +676,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
790 * currently active and whether or not it even has the 676 * currently active and whether or not it even has the
791 * command blocks built yet. 677 * command blocks built yet.
792 */ 678 */
793void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags) 679void scsi_adjust_queue_depth(struct scsi_device *sdev, int tags)
794{ 680{
795 unsigned long flags; 681 unsigned long flags;
796 682
@@ -818,26 +704,6 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags)
818 } 704 }
819 705
820 sdev->queue_depth = tags; 706 sdev->queue_depth = tags;
821 switch (tagged) {
822 case 0:
823 sdev->ordered_tags = 0;
824 sdev->simple_tags = 0;
825 break;
826 case MSG_ORDERED_TAG:
827 sdev->ordered_tags = 1;
828 sdev->simple_tags = 1;
829 break;
830 case MSG_SIMPLE_TAG:
831 sdev->ordered_tags = 0;
832 sdev->simple_tags = 1;
833 break;
834 default:
835 sdev->ordered_tags = 0;
836 sdev->simple_tags = 0;
837 sdev_printk(KERN_WARNING, sdev,
838 "scsi_adjust_queue_depth, bad queue type, "
839 "disabled\n");
840 }
841 out: 707 out:
842 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 708 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
843} 709}
@@ -885,19 +751,33 @@ int scsi_track_queue_full(struct scsi_device *sdev, int depth)
885 return 0; 751 return 0;
886 if (sdev->last_queue_full_depth < 8) { 752 if (sdev->last_queue_full_depth < 8) {
887 /* Drop back to untagged */ 753 /* Drop back to untagged */
888 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 754 scsi_set_tag_type(sdev, 0);
755 scsi_adjust_queue_depth(sdev, sdev->host->cmd_per_lun);
889 return -1; 756 return -1;
890 } 757 }
891 758
892 if (sdev->ordered_tags) 759 scsi_adjust_queue_depth(sdev, depth);
893 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth);
894 else
895 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth);
896 return depth; 760 return depth;
897} 761}
898EXPORT_SYMBOL(scsi_track_queue_full); 762EXPORT_SYMBOL(scsi_track_queue_full);
899 763
900/** 764/**
765 * scsi_change_queue_type() - Change a device's queue type
766 * @sdev: The SCSI device whose queue depth is to change
767 * @tag_type: Identifier for queue type
768 */
769int scsi_change_queue_type(struct scsi_device *sdev, int tag_type)
770{
771 if (!sdev->tagged_supported)
772 return 0;
773
774 scsi_set_tag_type(sdev, tag_type);
775 return tag_type;
776
777}
778EXPORT_SYMBOL(scsi_change_queue_type);
779
780/**
901 * scsi_vpd_inquiry - Request a device provide us with a VPD page 781 * scsi_vpd_inquiry - Request a device provide us with a VPD page
902 * @sdev: The device to ask 782 * @sdev: The device to ask
903 * @buffer: Where to put the result 783 * @buffer: Where to put the result
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 238e06f13b8a..378e0aae29ca 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2701,10 +2701,6 @@ static int scsi_debug_slave_configure(struct scsi_device *sdp)
2701 if (NULL == devip) 2701 if (NULL == devip)
2702 return 1; /* no resources, will be marked offline */ 2702 return 1; /* no resources, will be marked offline */
2703 sdp->hostdata = devip; 2703 sdp->hostdata = devip;
2704 sdp->tagged_supported = 1;
2705 if (sdp->host->cmd_per_lun)
2706 scsi_adjust_queue_depth(sdp, DEF_TAGGED_QUEUING,
2707 DEF_CMD_PER_LUN);
2708 blk_queue_max_segment_size(sdp->request_queue, -1U); 2704 blk_queue_max_segment_size(sdp->request_queue, -1U);
2709 if (scsi_debug_no_uld) 2705 if (scsi_debug_no_uld)
2710 sdp->no_uld_attach = 1; 2706 sdp->no_uld_attach = 1;
@@ -4214,7 +4210,7 @@ scsi_debug_queuecommand(struct scsi_cmnd *SCpnt)
4214 case READ_CAPACITY: 4210 case READ_CAPACITY:
4215 errsts = resp_readcap(SCpnt, devip); 4211 errsts = resp_readcap(SCpnt, devip);
4216 break; 4212 break;
4217 case SERVICE_ACTION_IN: 4213 case SERVICE_ACTION_IN_16:
4218 if (cmd[1] == SAI_READ_CAPACITY_16) 4214 if (cmd[1] == SAI_READ_CAPACITY_16)
4219 errsts = resp_readcap16(SCpnt, devip); 4215 errsts = resp_readcap16(SCpnt, devip);
4220 else if (cmd[1] == SAI_GET_LBA_STATUS) { 4216 else if (cmd[1] == SAI_GET_LBA_STATUS) {
@@ -4494,7 +4490,7 @@ sdebug_change_qdepth(struct scsi_device *sdev, int qdepth, int reason)
4494 /* allow to exceed max host queued_arr elements for testing */ 4490 /* allow to exceed max host queued_arr elements for testing */
4495 if (qdepth > SCSI_DEBUG_CANQUEUE + 10) 4491 if (qdepth > SCSI_DEBUG_CANQUEUE + 10)
4496 qdepth = SCSI_DEBUG_CANQUEUE + 10; 4492 qdepth = SCSI_DEBUG_CANQUEUE + 10;
4497 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 4493 scsi_adjust_queue_depth(sdev, qdepth);
4498 } else if (reason == SCSI_QDEPTH_QFULL) 4494 } else if (reason == SCSI_QDEPTH_QFULL)
4499 scsi_track_queue_full(sdev, qdepth); 4495 scsi_track_queue_full(sdev, qdepth);
4500 else 4496 else
@@ -4532,14 +4528,7 @@ sdebug_change_qdepth(struct scsi_device *sdev, int qdepth, int reason)
4532static int 4528static int
4533sdebug_change_qtype(struct scsi_device *sdev, int qtype) 4529sdebug_change_qtype(struct scsi_device *sdev, int qtype)
4534{ 4530{
4535 if (sdev->tagged_supported) { 4531 qtype = scsi_change_queue_type(sdev, qtype);
4536 scsi_set_tag_type(sdev, qtype);
4537 if (qtype)
4538 scsi_activate_tcq(sdev, sdev->queue_depth);
4539 else
4540 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4541 } else
4542 qtype = 0;
4543 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) { 4532 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) {
4544 const char *cp; 4533 const char *cp;
4545 4534
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index bc5ff6ff9c79..96627bae753c 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -36,6 +36,7 @@
36#include <scsi/scsi_transport.h> 36#include <scsi/scsi_transport.h>
37#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
38#include <scsi/scsi_ioctl.h> 38#include <scsi/scsi_ioctl.h>
39#include <scsi/sg.h>
39 40
40#include "scsi_priv.h" 41#include "scsi_priv.h"
41#include "scsi_logging.h" 42#include "scsi_logging.h"
@@ -157,8 +158,9 @@ scmd_eh_abort_handler(struct work_struct *work)
157 } else { 158 } else {
158 SCSI_LOG_ERROR_RECOVERY(3, 159 SCSI_LOG_ERROR_RECOVERY(3,
159 scmd_printk(KERN_INFO, scmd, 160 scmd_printk(KERN_INFO, scmd,
160 "scmd %p abort failed, rtn %d\n", 161 "scmd %p abort %s\n", scmd,
161 scmd, rtn)); 162 (rtn == FAST_IO_FAIL) ?
163 "not send" : "failed"));
162 } 164 }
163 } 165 }
164 166
@@ -355,7 +357,7 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
355 357
356 if (cmd_cancel || cmd_failed) { 358 if (cmd_cancel || cmd_failed) {
357 SCSI_LOG_ERROR_RECOVERY(3, 359 SCSI_LOG_ERROR_RECOVERY(3,
358 sdev_printk(KERN_INFO, sdev, 360 shost_printk(KERN_INFO, shost,
359 "%s: cmds failed: %d, cancel: %d\n", 361 "%s: cmds failed: %d, cancel: %d\n",
360 __func__, cmd_failed, 362 __func__, cmd_failed,
361 cmd_cancel)); 363 cmd_cancel));
@@ -869,7 +871,24 @@ static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
869 return rtn; 871 return rtn;
870} 872}
871 873
872static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt, struct scsi_cmnd *scmd) 874/**
875 * scsi_try_to_abort_cmd - Ask host to abort a SCSI command
876 * @scmd: SCSI cmd used to send a target reset
877 *
878 * Return value:
879 * SUCCESS, FAILED, or FAST_IO_FAIL
880 *
881 * Notes:
882 * SUCCESS does not necessarily indicate that the command
883 * has been aborted; it only indicates that the LLDDs
884 * has cleared all references to that command.
885 * LLDDs should return FAILED only if an abort was required
886 * but could not be executed. LLDDs should return FAST_IO_FAIL
887 * if the device is temporarily unavailable (eg due to a
888 * link down on FibreChannel)
889 */
890static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt,
891 struct scsi_cmnd *scmd)
873{ 892{
874 if (!hostt->eh_abort_handler) 893 if (!hostt->eh_abort_handler)
875 return FAILED; 894 return FAILED;
@@ -1156,9 +1175,9 @@ int scsi_eh_get_sense(struct list_head *work_q,
1156 shost = scmd->device->host; 1175 shost = scmd->device->host;
1157 if (scsi_host_eh_past_deadline(shost)) { 1176 if (scsi_host_eh_past_deadline(shost)) {
1158 SCSI_LOG_ERROR_RECOVERY(3, 1177 SCSI_LOG_ERROR_RECOVERY(3,
1159 shost_printk(KERN_INFO, shost, 1178 scmd_printk(KERN_INFO, scmd,
1160 "skip %s, past eh deadline\n", 1179 "%s: skip request sense, past eh deadline\n",
1161 __func__)); 1180 current->comm));
1162 break; 1181 break;
1163 } 1182 }
1164 if (status_byte(scmd->result) != CHECK_CONDITION) 1183 if (status_byte(scmd->result) != CHECK_CONDITION)
@@ -1180,7 +1199,7 @@ int scsi_eh_get_sense(struct list_head *work_q,
1180 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, 1199 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
1181 "sense requested for %p result %x\n", 1200 "sense requested for %p result %x\n",
1182 scmd, scmd->result)); 1201 scmd, scmd->result));
1183 SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense("bh", scmd)); 1202 SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd));
1184 1203
1185 rtn = scsi_decide_disposition(scmd); 1204 rtn = scsi_decide_disposition(scmd);
1186 1205
@@ -1265,9 +1284,9 @@ static int scsi_eh_test_devices(struct list_head *cmd_list,
1265 /* Push items back onto work_q */ 1284 /* Push items back onto work_q */
1266 list_splice_init(cmd_list, work_q); 1285 list_splice_init(cmd_list, work_q);
1267 SCSI_LOG_ERROR_RECOVERY(3, 1286 SCSI_LOG_ERROR_RECOVERY(3,
1268 shost_printk(KERN_INFO, sdev->host, 1287 sdev_printk(KERN_INFO, sdev,
1269 "skip %s, past eh deadline", 1288 "%s: skip test device, past eh deadline",
1270 __func__)); 1289 current->comm));
1271 break; 1290 break;
1272 } 1291 }
1273 } 1292 }
@@ -1318,21 +1337,20 @@ static int scsi_eh_abort_cmds(struct list_head *work_q,
1318 if (scsi_host_eh_past_deadline(shost)) { 1337 if (scsi_host_eh_past_deadline(shost)) {
1319 list_splice_init(&check_list, work_q); 1338 list_splice_init(&check_list, work_q);
1320 SCSI_LOG_ERROR_RECOVERY(3, 1339 SCSI_LOG_ERROR_RECOVERY(3,
1321 shost_printk(KERN_INFO, shost, 1340 scmd_printk(KERN_INFO, scmd,
1322 "skip %s, past eh deadline\n", 1341 "%s: skip aborting cmd, past eh deadline\n",
1323 __func__)); 1342 current->comm));
1324 return list_empty(work_q); 1343 return list_empty(work_q);
1325 } 1344 }
1326 SCSI_LOG_ERROR_RECOVERY(3, 1345 SCSI_LOG_ERROR_RECOVERY(3,
1327 shost_printk(KERN_INFO, shost, 1346 scmd_printk(KERN_INFO, scmd,
1328 "%s: aborting cmd: 0x%p\n", 1347 "%s: aborting cmd\n", current->comm));
1329 current->comm, scmd));
1330 rtn = scsi_try_to_abort_cmd(shost->hostt, scmd); 1348 rtn = scsi_try_to_abort_cmd(shost->hostt, scmd);
1331 if (rtn == FAILED) { 1349 if (rtn == FAILED) {
1332 SCSI_LOG_ERROR_RECOVERY(3, 1350 SCSI_LOG_ERROR_RECOVERY(3,
1333 shost_printk(KERN_INFO, shost, 1351 scmd_printk(KERN_INFO, scmd,
1334 "%s: aborting cmd failed: 0x%p\n", 1352 "%s: aborting cmd failed\n",
1335 current->comm, scmd)); 1353 current->comm));
1336 list_splice_init(&check_list, work_q); 1354 list_splice_init(&check_list, work_q);
1337 return list_empty(work_q); 1355 return list_empty(work_q);
1338 } 1356 }
@@ -1390,9 +1408,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
1390 shost_for_each_device(sdev, shost) { 1408 shost_for_each_device(sdev, shost) {
1391 if (scsi_host_eh_past_deadline(shost)) { 1409 if (scsi_host_eh_past_deadline(shost)) {
1392 SCSI_LOG_ERROR_RECOVERY(3, 1410 SCSI_LOG_ERROR_RECOVERY(3,
1393 shost_printk(KERN_INFO, shost, 1411 sdev_printk(KERN_INFO, sdev,
1394 "skip %s, past eh deadline\n", 1412 "%s: skip START_UNIT, past eh deadline\n",
1395 __func__)); 1413 current->comm));
1396 break; 1414 break;
1397 } 1415 }
1398 stu_scmd = NULL; 1416 stu_scmd = NULL;
@@ -1407,9 +1425,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
1407 continue; 1425 continue;
1408 1426
1409 SCSI_LOG_ERROR_RECOVERY(3, 1427 SCSI_LOG_ERROR_RECOVERY(3,
1410 shost_printk(KERN_INFO, shost, 1428 sdev_printk(KERN_INFO, sdev,
1411 "%s: Sending START_UNIT to sdev: 0x%p\n", 1429 "%s: Sending START_UNIT\n",
1412 current->comm, sdev)); 1430 current->comm));
1413 1431
1414 if (!scsi_eh_try_stu(stu_scmd)) { 1432 if (!scsi_eh_try_stu(stu_scmd)) {
1415 if (!scsi_device_online(sdev) || 1433 if (!scsi_device_online(sdev) ||
@@ -1423,9 +1441,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
1423 } 1441 }
1424 } else { 1442 } else {
1425 SCSI_LOG_ERROR_RECOVERY(3, 1443 SCSI_LOG_ERROR_RECOVERY(3,
1426 shost_printk(KERN_INFO, shost, 1444 sdev_printk(KERN_INFO, sdev,
1427 "%s: START_UNIT failed to sdev:" 1445 "%s: START_UNIT failed\n",
1428 " 0x%p\n", current->comm, sdev)); 1446 current->comm));
1429 } 1447 }
1430 } 1448 }
1431 1449
@@ -1456,9 +1474,9 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
1456 shost_for_each_device(sdev, shost) { 1474 shost_for_each_device(sdev, shost) {
1457 if (scsi_host_eh_past_deadline(shost)) { 1475 if (scsi_host_eh_past_deadline(shost)) {
1458 SCSI_LOG_ERROR_RECOVERY(3, 1476 SCSI_LOG_ERROR_RECOVERY(3,
1459 shost_printk(KERN_INFO, shost, 1477 sdev_printk(KERN_INFO, sdev,
1460 "skip %s, past eh deadline\n", 1478 "%s: skip BDR, past eh deadline\n",
1461 __func__)); 1479 current->comm));
1462 break; 1480 break;
1463 } 1481 }
1464 bdr_scmd = NULL; 1482 bdr_scmd = NULL;
@@ -1472,9 +1490,8 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
1472 continue; 1490 continue;
1473 1491
1474 SCSI_LOG_ERROR_RECOVERY(3, 1492 SCSI_LOG_ERROR_RECOVERY(3,
1475 shost_printk(KERN_INFO, shost, 1493 sdev_printk(KERN_INFO, sdev,
1476 "%s: Sending BDR sdev: 0x%p\n", 1494 "%s: Sending BDR\n", current->comm));
1477 current->comm, sdev));
1478 rtn = scsi_try_bus_device_reset(bdr_scmd); 1495 rtn = scsi_try_bus_device_reset(bdr_scmd);
1479 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { 1496 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
1480 if (!scsi_device_online(sdev) || 1497 if (!scsi_device_online(sdev) ||
@@ -1490,9 +1507,8 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
1490 } 1507 }
1491 } else { 1508 } else {
1492 SCSI_LOG_ERROR_RECOVERY(3, 1509 SCSI_LOG_ERROR_RECOVERY(3,
1493 shost_printk(KERN_INFO, shost, 1510 sdev_printk(KERN_INFO, sdev,
1494 "%s: BDR failed sdev: 0x%p\n", 1511 "%s: BDR failed\n", current->comm));
1495 current->comm, sdev));
1496 } 1512 }
1497 } 1513 }
1498 1514
@@ -1528,8 +1544,8 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost,
1528 list_splice_init(&tmp_list, work_q); 1544 list_splice_init(&tmp_list, work_q);
1529 SCSI_LOG_ERROR_RECOVERY(3, 1545 SCSI_LOG_ERROR_RECOVERY(3,
1530 shost_printk(KERN_INFO, shost, 1546 shost_printk(KERN_INFO, shost,
1531 "skip %s, past eh deadline\n", 1547 "%s: Skip target reset, past eh deadline\n",
1532 __func__)); 1548 current->comm));
1533 return list_empty(work_q); 1549 return list_empty(work_q);
1534 } 1550 }
1535 1551
@@ -1591,8 +1607,8 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
1591 list_splice_init(&check_list, work_q); 1607 list_splice_init(&check_list, work_q);
1592 SCSI_LOG_ERROR_RECOVERY(3, 1608 SCSI_LOG_ERROR_RECOVERY(3,
1593 shost_printk(KERN_INFO, shost, 1609 shost_printk(KERN_INFO, shost,
1594 "skip %s, past eh deadline\n", 1610 "%s: skip BRST, past eh deadline\n",
1595 __func__)); 1611 current->comm));
1596 return list_empty(work_q); 1612 return list_empty(work_q);
1597 } 1613 }
1598 1614
@@ -2193,9 +2209,9 @@ int scsi_error_handler(void *data)
2193 */ 2209 */
2194 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) { 2210 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) {
2195 SCSI_LOG_ERROR_RECOVERY(1, 2211 SCSI_LOG_ERROR_RECOVERY(1,
2196 printk(KERN_ERR "Error handler scsi_eh_%d " 2212 shost_printk(KERN_ERR, shost,
2197 "unable to autoresume\n", 2213 "scsi_eh_%d: unable to autoresume\n",
2198 shost->host_no)); 2214 shost->host_no));
2199 continue; 2215 continue;
2200 } 2216 }
2201 2217
@@ -2296,42 +2312,34 @@ scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
2296{ 2312{
2297} 2313}
2298 2314
2299/* 2315/**
2300 * Function: scsi_reset_provider 2316 * scsi_ioctl_reset: explicitly reset a host/bus/target/device
2301 * 2317 * @dev: scsi_device to operate on
2302 * Purpose: Send requested reset to a bus or device at any phase. 2318 * @arg: reset type (see sg.h)
2303 *
2304 * Arguments: device - device to send reset to
2305 * flag - reset type (see scsi.h)
2306 *
2307 * Returns: SUCCESS/FAILURE.
2308 *
2309 * Notes: This is used by the SCSI Generic driver to provide
2310 * Bus/Device reset capability.
2311 */ 2319 */
2312int 2320int
2313scsi_reset_provider(struct scsi_device *dev, int flag) 2321scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
2314{ 2322{
2315 struct scsi_cmnd *scmd; 2323 struct scsi_cmnd *scmd;
2316 struct Scsi_Host *shost = dev->host; 2324 struct Scsi_Host *shost = dev->host;
2317 struct request req; 2325 struct request req;
2318 unsigned long flags; 2326 unsigned long flags;
2319 int rtn; 2327 int error = 0, rtn, val;
2320 2328
2321 if (scsi_autopm_get_host(shost) < 0) 2329 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
2322 return FAILED; 2330 return -EACCES;
2323 2331
2324 if (!get_device(&dev->sdev_gendev)) { 2332 error = get_user(val, arg);
2325 rtn = FAILED; 2333 if (error)
2326 goto out_put_autopm_host; 2334 return error;
2327 } 2335
2336 if (scsi_autopm_get_host(shost) < 0)
2337 return -EIO;
2328 2338
2339 error = -EIO;
2329 scmd = scsi_get_command(dev, GFP_KERNEL); 2340 scmd = scsi_get_command(dev, GFP_KERNEL);
2330 if (!scmd) { 2341 if (!scmd)
2331 rtn = FAILED;
2332 put_device(&dev->sdev_gendev);
2333 goto out_put_autopm_host; 2342 goto out_put_autopm_host;
2334 }
2335 2343
2336 blk_rq_init(NULL, &req); 2344 blk_rq_init(NULL, &req);
2337 scmd->request = &req; 2345 scmd->request = &req;
@@ -2349,29 +2357,37 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
2349 shost->tmf_in_progress = 1; 2357 shost->tmf_in_progress = 1;
2350 spin_unlock_irqrestore(shost->host_lock, flags); 2358 spin_unlock_irqrestore(shost->host_lock, flags);
2351 2359
2352 switch (flag) { 2360 switch (val & ~SG_SCSI_RESET_NO_ESCALATE) {
2353 case SCSI_TRY_RESET_DEVICE: 2361 case SG_SCSI_RESET_NOTHING:
2362 rtn = SUCCESS;
2363 break;
2364 case SG_SCSI_RESET_DEVICE:
2354 rtn = scsi_try_bus_device_reset(scmd); 2365 rtn = scsi_try_bus_device_reset(scmd);
2355 if (rtn == SUCCESS) 2366 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2356 break; 2367 break;
2357 /* FALLTHROUGH */ 2368 /* FALLTHROUGH */
2358 case SCSI_TRY_RESET_TARGET: 2369 case SG_SCSI_RESET_TARGET:
2359 rtn = scsi_try_target_reset(scmd); 2370 rtn = scsi_try_target_reset(scmd);
2360 if (rtn == SUCCESS) 2371 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2361 break; 2372 break;
2362 /* FALLTHROUGH */ 2373 /* FALLTHROUGH */
2363 case SCSI_TRY_RESET_BUS: 2374 case SG_SCSI_RESET_BUS:
2364 rtn = scsi_try_bus_reset(scmd); 2375 rtn = scsi_try_bus_reset(scmd);
2365 if (rtn == SUCCESS) 2376 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2366 break; 2377 break;
2367 /* FALLTHROUGH */ 2378 /* FALLTHROUGH */
2368 case SCSI_TRY_RESET_HOST: 2379 case SG_SCSI_RESET_HOST:
2369 rtn = scsi_try_host_reset(scmd); 2380 rtn = scsi_try_host_reset(scmd);
2370 break; 2381 if (rtn == SUCCESS)
2382 break;
2371 default: 2383 default:
2384 /* FALLTHROUGH */
2372 rtn = FAILED; 2385 rtn = FAILED;
2386 break;
2373 } 2387 }
2374 2388
2389 error = (rtn == SUCCESS) ? 0 : -EIO;
2390
2375 spin_lock_irqsave(shost->host_lock, flags); 2391 spin_lock_irqsave(shost->host_lock, flags);
2376 shost->tmf_in_progress = 0; 2392 shost->tmf_in_progress = 0;
2377 spin_unlock_irqrestore(shost->host_lock, flags); 2393 spin_unlock_irqrestore(shost->host_lock, flags);
@@ -2385,15 +2401,15 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
2385 "waking up host to restart after TMF\n")); 2401 "waking up host to restart after TMF\n"));
2386 2402
2387 wake_up(&shost->host_wait); 2403 wake_up(&shost->host_wait);
2388
2389 scsi_run_host_queues(shost); 2404 scsi_run_host_queues(shost);
2390 2405
2391 scsi_next_command(scmd); 2406 scsi_put_command(scmd);
2407
2392out_put_autopm_host: 2408out_put_autopm_host:
2393 scsi_autopm_put_host(shost); 2409 scsi_autopm_put_host(shost);
2394 return rtn; 2410 return error;
2395} 2411}
2396EXPORT_SYMBOL(scsi_reset_provider); 2412EXPORT_SYMBOL(scsi_ioctl_reset);
2397 2413
2398/** 2414/**
2399 * scsi_normalize_sense - normalize main elements from either fixed or 2415 * scsi_normalize_sense - normalize main elements from either fixed or
@@ -2412,20 +2428,20 @@ EXPORT_SYMBOL(scsi_reset_provider);
2412 * responded to a SCSI command with the CHECK_CONDITION status. 2428 * responded to a SCSI command with the CHECK_CONDITION status.
2413 * 2429 *
2414 * Return value: 2430 * Return value:
2415 * 1 if valid sense data information found, else 0; 2431 * true if valid sense data information found, else false;
2416 */ 2432 */
2417int scsi_normalize_sense(const u8 *sense_buffer, int sb_len, 2433bool scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
2418 struct scsi_sense_hdr *sshdr) 2434 struct scsi_sense_hdr *sshdr)
2419{ 2435{
2420 if (!sense_buffer || !sb_len) 2436 if (!sense_buffer || !sb_len)
2421 return 0; 2437 return false;
2422 2438
2423 memset(sshdr, 0, sizeof(struct scsi_sense_hdr)); 2439 memset(sshdr, 0, sizeof(struct scsi_sense_hdr));
2424 2440
2425 sshdr->response_code = (sense_buffer[0] & 0x7f); 2441 sshdr->response_code = (sense_buffer[0] & 0x7f);
2426 2442
2427 if (!scsi_sense_valid(sshdr)) 2443 if (!scsi_sense_valid(sshdr))
2428 return 0; 2444 return false;
2429 2445
2430 if (sshdr->response_code >= 0x72) { 2446 if (sshdr->response_code >= 0x72) {
2431 /* 2447 /*
@@ -2455,12 +2471,12 @@ int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
2455 } 2471 }
2456 } 2472 }
2457 2473
2458 return 1; 2474 return true;
2459} 2475}
2460EXPORT_SYMBOL(scsi_normalize_sense); 2476EXPORT_SYMBOL(scsi_normalize_sense);
2461 2477
2462int scsi_command_normalize_sense(struct scsi_cmnd *cmd, 2478bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
2463 struct scsi_sense_hdr *sshdr) 2479 struct scsi_sense_hdr *sshdr)
2464{ 2480{
2465 return scsi_normalize_sense(cmd->sense_buffer, 2481 return scsi_normalize_sense(cmd->sense_buffer,
2466 SCSI_SENSE_BUFFERSIZE, sshdr); 2482 SCSI_SENSE_BUFFERSIZE, sshdr);
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 1aaaf43c6803..c4f7b56fa6f6 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -126,7 +126,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
126 sdev_printk(KERN_INFO, sdev, 126 sdev_printk(KERN_INFO, sdev,
127 "ioctl_internal_command return code = %x\n", 127 "ioctl_internal_command return code = %x\n",
128 result); 128 result);
129 scsi_print_sense_hdr(" ", &sshdr); 129 scsi_print_sense_hdr(sdev, NULL, &sshdr);
130 break; 130 break;
131 } 131 }
132 } 132 }
@@ -200,19 +200,6 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
200{ 200{
201 char scsi_cmd[MAX_COMMAND_SIZE]; 201 char scsi_cmd[MAX_COMMAND_SIZE];
202 202
203 /* No idea how this happens.... */
204 if (!sdev)
205 return -ENXIO;
206
207 /*
208 * If we are in the middle of error recovery, don't let anyone
209 * else try and use this device. Also, if error recovery fails, it
210 * may try and take the device offline, in which case all further
211 * access to the device is prohibited.
212 */
213 if (!scsi_block_when_processing_errors(sdev))
214 return -ENODEV;
215
216 /* Check for deprecated ioctls ... all the ioctls which don't 203 /* Check for deprecated ioctls ... all the ioctls which don't
217 * follow the new unique numbering scheme are deprecated */ 204 * follow the new unique numbering scheme are deprecated */
218 switch (cmd) { 205 switch (cmd) {
@@ -273,6 +260,8 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
273 START_STOP_TIMEOUT, NORMAL_RETRIES); 260 START_STOP_TIMEOUT, NORMAL_RETRIES);
274 case SCSI_IOCTL_GET_PCI: 261 case SCSI_IOCTL_GET_PCI:
275 return scsi_ioctl_get_pci(sdev, arg); 262 return scsi_ioctl_get_pci(sdev, arg);
263 case SG_SCSI_RESET:
264 return scsi_ioctl_reset(sdev, arg);
276 default: 265 default:
277 if (sdev->host->hostt->ioctl) 266 if (sdev->host->hostt->ioctl)
278 return sdev->host->hostt->ioctl(sdev, cmd, arg); 267 return sdev->host->hostt->ioctl(sdev, cmd, arg);
@@ -281,55 +270,20 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
281} 270}
282EXPORT_SYMBOL(scsi_ioctl); 271EXPORT_SYMBOL(scsi_ioctl);
283 272
284/** 273/*
285 * scsi_nonblockable_ioctl() - Handle SG_SCSI_RESET 274 * We can process a reset even when a device isn't fully operable.
286 * @sdev: scsi device receiving ioctl
287 * @cmd: Must be SC_SCSI_RESET
288 * @arg: pointer to int containing SG_SCSI_RESET_{DEVICE,BUS,HOST}
289 * @ndelay: file mode O_NDELAY flag
290 */ 275 */
291int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd, 276int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev, int cmd,
292 void __user *arg, int ndelay) 277 bool ndelay)
293{ 278{
294 int val, result; 279 if (cmd == SG_SCSI_RESET && ndelay) {
295
296 /* The first set of iocts may be executed even if we're doing
297 * error processing, as long as the device was opened
298 * non-blocking */
299 if (ndelay) {
300 if (scsi_host_in_recovery(sdev->host)) 280 if (scsi_host_in_recovery(sdev->host))
281 return -EAGAIN;
282 } else {
283 if (!scsi_block_when_processing_errors(sdev))
301 return -ENODEV; 284 return -ENODEV;
302 } else if (!scsi_block_when_processing_errors(sdev))
303 return -ENODEV;
304
305 switch (cmd) {
306 case SG_SCSI_RESET:
307 result = get_user(val, (int __user *)arg);
308 if (result)
309 return result;
310 if (val == SG_SCSI_RESET_NOTHING)
311 return 0;
312 switch (val) {
313 case SG_SCSI_RESET_DEVICE:
314 val = SCSI_TRY_RESET_DEVICE;
315 break;
316 case SG_SCSI_RESET_TARGET:
317 val = SCSI_TRY_RESET_TARGET;
318 break;
319 case SG_SCSI_RESET_BUS:
320 val = SCSI_TRY_RESET_BUS;
321 break;
322 case SG_SCSI_RESET_HOST:
323 val = SCSI_TRY_RESET_HOST;
324 break;
325 default:
326 return -EINVAL;
327 }
328 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
329 return -EACCES;
330 return (scsi_reset_provider(sdev, val) ==
331 SUCCESS) ? 0 : -EIO;
332 } 285 }
333 return -ENODEV; 286
287 return 0;
334} 288}
335EXPORT_SYMBOL(scsi_nonblockable_ioctl); 289EXPORT_SYMBOL_GPL(scsi_ioctl_block_when_processing_errors);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 50a6e1ac8d9c..7e3d954c9cac 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -22,6 +22,7 @@
22#include <linux/hardirq.h> 22#include <linux/hardirq.h>
23#include <linux/scatterlist.h> 23#include <linux/scatterlist.h>
24#include <linux/blk-mq.h> 24#include <linux/blk-mq.h>
25#include <linux/ratelimit.h>
25 26
26#include <scsi/scsi.h> 27#include <scsi/scsi.h>
27#include <scsi/scsi_cmnd.h> 28#include <scsi/scsi_cmnd.h>
@@ -47,7 +48,7 @@ struct scsi_host_sg_pool {
47 mempool_t *pool; 48 mempool_t *pool;
48}; 49};
49 50
50#define SP(x) { x, "sgpool-" __stringify(x) } 51#define SP(x) { .size = x, "sgpool-" __stringify(x) }
51#if (SCSI_MAX_SG_SEGMENTS < 32) 52#if (SCSI_MAX_SG_SEGMENTS < 32)
52#error SCSI_MAX_SG_SEGMENTS is too small (must be 32 or greater) 53#error SCSI_MAX_SG_SEGMENTS is too small (must be 32 or greater)
53#endif 54#endif
@@ -542,17 +543,6 @@ static void scsi_requeue_command(struct request_queue *q, struct scsi_cmnd *cmd)
542 put_device(&sdev->sdev_gendev); 543 put_device(&sdev->sdev_gendev);
543} 544}
544 545
545void scsi_next_command(struct scsi_cmnd *cmd)
546{
547 struct scsi_device *sdev = cmd->device;
548 struct request_queue *q = sdev->request_queue;
549
550 scsi_put_command(cmd);
551 scsi_run_queue(q);
552
553 put_device(&sdev->sdev_gendev);
554}
555
556void scsi_run_host_queues(struct Scsi_Host *shost) 546void scsi_run_host_queues(struct Scsi_Host *shost)
557{ 547{
558 struct scsi_device *sdev; 548 struct scsi_device *sdev;
@@ -598,10 +588,10 @@ static void scsi_free_sgtable(struct scsi_data_buffer *sdb, bool mq)
598 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free); 588 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free);
599} 589}
600 590
601static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, 591static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, bool mq)
602 gfp_t gfp_mask, bool mq)
603{ 592{
604 struct scatterlist *first_chunk = NULL; 593 struct scatterlist *first_chunk = NULL;
594 gfp_t gfp_mask = mq ? GFP_NOIO : GFP_ATOMIC;
605 int ret; 595 int ret;
606 596
607 BUG_ON(!nents); 597 BUG_ON(!nents);
@@ -730,8 +720,6 @@ static bool scsi_end_request(struct request *req, int error,
730 kblockd_schedule_work(&sdev->requeue_work); 720 kblockd_schedule_work(&sdev->requeue_work);
731 else 721 else
732 blk_mq_start_stopped_hw_queues(q, true); 722 blk_mq_start_stopped_hw_queues(q, true);
733
734 put_device(&sdev->sdev_gendev);
735 } else { 723 } else {
736 unsigned long flags; 724 unsigned long flags;
737 725
@@ -743,9 +731,12 @@ static bool scsi_end_request(struct request *req, int error,
743 spin_unlock_irqrestore(q->queue_lock, flags); 731 spin_unlock_irqrestore(q->queue_lock, flags);
744 732
745 scsi_release_buffers(cmd); 733 scsi_release_buffers(cmd);
746 scsi_next_command(cmd); 734
735 scsi_put_command(cmd);
736 scsi_run_queue(q);
747 } 737 }
748 738
739 put_device(&sdev->sdev_gendev);
749 return false; 740 return false;
750} 741}
751 742
@@ -831,8 +822,8 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
831 struct request *req = cmd->request; 822 struct request *req = cmd->request;
832 int error = 0; 823 int error = 0;
833 struct scsi_sense_hdr sshdr; 824 struct scsi_sense_hdr sshdr;
834 int sense_valid = 0; 825 bool sense_valid = false;
835 int sense_deferred = 0; 826 int sense_deferred = 0, level = 0;
836 enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY, 827 enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY,
837 ACTION_DELAYED_RETRY} action; 828 ACTION_DELAYED_RETRY} action;
838 unsigned long wait_for = (cmd->allowed + 1) * req->timeout; 829 unsigned long wait_for = (cmd->allowed + 1) * req->timeout;
@@ -912,7 +903,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
912 if ((sshdr.asc == 0x0) && (sshdr.ascq == 0x1d)) 903 if ((sshdr.asc == 0x0) && (sshdr.ascq == 0x1d))
913 ; 904 ;
914 else if (!(req->cmd_flags & REQ_QUIET)) 905 else if (!(req->cmd_flags & REQ_QUIET))
915 scsi_print_sense("", cmd); 906 scsi_print_sense(cmd);
916 result = 0; 907 result = 0;
917 /* BLOCK_PC may have set error */ 908 /* BLOCK_PC may have set error */
918 error = 0; 909 error = 0;
@@ -1039,10 +1030,24 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1039 case ACTION_FAIL: 1030 case ACTION_FAIL:
1040 /* Give up and fail the remainder of the request */ 1031 /* Give up and fail the remainder of the request */
1041 if (!(req->cmd_flags & REQ_QUIET)) { 1032 if (!(req->cmd_flags & REQ_QUIET)) {
1042 scsi_print_result(cmd); 1033 static DEFINE_RATELIMIT_STATE(_rs,
1043 if (driver_byte(result) & DRIVER_SENSE) 1034 DEFAULT_RATELIMIT_INTERVAL,
1044 scsi_print_sense("", cmd); 1035 DEFAULT_RATELIMIT_BURST);
1045 scsi_print_command(cmd); 1036
1037 if (unlikely(scsi_logging_level))
1038 level = SCSI_LOG_LEVEL(SCSI_LOG_MLCOMPLETE_SHIFT,
1039 SCSI_LOG_MLCOMPLETE_BITS);
1040
1041 /*
1042 * if logging is enabled the failure will be printed
1043 * in scsi_log_completion(), so avoid duplicate messages
1044 */
1045 if (!level && __ratelimit(&_rs)) {
1046 scsi_print_result(cmd, NULL, FAILED);
1047 if (driver_byte(result) & DRIVER_SENSE)
1048 scsi_print_sense(cmd);
1049 scsi_print_command(cmd);
1050 }
1046 } 1051 }
1047 if (!scsi_end_request(req, error, blk_rq_err_bytes(req), 0)) 1052 if (!scsi_end_request(req, error, blk_rq_err_bytes(req), 0))
1048 return; 1053 return;
@@ -1072,8 +1077,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1072 } 1077 }
1073} 1078}
1074 1079
1075static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb, 1080static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb)
1076 gfp_t gfp_mask)
1077{ 1081{
1078 int count; 1082 int count;
1079 1083
@@ -1081,7 +1085,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
1081 * If sg table allocation fails, requeue request later. 1085 * If sg table allocation fails, requeue request later.
1082 */ 1086 */
1083 if (unlikely(scsi_alloc_sgtable(sdb, req->nr_phys_segments, 1087 if (unlikely(scsi_alloc_sgtable(sdb, req->nr_phys_segments,
1084 gfp_mask, req->mq_ctx != NULL))) 1088 req->mq_ctx != NULL)))
1085 return BLKPREP_DEFER; 1089 return BLKPREP_DEFER;
1086 1090
1087 /* 1091 /*
@@ -1106,7 +1110,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
1106 * BLKPREP_DEFER if the failure is retryable 1110 * BLKPREP_DEFER if the failure is retryable
1107 * BLKPREP_KILL if the failure is fatal 1111 * BLKPREP_KILL if the failure is fatal
1108 */ 1112 */
1109int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask) 1113int scsi_init_io(struct scsi_cmnd *cmd)
1110{ 1114{
1111 struct scsi_device *sdev = cmd->device; 1115 struct scsi_device *sdev = cmd->device;
1112 struct request *rq = cmd->request; 1116 struct request *rq = cmd->request;
@@ -1115,7 +1119,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1115 1119
1116 BUG_ON(!rq->nr_phys_segments); 1120 BUG_ON(!rq->nr_phys_segments);
1117 1121
1118 error = scsi_init_sgtable(rq, &cmd->sdb, gfp_mask); 1122 error = scsi_init_sgtable(rq, &cmd->sdb);
1119 if (error) 1123 if (error)
1120 goto err_exit; 1124 goto err_exit;
1121 1125
@@ -1131,8 +1135,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1131 rq->next_rq->special = bidi_sdb; 1135 rq->next_rq->special = bidi_sdb;
1132 } 1136 }
1133 1137
1134 error = scsi_init_sgtable(rq->next_rq, rq->next_rq->special, 1138 error = scsi_init_sgtable(rq->next_rq, rq->next_rq->special);
1135 GFP_ATOMIC);
1136 if (error) 1139 if (error)
1137 goto err_exit; 1140 goto err_exit;
1138 } 1141 }
@@ -1144,7 +1147,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1144 BUG_ON(prot_sdb == NULL); 1147 BUG_ON(prot_sdb == NULL);
1145 ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio); 1148 ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio);
1146 1149
1147 if (scsi_alloc_sgtable(prot_sdb, ivecs, gfp_mask, is_mq)) { 1150 if (scsi_alloc_sgtable(prot_sdb, ivecs, is_mq)) {
1148 error = BLKPREP_DEFER; 1151 error = BLKPREP_DEFER;
1149 goto err_exit; 1152 goto err_exit;
1150 } 1153 }
@@ -1213,7 +1216,7 @@ static int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
1213 * submit a request without an attached bio. 1216 * submit a request without an attached bio.
1214 */ 1217 */
1215 if (req->bio) { 1218 if (req->bio) {
1216 int ret = scsi_init_io(cmd, GFP_ATOMIC); 1219 int ret = scsi_init_io(cmd);
1217 if (unlikely(ret)) 1220 if (unlikely(ret))
1218 return ret; 1221 return ret;
1219 } else { 1222 } else {
@@ -1638,6 +1641,87 @@ static void scsi_softirq_done(struct request *rq)
1638} 1641}
1639 1642
1640/** 1643/**
1644 * scsi_dispatch_command - Dispatch a command to the low-level driver.
1645 * @cmd: command block we are dispatching.
1646 *
1647 * Return: nonzero return request was rejected and device's queue needs to be
1648 * plugged.
1649 */
1650static int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
1651{
1652 struct Scsi_Host *host = cmd->device->host;
1653 int rtn = 0;
1654
1655 atomic_inc(&cmd->device->iorequest_cnt);
1656
1657 /* check if the device is still usable */
1658 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
1659 /* in SDEV_DEL we error all commands. DID_NO_CONNECT
1660 * returns an immediate error upwards, and signals
1661 * that the device is no longer present */
1662 cmd->result = DID_NO_CONNECT << 16;
1663 goto done;
1664 }
1665
1666 /* Check to see if the scsi lld made this device blocked. */
1667 if (unlikely(scsi_device_blocked(cmd->device))) {
1668 /*
1669 * in blocked state, the command is just put back on
1670 * the device queue. The suspend state has already
1671 * blocked the queue so future requests should not
1672 * occur until the device transitions out of the
1673 * suspend state.
1674 */
1675 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
1676 "queuecommand : device blocked\n"));
1677 return SCSI_MLQUEUE_DEVICE_BUSY;
1678 }
1679
1680 /* Store the LUN value in cmnd, if needed. */
1681 if (cmd->device->lun_in_cdb)
1682 cmd->cmnd[1] = (cmd->cmnd[1] & 0x1f) |
1683 (cmd->device->lun << 5 & 0xe0);
1684
1685 scsi_log_send(cmd);
1686
1687 /*
1688 * Before we queue this command, check if the command
1689 * length exceeds what the host adapter can handle.
1690 */
1691 if (cmd->cmd_len > cmd->device->host->max_cmd_len) {
1692 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
1693 "queuecommand : command too long. "
1694 "cdb_size=%d host->max_cmd_len=%d\n",
1695 cmd->cmd_len, cmd->device->host->max_cmd_len));
1696 cmd->result = (DID_ABORT << 16);
1697 goto done;
1698 }
1699
1700 if (unlikely(host->shost_state == SHOST_DEL)) {
1701 cmd->result = (DID_NO_CONNECT << 16);
1702 goto done;
1703
1704 }
1705
1706 trace_scsi_dispatch_cmd_start(cmd);
1707 rtn = host->hostt->queuecommand(host, cmd);
1708 if (rtn) {
1709 trace_scsi_dispatch_cmd_error(cmd, rtn);
1710 if (rtn != SCSI_MLQUEUE_DEVICE_BUSY &&
1711 rtn != SCSI_MLQUEUE_TARGET_BUSY)
1712 rtn = SCSI_MLQUEUE_HOST_BUSY;
1713
1714 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
1715 "queuecommand : request rejected\n"));
1716 }
1717
1718 return rtn;
1719 done:
1720 cmd->scsi_done(cmd);
1721 return 0;
1722}
1723
1724/**
1641 * scsi_done - Invoke completion on finished SCSI command. 1725 * scsi_done - Invoke completion on finished SCSI command.
1642 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives 1726 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
1643 * ownership back to SCSI Core -- i.e. the LLDD has finished with it. 1727 * ownership back to SCSI Core -- i.e. the LLDD has finished with it.
@@ -1725,7 +1809,7 @@ static void scsi_request_fn(struct request_queue *q)
1725 * we add the dev to the starved list so it eventually gets 1809 * we add the dev to the starved list so it eventually gets
1726 * a run when a tag is freed. 1810 * a run when a tag is freed.
1727 */ 1811 */
1728 if (blk_queue_tagged(q) && !blk_rq_tagged(req)) { 1812 if (blk_queue_tagged(q) && !(req->cmd_flags & REQ_QUEUED)) {
1729 spin_lock_irq(shost->host_lock); 1813 spin_lock_irq(shost->host_lock);
1730 if (list_empty(&sdev->starved_entry)) 1814 if (list_empty(&sdev->starved_entry))
1731 list_add_tail(&sdev->starved_entry, 1815 list_add_tail(&sdev->starved_entry,
@@ -1739,6 +1823,11 @@ static void scsi_request_fn(struct request_queue *q)
1739 1823
1740 if (!scsi_host_queue_ready(q, shost, sdev)) 1824 if (!scsi_host_queue_ready(q, shost, sdev))
1741 goto host_not_ready; 1825 goto host_not_ready;
1826
1827 if (sdev->simple_tags)
1828 cmd->flags |= SCMD_TAGGED;
1829 else
1830 cmd->flags &= ~SCMD_TAGGED;
1742 1831
1743 /* 1832 /*
1744 * Finally, initialize any error handling parameters, and set up 1833 * Finally, initialize any error handling parameters, and set up
@@ -1893,10 +1982,10 @@ static int scsi_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req,
1893 blk_mq_start_request(req); 1982 blk_mq_start_request(req);
1894 } 1983 }
1895 1984
1896 if (blk_queue_tagged(q)) 1985 if (sdev->simple_tags)
1897 req->cmd_flags |= REQ_QUEUED; 1986 cmd->flags |= SCMD_TAGGED;
1898 else 1987 else
1899 req->cmd_flags &= ~REQ_QUEUED; 1988 cmd->flags &= ~SCMD_TAGGED;
1900 1989
1901 scsi_init_cmd_errh(cmd); 1990 scsi_init_cmd_errh(cmd);
1902 cmd->scsi_done = scsi_mq_done; 1991 cmd->scsi_done = scsi_mq_done;
@@ -2091,7 +2180,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost)
2091 2180
2092 memset(&shost->tag_set, 0, sizeof(shost->tag_set)); 2181 memset(&shost->tag_set, 0, sizeof(shost->tag_set));
2093 shost->tag_set.ops = &scsi_mq_ops; 2182 shost->tag_set.ops = &scsi_mq_ops;
2094 shost->tag_set.nr_hw_queues = 1; 2183 shost->tag_set.nr_hw_queues = shost->nr_hw_queues ? : 1;
2095 shost->tag_set.queue_depth = shost->can_queue; 2184 shost->tag_set.queue_depth = shost->can_queue;
2096 shost->tag_set.cmd_size = cmd_size; 2185 shost->tag_set.cmd_size = cmd_size;
2097 shost->tag_set.numa_node = NUMA_NO_NODE; 2186 shost->tag_set.numa_node = NUMA_NO_NODE;
diff --git a/drivers/scsi/scsi_logging.h b/drivers/scsi/scsi_logging.h
index 1f65139e14f8..7fe64a847143 100644
--- a/drivers/scsi/scsi_logging.h
+++ b/drivers/scsi/scsi_logging.h
@@ -51,6 +51,7 @@ do { \
51 } while (0); \ 51 } while (0); \
52} while (0) 52} while (0)
53#else 53#else
54#define SCSI_LOG_LEVEL(SHIFT, BITS) 0
54#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) 55#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
55#endif /* CONFIG_SCSI_LOGGING */ 56#endif /* CONFIG_SCSI_LOGGING */
56 57
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 12b8e1bee7f0..2dc4a83fb84c 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -29,7 +29,6 @@ extern int scsi_init_hosts(void);
29extern void scsi_exit_hosts(void); 29extern void scsi_exit_hosts(void);
30 30
31/* scsi.c */ 31/* scsi.c */
32extern int scsi_dispatch_cmd(struct scsi_cmnd *cmd);
33extern int scsi_setup_command_freelist(struct Scsi_Host *shost); 32extern int scsi_setup_command_freelist(struct Scsi_Host *shost);
34extern void scsi_destroy_command_freelist(struct Scsi_Host *shost); 33extern void scsi_destroy_command_freelist(struct Scsi_Host *shost);
35#ifdef CONFIG_SCSI_LOGGING 34#ifdef CONFIG_SCSI_LOGGING
@@ -84,7 +83,6 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd);
84extern int scsi_maybe_unblock_host(struct scsi_device *sdev); 83extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
85extern void scsi_device_unbusy(struct scsi_device *sdev); 84extern void scsi_device_unbusy(struct scsi_device *sdev);
86extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason); 85extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason);
87extern void scsi_next_command(struct scsi_cmnd *cmd);
88extern void scsi_io_completion(struct scsi_cmnd *, unsigned int); 86extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
89extern void scsi_run_host_queues(struct Scsi_Host *shost); 87extern void scsi_run_host_queues(struct Scsi_Host *shost);
90extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev); 88extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index ba3f1e8d0d57..0cda53adfd35 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -286,7 +286,13 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
286 } 286 }
287 WARN_ON_ONCE(!blk_get_queue(sdev->request_queue)); 287 WARN_ON_ONCE(!blk_get_queue(sdev->request_queue));
288 sdev->request_queue->queuedata = sdev; 288 sdev->request_queue->queuedata = sdev;
289 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 289
290 if (!shost_use_blk_mq(sdev->host) &&
291 (shost->bqt || shost->hostt->use_blk_tags)) {
292 blk_queue_init_tags(sdev->request_queue,
293 sdev->host->cmd_per_lun, shost->bqt);
294 }
295 scsi_adjust_queue_depth(sdev, sdev->host->cmd_per_lun);
290 296
291 scsi_sysfs_device_initialize(sdev); 297 scsi_sysfs_device_initialize(sdev);
292 298
@@ -874,8 +880,10 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
874 (inq_result[3] & 0x0f) == 1 ? " CCS" : ""); 880 (inq_result[3] & 0x0f) == 1 ? " CCS" : "");
875 881
876 if ((sdev->scsi_level >= SCSI_2) && (inq_result[7] & 2) && 882 if ((sdev->scsi_level >= SCSI_2) && (inq_result[7] & 2) &&
877 !(*bflags & BLIST_NOTQ)) 883 !(*bflags & BLIST_NOTQ)) {
878 sdev->tagged_supported = 1; 884 sdev->tagged_supported = 1;
885 sdev->simple_tags = 1;
886 }
879 887
880 /* 888 /*
881 * Some devices (Texel CD ROM drives) have handshaking problems 889 * Some devices (Texel CD ROM drives) have handshaking problems
@@ -1214,9 +1222,9 @@ static void scsi_sequential_lun_scan(struct scsi_target *starget,
1214 sparse_lun = 0; 1222 sparse_lun = 0;
1215 1223
1216 /* 1224 /*
1217 * If less than SCSI_1_CSS, and no special lun scaning, stop 1225 * If less than SCSI_1_CCS, and no special lun scanning, stop
1218 * scanning; this matches 2.4 behaviour, but could just be a bug 1226 * scanning; this matches 2.4 behaviour, but could just be a bug
1219 * (to continue scanning a SCSI_1_CSS device). 1227 * (to continue scanning a SCSI_1_CCS device).
1220 * 1228 *
1221 * This test is broken. We might not have any device on lun0 for 1229 * This test is broken. We might not have any device on lun0 for
1222 * a sparselun device, and if that's the case then how would we 1230 * a sparselun device, and if that's the case then how would we
@@ -1585,16 +1593,15 @@ EXPORT_SYMBOL(scsi_add_device);
1585 1593
1586void scsi_rescan_device(struct device *dev) 1594void scsi_rescan_device(struct device *dev)
1587{ 1595{
1588 struct scsi_driver *drv;
1589
1590 if (!dev->driver) 1596 if (!dev->driver)
1591 return; 1597 return;
1592 1598
1593 drv = to_scsi_driver(dev->driver); 1599 if (try_module_get(dev->driver->owner)) {
1594 if (try_module_get(drv->owner)) { 1600 struct scsi_driver *drv = to_scsi_driver(dev->driver);
1601
1595 if (drv->rescan) 1602 if (drv->rescan)
1596 drv->rescan(dev); 1603 drv->rescan(dev);
1597 module_put(drv->owner); 1604 module_put(dev->driver->owner);
1598 } 1605 }
1599} 1606}
1600EXPORT_SYMBOL(scsi_rescan_device); 1607EXPORT_SYMBOL(scsi_rescan_device);
@@ -1727,7 +1734,7 @@ int scsi_scan_host_selected(struct Scsi_Host *shost, unsigned int channel,
1727 1734
1728 if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) || 1735 if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) ||
1729 ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) || 1736 ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) ||
1730 ((lun != SCAN_WILD_CARD) && (lun > shost->max_lun))) 1737 ((lun != SCAN_WILD_CARD) && (lun >= shost->max_lun)))
1731 return -EINVAL; 1738 return -EINVAL;
1732 1739
1733 mutex_lock(&shost->scan_mutex); 1740 mutex_lock(&shost->scan_mutex);
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index f4cb7b3e9e23..35d93b0af82b 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -727,9 +727,7 @@ show_queue_type_field(struct device *dev, struct device_attribute *attr,
727 struct scsi_device *sdev = to_scsi_device(dev); 727 struct scsi_device *sdev = to_scsi_device(dev);
728 const char *name = "none"; 728 const char *name = "none";
729 729
730 if (sdev->ordered_tags) 730 if (sdev->simple_tags)
731 name = "ordered";
732 else if (sdev->simple_tags)
733 name = "simple"; 731 name = "simple";
734 732
735 return snprintf(buf, 20, "%s\n", name); 733 return snprintf(buf, 20, "%s\n", name);
@@ -747,9 +745,12 @@ store_queue_type_field(struct device *dev, struct device_attribute *attr,
747 if (!sdev->tagged_supported || !sht->change_queue_type) 745 if (!sdev->tagged_supported || !sht->change_queue_type)
748 return -EINVAL; 746 return -EINVAL;
749 747
750 if (strncmp(buf, "ordered", 7) == 0) 748 /*
751 tag_type = MSG_ORDERED_TAG; 749 * We're never issueing order tags these days, but allow the value
752 else if (strncmp(buf, "simple", 6) == 0) 750 * for backwards compatibility.
751 */
752 if (strncmp(buf, "ordered", 7) == 0 ||
753 strncmp(buf, "simple", 6) == 0)
753 tag_type = MSG_SIMPLE_TAG; 754 tag_type = MSG_SIMPLE_TAG;
754 else if (strncmp(buf, "none", 4) != 0) 755 else if (strncmp(buf, "none", 4) != 0)
755 return -EINVAL; 756 return -EINVAL;
diff --git a/drivers/scsi/scsi_trace.c b/drivers/scsi/scsi_trace.c
index 503594e5f76d..82af28b90294 100644
--- a/drivers/scsi/scsi_trace.c
+++ b/drivers/scsi/scsi_trace.c
@@ -278,7 +278,7 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
278 return scsi_trace_rw16(p, cdb, len); 278 return scsi_trace_rw16(p, cdb, len);
279 case UNMAP: 279 case UNMAP:
280 return scsi_trace_unmap(p, cdb, len); 280 return scsi_trace_unmap(p, cdb, len);
281 case SERVICE_ACTION_IN: 281 case SERVICE_ACTION_IN_16:
282 return scsi_trace_service_action_in(p, cdb, len); 282 return scsi_trace_service_action_in(p, cdb, len);
283 case VARIABLE_LENGTH_CMD: 283 case VARIABLE_LENGTH_CMD:
284 return scsi_trace_varlen(p, cdb, len); 284 return scsi_trace_varlen(p, cdb, len);
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index cf08071a9b6e..fa2aece76cc2 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -32,6 +32,7 @@
32#include <scsi/scsi_host.h> 32#include <scsi/scsi_host.h>
33#include <scsi/scsi_cmnd.h> 33#include <scsi/scsi_cmnd.h>
34#include <scsi/scsi_eh.h> 34#include <scsi/scsi_eh.h>
35#include <scsi/scsi_tcq.h>
35#include <scsi/scsi_transport.h> 36#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_spi.h> 37#include <scsi/scsi_transport_spi.h>
37 38
@@ -1207,6 +1208,28 @@ int spi_populate_ppr_msg(unsigned char *msg, int period, int offset,
1207} 1208}
1208EXPORT_SYMBOL_GPL(spi_populate_ppr_msg); 1209EXPORT_SYMBOL_GPL(spi_populate_ppr_msg);
1209 1210
1211/**
1212 * spi_populate_tag_msg - place a tag message in a buffer
1213 * @msg: pointer to the area to place the tag
1214 * @cmd: pointer to the scsi command for the tag
1215 *
1216 * Notes:
1217 * designed to create the correct type of tag message for the
1218 * particular request. Returns the size of the tag message.
1219 * May return 0 if TCQ is disabled for this device.
1220 **/
1221int spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd)
1222{
1223 if (cmd->flags & SCMD_TAGGED) {
1224 *msg++ = MSG_SIMPLE_TAG;
1225 *msg++ = cmd->request->tag;
1226 return 2;
1227 }
1228
1229 return 0;
1230}
1231EXPORT_SYMBOL_GPL(spi_populate_tag_msg);
1232
1210#ifdef CONFIG_SCSI_CONSTANTS 1233#ifdef CONFIG_SCSI_CONSTANTS
1211static const char * const one_byte_msgs[] = { 1234static const char * const one_byte_msgs[] = {
1212/* 0x00 */ "Task Complete", NULL /* Extended Message */, "Save Pointers", 1235/* 0x00 */ "Task Complete", NULL /* Extended Message */, "Save Pointers",
diff --git a/drivers/scsi/scsicam.c b/drivers/scsi/scsicam.c
index 92d24d6dcb39..910f4a7a3924 100644
--- a/drivers/scsi/scsicam.c
+++ b/drivers/scsi/scsicam.c
@@ -163,8 +163,8 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
163 end_head * end_sector + end_sector; 163 end_head * end_sector + end_sector;
164 164
165 /* This is the actual _sector_ number at the end */ 165 /* This is the actual _sector_ number at the end */
166 logical_end = get_unaligned(&largest->start_sect) 166 logical_end = get_unaligned_le32(&largest->start_sect)
167 + get_unaligned(&largest->nr_sects); 167 + get_unaligned_le32(&largest->nr_sects);
168 168
169 /* This is for >1023 cylinders */ 169 /* This is for >1023 cylinders */
170 ext_cyl = (logical_end - (end_head * end_sector + end_sector)) 170 ext_cyl = (logical_end - (end_head * end_sector + end_sector))
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cfba74cd8e8b..fedab3c21ddf 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -116,7 +116,7 @@ static int sd_eh_action(struct scsi_cmnd *, int);
116static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer); 116static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
117static void scsi_disk_release(struct device *cdev); 117static void scsi_disk_release(struct device *cdev);
118static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); 118static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
119static void sd_print_result(struct scsi_disk *, int); 119static void sd_print_result(const struct scsi_disk *, const char *, int);
120 120
121static DEFINE_SPINLOCK(sd_index_lock); 121static DEFINE_SPINLOCK(sd_index_lock);
122static DEFINE_IDA(sd_index_ida); 122static DEFINE_IDA(sd_index_ida);
@@ -510,9 +510,9 @@ static const struct dev_pm_ops sd_pm_ops = {
510}; 510};
511 511
512static struct scsi_driver sd_template = { 512static struct scsi_driver sd_template = {
513 .owner = THIS_MODULE,
514 .gendrv = { 513 .gendrv = {
515 .name = "sd", 514 .name = "sd",
515 .owner = THIS_MODULE,
516 .probe = sd_probe, 516 .probe = sd_probe,
517 .remove = sd_remove, 517 .remove = sd_remove,
518 .shutdown = sd_shutdown, 518 .shutdown = sd_shutdown,
@@ -656,7 +656,7 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
656 unsigned int logical_block_size = sdkp->device->sector_size; 656 unsigned int logical_block_size = sdkp->device->sector_size;
657 unsigned int max_blocks = 0; 657 unsigned int max_blocks = 0;
658 658
659 q->limits.discard_zeroes_data = sdkp->lbprz; 659 q->limits.discard_zeroes_data = 0;
660 q->limits.discard_alignment = sdkp->unmap_alignment * 660 q->limits.discard_alignment = sdkp->unmap_alignment *
661 logical_block_size; 661 logical_block_size;
662 q->limits.discard_granularity = 662 q->limits.discard_granularity =
@@ -680,11 +680,13 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
680 case SD_LBP_WS16: 680 case SD_LBP_WS16:
681 max_blocks = min_not_zero(sdkp->max_ws_blocks, 681 max_blocks = min_not_zero(sdkp->max_ws_blocks,
682 (u32)SD_MAX_WS16_BLOCKS); 682 (u32)SD_MAX_WS16_BLOCKS);
683 q->limits.discard_zeroes_data = sdkp->lbprz;
683 break; 684 break;
684 685
685 case SD_LBP_WS10: 686 case SD_LBP_WS10:
686 max_blocks = min_not_zero(sdkp->max_ws_blocks, 687 max_blocks = min_not_zero(sdkp->max_ws_blocks,
687 (u32)SD_MAX_WS10_BLOCKS); 688 (u32)SD_MAX_WS10_BLOCKS);
689 q->limits.discard_zeroes_data = sdkp->lbprz;
688 break; 690 break;
689 691
690 case SD_LBP_ZERO: 692 case SD_LBP_ZERO:
@@ -784,7 +786,7 @@ static int sd_setup_discard_cmnd(struct scsi_cmnd *cmd)
784 * amount of blocks described by the request. 786 * amount of blocks described by the request.
785 */ 787 */
786 blk_add_request_payload(rq, page, len); 788 blk_add_request_payload(rq, page, len);
787 ret = scsi_init_io(cmd, GFP_ATOMIC); 789 ret = scsi_init_io(cmd);
788 rq->__data_len = nr_bytes; 790 rq->__data_len = nr_bytes;
789 791
790out: 792out:
@@ -878,7 +880,7 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
878 * knows how much to actually write. 880 * knows how much to actually write.
879 */ 881 */
880 rq->__data_len = sdp->sector_size; 882 rq->__data_len = sdp->sector_size;
881 ret = scsi_init_io(cmd, GFP_ATOMIC); 883 ret = scsi_init_io(cmd);
882 rq->__data_len = nr_bytes; 884 rq->__data_len = nr_bytes;
883 return ret; 885 return ret;
884} 886}
@@ -912,7 +914,7 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt)
912 int ret; 914 int ret;
913 unsigned char protect; 915 unsigned char protect;
914 916
915 ret = scsi_init_io(SCpnt, GFP_ATOMIC); 917 ret = scsi_init_io(SCpnt);
916 if (ret != BLKPREP_OK) 918 if (ret != BLKPREP_OK)
917 goto out; 919 goto out;
918 SCpnt = rq->special; 920 SCpnt = rq->special;
@@ -1334,9 +1336,9 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
1334 * may try and take the device offline, in which case all further 1336 * may try and take the device offline, in which case all further
1335 * access to the device is prohibited. 1337 * access to the device is prohibited.
1336 */ 1338 */
1337 error = scsi_nonblockable_ioctl(sdp, cmd, p, 1339 error = scsi_ioctl_block_when_processing_errors(sdp, cmd,
1338 (mode & FMODE_NDELAY) != 0); 1340 (mode & FMODE_NDELAY) != 0);
1339 if (!scsi_block_when_processing_errors(sdp) || !error) 1341 if (error)
1340 goto out; 1342 goto out;
1341 1343
1342 /* 1344 /*
@@ -1492,7 +1494,7 @@ static int sd_sync_cache(struct scsi_disk *sdkp)
1492 } 1494 }
1493 1495
1494 if (res) { 1496 if (res) {
1495 sd_print_result(sdkp, res); 1497 sd_print_result(sdkp, "Synchronize Cache(10) failed", res);
1496 1498
1497 if (driver_byte(res) & DRIVER_SENSE) 1499 if (driver_byte(res) & DRIVER_SENSE)
1498 sd_print_sense_hdr(sdkp, &sshdr); 1500 sd_print_sense_hdr(sdkp, &sshdr);
@@ -1541,31 +1543,19 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
1541 unsigned int cmd, unsigned long arg) 1543 unsigned int cmd, unsigned long arg)
1542{ 1544{
1543 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device; 1545 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device;
1544 int ret; 1546 int error;
1545
1546 ret = scsi_verify_blk_ioctl(bdev, cmd);
1547 if (ret < 0)
1548 return ret;
1549 1547
1550 /* 1548 error = scsi_ioctl_block_when_processing_errors(sdev, cmd,
1551 * If we are in the middle of error recovery, don't let anyone 1549 (mode & FMODE_NDELAY) != 0);
1552 * else try and use this device. Also, if error recovery fails, it 1550 if (error)
1553 * may try and take the device offline, in which case all further 1551 return error;
1554 * access to the device is prohibited.
1555 */
1556 if (!scsi_block_when_processing_errors(sdev))
1557 return -ENODEV;
1558 1552
1559 if (sdev->host->hostt->compat_ioctl) {
1560 ret = sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
1561
1562 return ret;
1563 }
1564
1565 /* 1553 /*
1566 * Let the static ioctl translation table take care of it. 1554 * Let the static ioctl translation table take care of it.
1567 */ 1555 */
1568 return -ENOIOCTLCMD; 1556 if (!sdev->host->hostt->compat_ioctl)
1557 return -ENOIOCTLCMD;
1558 return sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
1569} 1559}
1570#endif 1560#endif
1571 1561
@@ -1713,17 +1703,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1713 if (sense_valid) 1703 if (sense_valid)
1714 sense_deferred = scsi_sense_is_deferred(&sshdr); 1704 sense_deferred = scsi_sense_is_deferred(&sshdr);
1715 } 1705 }
1716#ifdef CONFIG_SCSI_LOGGING
1717 SCSI_LOG_HLCOMPLETE(1, scsi_print_result(SCpnt));
1718 if (sense_valid) {
1719 SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
1720 "sd_done: sb[respc,sk,asc,"
1721 "ascq]=%x,%x,%x,%x\n",
1722 sshdr.response_code,
1723 sshdr.sense_key, sshdr.asc,
1724 sshdr.ascq));
1725 }
1726#endif
1727 sdkp->medium_access_timed_out = 0; 1706 sdkp->medium_access_timed_out = 0;
1728 1707
1729 if (driver_byte(result) != DRIVER_SENSE && 1708 if (driver_byte(result) != DRIVER_SENSE &&
@@ -1743,7 +1722,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1743 * unknown amount of data was transferred so treat it as an 1722 * unknown amount of data was transferred so treat it as an
1744 * error. 1723 * error.
1745 */ 1724 */
1746 scsi_print_sense("sd", SCpnt);
1747 SCpnt->result = 0; 1725 SCpnt->result = 0;
1748 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); 1726 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1749 break; 1727 break;
@@ -1779,6 +1757,10 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1779 break; 1757 break;
1780 } 1758 }
1781 out: 1759 out:
1760 SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
1761 "sd_done: completed %d of %d bytes\n",
1762 good_bytes, scsi_bufflen(SCpnt)));
1763
1782 if (rq_data_dir(SCpnt->request) == READ && scsi_prot_sg_count(SCpnt)) 1764 if (rq_data_dir(SCpnt->request) == READ && scsi_prot_sg_count(SCpnt))
1783 sd_dif_complete(SCpnt, good_bytes); 1765 sd_dif_complete(SCpnt, good_bytes);
1784 1766
@@ -1834,12 +1816,12 @@ sd_spinup_disk(struct scsi_disk *sdkp)
1834 /* no sense, TUR either succeeded or failed 1816 /* no sense, TUR either succeeded or failed
1835 * with a status error */ 1817 * with a status error */
1836 if(!spintime && !scsi_status_is_good(the_result)) { 1818 if(!spintime && !scsi_status_is_good(the_result)) {
1837 sd_printk(KERN_NOTICE, sdkp, "Unit Not Ready\n"); 1819 sd_print_result(sdkp, "Test Unit Ready failed",
1838 sd_print_result(sdkp, the_result); 1820 the_result);
1839 } 1821 }
1840 break; 1822 break;
1841 } 1823 }
1842 1824
1843 /* 1825 /*
1844 * The device does not want the automatic start to be issued. 1826 * The device does not want the automatic start to be issued.
1845 */ 1827 */
@@ -1955,7 +1937,6 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
1955 struct scsi_sense_hdr *sshdr, int sense_valid, 1937 struct scsi_sense_hdr *sshdr, int sense_valid,
1956 int the_result) 1938 int the_result)
1957{ 1939{
1958 sd_print_result(sdkp, the_result);
1959 if (driver_byte(the_result) & DRIVER_SENSE) 1940 if (driver_byte(the_result) & DRIVER_SENSE)
1960 sd_print_sense_hdr(sdkp, sshdr); 1941 sd_print_sense_hdr(sdkp, sshdr);
1961 else 1942 else
@@ -2001,7 +1982,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
2001 1982
2002 do { 1983 do {
2003 memset(cmd, 0, 16); 1984 memset(cmd, 0, 16);
2004 cmd[0] = SERVICE_ACTION_IN; 1985 cmd[0] = SERVICE_ACTION_IN_16;
2005 cmd[1] = SAI_READ_CAPACITY_16; 1986 cmd[1] = SAI_READ_CAPACITY_16;
2006 cmd[13] = RC16_LEN; 1987 cmd[13] = RC16_LEN;
2007 memset(buffer, 0, RC16_LEN); 1988 memset(buffer, 0, RC16_LEN);
@@ -2036,7 +2017,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
2036 } while (the_result && retries); 2017 } while (the_result && retries);
2037 2018
2038 if (the_result) { 2019 if (the_result) {
2039 sd_printk(KERN_NOTICE, sdkp, "READ CAPACITY(16) failed\n"); 2020 sd_print_result(sdkp, "Read Capacity(16) failed", the_result);
2040 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result); 2021 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result);
2041 return -EINVAL; 2022 return -EINVAL;
2042 } 2023 }
@@ -2118,7 +2099,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
2118 } while (the_result && retries); 2099 } while (the_result && retries);
2119 2100
2120 if (the_result) { 2101 if (the_result) {
2121 sd_printk(KERN_NOTICE, sdkp, "READ CAPACITY failed\n"); 2102 sd_print_result(sdkp, "Read Capacity(10) failed", the_result);
2122 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result); 2103 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result);
2123 return -EINVAL; 2104 return -EINVAL;
2124 } 2105 }
@@ -2643,12 +2624,12 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
2643 2624
2644 } else { /* LBP VPD page tells us what to use */ 2625 } else { /* LBP VPD page tells us what to use */
2645 2626
2646 if (sdkp->lbpu && sdkp->max_unmap_blocks) 2627 if (sdkp->lbpws)
2647 sd_config_discard(sdkp, SD_LBP_UNMAP);
2648 else if (sdkp->lbpws)
2649 sd_config_discard(sdkp, SD_LBP_WS16); 2628 sd_config_discard(sdkp, SD_LBP_WS16);
2650 else if (sdkp->lbpws10) 2629 else if (sdkp->lbpws10)
2651 sd_config_discard(sdkp, SD_LBP_WS10); 2630 sd_config_discard(sdkp, SD_LBP_WS10);
2631 else if (sdkp->lbpu && sdkp->max_unmap_blocks)
2632 sd_config_discard(sdkp, SD_LBP_UNMAP);
2652 else 2633 else
2653 sd_config_discard(sdkp, SD_LBP_DISABLE); 2634 sd_config_discard(sdkp, SD_LBP_DISABLE);
2654 } 2635 }
@@ -3142,8 +3123,7 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
3142 res = scsi_execute_req_flags(sdp, cmd, DMA_NONE, NULL, 0, &sshdr, 3123 res = scsi_execute_req_flags(sdp, cmd, DMA_NONE, NULL, 0, &sshdr,
3143 SD_TIMEOUT, SD_MAX_RETRIES, NULL, REQ_PM); 3124 SD_TIMEOUT, SD_MAX_RETRIES, NULL, REQ_PM);
3144 if (res) { 3125 if (res) {
3145 sd_printk(KERN_WARNING, sdkp, "START_STOP FAILED\n"); 3126 sd_print_result(sdkp, "Start/Stop Unit failed", res);
3146 sd_print_result(sdkp, res);
3147 if (driver_byte(res) & DRIVER_SENSE) 3127 if (driver_byte(res) & DRIVER_SENSE)
3148 sd_print_sense_hdr(sdkp, &sshdr); 3128 sd_print_sense_hdr(sdkp, &sshdr);
3149 if (scsi_sense_valid(&sshdr) && 3129 if (scsi_sense_valid(&sshdr) &&
@@ -3337,15 +3317,27 @@ module_exit(exit_sd);
3337static void sd_print_sense_hdr(struct scsi_disk *sdkp, 3317static void sd_print_sense_hdr(struct scsi_disk *sdkp,
3338 struct scsi_sense_hdr *sshdr) 3318 struct scsi_sense_hdr *sshdr)
3339{ 3319{
3340 sd_printk(KERN_INFO, sdkp, " "); 3320 scsi_show_sense_hdr(sdkp->device,
3341 scsi_show_sense_hdr(sshdr); 3321 sdkp->disk ? sdkp->disk->disk_name : NULL, sshdr);
3342 sd_printk(KERN_INFO, sdkp, " "); 3322 scsi_show_extd_sense(sdkp->device,
3343 scsi_show_extd_sense(sshdr->asc, sshdr->ascq); 3323 sdkp->disk ? sdkp->disk->disk_name : NULL,
3324 sshdr->asc, sshdr->ascq);
3344} 3325}
3345 3326
3346static void sd_print_result(struct scsi_disk *sdkp, int result) 3327static void sd_print_result(const struct scsi_disk *sdkp, const char *msg,
3328 int result)
3347{ 3329{
3348 sd_printk(KERN_INFO, sdkp, " "); 3330 const char *hb_string = scsi_hostbyte_string(result);
3349 scsi_show_result(result); 3331 const char *db_string = scsi_driverbyte_string(result);
3332
3333 if (hb_string || db_string)
3334 sd_printk(KERN_INFO, sdkp,
3335 "%s: Result: hostbyte=%s driverbyte=%s\n", msg,
3336 hb_string ? hb_string : "invalid",
3337 db_string ? db_string : "invalid");
3338 else
3339 sd_printk(KERN_INFO, sdkp,
3340 "%s: Result: hostbyte=0x%02x driverbyte=0x%02x\n",
3341 msg, host_byte(result), driver_byte(result));
3350} 3342}
3351 3343
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 467377884b63..63ba5ca7f9a1 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -103,9 +103,9 @@ static inline struct scsi_disk *scsi_disk(struct gendisk *disk)
103 103
104#define sd_printk(prefix, sdsk, fmt, a...) \ 104#define sd_printk(prefix, sdsk, fmt, a...) \
105 (sdsk)->disk ? \ 105 (sdsk)->disk ? \
106 sdev_printk(prefix, (sdsk)->device, "[%s] " fmt, \ 106 sdev_prefix_printk(prefix, (sdsk)->device, \
107 (sdsk)->disk->disk_name, ##a) : \ 107 (sdsk)->disk->disk_name, fmt, ##a) : \
108 sdev_printk(prefix, (sdsk)->device, fmt, ##a) 108 sdev_printk(prefix, (sdsk)->device, fmt, ##a)
109 109
110#define sd_first_printk(prefix, sdsk, fmt, a...) \ 110#define sd_first_printk(prefix, sdsk, fmt, a...) \
111 do { \ 111 do { \
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index 80bfece1a2de..b7e79e7646ad 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -693,9 +693,9 @@ static struct class_interface ses_interface = {
693}; 693};
694 694
695static struct scsi_driver ses_template = { 695static struct scsi_driver ses_template = {
696 .owner = THIS_MODULE,
697 .gendrv = { 696 .gendrv = {
698 .name = "ses", 697 .name = "ses",
698 .owner = THIS_MODULE,
699 .probe = ses_probe, 699 .probe = ses_probe,
700 .remove = ses_remove, 700 .remove = ses_remove,
701 }, 701 },
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 60354449d9ed..b14f64cb9724 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -219,8 +219,8 @@ static void sg_device_destroy(struct kref *kref);
219#define SZ_SG_REQ_INFO sizeof(sg_req_info_t) 219#define SZ_SG_REQ_INFO sizeof(sg_req_info_t)
220 220
221#define sg_printk(prefix, sdp, fmt, a...) \ 221#define sg_printk(prefix, sdp, fmt, a...) \
222 sdev_printk(prefix, (sdp)->device, "[%s] " fmt, \ 222 sdev_prefix_printk(prefix, (sdp)->device, \
223 (sdp)->disk->disk_name, ##a) 223 (sdp)->disk->disk_name, fmt, ##a)
224 224
225static int sg_allow_access(struct file *filp, unsigned char *cmd) 225static int sg_allow_access(struct file *filp, unsigned char *cmd)
226{ 226{
@@ -1071,39 +1071,6 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1071 if (atomic_read(&sdp->detaching)) 1071 if (atomic_read(&sdp->detaching))
1072 return -ENODEV; 1072 return -ENODEV;
1073 return put_user(sdp->device->host->hostt->emulated, ip); 1073 return put_user(sdp->device->host->hostt->emulated, ip);
1074 case SG_SCSI_RESET:
1075 if (atomic_read(&sdp->detaching))
1076 return -ENODEV;
1077 if (filp->f_flags & O_NONBLOCK) {
1078 if (scsi_host_in_recovery(sdp->device->host))
1079 return -EBUSY;
1080 } else if (!scsi_block_when_processing_errors(sdp->device))
1081 return -EBUSY;
1082 result = get_user(val, ip);
1083 if (result)
1084 return result;
1085 if (SG_SCSI_RESET_NOTHING == val)
1086 return 0;
1087 switch (val) {
1088 case SG_SCSI_RESET_DEVICE:
1089 val = SCSI_TRY_RESET_DEVICE;
1090 break;
1091 case SG_SCSI_RESET_TARGET:
1092 val = SCSI_TRY_RESET_TARGET;
1093 break;
1094 case SG_SCSI_RESET_BUS:
1095 val = SCSI_TRY_RESET_BUS;
1096 break;
1097 case SG_SCSI_RESET_HOST:
1098 val = SCSI_TRY_RESET_HOST;
1099 break;
1100 default:
1101 return -EINVAL;
1102 }
1103 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1104 return -EACCES;
1105 return (scsi_reset_provider(sdp->device, val) ==
1106 SUCCESS) ? 0 : -EIO;
1107 case SCSI_IOCTL_SEND_COMMAND: 1074 case SCSI_IOCTL_SEND_COMMAND:
1108 if (atomic_read(&sdp->detaching)) 1075 if (atomic_read(&sdp->detaching))
1109 return -ENODEV; 1076 return -ENODEV;
@@ -1123,13 +1090,6 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1123 return result; 1090 return result;
1124 sdp->sgdebug = (char) val; 1091 sdp->sgdebug = (char) val;
1125 return 0; 1092 return 0;
1126 case SCSI_IOCTL_GET_IDLUN:
1127 case SCSI_IOCTL_GET_BUS_NUMBER:
1128 case SCSI_IOCTL_PROBE_HOST:
1129 case SG_GET_TRANSFORM:
1130 if (atomic_read(&sdp->detaching))
1131 return -ENODEV;
1132 return scsi_ioctl(sdp->device, cmd_in, p);
1133 case BLKSECTGET: 1093 case BLKSECTGET:
1134 return put_user(max_sectors_bytes(sdp->device->request_queue), 1094 return put_user(max_sectors_bytes(sdp->device->request_queue),
1135 ip); 1095 ip);
@@ -1145,11 +1105,25 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1145 return blk_trace_startstop(sdp->device->request_queue, 0); 1105 return blk_trace_startstop(sdp->device->request_queue, 0);
1146 case BLKTRACETEARDOWN: 1106 case BLKTRACETEARDOWN:
1147 return blk_trace_remove(sdp->device->request_queue); 1107 return blk_trace_remove(sdp->device->request_queue);
1108 case SCSI_IOCTL_GET_IDLUN:
1109 case SCSI_IOCTL_GET_BUS_NUMBER:
1110 case SCSI_IOCTL_PROBE_HOST:
1111 case SG_GET_TRANSFORM:
1112 case SG_SCSI_RESET:
1113 if (atomic_read(&sdp->detaching))
1114 return -ENODEV;
1115 break;
1148 default: 1116 default:
1149 if (read_only) 1117 if (read_only)
1150 return -EPERM; /* don't know so take safe approach */ 1118 return -EPERM; /* don't know so take safe approach */
1151 return scsi_ioctl(sdp->device, cmd_in, p); 1119 break;
1152 } 1120 }
1121
1122 result = scsi_ioctl_block_when_processing_errors(sdp->device,
1123 cmd_in, filp->f_flags & O_NDELAY);
1124 if (result)
1125 return result;
1126 return scsi_ioctl(sdp->device, cmd_in, p);
1153} 1127}
1154 1128
1155#ifdef CONFIG_COMPAT 1129#ifdef CONFIG_COMPAT
@@ -1360,7 +1334,7 @@ sg_rq_end_io(struct request *rq, int uptodate)
1360 if ((sdp->sgdebug > 0) && 1334 if ((sdp->sgdebug > 0) &&
1361 ((CHECK_CONDITION == srp->header.masked_status) || 1335 ((CHECK_CONDITION == srp->header.masked_status) ||
1362 (COMMAND_TERMINATED == srp->header.masked_status))) 1336 (COMMAND_TERMINATED == srp->header.masked_status)))
1363 __scsi_print_sense(__func__, sense, 1337 __scsi_print_sense(sdp->device, __func__, sense,
1364 SCSI_SENSE_BUFFERSIZE); 1338 SCSI_SENSE_BUFFERSIZE);
1365 1339
1366 /* Following if statement is a patch supplied by Eric Youngdale */ 1340 /* Following if statement is a patch supplied by Eric Youngdale */
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 2de44cc58b1a..8bd54a64efd6 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -88,9 +88,9 @@ static struct dev_pm_ops sr_pm_ops = {
88}; 88};
89 89
90static struct scsi_driver sr_template = { 90static struct scsi_driver sr_template = {
91 .owner = THIS_MODULE,
92 .gendrv = { 91 .gendrv = {
93 .name = "sr", 92 .name = "sr",
93 .owner = THIS_MODULE,
94 .probe = sr_probe, 94 .probe = sr_probe,
95 .remove = sr_remove, 95 .remove = sr_remove,
96 .pm = &sr_pm_ops, 96 .pm = &sr_pm_ops,
@@ -387,7 +387,7 @@ static int sr_init_command(struct scsi_cmnd *SCpnt)
387 struct request *rq = SCpnt->request; 387 struct request *rq = SCpnt->request;
388 int ret; 388 int ret;
389 389
390 ret = scsi_init_io(SCpnt, GFP_ATOMIC); 390 ret = scsi_init_io(SCpnt);
391 if (ret != BLKPREP_OK) 391 if (ret != BLKPREP_OK)
392 goto out; 392 goto out;
393 SCpnt = rq->special; 393 SCpnt = rq->special;
@@ -549,6 +549,11 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
549 549
550 mutex_lock(&sr_mutex); 550 mutex_lock(&sr_mutex);
551 551
552 ret = scsi_ioctl_block_when_processing_errors(sdev, cmd,
553 (mode & FMODE_NDELAY) != 0);
554 if (ret)
555 goto out;
556
552 /* 557 /*
553 * Send SCSI addressing ioctls directly to mid level, send other 558 * Send SCSI addressing ioctls directly to mid level, send other
554 * ioctls to cdrom/block level. 559 * ioctls to cdrom/block level.
@@ -564,16 +569,6 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
564 if (ret != -ENOSYS) 569 if (ret != -ENOSYS)
565 goto out; 570 goto out;
566 571
567 /*
568 * ENODEV means that we didn't recognise the ioctl, or that we
569 * cannot execute it in the current device state. In either
570 * case fall through to scsi_ioctl, which will return ENDOEV again
571 * if it doesn't recognise the ioctl
572 */
573 ret = scsi_nonblockable_ioctl(sdev, cmd, argp,
574 (mode & FMODE_NDELAY) != 0);
575 if (ret != -ENODEV)
576 goto out;
577 ret = scsi_ioctl(sdev, cmd, argp); 572 ret = scsi_ioctl(sdev, cmd, argp);
578 573
579out: 574out:
diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h
index 1d1f6f416c59..1de33719ad8e 100644
--- a/drivers/scsi/sr.h
+++ b/drivers/scsi/sr.h
@@ -57,8 +57,7 @@ typedef struct scsi_cd {
57} Scsi_CD; 57} Scsi_CD;
58 58
59#define sr_printk(prefix, cd, fmt, a...) \ 59#define sr_printk(prefix, cd, fmt, a...) \
60 sdev_printk(prefix, (cd)->device, "[%s] " fmt, \ 60 sdev_prefix_printk(prefix, (cd)->device, (cd)->cdi.name, fmt, ##a)
61 (cd)->cdi.name, ##a)
62 61
63int sr_do_ioctl(Scsi_CD *, struct packet_command *); 62int sr_do_ioctl(Scsi_CD *, struct packet_command *);
64 63
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 6389fcff12ec..fb929fac22ba 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -246,7 +246,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
246 "CDROM not ready. Make sure there " 246 "CDROM not ready. Make sure there "
247 "is a disc in the drive.\n"); 247 "is a disc in the drive.\n");
248#ifdef DEBUG 248#ifdef DEBUG
249 scsi_print_sense_hdr("sr", &sshdr); 249 scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
250#endif 250#endif
251 err = -ENOMEDIUM; 251 err = -ENOMEDIUM;
252 break; 252 break;
@@ -257,15 +257,15 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
257 /* sense: Invalid command operation code */ 257 /* sense: Invalid command operation code */
258 err = -EDRIVE_CANT_DO_THIS; 258 err = -EDRIVE_CANT_DO_THIS;
259#ifdef DEBUG 259#ifdef DEBUG
260 __scsi_print_command(cgc->cmd); 260 __scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
261 scsi_print_sense_hdr("sr", &sshdr); 261 scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
262#endif 262#endif
263 break; 263 break;
264 default: 264 default:
265 sr_printk(KERN_ERR, cd, 265 sr_printk(KERN_ERR, cd,
266 "CDROM (ioctl) error, command: "); 266 "CDROM (ioctl) error, command: ");
267 __scsi_print_command(cgc->cmd); 267 __scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
268 scsi_print_sense_hdr("sr", &sshdr); 268 scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
269 err = -EIO; 269 err = -EIO;
270 } 270 }
271 } 271 }
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 4daa372ed381..128d3b55bdd9 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -56,7 +56,8 @@ static const char *verstr = "20101219";
56 56
57/* The driver prints some debugging information on the console if DEBUG 57/* The driver prints some debugging information on the console if DEBUG
58 is defined and non-zero. */ 58 is defined and non-zero. */
59#define DEBUG 0 59#define DEBUG 1
60#define NO_DEBUG 0
60 61
61#define ST_DEB_MSG KERN_NOTICE 62#define ST_DEB_MSG KERN_NOTICE
62#if DEBUG 63#if DEBUG
@@ -80,6 +81,7 @@ static int max_sg_segs;
80static int try_direct_io = TRY_DIRECT_IO; 81static int try_direct_io = TRY_DIRECT_IO;
81static int try_rdio = 1; 82static int try_rdio = 1;
82static int try_wdio = 1; 83static int try_wdio = 1;
84static int debug_flag;
83 85
84static struct class st_sysfs_class; 86static struct class st_sysfs_class;
85static const struct attribute_group *st_dev_groups[]; 87static const struct attribute_group *st_dev_groups[];
@@ -100,6 +102,9 @@ module_param_named(max_sg_segs, max_sg_segs, int, 0);
100MODULE_PARM_DESC(max_sg_segs, "Maximum number of scatter/gather segments to use (256)"); 102MODULE_PARM_DESC(max_sg_segs, "Maximum number of scatter/gather segments to use (256)");
101module_param_named(try_direct_io, try_direct_io, int, 0); 103module_param_named(try_direct_io, try_direct_io, int, 0);
102MODULE_PARM_DESC(try_direct_io, "Try direct I/O between user buffer and tape drive (1)"); 104MODULE_PARM_DESC(try_direct_io, "Try direct I/O between user buffer and tape drive (1)");
105module_param_named(debug_flag, debug_flag, int, 0);
106MODULE_PARM_DESC(debug_flag, "Enable DEBUG, same as setting debugging=1");
107
103 108
104/* Extra parameters for testing */ 109/* Extra parameters for testing */
105module_param_named(try_rdio, try_rdio, int, 0); 110module_param_named(try_rdio, try_rdio, int, 0);
@@ -124,6 +129,9 @@ static struct st_dev_parm {
124 }, 129 },
125 { 130 {
126 "try_direct_io", &try_direct_io 131 "try_direct_io", &try_direct_io
132 },
133 {
134 "debug_flag", &debug_flag
127 } 135 }
128}; 136};
129#endif 137#endif
@@ -194,9 +202,9 @@ static int do_create_sysfs_files(void);
194static void do_remove_sysfs_files(void); 202static void do_remove_sysfs_files(void);
195 203
196static struct scsi_driver st_template = { 204static struct scsi_driver st_template = {
197 .owner = THIS_MODULE,
198 .gendrv = { 205 .gendrv = {
199 .name = "st", 206 .name = "st",
207 .owner = THIS_MODULE,
200 .probe = st_probe, 208 .probe = st_probe,
201 .remove = st_remove, 209 .remove = st_remove,
202 }, 210 },
@@ -306,8 +314,7 @@ static inline char *tape_name(struct scsi_tape *tape)
306} 314}
307 315
308#define st_printk(prefix, t, fmt, a...) \ 316#define st_printk(prefix, t, fmt, a...) \
309 sdev_printk(prefix, (t)->device, "%s: " fmt, \ 317 sdev_prefix_printk(prefix, (t)->device, tape_name(t), fmt, ##a)
310 tape_name(t), ##a)
311#ifdef DEBUG 318#ifdef DEBUG
312#define DEBC_printk(t, fmt, a...) \ 319#define DEBC_printk(t, fmt, a...) \
313 if (debugging) { st_printk(ST_DEB_MSG, t, fmt, ##a ); } 320 if (debugging) { st_printk(ST_DEB_MSG, t, fmt, ##a ); }
@@ -374,7 +381,8 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
374 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], 381 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
375 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); 382 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
376 if (cmdstatp->have_sense) 383 if (cmdstatp->have_sense)
377 __scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 384 __scsi_print_sense(STp->device, name,
385 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
378 } ) /* end DEB */ 386 } ) /* end DEB */
379 if (!debugging) { /* Abnormal conditions for tape */ 387 if (!debugging) { /* Abnormal conditions for tape */
380 if (!cmdstatp->have_sense) 388 if (!cmdstatp->have_sense)
@@ -390,7 +398,8 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
390 SRpnt->cmd[0] != MODE_SENSE && 398 SRpnt->cmd[0] != MODE_SENSE &&
391 SRpnt->cmd[0] != TEST_UNIT_READY) { 399 SRpnt->cmd[0] != TEST_UNIT_READY) {
392 400
393 __scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 401 __scsi_print_sense(STp->device, name,
402 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
394 } 403 }
395 } 404 }
396 405
@@ -852,17 +861,16 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
852/* Lock or unlock the drive door. Don't use when st_request allocated. */ 861/* Lock or unlock the drive door. Don't use when st_request allocated. */
853static int do_door_lock(struct scsi_tape * STp, int do_lock) 862static int do_door_lock(struct scsi_tape * STp, int do_lock)
854{ 863{
855 int retval, cmd; 864 int retval;
856 865
857 cmd = do_lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK;
858 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); 866 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl");
859 retval = scsi_ioctl(STp->device, cmd, NULL); 867
860 if (!retval) { 868 retval = scsi_set_medium_removal(STp->device,
869 do_lock ? SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
870 if (!retval)
861 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; 871 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
862 } 872 else
863 else {
864 STp->door_locked = ST_LOCK_FAILS; 873 STp->door_locked = ST_LOCK_FAILS;
865 }
866 return retval; 874 return retval;
867} 875}
868 876
@@ -3367,11 +3375,10 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
3367 * may try and take the device offline, in which case all further 3375 * may try and take the device offline, in which case all further
3368 * access to the device is prohibited. 3376 * access to the device is prohibited.
3369 */ 3377 */
3370 retval = scsi_nonblockable_ioctl(STp->device, cmd_in, p, 3378 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in,
3371 file->f_flags & O_NDELAY); 3379 file->f_flags & O_NDELAY);
3372 if (!scsi_block_when_processing_errors(STp->device) || retval != -ENODEV) 3380 if (retval)
3373 goto out; 3381 goto out;
3374 retval = 0;
3375 3382
3376 cmd_type = _IOC_TYPE(cmd_in); 3383 cmd_type = _IOC_TYPE(cmd_in);
3377 cmd_nr = _IOC_NR(cmd_in); 3384 cmd_nr = _IOC_NR(cmd_in);
@@ -4309,6 +4316,12 @@ static int __init init_st(void)
4309 printk(KERN_INFO "st: Version %s, fixed bufsize %d, s/g segs %d\n", 4316 printk(KERN_INFO "st: Version %s, fixed bufsize %d, s/g segs %d\n",
4310 verstr, st_fixed_buffer_size, st_max_sg_segs); 4317 verstr, st_fixed_buffer_size, st_max_sg_segs);
4311 4318
4319 debugging = (debug_flag > 0) ? debug_flag : NO_DEBUG;
4320 if (debugging) {
4321 printk(KERN_INFO "st: Debugging enabled debug_flag = %d\n",
4322 debugging);
4323 }
4324
4312 err = class_register(&st_sysfs_class); 4325 err = class_register(&st_sysfs_class);
4313 if (err) { 4326 if (err) {
4314 pr_err("Unable register sysfs class for SCSI tapes\n"); 4327 pr_err("Unable register sysfs class for SCSI tapes\n");
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 1aa4befcfbd0..98a62bc15069 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -544,33 +544,15 @@ stex_ss_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
544} 544}
545 545
546static int 546static int
547stex_slave_alloc(struct scsi_device *sdev)
548{
549 /* Cheat: usually extracted from Inquiry data */
550 sdev->tagged_supported = 1;
551
552 scsi_activate_tcq(sdev, sdev->host->can_queue);
553
554 return 0;
555}
556
557static int
558stex_slave_config(struct scsi_device *sdev) 547stex_slave_config(struct scsi_device *sdev)
559{ 548{
560 sdev->use_10_for_rw = 1; 549 sdev->use_10_for_rw = 1;
561 sdev->use_10_for_ms = 1; 550 sdev->use_10_for_ms = 1;
562 blk_queue_rq_timeout(sdev->request_queue, 60 * HZ); 551 blk_queue_rq_timeout(sdev->request_queue, 60 * HZ);
563 sdev->tagged_supported = 1;
564 552
565 return 0; 553 return 0;
566} 554}
567 555
568static void
569stex_slave_destroy(struct scsi_device *sdev)
570{
571 scsi_deactivate_tcq(sdev, 1);
572}
573
574static int 556static int
575stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 557stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
576{ 558{
@@ -1162,9 +1144,7 @@ static int stex_abort(struct scsi_cmnd *cmd)
1162 int result = SUCCESS; 1144 int result = SUCCESS;
1163 unsigned long flags; 1145 unsigned long flags;
1164 1146
1165 printk(KERN_INFO DRV_NAME 1147 scmd_printk(KERN_INFO, cmd, "aborting command\n");
1166 "(%s): aborting command\n", pci_name(hba->pdev));
1167 scsi_print_command(cmd);
1168 1148
1169 base = hba->mmio_base; 1149 base = hba->mmio_base;
1170 spin_lock_irqsave(host->host_lock, flags); 1150 spin_lock_irqsave(host->host_lock, flags);
@@ -1352,9 +1332,8 @@ static int stex_reset(struct scsi_cmnd *cmd)
1352 1332
1353 hba = (struct st_hba *) &cmd->device->host->hostdata[0]; 1333 hba = (struct st_hba *) &cmd->device->host->hostdata[0];
1354 1334
1355 printk(KERN_INFO DRV_NAME 1335 shost_printk(KERN_INFO, cmd->device->host,
1356 "(%s): resetting host\n", pci_name(hba->pdev)); 1336 "resetting host\n");
1357 scsi_print_command(cmd);
1358 1337
1359 return stex_do_reset(hba) ? FAILED : SUCCESS; 1338 return stex_do_reset(hba) ? FAILED : SUCCESS;
1360} 1339}
@@ -1391,12 +1370,11 @@ static struct scsi_host_template driver_template = {
1391 .proc_name = DRV_NAME, 1370 .proc_name = DRV_NAME,
1392 .bios_param = stex_biosparam, 1371 .bios_param = stex_biosparam,
1393 .queuecommand = stex_queuecommand, 1372 .queuecommand = stex_queuecommand,
1394 .slave_alloc = stex_slave_alloc,
1395 .slave_configure = stex_slave_config, 1373 .slave_configure = stex_slave_config,
1396 .slave_destroy = stex_slave_destroy,
1397 .eh_abort_handler = stex_abort, 1374 .eh_abort_handler = stex_abort,
1398 .eh_host_reset_handler = stex_reset, 1375 .eh_host_reset_handler = stex_reset,
1399 .this_id = -1, 1376 .this_id = -1,
1377 .use_blk_tags = 1,
1400}; 1378};
1401 1379
1402static struct pci_device_id stex_pci_tbl[] = { 1380static struct pci_device_id stex_pci_tbl[] = {
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 733e5f759518..ff8befbdf17c 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1097,7 +1097,8 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
1097 if (scmnd->result) { 1097 if (scmnd->result) {
1098 if (scsi_normalize_sense(scmnd->sense_buffer, 1098 if (scsi_normalize_sense(scmnd->sense_buffer,
1099 SCSI_SENSE_BUFFERSIZE, &sense_hdr)) 1099 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
1100 scsi_print_sense_hdr("storvsc", &sense_hdr); 1100 scsi_print_sense_hdr(scmnd->device, "storvsc",
1101 &sense_hdr);
1101 } 1102 }
1102 1103
1103 if (vm_srb->srb_status != SRB_STATUS_SUCCESS) 1104 if (vm_srb->srb_status != SRB_STATUS_SUCCESS)
@@ -1428,8 +1429,7 @@ static void storvsc_device_destroy(struct scsi_device *sdevice)
1428 1429
1429static int storvsc_device_configure(struct scsi_device *sdevice) 1430static int storvsc_device_configure(struct scsi_device *sdevice)
1430{ 1431{
1431 scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG, 1432 scsi_adjust_queue_depth(sdevice, STORVSC_MAX_IO_REQUESTS);
1432 STORVSC_MAX_IO_REQUESTS);
1433 1433
1434 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE); 1434 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
1435 1435
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 1a2367a1b1f2..835bd8dafe0a 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -2590,15 +2590,15 @@ static void NCR5380_reselect (struct Scsi_Host *instance)
2590 * Purpose : abort a command 2590 * Purpose : abort a command
2591 * 2591 *
2592 * Inputs : cmd - the struct scsi_cmnd to abort, code - code to set the 2592 * Inputs : cmd - the struct scsi_cmnd to abort, code - code to set the
2593 * host byte of the result field to, if zero DID_ABORTED is 2593 * host byte of the result field to, if zero DID_ABORTED is
2594 * used. 2594 * used.
2595 * 2595 *
2596 * Returns : 0 - success, -1 on failure. 2596 * Returns : SUCCESS - success, FAILED on failure.
2597 * 2597 *
2598 * XXX - there is no way to abort the command that is currently 2598 * XXX - there is no way to abort the command that is currently
2599 * connected, you have to wait for it to complete. If this is 2599 * connected, you have to wait for it to complete. If this is
2600 * a problem, we could implement longjmp() / setjmp(), setjmp() 2600 * a problem, we could implement longjmp() / setjmp(), setjmp()
2601 * called where the loop started in NCR5380_main(). 2601 * called where the loop started in NCR5380_main().
2602 */ 2602 */
2603 2603
2604static int NCR5380_abort(struct scsi_cmnd *cmd) 2604static int NCR5380_abort(struct scsi_cmnd *cmd)
@@ -2608,8 +2608,7 @@ static int NCR5380_abort(struct scsi_cmnd *cmd)
2608 struct scsi_cmnd *tmp, **prev; 2608 struct scsi_cmnd *tmp, **prev;
2609 unsigned long flags; 2609 unsigned long flags;
2610 2610
2611 printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO); 2611 scmd_printk(KERN_NOTICE, cmd, "aborting command\n");
2612 scsi_print_command(cmd);
2613 2612
2614 NCR5380_print_status (instance); 2613 NCR5380_print_status (instance);
2615 2614
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index e59e6f96b725..3557b385251a 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -820,9 +820,7 @@ static int sym53c8xx_slave_configure(struct scsi_device *sdev)
820 if (reqtags > SYM_CONF_MAX_TAG) 820 if (reqtags > SYM_CONF_MAX_TAG)
821 reqtags = SYM_CONF_MAX_TAG; 821 reqtags = SYM_CONF_MAX_TAG;
822 depth_to_use = reqtags ? reqtags : 1; 822 depth_to_use = reqtags ? reqtags : 1;
823 scsi_adjust_queue_depth(sdev, 823 scsi_adjust_queue_depth(sdev, depth_to_use);
824 sdev->tagged_supported ? MSG_SIMPLE_TAG : 0,
825 depth_to_use);
826 lp->s.scdev_depth = depth_to_use; 824 lp->s.scdev_depth = depth_to_use;
827 sym_tune_dev_queuing(tp, sdev->lun, reqtags); 825 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
828 826
diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c
index 764575726c85..844c9a048c00 100644
--- a/drivers/scsi/tmscsim.c
+++ b/drivers/scsi/tmscsim.c
@@ -243,7 +243,6 @@
243#include <scsi/scsicam.h> 243#include <scsi/scsicam.h>
244#include <scsi/scsi_tcq.h> 244#include <scsi/scsi_tcq.h>
245 245
246
247#define DC390_BANNER "Tekram DC390/AM53C974" 246#define DC390_BANNER "Tekram DC390/AM53C974"
248#define DC390_VERSION "2.1d 2004-05-27" 247#define DC390_VERSION "2.1d 2004-05-27"
249 248
@@ -508,7 +507,6 @@ dc390_StartSCSI( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_sr
508 struct scsi_cmnd *scmd = pSRB->pcmd; 507 struct scsi_cmnd *scmd = pSRB->pcmd;
509 struct scsi_device *sdev = scmd->device; 508 struct scsi_device *sdev = scmd->device;
510 u8 cmd, disc_allowed, try_sync_nego; 509 u8 cmd, disc_allowed, try_sync_nego;
511 char tag[2];
512 510
513 pSRB->ScsiPhase = SCSI_NOP0; 511 pSRB->ScsiPhase = SCSI_NOP0;
514 512
@@ -560,11 +558,11 @@ dc390_StartSCSI( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_sr
560 cmd = SEL_W_ATN; 558 cmd = SEL_W_ATN;
561 DC390_write8 (ScsiFifo, IDENTIFY(disc_allowed, pDCB->TargetLUN)); 559 DC390_write8 (ScsiFifo, IDENTIFY(disc_allowed, pDCB->TargetLUN));
562 /* Change 99/05/31: Don't use tags when not disconnecting (BUSY) */ 560 /* Change 99/05/31: Don't use tags when not disconnecting (BUSY) */
563 if ((pDCB->SyncMode & EN_TAG_QUEUEING) && disc_allowed && scsi_populate_tag_msg(scmd, tag)) { 561 if ((pDCB->SyncMode & EN_TAG_QUEUEING) && disc_allowed && (scmd->flags & SCMD_TAGGED)) {
564 DC390_write8(ScsiFifo, tag[0]); 562 DC390_write8(ScsiFifo, MSG_SIMPLE_TAG);
565 pDCB->TagMask |= 1 << tag[1]; 563 pDCB->TagMask |= 1 << scmd->request->tag;
566 pSRB->TagNumber = tag[1]; 564 pSRB->TagNumber = scmd->request->tag;
567 DC390_write8(ScsiFifo, tag[1]); 565 DC390_write8(ScsiFifo, scmd->request->tag);
568 DEBUG1(printk(KERN_INFO "DC390: Select w/DisCn for SRB %p, block tag %02x\n", pSRB, tag[1])); 566 DEBUG1(printk(KERN_INFO "DC390: Select w/DisCn for SRB %p, block tag %02x\n", pSRB, tag[1]));
569 cmd = SEL_W_ATN3; 567 cmd = SEL_W_ATN3;
570 } else { 568 } else {
@@ -2187,9 +2185,16 @@ static int dc390_slave_configure(struct scsi_device *sdev)
2187 struct dc390_dcb *dcb = (struct dc390_dcb *)sdev->hostdata; 2185 struct dc390_dcb *dcb = (struct dc390_dcb *)sdev->hostdata;
2188 2186
2189 acb->scan_devices = 0; 2187 acb->scan_devices = 0;
2188
2189 /*
2190 * XXX: Note that while this driver used to called scsi_activate_tcq,
2191 * it never actually set a tag type, so emulate the old behavior.
2192 */
2193 scsi_set_tag_type(sdev, 0);
2194
2190 if (sdev->tagged_supported && (dcb->DevMode & TAG_QUEUEING_)) { 2195 if (sdev->tagged_supported && (dcb->DevMode & TAG_QUEUEING_)) {
2191 dcb->SyncMode |= EN_TAG_QUEUEING; 2196 dcb->SyncMode |= EN_TAG_QUEUEING;
2192 scsi_activate_tcq(sdev, acb->TagMaxNum); 2197 scsi_adjust_queue_depth(sdev, acb->TagMaxNum);
2193 } 2198 }
2194 2199
2195 return 0; 2200 return 0;
@@ -2211,6 +2216,7 @@ static struct scsi_host_template driver_template = {
2211 .cmd_per_lun = 1, 2216 .cmd_per_lun = 1,
2212 .use_clustering = ENABLE_CLUSTERING, 2217 .use_clustering = ENABLE_CLUSTERING,
2213 .max_sectors = 0x4000, /* 8MiB = 16 * 1024 * 512 */ 2218 .max_sectors = 0x4000, /* 8MiB = 16 * 1024 * 512 */
2219 .use_blk_tags = 1,
2214}; 2220};
2215 2221
2216/*********************************************************************** 2222/***********************************************************************
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index d8dcf36aed11..aa0f4035afaf 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -696,25 +696,25 @@ static int u14_34f_slave_configure(struct scsi_device *dev) {
696 if (TLDEV(dev->type) && dev->tagged_supported) 696 if (TLDEV(dev->type) && dev->tagged_supported)
697 697
698 if (tag_mode == TAG_SIMPLE) { 698 if (tag_mode == TAG_SIMPLE) {
699 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, tqd); 699 scsi_adjust_queue_depth(dev, tqd);
700 tag_suffix = ", simple tags"; 700 tag_suffix = ", simple tags";
701 } 701 }
702 else if (tag_mode == TAG_ORDERED) { 702 else if (tag_mode == TAG_ORDERED) {
703 scsi_adjust_queue_depth(dev, MSG_ORDERED_TAG, tqd); 703 scsi_adjust_queue_depth(dev, tqd);
704 tag_suffix = ", ordered tags"; 704 tag_suffix = ", ordered tags";
705 } 705 }
706 else { 706 else {
707 scsi_adjust_queue_depth(dev, 0, tqd); 707 scsi_adjust_queue_depth(dev, tqd);
708 tag_suffix = ", no tags"; 708 tag_suffix = ", no tags";
709 } 709 }
710 710
711 else if (TLDEV(dev->type) && linked_comm) { 711 else if (TLDEV(dev->type) && linked_comm) {
712 scsi_adjust_queue_depth(dev, 0, tqd); 712 scsi_adjust_queue_depth(dev, tqd);
713 tag_suffix = ", untagged"; 713 tag_suffix = ", untagged";
714 } 714 }
715 715
716 else { 716 else {
717 scsi_adjust_queue_depth(dev, 0, utqd); 717 scsi_adjust_queue_depth(dev, utqd);
718 tag_suffix = ""; 718 tag_suffix = "";
719 } 719 }
720 720
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 605ca60e8a10..820fc7d96084 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2713,7 +2713,7 @@ static void ufshcd_set_queue_depth(struct scsi_device *sdev)
2713 2713
2714 dev_dbg(hba->dev, "%s: activate tcq with queue depth %d\n", 2714 dev_dbg(hba->dev, "%s: activate tcq with queue depth %d\n",
2715 __func__, lun_qdepth); 2715 __func__, lun_qdepth);
2716 scsi_activate_tcq(sdev, lun_qdepth); 2716 scsi_adjust_queue_depth(sdev, lun_qdepth);
2717} 2717}
2718 2718
2719/* 2719/*
@@ -2783,11 +2783,9 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
2783 struct ufs_hba *hba; 2783 struct ufs_hba *hba;
2784 2784
2785 hba = shost_priv(sdev->host); 2785 hba = shost_priv(sdev->host);
2786 sdev->tagged_supported = 1;
2787 2786
2788 /* Mode sense(6) is not supported by UFS, so use Mode sense(10) */ 2787 /* Mode sense(6) is not supported by UFS, so use Mode sense(10) */
2789 sdev->use_10_for_ms = 1; 2788 sdev->use_10_for_ms = 1;
2790 scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
2791 2789
2792 /* allow SCSI layer to restart the device in case of errors */ 2790 /* allow SCSI layer to restart the device in case of errors */
2793 sdev->allow_restart = 1; 2791 sdev->allow_restart = 1;
@@ -2823,9 +2821,7 @@ static int ufshcd_change_queue_depth(struct scsi_device *sdev,
2823 switch (reason) { 2821 switch (reason) {
2824 case SCSI_QDEPTH_DEFAULT: 2822 case SCSI_QDEPTH_DEFAULT:
2825 case SCSI_QDEPTH_RAMP_UP: 2823 case SCSI_QDEPTH_RAMP_UP:
2826 if (!sdev->tagged_supported) 2824 scsi_adjust_queue_depth(sdev, depth);
2827 depth = 1;
2828 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
2829 break; 2825 break;
2830 case SCSI_QDEPTH_QFULL: 2826 case SCSI_QDEPTH_QFULL:
2831 scsi_track_queue_full(sdev, depth); 2827 scsi_track_queue_full(sdev, depth);
@@ -2860,7 +2856,6 @@ static void ufshcd_slave_destroy(struct scsi_device *sdev)
2860 struct ufs_hba *hba; 2856 struct ufs_hba *hba;
2861 2857
2862 hba = shost_priv(sdev->host); 2858 hba = shost_priv(sdev->host);
2863 scsi_deactivate_tcq(sdev, hba->nutrs);
2864 /* Drop the reference as it won't be needed anymore */ 2859 /* Drop the reference as it won't be needed anymore */
2865 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) { 2860 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) {
2866 unsigned long flags; 2861 unsigned long flags;
@@ -4239,6 +4234,7 @@ static struct scsi_host_template ufshcd_driver_template = {
4239 .cmd_per_lun = UFSHCD_CMD_PER_LUN, 4234 .cmd_per_lun = UFSHCD_CMD_PER_LUN,
4240 .can_queue = UFSHCD_CAN_QUEUE, 4235 .can_queue = UFSHCD_CAN_QUEUE,
4241 .max_host_blocked = 1, 4236 .max_host_blocked = 1,
4237 .use_blk_tags = 1,
4242}; 4238};
4243 4239
4244static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg, 4240static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
@@ -4731,11 +4727,11 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
4731 START_STOP_TIMEOUT, 0, NULL, REQ_PM); 4727 START_STOP_TIMEOUT, 0, NULL, REQ_PM);
4732 if (ret) { 4728 if (ret) {
4733 sdev_printk(KERN_WARNING, sdp, 4729 sdev_printk(KERN_WARNING, sdp,
4734 "START_STOP failed for power mode: %d\n", pwr_mode); 4730 "START_STOP failed for power mode: %d, result %x\n",
4735 scsi_show_result(ret); 4731 pwr_mode, ret);
4736 if (driver_byte(ret) & DRIVER_SENSE) { 4732 if (driver_byte(ret) & DRIVER_SENSE) {
4737 scsi_show_sense_hdr(&sshdr); 4733 scsi_show_sense_hdr(sdp, NULL, &sshdr);
4738 scsi_show_extd_sense(sshdr.asc, sshdr.ascq); 4734 scsi_show_extd_sense(sdp, NULL, sshdr.asc, sshdr.ascq);
4739 } 4735 }
4740 } 4736 }
4741 4737
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index b83846fc7859..355afbc7fde1 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -683,9 +683,7 @@ static int virtscsi_change_queue_depth(struct scsi_device *sdev,
683 break; 683 break;
684 case SCSI_QDEPTH_RAMP_UP: /* Raise qdepth after BUSY state resolved */ 684 case SCSI_QDEPTH_RAMP_UP: /* Raise qdepth after BUSY state resolved */
685 case SCSI_QDEPTH_DEFAULT: /* Manual change via sysfs */ 685 case SCSI_QDEPTH_DEFAULT: /* Manual change via sysfs */
686 scsi_adjust_queue_depth(sdev, 686 scsi_adjust_queue_depth(sdev, min(max_depth, qdepth));
687 scsi_get_tag_type(sdev),
688 min(max_depth, qdepth));
689 break; 687 break;
690 default: 688 default:
691 return -EOPNOTSUPP; 689 return -EOPNOTSUPP;
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 598f65efaaec..c3b4f8b3a3a5 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -522,13 +522,13 @@ static int pvscsi_change_queue_depth(struct scsi_device *sdev,
522 max_depth = 1; 522 max_depth = 1;
523 if (qdepth > max_depth) 523 if (qdepth > max_depth)
524 qdepth = max_depth; 524 qdepth = max_depth;
525 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 525 scsi_adjust_queue_depth(sdev, qdepth);
526 526
527 if (sdev->inquiry_len > 7) 527 if (sdev->inquiry_len > 7)
528 sdev_printk(KERN_INFO, sdev, 528 sdev_printk(KERN_INFO, sdev,
529 "qdepth(%d), tagged(%d), simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", 529 "qdepth(%d), tagged(%d), simple(%d), scsi_level(%d), cmd_que(%d)\n",
530 sdev->queue_depth, sdev->tagged_supported, 530 sdev->queue_depth, sdev->tagged_supported,
531 sdev->simple_tags, sdev->ordered_tags, 531 sdev->simple_tags,
532 sdev->scsi_level, (sdev->inquiry[7] & 2) >> 1); 532 sdev->scsi_level, (sdev->inquiry[7] & 2) >> 1);
533 return sdev->queue_depth; 533 return sdev->queue_depth;
534} 534}
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index ab3ab27d49b7..0ed96644ec94 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -121,13 +121,13 @@ static int tcm_loop_change_queue_depth(
121{ 121{
122 switch (reason) { 122 switch (reason) {
123 case SCSI_QDEPTH_DEFAULT: 123 case SCSI_QDEPTH_DEFAULT:
124 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 124 scsi_adjust_queue_depth(sdev, depth);
125 break; 125 break;
126 case SCSI_QDEPTH_QFULL: 126 case SCSI_QDEPTH_QFULL:
127 scsi_track_queue_full(sdev, depth); 127 scsi_track_queue_full(sdev, depth);
128 break; 128 break;
129 case SCSI_QDEPTH_RAMP_UP: 129 case SCSI_QDEPTH_RAMP_UP:
130 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 130 scsi_adjust_queue_depth(sdev, depth);
131 break; 131 break;
132 default: 132 default:
133 return -EOPNOTSUPP; 133 return -EOPNOTSUPP;
@@ -135,33 +135,6 @@ static int tcm_loop_change_queue_depth(
135 return sdev->queue_depth; 135 return sdev->queue_depth;
136} 136}
137 137
138static int tcm_loop_change_queue_type(struct scsi_device *sdev, int tag)
139{
140 if (sdev->tagged_supported) {
141 scsi_set_tag_type(sdev, tag);
142
143 if (tag)
144 scsi_activate_tcq(sdev, sdev->queue_depth);
145 else
146 scsi_deactivate_tcq(sdev, sdev->queue_depth);
147 } else
148 tag = 0;
149
150 return tag;
151}
152
153/*
154 * Locate the SAM Task Attr from struct scsi_cmnd *
155 */
156static int tcm_loop_sam_attr(struct scsi_cmnd *sc, int tag)
157{
158 if (sc->device->tagged_supported &&
159 sc->device->ordered_tags && tag >= 0)
160 return MSG_ORDERED_TAG;
161
162 return MSG_SIMPLE_TAG;
163}
164
165static void tcm_loop_submission_work(struct work_struct *work) 138static void tcm_loop_submission_work(struct work_struct *work)
166{ 139{
167 struct tcm_loop_cmd *tl_cmd = 140 struct tcm_loop_cmd *tl_cmd =
@@ -220,7 +193,7 @@ static void tcm_loop_submission_work(struct work_struct *work)
220 193
221 rc = target_submit_cmd_map_sgls(se_cmd, tl_nexus->se_sess, sc->cmnd, 194 rc = target_submit_cmd_map_sgls(se_cmd, tl_nexus->se_sess, sc->cmnd,
222 &tl_cmd->tl_sense_buf[0], tl_cmd->sc->device->lun, 195 &tl_cmd->tl_sense_buf[0], tl_cmd->sc->device->lun,
223 transfer_length, tcm_loop_sam_attr(sc, tl_cmd->sc_cmd_tag), 196 transfer_length, MSG_SIMPLE_TAG,
224 sc->sc_data_direction, 0, 197 sc->sc_data_direction, 0,
225 scsi_sglist(sc), scsi_sg_count(sc), 198 scsi_sglist(sc), scsi_sg_count(sc),
226 sgl_bidi, sgl_bidi_count, 199 sgl_bidi, sgl_bidi_count,
@@ -431,27 +404,13 @@ static int tcm_loop_slave_alloc(struct scsi_device *sd)
431 return 0; 404 return 0;
432} 405}
433 406
434static int tcm_loop_slave_configure(struct scsi_device *sd)
435{
436 if (sd->tagged_supported) {
437 scsi_activate_tcq(sd, sd->queue_depth);
438 scsi_adjust_queue_depth(sd, MSG_SIMPLE_TAG,
439 sd->host->cmd_per_lun);
440 } else {
441 scsi_adjust_queue_depth(sd, 0,
442 sd->host->cmd_per_lun);
443 }
444
445 return 0;
446}
447
448static struct scsi_host_template tcm_loop_driver_template = { 407static struct scsi_host_template tcm_loop_driver_template = {
449 .show_info = tcm_loop_show_info, 408 .show_info = tcm_loop_show_info,
450 .proc_name = "tcm_loopback", 409 .proc_name = "tcm_loopback",
451 .name = "TCM_Loopback", 410 .name = "TCM_Loopback",
452 .queuecommand = tcm_loop_queuecommand, 411 .queuecommand = tcm_loop_queuecommand,
453 .change_queue_depth = tcm_loop_change_queue_depth, 412 .change_queue_depth = tcm_loop_change_queue_depth,
454 .change_queue_type = tcm_loop_change_queue_type, 413 .change_queue_type = scsi_change_queue_type,
455 .eh_abort_handler = tcm_loop_abort_task, 414 .eh_abort_handler = tcm_loop_abort_task,
456 .eh_device_reset_handler = tcm_loop_device_reset, 415 .eh_device_reset_handler = tcm_loop_device_reset,
457 .eh_target_reset_handler = tcm_loop_target_reset, 416 .eh_target_reset_handler = tcm_loop_target_reset,
@@ -462,8 +421,8 @@ static struct scsi_host_template tcm_loop_driver_template = {
462 .max_sectors = 0xFFFF, 421 .max_sectors = 0xFFFF,
463 .use_clustering = DISABLE_CLUSTERING, 422 .use_clustering = DISABLE_CLUSTERING,
464 .slave_alloc = tcm_loop_slave_alloc, 423 .slave_alloc = tcm_loop_slave_alloc,
465 .slave_configure = tcm_loop_slave_configure,
466 .module = THIS_MODULE, 424 .module = THIS_MODULE,
425 .use_blk_tags = 1,
467}; 426};
468 427
469static int tcm_loop_driver_probe(struct device *dev) 428static int tcm_loop_driver_probe(struct device *dev)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index fb87780929d2..75cbde1f7c5b 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -576,7 +576,7 @@ static inline int core_alua_state_standby(
576 case SEND_DIAGNOSTIC: 576 case SEND_DIAGNOSTIC:
577 case READ_CAPACITY: 577 case READ_CAPACITY:
578 return 0; 578 return 0;
579 case SERVICE_ACTION_IN: 579 case SERVICE_ACTION_IN_16:
580 switch (cdb[1] & 0x1f) { 580 switch (cdb[1] & 0x1f) {
581 case SAI_READ_CAPACITY_16: 581 case SAI_READ_CAPACITY_16:
582 return 0; 582 return 0;
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 9f93b8234095..4c261c33cf55 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -459,7 +459,7 @@ static int core_scsi3_pr_seq_non_holder(
459 case ACCESS_CONTROL_OUT: 459 case ACCESS_CONTROL_OUT:
460 case INQUIRY: 460 case INQUIRY:
461 case LOG_SENSE: 461 case LOG_SENSE:
462 case READ_MEDIA_SERIAL_NUMBER: 462 case SERVICE_ACTION_IN_12:
463 case REPORT_LUNS: 463 case REPORT_LUNS:
464 case REQUEST_SENSE: 464 case REQUEST_SENSE:
465 case PERSISTENT_RESERVE_IN: 465 case PERSISTENT_RESERVE_IN:
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index ebe62afb957d..8d171ff77e75 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -852,7 +852,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
852 size = READ_CAP_LEN; 852 size = READ_CAP_LEN;
853 cmd->execute_cmd = sbc_emulate_readcapacity; 853 cmd->execute_cmd = sbc_emulate_readcapacity;
854 break; 854 break;
855 case SERVICE_ACTION_IN: 855 case SERVICE_ACTION_IN_16:
856 switch (cmd->t_task_cdb[1] & 0x1f) { 856 switch (cmd->t_task_cdb[1] & 0x1f) {
857 case SAI_READ_CAPACITY_16: 857 case SAI_READ_CAPACITY_16:
858 cmd->execute_cmd = sbc_emulate_readcapacity_16; 858 cmd->execute_cmd = sbc_emulate_readcapacity_16;
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
index 6cdb7a534f23..024f58475a94 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
@@ -912,7 +912,7 @@ static int get_cmd_dir(const unsigned char *cdb)
912 case INQUIRY: 912 case INQUIRY:
913 case MODE_SENSE: 913 case MODE_SENSE:
914 case MODE_SENSE_10: 914 case MODE_SENSE_10:
915 case SERVICE_ACTION_IN: 915 case SERVICE_ACTION_IN_16:
916 case MAINTENANCE_IN: 916 case MAINTENANCE_IN:
917 case PERSISTENT_RESERVE_IN: 917 case PERSISTENT_RESERVE_IN:
918 case SECURITY_PROTOCOL_IN: 918 case SECURITY_PROTOCOL_IN:
diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c
index e08f64780e30..66a684a29938 100644
--- a/drivers/usb/storage/debug.c
+++ b/drivers/usb/storage/debug.c
@@ -164,10 +164,10 @@ void usb_stor_show_sense(const struct us_data *us,
164 unsigned char asc, 164 unsigned char asc,
165 unsigned char ascq) 165 unsigned char ascq)
166{ 166{
167 const char *what, *keystr; 167 const char *what, *keystr, *fmt;
168 168
169 keystr = scsi_sense_key_string(key); 169 keystr = scsi_sense_key_string(key);
170 what = scsi_extd_sense_format(asc, ascq); 170 what = scsi_extd_sense_format(asc, ascq, &fmt);
171 171
172 if (keystr == NULL) 172 if (keystr == NULL)
173 keystr = "(Unknown Key)"; 173 keystr = "(Unknown Key)";
@@ -175,8 +175,10 @@ void usb_stor_show_sense(const struct us_data *us,
175 what = "(unknown ASC/ASCQ)"; 175 what = "(unknown ASC/ASCQ)";
176 176
177 usb_stor_dbg(us, "%s: ", keystr); 177 usb_stor_dbg(us, "%s: ", keystr);
178 US_DEBUGPX(what, ascq); 178 if (fmt)
179 US_DEBUGPX("\n"); 179 US_DEBUGPX("%s (%s%x)\n", what, fmt, ascq);
180 else
181 US_DEBUGPX("%s\n", what);
180} 182}
181 183
182int usb_stor_dbg(const struct us_data *us, const char *fmt, ...) 184int usb_stor_dbg(const struct us_data *us, const char *fmt, ...)
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 89b24349269e..33f211b56a42 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -181,7 +181,7 @@ static int uas_get_tag(struct scsi_cmnd *cmnd)
181{ 181{
182 int tag; 182 int tag;
183 183
184 if (blk_rq_tagged(cmnd->request)) 184 if (cmnd->flags & SCMD_TAGGED)
185 tag = cmnd->request->tag + 2; 185 tag = cmnd->request->tag + 2;
186 else 186 else
187 tag = 1; 187 tag = 1;
@@ -799,8 +799,7 @@ static int uas_slave_configure(struct scsi_device *sdev)
799 if (devinfo->flags & US_FL_NO_REPORT_OPCODES) 799 if (devinfo->flags & US_FL_NO_REPORT_OPCODES)
800 sdev->no_report_opcodes = 1; 800 sdev->no_report_opcodes = 1;
801 801
802 scsi_set_tag_type(sdev, MSG_ORDERED_TAG); 802 scsi_adjust_queue_depth(sdev, devinfo->qdepth - 2);
803 scsi_activate_tcq(sdev, devinfo->qdepth - 2);
804 return 0; 803 return 0;
805} 804}
806 805
@@ -817,7 +816,6 @@ static struct scsi_host_template uas_host_template = {
817 .sg_tablesize = SG_NONE, 816 .sg_tablesize = SG_NONE,
818 .cmd_per_lun = 1, /* until we override it */ 817 .cmd_per_lun = 1, /* until we override it */
819 .skip_settle_delay = 1, 818 .skip_settle_delay = 1,
820 .ordered_tag = 1,
821 819
822 /* 820 /*
823 * The uas drivers expects tags not to be bigger than the maximum 821 * The uas drivers expects tags not to be bigger than the maximum
@@ -825,6 +823,7 @@ static struct scsi_host_template uas_host_template = {
825 * allocator. 823 * allocator.
826 */ 824 */
827 .disable_blk_mq = true, 825 .disable_blk_mq = true,
826 .use_blk_tags = 1,
828}; 827};
829 828
830#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ 829#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 3e32146472a5..50610a6acf3d 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -274,10 +274,6 @@ static void scsiback_print_status(char *sense_buffer, int errors,
274 tpg->tport->tport_name, pending_req->v2p->lun, 274 tpg->tport->tport_name, pending_req->v2p->lun,
275 pending_req->cmnd[0], status_byte(errors), msg_byte(errors), 275 pending_req->cmnd[0], status_byte(errors), msg_byte(errors),
276 host_byte(errors), driver_byte(errors)); 276 host_byte(errors), driver_byte(errors));
277
278 if (CHECK_CONDITION & status_byte(errors))
279 __scsi_print_sense("xen-pvscsi", sense_buffer,
280 SCSI_SENSE_BUFFERSIZE);
281} 277}
282 278
283static void scsiback_fast_flush_area(struct vscsibk_pend *req) 279static void scsiback_fast_flush_area(struct vscsibk_pend *req)
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index c9be1589415a..15f7034aa377 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -167,6 +167,23 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
167 gfp_t gfp, bool reserved); 167 gfp_t gfp, bool reserved);
168struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag); 168struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag);
169 169
170enum {
171 BLK_MQ_UNIQUE_TAG_BITS = 16,
172 BLK_MQ_UNIQUE_TAG_MASK = (1 << BLK_MQ_UNIQUE_TAG_BITS) - 1,
173};
174
175u32 blk_mq_unique_tag(struct request *rq);
176
177static inline u16 blk_mq_unique_tag_to_hwq(u32 unique_tag)
178{
179 return unique_tag >> BLK_MQ_UNIQUE_TAG_BITS;
180}
181
182static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
183{
184 return unique_tag & BLK_MQ_UNIQUE_TAG_MASK;
185}
186
170struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index); 187struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
171struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int); 188struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
172 189
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index aac0f9ea952a..6d76b8b4aa2b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1136,7 +1136,6 @@ static inline bool blk_needs_flush_plug(struct task_struct *tsk)
1136/* 1136/*
1137 * tag stuff 1137 * tag stuff
1138 */ 1138 */
1139#define blk_rq_tagged(rq) ((rq)->cmd_flags & REQ_QUEUED)
1140extern int blk_queue_start_tag(struct request_queue *, struct request *); 1139extern int blk_queue_start_tag(struct request_queue *, struct request *);
1141extern struct request *blk_queue_find_tag(struct request_queue *, int); 1140extern struct request *blk_queue_find_tag(struct request_queue *, int);
1142extern void blk_queue_end_tag(struct request_queue *, struct request *); 1141extern void blk_queue_end_tag(struct request_queue *, struct request *);
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index 52beadf9a29b..2e0cf568a9c1 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -1106,7 +1106,6 @@ int fc_eh_device_reset(struct scsi_cmnd *);
1106int fc_eh_host_reset(struct scsi_cmnd *); 1106int fc_eh_host_reset(struct scsi_cmnd *);
1107int fc_slave_alloc(struct scsi_device *); 1107int fc_slave_alloc(struct scsi_device *);
1108int fc_change_queue_depth(struct scsi_device *, int qdepth, int reason); 1108int fc_change_queue_depth(struct scsi_device *, int qdepth, int reason);
1109int fc_change_queue_type(struct scsi_device *, int tag_type);
1110 1109
1111/* 1110/*
1112 * ELS/CT interface 1111 * ELS/CT interface
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index d17178e6fcdd..8a7f8ad58aac 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -128,8 +128,10 @@ enum scsi_timeouts {
128#define MOVE_MEDIUM 0xa5 128#define MOVE_MEDIUM 0xa5
129#define EXCHANGE_MEDIUM 0xa6 129#define EXCHANGE_MEDIUM 0xa6
130#define READ_12 0xa8 130#define READ_12 0xa8
131#define SERVICE_ACTION_OUT_12 0xa9
131#define WRITE_12 0xaa 132#define WRITE_12 0xaa
132#define READ_MEDIA_SERIAL_NUMBER 0xab 133#define READ_MEDIA_SERIAL_NUMBER 0xab /* Obsolete with SPC-2 */
134#define SERVICE_ACTION_IN_12 0xab
133#define WRITE_VERIFY_12 0xae 135#define WRITE_VERIFY_12 0xae
134#define VERIFY_12 0xaf 136#define VERIFY_12 0xaf
135#define SEARCH_HIGH_12 0xb0 137#define SEARCH_HIGH_12 0xb0
@@ -151,7 +153,9 @@ enum scsi_timeouts {
151#define VERIFY_16 0x8f 153#define VERIFY_16 0x8f
152#define SYNCHRONIZE_CACHE_16 0x91 154#define SYNCHRONIZE_CACHE_16 0x91
153#define WRITE_SAME_16 0x93 155#define WRITE_SAME_16 0x93
154#define SERVICE_ACTION_IN 0x9e 156#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
157#define SERVICE_ACTION_IN_16 0x9e
158#define SERVICE_ACTION_OUT_16 0x9f
155/* values for service action in */ 159/* values for service action in */
156#define SAI_READ_CAPACITY_16 0x10 160#define SAI_READ_CAPACITY_16 0x10
157#define SAI_GET_LBA_STATUS 0x12 161#define SAI_GET_LBA_STATUS 0x12
@@ -165,8 +169,8 @@ enum scsi_timeouts {
165#define MI_REPORT_ALIASES 0x0b 169#define MI_REPORT_ALIASES 0x0b
166#define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c 170#define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
167#define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d 171#define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
168#define MI_REPORT_PRIORITY 0x0e 172#define MI_REPORT_PRIORITY 0x0e
169#define MI_REPORT_TIMESTAMP 0x0f 173#define MI_REPORT_TIMESTAMP 0x0f
170#define MI_MANAGEMENT_PROTOCOL_IN 0x10 174#define MI_MANAGEMENT_PROTOCOL_IN 0x10
171/* value for MI_REPORT_TARGET_PGS ext header */ 175/* value for MI_REPORT_TARGET_PGS ext header */
172#define MI_EXT_HDR_PARAM_FMT 0x20 176#define MI_EXT_HDR_PARAM_FMT 0x20
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 522a5f27f553..9fc1aecfc813 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -53,6 +53,9 @@ struct scsi_pointer {
53 volatile int phase; 53 volatile int phase;
54}; 54};
55 55
56/* for scmd->flags */
57#define SCMD_TAGGED (1 << 0)
58
56struct scsi_cmnd { 59struct scsi_cmnd {
57 struct scsi_device *device; 60 struct scsi_device *device;
58 struct list_head list; /* scsi_cmnd participates in queue lists */ 61 struct list_head list; /* scsi_cmnd participates in queue lists */
@@ -132,6 +135,7 @@ struct scsi_cmnd {
132 * to be at an address < 16Mb). */ 135 * to be at an address < 16Mb). */
133 136
134 int result; /* Status code from lower level driver */ 137 int result; /* Status code from lower level driver */
138 int flags; /* Command flags */
135 139
136 unsigned char tag; /* SCSI-II queued command tag */ 140 unsigned char tag; /* SCSI-II queued command tag */
137}; 141};
@@ -159,7 +163,7 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
159 size_t *offset, size_t *len); 163 size_t *offset, size_t *len);
160extern void scsi_kunmap_atomic_sg(void *virt); 164extern void scsi_kunmap_atomic_sg(void *virt);
161 165
162extern int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask); 166extern int scsi_init_io(struct scsi_cmnd *cmd);
163 167
164extern int scsi_dma_map(struct scsi_cmnd *cmd); 168extern int scsi_dma_map(struct scsi_cmnd *cmd);
165extern void scsi_dma_unmap(struct scsi_cmnd *cmd); 169extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h
index e89844cc2cd3..7982795df595 100644
--- a/include/scsi/scsi_dbg.h
+++ b/include/scsi/scsi_dbg.h
@@ -2,23 +2,27 @@
2#define _SCSI_SCSI_DBG_H 2#define _SCSI_SCSI_DBG_H
3 3
4struct scsi_cmnd; 4struct scsi_cmnd;
5struct scsi_device;
5struct scsi_sense_hdr; 6struct scsi_sense_hdr;
6 7
7extern void scsi_print_command(struct scsi_cmnd *); 8extern void scsi_print_command(struct scsi_cmnd *);
8extern void __scsi_print_command(unsigned char *); 9extern void __scsi_print_command(const unsigned char *, size_t);
9extern void scsi_show_extd_sense(unsigned char, unsigned char); 10extern void scsi_show_extd_sense(const struct scsi_device *, const char *,
10extern void scsi_show_sense_hdr(struct scsi_sense_hdr *); 11 unsigned char, unsigned char);
11extern void scsi_print_sense_hdr(const char *, struct scsi_sense_hdr *); 12extern void scsi_show_sense_hdr(const struct scsi_device *, const char *,
12extern void scsi_cmd_print_sense_hdr(struct scsi_cmnd *, const char *, 13 const struct scsi_sense_hdr *);
13 struct scsi_sense_hdr *); 14extern void scsi_print_sense_hdr(const struct scsi_device *, const char *,
14extern void scsi_print_sense(char *, struct scsi_cmnd *); 15 const struct scsi_sense_hdr *);
15extern void __scsi_print_sense(const char *name, 16extern void scsi_print_sense(const struct scsi_cmnd *);
17extern void __scsi_print_sense(const struct scsi_device *, const char *name,
16 const unsigned char *sense_buffer, 18 const unsigned char *sense_buffer,
17 int sense_len); 19 int sense_len);
18extern void scsi_show_result(int); 20extern void scsi_print_result(struct scsi_cmnd *, const char *, int);
19extern void scsi_print_result(struct scsi_cmnd *); 21extern const char *scsi_hostbyte_string(int);
20extern void scsi_print_status(unsigned char); 22extern const char *scsi_driverbyte_string(int);
23extern const char *scsi_mlreturn_string(int);
21extern const char *scsi_sense_key_string(unsigned char); 24extern const char *scsi_sense_key_string(unsigned char);
22extern const char *scsi_extd_sense_format(unsigned char, unsigned char); 25extern const char *scsi_extd_sense_format(unsigned char, unsigned char,
26 const char **);
23 27
24#endif /* _SCSI_SCSI_DBG_H */ 28#endif /* _SCSI_SCSI_DBG_H */
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 27ecee73bd72..0aeaa003c3c1 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -141,7 +141,6 @@ struct scsi_device {
141 unsigned ppr:1; /* Device supports PPR messages */ 141 unsigned ppr:1; /* Device supports PPR messages */
142 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */ 142 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */
143 unsigned simple_tags:1; /* simple queue tag messages are enabled */ 143 unsigned simple_tags:1; /* simple queue tag messages are enabled */
144 unsigned ordered_tags:1;/* ordered queue tag messages are enabled */
145 unsigned was_reset:1; /* There was a bus reset on the bus for 144 unsigned was_reset:1; /* There was a bus reset on the bus for
146 * this device */ 145 * this device */
147 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN 146 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
@@ -201,11 +200,6 @@ struct scsi_device {
201 unsigned long sdev_data[0]; 200 unsigned long sdev_data[0];
202} __attribute__((aligned(sizeof(unsigned long)))); 201} __attribute__((aligned(sizeof(unsigned long))));
203 202
204struct scsi_dh_devlist {
205 char *vendor;
206 char *model;
207};
208
209typedef void (*activate_complete)(void *, int); 203typedef void (*activate_complete)(void *, int);
210struct scsi_device_handler { 204struct scsi_device_handler {
211 /* Used by the infrastructure */ 205 /* Used by the infrastructure */
@@ -214,9 +208,8 @@ struct scsi_device_handler {
214 /* Filled by the hardware handler */ 208 /* Filled by the hardware handler */
215 struct module *module; 209 struct module *module;
216 const char *name; 210 const char *name;
217 const struct scsi_dh_devlist *devlist;
218 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *); 211 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *);
219 int (*attach)(struct scsi_device *); 212 struct scsi_dh_data *(*attach)(struct scsi_device *);
220 void (*detach)(struct scsi_device *); 213 void (*detach)(struct scsi_device *);
221 int (*activate)(struct scsi_device *, activate_complete, void *); 214 int (*activate)(struct scsi_device *, activate_complete, void *);
222 int (*prep_fn)(struct scsi_device *, struct request *); 215 int (*prep_fn)(struct scsi_device *, struct request *);
@@ -228,7 +221,6 @@ struct scsi_dh_data {
228 struct scsi_device_handler *scsi_dh; 221 struct scsi_device_handler *scsi_dh;
229 struct scsi_device *sdev; 222 struct scsi_device *sdev;
230 struct kref kref; 223 struct kref kref;
231 char buf[0];
232}; 224};
233 225
234#define to_scsi_device(d) \ 226#define to_scsi_device(d) \
@@ -244,6 +236,15 @@ struct scsi_dh_data {
244#define sdev_dbg(sdev, fmt, a...) \ 236#define sdev_dbg(sdev, fmt, a...) \
245 dev_dbg(&(sdev)->sdev_gendev, fmt, ##a) 237 dev_dbg(&(sdev)->sdev_gendev, fmt, ##a)
246 238
239/*
240 * like scmd_printk, but the device name is passed in
241 * as a string pointer
242 */
243#define sdev_prefix_printk(l, sdev, p, fmt, a...) \
244 (p) ? \
245 sdev_printk(l, sdev, "[%s] " fmt, p, ##a) : \
246 sdev_printk(l, sdev, fmt, ##a)
247
247#define scmd_printk(prefix, scmd, fmt, a...) \ 248#define scmd_printk(prefix, scmd, fmt, a...) \
248 (scmd)->request->rq_disk ? \ 249 (scmd)->request->rq_disk ? \
249 sdev_printk(prefix, (scmd)->device, "[%s] " fmt, \ 250 sdev_printk(prefix, (scmd)->device, "[%s] " fmt, \
@@ -379,7 +380,7 @@ extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
379#define __shost_for_each_device(sdev, shost) \ 380#define __shost_for_each_device(sdev, shost) \
380 list_for_each_entry((sdev), &((shost)->__devices), siblings) 381 list_for_each_entry((sdev), &((shost)->__devices), siblings)
381 382
382extern void scsi_adjust_queue_depth(struct scsi_device *, int, int); 383extern void scsi_adjust_queue_depth(struct scsi_device *, int);
383extern int scsi_track_queue_full(struct scsi_device *, int); 384extern int scsi_track_queue_full(struct scsi_device *, int);
384 385
385extern int scsi_set_medium_removal(struct scsi_device *, char); 386extern int scsi_set_medium_removal(struct scsi_device *, char);
diff --git a/include/scsi/scsi_driver.h b/include/scsi/scsi_driver.h
index c2b759809d8a..891a658aa867 100644
--- a/include/scsi/scsi_driver.h
+++ b/include/scsi/scsi_driver.h
@@ -9,7 +9,6 @@ struct scsi_cmnd;
9struct scsi_device; 9struct scsi_device;
10 10
11struct scsi_driver { 11struct scsi_driver {
12 struct module *owner;
13 struct device_driver gendrv; 12 struct device_driver gendrv;
14 13
15 void (*rescan)(struct device *); 14 void (*rescan)(struct device *);
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index 06a8790893ef..1e1421b06565 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -27,10 +27,10 @@ struct scsi_sense_hdr { /* See SPC-3 section 4.5 */
27 u8 additional_length; /* always 0 for fixed sense format */ 27 u8 additional_length; /* always 0 for fixed sense format */
28}; 28};
29 29
30static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr) 30static inline bool scsi_sense_valid(const struct scsi_sense_hdr *sshdr)
31{ 31{
32 if (!sshdr) 32 if (!sshdr)
33 return 0; 33 return false;
34 34
35 return (sshdr->response_code & 0x70) == 0x70; 35 return (sshdr->response_code & 0x70) == 0x70;
36} 36}
@@ -42,12 +42,12 @@ extern void scsi_eh_flush_done_q(struct list_head *done_q);
42extern void scsi_report_bus_reset(struct Scsi_Host *, int); 42extern void scsi_report_bus_reset(struct Scsi_Host *, int);
43extern void scsi_report_device_reset(struct Scsi_Host *, int, int); 43extern void scsi_report_device_reset(struct Scsi_Host *, int, int);
44extern int scsi_block_when_processing_errors(struct scsi_device *); 44extern int scsi_block_when_processing_errors(struct scsi_device *);
45extern int scsi_normalize_sense(const u8 *sense_buffer, int sb_len, 45extern bool scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
46 struct scsi_sense_hdr *sshdr); 46 struct scsi_sense_hdr *sshdr);
47extern int scsi_command_normalize_sense(struct scsi_cmnd *cmd, 47extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
48 struct scsi_sense_hdr *sshdr); 48 struct scsi_sense_hdr *sshdr);
49 49
50static inline int scsi_sense_is_deferred(struct scsi_sense_hdr *sshdr) 50static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr)
51{ 51{
52 return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1)); 52 return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1));
53} 53}
@@ -60,15 +60,7 @@ extern int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len,
60 60
61extern void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq); 61extern void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq);
62 62
63/* 63extern int scsi_ioctl_reset(struct scsi_device *, int __user *);
64 * Reset request from external source
65 */
66#define SCSI_TRY_RESET_DEVICE 1
67#define SCSI_TRY_RESET_BUS 2
68#define SCSI_TRY_RESET_HOST 3
69#define SCSI_TRY_RESET_TARGET 4
70
71extern int scsi_reset_provider(struct scsi_device *, int);
72 64
73struct scsi_eh_save { 65struct scsi_eh_save {
74 /* saved state */ 66 /* saved state */
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 5e362489ee88..61a81bf77e28 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -422,6 +422,11 @@ struct scsi_host_template {
422 unsigned char present; 422 unsigned char present;
423 423
424 /* 424 /*
425 * Let the block layer assigns tags to all commands.
426 */
427 unsigned use_blk_tags:1;
428
429 /*
425 * This specifies the mode that a LLD supports. 430 * This specifies the mode that a LLD supports.
426 */ 431 */
427 unsigned supported_mode:2; 432 unsigned supported_mode:2;
@@ -451,11 +456,6 @@ struct scsi_host_template {
451 */ 456 */
452 unsigned skip_settle_delay:1; 457 unsigned skip_settle_delay:1;
453 458
454 /*
455 * True if we are using ordered write support.
456 */
457 unsigned ordered_tag:1;
458
459 /* True if the controller does not support WRITE SAME */ 459 /* True if the controller does not support WRITE SAME */
460 unsigned no_write_same:1; 460 unsigned no_write_same:1;
461 461
@@ -638,6 +638,14 @@ struct Scsi_Host {
638 short unsigned int sg_prot_tablesize; 638 short unsigned int sg_prot_tablesize;
639 unsigned int max_sectors; 639 unsigned int max_sectors;
640 unsigned long dma_boundary; 640 unsigned long dma_boundary;
641 /*
642 * In scsi-mq mode, the number of hardware queues supported by the LLD.
643 *
644 * Note: it is assumed that each hardware queue has a queue depth of
645 * can_queue. In other words, the total queue depth per host
646 * is nr_hw_queues * can_queue.
647 */
648 unsigned nr_hw_queues;
641 /* 649 /*
642 * Used to assign serial numbers to the cmds. 650 * Used to assign serial numbers to the cmds.
643 * Protected by the host lock. 651 * Protected by the host lock.
@@ -647,7 +655,6 @@ struct Scsi_Host {
647 unsigned active_mode:2; 655 unsigned active_mode:2;
648 unsigned unchecked_isa_dma:1; 656 unsigned unchecked_isa_dma:1;
649 unsigned use_clustering:1; 657 unsigned use_clustering:1;
650 unsigned use_blk_tcq:1;
651 658
652 /* 659 /*
653 * Host has requested that no further requests come through for the 660 * Host has requested that no further requests come through for the
@@ -662,11 +669,6 @@ struct Scsi_Host {
662 */ 669 */
663 unsigned reverse_ordering:1; 670 unsigned reverse_ordering:1;
664 671
665 /*
666 * Ordered write support
667 */
668 unsigned ordered_tag:1;
669
670 /* Task mgmt function in progress */ 672 /* Task mgmt function in progress */
671 unsigned tmf_in_progress:1; 673 unsigned tmf_in_progress:1;
672 674
diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h
index b9006848b813..8d19d1d233c3 100644
--- a/include/scsi/scsi_ioctl.h
+++ b/include/scsi/scsi_ioctl.h
@@ -40,9 +40,9 @@ typedef struct scsi_fctargaddress {
40 unsigned char host_wwn[8]; // include NULL term. 40 unsigned char host_wwn[8]; // include NULL term.
41} Scsi_FCTargAddress; 41} Scsi_FCTargAddress;
42 42
43int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev,
44 int cmd, bool ndelay);
43extern int scsi_ioctl(struct scsi_device *, int, void __user *); 45extern int scsi_ioctl(struct scsi_device *, int, void __user *);
44extern int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd,
45 void __user *arg, int ndelay);
46 46
47#endif /* __KERNEL__ */ 47#endif /* __KERNEL__ */
48#endif /* _SCSI_IOCTL_H */ 48#endif /* _SCSI_IOCTL_H */
diff --git a/include/scsi/scsi_tcq.h b/include/scsi/scsi_tcq.h
index 56ed843969ca..fe4a70299419 100644
--- a/include/scsi/scsi_tcq.h
+++ b/include/scsi/scsi_tcq.h
@@ -16,20 +16,16 @@
16 16
17#ifdef CONFIG_BLOCK 17#ifdef CONFIG_BLOCK
18 18
19int scsi_change_queue_type(struct scsi_device *sdev, int tag_type);
20
19/** 21/**
20 * scsi_get_tag_type - get the type of tag the device supports 22 * scsi_get_tag_type - get the type of tag the device supports
21 * @sdev: the scsi device 23 * @sdev: the scsi device
22 *
23 * Notes:
24 * If the drive only supports simple tags, returns MSG_SIMPLE_TAG
25 * if it supports all tag types, returns MSG_ORDERED_TAG.
26 */ 24 */
27static inline int scsi_get_tag_type(struct scsi_device *sdev) 25static inline int scsi_get_tag_type(struct scsi_device *sdev)
28{ 26{
29 if (!sdev->tagged_supported) 27 if (!sdev->tagged_supported)
30 return 0; 28 return 0;
31 if (sdev->ordered_tags)
32 return MSG_ORDERED_TAG;
33 if (sdev->simple_tags) 29 if (sdev->simple_tags)
34 return MSG_SIMPLE_TAG; 30 return MSG_SIMPLE_TAG;
35 return 0; 31 return 0;
@@ -39,90 +35,33 @@ static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag)
39{ 35{
40 switch (tag) { 36 switch (tag) {
41 case MSG_ORDERED_TAG: 37 case MSG_ORDERED_TAG:
42 sdev->ordered_tags = 1;
43 /* fall through */
44 case MSG_SIMPLE_TAG: 38 case MSG_SIMPLE_TAG:
45 sdev->simple_tags = 1; 39 sdev->simple_tags = 1;
46 break; 40 break;
47 case 0: 41 case 0:
48 /* fall through */ 42 /* fall through */
49 default: 43 default:
50 sdev->ordered_tags = 0;
51 sdev->simple_tags = 0; 44 sdev->simple_tags = 0;
52 break; 45 break;
53 } 46 }
54} 47}
55/**
56 * scsi_activate_tcq - turn on tag command queueing
57 * @SDpnt: device to turn on TCQ for
58 * @depth: queue depth
59 *
60 * Notes:
61 * Eventually, I hope depth would be the maximum depth
62 * the device could cope with and the real queue depth
63 * would be adjustable from 0 to depth.
64 **/
65static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)
66{
67 if (!sdev->tagged_supported)
68 return;
69
70 if (shost_use_blk_mq(sdev->host))
71 queue_flag_set_unlocked(QUEUE_FLAG_QUEUED, sdev->request_queue);
72 else if (!blk_queue_tagged(sdev->request_queue))
73 blk_queue_init_tags(sdev->request_queue, depth,
74 sdev->host->bqt);
75
76 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
77}
78
79/**
80 * scsi_deactivate_tcq - turn off tag command queueing
81 * @SDpnt: device to turn off TCQ for
82 **/
83static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
84{
85 if (blk_queue_tagged(sdev->request_queue))
86 blk_queue_free_tags(sdev->request_queue);
87 scsi_adjust_queue_depth(sdev, 0, depth);
88}
89
90/**
91 * scsi_populate_tag_msg - place a tag message in a buffer
92 * @SCpnt: pointer to the Scsi_Cmnd for the tag
93 * @msg: pointer to the area to place the tag
94 *
95 * Notes:
96 * designed to create the correct type of tag message for the
97 * particular request. Returns the size of the tag message.
98 * May return 0 if TCQ is disabled for this device.
99 **/
100static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)
101{
102 struct request *req = cmd->request;
103
104 if (blk_rq_tagged(req)) {
105 *msg++ = MSG_SIMPLE_TAG;
106 *msg++ = req->tag;
107 return 2;
108 }
109
110 return 0;
111}
112 48
113static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost, 49static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost,
114 unsigned int hw_ctx, int tag) 50 int unique_tag)
115{ 51{
116 struct request *req; 52 u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag);
53 struct request *req = NULL;
117 54
118 req = blk_mq_tag_to_rq(shost->tag_set.tags[hw_ctx], tag); 55 if (hwq < shost->tag_set.nr_hw_queues)
56 req = blk_mq_tag_to_rq(shost->tag_set.tags[hwq],
57 blk_mq_unique_tag_to_tag(unique_tag));
119 return req ? (struct scsi_cmnd *)req->special : NULL; 58 return req ? (struct scsi_cmnd *)req->special : NULL;
120} 59}
121 60
122/** 61/**
123 * scsi_find_tag - find a tagged command by device 62 * scsi_find_tag - find a tagged command by device
124 * @SDpnt: pointer to the ScSI device 63 * @SDpnt: pointer to the ScSI device
125 * @tag: the tag number 64 * @tag: tag generated by blk_mq_unique_tag()
126 * 65 *
127 * Notes: 66 * Notes:
128 * Only works with tags allocated by the generic blk layer. 67 * Only works with tags allocated by the generic blk layer.
@@ -133,9 +72,9 @@ static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
133 72
134 if (tag != SCSI_NO_TAG) { 73 if (tag != SCSI_NO_TAG) {
135 if (shost_use_blk_mq(sdev->host)) 74 if (shost_use_blk_mq(sdev->host))
136 return scsi_mq_find_tag(sdev->host, 0, tag); 75 return scsi_mq_find_tag(sdev->host, tag);
137 76
138 req = blk_queue_find_tag(sdev->request_queue, tag); 77 req = blk_queue_find_tag(sdev->request_queue, tag);
139 return req ? (struct scsi_cmnd *)req->special : NULL; 78 return req ? (struct scsi_cmnd *)req->special : NULL;
140 } 79 }
141 80
@@ -174,7 +113,7 @@ static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
174/** 113/**
175 * scsi_host_find_tag - find the tagged command by host 114 * scsi_host_find_tag - find the tagged command by host
176 * @shost: pointer to scsi_host 115 * @shost: pointer to scsi_host
177 * @tag: tag of the scsi_cmnd 116 * @tag: tag generated by blk_mq_unique_tag()
178 * 117 *
179 * Notes: 118 * Notes:
180 * Only works with tags allocated by the generic blk layer. 119 * Only works with tags allocated by the generic blk layer.
@@ -186,7 +125,7 @@ static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
186 125
187 if (tag != SCSI_NO_TAG) { 126 if (tag != SCSI_NO_TAG) {
188 if (shost_use_blk_mq(shost)) 127 if (shost_use_blk_mq(shost))
189 return scsi_mq_find_tag(shost, 0, tag); 128 return scsi_mq_find_tag(shost, tag);
190 req = blk_map_queue_find_tag(shost->bqt, tag); 129 req = blk_map_queue_find_tag(shost->bqt, tag);
191 return req ? (struct scsi_cmnd *)req->special : NULL; 130 return req ? (struct scsi_cmnd *)req->special : NULL;
192 } 131 }
diff --git a/include/scsi/scsi_transport_spi.h b/include/scsi/scsi_transport_spi.h
index 7497a383b1a4..a4fa52b4d5c5 100644
--- a/include/scsi/scsi_transport_spi.h
+++ b/include/scsi/scsi_transport_spi.h
@@ -157,5 +157,6 @@ int spi_populate_width_msg(unsigned char *msg, int width);
157int spi_populate_sync_msg(unsigned char *msg, int period, int offset); 157int spi_populate_sync_msg(unsigned char *msg, int period, int offset);
158int spi_populate_ppr_msg(unsigned char *msg, int period, int offset, int width, 158int spi_populate_ppr_msg(unsigned char *msg, int period, int offset, int width,
159 int options); 159 int options);
160int spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd);
160 161
161#endif /* SCSI_TRANSPORT_SPI_H */ 162#endif /* SCSI_TRANSPORT_SPI_H */
diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index 750e5db7c6bf..3afec7032448 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -164,12 +164,15 @@ typedef struct sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
164 164
165/* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */ 165/* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */
166#define SG_SCSI_RESET 0x2284 166#define SG_SCSI_RESET 0x2284
167/* Associated values that can be given to SG_SCSI_RESET follow */ 167/* Associated values that can be given to SG_SCSI_RESET follow.
168 * SG_SCSI_RESET_NO_ESCALATE may be OR-ed to the _DEVICE, _TARGET, _BUS
169 * or _HOST reset value so only that action is attempted. */
168#define SG_SCSI_RESET_NOTHING 0 170#define SG_SCSI_RESET_NOTHING 0
169#define SG_SCSI_RESET_DEVICE 1 171#define SG_SCSI_RESET_DEVICE 1
170#define SG_SCSI_RESET_BUS 2 172#define SG_SCSI_RESET_BUS 2
171#define SG_SCSI_RESET_HOST 3 173#define SG_SCSI_RESET_HOST 3
172#define SG_SCSI_RESET_TARGET 4 174#define SG_SCSI_RESET_TARGET 4
175#define SG_SCSI_RESET_NO_ESCALATE 0x100
173 176
174/* synchronous SCSI command ioctl, (only in version 3 interface) */ 177/* synchronous SCSI command ioctl, (only in version 3 interface) */
175#define SG_IO 0x2285 /* similar effect as write() followed by read() */ 178#define SG_IO 0x2285 /* similar effect as write() followed by read() */
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index db6c93510f74..079bd10a01b4 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -94,7 +94,7 @@
94 scsi_opcode_name(WRITE_16), \ 94 scsi_opcode_name(WRITE_16), \
95 scsi_opcode_name(VERIFY_16), \ 95 scsi_opcode_name(VERIFY_16), \
96 scsi_opcode_name(WRITE_SAME_16), \ 96 scsi_opcode_name(WRITE_SAME_16), \
97 scsi_opcode_name(SERVICE_ACTION_IN), \ 97 scsi_opcode_name(SERVICE_ACTION_IN_16), \
98 scsi_opcode_name(SAI_READ_CAPACITY_16), \ 98 scsi_opcode_name(SAI_READ_CAPACITY_16), \
99 scsi_opcode_name(SAI_GET_LBA_STATUS), \ 99 scsi_opcode_name(SAI_GET_LBA_STATUS), \
100 scsi_opcode_name(MI_REPORT_TARGET_PGS), \ 100 scsi_opcode_name(MI_REPORT_TARGET_PGS), \
diff --git a/include/trace/events/target.h b/include/trace/events/target.h
index da9cc0f05c93..45403443dd82 100644
--- a/include/trace/events/target.h
+++ b/include/trace/events/target.h
@@ -96,7 +96,7 @@
96 scsi_opcode_name(WRITE_16), \ 96 scsi_opcode_name(WRITE_16), \
97 scsi_opcode_name(VERIFY_16), \ 97 scsi_opcode_name(VERIFY_16), \
98 scsi_opcode_name(WRITE_SAME_16), \ 98 scsi_opcode_name(WRITE_SAME_16), \
99 scsi_opcode_name(SERVICE_ACTION_IN), \ 99 scsi_opcode_name(SERVICE_ACTION_IN_16), \
100 scsi_opcode_name(SAI_READ_CAPACITY_16), \ 100 scsi_opcode_name(SAI_READ_CAPACITY_16), \
101 scsi_opcode_name(SAI_GET_LBA_STATUS), \ 101 scsi_opcode_name(SAI_GET_LBA_STATUS), \
102 scsi_opcode_name(MI_REPORT_TARGET_PGS), \ 102 scsi_opcode_name(MI_REPORT_TARGET_PGS), \
diff --git a/tools/lib/traceevent/plugin_scsi.c b/tools/lib/traceevent/plugin_scsi.c
index eda326fc8620..3727de48c8d5 100644
--- a/tools/lib/traceevent/plugin_scsi.c
+++ b/tools/lib/traceevent/plugin_scsi.c
@@ -85,8 +85,9 @@ typedef unsigned int u32;
85#define MOVE_MEDIUM 0xa5 85#define MOVE_MEDIUM 0xa5
86#define EXCHANGE_MEDIUM 0xa6 86#define EXCHANGE_MEDIUM 0xa6
87#define READ_12 0xa8 87#define READ_12 0xa8
88#define SERVICE_ACTION_OUT_12 0xa9
88#define WRITE_12 0xaa 89#define WRITE_12 0xaa
89#define READ_MEDIA_SERIAL_NUMBER 0xab 90#define SERVICE_ACTION_IN_12 0xab
90#define WRITE_VERIFY_12 0xae 91#define WRITE_VERIFY_12 0xae
91#define VERIFY_12 0xaf 92#define VERIFY_12 0xaf
92#define SEARCH_HIGH_12 0xb0 93#define SEARCH_HIGH_12 0xb0
@@ -107,7 +108,9 @@ typedef unsigned int u32;
107#define VERIFY_16 0x8f 108#define VERIFY_16 0x8f
108#define SYNCHRONIZE_CACHE_16 0x91 109#define SYNCHRONIZE_CACHE_16 0x91
109#define WRITE_SAME_16 0x93 110#define WRITE_SAME_16 0x93
110#define SERVICE_ACTION_IN 0x9e 111#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
112#define SERVICE_ACTION_IN_16 0x9e
113#define SERVICE_ACTION_OUT_16 0x9f
111/* values for service action in */ 114/* values for service action in */
112#define SAI_READ_CAPACITY_16 0x10 115#define SAI_READ_CAPACITY_16 0x10
113#define SAI_GET_LBA_STATUS 0x12 116#define SAI_GET_LBA_STATUS 0x12
@@ -393,7 +396,7 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
393 return scsi_trace_rw16(p, cdb, len); 396 return scsi_trace_rw16(p, cdb, len);
394 case UNMAP: 397 case UNMAP:
395 return scsi_trace_unmap(p, cdb, len); 398 return scsi_trace_unmap(p, cdb, len);
396 case SERVICE_ACTION_IN: 399 case SERVICE_ACTION_IN_16:
397 return scsi_trace_service_action_in(p, cdb, len); 400 return scsi_trace_service_action_in(p, cdb, len);
398 case VARIABLE_LENGTH_CMD: 401 case VARIABLE_LENGTH_CMD:
399 return scsi_trace_varlen(p, cdb, len); 402 return scsi_trace_varlen(p, cdb, len);