qed_sriov.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. #define QED_IOV_LEGACY_QID_RX (0)
  131. #define QED_IOV_LEGACY_QID_TX (1)
  132. #define QED_IOV_QID_INVALID (0xFE)
  133. struct qed_vf_queue_cid {
  134. bool b_is_tx;
  135. struct qed_queue_cid *p_cid;
  136. };
  137. /* Describes a qzone associated with the VF */
  138. struct qed_vf_queue {
  139. u16 fw_rx_qid;
  140. u16 fw_tx_qid;
  141. struct qed_vf_queue_cid cids[MAX_QUEUES_PER_QZONE];
  142. };
  143. enum vf_state {
  144. VF_FREE = 0, /* VF ready to be acquired holds no resc */
  145. VF_ACQUIRED, /* VF, acquired, but not initalized */
  146. VF_ENABLED, /* VF, Enabled */
  147. VF_RESET, /* VF, FLR'd, pending cleanup */
  148. VF_STOPPED /* VF, Stopped */
  149. };
  150. struct qed_vf_vlan_shadow {
  151. bool used;
  152. u16 vid;
  153. };
  154. struct qed_vf_shadow_config {
  155. /* Shadow copy of all guest vlans */
  156. struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1];
  157. /* Shadow copy of all configured MACs; Empty if forcing MACs */
  158. u8 macs[QED_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
  159. u8 inner_vlan_removal;
  160. };
  161. /* PFs maintain an array of this structure, per VF */
  162. struct qed_vf_info {
  163. struct qed_iov_vf_mbx vf_mbx;
  164. enum vf_state state;
  165. bool b_init;
  166. bool b_malicious;
  167. u8 to_disable;
  168. struct qed_bulletin bulletin;
  169. dma_addr_t vf_bulletin;
  170. /* PF saves a copy of the last VF acquire message */
  171. struct vfpf_acquire_tlv acquire;
  172. u32 concrete_fid;
  173. u16 opaque_fid;
  174. u16 mtu;
  175. u8 vport_id;
  176. u8 relative_vf_id;
  177. u8 abs_vf_id;
  178. #define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
  179. (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
  180. (p_vf)->abs_vf_id)
  181. u8 vport_instance;
  182. u8 num_rxqs;
  183. u8 num_txqs;
  184. u16 rx_coal;
  185. u16 tx_coal;
  186. u8 num_sbs;
  187. u8 num_mac_filters;
  188. u8 num_vlan_filters;
  189. struct qed_vf_queue vf_queues[QED_MAX_VF_CHAINS_PER_PF];
  190. u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
  191. u8 num_active_rxqs;
  192. struct qed_public_vf_info p_vf_info;
  193. bool spoof_chk;
  194. bool req_spoofchk_val;
  195. /* Stores the configuration requested by VF */
  196. struct qed_vf_shadow_config shadow_config;
  197. /* A bitfield using bulletin's valid-map bits, used to indicate
  198. * which of the bulletin board features have been configured.
  199. */
  200. u64 configured_features;
  201. #define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
  202. (1 << VLAN_ADDR_FORCED))
  203. };
  204. /* This structure is part of qed_hwfn and used only for PFs that have sriov
  205. * capability enabled.
  206. */
  207. struct qed_pf_iov {
  208. struct qed_vf_info vfs_array[MAX_NUM_VFS];
  209. u64 pending_flr[QED_VF_ARRAY_LENGTH];
  210. /* Allocate message address continuosuly and split to each VF */
  211. void *mbx_msg_virt_addr;
  212. dma_addr_t mbx_msg_phys_addr;
  213. u32 mbx_msg_size;
  214. void *mbx_reply_virt_addr;
  215. dma_addr_t mbx_reply_phys_addr;
  216. u32 mbx_reply_size;
  217. void *p_bulletins;
  218. dma_addr_t bulletins_phys;
  219. u32 bulletins_size;
  220. };
  221. enum qed_iov_wq_flag {
  222. QED_IOV_WQ_MSG_FLAG,
  223. QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
  224. QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
  225. QED_IOV_WQ_STOP_WQ_FLAG,
  226. QED_IOV_WQ_FLR_FLAG,
  227. QED_IOV_WQ_TRUST_FLAG,
  228. QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
  229. };
  230. #ifdef CONFIG_QED_SRIOV
  231. /**
  232. * @brief Check if given VF ID @vfid is valid
  233. * w.r.t. @b_enabled_only value
  234. * if b_enabled_only = true - only enabled VF id is valid
  235. * else any VF id less than max_vfs is valid
  236. *
  237. * @param p_hwfn
  238. * @param rel_vf_id - Relative VF ID
  239. * @param b_enabled_only - consider only enabled VF
  240. * @param b_non_malicious - true iff we want to validate vf isn't malicious.
  241. *
  242. * @return bool - true for valid VF ID
  243. */
  244. bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
  245. int rel_vf_id,
  246. bool b_enabled_only, bool b_non_malicious);
  247. /**
  248. * @brief - Given a VF index, return index of next [including that] active VF.
  249. *
  250. * @param p_hwfn
  251. * @param rel_vf_id
  252. *
  253. * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
  254. */
  255. u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);
  256. void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn,
  257. int vfid, u16 vxlan_port, u16 geneve_port);
  258. /**
  259. * @brief Read sriov related information and allocated resources
  260. * reads from configuraiton space, shmem, etc.
  261. *
  262. * @param p_hwfn
  263. *
  264. * @return int
  265. */
  266. int qed_iov_hw_info(struct qed_hwfn *p_hwfn);
  267. /**
  268. * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
  269. *
  270. * @param p_hwfn
  271. * @param p_iov
  272. * @param type
  273. * @param length
  274. *
  275. * @return pointer to the newly placed tlv
  276. */
  277. void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);
  278. /**
  279. * @brief list the types and lengths of the tlvs on the buffer
  280. *
  281. * @param p_hwfn
  282. * @param tlvs_list
  283. */
  284. void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);
  285. /**
  286. * @brief qed_iov_alloc - allocate sriov related resources
  287. *
  288. * @param p_hwfn
  289. *
  290. * @return int
  291. */
  292. int qed_iov_alloc(struct qed_hwfn *p_hwfn);
  293. /**
  294. * @brief qed_iov_setup - setup sriov related resources
  295. *
  296. * @param p_hwfn
  297. */
  298. void qed_iov_setup(struct qed_hwfn *p_hwfn);
  299. /**
  300. * @brief qed_iov_free - free sriov related resources
  301. *
  302. * @param p_hwfn
  303. */
  304. void qed_iov_free(struct qed_hwfn *p_hwfn);
  305. /**
  306. * @brief free sriov related memory that was allocated during hw_prepare
  307. *
  308. * @param cdev
  309. */
  310. void qed_iov_free_hw_info(struct qed_dev *cdev);
  311. /**
  312. * @brief Mark structs of vfs that have been FLR-ed.
  313. *
  314. * @param p_hwfn
  315. * @param disabled_vfs - bitmask of all VFs on path that were FLRed
  316. *
  317. * @return true iff one of the PF's vfs got FLRed. false otherwise.
  318. */
  319. bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
  320. /**
  321. * @brief Search extended TLVs in request/reply buffer.
  322. *
  323. * @param p_hwfn
  324. * @param p_tlvs_list - Pointer to tlvs list
  325. * @param req_type - Type of TLV
  326. *
  327. * @return pointer to tlv type if found, otherwise returns NULL.
  328. */
  329. void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
  330. void *p_tlvs_list, u16 req_type);
  331. void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
  332. int qed_iov_wq_start(struct qed_dev *cdev);
  333. void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
  334. void qed_vf_start_iov_wq(struct qed_dev *cdev);
  335. int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
  336. void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
  337. #else
  338. static inline bool
  339. qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
  340. int rel_vf_id, bool b_enabled_only, bool b_non_malicious)
  341. {
  342. return false;
  343. }
  344. static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
  345. u16 rel_vf_id)
  346. {
  347. return MAX_NUM_VFS;
  348. }
  349. static inline void
  350. qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn, int vfid,
  351. u16 vxlan_port, u16 geneve_port)
  352. {
  353. }
  354. static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
  355. {
  356. return 0;
  357. }
  358. static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
  359. {
  360. return 0;
  361. }
  362. static inline void qed_iov_setup(struct qed_hwfn *p_hwfn)
  363. {
  364. }
  365. static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
  366. {
  367. }
  368. static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
  369. {
  370. }
  371. static inline bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
  372. u32 *disabled_vfs)
  373. {
  374. return false;
  375. }
  376. static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
  377. {
  378. }
  379. static inline int qed_iov_wq_start(struct qed_dev *cdev)
  380. {
  381. return 0;
  382. }
  383. static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
  384. enum qed_iov_wq_flag flag)
  385. {
  386. }
  387. static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
  388. {
  389. }
  390. static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
  391. {
  392. return 0;
  393. }
  394. static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
  395. {
  396. }
  397. #endif
  398. #define qed_for_each_vf(_p_hwfn, _i) \
  399. for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
  400. _i < MAX_NUM_VFS; \
  401. _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))
  402. #endif