From 7390896b3484d44cbdb8bc4859964314ac66d3c9 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Mon, 26 Sep 2022 20:53:06 +0000 Subject: ata: libata: fix NCQ autosense logic Currently, the logic if we should call ata_scsi_set_sense() (and set flag ATA_QCFLAG_SENSE_VALID to indicate that we have successfully added sense data to the struct ata_queued_cmd) looks like this: if (dev->class == ATA_DEV_ZAC && ((qc->result_tf.status & ATA_SENSE) || qc->result_tf.auxiliary)) The problem with this is that a drive can support the NCQ command error log without supporting NCQ autosense. On such a drive, if the failing command has sense data, the status field in the NCQ command error log will have the ATA_SENSE bit set. It is just that this sense data is not included in the NCQ command error log when NCQ autosense is not supported. Instead the sense data has to be fetched using the REQUEST SENSE DATA EXT command. Therefore, we should only add the sense data if the drive supports NCQ autosense AND the ATA_SENSE bit is set in the status field. Fix this, and at the same time, remove the duplicated ATA_DEV_ZAC check. The struct ata_taskfile supplied to ata_eh_read_log_10h() is memset:ed before calling the function, so simply checking if qc->result_tf.auxiliary is set is sufficient to tell us that the log actually contained sense data. Fixes: d238ffd59d3c ("libata: do not attempt to retrieve sense code twice") Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libata-sata.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index b6806d41a8c5..fd4dccc25389 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1392,7 +1392,8 @@ static int ata_eh_read_log_10h(struct ata_device *dev, tf->hob_lbah = buf[10]; tf->nsect = buf[12]; tf->hob_nsect = buf[13]; - if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id)) + if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id) && + (tf->status & ATA_SENSE)) tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16]; return 0; @@ -1456,8 +1457,12 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) memcpy(&qc->result_tf, &tf, sizeof(tf)); qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48; qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; - if (dev->class == ATA_DEV_ZAC && - ((qc->result_tf.status & ATA_SENSE) || qc->result_tf.auxiliary)) { + + /* + * If the device supports NCQ autosense, ata_eh_read_log_10h() will have + * stored the sense data in qc->result_tf.auxiliary. + */ + if (qc->result_tf.auxiliary) { char sense_key, asc, ascq; sense_key = (qc->result_tf.auxiliary >> 16) & 0xff; -- cgit v1.2.3 From 461ec040677127510d018c06e64d868e5e91be75 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Mon, 26 Sep 2022 20:53:06 +0000 Subject: ata: libata: clarify when ata_eh_request_sense() will be called ata_eh_request_sense() returns early when flag ATA_QCFLAG_SENSE_VALID is set. However, since the call to ata_eh_request_sense() is guarded by a ATA_SENSE bit conditional, the logical conclusion for the reader is that all checks are performed at the call site. Highlight the fact that the sense data will not be fetched if flag ATA_QCFLAG_SENSE_VALID is already set by adding an additional check to the existing guarding conditional. No functional change. Additionally, add a comment explaining that ata_eh_analyze_tf() will only fetch the sense data if: -It was a non-NCQ command that failed, or -It was a NCQ command that failed, but the sense data was not included in the NCQ command error log (i.e. NCQ autosense is not supported). Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libata-eh.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 08e11bc312c2..70022bf91493 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1575,7 +1575,14 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc) switch (qc->dev->class) { case ATA_DEV_ZAC: - if (stat & ATA_SENSE) + /* + * Fetch the sense data explicitly if: + * -It was a non-NCQ command that failed, or + * -It was a NCQ command that failed, but the sense data + * was not included in the NCQ command error log + * (i.e. NCQ autosense is not supported by the device). + */ + if (!(qc->flags & ATA_QCFLAG_SENSE_VALID) && (stat & ATA_SENSE)) ata_eh_request_sense(qc); fallthrough; case ATA_DEV_ATA: -- cgit v1.2.3 From 4b89ad8e5e1233bfe642e0185e34ad5e1cefb19e Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Mon, 26 Sep 2022 20:53:07 +0000 Subject: ata: libata: only set sense valid flag if sense data is valid While this shouldn't be needed if all devices that claim that they support NCQ autosense (ata_id_has_ncq_autosense()) and/or the sense data reporting feature (ata_id_has_sense_reporting()), actually supported those features. However, there might be some old ATA devices that either have these bits set, even when they don't support those features, or they simply return malformed data when using those features. These devices should be quirked, but in order to try to minimize the impact for the users of these such devices, it was suggested by Damien Le Moal that it might be a good idea to sanity check the sense data received from the device. If the sense data looks bogus, then the sense data is never added to the scsi_cmnd command. Introduce a new function, ata_scsi_sense_is_valid(), and use it in all places where sense data is received from the device. Suggested-by: Damien Le Moal Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libata-eh.c | 6 ++++-- drivers/ata/libata-sata.c | 11 +++++++---- drivers/ata/libata-scsi.c | 16 ++++++++++++++++ drivers/ata/libata.h | 1 + 4 files changed, 28 insertions(+), 6 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 70022bf91493..0444e1c91c43 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1428,8 +1428,10 @@ static void ata_eh_request_sense(struct ata_queued_cmd *qc) err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); /* Ignore err_mask; ATA_ERR might be set */ if (tf.status & ATA_SENSE) { - ata_scsi_set_sense(dev, cmd, tf.lbah, tf.lbam, tf.lbal); - qc->flags |= ATA_QCFLAG_SENSE_VALID; + if (ata_scsi_sense_is_valid(tf.lbah, tf.lbam, tf.lbal)) { + ata_scsi_set_sense(dev, cmd, tf.lbah, tf.lbam, tf.lbal); + qc->flags |= ATA_QCFLAG_SENSE_VALID; + } } else { ata_dev_warn(dev, "request sense failed stat %02x emask %x\n", tf.status, err_mask); diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index fd4dccc25389..d6bbdfe0c455 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1468,10 +1468,13 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) sense_key = (qc->result_tf.auxiliary >> 16) & 0xff; asc = (qc->result_tf.auxiliary >> 8) & 0xff; ascq = qc->result_tf.auxiliary & 0xff; - ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq); - ata_scsi_set_sense_information(dev, qc->scsicmd, - &qc->result_tf); - qc->flags |= ATA_QCFLAG_SENSE_VALID; + if (ata_scsi_sense_is_valid(sense_key, asc, ascq)) { + ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, + ascq); + ata_scsi_set_sense_information(dev, qc->scsicmd, + &qc->result_tf); + qc->flags |= ATA_QCFLAG_SENSE_VALID; + } } ehc->i.err_mask &= ~AC_ERR_DEV; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index e2ebb0b065e2..1287386fd029 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -188,6 +188,22 @@ DEVICE_ATTR(unload_heads, S_IRUGO | S_IWUSR, ata_scsi_park_show, ata_scsi_park_store); EXPORT_SYMBOL_GPL(dev_attr_unload_heads); +bool ata_scsi_sense_is_valid(u8 sk, u8 asc, u8 ascq) +{ + /* + * If sk == NO_SENSE, and asc + ascq == NO ADDITIONAL SENSE INFORMATION, + * then there is no sense data to add. + */ + if (sk == 0 && asc == 0 && ascq == 0) + return false; + + /* If sk > COMPLETED, sense data is bogus. */ + if (sk > COMPLETED) + return false; + + return true; +} + void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq) { diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 2c5c8273af01..2cd6124a01e8 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -114,6 +114,7 @@ extern int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht); extern void ata_scsi_scan_host(struct ata_port *ap, int sync); extern int ata_scsi_offline_dev(struct ata_device *dev); +extern bool ata_scsi_sense_is_valid(u8 sk, u8 asc, u8 ascq); extern void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq); extern void ata_scsi_set_sense_information(struct ata_device *dev, -- cgit v1.2.3 From 013115d90e007585bb85b45a5dc301ef1be62aab Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Mon, 26 Sep 2022 20:53:08 +0000 Subject: ata: libata: fetch sense data for ATA devices supporting sense reporting Currently, the sense data reporting feature set is enabled for all ATA devices which supports the feature set (ata_id_has_sense_reporting()), see ata_dev_config_sense_reporting(). However, even if sense data reporting is enabled, and the device indicates that sense data is available, the sense data is only fetched for ATA ZAC devices. For regular ATA devices, the available sense data is never fetched, it is simply ignored. Instead, libata will use the ERROR + STATUS fields and map them to a very generic and reduced set of sense data, see ata_gen_ata_sense() and ata_to_sense_error(). When sense data reporting was first implemented, regular ATA devices did fetch the sense data from the device. However, this was restricted to only ATA ZAC devices in commit ca156e006add ("libata: don't request sense data on !ZAC ATA devices"). With recent changes related to sense data and NCQ autosense, we want to, once again, fetch the sense data for all ATA devices supporting sense reporting. ata_gen_ata_sense() should only be used for devices that don't support the sense data reporting feature set. hopefully the features will be more robust this time around. It is not just ZAC, many new ATA features, e.g. Command Duration Limits, relies on working NCQ autosense and sense data. Therefore, it is not really an option to avoid fetching the sense data forever. If we encounter a device that is misbehaving because the sense data is actually fetched, then that device should be quirked such that it never enables the sense data reporting feature set in the first place, since such a device is obviously not compliant with the specification. The order in which we will try to add sense data to a scsi_cmnd: 1) NCQ autosense (if supported) - ata_eh_analyze_ncq_error() 2) REQUEST SENSE DATA EXT (if supported) - ata_eh_request_sense() 3) error + status field translation - ata_gen_ata_sense(), called by ata_scsi_qc_complete() if neither 1) or 2) is supported. Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libata-eh.c | 3 +-- drivers/ata/libata-sata.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 0444e1c91c43..b08d02afce86 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1576,6 +1576,7 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc) } switch (qc->dev->class) { + case ATA_DEV_ATA: case ATA_DEV_ZAC: /* * Fetch the sense data explicitly if: @@ -1586,8 +1587,6 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc) */ if (!(qc->flags & ATA_QCFLAG_SENSE_VALID) && (stat & ATA_SENSE)) ata_eh_request_sense(qc); - fallthrough; - case ATA_DEV_ATA: if (err & ATA_ICRC) qc->err_mask |= AC_ERR_ATA_BUS; if (err & (ATA_UNC | ATA_AMNF)) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index d6bbdfe0c455..9d3aee8ffa57 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1392,8 +1392,7 @@ static int ata_eh_read_log_10h(struct ata_device *dev, tf->hob_lbah = buf[10]; tf->nsect = buf[12]; tf->hob_nsect = buf[13]; - if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id) && - (tf->status & ATA_SENSE)) + if (ata_id_has_ncq_autosense(dev->id) && (tf->status & ATA_SENSE)) tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16]; return 0; -- cgit v1.2.3 From 4ba09d202657d2004859f4c05fa3272873ceb08f Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Mon, 3 Oct 2022 21:46:52 +0200 Subject: ata: libahci: read correct status and error field for NCQ commands Currently, for PIO commands, ahci_qc_fill_rtf() reads the status and error fields from the PIO Setup FIS area of the Received FIS Structure. For any non-PIO command, ahci_qc_fill_rtf() currently reads the status and error fields from the D2H Register FIS area of the Received FIS Structure. This is simply not correct. According to the SATA 3.5a specification: 11.10 DMA DATA-IN command protocol and 11.11 DMA DATA-OUT command protocol: READ DMA and WRITE DMA (non-NCQ commands) will end with the Send_status state, which transmits a Register D2H FIS. Likewise, in: 11.15 FPDMA QUEUED command protocol: READ FPDMA QUEUED and WRITE FPDMA QUEUED (NCQ commands) will end with the SendStatus state, which transmits a Set Device Bits FIS. So, for NCQ commands, there is never a D2H Register FIS sent. Reading the status and error fields from the D2H Register FIS area for a NCQ command, will result in us returning the status and error values for the last non-NCQ command, which is incorrect. Update ahci_qc_fill_rtf() to read the status and error fields from the correct area in the Received FIS Structure for NCQ commands. Once reason why this has not been detected before, could be because, in case of an NCQ error, ata_eh_analyze_ncq_error() will overwrite the (incorrect) status and error values set by ahci_qc_fill_rtf(). However, even successful NCQ commands can have bits set in the status field (e.g. the sense data available bit), so it is mandatory to read the status from the correct area also for NCQ commands. Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libahci.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 954386a2b500..96bef8007856 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2071,6 +2071,20 @@ static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc) !(qc->flags & ATA_QCFLAG_FAILED)) { ata_tf_from_fis(rx_fis + RX_FIS_PIO_SETUP, &qc->result_tf); qc->result_tf.status = (rx_fis + RX_FIS_PIO_SETUP)[15]; + + /* + * For NCQ commands, we never get a D2H FIS, so reading the D2H Register + * FIS area of the Received FIS Structure (which contains a copy of the + * last D2H FIS received) will contain an outdated status code. + * For NCQ commands, we instead get a SDB FIS, so read the SDB FIS area + * instead. However, the SDB FIS does not contain the LBA, so we can't + * use the ata_tf_from_fis() helper. + */ + } else if (ata_is_ncq(qc->tf.protocol)) { + const u8 *fis = rx_fis + RX_FIS_SDB; + + qc->result_tf.status = fis[2]; + qc->result_tf.error = fis[3]; } else ata_tf_from_fis(rx_fis + RX_FIS_D2H_REG, &qc->result_tf); -- cgit v1.2.3 From 1dea5edc90855cab8359b599128e3f322803cd09 Mon Sep 17 00:00:00 2001 From: Christophe Leroy Date: Thu, 6 Oct 2022 07:17:07 +0200 Subject: ata: pata_mpc52xx: Replace NO_IRQ with 0 NO_IRQ is used to check the return of irq_of_parse_and_map(). On some architecture NO_IRQ is 0, on other architectures it is -1. irq_of_parse_and_map() returns 0 on error, independent of NO_IRQ. So use 0 instead of using NO_IRQ. Signed-off-by: Christophe Leroy Reviewed-by: Sergey Shtylyov Signed-off-by: Damien Le Moal --- drivers/ata/pata_mpc52xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c index 6559b606736d..3ebd6522a1fd 100644 --- a/drivers/ata/pata_mpc52xx.c +++ b/drivers/ata/pata_mpc52xx.c @@ -731,7 +731,7 @@ static int mpc52xx_ata_probe(struct platform_device *op) udma_mask = ATA_UDMA2 & ((1 << (*prop + 1)) - 1); ata_irq = irq_of_parse_and_map(op->dev.of_node, 0); - if (ata_irq == NO_IRQ) { + if (!ata_irq) { dev_err(&op->dev, "error mapping irq\n"); return -EINVAL; } -- cgit v1.2.3 From 6c4c900b7397365c1c1559fce90a50f1937921ee Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Thu, 13 Oct 2022 17:30:34 +0900 Subject: ata: sata_gemini: Remove dependency on OF for compile tests If CONFIG_OF is disabled, then using the macro of_match_ptr() results in the gemini_sata_of_match variable being unused, which generates a compilation warning and a compilation error if CONFIG_WERROR is enabled. Removing the use of this macro by directly assigning the gemini_sata_of_match match table to the .of_match_table field in the platform driver definition allows removing the dependency on OF for compile tests, thus improving compile test coverage. Fixes: f7220eac752f ("ata: Kconfig: fix sata gemini compile test condition") Signed-off-by: Damien Le Moal Reviewed-by: Linus Walleij --- drivers/ata/Kconfig | 2 +- drivers/ata/sata_gemini.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index 36833a862998..37e065106baf 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig @@ -295,7 +295,7 @@ config SATA_FSL config SATA_GEMINI tristate "Gemini SATA bridge support" - depends on ARCH_GEMINI || (OF && COMPILE_TEST) + depends on ARCH_GEMINI || COMPILE_TEST select SATA_HOST default ARCH_GEMINI help diff --git a/drivers/ata/sata_gemini.c b/drivers/ata/sata_gemini.c index b729e9919bb0..c42cc9bbbc4e 100644 --- a/drivers/ata/sata_gemini.c +++ b/drivers/ata/sata_gemini.c @@ -421,7 +421,7 @@ static const struct of_device_id gemini_sata_of_match[] = { static struct platform_driver gemini_sata_driver = { .driver = { .name = DRV_NAME, - .of_match_table = of_match_ptr(gemini_sata_of_match), + .of_match_table = gemini_sata_of_match, }, .probe = gemini_sata_probe, .remove = gemini_sata_remove, -- cgit v1.2.3 From dc62c7e6ed5351058bbb57495e73fa6b3757587a Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 14 Oct 2022 11:39:27 +0900 Subject: ata: pata_ftide010: Remove build dependency on OF The pata_ftide010 can be built without CONFIG_OF being enabled, as long as the macro of_match_ptr() is not used when initializing the platform driver .of_match_table field. Remove the use of this macro and the build dependency on OF. Signed-off-by: Damien Le Moal Reviewed-by: Linus Walleij Reviewed-by: Sergey Shtylyov --- drivers/ata/Kconfig | 1 - drivers/ata/pata_ftide010.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index 37e065106baf..b30f71859154 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig @@ -696,7 +696,6 @@ config PATA_EP93XX config PATA_FTIDE010 tristate "Faraday Technology FTIDE010 PATA support" - depends on OF depends on ARM || COMPILE_TEST depends on SATA_GEMINI help diff --git a/drivers/ata/pata_ftide010.c b/drivers/ata/pata_ftide010.c index 0117df0fe3c5..88924b5daa1a 100644 --- a/drivers/ata/pata_ftide010.c +++ b/drivers/ata/pata_ftide010.c @@ -560,7 +560,7 @@ static const struct of_device_id pata_ftide010_of_match[] = { static struct platform_driver pata_ftide010_driver = { .driver = { .name = DRV_NAME, - .of_match_table = of_match_ptr(pata_ftide010_of_match), + .of_match_table = pata_ftide010_of_match, }, .probe = pata_ftide010_probe, .remove = pata_ftide010_remove, -- cgit v1.2.3 From 4cb7c6f1ef9642cd2c8580b495fde47ffbaddef7 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Fri, 7 Oct 2022 15:23:38 +0200 Subject: ata: make use of ata_port_is_frozen() helper Clean up the code by making use of the newly introduced ata_port_is_frozen() helper function. Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libahci.c | 6 +++--- drivers/ata/libata-acpi.c | 4 ++-- drivers/ata/libata-core.c | 4 ++-- drivers/ata/libata-eh.c | 21 ++++++++++----------- drivers/ata/libata-sata.c | 2 +- drivers/ata/libata-scsi.c | 2 +- drivers/ata/sata_nv.c | 2 +- drivers/ata/sata_promise.c | 2 +- drivers/ata/sata_sx4.c | 2 +- 9 files changed, 22 insertions(+), 23 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 96bef8007856..29acc35bf4a6 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2120,7 +2120,7 @@ void ahci_error_handler(struct ata_port *ap) { struct ahci_host_priv *hpriv = ap->host->private_data; - if (!(ap->pflags & ATA_PFLAG_FROZEN)) { + if (!ata_port_is_frozen(ap)) { /* restart engine */ hpriv->stop_engine(ap); hpriv->start_engine(ap); @@ -2311,7 +2311,7 @@ static void ahci_pmp_attach(struct ata_port *ap) * Note that during initialization, the port is marked as * frozen since the irq handler is not yet registered. */ - if (!(ap->pflags & ATA_PFLAG_FROZEN)) + if (!ata_port_is_frozen(ap)) writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK); } @@ -2330,7 +2330,7 @@ static void ahci_pmp_detach(struct ata_port *ap) pp->intr_mask &= ~PORT_IRQ_BAD_PMP; /* see comment above in ahci_pmp_attach() */ - if (!(ap->pflags & ATA_PFLAG_FROZEN)) + if (!ata_port_is_frozen(ap)) writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK); } diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c index 61b4ccf88bf1..d36e71f475ab 100644 --- a/drivers/ata/libata-acpi.c +++ b/drivers/ata/libata-acpi.c @@ -992,7 +992,7 @@ int ata_acpi_on_devcfg(struct ata_device *dev) acpi_err: /* ignore evaluation failure if we can continue safely */ - if (rc == -EINVAL && !nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) + if (rc == -EINVAL && !nr_executed && !ata_port_is_frozen(ap)) return 0; /* fail and let EH retry once more for unknown IO errors */ @@ -1007,7 +1007,7 @@ int ata_acpi_on_devcfg(struct ata_device *dev) /* We can safely continue if no _GTF command has been executed * and port is not frozen. */ - if (!nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) + if (!nr_executed && !ata_port_is_frozen(ap)) return 0; return rc; diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index d3ce5c383f3a..695a20dee1d1 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1489,7 +1489,7 @@ static unsigned ata_exec_internal_sg(struct ata_device *dev, spin_lock_irqsave(ap->lock, flags); /* no internal command while frozen */ - if (ap->pflags & ATA_PFLAG_FROZEN) { + if (ata_port_is_frozen(ap)) { spin_unlock_irqrestore(ap->lock, flags); return AC_ERR_SYSTEM; } @@ -4721,7 +4721,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc) return; } - WARN_ON_ONCE(ap->pflags & ATA_PFLAG_FROZEN); + WARN_ON_ONCE(ata_port_is_frozen(ap)); /* read result TF if requested */ if (qc->flags & ATA_QCFLAG_RESULT_TF) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index b08d02afce86..bde15f855f70 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1406,7 +1406,7 @@ static void ata_eh_request_sense(struct ata_queued_cmd *qc) struct ata_taskfile tf; unsigned int err_mask; - if (qc->ap->pflags & ATA_PFLAG_FROZEN) { + if (ata_port_is_frozen(qc->ap)) { ata_dev_warn(dev, "sense data available but port frozen\n"); return; } @@ -1596,7 +1596,7 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc) break; case ATA_DEV_ATAPI: - if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) { + if (!ata_port_is_frozen(qc->ap)) { tmp = atapi_eh_request_sense(qc->dev, qc->scsicmd->sense_buffer, qc->result_tf.error >> 4); @@ -2003,7 +2003,7 @@ static void ata_eh_link_autopsy(struct ata_link *link) ehc->i.flags |= ATA_EHI_QUIET; /* enforce default EH actions */ - if (ap->pflags & ATA_PFLAG_FROZEN || + if (ata_port_is_frozen(ap) || all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) ehc->i.action |= ATA_EH_RESET; else if (((eflags & ATA_EFLAG_IS_IO) && all_err_mask) || @@ -2246,7 +2246,7 @@ static void ata_eh_link_report(struct ata_link *link) return; frozen = ""; - if (ap->pflags & ATA_PFLAG_FROZEN) + if (ata_port_is_frozen(ap)) frozen = " frozen"; if (ap->eh_tries < ATA_EH_MAX_TRIES) @@ -2567,8 +2567,7 @@ int ata_eh_reset(struct ata_link *link, int classify, if (reset && !(ehc->i.action & ATA_EH_RESET)) { ata_for_each_dev(dev, link, ALL) classes[dev->devno] = ATA_DEV_NONE; - if ((ap->pflags & ATA_PFLAG_FROZEN) && - ata_is_host_link(link)) + if (ata_port_is_frozen(ap) && ata_is_host_link(link)) ata_eh_thaw_port(ap); rc = 0; goto out; @@ -2726,7 +2725,7 @@ int ata_eh_reset(struct ata_link *link, int classify, ap->pflags &= ~ATA_PFLAG_EH_PENDING; spin_unlock_irqrestore(link->ap->lock, flags); - if (ap->pflags & ATA_PFLAG_FROZEN) + if (ata_port_is_frozen(ap)) ata_eh_thaw_port(ap); /* @@ -3233,7 +3232,7 @@ static int ata_eh_maybe_retry_flush(struct ata_device *dev) if (err_mask & AC_ERR_DEV) { qc->err_mask |= AC_ERR_DEV; qc->result_tf = tf; - if (!(ap->pflags & ATA_PFLAG_FROZEN)) + if (!ata_port_is_frozen(ap)) rc = 0; } } @@ -3410,7 +3409,7 @@ static int ata_eh_skip_recovery(struct ata_link *link) return 1; /* thaw frozen port and recover failed devices */ - if ((ap->pflags & ATA_PFLAG_FROZEN) || ata_link_nr_enabled(link)) + if (ata_port_is_frozen(ap) || ata_link_nr_enabled(link)) return 0; /* reset at least once if reset is requested */ @@ -3765,7 +3764,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, if (dev) ata_eh_handle_dev_fail(dev, rc); - if (ap->pflags & ATA_PFLAG_FROZEN) { + if (ata_port_is_frozen(ap)) { /* PMP reset requires working host port. * Can't retry if it's frozen. */ @@ -3939,7 +3938,7 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap) ap->pflags &= ~ATA_PFLAG_PM_PENDING; if (rc == 0) ap->pflags |= ATA_PFLAG_SUSPENDED; - else if (ap->pflags & ATA_PFLAG_FROZEN) + else if (ata_port_is_frozen(ap)) ata_port_schedule_eh(ap); spin_unlock_irqrestore(ap->lock, flags); diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 9d3aee8ffa57..283ce1ab29cf 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1420,7 +1420,7 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) int tag, rc; /* if frozen, we can't do much */ - if (ap->pflags & ATA_PFLAG_FROZEN) + if (ata_port_is_frozen(ap)) return; /* is it NCQ device error? */ diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 1287386fd029..4cb914103382 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -658,7 +658,7 @@ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, struct ata_queued_cmd *qc; int tag; - if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) + if (unlikely(ata_port_is_frozen(ap))) goto fail; if (ap->flags & ATA_FLAG_SAS_HOST) { diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c index 7f14d0d31057..9b2d289e89e1 100644 --- a/drivers/ata/sata_nv.c +++ b/drivers/ata/sata_nv.c @@ -2185,7 +2185,7 @@ static void nv_swncq_host_interrupt(struct ata_port *ap, u16 fis) if (!fis) return; - if (ap->pflags & ATA_PFLAG_FROZEN) + if (ata_port_is_frozen(ap)) return; if (fis & NV_SWNCQ_IRQ_HOTPLUG) { diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c index b8465fef2ed2..9cd7d8b71361 100644 --- a/drivers/ata/sata_promise.c +++ b/drivers/ata/sata_promise.c @@ -817,7 +817,7 @@ static int pdc_sata_hardreset(struct ata_link *link, unsigned int *class, static void pdc_error_handler(struct ata_port *ap) { - if (!(ap->pflags & ATA_PFLAG_FROZEN)) + if (!ata_port_is_frozen(ap)) pdc_reset_port(ap); ata_sff_error_handler(ap); diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c index 6ceec59cb291..ab70cbc78f96 100644 --- a/drivers/ata/sata_sx4.c +++ b/drivers/ata/sata_sx4.c @@ -855,7 +855,7 @@ static int pdc_softreset(struct ata_link *link, unsigned int *class, static void pdc_error_handler(struct ata_port *ap) { - if (!(ap->pflags & ATA_PFLAG_FROZEN)) + if (!ata_port_is_frozen(ap)) pdc_reset_port(ap); ata_sff_error_handler(ap); -- cgit v1.2.3 From 5122e53ee784b9a2a2f40d34222751b6b4ab076c Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Fri, 7 Oct 2022 15:23:40 +0200 Subject: ata: libata-core: do not retry reading the log on timeout ata_read_log_page() first tries to read the log using READ LOG DMA EXT. If that fails it will instead try to read the log using READ LOG EXT. ata_exec_internal_sg() is synchronous, so it will wait for the command to finish. If we actually got an error back from the device, it is correct to retry. However, if the command timed out, ata_exec_internal_sg() will freeze the port. There is no point in retrying if the port is frozen, as ata_exec_internal_sg() will return AC_ERR_SYSTEM on a frozen port, without ever sending the command down to the drive. Therefore, avoid retrying if the first command froze the port, as that will result in a misleading AC_ERR_SYSTEM error print, instead of printing the error that actually caused the port to be frozen (AC_ERR_TIMEOUT). Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libata-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 695a20dee1d1..884ae73b11ea 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2000,7 +2000,8 @@ retry: if (err_mask) { if (dma) { dev->horkage |= ATA_HORKAGE_NO_DMA_LOG; - goto retry; + if (!ata_port_is_frozen(dev->link->ap)) + goto retry; } ata_dev_err(dev, "Read log 0x%02x page 0x%02x failed, Emask 0x%x\n", -- cgit v1.2.3 From 43c10618700b5880097c0e13a36c94766998e8eb Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Wed, 19 Oct 2022 17:29:37 +0200 Subject: ata: remove palmchip pata_bk3710 driver This device was used only on the davinci dm644x platform that is now gone, and no references to the device remain in the kernel. Signed-off-by: Arnd Bergmann Acked-by: Marc Zyngier Acked-by: Bartosz Golaszewski Reviewed-by: Sergey Shtylyov Signed-off-by: Damien Le Moal --- drivers/ata/Kconfig | 10 -- drivers/ata/Makefile | 1 - drivers/ata/pata_bk3710.c | 380 ---------------------------------------------- 3 files changed, 391 deletions(-) delete mode 100644 drivers/ata/pata_bk3710.c (limited to 'drivers/ata') diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index b30f71859154..eceaec33af65 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig @@ -609,16 +609,6 @@ config PATA_ATP867X If unsure, say N. -config PATA_BK3710 - tristate "Palmchip BK3710 PATA support" - depends on ARCH_DAVINCI || COMPILE_TEST - select PATA_TIMINGS - help - This option enables support for the integrated IDE controller on - the TI DaVinci SoC. - - If unsure, say N. - config PATA_CMD64X tristate "CMD64x PATA support" depends on PCI diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile index 34623365d9a6..d2e36d367274 100644 --- a/drivers/ata/Makefile +++ b/drivers/ata/Makefile @@ -54,7 +54,6 @@ obj-$(CONFIG_PATA_AMD) += pata_amd.o obj-$(CONFIG_PATA_ARTOP) += pata_artop.o obj-$(CONFIG_PATA_ATIIXP) += pata_atiixp.o obj-$(CONFIG_PATA_ATP867X) += pata_atp867x.o -obj-$(CONFIG_PATA_BK3710) += pata_bk3710.o obj-$(CONFIG_PATA_CMD64X) += pata_cmd64x.o obj-$(CONFIG_PATA_CS5520) += pata_cs5520.o obj-$(CONFIG_PATA_CS5530) += pata_cs5530.o diff --git a/drivers/ata/pata_bk3710.c b/drivers/ata/pata_bk3710.c deleted file mode 100644 index fad95cfecced..000000000000 --- a/drivers/ata/pata_bk3710.c +++ /dev/null @@ -1,380 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -/* - * Palmchip BK3710 PATA controller driver - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * http://www.samsung.com - * - * Based on palm_bk3710.c: - * - * Copyright (C) 2006 Texas Instruments. - * Copyright (C) 2007 MontaVista Software, Inc., - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRV_NAME "pata_bk3710" - -#define BK3710_TF_OFFSET 0x1F0 -#define BK3710_CTL_OFFSET 0x3F6 - -#define BK3710_BMISP 0x02 -#define BK3710_IDETIMP 0x40 -#define BK3710_UDMACTL 0x48 -#define BK3710_MISCCTL 0x50 -#define BK3710_REGSTB 0x54 -#define BK3710_REGRCVR 0x58 -#define BK3710_DATSTB 0x5C -#define BK3710_DATRCVR 0x60 -#define BK3710_DMASTB 0x64 -#define BK3710_DMARCVR 0x68 -#define BK3710_UDMASTB 0x6C -#define BK3710_UDMATRP 0x70 -#define BK3710_UDMAENV 0x74 -#define BK3710_IORDYTMP 0x78 - -static struct scsi_host_template pata_bk3710_sht = { - ATA_BMDMA_SHT(DRV_NAME), -}; - -static unsigned int ideclk_period; /* in nanoseconds */ - -struct pata_bk3710_udmatiming { - unsigned int rptime; /* tRP -- Ready to pause time (nsec) */ - unsigned int cycletime; /* tCYCTYP2/2 -- avg Cycle Time (nsec) */ - /* tENV is always a minimum of 20 nsec */ -}; - -static const struct pata_bk3710_udmatiming pata_bk3710_udmatimings[6] = { - { 160, 240 / 2 }, /* UDMA Mode 0 */ - { 125, 160 / 2 }, /* UDMA Mode 1 */ - { 100, 120 / 2 }, /* UDMA Mode 2 */ - { 100, 90 / 2 }, /* UDMA Mode 3 */ - { 100, 60 / 2 }, /* UDMA Mode 4 */ - { 85, 40 / 2 }, /* UDMA Mode 5 */ -}; - -static void pata_bk3710_setudmamode(void __iomem *base, unsigned int dev, - unsigned int mode) -{ - u32 val32; - u16 val16; - u8 tenv, trp, t0; - - /* DMA Data Setup */ - t0 = DIV_ROUND_UP(pata_bk3710_udmatimings[mode].cycletime, - ideclk_period) - 1; - tenv = DIV_ROUND_UP(20, ideclk_period) - 1; - trp = DIV_ROUND_UP(pata_bk3710_udmatimings[mode].rptime, - ideclk_period) - 1; - - /* udmastb Ultra DMA Access Strobe Width */ - val32 = ioread32(base + BK3710_UDMASTB) & (0xFF << (dev ? 0 : 8)); - val32 |= t0 << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_UDMASTB); - - /* udmatrp Ultra DMA Ready to Pause Time */ - val32 = ioread32(base + BK3710_UDMATRP) & (0xFF << (dev ? 0 : 8)); - val32 |= trp << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_UDMATRP); - - /* udmaenv Ultra DMA envelop Time */ - val32 = ioread32(base + BK3710_UDMAENV) & (0xFF << (dev ? 0 : 8)); - val32 |= tenv << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_UDMAENV); - - /* Enable UDMA for Device */ - val16 = ioread16(base + BK3710_UDMACTL) | (1 << dev); - iowrite16(val16, base + BK3710_UDMACTL); -} - -static void pata_bk3710_setmwdmamode(void __iomem *base, unsigned int dev, - unsigned short min_cycle, - unsigned int mode) -{ - const struct ata_timing *t; - int cycletime; - u32 val32; - u16 val16; - u8 td, tkw, t0; - - t = ata_timing_find_mode(mode); - cycletime = max_t(int, t->cycle, min_cycle); - - /* DMA Data Setup */ - t0 = DIV_ROUND_UP(cycletime, ideclk_period); - td = DIV_ROUND_UP(t->active, ideclk_period); - tkw = t0 - td - 1; - td--; - - val32 = ioread32(base + BK3710_DMASTB) & (0xFF << (dev ? 0 : 8)); - val32 |= td << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_DMASTB); - - val32 = ioread32(base + BK3710_DMARCVR) & (0xFF << (dev ? 0 : 8)); - val32 |= tkw << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_DMARCVR); - - /* Disable UDMA for Device */ - val16 = ioread16(base + BK3710_UDMACTL) & ~(1 << dev); - iowrite16(val16, base + BK3710_UDMACTL); -} - -static void pata_bk3710_set_dmamode(struct ata_port *ap, - struct ata_device *adev) -{ - void __iomem *base = (void __iomem *)ap->ioaddr.bmdma_addr; - int is_slave = adev->devno; - const u8 xferspeed = adev->dma_mode; - - if (xferspeed >= XFER_UDMA_0) - pata_bk3710_setudmamode(base, is_slave, - xferspeed - XFER_UDMA_0); - else - pata_bk3710_setmwdmamode(base, is_slave, - adev->id[ATA_ID_EIDE_DMA_MIN], - xferspeed); -} - -static void pata_bk3710_setpiomode(void __iomem *base, struct ata_device *pair, - unsigned int dev, unsigned int cycletime, - unsigned int mode) -{ - const struct ata_timing *t; - u32 val32; - u8 t2, t2i, t0; - - t = ata_timing_find_mode(XFER_PIO_0 + mode); - - /* PIO Data Setup */ - t0 = DIV_ROUND_UP(cycletime, ideclk_period); - t2 = DIV_ROUND_UP(t->active, ideclk_period); - - t2i = t0 - t2 - 1; - t2--; - - val32 = ioread32(base + BK3710_DATSTB) & (0xFF << (dev ? 0 : 8)); - val32 |= t2 << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_DATSTB); - - val32 = ioread32(base + BK3710_DATRCVR) & (0xFF << (dev ? 0 : 8)); - val32 |= t2i << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_DATRCVR); - - /* FIXME: this is broken also in the old driver */ - if (pair) { - u8 mode2 = pair->pio_mode - XFER_PIO_0; - - if (mode2 < mode) - mode = mode2; - } - - /* TASKFILE Setup */ - t0 = DIV_ROUND_UP(t->cyc8b, ideclk_period); - t2 = DIV_ROUND_UP(t->act8b, ideclk_period); - - t2i = t0 - t2 - 1; - t2--; - - val32 = ioread32(base + BK3710_REGSTB) & (0xFF << (dev ? 0 : 8)); - val32 |= t2 << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_REGSTB); - - val32 = ioread32(base + BK3710_REGRCVR) & (0xFF << (dev ? 0 : 8)); - val32 |= t2i << (dev ? 8 : 0); - iowrite32(val32, base + BK3710_REGRCVR); -} - -static void pata_bk3710_set_piomode(struct ata_port *ap, - struct ata_device *adev) -{ - void __iomem *base = (void __iomem *)ap->ioaddr.bmdma_addr; - struct ata_device *pair = ata_dev_pair(adev); - const struct ata_timing *t = ata_timing_find_mode(adev->pio_mode); - const u16 *id = adev->id; - unsigned int cycle_time = 0; - int is_slave = adev->devno; - const u8 pio = adev->pio_mode - XFER_PIO_0; - - if (id[ATA_ID_FIELD_VALID] & 2) { - if (ata_id_has_iordy(id)) - cycle_time = id[ATA_ID_EIDE_PIO_IORDY]; - else - cycle_time = id[ATA_ID_EIDE_PIO]; - - /* conservative "downgrade" for all pre-ATA2 drives */ - if (pio < 3 && cycle_time < t->cycle) - cycle_time = 0; /* use standard timing */ - } - - if (!cycle_time) - cycle_time = t->cycle; - - pata_bk3710_setpiomode(base, pair, is_slave, cycle_time, pio); -} - -static void pata_bk3710_chipinit(void __iomem *base) -{ - /* - * REVISIT: the ATA reset signal needs to be managed through a - * GPIO, which means it should come from platform_data. Until - * we get and use such information, we have to trust that things - * have been reset before we get here. - */ - - /* - * Program the IDETIMP Register Value based on the following assumptions - * - * (ATA_IDETIMP_IDEEN , ENABLE ) | - * (ATA_IDETIMP_PREPOST1 , DISABLE) | - * (ATA_IDETIMP_PREPOST0 , DISABLE) | - * - * DM6446 silicon rev 2.1 and earlier have no observed net benefit - * from enabling prefetch/postwrite. - */ - iowrite16(BIT(15), base + BK3710_IDETIMP); - - /* - * UDMACTL Ultra-ATA DMA Control - * (ATA_UDMACTL_UDMAP1 , 0 ) | - * (ATA_UDMACTL_UDMAP0 , 0 ) - * - */ - iowrite16(0, base + BK3710_UDMACTL); - - /* - * MISCCTL Miscellaneous Conrol Register - * (ATA_MISCCTL_HWNHLD1P , 1 cycle) - * (ATA_MISCCTL_HWNHLD0P , 1 cycle) - * (ATA_MISCCTL_TIMORIDE , 1) - */ - iowrite32(0x001, base + BK3710_MISCCTL); - - /* - * IORDYTMP IORDY Timer for Primary Register - * (ATA_IORDYTMP_IORDYTMP , DISABLE) - */ - iowrite32(0, base + BK3710_IORDYTMP); - - /* - * Configure BMISP Register - * (ATA_BMISP_DMAEN1 , DISABLE ) | - * (ATA_BMISP_DMAEN0 , DISABLE ) | - * (ATA_BMISP_IORDYINT , CLEAR) | - * (ATA_BMISP_INTRSTAT , CLEAR) | - * (ATA_BMISP_DMAERROR , CLEAR) - */ - iowrite16(0xE, base + BK3710_BMISP); - - pata_bk3710_setpiomode(base, NULL, 0, 600, 0); - pata_bk3710_setpiomode(base, NULL, 1, 600, 0); -} - -static struct ata_port_operations pata_bk3710_ports_ops = { - .inherits = &ata_bmdma_port_ops, - .cable_detect = ata_cable_80wire, - - .set_piomode = pata_bk3710_set_piomode, - .set_dmamode = pata_bk3710_set_dmamode, -}; - -static int __init pata_bk3710_probe(struct platform_device *pdev) -{ - struct clk *clk; - struct resource *mem; - struct ata_host *host; - struct ata_port *ap; - void __iomem *base; - unsigned long rate; - int irq; - - clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(clk)) - return -ENODEV; - - clk_enable(clk); - rate = clk_get_rate(clk); - if (!rate) - return -EINVAL; - - /* NOTE: round *down* to meet minimum timings; we count in clocks */ - ideclk_period = 1000000000UL / rate; - - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - - irq = platform_get_irq(pdev, 0); - if (irq < 0) { - pr_err(DRV_NAME ": failed to get IRQ resource\n"); - return irq; - } - - base = devm_ioremap_resource(&pdev->dev, mem); - if (IS_ERR(base)) - return PTR_ERR(base); - - /* configure the Palmchip controller */ - pata_bk3710_chipinit(base); - - /* allocate host */ - host = ata_host_alloc(&pdev->dev, 1); - if (!host) - return -ENOMEM; - ap = host->ports[0]; - - ap->ops = &pata_bk3710_ports_ops; - ap->pio_mask = ATA_PIO4; - ap->mwdma_mask = ATA_MWDMA2; - ap->udma_mask = rate < 100000000 ? ATA_UDMA4 : ATA_UDMA5; - ap->flags |= ATA_FLAG_SLAVE_POSS; - - ap->ioaddr.data_addr = base + BK3710_TF_OFFSET; - ap->ioaddr.error_addr = base + BK3710_TF_OFFSET + 1; - ap->ioaddr.feature_addr = base + BK3710_TF_OFFSET + 1; - ap->ioaddr.nsect_addr = base + BK3710_TF_OFFSET + 2; - ap->ioaddr.lbal_addr = base + BK3710_TF_OFFSET + 3; - ap->ioaddr.lbam_addr = base + BK3710_TF_OFFSET + 4; - ap->ioaddr.lbah_addr = base + BK3710_TF_OFFSET + 5; - ap->ioaddr.device_addr = base + BK3710_TF_OFFSET + 6; - ap->ioaddr.status_addr = base + BK3710_TF_OFFSET + 7; - ap->ioaddr.command_addr = base + BK3710_TF_OFFSET + 7; - - ap->ioaddr.altstatus_addr = base + BK3710_CTL_OFFSET; - ap->ioaddr.ctl_addr = base + BK3710_CTL_OFFSET; - - ap->ioaddr.bmdma_addr = base; - - ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", - (unsigned long)base + BK3710_TF_OFFSET, - (unsigned long)base + BK3710_CTL_OFFSET); - - /* activate */ - return ata_host_activate(host, irq, ata_sff_interrupt, 0, - &pata_bk3710_sht); -} - -/* work with hotplug and coldplug */ -MODULE_ALIAS("platform:palm_bk3710"); - -static struct platform_driver pata_bk3710_driver = { - .driver = { - .name = "palm_bk3710", - }, -}; - -static int __init pata_bk3710_init(void) -{ - return platform_driver_probe(&pata_bk3710_driver, pata_bk3710_probe); -} - -module_init(pata_bk3710_init); -MODULE_LICENSE("GPL v2"); -- cgit v1.2.3 From de58fd3d80f884f7f322a06bfe08465e49b47c5d Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Mon, 24 Oct 2022 15:17:59 +0100 Subject: ata: sata_dwc_460ex: remove variable num_processed Variable num_processed is just being incremented and it's never used anywhere else. The variable and the increment are redundant so remove it. Signed-off-by: Colin Ian King Signed-off-by: Damien Le Moal --- drivers/ata/sata_dwc_460ex.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c index e3263e961045..fd699c5bfc34 100644 --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c @@ -472,7 +472,7 @@ static irqreturn_t sata_dwc_isr(int irq, void *dev_instance) struct ata_queued_cmd *qc; unsigned long flags; u8 status, tag; - int handled, num_processed, port = 0; + int handled, port = 0; uint intpr, sactive, sactive2, tag_mask; struct sata_dwc_device_port *hsdevp; hsdev->sactive_issued = 0; @@ -618,9 +618,7 @@ DRVSTILLBUSY: dev_dbg(ap->dev, "%s ATA status register=0x%x\n", __func__, status); tag = 0; - num_processed = 0; while (tag_mask) { - num_processed++; while (!(tag_mask & 0x00000001)) { tag++; tag_mask <<= 1; -- cgit v1.2.3 From d5b560c014eddce747b2fd528d3071ded215b219 Mon Sep 17 00:00:00 2001 From: Sergey Shtylyov Date: Thu, 10 Nov 2022 00:47:42 +0300 Subject: ata: libata-sff: kill unused ata_sff_busy_sleep() Nobody seems to call ata_sff_busy_sleep(), so we can get rid of it... Signed-off-by: Sergey Shtylyov Signed-off-by: Damien Le Moal --- drivers/ata/libata-sff.c | 56 ------------------------------------------------ include/linux/libata.h | 2 -- 2 files changed, 58 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index 7916e369e15e..153f49e00713 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c @@ -184,62 +184,6 @@ void ata_sff_dma_pause(struct ata_port *ap) } EXPORT_SYMBOL_GPL(ata_sff_dma_pause); -/** - * ata_sff_busy_sleep - sleep until BSY clears, or timeout - * @ap: port containing status register to be polled - * @tmout_pat: impatience timeout in msecs - * @tmout: overall timeout in msecs - * - * Sleep until ATA Status register bit BSY clears, - * or a timeout occurs. - * - * LOCKING: - * Kernel thread context (may sleep). - * - * RETURNS: - * 0 on success, -errno otherwise. - */ -int ata_sff_busy_sleep(struct ata_port *ap, - unsigned long tmout_pat, unsigned long tmout) -{ - unsigned long timer_start, timeout; - u8 status; - - status = ata_sff_busy_wait(ap, ATA_BUSY, 300); - timer_start = jiffies; - timeout = ata_deadline(timer_start, tmout_pat); - while (status != 0xff && (status & ATA_BUSY) && - time_before(jiffies, timeout)) { - ata_msleep(ap, 50); - status = ata_sff_busy_wait(ap, ATA_BUSY, 3); - } - - if (status != 0xff && (status & ATA_BUSY)) - ata_port_warn(ap, - "port is slow to respond, please be patient (Status 0x%x)\n", - status); - - timeout = ata_deadline(timer_start, tmout); - while (status != 0xff && (status & ATA_BUSY) && - time_before(jiffies, timeout)) { - ata_msleep(ap, 50); - status = ap->ops->sff_check_status(ap); - } - - if (status == 0xff) - return -ENODEV; - - if (status & ATA_BUSY) { - ata_port_err(ap, - "port failed to respond (%lu secs, Status 0x%x)\n", - DIV_ROUND_UP(tmout, 1000), status); - return -EBUSY; - } - - return 0; -} -EXPORT_SYMBOL_GPL(ata_sff_busy_sleep); - static int ata_sff_check_ready(struct ata_link *link) { u8 status = link->ap->ops->sff_check_status(link->ap); diff --git a/include/linux/libata.h b/include/linux/libata.h index af4953b95f76..c9149ebe7423 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1918,8 +1918,6 @@ extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device); extern u8 ata_sff_check_status(struct ata_port *ap); extern void ata_sff_pause(struct ata_port *ap); extern void ata_sff_dma_pause(struct ata_port *ap); -extern int ata_sff_busy_sleep(struct ata_port *ap, - unsigned long timeout_pat, unsigned long timeout); extern int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline); extern void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf); extern void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf); -- cgit v1.2.3 From aebf1e26a84f2e38cf38aa228546adc2a2ede1fb Mon Sep 17 00:00:00 2001 From: Minghao Chi Date: Fri, 11 Nov 2022 16:47:12 +0800 Subject: ata: pata_ep93xx: use devm_platform_get_and_ioremap_resource() Convert platform_get_resource(), devm_ioremap_resource() to a single call to devm_platform_get_and_ioremap_resource(), as this is exactly what this function does. Reported-by: Zeal Robot Signed-off-by: Minghao Chi Reviewed-by: Sergey Shtylyov Signed-off-by: Damien Le Moal --- drivers/ata/pata_ep93xx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/pata_ep93xx.c b/drivers/ata/pata_ep93xx.c index 6c75a22db12b..47845d920075 100644 --- a/drivers/ata/pata_ep93xx.c +++ b/drivers/ata/pata_ep93xx.c @@ -931,8 +931,7 @@ static int ep93xx_pata_probe(struct platform_device *pdev) goto err_rel_gpio; } - mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - ide_base = devm_ioremap_resource(&pdev->dev, mem_res); + ide_base = devm_platform_get_and_ioremap_resource(pdev, 0, &mem_res); if (IS_ERR(ide_base)) { err = PTR_ERR(ide_base); goto err_rel_gpio; -- cgit v1.2.3 From 01a965d750508cacdfc8aa04e567cbb0692ce649 Mon Sep 17 00:00:00 2001 From: Christophe Leroy Date: Fri, 11 Nov 2022 09:30:46 +0100 Subject: ata: sata_dwc_460ex: Check !irq instead of irq == NO_IRQ NO_IRQ is a relic from the old days. It is not used anymore in core functions. By the way, function irq_of_parse_and_map() returns value 0 on error. In some drivers, NO_IRQ is erroneously used to check the return of irq_of_parse_and_map(). It is not a real bug today because the only architectures using the drivers being fixed by this patch define NO_IRQ as 0, but there are architectures which define NO_IRQ as -1. If one day those architectures start using the non fixed drivers, there will be a problem. Long time ago Linus advocated for not using NO_IRQ, see https://lkml.org/lkml/2005/11/21/221 . He re-iterated the same view recently in https://lkml.org/lkml/2022/10/12/622 So test !irq instead of tesing irq == NO_IRQ. And remove the fallback definition of NO_IRQ at the top of the file. Signed-off-by: Christophe Leroy Signed-off-by: Damien Le Moal --- drivers/ata/sata_dwc_460ex.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c index fd699c5bfc34..21d77633a98f 100644 --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c @@ -42,10 +42,6 @@ #define sata_dwc_writel(a, v) writel_relaxed(v, a) #define sata_dwc_readl(a) readl_relaxed(a) -#ifndef NO_IRQ -#define NO_IRQ 0 -#endif - #define AHB_DMA_BRST_DFLT 64 /* 16 data items burst length */ enum { @@ -242,7 +238,7 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev, /* Get SATA DMA interrupt number */ hsdev->dma->irq = irq_of_parse_and_map(np, 1); - if (hsdev->dma->irq == NO_IRQ) { + if (!hsdev->dma->irq) { dev_err(dev, "no SATA DMA irq\n"); return -ENODEV; } @@ -1178,7 +1174,7 @@ static int sata_dwc_probe(struct platform_device *ofdev) /* Get SATA interrupt number */ irq = irq_of_parse_and_map(np, 0); - if (irq == NO_IRQ) { + if (!irq) { dev_err(dev, "no SATA DMA irq\n"); return -ENODEV; } -- cgit v1.2.3 From 6c57e74e6e03211dddba55619bfb5ddc52cef89d Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Sun, 13 Nov 2022 21:33:57 +0100 Subject: ata: ahci: Remove linux/msi.h include Nothing in this file needs anything from linux/msi.h Signed-off-by: Thomas Gleixner Cc: Damien Le Moal Cc: linux-ide@vger.kernel.org Signed-off-by: Damien Le Moal --- drivers/ata/ahci.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 639de2d75d63..0cfd0ec6229b 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3 From 3d8a3ae3d9660acd432b853c5f91d99bdaa63a23 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Mon, 14 Nov 2022 18:21:59 +0100 Subject: ata: libata: fix commands incorrectly not getting retried during NCQ error A NCQ error means that the device has aborted processing of all active commands. To get the single NCQ command that caused the NCQ error, host software has to read the NCQ error log, which also takes the device out of error state. When the device encounters a NCQ error, we receive an error interrupt from the HBA, and call ata_do_link_abort() to mark all outstanding commands on the link as ATA_QCFLAG_FAILED (which means that these commands are owned by libata EH), and then call ata_qc_complete() on them. ata_qc_complete() will call fill_result_tf() for all commands marked as ATA_QCFLAG_FAILED. The taskfile is simply the latest status/error as seen from the device's perspective. The taskfile will have ATA_ERR set in the status field and ATA_ABORTED set in the error field. When we fill the current taskfile values for all outstanding commands, that means that qc->result_tf will have ATA_ERR set for all commands owned by libata EH. When ata_eh_link_autopsy() later analyzes all commands owned by libata EH, it will call ata_eh_analyze_tf(), which will check if qc->result_tf has ATA_ERR set, if it does, it will set qc->err_mask (which marks the command as an error). When ata_eh_finish() later calls __ata_qc_complete() on all commands owned by libata EH, it will call qc->complete_fn() (ata_scsi_qc_complete()), ata_scsi_qc_complete() will call ata_gen_ata_sense() to generate sense data if qc->err_mask is set. This means that we will generate sense data for commands that should not have any sense data set. Having sense data set for the non-failed commands will cause SCSI to finish these commands instead of retrying them. While this incorrect behavior has existed for a long time, this first became a problem once we started reading the correct taskfile register in commit 4ba09d202657 ("ata: libahci: read correct status and error field for NCQ commands"). Before this commit, NCQ commands would read the taskfile values received from the last non-NCQ command completion, which most likely did not have ATA_ERR set, since the last non-NCQ command was most likely not an error. Fix this by changing ata_eh_analyze_ncq_error() to mark all non-failed commands as ATA_QCFLAG_RETRY, and change the loop in ata_eh_link_autopsy() to skip commands marked as ATA_QCFLAG_RETRY. While at it, make sure that we clear ATA_ERR and any error bits for all commands except the actual command that caused the NCQ error, so that no other libata code will be able to misinterpret these commands as errors. Fixes: 4ba09d202657 ("ata: libahci: read correct status and error field for NCQ commands") Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libata-eh.c | 1 + drivers/ata/libata-sata.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index bde15f855f70..34303ce67c14 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1955,6 +1955,7 @@ static void ata_eh_link_autopsy(struct ata_link *link) ata_qc_for_each_raw(ap, qc, tag) { if (!(qc->flags & ATA_QCFLAG_FAILED) || + qc->flags & ATA_QCFLAG_RETRY || ata_dev_phys_link(qc->dev) != link) continue; diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 283ce1ab29cf..18ef14e749a0 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1476,6 +1476,33 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) } } + ata_qc_for_each_raw(ap, qc, tag) { + if (!(qc->flags & ATA_QCFLAG_FAILED) || + ata_dev_phys_link(qc->dev) != link) + continue; + + /* Skip the single QC which caused the NCQ error. */ + if (qc->err_mask) + continue; + + /* + * For SATA, the STATUS and ERROR fields are shared for all NCQ + * commands that were completed with the same SDB FIS. + * Therefore, we have to clear the ATA_ERR bit for all QCs + * except the one that caused the NCQ error. + */ + qc->result_tf.status &= ~ATA_ERR; + qc->result_tf.error = 0; + + /* + * If we get a NCQ error, that means that a single command was + * aborted. All other failed commands for our link should be + * retried and has no business of going though further scrutiny + * by ata_eh_link_autopsy(). + */ + qc->flags |= ATA_QCFLAG_RETRY; + } + ehc->i.err_mask &= ~AC_ERR_DEV; } EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error); -- cgit v1.2.3 From f07788079f515ca4a681c5f595bdad19cfbd7b1d Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Sat, 3 Dec 2022 11:54:25 +0100 Subject: ata: ahci: fix enum constants for gcc-13 gcc-13 slightly changes the type of constant expressions that are defined in an enum, which triggers a compile time sanity check in libata: linux/drivers/ata/libahci.c: In function 'ahci_led_store': linux/include/linux/compiler_types.h:357:45: error: call to '__compiletime_assert_302' declared with attribute error: BUILD_BUG_ON failed: sizeof(_s) > sizeof(long) 357 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) The new behavior is that sizeof() returns the same value for the constant as it does for the enum type, which is generally more sensible and consistent. The problem in libata is that it contains a single enum definition for lots of unrelated constants, some of which are large positive (unsigned) integers like 0xffffffff, while others like (1<<31) are interpreted as negative integers, and this forces the enum type to become 64 bit wide even though most constants would still fit into a signed 32-bit 'int'. Fix this by changing the entire enum definition to use BIT(x) in place of (1< Cc: linux-ide@vger.kernel.org Cc: Damien Le Moal Cc: stable@vger.kernel.org Cc: Randy Dunlap Signed-off-by: Arnd Bergmann Tested-by: Luis Machado Signed-off-by: Damien Le Moal --- drivers/ata/ahci.h | 245 +++++++++++++++++++++++++++-------------------------- 1 file changed, 123 insertions(+), 122 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index da7ee8bec165..4cec725cf30a 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -24,6 +24,7 @@ #include #include #include +#include /* Enclosure Management Control */ #define EM_CTRL_MSG_TYPE 0x000f0000 @@ -53,12 +54,12 @@ enum { AHCI_PORT_PRIV_FBS_DMA_SZ = AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_AR_SZ + (AHCI_RX_FIS_SZ * 16), - AHCI_IRQ_ON_SG = (1 << 31), - AHCI_CMD_ATAPI = (1 << 5), - AHCI_CMD_WRITE = (1 << 6), - AHCI_CMD_PREFETCH = (1 << 7), - AHCI_CMD_RESET = (1 << 8), - AHCI_CMD_CLR_BUSY = (1 << 10), + AHCI_IRQ_ON_SG = BIT(31), + AHCI_CMD_ATAPI = BIT(5), + AHCI_CMD_WRITE = BIT(6), + AHCI_CMD_PREFETCH = BIT(7), + AHCI_CMD_RESET = BIT(8), + AHCI_CMD_CLR_BUSY = BIT(10), RX_FIS_PIO_SETUP = 0x20, /* offset of PIO Setup FIS data */ RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ @@ -76,37 +77,37 @@ enum { HOST_CAP2 = 0x24, /* host capabilities, extended */ /* HOST_CTL bits */ - HOST_RESET = (1 << 0), /* reset controller; self-clear */ - HOST_IRQ_EN = (1 << 1), /* global IRQ enable */ - HOST_MRSM = (1 << 2), /* MSI Revert to Single Message */ - HOST_AHCI_EN = (1 << 31), /* AHCI enabled */ + HOST_RESET = BIT(0), /* reset controller; self-clear */ + HOST_IRQ_EN = BIT(1), /* global IRQ enable */ + HOST_MRSM = BIT(2), /* MSI Revert to Single Message */ + HOST_AHCI_EN = BIT(31), /* AHCI enabled */ /* HOST_CAP bits */ - HOST_CAP_SXS = (1 << 5), /* Supports External SATA */ - HOST_CAP_EMS = (1 << 6), /* Enclosure Management support */ - HOST_CAP_CCC = (1 << 7), /* Command Completion Coalescing */ - HOST_CAP_PART = (1 << 13), /* Partial state capable */ - HOST_CAP_SSC = (1 << 14), /* Slumber state capable */ - HOST_CAP_PIO_MULTI = (1 << 15), /* PIO multiple DRQ support */ - HOST_CAP_FBS = (1 << 16), /* FIS-based switching support */ - HOST_CAP_PMP = (1 << 17), /* Port Multiplier support */ - HOST_CAP_ONLY = (1 << 18), /* Supports AHCI mode only */ - HOST_CAP_CLO = (1 << 24), /* Command List Override support */ - HOST_CAP_LED = (1 << 25), /* Supports activity LED */ - HOST_CAP_ALPM = (1 << 26), /* Aggressive Link PM support */ - HOST_CAP_SSS = (1 << 27), /* Staggered Spin-up */ - HOST_CAP_MPS = (1 << 28), /* Mechanical presence switch */ - HOST_CAP_SNTF = (1 << 29), /* SNotification register */ - HOST_CAP_NCQ = (1 << 30), /* Native Command Queueing */ - HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ + HOST_CAP_SXS = BIT(5), /* Supports External SATA */ + HOST_CAP_EMS = BIT(6), /* Enclosure Management support */ + HOST_CAP_CCC = BIT(7), /* Command Completion Coalescing */ + HOST_CAP_PART = BIT(13), /* Partial state capable */ + HOST_CAP_SSC = BIT(14), /* Slumber state capable */ + HOST_CAP_PIO_MULTI = BIT(15), /* PIO multiple DRQ support */ + HOST_CAP_FBS = BIT(16), /* FIS-based switching support */ + HOST_CAP_PMP = BIT(17), /* Port Multiplier support */ + HOST_CAP_ONLY = BIT(18), /* Supports AHCI mode only */ + HOST_CAP_CLO = BIT(24), /* Command List Override support */ + HOST_CAP_LED = BIT(25), /* Supports activity LED */ + HOST_CAP_ALPM = BIT(26), /* Aggressive Link PM support */ + HOST_CAP_SSS = BIT(27), /* Staggered Spin-up */ + HOST_CAP_MPS = BIT(28), /* Mechanical presence switch */ + HOST_CAP_SNTF = BIT(29), /* SNotification register */ + HOST_CAP_NCQ = BIT(30), /* Native Command Queueing */ + HOST_CAP_64 = BIT(31), /* PCI DAC (64-bit DMA) support */ /* HOST_CAP2 bits */ - HOST_CAP2_BOH = (1 << 0), /* BIOS/OS handoff supported */ - HOST_CAP2_NVMHCI = (1 << 1), /* NVMHCI supported */ - HOST_CAP2_APST = (1 << 2), /* Automatic partial to slumber */ - HOST_CAP2_SDS = (1 << 3), /* Support device sleep */ - HOST_CAP2_SADM = (1 << 4), /* Support aggressive DevSlp */ - HOST_CAP2_DESO = (1 << 5), /* DevSlp from slumber only */ + HOST_CAP2_BOH = BIT(0), /* BIOS/OS handoff supported */ + HOST_CAP2_NVMHCI = BIT(1), /* NVMHCI supported */ + HOST_CAP2_APST = BIT(2), /* Automatic partial to slumber */ + HOST_CAP2_SDS = BIT(3), /* Support device sleep */ + HOST_CAP2_SADM = BIT(4), /* Support aggressive DevSlp */ + HOST_CAP2_DESO = BIT(5), /* DevSlp from slumber only */ /* registers for each SATA port */ PORT_LST_ADDR = 0x00, /* command list DMA addr */ @@ -128,24 +129,24 @@ enum { PORT_DEVSLP = 0x44, /* device sleep */ /* PORT_IRQ_{STAT,MASK} bits */ - PORT_IRQ_COLD_PRES = (1 << 31), /* cold presence detect */ - PORT_IRQ_TF_ERR = (1 << 30), /* task file error */ - PORT_IRQ_HBUS_ERR = (1 << 29), /* host bus fatal error */ - PORT_IRQ_HBUS_DATA_ERR = (1 << 28), /* host bus data error */ - PORT_IRQ_IF_ERR = (1 << 27), /* interface fatal error */ - PORT_IRQ_IF_NONFATAL = (1 << 26), /* interface non-fatal error */ - PORT_IRQ_OVERFLOW = (1 << 24), /* xfer exhausted available S/G */ - PORT_IRQ_BAD_PMP = (1 << 23), /* incorrect port multiplier */ - - PORT_IRQ_PHYRDY = (1 << 22), /* PhyRdy changed */ - PORT_IRQ_DMPS = (1 << 7), /* mechanical presence status */ - PORT_IRQ_CONNECT = (1 << 6), /* port connect change status */ - PORT_IRQ_SG_DONE = (1 << 5), /* descriptor processed */ - PORT_IRQ_UNK_FIS = (1 << 4), /* unknown FIS rx'd */ - PORT_IRQ_SDB_FIS = (1 << 3), /* Set Device Bits FIS rx'd */ - PORT_IRQ_DMAS_FIS = (1 << 2), /* DMA Setup FIS rx'd */ - PORT_IRQ_PIOS_FIS = (1 << 1), /* PIO Setup FIS rx'd */ - PORT_IRQ_D2H_REG_FIS = (1 << 0), /* D2H Register FIS rx'd */ + PORT_IRQ_COLD_PRES = BIT(31), /* cold presence detect */ + PORT_IRQ_TF_ERR = BIT(30), /* task file error */ + PORT_IRQ_HBUS_ERR = BIT(29), /* host bus fatal error */ + PORT_IRQ_HBUS_DATA_ERR = BIT(28), /* host bus data error */ + PORT_IRQ_IF_ERR = BIT(27), /* interface fatal error */ + PORT_IRQ_IF_NONFATAL = BIT(26), /* interface non-fatal error */ + PORT_IRQ_OVERFLOW = BIT(24), /* xfer exhausted available S/G */ + PORT_IRQ_BAD_PMP = BIT(23), /* incorrect port multiplier */ + + PORT_IRQ_PHYRDY = BIT(22), /* PhyRdy changed */ + PORT_IRQ_DMPS = BIT(7), /* mechanical presence status */ + PORT_IRQ_CONNECT = BIT(6), /* port connect change status */ + PORT_IRQ_SG_DONE = BIT(5), /* descriptor processed */ + PORT_IRQ_UNK_FIS = BIT(4), /* unknown FIS rx'd */ + PORT_IRQ_SDB_FIS = BIT(3), /* Set Device Bits FIS rx'd */ + PORT_IRQ_DMAS_FIS = BIT(2), /* DMA Setup FIS rx'd */ + PORT_IRQ_PIOS_FIS = BIT(1), /* PIO Setup FIS rx'd */ + PORT_IRQ_D2H_REG_FIS = BIT(0), /* D2H Register FIS rx'd */ PORT_IRQ_FREEZE = PORT_IRQ_HBUS_ERR | PORT_IRQ_IF_ERR | @@ -161,27 +162,27 @@ enum { PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS, /* PORT_CMD bits */ - PORT_CMD_ASP = (1 << 27), /* Aggressive Slumber/Partial */ - PORT_CMD_ALPE = (1 << 26), /* Aggressive Link PM enable */ - PORT_CMD_ATAPI = (1 << 24), /* Device is ATAPI */ - PORT_CMD_FBSCP = (1 << 22), /* FBS Capable Port */ - PORT_CMD_ESP = (1 << 21), /* External Sata Port */ - PORT_CMD_CPD = (1 << 20), /* Cold Presence Detection */ - PORT_CMD_MPSP = (1 << 19), /* Mechanical Presence Switch */ - PORT_CMD_HPCP = (1 << 18), /* HotPlug Capable Port */ - PORT_CMD_PMP = (1 << 17), /* PMP attached */ - PORT_CMD_LIST_ON = (1 << 15), /* cmd list DMA engine running */ - PORT_CMD_FIS_ON = (1 << 14), /* FIS DMA engine running */ - PORT_CMD_FIS_RX = (1 << 4), /* Enable FIS receive DMA engine */ - PORT_CMD_CLO = (1 << 3), /* Command list override */ - PORT_CMD_POWER_ON = (1 << 2), /* Power up device */ - PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */ - PORT_CMD_START = (1 << 0), /* Enable port DMA engine */ - - PORT_CMD_ICC_MASK = (0xf << 28), /* i/f ICC state mask */ - PORT_CMD_ICC_ACTIVE = (0x1 << 28), /* Put i/f in active state */ - PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */ - PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */ + PORT_CMD_ASP = BIT(27), /* Aggressive Slumber/Partial */ + PORT_CMD_ALPE = BIT(26), /* Aggressive Link PM enable */ + PORT_CMD_ATAPI = BIT(24), /* Device is ATAPI */ + PORT_CMD_FBSCP = BIT(22), /* FBS Capable Port */ + PORT_CMD_ESP = BIT(21), /* External Sata Port */ + PORT_CMD_CPD = BIT(20), /* Cold Presence Detection */ + PORT_CMD_MPSP = BIT(19), /* Mechanical Presence Switch */ + PORT_CMD_HPCP = BIT(18), /* HotPlug Capable Port */ + PORT_CMD_PMP = BIT(17), /* PMP attached */ + PORT_CMD_LIST_ON = BIT(15), /* cmd list DMA engine running */ + PORT_CMD_FIS_ON = BIT(14), /* FIS DMA engine running */ + PORT_CMD_FIS_RX = BIT(4), /* Enable FIS receive DMA engine */ + PORT_CMD_CLO = BIT(3), /* Command list override */ + PORT_CMD_POWER_ON = BIT(2), /* Power up device */ + PORT_CMD_SPIN_UP = BIT(1), /* Spin up device */ + PORT_CMD_START = BIT(0), /* Enable port DMA engine */ + + PORT_CMD_ICC_MASK = (0xfu << 28), /* i/f ICC state mask */ + PORT_CMD_ICC_ACTIVE = (0x1u << 28), /* Put i/f in active state */ + PORT_CMD_ICC_PARTIAL = (0x2u << 28), /* Put i/f in partial state */ + PORT_CMD_ICC_SLUMBER = (0x6u << 28), /* Put i/f in slumber state */ /* PORT_CMD capabilities mask */ PORT_CMD_CAP = PORT_CMD_HPCP | PORT_CMD_MPSP | @@ -192,9 +193,9 @@ enum { PORT_FBS_ADO_OFFSET = 12, /* FBS active dev optimization offset */ PORT_FBS_DEV_OFFSET = 8, /* FBS device to issue offset */ PORT_FBS_DEV_MASK = (0xf << PORT_FBS_DEV_OFFSET), /* FBS.DEV */ - PORT_FBS_SDE = (1 << 2), /* FBS single device error */ - PORT_FBS_DEC = (1 << 1), /* FBS device error clear */ - PORT_FBS_EN = (1 << 0), /* Enable FBS */ + PORT_FBS_SDE = BIT(2), /* FBS single device error */ + PORT_FBS_DEC = BIT(1), /* FBS device error clear */ + PORT_FBS_EN = BIT(0), /* Enable FBS */ /* PORT_DEVSLP bits */ PORT_DEVSLP_DM_OFFSET = 25, /* DITO multiplier offset */ @@ -202,50 +203,50 @@ enum { PORT_DEVSLP_DITO_OFFSET = 15, /* DITO offset */ PORT_DEVSLP_MDAT_OFFSET = 10, /* Minimum assertion time */ PORT_DEVSLP_DETO_OFFSET = 2, /* DevSlp exit timeout */ - PORT_DEVSLP_DSP = (1 << 1), /* DevSlp present */ - PORT_DEVSLP_ADSE = (1 << 0), /* Aggressive DevSlp enable */ + PORT_DEVSLP_DSP = BIT(1), /* DevSlp present */ + PORT_DEVSLP_ADSE = BIT(0), /* Aggressive DevSlp enable */ /* hpriv->flags bits */ #define AHCI_HFLAGS(flags) .private_data = (void *)(flags) - AHCI_HFLAG_NO_NCQ = (1 << 0), - AHCI_HFLAG_IGN_IRQ_IF_ERR = (1 << 1), /* ignore IRQ_IF_ERR */ - AHCI_HFLAG_IGN_SERR_INTERNAL = (1 << 2), /* ignore SERR_INTERNAL */ - AHCI_HFLAG_32BIT_ONLY = (1 << 3), /* force 32bit */ - AHCI_HFLAG_MV_PATA = (1 << 4), /* PATA port */ - AHCI_HFLAG_NO_MSI = (1 << 5), /* no PCI MSI */ - AHCI_HFLAG_NO_PMP = (1 << 6), /* no PMP */ - AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */ - AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */ - AHCI_HFLAG_NO_SUSPEND = (1 << 10), /* don't suspend */ - AHCI_HFLAG_SRST_TOUT_IS_OFFLINE = (1 << 11), /* treat SRST timeout as - link offline */ - AHCI_HFLAG_NO_SNTF = (1 << 12), /* no sntf */ - AHCI_HFLAG_NO_FPDMA_AA = (1 << 13), /* no FPDMA AA */ - AHCI_HFLAG_YES_FBS = (1 << 14), /* force FBS cap on */ - AHCI_HFLAG_DELAY_ENGINE = (1 << 15), /* do not start engine on - port start (wait until - error-handling stage) */ - AHCI_HFLAG_NO_DEVSLP = (1 << 17), /* no device sleep */ - AHCI_HFLAG_NO_FBS = (1 << 18), /* no FBS */ + AHCI_HFLAG_NO_NCQ = BIT(0), + AHCI_HFLAG_IGN_IRQ_IF_ERR = BIT(1), /* ignore IRQ_IF_ERR */ + AHCI_HFLAG_IGN_SERR_INTERNAL = BIT(2), /* ignore SERR_INTERNAL */ + AHCI_HFLAG_32BIT_ONLY = BIT(3), /* force 32bit */ + AHCI_HFLAG_MV_PATA = BIT(4), /* PATA port */ + AHCI_HFLAG_NO_MSI = BIT(5), /* no PCI MSI */ + AHCI_HFLAG_NO_PMP = BIT(6), /* no PMP */ + AHCI_HFLAG_SECT255 = BIT(8), /* max 255 sectors */ + AHCI_HFLAG_YES_NCQ = BIT(9), /* force NCQ cap on */ + AHCI_HFLAG_NO_SUSPEND = BIT(10), /* don't suspend */ + AHCI_HFLAG_SRST_TOUT_IS_OFFLINE = BIT(11), /* treat SRST timeout as + link offline */ + AHCI_HFLAG_NO_SNTF = BIT(12), /* no sntf */ + AHCI_HFLAG_NO_FPDMA_AA = BIT(13), /* no FPDMA AA */ + AHCI_HFLAG_YES_FBS = BIT(14), /* force FBS cap on */ + AHCI_HFLAG_DELAY_ENGINE = BIT(15), /* do not start engine on + port start (wait until + error-handling stage) */ + AHCI_HFLAG_NO_DEVSLP = BIT(17), /* no device sleep */ + AHCI_HFLAG_NO_FBS = BIT(18), /* no FBS */ #ifdef CONFIG_PCI_MSI - AHCI_HFLAG_MULTI_MSI = (1 << 20), /* per-port MSI(-X) */ + AHCI_HFLAG_MULTI_MSI = BIT(20), /* per-port MSI(-X) */ #else /* compile out MSI infrastructure */ AHCI_HFLAG_MULTI_MSI = 0, #endif - AHCI_HFLAG_WAKE_BEFORE_STOP = (1 << 22), /* wake before DMA stop */ - AHCI_HFLAG_YES_ALPM = (1 << 23), /* force ALPM cap on */ - AHCI_HFLAG_NO_WRITE_TO_RO = (1 << 24), /* don't write to read - only registers */ - AHCI_HFLAG_USE_LPM_POLICY = (1 << 25), /* chipset that should use - SATA_MOBILE_LPM_POLICY - as default lpm_policy */ - AHCI_HFLAG_SUSPEND_PHYS = (1 << 26), /* handle PHYs during - suspend/resume */ - AHCI_HFLAG_NO_SXS = (1 << 28), /* SXS not supported */ + AHCI_HFLAG_WAKE_BEFORE_STOP = BIT(22), /* wake before DMA stop */ + AHCI_HFLAG_YES_ALPM = BIT(23), /* force ALPM cap on */ + AHCI_HFLAG_NO_WRITE_TO_RO = BIT(24), /* don't write to read + only registers */ + AHCI_HFLAG_USE_LPM_POLICY = BIT(25), /* chipset that should use + SATA_MOBILE_LPM_POLICY + as default lpm_policy */ + AHCI_HFLAG_SUSPEND_PHYS = BIT(26), /* handle PHYs during + suspend/resume */ + AHCI_HFLAG_NO_SXS = BIT(28), /* SXS not supported */ /* ap->flags bits */ @@ -261,22 +262,22 @@ enum { EM_MAX_RETRY = 5, /* em_ctl bits */ - EM_CTL_RST = (1 << 9), /* Reset */ - EM_CTL_TM = (1 << 8), /* Transmit Message */ - EM_CTL_MR = (1 << 0), /* Message Received */ - EM_CTL_ALHD = (1 << 26), /* Activity LED */ - EM_CTL_XMT = (1 << 25), /* Transmit Only */ - EM_CTL_SMB = (1 << 24), /* Single Message Buffer */ - EM_CTL_SGPIO = (1 << 19), /* SGPIO messages supported */ - EM_CTL_SES = (1 << 18), /* SES-2 messages supported */ - EM_CTL_SAFTE = (1 << 17), /* SAF-TE messages supported */ - EM_CTL_LED = (1 << 16), /* LED messages supported */ + EM_CTL_RST = BIT(9), /* Reset */ + EM_CTL_TM = BIT(8), /* Transmit Message */ + EM_CTL_MR = BIT(0), /* Message Received */ + EM_CTL_ALHD = BIT(26), /* Activity LED */ + EM_CTL_XMT = BIT(25), /* Transmit Only */ + EM_CTL_SMB = BIT(24), /* Single Message Buffer */ + EM_CTL_SGPIO = BIT(19), /* SGPIO messages supported */ + EM_CTL_SES = BIT(18), /* SES-2 messages supported */ + EM_CTL_SAFTE = BIT(17), /* SAF-TE messages supported */ + EM_CTL_LED = BIT(16), /* LED messages supported */ /* em message type */ - EM_MSG_TYPE_LED = (1 << 0), /* LED */ - EM_MSG_TYPE_SAFTE = (1 << 1), /* SAF-TE */ - EM_MSG_TYPE_SES2 = (1 << 2), /* SES-2 */ - EM_MSG_TYPE_SGPIO = (1 << 3), /* SGPIO */ + EM_MSG_TYPE_LED = BIT(0), /* LED */ + EM_MSG_TYPE_SAFTE = BIT(1), /* SAF-TE */ + EM_MSG_TYPE_SES2 = BIT(2), /* SES-2 */ + EM_MSG_TYPE_SGPIO = BIT(3), /* SGPIO */ }; struct ahci_cmd_hdr { -- cgit v1.2.3