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