Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
[sfrench/cifs-2.6.git] / drivers / net / ethernet / netronome / nfp / nfpcore / nfp_nsp.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 #ifndef NSP_NSP_H
35 #define NSP_NSP_H 1
36
37 #include <linux/types.h>
38 #include <linux/if_ether.h>
39
40 struct firmware;
41 struct nfp_cpp;
42 struct nfp_nsp;
43
44 struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp);
45 void nfp_nsp_close(struct nfp_nsp *state);
46 u16 nfp_nsp_get_abi_ver_major(struct nfp_nsp *state);
47 u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state);
48 int nfp_nsp_wait(struct nfp_nsp *state);
49 int nfp_nsp_device_soft_reset(struct nfp_nsp *state);
50 int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw);
51 int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw);
52 int nfp_nsp_mac_reinit(struct nfp_nsp *state);
53
54 static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
55 {
56         return nfp_nsp_get_abi_ver_minor(state) > 20;
57 }
58
59 enum nfp_eth_interface {
60         NFP_INTERFACE_NONE      = 0,
61         NFP_INTERFACE_SFP       = 1,
62         NFP_INTERFACE_SFPP      = 10,
63         NFP_INTERFACE_SFP28     = 28,
64         NFP_INTERFACE_QSFP      = 40,
65         NFP_INTERFACE_CXP       = 100,
66         NFP_INTERFACE_QSFP28    = 112,
67 };
68
69 enum nfp_eth_media {
70         NFP_MEDIA_DAC_PASSIVE = 0,
71         NFP_MEDIA_DAC_ACTIVE,
72         NFP_MEDIA_FIBRE,
73 };
74
75 enum nfp_eth_aneg {
76         NFP_ANEG_AUTO = 0,
77         NFP_ANEG_SEARCH,
78         NFP_ANEG_25G_CONSORTIUM,
79         NFP_ANEG_25G_IEEE,
80         NFP_ANEG_DISABLED,
81 };
82
83 enum nfp_eth_fec {
84         NFP_FEC_AUTO_BIT = 0,
85         NFP_FEC_BASER_BIT,
86         NFP_FEC_REED_SOLOMON_BIT,
87         NFP_FEC_DISABLED_BIT,
88 };
89
90 #define NFP_FEC_AUTO            BIT(NFP_FEC_AUTO_BIT)
91 #define NFP_FEC_BASER           BIT(NFP_FEC_BASER_BIT)
92 #define NFP_FEC_REED_SOLOMON    BIT(NFP_FEC_REED_SOLOMON_BIT)
93 #define NFP_FEC_DISABLED        BIT(NFP_FEC_DISABLED_BIT)
94
95 /**
96  * struct nfp_eth_table - ETH table information
97  * @count:      number of table entries
98  * @max_index:  max of @index fields of all @ports
99  * @ports:      table of ports
100  *
101  * @ports.eth_index:    port index according to legacy ethX numbering
102  * @ports.index:        chip-wide first channel index
103  * @ports.nbi:          NBI index
104  * @ports.base:         first channel index (within NBI)
105  * @ports.lanes:        number of channels
106  * @ports.speed:        interface speed (in Mbps)
107  * @ports.interface:    interface (module) plugged in
108  * @ports.media:        media type of the @interface
109  * @ports.fec:          forward error correction mode
110  * @ports.aneg:         auto negotiation mode
111  * @ports.mac_addr:     interface MAC address
112  * @ports.label_port:   port id
113  * @ports.label_subport:  id of interface within port (for split ports)
114  * @ports.enabled:      is enabled?
115  * @ports.tx_enabled:   is TX enabled?
116  * @ports.rx_enabled:   is RX enabled?
117  * @ports.override_changed: is media reconfig pending?
118  *
119  * @ports.port_type:    one of %PORT_* defines for ethtool
120  * @ports.port_lanes:   total number of lanes on the port (sum of lanes of all
121  *                      subports)
122  * @ports.is_split:     is interface part of a split port
123  * @ports.fec_modes_supported:  bitmap of FEC modes supported
124  */
125 struct nfp_eth_table {
126         unsigned int count;
127         unsigned int max_index;
128         struct nfp_eth_table_port {
129                 unsigned int eth_index;
130                 unsigned int index;
131                 unsigned int nbi;
132                 unsigned int base;
133                 unsigned int lanes;
134                 unsigned int speed;
135
136                 unsigned int interface;
137                 enum nfp_eth_media media;
138
139                 enum nfp_eth_fec fec;
140                 enum nfp_eth_aneg aneg;
141
142                 u8 mac_addr[ETH_ALEN];
143
144                 u8 label_port;
145                 u8 label_subport;
146
147                 bool enabled;
148                 bool tx_enabled;
149                 bool rx_enabled;
150
151                 bool override_changed;
152
153                 /* Computed fields */
154                 u8 port_type;
155
156                 unsigned int port_lanes;
157
158                 bool is_split;
159
160                 unsigned int fec_modes_supported;
161         } ports[0];
162 };
163
164 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
165 struct nfp_eth_table *
166 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
167
168 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
169 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
170                            bool configed);
171 int
172 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
173
174 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
175 {
176         return !!eth_port->fec_modes_supported;
177 }
178
179 static inline unsigned int
180 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
181 {
182         return eth_port->fec_modes_supported;
183 }
184
185 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
186 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
187 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
188
189 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
190 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
191 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
192
193 /**
194  * struct nfp_nsp_identify - NSP static information
195  * @version:      opaque version string
196  * @flags:        version flags
197  * @br_primary:   branch id of primary bootloader
198  * @br_secondary: branch id of secondary bootloader
199  * @br_nsp:       branch id of NSP
200  * @primary:      version of primarary bootloader
201  * @secondary:    version id of secondary bootloader
202  * @nsp:          version id of NSP
203  * @sensor_mask:  mask of present sensors available on NIC
204  */
205 struct nfp_nsp_identify {
206         char version[40];
207         u8 flags;
208         u8 br_primary;
209         u8 br_secondary;
210         u8 br_nsp;
211         u16 primary;
212         u16 secondary;
213         u16 nsp;
214         u64 sensor_mask;
215 };
216
217 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
218
219 enum nfp_nsp_sensor_id {
220         NFP_SENSOR_CHIP_TEMPERATURE,
221         NFP_SENSOR_ASSEMBLY_POWER,
222         NFP_SENSOR_ASSEMBLY_12V_POWER,
223         NFP_SENSOR_ASSEMBLY_3V3_POWER,
224 };
225
226 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
227                           long *val);
228
229 #endif