xref: /openbmc/linux/drivers/net/ethernet/intel/e1000e/e1000.h (revision 87832e937c808a7ebc41254b408362e3255c87c9)
1ae06c70bSJeff Kirsher /* SPDX-License-Identifier: GPL-2.0 */
251dce24bSJeff Kirsher /* Copyright(c) 1999 - 2018 Intel Corporation. */
3dee1ad47SJeff Kirsher 
4dee1ad47SJeff Kirsher /* Linux PRO/1000 Ethernet Driver main header file */
5dee1ad47SJeff Kirsher 
6dee1ad47SJeff Kirsher #ifndef _E1000_H_
7dee1ad47SJeff Kirsher #define _E1000_H_
8dee1ad47SJeff Kirsher 
9dee1ad47SJeff Kirsher #include <linux/bitops.h>
10dee1ad47SJeff Kirsher #include <linux/types.h>
11dee1ad47SJeff Kirsher #include <linux/timer.h>
12dee1ad47SJeff Kirsher #include <linux/workqueue.h>
13dee1ad47SJeff Kirsher #include <linux/io.h>
14dee1ad47SJeff Kirsher #include <linux/netdevice.h>
15dee1ad47SJeff Kirsher #include <linux/pci.h>
16dee1ad47SJeff Kirsher #include <linux/crc32.h>
17dee1ad47SJeff Kirsher #include <linux/if_vlan.h>
1874d23cc7SRichard Cochran #include <linux/timecounter.h>
19b67e1913SBruce Allan #include <linux/net_tstamp.h>
20d89777bfSBruce Allan #include <linux/ptp_clock_kernel.h>
21d89777bfSBruce Allan #include <linux/ptp_classify.h>
22c2ade1a4SBruce Allan #include <linux/mii.h>
23d495bcb8SBruce Allan #include <linux/mdio.h>
246042d434SHao Chen #include <linux/mutex.h>
255684044fSDavid Ahern #include <linux/pm_qos.h>
26dee1ad47SJeff Kirsher #include "hw.h"
27dee1ad47SJeff Kirsher 
28dee1ad47SJeff Kirsher struct e1000_info;
29dee1ad47SJeff Kirsher 
30dee1ad47SJeff Kirsher #define e_dbg(format, arg...) \
31dee1ad47SJeff Kirsher 	netdev_dbg(hw->adapter->netdev, format, ## arg)
32dee1ad47SJeff Kirsher #define e_err(format, arg...) \
33dee1ad47SJeff Kirsher 	netdev_err(adapter->netdev, format, ## arg)
34dee1ad47SJeff Kirsher #define e_info(format, arg...) \
35dee1ad47SJeff Kirsher 	netdev_info(adapter->netdev, format, ## arg)
36dee1ad47SJeff Kirsher #define e_warn(format, arg...) \
37dee1ad47SJeff Kirsher 	netdev_warn(adapter->netdev, format, ## arg)
38dee1ad47SJeff Kirsher #define e_notice(format, arg...) \
39dee1ad47SJeff Kirsher 	netdev_notice(adapter->netdev, format, ## arg)
40dee1ad47SJeff Kirsher 
41dee1ad47SJeff Kirsher /* Interrupt modes, as used by the IntMode parameter */
42dee1ad47SJeff Kirsher #define E1000E_INT_MODE_LEGACY		0
43dee1ad47SJeff Kirsher #define E1000E_INT_MODE_MSI		1
44dee1ad47SJeff Kirsher #define E1000E_INT_MODE_MSIX		2
45dee1ad47SJeff Kirsher 
46dee1ad47SJeff Kirsher /* Tx/Rx descriptor defines */
47dee1ad47SJeff Kirsher #define E1000_DEFAULT_TXD		256
48dee1ad47SJeff Kirsher #define E1000_MAX_TXD			4096
49dee1ad47SJeff Kirsher #define E1000_MIN_TXD			64
50dee1ad47SJeff Kirsher 
51dee1ad47SJeff Kirsher #define E1000_DEFAULT_RXD		256
52dee1ad47SJeff Kirsher #define E1000_MAX_RXD			4096
53dee1ad47SJeff Kirsher #define E1000_MIN_RXD			64
54dee1ad47SJeff Kirsher 
55dee1ad47SJeff Kirsher #define E1000_MIN_ITR_USECS		10 /* 100000 irq/sec */
56dee1ad47SJeff Kirsher #define E1000_MAX_ITR_USECS		10000 /* 100    irq/sec */
57dee1ad47SJeff Kirsher 
58dee1ad47SJeff Kirsher #define E1000_FC_PAUSE_TIME		0x0680 /* 858 usec */
59dee1ad47SJeff Kirsher 
60dee1ad47SJeff Kirsher /* How many Tx Descriptors do we need to call netif_wake_queue ? */
61dee1ad47SJeff Kirsher /* How many Rx Buffers do we bundle into one write to the hardware ? */
62dee1ad47SJeff Kirsher #define E1000_RX_BUFFER_WRITE		16 /* Must be power of 2 */
63dee1ad47SJeff Kirsher 
64dee1ad47SJeff Kirsher #define AUTO_ALL_MODES			0
65dee1ad47SJeff Kirsher #define E1000_EEPROM_APME		0x0400
66dee1ad47SJeff Kirsher 
67dee1ad47SJeff Kirsher #define E1000_MNG_VLAN_NONE		(-1)
68dee1ad47SJeff Kirsher 
69dee1ad47SJeff Kirsher #define DEFAULT_JUMBO			9234
70dee1ad47SJeff Kirsher 
71dee1ad47SJeff Kirsher /* Time to wait before putting the device into D3 if there's no link (in ms). */
72dee1ad47SJeff Kirsher #define LINK_TIMEOUT		100
73dee1ad47SJeff Kirsher 
74e921eb1aSBruce Allan /* Count for polling __E1000_RESET condition every 10-20msec.
75bb9e44d0SBruce Allan  * Experimentation has shown the reset can take approximately 210msec.
76bb9e44d0SBruce Allan  */
77bb9e44d0SBruce Allan #define E1000_CHECK_RESET_COUNT		25
78bb9e44d0SBruce Allan 
79ff917429SYanir Lubetkin #define PCICFG_DESC_RING_STATUS		0xe4
80ff917429SYanir Lubetkin #define FLUSH_DESC_REQUIRED		0x100
81dee1ad47SJeff Kirsher 
82e921eb1aSBruce Allan /* in the case of WTHRESH, it appears at least the 82571/2 hardware
83dee1ad47SJeff Kirsher  * writes back 4 descriptors when WTHRESH=5, and 3 descriptors when
848edc0e62SHiroaki SHIMODA  * WTHRESH=4, so a setting of 5 gives the most efficient bus
858edc0e62SHiroaki SHIMODA  * utilization but to avoid possible Tx stalls, set it to 1
86dee1ad47SJeff Kirsher  */
87dee1ad47SJeff Kirsher #define E1000_TXDCTL_DMA_BURST_ENABLE                          \
88dee1ad47SJeff Kirsher 	(E1000_TXDCTL_GRAN | /* set descriptor granularity */  \
89dee1ad47SJeff Kirsher 	 E1000_TXDCTL_COUNT_DESC |                             \
9018dd2392SJacob Keller 	 (1u << 16) | /* wthresh must be +1 more than desired */\
9118dd2392SJacob Keller 	 (1u << 8)  | /* hthresh */                             \
92dee1ad47SJeff Kirsher 	 0x1f)        /* pthresh */
93dee1ad47SJeff Kirsher 
94dee1ad47SJeff Kirsher #define E1000_RXDCTL_DMA_BURST_ENABLE                          \
95dee1ad47SJeff Kirsher 	(0x01000000 | /* set descriptor granularity */         \
9618dd2392SJacob Keller 	 (4u << 16) | /* set writeback threshold    */         \
9718dd2392SJacob Keller 	 (4u << 8)  | /* set prefetch threshold     */         \
98dee1ad47SJeff Kirsher 	 0x20)        /* set hthresh                */
99dee1ad47SJeff Kirsher 
10018dd2392SJacob Keller #define E1000_TIDV_FPD BIT(31)
10118dd2392SJacob Keller #define E1000_RDTR_FPD BIT(31)
102dee1ad47SJeff Kirsher 
103dee1ad47SJeff Kirsher enum e1000_boards {
104dee1ad47SJeff Kirsher 	board_82571,
105dee1ad47SJeff Kirsher 	board_82572,
106dee1ad47SJeff Kirsher 	board_82573,
107dee1ad47SJeff Kirsher 	board_82574,
108dee1ad47SJeff Kirsher 	board_82583,
109dee1ad47SJeff Kirsher 	board_80003es2lan,
110dee1ad47SJeff Kirsher 	board_ich8lan,
111dee1ad47SJeff Kirsher 	board_ich9lan,
112dee1ad47SJeff Kirsher 	board_ich10lan,
113dee1ad47SJeff Kirsher 	board_pchlan,
114dee1ad47SJeff Kirsher 	board_pch2lan,
1152fbe4526SBruce Allan 	board_pch_lpt,
1163a3173b9SSasha Neftin 	board_pch_spt,
117280db5d4SSasha Neftin 	board_pch_cnp,
11868defd52SSasha Neftin 	board_pch_tgp,
119db2d737dSSasha Neftin 	board_pch_adp,
120db2d737dSSasha Neftin 	board_pch_mtp
121dee1ad47SJeff Kirsher };
122dee1ad47SJeff Kirsher 
123dee1ad47SJeff Kirsher struct e1000_ps_page {
124dee1ad47SJeff Kirsher 	struct page *page;
125dee1ad47SJeff Kirsher 	u64 dma; /* must be u64 - written to hw */
126dee1ad47SJeff Kirsher };
127dee1ad47SJeff Kirsher 
128e921eb1aSBruce Allan /* wrappers around a pointer to a socket buffer,
129dee1ad47SJeff Kirsher  * so a DMA handle can be stored along with the buffer
130dee1ad47SJeff Kirsher  */
131dee1ad47SJeff Kirsher struct e1000_buffer {
132dee1ad47SJeff Kirsher 	dma_addr_t dma;
133dee1ad47SJeff Kirsher 	struct sk_buff *skb;
134dee1ad47SJeff Kirsher 	union {
135dee1ad47SJeff Kirsher 		/* Tx */
136dee1ad47SJeff Kirsher 		struct {
137dee1ad47SJeff Kirsher 			unsigned long time_stamp;
138dee1ad47SJeff Kirsher 			u16 length;
139dee1ad47SJeff Kirsher 			u16 next_to_watch;
140dee1ad47SJeff Kirsher 			unsigned int segs;
141dee1ad47SJeff Kirsher 			unsigned int bytecount;
142dee1ad47SJeff Kirsher 			u16 mapped_as_page;
143dee1ad47SJeff Kirsher 		};
144dee1ad47SJeff Kirsher 		/* Rx */
145dee1ad47SJeff Kirsher 		struct {
146dee1ad47SJeff Kirsher 			/* arrays of page information for packet split */
147dee1ad47SJeff Kirsher 			struct e1000_ps_page *ps_pages;
148dee1ad47SJeff Kirsher 			struct page *page;
149dee1ad47SJeff Kirsher 		};
150dee1ad47SJeff Kirsher 	};
151dee1ad47SJeff Kirsher };
152dee1ad47SJeff Kirsher 
153dee1ad47SJeff Kirsher struct e1000_ring {
15455aa6985SBruce Allan 	struct e1000_adapter *adapter;	/* back pointer to adapter */
155dee1ad47SJeff Kirsher 	void *desc;			/* pointer to ring memory  */
156dee1ad47SJeff Kirsher 	dma_addr_t dma;			/* phys address of ring    */
157dee1ad47SJeff Kirsher 	unsigned int size;		/* length of ring in bytes */
158dee1ad47SJeff Kirsher 	unsigned int count;		/* number of desc. in ring */
159dee1ad47SJeff Kirsher 
160dee1ad47SJeff Kirsher 	u16 next_to_use;
161dee1ad47SJeff Kirsher 	u16 next_to_clean;
162dee1ad47SJeff Kirsher 
163c5083cf6SBruce Allan 	void __iomem *head;
164c5083cf6SBruce Allan 	void __iomem *tail;
165dee1ad47SJeff Kirsher 
166dee1ad47SJeff Kirsher 	/* array of buffer information structs */
167dee1ad47SJeff Kirsher 	struct e1000_buffer *buffer_info;
168dee1ad47SJeff Kirsher 
169dee1ad47SJeff Kirsher 	char name[IFNAMSIZ + 5];
170dee1ad47SJeff Kirsher 	u32 ims_val;
171dee1ad47SJeff Kirsher 	u32 itr_val;
172c5083cf6SBruce Allan 	void __iomem *itr_register;
173dee1ad47SJeff Kirsher 	int set_itr;
174dee1ad47SJeff Kirsher 
175dee1ad47SJeff Kirsher 	struct sk_buff *rx_skb_top;
176dee1ad47SJeff Kirsher };
177dee1ad47SJeff Kirsher 
178dee1ad47SJeff Kirsher /* PHY register snapshot values */
179dee1ad47SJeff Kirsher struct e1000_phy_regs {
180dee1ad47SJeff Kirsher 	u16 bmcr;		/* basic mode control register    */
181dee1ad47SJeff Kirsher 	u16 bmsr;		/* basic mode status register     */
182dee1ad47SJeff Kirsher 	u16 advertise;		/* auto-negotiation advertisement */
183dee1ad47SJeff Kirsher 	u16 lpa;		/* link partner ability register  */
184dee1ad47SJeff Kirsher 	u16 expansion;		/* auto-negotiation expansion reg */
185dee1ad47SJeff Kirsher 	u16 ctrl1000;		/* 1000BASE-T control register    */
186dee1ad47SJeff Kirsher 	u16 stat1000;		/* 1000BASE-T status register     */
187dee1ad47SJeff Kirsher 	u16 estatus;		/* extended status register       */
188dee1ad47SJeff Kirsher };
189dee1ad47SJeff Kirsher 
190dee1ad47SJeff Kirsher /* board specific private data structure */
191dee1ad47SJeff Kirsher struct e1000_adapter {
192d5ad7a6aSJeff Kirsher 	struct timer_list watchdog_timer;
193dee1ad47SJeff Kirsher 	struct timer_list phy_info_timer;
194dee1ad47SJeff Kirsher 	struct timer_list blink_timer;
195dee1ad47SJeff Kirsher 
196dee1ad47SJeff Kirsher 	struct work_struct reset_task;
197d5ad7a6aSJeff Kirsher 	struct work_struct watchdog_task;
198dee1ad47SJeff Kirsher 
199dee1ad47SJeff Kirsher 	const struct e1000_info *ei;
200dee1ad47SJeff Kirsher 
201dee1ad47SJeff Kirsher 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
202dee1ad47SJeff Kirsher 	u32 bd_number;
203dee1ad47SJeff Kirsher 	u32 rx_buffer_len;
204dee1ad47SJeff Kirsher 	u16 mng_vlan_id;
205dee1ad47SJeff Kirsher 	u16 link_speed;
206dee1ad47SJeff Kirsher 	u16 link_duplex;
207dee1ad47SJeff Kirsher 	u16 eeprom_vers;
208dee1ad47SJeff Kirsher 
209dee1ad47SJeff Kirsher 	/* track device up/down/testing state */
210dee1ad47SJeff Kirsher 	unsigned long state;
211dee1ad47SJeff Kirsher 
212dee1ad47SJeff Kirsher 	/* Interrupt Throttle Rate */
213dee1ad47SJeff Kirsher 	u32 itr;
214dee1ad47SJeff Kirsher 	u32 itr_setting;
215dee1ad47SJeff Kirsher 	u16 tx_itr;
216dee1ad47SJeff Kirsher 	u16 rx_itr;
217dee1ad47SJeff Kirsher 
21833550cecSBruce Allan 	/* Tx - one ring per active queue */
21933550cecSBruce Allan 	struct e1000_ring *tx_ring ____cacheline_aligned_in_smp;
220d821a4c4SBruce Allan 	u32 tx_fifo_limit;
221dee1ad47SJeff Kirsher 
222dee1ad47SJeff Kirsher 	struct napi_struct napi;
223dee1ad47SJeff Kirsher 
22494fb848bSBruce Allan 	unsigned int uncorr_errors;	/* uncorrectable ECC errors */
22594fb848bSBruce Allan 	unsigned int corr_errors;	/* correctable ECC errors */
226dee1ad47SJeff Kirsher 	unsigned int restart_queue;
227dee1ad47SJeff Kirsher 	u32 txd_cmd;
228dee1ad47SJeff Kirsher 
229dee1ad47SJeff Kirsher 	bool detect_tx_hung;
23009357b00SJeff Kirsher 	bool tx_hang_recheck;
231dee1ad47SJeff Kirsher 	u8 tx_timeout_factor;
232dee1ad47SJeff Kirsher 
233dee1ad47SJeff Kirsher 	u32 tx_int_delay;
234dee1ad47SJeff Kirsher 	u32 tx_abs_int_delay;
235dee1ad47SJeff Kirsher 
236dee1ad47SJeff Kirsher 	unsigned int total_tx_bytes;
237dee1ad47SJeff Kirsher 	unsigned int total_tx_packets;
238dee1ad47SJeff Kirsher 	unsigned int total_rx_bytes;
239dee1ad47SJeff Kirsher 	unsigned int total_rx_packets;
240dee1ad47SJeff Kirsher 
241dee1ad47SJeff Kirsher 	/* Tx stats */
242dee1ad47SJeff Kirsher 	u64 tpt_old;
243dee1ad47SJeff Kirsher 	u64 colc_old;
244dee1ad47SJeff Kirsher 	u32 gotc;
245dee1ad47SJeff Kirsher 	u64 gotc_old;
246dee1ad47SJeff Kirsher 	u32 tx_timeout_count;
247dee1ad47SJeff Kirsher 	u32 tx_fifo_head;
248dee1ad47SJeff Kirsher 	u32 tx_head_addr;
249dee1ad47SJeff Kirsher 	u32 tx_fifo_size;
250dee1ad47SJeff Kirsher 	u32 tx_dma_failed;
25159c871c5SJakub Kicinski 	u32 tx_hwtstamp_timeouts;
252cff57141SJacob Keller 	u32 tx_hwtstamp_skipped;
253dee1ad47SJeff Kirsher 
254e921eb1aSBruce Allan 	/* Rx */
25555aa6985SBruce Allan 	bool (*clean_rx)(struct e1000_ring *ring, int *work_done,
25655aa6985SBruce Allan 			 int work_to_do) ____cacheline_aligned_in_smp;
25755aa6985SBruce Allan 	void (*alloc_rx_buf)(struct e1000_ring *ring, int cleaned_count,
25855aa6985SBruce Allan 			     gfp_t gfp);
259dee1ad47SJeff Kirsher 	struct e1000_ring *rx_ring;
260dee1ad47SJeff Kirsher 
261dee1ad47SJeff Kirsher 	u32 rx_int_delay;
262dee1ad47SJeff Kirsher 	u32 rx_abs_int_delay;
263dee1ad47SJeff Kirsher 
264dee1ad47SJeff Kirsher 	/* Rx stats */
265dee1ad47SJeff Kirsher 	u64 hw_csum_err;
266dee1ad47SJeff Kirsher 	u64 hw_csum_good;
267dee1ad47SJeff Kirsher 	u64 rx_hdr_split;
268dee1ad47SJeff Kirsher 	u32 gorc;
269dee1ad47SJeff Kirsher 	u64 gorc_old;
270dee1ad47SJeff Kirsher 	u32 alloc_rx_buff_failed;
271dee1ad47SJeff Kirsher 	u32 rx_dma_failed;
272b67e1913SBruce Allan 	u32 rx_hwtstamp_cleared;
273dee1ad47SJeff Kirsher 
274dee1ad47SJeff Kirsher 	unsigned int rx_ps_pages;
275dee1ad47SJeff Kirsher 	u16 rx_ps_bsize0;
276dee1ad47SJeff Kirsher 	u32 max_frame_size;
277dee1ad47SJeff Kirsher 	u32 min_frame_size;
278dee1ad47SJeff Kirsher 
279dee1ad47SJeff Kirsher 	/* OS defined structs */
280dee1ad47SJeff Kirsher 	struct net_device *netdev;
281dee1ad47SJeff Kirsher 	struct pci_dev *pdev;
282dee1ad47SJeff Kirsher 
283dee1ad47SJeff Kirsher 	/* structs defined in e1000_hw.h */
284dee1ad47SJeff Kirsher 	struct e1000_hw hw;
285dee1ad47SJeff Kirsher 
2869d57088bSBruce Allan 	spinlock_t stats64_lock;	/* protects statistics counters */
287dee1ad47SJeff Kirsher 	struct e1000_hw_stats stats;
288dee1ad47SJeff Kirsher 	struct e1000_phy_info phy_info;
289dee1ad47SJeff Kirsher 	struct e1000_phy_stats phy_stats;
290dee1ad47SJeff Kirsher 
291dee1ad47SJeff Kirsher 	/* Snapshot of PHY registers */
292dee1ad47SJeff Kirsher 	struct e1000_phy_regs phy_regs;
293dee1ad47SJeff Kirsher 
294dee1ad47SJeff Kirsher 	struct e1000_ring test_tx_ring;
295dee1ad47SJeff Kirsher 	struct e1000_ring test_rx_ring;
296dee1ad47SJeff Kirsher 	u32 test_icr;
297dee1ad47SJeff Kirsher 
298dee1ad47SJeff Kirsher 	u32 msg_enable;
299dee1ad47SJeff Kirsher 	unsigned int num_vectors;
300dee1ad47SJeff Kirsher 	struct msix_entry *msix_entries;
301dee1ad47SJeff Kirsher 	int int_mode;
302dee1ad47SJeff Kirsher 	u32 eiac_mask;
303dee1ad47SJeff Kirsher 
304dee1ad47SJeff Kirsher 	u32 eeprom_wol;
305dee1ad47SJeff Kirsher 	u32 wol;
306dee1ad47SJeff Kirsher 	u32 pba;
307dee1ad47SJeff Kirsher 	u32 max_hw_frame_size;
308dee1ad47SJeff Kirsher 
309dee1ad47SJeff Kirsher 	bool fc_autoneg;
310dee1ad47SJeff Kirsher 
311dee1ad47SJeff Kirsher 	unsigned int flags;
312dee1ad47SJeff Kirsher 	unsigned int flags2;
313dee1ad47SJeff Kirsher 	struct work_struct downshift_task;
314dee1ad47SJeff Kirsher 	struct work_struct update_phy_task;
315dee1ad47SJeff Kirsher 	struct work_struct print_hang_task;
316dee1ad47SJeff Kirsher 
317dee1ad47SJeff Kirsher 	int phy_hang_count;
31855aa6985SBruce Allan 
31955aa6985SBruce Allan 	u16 tx_ring_count;
32055aa6985SBruce Allan 	u16 rx_ring_count;
321b67e1913SBruce Allan 
322b67e1913SBruce Allan 	struct hwtstamp_config hwtstamp_config;
323b67e1913SBruce Allan 	struct delayed_work systim_overflow_work;
324b67e1913SBruce Allan 	struct sk_buff *tx_hwtstamp_skb;
32559c871c5SJakub Kicinski 	unsigned long tx_hwtstamp_start;
326b67e1913SBruce Allan 	struct work_struct tx_hwtstamp_work;
327b67e1913SBruce Allan 	spinlock_t systim_lock;	/* protects SYSTIML/H regsters */
328b67e1913SBruce Allan 	struct cyclecounter cc;
329b67e1913SBruce Allan 	struct timecounter tc;
330d89777bfSBruce Allan 	struct ptp_clock *ptp_clock;
331d89777bfSBruce Allan 	struct ptp_clock_info ptp_clock_info;
332e2c65448SThomas Graf 	struct pm_qos_request pm_qos_req;
333abab010fSJacob Keller 	long ptp_delta;
334d495bcb8SBruce Allan 
335d495bcb8SBruce Allan 	u16 eee_advert;
336dee1ad47SJeff Kirsher };
337dee1ad47SJeff Kirsher 
338dee1ad47SJeff Kirsher struct e1000_info {
339dee1ad47SJeff Kirsher 	enum e1000_mac_type	mac;
340dee1ad47SJeff Kirsher 	unsigned int		flags;
341dee1ad47SJeff Kirsher 	unsigned int		flags2;
342dee1ad47SJeff Kirsher 	u32			pba;
343dee1ad47SJeff Kirsher 	u32			max_hw_frame_size;
344dee1ad47SJeff Kirsher 	s32			(*get_variants)(struct e1000_adapter *);
3458ce9d6c7SJeff Kirsher 	const struct e1000_mac_operations *mac_ops;
3468ce9d6c7SJeff Kirsher 	const struct e1000_phy_operations *phy_ops;
3478ce9d6c7SJeff Kirsher 	const struct e1000_nvm_operations *nvm_ops;
348dee1ad47SJeff Kirsher };
349dee1ad47SJeff Kirsher 
350d89777bfSBruce Allan s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca);
351d89777bfSBruce Allan 
352b67e1913SBruce Allan /* The system time is maintained by a 64-bit counter comprised of the 32-bit
353b67e1913SBruce Allan  * SYSTIMH and SYSTIML registers.  How the counter increments (and therefore
354b67e1913SBruce Allan  * its resolution) is based on the contents of the TIMINCA register - it
355b67e1913SBruce Allan  * increments every incperiod (bits 31:24) clock ticks by incvalue (bits 23:0).
356b67e1913SBruce Allan  * For the best accuracy, the incperiod should be as small as possible.  The
357b67e1913SBruce Allan  * incvalue is scaled by a factor as large as possible (while still fitting
358b67e1913SBruce Allan  * in bits 23:0) so that relatively small clock corrections can be made.
359b67e1913SBruce Allan  *
360b67e1913SBruce Allan  * As a result, a shift of INCVALUE_SHIFT_n is used to fit a value of
361b67e1913SBruce Allan  * INCVALUE_n into the TIMINCA register allowing 32+8+(24-INCVALUE_SHIFT_n)
362b67e1913SBruce Allan  * bits to count nanoseconds leaving the rest for fractional nonseconds.
363*e9ad7a80SJacob Keller  *
364*e9ad7a80SJacob Keller  * Any given INCVALUE also has an associated maximum adjustment value. This
365*e9ad7a80SJacob Keller  * maximum adjustment value is the largest increase (or decrease) which can be
366*e9ad7a80SJacob Keller  * safely applied without overflowing the INCVALUE. Since INCVALUE has
367*e9ad7a80SJacob Keller  * a maximum range of 24 bits, its largest value is 0xFFFFFF.
368*e9ad7a80SJacob Keller  *
369*e9ad7a80SJacob Keller  * To understand where the maximum value comes from, consider the following
370*e9ad7a80SJacob Keller  * equation:
371*e9ad7a80SJacob Keller  *
372*e9ad7a80SJacob Keller  *   new_incval = base_incval + (base_incval * adjustment) / 1billion
373*e9ad7a80SJacob Keller  *
374*e9ad7a80SJacob Keller  * To avoid overflow that means:
375*e9ad7a80SJacob Keller  *   max_incval = base_incval + (base_incval * max_adj) / billion
376*e9ad7a80SJacob Keller  *
377*e9ad7a80SJacob Keller  * Re-arranging:
378*e9ad7a80SJacob Keller  *   max_adj = floor(((max_incval - base_incval) * 1billion) / 1billion)
379b67e1913SBruce Allan  */
38068fe1d5dSSasha Neftin #define INCVALUE_96MHZ		125
38168fe1d5dSSasha Neftin #define INCVALUE_SHIFT_96MHZ	17
38268fe1d5dSSasha Neftin #define INCPERIOD_SHIFT_96MHZ	2
38368fe1d5dSSasha Neftin #define INCPERIOD_96MHZ		(12 >> INCPERIOD_SHIFT_96MHZ)
384*e9ad7a80SJacob Keller #define MAX_PPB_96MHZ		23999900 /* 23,999,900 ppb */
385b67e1913SBruce Allan 
38668fe1d5dSSasha Neftin #define INCVALUE_25MHZ		40
38768fe1d5dSSasha Neftin #define INCVALUE_SHIFT_25MHZ	18
38868fe1d5dSSasha Neftin #define INCPERIOD_25MHZ		1
389*e9ad7a80SJacob Keller #define MAX_PPB_25MHZ		599999900 /* 599,999,900 ppb */
390b67e1913SBruce Allan 
39168fe1d5dSSasha Neftin #define INCVALUE_24MHZ		125
39268fe1d5dSSasha Neftin #define INCVALUE_SHIFT_24MHZ	14
39368fe1d5dSSasha Neftin #define INCPERIOD_24MHZ		3
394*e9ad7a80SJacob Keller #define MAX_PPB_24MHZ		999999999 /* 999,999,999 ppb */
39568fe1d5dSSasha Neftin 
39668fe1d5dSSasha Neftin #define INCVALUE_38400KHZ	26
39768fe1d5dSSasha Neftin #define INCVALUE_SHIFT_38400KHZ	19
39868fe1d5dSSasha Neftin #define INCPERIOD_38400KHZ	1
399*e9ad7a80SJacob Keller #define MAX_PPB_38400KHZ	230769100 /* 230,769,100 ppb */
40083129b37SYanir Lubetkin 
401b67e1913SBruce Allan /* Another drawback of scaling the incvalue by a large factor is the
402b67e1913SBruce Allan  * 64-bit SYSTIM register overflows more quickly.  This is dealt with
403b67e1913SBruce Allan  * by simply reading the clock before it overflows.
404b67e1913SBruce Allan  *
405b67e1913SBruce Allan  * Clock	ns bits	Overflows after
406b67e1913SBruce Allan  * ~~~~~~	~~~~~~~	~~~~~~~~~~~~~~~
407b67e1913SBruce Allan  * 96MHz	47-bit	2^(47-INCPERIOD_SHIFT_96MHz) / 10^9 / 3600 = 9.77 hrs
408b67e1913SBruce Allan  * 25MHz	46-bit	2^46 / 10^9 / 3600 = 19.55 hours
409b67e1913SBruce Allan  */
410b67e1913SBruce Allan #define E1000_SYSTIM_OVERFLOW_PERIOD	(HZ * 60 * 60 * 4)
4115e7ff970STodd Fujinaka #define E1000_MAX_82574_SYSTIM_REREADS	50
4125e7ff970STodd Fujinaka #define E1000_82574_SYSTIM_EPSILON	(1ULL << 35ULL)
413b67e1913SBruce Allan 
414dee1ad47SJeff Kirsher /* hardware capability, feature, and workaround flags */
41518dd2392SJacob Keller #define FLAG_HAS_AMT                      BIT(0)
41618dd2392SJacob Keller #define FLAG_HAS_FLASH                    BIT(1)
41718dd2392SJacob Keller #define FLAG_HAS_HW_VLAN_FILTER           BIT(2)
41818dd2392SJacob Keller #define FLAG_HAS_WOL                      BIT(3)
41918dd2392SJacob Keller /* reserved BIT(4) */
42018dd2392SJacob Keller #define FLAG_HAS_CTRLEXT_ON_LOAD          BIT(5)
42118dd2392SJacob Keller #define FLAG_HAS_SWSM_ON_LOAD             BIT(6)
42218dd2392SJacob Keller #define FLAG_HAS_JUMBO_FRAMES             BIT(7)
42318dd2392SJacob Keller #define FLAG_READ_ONLY_NVM                BIT(8)
42418dd2392SJacob Keller #define FLAG_IS_ICH                       BIT(9)
42518dd2392SJacob Keller #define FLAG_HAS_MSIX                     BIT(10)
42618dd2392SJacob Keller #define FLAG_HAS_SMART_POWER_DOWN         BIT(11)
42718dd2392SJacob Keller #define FLAG_IS_QUAD_PORT_A               BIT(12)
42818dd2392SJacob Keller #define FLAG_IS_QUAD_PORT                 BIT(13)
42918dd2392SJacob Keller #define FLAG_HAS_HW_TIMESTAMP             BIT(14)
43018dd2392SJacob Keller #define FLAG_APME_IN_WUC                  BIT(15)
43118dd2392SJacob Keller #define FLAG_APME_IN_CTRL3                BIT(16)
43218dd2392SJacob Keller #define FLAG_APME_CHECK_PORT_B            BIT(17)
43318dd2392SJacob Keller #define FLAG_DISABLE_FC_PAUSE_TIME        BIT(18)
43418dd2392SJacob Keller #define FLAG_NO_WAKE_UCAST                BIT(19)
43518dd2392SJacob Keller #define FLAG_MNG_PT_ENABLED               BIT(20)
43618dd2392SJacob Keller #define FLAG_RESET_OVERWRITES_LAA         BIT(21)
43718dd2392SJacob Keller #define FLAG_TARC_SPEED_MODE_BIT          BIT(22)
43818dd2392SJacob Keller #define FLAG_TARC_SET_BIT_ZERO            BIT(23)
43918dd2392SJacob Keller #define FLAG_RX_NEEDS_RESTART             BIT(24)
44018dd2392SJacob Keller #define FLAG_LSC_GIG_SPEED_DROP           BIT(25)
44118dd2392SJacob Keller #define FLAG_SMART_POWER_DOWN             BIT(26)
44218dd2392SJacob Keller #define FLAG_MSI_ENABLED                  BIT(27)
44318dd2392SJacob Keller /* reserved BIT(28) */
44418dd2392SJacob Keller #define FLAG_TSO_FORCE                    BIT(29)
44518dd2392SJacob Keller #define FLAG_RESTART_NOW                  BIT(30)
44618dd2392SJacob Keller #define FLAG_MSI_TEST_FAILED              BIT(31)
447dee1ad47SJeff Kirsher 
44818dd2392SJacob Keller #define FLAG2_CRC_STRIPPING               BIT(0)
44918dd2392SJacob Keller #define FLAG2_HAS_PHY_WAKEUP              BIT(1)
45018dd2392SJacob Keller #define FLAG2_IS_DISCARDING               BIT(2)
45118dd2392SJacob Keller #define FLAG2_DISABLE_ASPM_L1             BIT(3)
45218dd2392SJacob Keller #define FLAG2_HAS_PHY_STATS               BIT(4)
45318dd2392SJacob Keller #define FLAG2_HAS_EEE                     BIT(5)
45418dd2392SJacob Keller #define FLAG2_DMA_BURST                   BIT(6)
45518dd2392SJacob Keller #define FLAG2_DISABLE_ASPM_L0S            BIT(7)
45618dd2392SJacob Keller #define FLAG2_DISABLE_AIM                 BIT(8)
45718dd2392SJacob Keller #define FLAG2_CHECK_PHY_HANG              BIT(9)
45818dd2392SJacob Keller #define FLAG2_NO_DISABLE_RX               BIT(10)
45918dd2392SJacob Keller #define FLAG2_PCIM2PCI_ARBITER_WA         BIT(11)
46018dd2392SJacob Keller #define FLAG2_DFLT_CRC_STRIPPING          BIT(12)
46118dd2392SJacob Keller #define FLAG2_CHECK_RX_HWTSTAMP           BIT(13)
4620be5b96cSJarod Wilson #define FLAG2_CHECK_SYSTIM_OVERFLOW       BIT(14)
4633c98cbf2SMario Limonciello #define FLAG2_ENABLE_S0IX_FLOWS           BIT(15)
464dee1ad47SJeff Kirsher 
465dee1ad47SJeff Kirsher #define E1000_RX_DESC_PS(R, i)	    \
466dee1ad47SJeff Kirsher 	(&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
4675f450212SBruce Allan #define E1000_RX_DESC_EXT(R, i)	    \
4685f450212SBruce Allan 	(&(((union e1000_rx_desc_extended *)((R).desc))[i]))
469dee1ad47SJeff Kirsher #define E1000_GET_DESC(R, i, type)	(&(((struct type *)((R).desc))[i]))
470dee1ad47SJeff Kirsher #define E1000_TX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_tx_desc)
471dee1ad47SJeff Kirsher #define E1000_CONTEXT_DESC(R, i)	E1000_GET_DESC(R, i, e1000_context_desc)
472dee1ad47SJeff Kirsher 
473dee1ad47SJeff Kirsher enum e1000_state_t {
474dee1ad47SJeff Kirsher 	__E1000_TESTING,
475dee1ad47SJeff Kirsher 	__E1000_RESETTING,
476a90b412cSBruce Allan 	__E1000_ACCESS_SHARED_RESOURCE,
477dee1ad47SJeff Kirsher 	__E1000_DOWN
478dee1ad47SJeff Kirsher };
479dee1ad47SJeff Kirsher 
480dee1ad47SJeff Kirsher enum latency_range {
481dee1ad47SJeff Kirsher 	lowest_latency = 0,
482dee1ad47SJeff Kirsher 	low_latency = 1,
483dee1ad47SJeff Kirsher 	bulk_latency = 2,
484dee1ad47SJeff Kirsher 	latency_invalid = 255
485dee1ad47SJeff Kirsher };
486dee1ad47SJeff Kirsher 
487dee1ad47SJeff Kirsher extern char e1000e_driver_name[];
488dee1ad47SJeff Kirsher 
4895ccc921aSJoe Perches void e1000e_check_options(struct e1000_adapter *adapter);
4905ccc921aSJoe Perches void e1000e_set_ethtool_ops(struct net_device *netdev);
491dee1ad47SJeff Kirsher 
492d5ea45daSStefan Assmann int e1000e_open(struct net_device *netdev);
493d5ea45daSStefan Assmann int e1000e_close(struct net_device *netdev);
494386164d9SAlexander Duyck void e1000e_up(struct e1000_adapter *adapter);
49528002099SDavid Ertman void e1000e_down(struct e1000_adapter *adapter, bool reset);
4965ccc921aSJoe Perches void e1000e_reinit_locked(struct e1000_adapter *adapter);
4975ccc921aSJoe Perches void e1000e_reset(struct e1000_adapter *adapter);
4985ccc921aSJoe Perches void e1000e_power_up_phy(struct e1000_adapter *adapter);
4995ccc921aSJoe Perches int e1000e_setup_rx_resources(struct e1000_ring *ring);
5005ccc921aSJoe Perches int e1000e_setup_tx_resources(struct e1000_ring *ring);
5015ccc921aSJoe Perches void e1000e_free_rx_resources(struct e1000_ring *ring);
5025ccc921aSJoe Perches void e1000e_free_tx_resources(struct e1000_ring *ring);
503bc1f4470Sstephen hemminger void e1000e_get_stats64(struct net_device *netdev,
5045ccc921aSJoe Perches 			struct rtnl_link_stats64 *stats);
5055ccc921aSJoe Perches void e1000e_set_interrupt_capability(struct e1000_adapter *adapter);
5065ccc921aSJoe Perches void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter);
5075ccc921aSJoe Perches void e1000e_get_hw_control(struct e1000_adapter *adapter);
5085ccc921aSJoe Perches void e1000e_release_hw_control(struct e1000_adapter *adapter);
5095ccc921aSJoe Perches void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr);
510dee1ad47SJeff Kirsher 
511dee1ad47SJeff Kirsher extern unsigned int copybreak;
512dee1ad47SJeff Kirsher 
5138ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82571_info;
5148ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82572_info;
5158ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82573_info;
5168ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82574_info;
5178ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82583_info;
5188ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_ich8_info;
5198ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_ich9_info;
5208ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_ich10_info;
5218ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_pch_info;
5228ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_pch2_info;
5232fbe4526SBruce Allan extern const struct e1000_info e1000_pch_lpt_info;
52479849ebcSDavid Ertman extern const struct e1000_info e1000_pch_spt_info;
5253a3173b9SSasha Neftin extern const struct e1000_info e1000_pch_cnp_info;
526280db5d4SSasha Neftin extern const struct e1000_info e1000_pch_tgp_info;
52768defd52SSasha Neftin extern const struct e1000_info e1000_pch_adp_info;
528db2d737dSSasha Neftin extern const struct e1000_info e1000_pch_mtp_info;
5298ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_es2_info;
530dee1ad47SJeff Kirsher 
5315ccc921aSJoe Perches void e1000e_ptp_init(struct e1000_adapter *adapter);
5325ccc921aSJoe Perches void e1000e_ptp_remove(struct e1000_adapter *adapter);
533dee1ad47SJeff Kirsher 
53498942d70SMiroslav Lichvar u64 e1000e_read_systim(struct e1000_adapter *adapter,
53598942d70SMiroslav Lichvar 		       struct ptp_system_timestamp *sts);
53698942d70SMiroslav Lichvar 
e1000_phy_hw_reset(struct e1000_hw * hw)537dee1ad47SJeff Kirsher static inline s32 e1000_phy_hw_reset(struct e1000_hw *hw)
538dee1ad47SJeff Kirsher {
539dee1ad47SJeff Kirsher 	return hw->phy.ops.reset(hw);
540dee1ad47SJeff Kirsher }
541dee1ad47SJeff Kirsher 
e1e_rphy(struct e1000_hw * hw,u32 offset,u16 * data)542dee1ad47SJeff Kirsher static inline s32 e1e_rphy(struct e1000_hw *hw, u32 offset, u16 *data)
543dee1ad47SJeff Kirsher {
544dee1ad47SJeff Kirsher 	return hw->phy.ops.read_reg(hw, offset, data);
545dee1ad47SJeff Kirsher }
546dee1ad47SJeff Kirsher 
e1e_rphy_locked(struct e1000_hw * hw,u32 offset,u16 * data)547f1430d69SBruce Allan static inline s32 e1e_rphy_locked(struct e1000_hw *hw, u32 offset, u16 *data)
548f1430d69SBruce Allan {
549f1430d69SBruce Allan 	return hw->phy.ops.read_reg_locked(hw, offset, data);
550f1430d69SBruce Allan }
551f1430d69SBruce Allan 
e1e_wphy(struct e1000_hw * hw,u32 offset,u16 data)552dee1ad47SJeff Kirsher static inline s32 e1e_wphy(struct e1000_hw *hw, u32 offset, u16 data)
553dee1ad47SJeff Kirsher {
554dee1ad47SJeff Kirsher 	return hw->phy.ops.write_reg(hw, offset, data);
555dee1ad47SJeff Kirsher }
556dee1ad47SJeff Kirsher 
e1e_wphy_locked(struct e1000_hw * hw,u32 offset,u16 data)557f1430d69SBruce Allan static inline s32 e1e_wphy_locked(struct e1000_hw *hw, u32 offset, u16 data)
558f1430d69SBruce Allan {
559f1430d69SBruce Allan 	return hw->phy.ops.write_reg_locked(hw, offset, data);
560f1430d69SBruce Allan }
561f1430d69SBruce Allan 
5625ccc921aSJoe Perches void e1000e_reload_nvm_generic(struct e1000_hw *hw);
563dee1ad47SJeff Kirsher 
e1000e_read_mac_addr(struct e1000_hw * hw)564dee1ad47SJeff Kirsher static inline s32 e1000e_read_mac_addr(struct e1000_hw *hw)
565dee1ad47SJeff Kirsher {
566dee1ad47SJeff Kirsher 	if (hw->mac.ops.read_mac_addr)
567dee1ad47SJeff Kirsher 		return hw->mac.ops.read_mac_addr(hw);
568dee1ad47SJeff Kirsher 
569dee1ad47SJeff Kirsher 	return e1000_read_mac_addr_generic(hw);
570dee1ad47SJeff Kirsher }
571dee1ad47SJeff Kirsher 
e1000_validate_nvm_checksum(struct e1000_hw * hw)572dee1ad47SJeff Kirsher static inline s32 e1000_validate_nvm_checksum(struct e1000_hw *hw)
573dee1ad47SJeff Kirsher {
574dee1ad47SJeff Kirsher 	return hw->nvm.ops.validate(hw);
575dee1ad47SJeff Kirsher }
576dee1ad47SJeff Kirsher 
e1000e_update_nvm_checksum(struct e1000_hw * hw)577dee1ad47SJeff Kirsher static inline s32 e1000e_update_nvm_checksum(struct e1000_hw *hw)
578dee1ad47SJeff Kirsher {
579dee1ad47SJeff Kirsher 	return hw->nvm.ops.update(hw);
580dee1ad47SJeff Kirsher }
581dee1ad47SJeff Kirsher 
e1000_read_nvm(struct e1000_hw * hw,u16 offset,u16 words,u16 * data)582c29c3ba5SBruce Allan static inline s32 e1000_read_nvm(struct e1000_hw *hw, u16 offset, u16 words,
583c29c3ba5SBruce Allan 				 u16 *data)
584dee1ad47SJeff Kirsher {
585dee1ad47SJeff Kirsher 	return hw->nvm.ops.read(hw, offset, words, data);
586dee1ad47SJeff Kirsher }
587dee1ad47SJeff Kirsher 
e1000_write_nvm(struct e1000_hw * hw,u16 offset,u16 words,u16 * data)588c29c3ba5SBruce Allan static inline s32 e1000_write_nvm(struct e1000_hw *hw, u16 offset, u16 words,
589c29c3ba5SBruce Allan 				  u16 *data)
590dee1ad47SJeff Kirsher {
591dee1ad47SJeff Kirsher 	return hw->nvm.ops.write(hw, offset, words, data);
592dee1ad47SJeff Kirsher }
593dee1ad47SJeff Kirsher 
e1000_get_phy_info(struct e1000_hw * hw)594dee1ad47SJeff Kirsher static inline s32 e1000_get_phy_info(struct e1000_hw *hw)
595dee1ad47SJeff Kirsher {
596dee1ad47SJeff Kirsher 	return hw->phy.ops.get_info(hw);
597dee1ad47SJeff Kirsher }
598dee1ad47SJeff Kirsher 
__er32(struct e1000_hw * hw,unsigned long reg)599dee1ad47SJeff Kirsher static inline u32 __er32(struct e1000_hw *hw, unsigned long reg)
600dee1ad47SJeff Kirsher {
601dee1ad47SJeff Kirsher 	return readl(hw->hw_addr + reg);
602dee1ad47SJeff Kirsher }
603dee1ad47SJeff Kirsher 
604bdc125f7SBruce Allan #define er32(reg)	__er32(hw, E1000_##reg)
605bdc125f7SBruce Allan 
606c6f3148cSAndi Kleen void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val);
607dee1ad47SJeff Kirsher 
608bdc125f7SBruce Allan #define ew32(reg, val)	__ew32(hw, E1000_##reg, (val))
609bdc125f7SBruce Allan 
610bdc125f7SBruce Allan #define e1e_flush()	er32(STATUS)
611bdc125f7SBruce Allan 
612bdc125f7SBruce Allan #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) \
613bdc125f7SBruce Allan 	(__ew32((a), (reg + ((offset) << 2)), (value)))
614bdc125f7SBruce Allan 
615bdc125f7SBruce Allan #define E1000_READ_REG_ARRAY(a, reg, offset) \
616bdc125f7SBruce Allan 	(readl((a)->hw_addr + reg + ((offset) << 2)))
617bdc125f7SBruce Allan 
618dee1ad47SJeff Kirsher #endif /* _E1000_H_ */
619