18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/* 10G controller driver for Samsung SoCs
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2013 Samsung Electronics Co., Ltd.
58c2ecf20Sopenharmony_ci *		http://www.samsung.com
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Siva Reddy Kallam <siva.kallam@samsung.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef __SXGBE_COMMON_H__
118c2ecf20Sopenharmony_ci#define __SXGBE_COMMON_H__
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* forward references */
148c2ecf20Sopenharmony_cistruct sxgbe_desc_ops;
158c2ecf20Sopenharmony_cistruct sxgbe_dma_ops;
168c2ecf20Sopenharmony_cistruct sxgbe_mtl_ops;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define SXGBE_RESOURCE_NAME	"sam_sxgbeeth"
198c2ecf20Sopenharmony_ci#define DRV_MODULE_VERSION	"November_2013"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* MAX HW feature words */
228c2ecf20Sopenharmony_ci#define SXGBE_HW_WORDS 3
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define SXGBE_RX_COE_NONE	0
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* CSR Frequency Access Defines*/
278c2ecf20Sopenharmony_ci#define SXGBE_CSR_F_150M	150000000
288c2ecf20Sopenharmony_ci#define SXGBE_CSR_F_250M	250000000
298c2ecf20Sopenharmony_ci#define SXGBE_CSR_F_300M	300000000
308c2ecf20Sopenharmony_ci#define SXGBE_CSR_F_350M	350000000
318c2ecf20Sopenharmony_ci#define SXGBE_CSR_F_400M	400000000
328c2ecf20Sopenharmony_ci#define SXGBE_CSR_F_500M	500000000
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* pause time */
358c2ecf20Sopenharmony_ci#define SXGBE_PAUSE_TIME 0x200
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* tx queues */
388c2ecf20Sopenharmony_ci#define SXGBE_TX_QUEUES   8
398c2ecf20Sopenharmony_ci#define SXGBE_RX_QUEUES   16
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* Calculated based how much time does it take to fill 256KB Rx memory
428c2ecf20Sopenharmony_ci * at 10Gb speed at 156MHz clock rate and considered little less then
438c2ecf20Sopenharmony_ci * the actual value.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#define SXGBE_MAX_DMA_RIWT	0x70
468c2ecf20Sopenharmony_ci#define SXGBE_MIN_DMA_RIWT	0x01
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* Tx coalesce parameters */
498c2ecf20Sopenharmony_ci#define SXGBE_COAL_TX_TIMER	40000
508c2ecf20Sopenharmony_ci#define SXGBE_MAX_COAL_TX_TICK	100000
518c2ecf20Sopenharmony_ci#define SXGBE_TX_MAX_FRAMES	512
528c2ecf20Sopenharmony_ci#define SXGBE_TX_FRAMES	128
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* SXGBE TX FIFO is 8K, Rx FIFO is 16K */
558c2ecf20Sopenharmony_ci#define BUF_SIZE_16KiB 16384
568c2ecf20Sopenharmony_ci#define BUF_SIZE_8KiB 8192
578c2ecf20Sopenharmony_ci#define BUF_SIZE_4KiB 4096
588c2ecf20Sopenharmony_ci#define BUF_SIZE_2KiB 2048
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define SXGBE_DEFAULT_LIT_LS	0x3E8
618c2ecf20Sopenharmony_ci#define SXGBE_DEFAULT_TWT_LS	0x0
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* Flow Control defines */
648c2ecf20Sopenharmony_ci#define SXGBE_FLOW_OFF		0
658c2ecf20Sopenharmony_ci#define SXGBE_FLOW_RX		1
668c2ecf20Sopenharmony_ci#define SXGBE_FLOW_TX		2
678c2ecf20Sopenharmony_ci#define SXGBE_FLOW_AUTO		(SXGBE_FLOW_TX | SXGBE_FLOW_RX)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define SF_DMA_MODE 1		/* DMA STORE-AND-FORWARD Operation Mode */
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* errors */
728c2ecf20Sopenharmony_ci#define RX_GMII_ERR		0x01
738c2ecf20Sopenharmony_ci#define RX_WATCHDOG_ERR		0x02
748c2ecf20Sopenharmony_ci#define RX_CRC_ERR		0x03
758c2ecf20Sopenharmony_ci#define RX_GAINT_ERR		0x04
768c2ecf20Sopenharmony_ci#define RX_IP_HDR_ERR		0x05
778c2ecf20Sopenharmony_ci#define RX_PAYLOAD_ERR		0x06
788c2ecf20Sopenharmony_ci#define RX_OVERFLOW_ERR		0x07
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* pkt type */
818c2ecf20Sopenharmony_ci#define RX_LEN_PKT		0x00
828c2ecf20Sopenharmony_ci#define RX_MACCTL_PKT		0x01
838c2ecf20Sopenharmony_ci#define RX_DCBCTL_PKT		0x02
848c2ecf20Sopenharmony_ci#define RX_ARP_PKT		0x03
858c2ecf20Sopenharmony_ci#define RX_OAM_PKT		0x04
868c2ecf20Sopenharmony_ci#define RX_UNTAG_PKT		0x05
878c2ecf20Sopenharmony_ci#define RX_OTHER_PKT		0x07
888c2ecf20Sopenharmony_ci#define RX_SVLAN_PKT		0x08
898c2ecf20Sopenharmony_ci#define RX_CVLAN_PKT		0x09
908c2ecf20Sopenharmony_ci#define RX_DVLAN_OCVLAN_ICVLAN_PKT		0x0A
918c2ecf20Sopenharmony_ci#define RX_DVLAN_OSVLAN_ISVLAN_PKT		0x0B
928c2ecf20Sopenharmony_ci#define RX_DVLAN_OSVLAN_ICVLAN_PKT		0x0C
938c2ecf20Sopenharmony_ci#define RX_DVLAN_OCVLAN_ISVLAN_PKT		0x0D
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define RX_NOT_IP_PKT		0x00
968c2ecf20Sopenharmony_ci#define RX_IPV4_TCP_PKT		0x01
978c2ecf20Sopenharmony_ci#define RX_IPV4_UDP_PKT		0x02
988c2ecf20Sopenharmony_ci#define RX_IPV4_ICMP_PKT	0x03
998c2ecf20Sopenharmony_ci#define RX_IPV4_UNKNOWN_PKT	0x07
1008c2ecf20Sopenharmony_ci#define RX_IPV6_TCP_PKT		0x09
1018c2ecf20Sopenharmony_ci#define RX_IPV6_UDP_PKT		0x0A
1028c2ecf20Sopenharmony_ci#define RX_IPV6_ICMP_PKT	0x0B
1038c2ecf20Sopenharmony_ci#define RX_IPV6_UNKNOWN_PKT	0x0F
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define RX_NO_PTP		0x00
1068c2ecf20Sopenharmony_ci#define RX_PTP_SYNC		0x01
1078c2ecf20Sopenharmony_ci#define RX_PTP_FOLLOW_UP	0x02
1088c2ecf20Sopenharmony_ci#define RX_PTP_DELAY_REQ	0x03
1098c2ecf20Sopenharmony_ci#define RX_PTP_DELAY_RESP	0x04
1108c2ecf20Sopenharmony_ci#define RX_PTP_PDELAY_REQ	0x05
1118c2ecf20Sopenharmony_ci#define RX_PTP_PDELAY_RESP	0x06
1128c2ecf20Sopenharmony_ci#define RX_PTP_PDELAY_FOLLOW_UP	0x07
1138c2ecf20Sopenharmony_ci#define RX_PTP_ANNOUNCE		0x08
1148c2ecf20Sopenharmony_ci#define RX_PTP_MGMT		0x09
1158c2ecf20Sopenharmony_ci#define RX_PTP_SIGNAL		0x0A
1168c2ecf20Sopenharmony_ci#define RX_PTP_RESV_MSG		0x0F
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* EEE-LPI mode  flags*/
1198c2ecf20Sopenharmony_ci#define TX_ENTRY_LPI_MODE	0x10
1208c2ecf20Sopenharmony_ci#define TX_EXIT_LPI_MODE	0x20
1218c2ecf20Sopenharmony_ci#define RX_ENTRY_LPI_MODE	0x40
1228c2ecf20Sopenharmony_ci#define RX_EXIT_LPI_MODE	0x80
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/* EEE-LPI Interrupt status flag */
1258c2ecf20Sopenharmony_ci#define LPI_INT_STATUS		BIT(5)
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* EEE-LPI Default timer values */
1288c2ecf20Sopenharmony_ci#define LPI_LINK_STATUS_TIMER	0x3E8
1298c2ecf20Sopenharmony_ci#define LPI_MAC_WAIT_TIMER	0x00
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* EEE-LPI Control and status definitions */
1328c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_TXA	BIT(19)
1338c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_PLSDIS	BIT(18)
1348c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_PLS	BIT(17)
1358c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_LPIEN	BIT(16)
1368c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_TXRSTP	BIT(11)
1378c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_RXRSTP	BIT(10)
1388c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_RLPIST	BIT(9)
1398c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_TLPIST	BIT(8)
1408c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_RLPIEX	BIT(3)
1418c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_RLPIEN	BIT(2)
1428c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_TLPIEX	BIT(1)
1438c2ecf20Sopenharmony_ci#define LPI_CTRL_STATUS_TLPIEN	BIT(0)
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cienum dma_irq_status {
1468c2ecf20Sopenharmony_ci	tx_hard_error	= BIT(0),
1478c2ecf20Sopenharmony_ci	tx_bump_tc	= BIT(1),
1488c2ecf20Sopenharmony_ci	handle_tx	= BIT(2),
1498c2ecf20Sopenharmony_ci	rx_hard_error	= BIT(3),
1508c2ecf20Sopenharmony_ci	rx_bump_tc	= BIT(4),
1518c2ecf20Sopenharmony_ci	handle_rx	= BIT(5),
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#define NETIF_F_HW_VLAN_ALL     (NETIF_F_HW_VLAN_CTAG_RX |	\
1558c2ecf20Sopenharmony_ci				 NETIF_F_HW_VLAN_STAG_RX |	\
1568c2ecf20Sopenharmony_ci				 NETIF_F_HW_VLAN_CTAG_TX |	\
1578c2ecf20Sopenharmony_ci				 NETIF_F_HW_VLAN_STAG_TX |	\
1588c2ecf20Sopenharmony_ci				 NETIF_F_HW_VLAN_CTAG_FILTER |	\
1598c2ecf20Sopenharmony_ci				 NETIF_F_HW_VLAN_STAG_FILTER)
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* MMC control defines */
1628c2ecf20Sopenharmony_ci#define SXGBE_MMC_CTRL_CNT_FRZ  0x00000008
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/* SXGBE HW ADDR regs */
1658c2ecf20Sopenharmony_ci#define SXGBE_ADDR_HIGH(reg)    (((reg > 15) ? 0x00000800 : 0x00000040) + \
1668c2ecf20Sopenharmony_ci				 (reg * 8))
1678c2ecf20Sopenharmony_ci#define SXGBE_ADDR_LOW(reg)     (((reg > 15) ? 0x00000804 : 0x00000044) + \
1688c2ecf20Sopenharmony_ci				 (reg * 8))
1698c2ecf20Sopenharmony_ci#define SXGBE_MAX_PERFECT_ADDRESSES 32 /* Maximum unicast perfect filtering */
1708c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER       0x00000004      /* Frame Filter */
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* SXGBE Frame Filter defines */
1738c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_PR    0x00000001      /* Promiscuous Mode */
1748c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_HUC   0x00000002      /* Hash Unicast */
1758c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_HMC   0x00000004      /* Hash Multicast */
1768c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_DAIF  0x00000008      /* DA Inverse Filtering */
1778c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_PM    0x00000010      /* Pass all multicast */
1788c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_DBF   0x00000020      /* Disable Broadcast frames */
1798c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_SAIF  0x00000100      /* Inverse Filtering */
1808c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_SAF   0x00000200      /* Source Address Filter */
1818c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_HPF   0x00000400      /* Hash or perfect Filter */
1828c2ecf20Sopenharmony_ci#define SXGBE_FRAME_FILTER_RA    0x80000000      /* Receive all mode */
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#define SXGBE_HASH_TABLE_SIZE    64
1858c2ecf20Sopenharmony_ci#define SXGBE_HASH_HIGH          0x00000008      /* Multicast Hash Table High */
1868c2ecf20Sopenharmony_ci#define SXGBE_HASH_LOW           0x0000000c      /* Multicast Hash Table Low */
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define SXGBE_HI_REG_AE          0x80000000
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/* Minimum and maximum MTU */
1918c2ecf20Sopenharmony_ci#define MIN_MTU         68
1928c2ecf20Sopenharmony_ci#define MAX_MTU         9000
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci#define SXGBE_FOR_EACH_QUEUE(max_queues, queue_num)			\
1958c2ecf20Sopenharmony_ci	for (queue_num = 0; queue_num < max_queues; queue_num++)
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci#define DRV_VERSION "1.0.0"
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci#define SXGBE_MAX_RX_CHANNELS	16
2008c2ecf20Sopenharmony_ci#define SXGBE_MAX_TX_CHANNELS	16
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci#define START_MAC_REG_OFFSET	0x0000
2038c2ecf20Sopenharmony_ci#define MAX_MAC_REG_OFFSET	0x0DFC
2048c2ecf20Sopenharmony_ci#define START_MTL_REG_OFFSET	0x1000
2058c2ecf20Sopenharmony_ci#define MAX_MTL_REG_OFFSET	0x18FC
2068c2ecf20Sopenharmony_ci#define START_DMA_REG_OFFSET	0x3000
2078c2ecf20Sopenharmony_ci#define MAX_DMA_REG_OFFSET	0x38FC
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#define REG_SPACE_SIZE		0x2000
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* sxgbe statistics counters */
2128c2ecf20Sopenharmony_cistruct sxgbe_extra_stats {
2138c2ecf20Sopenharmony_ci	/* TX/RX IRQ events */
2148c2ecf20Sopenharmony_ci	unsigned long tx_underflow_irq;
2158c2ecf20Sopenharmony_ci	unsigned long tx_process_stopped_irq;
2168c2ecf20Sopenharmony_ci	unsigned long tx_ctxt_desc_err;
2178c2ecf20Sopenharmony_ci	unsigned long tx_threshold;
2188c2ecf20Sopenharmony_ci	unsigned long rx_threshold;
2198c2ecf20Sopenharmony_ci	unsigned long tx_pkt_n;
2208c2ecf20Sopenharmony_ci	unsigned long rx_pkt_n;
2218c2ecf20Sopenharmony_ci	unsigned long normal_irq_n;
2228c2ecf20Sopenharmony_ci	unsigned long tx_normal_irq_n;
2238c2ecf20Sopenharmony_ci	unsigned long rx_normal_irq_n;
2248c2ecf20Sopenharmony_ci	unsigned long napi_poll;
2258c2ecf20Sopenharmony_ci	unsigned long tx_clean;
2268c2ecf20Sopenharmony_ci	unsigned long tx_reset_ic_bit;
2278c2ecf20Sopenharmony_ci	unsigned long rx_process_stopped_irq;
2288c2ecf20Sopenharmony_ci	unsigned long rx_underflow_irq;
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	/* Bus access errors */
2318c2ecf20Sopenharmony_ci	unsigned long fatal_bus_error_irq;
2328c2ecf20Sopenharmony_ci	unsigned long tx_read_transfer_err;
2338c2ecf20Sopenharmony_ci	unsigned long tx_write_transfer_err;
2348c2ecf20Sopenharmony_ci	unsigned long tx_desc_access_err;
2358c2ecf20Sopenharmony_ci	unsigned long tx_buffer_access_err;
2368c2ecf20Sopenharmony_ci	unsigned long tx_data_transfer_err;
2378c2ecf20Sopenharmony_ci	unsigned long rx_read_transfer_err;
2388c2ecf20Sopenharmony_ci	unsigned long rx_write_transfer_err;
2398c2ecf20Sopenharmony_ci	unsigned long rx_desc_access_err;
2408c2ecf20Sopenharmony_ci	unsigned long rx_buffer_access_err;
2418c2ecf20Sopenharmony_ci	unsigned long rx_data_transfer_err;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	/* EEE-LPI stats */
2448c2ecf20Sopenharmony_ci	unsigned long tx_lpi_entry_n;
2458c2ecf20Sopenharmony_ci	unsigned long tx_lpi_exit_n;
2468c2ecf20Sopenharmony_ci	unsigned long rx_lpi_entry_n;
2478c2ecf20Sopenharmony_ci	unsigned long rx_lpi_exit_n;
2488c2ecf20Sopenharmony_ci	unsigned long eee_wakeup_error_n;
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	/* RX specific */
2518c2ecf20Sopenharmony_ci	/* L2 error */
2528c2ecf20Sopenharmony_ci	unsigned long rx_code_gmii_err;
2538c2ecf20Sopenharmony_ci	unsigned long rx_watchdog_err;
2548c2ecf20Sopenharmony_ci	unsigned long rx_crc_err;
2558c2ecf20Sopenharmony_ci	unsigned long rx_gaint_pkt_err;
2568c2ecf20Sopenharmony_ci	unsigned long ip_hdr_err;
2578c2ecf20Sopenharmony_ci	unsigned long ip_payload_err;
2588c2ecf20Sopenharmony_ci	unsigned long overflow_error;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	/* L2 Pkt type */
2618c2ecf20Sopenharmony_ci	unsigned long len_pkt;
2628c2ecf20Sopenharmony_ci	unsigned long mac_ctl_pkt;
2638c2ecf20Sopenharmony_ci	unsigned long dcb_ctl_pkt;
2648c2ecf20Sopenharmony_ci	unsigned long arp_pkt;
2658c2ecf20Sopenharmony_ci	unsigned long oam_pkt;
2668c2ecf20Sopenharmony_ci	unsigned long untag_okt;
2678c2ecf20Sopenharmony_ci	unsigned long other_pkt;
2688c2ecf20Sopenharmony_ci	unsigned long svlan_tag_pkt;
2698c2ecf20Sopenharmony_ci	unsigned long cvlan_tag_pkt;
2708c2ecf20Sopenharmony_ci	unsigned long dvlan_ocvlan_icvlan_pkt;
2718c2ecf20Sopenharmony_ci	unsigned long dvlan_osvlan_isvlan_pkt;
2728c2ecf20Sopenharmony_ci	unsigned long dvlan_osvlan_icvlan_pkt;
2738c2ecf20Sopenharmony_ci	unsigned long dvan_ocvlan_icvlan_pkt;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	/* L3/L4 Pkt type */
2768c2ecf20Sopenharmony_ci	unsigned long not_ip_pkt;
2778c2ecf20Sopenharmony_ci	unsigned long ip4_tcp_pkt;
2788c2ecf20Sopenharmony_ci	unsigned long ip4_udp_pkt;
2798c2ecf20Sopenharmony_ci	unsigned long ip4_icmp_pkt;
2808c2ecf20Sopenharmony_ci	unsigned long ip4_unknown_pkt;
2818c2ecf20Sopenharmony_ci	unsigned long ip6_tcp_pkt;
2828c2ecf20Sopenharmony_ci	unsigned long ip6_udp_pkt;
2838c2ecf20Sopenharmony_ci	unsigned long ip6_icmp_pkt;
2848c2ecf20Sopenharmony_ci	unsigned long ip6_unknown_pkt;
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	/* Filter specific */
2878c2ecf20Sopenharmony_ci	unsigned long vlan_filter_match;
2888c2ecf20Sopenharmony_ci	unsigned long sa_filter_fail;
2898c2ecf20Sopenharmony_ci	unsigned long da_filter_fail;
2908c2ecf20Sopenharmony_ci	unsigned long hash_filter_pass;
2918c2ecf20Sopenharmony_ci	unsigned long l3_filter_match;
2928c2ecf20Sopenharmony_ci	unsigned long l4_filter_match;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	/* RX context specific */
2958c2ecf20Sopenharmony_ci	unsigned long timestamp_dropped;
2968c2ecf20Sopenharmony_ci	unsigned long rx_msg_type_no_ptp;
2978c2ecf20Sopenharmony_ci	unsigned long rx_ptp_type_sync;
2988c2ecf20Sopenharmony_ci	unsigned long rx_ptp_type_follow_up;
2998c2ecf20Sopenharmony_ci	unsigned long rx_ptp_type_delay_req;
3008c2ecf20Sopenharmony_ci	unsigned long rx_ptp_type_delay_resp;
3018c2ecf20Sopenharmony_ci	unsigned long rx_ptp_type_pdelay_req;
3028c2ecf20Sopenharmony_ci	unsigned long rx_ptp_type_pdelay_resp;
3038c2ecf20Sopenharmony_ci	unsigned long rx_ptp_type_pdelay_follow_up;
3048c2ecf20Sopenharmony_ci	unsigned long rx_ptp_announce;
3058c2ecf20Sopenharmony_ci	unsigned long rx_ptp_mgmt;
3068c2ecf20Sopenharmony_ci	unsigned long rx_ptp_signal;
3078c2ecf20Sopenharmony_ci	unsigned long rx_ptp_resv_msg_type;
3088c2ecf20Sopenharmony_ci};
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_cistruct mac_link {
3118c2ecf20Sopenharmony_ci	int port;
3128c2ecf20Sopenharmony_ci	int duplex;
3138c2ecf20Sopenharmony_ci	int speed;
3148c2ecf20Sopenharmony_ci};
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_cistruct mii_regs {
3178c2ecf20Sopenharmony_ci	unsigned int addr;	/* MII Address */
3188c2ecf20Sopenharmony_ci	unsigned int data;	/* MII Data */
3198c2ecf20Sopenharmony_ci};
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistruct sxgbe_core_ops {
3228c2ecf20Sopenharmony_ci	/* MAC core initialization */
3238c2ecf20Sopenharmony_ci	void (*core_init)(void __iomem *ioaddr);
3248c2ecf20Sopenharmony_ci	/* Dump MAC registers */
3258c2ecf20Sopenharmony_ci	void (*dump_regs)(void __iomem *ioaddr);
3268c2ecf20Sopenharmony_ci	/* Handle extra events on specific interrupts hw dependent */
3278c2ecf20Sopenharmony_ci	int (*host_irq_status)(void __iomem *ioaddr,
3288c2ecf20Sopenharmony_ci			       struct sxgbe_extra_stats *x);
3298c2ecf20Sopenharmony_ci	/* Set power management mode (e.g. magic frame) */
3308c2ecf20Sopenharmony_ci	void (*pmt)(void __iomem *ioaddr, unsigned long mode);
3318c2ecf20Sopenharmony_ci	/* Set/Get Unicast MAC addresses */
3328c2ecf20Sopenharmony_ci	void (*set_umac_addr)(void __iomem *ioaddr, unsigned char *addr,
3338c2ecf20Sopenharmony_ci			      unsigned int reg_n);
3348c2ecf20Sopenharmony_ci	void (*get_umac_addr)(void __iomem *ioaddr, unsigned char *addr,
3358c2ecf20Sopenharmony_ci			      unsigned int reg_n);
3368c2ecf20Sopenharmony_ci	void (*enable_rx)(void __iomem *ioaddr, bool enable);
3378c2ecf20Sopenharmony_ci	void (*enable_tx)(void __iomem *ioaddr, bool enable);
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	/* controller version specific operations */
3408c2ecf20Sopenharmony_ci	int (*get_controller_version)(void __iomem *ioaddr);
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	/* If supported then get the optional core features */
3438c2ecf20Sopenharmony_ci	unsigned int (*get_hw_feature)(void __iomem *ioaddr,
3448c2ecf20Sopenharmony_ci				       unsigned char feature_index);
3458c2ecf20Sopenharmony_ci	/* adjust SXGBE speed */
3468c2ecf20Sopenharmony_ci	void (*set_speed)(void __iomem *ioaddr, unsigned char speed);
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	/* EEE-LPI specific operations */
3498c2ecf20Sopenharmony_ci	void (*set_eee_mode)(void __iomem *ioaddr);
3508c2ecf20Sopenharmony_ci	void (*reset_eee_mode)(void __iomem *ioaddr);
3518c2ecf20Sopenharmony_ci	void (*set_eee_timer)(void __iomem *ioaddr, const int ls,
3528c2ecf20Sopenharmony_ci			      const int tw);
3538c2ecf20Sopenharmony_ci	void (*set_eee_pls)(void __iomem *ioaddr, const int link);
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	/* Enable disable checksum offload operations */
3568c2ecf20Sopenharmony_ci	void (*enable_rx_csum)(void __iomem *ioaddr);
3578c2ecf20Sopenharmony_ci	void (*disable_rx_csum)(void __iomem *ioaddr);
3588c2ecf20Sopenharmony_ci	void (*enable_rxqueue)(void __iomem *ioaddr, int queue_num);
3598c2ecf20Sopenharmony_ci	void (*disable_rxqueue)(void __iomem *ioaddr, int queue_num);
3608c2ecf20Sopenharmony_ci};
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ciconst struct sxgbe_core_ops *sxgbe_get_core_ops(void);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistruct sxgbe_ops {
3658c2ecf20Sopenharmony_ci	const struct sxgbe_core_ops *mac;
3668c2ecf20Sopenharmony_ci	const struct sxgbe_desc_ops *desc;
3678c2ecf20Sopenharmony_ci	const struct sxgbe_dma_ops *dma;
3688c2ecf20Sopenharmony_ci	const struct sxgbe_mtl_ops *mtl;
3698c2ecf20Sopenharmony_ci	struct mii_regs mii;	/* MII register Addresses */
3708c2ecf20Sopenharmony_ci	struct mac_link link;
3718c2ecf20Sopenharmony_ci	unsigned int ctrl_uid;
3728c2ecf20Sopenharmony_ci	unsigned int ctrl_id;
3738c2ecf20Sopenharmony_ci};
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci/* SXGBE private data structures */
3768c2ecf20Sopenharmony_cistruct sxgbe_tx_queue {
3778c2ecf20Sopenharmony_ci	unsigned int irq_no;
3788c2ecf20Sopenharmony_ci	struct sxgbe_priv_data *priv_ptr;
3798c2ecf20Sopenharmony_ci	struct sxgbe_tx_norm_desc *dma_tx;
3808c2ecf20Sopenharmony_ci	dma_addr_t dma_tx_phy;
3818c2ecf20Sopenharmony_ci	dma_addr_t *tx_skbuff_dma;
3828c2ecf20Sopenharmony_ci	struct sk_buff **tx_skbuff;
3838c2ecf20Sopenharmony_ci	struct timer_list txtimer;
3848c2ecf20Sopenharmony_ci	unsigned int cur_tx;
3858c2ecf20Sopenharmony_ci	unsigned int dirty_tx;
3868c2ecf20Sopenharmony_ci	u32 tx_count_frames;
3878c2ecf20Sopenharmony_ci	u32 tx_coal_frames;
3888c2ecf20Sopenharmony_ci	u32 tx_coal_timer;
3898c2ecf20Sopenharmony_ci	int hwts_tx_en;
3908c2ecf20Sopenharmony_ci	u16 prev_mss;
3918c2ecf20Sopenharmony_ci	u8 queue_no;
3928c2ecf20Sopenharmony_ci};
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_cistruct sxgbe_rx_queue {
3958c2ecf20Sopenharmony_ci	struct sxgbe_priv_data *priv_ptr;
3968c2ecf20Sopenharmony_ci	struct sxgbe_rx_norm_desc *dma_rx;
3978c2ecf20Sopenharmony_ci	struct sk_buff **rx_skbuff;
3988c2ecf20Sopenharmony_ci	unsigned int cur_rx;
3998c2ecf20Sopenharmony_ci	unsigned int dirty_rx;
4008c2ecf20Sopenharmony_ci	unsigned int irq_no;
4018c2ecf20Sopenharmony_ci	u32 rx_riwt;
4028c2ecf20Sopenharmony_ci	dma_addr_t *rx_skbuff_dma;
4038c2ecf20Sopenharmony_ci	dma_addr_t dma_rx_phy;
4048c2ecf20Sopenharmony_ci	u8 queue_no;
4058c2ecf20Sopenharmony_ci};
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci/* SXGBE HW capabilities */
4088c2ecf20Sopenharmony_cistruct sxgbe_hw_features {
4098c2ecf20Sopenharmony_ci	/****** CAP [0] *******/
4108c2ecf20Sopenharmony_ci	unsigned int pmt_remote_wake_up;
4118c2ecf20Sopenharmony_ci	unsigned int pmt_magic_frame;
4128c2ecf20Sopenharmony_ci	/* IEEE 1588-2008 */
4138c2ecf20Sopenharmony_ci	unsigned int atime_stamp;
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	unsigned int eee;
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci	unsigned int tx_csum_offload;
4188c2ecf20Sopenharmony_ci	unsigned int rx_csum_offload;
4198c2ecf20Sopenharmony_ci	unsigned int multi_macaddr;
4208c2ecf20Sopenharmony_ci	unsigned int tstamp_srcselect;
4218c2ecf20Sopenharmony_ci	unsigned int sa_vlan_insert;
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	/****** CAP [1] *******/
4248c2ecf20Sopenharmony_ci	unsigned int rxfifo_size;
4258c2ecf20Sopenharmony_ci	unsigned int txfifo_size;
4268c2ecf20Sopenharmony_ci	unsigned int atstmap_hword;
4278c2ecf20Sopenharmony_ci	unsigned int dcb_enable;
4288c2ecf20Sopenharmony_ci	unsigned int splithead_enable;
4298c2ecf20Sopenharmony_ci	unsigned int tcpseg_offload;
4308c2ecf20Sopenharmony_ci	unsigned int debug_mem;
4318c2ecf20Sopenharmony_ci	unsigned int rss_enable;
4328c2ecf20Sopenharmony_ci	unsigned int hash_tsize;
4338c2ecf20Sopenharmony_ci	unsigned int l3l4_filer_size;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	/* This value is in bytes and
4368c2ecf20Sopenharmony_ci	 * as mentioned in HW features
4378c2ecf20Sopenharmony_ci	 * of SXGBE data book
4388c2ecf20Sopenharmony_ci	 */
4398c2ecf20Sopenharmony_ci	unsigned int rx_mtl_qsize;
4408c2ecf20Sopenharmony_ci	unsigned int tx_mtl_qsize;
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	/****** CAP [2] *******/
4438c2ecf20Sopenharmony_ci	/* TX and RX number of channels */
4448c2ecf20Sopenharmony_ci	unsigned int rx_mtl_queues;
4458c2ecf20Sopenharmony_ci	unsigned int tx_mtl_queues;
4468c2ecf20Sopenharmony_ci	unsigned int rx_dma_channels;
4478c2ecf20Sopenharmony_ci	unsigned int tx_dma_channels;
4488c2ecf20Sopenharmony_ci	unsigned int pps_output_count;
4498c2ecf20Sopenharmony_ci	unsigned int aux_input_count;
4508c2ecf20Sopenharmony_ci};
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_cistruct sxgbe_priv_data {
4538c2ecf20Sopenharmony_ci	/* DMA descriptos */
4548c2ecf20Sopenharmony_ci	struct sxgbe_tx_queue *txq[SXGBE_TX_QUEUES];
4558c2ecf20Sopenharmony_ci	struct sxgbe_rx_queue *rxq[SXGBE_RX_QUEUES];
4568c2ecf20Sopenharmony_ci	u8 cur_rx_qnum;
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci	unsigned int dma_tx_size;
4598c2ecf20Sopenharmony_ci	unsigned int dma_rx_size;
4608c2ecf20Sopenharmony_ci	unsigned int dma_buf_sz;
4618c2ecf20Sopenharmony_ci	u32 rx_riwt;
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	struct napi_struct napi;
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	void __iomem *ioaddr;
4668c2ecf20Sopenharmony_ci	struct net_device *dev;
4678c2ecf20Sopenharmony_ci	struct device *device;
4688c2ecf20Sopenharmony_ci	struct sxgbe_ops *hw;	/* sxgbe specific ops */
4698c2ecf20Sopenharmony_ci	int no_csum_insertion;
4708c2ecf20Sopenharmony_ci	int irq;
4718c2ecf20Sopenharmony_ci	int rxcsum_insertion;
4728c2ecf20Sopenharmony_ci	spinlock_t stats_lock;	/* lock for tx/rx statatics */
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	int oldlink;
4758c2ecf20Sopenharmony_ci	int speed;
4768c2ecf20Sopenharmony_ci	int oldduplex;
4778c2ecf20Sopenharmony_ci	struct mii_bus *mii;
4788c2ecf20Sopenharmony_ci	int mii_irq[PHY_MAX_ADDR];
4798c2ecf20Sopenharmony_ci	u8 rx_pause;
4808c2ecf20Sopenharmony_ci	u8 tx_pause;
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	struct sxgbe_extra_stats xstats;
4838c2ecf20Sopenharmony_ci	struct sxgbe_plat_data *plat;
4848c2ecf20Sopenharmony_ci	struct sxgbe_hw_features hw_cap;
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci	u32 msg_enable;
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci	struct clk *sxgbe_clk;
4898c2ecf20Sopenharmony_ci	int clk_csr;
4908c2ecf20Sopenharmony_ci	unsigned int mode;
4918c2ecf20Sopenharmony_ci	unsigned int default_addend;
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	/* advanced time stamp support */
4948c2ecf20Sopenharmony_ci	u32 adv_ts;
4958c2ecf20Sopenharmony_ci	int use_riwt;
4968c2ecf20Sopenharmony_ci	struct ptp_clock *ptp_clock;
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	/* tc control */
4998c2ecf20Sopenharmony_ci	int tx_tc;
5008c2ecf20Sopenharmony_ci	int rx_tc;
5018c2ecf20Sopenharmony_ci	/* EEE-LPI specific members */
5028c2ecf20Sopenharmony_ci	struct timer_list eee_ctrl_timer;
5038c2ecf20Sopenharmony_ci	bool tx_path_in_lpi_mode;
5048c2ecf20Sopenharmony_ci	int lpi_irq;
5058c2ecf20Sopenharmony_ci	int eee_enabled;
5068c2ecf20Sopenharmony_ci	int eee_active;
5078c2ecf20Sopenharmony_ci	int tx_lpi_timer;
5088c2ecf20Sopenharmony_ci};
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci/* Function prototypes */
5118c2ecf20Sopenharmony_cistruct sxgbe_priv_data *sxgbe_drv_probe(struct device *device,
5128c2ecf20Sopenharmony_ci					struct sxgbe_plat_data *plat_dat,
5138c2ecf20Sopenharmony_ci					void __iomem *addr);
5148c2ecf20Sopenharmony_ciint sxgbe_drv_remove(struct net_device *ndev);
5158c2ecf20Sopenharmony_civoid sxgbe_set_ethtool_ops(struct net_device *netdev);
5168c2ecf20Sopenharmony_ciint sxgbe_mdio_unregister(struct net_device *ndev);
5178c2ecf20Sopenharmony_ciint sxgbe_mdio_register(struct net_device *ndev);
5188c2ecf20Sopenharmony_ciint sxgbe_register_platform(void);
5198c2ecf20Sopenharmony_civoid sxgbe_unregister_platform(void);
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
5228c2ecf20Sopenharmony_ciint sxgbe_suspend(struct net_device *ndev);
5238c2ecf20Sopenharmony_ciint sxgbe_resume(struct net_device *ndev);
5248c2ecf20Sopenharmony_ciint sxgbe_freeze(struct net_device *ndev);
5258c2ecf20Sopenharmony_ciint sxgbe_restore(struct net_device *ndev);
5268c2ecf20Sopenharmony_ci#endif /* CONFIG_PM */
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ciconst struct sxgbe_mtl_ops *sxgbe_get_mtl_ops(void);
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_civoid sxgbe_disable_eee_mode(struct sxgbe_priv_data * const priv);
5318c2ecf20Sopenharmony_cibool sxgbe_eee_init(struct sxgbe_priv_data * const priv);
5328c2ecf20Sopenharmony_ci#endif /* __SXGBE_COMMON_H__ */
533