Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
0002 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */
0003 
0004 #ifndef NSP_NSP_H
0005 #define NSP_NSP_H 1
0006 
0007 #include <linux/types.h>
0008 #include <linux/if_ether.h>
0009 
0010 struct firmware;
0011 struct nfp_cpp;
0012 struct nfp_nsp;
0013 
0014 struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp);
0015 void nfp_nsp_close(struct nfp_nsp *state);
0016 u16 nfp_nsp_get_abi_ver_major(struct nfp_nsp *state);
0017 u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state);
0018 int nfp_nsp_wait(struct nfp_nsp *state);
0019 int nfp_nsp_device_soft_reset(struct nfp_nsp *state);
0020 int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw);
0021 int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw);
0022 int nfp_nsp_mac_reinit(struct nfp_nsp *state);
0023 int nfp_nsp_load_stored_fw(struct nfp_nsp *state);
0024 int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size);
0025 int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state, void *buf,
0026                    unsigned int size, const char *default_val);
0027 int nfp_nsp_hwinfo_set(struct nfp_nsp *state, void *buf, unsigned int size);
0028 int nfp_nsp_fw_loaded(struct nfp_nsp *state);
0029 int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index,
0030                    unsigned int offset, void *data,
0031                    unsigned int len, unsigned int *read_len);
0032 
0033 static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
0034 {
0035     return nfp_nsp_get_abi_ver_minor(state) > 20;
0036 }
0037 
0038 static inline bool nfp_nsp_has_stored_fw_load(struct nfp_nsp *state)
0039 {
0040     return nfp_nsp_get_abi_ver_minor(state) > 23;
0041 }
0042 
0043 static inline bool nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state)
0044 {
0045     return nfp_nsp_get_abi_ver_minor(state) > 24;
0046 }
0047 
0048 static inline bool nfp_nsp_has_hwinfo_set(struct nfp_nsp *state)
0049 {
0050     return nfp_nsp_get_abi_ver_minor(state) > 25;
0051 }
0052 
0053 static inline bool nfp_nsp_has_fw_loaded(struct nfp_nsp *state)
0054 {
0055     return nfp_nsp_get_abi_ver_minor(state) > 25;
0056 }
0057 
0058 static inline bool nfp_nsp_has_versions(struct nfp_nsp *state)
0059 {
0060     return nfp_nsp_get_abi_ver_minor(state) > 27;
0061 }
0062 
0063 static inline bool nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state)
0064 {
0065     return nfp_nsp_get_abi_ver_minor(state) > 28;
0066 }
0067 
0068 enum nfp_eth_interface {
0069     NFP_INTERFACE_NONE  = 0,
0070     NFP_INTERFACE_SFP   = 1,
0071     NFP_INTERFACE_SFPP  = 10,
0072     NFP_INTERFACE_SFP28 = 28,
0073     NFP_INTERFACE_QSFP  = 40,
0074     NFP_INTERFACE_RJ45  = 45,
0075     NFP_INTERFACE_CXP   = 100,
0076     NFP_INTERFACE_QSFP28    = 112,
0077 };
0078 
0079 enum nfp_eth_media {
0080     NFP_MEDIA_DAC_PASSIVE = 0,
0081     NFP_MEDIA_DAC_ACTIVE,
0082     NFP_MEDIA_FIBRE,
0083 };
0084 
0085 enum nfp_eth_aneg {
0086     NFP_ANEG_AUTO = 0,
0087     NFP_ANEG_SEARCH,
0088     NFP_ANEG_25G_CONSORTIUM,
0089     NFP_ANEG_25G_IEEE,
0090     NFP_ANEG_DISABLED,
0091 };
0092 
0093 enum nfp_eth_fec {
0094     NFP_FEC_AUTO_BIT = 0,
0095     NFP_FEC_BASER_BIT,
0096     NFP_FEC_REED_SOLOMON_BIT,
0097     NFP_FEC_DISABLED_BIT,
0098 };
0099 
0100 #define NFP_FEC_AUTO        BIT(NFP_FEC_AUTO_BIT)
0101 #define NFP_FEC_BASER       BIT(NFP_FEC_BASER_BIT)
0102 #define NFP_FEC_REED_SOLOMON    BIT(NFP_FEC_REED_SOLOMON_BIT)
0103 #define NFP_FEC_DISABLED    BIT(NFP_FEC_DISABLED_BIT)
0104 
0105 /* Defines the valid values of the 'abi_drv_reset' hwinfo key */
0106 #define NFP_NSP_DRV_RESET_DISK          0
0107 #define NFP_NSP_DRV_RESET_ALWAYS        1
0108 #define NFP_NSP_DRV_RESET_NEVER         2
0109 #define NFP_NSP_DRV_RESET_DEFAULT       "0"
0110 
0111 /* Defines the valid values of the 'app_fw_from_flash' hwinfo key */
0112 #define NFP_NSP_APP_FW_LOAD_DISK        0
0113 #define NFP_NSP_APP_FW_LOAD_FLASH       1
0114 #define NFP_NSP_APP_FW_LOAD_PREF        2
0115 #define NFP_NSP_APP_FW_LOAD_DEFAULT     "2"
0116 
0117 /* Define the default value for the 'abi_drv_load_ifc' key */
0118 #define NFP_NSP_DRV_LOAD_IFC_DEFAULT        "0x10ff"
0119 
0120 /**
0121  * struct nfp_eth_table - ETH table information
0122  * @count:  number of table entries
0123  * @max_index:  max of @index fields of all @ports
0124  * @ports:  table of ports
0125  *
0126  * @ports.eth_index:    port index according to legacy ethX numbering
0127  * @ports.index:    chip-wide first channel index
0128  * @ports.nbi:      NBI index
0129  * @ports.base:     first channel index (within NBI)
0130  * @ports.lanes:    number of channels
0131  * @ports.speed:    interface speed (in Mbps)
0132  * @ports.interface:    interface (module) plugged in
0133  * @ports.media:    media type of the @interface
0134  * @ports.fec:      forward error correction mode
0135  * @ports.aneg:     auto negotiation mode
0136  * @ports.mac_addr: interface MAC address
0137  * @ports.label_port:   port id
0138  * @ports.label_subport:  id of interface within port (for split ports)
0139  * @ports.enabled:  is enabled?
0140  * @ports.tx_enabled:   is TX enabled?
0141  * @ports.rx_enabled:   is RX enabled?
0142  * @ports.override_changed: is media reconfig pending?
0143  *
0144  * @ports.port_type:    one of %PORT_* defines for ethtool
0145  * @ports.port_lanes:   total number of lanes on the port (sum of lanes of all
0146  *          subports)
0147  * @ports.is_split: is interface part of a split port
0148  * @ports.fec_modes_supported:  bitmap of FEC modes supported
0149  */
0150 struct nfp_eth_table {
0151     unsigned int count;
0152     unsigned int max_index;
0153     struct nfp_eth_table_port {
0154         unsigned int eth_index;
0155         unsigned int index;
0156         unsigned int nbi;
0157         unsigned int base;
0158         unsigned int lanes;
0159         unsigned int speed;
0160 
0161         unsigned int interface;
0162         enum nfp_eth_media media;
0163 
0164         enum nfp_eth_fec fec;
0165         enum nfp_eth_aneg aneg;
0166 
0167         u8 mac_addr[ETH_ALEN];
0168 
0169         u8 label_port;
0170         u8 label_subport;
0171 
0172         bool enabled;
0173         bool tx_enabled;
0174         bool rx_enabled;
0175 
0176         bool override_changed;
0177 
0178         /* Computed fields */
0179         u8 port_type;
0180 
0181         unsigned int port_lanes;
0182 
0183         bool is_split;
0184 
0185         unsigned int fec_modes_supported;
0186     } ports[];
0187 };
0188 
0189 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
0190 struct nfp_eth_table *
0191 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
0192 
0193 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
0194 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
0195                bool configed);
0196 int
0197 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
0198 
0199 int nfp_eth_set_idmode(struct nfp_cpp *cpp, unsigned int idx, bool state);
0200 
0201 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
0202 {
0203     return !!eth_port->fec_modes_supported;
0204 }
0205 
0206 static inline unsigned int
0207 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
0208 {
0209     return eth_port->fec_modes_supported;
0210 }
0211 
0212 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
0213 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
0214 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
0215 
0216 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
0217 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
0218 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
0219 
0220 /**
0221  * struct nfp_nsp_identify - NSP static information
0222  * @version:      opaque version string
0223  * @flags:        version flags
0224  * @br_primary:   branch id of primary bootloader
0225  * @br_secondary: branch id of secondary bootloader
0226  * @br_nsp:       branch id of NSP
0227  * @primary:      version of primarary bootloader
0228  * @secondary:    version id of secondary bootloader
0229  * @nsp:          version id of NSP
0230  * @sensor_mask:  mask of present sensors available on NIC
0231  */
0232 struct nfp_nsp_identify {
0233     char version[40];
0234     u8 flags;
0235     u8 br_primary;
0236     u8 br_secondary;
0237     u8 br_nsp;
0238     u16 primary;
0239     u16 secondary;
0240     u16 nsp;
0241     u64 sensor_mask;
0242 };
0243 
0244 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
0245 
0246 enum nfp_nsp_sensor_id {
0247     NFP_SENSOR_CHIP_TEMPERATURE,
0248     NFP_SENSOR_ASSEMBLY_POWER,
0249     NFP_SENSOR_ASSEMBLY_12V_POWER,
0250     NFP_SENSOR_ASSEMBLY_3V3_POWER,
0251 };
0252 
0253 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
0254               long *val);
0255 
0256 #define NFP_NSP_VERSION_BUFSZ   1024 /* reasonable size, not in the ABI */
0257 
0258 enum nfp_nsp_versions {
0259     NFP_VERSIONS_BSP,
0260     NFP_VERSIONS_CPLD,
0261     NFP_VERSIONS_APP,
0262     NFP_VERSIONS_BUNDLE,
0263     NFP_VERSIONS_UNDI,
0264     NFP_VERSIONS_NCSI,
0265     NFP_VERSIONS_CFGR,
0266 };
0267 
0268 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size);
0269 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
0270                  const u8 *buf, unsigned int size);
0271 #endif