Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * 3 : : * Copyright(c) 2019-2021 Xilinx, Inc. 4 : : * Copyright(c) 2016-2019 Solarflare Communications Inc. 5 : : * 6 : : * This software was jointly developed between OKTET Labs (under contract 7 : : * for Solarflare) and Solarflare Communications, Inc. 8 : : */ 9 : : 10 : : #ifndef _SFC_H 11 : : #define _SFC_H 12 : : 13 : : #include <stdbool.h> 14 : : 15 : : #include <rte_pci.h> 16 : : #include <bus_pci_driver.h> 17 : : #include <ethdev_driver.h> 18 : : #include <rte_kvargs.h> 19 : : #include <rte_spinlock.h> 20 : : #include <rte_atomic.h> 21 : : 22 : : #include "efx.h" 23 : : 24 : : #include "sfc_efx_mcdi.h" 25 : : #include "sfc_efx.h" 26 : : 27 : : #include "sfc_debug.h" 28 : : #include "sfc_log.h" 29 : : #include "sfc_filter.h" 30 : : #include "sfc_flow_rss.h" 31 : : #include "sfc_flow_tunnel.h" 32 : : #include "sfc_sriov.h" 33 : : #include "sfc_mae.h" 34 : : #include "sfc_tbls.h" 35 : : #include "sfc_dp.h" 36 : : #include "sfc_sw_stats.h" 37 : : #include "sfc_repr_proxy.h" 38 : : #include "sfc_service.h" 39 : : #include "sfc_ethdev_state.h" 40 : : #include "sfc_nic_dma_dp.h" 41 : : 42 : : #ifdef __cplusplus 43 : : extern "C" { 44 : : #endif 45 : : 46 : : enum sfc_dev_filter_mode { 47 : : SFC_DEV_FILTER_MODE_PROMISC = 0, 48 : : SFC_DEV_FILTER_MODE_ALLMULTI, 49 : : 50 : : SFC_DEV_FILTER_NMODES 51 : : }; 52 : : 53 : : struct sfc_intr { 54 : : efx_intr_type_t type; 55 : : rte_intr_callback_fn handler; 56 : : boolean_t lsc_intr; 57 : : boolean_t rxq_intr; 58 : : }; 59 : : 60 : : struct sfc_rxq; 61 : : struct sfc_txq; 62 : : 63 : : struct sfc_rxq_info; 64 : : struct sfc_txq_info; 65 : : struct sfc_dp_rx; 66 : : 67 : : struct sfc_port { 68 : : unsigned int lsc_seq; 69 : : 70 : : efx_phy_lane_count_t phy_lane_count_active; 71 : : efx_phy_lane_count_t phy_lane_count_req; 72 : : uint32_t phy_adv_cap_mask; 73 : : uint32_t phy_adv_cap; 74 : : uint32_t fec_cfg; 75 : : bool fec_auto; 76 : : 77 : : unsigned int flow_ctrl; 78 : : boolean_t flow_ctrl_autoneg; 79 : : boolean_t include_fcs; 80 : : boolean_t vlan_strip; 81 : : size_t pdu; 82 : : 83 : : /* 84 : : * Flow API isolated mode overrides promisc and allmulti settings; 85 : : * they won't be applied if isolated mode is active 86 : : */ 87 : : boolean_t promisc; 88 : : boolean_t allmulti; 89 : : 90 : : struct rte_ether_addr default_mac_addr; 91 : : 92 : : unsigned int max_mcast_addrs; 93 : : unsigned int nb_mcast_addrs; 94 : : uint8_t *mcast_addrs; 95 : : 96 : : uint64_t *mac_stats_buf; 97 : : unsigned int mac_stats_nb_supported; 98 : : efsys_mem_t mac_stats_dma_mem; 99 : : boolean_t mac_stats_reset_pending; 100 : : uint16_t mac_stats_update_period_ms; 101 : : uint32_t mac_stats_update_generation; 102 : : boolean_t mac_stats_periodic_dma_supported; 103 : : uint64_t mac_stats_last_request_timestamp; 104 : : 105 : : uint32_t mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES]; 106 : : 107 : : unsigned int mac_stats_by_id[EFX_MAC_NSTATS]; 108 : : 109 : : uint64_t ipackets; 110 : : }; 111 : : 112 : : struct sfc_rss_hf_rte_to_efx { 113 : : uint64_t rte; 114 : : efx_rx_hash_type_t efx; 115 : : }; 116 : : 117 : : struct sfc_rss { 118 : : unsigned int channels; 119 : : efx_rx_scale_context_type_t context_type; 120 : : efx_rx_hash_support_t hash_support; 121 : : efx_rx_hash_alg_t hash_alg; 122 : : unsigned int hf_map_nb_entries; 123 : : struct sfc_rss_hf_rte_to_efx *hf_map; 124 : : 125 : : efx_rx_hash_type_t hash_types; 126 : : unsigned int tbl[EFX_RSS_TBL_SIZE]; 127 : : uint8_t key[EFX_RSS_KEY_SIZE]; 128 : : 129 : : struct sfc_flow_rss_ctx dummy_ctx; 130 : : }; 131 : : 132 : : /* Adapter private data shared by primary and secondary processes */ 133 : : struct sfc_adapter_shared { 134 : : unsigned int rxq_count; 135 : : struct sfc_rxq_info *rxq_info; 136 : : unsigned int ethdev_rxq_count; 137 : : 138 : : unsigned int txq_count; 139 : : struct sfc_txq_info *txq_info; 140 : : unsigned int ethdev_txq_count; 141 : : 142 : : struct sfc_rss rss; 143 : : 144 : : boolean_t isolated; 145 : : uint32_t tunnel_encaps; 146 : : 147 : : char log_prefix[SFC_LOG_PREFIX_MAX]; 148 : : struct rte_pci_addr pci_addr; 149 : : uint16_t port_id; 150 : : 151 : : char *dp_rx_name; 152 : : char *dp_tx_name; 153 : : 154 : : bool counters_rxq_allocated; 155 : : unsigned int nb_repr_rxq; 156 : : unsigned int nb_repr_txq; 157 : : 158 : : struct sfc_nic_dma_info nic_dma_info; 159 : : }; 160 : : 161 : : /* Adapter process private data */ 162 : : struct sfc_adapter_priv { 163 : : struct sfc_adapter_shared *shared; 164 : : const struct sfc_dp_rx *dp_rx; 165 : : const struct sfc_dp_tx *dp_tx; 166 : : uint32_t logtype_main; 167 : : }; 168 : : 169 : : static inline struct sfc_adapter_priv * 170 : : sfc_adapter_priv_by_eth_dev(struct rte_eth_dev *eth_dev) 171 : : { 172 [ # # # # : 0 : struct sfc_adapter_priv *sap = eth_dev->process_private; # # # # # # # # # # # # # # # # # # # # # # # # ] 173 : : 174 : : SFC_ASSERT(sap != NULL); 175 : : return sap; 176 : : } 177 : : 178 : : /* RxQ dedicated for counters (counter only RxQ) data */ 179 : : struct sfc_counter_rxq { 180 : : unsigned int state; 181 : : #define SFC_COUNTER_RXQ_ATTACHED 0x1 182 : : #define SFC_COUNTER_RXQ_INITIALIZED 0x2 183 : : sfc_sw_index_t sw_index; 184 : : struct rte_mempool *mp; 185 : : }; 186 : : 187 : : struct sfc_sw_stat_data { 188 : : const struct sfc_sw_stat_descr *descr; 189 : : /* Cache fragment */ 190 : : uint64_t *cache; 191 : : }; 192 : : 193 : : struct sfc_sw_stats { 194 : : /* Number extended statistics provided by SW stats */ 195 : : unsigned int xstats_count; 196 : : /* Supported SW statistics */ 197 : : struct sfc_sw_stat_data *supp; 198 : : unsigned int supp_count; 199 : : 200 : : /* Cache for all supported SW statistics */ 201 : : uint64_t *cache; 202 : : unsigned int cache_count; 203 : : 204 : : uint64_t *reset_vals; 205 : : /* Location of per-queue reset values for packets/bytes in reset_vals */ 206 : : uint64_t *reset_rx_pkts; 207 : : uint64_t *reset_rx_bytes; 208 : : uint64_t *reset_tx_pkts; 209 : : uint64_t *reset_tx_bytes; 210 : : 211 : : rte_spinlock_t queues_bitmap_lock; 212 : : void *queues_bitmap_mem; 213 : : struct rte_bitmap *queues_bitmap; 214 : : }; 215 : : 216 : : /* Adapter private data */ 217 : : struct sfc_adapter { 218 : : /* 219 : : * It must be the first field of the sfc_adapter structure since 220 : : * sfc_adapter is the primary process private data (i.e. process 221 : : * private data plus additional primary process specific data). 222 : : */ 223 : : struct sfc_adapter_priv priv; 224 : : 225 : : /* 226 : : * PMD setup and configuration is not thread safe. Since it is not 227 : : * performance sensitive, it is better to guarantee thread-safety 228 : : * and add device level lock. Adapter control operations which 229 : : * change its state should acquire the lock. 230 : : */ 231 : : rte_spinlock_t lock; 232 : : enum sfc_ethdev_state state; 233 : : struct rte_eth_dev *eth_dev; 234 : : struct rte_kvargs *kvargs; 235 : : int socket_id; 236 : : efsys_bar_t mem_bar; 237 : : /* Function control window offset */ 238 : : efsys_dma_addr_t fcw_offset; 239 : : efx_family_t family; 240 : : efx_nic_t *nic; 241 : : rte_spinlock_t nic_lock; 242 : : rte_atomic32_t restart_required; 243 : : 244 : : struct sfc_efx_mcdi mcdi; 245 : : struct sfc_sriov sriov; 246 : : struct sfc_intr intr; 247 : : struct sfc_port port; 248 : : struct sfc_sw_stats sw_stats; 249 : : struct sfc_flow_rss flow_rss; 250 : : /* Registry of contexts used in Flow Tunnel (FT) offload */ 251 : : struct sfc_ft_ctx ft_ctx_pool[SFC_FT_MAX_NTUNNELS]; 252 : : struct sfc_filter filter; 253 : : struct sfc_mae mae; 254 : : struct sfc_tbls hw_tables; 255 : : struct sfc_repr_proxy repr_proxy; 256 : : 257 : : struct sfc_flow_indir_actions flow_indir_actions; 258 : : struct sfc_flow_list flow_list; 259 : : 260 : : unsigned int rxq_max; 261 : : unsigned int txq_max; 262 : : 263 : : unsigned int rxq_max_entries; 264 : : unsigned int rxq_min_entries; 265 : : 266 : : unsigned int txq_max_entries; 267 : : unsigned int txq_min_entries; 268 : : 269 : : unsigned int evq_max_entries; 270 : : unsigned int evq_min_entries; 271 : : 272 : : uint32_t evq_flags; 273 : : unsigned int evq_count; 274 : : 275 : : unsigned int mgmt_evq_index; 276 : : /* 277 : : * The lock is used to serialise management event queue polling 278 : : * which can be done from different context. Also the lock 279 : : * guarantees that mgmt_evq_running is preserved while the lock 280 : : * is held. It is used to serialise polling and start/stop 281 : : * operations. 282 : : * 283 : : * Locks which may be held when the lock is acquired: 284 : : * - adapter lock, when: 285 : : * - device start/stop to change mgmt_evq_running 286 : : * - any control operations in client side MCDI proxy handling to 287 : : * poll management event queue waiting for proxy response 288 : : * - MCDI lock, when: 289 : : * - any control operations in client side MCDI proxy handling to 290 : : * poll management event queue waiting for proxy response 291 : : * 292 : : * Locks which are acquired with the lock held: 293 : : * - nic_lock, when: 294 : : * - MC event processing on management event queue polling 295 : : * (e.g. MC REBOOT or BADASSERT events) 296 : : */ 297 : : rte_spinlock_t mgmt_evq_lock; 298 : : bool mgmt_evq_running; 299 : : struct sfc_evq *mgmt_evq; 300 : : 301 : : struct sfc_counter_rxq counter_rxq; 302 : : 303 : : struct sfc_rxq *rxq_ctrl; 304 : : struct sfc_txq *txq_ctrl; 305 : : 306 : : boolean_t tso; 307 : : boolean_t tso_encap; 308 : : 309 : : uint64_t negotiated_rx_metadata; 310 : : 311 : : uint32_t rxd_wait_timeout_ns; 312 : : 313 : : bool switchdev; 314 : : 315 : : bool link_ev_need_poll; 316 : : }; 317 : : 318 : : static inline struct sfc_adapter_shared * 319 : : sfc_adapter_shared_by_eth_dev(struct rte_eth_dev *eth_dev) 320 : : { 321 [ # # # # : 0 : struct sfc_adapter_shared *sas = eth_dev->data->dev_private; # # # # # ] 322 : : 323 : : return sas; 324 : : } 325 : : 326 : : static inline struct sfc_adapter * 327 : : sfc_adapter_by_eth_dev(struct rte_eth_dev *eth_dev) 328 : : { 329 : : struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(eth_dev); 330 : : 331 : : SFC_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); 332 : : 333 : : return container_of(sap, struct sfc_adapter, priv); 334 : : } 335 : : 336 : : static inline struct sfc_adapter_shared * 337 : : sfc_sa2shared(struct sfc_adapter *sa) 338 : : { 339 [ # # # # : 0 : return sa->priv.shared; # # # # # # ] 340 : : } 341 : : 342 : : /* 343 : : * Add wrapper functions to acquire/release lock to be able to remove or 344 : : * change the lock in one place. 345 : : */ 346 : : 347 : : #define sfc_adapter_lock_init(sa) rte_spinlock_init(&(sa)->lock) 348 : : #define sfc_adapter_is_locked(sa) rte_spinlock_is_locked(&(sa)->lock) 349 : : #define sfc_adapter_lock(sa) rte_spinlock_lock(&(sa)->lock) 350 : : #define sfc_adapter_trylock(sa) rte_spinlock_trylock(&(sa)->lock) 351 : : #define sfc_adapter_unlock(sa) rte_spinlock_unlock(&(sa)->lock) 352 : : #define sfc_adapter_lock_fini(sa) RTE_SET_USED(sa) 353 : : 354 : : static inline unsigned int 355 : : sfc_nb_counter_rxq(const struct sfc_adapter_shared *sas) 356 : : { 357 : 0 : return sas->counters_rxq_allocated ? 1 : 0; 358 : : } 359 : : 360 : : bool sfc_repr_supported(const struct sfc_adapter *sa); 361 : : bool sfc_repr_available(const struct sfc_adapter_shared *sas); 362 : : 363 : : static inline unsigned int 364 : : sfc_repr_nb_rxq(const struct sfc_adapter_shared *sas) 365 : : { 366 [ # # # # : 0 : return sas->nb_repr_rxq; # # # # # # # # # # ] 367 : : } 368 : : 369 : : static inline unsigned int 370 : : sfc_repr_nb_txq(const struct sfc_adapter_shared *sas) 371 : : { 372 [ # # # # : 0 : return sas->nb_repr_txq; # # # # # # # # ] 373 : : } 374 : : 375 : : /** Get the number of milliseconds since boot from the default timer */ 376 : : static inline uint64_t 377 : : sfc_get_system_msecs(void) 378 : : { 379 [ # # ]: 0 : return rte_get_timer_cycles() * MS_PER_S / rte_get_timer_hz(); 380 : : } 381 : : 382 : : int sfc_dma_alloc(struct sfc_adapter *sa, const char *name, uint16_t id, 383 : : efx_nic_dma_addr_type_t addr_type, size_t len, int socket_id, 384 : : efsys_mem_t *esmp); 385 : : void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp); 386 : : 387 : : uint32_t sfc_register_logtype(const struct rte_pci_addr *pci_addr, 388 : : const char *lt_prefix_str, 389 : : uint32_t ll_default); 390 : : 391 : : int sfc_probe(struct sfc_adapter *sa); 392 : : void sfc_unprobe(struct sfc_adapter *sa); 393 : : int sfc_attach(struct sfc_adapter *sa); 394 : : void sfc_pre_detach(struct sfc_adapter *sa); 395 : : void sfc_detach(struct sfc_adapter *sa); 396 : : int sfc_start(struct sfc_adapter *sa); 397 : : void sfc_stop(struct sfc_adapter *sa); 398 : : 399 : : void sfc_schedule_restart(struct sfc_adapter *sa); 400 : : 401 : : int sfc_mcdi_init(struct sfc_adapter *sa); 402 : : void sfc_mcdi_fini(struct sfc_adapter *sa); 403 : : 404 : : int sfc_configure(struct sfc_adapter *sa); 405 : : void sfc_close(struct sfc_adapter *sa); 406 : : 407 : : int sfc_intr_attach(struct sfc_adapter *sa); 408 : : void sfc_intr_detach(struct sfc_adapter *sa); 409 : : int sfc_intr_configure(struct sfc_adapter *sa); 410 : : void sfc_intr_close(struct sfc_adapter *sa); 411 : : int sfc_intr_start(struct sfc_adapter *sa); 412 : : void sfc_intr_stop(struct sfc_adapter *sa); 413 : : 414 : : int sfc_port_attach(struct sfc_adapter *sa); 415 : : void sfc_port_detach(struct sfc_adapter *sa); 416 : : int sfc_port_configure(struct sfc_adapter *sa); 417 : : void sfc_port_close(struct sfc_adapter *sa); 418 : : int sfc_port_start(struct sfc_adapter *sa); 419 : : void sfc_port_stop(struct sfc_adapter *sa); 420 : : void sfc_port_link_mode_to_info(efx_link_mode_t link_mode, 421 : : struct rte_eth_link *link_info); 422 : : int sfc_port_update_mac_stats(struct sfc_adapter *sa, boolean_t manual_update); 423 : : int sfc_port_get_mac_stats(struct sfc_adapter *sa, struct rte_eth_xstat *xstats, 424 : : unsigned int xstats_count, unsigned int *nb_written); 425 : : int sfc_port_get_mac_stats_by_id(struct sfc_adapter *sa, const uint64_t *ids, 426 : : uint64_t *values, unsigned int n); 427 : : int sfc_port_reset_mac_stats(struct sfc_adapter *sa); 428 : : int sfc_set_rx_mode(struct sfc_adapter *sa); 429 : : int sfc_set_rx_mode_unchecked(struct sfc_adapter *sa); 430 : : 431 : : struct sfc_hw_switch_id; 432 : : 433 : : int sfc_hw_switch_id_init(struct sfc_adapter *sa, 434 : : struct sfc_hw_switch_id **idp); 435 : : void sfc_hw_switch_id_fini(struct sfc_adapter *sa, 436 : : struct sfc_hw_switch_id *idp); 437 : : bool sfc_hw_switch_ids_equal(const struct sfc_hw_switch_id *left, 438 : : const struct sfc_hw_switch_id *right); 439 : : 440 : : #ifdef __cplusplus 441 : : } 442 : : #endif 443 : : 444 : : #endif /* _SFC_H */