1 /*
2  * Copyright (C) 2015-2017 Netronome Systems, Inc.
3  *
4  * This software is dual licensed under the GNU General License Version 2,
5  * June 1991 as shown in the file COPYING in the top-level directory of this
6  * source tree or the BSD 2-Clause License provided below.  You have the
7  * option to license this software under the complete terms of either license.
8  *
9  * The BSD 2-Clause License:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      1. Redistributions of source code must retain the above
16  *         copyright notice, this list of conditions and the following
17  *         disclaimer.
18  *
19  *      2. Redistributions in binary form must reproduce the above
20  *         copyright notice, this list of conditions and the following
21  *         disclaimer in the documentation and/or other materials
22  *         provided with the distribution.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31  * SOFTWARE.
32  */
33 
34 /*
35  * nfp_main.h
36  * Author: Jason McMullan <jason.mcmullan@netronome.com>
37  */
38 
39 #ifndef NFP_MAIN_H
40 #define NFP_MAIN_H
41 
42 #include <linux/list.h>
43 #include <linux/types.h>
44 #include <linux/msi.h>
45 #include <linux/mutex.h>
46 #include <linux/pci.h>
47 #include <linux/workqueue.h>
48 
49 struct dentry;
50 struct device;
51 struct devlink_ops;
52 struct pci_dev;
53 
54 struct nfp_cpp;
55 struct nfp_cpp_area;
56 struct nfp_eth_table;
57 struct nfp_hwinfo;
58 struct nfp_mip;
59 struct nfp_net;
60 struct nfp_nsp_identify;
61 struct nfp_port;
62 struct nfp_rtsym_table;
63 
64 /**
65  * struct nfp_pf - NFP PF-specific device structure
66  * @pdev:		Backpointer to PCI device
67  * @cpp:		Pointer to the CPP handle
68  * @app:		Pointer to the APP handle
69  * @data_vnic_bar:	Pointer to the CPP area for the data vNICs' BARs
70  * @ctrl_vnic_bar:	Pointer to the CPP area for the ctrl vNIC's BAR
71  * @qc_area:		Pointer to the CPP area for the queues
72  * @mac_stats_bar:	Pointer to the CPP area for the MAC stats
73  * @mac_stats_mem:	Pointer to mapped MAC stats area
74  * @vf_cfg_bar:		Pointer to the CPP area for the VF configuration BAR
75  * @vf_cfg_mem:		Pointer to mapped VF configuration area
76  * @irq_entries:	Array of MSI-X entries for all vNICs
77  * @limit_vfs:		Number of VFs supported by firmware (~0 for PCI limit)
78  * @num_vfs:		Number of SR-IOV VFs enabled
79  * @fw_loaded:		Is the firmware loaded?
80  * @ctrl_vnic:		Pointer to the control vNIC if available
81  * @mip:		MIP handle
82  * @rtbl:		RTsym table
83  * @hwinfo:		HWInfo table
84  * @eth_tbl:		NSP ETH table
85  * @nspi:		NSP identification info
86  * @hwmon_dev:		pointer to hwmon device
87  * @ddir:		Per-device debugfs directory
88  * @max_data_vnics:	Number of data vNICs app firmware supports
89  * @num_vnics:		Number of vNICs spawned
90  * @vnics:		Linked list of vNIC structures (struct nfp_net)
91  * @ports:		Linked list of port structures (struct nfp_port)
92  * @wq:			Workqueue for running works which need to grab @lock
93  * @port_refresh_work:	Work entry for taking netdevs out
94  * @lock:		Protects all fields which may change after probe
95  */
96 struct nfp_pf {
97 	struct pci_dev *pdev;
98 
99 	struct nfp_cpp *cpp;
100 
101 	struct nfp_app *app;
102 
103 	struct nfp_cpp_area *data_vnic_bar;
104 	struct nfp_cpp_area *ctrl_vnic_bar;
105 	struct nfp_cpp_area *qc_area;
106 	struct nfp_cpp_area *mac_stats_bar;
107 	u8 __iomem *mac_stats_mem;
108 	struct nfp_cpp_area *vf_cfg_bar;
109 	u8 __iomem *vf_cfg_mem;
110 
111 	struct msix_entry *irq_entries;
112 
113 	unsigned int limit_vfs;
114 	unsigned int num_vfs;
115 
116 	bool fw_loaded;
117 
118 	struct nfp_net *ctrl_vnic;
119 
120 	const struct nfp_mip *mip;
121 	struct nfp_rtsym_table *rtbl;
122 	struct nfp_hwinfo *hwinfo;
123 	struct nfp_eth_table *eth_tbl;
124 	struct nfp_nsp_identify *nspi;
125 
126 	struct device *hwmon_dev;
127 
128 	struct dentry *ddir;
129 
130 	unsigned int max_data_vnics;
131 	unsigned int num_vnics;
132 
133 	struct list_head vnics;
134 	struct list_head ports;
135 
136 	struct workqueue_struct *wq;
137 	struct work_struct port_refresh_work;
138 
139 	struct mutex lock;
140 };
141 
142 extern struct pci_driver nfp_netvf_pci_driver;
143 
144 extern const struct devlink_ops nfp_devlink_ops;
145 
146 int nfp_net_pci_probe(struct nfp_pf *pf);
147 void nfp_net_pci_remove(struct nfp_pf *pf);
148 
149 int nfp_hwmon_register(struct nfp_pf *pf);
150 void nfp_hwmon_unregister(struct nfp_pf *pf);
151 
152 void nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_port *port);
153 
154 bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
155 
156 #endif /* NFP_MAIN_H */
157