Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2295723rwb; Fri, 11 Nov 2022 07:32:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf577tSaeliEYMnCf4kMCgE6FTROc/t38SY8UuTgt3uzal91BfQG5yLrB1XRS/9EkdhXpLou X-Received: by 2002:a17:906:1954:b0:7ad:93df:db1e with SMTP id b20-20020a170906195400b007ad93dfdb1emr2265939eje.445.1668180772861; Fri, 11 Nov 2022 07:32:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668180772; cv=none; d=google.com; s=arc-20160816; b=LfEbLv3ppihhYieUcSgCp+vLxK121HTJoECUCqLnCfwqHrVBVpyC5zhNK1wkDCJhPT qfDtD/HK0WUTLIJ0h6cFwIn4tfu1R36qGPFbxdDnpq+QlmyYqwJYim56SWvhpvxYepNW gCFndHBWkl2segYz8sRIYXT65HLZ5HKdM5OkGGeh0JTUQNaA1ENN9llKsylg4wGsNlfX XiHEFEt+zjsHI+TQmRF9m3jLvyNV3LO0JZbalgt+jIQa5jQPzBlH8l8onGCUfXiIHvxL 1cuS1z58zS7VucXGlK/pxIUN8D2H5Tw3VWH1y1cRXqFura0Goo5NB8MeHk0UlN0QsLlI p/9w== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs24-20020a1709073e9800b0077945c44b7fsi2581548ejc.856.2022.11.11.07.32.30; Fri, 11 Nov 2022 07:32:52 -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 + 91 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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, -- 2.23.0