18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright(c) 2007 Atheros Corporation. All rights reserved. 48c2ecf20Sopenharmony_ci * Copyright(c) 2007 xiong huang <xiong.huang@atheros.com> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Derived from Intel e1000 driver 78c2ecf20Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _ATL1E_H_ 118c2ecf20Sopenharmony_ci#define _ATL1E_H_ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 148c2ecf20Sopenharmony_ci#include <linux/types.h> 158c2ecf20Sopenharmony_ci#include <linux/errno.h> 168c2ecf20Sopenharmony_ci#include <linux/module.h> 178c2ecf20Sopenharmony_ci#include <linux/pci.h> 188c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 198c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 208c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 218c2ecf20Sopenharmony_ci#include <linux/ioport.h> 228c2ecf20Sopenharmony_ci#include <linux/slab.h> 238c2ecf20Sopenharmony_ci#include <linux/list.h> 248c2ecf20Sopenharmony_ci#include <linux/delay.h> 258c2ecf20Sopenharmony_ci#include <linux/sched.h> 268c2ecf20Sopenharmony_ci#include <linux/in.h> 278c2ecf20Sopenharmony_ci#include <linux/ip.h> 288c2ecf20Sopenharmony_ci#include <linux/ipv6.h> 298c2ecf20Sopenharmony_ci#include <linux/udp.h> 308c2ecf20Sopenharmony_ci#include <linux/mii.h> 318c2ecf20Sopenharmony_ci#include <linux/io.h> 328c2ecf20Sopenharmony_ci#include <linux/vmalloc.h> 338c2ecf20Sopenharmony_ci#include <linux/pagemap.h> 348c2ecf20Sopenharmony_ci#include <linux/tcp.h> 358c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 368c2ecf20Sopenharmony_ci#include <linux/if_vlan.h> 378c2ecf20Sopenharmony_ci#include <linux/workqueue.h> 388c2ecf20Sopenharmony_ci#include <net/checksum.h> 398c2ecf20Sopenharmony_ci#include <net/ip6_checksum.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#include "atl1e_hw.h" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define PCI_REG_COMMAND 0x04 /* PCI Command Register */ 448c2ecf20Sopenharmony_ci#define CMD_IO_SPACE 0x0001 458c2ecf20Sopenharmony_ci#define CMD_MEMORY_SPACE 0x0002 468c2ecf20Sopenharmony_ci#define CMD_BUS_MASTER 0x0004 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define BAR_0 0 498c2ecf20Sopenharmony_ci#define BAR_1 1 508c2ecf20Sopenharmony_ci#define BAR_5 5 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* Wake Up Filter Control */ 538c2ecf20Sopenharmony_ci#define AT_WUFC_LNKC 0x00000001 /* Link Status Change Wakeup Enable */ 548c2ecf20Sopenharmony_ci#define AT_WUFC_MAG 0x00000002 /* Magic Packet Wakeup Enable */ 558c2ecf20Sopenharmony_ci#define AT_WUFC_EX 0x00000004 /* Directed Exact Wakeup Enable */ 568c2ecf20Sopenharmony_ci#define AT_WUFC_MC 0x00000008 /* Multicast Wakeup Enable */ 578c2ecf20Sopenharmony_ci#define AT_WUFC_BC 0x00000010 /* Broadcast Wakeup Enable */ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define SPEED_0 0xffff 608c2ecf20Sopenharmony_ci#define HALF_DUPLEX 1 618c2ecf20Sopenharmony_ci#define FULL_DUPLEX 2 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* Error Codes */ 648c2ecf20Sopenharmony_ci#define AT_ERR_EEPROM 1 658c2ecf20Sopenharmony_ci#define AT_ERR_PHY 2 668c2ecf20Sopenharmony_ci#define AT_ERR_CONFIG 3 678c2ecf20Sopenharmony_ci#define AT_ERR_PARAM 4 688c2ecf20Sopenharmony_ci#define AT_ERR_MAC_TYPE 5 698c2ecf20Sopenharmony_ci#define AT_ERR_PHY_TYPE 6 708c2ecf20Sopenharmony_ci#define AT_ERR_PHY_SPEED 7 718c2ecf20Sopenharmony_ci#define AT_ERR_PHY_RES 8 728c2ecf20Sopenharmony_ci#define AT_ERR_TIMEOUT 9 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define MAX_JUMBO_FRAME_SIZE 0x2000 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define AT_VLAN_TAG_TO_TPD_TAG(_vlan, _tpd) \ 778c2ecf20Sopenharmony_ci _tpd = (((_vlan) << (4)) | (((_vlan) >> 13) & 7) |\ 788c2ecf20Sopenharmony_ci (((_vlan) >> 9) & 8)) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define AT_TPD_TAG_TO_VLAN_TAG(_tpd, _vlan) \ 818c2ecf20Sopenharmony_ci _vlan = (((_tpd) >> 8) | (((_tpd) & 0x77) << 9) |\ 828c2ecf20Sopenharmony_ci (((_tdp) & 0x88) << 5)) 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define AT_MAX_RECEIVE_QUEUE 4 858c2ecf20Sopenharmony_ci#define AT_PAGE_NUM_PER_QUEUE 2 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define AT_DMA_HI_ADDR_MASK 0xffffffff00000000ULL 888c2ecf20Sopenharmony_ci#define AT_DMA_LO_ADDR_MASK 0x00000000ffffffffULL 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define AT_TX_WATCHDOG (5 * HZ) 918c2ecf20Sopenharmony_ci#define AT_MAX_INT_WORK 10 928c2ecf20Sopenharmony_ci#define AT_TWSI_EEPROM_TIMEOUT 100 938c2ecf20Sopenharmony_ci#define AT_HW_MAX_IDLE_DELAY 10 948c2ecf20Sopenharmony_ci#define AT_SUSPEND_LINK_TIMEOUT 28 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#define AT_REGS_LEN 75 978c2ecf20Sopenharmony_ci#define AT_EEPROM_LEN 512 988c2ecf20Sopenharmony_ci#define AT_ADV_MASK (ADVERTISE_10_HALF |\ 998c2ecf20Sopenharmony_ci ADVERTISE_10_FULL |\ 1008c2ecf20Sopenharmony_ci ADVERTISE_100_HALF |\ 1018c2ecf20Sopenharmony_ci ADVERTISE_100_FULL |\ 1028c2ecf20Sopenharmony_ci ADVERTISE_1000_FULL) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* tpd word 2 */ 1058c2ecf20Sopenharmony_ci#define TPD_BUFLEN_MASK 0x3FFF 1068c2ecf20Sopenharmony_ci#define TPD_BUFLEN_SHIFT 0 1078c2ecf20Sopenharmony_ci#define TPD_DMAINT_MASK 0x0001 1088c2ecf20Sopenharmony_ci#define TPD_DMAINT_SHIFT 14 1098c2ecf20Sopenharmony_ci#define TPD_PKTNT_MASK 0x0001 1108c2ecf20Sopenharmony_ci#define TPD_PKTINT_SHIFT 15 1118c2ecf20Sopenharmony_ci#define TPD_VLANTAG_MASK 0xFFFF 1128c2ecf20Sopenharmony_ci#define TPD_VLAN_SHIFT 16 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* tpd word 3 bits 0:4 */ 1158c2ecf20Sopenharmony_ci#define TPD_EOP_MASK 0x0001 1168c2ecf20Sopenharmony_ci#define TPD_EOP_SHIFT 0 1178c2ecf20Sopenharmony_ci#define TPD_IP_VERSION_MASK 0x0001 1188c2ecf20Sopenharmony_ci#define TPD_IP_VERSION_SHIFT 1 /* 0 : IPV4, 1 : IPV6 */ 1198c2ecf20Sopenharmony_ci#define TPD_INS_VL_TAG_MASK 0x0001 1208c2ecf20Sopenharmony_ci#define TPD_INS_VL_TAG_SHIFT 2 1218c2ecf20Sopenharmony_ci#define TPD_CC_SEGMENT_EN_MASK 0x0001 1228c2ecf20Sopenharmony_ci#define TPD_CC_SEGMENT_EN_SHIFT 3 1238c2ecf20Sopenharmony_ci#define TPD_SEGMENT_EN_MASK 0x0001 1248c2ecf20Sopenharmony_ci#define TPD_SEGMENT_EN_SHIFT 4 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci/* tdp word 3 bits 5:7 if ip version is 0 */ 1278c2ecf20Sopenharmony_ci#define TPD_IP_CSUM_MASK 0x0001 1288c2ecf20Sopenharmony_ci#define TPD_IP_CSUM_SHIFT 5 1298c2ecf20Sopenharmony_ci#define TPD_TCP_CSUM_MASK 0x0001 1308c2ecf20Sopenharmony_ci#define TPD_TCP_CSUM_SHIFT 6 1318c2ecf20Sopenharmony_ci#define TPD_UDP_CSUM_MASK 0x0001 1328c2ecf20Sopenharmony_ci#define TPD_UDP_CSUM_SHIFT 7 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* tdp word 3 bits 5:7 if ip version is 1 */ 1358c2ecf20Sopenharmony_ci#define TPD_V6_IPHLLO_MASK 0x0007 1368c2ecf20Sopenharmony_ci#define TPD_V6_IPHLLO_SHIFT 7 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/* tpd word 3 bits 8:9 bit */ 1398c2ecf20Sopenharmony_ci#define TPD_VL_TAGGED_MASK 0x0001 1408c2ecf20Sopenharmony_ci#define TPD_VL_TAGGED_SHIFT 8 1418c2ecf20Sopenharmony_ci#define TPD_ETHTYPE_MASK 0x0001 1428c2ecf20Sopenharmony_ci#define TPD_ETHTYPE_SHIFT 9 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* tdp word 3 bits 10:13 if ip version is 0 */ 1458c2ecf20Sopenharmony_ci#define TDP_V4_IPHL_MASK 0x000F 1468c2ecf20Sopenharmony_ci#define TPD_V4_IPHL_SHIFT 10 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* tdp word 3 bits 10:13 if ip version is 1 */ 1498c2ecf20Sopenharmony_ci#define TPD_V6_IPHLHI_MASK 0x000F 1508c2ecf20Sopenharmony_ci#define TPD_V6_IPHLHI_SHIFT 10 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci/* tpd word 3 bit 14:31 if segment enabled */ 1538c2ecf20Sopenharmony_ci#define TPD_TCPHDRLEN_MASK 0x000F 1548c2ecf20Sopenharmony_ci#define TPD_TCPHDRLEN_SHIFT 14 1558c2ecf20Sopenharmony_ci#define TPD_HDRFLAG_MASK 0x0001 1568c2ecf20Sopenharmony_ci#define TPD_HDRFLAG_SHIFT 18 1578c2ecf20Sopenharmony_ci#define TPD_MSS_MASK 0x1FFF 1588c2ecf20Sopenharmony_ci#define TPD_MSS_SHIFT 19 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/* tdp word 3 bit 16:31 if custom csum enabled */ 1618c2ecf20Sopenharmony_ci#define TPD_PLOADOFFSET_MASK 0x00FF 1628c2ecf20Sopenharmony_ci#define TPD_PLOADOFFSET_SHIFT 16 1638c2ecf20Sopenharmony_ci#define TPD_CCSUMOFFSET_MASK 0x00FF 1648c2ecf20Sopenharmony_ci#define TPD_CCSUMOFFSET_SHIFT 24 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistruct atl1e_tpd_desc { 1678c2ecf20Sopenharmony_ci __le64 buffer_addr; 1688c2ecf20Sopenharmony_ci __le32 word2; 1698c2ecf20Sopenharmony_ci __le32 word3; 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci/* how about 0x2000 */ 1738c2ecf20Sopenharmony_ci#define MAX_TX_BUF_LEN 0x2000 1748c2ecf20Sopenharmony_ci#define MAX_TX_BUF_SHIFT 13 1758c2ecf20Sopenharmony_ci#define MAX_TSO_SEG_SIZE 0x3c00 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* rrs word 1 bit 0:31 */ 1788c2ecf20Sopenharmony_ci#define RRS_RX_CSUM_MASK 0xFFFF 1798c2ecf20Sopenharmony_ci#define RRS_RX_CSUM_SHIFT 0 1808c2ecf20Sopenharmony_ci#define RRS_PKT_SIZE_MASK 0x3FFF 1818c2ecf20Sopenharmony_ci#define RRS_PKT_SIZE_SHIFT 16 1828c2ecf20Sopenharmony_ci#define RRS_CPU_NUM_MASK 0x0003 1838c2ecf20Sopenharmony_ci#define RRS_CPU_NUM_SHIFT 30 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define RRS_IS_RSS_IPV4 0x0001 1868c2ecf20Sopenharmony_ci#define RRS_IS_RSS_IPV4_TCP 0x0002 1878c2ecf20Sopenharmony_ci#define RRS_IS_RSS_IPV6 0x0004 1888c2ecf20Sopenharmony_ci#define RRS_IS_RSS_IPV6_TCP 0x0008 1898c2ecf20Sopenharmony_ci#define RRS_IS_IPV6 0x0010 1908c2ecf20Sopenharmony_ci#define RRS_IS_IP_FRAG 0x0020 1918c2ecf20Sopenharmony_ci#define RRS_IS_IP_DF 0x0040 1928c2ecf20Sopenharmony_ci#define RRS_IS_802_3 0x0080 1938c2ecf20Sopenharmony_ci#define RRS_IS_VLAN_TAG 0x0100 1948c2ecf20Sopenharmony_ci#define RRS_IS_ERR_FRAME 0x0200 1958c2ecf20Sopenharmony_ci#define RRS_IS_IPV4 0x0400 1968c2ecf20Sopenharmony_ci#define RRS_IS_UDP 0x0800 1978c2ecf20Sopenharmony_ci#define RRS_IS_TCP 0x1000 1988c2ecf20Sopenharmony_ci#define RRS_IS_BCAST 0x2000 1998c2ecf20Sopenharmony_ci#define RRS_IS_MCAST 0x4000 2008c2ecf20Sopenharmony_ci#define RRS_IS_PAUSE 0x8000 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci#define RRS_ERR_BAD_CRC 0x0001 2038c2ecf20Sopenharmony_ci#define RRS_ERR_CODE 0x0002 2048c2ecf20Sopenharmony_ci#define RRS_ERR_DRIBBLE 0x0004 2058c2ecf20Sopenharmony_ci#define RRS_ERR_RUNT 0x0008 2068c2ecf20Sopenharmony_ci#define RRS_ERR_RX_OVERFLOW 0x0010 2078c2ecf20Sopenharmony_ci#define RRS_ERR_TRUNC 0x0020 2088c2ecf20Sopenharmony_ci#define RRS_ERR_IP_CSUM 0x0040 2098c2ecf20Sopenharmony_ci#define RRS_ERR_L4_CSUM 0x0080 2108c2ecf20Sopenharmony_ci#define RRS_ERR_LENGTH 0x0100 2118c2ecf20Sopenharmony_ci#define RRS_ERR_DES_ADDR 0x0200 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistruct atl1e_recv_ret_status { 2148c2ecf20Sopenharmony_ci u16 seq_num; 2158c2ecf20Sopenharmony_ci u16 hash_lo; 2168c2ecf20Sopenharmony_ci __le32 word1; 2178c2ecf20Sopenharmony_ci u16 pkt_flag; 2188c2ecf20Sopenharmony_ci u16 err_flag; 2198c2ecf20Sopenharmony_ci u16 hash_hi; 2208c2ecf20Sopenharmony_ci u16 vtag; 2218c2ecf20Sopenharmony_ci}; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_cienum atl1e_dma_req_block { 2248c2ecf20Sopenharmony_ci atl1e_dma_req_128 = 0, 2258c2ecf20Sopenharmony_ci atl1e_dma_req_256 = 1, 2268c2ecf20Sopenharmony_ci atl1e_dma_req_512 = 2, 2278c2ecf20Sopenharmony_ci atl1e_dma_req_1024 = 3, 2288c2ecf20Sopenharmony_ci atl1e_dma_req_2048 = 4, 2298c2ecf20Sopenharmony_ci atl1e_dma_req_4096 = 5 2308c2ecf20Sopenharmony_ci}; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cienum atl1e_rrs_type { 2338c2ecf20Sopenharmony_ci atl1e_rrs_disable = 0, 2348c2ecf20Sopenharmony_ci atl1e_rrs_ipv4 = 1, 2358c2ecf20Sopenharmony_ci atl1e_rrs_ipv4_tcp = 2, 2368c2ecf20Sopenharmony_ci atl1e_rrs_ipv6 = 4, 2378c2ecf20Sopenharmony_ci atl1e_rrs_ipv6_tcp = 8 2388c2ecf20Sopenharmony_ci}; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_cienum atl1e_nic_type { 2418c2ecf20Sopenharmony_ci athr_l1e = 0, 2428c2ecf20Sopenharmony_ci athr_l2e_revA = 1, 2438c2ecf20Sopenharmony_ci athr_l2e_revB = 2 2448c2ecf20Sopenharmony_ci}; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cistruct atl1e_hw_stats { 2478c2ecf20Sopenharmony_ci /* rx */ 2488c2ecf20Sopenharmony_ci unsigned long rx_ok; /* The number of good packet received. */ 2498c2ecf20Sopenharmony_ci unsigned long rx_bcast; /* The number of good broadcast packet received. */ 2508c2ecf20Sopenharmony_ci unsigned long rx_mcast; /* The number of good multicast packet received. */ 2518c2ecf20Sopenharmony_ci unsigned long rx_pause; /* The number of Pause packet received. */ 2528c2ecf20Sopenharmony_ci unsigned long rx_ctrl; /* The number of Control packet received other than Pause frame. */ 2538c2ecf20Sopenharmony_ci unsigned long rx_fcs_err; /* The number of packets with bad FCS. */ 2548c2ecf20Sopenharmony_ci unsigned long rx_len_err; /* The number of packets with mismatch of length field and actual size. */ 2558c2ecf20Sopenharmony_ci unsigned long rx_byte_cnt; /* The number of bytes of good packet received. FCS is NOT included. */ 2568c2ecf20Sopenharmony_ci unsigned long rx_runt; /* The number of packets received that are less than 64 byte long and with good FCS. */ 2578c2ecf20Sopenharmony_ci unsigned long rx_frag; /* The number of packets received that are less than 64 byte long and with bad FCS. */ 2588c2ecf20Sopenharmony_ci unsigned long rx_sz_64; /* The number of good and bad packets received that are 64 byte long. */ 2598c2ecf20Sopenharmony_ci unsigned long rx_sz_65_127; /* The number of good and bad packets received that are between 65 and 127-byte long. */ 2608c2ecf20Sopenharmony_ci unsigned long rx_sz_128_255; /* The number of good and bad packets received that are between 128 and 255-byte long. */ 2618c2ecf20Sopenharmony_ci unsigned long rx_sz_256_511; /* The number of good and bad packets received that are between 256 and 511-byte long. */ 2628c2ecf20Sopenharmony_ci unsigned long rx_sz_512_1023; /* The number of good and bad packets received that are between 512 and 1023-byte long. */ 2638c2ecf20Sopenharmony_ci unsigned long rx_sz_1024_1518; /* The number of good and bad packets received that are between 1024 and 1518-byte long. */ 2648c2ecf20Sopenharmony_ci unsigned long rx_sz_1519_max; /* The number of good and bad packets received that are between 1519-byte and MTU. */ 2658c2ecf20Sopenharmony_ci unsigned long rx_sz_ov; /* The number of good and bad packets received that are more than MTU size truncated by Selene. */ 2668c2ecf20Sopenharmony_ci unsigned long rx_rxf_ov; /* The number of frame dropped due to occurrence of RX FIFO overflow. */ 2678c2ecf20Sopenharmony_ci unsigned long rx_rrd_ov; /* The number of frame dropped due to occurrence of RRD overflow. */ 2688c2ecf20Sopenharmony_ci unsigned long rx_align_err; /* Alignment Error */ 2698c2ecf20Sopenharmony_ci unsigned long rx_bcast_byte_cnt; /* The byte count of broadcast packet received, excluding FCS. */ 2708c2ecf20Sopenharmony_ci unsigned long rx_mcast_byte_cnt; /* The byte count of multicast packet received, excluding FCS. */ 2718c2ecf20Sopenharmony_ci unsigned long rx_err_addr; /* The number of packets dropped due to address filtering. */ 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci /* tx */ 2748c2ecf20Sopenharmony_ci unsigned long tx_ok; /* The number of good packet transmitted. */ 2758c2ecf20Sopenharmony_ci unsigned long tx_bcast; /* The number of good broadcast packet transmitted. */ 2768c2ecf20Sopenharmony_ci unsigned long tx_mcast; /* The number of good multicast packet transmitted. */ 2778c2ecf20Sopenharmony_ci unsigned long tx_pause; /* The number of Pause packet transmitted. */ 2788c2ecf20Sopenharmony_ci unsigned long tx_exc_defer; /* The number of packets transmitted with excessive deferral. */ 2798c2ecf20Sopenharmony_ci unsigned long tx_ctrl; /* The number of packets transmitted is a control frame, excluding Pause frame. */ 2808c2ecf20Sopenharmony_ci unsigned long tx_defer; /* The number of packets transmitted that is deferred. */ 2818c2ecf20Sopenharmony_ci unsigned long tx_byte_cnt; /* The number of bytes of data transmitted. FCS is NOT included. */ 2828c2ecf20Sopenharmony_ci unsigned long tx_sz_64; /* The number of good and bad packets transmitted that are 64 byte long. */ 2838c2ecf20Sopenharmony_ci unsigned long tx_sz_65_127; /* The number of good and bad packets transmitted that are between 65 and 127-byte long. */ 2848c2ecf20Sopenharmony_ci unsigned long tx_sz_128_255; /* The number of good and bad packets transmitted that are between 128 and 255-byte long. */ 2858c2ecf20Sopenharmony_ci unsigned long tx_sz_256_511; /* The number of good and bad packets transmitted that are between 256 and 511-byte long. */ 2868c2ecf20Sopenharmony_ci unsigned long tx_sz_512_1023; /* The number of good and bad packets transmitted that are between 512 and 1023-byte long. */ 2878c2ecf20Sopenharmony_ci unsigned long tx_sz_1024_1518; /* The number of good and bad packets transmitted that are between 1024 and 1518-byte long. */ 2888c2ecf20Sopenharmony_ci unsigned long tx_sz_1519_max; /* The number of good and bad packets transmitted that are between 1519-byte and MTU. */ 2898c2ecf20Sopenharmony_ci unsigned long tx_1_col; /* The number of packets subsequently transmitted successfully with a single prior collision. */ 2908c2ecf20Sopenharmony_ci unsigned long tx_2_col; /* The number of packets subsequently transmitted successfully with multiple prior collisions. */ 2918c2ecf20Sopenharmony_ci unsigned long tx_late_col; /* The number of packets transmitted with late collisions. */ 2928c2ecf20Sopenharmony_ci unsigned long tx_abort_col; /* The number of transmit packets aborted due to excessive collisions. */ 2938c2ecf20Sopenharmony_ci unsigned long tx_underrun; /* The number of transmit packets aborted due to transmit FIFO underrun, or TRD FIFO underrun */ 2948c2ecf20Sopenharmony_ci unsigned long tx_rd_eop; /* The number of times that read beyond the EOP into the next frame area when TRD was not written timely */ 2958c2ecf20Sopenharmony_ci unsigned long tx_len_err; /* The number of transmit packets with length field does NOT match the actual frame size. */ 2968c2ecf20Sopenharmony_ci unsigned long tx_trunc; /* The number of transmit packets truncated due to size exceeding MTU. */ 2978c2ecf20Sopenharmony_ci unsigned long tx_bcast_byte; /* The byte count of broadcast packet transmitted, excluding FCS. */ 2988c2ecf20Sopenharmony_ci unsigned long tx_mcast_byte; /* The byte count of multicast packet transmitted, excluding FCS. */ 2998c2ecf20Sopenharmony_ci}; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_cistruct atl1e_hw { 3028c2ecf20Sopenharmony_ci u8 __iomem *hw_addr; /* inner register address */ 3038c2ecf20Sopenharmony_ci resource_size_t mem_rang; 3048c2ecf20Sopenharmony_ci struct atl1e_adapter *adapter; 3058c2ecf20Sopenharmony_ci enum atl1e_nic_type nic_type; 3068c2ecf20Sopenharmony_ci u16 device_id; 3078c2ecf20Sopenharmony_ci u16 vendor_id; 3088c2ecf20Sopenharmony_ci u16 subsystem_id; 3098c2ecf20Sopenharmony_ci u16 subsystem_vendor_id; 3108c2ecf20Sopenharmony_ci u8 revision_id; 3118c2ecf20Sopenharmony_ci u16 pci_cmd_word; 3128c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 3138c2ecf20Sopenharmony_ci u8 perm_mac_addr[ETH_ALEN]; 3148c2ecf20Sopenharmony_ci u8 preamble_len; 3158c2ecf20Sopenharmony_ci u16 max_frame_size; 3168c2ecf20Sopenharmony_ci u16 rx_jumbo_th; 3178c2ecf20Sopenharmony_ci u16 tx_jumbo_th; 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci u16 media_type; 3208c2ecf20Sopenharmony_ci#define MEDIA_TYPE_AUTO_SENSOR 0 3218c2ecf20Sopenharmony_ci#define MEDIA_TYPE_100M_FULL 1 3228c2ecf20Sopenharmony_ci#define MEDIA_TYPE_100M_HALF 2 3238c2ecf20Sopenharmony_ci#define MEDIA_TYPE_10M_FULL 3 3248c2ecf20Sopenharmony_ci#define MEDIA_TYPE_10M_HALF 4 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci u16 autoneg_advertised; 3278c2ecf20Sopenharmony_ci#define ADVERTISE_10_HALF 0x0001 3288c2ecf20Sopenharmony_ci#define ADVERTISE_10_FULL 0x0002 3298c2ecf20Sopenharmony_ci#define ADVERTISE_100_HALF 0x0004 3308c2ecf20Sopenharmony_ci#define ADVERTISE_100_FULL 0x0008 3318c2ecf20Sopenharmony_ci#define ADVERTISE_1000_HALF 0x0010 /* Not used, just FYI */ 3328c2ecf20Sopenharmony_ci#define ADVERTISE_1000_FULL 0x0020 3338c2ecf20Sopenharmony_ci u16 mii_autoneg_adv_reg; 3348c2ecf20Sopenharmony_ci u16 mii_1000t_ctrl_reg; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci u16 imt; /* Interrupt Moderator timer ( 2us resolution) */ 3378c2ecf20Sopenharmony_ci u16 ict; /* Interrupt Clear timer (2us resolution) */ 3388c2ecf20Sopenharmony_ci u32 smb_timer; 3398c2ecf20Sopenharmony_ci u16 rrd_thresh; /* Threshold of number of RRD produced to trigger 3408c2ecf20Sopenharmony_ci interrupt request */ 3418c2ecf20Sopenharmony_ci u16 tpd_thresh; 3428c2ecf20Sopenharmony_ci u16 rx_count_down; /* 2us resolution */ 3438c2ecf20Sopenharmony_ci u16 tx_count_down; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci u8 tpd_burst; /* Number of TPD to prefetch in cache-aligned burst. */ 3468c2ecf20Sopenharmony_ci enum atl1e_rrs_type rrs_type; 3478c2ecf20Sopenharmony_ci u32 base_cpu; 3488c2ecf20Sopenharmony_ci u32 indirect_tab; 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci enum atl1e_dma_req_block dmar_block; 3518c2ecf20Sopenharmony_ci enum atl1e_dma_req_block dmaw_block; 3528c2ecf20Sopenharmony_ci u8 dmaw_dly_cnt; 3538c2ecf20Sopenharmony_ci u8 dmar_dly_cnt; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci bool phy_configured; 3568c2ecf20Sopenharmony_ci bool re_autoneg; 3578c2ecf20Sopenharmony_ci bool emi_ca; 3588c2ecf20Sopenharmony_ci}; 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci/* 3618c2ecf20Sopenharmony_ci * wrapper around a pointer to a socket buffer, 3628c2ecf20Sopenharmony_ci * so a DMA handle can be stored along with the buffer 3638c2ecf20Sopenharmony_ci */ 3648c2ecf20Sopenharmony_cistruct atl1e_tx_buffer { 3658c2ecf20Sopenharmony_ci struct sk_buff *skb; 3668c2ecf20Sopenharmony_ci u16 flags; 3678c2ecf20Sopenharmony_ci#define ATL1E_TX_PCIMAP_SINGLE 0x0001 3688c2ecf20Sopenharmony_ci#define ATL1E_TX_PCIMAP_PAGE 0x0002 3698c2ecf20Sopenharmony_ci#define ATL1E_TX_PCIMAP_TYPE_MASK 0x0003 3708c2ecf20Sopenharmony_ci u16 length; 3718c2ecf20Sopenharmony_ci dma_addr_t dma; 3728c2ecf20Sopenharmony_ci}; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci#define ATL1E_SET_PCIMAP_TYPE(tx_buff, type) do { \ 3758c2ecf20Sopenharmony_ci ((tx_buff)->flags) &= ~ATL1E_TX_PCIMAP_TYPE_MASK; \ 3768c2ecf20Sopenharmony_ci ((tx_buff)->flags) |= (type); \ 3778c2ecf20Sopenharmony_ci } while (0) 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistruct atl1e_rx_page { 3808c2ecf20Sopenharmony_ci dma_addr_t dma; /* receive rage DMA address */ 3818c2ecf20Sopenharmony_ci u8 *addr; /* receive rage virtual address */ 3828c2ecf20Sopenharmony_ci dma_addr_t write_offset_dma; /* the DMA address which contain the 3838c2ecf20Sopenharmony_ci receive data offset in the page */ 3848c2ecf20Sopenharmony_ci u32 *write_offset_addr; /* the virtaul address which contain 3858c2ecf20Sopenharmony_ci the receive data offset in the page */ 3868c2ecf20Sopenharmony_ci u32 read_offset; /* the offset where we have read */ 3878c2ecf20Sopenharmony_ci}; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_cistruct atl1e_rx_page_desc { 3908c2ecf20Sopenharmony_ci struct atl1e_rx_page rx_page[AT_PAGE_NUM_PER_QUEUE]; 3918c2ecf20Sopenharmony_ci u8 rx_using; 3928c2ecf20Sopenharmony_ci u16 rx_nxseq; 3938c2ecf20Sopenharmony_ci}; 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci/* transmit packet descriptor (tpd) ring */ 3968c2ecf20Sopenharmony_cistruct atl1e_tx_ring { 3978c2ecf20Sopenharmony_ci struct atl1e_tpd_desc *desc; /* descriptor ring virtual address */ 3988c2ecf20Sopenharmony_ci dma_addr_t dma; /* descriptor ring physical address */ 3998c2ecf20Sopenharmony_ci u16 count; /* the count of transmit rings */ 4008c2ecf20Sopenharmony_ci rwlock_t tx_lock; 4018c2ecf20Sopenharmony_ci u16 next_to_use; 4028c2ecf20Sopenharmony_ci atomic_t next_to_clean; 4038c2ecf20Sopenharmony_ci struct atl1e_tx_buffer *tx_buffer; 4048c2ecf20Sopenharmony_ci dma_addr_t cmb_dma; 4058c2ecf20Sopenharmony_ci u32 *cmb; 4068c2ecf20Sopenharmony_ci}; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci/* receive packet descriptor ring */ 4098c2ecf20Sopenharmony_cistruct atl1e_rx_ring { 4108c2ecf20Sopenharmony_ci void *desc; 4118c2ecf20Sopenharmony_ci dma_addr_t dma; 4128c2ecf20Sopenharmony_ci int size; 4138c2ecf20Sopenharmony_ci u32 page_size; /* bytes length of rxf page */ 4148c2ecf20Sopenharmony_ci u32 real_page_size; /* real_page_size = page_size + jumbo + aliagn */ 4158c2ecf20Sopenharmony_ci struct atl1e_rx_page_desc rx_page_desc[AT_MAX_RECEIVE_QUEUE]; 4168c2ecf20Sopenharmony_ci}; 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci/* board specific private data structure */ 4198c2ecf20Sopenharmony_cistruct atl1e_adapter { 4208c2ecf20Sopenharmony_ci struct net_device *netdev; 4218c2ecf20Sopenharmony_ci struct pci_dev *pdev; 4228c2ecf20Sopenharmony_ci struct napi_struct napi; 4238c2ecf20Sopenharmony_ci struct mii_if_info mii; /* MII interface info */ 4248c2ecf20Sopenharmony_ci struct atl1e_hw hw; 4258c2ecf20Sopenharmony_ci struct atl1e_hw_stats hw_stats; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci u32 wol; 4288c2ecf20Sopenharmony_ci u16 link_speed; 4298c2ecf20Sopenharmony_ci u16 link_duplex; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci spinlock_t mdio_lock; 4328c2ecf20Sopenharmony_ci atomic_t irq_sem; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci struct work_struct reset_task; 4358c2ecf20Sopenharmony_ci struct work_struct link_chg_task; 4368c2ecf20Sopenharmony_ci struct timer_list watchdog_timer; 4378c2ecf20Sopenharmony_ci struct timer_list phy_config_timer; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci /* All Descriptor memory */ 4408c2ecf20Sopenharmony_ci dma_addr_t ring_dma; 4418c2ecf20Sopenharmony_ci void *ring_vir_addr; 4428c2ecf20Sopenharmony_ci u32 ring_size; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci struct atl1e_tx_ring tx_ring; 4458c2ecf20Sopenharmony_ci struct atl1e_rx_ring rx_ring; 4468c2ecf20Sopenharmony_ci int num_rx_queues; 4478c2ecf20Sopenharmony_ci unsigned long flags; 4488c2ecf20Sopenharmony_ci#define __AT_TESTING 0x0001 4498c2ecf20Sopenharmony_ci#define __AT_RESETTING 0x0002 4508c2ecf20Sopenharmony_ci#define __AT_DOWN 0x0003 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci u32 bd_number; /* board number;*/ 4538c2ecf20Sopenharmony_ci u32 pci_state[16]; 4548c2ecf20Sopenharmony_ci u32 *config_space; 4558c2ecf20Sopenharmony_ci}; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci#define AT_WRITE_REG(a, reg, value) ( \ 4588c2ecf20Sopenharmony_ci writel((value), ((a)->hw_addr + reg))) 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci#define AT_WRITE_FLUSH(a) (\ 4618c2ecf20Sopenharmony_ci readl((a)->hw_addr)) 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci#define AT_READ_REG(a, reg) ( \ 4648c2ecf20Sopenharmony_ci readl((a)->hw_addr + reg)) 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci#define AT_WRITE_REGB(a, reg, value) (\ 4678c2ecf20Sopenharmony_ci writeb((value), ((a)->hw_addr + reg))) 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci#define AT_READ_REGB(a, reg) (\ 4708c2ecf20Sopenharmony_ci readb((a)->hw_addr + reg)) 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci#define AT_WRITE_REGW(a, reg, value) (\ 4738c2ecf20Sopenharmony_ci writew((value), ((a)->hw_addr + reg))) 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci#define AT_READ_REGW(a, reg) (\ 4768c2ecf20Sopenharmony_ci readw((a)->hw_addr + reg)) 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci#define AT_WRITE_REG_ARRAY(a, reg, offset, value) ( \ 4798c2ecf20Sopenharmony_ci writel((value), (((a)->hw_addr + reg) + ((offset) << 2)))) 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci#define AT_READ_REG_ARRAY(a, reg, offset) ( \ 4828c2ecf20Sopenharmony_ci readl(((a)->hw_addr + reg) + ((offset) << 2))) 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ciextern char atl1e_driver_name[]; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_civoid atl1e_check_options(struct atl1e_adapter *adapter); 4878c2ecf20Sopenharmony_ciint atl1e_up(struct atl1e_adapter *adapter); 4888c2ecf20Sopenharmony_civoid atl1e_down(struct atl1e_adapter *adapter); 4898c2ecf20Sopenharmony_civoid atl1e_reinit_locked(struct atl1e_adapter *adapter); 4908c2ecf20Sopenharmony_cis32 atl1e_reset_hw(struct atl1e_hw *hw); 4918c2ecf20Sopenharmony_civoid atl1e_set_ethtool_ops(struct net_device *netdev); 4928c2ecf20Sopenharmony_ci#endif /* _ATL1_E_H_ */ 493