Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2294216rwb; Fri, 11 Nov 2022 07:31:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf5nfAX0DD+CilwUdTsp9exfLYe2/Z8DaJatHx40+rqBta89p6BCSxDSuSNrlljvXWkhQAJB X-Received: by 2002:a17:906:a046:b0:741:5c0e:1058 with SMTP id bg6-20020a170906a04600b007415c0e1058mr2220373ejb.472.1668180717180; Fri, 11 Nov 2022 07:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668180717; cv=none; d=google.com; s=arc-20160816; b=t4+zIlBIh6qnNlfIeKDkRlIXpa02xKMR/9l+7lPAvvxrTp8kCKPkZRWbMRRfG5iyWv r32XLm/2PMfslffXobU1VQnmFIBXUYr9XfPI1Zt2eVjj5evTcMvjsoziNwlShdsiTgtd TcLL10mLJvmsvTzzgwZGDWRd+M/jV03S0YpyMTJiIAwPV+z45Mrxt+kYMWy4sfA77vIl PoOXoq32NobclV0rIb97IAcA4/TEt/oO6NwupQQOExPlr4wlSRmcTbp+Ea1joXQXzZpj ltBcNEAI5cQYoJXtJI6MPmgA59GEQRLLGxrk93d0oqxsdVSRhAcJXBiNiSUCOIoRFdgE xBCw== 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=paWB6LA4tvd+J1mXniXlZAfOslSPztEcV2p7IKlUSqs=; b=jC6bo7iOFlh/GlGf2okg+xZ1+7IyNVGrEgYfdGzJPf/bxP+WbnVh8tvl81Qnbp+urB 2hAJ44qyYbaoEEpnO/wXIw1viJXYA/jThvWWtc38uppCRUAmCN5ZaTteW6aae+ilSfkc V1BX8/z9+OjoGuYBHN22ncc7m7N+7ZzqND+dpXTXzEVpBWogYHDIrRB4XKWBCwtUVJ29 x6LZ5CzbKIlg7IFnXPAgq+VG+cjRrMoFg/1sQscU3YUv6/EWjzklRv44aPEAxHugmFuK T0cglCfAJtVA7L+GWQXSRpZKKlVnQTPUeUcvGXzJS0OedKV2nIr4EZD2l3uvVKCaDaRp RvbQ== 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 o15-20020a170906600f00b00782e85ae302si1738604ejj.574.2022.11.11.07.31.34; Fri, 11 Nov 2022 07:31:57 -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 S234416AbiKKO1h (ORCPT + 91 others); Fri, 11 Nov 2022 09:27:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbiKKO1a (ORCPT ); Fri, 11 Nov 2022 09:27:30 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257E11AD; Fri, 11 Nov 2022 06:27:29 -0800 (PST) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N81Hg1GfHzmVpr; Fri, 11 Nov 2022 22:27:11 +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:26 +0800 From: "Longpeng(Mike)" To: CC: , , , , , , , , Longpeng Subject: [RFC 1/4] pci/sriov: extract sriov_numvfs common helper Date: Fri, 11 Nov 2022 22:27:19 +0800 Message-ID: <20221111142722.1172-2-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 Extract a common helper to set sriov nums. Signed-off-by: Longpeng --- drivers/pci/iov.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 952217572113..3b441cd92960 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -406,23 +406,9 @@ static ssize_t sriov_numvfs_show(struct device *dev, return sysfs_emit(buf, "%u\n", num_vfs); } -/* - * num_vfs > 0; number of VFs to enable - * num_vfs = 0; disable all VFs - * - * Note: SRIOV spec does not allow partial VF - * disable, so it's all or none. - */ -static ssize_t sriov_numvfs_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int sriov_numvfs_common(struct pci_dev *pdev, u16 num_vfs) { - struct pci_dev *pdev = to_pci_dev(dev); int ret = 0; - u16 num_vfs; - - if (kstrtou16(buf, 0, &num_vfs) < 0) - return -EINVAL; if (num_vfs > pci_sriov_get_totalvfs(pdev)) return -ERANGE; @@ -471,6 +457,28 @@ static ssize_t sriov_numvfs_store(struct device *dev, exit: device_unlock(&pdev->dev); + return ret; +} + +/* + * num_vfs > 0; number of VFs to enable + * num_vfs = 0; disable all VFs + * + * Note: SRIOV spec does not allow partial VF + * disable, so it's all or none. + */ +static ssize_t sriov_numvfs_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + int ret; + u16 num_vfs; + + if (kstrtou16(buf, 0, &num_vfs) < 0) + return -EINVAL; + + ret = sriov_numvfs_common(pdev, num_vfs); if (ret < 0) return ret; -- 2.23.0