162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* atl2.h -- atl2 driver definitions 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright(c) 2007 Atheros Corporation. All rights reserved. 562306a36Sopenharmony_ci * Copyright(c) 2006 xiong huang <xiong.huang@atheros.com> 662306a36Sopenharmony_ci * Copyright(c) 2007 Chris Snook <csnook@redhat.com> 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Derived from Intel e1000 driver 962306a36Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifndef _ATL2_H_ 1362306a36Sopenharmony_ci#define _ATL2_H_ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/atomic.h> 1662306a36Sopenharmony_ci#include <linux/netdevice.h> 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#ifndef _ATL2_HW_H_ 1962306a36Sopenharmony_ci#define _ATL2_HW_H_ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#ifndef _ATL2_OSDEP_H_ 2262306a36Sopenharmony_ci#define _ATL2_OSDEP_H_ 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#include <linux/pci.h> 2562306a36Sopenharmony_ci#include <linux/delay.h> 2662306a36Sopenharmony_ci#include <linux/interrupt.h> 2762306a36Sopenharmony_ci#include <linux/if_ether.h> 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#include "atlx.h" 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#ifdef ETHTOOL_OPS_COMPAT 3262306a36Sopenharmony_ciint ethtool_ioctl(struct ifreq *ifr); 3362306a36Sopenharmony_ci#endif 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define PCI_COMMAND_REGISTER PCI_COMMAND 3662306a36Sopenharmony_ci#define CMD_MEM_WRT_INVALIDATE PCI_COMMAND_INVALIDATE 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define ATL2_WRITE_REG(a, reg, value) (iowrite32((value), \ 3962306a36Sopenharmony_ci ((a)->hw_addr + (reg)))) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define ATL2_WRITE_FLUSH(a) (ioread32((a)->hw_addr)) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define ATL2_READ_REG(a, reg) (ioread32((a)->hw_addr + (reg))) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define ATL2_WRITE_REGB(a, reg, value) (iowrite8((value), \ 4662306a36Sopenharmony_ci ((a)->hw_addr + (reg)))) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#define ATL2_READ_REGB(a, reg) (ioread8((a)->hw_addr + (reg))) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define ATL2_WRITE_REGW(a, reg, value) (iowrite16((value), \ 5162306a36Sopenharmony_ci ((a)->hw_addr + (reg)))) 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define ATL2_READ_REGW(a, reg) (ioread16((a)->hw_addr + (reg))) 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci#define ATL2_WRITE_REG_ARRAY(a, reg, offset, value) \ 5662306a36Sopenharmony_ci (iowrite32((value), (((a)->hw_addr + (reg)) + ((offset) << 2)))) 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define ATL2_READ_REG_ARRAY(a, reg, offset) \ 5962306a36Sopenharmony_ci (ioread32(((a)->hw_addr + (reg)) + ((offset) << 2))) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci#endif /* _ATL2_OSDEP_H_ */ 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistruct atl2_adapter; 6462306a36Sopenharmony_cistruct atl2_hw; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* function prototype */ 6762306a36Sopenharmony_cistatic s32 atl2_reset_hw(struct atl2_hw *hw); 6862306a36Sopenharmony_cistatic s32 atl2_read_mac_addr(struct atl2_hw *hw); 6962306a36Sopenharmony_cistatic s32 atl2_init_hw(struct atl2_hw *hw); 7062306a36Sopenharmony_cistatic s32 atl2_get_speed_and_duplex(struct atl2_hw *hw, u16 *speed, 7162306a36Sopenharmony_ci u16 *duplex); 7262306a36Sopenharmony_cistatic u32 atl2_hash_mc_addr(struct atl2_hw *hw, u8 *mc_addr); 7362306a36Sopenharmony_cistatic void atl2_hash_set(struct atl2_hw *hw, u32 hash_value); 7462306a36Sopenharmony_cistatic s32 atl2_read_phy_reg(struct atl2_hw *hw, u16 reg_addr, u16 *phy_data); 7562306a36Sopenharmony_cistatic s32 atl2_write_phy_reg(struct atl2_hw *hw, u32 reg_addr, u16 phy_data); 7662306a36Sopenharmony_cistatic void atl2_read_pci_cfg(struct atl2_hw *hw, u32 reg, u16 *value); 7762306a36Sopenharmony_cistatic void atl2_write_pci_cfg(struct atl2_hw *hw, u32 reg, u16 *value); 7862306a36Sopenharmony_cistatic void atl2_set_mac_addr(struct atl2_hw *hw); 7962306a36Sopenharmony_cistatic bool atl2_read_eeprom(struct atl2_hw *hw, u32 Offset, u32 *pValue); 8062306a36Sopenharmony_cistatic bool atl2_write_eeprom(struct atl2_hw *hw, u32 offset, u32 value); 8162306a36Sopenharmony_cistatic s32 atl2_phy_init(struct atl2_hw *hw); 8262306a36Sopenharmony_cistatic int atl2_check_eeprom_exist(struct atl2_hw *hw); 8362306a36Sopenharmony_cistatic void atl2_force_ps(struct atl2_hw *hw); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* register definition */ 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* Block IDLE Status Register */ 8862306a36Sopenharmony_ci#define IDLE_STATUS_RXMAC 1 /* 1: RXMAC is non-IDLE */ 8962306a36Sopenharmony_ci#define IDLE_STATUS_TXMAC 2 /* 1: TXMAC is non-IDLE */ 9062306a36Sopenharmony_ci#define IDLE_STATUS_DMAR 8 /* 1: DMAR is non-IDLE */ 9162306a36Sopenharmony_ci#define IDLE_STATUS_DMAW 4 /* 1: DMAW is non-IDLE */ 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/* MDIO Control Register */ 9462306a36Sopenharmony_ci#define MDIO_WAIT_TIMES 10 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/* MAC Control Register */ 9762306a36Sopenharmony_ci#define MAC_CTRL_DBG_TX_BKPRESURE 0x100000 /* 1: TX max backoff */ 9862306a36Sopenharmony_ci#define MAC_CTRL_MACLP_CLK_PHY 0x8000000 /* 1: 25MHz from phy */ 9962306a36Sopenharmony_ci#define MAC_CTRL_HALF_LEFT_BUF_SHIFT 28 10062306a36Sopenharmony_ci#define MAC_CTRL_HALF_LEFT_BUF_MASK 0xF /* MAC retry buf x32B */ 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci/* Internal SRAM Partition Register */ 10362306a36Sopenharmony_ci#define REG_SRAM_TXRAM_END 0x1500 /* Internal tail address of TXRAM 10462306a36Sopenharmony_ci * default: 2byte*1024 */ 10562306a36Sopenharmony_ci#define REG_SRAM_RXRAM_END 0x1502 /* Internal tail address of RXRAM 10662306a36Sopenharmony_ci * default: 2byte*1024 */ 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci/* Descriptor Control register */ 10962306a36Sopenharmony_ci#define REG_TXD_BASE_ADDR_LO 0x1544 /* The base address of the Transmit 11062306a36Sopenharmony_ci * Data Mem low 32-bit(dword align) */ 11162306a36Sopenharmony_ci#define REG_TXD_MEM_SIZE 0x1548 /* Transmit Data Memory size(by 11262306a36Sopenharmony_ci * double word , max 256KB) */ 11362306a36Sopenharmony_ci#define REG_TXS_BASE_ADDR_LO 0x154C /* The base address of the Transmit 11462306a36Sopenharmony_ci * Status Memory low 32-bit(dword word 11562306a36Sopenharmony_ci * align) */ 11662306a36Sopenharmony_ci#define REG_TXS_MEM_SIZE 0x1550 /* double word unit, max 4*2047 11762306a36Sopenharmony_ci * bytes. */ 11862306a36Sopenharmony_ci#define REG_RXD_BASE_ADDR_LO 0x1554 /* The base address of the Transmit 11962306a36Sopenharmony_ci * Status Memory low 32-bit(unit 8 12062306a36Sopenharmony_ci * bytes) */ 12162306a36Sopenharmony_ci#define REG_RXD_BUF_NUM 0x1558 /* Receive Data & Status Memory buffer 12262306a36Sopenharmony_ci * number (unit 1536bytes, max 12362306a36Sopenharmony_ci * 1536*2047) */ 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* DMAR Control Register */ 12662306a36Sopenharmony_ci#define REG_DMAR 0x1580 12762306a36Sopenharmony_ci#define DMAR_EN 0x1 /* 1: Enable DMAR */ 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci/* TX Cur-Through (early tx threshold) Control Register */ 13062306a36Sopenharmony_ci#define REG_TX_CUT_THRESH 0x1590 /* TxMac begin transmit packet 13162306a36Sopenharmony_ci * threshold(unit word) */ 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci/* DMAW Control Register */ 13462306a36Sopenharmony_ci#define REG_DMAW 0x15A0 13562306a36Sopenharmony_ci#define DMAW_EN 0x1 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci/* Flow control register */ 13862306a36Sopenharmony_ci#define REG_PAUSE_ON_TH 0x15A8 /* RXD high watermark of overflow 13962306a36Sopenharmony_ci * threshold configuration register */ 14062306a36Sopenharmony_ci#define REG_PAUSE_OFF_TH 0x15AA /* RXD lower watermark of overflow 14162306a36Sopenharmony_ci * threshold configuration register */ 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci/* Mailbox Register */ 14462306a36Sopenharmony_ci#define REG_MB_TXD_WR_IDX 0x15f0 /* double word align */ 14562306a36Sopenharmony_ci#define REG_MB_RXD_RD_IDX 0x15F4 /* RXD Read index (unit: 1536byets) */ 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci/* Interrupt Status Register */ 14862306a36Sopenharmony_ci#define ISR_TIMER 1 /* Interrupt when Timer counts down to zero */ 14962306a36Sopenharmony_ci#define ISR_MANUAL 2 /* Software manual interrupt, for debug. Set 15062306a36Sopenharmony_ci * when SW_MAN_INT_EN is set in Table 51 15162306a36Sopenharmony_ci * Selene Master Control Register 15262306a36Sopenharmony_ci * (Offset 0x1400). */ 15362306a36Sopenharmony_ci#define ISR_RXF_OV 4 /* RXF overflow interrupt */ 15462306a36Sopenharmony_ci#define ISR_TXF_UR 8 /* TXF underrun interrupt */ 15562306a36Sopenharmony_ci#define ISR_TXS_OV 0x10 /* Internal transmit status buffer full 15662306a36Sopenharmony_ci * interrupt */ 15762306a36Sopenharmony_ci#define ISR_RXS_OV 0x20 /* Internal receive status buffer full 15862306a36Sopenharmony_ci * interrupt */ 15962306a36Sopenharmony_ci#define ISR_LINK_CHG 0x40 /* Link Status Change Interrupt */ 16062306a36Sopenharmony_ci#define ISR_HOST_TXD_UR 0x80 16162306a36Sopenharmony_ci#define ISR_HOST_RXD_OV 0x100 /* Host rx data memory full , one pulse */ 16262306a36Sopenharmony_ci#define ISR_DMAR_TO_RST 0x200 /* DMAR op timeout interrupt. SW should 16362306a36Sopenharmony_ci * do Reset */ 16462306a36Sopenharmony_ci#define ISR_DMAW_TO_RST 0x400 16562306a36Sopenharmony_ci#define ISR_PHY 0x800 /* phy interrupt */ 16662306a36Sopenharmony_ci#define ISR_TS_UPDATE 0x10000 /* interrupt after new tx pkt status written 16762306a36Sopenharmony_ci * to host */ 16862306a36Sopenharmony_ci#define ISR_RS_UPDATE 0x20000 /* interrupt ater new rx pkt status written 16962306a36Sopenharmony_ci * to host. */ 17062306a36Sopenharmony_ci#define ISR_TX_EARLY 0x40000 /* interrupt when txmac begin transmit one 17162306a36Sopenharmony_ci * packet */ 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci#define ISR_TX_EVENT (ISR_TXF_UR | ISR_TXS_OV | ISR_HOST_TXD_UR |\ 17462306a36Sopenharmony_ci ISR_TS_UPDATE | ISR_TX_EARLY) 17562306a36Sopenharmony_ci#define ISR_RX_EVENT (ISR_RXF_OV | ISR_RXS_OV | ISR_HOST_RXD_OV |\ 17662306a36Sopenharmony_ci ISR_RS_UPDATE) 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#define IMR_NORMAL_MASK (\ 17962306a36Sopenharmony_ci /*ISR_LINK_CHG |*/\ 18062306a36Sopenharmony_ci ISR_MANUAL |\ 18162306a36Sopenharmony_ci ISR_DMAR_TO_RST |\ 18262306a36Sopenharmony_ci ISR_DMAW_TO_RST |\ 18362306a36Sopenharmony_ci ISR_PHY |\ 18462306a36Sopenharmony_ci ISR_PHY_LINKDOWN |\ 18562306a36Sopenharmony_ci ISR_TS_UPDATE |\ 18662306a36Sopenharmony_ci ISR_RS_UPDATE) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci/* Receive MAC Statistics Registers */ 18962306a36Sopenharmony_ci#define REG_STS_RX_PAUSE 0x1700 /* Num pause packets received */ 19062306a36Sopenharmony_ci#define REG_STS_RXD_OV 0x1704 /* Num frames dropped due to RX 19162306a36Sopenharmony_ci * FIFO overflow */ 19262306a36Sopenharmony_ci#define REG_STS_RXS_OV 0x1708 /* Num frames dropped due to RX 19362306a36Sopenharmony_ci * Status Buffer Overflow */ 19462306a36Sopenharmony_ci#define REG_STS_RX_FILTER 0x170C /* Num packets dropped due to 19562306a36Sopenharmony_ci * address filtering */ 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci/* MII definitions */ 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci/* PHY Common Register */ 20062306a36Sopenharmony_ci#define MII_SMARTSPEED 0x14 20162306a36Sopenharmony_ci#define MII_DBG_ADDR 0x1D 20262306a36Sopenharmony_ci#define MII_DBG_DATA 0x1E 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci/* PCI Command Register Bit Definitions */ 20562306a36Sopenharmony_ci#define PCI_REG_COMMAND 0x04 20662306a36Sopenharmony_ci#define CMD_IO_SPACE 0x0001 20762306a36Sopenharmony_ci#define CMD_MEMORY_SPACE 0x0002 20862306a36Sopenharmony_ci#define CMD_BUS_MASTER 0x0004 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci#define MEDIA_TYPE_100M_FULL 1 21162306a36Sopenharmony_ci#define MEDIA_TYPE_100M_HALF 2 21262306a36Sopenharmony_ci#define MEDIA_TYPE_10M_FULL 3 21362306a36Sopenharmony_ci#define MEDIA_TYPE_10M_HALF 4 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci#define AUTONEG_ADVERTISE_SPEED_DEFAULT 0x000F /* Everything */ 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci/* The size (in bytes) of a ethernet packet */ 21862306a36Sopenharmony_ci#define MAXIMUM_ETHERNET_FRAME_SIZE 1518 /* with FCS */ 21962306a36Sopenharmony_ci#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* with FCS */ 22062306a36Sopenharmony_ci#define MAX_JUMBO_FRAME_SIZE 0x2000 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_cistruct tx_pkt_header { 22362306a36Sopenharmony_ci unsigned pkt_size:11; 22462306a36Sopenharmony_ci unsigned:4; /* reserved */ 22562306a36Sopenharmony_ci unsigned ins_vlan:1; /* txmac should insert vlan */ 22662306a36Sopenharmony_ci unsigned short vlan; /* vlan tag */ 22762306a36Sopenharmony_ci}; 22862306a36Sopenharmony_ci/* FIXME: replace above bitfields with MASK/SHIFT defines below */ 22962306a36Sopenharmony_ci#define TX_PKT_HEADER_SIZE_MASK 0x7FF 23062306a36Sopenharmony_ci#define TX_PKT_HEADER_SIZE_SHIFT 0 23162306a36Sopenharmony_ci#define TX_PKT_HEADER_INS_VLAN_MASK 0x1 23262306a36Sopenharmony_ci#define TX_PKT_HEADER_INS_VLAN_SHIFT 15 23362306a36Sopenharmony_ci#define TX_PKT_HEADER_VLAN_TAG_MASK 0xFFFF 23462306a36Sopenharmony_ci#define TX_PKT_HEADER_VLAN_TAG_SHIFT 16 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_cistruct tx_pkt_status { 23762306a36Sopenharmony_ci unsigned pkt_size:11; 23862306a36Sopenharmony_ci unsigned:5; /* reserved */ 23962306a36Sopenharmony_ci unsigned ok:1; /* current packet transmitted without error */ 24062306a36Sopenharmony_ci unsigned bcast:1; /* broadcast packet */ 24162306a36Sopenharmony_ci unsigned mcast:1; /* multicast packet */ 24262306a36Sopenharmony_ci unsigned pause:1; /* transmiited a pause frame */ 24362306a36Sopenharmony_ci unsigned ctrl:1; 24462306a36Sopenharmony_ci unsigned defer:1; /* current packet is xmitted with defer */ 24562306a36Sopenharmony_ci unsigned exc_defer:1; 24662306a36Sopenharmony_ci unsigned single_col:1; 24762306a36Sopenharmony_ci unsigned multi_col:1; 24862306a36Sopenharmony_ci unsigned late_col:1; 24962306a36Sopenharmony_ci unsigned abort_col:1; 25062306a36Sopenharmony_ci unsigned underrun:1; /* current packet is aborted 25162306a36Sopenharmony_ci * due to txram underrun */ 25262306a36Sopenharmony_ci unsigned:3; /* reserved */ 25362306a36Sopenharmony_ci unsigned update:1; /* always 1'b1 in tx_status_buf */ 25462306a36Sopenharmony_ci}; 25562306a36Sopenharmony_ci/* FIXME: replace above bitfields with MASK/SHIFT defines below */ 25662306a36Sopenharmony_ci#define TX_PKT_STATUS_SIZE_MASK 0x7FF 25762306a36Sopenharmony_ci#define TX_PKT_STATUS_SIZE_SHIFT 0 25862306a36Sopenharmony_ci#define TX_PKT_STATUS_OK_MASK 0x1 25962306a36Sopenharmony_ci#define TX_PKT_STATUS_OK_SHIFT 16 26062306a36Sopenharmony_ci#define TX_PKT_STATUS_BCAST_MASK 0x1 26162306a36Sopenharmony_ci#define TX_PKT_STATUS_BCAST_SHIFT 17 26262306a36Sopenharmony_ci#define TX_PKT_STATUS_MCAST_MASK 0x1 26362306a36Sopenharmony_ci#define TX_PKT_STATUS_MCAST_SHIFT 18 26462306a36Sopenharmony_ci#define TX_PKT_STATUS_PAUSE_MASK 0x1 26562306a36Sopenharmony_ci#define TX_PKT_STATUS_PAUSE_SHIFT 19 26662306a36Sopenharmony_ci#define TX_PKT_STATUS_CTRL_MASK 0x1 26762306a36Sopenharmony_ci#define TX_PKT_STATUS_CTRL_SHIFT 20 26862306a36Sopenharmony_ci#define TX_PKT_STATUS_DEFER_MASK 0x1 26962306a36Sopenharmony_ci#define TX_PKT_STATUS_DEFER_SHIFT 21 27062306a36Sopenharmony_ci#define TX_PKT_STATUS_EXC_DEFER_MASK 0x1 27162306a36Sopenharmony_ci#define TX_PKT_STATUS_EXC_DEFER_SHIFT 22 27262306a36Sopenharmony_ci#define TX_PKT_STATUS_SINGLE_COL_MASK 0x1 27362306a36Sopenharmony_ci#define TX_PKT_STATUS_SINGLE_COL_SHIFT 23 27462306a36Sopenharmony_ci#define TX_PKT_STATUS_MULTI_COL_MASK 0x1 27562306a36Sopenharmony_ci#define TX_PKT_STATUS_MULTI_COL_SHIFT 24 27662306a36Sopenharmony_ci#define TX_PKT_STATUS_LATE_COL_MASK 0x1 27762306a36Sopenharmony_ci#define TX_PKT_STATUS_LATE_COL_SHIFT 25 27862306a36Sopenharmony_ci#define TX_PKT_STATUS_ABORT_COL_MASK 0x1 27962306a36Sopenharmony_ci#define TX_PKT_STATUS_ABORT_COL_SHIFT 26 28062306a36Sopenharmony_ci#define TX_PKT_STATUS_UNDERRUN_MASK 0x1 28162306a36Sopenharmony_ci#define TX_PKT_STATUS_UNDERRUN_SHIFT 27 28262306a36Sopenharmony_ci#define TX_PKT_STATUS_UPDATE_MASK 0x1 28362306a36Sopenharmony_ci#define TX_PKT_STATUS_UPDATE_SHIFT 31 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_cistruct rx_pkt_status { 28662306a36Sopenharmony_ci unsigned pkt_size:11; /* packet size, max 2047 bytes */ 28762306a36Sopenharmony_ci unsigned:5; /* reserved */ 28862306a36Sopenharmony_ci unsigned ok:1; /* current packet received ok without error */ 28962306a36Sopenharmony_ci unsigned bcast:1; /* current packet is broadcast */ 29062306a36Sopenharmony_ci unsigned mcast:1; /* current packet is multicast */ 29162306a36Sopenharmony_ci unsigned pause:1; 29262306a36Sopenharmony_ci unsigned ctrl:1; 29362306a36Sopenharmony_ci unsigned crc:1; /* received a packet with crc error */ 29462306a36Sopenharmony_ci unsigned code:1; /* received a packet with code error */ 29562306a36Sopenharmony_ci unsigned runt:1; /* received a packet less than 64 bytes 29662306a36Sopenharmony_ci * with good crc */ 29762306a36Sopenharmony_ci unsigned frag:1; /* received a packet less than 64 bytes 29862306a36Sopenharmony_ci * with bad crc */ 29962306a36Sopenharmony_ci unsigned trunc:1; /* current frame truncated due to rxram full */ 30062306a36Sopenharmony_ci unsigned align:1; /* this packet is alignment error */ 30162306a36Sopenharmony_ci unsigned vlan:1; /* this packet has vlan */ 30262306a36Sopenharmony_ci unsigned:3; /* reserved */ 30362306a36Sopenharmony_ci unsigned update:1; 30462306a36Sopenharmony_ci unsigned short vtag; /* vlan tag */ 30562306a36Sopenharmony_ci unsigned:16; 30662306a36Sopenharmony_ci}; 30762306a36Sopenharmony_ci/* FIXME: replace above bitfields with MASK/SHIFT defines below */ 30862306a36Sopenharmony_ci#define RX_PKT_STATUS_SIZE_MASK 0x7FF 30962306a36Sopenharmony_ci#define RX_PKT_STATUS_SIZE_SHIFT 0 31062306a36Sopenharmony_ci#define RX_PKT_STATUS_OK_MASK 0x1 31162306a36Sopenharmony_ci#define RX_PKT_STATUS_OK_SHIFT 16 31262306a36Sopenharmony_ci#define RX_PKT_STATUS_BCAST_MASK 0x1 31362306a36Sopenharmony_ci#define RX_PKT_STATUS_BCAST_SHIFT 17 31462306a36Sopenharmony_ci#define RX_PKT_STATUS_MCAST_MASK 0x1 31562306a36Sopenharmony_ci#define RX_PKT_STATUS_MCAST_SHIFT 18 31662306a36Sopenharmony_ci#define RX_PKT_STATUS_PAUSE_MASK 0x1 31762306a36Sopenharmony_ci#define RX_PKT_STATUS_PAUSE_SHIFT 19 31862306a36Sopenharmony_ci#define RX_PKT_STATUS_CTRL_MASK 0x1 31962306a36Sopenharmony_ci#define RX_PKT_STATUS_CTRL_SHIFT 20 32062306a36Sopenharmony_ci#define RX_PKT_STATUS_CRC_MASK 0x1 32162306a36Sopenharmony_ci#define RX_PKT_STATUS_CRC_SHIFT 21 32262306a36Sopenharmony_ci#define RX_PKT_STATUS_CODE_MASK 0x1 32362306a36Sopenharmony_ci#define RX_PKT_STATUS_CODE_SHIFT 22 32462306a36Sopenharmony_ci#define RX_PKT_STATUS_RUNT_MASK 0x1 32562306a36Sopenharmony_ci#define RX_PKT_STATUS_RUNT_SHIFT 23 32662306a36Sopenharmony_ci#define RX_PKT_STATUS_FRAG_MASK 0x1 32762306a36Sopenharmony_ci#define RX_PKT_STATUS_FRAG_SHIFT 24 32862306a36Sopenharmony_ci#define RX_PKT_STATUS_TRUNK_MASK 0x1 32962306a36Sopenharmony_ci#define RX_PKT_STATUS_TRUNK_SHIFT 25 33062306a36Sopenharmony_ci#define RX_PKT_STATUS_ALIGN_MASK 0x1 33162306a36Sopenharmony_ci#define RX_PKT_STATUS_ALIGN_SHIFT 26 33262306a36Sopenharmony_ci#define RX_PKT_STATUS_VLAN_MASK 0x1 33362306a36Sopenharmony_ci#define RX_PKT_STATUS_VLAN_SHIFT 27 33462306a36Sopenharmony_ci#define RX_PKT_STATUS_UPDATE_MASK 0x1 33562306a36Sopenharmony_ci#define RX_PKT_STATUS_UPDATE_SHIFT 31 33662306a36Sopenharmony_ci#define RX_PKT_STATUS_VLAN_TAG_MASK 0xFFFF 33762306a36Sopenharmony_ci#define RX_PKT_STATUS_VLAN_TAG_SHIFT 32 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_cistruct rx_desc { 34062306a36Sopenharmony_ci struct rx_pkt_status status; 34162306a36Sopenharmony_ci unsigned char packet[1536-sizeof(struct rx_pkt_status)]; 34262306a36Sopenharmony_ci}; 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_cienum atl2_speed_duplex { 34562306a36Sopenharmony_ci atl2_10_half = 0, 34662306a36Sopenharmony_ci atl2_10_full = 1, 34762306a36Sopenharmony_ci atl2_100_half = 2, 34862306a36Sopenharmony_ci atl2_100_full = 3 34962306a36Sopenharmony_ci}; 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_cistruct atl2_spi_flash_dev { 35262306a36Sopenharmony_ci const char *manu_name; /* manufacturer id */ 35362306a36Sopenharmony_ci /* op-code */ 35462306a36Sopenharmony_ci u8 cmdWRSR; 35562306a36Sopenharmony_ci u8 cmdREAD; 35662306a36Sopenharmony_ci u8 cmdPROGRAM; 35762306a36Sopenharmony_ci u8 cmdWREN; 35862306a36Sopenharmony_ci u8 cmdWRDI; 35962306a36Sopenharmony_ci u8 cmdRDSR; 36062306a36Sopenharmony_ci u8 cmdRDID; 36162306a36Sopenharmony_ci u8 cmdSECTOR_ERASE; 36262306a36Sopenharmony_ci u8 cmdCHIP_ERASE; 36362306a36Sopenharmony_ci}; 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_ci/* Structure containing variables used by the shared code (atl2_hw.c) */ 36662306a36Sopenharmony_cistruct atl2_hw { 36762306a36Sopenharmony_ci u8 __iomem *hw_addr; 36862306a36Sopenharmony_ci void *back; 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ci u8 preamble_len; 37162306a36Sopenharmony_ci u8 max_retry; /* Retransmission maximum, afterwards the 37262306a36Sopenharmony_ci * packet will be discarded. */ 37362306a36Sopenharmony_ci u8 jam_ipg; /* IPG to start JAM for collision based flow 37462306a36Sopenharmony_ci * control in half-duplex mode. In unit of 37562306a36Sopenharmony_ci * 8-bit time. */ 37662306a36Sopenharmony_ci u8 ipgt; /* Desired back to back inter-packet gap. The 37762306a36Sopenharmony_ci * default is 96-bit time. */ 37862306a36Sopenharmony_ci u8 min_ifg; /* Minimum number of IFG to enforce in between 37962306a36Sopenharmony_ci * RX frames. Frame gap below such IFP is 38062306a36Sopenharmony_ci * dropped. */ 38162306a36Sopenharmony_ci u8 ipgr1; /* 64bit Carrier-Sense window */ 38262306a36Sopenharmony_ci u8 ipgr2; /* 96-bit IPG window */ 38362306a36Sopenharmony_ci u8 retry_buf; /* When half-duplex mode, should hold some 38462306a36Sopenharmony_ci * bytes for mac retry . (8*4bytes unit) */ 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ci u16 fc_rxd_hi; 38762306a36Sopenharmony_ci u16 fc_rxd_lo; 38862306a36Sopenharmony_ci u16 lcol; /* Collision Window */ 38962306a36Sopenharmony_ci u16 max_frame_size; 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_ci u16 MediaType; 39262306a36Sopenharmony_ci u16 autoneg_advertised; 39362306a36Sopenharmony_ci u16 pci_cmd_word; 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ci u16 mii_autoneg_adv_reg; 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_ci u32 mem_rang; 39862306a36Sopenharmony_ci u32 txcw; 39962306a36Sopenharmony_ci u32 mc_filter_type; 40062306a36Sopenharmony_ci u32 num_mc_addrs; 40162306a36Sopenharmony_ci u32 collision_delta; 40262306a36Sopenharmony_ci u32 tx_packet_delta; 40362306a36Sopenharmony_ci u16 phy_spd_default; 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ci u16 device_id; 40662306a36Sopenharmony_ci u16 vendor_id; 40762306a36Sopenharmony_ci u16 subsystem_id; 40862306a36Sopenharmony_ci u16 subsystem_vendor_id; 40962306a36Sopenharmony_ci u8 revision_id; 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci /* spi flash */ 41262306a36Sopenharmony_ci u8 flash_vendor; 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci u8 dma_fairness; 41562306a36Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 41662306a36Sopenharmony_ci u8 perm_mac_addr[ETH_ALEN]; 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ci /* FIXME */ 41962306a36Sopenharmony_ci /* bool phy_preamble_sup; */ 42062306a36Sopenharmony_ci bool phy_configured; 42162306a36Sopenharmony_ci}; 42262306a36Sopenharmony_ci 42362306a36Sopenharmony_ci#endif /* _ATL2_HW_H_ */ 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_cistruct atl2_ring_header { 42662306a36Sopenharmony_ci /* pointer to the descriptor ring memory */ 42762306a36Sopenharmony_ci void *desc; 42862306a36Sopenharmony_ci /* physical address of the descriptor ring */ 42962306a36Sopenharmony_ci dma_addr_t dma; 43062306a36Sopenharmony_ci /* length of descriptor ring in bytes */ 43162306a36Sopenharmony_ci unsigned int size; 43262306a36Sopenharmony_ci}; 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ci/* board specific private data structure */ 43562306a36Sopenharmony_cistruct atl2_adapter { 43662306a36Sopenharmony_ci /* OS defined structs */ 43762306a36Sopenharmony_ci struct net_device *netdev; 43862306a36Sopenharmony_ci struct pci_dev *pdev; 43962306a36Sopenharmony_ci u32 wol; 44062306a36Sopenharmony_ci u16 link_speed; 44162306a36Sopenharmony_ci u16 link_duplex; 44262306a36Sopenharmony_ci 44362306a36Sopenharmony_ci spinlock_t stats_lock; 44462306a36Sopenharmony_ci 44562306a36Sopenharmony_ci struct work_struct reset_task; 44662306a36Sopenharmony_ci struct work_struct link_chg_task; 44762306a36Sopenharmony_ci struct timer_list watchdog_timer; 44862306a36Sopenharmony_ci struct timer_list phy_config_timer; 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci unsigned long cfg_phy; 45162306a36Sopenharmony_ci bool mac_disabled; 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ci /* All Descriptor memory */ 45462306a36Sopenharmony_ci dma_addr_t ring_dma; 45562306a36Sopenharmony_ci void *ring_vir_addr; 45662306a36Sopenharmony_ci int ring_size; 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ci struct tx_pkt_header *txd_ring; 45962306a36Sopenharmony_ci dma_addr_t txd_dma; 46062306a36Sopenharmony_ci 46162306a36Sopenharmony_ci struct tx_pkt_status *txs_ring; 46262306a36Sopenharmony_ci dma_addr_t txs_dma; 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ci struct rx_desc *rxd_ring; 46562306a36Sopenharmony_ci dma_addr_t rxd_dma; 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_ci u32 txd_ring_size; /* bytes per unit */ 46862306a36Sopenharmony_ci u32 txs_ring_size; /* dwords per unit */ 46962306a36Sopenharmony_ci u32 rxd_ring_size; /* 1536 bytes per unit */ 47062306a36Sopenharmony_ci 47162306a36Sopenharmony_ci /* read /write ptr: */ 47262306a36Sopenharmony_ci /* host */ 47362306a36Sopenharmony_ci u32 txd_write_ptr; 47462306a36Sopenharmony_ci u32 txs_next_clear; 47562306a36Sopenharmony_ci u32 rxd_read_ptr; 47662306a36Sopenharmony_ci 47762306a36Sopenharmony_ci /* nic */ 47862306a36Sopenharmony_ci atomic_t txd_read_ptr; 47962306a36Sopenharmony_ci atomic_t txs_write_ptr; 48062306a36Sopenharmony_ci u32 rxd_write_ptr; 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_ci /* Interrupt Moderator timer ( 2us resolution) */ 48362306a36Sopenharmony_ci u16 imt; 48462306a36Sopenharmony_ci /* Interrupt Clear timer (2us resolution) */ 48562306a36Sopenharmony_ci u16 ict; 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci unsigned long flags; 48862306a36Sopenharmony_ci /* structs defined in atl2_hw.h */ 48962306a36Sopenharmony_ci u32 bd_number; /* board number */ 49062306a36Sopenharmony_ci bool pci_using_64; 49162306a36Sopenharmony_ci bool have_msi; 49262306a36Sopenharmony_ci struct atl2_hw hw; 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ci u32 usr_cmd; 49562306a36Sopenharmony_ci /* FIXME */ 49662306a36Sopenharmony_ci /* u32 regs_buff[ATL2_REGS_LEN]; */ 49762306a36Sopenharmony_ci u32 pci_state[16]; 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci u32 *config_space; 50062306a36Sopenharmony_ci}; 50162306a36Sopenharmony_ci 50262306a36Sopenharmony_cienum atl2_state_t { 50362306a36Sopenharmony_ci __ATL2_TESTING, 50462306a36Sopenharmony_ci __ATL2_RESETTING, 50562306a36Sopenharmony_ci __ATL2_DOWN 50662306a36Sopenharmony_ci}; 50762306a36Sopenharmony_ci 50862306a36Sopenharmony_ci#endif /* _ATL2_H_ */ 509