1 /* SPDX-License-Identifier: GPL-2.0 */
9 #include <linux/platform_device.h>
10 #include <linux/dma-mapping.h>
11 #include <linux/etherdevice.h>
12 #include <linux/phy.h>
13 #include <linux/ethtool.h>
14 #include <linux/net_tstamp.h>
15 #include <linux/ptp_clock_kernel.h>
16 #include <linux/miscdevice.h>
21 #define TSNEP_RING_SIZE 256
22 #define TSNEP_RING_MASK (TSNEP_RING_SIZE - 1)
23 #define TSNEP_RING_RX_REFILL 16
24 #define TSNEP_RING_RX_REUSE (TSNEP_RING_SIZE - TSNEP_RING_SIZE / 4)
25 #define TSNEP_RING_ENTRIES_PER_PAGE (PAGE_SIZE / TSNEP_DESC_SIZE)
26 #define TSNEP_RING_PAGE_COUNT (TSNEP_RING_SIZE / TSNEP_RING_ENTRIES_PER_PAGE)
33 u64 cycle_time_extension;
35 struct tsnep_gcl_operation operation[TSNEP_GCL_COUNT];
44 enum tsnep_rxnfc_filter_type {
45 TSNEP_RXNFC_ETHER_TYPE,
48 struct tsnep_rxnfc_filter {
49 enum tsnep_rxnfc_filter_type type;
55 struct tsnep_rxnfc_rule {
56 struct list_head list;
57 struct tsnep_rxnfc_filter filter;
62 struct tsnep_tx_entry {
63 struct tsnep_tx_desc *desc;
64 struct tsnep_tx_desc_wb *desc_wb;
73 struct xdp_frame *xdpf;
77 DEFINE_DMA_UNMAP_ADDR(dma);
81 struct tsnep_adapter *adapter;
85 void *page[TSNEP_RING_PAGE_COUNT];
86 dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
88 struct tsnep_tx_entry entry[TSNEP_RING_SIZE];
92 int increment_owner_counter;
93 struct xsk_buff_pool *xsk_pool;
100 struct tsnep_rx_entry {
101 struct tsnep_rx_desc *desc;
102 struct tsnep_rx_desc_wb *desc_wb;
109 struct xdp_buff *xdp;
116 struct tsnep_adapter *adapter;
121 void *page[TSNEP_RING_PAGE_COUNT];
122 dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
124 struct tsnep_rx_entry entry[TSNEP_RING_SIZE];
128 int increment_owner_counter;
129 struct page_pool *page_pool;
130 struct page **page_buffer;
131 struct xsk_buff_pool *xsk_pool;
132 struct xdp_buff **xdp_batch;
140 struct xdp_rxq_info xdp_rxq;
141 struct xdp_rxq_info xdp_rxq_zc;
145 struct tsnep_adapter *adapter;
146 char name[IFNAMSIZ + 16];
151 struct napi_struct napi;
155 void __iomem *irq_delay_addr;
159 struct tsnep_adapter {
160 struct net_device *netdev;
161 u8 mac_address[ETH_ALEN];
162 struct mii_bus *mdiobus;
163 bool suppress_preamble;
164 phy_interface_t phy_mode;
165 struct phy_device *phydev;
168 struct platform_device *pdev;
169 struct device *dmadev;
173 /* gate control lock */
174 struct mutex gate_control_lock;
175 bool gate_control_active;
176 struct tsnep_gcl gcl[2];
179 struct hwtstamp_config hwtstamp_config;
180 struct ptp_clock *ptp_clock;
181 struct ptp_clock_info ptp_clock_info;
185 /* RX flow classification rules lock */
186 struct mutex rxnfc_lock;
187 struct list_head rxnfc_rules;
191 struct bpf_prog *xdp_prog;
194 struct tsnep_tx tx[TSNEP_MAX_QUEUES];
196 struct tsnep_rx rx[TSNEP_MAX_QUEUES];
199 struct tsnep_queue queue[TSNEP_MAX_QUEUES];
202 extern const struct ethtool_ops tsnep_ethtool_ops;
204 int tsnep_ptp_init(struct tsnep_adapter *adapter);
205 void tsnep_ptp_cleanup(struct tsnep_adapter *adapter);
206 int tsnep_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
208 int tsnep_tc_init(struct tsnep_adapter *adapter);
209 void tsnep_tc_cleanup(struct tsnep_adapter *adapter);
210 int tsnep_tc_setup(struct net_device *netdev, enum tc_setup_type type,
213 int tsnep_rxnfc_init(struct tsnep_adapter *adapter);
214 void tsnep_rxnfc_cleanup(struct tsnep_adapter *adapter);
215 int tsnep_rxnfc_get_rule(struct tsnep_adapter *adapter,
216 struct ethtool_rxnfc *cmd);
217 int tsnep_rxnfc_get_all(struct tsnep_adapter *adapter,
218 struct ethtool_rxnfc *cmd,
220 int tsnep_rxnfc_add_rule(struct tsnep_adapter *adapter,
221 struct ethtool_rxnfc *cmd);
222 int tsnep_rxnfc_del_rule(struct tsnep_adapter *adapter,
223 struct ethtool_rxnfc *cmd);
225 int tsnep_xdp_setup_prog(struct tsnep_adapter *adapter, struct bpf_prog *prog,
226 struct netlink_ext_ack *extack);
227 int tsnep_xdp_setup_pool(struct tsnep_adapter *adapter,
228 struct xsk_buff_pool *pool, u16 queue_id);
230 #if IS_ENABLED(CONFIG_TSNEP_SELFTESTS)
231 int tsnep_ethtool_get_test_count(void);
232 void tsnep_ethtool_get_test_strings(u8 *data);
233 void tsnep_ethtool_self_test(struct net_device *netdev,
234 struct ethtool_test *eth_test, u64 *data);
236 static inline int tsnep_ethtool_get_test_count(void)
241 static inline void tsnep_ethtool_get_test_strings(u8 *data)
246 static inline void tsnep_ethtool_self_test(struct net_device *dev,
247 struct ethtool_test *eth_test,
252 #endif /* CONFIG_TSNEP_SELFTESTS */
254 void tsnep_get_system_time(struct tsnep_adapter *adapter, u64 *time);
255 int tsnep_set_irq_coalesce(struct tsnep_queue *queue, u32 usecs);
256 u32 tsnep_get_irq_coalesce(struct tsnep_queue *queue);
257 int tsnep_enable_xsk(struct tsnep_queue *queue, struct xsk_buff_pool *pool);
258 void tsnep_disable_xsk(struct tsnep_queue *queue);
260 #endif /* _TSNEP_H */