162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright(c) 2008 - 2009 Atheros Corporation. All rights reserved.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Derived from Intel e1000 driver
662306a36Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _ATL1C_H_
1062306a36Sopenharmony_ci#define _ATL1C_H_
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/interrupt.h>
1362306a36Sopenharmony_ci#include <linux/types.h>
1462306a36Sopenharmony_ci#include <linux/errno.h>
1562306a36Sopenharmony_ci#include <linux/module.h>
1662306a36Sopenharmony_ci#include <linux/pci.h>
1762306a36Sopenharmony_ci#include <linux/netdevice.h>
1862306a36Sopenharmony_ci#include <linux/etherdevice.h>
1962306a36Sopenharmony_ci#include <linux/skbuff.h>
2062306a36Sopenharmony_ci#include <linux/ioport.h>
2162306a36Sopenharmony_ci#include <linux/slab.h>
2262306a36Sopenharmony_ci#include <linux/list.h>
2362306a36Sopenharmony_ci#include <linux/delay.h>
2462306a36Sopenharmony_ci#include <linux/sched.h>
2562306a36Sopenharmony_ci#include <linux/in.h>
2662306a36Sopenharmony_ci#include <linux/ip.h>
2762306a36Sopenharmony_ci#include <linux/ipv6.h>
2862306a36Sopenharmony_ci#include <linux/udp.h>
2962306a36Sopenharmony_ci#include <linux/mii.h>
3062306a36Sopenharmony_ci#include <linux/io.h>
3162306a36Sopenharmony_ci#include <linux/vmalloc.h>
3262306a36Sopenharmony_ci#include <linux/pagemap.h>
3362306a36Sopenharmony_ci#include <linux/tcp.h>
3462306a36Sopenharmony_ci#include <linux/ethtool.h>
3562306a36Sopenharmony_ci#include <linux/if_vlan.h>
3662306a36Sopenharmony_ci#include <linux/workqueue.h>
3762306a36Sopenharmony_ci#include <net/checksum.h>
3862306a36Sopenharmony_ci#include <net/ip6_checksum.h>
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#include "atl1c_hw.h"
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* Wake Up Filter Control */
4362306a36Sopenharmony_ci#define AT_WUFC_LNKC 0x00000001 /* Link Status Change Wakeup Enable */
4462306a36Sopenharmony_ci#define AT_WUFC_MAG  0x00000002 /* Magic Packet Wakeup Enable */
4562306a36Sopenharmony_ci#define AT_WUFC_EX   0x00000004 /* Directed Exact Wakeup Enable */
4662306a36Sopenharmony_ci#define AT_WUFC_MC   0x00000008 /* Multicast Wakeup Enable */
4762306a36Sopenharmony_ci#define AT_WUFC_BC   0x00000010 /* Broadcast Wakeup Enable */
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define AT_VLAN_TO_TAG(_vlan, _tag)	   \
5062306a36Sopenharmony_ci	_tag =  ((((_vlan) >> 8) & 0xFF)  |\
5162306a36Sopenharmony_ci		 (((_vlan) & 0xFF) << 8))
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#define AT_TAG_TO_VLAN(_tag, _vlan) 	 \
5462306a36Sopenharmony_ci	_vlan = ((((_tag) >> 8) & 0xFF) |\
5562306a36Sopenharmony_ci		(((_tag) & 0xFF) << 8))
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define SPEED_0		   0xffff
5862306a36Sopenharmony_ci#define HALF_DUPLEX        1
5962306a36Sopenharmony_ci#define FULL_DUPLEX        2
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci#define AT_RX_BUF_SIZE		(ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)
6262306a36Sopenharmony_ci#define MAX_JUMBO_FRAME_SIZE	(6*1024)
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#define AT_MAX_RECEIVE_QUEUE    4
6562306a36Sopenharmony_ci#define AT_DEF_RECEIVE_QUEUE	1
6662306a36Sopenharmony_ci#define AT_MAX_TRANSMIT_QUEUE  4
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define AT_DMA_HI_ADDR_MASK     0xffffffff00000000ULL
6962306a36Sopenharmony_ci#define AT_DMA_LO_ADDR_MASK     0x00000000ffffffffULL
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define AT_TX_WATCHDOG  (5 * HZ)
7262306a36Sopenharmony_ci#define AT_MAX_INT_WORK		5
7362306a36Sopenharmony_ci#define AT_TWSI_EEPROM_TIMEOUT 	100
7462306a36Sopenharmony_ci#define AT_HW_MAX_IDLE_DELAY 	10
7562306a36Sopenharmony_ci#define AT_SUSPEND_LINK_TIMEOUT 100
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#define AT_ASPM_L0S_TIMER	6
7862306a36Sopenharmony_ci#define AT_ASPM_L1_TIMER	12
7962306a36Sopenharmony_ci#define AT_LCKDET_TIMER		12
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define ATL1C_PCIE_L0S_L1_DISABLE 	0x01
8262306a36Sopenharmony_ci#define ATL1C_PCIE_PHY_RESET		0x02
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#define ATL1C_ASPM_L0s_ENABLE		0x0001
8562306a36Sopenharmony_ci#define ATL1C_ASPM_L1_ENABLE		0x0002
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define AT_REGS_LEN	(74 * sizeof(u32))
8862306a36Sopenharmony_ci#define AT_EEPROM_LEN 	512
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define ATL1C_GET_DESC(R, i, type)	(&(((type *)((R)->desc))[i]))
9162306a36Sopenharmony_ci#define ATL1C_RFD_DESC(R, i)	ATL1C_GET_DESC(R, i, struct atl1c_rx_free_desc)
9262306a36Sopenharmony_ci#define ATL1C_TPD_DESC(R, i)	ATL1C_GET_DESC(R, i, struct atl1c_tpd_desc)
9362306a36Sopenharmony_ci#define ATL1C_RRD_DESC(R, i)	ATL1C_GET_DESC(R, i, struct atl1c_recv_ret_status)
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/* tpd word 1 bit 0:7 General Checksum task offload */
9662306a36Sopenharmony_ci#define TPD_L4HDR_OFFSET_MASK	0x00FF
9762306a36Sopenharmony_ci#define TPD_L4HDR_OFFSET_SHIFT	0
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci/* tpd word 1 bit 0:7 Large Send task offload (IPv4/IPV6) */
10062306a36Sopenharmony_ci#define TPD_TCPHDR_OFFSET_MASK	0x00FF
10162306a36Sopenharmony_ci#define TPD_TCPHDR_OFFSET_SHIFT	0
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* tpd word 1 bit 0:7 Custom Checksum task offload */
10462306a36Sopenharmony_ci#define TPD_PLOADOFFSET_MASK	0x00FF
10562306a36Sopenharmony_ci#define TPD_PLOADOFFSET_SHIFT	0
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/* tpd word 1 bit 8:17 */
10862306a36Sopenharmony_ci#define TPD_CCSUM_EN_MASK	0x0001
10962306a36Sopenharmony_ci#define TPD_CCSUM_EN_SHIFT	8
11062306a36Sopenharmony_ci#define TPD_IP_CSUM_MASK	0x0001
11162306a36Sopenharmony_ci#define TPD_IP_CSUM_SHIFT	9
11262306a36Sopenharmony_ci#define TPD_TCP_CSUM_MASK	0x0001
11362306a36Sopenharmony_ci#define TPD_TCP_CSUM_SHIFT	10
11462306a36Sopenharmony_ci#define TPD_UDP_CSUM_MASK	0x0001
11562306a36Sopenharmony_ci#define TPD_UDP_CSUM_SHIFT	11
11662306a36Sopenharmony_ci#define TPD_LSO_EN_MASK		0x0001	/* TCP Large Send Offload */
11762306a36Sopenharmony_ci#define TPD_LSO_EN_SHIFT	12
11862306a36Sopenharmony_ci#define TPD_LSO_VER_MASK	0x0001
11962306a36Sopenharmony_ci#define TPD_LSO_VER_SHIFT	13 	/* 0 : ipv4; 1 : ipv4/ipv6 */
12062306a36Sopenharmony_ci#define TPD_CON_VTAG_MASK	0x0001
12162306a36Sopenharmony_ci#define TPD_CON_VTAG_SHIFT	14
12262306a36Sopenharmony_ci#define TPD_INS_VTAG_MASK	0x0001
12362306a36Sopenharmony_ci#define TPD_INS_VTAG_SHIFT	15
12462306a36Sopenharmony_ci#define TPD_IPV4_PACKET_MASK	0x0001  /* valid when LSO VER  is 1 */
12562306a36Sopenharmony_ci#define TPD_IPV4_PACKET_SHIFT	16
12662306a36Sopenharmony_ci#define TPD_ETH_TYPE_MASK	0x0001
12762306a36Sopenharmony_ci#define TPD_ETH_TYPE_SHIFT	17	/* 0 : 802.3 frame; 1 : Ethernet */
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci/* tpd word 18:25 Custom Checksum task offload */
13062306a36Sopenharmony_ci#define TPD_CCSUM_OFFSET_MASK	0x00FF
13162306a36Sopenharmony_ci#define TPD_CCSUM_OFFSET_SHIFT	18
13262306a36Sopenharmony_ci#define TPD_CCSUM_EPAD_MASK	0x0001
13362306a36Sopenharmony_ci#define TPD_CCSUM_EPAD_SHIFT	30
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/* tpd word 18:30 Large Send task offload (IPv4/IPV6) */
13662306a36Sopenharmony_ci#define TPD_MSS_MASK            0x1FFF
13762306a36Sopenharmony_ci#define TPD_MSS_SHIFT		18
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci#define TPD_EOP_MASK		0x0001
14062306a36Sopenharmony_ci#define TPD_EOP_SHIFT		31
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_cistruct atl1c_tpd_desc {
14362306a36Sopenharmony_ci	__le16	buffer_len; /* include 4-byte CRC */
14462306a36Sopenharmony_ci	__le16	vlan_tag;
14562306a36Sopenharmony_ci	__le32	word1;
14662306a36Sopenharmony_ci	__le64	buffer_addr;
14762306a36Sopenharmony_ci};
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_cistruct atl1c_tpd_ext_desc {
15062306a36Sopenharmony_ci	u32 reservd_0;
15162306a36Sopenharmony_ci	__le32 word1;
15262306a36Sopenharmony_ci	__le32 pkt_len;
15362306a36Sopenharmony_ci	u32 reservd_1;
15462306a36Sopenharmony_ci};
15562306a36Sopenharmony_ci/* rrs word 0 bit 0:31 */
15662306a36Sopenharmony_ci#define RRS_RX_CSUM_MASK	0xFFFF
15762306a36Sopenharmony_ci#define RRS_RX_CSUM_SHIFT	0
15862306a36Sopenharmony_ci#define RRS_RX_RFD_CNT_MASK	0x000F
15962306a36Sopenharmony_ci#define RRS_RX_RFD_CNT_SHIFT	16
16062306a36Sopenharmony_ci#define RRS_RX_RFD_INDEX_MASK	0x0FFF
16162306a36Sopenharmony_ci#define RRS_RX_RFD_INDEX_SHIFT	20
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci/* rrs flag bit 0:16 */
16462306a36Sopenharmony_ci#define RRS_HEAD_LEN_MASK	0x00FF
16562306a36Sopenharmony_ci#define RRS_HEAD_LEN_SHIFT	0
16662306a36Sopenharmony_ci#define RRS_HDS_TYPE_MASK	0x0003
16762306a36Sopenharmony_ci#define RRS_HDS_TYPE_SHIFT	8
16862306a36Sopenharmony_ci#define RRS_CPU_NUM_MASK	0x0003
16962306a36Sopenharmony_ci#define	RRS_CPU_NUM_SHIFT	10
17062306a36Sopenharmony_ci#define RRS_HASH_FLG_MASK	0x000F
17162306a36Sopenharmony_ci#define RRS_HASH_FLG_SHIFT	12
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#define RRS_HDS_TYPE_HEAD	1
17462306a36Sopenharmony_ci#define RRS_HDS_TYPE_DATA	2
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci#define RRS_IS_NO_HDS_TYPE(flag) \
17762306a36Sopenharmony_ci	((((flag) >> (RRS_HDS_TYPE_SHIFT)) & RRS_HDS_TYPE_MASK) == 0)
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci#define RRS_IS_HDS_HEAD(flag) \
18062306a36Sopenharmony_ci	((((flag) >> (RRS_HDS_TYPE_SHIFT)) & RRS_HDS_TYPE_MASK) == \
18162306a36Sopenharmony_ci			RRS_HDS_TYPE_HEAD)
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci#define RRS_IS_HDS_DATA(flag) \
18462306a36Sopenharmony_ci	((((flag) >> (RRS_HDS_TYPE_SHIFT)) & RRS_HDS_TYPE_MASK) == \
18562306a36Sopenharmony_ci			RRS_HDS_TYPE_DATA)
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci/* rrs word 3 bit 0:31 */
18862306a36Sopenharmony_ci#define RRS_PKT_SIZE_MASK	0x3FFF
18962306a36Sopenharmony_ci#define RRS_PKT_SIZE_SHIFT	0
19062306a36Sopenharmony_ci#define RRS_ERR_L4_CSUM_MASK	0x0001
19162306a36Sopenharmony_ci#define RRS_ERR_L4_CSUM_SHIFT	14
19262306a36Sopenharmony_ci#define RRS_ERR_IP_CSUM_MASK	0x0001
19362306a36Sopenharmony_ci#define RRS_ERR_IP_CSUM_SHIFT	15
19462306a36Sopenharmony_ci#define RRS_VLAN_INS_MASK	0x0001
19562306a36Sopenharmony_ci#define RRS_VLAN_INS_SHIFT	16
19662306a36Sopenharmony_ci#define RRS_PROT_ID_MASK	0x0007
19762306a36Sopenharmony_ci#define RRS_PROT_ID_SHIFT	17
19862306a36Sopenharmony_ci#define RRS_RX_ERR_SUM_MASK	0x0001
19962306a36Sopenharmony_ci#define RRS_RX_ERR_SUM_SHIFT	20
20062306a36Sopenharmony_ci#define RRS_RX_ERR_CRC_MASK	0x0001
20162306a36Sopenharmony_ci#define RRS_RX_ERR_CRC_SHIFT	21
20262306a36Sopenharmony_ci#define RRS_RX_ERR_FAE_MASK	0x0001
20362306a36Sopenharmony_ci#define RRS_RX_ERR_FAE_SHIFT	22
20462306a36Sopenharmony_ci#define RRS_RX_ERR_TRUNC_MASK	0x0001
20562306a36Sopenharmony_ci#define RRS_RX_ERR_TRUNC_SHIFT	23
20662306a36Sopenharmony_ci#define RRS_RX_ERR_RUNC_MASK	0x0001
20762306a36Sopenharmony_ci#define RRS_RX_ERR_RUNC_SHIFT	24
20862306a36Sopenharmony_ci#define RRS_RX_ERR_ICMP_MASK	0x0001
20962306a36Sopenharmony_ci#define RRS_RX_ERR_ICMP_SHIFT	25
21062306a36Sopenharmony_ci#define RRS_PACKET_BCAST_MASK	0x0001
21162306a36Sopenharmony_ci#define RRS_PACKET_BCAST_SHIFT	26
21262306a36Sopenharmony_ci#define RRS_PACKET_MCAST_MASK	0x0001
21362306a36Sopenharmony_ci#define RRS_PACKET_MCAST_SHIFT	27
21462306a36Sopenharmony_ci#define RRS_PACKET_TYPE_MASK	0x0001
21562306a36Sopenharmony_ci#define RRS_PACKET_TYPE_SHIFT	28
21662306a36Sopenharmony_ci#define RRS_FIFO_FULL_MASK	0x0001
21762306a36Sopenharmony_ci#define RRS_FIFO_FULL_SHIFT	29
21862306a36Sopenharmony_ci#define RRS_802_3_LEN_ERR_MASK 	0x0001
21962306a36Sopenharmony_ci#define RRS_802_3_LEN_ERR_SHIFT 30
22062306a36Sopenharmony_ci#define RRS_RXD_UPDATED_MASK	0x0001
22162306a36Sopenharmony_ci#define RRS_RXD_UPDATED_SHIFT	31
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci#define RRS_ERR_L4_CSUM         0x00004000
22462306a36Sopenharmony_ci#define RRS_ERR_IP_CSUM         0x00008000
22562306a36Sopenharmony_ci#define RRS_VLAN_INS            0x00010000
22662306a36Sopenharmony_ci#define RRS_RX_ERR_SUM          0x00100000
22762306a36Sopenharmony_ci#define RRS_RX_ERR_CRC          0x00200000
22862306a36Sopenharmony_ci#define RRS_802_3_LEN_ERR	0x40000000
22962306a36Sopenharmony_ci#define RRS_RXD_UPDATED		0x80000000
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci#define RRS_PACKET_TYPE_802_3  	1
23262306a36Sopenharmony_ci#define RRS_PACKET_TYPE_ETH	0
23362306a36Sopenharmony_ci#define RRS_PACKET_IS_ETH(word) \
23462306a36Sopenharmony_ci	((((word) >> RRS_PACKET_TYPE_SHIFT) & RRS_PACKET_TYPE_MASK) == \
23562306a36Sopenharmony_ci			RRS_PACKET_TYPE_ETH)
23662306a36Sopenharmony_ci#define RRS_RXD_IS_VALID(word) \
23762306a36Sopenharmony_ci	((((word) >> RRS_RXD_UPDATED_SHIFT) & RRS_RXD_UPDATED_MASK) == 1)
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci#define RRS_PACKET_PROT_IS_IPV4_ONLY(word) \
24062306a36Sopenharmony_ci	((((word) >> RRS_PROT_ID_SHIFT) & RRS_PROT_ID_MASK) == 1)
24162306a36Sopenharmony_ci#define RRS_PACKET_PROT_IS_IPV6_ONLY(word) \
24262306a36Sopenharmony_ci	((((word) >> RRS_PROT_ID_SHIFT) & RRS_PROT_ID_MASK) == 6)
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci#define RRS_MT_PROT_ID_TCPUDP	BIT(19)
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_cistruct atl1c_recv_ret_status {
24762306a36Sopenharmony_ci	__le32  word0;
24862306a36Sopenharmony_ci	__le32	rss_hash;
24962306a36Sopenharmony_ci	__le16	vlan_tag;
25062306a36Sopenharmony_ci	__le16	flag;
25162306a36Sopenharmony_ci	__le32	word3;
25262306a36Sopenharmony_ci};
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci/* RFD descriptor */
25562306a36Sopenharmony_cistruct atl1c_rx_free_desc {
25662306a36Sopenharmony_ci	__le64	buffer_addr;
25762306a36Sopenharmony_ci};
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci/* DMA Order Settings */
26062306a36Sopenharmony_cienum atl1c_dma_order {
26162306a36Sopenharmony_ci	atl1c_dma_ord_in = 1,
26262306a36Sopenharmony_ci	atl1c_dma_ord_enh = 2,
26362306a36Sopenharmony_ci	atl1c_dma_ord_out = 4
26462306a36Sopenharmony_ci};
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_cienum atl1c_dma_rcb {
26762306a36Sopenharmony_ci	atl1c_rcb_64 = 0,
26862306a36Sopenharmony_ci	atl1c_rcb_128 = 1
26962306a36Sopenharmony_ci};
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_cienum atl1c_mac_speed {
27262306a36Sopenharmony_ci	atl1c_mac_speed_0 = 0,
27362306a36Sopenharmony_ci	atl1c_mac_speed_10_100 = 1,
27462306a36Sopenharmony_ci	atl1c_mac_speed_1000 = 2
27562306a36Sopenharmony_ci};
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_cienum atl1c_dma_req_block {
27862306a36Sopenharmony_ci	atl1c_dma_req_128 = 0,
27962306a36Sopenharmony_ci	atl1c_dma_req_256 = 1,
28062306a36Sopenharmony_ci	atl1c_dma_req_512 = 2,
28162306a36Sopenharmony_ci	atl1c_dma_req_1024 = 3,
28262306a36Sopenharmony_ci	atl1c_dma_req_2048 = 4,
28362306a36Sopenharmony_ci	atl1c_dma_req_4096 = 5
28462306a36Sopenharmony_ci};
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_cienum atl1c_nic_type {
28862306a36Sopenharmony_ci	athr_l1c = 0,
28962306a36Sopenharmony_ci	athr_l2c = 1,
29062306a36Sopenharmony_ci	athr_l2c_b,
29162306a36Sopenharmony_ci	athr_l2c_b2,
29262306a36Sopenharmony_ci	athr_l1d,
29362306a36Sopenharmony_ci	athr_l1d_2,
29462306a36Sopenharmony_ci	athr_mt,
29562306a36Sopenharmony_ci};
29662306a36Sopenharmony_ci
29762306a36Sopenharmony_cistruct atl1c_hw_stats {
29862306a36Sopenharmony_ci	/* rx */
29962306a36Sopenharmony_ci	unsigned long rx_ok;		/* The number of good packet received. */
30062306a36Sopenharmony_ci	unsigned long rx_bcast;		/* The number of good broadcast packet received. */
30162306a36Sopenharmony_ci	unsigned long rx_mcast;		/* The number of good multicast packet received. */
30262306a36Sopenharmony_ci	unsigned long rx_pause;		/* The number of Pause packet received. */
30362306a36Sopenharmony_ci	unsigned long rx_ctrl;		/* The number of Control packet received other than Pause frame. */
30462306a36Sopenharmony_ci	unsigned long rx_fcs_err;	/* The number of packets with bad FCS. */
30562306a36Sopenharmony_ci	unsigned long rx_len_err;	/* The number of packets with mismatch of length field and actual size. */
30662306a36Sopenharmony_ci	unsigned long rx_byte_cnt;	/* The number of bytes of good packet received. FCS is NOT included. */
30762306a36Sopenharmony_ci	unsigned long rx_runt;		/* The number of packets received that are less than 64 byte long and with good FCS. */
30862306a36Sopenharmony_ci	unsigned long rx_frag;		/* The number of packets received that are less than 64 byte long and with bad FCS. */
30962306a36Sopenharmony_ci	unsigned long rx_sz_64;		/* The number of good and bad packets received that are 64 byte long. */
31062306a36Sopenharmony_ci	unsigned long rx_sz_65_127;	/* The number of good and bad packets received that are between 65 and 127-byte long. */
31162306a36Sopenharmony_ci	unsigned long rx_sz_128_255;	/* The number of good and bad packets received that are between 128 and 255-byte long. */
31262306a36Sopenharmony_ci	unsigned long rx_sz_256_511;	/* The number of good and bad packets received that are between 256 and 511-byte long. */
31362306a36Sopenharmony_ci	unsigned long rx_sz_512_1023;	/* The number of good and bad packets received that are between 512 and 1023-byte long. */
31462306a36Sopenharmony_ci	unsigned long rx_sz_1024_1518;	/* The number of good and bad packets received that are between 1024 and 1518-byte long. */
31562306a36Sopenharmony_ci	unsigned long rx_sz_1519_max;	/* The number of good and bad packets received that are between 1519-byte and MTU. */
31662306a36Sopenharmony_ci	unsigned long rx_sz_ov;		/* The number of good and bad packets received that are more than MTU size truncated by Selene. */
31762306a36Sopenharmony_ci	unsigned long rx_rxf_ov;	/* The number of frame dropped due to occurrence of RX FIFO overflow. */
31862306a36Sopenharmony_ci	unsigned long rx_rrd_ov;	/* The number of frame dropped due to occurrence of RRD overflow. */
31962306a36Sopenharmony_ci	unsigned long rx_align_err;	/* Alignment Error */
32062306a36Sopenharmony_ci	unsigned long rx_bcast_byte_cnt; /* The byte count of broadcast packet received, excluding FCS. */
32162306a36Sopenharmony_ci	unsigned long rx_mcast_byte_cnt; /* The byte count of multicast packet received, excluding FCS. */
32262306a36Sopenharmony_ci	unsigned long rx_err_addr;	/* The number of packets dropped due to address filtering. */
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci	/* tx */
32562306a36Sopenharmony_ci	unsigned long tx_ok;		/* The number of good packet transmitted. */
32662306a36Sopenharmony_ci	unsigned long tx_bcast;		/* The number of good broadcast packet transmitted. */
32762306a36Sopenharmony_ci	unsigned long tx_mcast;		/* The number of good multicast packet transmitted. */
32862306a36Sopenharmony_ci	unsigned long tx_pause;		/* The number of Pause packet transmitted. */
32962306a36Sopenharmony_ci	unsigned long tx_exc_defer;	/* The number of packets transmitted with excessive deferral. */
33062306a36Sopenharmony_ci	unsigned long tx_ctrl;		/* The number of packets transmitted is a control frame, excluding Pause frame. */
33162306a36Sopenharmony_ci	unsigned long tx_defer;		/* The number of packets transmitted that is deferred. */
33262306a36Sopenharmony_ci	unsigned long tx_byte_cnt;	/* The number of bytes of data transmitted. FCS is NOT included. */
33362306a36Sopenharmony_ci	unsigned long tx_sz_64;		/* The number of good and bad packets transmitted that are 64 byte long. */
33462306a36Sopenharmony_ci	unsigned long tx_sz_65_127;	/* The number of good and bad packets transmitted that are between 65 and 127-byte long. */
33562306a36Sopenharmony_ci	unsigned long tx_sz_128_255;	/* The number of good and bad packets transmitted that are between 128 and 255-byte long. */
33662306a36Sopenharmony_ci	unsigned long tx_sz_256_511;	/* The number of good and bad packets transmitted that are between 256 and 511-byte long. */
33762306a36Sopenharmony_ci	unsigned long tx_sz_512_1023;	/* The number of good and bad packets transmitted that are between 512 and 1023-byte long. */
33862306a36Sopenharmony_ci	unsigned long tx_sz_1024_1518;	/* The number of good and bad packets transmitted that are between 1024 and 1518-byte long. */
33962306a36Sopenharmony_ci	unsigned long tx_sz_1519_max;	/* The number of good and bad packets transmitted that are between 1519-byte and MTU. */
34062306a36Sopenharmony_ci	unsigned long tx_1_col;		/* The number of packets subsequently transmitted successfully with a single prior collision. */
34162306a36Sopenharmony_ci	unsigned long tx_2_col;		/* The number of packets subsequently transmitted successfully with multiple prior collisions. */
34262306a36Sopenharmony_ci	unsigned long tx_late_col;	/* The number of packets transmitted with late collisions. */
34362306a36Sopenharmony_ci	unsigned long tx_abort_col;	/* The number of transmit packets aborted due to excessive collisions. */
34462306a36Sopenharmony_ci	unsigned long tx_underrun;	/* The number of transmit packets aborted due to transmit FIFO underrun, or TRD FIFO underrun */
34562306a36Sopenharmony_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 */
34662306a36Sopenharmony_ci	unsigned long tx_len_err;	/* The number of transmit packets with length field does NOT match the actual frame size. */
34762306a36Sopenharmony_ci	unsigned long tx_trunc;		/* The number of transmit packets truncated due to size exceeding MTU. */
34862306a36Sopenharmony_ci	unsigned long tx_bcast_byte;	/* The byte count of broadcast packet transmitted, excluding FCS. */
34962306a36Sopenharmony_ci	unsigned long tx_mcast_byte;	/* The byte count of multicast packet transmitted, excluding FCS. */
35062306a36Sopenharmony_ci};
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_cistruct atl1c_hw {
35362306a36Sopenharmony_ci	u8 __iomem      *hw_addr;            /* inner register address */
35462306a36Sopenharmony_ci	struct atl1c_adapter *adapter;
35562306a36Sopenharmony_ci	enum atl1c_nic_type  nic_type;
35662306a36Sopenharmony_ci	enum atl1c_dma_order dma_order;
35762306a36Sopenharmony_ci	enum atl1c_dma_rcb   rcb_value;
35862306a36Sopenharmony_ci	enum atl1c_dma_req_block dmar_block;
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci	u16 device_id;
36162306a36Sopenharmony_ci	u16 vendor_id;
36262306a36Sopenharmony_ci	u16 subsystem_id;
36362306a36Sopenharmony_ci	u16 subsystem_vendor_id;
36462306a36Sopenharmony_ci	u8 revision_id;
36562306a36Sopenharmony_ci	u16 phy_id1;
36662306a36Sopenharmony_ci	u16 phy_id2;
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ci	spinlock_t intr_mask_lock;	/* protect the intr_mask */
36962306a36Sopenharmony_ci	u32 intr_mask;
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci	u8 preamble_len;
37262306a36Sopenharmony_ci	u16 max_frame_size;
37362306a36Sopenharmony_ci	u16 min_frame_size;
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci	enum atl1c_mac_speed mac_speed;
37662306a36Sopenharmony_ci	bool mac_duplex;
37762306a36Sopenharmony_ci	bool hibernate;
37862306a36Sopenharmony_ci	u16 media_type;
37962306a36Sopenharmony_ci#define MEDIA_TYPE_AUTO_SENSOR  0
38062306a36Sopenharmony_ci#define MEDIA_TYPE_100M_FULL    1
38162306a36Sopenharmony_ci#define MEDIA_TYPE_100M_HALF    2
38262306a36Sopenharmony_ci#define MEDIA_TYPE_10M_FULL     3
38362306a36Sopenharmony_ci#define MEDIA_TYPE_10M_HALF     4
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci	u16 autoneg_advertised;
38662306a36Sopenharmony_ci	u16 mii_autoneg_adv_reg;
38762306a36Sopenharmony_ci	u16 mii_1000t_ctrl_reg;
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ci	u16 tx_imt;	/* TX Interrupt Moderator timer ( 2us resolution) */
39062306a36Sopenharmony_ci	u16 rx_imt;	/* RX Interrupt Moderator timer ( 2us resolution) */
39162306a36Sopenharmony_ci	u16 ict;        /* Interrupt Clear timer (2us resolution) */
39262306a36Sopenharmony_ci	u16 ctrl_flags;
39362306a36Sopenharmony_ci#define ATL1C_INTR_CLEAR_ON_READ	0x0001
39462306a36Sopenharmony_ci#define ATL1C_INTR_MODRT_ENABLE	 	0x0002
39562306a36Sopenharmony_ci#define ATL1C_CMB_ENABLE		0x0004
39662306a36Sopenharmony_ci#define ATL1C_SMB_ENABLE		0x0010
39762306a36Sopenharmony_ci#define ATL1C_TXQ_MODE_ENHANCE		0x0020
39862306a36Sopenharmony_ci#define ATL1C_RX_IPV6_CHKSUM		0x0040
39962306a36Sopenharmony_ci#define ATL1C_ASPM_L0S_SUPPORT		0x0080
40062306a36Sopenharmony_ci#define ATL1C_ASPM_L1_SUPPORT		0x0100
40162306a36Sopenharmony_ci#define ATL1C_ASPM_CTRL_MON		0x0200
40262306a36Sopenharmony_ci#define ATL1C_HIB_DISABLE		0x0400
40362306a36Sopenharmony_ci#define ATL1C_APS_MODE_ENABLE           0x0800
40462306a36Sopenharmony_ci#define ATL1C_LINK_EXT_SYNC             0x1000
40562306a36Sopenharmony_ci#define ATL1C_CLK_GATING_EN             0x2000
40662306a36Sopenharmony_ci#define ATL1C_FPGA_VERSION              0x8000
40762306a36Sopenharmony_ci	u16 link_cap_flags;
40862306a36Sopenharmony_ci#define ATL1C_LINK_CAP_1000M		0x0001
40962306a36Sopenharmony_ci	u32 smb_timer;
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_ci	u16 rrd_thresh; /* Threshold of number of RRD produced to trigger
41262306a36Sopenharmony_ci			  interrupt request */
41362306a36Sopenharmony_ci	u16 tpd_thresh;
41462306a36Sopenharmony_ci	u8 tpd_burst;   /* Number of TPD to prefetch in cache-aligned burst. */
41562306a36Sopenharmony_ci	u8 rfd_burst;
41662306a36Sopenharmony_ci	u32 base_cpu;
41762306a36Sopenharmony_ci	u32 indirect_tab;
41862306a36Sopenharmony_ci	u8 mac_addr[ETH_ALEN];
41962306a36Sopenharmony_ci	u8 perm_mac_addr[ETH_ALEN];
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ci	bool phy_configured;
42262306a36Sopenharmony_ci	bool re_autoneg;
42362306a36Sopenharmony_ci	bool emi_ca;
42462306a36Sopenharmony_ci	bool msi_lnkpatch;	/* link patch for specific platforms */
42562306a36Sopenharmony_ci};
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci/*
42862306a36Sopenharmony_ci * atl1c_ring_header represents a single, contiguous block of DMA space
42962306a36Sopenharmony_ci * mapped for the three descriptor rings (tpd, rfd, rrd) described below
43062306a36Sopenharmony_ci */
43162306a36Sopenharmony_cistruct atl1c_ring_header {
43262306a36Sopenharmony_ci	void *desc;		/* virtual address */
43362306a36Sopenharmony_ci	dma_addr_t dma;		/* physical address*/
43462306a36Sopenharmony_ci	unsigned int size;	/* length in bytes */
43562306a36Sopenharmony_ci};
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_ci/*
43862306a36Sopenharmony_ci * atl1c_buffer is wrapper around a pointer to a socket buffer
43962306a36Sopenharmony_ci * so a DMA handle can be stored along with the skb
44062306a36Sopenharmony_ci */
44162306a36Sopenharmony_cistruct atl1c_buffer {
44262306a36Sopenharmony_ci	struct sk_buff *skb;	/* socket buffer */
44362306a36Sopenharmony_ci	u16 length;		/* rx buffer length */
44462306a36Sopenharmony_ci	u16 flags;		/* information of buffer */
44562306a36Sopenharmony_ci#define ATL1C_BUFFER_FREE		0x0001
44662306a36Sopenharmony_ci#define ATL1C_BUFFER_BUSY		0x0002
44762306a36Sopenharmony_ci#define ATL1C_BUFFER_STATE_MASK		0x0003
44862306a36Sopenharmony_ci
44962306a36Sopenharmony_ci#define ATL1C_PCIMAP_SINGLE		0x0004
45062306a36Sopenharmony_ci#define ATL1C_PCIMAP_PAGE		0x0008
45162306a36Sopenharmony_ci#define ATL1C_PCIMAP_TYPE_MASK		0x000C
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci#define ATL1C_PCIMAP_TODEVICE		0x0010
45462306a36Sopenharmony_ci#define ATL1C_PCIMAP_FROMDEVICE		0x0020
45562306a36Sopenharmony_ci#define ATL1C_PCIMAP_DIRECTION_MASK	0x0030
45662306a36Sopenharmony_ci	dma_addr_t dma;
45762306a36Sopenharmony_ci};
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci#define ATL1C_SET_BUFFER_STATE(buff, state) do {	\
46062306a36Sopenharmony_ci	((buff)->flags) &= ~ATL1C_BUFFER_STATE_MASK;	\
46162306a36Sopenharmony_ci	((buff)->flags) |= (state);			\
46262306a36Sopenharmony_ci	} while (0)
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_ci#define ATL1C_SET_PCIMAP_TYPE(buff, type, direction) do {	\
46562306a36Sopenharmony_ci	((buff)->flags) &= ~ATL1C_PCIMAP_TYPE_MASK;		\
46662306a36Sopenharmony_ci	((buff)->flags) |= (type);				\
46762306a36Sopenharmony_ci	((buff)->flags) &= ~ATL1C_PCIMAP_DIRECTION_MASK;	\
46862306a36Sopenharmony_ci	((buff)->flags) |= (direction);				\
46962306a36Sopenharmony_ci	} while (0)
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci/* transimit packet descriptor (tpd) ring */
47262306a36Sopenharmony_cistruct atl1c_tpd_ring {
47362306a36Sopenharmony_ci	struct atl1c_adapter *adapter;
47462306a36Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
47562306a36Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
47662306a36Sopenharmony_ci	u16 num;
47762306a36Sopenharmony_ci	u16 size;		/* descriptor ring length in bytes */
47862306a36Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
47962306a36Sopenharmony_ci	u16 next_to_use;
48062306a36Sopenharmony_ci	atomic_t next_to_clean;
48162306a36Sopenharmony_ci	struct atl1c_buffer *buffer_info;
48262306a36Sopenharmony_ci	struct napi_struct napi;
48362306a36Sopenharmony_ci};
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ci/* receive free descriptor (rfd) ring */
48662306a36Sopenharmony_cistruct atl1c_rfd_ring {
48762306a36Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
48862306a36Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
48962306a36Sopenharmony_ci	u16 size;		/* descriptor ring length in bytes */
49062306a36Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
49162306a36Sopenharmony_ci	u16 next_to_use;
49262306a36Sopenharmony_ci	u16 next_to_clean;
49362306a36Sopenharmony_ci	struct atl1c_buffer *buffer_info;
49462306a36Sopenharmony_ci};
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci/* receive return descriptor (rrd) ring */
49762306a36Sopenharmony_cistruct atl1c_rrd_ring {
49862306a36Sopenharmony_ci	struct atl1c_adapter *adapter;
49962306a36Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
50062306a36Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
50162306a36Sopenharmony_ci	u16 num;
50262306a36Sopenharmony_ci	u16 size;		/* descriptor ring length in bytes */
50362306a36Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
50462306a36Sopenharmony_ci	u16 next_to_use;
50562306a36Sopenharmony_ci	u16 next_to_clean;
50662306a36Sopenharmony_ci	struct napi_struct napi;
50762306a36Sopenharmony_ci};
50862306a36Sopenharmony_ci
50962306a36Sopenharmony_ci/* board specific private data structure */
51062306a36Sopenharmony_cistruct atl1c_adapter {
51162306a36Sopenharmony_ci	struct net_device   *netdev;
51262306a36Sopenharmony_ci	struct pci_dev      *pdev;
51362306a36Sopenharmony_ci	struct atl1c_hw        hw;
51462306a36Sopenharmony_ci	struct atl1c_hw_stats  hw_stats;
51562306a36Sopenharmony_ci	struct mii_if_info  mii;    /* MII interface info */
51662306a36Sopenharmony_ci	u16 rx_buffer_len;
51762306a36Sopenharmony_ci	unsigned int tx_queue_count;
51862306a36Sopenharmony_ci	unsigned int rx_queue_count;
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_ci	unsigned long flags;
52162306a36Sopenharmony_ci#define __AT_TESTING        0x0001
52262306a36Sopenharmony_ci#define __AT_RESETTING      0x0002
52362306a36Sopenharmony_ci#define __AT_DOWN           0x0003
52462306a36Sopenharmony_ci	unsigned long work_event;
52562306a36Sopenharmony_ci#define	ATL1C_WORK_EVENT_RESET		0
52662306a36Sopenharmony_ci#define	ATL1C_WORK_EVENT_LINK_CHANGE	1
52762306a36Sopenharmony_ci	u32 msg_enable;
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ci	bool have_msi;
53062306a36Sopenharmony_ci	u32 wol;
53162306a36Sopenharmony_ci	u16 link_speed;
53262306a36Sopenharmony_ci	u16 link_duplex;
53362306a36Sopenharmony_ci
53462306a36Sopenharmony_ci	spinlock_t mdio_lock;
53562306a36Sopenharmony_ci	atomic_t irq_sem;
53662306a36Sopenharmony_ci
53762306a36Sopenharmony_ci	struct work_struct common_task;
53862306a36Sopenharmony_ci	struct timer_list watchdog_timer;
53962306a36Sopenharmony_ci	struct timer_list phy_config_timer;
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci	/* All Descriptor memory */
54262306a36Sopenharmony_ci	struct atl1c_ring_header ring_header;
54362306a36Sopenharmony_ci	struct atl1c_tpd_ring tpd_ring[AT_MAX_TRANSMIT_QUEUE];
54462306a36Sopenharmony_ci	struct atl1c_rfd_ring rfd_ring[AT_MAX_RECEIVE_QUEUE];
54562306a36Sopenharmony_ci	struct atl1c_rrd_ring rrd_ring[AT_MAX_RECEIVE_QUEUE];
54662306a36Sopenharmony_ci	u32 bd_number;     /* board number;*/
54762306a36Sopenharmony_ci};
54862306a36Sopenharmony_ci
54962306a36Sopenharmony_ci#define AT_WRITE_REG(a, reg, value) ( \
55062306a36Sopenharmony_ci		writel((value), ((a)->hw_addr + reg)))
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci#define AT_WRITE_FLUSH(a) (\
55362306a36Sopenharmony_ci		readl((a)->hw_addr))
55462306a36Sopenharmony_ci
55562306a36Sopenharmony_ci#define AT_READ_REG(a, reg, pdata) do {					\
55662306a36Sopenharmony_ci		if (unlikely((a)->hibernate)) {				\
55762306a36Sopenharmony_ci			readl((a)->hw_addr + reg);			\
55862306a36Sopenharmony_ci			*(u32 *)pdata = readl((a)->hw_addr + reg);	\
55962306a36Sopenharmony_ci		} else {						\
56062306a36Sopenharmony_ci			*(u32 *)pdata = readl((a)->hw_addr + reg);	\
56162306a36Sopenharmony_ci		}							\
56262306a36Sopenharmony_ci	} while (0)
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_ci#define AT_WRITE_REGB(a, reg, value) (\
56562306a36Sopenharmony_ci		writeb((value), ((a)->hw_addr + reg)))
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_ci#define AT_READ_REGB(a, reg) (\
56862306a36Sopenharmony_ci		readb((a)->hw_addr + reg))
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ci#define AT_WRITE_REGW(a, reg, value) (\
57162306a36Sopenharmony_ci		writew((value), ((a)->hw_addr + reg)))
57262306a36Sopenharmony_ci
57362306a36Sopenharmony_ci#define AT_READ_REGW(a, reg, pdata) do {				\
57462306a36Sopenharmony_ci		if (unlikely((a)->hibernate)) {				\
57562306a36Sopenharmony_ci			readw((a)->hw_addr + reg);			\
57662306a36Sopenharmony_ci			*(u16 *)pdata = readw((a)->hw_addr + reg);	\
57762306a36Sopenharmony_ci		} else {						\
57862306a36Sopenharmony_ci			*(u16 *)pdata = readw((a)->hw_addr + reg);	\
57962306a36Sopenharmony_ci		}							\
58062306a36Sopenharmony_ci	} while (0)
58162306a36Sopenharmony_ci
58262306a36Sopenharmony_ci#define AT_WRITE_REG_ARRAY(a, reg, offset, value) ( \
58362306a36Sopenharmony_ci		writel((value), (((a)->hw_addr + reg) + ((offset) << 2))))
58462306a36Sopenharmony_ci
58562306a36Sopenharmony_ci#define AT_READ_REG_ARRAY(a, reg, offset) ( \
58662306a36Sopenharmony_ci		readl(((a)->hw_addr + reg) + ((offset) << 2)))
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ciextern char atl1c_driver_name[];
58962306a36Sopenharmony_ci
59062306a36Sopenharmony_civoid atl1c_reinit_locked(struct atl1c_adapter *adapter);
59162306a36Sopenharmony_cis32 atl1c_reset_hw(struct atl1c_hw *hw);
59262306a36Sopenharmony_civoid atl1c_set_ethtool_ops(struct net_device *netdev);
59362306a36Sopenharmony_ci#endif /* _ATL1C_H_ */
594