i40e.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*******************************************************************************
  3. *
  4. * Intel Ethernet Controller XL710 Family Linux Driver
  5. * Copyright(c) 2013 - 2017 Intel Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. #ifndef _I40E_H_
  28. #define _I40E_H_
  29. #include <net/tcp.h>
  30. #include <net/udp.h>
  31. #include <linux/types.h>
  32. #include <linux/errno.h>
  33. #include <linux/module.h>
  34. #include <linux/pci.h>
  35. #include <linux/aer.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/ioport.h>
  38. #include <linux/iommu.h>
  39. #include <linux/slab.h>
  40. #include <linux/list.h>
  41. #include <linux/hashtable.h>
  42. #include <linux/string.h>
  43. #include <linux/in.h>
  44. #include <linux/ip.h>
  45. #include <linux/sctp.h>
  46. #include <linux/pkt_sched.h>
  47. #include <linux/ipv6.h>
  48. #include <net/checksum.h>
  49. #include <net/ip6_checksum.h>
  50. #include <linux/ethtool.h>
  51. #include <linux/if_vlan.h>
  52. #include <linux/if_bridge.h>
  53. #include <linux/clocksource.h>
  54. #include <linux/net_tstamp.h>
  55. #include <linux/ptp_clock_kernel.h>
  56. #include <net/pkt_cls.h>
  57. #include <net/tc_act/tc_gact.h>
  58. #include <net/tc_act/tc_mirred.h>
  59. #include "i40e_type.h"
  60. #include "i40e_prototype.h"
  61. #include "i40e_client.h"
  62. #include <linux/avf/virtchnl.h>
  63. #include "i40e_virtchnl_pf.h"
  64. #include "i40e_txrx.h"
  65. #include "i40e_dcb.h"
  66. /* Useful i40e defaults */
  67. #define I40E_MAX_VEB 16
  68. #define I40E_MAX_NUM_DESCRIPTORS 4096
  69. #define I40E_MAX_CSR_SPACE (4 * 1024 * 1024 - 64 * 1024)
  70. #define I40E_DEFAULT_NUM_DESCRIPTORS 512
  71. #define I40E_REQ_DESCRIPTOR_MULTIPLE 32
  72. #define I40E_MIN_NUM_DESCRIPTORS 64
  73. #define I40E_MIN_MSIX 2
  74. #define I40E_DEFAULT_NUM_VMDQ_VSI 8 /* max 256 VSIs */
  75. #define I40E_MIN_VSI_ALLOC 83 /* LAN, ATR, FCOE, 64 VF */
  76. /* max 16 qps */
  77. #define i40e_default_queues_per_vmdq(pf) \
  78. (((pf)->hw_features & I40E_HW_RSS_AQ_CAPABLE) ? 4 : 1)
  79. #define I40E_DEFAULT_QUEUES_PER_VF 4
  80. #define I40E_MAX_VF_QUEUES 16
  81. #define I40E_DEFAULT_QUEUES_PER_TC 1 /* should be a power of 2 */
  82. #define i40e_pf_get_max_q_per_tc(pf) \
  83. (((pf)->hw_features & I40E_HW_128_QP_RSS_CAPABLE) ? 128 : 64)
  84. #define I40E_FDIR_RING 0
  85. #define I40E_FDIR_RING_COUNT 32
  86. #define I40E_MAX_AQ_BUF_SIZE 4096
  87. #define I40E_AQ_LEN 256
  88. #define I40E_AQ_WORK_LIMIT 66 /* max number of VFs + a little */
  89. #define I40E_MAX_USER_PRIORITY 8
  90. #define I40E_DEFAULT_TRAFFIC_CLASS BIT(0)
  91. #define I40E_DEFAULT_MSG_ENABLE 4
  92. #define I40E_QUEUE_WAIT_RETRY_LIMIT 10
  93. #define I40E_INT_NAME_STR_LEN (IFNAMSIZ + 16)
  94. #define I40E_NVM_VERSION_LO_SHIFT 0
  95. #define I40E_NVM_VERSION_LO_MASK (0xff << I40E_NVM_VERSION_LO_SHIFT)
  96. #define I40E_NVM_VERSION_HI_SHIFT 12
  97. #define I40E_NVM_VERSION_HI_MASK (0xf << I40E_NVM_VERSION_HI_SHIFT)
  98. #define I40E_OEM_VER_BUILD_MASK 0xffff
  99. #define I40E_OEM_VER_PATCH_MASK 0xff
  100. #define I40E_OEM_VER_BUILD_SHIFT 8
  101. #define I40E_OEM_VER_SHIFT 24
  102. #define I40E_PHY_DEBUG_ALL \
  103. (I40E_AQ_PHY_DEBUG_DISABLE_LINK_FW | \
  104. I40E_AQ_PHY_DEBUG_DISABLE_ALL_LINK_FW)
  105. #define I40E_OEM_EETRACK_ID 0xffffffff
  106. #define I40E_OEM_GEN_SHIFT 24
  107. #define I40E_OEM_SNAP_MASK 0x00ff0000
  108. #define I40E_OEM_SNAP_SHIFT 16
  109. #define I40E_OEM_RELEASE_MASK 0x0000ffff
  110. /* The values in here are decimal coded as hex as is the case in the NVM map*/
  111. #define I40E_CURRENT_NVM_VERSION_HI 0x2
  112. #define I40E_CURRENT_NVM_VERSION_LO 0x40
  113. #define I40E_RX_DESC(R, i) \
  114. (&(((union i40e_32byte_rx_desc *)((R)->desc))[i]))
  115. #define I40E_TX_DESC(R, i) \
  116. (&(((struct i40e_tx_desc *)((R)->desc))[i]))
  117. #define I40E_TX_CTXTDESC(R, i) \
  118. (&(((struct i40e_tx_context_desc *)((R)->desc))[i]))
  119. #define I40E_TX_FDIRDESC(R, i) \
  120. (&(((struct i40e_filter_program_desc *)((R)->desc))[i]))
  121. /* default to trying for four seconds */
  122. #define I40E_TRY_LINK_TIMEOUT (4 * HZ)
  123. /* BW rate limiting */
  124. #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
  125. #define I40E_BW_MBPS_DIVISOR 125000 /* rate / (1000000 / 8) Mbps */
  126. #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* accumulate 4 credits max */
  127. /* driver state flags */
  128. enum i40e_state_t {
  129. __I40E_TESTING,
  130. __I40E_CONFIG_BUSY,
  131. __I40E_CONFIG_DONE,
  132. __I40E_DOWN,
  133. __I40E_SERVICE_SCHED,
  134. __I40E_ADMINQ_EVENT_PENDING,
  135. __I40E_MDD_EVENT_PENDING,
  136. __I40E_VFLR_EVENT_PENDING,
  137. __I40E_RESET_RECOVERY_PENDING,
  138. __I40E_MISC_IRQ_REQUESTED,
  139. __I40E_RESET_INTR_RECEIVED,
  140. __I40E_REINIT_REQUESTED,
  141. __I40E_PF_RESET_REQUESTED,
  142. __I40E_CORE_RESET_REQUESTED,
  143. __I40E_GLOBAL_RESET_REQUESTED,
  144. __I40E_EMP_RESET_REQUESTED,
  145. __I40E_EMP_RESET_INTR_RECEIVED,
  146. __I40E_SUSPENDED,
  147. __I40E_PTP_TX_IN_PROGRESS,
  148. __I40E_BAD_EEPROM,
  149. __I40E_DOWN_REQUESTED,
  150. __I40E_FD_FLUSH_REQUESTED,
  151. __I40E_FD_ATR_AUTO_DISABLED,
  152. __I40E_FD_SB_AUTO_DISABLED,
  153. __I40E_RESET_FAILED,
  154. __I40E_PORT_SUSPENDED,
  155. __I40E_VF_DISABLE,
  156. __I40E_MACVLAN_SYNC_PENDING,
  157. __I40E_UDP_FILTER_SYNC_PENDING,
  158. __I40E_TEMP_LINK_POLLING,
  159. __I40E_CLIENT_SERVICE_REQUESTED,
  160. __I40E_CLIENT_L2_CHANGE,
  161. __I40E_CLIENT_RESET,
  162. /* This must be last as it determines the size of the BITMAP */
  163. __I40E_STATE_SIZE__,
  164. };
  165. #define I40E_PF_RESET_FLAG BIT_ULL(__I40E_PF_RESET_REQUESTED)
  166. /* VSI state flags */
  167. enum i40e_vsi_state_t {
  168. __I40E_VSI_DOWN,
  169. __I40E_VSI_NEEDS_RESTART,
  170. __I40E_VSI_SYNCING_FILTERS,
  171. __I40E_VSI_OVERFLOW_PROMISC,
  172. __I40E_VSI_REINIT_REQUESTED,
  173. __I40E_VSI_DOWN_REQUESTED,
  174. /* This must be last as it determines the size of the BITMAP */
  175. __I40E_VSI_STATE_SIZE__,
  176. };
  177. enum i40e_interrupt_policy {
  178. I40E_INTERRUPT_BEST_CASE,
  179. I40E_INTERRUPT_MEDIUM,
  180. I40E_INTERRUPT_LOWEST
  181. };
  182. struct i40e_lump_tracking {
  183. u16 num_entries;
  184. u16 search_hint;
  185. u16 list[0];
  186. #define I40E_PILE_VALID_BIT 0x8000
  187. #define I40E_IWARP_IRQ_PILE_ID (I40E_PILE_VALID_BIT - 2)
  188. };
  189. #define I40E_DEFAULT_ATR_SAMPLE_RATE 20
  190. #define I40E_FDIR_MAX_RAW_PACKET_SIZE 512
  191. #define I40E_FDIR_BUFFER_FULL_MARGIN 10
  192. #define I40E_FDIR_BUFFER_HEAD_ROOM 32
  193. #define I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR (I40E_FDIR_BUFFER_HEAD_ROOM * 4)
  194. #define I40E_HKEY_ARRAY_SIZE ((I40E_PFQF_HKEY_MAX_INDEX + 1) * 4)
  195. #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
  196. #define I40E_VF_HLUT_ARRAY_SIZE ((I40E_VFQF_HLUT1_MAX_INDEX + 1) * 4)
  197. enum i40e_fd_stat_idx {
  198. I40E_FD_STAT_ATR,
  199. I40E_FD_STAT_SB,
  200. I40E_FD_STAT_ATR_TUNNEL,
  201. I40E_FD_STAT_PF_COUNT
  202. };
  203. #define I40E_FD_STAT_PF_IDX(pf_id) ((pf_id) * I40E_FD_STAT_PF_COUNT)
  204. #define I40E_FD_ATR_STAT_IDX(pf_id) \
  205. (I40E_FD_STAT_PF_IDX(pf_id) + I40E_FD_STAT_ATR)
  206. #define I40E_FD_SB_STAT_IDX(pf_id) \
  207. (I40E_FD_STAT_PF_IDX(pf_id) + I40E_FD_STAT_SB)
  208. #define I40E_FD_ATR_TUNNEL_STAT_IDX(pf_id) \
  209. (I40E_FD_STAT_PF_IDX(pf_id) + I40E_FD_STAT_ATR_TUNNEL)
  210. /* The following structure contains the data parsed from the user-defined
  211. * field of the ethtool_rx_flow_spec structure.
  212. */
  213. struct i40e_rx_flow_userdef {
  214. bool flex_filter;
  215. u16 flex_word;
  216. u16 flex_offset;
  217. };
  218. struct i40e_fdir_filter {
  219. struct hlist_node fdir_node;
  220. /* filter ipnut set */
  221. u8 flow_type;
  222. u8 ip4_proto;
  223. /* TX packet view of src and dst */
  224. __be32 dst_ip;
  225. __be32 src_ip;
  226. __be16 src_port;
  227. __be16 dst_port;
  228. __be32 sctp_v_tag;
  229. /* Flexible data to match within the packet payload */
  230. __be16 flex_word;
  231. u16 flex_offset;
  232. bool flex_filter;
  233. /* filter control */
  234. u16 q_index;
  235. u8 flex_off;
  236. u8 pctype;
  237. u16 dest_vsi;
  238. u8 dest_ctl;
  239. u8 fd_status;
  240. u16 cnt_index;
  241. u32 fd_id;
  242. };
  243. #define I40E_CLOUD_FIELD_OMAC 0x01
  244. #define I40E_CLOUD_FIELD_IMAC 0x02
  245. #define I40E_CLOUD_FIELD_IVLAN 0x04
  246. #define I40E_CLOUD_FIELD_TEN_ID 0x08
  247. #define I40E_CLOUD_FIELD_IIP 0x10
  248. #define I40E_CLOUD_FILTER_FLAGS_OMAC I40E_CLOUD_FIELD_OMAC
  249. #define I40E_CLOUD_FILTER_FLAGS_IMAC I40E_CLOUD_FIELD_IMAC
  250. #define I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN (I40E_CLOUD_FIELD_IMAC | \
  251. I40E_CLOUD_FIELD_IVLAN)
  252. #define I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID (I40E_CLOUD_FIELD_IMAC | \
  253. I40E_CLOUD_FIELD_TEN_ID)
  254. #define I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC (I40E_CLOUD_FIELD_OMAC | \
  255. I40E_CLOUD_FIELD_IMAC | \
  256. I40E_CLOUD_FIELD_TEN_ID)
  257. #define I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID (I40E_CLOUD_FIELD_IMAC | \
  258. I40E_CLOUD_FIELD_IVLAN | \
  259. I40E_CLOUD_FIELD_TEN_ID)
  260. #define I40E_CLOUD_FILTER_FLAGS_IIP I40E_CLOUD_FIELD_IIP
  261. struct i40e_cloud_filter {
  262. struct hlist_node cloud_node;
  263. unsigned long cookie;
  264. /* cloud filter input set follows */
  265. u8 dst_mac[ETH_ALEN];
  266. u8 src_mac[ETH_ALEN];
  267. __be16 vlan_id;
  268. u16 seid; /* filter control */
  269. __be16 dst_port;
  270. __be16 src_port;
  271. u32 tenant_id;
  272. union {
  273. struct {
  274. struct in_addr dst_ip;
  275. struct in_addr src_ip;
  276. } v4;
  277. struct {
  278. struct in6_addr dst_ip6;
  279. struct in6_addr src_ip6;
  280. } v6;
  281. } ip;
  282. #define dst_ipv6 ip.v6.dst_ip6.s6_addr32
  283. #define src_ipv6 ip.v6.src_ip6.s6_addr32
  284. #define dst_ipv4 ip.v4.dst_ip.s_addr
  285. #define src_ipv4 ip.v4.src_ip.s_addr
  286. u16 n_proto; /* Ethernet Protocol */
  287. u8 ip_proto; /* IPPROTO value */
  288. u8 flags;
  289. #define I40E_CLOUD_TNL_TYPE_NONE 0xff
  290. u8 tunnel_type;
  291. };
  292. #define I40E_ETH_P_LLDP 0x88cc
  293. #define I40E_DCB_PRIO_TYPE_STRICT 0
  294. #define I40E_DCB_PRIO_TYPE_ETS 1
  295. #define I40E_DCB_STRICT_PRIO_CREDITS 127
  296. /* DCB per TC information data structure */
  297. struct i40e_tc_info {
  298. u16 qoffset; /* Queue offset from base queue */
  299. u16 qcount; /* Total Queues */
  300. u8 netdev_tc; /* Netdev TC index if netdev associated */
  301. };
  302. /* TC configuration data structure */
  303. struct i40e_tc_configuration {
  304. u8 numtc; /* Total number of enabled TCs */
  305. u8 enabled_tc; /* TC map */
  306. struct i40e_tc_info tc_info[I40E_MAX_TRAFFIC_CLASS];
  307. };
  308. struct i40e_udp_port_config {
  309. /* AdminQ command interface expects port number in Host byte order */
  310. u16 port;
  311. u8 type;
  312. };
  313. /* macros related to FLX_PIT */
  314. #define I40E_FLEX_SET_FSIZE(fsize) (((fsize) << \
  315. I40E_PRTQF_FLX_PIT_FSIZE_SHIFT) & \
  316. I40E_PRTQF_FLX_PIT_FSIZE_MASK)
  317. #define I40E_FLEX_SET_DST_WORD(dst) (((dst) << \
  318. I40E_PRTQF_FLX_PIT_DEST_OFF_SHIFT) & \
  319. I40E_PRTQF_FLX_PIT_DEST_OFF_MASK)
  320. #define I40E_FLEX_SET_SRC_WORD(src) (((src) << \
  321. I40E_PRTQF_FLX_PIT_SOURCE_OFF_SHIFT) & \
  322. I40E_PRTQF_FLX_PIT_SOURCE_OFF_MASK)
  323. #define I40E_FLEX_PREP_VAL(dst, fsize, src) (I40E_FLEX_SET_DST_WORD(dst) | \
  324. I40E_FLEX_SET_FSIZE(fsize) | \
  325. I40E_FLEX_SET_SRC_WORD(src))
  326. #define I40E_FLEX_PIT_GET_SRC(flex) (((flex) & \
  327. I40E_PRTQF_FLX_PIT_SOURCE_OFF_MASK) >> \
  328. I40E_PRTQF_FLX_PIT_SOURCE_OFF_SHIFT)
  329. #define I40E_FLEX_PIT_GET_DST(flex) (((flex) & \
  330. I40E_PRTQF_FLX_PIT_DEST_OFF_MASK) >> \
  331. I40E_PRTQF_FLX_PIT_DEST_OFF_SHIFT)
  332. #define I40E_FLEX_PIT_GET_FSIZE(flex) (((flex) & \
  333. I40E_PRTQF_FLX_PIT_FSIZE_MASK) >> \
  334. I40E_PRTQF_FLX_PIT_FSIZE_SHIFT)
  335. #define I40E_MAX_FLEX_SRC_OFFSET 0x1F
  336. /* macros related to GLQF_ORT */
  337. #define I40E_ORT_SET_IDX(idx) (((idx) << \
  338. I40E_GLQF_ORT_PIT_INDX_SHIFT) & \
  339. I40E_GLQF_ORT_PIT_INDX_MASK)
  340. #define I40E_ORT_SET_COUNT(count) (((count) << \
  341. I40E_GLQF_ORT_FIELD_CNT_SHIFT) & \
  342. I40E_GLQF_ORT_FIELD_CNT_MASK)
  343. #define I40E_ORT_SET_PAYLOAD(payload) (((payload) << \
  344. I40E_GLQF_ORT_FLX_PAYLOAD_SHIFT) & \
  345. I40E_GLQF_ORT_FLX_PAYLOAD_MASK)
  346. #define I40E_ORT_PREP_VAL(idx, count, payload) (I40E_ORT_SET_IDX(idx) | \
  347. I40E_ORT_SET_COUNT(count) | \
  348. I40E_ORT_SET_PAYLOAD(payload))
  349. #define I40E_L3_GLQF_ORT_IDX 34
  350. #define I40E_L4_GLQF_ORT_IDX 35
  351. /* Flex PIT register index */
  352. #define I40E_FLEX_PIT_IDX_START_L2 0
  353. #define I40E_FLEX_PIT_IDX_START_L3 3
  354. #define I40E_FLEX_PIT_IDX_START_L4 6
  355. #define I40E_FLEX_PIT_TABLE_SIZE 3
  356. #define I40E_FLEX_DEST_UNUSED 63
  357. #define I40E_FLEX_INDEX_ENTRIES 8
  358. /* Flex MASK to disable all flexible entries */
  359. #define I40E_FLEX_INPUT_MASK (I40E_FLEX_50_MASK | I40E_FLEX_51_MASK | \
  360. I40E_FLEX_52_MASK | I40E_FLEX_53_MASK | \
  361. I40E_FLEX_54_MASK | I40E_FLEX_55_MASK | \
  362. I40E_FLEX_56_MASK | I40E_FLEX_57_MASK)
  363. struct i40e_flex_pit {
  364. struct list_head list;
  365. u16 src_offset;
  366. u8 pit_index;
  367. };
  368. struct i40e_channel {
  369. struct list_head list;
  370. bool initialized;
  371. u8 type;
  372. u16 vsi_number; /* Assigned VSI number from AQ 'Add VSI' response */
  373. u16 stat_counter_idx;
  374. u16 base_queue;
  375. u16 num_queue_pairs; /* Requested by user */
  376. u16 seid;
  377. u8 enabled_tc;
  378. struct i40e_aqc_vsi_properties_data info;
  379. u64 max_tx_rate;
  380. /* track this channel belongs to which VSI */
  381. struct i40e_vsi *parent_vsi;
  382. };
  383. /* struct that defines the Ethernet device */
  384. struct i40e_pf {
  385. struct pci_dev *pdev;
  386. struct i40e_hw hw;
  387. DECLARE_BITMAP(state, __I40E_STATE_SIZE__);
  388. struct msix_entry *msix_entries;
  389. bool fc_autoneg_status;
  390. u16 eeprom_version;
  391. u16 num_vmdq_vsis; /* num vmdq vsis this PF has set up */
  392. u16 num_vmdq_qps; /* num queue pairs per vmdq pool */
  393. u16 num_vmdq_msix; /* num queue vectors per vmdq pool */
  394. u16 num_req_vfs; /* num VFs requested for this PF */
  395. u16 num_vf_qps; /* num queue pairs per VF */
  396. u16 num_lan_qps; /* num lan queues this PF has set up */
  397. u16 num_lan_msix; /* num queue vectors for the base PF vsi */
  398. u16 num_fdsb_msix; /* num queue vectors for sideband Fdir */
  399. u16 num_iwarp_msix; /* num of iwarp vectors for this PF */
  400. int iwarp_base_vector;
  401. int queues_left; /* queues left unclaimed */
  402. u16 alloc_rss_size; /* allocated RSS queues */
  403. u16 rss_size_max; /* HW defined max RSS queues */
  404. u16 fdir_pf_filter_count; /* num of guaranteed filters for this PF */
  405. u16 num_alloc_vsi; /* num VSIs this driver supports */
  406. u8 atr_sample_rate;
  407. bool wol_en;
  408. struct hlist_head fdir_filter_list;
  409. u16 fdir_pf_active_filters;
  410. unsigned long fd_flush_timestamp;
  411. u32 fd_flush_cnt;
  412. u32 fd_add_err;
  413. u32 fd_atr_cnt;
  414. /* Book-keeping of side-band filter count per flow-type.
  415. * This is used to detect and handle input set changes for
  416. * respective flow-type.
  417. */
  418. u16 fd_tcp4_filter_cnt;
  419. u16 fd_udp4_filter_cnt;
  420. u16 fd_sctp4_filter_cnt;
  421. u16 fd_ip4_filter_cnt;
  422. /* Flexible filter table values that need to be programmed into
  423. * hardware, which expects L3 and L4 to be programmed separately. We
  424. * need to ensure that the values are in ascended order and don't have
  425. * duplicates, so we track each L3 and L4 values in separate lists.
  426. */
  427. struct list_head l3_flex_pit_list;
  428. struct list_head l4_flex_pit_list;
  429. struct i40e_udp_port_config udp_ports[I40E_MAX_PF_UDP_OFFLOAD_PORTS];
  430. u16 pending_udp_bitmap;
  431. struct hlist_head cloud_filter_list;
  432. u16 num_cloud_filters;
  433. enum i40e_interrupt_policy int_policy;
  434. u16 rx_itr_default;
  435. u16 tx_itr_default;
  436. u32 msg_enable;
  437. char int_name[I40E_INT_NAME_STR_LEN];
  438. u16 adminq_work_limit; /* num of admin receive queue desc to process */
  439. unsigned long service_timer_period;
  440. unsigned long service_timer_previous;
  441. struct timer_list service_timer;
  442. struct work_struct service_task;
  443. u32 hw_features;
  444. #define I40E_HW_RSS_AQ_CAPABLE BIT(0)
  445. #define I40E_HW_128_QP_RSS_CAPABLE BIT(1)
  446. #define I40E_HW_ATR_EVICT_CAPABLE BIT(2)
  447. #define I40E_HW_WB_ON_ITR_CAPABLE BIT(3)
  448. #define I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE BIT(4)
  449. #define I40E_HW_NO_PCI_LINK_CHECK BIT(5)
  450. #define I40E_HW_100M_SGMII_CAPABLE BIT(6)
  451. #define I40E_HW_NO_DCB_SUPPORT BIT(7)
  452. #define I40E_HW_USE_SET_LLDP_MIB BIT(8)
  453. #define I40E_HW_GENEVE_OFFLOAD_CAPABLE BIT(9)
  454. #define I40E_HW_PTP_L4_CAPABLE BIT(10)
  455. #define I40E_HW_WOL_MC_MAGIC_PKT_WAKE BIT(11)
  456. #define I40E_HW_MPLS_HDR_OFFLOAD_CAPABLE BIT(12)
  457. #define I40E_HW_HAVE_CRT_RETIMER BIT(13)
  458. #define I40E_HW_OUTER_UDP_CSUM_CAPABLE BIT(14)
  459. #define I40E_HW_PHY_CONTROLS_LEDS BIT(15)
  460. #define I40E_HW_STOP_FW_LLDP BIT(16)
  461. #define I40E_HW_PORT_ID_VALID BIT(17)
  462. #define I40E_HW_RESTART_AUTONEG BIT(18)
  463. #define I40E_HW_STOPPABLE_FW_LLDP BIT(19)
  464. u32 flags;
  465. #define I40E_FLAG_RX_CSUM_ENABLED BIT(0)
  466. #define I40E_FLAG_MSI_ENABLED BIT(1)
  467. #define I40E_FLAG_MSIX_ENABLED BIT(2)
  468. #define I40E_FLAG_RSS_ENABLED BIT(3)
  469. #define I40E_FLAG_VMDQ_ENABLED BIT(4)
  470. #define I40E_FLAG_SRIOV_ENABLED BIT(5)
  471. #define I40E_FLAG_DCB_CAPABLE BIT(6)
  472. #define I40E_FLAG_DCB_ENABLED BIT(7)
  473. #define I40E_FLAG_FD_SB_ENABLED BIT(8)
  474. #define I40E_FLAG_FD_ATR_ENABLED BIT(9)
  475. #define I40E_FLAG_MFP_ENABLED BIT(10)
  476. #define I40E_FLAG_HW_ATR_EVICT_ENABLED BIT(11)
  477. #define I40E_FLAG_VEB_MODE_ENABLED BIT(12)
  478. #define I40E_FLAG_VEB_STATS_ENABLED BIT(13)
  479. #define I40E_FLAG_LINK_POLLING_ENABLED BIT(14)
  480. #define I40E_FLAG_TRUE_PROMISC_SUPPORT BIT(15)
  481. #define I40E_FLAG_LEGACY_RX BIT(16)
  482. #define I40E_FLAG_PTP BIT(17)
  483. #define I40E_FLAG_IWARP_ENABLED BIT(18)
  484. #define I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED BIT(19)
  485. #define I40E_FLAG_SOURCE_PRUNING_DISABLED BIT(20)
  486. #define I40E_FLAG_TC_MQPRIO BIT(21)
  487. #define I40E_FLAG_FD_SB_INACTIVE BIT(22)
  488. #define I40E_FLAG_FD_SB_TO_CLOUD_FILTER BIT(23)
  489. #define I40E_FLAG_DISABLE_FW_LLDP BIT(24)
  490. struct i40e_client_instance *cinst;
  491. bool stat_offsets_loaded;
  492. struct i40e_hw_port_stats stats;
  493. struct i40e_hw_port_stats stats_offsets;
  494. u32 tx_timeout_count;
  495. u32 tx_timeout_recovery_level;
  496. unsigned long tx_timeout_last_recovery;
  497. u32 tx_sluggish_count;
  498. u32 hw_csum_rx_error;
  499. u32 led_status;
  500. u16 corer_count; /* Core reset count */
  501. u16 globr_count; /* Global reset count */
  502. u16 empr_count; /* EMP reset count */
  503. u16 pfr_count; /* PF reset count */
  504. u16 sw_int_count; /* SW interrupt count */
  505. struct mutex switch_mutex;
  506. u16 lan_vsi; /* our default LAN VSI */
  507. u16 lan_veb; /* initial relay, if exists */
  508. #define I40E_NO_VEB 0xffff
  509. #define I40E_NO_VSI 0xffff
  510. u16 next_vsi; /* Next unallocated VSI - 0-based! */
  511. struct i40e_vsi **vsi;
  512. struct i40e_veb *veb[I40E_MAX_VEB];
  513. struct i40e_lump_tracking *qp_pile;
  514. struct i40e_lump_tracking *irq_pile;
  515. /* switch config info */
  516. u16 pf_seid;
  517. u16 main_vsi_seid;
  518. u16 mac_seid;
  519. struct kobject *switch_kobj;
  520. #ifdef CONFIG_DEBUG_FS
  521. struct dentry *i40e_dbg_pf;
  522. #endif /* CONFIG_DEBUG_FS */
  523. bool cur_promisc;
  524. u16 instance; /* A unique number per i40e_pf instance in the system */
  525. /* sr-iov config info */
  526. struct i40e_vf *vf;
  527. int num_alloc_vfs; /* actual number of VFs allocated */
  528. u32 vf_aq_requests;
  529. u32 arq_overflows; /* Not fatal, possibly indicative of problems */
  530. /* DCBx/DCBNL capability for PF that indicates
  531. * whether DCBx is managed by firmware or host
  532. * based agent (LLDPAD). Also, indicates what
  533. * flavor of DCBx protocol (IEEE/CEE) is supported
  534. * by the device. For now we're supporting IEEE
  535. * mode only.
  536. */
  537. u16 dcbx_cap;
  538. struct i40e_filter_control_settings filter_settings;
  539. struct ptp_clock *ptp_clock;
  540. struct ptp_clock_info ptp_caps;
  541. struct sk_buff *ptp_tx_skb;
  542. unsigned long ptp_tx_start;
  543. struct hwtstamp_config tstamp_config;
  544. struct mutex tmreg_lock; /* Used to protect the SYSTIME registers. */
  545. u64 ptp_base_adj;
  546. u32 tx_hwtstamp_timeouts;
  547. u32 tx_hwtstamp_skipped;
  548. u32 rx_hwtstamp_cleared;
  549. u32 latch_event_flags;
  550. spinlock_t ptp_rx_lock; /* Used to protect Rx timestamp registers. */
  551. unsigned long latch_events[4];
  552. bool ptp_tx;
  553. bool ptp_rx;
  554. u16 rss_table_size; /* HW RSS table size */
  555. u32 max_bw;
  556. u32 min_bw;
  557. u32 ioremap_len;
  558. u32 fd_inv;
  559. u16 phy_led_val;
  560. u16 override_q_count;
  561. u16 last_sw_conf_flags;
  562. u16 last_sw_conf_valid_flags;
  563. };
  564. /**
  565. * i40e_mac_to_hkey - Convert a 6-byte MAC Address to a u64 hash key
  566. * @macaddr: the MAC Address as the base key
  567. *
  568. * Simply copies the address and returns it as a u64 for hashing
  569. **/
  570. static inline u64 i40e_addr_to_hkey(const u8 *macaddr)
  571. {
  572. u64 key = 0;
  573. ether_addr_copy((u8 *)&key, macaddr);
  574. return key;
  575. }
  576. enum i40e_filter_state {
  577. I40E_FILTER_INVALID = 0, /* Invalid state */
  578. I40E_FILTER_NEW, /* New, not sent to FW yet */
  579. I40E_FILTER_ACTIVE, /* Added to switch by FW */
  580. I40E_FILTER_FAILED, /* Rejected by FW */
  581. I40E_FILTER_REMOVE, /* To be removed */
  582. /* There is no 'removed' state; the filter struct is freed */
  583. };
  584. struct i40e_mac_filter {
  585. struct hlist_node hlist;
  586. u8 macaddr[ETH_ALEN];
  587. #define I40E_VLAN_ANY -1
  588. s16 vlan;
  589. enum i40e_filter_state state;
  590. };
  591. /* Wrapper structure to keep track of filters while we are preparing to send
  592. * firmware commands. We cannot send firmware commands while holding a
  593. * spinlock, since it might sleep. To avoid this, we wrap the added filters in
  594. * a separate structure, which will track the state change and update the real
  595. * filter while under lock. We can't simply hold the filters in a separate
  596. * list, as this opens a window for a race condition when adding new MAC
  597. * addresses to all VLANs, or when adding new VLANs to all MAC addresses.
  598. */
  599. struct i40e_new_mac_filter {
  600. struct hlist_node hlist;
  601. struct i40e_mac_filter *f;
  602. /* Track future changes to state separately */
  603. enum i40e_filter_state state;
  604. };
  605. struct i40e_veb {
  606. struct i40e_pf *pf;
  607. u16 idx;
  608. u16 veb_idx; /* index of VEB parent */
  609. u16 seid;
  610. u16 uplink_seid;
  611. u16 stats_idx; /* index of VEB parent */
  612. u8 enabled_tc;
  613. u16 bridge_mode; /* Bridge Mode (VEB/VEPA) */
  614. u16 flags;
  615. u16 bw_limit;
  616. u8 bw_max_quanta;
  617. bool is_abs_credits;
  618. u8 bw_tc_share_credits[I40E_MAX_TRAFFIC_CLASS];
  619. u16 bw_tc_limit_credits[I40E_MAX_TRAFFIC_CLASS];
  620. u8 bw_tc_max_quanta[I40E_MAX_TRAFFIC_CLASS];
  621. struct kobject *kobj;
  622. bool stat_offsets_loaded;
  623. struct i40e_eth_stats stats;
  624. struct i40e_eth_stats stats_offsets;
  625. struct i40e_veb_tc_stats tc_stats;
  626. struct i40e_veb_tc_stats tc_stats_offsets;
  627. };
  628. /* struct that defines a VSI, associated with a dev */
  629. struct i40e_vsi {
  630. struct net_device *netdev;
  631. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  632. bool netdev_registered;
  633. bool stat_offsets_loaded;
  634. u32 current_netdev_flags;
  635. DECLARE_BITMAP(state, __I40E_VSI_STATE_SIZE__);
  636. #define I40E_VSI_FLAG_FILTER_CHANGED BIT(0)
  637. #define I40E_VSI_FLAG_VEB_OWNER BIT(1)
  638. unsigned long flags;
  639. /* Per VSI lock to protect elements/hash (MAC filter) */
  640. spinlock_t mac_filter_hash_lock;
  641. /* Fixed size hash table with 2^8 buckets for MAC filters */
  642. DECLARE_HASHTABLE(mac_filter_hash, 8);
  643. bool has_vlan_filter;
  644. /* VSI stats */
  645. struct rtnl_link_stats64 net_stats;
  646. struct rtnl_link_stats64 net_stats_offsets;
  647. struct i40e_eth_stats eth_stats;
  648. struct i40e_eth_stats eth_stats_offsets;
  649. u32 tx_restart;
  650. u32 tx_busy;
  651. u64 tx_linearize;
  652. u64 tx_force_wb;
  653. u32 rx_buf_failed;
  654. u32 rx_page_failed;
  655. /* These are containers of ring pointers, allocated at run-time */
  656. struct i40e_ring **rx_rings;
  657. struct i40e_ring **tx_rings;
  658. struct i40e_ring **xdp_rings; /* XDP Tx rings */
  659. u32 active_filters;
  660. u32 promisc_threshold;
  661. u16 work_limit;
  662. u16 int_rate_limit; /* value in usecs */
  663. u16 rss_table_size; /* HW RSS table size */
  664. u16 rss_size; /* Allocated RSS queues */
  665. u8 *rss_hkey_user; /* User configured hash keys */
  666. u8 *rss_lut_user; /* User configured lookup table entries */
  667. u16 max_frame;
  668. u16 rx_buf_len;
  669. struct bpf_prog *xdp_prog;
  670. /* List of q_vectors allocated to this VSI */
  671. struct i40e_q_vector **q_vectors;
  672. int num_q_vectors;
  673. int base_vector;
  674. bool irqs_ready;
  675. u16 seid; /* HW index of this VSI (absolute index) */
  676. u16 id; /* VSI number */
  677. u16 uplink_seid;
  678. u16 base_queue; /* vsi's first queue in hw array */
  679. u16 alloc_queue_pairs; /* Allocated Tx/Rx queues */
  680. u16 req_queue_pairs; /* User requested queue pairs */
  681. u16 num_queue_pairs; /* Used tx and rx pairs */
  682. u16 num_desc;
  683. enum i40e_vsi_type type; /* VSI type, e.g., LAN, FCoE, etc */
  684. s16 vf_id; /* Virtual function ID for SRIOV VSIs */
  685. struct tc_mqprio_qopt_offload mqprio_qopt; /* queue parameters */
  686. struct i40e_tc_configuration tc_config;
  687. struct i40e_aqc_vsi_properties_data info;
  688. /* VSI BW limit (absolute across all TCs) */
  689. u16 bw_limit; /* VSI BW Limit (0 = disabled) */
  690. u8 bw_max_quanta; /* Max Quanta when BW limit is enabled */
  691. /* Relative TC credits across VSIs */
  692. u8 bw_ets_share_credits[I40E_MAX_TRAFFIC_CLASS];
  693. /* TC BW limit credits within VSI */
  694. u16 bw_ets_limit_credits[I40E_MAX_TRAFFIC_CLASS];
  695. /* TC BW limit max quanta within VSI */
  696. u8 bw_ets_max_quanta[I40E_MAX_TRAFFIC_CLASS];
  697. struct i40e_pf *back; /* Backreference to associated PF */
  698. u16 idx; /* index in pf->vsi[] */
  699. u16 veb_idx; /* index of VEB parent */
  700. struct kobject *kobj; /* sysfs object */
  701. bool current_isup; /* Sync 'link up' logging */
  702. enum i40e_aq_link_speed current_speed; /* Sync link speed logging */
  703. /* channel specific fields */
  704. u16 cnt_q_avail; /* num of queues available for channel usage */
  705. u16 orig_rss_size;
  706. u16 current_rss_size;
  707. bool reconfig_rss;
  708. u16 next_base_queue; /* next queue to be used for channel setup */
  709. struct list_head ch_list;
  710. u16 tc_seid_map[I40E_MAX_TRAFFIC_CLASS];
  711. void *priv; /* client driver data reference. */
  712. /* VSI specific handlers */
  713. irqreturn_t (*irq_handler)(int irq, void *data);
  714. } ____cacheline_internodealigned_in_smp;
  715. struct i40e_netdev_priv {
  716. struct i40e_vsi *vsi;
  717. };
  718. /* struct that defines an interrupt vector */
  719. struct i40e_q_vector {
  720. struct i40e_vsi *vsi;
  721. u16 v_idx; /* index in the vsi->q_vector array. */
  722. u16 reg_idx; /* register index of the interrupt */
  723. struct napi_struct napi;
  724. struct i40e_ring_container rx;
  725. struct i40e_ring_container tx;
  726. u8 itr_countdown; /* when 0 should adjust adaptive ITR */
  727. u8 num_ringpairs; /* total number of ring pairs in vector */
  728. cpumask_t affinity_mask;
  729. struct irq_affinity_notify affinity_notify;
  730. struct rcu_head rcu; /* to avoid race with update stats on free */
  731. char name[I40E_INT_NAME_STR_LEN];
  732. bool arm_wb_state;
  733. } ____cacheline_internodealigned_in_smp;
  734. /* lan device */
  735. struct i40e_device {
  736. struct list_head list;
  737. struct i40e_pf *pf;
  738. };
  739. /**
  740. * i40e_nvm_version_str - format the NVM version strings
  741. * @hw: ptr to the hardware info
  742. **/
  743. static inline char *i40e_nvm_version_str(struct i40e_hw *hw)
  744. {
  745. static char buf[32];
  746. u32 full_ver;
  747. full_ver = hw->nvm.oem_ver;
  748. if (hw->nvm.eetrack == I40E_OEM_EETRACK_ID) {
  749. u8 gen, snap;
  750. u16 release;
  751. gen = (u8)(full_ver >> I40E_OEM_GEN_SHIFT);
  752. snap = (u8)((full_ver & I40E_OEM_SNAP_MASK) >>
  753. I40E_OEM_SNAP_SHIFT);
  754. release = (u16)(full_ver & I40E_OEM_RELEASE_MASK);
  755. snprintf(buf, sizeof(buf), "%x.%x.%x", gen, snap, release);
  756. } else {
  757. u8 ver, patch;
  758. u16 build;
  759. ver = (u8)(full_ver >> I40E_OEM_VER_SHIFT);
  760. build = (u16)((full_ver >> I40E_OEM_VER_BUILD_SHIFT) &
  761. I40E_OEM_VER_BUILD_MASK);
  762. patch = (u8)(full_ver & I40E_OEM_VER_PATCH_MASK);
  763. snprintf(buf, sizeof(buf),
  764. "%x.%02x 0x%x %d.%d.%d",
  765. (hw->nvm.version & I40E_NVM_VERSION_HI_MASK) >>
  766. I40E_NVM_VERSION_HI_SHIFT,
  767. (hw->nvm.version & I40E_NVM_VERSION_LO_MASK) >>
  768. I40E_NVM_VERSION_LO_SHIFT,
  769. hw->nvm.eetrack, ver, build, patch);
  770. }
  771. return buf;
  772. }
  773. /**
  774. * i40e_netdev_to_pf: Retrieve the PF struct for given netdev
  775. * @netdev: the corresponding netdev
  776. *
  777. * Return the PF struct for the given netdev
  778. **/
  779. static inline struct i40e_pf *i40e_netdev_to_pf(struct net_device *netdev)
  780. {
  781. struct i40e_netdev_priv *np = netdev_priv(netdev);
  782. struct i40e_vsi *vsi = np->vsi;
  783. return vsi->back;
  784. }
  785. static inline void i40e_vsi_setup_irqhandler(struct i40e_vsi *vsi,
  786. irqreturn_t (*irq_handler)(int, void *))
  787. {
  788. vsi->irq_handler = irq_handler;
  789. }
  790. /**
  791. * i40e_get_fd_cnt_all - get the total FD filter space available
  792. * @pf: pointer to the PF struct
  793. **/
  794. static inline int i40e_get_fd_cnt_all(struct i40e_pf *pf)
  795. {
  796. return pf->hw.fdir_shared_filter_count + pf->fdir_pf_filter_count;
  797. }
  798. /**
  799. * i40e_read_fd_input_set - reads value of flow director input set register
  800. * @pf: pointer to the PF struct
  801. * @addr: register addr
  802. *
  803. * This function reads value of flow director input set register
  804. * specified by 'addr' (which is specific to flow-type)
  805. **/
  806. static inline u64 i40e_read_fd_input_set(struct i40e_pf *pf, u16 addr)
  807. {
  808. u64 val;
  809. val = i40e_read_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 1));
  810. val <<= 32;
  811. val += i40e_read_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 0));
  812. return val;
  813. }
  814. /**
  815. * i40e_write_fd_input_set - writes value into flow director input set register
  816. * @pf: pointer to the PF struct
  817. * @addr: register addr
  818. * @val: value to be written
  819. *
  820. * This function writes specified value to the register specified by 'addr'.
  821. * This register is input set register based on flow-type.
  822. **/
  823. static inline void i40e_write_fd_input_set(struct i40e_pf *pf,
  824. u16 addr, u64 val)
  825. {
  826. i40e_write_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 1),
  827. (u32)(val >> 32));
  828. i40e_write_rx_ctl(&pf->hw, I40E_PRTQF_FD_INSET(addr, 0),
  829. (u32)(val & 0xFFFFFFFFULL));
  830. }
  831. /* needed by i40e_ethtool.c */
  832. int i40e_up(struct i40e_vsi *vsi);
  833. void i40e_down(struct i40e_vsi *vsi);
  834. extern const char i40e_driver_name[];
  835. extern const char i40e_driver_version_str[];
  836. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags);
  837. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired);
  838. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  839. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  840. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  841. u16 rss_table_size, u16 rss_size);
  842. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id);
  843. /**
  844. * i40e_find_vsi_by_type - Find and return Flow Director VSI
  845. * @pf: PF to search for VSI
  846. * @type: Value indicating type of VSI we are looking for
  847. **/
  848. static inline struct i40e_vsi *
  849. i40e_find_vsi_by_type(struct i40e_pf *pf, u16 type)
  850. {
  851. int i;
  852. for (i = 0; i < pf->num_alloc_vsi; i++) {
  853. struct i40e_vsi *vsi = pf->vsi[i];
  854. if (vsi && vsi->type == type)
  855. return vsi;
  856. }
  857. return NULL;
  858. }
  859. void i40e_update_stats(struct i40e_vsi *vsi);
  860. void i40e_update_eth_stats(struct i40e_vsi *vsi);
  861. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi);
  862. int i40e_fetch_switch_configuration(struct i40e_pf *pf,
  863. bool printconfig);
  864. int i40e_add_del_fdir(struct i40e_vsi *vsi,
  865. struct i40e_fdir_filter *input, bool add);
  866. void i40e_fdir_check_and_reenable(struct i40e_pf *pf);
  867. u32 i40e_get_current_fd_count(struct i40e_pf *pf);
  868. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf);
  869. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf);
  870. u32 i40e_get_global_fd_count(struct i40e_pf *pf);
  871. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features);
  872. void i40e_set_ethtool_ops(struct net_device *netdev);
  873. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  874. const u8 *macaddr, s16 vlan);
  875. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f);
  876. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan);
  877. int i40e_sync_vsi_filters(struct i40e_vsi *vsi);
  878. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  879. u16 uplink, u32 param1);
  880. int i40e_vsi_release(struct i40e_vsi *vsi);
  881. void i40e_service_event_schedule(struct i40e_pf *pf);
  882. void i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id,
  883. u8 *msg, u16 len);
  884. int i40e_vsi_start_rings(struct i40e_vsi *vsi);
  885. void i40e_vsi_stop_rings(struct i40e_vsi *vsi);
  886. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi);
  887. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi);
  888. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count);
  889. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, u16 uplink_seid,
  890. u16 downlink_seid, u8 enabled_tc);
  891. void i40e_veb_release(struct i40e_veb *veb);
  892. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc);
  893. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid);
  894. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi);
  895. void i40e_vsi_reset_stats(struct i40e_vsi *vsi);
  896. void i40e_pf_reset_stats(struct i40e_pf *pf);
  897. #ifdef CONFIG_DEBUG_FS
  898. void i40e_dbg_pf_init(struct i40e_pf *pf);
  899. void i40e_dbg_pf_exit(struct i40e_pf *pf);
  900. void i40e_dbg_init(void);
  901. void i40e_dbg_exit(void);
  902. #else
  903. static inline void i40e_dbg_pf_init(struct i40e_pf *pf) {}
  904. static inline void i40e_dbg_pf_exit(struct i40e_pf *pf) {}
  905. static inline void i40e_dbg_init(void) {}
  906. static inline void i40e_dbg_exit(void) {}
  907. #endif /* CONFIG_DEBUG_FS*/
  908. /* needed by client drivers */
  909. int i40e_lan_add_device(struct i40e_pf *pf);
  910. int i40e_lan_del_device(struct i40e_pf *pf);
  911. void i40e_client_subtask(struct i40e_pf *pf);
  912. void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi);
  913. void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset);
  914. void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs);
  915. void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id);
  916. void i40e_client_update_msix_info(struct i40e_pf *pf);
  917. int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id);
  918. /**
  919. * i40e_irq_dynamic_enable - Enable default interrupt generation settings
  920. * @vsi: pointer to a vsi
  921. * @vector: enable a particular Hw Interrupt vector, without base_vector
  922. **/
  923. static inline void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
  924. {
  925. struct i40e_pf *pf = vsi->back;
  926. struct i40e_hw *hw = &pf->hw;
  927. u32 val;
  928. val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
  929. I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
  930. (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  931. wr32(hw, I40E_PFINT_DYN_CTLN(vector + vsi->base_vector - 1), val);
  932. /* skip the flush */
  933. }
  934. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf);
  935. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf);
  936. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  937. int i40e_open(struct net_device *netdev);
  938. int i40e_close(struct net_device *netdev);
  939. int i40e_vsi_open(struct i40e_vsi *vsi);
  940. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi);
  941. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid);
  942. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid);
  943. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid);
  944. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid);
  945. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  946. const u8 *macaddr);
  947. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr);
  948. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi);
  949. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr);
  950. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi);
  951. #ifdef CONFIG_I40E_DCB
  952. void i40e_dcbnl_flush_apps(struct i40e_pf *pf,
  953. struct i40e_dcbx_config *old_cfg,
  954. struct i40e_dcbx_config *new_cfg);
  955. void i40e_dcbnl_set_all(struct i40e_vsi *vsi);
  956. void i40e_dcbnl_setup(struct i40e_vsi *vsi);
  957. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  958. struct i40e_dcbx_config *old_cfg,
  959. struct i40e_dcbx_config *new_cfg);
  960. #endif /* CONFIG_I40E_DCB */
  961. void i40e_ptp_rx_hang(struct i40e_pf *pf);
  962. void i40e_ptp_tx_hang(struct i40e_pf *pf);
  963. void i40e_ptp_tx_hwtstamp(struct i40e_pf *pf);
  964. void i40e_ptp_rx_hwtstamp(struct i40e_pf *pf, struct sk_buff *skb, u8 index);
  965. void i40e_ptp_set_increment(struct i40e_pf *pf);
  966. int i40e_ptp_set_ts_config(struct i40e_pf *pf, struct ifreq *ifr);
  967. int i40e_ptp_get_ts_config(struct i40e_pf *pf, struct ifreq *ifr);
  968. void i40e_ptp_init(struct i40e_pf *pf);
  969. void i40e_ptp_stop(struct i40e_pf *pf);
  970. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi);
  971. i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf);
  972. i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf);
  973. i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf);
  974. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup);
  975. static inline bool i40e_enabled_xdp_vsi(struct i40e_vsi *vsi)
  976. {
  977. return !!vsi->xdp_prog;
  978. }
  979. int i40e_create_queue_channel(struct i40e_vsi *vsi, struct i40e_channel *ch);
  980. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate);
  981. int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  982. struct i40e_cloud_filter *filter,
  983. bool add);
  984. int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  985. struct i40e_cloud_filter *filter,
  986. bool add);
  987. #endif /* _I40E_H_ */