qed_sriov.h 9.4 KB

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