idpf.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (C) 2023 Intel Corporation */
  3. #ifndef _IDPF_H_
  4. #define _IDPF_H_
  5. /* Forward declaration */
  6. struct idpf_adapter;
  7. struct idpf_vport;
  8. struct idpf_vport_max_q;
  9. #include <net/pkt_sched.h>
  10. #include <linux/aer.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/pci.h>
  13. #include <linux/bitfield.h>
  14. #include <linux/sctp.h>
  15. #include <linux/ethtool_netlink.h>
  16. #include <net/gro.h>
  17. #include "virtchnl2.h"
  18. #include "idpf_txrx.h"
  19. #include "idpf_controlq.h"
  20. #define GETMAXVAL(num_bits) GENMASK((num_bits) - 1, 0)
  21. #define IDPF_NO_FREE_SLOT 0xffff
  22. /* Default Mailbox settings */
  23. #define IDPF_NUM_FILTERS_PER_MSG 20
  24. #define IDPF_NUM_DFLT_MBX_Q 2 /* includes both TX and RX */
  25. #define IDPF_DFLT_MBX_Q_LEN 64
  26. #define IDPF_DFLT_MBX_ID -1
  27. /* maximum number of times to try before resetting mailbox */
  28. #define IDPF_MB_MAX_ERR 20
  29. #define IDPF_NUM_CHUNKS_PER_MSG(struct_sz, chunk_sz) \
  30. ((IDPF_CTLQ_MAX_BUF_LEN - (struct_sz)) / (chunk_sz))
  31. #define IDPF_MAX_WAIT 500
  32. /* available message levels */
  33. #define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  34. #define IDPF_DIM_PROFILE_SLOTS 5
  35. #define IDPF_VIRTCHNL_VERSION_MAJOR VIRTCHNL2_VERSION_MAJOR_2
  36. #define IDPF_VIRTCHNL_VERSION_MINOR VIRTCHNL2_VERSION_MINOR_0
  37. /**
  38. * struct idpf_mac_filter
  39. * @list: list member field
  40. * @macaddr: MAC address
  41. * @remove: filter should be removed (virtchnl)
  42. * @add: filter should be added (virtchnl)
  43. */
  44. struct idpf_mac_filter {
  45. struct list_head list;
  46. u8 macaddr[ETH_ALEN];
  47. bool remove;
  48. bool add;
  49. };
  50. /**
  51. * enum idpf_state - State machine to handle bring up
  52. * @__IDPF_VER_CHECK: Negotiate virtchnl version
  53. * @__IDPF_GET_CAPS: Negotiate capabilities
  54. * @__IDPF_INIT_SW: Init based on given capabilities
  55. * @__IDPF_STATE_LAST: Must be last, used to determine size
  56. */
  57. enum idpf_state {
  58. __IDPF_VER_CHECK,
  59. __IDPF_GET_CAPS,
  60. __IDPF_INIT_SW,
  61. __IDPF_STATE_LAST,
  62. };
  63. /**
  64. * enum idpf_flags - Hard reset causes.
  65. * @IDPF_HR_FUNC_RESET: Hard reset when TxRx timeout
  66. * @IDPF_HR_DRV_LOAD: Set on driver load for a clean HW
  67. * @IDPF_HR_RESET_IN_PROG: Reset in progress
  68. * @IDPF_REMOVE_IN_PROG: Driver remove in progress
  69. * @IDPF_MB_INTR_MODE: Mailbox in interrupt mode
  70. * @IDPF_VC_CORE_INIT: virtchnl core has been init
  71. * @IDPF_FLAGS_NBITS: Must be last
  72. */
  73. enum idpf_flags {
  74. IDPF_HR_FUNC_RESET,
  75. IDPF_HR_DRV_LOAD,
  76. IDPF_HR_RESET_IN_PROG,
  77. IDPF_REMOVE_IN_PROG,
  78. IDPF_MB_INTR_MODE,
  79. IDPF_VC_CORE_INIT,
  80. IDPF_FLAGS_NBITS,
  81. };
  82. /**
  83. * enum idpf_cap_field - Offsets into capabilities struct for specific caps
  84. * @IDPF_BASE_CAPS: generic base capabilities
  85. * @IDPF_CSUM_CAPS: checksum offload capabilities
  86. * @IDPF_SEG_CAPS: segmentation offload capabilities
  87. * @IDPF_RSS_CAPS: RSS offload capabilities
  88. * @IDPF_HSPLIT_CAPS: Header split capabilities
  89. * @IDPF_RSC_CAPS: RSC offload capabilities
  90. * @IDPF_OTHER_CAPS: miscellaneous offloads
  91. *
  92. * Used when checking for a specific capability flag since different capability
  93. * sets are not mutually exclusive numerically, the caller must specify which
  94. * type of capability they are checking for.
  95. */
  96. enum idpf_cap_field {
  97. IDPF_BASE_CAPS = -1,
  98. IDPF_CSUM_CAPS = offsetof(struct virtchnl2_get_capabilities,
  99. csum_caps),
  100. IDPF_SEG_CAPS = offsetof(struct virtchnl2_get_capabilities,
  101. seg_caps),
  102. IDPF_RSS_CAPS = offsetof(struct virtchnl2_get_capabilities,
  103. rss_caps),
  104. IDPF_HSPLIT_CAPS = offsetof(struct virtchnl2_get_capabilities,
  105. hsplit_caps),
  106. IDPF_RSC_CAPS = offsetof(struct virtchnl2_get_capabilities,
  107. rsc_caps),
  108. IDPF_OTHER_CAPS = offsetof(struct virtchnl2_get_capabilities,
  109. other_caps),
  110. };
  111. /**
  112. * enum idpf_vport_state - Current vport state
  113. * @__IDPF_VPORT_DOWN: Vport is down
  114. * @__IDPF_VPORT_UP: Vport is up
  115. * @__IDPF_VPORT_STATE_LAST: Must be last, number of states
  116. */
  117. enum idpf_vport_state {
  118. __IDPF_VPORT_DOWN,
  119. __IDPF_VPORT_UP,
  120. __IDPF_VPORT_STATE_LAST,
  121. };
  122. /**
  123. * struct idpf_netdev_priv - Struct to store vport back pointer
  124. * @adapter: Adapter back pointer
  125. * @vport: Vport back pointer
  126. * @vport_id: Vport identifier
  127. * @link_speed_mbps: Link speed in mbps
  128. * @vport_idx: Relative vport index
  129. * @max_tx_hdr_size: Max header length hardware can support
  130. * @state: See enum idpf_vport_state
  131. * @netstats: Packet and byte stats
  132. * @stats_lock: Lock to protect stats update
  133. */
  134. struct idpf_netdev_priv {
  135. struct idpf_adapter *adapter;
  136. struct idpf_vport *vport;
  137. u32 vport_id;
  138. u32 link_speed_mbps;
  139. u16 vport_idx;
  140. u16 max_tx_hdr_size;
  141. enum idpf_vport_state state;
  142. struct rtnl_link_stats64 netstats;
  143. spinlock_t stats_lock;
  144. };
  145. /**
  146. * struct idpf_reset_reg - Reset register offsets/masks
  147. * @rstat: Reset status register
  148. * @rstat_m: Reset status mask
  149. */
  150. struct idpf_reset_reg {
  151. void __iomem *rstat;
  152. u32 rstat_m;
  153. };
  154. /**
  155. * struct idpf_vport_max_q - Queue limits
  156. * @max_rxq: Maximum number of RX queues supported
  157. * @max_txq: Maixmum number of TX queues supported
  158. * @max_bufq: In splitq, maximum number of buffer queues supported
  159. * @max_complq: In splitq, maximum number of completion queues supported
  160. */
  161. struct idpf_vport_max_q {
  162. u16 max_rxq;
  163. u16 max_txq;
  164. u16 max_bufq;
  165. u16 max_complq;
  166. };
  167. /**
  168. * struct idpf_reg_ops - Device specific register operation function pointers
  169. * @ctlq_reg_init: Mailbox control queue register initialization
  170. * @intr_reg_init: Traffic interrupt register initialization
  171. * @mb_intr_reg_init: Mailbox interrupt register initialization
  172. * @reset_reg_init: Reset register initialization
  173. * @trigger_reset: Trigger a reset to occur
  174. */
  175. struct idpf_reg_ops {
  176. void (*ctlq_reg_init)(struct idpf_ctlq_create_info *cq);
  177. int (*intr_reg_init)(struct idpf_vport *vport);
  178. void (*mb_intr_reg_init)(struct idpf_adapter *adapter);
  179. void (*reset_reg_init)(struct idpf_adapter *adapter);
  180. void (*trigger_reset)(struct idpf_adapter *adapter,
  181. enum idpf_flags trig_cause);
  182. };
  183. /**
  184. * struct idpf_dev_ops - Device specific operations
  185. * @reg_ops: Register operations
  186. */
  187. struct idpf_dev_ops {
  188. struct idpf_reg_ops reg_ops;
  189. };
  190. /**
  191. * enum idpf_vport_reset_cause - Vport soft reset causes
  192. * @IDPF_SR_Q_CHANGE: Soft reset queue change
  193. * @IDPF_SR_Q_DESC_CHANGE: Soft reset descriptor change
  194. * @IDPF_SR_MTU_CHANGE: Soft reset MTU change
  195. * @IDPF_SR_RSC_CHANGE: Soft reset RSC change
  196. */
  197. enum idpf_vport_reset_cause {
  198. IDPF_SR_Q_CHANGE,
  199. IDPF_SR_Q_DESC_CHANGE,
  200. IDPF_SR_MTU_CHANGE,
  201. IDPF_SR_RSC_CHANGE,
  202. };
  203. /**
  204. * enum idpf_vport_flags - Vport flags
  205. * @IDPF_VPORT_DEL_QUEUES: To send delete queues message
  206. * @IDPF_VPORT_SW_MARKER: Indicate TX pipe drain software marker packets
  207. * processing is done
  208. * @IDPF_VPORT_FLAGS_NBITS: Must be last
  209. */
  210. enum idpf_vport_flags {
  211. IDPF_VPORT_DEL_QUEUES,
  212. IDPF_VPORT_SW_MARKER,
  213. IDPF_VPORT_FLAGS_NBITS,
  214. };
  215. struct idpf_port_stats {
  216. struct u64_stats_sync stats_sync;
  217. u64_stats_t rx_hw_csum_err;
  218. u64_stats_t rx_hsplit;
  219. u64_stats_t rx_hsplit_hbo;
  220. u64_stats_t rx_bad_descs;
  221. u64_stats_t tx_linearize;
  222. u64_stats_t tx_busy;
  223. u64_stats_t tx_drops;
  224. u64_stats_t tx_dma_map_errs;
  225. struct virtchnl2_vport_stats vport_stats;
  226. };
  227. /**
  228. * struct idpf_vport - Handle for netdevices and queue resources
  229. * @num_txq: Number of allocated TX queues
  230. * @num_complq: Number of allocated completion queues
  231. * @txq_desc_count: TX queue descriptor count
  232. * @complq_desc_count: Completion queue descriptor count
  233. * @compln_clean_budget: Work budget for completion clean
  234. * @num_txq_grp: Number of TX queue groups
  235. * @txq_grps: Array of TX queue groups
  236. * @txq_model: Split queue or single queue queuing model
  237. * @txqs: Used only in hotpath to get to the right queue very fast
  238. * @crc_enable: Enable CRC insertion offload
  239. * @num_rxq: Number of allocated RX queues
  240. * @num_bufq: Number of allocated buffer queues
  241. * @rxq_desc_count: RX queue descriptor count. *MUST* have enough descriptors
  242. * to complete all buffer descriptors for all buffer queues in
  243. * the worst case.
  244. * @num_bufqs_per_qgrp: Buffer queues per RX queue in a given grouping
  245. * @bufq_desc_count: Buffer queue descriptor count
  246. * @num_rxq_grp: Number of RX queues in a group
  247. * @rxq_grps: Total number of RX groups. Number of groups * number of RX per
  248. * group will yield total number of RX queues.
  249. * @rxq_model: Splitq queue or single queue queuing model
  250. * @rx_ptype_lkup: Lookup table for ptypes on RX
  251. * @adapter: back pointer to associated adapter
  252. * @netdev: Associated net_device. Each vport should have one and only one
  253. * associated netdev.
  254. * @flags: See enum idpf_vport_flags
  255. * @vport_type: Default SRIOV, SIOV, etc.
  256. * @vport_id: Device given vport identifier
  257. * @idx: Software index in adapter vports struct
  258. * @default_vport: Use this vport if one isn't specified
  259. * @base_rxd: True if the driver should use base descriptors instead of flex
  260. * @num_q_vectors: Number of IRQ vectors allocated
  261. * @q_vectors: Array of queue vectors
  262. * @q_vector_idxs: Starting index of queue vectors
  263. * @max_mtu: device given max possible MTU
  264. * @default_mac_addr: device will give a default MAC to use
  265. * @rx_itr_profile: RX profiles for Dynamic Interrupt Moderation
  266. * @tx_itr_profile: TX profiles for Dynamic Interrupt Moderation
  267. * @port_stats: per port csum, header split, and other offload stats
  268. * @link_up: True if link is up
  269. * @sw_marker_wq: workqueue for marker packets
  270. */
  271. struct idpf_vport {
  272. u16 num_txq;
  273. u16 num_complq;
  274. u32 txq_desc_count;
  275. u32 complq_desc_count;
  276. u32 compln_clean_budget;
  277. u16 num_txq_grp;
  278. struct idpf_txq_group *txq_grps;
  279. u32 txq_model;
  280. struct idpf_tx_queue **txqs;
  281. bool crc_enable;
  282. u16 num_rxq;
  283. u16 num_bufq;
  284. u32 rxq_desc_count;
  285. u8 num_bufqs_per_qgrp;
  286. u32 bufq_desc_count[IDPF_MAX_BUFQS_PER_RXQ_GRP];
  287. u16 num_rxq_grp;
  288. struct idpf_rxq_group *rxq_grps;
  289. u32 rxq_model;
  290. struct libeth_rx_pt *rx_ptype_lkup;
  291. struct idpf_adapter *adapter;
  292. struct net_device *netdev;
  293. DECLARE_BITMAP(flags, IDPF_VPORT_FLAGS_NBITS);
  294. u16 vport_type;
  295. u32 vport_id;
  296. u16 idx;
  297. bool default_vport;
  298. bool base_rxd;
  299. u16 num_q_vectors;
  300. struct idpf_q_vector *q_vectors;
  301. u16 *q_vector_idxs;
  302. u16 max_mtu;
  303. u8 default_mac_addr[ETH_ALEN];
  304. u16 rx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
  305. u16 tx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
  306. struct idpf_port_stats port_stats;
  307. bool link_up;
  308. wait_queue_head_t sw_marker_wq;
  309. };
  310. /**
  311. * enum idpf_user_flags
  312. * @__IDPF_USER_FLAG_HSPLIT: header split state
  313. * @__IDPF_PROMISC_UC: Unicast promiscuous mode
  314. * @__IDPF_PROMISC_MC: Multicast promiscuous mode
  315. * @__IDPF_USER_FLAGS_NBITS: Must be last
  316. */
  317. enum idpf_user_flags {
  318. __IDPF_USER_FLAG_HSPLIT = 0U,
  319. __IDPF_PROMISC_UC = 32,
  320. __IDPF_PROMISC_MC,
  321. __IDPF_USER_FLAGS_NBITS,
  322. };
  323. /**
  324. * struct idpf_rss_data - Associated RSS data
  325. * @rss_key_size: Size of RSS hash key
  326. * @rss_key: RSS hash key
  327. * @rss_lut_size: Size of RSS lookup table
  328. * @rss_lut: RSS lookup table
  329. * @cached_lut: Used to restore previously init RSS lut
  330. */
  331. struct idpf_rss_data {
  332. u16 rss_key_size;
  333. u8 *rss_key;
  334. u16 rss_lut_size;
  335. u32 *rss_lut;
  336. u32 *cached_lut;
  337. };
  338. /**
  339. * struct idpf_q_coalesce - User defined coalescing configuration values for
  340. * a single queue.
  341. * @tx_intr_mode: Dynamic TX ITR or not
  342. * @rx_intr_mode: Dynamic RX ITR or not
  343. * @tx_coalesce_usecs: TX interrupt throttling rate
  344. * @rx_coalesce_usecs: RX interrupt throttling rate
  345. *
  346. * Used to restore user coalescing configuration after a reset.
  347. */
  348. struct idpf_q_coalesce {
  349. u32 tx_intr_mode;
  350. u32 rx_intr_mode;
  351. u32 tx_coalesce_usecs;
  352. u32 rx_coalesce_usecs;
  353. };
  354. /**
  355. * struct idpf_vport_user_config_data - User defined configuration values for
  356. * each vport.
  357. * @rss_data: See struct idpf_rss_data
  358. * @q_coalesce: Array of per queue coalescing data
  359. * @num_req_tx_qs: Number of user requested TX queues through ethtool
  360. * @num_req_rx_qs: Number of user requested RX queues through ethtool
  361. * @num_req_txq_desc: Number of user requested TX queue descriptors through
  362. * ethtool
  363. * @num_req_rxq_desc: Number of user requested RX queue descriptors through
  364. * ethtool
  365. * @user_flags: User toggled config flags
  366. * @mac_filter_list: List of MAC filters
  367. *
  368. * Used to restore configuration after a reset as the vport will get wiped.
  369. */
  370. struct idpf_vport_user_config_data {
  371. struct idpf_rss_data rss_data;
  372. struct idpf_q_coalesce *q_coalesce;
  373. u16 num_req_tx_qs;
  374. u16 num_req_rx_qs;
  375. u32 num_req_txq_desc;
  376. u32 num_req_rxq_desc;
  377. DECLARE_BITMAP(user_flags, __IDPF_USER_FLAGS_NBITS);
  378. struct list_head mac_filter_list;
  379. };
  380. /**
  381. * enum idpf_vport_config_flags - Vport config flags
  382. * @IDPF_VPORT_REG_NETDEV: Register netdev
  383. * @IDPF_VPORT_UP_REQUESTED: Set if interface up is requested on core reset
  384. * @IDPF_VPORT_CONFIG_FLAGS_NBITS: Must be last
  385. */
  386. enum idpf_vport_config_flags {
  387. IDPF_VPORT_REG_NETDEV,
  388. IDPF_VPORT_UP_REQUESTED,
  389. IDPF_VPORT_CONFIG_FLAGS_NBITS,
  390. };
  391. /**
  392. * struct idpf_avail_queue_info
  393. * @avail_rxq: Available RX queues
  394. * @avail_txq: Available TX queues
  395. * @avail_bufq: Available buffer queues
  396. * @avail_complq: Available completion queues
  397. *
  398. * Maintain total queues available after allocating max queues to each vport.
  399. */
  400. struct idpf_avail_queue_info {
  401. u16 avail_rxq;
  402. u16 avail_txq;
  403. u16 avail_bufq;
  404. u16 avail_complq;
  405. };
  406. /**
  407. * struct idpf_vector_info - Utility structure to pass function arguments as a
  408. * structure
  409. * @num_req_vecs: Vectors required based on the number of queues updated by the
  410. * user via ethtool
  411. * @num_curr_vecs: Current number of vectors, must be >= @num_req_vecs
  412. * @index: Relative starting index for vectors
  413. * @default_vport: Vectors are for default vport
  414. */
  415. struct idpf_vector_info {
  416. u16 num_req_vecs;
  417. u16 num_curr_vecs;
  418. u16 index;
  419. bool default_vport;
  420. };
  421. /**
  422. * struct idpf_vector_lifo - Stack to maintain vector indexes used for vector
  423. * distribution algorithm
  424. * @top: Points to stack top i.e. next available vector index
  425. * @base: Always points to start of the free pool
  426. * @size: Total size of the vector stack
  427. * @vec_idx: Array to store all the vector indexes
  428. *
  429. * Vector stack maintains all the relative vector indexes at the *adapter*
  430. * level. This stack is divided into 2 parts, first one is called as 'default
  431. * pool' and other one is called 'free pool'. Vector distribution algorithm
  432. * gives priority to default vports in a way that at least IDPF_MIN_Q_VEC
  433. * vectors are allocated per default vport and the relative vector indexes for
  434. * those are maintained in default pool. Free pool contains all the unallocated
  435. * vector indexes which can be allocated on-demand basis. Mailbox vector index
  436. * is maintained in the default pool of the stack.
  437. */
  438. struct idpf_vector_lifo {
  439. u16 top;
  440. u16 base;
  441. u16 size;
  442. u16 *vec_idx;
  443. };
  444. /**
  445. * struct idpf_vport_config - Vport configuration data
  446. * @user_config: see struct idpf_vport_user_config_data
  447. * @max_q: Maximum possible queues
  448. * @req_qs_chunks: Queue chunk data for requested queues
  449. * @mac_filter_list_lock: Lock to protect mac filters
  450. * @flags: See enum idpf_vport_config_flags
  451. */
  452. struct idpf_vport_config {
  453. struct idpf_vport_user_config_data user_config;
  454. struct idpf_vport_max_q max_q;
  455. struct virtchnl2_add_queues *req_qs_chunks;
  456. spinlock_t mac_filter_list_lock;
  457. DECLARE_BITMAP(flags, IDPF_VPORT_CONFIG_FLAGS_NBITS);
  458. };
  459. struct idpf_vc_xn_manager;
  460. /**
  461. * struct idpf_adapter - Device data struct generated on probe
  462. * @pdev: PCI device struct given on probe
  463. * @virt_ver_maj: Virtchnl version major
  464. * @virt_ver_min: Virtchnl version minor
  465. * @msg_enable: Debug message level enabled
  466. * @mb_wait_count: Number of times mailbox was attempted initialization
  467. * @state: Init state machine
  468. * @flags: See enum idpf_flags
  469. * @reset_reg: See struct idpf_reset_reg
  470. * @hw: Device access data
  471. * @num_req_msix: Requested number of MSIX vectors
  472. * @num_avail_msix: Available number of MSIX vectors
  473. * @num_msix_entries: Number of entries in MSIX table
  474. * @msix_entries: MSIX table
  475. * @req_vec_chunks: Requested vector chunk data
  476. * @mb_vector: Mailbox vector data
  477. * @vector_stack: Stack to store the msix vector indexes
  478. * @irq_mb_handler: Handler for hard interrupt for mailbox
  479. * @tx_timeout_count: Number of TX timeouts that have occurred
  480. * @avail_queues: Device given queue limits
  481. * @vports: Array to store vports created by the driver
  482. * @netdevs: Associated Vport netdevs
  483. * @vport_params_reqd: Vport params requested
  484. * @vport_params_recvd: Vport params received
  485. * @vport_ids: Array of device given vport identifiers
  486. * @vport_config: Vport config parameters
  487. * @max_vports: Maximum vports that can be allocated
  488. * @num_alloc_vports: Current number of vports allocated
  489. * @next_vport: Next free slot in pf->vport[] - 0-based!
  490. * @init_task: Initialization task
  491. * @init_wq: Workqueue for initialization task
  492. * @serv_task: Periodically recurring maintenance task
  493. * @serv_wq: Workqueue for service task
  494. * @mbx_task: Task to handle mailbox interrupts
  495. * @mbx_wq: Workqueue for mailbox responses
  496. * @vc_event_task: Task to handle out of band virtchnl event notifications
  497. * @vc_event_wq: Workqueue for virtchnl events
  498. * @stats_task: Periodic statistics retrieval task
  499. * @stats_wq: Workqueue for statistics task
  500. * @caps: Negotiated capabilities with device
  501. * @vcxn_mngr: Virtchnl transaction manager
  502. * @dev_ops: See idpf_dev_ops
  503. * @num_vfs: Number of allocated VFs through sysfs. PF does not directly talk
  504. * to VFs but is used to initialize them
  505. * @crc_enable: Enable CRC insertion offload
  506. * @req_tx_splitq: TX split or single queue model to request
  507. * @req_rx_splitq: RX split or single queue model to request
  508. * @vport_ctrl_lock: Lock to protect the vport control flow
  509. * @vector_lock: Lock to protect vector distribution
  510. * @queue_lock: Lock to protect queue distribution
  511. * @vc_buf_lock: Lock to protect virtchnl buffer
  512. */
  513. struct idpf_adapter {
  514. struct pci_dev *pdev;
  515. u32 virt_ver_maj;
  516. u32 virt_ver_min;
  517. u32 msg_enable;
  518. u32 mb_wait_count;
  519. enum idpf_state state;
  520. DECLARE_BITMAP(flags, IDPF_FLAGS_NBITS);
  521. struct idpf_reset_reg reset_reg;
  522. struct idpf_hw hw;
  523. u16 num_req_msix;
  524. u16 num_avail_msix;
  525. u16 num_msix_entries;
  526. struct msix_entry *msix_entries;
  527. struct virtchnl2_alloc_vectors *req_vec_chunks;
  528. struct idpf_q_vector mb_vector;
  529. struct idpf_vector_lifo vector_stack;
  530. irqreturn_t (*irq_mb_handler)(int irq, void *data);
  531. u32 tx_timeout_count;
  532. struct idpf_avail_queue_info avail_queues;
  533. struct idpf_vport **vports;
  534. struct net_device **netdevs;
  535. struct virtchnl2_create_vport **vport_params_reqd;
  536. struct virtchnl2_create_vport **vport_params_recvd;
  537. u32 *vport_ids;
  538. struct idpf_vport_config **vport_config;
  539. u16 max_vports;
  540. u16 num_alloc_vports;
  541. u16 next_vport;
  542. struct delayed_work init_task;
  543. struct workqueue_struct *init_wq;
  544. struct delayed_work serv_task;
  545. struct workqueue_struct *serv_wq;
  546. struct delayed_work mbx_task;
  547. struct workqueue_struct *mbx_wq;
  548. struct delayed_work vc_event_task;
  549. struct workqueue_struct *vc_event_wq;
  550. struct delayed_work stats_task;
  551. struct workqueue_struct *stats_wq;
  552. struct virtchnl2_get_capabilities caps;
  553. struct idpf_vc_xn_manager *vcxn_mngr;
  554. struct idpf_dev_ops dev_ops;
  555. int num_vfs;
  556. bool crc_enable;
  557. bool req_tx_splitq;
  558. bool req_rx_splitq;
  559. struct mutex vport_ctrl_lock;
  560. struct mutex vector_lock;
  561. struct mutex queue_lock;
  562. struct mutex vc_buf_lock;
  563. };
  564. /**
  565. * idpf_is_queue_model_split - check if queue model is split
  566. * @q_model: queue model single or split
  567. *
  568. * Returns true if queue model is split else false
  569. */
  570. static inline int idpf_is_queue_model_split(u16 q_model)
  571. {
  572. return !IS_ENABLED(CONFIG_IDPF_SINGLEQ) ||
  573. q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT;
  574. }
  575. #define idpf_is_cap_ena(adapter, field, flag) \
  576. idpf_is_capability_ena(adapter, false, field, flag)
  577. #define idpf_is_cap_ena_all(adapter, field, flag) \
  578. idpf_is_capability_ena(adapter, true, field, flag)
  579. bool idpf_is_capability_ena(struct idpf_adapter *adapter, bool all,
  580. enum idpf_cap_field field, u64 flag);
  581. #define IDPF_CAP_RSS (\
  582. VIRTCHNL2_CAP_RSS_IPV4_TCP |\
  583. VIRTCHNL2_CAP_RSS_IPV4_TCP |\
  584. VIRTCHNL2_CAP_RSS_IPV4_UDP |\
  585. VIRTCHNL2_CAP_RSS_IPV4_SCTP |\
  586. VIRTCHNL2_CAP_RSS_IPV4_OTHER |\
  587. VIRTCHNL2_CAP_RSS_IPV6_TCP |\
  588. VIRTCHNL2_CAP_RSS_IPV6_TCP |\
  589. VIRTCHNL2_CAP_RSS_IPV6_UDP |\
  590. VIRTCHNL2_CAP_RSS_IPV6_SCTP |\
  591. VIRTCHNL2_CAP_RSS_IPV6_OTHER)
  592. #define IDPF_CAP_RSC (\
  593. VIRTCHNL2_CAP_RSC_IPV4_TCP |\
  594. VIRTCHNL2_CAP_RSC_IPV6_TCP)
  595. #define IDPF_CAP_HSPLIT (\
  596. VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
  597. VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
  598. #define IDPF_CAP_TX_CSUM_L4V4 (\
  599. VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP |\
  600. VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP)
  601. #define IDPF_CAP_TX_CSUM_L4V6 (\
  602. VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP |\
  603. VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP)
  604. #define IDPF_CAP_RX_CSUM (\
  605. VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 |\
  606. VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP |\
  607. VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP |\
  608. VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP |\
  609. VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP)
  610. #define IDPF_CAP_TX_SCTP_CSUM (\
  611. VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP |\
  612. VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP)
  613. #define IDPF_CAP_TUNNEL_TX_CSUM (\
  614. VIRTCHNL2_CAP_TX_CSUM_L3_SINGLE_TUNNEL |\
  615. VIRTCHNL2_CAP_TX_CSUM_L4_SINGLE_TUNNEL)
  616. /**
  617. * idpf_get_reserved_vecs - Get reserved vectors
  618. * @adapter: private data struct
  619. */
  620. static inline u16 idpf_get_reserved_vecs(struct idpf_adapter *adapter)
  621. {
  622. return le16_to_cpu(adapter->caps.num_allocated_vectors);
  623. }
  624. /**
  625. * idpf_get_default_vports - Get default number of vports
  626. * @adapter: private data struct
  627. */
  628. static inline u16 idpf_get_default_vports(struct idpf_adapter *adapter)
  629. {
  630. return le16_to_cpu(adapter->caps.default_num_vports);
  631. }
  632. /**
  633. * idpf_get_max_vports - Get max number of vports
  634. * @adapter: private data struct
  635. */
  636. static inline u16 idpf_get_max_vports(struct idpf_adapter *adapter)
  637. {
  638. return le16_to_cpu(adapter->caps.max_vports);
  639. }
  640. /**
  641. * idpf_get_max_tx_bufs - Get max scatter-gather buffers supported by the device
  642. * @adapter: private data struct
  643. */
  644. static inline unsigned int idpf_get_max_tx_bufs(struct idpf_adapter *adapter)
  645. {
  646. return adapter->caps.max_sg_bufs_per_tx_pkt;
  647. }
  648. /**
  649. * idpf_get_min_tx_pkt_len - Get min packet length supported by the device
  650. * @adapter: private data struct
  651. */
  652. static inline u8 idpf_get_min_tx_pkt_len(struct idpf_adapter *adapter)
  653. {
  654. u8 pkt_len = adapter->caps.min_sso_packet_len;
  655. return pkt_len ? pkt_len : IDPF_TX_MIN_PKT_LEN;
  656. }
  657. /**
  658. * idpf_get_reg_addr - Get BAR0 register address
  659. * @adapter: private data struct
  660. * @reg_offset: register offset value
  661. *
  662. * Based on the register offset, return the actual BAR0 register address
  663. */
  664. static inline void __iomem *idpf_get_reg_addr(struct idpf_adapter *adapter,
  665. resource_size_t reg_offset)
  666. {
  667. return (void __iomem *)(adapter->hw.hw_addr + reg_offset);
  668. }
  669. /**
  670. * idpf_is_reset_detected - check if we were reset at some point
  671. * @adapter: driver specific private structure
  672. *
  673. * Returns true if we are either in reset currently or were previously reset.
  674. */
  675. static inline bool idpf_is_reset_detected(struct idpf_adapter *adapter)
  676. {
  677. if (!adapter->hw.arq)
  678. return true;
  679. return !(readl(idpf_get_reg_addr(adapter, adapter->hw.arq->reg.len)) &
  680. adapter->hw.arq->reg.len_mask);
  681. }
  682. /**
  683. * idpf_is_reset_in_prog - check if reset is in progress
  684. * @adapter: driver specific private structure
  685. *
  686. * Returns true if hard reset is in progress, false otherwise
  687. */
  688. static inline bool idpf_is_reset_in_prog(struct idpf_adapter *adapter)
  689. {
  690. return (test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags) ||
  691. test_bit(IDPF_HR_FUNC_RESET, adapter->flags) ||
  692. test_bit(IDPF_HR_DRV_LOAD, adapter->flags));
  693. }
  694. /**
  695. * idpf_netdev_to_vport - get a vport handle from a netdev
  696. * @netdev: network interface device structure
  697. */
  698. static inline struct idpf_vport *idpf_netdev_to_vport(struct net_device *netdev)
  699. {
  700. struct idpf_netdev_priv *np = netdev_priv(netdev);
  701. return np->vport;
  702. }
  703. /**
  704. * idpf_netdev_to_adapter - Get adapter handle from a netdev
  705. * @netdev: Network interface device structure
  706. */
  707. static inline struct idpf_adapter *idpf_netdev_to_adapter(struct net_device *netdev)
  708. {
  709. struct idpf_netdev_priv *np = netdev_priv(netdev);
  710. return np->adapter;
  711. }
  712. /**
  713. * idpf_is_feature_ena - Determine if a particular feature is enabled
  714. * @vport: Vport to check
  715. * @feature: Netdev flag to check
  716. *
  717. * Returns true or false if a particular feature is enabled.
  718. */
  719. static inline bool idpf_is_feature_ena(const struct idpf_vport *vport,
  720. netdev_features_t feature)
  721. {
  722. return vport->netdev->features & feature;
  723. }
  724. /**
  725. * idpf_get_max_tx_hdr_size -- get the size of tx header
  726. * @adapter: Driver specific private structure
  727. */
  728. static inline u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter)
  729. {
  730. return le16_to_cpu(adapter->caps.max_tx_hdr_size);
  731. }
  732. /**
  733. * idpf_vport_ctrl_lock - Acquire the vport control lock
  734. * @netdev: Network interface device structure
  735. *
  736. * This lock should be used by non-datapath code to protect against vport
  737. * destruction.
  738. */
  739. static inline void idpf_vport_ctrl_lock(struct net_device *netdev)
  740. {
  741. struct idpf_netdev_priv *np = netdev_priv(netdev);
  742. mutex_lock(&np->adapter->vport_ctrl_lock);
  743. }
  744. /**
  745. * idpf_vport_ctrl_unlock - Release the vport control lock
  746. * @netdev: Network interface device structure
  747. */
  748. static inline void idpf_vport_ctrl_unlock(struct net_device *netdev)
  749. {
  750. struct idpf_netdev_priv *np = netdev_priv(netdev);
  751. mutex_unlock(&np->adapter->vport_ctrl_lock);
  752. }
  753. void idpf_statistics_task(struct work_struct *work);
  754. void idpf_init_task(struct work_struct *work);
  755. void idpf_service_task(struct work_struct *work);
  756. void idpf_mbx_task(struct work_struct *work);
  757. void idpf_vc_event_task(struct work_struct *work);
  758. void idpf_dev_ops_init(struct idpf_adapter *adapter);
  759. void idpf_vf_dev_ops_init(struct idpf_adapter *adapter);
  760. int idpf_intr_req(struct idpf_adapter *adapter);
  761. void idpf_intr_rel(struct idpf_adapter *adapter);
  762. u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter);
  763. int idpf_initiate_soft_reset(struct idpf_vport *vport,
  764. enum idpf_vport_reset_cause reset_cause);
  765. void idpf_deinit_task(struct idpf_adapter *adapter);
  766. int idpf_req_rel_vector_indexes(struct idpf_adapter *adapter,
  767. u16 *q_vector_idxs,
  768. struct idpf_vector_info *vec_info);
  769. void idpf_set_ethtool_ops(struct net_device *netdev);
  770. void idpf_vport_intr_write_itr(struct idpf_q_vector *q_vector,
  771. u16 itr, bool tx);
  772. int idpf_sriov_configure(struct pci_dev *pdev, int num_vfs);
  773. u8 idpf_vport_get_hsplit(const struct idpf_vport *vport);
  774. bool idpf_vport_set_hsplit(const struct idpf_vport *vport, u8 val);
  775. #endif /* !_IDPF_H_ */