GNU Linux-libre 4.14.251-gnu1
[releases.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
52 enum nfp_eth_interface {
53         NFP_INTERFACE_NONE      = 0,
54         NFP_INTERFACE_SFP       = 1,
55         NFP_INTERFACE_SFPP      = 10,
56         NFP_INTERFACE_SFP28     = 28,
57         NFP_INTERFACE_QSFP      = 40,
58         NFP_INTERFACE_CXP       = 100,
59         NFP_INTERFACE_QSFP28    = 112,
60 };
61
62 enum nfp_eth_media {
63         NFP_MEDIA_DAC_PASSIVE = 0,
64         NFP_MEDIA_DAC_ACTIVE,
65         NFP_MEDIA_FIBRE,
66 };
67
68 enum nfp_eth_aneg {
69         NFP_ANEG_AUTO = 0,
70         NFP_ANEG_SEARCH,
71         NFP_ANEG_25G_CONSORTIUM,
72         NFP_ANEG_25G_IEEE,
73         NFP_ANEG_DISABLED,
74 };
75
76 /**
77  * struct nfp_eth_table - ETH table information
78  * @count:      number of table entries
79  * @max_index:  max of @index fields of all @ports
80  * @ports:      table of ports
81  *
82  * @eth_index:  port index according to legacy ethX numbering
83  * @index:      chip-wide first channel index
84  * @nbi:        NBI index
85  * @base:       first channel index (within NBI)
86  * @lanes:      number of channels
87  * @speed:      interface speed (in Mbps)
88  * @interface:  interface (module) plugged in
89  * @media:      media type of the @interface
90  * @aneg:       auto negotiation mode
91  * @mac_addr:   interface MAC address
92  * @label_port: port id
93  * @label_subport:  id of interface within port (for split ports)
94  * @enabled:    is enabled?
95  * @tx_enabled: is TX enabled?
96  * @rx_enabled: is RX enabled?
97  * @override_changed: is media reconfig pending?
98  *
99  * @port_type:  one of %PORT_* defines for ethtool
100  * @port_lanes: total number of lanes on the port (sum of lanes of all subports)
101  * @is_split:   is interface part of a split port
102  */
103 struct nfp_eth_table {
104         unsigned int count;
105         unsigned int max_index;
106         struct nfp_eth_table_port {
107                 unsigned int eth_index;
108                 unsigned int index;
109                 unsigned int nbi;
110                 unsigned int base;
111                 unsigned int lanes;
112                 unsigned int speed;
113
114                 unsigned int interface;
115                 enum nfp_eth_media media;
116
117                 enum nfp_eth_aneg aneg;
118
119                 u8 mac_addr[ETH_ALEN];
120
121                 u8 label_port;
122                 u8 label_subport;
123
124                 bool enabled;
125                 bool tx_enabled;
126                 bool rx_enabled;
127
128                 bool override_changed;
129
130                 /* Computed fields */
131                 u8 port_type;
132
133                 unsigned int port_lanes;
134
135                 bool is_split;
136         } ports[0];
137 };
138
139 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
140 struct nfp_eth_table *
141 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
142
143 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
144 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
145                            bool configed);
146
147 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
148 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
149 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
150
151 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
152 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
153 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
154
155 /**
156  * struct nfp_nsp_identify - NSP static information
157  * @version:      opaque version string
158  * @flags:        version flags
159  * @br_primary:   branch id of primary bootloader
160  * @br_secondary: branch id of secondary bootloader
161  * @br_nsp:       branch id of NSP
162  * @primary:      version of primarary bootloader
163  * @secondary:    version id of secondary bootloader
164  * @nsp:          version id of NSP
165  * @sensor_mask:  mask of present sensors available on NIC
166  */
167 struct nfp_nsp_identify {
168         char version[40];
169         u8 flags;
170         u8 br_primary;
171         u8 br_secondary;
172         u8 br_nsp;
173         u16 primary;
174         u16 secondary;
175         u16 nsp;
176         u64 sensor_mask;
177 };
178
179 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
180
181 enum nfp_nsp_sensor_id {
182         NFP_SENSOR_CHIP_TEMPERATURE,
183         NFP_SENSOR_ASSEMBLY_POWER,
184         NFP_SENSOR_ASSEMBLY_12V_POWER,
185         NFP_SENSOR_ASSEMBLY_3V3_POWER,
186 };
187
188 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
189                           long *val);
190
191 #endif