Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
| 2 | * Copyright (c) 2015 QLogic Corporation |
| 3 | * |
| 4 | * This software is available under the terms of the GNU General Public License |
| 5 | * (GPL) Version 2, available from the file COPYING in the main directory of |
| 6 | * this source tree. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _QED_SRIOV_H |
| 10 | #define _QED_SRIOV_H |
| 11 | #include <linux/types.h> |
| 12 | #include "qed_vf.h" |
| 13 | #define QED_VF_ARRAY_LENGTH (3) |
| 14 | |
| 15 | #define IS_VF(cdev) ((cdev)->b_is_vf) |
| 16 | #define IS_PF(cdev) (!((cdev)->b_is_vf)) |
| 17 | #ifdef CONFIG_QED_SRIOV |
| 18 | #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->cdev->p_iov_info)) |
| 19 | #else |
| 20 | #define IS_PF_SRIOV(p_hwfn) (0) |
| 21 | #endif |
| 22 | #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info)) |
| 23 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 24 | #define QED_MAX_VF_CHAINS_PER_PF 16 |
| 25 | #define QED_ETH_VF_NUM_VLAN_FILTERS 2 |
| 26 | |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 27 | #define QED_ETH_MAX_VF_NUM_VLAN_FILTERS \ |
| 28 | (MAX_NUM_VFS * QED_ETH_VF_NUM_VLAN_FILTERS) |
| 29 | |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 30 | enum qed_iov_vport_update_flag { |
| 31 | QED_IOV_VP_UPDATE_ACTIVATE, |
Yuval Mintz | 17b235c | 2016-05-11 16:36:18 +0300 | [diff] [blame] | 32 | QED_IOV_VP_UPDATE_VLAN_STRIP, |
| 33 | QED_IOV_VP_UPDATE_TX_SWITCH, |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 34 | QED_IOV_VP_UPDATE_MCAST, |
| 35 | QED_IOV_VP_UPDATE_ACCEPT_PARAM, |
| 36 | QED_IOV_VP_UPDATE_RSS, |
Yuval Mintz | 17b235c | 2016-05-11 16:36:18 +0300 | [diff] [blame] | 37 | QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN, |
| 38 | QED_IOV_VP_UPDATE_SGE_TPA, |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 39 | QED_IOV_VP_UPDATE_MAX, |
| 40 | }; |
| 41 | |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 42 | struct qed_public_vf_info { |
| 43 | /* These copies will later be reflected in the bulletin board, |
| 44 | * but this copy should be newer. |
| 45 | */ |
Yuval Mintz | eff1696 | 2016-05-11 16:36:21 +0300 | [diff] [blame] | 46 | u8 forced_mac[ETH_ALEN]; |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 47 | u16 forced_vlan; |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 48 | u8 mac[ETH_ALEN]; |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 49 | |
| 50 | /* IFLA_VF_LINK_STATE_<X> */ |
| 51 | int link_state; |
| 52 | |
| 53 | /* Currently configured Tx rate in MB/sec. 0 if unconfigured */ |
| 54 | int tx_rate; |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 55 | }; |
| 56 | |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 57 | /* This struct is part of qed_dev and contains data relevant to all hwfns; |
| 58 | * Initialized only if SR-IOV cpabability is exposed in PCIe config space. |
| 59 | */ |
| 60 | struct qed_hw_sriov_info { |
| 61 | int pos; /* capability position */ |
| 62 | int nres; /* number of resources */ |
| 63 | u32 cap; /* SR-IOV Capabilities */ |
| 64 | u16 ctrl; /* SR-IOV Control */ |
| 65 | u16 total_vfs; /* total VFs associated with the PF */ |
| 66 | u16 num_vfs; /* number of vfs that have been started */ |
| 67 | u16 initial_vfs; /* initial VFs associated with the PF */ |
| 68 | u16 nr_virtfn; /* number of VFs available */ |
| 69 | u16 offset; /* first VF Routing ID offset */ |
| 70 | u16 stride; /* following VF stride */ |
| 71 | u16 vf_device_id; /* VF device id */ |
| 72 | u32 pgsz; /* page size for BAR alignment */ |
| 73 | u8 link; /* Function Dependency Link */ |
| 74 | |
| 75 | u32 first_vf_in_pf; |
| 76 | }; |
| 77 | |
| 78 | /* This mailbox is maintained per VF in its PF contains all information |
| 79 | * required for sending / receiving a message. |
| 80 | */ |
| 81 | struct qed_iov_vf_mbx { |
| 82 | union vfpf_tlvs *req_virt; |
| 83 | dma_addr_t req_phys; |
| 84 | union pfvf_tlvs *reply_virt; |
| 85 | dma_addr_t reply_phys; |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 86 | |
| 87 | /* Address in VF where a pending message is located */ |
| 88 | dma_addr_t pending_req; |
| 89 | |
| 90 | u8 *offset; |
| 91 | |
| 92 | /* saved VF request header */ |
| 93 | struct vfpf_first_tlv first_tlv; |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 94 | }; |
| 95 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 96 | struct qed_vf_q_info { |
| 97 | u16 fw_rx_qid; |
| 98 | u16 fw_tx_qid; |
| 99 | u8 fw_cid; |
| 100 | u8 rxq_active; |
| 101 | u8 txq_active; |
| 102 | }; |
| 103 | |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 104 | enum vf_state { |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 105 | VF_FREE = 0, /* VF ready to be acquired holds no resc */ |
| 106 | VF_ACQUIRED, /* VF, acquired, but not initalized */ |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 107 | VF_ENABLED, /* VF, Enabled */ |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 108 | VF_RESET, /* VF, FLR'd, pending cleanup */ |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 109 | VF_STOPPED /* VF, Stopped */ |
| 110 | }; |
| 111 | |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 112 | struct qed_vf_vlan_shadow { |
| 113 | bool used; |
| 114 | u16 vid; |
| 115 | }; |
| 116 | |
| 117 | struct qed_vf_shadow_config { |
| 118 | /* Shadow copy of all guest vlans */ |
| 119 | struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1]; |
| 120 | |
| 121 | u8 inner_vlan_removal; |
| 122 | }; |
| 123 | |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 124 | /* PFs maintain an array of this structure, per VF */ |
| 125 | struct qed_vf_info { |
| 126 | struct qed_iov_vf_mbx vf_mbx; |
| 127 | enum vf_state state; |
| 128 | bool b_init; |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 129 | u8 to_disable; |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 130 | |
| 131 | struct qed_bulletin bulletin; |
| 132 | dma_addr_t vf_bulletin; |
| 133 | |
Yuval Mintz | 1fe614d | 2016-06-05 13:11:11 +0300 | [diff] [blame^] | 134 | /* PF saves a copy of the last VF acquire message */ |
| 135 | struct vfpf_acquire_tlv acquire; |
| 136 | |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 137 | u32 concrete_fid; |
| 138 | u16 opaque_fid; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 139 | u16 mtu; |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 140 | |
| 141 | u8 vport_id; |
| 142 | u8 relative_vf_id; |
| 143 | u8 abs_vf_id; |
| 144 | #define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \ |
| 145 | (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \ |
| 146 | (p_vf)->abs_vf_id) |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 147 | |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 148 | u8 vport_instance; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 149 | u8 num_rxqs; |
| 150 | u8 num_txqs; |
| 151 | |
| 152 | u8 num_sbs; |
| 153 | |
| 154 | u8 num_mac_filters; |
| 155 | u8 num_vlan_filters; |
| 156 | struct qed_vf_q_info vf_queues[QED_MAX_VF_CHAINS_PER_PF]; |
| 157 | u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF]; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 158 | u8 num_active_rxqs; |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 159 | struct qed_public_vf_info p_vf_info; |
Yuval Mintz | 6ddc760 | 2016-05-11 16:36:23 +0300 | [diff] [blame] | 160 | bool spoof_chk; |
| 161 | bool req_spoofchk_val; |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 162 | |
| 163 | /* Stores the configuration requested by VF */ |
| 164 | struct qed_vf_shadow_config shadow_config; |
| 165 | |
| 166 | /* A bitfield using bulletin's valid-map bits, used to indicate |
| 167 | * which of the bulletin board features have been configured. |
| 168 | */ |
| 169 | u64 configured_features; |
| 170 | #define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \ |
| 171 | (1 << VLAN_ADDR_FORCED)) |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | /* This structure is part of qed_hwfn and used only for PFs that have sriov |
| 175 | * capability enabled. |
| 176 | */ |
| 177 | struct qed_pf_iov { |
| 178 | struct qed_vf_info vfs_array[MAX_NUM_VFS]; |
| 179 | u64 pending_events[QED_VF_ARRAY_LENGTH]; |
| 180 | u64 pending_flr[QED_VF_ARRAY_LENGTH]; |
| 181 | |
| 182 | /* Allocate message address continuosuly and split to each VF */ |
| 183 | void *mbx_msg_virt_addr; |
| 184 | dma_addr_t mbx_msg_phys_addr; |
| 185 | u32 mbx_msg_size; |
| 186 | void *mbx_reply_virt_addr; |
| 187 | dma_addr_t mbx_reply_phys_addr; |
| 188 | u32 mbx_reply_size; |
| 189 | void *p_bulletins; |
| 190 | dma_addr_t bulletins_phys; |
| 191 | u32 bulletins_size; |
| 192 | }; |
| 193 | |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 194 | enum qed_iov_wq_flag { |
| 195 | QED_IOV_WQ_MSG_FLAG, |
| 196 | QED_IOV_WQ_SET_UNICAST_FILTER_FLAG, |
| 197 | QED_IOV_WQ_BULLETIN_UPDATE_FLAG, |
| 198 | QED_IOV_WQ_STOP_WQ_FLAG, |
| 199 | QED_IOV_WQ_FLR_FLAG, |
| 200 | }; |
| 201 | |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 202 | #ifdef CONFIG_QED_SRIOV |
| 203 | /** |
| 204 | * @brief - Given a VF index, return index of next [including that] active VF. |
| 205 | * |
| 206 | * @param p_hwfn |
| 207 | * @param rel_vf_id |
| 208 | * |
| 209 | * @return MAX_NUM_VFS in case no further active VFs, otherwise index. |
| 210 | */ |
| 211 | u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id); |
| 212 | |
| 213 | /** |
| 214 | * @brief Read sriov related information and allocated resources |
| 215 | * reads from configuraiton space, shmem, etc. |
| 216 | * |
| 217 | * @param p_hwfn |
| 218 | * |
| 219 | * @return int |
| 220 | */ |
| 221 | int qed_iov_hw_info(struct qed_hwfn *p_hwfn); |
| 222 | |
| 223 | /** |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 224 | * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset |
| 225 | * |
| 226 | * @param p_hwfn |
| 227 | * @param p_iov |
| 228 | * @param type |
| 229 | * @param length |
| 230 | * |
| 231 | * @return pointer to the newly placed tlv |
| 232 | */ |
| 233 | void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length); |
| 234 | |
| 235 | /** |
| 236 | * @brief list the types and lengths of the tlvs on the buffer |
| 237 | * |
| 238 | * @param p_hwfn |
| 239 | * @param tlvs_list |
| 240 | */ |
| 241 | void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list); |
| 242 | |
| 243 | /** |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 244 | * @brief qed_iov_alloc - allocate sriov related resources |
| 245 | * |
| 246 | * @param p_hwfn |
| 247 | * |
| 248 | * @return int |
| 249 | */ |
| 250 | int qed_iov_alloc(struct qed_hwfn *p_hwfn); |
| 251 | |
| 252 | /** |
| 253 | * @brief qed_iov_setup - setup sriov related resources |
| 254 | * |
| 255 | * @param p_hwfn |
| 256 | * @param p_ptt |
| 257 | */ |
| 258 | void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt); |
| 259 | |
| 260 | /** |
| 261 | * @brief qed_iov_free - free sriov related resources |
| 262 | * |
| 263 | * @param p_hwfn |
| 264 | */ |
| 265 | void qed_iov_free(struct qed_hwfn *p_hwfn); |
| 266 | |
| 267 | /** |
| 268 | * @brief free sriov related memory that was allocated during hw_prepare |
| 269 | * |
| 270 | * @param cdev |
| 271 | */ |
| 272 | void qed_iov_free_hw_info(struct qed_dev *cdev); |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 273 | |
| 274 | /** |
| 275 | * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe. |
| 276 | * |
| 277 | * @param p_hwfn |
| 278 | * @param opcode |
| 279 | * @param echo |
| 280 | * @param data |
| 281 | */ |
| 282 | int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn, |
| 283 | u8 opcode, __le16 echo, union event_ring_data *data); |
| 284 | |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 285 | /** |
| 286 | * @brief Mark structs of vfs that have been FLR-ed. |
| 287 | * |
| 288 | * @param p_hwfn |
| 289 | * @param disabled_vfs - bitmask of all VFs on path that were FLRed |
| 290 | * |
| 291 | * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise. |
| 292 | */ |
| 293 | int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs); |
| 294 | |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 295 | /** |
| 296 | * @brief Search extended TLVs in request/reply buffer. |
| 297 | * |
| 298 | * @param p_hwfn |
| 299 | * @param p_tlvs_list - Pointer to tlvs list |
| 300 | * @param req_type - Type of TLV |
| 301 | * |
| 302 | * @return pointer to tlv type if found, otherwise returns NULL. |
| 303 | */ |
| 304 | void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn, |
| 305 | void *p_tlvs_list, u16 req_type); |
| 306 | |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 307 | void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first); |
| 308 | int qed_iov_wq_start(struct qed_dev *cdev); |
| 309 | |
| 310 | void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 311 | void qed_vf_start_iov_wq(struct qed_dev *cdev); |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 312 | int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled); |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 313 | void qed_inform_vf_link_state(struct qed_hwfn *hwfn); |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 314 | #else |
| 315 | static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, |
| 316 | u16 rel_vf_id) |
| 317 | { |
| 318 | return MAX_NUM_VFS; |
| 319 | } |
| 320 | |
| 321 | static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn) |
| 322 | { |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn) |
| 327 | { |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static inline void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 332 | { |
| 333 | } |
| 334 | |
| 335 | static inline void qed_iov_free(struct qed_hwfn *p_hwfn) |
| 336 | { |
| 337 | } |
| 338 | |
| 339 | static inline void qed_iov_free_hw_info(struct qed_dev *cdev) |
| 340 | { |
| 341 | } |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 342 | |
| 343 | static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn, |
| 344 | u8 opcode, |
| 345 | __le16 echo, union event_ring_data *data) |
| 346 | { |
| 347 | return -EINVAL; |
| 348 | } |
| 349 | |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 350 | static inline int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, |
| 351 | u32 *disabled_vfs) |
| 352 | { |
| 353 | return 0; |
| 354 | } |
| 355 | |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 356 | static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first) |
| 357 | { |
| 358 | } |
| 359 | |
| 360 | static inline int qed_iov_wq_start(struct qed_dev *cdev) |
| 361 | { |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | static inline void qed_schedule_iov(struct qed_hwfn *hwfn, |
| 366 | enum qed_iov_wq_flag flag) |
| 367 | { |
| 368 | } |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 369 | |
| 370 | static inline void qed_vf_start_iov_wq(struct qed_dev *cdev) |
| 371 | { |
| 372 | } |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 373 | |
| 374 | static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled) |
| 375 | { |
| 376 | return 0; |
| 377 | } |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 378 | |
| 379 | static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn) |
| 380 | { |
| 381 | } |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 382 | #endif |
| 383 | |
| 384 | #define qed_for_each_vf(_p_hwfn, _i) \ |
| 385 | for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \ |
| 386 | _i < MAX_NUM_VFS; \ |
| 387 | _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1)) |
| 388 | |
| 389 | #endif |