1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2021 Gerhard Engleder <gerhard@engleder-embedded.com> */
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>
20 #define TSNEP_RING_SIZE 256
21 #define TSNEP_RING_ENTRIES_PER_PAGE (PAGE_SIZE / TSNEP_DESC_SIZE)
22 #define TSNEP_RING_PAGE_COUNT (TSNEP_RING_SIZE / TSNEP_RING_ENTRIES_PER_PAGE)
24 #define TSNEP_QUEUES 1
31 u64 cycle_time_extension;
33 struct tsnep_gcl_operation operation[TSNEP_GCL_COUNT];
42 struct tsnep_tx_entry {
43 struct tsnep_tx_desc *desc;
44 struct tsnep_tx_desc_wb *desc_wb;
52 DEFINE_DMA_UNMAP_ADDR(dma);
56 struct tsnep_adapter *adapter;
59 void *page[TSNEP_RING_PAGE_COUNT];
60 dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
64 struct tsnep_tx_entry entry[TSNEP_RING_SIZE];
68 int increment_owner_counter;
75 struct tsnep_rx_entry {
76 struct tsnep_rx_desc *desc;
77 struct tsnep_rx_desc_wb *desc_wb;
84 DEFINE_DMA_UNMAP_ADDR(dma);
88 struct tsnep_adapter *adapter;
91 void *page[TSNEP_RING_PAGE_COUNT];
92 dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
94 struct tsnep_rx_entry entry[TSNEP_RING_SIZE];
97 int increment_owner_counter;
106 struct tsnep_adapter *adapter;
111 struct napi_struct napi;
116 struct tsnep_adapter {
117 struct net_device *netdev;
118 u8 mac_address[ETH_ALEN];
119 struct mii_bus *mdiobus;
120 bool suppress_preamble;
121 phy_interface_t phy_mode;
122 struct phy_device *phydev;
125 struct platform_device *pdev;
126 struct device *dmadev;
131 /* gate control lock */
132 struct mutex gate_control_lock;
133 bool gate_control_active;
134 struct tsnep_gcl gcl[2];
137 struct hwtstamp_config hwtstamp_config;
138 struct ptp_clock *ptp_clock;
139 struct ptp_clock_info ptp_clock_info;
144 struct tsnep_tx tx[TSNEP_MAX_QUEUES];
146 struct tsnep_rx rx[TSNEP_MAX_QUEUES];
149 struct tsnep_queue queue[TSNEP_MAX_QUEUES];
152 extern const struct ethtool_ops tsnep_ethtool_ops;
154 int tsnep_ptp_init(struct tsnep_adapter *adapter);
155 void tsnep_ptp_cleanup(struct tsnep_adapter *adapter);
156 int tsnep_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
158 int tsnep_tc_init(struct tsnep_adapter *adapter);
159 void tsnep_tc_cleanup(struct tsnep_adapter *adapter);
160 int tsnep_tc_setup(struct net_device *netdev, enum tc_setup_type type,
163 #if IS_ENABLED(CONFIG_TSNEP_SELFTESTS)
164 int tsnep_ethtool_get_test_count(void);
165 void tsnep_ethtool_get_test_strings(u8 *data);
166 void tsnep_ethtool_self_test(struct net_device *netdev,
167 struct ethtool_test *eth_test, u64 *data);
169 static inline int tsnep_ethtool_get_test_count(void)
174 static inline void tsnep_ethtool_get_test_strings(u8 *data)
179 static inline void tsnep_ethtool_self_test(struct net_device *dev,
180 struct ethtool_test *eth_test,
185 #endif /* CONFIG_TSNEP_SELFTESTS */
187 void tsnep_get_system_time(struct tsnep_adapter *adapter, u64 *time);
189 #endif /* _TSNEP_H */