Release 4.15 drivers/net/ethernet/mellanox/mlx5/core/sriov.c
  
  
  
/*
 * Copyright (c) 2014, Mellanox Technologies inc.  All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#include <linux/pci.h>
#include <linux/mlx5/driver.h>
#include <linux/mlx5/vport.h>
#include "mlx5_core.h"
#include "eswitch.h"
bool mlx5_sriov_is_enabled(struct mlx5_core_dev *dev)
{
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	return !!sriov->num_vfs;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Aviv Heller | 29 | 100.00% | 1 | 100.00% | 
| Total | 29 | 100.00% | 1 | 100.00% | 
static int sriov_restore_guids(struct mlx5_core_dev *dev, int vf)
{
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	struct mlx5_hca_vport_context *in;
	int err = 0;
	/* Restore sriov guid and policy settings */
	if (sriov->vfs_ctx[vf].node_guid ||
	    sriov->vfs_ctx[vf].port_guid ||
	    sriov->vfs_ctx[vf].policy != MLX5_POLICY_INVALID) {
		in = kzalloc(sizeof(*in), GFP_KERNEL);
		if (!in)
			return -ENOMEM;
		in->node_guid = sriov->vfs_ctx[vf].node_guid;
		in->port_guid = sriov->vfs_ctx[vf].port_guid;
		in->policy = sriov->vfs_ctx[vf].policy;
		in->field_select =
			!!(in->port_guid) * MLX5_HCA_VPORT_SEL_PORT_GUID |
			!!(in->node_guid) * MLX5_HCA_VPORT_SEL_NODE_GUID |
			!!(in->policy) * MLX5_HCA_VPORT_SEL_STATE_POLICY;
		err = mlx5_core_modify_hca_vport_context(dev, 1, 1, vf + 1, in);
		if (err)
			mlx5_core_warn(dev, "modify vport context failed, unable to restore VF %d settings\n", vf);
		kfree(in);
	}
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Bodong Wang | 203 | 100.00% | 1 | 100.00% | 
| Total | 203 | 100.00% | 1 | 100.00% | 
static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
{
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	int err;
	int vf;
	if (sriov->enabled_vfs) {
		mlx5_core_warn(dev,
			       "failed to enable SRIOV on device, already enabled with %d vfs\n",
			       sriov->enabled_vfs);
		return -EBUSY;
	}
	err = mlx5_eswitch_enable_sriov(dev->priv.eswitch, num_vfs, SRIOV_LEGACY);
	if (err) {
		mlx5_core_warn(dev,
			       "failed to enable eswitch SRIOV (%d)\n", err);
		return err;
	}
	for (vf = 0; vf < num_vfs; vf++) {
		err = mlx5_core_enable_hca(dev, vf + 1);
		if (err) {
			mlx5_core_warn(dev, "failed to enable VF %d (%d)\n", vf, err);
			continue;
		}
		sriov->vfs_ctx[vf].enabled = 1;
		sriov->enabled_vfs++;
		if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) {
			err = sriov_restore_guids(dev, vf);
			if (err) {
				mlx5_core_warn(dev,
					       "failed to restore VF %d settings, err %d\n",
					       vf, err);
				continue;
			}
		}
		mlx5_core_dbg(dev, "successfully enabled VF* %d\n", vf);
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 85 | 42.50% | 1 | 33.33% | 
| Mohamad Haj Yahia | 75 | 37.50% | 1 | 33.33% | 
| Bodong Wang | 40 | 20.00% | 1 | 33.33% | 
| Total | 200 | 100.00% | 3 | 100.00% | 
static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev)
{
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	int err;
	int vf;
	if (!sriov->enabled_vfs)
		goto out;
	for (vf = 0; vf < sriov->num_vfs; vf++) {
		if (!sriov->vfs_ctx[vf].enabled)
			continue;
		err = mlx5_core_disable_hca(dev, vf + 1);
		if (err) {
			mlx5_core_warn(dev, "failed to disable VF %d\n", vf);
			continue;
		}
		sriov->vfs_ctx[vf].enabled = 0;
		sriov->enabled_vfs--;
	}
out:
	mlx5_eswitch_disable_sriov(dev->priv.eswitch);
	if (mlx5_wait_for_vf_pages(dev))
		mlx5_core_warn(dev, "timeout reclaiming VFs pages\n");
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 76 | 55.47% | 1 | 25.00% | 
| Mohamad Haj Yahia | 56 | 40.88% | 1 | 25.00% | 
| Eran Ben Elisha | 3 | 2.19% | 1 | 25.00% | 
| Saeed Mahameed | 2 | 1.46% | 1 | 25.00% | 
| Total | 137 | 100.00% | 4 | 100.00% | 
static int mlx5_pci_enable_sriov(struct pci_dev *pdev, int num_vfs)
{
	struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
	int err = 0;
	if (pci_num_vf(pdev)) {
		mlx5_core_warn(dev, "Unable to enable pci sriov, already enabled\n");
		return -EBUSY;
	}
	err = pci_enable_sriov(pdev, num_vfs);
	if (err)
		mlx5_core_warn(dev, "pci_enable_sriov failed : %d\n", err);
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 59 | 79.73% | 1 | 50.00% | 
| Mohamad Haj Yahia | 15 | 20.27% | 1 | 50.00% | 
| Total | 74 | 100.00% | 2 | 100.00% | 
static void mlx5_pci_disable_sriov(struct pci_dev *pdev)
{
	pci_disable_sriov(pdev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Mohamad Haj Yahia | 12 | 75.00% | 1 | 50.00% | 
| Eli Cohen | 4 | 25.00% | 1 | 50.00% | 
| Total | 16 | 100.00% | 2 | 100.00% | 
static int mlx5_sriov_enable(struct pci_dev *pdev, int num_vfs)
{
	struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	int err = 0;
	err = mlx5_device_enable_sriov(dev, num_vfs);
	if (err) {
		mlx5_core_warn(dev, "mlx5_device_enable_sriov failed : %d\n", err);
		return err;
	}
	err = mlx5_pci_enable_sriov(pdev, num_vfs);
	if (err) {
		mlx5_core_warn(dev, "mlx5_pci_enable_sriov failed : %d\n", err);
		mlx5_device_disable_sriov(dev);
		return err;
	}
	sriov->num_vfs = num_vfs;
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 72 | 66.06% | 1 | 50.00% | 
| Mohamad Haj Yahia | 37 | 33.94% | 1 | 50.00% | 
| Total | 109 | 100.00% | 2 | 100.00% | 
static void mlx5_sriov_disable(struct pci_dev *pdev)
{
	struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	mlx5_pci_disable_sriov(pdev);
	mlx5_device_disable_sriov(dev);
	sriov->num_vfs = 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 35 | 71.43% | 1 | 50.00% | 
| Mohamad Haj Yahia | 14 | 28.57% | 1 | 50.00% | 
| Total | 49 | 100.00% | 2 | 100.00% | 
int mlx5_core_sriov_configure(struct pci_dev *pdev, int num_vfs)
{
	struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
	int err = 0;
	mlx5_core_dbg(dev, "requested num_vfs %d\n", num_vfs);
	if (!mlx5_core_is_pf(dev))
		return -EPERM;
	if (num_vfs) {
		int ret;
		ret = mlx5_lag_forbid(dev);
		if (ret && (ret != -ENODEV))
			return ret;
	}
	if (num_vfs) {
		err = mlx5_sriov_enable(pdev, num_vfs);
	} else {
		mlx5_sriov_disable(pdev);
		mlx5_lag_allow(dev);
	}
	return err ? err : num_vfs;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 65 | 57.02% | 1 | 20.00% | 
| Moni Shoua | 27 | 23.68% | 1 | 20.00% | 
| Aviv Heller | 12 | 10.53% | 1 | 20.00% | 
| Mohamad Haj Yahia | 9 | 7.89% | 1 | 20.00% | 
| Masanari Iida | 1 | 0.88% | 1 | 20.00% | 
| Total | 114 | 100.00% | 5 | 100.00% | 
int mlx5_sriov_attach(struct mlx5_core_dev *dev)
{
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	if (!mlx5_core_is_pf(dev) || !sriov->num_vfs)
		return 0;
	/* If sriov VFs exist in PCI level, enable them in device level */
	return mlx5_device_enable_sriov(dev, sriov->num_vfs);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Mohamad Haj Yahia | 49 | 100.00% | 1 | 100.00% | 
| Total | 49 | 100.00% | 1 | 100.00% | 
void mlx5_sriov_detach(struct mlx5_core_dev *dev)
{
	if (!mlx5_core_is_pf(dev))
		return;
	mlx5_device_disable_sriov(dev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Mohamad Haj Yahia | 24 | 100.00% | 1 | 100.00% | 
| Total | 24 | 100.00% | 1 | 100.00% | 
int mlx5_sriov_init(struct mlx5_core_dev *dev)
{
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	struct pci_dev *pdev = dev->pdev;
	int total_vfs;
	if (!mlx5_core_is_pf(dev))
		return 0;
	total_vfs = pci_sriov_get_totalvfs(pdev);
	sriov->num_vfs = pci_num_vf(pdev);
	sriov->vfs_ctx = kcalloc(total_vfs, sizeof(*sriov->vfs_ctx), GFP_KERNEL);
	if (!sriov->vfs_ctx)
		return -ENOMEM;
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 83 | 88.30% | 1 | 33.33% | 
| Mohamad Haj Yahia | 11 | 11.70% | 2 | 66.67% | 
| Total | 94 | 100.00% | 3 | 100.00% | 
void mlx5_sriov_cleanup(struct mlx5_core_dev *dev)
{
	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
	if (!mlx5_core_is_pf(dev))
		return;
	kfree(sriov->vfs_ctx);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 25 | 65.79% | 1 | 50.00% | 
| Mohamad Haj Yahia | 13 | 34.21% | 1 | 50.00% | 
| Total | 38 | 100.00% | 2 | 100.00% | 
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eli Cohen | 514 | 44.62% | 1 | 9.09% | 
| Mohamad Haj Yahia | 315 | 27.34% | 3 | 27.27% | 
| Bodong Wang | 246 | 21.35% | 1 | 9.09% | 
| Aviv Heller | 41 | 3.56% | 1 | 9.09% | 
| Moni Shoua | 27 | 2.34% | 1 | 9.09% | 
| Saeed Mahameed | 5 | 0.43% | 2 | 18.18% | 
| Eran Ben Elisha | 3 | 0.26% | 1 | 9.09% | 
| Masanari Iida | 1 | 0.09% | 1 | 9.09% | 
| Total | 1152 | 100.00% | 11 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.