1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /* QLogic qed NIC Driver
3 * Copyright (c) 2015-2017 QLogic Corporation
4 * Copyright (c) 2019-2020 Marvell International Ltd.
9 #include <linux/types.h>
12 #define QED_ETH_VF_NUM_MAC_FILTERS 1
13 #define QED_ETH_VF_NUM_VLAN_FILTERS 2
14 #define QED_VF_ARRAY_LENGTH (3)
16 #ifdef CONFIG_QED_SRIOV
17 #define IS_VF(cdev) ((cdev)->b_is_vf)
18 #define IS_PF(cdev) (!((cdev)->b_is_vf))
19 #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->cdev->p_iov_info))
21 #define IS_VF(cdev) (0)
22 #define IS_PF(cdev) (1)
23 #define IS_PF_SRIOV(p_hwfn) (0)
25 #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
27 #define QED_MAX_VF_CHAINS_PER_PF 16
29 #define QED_ETH_MAX_VF_NUM_VLAN_FILTERS \
30 (MAX_NUM_VFS * QED_ETH_VF_NUM_VLAN_FILTERS)
32 enum qed_iov_vport_update_flag {
33 QED_IOV_VP_UPDATE_ACTIVATE,
34 QED_IOV_VP_UPDATE_VLAN_STRIP,
35 QED_IOV_VP_UPDATE_TX_SWITCH,
36 QED_IOV_VP_UPDATE_MCAST,
37 QED_IOV_VP_UPDATE_ACCEPT_PARAM,
38 QED_IOV_VP_UPDATE_RSS,
39 QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN,
40 QED_IOV_VP_UPDATE_SGE_TPA,
41 QED_IOV_VP_UPDATE_MAX,
44 struct qed_public_vf_info {
45 /* These copies will later be reflected in the bulletin board,
46 * but this copy should be newer.
48 u8 forced_mac[ETH_ALEN];
52 /* IFLA_VF_LINK_STATE_<X> */
55 /* Currently configured Tx rate in MB/sec. 0 if unconfigured */
58 /* Trusted VFs can configure promiscuous mode.
59 * Also store shadow promisc configuration if needed.
61 bool is_trusted_configured;
62 bool is_trusted_request;
68 struct qed_iov_vf_init_params {
71 /* Number of requested Queues; Currently, don't support different
72 * number of Rx/Tx queues.
77 /* Allow the client to choose which qzones to use for Rx/Tx,
78 * and which queue_base to use for Tx queues on a per-queue basis.
79 * Notice values should be relative to the PF resources.
81 u16 req_rx_queue[QED_MAX_VF_CHAINS_PER_PF];
82 u16 req_tx_queue[QED_MAX_VF_CHAINS_PER_PF];
85 /* This struct is part of qed_dev and contains data relevant to all hwfns;
86 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
88 struct qed_hw_sriov_info {
89 int pos; /* capability position */
90 int nres; /* number of resources */
91 u32 cap; /* SR-IOV Capabilities */
92 u16 ctrl; /* SR-IOV Control */
93 u16 total_vfs; /* total VFs associated with the PF */
94 u16 num_vfs; /* number of vfs that have been started */
95 u16 initial_vfs; /* initial VFs associated with the PF */
96 u16 nr_virtfn; /* number of VFs available */
97 u16 offset; /* first VF Routing ID offset */
98 u16 stride; /* following VF stride */
99 u16 vf_device_id; /* VF device id */
100 u32 pgsz; /* page size for BAR alignment */
101 u8 link; /* Function Dependency Link */
106 /* This mailbox is maintained per VF in its PF contains all information
107 * required for sending / receiving a message.
109 struct qed_iov_vf_mbx {
110 union vfpf_tlvs *req_virt;
112 union pfvf_tlvs *reply_virt;
113 dma_addr_t reply_phys;
115 /* Address in VF where a pending message is located */
116 dma_addr_t pending_req;
118 /* Message from VF awaits handling */
123 /* saved VF request header */
124 struct vfpf_first_tlv first_tlv;
127 #define QED_IOV_LEGACY_QID_RX (0)
128 #define QED_IOV_LEGACY_QID_TX (1)
129 #define QED_IOV_QID_INVALID (0xFE)
131 struct qed_vf_queue_cid {
133 struct qed_queue_cid *p_cid;
136 /* Describes a qzone associated with the VF */
137 struct qed_vf_queue {
141 struct qed_vf_queue_cid cids[MAX_QUEUES_PER_QZONE];
145 VF_FREE = 0, /* VF ready to be acquired holds no resc */
146 VF_ACQUIRED, /* VF, acquired, but not initalized */
147 VF_ENABLED, /* VF, Enabled */
148 VF_RESET, /* VF, FLR'd, pending cleanup */
149 VF_STOPPED /* VF, Stopped */
152 struct qed_vf_vlan_shadow {
157 struct qed_vf_shadow_config {
158 /* Shadow copy of all guest vlans */
159 struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1];
161 /* Shadow copy of all configured MACs; Empty if forcing MACs */
162 u8 macs[QED_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
163 u8 inner_vlan_removal;
166 /* PFs maintain an array of this structure, per VF */
168 struct qed_iov_vf_mbx vf_mbx;
174 struct qed_bulletin bulletin;
175 dma_addr_t vf_bulletin;
177 /* PF saves a copy of the last VF acquire message */
178 struct vfpf_acquire_tlv acquire;
187 #define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
188 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
203 struct qed_vf_queue vf_queues[QED_MAX_VF_CHAINS_PER_PF];
204 u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
206 struct qed_public_vf_info p_vf_info;
208 bool req_spoofchk_val;
210 /* Stores the configuration requested by VF */
211 struct qed_vf_shadow_config shadow_config;
213 /* A bitfield using bulletin's valid-map bits, used to indicate
214 * which of the bulletin board features have been configured.
216 u64 configured_features;
217 #define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
218 (1 << VLAN_ADDR_FORCED))
221 /* This structure is part of qed_hwfn and used only for PFs that have sriov
222 * capability enabled.
225 struct qed_vf_info vfs_array[MAX_NUM_VFS];
226 u64 pending_flr[QED_VF_ARRAY_LENGTH];
228 /* Allocate message address continuosuly and split to each VF */
229 void *mbx_msg_virt_addr;
230 dma_addr_t mbx_msg_phys_addr;
232 void *mbx_reply_virt_addr;
233 dma_addr_t mbx_reply_phys_addr;
236 dma_addr_t bulletins_phys;
240 enum qed_iov_wq_flag {
242 QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
243 QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
244 QED_IOV_WQ_STOP_WQ_FLAG,
246 QED_IOV_WQ_TRUST_FLAG,
247 QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
250 extern const struct qed_iov_hv_ops qed_iov_ops_pass;
252 #ifdef CONFIG_QED_SRIOV
254 * @brief Check if given VF ID @vfid is valid
255 * w.r.t. @b_enabled_only value
256 * if b_enabled_only = true - only enabled VF id is valid
257 * else any VF id less than max_vfs is valid
260 * @param rel_vf_id - Relative VF ID
261 * @param b_enabled_only - consider only enabled VF
262 * @param b_non_malicious - true iff we want to validate vf isn't malicious.
264 * @return bool - true for valid VF ID
266 bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
268 bool b_enabled_only, bool b_non_malicious);
271 * @brief - Given a VF index, return index of next [including that] active VF.
276 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
278 u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);
280 void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn,
281 int vfid, u16 vxlan_port, u16 geneve_port);
284 * @brief Read sriov related information and allocated resources
285 * reads from configuration space, shmem, etc.
291 int qed_iov_hw_info(struct qed_hwfn *p_hwfn);
294 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
301 * @return pointer to the newly placed tlv
303 void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);
306 * @brief list the types and lengths of the tlvs on the buffer
311 void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);
314 * @brief qed_iov_alloc - allocate sriov related resources
320 int qed_iov_alloc(struct qed_hwfn *p_hwfn);
323 * @brief qed_iov_setup - setup sriov related resources
327 void qed_iov_setup(struct qed_hwfn *p_hwfn);
330 * @brief qed_iov_free - free sriov related resources
334 void qed_iov_free(struct qed_hwfn *p_hwfn);
337 * @brief free sriov related memory that was allocated during hw_prepare
341 void qed_iov_free_hw_info(struct qed_dev *cdev);
344 * @brief Mark structs of vfs that have been FLR-ed.
347 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
349 * @return true iff one of the PF's vfs got FLRed. false otherwise.
351 bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
354 * @brief Search extended TLVs in request/reply buffer.
357 * @param p_tlvs_list - Pointer to tlvs list
358 * @param req_type - Type of TLV
360 * @return pointer to tlv type if found, otherwise returns NULL.
362 void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
363 void *p_tlvs_list, u16 req_type);
365 void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
366 int qed_iov_wq_start(struct qed_dev *cdev);
368 void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
369 void qed_vf_start_iov_wq(struct qed_dev *cdev);
370 int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
371 void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
374 qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
375 int rel_vf_id, bool b_enabled_only, bool b_non_malicious)
380 static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
387 qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn, int vfid,
388 u16 vxlan_port, u16 geneve_port)
392 static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
397 static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
402 static inline void qed_iov_setup(struct qed_hwfn *p_hwfn)
406 static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
410 static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
414 static inline bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
420 static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
424 static inline int qed_iov_wq_start(struct qed_dev *cdev)
429 static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
430 enum qed_iov_wq_flag flag)
434 static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
438 static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
443 static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
448 #define qed_for_each_vf(_p_hwfn, _i) \
449 for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
451 _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))