196de2506SJakub Kicinski // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
296de2506SJakub Kicinski /* Copyright (C) 2017 Netronome Systems, Inc. */
38aa0cb00SJakub Kicinski
48aa0cb00SJakub Kicinski #include "../nfpcore/nfp_cpp.h"
58aa0cb00SJakub Kicinski #include "../nfpcore/nfp_nsp.h"
68aa0cb00SJakub Kicinski #include "../nfp_app.h"
78aa0cb00SJakub Kicinski #include "../nfp_main.h"
89b7fe804SBin Chen #include "../nfp_net.h"
99b7fe804SBin Chen #include "main.h"
108aa0cb00SJakub Kicinski
nfp_nic_init(struct nfp_app * app)118aa0cb00SJakub Kicinski static int nfp_nic_init(struct nfp_app *app)
128aa0cb00SJakub Kicinski {
138aa0cb00SJakub Kicinski struct nfp_pf *pf = app->pf;
148aa0cb00SJakub Kicinski
158aa0cb00SJakub Kicinski if (pf->eth_tbl && pf->max_data_vnics != pf->eth_tbl->count) {
168aa0cb00SJakub Kicinski nfp_err(pf->cpp, "ETH entries don't match vNICs (%d vs %d)\n",
178aa0cb00SJakub Kicinski pf->max_data_vnics, pf->eth_tbl->count);
188aa0cb00SJakub Kicinski return -EINVAL;
198aa0cb00SJakub Kicinski }
208aa0cb00SJakub Kicinski
218aa0cb00SJakub Kicinski return 0;
228aa0cb00SJakub Kicinski }
238aa0cb00SJakub Kicinski
nfp_nic_sriov_enable(struct nfp_app * app,int num_vfs)2425528d90SPablo Cascón static int nfp_nic_sriov_enable(struct nfp_app *app, int num_vfs)
2525528d90SPablo Cascón {
2625528d90SPablo Cascón return 0;
2725528d90SPablo Cascón }
2825528d90SPablo Cascón
nfp_nic_sriov_disable(struct nfp_app * app)2925528d90SPablo Cascón static void nfp_nic_sriov_disable(struct nfp_app *app)
3025528d90SPablo Cascón {
3125528d90SPablo Cascón }
3225528d90SPablo Cascón
nfp_nic_vnic_init(struct nfp_app * app,struct nfp_net * nn)339b7fe804SBin Chen static int nfp_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn)
349b7fe804SBin Chen {
35*ca3daf43SHuayu Chen return nfp_nic_dcb_init(nn);
36*ca3daf43SHuayu Chen }
379b7fe804SBin Chen
nfp_nic_vnic_clean(struct nfp_app * app,struct nfp_net * nn)38*ca3daf43SHuayu Chen static void nfp_nic_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
39*ca3daf43SHuayu Chen {
40*ca3daf43SHuayu Chen nfp_nic_dcb_clean(nn);
419b7fe804SBin Chen }
429b7fe804SBin Chen
nfp_nic_vnic_alloc(struct nfp_app * app,struct nfp_net * nn,unsigned int id)439b7fe804SBin Chen static int nfp_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
449b7fe804SBin Chen unsigned int id)
459b7fe804SBin Chen {
469b7fe804SBin Chen struct nfp_app_nic_private *app_pri = nn->app_priv;
479b7fe804SBin Chen int err;
489b7fe804SBin Chen
499b7fe804SBin Chen err = nfp_app_nic_vnic_alloc(app, nn, id);
509b7fe804SBin Chen if (err)
519b7fe804SBin Chen return err;
529b7fe804SBin Chen
539b7fe804SBin Chen if (sizeof(*app_pri)) {
549b7fe804SBin Chen nn->app_priv = kzalloc(sizeof(*app_pri), GFP_KERNEL);
559b7fe804SBin Chen if (!nn->app_priv)
569b7fe804SBin Chen return -ENOMEM;
579b7fe804SBin Chen }
589b7fe804SBin Chen
599b7fe804SBin Chen return 0;
609b7fe804SBin Chen }
619b7fe804SBin Chen
nfp_nic_vnic_free(struct nfp_app * app,struct nfp_net * nn)629b7fe804SBin Chen static void nfp_nic_vnic_free(struct nfp_app *app, struct nfp_net *nn)
639b7fe804SBin Chen {
649b7fe804SBin Chen kfree(nn->app_priv);
659b7fe804SBin Chen }
669b7fe804SBin Chen
678aa0cb00SJakub Kicinski const struct nfp_app_type app_nic = {
688aa0cb00SJakub Kicinski .id = NFP_APP_CORE_NIC,
692707d6f1SJakub Kicinski .name = "nic",
708aa0cb00SJakub Kicinski
718aa0cb00SJakub Kicinski .init = nfp_nic_init,
729b7fe804SBin Chen .vnic_alloc = nfp_nic_vnic_alloc,
739b7fe804SBin Chen .vnic_free = nfp_nic_vnic_free,
7425528d90SPablo Cascón .sriov_enable = nfp_nic_sriov_enable,
7525528d90SPablo Cascón .sriov_disable = nfp_nic_sriov_disable,
769b7fe804SBin Chen
779b7fe804SBin Chen .vnic_init = nfp_nic_vnic_init,
78*ca3daf43SHuayu Chen .vnic_clean = nfp_nic_vnic_clean,
798aa0cb00SJakub Kicinski };
80