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