162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
462306a36Sopenharmony_ci * Copyright(c) 2006 - 2007 Chris Snook <csnook@redhat.com>
562306a36Sopenharmony_ci * Copyright(c) 2006 - 2008 Jay Cliburn <jcliburn@gmail.com>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Derived from Intel e1000 driver
862306a36Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef ATL1_H
1262306a36Sopenharmony_ci#define ATL1_H
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/compiler.h>
1562306a36Sopenharmony_ci#include <linux/ethtool.h>
1662306a36Sopenharmony_ci#include <linux/if_vlan.h>
1762306a36Sopenharmony_ci#include <linux/mii.h>
1862306a36Sopenharmony_ci#include <linux/module.h>
1962306a36Sopenharmony_ci#include <linux/skbuff.h>
2062306a36Sopenharmony_ci#include <linux/spinlock.h>
2162306a36Sopenharmony_ci#include <linux/timer.h>
2262306a36Sopenharmony_ci#include <linux/types.h>
2362306a36Sopenharmony_ci#include <linux/workqueue.h>
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#include "atlx.h"
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#define ATLX_DRIVER_NAME "atl1"
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciMODULE_DESCRIPTION("Atheros L1 Gigabit Ethernet Driver");
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define atlx_adapter		atl1_adapter
3262306a36Sopenharmony_ci#define atlx_check_for_link	atl1_check_for_link
3362306a36Sopenharmony_ci#define atlx_check_link		atl1_check_link
3462306a36Sopenharmony_ci#define atlx_hash_mc_addr	atl1_hash_mc_addr
3562306a36Sopenharmony_ci#define atlx_hash_set		atl1_hash_set
3662306a36Sopenharmony_ci#define atlx_hw			atl1_hw
3762306a36Sopenharmony_ci#define atlx_mii_ioctl		atl1_mii_ioctl
3862306a36Sopenharmony_ci#define atlx_read_phy_reg	atl1_read_phy_reg
3962306a36Sopenharmony_ci#define atlx_set_mac		atl1_set_mac
4062306a36Sopenharmony_ci#define atlx_set_mac_addr	atl1_set_mac_addr
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistruct atl1_adapter;
4362306a36Sopenharmony_cistruct atl1_hw;
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/* function prototypes needed by multiple files */
4662306a36Sopenharmony_cistatic u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
4762306a36Sopenharmony_cistatic void atl1_hash_set(struct atl1_hw *hw, u32 hash_value);
4862306a36Sopenharmony_cistatic void atl1_set_mac_addr(struct atl1_hw *hw);
4962306a36Sopenharmony_cistatic int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5062306a36Sopenharmony_ci	int cmd);
5162306a36Sopenharmony_cistatic u32 atl1_check_link(struct atl1_adapter *adapter);
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* hardware definitions specific to L1 */
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* Block IDLE Status Register */
5662306a36Sopenharmony_ci#define IDLE_STATUS_RXMAC			0x1
5762306a36Sopenharmony_ci#define IDLE_STATUS_TXMAC			0x2
5862306a36Sopenharmony_ci#define IDLE_STATUS_RXQ				0x4
5962306a36Sopenharmony_ci#define IDLE_STATUS_TXQ				0x8
6062306a36Sopenharmony_ci#define IDLE_STATUS_DMAR			0x10
6162306a36Sopenharmony_ci#define IDLE_STATUS_DMAW			0x20
6262306a36Sopenharmony_ci#define IDLE_STATUS_SMB				0x40
6362306a36Sopenharmony_ci#define IDLE_STATUS_CMB				0x80
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/* MDIO Control Register */
6662306a36Sopenharmony_ci#define MDIO_WAIT_TIMES				30
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* MAC Control Register */
6962306a36Sopenharmony_ci#define MAC_CTRL_TX_PAUSE			0x10000
7062306a36Sopenharmony_ci#define MAC_CTRL_SCNT				0x20000
7162306a36Sopenharmony_ci#define MAC_CTRL_SRST_TX			0x40000
7262306a36Sopenharmony_ci#define MAC_CTRL_TX_SIMURST			0x80000
7362306a36Sopenharmony_ci#define MAC_CTRL_SPEED_SHIFT			20
7462306a36Sopenharmony_ci#define MAC_CTRL_SPEED_MASK			0x300000
7562306a36Sopenharmony_ci#define MAC_CTRL_SPEED_1000			0x2
7662306a36Sopenharmony_ci#define MAC_CTRL_SPEED_10_100			0x1
7762306a36Sopenharmony_ci#define MAC_CTRL_DBG_TX_BKPRESURE		0x400000
7862306a36Sopenharmony_ci#define MAC_CTRL_TX_HUGE			0x800000
7962306a36Sopenharmony_ci#define MAC_CTRL_RX_CHKSUM_EN			0x1000000
8062306a36Sopenharmony_ci#define MAC_CTRL_DBG				0x8000000
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/* Wake-On-Lan control register */
8362306a36Sopenharmony_ci#define WOL_CLK_SWITCH_EN			0x8000
8462306a36Sopenharmony_ci#define WOL_PT5_EN				0x200000
8562306a36Sopenharmony_ci#define WOL_PT6_EN				0x400000
8662306a36Sopenharmony_ci#define WOL_PT5_MATCH				0x8000000
8762306a36Sopenharmony_ci#define WOL_PT6_MATCH				0x10000000
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/* WOL Length ( 2 DWORD ) */
9062306a36Sopenharmony_ci#define REG_WOL_PATTERN_LEN			0x14A4
9162306a36Sopenharmony_ci#define WOL_PT_LEN_MASK				0x7F
9262306a36Sopenharmony_ci#define WOL_PT0_LEN_SHIFT			0
9362306a36Sopenharmony_ci#define WOL_PT1_LEN_SHIFT			8
9462306a36Sopenharmony_ci#define WOL_PT2_LEN_SHIFT			16
9562306a36Sopenharmony_ci#define WOL_PT3_LEN_SHIFT			24
9662306a36Sopenharmony_ci#define WOL_PT4_LEN_SHIFT			0
9762306a36Sopenharmony_ci#define WOL_PT5_LEN_SHIFT			8
9862306a36Sopenharmony_ci#define WOL_PT6_LEN_SHIFT			16
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/* Internal SRAM Partition Registers, low 32 bits */
10162306a36Sopenharmony_ci#define REG_SRAM_RFD_LEN			0x1504
10262306a36Sopenharmony_ci#define REG_SRAM_RRD_ADDR			0x1508
10362306a36Sopenharmony_ci#define REG_SRAM_RRD_LEN			0x150C
10462306a36Sopenharmony_ci#define REG_SRAM_TPD_ADDR			0x1510
10562306a36Sopenharmony_ci#define REG_SRAM_TPD_LEN			0x1514
10662306a36Sopenharmony_ci#define REG_SRAM_TRD_ADDR			0x1518
10762306a36Sopenharmony_ci#define REG_SRAM_TRD_LEN			0x151C
10862306a36Sopenharmony_ci#define REG_SRAM_RXF_ADDR			0x1520
10962306a36Sopenharmony_ci#define REG_SRAM_RXF_LEN			0x1524
11062306a36Sopenharmony_ci#define REG_SRAM_TXF_ADDR			0x1528
11162306a36Sopenharmony_ci#define REG_SRAM_TXF_LEN			0x152C
11262306a36Sopenharmony_ci#define REG_SRAM_TCPH_PATH_ADDR			0x1530
11362306a36Sopenharmony_ci#define SRAM_TCPH_ADDR_MASK			0xFFF
11462306a36Sopenharmony_ci#define SRAM_TCPH_ADDR_SHIFT			0
11562306a36Sopenharmony_ci#define SRAM_PATH_ADDR_MASK			0xFFF
11662306a36Sopenharmony_ci#define SRAM_PATH_ADDR_SHIFT			16
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/* Load Ptr Register */
11962306a36Sopenharmony_ci#define REG_LOAD_PTR				0x1534
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci/* Descriptor Control registers, low 32 bits */
12262306a36Sopenharmony_ci#define REG_DESC_RFD_ADDR_LO			0x1544
12362306a36Sopenharmony_ci#define REG_DESC_RRD_ADDR_LO			0x1548
12462306a36Sopenharmony_ci#define REG_DESC_TPD_ADDR_LO			0x154C
12562306a36Sopenharmony_ci#define REG_DESC_CMB_ADDR_LO			0x1550
12662306a36Sopenharmony_ci#define REG_DESC_SMB_ADDR_LO			0x1554
12762306a36Sopenharmony_ci#define REG_DESC_RFD_RRD_RING_SIZE		0x1558
12862306a36Sopenharmony_ci#define DESC_RFD_RING_SIZE_MASK			0x7FF
12962306a36Sopenharmony_ci#define DESC_RFD_RING_SIZE_SHIFT		0
13062306a36Sopenharmony_ci#define DESC_RRD_RING_SIZE_MASK			0x7FF
13162306a36Sopenharmony_ci#define DESC_RRD_RING_SIZE_SHIFT		16
13262306a36Sopenharmony_ci#define REG_DESC_TPD_RING_SIZE			0x155C
13362306a36Sopenharmony_ci#define DESC_TPD_RING_SIZE_MASK			0x3FF
13462306a36Sopenharmony_ci#define DESC_TPD_RING_SIZE_SHIFT		0
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/* TXQ Control Register */
13762306a36Sopenharmony_ci#define REG_TXQ_CTRL				0x1580
13862306a36Sopenharmony_ci#define TXQ_CTRL_TPD_BURST_NUM_SHIFT		0
13962306a36Sopenharmony_ci#define TXQ_CTRL_TPD_BURST_NUM_MASK		0x1F
14062306a36Sopenharmony_ci#define TXQ_CTRL_EN				0x20
14162306a36Sopenharmony_ci#define TXQ_CTRL_ENH_MODE			0x40
14262306a36Sopenharmony_ci#define TXQ_CTRL_TPD_FETCH_TH_SHIFT		8
14362306a36Sopenharmony_ci#define TXQ_CTRL_TPD_FETCH_TH_MASK		0x3F
14462306a36Sopenharmony_ci#define TXQ_CTRL_TXF_BURST_NUM_SHIFT		16
14562306a36Sopenharmony_ci#define TXQ_CTRL_TXF_BURST_NUM_MASK		0xFFFF
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci/* Jumbo packet Threshold for task offload */
14862306a36Sopenharmony_ci#define REG_TX_JUMBO_TASK_TH_TPD_IPG		0x1584
14962306a36Sopenharmony_ci#define TX_JUMBO_TASK_TH_MASK			0x7FF
15062306a36Sopenharmony_ci#define TX_JUMBO_TASK_TH_SHIFT			0
15162306a36Sopenharmony_ci#define TX_TPD_MIN_IPG_MASK			0x1F
15262306a36Sopenharmony_ci#define TX_TPD_MIN_IPG_SHIFT			16
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/* RXQ Control Register */
15562306a36Sopenharmony_ci#define REG_RXQ_CTRL				0x15A0
15662306a36Sopenharmony_ci#define RXQ_CTRL_RFD_BURST_NUM_SHIFT		0
15762306a36Sopenharmony_ci#define RXQ_CTRL_RFD_BURST_NUM_MASK		0xFF
15862306a36Sopenharmony_ci#define RXQ_CTRL_RRD_BURST_THRESH_SHIFT		8
15962306a36Sopenharmony_ci#define RXQ_CTRL_RRD_BURST_THRESH_MASK		0xFF
16062306a36Sopenharmony_ci#define RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT		16
16162306a36Sopenharmony_ci#define RXQ_CTRL_RFD_PREF_MIN_IPG_MASK		0x1F
16262306a36Sopenharmony_ci#define RXQ_CTRL_CUT_THRU_EN			0x40000000
16362306a36Sopenharmony_ci#define RXQ_CTRL_EN				0x80000000
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/* Rx jumbo packet threshold and rrd  retirement timer */
16662306a36Sopenharmony_ci#define REG_RXQ_JMBOSZ_RRDTIM			0x15A4
16762306a36Sopenharmony_ci#define RXQ_JMBOSZ_TH_MASK			0x7FF
16862306a36Sopenharmony_ci#define RXQ_JMBOSZ_TH_SHIFT			0
16962306a36Sopenharmony_ci#define RXQ_JMBO_LKAH_MASK			0xF
17062306a36Sopenharmony_ci#define RXQ_JMBO_LKAH_SHIFT			11
17162306a36Sopenharmony_ci#define RXQ_RRD_TIMER_MASK			0xFFFF
17262306a36Sopenharmony_ci#define RXQ_RRD_TIMER_SHIFT			16
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci/* RFD flow control register */
17562306a36Sopenharmony_ci#define REG_RXQ_RXF_PAUSE_THRESH		0x15A8
17662306a36Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_HI_SHIFT		16
17762306a36Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_HI_MASK		0xFFF
17862306a36Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_LO_SHIFT		0
17962306a36Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_LO_MASK		0xFFF
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci/* RRD flow control register */
18262306a36Sopenharmony_ci#define REG_RXQ_RRD_PAUSE_THRESH		0x15AC
18362306a36Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_HI_SHIFT		0
18462306a36Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_HI_MASK		0xFFF
18562306a36Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_LO_SHIFT		16
18662306a36Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_LO_MASK		0xFFF
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci/* DMA Engine Control Register */
18962306a36Sopenharmony_ci#define REG_DMA_CTRL				0x15C0
19062306a36Sopenharmony_ci#define DMA_CTRL_DMAR_IN_ORDER			0x1
19162306a36Sopenharmony_ci#define DMA_CTRL_DMAR_ENH_ORDER			0x2
19262306a36Sopenharmony_ci#define DMA_CTRL_DMAR_OUT_ORDER			0x4
19362306a36Sopenharmony_ci#define DMA_CTRL_RCB_VALUE			0x8
19462306a36Sopenharmony_ci#define DMA_CTRL_DMAR_BURST_LEN_SHIFT		4
19562306a36Sopenharmony_ci#define DMA_CTRL_DMAR_BURST_LEN_MASK		7
19662306a36Sopenharmony_ci#define DMA_CTRL_DMAW_BURST_LEN_SHIFT		7
19762306a36Sopenharmony_ci#define DMA_CTRL_DMAW_BURST_LEN_MASK		7
19862306a36Sopenharmony_ci#define DMA_CTRL_DMAR_EN			0x400
19962306a36Sopenharmony_ci#define DMA_CTRL_DMAW_EN			0x800
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci/* CMB/SMB Control Register */
20262306a36Sopenharmony_ci#define REG_CSMB_CTRL				0x15D0
20362306a36Sopenharmony_ci#define CSMB_CTRL_CMB_NOW			1
20462306a36Sopenharmony_ci#define CSMB_CTRL_SMB_NOW			2
20562306a36Sopenharmony_ci#define CSMB_CTRL_CMB_EN			4
20662306a36Sopenharmony_ci#define CSMB_CTRL_SMB_EN			8
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci/* CMB DMA Write Threshold Register */
20962306a36Sopenharmony_ci#define REG_CMB_WRITE_TH			0x15D4
21062306a36Sopenharmony_ci#define CMB_RRD_TH_SHIFT			0
21162306a36Sopenharmony_ci#define CMB_RRD_TH_MASK				0x7FF
21262306a36Sopenharmony_ci#define CMB_TPD_TH_SHIFT			16
21362306a36Sopenharmony_ci#define CMB_TPD_TH_MASK				0x7FF
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci/* RX/TX count-down timer to trigger CMB-write. 2us resolution. */
21662306a36Sopenharmony_ci#define REG_CMB_WRITE_TIMER			0x15D8
21762306a36Sopenharmony_ci#define CMB_RX_TM_SHIFT				0
21862306a36Sopenharmony_ci#define CMB_RX_TM_MASK				0xFFFF
21962306a36Sopenharmony_ci#define CMB_TX_TM_SHIFT				16
22062306a36Sopenharmony_ci#define CMB_TX_TM_MASK				0xFFFF
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci/* Number of packet received since last CMB write */
22362306a36Sopenharmony_ci#define REG_CMB_RX_PKT_CNT			0x15DC
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci/* Number of packet transmitted since last CMB write */
22662306a36Sopenharmony_ci#define REG_CMB_TX_PKT_CNT			0x15E0
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci/* SMB auto DMA timer register */
22962306a36Sopenharmony_ci#define REG_SMB_TIMER				0x15E4
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci/* Mailbox Register */
23262306a36Sopenharmony_ci#define REG_MAILBOX				0x15F0
23362306a36Sopenharmony_ci#define MB_RFD_PROD_INDX_SHIFT			0
23462306a36Sopenharmony_ci#define MB_RFD_PROD_INDX_MASK			0x7FF
23562306a36Sopenharmony_ci#define MB_RRD_CONS_INDX_SHIFT			11
23662306a36Sopenharmony_ci#define MB_RRD_CONS_INDX_MASK			0x7FF
23762306a36Sopenharmony_ci#define MB_TPD_PROD_INDX_SHIFT			22
23862306a36Sopenharmony_ci#define MB_TPD_PROD_INDX_MASK			0x3FF
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci/* Interrupt Status Register */
24162306a36Sopenharmony_ci#define ISR_SMB					0x1
24262306a36Sopenharmony_ci#define ISR_TIMER				0x2
24362306a36Sopenharmony_ci#define ISR_MANUAL				0x4
24462306a36Sopenharmony_ci#define ISR_RXF_OV				0x8
24562306a36Sopenharmony_ci#define ISR_RFD_UNRUN				0x10
24662306a36Sopenharmony_ci#define ISR_RRD_OV				0x20
24762306a36Sopenharmony_ci#define ISR_TXF_UNRUN				0x40
24862306a36Sopenharmony_ci#define ISR_LINK				0x80
24962306a36Sopenharmony_ci#define ISR_HOST_RFD_UNRUN			0x100
25062306a36Sopenharmony_ci#define ISR_HOST_RRD_OV				0x200
25162306a36Sopenharmony_ci#define ISR_DMAR_TO_RST				0x400
25262306a36Sopenharmony_ci#define ISR_DMAW_TO_RST				0x800
25362306a36Sopenharmony_ci#define ISR_GPHY				0x1000
25462306a36Sopenharmony_ci#define ISR_RX_PKT				0x10000
25562306a36Sopenharmony_ci#define ISR_TX_PKT				0x20000
25662306a36Sopenharmony_ci#define ISR_TX_DMA				0x40000
25762306a36Sopenharmony_ci#define ISR_RX_DMA				0x80000
25862306a36Sopenharmony_ci#define ISR_CMB_RX				0x100000
25962306a36Sopenharmony_ci#define ISR_CMB_TX				0x200000
26062306a36Sopenharmony_ci#define ISR_MAC_RX				0x400000
26162306a36Sopenharmony_ci#define ISR_MAC_TX				0x800000
26262306a36Sopenharmony_ci#define ISR_DIS_SMB				0x20000000
26362306a36Sopenharmony_ci#define ISR_DIS_DMA				0x40000000
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci/* Normal Interrupt mask without RX/TX enabled */
26662306a36Sopenharmony_ci#define IMR_NORXTX_MASK	(\
26762306a36Sopenharmony_ci	ISR_SMB		|\
26862306a36Sopenharmony_ci	ISR_GPHY	|\
26962306a36Sopenharmony_ci	ISR_PHY_LINKDOWN|\
27062306a36Sopenharmony_ci	ISR_DMAR_TO_RST	|\
27162306a36Sopenharmony_ci	ISR_DMAW_TO_RST)
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci/* Normal Interrupt mask  */
27462306a36Sopenharmony_ci#define IMR_NORMAL_MASK	(\
27562306a36Sopenharmony_ci	IMR_NORXTX_MASK	|\
27662306a36Sopenharmony_ci	ISR_CMB_TX	|\
27762306a36Sopenharmony_ci	ISR_CMB_RX)
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci/* Debug Interrupt Mask  (enable all interrupt) */
28062306a36Sopenharmony_ci#define IMR_DEBUG_MASK	(\
28162306a36Sopenharmony_ci	ISR_SMB		|\
28262306a36Sopenharmony_ci	ISR_TIMER	|\
28362306a36Sopenharmony_ci	ISR_MANUAL	|\
28462306a36Sopenharmony_ci	ISR_RXF_OV	|\
28562306a36Sopenharmony_ci	ISR_RFD_UNRUN	|\
28662306a36Sopenharmony_ci	ISR_RRD_OV	|\
28762306a36Sopenharmony_ci	ISR_TXF_UNRUN	|\
28862306a36Sopenharmony_ci	ISR_LINK	|\
28962306a36Sopenharmony_ci	ISR_CMB_TX	|\
29062306a36Sopenharmony_ci	ISR_CMB_RX	|\
29162306a36Sopenharmony_ci	ISR_RX_PKT	|\
29262306a36Sopenharmony_ci	ISR_TX_PKT	|\
29362306a36Sopenharmony_ci	ISR_MAC_RX	|\
29462306a36Sopenharmony_ci	ISR_MAC_TX)
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci#define MEDIA_TYPE_1000M_FULL			1
29762306a36Sopenharmony_ci#define MEDIA_TYPE_100M_FULL			2
29862306a36Sopenharmony_ci#define MEDIA_TYPE_100M_HALF			3
29962306a36Sopenharmony_ci#define MEDIA_TYPE_10M_FULL			4
30062306a36Sopenharmony_ci#define MEDIA_TYPE_10M_HALF			5
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci#define AUTONEG_ADVERTISE_SPEED_DEFAULT		0x002F	/* All but 1000-Half */
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci#define MAX_JUMBO_FRAME_SIZE			10240
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci#define ATL1_EEDUMP_LEN				48
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci/* Statistics counters collected by the MAC */
30962306a36Sopenharmony_cistruct stats_msg_block {
31062306a36Sopenharmony_ci	/* rx */
31162306a36Sopenharmony_ci	u32 rx_ok;		/* good RX packets */
31262306a36Sopenharmony_ci	u32 rx_bcast;		/* good RX broadcast packets */
31362306a36Sopenharmony_ci	u32 rx_mcast;		/* good RX multicast packets */
31462306a36Sopenharmony_ci	u32 rx_pause;		/* RX pause frames */
31562306a36Sopenharmony_ci	u32 rx_ctrl;		/* RX control packets other than pause frames */
31662306a36Sopenharmony_ci	u32 rx_fcs_err;		/* RX packets with bad FCS */
31762306a36Sopenharmony_ci	u32 rx_len_err;		/* RX packets with length != actual size */
31862306a36Sopenharmony_ci	u32 rx_byte_cnt;	/* good bytes received. FCS is NOT included */
31962306a36Sopenharmony_ci	u32 rx_runt;		/* RX packets < 64 bytes with good FCS */
32062306a36Sopenharmony_ci	u32 rx_frag;		/* RX packets < 64 bytes with bad FCS */
32162306a36Sopenharmony_ci	u32 rx_sz_64;		/* 64 byte RX packets */
32262306a36Sopenharmony_ci	u32 rx_sz_65_127;
32362306a36Sopenharmony_ci	u32 rx_sz_128_255;
32462306a36Sopenharmony_ci	u32 rx_sz_256_511;
32562306a36Sopenharmony_ci	u32 rx_sz_512_1023;
32662306a36Sopenharmony_ci	u32 rx_sz_1024_1518;
32762306a36Sopenharmony_ci	u32 rx_sz_1519_max;	/* 1519 byte to MTU RX packets */
32862306a36Sopenharmony_ci	u32 rx_sz_ov;		/* truncated RX packets > MTU */
32962306a36Sopenharmony_ci	u32 rx_rxf_ov;		/* frames dropped due to RX FIFO overflow */
33062306a36Sopenharmony_ci	u32 rx_rrd_ov;		/* frames dropped due to RRD overflow */
33162306a36Sopenharmony_ci	u32 rx_align_err;	/* alignment errors */
33262306a36Sopenharmony_ci	u32 rx_bcast_byte_cnt;	/* RX broadcast bytes, excluding FCS */
33362306a36Sopenharmony_ci	u32 rx_mcast_byte_cnt;	/* RX multicast bytes, excluding FCS */
33462306a36Sopenharmony_ci	u32 rx_err_addr;	/* packets dropped due to address filtering */
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci	/* tx */
33762306a36Sopenharmony_ci	u32 tx_ok;		/* good TX packets */
33862306a36Sopenharmony_ci	u32 tx_bcast;		/* good TX broadcast packets */
33962306a36Sopenharmony_ci	u32 tx_mcast;		/* good TX multicast packets */
34062306a36Sopenharmony_ci	u32 tx_pause;		/* TX pause frames */
34162306a36Sopenharmony_ci	u32 tx_exc_defer;	/* TX packets deferred excessively */
34262306a36Sopenharmony_ci	u32 tx_ctrl;		/* TX control frames, excluding pause frames */
34362306a36Sopenharmony_ci	u32 tx_defer;		/* TX packets deferred */
34462306a36Sopenharmony_ci	u32 tx_byte_cnt;	/* bytes transmitted, FCS is NOT included */
34562306a36Sopenharmony_ci	u32 tx_sz_64;		/* 64 byte TX packets */
34662306a36Sopenharmony_ci	u32 tx_sz_65_127;
34762306a36Sopenharmony_ci	u32 tx_sz_128_255;
34862306a36Sopenharmony_ci	u32 tx_sz_256_511;
34962306a36Sopenharmony_ci	u32 tx_sz_512_1023;
35062306a36Sopenharmony_ci	u32 tx_sz_1024_1518;
35162306a36Sopenharmony_ci	u32 tx_sz_1519_max;	/* 1519 byte to MTU TX packets */
35262306a36Sopenharmony_ci	u32 tx_1_col;		/* packets TX after a single collision */
35362306a36Sopenharmony_ci	u32 tx_2_col;		/* packets TX after multiple collisions */
35462306a36Sopenharmony_ci	u32 tx_late_col;	/* TX packets with late collisions */
35562306a36Sopenharmony_ci	u32 tx_abort_col;	/* TX packets aborted w/excessive collisions */
35662306a36Sopenharmony_ci	u32 tx_underrun;	/* TX packets aborted due to TX FIFO underrun
35762306a36Sopenharmony_ci				 * or TRD FIFO underrun */
35862306a36Sopenharmony_ci	u32 tx_rd_eop;		/* reads beyond the EOP into the next frame
35962306a36Sopenharmony_ci				 * when TRD was not written timely */
36062306a36Sopenharmony_ci	u32 tx_len_err;		/* TX packets where length != actual size */
36162306a36Sopenharmony_ci	u32 tx_trunc;		/* TX packets truncated due to size > MTU */
36262306a36Sopenharmony_ci	u32 tx_bcast_byte;	/* broadcast bytes transmitted, excluding FCS */
36362306a36Sopenharmony_ci	u32 tx_mcast_byte;	/* multicast bytes transmitted, excluding FCS */
36462306a36Sopenharmony_ci	u32 smb_updated;	/* 1: SMB Updated. This is used by software to
36562306a36Sopenharmony_ci				 * indicate the statistics update. Software
36662306a36Sopenharmony_ci				 * should clear this bit after retrieving the
36762306a36Sopenharmony_ci				 * statistics information. */
36862306a36Sopenharmony_ci};
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci/* Coalescing Message Block */
37162306a36Sopenharmony_cistruct coals_msg_block {
37262306a36Sopenharmony_ci	u32 int_stats;		/* interrupt status */
37362306a36Sopenharmony_ci	u16 rrd_prod_idx;	/* TRD Producer Index. */
37462306a36Sopenharmony_ci	u16 rfd_cons_idx;	/* RFD Consumer Index. */
37562306a36Sopenharmony_ci	u16 update;		/* Selene sets this bit every time it DMAs the
37662306a36Sopenharmony_ci				 * CMB to host memory. Software should clear
37762306a36Sopenharmony_ci				 * this bit when CMB info is processed. */
37862306a36Sopenharmony_ci	u16 tpd_cons_idx;	/* TPD Consumer Index. */
37962306a36Sopenharmony_ci};
38062306a36Sopenharmony_ci
38162306a36Sopenharmony_ci/* RRD descriptor */
38262306a36Sopenharmony_cistruct rx_return_desc {
38362306a36Sopenharmony_ci	u8 num_buf;	/* Number of RFD buffers used by the received packet */
38462306a36Sopenharmony_ci	u8 resved;
38562306a36Sopenharmony_ci	u16 buf_indx;	/* RFD Index of the first buffer */
38662306a36Sopenharmony_ci	union {
38762306a36Sopenharmony_ci		u32 valid;
38862306a36Sopenharmony_ci		struct {
38962306a36Sopenharmony_ci			u16 rx_chksum;
39062306a36Sopenharmony_ci			u16 pkt_size;
39162306a36Sopenharmony_ci		} xsum_sz;
39262306a36Sopenharmony_ci	} xsz;
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci	u16 pkt_flg;	/* Packet flags */
39562306a36Sopenharmony_ci	u16 err_flg;	/* Error flags */
39662306a36Sopenharmony_ci	u16 resved2;
39762306a36Sopenharmony_ci	u16 vlan_tag;	/* VLAN TAG */
39862306a36Sopenharmony_ci};
39962306a36Sopenharmony_ci
40062306a36Sopenharmony_ci#define PACKET_FLAG_ETH_TYPE	0x0080
40162306a36Sopenharmony_ci#define PACKET_FLAG_VLAN_INS	0x0100
40262306a36Sopenharmony_ci#define PACKET_FLAG_ERR		0x0200
40362306a36Sopenharmony_ci#define PACKET_FLAG_IPV4	0x0400
40462306a36Sopenharmony_ci#define PACKET_FLAG_UDP		0x0800
40562306a36Sopenharmony_ci#define PACKET_FLAG_TCP		0x1000
40662306a36Sopenharmony_ci#define PACKET_FLAG_BCAST	0x2000
40762306a36Sopenharmony_ci#define PACKET_FLAG_MCAST	0x4000
40862306a36Sopenharmony_ci#define PACKET_FLAG_PAUSE	0x8000
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci#define ERR_FLAG_CRC		0x0001
41162306a36Sopenharmony_ci#define ERR_FLAG_CODE		0x0002
41262306a36Sopenharmony_ci#define ERR_FLAG_DRIBBLE	0x0004
41362306a36Sopenharmony_ci#define ERR_FLAG_RUNT		0x0008
41462306a36Sopenharmony_ci#define ERR_FLAG_OV		0x0010
41562306a36Sopenharmony_ci#define ERR_FLAG_TRUNC		0x0020
41662306a36Sopenharmony_ci#define ERR_FLAG_IP_CHKSUM	0x0040
41762306a36Sopenharmony_ci#define ERR_FLAG_L4_CHKSUM	0x0080
41862306a36Sopenharmony_ci#define ERR_FLAG_LEN		0x0100
41962306a36Sopenharmony_ci#define ERR_FLAG_DES_ADDR	0x0200
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ci/* RFD descriptor */
42262306a36Sopenharmony_cistruct rx_free_desc {
42362306a36Sopenharmony_ci	__le64 buffer_addr;	/* Address of the descriptor's data buffer */
42462306a36Sopenharmony_ci	__le16 buf_len;		/* Size of the receive buffer in host memory */
42562306a36Sopenharmony_ci	u16 coalese;		/* Update consumer index to host after the
42662306a36Sopenharmony_ci				 * reception of this frame */
42762306a36Sopenharmony_ci	/* __packed is required */
42862306a36Sopenharmony_ci} __packed;
42962306a36Sopenharmony_ci
43062306a36Sopenharmony_ci/*
43162306a36Sopenharmony_ci * The L1 transmit packet descriptor is comprised of four 32-bit words.
43262306a36Sopenharmony_ci *
43362306a36Sopenharmony_ci *	31					0
43462306a36Sopenharmony_ci *	+---------------------------------------+
43562306a36Sopenharmony_ci *      |	Word 0: Buffer addr lo 		|
43662306a36Sopenharmony_ci *      +---------------------------------------+
43762306a36Sopenharmony_ci *      |	Word 1: Buffer addr hi		|
43862306a36Sopenharmony_ci *      +---------------------------------------+
43962306a36Sopenharmony_ci *      |		Word 2			|
44062306a36Sopenharmony_ci *      +---------------------------------------+
44162306a36Sopenharmony_ci *      |		Word 3			|
44262306a36Sopenharmony_ci *      +---------------------------------------+
44362306a36Sopenharmony_ci *
44462306a36Sopenharmony_ci * Words 0 and 1 combine to form a 64-bit buffer address.
44562306a36Sopenharmony_ci *
44662306a36Sopenharmony_ci * Word 2 is self explanatory in the #define block below.
44762306a36Sopenharmony_ci *
44862306a36Sopenharmony_ci * Word 3 has two forms, depending upon the state of bits 3 and 4.
44962306a36Sopenharmony_ci * If bits 3 and 4 are both zero, then bits 14:31 are unused by the
45062306a36Sopenharmony_ci * hardware.  Otherwise, if either bit 3 or 4 is set, the definition
45162306a36Sopenharmony_ci * of bits 14:31 vary according to the following depiction.
45262306a36Sopenharmony_ci *
45362306a36Sopenharmony_ci *	0	End of packet			0	End of packet
45462306a36Sopenharmony_ci *	1	Coalesce			1	Coalesce
45562306a36Sopenharmony_ci *	2	Insert VLAN tag			2	Insert VLAN tag
45662306a36Sopenharmony_ci *	3	Custom csum enable = 0		3	Custom csum enable = 1
45762306a36Sopenharmony_ci *	4	Segment enable = 1		4	Segment enable = 0
45862306a36Sopenharmony_ci *	5	Generate IP checksum		5	Generate IP checksum
45962306a36Sopenharmony_ci *	6	Generate TCP checksum		6	Generate TCP checksum
46062306a36Sopenharmony_ci *	7	Generate UDP checksum		7	Generate UDP checksum
46162306a36Sopenharmony_ci *	8	VLAN tagged			8	VLAN tagged
46262306a36Sopenharmony_ci *	9	Ethernet frame type		9	Ethernet frame type
46362306a36Sopenharmony_ci *	10-+ 					10-+
46462306a36Sopenharmony_ci *	11 |	IP hdr length (10:13)		11 |	IP hdr length (10:13)
46562306a36Sopenharmony_ci *	12 |	(num 32-bit words)		12 |	(num 32-bit words)
46662306a36Sopenharmony_ci *	13-+					13-+
46762306a36Sopenharmony_ci *	14-+					14	Unused
46862306a36Sopenharmony_ci *	15 |	TCP hdr length (14:17)		15	Unused
46962306a36Sopenharmony_ci *	16 |	(num 32-bit words)		16-+
47062306a36Sopenharmony_ci *	17-+					17 |
47162306a36Sopenharmony_ci *	18	Header TPD flag			18 |
47262306a36Sopenharmony_ci *	19-+					19 |	Payload offset
47362306a36Sopenharmony_ci *	20 |					20 |	    (16:23)
47462306a36Sopenharmony_ci *	21 |					21 |
47562306a36Sopenharmony_ci *	22 |					22 |
47662306a36Sopenharmony_ci *	23 |					23-+
47762306a36Sopenharmony_ci *	24 |					24-+
47862306a36Sopenharmony_ci *	25 |	MSS (19:31)			25 |
47962306a36Sopenharmony_ci *	26 |					26 |
48062306a36Sopenharmony_ci *	27 |					27 |	Custom csum offset
48162306a36Sopenharmony_ci *	28 |					28 |	     (24:31)
48262306a36Sopenharmony_ci *	29 |					29 |
48362306a36Sopenharmony_ci *	30 |					30 |
48462306a36Sopenharmony_ci *	31-+					31-+
48562306a36Sopenharmony_ci */
48662306a36Sopenharmony_ci
48762306a36Sopenharmony_ci/* tpd word 2 */
48862306a36Sopenharmony_ci#define TPD_BUFLEN_MASK		0x3FFF
48962306a36Sopenharmony_ci#define TPD_BUFLEN_SHIFT	0
49062306a36Sopenharmony_ci#define TPD_DMAINT_MASK		0x0001
49162306a36Sopenharmony_ci#define TPD_DMAINT_SHIFT	14
49262306a36Sopenharmony_ci#define TPD_PKTNT_MASK		0x0001
49362306a36Sopenharmony_ci#define TPD_PKTINT_SHIFT	15
49462306a36Sopenharmony_ci#define TPD_VLANTAG_MASK	0xFFFF
49562306a36Sopenharmony_ci#define TPD_VLANTAG_SHIFT	16
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci/* tpd word 3 bits 0:13 */
49862306a36Sopenharmony_ci#define TPD_EOP_MASK		0x0001
49962306a36Sopenharmony_ci#define TPD_EOP_SHIFT		0
50062306a36Sopenharmony_ci#define TPD_COALESCE_MASK	0x0001
50162306a36Sopenharmony_ci#define TPD_COALESCE_SHIFT	1
50262306a36Sopenharmony_ci#define TPD_INS_VL_TAG_MASK	0x0001
50362306a36Sopenharmony_ci#define TPD_INS_VL_TAG_SHIFT	2
50462306a36Sopenharmony_ci#define TPD_CUST_CSUM_EN_MASK	0x0001
50562306a36Sopenharmony_ci#define TPD_CUST_CSUM_EN_SHIFT	3
50662306a36Sopenharmony_ci#define TPD_SEGMENT_EN_MASK	0x0001
50762306a36Sopenharmony_ci#define TPD_SEGMENT_EN_SHIFT	4
50862306a36Sopenharmony_ci#define TPD_IP_CSUM_MASK	0x0001
50962306a36Sopenharmony_ci#define TPD_IP_CSUM_SHIFT	5
51062306a36Sopenharmony_ci#define TPD_TCP_CSUM_MASK	0x0001
51162306a36Sopenharmony_ci#define TPD_TCP_CSUM_SHIFT	6
51262306a36Sopenharmony_ci#define TPD_UDP_CSUM_MASK	0x0001
51362306a36Sopenharmony_ci#define TPD_UDP_CSUM_SHIFT	7
51462306a36Sopenharmony_ci#define TPD_VL_TAGGED_MASK	0x0001
51562306a36Sopenharmony_ci#define TPD_VL_TAGGED_SHIFT	8
51662306a36Sopenharmony_ci#define TPD_ETHTYPE_MASK	0x0001
51762306a36Sopenharmony_ci#define TPD_ETHTYPE_SHIFT	9
51862306a36Sopenharmony_ci#define TPD_IPHL_MASK		0x000F
51962306a36Sopenharmony_ci#define TPD_IPHL_SHIFT		10
52062306a36Sopenharmony_ci
52162306a36Sopenharmony_ci/* tpd word 3 bits 14:31 if segment enabled */
52262306a36Sopenharmony_ci#define TPD_TCPHDRLEN_MASK	0x000F
52362306a36Sopenharmony_ci#define TPD_TCPHDRLEN_SHIFT	14
52462306a36Sopenharmony_ci#define TPD_HDRFLAG_MASK	0x0001
52562306a36Sopenharmony_ci#define TPD_HDRFLAG_SHIFT	18
52662306a36Sopenharmony_ci#define TPD_MSS_MASK		0x1FFF
52762306a36Sopenharmony_ci#define TPD_MSS_SHIFT		19
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ci/* tpd word 3 bits 16:31 if custom csum enabled */
53062306a36Sopenharmony_ci#define TPD_PLOADOFFSET_MASK	0x00FF
53162306a36Sopenharmony_ci#define TPD_PLOADOFFSET_SHIFT	16
53262306a36Sopenharmony_ci#define TPD_CCSUMOFFSET_MASK	0x00FF
53362306a36Sopenharmony_ci#define TPD_CCSUMOFFSET_SHIFT	24
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_cistruct tx_packet_desc {
53662306a36Sopenharmony_ci	__le64 buffer_addr;
53762306a36Sopenharmony_ci	__le32 word2;
53862306a36Sopenharmony_ci	__le32 word3;
53962306a36Sopenharmony_ci};
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci/* DMA Order Settings */
54262306a36Sopenharmony_cienum atl1_dma_order {
54362306a36Sopenharmony_ci	atl1_dma_ord_in = 1,
54462306a36Sopenharmony_ci	atl1_dma_ord_enh = 2,
54562306a36Sopenharmony_ci	atl1_dma_ord_out = 4
54662306a36Sopenharmony_ci};
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_cienum atl1_dma_rcb {
54962306a36Sopenharmony_ci	atl1_rcb_64 = 0,
55062306a36Sopenharmony_ci	atl1_rcb_128 = 1
55162306a36Sopenharmony_ci};
55262306a36Sopenharmony_ci
55362306a36Sopenharmony_cienum atl1_dma_req_block {
55462306a36Sopenharmony_ci	atl1_dma_req_128 = 0,
55562306a36Sopenharmony_ci	atl1_dma_req_256 = 1,
55662306a36Sopenharmony_ci	atl1_dma_req_512 = 2,
55762306a36Sopenharmony_ci	atl1_dma_req_1024 = 3,
55862306a36Sopenharmony_ci	atl1_dma_req_2048 = 4,
55962306a36Sopenharmony_ci	atl1_dma_req_4096 = 5
56062306a36Sopenharmony_ci};
56162306a36Sopenharmony_ci
56262306a36Sopenharmony_ci#define ATL1_MAX_INTR		3
56362306a36Sopenharmony_ci#define ATL1_MAX_TX_BUF_LEN	0x3000	/* 12288 bytes */
56462306a36Sopenharmony_ci
56562306a36Sopenharmony_ci#define ATL1_DEFAULT_TPD	256
56662306a36Sopenharmony_ci#define ATL1_MAX_TPD		1024
56762306a36Sopenharmony_ci#define ATL1_MIN_TPD		64
56862306a36Sopenharmony_ci#define ATL1_DEFAULT_RFD	512
56962306a36Sopenharmony_ci#define ATL1_MIN_RFD		128
57062306a36Sopenharmony_ci#define ATL1_MAX_RFD		2048
57162306a36Sopenharmony_ci#define ATL1_REG_COUNT		1538
57262306a36Sopenharmony_ci
57362306a36Sopenharmony_ci#define ATL1_GET_DESC(R, i, type)	(&(((type *)((R)->desc))[i]))
57462306a36Sopenharmony_ci#define ATL1_RFD_DESC(R, i)	ATL1_GET_DESC(R, i, struct rx_free_desc)
57562306a36Sopenharmony_ci#define ATL1_TPD_DESC(R, i)	ATL1_GET_DESC(R, i, struct tx_packet_desc)
57662306a36Sopenharmony_ci#define ATL1_RRD_DESC(R, i)	ATL1_GET_DESC(R, i, struct rx_return_desc)
57762306a36Sopenharmony_ci
57862306a36Sopenharmony_ci/*
57962306a36Sopenharmony_ci * atl1_ring_header represents a single, contiguous block of DMA space
58062306a36Sopenharmony_ci * mapped for the three descriptor rings (tpd, rfd, rrd) and the two
58162306a36Sopenharmony_ci * message blocks (cmb, smb) described below
58262306a36Sopenharmony_ci */
58362306a36Sopenharmony_cistruct atl1_ring_header {
58462306a36Sopenharmony_ci	void *desc;		/* virtual address */
58562306a36Sopenharmony_ci	dma_addr_t dma;		/* physical address*/
58662306a36Sopenharmony_ci	unsigned int size;	/* length in bytes */
58762306a36Sopenharmony_ci};
58862306a36Sopenharmony_ci
58962306a36Sopenharmony_ci/*
59062306a36Sopenharmony_ci * atl1_buffer is wrapper around a pointer to a socket buffer
59162306a36Sopenharmony_ci * so a DMA handle can be stored along with the skb
59262306a36Sopenharmony_ci */
59362306a36Sopenharmony_cistruct atl1_buffer {
59462306a36Sopenharmony_ci	struct sk_buff *skb;	/* socket buffer */
59562306a36Sopenharmony_ci	u16 length;		/* rx buffer length */
59662306a36Sopenharmony_ci	u16 alloced;		/* 1 if skb allocated */
59762306a36Sopenharmony_ci	dma_addr_t dma;
59862306a36Sopenharmony_ci};
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_ci/* transmit packet descriptor (tpd) ring */
60162306a36Sopenharmony_cistruct atl1_tpd_ring {
60262306a36Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
60362306a36Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
60462306a36Sopenharmony_ci	u16 size;		/* descriptor ring length in bytes */
60562306a36Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
60662306a36Sopenharmony_ci	u16 hw_idx;		/* hardware index */
60762306a36Sopenharmony_ci	atomic_t next_to_clean;
60862306a36Sopenharmony_ci	atomic_t next_to_use;
60962306a36Sopenharmony_ci	struct atl1_buffer *buffer_info;
61062306a36Sopenharmony_ci};
61162306a36Sopenharmony_ci
61262306a36Sopenharmony_ci/* receive free descriptor (rfd) ring */
61362306a36Sopenharmony_cistruct atl1_rfd_ring {
61462306a36Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
61562306a36Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
61662306a36Sopenharmony_ci	u16 size;		/* descriptor ring length in bytes */
61762306a36Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
61862306a36Sopenharmony_ci	atomic_t next_to_use;
61962306a36Sopenharmony_ci	u16 next_to_clean;
62062306a36Sopenharmony_ci	struct atl1_buffer *buffer_info;
62162306a36Sopenharmony_ci};
62262306a36Sopenharmony_ci
62362306a36Sopenharmony_ci/* receive return descriptor (rrd) ring */
62462306a36Sopenharmony_cistruct atl1_rrd_ring {
62562306a36Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
62662306a36Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
62762306a36Sopenharmony_ci	unsigned int size;	/* descriptor ring length in bytes */
62862306a36Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
62962306a36Sopenharmony_ci	u16 next_to_use;
63062306a36Sopenharmony_ci	atomic_t next_to_clean;
63162306a36Sopenharmony_ci};
63262306a36Sopenharmony_ci
63362306a36Sopenharmony_ci/* coalescing message block (cmb) */
63462306a36Sopenharmony_cistruct atl1_cmb {
63562306a36Sopenharmony_ci	struct coals_msg_block *cmb;
63662306a36Sopenharmony_ci	dma_addr_t dma;
63762306a36Sopenharmony_ci};
63862306a36Sopenharmony_ci
63962306a36Sopenharmony_ci/* statistics message block (smb) */
64062306a36Sopenharmony_cistruct atl1_smb {
64162306a36Sopenharmony_ci	struct stats_msg_block *smb;
64262306a36Sopenharmony_ci	dma_addr_t dma;
64362306a36Sopenharmony_ci};
64462306a36Sopenharmony_ci
64562306a36Sopenharmony_ci/* Statistics counters */
64662306a36Sopenharmony_cistruct atl1_sft_stats {
64762306a36Sopenharmony_ci	u64 rx_packets;
64862306a36Sopenharmony_ci	u64 tx_packets;
64962306a36Sopenharmony_ci	u64 rx_bytes;
65062306a36Sopenharmony_ci	u64 tx_bytes;
65162306a36Sopenharmony_ci	u64 multicast;
65262306a36Sopenharmony_ci	u64 collisions;
65362306a36Sopenharmony_ci	u64 rx_errors;
65462306a36Sopenharmony_ci	u64 rx_length_errors;
65562306a36Sopenharmony_ci	u64 rx_crc_errors;
65662306a36Sopenharmony_ci	u64 rx_dropped;
65762306a36Sopenharmony_ci	u64 rx_frame_errors;
65862306a36Sopenharmony_ci	u64 rx_fifo_errors;
65962306a36Sopenharmony_ci	u64 rx_missed_errors;
66062306a36Sopenharmony_ci	u64 tx_errors;
66162306a36Sopenharmony_ci	u64 tx_fifo_errors;
66262306a36Sopenharmony_ci	u64 tx_aborted_errors;
66362306a36Sopenharmony_ci	u64 tx_window_errors;
66462306a36Sopenharmony_ci	u64 tx_carrier_errors;
66562306a36Sopenharmony_ci	u64 tx_pause;		/* TX pause frames */
66662306a36Sopenharmony_ci	u64 excecol;		/* TX packets w/ excessive collisions */
66762306a36Sopenharmony_ci	u64 deffer;		/* TX packets deferred */
66862306a36Sopenharmony_ci	u64 scc;		/* packets TX after a single collision */
66962306a36Sopenharmony_ci	u64 mcc;		/* packets TX after multiple collisions */
67062306a36Sopenharmony_ci	u64 latecol;		/* TX packets w/ late collisions */
67162306a36Sopenharmony_ci	u64 tx_underrun;	/* TX packets aborted due to TX FIFO underrun
67262306a36Sopenharmony_ci				 * or TRD FIFO underrun */
67362306a36Sopenharmony_ci	u64 tx_trunc;		/* TX packets truncated due to size > MTU */
67462306a36Sopenharmony_ci	u64 rx_pause;		/* num Pause packets received. */
67562306a36Sopenharmony_ci	u64 rx_rrd_ov;
67662306a36Sopenharmony_ci	u64 rx_trunc;
67762306a36Sopenharmony_ci};
67862306a36Sopenharmony_ci
67962306a36Sopenharmony_ci/* hardware structure */
68062306a36Sopenharmony_cistruct atl1_hw {
68162306a36Sopenharmony_ci	u8 __iomem *hw_addr;
68262306a36Sopenharmony_ci	struct atl1_adapter *back;
68362306a36Sopenharmony_ci	enum atl1_dma_order dma_ord;
68462306a36Sopenharmony_ci	enum atl1_dma_rcb rcb_value;
68562306a36Sopenharmony_ci	enum atl1_dma_req_block dmar_block;
68662306a36Sopenharmony_ci	enum atl1_dma_req_block dmaw_block;
68762306a36Sopenharmony_ci	u8 preamble_len;
68862306a36Sopenharmony_ci	u8 max_retry;
68962306a36Sopenharmony_ci	u8 jam_ipg;		/* IPG to start JAM for collision based flow
69062306a36Sopenharmony_ci				 * control in half-duplex mode. In units of
69162306a36Sopenharmony_ci				 * 8-bit time */
69262306a36Sopenharmony_ci	u8 ipgt;		/* Desired back to back inter-packet gap.
69362306a36Sopenharmony_ci				 * The default is 96-bit time */
69462306a36Sopenharmony_ci	u8 min_ifg;		/* Minimum number of IFG to enforce in between
69562306a36Sopenharmony_ci				 * receive frames. Frame gap below such IFP
69662306a36Sopenharmony_ci				 * is dropped */
69762306a36Sopenharmony_ci	u8 ipgr1;		/* 64bit Carrier-Sense window */
69862306a36Sopenharmony_ci	u8 ipgr2;		/* 96-bit IPG window */
69962306a36Sopenharmony_ci	u8 tpd_burst;		/* Number of TPD to prefetch in cache-aligned
70062306a36Sopenharmony_ci				 * burst. Each TPD is 16 bytes long */
70162306a36Sopenharmony_ci	u8 rfd_burst;		/* Number of RFD to prefetch in cache-aligned
70262306a36Sopenharmony_ci				 * burst. Each RFD is 12 bytes long */
70362306a36Sopenharmony_ci	u8 rfd_fetch_gap;
70462306a36Sopenharmony_ci	u8 rrd_burst;		/* Threshold number of RRDs that can be retired
70562306a36Sopenharmony_ci				 * in a burst. Each RRD is 16 bytes long */
70662306a36Sopenharmony_ci	u8 tpd_fetch_th;
70762306a36Sopenharmony_ci	u8 tpd_fetch_gap;
70862306a36Sopenharmony_ci	u16 tx_jumbo_task_th;
70962306a36Sopenharmony_ci	u16 txf_burst;		/* Number of data bytes to read in a cache-
71062306a36Sopenharmony_ci				 * aligned burst. Each SRAM entry is 8 bytes */
71162306a36Sopenharmony_ci	u16 rx_jumbo_th;	/* Jumbo packet size for non-VLAN packet. VLAN
71262306a36Sopenharmony_ci				 * packets should add 4 bytes */
71362306a36Sopenharmony_ci	u16 rx_jumbo_lkah;
71462306a36Sopenharmony_ci	u16 rrd_ret_timer;	/* RRD retirement timer. Decrement by 1 after
71562306a36Sopenharmony_ci				 * every 512ns passes. */
71662306a36Sopenharmony_ci	u16 lcol;		/* Collision Window */
71762306a36Sopenharmony_ci
71862306a36Sopenharmony_ci	u16 cmb_tpd;
71962306a36Sopenharmony_ci	u16 cmb_rrd;
72062306a36Sopenharmony_ci	u16 cmb_rx_timer;
72162306a36Sopenharmony_ci	u16 cmb_tx_timer;
72262306a36Sopenharmony_ci	u32 smb_timer;
72362306a36Sopenharmony_ci	u16 media_type;
72462306a36Sopenharmony_ci	u16 autoneg_advertised;
72562306a36Sopenharmony_ci
72662306a36Sopenharmony_ci	u16 mii_autoneg_adv_reg;
72762306a36Sopenharmony_ci	u16 mii_1000t_ctrl_reg;
72862306a36Sopenharmony_ci
72962306a36Sopenharmony_ci	u32 max_frame_size;
73062306a36Sopenharmony_ci	u32 min_frame_size;
73162306a36Sopenharmony_ci
73262306a36Sopenharmony_ci	u16 dev_rev;
73362306a36Sopenharmony_ci
73462306a36Sopenharmony_ci	/* spi flash */
73562306a36Sopenharmony_ci	u8 flash_vendor;
73662306a36Sopenharmony_ci
73762306a36Sopenharmony_ci	u8 mac_addr[ETH_ALEN];
73862306a36Sopenharmony_ci	u8 perm_mac_addr[ETH_ALEN];
73962306a36Sopenharmony_ci
74062306a36Sopenharmony_ci	bool phy_configured;
74162306a36Sopenharmony_ci};
74262306a36Sopenharmony_ci
74362306a36Sopenharmony_cistruct atl1_adapter {
74462306a36Sopenharmony_ci	struct net_device *netdev;
74562306a36Sopenharmony_ci	struct pci_dev *pdev;
74662306a36Sopenharmony_ci
74762306a36Sopenharmony_ci	struct atl1_sft_stats soft_stats;
74862306a36Sopenharmony_ci	u32 rx_buffer_len;
74962306a36Sopenharmony_ci	u32 wol;
75062306a36Sopenharmony_ci	u16 link_speed;
75162306a36Sopenharmony_ci	u16 link_duplex;
75262306a36Sopenharmony_ci	spinlock_t lock;
75362306a36Sopenharmony_ci	struct napi_struct napi;
75462306a36Sopenharmony_ci	struct work_struct reset_dev_task;
75562306a36Sopenharmony_ci	struct work_struct link_chg_task;
75662306a36Sopenharmony_ci
75762306a36Sopenharmony_ci	struct timer_list phy_config_timer;
75862306a36Sopenharmony_ci	bool phy_timer_pending;
75962306a36Sopenharmony_ci
76062306a36Sopenharmony_ci	/* all descriptor rings' memory */
76162306a36Sopenharmony_ci	struct atl1_ring_header ring_header;
76262306a36Sopenharmony_ci
76362306a36Sopenharmony_ci	/* TX */
76462306a36Sopenharmony_ci	struct atl1_tpd_ring tpd_ring;
76562306a36Sopenharmony_ci	spinlock_t mb_lock;
76662306a36Sopenharmony_ci
76762306a36Sopenharmony_ci	/* RX */
76862306a36Sopenharmony_ci	struct atl1_rfd_ring rfd_ring;
76962306a36Sopenharmony_ci	struct atl1_rrd_ring rrd_ring;
77062306a36Sopenharmony_ci	u64 hw_csum_err;
77162306a36Sopenharmony_ci	u64 hw_csum_good;
77262306a36Sopenharmony_ci	u32 msg_enable;
77362306a36Sopenharmony_ci	u16 imt;		/* interrupt moderator timer (2us resolution) */
77462306a36Sopenharmony_ci	u16 ict;		/* interrupt clear timer (2us resolution */
77562306a36Sopenharmony_ci	struct mii_if_info mii;	/* MII interface info */
77662306a36Sopenharmony_ci
77762306a36Sopenharmony_ci	/*
77862306a36Sopenharmony_ci	 * Use this value to check is napi handler allowed to
77962306a36Sopenharmony_ci	 * enable ints or not
78062306a36Sopenharmony_ci	 */
78162306a36Sopenharmony_ci	bool int_enabled;
78262306a36Sopenharmony_ci
78362306a36Sopenharmony_ci	u32 bd_number;		/* board number */
78462306a36Sopenharmony_ci	bool pci_using_64;
78562306a36Sopenharmony_ci	struct atl1_hw hw;
78662306a36Sopenharmony_ci	struct atl1_smb smb;
78762306a36Sopenharmony_ci	struct atl1_cmb cmb;
78862306a36Sopenharmony_ci};
78962306a36Sopenharmony_ci
79062306a36Sopenharmony_ci#endif /* ATL1_H */
791