ice_vf_lib.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2018-2021, Intel Corporation. */
  3. #ifndef _ICE_VF_LIB_H_
  4. #define _ICE_VF_LIB_H_
  5. #include <linux/types.h>
  6. #include <linux/hashtable.h>
  7. #include <linux/bitmap.h>
  8. #include <linux/mutex.h>
  9. #include <linux/pci.h>
  10. #include <net/devlink.h>
  11. #include <linux/avf/virtchnl.h>
  12. #include "ice_type.h"
  13. #include "ice_flow.h"
  14. #include "ice_virtchnl_fdir.h"
  15. #include "ice_vsi_vlan_ops.h"
  16. #define ICE_MAX_SRIOV_VFS 256
  17. /* VF resource constraints */
  18. #define ICE_MAX_RSS_QS_PER_VF 16
  19. struct ice_pf;
  20. struct ice_vf;
  21. struct ice_virtchnl_ops;
  22. /* VF capabilities */
  23. enum ice_virtchnl_cap {
  24. ICE_VIRTCHNL_VF_CAP_PRIVILEGE = 0,
  25. };
  26. /* Specific VF states */
  27. enum ice_vf_states {
  28. ICE_VF_STATE_INIT = 0, /* PF is initializing VF */
  29. ICE_VF_STATE_ACTIVE, /* VF resources are allocated for use */
  30. ICE_VF_STATE_QS_ENA, /* VF queue(s) enabled */
  31. ICE_VF_STATE_DIS,
  32. ICE_VF_STATE_MC_PROMISC,
  33. ICE_VF_STATE_UC_PROMISC,
  34. ICE_VF_STATES_NBITS
  35. };
  36. struct ice_time_mac {
  37. unsigned long time_modified;
  38. u8 addr[ETH_ALEN];
  39. };
  40. /* VF MDD events print structure */
  41. struct ice_mdd_vf_events {
  42. u16 count; /* total count of Rx|Tx events */
  43. /* count number of the last printed event */
  44. u16 last_printed;
  45. };
  46. /* Structure to store fdir fv entry */
  47. struct ice_fdir_prof_info {
  48. struct ice_parser_profile prof;
  49. u64 fdir_active_cnt;
  50. };
  51. /* VF operations */
  52. struct ice_vf_ops {
  53. enum ice_disq_rst_src reset_type;
  54. void (*free)(struct ice_vf *vf);
  55. void (*clear_reset_state)(struct ice_vf *vf);
  56. void (*clear_mbx_register)(struct ice_vf *vf);
  57. void (*trigger_reset_register)(struct ice_vf *vf, bool is_vflr);
  58. bool (*poll_reset_status)(struct ice_vf *vf);
  59. void (*clear_reset_trigger)(struct ice_vf *vf);
  60. void (*irq_close)(struct ice_vf *vf);
  61. void (*post_vsi_rebuild)(struct ice_vf *vf);
  62. };
  63. /* Virtchnl/SR-IOV config info */
  64. struct ice_vfs {
  65. DECLARE_HASHTABLE(table, 8); /* table of VF entries */
  66. struct mutex table_lock; /* Lock for protecting the hash table */
  67. u16 num_supported; /* max supported VFs on this PF */
  68. u16 num_qps_per; /* number of queue pairs per VF */
  69. u16 num_msix_per; /* default MSI-X vectors per VF */
  70. unsigned long last_printed_mdd_jiffies; /* MDD message rate limit */
  71. };
  72. /* VF information structure */
  73. struct ice_vf {
  74. struct hlist_node entry;
  75. struct rcu_head rcu;
  76. struct kref refcnt;
  77. struct ice_pf *pf;
  78. struct pci_dev *vfdev;
  79. /* Used during virtchnl message handling and NDO ops against the VF
  80. * that will trigger a VFR
  81. */
  82. struct mutex cfg_lock;
  83. u16 vf_id; /* VF ID in the PF space */
  84. u16 lan_vsi_idx; /* index into PF struct */
  85. u16 ctrl_vsi_idx;
  86. struct ice_vf_fdir fdir;
  87. struct ice_fdir_prof_info fdir_prof_info[ICE_MAX_PTGS];
  88. /* first vector index of this VF in the PF space */
  89. int first_vector_idx;
  90. struct ice_sw *vf_sw_id; /* switch ID the VF VSIs connect to */
  91. struct virtchnl_version_info vf_ver;
  92. u32 driver_caps; /* reported by VF driver */
  93. u8 dev_lan_addr[ETH_ALEN];
  94. u8 hw_lan_addr[ETH_ALEN];
  95. struct ice_time_mac legacy_last_added_umac;
  96. DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
  97. DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
  98. struct ice_vlan port_vlan_info; /* Port VLAN ID, QoS, and TPID */
  99. struct virtchnl_vlan_caps vlan_v2_caps;
  100. struct ice_mbx_vf_info mbx_info;
  101. u8 pf_set_mac:1; /* VF MAC address set by VMM admin */
  102. u8 trusted:1;
  103. u8 spoofchk:1;
  104. u8 link_forced:1;
  105. u8 link_up:1; /* only valid if VF link is forced */
  106. unsigned int min_tx_rate; /* Minimum Tx bandwidth limit in Mbps */
  107. unsigned int max_tx_rate; /* Maximum Tx bandwidth limit in Mbps */
  108. DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
  109. unsigned long vf_caps; /* VF's adv. capabilities */
  110. u8 num_req_qs; /* num of queue pairs requested by VF */
  111. u16 num_mac;
  112. u16 num_vf_qs; /* num of queue configured per VF */
  113. u8 vlan_strip_ena; /* Outer and Inner VLAN strip enable */
  114. #define ICE_INNER_VLAN_STRIP_ENA BIT(0)
  115. #define ICE_OUTER_VLAN_STRIP_ENA BIT(1)
  116. struct ice_mdd_vf_events mdd_rx_events;
  117. struct ice_mdd_vf_events mdd_tx_events;
  118. DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
  119. unsigned long repr_id;
  120. const struct ice_virtchnl_ops *virtchnl_ops;
  121. const struct ice_vf_ops *vf_ops;
  122. /* devlink port data */
  123. struct devlink_port devlink_port;
  124. u16 num_msix; /* num of MSI-X configured on this VF */
  125. };
  126. /* Flags for controlling behavior of ice_reset_vf */
  127. enum ice_vf_reset_flags {
  128. ICE_VF_RESET_VFLR = BIT(0), /* Indicate a VFLR reset */
  129. ICE_VF_RESET_NOTIFY = BIT(1), /* Notify VF prior to reset */
  130. ICE_VF_RESET_LOCK = BIT(2), /* Acquire the VF cfg_lock */
  131. };
  132. static inline u16 ice_vf_get_port_vlan_id(struct ice_vf *vf)
  133. {
  134. return vf->port_vlan_info.vid;
  135. }
  136. static inline u8 ice_vf_get_port_vlan_prio(struct ice_vf *vf)
  137. {
  138. return vf->port_vlan_info.prio;
  139. }
  140. static inline bool ice_vf_is_port_vlan_ena(struct ice_vf *vf)
  141. {
  142. return (ice_vf_get_port_vlan_id(vf) || ice_vf_get_port_vlan_prio(vf));
  143. }
  144. static inline u16 ice_vf_get_port_vlan_tpid(struct ice_vf *vf)
  145. {
  146. return vf->port_vlan_info.tpid;
  147. }
  148. /* VF Hash Table access functions
  149. *
  150. * These functions provide abstraction for interacting with the VF hash table.
  151. * In general, direct access to the hash table should be avoided outside of
  152. * these functions where possible.
  153. *
  154. * The VF entries in the hash table are protected by reference counting to
  155. * track lifetime of accesses from the table. The ice_get_vf_by_id() function
  156. * obtains a reference to the VF structure which must be dropped by using
  157. * ice_put_vf().
  158. */
  159. /**
  160. * ice_for_each_vf - Iterate over each VF entry
  161. * @pf: pointer to the PF private structure
  162. * @bkt: bucket index used for iteration
  163. * @vf: pointer to the VF entry currently being processed in the loop
  164. *
  165. * The bkt variable is an unsigned integer iterator used to traverse the VF
  166. * entries. It is *not* guaranteed to be the VF's vf_id. Do not assume it is.
  167. * Use vf->vf_id to get the id number if needed.
  168. *
  169. * The caller is expected to be under the table_lock mutex for the entire
  170. * loop. Use this iterator if your loop is long or if it might sleep.
  171. */
  172. #define ice_for_each_vf(pf, bkt, vf) \
  173. hash_for_each((pf)->vfs.table, (bkt), (vf), entry)
  174. /**
  175. * ice_for_each_vf_rcu - Iterate over each VF entry protected by RCU
  176. * @pf: pointer to the PF private structure
  177. * @bkt: bucket index used for iteration
  178. * @vf: pointer to the VF entry currently being processed in the loop
  179. *
  180. * The bkt variable is an unsigned integer iterator used to traverse the VF
  181. * entries. It is *not* guaranteed to be the VF's vf_id. Do not assume it is.
  182. * Use vf->vf_id to get the id number if needed.
  183. *
  184. * The caller is expected to be under rcu_read_lock() for the entire loop.
  185. * Only use this iterator if your loop is short and you can guarantee it does
  186. * not sleep.
  187. */
  188. #define ice_for_each_vf_rcu(pf, bkt, vf) \
  189. hash_for_each_rcu((pf)->vfs.table, (bkt), (vf), entry)
  190. #ifdef CONFIG_PCI_IOV
  191. struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id);
  192. void ice_put_vf(struct ice_vf *vf);
  193. bool ice_has_vfs(struct ice_pf *pf);
  194. u16 ice_get_num_vfs(struct ice_pf *pf);
  195. struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf);
  196. bool ice_is_vf_disabled(struct ice_vf *vf);
  197. int ice_check_vf_ready_for_cfg(struct ice_vf *vf);
  198. void ice_set_vf_state_dis(struct ice_vf *vf);
  199. bool ice_is_any_vf_in_unicast_promisc(struct ice_pf *pf);
  200. void
  201. ice_vf_get_promisc_masks(struct ice_vf *vf, struct ice_vsi *vsi,
  202. u8 *ucast_m, u8 *mcast_m);
  203. int
  204. ice_vf_set_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m);
  205. int
  206. ice_vf_clear_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m);
  207. int ice_reset_vf(struct ice_vf *vf, u32 flags);
  208. void ice_reset_all_vfs(struct ice_pf *pf);
  209. struct ice_vsi *ice_get_vf_ctrl_vsi(struct ice_pf *pf, struct ice_vsi *vsi);
  210. #else /* CONFIG_PCI_IOV */
  211. static inline struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id)
  212. {
  213. return NULL;
  214. }
  215. static inline void ice_put_vf(struct ice_vf *vf)
  216. {
  217. }
  218. static inline bool ice_has_vfs(struct ice_pf *pf)
  219. {
  220. return false;
  221. }
  222. static inline u16 ice_get_num_vfs(struct ice_pf *pf)
  223. {
  224. return 0;
  225. }
  226. static inline struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf)
  227. {
  228. return NULL;
  229. }
  230. static inline bool ice_is_vf_disabled(struct ice_vf *vf)
  231. {
  232. return true;
  233. }
  234. static inline int ice_check_vf_ready_for_cfg(struct ice_vf *vf)
  235. {
  236. return -EOPNOTSUPP;
  237. }
  238. static inline void ice_set_vf_state_dis(struct ice_vf *vf)
  239. {
  240. }
  241. static inline bool ice_is_any_vf_in_unicast_promisc(struct ice_pf *pf)
  242. {
  243. return false;
  244. }
  245. static inline int
  246. ice_vf_set_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m)
  247. {
  248. return -EOPNOTSUPP;
  249. }
  250. static inline int
  251. ice_vf_clear_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m)
  252. {
  253. return -EOPNOTSUPP;
  254. }
  255. static inline int ice_reset_vf(struct ice_vf *vf, u32 flags)
  256. {
  257. return 0;
  258. }
  259. static inline void ice_reset_all_vfs(struct ice_pf *pf)
  260. {
  261. }
  262. static inline struct ice_vsi *
  263. ice_get_vf_ctrl_vsi(struct ice_pf *pf, struct ice_vsi *vsi)
  264. {
  265. return NULL;
  266. }
  267. #endif /* !CONFIG_PCI_IOV */
  268. #endif /* _ICE_VF_LIB_H_ */