i40e.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2013 - 2021 Intel Corporation. */
  3. #ifndef _I40E_H_
  4. #define _I40E_H_
  5. #include <linux/linkmode.h>
  6. #include <linux/pci.h>
  7. #include <linux/ptp_clock_kernel.h>
  8. #include <linux/types.h>
  9. #include <linux/avf/virtchnl.h>
  10. #include <linux/net/intel/i40e_client.h>
  11. #include <net/devlink.h>
  12. #include <net/pkt_cls.h>
  13. #include <net/udp_tunnel.h>
  14. #include "i40e_dcb.h"
  15. #include "i40e_debug.h"
  16. #include "i40e_devlink.h"
  17. #include "i40e_io.h"
  18. #include "i40e_prototype.h"
  19. #include "i40e_register.h"
  20. #include "i40e_txrx.h"
  21. /* Useful i40e defaults */
  22. #define I40E_MAX_VEB 16
  23. #define I40E_MAX_NUM_DESCRIPTORS 4096
  24. #define I40E_MAX_NUM_DESCRIPTORS_XL710 8160
  25. #define I40E_MAX_CSR_SPACE (4 * 1024 * 1024 - 64 * 1024)
  26. #define I40E_DEFAULT_NUM_DESCRIPTORS 512
  27. #define I40E_REQ_DESCRIPTOR_MULTIPLE 32
  28. #define I40E_MIN_NUM_DESCRIPTORS 64
  29. #define I40E_MIN_MSIX 2
  30. #define I40E_DEFAULT_NUM_VMDQ_VSI 8 /* max 256 VSIs */
  31. #define I40E_MIN_VSI_ALLOC 83 /* LAN, ATR, FCOE, 64 VF */
  32. /* max 16 qps */
  33. #define i40e_default_queues_per_vmdq(pf) \
  34. (test_bit(I40E_HW_CAP_RSS_AQ, (pf)->hw.caps) ? 4 : 1)
  35. #define I40E_DEFAULT_QUEUES_PER_VF 4
  36. #define I40E_MAX_VF_QUEUES 16
  37. #define i40e_pf_get_max_q_per_tc(pf) \
  38. (test_bit(I40E_HW_CAP_128_QP_RSS, (pf)->hw.caps) ? 128 : 64)
  39. #define I40E_FDIR_RING_COUNT 32
  40. #define I40E_MAX_AQ_BUF_SIZE 4096
  41. #define I40E_AQ_LEN 256
  42. #define I40E_MIN_ARQ_LEN 1
  43. #define I40E_MIN_ASQ_LEN 2
  44. #define I40E_AQ_WORK_LIMIT 66 /* max number of VFs + a little */
  45. #define I40E_MAX_USER_PRIORITY 8
  46. #define I40E_DEFAULT_TRAFFIC_CLASS BIT(0)
  47. #define I40E_QUEUE_WAIT_RETRY_LIMIT 10
  48. #define I40E_INT_NAME_STR_LEN (IFNAMSIZ + 16)
  49. #define I40E_PHY_DEBUG_ALL \
  50. (I40E_AQ_PHY_DEBUG_DISABLE_LINK_FW | \
  51. I40E_AQ_PHY_DEBUG_DISABLE_ALL_LINK_FW)
  52. #define I40E_OEM_EETRACK_ID 0xffffffff
  53. #define I40E_NVM_VERSION_LO_MASK GENMASK(7, 0)
  54. #define I40E_NVM_VERSION_HI_MASK GENMASK(15, 12)
  55. #define I40E_OEM_VER_BUILD_MASK GENMASK(23, 8)
  56. #define I40E_OEM_VER_PATCH_MASK GENMASK(7, 0)
  57. #define I40E_OEM_VER_MASK GENMASK(31, 24)
  58. #define I40E_OEM_GEN_MASK GENMASK(31, 24)
  59. #define I40E_OEM_SNAP_MASK GENMASK(23, 16)
  60. #define I40E_OEM_RELEASE_MASK GENMASK(15, 0)
  61. #define I40E_RX_DESC(R, i) \
  62. (&(((union i40e_rx_desc *)((R)->desc))[i]))
  63. #define I40E_TX_DESC(R, i) \
  64. (&(((struct i40e_tx_desc *)((R)->desc))[i]))
  65. #define I40E_TX_CTXTDESC(R, i) \
  66. (&(((struct i40e_tx_context_desc *)((R)->desc))[i]))
  67. #define I40E_TX_FDIRDESC(R, i) \
  68. (&(((struct i40e_filter_program_desc *)((R)->desc))[i]))
  69. /* BW rate limiting */
  70. #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
  71. #define I40E_BW_MBPS_DIVISOR 125000 /* rate / (1000000 / 8) Mbps */
  72. #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* accumulate 4 credits max */
  73. /* driver state flags */
  74. enum i40e_state {
  75. __I40E_TESTING,
  76. __I40E_CONFIG_BUSY,
  77. __I40E_CONFIG_DONE,
  78. __I40E_DOWN,
  79. __I40E_SERVICE_SCHED,
  80. __I40E_ADMINQ_EVENT_PENDING,
  81. __I40E_MDD_EVENT_PENDING,
  82. __I40E_VFLR_EVENT_PENDING,
  83. __I40E_RESET_RECOVERY_PENDING,
  84. __I40E_TIMEOUT_RECOVERY_PENDING,
  85. __I40E_MISC_IRQ_REQUESTED,
  86. __I40E_RESET_INTR_RECEIVED,
  87. __I40E_REINIT_REQUESTED,
  88. __I40E_PF_RESET_REQUESTED,
  89. __I40E_PF_RESET_AND_REBUILD_REQUESTED,
  90. __I40E_CORE_RESET_REQUESTED,
  91. __I40E_GLOBAL_RESET_REQUESTED,
  92. __I40E_EMP_RESET_INTR_RECEIVED,
  93. __I40E_SUSPENDED,
  94. __I40E_PTP_TX_IN_PROGRESS,
  95. __I40E_BAD_EEPROM,
  96. __I40E_DOWN_REQUESTED,
  97. __I40E_FD_FLUSH_REQUESTED,
  98. __I40E_FD_ATR_AUTO_DISABLED,
  99. __I40E_FD_SB_AUTO_DISABLED,
  100. __I40E_RESET_FAILED,
  101. __I40E_PORT_SUSPENDED,
  102. __I40E_VF_DISABLE,
  103. __I40E_MACVLAN_SYNC_PENDING,
  104. __I40E_TEMP_LINK_POLLING,
  105. __I40E_CLIENT_SERVICE_REQUESTED,
  106. __I40E_CLIENT_L2_CHANGE,
  107. __I40E_CLIENT_RESET,
  108. __I40E_VIRTCHNL_OP_PENDING,
  109. __I40E_RECOVERY_MODE,
  110. __I40E_VF_RESETS_DISABLED, /* disable resets during i40e_remove */
  111. __I40E_IN_REMOVE,
  112. __I40E_VFS_RELEASING,
  113. /* This must be last as it determines the size of the BITMAP */
  114. __I40E_STATE_SIZE__,
  115. };
  116. #define I40E_PF_RESET_FLAG BIT_ULL(__I40E_PF_RESET_REQUESTED)
  117. #define I40E_PF_RESET_AND_REBUILD_FLAG \
  118. BIT_ULL(__I40E_PF_RESET_AND_REBUILD_REQUESTED)
  119. /* VSI state flags */
  120. enum i40e_vsi_state {
  121. __I40E_VSI_DOWN,
  122. __I40E_VSI_NEEDS_RESTART,
  123. __I40E_VSI_SYNCING_FILTERS,
  124. __I40E_VSI_OVERFLOW_PROMISC,
  125. __I40E_VSI_REINIT_REQUESTED,
  126. __I40E_VSI_DOWN_REQUESTED,
  127. __I40E_VSI_RELEASING,
  128. /* This must be last as it determines the size of the BITMAP */
  129. __I40E_VSI_STATE_SIZE__,
  130. };
  131. enum i40e_pf_flags {
  132. I40E_FLAG_MSI_ENA,
  133. I40E_FLAG_MSIX_ENA,
  134. I40E_FLAG_RSS_ENA,
  135. I40E_FLAG_VMDQ_ENA,
  136. I40E_FLAG_SRIOV_ENA,
  137. I40E_FLAG_DCB_CAPABLE,
  138. I40E_FLAG_DCB_ENA,
  139. I40E_FLAG_FD_SB_ENA,
  140. I40E_FLAG_FD_ATR_ENA,
  141. I40E_FLAG_MFP_ENA,
  142. I40E_FLAG_HW_ATR_EVICT_ENA,
  143. I40E_FLAG_VEB_MODE_ENA,
  144. I40E_FLAG_VEB_STATS_ENA,
  145. I40E_FLAG_LINK_POLLING_ENA,
  146. I40E_FLAG_TRUE_PROMISC_ENA,
  147. I40E_FLAG_LEGACY_RX_ENA,
  148. I40E_FLAG_PTP_ENA,
  149. I40E_FLAG_IWARP_ENA,
  150. I40E_FLAG_LINK_DOWN_ON_CLOSE_ENA,
  151. I40E_FLAG_SOURCE_PRUNING_DIS,
  152. I40E_FLAG_TC_MQPRIO_ENA,
  153. I40E_FLAG_FD_SB_INACTIVE,
  154. I40E_FLAG_FD_SB_TO_CLOUD_FILTER,
  155. I40E_FLAG_FW_LLDP_DIS,
  156. I40E_FLAG_RS_FEC,
  157. I40E_FLAG_BASE_R_FEC,
  158. /* TOTAL_PORT_SHUTDOWN_ENA
  159. * Allows to physically disable the link on the NIC's port.
  160. * If enabled, (after link down request from the OS)
  161. * no link, traffic or led activity is possible on that port.
  162. *
  163. * If I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENA is set, the
  164. * I40E_FLAG_LINK_DOWN_ON_CLOSE_ENA must be explicitly forced
  165. * to true and cannot be disabled by system admin at that time.
  166. * The functionalities are exclusive in terms of configuration, but
  167. * they also have similar behavior (allowing to disable physical
  168. * link of the port), with following differences:
  169. * - LINK_DOWN_ON_CLOSE_ENA is configurable at host OS run-time and
  170. * is supported by whole family of 7xx Intel Ethernet Controllers
  171. * - TOTAL_PORT_SHUTDOWN_ENA may be enabled only before OS loads
  172. * (in BIOS) only if motherboard's BIOS and NIC's FW has support of it
  173. * - when LINK_DOWN_ON_CLOSE_ENABLED is used, the link is being brought
  174. * down by sending phy_type=0 to NIC's FW
  175. * - when TOTAL_PORT_SHUTDOWN_ENA is used, phy_type is not altered,
  176. * instead the link is being brought down by clearing
  177. * bit (I40E_AQ_PHY_ENABLE_LINK) in abilities field of
  178. * i40e_aq_set_phy_config structure
  179. */
  180. I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENA,
  181. I40E_FLAG_VF_VLAN_PRUNING_ENA,
  182. I40E_PF_FLAGS_NBITS, /* must be last */
  183. };
  184. enum i40e_interrupt_policy {
  185. I40E_INTERRUPT_BEST_CASE,
  186. I40E_INTERRUPT_MEDIUM,
  187. I40E_INTERRUPT_LOWEST
  188. };
  189. struct i40e_lump_tracking {
  190. u16 num_entries;
  191. u16 list[];
  192. #define I40E_PILE_VALID_BIT 0x8000
  193. #define I40E_IWARP_IRQ_PILE_ID (I40E_PILE_VALID_BIT - 2)
  194. };
  195. #define I40E_DEFAULT_ATR_SAMPLE_RATE 20
  196. #define I40E_FDIR_MAX_RAW_PACKET_SIZE 512
  197. #define I40E_FDIR_BUFFER_FULL_MARGIN 10
  198. #define I40E_FDIR_BUFFER_HEAD_ROOM 32
  199. #define I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR (I40E_FDIR_BUFFER_HEAD_ROOM * 4)
  200. #define I40E_HKEY_ARRAY_SIZE ((I40E_PFQF_HKEY_MAX_INDEX + 1) * 4)
  201. #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
  202. #define I40E_VF_HLUT_ARRAY_SIZE ((I40E_VFQF_HLUT1_MAX_INDEX + 1) * 4)
  203. enum i40e_fd_stat_idx {
  204. I40E_FD_STAT_ATR,
  205. I40E_FD_STAT_SB,
  206. I40E_FD_STAT_ATR_TUNNEL,
  207. I40E_FD_STAT_PF_COUNT
  208. };
  209. #define I40E_FD_STAT_PF_IDX(pf_id) ((pf_id) * I40E_FD_STAT_PF_COUNT)
  210. #define I40E_FD_ATR_STAT_IDX(pf_id) \
  211. (I40E_FD_STAT_PF_IDX(pf_id) + I40E_FD_STAT_ATR)
  212. #define I40E_FD_SB_STAT_IDX(pf_id) \
  213. (I40E_FD_STAT_PF_IDX(pf_id) + I40E_FD_STAT_SB)
  214. #define I40E_FD_ATR_TUNNEL_STAT_IDX(pf_id) \
  215. (I40E_FD_STAT_PF_IDX(pf_id) + I40E_FD_STAT_ATR_TUNNEL)
  216. /* The following structure contains the data parsed from the user-defined
  217. * field of the ethtool_rx_flow_spec structure.
  218. */
  219. struct i40e_rx_flow_userdef {
  220. bool flex_filter;
  221. u16 flex_word;
  222. u16 flex_offset;
  223. };
  224. struct i40e_fdir_filter {
  225. struct hlist_node fdir_node;
  226. /* filter ipnut set */
  227. u8 flow_type;
  228. u8 ipl4_proto;
  229. /* TX packet view of src and dst */
  230. __be32 dst_ip;
  231. __be32 src_ip;
  232. __be32 dst_ip6[4];
  233. __be32 src_ip6[4];
  234. __be16 src_port;
  235. __be16 dst_port;
  236. __be32 sctp_v_tag;
  237. __be16 vlan_etype;
  238. __be16 vlan_tag;
  239. /* Flexible data to match within the packet payload */
  240. __be16 flex_word;
  241. u16 flex_offset;
  242. bool flex_filter;
  243. /* filter control */
  244. u16 q_index;
  245. u8 flex_off;
  246. u8 pctype;
  247. u16 dest_vsi;
  248. u8 dest_ctl;
  249. u8 fd_status;
  250. u16 cnt_index;
  251. u32 fd_id;
  252. };
  253. #define I40E_CLOUD_FIELD_OMAC BIT(0)
  254. #define I40E_CLOUD_FIELD_IMAC BIT(1)
  255. #define I40E_CLOUD_FIELD_IVLAN BIT(2)
  256. #define I40E_CLOUD_FIELD_TEN_ID BIT(3)
  257. #define I40E_CLOUD_FIELD_IIP BIT(4)
  258. #define I40E_CLOUD_FILTER_FLAGS_OMAC I40E_CLOUD_FIELD_OMAC
  259. #define I40E_CLOUD_FILTER_FLAGS_IMAC I40E_CLOUD_FIELD_IMAC
  260. #define I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN (I40E_CLOUD_FIELD_IMAC | \
  261. I40E_CLOUD_FIELD_IVLAN)
  262. #define I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID (I40E_CLOUD_FIELD_IMAC | \
  263. I40E_CLOUD_FIELD_TEN_ID)
  264. #define I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC (I40E_CLOUD_FIELD_OMAC | \
  265. I40E_CLOUD_FIELD_IMAC | \
  266. I40E_CLOUD_FIELD_TEN_ID)
  267. #define I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID (I40E_CLOUD_FIELD_IMAC | \
  268. I40E_CLOUD_FIELD_IVLAN | \
  269. I40E_CLOUD_FIELD_TEN_ID)
  270. #define I40E_CLOUD_FILTER_FLAGS_IIP I40E_CLOUD_FIELD_IIP
  271. struct i40e_cloud_filter {
  272. struct hlist_node cloud_node;
  273. unsigned long cookie;
  274. /* cloud filter input set follows */
  275. u8 dst_mac[ETH_ALEN];
  276. u8 src_mac[ETH_ALEN];
  277. __be16 vlan_id;
  278. u16 seid; /* filter control */
  279. __be16 dst_port;
  280. __be16 src_port;
  281. u32 tenant_id;
  282. union {
  283. struct {
  284. struct in_addr dst_ip;
  285. struct in_addr src_ip;
  286. } v4;
  287. struct {
  288. struct in6_addr dst_ip6;
  289. struct in6_addr src_ip6;
  290. } v6;
  291. } ip;
  292. #define dst_ipv6 ip.v6.dst_ip6.s6_addr32
  293. #define src_ipv6 ip.v6.src_ip6.s6_addr32
  294. #define dst_ipv4 ip.v4.dst_ip.s_addr
  295. #define src_ipv4 ip.v4.src_ip.s_addr
  296. u16 n_proto; /* Ethernet Protocol */
  297. u8 ip_proto; /* IPPROTO value */
  298. u8 flags;
  299. #define I40E_CLOUD_TNL_TYPE_NONE 0xff
  300. u8 tunnel_type;
  301. };
  302. #define I40E_DCB_PRIO_TYPE_STRICT 0
  303. #define I40E_DCB_PRIO_TYPE_ETS 1
  304. #define I40E_DCB_STRICT_PRIO_CREDITS 127
  305. /* DCB per TC information data structure */
  306. struct i40e_tc_info {
  307. u16 qoffset; /* Queue offset from base queue */
  308. u16 qcount; /* Total Queues */
  309. u8 netdev_tc; /* Netdev TC index if netdev associated */
  310. };
  311. /* TC configuration data structure */
  312. struct i40e_tc_configuration {
  313. u8 numtc; /* Total number of enabled TCs */
  314. u8 enabled_tc; /* TC map */
  315. struct i40e_tc_info tc_info[I40E_MAX_TRAFFIC_CLASS];
  316. };
  317. #define I40E_UDP_PORT_INDEX_UNUSED 255
  318. struct i40e_udp_port_config {
  319. /* AdminQ command interface expects port number in Host byte order */
  320. u16 port;
  321. u8 type;
  322. u8 filter_index;
  323. };
  324. /* macros related to FLX_PIT */
  325. #define I40E_FLEX_SET_FSIZE(fsize) (((fsize) << \
  326. I40E_PRTQF_FLX_PIT_FSIZE_SHIFT) & \
  327. I40E_PRTQF_FLX_PIT_FSIZE_MASK)
  328. #define I40E_FLEX_SET_DST_WORD(dst) (((dst) << \
  329. I40E_PRTQF_FLX_PIT_DEST_OFF_SHIFT) & \
  330. I40E_PRTQF_FLX_PIT_DEST_OFF_MASK)
  331. #define I40E_FLEX_SET_SRC_WORD(src) (((src) << \
  332. I40E_PRTQF_FLX_PIT_SOURCE_OFF_SHIFT) & \
  333. I40E_PRTQF_FLX_PIT_SOURCE_OFF_MASK)
  334. #define I40E_FLEX_PREP_VAL(dst, fsize, src) (I40E_FLEX_SET_DST_WORD(dst) | \
  335. I40E_FLEX_SET_FSIZE(fsize) | \
  336. I40E_FLEX_SET_SRC_WORD(src))
  337. #define I40E_MAX_FLEX_SRC_OFFSET 0x1F
  338. /* macros related to GLQF_ORT */
  339. #define I40E_ORT_SET_IDX(idx) (((idx) << \
  340. I40E_GLQF_ORT_PIT_INDX_SHIFT) & \
  341. I40E_GLQF_ORT_PIT_INDX_MASK)
  342. #define I40E_ORT_SET_COUNT(count) (((count) << \
  343. I40E_GLQF_ORT_FIELD_CNT_SHIFT) & \
  344. I40E_GLQF_ORT_FIELD_CNT_MASK)
  345. #define I40E_ORT_SET_PAYLOAD(payload) (((payload) << \
  346. I40E_GLQF_ORT_FLX_PAYLOAD_SHIFT) & \
  347. I40E_GLQF_ORT_FLX_PAYLOAD_MASK)
  348. #define I40E_ORT_PREP_VAL(idx, count, payload) (I40E_ORT_SET_IDX(idx) | \
  349. I40E_ORT_SET_COUNT(count) | \
  350. I40E_ORT_SET_PAYLOAD(payload))
  351. #define I40E_L3_GLQF_ORT_IDX 34
  352. #define I40E_L4_GLQF_ORT_IDX 35
  353. /* Flex PIT register index */
  354. #define I40E_FLEX_PIT_IDX_START_L3 3
  355. #define I40E_FLEX_PIT_IDX_START_L4 6
  356. #define I40E_FLEX_PIT_TABLE_SIZE 3
  357. #define I40E_FLEX_DEST_UNUSED 63
  358. #define I40E_FLEX_INDEX_ENTRIES 8
  359. /* Flex MASK to disable all flexible entries */
  360. #define I40E_FLEX_INPUT_MASK (I40E_FLEX_50_MASK | I40E_FLEX_51_MASK | \
  361. I40E_FLEX_52_MASK | I40E_FLEX_53_MASK | \
  362. I40E_FLEX_54_MASK | I40E_FLEX_55_MASK | \
  363. I40E_FLEX_56_MASK | I40E_FLEX_57_MASK)
  364. #define I40E_QINT_TQCTL_VAL(qp, vector, nextq_type) \
  365. (I40E_QINT_TQCTL_CAUSE_ENA_MASK | \
  366. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | \
  367. ((vector) << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | \
  368. ((qp) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | \
  369. (I40E_QUEUE_TYPE_##nextq_type << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT))
  370. #define I40E_QINT_RQCTL_VAL(qp, vector, nextq_type) \
  371. (I40E_QINT_RQCTL_CAUSE_ENA_MASK | \
  372. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | \
  373. ((vector) << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | \
  374. ((qp) << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | \
  375. (I40E_QUEUE_TYPE_##nextq_type << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT))
  376. struct i40e_flex_pit {
  377. struct list_head list;
  378. u16 src_offset;
  379. u8 pit_index;
  380. };
  381. struct i40e_fwd_adapter {
  382. struct net_device *netdev;
  383. int bit_no;
  384. };
  385. struct i40e_channel {
  386. struct list_head list;
  387. bool initialized;
  388. u8 type;
  389. u16 vsi_number; /* Assigned VSI number from AQ 'Add VSI' response */
  390. u16 stat_counter_idx;
  391. u16 base_queue;
  392. u16 num_queue_pairs; /* Requested by user */
  393. u16 seid;
  394. u8 enabled_tc;
  395. struct i40e_aqc_vsi_properties_data info;
  396. u64 max_tx_rate;
  397. struct i40e_fwd_adapter *fwd;
  398. /* track this channel belongs to which VSI */
  399. struct i40e_vsi *parent_vsi;
  400. };
  401. struct i40e_ptp_pins_settings;
  402. static inline bool i40e_is_channel_macvlan(struct i40e_channel *ch)
  403. {
  404. return !!ch->fwd;
  405. }
  406. static inline const u8 *i40e_channel_mac(struct i40e_channel *ch)
  407. {
  408. if (i40e_is_channel_macvlan(ch))
  409. return ch->fwd->netdev->dev_addr;
  410. else
  411. return NULL;
  412. }
  413. /* struct that defines the Ethernet device */
  414. struct i40e_pf {
  415. struct pci_dev *pdev;
  416. struct devlink_port devlink_port;
  417. struct i40e_hw hw;
  418. DECLARE_BITMAP(state, __I40E_STATE_SIZE__);
  419. struct msix_entry *msix_entries;
  420. u16 num_vmdq_vsis; /* num vmdq vsis this PF has set up */
  421. u16 num_vmdq_qps; /* num queue pairs per vmdq pool */
  422. u16 num_vmdq_msix; /* num queue vectors per vmdq pool */
  423. u16 num_req_vfs; /* num VFs requested for this PF */
  424. u16 num_vf_qps; /* num queue pairs per VF */
  425. u16 num_lan_qps; /* num lan queues this PF has set up */
  426. u16 num_lan_msix; /* num queue vectors for the base PF vsi */
  427. u16 num_fdsb_msix; /* num queue vectors for sideband Fdir */
  428. u16 num_iwarp_msix; /* num of iwarp vectors for this PF */
  429. int iwarp_base_vector;
  430. int queues_left; /* queues left unclaimed */
  431. u16 alloc_rss_size; /* allocated RSS queues */
  432. u16 rss_size_max; /* HW defined max RSS queues */
  433. u16 fdir_pf_filter_count; /* num of guaranteed filters for this PF */
  434. u16 num_alloc_vsi; /* num VSIs this driver supports */
  435. bool wol_en;
  436. struct hlist_head fdir_filter_list;
  437. u16 fdir_pf_active_filters;
  438. unsigned long fd_flush_timestamp;
  439. u32 fd_flush_cnt;
  440. u32 fd_add_err;
  441. u32 fd_atr_cnt;
  442. /* Book-keeping of side-band filter count per flow-type.
  443. * This is used to detect and handle input set changes for
  444. * respective flow-type.
  445. */
  446. u16 fd_tcp4_filter_cnt;
  447. u16 fd_udp4_filter_cnt;
  448. u16 fd_sctp4_filter_cnt;
  449. u16 fd_ip4_filter_cnt;
  450. u16 fd_tcp6_filter_cnt;
  451. u16 fd_udp6_filter_cnt;
  452. u16 fd_sctp6_filter_cnt;
  453. u16 fd_ip6_filter_cnt;
  454. /* Flexible filter table values that need to be programmed into
  455. * hardware, which expects L3 and L4 to be programmed separately. We
  456. * need to ensure that the values are in ascended order and don't have
  457. * duplicates, so we track each L3 and L4 values in separate lists.
  458. */
  459. struct list_head l3_flex_pit_list;
  460. struct list_head l4_flex_pit_list;
  461. struct udp_tunnel_nic_shared udp_tunnel_shared;
  462. struct udp_tunnel_nic_info udp_tunnel_nic;
  463. struct hlist_head cloud_filter_list;
  464. u16 num_cloud_filters;
  465. u16 rx_itr_default;
  466. u16 tx_itr_default;
  467. u32 msg_enable;
  468. char int_name[I40E_INT_NAME_STR_LEN];
  469. unsigned long service_timer_period;
  470. unsigned long service_timer_previous;
  471. struct timer_list service_timer;
  472. struct work_struct service_task;
  473. DECLARE_BITMAP(flags, I40E_PF_FLAGS_NBITS);
  474. struct i40e_client_instance *cinst;
  475. bool stat_offsets_loaded;
  476. struct i40e_hw_port_stats stats;
  477. struct i40e_hw_port_stats stats_offsets;
  478. u32 tx_timeout_count;
  479. u32 tx_timeout_recovery_level;
  480. unsigned long tx_timeout_last_recovery;
  481. u32 hw_csum_rx_error;
  482. u32 led_status;
  483. u16 corer_count; /* Core reset count */
  484. u16 globr_count; /* Global reset count */
  485. u16 empr_count; /* EMP reset count */
  486. u16 pfr_count; /* PF reset count */
  487. u16 sw_int_count; /* SW interrupt count */
  488. struct mutex switch_mutex;
  489. u16 lan_vsi; /* our default LAN VSI */
  490. u16 lan_veb; /* initial relay, if exists */
  491. #define I40E_NO_VEB 0xffff
  492. #define I40E_NO_VSI 0xffff
  493. u16 next_vsi; /* Next unallocated VSI - 0-based! */
  494. struct i40e_vsi **vsi;
  495. struct i40e_veb *veb[I40E_MAX_VEB];
  496. struct i40e_lump_tracking *qp_pile;
  497. struct i40e_lump_tracking *irq_pile;
  498. /* switch config info */
  499. u16 main_vsi_seid;
  500. u16 mac_seid;
  501. #ifdef CONFIG_DEBUG_FS
  502. struct dentry *i40e_dbg_pf;
  503. #endif /* CONFIG_DEBUG_FS */
  504. bool cur_promisc;
  505. /* sr-iov config info */
  506. struct i40e_vf *vf;
  507. int num_alloc_vfs; /* actual number of VFs allocated */
  508. u32 vf_aq_requests;
  509. u32 arq_overflows; /* Not fatal, possibly indicative of problems */
  510. /* DCBx/DCBNL capability for PF that indicates
  511. * whether DCBx is managed by firmware or host
  512. * based agent (LLDPAD). Also, indicates what
  513. * flavor of DCBx protocol (IEEE/CEE) is supported
  514. * by the device. For now we're supporting IEEE
  515. * mode only.
  516. */
  517. u16 dcbx_cap;
  518. struct i40e_filter_control_settings filter_settings;
  519. struct i40e_rx_pb_config pb_cfg; /* Current Rx packet buffer config */
  520. struct i40e_dcbx_config tmp_cfg;
  521. /* GPIO defines used by PTP */
  522. #define I40E_SDP3_2 18
  523. #define I40E_SDP3_3 19
  524. #define I40E_GPIO_4 20
  525. #define I40E_LED2_0 26
  526. #define I40E_LED2_1 27
  527. #define I40E_LED3_0 28
  528. #define I40E_LED3_1 29
  529. #define I40E_GLGEN_GPIO_SET_SDP_DATA_HI \
  530. (1 << I40E_GLGEN_GPIO_SET_SDP_DATA_SHIFT)
  531. #define I40E_GLGEN_GPIO_SET_DRV_SDP_DATA \
  532. (1 << I40E_GLGEN_GPIO_SET_DRIVE_SDP_SHIFT)
  533. #define I40E_GLGEN_GPIO_CTL_PRT_NUM_0 \
  534. (0 << I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT)
  535. #define I40E_GLGEN_GPIO_CTL_PRT_NUM_1 \
  536. (1 << I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT)
  537. #define I40E_GLGEN_GPIO_CTL_RESERVED BIT(2)
  538. #define I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_Z \
  539. (1 << I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_SHIFT)
  540. #define I40E_GLGEN_GPIO_CTL_DIR_OUT \
  541. (1 << I40E_GLGEN_GPIO_CTL_PIN_DIR_SHIFT)
  542. #define I40E_GLGEN_GPIO_CTL_TRI_DRV_HI \
  543. (1 << I40E_GLGEN_GPIO_CTL_TRI_CTL_SHIFT)
  544. #define I40E_GLGEN_GPIO_CTL_OUT_HI_RST \
  545. (1 << I40E_GLGEN_GPIO_CTL_OUT_CTL_SHIFT)
  546. #define I40E_GLGEN_GPIO_CTL_TIMESYNC_0 \
  547. (3 << I40E_GLGEN_GPIO_CTL_PIN_FUNC_SHIFT)
  548. #define I40E_GLGEN_GPIO_CTL_TIMESYNC_1 \
  549. (4 << I40E_GLGEN_GPIO_CTL_PIN_FUNC_SHIFT)
  550. #define I40E_GLGEN_GPIO_CTL_NOT_FOR_PHY_CONN \
  551. (0x3F << I40E_GLGEN_GPIO_CTL_PHY_PIN_NAME_SHIFT)
  552. #define I40E_GLGEN_GPIO_CTL_OUT_DEFAULT \
  553. (1 << I40E_GLGEN_GPIO_CTL_OUT_DEFAULT_SHIFT)
  554. #define I40E_GLGEN_GPIO_CTL_PORT_0_IN_TIMESYNC_0 \
  555. (I40E_GLGEN_GPIO_CTL_NOT_FOR_PHY_CONN | \
  556. I40E_GLGEN_GPIO_CTL_TIMESYNC_0 | \
  557. I40E_GLGEN_GPIO_CTL_RESERVED | I40E_GLGEN_GPIO_CTL_PRT_NUM_0)
  558. #define I40E_GLGEN_GPIO_CTL_PORT_1_IN_TIMESYNC_0 \
  559. (I40E_GLGEN_GPIO_CTL_NOT_FOR_PHY_CONN | \
  560. I40E_GLGEN_GPIO_CTL_TIMESYNC_0 | \
  561. I40E_GLGEN_GPIO_CTL_RESERVED | I40E_GLGEN_GPIO_CTL_PRT_NUM_1)
  562. #define I40E_GLGEN_GPIO_CTL_PORT_0_OUT_TIMESYNC_1 \
  563. (I40E_GLGEN_GPIO_CTL_NOT_FOR_PHY_CONN | \
  564. I40E_GLGEN_GPIO_CTL_TIMESYNC_1 | I40E_GLGEN_GPIO_CTL_OUT_HI_RST | \
  565. I40E_GLGEN_GPIO_CTL_TRI_DRV_HI | I40E_GLGEN_GPIO_CTL_DIR_OUT | \
  566. I40E_GLGEN_GPIO_CTL_RESERVED | I40E_GLGEN_GPIO_CTL_PRT_NUM_0)
  567. #define I40E_GLGEN_GPIO_CTL_PORT_1_OUT_TIMESYNC_1 \
  568. (I40E_GLGEN_GPIO_CTL_NOT_FOR_PHY_CONN | \
  569. I40E_GLGEN_GPIO_CTL_TIMESYNC_1 | I40E_GLGEN_GPIO_CTL_OUT_HI_RST | \
  570. I40E_GLGEN_GPIO_CTL_TRI_DRV_HI | I40E_GLGEN_GPIO_CTL_DIR_OUT | \
  571. I40E_GLGEN_GPIO_CTL_RESERVED | I40E_GLGEN_GPIO_CTL_PRT_NUM_1)
  572. #define I40E_GLGEN_GPIO_CTL_LED_INIT \
  573. (I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_Z | \
  574. I40E_GLGEN_GPIO_CTL_DIR_OUT | \
  575. I40E_GLGEN_GPIO_CTL_TRI_DRV_HI | \
  576. I40E_GLGEN_GPIO_CTL_OUT_HI_RST | \
  577. I40E_GLGEN_GPIO_CTL_OUT_DEFAULT | \
  578. I40E_GLGEN_GPIO_CTL_NOT_FOR_PHY_CONN)
  579. #define I40E_PRTTSYN_AUX_1_INSTNT \
  580. (1 << I40E_PRTTSYN_AUX_1_INSTNT_SHIFT)
  581. #define I40E_PRTTSYN_AUX_0_OUT_ENABLE \
  582. (1 << I40E_PRTTSYN_AUX_0_OUT_ENA_SHIFT)
  583. #define I40E_PRTTSYN_AUX_0_OUT_CLK_MOD (3 << I40E_PRTTSYN_AUX_0_OUTMOD_SHIFT)
  584. #define I40E_PRTTSYN_AUX_0_OUT_ENABLE_CLK_MOD \
  585. (I40E_PRTTSYN_AUX_0_OUT_ENABLE | I40E_PRTTSYN_AUX_0_OUT_CLK_MOD)
  586. #define I40E_PTP_HALF_SECOND 500000000LL /* nano seconds */
  587. #define I40E_PTP_2_SEC_DELAY 2
  588. struct ptp_clock *ptp_clock;
  589. struct ptp_clock_info ptp_caps;
  590. struct sk_buff *ptp_tx_skb;
  591. unsigned long ptp_tx_start;
  592. struct hwtstamp_config tstamp_config;
  593. struct timespec64 ptp_prev_hw_time;
  594. struct work_struct ptp_extts0_work;
  595. ktime_t ptp_reset_start;
  596. struct mutex tmreg_lock; /* Used to protect the SYSTIME registers. */
  597. u32 ptp_adj_mult;
  598. u32 tx_hwtstamp_timeouts;
  599. u32 tx_hwtstamp_skipped;
  600. u32 rx_hwtstamp_cleared;
  601. u32 latch_event_flags;
  602. spinlock_t ptp_rx_lock; /* Used to protect Rx timestamp registers. */
  603. unsigned long latch_events[4];
  604. bool ptp_tx;
  605. bool ptp_rx;
  606. struct i40e_ptp_pins_settings *ptp_pins;
  607. u16 rss_table_size; /* HW RSS table size */
  608. u32 max_bw;
  609. u32 min_bw;
  610. u32 ioremap_len;
  611. u32 fd_inv;
  612. u16 phy_led_val;
  613. u16 last_sw_conf_flags;
  614. u16 last_sw_conf_valid_flags;
  615. /* List to keep previous DDP profiles to be rolled back in the future */
  616. struct list_head ddp_old_prof;
  617. };
  618. /**
  619. * __i40e_pf_next_vsi - get next valid VSI
  620. * @pf: pointer to the PF struct
  621. * @idx: pointer to start position number
  622. *
  623. * Find and return next non-NULL VSI pointer in pf->vsi array and
  624. * updates idx position. Returns NULL if no VSI is found.
  625. **/
  626. static __always_inline struct i40e_vsi *
  627. __i40e_pf_next_vsi(struct i40e_pf *pf, int *idx)
  628. {
  629. while (*idx < pf->num_alloc_vsi) {
  630. if (pf->vsi[*idx])
  631. return pf->vsi[*idx];
  632. (*idx)++;
  633. }
  634. return NULL;
  635. }
  636. #define i40e_pf_for_each_vsi(_pf, _i, _vsi) \
  637. for (_i = 0, _vsi = __i40e_pf_next_vsi(_pf, &_i); \
  638. _vsi; \
  639. _i++, _vsi = __i40e_pf_next_vsi(_pf, &_i))
  640. /**
  641. * __i40e_pf_next_veb - get next valid VEB
  642. * @pf: pointer to the PF struct
  643. * @idx: pointer to start position number
  644. *
  645. * Find and return next non-NULL VEB pointer in pf->veb array and
  646. * updates idx position. Returns NULL if no VEB is found.
  647. **/
  648. static __always_inline struct i40e_veb *
  649. __i40e_pf_next_veb(struct i40e_pf *pf, int *idx)
  650. {
  651. while (*idx < I40E_MAX_VEB) {
  652. if (pf->veb[*idx])
  653. return pf->veb[*idx];
  654. (*idx)++;
  655. }
  656. return NULL;
  657. }
  658. #define i40e_pf_for_each_veb(_pf, _i, _veb) \
  659. for (_i = 0, _veb = __i40e_pf_next_veb(_pf, &_i); \
  660. _veb; \
  661. _i++, _veb = __i40e_pf_next_veb(_pf, &_i))
  662. /**
  663. * i40e_addr_to_hkey - Convert a 6-byte MAC Address to a u64 hash key
  664. * @macaddr: the MAC Address as the base key
  665. *
  666. * Simply copies the address and returns it as a u64 for hashing
  667. **/
  668. static inline u64 i40e_addr_to_hkey(const u8 *macaddr)
  669. {
  670. u64 key = 0;
  671. ether_addr_copy((u8 *)&key, macaddr);
  672. return key;
  673. }
  674. enum i40e_filter_state {
  675. I40E_FILTER_INVALID = 0, /* Invalid state */
  676. I40E_FILTER_NEW, /* New, not sent to FW yet */
  677. I40E_FILTER_ACTIVE, /* Added to switch by FW */
  678. I40E_FILTER_FAILED, /* Rejected by FW */
  679. I40E_FILTER_REMOVE, /* To be removed */
  680. I40E_FILTER_NEW_SYNC, /* New, not sent yet, is in i40e_sync_vsi_filters() */
  681. /* There is no 'removed' state; the filter struct is freed */
  682. };
  683. struct i40e_mac_filter {
  684. struct hlist_node hlist;
  685. u8 macaddr[ETH_ALEN];
  686. #define I40E_VLAN_ANY -1
  687. s16 vlan;
  688. enum i40e_filter_state state;
  689. };
  690. /* Wrapper structure to keep track of filters while we are preparing to send
  691. * firmware commands. We cannot send firmware commands while holding a
  692. * spinlock, since it might sleep. To avoid this, we wrap the added filters in
  693. * a separate structure, which will track the state change and update the real
  694. * filter while under lock. We can't simply hold the filters in a separate
  695. * list, as this opens a window for a race condition when adding new MAC
  696. * addresses to all VLANs, or when adding new VLANs to all MAC addresses.
  697. */
  698. struct i40e_new_mac_filter {
  699. struct hlist_node hlist;
  700. struct i40e_mac_filter *f;
  701. /* Track future changes to state separately */
  702. enum i40e_filter_state state;
  703. };
  704. struct i40e_veb {
  705. struct i40e_pf *pf;
  706. u16 idx;
  707. u16 seid;
  708. u16 uplink_seid;
  709. u16 stats_idx; /* index of VEB parent */
  710. u8 enabled_tc;
  711. u16 bridge_mode; /* Bridge Mode (VEB/VEPA) */
  712. u16 bw_limit;
  713. u8 bw_max_quanta;
  714. bool is_abs_credits;
  715. u8 bw_tc_share_credits[I40E_MAX_TRAFFIC_CLASS];
  716. u16 bw_tc_limit_credits[I40E_MAX_TRAFFIC_CLASS];
  717. u8 bw_tc_max_quanta[I40E_MAX_TRAFFIC_CLASS];
  718. struct kobject *kobj;
  719. bool stat_offsets_loaded;
  720. struct i40e_eth_stats stats;
  721. struct i40e_eth_stats stats_offsets;
  722. struct i40e_veb_tc_stats tc_stats;
  723. struct i40e_veb_tc_stats tc_stats_offsets;
  724. };
  725. /* struct that defines a VSI, associated with a dev */
  726. struct i40e_vsi {
  727. struct net_device *netdev;
  728. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  729. bool netdev_registered;
  730. bool stat_offsets_loaded;
  731. u32 current_netdev_flags;
  732. DECLARE_BITMAP(state, __I40E_VSI_STATE_SIZE__);
  733. #define I40E_VSI_FLAG_FILTER_CHANGED BIT(0)
  734. #define I40E_VSI_FLAG_VEB_OWNER BIT(1)
  735. unsigned long flags;
  736. /* Per VSI lock to protect elements/hash (MAC filter) */
  737. spinlock_t mac_filter_hash_lock;
  738. /* Fixed size hash table with 2^8 buckets for MAC filters */
  739. DECLARE_HASHTABLE(mac_filter_hash, 8);
  740. bool has_vlan_filter;
  741. /* VSI stats */
  742. struct rtnl_link_stats64 net_stats;
  743. struct rtnl_link_stats64 net_stats_offsets;
  744. struct i40e_eth_stats eth_stats;
  745. struct i40e_eth_stats eth_stats_offsets;
  746. u64 tx_restart;
  747. u64 tx_busy;
  748. u64 tx_linearize;
  749. u64 tx_force_wb;
  750. u64 tx_stopped;
  751. u64 rx_buf_failed;
  752. u64 rx_page_failed;
  753. u64 rx_page_reuse;
  754. u64 rx_page_alloc;
  755. u64 rx_page_waive;
  756. u64 rx_page_busy;
  757. /* These are containers of ring pointers, allocated at run-time */
  758. struct i40e_ring **rx_rings;
  759. struct i40e_ring **tx_rings;
  760. struct i40e_ring **xdp_rings; /* XDP Tx rings */
  761. u32 active_filters;
  762. u32 promisc_threshold;
  763. u16 work_limit;
  764. u16 int_rate_limit; /* value in usecs */
  765. u16 rss_table_size; /* HW RSS table size */
  766. u16 rss_size; /* Allocated RSS queues */
  767. u8 *rss_hkey_user; /* User configured hash keys */
  768. u8 *rss_lut_user; /* User configured lookup table entries */
  769. u16 max_frame;
  770. u16 rx_buf_len;
  771. struct bpf_prog *xdp_prog;
  772. /* List of q_vectors allocated to this VSI */
  773. struct i40e_q_vector **q_vectors;
  774. int num_q_vectors;
  775. int base_vector;
  776. bool irqs_ready;
  777. u16 seid; /* HW index of this VSI (absolute index) */
  778. u16 id; /* VSI number */
  779. u16 uplink_seid;
  780. u16 base_queue; /* vsi's first queue in hw array */
  781. u16 alloc_queue_pairs; /* Allocated Tx/Rx queues */
  782. u16 req_queue_pairs; /* User requested queue pairs */
  783. u16 num_queue_pairs; /* Used tx and rx pairs */
  784. u16 num_tx_desc;
  785. u16 num_rx_desc;
  786. enum i40e_vsi_type type; /* VSI type, e.g., LAN, FCoE, etc */
  787. s16 vf_id; /* Virtual function ID for SRIOV VSIs */
  788. struct tc_mqprio_qopt_offload mqprio_qopt; /* queue parameters */
  789. struct i40e_tc_configuration tc_config;
  790. struct i40e_aqc_vsi_properties_data info;
  791. /* VSI BW limit (absolute across all TCs) */
  792. u16 bw_limit; /* VSI BW Limit (0 = disabled) */
  793. u8 bw_max_quanta; /* Max Quanta when BW limit is enabled */
  794. /* Relative TC credits across VSIs */
  795. u8 bw_ets_share_credits[I40E_MAX_TRAFFIC_CLASS];
  796. /* TC BW limit credits within VSI */
  797. u16 bw_ets_limit_credits[I40E_MAX_TRAFFIC_CLASS];
  798. /* TC BW limit max quanta within VSI */
  799. u8 bw_ets_max_quanta[I40E_MAX_TRAFFIC_CLASS];
  800. struct i40e_pf *back; /* Backreference to associated PF */
  801. u16 idx; /* index in pf->vsi[] */
  802. u16 veb_idx; /* index of VEB parent */
  803. struct kobject *kobj; /* sysfs object */
  804. bool current_isup; /* Sync 'link up' logging */
  805. enum i40e_aq_link_speed current_speed; /* Sync link speed logging */
  806. /* channel specific fields */
  807. u16 cnt_q_avail; /* num of queues available for channel usage */
  808. u16 orig_rss_size;
  809. u16 current_rss_size;
  810. bool reconfig_rss;
  811. u16 next_base_queue; /* next queue to be used for channel setup */
  812. struct list_head ch_list;
  813. u16 tc_seid_map[I40E_MAX_TRAFFIC_CLASS];
  814. /* macvlan fields */
  815. #define I40E_MAX_MACVLANS 128 /* Max HW vectors - 1 on FVL */
  816. #define I40E_MIN_MACVLAN_VECTORS 2 /* Min vectors to enable macvlans */
  817. DECLARE_BITMAP(fwd_bitmask, I40E_MAX_MACVLANS);
  818. struct list_head macvlan_list;
  819. int macvlan_cnt;
  820. void *priv; /* client driver data reference. */
  821. /* VSI specific handlers */
  822. irqreturn_t (*irq_handler)(int irq, void *data);
  823. unsigned long *af_xdp_zc_qps; /* tracks AF_XDP ZC enabled qps */
  824. } ____cacheline_internodealigned_in_smp;
  825. struct i40e_netdev_priv {
  826. struct i40e_vsi *vsi;
  827. };
  828. extern struct ida i40e_client_ida;
  829. /* struct that defines an interrupt vector */
  830. struct i40e_q_vector {
  831. struct i40e_vsi *vsi;
  832. u16 v_idx; /* index in the vsi->q_vector array. */
  833. u16 reg_idx; /* register index of the interrupt */
  834. struct napi_struct napi;
  835. struct rcu_head rcu; /* to avoid race with update stats on free */
  836. struct i40e_ring_container rx;
  837. struct i40e_ring_container tx;
  838. u8 itr_countdown; /* when 0 should adjust adaptive ITR */
  839. u8 num_ringpairs; /* total number of ring pairs in vector */
  840. cpumask_t affinity_mask;
  841. struct irq_affinity_notify affinity_notify;
  842. char name[I40E_INT_NAME_STR_LEN];
  843. bool arm_wb_state;
  844. bool in_busy_poll;
  845. int irq_num; /* IRQ assigned to this q_vector */
  846. } ____cacheline_internodealigned_in_smp;
  847. /* lan device */
  848. struct i40e_device {
  849. struct list_head list;
  850. struct i40e_pf *pf;
  851. };
  852. /**
  853. * i40e_info_nvm_ver - format the NVM version string
  854. * @hw: ptr to the hardware info
  855. * @buf: string buffer to store
  856. * @len: buffer size
  857. *
  858. * Formats NVM version string as:
  859. * <gen>.<snap>.<release> when eetrackid == I40E_OEM_EETRACK_ID
  860. * <nvm_major>.<nvm_minor> otherwise
  861. **/
  862. static inline void i40e_info_nvm_ver(struct i40e_hw *hw, char *buf, size_t len)
  863. {
  864. struct i40e_nvm_info *nvm = &hw->nvm;
  865. if (nvm->eetrack == I40E_OEM_EETRACK_ID) {
  866. u32 full_ver = nvm->oem_ver;
  867. u8 gen, snap;
  868. u16 release;
  869. gen = FIELD_GET(I40E_OEM_GEN_MASK, full_ver);
  870. snap = FIELD_GET(I40E_OEM_SNAP_MASK, full_ver);
  871. release = FIELD_GET(I40E_OEM_RELEASE_MASK, full_ver);
  872. snprintf(buf, len, "%x.%x.%x", gen, snap, release);
  873. } else {
  874. u8 major, minor;
  875. major = FIELD_GET(I40E_NVM_VERSION_HI_MASK, nvm->version);
  876. minor = FIELD_GET(I40E_NVM_VERSION_LO_MASK, nvm->version);
  877. snprintf(buf, len, "%x.%02x", major, minor);
  878. }
  879. }
  880. /**
  881. * i40e_info_eetrack - format the EETrackID string
  882. * @hw: ptr to the hardware info
  883. * @buf: string buffer to store
  884. * @len: buffer size
  885. *
  886. * Returns hexadecimally formated EETrackID if it is
  887. * different from I40E_OEM_EETRACK_ID or empty string.
  888. **/
  889. static inline void i40e_info_eetrack(struct i40e_hw *hw, char *buf, size_t len)
  890. {
  891. struct i40e_nvm_info *nvm = &hw->nvm;
  892. buf[0] = '\0';
  893. if (nvm->eetrack != I40E_OEM_EETRACK_ID)
  894. snprintf(buf, len, "0x%08x", nvm->eetrack);
  895. }
  896. /**
  897. * i40e_info_civd_ver - format the NVM version strings
  898. * @hw: ptr to the hardware info
  899. * @buf: string buffer to store
  900. * @len: buffer size
  901. *
  902. * Returns formated combo image version if adapter's EETrackID is
  903. * different from I40E_OEM_EETRACK_ID or empty string.
  904. **/
  905. static inline void i40e_info_civd_ver(struct i40e_hw *hw, char *buf, size_t len)
  906. {
  907. struct i40e_nvm_info *nvm = &hw->nvm;
  908. buf[0] = '\0';
  909. if (nvm->eetrack != I40E_OEM_EETRACK_ID) {
  910. u32 full_ver = nvm->oem_ver;
  911. u8 major, minor;
  912. u16 build;
  913. major = FIELD_GET(I40E_OEM_VER_MASK, full_ver);
  914. build = FIELD_GET(I40E_OEM_VER_BUILD_MASK, full_ver);
  915. minor = FIELD_GET(I40E_OEM_VER_PATCH_MASK, full_ver);
  916. snprintf(buf, len, "%d.%d.%d", major, build, minor);
  917. }
  918. }
  919. /**
  920. * i40e_nvm_version_str - format the NVM version strings
  921. * @hw: ptr to the hardware info
  922. * @buf: string buffer to store
  923. * @len: buffer size
  924. **/
  925. static inline char *i40e_nvm_version_str(struct i40e_hw *hw, char *buf,
  926. size_t len)
  927. {
  928. char ver[16] = " ";
  929. /* Get NVM version */
  930. i40e_info_nvm_ver(hw, buf, len);
  931. /* Append EETrackID if provided */
  932. i40e_info_eetrack(hw, &ver[1], sizeof(ver) - 1);
  933. if (strlen(ver) > 1)
  934. strlcat(buf, ver, len);
  935. /* Append combo image version if provided */
  936. i40e_info_civd_ver(hw, &ver[1], sizeof(ver) - 1);
  937. if (strlen(ver) > 1)
  938. strlcat(buf, ver, len);
  939. return buf;
  940. }
  941. /**
  942. * i40e_netdev_to_pf: Retrieve the PF struct for given netdev
  943. * @netdev: the corresponding netdev
  944. *
  945. * Return the PF struct for the given netdev
  946. **/
  947. static inline struct i40e_pf *i40e_netdev_to_pf(struct net_device *netdev)
  948. {
  949. struct i40e_netdev_priv *np = netdev_priv(netdev);
  950. struct i40e_vsi *vsi = np->vsi;
  951. return vsi->back;
  952. }
  953. static inline void i40e_vsi_setup_irqhandler(struct i40e_vsi *vsi,
  954. irqreturn_t (*irq_handler)(int, void *))
  955. {
  956. vsi->irq_handler = irq_handler;
  957. }
  958. /**
  959. * i40e_get_fd_cnt_all - get the total FD filter space available
  960. * @pf: pointer to the PF struct
  961. **/
  962. static inline int i40e_get_fd_cnt_all(struct i40e_pf *pf)
  963. {
  964. return pf->hw.fdir_shared_filter_count + pf->fdir_pf_filter_count;
  965. }
  966. /**
  967. * i40e_read_fd_input_set - reads value of flow director input set register
  968. * @pf: pointer to the PF struct
  969. * @addr: register addr
  970. *
  971. * This function reads value of flow director input set register
  972. * specified by 'addr' (which is specific to flow-type)
  973. **/
  974. static inline u64 i40e_read_fd_input_set(struct i40e_pf *pf, u16 addr)
  975. {
  976. u64 val;
  977. val = i40e_read_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 1));
  978. val <<= 32;
  979. val += i40e_read_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 0));
  980. return val;
  981. }
  982. /**
  983. * i40e_write_fd_input_set - writes value into flow director input set register
  984. * @pf: pointer to the PF struct
  985. * @addr: register addr
  986. * @val: value to be written
  987. *
  988. * This function writes specified value to the register specified by 'addr'.
  989. * This register is input set register based on flow-type.
  990. **/
  991. static inline void i40e_write_fd_input_set(struct i40e_pf *pf,
  992. u16 addr, u64 val)
  993. {
  994. i40e_write_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 1),
  995. (u32)(val >> 32));
  996. i40e_write_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 0),
  997. (u32)(val & 0xFFFFFFFFULL));
  998. }
  999. /**
  1000. * i40e_get_pf_count - get PCI PF count.
  1001. * @hw: pointer to a hw.
  1002. *
  1003. * Reports the function number of the highest PCI physical
  1004. * function plus 1 as it is loaded from the NVM.
  1005. *
  1006. * Return: PCI PF count.
  1007. **/
  1008. static inline u32 i40e_get_pf_count(struct i40e_hw *hw)
  1009. {
  1010. return FIELD_GET(I40E_GLGEN_PCIFCNCNT_PCIPFCNT_MASK,
  1011. rd32(hw, I40E_GLGEN_PCIFCNCNT));
  1012. }
  1013. /* needed by i40e_ethtool.c */
  1014. int i40e_up(struct i40e_vsi *vsi);
  1015. void i40e_down(struct i40e_vsi *vsi);
  1016. extern const char i40e_driver_name[];
  1017. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags);
  1018. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired);
  1019. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  1020. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  1021. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  1022. u16 rss_table_size, u16 rss_size);
  1023. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id);
  1024. /**
  1025. * i40e_find_vsi_by_type - Find and return Flow Director VSI
  1026. * @pf: PF to search for VSI
  1027. * @type: Value indicating type of VSI we are looking for
  1028. **/
  1029. static inline struct i40e_vsi *
  1030. i40e_find_vsi_by_type(struct i40e_pf *pf, u16 type)
  1031. {
  1032. struct i40e_vsi *vsi;
  1033. int i;
  1034. i40e_pf_for_each_vsi(pf, i, vsi)
  1035. if (vsi->type == type)
  1036. return vsi;
  1037. return NULL;
  1038. }
  1039. void i40e_update_stats(struct i40e_vsi *vsi);
  1040. void i40e_update_veb_stats(struct i40e_veb *veb);
  1041. void i40e_update_eth_stats(struct i40e_vsi *vsi);
  1042. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi);
  1043. int i40e_fetch_switch_configuration(struct i40e_pf *pf,
  1044. bool printconfig);
  1045. int i40e_add_del_fdir(struct i40e_vsi *vsi,
  1046. struct i40e_fdir_filter *input, bool add);
  1047. void i40e_fdir_check_and_reenable(struct i40e_pf *pf);
  1048. u32 i40e_get_current_fd_count(struct i40e_pf *pf);
  1049. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf);
  1050. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf);
  1051. u32 i40e_get_global_fd_count(struct i40e_pf *pf);
  1052. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features);
  1053. void i40e_set_ethtool_ops(struct net_device *netdev);
  1054. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1055. const u8 *macaddr, s16 vlan);
  1056. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f);
  1057. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan);
  1058. int i40e_sync_vsi_filters(struct i40e_vsi *vsi);
  1059. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  1060. u16 uplink, u32 param1);
  1061. int i40e_vsi_release(struct i40e_vsi *vsi);
  1062. void i40e_service_event_schedule(struct i40e_pf *pf);
  1063. void i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id,
  1064. u8 *msg, u16 len);
  1065. int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q, bool is_xdp,
  1066. bool enable);
  1067. int i40e_control_wait_rx_q(struct i40e_pf *pf, int pf_q, bool enable);
  1068. int i40e_vsi_start_rings(struct i40e_vsi *vsi);
  1069. void i40e_vsi_stop_rings(struct i40e_vsi *vsi);
  1070. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi);
  1071. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi);
  1072. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count);
  1073. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 uplink_seid,
  1074. u16 downlink_seid, u8 enabled_tc);
  1075. void i40e_veb_release(struct i40e_veb *veb);
  1076. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc);
  1077. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid);
  1078. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi);
  1079. void i40e_vsi_reset_stats(struct i40e_vsi *vsi);
  1080. void i40e_pf_reset_stats(struct i40e_pf *pf);
  1081. #ifdef CONFIG_DEBUG_FS
  1082. void i40e_dbg_pf_init(struct i40e_pf *pf);
  1083. void i40e_dbg_pf_exit(struct i40e_pf *pf);
  1084. void i40e_dbg_init(void);
  1085. void i40e_dbg_exit(void);
  1086. #else
  1087. static inline void i40e_dbg_pf_init(struct i40e_pf *pf) {}
  1088. static inline void i40e_dbg_pf_exit(struct i40e_pf *pf) {}
  1089. static inline void i40e_dbg_init(void) {}
  1090. static inline void i40e_dbg_exit(void) {}
  1091. #endif /* CONFIG_DEBUG_FS*/
  1092. /* needed by client drivers */
  1093. int i40e_lan_add_device(struct i40e_pf *pf);
  1094. int i40e_lan_del_device(struct i40e_pf *pf);
  1095. void i40e_client_subtask(struct i40e_pf *pf);
  1096. void i40e_notify_client_of_l2_param_changes(struct i40e_pf *pf);
  1097. void i40e_notify_client_of_netdev_close(struct i40e_pf *pf, bool reset);
  1098. void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs);
  1099. void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id);
  1100. void i40e_client_update_msix_info(struct i40e_pf *pf);
  1101. int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id);
  1102. /**
  1103. * i40e_irq_dynamic_enable - Enable default interrupt generation settings
  1104. * @vsi: pointer to a vsi
  1105. * @vector: enable a particular Hw Interrupt vector, without base_vector
  1106. **/
  1107. static inline void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
  1108. {
  1109. struct i40e_pf *pf = vsi->back;
  1110. struct i40e_hw *hw = &pf->hw;
  1111. u32 val;
  1112. val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
  1113. I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
  1114. (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  1115. wr32(hw, I40E_PFINT_DYN_CTLN(vector + vsi->base_vector - 1), val);
  1116. /* skip the flush */
  1117. }
  1118. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf);
  1119. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf);
  1120. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  1121. int i40e_open(struct net_device *netdev);
  1122. int i40e_close(struct net_device *netdev);
  1123. int i40e_vsi_open(struct i40e_vsi *vsi);
  1124. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi);
  1125. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid);
  1126. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid);
  1127. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid);
  1128. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid);
  1129. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  1130. const u8 *macaddr);
  1131. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr);
  1132. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi);
  1133. int i40e_count_all_filters(struct i40e_vsi *vsi);
  1134. int i40e_count_active_filters(struct i40e_vsi *vsi);
  1135. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr);
  1136. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi);
  1137. static inline bool i40e_is_sw_dcb(struct i40e_pf *pf)
  1138. {
  1139. return test_bit(I40E_FLAG_FW_LLDP_DIS, pf->flags);
  1140. }
  1141. #ifdef CONFIG_I40E_DCB
  1142. void i40e_dcbnl_flush_apps(struct i40e_pf *pf,
  1143. struct i40e_dcbx_config *old_cfg,
  1144. struct i40e_dcbx_config *new_cfg);
  1145. void i40e_dcbnl_set_all(struct i40e_vsi *vsi);
  1146. void i40e_dcbnl_setup(struct i40e_vsi *vsi);
  1147. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  1148. struct i40e_dcbx_config *old_cfg,
  1149. struct i40e_dcbx_config *new_cfg);
  1150. int i40e_hw_dcb_config(struct i40e_pf *pf, struct i40e_dcbx_config *new_cfg);
  1151. int i40e_dcb_sw_default_config(struct i40e_pf *pf);
  1152. #endif /* CONFIG_I40E_DCB */
  1153. void i40e_ptp_rx_hang(struct i40e_pf *pf);
  1154. void i40e_ptp_tx_hang(struct i40e_pf *pf);
  1155. void i40e_ptp_tx_hwtstamp(struct i40e_pf *pf);
  1156. void i40e_ptp_rx_hwtstamp(struct i40e_pf *pf, struct sk_buff *skb, u8 index);
  1157. void i40e_ptp_set_increment(struct i40e_pf *pf);
  1158. int i40e_ptp_set_ts_config(struct i40e_pf *pf, struct ifreq *ifr);
  1159. int i40e_ptp_get_ts_config(struct i40e_pf *pf, struct ifreq *ifr);
  1160. void i40e_ptp_save_hw_time(struct i40e_pf *pf);
  1161. void i40e_ptp_restore_hw_time(struct i40e_pf *pf);
  1162. void i40e_ptp_init(struct i40e_pf *pf);
  1163. void i40e_ptp_stop(struct i40e_pf *pf);
  1164. int i40e_ptp_alloc_pins(struct i40e_pf *pf);
  1165. int i40e_update_adq_vsi_queues(struct i40e_vsi *vsi, int vsi_offset);
  1166. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi);
  1167. int i40e_get_partition_bw_setting(struct i40e_pf *pf);
  1168. int i40e_set_partition_bw_setting(struct i40e_pf *pf);
  1169. int i40e_commit_partition_bw_setting(struct i40e_pf *pf);
  1170. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup);
  1171. void i40e_set_fec_in_flags(u8 fec_cfg, unsigned long *flags);
  1172. static inline bool i40e_enabled_xdp_vsi(struct i40e_vsi *vsi)
  1173. {
  1174. return !!READ_ONCE(vsi->xdp_prog);
  1175. }
  1176. int i40e_create_queue_channel(struct i40e_vsi *vsi, struct i40e_channel *ch);
  1177. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate);
  1178. int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  1179. struct i40e_cloud_filter *filter,
  1180. bool add);
  1181. int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  1182. struct i40e_cloud_filter *filter,
  1183. bool add);
  1184. /**
  1185. * i40e_is_tc_mqprio_enabled - check if TC MQPRIO is enabled on PF
  1186. * @pf: pointer to a pf.
  1187. *
  1188. * Check and return state of flag I40E_FLAG_TC_MQPRIO.
  1189. *
  1190. * Return: true/false if I40E_FLAG_TC_MQPRIO is set or not
  1191. **/
  1192. static inline bool i40e_is_tc_mqprio_enabled(struct i40e_pf *pf)
  1193. {
  1194. return test_bit(I40E_FLAG_TC_MQPRIO_ENA, pf->flags);
  1195. }
  1196. /**
  1197. * i40e_hw_to_pf - get pf pointer from the hardware structure
  1198. * @hw: pointer to the device HW structure
  1199. **/
  1200. static inline struct i40e_pf *i40e_hw_to_pf(struct i40e_hw *hw)
  1201. {
  1202. return container_of(hw, struct i40e_pf, hw);
  1203. }
  1204. struct device *i40e_hw_to_dev(struct i40e_hw *hw);
  1205. /**
  1206. * i40e_pf_get_vsi_by_seid - find VSI by SEID
  1207. * @pf: pointer to a PF
  1208. * @seid: SEID of the VSI
  1209. **/
  1210. static inline struct i40e_vsi *
  1211. i40e_pf_get_vsi_by_seid(struct i40e_pf *pf, u16 seid)
  1212. {
  1213. struct i40e_vsi *vsi;
  1214. int i;
  1215. i40e_pf_for_each_vsi(pf, i, vsi)
  1216. if (vsi->seid == seid)
  1217. return vsi;
  1218. return NULL;
  1219. }
  1220. /**
  1221. * i40e_pf_get_main_vsi - get pointer to main VSI
  1222. * @pf: pointer to a PF
  1223. *
  1224. * Return: pointer to main VSI or NULL if it does not exist
  1225. **/
  1226. static inline struct i40e_vsi *i40e_pf_get_main_vsi(struct i40e_pf *pf)
  1227. {
  1228. return (pf->lan_vsi != I40E_NO_VSI) ? pf->vsi[pf->lan_vsi] : NULL;
  1229. }
  1230. /**
  1231. * i40e_pf_get_veb_by_seid - find VEB by SEID
  1232. * @pf: pointer to a PF
  1233. * @seid: SEID of the VSI
  1234. **/
  1235. static inline struct i40e_veb *
  1236. i40e_pf_get_veb_by_seid(struct i40e_pf *pf, u16 seid)
  1237. {
  1238. struct i40e_veb *veb;
  1239. int i;
  1240. i40e_pf_for_each_veb(pf, i, veb)
  1241. if (veb->seid == seid)
  1242. return veb;
  1243. return NULL;
  1244. }
  1245. /**
  1246. * i40e_pf_get_main_veb - get pointer to main VEB
  1247. * @pf: pointer to a PF
  1248. *
  1249. * Return: pointer to main VEB or NULL if it does not exist
  1250. **/
  1251. static inline struct i40e_veb *i40e_pf_get_main_veb(struct i40e_pf *pf)
  1252. {
  1253. return (pf->lan_veb != I40E_NO_VEB) ? pf->veb[pf->lan_veb] : NULL;
  1254. }
  1255. #endif /* _I40E_H_ */