18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright(c) 2006 - 2007 Chris Snook <csnook@redhat.com>
58c2ecf20Sopenharmony_ci * Copyright(c) 2006 - 2008 Jay Cliburn <jcliburn@gmail.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Derived from Intel e1000 driver
88c2ecf20Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef ATL1_H
128c2ecf20Sopenharmony_ci#define ATL1_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/compiler.h>
158c2ecf20Sopenharmony_ci#include <linux/ethtool.h>
168c2ecf20Sopenharmony_ci#include <linux/if_vlan.h>
178c2ecf20Sopenharmony_ci#include <linux/mii.h>
188c2ecf20Sopenharmony_ci#include <linux/module.h>
198c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
208c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
218c2ecf20Sopenharmony_ci#include <linux/timer.h>
228c2ecf20Sopenharmony_ci#include <linux/types.h>
238c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include "atlx.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define ATLX_DRIVER_NAME "atl1"
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Atheros L1 Gigabit Ethernet Driver");
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define atlx_adapter		atl1_adapter
328c2ecf20Sopenharmony_ci#define atlx_check_for_link	atl1_check_for_link
338c2ecf20Sopenharmony_ci#define atlx_check_link		atl1_check_link
348c2ecf20Sopenharmony_ci#define atlx_hash_mc_addr	atl1_hash_mc_addr
358c2ecf20Sopenharmony_ci#define atlx_hash_set		atl1_hash_set
368c2ecf20Sopenharmony_ci#define atlx_hw			atl1_hw
378c2ecf20Sopenharmony_ci#define atlx_mii_ioctl		atl1_mii_ioctl
388c2ecf20Sopenharmony_ci#define atlx_read_phy_reg	atl1_read_phy_reg
398c2ecf20Sopenharmony_ci#define atlx_set_mac		atl1_set_mac
408c2ecf20Sopenharmony_ci#define atlx_set_mac_addr	atl1_set_mac_addr
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct atl1_adapter;
438c2ecf20Sopenharmony_cistruct atl1_hw;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* function prototypes needed by multiple files */
468c2ecf20Sopenharmony_cistatic u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
478c2ecf20Sopenharmony_cistatic void atl1_hash_set(struct atl1_hw *hw, u32 hash_value);
488c2ecf20Sopenharmony_cistatic void atl1_set_mac_addr(struct atl1_hw *hw);
498c2ecf20Sopenharmony_cistatic int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
508c2ecf20Sopenharmony_ci	int cmd);
518c2ecf20Sopenharmony_cistatic u32 atl1_check_link(struct atl1_adapter *adapter);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* hardware definitions specific to L1 */
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* Block IDLE Status Register */
568c2ecf20Sopenharmony_ci#define IDLE_STATUS_RXMAC			0x1
578c2ecf20Sopenharmony_ci#define IDLE_STATUS_TXMAC			0x2
588c2ecf20Sopenharmony_ci#define IDLE_STATUS_RXQ				0x4
598c2ecf20Sopenharmony_ci#define IDLE_STATUS_TXQ				0x8
608c2ecf20Sopenharmony_ci#define IDLE_STATUS_DMAR			0x10
618c2ecf20Sopenharmony_ci#define IDLE_STATUS_DMAW			0x20
628c2ecf20Sopenharmony_ci#define IDLE_STATUS_SMB				0x40
638c2ecf20Sopenharmony_ci#define IDLE_STATUS_CMB				0x80
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* MDIO Control Register */
668c2ecf20Sopenharmony_ci#define MDIO_WAIT_TIMES				30
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* MAC Control Register */
698c2ecf20Sopenharmony_ci#define MAC_CTRL_TX_PAUSE			0x10000
708c2ecf20Sopenharmony_ci#define MAC_CTRL_SCNT				0x20000
718c2ecf20Sopenharmony_ci#define MAC_CTRL_SRST_TX			0x40000
728c2ecf20Sopenharmony_ci#define MAC_CTRL_TX_SIMURST			0x80000
738c2ecf20Sopenharmony_ci#define MAC_CTRL_SPEED_SHIFT			20
748c2ecf20Sopenharmony_ci#define MAC_CTRL_SPEED_MASK			0x300000
758c2ecf20Sopenharmony_ci#define MAC_CTRL_SPEED_1000			0x2
768c2ecf20Sopenharmony_ci#define MAC_CTRL_SPEED_10_100			0x1
778c2ecf20Sopenharmony_ci#define MAC_CTRL_DBG_TX_BKPRESURE		0x400000
788c2ecf20Sopenharmony_ci#define MAC_CTRL_TX_HUGE			0x800000
798c2ecf20Sopenharmony_ci#define MAC_CTRL_RX_CHKSUM_EN			0x1000000
808c2ecf20Sopenharmony_ci#define MAC_CTRL_DBG				0x8000000
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/* Wake-On-Lan control register */
838c2ecf20Sopenharmony_ci#define WOL_CLK_SWITCH_EN			0x8000
848c2ecf20Sopenharmony_ci#define WOL_PT5_EN				0x200000
858c2ecf20Sopenharmony_ci#define WOL_PT6_EN				0x400000
868c2ecf20Sopenharmony_ci#define WOL_PT5_MATCH				0x8000000
878c2ecf20Sopenharmony_ci#define WOL_PT6_MATCH				0x10000000
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* WOL Length ( 2 DWORD ) */
908c2ecf20Sopenharmony_ci#define REG_WOL_PATTERN_LEN			0x14A4
918c2ecf20Sopenharmony_ci#define WOL_PT_LEN_MASK				0x7F
928c2ecf20Sopenharmony_ci#define WOL_PT0_LEN_SHIFT			0
938c2ecf20Sopenharmony_ci#define WOL_PT1_LEN_SHIFT			8
948c2ecf20Sopenharmony_ci#define WOL_PT2_LEN_SHIFT			16
958c2ecf20Sopenharmony_ci#define WOL_PT3_LEN_SHIFT			24
968c2ecf20Sopenharmony_ci#define WOL_PT4_LEN_SHIFT			0
978c2ecf20Sopenharmony_ci#define WOL_PT5_LEN_SHIFT			8
988c2ecf20Sopenharmony_ci#define WOL_PT6_LEN_SHIFT			16
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Internal SRAM Partition Registers, low 32 bits */
1018c2ecf20Sopenharmony_ci#define REG_SRAM_RFD_LEN			0x1504
1028c2ecf20Sopenharmony_ci#define REG_SRAM_RRD_ADDR			0x1508
1038c2ecf20Sopenharmony_ci#define REG_SRAM_RRD_LEN			0x150C
1048c2ecf20Sopenharmony_ci#define REG_SRAM_TPD_ADDR			0x1510
1058c2ecf20Sopenharmony_ci#define REG_SRAM_TPD_LEN			0x1514
1068c2ecf20Sopenharmony_ci#define REG_SRAM_TRD_ADDR			0x1518
1078c2ecf20Sopenharmony_ci#define REG_SRAM_TRD_LEN			0x151C
1088c2ecf20Sopenharmony_ci#define REG_SRAM_RXF_ADDR			0x1520
1098c2ecf20Sopenharmony_ci#define REG_SRAM_RXF_LEN			0x1524
1108c2ecf20Sopenharmony_ci#define REG_SRAM_TXF_ADDR			0x1528
1118c2ecf20Sopenharmony_ci#define REG_SRAM_TXF_LEN			0x152C
1128c2ecf20Sopenharmony_ci#define REG_SRAM_TCPH_PATH_ADDR			0x1530
1138c2ecf20Sopenharmony_ci#define SRAM_TCPH_ADDR_MASK			0xFFF
1148c2ecf20Sopenharmony_ci#define SRAM_TCPH_ADDR_SHIFT			0
1158c2ecf20Sopenharmony_ci#define SRAM_PATH_ADDR_MASK			0xFFF
1168c2ecf20Sopenharmony_ci#define SRAM_PATH_ADDR_SHIFT			16
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* Load Ptr Register */
1198c2ecf20Sopenharmony_ci#define REG_LOAD_PTR				0x1534
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* Descriptor Control registers, low 32 bits */
1228c2ecf20Sopenharmony_ci#define REG_DESC_RFD_ADDR_LO			0x1544
1238c2ecf20Sopenharmony_ci#define REG_DESC_RRD_ADDR_LO			0x1548
1248c2ecf20Sopenharmony_ci#define REG_DESC_TPD_ADDR_LO			0x154C
1258c2ecf20Sopenharmony_ci#define REG_DESC_CMB_ADDR_LO			0x1550
1268c2ecf20Sopenharmony_ci#define REG_DESC_SMB_ADDR_LO			0x1554
1278c2ecf20Sopenharmony_ci#define REG_DESC_RFD_RRD_RING_SIZE		0x1558
1288c2ecf20Sopenharmony_ci#define DESC_RFD_RING_SIZE_MASK			0x7FF
1298c2ecf20Sopenharmony_ci#define DESC_RFD_RING_SIZE_SHIFT		0
1308c2ecf20Sopenharmony_ci#define DESC_RRD_RING_SIZE_MASK			0x7FF
1318c2ecf20Sopenharmony_ci#define DESC_RRD_RING_SIZE_SHIFT		16
1328c2ecf20Sopenharmony_ci#define REG_DESC_TPD_RING_SIZE			0x155C
1338c2ecf20Sopenharmony_ci#define DESC_TPD_RING_SIZE_MASK			0x3FF
1348c2ecf20Sopenharmony_ci#define DESC_TPD_RING_SIZE_SHIFT		0
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* TXQ Control Register */
1378c2ecf20Sopenharmony_ci#define REG_TXQ_CTRL				0x1580
1388c2ecf20Sopenharmony_ci#define TXQ_CTRL_TPD_BURST_NUM_SHIFT		0
1398c2ecf20Sopenharmony_ci#define TXQ_CTRL_TPD_BURST_NUM_MASK		0x1F
1408c2ecf20Sopenharmony_ci#define TXQ_CTRL_EN				0x20
1418c2ecf20Sopenharmony_ci#define TXQ_CTRL_ENH_MODE			0x40
1428c2ecf20Sopenharmony_ci#define TXQ_CTRL_TPD_FETCH_TH_SHIFT		8
1438c2ecf20Sopenharmony_ci#define TXQ_CTRL_TPD_FETCH_TH_MASK		0x3F
1448c2ecf20Sopenharmony_ci#define TXQ_CTRL_TXF_BURST_NUM_SHIFT		16
1458c2ecf20Sopenharmony_ci#define TXQ_CTRL_TXF_BURST_NUM_MASK		0xFFFF
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* Jumbo packet Threshold for task offload */
1488c2ecf20Sopenharmony_ci#define REG_TX_JUMBO_TASK_TH_TPD_IPG		0x1584
1498c2ecf20Sopenharmony_ci#define TX_JUMBO_TASK_TH_MASK			0x7FF
1508c2ecf20Sopenharmony_ci#define TX_JUMBO_TASK_TH_SHIFT			0
1518c2ecf20Sopenharmony_ci#define TX_TPD_MIN_IPG_MASK			0x1F
1528c2ecf20Sopenharmony_ci#define TX_TPD_MIN_IPG_SHIFT			16
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* RXQ Control Register */
1558c2ecf20Sopenharmony_ci#define REG_RXQ_CTRL				0x15A0
1568c2ecf20Sopenharmony_ci#define RXQ_CTRL_RFD_BURST_NUM_SHIFT		0
1578c2ecf20Sopenharmony_ci#define RXQ_CTRL_RFD_BURST_NUM_MASK		0xFF
1588c2ecf20Sopenharmony_ci#define RXQ_CTRL_RRD_BURST_THRESH_SHIFT		8
1598c2ecf20Sopenharmony_ci#define RXQ_CTRL_RRD_BURST_THRESH_MASK		0xFF
1608c2ecf20Sopenharmony_ci#define RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT		16
1618c2ecf20Sopenharmony_ci#define RXQ_CTRL_RFD_PREF_MIN_IPG_MASK		0x1F
1628c2ecf20Sopenharmony_ci#define RXQ_CTRL_CUT_THRU_EN			0x40000000
1638c2ecf20Sopenharmony_ci#define RXQ_CTRL_EN				0x80000000
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/* Rx jumbo packet threshold and rrd  retirement timer */
1668c2ecf20Sopenharmony_ci#define REG_RXQ_JMBOSZ_RRDTIM			0x15A4
1678c2ecf20Sopenharmony_ci#define RXQ_JMBOSZ_TH_MASK			0x7FF
1688c2ecf20Sopenharmony_ci#define RXQ_JMBOSZ_TH_SHIFT			0
1698c2ecf20Sopenharmony_ci#define RXQ_JMBO_LKAH_MASK			0xF
1708c2ecf20Sopenharmony_ci#define RXQ_JMBO_LKAH_SHIFT			11
1718c2ecf20Sopenharmony_ci#define RXQ_RRD_TIMER_MASK			0xFFFF
1728c2ecf20Sopenharmony_ci#define RXQ_RRD_TIMER_SHIFT			16
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* RFD flow control register */
1758c2ecf20Sopenharmony_ci#define REG_RXQ_RXF_PAUSE_THRESH		0x15A8
1768c2ecf20Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_HI_SHIFT		16
1778c2ecf20Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_HI_MASK		0xFFF
1788c2ecf20Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_LO_SHIFT		0
1798c2ecf20Sopenharmony_ci#define RXQ_RXF_PAUSE_TH_LO_MASK		0xFFF
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* RRD flow control register */
1828c2ecf20Sopenharmony_ci#define REG_RXQ_RRD_PAUSE_THRESH		0x15AC
1838c2ecf20Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_HI_SHIFT		0
1848c2ecf20Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_HI_MASK		0xFFF
1858c2ecf20Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_LO_SHIFT		16
1868c2ecf20Sopenharmony_ci#define RXQ_RRD_PAUSE_TH_LO_MASK		0xFFF
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* DMA Engine Control Register */
1898c2ecf20Sopenharmony_ci#define REG_DMA_CTRL				0x15C0
1908c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAR_IN_ORDER			0x1
1918c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAR_ENH_ORDER			0x2
1928c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAR_OUT_ORDER			0x4
1938c2ecf20Sopenharmony_ci#define DMA_CTRL_RCB_VALUE			0x8
1948c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAR_BURST_LEN_SHIFT		4
1958c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAR_BURST_LEN_MASK		7
1968c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAW_BURST_LEN_SHIFT		7
1978c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAW_BURST_LEN_MASK		7
1988c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAR_EN			0x400
1998c2ecf20Sopenharmony_ci#define DMA_CTRL_DMAW_EN			0x800
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/* CMB/SMB Control Register */
2028c2ecf20Sopenharmony_ci#define REG_CSMB_CTRL				0x15D0
2038c2ecf20Sopenharmony_ci#define CSMB_CTRL_CMB_NOW			1
2048c2ecf20Sopenharmony_ci#define CSMB_CTRL_SMB_NOW			2
2058c2ecf20Sopenharmony_ci#define CSMB_CTRL_CMB_EN			4
2068c2ecf20Sopenharmony_ci#define CSMB_CTRL_SMB_EN			8
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* CMB DMA Write Threshold Register */
2098c2ecf20Sopenharmony_ci#define REG_CMB_WRITE_TH			0x15D4
2108c2ecf20Sopenharmony_ci#define CMB_RRD_TH_SHIFT			0
2118c2ecf20Sopenharmony_ci#define CMB_RRD_TH_MASK				0x7FF
2128c2ecf20Sopenharmony_ci#define CMB_TPD_TH_SHIFT			16
2138c2ecf20Sopenharmony_ci#define CMB_TPD_TH_MASK				0x7FF
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci/* RX/TX count-down timer to trigger CMB-write. 2us resolution. */
2168c2ecf20Sopenharmony_ci#define REG_CMB_WRITE_TIMER			0x15D8
2178c2ecf20Sopenharmony_ci#define CMB_RX_TM_SHIFT				0
2188c2ecf20Sopenharmony_ci#define CMB_RX_TM_MASK				0xFFFF
2198c2ecf20Sopenharmony_ci#define CMB_TX_TM_SHIFT				16
2208c2ecf20Sopenharmony_ci#define CMB_TX_TM_MASK				0xFFFF
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/* Number of packet received since last CMB write */
2238c2ecf20Sopenharmony_ci#define REG_CMB_RX_PKT_CNT			0x15DC
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci/* Number of packet transmitted since last CMB write */
2268c2ecf20Sopenharmony_ci#define REG_CMB_TX_PKT_CNT			0x15E0
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* SMB auto DMA timer register */
2298c2ecf20Sopenharmony_ci#define REG_SMB_TIMER				0x15E4
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci/* Mailbox Register */
2328c2ecf20Sopenharmony_ci#define REG_MAILBOX				0x15F0
2338c2ecf20Sopenharmony_ci#define MB_RFD_PROD_INDX_SHIFT			0
2348c2ecf20Sopenharmony_ci#define MB_RFD_PROD_INDX_MASK			0x7FF
2358c2ecf20Sopenharmony_ci#define MB_RRD_CONS_INDX_SHIFT			11
2368c2ecf20Sopenharmony_ci#define MB_RRD_CONS_INDX_MASK			0x7FF
2378c2ecf20Sopenharmony_ci#define MB_TPD_PROD_INDX_SHIFT			22
2388c2ecf20Sopenharmony_ci#define MB_TPD_PROD_INDX_MASK			0x3FF
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/* Interrupt Status Register */
2418c2ecf20Sopenharmony_ci#define ISR_SMB					0x1
2428c2ecf20Sopenharmony_ci#define ISR_TIMER				0x2
2438c2ecf20Sopenharmony_ci#define ISR_MANUAL				0x4
2448c2ecf20Sopenharmony_ci#define ISR_RXF_OV				0x8
2458c2ecf20Sopenharmony_ci#define ISR_RFD_UNRUN				0x10
2468c2ecf20Sopenharmony_ci#define ISR_RRD_OV				0x20
2478c2ecf20Sopenharmony_ci#define ISR_TXF_UNRUN				0x40
2488c2ecf20Sopenharmony_ci#define ISR_LINK				0x80
2498c2ecf20Sopenharmony_ci#define ISR_HOST_RFD_UNRUN			0x100
2508c2ecf20Sopenharmony_ci#define ISR_HOST_RRD_OV				0x200
2518c2ecf20Sopenharmony_ci#define ISR_DMAR_TO_RST				0x400
2528c2ecf20Sopenharmony_ci#define ISR_DMAW_TO_RST				0x800
2538c2ecf20Sopenharmony_ci#define ISR_GPHY				0x1000
2548c2ecf20Sopenharmony_ci#define ISR_RX_PKT				0x10000
2558c2ecf20Sopenharmony_ci#define ISR_TX_PKT				0x20000
2568c2ecf20Sopenharmony_ci#define ISR_TX_DMA				0x40000
2578c2ecf20Sopenharmony_ci#define ISR_RX_DMA				0x80000
2588c2ecf20Sopenharmony_ci#define ISR_CMB_RX				0x100000
2598c2ecf20Sopenharmony_ci#define ISR_CMB_TX				0x200000
2608c2ecf20Sopenharmony_ci#define ISR_MAC_RX				0x400000
2618c2ecf20Sopenharmony_ci#define ISR_MAC_TX				0x800000
2628c2ecf20Sopenharmony_ci#define ISR_DIS_SMB				0x20000000
2638c2ecf20Sopenharmony_ci#define ISR_DIS_DMA				0x40000000
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/* Normal Interrupt mask without RX/TX enabled */
2668c2ecf20Sopenharmony_ci#define IMR_NORXTX_MASK	(\
2678c2ecf20Sopenharmony_ci	ISR_SMB		|\
2688c2ecf20Sopenharmony_ci	ISR_GPHY	|\
2698c2ecf20Sopenharmony_ci	ISR_PHY_LINKDOWN|\
2708c2ecf20Sopenharmony_ci	ISR_DMAR_TO_RST	|\
2718c2ecf20Sopenharmony_ci	ISR_DMAW_TO_RST)
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci/* Normal Interrupt mask  */
2748c2ecf20Sopenharmony_ci#define IMR_NORMAL_MASK	(\
2758c2ecf20Sopenharmony_ci	IMR_NORXTX_MASK	|\
2768c2ecf20Sopenharmony_ci	ISR_CMB_TX	|\
2778c2ecf20Sopenharmony_ci	ISR_CMB_RX)
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci/* Debug Interrupt Mask  (enable all interrupt) */
2808c2ecf20Sopenharmony_ci#define IMR_DEBUG_MASK	(\
2818c2ecf20Sopenharmony_ci	ISR_SMB		|\
2828c2ecf20Sopenharmony_ci	ISR_TIMER	|\
2838c2ecf20Sopenharmony_ci	ISR_MANUAL	|\
2848c2ecf20Sopenharmony_ci	ISR_RXF_OV	|\
2858c2ecf20Sopenharmony_ci	ISR_RFD_UNRUN	|\
2868c2ecf20Sopenharmony_ci	ISR_RRD_OV	|\
2878c2ecf20Sopenharmony_ci	ISR_TXF_UNRUN	|\
2888c2ecf20Sopenharmony_ci	ISR_LINK	|\
2898c2ecf20Sopenharmony_ci	ISR_CMB_TX	|\
2908c2ecf20Sopenharmony_ci	ISR_CMB_RX	|\
2918c2ecf20Sopenharmony_ci	ISR_RX_PKT	|\
2928c2ecf20Sopenharmony_ci	ISR_TX_PKT	|\
2938c2ecf20Sopenharmony_ci	ISR_MAC_RX	|\
2948c2ecf20Sopenharmony_ci	ISR_MAC_TX)
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci#define MEDIA_TYPE_1000M_FULL			1
2978c2ecf20Sopenharmony_ci#define MEDIA_TYPE_100M_FULL			2
2988c2ecf20Sopenharmony_ci#define MEDIA_TYPE_100M_HALF			3
2998c2ecf20Sopenharmony_ci#define MEDIA_TYPE_10M_FULL			4
3008c2ecf20Sopenharmony_ci#define MEDIA_TYPE_10M_HALF			5
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci#define AUTONEG_ADVERTISE_SPEED_DEFAULT		0x002F	/* All but 1000-Half */
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci#define MAX_JUMBO_FRAME_SIZE			10240
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci#define ATL1_EEDUMP_LEN				48
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci/* Statistics counters collected by the MAC */
3098c2ecf20Sopenharmony_cistruct stats_msg_block {
3108c2ecf20Sopenharmony_ci	/* rx */
3118c2ecf20Sopenharmony_ci	u32 rx_ok;		/* good RX packets */
3128c2ecf20Sopenharmony_ci	u32 rx_bcast;		/* good RX broadcast packets */
3138c2ecf20Sopenharmony_ci	u32 rx_mcast;		/* good RX multicast packets */
3148c2ecf20Sopenharmony_ci	u32 rx_pause;		/* RX pause frames */
3158c2ecf20Sopenharmony_ci	u32 rx_ctrl;		/* RX control packets other than pause frames */
3168c2ecf20Sopenharmony_ci	u32 rx_fcs_err;		/* RX packets with bad FCS */
3178c2ecf20Sopenharmony_ci	u32 rx_len_err;		/* RX packets with length != actual size */
3188c2ecf20Sopenharmony_ci	u32 rx_byte_cnt;	/* good bytes received. FCS is NOT included */
3198c2ecf20Sopenharmony_ci	u32 rx_runt;		/* RX packets < 64 bytes with good FCS */
3208c2ecf20Sopenharmony_ci	u32 rx_frag;		/* RX packets < 64 bytes with bad FCS */
3218c2ecf20Sopenharmony_ci	u32 rx_sz_64;		/* 64 byte RX packets */
3228c2ecf20Sopenharmony_ci	u32 rx_sz_65_127;
3238c2ecf20Sopenharmony_ci	u32 rx_sz_128_255;
3248c2ecf20Sopenharmony_ci	u32 rx_sz_256_511;
3258c2ecf20Sopenharmony_ci	u32 rx_sz_512_1023;
3268c2ecf20Sopenharmony_ci	u32 rx_sz_1024_1518;
3278c2ecf20Sopenharmony_ci	u32 rx_sz_1519_max;	/* 1519 byte to MTU RX packets */
3288c2ecf20Sopenharmony_ci	u32 rx_sz_ov;		/* truncated RX packets > MTU */
3298c2ecf20Sopenharmony_ci	u32 rx_rxf_ov;		/* frames dropped due to RX FIFO overflow */
3308c2ecf20Sopenharmony_ci	u32 rx_rrd_ov;		/* frames dropped due to RRD overflow */
3318c2ecf20Sopenharmony_ci	u32 rx_align_err;	/* alignment errors */
3328c2ecf20Sopenharmony_ci	u32 rx_bcast_byte_cnt;	/* RX broadcast bytes, excluding FCS */
3338c2ecf20Sopenharmony_ci	u32 rx_mcast_byte_cnt;	/* RX multicast bytes, excluding FCS */
3348c2ecf20Sopenharmony_ci	u32 rx_err_addr;	/* packets dropped due to address filtering */
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	/* tx */
3378c2ecf20Sopenharmony_ci	u32 tx_ok;		/* good TX packets */
3388c2ecf20Sopenharmony_ci	u32 tx_bcast;		/* good TX broadcast packets */
3398c2ecf20Sopenharmony_ci	u32 tx_mcast;		/* good TX multicast packets */
3408c2ecf20Sopenharmony_ci	u32 tx_pause;		/* TX pause frames */
3418c2ecf20Sopenharmony_ci	u32 tx_exc_defer;	/* TX packets deferred excessively */
3428c2ecf20Sopenharmony_ci	u32 tx_ctrl;		/* TX control frames, excluding pause frames */
3438c2ecf20Sopenharmony_ci	u32 tx_defer;		/* TX packets deferred */
3448c2ecf20Sopenharmony_ci	u32 tx_byte_cnt;	/* bytes transmitted, FCS is NOT included */
3458c2ecf20Sopenharmony_ci	u32 tx_sz_64;		/* 64 byte TX packets */
3468c2ecf20Sopenharmony_ci	u32 tx_sz_65_127;
3478c2ecf20Sopenharmony_ci	u32 tx_sz_128_255;
3488c2ecf20Sopenharmony_ci	u32 tx_sz_256_511;
3498c2ecf20Sopenharmony_ci	u32 tx_sz_512_1023;
3508c2ecf20Sopenharmony_ci	u32 tx_sz_1024_1518;
3518c2ecf20Sopenharmony_ci	u32 tx_sz_1519_max;	/* 1519 byte to MTU TX packets */
3528c2ecf20Sopenharmony_ci	u32 tx_1_col;		/* packets TX after a single collision */
3538c2ecf20Sopenharmony_ci	u32 tx_2_col;		/* packets TX after multiple collisions */
3548c2ecf20Sopenharmony_ci	u32 tx_late_col;	/* TX packets with late collisions */
3558c2ecf20Sopenharmony_ci	u32 tx_abort_col;	/* TX packets aborted w/excessive collisions */
3568c2ecf20Sopenharmony_ci	u32 tx_underrun;	/* TX packets aborted due to TX FIFO underrun
3578c2ecf20Sopenharmony_ci				 * or TRD FIFO underrun */
3588c2ecf20Sopenharmony_ci	u32 tx_rd_eop;		/* reads beyond the EOP into the next frame
3598c2ecf20Sopenharmony_ci				 * when TRD was not written timely */
3608c2ecf20Sopenharmony_ci	u32 tx_len_err;		/* TX packets where length != actual size */
3618c2ecf20Sopenharmony_ci	u32 tx_trunc;		/* TX packets truncated due to size > MTU */
3628c2ecf20Sopenharmony_ci	u32 tx_bcast_byte;	/* broadcast bytes transmitted, excluding FCS */
3638c2ecf20Sopenharmony_ci	u32 tx_mcast_byte;	/* multicast bytes transmitted, excluding FCS */
3648c2ecf20Sopenharmony_ci	u32 smb_updated;	/* 1: SMB Updated. This is used by software to
3658c2ecf20Sopenharmony_ci				 * indicate the statistics update. Software
3668c2ecf20Sopenharmony_ci				 * should clear this bit after retrieving the
3678c2ecf20Sopenharmony_ci				 * statistics information. */
3688c2ecf20Sopenharmony_ci};
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci/* Coalescing Message Block */
3718c2ecf20Sopenharmony_cistruct coals_msg_block {
3728c2ecf20Sopenharmony_ci	u32 int_stats;		/* interrupt status */
3738c2ecf20Sopenharmony_ci	u16 rrd_prod_idx;	/* TRD Producer Index. */
3748c2ecf20Sopenharmony_ci	u16 rfd_cons_idx;	/* RFD Consumer Index. */
3758c2ecf20Sopenharmony_ci	u16 update;		/* Selene sets this bit every time it DMAs the
3768c2ecf20Sopenharmony_ci				 * CMB to host memory. Software should clear
3778c2ecf20Sopenharmony_ci				 * this bit when CMB info is processed. */
3788c2ecf20Sopenharmony_ci	u16 tpd_cons_idx;	/* TPD Consumer Index. */
3798c2ecf20Sopenharmony_ci};
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci/* RRD descriptor */
3828c2ecf20Sopenharmony_cistruct rx_return_desc {
3838c2ecf20Sopenharmony_ci	u8 num_buf;	/* Number of RFD buffers used by the received packet */
3848c2ecf20Sopenharmony_ci	u8 resved;
3858c2ecf20Sopenharmony_ci	u16 buf_indx;	/* RFD Index of the first buffer */
3868c2ecf20Sopenharmony_ci	union {
3878c2ecf20Sopenharmony_ci		u32 valid;
3888c2ecf20Sopenharmony_ci		struct {
3898c2ecf20Sopenharmony_ci			u16 rx_chksum;
3908c2ecf20Sopenharmony_ci			u16 pkt_size;
3918c2ecf20Sopenharmony_ci		} xsum_sz;
3928c2ecf20Sopenharmony_ci	} xsz;
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	u16 pkt_flg;	/* Packet flags */
3958c2ecf20Sopenharmony_ci	u16 err_flg;	/* Error flags */
3968c2ecf20Sopenharmony_ci	u16 resved2;
3978c2ecf20Sopenharmony_ci	u16 vlan_tag;	/* VLAN TAG */
3988c2ecf20Sopenharmony_ci};
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci#define PACKET_FLAG_ETH_TYPE	0x0080
4018c2ecf20Sopenharmony_ci#define PACKET_FLAG_VLAN_INS	0x0100
4028c2ecf20Sopenharmony_ci#define PACKET_FLAG_ERR		0x0200
4038c2ecf20Sopenharmony_ci#define PACKET_FLAG_IPV4	0x0400
4048c2ecf20Sopenharmony_ci#define PACKET_FLAG_UDP		0x0800
4058c2ecf20Sopenharmony_ci#define PACKET_FLAG_TCP		0x1000
4068c2ecf20Sopenharmony_ci#define PACKET_FLAG_BCAST	0x2000
4078c2ecf20Sopenharmony_ci#define PACKET_FLAG_MCAST	0x4000
4088c2ecf20Sopenharmony_ci#define PACKET_FLAG_PAUSE	0x8000
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci#define ERR_FLAG_CRC		0x0001
4118c2ecf20Sopenharmony_ci#define ERR_FLAG_CODE		0x0002
4128c2ecf20Sopenharmony_ci#define ERR_FLAG_DRIBBLE	0x0004
4138c2ecf20Sopenharmony_ci#define ERR_FLAG_RUNT		0x0008
4148c2ecf20Sopenharmony_ci#define ERR_FLAG_OV		0x0010
4158c2ecf20Sopenharmony_ci#define ERR_FLAG_TRUNC		0x0020
4168c2ecf20Sopenharmony_ci#define ERR_FLAG_IP_CHKSUM	0x0040
4178c2ecf20Sopenharmony_ci#define ERR_FLAG_L4_CHKSUM	0x0080
4188c2ecf20Sopenharmony_ci#define ERR_FLAG_LEN		0x0100
4198c2ecf20Sopenharmony_ci#define ERR_FLAG_DES_ADDR	0x0200
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci/* RFD descriptor */
4228c2ecf20Sopenharmony_cistruct rx_free_desc {
4238c2ecf20Sopenharmony_ci	__le64 buffer_addr;	/* Address of the descriptor's data buffer */
4248c2ecf20Sopenharmony_ci	__le16 buf_len;		/* Size of the receive buffer in host memory */
4258c2ecf20Sopenharmony_ci	u16 coalese;		/* Update consumer index to host after the
4268c2ecf20Sopenharmony_ci				 * reception of this frame */
4278c2ecf20Sopenharmony_ci	/* __packed is required */
4288c2ecf20Sopenharmony_ci} __packed;
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci/*
4318c2ecf20Sopenharmony_ci * The L1 transmit packet descriptor is comprised of four 32-bit words.
4328c2ecf20Sopenharmony_ci *
4338c2ecf20Sopenharmony_ci *	31					0
4348c2ecf20Sopenharmony_ci *	+---------------------------------------+
4358c2ecf20Sopenharmony_ci *      |	Word 0: Buffer addr lo 		|
4368c2ecf20Sopenharmony_ci *      +---------------------------------------+
4378c2ecf20Sopenharmony_ci *      |	Word 1: Buffer addr hi		|
4388c2ecf20Sopenharmony_ci *      +---------------------------------------+
4398c2ecf20Sopenharmony_ci *      |		Word 2			|
4408c2ecf20Sopenharmony_ci *      +---------------------------------------+
4418c2ecf20Sopenharmony_ci *      |		Word 3			|
4428c2ecf20Sopenharmony_ci *      +---------------------------------------+
4438c2ecf20Sopenharmony_ci *
4448c2ecf20Sopenharmony_ci * Words 0 and 1 combine to form a 64-bit buffer address.
4458c2ecf20Sopenharmony_ci *
4468c2ecf20Sopenharmony_ci * Word 2 is self explanatory in the #define block below.
4478c2ecf20Sopenharmony_ci *
4488c2ecf20Sopenharmony_ci * Word 3 has two forms, depending upon the state of bits 3 and 4.
4498c2ecf20Sopenharmony_ci * If bits 3 and 4 are both zero, then bits 14:31 are unused by the
4508c2ecf20Sopenharmony_ci * hardware.  Otherwise, if either bit 3 or 4 is set, the definition
4518c2ecf20Sopenharmony_ci * of bits 14:31 vary according to the following depiction.
4528c2ecf20Sopenharmony_ci *
4538c2ecf20Sopenharmony_ci *	0	End of packet			0	End of packet
4548c2ecf20Sopenharmony_ci *	1	Coalesce			1	Coalesce
4558c2ecf20Sopenharmony_ci *	2	Insert VLAN tag			2	Insert VLAN tag
4568c2ecf20Sopenharmony_ci *	3	Custom csum enable = 0		3	Custom csum enable = 1
4578c2ecf20Sopenharmony_ci *	4	Segment enable = 1		4	Segment enable = 0
4588c2ecf20Sopenharmony_ci *	5	Generate IP checksum		5	Generate IP checksum
4598c2ecf20Sopenharmony_ci *	6	Generate TCP checksum		6	Generate TCP checksum
4608c2ecf20Sopenharmony_ci *	7	Generate UDP checksum		7	Generate UDP checksum
4618c2ecf20Sopenharmony_ci *	8	VLAN tagged			8	VLAN tagged
4628c2ecf20Sopenharmony_ci *	9	Ethernet frame type		9	Ethernet frame type
4638c2ecf20Sopenharmony_ci *	10-+ 					10-+
4648c2ecf20Sopenharmony_ci *	11 |	IP hdr length (10:13)		11 |	IP hdr length (10:13)
4658c2ecf20Sopenharmony_ci *	12 |	(num 32-bit words)		12 |	(num 32-bit words)
4668c2ecf20Sopenharmony_ci *	13-+					13-+
4678c2ecf20Sopenharmony_ci *	14-+					14	Unused
4688c2ecf20Sopenharmony_ci *	15 |	TCP hdr length (14:17)		15	Unused
4698c2ecf20Sopenharmony_ci *	16 |	(num 32-bit words)		16-+
4708c2ecf20Sopenharmony_ci *	17-+					17 |
4718c2ecf20Sopenharmony_ci *	18	Header TPD flag			18 |
4728c2ecf20Sopenharmony_ci *	19-+					19 |	Payload offset
4738c2ecf20Sopenharmony_ci *	20 |					20 |	    (16:23)
4748c2ecf20Sopenharmony_ci *	21 |					21 |
4758c2ecf20Sopenharmony_ci *	22 |					22 |
4768c2ecf20Sopenharmony_ci *	23 |					23-+
4778c2ecf20Sopenharmony_ci *	24 |					24-+
4788c2ecf20Sopenharmony_ci *	25 |	MSS (19:31)			25 |
4798c2ecf20Sopenharmony_ci *	26 |					26 |
4808c2ecf20Sopenharmony_ci *	27 |					27 |	Custom csum offset
4818c2ecf20Sopenharmony_ci *	28 |					28 |	     (24:31)
4828c2ecf20Sopenharmony_ci *	29 |					29 |
4838c2ecf20Sopenharmony_ci *	30 |					30 |
4848c2ecf20Sopenharmony_ci *	31-+					31-+
4858c2ecf20Sopenharmony_ci */
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci/* tpd word 2 */
4888c2ecf20Sopenharmony_ci#define TPD_BUFLEN_MASK		0x3FFF
4898c2ecf20Sopenharmony_ci#define TPD_BUFLEN_SHIFT	0
4908c2ecf20Sopenharmony_ci#define TPD_DMAINT_MASK		0x0001
4918c2ecf20Sopenharmony_ci#define TPD_DMAINT_SHIFT	14
4928c2ecf20Sopenharmony_ci#define TPD_PKTNT_MASK		0x0001
4938c2ecf20Sopenharmony_ci#define TPD_PKTINT_SHIFT	15
4948c2ecf20Sopenharmony_ci#define TPD_VLANTAG_MASK	0xFFFF
4958c2ecf20Sopenharmony_ci#define TPD_VLANTAG_SHIFT	16
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci/* tpd word 3 bits 0:13 */
4988c2ecf20Sopenharmony_ci#define TPD_EOP_MASK		0x0001
4998c2ecf20Sopenharmony_ci#define TPD_EOP_SHIFT		0
5008c2ecf20Sopenharmony_ci#define TPD_COALESCE_MASK	0x0001
5018c2ecf20Sopenharmony_ci#define TPD_COALESCE_SHIFT	1
5028c2ecf20Sopenharmony_ci#define TPD_INS_VL_TAG_MASK	0x0001
5038c2ecf20Sopenharmony_ci#define TPD_INS_VL_TAG_SHIFT	2
5048c2ecf20Sopenharmony_ci#define TPD_CUST_CSUM_EN_MASK	0x0001
5058c2ecf20Sopenharmony_ci#define TPD_CUST_CSUM_EN_SHIFT	3
5068c2ecf20Sopenharmony_ci#define TPD_SEGMENT_EN_MASK	0x0001
5078c2ecf20Sopenharmony_ci#define TPD_SEGMENT_EN_SHIFT	4
5088c2ecf20Sopenharmony_ci#define TPD_IP_CSUM_MASK	0x0001
5098c2ecf20Sopenharmony_ci#define TPD_IP_CSUM_SHIFT	5
5108c2ecf20Sopenharmony_ci#define TPD_TCP_CSUM_MASK	0x0001
5118c2ecf20Sopenharmony_ci#define TPD_TCP_CSUM_SHIFT	6
5128c2ecf20Sopenharmony_ci#define TPD_UDP_CSUM_MASK	0x0001
5138c2ecf20Sopenharmony_ci#define TPD_UDP_CSUM_SHIFT	7
5148c2ecf20Sopenharmony_ci#define TPD_VL_TAGGED_MASK	0x0001
5158c2ecf20Sopenharmony_ci#define TPD_VL_TAGGED_SHIFT	8
5168c2ecf20Sopenharmony_ci#define TPD_ETHTYPE_MASK	0x0001
5178c2ecf20Sopenharmony_ci#define TPD_ETHTYPE_SHIFT	9
5188c2ecf20Sopenharmony_ci#define TPD_IPHL_MASK		0x000F
5198c2ecf20Sopenharmony_ci#define TPD_IPHL_SHIFT		10
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci/* tpd word 3 bits 14:31 if segment enabled */
5228c2ecf20Sopenharmony_ci#define TPD_TCPHDRLEN_MASK	0x000F
5238c2ecf20Sopenharmony_ci#define TPD_TCPHDRLEN_SHIFT	14
5248c2ecf20Sopenharmony_ci#define TPD_HDRFLAG_MASK	0x0001
5258c2ecf20Sopenharmony_ci#define TPD_HDRFLAG_SHIFT	18
5268c2ecf20Sopenharmony_ci#define TPD_MSS_MASK		0x1FFF
5278c2ecf20Sopenharmony_ci#define TPD_MSS_SHIFT		19
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci/* tpd word 3 bits 16:31 if custom csum enabled */
5308c2ecf20Sopenharmony_ci#define TPD_PLOADOFFSET_MASK	0x00FF
5318c2ecf20Sopenharmony_ci#define TPD_PLOADOFFSET_SHIFT	16
5328c2ecf20Sopenharmony_ci#define TPD_CCSUMOFFSET_MASK	0x00FF
5338c2ecf20Sopenharmony_ci#define TPD_CCSUMOFFSET_SHIFT	24
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_cistruct tx_packet_desc {
5368c2ecf20Sopenharmony_ci	__le64 buffer_addr;
5378c2ecf20Sopenharmony_ci	__le32 word2;
5388c2ecf20Sopenharmony_ci	__le32 word3;
5398c2ecf20Sopenharmony_ci};
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci/* DMA Order Settings */
5428c2ecf20Sopenharmony_cienum atl1_dma_order {
5438c2ecf20Sopenharmony_ci	atl1_dma_ord_in = 1,
5448c2ecf20Sopenharmony_ci	atl1_dma_ord_enh = 2,
5458c2ecf20Sopenharmony_ci	atl1_dma_ord_out = 4
5468c2ecf20Sopenharmony_ci};
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_cienum atl1_dma_rcb {
5498c2ecf20Sopenharmony_ci	atl1_rcb_64 = 0,
5508c2ecf20Sopenharmony_ci	atl1_rcb_128 = 1
5518c2ecf20Sopenharmony_ci};
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_cienum atl1_dma_req_block {
5548c2ecf20Sopenharmony_ci	atl1_dma_req_128 = 0,
5558c2ecf20Sopenharmony_ci	atl1_dma_req_256 = 1,
5568c2ecf20Sopenharmony_ci	atl1_dma_req_512 = 2,
5578c2ecf20Sopenharmony_ci	atl1_dma_req_1024 = 3,
5588c2ecf20Sopenharmony_ci	atl1_dma_req_2048 = 4,
5598c2ecf20Sopenharmony_ci	atl1_dma_req_4096 = 5
5608c2ecf20Sopenharmony_ci};
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci#define ATL1_MAX_INTR		3
5638c2ecf20Sopenharmony_ci#define ATL1_MAX_TX_BUF_LEN	0x3000	/* 12288 bytes */
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci#define ATL1_DEFAULT_TPD	256
5668c2ecf20Sopenharmony_ci#define ATL1_MAX_TPD		1024
5678c2ecf20Sopenharmony_ci#define ATL1_MIN_TPD		64
5688c2ecf20Sopenharmony_ci#define ATL1_DEFAULT_RFD	512
5698c2ecf20Sopenharmony_ci#define ATL1_MIN_RFD		128
5708c2ecf20Sopenharmony_ci#define ATL1_MAX_RFD		2048
5718c2ecf20Sopenharmony_ci#define ATL1_REG_COUNT		1538
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci#define ATL1_GET_DESC(R, i, type)	(&(((type *)((R)->desc))[i]))
5748c2ecf20Sopenharmony_ci#define ATL1_RFD_DESC(R, i)	ATL1_GET_DESC(R, i, struct rx_free_desc)
5758c2ecf20Sopenharmony_ci#define ATL1_TPD_DESC(R, i)	ATL1_GET_DESC(R, i, struct tx_packet_desc)
5768c2ecf20Sopenharmony_ci#define ATL1_RRD_DESC(R, i)	ATL1_GET_DESC(R, i, struct rx_return_desc)
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_ci/*
5798c2ecf20Sopenharmony_ci * atl1_ring_header represents a single, contiguous block of DMA space
5808c2ecf20Sopenharmony_ci * mapped for the three descriptor rings (tpd, rfd, rrd) and the two
5818c2ecf20Sopenharmony_ci * message blocks (cmb, smb) described below
5828c2ecf20Sopenharmony_ci */
5838c2ecf20Sopenharmony_cistruct atl1_ring_header {
5848c2ecf20Sopenharmony_ci	void *desc;		/* virtual address */
5858c2ecf20Sopenharmony_ci	dma_addr_t dma;		/* physical address*/
5868c2ecf20Sopenharmony_ci	unsigned int size;	/* length in bytes */
5878c2ecf20Sopenharmony_ci};
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci/*
5908c2ecf20Sopenharmony_ci * atl1_buffer is wrapper around a pointer to a socket buffer
5918c2ecf20Sopenharmony_ci * so a DMA handle can be stored along with the skb
5928c2ecf20Sopenharmony_ci */
5938c2ecf20Sopenharmony_cistruct atl1_buffer {
5948c2ecf20Sopenharmony_ci	struct sk_buff *skb;	/* socket buffer */
5958c2ecf20Sopenharmony_ci	u16 length;		/* rx buffer length */
5968c2ecf20Sopenharmony_ci	u16 alloced;		/* 1 if skb allocated */
5978c2ecf20Sopenharmony_ci	dma_addr_t dma;
5988c2ecf20Sopenharmony_ci};
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci/* transmit packet descriptor (tpd) ring */
6018c2ecf20Sopenharmony_cistruct atl1_tpd_ring {
6028c2ecf20Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
6038c2ecf20Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
6048c2ecf20Sopenharmony_ci	u16 size;		/* descriptor ring length in bytes */
6058c2ecf20Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
6068c2ecf20Sopenharmony_ci	u16 hw_idx;		/* hardware index */
6078c2ecf20Sopenharmony_ci	atomic_t next_to_clean;
6088c2ecf20Sopenharmony_ci	atomic_t next_to_use;
6098c2ecf20Sopenharmony_ci	struct atl1_buffer *buffer_info;
6108c2ecf20Sopenharmony_ci};
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci/* receive free descriptor (rfd) ring */
6138c2ecf20Sopenharmony_cistruct atl1_rfd_ring {
6148c2ecf20Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
6158c2ecf20Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
6168c2ecf20Sopenharmony_ci	u16 size;		/* descriptor ring length in bytes */
6178c2ecf20Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
6188c2ecf20Sopenharmony_ci	atomic_t next_to_use;
6198c2ecf20Sopenharmony_ci	u16 next_to_clean;
6208c2ecf20Sopenharmony_ci	struct atl1_buffer *buffer_info;
6218c2ecf20Sopenharmony_ci};
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci/* receive return descriptor (rrd) ring */
6248c2ecf20Sopenharmony_cistruct atl1_rrd_ring {
6258c2ecf20Sopenharmony_ci	void *desc;		/* descriptor ring virtual address */
6268c2ecf20Sopenharmony_ci	dma_addr_t dma;		/* descriptor ring physical address */
6278c2ecf20Sopenharmony_ci	unsigned int size;	/* descriptor ring length in bytes */
6288c2ecf20Sopenharmony_ci	u16 count;		/* number of descriptors in the ring */
6298c2ecf20Sopenharmony_ci	u16 next_to_use;
6308c2ecf20Sopenharmony_ci	atomic_t next_to_clean;
6318c2ecf20Sopenharmony_ci};
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci/* coalescing message block (cmb) */
6348c2ecf20Sopenharmony_cistruct atl1_cmb {
6358c2ecf20Sopenharmony_ci	struct coals_msg_block *cmb;
6368c2ecf20Sopenharmony_ci	dma_addr_t dma;
6378c2ecf20Sopenharmony_ci};
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ci/* statistics message block (smb) */
6408c2ecf20Sopenharmony_cistruct atl1_smb {
6418c2ecf20Sopenharmony_ci	struct stats_msg_block *smb;
6428c2ecf20Sopenharmony_ci	dma_addr_t dma;
6438c2ecf20Sopenharmony_ci};
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci/* Statistics counters */
6468c2ecf20Sopenharmony_cistruct atl1_sft_stats {
6478c2ecf20Sopenharmony_ci	u64 rx_packets;
6488c2ecf20Sopenharmony_ci	u64 tx_packets;
6498c2ecf20Sopenharmony_ci	u64 rx_bytes;
6508c2ecf20Sopenharmony_ci	u64 tx_bytes;
6518c2ecf20Sopenharmony_ci	u64 multicast;
6528c2ecf20Sopenharmony_ci	u64 collisions;
6538c2ecf20Sopenharmony_ci	u64 rx_errors;
6548c2ecf20Sopenharmony_ci	u64 rx_length_errors;
6558c2ecf20Sopenharmony_ci	u64 rx_crc_errors;
6568c2ecf20Sopenharmony_ci	u64 rx_dropped;
6578c2ecf20Sopenharmony_ci	u64 rx_frame_errors;
6588c2ecf20Sopenharmony_ci	u64 rx_fifo_errors;
6598c2ecf20Sopenharmony_ci	u64 rx_missed_errors;
6608c2ecf20Sopenharmony_ci	u64 tx_errors;
6618c2ecf20Sopenharmony_ci	u64 tx_fifo_errors;
6628c2ecf20Sopenharmony_ci	u64 tx_aborted_errors;
6638c2ecf20Sopenharmony_ci	u64 tx_window_errors;
6648c2ecf20Sopenharmony_ci	u64 tx_carrier_errors;
6658c2ecf20Sopenharmony_ci	u64 tx_pause;		/* TX pause frames */
6668c2ecf20Sopenharmony_ci	u64 excecol;		/* TX packets w/ excessive collisions */
6678c2ecf20Sopenharmony_ci	u64 deffer;		/* TX packets deferred */
6688c2ecf20Sopenharmony_ci	u64 scc;		/* packets TX after a single collision */
6698c2ecf20Sopenharmony_ci	u64 mcc;		/* packets TX after multiple collisions */
6708c2ecf20Sopenharmony_ci	u64 latecol;		/* TX packets w/ late collisions */
6718c2ecf20Sopenharmony_ci	u64 tx_underrun;	/* TX packets aborted due to TX FIFO underrun
6728c2ecf20Sopenharmony_ci				 * or TRD FIFO underrun */
6738c2ecf20Sopenharmony_ci	u64 tx_trunc;		/* TX packets truncated due to size > MTU */
6748c2ecf20Sopenharmony_ci	u64 rx_pause;		/* num Pause packets received. */
6758c2ecf20Sopenharmony_ci	u64 rx_rrd_ov;
6768c2ecf20Sopenharmony_ci	u64 rx_trunc;
6778c2ecf20Sopenharmony_ci};
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci/* hardware structure */
6808c2ecf20Sopenharmony_cistruct atl1_hw {
6818c2ecf20Sopenharmony_ci	u8 __iomem *hw_addr;
6828c2ecf20Sopenharmony_ci	struct atl1_adapter *back;
6838c2ecf20Sopenharmony_ci	enum atl1_dma_order dma_ord;
6848c2ecf20Sopenharmony_ci	enum atl1_dma_rcb rcb_value;
6858c2ecf20Sopenharmony_ci	enum atl1_dma_req_block dmar_block;
6868c2ecf20Sopenharmony_ci	enum atl1_dma_req_block dmaw_block;
6878c2ecf20Sopenharmony_ci	u8 preamble_len;
6888c2ecf20Sopenharmony_ci	u8 max_retry;
6898c2ecf20Sopenharmony_ci	u8 jam_ipg;		/* IPG to start JAM for collision based flow
6908c2ecf20Sopenharmony_ci				 * control in half-duplex mode. In units of
6918c2ecf20Sopenharmony_ci				 * 8-bit time */
6928c2ecf20Sopenharmony_ci	u8 ipgt;		/* Desired back to back inter-packet gap.
6938c2ecf20Sopenharmony_ci				 * The default is 96-bit time */
6948c2ecf20Sopenharmony_ci	u8 min_ifg;		/* Minimum number of IFG to enforce in between
6958c2ecf20Sopenharmony_ci				 * receive frames. Frame gap below such IFP
6968c2ecf20Sopenharmony_ci				 * is dropped */
6978c2ecf20Sopenharmony_ci	u8 ipgr1;		/* 64bit Carrier-Sense window */
6988c2ecf20Sopenharmony_ci	u8 ipgr2;		/* 96-bit IPG window */
6998c2ecf20Sopenharmony_ci	u8 tpd_burst;		/* Number of TPD to prefetch in cache-aligned
7008c2ecf20Sopenharmony_ci				 * burst. Each TPD is 16 bytes long */
7018c2ecf20Sopenharmony_ci	u8 rfd_burst;		/* Number of RFD to prefetch in cache-aligned
7028c2ecf20Sopenharmony_ci				 * burst. Each RFD is 12 bytes long */
7038c2ecf20Sopenharmony_ci	u8 rfd_fetch_gap;
7048c2ecf20Sopenharmony_ci	u8 rrd_burst;		/* Threshold number of RRDs that can be retired
7058c2ecf20Sopenharmony_ci				 * in a burst. Each RRD is 16 bytes long */
7068c2ecf20Sopenharmony_ci	u8 tpd_fetch_th;
7078c2ecf20Sopenharmony_ci	u8 tpd_fetch_gap;
7088c2ecf20Sopenharmony_ci	u16 tx_jumbo_task_th;
7098c2ecf20Sopenharmony_ci	u16 txf_burst;		/* Number of data bytes to read in a cache-
7108c2ecf20Sopenharmony_ci				 * aligned burst. Each SRAM entry is 8 bytes */
7118c2ecf20Sopenharmony_ci	u16 rx_jumbo_th;	/* Jumbo packet size for non-VLAN packet. VLAN
7128c2ecf20Sopenharmony_ci				 * packets should add 4 bytes */
7138c2ecf20Sopenharmony_ci	u16 rx_jumbo_lkah;
7148c2ecf20Sopenharmony_ci	u16 rrd_ret_timer;	/* RRD retirement timer. Decrement by 1 after
7158c2ecf20Sopenharmony_ci				 * every 512ns passes. */
7168c2ecf20Sopenharmony_ci	u16 lcol;		/* Collision Window */
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci	u16 cmb_tpd;
7198c2ecf20Sopenharmony_ci	u16 cmb_rrd;
7208c2ecf20Sopenharmony_ci	u16 cmb_rx_timer;
7218c2ecf20Sopenharmony_ci	u16 cmb_tx_timer;
7228c2ecf20Sopenharmony_ci	u32 smb_timer;
7238c2ecf20Sopenharmony_ci	u16 media_type;
7248c2ecf20Sopenharmony_ci	u16 autoneg_advertised;
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci	u16 mii_autoneg_adv_reg;
7278c2ecf20Sopenharmony_ci	u16 mii_1000t_ctrl_reg;
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	u32 max_frame_size;
7308c2ecf20Sopenharmony_ci	u32 min_frame_size;
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	u16 dev_rev;
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	/* spi flash */
7358c2ecf20Sopenharmony_ci	u8 flash_vendor;
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci	u8 mac_addr[ETH_ALEN];
7388c2ecf20Sopenharmony_ci	u8 perm_mac_addr[ETH_ALEN];
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	bool phy_configured;
7418c2ecf20Sopenharmony_ci};
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_cistruct atl1_adapter {
7448c2ecf20Sopenharmony_ci	struct net_device *netdev;
7458c2ecf20Sopenharmony_ci	struct pci_dev *pdev;
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_ci	struct atl1_sft_stats soft_stats;
7488c2ecf20Sopenharmony_ci	u32 rx_buffer_len;
7498c2ecf20Sopenharmony_ci	u32 wol;
7508c2ecf20Sopenharmony_ci	u16 link_speed;
7518c2ecf20Sopenharmony_ci	u16 link_duplex;
7528c2ecf20Sopenharmony_ci	spinlock_t lock;
7538c2ecf20Sopenharmony_ci	struct napi_struct napi;
7548c2ecf20Sopenharmony_ci	struct work_struct reset_dev_task;
7558c2ecf20Sopenharmony_ci	struct work_struct link_chg_task;
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	struct timer_list phy_config_timer;
7588c2ecf20Sopenharmony_ci	bool phy_timer_pending;
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci	/* all descriptor rings' memory */
7618c2ecf20Sopenharmony_ci	struct atl1_ring_header ring_header;
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci	/* TX */
7648c2ecf20Sopenharmony_ci	struct atl1_tpd_ring tpd_ring;
7658c2ecf20Sopenharmony_ci	spinlock_t mb_lock;
7668c2ecf20Sopenharmony_ci
7678c2ecf20Sopenharmony_ci	/* RX */
7688c2ecf20Sopenharmony_ci	struct atl1_rfd_ring rfd_ring;
7698c2ecf20Sopenharmony_ci	struct atl1_rrd_ring rrd_ring;
7708c2ecf20Sopenharmony_ci	u64 hw_csum_err;
7718c2ecf20Sopenharmony_ci	u64 hw_csum_good;
7728c2ecf20Sopenharmony_ci	u32 msg_enable;
7738c2ecf20Sopenharmony_ci	u16 imt;		/* interrupt moderator timer (2us resolution) */
7748c2ecf20Sopenharmony_ci	u16 ict;		/* interrupt clear timer (2us resolution */
7758c2ecf20Sopenharmony_ci	struct mii_if_info mii;	/* MII interface info */
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	/*
7788c2ecf20Sopenharmony_ci	 * Use this value to check is napi handler allowed to
7798c2ecf20Sopenharmony_ci	 * enable ints or not
7808c2ecf20Sopenharmony_ci	 */
7818c2ecf20Sopenharmony_ci	bool int_enabled;
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	u32 bd_number;		/* board number */
7848c2ecf20Sopenharmony_ci	bool pci_using_64;
7858c2ecf20Sopenharmony_ci	struct atl1_hw hw;
7868c2ecf20Sopenharmony_ci	struct atl1_smb smb;
7878c2ecf20Sopenharmony_ci	struct atl1_cmb cmb;
7888c2ecf20Sopenharmony_ci};
7898c2ecf20Sopenharmony_ci
7908c2ecf20Sopenharmony_ci#endif /* ATL1_H */
791