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