Skip to contentSkip to conversation

libata: Improve ATA queued command allocation

PATCH Applied John Garry 2 participants 2 messages Apr 8, 2022 – Apr 11, 2022

Subsystems (2)
lore
Share & tools
lore

John Garry

author
#0 lore raw

PATCH v4 1/1 libata: Improve ATA queued command allocation

Improve ATA queued command allocation as follows:

- For attaining a qc tag for a SAS host we need to allocate a bit in ata_port.sas_tag_allocated bitmap.

However we already have a unique tag per device in range [0, ATA_MAX_QUEUE -1] in the scsi cmnd budget token, so just use that instead.

- It is a bit pointless to have ata_qc_new_init() in libata-core.c since it pokes scsi internals, so inline it in ata_scsi_qc_new() (in libata-scsi.c). Also update Doc accordingly.

- Use standard SCSI helpers set_host_byte() and set_status_byte() in ata_scsi_qc_new().

Christoph Hellwig originally contributed the change to inline ata_qc_new_init().

---
Do not apply on a kernel without "scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map()" - hopefully v5.18-rc2 will include it.

Changes since v3:
- Add RB tag (thanks)
- remove double set of qc->scsicmd (Advised by Christoph)

Changes since v2 series:
- combine into a single patch
- use scsi helpers (Damien)
- use inclusive brackets for commit message description

Documentation/driver-api/libata.rst +0 -11
index d477e296bda5..311af516a3fd 100644
@@ -424,12 +424,6 @@ How commands are issued
 -----------------------
 
 Internal commands
-    First, qc is allocated and initialized using :c:func:`ata_qc_new_init`.
-    Although :c:func:`ata_qc_new_init` doesn't implement any wait or retry
-    mechanism when qc is not available, internal commands are currently
-    issued only during initialization and error recovery, so no other
-    command is active and allocation is guaranteed to succeed.
-
     Once allocated qc's taskfile is initialized for the command to be
     executed. qc currently has two mechanisms to notify completion. One
     is via ``qc->complete_fn()`` callback and the other is completion
@@ -447,11 +441,6 @@ SCSI commands
     translated. No qc is involved in processing a simulated scmd. The
     result is computed right away and the scmd is completed.
 
-    For a translated scmd, :c:func:`ata_qc_new_init` is invoked to allocate a
-    qc and the scmd is translated into the qc. SCSI midlayer's
-    completion notification function pointer is stored into
-    ``qc->scsidone``.
-
     ``qc->complete_fn()`` callback is used for completion notification. ATA
     commands use :c:func:`ata_scsi_qc_complete` while ATAPI commands use
     :c:func:`atapi_qc_complete`. Both functions end up calling ``qc->scsidone``
drivers/ata/libata-core.c +1 -47

62 lines not on this page · raw message

drivers/ata/libata-sata.c +0 -25
index 044a16daa2d4..7a5fe41aa5ae 100644
@@ -1268,31 +1268,6 @@ int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
 }
 EXPORT_SYMBOL_GPL(ata_sas_queuecmd);
 
-int ata_sas_allocate_tag(struct ata_port *ap)
-{
-	unsigned int max_queue = ap->host->n_tags;
-	unsigned int i, tag;
-
-	for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) {
-		tag = tag < max_queue ? tag : 0;
-
-		/* the last tag is reserved for internal command. */
-		if (ata_tag_internal(tag))
-			continue;
-
-		if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) {
-			ap->sas_last_tag = tag;
-			return tag;
-		}
-	}
-	return -1;
-}
-
-void ata_sas_free_tag(unsigned int tag, struct ata_port *ap)
-{
-	clear_bit(tag, &ap->sas_tag_allocated);
-}
-
 /**
  *	sata_async_notification - SATA async notification handler
  *	@ap: ATA port where async notification is received
drivers/ata/libata-scsi.c +35 -11

59 lines not on this page · raw message

drivers/ata/libata.h +0 -13
index c9c2496d91ea..926a7f41303d 100644
@@ -44,7 +44,6 @@ static inline void ata_force_cbl(struct ata_port *ap) { }
 #endif
 extern u64 ata_tf_to_lba(const struct ata_taskfile *tf);
 extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
-extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
 extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
 			   u64 block, u32 n_block, unsigned int tf_flags,
 			   unsigned int tag, int class);
@@ -91,18 +90,6 @@ extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
 
 #define to_ata_port(d) container_of(d, struct ata_port, tdev)
 
-/* libata-sata.c */
-#ifdef CONFIG_SATA_HOST
-int ata_sas_allocate_tag(struct ata_port *ap);
-void ata_sas_free_tag(unsigned int tag, struct ata_port *ap);
-#else
-static inline int ata_sas_allocate_tag(struct ata_port *ap)
-{
-	return -EOPNOTSUPP;
-}
-static inline void ata_sas_free_tag(unsigned int tag, struct ata_port *ap) { }
-#endif
-
 /* libata-acpi.c */
 #ifdef CONFIG_ATA_ACPI
 extern unsigned int ata_acpi_gtf_filter;
include/linux/libata.h +0 -1
index 9b1d3d8b1252..16107122e587 100644
@@ -820,7 +820,6 @@ struct ata_port {
 	unsigned int		cbl;	/* cable type; ATA_CBL_xxx */
 
 	struct ata_queued_cmd	qcmd[ATA_MAX_QUEUE + 1];
-	unsigned long		sas_tag_allocated; /* for sas tag allocation only */
 	u64			qc_active;
 	int			nr_active_links; /* #links with active qcs */
 	unsigned int		sas_last_tag;	/* track next tag hw expects */
Signature · 1 line
2.26.2
#1 lore raw
Quoted 13 lines · John Garry

Improve ATA queued command allocation as follows:

- For attaining a qc tag for a SAS host we need to allocate a bit in ata_port.sas_tag_allocated bitmap.

However we already have a unique tag per device in range [0, ATA_MAX_QUEUE -1] in the scsi cmnd budget token, so just use that instead.

- It is a bit pointless to have ata_qc_new_init() in libata-core.c since it pokes scsi internals, so inline it in ata_scsi_qc_new() (in libata-scsi.c). Also update Doc accordingly.

Quoted 8 lines

- Use standard SCSI helpers set_host_byte() and set_status_byte() in ata_scsi_qc_new().

Christoph Hellwig originally contributed the change to inline ata_qc_new_init().

Applied to for-5.19. Thanks !

Signature · 2 lines
Damien Le Moal
Western Digital Research