summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/fungible/funeth/funeth.h
blob: 1250e10d21db263c8d2bd10f290c887cc4f1ccca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */

#ifndef _FUNETH_H
#define _FUNETH_H

#include <uapi/linux/if_ether.h>
#include <uapi/linux/net_tstamp.h>
#include <linux/mutex.h>
#include <linux/seqlock.h>
#include <linux/xarray.h>
#include <net/devlink.h>
#include "fun_dev.h"

#define ADMIN_SQE_SIZE SZ_128
#define ADMIN_CQE_SIZE SZ_64
#define ADMIN_RSP_MAX_LEN (ADMIN_CQE_SIZE - sizeof(struct fun_cqe_info))

#define FUN_MAX_MTU 9024

#define SQ_DEPTH 512U
#define CQ_DEPTH 1024U
#define RQ_DEPTH (512U / (PAGE_SIZE / 4096))

#define CQ_INTCOAL_USEC 10
#define CQ_INTCOAL_NPKT 16
#define SQ_INTCOAL_USEC 10
#define SQ_INTCOAL_NPKT 16

#define INVALID_LPORT 0xffff

#define FUN_PORT_CAP_PAUSE_MASK (FUN_PORT_CAP_TX_PAUSE | FUN_PORT_CAP_RX_PAUSE)

struct fun_vport_info {
	u8 mac[ETH_ALEN];
	u16 vlan;
	__be16 vlan_proto;
	u8 qos;
	u8 spoofchk:1;
	u8 trusted:1;
	unsigned int max_rate;
};

/* "subclass" of fun_dev for Ethernet functions */
struct fun_ethdev {
	struct fun_dev fdev;

	/* the function's network ports */
	struct net_device **netdevs;
	unsigned int num_ports;

	/* configuration for the function's virtual ports */
	unsigned int num_vports;
	struct fun_vport_info *vport_info;

	struct mutex state_mutex; /* nests inside RTNL if both taken */

	unsigned int nsqs_per_port;
};

static inline struct fun_ethdev *to_fun_ethdev(struct fun_dev *p)
{
	return container_of(p, struct fun_ethdev, fdev);
}

struct fun_qset {
	struct funeth_rxq **rxqs;
	struct funeth_txq **txqs;
	struct funeth_txq **xdpqs;
	unsigned int nrxqs;
	unsigned int ntxqs;
	unsigned int nxdpqs;
	unsigned int rxq_start;
	unsigned int txq_start;
	unsigned int xdpq_start;
	unsigned int cq_depth;
	unsigned int rq_depth;
	unsigned int sq_depth;
	int state;
};

/* Per netdevice driver state, i.e., netdev_priv. */
struct funeth_priv {
	struct fun_dev *fdev;
	struct pci_dev *pdev;
	struct net_device *netdev;

	struct funeth_rxq * __rcu *rxqs;
	struct funeth_txq **txqs;
	struct funeth_txq * __rcu *xdpqs;

	struct xarray irqs;
	unsigned int num_tx_irqs;
	unsigned int num_rx_irqs;
	unsigned int rx_irq_ofst;

	unsigned int lane_attrs;
	u16 lport;

	/* link settings */
	u64 port_caps;
	u64 advertising;
	u64 lp_advertising;
	unsigned int link_speed;
	u8 xcvr_type;
	u8 active_fc;
	u8 active_fec;
	u8 link_down_reason;
	seqcount_t link_seq;

	u32 msg_enable;

	unsigned int num_xdpqs;

	/* ethtool, etc. config parameters */
	unsigned int sq_depth;
	unsigned int rq_depth;
	unsigned int cq_depth;
	unsigned int cq_irq_db;
	u8 tx_coal_usec;
	u8 tx_coal_count;
	u8 rx_coal_usec;
	u8 rx_coal_count;

	struct hwtstamp_config hwtstamp_cfg;

	/* cumulative queue stats from earlier queue instances */
	u64 tx_packets;
	u64 tx_bytes;
	u64 tx_dropped;
	u64 rx_packets;
	u64 rx_bytes;
	u64 rx_dropped;

	/* RSS */
	unsigned int rss_hw_id;
	enum fun_eth_hash_alg hash_algo;
	u8 rss_key[FUN_ETH_RSS_MAX_KEY_SIZE];
	unsigned int indir_table_nentries;
	u32 indir_table[FUN_ETH_RSS_MAX_INDIR_ENT];
	dma_addr_t rss_dma_addr;
	void *rss_cfg;

	/* DMA area for port stats */
	dma_addr_t stats_dma_addr;
	__be64 *stats;

	struct bpf_prog *xdp_prog;

	struct devlink_port dl_port;

	/* kTLS state */
	unsigned int ktls_id;
	atomic64_t tx_tls_add;
	atomic64_t tx_tls_del;
	atomic64_t tx_tls_resync;
};

void fun_set_ethtool_ops(struct net_device *netdev);
int fun_port_write_cmd(struct funeth_priv *fp, int key, u64 data);
int fun_port_read_cmd(struct funeth_priv *fp, int key, u64 *data);
int fun_create_and_bind_tx(struct funeth_priv *fp, u32 sqid);
int fun_replace_queues(struct net_device *dev, struct fun_qset *newqs,
		       struct netlink_ext_ack *extack);
int fun_change_num_queues(struct net_device *dev, unsigned int ntx,
			  unsigned int nrx);
void fun_set_ring_count(struct net_device *netdev, unsigned int ntx,
			unsigned int nrx);
int fun_config_rss(struct net_device *dev, int algo, const u8 *key,
		   const u32 *qtable, u8 op);

#endif /* _FUNETH_H */