qed_sriov.h 9.9 KB

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