162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright(c) 2007 Atheros Corporation. All rights reserved.
462306a36Sopenharmony_ci * Copyright(c) 2007 xiong huang <xiong.huang@atheros.com>
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Derived from Intel e1000 driver
762306a36Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef _ATL1E_H_
1162306a36Sopenharmony_ci#define _ATL1E_H_
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <linux/interrupt.h>
1462306a36Sopenharmony_ci#include <linux/types.h>
1562306a36Sopenharmony_ci#include <linux/errno.h>
1662306a36Sopenharmony_ci#include <linux/module.h>
1762306a36Sopenharmony_ci#include <linux/pci.h>
1862306a36Sopenharmony_ci#include <linux/netdevice.h>
1962306a36Sopenharmony_ci#include <linux/etherdevice.h>
2062306a36Sopenharmony_ci#include <linux/skbuff.h>
2162306a36Sopenharmony_ci#include <linux/ioport.h>
2262306a36Sopenharmony_ci#include <linux/slab.h>
2362306a36Sopenharmony_ci#include <linux/list.h>
2462306a36Sopenharmony_ci#include <linux/delay.h>
2562306a36Sopenharmony_ci#include <linux/sched.h>
2662306a36Sopenharmony_ci#include <linux/in.h>
2762306a36Sopenharmony_ci#include <linux/ip.h>
2862306a36Sopenharmony_ci#include <linux/ipv6.h>
2962306a36Sopenharmony_ci#include <linux/udp.h>
3062306a36Sopenharmony_ci#include <linux/mii.h>
3162306a36Sopenharmony_ci#include <linux/io.h>
3262306a36Sopenharmony_ci#include <linux/vmalloc.h>
3362306a36Sopenharmony_ci#include <linux/pagemap.h>
3462306a36Sopenharmony_ci#include <linux/tcp.h>
3562306a36Sopenharmony_ci#include <linux/ethtool.h>
3662306a36Sopenharmony_ci#include <linux/if_vlan.h>
3762306a36Sopenharmony_ci#include <linux/workqueue.h>
3862306a36Sopenharmony_ci#include <net/checksum.h>
3962306a36Sopenharmony_ci#include <net/ip6_checksum.h>
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#include "atl1e_hw.h"
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define PCI_REG_COMMAND	 0x04    /* PCI Command Register */
4462306a36Sopenharmony_ci#define CMD_IO_SPACE	 0x0001
4562306a36Sopenharmony_ci#define CMD_MEMORY_SPACE 0x0002
4662306a36Sopenharmony_ci#define CMD_BUS_MASTER   0x0004
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define BAR_0   0
4962306a36Sopenharmony_ci#define BAR_1   1
5062306a36Sopenharmony_ci#define BAR_5   5
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* Wake Up Filter Control */
5362306a36Sopenharmony_ci#define AT_WUFC_LNKC 0x00000001 /* Link Status Change Wakeup Enable */
5462306a36Sopenharmony_ci#define AT_WUFC_MAG  0x00000002 /* Magic Packet Wakeup Enable */
5562306a36Sopenharmony_ci#define AT_WUFC_EX   0x00000004 /* Directed Exact Wakeup Enable */
5662306a36Sopenharmony_ci#define AT_WUFC_MC   0x00000008 /* Multicast Wakeup Enable */
5762306a36Sopenharmony_ci#define AT_WUFC_BC   0x00000010 /* Broadcast Wakeup Enable */
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define SPEED_0		   0xffff
6062306a36Sopenharmony_ci#define HALF_DUPLEX        1
6162306a36Sopenharmony_ci#define FULL_DUPLEX        2
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* Error Codes */
6462306a36Sopenharmony_ci#define AT_ERR_EEPROM      1
6562306a36Sopenharmony_ci#define AT_ERR_PHY         2
6662306a36Sopenharmony_ci#define AT_ERR_CONFIG      3
6762306a36Sopenharmony_ci#define AT_ERR_PARAM       4
6862306a36Sopenharmony_ci#define AT_ERR_MAC_TYPE    5
6962306a36Sopenharmony_ci#define AT_ERR_PHY_TYPE    6
7062306a36Sopenharmony_ci#define AT_ERR_PHY_SPEED   7
7162306a36Sopenharmony_ci#define AT_ERR_PHY_RES     8
7262306a36Sopenharmony_ci#define AT_ERR_TIMEOUT     9
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define MAX_JUMBO_FRAME_SIZE 0x2000
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define AT_VLAN_TAG_TO_TPD_TAG(_vlan, _tpd)    \
7762306a36Sopenharmony_ci	_tpd = (((_vlan) << (4)) | (((_vlan) >> 13) & 7) |\
7862306a36Sopenharmony_ci		 (((_vlan) >> 9) & 8))
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define AT_TPD_TAG_TO_VLAN_TAG(_tpd, _vlan)    \
8162306a36Sopenharmony_ci	_vlan = (((_tpd) >> 8) | (((_tpd) & 0x77) << 9) |\
8262306a36Sopenharmony_ci		   (((_tdp) & 0x88) << 5))
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#define AT_MAX_RECEIVE_QUEUE    4
8562306a36Sopenharmony_ci#define AT_PAGE_NUM_PER_QUEUE   2
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define AT_DMA_HI_ADDR_MASK     0xffffffff00000000ULL
8862306a36Sopenharmony_ci#define AT_DMA_LO_ADDR_MASK     0x00000000ffffffffULL
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define AT_TX_WATCHDOG  (5 * HZ)
9162306a36Sopenharmony_ci#define AT_MAX_INT_WORK		10
9262306a36Sopenharmony_ci#define AT_TWSI_EEPROM_TIMEOUT 	100
9362306a36Sopenharmony_ci#define AT_HW_MAX_IDLE_DELAY 	10
9462306a36Sopenharmony_ci#define AT_SUSPEND_LINK_TIMEOUT 28
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define AT_REGS_LEN	75
9762306a36Sopenharmony_ci#define AT_EEPROM_LEN 	512
9862306a36Sopenharmony_ci#define AT_ADV_MASK	(ADVERTISE_10_HALF  |\
9962306a36Sopenharmony_ci			 ADVERTISE_10_FULL  |\
10062306a36Sopenharmony_ci			 ADVERTISE_100_HALF |\
10162306a36Sopenharmony_ci			 ADVERTISE_100_FULL |\
10262306a36Sopenharmony_ci			 ADVERTISE_1000_FULL)
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/* tpd word 2 */
10562306a36Sopenharmony_ci#define TPD_BUFLEN_MASK 	0x3FFF
10662306a36Sopenharmony_ci#define TPD_BUFLEN_SHIFT        0
10762306a36Sopenharmony_ci#define TPD_DMAINT_MASK		0x0001
10862306a36Sopenharmony_ci#define TPD_DMAINT_SHIFT        14
10962306a36Sopenharmony_ci#define TPD_PKTNT_MASK          0x0001
11062306a36Sopenharmony_ci#define TPD_PKTINT_SHIFT        15
11162306a36Sopenharmony_ci#define TPD_VLANTAG_MASK        0xFFFF
11262306a36Sopenharmony_ci#define TPD_VLAN_SHIFT          16
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci/* tpd word 3 bits 0:4 */
11562306a36Sopenharmony_ci#define TPD_EOP_MASK            0x0001
11662306a36Sopenharmony_ci#define TPD_EOP_SHIFT           0
11762306a36Sopenharmony_ci#define TPD_IP_VERSION_MASK	0x0001
11862306a36Sopenharmony_ci#define TPD_IP_VERSION_SHIFT	1	/* 0 : IPV4, 1 : IPV6 */
11962306a36Sopenharmony_ci#define TPD_INS_VL_TAG_MASK	0x0001
12062306a36Sopenharmony_ci#define TPD_INS_VL_TAG_SHIFT	2
12162306a36Sopenharmony_ci#define TPD_CC_SEGMENT_EN_MASK	0x0001
12262306a36Sopenharmony_ci#define TPD_CC_SEGMENT_EN_SHIFT	3
12362306a36Sopenharmony_ci#define TPD_SEGMENT_EN_MASK     0x0001
12462306a36Sopenharmony_ci#define TPD_SEGMENT_EN_SHIFT    4
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/* tdp word 3 bits 5:7 if ip version is 0 */
12762306a36Sopenharmony_ci#define TPD_IP_CSUM_MASK        0x0001
12862306a36Sopenharmony_ci#define TPD_IP_CSUM_SHIFT       5
12962306a36Sopenharmony_ci#define TPD_TCP_CSUM_MASK       0x0001
13062306a36Sopenharmony_ci#define TPD_TCP_CSUM_SHIFT      6
13162306a36Sopenharmony_ci#define TPD_UDP_CSUM_MASK       0x0001
13262306a36Sopenharmony_ci#define TPD_UDP_CSUM_SHIFT      7
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/* tdp word 3 bits 5:7 if ip version is 1 */
13562306a36Sopenharmony_ci#define TPD_V6_IPHLLO_MASK	0x0007
13662306a36Sopenharmony_ci#define TPD_V6_IPHLLO_SHIFT	7
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci/* tpd word 3 bits 8:9 bit */
13962306a36Sopenharmony_ci#define TPD_VL_TAGGED_MASK      0x0001
14062306a36Sopenharmony_ci#define TPD_VL_TAGGED_SHIFT     8
14162306a36Sopenharmony_ci#define TPD_ETHTYPE_MASK        0x0001
14262306a36Sopenharmony_ci#define TPD_ETHTYPE_SHIFT       9
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* tdp word 3 bits 10:13 if ip version is 0 */
14562306a36Sopenharmony_ci#define TDP_V4_IPHL_MASK	0x000F
14662306a36Sopenharmony_ci#define TPD_V4_IPHL_SHIFT	10
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/* tdp word 3 bits 10:13 if ip version is 1 */
14962306a36Sopenharmony_ci#define TPD_V6_IPHLHI_MASK	0x000F
15062306a36Sopenharmony_ci#define TPD_V6_IPHLHI_SHIFT	10
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/* tpd word 3 bit 14:31 if segment enabled */
15362306a36Sopenharmony_ci#define TPD_TCPHDRLEN_MASK      0x000F
15462306a36Sopenharmony_ci#define TPD_TCPHDRLEN_SHIFT     14
15562306a36Sopenharmony_ci#define TPD_HDRFLAG_MASK        0x0001
15662306a36Sopenharmony_ci#define TPD_HDRFLAG_SHIFT       18
15762306a36Sopenharmony_ci#define TPD_MSS_MASK            0x1FFF
15862306a36Sopenharmony_ci#define TPD_MSS_SHIFT           19
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci/* tdp word 3 bit 16:31 if custom csum enabled */
16162306a36Sopenharmony_ci#define TPD_PLOADOFFSET_MASK    0x00FF
16262306a36Sopenharmony_ci#define TPD_PLOADOFFSET_SHIFT   16
16362306a36Sopenharmony_ci#define TPD_CCSUMOFFSET_MASK    0x00FF
16462306a36Sopenharmony_ci#define TPD_CCSUMOFFSET_SHIFT   24
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_cistruct atl1e_tpd_desc {
16762306a36Sopenharmony_ci	__le64 buffer_addr;
16862306a36Sopenharmony_ci	__le32 word2;
16962306a36Sopenharmony_ci	__le32 word3;
17062306a36Sopenharmony_ci};
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ci/* how about 0x2000 */
17362306a36Sopenharmony_ci#define MAX_TX_BUF_LEN      0x2000
17462306a36Sopenharmony_ci#define MAX_TX_BUF_SHIFT    13
17562306a36Sopenharmony_ci#define MAX_TSO_SEG_SIZE    0x3c00
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/* rrs word 1 bit 0:31 */
17862306a36Sopenharmony_ci#define RRS_RX_CSUM_MASK	0xFFFF
17962306a36Sopenharmony_ci#define RRS_RX_CSUM_SHIFT	0
18062306a36Sopenharmony_ci#define RRS_PKT_SIZE_MASK	0x3FFF
18162306a36Sopenharmony_ci#define RRS_PKT_SIZE_SHIFT	16
18262306a36Sopenharmony_ci#define RRS_CPU_NUM_MASK	0x0003
18362306a36Sopenharmony_ci#define	RRS_CPU_NUM_SHIFT	30
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci#define	RRS_IS_RSS_IPV4		0x0001
18662306a36Sopenharmony_ci#define RRS_IS_RSS_IPV4_TCP	0x0002
18762306a36Sopenharmony_ci#define RRS_IS_RSS_IPV6		0x0004
18862306a36Sopenharmony_ci#define RRS_IS_RSS_IPV6_TCP	0x0008
18962306a36Sopenharmony_ci#define RRS_IS_IPV6		0x0010
19062306a36Sopenharmony_ci#define RRS_IS_IP_FRAG		0x0020
19162306a36Sopenharmony_ci#define RRS_IS_IP_DF		0x0040
19262306a36Sopenharmony_ci#define RRS_IS_802_3		0x0080
19362306a36Sopenharmony_ci#define RRS_IS_VLAN_TAG		0x0100
19462306a36Sopenharmony_ci#define RRS_IS_ERR_FRAME	0x0200
19562306a36Sopenharmony_ci#define RRS_IS_IPV4		0x0400
19662306a36Sopenharmony_ci#define RRS_IS_UDP		0x0800
19762306a36Sopenharmony_ci#define RRS_IS_TCP		0x1000
19862306a36Sopenharmony_ci#define RRS_IS_BCAST		0x2000
19962306a36Sopenharmony_ci#define RRS_IS_MCAST		0x4000
20062306a36Sopenharmony_ci#define RRS_IS_PAUSE		0x8000
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci#define RRS_ERR_BAD_CRC		0x0001
20362306a36Sopenharmony_ci#define RRS_ERR_CODE		0x0002
20462306a36Sopenharmony_ci#define RRS_ERR_DRIBBLE		0x0004
20562306a36Sopenharmony_ci#define RRS_ERR_RUNT		0x0008
20662306a36Sopenharmony_ci#define RRS_ERR_RX_OVERFLOW	0x0010
20762306a36Sopenharmony_ci#define RRS_ERR_TRUNC		0x0020
20862306a36Sopenharmony_ci#define RRS_ERR_IP_CSUM		0x0040
20962306a36Sopenharmony_ci#define RRS_ERR_L4_CSUM		0x0080
21062306a36Sopenharmony_ci#define RRS_ERR_LENGTH		0x0100
21162306a36Sopenharmony_ci#define RRS_ERR_DES_ADDR	0x0200
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_cistruct atl1e_recv_ret_status {
21462306a36Sopenharmony_ci	u16 seq_num;
21562306a36Sopenharmony_ci	u16 hash_lo;
21662306a36Sopenharmony_ci	__le32	word1;
21762306a36Sopenharmony_ci	u16 pkt_flag;
21862306a36Sopenharmony_ci	u16 err_flag;
21962306a36Sopenharmony_ci	u16 hash_hi;
22062306a36Sopenharmony_ci	u16 vtag;
22162306a36Sopenharmony_ci};
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_cienum atl1e_dma_req_block {
22462306a36Sopenharmony_ci	atl1e_dma_req_128 = 0,
22562306a36Sopenharmony_ci	atl1e_dma_req_256 = 1,
22662306a36Sopenharmony_ci	atl1e_dma_req_512 = 2,
22762306a36Sopenharmony_ci	atl1e_dma_req_1024 = 3,
22862306a36Sopenharmony_ci	atl1e_dma_req_2048 = 4,
22962306a36Sopenharmony_ci	atl1e_dma_req_4096 = 5
23062306a36Sopenharmony_ci};
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_cienum atl1e_rrs_type {
23362306a36Sopenharmony_ci	atl1e_rrs_disable = 0,
23462306a36Sopenharmony_ci	atl1e_rrs_ipv4 = 1,
23562306a36Sopenharmony_ci	atl1e_rrs_ipv4_tcp = 2,
23662306a36Sopenharmony_ci	atl1e_rrs_ipv6 = 4,
23762306a36Sopenharmony_ci	atl1e_rrs_ipv6_tcp = 8
23862306a36Sopenharmony_ci};
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_cienum atl1e_nic_type {
24162306a36Sopenharmony_ci	athr_l1e = 0,
24262306a36Sopenharmony_ci	athr_l2e_revA = 1,
24362306a36Sopenharmony_ci	athr_l2e_revB = 2
24462306a36Sopenharmony_ci};
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_cistruct atl1e_hw_stats {
24762306a36Sopenharmony_ci	/* rx */
24862306a36Sopenharmony_ci	unsigned long rx_ok;	      /* The number of good packet received. */
24962306a36Sopenharmony_ci	unsigned long rx_bcast;       /* The number of good broadcast packet received. */
25062306a36Sopenharmony_ci	unsigned long rx_mcast;       /* The number of good multicast packet received. */
25162306a36Sopenharmony_ci	unsigned long rx_pause;       /* The number of Pause packet received. */
25262306a36Sopenharmony_ci	unsigned long rx_ctrl;        /* The number of Control packet received other than Pause frame. */
25362306a36Sopenharmony_ci	unsigned long rx_fcs_err;     /* The number of packets with bad FCS. */
25462306a36Sopenharmony_ci	unsigned long rx_len_err;     /* The number of packets with mismatch of length field and actual size. */
25562306a36Sopenharmony_ci	unsigned long rx_byte_cnt;    /* The number of bytes of good packet received. FCS is NOT included. */
25662306a36Sopenharmony_ci	unsigned long rx_runt;        /* The number of packets received that are less than 64 byte long and with good FCS. */
25762306a36Sopenharmony_ci	unsigned long rx_frag;        /* The number of packets received that are less than 64 byte long and with bad FCS. */
25862306a36Sopenharmony_ci	unsigned long rx_sz_64;       /* The number of good and bad packets received that are 64 byte long. */
25962306a36Sopenharmony_ci	unsigned long rx_sz_65_127;   /* The number of good and bad packets received that are between 65 and 127-byte long. */
26062306a36Sopenharmony_ci	unsigned long rx_sz_128_255;  /* The number of good and bad packets received that are between 128 and 255-byte long. */
26162306a36Sopenharmony_ci	unsigned long rx_sz_256_511;  /* The number of good and bad packets received that are between 256 and 511-byte long. */
26262306a36Sopenharmony_ci	unsigned long rx_sz_512_1023; /* The number of good and bad packets received that are between 512 and 1023-byte long. */
26362306a36Sopenharmony_ci	unsigned long rx_sz_1024_1518;    /* The number of good and bad packets received that are between 1024 and 1518-byte long. */
26462306a36Sopenharmony_ci	unsigned long rx_sz_1519_max; /* The number of good and bad packets received that are between 1519-byte and MTU. */
26562306a36Sopenharmony_ci	unsigned long rx_sz_ov;       /* The number of good and bad packets received that are more than MTU size truncated by Selene. */
26662306a36Sopenharmony_ci	unsigned long rx_rxf_ov;      /* The number of frame dropped due to occurrence of RX FIFO overflow. */
26762306a36Sopenharmony_ci	unsigned long rx_rrd_ov;      /* The number of frame dropped due to occurrence of RRD overflow. */
26862306a36Sopenharmony_ci	unsigned long rx_align_err;   /* Alignment Error */
26962306a36Sopenharmony_ci	unsigned long rx_bcast_byte_cnt;  /* The byte count of broadcast packet received, excluding FCS. */
27062306a36Sopenharmony_ci	unsigned long rx_mcast_byte_cnt;  /* The byte count of multicast packet received, excluding FCS. */
27162306a36Sopenharmony_ci	unsigned long rx_err_addr;    /* The number of packets dropped due to address filtering. */
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci	/* tx */
27462306a36Sopenharmony_ci	unsigned long tx_ok;      /* The number of good packet transmitted. */
27562306a36Sopenharmony_ci	unsigned long tx_bcast;       /* The number of good broadcast packet transmitted. */
27662306a36Sopenharmony_ci	unsigned long tx_mcast;       /* The number of good multicast packet transmitted. */
27762306a36Sopenharmony_ci	unsigned long tx_pause;       /* The number of Pause packet transmitted. */
27862306a36Sopenharmony_ci	unsigned long tx_exc_defer;   /* The number of packets transmitted with excessive deferral. */
27962306a36Sopenharmony_ci	unsigned long tx_ctrl;        /* The number of packets transmitted is a control frame, excluding Pause frame. */
28062306a36Sopenharmony_ci	unsigned long tx_defer;       /* The number of packets transmitted that is deferred. */
28162306a36Sopenharmony_ci	unsigned long tx_byte_cnt;    /* The number of bytes of data transmitted. FCS is NOT included. */
28262306a36Sopenharmony_ci	unsigned long tx_sz_64;       /* The number of good and bad packets transmitted that are 64 byte long. */
28362306a36Sopenharmony_ci	unsigned long tx_sz_65_127;   /* The number of good and bad packets transmitted that are between 65 and 127-byte long. */
28462306a36Sopenharmony_ci	unsigned long tx_sz_128_255;  /* The number of good and bad packets transmitted that are between 128 and 255-byte long. */
28562306a36Sopenharmony_ci	unsigned long tx_sz_256_511;  /* The number of good and bad packets transmitted that are between 256 and 511-byte long. */
28662306a36Sopenharmony_ci	unsigned long tx_sz_512_1023; /* The number of good and bad packets transmitted that are between 512 and 1023-byte long. */
28762306a36Sopenharmony_ci	unsigned long tx_sz_1024_1518;    /* The number of good and bad packets transmitted that are between 1024 and 1518-byte long. */
28862306a36Sopenharmony_ci	unsigned long tx_sz_1519_max; /* The number of good and bad packets transmitted that are between 1519-byte and MTU. */
28962306a36Sopenharmony_ci	unsigned long tx_1_col;       /* The number of packets subsequently transmitted successfully with a single prior collision. */
29062306a36Sopenharmony_ci	unsigned long tx_2_col;       /* The number of packets subsequently transmitted successfully with multiple prior collisions. */
29162306a36Sopenharmony_ci	unsigned long tx_late_col;    /* The number of packets transmitted with late collisions. */
29262306a36Sopenharmony_ci	unsigned long tx_abort_col;   /* The number of transmit packets aborted due to excessive collisions. */
29362306a36Sopenharmony_ci	unsigned long tx_underrun;    /* The number of transmit packets aborted due to transmit FIFO underrun, or TRD FIFO underrun */
29462306a36Sopenharmony_ci	unsigned long tx_rd_eop;      /* The number of times that read beyond the EOP into the next frame area when TRD was not written timely */
29562306a36Sopenharmony_ci	unsigned long tx_len_err;     /* The number of transmit packets with length field does NOT match the actual frame size. */
29662306a36Sopenharmony_ci	unsigned long tx_trunc;       /* The number of transmit packets truncated due to size exceeding MTU. */
29762306a36Sopenharmony_ci	unsigned long tx_bcast_byte;  /* The byte count of broadcast packet transmitted, excluding FCS. */
29862306a36Sopenharmony_ci	unsigned long tx_mcast_byte;  /* The byte count of multicast packet transmitted, excluding FCS. */
29962306a36Sopenharmony_ci};
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_cistruct atl1e_hw {
30262306a36Sopenharmony_ci	u8 __iomem      *hw_addr;            /* inner register address */
30362306a36Sopenharmony_ci	resource_size_t mem_rang;
30462306a36Sopenharmony_ci	struct atl1e_adapter *adapter;
30562306a36Sopenharmony_ci	enum atl1e_nic_type  nic_type;
30662306a36Sopenharmony_ci	u16 device_id;
30762306a36Sopenharmony_ci	u16 vendor_id;
30862306a36Sopenharmony_ci	u16 subsystem_id;
30962306a36Sopenharmony_ci	u16 subsystem_vendor_id;
31062306a36Sopenharmony_ci	u8  revision_id;
31162306a36Sopenharmony_ci	u16 pci_cmd_word;
31262306a36Sopenharmony_ci	u8 mac_addr[ETH_ALEN];
31362306a36Sopenharmony_ci	u8 perm_mac_addr[ETH_ALEN];
31462306a36Sopenharmony_ci	u8 preamble_len;
31562306a36Sopenharmony_ci	u16 max_frame_size;
31662306a36Sopenharmony_ci	u16 rx_jumbo_th;
31762306a36Sopenharmony_ci	u16 tx_jumbo_th;
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci	u16 media_type;
32062306a36Sopenharmony_ci#define MEDIA_TYPE_AUTO_SENSOR  0
32162306a36Sopenharmony_ci#define MEDIA_TYPE_100M_FULL    1
32262306a36Sopenharmony_ci#define MEDIA_TYPE_100M_HALF    2
32362306a36Sopenharmony_ci#define MEDIA_TYPE_10M_FULL     3
32462306a36Sopenharmony_ci#define MEDIA_TYPE_10M_HALF     4
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ci	u16 autoneg_advertised;
32762306a36Sopenharmony_ci#define ADVERTISE_10_HALF               0x0001
32862306a36Sopenharmony_ci#define ADVERTISE_10_FULL               0x0002
32962306a36Sopenharmony_ci#define ADVERTISE_100_HALF              0x0004
33062306a36Sopenharmony_ci#define ADVERTISE_100_FULL              0x0008
33162306a36Sopenharmony_ci#define ADVERTISE_1000_HALF             0x0010 /* Not used, just FYI */
33262306a36Sopenharmony_ci#define ADVERTISE_1000_FULL             0x0020
33362306a36Sopenharmony_ci	u16 mii_autoneg_adv_reg;
33462306a36Sopenharmony_ci	u16 mii_1000t_ctrl_reg;
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci	u16 imt;        /* Interrupt Moderator timer ( 2us resolution) */
33762306a36Sopenharmony_ci	u16 ict;        /* Interrupt Clear timer (2us resolution) */
33862306a36Sopenharmony_ci	u32 smb_timer;
33962306a36Sopenharmony_ci	u16 rrd_thresh; /* Threshold of number of RRD produced to trigger
34062306a36Sopenharmony_ci			  interrupt request */
34162306a36Sopenharmony_ci	u16 tpd_thresh;
34262306a36Sopenharmony_ci	u16 rx_count_down; /* 2us resolution */
34362306a36Sopenharmony_ci	u16 tx_count_down;
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci	u8 tpd_burst;   /* Number of TPD to prefetch in cache-aligned burst. */
34662306a36Sopenharmony_ci	enum atl1e_rrs_type rrs_type;
34762306a36Sopenharmony_ci	u32 base_cpu;
34862306a36Sopenharmony_ci	u32 indirect_tab;
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci	enum atl1e_dma_req_block dmar_block;
35162306a36Sopenharmony_ci	enum atl1e_dma_req_block dmaw_block;
35262306a36Sopenharmony_ci	u8 dmaw_dly_cnt;
35362306a36Sopenharmony_ci	u8 dmar_dly_cnt;
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ci	bool phy_configured;
35662306a36Sopenharmony_ci	bool re_autoneg;
35762306a36Sopenharmony_ci	bool emi_ca;
35862306a36Sopenharmony_ci};
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci/*
36162306a36Sopenharmony_ci * wrapper around a pointer to a socket buffer,
36262306a36Sopenharmony_ci * so a DMA handle can be stored along with the buffer
36362306a36Sopenharmony_ci */
36462306a36Sopenharmony_cistruct atl1e_tx_buffer {
36562306a36Sopenharmony_ci	struct sk_buff *skb;
36662306a36Sopenharmony_ci	u16 flags;
36762306a36Sopenharmony_ci#define ATL1E_TX_PCIMAP_SINGLE		0x0001
36862306a36Sopenharmony_ci#define ATL1E_TX_PCIMAP_PAGE		0x0002
36962306a36Sopenharmony_ci#define ATL1E_TX_PCIMAP_TYPE_MASK	0x0003
37062306a36Sopenharmony_ci	u16 length;
37162306a36Sopenharmony_ci	dma_addr_t dma;
37262306a36Sopenharmony_ci};
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ci#define ATL1E_SET_PCIMAP_TYPE(tx_buff, type) do {		\
37562306a36Sopenharmony_ci	((tx_buff)->flags) &= ~ATL1E_TX_PCIMAP_TYPE_MASK;	\
37662306a36Sopenharmony_ci	((tx_buff)->flags) |= (type);				\
37762306a36Sopenharmony_ci	} while (0)
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_cistruct atl1e_rx_page {
38062306a36Sopenharmony_ci	dma_addr_t	dma;    /* receive rage DMA address */
38162306a36Sopenharmony_ci	u8		*addr;   /* receive rage virtual address */
38262306a36Sopenharmony_ci	dma_addr_t	write_offset_dma;  /* the DMA address which contain the
38362306a36Sopenharmony_ci					      receive data offset in the page */
38462306a36Sopenharmony_ci	u32		*write_offset_addr; /* the virtaul address which contain
38562306a36Sopenharmony_ci					     the receive data offset in the page */
38662306a36Sopenharmony_ci	u32		read_offset;       /* the offset where we have read */
38762306a36Sopenharmony_ci};
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_cistruct atl1e_rx_page_desc {
39062306a36Sopenharmony_ci	struct atl1e_rx_page   rx_page[AT_PAGE_NUM_PER_QUEUE];
39162306a36Sopenharmony_ci	u8  rx_using;
39262306a36Sopenharmony_ci	u16 rx_nxseq;
39362306a36Sopenharmony_ci};
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci/* transmit packet descriptor (tpd) ring */
39662306a36Sopenharmony_cistruct atl1e_tx_ring {
39762306a36Sopenharmony_ci	struct atl1e_tpd_desc *desc;  /* descriptor ring virtual address  */
39862306a36Sopenharmony_ci	dma_addr_t	   dma;    /* descriptor ring physical address */
39962306a36Sopenharmony_ci	u16       	   count;  /* the count of transmit rings  */
40062306a36Sopenharmony_ci	rwlock_t	   tx_lock;
40162306a36Sopenharmony_ci	u16		   next_to_use;
40262306a36Sopenharmony_ci	atomic_t	   next_to_clean;
40362306a36Sopenharmony_ci	struct atl1e_tx_buffer *tx_buffer;
40462306a36Sopenharmony_ci	dma_addr_t	   cmb_dma;
40562306a36Sopenharmony_ci	u32		   *cmb;
40662306a36Sopenharmony_ci};
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_ci/* receive packet descriptor ring */
40962306a36Sopenharmony_cistruct atl1e_rx_ring {
41062306a36Sopenharmony_ci	void        	*desc;
41162306a36Sopenharmony_ci	dma_addr_t  	dma;
41262306a36Sopenharmony_ci	int         	size;
41362306a36Sopenharmony_ci	u32	    	page_size; /* bytes length of rxf page */
41462306a36Sopenharmony_ci	u32		real_page_size; /* real_page_size = page_size + jumbo + aliagn */
41562306a36Sopenharmony_ci	struct atl1e_rx_page_desc	rx_page_desc[AT_MAX_RECEIVE_QUEUE];
41662306a36Sopenharmony_ci};
41762306a36Sopenharmony_ci
41862306a36Sopenharmony_ci/* board specific private data structure */
41962306a36Sopenharmony_cistruct atl1e_adapter {
42062306a36Sopenharmony_ci	struct net_device   *netdev;
42162306a36Sopenharmony_ci	struct pci_dev      *pdev;
42262306a36Sopenharmony_ci	struct napi_struct  napi;
42362306a36Sopenharmony_ci	struct mii_if_info  mii;    /* MII interface info */
42462306a36Sopenharmony_ci	struct atl1e_hw        hw;
42562306a36Sopenharmony_ci	struct atl1e_hw_stats  hw_stats;
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci	u32 wol;
42862306a36Sopenharmony_ci	u16 link_speed;
42962306a36Sopenharmony_ci	u16 link_duplex;
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci	spinlock_t mdio_lock;
43262306a36Sopenharmony_ci	atomic_t irq_sem;
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci	struct work_struct reset_task;
43562306a36Sopenharmony_ci	struct work_struct link_chg_task;
43662306a36Sopenharmony_ci	struct timer_list watchdog_timer;
43762306a36Sopenharmony_ci	struct timer_list phy_config_timer;
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci	/* All Descriptor memory */
44062306a36Sopenharmony_ci	dma_addr_t  	ring_dma;
44162306a36Sopenharmony_ci	void     	*ring_vir_addr;
44262306a36Sopenharmony_ci	u32             ring_size;
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ci	struct atl1e_tx_ring tx_ring;
44562306a36Sopenharmony_ci	struct atl1e_rx_ring rx_ring;
44662306a36Sopenharmony_ci	int num_rx_queues;
44762306a36Sopenharmony_ci	unsigned long flags;
44862306a36Sopenharmony_ci#define __AT_TESTING        0x0001
44962306a36Sopenharmony_ci#define __AT_RESETTING      0x0002
45062306a36Sopenharmony_ci#define __AT_DOWN           0x0003
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_ci	u32 bd_number;     /* board number;*/
45362306a36Sopenharmony_ci	u32 pci_state[16];
45462306a36Sopenharmony_ci	u32 *config_space;
45562306a36Sopenharmony_ci};
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci#define AT_WRITE_REG(a, reg, value) ( \
45862306a36Sopenharmony_ci		writel((value), ((a)->hw_addr + reg)))
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci#define AT_WRITE_FLUSH(a) (\
46162306a36Sopenharmony_ci		readl((a)->hw_addr))
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci#define AT_READ_REG(a, reg) ( \
46462306a36Sopenharmony_ci		readl((a)->hw_addr + reg))
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci#define AT_WRITE_REGB(a, reg, value) (\
46762306a36Sopenharmony_ci		writeb((value), ((a)->hw_addr + reg)))
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_ci#define AT_READ_REGB(a, reg) (\
47062306a36Sopenharmony_ci		readb((a)->hw_addr + reg))
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_ci#define AT_WRITE_REGW(a, reg, value) (\
47362306a36Sopenharmony_ci		writew((value), ((a)->hw_addr + reg)))
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ci#define AT_READ_REGW(a, reg) (\
47662306a36Sopenharmony_ci		readw((a)->hw_addr + reg))
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci#define AT_WRITE_REG_ARRAY(a, reg, offset, value) ( \
47962306a36Sopenharmony_ci		writel((value), (((a)->hw_addr + reg) + ((offset) << 2))))
48062306a36Sopenharmony_ci
48162306a36Sopenharmony_ci#define AT_READ_REG_ARRAY(a, reg, offset) ( \
48262306a36Sopenharmony_ci		readl(((a)->hw_addr + reg) + ((offset) << 2)))
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_ciextern char atl1e_driver_name[];
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_civoid atl1e_check_options(struct atl1e_adapter *adapter);
48762306a36Sopenharmony_ciint atl1e_up(struct atl1e_adapter *adapter);
48862306a36Sopenharmony_civoid atl1e_down(struct atl1e_adapter *adapter);
48962306a36Sopenharmony_civoid atl1e_reinit_locked(struct atl1e_adapter *adapter);
49062306a36Sopenharmony_cis32 atl1e_reset_hw(struct atl1e_hw *hw);
49162306a36Sopenharmony_civoid atl1e_set_ethtool_ops(struct net_device *netdev);
49262306a36Sopenharmony_ci#endif /* _ATL1_E_H_ */
493