1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 /* Copyright (C) 2017 Netronome Systems, Inc. */ 3 4 #include "../nfpcore/nfp_cpp.h" 5 #include "../nfpcore/nfp_nsp.h" 6 #include "../nfp_app.h" 7 #include "../nfp_main.h" 8 #include "../nfp_net.h" 9 #include "main.h" 10 11 static int nfp_nic_init(struct nfp_app *app) 12 { 13 struct nfp_pf *pf = app->pf; 14 15 if (pf->eth_tbl && pf->max_data_vnics != pf->eth_tbl->count) { 16 nfp_err(pf->cpp, "ETH entries don't match vNICs (%d vs %d)\n", 17 pf->max_data_vnics, pf->eth_tbl->count); 18 return -EINVAL; 19 } 20 21 return 0; 22 } 23 24 static int nfp_nic_sriov_enable(struct nfp_app *app, int num_vfs) 25 { 26 return 0; 27 } 28 29 static void nfp_nic_sriov_disable(struct nfp_app *app) 30 { 31 } 32 33 static int nfp_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn) 34 { 35 nfp_nic_dcb_init(nn); 36 37 return 0; 38 } 39 40 static int nfp_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn, 41 unsigned int id) 42 { 43 struct nfp_app_nic_private *app_pri = nn->app_priv; 44 int err; 45 46 err = nfp_app_nic_vnic_alloc(app, nn, id); 47 if (err) 48 return err; 49 50 if (sizeof(*app_pri)) { 51 nn->app_priv = kzalloc(sizeof(*app_pri), GFP_KERNEL); 52 if (!nn->app_priv) 53 return -ENOMEM; 54 } 55 56 return 0; 57 } 58 59 static void nfp_nic_vnic_free(struct nfp_app *app, struct nfp_net *nn) 60 { 61 kfree(nn->app_priv); 62 } 63 64 const struct nfp_app_type app_nic = { 65 .id = NFP_APP_CORE_NIC, 66 .name = "nic", 67 68 .init = nfp_nic_init, 69 .vnic_alloc = nfp_nic_vnic_alloc, 70 .vnic_free = nfp_nic_vnic_free, 71 .sriov_enable = nfp_nic_sriov_enable, 72 .sriov_disable = nfp_nic_sriov_disable, 73 74 .vnic_init = nfp_nic_vnic_init, 75 }; 76