From patchwork Fri Nov 11 14:27:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 18860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp782122wru; Fri, 11 Nov 2022 06:47:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf58/hvnIfesExXDq185kf2tqOvIPO1KRTCwaIbieQauTZ0D2M3y3/r6iRtTHpU+VWOxx3U7 X-Received: by 2002:a17:907:c68a:b0:78d:860b:788f with SMTP id ue10-20020a170907c68a00b0078d860b788fmr1986548ejc.561.1668178071420; Fri, 11 Nov 2022 06:47:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178071; cv=none; d=google.com; s=arc-20160816; b=QAzrcpNu0rPDddVlHHauhrTcv5tHM3RxAe8Y9oCtUu0XD5mLOC9evOmnOcG9QKmMlB GACop9BHat244+5z//5h6FnPOc8tR/gtiMOeHyQJO2WjRROu9nK1i2d26/Fk00z/c9Fp RMSM+Cl88V2fS+FpvAk9Qv752x84AZ43wFLOHioMabdG91bHuDJqRAJP08ML+6968cLy GOQtQEDLazMRq1ptP2D/RJDiIq9XWNnmUEsq5lHDmZ0zCgCWAruWD1Cn3kcesBY/WY83 Ww78CAyWhCaPAwgWo5W54bGQJrfdNfC7vib41jsN6OFu72CsclC9uR1NH14s89ZZGcDj nThQ== 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=3/C1aL8+PvRjILigbqt9duU/DTbl295v1z+uX4u48m0=; b=oyqSyCWSN5L3YAXz2pexHVXSxi+fFu6Le+bJfFA30+jDN/gVu7YdsdFatW2K56e5uv R9XiEHhJ6dlSizYRoS7rKY9Lp+nbiUTTEQ9ozY/8JcvO1YIrLPBnyT0UBAvzmeJDlW+Z qj5/JekWAgXFbOHt55PEHSKt4+GAA6WQUIzO3kx+UBKJnVhAmm1mw7LAjfK/cNRlnBKM qIPC+Xmz3Z2GqEZbD3DNeL/49GPr7vkanEwF3hldbeRa9V8NRmzoZcP5+rGzxmtjCCRc GEhWWB34QeS3GLV3PxyUk7R96o/Xi9Y4qZejp5dBUPCYKf8/IMS5kMMLkhHjyCwAJacA ckTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o22-20020a509b16000000b00462e23be64fsi2013242edi.578.2022.11.11.06.47.27; Fri, 11 Nov 2022 06:47:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S234552AbiKKO1u (ORCPT + 99 others); Fri, 11 Nov 2022 09:27:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiKKO1b (ORCPT ); Fri, 11 Nov 2022 09:27:31 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 418F1BB4; Fri, 11 Nov 2022 06:27:31 -0800 (PST) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N81Ck5sMrzbngJ; Fri, 11 Nov 2022 22:23:46 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi100025.china.huawei.com (7.221.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 22:27:28 +0800 From: "Longpeng(Mike)" To: CC: , , , , , , , , Longpeng Subject: [RFC 4/4] pci/sriov: add sriov_scan_vf_id interface Date: Fri, 11 Nov 2022 22:27:22 +0800 Message-ID: <20221111142722.1172-5-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20221111142722.1172-1-longpeng2@huawei.com> References: <20221111142722.1172-1-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi100025.china.huawei.com (7.221.188.158) 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 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749211489053449435?= X-GMAIL-MSGID: =?utf-8?q?1749211489053449435?= From: Longpeng The users can add a specific VF through the sriov_scan_vf_id interface. For example: echo 4 > /sys/bus/pci/devices/0000\:65\:00.0/sriov_scan_vf_id ( Add VF4 into the system. ) Signed-off-by: Longpeng --- drivers/pci/iov.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index cb24d4b60e0d..2b585b3a9ad8 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -553,6 +553,51 @@ static ssize_t sriov_numvfs_no_scan_show(struct device *dev, return sriov_numvfs_show(dev, attr, buf); } +static ssize_t sriov_scan_vf_id_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + u16 vf_id; + ssize_t ret; + + if (kstrtou16(buf, 0, &vf_id) < 0) + return -EINVAL; + + device_lock(&pdev->dev); + + if (!pdev->sriov->num_VFs) { + ret = -ENOENT; + goto exit; + } + + if (vf_id >= pdev->sriov->num_VFs) { + ret = -ENODEV; + goto exit; + } + + if (test_bit(vf_id, pdev->sriov->vf_bitmap)) { + ret = -EEXIST; + goto exit; + } + + device_unlock(&pdev->dev); + + /* Already scanned VF0 when enabling VFs */ + if (vf_id == 0) + return count; + + ret = pci_iov_add_virtfn(pdev, vf_id); + if (ret < 0) + return ret; + + return count; + +exit: + device_unlock(&pdev->dev); + return ret; +} + static ssize_t sriov_offset_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -607,6 +652,7 @@ static ssize_t sriov_drivers_autoprobe_store(struct device *dev, static DEVICE_ATTR_RO(sriov_totalvfs); static DEVICE_ATTR_RW(sriov_numvfs); static DEVICE_ATTR_RW(sriov_numvfs_no_scan); +static DEVICE_ATTR_WO(sriov_scan_vf_id); static DEVICE_ATTR_RO(sriov_offset); static DEVICE_ATTR_RO(sriov_stride); static DEVICE_ATTR_RO(sriov_vf_device); @@ -616,6 +662,7 @@ static struct attribute *sriov_pf_dev_attrs[] = { &dev_attr_sriov_totalvfs.attr, &dev_attr_sriov_numvfs.attr, &dev_attr_sriov_numvfs_no_scan.attr, + &dev_attr_sriov_scan_vf_id.attr, &dev_attr_sriov_offset.attr, &dev_attr_sriov_stride.attr, &dev_attr_sriov_vf_device.attr,