18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/****************************************************************************
38c2ecf20Sopenharmony_ci * Driver for Solarflare network controllers and boards
48c2ecf20Sopenharmony_ci * Copyright 2014-2015 Solarflare Communications Inc.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#include <linux/module.h>
78c2ecf20Sopenharmony_ci#include "net_driver.h"
88c2ecf20Sopenharmony_ci#include "nic.h"
98c2ecf20Sopenharmony_ci#include "sriov.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciint efx_sriov_set_vf_mac(struct net_device *net_dev, int vf_i, u8 *mac)
128c2ecf20Sopenharmony_ci{
138c2ecf20Sopenharmony_ci	struct efx_nic *efx = netdev_priv(net_dev);
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci	if (efx->type->sriov_set_vf_mac)
168c2ecf20Sopenharmony_ci		return efx->type->sriov_set_vf_mac(efx, vf_i, mac);
178c2ecf20Sopenharmony_ci	else
188c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciint efx_sriov_set_vf_vlan(struct net_device *net_dev, int vf_i, u16 vlan,
228c2ecf20Sopenharmony_ci			  u8 qos, __be16 vlan_proto)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	struct efx_nic *efx = netdev_priv(net_dev);
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	if (efx->type->sriov_set_vf_vlan) {
278c2ecf20Sopenharmony_ci		if ((vlan & ~VLAN_VID_MASK) ||
288c2ecf20Sopenharmony_ci		    (qos & ~(VLAN_PRIO_MASK >> VLAN_PRIO_SHIFT)))
298c2ecf20Sopenharmony_ci			return -EINVAL;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci		if (vlan_proto != htons(ETH_P_8021Q))
328c2ecf20Sopenharmony_ci			return -EPROTONOSUPPORT;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci		return efx->type->sriov_set_vf_vlan(efx, vf_i, vlan, qos);
358c2ecf20Sopenharmony_ci	} else {
368c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
378c2ecf20Sopenharmony_ci	}
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciint efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf_i,
418c2ecf20Sopenharmony_ci			      bool spoofchk)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	struct efx_nic *efx = netdev_priv(net_dev);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	if (efx->type->sriov_set_vf_spoofchk)
468c2ecf20Sopenharmony_ci		return efx->type->sriov_set_vf_spoofchk(efx, vf_i, spoofchk);
478c2ecf20Sopenharmony_ci	else
488c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciint efx_sriov_get_vf_config(struct net_device *net_dev, int vf_i,
528c2ecf20Sopenharmony_ci			    struct ifla_vf_info *ivi)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	struct efx_nic *efx = netdev_priv(net_dev);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	if (efx->type->sriov_get_vf_config)
578c2ecf20Sopenharmony_ci		return efx->type->sriov_get_vf_config(efx, vf_i, ivi);
588c2ecf20Sopenharmony_ci	else
598c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciint efx_sriov_set_vf_link_state(struct net_device *net_dev, int vf_i,
638c2ecf20Sopenharmony_ci				int link_state)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	struct efx_nic *efx = netdev_priv(net_dev);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	if (efx->type->sriov_set_vf_link_state)
688c2ecf20Sopenharmony_ci		return efx->type->sriov_set_vf_link_state(efx, vf_i,
698c2ecf20Sopenharmony_ci							  link_state);
708c2ecf20Sopenharmony_ci	else
718c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
728c2ecf20Sopenharmony_ci}
73