1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2014-2018 Netronome Systems, Inc. 3 * All rights reserved. 4 */ 5 6 #ifndef __NFP_NET_COMMON_H__ 7 #define __NFP_NET_COMMON_H__ 8 9 #include <bus_pci_driver.h> 10 #include <ethdev_driver.h> 11 #include <nfp_common.h> 12 #include <nfp_dev.h> 13 #include <rte_spinlock.h> 14 15 #include "nfpcore/nfp_sync.h" 16 #include "nfp_net_ctrl.h" 17 #include "nfp_service.h" 18 #include "nfp_net_meta.h" 19 20 /* Interrupt definitions */ 21 #define NFP_NET_IRQ_LSC_IDX 0 22 23 /* Default values for RX/TX configuration */ 24 #define DEFAULT_RX_FREE_THRESH 32 25 #define DEFAULT_RX_PTHRESH 8 26 #define DEFAULT_RX_HTHRESH 8 27 #define DEFAULT_RX_WTHRESH 0 28 29 #define DEFAULT_TX_RS_THRESH 32 30 #define DEFAULT_TX_FREE_THRESH 32 31 #define DEFAULT_TX_PTHRESH 32 32 #define DEFAULT_TX_HTHRESH 0 33 #define DEFAULT_TX_WTHRESH 0 34 #define DEFAULT_TX_RSBIT_THRESH 32 35 36 /* Alignment for dma zones */ 37 #define NFP_MEMZONE_ALIGN 128 38 39 /* Number of supported physical ports */ 40 #define NFP_MAX_PHYPORTS 12 41 42 #define NFP_BEAT_LENGTH 8 43 44 /* RSS capability*/ 45 #define NFP_NET_RSS_CAP (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | \ 46 RTE_ETH_RSS_NONFRAG_IPV4_TCP | \ 47 RTE_ETH_RSS_NONFRAG_IPV4_UDP | \ 48 RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \ 49 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \ 50 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \ 51 RTE_ETH_RSS_NONFRAG_IPV6_SCTP) 52 53 /* The length of firmware version string */ 54 #define FW_VER_LEN 32 55 56 /* 57 * Each PF has corresponding word to beat: 58 * Offset | Usage 59 * 0 | magic number 60 * 8 | beat of Pf0 61 * 16 | beat of Pf1 62 * 24 | beat of Pf2 63 * 32 | beat of Pf3 64 */ 65 #define NFP_BEAT_OFFSET(_x) (((_x) + 1) * NFP_BEAT_LENGTH) 66 67 /* Firmware application ID's */ 68 enum nfp_app_fw_id { 69 NFP_APP_FW_CORE_NIC = 0x1, 70 NFP_APP_FW_FLOWER_NIC = 0x3, 71 }; 72 73 /* Parsed control BAR TLV capabilities */ 74 struct nfp_net_tlv_caps { 75 uint32_t mbox_off; /**< VNIC mailbox area offset */ 76 uint32_t mbox_len; /**< VNIC mailbox area length */ 77 uint32_t mbox_cmsg_types; /**< Cmsgs which can be passed through the mailbox */ 78 }; 79 80 struct nfp_multi_pf { 81 /** Support multiple PF */ 82 bool enabled; 83 /** Function index */ 84 uint8_t function_id; 85 /** Pointer to CPP area for beat to keepalive */ 86 struct nfp_cpp_area *beat_area; 87 /** Pointer to mapped beat address used for keepalive */ 88 uint8_t *beat_addr; 89 }; 90 91 struct nfp_flower_service; 92 93 struct nfp_process_share { 94 struct nfp_flower_service *fl_service; 95 }; 96 97 struct nfp_devargs { 98 /** Force reload firmware */ 99 bool force_reload_fw; 100 101 /** Enable CPP bridge service */ 102 bool cpp_service_enable; 103 }; 104 105 struct nfp_pf_dev { 106 /** Backpointer to associated pci device */ 107 struct rte_pci_device *pci_dev; 108 109 enum nfp_app_fw_id app_fw_id; 110 111 struct nfp_net_fw_ver ver; 112 113 /** Pointer to the app running on the PF */ 114 void *app_fw_priv; 115 116 /** The eth table reported by firmware */ 117 struct nfp_eth_table *nfp_eth_table; 118 119 uint8_t *ctrl_bar; 120 uint32_t ctrl_bar_size; 121 122 struct nfp_cpp *cpp; 123 struct nfp_cpp_area *ctrl_area; 124 struct nfp_cpp_area *qc_area; 125 126 /** Pointer to the CPP area for the VF configuration BAR */ 127 struct nfp_cpp_area *vf_area; 128 /** Pointer to mapped VF configuration area */ 129 uint8_t *vf_bar; 130 /** Pointer to the CPP area for the VF config table */ 131 struct nfp_cpp_area *vf_cfg_tbl_area; 132 /** Pointer to mapped VF config table */ 133 uint8_t *vf_cfg_tbl_bar; 134 135 uint8_t *qc_bar; 136 137 struct nfp_cpp_area *mac_stats_area; 138 uint8_t *mac_stats_bar; 139 140 struct nfp_hwinfo *hwinfo; 141 struct nfp_rtsym_table *sym_tbl; 142 143 /** Service info of cpp bridge service */ 144 struct nfp_service_info cpp_service_info; 145 146 /** Multiple PF configuration */ 147 struct nfp_multi_pf multi_pf; 148 149 /** Supported speeds bitmap */ 150 uint32_t speed_capa; 151 152 /** Synchronized info */ 153 struct nfp_sync *sync; 154 struct nfp_process_share process_share; 155 156 /** NFP devarg param */ 157 struct nfp_devargs devargs; 158 159 /** Number of VFs supported by firmware shared by all PFs */ 160 uint16_t max_vfs; 161 /** Number of VFs supported by firmware for this PF */ 162 uint16_t sriov_vf; 163 164 uint8_t total_phyports; 165 /** Id of first VF that belongs to this PF */ 166 uint8_t vf_base_id; 167 /** Number of queues per VF */ 168 uint32_t queue_per_vf; 169 170 /** Record the speed uptade */ 171 bool speed_updated; 172 173 /** Function pointer used to check the metadata of recv pkts. */ 174 bool (*recv_pkt_meta_check_t)(struct nfp_net_meta_parsed *meta); 175 }; 176 177 #define NFP_NET_ETH_FLOW_LIMIT 8 178 #define NFP_NET_IPV4_FLOW_LIMIT 1024 179 #define NFP_NET_IPV6_FLOW_LIMIT 1024 180 181 #define NFP_NET_FLOW_LIMIT ((NFP_NET_ETH_FLOW_LIMIT) + \ 182 (NFP_NET_IPV4_FLOW_LIMIT) + \ 183 (NFP_NET_IPV6_FLOW_LIMIT)) 184 185 struct nfp_net_flow_count { 186 uint16_t eth_count; 187 uint16_t ipv4_count; 188 uint16_t ipv6_count; 189 }; 190 191 #define NFP_NET_HASH_REDUNDANCE (1.2) 192 193 struct nfp_net_priv { 194 uint32_t hash_seed; /**< Hash seed for hash tables in this structure. */ 195 struct rte_hash *flow_table; /**< Hash table to store flow rules. */ 196 struct nfp_net_flow_count flow_count; /**< Flow count in hash table */ 197 uint32_t flow_limit; /**< Flow limit of hash table */ 198 bool *flow_position; /**< Flow position array */ 199 }; 200 201 struct nfp_app_fw_nic { 202 /** 203 * Array of physical ports belonging to this CoreNIC app. 204 * This is really a list of vNIC's, one for each physical port. 205 */ 206 struct nfp_net_hw *ports[NFP_MAX_PHYPORTS]; 207 208 bool multiport; 209 }; 210 211 struct nfp_net_hw_priv { 212 struct nfp_pf_dev *pf_dev; 213 214 /** NFP ASIC params */ 215 const struct nfp_dev_info *dev_info; 216 217 bool is_pf; 218 }; 219 220 struct nfp_net_hw { 221 /** The parent class */ 222 struct nfp_hw super; 223 224 /** TX pointer ring write back memzone */ 225 const struct rte_memzone *txrwb_mz; 226 227 /** Info from the firmware */ 228 uint32_t max_mtu; 229 uint32_t mtu; 230 uint32_t rx_offset; 231 enum nfp_net_meta_format meta_format; 232 233 uint8_t *tx_bar; 234 uint8_t *rx_bar; 235 236 int stride_rx; 237 int stride_tx; 238 239 uint16_t vxlan_ports[NFP_NET_N_VXLAN_PORTS]; 240 uint8_t vxlan_usecnt[NFP_NET_N_VXLAN_PORTS]; 241 242 uint32_t max_tx_queues; 243 uint32_t max_rx_queues; 244 uint16_t flbufsz; 245 bool flbufsz_set_flag; 246 uint16_t device_id; 247 uint16_t vendor_id; 248 uint16_t subsystem_device_id; 249 uint16_t subsystem_vendor_id; 250 251 /** Records starting point for counters */ 252 struct rte_eth_stats eth_stats_base; 253 struct rte_eth_xstat *eth_xstats_base; 254 255 struct nfp_cpp_area *ctrl_area; 256 uint8_t *mac_stats; 257 258 /** Sequential physical port number, only valid for CoreNIC firmware */ 259 uint8_t idx; 260 /** Internal port number as seen from NFP */ 261 uint8_t nfp_idx; 262 263 struct nfp_net_tlv_caps tlv_caps; 264 265 struct nfp_net_ipsec_data *ipsec_data; 266 267 /** Used for rte_flow of CoreNIC firmware */ 268 struct nfp_net_priv *priv; 269 270 /** Used for firmware version */ 271 char fw_version[FW_VER_LEN]; 272 }; 273 274 static inline uint32_t 275 nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info, 276 uint16_t queue) 277 { 278 return dev_info->qc_addr_offset + NFP_QCP_QUEUE_ADDR_SZ * 279 (queue & dev_info->qc_idx_mask); 280 } 281 282 /* Prototypes for common NFP functions */ 283 int nfp_net_mbox_reconfig(struct nfp_net_hw *hw, uint32_t mbox_cmd); 284 int nfp_net_configure(struct rte_eth_dev *dev); 285 int nfp_net_common_init(struct nfp_pf_dev *pf_dev, struct nfp_net_hw *hw); 286 void nfp_net_log_device_information(const struct nfp_net_hw *hw, 287 struct nfp_pf_dev *pf_dev); 288 void nfp_net_enable_queues(struct rte_eth_dev *dev); 289 void nfp_net_disable_queues(struct rte_eth_dev *dev); 290 void nfp_net_params_setup(struct nfp_net_hw *hw); 291 int nfp_net_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr); 292 int nfp_configure_rx_interrupt(struct rte_eth_dev *dev, 293 struct rte_intr_handle *intr_handle); 294 uint32_t nfp_check_offloads(struct rte_eth_dev *dev); 295 int nfp_net_promisc_enable(struct rte_eth_dev *dev); 296 int nfp_net_promisc_disable(struct rte_eth_dev *dev); 297 int nfp_net_allmulticast_enable(struct rte_eth_dev *dev); 298 int nfp_net_allmulticast_disable(struct rte_eth_dev *dev); 299 int nfp_net_link_update_common(struct rte_eth_dev *dev, 300 struct rte_eth_link *link, 301 uint32_t link_status); 302 int nfp_net_link_update(struct rte_eth_dev *dev, 303 __rte_unused int wait_to_complete); 304 int nfp_net_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats); 305 int nfp_net_stats_reset(struct rte_eth_dev *dev); 306 uint32_t nfp_net_xstats_size(const struct rte_eth_dev *dev); 307 int nfp_net_xstats_get_names(struct rte_eth_dev *dev, 308 struct rte_eth_xstat_name *xstats_names, 309 unsigned int size __rte_unused); 310 int nfp_net_xstats_get(struct rte_eth_dev *dev, 311 struct rte_eth_xstat *xstats, 312 unsigned int n __rte_unused); 313 int nfp_net_xstats_get_names_by_id(struct rte_eth_dev *dev, 314 const uint64_t *ids, 315 struct rte_eth_xstat_name *xstats_names, 316 unsigned int size); 317 int nfp_net_xstats_get_by_id(struct rte_eth_dev *dev, 318 const uint64_t *ids, 319 uint64_t *values, 320 unsigned int n); 321 int nfp_net_xstats_reset(struct rte_eth_dev *dev); 322 int nfp_net_infos_get(struct rte_eth_dev *dev, 323 struct rte_eth_dev_info *dev_info); 324 const uint32_t *nfp_net_supported_ptypes_get(struct rte_eth_dev *dev, 325 size_t *no_of_elements); 326 int nfp_net_ptypes_set(struct rte_eth_dev *dev, uint32_t ptype_mask); 327 int nfp_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id); 328 int nfp_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id); 329 void nfp_net_params_setup(struct nfp_net_hw *hw); 330 void nfp_net_cfg_queue_setup(struct nfp_net_hw *hw); 331 void nfp_net_irq_unmask(struct rte_eth_dev *dev); 332 void nfp_net_dev_interrupt_handler(void *param); 333 void nfp_net_dev_interrupt_delayed_handler(void *param); 334 int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); 335 int nfp_net_vlan_offload_set(struct rte_eth_dev *dev, int mask); 336 int nfp_net_reta_update(struct rte_eth_dev *dev, 337 struct rte_eth_rss_reta_entry64 *reta_conf, 338 uint16_t reta_size); 339 int nfp_net_reta_query(struct rte_eth_dev *dev, 340 struct rte_eth_rss_reta_entry64 *reta_conf, 341 uint16_t reta_size); 342 int nfp_net_rss_hash_update(struct rte_eth_dev *dev, 343 struct rte_eth_rss_conf *rss_conf); 344 int nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev, 345 struct rte_eth_rss_conf *rss_conf); 346 int nfp_net_rss_config_default(struct rte_eth_dev *dev); 347 void nfp_net_stop_rx_queue(struct rte_eth_dev *dev); 348 void nfp_net_close_rx_queue(struct rte_eth_dev *dev); 349 void nfp_net_stop_tx_queue(struct rte_eth_dev *dev); 350 void nfp_net_close_tx_queue(struct rte_eth_dev *dev); 351 int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, 352 size_t idx, 353 uint16_t port, 354 uint32_t ctrl); 355 void nfp_net_rx_desc_limits(struct nfp_net_hw_priv *hw_priv, 356 uint16_t *min_rx_desc, 357 uint16_t *max_rx_desc); 358 void nfp_net_tx_desc_limits(struct nfp_net_hw_priv *hw_priv, 359 uint16_t *min_tx_desc, 360 uint16_t *max_tx_desc); 361 int nfp_net_check_dma_mask(struct nfp_pf_dev *pf_dev, char *name); 362 int nfp_net_firmware_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size); 363 bool nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver version); 364 bool nfp_net_is_valid_version_class(struct nfp_net_fw_ver version); 365 struct nfp_net_hw *nfp_net_get_hw(const struct rte_eth_dev *dev); 366 uint8_t nfp_net_get_idx(const struct rte_eth_dev *dev); 367 int nfp_net_stop(struct rte_eth_dev *dev); 368 int nfp_net_flow_ctrl_get(struct rte_eth_dev *dev, 369 struct rte_eth_fc_conf *fc_conf); 370 int nfp_net_flow_ctrl_set(struct rte_eth_dev *dev, 371 struct rte_eth_fc_conf *fc_conf); 372 void nfp_pf_uninit(struct nfp_net_hw_priv *hw_priv); 373 int nfp_net_fec_get_capability(struct rte_eth_dev *dev, 374 struct rte_eth_fec_capa *speed_fec_capa, 375 unsigned int num); 376 int nfp_net_fec_get(struct rte_eth_dev *dev, 377 uint32_t *fec_capa); 378 int nfp_net_fec_set(struct rte_eth_dev *dev, 379 uint32_t fec_capa); 380 void nfp_net_get_fw_version(struct nfp_cpp *cpp, 381 uint32_t *fw_version); 382 int nfp_net_txrwb_alloc(struct rte_eth_dev *eth_dev); 383 void nfp_net_txrwb_free(struct rte_eth_dev *eth_dev); 384 uint32_t nfp_net_get_phyports_from_nsp(struct nfp_pf_dev *pf_dev); 385 uint32_t nfp_net_get_phyports_from_fw(struct nfp_pf_dev *pf_dev); 386 uint8_t nfp_function_id_get(const struct nfp_pf_dev *pf_dev, 387 uint8_t port_id); 388 int nfp_net_vf_config_app_init(struct nfp_net_hw *net_hw, 389 struct nfp_pf_dev *pf_dev); 390 bool nfp_net_version_check(struct nfp_hw *hw, 391 struct nfp_pf_dev *pf_dev); 392 void nfp_net_ctrl_bar_size_set(struct nfp_pf_dev *pf_dev); 393 void nfp_net_notify_port_speed(struct nfp_net_hw *hw, 394 struct rte_eth_link *link); 395 bool nfp_net_recv_pkt_meta_check_register(struct nfp_net_hw_priv *hw_priv); 396 397 int nfp_net_get_eeprom_len(struct rte_eth_dev *dev); 398 int nfp_net_get_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *eeprom); 399 int nfp_net_set_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *eeprom); 400 int nfp_net_get_module_info(struct rte_eth_dev *dev, struct rte_eth_dev_module_info *info); 401 int nfp_net_get_module_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *info); 402 int nfp_net_led_on(struct rte_eth_dev *dev); 403 int nfp_net_led_off(struct rte_eth_dev *dev); 404 405 #define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\ 406 ((struct nfp_app_fw_nic *)app_fw_priv) 407 408 #define NFP_PRIV_TO_APP_FW_FLOWER(app_fw_priv)\ 409 ((struct nfp_app_fw_flower *)app_fw_priv) 410 411 #endif /* __NFP_NET_COMMON_H__ */ 412