xref: /linux/drivers/net/ethernet/stmicro/stmmac/stmmac.h (revision 31d166642c7c601c65eccf0ff2e0afe9a0538be2)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*******************************************************************************
3   Copyright (C) 2007-2009  STMicroelectronics Ltd
4 
5 
6   Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
7 *******************************************************************************/
8 
9 #ifndef __STMMAC_H__
10 #define __STMMAC_H__
11 
12 #define STMMAC_RESOURCE_NAME   "stmmaceth"
13 #define DRV_MODULE_VERSION	"Jan_2016"
14 
15 #include <linux/clk.h>
16 #include <linux/stmmac.h>
17 #include <linux/phylink.h>
18 #include <linux/pci.h>
19 #include "common.h"
20 #include <linux/ptp_clock_kernel.h>
21 #include <linux/net_tstamp.h>
22 #include <linux/reset.h>
23 
24 struct stmmac_resources {
25 	void __iomem *addr;
26 	const char *mac;
27 	int wol_irq;
28 	int lpi_irq;
29 	int irq;
30 };
31 
32 struct stmmac_tx_info {
33 	dma_addr_t buf;
34 	bool map_as_page;
35 	unsigned len;
36 	bool last_segment;
37 	bool is_jumbo;
38 };
39 
40 /* Frequently used values are kept adjacent for cache effect */
41 struct stmmac_tx_queue {
42 	u32 tx_count_frames;
43 	struct timer_list txtimer;
44 	u32 queue_index;
45 	struct stmmac_priv *priv_data;
46 	struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
47 	struct dma_desc *dma_tx;
48 	struct sk_buff **tx_skbuff;
49 	struct stmmac_tx_info *tx_skbuff_dma;
50 	unsigned int cur_tx;
51 	unsigned int dirty_tx;
52 	dma_addr_t dma_tx_phy;
53 	u32 tx_tail_addr;
54 	u32 mss;
55 };
56 
57 struct stmmac_rx_queue {
58 	u32 queue_index;
59 	struct stmmac_priv *priv_data;
60 	struct dma_extended_desc *dma_erx;
61 	struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
62 	struct sk_buff **rx_skbuff;
63 	dma_addr_t *rx_skbuff_dma;
64 	unsigned int cur_rx;
65 	unsigned int dirty_rx;
66 	u32 rx_zeroc_thresh;
67 	dma_addr_t dma_rx_phy;
68 	u32 rx_tail_addr;
69 };
70 
71 struct stmmac_channel {
72 	struct napi_struct rx_napi ____cacheline_aligned_in_smp;
73 	struct napi_struct tx_napi ____cacheline_aligned_in_smp;
74 	struct stmmac_priv *priv_data;
75 	u32 index;
76 };
77 
78 struct stmmac_tc_entry {
79 	bool in_use;
80 	bool in_hw;
81 	bool is_last;
82 	bool is_frag;
83 	void *frag_ptr;
84 	unsigned int table_pos;
85 	u32 handle;
86 	u32 prio;
87 	struct {
88 		u32 match_data;
89 		u32 match_en;
90 		u8 af:1;
91 		u8 rf:1;
92 		u8 im:1;
93 		u8 nc:1;
94 		u8 res1:4;
95 		u8 frame_offset;
96 		u8 ok_index;
97 		u8 dma_ch_no;
98 		u32 res2;
99 	} __packed val;
100 };
101 
102 #define STMMAC_PPS_MAX		4
103 struct stmmac_pps_cfg {
104 	bool available;
105 	struct timespec64 start;
106 	struct timespec64 period;
107 };
108 
109 struct stmmac_priv {
110 	/* Frequently used values are kept adjacent for cache effect */
111 	u32 tx_coal_frames;
112 	u32 tx_coal_timer;
113 
114 	int tx_coalesce;
115 	int hwts_tx_en;
116 	bool tx_path_in_lpi_mode;
117 	bool tso;
118 
119 	unsigned int dma_buf_sz;
120 	unsigned int rx_copybreak;
121 	u32 rx_riwt;
122 	int hwts_rx_en;
123 
124 	void __iomem *ioaddr;
125 	struct net_device *dev;
126 	struct device *device;
127 	struct mac_device_info *hw;
128 	int (*hwif_quirks)(struct stmmac_priv *priv);
129 	struct mutex lock;
130 
131 	/* RX Queue */
132 	struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
133 
134 	/* TX Queue */
135 	struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
136 
137 	/* Generic channel for NAPI */
138 	struct stmmac_channel channel[STMMAC_CH_MAX];
139 
140 	int speed;
141 	unsigned int flow_ctrl;
142 	unsigned int pause;
143 	struct mii_bus *mii;
144 	int mii_irq[PHY_MAX_ADDR];
145 
146 	struct phylink_config phylink_config;
147 	struct phylink *phylink;
148 
149 	struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
150 	struct stmmac_safety_stats sstats;
151 	struct plat_stmmacenet_data *plat;
152 	struct dma_features dma_cap;
153 	struct stmmac_counters mmc;
154 	int hw_cap_support;
155 	int synopsys_id;
156 	u32 msg_enable;
157 	int wolopts;
158 	int wol_irq;
159 	int clk_csr;
160 	struct timer_list eee_ctrl_timer;
161 	int lpi_irq;
162 	int eee_enabled;
163 	int eee_active;
164 	int tx_lpi_timer;
165 	unsigned int mode;
166 	unsigned int chain_mode;
167 	int extend_desc;
168 	struct hwtstamp_config tstamp_config;
169 	struct ptp_clock *ptp_clock;
170 	struct ptp_clock_info ptp_clock_ops;
171 	unsigned int default_addend;
172 	u32 sub_second_inc;
173 	u32 systime_flags;
174 	u32 adv_ts;
175 	int use_riwt;
176 	int irq_wake;
177 	spinlock_t ptp_lock;
178 	void __iomem *mmcaddr;
179 	void __iomem *ptpaddr;
180 
181 #ifdef CONFIG_DEBUG_FS
182 	struct dentry *dbgfs_dir;
183 	struct dentry *dbgfs_rings_status;
184 	struct dentry *dbgfs_dma_cap;
185 #endif
186 
187 	unsigned long state;
188 	struct workqueue_struct *wq;
189 	struct work_struct service_task;
190 
191 	/* TC Handling */
192 	unsigned int tc_entries_max;
193 	unsigned int tc_off_max;
194 	struct stmmac_tc_entry *tc_entries;
195 
196 	/* Pulse Per Second output */
197 	struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
198 };
199 
200 enum stmmac_state {
201 	STMMAC_DOWN,
202 	STMMAC_RESET_REQUESTED,
203 	STMMAC_RESETING,
204 	STMMAC_SERVICE_SCHED,
205 };
206 
207 int stmmac_mdio_unregister(struct net_device *ndev);
208 int stmmac_mdio_register(struct net_device *ndev);
209 int stmmac_mdio_reset(struct mii_bus *mii);
210 void stmmac_set_ethtool_ops(struct net_device *netdev);
211 
212 void stmmac_ptp_register(struct stmmac_priv *priv);
213 void stmmac_ptp_unregister(struct stmmac_priv *priv);
214 int stmmac_resume(struct device *dev);
215 int stmmac_suspend(struct device *dev);
216 int stmmac_dvr_remove(struct device *dev);
217 int stmmac_dvr_probe(struct device *device,
218 		     struct plat_stmmacenet_data *plat_dat,
219 		     struct stmmac_resources *res);
220 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
221 bool stmmac_eee_init(struct stmmac_priv *priv);
222 
223 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
224 void stmmac_selftest_run(struct net_device *dev,
225 			 struct ethtool_test *etest, u64 *buf);
226 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
227 int stmmac_selftest_get_count(struct stmmac_priv *priv);
228 #else
229 static inline void stmmac_selftest_run(struct net_device *dev,
230 				       struct ethtool_test *etest, u64 *buf)
231 {
232 	/* Not enabled */
233 }
234 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
235 					       u8 *data)
236 {
237 	/* Not enabled */
238 }
239 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
240 {
241 	return -EOPNOTSUPP;
242 }
243 #endif /* CONFIG_STMMAC_SELFTESTS */
244 
245 #endif /* __STMMAC_H__ */
246