qed_sriov.h 12 KB

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