linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "luobin (L)" <luobin9@huawei.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: <davem@davemloft.net>, <linux-kernel@vger.kernel.org>,
	<netdev@vger.kernel.org>, <luoxianjun@huawei.com>,
	<yin.yinshi@huawei.com>, <cloud.wangxiaoyun@huawei.com>
Subject: Re: [PATCH net-next 2/3] hinic: add sriov feature support
Date: Thu, 23 Apr 2020 20:17:32 +0800	[thread overview]
Message-ID: <f739eabf-4254-04ae-53e9-35a6ccf0c831@huawei.com> (raw)
In-Reply-To: <20200421112121.2f0ddf30@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>

These bit locks are mainly used for extendibility, and other opinions are accepted.Thanks for your review.

On 2020/4/22 2:21, Jakub Kicinski wrote:
> On Tue, 21 Apr 2020 04:56:34 +0000 Luo bin wrote:
>> +int hinic_pci_sriov_disable(struct pci_dev *pdev)
>> +{
>> +	struct hinic_sriov_info *sriov_info;
>> +	u16 tmp_vfs;
>> +
>> +	sriov_info = hinic_get_sriov_info_by_pcidev(pdev);
>> +	/* if SR-IOV is already disabled then nothing will be done */
>> +	if (!sriov_info->sriov_enabled)
>> +		return 0;
> Can't happen see below.
>
>> +	if (test_and_set_bit(HINIC_SRIOV_DISABLE, &sriov_info->state)) {
>> +		dev_err(&pdev->dev,
>> +			"SR-IOV disable in process, please wait");
>> +		return -EPERM;
>> +	}
> Hm. I don't understand why you need these bit locks.
>
>> +	/* If our VFs are assigned we cannot shut down SR-IOV
>> +	 * without causing issues, so just leave the hardware
>> +	 * available but disabled
>> +	 */
>> +	if (pci_vfs_assigned(sriov_info->pdev)) {
>> +		clear_bit(HINIC_SRIOV_DISABLE, &sriov_info->state);
>> +		dev_warn(&pdev->dev, "Unloading driver while VFs are assigned - VFs will not be deallocated\n");
>> +		return -EPERM;
>> +	}
>> +	sriov_info->sriov_enabled = false;
>> +
>> +	/* disable iov and allow time for transactions to clear */
>> +	pci_disable_sriov(sriov_info->pdev);
>> +
>> +	tmp_vfs = (u16)sriov_info->num_vfs;
>> +	sriov_info->num_vfs = 0;
>> +	hinic_deinit_vf_hw(sriov_info, OS_VF_ID_TO_HW(0),
>> +			   OS_VF_ID_TO_HW(tmp_vfs - 1));
>> +
>> +	clear_bit(HINIC_SRIOV_DISABLE, &sriov_info->state);
>> +
>> +	return 0;
>> +}
>> +
>> +int hinic_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
>> +{
>> +	struct hinic_sriov_info *sriov_info;
>> +	int pre_existing_vfs = 0;
>> +	int err = 0;
>> +
>> +	sriov_info = hinic_get_sriov_info_by_pcidev(pdev);
>> +
>> +	if (test_and_set_bit(HINIC_SRIOV_ENABLE, &sriov_info->state)) {
>> +		dev_err(&pdev->dev,
>> +			"SR-IOV enable in process, please wait, num_vfs %d\n",
>> +			num_vfs);
>> +		return -EPERM;
>> +	}
> This should never happen, PCI core code will prevent SR-IOV from being
> enabled twice in a row, and concurrently. See sriov_numvfs_store().
>
>> +	pre_existing_vfs = pci_num_vf(sriov_info->pdev);
>> +
>> +	if (num_vfs > pci_sriov_get_totalvfs(sriov_info->pdev)) {
>> +		clear_bit(HINIC_SRIOV_ENABLE, &sriov_info->state);
>> +		return -ERANGE;
>> +	}
> Again, can't happen.
>
>> +	if (pre_existing_vfs && pre_existing_vfs != num_vfs) {
>> +		err = hinic_pci_sriov_disable(sriov_info->pdev);
>> +		if (err) {
>> +			clear_bit(HINIC_SRIOV_ENABLE, &sriov_info->state);
>> +			return err;
>> +		}
> And this.
>
>> +	} else if (pre_existing_vfs == num_vfs) {
> Or this.
>
>> +		clear_bit(HINIC_SRIOV_ENABLE, &sriov_info->state);
>> +		return num_vfs;
>> +	}
>> +
>> +	err = pci_enable_sriov(sriov_info->pdev, num_vfs);
>> +	if (err) {
>> +		dev_err(&pdev->dev,
>> +			"Failed to enable SR-IOV, error %d\n", err);
>> +		clear_bit(HINIC_SRIOV_ENABLE, &sriov_info->state);
>> +		return err;
>> +	}
>> +
>> +	sriov_info->sriov_enabled = true;
>> +	sriov_info->num_vfs = num_vfs;
>> +	clear_bit(HINIC_SRIOV_ENABLE, &sriov_info->state);
>> +
>> +	return num_vfs;
>> +}
>> +
>> +int hinic_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
>> +{
>> +	struct hinic_sriov_info *sriov_info;
>> +
>> +	sriov_info = hinic_get_sriov_info_by_pcidev(dev);
>> +
>> +	if (test_bit(HINIC_FUNC_REMOVE, &sriov_info->state))
>> +		return -EFAULT;
> I don't think EFAULT is not a correct error code here. Use EBUSY, or
> ENODEV?
>
>> +	if (!num_vfs)
>> +		return hinic_pci_sriov_disable(dev);
>> +	else
>> +		return hinic_pci_sriov_enable(dev, num_vfs);
>> +}
> .

  reply	other threads:[~2020-04-23 12:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21  4:56 [PATCH net-next 0/3] hinic: add SR-IOV support Luo bin
2020-04-21  4:56 ` [PATCH net-next 1/3] hinic: add mailbox function support Luo bin
2020-04-21 18:13   ` Jakub Kicinski
2020-04-23 12:08     ` luobin (L)
2020-04-21  4:56 ` [PATCH net-next 2/3] hinic: add sriov feature support Luo bin
2020-04-21 18:21   ` Jakub Kicinski
2020-04-23 12:17     ` luobin (L) [this message]
2020-04-21  4:56 ` [PATCH net-next 3/3] hinic: add net_device_ops associated with vf Luo bin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f739eabf-4254-04ae-53e9-35a6ccf0c831@huawei.com \
    --to=luobin9@huawei.com \
    --cc=cloud.wangxiaoyun@huawei.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luoxianjun@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=yin.yinshi@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).