Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp2363977rwb; Fri, 5 Aug 2022 19:55:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR7VNsbt90t1KcaWE9Nv6UfYJaZmCqN1hOJn026UGxbHTxWwQQ2BNcJOZ9mkiMdP4sxzd2J0 X-Received: by 2002:a17:907:96a1:b0:730:e0bd:1420 with SMTP id hd33-20020a17090796a100b00730e0bd1420mr5834341ejc.83.1659754511058; Fri, 05 Aug 2022 19:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659754511; cv=none; d=google.com; s=arc-20160816; b=ZZk9XP2y+Hi/7MxvcTzI23dGsmEud4mFKulk97u5Sk4QTWg9SIShnLWord9fZD773Y Sn4ybVcidgbeDYtYYFT6AR7eUPDajFuqtcEP5DdJ7jBdI6Nfw6qDOs9yTy127PXx/W7B kv1+weWi++cZEWmR8aeDWd1E7L18pPZlBbHw1vbKQxI32o/NkofX9wLcmtP82XeOuQku vyB30v7mABMdg1WTrvWjYumOUQg7QjMNIT0tZB6z1/aDe4SzOrxsnTCFD82ZZm6Ce+n4 gkf0cFOoWptUpQD75l4ey8V1+DkWANc/ySielXCt2QVKfYE2PkV+cKJ7Vri9kr5IP8SJ u9Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5A4dduS4wjwVKzYStzG+2QujyaS9JUF5rFdvmJ0IcCE=; b=thhMGZSp8wAK8ZWVucYIHVyzDYnfHPSqXLn9cIgRPuoHMdH7sT1DwWungnIsNOO1+i 2m3G85mVueyc/oS7u1P2Watn1jv+q/goE6Oyb75e+HerU3RmA2qvFhEQRNi49I8Ex7Ge 4Rfso1pkknRCMAXid6h47bWJiC3rD13fGOKiNW7e8zo7lk7AweCQUtR3kXNvaqTVHgTw enLxiP+0l4BSsnHSemTiRxXUzpqpWKGn+ywJzkX0Fjzvm70SoVpZx+52a73Xf3Fdgh2d 8V1ii6iGbd/BEtA5XuneWh5Ow4vyxdFpfte0bDN13HaVBST76r6juDUQAk54VAyfru5x Bvfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z15-20020a05640240cf00b0043e14ec047bsi1377608edb.6.2022.08.05.19.54.46; Fri, 05 Aug 2022 19:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241709AbiHFChD (ORCPT + 99 others); Fri, 5 Aug 2022 22:37:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241607AbiHFCg4 (ORCPT ); Fri, 5 Aug 2022 22:36:56 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00BF87B7BB; Fri, 5 Aug 2022 19:36:53 -0700 (PDT) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4M063F0jgdz1M8Zr; Sat, 6 Aug 2022 10:33:45 +0800 (CST) Received: from dggpeml100012.china.huawei.com (7.185.36.121) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 6 Aug 2022 10:36:50 +0800 Received: from huawei.com (10.67.165.24) by dggpeml100012.china.huawei.com (7.185.36.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 6 Aug 2022 10:36:50 +0800 From: Kai Ye To: , CC: , , , , Subject: [PATCH v7 1/3] uacce: supports device isolation feature Date: Sat, 6 Aug 2022 10:29:41 +0800 Message-ID: <20220806022943.47292-2-yekai13@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220806022943.47292-1-yekai13@huawei.com> References: <20220806022943.47292-1-yekai13@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml100012.china.huawei.com (7.185.36.121) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org UACCE adds the hardware error isolation API. Users can configure the isolation frequency by this sysfs node. UACCE reports the device isolate state to the user space. If the AER error frequency exceeds the value of setting for a certain period of time, the device will be isolated. Signed-off-by: Kai Ye --- drivers/misc/uacce/uacce.c | 58 ++++++++++++++++++++++++++++++++++++++ include/linux/uacce.h | 11 ++++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 281c54003edc..41f454c89cd1 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -7,6 +7,8 @@ #include #include +#define MAX_ERR_ISOLATE_COUNT 65535 + static struct class *uacce_class; static dev_t uacce_devt; static DEFINE_MUTEX(uacce_mutex); @@ -339,12 +341,57 @@ static ssize_t region_dus_size_show(struct device *dev, uacce->qf_pg_num[UACCE_QFRT_DUS] << PAGE_SHIFT); } +static ssize_t isolate_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct uacce_device *uacce = to_uacce_device(dev); + + if (!uacce->ops->get_isolate_state) + return -ENODEV; + + return sysfs_emit(buf, "%d\n", uacce->ops->get_isolate_state(uacce)); +} + +static ssize_t isolate_strategy_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct uacce_device *uacce = to_uacce_device(dev); + u32 val; + + val = uacce->ops->isolate_strategy_read(uacce); + if (val > MAX_ERR_ISOLATE_COUNT) + return -EINVAL; + + return sysfs_emit(buf, "%u\n", val); +} + +static ssize_t isolate_strategy_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct uacce_device *uacce = to_uacce_device(dev); + unsigned long val; + int ret; + + if (kstrtoul(buf, 0, &val) < 0) + return -EINVAL; + + if (val > MAX_ERR_ISOLATE_COUNT) + return -EINVAL; + + ret = uacce->ops->isolate_strategy_write(uacce, val); + + return ret ? ret : count; +} + static DEVICE_ATTR_RO(api); static DEVICE_ATTR_RO(flags); static DEVICE_ATTR_RO(available_instances); static DEVICE_ATTR_RO(algorithms); 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 struct attribute *uacce_dev_attrs[] = { &dev_attr_api.attr, @@ -353,6 +400,8 @@ static struct attribute *uacce_dev_attrs[] = { &dev_attr_algorithms.attr, &dev_attr_region_mmio_size.attr, &dev_attr_region_dus_size.attr, + &dev_attr_isolate.attr, + &dev_attr_isolate_strategy.attr, NULL, }; @@ -368,6 +417,15 @@ static umode_t uacce_dev_is_visible(struct kobject *kobj, (!uacce->qf_pg_num[UACCE_QFRT_DUS]))) return 0; + if (attr == &dev_attr_isolate_strategy.attr && + (!uacce->ops->isolate_strategy_read || + !uacce->ops->isolate_strategy_write)) + return 0; + + if (attr == &dev_attr_isolate.attr && + !uacce->ops->get_isolate_state) + return 0; + return attr->mode; } diff --git a/include/linux/uacce.h b/include/linux/uacce.h index 48e319f40275..69e8f238d80c 100644 --- a/include/linux/uacce.h +++ b/include/linux/uacce.h @@ -30,6 +30,9 @@ struct uacce_qfile_region { * @is_q_updated: check whether the task is finished * @mmap: mmap addresses of queue to user space * @ioctl: ioctl for user space users of the queue + * @get_isolate_state: get the device state after set the isolate strategy + * @isolate_strategy_write: stored the isolate strategy to the device + * @isolate_strategy_read: read the isolate strategy value from the device */ struct uacce_ops { int (*get_available_instances)(struct uacce_device *uacce); @@ -43,6 +46,9 @@ struct uacce_ops { struct uacce_qfile_region *qfr); long (*ioctl)(struct uacce_queue *q, unsigned int cmd, unsigned long arg); + enum uacce_dev_state (*get_isolate_state)(struct uacce_device *uacce); + int (*isolate_strategy_write)(struct uacce_device *uacce, u32 freq); + u32 (*isolate_strategy_read)(struct uacce_device *uacce); }; /** @@ -57,6 +63,11 @@ struct uacce_interface { const struct uacce_ops *ops; }; +enum uacce_dev_state { + UACCE_DEV_NORMAL, + UACCE_DEV_ISOLATE, +}; + enum uacce_q_state { UACCE_Q_ZOMBIE = 0, UACCE_Q_INIT, -- 2.33.0