1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */ 3 4 #ifndef NSP_NSP_H 5 #define NSP_NSP_H 1 6 7 #include <linux/types.h> 8 #include <linux/if_ether.h> 9 10 struct firmware; 11 struct nfp_cpp; 12 struct nfp_nsp; 13 14 struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); 15 void nfp_nsp_close(struct nfp_nsp *state); 16 u16 nfp_nsp_get_abi_ver_major(struct nfp_nsp *state); 17 u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state); 18 int nfp_nsp_wait(struct nfp_nsp *state); 19 int nfp_nsp_device_soft_reset(struct nfp_nsp *state); 20 int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw); 21 int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw); 22 int nfp_nsp_mac_reinit(struct nfp_nsp *state); 23 int nfp_nsp_load_stored_fw(struct nfp_nsp *state); 24 int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size); 25 int nfp_nsp_fw_loaded(struct nfp_nsp *state); 26 int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index, 27 unsigned int offset, void *data, 28 unsigned int len, unsigned int *read_len); 29 30 static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state) 31 { 32 return nfp_nsp_get_abi_ver_minor(state) > 20; 33 } 34 35 static inline bool nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) 36 { 37 return nfp_nsp_get_abi_ver_minor(state) > 23; 38 } 39 40 static inline bool nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) 41 { 42 return nfp_nsp_get_abi_ver_minor(state) > 24; 43 } 44 45 static inline bool nfp_nsp_has_fw_loaded(struct nfp_nsp *state) 46 { 47 return nfp_nsp_get_abi_ver_minor(state) > 25; 48 } 49 50 static inline bool nfp_nsp_has_versions(struct nfp_nsp *state) 51 { 52 return nfp_nsp_get_abi_ver_minor(state) > 27; 53 } 54 55 static inline bool nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) 56 { 57 return nfp_nsp_get_abi_ver_minor(state) > 28; 58 } 59 60 enum nfp_eth_interface { 61 NFP_INTERFACE_NONE = 0, 62 NFP_INTERFACE_SFP = 1, 63 NFP_INTERFACE_SFPP = 10, 64 NFP_INTERFACE_SFP28 = 28, 65 NFP_INTERFACE_QSFP = 40, 66 NFP_INTERFACE_RJ45 = 45, 67 NFP_INTERFACE_CXP = 100, 68 NFP_INTERFACE_QSFP28 = 112, 69 }; 70 71 enum nfp_eth_media { 72 NFP_MEDIA_DAC_PASSIVE = 0, 73 NFP_MEDIA_DAC_ACTIVE, 74 NFP_MEDIA_FIBRE, 75 }; 76 77 enum nfp_eth_aneg { 78 NFP_ANEG_AUTO = 0, 79 NFP_ANEG_SEARCH, 80 NFP_ANEG_25G_CONSORTIUM, 81 NFP_ANEG_25G_IEEE, 82 NFP_ANEG_DISABLED, 83 }; 84 85 enum nfp_eth_fec { 86 NFP_FEC_AUTO_BIT = 0, 87 NFP_FEC_BASER_BIT, 88 NFP_FEC_REED_SOLOMON_BIT, 89 NFP_FEC_DISABLED_BIT, 90 }; 91 92 #define NFP_FEC_AUTO BIT(NFP_FEC_AUTO_BIT) 93 #define NFP_FEC_BASER BIT(NFP_FEC_BASER_BIT) 94 #define NFP_FEC_REED_SOLOMON BIT(NFP_FEC_REED_SOLOMON_BIT) 95 #define NFP_FEC_DISABLED BIT(NFP_FEC_DISABLED_BIT) 96 97 /** 98 * struct nfp_eth_table - ETH table information 99 * @count: number of table entries 100 * @max_index: max of @index fields of all @ports 101 * @ports: table of ports 102 * 103 * @ports.eth_index: port index according to legacy ethX numbering 104 * @ports.index: chip-wide first channel index 105 * @ports.nbi: NBI index 106 * @ports.base: first channel index (within NBI) 107 * @ports.lanes: number of channels 108 * @ports.speed: interface speed (in Mbps) 109 * @ports.interface: interface (module) plugged in 110 * @ports.media: media type of the @interface 111 * @ports.fec: forward error correction mode 112 * @ports.aneg: auto negotiation mode 113 * @ports.mac_addr: interface MAC address 114 * @ports.label_port: port id 115 * @ports.label_subport: id of interface within port (for split ports) 116 * @ports.enabled: is enabled? 117 * @ports.tx_enabled: is TX enabled? 118 * @ports.rx_enabled: is RX enabled? 119 * @ports.override_changed: is media reconfig pending? 120 * 121 * @ports.port_type: one of %PORT_* defines for ethtool 122 * @ports.port_lanes: total number of lanes on the port (sum of lanes of all 123 * subports) 124 * @ports.is_split: is interface part of a split port 125 * @ports.fec_modes_supported: bitmap of FEC modes supported 126 */ 127 struct nfp_eth_table { 128 unsigned int count; 129 unsigned int max_index; 130 struct nfp_eth_table_port { 131 unsigned int eth_index; 132 unsigned int index; 133 unsigned int nbi; 134 unsigned int base; 135 unsigned int lanes; 136 unsigned int speed; 137 138 unsigned int interface; 139 enum nfp_eth_media media; 140 141 enum nfp_eth_fec fec; 142 enum nfp_eth_aneg aneg; 143 144 u8 mac_addr[ETH_ALEN]; 145 146 u8 label_port; 147 u8 label_subport; 148 149 bool enabled; 150 bool tx_enabled; 151 bool rx_enabled; 152 153 bool override_changed; 154 155 /* Computed fields */ 156 u8 port_type; 157 158 unsigned int port_lanes; 159 160 bool is_split; 161 162 unsigned int fec_modes_supported; 163 } ports[0]; 164 }; 165 166 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); 167 struct nfp_eth_table * 168 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp); 169 170 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable); 171 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, 172 bool configed); 173 int 174 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); 175 176 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) 177 { 178 return !!eth_port->fec_modes_supported; 179 } 180 181 static inline unsigned int 182 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port) 183 { 184 return eth_port->fec_modes_supported; 185 } 186 187 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx); 188 int nfp_eth_config_commit_end(struct nfp_nsp *nsp); 189 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); 190 191 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); 192 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed); 193 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes); 194 195 /** 196 * struct nfp_nsp_identify - NSP static information 197 * @version: opaque version string 198 * @flags: version flags 199 * @br_primary: branch id of primary bootloader 200 * @br_secondary: branch id of secondary bootloader 201 * @br_nsp: branch id of NSP 202 * @primary: version of primarary bootloader 203 * @secondary: version id of secondary bootloader 204 * @nsp: version id of NSP 205 * @sensor_mask: mask of present sensors available on NIC 206 */ 207 struct nfp_nsp_identify { 208 char version[40]; 209 u8 flags; 210 u8 br_primary; 211 u8 br_secondary; 212 u8 br_nsp; 213 u16 primary; 214 u16 secondary; 215 u16 nsp; 216 u64 sensor_mask; 217 }; 218 219 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); 220 221 enum nfp_nsp_sensor_id { 222 NFP_SENSOR_CHIP_TEMPERATURE, 223 NFP_SENSOR_ASSEMBLY_POWER, 224 NFP_SENSOR_ASSEMBLY_12V_POWER, 225 NFP_SENSOR_ASSEMBLY_3V3_POWER, 226 }; 227 228 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, 229 long *val); 230 231 #define NFP_NSP_VERSION_BUFSZ 1024 /* reasonable size, not in the ABI */ 232 233 enum nfp_nsp_versions { 234 NFP_VERSIONS_BSP, 235 NFP_VERSIONS_CPLD, 236 NFP_VERSIONS_APP, 237 NFP_VERSIONS_BUNDLE, 238 NFP_VERSIONS_UNDI, 239 NFP_VERSIONS_NCSI, 240 NFP_VERSIONS_CFGR, 241 }; 242 243 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size); 244 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash, 245 const u8 *buf, unsigned int size); 246 #endif 247