Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp251080lqg; Fri, 1 Mar 2024 04:23:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVPq7onJdRoWe/FHDz6cifNYkxDlKpdA1KhC4kiZriJi1JPQFgTwn1DpfaBWqiW/lDPQc4iu6GPcsisTsw7oQAMLqeF9cwvonZBKaw5Dw== X-Google-Smtp-Source: AGHT+IFSHnhloajl6gqmInhCPfVNH6d1pxUIr4Y8Ad7f1YQwM8+gbe76q03lmMS4eB3GfHU4AFX1 X-Received: by 2002:a05:6e02:1885:b0:365:24c1:c996 with SMTP id o5-20020a056e02188500b0036524c1c996mr1556138ilu.19.1709295780159; Fri, 01 Mar 2024 04:23:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709295780; cv=pass; d=google.com; s=arc-20160816; b=taGCAXWlleIVk9EDJU17s/UpL+2kldoea9Myt5yetg3wyapbq9mmvE2ra5urPXRpiL QexLWxUQNRbduTeebwJJRjWtdWgimmMw+hI+DjU5+7RKMaebDoYq32wYGUoniLqaK4hq oFu5UZy5pDHeB90GBtz0uszixYVXGzpfHxyn1ga6QaNNNMXgJQuMsBGPBTWXg3+tvY3x /zo4J/9ABgx+gCaHuOO54jUfYXCjcuSjzSFP/8eqYJTjnmrSfdKDoUHrk5vHlSsP+OHL Ujbj/aZbtqUdZq9LRh1qTRtdy9XMTw+clp7V5RzOYtz3Sk0bcsJkQXAdP4CvUZTX+o40 BHSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=eessbl0sHEzy8Q2donVrb1zcLEmpZ20mDzg4aLin/mU=; fh=egp9p2fZDzhl+ld6YZhjul19ncEX0a6Bo8MGejGaW6U=; b=koRmpOMWbNH1FjH5Pt0EPqo/Si7ikpqJL0sGUaInxmbV5xgChQ2GW97UvM3GAvtfVW y+ElRofXtqmFUaspVFsvM+Wr0H9i///9vFSUTaDpM2ELPpaRP/gyqFMGYN1we83JgtqT uQ9ALGl5eynESnTJ3RsauNVQMWaAU7UHGEL4l8xSxPg+5HNIUwD/SNpJXgUzbS5ngAfs haVug7TM0upe+Xt1RQZr/kRXYTQiJQrhBm9Bl9wo/SVuuYwMV0POHEA04R2ELNO+4pI4 0S2kz1PlQf6vALJaNobCEukVdbactBD2kl1nNtSbN+BjeFRRCz4CG3Jm7l1hyVrIk7fD Jkrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aqtMsfNA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88392-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88392-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r33-20020a635161000000b005e45abc35dfsi3376908pgl.239.2024.03.01.04.22.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 04:23:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88392-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aqtMsfNA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88392-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88392-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B4CF02884CB for ; Fri, 1 Mar 2024 12:22:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1ADFB6EB40; Fri, 1 Mar 2024 12:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aqtMsfNA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11FA26E5E3; Fri, 1 Mar 2024 12:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709295769; cv=none; b=nzoJ+22PDZ5wkuPvCTs9grt4bho6iA6TNpFhdIy58U7dAOyjXOQCD9GNjIDWBbcWlkrJnUY3xFP9NXfNGOYmzYetju73/oZQM0o724BOilTZFV9sIzifCeNoXFgu6WuW7kEq2eB9Sz5kTQRS+sF4ShIlOSB6NvZkL3N1r9mkH9g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709295769; c=relaxed/simple; bh=CRnowRjLCq+kORKKl47Vuo6OyiXmlws02WybHbJRUtY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oAml5Ac0dcXRDYR5E7LcJTaB+Pzhrcss4fXrznWDR/lX40yNOiqplrZOxWisWWRJamxHvxqcm1SCusPifzQQC/slEWBeeghNrdTvrASdNMSnbBiMbxcpmbPR1v5orF2JLmDJKD/+SAptLMYb5ZZ+5gL+GSGt6UvxWR74Xz9cer0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aqtMsfNA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 418F1C433C7; Fri, 1 Mar 2024 12:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709295768; bh=CRnowRjLCq+kORKKl47Vuo6OyiXmlws02WybHbJRUtY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=aqtMsfNAR2OO6tIf5w0VRZoJVrzX3aqu9nDKPy/fQofWPzDN+jOA9/9O3QYIHx5fM sR4xldaBJb+JkXylQffa4od2bwQlbZ2jqyyrE5oIpepMdLkr745POXouywD/2p6bDJ ICjmx33b2GDko/jaK9PjXi1gRxUv1H8JmZ4alqPqacM1VOunD422KE9k+Cyi8+cPYE 11uEe1QAhwA/W9BdfpmZHeRUOHRD8zDDGLS3rblgQN2DEwMnce3O+D7bApEaxew78v XmtjxTBNYohLRm5wk1g6D4RKH6irJE2tGlRbeAMWNGbWsg3Mm96tdR9SlQ0fNDUgAA 7eqikxGlZ4BQg== Message-ID: <85c669ac-8592-46c7-9716-1e76f5aae220@kernel.org> Date: Fri, 1 Mar 2024 04:22:47 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] scsi: libsas: Define NCQ Priority sysfs attributes for SATA devices Content-Language: en-US To: John Garry , Igor Pylypiv , Niklas Cassel , Jason Yan , "James E.J. Bottomley" , "Martin K. Petersen" , Jack Wang , Hannes Reinecke Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, TJ Adams References: <20240301013759.516817-1-ipylypiv@google.com> <20240301013759.516817-3-ipylypiv@google.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024/03/01 3:57, John Garry wrote: > On 01/03/2024 01:37, Igor Pylypiv wrote: >> Libata sysfs attributes cannot be used for libsas managed SATA devices >> because the ata_port location is different for libsas. >> >> Defined sysfs attributes (visible for SATA devices only): >> - /sys/block/*/device/sas_ncq_prio_enable >> - /sys/block/*/device/sas_ncq_prio_supported Please no ! I know that the Broadcom mpt3sas driver has this attribute named sas_ncq_prio_*, but I really think that it was a very unfortunate choice as that makes it different from the attribute for libata, which does not have the sas_ prefix. That means that an attribute controlling a *device* feature has 2 different name depending on the hba used for the device. That is super annoying to deal with in user space... So please, let's name this ncq_prio_*, same as for AHCI. SAS does have a concept of priority, but that is for data frames and has nothing to do with the actual command being transported. So mixing up sas and ncq in the same name is only confusing... For the Broadcom mpt3sas driver, we can define a link to have that same name for the attributes to have everything consistent. > > it would be good to show the full path > >> >> The newly defined attributes will pass the correct ata_port to libata >> helper functions. >> >> Signed-off-by: Igor Pylypiv >> Reviewed-by: TJ Adams >> --- >> drivers/scsi/libsas/sas_ata.c | 87 +++++++++++++++++++++++++++++++++++ >> include/scsi/sas_ata.h | 6 +++ >> 2 files changed, 93 insertions(+) >> >> diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c >> index 12e2653846e3..e0b19eee09b5 100644 >> --- a/drivers/scsi/libsas/sas_ata.c >> +++ b/drivers/scsi/libsas/sas_ata.c >> @@ -964,3 +964,90 @@ int sas_execute_ata_cmd(struct domain_device *device, u8 *fis, int force_phy_id) >> force_phy_id, &tmf_task); >> } >> EXPORT_SYMBOL_GPL(sas_execute_ata_cmd); >> + >> +static ssize_t sas_ncq_prio_supported_show(struct device *device, >> + struct device_attribute *attr, >> + char *buf) >> +{ >> + struct scsi_device *sdev = to_scsi_device(device); >> + struct domain_device *ddev = sdev_to_domain_dev(sdev); >> + int res; >> + >> + // This attribute shall be visible for SATA devices only > > Please don't use c99 comment style > >> + if (WARN_ON(!dev_is_sata(ddev))) >> + return -EINVAL; >> + >> + res = ata_ncq_prio_supported(ddev->sata_dev.ap, sdev); >> + if (res < 0) >> + return res; >> + >> + return sysfs_emit(buf, "%u\n", res); >> +} >> +static DEVICE_ATTR_RO(sas_ncq_prio_supported); >> + >> +static ssize_t sas_ncq_prio_enable_show(struct device *device, >> + struct device_attribute *attr, >> + char *buf) >> +{ >> + struct scsi_device *sdev = to_scsi_device(device); >> + struct domain_device *ddev = sdev_to_domain_dev(sdev); >> + int res; >> + >> + // This attribute shall be visible for SATA devices only >> + if (WARN_ON(!dev_is_sata(ddev))) >> + return -EINVAL; >> + >> + res = ata_ncq_prio_enabled(ddev->sata_dev.ap, sdev); >> + if (res < 0) >> + return res; >> + >> + return sysfs_emit(buf, "%u\n", res); >> +} >> + >> +static ssize_t sas_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 domain_device *ddev = sdev_to_domain_dev(sdev); >> + long input; >> + int res; >> + >> + // This attribute shall be visible for SATA devices only >> + if (WARN_ON(!dev_is_sata(ddev))) >> + return -EINVAL; >> + >> + res = kstrtol(buf, 10, &input); > > I think that kstrtobool_from_user() could be used. But > kstrtobool_from_user() handles more than 0/1, so that would be a > different behaviour, so maybe better not to use. > > I would also suggest factor out some of ata_ncq_prio_enable_store() with > this, but a public API which accepts char * would be a bit odd. kstrtobool() is I think the standard way of parsing bool sysfs attributes. > > >> + if (res) >> + return res; >> + if ((input < 0) || (input > 1)) >> + return -EINVAL; >> + >> + return ata_ncq_prio_enable(ddev->sata_dev.ap, sdev, input) ? : len; > > Please don't use ternary operator like this. This seems more > straightforfward: > > res = ata_ncq_prio_enable(); > if (res) > return res; > return len; > >> +} >> +static DEVICE_ATTR_RW(sas_ncq_prio_enable); >> + >> +static struct attribute *sas_ata_sdev_attrs[] = { >> + &dev_attr_sas_ncq_prio_supported.attr, >> + &dev_attr_sas_ncq_prio_enable.attr, >> + NULL >> +}; >> + >> +static umode_t sas_ata_attr_is_visible(struct kobject *kobj, >> + struct attribute *attr, int i) >> +{ >> + struct device *dev = kobj_to_dev(kobj); >> + struct scsi_device *sdev = to_scsi_device(dev); >> + struct domain_device *ddev = sdev_to_domain_dev(sdev); >> + >> + if (!dev_is_sata(ddev)) >> + return 0; >> + >> + return attr->mode; >> +} >> + >> +const struct attribute_group sas_ata_sdev_attr_group = { >> + .attrs = sas_ata_sdev_attrs, >> + .is_visible = sas_ata_attr_is_visible, >> +}; >> +EXPORT_SYMBOL_GPL(sas_ata_sdev_attr_group); >> diff --git a/include/scsi/sas_ata.h b/include/scsi/sas_ata.h >> index 2f8c719840a6..cded782fdf33 100644 >> --- a/include/scsi/sas_ata.h >> +++ b/include/scsi/sas_ata.h >> @@ -39,6 +39,8 @@ int smp_ata_check_ready_type(struct ata_link *link); >> int sas_discover_sata(struct domain_device *dev); >> int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *phy, >> struct domain_device *child, int phy_id); >> + >> +extern const struct attribute_group sas_ata_sdev_attr_group; >> #else >> >> static inline void sas_ata_disabled_notice(void) >> @@ -123,6 +125,10 @@ static inline int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *p >> sas_ata_disabled_notice(); >> return -ENODEV; >> } >> + >> +static const struct attribute_group sas_ata_sdev_attr_group = { >> + .attrs = NULL, >> +}; >> #endif >> >> #endif /* _SAS_ATA_H_ */ > -- Damien Le Moal Western Digital Research