1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2016 - 2018 Cavium Inc. 3 * All rights reserved. 4 * www.cavium.com 5 */ 6 7 #ifndef __ECORE_SRIOV_H__ 8 #define __ECORE_SRIOV_H__ 9 10 #include "ecore_status.h" 11 #include "ecore_vfpf_if.h" 12 #include "ecore_iov_api.h" 13 #include "ecore_hsi_common.h" 14 #include "ecore_l2.h" 15 16 #define ECORE_ETH_MAX_VF_NUM_VLAN_FILTERS \ 17 (MAX_NUM_VFS_K2 * ECORE_ETH_VF_NUM_VLAN_FILTERS) 18 19 /* Represents a full message. Both the request filled by VF 20 * and the response filled by the PF. The VF needs one copy 21 * of this message, it fills the request part and sends it to 22 * the PF. The PF will copy the response to the response part for 23 * the VF to later read it. The PF needs to hold a message like this 24 * per VF, the request that is copied to the PF is placed in the 25 * request size, and the response is filled by the PF before sending 26 * it to the VF. 27 */ 28 struct ecore_vf_mbx_msg { 29 union vfpf_tlvs req; 30 union pfvf_tlvs resp; 31 }; 32 33 /* This mailbox is maintained per VF in its PF 34 * contains all information required for sending / receiving 35 * a message 36 */ 37 struct ecore_iov_vf_mbx { 38 union vfpf_tlvs *req_virt; 39 dma_addr_t req_phys; 40 union pfvf_tlvs *reply_virt; 41 dma_addr_t reply_phys; 42 43 /* Address in VF where a pending message is located */ 44 dma_addr_t pending_req; 45 46 /* Message from VF awaits handling */ 47 bool b_pending_msg; 48 49 u8 *offset; 50 51 #ifdef CONFIG_ECORE_SW_CHANNEL 52 struct ecore_iov_sw_mbx sw_mbx; 53 #endif 54 55 /* VF GPA address */ 56 u32 vf_addr_lo; 57 u32 vf_addr_hi; 58 59 struct vfpf_first_tlv first_tlv; /* saved VF request header */ 60 61 u8 flags; 62 #define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent 63 * more then one pending msg 64 */ 65 }; 66 67 #define ECORE_IOV_LEGACY_QID_RX (0) 68 #define ECORE_IOV_LEGACY_QID_TX (1) 69 #define ECORE_IOV_QID_INVALID (0xFE) 70 71 struct ecore_vf_queue_cid { 72 bool b_is_tx; 73 struct ecore_queue_cid *p_cid; 74 }; 75 76 /* Describes a qzone associated with the VF */ 77 struct ecore_vf_queue { 78 /* Input from upper-layer, mapping relateive queue to queue-zone */ 79 u16 fw_rx_qid; 80 u16 fw_tx_qid; 81 82 struct ecore_vf_queue_cid cids[MAX_QUEUES_PER_QZONE]; 83 }; 84 85 enum vf_state { 86 VF_FREE = 0, /* VF ready to be acquired holds no resc */ 87 VF_ACQUIRED = 1, /* VF, acquired, but not initalized */ 88 VF_ENABLED = 2, /* VF, Enabled */ 89 VF_RESET = 3, /* VF, FLR'd, pending cleanup */ 90 VF_STOPPED = 4 /* VF, Stopped */ 91 }; 92 93 struct ecore_vf_vlan_shadow { 94 bool used; 95 u16 vid; 96 }; 97 98 struct ecore_vf_shadow_config { 99 /* Shadow copy of all guest vlans */ 100 struct ecore_vf_vlan_shadow vlans[ECORE_ETH_VF_NUM_VLAN_FILTERS + 1]; 101 102 /* Shadow copy of all configured MACs; Empty if forcing MACs */ 103 u8 macs[ECORE_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN]; 104 u8 inner_vlan_removal; 105 }; 106 107 /* PFs maintain an array of this structure, per VF */ 108 struct ecore_vf_info { 109 struct ecore_iov_vf_mbx vf_mbx; 110 enum vf_state state; 111 bool b_init; 112 bool b_malicious; 113 u8 to_disable; 114 115 struct ecore_bulletin bulletin; 116 dma_addr_t vf_bulletin; 117 118 #ifdef CONFIG_ECORE_SW_CHANNEL 119 /* Determine whether PF communicate with VF using HW/SW channel */ 120 bool b_hw_channel; 121 #endif 122 123 /* PF saves a copy of the last VF acquire message */ 124 struct vfpf_acquire_tlv acquire; 125 126 u32 concrete_fid; 127 u16 opaque_fid; 128 u16 mtu; 129 130 u8 vport_id; 131 u8 rss_eng_id; 132 u8 relative_vf_id; 133 u8 abs_vf_id; 134 #define ECORE_VF_ABS_ID(p_hwfn, p_vf) (ECORE_PATH_ID(p_hwfn) ? \ 135 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \ 136 (p_vf)->abs_vf_id) 137 138 u8 vport_instance; /* Number of active vports */ 139 u8 num_rxqs; 140 u8 num_txqs; 141 142 u16 rx_coal; 143 u16 tx_coal; 144 145 u8 num_sbs; 146 147 u8 num_mac_filters; 148 u8 num_vlan_filters; 149 150 struct ecore_vf_queue vf_queues[ECORE_MAX_VF_CHAINS_PER_PF]; 151 u16 igu_sbs[ECORE_MAX_VF_CHAINS_PER_PF]; 152 153 /* TODO - Only windows is using it - should be removed */ 154 u8 was_malicious; 155 u8 num_active_rxqs; 156 void *ctx; 157 struct ecore_public_vf_info p_vf_info; 158 bool spoof_chk; /* Current configured on HW */ 159 bool req_spoofchk_val; /* Requested value */ 160 161 /* Stores the configuration requested by VF */ 162 struct ecore_vf_shadow_config shadow_config; 163 164 /* A bitfield using bulletin's valid-map bits, used to indicate 165 * which of the bulletin board features have been configured. 166 */ 167 u64 configured_features; 168 #define ECORE_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \ 169 (1 << VLAN_ADDR_FORCED)) 170 }; 171 172 /* This structure is part of ecore_hwfn and used only for PFs that have sriov 173 * capability enabled. 174 */ 175 struct ecore_pf_iov { 176 struct ecore_vf_info vfs_array[MAX_NUM_VFS_K2]; 177 u64 pending_flr[ECORE_VF_ARRAY_LENGTH]; 178 179 #ifndef REMOVE_DBG 180 /* This doesn't serve anything functionally, but it makes windows 181 * debugging of IOV related issues easier. 182 */ 183 u64 active_vfs[ECORE_VF_ARRAY_LENGTH]; 184 #endif 185 186 /* Allocate message address continuosuly and split to each VF */ 187 void *mbx_msg_virt_addr; 188 dma_addr_t mbx_msg_phys_addr; 189 u32 mbx_msg_size; 190 void *mbx_reply_virt_addr; 191 dma_addr_t mbx_reply_phys_addr; 192 u32 mbx_reply_size; 193 void *p_bulletins; 194 dma_addr_t bulletins_phys; 195 u32 bulletins_size; 196 }; 197 198 #ifdef CONFIG_ECORE_SRIOV 199 /** 200 * @brief Read sriov related information and allocated resources 201 * reads from configuraiton space, shmem, etc. 202 * 203 * @param p_hwfn 204 * 205 * @return enum _ecore_status_t 206 */ 207 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn); 208 209 /** 210 * @brief ecore_add_tlv - place a given tlv on the tlv buffer at next offset 211 * 212 * @param offset 213 * @param type 214 * @param length 215 * 216 * @return pointer to the newly placed tlv 217 */ 218 void *ecore_add_tlv(u8 **offset, u16 type, u16 length); 219 220 /** 221 * @brief list the types and lengths of the tlvs on the buffer 222 * 223 * @param p_hwfn 224 * @param tlvs_list 225 */ 226 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, 227 void *tlvs_list); 228 229 /** 230 * @brief ecore_iov_alloc - allocate sriov related resources 231 * 232 * @param p_hwfn 233 * 234 * @return enum _ecore_status_t 235 */ 236 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn); 237 238 /** 239 * @brief ecore_iov_setup - setup sriov related resources 240 * 241 * @param p_hwfn 242 */ 243 void ecore_iov_setup(struct ecore_hwfn *p_hwfn); 244 245 /** 246 * @brief ecore_iov_free - free sriov related resources 247 * 248 * @param p_hwfn 249 */ 250 void ecore_iov_free(struct ecore_hwfn *p_hwfn); 251 252 /** 253 * @brief free sriov related memory that was allocated during hw_prepare 254 * 255 * @param p_dev 256 */ 257 void ecore_iov_free_hw_info(struct ecore_dev *p_dev); 258 259 /** 260 * @brief Mark structs of vfs that have been FLR-ed. 261 * 262 * @param p_hwfn 263 * @param disabled_vfs - bitmask of all VFs on path that were FLRed 264 * 265 * @return true iff one of the PF's vfs got FLRed. false otherwise. 266 */ 267 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, 268 u32 *disabled_vfs); 269 270 /** 271 * @brief Search extended TLVs in request/reply buffer. 272 * 273 * @param p_hwfn 274 * @param p_tlvs_list - Pointer to tlvs list 275 * @param req_type - Type of TLV 276 * 277 * @return pointer to tlv type if found, otherwise returns NULL. 278 */ 279 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn, 280 void *p_tlvs_list, u16 req_type); 281 282 /** 283 * @brief ecore_iov_get_vf_info - return the database of a 284 * specific VF 285 * 286 * @param p_hwfn 287 * @param relative_vf_id - relative id of the VF for which info 288 * is requested 289 * @param b_enabled_only - false iff want to access even if vf is disabled 290 * 291 * @return struct ecore_vf_info* 292 */ 293 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn, 294 u16 relative_vf_id, 295 bool b_enabled_only); 296 #endif 297 #endif /* __ECORE_SRIOV_H__ */ 298