iavf.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #ifndef _IAVF_H_
  4. #define _IAVF_H_
  5. #include <linux/module.h>
  6. #include <linux/pci.h>
  7. #include <linux/aer.h>
  8. #include <linux/netdevice.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/ethtool.h>
  12. #include <linux/if_vlan.h>
  13. #include <linux/ip.h>
  14. #include <linux/tcp.h>
  15. #include <linux/sctp.h>
  16. #include <linux/ipv6.h>
  17. #include <linux/kernel.h>
  18. #include <linux/bitops.h>
  19. #include <linux/timer.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/wait.h>
  22. #include <linux/delay.h>
  23. #include <linux/gfp.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/socket.h>
  28. #include <linux/jiffies.h>
  29. #include <net/ip6_checksum.h>
  30. #include <net/pkt_cls.h>
  31. #include <net/udp.h>
  32. #include <net/tc_act/tc_gact.h>
  33. #include <net/tc_act/tc_mirred.h>
  34. #include "iavf_type.h"
  35. #include <linux/avf/virtchnl.h>
  36. #include "iavf_txrx.h"
  37. #include "iavf_fdir.h"
  38. #include "iavf_adv_rss.h"
  39. #include <linux/bitmap.h>
  40. #define DEFAULT_DEBUG_LEVEL_SHIFT 3
  41. #define PFX "iavf: "
  42. int iavf_status_to_errno(enum iavf_status status);
  43. int virtchnl_status_to_errno(enum virtchnl_status_code v_status);
  44. /* VSI state flags shared with common code */
  45. enum iavf_vsi_state_t {
  46. __IAVF_VSI_DOWN,
  47. /* This must be last as it determines the size of the BITMAP */
  48. __IAVF_VSI_STATE_SIZE__,
  49. };
  50. /* dummy struct to make common code less painful */
  51. struct iavf_vsi {
  52. struct iavf_adapter *back;
  53. struct net_device *netdev;
  54. u16 seid;
  55. u16 id;
  56. DECLARE_BITMAP(state, __IAVF_VSI_STATE_SIZE__);
  57. int base_vector;
  58. u16 qs_handle;
  59. void *priv; /* client driver data reference. */
  60. };
  61. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  62. #define IAVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  63. #define IAVF_DEFAULT_TXD 512
  64. #define IAVF_DEFAULT_RXD 512
  65. #define IAVF_MAX_TXD 4096
  66. #define IAVF_MIN_TXD 64
  67. #define IAVF_MAX_RXD 4096
  68. #define IAVF_MIN_RXD 64
  69. #define IAVF_REQ_DESCRIPTOR_MULTIPLE 32
  70. #define IAVF_MAX_AQ_BUF_SIZE 4096
  71. #define IAVF_AQ_LEN 32
  72. #define IAVF_AQ_MAX_ERR 20 /* times to try before resetting AQ */
  73. #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
  74. #define IAVF_RX_DESC(R, i) (&(((union iavf_32byte_rx_desc *)((R)->desc))[i]))
  75. #define IAVF_TX_DESC(R, i) (&(((struct iavf_tx_desc *)((R)->desc))[i]))
  76. #define IAVF_TX_CTXTDESC(R, i) \
  77. (&(((struct iavf_tx_context_desc *)((R)->desc))[i]))
  78. #define IAVF_MAX_REQ_QUEUES 16
  79. #define IAVF_HKEY_ARRAY_SIZE ((IAVF_VFQF_HKEY_MAX_INDEX + 1) * 4)
  80. #define IAVF_HLUT_ARRAY_SIZE ((IAVF_VFQF_HLUT_MAX_INDEX + 1) * 4)
  81. #define IAVF_MBPS_DIVISOR 125000 /* divisor to convert to Mbps */
  82. #define IAVF_MBPS_QUANTA 50
  83. #define IAVF_VIRTCHNL_VF_RESOURCE_SIZE (sizeof(struct virtchnl_vf_resource) + \
  84. (IAVF_MAX_VF_VSI * \
  85. sizeof(struct virtchnl_vsi_resource)))
  86. /* MAX_MSIX_Q_VECTORS of these are allocated,
  87. * but we only use one per queue-specific vector.
  88. */
  89. struct iavf_q_vector {
  90. struct iavf_adapter *adapter;
  91. struct iavf_vsi *vsi;
  92. struct napi_struct napi;
  93. struct iavf_ring_container rx;
  94. struct iavf_ring_container tx;
  95. u32 ring_mask;
  96. u8 itr_countdown; /* when 0 should adjust adaptive ITR */
  97. u8 num_ringpairs; /* total number of ring pairs in vector */
  98. u16 v_idx; /* index in the vsi->q_vector array. */
  99. u16 reg_idx; /* register index of the interrupt */
  100. char name[IFNAMSIZ + 15];
  101. bool arm_wb_state;
  102. cpumask_t affinity_mask;
  103. struct irq_affinity_notify affinity_notify;
  104. };
  105. /* Helper macros to switch between ints/sec and what the register uses.
  106. * And yes, it's the same math going both ways. The lowest value
  107. * supported by all of the iavf hardware is 8.
  108. */
  109. #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
  110. ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
  111. #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
  112. #define IAVF_DESC_UNUSED(R) \
  113. ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
  114. (R)->next_to_clean - (R)->next_to_use - 1)
  115. #define OTHER_VECTOR 1
  116. #define NONQ_VECS (OTHER_VECTOR)
  117. #define MIN_MSIX_Q_VECTORS 1
  118. #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NONQ_VECS)
  119. #define IAVF_QUEUE_END_OF_LIST 0x7FF
  120. #define IAVF_FREE_VECTOR 0x7FFF
  121. struct iavf_mac_filter {
  122. struct list_head list;
  123. u8 macaddr[ETH_ALEN];
  124. struct {
  125. u8 is_new_mac:1; /* filter is new, wait for PF decision */
  126. u8 remove:1; /* filter needs to be removed */
  127. u8 add:1; /* filter needs to be added */
  128. u8 is_primary:1; /* filter is a default VF MAC */
  129. u8 add_handled:1; /* received response for filter add */
  130. u8 padding:3;
  131. };
  132. };
  133. #define IAVF_VLAN(vid, tpid) ((struct iavf_vlan){ vid, tpid })
  134. struct iavf_vlan {
  135. u16 vid;
  136. u16 tpid;
  137. };
  138. enum iavf_vlan_state_t {
  139. IAVF_VLAN_INVALID,
  140. IAVF_VLAN_ADD, /* filter needs to be added */
  141. IAVF_VLAN_IS_NEW, /* filter is new, wait for PF answer */
  142. IAVF_VLAN_ACTIVE, /* filter is accepted by PF */
  143. IAVF_VLAN_DISABLE, /* filter needs to be deleted by PF, then marked INACTIVE */
  144. IAVF_VLAN_INACTIVE, /* filter is inactive, we are in IFF_DOWN */
  145. IAVF_VLAN_REMOVE, /* filter needs to be removed from list */
  146. };
  147. struct iavf_vlan_filter {
  148. struct list_head list;
  149. struct iavf_vlan vlan;
  150. enum iavf_vlan_state_t state;
  151. };
  152. #define IAVF_MAX_TRAFFIC_CLASS 4
  153. /* State of traffic class creation */
  154. enum iavf_tc_state_t {
  155. __IAVF_TC_INVALID, /* no traffic class, default state */
  156. __IAVF_TC_RUNNING, /* traffic classes have been created */
  157. };
  158. /* channel info */
  159. struct iavf_channel_config {
  160. struct virtchnl_channel_info ch_info[IAVF_MAX_TRAFFIC_CLASS];
  161. enum iavf_tc_state_t state;
  162. u8 total_qps;
  163. };
  164. /* State of cloud filter */
  165. enum iavf_cloud_filter_state_t {
  166. __IAVF_CF_INVALID, /* cloud filter not added */
  167. __IAVF_CF_ADD_PENDING, /* cloud filter pending add by the PF */
  168. __IAVF_CF_DEL_PENDING, /* cloud filter pending del by the PF */
  169. __IAVF_CF_ACTIVE, /* cloud filter is active */
  170. };
  171. /* Driver state. The order of these is important! */
  172. enum iavf_state_t {
  173. __IAVF_STARTUP, /* driver loaded, probe complete */
  174. __IAVF_REMOVE, /* driver is being unloaded */
  175. __IAVF_INIT_VERSION_CHECK, /* aq msg sent, awaiting reply */
  176. __IAVF_INIT_GET_RESOURCES, /* aq msg sent, awaiting reply */
  177. __IAVF_INIT_EXTENDED_CAPS, /* process extended caps which require aq msg exchange */
  178. __IAVF_INIT_CONFIG_ADAPTER,
  179. __IAVF_INIT_SW, /* got resources, setting up structs */
  180. __IAVF_INIT_FAILED, /* init failed, restarting procedure */
  181. __IAVF_RESETTING, /* in reset */
  182. __IAVF_COMM_FAILED, /* communication with PF failed */
  183. /* Below here, watchdog is running */
  184. __IAVF_DOWN, /* ready, can be opened */
  185. __IAVF_DOWN_PENDING, /* descending, waiting for watchdog */
  186. __IAVF_TESTING, /* in ethtool self-test */
  187. __IAVF_RUNNING, /* opened, working */
  188. };
  189. enum iavf_critical_section_t {
  190. __IAVF_IN_REMOVE_TASK, /* device being removed */
  191. };
  192. #define IAVF_CLOUD_FIELD_OMAC 0x01
  193. #define IAVF_CLOUD_FIELD_IMAC 0x02
  194. #define IAVF_CLOUD_FIELD_IVLAN 0x04
  195. #define IAVF_CLOUD_FIELD_TEN_ID 0x08
  196. #define IAVF_CLOUD_FIELD_IIP 0x10
  197. #define IAVF_CF_FLAGS_OMAC IAVF_CLOUD_FIELD_OMAC
  198. #define IAVF_CF_FLAGS_IMAC IAVF_CLOUD_FIELD_IMAC
  199. #define IAVF_CF_FLAGS_IMAC_IVLAN (IAVF_CLOUD_FIELD_IMAC |\
  200. IAVF_CLOUD_FIELD_IVLAN)
  201. #define IAVF_CF_FLAGS_IMAC_TEN_ID (IAVF_CLOUD_FIELD_IMAC |\
  202. IAVF_CLOUD_FIELD_TEN_ID)
  203. #define IAVF_CF_FLAGS_OMAC_TEN_ID_IMAC (IAVF_CLOUD_FIELD_OMAC |\
  204. IAVF_CLOUD_FIELD_IMAC |\
  205. IAVF_CLOUD_FIELD_TEN_ID)
  206. #define IAVF_CF_FLAGS_IMAC_IVLAN_TEN_ID (IAVF_CLOUD_FIELD_IMAC |\
  207. IAVF_CLOUD_FIELD_IVLAN |\
  208. IAVF_CLOUD_FIELD_TEN_ID)
  209. #define IAVF_CF_FLAGS_IIP IAVF_CLOUD_FIELD_IIP
  210. /* bookkeeping of cloud filters */
  211. struct iavf_cloud_filter {
  212. enum iavf_cloud_filter_state_t state;
  213. struct list_head list;
  214. struct virtchnl_filter f;
  215. unsigned long cookie;
  216. bool del; /* filter needs to be deleted */
  217. bool add; /* filter needs to be added */
  218. };
  219. #define IAVF_RESET_WAIT_MS 10
  220. #define IAVF_RESET_WAIT_DETECTED_COUNT 500
  221. #define IAVF_RESET_WAIT_COMPLETE_COUNT 2000
  222. /* board specific private data structure */
  223. struct iavf_adapter {
  224. struct workqueue_struct *wq;
  225. struct work_struct reset_task;
  226. struct work_struct adminq_task;
  227. struct work_struct finish_config;
  228. struct delayed_work client_task;
  229. wait_queue_head_t down_waitqueue;
  230. wait_queue_head_t reset_waitqueue;
  231. wait_queue_head_t vc_waitqueue;
  232. struct iavf_q_vector *q_vectors;
  233. struct list_head vlan_filter_list;
  234. int num_vlan_filters;
  235. struct list_head mac_filter_list;
  236. struct mutex crit_lock;
  237. struct mutex client_lock;
  238. /* Lock to protect accesses to MAC and VLAN lists */
  239. spinlock_t mac_vlan_list_lock;
  240. char misc_vector_name[IFNAMSIZ + 9];
  241. int num_active_queues;
  242. int num_req_queues;
  243. /* TX */
  244. struct iavf_ring *tx_rings;
  245. u32 tx_timeout_count;
  246. u32 tx_desc_count;
  247. /* RX */
  248. struct iavf_ring *rx_rings;
  249. u64 hw_csum_rx_error;
  250. u32 rx_desc_count;
  251. int num_msix_vectors;
  252. int num_iwarp_msix;
  253. int iwarp_base_vector;
  254. u32 client_pending;
  255. struct iavf_client_instance *cinst;
  256. struct msix_entry *msix_entries;
  257. u32 flags;
  258. #define IAVF_FLAG_RX_CSUM_ENABLED BIT(0)
  259. #define IAVF_FLAG_PF_COMMS_FAILED BIT(3)
  260. #define IAVF_FLAG_RESET_PENDING BIT(4)
  261. #define IAVF_FLAG_RESET_NEEDED BIT(5)
  262. #define IAVF_FLAG_WB_ON_ITR_CAPABLE BIT(6)
  263. #define IAVF_FLAG_SERVICE_CLIENT_REQUESTED BIT(9)
  264. #define IAVF_FLAG_CLIENT_NEEDS_OPEN BIT(10)
  265. #define IAVF_FLAG_CLIENT_NEEDS_CLOSE BIT(11)
  266. #define IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS BIT(12)
  267. #define IAVF_FLAG_LEGACY_RX BIT(15)
  268. #define IAVF_FLAG_REINIT_ITR_NEEDED BIT(16)
  269. #define IAVF_FLAG_QUEUES_DISABLED BIT(17)
  270. #define IAVF_FLAG_SETUP_NETDEV_FEATURES BIT(18)
  271. #define IAVF_FLAG_REINIT_MSIX_NEEDED BIT(20)
  272. /* duplicates for common code */
  273. #define IAVF_FLAG_DCB_ENABLED 0
  274. /* flags for admin queue service task */
  275. u64 aq_required;
  276. #define IAVF_FLAG_AQ_ENABLE_QUEUES BIT_ULL(0)
  277. #define IAVF_FLAG_AQ_DISABLE_QUEUES BIT_ULL(1)
  278. #define IAVF_FLAG_AQ_ADD_MAC_FILTER BIT_ULL(2)
  279. #define IAVF_FLAG_AQ_ADD_VLAN_FILTER BIT_ULL(3)
  280. #define IAVF_FLAG_AQ_DEL_MAC_FILTER BIT_ULL(4)
  281. #define IAVF_FLAG_AQ_DEL_VLAN_FILTER BIT_ULL(5)
  282. #define IAVF_FLAG_AQ_CONFIGURE_QUEUES BIT_ULL(6)
  283. #define IAVF_FLAG_AQ_MAP_VECTORS BIT_ULL(7)
  284. #define IAVF_FLAG_AQ_HANDLE_RESET BIT_ULL(8)
  285. #define IAVF_FLAG_AQ_CONFIGURE_RSS BIT_ULL(9) /* direct AQ config */
  286. #define IAVF_FLAG_AQ_GET_CONFIG BIT_ULL(10)
  287. /* Newer style, RSS done by the PF so we can ignore hardware vagaries. */
  288. #define IAVF_FLAG_AQ_GET_HENA BIT_ULL(11)
  289. #define IAVF_FLAG_AQ_SET_HENA BIT_ULL(12)
  290. #define IAVF_FLAG_AQ_SET_RSS_KEY BIT_ULL(13)
  291. #define IAVF_FLAG_AQ_SET_RSS_LUT BIT_ULL(14)
  292. #define IAVF_FLAG_AQ_CONFIGURE_PROMISC_MODE BIT_ULL(15)
  293. #define IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING BIT_ULL(19)
  294. #define IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING BIT_ULL(20)
  295. #define IAVF_FLAG_AQ_ENABLE_CHANNELS BIT_ULL(21)
  296. #define IAVF_FLAG_AQ_DISABLE_CHANNELS BIT_ULL(22)
  297. #define IAVF_FLAG_AQ_ADD_CLOUD_FILTER BIT_ULL(23)
  298. #define IAVF_FLAG_AQ_DEL_CLOUD_FILTER BIT_ULL(24)
  299. #define IAVF_FLAG_AQ_ADD_FDIR_FILTER BIT_ULL(25)
  300. #define IAVF_FLAG_AQ_DEL_FDIR_FILTER BIT_ULL(26)
  301. #define IAVF_FLAG_AQ_ADD_ADV_RSS_CFG BIT_ULL(27)
  302. #define IAVF_FLAG_AQ_DEL_ADV_RSS_CFG BIT_ULL(28)
  303. #define IAVF_FLAG_AQ_REQUEST_STATS BIT_ULL(29)
  304. #define IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS BIT_ULL(30)
  305. #define IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING BIT_ULL(31)
  306. #define IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING BIT_ULL(32)
  307. #define IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING BIT_ULL(33)
  308. #define IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING BIT_ULL(34)
  309. #define IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION BIT_ULL(35)
  310. #define IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION BIT_ULL(36)
  311. #define IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION BIT_ULL(37)
  312. #define IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION BIT_ULL(38)
  313. /* flags for processing extended capability messages during
  314. * __IAVF_INIT_EXTENDED_CAPS. Each capability exchange requires
  315. * both a SEND and a RECV step, which must be processed in sequence.
  316. *
  317. * During the __IAVF_INIT_EXTENDED_CAPS state, the driver will
  318. * process one flag at a time during each state loop.
  319. */
  320. u64 extended_caps;
  321. #define IAVF_EXTENDED_CAP_SEND_VLAN_V2 BIT_ULL(0)
  322. #define IAVF_EXTENDED_CAP_RECV_VLAN_V2 BIT_ULL(1)
  323. #define IAVF_EXTENDED_CAPS \
  324. (IAVF_EXTENDED_CAP_SEND_VLAN_V2 | \
  325. IAVF_EXTENDED_CAP_RECV_VLAN_V2)
  326. /* Lock to prevent possible clobbering of
  327. * current_netdev_promisc_flags
  328. */
  329. spinlock_t current_netdev_promisc_flags_lock;
  330. netdev_features_t current_netdev_promisc_flags;
  331. /* OS defined structs */
  332. struct net_device *netdev;
  333. struct pci_dev *pdev;
  334. struct iavf_hw hw; /* defined in iavf_type.h */
  335. enum iavf_state_t state;
  336. enum iavf_state_t last_state;
  337. unsigned long crit_section;
  338. struct delayed_work watchdog_task;
  339. bool netdev_registered;
  340. bool link_up;
  341. enum virtchnl_link_speed link_speed;
  342. /* This is only populated if the VIRTCHNL_VF_CAP_ADV_LINK_SPEED is set
  343. * in vf_res->vf_cap_flags. Use ADV_LINK_SUPPORT macro to determine if
  344. * this field is valid. This field should be used going forward and the
  345. * enum virtchnl_link_speed above should be considered the legacy way of
  346. * storing/communicating link speeds.
  347. */
  348. u32 link_speed_mbps;
  349. enum virtchnl_ops current_op;
  350. #define CLIENT_ALLOWED(_a) ((_a)->vf_res ? \
  351. (_a)->vf_res->vf_cap_flags & \
  352. VIRTCHNL_VF_OFFLOAD_IWARP : \
  353. 0)
  354. #define CLIENT_ENABLED(_a) ((_a)->cinst)
  355. /* RSS by the PF should be preferred over RSS via other methods. */
  356. #define RSS_PF(_a) ((_a)->vf_res->vf_cap_flags & \
  357. VIRTCHNL_VF_OFFLOAD_RSS_PF)
  358. #define RSS_AQ(_a) ((_a)->vf_res->vf_cap_flags & \
  359. VIRTCHNL_VF_OFFLOAD_RSS_AQ)
  360. #define RSS_REG(_a) (!((_a)->vf_res->vf_cap_flags & \
  361. (VIRTCHNL_VF_OFFLOAD_RSS_AQ | \
  362. VIRTCHNL_VF_OFFLOAD_RSS_PF)))
  363. #define VLAN_ALLOWED(_a) ((_a)->vf_res->vf_cap_flags & \
  364. VIRTCHNL_VF_OFFLOAD_VLAN)
  365. #define VLAN_V2_ALLOWED(_a) ((_a)->vf_res->vf_cap_flags & \
  366. VIRTCHNL_VF_OFFLOAD_VLAN_V2)
  367. #define VLAN_V2_FILTERING_ALLOWED(_a) \
  368. (VLAN_V2_ALLOWED((_a)) && \
  369. ((_a)->vlan_v2_caps.filtering.filtering_support.outer || \
  370. (_a)->vlan_v2_caps.filtering.filtering_support.inner))
  371. #define VLAN_FILTERING_ALLOWED(_a) \
  372. (VLAN_ALLOWED((_a)) || VLAN_V2_FILTERING_ALLOWED((_a)))
  373. #define ADV_LINK_SUPPORT(_a) ((_a)->vf_res->vf_cap_flags & \
  374. VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
  375. #define FDIR_FLTR_SUPPORT(_a) ((_a)->vf_res->vf_cap_flags & \
  376. VIRTCHNL_VF_OFFLOAD_FDIR_PF)
  377. #define ADV_RSS_SUPPORT(_a) ((_a)->vf_res->vf_cap_flags & \
  378. VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
  379. struct virtchnl_vf_resource *vf_res; /* incl. all VSIs */
  380. struct virtchnl_vsi_resource *vsi_res; /* our LAN VSI */
  381. struct virtchnl_version_info pf_version;
  382. #define PF_IS_V11(_a) (((_a)->pf_version.major == 1) && \
  383. ((_a)->pf_version.minor == 1))
  384. struct virtchnl_vlan_caps vlan_v2_caps;
  385. u16 msg_enable;
  386. struct iavf_eth_stats current_stats;
  387. struct iavf_vsi vsi;
  388. u32 aq_wait_count;
  389. /* RSS stuff */
  390. u64 hena;
  391. u16 rss_key_size;
  392. u16 rss_lut_size;
  393. u8 *rss_key;
  394. u8 *rss_lut;
  395. /* ADQ related members */
  396. struct iavf_channel_config ch_config;
  397. u8 num_tc;
  398. struct list_head cloud_filter_list;
  399. /* lock to protect access to the cloud filter list */
  400. spinlock_t cloud_filter_list_lock;
  401. u16 num_cloud_filters;
  402. /* snapshot of "num_active_queues" before setup_tc for qdisc add
  403. * is invoked. This information is useful during qdisc del flow,
  404. * to restore correct number of queues
  405. */
  406. int orig_num_active_queues;
  407. #define IAVF_MAX_FDIR_FILTERS 128 /* max allowed Flow Director filters */
  408. u16 fdir_active_fltr;
  409. struct list_head fdir_list_head;
  410. spinlock_t fdir_fltr_lock; /* protect the Flow Director filter list */
  411. struct list_head adv_rss_list_head;
  412. spinlock_t adv_rss_lock; /* protect the RSS management list */
  413. };
  414. /* Ethtool Private Flags */
  415. /* lan device, used by client interface */
  416. struct iavf_device {
  417. struct list_head list;
  418. struct iavf_adapter *vf;
  419. };
  420. /* needed by iavf_ethtool.c */
  421. extern char iavf_driver_name[];
  422. static inline const char *iavf_state_str(enum iavf_state_t state)
  423. {
  424. switch (state) {
  425. case __IAVF_STARTUP:
  426. return "__IAVF_STARTUP";
  427. case __IAVF_REMOVE:
  428. return "__IAVF_REMOVE";
  429. case __IAVF_INIT_VERSION_CHECK:
  430. return "__IAVF_INIT_VERSION_CHECK";
  431. case __IAVF_INIT_GET_RESOURCES:
  432. return "__IAVF_INIT_GET_RESOURCES";
  433. case __IAVF_INIT_EXTENDED_CAPS:
  434. return "__IAVF_INIT_EXTENDED_CAPS";
  435. case __IAVF_INIT_CONFIG_ADAPTER:
  436. return "__IAVF_INIT_CONFIG_ADAPTER";
  437. case __IAVF_INIT_SW:
  438. return "__IAVF_INIT_SW";
  439. case __IAVF_INIT_FAILED:
  440. return "__IAVF_INIT_FAILED";
  441. case __IAVF_RESETTING:
  442. return "__IAVF_RESETTING";
  443. case __IAVF_COMM_FAILED:
  444. return "__IAVF_COMM_FAILED";
  445. case __IAVF_DOWN:
  446. return "__IAVF_DOWN";
  447. case __IAVF_DOWN_PENDING:
  448. return "__IAVF_DOWN_PENDING";
  449. case __IAVF_TESTING:
  450. return "__IAVF_TESTING";
  451. case __IAVF_RUNNING:
  452. return "__IAVF_RUNNING";
  453. default:
  454. return "__IAVF_UNKNOWN_STATE";
  455. }
  456. }
  457. static inline void iavf_change_state(struct iavf_adapter *adapter,
  458. enum iavf_state_t state)
  459. {
  460. if (adapter->state != state) {
  461. adapter->last_state = adapter->state;
  462. adapter->state = state;
  463. }
  464. dev_dbg(&adapter->pdev->dev,
  465. "state transition from:%s to:%s\n",
  466. iavf_state_str(adapter->last_state),
  467. iavf_state_str(adapter->state));
  468. }
  469. int iavf_up(struct iavf_adapter *adapter);
  470. void iavf_down(struct iavf_adapter *adapter);
  471. int iavf_process_config(struct iavf_adapter *adapter);
  472. int iavf_parse_vf_resource_msg(struct iavf_adapter *adapter);
  473. void iavf_schedule_reset(struct iavf_adapter *adapter, u64 flags);
  474. void iavf_schedule_aq_request(struct iavf_adapter *adapter, u64 flags);
  475. void iavf_schedule_finish_config(struct iavf_adapter *adapter);
  476. void iavf_reset(struct iavf_adapter *adapter);
  477. void iavf_set_ethtool_ops(struct net_device *netdev);
  478. void iavf_update_stats(struct iavf_adapter *adapter);
  479. void iavf_free_all_tx_resources(struct iavf_adapter *adapter);
  480. void iavf_free_all_rx_resources(struct iavf_adapter *adapter);
  481. void iavf_napi_add_all(struct iavf_adapter *adapter);
  482. void iavf_napi_del_all(struct iavf_adapter *adapter);
  483. int iavf_send_api_ver(struct iavf_adapter *adapter);
  484. int iavf_verify_api_ver(struct iavf_adapter *adapter);
  485. int iavf_send_vf_config_msg(struct iavf_adapter *adapter);
  486. int iavf_get_vf_config(struct iavf_adapter *adapter);
  487. int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter);
  488. int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter);
  489. void iavf_set_queue_vlan_tag_loc(struct iavf_adapter *adapter);
  490. u16 iavf_get_num_vlans_added(struct iavf_adapter *adapter);
  491. void iavf_irq_enable(struct iavf_adapter *adapter, bool flush);
  492. void iavf_configure_queues(struct iavf_adapter *adapter);
  493. void iavf_deconfigure_queues(struct iavf_adapter *adapter);
  494. void iavf_enable_queues(struct iavf_adapter *adapter);
  495. void iavf_disable_queues(struct iavf_adapter *adapter);
  496. void iavf_map_queues(struct iavf_adapter *adapter);
  497. int iavf_request_queues(struct iavf_adapter *adapter, int num);
  498. void iavf_add_ether_addrs(struct iavf_adapter *adapter);
  499. void iavf_del_ether_addrs(struct iavf_adapter *adapter);
  500. void iavf_add_vlans(struct iavf_adapter *adapter);
  501. void iavf_del_vlans(struct iavf_adapter *adapter);
  502. void iavf_set_promiscuous(struct iavf_adapter *adapter);
  503. bool iavf_promiscuous_mode_changed(struct iavf_adapter *adapter);
  504. void iavf_request_stats(struct iavf_adapter *adapter);
  505. int iavf_request_reset(struct iavf_adapter *adapter);
  506. void iavf_get_hena(struct iavf_adapter *adapter);
  507. void iavf_set_hena(struct iavf_adapter *adapter);
  508. void iavf_set_rss_key(struct iavf_adapter *adapter);
  509. void iavf_set_rss_lut(struct iavf_adapter *adapter);
  510. void iavf_enable_vlan_stripping(struct iavf_adapter *adapter);
  511. void iavf_disable_vlan_stripping(struct iavf_adapter *adapter);
  512. void iavf_virtchnl_completion(struct iavf_adapter *adapter,
  513. enum virtchnl_ops v_opcode,
  514. enum iavf_status v_retval, u8 *msg, u16 msglen);
  515. int iavf_config_rss(struct iavf_adapter *adapter);
  516. int iavf_lan_add_device(struct iavf_adapter *adapter);
  517. int iavf_lan_del_device(struct iavf_adapter *adapter);
  518. void iavf_client_subtask(struct iavf_adapter *adapter);
  519. void iavf_notify_client_message(struct iavf_vsi *vsi, u8 *msg, u16 len);
  520. void iavf_notify_client_l2_params(struct iavf_vsi *vsi);
  521. void iavf_notify_client_open(struct iavf_vsi *vsi);
  522. void iavf_notify_client_close(struct iavf_vsi *vsi, bool reset);
  523. void iavf_enable_channels(struct iavf_adapter *adapter);
  524. void iavf_disable_channels(struct iavf_adapter *adapter);
  525. void iavf_add_cloud_filter(struct iavf_adapter *adapter);
  526. void iavf_del_cloud_filter(struct iavf_adapter *adapter);
  527. void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid);
  528. void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid);
  529. void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid);
  530. void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid);
  531. void iavf_add_fdir_filter(struct iavf_adapter *adapter);
  532. void iavf_del_fdir_filter(struct iavf_adapter *adapter);
  533. void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter);
  534. void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter);
  535. struct iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter,
  536. const u8 *macaddr);
  537. int iavf_wait_for_reset(struct iavf_adapter *adapter);
  538. #endif /* _IAVF_H_ */