Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge patch series "Add Command Duration Limits support"

Niklas Cassel <nks@flawful.org> says:

This series adds support for Command Duration Limits.
The series is based on linux tag: v6.4-rc1
The series can also be found in git: https://github.com/floatious/linux/commits/cdl-v7

=================
CDL in ATA / SCSI
=================
Command Duration Limits is defined in:
T13 ATA Command Set - 5 (ACS-5) and
T10 SCSI Primary Commands - 6 (SPC-6) respectively
(a simpler version of CDL is defined in T10 SPC-5).

CDL defines Duration Limits Descriptors (DLD).
7 DLDs for read commands and 7 DLDs for write commands.
Simply put, a DLD contains a limit and a policy.

A command can specify that a certain limit should be applied by setting
the DLD index field (3 bits, so 0-7) in the command itself.

The DLD index points to one of the 7 DLDs.
DLD index 0 means no descriptor, so no limit.
DLD index 1-7 means DLD 1-7.

A DLD can have a few different policies, but the two major ones are:
-Policy 0xF (abort), command will be completed with command aborted error
(ATA) or status CHECK CONDITION (SCSI), with sense data indicating that
the command timed out.
-Policy 0xD (complete-unavailable), command will be completed without
error (ATA) or status GOOD (SCSI), with sense data indicating that the
command timed out. Note that the command will not have transferred any
data to/from the device when the command timed out, even though the
command returned success.

Regardless of the CDL policy, in case of a CDL timeout, the I/O will
result in a -ETIME error to user-space.

The DLDs are defined in the CDL log page(s) and are readable and writable.
Reading and writing the CDL DLDs are outside the scope of the kernel.
If a user wants to read or write the descriptors, they can do so using a
user-space application that sends passthrough commands, such as cdl-tools:
https://github.com/westerndigitalcorporation/cdl-tools

================================
The introduction of ioprio hints
================================
What the kernel does provide, is a method to let I/O use one of the CDL DLDs
defined in the device. Note that the kernel will simply forward the DLD index
to the device, so the kernel currently does not know, nor does it need to know,
how the DLDs are defined inside the device.

The way that the CDL DLD index is supplied to the kernel is by introducing a
new 10 bit "ioprio hint" field within the existing 16 bit ioprio definition.

Currently, only 6 out of the 16 ioprio bits are in use, the remaining 10 bits
are unused, and are currently explicitly disallowed to be set by the kernel.

For now, we only add ioprio hints representing CDL DLD index 1-7. Additional
ioprio hints for other QoS features could be defined in the future.

A theoretical future work could be to make an I/O scheduler aware of these
hints. E.g. for CDL, an I/O scheduler could make use of the duration limit
in each descriptor, and take that information into account while scheduling
commands. Right now, the ioprio hints will be ignored by the I/O schedulers.

==============================
How to use CDL from user-space
==============================
Since CDL is mutually exclusive with NCQ priority
(see ncq_prio_enable and sas_ncq_prio_enable in
Documentation/ABI/testing/sysfs-block-device),
CDL has to be explicitly enabled using:
echo 1 > /sys/block/$bdev/device/cdl_enable

Since the ioprio hints are supplied through the existing I/O priority API,
it should be simple for an application to make use of the ioprio hints.

It simply has to reuse one of the new macros defined in
include/uapi/linux/ioprio.h: IOPRIO_PRIO_HINT() or IOPRIO_PRIO_VALUE_HINT(),
and supply one of the new hints defined in include/uapi/linux/ioprio.h:
IOPRIO_HINT_DEV_DURATION_LIMIT_[1-7], which indicates that the I/O should
use the corresponding CDL DLD index 1-7.

By reusing the I/O priority API, the user can both define a DLD to use per
AIO (io_uring sqe->ioprio or libaio iocb->aio_reqprio) or per-thread
(ioprio_set()).

=======
Testing
=======
With the following fio patches:
https://github.com/floatious/fio/commits/cdl

fio adds support for ioprio hints, such that CDL can be tested using e.g.:
fio --ioengine=io_uring --cmdprio_percentage=10 --cmdprio_hint=DLD_index

A simple way to test is to use a DLD with a very short duration limit,
and send large reads. Regardless of the CDL policy, in case of a CDL
timeout, the I/O will result in a -ETIME error to user-space.

We also provide a CDL test suite located in the cdl-tools repo, see:
https://github.com/westerndigitalcorporation/cdl-tools#testing-a-system-command-duration-limits-support

We have tested this patch series using:
-real hardware
-the following QEMU implementation:
https://github.com/floatious/qemu/tree/cdl
(NOTE: the QEMU implementation requires you to define the CDL policy at compile
time, so you currently need to recompile QEMU when switching between policies.)

===================
Further information
===================
For further information about CDL, see Damien's slides:

Presented at SDC 2021:
https://www.snia.org/sites/default/files/SDC/2021/pdfs/SNIA-SDC21-LeMoal-Be-On-Time-command-duration-limits-Feature-Support-in%20Linux.pdf

Presented at Lund Linux Con 2022:
https://drive.google.com/file/d/1I6ChFc0h4JY9qZdO1bY5oCAdYCSZVqWw/view?usp=sharing

================
Changes since V6
================
-Rebased series on v6.4-rc1.
-Picked up Reviewed-by tags from Hannes (Thank you Hannes!)
-Picked up Reviewed-by tag from Christoph (Thank you Christoph!)
-Changed KernelVersion from 6.4 to 6.5 for new sysfs attributes.

For older change logs, see previous patch series versions:
https://lore.kernel.org/linux-scsi/20230406113252.41211-1-nks@flawful.org/
https://lore.kernel.org/linux-scsi/20230404182428.715140-1-nks@flawful.org/
https://lore.kernel.org/linux-scsi/20230309215516.3800571-1-niklas.cassel@wdc.com/
https://lore.kernel.org/linux-scsi/20230124190308.127318-1-niklas.cassel@wdc.com/
https://lore.kernel.org/linux-scsi/20230112140412.667308-1-niklas.cassel@wdc.com/
https://lore.kernel.org/linux-scsi/20221208105947.2399894-1-niklas.cassel@wdc.com/

Link: https://lore.kernel.org/r/20230511011356.227789-1-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

