libata: separate out ata_ncq_enabled()
PATCH 1/3 libata: separate out ata_ncq_enabled()
Separate out ata_ncq_enabled().
--- drivers/ata/libata-core.c | 4 +--- include/linux/libata.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +1 -3
@@ -311,9 +311,7 @@ int ata_build_rw_tf(struct ata_taskfile tf->flags |=ATA_TFLAG_ISADDR |ATA_TFLAG_DEVICE ; tf->flags |= tf_flags; -if ((dev->flags & (ATA_DFLAG_PIO |ATA_DFLAG_NCQ_OFF | -ATA_DFLAG_NCQ )) ==ATA_DFLAG_NCQ && -likely (tag !=ATA_TAG_INTERNAL )) { +if (ata_ncq_enabled (dev) &&likely (tag !=ATA_TAG_INTERNAL )) {/* yay, NCQ */ if (!lba_48_ok (block, n_block))return -ERANGE ;
include/linux/libata.h +15 -0
@@ -1026,6 +1026,21 @@ static inline u8 ata_chk_status(struct areturn ap->ops->check_status (ap); } +/** +* ata_ncq_enabled - Test whether NCQ is enabled +* @dev: ATA device to test for +* +* LOCKING: +* spin_lock_irqsave(host lock) +* +* RETURNS: +* 1 if NCQ is enabled for @dev, 0 otherwise. +*/ +static inline int ata_ncq_enabled (struct ata_device *dev) +{ +return (dev->flags & (ATA_DFLAG_PIO |ATA_DFLAG_NCQ_OFF | +ATA_DFLAG_NCQ )) ==ATA_DFLAG_NCQ ; +}/** * ata_pause - Flush writes and pause 400 nanoseconds.
PATCH 2/3 libata: fix ata_scmd_need_defer()
Fix ata_scmd_need_defer() such that...
* whether NCQ is used or not is exactly determined using the same criteria as the issue path.
* defer-check is performed in all cases.
This fixes race condition where turning off NCQ on the fly causes non-NCQ commands sneak into NCQ phase.
--- drivers/ata/libata-scsi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/ata/libata-scsi.c +2 -4
@@ -1495,11 +1495,9 @@ static void ata_scsi_qc_complete(structstatic int ata_scmd_need_defer (struct ata_device *dev,int is_io) {struct ata_port *ap = dev->ap; +int is_ncq = is_io &&ata_ncq_enabled (dev); -if (!(dev->flags &ATA_DFLAG_NCQ )) -return 0 ; - -if (is_io) { +if (is_ncq) {if (!ata_tag_valid (ap->active_tag))return 0 ; }else {
PATCH 3/3 libata: fix ata_scsi_change_queue_depth()
Fix ata_scsi_change_queue_depth() such that...
* NCQ on/off is exactly determined using the same logic as the issue path.
* queue depth is adjusted to 1 if NCQ is not enabled.
* -EINVAL is returned if requested action is ignored due to limitations.
This fixes the bug which allows queue depth to be increased on blacklisted NCQ hosts/devices.
--- drivers/ata/libata-scsi.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/ata/libata-scsi.c +15 -12
@@ -986,29 +986,32 @@ int ata_scsi_change_queue_depth(struct sstruct ata_port *ap =ata_shost_to_port (sdev->host);struct ata_device *dev;unsigned long flags; -int max_depth; -if (queue_depth <1 ) +if (queue_depth <1 || queue_depth == sdev->queue_depth)return sdev->queue_depth; dev =ata_scsi_find_dev (ap, sdev);if (!dev || !ata_dev_enabled (dev))return sdev->queue_depth; - max_depth =min (sdev->host->can_queue,ata_id_queue_depth (dev->id)); - max_depth =min (ATA_MAX_QUEUE -1 , max_depth); -if (queue_depth > max_depth) - queue_depth = max_depth; - -scsi_adjust_queue_depth (sdev,MSG_SIMPLE_TAG , queue_depth); - +/* NCQ enabled? */ spin_lock_irqsave (ap->lock, flags); -if (queue_depth >1 ) - dev->flags &= ~ATA_DFLAG_NCQ_OFF ; -else + dev->flags &= ~ATA_DFLAG_NCQ_OFF ; +if (queue_depth ==1 || !ata_ncq_enabled (dev)) { dev->flags |=ATA_DFLAG_NCQ_OFF ; + queue_depth =1 ; + }spin_unlock_irqrestore (ap->lock, flags); +/* limit and apply queue depth */ + queue_depth =min (queue_depth, sdev->host->can_queue); + queue_depth =min (queue_depth,ata_id_queue_depth (dev->id)); + queue_depth =min (queue_depth,ATA_MAX_QUEUE -1 ); + +if (sdev->queue_depth == queue_depth) +return -EINVAL ; + +scsi_adjust_queue_depth (sdev,MSG_SIMPLE_TAG , queue_depth);return queue_depth; }
Quoted 7 lines · Tejun Heo
Separate out
ata_ncq_enabled().Signed-off-by Tejun Heo <[email protected]>--- drivers/ata/libata-core.c | 4 +--- include/linux/libata.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-)
applied 1-3