1c7e9729dSAlejandro Lucero /* SPDX-License-Identifier: BSD-3-Clause 2c7e9729dSAlejandro Lucero * Copyright(c) 2018 Netronome Systems, Inc. 3c7e9729dSAlejandro Lucero * All rights reserved. 4c7e9729dSAlejandro Lucero */ 5c7e9729dSAlejandro Lucero 62cd8817aSChaoyong He #ifndef __NSP_NSP_H__ 72cd8817aSChaoyong He #define __NSP_NSP_H__ 8c7e9729dSAlejandro Lucero 9c7e9729dSAlejandro Lucero #include "nfp_cpp.h" 10c7e9729dSAlejandro Lucero 117f693813SChaoyong He /* EEPROM byte offsets */ 127f693813SChaoyong He #define SFP_SFF8472_COMPLIANCE 0x5e 137f693813SChaoyong He #define SFP_SFF_REV_COMPLIANCE 1 147f693813SChaoyong He #define NSP_SFF_EEPROM_BLOCK_LEN 8 157f693813SChaoyong He 169e76c352SChaoyong He /* Defines the valid values of the 'abi_drv_reset' hwinfo key */ 179e76c352SChaoyong He #define NFP_NSP_DRV_RESET_DISK 0 189e76c352SChaoyong He #define NFP_NSP_DRV_RESET_ALWAYS 1 199e76c352SChaoyong He #define NFP_NSP_DRV_RESET_NEVER 2 209e76c352SChaoyong He #define NFP_NSP_DRV_RESET_DEFAULT "0" 219e76c352SChaoyong He 229e76c352SChaoyong He /* Defines the valid values of the 'app_fw_from_flash' hwinfo key */ 239e76c352SChaoyong He #define NFP_NSP_APP_FW_LOAD_DISK 0 249e76c352SChaoyong He #define NFP_NSP_APP_FW_LOAD_FLASH 1 259e76c352SChaoyong He #define NFP_NSP_APP_FW_LOAD_PREF 2 269e76c352SChaoyong He #define NFP_NSP_APP_FW_LOAD_DEFAULT "2" 279e76c352SChaoyong He 28acaa57efSChaoyong He struct nfp_nsp; 29c7e9729dSAlejandro Lucero 30c7e9729dSAlejandro Lucero struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); 31c7e9729dSAlejandro Lucero void nfp_nsp_close(struct nfp_nsp *state); 32c7e9729dSAlejandro Lucero uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state); 33c7e9729dSAlejandro Lucero uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state); 34c7e9729dSAlejandro Lucero int nfp_nsp_wait(struct nfp_nsp *state); 35c7e9729dSAlejandro Lucero int nfp_nsp_device_soft_reset(struct nfp_nsp *state); 3608461d7bSPeng Zhang int nfp_nsp_device_activate(struct nfp_nsp *state); 37c69debceSChaoyong He int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size); 38c7e9729dSAlejandro Lucero int nfp_nsp_mac_reinit(struct nfp_nsp *state); 39c69debceSChaoyong He int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); 40c69debceSChaoyong He int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, 41c69debceSChaoyong He void *buf, size_t size); 42c7e9729dSAlejandro Lucero 43acaa57efSChaoyong He static inline bool 44d108b9e9SChaoyong He nfp_nsp_has_mac_reinit(struct nfp_nsp *state) 45c7e9729dSAlejandro Lucero { 46c7e9729dSAlejandro Lucero return nfp_nsp_get_abi_ver_minor(state) > 20; 47c7e9729dSAlejandro Lucero } 48c7e9729dSAlejandro Lucero 49acaa57efSChaoyong He static inline bool 50acaa57efSChaoyong He nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) 51acaa57efSChaoyong He { 52acaa57efSChaoyong He return nfp_nsp_get_abi_ver_minor(state) > 23; 53acaa57efSChaoyong He } 54acaa57efSChaoyong He 55acaa57efSChaoyong He static inline bool 56acaa57efSChaoyong He nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) 57acaa57efSChaoyong He { 58acaa57efSChaoyong He return nfp_nsp_get_abi_ver_minor(state) > 24; 59acaa57efSChaoyong He } 60acaa57efSChaoyong He 61acaa57efSChaoyong He static inline bool 62acaa57efSChaoyong He nfp_nsp_has_hwinfo_set(struct nfp_nsp *state) 63acaa57efSChaoyong He { 64acaa57efSChaoyong He return nfp_nsp_get_abi_ver_minor(state) > 25; 65acaa57efSChaoyong He } 66acaa57efSChaoyong He 67acaa57efSChaoyong He static inline bool 68acaa57efSChaoyong He nfp_nsp_has_fw_loaded(struct nfp_nsp *state) 69acaa57efSChaoyong He { 70acaa57efSChaoyong He return nfp_nsp_get_abi_ver_minor(state) > 25; 71acaa57efSChaoyong He } 72acaa57efSChaoyong He 73acaa57efSChaoyong He static inline bool 74acaa57efSChaoyong He nfp_nsp_has_versions(struct nfp_nsp *state) 75acaa57efSChaoyong He { 76acaa57efSChaoyong He return nfp_nsp_get_abi_ver_minor(state) > 27; 77acaa57efSChaoyong He } 78acaa57efSChaoyong He 79acaa57efSChaoyong He static inline bool 80acaa57efSChaoyong He nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) 81acaa57efSChaoyong He { 82acaa57efSChaoyong He return nfp_nsp_get_abi_ver_minor(state) > 28; 83acaa57efSChaoyong He } 84acaa57efSChaoyong He 85acaa57efSChaoyong He static inline bool 86acaa57efSChaoyong He nfp_nsp_has_read_media(struct nfp_nsp *state) 87acaa57efSChaoyong He { 88acaa57efSChaoyong He return nfp_nsp_get_abi_ver_minor(state) > 33; 89acaa57efSChaoyong He } 90acaa57efSChaoyong He 91c7e9729dSAlejandro Lucero enum nfp_eth_interface { 92c7e9729dSAlejandro Lucero NFP_INTERFACE_NONE = 0, 93c7e9729dSAlejandro Lucero NFP_INTERFACE_SFP = 1, 94c7e9729dSAlejandro Lucero NFP_INTERFACE_SFPP = 10, 95c7e9729dSAlejandro Lucero NFP_INTERFACE_SFP28 = 28, 96c7e9729dSAlejandro Lucero NFP_INTERFACE_QSFP = 40, 97acaa57efSChaoyong He NFP_INTERFACE_RJ45 = 45, 98c7e9729dSAlejandro Lucero NFP_INTERFACE_CXP = 100, 99c7e9729dSAlejandro Lucero NFP_INTERFACE_QSFP28 = 112, 100c7e9729dSAlejandro Lucero }; 101c7e9729dSAlejandro Lucero 102c7e9729dSAlejandro Lucero enum nfp_eth_media { 103c7e9729dSAlejandro Lucero NFP_MEDIA_DAC_PASSIVE = 0, 104c7e9729dSAlejandro Lucero NFP_MEDIA_DAC_ACTIVE, 105c7e9729dSAlejandro Lucero NFP_MEDIA_FIBRE, 106c7e9729dSAlejandro Lucero }; 107c7e9729dSAlejandro Lucero 108c7e9729dSAlejandro Lucero enum nfp_eth_aneg { 109c7e9729dSAlejandro Lucero NFP_ANEG_AUTO = 0, 110c7e9729dSAlejandro Lucero NFP_ANEG_SEARCH, 111c7e9729dSAlejandro Lucero NFP_ANEG_25G_CONSORTIUM, 112c7e9729dSAlejandro Lucero NFP_ANEG_25G_IEEE, 113c7e9729dSAlejandro Lucero NFP_ANEG_DISABLED, 114c7e9729dSAlejandro Lucero }; 115c7e9729dSAlejandro Lucero 116c7e9729dSAlejandro Lucero enum nfp_eth_fec { 117c7e9729dSAlejandro Lucero NFP_FEC_AUTO_BIT = 0, 118c7e9729dSAlejandro Lucero NFP_FEC_BASER_BIT, 119c7e9729dSAlejandro Lucero NFP_FEC_REED_SOLOMON_BIT, 120c7e9729dSAlejandro Lucero NFP_FEC_DISABLED_BIT, 12137bd1b84SZerun Fu NFP_FEC_INVALID_BIT, 122c7e9729dSAlejandro Lucero }; 123c7e9729dSAlejandro Lucero 1248987de81SChaoyong He #define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) 1258987de81SChaoyong He #define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) 1268987de81SChaoyong He #define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) 1278987de81SChaoyong He #define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) 128c7e9729dSAlejandro Lucero 1296d03aa61SChaoyong He /* ETH table information */ 130c7e9729dSAlejandro Lucero struct nfp_eth_table { 1316d03aa61SChaoyong He uint32_t count; /**< Number of table entries */ 1326d03aa61SChaoyong He uint32_t max_index; /**< Max of @index fields of all @ports */ 133c7e9729dSAlejandro Lucero struct nfp_eth_table_port { 1346d03aa61SChaoyong He /** Port index according to legacy ethX numbering */ 135c69debceSChaoyong He uint32_t eth_index; 1366d03aa61SChaoyong He uint32_t index; /**< Chip-wide first channel index */ 1376d03aa61SChaoyong He uint32_t nbi; /**< NBI index */ 1386d03aa61SChaoyong He uint32_t base; /**< First channel index (within NBI) */ 1396d03aa61SChaoyong He uint32_t lanes; /**< Number of channels */ 1406d03aa61SChaoyong He uint32_t speed; /**< Interface speed (in Mbps) */ 141c7e9729dSAlejandro Lucero 1426d03aa61SChaoyong He uint32_t interface; /**< Interface (module) plugged in */ 1436d03aa61SChaoyong He enum nfp_eth_media media; /**< Media type of the @interface */ 144c7e9729dSAlejandro Lucero 1456d03aa61SChaoyong He enum nfp_eth_fec fec; /**< Forward Error Correction mode */ 146acaa57efSChaoyong He enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */ 1476d03aa61SChaoyong He enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ 148c7e9729dSAlejandro Lucero 1496d03aa61SChaoyong He struct rte_ether_addr mac_addr; /**< Interface MAC address */ 150c7e9729dSAlejandro Lucero 1516d03aa61SChaoyong He uint8_t label_port; /**< Port id */ 1526d03aa61SChaoyong He /** Id of interface within port (for split ports) */ 153c7e9729dSAlejandro Lucero uint8_t label_subport; 154c7e9729dSAlejandro Lucero 155acaa57efSChaoyong He bool enabled; /**< Enable port */ 156acaa57efSChaoyong He bool tx_enabled; /**< Enable TX */ 157acaa57efSChaoyong He bool rx_enabled; /**< Enable RX */ 158acaa57efSChaoyong He bool supp_aneg; /**< Support auto negotiation */ 159c7e9729dSAlejandro Lucero 160acaa57efSChaoyong He bool override_changed; /**< Media reconfig pending */ 16151d15e82SZerun Fu bool rx_pause_enabled; /**< Switch of RX pause frame */ 16251d15e82SZerun Fu bool tx_pause_enabled; /**< Switch of TX pause frame */ 163c7e9729dSAlejandro Lucero 1646d03aa61SChaoyong He uint8_t port_type; /**< One of %PORT_* */ 1656d03aa61SChaoyong He /** Sum of lanes of all subports of this port */ 166c69debceSChaoyong He uint32_t port_lanes; 167c7e9729dSAlejandro Lucero 168acaa57efSChaoyong He bool is_split; /**< Split port */ 169c7e9729dSAlejandro Lucero 1706d03aa61SChaoyong He uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ 1716d03aa61SChaoyong He } ports[]; /**< Table of ports */ 172c7e9729dSAlejandro Lucero }; 173c7e9729dSAlejandro Lucero 174c7e9729dSAlejandro Lucero struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); 175c7e9729dSAlejandro Lucero 176acaa57efSChaoyong He int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable); 177acaa57efSChaoyong He int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured); 178c69debceSChaoyong He int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); 179c7e9729dSAlejandro Lucero 180c69debceSChaoyong He int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); 181c7e9729dSAlejandro Lucero int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, 182c69debceSChaoyong He size_t size); 183c7e9729dSAlejandro Lucero void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, 184c69debceSChaoyong He uint32_t idx); 185c7e9729dSAlejandro Lucero void nfp_nsp_config_clear_state(struct nfp_nsp *state); 186acaa57efSChaoyong He void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified); 187c7e9729dSAlejandro Lucero void *nfp_nsp_config_entries(struct nfp_nsp *state); 188acaa57efSChaoyong He struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state); 189acaa57efSChaoyong He bool nfp_nsp_config_modified(struct nfp_nsp *state); 190c69debceSChaoyong He uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); 191c7a6970fSZerun Fu int nfp_nsp_hwinfo_set(struct nfp_nsp *state, 192c7a6970fSZerun Fu const void *buf, 193c7a6970fSZerun Fu size_t size); 1943110ab73SZerun Fu int nfp_nsp_read_media(struct nfp_nsp *state, 1953110ab73SZerun Fu void *buf, 1963110ab73SZerun Fu size_t size); 197c7e9729dSAlejandro Lucero 198acaa57efSChaoyong He static inline bool 199d108b9e9SChaoyong He nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) 200c7e9729dSAlejandro Lucero { 201c69debceSChaoyong He return eth_port->fec_modes_supported != 0; 202c7e9729dSAlejandro Lucero } 203c7e9729dSAlejandro Lucero 204c69debceSChaoyong He static inline uint32_t 205c7e9729dSAlejandro Lucero nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port) 206c7e9729dSAlejandro Lucero { 207c7e9729dSAlejandro Lucero return eth_port->fec_modes_supported; 208c7e9729dSAlejandro Lucero } 209c7e9729dSAlejandro Lucero 210c69debceSChaoyong He struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); 211c7e9729dSAlejandro Lucero int nfp_eth_config_commit_end(struct nfp_nsp *nsp); 212c7e9729dSAlejandro Lucero void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); 213c7e9729dSAlejandro Lucero 214588c5b10SChaoyong He int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); 215588c5b10SChaoyong He int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); 216588c5b10SChaoyong He int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); 21768aa3537SZerun Fu int nfp_eth_set_tx_pause(struct nfp_nsp *nsp, bool tx_pause); 21868aa3537SZerun Fu int nfp_eth_set_rx_pause(struct nfp_nsp *nsp, bool rx_pause); 219*8bd6f540SChaoyong He int nfp_eth_set_idmode(struct nfp_cpp *cpp, uint32_t idx, bool is_on); 220c7e9729dSAlejandro Lucero 2216d03aa61SChaoyong He /* NSP static information */ 222c7e9729dSAlejandro Lucero struct nfp_nsp_identify { 2236d03aa61SChaoyong He char version[40]; /**< Opaque version string */ 2246d03aa61SChaoyong He uint8_t flags; /**< Version flags */ 2256d03aa61SChaoyong He uint8_t br_primary; /**< Branch id of primary bootloader */ 2266d03aa61SChaoyong He uint8_t br_secondary; /**< Branch id of secondary bootloader */ 2276d03aa61SChaoyong He uint8_t br_nsp; /**< Branch id of NSP */ 2286d03aa61SChaoyong He uint16_t primary; /**< Version of primary bootloader */ 2296d03aa61SChaoyong He uint16_t secondary; /**< Version id of secondary bootloader */ 2306d03aa61SChaoyong He uint16_t nsp; /**< Version id of NSP */ 2316d03aa61SChaoyong He uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ 232c7e9729dSAlejandro Lucero }; 233c7e9729dSAlejandro Lucero 234588c5b10SChaoyong He struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp); 235c7e9729dSAlejandro Lucero 236c7e9729dSAlejandro Lucero enum nfp_nsp_sensor_id { 237c7e9729dSAlejandro Lucero NFP_SENSOR_CHIP_TEMPERATURE, 238c7e9729dSAlejandro Lucero NFP_SENSOR_ASSEMBLY_POWER, 239c7e9729dSAlejandro Lucero NFP_SENSOR_ASSEMBLY_12V_POWER, 240c7e9729dSAlejandro Lucero NFP_SENSOR_ASSEMBLY_3V3_POWER, 241c7e9729dSAlejandro Lucero }; 242c7e9729dSAlejandro Lucero 243c7e9729dSAlejandro Lucero int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, 244c69debceSChaoyong He uint32_t *val); 245f53439aaSPeng Zhang bool nfp_nsp_fw_loaded(struct nfp_nsp *state); 2469e76c352SChaoyong He int nfp_nsp_load_stored_fw(struct nfp_nsp *state); 2477f693813SChaoyong He int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, uint32_t size); 2489e76c352SChaoyong He int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state, 2499e76c352SChaoyong He void *buf, size_t size, const char *default_val); 2507f693813SChaoyong He int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index, 2517f693813SChaoyong He uint32_t offset, void *data, 2527f693813SChaoyong He uint32_t len, uint32_t *read_len); 253c7e9729dSAlejandro Lucero 2543110ab73SZerun Fu /* The buf used to receive bitmap of link modes */ 2553110ab73SZerun Fu struct nfp_eth_media_buf { 2563110ab73SZerun Fu uint8_t eth_index; 2573110ab73SZerun Fu uint8_t reserved[7]; 2583110ab73SZerun Fu uint64_t supported_modes[2]; 2593110ab73SZerun Fu uint64_t reserved_2[2]; 2603110ab73SZerun Fu }; 2613110ab73SZerun Fu 2623110ab73SZerun Fu /* Link modes about RJ45 haven't been used, so there's no mapping to them */ 2633110ab73SZerun Fu enum nfp_link_mode_list { 2643110ab73SZerun Fu NFP_MEDIA_W0_RJ45_10M, 2653110ab73SZerun Fu NFP_MEDIA_W0_RJ45_10M_HD, 2663110ab73SZerun Fu NFP_MEDIA_W0_RJ45_100M, 2673110ab73SZerun Fu NFP_MEDIA_W0_RJ45_100M_HD, 2683110ab73SZerun Fu NFP_MEDIA_W0_RJ45_1G, 2693110ab73SZerun Fu NFP_MEDIA_W0_RJ45_2P5G, 2703110ab73SZerun Fu NFP_MEDIA_W0_RJ45_5G, 2713110ab73SZerun Fu NFP_MEDIA_W0_RJ45_10G, 2723110ab73SZerun Fu NFP_MEDIA_1000BASE_CX, 2733110ab73SZerun Fu NFP_MEDIA_1000BASE_KX, 2743110ab73SZerun Fu NFP_MEDIA_10GBASE_KX4, 2753110ab73SZerun Fu NFP_MEDIA_10GBASE_KR, 2763110ab73SZerun Fu NFP_MEDIA_10GBASE_CX4, 2773110ab73SZerun Fu NFP_MEDIA_10GBASE_CR, 2783110ab73SZerun Fu NFP_MEDIA_10GBASE_SR, 2793110ab73SZerun Fu NFP_MEDIA_10GBASE_ER, 2803110ab73SZerun Fu NFP_MEDIA_25GBASE_KR, 2813110ab73SZerun Fu NFP_MEDIA_25GBASE_KR_S, 2823110ab73SZerun Fu NFP_MEDIA_25GBASE_CR, 2833110ab73SZerun Fu NFP_MEDIA_25GBASE_CR_S, 2843110ab73SZerun Fu NFP_MEDIA_25GBASE_SR, 2853110ab73SZerun Fu NFP_MEDIA_40GBASE_CR4, 2863110ab73SZerun Fu NFP_MEDIA_40GBASE_KR4, 2873110ab73SZerun Fu NFP_MEDIA_40GBASE_SR4, 2883110ab73SZerun Fu NFP_MEDIA_40GBASE_LR4, 2893110ab73SZerun Fu NFP_MEDIA_50GBASE_KR, 2903110ab73SZerun Fu NFP_MEDIA_50GBASE_SR, 2913110ab73SZerun Fu NFP_MEDIA_50GBASE_CR, 2923110ab73SZerun Fu NFP_MEDIA_50GBASE_LR, 2933110ab73SZerun Fu NFP_MEDIA_50GBASE_ER, 2943110ab73SZerun Fu NFP_MEDIA_50GBASE_FR, 2953110ab73SZerun Fu NFP_MEDIA_100GBASE_KR4, 2963110ab73SZerun Fu NFP_MEDIA_100GBASE_SR4, 2973110ab73SZerun Fu NFP_MEDIA_100GBASE_CR4, 2983110ab73SZerun Fu NFP_MEDIA_100GBASE_KP4, 2993110ab73SZerun Fu NFP_MEDIA_100GBASE_CR10, 3003110ab73SZerun Fu NFP_MEDIA_10GBASE_LR, 3013110ab73SZerun Fu NFP_MEDIA_25GBASE_LR, 3023110ab73SZerun Fu NFP_MEDIA_25GBASE_ER, 3033110ab73SZerun Fu NFP_MEDIA_LINK_MODES_NUMBER 3043110ab73SZerun Fu }; 3053110ab73SZerun Fu 3062cd8817aSChaoyong He #endif /* __NSP_NSP_H__ */ 307