From nobody Thu Sep 24 20:37:31 2026 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (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 CE9663B2FC8 for ; Mon, 21 Sep 2026 07:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789977101; cv=none; b=pxT+I2KcrUzRe24luLCFtW8+lB8oCXLSqpL73yxyz47SVkSK/udmFCU5rt78zDqjDFc4qUfYaI0yoLDNcAoNDTDWMtBAMzSIfNww8toRhAd9WpTF+xxyWWGvcxRrCDuj7UDEYbonzmPoBMRhgGlD2i9ZhoBhcAIpI8+xj+J1L2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789977101; c=relaxed/simple; bh=ESQNEvFfPzzRUgnfdqnXLHe/3SZO7zRarxf4L4yUZ1o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cqd8CoGAsfYmxSKwBo6KJezL3qXoTUggRUgoGMGsbb6pMF5tJHN+EF5Nd5VZduyB+7iNnP201C5EKWaIQM5pnQNivQzd+hag/w9UHclu1d/ph4Us0L1gY6YFmaULFkjqqdhwqGU7nEOYB/wrMMroPsjJzRpyNn5M2Vqmhmb5+yo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=J9WjsNCP; arc=none smtp.client-ip=113.46.200.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="J9WjsNCP" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=3F9Zbl7cldLKP/exScva/1zjnjVySMDwTKk76isZ55U=; b=J9WjsNCPCrZ7yuO/apKwYobkKyJlhwFmuy9Uioh5q/FGhjT8D7ip656zcC814T0QNxYNLzr4E MUm9FxSi2BvYZW2khVQZ1sE0RdAy5daWAAhI6HXDThkHeTlXukk1+tfe2dDFMOO0BqMqaIG/h9b torr1jqarWP4Ksal7NS65CQ= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4hpFVl6dL6z1T4JM; Mon, 21 Sep 2026 15:39:43 +0800 (CST) Received: from kwepemf200011.china.huawei.com (unknown [7.202.181.237]) by mail.maildlp.com (Postfix) with ESMTPS id 6A3A640579; Mon, 21 Sep 2026 15:51:32 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by kwepemf200011.china.huawei.com (7.202.181.237) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Mon, 21 Sep 2026 15:51:31 +0800 From: Weili Qian To: , <--to=herbert@gondor.apana.org.au>, <--to=zhangfei.gao@linaro.org>, <--to=wangzhou1@hisilicon.com>, <--cc=linux-crypto@vger.kernel.org> CC: , <--cc=huangchenghai2@huawei.com>, <--cc=liulongfang@huawei.com> Subject: [PATCH 1/2] uacce: add device usage sysfs interface Date: Mon, 21 Sep 2026 15:51:30 +0800 Message-ID: <20260921075131.1062155-2-qianweili@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260921075131.1062155-1-qianweili@huawei.com> References: <20260921075131.1062155-1-qianweili@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemf200011.china.huawei.com (7.202.181.237) Content-Type: text/plain; charset="utf-8" Userspace has no way to query the runtime usage of a UACCE device; it can only be inferred indirectly from queue state, which is neither accurate nor uniform across drivers. Add a read-only dev_usage sysfs attribute and a get_dev_usage callback in struct uacce_ops. A driver implementing the callback writes the current usage as a percentage (0-100) string into the caller-provided buffer and returns the number of bytes written; dev_usage_show() appends the trailing newline. The attribute is hidden via uacce_dev_is_visible() when the driver does not provide the callback. The corresponding ABI entry is added to Documentation/ABI/testing/ sysfs-driver-uacce. Signed-off-by: Weili Qian --- Documentation/ABI/testing/sysfs-driver-uacce | 9 +++++++++ drivers/misc/uacce/uacce.c | 19 +++++++++++++++++++ include/linux/uacce.h | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-driver-uacce b/Documentation/A= BI/testing/sysfs-driver-uacce index d3f0b8f3c589..3e4af4c1e5a9 100644 --- a/Documentation/ABI/testing/sysfs-driver-uacce +++ b/Documentation/ABI/testing/sysfs-driver-uacce @@ -55,3 +55,12 @@ Date: Feb 2020 KernelVersion: 5.7 Contact: linux-accelerators@lists.ozlabs.org Description: Size (bytes) of dus region queue file + +What: /sys/class/uacce//dev_usage +Date: Sep 2026 +KernelVersion: 7.3 +Contact: linux-accelerators@lists.ozlabs.org +Description: (R) Current usage of the device, reported as a driver-defi= ned + string of up to PAGE_SIZE - 1 bytes. Usage is expressed as= a + percentage (0-100). The attribute is hidden if the driver = does + not implement the get_dev_usage callback. diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 45521d4a56d1..545ba35a590b 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -433,6 +433,20 @@ static ssize_t isolate_strategy_store(struct device *d= ev, struct device_attribut return count; } =20 +static ssize_t dev_usage_show(struct device *dev, struct device_attribute = *attr, char *buf) +{ + struct uacce_device *uacce =3D to_uacce_device(dev); + int ret; + + ret =3D uacce->ops->get_dev_usage(uacce, buf, PAGE_SIZE - 1); + if (ret < 0) + return ret; + + buf[ret++] =3D '\n'; + + return ret; +} + static DEVICE_ATTR_RO(api); static DEVICE_ATTR_RO(flags); static DEVICE_ATTR_RO(available_instances); @@ -441,6 +455,7 @@ static DEVICE_ATTR_RO(region_mmio_size); static DEVICE_ATTR_RO(region_dus_size); static DEVICE_ATTR_RO(isolate); static DEVICE_ATTR_RW(isolate_strategy); +static DEVICE_ATTR_RO(dev_usage); =20 static struct attribute *uacce_dev_attrs[] =3D { &dev_attr_api.attr, @@ -451,6 +466,7 @@ static struct attribute *uacce_dev_attrs[] =3D { &dev_attr_region_dus_size.attr, &dev_attr_isolate.attr, &dev_attr_isolate_strategy.attr, + &dev_attr_dev_usage.attr, NULL, }; =20 @@ -474,6 +490,9 @@ static umode_t uacce_dev_is_visible(struct kobject *kob= j, if (attr =3D=3D &dev_attr_isolate.attr && !uacce->ops->get_isolate_state) return 0; =20 + if (attr =3D=3D &dev_attr_dev_usage.attr && !uacce->ops->get_dev_usage) + return 0; + return attr->mode; } =20 diff --git a/include/linux/uacce.h b/include/linux/uacce.h index e290c0269944..8f0b9765e4b6 100644 --- a/include/linux/uacce.h +++ b/include/linux/uacce.h @@ -34,6 +34,10 @@ struct uacce_qfile_region { * @get_isolate_state: get the device state after set the isolate strategy * @isolate_err_threshold_write: stored the isolate error threshold to the= device * @isolate_err_threshold_read: read the isolate error threshold value fro= m the device + * @get_dev_usage: get the device usage. Write a string describing current + * usage as a percentage (0-100) into @buf, at most @size + * bytes, without a trailing newline. Return the number of + * bytes written on success or a negative errno on failure. */ struct uacce_ops { int (*get_available_instances)(struct uacce_device *uacce); @@ -50,6 +54,7 @@ struct uacce_ops { enum uacce_dev_state (*get_isolate_state)(struct uacce_device *uacce); int (*isolate_err_threshold_write)(struct uacce_device *uacce, u32 num); u32 (*isolate_err_threshold_read)(struct uacce_device *uacce); + int (*get_dev_usage)(struct uacce_device *uacce, char *buf, int size); }; =20 /** --=20 2.43.0 From nobody Thu Sep 24 20:37:31 2026 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (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 D4B5344A3E6 for ; Mon, 21 Sep 2026 07:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789977103; cv=none; b=FU5FX9iHVMv8Eo96ZapAl2CZDpu3NrjLdo7rgp7S681AJAPh774H7ldTsY4gD8ebx1rt0as2AKQaJtAhBvclM19V3VQz383WiAbsa8qQKlUQuJurFL1VlW5GCQUjT0QfOPVwU/cjNMoPzkcZ+PgTp+6W//03nyShkdHsONEP60M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789977103; c=relaxed/simple; bh=1sPWSo/ze+34c6q6DLdKEF4oZ9Qog3eBvO+2iEs87JY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A7ogF9/6Nhvm+L8rgt7Hl95JDgr0W7wGBUEM6ubfHggr1nS8EcwAIlMhxw+HltCD4RmJXXBT6L3hH5IRV1U/5byKqsPnkMEQdbdSZyLex0d4I0qEP2ux5MCNy/coee1walwtufXGDAD1wiPiG+zlD0JVyqXgaeJaR9350Utxhdw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=HUVRPP9A; arc=none smtp.client-ip=113.46.200.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="HUVRPP9A" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=3OMOKHpD7ulr2m9IDnPxpFfRC91YhtYm/2SLkFlgfTA=; b=HUVRPP9A8UFsCVT9tT3c543xKpKNeC+y2zYTwidWFsARx9xRk0iRSEEw2ZNdhsDMIrKLVA+S+ XfumiSLokoIHDpsscgBEQn0fjQuwkieZ1mOfj+QSoha2/y7TTYsh6NDD6p3APmArq6fF+PGvC1K jj451b3Hw6UdTMT4XHak5R4= Received: from mail.maildlp.com (unknown [172.19.163.127]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4hpFWf6XdszmV8f; Mon, 21 Sep 2026 15:40:30 +0800 (CST) Received: from kwepemf200011.china.huawei.com (unknown [7.202.181.237]) by mail.maildlp.com (Postfix) with ESMTPS id CCB7540573; Mon, 21 Sep 2026 15:51:32 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by kwepemf200011.china.huawei.com (7.202.181.237) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Mon, 21 Sep 2026 15:51:32 +0800 From: Weili Qian To: , <--to=herbert@gondor.apana.org.au>, <--to=zhangfei.gao@linaro.org>, <--to=wangzhou1@hisilicon.com>, <--cc=linux-crypto@vger.kernel.org> CC: , <--cc=huangchenghai2@huawei.com>, <--cc=liulongfang@huawei.com> Subject: [PATCH 2/2] crypto: hisilicon/qm - implement uacce get_dev_usage callback Date: Mon, 21 Sep 2026 15:51:31 +0800 Message-ID: <20260921075131.1062155-3-qianweili@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260921075131.1062155-1-qianweili@huawei.com> References: <20260921075131.1062155-1-qianweili@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemf200011.china.huawei.com (7.202.181.237) Content-Type: text/plain; charset="utf-8" The HiSilicon QM driver does not implement the get_dev_usage callback, so the dev_usage sysfs attribute is hidden on its UACCE devices and userspace cannot query per-channel usage through sysfs. Implement hisi_qm_get_dev_usage and register it in uacce_qm_ops. For each channel the callback reads the channel-usage register and derives the usage via the existing qm_usage_percent() helper, moved to qm.c with a shared declaration in qm_common.h to avoid duplication. The channel-usage registers exist only on QM_HW_V5 and later, so the callback returns -ENODEV on older revisions. Signed-off-by: Weili Qian --- drivers/crypto/hisilicon/debugfs.c | 17 --------- drivers/crypto/hisilicon/qm.c | 52 ++++++++++++++++++++++++++++ drivers/crypto/hisilicon/qm_common.h | 1 + 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/drivers/crypto/hisilicon/debugfs.c b/drivers/crypto/hisilicon/= debugfs.c index 3ee6de16e3f1..83dfbe74e704 100644 --- a/drivers/crypto/hisilicon/debugfs.c +++ b/drivers/crypto/hisilicon/debugfs.c @@ -1040,23 +1040,6 @@ void hisi_qm_show_last_dfx_regs(struct hisi_qm *qm) } } =20 -static int qm_usage_percent(struct hisi_qm *qm, int chan_num) -{ - u32 val, used_bw, total_bw; - - val =3D readl(qm->io_base + QM_CHANNEL_USAGE_OFFSET + - chan_num * QM_CHANNEL_ADDR_INTRVL); - used_bw =3D lower_16_bits(val); - total_bw =3D upper_16_bits(val); - if (!total_bw) - return -EIO; - - if (total_bw <=3D used_bw) - return QM_MAX_DEV_USAGE; - - return (used_bw * QM_DEV_USAGE_RATE) / total_bw; -} - static int qm_usage_show(struct seq_file *s, void *unused) { struct hisi_qm *qm =3D s->private; diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index c01966a4a33f..6cd1e98dd9e3 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -2884,6 +2884,57 @@ static u32 hisi_qm_isolate_threshold_read(struct uac= ce_device *uacce) return qm->isolate_data.err_threshold; } =20 +int qm_usage_percent(struct hisi_qm *qm, int chan_idx) +{ + u32 val, used_bw, total_bw; + + val =3D readl(qm->io_base + QM_CHANNEL_USAGE_OFFSET + + chan_idx * QM_CHANNEL_ADDR_INTRVL); + used_bw =3D lower_16_bits(val); + total_bw =3D upper_16_bits(val); + if (!total_bw) + return -EIO; + + if (total_bw <=3D used_bw) + return QM_MAX_DEV_USAGE; + + return (used_bw * QM_DEV_USAGE_RATE) / total_bw; +} + +static int hisi_qm_get_dev_usage(struct uacce_device *uacce, char *buf, in= t size) +{ + struct hisi_qm *qm =3D uacce->priv; + struct qm_channel *channel_data =3D &qm->channel_data; + const char *sep =3D ""; + int ret, i, len =3D 0; + + if (qm->ver < QM_HW_V5) + return -ENODEV; + + ret =3D qm_pm_get_sync(qm); + if (ret) + return ret; + + for (i =3D 0; i < channel_data->channel_num; i++) { + ret =3D qm_usage_percent(qm, i); + if (ret < 0) + goto out; + + if (len >=3D size) + break; + + len +=3D scnprintf(buf + len, size - len, "%s%s: %d", + sep, channel_data->channel_name[i], ret); + sep =3D "\n"; + } + + ret =3D len; +out: + qm_pm_put_sync(qm); + + return ret; +} + static const struct uacce_ops uacce_qm_ops =3D { .get_available_instances =3D hisi_qm_get_available_instances, .get_queue =3D hisi_qm_uacce_get_queue, @@ -2896,6 +2947,7 @@ static const struct uacce_ops uacce_qm_ops =3D { .get_isolate_state =3D hisi_qm_get_isolate_state, .isolate_err_threshold_write =3D hisi_qm_isolate_threshold_write, .isolate_err_threshold_read =3D hisi_qm_isolate_threshold_read, + .get_dev_usage =3D hisi_qm_get_dev_usage, }; =20 static void qm_remove_uacce(struct hisi_qm *qm) diff --git a/drivers/crypto/hisilicon/qm_common.h b/drivers/crypto/hisilico= n/qm_common.h index 0760bf55f13e..78bcf40bd851 100644 --- a/drivers/crypto/hisilicon/qm_common.h +++ b/drivers/crypto/hisilicon/qm_common.h @@ -75,5 +75,6 @@ struct qm_aeqc { int qm_set_and_get_xqc(struct hisi_qm *qm, u8 cmd, void *xqc, u32 qp_id, b= ool op); void hisi_qm_show_last_dfx_regs(struct hisi_qm *qm); void hisi_qm_set_algqos_init(struct hisi_qm *qm); +int qm_usage_percent(struct hisi_qm *qm, int chan_idx); =20 #endif --=20 2.43.0