i40evf.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #ifndef _I40EVF_H_
  4. #define _I40EVF_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 "i40e_type.h"
  35. #include <linux/avf/virtchnl.h>
  36. #include "i40e_txrx.h"
  37. #define DEFAULT_DEBUG_LEVEL_SHIFT 3
  38. #define PFX "i40evf: "
  39. /* VSI state flags shared with common code */
  40. enum i40evf_vsi_state_t {
  41. __I40E_VSI_DOWN,
  42. /* This must be last as it determines the size of the BITMAP */
  43. __I40E_VSI_STATE_SIZE__,
  44. };
  45. /* dummy struct to make common code less painful */
  46. struct i40e_vsi {
  47. struct i40evf_adapter *back;
  48. struct net_device *netdev;
  49. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  50. u16 seid;
  51. u16 id;
  52. DECLARE_BITMAP(state, __I40E_VSI_STATE_SIZE__);
  53. int base_vector;
  54. u16 work_limit;
  55. u16 qs_handle;
  56. void *priv; /* client driver data reference. */
  57. };
  58. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  59. #define I40EVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  60. #define I40EVF_DEFAULT_TXD 512
  61. #define I40EVF_DEFAULT_RXD 512
  62. #define I40EVF_MAX_TXD 4096
  63. #define I40EVF_MIN_TXD 64
  64. #define I40EVF_MAX_RXD 4096
  65. #define I40EVF_MIN_RXD 64
  66. #define I40EVF_REQ_DESCRIPTOR_MULTIPLE 32
  67. #define I40EVF_MAX_AQ_BUF_SIZE 4096
  68. #define I40EVF_AQ_LEN 32
  69. #define I40EVF_AQ_MAX_ERR 20 /* times to try before resetting AQ */
  70. #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
  71. #define I40E_RX_DESC(R, i) (&(((union i40e_32byte_rx_desc *)((R)->desc))[i]))
  72. #define I40E_TX_DESC(R, i) (&(((struct i40e_tx_desc *)((R)->desc))[i]))
  73. #define I40E_TX_CTXTDESC(R, i) \
  74. (&(((struct i40e_tx_context_desc *)((R)->desc))[i]))
  75. #define I40EVF_MAX_REQ_QUEUES 4
  76. #define I40EVF_HKEY_ARRAY_SIZE ((I40E_VFQF_HKEY_MAX_INDEX + 1) * 4)
  77. #define I40EVF_HLUT_ARRAY_SIZE ((I40E_VFQF_HLUT_MAX_INDEX + 1) * 4)
  78. #define I40EVF_MBPS_DIVISOR 125000 /* divisor to convert to Mbps */
  79. /* MAX_MSIX_Q_VECTORS of these are allocated,
  80. * but we only use one per queue-specific vector.
  81. */
  82. struct i40e_q_vector {
  83. struct i40evf_adapter *adapter;
  84. struct i40e_vsi *vsi;
  85. struct napi_struct napi;
  86. struct i40e_ring_container rx;
  87. struct i40e_ring_container tx;
  88. u32 ring_mask;
  89. u8 itr_countdown; /* when 0 should adjust adaptive ITR */
  90. u8 num_ringpairs; /* total number of ring pairs in vector */
  91. u16 v_idx; /* index in the vsi->q_vector array. */
  92. u16 reg_idx; /* register index of the interrupt */
  93. char name[IFNAMSIZ + 15];
  94. bool arm_wb_state;
  95. cpumask_t affinity_mask;
  96. struct irq_affinity_notify affinity_notify;
  97. };
  98. /* Helper macros to switch between ints/sec and what the register uses.
  99. * And yes, it's the same math going both ways. The lowest value
  100. * supported by all of the i40e hardware is 8.
  101. */
  102. #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
  103. ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
  104. #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
  105. #define I40EVF_DESC_UNUSED(R) \
  106. ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
  107. (R)->next_to_clean - (R)->next_to_use - 1)
  108. #define I40EVF_RX_DESC_ADV(R, i) \
  109. (&(((union i40e_adv_rx_desc *)((R).desc))[i]))
  110. #define I40EVF_TX_DESC_ADV(R, i) \
  111. (&(((union i40e_adv_tx_desc *)((R).desc))[i]))
  112. #define I40EVF_TX_CTXTDESC_ADV(R, i) \
  113. (&(((struct i40e_adv_tx_context_desc *)((R).desc))[i]))
  114. #define OTHER_VECTOR 1
  115. #define NONQ_VECS (OTHER_VECTOR)
  116. #define MIN_MSIX_Q_VECTORS 1
  117. #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NONQ_VECS)
  118. #define I40EVF_QUEUE_END_OF_LIST 0x7FF
  119. #define I40EVF_FREE_VECTOR 0x7FFF
  120. struct i40evf_mac_filter {
  121. struct list_head list;
  122. u8 macaddr[ETH_ALEN];
  123. bool remove; /* filter needs to be removed */
  124. bool add; /* filter needs to be added */
  125. };
  126. struct i40evf_vlan_filter {
  127. struct list_head list;
  128. u16 vlan;
  129. bool remove; /* filter needs to be removed */
  130. bool add; /* filter needs to be added */
  131. };
  132. #define I40EVF_MAX_TRAFFIC_CLASS 4
  133. /* State of traffic class creation */
  134. enum i40evf_tc_state_t {
  135. __I40EVF_TC_INVALID, /* no traffic class, default state */
  136. __I40EVF_TC_RUNNING, /* traffic classes have been created */
  137. };
  138. /* channel info */
  139. struct i40evf_channel_config {
  140. struct virtchnl_channel_info ch_info[I40EVF_MAX_TRAFFIC_CLASS];
  141. enum i40evf_tc_state_t state;
  142. u8 total_qps;
  143. };
  144. /* State of cloud filter */
  145. enum i40evf_cloud_filter_state_t {
  146. __I40EVF_CF_INVALID, /* cloud filter not added */
  147. __I40EVF_CF_ADD_PENDING, /* cloud filter pending add by the PF */
  148. __I40EVF_CF_DEL_PENDING, /* cloud filter pending del by the PF */
  149. __I40EVF_CF_ACTIVE, /* cloud filter is active */
  150. };
  151. /* Driver state. The order of these is important! */
  152. enum i40evf_state_t {
  153. __I40EVF_STARTUP, /* driver loaded, probe complete */
  154. __I40EVF_REMOVE, /* driver is being unloaded */
  155. __I40EVF_INIT_VERSION_CHECK, /* aq msg sent, awaiting reply */
  156. __I40EVF_INIT_GET_RESOURCES, /* aq msg sent, awaiting reply */
  157. __I40EVF_INIT_SW, /* got resources, setting up structs */
  158. __I40EVF_RESETTING, /* in reset */
  159. /* Below here, watchdog is running */
  160. __I40EVF_DOWN, /* ready, can be opened */
  161. __I40EVF_DOWN_PENDING, /* descending, waiting for watchdog */
  162. __I40EVF_TESTING, /* in ethtool self-test */
  163. __I40EVF_RUNNING, /* opened, working */
  164. };
  165. enum i40evf_critical_section_t {
  166. __I40EVF_IN_CRITICAL_TASK, /* cannot be interrupted */
  167. __I40EVF_IN_CLIENT_TASK,
  168. __I40EVF_IN_REMOVE_TASK, /* device being removed */
  169. };
  170. #define I40EVF_CLOUD_FIELD_OMAC 0x01
  171. #define I40EVF_CLOUD_FIELD_IMAC 0x02
  172. #define I40EVF_CLOUD_FIELD_IVLAN 0x04
  173. #define I40EVF_CLOUD_FIELD_TEN_ID 0x08
  174. #define I40EVF_CLOUD_FIELD_IIP 0x10
  175. #define I40EVF_CF_FLAGS_OMAC I40EVF_CLOUD_FIELD_OMAC
  176. #define I40EVF_CF_FLAGS_IMAC I40EVF_CLOUD_FIELD_IMAC
  177. #define I40EVF_CF_FLAGS_IMAC_IVLAN (I40EVF_CLOUD_FIELD_IMAC |\
  178. I40EVF_CLOUD_FIELD_IVLAN)
  179. #define I40EVF_CF_FLAGS_IMAC_TEN_ID (I40EVF_CLOUD_FIELD_IMAC |\
  180. I40EVF_CLOUD_FIELD_TEN_ID)
  181. #define I40EVF_CF_FLAGS_OMAC_TEN_ID_IMAC (I40EVF_CLOUD_FIELD_OMAC |\
  182. I40EVF_CLOUD_FIELD_IMAC |\
  183. I40EVF_CLOUD_FIELD_TEN_ID)
  184. #define I40EVF_CF_FLAGS_IMAC_IVLAN_TEN_ID (I40EVF_CLOUD_FIELD_IMAC |\
  185. I40EVF_CLOUD_FIELD_IVLAN |\
  186. I40EVF_CLOUD_FIELD_TEN_ID)
  187. #define I40EVF_CF_FLAGS_IIP I40E_CLOUD_FIELD_IIP
  188. /* bookkeeping of cloud filters */
  189. struct i40evf_cloud_filter {
  190. enum i40evf_cloud_filter_state_t state;
  191. struct list_head list;
  192. struct virtchnl_filter f;
  193. unsigned long cookie;
  194. bool del; /* filter needs to be deleted */
  195. bool add; /* filter needs to be added */
  196. };
  197. /* board specific private data structure */
  198. struct i40evf_adapter {
  199. struct timer_list watchdog_timer;
  200. struct work_struct reset_task;
  201. struct work_struct adminq_task;
  202. struct delayed_work client_task;
  203. struct delayed_work init_task;
  204. wait_queue_head_t down_waitqueue;
  205. struct i40e_q_vector *q_vectors;
  206. struct list_head vlan_filter_list;
  207. struct list_head mac_filter_list;
  208. /* Lock to protect accesses to MAC and VLAN lists */
  209. spinlock_t mac_vlan_list_lock;
  210. char misc_vector_name[IFNAMSIZ + 9];
  211. int num_active_queues;
  212. int num_req_queues;
  213. /* TX */
  214. struct i40e_ring *tx_rings;
  215. u32 tx_timeout_count;
  216. u32 tx_desc_count;
  217. /* RX */
  218. struct i40e_ring *rx_rings;
  219. u64 hw_csum_rx_error;
  220. u32 rx_desc_count;
  221. int num_msix_vectors;
  222. int num_iwarp_msix;
  223. int iwarp_base_vector;
  224. u32 client_pending;
  225. struct i40e_client_instance *cinst;
  226. struct msix_entry *msix_entries;
  227. u32 flags;
  228. #define I40EVF_FLAG_RX_CSUM_ENABLED BIT(0)
  229. #define I40EVF_FLAG_PF_COMMS_FAILED BIT(3)
  230. #define I40EVF_FLAG_RESET_PENDING BIT(4)
  231. #define I40EVF_FLAG_RESET_NEEDED BIT(5)
  232. #define I40EVF_FLAG_WB_ON_ITR_CAPABLE BIT(6)
  233. #define I40EVF_FLAG_ADDR_SET_BY_PF BIT(8)
  234. #define I40EVF_FLAG_SERVICE_CLIENT_REQUESTED BIT(9)
  235. #define I40EVF_FLAG_CLIENT_NEEDS_OPEN BIT(10)
  236. #define I40EVF_FLAG_CLIENT_NEEDS_CLOSE BIT(11)
  237. #define I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS BIT(12)
  238. #define I40EVF_FLAG_PROMISC_ON BIT(13)
  239. #define I40EVF_FLAG_ALLMULTI_ON BIT(14)
  240. #define I40EVF_FLAG_LEGACY_RX BIT(15)
  241. #define I40EVF_FLAG_REINIT_ITR_NEEDED BIT(16)
  242. #define I40EVF_FLAG_QUEUES_DISABLED BIT(17)
  243. /* duplicates for common code */
  244. #define I40E_FLAG_DCB_ENABLED 0
  245. #define I40E_FLAG_RX_CSUM_ENABLED I40EVF_FLAG_RX_CSUM_ENABLED
  246. #define I40E_FLAG_LEGACY_RX I40EVF_FLAG_LEGACY_RX
  247. /* flags for admin queue service task */
  248. u32 aq_required;
  249. #define I40EVF_FLAG_AQ_ENABLE_QUEUES BIT(0)
  250. #define I40EVF_FLAG_AQ_DISABLE_QUEUES BIT(1)
  251. #define I40EVF_FLAG_AQ_ADD_MAC_FILTER BIT(2)
  252. #define I40EVF_FLAG_AQ_ADD_VLAN_FILTER BIT(3)
  253. #define I40EVF_FLAG_AQ_DEL_MAC_FILTER BIT(4)
  254. #define I40EVF_FLAG_AQ_DEL_VLAN_FILTER BIT(5)
  255. #define I40EVF_FLAG_AQ_CONFIGURE_QUEUES BIT(6)
  256. #define I40EVF_FLAG_AQ_MAP_VECTORS BIT(7)
  257. #define I40EVF_FLAG_AQ_HANDLE_RESET BIT(8)
  258. #define I40EVF_FLAG_AQ_CONFIGURE_RSS BIT(9) /* direct AQ config */
  259. #define I40EVF_FLAG_AQ_GET_CONFIG BIT(10)
  260. /* Newer style, RSS done by the PF so we can ignore hardware vagaries. */
  261. #define I40EVF_FLAG_AQ_GET_HENA BIT(11)
  262. #define I40EVF_FLAG_AQ_SET_HENA BIT(12)
  263. #define I40EVF_FLAG_AQ_SET_RSS_KEY BIT(13)
  264. #define I40EVF_FLAG_AQ_SET_RSS_LUT BIT(14)
  265. #define I40EVF_FLAG_AQ_REQUEST_PROMISC BIT(15)
  266. #define I40EVF_FLAG_AQ_RELEASE_PROMISC BIT(16)
  267. #define I40EVF_FLAG_AQ_REQUEST_ALLMULTI BIT(17)
  268. #define I40EVF_FLAG_AQ_RELEASE_ALLMULTI BIT(18)
  269. #define I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING BIT(19)
  270. #define I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING BIT(20)
  271. #define I40EVF_FLAG_AQ_ENABLE_CHANNELS BIT(21)
  272. #define I40EVF_FLAG_AQ_DISABLE_CHANNELS BIT(22)
  273. #define I40EVF_FLAG_AQ_ADD_CLOUD_FILTER BIT(23)
  274. #define I40EVF_FLAG_AQ_DEL_CLOUD_FILTER BIT(24)
  275. /* OS defined structs */
  276. struct net_device *netdev;
  277. struct pci_dev *pdev;
  278. struct i40e_hw hw; /* defined in i40e_type.h */
  279. enum i40evf_state_t state;
  280. unsigned long crit_section;
  281. struct work_struct watchdog_task;
  282. bool netdev_registered;
  283. bool link_up;
  284. enum virtchnl_link_speed link_speed;
  285. enum virtchnl_ops current_op;
  286. #define CLIENT_ALLOWED(_a) ((_a)->vf_res ? \
  287. (_a)->vf_res->vf_cap_flags & \
  288. VIRTCHNL_VF_OFFLOAD_IWARP : \
  289. 0)
  290. #define CLIENT_ENABLED(_a) ((_a)->cinst)
  291. /* RSS by the PF should be preferred over RSS via other methods. */
  292. #define RSS_PF(_a) ((_a)->vf_res->vf_cap_flags & \
  293. VIRTCHNL_VF_OFFLOAD_RSS_PF)
  294. #define RSS_AQ(_a) ((_a)->vf_res->vf_cap_flags & \
  295. VIRTCHNL_VF_OFFLOAD_RSS_AQ)
  296. #define RSS_REG(_a) (!((_a)->vf_res->vf_cap_flags & \
  297. (VIRTCHNL_VF_OFFLOAD_RSS_AQ | \
  298. VIRTCHNL_VF_OFFLOAD_RSS_PF)))
  299. #define VLAN_ALLOWED(_a) ((_a)->vf_res->vf_cap_flags & \
  300. VIRTCHNL_VF_OFFLOAD_VLAN)
  301. struct virtchnl_vf_resource *vf_res; /* incl. all VSIs */
  302. struct virtchnl_vsi_resource *vsi_res; /* our LAN VSI */
  303. struct virtchnl_version_info pf_version;
  304. #define PF_IS_V11(_a) (((_a)->pf_version.major == 1) && \
  305. ((_a)->pf_version.minor == 1))
  306. u16 msg_enable;
  307. struct i40e_eth_stats current_stats;
  308. struct i40e_vsi vsi;
  309. u32 aq_wait_count;
  310. /* RSS stuff */
  311. u64 hena;
  312. u16 rss_key_size;
  313. u16 rss_lut_size;
  314. u8 *rss_key;
  315. u8 *rss_lut;
  316. /* ADQ related members */
  317. struct i40evf_channel_config ch_config;
  318. u8 num_tc;
  319. struct list_head cloud_filter_list;
  320. /* lock to protest access to the cloud filter list */
  321. spinlock_t cloud_filter_list_lock;
  322. u16 num_cloud_filters;
  323. };
  324. /* Ethtool Private Flags */
  325. /* lan device */
  326. struct i40e_device {
  327. struct list_head list;
  328. struct i40evf_adapter *vf;
  329. };
  330. /* needed by i40evf_ethtool.c */
  331. extern char i40evf_driver_name[];
  332. extern const char i40evf_driver_version[];
  333. int i40evf_up(struct i40evf_adapter *adapter);
  334. void i40evf_down(struct i40evf_adapter *adapter);
  335. int i40evf_process_config(struct i40evf_adapter *adapter);
  336. void i40evf_schedule_reset(struct i40evf_adapter *adapter);
  337. void i40evf_reset(struct i40evf_adapter *adapter);
  338. void i40evf_set_ethtool_ops(struct net_device *netdev);
  339. void i40evf_update_stats(struct i40evf_adapter *adapter);
  340. void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter);
  341. int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter);
  342. void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask);
  343. void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter);
  344. void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter);
  345. void i40e_napi_add_all(struct i40evf_adapter *adapter);
  346. void i40e_napi_del_all(struct i40evf_adapter *adapter);
  347. int i40evf_send_api_ver(struct i40evf_adapter *adapter);
  348. int i40evf_verify_api_ver(struct i40evf_adapter *adapter);
  349. int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter);
  350. int i40evf_get_vf_config(struct i40evf_adapter *adapter);
  351. void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush);
  352. void i40evf_configure_queues(struct i40evf_adapter *adapter);
  353. void i40evf_deconfigure_queues(struct i40evf_adapter *adapter);
  354. void i40evf_enable_queues(struct i40evf_adapter *adapter);
  355. void i40evf_disable_queues(struct i40evf_adapter *adapter);
  356. void i40evf_map_queues(struct i40evf_adapter *adapter);
  357. int i40evf_request_queues(struct i40evf_adapter *adapter, int num);
  358. void i40evf_add_ether_addrs(struct i40evf_adapter *adapter);
  359. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter);
  360. void i40evf_add_vlans(struct i40evf_adapter *adapter);
  361. void i40evf_del_vlans(struct i40evf_adapter *adapter);
  362. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags);
  363. void i40evf_request_stats(struct i40evf_adapter *adapter);
  364. void i40evf_request_reset(struct i40evf_adapter *adapter);
  365. void i40evf_get_hena(struct i40evf_adapter *adapter);
  366. void i40evf_set_hena(struct i40evf_adapter *adapter);
  367. void i40evf_set_rss_key(struct i40evf_adapter *adapter);
  368. void i40evf_set_rss_lut(struct i40evf_adapter *adapter);
  369. void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter);
  370. void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter);
  371. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  372. enum virtchnl_ops v_opcode,
  373. i40e_status v_retval, u8 *msg, u16 msglen);
  374. int i40evf_config_rss(struct i40evf_adapter *adapter);
  375. int i40evf_lan_add_device(struct i40evf_adapter *adapter);
  376. int i40evf_lan_del_device(struct i40evf_adapter *adapter);
  377. void i40evf_client_subtask(struct i40evf_adapter *adapter);
  378. void i40evf_notify_client_message(struct i40e_vsi *vsi, u8 *msg, u16 len);
  379. void i40evf_notify_client_l2_params(struct i40e_vsi *vsi);
  380. void i40evf_notify_client_open(struct i40e_vsi *vsi);
  381. void i40evf_notify_client_close(struct i40e_vsi *vsi, bool reset);
  382. void i40evf_enable_channels(struct i40evf_adapter *adapter);
  383. void i40evf_disable_channels(struct i40evf_adapter *adapter);
  384. void i40evf_add_cloud_filter(struct i40evf_adapter *adapter);
  385. void i40evf_del_cloud_filter(struct i40evf_adapter *adapter);
  386. #endif /* _I40EVF_H_ */