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