Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2023 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef _IDPF_COMMON_DEVICE_H_ 6 : : #define _IDPF_COMMON_DEVICE_H_ 7 : : 8 : : #include <rte_mbuf_ptype.h> 9 : : #include "base/idpf_prototype.h" 10 : : #include "base/virtchnl2.h" 11 : : #include "idpf_common_logs.h" 12 : : 13 : : #define IDPF_DEV_ID_SRIOV 0x145C 14 : : 15 : : #define IDPF_RSS_KEY_LEN 52 16 : : 17 : : #define IDPF_CTLQ_ID -1 18 : : #define IDPF_CTLQ_LEN 64 19 : : #define IDPF_DFLT_MBX_BUF_SIZE 4096 20 : : 21 : : #define IDPF_DEFAULT_RXQ_NUM 16 22 : : #define IDPF_RX_BUFQ_PER_GRP 2 23 : : #define IDPF_RXQ_PER_GRP 1 24 : : #define IDPF_DEFAULT_TXQ_NUM 16 25 : : #define IDPF_TX_COMPLQ_PER_GRP 1 26 : : #define IDPF_TXQ_PER_GRP 1 27 : : 28 : : #define IDPF_MIN_FRAME_SIZE 14 29 : : 30 : : #define IDPF_MAX_PKT_TYPE 1024 31 : : 32 : : #define IDPF_DFLT_INTERVAL 16 33 : : 34 : : #define IDPF_RX_MAX_PTYPE_PROTO_IDS 32 35 : : #define IDPF_RX_MAX_PTYPE_SZ (sizeof(struct virtchnl2_ptype) + \ 36 : : (sizeof(uint16_t) * \ 37 : : (IDPF_RX_MAX_PTYPE_PROTO_IDS - 1))) 38 : : #define IDPF_RX_PTYPE_HDR_SZ (sizeof(struct virtchnl2_get_ptype_info) - \ 39 : : sizeof(struct virtchnl2_ptype)) 40 : : #define IDPF_RX_MAX_PTYPES_PER_BUF \ 41 : : ((IDPF_DFLT_MBX_BUF_SIZE - IDPF_RX_PTYPE_HDR_SZ)/ \ 42 : : IDPF_RX_MAX_PTYPE_SZ) 43 : : #define IDPF_GET_PTYPE_SIZE(p) \ 44 : : (sizeof(struct virtchnl2_ptype) + \ 45 : : (((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof((p)->proto_id[0]))) 46 : : 47 : : struct idpf_adapter { 48 : : struct idpf_hw hw; 49 : : struct virtchnl2_version_info virtchnl_version; 50 : : struct virtchnl2_get_capabilities caps; 51 : : volatile RTE_ATOMIC(uint32_t) pend_cmd; /* pending command not finished */ 52 : : uint32_t cmd_retval; /* return value of the cmd response from cp */ 53 : : uint8_t *mbx_resp; /* buffer to store the mailbox response from cp */ 54 : : 55 : : alignas(RTE_CACHE_LINE_MIN_SIZE) uint32_t ptype_tbl[IDPF_MAX_PKT_TYPE]; 56 : : 57 : : bool is_tx_singleq; /* true - single queue model, false - split queue model */ 58 : : bool is_rx_singleq; /* true - single queue model, false - split queue model */ 59 : : 60 : : /* For timestamp */ 61 : : uint64_t time_hw; 62 : : }; 63 : : 64 : : struct idpf_chunks_info { 65 : : uint32_t tx_start_qid; 66 : : uint32_t rx_start_qid; 67 : : /* Valid only if split queue model */ 68 : : uint32_t tx_compl_start_qid; 69 : : uint32_t rx_buf_start_qid; 70 : : 71 : : uint64_t tx_qtail_start; 72 : : uint32_t tx_qtail_spacing; 73 : : uint64_t rx_qtail_start; 74 : : uint32_t rx_qtail_spacing; 75 : : uint64_t tx_compl_qtail_start; 76 : : uint32_t tx_compl_qtail_spacing; 77 : : uint64_t rx_buf_qtail_start; 78 : : uint32_t rx_buf_qtail_spacing; 79 : : }; 80 : : 81 : : struct idpf_vport { 82 : : struct idpf_adapter *adapter; /* Backreference to associated adapter */ 83 : : union { 84 : : struct virtchnl2_create_vport info; /* virtchnl response info handling */ 85 : : uint8_t data[IDPF_DFLT_MBX_BUF_SIZE]; 86 : : } vport_info; 87 : : uint16_t sw_idx; /* SW index in adapter->vports[]*/ 88 : : uint16_t vport_id; 89 : : uint32_t txq_model; 90 : : uint32_t rxq_model; 91 : : uint16_t num_tx_q; 92 : : /* valid only if txq_model is split Q */ 93 : : uint16_t num_tx_complq; 94 : : uint16_t num_rx_q; 95 : : /* valid only if rxq_model is split Q */ 96 : : uint16_t num_rx_bufq; 97 : : 98 : : uint16_t max_mtu; 99 : : uint8_t default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 100 : : 101 : : enum virtchnl_rss_algorithm rss_algorithm; 102 : : uint16_t rss_key_size; 103 : : uint16_t rss_lut_size; 104 : : 105 : : void *dev_data; /* Pointer to the device data */ 106 : : uint16_t max_pkt_len; /* Maximum packet length */ 107 : : 108 : : /* RSS info */ 109 : : uint32_t *rss_lut; 110 : : uint8_t *rss_key; 111 : : uint64_t rss_hf; 112 : : uint64_t last_general_rss_hf; 113 : : 114 : : /* MSIX info*/ 115 : : struct virtchnl2_queue_vector *qv_map; /* queue vector mapping */ 116 : : uint16_t max_vectors; 117 : : struct virtchnl2_alloc_vectors *recv_vectors; 118 : : 119 : : /* Chunk info */ 120 : : struct idpf_chunks_info chunks_info; 121 : : 122 : : uint16_t devarg_id; 123 : : 124 : : bool rx_vec_allowed; 125 : : bool tx_vec_allowed; 126 : : bool rx_use_avx512; 127 : : bool tx_use_avx512; 128 : : 129 : : struct virtchnl2_vport_stats eth_stats_offset; 130 : : 131 : : /* Event from ipf */ 132 : : bool link_up; 133 : : uint32_t link_speed; 134 : : }; 135 : : 136 : : /* Message type read in virtual channel from PF */ 137 : : enum idpf_vc_result { 138 : : IDPF_MSG_ERR = -1, /* Meet error when accessing admin queue */ 139 : : IDPF_MSG_NON, /* Read nothing from admin queue */ 140 : : IDPF_MSG_SYS, /* Read system msg from admin queue */ 141 : : IDPF_MSG_CMD, /* Read async command result */ 142 : : }; 143 : : 144 : : /* structure used for sending and checking response of virtchnl ops */ 145 : : struct idpf_cmd_info { 146 : : uint32_t ops; 147 : : uint8_t *in_args; /* buffer for sending */ 148 : : uint32_t in_args_size; /* buffer size for sending */ 149 : : uint8_t *out_buffer; /* buffer for response */ 150 : : uint32_t out_size; /* buffer size for response */ 151 : : }; 152 : : 153 : : /* notify current command done. Only call in case execute 154 : : * _atomic_set_cmd successfully. 155 : : */ 156 : : static inline void 157 : : notify_cmd(struct idpf_adapter *adapter, int msg_ret) 158 : : { 159 : : adapter->cmd_retval = msg_ret; 160 : : /* Return value may be checked in anither thread, need to ensure the coherence. */ 161 : : rte_wmb(); 162 : 0 : adapter->pend_cmd = VIRTCHNL2_OP_UNKNOWN; 163 : 0 : } 164 : : 165 : : /* clear current command. Only call in case execute 166 : : * _atomic_set_cmd successfully. 167 : : */ 168 : : static inline void 169 : : clear_cmd(struct idpf_adapter *adapter) 170 : : { 171 : : /* Return value may be checked in anither thread, need to ensure the coherence. */ 172 : : rte_wmb(); 173 : 0 : adapter->pend_cmd = VIRTCHNL2_OP_UNKNOWN; 174 : 0 : adapter->cmd_retval = VIRTCHNL_STATUS_SUCCESS; 175 : 0 : } 176 : : 177 : : /* Check there is pending cmd in execution. If none, set new command. */ 178 : : static inline bool 179 : 0 : atomic_set_cmd(struct idpf_adapter *adapter, uint32_t ops) 180 : : { 181 : : uint32_t op_unk = VIRTCHNL2_OP_UNKNOWN; 182 : 0 : bool ret = rte_atomic_compare_exchange_strong_explicit(&adapter->pend_cmd, &op_unk, ops, 183 : : rte_memory_order_acquire, rte_memory_order_acquire); 184 : : 185 [ # # ]: 0 : if (!ret) 186 : 0 : DRV_LOG(ERR, "There is incomplete cmd %d", adapter->pend_cmd); 187 : : 188 : 0 : return !ret; 189 : : } 190 : : 191 : : __rte_internal 192 : : int idpf_adapter_init(struct idpf_adapter *adapter); 193 : : __rte_internal 194 : : int idpf_adapter_deinit(struct idpf_adapter *adapter); 195 : : __rte_internal 196 : : int idpf_vport_init(struct idpf_vport *vport, 197 : : struct virtchnl2_create_vport *vport_req_info, 198 : : void *dev_data); 199 : : __rte_internal 200 : : int idpf_vport_deinit(struct idpf_vport *vport); 201 : : __rte_internal 202 : : int idpf_vport_rss_config(struct idpf_vport *vport); 203 : : __rte_internal 204 : : int idpf_vport_irq_map_config(struct idpf_vport *vport, uint16_t nb_rx_queues); 205 : : __rte_internal 206 : : int idpf_vport_irq_unmap_config(struct idpf_vport *vport, uint16_t nb_rx_queues); 207 : : __rte_internal 208 : : int idpf_vport_info_init(struct idpf_vport *vport, 209 : : struct virtchnl2_create_vport *vport_info); 210 : : __rte_internal 211 : : void idpf_vport_stats_update(struct virtchnl2_vport_stats *oes, struct virtchnl2_vport_stats *nes); 212 : : __rte_internal 213 : : int idpf_vport_irq_map_config_by_qids(struct idpf_vport *vport, 214 : : uint32_t *qids, 215 : : uint16_t nb_rx_queues); 216 : : 217 : : #endif /* _IDPF_COMMON_DEVICE_H_ */