+1194 -146
+22
Documentation/ABI/testing/sysfs-block-device
··· 95 95 This file does not exist if the HBA driver does not implement 96 96 support for the SATA NCQ priority feature, regardless of the 97 97 device support for this feature. 98 + 99 + 100 + What: /sys/block/*/device/cdl_supported 101 + Date: May, 2023 102 + KernelVersion: v6.5 103 + Contact: linux-scsi@vger.kernel.org 104 + Description: 105 + (RO) Indicates if the device supports the command duration 106 + limits feature found in some ATA and SCSI devices. 107 + 108 + 109 + What: /sys/block/*/device/cdl_enable 110 + Date: May, 2023 111 + KernelVersion: v6.5 112 + Contact: linux-scsi@vger.kernel.org 113 + Description: 114 + (RW) For a device supporting the command duration limits 115 + feature, write to the file to turn on or off the feature. 116 + By default this feature is turned off. 117 + Writing "1" to this file enables the use of command duration 118 + limits for read and write commands in the kernel and turns on 119 + the feature on the device. Writing "0" disables the feature.
+4 -4
block/bfq-iosched.c
··· 5524 5524 bfqq->new_ioprio_class = task_nice_ioclass(tsk); 5525 5525 break; 5526 5526 case IOPRIO_CLASS_RT: 5527 - bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); 5527 + bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); 5528 5528 bfqq->new_ioprio_class = IOPRIO_CLASS_RT; 5529 5529 break; 5530 5530 case IOPRIO_CLASS_BE: 5531 - bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); 5531 + bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); 5532 5532 bfqq->new_ioprio_class = IOPRIO_CLASS_BE; 5533 5533 break; 5534 5534 case IOPRIO_CLASS_IDLE: 5535 5535 bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE; 5536 - bfqq->new_ioprio = 7; 5536 + bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1; 5537 5537 break; 5538 5538 } 5539 5539 ··· 5830 5830 struct bfq_io_cq *bic, 5831 5831 bool respawn) 5832 5832 { 5833 - const int ioprio = IOPRIO_PRIO_DATA(bic->ioprio); 5833 + const int ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); 5834 5834 const int ioprio_class = IOPRIO_PRIO_CLASS(bic->ioprio); 5835 5835 struct bfq_queue **async_bfqq = NULL; 5836 5836 struct bfq_queue *bfqq;
+3
block/blk-core.c
··· 170 170 [BLK_STS_ZONE_OPEN_RESOURCE] = { -ETOOMANYREFS, "open zones exceeded" }, 171 171 [BLK_STS_ZONE_ACTIVE_RESOURCE] = { -EOVERFLOW, "active zones exceeded" }, 172 172 173 + /* Command duration limit device-side timeout */ 174 + [BLK_STS_DURATION_LIMIT] = { -ETIME, "duration limit exceeded" }, 175 + 173 176 /* everything else not covered above: */ 174 177 [BLK_STS_IOERR] = { -EIO, "I/O" }, 175 178 };
+3 -3
block/ioprio.c
··· 33 33 int ioprio_check_cap(int ioprio) 34 34 { 35 35 int class = IOPRIO_PRIO_CLASS(ioprio); 36 - int data = IOPRIO_PRIO_DATA(ioprio); 36 + int level = IOPRIO_PRIO_LEVEL(ioprio); 37 37 38 38 switch (class) { 39 39 case IOPRIO_CLASS_RT: ··· 49 49 fallthrough; 50 50 /* rt has prio field too */ 51 51 case IOPRIO_CLASS_BE: 52 - if (data >= IOPRIO_NR_LEVELS || data < 0) 52 + if (level >= IOPRIO_NR_LEVELS) 53 53 return -EINVAL; 54 54 break; 55 55 case IOPRIO_CLASS_IDLE: 56 56 break; 57 57 case IOPRIO_CLASS_NONE: 58 - if (data) 58 + if (level) 59 59 return -EINVAL; 60 60 break; 61 61 default:
+200 -4
drivers/ata/libata-core.c
··· 665 665 return block; 666 666 } 667 667 668 + /* 669 + * Set a taskfile command duration limit index. 670 + */ 671 + static inline void ata_set_tf_cdl(struct ata_queued_cmd *qc, int cdl) 672 + { 673 + struct ata_taskfile *tf = &qc->tf; 674 + 675 + if (tf->protocol == ATA_PROT_NCQ) 676 + tf->auxiliary |= cdl; 677 + else 678 + tf->feature |= cdl; 679 + 680 + /* 681 + * Mark this command as having a CDL and request the result 682 + * task file so that we can inspect the sense data available 683 + * bit on completion. 684 + */ 685 + qc->flags |= ATA_QCFLAG_HAS_CDL | ATA_QCFLAG_RESULT_TF; 686 + } 687 + 668 688 /** 669 689 * ata_build_rw_tf - Build ATA taskfile for given read/write request 670 690 * @qc: Metadata associated with the taskfile to build 671 691 * @block: Block address 672 692 * @n_block: Number of blocks 673 693 * @tf_flags: RW/FUA etc... 694 + * @cdl: Command duration limit index 674 695 * @class: IO priority class 675 696 * 676 697 * LOCKING: ··· 706 685 * -EINVAL if the request is invalid. 707 686 */ 708 687 int ata_build_rw_tf(struct ata_queued_cmd *qc, u64 block, u32 n_block, 709 - unsigned int tf_flags, int class) 688 + unsigned int tf_flags, int cdl, int class) 710 689 { 711 690 struct ata_taskfile *tf = &qc->tf; 712 691 struct ata_device *dev = qc->dev; ··· 745 724 if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED && 746 725 class == IOPRIO_CLASS_RT) 747 726 tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO; 727 + 728 + if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) 729 + ata_set_tf_cdl(qc, cdl); 730 + 748 731 } else if (dev->flags & ATA_DFLAG_LBA) { 749 732 tf->flags |= ATA_TFLAG_LBA; 750 733 751 - /* We need LBA48 for FUA writes */ 752 - if (!(tf->flags & ATA_TFLAG_FUA) && lba_28_ok(block, n_block)) { 734 + if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) 735 + ata_set_tf_cdl(qc, cdl); 736 + 737 + /* Both FUA writes and a CDL index require 48-bit commands */ 738 + if (!(tf->flags & ATA_TFLAG_FUA) && 739 + !(qc->flags & ATA_QCFLAG_HAS_CDL) && 740 + lba_28_ok(block, n_block)) { 753 741 /* use LBA28 */ 754 742 tf->device |= (block >> 24) & 0xf; 755 743 } else if (lba_48_ok(block, n_block)) { ··· 2397 2367 dev->flags |= ATA_DFLAG_TRUSTED; 2398 2368 } 2399 2369 2370 + static void ata_dev_config_cdl(struct ata_device *dev) 2371 + { 2372 + struct ata_port *ap = dev->link->ap; 2373 + unsigned int err_mask; 2374 + bool cdl_enabled; 2375 + u64 val; 2376 + 2377 + if (ata_id_major_version(dev->id) < 12) 2378 + goto not_supported; 2379 + 2380 + if (!ata_log_supported(dev, ATA_LOG_IDENTIFY_DEVICE) || 2381 + !ata_identify_page_supported(dev, ATA_LOG_SUPPORTED_CAPABILITIES) || 2382 + !ata_identify_page_supported(dev, ATA_LOG_CURRENT_SETTINGS)) 2383 + goto not_supported; 2384 + 2385 + err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 2386 + ATA_LOG_SUPPORTED_CAPABILITIES, 2387 + ap->sector_buf, 1); 2388 + if (err_mask) 2389 + goto not_supported; 2390 + 2391 + /* Check Command Duration Limit Supported bits */ 2392 + val = get_unaligned_le64(&ap->sector_buf[168]); 2393 + if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(0))) 2394 + goto not_supported; 2395 + 2396 + /* Warn the user if command duration guideline is not supported */ 2397 + if (!(val & BIT_ULL(1))) 2398 + ata_dev_warn(dev, 2399 + "Command duration guideline is not supported\n"); 2400 + 2401 + /* 2402 + * We must have support for the sense data for successful NCQ commands 2403 + * log indicated by the successful NCQ command sense data supported bit. 2404 + */ 2405 + val = get_unaligned_le64(&ap->sector_buf[8]); 2406 + if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(47))) { 2407 + ata_dev_warn(dev, 2408 + "CDL supported but Successful NCQ Command Sense Data is not supported\n"); 2409 + goto not_supported; 2410 + } 2411 + 2412 + /* Without NCQ autosense, the successful NCQ commands log is useless. */ 2413 + if (!ata_id_has_ncq_autosense(dev->id)) { 2414 + ata_dev_warn(dev, 2415 + "CDL supported but NCQ autosense is not supported\n"); 2416 + goto not_supported; 2417 + } 2418 + 2419 + /* 2420 + * If CDL is marked as enabled, make sure the feature is enabled too. 2421 + * Conversely, if CDL is disabled, make sure the feature is turned off. 2422 + */ 2423 + err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 2424 + ATA_LOG_CURRENT_SETTINGS, 2425 + ap->sector_buf, 1); 2426 + if (err_mask) 2427 + goto not_supported; 2428 + 2429 + val = get_unaligned_le64(&ap->sector_buf[8]); 2430 + cdl_enabled = val & BIT_ULL(63) && val & BIT_ULL(21); 2431 + if (dev->flags & ATA_DFLAG_CDL_ENABLED) { 2432 + if (!cdl_enabled) { 2433 + /* Enable CDL on the device */ 2434 + err_mask = ata_dev_set_feature(dev, SETFEATURES_CDL, 1); 2435 + if (err_mask) { 2436 + ata_dev_err(dev, 2437 + "Enable CDL feature failed\n"); 2438 + goto not_supported; 2439 + } 2440 + } 2441 + } else { 2442 + if (cdl_enabled) { 2443 + /* Disable CDL on the device */ 2444 + err_mask = ata_dev_set_feature(dev, SETFEATURES_CDL, 0); 2445 + if (err_mask) { 2446 + ata_dev_err(dev, 2447 + "Disable CDL feature failed\n"); 2448 + goto not_supported; 2449 + } 2450 + } 2451 + } 2452 + 2453 + /* 2454 + * While CDL itself has to be enabled using sysfs, CDL requires that 2455 + * sense data for successful NCQ commands is enabled to work properly. 2456 + * Just like ata_dev_config_sense_reporting(), enable it unconditionally 2457 + * if supported. 2458 + */ 2459 + if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(18))) { 2460 + err_mask = ata_dev_set_feature(dev, 2461 + SETFEATURE_SENSE_DATA_SUCC_NCQ, 0x1); 2462 + if (err_mask) { 2463 + ata_dev_warn(dev, 2464 + "failed to enable Sense Data for successful NCQ commands, Emask 0x%x\n", 2465 + err_mask); 2466 + goto not_supported; 2467 + } 2468 + } 2469 + 2470 + /* 2471 + * Allocate a buffer to handle reading the sense data for successful 2472 + * NCQ Commands log page for commands using a CDL with one of the limit 2473 + * policy set to 0xD (successful completion with sense data available 2474 + * bit set). 2475 + */ 2476 + if (!ap->ncq_sense_buf) { 2477 + ap->ncq_sense_buf = kmalloc(ATA_LOG_SENSE_NCQ_SIZE, GFP_KERNEL); 2478 + if (!ap->ncq_sense_buf) 2479 + goto not_supported; 2480 + } 2481 + 2482 + /* 2483 + * Command duration limits is supported: cache the CDL log page 18h 2484 + * (command duration descriptors). 2485 + */ 2486 + err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, ap->sector_buf, 1); 2487 + if (err_mask) { 2488 + ata_dev_warn(dev, "Read Command Duration Limits log failed\n"); 2489 + goto not_supported; 2490 + } 2491 + 2492 + memcpy(dev->cdl, ap->sector_buf, ATA_LOG_CDL_SIZE); 2493 + dev->flags |= ATA_DFLAG_CDL; 2494 + 2495 + return; 2496 + 2497 + not_supported: 2498 + dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); 2499 + kfree(ap->ncq_sense_buf); 2500 + ap->ncq_sense_buf = NULL; 2501 + } 2502 + 2400 2503 static int ata_dev_config_lba(struct ata_device *dev) 2401 2504 { 2402 2505 const u16 *id = dev->id; ··· 2697 2534 return; 2698 2535 2699 2536 ata_dev_info(dev, 2700 - "Features:%s%s%s%s%s%s%s\n", 2537 + "Features:%s%s%s%s%s%s%s%s\n", 2701 2538 dev->flags & ATA_DFLAG_FUA ? " FUA" : "", 2702 2539 dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", 2703 2540 dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", 2704 2541 dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", 2705 2542 dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", 2706 2543 dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "", 2544 + dev->flags & ATA_DFLAG_CDL ? " CDL" : "", 2707 2545 dev->cpr_log ? " CPR" : ""); 2708 2546 } 2709 2547 ··· 2866 2702 ata_dev_config_zac(dev); 2867 2703 ata_dev_config_trusted(dev); 2868 2704 ata_dev_config_cpr(dev); 2705 + ata_dev_config_cdl(dev); 2869 2706 dev->cdb_len = 32; 2870 2707 2871 2708 if (print_info) ··· 4931 4766 fill_result_tf(qc); 4932 4767 4933 4768 trace_ata_qc_complete_done(qc); 4769 + 4770 + /* 4771 + * For CDL commands that completed without an error, check if 4772 + * we have sense data (ATA_SENSE is set). If we do, then the 4773 + * command may have been aborted by the device due to a limit 4774 + * timeout using the policy 0xD. For these commands, invoke EH 4775 + * to get the command sense data. 4776 + */ 4777 + if (qc->result_tf.status & ATA_SENSE && 4778 + ((ata_is_ncq(qc->tf.protocol) && 4779 + dev->flags & ATA_DFLAG_CDL_ENABLED) || 4780 + (!(ata_is_ncq(qc->tf.protocol) && 4781 + ata_id_sense_reporting_enabled(dev->id))))) { 4782 + /* 4783 + * Tell SCSI EH to not overwrite scmd->result even if 4784 + * this command is finished with result SAM_STAT_GOOD. 4785 + */ 4786 + qc->scsicmd->flags |= SCMD_FORCE_EH_SUCCESS; 4787 + qc->flags |= ATA_QCFLAG_EH_SUCCESS_CMD; 4788 + ehi->dev_action[dev->devno] |= ATA_EH_GET_SUCCESS_SENSE; 4789 + 4790 + /* 4791 + * set pending so that ata_qc_schedule_eh() does not 4792 + * trigger fast drain, and freeze the port. 4793 + */ 4794 + ap->pflags |= ATA_PFLAG_EH_PENDING; 4795 + ata_qc_schedule_eh(qc); 4796 + return; 4797 + } 4798 + 4934 4799 /* Some commands need post-processing after successful 4935 4800 * completion. 4936 4801 */ ··· 5593 5398 5594 5399 kfree(ap->pmp_link); 5595 5400 kfree(ap->slave_link); 5401 + kfree(ap->ncq_sense_buf); 5596 5402 kfree(ap); 5597 5403 host->ports[i] = NULL; 5598 5404 }
+120 -10
drivers/ata/libata-eh.c
··· 1401 1401 * 1402 1402 * LOCKING: 1403 1403 * Kernel thread context (may sleep). 1404 + * 1405 + * RETURNS: 1406 + * true if sense data could be fetched, false otherwise. 1404 1407 */ 1405 - static void ata_eh_request_sense(struct ata_queued_cmd *qc) 1408 + static bool ata_eh_request_sense(struct ata_queued_cmd *qc) 1406 1409 { 1407 1410 struct scsi_cmnd *cmd = qc->scsicmd; 1408 1411 struct ata_device *dev = qc->dev; ··· 1414 1411 1415 1412 if (ata_port_is_frozen(qc->ap)) { 1416 1413 ata_dev_warn(dev, "sense data available but port frozen\n"); 1417 - return; 1414 + return false; 1418 1415 } 1419 - 1420 - if (!cmd || qc->flags & ATA_QCFLAG_SENSE_VALID) 1421 - return; 1422 1416 1423 1417 if (!ata_id_sense_reporting_enabled(dev->id)) { 1424 1418 ata_dev_warn(qc->dev, "sense data reporting disabled\n"); 1425 - return; 1419 + return false; 1426 1420 } 1427 1421 1428 1422 ata_tf_init(dev, &tf); ··· 1432 1432 /* Ignore err_mask; ATA_ERR might be set */ 1433 1433 if (tf.status & ATA_SENSE) { 1434 1434 if (ata_scsi_sense_is_valid(tf.lbah, tf.lbam, tf.lbal)) { 1435 - ata_scsi_set_sense(dev, cmd, tf.lbah, tf.lbam, tf.lbal); 1435 + /* Set sense without also setting scsicmd->result */ 1436 + scsi_build_sense_buffer(dev->flags & ATA_DFLAG_D_SENSE, 1437 + cmd->sense_buffer, tf.lbah, 1438 + tf.lbam, tf.lbal); 1436 1439 qc->flags |= ATA_QCFLAG_SENSE_VALID; 1440 + return true; 1437 1441 } 1438 1442 } else { 1439 1443 ata_dev_warn(dev, "request sense failed stat %02x emask %x\n", 1440 1444 tf.status, err_mask); 1441 1445 } 1446 + 1447 + return false; 1442 1448 } 1443 1449 1444 1450 /** ··· 1594 1588 * was not included in the NCQ command error log 1595 1589 * (i.e. NCQ autosense is not supported by the device). 1596 1590 */ 1597 - if (!(qc->flags & ATA_QCFLAG_SENSE_VALID) && (stat & ATA_SENSE)) 1598 - ata_eh_request_sense(qc); 1591 + if (!(qc->flags & ATA_QCFLAG_SENSE_VALID) && 1592 + (stat & ATA_SENSE) && ata_eh_request_sense(qc)) 1593 + set_status_byte(qc->scsicmd, SAM_STAT_CHECK_CONDITION); 1599 1594 if (err & ATA_ICRC) 1600 1595 qc->err_mask |= AC_ERR_ATA_BUS; 1601 1596 if (err & (ATA_UNC | ATA_AMNF)) ··· 1917 1910 return qc->flags & ATA_QCFLAG_QUIET; 1918 1911 } 1919 1912 1913 + static int ata_eh_read_sense_success_non_ncq(struct ata_link *link) 1914 + { 1915 + struct ata_port *ap = link->ap; 1916 + struct ata_queued_cmd *qc; 1917 + 1918 + qc = __ata_qc_from_tag(ap, link->active_tag); 1919 + if (!qc) 1920 + return -EIO; 1921 + 1922 + if (!(qc->flags & ATA_QCFLAG_EH) || 1923 + !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || 1924 + qc->err_mask) 1925 + return -EIO; 1926 + 1927 + if (!ata_eh_request_sense(qc)) 1928 + return -EIO; 1929 + 1930 + /* 1931 + * If we have sense data, call scsi_check_sense() in order to set the 1932 + * correct SCSI ML byte (if any). No point in checking the return value, 1933 + * since the command has already completed successfully. 1934 + */ 1935 + scsi_check_sense(qc->scsicmd); 1936 + 1937 + return 0; 1938 + } 1939 + 1940 + static void ata_eh_get_success_sense(struct ata_link *link) 1941 + { 1942 + struct ata_eh_context *ehc = &link->eh_context; 1943 + struct ata_device *dev = link->device; 1944 + struct ata_port *ap = link->ap; 1945 + struct ata_queued_cmd *qc; 1946 + int tag, ret = 0; 1947 + 1948 + if (!(ehc->i.dev_action[dev->devno] & ATA_EH_GET_SUCCESS_SENSE)) 1949 + return; 1950 + 1951 + /* if frozen, we can't do much */ 1952 + if (ata_port_is_frozen(ap)) { 1953 + ata_dev_warn(dev, 1954 + "successful sense data available but port frozen\n"); 1955 + goto out; 1956 + } 1957 + 1958 + /* 1959 + * If the link has sactive set, then we have outstanding NCQ commands 1960 + * and have to read the Successful NCQ Commands log to get the sense 1961 + * data. Otherwise, we are dealing with a non-NCQ command and use 1962 + * request sense ext command to retrieve the sense data. 1963 + */ 1964 + if (link->sactive) 1965 + ret = ata_eh_read_sense_success_ncq_log(link); 1966 + else 1967 + ret = ata_eh_read_sense_success_non_ncq(link); 1968 + if (ret) 1969 + goto out; 1970 + 1971 + ata_eh_done(link, dev, ATA_EH_GET_SUCCESS_SENSE); 1972 + return; 1973 + 1974 + out: 1975 + /* 1976 + * If we failed to get sense data for a successful command that ought to 1977 + * have sense data, we cannot simply return BLK_STS_OK to user space. 1978 + * This is because we can't know if the sense data that we couldn't get 1979 + * was actually "DATA CURRENTLY UNAVAILABLE". Reporting such a command 1980 + * as success to user space would result in a silent data corruption. 1981 + * Thus, add a bogus ABORTED_COMMAND sense data to such commands, such 1982 + * that SCSI will report these commands as BLK_STS_IOERR to user space. 1983 + */ 1984 + ata_qc_for_each_raw(ap, qc, tag) { 1985 + if (!(qc->flags & ATA_QCFLAG_EH) || 1986 + !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || 1987 + qc->err_mask || 1988 + ata_dev_phys_link(qc->dev) != link) 1989 + continue; 1990 + 1991 + /* We managed to get sense for this success command, skip. */ 1992 + if (qc->flags & ATA_QCFLAG_SENSE_VALID) 1993 + continue; 1994 + 1995 + /* This success command did not have any sense data, skip. */ 1996 + if (!(qc->result_tf.status & ATA_SENSE)) 1997 + continue; 1998 + 1999 + /* This success command had sense data, but we failed to get. */ 2000 + ata_scsi_set_sense(dev, qc->scsicmd, ABORTED_COMMAND, 0, 0); 2001 + qc->flags |= ATA_QCFLAG_SENSE_VALID; 2002 + } 2003 + ata_eh_done(link, dev, ATA_EH_GET_SUCCESS_SENSE); 2004 + } 2005 + 1920 2006 /** 1921 2007 * ata_eh_link_autopsy - analyze error and determine recovery action 1922 2008 * @link: host link to perform autopsy on ··· 2050 1950 /* analyze NCQ failure */ 2051 1951 ata_eh_analyze_ncq_error(link); 2052 1952 1953 + /* 1954 + * Check if this was a successful command that simply needs sense data. 1955 + * Since the sense data is not part of the completion, we need to fetch 1956 + * it using an additional command. Since this can't be done from irq 1957 + * context, the sense data for successful commands are fetched by EH. 1958 + */ 1959 + ata_eh_get_success_sense(link); 1960 + 2053 1961 /* any real error trumps AC_ERR_OTHER */ 2054 1962 if (ehc->i.err_mask & ~AC_ERR_OTHER) 2055 1963 ehc->i.err_mask &= ~AC_ERR_OTHER; ··· 2067 1959 ata_qc_for_each_raw(ap, qc, tag) { 2068 1960 if (!(qc->flags & ATA_QCFLAG_EH) || 2069 1961 qc->flags & ATA_QCFLAG_RETRY || 1962 + qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD || 2070 1963 ata_dev_phys_link(qc->dev) != link) 2071 1964 continue; 2072 1965 ··· 3927 3818 else 3928 3819 ata_eh_qc_complete(qc); 3929 3820 } else { 3930 - if (qc->flags & ATA_QCFLAG_SENSE_VALID) { 3821 + if (qc->flags & ATA_QCFLAG_SENSE_VALID || 3822 + qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) { 3931 3823 ata_eh_qc_complete(qc); 3932 3824 } else { 3933 3825 /* feed zero TF to sense generation */
+101 -2
drivers/ata/libata-sata.c
··· 11 11 #include <linux/module.h> 12 12 #include <scsi/scsi_cmnd.h> 13 13 #include <scsi/scsi_device.h> 14 + #include <scsi/scsi_eh.h> 14 15 #include <linux/libata.h> 16 + #include <asm/unaligned.h> 15 17 16 18 #include "libata.h" 17 19 #include "libata-transport.h" ··· 909 907 goto unlock; 910 908 } 911 909 912 - if (input) 910 + if (input) { 911 + if (dev->flags & ATA_DFLAG_CDL_ENABLED) { 912 + ata_dev_err(dev, 913 + "CDL must be disabled to enable NCQ priority\n"); 914 + rc = -EINVAL; 915 + goto unlock; 916 + } 913 917 dev->flags |= ATA_DFLAG_NCQ_PRIO_ENABLED; 914 - else 918 + } else { 915 919 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLED; 920 + } 916 921 917 922 unlock: 918 923 spin_unlock_irq(ap->lock); ··· 1411 1402 } 1412 1403 1413 1404 /** 1405 + * ata_eh_read_sense_success_ncq_log - Read the sense data for successful 1406 + * NCQ commands log 1407 + * @link: ATA link to get sense data for 1408 + * 1409 + * Read the sense data for successful NCQ commands log page to obtain 1410 + * sense data for all NCQ commands that completed successfully with 1411 + * the sense data available bit set. 1412 + * 1413 + * LOCKING: 1414 + * Kernel thread context (may sleep). 1415 + * 1416 + * RETURNS: 1417 + * 0 on success, -errno otherwise. 1418 + */ 1419 + int ata_eh_read_sense_success_ncq_log(struct ata_link *link) 1420 + { 1421 + struct ata_device *dev = link->device; 1422 + struct ata_port *ap = dev->link->ap; 1423 + u8 *buf = ap->ncq_sense_buf; 1424 + struct ata_queued_cmd *qc; 1425 + unsigned int err_mask, tag; 1426 + u8 *sense, sk = 0, asc = 0, ascq = 0; 1427 + u64 sense_valid, val; 1428 + int ret = 0; 1429 + 1430 + err_mask = ata_read_log_page(dev, ATA_LOG_SENSE_NCQ, 0, buf, 2); 1431 + if (err_mask) { 1432 + ata_dev_err(dev, 1433 + "Failed to read Sense Data for Successful NCQ Commands log\n"); 1434 + return -EIO; 1435 + } 1436 + 1437 + /* Check the log header */ 1438 + val = get_unaligned_le64(&buf[0]); 1439 + if ((val & 0xffff) != 1 || ((val >> 16) & 0xff) != 0x0f) { 1440 + ata_dev_err(dev, 1441 + "Invalid Sense Data for Successful NCQ Commands log\n"); 1442 + return -EIO; 1443 + } 1444 + 1445 + sense_valid = (u64)buf[8] | ((u64)buf[9] << 8) | 1446 + ((u64)buf[10] << 16) | ((u64)buf[11] << 24); 1447 + 1448 + ata_qc_for_each_raw(ap, qc, tag) { 1449 + if (!(qc->flags & ATA_QCFLAG_EH) || 1450 + !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || 1451 + qc->err_mask || 1452 + ata_dev_phys_link(qc->dev) != link) 1453 + continue; 1454 + 1455 + /* 1456 + * If the command does not have any sense data, clear ATA_SENSE. 1457 + * Keep ATA_QCFLAG_EH_SUCCESS_CMD so that command is finished. 1458 + */ 1459 + if (!(sense_valid & (1ULL << tag))) { 1460 + qc->result_tf.status &= ~ATA_SENSE; 1461 + continue; 1462 + } 1463 + 1464 + sense = &buf[32 + 24 * tag]; 1465 + sk = sense[0]; 1466 + asc = sense[1]; 1467 + ascq = sense[2]; 1468 + 1469 + if (!ata_scsi_sense_is_valid(sk, asc, ascq)) { 1470 + ret = -EIO; 1471 + continue; 1472 + } 1473 + 1474 + /* Set sense without also setting scsicmd->result */ 1475 + scsi_build_sense_buffer(dev->flags & ATA_DFLAG_D_SENSE, 1476 + qc->scsicmd->sense_buffer, sk, 1477 + asc, ascq); 1478 + qc->flags |= ATA_QCFLAG_SENSE_VALID; 1479 + 1480 + /* 1481 + * If we have sense data, call scsi_check_sense() in order to 1482 + * set the correct SCSI ML byte (if any). No point in checking 1483 + * the return value, since the command has already completed 1484 + * successfully. 1485 + */ 1486 + scsi_check_sense(qc->scsicmd); 1487 + } 1488 + 1489 + return ret; 1490 + } 1491 + EXPORT_SYMBOL_GPL(ata_eh_read_sense_success_ncq_log); 1492 + 1493 + /** 1414 1494 * ata_eh_analyze_ncq_error - analyze NCQ error 1415 1495 * @link: ATA link to analyze NCQ error for 1416 1496 * ··· 1579 1481 1580 1482 ata_qc_for_each_raw(ap, qc, tag) { 1581 1483 if (!(qc->flags & ATA_QCFLAG_EH) || 1484 + qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD || 1582 1485 ata_dev_phys_link(qc->dev) != link) 1583 1486 continue; 1584 1487
+317 -65
drivers/ata/libata-scsi.c
··· 37 37 #include "libata.h" 38 38 #include "libata-transport.h" 39 39 40 - #define ATA_SCSI_RBUF_SIZE 576 40 + #define ATA_SCSI_RBUF_SIZE 2048 41 41 42 42 static DEFINE_SPINLOCK(ata_scsi_rbuf_lock); 43 43 static u8 ata_scsi_rbuf[ATA_SCSI_RBUF_SIZE]; ··· 47 47 static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap, 48 48 const struct scsi_device *scsidev); 49 49 50 - #define RW_RECOVERY_MPAGE 0x1 51 - #define RW_RECOVERY_MPAGE_LEN 12 52 - #define CACHE_MPAGE 0x8 53 - #define CACHE_MPAGE_LEN 20 54 - #define CONTROL_MPAGE 0xa 55 - #define CONTROL_MPAGE_LEN 12 56 - #define ALL_MPAGES 0x3f 57 - #define ALL_SUB_MPAGES 0xff 58 - 50 + #define RW_RECOVERY_MPAGE 0x1 51 + #define RW_RECOVERY_MPAGE_LEN 12 52 + #define CACHE_MPAGE 0x8 53 + #define CACHE_MPAGE_LEN 20 54 + #define CONTROL_MPAGE 0xa 55 + #define CONTROL_MPAGE_LEN 12 56 + #define ALL_MPAGES 0x3f 57 + #define ALL_SUB_MPAGES 0xff 58 + #define CDL_T2A_SUB_MPAGE 0x07 59 + #define CDL_T2B_SUB_MPAGE 0x08 60 + #define CDL_T2_SUB_MPAGE_LEN 232 61 + #define ATA_FEATURE_SUB_MPAGE 0xf2 62 + #define ATA_FEATURE_SUB_MPAGE_LEN 16 59 63 60 64 static const u8 def_rw_recovery_mpage[RW_RECOVERY_MPAGE_LEN] = { 61 65 RW_RECOVERY_MPAGE, ··· 213 209 { 214 210 bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); 215 211 216 - if (!cmd) 217 - return; 218 - 219 212 scsi_build_sense(cmd, d_sense, sk, asc, ascq); 220 213 } 221 214 ··· 221 220 const struct ata_taskfile *tf) 222 221 { 223 222 u64 information; 224 - 225 - if (!cmd) 226 - return; 227 223 228 224 information = ata_tf_read_block(tf, dev); 229 225 if (information == U64_MAX) ··· 1381 1383 } 1382 1384 1383 1385 /** 1386 + * scsi_dld - Get duration limit descriptor index 1387 + * @cdb: SCSI command to translate 1388 + * 1389 + * Returns the dld bits indicating the index of a command duration limit 1390 + * descriptor. 1391 + */ 1392 + static inline int scsi_dld(const u8 *cdb) 1393 + { 1394 + return ((cdb[1] & 0x01) << 2) | ((cdb[14] >> 6) & 0x03); 1395 + } 1396 + 1397 + /** 1384 1398 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one 1385 1399 * @qc: Storage for translated ATA taskfile 1386 1400 * ··· 1560 1550 struct request *rq = scsi_cmd_to_rq(scmd); 1561 1551 int class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); 1562 1552 unsigned int tf_flags = 0; 1553 + int dld = 0; 1563 1554 u64 block; 1564 1555 u32 n_block; 1565 1556 int rc; ··· 1611 1600 goto invalid_fld; 1612 1601 } 1613 1602 scsi_16_lba_len(cdb, &block, &n_block); 1603 + dld = scsi_dld(cdb); 1614 1604 if (cdb[1] & (1 << 3)) 1615 1605 tf_flags |= ATA_TFLAG_FUA; 1616 1606 if (!ata_check_nblocks(scmd, n_block)) ··· 1636 1624 qc->flags |= ATA_QCFLAG_IO; 1637 1625 qc->nbytes = n_block * scmd->device->sector_size; 1638 1626 1639 - rc = ata_build_rw_tf(qc, block, n_block, tf_flags, class); 1627 + rc = ata_build_rw_tf(qc, block, n_block, tf_flags, dld, class); 1640 1628 if (likely(rc == 0)) 1641 1629 return 0; 1642 1630 ··· 2215 2203 return sizeof(def_cache_mpage); 2216 2204 } 2217 2205 2206 + /* 2207 + * Simulate MODE SENSE control mode page, sub-page 0. 2208 + */ 2209 + static unsigned int ata_msense_control_spg0(struct ata_device *dev, u8 *buf, 2210 + bool changeable) 2211 + { 2212 + modecpy(buf, def_control_mpage, 2213 + sizeof(def_control_mpage), changeable); 2214 + if (changeable) { 2215 + /* ata_mselect_control() */ 2216 + buf[2] |= (1 << 2); 2217 + } else { 2218 + bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); 2219 + 2220 + /* descriptor format sense data */ 2221 + buf[2] |= (d_sense << 2); 2222 + } 2223 + 2224 + return sizeof(def_control_mpage); 2225 + } 2226 + 2227 + /* 2228 + * Translate an ATA duration limit in microseconds to a SCSI duration limit 2229 + * using the t2cdlunits 0xa (10ms). Since the SCSI duration limits are 2-bytes 2230 + * only, take care of overflows. 2231 + */ 2232 + static inline u16 ata_xlat_cdl_limit(u8 *buf) 2233 + { 2234 + u32 limit = get_unaligned_le32(buf); 2235 + 2236 + return min_t(u32, limit / 10000, 65535); 2237 + } 2238 + 2239 + /* 2240 + * Simulate MODE SENSE control mode page, sub-pages 07h and 08h 2241 + * (command duration limits T2A and T2B mode pages). 2242 + */ 2243 + static unsigned int ata_msense_control_spgt2(struct ata_device *dev, u8 *buf, 2244 + u8 spg) 2245 + { 2246 + u8 *b, *cdl = dev->cdl, *desc; 2247 + u32 policy; 2248 + int i; 2249 + 2250 + /* 2251 + * Fill the subpage. The first four bytes of the T2A/T2B mode pages 2252 + * are a header. The PAGE LENGTH field is the size of the page 2253 + * excluding the header. 2254 + */ 2255 + buf[0] = CONTROL_MPAGE; 2256 + buf[1] = spg; 2257 + put_unaligned_be16(CDL_T2_SUB_MPAGE_LEN - 4, &buf[2]); 2258 + if (spg == CDL_T2A_SUB_MPAGE) { 2259 + /* 2260 + * Read descriptors map to the T2A page: 2261 + * set perf_vs_duration_guidleine. 2262 + */ 2263 + buf[7] = (cdl[0] & 0x03) << 4; 2264 + desc = cdl + 64; 2265 + } else { 2266 + /* Write descriptors map to the T2B page */ 2267 + desc = cdl + 288; 2268 + } 2269 + 2270 + /* Fill the T2 page descriptors */ 2271 + b = &buf[8]; 2272 + policy = get_unaligned_le32(&cdl[0]); 2273 + for (i = 0; i < 7; i++, b += 32, desc += 32) { 2274 + /* t2cdlunits: fixed to 10ms */ 2275 + b[0] = 0x0a; 2276 + 2277 + /* Max inactive time and its policy */ 2278 + put_unaligned_be16(ata_xlat_cdl_limit(&desc[8]), &b[2]); 2279 + b[6] = ((policy >> 8) & 0x0f) << 4; 2280 + 2281 + /* Max active time and its policy */ 2282 + put_unaligned_be16(ata_xlat_cdl_limit(&desc[4]), &b[4]); 2283 + b[6] |= (policy >> 4) & 0x0f; 2284 + 2285 + /* Command duration guideline and its policy */ 2286 + put_unaligned_be16(ata_xlat_cdl_limit(&desc[16]), &b[10]); 2287 + b[14] = policy & 0x0f; 2288 + } 2289 + 2290 + return CDL_T2_SUB_MPAGE_LEN; 2291 + } 2292 + 2293 + /* 2294 + * Simulate MODE SENSE control mode page, sub-page f2h 2295 + * (ATA feature control mode page). 2296 + */ 2297 + static unsigned int ata_msense_control_ata_feature(struct ata_device *dev, 2298 + u8 *buf) 2299 + { 2300 + /* PS=0, SPF=1 */ 2301 + buf[0] = CONTROL_MPAGE | (1 << 6); 2302 + buf[1] = ATA_FEATURE_SUB_MPAGE; 2303 + 2304 + /* 2305 + * The first four bytes of ATA Feature Control mode page are a header. 2306 + * The PAGE LENGTH field is the size of the page excluding the header. 2307 + */ 2308 + put_unaligned_be16(ATA_FEATURE_SUB_MPAGE_LEN - 4, &buf[2]); 2309 + 2310 + if (dev->flags & ATA_DFLAG_CDL) 2311 + buf[4] = 0x02; /* Support T2A and T2B pages */ 2312 + else 2313 + buf[4] = 0; 2314 + 2315 + return ATA_FEATURE_SUB_MPAGE_LEN; 2316 + } 2317 + 2218 2318 /** 2219 2319 * ata_msense_control - Simulate MODE SENSE control mode page 2220 2320 * @dev: ATA device of interest 2221 2321 * @buf: output buffer 2322 + * @spg: sub-page code 2222 2323 * @changeable: whether changeable parameters are requested 2223 2324 * 2224 2325 * Generate a generic MODE SENSE control mode page. ··· 2340 2215 * None. 2341 2216 */ 2342 2217 static unsigned int ata_msense_control(struct ata_device *dev, u8 *buf, 2343 - bool changeable) 2218 + u8 spg, bool changeable) 2344 2219 { 2345 - modecpy(buf, def_control_mpage, sizeof(def_control_mpage), changeable); 2346 - if (changeable) { 2347 - buf[2] |= (1 << 2); /* ata_mselect_control() */ 2348 - } else { 2349 - bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); 2220 + unsigned int n; 2350 2221 2351 - buf[2] |= (d_sense << 2); /* descriptor format sense data */ 2222 + switch (spg) { 2223 + case 0: 2224 + return ata_msense_control_spg0(dev, buf, changeable); 2225 + case CDL_T2A_SUB_MPAGE: 2226 + case CDL_T2B_SUB_MPAGE: 2227 + return ata_msense_control_spgt2(dev, buf, spg); 2228 + case ATA_FEATURE_SUB_MPAGE: 2229 + return ata_msense_control_ata_feature(dev, buf); 2230 + case ALL_SUB_MPAGES: 2231 + n = ata_msense_control_spg0(dev, buf, changeable); 2232 + n += ata_msense_control_spgt2(dev, buf + n, CDL_T2A_SUB_MPAGE); 2233 + n += ata_msense_control_spgt2(dev, buf + n, CDL_T2A_SUB_MPAGE); 2234 + n += ata_msense_control_ata_feature(dev, buf + n); 2235 + return n; 2236 + default: 2237 + return 0; 2352 2238 } 2353 - return sizeof(def_control_mpage); 2354 2239 } 2355 2240 2356 2241 /** ··· 2433 2298 2434 2299 pg = scsicmd[2] & 0x3f; 2435 2300 spg = scsicmd[3]; 2301 + 2436 2302 /* 2437 - * No mode subpages supported (yet) but asking for _all_ 2438 - * subpages may be valid 2303 + * Supported subpages: all subpages and sub-pages 07h, 08h and f2h of 2304 + * the control page. 2439 2305 */ 2440 - if (spg && (spg != ALL_SUB_MPAGES)) { 2441 - fp = 3; 2442 - goto invalid_fld; 2306 + if (spg) { 2307 + switch (spg) { 2308 + case ALL_SUB_MPAGES: 2309 + break; 2310 + case CDL_T2A_SUB_MPAGE: 2311 + case CDL_T2B_SUB_MPAGE: 2312 + case ATA_FEATURE_SUB_MPAGE: 2313 + if (dev->flags & ATA_DFLAG_CDL && pg == CONTROL_MPAGE) 2314 + break; 2315 + fallthrough; 2316 + default: 2317 + fp = 3; 2318 + goto invalid_fld; 2319 + } 2443 2320 } 2444 2321 2445 2322 switch(pg) { ··· 2464 2317 break; 2465 2318 2466 2319 case CONTROL_MPAGE: 2467 - p += ata_msense_control(args->dev, p, page_control == 1); 2320 + p += ata_msense_control(args->dev, p, spg, page_control == 1); 2468 2321 break; 2469 2322 2470 2323 case ALL_MPAGES: 2471 2324 p += ata_msense_rw_recovery(p, page_control == 1); 2472 2325 p += ata_msense_caching(args->id, p, page_control == 1); 2473 - p += ata_msense_control(args->dev, p, page_control == 1); 2326 + p += ata_msense_control(args->dev, p, spg, page_control == 1); 2474 2327 break; 2475 2328 2476 2329 default: /* invalid page code */ ··· 2489 2342 memcpy(rbuf + 4, sat_blk_desc, sizeof(sat_blk_desc)); 2490 2343 } 2491 2344 } else { 2492 - unsigned int output_len = p - rbuf - 2; 2493 - 2494 - rbuf[0] = output_len >> 8; 2495 - rbuf[1] = output_len; 2345 + put_unaligned_be16(p - rbuf - 2, &rbuf[0]); 2496 2346 rbuf[3] |= dpofua; 2497 2347 if (ebd) { 2498 2348 rbuf[7] = sizeof(sat_blk_desc); ··· 3386 3242 { 3387 3243 struct ata_device *dev = args->dev; 3388 3244 u8 *cdb = args->cmd->cmnd; 3389 - u8 supported = 0; 3245 + u8 supported = 0, cdlp = 0, rwcdlp = 0; 3390 3246 unsigned int err = 0; 3391 3247 3392 3248 if (cdb[2] != 1 && cdb[2] != 3) { ··· 3413 3269 case MAINTENANCE_IN: 3414 3270 case READ_6: 3415 3271 case READ_10: 3416 - case READ_16: 3417 3272 case WRITE_6: 3418 3273 case WRITE_10: 3419 - case WRITE_16: 3420 3274 case ATA_12: 3421 3275 case ATA_16: 3422 3276 case VERIFY: ··· 3423 3281 case MODE_SELECT_10: 3424 3282 case START_STOP: 3425 3283 supported = 3; 3284 + break; 3285 + case READ_16: 3286 + supported = 3; 3287 + if (dev->flags & ATA_DFLAG_CDL) { 3288 + /* 3289 + * CDL read descriptors map to the T2A page, that is, 3290 + * rwcdlp = 0x01 and cdlp = 0x01 3291 + */ 3292 + rwcdlp = 0x01; 3293 + cdlp = 0x01 << 3; 3294 + } 3295 + break; 3296 + case WRITE_16: 3297 + supported = 3; 3298 + if (dev->flags & ATA_DFLAG_CDL) { 3299 + /* 3300 + * CDL write descriptors map to the T2B page, that is, 3301 + * rwcdlp = 0x01 and cdlp = 0x02 3302 + */ 3303 + rwcdlp = 0x01; 3304 + cdlp = 0x02 << 3; 3305 + } 3426 3306 break; 3427 3307 case ZBC_IN: 3428 3308 case ZBC_OUT: ··· 3461 3297 break; 3462 3298 } 3463 3299 out: 3464 - rbuf[1] = supported; /* supported */ 3300 + /* One command format */ 3301 + rbuf[0] = rwcdlp; 3302 + rbuf[1] = cdlp | supported; 3465 3303 return err; 3466 3304 } 3467 3305 ··· 3753 3587 return 0; 3754 3588 } 3755 3589 3756 - /** 3757 - * ata_mselect_control - Simulate MODE SELECT for control page 3758 - * @qc: Storage for translated ATA taskfile 3759 - * @buf: input buffer 3760 - * @len: number of valid bytes in the input buffer 3761 - * @fp: out parameter for the failed field on error 3762 - * 3763 - * Prepare a taskfile to modify caching information for the device. 3764 - * 3765 - * LOCKING: 3766 - * None. 3590 + /* 3591 + * Simulate MODE SELECT control mode page, sub-page 0. 3767 3592 */ 3768 - static int ata_mselect_control(struct ata_queued_cmd *qc, 3769 - const u8 *buf, int len, u16 *fp) 3593 + static int ata_mselect_control_spg0(struct ata_queued_cmd *qc, 3594 + const u8 *buf, int len, u16 *fp) 3770 3595 { 3771 3596 struct ata_device *dev = qc->dev; 3772 3597 u8 mpage[CONTROL_MPAGE_LEN]; ··· 3779 3622 /* 3780 3623 * Check that read-only bits are not modified. 3781 3624 */ 3782 - ata_msense_control(dev, mpage, false); 3625 + ata_msense_control_spg0(dev, mpage, false); 3783 3626 for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) { 3784 3627 if (i == 0) 3785 3628 continue; ··· 3793 3636 else 3794 3637 dev->flags &= ~ATA_DFLAG_D_SENSE; 3795 3638 return 0; 3639 + } 3640 + 3641 + /* 3642 + * Translate MODE SELECT control mode page, sub-pages f2h (ATA feature mode 3643 + * page) into a SET FEATURES command. 3644 + */ 3645 + static unsigned int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, 3646 + const u8 *buf, int len, 3647 + u16 *fp) 3648 + { 3649 + struct ata_device *dev = qc->dev; 3650 + struct ata_taskfile *tf = &qc->tf; 3651 + u8 cdl_action; 3652 + 3653 + /* 3654 + * The first four bytes of ATA Feature Control mode page are a header, 3655 + * so offsets in mpage are off by 4 compared to buf. Same for len. 3656 + */ 3657 + if (len != ATA_FEATURE_SUB_MPAGE_LEN - 4) { 3658 + *fp = min(len, ATA_FEATURE_SUB_MPAGE_LEN - 4); 3659 + return -EINVAL; 3660 + } 3661 + 3662 + /* Check cdl_ctrl */ 3663 + switch (buf[0] & 0x03) { 3664 + case 0: 3665 + /* Disable CDL */ 3666 + cdl_action = 0; 3667 + dev->flags &= ~ATA_DFLAG_CDL_ENABLED; 3668 + break; 3669 + case 0x02: 3670 + /* Enable CDL T2A/T2B: NCQ priority must be disabled */ 3671 + if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED) { 3672 + ata_dev_err(dev, 3673 + "NCQ priority must be disabled to enable CDL\n"); 3674 + return -EINVAL; 3675 + } 3676 + cdl_action = 1; 3677 + dev->flags |= ATA_DFLAG_CDL_ENABLED; 3678 + break; 3679 + default: 3680 + *fp = 0; 3681 + return -EINVAL; 3682 + } 3683 + 3684 + tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; 3685 + tf->protocol = ATA_PROT_NODATA; 3686 + tf->command = ATA_CMD_SET_FEATURES; 3687 + tf->feature = SETFEATURES_CDL; 3688 + tf->nsect = cdl_action; 3689 + 3690 + return 1; 3691 + } 3692 + 3693 + /** 3694 + * ata_mselect_control - Simulate MODE SELECT for control page 3695 + * @qc: Storage for translated ATA taskfile 3696 + * @buf: input buffer 3697 + * @len: number of valid bytes in the input buffer 3698 + * @fp: out parameter for the failed field on error 3699 + * 3700 + * Prepare a taskfile to modify caching information for the device. 3701 + * 3702 + * LOCKING: 3703 + * None. 3704 + */ 3705 + static int ata_mselect_control(struct ata_queued_cmd *qc, u8 spg, 3706 + const u8 *buf, int len, u16 *fp) 3707 + { 3708 + switch (spg) { 3709 + case 0: 3710 + return ata_mselect_control_spg0(qc, buf, len, fp); 3711 + case ATA_FEATURE_SUB_MPAGE: 3712 + return ata_mselect_control_ata_feature(qc, buf, len, fp); 3713 + default: 3714 + return -EINVAL; 3715 + } 3796 3716 } 3797 3717 3798 3718 /** ··· 3889 3655 const u8 *cdb = scmd->cmnd; 3890 3656 u8 pg, spg; 3891 3657 unsigned six_byte, pg_len, hdr_len, bd_len; 3892 - int len; 3658 + int len, ret; 3893 3659 u16 fp = (u16)-1; 3894 3660 u8 bp = 0xff; 3895 3661 u8 buffer[64]; ··· 3974 3740 } 3975 3741 3976 3742 /* 3977 - * No mode subpages supported (yet) but asking for _all_ 3978 - * subpages may be valid 3743 + * Supported subpages: all subpages and ATA feature sub-page f2h of 3744 + * the control page. 3979 3745 */ 3980 - if (spg && (spg != ALL_SUB_MPAGES)) { 3981 - fp = (p[0] & 0x40) ? 1 : 0; 3982 - fp += hdr_len + bd_len; 3983 - goto invalid_param; 3746 + if (spg) { 3747 + switch (spg) { 3748 + case ALL_SUB_MPAGES: 3749 + /* All subpages is not supported for the control page */ 3750 + if (pg == CONTROL_MPAGE) { 3751 + fp = (p[0] & 0x40) ? 1 : 0; 3752 + fp += hdr_len + bd_len; 3753 + goto invalid_param; 3754 + } 3755 + break; 3756 + case ATA_FEATURE_SUB_MPAGE: 3757 + if (qc->dev->flags & ATA_DFLAG_CDL && 3758 + pg == CONTROL_MPAGE) 3759 + break; 3760 + fallthrough; 3761 + default: 3762 + fp = (p[0] & 0x40) ? 1 : 0; 3763 + fp += hdr_len + bd_len; 3764 + goto invalid_param; 3765 + } 3984 3766 } 3985 3767 if (pg_len > len) 3986 3768 goto invalid_param_len; ··· 4009 3759 } 4010 3760 break; 4011 3761 case CONTROL_MPAGE: 4012 - if (ata_mselect_control(qc, p, pg_len, &fp) < 0) { 3762 + ret = ata_mselect_control(qc, spg, p, pg_len, &fp); 3763 + if (ret < 0) { 4013 3764 fp += hdr_len + bd_len; 4014 3765 goto invalid_param; 4015 - } else { 4016 - goto skip; /* No ATA command to send */ 4017 3766 } 3767 + if (!ret) 3768 + goto skip; /* No ATA command to send */ 4018 3769 break; 4019 - default: /* invalid page code */ 3770 + default: 3771 + /* Invalid page code */ 4020 3772 fp = bd_len + hdr_len; 4021 3773 goto invalid_param; 4022 3774 }
+1 -1
drivers/ata/libata.h
··· 45 45 extern u64 ata_tf_to_lba(const struct ata_taskfile *tf); 46 46 extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf); 47 47 extern int ata_build_rw_tf(struct ata_queued_cmd *qc, u64 block, u32 n_block, 48 - unsigned int tf_flags, int class); 48 + unsigned int tf_flags, int dld, int class); 49 49 extern u64 ata_tf_read_block(const struct ata_taskfile *tf, 50 50 struct ata_device *dev); 51 51 extern unsigned ata_exec_internal(struct ata_device *dev,
+161 -8
drivers/scsi/scsi.c
··· 504 504 } 505 505 506 506 /** 507 - * scsi_report_opcode - Find out if a given command opcode is supported 507 + * scsi_report_opcode - Find out if a given command is supported 508 508 * @sdev: scsi device to query 509 509 * @buffer: scratch buffer (must be at least 20 bytes long) 510 510 * @len: length of buffer 511 - * @opcode: opcode for command to look up 511 + * @opcode: opcode for the command to look up 512 + * @sa: service action for the command to look up 512 513 * 513 - * Uses the REPORT SUPPORTED OPERATION CODES to look up the given 514 - * opcode. Returns -EINVAL if RSOC fails, 0 if the command opcode is 515 - * unsupported and 1 if the device claims to support the command. 514 + * Uses the REPORT SUPPORTED OPERATION CODES to check support for the 515 + * command identified with @opcode and @sa. If the command does not 516 + * have a service action, @sa must be 0. Returns -EINVAL if RSOC fails, 517 + * 0 if the command is not supported and 1 if the device claims to 518 + * support the command. 516 519 */ 517 520 int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, 518 - unsigned int len, unsigned char opcode) 521 + unsigned int len, unsigned char opcode, 522 + unsigned short sa) 519 523 { 520 524 unsigned char cmd[16]; 521 525 struct scsi_sense_hdr sshdr; ··· 543 539 memset(cmd, 0, 16); 544 540 cmd[0] = MAINTENANCE_IN; 545 541 cmd[1] = MI_REPORT_SUPPORTED_OPERATION_CODES; 546 - cmd[2] = 1; /* One command format */ 547 - cmd[3] = opcode; 542 + if (!sa) { 543 + cmd[2] = 1; /* One command format */ 544 + cmd[3] = opcode; 545 + } else { 546 + cmd[2] = 3; /* One command format with service action */ 547 + cmd[3] = opcode; 548 + put_unaligned_be16(sa, &cmd[4]); 549 + } 548 550 put_unaligned_be32(request_len, &cmd[6]); 549 551 memset(buffer, 0, len); 550 552 ··· 569 559 return 0; 570 560 } 571 561 EXPORT_SYMBOL(scsi_report_opcode); 562 + 563 + #define SCSI_CDL_CHECK_BUF_LEN 64 564 + 565 + static bool scsi_cdl_check_cmd(struct scsi_device *sdev, u8 opcode, u16 sa, 566 + unsigned char *buf) 567 + { 568 + int ret; 569 + u8 cdlp; 570 + 571 + /* Check operation code */ 572 + ret = scsi_report_opcode(sdev, buf, SCSI_CDL_CHECK_BUF_LEN, opcode, sa); 573 + if (ret <= 0) 574 + return false; 575 + 576 + if ((buf[1] & 0x03) != 0x03) 577 + return false; 578 + 579 + /* See SPC-6, one command format of REPORT SUPPORTED OPERATION CODES */ 580 + cdlp = (buf[1] & 0x18) >> 3; 581 + if (buf[0] & 0x01) { 582 + /* rwcdlp == 1 */ 583 + switch (cdlp) { 584 + case 0x01: 585 + /* T2A page */ 586 + return true; 587 + case 0x02: 588 + /* T2B page */ 589 + return true; 590 + } 591 + } else { 592 + /* rwcdlp == 0 */ 593 + switch (cdlp) { 594 + case 0x01: 595 + /* A page */ 596 + return true; 597 + case 0x02: 598 + /* B page */ 599 + return true; 600 + } 601 + } 602 + 603 + return false; 604 + } 605 + 606 + /** 607 + * scsi_cdl_check - Check if a SCSI device supports Command Duration Limits 608 + * @sdev: The device to check 609 + */ 610 + void scsi_cdl_check(struct scsi_device *sdev) 611 + { 612 + bool cdl_supported; 613 + unsigned char *buf; 614 + 615 + buf = kmalloc(SCSI_CDL_CHECK_BUF_LEN, GFP_KERNEL); 616 + if (!buf) { 617 + sdev->cdl_supported = 0; 618 + return; 619 + } 620 + 621 + /* Check support for READ_16, WRITE_16, READ_32 and WRITE_32 commands */ 622 + cdl_supported = 623 + scsi_cdl_check_cmd(sdev, READ_16, 0, buf) || 624 + scsi_cdl_check_cmd(sdev, WRITE_16, 0, buf) || 625 + scsi_cdl_check_cmd(sdev, VARIABLE_LENGTH_CMD, READ_32, buf) || 626 + scsi_cdl_check_cmd(sdev, VARIABLE_LENGTH_CMD, WRITE_32, buf); 627 + if (cdl_supported) { 628 + /* 629 + * We have CDL support: force the use of READ16/WRITE16. 630 + * READ32 and WRITE32 will be used for devices that support 631 + * the T10_PI_TYPE2_PROTECTION protection type. 632 + */ 633 + sdev->use_16_for_rw = 1; 634 + sdev->use_10_for_rw = 0; 635 + 636 + sdev->cdl_supported = 1; 637 + } else { 638 + sdev->cdl_supported = 0; 639 + } 640 + 641 + kfree(buf); 642 + } 643 + 644 + /** 645 + * scsi_cdl_enable - Enable or disable a SCSI device supports for Command 646 + * Duration Limits 647 + * @sdev: The target device 648 + * @enable: the target state 649 + */ 650 + int scsi_cdl_enable(struct scsi_device *sdev, bool enable) 651 + { 652 + struct scsi_mode_data data; 653 + struct scsi_sense_hdr sshdr; 654 + struct scsi_vpd *vpd; 655 + bool is_ata = false; 656 + char buf[64]; 657 + int ret; 658 + 659 + if (!sdev->cdl_supported) 660 + return -EOPNOTSUPP; 661 + 662 + rcu_read_lock(); 663 + vpd = rcu_dereference(sdev->vpd_pg89); 664 + if (vpd) 665 + is_ata = true; 666 + rcu_read_unlock(); 667 + 668 + /* 669 + * For ATA devices, CDL needs to be enabled with a SET FEATURES command. 670 + */ 671 + if (is_ata) { 672 + char *buf_data; 673 + int len; 674 + 675 + ret = scsi_mode_sense(sdev, 0x08, 0x0a, 0xf2, buf, sizeof(buf), 676 + 5 * HZ, 3, &data, NULL); 677 + if (ret) 678 + return -EINVAL; 679 + 680 + /* Enable CDL using the ATA feature page */ 681 + len = min_t(size_t, sizeof(buf), 682 + data.length - data.header_length - 683 + data.block_descriptor_length); 684 + buf_data = buf + data.header_length + 685 + data.block_descriptor_length; 686 + if (enable) 687 + buf_data[4] = 0x02; 688 + else 689 + buf_data[4] = 0; 690 + 691 + ret = scsi_mode_select(sdev, 1, 0, buf_data, len, 5 * HZ, 3, 692 + &data, &sshdr); 693 + if (ret) { 694 + if (scsi_sense_valid(&sshdr)) 695 + scsi_print_sense_hdr(sdev, 696 + dev_name(&sdev->sdev_gendev), &sshdr); 697 + return ret; 698 + } 699 + } 700 + 701 + sdev->cdl_enable = enable; 702 + 703 + return 0; 704 + } 572 705 573 706 /** 574 707 * scsi_device_get - get an additional reference to a scsi_device
+47 -1
drivers/scsi/scsi_error.c
··· 536 536 */ 537 537 enum scsi_disposition scsi_check_sense(struct scsi_cmnd *scmd) 538 538 { 539 + struct request *req = scsi_cmd_to_rq(scmd); 539 540 struct scsi_device *sdev = scmd->device; 540 541 struct scsi_sense_hdr sshdr; 541 542 ··· 595 594 case ABORTED_COMMAND: 596 595 if (sshdr.asc == 0x10) /* DIF */ 597 596 return SUCCESS; 597 + 598 + /* 599 + * Check aborts due to command duration limit policy: 600 + * ABORTED COMMAND additional sense code with the 601 + * COMMAND TIMEOUT BEFORE PROCESSING or 602 + * COMMAND TIMEOUT DURING PROCESSING or 603 + * COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR RECOVERY 604 + * additional sense code qualifiers. 605 + */ 606 + if (sshdr.asc == 0x2e && 607 + sshdr.ascq >= 0x01 && sshdr.ascq <= 0x03) { 608 + set_scsi_ml_byte(scmd, SCSIML_STAT_DL_TIMEOUT); 609 + req->cmd_flags |= REQ_FAILFAST_DEV; 610 + req->rq_flags |= RQF_QUIET; 611 + return SUCCESS; 612 + } 598 613 599 614 if (sshdr.asc == 0x44 && sdev->sdev_bflags & BLIST_RETRY_ITF) 600 615 return ADD_TO_MLQUEUE; ··· 708 691 } 709 692 return SUCCESS; 710 693 694 + case COMPLETED: 695 + if (sshdr.asc == 0x55 && sshdr.ascq == 0x0a) { 696 + set_scsi_ml_byte(scmd, SCSIML_STAT_DL_TIMEOUT); 697 + req->cmd_flags |= REQ_FAILFAST_DEV; 698 + req->rq_flags |= RQF_QUIET; 699 + } 700 + return SUCCESS; 701 + 711 702 default: 712 703 return SUCCESS; 713 704 } ··· 810 785 switch (get_status_byte(scmd)) { 811 786 case SAM_STAT_GOOD: 812 787 scsi_handle_queue_ramp_up(scmd->device); 788 + if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) 789 + /* 790 + * If we have sense data, call scsi_check_sense() in 791 + * order to set the correct SCSI ML byte (if any). 792 + * No point in checking the return value, since the 793 + * command has already completed successfully. 794 + */ 795 + scsi_check_sense(scmd); 813 796 fallthrough; 814 797 case SAM_STAT_COMMAND_TERMINATED: 815 798 return SUCCESS; ··· 1840 1807 return !!(req->cmd_flags & REQ_FAILFAST_DRIVER); 1841 1808 } 1842 1809 1810 + /* Never retry commands aborted due to a duration limit timeout */ 1811 + if (scsi_ml_byte(scmd->result) == SCSIML_STAT_DL_TIMEOUT) 1812 + return true; 1813 + 1843 1814 if (!scsi_status_is_check_condition(scmd->result)) 1844 1815 return false; 1845 1816 ··· 2003 1966 if (scmd->cmnd[0] == REPORT_LUNS) 2004 1967 scmd->device->sdev_target->expecting_lun_change = 0; 2005 1968 scsi_handle_queue_ramp_up(scmd->device); 1969 + if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) 1970 + /* 1971 + * If we have sense data, call scsi_check_sense() in 1972 + * order to set the correct SCSI ML byte (if any). 1973 + * No point in checking the return value, since the 1974 + * command has already completed successfully. 1975 + */ 1976 + scsi_check_sense(scmd); 2006 1977 fallthrough; 2007 1978 case SAM_STAT_COMMAND_TERMINATED: 2008 1979 return SUCCESS; ··· 2210 2165 * scsi_eh_get_sense), scmd->result is already 2211 2166 * set, do not set DID_TIME_OUT. 2212 2167 */ 2213 - if (!scmd->result) 2168 + if (!scmd->result && 2169 + !(scmd->flags & SCMD_FORCE_EH_SUCCESS)) 2214 2170 scmd->result |= (DID_TIME_OUT << 16); 2215 2171 SCSI_LOG_ERROR_RECOVERY(3, 2216 2172 scmd_printk(KERN_INFO, scmd,
+8 -7
drivers/scsi/scsi_lib.c
··· 578 578 return false; 579 579 } 580 580 581 - static inline u8 get_scsi_ml_byte(int result) 582 - { 583 - return (result >> 8) & 0xff; 584 - } 585 - 586 581 /** 587 582 * scsi_result_to_blk_status - translate a SCSI result code into blk_status_t 588 583 * @result: scsi error code ··· 590 595 * Check the scsi-ml byte first in case we converted a host or status 591 596 * byte. 592 597 */ 593 - switch (get_scsi_ml_byte(result)) { 598 + switch (scsi_ml_byte(result)) { 594 599 case SCSIML_STAT_OK: 595 600 break; 596 601 case SCSIML_STAT_RESV_CONFLICT: ··· 601 606 return BLK_STS_MEDIUM; 602 607 case SCSIML_STAT_TGT_FAILURE: 603 608 return BLK_STS_TARGET; 609 + case SCSIML_STAT_DL_TIMEOUT: 610 + return BLK_STS_DURATION_LIMIT; 604 611 } 605 612 606 613 switch (host_byte(result)) { ··· 800 803 blk_stat = BLK_STS_ZONE_OPEN_RESOURCE; 801 804 } 802 805 break; 806 + case COMPLETED: 807 + fallthrough; 803 808 default: 804 809 action = ACTION_FAIL; 805 810 break; ··· 2148 2149 * @sdev: SCSI device to be queried 2149 2150 * @dbd: set to prevent mode sense from returning block descriptors 2150 2151 * @modepage: mode page being requested 2152 + * @subpage: sub-page of the mode page being requested 2151 2153 * @buffer: request buffer (may not be smaller than eight bytes) 2152 2154 * @len: length of request buffer. 2153 2155 * @timeout: command timeout ··· 2160 2160 * Returns zero if successful, or a negative error number on failure 2161 2161 */ 2162 2162 int 2163 - scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, 2163 + scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, int subpage, 2164 2164 unsigned char *buffer, int len, int timeout, int retries, 2165 2165 struct scsi_mode_data *data, struct scsi_sense_hdr *sshdr) 2166 2166 { ··· 2180 2180 dbd = sdev->set_dbd_for_ms ? 8 : dbd; 2181 2181 cmd[1] = dbd & 0x18; /* allows DBD and LLBA bits */ 2182 2182 cmd[2] = modepage; 2183 + cmd[3] = subpage; 2183 2184 2184 2185 sshdr = exec_args.sshdr; 2185 2186
+6
drivers/scsi/scsi_priv.h
··· 27 27 SCSIML_STAT_NOSPC = 0x02, /* Space allocation on the dev failed */ 28 28 SCSIML_STAT_MED_ERROR = 0x03, /* Medium error */ 29 29 SCSIML_STAT_TGT_FAILURE = 0x04, /* Permanent target failure */ 30 + SCSIML_STAT_DL_TIMEOUT = 0x05, /* Command Duration Limit timeout */ 30 31 }; 32 + 33 + static inline u8 scsi_ml_byte(int result) 34 + { 35 + return (result >> 8) & 0xff; 36 + } 31 37 32 38 /* 33 39 * Scsi Error Handler Flags
+3
drivers/scsi/scsi_scan.c
··· 1087 1087 if (sdev->scsi_level >= SCSI_3) 1088 1088 scsi_attach_vpd(sdev); 1089 1089 1090 + scsi_cdl_check(sdev); 1091 + 1090 1092 sdev->max_queue_depth = sdev->queue_depth; 1091 1093 WARN_ON_ONCE(sdev->max_queue_depth > sdev->budget_map.depth); 1092 1094 sdev->sdev_bflags = *bflags; ··· 1626 1624 device_lock(dev); 1627 1625 1628 1626 scsi_attach_vpd(sdev); 1627 + scsi_cdl_check(sdev); 1629 1628 1630 1629 if (sdev->handler && sdev->handler->rescan) 1631 1630 sdev->handler->rescan(sdev);
+30
drivers/scsi/scsi_sysfs.c
··· 670 670 sdev_rd_attr (vendor, "%.8s\n"); 671 671 sdev_rd_attr (model, "%.16s\n"); 672 672 sdev_rd_attr (rev, "%.4s\n"); 673 + sdev_rd_attr (cdl_supported, "%d\n"); 673 674 674 675 static ssize_t 675 676 sdev_show_device_busy(struct device *dev, struct device_attribute *attr, ··· 1222 1221 sdev_show_queue_ramp_up_period, 1223 1222 sdev_store_queue_ramp_up_period); 1224 1223 1224 + static ssize_t sdev_show_cdl_enable(struct device *dev, 1225 + struct device_attribute *attr, char *buf) 1226 + { 1227 + struct scsi_device *sdev = to_scsi_device(dev); 1228 + 1229 + return sysfs_emit(buf, "%d\n", (int)sdev->cdl_enable); 1230 + } 1231 + 1232 + static ssize_t sdev_store_cdl_enable(struct device *dev, 1233 + struct device_attribute *attr, 1234 + const char *buf, size_t count) 1235 + { 1236 + int ret; 1237 + bool v; 1238 + 1239 + if (kstrtobool(buf, &v)) 1240 + return -EINVAL; 1241 + 1242 + ret = scsi_cdl_enable(to_scsi_device(dev), v); 1243 + if (ret) 1244 + return ret; 1245 + 1246 + return count; 1247 + } 1248 + static DEVICE_ATTR(cdl_enable, S_IRUGO | S_IWUSR, 1249 + sdev_show_cdl_enable, sdev_store_cdl_enable); 1250 + 1225 1251 static umode_t scsi_sdev_attr_is_visible(struct kobject *kobj, 1226 1252 struct attribute *attr, int i) 1227 1253 { ··· 1328 1300 &dev_attr_preferred_path.attr, 1329 1301 #endif 1330 1302 &dev_attr_queue_ramp_up_period.attr, 1303 + &dev_attr_cdl_supported.attr, 1304 + &dev_attr_cdl_enable.attr, 1331 1305 REF_EVT(media_change), 1332 1306 REF_EVT(inquiry_change_reported), 1333 1307 REF_EVT(capacity_change_reported),
+1 -1
drivers/scsi/scsi_transport_sas.c
··· 1245 1245 if (!buffer) 1246 1246 return -ENOMEM; 1247 1247 1248 - error = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3, 1248 + error = scsi_mode_sense(sdev, 1, 0x19, 0, buffer, BUF_SIZE, 30*HZ, 3, 1249 1249 &mode_data, NULL); 1250 1250 1251 1251 if (error)
+43 -16
drivers/scsi/sd.c
··· 184 184 return count; 185 185 } 186 186 187 - if (scsi_mode_sense(sdp, 0x08, 8, buffer, sizeof(buffer), SD_TIMEOUT, 187 + if (scsi_mode_sense(sdp, 0x08, 8, 0, buffer, sizeof(buffer), SD_TIMEOUT, 188 188 sdkp->max_retries, &data, NULL)) 189 189 return -EINVAL; 190 190 len = min_t(size_t, sizeof(buffer), data.length - data.header_length - ··· 1042 1042 1043 1043 static blk_status_t sd_setup_rw32_cmnd(struct scsi_cmnd *cmd, bool write, 1044 1044 sector_t lba, unsigned int nr_blocks, 1045 - unsigned char flags) 1045 + unsigned char flags, unsigned int dld) 1046 1046 { 1047 1047 cmd->cmd_len = SD_EXT_CDB_SIZE; 1048 1048 cmd->cmnd[0] = VARIABLE_LENGTH_CMD; 1049 1049 cmd->cmnd[7] = 0x18; /* Additional CDB len */ 1050 1050 cmd->cmnd[9] = write ? WRITE_32 : READ_32; 1051 1051 cmd->cmnd[10] = flags; 1052 + cmd->cmnd[11] = dld & 0x07; 1052 1053 put_unaligned_be64(lba, &cmd->cmnd[12]); 1053 1054 put_unaligned_be32(lba, &cmd->cmnd[20]); /* Expected Indirect LBA */ 1054 1055 put_unaligned_be32(nr_blocks, &cmd->cmnd[28]); ··· 1059 1058 1060 1059 static blk_status_t sd_setup_rw16_cmnd(struct scsi_cmnd *cmd, bool write, 1061 1060 sector_t lba, unsigned int nr_blocks, 1062 - unsigned char flags) 1061 + unsigned char flags, unsigned int dld) 1063 1062 { 1064 1063 cmd->cmd_len = 16; 1065 1064 cmd->cmnd[0] = write ? WRITE_16 : READ_16; 1066 - cmd->cmnd[1] = flags; 1067 - cmd->cmnd[14] = 0; 1065 + cmd->cmnd[1] = flags | ((dld >> 2) & 0x01); 1066 + cmd->cmnd[14] = (dld & 0x03) << 6; 1068 1067 cmd->cmnd[15] = 0; 1069 1068 put_unaligned_be64(lba, &cmd->cmnd[2]); 1070 1069 put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); ··· 1116 1115 return BLK_STS_OK; 1117 1116 } 1118 1117 1118 + /* 1119 + * Check if a command has a duration limit set. If it does, and the target 1120 + * device supports CDL and the feature is enabled, return the limit 1121 + * descriptor index to use. Return 0 (no limit) otherwise. 1122 + */ 1123 + static int sd_cdl_dld(struct scsi_disk *sdkp, struct scsi_cmnd *scmd) 1124 + { 1125 + struct scsi_device *sdp = sdkp->device; 1126 + int hint; 1127 + 1128 + if (!sdp->cdl_supported || !sdp->cdl_enable) 1129 + return 0; 1130 + 1131 + /* 1132 + * Use "no limit" if the request ioprio does not specify a duration 1133 + * limit hint. 1134 + */ 1135 + hint = IOPRIO_PRIO_HINT(req_get_ioprio(scsi_cmd_to_rq(scmd))); 1136 + if (hint < IOPRIO_HINT_DEV_DURATION_LIMIT_1 || 1137 + hint > IOPRIO_HINT_DEV_DURATION_LIMIT_7) 1138 + return 0; 1139 + 1140 + return (hint - IOPRIO_HINT_DEV_DURATION_LIMIT_1) + 1; 1141 + } 1142 + 1119 1143 static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) 1120 1144 { 1121 1145 struct request *rq = scsi_cmd_to_rq(cmd); ··· 1152 1126 unsigned int mask = logical_to_sectors(sdp, 1) - 1; 1153 1127 bool write = rq_data_dir(rq) == WRITE; 1154 1128 unsigned char protect, fua; 1129 + unsigned int dld; 1155 1130 blk_status_t ret; 1156 1131 unsigned int dif; 1157 1132 bool dix; ··· 1202 1175 fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; 1203 1176 dix = scsi_prot_sg_count(cmd); 1204 1177 dif = scsi_host_dif_capable(cmd->device->host, sdkp->protection_type); 1178 + dld = sd_cdl_dld(sdkp, cmd); 1205 1179 1206 1180 if (dif || dix) 1207 1181 protect = sd_setup_protect_cmnd(cmd, dix, dif); ··· 1211 1183 1212 1184 if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { 1213 1185 ret = sd_setup_rw32_cmnd(cmd, write, lba, nr_blocks, 1214 - protect | fua); 1186 + protect | fua, dld); 1215 1187 } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { 1216 1188 ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks, 1217 - protect | fua); 1189 + protect | fua, dld); 1218 1190 } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || 1219 1191 sdp->use_10_for_rw || protect) { 1220 1192 ret = sd_setup_rw10_cmnd(cmd, write, lba, nr_blocks, ··· 2711 2683 if (sdkp->device->use_10_for_ms && len < 8) 2712 2684 len = 8; 2713 2685 2714 - return scsi_mode_sense(sdkp->device, dbd, modepage, buffer, len, 2715 - SD_TIMEOUT, sdkp->max_retries, data, 2716 - sshdr); 2686 + return scsi_mode_sense(sdkp->device, dbd, modepage, 0, buffer, len, 2687 + SD_TIMEOUT, sdkp->max_retries, data, sshdr); 2717 2688 } 2718 2689 2719 2690 /* ··· 2969 2942 if (sdkp->protection_type == 0) 2970 2943 return; 2971 2944 2972 - res = scsi_mode_sense(sdp, 1, 0x0a, buffer, 36, SD_TIMEOUT, 2945 + res = scsi_mode_sense(sdp, 1, 0x0a, 0, buffer, 36, SD_TIMEOUT, 2973 2946 sdkp->max_retries, &data, &sshdr); 2974 2947 2975 2948 if (res < 0 || !data.header_length || ··· 3158 3131 return; 3159 3132 } 3160 3133 3161 - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, INQUIRY) < 0) { 3134 + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, INQUIRY, 0) < 0) { 3162 3135 struct scsi_vpd *vpd; 3163 3136 3164 3137 sdev->no_report_opcodes = 1; ··· 3174 3147 rcu_read_unlock(); 3175 3148 } 3176 3149 3177 - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1) 3150 + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16, 0) == 1) 3178 3151 sdkp->ws16 = 1; 3179 3152 3180 - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1) 3153 + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME, 0) == 1) 3181 3154 sdkp->ws10 = 1; 3182 3155 } 3183 3156 ··· 3189 3162 return; 3190 3163 3191 3164 if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, 3192 - SECURITY_PROTOCOL_IN) == 1 && 3165 + SECURITY_PROTOCOL_IN, 0) == 1 && 3193 3166 scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, 3194 - SECURITY_PROTOCOL_OUT) == 1) 3167 + SECURITY_PROTOCOL_OUT, 0) == 1) 3195 3168 sdkp->security = 1; 3196 3169 } 3197 3170
+1 -1
drivers/scsi/sr.c
··· 825 825 scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr); 826 826 827 827 /* ask for mode page 0x2a */ 828 - rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, ms_len, 828 + rc = scsi_mode_sense(cd->device, 0, 0x2a, 0, buffer, ms_len, 829 829 SR_TIMEOUT, 3, &data, NULL); 830 830 831 831 if (rc < 0 || data.length > ms_len ||
+10 -1
include/linux/ata.h
··· 322 322 ATA_LOG_SATA_NCQ = 0x10, 323 323 ATA_LOG_NCQ_NON_DATA = 0x12, 324 324 ATA_LOG_NCQ_SEND_RECV = 0x13, 325 + ATA_LOG_CDL = 0x18, 326 + ATA_LOG_CDL_SIZE = ATA_SECT_SIZE, 325 327 ATA_LOG_IDENTIFY_DEVICE = 0x30, 328 + ATA_LOG_SENSE_NCQ = 0x0F, 329 + ATA_LOG_SENSE_NCQ_SIZE = ATA_SECT_SIZE * 2, 326 330 ATA_LOG_CONCURRENT_POSITIONING_RANGES = 0x47, 327 331 328 332 /* Identify device log pages: */ 333 + ATA_LOG_SUPPORTED_CAPABILITIES = 0x03, 334 + ATA_LOG_CURRENT_SETTINGS = 0x04, 329 335 ATA_LOG_SECURITY = 0x06, 330 336 ATA_LOG_SATA_SETTINGS = 0x08, 331 337 ATA_LOG_ZONED_INFORMATION = 0x09, 332 338 333 - /* Identify device SATA settings log:*/ 339 + /* Identify device SATA settings log: */ 334 340 ATA_LOG_DEVSLP_OFFSET = 0x30, 335 341 ATA_LOG_DEVSLP_SIZE = 0x08, 336 342 ATA_LOG_DEVSLP_MDAT = 0x00, ··· 421 415 SETFEATURES_SATA_ENABLE = 0x10, /* Enable use of SATA feature */ 422 416 SETFEATURES_SATA_DISABLE = 0x90, /* Disable use of SATA feature */ 423 417 418 + SETFEATURES_CDL = 0x0d, /* Enable/disable cmd duration limits */ 419 + 424 420 /* SETFEATURE Sector counts for SATA features */ 425 421 SATA_FPDMA_OFFSET = 0x01, /* FPDMA non-zero buffer offsets */ 426 422 SATA_FPDMA_AA = 0x02, /* FPDMA Setup FIS Auto-Activate */ ··· 433 425 SATA_DEVSLP = 0x09, /* Device Sleep */ 434 426 435 427 SETFEATURE_SENSE_DATA = 0xC3, /* Sense Data Reporting feature */ 428 + SETFEATURE_SENSE_DATA_SUCC_NCQ = 0xC4, /* Sense Data for successful NCQ commands */ 436 429 437 430 /* feature values for SET_MAX */ 438 431 ATA_SET_MAX_ADDR = 0x00,
+6
include/linux/blk_types.h
··· 171 171 */ 172 172 #define BLK_STS_OFFLINE ((__force blk_status_t)17) 173 173 174 + /* 175 + * BLK_STS_DURATION_LIMIT is returned from the driver when the target device 176 + * aborted the command because it exceeded one of its Command Duration Limits. 177 + */ 178 + #define BLK_STS_DURATION_LIMIT ((__force blk_status_t)18) 179 + 174 180 /** 175 181 * blk_path_error - returns true if error may be path related 176 182 * @error: status the request was completed with
+27 -11
include/linux/libata.h
··· 94 94 ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */ 95 95 ATA_DFLAG_NCQ_SEND_RECV = (1 << 11), /* device supports NCQ SEND and RECV */ 96 96 ATA_DFLAG_NCQ_PRIO = (1 << 12), /* device supports NCQ priority */ 97 - ATA_DFLAG_CFG_MASK = (1 << 13) - 1, 97 + ATA_DFLAG_CDL = (1 << 13), /* supports cmd duration limits */ 98 + ATA_DFLAG_CFG_MASK = (1 << 14) - 1, 98 99 99 - ATA_DFLAG_PIO = (1 << 13), /* device limited to PIO mode */ 100 - ATA_DFLAG_NCQ_OFF = (1 << 14), /* device limited to non-NCQ mode */ 101 - ATA_DFLAG_SLEEPING = (1 << 15), /* device is sleeping */ 102 - ATA_DFLAG_DUBIOUS_XFER = (1 << 16), /* data transfer not verified */ 103 - ATA_DFLAG_NO_UNLOAD = (1 << 17), /* device doesn't support unload */ 104 - ATA_DFLAG_UNLOCK_HPA = (1 << 18), /* unlock HPA */ 105 - ATA_DFLAG_INIT_MASK = (1 << 19) - 1, 100 + ATA_DFLAG_PIO = (1 << 14), /* device limited to PIO mode */ 101 + ATA_DFLAG_NCQ_OFF = (1 << 15), /* device limited to non-NCQ mode */ 102 + ATA_DFLAG_SLEEPING = (1 << 16), /* device is sleeping */ 103 + ATA_DFLAG_DUBIOUS_XFER = (1 << 17), /* data transfer not verified */ 104 + ATA_DFLAG_NO_UNLOAD = (1 << 18), /* device doesn't support unload */ 105 + ATA_DFLAG_UNLOCK_HPA = (1 << 19), /* unlock HPA */ 106 + ATA_DFLAG_INIT_MASK = (1 << 20) - 1, 106 107 107 - ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 19), /* Priority cmds sent to dev */ 108 + ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 20), /* Priority cmds sent to dev */ 109 + ATA_DFLAG_CDL_ENABLED = (1 << 21), /* cmd duration limits is enabled */ 108 110 ATA_DFLAG_DETACH = (1 << 24), 109 111 ATA_DFLAG_DETACHED = (1 << 25), 110 112 ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */ ··· 117 115 118 116 ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \ 119 117 ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \ 120 - ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA), 118 + ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA | \ 119 + ATA_DFLAG_CDL), 121 120 122 121 ATA_DEV_UNKNOWN = 0, /* unknown device */ 123 122 ATA_DEV_ATA = 1, /* ATA device */ ··· 209 206 ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */ 210 207 ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */ 211 208 ATA_QCFLAG_RETRY = (1 << 7), /* retry after failure */ 209 + ATA_QCFLAG_HAS_CDL = (1 << 8), /* qc has CDL a descriptor set */ 212 210 213 211 ATA_QCFLAG_EH = (1 << 16), /* cmd aborted and owned by EH */ 214 212 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */ 215 213 ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */ 214 + ATA_QCFLAG_EH_SUCCESS_CMD = (1 << 19), /* EH should fetch sense for this successful cmd */ 216 215 217 216 /* host set flags */ 218 217 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */ ··· 313 308 ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET, 314 309 ATA_EH_ENABLE_LINK = (1 << 3), 315 310 ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */ 311 + ATA_EH_GET_SUCCESS_SENSE = (1 << 6), /* Get sense data for successful cmd */ 316 312 317 - ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK, 313 + ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK | 314 + ATA_EH_GET_SUCCESS_SENSE, 318 315 ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET | 319 316 ATA_EH_ENABLE_LINK, 320 317 ··· 716 709 /* Concurrent positioning ranges */ 717 710 struct ata_cpr_log *cpr_log; 718 711 712 + /* Command Duration Limits log support */ 713 + u8 cdl[ATA_LOG_CDL_SIZE]; 714 + 719 715 /* error history */ 720 716 int spdn_cnt; 721 717 /* ering is CLEAR_END, read comment above CLEAR_END */ ··· 870 860 struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */ 871 861 #endif 872 862 /* owned by EH */ 863 + u8 *ncq_sense_buf; 873 864 u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned; 874 865 }; 875 866 ··· 1189 1178 bool *online, int (*check_ready)(struct ata_link *)); 1190 1179 extern int sata_link_resume(struct ata_link *link, const unsigned long *params, 1191 1180 unsigned long deadline); 1181 + extern int ata_eh_read_sense_success_ncq_log(struct ata_link *link); 1192 1182 extern void ata_eh_analyze_ncq_error(struct ata_link *link); 1193 1183 #else 1194 1184 static inline const unsigned long * ··· 1224 1212 static inline int sata_link_resume(struct ata_link *link, 1225 1213 const unsigned long *params, 1226 1214 unsigned long deadline) 1215 + { 1216 + return -EOPNOTSUPP; 1217 + } 1218 + static inline int ata_eh_read_sense_success_ncq_log(struct ata_link *link) 1227 1219 { 1228 1220 return -EOPNOTSUPP; 1229 1221 }
+5
include/scsi/scsi_cmnd.h
··· 52 52 #define SCMD_TAGGED (1 << 0) 53 53 #define SCMD_INITIALIZED (1 << 1) 54 54 #define SCMD_LAST (1 << 2) 55 + /* 56 + * libata uses SCSI EH to fetch sense data for successful commands. 57 + * SCSI EH should not overwrite scmd->result when SCMD_FORCE_EH_SUCCESS is set. 58 + */ 59 + #define SCMD_FORCE_EH_SUCCESS (1 << 3) 55 60 #define SCMD_FAIL_IF_RECOVERING (1 << 4) 56 61 /* flags preserved across unprep / reprep */ 57 62 #define SCMD_PRESERVED_FLAGS (SCMD_INITIALIZED | SCMD_FAIL_IF_RECOVERING)
+12 -6
include/scsi/scsi_device.h
··· 218 218 unsigned silence_suspend:1; /* Do not print runtime PM related messages */ 219 219 unsigned no_vpd_size:1; /* No VPD size reported in header */ 220 220 221 + unsigned cdl_supported:1; /* Command duration limits supported */ 222 + unsigned cdl_enable:1; /* Enable/disable Command duration limits */ 223 + 221 224 unsigned int queue_stopped; /* request queue is quiesced */ 222 225 bool offline_already; /* Device offline message logged */ 223 226 ··· 367 364 extern void scsi_remove_device(struct scsi_device *); 368 365 extern int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh); 369 366 void scsi_attach_vpd(struct scsi_device *sdev); 367 + void scsi_cdl_check(struct scsi_device *sdev); 368 + int scsi_cdl_enable(struct scsi_device *sdev, bool enable); 370 369 371 370 extern struct scsi_device *scsi_device_from_queue(struct request_queue *q); 372 371 extern int __must_check scsi_device_get(struct scsi_device *); ··· 426 421 427 422 extern int scsi_set_medium_removal(struct scsi_device *, char); 428 423 429 - extern int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, 430 - unsigned char *buffer, int len, int timeout, 431 - int retries, struct scsi_mode_data *data, 432 - struct scsi_sense_hdr *); 424 + int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, 425 + int subpage, unsigned char *buffer, int len, int timeout, 426 + int retries, struct scsi_mode_data *data, 427 + struct scsi_sense_hdr *); 433 428 extern int scsi_mode_select(struct scsi_device *sdev, int pf, int sp, 434 429 unsigned char *buffer, int len, int timeout, 435 430 int retries, struct scsi_mode_data *data, ··· 438 433 int retries, struct scsi_sense_hdr *sshdr); 439 434 extern int scsi_get_vpd_page(struct scsi_device *, u8 page, unsigned char *buf, 440 435 int buf_len); 441 - extern int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, 442 - unsigned int len, unsigned char opcode); 436 + int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, 437 + unsigned int len, unsigned char opcode, 438 + unsigned short sa); 443 439 extern int scsi_device_set_state(struct scsi_device *sdev, 444 440 enum scsi_device_state state); 445 441 extern struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type,
+63 -5
include/uapi/linux/ioprio.h
··· 17 17 ((data) & IOPRIO_PRIO_MASK)) 18 18 19 19 /* 20 - * These are the io priority groups as implemented by the BFQ and mq-deadline 20 + * These are the io priority classes as implemented by the BFQ and mq-deadline 21 21 * schedulers. RT is the realtime class, it always gets premium service. For 22 22 * ATA disks supporting NCQ IO priority, RT class IOs will be processed using 23 23 * high priority NCQ commands. BE is the best-effort scheduling class, the ··· 32 32 }; 33 33 34 34 /* 35 - * The RT and BE priority classes both support up to 8 priority levels. 35 + * The RT and BE priority classes both support up to 8 priority levels that 36 + * can be specified using the lower 3-bits of the priority data. 36 37 */ 37 - #define IOPRIO_NR_LEVELS 8 38 - #define IOPRIO_BE_NR IOPRIO_NR_LEVELS 38 + #define IOPRIO_LEVEL_NR_BITS 3 39 + #define IOPRIO_NR_LEVELS (1 << IOPRIO_LEVEL_NR_BITS) 40 + #define IOPRIO_LEVEL_MASK (IOPRIO_NR_LEVELS - 1) 41 + #define IOPRIO_PRIO_LEVEL(ioprio) ((ioprio) & IOPRIO_LEVEL_MASK) 39 42 43 + #define IOPRIO_BE_NR IOPRIO_NR_LEVELS 44 + 45 + /* 46 + * Possible values for the "which" argument of the ioprio_get() and 47 + * ioprio_set() system calls (see "man ioprio_set"). 48 + */ 40 49 enum { 41 50 IOPRIO_WHO_PROCESS = 1, 42 51 IOPRIO_WHO_PGRP, ··· 53 44 }; 54 45 55 46 /* 56 - * Fallback BE priority level. 47 + * Fallback BE class priority level. 57 48 */ 58 49 #define IOPRIO_NORM 4 59 50 #define IOPRIO_BE_NORM IOPRIO_NORM 51 + 52 + /* 53 + * The 10 bits between the priority class and the priority level are used to 54 + * optionally define I/O hints for any combination of I/O priority class and 55 + * level. Depending on the kernel configuration, I/O scheduler being used and 56 + * the target I/O device being used, hints can influence how I/Os are processed 57 + * without affecting the I/O scheduling ordering defined by the I/O priority 58 + * class and level. 59 + */ 60 + #define IOPRIO_HINT_SHIFT IOPRIO_LEVEL_NR_BITS 61 + #define IOPRIO_HINT_NR_BITS 10 62 + #define IOPRIO_NR_HINTS (1 << IOPRIO_HINT_NR_BITS) 63 + #define IOPRIO_HINT_MASK (IOPRIO_NR_HINTS - 1) 64 + #define IOPRIO_PRIO_HINT(ioprio) \ 65 + (((ioprio) >> IOPRIO_HINT_SHIFT) & IOPRIO_HINT_MASK) 66 + 67 + /* 68 + * Alternate macro for IOPRIO_PRIO_VALUE() to define an I/O priority with 69 + * a class, level and hint. 70 + */ 71 + #define IOPRIO_PRIO_VALUE_HINT(class, level, hint) \ 72 + ((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \ 73 + (((hint) & IOPRIO_HINT_MASK) << IOPRIO_HINT_SHIFT) | \ 74 + ((level) & IOPRIO_LEVEL_MASK)) 75 + 76 + /* 77 + * I/O hints. 78 + */ 79 + enum { 80 + /* No hint */ 81 + IOPRIO_HINT_NONE = 0, 82 + 83 + /* 84 + * Device command duration limits: indicate to the device a desired 85 + * duration limit for the commands that will be used to process an I/O. 86 + * These will currently only be effective for SCSI and ATA devices that 87 + * support the command duration limits feature. If this feature is 88 + * enabled, then the commands issued to the device to process an I/O with 89 + * one of these hints set will have the duration limit index (dld field) 90 + * set to the value of the hint. 91 + */ 92 + IOPRIO_HINT_DEV_DURATION_LIMIT_1 = 1, 93 + IOPRIO_HINT_DEV_DURATION_LIMIT_2 = 2, 94 + IOPRIO_HINT_DEV_DURATION_LIMIT_3 = 3, 95 + IOPRIO_HINT_DEV_DURATION_LIMIT_4 = 4, 96 + IOPRIO_HINT_DEV_DURATION_LIMIT_5 = 5, 97 + IOPRIO_HINT_DEV_DURATION_LIMIT_6 = 6, 98 + IOPRIO_HINT_DEV_DURATION_LIMIT_7 = 7, 99 + }; 60 100 61 101 #endif /* _UAPI_LINUX_IOPRIO_H */