funeth.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
  2. #ifndef _FUNETH_H
  3. #define _FUNETH_H
  4. #include <uapi/linux/if_ether.h>
  5. #include <uapi/linux/net_tstamp.h>
  6. #include <linux/mutex.h>
  7. #include <linux/seqlock.h>
  8. #include <linux/xarray.h>
  9. #include <net/devlink.h>
  10. #include "fun_dev.h"
  11. #define ADMIN_SQE_SIZE SZ_128
  12. #define ADMIN_CQE_SIZE SZ_64
  13. #define ADMIN_RSP_MAX_LEN (ADMIN_CQE_SIZE - sizeof(struct fun_cqe_info))
  14. #define FUN_MAX_MTU 9024
  15. #define SQ_DEPTH 512U
  16. #define CQ_DEPTH 1024U
  17. #define RQ_DEPTH (512U / (PAGE_SIZE / 4096))
  18. #define CQ_INTCOAL_USEC 10
  19. #define CQ_INTCOAL_NPKT 16
  20. #define SQ_INTCOAL_USEC 10
  21. #define SQ_INTCOAL_NPKT 16
  22. #define INVALID_LPORT 0xffff
  23. #define FUN_PORT_CAP_PAUSE_MASK (FUN_PORT_CAP_TX_PAUSE | FUN_PORT_CAP_RX_PAUSE)
  24. struct fun_vport_info {
  25. u8 mac[ETH_ALEN];
  26. u16 vlan;
  27. __be16 vlan_proto;
  28. u8 qos;
  29. u8 spoofchk:1;
  30. u8 trusted:1;
  31. unsigned int max_rate;
  32. };
  33. /* "subclass" of fun_dev for Ethernet functions */
  34. struct fun_ethdev {
  35. struct fun_dev fdev;
  36. /* the function's network ports */
  37. struct net_device **netdevs;
  38. unsigned int num_ports;
  39. /* configuration for the function's virtual ports */
  40. unsigned int num_vports;
  41. struct fun_vport_info *vport_info;
  42. struct mutex state_mutex; /* nests inside RTNL if both taken */
  43. unsigned int nsqs_per_port;
  44. };
  45. static inline struct fun_ethdev *to_fun_ethdev(struct fun_dev *p)
  46. {
  47. return container_of(p, struct fun_ethdev, fdev);
  48. }
  49. struct fun_qset {
  50. struct funeth_rxq **rxqs;
  51. struct funeth_txq **txqs;
  52. struct funeth_txq **xdpqs;
  53. unsigned int nrxqs;
  54. unsigned int ntxqs;
  55. unsigned int nxdpqs;
  56. unsigned int rxq_start;
  57. unsigned int txq_start;
  58. unsigned int xdpq_start;
  59. unsigned int cq_depth;
  60. unsigned int rq_depth;
  61. unsigned int sq_depth;
  62. int state;
  63. };
  64. /* Per netdevice driver state, i.e., netdev_priv. */
  65. struct funeth_priv {
  66. struct fun_dev *fdev;
  67. struct pci_dev *pdev;
  68. struct net_device *netdev;
  69. struct funeth_rxq * __rcu *rxqs;
  70. struct funeth_txq **txqs;
  71. struct funeth_txq * __rcu *xdpqs;
  72. struct xarray irqs;
  73. unsigned int num_tx_irqs;
  74. unsigned int num_rx_irqs;
  75. unsigned int rx_irq_ofst;
  76. unsigned int lane_attrs;
  77. u16 lport;
  78. /* link settings */
  79. u64 port_caps;
  80. u64 advertising;
  81. u64 lp_advertising;
  82. unsigned int link_speed;
  83. u8 xcvr_type;
  84. u8 active_fc;
  85. u8 active_fec;
  86. u8 link_down_reason;
  87. seqcount_t link_seq;
  88. u32 msg_enable;
  89. unsigned int num_xdpqs;
  90. /* ethtool, etc. config parameters */
  91. unsigned int sq_depth;
  92. unsigned int rq_depth;
  93. unsigned int cq_depth;
  94. unsigned int cq_irq_db;
  95. u8 tx_coal_usec;
  96. u8 tx_coal_count;
  97. u8 rx_coal_usec;
  98. u8 rx_coal_count;
  99. struct hwtstamp_config hwtstamp_cfg;
  100. /* cumulative queue stats from earlier queue instances */
  101. u64 tx_packets;
  102. u64 tx_bytes;
  103. u64 tx_dropped;
  104. u64 rx_packets;
  105. u64 rx_bytes;
  106. u64 rx_dropped;
  107. /* RSS */
  108. unsigned int rss_hw_id;
  109. enum fun_eth_hash_alg hash_algo;
  110. u8 rss_key[FUN_ETH_RSS_MAX_KEY_SIZE];
  111. unsigned int indir_table_nentries;
  112. u32 indir_table[FUN_ETH_RSS_MAX_INDIR_ENT];
  113. dma_addr_t rss_dma_addr;
  114. void *rss_cfg;
  115. /* DMA area for port stats */
  116. dma_addr_t stats_dma_addr;
  117. __be64 *stats;
  118. struct bpf_prog *xdp_prog;
  119. struct devlink_port dl_port;
  120. /* kTLS state */
  121. unsigned int ktls_id;
  122. atomic64_t tx_tls_add;
  123. atomic64_t tx_tls_del;
  124. atomic64_t tx_tls_resync;
  125. };
  126. void fun_set_ethtool_ops(struct net_device *netdev);
  127. int fun_port_write_cmd(struct funeth_priv *fp, int key, u64 data);
  128. int fun_port_read_cmd(struct funeth_priv *fp, int key, u64 *data);
  129. int fun_create_and_bind_tx(struct funeth_priv *fp, u32 sqid);
  130. int fun_replace_queues(struct net_device *dev, struct fun_qset *newqs,
  131. struct netlink_ext_ack *extack);
  132. int fun_change_num_queues(struct net_device *dev, unsigned int ntx,
  133. unsigned int nrx);
  134. void fun_set_ring_count(struct net_device *netdev, unsigned int ntx,
  135. unsigned int nrx);
  136. int fun_config_rss(struct net_device *dev, int algo, const u8 *key,
  137. const u32 *qtable, u8 op);
  138. #endif /* _FUNETH_H */