1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2019-2021 Xilinx, Inc. 4 * Copyright(c) 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_REPR_PROXY_H 11 #define _SFC_REPR_PROXY_H 12 13 #include <stdint.h> 14 15 #include <rte_ring.h> 16 #include <rte_mempool.h> 17 18 #include "efx.h" 19 20 #include "sfc_repr.h" 21 #include "sfc_dp.h" 22 #include "sfc_flow.h" 23 #include "sfc_mae.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* Number of supported RxQs with different mbuf memory pools */ 30 #define SFC_REPR_PROXY_NB_RXQ_MIN (1) 31 #define SFC_REPR_PROXY_NB_RXQ_MAX (1) 32 33 /* One TxQ is required and sufficient for port representors support */ 34 #define SFC_REPR_PROXY_NB_TXQ_MIN (1) 35 #define SFC_REPR_PROXY_NB_TXQ_MAX (1) 36 37 #define SFC_REPR_PROXY_RX_DESC_COUNT 256 38 #define SFC_REPR_PROXY_RXQ_REFILL_LEVEL (SFC_REPR_PROXY_RX_DESC_COUNT / 4) 39 #define SFC_REPR_PROXY_RX_BURST 32 40 41 #define SFC_REPR_PROXY_TX_DESC_COUNT 256 42 #define SFC_REPR_PROXY_TXQ_FREE_THRESH (SFC_REPR_PROXY_TX_DESC_COUNT / 4) 43 #define SFC_REPR_PROXY_TX_BURST 32 44 45 struct sfc_repr_proxy_rxq { 46 struct rte_ring *ring; 47 struct rte_mempool *mb_pool; 48 }; 49 50 struct sfc_repr_proxy_txq { 51 struct rte_ring *ring; 52 }; 53 54 struct sfc_repr_proxy_filter { 55 /* 56 * 2 filters are required to match all incoming traffic, unknown 57 * unicast and unknown multicast. 58 */ 59 efx_filter_spec_t specs[2]; 60 }; 61 62 struct sfc_repr_proxy_port { 63 TAILQ_ENTRY(sfc_repr_proxy_port) entries; 64 uint16_t repr_id; 65 uint16_t rte_port_id; 66 efx_mport_id_t egress_mport; 67 struct sfc_repr_proxy_rxq rxq[SFC_REPR_RXQ_MAX]; 68 struct sfc_repr_proxy_txq txq[SFC_REPR_TXQ_MAX]; 69 struct sfc_mae_rule *mae_rule; 70 bool enabled; 71 bool started; 72 }; 73 74 struct sfc_repr_proxy_dp_rxq { 75 struct rte_mempool *mp; 76 unsigned int ref_count; 77 78 eth_rx_burst_t pkt_burst; 79 struct sfc_dp_rxq *dp; 80 81 uint16_t route_port_id; 82 bool stop_route; 83 unsigned int available; 84 unsigned int forwarded; 85 unsigned int routed; 86 struct rte_mbuf *pkts[SFC_REPR_PROXY_TX_BURST]; 87 88 sfc_sw_index_t sw_index; 89 }; 90 91 struct sfc_repr_proxy_dp_txq { 92 eth_tx_burst_t pkt_burst; 93 struct sfc_dp_txq *dp; 94 95 unsigned int available; 96 unsigned int transmitted; 97 struct rte_mbuf *tx_pkts[SFC_REPR_PROXY_TX_BURST]; 98 99 sfc_sw_index_t sw_index; 100 }; 101 102 enum sfc_repr_proxy_mbox_op { 103 SFC_REPR_PROXY_MBOX_ADD_PORT, 104 SFC_REPR_PROXY_MBOX_DEL_PORT, 105 SFC_REPR_PROXY_MBOX_START_PORT, 106 SFC_REPR_PROXY_MBOX_STOP_PORT, 107 }; 108 109 struct sfc_repr_proxy_mbox { 110 struct sfc_repr_proxy_port *port; 111 enum sfc_repr_proxy_mbox_op op; 112 113 bool write_marker; 114 bool ack; 115 }; 116 117 TAILQ_HEAD(sfc_repr_proxy_ports, sfc_repr_proxy_port); 118 119 struct sfc_repr_proxy { 120 uint32_t service_core_id; 121 uint32_t service_id; 122 efx_mport_id_t mport_alias; 123 struct sfc_repr_proxy_ports ports; 124 bool started; 125 struct sfc_repr_proxy_dp_rxq dp_rxq[SFC_REPR_PROXY_NB_RXQ_MAX]; 126 struct sfc_repr_proxy_dp_txq dp_txq[SFC_REPR_PROXY_NB_TXQ_MAX]; 127 struct sfc_repr_proxy_filter mport_filter; 128 129 struct sfc_repr_proxy_mbox mbox; 130 unsigned int nb_txq; 131 unsigned int nb_rxq; 132 }; 133 134 struct sfc_adapter; 135 136 int sfc_repr_proxy_attach(struct sfc_adapter *sa); 137 void sfc_repr_proxy_pre_detach(struct sfc_adapter *sa); 138 void sfc_repr_proxy_detach(struct sfc_adapter *sa); 139 int sfc_repr_proxy_txq_init(struct sfc_adapter *sa); 140 void sfc_repr_proxy_txq_fini(struct sfc_adapter *sa); 141 int sfc_repr_proxy_start(struct sfc_adapter *sa); 142 void sfc_repr_proxy_stop(struct sfc_adapter *sa); 143 144 #ifdef __cplusplus 145 } 146 #endif 147 #endif /* _SFC_REPR_PROXY_H */ 148