History

Merge tag 'ata-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux

Pull ata updates from Damien Le Moal: - Some code cleanups to rename the function used to identify ZAC devices and declare some local functions static (me) - Refactoring and improvement of the translation of the SCSI REPORT SUPPORTED OPCODES command to allow users access to the entire list of supported commands (me) - Fix the translation of the WRITE SAME command with UNMAP bit set (DSM TRIM) for devices with a sector size larger than 2K and devices that support multiple TRIM segments (Niklas) - Add support detecting support for and translating the SCSI commands related to the storage elements depopulation feature (GET PHYSICAL ELEMENT STATUS, REMOVE ELEMENT AND TRUCATE, REMOVE ELEMENT AND MODIFY ZONES and RESTORE ELEMENTS AND REBUILD) (me) - Improvements to the sata_mv driver probe code (clocks and IRQ initialization) (Rosen) - Improve resource initialization in the pata_rb532_cf, pata_pxa, sata_highbank and ahci_da850 drivers (Rosen) - Improve PIO data-in command completions to better hndle slow devices, e.g. CF cards (Richard) - Improve the DMA channel management using device resources in the pata_pxa driver (Rosen) - Fix the pata_ep93xx driver to correctly fallback to PIO mode if DMA initialization fails (Rosen) - Use named initializers to define the match tables of the ahci_xgene, ahci_qoriq and ahci_platform drivers (Pawel) * tag 'ata-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux: (28 commits) ata: use named initializers for acpi_device_id ata: pata_ep93xx: fix PIO fallback when DMA init fails ata: pata_pxa: use devres for DMA channel management ata: libata-sff: don't busy-wait for PIO data-in command completion ata: ahci_da850: use devm_platform_ioremap_resource() ata: sata_highbank: use devm_platform_ioremap_resource ata: pata_pxa: use devm_platform_ioremap_resource ata: pata_rb532_cf: use devm_platform_ioremap_resource() ata: sata_mv: use devm clock helpers ata: sata_mv: Use platform_get_irq() to get interrupt ata: pata_mpc52xx: Remove redundant dev_err() ata: libata-eh: make ata_eh_qc_complete() and ata_eh_qc_retry() static ata: libata-scsi: add support for the REMOVE ELEMENT AND MODIFY ZONES command ata: libata-scsi: add support for the RESTORE ELEMENTS AND REBUILD command ata: libata-scsi: add support for the REMOVE ELEMENT AND TRUNCATE command ata: libata-scsi: add support for the GET PHYSICAL ELEMENT STATUS command ata: libata-core: detect support for depopulation capabilities ata: libata-scsi: improve ata_get_xlat_func ata: libata: improve the definition of device flags scsi: define depopulation capabilities related service actions ...

Linus Torvalds committed 2 months ago

Commit faabe2d2 parents 59e6295 73b6bf320 files · +915 −345Browse files

Unified · Split

20 files
  1. drivers/ata/ahci_da850.c +4 −13
  2. drivers/ata/ahci_platform.c +2 −2
  3. drivers/ata/ahci_qoriq.c +1 −1
  4. drivers/ata/ahci_seattle.c +2 −2
  5. drivers/ata/ahci_xgene.c +3 −3
  6. drivers/ata/libata-core.c +74 −5
  7. drivers/ata/libata-eh.c +4 −2
  8. drivers/ata/libata-scsi.c +610 −104
  9. drivers/ata/libata-sff.c +17 −7
  10. drivers/ata/libata.h +1 −1
  11. drivers/ata/pata_ep93xx.c +21 −9
  12. drivers/ata/pata_mpc52xx.c +1 −3
  13. drivers/ata/pata_pxa.c +10 −42
  14. drivers/ata/pata_rb532_cf.c +5 −11
  15. drivers/ata/sata_highbank.c +5 −13
  16. drivers/ata/sata_mv.c +14 −38
  17. drivers/scsi/scsi_debug.c +0 −46
  18. include/linux/ata.h +17 −0
  19. include/linux/libata.h +50 −43
  20. include/scsi/scsi_proto.h +74 −0
