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