GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / net / ethernet / netronome / nfp / 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/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  * @vfcfg_tbl2_area:    Pointer to the CPP area for the VF config table
77  * @vfcfg_tbl2:         Pointer to mapped VF config table
78  * @irq_entries:        Array of MSI-X entries for all vNICs
79  * @limit_vfs:          Number of VFs supported by firmware (~0 for PCI limit)
80  * @num_vfs:            Number of SR-IOV VFs enabled
81  * @fw_loaded:          Is the firmware loaded?
82  * @ctrl_vnic:          Pointer to the control vNIC if available
83  * @mip:                MIP handle
84  * @rtbl:               RTsym table
85  * @hwinfo:             HWInfo table
86  * @eth_tbl:            NSP ETH table
87  * @nspi:               NSP identification info
88  * @hwmon_dev:          pointer to hwmon device
89  * @ddir:               Per-device debugfs directory
90  * @max_data_vnics:     Number of data vNICs app firmware supports
91  * @num_vnics:          Number of vNICs spawned
92  * @vnics:              Linked list of vNIC structures (struct nfp_net)
93  * @ports:              Linked list of port structures (struct nfp_port)
94  * @wq:                 Workqueue for running works which need to grab @lock
95  * @port_refresh_work:  Work entry for taking netdevs out
96  * @lock:               Protects all fields which may change after probe
97  */
98 struct nfp_pf {
99         struct pci_dev *pdev;
100
101         struct nfp_cpp *cpp;
102
103         struct nfp_app *app;
104
105         struct nfp_cpp_area *data_vnic_bar;
106         struct nfp_cpp_area *ctrl_vnic_bar;
107         struct nfp_cpp_area *qc_area;
108         struct nfp_cpp_area *mac_stats_bar;
109         u8 __iomem *mac_stats_mem;
110         struct nfp_cpp_area *vf_cfg_bar;
111         u8 __iomem *vf_cfg_mem;
112         struct nfp_cpp_area *vfcfg_tbl2_area;
113         u8 __iomem *vfcfg_tbl2;
114
115         struct msix_entry *irq_entries;
116
117         unsigned int limit_vfs;
118         unsigned int num_vfs;
119
120         bool fw_loaded;
121
122         struct nfp_net *ctrl_vnic;
123
124         const struct nfp_mip *mip;
125         struct nfp_rtsym_table *rtbl;
126         struct nfp_hwinfo *hwinfo;
127         struct nfp_eth_table *eth_tbl;
128         struct nfp_nsp_identify *nspi;
129
130         struct device *hwmon_dev;
131
132         struct dentry *ddir;
133
134         unsigned int max_data_vnics;
135         unsigned int num_vnics;
136
137         struct list_head vnics;
138         struct list_head ports;
139
140         struct workqueue_struct *wq;
141         struct work_struct port_refresh_work;
142
143         struct mutex lock;
144 };
145
146 extern struct pci_driver nfp_netvf_pci_driver;
147
148 extern const struct devlink_ops nfp_devlink_ops;
149
150 int nfp_net_pci_probe(struct nfp_pf *pf);
151 void nfp_net_pci_remove(struct nfp_pf *pf);
152
153 int nfp_hwmon_register(struct nfp_pf *pf);
154 void nfp_hwmon_unregister(struct nfp_pf *pf);
155
156 void nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_port *port);
157
158 bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
159
160 #endif /* NFP_MAIN_H */