drivers/ata/ahci_da850.c+4−13
@@ -162,7 +162,6 @@ static int ahci_da850_probe(struct platform_device *pdev) · 161 unmodified lines
162162 struct device *dev = &pdev->dev;
163163 struct ahci_host_priv *hpriv;
164164 void __iomem *pwrdn_reg;
165− struct resource *res;
166165 u32 mpy;
167166 int rc;
168167
@@ -198,22 +197,14 @@ static int ahci_da850_probe(struct platform_device *pdev) · 29 unmodified lines
198197 return -EINVAL;
199198 }
200199
200+ pwrdn_reg = devm_platform_ioremap_resource(pdev, 1);
201+ if (IS_ERR(pwrdn_reg))
202+ return PTR_ERR(pwrdn_reg);
203+
201204 rc = ahci_platform_enable_resources(hpriv);
202205 if (rc)
203206 return rc;
204207
205− res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
206− if (!res) {
207− rc = -ENODEV;
208− goto disable_resources;
209− }
210−
211− pwrdn_reg = devm_ioremap(dev, res->start, resource_size(res));
212− if (!pwrdn_reg) {
213− rc = -ENOMEM;
214− goto disable_resources;
215− }
216−
217208 da850_sata_init(dev, pwrdn_reg, hpriv->mmio, mpy);
218209
219210 rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info,
drivers/ata/ahci_platform.c+2−2
@@ -87,9 +87,9 @@ static const struct of_device_id ahci_of_match[] = { · 86 unmodified lines
8787 MODULE_DEVICE_TABLE(of, ahci_of_match);
8888
8989 static const struct acpi_device_id ahci_acpi_match[] = {
90− { "APMC0D33", (unsigned long)&ahci_port_info_nolpm },
90+ { .id = "APMC0D33", .driver_data = (unsigned long)&ahci_port_info_nolpm },
9191 { ACPI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff) },
92− {},
92+ { }
9393 };
9494 MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
9595
drivers/ata/ahci_qoriq.c+1−1
@@ -80,7 +80,7 @@ static const struct of_device_id ahci_qoriq_of_match[] = { · 79 unmodified lines
8080 MODULE_DEVICE_TABLE(of, ahci_qoriq_of_match);
8181
8282 static const struct acpi_device_id ahci_qoriq_acpi_match[] = {
83− {"NXP0004", .driver_data = (kernel_ulong_t)AHCI_LX2160A},
83+ { .id = "NXP0004", .driver_data = (kernel_ulong_t)AHCI_LX2160A },
8484 { }
8585 };
8686 MODULE_DEVICE_TABLE(acpi, ahci_qoriq_acpi_match);
drivers/ata/ahci_seattle.c+2−2
@@ -178,8 +178,8 @@ static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend, · 177 unmodified lines
178178 ahci_platform_resume);
179179
180180 static const struct acpi_device_id ahci_acpi_match[] = {
181− { "AMDI0600", 0 },
182− {}
181+ { .id = "AMDI0600" },
182+ { }
183183 };
184184 MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
185185
drivers/ata/ahci_xgene.c+3−3
@@ -710,9 +710,9 @@ static const struct scsi_host_template ahci_platform_sht = { · 709 unmodified lines
710710
711711 #ifdef CONFIG_ACPI
712712 static const struct acpi_device_id xgene_ahci_acpi_match[] = {
713− { "APMC0D0D", XGENE_AHCI_V1},
714− { "APMC0D32", XGENE_AHCI_V2},
715− {},
713+ { .id = "APMC0D0D", .driver_data = XGENE_AHCI_V1 },
714+ { .id = "APMC0D32", .driver_data = XGENE_AHCI_V2 },
715+ { }
716716 };
717717 MODULE_DEVICE_TABLE(acpi, xgene_ahci_acpi_match);
718718 #endif
drivers/ata/libata-core.c+74−5
@@ -2488,7 +2488,7 @@ static void ata_dev_config_sense_reporting(struct ata_device *dev) · 2487 unmodified lines
24882488 }
24892489 }
24902490
2491−static void ata_dev_config_zac(struct ata_device *dev)
2491+static void ata_dev_config_zoned(struct ata_device *dev)
24922492 {
24932493 unsigned int err_mask;
24942494 u8 *identify_buf = dev->sector_buf;
@@ -2497,7 +2497,7 @@ static void ata_dev_config_zac(struct ata_device *dev) · 2 unmodified lines
24972497 dev->zac_zones_optimal_nonseq = U32_MAX;
24982498 dev->zac_zones_max_open = U32_MAX;
24992499
2500− if (!ata_dev_is_zac(dev))
2500+ if (!ata_dev_is_zoned(dev))
25012501 return;
25022502
25032503 if (!ata_identify_page_supported(dev, ATA_LOG_ZONED_INFORMATION)) {
@@ -2705,6 +2705,71 @@ not_supported: · 201 unmodified lines
27052705 ata_dev_cleanup_cdl_resources(dev);
27062706 }
27072707
2708+static void ata_dev_config_depop(struct ata_device *dev)
2709+{
2710+ unsigned int err_mask;
2711+ u64 val;
2712+
2713+ /* Ignore old drives. */
2714+ if (ata_id_major_version(dev->id) < 11)
2715+ goto not_supported;
2716+
2717+ /* NCQ Autosense is required. */
2718+ if (!ata_identify_page_supported(dev, ATA_LOG_SUPPORTED_CAPABILITIES) ||
2719+ !ata_id_has_ncq_autosense(dev->id))
2720+ goto not_supported;
2721+
2722+ err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE,
2723+ ATA_LOG_SUPPORTED_CAPABILITIES,
2724+ dev->sector_buf, 1);
2725+ if (err_mask)
2726+ goto not_supported;
2727+
2728+ /* Check depopulation capabilities bits. */
2729+ val = get_unaligned_le64(&dev->sector_buf[152]);
2730+ if (!(val & BIT_ULL(63)))
2731+ goto not_supported;
2732+
2733+ /*
2734+ * Support for at least the GET PHYSICAL ELEMENT STATUS and
2735+ * REMOVE ELEMENT AND TRUNCATE commands is mandated.
2736+ */
2737+ if (!(val & BIT_ULL(0)) || !(val & BIT_ULL(1)))
2738+ goto not_supported;
2739+
2740+ dev->flags |= ATA_DFLAG_DEPOP;
2741+
2742+ /* Check if RESTORE ELEMENTS AND REBUILD is supported. */
2743+ if (val & BIT_ULL(2))
2744+ dev->flags |= ATA_DFLAG_DEPOP_RESTORE;
2745+
2746+ /*
2747+ * For ZAC devices, check if REMOVE ELEMENT AND MODIFY ZONES is
2748+ * supported.
2749+ */
2750+ if (dev->class != ATA_DEV_ZAC)
2751+ return;
2752+
2753+ err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE,
2754+ ATA_LOG_ZONED_INFORMATION,
2755+ dev->sector_buf, 1);
2756+ if (err_mask)
2757+ return;
2758+
2759+ val = get_unaligned_le64(&dev->sector_buf[8]);
2760+ if (!(val & BIT_ULL(63)))
2761+ return;
2762+
2763+ if (val & BIT_ULL(1))
2764+ dev->flags |= ATA_DFLAG_DEPOP_MODIFY;
2765+
2766+ return;
2767+
2768+not_supported:
2769+ dev->flags &= ~(ATA_DFLAG_DEPOP | ATA_DFLAG_DEPOP_RESTORE |
2770+ ATA_DFLAG_DEPOP_MODIFY);
2771+}
2772+
27082773 static int ata_dev_config_lba(struct ata_device *dev)
27092774 {
27102775 const u16 *id = dev->id;
@@ -2942,7 +3007,7 @@ static void ata_dev_print_features(struct ata_device *dev) · 231 unmodified lines
29423007 return;
29433008
29443009 ata_dev_info(dev,
2945− "Features:%s%s%s%s%s%s%s%s%s%s\n",
3010+ "Features:%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
29463011 dev->flags & ATA_DFLAG_FUA ? " FUA" : "",
29473012 dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "",
29483013 dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "",
@@ -2952,7 +3017,10 @@ static void ata_dev_print_features(struct ata_device *dev) · 3 unmodified lines
29523017 dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "",
29533018 dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "",
29543019 dev->flags & ATA_DFLAG_CDL ? " CDL" : "",
2955− dev->cpr_log ? " CPR" : "");
3020+ dev->cpr_log ? " CPR" : "",
3021+ dev->flags & ATA_DFLAG_DEPOP ? " Depop" : "",
3022+ dev->flags & ATA_DFLAG_DEPOP_RESTORE ? " Depop-Restore" : "",
3023+ dev->flags & ATA_DFLAG_DEPOP_MODIFY ? " Depop-Modify" : "");
29563024 }
29573025
29583026 /**
@@ -3111,10 +3179,11 @@ int ata_dev_configure(struct ata_device *dev) · 152 unmodified lines
31113179 ata_dev_config_fua(dev);
31123180 ata_dev_config_devslp(dev);
31133181 ata_dev_config_sense_reporting(dev);
3114− ata_dev_config_zac(dev);
3182+ ata_dev_config_zoned(dev);
31153183 ata_dev_config_trusted(dev);
31163184 ata_dev_config_cpr(dev);
31173185 ata_dev_config_cdl(dev);
3186+ ata_dev_config_depop(dev);
31183187 dev->cdb_len = 32;
31193188
31203189 if (print_info)
drivers/ata/libata-eh.c+4−2
@@ -1221,9 +1221,10 @@ static void __ata_eh_qc_complete(struct ata_queued_cmd *qc) · 1220 unmodified lines
12211221 * Indicate to the mid and upper layers that an ATA command has
12221222 * completed. To be used from EH.
12231223 */
1224−void ata_eh_qc_complete(struct ata_queued_cmd *qc)
1224+static void ata_eh_qc_complete(struct ata_queued_cmd *qc)
12251225 {
12261226 struct scsi_cmnd *scmd = qc->scsicmd;
1227+
12271228 scmd->retries = scmd->allowed;
12281229 __ata_eh_qc_complete(qc);
12291230 }
@@ -1239,9 +1240,10 @@ void ata_eh_qc_complete(struct ata_queued_cmd *qc) · 9 unmodified lines
12391240 * scmd->allowed is incremented for commands which get retried
12401241 * due to unrelated failures (qc->err_mask is zero).
12411242 */
1242−void ata_eh_qc_retry(struct ata_queued_cmd *qc)
1243+static void ata_eh_qc_retry(struct ata_queued_cmd *qc)
12431244 {
12441245 struct scsi_cmnd *scmd = qc->scsicmd;
1246+
12451247 if (!qc->err_mask)
12461248 scmd->allowed++;
12471249 __ata_eh_qc_complete(qc);
drivers/ata/libata-scsi.c+610−104
@@ -2106,7 +2106,7 @@ static unsigned int ata_scsiop_inq_std(struct ata_device *dev, · 2105 unmodified lines
21062106 if (rbuf[32] == 0 || rbuf[32] == ' ')
21072107 memcpy(&rbuf[32], "n/a ", 4);
21082108
2109− if (ata_id_zoned_cap(dev->id) || dev->class == ATA_DEV_ZAC)
2109+ if (ata_dev_is_zoned(dev))
21102110 memcpy(rbuf + 58, versions_zbc, sizeof(versions_zbc));
21112111 else
21122112 memcpy(rbuf + 58, versions, sizeof(versions));
@@ -2146,7 +2146,7 @@ static unsigned int ata_scsiop_inq_00(struct ata_device *dev, · 33 unmodified lines
21462146 };
21472147
21482148 for (i = 0; i < sizeof(pages); i++) {
2149− if (pages[i] == 0xb6 && !ata_dev_is_zac(dev))
2149+ if (pages[i] == 0xb6 && !ata_dev_is_zoned(dev))
21502150 continue;
21512151 rbuf[num_pages + 4] = pages[i];
21522152 num_pages++;
@@ -2284,6 +2284,39 @@ static unsigned int ata_scsiop_inq_89(struct ata_device *dev, · 131 unmodified lines
22842284 return get_unaligned_be16(&rbuf[2]) + 4;
22852285 }
22862286
2287+/**
2288+ * ata_dsm_trim_pages - maximum DSM TRIM payload for a device, in 512-byte pages
2289+ * @dev: ATA device the DATA SET MANAGEMENT TRIM command will be sent to
2290+ *
2291+ * A DATA SET MANAGEMENT TRIM payload is a list of 512-byte pages, each holding
2292+ * up to ATA_MAX_TRIM_RNUM (64) LBA Range Entries; the format is page-based and
2293+ * unrelated to the logical sector size.
2294+ *
2295+ * The logical sector size still bounds it, though: the descriptor is written
2296+ * directly into the WRITE SAME data-out buffer, which sd sizes to a single
2297+ * logical block, so it can hold at most sector_size / 512 pages.
2298+ *
2299+ * Return: the maximum number of 512-byte pages a single translated WRITE SAME
2300+ * command may send to @dev (never less than one), that is the smaller of:
2301+ * - MAX PAGES PER DSM COMMAND (IDENTIFY DEVICE word 105), when the device
2302+ * reports a non-zero limit; and
2303+ * - the logical sector size expressed in 512-byte pages (see above).
2304+ */
2305+static unsigned int ata_dsm_trim_pages(struct ata_device *dev)
2306+{
2307+ unsigned int sector_size = ata_id_logical_sector_size(dev->id);
2308+ unsigned int max_pages = ata_id_dsm_max_pages(dev->id);
2309+ unsigned int pages = sector_size / ATA_SECT_SIZE;
2310+
2311+ /* If the device does not specify a limit, assume only a single page. */
2312+ if (!max_pages)
2313+ max_pages = 1;
2314+
2315+ pages = min_not_zero(pages, max_pages);
2316+
2317+ return pages;
2318+}
2319+
22872320 /**
22882321 * ata_scsiop_inq_b0 - Simulate INQUIRY VPD page B0, Block Limits
22892322 * @dev: Target device.
@@ -2323,7 +2356,8 @@ static unsigned int ata_scsiop_inq_b0(struct ata_device *dev, · 33 unmodified lines
23232356 * with the unmap bit set.
23242357 */
23252358 if (ata_id_has_trim(dev->id)) {
2326− u64 max_blocks = 65535 * ATA_MAX_TRIM_RNUM;
2359+ unsigned int max_pages = ata_dsm_trim_pages(dev);
2360+ u64 max_blocks = max_pages * ATA_MAX_TRIM_RNUM * (u64)U16_MAX;
23272361
23282362 if (dev->quirks & ATA_QUIRK_MAX_TRIM_128M)
23292363 max_blocks = 128 << (20 - SECTOR_SHIFT);
@@ -2403,7 +2437,7 @@ static unsigned int ata_scsiop_inq_b2(struct ata_device *dev, · 73 unmodified lines
24032437 static unsigned int ata_scsiop_inq_b6(struct ata_device *dev,
24042438 struct scsi_cmnd *cmd, u8 *rbuf)
24052439 {
2406− if (!ata_dev_is_zac(dev)) {
2440+ if (!ata_dev_is_zoned(dev)) {
24072441 ata_scsi_set_invalid_field(dev, cmd, 2, 0xff);
24082442 return 0;
24092443 }
@@ -2934,7 +2968,7 @@ static unsigned int ata_scsiop_read_cap(struct ata_device *dev, · 524 unmodified lines
29342968 rbuf[10] = sector_size >> (8 * 1);
29352969 rbuf[11] = sector_size;
29362970
2937− if (ata_id_zoned_cap(dev->id) || dev->class == ATA_DEV_ZAC)
2971+ if (ata_dev_is_zoned(dev))
29382972 rbuf[12] = (1 << 4); /* RC_BASIS */
29392973 rbuf[13] = log2_per_phys;
29402974 rbuf[14] = (lowest_aligned >> 8) & 0x3f;
@@ -3524,14 +3558,14 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) · 583 unmodified lines
35243558 /**
35253559 * ata_format_dsm_trim_descr() - SATL Write Same to DSM Trim
35263560 * @cmd: SCSI command being translated
3527− * @trmax: Maximum number of entries that will fit in sector_size bytes.
3561+ * @size: DSM TRIM payload size in bytes (a multiple of 512)
35283562 * @sector: Starting sector
35293563 * @count: Total Range of request in logical sectors
35303564 *
35313565 * Rewrite the WRITE SAME descriptor to be a DSM TRIM little-endian formatted
35323566 * descriptor.
35333567 *
3534− * Upto 64 entries of the format:
3568+ * The payload is a list of @size / 8 entries of the format:
35353569 * 63:48 Range Length
35363570 * 47:0 LBA
35373571 *
@@ -3540,39 +3574,45 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) · 2 unmodified lines
35403574 *
35413575 * NOTE: this is the same format as ADD LBA(S) TO NV CACHE PINNED SET
35423576 *
3543− * Return: Number of bytes copied into sglist.
3577+ * The descriptor is written straight into the WRITE SAME data-out buffer;
3578+ * ata_dsm_trim_pages() guarantees @size does not exceed that buffer (one
3579+ * logical block). An atomic sg_miter mapping is used so this works from the
3580+ * command submission path and, unlike page_address(), copes with a high
3581+ * memory payload.
3582+ *
3583+ * Return: Number of bytes written into the data-out buffer.
35443584 */
3545−static size_t ata_format_dsm_trim_descr(struct scsi_cmnd *cmd, u32 trmax,
3585+static size_t ata_format_dsm_trim_descr(struct scsi_cmnd *cmd, size_t size,
35463586 u64 sector, u32 count)
35473587 {
3548− struct scsi_device *sdp = cmd->device;
3549− size_t len = sdp->sector_size;
3550− size_t r;
3551− __le64 *buf;
3552− u32 i = 0;
3553− unsigned long flags;
3588+ struct sg_mapping_iter miter;
3589+ size_t offset = 0;
3590+
3591+ sg_miter_start(&miter, scsi_sglist(cmd), scsi_sg_count(cmd),
3592+ SG_MITER_TO_SG | SG_MITER_ATOMIC);
3593+ while (offset < size && sg_miter_next(&miter)) {
3594+ __le64 *buf = miter.addr;
3595+ size_t chunk = min_t(size_t, miter.length, size - offset);
3596+ unsigned int n = chunk / sizeof(__le64);
3597+ unsigned int i;
35543598
3555− WARN_ON(len > ATA_SCSI_RBUF_SIZE);
3599+ for (i = 0; i < n; i++) {
3600+ u64 entry = 0;
35563601
3557− if (len > ATA_SCSI_RBUF_SIZE)
3558− len = ATA_SCSI_RBUF_SIZE;
3602+ if (count) {
3603+ u32 rlen = min_t(u32, count, 0xffff);
35593604
3560− spin_lock_irqsave(&ata_scsi_rbuf_lock, flags);
3561− buf = ((void *)ata_scsi_rbuf);
3562− memset(buf, 0, len);
3563− while (i < trmax) {
3564− u64 entry = sector |
3565− ((u64)(count > 0xffff ? 0xffff : count) << 48);
3566− buf[i++] = __cpu_to_le64(entry);
3567− if (count <= 0xffff)
3568− break;
3569− count -= 0xffff;
3570− sector += 0xffff;
3605+ entry = sector | ((u64)rlen << 48);
3606+ sector += rlen;
3607+ count -= rlen;
3608+ }
3609+ buf[i] = cpu_to_le64(entry);
3610+ }
3611+ offset += n * sizeof(__le64);
35713612 }
3572− r = sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), buf, len);
3573− spin_unlock_irqrestore(&ata_scsi_rbuf_lock, flags);
3613+ sg_miter_stop(&miter);
35743614
3575− return r;
3615+ return offset;
35763616 }
35773617
35783618 /**
@@ -3590,14 +3630,13 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) · 11 unmodified lines
35903630 {
35913631 struct ata_taskfile *tf = &qc->tf;
35923632 struct scsi_cmnd *scmd = qc->scsicmd;
3593− struct scsi_device *sdp = scmd->device;
3594− size_t len = sdp->sector_size;
35953633 struct ata_device *dev = qc->dev;
35963634 const u8 *cdb = scmd->cmnd;
3635+ unsigned int max_pages = ata_dsm_trim_pages(dev);
3636+ unsigned int n_pages;
3637+ size_t size;
35973638 u64 block;
35983639 u32 n_block;
3599− const u32 trmax = len >> 3;
3600− u32 size;
36013640 u16 fp;
36023641 u8 bp = 0xff;
36033642 u8 unmap = cdb[1] & 0x8;
@@ -3627,7 +3666,7 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) · 23 unmodified lines
36273666 goto invalid_fld;
36283667 }
36293668 /* If the request is too large the cmd is invalid */
3630− if (n_block > 0xffff * trmax) {
3669+ if (n_block > max_pages * ATA_MAX_TRIM_RNUM * (u64)U16_MAX) {
36313670 fp = 2;
36323671 goto invalid_fld;
36333672 }
@@ -3640,31 +3679,39 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) · 6 unmodified lines
36403679 goto invalid_param_len;
36413680
36423681 /*
3643− * size must match sector size in bytes
3644− * For DATA SET MANAGEMENT TRIM in ACS-2 nsect (aka count)
3645− * is defined as number of 512 byte blocks to be transferred.
3682+ * The DATA SET MANAGEMENT TRIM payload is a whole number of 512-byte
3683+ * pages (each holding up to ATA_MAX_TRIM_RNUM LBA Range Entries),
3684+ * independent of the logical sector size. Only use as many pages as
3685+ * are needed to describe the request, capped at max_pages.
36463686 */
3687+ n_pages = DIV_ROUND_UP(DIV_ROUND_UP(n_block, U16_MAX),
3688+ ATA_MAX_TRIM_RNUM);
3689+ n_pages = clamp(n_pages, 1U, max_pages);
3690+ size = (size_t)n_pages * ATA_SECT_SIZE;
36473691
3648− size = ata_format_dsm_trim_descr(scmd, trmax, block, n_block);
3649− if (size != len)
3692+ if (ata_format_dsm_trim_descr(scmd, size, block, n_block) != size)
36503693 goto invalid_param_len;
36513694
3695+ /*
3696+ * For DATA SET MANAGEMENT TRIM the COUNT field (aka nsect) is the
3697+ * number of 512-byte pages to be transferred.
3698+ */
36523699 if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) {
36533700 /* Newer devices support queued TRIM commands */
36543701 tf->protocol = ATA_PROT_NCQ;
36553702 tf->command = ATA_CMD_FPDMA_SEND;
36563703 tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f;
36573704 tf->nsect = qc->hw_tag << 3;
3658− tf->hob_feature = (size / 512) >> 8;
3659− tf->feature = size / 512;
3705+ tf->hob_feature = n_pages >> 8;
3706+ tf->feature = n_pages;
36603707
36613708 tf->auxiliary = 1;
36623709 } else {
36633710 tf->protocol = ATA_PROT_DMA;
36643711 tf->hob_feature = 0;
36653712 tf->feature = ATA_DSM_TRIM;
3666− tf->hob_nsect = (size / 512) >> 8;
3667− tf->nsect = size / 512;
3713+ tf->hob_nsect = n_pages >> 8;
3714+ tf->nsect = n_pages;
36683715 tf->command = ATA_CMD_DSM;
36693716 }
36703717
@@ -3672,6 +3719,12 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) · 1 unmodified line
36723719 ATA_TFLAG_WRITE;
36733720
36743721 ata_qc_set_pc_nbytes(qc);
3722+ /*
3723+ * The DSM TRIM payload (size) may be smaller than the WRITE SAME
3724+ * data-out buffer (one logical block); only transfer the pages that
3725+ * were actually built so the transfer length matches the COUNT field.
3726+ */
3727+ qc->nbytes = size;
36753728
36763729 return 0;
36773730
@@ -3688,88 +3741,286 @@ invalid_opcode: · 10 unmodified lines
36883741 return 1;
36893742 }
36903743
3691−static unsigned int ata_scsi_report_supported_opcodes(struct ata_device *dev,
3692− struct scsi_cmnd *cmd,
3693− u8 *rbuf)
3744+struct ata_scsi_cmd {
3745+ u8 op;
3746+ u8 cdb_len;
3747+ bool sa_valid;
3748+ u16 sa;
3749+};
3750+
3751+/*
3752+ * Array of commands supported with translation or emulation, sorted in
3753+ * ascending opcode and service action order. All of these commands are
3754+ * processed either in ata_xlat_func() or in ata_scsi_simulate();
3755+ *
3756+ * Note: commands that are not fully supported may be left out of this array
3757+ * so that they are not reported as supported for passthrough but still
3758+ * available through the block layer. For now, this includes the following
3759+ * commands:
3760+ * - WRITE_SAME_16: ata_scsi_write_same_xlat() forbids passthrough commands
3761+ */
3762+static const struct ata_scsi_cmd ata_supported_cmds[] = {
3763+ { .op = TEST_UNIT_READY, .cdb_len = 6 },
3764+ { .op = REZERO_UNIT, .cdb_len = 6 },
3765+ { .op = REQUEST_SENSE, .cdb_len = 6 },
3766+ { .op = READ_6, .cdb_len = 6 },
3767+ { .op = WRITE_6, .cdb_len = 6 },
3768+ { .op = SEEK_6, .cdb_len = 6 },
3769+ { .op = INQUIRY, .cdb_len = 6 },
3770+ { .op = MODE_SELECT, .cdb_len = 6 },
3771+ { .op = MODE_SENSE, .cdb_len = 6 },
3772+ { .op = START_STOP, .cdb_len = 6 },
3773+ { .op = SEND_DIAGNOSTIC, .cdb_len = 6 },
3774+ { .op = READ_CAPACITY, .cdb_len = 10 },
3775+ { .op = READ_10, .cdb_len = 10 },
3776+ { .op = WRITE_10, .cdb_len = 10 },
3777+ { .op = SEEK_10, .cdb_len = 10 },
3778+ { .op = VERIFY, .cdb_len = 10 },
3779+ { .op = SYNCHRONIZE_CACHE, .cdb_len = 10 },
3780+ { .op = MODE_SELECT_10, .cdb_len = 10 },
3781+ { .op = MODE_SENSE_10, .cdb_len = 10 },
3782+ {
3783+ .op = VARIABLE_LENGTH_CMD, .cdb_len = 32,
3784+ .sa_valid = true,
3785+ .sa = ATA_32
3786+ },
3787+ { .op = ATA_16, .cdb_len = 16 },
3788+ { .op = READ_16, .cdb_len = 16 },
3789+ { .op = WRITE_16, .cdb_len = 16 },
3790+ { .op = VERIFY_16, .cdb_len = 16 },
3791+ { .op = SYNCHRONIZE_CACHE_16, .cdb_len = 16 },
3792+ {
3793+ .op = ZBC_OUT, .cdb_len = 16,
3794+ .sa_valid = true,
3795+ .sa = ZO_CLOSE_ZONE
3796+ },
3797+ {
3798+ .op = ZBC_OUT, .cdb_len = 16,
3799+ .sa_valid = true,
3800+ .sa = ZO_FINISH_ZONE
3801+ },
3802+ {
3803+ .op = ZBC_OUT, .cdb_len = 16,
3804+ .sa_valid = true,
3805+ .sa = ZO_OPEN_ZONE
3806+ },
3807+ {
3808+ .op = ZBC_OUT, .cdb_len = 16,
3809+ .sa_valid = true,
3810+ .sa = ZO_RESET_WRITE_POINTER
3811+ },
3812+ {
3813+ .op = ZBC_IN, .cdb_len = 16,
3814+ .sa_valid = true,
3815+ .sa = ZI_REPORT_ZONES
3816+ },
3817+ {
3818+ .op = SERVICE_ACTION_IN_16, .cdb_len = 16,
3819+ .sa_valid = true,
3820+ .sa = SAI_READ_CAPACITY_16
3821+ },
3822+ {
3823+ .op = SERVICE_ACTION_IN_16, .cdb_len = 16,
3824+ .sa_valid = true,
3825+ .sa = SAI_GET_PHYSICAL_ELEMENT_STATUS
3826+ },
3827+ {
3828+ .op = SERVICE_ACTION_IN_16, .cdb_len = 16,
3829+ .sa_valid = true,
3830+ .sa = SAI_REMOVE_ELEMENT_AND_TRUNCATE
3831+ },
3832+ {
3833+ .op = SERVICE_ACTION_IN_16, .cdb_len = 16,
3834+ .sa_valid = true,
3835+ .sa = SAI_RESTORE_ELEMENTS_AND_REBUILD
3836+ },
3837+ {
3838+ .op = SERVICE_ACTION_IN_16, .cdb_len = 16,
3839+ .sa_valid = true,
3840+ .sa = SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES
3841+ },
3842+ { .op = REPORT_LUNS, .cdb_len = 12 },
3843+ { .op = ATA_12, .cdb_len = 12 },
3844+ { .op = SECURITY_PROTOCOL_IN, .cdb_len = 12 },
3845+ {
3846+ .op = MAINTENANCE_IN, .cdb_len = 12,
3847+ .sa_valid = true,
3848+ .sa = MI_REPORT_SUPPORTED_OPERATION_CODES
3849+ },
3850+ { .op = SECURITY_PROTOCOL_OUT, .cdb_len = 12 },
3851+};
3852+
3853+static const struct ata_scsi_cmd *ata_scsi_get_supported_cmd(u8 op, u16 sa)
36943854 {
3695− u8 *cdb = cmd->cmnd;
3696− u8 supported = 0, cdlp = 0, rwcdlp = 0;
3855+ const struct ata_scsi_cmd *cmd;
3856+ int i;
36973857
3698− if (cdb[2] != 1 && cdb[2] != 3) {
3699− ata_dev_warn(dev, "invalid command format %d\n", cdb[2]);
3700− ata_scsi_set_invalid_field(dev, cmd, 2, 0xff);
3701− return 0;
3858+ for (i = 0; i < ARRAY_SIZE(ata_supported_cmds); i++) {
3859+ cmd = &ata_supported_cmds[i];
3860+ if (cmd->op == op && cmd->sa == sa)
3861+ return cmd;
37023862 }
37033863
3704− switch (cdb[3]) {
3705− case INQUIRY:
3706− case MODE_SENSE:
3707− case MODE_SENSE_10:
3708− case READ_CAPACITY:
3709− case SERVICE_ACTION_IN_16:
3710− case REPORT_LUNS:
3711− case REQUEST_SENSE:
3712− case SYNCHRONIZE_CACHE:
3713− case SYNCHRONIZE_CACHE_16:
3714− case REZERO_UNIT:
3715− case SEEK_6:
3716− case SEEK_10:
3717− case TEST_UNIT_READY:
3718− case SEND_DIAGNOSTIC:
3719− case MAINTENANCE_IN:
3720− case READ_6:
3721− case READ_10:
3722− case WRITE_6:
3723− case WRITE_10:
3724− case ATA_12:
3725− case ATA_16:
3726− case VERIFY:
3727− case VERIFY_16:
3728− case MODE_SELECT:
3729− case MODE_SELECT_10:
3730− case START_STOP:
3731− supported = 3;
3732− break;
3864+ return NULL;
3865+}
3866+
3867+static bool ata_scsi_supported_cmd_use_sa(u8 op)
3868+{
3869+ const struct ata_scsi_cmd *cmd;
3870+ int i;
3871+
3872+ for (i = 0; i < ARRAY_SIZE(ata_supported_cmds); i++) {
3873+ cmd = &ata_supported_cmds[i];
3874+ if (cmd->op == op)
3875+ return cmd->sa_valid;
3876+ }
3877+
3878+ return false;
3879+}
3880+
3881+struct ata_scsi_cmd_support {
3882+ u8 cdlp;
3883+ u8 rwcdlp;
3884+};
3885+
3886+static bool ata_scsi_cmd_is_supported(struct ata_device *dev, u8 op, u16 sa,
3887+ struct ata_scsi_cmd_support *sup)
3888+{
3889+ const struct ata_scsi_cmd *cmd;
3890+
3891+ /* First, see if we support the command. */
3892+ cmd = ata_scsi_get_supported_cmd(op, sa);
3893+ if (!cmd)
3894+ return false;
3895+
3896+ /* Now refine the support report depending on the device features. */
3897+ memset(sup, 0, sizeof(*sup));
3898+ switch (op) {
37333899 case READ_16:
3734− supported = 3;
37353900 if (dev->flags & ATA_DFLAG_CDL) {
37363901 /*
37373902 * CDL read descriptors map to the T2A page, that is,
37383903 * rwcdlp = 0x01 and cdlp = 0x01
37393904 */
3740− rwcdlp = 0x01;
3741− cdlp = 0x01 << 3;
3905+ sup->rwcdlp = 0x01;
3906+ sup->cdlp = 0x01;
37423907 }
37433908 break;
37443909 case WRITE_16:
3745− supported = 3;
37463910 if (dev->flags & ATA_DFLAG_CDL) {
37473911 /*
37483912 * CDL write descriptors map to the T2B page, that is,
37493913 * rwcdlp = 0x01 and cdlp = 0x02
37503914 */
3751− rwcdlp = 0x01;
3752− cdlp = 0x02 << 3;
3915+ sup->rwcdlp = 0x01;
3916+ sup->cdlp = 0x02;
37533917 }
37543918 break;
37553919 case ZBC_IN:
37563920 case ZBC_OUT:
3757− if (ata_id_zoned_cap(dev->id) ||
3758− dev->class == ATA_DEV_ZAC)
3759− supported = 3;
3921+ return ata_dev_is_zoned(dev);
3922+ case SERVICE_ACTION_IN_16:
3923+ switch (sa) {
3924+ case SAI_GET_PHYSICAL_ELEMENT_STATUS:
3925+ case SAI_REMOVE_ELEMENT_AND_TRUNCATE:
3926+ return dev->flags & ATA_DFLAG_DEPOP;
3927+ case SAI_RESTORE_ELEMENTS_AND_REBUILD:
3928+ return dev->flags & ATA_DFLAG_DEPOP_RESTORE;
3929+ case SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES:
3930+ return dev->flags & ATA_DFLAG_DEPOP_MODIFY;
3931+ default:
3932+ return true;
3933+ }
37603934 break;
37613935 case SECURITY_PROTOCOL_IN:
37623936 case SECURITY_PROTOCOL_OUT:
3763− if (dev->flags & ATA_DFLAG_TRUSTED)
3764− supported = 3;
3765− break;
3937+ return dev->flags & ATA_DFLAG_TRUSTED;
37663938 default:
37673939 break;
37683940 }
37693941
3942+ return true;
3943+}
3944+
3945+static unsigned int
3946+ata_scsi_report_all_supported_opcodes(struct ata_device *dev, u8 *rbuf)
3947+{
3948+ struct ata_scsi_cmd_support sup;
3949+ const struct ata_scsi_cmd *cmd;
3950+ unsigned int len = 4;
3951+ u8 *buf = &rbuf[len];
3952+ int i;
3953+
3954+ for (i = 0; i < ARRAY_SIZE(ata_supported_cmds); i++) {
3955+ if (len > ATA_SCSI_RBUF_SIZE - 8)
3956+ break;
3957+
3958+ cmd = &ata_supported_cmds[i];
3959+
3960+ /* All command format */
3961+ if (!ata_scsi_cmd_is_supported(dev, cmd->op, cmd->sa, &sup))
3962+ continue;
3963+
3964+ buf[0] = cmd->op;
3965+ put_unaligned_be16(cmd->sa, &buf[2]);
3966+ buf[5] = (sup.rwcdlp << 6) | (sup.cdlp << 2);
3967+ if (cmd->sa_valid)
3968+ buf[5] |= 0x01;
3969+ put_unaligned_be16(cmd->cdb_len, &buf[6]);
3970+
3971+ /* CTDP == 0 */
3972+ len += 8;
3973+ buf += 8;
3974+ }
3975+
3976+ put_unaligned_be32(len - 4, &rbuf[0]);
3977+
3978+ return len;
3979+}
3980+
3981+static unsigned int ata_scsi_report_supported_opcodes(struct ata_device *dev,
3982+ struct scsi_cmnd *cmd,
3983+ u8 *rbuf)
3984+{
3985+ struct ata_scsi_cmd_support sup;
3986+ u8 *cdb = cmd->cmnd;
3987+ u16 sa = 0;
3988+
3989+ switch (cdb[2]) {
3990+ case 0:
3991+ /* All command format */
3992+ return ata_scsi_report_all_supported_opcodes(dev, rbuf);
3993+ case 1:
3994+ /* One command format with command support data, ignore sa. */
3995+ if (ata_scsi_supported_cmd_use_sa(cdb[3])) {
3996+ ata_scsi_set_invalid_field(dev, cmd, 3, 0xff);
3997+ return 0;
3998+ }
3999+ break;
4000+ case 2:
4001+ /* One command format, must have sa. */
4002+ if (!ata_scsi_supported_cmd_use_sa(cdb[3])) {
4003+ ata_scsi_set_invalid_field(dev, cmd, 3, 0xff);
4004+ return 0;
4005+ }
4006+ fallthrough;
4007+ case 3:
4008+ /* One command format */
4009+ sa = get_unaligned_be16(&cdb[4]);
4010+ break;
4011+ default:
4012+ ata_dev_warn(dev, "invalid command format %d\n", cdb[2]);
4013+ ata_scsi_set_invalid_field(dev, cmd, 2, 0xff);
4014+ return 0;
4015+ }
4016+
37704017 /* One command format */
3771− rbuf[0] = rwcdlp;
3772− rbuf[1] = cdlp | supported;
4018+ if (ata_scsi_cmd_is_supported(dev, cdb[3], sa, &sup)) {
4019+ rbuf[0] = sup.rwcdlp;
4020+ rbuf[1] = (sup.cdlp << 3) | 0x03;
4021+ } else {
4022+ rbuf[1] = 0x01;
4023+ }
37734024
37744025 return 4;
37754026 }
@@ -4452,6 +4703,245 @@ static unsigned int ata_scsi_security_inout_xlat(struct ata_queued_cmd *qc) · 676 unmodified lines
44524703 return 0;
44534704 }
44544705
4706+/*
4707+ * Convert T-13 little-endian field representation of GET PHYSICAL ELEMENT
4708+ * STATUS DMA command reply into T-10 big-endian field representation.
4709+ */
4710+static void ata_scsi_get_phys_element_status_complete(struct ata_queued_cmd *qc)
4711+{
4712+ struct scsi_cmnd *scmd = qc->scsicmd;
4713+ struct sg_mapping_iter miter;
4714+ unsigned int bytes = 0;
4715+
4716+ lockdep_assert_held(qc->ap->lock);
4717+
4718+ sg_miter_start(&miter, scsi_sglist(scmd), scsi_sg_count(scmd),
4719+ SG_MITER_TO_SG | SG_MITER_ATOMIC);
4720+
4721+ while (sg_miter_next(&miter)) {
4722+ unsigned int offset = 0;
4723+
4724+ if (bytes == 0) {
4725+ u32 num_desc, num_desc_returned, id;
4726+ u16 max_depop, cur_depop;
4727+ char *hdr;
4728+
4729+ /* Swizzle the header */
4730+ hdr = miter.addr;
4731+ num_desc = get_unaligned_le32(&hdr[0]);
4732+ num_desc_returned = get_unaligned_le32(&hdr[4]);
4733+ id = get_unaligned_le32(&hdr[8]);
4734+ max_depop = get_unaligned_le16(&hdr[12]);
4735+ cur_depop = get_unaligned_le16(&hdr[14]);
4736+
4737+ put_unaligned_be32(num_desc, &hdr[0]);
4738+ put_unaligned_be32(num_desc_returned, &hdr[4]);
4739+ put_unaligned_be32(id, &hdr[8]);
4740+ put_unaligned_be16(max_depop, &hdr[12]);
4741+ put_unaligned_be16(cur_depop, &hdr[14]);
4742+
4743+ offset += 32;
4744+ bytes += 32;
4745+ }
4746+
4747+ /* Swizzle the descriptors. */
4748+ while (offset < miter.length) {
4749+ char *desc;
4750+ u32 id;
4751+ u8 type;
4752+
4753+ desc = miter.addr + offset;
4754+ id = get_unaligned_le32(&desc[4]);
4755+ put_unaligned_be32(id, &desc[4]);
4756+
4757+ type = desc[14];
4758+ if (type == SCSI_PHYS_ELEM_TYPE_ALL_ACCESS_STORAGE) {
4759+ u64 capacity = get_unaligned_le64(&desc[16]);
4760+
4761+ put_unaligned_be64(capacity, &desc[16]);
4762+ } else {
4763+ u64 num_zones;
4764+
4765+ id = get_unaligned_le32(&desc[16]);
4766+ num_zones = get_unaligned_le64(&desc[24]);
4767+
4768+ put_unaligned_be32(id, &desc[16]);
4769+ put_unaligned_be64(num_zones, &desc[24]);
4770+ }
4771+
4772+ offset += 32;
4773+ bytes += 32;
4774+ }
4775+ }
4776+ sg_miter_stop(&miter);
4777+
4778+ ata_scsi_qc_complete(qc);
4779+}
4780+
4781+static unsigned int
4782+ata_scsi_get_phys_element_status_xlat(struct ata_queued_cmd *qc)
4783+{
4784+ struct scsi_cmnd *scmd = qc->scsicmd;
4785+ const u8 *cdb = scmd->cmnd;
4786+ struct ata_device *dev = qc->dev;
4787+ struct ata_taskfile *tf = &qc->tf;
4788+ u32 starting_element, len;
4789+
4790+ /* ATA_CMD_GET_PHYS_ELEMENT_STATUS is a DMA command. */
4791+ if (!(dev->flags & ATA_DFLAG_DEPOP) || !ata_dma_enabled(dev)) {
4792+ ata_scsi_set_sense(dev, scmd, ILLEGAL_REQUEST, 0x20, 0x0);
4793+ return 1;
4794+ }
4795+
4796+ len = get_unaligned_be32(&cdb[10]) / ATA_SECT_SIZE;
4797+ if (!len || len > U16_MAX) {
4798+ ata_scsi_set_invalid_field(dev, scmd, 10, 0);
4799+ return 1;
4800+ }
4801+
4802+ tf->protocol = ATA_PROT_DMA;
4803+ tf->command = ATA_CMD_GET_PHYS_ELEMENT_STATUS;
4804+ tf->hob_feature = cdb[14];
4805+ tf->hob_nsect = (len >> 8) & 0xff;
4806+ tf->nsect = len & 0xff;
4807+
4808+ starting_element = get_unaligned_be32(&cdb[6]);
4809+ if (starting_element) {
4810+ tf->hob_lbal = (starting_element >> 24) & 0xff;
4811+ tf->lbah = (starting_element >> 16) & 0xff;
4812+ tf->lbam = (starting_element >> 8) & 0xff;
4813+ tf->lbal = starting_element & 0xff;
4814+ }
4815+ tf->device = ATA_LBA;
4816+ tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
4817+
4818+ ata_qc_set_pc_nbytes(qc);
4819+
4820+ qc->flags |= ATA_QCFLAG_RESULT_TF;
4821+ qc->complete_fn = ata_scsi_get_phys_element_status_complete;
4822+
4823+ return 0;
4824+}
4825+
4826+static void ata_scsi_depop_ua_cap_changed_complete(struct ata_queued_cmd *qc)
4827+{
4828+ struct scsi_cmnd *scmd = qc->scsicmd;
4829+ u8 *cdb = scmd->cmnd;
4830+ bool is_ata_passthru = cdb[0] == ATA_16 || cdb[0] == ATA_12;
4831+ bool is_success = qc->err_mask == 0;
4832+
4833+ /*
4834+ * For successful non-passthrough commands, raise a UNIT ATTENTION with
4835+ * the additional sense code set to CAPACITY DATA HAS CHANGED to be
4836+ * raised. Note that this should be done only if the capacity has
4837+ * actually changed, which may not be the case if the element that was
4838+ * specified for depopulation was already depopulated, or we did not
4839+ * restore any removed element. But a capacity change unit attention is
4840+ * harmless, so always raise the unit attention.
4841+ */
4842+ if (is_success && !is_ata_passthru)
4843+ ata_scsi_set_sense(qc->dev, scmd, UNIT_ATTENTION,
4844+ UA_CHANGED_ASC, CAPACITY_CHANGED_ASCQ);
4845+ ata_scsi_qc_complete(qc);
4846+}
4847+
4848+static unsigned int
4849+ata_scsi_remove_element_and_truncate_xlat(struct ata_queued_cmd *qc)
4850+{
4851+ struct scsi_cmnd *scmd = qc->scsicmd;
4852+ const u8 *cdb = scmd->cmnd;
4853+ struct ata_device *dev = qc->dev;
4854+ struct ata_taskfile *tf = &qc->tf;
4855+ u64 req_capacity;
4856+ u32 id;
4857+
4858+ if (!(dev->flags & ATA_DFLAG_DEPOP)) {
4859+ ata_scsi_set_sense(dev, scmd, ILLEGAL_REQUEST, 0x20, 0x0);
4860+ return 1;
4861+ }
4862+
4863+ req_capacity = get_unaligned_be64(&cdb[2]);
4864+ if (req_capacity == 1) {
4865+ ata_scsi_set_invalid_field(dev, scmd, 2, 0);
4866+ return 1;
4867+ }
4868+
4869+ id = get_unaligned_be32(&cdb[10]);
4870+
4871+ tf->protocol = ATA_PROT_NODATA;
4872+ tf->command = ATA_CMD_REMOVE_ELEMENT_AND_TRUNCATE;
4873+ tf->hob_feature = (id >> 24) & 0xff;
4874+ tf->feature = (id >> 16) & 0xff;
4875+ tf->hob_nsect = (id >> 8) & 0xff;
4876+ tf->nsect = id & 0xff;
4877+ tf->hob_lbah = (req_capacity >> 40) & 0xff;
4878+ tf->hob_lbam = (req_capacity >> 32) & 0xff;
4879+ tf->hob_lbal = (req_capacity >> 24) & 0xff;
4880+ tf->lbah = (req_capacity >> 16) & 0xff;
4881+ tf->lbam = (req_capacity >> 8) & 0xff;
4882+ tf->lbal = req_capacity & 0xff;
4883+ tf->device = ATA_LBA;
4884+ tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
4885+
4886+ qc->flags |= ATA_QCFLAG_RESULT_TF;
4887+ qc->complete_fn = ata_scsi_depop_ua_cap_changed_complete;
4888+
4889+ return 0;
4890+}
4891+
4892+static unsigned int
4893+ata_scsi_remove_element_and_modify_zones_xlat(struct ata_queued_cmd *qc)
4894+{
4895+ struct scsi_cmnd *scmd = qc->scsicmd;
4896+ const u8 *cdb = scmd->cmnd;
4897+ struct ata_device *dev = qc->dev;
4898+ struct ata_taskfile *tf = &qc->tf;
4899+ u32 id;
4900+
4901+ if (!(dev->flags & ATA_DFLAG_DEPOP_MODIFY)) {
4902+ ata_scsi_set_sense(dev, scmd, ILLEGAL_REQUEST, 0x20, 0x0);
4903+ return 1;
4904+ }
4905+
4906+ id = get_unaligned_be32(&cdb[10]);
4907+
4908+ tf->protocol = ATA_PROT_NODATA;
4909+ tf->command = ATA_CMD_REMOVE_ELEMENT_AND_MODIFY_ZONES;
4910+ tf->hob_feature = (id >> 24) & 0xff;
4911+ tf->feature = (id >> 16) & 0xff;
4912+ tf->hob_nsect = (id >> 8) & 0xff;
4913+ tf->nsect = id & 0xff;
4914+ tf->device = ATA_LBA;
4915+ tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
4916+
4917+ qc->flags |= ATA_QCFLAG_RESULT_TF;
4918+
4919+ return 0;
4920+}
4921+
4922+static unsigned int
4923+ata_scsi_restore_elements_and_rebuild_xlat(struct ata_queued_cmd *qc)
4924+{
4925+ struct scsi_cmnd *scmd = qc->scsicmd;
4926+ struct ata_device *dev = qc->dev;
4927+ struct ata_taskfile *tf = &qc->tf;
4928+
4929+ if (!(dev->flags & ATA_DFLAG_DEPOP_RESTORE)) {
4930+ ata_scsi_set_sense(dev, scmd, ILLEGAL_REQUEST, 0x20, 0x0);
4931+ return 1;
4932+ }
4933+
4934+ tf->protocol = ATA_PROT_NODATA;
4935+ tf->command = ATA_CMD_RESTORE_ELEMENTS_AND_REBUILD;
4936+ tf->device = ATA_LBA;
4937+ tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
4938+
4939+ qc->flags |= ATA_QCFLAG_RESULT_TF;
4940+ qc->complete_fn = ata_scsi_depop_ua_cap_changed_complete;
4941+
4942+ return 0;
4943+}
4944+
44554945 /**
44564946 * ata_scsi_var_len_cdb_xlat - SATL variable length CDB to Handler
44574947 * @qc: Command to be translated
@@ -4483,7 +4973,7 @@ static unsigned int ata_scsi_var_len_cdb_xlat(struct ata_queued_cmd *qc) · 25 unmodified lines
44834973 /**
44844974 * ata_get_xlat_func - check if SCSI to ATA translation is possible
44854975 * @dev: ATA device
4486− * @cmd: SCSI command opcode to consider
4976+ * @cdb: CDB of the SCSI command to consider
44874977 *
44884978 * Look up the SCSI command given, and determine whether the
44894979 * SCSI command is to be translated or simulated.
@@ -4492,9 +4982,12 @@ static unsigned int ata_scsi_var_len_cdb_xlat(struct ata_queued_cmd *qc) · 2 unmodified lines
44924982 * Pointer to translation function if possible, %NULL if not.
44934983 */
44944984
4495−static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
4985+static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev,
4986+ u8 *cdb)
44964987 {
4497− switch (cmd) {
4988+ u8 sa;
4989+
4990+ switch (cdb[0]) {
44984991 case READ_6:
44994992 case READ_10:
45004993 case READ_16:
@@ -4528,6 +5021,18 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) · 27 unmodified lines
45285021 case MODE_SELECT_10:
45295022 return ata_scsi_mode_select_xlat;
45305023
5024+ case SERVICE_ACTION_IN_16:
5025+ sa = cdb[1] & 0x1f;
5026+ if (sa == SAI_GET_PHYSICAL_ELEMENT_STATUS)
5027+ return ata_scsi_get_phys_element_status_xlat;
5028+ if (sa == SAI_REMOVE_ELEMENT_AND_TRUNCATE)
5029+ return ata_scsi_remove_element_and_truncate_xlat;
5030+ if (sa == SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES)
5031+ return ata_scsi_remove_element_and_modify_zones_xlat;
5032+ if (sa == SAI_RESTORE_ELEMENTS_AND_REBUILD)
5033+ return ata_scsi_restore_elements_and_rebuild_xlat;
5034+ break;
5035+
45315036 case ZBC_IN:
45325037 return ata_scsi_zbc_in_xlat;
45335038
@@ -4625,7 +5130,8 @@ enum scsi_qc_status __ata_scsi_queuecmd(struct scsi_cmnd *scmd, · 91 unmodified lines
46255130 struct ata_port *ap)
46265131 __must_hold(ap->lock)
46275132 {
4628− u8 scsi_op = scmd->cmnd[0];
5133+ u8 *cdb = scmd->cmnd;
5134+ u8 scsi_op = cdb[0];
46295135 ata_xlat_func_t xlat_func;
46305136
46315137 /*
@@ -4645,7 +5151,7 @@ enum scsi_qc_status __ata_scsi_queuecmd(struct scsi_cmnd *scmd, · 13 unmodified lines
46455151 if (unlikely(scmd->cmd_len > dev->cdb_len))
46465152 goto bad_cdb_len;
46475153
4648− xlat_func = ata_get_xlat_func(dev, scsi_op);
5154+ xlat_func = ata_get_xlat_func(dev, cdb);
46495155 } else if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
46505156 /* relay SCSI command to ATAPI device */
46515157 int len = COMMAND_SIZE(scsi_op);
@@ -4661,7 +5167,7 @@ enum scsi_qc_status __ata_scsi_queuecmd(struct scsi_cmnd *scmd, · 9 unmodified lines
46615167 if (unlikely(scmd->cmd_len > 16))
46625168 goto bad_cdb_len;
46635169
4664− xlat_func = ata_get_xlat_func(dev, scsi_op);
5170+ xlat_func = ata_get_xlat_func(dev, cdb);
46655171 }
46665172
46675173 if (xlat_func)
drivers/ata/libata-sff.c+17−7
@@ -1114,8 +1114,14 @@ fsm_start: · 1113 unmodified lines
11141114
11151115 if (ap->hsm_task_state == HSM_ST_LAST &&
11161116 (!(qc->tf.flags & ATA_TFLAG_WRITE))) {
1117− /* all data read */
1118− status = ata_wait_idle(ap);
1117+ status = ata_sff_busy_wait(ap,
1118+ ATA_BUSY | ATA_DRQ, 10);
1119+ if (status != 0xff &&
1120+ (status & (ATA_BUSY | ATA_DRQ))) {
1121+ qc->tf.flags |= ATA_TFLAG_POLLING;
1122+ ata_sff_queue_pio_task(link, 0);
1123+ return 0;
1124+ }
11191125 goto fsm_start;
11201126 }
11211127 }
@@ -1213,7 +1219,7 @@ static void ata_sff_pio_task(struct work_struct *work) · 91 unmodified lines
12131219 container_of(work, struct ata_port, sff_pio_task.work);
12141220 struct ata_link *link = ap->sff_pio_task_link;
12151221 struct ata_queued_cmd *qc;
1216− u8 status;
1222+ u8 status, wait_mask;
12171223 int poll_next;
12181224
12191225 spin_lock_irq(ap->lock);
@@ -1229,6 +1235,10 @@ static void ata_sff_pio_task(struct work_struct *work) · 9 unmodified lines
12291235 fsm_start:
12301236 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE);
12311237
1238+ wait_mask = ATA_BUSY;
1239+ if (ap->hsm_task_state == HSM_ST_LAST)
1240+ wait_mask |= ATA_DRQ;
1241+
12321242 /*
12331243 * This is purely heuristic. This is a fast path.
12341244 * Sometimes when we enter, BSY will be cleared in
@@ -1236,14 +1246,14 @@ fsm_start: · 1 unmodified line
12361246 * or something. Snooze for a couple msecs, then
12371247 * chk-status again. If still busy, queue delayed work.
12381248 */
1239− status = ata_sff_busy_wait(ap, ATA_BUSY, 5);
1240− if (status & ATA_BUSY) {
1249+ status = ata_sff_busy_wait(ap, wait_mask, 5);
1250+ if (status & wait_mask) {
12411251 spin_unlock_irq(ap->lock);
12421252 ata_msleep(ap, 2);
12431253 spin_lock_irq(ap->lock);
12441254
1245− status = ata_sff_busy_wait(ap, ATA_BUSY, 10);
1246− if (status & ATA_BUSY) {
1255+ status = ata_sff_busy_wait(ap, wait_mask, 10);
1256+ if (status & wait_mask) {
12471257 ata_sff_queue_pio_task(link, ATA_SHORT_PAUSE);
12481258 goto out_unlock;
12491259 }
drivers/ata/libata.h+1−1
@@ -44,7 +44,7 @@ static inline bool ata_sstatus_online(u32 sstatus) · 43 unmodified lines
4444 return (sstatus & 0xf) == 0x3;
4545 }
4646
47−static inline bool ata_dev_is_zac(struct ata_device *dev)
47+static inline bool ata_dev_is_zoned(struct ata_device *dev)
4848 {
4949 /* Host managed device or host aware device */
5050 return dev->class == ATA_DEV_ZAC ||
drivers/ata/pata_ep93xx.c+21−9
@@ -656,14 +656,22 @@ static int ep93xx_pata_dma_init(struct ep93xx_pata_data *drv_data) · 655 unmodified lines
656656 * start of new transfer.
657657 */
658658 drv_data->dma_rx_channel = dma_request_chan(dev, "rx");
659− if (IS_ERR(drv_data->dma_rx_channel))
660− return dev_err_probe(dev, PTR_ERR(drv_data->dma_rx_channel),
661− "rx DMA setup failed\n");
659+ if (IS_ERR(drv_data->dma_rx_channel)) {
660+ ret = PTR_ERR(drv_data->dma_rx_channel);
661+ drv_data->dma_rx_channel = NULL;
662+ if (ret == -EPROBE_DEFER)
663+ return ret;
664+ dev_warn(dev, "rx DMA unavailable, using PIO\n");
665+ return 0;
666+ }
662667
663668 drv_data->dma_tx_channel = dma_request_chan(&pdev->dev, "tx");
664669 if (IS_ERR(drv_data->dma_tx_channel)) {
665− ret = dev_err_probe(dev, PTR_ERR(drv_data->dma_tx_channel),
666− "tx DMA setup failed\n");
670+ ret = PTR_ERR(drv_data->dma_tx_channel);
671+ drv_data->dma_tx_channel = NULL;
672+ if (ret == -EPROBE_DEFER)
673+ goto fail_release_rx;
674+ dev_warn(dev, "tx DMA unavailable, using PIO\n");
667675 goto fail_release_rx;
668676 }
669677
@@ -674,7 +682,7 @@ static int ep93xx_pata_dma_init(struct ep93xx_pata_data *drv_data) · 4 unmodified lines
674682 conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
675683 ret = dmaengine_slave_config(drv_data->dma_rx_channel, &conf);
676684 if (ret) {
677− dev_err_probe(dev, ret, "failed to configure rx dma channel");
685+ dev_warn(dev, "failed to configure rx dma channel, using PIO\n");
678686 goto fail_release_dma;
679687 }
680688
@@ -685,7 +693,7 @@ static int ep93xx_pata_dma_init(struct ep93xx_pata_data *drv_data) · 4 unmodified lines
685693 conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
686694 ret = dmaengine_slave_config(drv_data->dma_tx_channel, &conf);
687695 if (ret) {
688− dev_err_probe(dev, ret, "failed to configure tx dma channel");
696+ dev_warn(dev, "failed to configure tx dma channel, using PIO\n");
689697 goto fail_release_dma;
690698 }
691699
@@ -693,10 +701,14 @@ static int ep93xx_pata_dma_init(struct ep93xx_pata_data *drv_data) · 1 unmodified line
693701
694702 fail_release_rx:
695703 dma_release_channel(drv_data->dma_rx_channel);
704+ drv_data->dma_rx_channel = NULL;
705+ if (ret == -EPROBE_DEFER)
706+ return ret;
707+ return 0;
708+
696709 fail_release_dma:
697710 ep93xx_pata_release_dma(drv_data);
698−
699− return ret;
711+ return 0;
700712 }
701713
702714 static void ep93xx_pata_dma_start(struct ata_queued_cmd *qc)
drivers/ata/pata_mpc52xx.c+1−3
@@ -769,10 +769,8 @@ static int mpc52xx_ata_probe(struct platform_device *op) · 768 unmodified lines
769769 task_irq = bcom_get_task_irq(dmatsk);
770770 rv = devm_request_irq(&op->dev, task_irq, &mpc52xx_ata_task_irq, 0,
771771 "ATA task", priv);
772− if (rv) {
773− dev_err(&op->dev, "error requesting DMA IRQ\n");
772+ if (rv)
774773 goto err2;
775− }
776774 priv->dmatsk = dmatsk;
777775
778776 /* Init the hw */
drivers/ata/pata_pxa.c+10−42
@@ -161,8 +161,6 @@ static int pxa_ata_probe(struct platform_device *pdev) · 160 unmodified lines
161161 struct ata_host *host;
162162 struct ata_port *ap;
163163 struct pata_pxa_data *data;
164− struct resource *cmd_res;
165− struct resource *ctl_res;
166164 struct resource *dma_res;
167165 struct pata_pxa_pdata *pdata = dev_get_platdata(&pdev->dev);
168166 struct dma_slave_config config;
@@ -181,20 +179,6 @@ static int pxa_ata_probe(struct platform_device *pdev) · 12 unmodified lines
181179 return -EINVAL;
182180 }
183181
184− /*
185− * CMD port base address
186− */
187− cmd_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
188− if (unlikely(cmd_res == NULL))
189− return -EINVAL;
190−
191− /*
192− * CTL port base address
193− */
194− ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
195− if (unlikely(ctl_res == NULL))
196− return -EINVAL;
197−
198182 /*
199183 * DMA port base address
200184 */
@@ -221,14 +205,12 @@ static int pxa_ata_probe(struct platform_device *pdev) · 20 unmodified lines
221205 ap->pio_mask = ATA_PIO4;
222206 ap->mwdma_mask = ATA_MWDMA2;
223207
224− ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, cmd_res->start,
225− resource_size(cmd_res));
226− if (!ap->ioaddr.cmd_addr)
227− return -ENOMEM;
228− ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
229− resource_size(ctl_res));
230− if (!ap->ioaddr.ctl_addr)
231− return -ENOMEM;
208+ ap->ioaddr.cmd_addr = devm_platform_ioremap_resource(pdev, 0);
209+ if (IS_ERR(ap->ioaddr.cmd_addr))
210+ return PTR_ERR(ap->ioaddr.cmd_addr);
211+ ap->ioaddr.ctl_addr = devm_platform_ioremap_resource(pdev, 1);
212+ if (IS_ERR(ap->ioaddr.ctl_addr))
213+ return PTR_ERR(ap->ioaddr.ctl_addr);
232214 ap->ioaddr.bmdma_addr = devm_ioremap(&pdev->dev, dma_res->start,
233215 resource_size(dma_res));
234216 if (!ap->ioaddr.bmdma_addr)
@@ -280,40 +262,26 @@ static int pxa_ata_probe(struct platform_device *pdev) · 45 unmodified lines
280262 /*
281263 * Request the DMA channel
282264 */
283− data->dma_chan = dma_request_chan(&pdev->dev, "data");
265+ data->dma_chan = devm_dma_request_chan(&pdev->dev, "data");
284266 if (IS_ERR(data->dma_chan))
285267 return PTR_ERR(data->dma_chan);
268+
286269 ret = dmaengine_slave_config(data->dma_chan, &config);
287270 if (ret < 0) {
288271 dev_err(&pdev->dev, "dma configuration failed: %d\n", ret);
289− dma_release_channel(data->dma_chan);
290272 return ret;
291273 }
292274
293275 /*
294276 * Activate the ATA host
295277 */
296− ret = ata_host_activate(host, irq, ata_sff_interrupt,
278+ return ata_host_activate(host, irq, ata_sff_interrupt,
297279 pdata->irq_flags, &pxa_ata_sht);
298− if (ret)
299− dma_release_channel(data->dma_chan);
300−
301− return ret;
302−}
303−
304−static void pxa_ata_remove(struct platform_device *pdev)
305−{
306− struct ata_host *host = platform_get_drvdata(pdev);
307− struct pata_pxa_data *data = host->ports[0]->private_data;
308−
309− dma_release_channel(data->dma_chan);
310−
311− ata_host_detach(host);
312280 }
313281
314282 static struct platform_driver pxa_ata_driver = {
315283 .probe = pxa_ata_probe,
316− .remove = pxa_ata_remove,
284+ .remove = ata_platform_remove_one,
317285 .driver = {
318286 .name = DRV_NAME,
319287 },
drivers/ata/pata_rb532_cf.c+5−11
@@ -103,16 +103,14 @@ static int rb532_pata_driver_probe(struct platform_device *pdev) · 102 unmodified lines
103103 {
104104 int irq;
105105 struct gpio_desc *gpiod;
106− struct resource *res;
107106 struct ata_host *ah;
108107 struct rb532_cf_info *info;
108+ void __iomem *iobase;
109109 int ret;
110110
111− res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
112− if (!res) {
113− dev_err(&pdev->dev, "no IOMEM resource found\n");
114− return -EINVAL;
115− }
111+ iobase = devm_platform_ioremap_resource(pdev, 0);
112+ if (IS_ERR(iobase))
113+ return PTR_ERR(iobase);
116114
117115 irq = platform_get_irq(pdev, 0);
118116 if (irq < 0)
@@ -139,11 +137,7 @@ static int rb532_pata_driver_probe(struct platform_device *pdev) · 20 unmodified lines
139137 ah->private_data = info;
140138 info->gpio_line = gpiod;
141139 info->irq = irq;
142−
143− info->iobase = devm_ioremap(&pdev->dev, res->start,
144− resource_size(res));
145− if (!info->iobase)
146− return -ENOMEM;
140+ info->iobase = iobase;
147141
148142 rb532_pata_setup_ports(ah);
149143
drivers/ata/sata_highbank.c+5−13
@@ -455,7 +455,7 @@ static int ahci_highbank_probe(struct platform_device *pdev) · 454 unmodified lines
455455 struct ahci_host_priv *hpriv;
456456 struct ecx_plat_data *pdata;
457457 struct ata_host *host;
458− struct resource *mem;
458+ void __iomem *mmio;
459459 int irq;
460460 int i;
461461 int rc;
@@ -463,11 +463,9 @@ static int ahci_highbank_probe(struct platform_device *pdev) · 1 unmodified line
463463 struct ata_port_info pi = ahci_highbank_port_info;
464464 const struct ata_port_info *ppi[] = { &pi, NULL };
465465
466− mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
467− if (!mem) {
468− dev_err(dev, "no mmio space\n");
469− return -EINVAL;
470− }
466+ mmio = devm_platform_ioremap_resource(pdev, 0);
467+ if (IS_ERR(mmio))
468+ return PTR_ERR(mmio);
471469
472470 irq = platform_get_irq(pdev, 0);
473471 if (irq < 0)
@@ -488,12 +486,7 @@ static int ahci_highbank_probe(struct platform_device *pdev) · 14 unmodified lines
488486
489487 hpriv->irq = irq;
490488 hpriv->flags |= (unsigned long)pi.private_data;
491−
492− hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem));
493− if (!hpriv->mmio) {
494− dev_err(dev, "can't map %pR\n", mem);
495− return -ENOMEM;
496− }
489+ hpriv->mmio = mmio;
497490
498491 rc = highbank_initialize_phys(dev, hpriv->mmio);
499492 if (rc)
@@ -537,7 +530,6 @@ static int ahci_highbank_probe(struct platform_device *pdev) · 37 unmodified lines
537530 for (i = 0; i < host->n_ports; i++) {
538531 struct ata_port *ap = host->ports[i];
539532
540− ata_port_desc(ap, "mmio %pR", mem);
541533 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
542534
543535 /* set enclosure management message type */
drivers/ata/sata_mv.c+14−38
@@ -4054,17 +4054,13 @@ static int mv_platform_probe(struct platform_device *pdev) · 4053 unmodified lines
40544054 n_ports);
40554055 return -EINVAL;
40564056 }
4057−
4058− irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
40594057 } else {
40604058 mv_platform_data = dev_get_platdata(&pdev->dev);
40614059 n_ports = mv_platform_data->n_ports;
4062− irq = platform_get_irq(pdev, 0);
40634060 }
4061+ irq = platform_get_irq(pdev, 0);
40644062 if (irq < 0)
40654063 return irq;
4066− if (!irq)
4067− return -EINVAL;
40684064
40694065 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
40704066 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
@@ -4092,21 +4088,19 @@ static int mv_platform_probe(struct platform_device *pdev) · 21 unmodified lines
40924088
40934089 hpriv->base -= SATAHC0_REG_BASE;
40944090
4095− hpriv->clk = clk_get(&pdev->dev, NULL);
4096− if (IS_ERR(hpriv->clk)) {
4097− dev_notice(&pdev->dev, "cannot get optional clkdev\n");
4098− } else {
4099− rc = clk_prepare_enable(hpriv->clk);
4100− if (rc)
4101− goto err;
4102− }
4091+ hpriv->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
4092+ if (IS_ERR(hpriv->clk))
4093+ return PTR_ERR(hpriv->clk);
41034094
41044095 for (port = 0; port < n_ports; port++) {
41054096 char port_number[16];
41064097 sprintf(port_number, "%d", port);
4107− hpriv->port_clks[port] = clk_get(&pdev->dev, port_number);
4108− if (!IS_ERR(hpriv->port_clks[port]))
4109− clk_prepare_enable(hpriv->port_clks[port]);
4098+ hpriv->port_clks[port] = devm_clk_get_optional_enabled(&pdev->dev, port_number);
4099+ if (IS_ERR(hpriv->port_clks[port])) {
4100+ rc = PTR_ERR(hpriv->port_clks[port]);
4101+ hpriv->n_ports = port;
4102+ goto err;
4103+ }
41104104
41114105 sprintf(port_number, "port%d", port);
41124106 hpriv->port_phys[port] = devm_phy_optional_get(&pdev->dev,
@@ -4120,8 +4114,8 @@ static int mv_platform_probe(struct platform_device *pdev) · 7 unmodified lines
41204114 /* Cleanup only the initialized ports */
41214115 hpriv->n_ports = port;
41224116 goto err;
4123− } else
4124− phy_power_on(hpriv->port_phys[port]);
4117+ }
4118+ phy_power_on(hpriv->port_phys[port]);
41254119 }
41264120
41274121 /* All the ports have been initialized */
@@ -4160,17 +4154,8 @@ static int mv_platform_probe(struct platform_device *pdev) · 32 unmodified lines
41604154 return 0;
41614155
41624156 err:
4163− if (!IS_ERR(hpriv->clk)) {
4164− clk_disable_unprepare(hpriv->clk);
4165− clk_put(hpriv->clk);
4166− }
4167− for (port = 0; port < hpriv->n_ports; port++) {
4168− if (!IS_ERR(hpriv->port_clks[port])) {
4169− clk_disable_unprepare(hpriv->port_clks[port]);
4170− clk_put(hpriv->port_clks[port]);
4171− }
4157+ for (port = 0; port < hpriv->n_ports; port++)
41724158 phy_power_off(hpriv->port_phys[port]);
4173− }
41744159
41754160 return rc;
41764161 }
@@ -4190,17 +4175,8 @@ static void mv_platform_remove(struct platform_device *pdev) · 13 unmodified lines
41904175 int port;
41914176 ata_host_detach(host);
41924177
4193− if (!IS_ERR(hpriv->clk)) {
4194− clk_disable_unprepare(hpriv->clk);
4195− clk_put(hpriv->clk);
4196− }
4197− for (port = 0; port < host->n_ports; port++) {
4198− if (!IS_ERR(hpriv->port_clks[port])) {
4199− clk_disable_unprepare(hpriv->port_clks[port]);
4200− clk_put(hpriv->port_clks[port]);
4201− }
4178+ for (port = 0; port < host->n_ports; port++)
42024179 phy_power_off(hpriv->port_phys[port]);
4203− }
42044180 }
42054181
42064182 #ifdef CONFIG_PM_SLEEP
drivers/scsi/scsi_debug.c+0−46
@@ -67,52 +67,6 @@ static const char *sdebug_version_date = "20210520"; · 66 unmodified lines
6767
6868 #define MY_NAME "scsi_debug"
6969
70−/* Additional Sense Code (ASC) */
71−#define NO_ADDITIONAL_SENSE 0x0
72−#define OVERLAP_ATOMIC_COMMAND_ASC 0x0
73−#define OVERLAP_ATOMIC_COMMAND_ASCQ 0x23
74−#define FILEMARK_DETECTED_ASCQ 0x1
75−#define EOP_EOM_DETECTED_ASCQ 0x2
76−#define BEGINNING_OF_P_M_DETECTED_ASCQ 0x4
77−#define EOD_DETECTED_ASCQ 0x5
78−#define LOGICAL_UNIT_NOT_READY 0x4
79−#define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8
80−#define UNRECOVERED_READ_ERR 0x11
81−#define PARAMETER_LIST_LENGTH_ERR 0x1a
82−#define INVALID_OPCODE 0x20
83−#define LBA_OUT_OF_RANGE 0x21
84−#define INVALID_FIELD_IN_CDB 0x24
85−#define INVALID_FIELD_IN_PARAM_LIST 0x26
86−#define WRITE_PROTECTED 0x27
87−#define UA_READY_ASC 0x28
88−#define UA_RESET_ASC 0x29
89−#define UA_CHANGED_ASC 0x2a
90−#define TOO_MANY_IN_PARTITION_ASC 0x3b
91−#define TARGET_CHANGED_ASC 0x3f
92−#define LUNS_CHANGED_ASCQ 0x0e
93−#define INSUFF_RES_ASC 0x55
94−#define INSUFF_RES_ASCQ 0x3
95−#define POWER_ON_RESET_ASCQ 0x0
96−#define POWER_ON_OCCURRED_ASCQ 0x1
97−#define BUS_RESET_ASCQ 0x2 /* scsi bus reset occurred */
98−#define MODE_CHANGED_ASCQ 0x1 /* mode parameters changed */
99−#define CAPACITY_CHANGED_ASCQ 0x9
100−#define SAVING_PARAMS_UNSUP 0x39
101−#define TRANSPORT_PROBLEM 0x4b
102−#define THRESHOLD_EXCEEDED 0x5d
103−#define LOW_POWER_COND_ON 0x5e
104−#define MISCOMPARE_VERIFY_ASC 0x1d
105−#define MICROCODE_CHANGED_ASCQ 0x1 /* with TARGET_CHANGED_ASC */
106−#define MICROCODE_CHANGED_WO_RESET_ASCQ 0x16
107−#define WRITE_ERROR_ASC 0xc
108−#define UNALIGNED_WRITE_ASCQ 0x4
109−#define WRITE_BOUNDARY_ASCQ 0x5
110−#define READ_INVDATA_ASCQ 0x6
111−#define READ_BOUNDARY_ASCQ 0x7
112−#define ATTEMPT_ACCESS_GAP 0x9
113−#define INSUFF_ZONE_ASCQ 0xe
114−/* see drivers/scsi/sense_codes.h */
115−
11670 /* Additional Sense Code Qualifier (ASCQ) */
11771 #define ACK_NAK_TO 0x3
11872
include/linux/ata.h+17−0
@@ -75,6 +75,7 @@ enum { · 74 unmodified lines
7575 ATA_ID_HW_CONFIG = 93,
7676 ATA_ID_SPG = 98,
7777 ATA_ID_LBA_CAPACITY_2 = 100,
78+ ATA_ID_MAX_PAGES_PER_DSM = 105,
7879 ATA_ID_SECTOR_SIZE = 106,
7980 ATA_ID_WWN = 108,
8081 ATA_ID_LOGICAL_SECTOR_SIZE = 117, /* and 118 */
@@ -288,6 +289,10 @@ enum { · 207 unmodified lines
288289 ATA_CMD_SANITIZE_DEVICE = 0xB4,
289290 ATA_CMD_ZAC_MGMT_IN = 0x4A,
290291 ATA_CMD_ZAC_MGMT_OUT = 0x9F,
292+ ATA_CMD_GET_PHYS_ELEMENT_STATUS = 0x12,
293+ ATA_CMD_REMOVE_ELEMENT_AND_TRUNCATE = 0x7c,
294+ ATA_CMD_RESTORE_ELEMENTS_AND_REBUILD = 0x7d,
295+ ATA_CMD_REMOVE_ELEMENT_AND_MODIFY_ZONES = 0x7e,
291296
292297 /* marked obsolete in the ATA/ATAPI-7 spec */
293298 ATA_CMD_RESTORE = 0x10,
@@ -928,6 +933,18 @@ static inline bool ata_id_has_trim(const u16 *id) · 634 unmodified lines
928933 return false;
929934 }
930935
936+static inline u16 ata_id_dsm_max_pages(const u16 *id)
937+{
938+ /*
939+ * IDENTIFY DEVICE word 105: MAX PAGES PER DSM COMMAND. Maximum number
940+ * of 512-byte pages of LBA Range Entries the device accepts in a
941+ * single DATA SET MANAGEMENT command. Zero means the device does not
942+ * specify a limit. The field is reserved unless TRIM is supported, so
943+ * callers must gate on ata_id_has_trim().
944+ */
945+ return id[ATA_ID_MAX_PAGES_PER_DSM];
946+}
947+
931948 static inline bool ata_id_has_zero_after_trim(const u16 *id)
932949 {
933950 /* DSM supported, deterministic read, and read zero after trim set */
include/linux/libata.h+50−43
@@ -121,6 +121,55 @@ enum { · 120 unmodified lines
121121 ATA_QUIRK_NO_FUA = BIT_ULL(__ATA_QUIRK_NO_FUA),
122122 };
123123
124+/*
125+ * struct ata_device flags
126+ */
127+enum {
128+ ATA_DFLAG_LBA = (1UL << 0), /* device supports LBA */
129+ ATA_DFLAG_LBA48 = (1UL << 1), /* device supports LBA48 */
130+ ATA_DFLAG_CDB_INTR = (1UL << 2), /* device asserts INTRQ when ready for CDB */
131+ ATA_DFLAG_NCQ = (1UL << 3), /* device supports NCQ */
132+ ATA_DFLAG_FLUSH_EXT = (1UL << 4), /* do FLUSH_EXT instead of FLUSH */
133+ ATA_DFLAG_ACPI_PENDING = (1UL << 5), /* ACPI resume action pending */
134+ ATA_DFLAG_ACPI_FAILED = (1UL << 6), /* ACPI on devcfg has failed */
135+ ATA_DFLAG_AN = (1UL << 7), /* AN configured */
136+ ATA_DFLAG_TRUSTED = (1UL << 8), /* device supports trusted send/recv */
137+ ATA_DFLAG_FUA = (1UL << 9), /* device supports FUA */
138+ ATA_DFLAG_DMADIR = (1UL << 10), /* device requires DMADIR */
139+ ATA_DFLAG_NCQ_SEND_RECV = (1UL << 11), /* device supports NCQ SEND and RECV */
140+ ATA_DFLAG_NCQ_PRIO = (1UL << 12), /* device supports NCQ priority */
141+ ATA_DFLAG_CDL = (1UL << 13), /* supports cmd duration limits */
142+ ATA_DFLAG_DEPOP = (1UL << 14), /* supports depopulation capability */
143+ ATA_DFLAG_DEPOP_RESTORE = (1UL << 15), /* supports depopulation restoration */
144+ ATA_DFLAG_DEPOP_MODIFY = (1UL << 16), /* supports zoned depopulation */
145+ ATA_DFLAG_CFG_MASK = (1UL << 17) - 1,
146+
147+ ATA_DFLAG_PIO = (1UL << 17), /* device limited to PIO mode */
148+ ATA_DFLAG_NCQ_OFF = (1UL << 18), /* device limited to non-NCQ mode */
149+ ATA_DFLAG_SLEEPING = (1UL << 19), /* device is sleeping */
150+ ATA_DFLAG_DUBIOUS_XFER = (1UL << 20), /* data transfer not verified */
151+ ATA_DFLAG_NO_UNLOAD = (1UL << 21), /* device doesn't support unload */
152+ ATA_DFLAG_UNLOCK_HPA = (1UL << 22), /* unlock HPA */
153+ ATA_DFLAG_INIT_MASK = (1UL << 23) - 1,
154+
155+ ATA_DFLAG_NCQ_PRIO_ENABLED = (1UL << 23), /* Priority cmds sent to dev */
156+ ATA_DFLAG_CDL_ENABLED = (1UL << 24), /* cmd duration limits is enabled */
157+ ATA_DFLAG_RESUMING = (1UL << 25), /* Device is resuming */
158+ ATA_DFLAG_DETACH = (1UL << 26),
159+ ATA_DFLAG_DETACHED = (1UL << 27),
160+ ATA_DFLAG_DA = (1UL << 28), /* device supports Device Attention */
161+ ATA_DFLAG_DEVSLP = (1UL << 29), /* device supports Device Sleep */
162+ ATA_DFLAG_ACPI_DISABLED = (1UL << 30), /* ACPI for the device is disabled */
163+ ATA_DFLAG_D_SENSE = (1UL << 31), /* Descriptor sense requested */
164+
165+ ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \
166+ ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \
167+ ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA | \
168+ ATA_DFLAG_CDL | ATA_DFLAG_DEPOP | \
169+ ATA_DFLAG_DEPOP_RESTORE |
170+ ATA_DFLAG_DEPOP_MODIFY)
171+};
172+
124173 enum {
125174 /* various global constants */
126175 LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
@@ -146,46 +195,7 @@ enum { · 19 unmodified lines
146195 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
147196 ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
148197
149− /* struct ata_device stuff */
150− ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */
151− ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */
152− ATA_DFLAG_CDB_INTR = (1 << 2), /* device asserts INTRQ when ready for CDB */
153− ATA_DFLAG_NCQ = (1 << 3), /* device supports NCQ */
154− ATA_DFLAG_FLUSH_EXT = (1 << 4), /* do FLUSH_EXT instead of FLUSH */
155− ATA_DFLAG_ACPI_PENDING = (1 << 5), /* ACPI resume action pending */
156− ATA_DFLAG_ACPI_FAILED = (1 << 6), /* ACPI on devcfg has failed */
157− ATA_DFLAG_AN = (1 << 7), /* AN configured */
158− ATA_DFLAG_TRUSTED = (1 << 8), /* device supports trusted send/recv */
159− ATA_DFLAG_FUA = (1 << 9), /* device supports FUA */
160− ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */
161− ATA_DFLAG_NCQ_SEND_RECV = (1 << 11), /* device supports NCQ SEND and RECV */
162− ATA_DFLAG_NCQ_PRIO = (1 << 12), /* device supports NCQ priority */
163− ATA_DFLAG_CDL = (1 << 13), /* supports cmd duration limits */
164− ATA_DFLAG_CFG_MASK = (1 << 14) - 1,
165−
166− ATA_DFLAG_PIO = (1 << 14), /* device limited to PIO mode */
167− ATA_DFLAG_NCQ_OFF = (1 << 15), /* device limited to non-NCQ mode */
168− ATA_DFLAG_SLEEPING = (1 << 16), /* device is sleeping */
169− ATA_DFLAG_DUBIOUS_XFER = (1 << 17), /* data transfer not verified */
170− ATA_DFLAG_NO_UNLOAD = (1 << 18), /* device doesn't support unload */
171− ATA_DFLAG_UNLOCK_HPA = (1 << 19), /* unlock HPA */
172− ATA_DFLAG_INIT_MASK = (1 << 20) - 1,
173−
174− ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 20), /* Priority cmds sent to dev */
175− ATA_DFLAG_CDL_ENABLED = (1 << 21), /* cmd duration limits is enabled */
176− ATA_DFLAG_RESUMING = (1 << 22), /* Device is resuming */
177− ATA_DFLAG_DETACH = (1 << 24),
178− ATA_DFLAG_DETACHED = (1 << 25),
179− ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */
180− ATA_DFLAG_DEVSLP = (1 << 27), /* device supports Device Sleep */
181− ATA_DFLAG_ACPI_DISABLED = (1 << 28), /* ACPI for the device is disabled */
182− ATA_DFLAG_D_SENSE = (1 << 29), /* Descriptor sense requested */
183−
184− ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \
185− ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \
186− ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA | \
187− ATA_DFLAG_CDL),
188−
198+ /* sturct ata_device class. */
189199 ATA_DEV_UNKNOWN = 0, /* unknown device */
190200 ATA_DEV_ATA = 1, /* ATA device */
191201 ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */
@@ -1421,9 +1431,6 @@ extern int ata_port_freeze(struct ata_port *ap); · 1229 unmodified lines
14211431 extern void ata_eh_freeze_port(struct ata_port *ap);
14221432 extern void ata_eh_thaw_port(struct ata_port *ap);
14231433
1424−extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
1425−extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1426−
14271434 extern void ata_std_error_handler(struct ata_port *ap)
14281435 __must_hold(&ap->host->eh_mutex);
14291436 extern void ata_std_sched_eh(struct ata_port *ap);
include/scsi/scsi_proto.h+74−0
@@ -129,6 +129,10 @@ · 128 unmodified lines
129129 #define SAI_GET_LBA_STATUS 0x12
130130 #define SAI_REPORT_REFERRALS 0x13
131131 #define SAI_GET_STREAM_STATUS 0x16
132+#define SAI_GET_PHYSICAL_ELEMENT_STATUS 0x17
133+#define SAI_REMOVE_ELEMENT_AND_TRUNCATE 0x18
134+#define SAI_RESTORE_ELEMENTS_AND_REBUILD 0x19
135+#define SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES 0x1a
132136 /* values for maintenance in */
133137 #define MI_REPORT_IDENTIFYING_INFORMATION 0x05
134138 #define MI_REPORT_TARGET_PGS 0x0a
@@ -233,6 +237,57 @@ enum sam_status { · 98 unmodified lines
233237 #define MISCOMPARE 0x0e
234238 #define COMPLETED 0x0f
235239
240+/*
241+ * Additional Sense Codes (ASC).
242+ */
243+#define NO_ADDITIONAL_SENSE 0x00
244+#define OVERLAP_ATOMIC_COMMAND_ASC 0x00
245+#define LOGICAL_UNIT_NOT_READY 0x04
246+#define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8
247+#define WRITE_ERROR_ASC 0x0c
248+#define UNRECOVERED_READ_ERR 0x11
249+#define PARAMETER_LIST_LENGTH_ERR 0x1a
250+#define MISCOMPARE_VERIFY_ASC 0x1d
251+#define INVALID_OPCODE 0x20
252+#define LBA_OUT_OF_RANGE 0x21
253+#define INVALID_FIELD_IN_CDB 0x24
254+#define INVALID_FIELD_IN_PARAM_LIST 0x26
255+#define WRITE_PROTECTED 0x27
256+#define UA_READY_ASC 0x28
257+#define UA_RESET_ASC 0x29
258+#define UA_CHANGED_ASC 0x2a
259+#define TOO_MANY_IN_PARTITION_ASC 0x3b
260+#define TARGET_CHANGED_ASC 0x3f
261+#define SAVING_PARAMS_UNSUP 0x39
262+#define TRANSPORT_PROBLEM 0x4b
263+#define INSUFF_RES_ASC 0x55
264+#define LOW_POWER_COND_ON 0x5e
265+#define THRESHOLD_EXCEEDED 0x5d
266+
267+/*
268+ * Additional Sense Code Qualifiers (ASCQ).
269+ */
270+#define POWER_ON_RESET_ASCQ 0x00
271+#define MODE_CHANGED_ASCQ 0x01 /* mode parameters changed */
272+#define FILEMARK_DETECTED_ASCQ 0x01
273+#define POWER_ON_OCCURRED_ASCQ 0x01
274+#define MICROCODE_CHANGED_ASCQ 0x01 /* with TARGET_CHANGED_ASC */
275+#define BUS_RESET_ASCQ 0x02 /* scsi bus reset occurred */
276+#define EOP_EOM_DETECTED_ASCQ 0x02
277+#define INSUFF_RES_ASCQ 0x03
278+#define BEGINNING_OF_P_M_DETECTED_ASCQ 0x04
279+#define UNALIGNED_WRITE_ASCQ 0x04
280+#define EOD_DETECTED_ASCQ 0x05
281+#define WRITE_BOUNDARY_ASCQ 0x05
282+#define READ_INVDATA_ASCQ 0x06
283+#define READ_BOUNDARY_ASCQ 0x07
284+#define CAPACITY_CHANGED_ASCQ 0x09
285+#define ATTEMPT_ACCESS_GAP 0x09
286+#define LUNS_CHANGED_ASCQ 0x0e
287+#define INSUFF_ZONE_ASCQ 0x0e
288+#define MICROCODE_CHANGED_WO_RESET_ASCQ 0x16
289+#define OVERLAP_ATOMIC_COMMAND_ASCQ 0x23
290+
236291 /*
237292 * DEVICE TYPES
238293 * Please keep them in 0x%02x format for $MODALIAS to work
@@ -413,6 +468,25 @@ enum zbc_zone_alignment_method { · 174 unmodified lines
413468 ZBC_CONSTANT_ZONE_START_OFFSET = 0x8,
414469 };
415470
471+/* SCSI physical element types */
472+enum scsi_phys_element_type {
473+ SCSI_PHYS_ELEM_TYPE_ALL_ACCESS_STORAGE = 0x1,
474+ SCSI_PHYS_ELEM_TYPE_FRAC_ACCESS_STORAGE = 0x2,
475+};
476+
477+/* SCSI physical element health. */
478+enum scsi_phys_element_health {
479+ SCSI_PHYS_ELEM_HEALTH_NOT_REPORTED = 0x00,
480+ SCSI_PHYS_ELEM_HEALTH_WITHIN_SPEC_LIMITS = 0x01,
481+ SCSI_PHYS_ELEM_HEALTH_AT_SPEC_LIMITS = 0x64,
482+ SCSI_PHYS_ELEM_HEALTH_OUTSIDE_SPEC_LIMITS = 0x65,
483+ SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_ERR = 0xFB,
484+ SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_IN_PROGRESS = 0xFC,
485+ SCSI_PHYS_ELEM_HEALTH_DEPOP_ERR = 0xFD,
486+ SCSI_PHYS_ELEM_HEALTH_DEPOP_IN_PROGRESS = 0xFE,
487+ SCSI_PHYS_ELEM_HEALTH_DEPOP_OK = 0xFF,
488+};
489+
416490 /* Version descriptor values for INQUIRY */
417491 enum scsi_version_descriptor {
418492 SCSI_VERSION_DESCRIPTOR_FCP4 = 0x0a40,