Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2023 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef _CPFL_ETHDEV_H_ 6 : : #define _CPFL_ETHDEV_H_ 7 : : 8 : : #include <stdint.h> 9 : : #include <rte_malloc.h> 10 : : #include <rte_spinlock.h> 11 : : #include <rte_ethdev.h> 12 : : #include <rte_kvargs.h> 13 : : #include <rte_hash.h> 14 : : #include <ethdev_driver.h> 15 : : #include <ethdev_pci.h> 16 : : 17 : : #include <idpf_common_device.h> 18 : : #include <idpf_common_virtchnl.h> 19 : : #include <base/idpf_prototype.h> 20 : : #include <base/virtchnl2.h> 21 : : 22 : : #include "cpfl_logs.h" 23 : : #include "cpfl_cpchnl.h" 24 : : #include "cpfl_representor.h" 25 : : #include "cpfl_controlq.h" 26 : : 27 : : /* Currently, backend supports up to 8 vports */ 28 : : #define CPFL_MAX_VPORT_NUM 8 29 : : 30 : : #define CPFL_INVALID_VPORT_IDX 0xffff 31 : : 32 : : #define CPFL_DFLT_Q_VEC_NUM 1 33 : : 34 : : #define CPFL_MIN_BUF_SIZE 1024 35 : : #define CPFL_MAX_FRAME_SIZE 9728 36 : : #define CPFL_DEFAULT_MTU RTE_ETHER_MTU 37 : : 38 : : #define CPFL_VLAN_TAG_SIZE 4 39 : : #define CPFL_ETH_OVERHEAD \ 40 : : (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + CPFL_VLAN_TAG_SIZE * 2) 41 : : 42 : : #define CPFL_RSS_OFFLOAD_ALL ( \ 43 : : RTE_ETH_RSS_IPV4 | \ 44 : : RTE_ETH_RSS_FRAG_IPV4 | \ 45 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | \ 46 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP | \ 47 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \ 48 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER | \ 49 : : RTE_ETH_RSS_IPV6 | \ 50 : : RTE_ETH_RSS_FRAG_IPV6 | \ 51 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | \ 52 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP | \ 53 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \ 54 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER | \ 55 : : RTE_ETH_RSS_L2_PAYLOAD) 56 : : 57 : : #define CPFL_ADAPTER_NAME_LEN (PCI_PRI_STR_SIZE + 1) 58 : : 59 : : #define CPFL_ALARM_INTERVAL 50000 /* us */ 60 : : 61 : : /* Device IDs */ 62 : : #define IDPF_DEV_ID_CPF 0x1453 63 : : #define VIRTCHNL2_QUEUE_GROUP_P2P 0x100 64 : : 65 : : #define CPFL_HOST_ID_NUM 2 66 : : #define CPFL_PF_TYPE_NUM 2 67 : : #define CPFL_HOST_ID_HOST 0 68 : : #define CPFL_HOST_ID_ACC 1 69 : : #define CPFL_PF_TYPE_APF 0 70 : : #define CPFL_PF_TYPE_CPF 1 71 : : 72 : : /* Function IDs on IMC side */ 73 : : #define CPFL_HOST0_APF 0 74 : : #define CPFL_ACC_APF_ID 4 75 : : #define CPFL_HOST0_CPF_ID 8 76 : : #define CPFL_ACC_CPF_ID 12 77 : : 78 : : #define CPFL_VPORT_LAN_PF 0 79 : : #define CPFL_VPORT_LAN_VF 1 80 : : 81 : : #define CPFL_FLOW_FILE_LEN 100 82 : : #define CPFL_INVALID_HW_ID UINT16_MAX 83 : : #define CPFL_META_CHUNK_LENGTH 1024 84 : : #define CPFL_META_LENGTH 32 85 : : 86 : : #define CPFL_RX_CFGQ_NUM 4 87 : : #define CPFL_TX_CFGQ_NUM 4 88 : : #define CPFL_FPCP_CFGQ_TX 0 89 : : #define CPFL_FPCP_CFGQ_RX 1 90 : : #define CPFL_CFGQ_NUM 8 91 : : 92 : : /* bit[15:14] type 93 : : * bit[13] host/accelerator core 94 : : * bit[12] apf/cpf 95 : : * bit[11:0] vf 96 : : */ 97 : : #define CPFL_REPRESENTOR_ID(type, host_id, pf_id, vf_id) \ 98 : : ((((type) & 0x3) << 14) + (((host_id) & 0x1) << 13) + \ 99 : : (((pf_id) & 0x1) << 12) + ((vf_id) & 0xfff)) 100 : : 101 : : struct cpfl_vport_param { 102 : : struct cpfl_adapter_ext *adapter; 103 : : uint16_t devarg_id; /* arg id from user */ 104 : : uint16_t idx; /* index in adapter->vports[]*/ 105 : : }; 106 : : 107 : : #define CPFL_REPR_ARG_NUM_MAX 4 108 : : /* Struct used when parse driver specific devargs */ 109 : : struct cpfl_devargs { 110 : : uint16_t req_vports[CPFL_MAX_VPORT_NUM]; 111 : : uint16_t req_vport_nb; 112 : : uint8_t repr_args_num; 113 : : struct rte_eth_devargs repr_args[CPFL_REPR_ARG_NUM_MAX]; 114 : : char flow_parser[CPFL_FLOW_FILE_LEN]; 115 : : }; 116 : : 117 : : struct p2p_queue_chunks_info { 118 : : uint32_t tx_start_qid; 119 : : uint32_t rx_start_qid; 120 : : uint32_t tx_compl_start_qid; 121 : : uint32_t rx_buf_start_qid; 122 : : 123 : : uint64_t tx_qtail_start; 124 : : uint32_t tx_qtail_spacing; 125 : : uint64_t rx_qtail_start; 126 : : uint32_t rx_qtail_spacing; 127 : : uint64_t tx_compl_qtail_start; 128 : : uint32_t tx_compl_qtail_spacing; 129 : : uint64_t rx_buf_qtail_start; 130 : : uint32_t rx_buf_qtail_spacing; 131 : : }; 132 : : 133 : : struct cpfl_vport_id { 134 : : uint32_t vport_id; 135 : : uint8_t func_type; 136 : : uint8_t pf_id; 137 : : uint16_t vf_id; 138 : : }; 139 : : 140 : : struct cpfl_vport_info { 141 : : struct cpchnl2_event_vport_created vport; 142 : : bool enabled; 143 : : }; 144 : : 145 : : enum cpfl_itf_type { 146 : : CPFL_ITF_TYPE_VPORT, 147 : : CPFL_ITF_TYPE_REPRESENTOR, 148 : : }; 149 : : 150 : : TAILQ_HEAD(cpfl_flow_list, rte_flow); 151 : : 152 : : #define CPFL_FLOW_BATCH_SIZE 490 153 : : struct cpfl_itf { 154 : : enum cpfl_itf_type type; 155 : : struct cpfl_adapter_ext *adapter; 156 : : struct cpfl_flow_list flow_list; 157 : : struct idpf_dma_mem flow_dma; 158 : : struct idpf_dma_mem dma[CPFL_FLOW_BATCH_SIZE]; 159 : : struct idpf_ctlq_msg msg[CPFL_FLOW_BATCH_SIZE]; 160 : : void *data; 161 : : }; 162 : : 163 : : struct cpfl_vport { 164 : : struct cpfl_itf itf; 165 : : struct idpf_vport base; 166 : : struct p2p_queue_chunks_info *p2p_q_chunks_info; 167 : : 168 : : struct rte_mempool *p2p_mp; 169 : : 170 : : uint16_t nb_data_rxq; 171 : : uint16_t nb_data_txq; 172 : : uint16_t nb_p2p_rxq; 173 : : uint16_t nb_p2p_txq; 174 : : 175 : : struct idpf_rx_queue *p2p_rx_bufq; 176 : : struct idpf_tx_queue *p2p_tx_complq; 177 : : bool p2p_manual_bind; 178 : : }; 179 : : 180 : : struct cpfl_repr { 181 : : struct cpfl_itf itf; 182 : : struct cpfl_repr_id repr_id; 183 : : struct rte_ether_addr mac_addr; 184 : : struct cpfl_vport_info *vport_info; 185 : : bool func_up; /* If the represented function is up */ 186 : : }; 187 : : 188 : : struct cpfl_metadata_chunk { 189 : : int type; 190 : : uint8_t data[CPFL_META_CHUNK_LENGTH]; 191 : : }; 192 : : 193 : : /** 194 : : * It is driver's responsibility to simlulate a metadata buffer which 195 : : * can be used as data source to fill the key of a flow rule. 196 : : */ 197 : : struct cpfl_metadata { 198 : : int length; 199 : : struct cpfl_metadata_chunk chunks[CPFL_META_LENGTH]; 200 : : }; 201 : : 202 : : struct cpfl_adapter_ext { 203 : : TAILQ_ENTRY(cpfl_adapter_ext) next; 204 : : struct idpf_adapter base; 205 : : 206 : : char name[CPFL_ADAPTER_NAME_LEN]; 207 : : 208 : : struct cpfl_vport **vports; 209 : : uint16_t max_vport_nb; 210 : : 211 : : uint16_t cur_vports; /* bit mask of created vport */ 212 : : uint16_t cur_vport_nb; 213 : : 214 : : uint16_t used_vecs_num; 215 : : 216 : : rte_spinlock_t vport_map_lock; 217 : : struct rte_hash *vport_map_hash; 218 : : 219 : : rte_spinlock_t repr_lock; 220 : : struct rte_hash *repr_allowlist_hash; 221 : : 222 : : struct cpfl_flow_js_parser *flow_parser; 223 : : struct rte_bitmap *mod_bm; 224 : : void *mod_bm_mem; 225 : : 226 : : struct cpfl_metadata meta; 227 : : 228 : : /* ctrl vport and ctrl queues. */ 229 : : struct cpfl_vport ctrl_vport; 230 : : uint8_t ctrl_vport_recv_info[IDPF_DFLT_MBX_BUF_SIZE]; 231 : : struct idpf_ctlq_info *ctlqp[CPFL_CFGQ_NUM]; 232 : : struct cpfl_ctlq_create_info cfgq_info[CPFL_CFGQ_NUM]; 233 : : }; 234 : : 235 : : TAILQ_HEAD(cpfl_adapter_list, cpfl_adapter_ext); 236 : : 237 : : int cpfl_vport_info_create(struct cpfl_adapter_ext *adapter, 238 : : struct cpfl_vport_id *vport_identity, 239 : : struct cpchnl2_event_vport_created *vport); 240 : : int cpfl_cc_vport_list_get(struct cpfl_adapter_ext *adapter, 241 : : struct cpfl_vport_id *vi, 242 : : struct cpchnl2_get_vport_list_response *response); 243 : : int cpfl_cc_vport_info_get(struct cpfl_adapter_ext *adapter, 244 : : struct cpchnl2_vport_id *vport_id, 245 : : struct cpfl_vport_id *vi, 246 : : struct cpchnl2_get_vport_info_response *response); 247 : : int cpfl_vc_create_ctrl_vport(struct cpfl_adapter_ext *adapter); 248 : : int cpfl_config_ctlq_rx(struct cpfl_adapter_ext *adapter); 249 : : int cpfl_config_ctlq_tx(struct cpfl_adapter_ext *adapter); 250 : : int cpfl_alloc_dma_mem_batch(struct idpf_dma_mem *orig_dma, struct idpf_dma_mem *dma, 251 : : uint32_t size, int batch_size); 252 : : 253 : : #define CPFL_DEV_TO_PCI(eth_dev) \ 254 : : RTE_DEV_TO_PCI((eth_dev)->device) 255 : : #define CPFL_ADAPTER_TO_EXT(p) \ 256 : : container_of((p), struct cpfl_adapter_ext, base) 257 : : #define CPFL_DEV_TO_VPORT(dev) \ 258 : : ((struct cpfl_vport *)((dev)->data->dev_private)) 259 : : #define CPFL_DEV_TO_REPR(dev) \ 260 : : ((struct cpfl_repr *)((dev)->data->dev_private)) 261 : : #define CPFL_DEV_TO_ITF(dev) \ 262 : : ((struct cpfl_itf *)((dev)->data->dev_private)) 263 : : 264 : : static inline uint16_t 265 : : cpfl_get_port_id(struct cpfl_itf *itf) 266 : : { 267 [ # # ]: 0 : if (!itf) 268 : : return CPFL_INVALID_HW_ID; 269 : : 270 [ # # ]: 0 : if (itf->type == CPFL_ITF_TYPE_VPORT) { 271 : : struct cpfl_vport *vport = (void *)itf; 272 : : 273 [ # # ]: 0 : return vport->base.devarg_id; 274 : : } 275 : : 276 : : return CPFL_INVALID_HW_ID; 277 : : } 278 : : 279 : : static inline uint16_t 280 : 0 : cpfl_get_vsi_id(struct cpfl_itf *itf) 281 : : { 282 : : struct cpfl_vport_info *info; 283 : : uint32_t vport_id; 284 : : int ret; 285 : : struct cpfl_vport_id vport_identity; 286 : : 287 [ # # ]: 0 : if (!itf) 288 : : return CPFL_INVALID_HW_ID; 289 : : 290 [ # # ]: 0 : if (itf->type == CPFL_ITF_TYPE_REPRESENTOR) { 291 : : struct cpfl_repr *repr = (void *)itf; 292 : : 293 : 0 : return repr->vport_info->vport.info.vsi_id; 294 [ # # ]: 0 : } else if (itf->type == CPFL_ITF_TYPE_VPORT) { 295 : 0 : vport_id = ((struct cpfl_vport *)itf)->base.vport_id; 296 : : 297 : 0 : vport_identity.func_type = CPCHNL2_FTYPE_LAN_PF; 298 : : /* host: CPFL_HOST0_CPF_ID, acc: CPFL_ACC_CPF_ID */ 299 : 0 : vport_identity.pf_id = CPFL_ACC_CPF_ID; 300 : 0 : vport_identity.vf_id = 0; 301 : 0 : vport_identity.vport_id = vport_id; 302 : 0 : ret = rte_hash_lookup_data(itf->adapter->vport_map_hash, 303 : : &vport_identity, 304 : : (void **)&info); 305 [ # # ]: 0 : if (ret < 0) { 306 : 0 : PMD_DRV_LOG(ERR, "vport id not exist"); 307 : 0 : goto err; 308 : : } 309 : : 310 : 0 : return info->vport.info.vsi_id; 311 : : } 312 : : 313 : 0 : err: 314 : : return CPFL_INVALID_HW_ID; 315 : : } 316 : : 317 : : static inline struct cpfl_itf * 318 : 0 : cpfl_get_itf_by_port_id(uint16_t port_id) 319 : : { 320 : : struct rte_eth_dev *dev; 321 : : 322 [ # # ]: 0 : if (port_id >= RTE_MAX_ETHPORTS) { 323 : 0 : PMD_DRV_LOG(ERR, "port_id should be < %d.", RTE_MAX_ETHPORTS); 324 : 0 : return NULL; 325 : : } 326 : : 327 : 0 : dev = &rte_eth_devices[port_id]; 328 [ # # ]: 0 : if (dev->state == RTE_ETH_DEV_UNUSED) { 329 : 0 : PMD_DRV_LOG(ERR, "eth_dev[%d] is unused.", port_id); 330 : 0 : return NULL; 331 : : } 332 : : 333 [ # # ]: 0 : if (!dev->data) { 334 : 0 : PMD_DRV_LOG(ERR, "eth_dev[%d] data not be allocated.", port_id); 335 : 0 : return NULL; 336 : : } 337 : : 338 : 0 : return CPFL_DEV_TO_ITF(dev); 339 : : } 340 : : #endif /* _CPFL_ETHDEV_H_ */