linux/drivers/net/ethernet/netronome/nfp/nic/main.c
Huayu Chen ca3daf437d nfp: correct cleanup related to DCB resources
This patch corrects two oversights relating to releasing resources
and DCB initialisation.

1. If mapping of the dcbcfg_tbl area fails: an error should be
   propagated, allowing partial initialisation (probe) to be unwound.

2. Conversely, if where dcbcfg_tbl is successfully mapped: it should
   be unmapped in nfp_nic_dcb_clean() which is called via various error
   cleanup paths, and shutdown or removal of the PCIE device.

Fixes: 9b7fe8046d ("nfp: add DCB IEEE support")
Signed-off-by: Huayu Chen <huayu.chen@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Link: https://lore.kernel.org/r/20230131163033.981937-1-simon.horman@corigine.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2023-02-01 19:57:30 -08:00

79 lines
1.7 KiB
C

// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright (C) 2017 Netronome Systems, Inc. */
#include "../nfpcore/nfp_cpp.h"
#include "../nfpcore/nfp_nsp.h"
#include "../nfp_app.h"
#include "../nfp_main.h"
#include "../nfp_net.h"
#include "main.h"
static int nfp_nic_init(struct nfp_app *app)
{
struct nfp_pf *pf = app->pf;
if (pf->eth_tbl && pf->max_data_vnics != pf->eth_tbl->count) {
nfp_err(pf->cpp, "ETH entries don't match vNICs (%d vs %d)\n",
pf->max_data_vnics, pf->eth_tbl->count);
return -EINVAL;
}
return 0;
}
static int nfp_nic_sriov_enable(struct nfp_app *app, int num_vfs)
{
return 0;
}
static void nfp_nic_sriov_disable(struct nfp_app *app)
{
}
static int nfp_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn)
{
return nfp_nic_dcb_init(nn);
}
static void nfp_nic_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
{
nfp_nic_dcb_clean(nn);
}
static int nfp_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
unsigned int id)
{
struct nfp_app_nic_private *app_pri = nn->app_priv;
int err;
err = nfp_app_nic_vnic_alloc(app, nn, id);
if (err)
return err;
if (sizeof(*app_pri)) {
nn->app_priv = kzalloc(sizeof(*app_pri), GFP_KERNEL);
if (!nn->app_priv)
return -ENOMEM;
}
return 0;
}
static void nfp_nic_vnic_free(struct nfp_app *app, struct nfp_net *nn)
{
kfree(nn->app_priv);
}
const struct nfp_app_type app_nic = {
.id = NFP_APP_CORE_NIC,
.name = "nic",
.init = nfp_nic_init,
.vnic_alloc = nfp_nic_vnic_alloc,
.vnic_free = nfp_nic_vnic_free,
.sriov_enable = nfp_nic_sriov_enable,
.sriov_disable = nfp_nic_sriov_disable,
.vnic_init = nfp_nic_vnic_init,
.vnic_clean = nfp_nic_vnic_clean,
};