From patchwork Fri Nov 11 14:27:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 18857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp781652wru; Fri, 11 Nov 2022 06:46:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf7kcPoi1+OSEhhFRPnfk20Ykhfgy0w91HUh6yjYyGwICT/oUJhXCENf/bPQLgx3t2an02HB X-Received: by 2002:a17:906:3547:b0:7aa:40ea:faae with SMTP id s7-20020a170906354700b007aa40eafaaemr2052263eja.551.1668178019447; Fri, 11 Nov 2022 06:46:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178019; cv=none; d=google.com; s=arc-20160816; b=NJlqWJG3IJBK0x5tq8zRvs1IINxBw7VhjMnK1vAQKhPF8DgYGqertUJcySNsU1Zkyt O2DdanvIypqNR7AqqXRK67WlXl0M4D1nKGLel6SxKtZ7Ldutp78eU5amJG8wrNU7mpOf Yvxs7ResGn0WitfHSTVpRvmJIaHDPnjCjh1IGvGmwIDTcJ5UVAnXIt1OeHna5+bQ9SQF qSIpDo6BPcU+gOt4lxuwFWN4d8wm5be61ZzjnFmUcTM1Glr1ToShv2Ww4gSMmpntIfNG EekX5WCAMu9I1Hzt2HJ9kcbnLtruI0+OCtPTS8Q0VPh494uJfNoKU/vnMEYPw2oZCZul O69g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020aa7d2da000000b00461c43d1113si2052750edr.569.2022.11.11.06.46.34; Fri, 11 Nov 2022 06:46:59 -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 + 99 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 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?1749211434961563077?= X-GMAIL-MSGID: =?utf-8?q?1749211434961563077?= 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;