drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c- Extension
.c- Size
- 8919 bytes
- Lines
- 312
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/errno.hlinux/etherdevice.hlinux/if_link.hlinux/if_ether.hnfpcore/nfp_cpp.hnfp_app.hnfp_main.hnfp_net_ctrl.hnfp_net.hnfp_net_sriov.h
Detected Declarations
function nfp_net_sriov_checkfunction nfp_net_sriov_updatefunction nfp_app_set_vf_macfunction nfp_app_set_vf_vlanfunction nfp_app_set_vf_ratefunction nfp_app_set_vf_spoofchkfunction nfp_app_set_vf_trustfunction nfp_app_set_vf_link_statefunction nfp_app_get_vf_config
Annotated Snippet
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright (C) 2017-2019 Netronome Systems, Inc. */
#include <linux/bitfield.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/if_link.h>
#include <linux/if_ether.h>
#include "nfpcore/nfp_cpp.h"
#include "nfp_app.h"
#include "nfp_main.h"
#include "nfp_net_ctrl.h"
#include "nfp_net.h"
#include "nfp_net_sriov.h"
static int
nfp_net_sriov_check(struct nfp_app *app, int vf, u16 cap, const char *msg, bool warn)
{
u16 cap_vf;
if (!app || !app->pf->vfcfg_tbl2)
return -EOPNOTSUPP;
cap_vf = readw(app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_CAP);
if ((cap_vf & cap) != cap) {
if (warn)
nfp_warn(app->pf->cpp, "ndo_set_vf_%s not supported\n", msg);
return -EOPNOTSUPP;
}
if (vf < 0 || vf >= app->pf->num_vfs) {
if (warn)
nfp_warn(app->pf->cpp, "invalid VF id %d\n", vf);
return -EINVAL;
}
return 0;
}
static int
nfp_net_sriov_update(struct nfp_app *app, int vf, u16 update, const char *msg)
{
struct nfp_net *nn;
int ret;
/* Write update info to mailbox in VF config symbol */
writeb(vf, app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_VF_NUM);
writew(update, app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_UPD);
nn = list_first_entry(&app->pf->vnics, struct nfp_net, vnic_list);
/* Signal VF reconfiguration */
ret = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_VF);
if (ret)
return ret;
ret = readw(app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_RET);
if (ret)
nfp_warn(app->pf->cpp,
"FW refused VF %s update with errno: %d\n", msg, ret);
return -ret;
}
int nfp_app_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
{
struct nfp_app *app = nfp_app_from_netdev(netdev);
unsigned int vf_offset;
int err;
err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_MAC, "mac", true);
if (err)
return err;
if (is_multicast_ether_addr(mac)) {
nfp_warn(app->pf->cpp,
"invalid Ethernet address %pM for VF id %d\n",
mac, vf);
return -EINVAL;
}
/* Write MAC to VF entry in VF config symbol */
vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ;
writel(get_unaligned_be32(mac), app->pf->vfcfg_tbl2 + vf_offset);
writew(get_unaligned_be16(mac + 4),
app->pf->vfcfg_tbl2 + vf_offset + NFP_NET_VF_CFG_MAC_LO);
err = nfp_net_sriov_update(app, vf, NFP_NET_VF_CFG_MB_UPD_MAC, "MAC");
if (!err)
nfp_info(app->pf->cpp,
"MAC %pM set on VF %d, reload the VF driver to make this change effective.\n",
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/errno.h`, `linux/etherdevice.h`, `linux/if_link.h`, `linux/if_ether.h`, `nfpcore/nfp_cpp.h`, `nfp_app.h`, `nfp_main.h`.
- Detected declarations: `function nfp_net_sriov_check`, `function nfp_net_sriov_update`, `function nfp_app_set_vf_mac`, `function nfp_app_set_vf_vlan`, `function nfp_app_set_vf_rate`, `function nfp_app_set_vf_spoofchk`, `function nfp_app_set_vf_trust`, `function nfp_app_set_vf_link_state`, `function nfp_app_get_vf_config`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.