1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */
3 
4 /*
5  * nfp_main.h
6  * Author: Jason McMullan <jason.mcmullan@netronome.com>
7  */
8 
9 #ifndef NFP_MAIN_H
10 #define NFP_MAIN_H
11 
12 #include <linux/ethtool.h>
13 #include <linux/list.h>
14 #include <linux/types.h>
15 #include <linux/msi.h>
16 #include <linux/pci.h>
17 #include <linux/workqueue.h>
18 #include <net/devlink.h>
19 
20 struct dentry;
21 struct device;
22 struct pci_dev;
23 
24 struct nfp_cpp;
25 struct nfp_cpp_area;
26 struct nfp_eth_table;
27 struct nfp_hwinfo;
28 struct nfp_mip;
29 struct nfp_net;
30 struct nfp_nsp_identify;
31 struct nfp_port;
32 struct nfp_rtsym;
33 struct nfp_rtsym_table;
34 struct nfp_shared_buf;
35 
36 /**
37  * struct nfp_dumpspec - NFP FW dump specification structure
38  * @size:	Size of the data
39  * @data:	Sequence of TLVs, each being an instruction to dump some data
40  *		from FW
41  */
42 struct nfp_dumpspec {
43 	u32 size;
44 	u8 data[];
45 };
46 
47 /**
48  * struct nfp_pf - NFP PF-specific device structure
49  * @pdev:		Backpointer to PCI device
50  * @dev_info:		NFP ASIC params
51  * @cpp:		Pointer to the CPP handle
52  * @app:		Pointer to the APP handle
53  * @data_vnic_bar:	Pointer to the CPP area for the data vNICs' BARs
54  * @ctrl_vnic_bar:	Pointer to the CPP area for the ctrl vNIC's BAR
55  * @qc_area:		Pointer to the CPP area for the queues
56  * @mac_stats_bar:	Pointer to the CPP area for the MAC stats
57  * @mac_stats_mem:	Pointer to mapped MAC stats area
58  * @vf_cfg_bar:		Pointer to the CPP area for the VF configuration BAR
59  * @vf_cfg_mem:		Pointer to mapped VF configuration area
60  * @vfcfg_tbl2_area:	Pointer to the CPP area for the VF config table
61  * @vfcfg_tbl2:		Pointer to mapped VF config table
62  * @mbox:		RTSym of per-PCI PF mailbox (under devlink lock)
63  * @irq_entries:	Array of MSI-X entries for all vNICs
64  * @limit_vfs:		Number of VFs supported by firmware (~0 for PCI limit)
65  * @num_vfs:		Number of SR-IOV VFs enabled
66  * @fw_loaded:		Is the firmware loaded?
67  * @unload_fw_on_remove:Do we need to unload firmware on driver removal?
68  * @sp_indiff:		Is the firmware indifferent to physical port speed?
69  * @ctrl_vnic:		Pointer to the control vNIC if available
70  * @mip:		MIP handle
71  * @rtbl:		RTsym table
72  * @hwinfo:		HWInfo table
73  * @dumpspec:		Debug dump specification
74  * @dump_flag:		Store dump flag between set_dump and get_dump_flag
75  * @dump_len:		Store dump length between set_dump and get_dump_flag
76  * @eth_tbl:		NSP ETH table
77  * @nspi:		NSP identification info
78  * @hwmon_dev:		pointer to hwmon device
79  * @ddir:		Per-device debugfs directory
80  * @max_data_vnics:	Number of data vNICs app firmware supports
81  * @num_vnics:		Number of vNICs spawned
82  * @vnics:		Linked list of vNIC structures (struct nfp_net)
83  * @ports:		Linked list of port structures (struct nfp_port)
84  * @wq:			Workqueue for running works which need to grab @lock
85  * @port_refresh_work:	Work entry for taking netdevs out
86  * @shared_bufs:	Array of shared buffer structures if FW has any SBs
87  * @num_shared_bufs:	Number of elements in @shared_bufs
88  *
89  * Fields which may change after proble are protected by devlink instance lock.
90  */
91 struct nfp_pf {
92 	struct pci_dev *pdev;
93 	const struct nfp_dev_info *dev_info;
94 
95 	struct nfp_cpp *cpp;
96 
97 	struct nfp_app *app;
98 
99 	struct nfp_cpp_area *data_vnic_bar;
100 	struct nfp_cpp_area *ctrl_vnic_bar;
101 	struct nfp_cpp_area *qc_area;
102 	struct nfp_cpp_area *mac_stats_bar;
103 	u8 __iomem *mac_stats_mem;
104 	struct nfp_cpp_area *vf_cfg_bar;
105 	u8 __iomem *vf_cfg_mem;
106 	struct nfp_cpp_area *vfcfg_tbl2_area;
107 	u8 __iomem *vfcfg_tbl2;
108 
109 	const struct nfp_rtsym *mbox;
110 
111 	struct msix_entry *irq_entries;
112 
113 	unsigned int limit_vfs;
114 	unsigned int num_vfs;
115 
116 	bool fw_loaded;
117 	bool unload_fw_on_remove;
118 	bool sp_indiff;
119 
120 	struct nfp_net *ctrl_vnic;
121 
122 	const struct nfp_mip *mip;
123 	struct nfp_rtsym_table *rtbl;
124 	struct nfp_hwinfo *hwinfo;
125 	struct nfp_dumpspec *dumpspec;
126 	u32 dump_flag;
127 	u32 dump_len;
128 	struct nfp_eth_table *eth_tbl;
129 	struct nfp_nsp_identify *nspi;
130 
131 	struct device *hwmon_dev;
132 
133 	struct dentry *ddir;
134 
135 	unsigned int max_data_vnics;
136 	unsigned int num_vnics;
137 
138 	struct list_head vnics;
139 	struct list_head ports;
140 
141 	struct workqueue_struct *wq;
142 	struct work_struct port_refresh_work;
143 
144 	struct nfp_shared_buf *shared_bufs;
145 	unsigned int num_shared_bufs;
146 };
147 
148 extern struct pci_driver nfp_netvf_pci_driver;
149 
150 extern const struct devlink_ops nfp_devlink_ops;
151 
152 int nfp_net_pci_probe(struct nfp_pf *pf);
153 void nfp_net_pci_remove(struct nfp_pf *pf);
154 
155 int nfp_hwmon_register(struct nfp_pf *pf);
156 void nfp_hwmon_unregister(struct nfp_pf *pf);
157 
158 void
159 nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev,
160 		     struct nfp_port *port);
161 
162 bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
163 
164 int nfp_pf_rtsym_read_optional(struct nfp_pf *pf, const char *format,
165 			       unsigned int default_val);
166 u8 __iomem *
167 nfp_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt,
168 		 unsigned int min_size, struct nfp_cpp_area **area);
169 int nfp_mbox_cmd(struct nfp_pf *pf, u32 cmd, void *in_data, u64 in_length,
170 		 void *out_data, u64 out_length);
171 int nfp_flash_update_common(struct nfp_pf *pf, const struct firmware *fw,
172 			    struct netlink_ext_ack *extack);
173 
174 enum nfp_dump_diag {
175 	NFP_DUMP_NSP_DIAG = 0,
176 };
177 
178 struct nfp_dumpspec *
179 nfp_net_dump_load_dumpspec(struct nfp_cpp *cpp, struct nfp_rtsym_table *rtbl);
180 s64 nfp_net_dump_calculate_size(struct nfp_pf *pf, struct nfp_dumpspec *spec,
181 				u32 flag);
182 int nfp_net_dump_populate_buffer(struct nfp_pf *pf, struct nfp_dumpspec *spec,
183 				 struct ethtool_dump *dump_param, void *dest);
184 
185 int nfp_shared_buf_register(struct nfp_pf *pf);
186 void nfp_shared_buf_unregister(struct nfp_pf *pf);
187 int nfp_shared_buf_pool_get(struct nfp_pf *pf, unsigned int sb, u16 pool_index,
188 			    struct devlink_sb_pool_info *pool_info);
189 int nfp_shared_buf_pool_set(struct nfp_pf *pf, unsigned int sb,
190 			    u16 pool_index, u32 size,
191 			    enum devlink_sb_threshold_type threshold_type);
192 
193 int nfp_devlink_params_register(struct nfp_pf *pf);
194 void nfp_devlink_params_unregister(struct nfp_pf *pf);
195 
196 unsigned int nfp_net_lr2speed(unsigned int linkrate);
197 unsigned int nfp_net_speed2lr(unsigned int speed);
198 #endif /* NFP_MAIN_H */
199