Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp787742lqs; Tue, 5 Mar 2024 17:23:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU9ziduNziwA5gx33TyTGlGN2JbPtkppMLXSUcgCiyPE43K5zZygTSGlHQeFcVBTWC8U3K6Uebk72yfIfWIkv5YbdGcVPZqSFU+lFmhEA== X-Google-Smtp-Source: AGHT+IENpUIu9/oj+q38ySn8KALb+d8VXLkuUkoNrInxKlMMA5qKMUPtLI1J1kK5cpn389ywxL1Y X-Received: by 2002:aa7:dcc5:0:b0:567:a2c7:27b4 with SMTP id w5-20020aa7dcc5000000b00567a2c727b4mr2584995edu.5.1709688192810; Tue, 05 Mar 2024 17:23:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709688192; cv=pass; d=google.com; s=arc-20160816; b=u0mHzZEf89oNMcVmQ2UIAutjst8Minmv1RJlNId5jXao1cULiyZ1kQE6s9RrFj/WZg swmhxwM/1AFIim4iW2ZCjav8mCKQAyLtRDoboB52mGdn5PJvr2cd8V7kVk/1aldgzRmF fHICBh7iRTHtl8gWPlfOPWNzkDaWPsQZYh2wP9jL4V81KtGlotWFj/6+Yj5MmH+ILPdU 4DX6sV0IRw+G6tUvXLmn4KNv10+aOJJVRadqMUwJwifh6UNvSn54iquGwo17rG8Y1Vdy CwqIMPt6yN9u+aLmbkf7Rpjj9JE5Oa3ndxavypBhLr/k8t4yB0R/VsUsYLftula1+Cmg As2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=hWaHPf3ur6A4qCJxa5rb9778tyG9D1zv7n6pTIOMylY=; fh=0UZI2ZFdJO6iFJFDaOcOsIVg5kT8KLWzW7oR0Sdk3E8=; b=CU5IUiSetDVlWsZFF/K6TPUCy5cZc2N9uZaRq+4Eqjvl2bbD7nVYj/z0FPzNnwjh8U KPl61UEfRE1ufkCThiPlTV+e0f/yfkVCWXQ5TAXZf/eSaTdBEleFCN4tZbN46+zPV2W8 4oyb1uwW/eLa4L7KPqPvrxcEmedx27S045k+l6r5q75mJJBmfeypTlxzt+k52dnWkihC ZAMHst1lh08jgS1e3Ox5EIGiVqUj97mQEzval6HjNI5lpfz3W/RqE1wCoGgPDCmSzwXM De0ZRj7StOlFTmTzqxZ++PD8LVhx/N6HGIxGrOTgZJ69xH1eWDJ++CKuSQH1EZGs6bYJ Pibw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=swLQjKvz; arc=pass (i=1 spf=pass spfdomain=flex--ipylypiv.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-93190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w22-20020a05640234d600b00566c2e8bd14si4856328edc.127.2024.03.05.17.23.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 17:23:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=swLQjKvz; arc=pass (i=1 spf=pass spfdomain=flex--ipylypiv.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-93190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 54DA41F22BA1 for ; Wed, 6 Mar 2024 01:23:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C7051172C; Wed, 6 Mar 2024 01:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="swLQjKvz" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61D266FD7 for ; Wed, 6 Mar 2024 01:22:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709688155; cv=none; b=cXoe740DE/L+edOJX5o2n0XoLzTqi6mfJE/vQa07NPxj9gFrguayUrQvzJ0kxiDfXmQh3QGUS1eXM4ppKbM31FdFG6nO0HfcKEf2yx/a8FIOnwwgKIWS/+fJ8W8TATlbXtvswLfH2BaNSJspyOVdYT2EB3hy+6AEAF6zYTMfKxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709688155; c=relaxed/simple; bh=HdE6FN0o7wTsTE4Ul3fnw6MLY1Eiy7U6ACIH7VY572U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I5IwNeHcDYxCWreRb5T5/4htfLk+KizPVzl35fumsC43frveNzFjX7I1IwXj7Ktmf6XidHXH+Whcv5QBJtvd8sMh6rkptYYAzun0mWdN4mVaLuIVCY+Hh6MvgmyExyZyFqnmg/tD0b//Xl6jTu/glB4uZFz1NZtu7WhCr/ZZqYY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=swLQjKvz; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6099e707622so24523477b3.3 for ; Tue, 05 Mar 2024 17:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709688152; x=1710292952; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hWaHPf3ur6A4qCJxa5rb9778tyG9D1zv7n6pTIOMylY=; b=swLQjKvzg/27APMhBRnnxlopiH/s6Yw8Rc3gmJ1cRzO2DfvEZ9kJEcpCSsrQI3xsdn RTEbhpmJyX/7MQalwVDKFuMmUW6ByRtFNSR9W4qs6M0c0Tw3PIvJItqOS7FPmi6X7Xgx LBsukHf2AE2J4GKTq78QklDhOxUts4jy4X78MIy5oDkkLQ+f+GjdtNUXKdtHMgrgdoO1 SyDtjqfJNvvFrSmJGkVeaHjIzgez7GwqkPbIzIFvuDAHbT4WcoqRiqEeA+XgvkBZjSLt Eab3muGN9002jgAdhbe8V2yA/qr68TNM4kcHdg79e6uwXouz6t4tBJNtx72beEAlH5Hk Dvrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709688152; x=1710292952; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hWaHPf3ur6A4qCJxa5rb9778tyG9D1zv7n6pTIOMylY=; b=Wak0U1uZfQU674d3OoUVE6m6tXiNF7CP3fgmF/XTVUdOrKpnGhqj7ZwQRE/4/HY0WD QXreZHXDItL8VFjIHv0U7VVtIw+yywA0JPMTVCQuo4Il8Yv1+MdgBGH+DI/P4MdT0ZpI QHIGim6PZOUMck5IXKPT/1nO6yut02PnZPMzOie6hUIt8lEKbWfHQAipH0pOreimIWgs UA2FcEO2BmmyYxCkstuc5qfYa0T6kfCszSuMmdpcYRwquDwVna5sgurvNREG7JQutT9r QI2yJbvj/p0DAaoSLo8s4M80Vr+UeC2ExQ10tyUqwlnSsl2UlEZCrWk/paOyfLGMa6H2 HSjw== X-Forwarded-Encrypted: i=1; AJvYcCWDTJSSYtWVdNLPLvLgyKhVFiZrlEKqjyvcYXuylVOhDbPjhQmC6lMcLfjdcdDKxLiqgWrnadWzQGtPf6+IT8BAxdEjpda/Uv+kDw93 X-Gm-Message-State: AOJu0YyaRPKNfCTweH+r1kvlBXGg2VORb8uH8azHhKiDZvRyGY6V9hWV 7LY5BE7/VDwiaQz52ded043+ahNy+441f8mMjS1tPvgkoLAIvSNWClVY6n5fTE6ZPJzBGzDFenc qCd8Yz9QXag== X-Received: from ipylypiv.svl.corp.google.com ([2620:15c:2c5:13:69ff:df2c:aa81:7b74]) (user=ipylypiv job=sendgmr) by 2002:a05:690c:3508:b0:609:3212:94c7 with SMTP id fq8-20020a05690c350800b00609321294c7mr3942886ywb.6.1709688152470; Tue, 05 Mar 2024 17:22:32 -0800 (PST) Date: Tue, 5 Mar 2024 17:22:20 -0800 In-Reply-To: <20240306012226.3398927-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240306012226.3398927-1-ipylypiv@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240306012226.3398927-2-ipylypiv@google.com> Subject: [PATCH v7 1/7] ata: libata-sata: Factor out NCQ Priority configuration helpers From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel , John Garry , Jason Yan , "James E.J. Bottomley" , "Martin K. Petersen" , Jack Wang , Hannes Reinecke , Xiang Chen , Artur Paszkiewicz , Bart Van Assche Cc: TJ Adams , linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv Content-Type: text/plain; charset="UTF-8" Export libata NCQ Priority configuration helpers to be reused for libsas managed SATA devices. Acked-by: Damien Le Moal Reviewed-by: Jason Yan Signed-off-by: Igor Pylypiv --- drivers/ata/libata-sata.c | 140 +++++++++++++++++++++++++++----------- include/linux/libata.h | 6 ++ 2 files changed, 107 insertions(+), 39 deletions(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 0fb1934875f2..f00dd02dc6f8 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -848,80 +848,122 @@ DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, ata_scsi_lpm_show, ata_scsi_lpm_store); EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy); -static ssize_t ata_ncq_prio_supported_show(struct device *device, - struct device_attribute *attr, - char *buf) +/** + * ata_ncq_prio_supported - Check if device supports NCQ Priority + * @ap: ATA port of the target device + * @sdev: SCSI device + * @supported: Address of a boolean to store the result + * + * Helper to check if device supports NCQ Priority feature. + */ +int ata_ncq_prio_supported(struct ata_port *ap, struct scsi_device *sdev, + bool *supported) { - struct scsi_device *sdev = to_scsi_device(device); - struct ata_port *ap = ata_shost_to_port(sdev->host); struct ata_device *dev; - bool ncq_prio_supported; + unsigned long flags; int rc = 0; - spin_lock_irq(ap->lock); + spin_lock_irqsave(ap->lock, flags); dev = ata_scsi_find_dev(ap, sdev); if (!dev) rc = -ENODEV; else - ncq_prio_supported = dev->flags & ATA_DFLAG_NCQ_PRIO; - spin_unlock_irq(ap->lock); + *supported = dev->flags & ATA_DFLAG_NCQ_PRIO; + spin_unlock_irqrestore(ap->lock, flags); + return rc; +} +EXPORT_SYMBOL_GPL(ata_ncq_prio_supported); + +static ssize_t ata_ncq_prio_supported_show(struct device *device, + struct device_attribute *attr, + char *buf) +{ + struct scsi_device *sdev = to_scsi_device(device); + struct ata_port *ap = ata_shost_to_port(sdev->host); + bool supported; + int rc; - return rc ? rc : sysfs_emit(buf, "%u\n", ncq_prio_supported); + rc = ata_ncq_prio_supported(ap, sdev, &supported); + if (rc) + return rc; + + return sysfs_emit(buf, "%d\n", supported); } DEVICE_ATTR(ncq_prio_supported, S_IRUGO, ata_ncq_prio_supported_show, NULL); EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_supported); -static ssize_t ata_ncq_prio_enable_show(struct device *device, - struct device_attribute *attr, - char *buf) +/** + * ata_ncq_prio_enabled - Check if NCQ Priority is enabled + * @ap: ATA port of the target device + * @sdev: SCSI device + * @enabled: Address of a boolean to store the result + * + * Helper to check if NCQ Priority feature is enabled. + */ +int ata_ncq_prio_enabled(struct ata_port *ap, struct scsi_device *sdev, + bool *enabled) { - struct scsi_device *sdev = to_scsi_device(device); - struct ata_port *ap = ata_shost_to_port(sdev->host); struct ata_device *dev; - bool ncq_prio_enable; + unsigned long flags; int rc = 0; - spin_lock_irq(ap->lock); + spin_lock_irqsave(ap->lock, flags); dev = ata_scsi_find_dev(ap, sdev); if (!dev) rc = -ENODEV; else - ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED; - spin_unlock_irq(ap->lock); - - return rc ? rc : sysfs_emit(buf, "%u\n", ncq_prio_enable); + *enabled = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED; + spin_unlock_irqrestore(ap->lock, flags); + return rc; } +EXPORT_SYMBOL_GPL(ata_ncq_prio_enabled); -static ssize_t ata_ncq_prio_enable_store(struct device *device, - struct device_attribute *attr, - const char *buf, size_t len) +static ssize_t ata_ncq_prio_enable_show(struct device *device, + struct device_attribute *attr, + char *buf) { struct scsi_device *sdev = to_scsi_device(device); - struct ata_port *ap; - struct ata_device *dev; - long int input; - int rc = 0; + struct ata_port *ap = ata_shost_to_port(sdev->host); + bool enabled; + int rc; - rc = kstrtol(buf, 10, &input); + rc = ata_ncq_prio_enabled(ap, sdev, &enabled); if (rc) return rc; - if ((input < 0) || (input > 1)) - return -EINVAL; - ap = ata_shost_to_port(sdev->host); - dev = ata_scsi_find_dev(ap, sdev); - if (unlikely(!dev)) - return -ENODEV; + return sysfs_emit(buf, "%d\n", enabled); +} + +/** + * ata_ncq_prio_enable - Enable/disable NCQ Priority + * @ap: ATA port of the target device + * @sdev: SCSI device + * @enable: true - enable NCQ Priority, false - disable NCQ Priority + * + * Helper to enable/disable NCQ Priority feature. + */ +int ata_ncq_prio_enable(struct ata_port *ap, struct scsi_device *sdev, + bool enable) +{ + struct ata_device *dev; + unsigned long flags; + int rc = 0; + + spin_lock_irqsave(ap->lock, flags); - spin_lock_irq(ap->lock); + dev = ata_scsi_find_dev(ap, sdev); + if (!dev) { + rc = -ENODEV; + goto unlock; + } if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) { rc = -EINVAL; goto unlock; } - if (input) { + if (enable) { if (dev->flags & ATA_DFLAG_CDL_ENABLED) { ata_dev_err(dev, "CDL must be disabled to enable NCQ priority\n"); @@ -934,9 +976,29 @@ static ssize_t ata_ncq_prio_enable_store(struct device *device, } unlock: - spin_unlock_irq(ap->lock); + spin_unlock_irqrestore(ap->lock, flags); + return rc; +} +EXPORT_SYMBOL_GPL(ata_ncq_prio_enable); + +static ssize_t ata_ncq_prio_enable_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct scsi_device *sdev = to_scsi_device(device); + struct ata_port *ap = ata_shost_to_port(sdev->host); + bool enable; + int rc; + + rc = kstrtobool(buf, &enable); + if (rc) + return rc; + + rc = ata_ncq_prio_enable(ap, sdev, enable); + if (rc) + return rc; - return rc ? rc : len; + return len; } DEVICE_ATTR(ncq_prio_enable, S_IRUGO | S_IWUSR, diff --git a/include/linux/libata.h b/include/linux/libata.h index 26d68115afb8..6dd9a4f9ca7c 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1157,6 +1157,12 @@ extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth); extern int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, int queue_depth); +extern int ata_ncq_prio_supported(struct ata_port *ap, struct scsi_device *sdev, + bool *supported); +extern int ata_ncq_prio_enabled(struct ata_port *ap, struct scsi_device *sdev, + bool *enabled); +extern int ata_ncq_prio_enable(struct ata_port *ap, struct scsi_device *sdev, + bool enable); extern struct ata_device *ata_dev_pair(struct ata_device *adev); extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev); extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap); -- 2.44.0.278.ge034bb2e1d-goog