18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/* atl2.h -- atl2 driver definitions
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright(c) 2007 Atheros Corporation. All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright(c) 2006 xiong huang <xiong.huang@atheros.com>
68c2ecf20Sopenharmony_ci * Copyright(c) 2007 Chris Snook <csnook@redhat.com>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Derived from Intel e1000 driver
98c2ecf20Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef _ATL2_H_
138c2ecf20Sopenharmony_ci#define _ATL2_H_
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/atomic.h>
168c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef _ATL2_HW_H_
198c2ecf20Sopenharmony_ci#define _ATL2_HW_H_
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifndef _ATL2_OSDEP_H_
228c2ecf20Sopenharmony_ci#define _ATL2_OSDEP_H_
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <linux/pci.h>
258c2ecf20Sopenharmony_ci#include <linux/delay.h>
268c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
278c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include "atlx.h"
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#ifdef ETHTOOL_OPS_COMPAT
328c2ecf20Sopenharmony_ciint ethtool_ioctl(struct ifreq *ifr);
338c2ecf20Sopenharmony_ci#endif
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define PCI_COMMAND_REGISTER	PCI_COMMAND
368c2ecf20Sopenharmony_ci#define CMD_MEM_WRT_INVALIDATE	PCI_COMMAND_INVALIDATE
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define ATL2_WRITE_REG(a, reg, value) (iowrite32((value), \
398c2ecf20Sopenharmony_ci	((a)->hw_addr + (reg))))
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define ATL2_WRITE_FLUSH(a) (ioread32((a)->hw_addr))
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define ATL2_READ_REG(a, reg) (ioread32((a)->hw_addr + (reg)))
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define ATL2_WRITE_REGB(a, reg, value) (iowrite8((value), \
468c2ecf20Sopenharmony_ci	((a)->hw_addr + (reg))))
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define ATL2_READ_REGB(a, reg) (ioread8((a)->hw_addr + (reg)))
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define ATL2_WRITE_REGW(a, reg, value) (iowrite16((value), \
518c2ecf20Sopenharmony_ci	((a)->hw_addr + (reg))))
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define ATL2_READ_REGW(a, reg) (ioread16((a)->hw_addr + (reg)))
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define ATL2_WRITE_REG_ARRAY(a, reg, offset, value) \
568c2ecf20Sopenharmony_ci	(iowrite32((value), (((a)->hw_addr + (reg)) + ((offset) << 2))))
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define ATL2_READ_REG_ARRAY(a, reg, offset) \
598c2ecf20Sopenharmony_ci	(ioread32(((a)->hw_addr + (reg)) + ((offset) << 2)))
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#endif /* _ATL2_OSDEP_H_ */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct atl2_adapter;
648c2ecf20Sopenharmony_cistruct atl2_hw;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/* function prototype */
678c2ecf20Sopenharmony_cistatic s32 atl2_reset_hw(struct atl2_hw *hw);
688c2ecf20Sopenharmony_cistatic s32 atl2_read_mac_addr(struct atl2_hw *hw);
698c2ecf20Sopenharmony_cistatic s32 atl2_init_hw(struct atl2_hw *hw);
708c2ecf20Sopenharmony_cistatic s32 atl2_get_speed_and_duplex(struct atl2_hw *hw, u16 *speed,
718c2ecf20Sopenharmony_ci	u16 *duplex);
728c2ecf20Sopenharmony_cistatic u32 atl2_hash_mc_addr(struct atl2_hw *hw, u8 *mc_addr);
738c2ecf20Sopenharmony_cistatic void atl2_hash_set(struct atl2_hw *hw, u32 hash_value);
748c2ecf20Sopenharmony_cistatic s32 atl2_read_phy_reg(struct atl2_hw *hw, u16 reg_addr, u16 *phy_data);
758c2ecf20Sopenharmony_cistatic s32 atl2_write_phy_reg(struct atl2_hw *hw, u32 reg_addr, u16 phy_data);
768c2ecf20Sopenharmony_cistatic void atl2_read_pci_cfg(struct atl2_hw *hw, u32 reg, u16 *value);
778c2ecf20Sopenharmony_cistatic void atl2_write_pci_cfg(struct atl2_hw *hw, u32 reg, u16 *value);
788c2ecf20Sopenharmony_cistatic void atl2_set_mac_addr(struct atl2_hw *hw);
798c2ecf20Sopenharmony_cistatic bool atl2_read_eeprom(struct atl2_hw *hw, u32 Offset, u32 *pValue);
808c2ecf20Sopenharmony_cistatic bool atl2_write_eeprom(struct atl2_hw *hw, u32 offset, u32 value);
818c2ecf20Sopenharmony_cistatic s32 atl2_phy_init(struct atl2_hw *hw);
828c2ecf20Sopenharmony_cistatic int atl2_check_eeprom_exist(struct atl2_hw *hw);
838c2ecf20Sopenharmony_cistatic void atl2_force_ps(struct atl2_hw *hw);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* register definition */
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* Block IDLE Status Register */
888c2ecf20Sopenharmony_ci#define IDLE_STATUS_RXMAC	1	/* 1: RXMAC is non-IDLE */
898c2ecf20Sopenharmony_ci#define IDLE_STATUS_TXMAC	2	/* 1: TXMAC is non-IDLE */
908c2ecf20Sopenharmony_ci#define IDLE_STATUS_DMAR	8	/* 1: DMAR is non-IDLE */
918c2ecf20Sopenharmony_ci#define IDLE_STATUS_DMAW	4	/* 1: DMAW is non-IDLE */
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* MDIO Control Register */
948c2ecf20Sopenharmony_ci#define MDIO_WAIT_TIMES		10
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* MAC Control Register */
978c2ecf20Sopenharmony_ci#define MAC_CTRL_DBG_TX_BKPRESURE	0x100000	/* 1: TX max backoff */
988c2ecf20Sopenharmony_ci#define MAC_CTRL_MACLP_CLK_PHY		0x8000000	/* 1: 25MHz from phy */
998c2ecf20Sopenharmony_ci#define MAC_CTRL_HALF_LEFT_BUF_SHIFT	28
1008c2ecf20Sopenharmony_ci#define MAC_CTRL_HALF_LEFT_BUF_MASK	0xF		/* MAC retry buf x32B */
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* Internal SRAM Partition Register */
1038c2ecf20Sopenharmony_ci#define REG_SRAM_TXRAM_END	0x1500	/* Internal tail address of TXRAM
1048c2ecf20Sopenharmony_ci					 * default: 2byte*1024 */
1058c2ecf20Sopenharmony_ci#define REG_SRAM_RXRAM_END	0x1502	/* Internal tail address of RXRAM
1068c2ecf20Sopenharmony_ci					 * default: 2byte*1024 */
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* Descriptor Control register */
1098c2ecf20Sopenharmony_ci#define REG_TXD_BASE_ADDR_LO	0x1544	/* The base address of the Transmit
1108c2ecf20Sopenharmony_ci					 * Data Mem low 32-bit(dword align) */
1118c2ecf20Sopenharmony_ci#define REG_TXD_MEM_SIZE	0x1548	/* Transmit Data Memory size(by
1128c2ecf20Sopenharmony_ci					 * double word , max 256KB) */
1138c2ecf20Sopenharmony_ci#define REG_TXS_BASE_ADDR_LO	0x154C	/* The base address of the Transmit
1148c2ecf20Sopenharmony_ci					 * Status Memory low 32-bit(dword word
1158c2ecf20Sopenharmony_ci					 * align) */
1168c2ecf20Sopenharmony_ci#define REG_TXS_MEM_SIZE	0x1550	/* double word unit, max 4*2047
1178c2ecf20Sopenharmony_ci					 * bytes. */
1188c2ecf20Sopenharmony_ci#define REG_RXD_BASE_ADDR_LO	0x1554	/* The base address of the Transmit
1198c2ecf20Sopenharmony_ci					 * Status Memory low 32-bit(unit 8
1208c2ecf20Sopenharmony_ci					 * bytes) */
1218c2ecf20Sopenharmony_ci#define REG_RXD_BUF_NUM		0x1558	/* Receive Data & Status Memory buffer
1228c2ecf20Sopenharmony_ci					 * number (unit 1536bytes, max
1238c2ecf20Sopenharmony_ci					 * 1536*2047) */
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/* DMAR Control Register */
1268c2ecf20Sopenharmony_ci#define REG_DMAR	0x1580
1278c2ecf20Sopenharmony_ci#define     DMAR_EN	0x1	/* 1: Enable DMAR */
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* TX Cur-Through (early tx threshold) Control Register */
1308c2ecf20Sopenharmony_ci#define REG_TX_CUT_THRESH	0x1590	/* TxMac begin transmit packet
1318c2ecf20Sopenharmony_ci					 * threshold(unit word) */
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/* DMAW Control Register */
1348c2ecf20Sopenharmony_ci#define REG_DMAW	0x15A0
1358c2ecf20Sopenharmony_ci#define     DMAW_EN	0x1
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/* Flow control register */
1388c2ecf20Sopenharmony_ci#define REG_PAUSE_ON_TH		0x15A8	/* RXD high watermark of overflow
1398c2ecf20Sopenharmony_ci					 * threshold configuration register */
1408c2ecf20Sopenharmony_ci#define REG_PAUSE_OFF_TH	0x15AA	/* RXD lower watermark of overflow
1418c2ecf20Sopenharmony_ci					 * threshold configuration register */
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/* Mailbox Register */
1448c2ecf20Sopenharmony_ci#define REG_MB_TXD_WR_IDX	0x15f0	/* double word align */
1458c2ecf20Sopenharmony_ci#define REG_MB_RXD_RD_IDX	0x15F4	/* RXD Read index (unit: 1536byets) */
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* Interrupt Status Register */
1488c2ecf20Sopenharmony_ci#define ISR_TIMER	1	/* Interrupt when Timer counts down to zero */
1498c2ecf20Sopenharmony_ci#define ISR_MANUAL	2	/* Software manual interrupt, for debug. Set
1508c2ecf20Sopenharmony_ci				 * when SW_MAN_INT_EN is set in Table 51
1518c2ecf20Sopenharmony_ci				 * Selene Master Control Register
1528c2ecf20Sopenharmony_ci				 * (Offset 0x1400). */
1538c2ecf20Sopenharmony_ci#define ISR_RXF_OV	4	/* RXF overflow interrupt */
1548c2ecf20Sopenharmony_ci#define ISR_TXF_UR	8	/* TXF underrun interrupt */
1558c2ecf20Sopenharmony_ci#define ISR_TXS_OV	0x10	/* Internal transmit status buffer full
1568c2ecf20Sopenharmony_ci				 * interrupt */
1578c2ecf20Sopenharmony_ci#define ISR_RXS_OV	0x20	/* Internal receive status buffer full
1588c2ecf20Sopenharmony_ci				 * interrupt */
1598c2ecf20Sopenharmony_ci#define ISR_LINK_CHG	0x40	/* Link Status Change Interrupt */
1608c2ecf20Sopenharmony_ci#define ISR_HOST_TXD_UR	0x80
1618c2ecf20Sopenharmony_ci#define ISR_HOST_RXD_OV	0x100	/* Host rx data memory full , one pulse */
1628c2ecf20Sopenharmony_ci#define ISR_DMAR_TO_RST	0x200	/* DMAR op timeout interrupt. SW should
1638c2ecf20Sopenharmony_ci				 * do Reset */
1648c2ecf20Sopenharmony_ci#define ISR_DMAW_TO_RST	0x400
1658c2ecf20Sopenharmony_ci#define ISR_PHY		0x800	/* phy interrupt */
1668c2ecf20Sopenharmony_ci#define ISR_TS_UPDATE	0x10000	/* interrupt after new tx pkt status written
1678c2ecf20Sopenharmony_ci				 * to host */
1688c2ecf20Sopenharmony_ci#define ISR_RS_UPDATE	0x20000	/* interrupt ater new rx pkt status written
1698c2ecf20Sopenharmony_ci				 * to host. */
1708c2ecf20Sopenharmony_ci#define ISR_TX_EARLY	0x40000	/* interrupt when txmac begin transmit one
1718c2ecf20Sopenharmony_ci				 * packet */
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define ISR_TX_EVENT (ISR_TXF_UR | ISR_TXS_OV | ISR_HOST_TXD_UR |\
1748c2ecf20Sopenharmony_ci	ISR_TS_UPDATE | ISR_TX_EARLY)
1758c2ecf20Sopenharmony_ci#define ISR_RX_EVENT (ISR_RXF_OV | ISR_RXS_OV | ISR_HOST_RXD_OV |\
1768c2ecf20Sopenharmony_ci	 ISR_RS_UPDATE)
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#define IMR_NORMAL_MASK		(\
1798c2ecf20Sopenharmony_ci	/*ISR_LINK_CHG		|*/\
1808c2ecf20Sopenharmony_ci	ISR_MANUAL		|\
1818c2ecf20Sopenharmony_ci	ISR_DMAR_TO_RST		|\
1828c2ecf20Sopenharmony_ci	ISR_DMAW_TO_RST		|\
1838c2ecf20Sopenharmony_ci	ISR_PHY			|\
1848c2ecf20Sopenharmony_ci	ISR_PHY_LINKDOWN	|\
1858c2ecf20Sopenharmony_ci	ISR_TS_UPDATE		|\
1868c2ecf20Sopenharmony_ci	ISR_RS_UPDATE)
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* Receive MAC Statistics Registers */
1898c2ecf20Sopenharmony_ci#define REG_STS_RX_PAUSE	0x1700	/* Num pause packets received */
1908c2ecf20Sopenharmony_ci#define REG_STS_RXD_OV		0x1704	/* Num frames dropped due to RX
1918c2ecf20Sopenharmony_ci					 * FIFO overflow */
1928c2ecf20Sopenharmony_ci#define REG_STS_RXS_OV		0x1708	/* Num frames dropped due to RX
1938c2ecf20Sopenharmony_ci					 * Status Buffer Overflow */
1948c2ecf20Sopenharmony_ci#define REG_STS_RX_FILTER	0x170C	/* Num packets dropped due to
1958c2ecf20Sopenharmony_ci					 * address filtering */
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/* MII definitions */
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* PHY Common Register */
2008c2ecf20Sopenharmony_ci#define MII_SMARTSPEED	0x14
2018c2ecf20Sopenharmony_ci#define MII_DBG_ADDR	0x1D
2028c2ecf20Sopenharmony_ci#define MII_DBG_DATA	0x1E
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* PCI Command Register Bit Definitions */
2058c2ecf20Sopenharmony_ci#define PCI_REG_COMMAND		0x04
2068c2ecf20Sopenharmony_ci#define CMD_IO_SPACE		0x0001
2078c2ecf20Sopenharmony_ci#define CMD_MEMORY_SPACE	0x0002
2088c2ecf20Sopenharmony_ci#define CMD_BUS_MASTER		0x0004
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci#define MEDIA_TYPE_100M_FULL	1
2118c2ecf20Sopenharmony_ci#define MEDIA_TYPE_100M_HALF	2
2128c2ecf20Sopenharmony_ci#define MEDIA_TYPE_10M_FULL	3
2138c2ecf20Sopenharmony_ci#define MEDIA_TYPE_10M_HALF	4
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci#define AUTONEG_ADVERTISE_SPEED_DEFAULT	0x000F	/* Everything */
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/* The size (in bytes) of a ethernet packet */
2188c2ecf20Sopenharmony_ci#define MAXIMUM_ETHERNET_FRAME_SIZE	1518	/* with FCS */
2198c2ecf20Sopenharmony_ci#define MINIMUM_ETHERNET_FRAME_SIZE	64	/* with FCS */
2208c2ecf20Sopenharmony_ci#define MAX_JUMBO_FRAME_SIZE		0x2000
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistruct tx_pkt_header {
2238c2ecf20Sopenharmony_ci	unsigned pkt_size:11;
2248c2ecf20Sopenharmony_ci	unsigned:4;			/* reserved */
2258c2ecf20Sopenharmony_ci	unsigned ins_vlan:1;		/* txmac should insert vlan */
2268c2ecf20Sopenharmony_ci	unsigned short vlan;		/* vlan tag */
2278c2ecf20Sopenharmony_ci};
2288c2ecf20Sopenharmony_ci/* FIXME: replace above bitfields with MASK/SHIFT defines below */
2298c2ecf20Sopenharmony_ci#define TX_PKT_HEADER_SIZE_MASK		0x7FF
2308c2ecf20Sopenharmony_ci#define TX_PKT_HEADER_SIZE_SHIFT	0
2318c2ecf20Sopenharmony_ci#define TX_PKT_HEADER_INS_VLAN_MASK	0x1
2328c2ecf20Sopenharmony_ci#define TX_PKT_HEADER_INS_VLAN_SHIFT	15
2338c2ecf20Sopenharmony_ci#define TX_PKT_HEADER_VLAN_TAG_MASK	0xFFFF
2348c2ecf20Sopenharmony_ci#define TX_PKT_HEADER_VLAN_TAG_SHIFT	16
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_cistruct tx_pkt_status {
2378c2ecf20Sopenharmony_ci	unsigned pkt_size:11;
2388c2ecf20Sopenharmony_ci	unsigned:5;		/* reserved */
2398c2ecf20Sopenharmony_ci	unsigned ok:1;		/* current packet transmitted without error */
2408c2ecf20Sopenharmony_ci	unsigned bcast:1;	/* broadcast packet */
2418c2ecf20Sopenharmony_ci	unsigned mcast:1;	/* multicast packet */
2428c2ecf20Sopenharmony_ci	unsigned pause:1;	/* transmiited a pause frame */
2438c2ecf20Sopenharmony_ci	unsigned ctrl:1;
2448c2ecf20Sopenharmony_ci	unsigned defer:1;    	/* current packet is xmitted with defer */
2458c2ecf20Sopenharmony_ci	unsigned exc_defer:1;
2468c2ecf20Sopenharmony_ci	unsigned single_col:1;
2478c2ecf20Sopenharmony_ci	unsigned multi_col:1;
2488c2ecf20Sopenharmony_ci	unsigned late_col:1;
2498c2ecf20Sopenharmony_ci	unsigned abort_col:1;
2508c2ecf20Sopenharmony_ci	unsigned underrun:1;	/* current packet is aborted
2518c2ecf20Sopenharmony_ci				 * due to txram underrun */
2528c2ecf20Sopenharmony_ci	unsigned:3;		/* reserved */
2538c2ecf20Sopenharmony_ci	unsigned update:1;	/* always 1'b1 in tx_status_buf */
2548c2ecf20Sopenharmony_ci};
2558c2ecf20Sopenharmony_ci/* FIXME: replace above bitfields with MASK/SHIFT defines below */
2568c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_SIZE_MASK		0x7FF
2578c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_SIZE_SHIFT	0
2588c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_OK_MASK		0x1
2598c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_OK_SHIFT		16
2608c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_BCAST_MASK	0x1
2618c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_BCAST_SHIFT	17
2628c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_MCAST_MASK	0x1
2638c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_MCAST_SHIFT	18
2648c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_PAUSE_MASK	0x1
2658c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_PAUSE_SHIFT	19
2668c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_CTRL_MASK		0x1
2678c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_CTRL_SHIFT	20
2688c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_DEFER_MASK	0x1
2698c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_DEFER_SHIFT	21
2708c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_EXC_DEFER_MASK	0x1
2718c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_EXC_DEFER_SHIFT	22
2728c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_SINGLE_COL_MASK	0x1
2738c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_SINGLE_COL_SHIFT	23
2748c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_MULTI_COL_MASK	0x1
2758c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_MULTI_COL_SHIFT	24
2768c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_LATE_COL_MASK	0x1
2778c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_LATE_COL_SHIFT	25
2788c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_ABORT_COL_MASK	0x1
2798c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_ABORT_COL_SHIFT	26
2808c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_UNDERRUN_MASK	0x1
2818c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_UNDERRUN_SHIFT	27
2828c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_UPDATE_MASK	0x1
2838c2ecf20Sopenharmony_ci#define TX_PKT_STATUS_UPDATE_SHIFT	31
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_cistruct rx_pkt_status {
2868c2ecf20Sopenharmony_ci	unsigned pkt_size:11;	/* packet size, max 2047 bytes */
2878c2ecf20Sopenharmony_ci	unsigned:5;		/* reserved */
2888c2ecf20Sopenharmony_ci	unsigned ok:1;		/* current packet received ok without error */
2898c2ecf20Sopenharmony_ci	unsigned bcast:1;	/* current packet is broadcast */
2908c2ecf20Sopenharmony_ci	unsigned mcast:1;	/* current packet is multicast */
2918c2ecf20Sopenharmony_ci	unsigned pause:1;
2928c2ecf20Sopenharmony_ci	unsigned ctrl:1;
2938c2ecf20Sopenharmony_ci	unsigned crc:1;		/* received a packet with crc error */
2948c2ecf20Sopenharmony_ci	unsigned code:1;	/* received a packet with code error */
2958c2ecf20Sopenharmony_ci	unsigned runt:1;	/* received a packet less than 64 bytes
2968c2ecf20Sopenharmony_ci				 * with good crc */
2978c2ecf20Sopenharmony_ci	unsigned frag:1;	/* received a packet less than 64 bytes
2988c2ecf20Sopenharmony_ci				 * with bad crc */
2998c2ecf20Sopenharmony_ci	unsigned trunc:1;	/* current frame truncated due to rxram full */
3008c2ecf20Sopenharmony_ci	unsigned align:1;	/* this packet is alignment error */
3018c2ecf20Sopenharmony_ci	unsigned vlan:1;	/* this packet has vlan */
3028c2ecf20Sopenharmony_ci	unsigned:3;		/* reserved */
3038c2ecf20Sopenharmony_ci	unsigned update:1;
3048c2ecf20Sopenharmony_ci	unsigned short vtag;	/* vlan tag */
3058c2ecf20Sopenharmony_ci	unsigned:16;
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci/* FIXME: replace above bitfields with MASK/SHIFT defines below */
3088c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_SIZE_MASK		0x7FF
3098c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_SIZE_SHIFT	0
3108c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_OK_MASK		0x1
3118c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_OK_SHIFT		16
3128c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_BCAST_MASK	0x1
3138c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_BCAST_SHIFT	17
3148c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_MCAST_MASK	0x1
3158c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_MCAST_SHIFT	18
3168c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_PAUSE_MASK	0x1
3178c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_PAUSE_SHIFT	19
3188c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_CTRL_MASK		0x1
3198c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_CTRL_SHIFT	20
3208c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_CRC_MASK		0x1
3218c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_CRC_SHIFT		21
3228c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_CODE_MASK		0x1
3238c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_CODE_SHIFT	22
3248c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_RUNT_MASK		0x1
3258c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_RUNT_SHIFT	23
3268c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_FRAG_MASK		0x1
3278c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_FRAG_SHIFT	24
3288c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_TRUNK_MASK	0x1
3298c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_TRUNK_SHIFT	25
3308c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_ALIGN_MASK	0x1
3318c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_ALIGN_SHIFT	26
3328c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_VLAN_MASK		0x1
3338c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_VLAN_SHIFT	27
3348c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_UPDATE_MASK	0x1
3358c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_UPDATE_SHIFT	31
3368c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_VLAN_TAG_MASK	0xFFFF
3378c2ecf20Sopenharmony_ci#define RX_PKT_STATUS_VLAN_TAG_SHIFT	32
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cistruct rx_desc {
3408c2ecf20Sopenharmony_ci	struct rx_pkt_status	status;
3418c2ecf20Sopenharmony_ci	unsigned char     	packet[1536-sizeof(struct rx_pkt_status)];
3428c2ecf20Sopenharmony_ci};
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_cienum atl2_speed_duplex {
3458c2ecf20Sopenharmony_ci	atl2_10_half = 0,
3468c2ecf20Sopenharmony_ci	atl2_10_full = 1,
3478c2ecf20Sopenharmony_ci	atl2_100_half = 2,
3488c2ecf20Sopenharmony_ci	atl2_100_full = 3
3498c2ecf20Sopenharmony_ci};
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cistruct atl2_spi_flash_dev {
3528c2ecf20Sopenharmony_ci	const char *manu_name;	/* manufacturer id */
3538c2ecf20Sopenharmony_ci	/* op-code */
3548c2ecf20Sopenharmony_ci	u8 cmdWRSR;
3558c2ecf20Sopenharmony_ci	u8 cmdREAD;
3568c2ecf20Sopenharmony_ci	u8 cmdPROGRAM;
3578c2ecf20Sopenharmony_ci	u8 cmdWREN;
3588c2ecf20Sopenharmony_ci	u8 cmdWRDI;
3598c2ecf20Sopenharmony_ci	u8 cmdRDSR;
3608c2ecf20Sopenharmony_ci	u8 cmdRDID;
3618c2ecf20Sopenharmony_ci	u8 cmdSECTOR_ERASE;
3628c2ecf20Sopenharmony_ci	u8 cmdCHIP_ERASE;
3638c2ecf20Sopenharmony_ci};
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci/* Structure containing variables used by the shared code (atl2_hw.c) */
3668c2ecf20Sopenharmony_cistruct atl2_hw {
3678c2ecf20Sopenharmony_ci	u8 __iomem *hw_addr;
3688c2ecf20Sopenharmony_ci	void *back;
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	u8 preamble_len;
3718c2ecf20Sopenharmony_ci	u8 max_retry;          /* Retransmission maximum, afterwards the
3728c2ecf20Sopenharmony_ci				* packet will be discarded. */
3738c2ecf20Sopenharmony_ci	u8 jam_ipg;            /* IPG to start JAM for collision based flow
3748c2ecf20Sopenharmony_ci				* control in half-duplex mode. In unit of
3758c2ecf20Sopenharmony_ci				* 8-bit time. */
3768c2ecf20Sopenharmony_ci	u8 ipgt;               /* Desired back to back inter-packet gap. The
3778c2ecf20Sopenharmony_ci				* default is 96-bit time. */
3788c2ecf20Sopenharmony_ci	u8 min_ifg;            /* Minimum number of IFG to enforce in between
3798c2ecf20Sopenharmony_ci				* RX frames. Frame gap below such IFP is
3808c2ecf20Sopenharmony_ci				* dropped. */
3818c2ecf20Sopenharmony_ci	u8 ipgr1;              /* 64bit Carrier-Sense window */
3828c2ecf20Sopenharmony_ci	u8 ipgr2;              /* 96-bit IPG window */
3838c2ecf20Sopenharmony_ci	u8 retry_buf;          /* When half-duplex mode, should hold some
3848c2ecf20Sopenharmony_ci				* bytes for mac retry . (8*4bytes unit) */
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	u16 fc_rxd_hi;
3878c2ecf20Sopenharmony_ci	u16 fc_rxd_lo;
3888c2ecf20Sopenharmony_ci	u16 lcol;              /* Collision Window */
3898c2ecf20Sopenharmony_ci	u16 max_frame_size;
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	u16 MediaType;
3928c2ecf20Sopenharmony_ci	u16 autoneg_advertised;
3938c2ecf20Sopenharmony_ci	u16 pci_cmd_word;
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	u16 mii_autoneg_adv_reg;
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	u32 mem_rang;
3988c2ecf20Sopenharmony_ci	u32 txcw;
3998c2ecf20Sopenharmony_ci	u32 mc_filter_type;
4008c2ecf20Sopenharmony_ci	u32 num_mc_addrs;
4018c2ecf20Sopenharmony_ci	u32 collision_delta;
4028c2ecf20Sopenharmony_ci	u32 tx_packet_delta;
4038c2ecf20Sopenharmony_ci	u16 phy_spd_default;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	u16 device_id;
4068c2ecf20Sopenharmony_ci	u16 vendor_id;
4078c2ecf20Sopenharmony_ci	u16 subsystem_id;
4088c2ecf20Sopenharmony_ci	u16 subsystem_vendor_id;
4098c2ecf20Sopenharmony_ci	u8 revision_id;
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	/* spi flash */
4128c2ecf20Sopenharmony_ci	u8 flash_vendor;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	u8 dma_fairness;
4158c2ecf20Sopenharmony_ci	u8 mac_addr[ETH_ALEN];
4168c2ecf20Sopenharmony_ci	u8 perm_mac_addr[ETH_ALEN];
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	/* FIXME */
4198c2ecf20Sopenharmony_ci	/* bool phy_preamble_sup; */
4208c2ecf20Sopenharmony_ci	bool phy_configured;
4218c2ecf20Sopenharmony_ci};
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci#endif /* _ATL2_HW_H_ */
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistruct atl2_ring_header {
4268c2ecf20Sopenharmony_ci    /* pointer to the descriptor ring memory */
4278c2ecf20Sopenharmony_ci    void *desc;
4288c2ecf20Sopenharmony_ci    /* physical address of the descriptor ring */
4298c2ecf20Sopenharmony_ci    dma_addr_t dma;
4308c2ecf20Sopenharmony_ci    /* length of descriptor ring in bytes */
4318c2ecf20Sopenharmony_ci    unsigned int size;
4328c2ecf20Sopenharmony_ci};
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci/* board specific private data structure */
4358c2ecf20Sopenharmony_cistruct atl2_adapter {
4368c2ecf20Sopenharmony_ci	/* OS defined structs */
4378c2ecf20Sopenharmony_ci	struct net_device *netdev;
4388c2ecf20Sopenharmony_ci	struct pci_dev *pdev;
4398c2ecf20Sopenharmony_ci	u32 wol;
4408c2ecf20Sopenharmony_ci	u16 link_speed;
4418c2ecf20Sopenharmony_ci	u16 link_duplex;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	spinlock_t stats_lock;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	struct work_struct reset_task;
4468c2ecf20Sopenharmony_ci	struct work_struct link_chg_task;
4478c2ecf20Sopenharmony_ci	struct timer_list watchdog_timer;
4488c2ecf20Sopenharmony_ci	struct timer_list phy_config_timer;
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci	unsigned long cfg_phy;
4518c2ecf20Sopenharmony_ci	bool mac_disabled;
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	/* All Descriptor memory */
4548c2ecf20Sopenharmony_ci	dma_addr_t	ring_dma;
4558c2ecf20Sopenharmony_ci	void		*ring_vir_addr;
4568c2ecf20Sopenharmony_ci	int		ring_size;
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci	struct tx_pkt_header	*txd_ring;
4598c2ecf20Sopenharmony_ci	dma_addr_t	txd_dma;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	struct tx_pkt_status	*txs_ring;
4628c2ecf20Sopenharmony_ci	dma_addr_t	txs_dma;
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	struct rx_desc	*rxd_ring;
4658c2ecf20Sopenharmony_ci	dma_addr_t	rxd_dma;
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	u32 txd_ring_size;         /* bytes per unit */
4688c2ecf20Sopenharmony_ci	u32 txs_ring_size;         /* dwords per unit */
4698c2ecf20Sopenharmony_ci	u32 rxd_ring_size;         /* 1536 bytes per unit */
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	/* read /write ptr: */
4728c2ecf20Sopenharmony_ci	/* host */
4738c2ecf20Sopenharmony_ci	u32 txd_write_ptr;
4748c2ecf20Sopenharmony_ci	u32 txs_next_clear;
4758c2ecf20Sopenharmony_ci	u32 rxd_read_ptr;
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	/* nic */
4788c2ecf20Sopenharmony_ci	atomic_t txd_read_ptr;
4798c2ecf20Sopenharmony_ci	atomic_t txs_write_ptr;
4808c2ecf20Sopenharmony_ci	u32 rxd_write_ptr;
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	/* Interrupt Moderator timer ( 2us resolution) */
4838c2ecf20Sopenharmony_ci	u16 imt;
4848c2ecf20Sopenharmony_ci	/* Interrupt Clear timer (2us resolution) */
4858c2ecf20Sopenharmony_ci	u16 ict;
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci	unsigned long flags;
4888c2ecf20Sopenharmony_ci	/* structs defined in atl2_hw.h */
4898c2ecf20Sopenharmony_ci	u32 bd_number;     /* board number */
4908c2ecf20Sopenharmony_ci	bool pci_using_64;
4918c2ecf20Sopenharmony_ci	bool have_msi;
4928c2ecf20Sopenharmony_ci	struct atl2_hw hw;
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	u32 usr_cmd;
4958c2ecf20Sopenharmony_ci	/* FIXME */
4968c2ecf20Sopenharmony_ci	/* u32 regs_buff[ATL2_REGS_LEN]; */
4978c2ecf20Sopenharmony_ci	u32 pci_state[16];
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci	u32 *config_space;
5008c2ecf20Sopenharmony_ci};
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_cienum atl2_state_t {
5038c2ecf20Sopenharmony_ci	__ATL2_TESTING,
5048c2ecf20Sopenharmony_ci	__ATL2_RESETTING,
5058c2ecf20Sopenharmony_ci	__ATL2_DOWN
5068c2ecf20Sopenharmony_ci};
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci#endif /* _ATL2_H_ */
509