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 
nfp_nic_init(struct nfp_app * app)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 
nfp_nic_sriov_enable(struct nfp_app * app,int num_vfs)24 static int nfp_nic_sriov_enable(struct nfp_app *app, int num_vfs)
25 {
26 	return 0;
27 }
28 
nfp_nic_sriov_disable(struct nfp_app * app)29 static void nfp_nic_sriov_disable(struct nfp_app *app)
30 {
31 }
32 
nfp_nic_vnic_init(struct nfp_app * app,struct nfp_net * nn)33 static int nfp_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn)
34 {
35 	return nfp_nic_dcb_init(nn);
36 }
37 
nfp_nic_vnic_clean(struct nfp_app * app,struct nfp_net * nn)38 static void nfp_nic_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
39 {
40 	nfp_nic_dcb_clean(nn);
41 }
42 
nfp_nic_vnic_alloc(struct nfp_app * app,struct nfp_net * nn,unsigned int id)43 static int nfp_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
44 			      unsigned int id)
45 {
46 	struct nfp_app_nic_private *app_pri = nn->app_priv;
47 	int err;
48 
49 	err = nfp_app_nic_vnic_alloc(app, nn, id);
50 	if (err)
51 		return err;
52 
53 	if (sizeof(*app_pri)) {
54 		nn->app_priv = kzalloc(sizeof(*app_pri), GFP_KERNEL);
55 		if (!nn->app_priv)
56 			return -ENOMEM;
57 	}
58 
59 	return 0;
60 }
61 
nfp_nic_vnic_free(struct nfp_app * app,struct nfp_net * nn)62 static void nfp_nic_vnic_free(struct nfp_app *app, struct nfp_net *nn)
63 {
64 	kfree(nn->app_priv);
65 }
66 
67 const struct nfp_app_type app_nic = {
68 	.id		= NFP_APP_CORE_NIC,
69 	.name		= "nic",
70 
71 	.init		= nfp_nic_init,
72 	.vnic_alloc	= nfp_nic_vnic_alloc,
73 	.vnic_free	= nfp_nic_vnic_free,
74 	.sriov_enable	= nfp_nic_sriov_enable,
75 	.sriov_disable	= nfp_nic_sriov_disable,
76 
77 	.vnic_init      = nfp_nic_vnic_init,
78 	.vnic_clean     = nfp_nic_vnic_clean,
79 };
80