1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
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
11 #include <linux/types.h>
13 #define QED_VF_ARRAY_LENGTH (3)
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))
20 #define IS_PF_SRIOV(p_hwfn) (0)
22 #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
24 #define QED_MAX_VF_CHAINS_PER_PF 16
25 #define QED_ETH_VF_NUM_VLAN_FILTERS 2
27 struct qed_public_vf_info
{
28 /* These copies will later be reflected in the bulletin board,
29 * but this copy should be newer.
34 /* This struct is part of qed_dev and contains data relevant to all hwfns;
35 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
37 struct qed_hw_sriov_info
{
38 int pos
; /* capability position */
39 int nres
; /* number of resources */
40 u32 cap
; /* SR-IOV Capabilities */
41 u16 ctrl
; /* SR-IOV Control */
42 u16 total_vfs
; /* total VFs associated with the PF */
43 u16 num_vfs
; /* number of vfs that have been started */
44 u16 initial_vfs
; /* initial VFs associated with the PF */
45 u16 nr_virtfn
; /* number of VFs available */
46 u16 offset
; /* first VF Routing ID offset */
47 u16 stride
; /* following VF stride */
48 u16 vf_device_id
; /* VF device id */
49 u32 pgsz
; /* page size for BAR alignment */
50 u8 link
; /* Function Dependency Link */
55 /* This mailbox is maintained per VF in its PF contains all information
56 * required for sending / receiving a message.
58 struct qed_iov_vf_mbx
{
59 union vfpf_tlvs
*req_virt
;
61 union pfvf_tlvs
*reply_virt
;
62 dma_addr_t reply_phys
;
64 /* Address in VF where a pending message is located */
65 dma_addr_t pending_req
;
69 /* saved VF request header */
70 struct vfpf_first_tlv first_tlv
;
73 struct qed_vf_q_info
{
82 VF_FREE
= 0, /* VF ready to be acquired holds no resc */
83 VF_ACQUIRED
, /* VF, acquired, but not initalized */
84 VF_RESET
, /* VF, FLR'd, pending cleanup */
85 VF_STOPPED
/* VF, Stopped */
88 /* PFs maintain an array of this structure, per VF */
90 struct qed_iov_vf_mbx vf_mbx
;
95 struct qed_bulletin bulletin
;
96 dma_addr_t vf_bulletin
;
104 #define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
105 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
115 struct qed_vf_q_info vf_queues
[QED_MAX_VF_CHAINS_PER_PF
];
116 u16 igu_sbs
[QED_MAX_VF_CHAINS_PER_PF
];
117 struct qed_public_vf_info p_vf_info
;
120 /* This structure is part of qed_hwfn and used only for PFs that have sriov
121 * capability enabled.
124 struct qed_vf_info vfs_array
[MAX_NUM_VFS
];
125 u64 pending_events
[QED_VF_ARRAY_LENGTH
];
126 u64 pending_flr
[QED_VF_ARRAY_LENGTH
];
128 /* Allocate message address continuosuly and split to each VF */
129 void *mbx_msg_virt_addr
;
130 dma_addr_t mbx_msg_phys_addr
;
132 void *mbx_reply_virt_addr
;
133 dma_addr_t mbx_reply_phys_addr
;
136 dma_addr_t bulletins_phys
;
140 enum qed_iov_wq_flag
{
142 QED_IOV_WQ_SET_UNICAST_FILTER_FLAG
,
143 QED_IOV_WQ_BULLETIN_UPDATE_FLAG
,
144 QED_IOV_WQ_STOP_WQ_FLAG
,
148 #ifdef CONFIG_QED_SRIOV
150 * @brief - Given a VF index, return index of next [including that] active VF.
155 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
157 u16
qed_iov_get_next_active_vf(struct qed_hwfn
*p_hwfn
, u16 rel_vf_id
);
160 * @brief Read sriov related information and allocated resources
161 * reads from configuraiton space, shmem, etc.
167 int qed_iov_hw_info(struct qed_hwfn
*p_hwfn
);
170 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
177 * @return pointer to the newly placed tlv
179 void *qed_add_tlv(struct qed_hwfn
*p_hwfn
, u8
**offset
, u16 type
, u16 length
);
182 * @brief list the types and lengths of the tlvs on the buffer
187 void qed_dp_tlv_list(struct qed_hwfn
*p_hwfn
, void *tlvs_list
);
190 * @brief qed_iov_alloc - allocate sriov related resources
196 int qed_iov_alloc(struct qed_hwfn
*p_hwfn
);
199 * @brief qed_iov_setup - setup sriov related resources
204 void qed_iov_setup(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
);
207 * @brief qed_iov_free - free sriov related resources
211 void qed_iov_free(struct qed_hwfn
*p_hwfn
);
214 * @brief free sriov related memory that was allocated during hw_prepare
218 void qed_iov_free_hw_info(struct qed_dev
*cdev
);
221 * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe.
228 int qed_sriov_eqe_event(struct qed_hwfn
*p_hwfn
,
229 u8 opcode
, __le16 echo
, union event_ring_data
*data
);
232 * @brief Mark structs of vfs that have been FLR-ed.
235 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
237 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
239 int qed_iov_mark_vf_flr(struct qed_hwfn
*p_hwfn
, u32
*disabled_vfs
);
241 void qed_iov_wq_stop(struct qed_dev
*cdev
, bool schedule_first
);
242 int qed_iov_wq_start(struct qed_dev
*cdev
);
244 void qed_schedule_iov(struct qed_hwfn
*hwfn
, enum qed_iov_wq_flag flag
);
245 void qed_vf_start_iov_wq(struct qed_dev
*cdev
);
246 int qed_sriov_disable(struct qed_dev
*cdev
, bool pci_enabled
);
248 static inline u16
qed_iov_get_next_active_vf(struct qed_hwfn
*p_hwfn
,
254 static inline int qed_iov_hw_info(struct qed_hwfn
*p_hwfn
)
259 static inline int qed_iov_alloc(struct qed_hwfn
*p_hwfn
)
264 static inline void qed_iov_setup(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
)
268 static inline void qed_iov_free(struct qed_hwfn
*p_hwfn
)
272 static inline void qed_iov_free_hw_info(struct qed_dev
*cdev
)
276 static inline int qed_sriov_eqe_event(struct qed_hwfn
*p_hwfn
,
278 __le16 echo
, union event_ring_data
*data
)
283 static inline int qed_iov_mark_vf_flr(struct qed_hwfn
*p_hwfn
,
289 static inline void qed_iov_wq_stop(struct qed_dev
*cdev
, bool schedule_first
)
293 static inline int qed_iov_wq_start(struct qed_dev
*cdev
)
298 static inline void qed_schedule_iov(struct qed_hwfn
*hwfn
,
299 enum qed_iov_wq_flag flag
)
303 static inline void qed_vf_start_iov_wq(struct qed_dev
*cdev
)
307 static inline int qed_sriov_disable(struct qed_dev
*cdev
, bool pci_enabled
)
313 #define qed_for_each_vf(_p_hwfn, _i) \
314 for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
316 _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))