1. 31 Jan, 2023 3 commits
    • Ondrej Zary's avatar
      drivers/block: Move PARIDE protocol modules to drivers/ata/pata_parport · 72f2b0b2
      Ondrej Zary authored
      Move PARIDE protocol modules out of drivers/block into
      drivers/ata/pata_parport and update the CONFIG_ symbol names to
      PATA_PARPORT.
      
      [Damien]
      The pata_parport driver file itsef is also moved together with the
      protocol modules in drivers/ata/pata_parport.
      Signed-off-by: default avatarOndrej Zary <linux@zary.sk>
      Acked-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      72f2b0b2
    • Ondrej Zary's avatar
      drivers/block: Remove PARIDE core and high-level protocols · 7750d8b5
      Ondrej Zary authored
      Remove PARIDE core and high level protocols, taking care not to break
      low-level drivers (used by pata_parport). Also update documentation.
      Signed-off-by: default avatarOndrej Zary <linux@zary.sk>
      Acked-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      7750d8b5
    • Ondrej Zary's avatar
      ata: pata_parport: add driver (PARIDE replacement) · 246a1c4c
      Ondrej Zary authored
      The pata_parport is a libata-based replacement of the old PARIDE
      subsystem - driver for parallel port IDE devices.
      It uses the original paride low-level protocol drivers but does not
      need the high-level drivers (pd, pcd, pf, pt, pg). The IDE devices
      behind parallel port adapters are handled by the ATA layer.
      
      This will allow paride and its high-level drivers to be removed.
      
      Unfortunately, libata drivers cannot sleep so pata_parport claims
      parport before activating the ata host and keeps it claimed (and
      protocol connected) until the ata host is removed. This means that
      no devices can be chained (neither other pata_parport devices nor
      a printer).
      
      paride and pata_parport are mutually exclusive because the compiled
      protocol drivers are incompatible.
      
      Tested with:
       - Imation SuperDisk LS-120 and HP C4381A (EPAT)
       - Freecom Parallel CD (FRPW)
       - Toshiba Mobile CD-RW 2793008 w/Freecom Parallel Cable rev.903 (FRIQ)
       - Backpack CD-RW 222011 and CD-RW 19350 (BPCK6)
      
      The following bugs in low-level protocol drivers were found and will
      be fixed later:
      
      Note: EPP-32 mode is buggy in EPAT - and also in all other protocol
      drivers - they don't handle non-multiple-of-4 block transfers
      correctly. This causes problems with LS-120 drive.
      There is also another bug in EPAT: EPP modes don't work unless a 4-bit
      or 8-bit mode is used first (probably some initialization missing?).
      Once the device is initialized, EPP works until power cycle.
      
      So after device power on, you have to:
      echo "parport0 epat 0" >/sys/bus/pata_parport/new_device
      echo pata_parport.0 >/sys/bus/pata_parport/delete_device
      echo "parport0 epat 4" >/sys/bus/pata_parport/new_device
      (autoprobe will initialize correctly as it tries the slowest modes
      first but you'll get the broken EPP-32 mode)
      
      Note: EPP modes are buggy in FRPW, only modes 0 and 1 work.
      Signed-off-by: default avatarOndrej Zary <linux@zary.sk>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
      Acked-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      246a1c4c
  2. 13 Jan, 2023 6 commits
  3. 04 Jan, 2023 8 commits
    • Damien Le Moal's avatar
      ata: libata-scsi: improve ata_scsiop_maint_in() · 002c4871
      Damien Le Moal authored
      Allow translation of REPORT_SUPPORTED_OPERATION_CODES commands using
      the command format 0x3, that is, checking support for commands that are
      identified using an opcode and a service action.
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      002c4871
    • Niklas Cassel's avatar
      ata: libata-scsi: do not overwrite SCSI ML and status bytes · 7574a837
      Niklas Cassel authored
      For SCSI ML byte:
      In the case where a command is completed via libata EH:
      irq -> ata_qc_complete() -> ata_qc_schedule_eh()
      irq done
      ... -> ata_do_eh() -> ata_eh_link_autopsy() -> ata_eh_finish() ->
      ata_eh_qc_complete() -> __ata_eh_qc_complete() -> __ata_qc_complete() ->
      qc->complete_fn() (ata_scsi_qc_complete()) -> ata_qc_done() ->
      qc->scsidone() (empty stub)
      ... -> scsi_eh_finish_cmd() -> scsi_eh_flush_done_q() ->
      scsi_finish_command()
      
      ata_eh_link_autopsy() will call ata_eh_analyze_tf(), which calls
      scsi_check_sense(), which sets the SCSI ML byte.
      
      Since ata_scsi_qc_complete() is called after scsi_check_sense() when
      a command is completed via libata EH, we cannot simply overwrite the
      SCSI ML byte that was set earlier in the call chain.
      
      For SCSI status byte:
      When a SCSI command is prepared using scsi_prepare_cmd(), it sets
      cmd->result to 0. (SAM_STAT_GOOD is defined as 0x0).
      Likewise, when a command is requeued from SCSI EH, scsi_queue_insert()
      is called, which sets cmd->result to 0.
      
      A SCSI command thus always has a GOOD status by default when being
      sent to libata.
      
      If libata fetches sense data from the device, it will call
      ata_scsi_set_sense(), which will set the status byte to
      SAM_STAT_CHECK_CONDITION, if the caller deems that the status should be
      a check condition.
      
      ata_scsi_qc_complete() should therefore never overwrite the existing
      status byte, because if it is != GOOD, it was set by libata itself,
      for a reason.
      
      For the host byte:
      When libata abort commands, because of a NCQ error, it will schedule
      SCSI EH for all QCs using blk_abort_request(), which will all end up in
      scsi_timeout(), which will call scsi_abort_command(). scsi_timeout()
      sets DID_TIME_OUT regardless if a command was aborted or timed out.
      If we don't clear the DID_TIME_OUT byte for the QC that caused the
      NCQ error, that QC will be reported as a timed out command, instead
      of being reported as a NCQ error.
      
      For a command that actually timed out, DID_TIME_OUT would be fine to
      keep, but libata has its own way of detecting that a command timed out
      (see ata_scsi_cmd_error_handler()), and sets AC_ERR_TIMEOUT if that is
      the case. libata will retry timed out commands.
      
      We could clear DID_TIME_OUT only for the QC that caused the NCQ error,
      but since libata has its own way of detecting timeouts, simply clear it
      always.
      
      Note that the existing ata_scsi_qc_complete() code does:
      cmd->result = SAM_STAT_CHECK_CONDITION or cmd->result = SAM_STAT_GOOD.
      This WILL clear the host byte. So us clearing the host byte
      unconditionally is in line with the existing libata behavior.
      Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      7574a837
    • Niklas Cassel's avatar
      ata: libata: move NCQ related ATA_DFLAGs · 87aab3c4
      Niklas Cassel authored
      ata_dev_configure() starts off by clearing all flags in ATA_DFLAG_CFG_MASK:
      dev->flags &= ~ATA_DFLAG_CFG_MASK;
      
      ata_dev_configure() then calls ata_dev_config_lba() which calls
      ata_dev_config_ncq().
      
      ata_dev_config_ncq() will set the correct ATA_DFLAGs depending on what is
      actually supported.
      
      Since these flags are set by ata_dev_configure(), they should be in
      ATA_DFLAG_CFG_MASK and not in ATA_DFLAG_INIT_MASK.
      
      ATA_DFLAG_NCQ_PRIO_ENABLED is set via sysfs, is should therefore not be in
      ATA_DFLAG_CFG_MASK. It also cannot be in ATA_DFLAG_INIT_MASK, because
      ata_eh_schedule_probe() calls ata_dev_init(), which will clear all flags in
      ATA_DFLAG_INIT_MASK.
      
      This means that ATA_DFLAG_NCQ_PRIO_ENABLED (the value the user sets via
      sysfs) would get silently cleared if ata_eh_schedule_probe() is called.
      While that should only happen in certain circumstances, it still doesn't
      seem right that it can get silently cleared.
      
      (ata_dev_config_ncq_prio() will still clear the ATA_DFLAG_NCQ_PRIO_ENABLED
      flag if ATA_DFLAG_NCQ_PRIO is suddenly no longer supported after a
      revalidation.)
      
      Because of this, move ATA_DFLAG_NCQ_PRIO_ENABLED to be outside of both
      ATA_DFLAG_CFG_MASK and ATA_DFLAG_INIT_MASK.
      Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      87aab3c4
    • Niklas Cassel's avatar
      ata: libata: respect successfully completed commands during errors · 7affcded
      Niklas Cassel authored
      In AHCI specification 1.3.1:
      "5.5.3 Processing Completed Commands"
      
      "For each port that has an interrupt pending:
      
      1. Software determines the cause of the interrupt by reading the PxIS
         register. It is possible for multiple bits to be set.
      2. Software clears appropriate bits in the PxIS register corresponding
         to the cause of the interrupt.
      3. Software clears the interrupt bit in IS.IPS corresponding to the port.
      4. If executing non-queued commands, software reads the PxCI register,
         and compares the current value to the list of commands previously
         issued by software that are still outstanding. If executing native
         queued commands, software reads the PxSACT register and compares the
         current value to the list of commands previously issued by software.
         Software completes with success any outstanding command whose
         corresponding bit has been cleared in the respective register. PxCI
         and PxSACT are volatile registers; software should only use their
         values to determine commands that have completed, not to determine
         which commands have previously been issued.
      5. If there were errors, noted in the PxIS register, software performs
         error recovery actions (see section 6.2.2)."
      
      The documentation for the PxSACT shadow register in AHCI:
      "The device clears bits in this field by sending a Set Device Bits FIS
      to the host. The HBA clears bits in this field that are set to ‘1’ in
      the SActive field of the Set Device Bits FIS. The HBA only clears bits
      that correspond to native queued commands that have completed
      successfully."
      
      Additionally, in SATA specification 3.5a:
      "11.15 FPDMA QUEUED command protocol"
      
      "DFPDMAQ11: ERROR
      Halt command processing and transmit Set Device Bits FIS to host
      with the ERR bit in Status field set to one, Interrupt bit set to one,
      ATA error code set to one in the ERROR field, bits in ACT field cleared
      to zero for any outstanding queued commands, and bits set to one
      for any successfully completed queued commands that completion
      notification not yet delivered."
      
      I.e. even when the HBA triggers an error interrupt, the HBA will still
      clear successfully completed commands in PxSACT. Commands that did not
      complete successfully will still have its bit set in PxSACT.
      (Which means the command that caused the NCQ error and queued commands
      that had not yet finished at the time when the NCQ error occurred.)
      
      Additionally, for a HBA that does not have the libata flag
      AHCI_HFLAG_MULTI_MSI set, all ap->locks will point to host->lock, which
      means that IRQs will be disabled for one port while another port's IRQ
      handler is running. The HBA will still receive FISes from the device,
      even if IRQs on the HBA itself are disabled. What can thus e.g. receive
      a FIS that completes several commands successfully, followed by a FIS
      that does (or does not) complete additional commands with the error bit
      set, to indicate that at least one command was aborted.
      
      Therefore, modify ahci_handle_port_interrupt() using the new helper
      ahci_qc_complete() to complete the commands that have already been
      signaled as successfully through a regular completion SDB FIS, as not
      doing so would simply cause successfully completed commands to be
      retried for no good reason.
      Co-developed-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      7affcded
    • Niklas Cassel's avatar
      ata: libata: read the shared status for successful NCQ commands once · 93c4aa44
      Niklas Cassel authored
      Currently, the status is being read for each QC, inside
      ata_qc_complete(), which means that QCs being completed by
      ata_qc_complete_multiple() (i.e. multiple QCs completed during a single
      interrupt), can have different status and error bits set. This is
      because the FIS Receive Area will get updated as soon as the HBA
      receives a new FIS from the device in the NCQ case.
      
      Here is an example of the problem:
      ata14.00: ata_qc_complete_multiple: done_mask: 0x180000
      qc tag: 19 cmd: 0x61 flags: 0x11b err_mask: 0x0 tf->status: 0x40
      qc tag: 20 cmd: 0x61 flags: 0x11b err_mask: 0x0 tf->status: 0x43
      
      A print in ata_qc_complete_multiple(), shows that done_mask is: 0x180000
      which means that tag 19 and 20 were completed. Another print in
      ata_qc_complete(), after the call to fill_result_tf(), shows that tag 19
      and 20 have different status values, even though they were completed in
      the same ata_qc_complete_multiple() call.
      
      If PMP is not enabled, simply read the status and error once, before
      calling ata_qc_complete() for each QC. Without PMP, we know that all QCs
      must share the same status and error values.
      
      If PMP is enabled, we also read the status before calling
      ata_qc_complete(), however, we still read the status for each QC, since
      the QCs can belong to different PMP links (which means that the QCs
      does not necessarily share the same status and error values).
      
      Do all this by introducing the new port operation .qc_ncq_fill_rtf. If
      set, this operation is called in ata_qc_complete_multiple() to set the
      result tf for all completed QCs signaled by the last SDB FIS received.
      
      QCs that have their result tf filled are marked with the new flag
      ATA_QCFLAG_RTF_FILLED so that any later execution of the qc_fill_rtf
      port operation does nothing (e.g. when called from ata_qc_complete()).
      Co-developed-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      93c4aa44
    • Damien Le Moal's avatar
      ata: libata: simplify qc_fill_rtf port operation interface · 931139af
      Damien Le Moal authored
      The boolean return value of the qc_fill_rtf operation is used nowhere.
      Simplify this operation interface by making it a void function. All
      drivers defining this operation are also updated.
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      931139af
    • Niklas Cassel's avatar
      ata: scsi: rename flag ATA_QCFLAG_FAILED to ATA_QCFLAG_EH · 87629312
      Niklas Cassel authored
      The name ATA_QCFLAG_FAILED is misleading since it does not mean that a
      QC completed in error, or that it didn't complete at all. It means that
      libata decided to schedule EH for the QC, so the QC is now owned by the
      libata error handler (EH).
      
      The normal execution path is responsible for not accessing a QC owned
      by EH. libata core enforces the rule by returning NULL from
      ata_qc_from_tag() for QCs owned by EH.
      
      It is quite easy to mistake that a QC marked with ATA_QCFLAG_FAILED was
      an error. However, a QC that was actually an error is instead indicated
      by having qc->err_mask set. E.g. when we have a NCQ error, we abort all
      QCs, which currently will mark all QCs as ATA_QCFLAG_FAILED. However, it
      will only be a single QC that is an error (i.e. has qc->err_mask set).
      
      Rename ATA_QCFLAG_FAILED to ATA_QCFLAG_EH to more clearly highlight that
      this flag simply means that a QC is now owned by EH. This new name will
      not mislead to think that the QC was an error (which is instead
      indicated by having qc->err_mask set).
      
      This also makes it more obvious that the EH code skips all QCs that do
      not have ATA_QCFLAG_EH set (rather than ATA_QCFLAG_FAILED), since the EH
      code should simply only care about QCs that are owned by EH itself.
      Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      87629312
    • Wenchao Hao's avatar
      ata: libata-eh: Cleanup ata_scsi_cmd_error_handler() · b83ad9ee
      Wenchao Hao authored
      If ap->ops->error_handler is NULL just return. This patch also
      fixes some comment style issue.
      Signed-off-by: default avatarWenchao Hao <haowenchao@huawei.com>
      Reviewed-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      b83ad9ee
  4. 02 Jan, 2023 1 commit
  5. 01 Jan, 2023 6 commits
  6. 31 Dec, 2022 2 commits
  7. 30 Dec, 2022 14 commits