Skip to content

Commit 2fca5cc

Browse files
Jens Axboetorvalds
authored andcommitted
libata: switch to using block layer tagging support
libata currently has a pretty dumb ATA_MAX_QUEUE loop for finding a free tag to use. Instead of fixing that up, convert libata to using block layer tagging - gets rid of code in libata, and is also much faster. Signed-off-by: Jens Axboe <[email protected]> Acked-by: Tejun Heo <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 332edc2 commit 2fca5cc

File tree

4 files changed

+31
-65
lines changed

4 files changed

+31
-65
lines changed

drivers/ata/libata-core.c

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,8 +1713,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
17131713
else
17141714
tag = 0;
17151715

1716-
if (test_and_set_bit(tag, &ap->qc_allocated))
1717-
BUG();
17181716
qc = __ata_qc_from_tag(ap, tag);
17191717

17201718
qc->tag = tag;
@@ -4552,37 +4550,6 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
45524550
#endif /* __BIG_ENDIAN */
45534551
}
45544552

4555-
/**
4556-
* ata_qc_new - Request an available ATA command, for queueing
4557-
* @ap: Port associated with device @dev
4558-
* @dev: Device from whom we request an available command structure
4559-
*
4560-
* LOCKING:
4561-
* None.
4562-
*/
4563-
4564-
static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
4565-
{
4566-
struct ata_queued_cmd *qc = NULL;
4567-
unsigned int i;
4568-
4569-
/* no command while frozen */
4570-
if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4571-
return NULL;
4572-
4573-
/* the last tag is reserved for internal command. */
4574-
for (i = 0; i < ATA_MAX_QUEUE - 1; i++)
4575-
if (!test_and_set_bit(i, &ap->qc_allocated)) {
4576-
qc = __ata_qc_from_tag(ap, i);
4577-
break;
4578-
}
4579-
4580-
if (qc)
4581-
qc->tag = i;
4582-
4583-
return qc;
4584-
}
4585-
45864553
/**
45874554
* ata_qc_new_init - Request an available ATA command, and initialize it
45884555
* @dev: Device from whom we request an available command structure
@@ -4591,48 +4558,27 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
45914558
* None.
45924559
*/
45934560

4594-
struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev)
4561+
struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
45954562
{
45964563
struct ata_port *ap = dev->link->ap;
45974564
struct ata_queued_cmd *qc;
45984565

4599-
qc = ata_qc_new(ap);
4566+
if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4567+
return NULL;
4568+
4569+
qc = __ata_qc_from_tag(ap, tag);
46004570
if (qc) {
46014571
qc->scsicmd = NULL;
46024572
qc->ap = ap;
46034573
qc->dev = dev;
4574+
qc->tag = tag;
46044575

46054576
ata_qc_reinit(qc);
46064577
}
46074578

46084579
return qc;
46094580
}
46104581

4611-
/**
4612-
* ata_qc_free - free unused ata_queued_cmd
4613-
* @qc: Command to complete
4614-
*
4615-
* Designed to free unused ata_queued_cmd object
4616-
* in case something prevents using it.
4617-
*
4618-
* LOCKING:
4619-
* spin_lock_irqsave(host lock)
4620-
*/
4621-
void ata_qc_free(struct ata_queued_cmd *qc)
4622-
{
4623-
struct ata_port *ap = qc->ap;
4624-
unsigned int tag;
4625-
4626-
WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
4627-
4628-
qc->flags = 0;
4629-
tag = qc->tag;
4630-
if (likely(ata_tag_valid(tag))) {
4631-
qc->tag = ATA_TAG_POISON;
4632-
clear_bit(tag, &ap->qc_allocated);
4633-
}
4634-
}
4635-
46364582
void __ata_qc_complete(struct ata_queued_cmd *qc)
46374583
{
46384584
struct ata_port *ap = qc->ap;

drivers/ata/libata-scsi.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
708708
{
709709
struct ata_queued_cmd *qc;
710710

711-
qc = ata_qc_new_init(dev);
711+
qc = ata_qc_new_init(dev, cmd->request->tag);
712712
if (qc) {
713713
qc->scsicmd = cmd;
714714
qc->scsidone = done;
@@ -1103,7 +1103,8 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
11031103

11041104
depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id));
11051105
depth = min(ATA_MAX_QUEUE - 1, depth);
1106-
scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth);
1106+
scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
1107+
scsi_activate_tcq(sdev, depth);
11071108
}
11081109

11091110
return 0;
@@ -1943,6 +1944,11 @@ static unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf)
19431944
hdr[1] |= (1 << 7);
19441945

19451946
memcpy(rbuf, hdr, sizeof(hdr));
1947+
1948+
/* if ncq, set tags supported */
1949+
if (ata_id_has_ncq(args->id))
1950+
rbuf[7] |= (1 << 1);
1951+
19461952
memcpy(&rbuf[8], "ATA ", 8);
19471953
ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16);
19481954
ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV, 4);

drivers/ata/libata.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extern struct ata_link *ata_dev_phys_link(struct ata_device *dev);
7474
extern void ata_force_cbl(struct ata_port *ap);
7575
extern u64 ata_tf_to_lba(const struct ata_taskfile *tf);
7676
extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
77-
extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev);
77+
extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
7878
extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
7979
u64 block, u32 n_block, unsigned int tf_flags,
8080
unsigned int tag);
@@ -103,7 +103,6 @@ extern int ata_dev_configure(struct ata_device *dev);
103103
extern int sata_down_spd_limit(struct ata_link *link);
104104
extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
105105
extern void ata_sg_clean(struct ata_queued_cmd *qc);
106-
extern void ata_qc_free(struct ata_queued_cmd *qc);
107106
extern void ata_qc_issue(struct ata_queued_cmd *qc);
108107
extern void __ata_qc_complete(struct ata_queued_cmd *qc);
109108
extern int atapi_check_dma(struct ata_queued_cmd *qc);
@@ -119,6 +118,22 @@ extern struct ata_port *ata_port_alloc(struct ata_host *host);
119118
extern void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy);
120119
extern void ata_lpm_schedule(struct ata_port *ap, enum link_pm);
121120

121+
/**
122+
* ata_qc_free - free unused ata_queued_cmd
123+
* @qc: Command to complete
124+
*
125+
* Designed to free unused ata_queued_cmd object
126+
* in case something prevents using it.
127+
*
128+
* LOCKING:
129+
* spin_lock_irqsave(host lock)
130+
*/
131+
static inline void ata_qc_free(struct ata_queued_cmd *qc)
132+
{
133+
qc->flags = 0;
134+
qc->tag = ATA_TAG_POISON;
135+
}
136+
122137
/* libata-acpi.c */
123138
#ifdef CONFIG_ATA_ACPI
124139
extern void ata_acpi_associate_sata_port(struct ata_port *ap);

include/linux/libata.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ struct ata_port {
695695
unsigned int cbl; /* cable type; ATA_CBL_xxx */
696696

697697
struct ata_queued_cmd qcmd[ATA_MAX_QUEUE];
698-
unsigned long qc_allocated;
699698
unsigned int qc_active;
700699
int nr_active_links; /* #links with active qcs */
701700

0 commit comments

Comments
 (0)