From 5ac40790b4708e4cb1a64ba2cb77320939bc5240 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 11 May 2018 12:51:03 -0600 Subject: libata: introduce notion of separate hardware tags Rigth now these are the same, but drivers should be using ->hw_tag for their command setup and issue. Signed-off-by: Jens Axboe Signed-off-by: Tejun Heo --- include/linux/libata.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/linux') diff --git a/include/linux/libata.h b/include/linux/libata.h index 1795fecdea17..07a8d54ba7af 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -637,7 +637,8 @@ struct ata_queued_cmd { u8 cdb[ATAPI_CDB_LEN]; unsigned long flags; /* ATA_QCFLAG_xxx */ - unsigned int tag; + unsigned int tag; /* libata core tag */ + unsigned int hw_tag; /* driver tag */ unsigned int n_elem; unsigned int orig_n_elem; -- cgit v1.2.3 From e3ed8939644166a7560a33c46f508584a7f1756a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 11 May 2018 12:51:05 -0600 Subject: libata: bump ->qc_active to a 64-bit type This is in preparation for allowing full usage of the tag space, which means that our reserved error handling command will be using an internal tag value of 32. This doesn't fit in a u32, so move to a u64. Signed-off-by: Jens Axboe Signed-off-by: Tejun Heo --- drivers/ata/libata-core.c | 17 +++++++++-------- drivers/ata/sata_fsl.c | 2 +- drivers/ata/sata_mv.c | 2 +- drivers/ata/sata_nv.c | 2 +- include/linux/libata.h | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) (limited to 'include/linux') diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 1687e24d3633..b079c3b5ec27 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1571,7 +1571,8 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, int auto_timeout = 0; struct ata_queued_cmd *qc; unsigned int tag, preempted_tag; - u32 preempted_sactive, preempted_qc_active; + u32 preempted_sactive; + u64 preempted_qc_active; int preempted_nr_active_links; DECLARE_COMPLETION_ONSTACK(wait); unsigned long flags; @@ -5195,7 +5196,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc) * is called. (when rc != 0 and atapi request sense is needed) */ qc->flags &= ~ATA_QCFLAG_ACTIVE; - ap->qc_active &= ~(1 << qc->tag); + ap->qc_active &= ~(1ULL << qc->tag); /* call completion callback */ qc->complete_fn(qc); @@ -5352,29 +5353,29 @@ void ata_qc_complete(struct ata_queued_cmd *qc) * RETURNS: * Number of completed commands on success, -errno otherwise. */ -int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active) +int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active) { int nr_done = 0; - u32 done_mask; + u64 done_mask; done_mask = ap->qc_active ^ qc_active; if (unlikely(done_mask & qc_active)) { - ata_port_err(ap, "illegal qc_active transition (%08x->%08x)\n", + ata_port_err(ap, "illegal qc_active transition (%08llx->%08llx)\n", ap->qc_active, qc_active); return -EINVAL; } while (done_mask) { struct ata_queued_cmd *qc; - unsigned int tag = __ffs(done_mask); + unsigned int tag = __ffs64(done_mask); qc = ata_qc_from_tag(ap, tag); if (qc) { ata_qc_complete(qc); nr_done++; } - done_mask &= ~(1 << tag); + done_mask &= ~(1ULL << tag); } return nr_done; @@ -5418,7 +5419,7 @@ void ata_qc_issue(struct ata_queued_cmd *qc) } qc->flags |= ATA_QCFLAG_ACTIVE; - ap->qc_active |= 1 << qc->tag; + ap->qc_active |= 1ULL << qc->tag; /* * We guarantee to LLDs that they will have at least one diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c index cb67847d2157..1b22d5c339d7 100644 --- a/drivers/ata/sata_fsl.c +++ b/drivers/ata/sata_fsl.c @@ -1266,7 +1266,7 @@ static void sata_fsl_host_intr(struct ata_port *ap) } VPRINTK("Status of all queues :\n"); - VPRINTK("done_mask/CC = 0x%x, CA = 0x%x, CE=0x%x,CQ=0x%x,apqa=0x%x\n", + VPRINTK("done_mask/CC = 0x%x, CA = 0x%x, CE=0x%x,CQ=0x%x,apqa=0x%llx\n", done_mask, ioread32(hcr_base + CA), ioread32(hcr_base + CE), diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index 3a08f38c695c..cddf96f6e431 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -2539,7 +2539,7 @@ static int mv_handle_fbs_ncq_dev_err(struct ata_port *ap) failed_links = hweight16(new_map); ata_port_info(ap, - "%s: pmp_map=%04x qc_map=%04x failed_links=%d nr_active_links=%d\n", + "%s: pmp_map=%04x qc_map=%04llx failed_links=%d nr_active_links=%d\n", __func__, pp->delayed_eh_pmp_map, ap->qc_active, failed_links, ap->nr_active_links); diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c index d83afc3dbf94..9a74f9ff5ebc 100644 --- a/drivers/ata/sata_nv.c +++ b/drivers/ata/sata_nv.c @@ -1782,7 +1782,7 @@ static void nv_swncq_ncq_stop(struct ata_port *ap) u32 sactive; u32 done_mask; - ata_port_err(ap, "EH in SWNCQ mode,QC:qc_active 0x%X sactive 0x%X\n", + ata_port_err(ap, "EH in SWNCQ mode,QC:qc_active 0x%llX sactive 0x%X\n", ap->qc_active, ap->link.sactive); ata_port_err(ap, "SWNCQ:qc_active 0x%X defer_bits 0x%X last_issue_tag 0x%x\n " diff --git a/include/linux/libata.h b/include/linux/libata.h index 07a8d54ba7af..2881919b3728 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -852,7 +852,7 @@ struct ata_port { struct ata_queued_cmd qcmd[ATA_MAX_QUEUE]; unsigned long sas_tag_allocated; /* for sas tag allocation only */ - unsigned int qc_active; + u64 qc_active; int nr_active_links; /* #links with active qcs */ unsigned int sas_last_tag; /* track next tag hw expects */ @@ -1185,7 +1185,7 @@ extern void ata_id_c_string(const u16 *id, unsigned char *s, extern unsigned int ata_do_dev_read_id(struct ata_device *dev, struct ata_taskfile *tf, u16 *id); extern void ata_qc_complete(struct ata_queued_cmd *qc); -extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active); +extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active); extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd); extern int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev, -- cgit v1.2.3 From 2e2cc676cee8962cdc82a23723df2fb394d35c64 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 11 May 2018 12:51:06 -0600 Subject: libata: use ata_tag_internal() consistently Some check for the value directly, use the provided helper instead. Also make it return a bool, since that's what it does. Signed-off-by: Jens Axboe Signed-off-by: Tejun Heo --- drivers/ata/libata-core.c | 2 +- drivers/ata/libata-scsi.c | 2 +- include/linux/libata.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include/linux') diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index b079c3b5ec27..8fd352d4c190 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -759,7 +759,7 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; tf->flags |= tf_flags; - if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) { + if (ata_ncq_enabled(dev) && !ata_tag_internal(tag)) { /* yay, NCQ */ if (!lba_48_ok(block, n_block)) return -ERANGE; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 28e1af2bae5f..143cdad7d81a 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -5120,7 +5120,7 @@ int ata_sas_allocate_tag(struct ata_port *ap) tag = tag < max_queue ? tag : 0; /* the last tag is reserved for internal command. */ - if (tag == ATA_TAG_INTERNAL) + if (ata_tag_internal(tag)) continue; if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) { diff --git a/include/linux/libata.h b/include/linux/libata.h index 2881919b3728..60ce1ba26fdd 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1491,7 +1491,7 @@ static inline unsigned int ata_tag_valid(unsigned int tag) return (tag < ATA_MAX_QUEUE) ? 1 : 0; } -static inline unsigned int ata_tag_internal(unsigned int tag) +static inline bool ata_tag_internal(unsigned int tag) { return tag == ATA_TAG_INTERNAL; } -- cgit v1.2.3 From 28361c403683c2b00d4f5e76045f3ccd299bf99d Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 11 May 2018 12:51:09 -0600 Subject: libata: add extra internal command Bump the internal tag to 32, instead of stealing the last tag in our regular command space. This works just fine, since we don't actually need a separate hardware tag for this. Internal commands cannot coexist with NCQ commands. As a bonus, we get rid of the special casing of what tag to use for the internal command. This is in preparation for utilizing all 32 commands for normal IO. Signed-off-by: Jens Axboe Signed-off-by: Tejun Heo --- drivers/ata/libata-core.c | 22 ++++++---------------- drivers/ata/libata-eh.c | 3 ++- include/linux/libata.h | 15 +++++++-------- 3 files changed, 15 insertions(+), 25 deletions(-) (limited to 'include/linux') diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 8fd352d4c190..5e2f679322cc 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1570,7 +1570,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, u8 command = tf->command; int auto_timeout = 0; struct ata_queued_cmd *qc; - unsigned int tag, preempted_tag; + unsigned int preempted_tag; u32 preempted_sactive; u64 preempted_qc_active; int preempted_nr_active_links; @@ -1588,20 +1588,10 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, } /* initialize internal qc */ + qc = __ata_qc_from_tag(ap, ATA_TAG_INTERNAL); - /* XXX: Tag 0 is used for drivers with legacy EH as some - * drivers choke if any other tag is given. This breaks - * ata_tag_internal() test for those drivers. Don't use new - * EH stuff without converting to it. - */ - if (ap->ops->error_handler) - tag = ATA_TAG_INTERNAL; - else - tag = 0; - - qc = __ata_qc_from_tag(ap, tag); - - qc->tag = qc->hw_tag = tag; + qc->tag = ATA_TAG_INTERNAL; + qc->hw_tag = 0; qc->scsicmd = NULL; qc->ap = ap; qc->dev = dev; @@ -5156,7 +5146,7 @@ void ata_qc_free(struct ata_queued_cmd *qc) qc->flags = 0; tag = qc->tag; - if (likely(ata_tag_valid(tag))) { + if (ata_tag_valid(tag)) { qc->tag = ATA_TAG_POISON; if (ap->flags & ATA_FLAG_SAS_HOST) ata_sas_free_tag(tag, ap); @@ -5415,7 +5405,7 @@ void ata_qc_issue(struct ata_queued_cmd *qc) WARN_ON_ONCE(link->sactive); ap->nr_active_links++; - link->active_tag = qc->hw_tag; + link->active_tag = qc->tag; } qc->flags |= ATA_QCFLAG_ACTIVE; diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 9f9aad77fbcd..eadbe26ba3dc 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1057,7 +1057,8 @@ static int ata_do_link_abort(struct ata_port *ap, struct ata_link *link) /* we're gonna abort all commands, no need for fast drain */ ata_eh_set_pending(ap, 0); - for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { + /* include internal tag in iteration */ + for (tag = 0; tag <= ATA_MAX_QUEUE; tag++) { struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); if (qc && (!link || qc->dev->link == link)) { diff --git a/include/linux/libata.h b/include/linux/libata.h index 60ce1ba26fdd..1d026719461b 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -125,9 +125,8 @@ enum { LIBATA_MAX_PRD = ATA_MAX_PRD / 2, LIBATA_DUMB_MAX_PRD = ATA_MAX_PRD / 4, /* Worst case */ ATA_DEF_QUEUE = 1, - /* tag ATA_MAX_QUEUE - 1 is reserved for internal commands */ ATA_MAX_QUEUE = 32, - ATA_TAG_INTERNAL = ATA_MAX_QUEUE - 1, + ATA_TAG_INTERNAL = ATA_MAX_QUEUE, ATA_SHORT_PAUSE = 16, ATAPI_MAX_DRAIN = 16 << 10, @@ -850,7 +849,7 @@ struct ata_port { unsigned int udma_mask; unsigned int cbl; /* cable type; ATA_CBL_xxx */ - struct ata_queued_cmd qcmd[ATA_MAX_QUEUE]; + 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 */ @@ -1486,14 +1485,14 @@ extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset, const char *name); #endif -static inline unsigned int ata_tag_valid(unsigned int tag) +static inline bool ata_tag_internal(unsigned int tag) { - return (tag < ATA_MAX_QUEUE) ? 1 : 0; + return tag == ATA_TAG_INTERNAL; } -static inline bool ata_tag_internal(unsigned int tag) +static inline bool ata_tag_valid(unsigned int tag) { - return tag == ATA_TAG_INTERNAL; + return tag < ATA_MAX_QUEUE || ata_tag_internal(tag); } /* @@ -1656,7 +1655,7 @@ static inline void ata_qc_set_polling(struct ata_queued_cmd *qc) static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap, unsigned int tag) { - if (likely(ata_tag_valid(tag))) + if (ata_tag_valid(tag)) return &ap->qcmd[tag]; return NULL; } -- cgit v1.2.3