xref: /freebsd/sys/dev/axgbe/xgbe.h (revision 2b8df536a68169953a9fa470b78a021156d997aa)
144b781cfSAndrew Turner /*
244b781cfSAndrew Turner  * AMD 10Gb Ethernet driver
344b781cfSAndrew Turner  *
47113afc8SEmmanuel Vadot  * Copyright (c) 2014-2016,2020 Advanced Micro Devices, Inc.
57113afc8SEmmanuel Vadot  *
644b781cfSAndrew Turner  * This file is available to you under your choice of the following two
744b781cfSAndrew Turner  * licenses:
844b781cfSAndrew Turner  *
944b781cfSAndrew Turner  * License 1: GPLv2
1044b781cfSAndrew Turner  *
1144b781cfSAndrew Turner  * This file is free software; you may copy, redistribute and/or modify
1244b781cfSAndrew Turner  * it under the terms of the GNU General Public License as published by
1344b781cfSAndrew Turner  * the Free Software Foundation, either version 2 of the License, or (at
1444b781cfSAndrew Turner  * your option) any later version.
1544b781cfSAndrew Turner  *
1644b781cfSAndrew Turner  * This file is distributed in the hope that it will be useful, but
1744b781cfSAndrew Turner  * WITHOUT ANY WARRANTY; without even the implied warranty of
1844b781cfSAndrew Turner  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1944b781cfSAndrew Turner  * General Public License for more details.
2044b781cfSAndrew Turner  *
2144b781cfSAndrew Turner  * You should have received a copy of the GNU General Public License
2244b781cfSAndrew Turner  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
2344b781cfSAndrew Turner  *
2444b781cfSAndrew Turner  * This file incorporates work covered by the following copyright and
2544b781cfSAndrew Turner  * permission notice:
2644b781cfSAndrew Turner  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
2744b781cfSAndrew Turner  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
2844b781cfSAndrew Turner  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
2944b781cfSAndrew Turner  *     and you.
3044b781cfSAndrew Turner  *
3144b781cfSAndrew Turner  *     The Software IS NOT an item of Licensed Software or Licensed Product
3244b781cfSAndrew Turner  *     under any End User Software License Agreement or Agreement for Licensed
3344b781cfSAndrew Turner  *     Product with Synopsys or any supplement thereto.  Permission is hereby
3444b781cfSAndrew Turner  *     granted, free of charge, to any person obtaining a copy of this software
3544b781cfSAndrew Turner  *     annotated with this license and the Software, to deal in the Software
3644b781cfSAndrew Turner  *     without restriction, including without limitation the rights to use,
3744b781cfSAndrew Turner  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
3844b781cfSAndrew Turner  *     of the Software, and to permit persons to whom the Software is furnished
3944b781cfSAndrew Turner  *     to do so, subject to the following conditions:
4044b781cfSAndrew Turner  *
4144b781cfSAndrew Turner  *     The above copyright notice and this permission notice shall be included
4244b781cfSAndrew Turner  *     in all copies or substantial portions of the Software.
4344b781cfSAndrew Turner  *
4444b781cfSAndrew Turner  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
4544b781cfSAndrew Turner  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
4644b781cfSAndrew Turner  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
4744b781cfSAndrew Turner  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
4844b781cfSAndrew Turner  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4944b781cfSAndrew Turner  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5044b781cfSAndrew Turner  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5144b781cfSAndrew Turner  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5244b781cfSAndrew Turner  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5344b781cfSAndrew Turner  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
5444b781cfSAndrew Turner  *     THE POSSIBILITY OF SUCH DAMAGE.
5544b781cfSAndrew Turner  *
5644b781cfSAndrew Turner  *
5744b781cfSAndrew Turner  * License 2: Modified BSD
5844b781cfSAndrew Turner  *
5944b781cfSAndrew Turner  * Redistribution and use in source and binary forms, with or without
6044b781cfSAndrew Turner  * modification, are permitted provided that the following conditions are met:
6144b781cfSAndrew Turner  *     * Redistributions of source code must retain the above copyright
6244b781cfSAndrew Turner  *       notice, this list of conditions and the following disclaimer.
6344b781cfSAndrew Turner  *     * Redistributions in binary form must reproduce the above copyright
6444b781cfSAndrew Turner  *       notice, this list of conditions and the following disclaimer in the
6544b781cfSAndrew Turner  *       documentation and/or other materials provided with the distribution.
6644b781cfSAndrew Turner  *     * Neither the name of Advanced Micro Devices, Inc. nor the
6744b781cfSAndrew Turner  *       names of its contributors may be used to endorse or promote products
6844b781cfSAndrew Turner  *       derived from this software without specific prior written permission.
6944b781cfSAndrew Turner  *
7044b781cfSAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
7144b781cfSAndrew Turner  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7244b781cfSAndrew Turner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7344b781cfSAndrew Turner  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
7444b781cfSAndrew Turner  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7544b781cfSAndrew Turner  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
7644b781cfSAndrew Turner  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7744b781cfSAndrew Turner  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7844b781cfSAndrew Turner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
7944b781cfSAndrew Turner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8044b781cfSAndrew Turner  *
8144b781cfSAndrew Turner  * This file incorporates work covered by the following copyright and
8244b781cfSAndrew Turner  * permission notice:
8344b781cfSAndrew Turner  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
8444b781cfSAndrew Turner  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
8544b781cfSAndrew Turner  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
8644b781cfSAndrew Turner  *     and you.
8744b781cfSAndrew Turner  *
8844b781cfSAndrew Turner  *     The Software IS NOT an item of Licensed Software or Licensed Product
8944b781cfSAndrew Turner  *     under any End User Software License Agreement or Agreement for Licensed
9044b781cfSAndrew Turner  *     Product with Synopsys or any supplement thereto.  Permission is hereby
9144b781cfSAndrew Turner  *     granted, free of charge, to any person obtaining a copy of this software
9244b781cfSAndrew Turner  *     annotated with this license and the Software, to deal in the Software
9344b781cfSAndrew Turner  *     without restriction, including without limitation the rights to use,
9444b781cfSAndrew Turner  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9544b781cfSAndrew Turner  *     of the Software, and to permit persons to whom the Software is furnished
9644b781cfSAndrew Turner  *     to do so, subject to the following conditions:
9744b781cfSAndrew Turner  *
9844b781cfSAndrew Turner  *     The above copyright notice and this permission notice shall be included
9944b781cfSAndrew Turner  *     in all copies or substantial portions of the Software.
10044b781cfSAndrew Turner  *
10144b781cfSAndrew Turner  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
10244b781cfSAndrew Turner  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
10344b781cfSAndrew Turner  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
10444b781cfSAndrew Turner  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
10544b781cfSAndrew Turner  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10644b781cfSAndrew Turner  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10744b781cfSAndrew Turner  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10844b781cfSAndrew Turner  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10944b781cfSAndrew Turner  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
11044b781cfSAndrew Turner  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
11144b781cfSAndrew Turner  *     THE POSSIBILITY OF SUCH DAMAGE.
11244b781cfSAndrew Turner  */
11344b781cfSAndrew Turner 
11444b781cfSAndrew Turner #ifndef __XGBE_H__
11544b781cfSAndrew Turner #define __XGBE_H__
11644b781cfSAndrew Turner 
1177113afc8SEmmanuel Vadot #include <sys/param.h>
1187113afc8SEmmanuel Vadot #include <sys/kernel.h>
1197113afc8SEmmanuel Vadot #include <sys/bus.h>
1207113afc8SEmmanuel Vadot #include <sys/socket.h>
1217113afc8SEmmanuel Vadot #include <sys/bitstring.h>
1227113afc8SEmmanuel Vadot 
1237113afc8SEmmanuel Vadot #include <net/if.h>
1247113afc8SEmmanuel Vadot #include <net/if_media.h>
1257113afc8SEmmanuel Vadot 
1267113afc8SEmmanuel Vadot #include <dev/mii/mii.h>
1277113afc8SEmmanuel Vadot #include <dev/mii/miivar.h>
1287113afc8SEmmanuel Vadot 
1299c6d6488SAndrew Turner #include "xgbe_osdep.h"
1309c6d6488SAndrew Turner 
1319c6d6488SAndrew Turner /* From linux/dcbnl.h */
1329c6d6488SAndrew Turner #define IEEE_8021QAZ_MAX_TCS	8
13344b781cfSAndrew Turner 
13444b781cfSAndrew Turner #define XGBE_DRV_NAME		"amd-xgbe"
1357113afc8SEmmanuel Vadot #define XGBE_DRV_VERSION	"1.0.3"
13644b781cfSAndrew Turner #define XGBE_DRV_DESC		"AMD 10 Gigabit Ethernet Driver"
13744b781cfSAndrew Turner 
13844b781cfSAndrew Turner /* Descriptor related defines */
13944b781cfSAndrew Turner #define XGBE_TX_DESC_CNT	512
14044b781cfSAndrew Turner #define XGBE_TX_DESC_MIN_FREE	(XGBE_TX_DESC_CNT >> 3)
14144b781cfSAndrew Turner #define XGBE_TX_DESC_MAX_PROC	(XGBE_TX_DESC_CNT >> 1)
14244b781cfSAndrew Turner #define XGBE_RX_DESC_CNT	512
14344b781cfSAndrew Turner 
1447113afc8SEmmanuel Vadot #define XGBE_TX_DESC_CNT_MIN	64
1457113afc8SEmmanuel Vadot #define XGBE_TX_DESC_CNT_MAX	4096
1467113afc8SEmmanuel Vadot #define XGBE_RX_DESC_CNT_MIN	64
1477113afc8SEmmanuel Vadot #define XGBE_RX_DESC_CNT_MAX	4096
1487113afc8SEmmanuel Vadot #define XGBE_TX_DESC_CNT_DEFAULT 512
1497113afc8SEmmanuel Vadot #define XGBE_RX_DESC_CNT_DEFAULT 512
1507113afc8SEmmanuel Vadot 
15144b781cfSAndrew Turner #define XGBE_TX_MAX_BUF_SIZE	(0x3fff & ~(64 - 1))
15244b781cfSAndrew Turner 
15344b781cfSAndrew Turner /* Descriptors required for maximum contiguous TSO/GSO packet */
15444b781cfSAndrew Turner #define XGBE_TX_MAX_SPLIT	((GSO_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
15544b781cfSAndrew Turner 
15644b781cfSAndrew Turner /* Maximum possible descriptors needed for an SKB:
15744b781cfSAndrew Turner  * - Maximum number of SKB frags
15844b781cfSAndrew Turner  * - Maximum descriptors for contiguous TSO/GSO packet
15944b781cfSAndrew Turner  * - Possible context descriptor
16044b781cfSAndrew Turner  * - Possible TSO header descriptor
16144b781cfSAndrew Turner  */
16244b781cfSAndrew Turner #define XGBE_TX_MAX_DESCS	(MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
16344b781cfSAndrew Turner 
1649c6d6488SAndrew Turner #define XGBE_RX_MIN_BUF_SIZE	1522
16544b781cfSAndrew Turner #define XGBE_RX_BUF_ALIGN	64
16644b781cfSAndrew Turner #define XGBE_SKB_ALLOC_SIZE	256
1677113afc8SEmmanuel Vadot #define XGBE_SPH_HDSMS_SIZE	2	/* Keep in sync with SKB_ALLOC_SIZ */
16844b781cfSAndrew Turner 
16944b781cfSAndrew Turner #define XGBE_MAX_DMA_CHANNELS	16
17044b781cfSAndrew Turner #define XGBE_MAX_QUEUES		16
1717113afc8SEmmanuel Vadot #define XGBE_PRIORITY_QUEUES	8
17244b781cfSAndrew Turner #define XGBE_DMA_STOP_TIMEOUT	5
17344b781cfSAndrew Turner 
17444b781cfSAndrew Turner /* DMA cache settings - Outer sharable, write-back, write-allocate */
1757113afc8SEmmanuel Vadot #define XGBE_DMA_OS_ARCR	0x002b2b2b
1767113afc8SEmmanuel Vadot #define XGBE_DMA_OS_AWCR	0x2f2f2f2f
17744b781cfSAndrew Turner 
17844b781cfSAndrew Turner /* DMA cache settings - System, no caches used */
1797113afc8SEmmanuel Vadot #define XGBE_DMA_SYS_ARCR	0x00303030
1807113afc8SEmmanuel Vadot #define XGBE_DMA_SYS_AWCR	0x30303030
18144b781cfSAndrew Turner 
1827113afc8SEmmanuel Vadot /* DMA cache settings - PCI device */
183*2b8df536SStephan de Wit #define XGBE_DMA_PCI_ARCR	0x000f0f0f
184*2b8df536SStephan de Wit #define XGBE_DMA_PCI_AWCR	0x0f0f0f0f
185*2b8df536SStephan de Wit #define XGBE_DMA_PCI_AWARCR	0x00000f0f
1867113afc8SEmmanuel Vadot 
1877113afc8SEmmanuel Vadot /* DMA channel interrupt modes */
1887113afc8SEmmanuel Vadot #define XGBE_IRQ_MODE_EDGE	0
1897113afc8SEmmanuel Vadot #define XGBE_IRQ_MODE_LEVEL	1
19044b781cfSAndrew Turner 
19144b781cfSAndrew Turner #define XGMAC_MIN_PACKET	60
19244b781cfSAndrew Turner #define XGMAC_STD_PACKET_MTU	1500
19344b781cfSAndrew Turner #define XGMAC_MAX_STD_PACKET	1518
19444b781cfSAndrew Turner #define XGMAC_JUMBO_PACKET_MTU	9000
19544b781cfSAndrew Turner #define XGMAC_MAX_JUMBO_PACKET	9018
1967113afc8SEmmanuel Vadot #define XGMAC_ETH_PREAMBLE	(12 + 8) /* Inter-frame gap + preamble */
1977113afc8SEmmanuel Vadot 
1987113afc8SEmmanuel Vadot #define XGMAC_PFC_DATA_LEN	46
1997113afc8SEmmanuel Vadot #define XGMAC_PFC_DELAYS	14000
2007113afc8SEmmanuel Vadot 
2017113afc8SEmmanuel Vadot #define XGMAC_PRIO_QUEUES(_cnt)					\
2027113afc8SEmmanuel Vadot 	min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
20344b781cfSAndrew Turner 
20444b781cfSAndrew Turner /* Common property names */
20544b781cfSAndrew Turner #define XGBE_MAC_ADDR_PROPERTY	"mac-address"
20644b781cfSAndrew Turner #define XGBE_PHY_MODE_PROPERTY	"phy-mode"
20744b781cfSAndrew Turner #define XGBE_DMA_IRQS_PROPERTY	"amd,per-channel-interrupt"
20844b781cfSAndrew Turner #define XGBE_SPEEDSET_PROPERTY	"amd,speed-set"
20944b781cfSAndrew Turner #define XGBE_BLWC_PROPERTY	"amd,serdes-blwc"
21044b781cfSAndrew Turner #define XGBE_CDR_RATE_PROPERTY	"amd,serdes-cdr-rate"
21144b781cfSAndrew Turner #define XGBE_PQ_SKEW_PROPERTY	"amd,serdes-pq-skew"
21244b781cfSAndrew Turner #define XGBE_TX_AMP_PROPERTY	"amd,serdes-tx-amp"
21344b781cfSAndrew Turner #define XGBE_DFE_CFG_PROPERTY	"amd,serdes-dfe-tap-config"
21444b781cfSAndrew Turner #define XGBE_DFE_ENA_PROPERTY	"amd,serdes-dfe-tap-enable"
21544b781cfSAndrew Turner 
21644b781cfSAndrew Turner /* Device-tree clock names */
21744b781cfSAndrew Turner #define XGBE_DMA_CLOCK		"dma_clk"
21844b781cfSAndrew Turner #define XGBE_PTP_CLOCK		"ptp_clk"
21944b781cfSAndrew Turner 
22044b781cfSAndrew Turner /* ACPI property names */
22144b781cfSAndrew Turner #define XGBE_ACPI_DMA_FREQ	"amd,dma-freq"
22244b781cfSAndrew Turner #define XGBE_ACPI_PTP_FREQ	"amd,ptp-freq"
22344b781cfSAndrew Turner 
2247113afc8SEmmanuel Vadot /* PCI BAR mapping */
2257113afc8SEmmanuel Vadot #define XGBE_XGMAC_BAR		0
2267113afc8SEmmanuel Vadot #define XGBE_XPCS_BAR		1
2277113afc8SEmmanuel Vadot #define XGBE_MAC_PROP_OFFSET	0x1d000
2287113afc8SEmmanuel Vadot #define XGBE_I2C_CTRL_OFFSET	0x1e000
2297113afc8SEmmanuel Vadot 
2307113afc8SEmmanuel Vadot /* PCI MSI/MSIx support */
2317113afc8SEmmanuel Vadot #define XGBE_MSI_BASE_COUNT	4
2327113afc8SEmmanuel Vadot #define XGBE_MSI_MIN_COUNT	(XGBE_MSI_BASE_COUNT + 1)
2337113afc8SEmmanuel Vadot 
2347113afc8SEmmanuel Vadot /* PCI clock frequencies */
2357113afc8SEmmanuel Vadot #define XGBE_V2_DMA_CLOCK_FREQ	500000000	/* 500 MHz */
2367113afc8SEmmanuel Vadot #define XGBE_V2_PTP_CLOCK_FREQ	125000000	/* 125 MHz */
2377113afc8SEmmanuel Vadot 
23844b781cfSAndrew Turner /* Timestamp support - values based on 50MHz PTP clock
23944b781cfSAndrew Turner  *   50MHz => 20 nsec
24044b781cfSAndrew Turner  */
24144b781cfSAndrew Turner #define XGBE_TSTAMP_SSINC	20
24244b781cfSAndrew Turner #define XGBE_TSTAMP_SNSINC	0
24344b781cfSAndrew Turner 
24444b781cfSAndrew Turner /* Driver PMT macros */
24544b781cfSAndrew Turner #define XGMAC_DRIVER_CONTEXT	1
24644b781cfSAndrew Turner #define XGMAC_IOCTL_CONTEXT	2
24744b781cfSAndrew Turner 
2487113afc8SEmmanuel Vadot #define XGMAC_FIFO_MIN_ALLOC	2048
2497113afc8SEmmanuel Vadot #define XGMAC_FIFO_UNIT		256
2507113afc8SEmmanuel Vadot #define XGMAC_FIFO_ALIGN(_x)				\
2517113afc8SEmmanuel Vadot 	(((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
2527113afc8SEmmanuel Vadot #define XGMAC_FIFO_FC_OFF	2048
2537113afc8SEmmanuel Vadot #define XGMAC_FIFO_FC_MIN	4096
25444b781cfSAndrew Turner #define XGBE_FIFO_MAX		81920
25544b781cfSAndrew Turner 
25644b781cfSAndrew Turner #define XGBE_TC_MIN_QUANTUM	10
25744b781cfSAndrew Turner 
25844b781cfSAndrew Turner /* Helper macro for descriptor handling
25944b781cfSAndrew Turner  *  Always use XGBE_GET_DESC_DATA to access the descriptor data
26044b781cfSAndrew Turner  *  since the index is free-running and needs to be and-ed
26144b781cfSAndrew Turner  *  with the descriptor count value of the ring to index to
26244b781cfSAndrew Turner  *  the proper descriptor data.
26344b781cfSAndrew Turner  */
26444b781cfSAndrew Turner #define XGBE_GET_DESC_DATA(_ring, _idx)				\
26544b781cfSAndrew Turner 	((_ring)->rdata +					\
26644b781cfSAndrew Turner 	 ((_idx) & ((_ring)->rdesc_count - 1)))
26744b781cfSAndrew Turner 
26844b781cfSAndrew Turner /* Default coalescing parameters */
26944b781cfSAndrew Turner #define XGMAC_INIT_DMA_TX_USECS		1000
27044b781cfSAndrew Turner #define XGMAC_INIT_DMA_TX_FRAMES	25
27144b781cfSAndrew Turner 
27244b781cfSAndrew Turner #define XGMAC_MAX_DMA_RIWT		0xff
27344b781cfSAndrew Turner #define XGMAC_INIT_DMA_RX_USECS		30
27444b781cfSAndrew Turner #define XGMAC_INIT_DMA_RX_FRAMES	25
27544b781cfSAndrew Turner 
27644b781cfSAndrew Turner /* Flow control queue count */
27744b781cfSAndrew Turner #define XGMAC_MAX_FLOW_CONTROL_QUEUES	8
27844b781cfSAndrew Turner 
2797113afc8SEmmanuel Vadot /* Flow control threshold units */
2807113afc8SEmmanuel Vadot #define XGMAC_FLOW_CONTROL_UNIT		512
2817113afc8SEmmanuel Vadot #define XGMAC_FLOW_CONTROL_ALIGN(_x)				\
2827113afc8SEmmanuel Vadot 	(((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
2837113afc8SEmmanuel Vadot #define XGMAC_FLOW_CONTROL_VALUE(_x)				\
2847113afc8SEmmanuel Vadot 	(((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
2857113afc8SEmmanuel Vadot #define XGMAC_FLOW_CONTROL_MAX		33280
2867113afc8SEmmanuel Vadot 
28744b781cfSAndrew Turner /* Maximum MAC address hash table size (256 bits = 8 bytes) */
28844b781cfSAndrew Turner #define XGBE_MAC_HASH_TABLE_SIZE	8
28944b781cfSAndrew Turner 
29044b781cfSAndrew Turner /* Receive Side Scaling */
29144b781cfSAndrew Turner #define XGBE_RSS_HASH_KEY_SIZE		40
29244b781cfSAndrew Turner #define XGBE_RSS_MAX_TABLE_SIZE		256
29344b781cfSAndrew Turner #define XGBE_RSS_LOOKUP_TABLE_TYPE	0
29444b781cfSAndrew Turner #define XGBE_RSS_HASH_KEY_TYPE		1
29544b781cfSAndrew Turner 
29644b781cfSAndrew Turner /* Auto-negotiation */
29744b781cfSAndrew Turner #define XGBE_AN_MS_TIMEOUT		500
29844b781cfSAndrew Turner #define XGBE_LINK_TIMEOUT		10
29944b781cfSAndrew Turner 
3007113afc8SEmmanuel Vadot #define XGBE_SGMII_AN_LINK_STATUS	BIT(1)
3017113afc8SEmmanuel Vadot #define XGBE_SGMII_AN_LINK_SPEED	(BIT(2) | BIT(3))
3027113afc8SEmmanuel Vadot #define XGBE_SGMII_AN_LINK_SPEED_100	0x04
3037113afc8SEmmanuel Vadot #define XGBE_SGMII_AN_LINK_SPEED_1000	0x08
3047113afc8SEmmanuel Vadot #define XGBE_SGMII_AN_LINK_DUPLEX	BIT(4)
3057113afc8SEmmanuel Vadot 
3067113afc8SEmmanuel Vadot /* ECC correctable error notification window (seconds) */
3077113afc8SEmmanuel Vadot #define XGBE_ECC_LIMIT			60
3087113afc8SEmmanuel Vadot 
30944b781cfSAndrew Turner #define XGBE_AN_INT_CMPLT		0x01
31044b781cfSAndrew Turner #define XGBE_AN_INC_LINK		0x02
31144b781cfSAndrew Turner #define XGBE_AN_PG_RCV			0x04
31244b781cfSAndrew Turner #define XGBE_AN_INT_MASK		0x07
31344b781cfSAndrew Turner 
3147113afc8SEmmanuel Vadot #define	XGBE_SGMII_AN_LINK_STATUS	BIT(1)
3157113afc8SEmmanuel Vadot #define	XGBE_SGMII_AN_LINK_SPEED	(BIT(2) | BIT(3))
3167113afc8SEmmanuel Vadot #define	XGBE_SGMII_AN_LINK_SPEED_100	0x04
3177113afc8SEmmanuel Vadot #define	XGBE_SGMII_AN_LINK_SPEED_1000	0x08
3187113afc8SEmmanuel Vadot #define	XGBE_SGMII_AN_LINK_DUPLEX	BIT(4)
3197113afc8SEmmanuel Vadot 
32044b781cfSAndrew Turner /* Rate-change complete wait/retry count */
32144b781cfSAndrew Turner #define XGBE_RATECHANGE_COUNT		500
32244b781cfSAndrew Turner 
32344b781cfSAndrew Turner /* Default SerDes settings */
32444b781cfSAndrew Turner #define XGBE_SPEED_10000_BLWC		0
32544b781cfSAndrew Turner #define XGBE_SPEED_10000_CDR		0x7
32644b781cfSAndrew Turner #define XGBE_SPEED_10000_PLL		0x1
32744b781cfSAndrew Turner #define XGBE_SPEED_10000_PQ		0x12
32844b781cfSAndrew Turner #define XGBE_SPEED_10000_RATE		0x0
32944b781cfSAndrew Turner #define XGBE_SPEED_10000_TXAMP		0xa
33044b781cfSAndrew Turner #define XGBE_SPEED_10000_WORD		0x7
33144b781cfSAndrew Turner #define XGBE_SPEED_10000_DFE_TAP_CONFIG	0x1
33244b781cfSAndrew Turner #define XGBE_SPEED_10000_DFE_TAP_ENABLE	0x7f
33344b781cfSAndrew Turner 
33444b781cfSAndrew Turner #define XGBE_SPEED_2500_BLWC		1
33544b781cfSAndrew Turner #define XGBE_SPEED_2500_CDR		0x2
33644b781cfSAndrew Turner #define XGBE_SPEED_2500_PLL		0x0
33744b781cfSAndrew Turner #define XGBE_SPEED_2500_PQ		0xa
33844b781cfSAndrew Turner #define XGBE_SPEED_2500_RATE		0x1
33944b781cfSAndrew Turner #define XGBE_SPEED_2500_TXAMP		0xf
34044b781cfSAndrew Turner #define XGBE_SPEED_2500_WORD		0x1
34144b781cfSAndrew Turner #define XGBE_SPEED_2500_DFE_TAP_CONFIG	0x3
34244b781cfSAndrew Turner #define XGBE_SPEED_2500_DFE_TAP_ENABLE	0x0
34344b781cfSAndrew Turner 
34444b781cfSAndrew Turner #define XGBE_SPEED_1000_BLWC		1
34544b781cfSAndrew Turner #define XGBE_SPEED_1000_CDR		0x2
34644b781cfSAndrew Turner #define XGBE_SPEED_1000_PLL		0x0
34744b781cfSAndrew Turner #define XGBE_SPEED_1000_PQ		0xa
34844b781cfSAndrew Turner #define XGBE_SPEED_1000_RATE		0x3
34944b781cfSAndrew Turner #define XGBE_SPEED_1000_TXAMP		0xf
35044b781cfSAndrew Turner #define XGBE_SPEED_1000_WORD		0x1
35144b781cfSAndrew Turner #define XGBE_SPEED_1000_DFE_TAP_CONFIG	0x3
35244b781cfSAndrew Turner #define XGBE_SPEED_1000_DFE_TAP_ENABLE	0x0
35344b781cfSAndrew Turner 
3547113afc8SEmmanuel Vadot /* TSO related macros */
3557113afc8SEmmanuel Vadot #define XGBE_TSO_MAX_SIZE		UINT16_MAX
3567113afc8SEmmanuel Vadot 
3577113afc8SEmmanuel Vadot /* MDIO port types */
3587113afc8SEmmanuel Vadot #define XGMAC_MAX_C22_PORT		3
3597113afc8SEmmanuel Vadot 
3607113afc8SEmmanuel Vadot /* Link mode bit operations */
3617113afc8SEmmanuel Vadot #define XGBE_ZERO_SUP(_phy)	      \
3627113afc8SEmmanuel Vadot 	((_phy)->supported = 0)
3637113afc8SEmmanuel Vadot 
3647113afc8SEmmanuel Vadot #define XGBE_SET_SUP(_phy, _mode)	\
3657113afc8SEmmanuel Vadot 	((_phy)->supported |= SUPPORTED_##_mode)
3667113afc8SEmmanuel Vadot 
3677113afc8SEmmanuel Vadot #define XGBE_CLR_SUP(_phy, _mode)	\
3687113afc8SEmmanuel Vadot 	((_phy)->supported &= ~SUPPORTED_##_mode)
3697113afc8SEmmanuel Vadot 
3707113afc8SEmmanuel Vadot #define XGBE_IS_SUP(_phy, _mode) \
3717113afc8SEmmanuel Vadot 	((_phy)->supported & SUPPORTED_##_mode)
3727113afc8SEmmanuel Vadot 
3737113afc8SEmmanuel Vadot #define XGBE_ZERO_ADV(_phy)	      \
3747113afc8SEmmanuel Vadot 	((_phy)->advertising = 0)
3757113afc8SEmmanuel Vadot 
3767113afc8SEmmanuel Vadot #define XGBE_SET_ADV(_phy, _mode)	\
3777113afc8SEmmanuel Vadot 	((_phy)->advertising |= ADVERTISED_##_mode)
3787113afc8SEmmanuel Vadot 
3797113afc8SEmmanuel Vadot #define XGBE_CLR_ADV(_phy, _mode)	\
3807113afc8SEmmanuel Vadot 	((_phy)->advertising &= ~ADVERTISED_##_mode)
3817113afc8SEmmanuel Vadot 
3827113afc8SEmmanuel Vadot #define XGBE_ADV(_phy, _mode)	    \
3837113afc8SEmmanuel Vadot 	((_phy)->advertising & ADVERTISED_##_mode)
3847113afc8SEmmanuel Vadot 
3857113afc8SEmmanuel Vadot #define XGBE_ZERO_LP_ADV(_phy)	   \
3867113afc8SEmmanuel Vadot 	((_phy)->lp_advertising = 0)
3877113afc8SEmmanuel Vadot 
3887113afc8SEmmanuel Vadot #define XGBE_SET_LP_ADV(_phy, _mode)     \
3897113afc8SEmmanuel Vadot 	((_phy)->lp_advertising |= ADVERTISED_##_mode)
3907113afc8SEmmanuel Vadot 
3917113afc8SEmmanuel Vadot #define XGBE_CLR_LP_ADV(_phy, _mode)     \
3927113afc8SEmmanuel Vadot 	((_phy)->lp_advertising &= ~ADVERTISED_##_mode)
3937113afc8SEmmanuel Vadot 
3947113afc8SEmmanuel Vadot #define XGBE_LP_ADV(_phy, _mode)	 \
3957113afc8SEmmanuel Vadot 	((_phy)->lp_advertising & ADVERTISED_##_mode)
3967113afc8SEmmanuel Vadot 
3977113afc8SEmmanuel Vadot #define XGBE_LM_COPY(_dphy, _dname, _sphy, _sname)	\
3987113afc8SEmmanuel Vadot 	((_dphy)->_dname = (_sphy)->_sname)
3997113afc8SEmmanuel Vadot 
40044b781cfSAndrew Turner struct xgbe_prv_data;
40144b781cfSAndrew Turner 
40244b781cfSAndrew Turner struct xgbe_packet_data {
4039c6d6488SAndrew Turner 	struct mbuf *m;
40444b781cfSAndrew Turner 
40544b781cfSAndrew Turner 	unsigned int attributes;
40644b781cfSAndrew Turner 
40744b781cfSAndrew Turner 	unsigned int errors;
40844b781cfSAndrew Turner 
40944b781cfSAndrew Turner 	unsigned int rdesc_count;
41044b781cfSAndrew Turner 	unsigned int length;
41144b781cfSAndrew Turner 
4127113afc8SEmmanuel Vadot 	unsigned int header_len;
4137113afc8SEmmanuel Vadot 	unsigned int tcp_header_len;
4147113afc8SEmmanuel Vadot 	unsigned int tcp_payload_len;
4157113afc8SEmmanuel Vadot 	unsigned short mss;
4167113afc8SEmmanuel Vadot 
4177113afc8SEmmanuel Vadot 	unsigned short vlan_ctag;
4187113afc8SEmmanuel Vadot 
4197113afc8SEmmanuel Vadot 	uint64_t rx_tstamp;
42044b781cfSAndrew Turner 
42144b781cfSAndrew Turner 	unsigned int tx_packets;
42244b781cfSAndrew Turner 	unsigned int tx_bytes;
4237113afc8SEmmanuel Vadot 
4247113afc8SEmmanuel Vadot 	uint32_t rss_hash;
4257113afc8SEmmanuel Vadot 	uint32_t rss_hash_type;
42644b781cfSAndrew Turner };
42744b781cfSAndrew Turner 
42844b781cfSAndrew Turner /* Common Rx and Tx descriptor mapping */
42944b781cfSAndrew Turner struct xgbe_ring_desc {
43044b781cfSAndrew Turner 	__le32 desc0;
43144b781cfSAndrew Turner 	__le32 desc1;
43244b781cfSAndrew Turner 	__le32 desc2;
43344b781cfSAndrew Turner 	__le32 desc3;
43444b781cfSAndrew Turner };
43544b781cfSAndrew Turner 
43644b781cfSAndrew Turner /* Tx-related ring data */
43744b781cfSAndrew Turner struct xgbe_tx_ring_data {
43844b781cfSAndrew Turner 	unsigned int packets;		/* BQL packet count */
43944b781cfSAndrew Turner 	unsigned int bytes;		/* BQL byte count */
44044b781cfSAndrew Turner };
44144b781cfSAndrew Turner 
44244b781cfSAndrew Turner /* Rx-related ring data */
44344b781cfSAndrew Turner struct xgbe_rx_ring_data {
44444b781cfSAndrew Turner 	unsigned short hdr_len;		/* Length of received header */
44544b781cfSAndrew Turner 	unsigned short len;		/* Length of received packet */
44644b781cfSAndrew Turner };
44744b781cfSAndrew Turner 
44844b781cfSAndrew Turner /* Structure used to hold information related to the descriptor
44944b781cfSAndrew Turner  * and the packet associated with the descriptor (always use
45044b781cfSAndrew Turner  * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
45144b781cfSAndrew Turner  */
45244b781cfSAndrew Turner struct xgbe_ring_data {
45344b781cfSAndrew Turner 	struct xgbe_ring_desc *rdesc;	/* Virtual address of descriptor */
4549c6d6488SAndrew Turner 	bus_addr_t rdata_paddr;
45544b781cfSAndrew Turner 
45644b781cfSAndrew Turner 	struct xgbe_tx_ring_data tx;	/* Tx-related data */
45744b781cfSAndrew Turner 	struct xgbe_rx_ring_data rx;	/* Rx-related data */
4587113afc8SEmmanuel Vadot 
4597113afc8SEmmanuel Vadot 
4607113afc8SEmmanuel Vadot 	/* Incomplete receive save location.  If the budget is exhausted
4617113afc8SEmmanuel Vadot 	 * or the last descriptor (last normal descriptor or a following
4627113afc8SEmmanuel Vadot 	 * context descriptor) has not been DMA'd yet the current state
4637113afc8SEmmanuel Vadot 	 * of the receive processing needs to be saved.
4647113afc8SEmmanuel Vadot 	 */
4657113afc8SEmmanuel Vadot 	unsigned int state_saved;
4667113afc8SEmmanuel Vadot 	struct {
4677113afc8SEmmanuel Vadot 		struct mbuf *m;
4687113afc8SEmmanuel Vadot 		unsigned int len;
4697113afc8SEmmanuel Vadot 		unsigned int error;
4707113afc8SEmmanuel Vadot 	} state;
4717113afc8SEmmanuel Vadot 
47244b781cfSAndrew Turner };
47344b781cfSAndrew Turner 
47444b781cfSAndrew Turner struct xgbe_ring {
47544b781cfSAndrew Turner 	/* Ring lock - used just for TX rings at the moment */
47644b781cfSAndrew Turner 	spinlock_t lock;
47744b781cfSAndrew Turner 
47844b781cfSAndrew Turner 	/* Per packet related information */
47944b781cfSAndrew Turner 	struct xgbe_packet_data packet_data;
48044b781cfSAndrew Turner 
48144b781cfSAndrew Turner 	/* Virtual/DMA addresses and count of allocated descriptor memory */
48244b781cfSAndrew Turner 	struct xgbe_ring_desc *rdesc;
4839c6d6488SAndrew Turner 	bus_addr_t rdesc_paddr;
48444b781cfSAndrew Turner 	unsigned int rdesc_count;
48544b781cfSAndrew Turner 
48644b781cfSAndrew Turner 	/* Array of descriptor data corresponding the descriptor memory
48744b781cfSAndrew Turner 	 * (always use the XGBE_GET_DESC_DATA macro to access this data)
48844b781cfSAndrew Turner 	 */
48944b781cfSAndrew Turner 	struct xgbe_ring_data *rdata;
49044b781cfSAndrew Turner 
49144b781cfSAndrew Turner 	/* Ring index values
49244b781cfSAndrew Turner 	 *  cur   - Tx: index of descriptor to be used for current transfer
49344b781cfSAndrew Turner 	 *	  Rx: index of descriptor to check for packet availability
49444b781cfSAndrew Turner 	 *  dirty - Tx: index of descriptor to check for transfer complete
49544b781cfSAndrew Turner 	 *	  Rx: index of descriptor to check for buffer reallocation
49644b781cfSAndrew Turner 	 */
49744b781cfSAndrew Turner 	unsigned int cur;
49844b781cfSAndrew Turner 	unsigned int dirty;
49944b781cfSAndrew Turner 
50044b781cfSAndrew Turner 	/* Coalesce frame count used for interrupt bit setting */
50144b781cfSAndrew Turner 	unsigned int coalesce_count;
50244b781cfSAndrew Turner 
50344b781cfSAndrew Turner 	union {
50444b781cfSAndrew Turner 		struct {
50544b781cfSAndrew Turner 			unsigned int queue_stopped;
50644b781cfSAndrew Turner 			unsigned int xmit_more;
50744b781cfSAndrew Turner 			unsigned short cur_mss;
50844b781cfSAndrew Turner 			unsigned short cur_vlan_ctag;
50944b781cfSAndrew Turner 		} tx;
51044b781cfSAndrew Turner 	};
5117113afc8SEmmanuel Vadot 
5127113afc8SEmmanuel Vadot 	uint16_t prev_pidx;
5137113afc8SEmmanuel Vadot 	uint8_t prev_count;
5147113afc8SEmmanuel Vadot 
5159c6d6488SAndrew Turner } __aligned(CACHE_LINE_SIZE);
51644b781cfSAndrew Turner 
51744b781cfSAndrew Turner /* Structure used to describe the descriptor rings associated with
51844b781cfSAndrew Turner  * a DMA channel.
51944b781cfSAndrew Turner  */
52044b781cfSAndrew Turner struct xgbe_channel {
52144b781cfSAndrew Turner 	char name[16];
52244b781cfSAndrew Turner 
52344b781cfSAndrew Turner 	/* Address of private data area for device */
52444b781cfSAndrew Turner 	struct xgbe_prv_data *pdata;
52544b781cfSAndrew Turner 
52644b781cfSAndrew Turner 	/* Queue index and base address of queue's DMA registers */
52744b781cfSAndrew Turner 	unsigned int queue_index;
5289c6d6488SAndrew Turner 	bus_space_tag_t dma_tag;
5299c6d6488SAndrew Turner 	bus_space_handle_t dma_handle;
5307113afc8SEmmanuel Vadot 	int	dma_irq_rid;
53144b781cfSAndrew Turner 
53244b781cfSAndrew Turner 	/* Per channel interrupt irq number */
5339c6d6488SAndrew Turner 	struct resource *dma_irq_res;
5349c6d6488SAndrew Turner 	void *dma_irq_tag;
53544b781cfSAndrew Turner 
5367113afc8SEmmanuel Vadot 	/* Per channel interrupt enablement tracker */
5377113afc8SEmmanuel Vadot 	unsigned int curr_ier;
53844b781cfSAndrew Turner 	unsigned int saved_ier;
53944b781cfSAndrew Turner 
54044b781cfSAndrew Turner 	struct xgbe_ring *tx_ring;
54144b781cfSAndrew Turner 	struct xgbe_ring *rx_ring;
5429c6d6488SAndrew Turner } __aligned(CACHE_LINE_SIZE);
54344b781cfSAndrew Turner 
54444b781cfSAndrew Turner enum xgbe_state {
54544b781cfSAndrew Turner 	XGBE_DOWN,
54644b781cfSAndrew Turner 	XGBE_LINK_INIT,
54744b781cfSAndrew Turner 	XGBE_LINK_ERR,
5487113afc8SEmmanuel Vadot 	XGBE_STOPPED,
54944b781cfSAndrew Turner };
55044b781cfSAndrew Turner 
55144b781cfSAndrew Turner enum xgbe_int {
55244b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_TI,
55344b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_TPS,
55444b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_TBU,
55544b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_RI,
55644b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_RBU,
55744b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_RPS,
55844b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_TI_RI,
55944b781cfSAndrew Turner 	XGMAC_INT_DMA_CH_SR_FBE,
56044b781cfSAndrew Turner 	XGMAC_INT_DMA_ALL,
56144b781cfSAndrew Turner };
56244b781cfSAndrew Turner 
56344b781cfSAndrew Turner enum xgbe_int_state {
56444b781cfSAndrew Turner 	XGMAC_INT_STATE_SAVE,
56544b781cfSAndrew Turner 	XGMAC_INT_STATE_RESTORE,
56644b781cfSAndrew Turner };
56744b781cfSAndrew Turner 
5687113afc8SEmmanuel Vadot enum xgbe_ecc_sec {
5697113afc8SEmmanuel Vadot 	XGBE_ECC_SEC_TX,
5707113afc8SEmmanuel Vadot 	XGBE_ECC_SEC_RX,
5717113afc8SEmmanuel Vadot 	XGBE_ECC_SEC_DESC,
5727113afc8SEmmanuel Vadot };
5737113afc8SEmmanuel Vadot 
57444b781cfSAndrew Turner enum xgbe_speed {
57544b781cfSAndrew Turner 	XGBE_SPEED_1000 = 0,
57644b781cfSAndrew Turner 	XGBE_SPEED_2500,
57744b781cfSAndrew Turner 	XGBE_SPEED_10000,
57844b781cfSAndrew Turner 	XGBE_SPEEDS,
57944b781cfSAndrew Turner };
58044b781cfSAndrew Turner 
5817113afc8SEmmanuel Vadot enum xgbe_xpcs_access {
5827113afc8SEmmanuel Vadot 	XGBE_XPCS_ACCESS_V1 = 0,
5837113afc8SEmmanuel Vadot 	XGBE_XPCS_ACCESS_V2,
5847113afc8SEmmanuel Vadot };
5857113afc8SEmmanuel Vadot 
5867113afc8SEmmanuel Vadot enum xgbe_an_mode {
5877113afc8SEmmanuel Vadot 	XGBE_AN_MODE_CL73 = 0,
5887113afc8SEmmanuel Vadot 	XGBE_AN_MODE_CL73_REDRV,
5897113afc8SEmmanuel Vadot 	XGBE_AN_MODE_CL37,
5907113afc8SEmmanuel Vadot 	XGBE_AN_MODE_CL37_SGMII,
5917113afc8SEmmanuel Vadot 	XGBE_AN_MODE_NONE,
5927113afc8SEmmanuel Vadot };
5937113afc8SEmmanuel Vadot 
59444b781cfSAndrew Turner enum xgbe_an {
59544b781cfSAndrew Turner 	XGBE_AN_READY = 0,
59644b781cfSAndrew Turner 	XGBE_AN_PAGE_RECEIVED,
59744b781cfSAndrew Turner 	XGBE_AN_INCOMPAT_LINK,
59844b781cfSAndrew Turner 	XGBE_AN_COMPLETE,
59944b781cfSAndrew Turner 	XGBE_AN_NO_LINK,
60044b781cfSAndrew Turner 	XGBE_AN_ERROR,
60144b781cfSAndrew Turner };
60244b781cfSAndrew Turner 
60344b781cfSAndrew Turner enum xgbe_rx {
60444b781cfSAndrew Turner 	XGBE_RX_BPA = 0,
60544b781cfSAndrew Turner 	XGBE_RX_XNP,
60644b781cfSAndrew Turner 	XGBE_RX_COMPLETE,
60744b781cfSAndrew Turner 	XGBE_RX_ERROR,
60844b781cfSAndrew Turner };
60944b781cfSAndrew Turner 
61044b781cfSAndrew Turner enum xgbe_mode {
61144b781cfSAndrew Turner 	XGBE_MODE_KR = 0,
61244b781cfSAndrew Turner 	XGBE_MODE_KX,
6137113afc8SEmmanuel Vadot 	XGBE_MODE_KX_1000,
6147113afc8SEmmanuel Vadot 	XGBE_MODE_KX_2500,
6157113afc8SEmmanuel Vadot 	XGBE_MODE_X,
6167113afc8SEmmanuel Vadot 	XGBE_MODE_SGMII_100,
6177113afc8SEmmanuel Vadot 	XGBE_MODE_SGMII_1000,
6187113afc8SEmmanuel Vadot 	XGBE_MODE_SFI,
6197113afc8SEmmanuel Vadot 	XGBE_MODE_UNKNOWN,
62044b781cfSAndrew Turner };
62144b781cfSAndrew Turner 
62244b781cfSAndrew Turner enum xgbe_speedset {
62344b781cfSAndrew Turner 	XGBE_SPEEDSET_1000_10000 = 0,
62444b781cfSAndrew Turner 	XGBE_SPEEDSET_2500_10000,
62544b781cfSAndrew Turner };
62644b781cfSAndrew Turner 
6277113afc8SEmmanuel Vadot enum xgbe_mdio_mode {
6287113afc8SEmmanuel Vadot 	XGBE_MDIO_MODE_NONE = 0,
6297113afc8SEmmanuel Vadot 	XGBE_MDIO_MODE_CL22,
6307113afc8SEmmanuel Vadot 	XGBE_MDIO_MODE_CL45,
6317113afc8SEmmanuel Vadot };
6327113afc8SEmmanuel Vadot 
63344b781cfSAndrew Turner struct xgbe_phy {
6347113afc8SEmmanuel Vadot 	uint32_t supported;
6357113afc8SEmmanuel Vadot 	uint32_t advertising;
6367113afc8SEmmanuel Vadot 	uint32_t lp_advertising;
63744b781cfSAndrew Turner 
63844b781cfSAndrew Turner 	int address;
63944b781cfSAndrew Turner 
64044b781cfSAndrew Turner 	int autoneg;
64144b781cfSAndrew Turner 	int speed;
64244b781cfSAndrew Turner 	int duplex;
64344b781cfSAndrew Turner 
64444b781cfSAndrew Turner 	int link;
64544b781cfSAndrew Turner 
64644b781cfSAndrew Turner 	int pause_autoneg;
64744b781cfSAndrew Turner 	int tx_pause;
64844b781cfSAndrew Turner 	int rx_pause;
6497113afc8SEmmanuel Vadot 
6507113afc8SEmmanuel Vadot 	int pause;
6517113afc8SEmmanuel Vadot 	int asym_pause;
6527113afc8SEmmanuel Vadot };
6537113afc8SEmmanuel Vadot 
6547113afc8SEmmanuel Vadot enum xgbe_i2c_cmd {
6557113afc8SEmmanuel Vadot 	XGBE_I2C_CMD_READ = 0,
6567113afc8SEmmanuel Vadot 	XGBE_I2C_CMD_WRITE,
6577113afc8SEmmanuel Vadot };
6587113afc8SEmmanuel Vadot 
6597113afc8SEmmanuel Vadot struct xgbe_i2c_op {
6607113afc8SEmmanuel Vadot 	enum xgbe_i2c_cmd cmd;
6617113afc8SEmmanuel Vadot 
6627113afc8SEmmanuel Vadot 	unsigned int target;
6637113afc8SEmmanuel Vadot 
6647113afc8SEmmanuel Vadot 	void *buf;
6657113afc8SEmmanuel Vadot 	unsigned int len;
6667113afc8SEmmanuel Vadot };
6677113afc8SEmmanuel Vadot 
6687113afc8SEmmanuel Vadot struct xgbe_i2c_op_state {
6697113afc8SEmmanuel Vadot 	struct xgbe_i2c_op *op;
6707113afc8SEmmanuel Vadot 
6717113afc8SEmmanuel Vadot 	unsigned int tx_len;
6727113afc8SEmmanuel Vadot 	unsigned char *tx_buf;
6737113afc8SEmmanuel Vadot 
6747113afc8SEmmanuel Vadot 	unsigned int rx_len;
6757113afc8SEmmanuel Vadot 	unsigned char *rx_buf;
6767113afc8SEmmanuel Vadot 
6777113afc8SEmmanuel Vadot 	unsigned int tx_abort_source;
6787113afc8SEmmanuel Vadot 
6797113afc8SEmmanuel Vadot 	int ret;
6807113afc8SEmmanuel Vadot };
6817113afc8SEmmanuel Vadot 
6827113afc8SEmmanuel Vadot struct xgbe_i2c {
6837113afc8SEmmanuel Vadot 	unsigned int started;
6847113afc8SEmmanuel Vadot 	unsigned int max_speed_mode;
6857113afc8SEmmanuel Vadot 	unsigned int rx_fifo_size;
6867113afc8SEmmanuel Vadot 	unsigned int tx_fifo_size;
6877113afc8SEmmanuel Vadot 
6887113afc8SEmmanuel Vadot 	struct xgbe_i2c_op_state op_state;
68944b781cfSAndrew Turner };
69044b781cfSAndrew Turner 
69144b781cfSAndrew Turner struct xgbe_mmc_stats {
69244b781cfSAndrew Turner 	/* Tx Stats */
6937113afc8SEmmanuel Vadot 	uint64_t txoctetcount_gb;
6947113afc8SEmmanuel Vadot 	uint64_t txframecount_gb;
6957113afc8SEmmanuel Vadot 	uint64_t txbroadcastframes_g;
6967113afc8SEmmanuel Vadot 	uint64_t txmulticastframes_g;
6977113afc8SEmmanuel Vadot 	uint64_t tx64octets_gb;
6987113afc8SEmmanuel Vadot 	uint64_t tx65to127octets_gb;
6997113afc8SEmmanuel Vadot 	uint64_t tx128to255octets_gb;
7007113afc8SEmmanuel Vadot 	uint64_t tx256to511octets_gb;
7017113afc8SEmmanuel Vadot 	uint64_t tx512to1023octets_gb;
7027113afc8SEmmanuel Vadot 	uint64_t tx1024tomaxoctets_gb;
7037113afc8SEmmanuel Vadot 	uint64_t txunicastframes_gb;
7047113afc8SEmmanuel Vadot 	uint64_t txmulticastframes_gb;
7057113afc8SEmmanuel Vadot 	uint64_t txbroadcastframes_gb;
7067113afc8SEmmanuel Vadot 	uint64_t txunderflowerror;
7077113afc8SEmmanuel Vadot 	uint64_t txoctetcount_g;
7087113afc8SEmmanuel Vadot 	uint64_t txframecount_g;
7097113afc8SEmmanuel Vadot 	uint64_t txpauseframes;
7107113afc8SEmmanuel Vadot 	uint64_t txvlanframes_g;
71144b781cfSAndrew Turner 
71244b781cfSAndrew Turner 	/* Rx Stats */
7137113afc8SEmmanuel Vadot 	uint64_t rxframecount_gb;
7147113afc8SEmmanuel Vadot 	uint64_t rxoctetcount_gb;
7157113afc8SEmmanuel Vadot 	uint64_t rxoctetcount_g;
7167113afc8SEmmanuel Vadot 	uint64_t rxbroadcastframes_g;
7177113afc8SEmmanuel Vadot 	uint64_t rxmulticastframes_g;
7187113afc8SEmmanuel Vadot 	uint64_t rxcrcerror;
7197113afc8SEmmanuel Vadot 	uint64_t rxrunterror;
7207113afc8SEmmanuel Vadot 	uint64_t rxjabbererror;
7217113afc8SEmmanuel Vadot 	uint64_t rxundersize_g;
7227113afc8SEmmanuel Vadot 	uint64_t rxoversize_g;
7237113afc8SEmmanuel Vadot 	uint64_t rx64octets_gb;
7247113afc8SEmmanuel Vadot 	uint64_t rx65to127octets_gb;
7257113afc8SEmmanuel Vadot 	uint64_t rx128to255octets_gb;
7267113afc8SEmmanuel Vadot 	uint64_t rx256to511octets_gb;
7277113afc8SEmmanuel Vadot 	uint64_t rx512to1023octets_gb;
7287113afc8SEmmanuel Vadot 	uint64_t rx1024tomaxoctets_gb;
7297113afc8SEmmanuel Vadot 	uint64_t rxunicastframes_g;
7307113afc8SEmmanuel Vadot 	uint64_t rxlengtherror;
7317113afc8SEmmanuel Vadot 	uint64_t rxoutofrangetype;
7327113afc8SEmmanuel Vadot 	uint64_t rxpauseframes;
7337113afc8SEmmanuel Vadot 	uint64_t rxfifooverflow;
7347113afc8SEmmanuel Vadot 	uint64_t rxvlanframes_gb;
7357113afc8SEmmanuel Vadot 	uint64_t rxwatchdogerror;
73644b781cfSAndrew Turner };
73744b781cfSAndrew Turner 
73844b781cfSAndrew Turner struct xgbe_ext_stats {
7397113afc8SEmmanuel Vadot 	uint64_t tx_tso_packets;
7407113afc8SEmmanuel Vadot 	uint64_t rx_split_header_packets;
7417113afc8SEmmanuel Vadot 	uint64_t rx_buffer_unavailable;
7427113afc8SEmmanuel Vadot 
7437113afc8SEmmanuel Vadot 	uint64_t txq_packets[XGBE_MAX_DMA_CHANNELS];
7447113afc8SEmmanuel Vadot 	uint64_t txq_bytes[XGBE_MAX_DMA_CHANNELS];
7457113afc8SEmmanuel Vadot 	uint64_t rxq_packets[XGBE_MAX_DMA_CHANNELS];
7467113afc8SEmmanuel Vadot 	uint64_t rxq_bytes[XGBE_MAX_DMA_CHANNELS];
7477113afc8SEmmanuel Vadot 
7487113afc8SEmmanuel Vadot 	uint64_t tx_vxlan_packets;
7497113afc8SEmmanuel Vadot 	uint64_t rx_vxlan_packets;
7507113afc8SEmmanuel Vadot 	uint64_t rx_csum_errors;
7517113afc8SEmmanuel Vadot 	uint64_t rx_vxlan_csum_errors;
75244b781cfSAndrew Turner };
75344b781cfSAndrew Turner 
75444b781cfSAndrew Turner struct xgbe_hw_if {
75544b781cfSAndrew Turner 	int (*tx_complete)(struct xgbe_ring_desc *);
75644b781cfSAndrew Turner 
7577113afc8SEmmanuel Vadot 	int (*set_mac_address)(struct xgbe_prv_data *, uint8_t *addr);
75844b781cfSAndrew Turner 	int (*config_rx_mode)(struct xgbe_prv_data *);
75944b781cfSAndrew Turner 
76044b781cfSAndrew Turner 	int (*enable_rx_csum)(struct xgbe_prv_data *);
76144b781cfSAndrew Turner 	int (*disable_rx_csum)(struct xgbe_prv_data *);
76244b781cfSAndrew Turner 
76344b781cfSAndrew Turner 	int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
76444b781cfSAndrew Turner 	int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
76544b781cfSAndrew Turner 	int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
76644b781cfSAndrew Turner 	int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
76744b781cfSAndrew Turner 	int (*update_vlan_hash_table)(struct xgbe_prv_data *);
76844b781cfSAndrew Turner 
76944b781cfSAndrew Turner 	int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
77044b781cfSAndrew Turner 	void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
7717113afc8SEmmanuel Vadot 	int (*set_speed)(struct xgbe_prv_data *, int);
7727113afc8SEmmanuel Vadot 
7737113afc8SEmmanuel Vadot 	int (*set_ext_mii_mode)(struct xgbe_prv_data *, unsigned int,
7747113afc8SEmmanuel Vadot 	    enum xgbe_mdio_mode);
7757113afc8SEmmanuel Vadot 	int (*read_ext_mii_regs)(struct xgbe_prv_data *, int, int);
7767113afc8SEmmanuel Vadot 	int (*write_ext_mii_regs)(struct xgbe_prv_data *, int, int, uint16_t);
7777113afc8SEmmanuel Vadot 
7787113afc8SEmmanuel Vadot 	int (*set_gpio)(struct xgbe_prv_data *, unsigned int);
7797113afc8SEmmanuel Vadot 	int (*clr_gpio)(struct xgbe_prv_data *, unsigned int);
78044b781cfSAndrew Turner 
78144b781cfSAndrew Turner 	void (*enable_tx)(struct xgbe_prv_data *);
78244b781cfSAndrew Turner 	void (*disable_tx)(struct xgbe_prv_data *);
78344b781cfSAndrew Turner 	void (*enable_rx)(struct xgbe_prv_data *);
78444b781cfSAndrew Turner 	void (*disable_rx)(struct xgbe_prv_data *);
78544b781cfSAndrew Turner 
78644b781cfSAndrew Turner 	void (*powerup_tx)(struct xgbe_prv_data *);
78744b781cfSAndrew Turner 	void (*powerdown_tx)(struct xgbe_prv_data *);
78844b781cfSAndrew Turner 	void (*powerup_rx)(struct xgbe_prv_data *);
78944b781cfSAndrew Turner 	void (*powerdown_rx)(struct xgbe_prv_data *);
79044b781cfSAndrew Turner 
79144b781cfSAndrew Turner 	int (*init)(struct xgbe_prv_data *);
79244b781cfSAndrew Turner 	int (*exit)(struct xgbe_prv_data *);
79344b781cfSAndrew Turner 
79444b781cfSAndrew Turner 	int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
79544b781cfSAndrew Turner 	int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
79644b781cfSAndrew Turner 	int (*dev_read)(struct xgbe_channel *);
79744b781cfSAndrew Turner 	void (*tx_desc_init)(struct xgbe_channel *);
79844b781cfSAndrew Turner 	void (*rx_desc_init)(struct xgbe_channel *);
79944b781cfSAndrew Turner 	void (*tx_desc_reset)(struct xgbe_ring_data *);
80044b781cfSAndrew Turner 	int (*is_last_desc)(struct xgbe_ring_desc *);
80144b781cfSAndrew Turner 	int (*is_context_desc)(struct xgbe_ring_desc *);
80244b781cfSAndrew Turner 
80344b781cfSAndrew Turner 	/* For FLOW ctrl */
80444b781cfSAndrew Turner 	int (*config_tx_flow_control)(struct xgbe_prv_data *);
80544b781cfSAndrew Turner 	int (*config_rx_flow_control)(struct xgbe_prv_data *);
80644b781cfSAndrew Turner 
80744b781cfSAndrew Turner 	/* For RX coalescing */
80844b781cfSAndrew Turner 	int (*config_rx_coalesce)(struct xgbe_prv_data *);
80944b781cfSAndrew Turner 	int (*config_tx_coalesce)(struct xgbe_prv_data *);
81044b781cfSAndrew Turner 	unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
81144b781cfSAndrew Turner 	unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
81244b781cfSAndrew Turner 
81344b781cfSAndrew Turner 	/* For RX and TX threshold config */
81444b781cfSAndrew Turner 	int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
81544b781cfSAndrew Turner 	int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
81644b781cfSAndrew Turner 
81744b781cfSAndrew Turner 	/* For RX and TX Store and Forward Mode config */
81844b781cfSAndrew Turner 	int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
81944b781cfSAndrew Turner 	int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
82044b781cfSAndrew Turner 
82144b781cfSAndrew Turner 	/* For TX DMA Operate on Second Frame config */
82244b781cfSAndrew Turner 	int (*config_osp_mode)(struct xgbe_prv_data *);
82344b781cfSAndrew Turner 
82444b781cfSAndrew Turner 	/* For MMC statistics */
82544b781cfSAndrew Turner 	void (*rx_mmc_int)(struct xgbe_prv_data *);
82644b781cfSAndrew Turner 	void (*tx_mmc_int)(struct xgbe_prv_data *);
82744b781cfSAndrew Turner 	void (*read_mmc_stats)(struct xgbe_prv_data *);
82844b781cfSAndrew Turner 
82944b781cfSAndrew Turner 	/* For Receive Side Scaling */
8307113afc8SEmmanuel Vadot 	int (*enable_rss)(struct xgbe_prv_data *);
83144b781cfSAndrew Turner 	int (*disable_rss)(struct xgbe_prv_data *);
8327113afc8SEmmanuel Vadot 	int (*set_rss_hash_key)(struct xgbe_prv_data *, const uint8_t *);
8337113afc8SEmmanuel Vadot 	int (*set_rss_lookup_table)(struct xgbe_prv_data *, const uint32_t *);
8347113afc8SEmmanuel Vadot };
8357113afc8SEmmanuel Vadot 
8367113afc8SEmmanuel Vadot /* This structure represents implementation specific routines for an
8377113afc8SEmmanuel Vadot  * implementation of a PHY. All routines are required unless noted below.
8387113afc8SEmmanuel Vadot  *   Optional routines:
8397113afc8SEmmanuel Vadot  *     an_pre, an_post
8407113afc8SEmmanuel Vadot  *     kr_training_pre, kr_training_post
8417113afc8SEmmanuel Vadot  *     module_info, module_eeprom
8427113afc8SEmmanuel Vadot  */
8437113afc8SEmmanuel Vadot struct xgbe_phy_impl_if {
8447113afc8SEmmanuel Vadot 	/* Perform Setup/teardown actions */
8457113afc8SEmmanuel Vadot 	int (*init)(struct xgbe_prv_data *);
8467113afc8SEmmanuel Vadot 	void (*exit)(struct xgbe_prv_data *);
8477113afc8SEmmanuel Vadot 
8487113afc8SEmmanuel Vadot 	/* Perform start/stop specific actions */
8497113afc8SEmmanuel Vadot 	int (*reset)(struct xgbe_prv_data *);
8507113afc8SEmmanuel Vadot 	int (*start)(struct xgbe_prv_data *);
8517113afc8SEmmanuel Vadot 	void (*stop)(struct xgbe_prv_data *);
8527113afc8SEmmanuel Vadot 
8537113afc8SEmmanuel Vadot 	/* Return the link status */
8547113afc8SEmmanuel Vadot 	int (*link_status)(struct xgbe_prv_data *, int *);
8557113afc8SEmmanuel Vadot 
8567113afc8SEmmanuel Vadot 	/* Indicate if a particular speed is valid */
8577113afc8SEmmanuel Vadot 	bool (*valid_speed)(struct xgbe_prv_data *, int);
8587113afc8SEmmanuel Vadot 
8597113afc8SEmmanuel Vadot 	/* Check if the specified mode can/should be used */
8607113afc8SEmmanuel Vadot 	bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
8617113afc8SEmmanuel Vadot 	/* Switch the PHY into various modes */
8627113afc8SEmmanuel Vadot 	void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
8637113afc8SEmmanuel Vadot 	/* Retrieve mode needed for a specific speed */
8647113afc8SEmmanuel Vadot 	enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
8657113afc8SEmmanuel Vadot 	/* Retrieve new/next mode when trying to auto-negotiate */
8667113afc8SEmmanuel Vadot 	enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
8677113afc8SEmmanuel Vadot 	/* Retrieve current mode */
8687113afc8SEmmanuel Vadot 	enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
8697113afc8SEmmanuel Vadot 	/* Retrieve interface sub-type */
8707113afc8SEmmanuel Vadot 	void (*get_type)(struct xgbe_prv_data *, struct ifmediareq *);
8717113afc8SEmmanuel Vadot 
8727113afc8SEmmanuel Vadot 	/* Retrieve current auto-negotiation mode */
8737113afc8SEmmanuel Vadot 	enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
8747113afc8SEmmanuel Vadot 
8757113afc8SEmmanuel Vadot 	/* Configure auto-negotiation settings */
8767113afc8SEmmanuel Vadot 	int (*an_config)(struct xgbe_prv_data *);
8777113afc8SEmmanuel Vadot 
8787113afc8SEmmanuel Vadot 	/* Set/override auto-negotiation advertisement settings */
8797113afc8SEmmanuel Vadot 	void (*an_advertising)(struct xgbe_prv_data *,
8807113afc8SEmmanuel Vadot 	    struct xgbe_phy *);
8817113afc8SEmmanuel Vadot 
8827113afc8SEmmanuel Vadot 	/* Process results of auto-negotiation */
8837113afc8SEmmanuel Vadot 	enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
8847113afc8SEmmanuel Vadot 
8857113afc8SEmmanuel Vadot 	/* Pre/Post auto-negotiation support */
8867113afc8SEmmanuel Vadot 	void (*an_pre)(struct xgbe_prv_data *);
8877113afc8SEmmanuel Vadot 	void (*an_post)(struct xgbe_prv_data *);
8887113afc8SEmmanuel Vadot 
8897113afc8SEmmanuel Vadot 	/* Pre/Post KR training enablement support */
8907113afc8SEmmanuel Vadot 	void (*kr_training_pre)(struct xgbe_prv_data *);
8917113afc8SEmmanuel Vadot 	void (*kr_training_post)(struct xgbe_prv_data *);
8927113afc8SEmmanuel Vadot 
8937113afc8SEmmanuel Vadot 	/* SFP module related info */
8947113afc8SEmmanuel Vadot 	int (*module_info)(struct xgbe_prv_data *pdata);
8957113afc8SEmmanuel Vadot 	int (*module_eeprom)(struct xgbe_prv_data *pdata);
89644b781cfSAndrew Turner };
89744b781cfSAndrew Turner 
89844b781cfSAndrew Turner struct xgbe_phy_if {
8997113afc8SEmmanuel Vadot 	/* For PHY setup/teardown */
9007113afc8SEmmanuel Vadot 	int (*phy_init)(struct xgbe_prv_data *);
9017113afc8SEmmanuel Vadot 	void (*phy_exit)(struct xgbe_prv_data *);
90244b781cfSAndrew Turner 
90344b781cfSAndrew Turner 	/* For PHY support when setting device up/down */
90444b781cfSAndrew Turner 	int (*phy_reset)(struct xgbe_prv_data *);
90544b781cfSAndrew Turner 	int (*phy_start)(struct xgbe_prv_data *);
90644b781cfSAndrew Turner 	void (*phy_stop)(struct xgbe_prv_data *);
90744b781cfSAndrew Turner 
90844b781cfSAndrew Turner 	/* For PHY support while device is up */
90944b781cfSAndrew Turner 	void (*phy_status)(struct xgbe_prv_data *);
91044b781cfSAndrew Turner 	int (*phy_config_aneg)(struct xgbe_prv_data *);
9117113afc8SEmmanuel Vadot 
9127113afc8SEmmanuel Vadot 	/* For PHY settings validation */
9137113afc8SEmmanuel Vadot 	bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
9147113afc8SEmmanuel Vadot 
9157113afc8SEmmanuel Vadot 	/* For single interrupt support */
9167113afc8SEmmanuel Vadot 	void (*an_isr)(struct xgbe_prv_data *);
9177113afc8SEmmanuel Vadot 
9187113afc8SEmmanuel Vadot 	/* PHY implementation specific services */
9197113afc8SEmmanuel Vadot 	struct xgbe_phy_impl_if phy_impl;
9207113afc8SEmmanuel Vadot };
9217113afc8SEmmanuel Vadot 
9227113afc8SEmmanuel Vadot struct xgbe_i2c_if {
9237113afc8SEmmanuel Vadot 	/* For initial I2C setup */
9247113afc8SEmmanuel Vadot 	int (*i2c_init)(struct xgbe_prv_data *);
9257113afc8SEmmanuel Vadot 
9267113afc8SEmmanuel Vadot 	/* For I2C support when setting device up/down */
9277113afc8SEmmanuel Vadot 	int (*i2c_start)(struct xgbe_prv_data *);
9287113afc8SEmmanuel Vadot 	void (*i2c_stop)(struct xgbe_prv_data *);
9297113afc8SEmmanuel Vadot 
9307113afc8SEmmanuel Vadot 	/* For performing I2C operations */
9317113afc8SEmmanuel Vadot 	int (*i2c_xfer)(struct xgbe_prv_data *, struct xgbe_i2c_op *);
9327113afc8SEmmanuel Vadot 
9337113afc8SEmmanuel Vadot 	/* For single interrupt support */
9347113afc8SEmmanuel Vadot 	void (*i2c_isr)(struct xgbe_prv_data *);
93544b781cfSAndrew Turner };
93644b781cfSAndrew Turner 
93744b781cfSAndrew Turner struct xgbe_desc_if {
93844b781cfSAndrew Turner 	int (*alloc_ring_resources)(struct xgbe_prv_data *);
93944b781cfSAndrew Turner 	void (*free_ring_resources)(struct xgbe_prv_data *);
9409c6d6488SAndrew Turner 	int (*map_tx_skb)(struct xgbe_channel *, struct mbuf *);
94144b781cfSAndrew Turner 	int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
94244b781cfSAndrew Turner 			     struct xgbe_ring_data *);
94344b781cfSAndrew Turner 	void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
94444b781cfSAndrew Turner 	void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
94544b781cfSAndrew Turner 	void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
94644b781cfSAndrew Turner };
94744b781cfSAndrew Turner 
94844b781cfSAndrew Turner /* This structure contains flags that indicate what hardware features
94944b781cfSAndrew Turner  * or configurations are present in the device.
95044b781cfSAndrew Turner  */
95144b781cfSAndrew Turner struct xgbe_hw_features {
95244b781cfSAndrew Turner 	/* HW Version */
95344b781cfSAndrew Turner 	unsigned int version;
95444b781cfSAndrew Turner 
95544b781cfSAndrew Turner 	/* HW Feature Register0 */
95644b781cfSAndrew Turner 	unsigned int gmii;		/* 1000 Mbps support */
95744b781cfSAndrew Turner 	unsigned int vlhash;		/* VLAN Hash Filter */
95844b781cfSAndrew Turner 	unsigned int sma;		/* SMA(MDIO) Interface */
95944b781cfSAndrew Turner 	unsigned int rwk;		/* PMT remote wake-up packet */
96044b781cfSAndrew Turner 	unsigned int mgk;		/* PMT magic packet */
96144b781cfSAndrew Turner 	unsigned int mmc;		/* RMON module */
96244b781cfSAndrew Turner 	unsigned int aoe;		/* ARP Offload */
96344b781cfSAndrew Turner 	unsigned int ts;		/* IEEE 1588-2008 Advanced Timestamp */
96444b781cfSAndrew Turner 	unsigned int eee;		/* Energy Efficient Ethernet */
96544b781cfSAndrew Turner 	unsigned int tx_coe;		/* Tx Checksum Offload */
96644b781cfSAndrew Turner 	unsigned int rx_coe;		/* Rx Checksum Offload */
96744b781cfSAndrew Turner 	unsigned int addn_mac;		/* Additional MAC Addresses */
96844b781cfSAndrew Turner 	unsigned int ts_src;		/* Timestamp Source */
96944b781cfSAndrew Turner 	unsigned int sa_vlan_ins;	/* Source Address or VLAN Insertion */
9707113afc8SEmmanuel Vadot 	unsigned int vxn;		/* VXLAN/NVGRE */
97144b781cfSAndrew Turner 
97244b781cfSAndrew Turner 	/* HW Feature Register1 */
97344b781cfSAndrew Turner 	unsigned int rx_fifo_size;	/* MTL Receive FIFO Size */
97444b781cfSAndrew Turner 	unsigned int tx_fifo_size;	/* MTL Transmit FIFO Size */
97544b781cfSAndrew Turner 	unsigned int adv_ts_hi;		/* Advance Timestamping High Word */
97644b781cfSAndrew Turner 	unsigned int dma_width;		/* DMA width */
97744b781cfSAndrew Turner 	unsigned int dcb;		/* DCB Feature */
97844b781cfSAndrew Turner 	unsigned int sph;		/* Split Header Feature */
97944b781cfSAndrew Turner 	unsigned int tso;		/* TCP Segmentation Offload */
98044b781cfSAndrew Turner 	unsigned int dma_debug;		/* DMA Debug Registers */
98144b781cfSAndrew Turner 	unsigned int rss;		/* Receive Side Scaling */
98244b781cfSAndrew Turner 	unsigned int tc_cnt;		/* Number of Traffic Classes */
98344b781cfSAndrew Turner 	unsigned int hash_table_size;	/* Hash Table Size */
98444b781cfSAndrew Turner 	unsigned int l3l4_filter_num;	/* Number of L3-L4 Filters */
98544b781cfSAndrew Turner 
98644b781cfSAndrew Turner 	/* HW Feature Register2 */
98744b781cfSAndrew Turner 	unsigned int rx_q_cnt;		/* Number of MTL Receive Queues */
98844b781cfSAndrew Turner 	unsigned int tx_q_cnt;		/* Number of MTL Transmit Queues */
98944b781cfSAndrew Turner 	unsigned int rx_ch_cnt;		/* Number of DMA Receive Channels */
99044b781cfSAndrew Turner 	unsigned int tx_ch_cnt;		/* Number of DMA Transmit Channels */
99144b781cfSAndrew Turner 	unsigned int pps_out_num;	/* Number of PPS outputs */
99244b781cfSAndrew Turner 	unsigned int aux_snap_num;	/* Number of Aux snapshot inputs */
99344b781cfSAndrew Turner };
99444b781cfSAndrew Turner 
9957113afc8SEmmanuel Vadot struct xgbe_version_data {
9967113afc8SEmmanuel Vadot 	void (*init_function_ptrs_phy_impl)(struct xgbe_phy_if *);
9977113afc8SEmmanuel Vadot 	enum xgbe_xpcs_access xpcs_access;
9987113afc8SEmmanuel Vadot 	unsigned int mmc_64bit;
9997113afc8SEmmanuel Vadot 	unsigned int tx_max_fifo_size;
10007113afc8SEmmanuel Vadot 	unsigned int rx_max_fifo_size;
10017113afc8SEmmanuel Vadot 	unsigned int tx_tstamp_workaround;
10027113afc8SEmmanuel Vadot 	unsigned int ecc_support;
10037113afc8SEmmanuel Vadot 	unsigned int i2c_support;
10047113afc8SEmmanuel Vadot 	unsigned int irq_reissue_support;
10057113afc8SEmmanuel Vadot 	unsigned int tx_desc_prefetch;
10067113afc8SEmmanuel Vadot 	unsigned int rx_desc_prefetch;
10077113afc8SEmmanuel Vadot 	unsigned int an_cdr_workaround;
10087113afc8SEmmanuel Vadot };
10097113afc8SEmmanuel Vadot 
101044b781cfSAndrew Turner struct xgbe_prv_data {
1011402810d3SJustin Hibbits 	if_t netdev;
10127113afc8SEmmanuel Vadot 
101344b781cfSAndrew Turner 	struct platform_device *pdev;
101444b781cfSAndrew Turner 	struct acpi_device *adev;
10159c6d6488SAndrew Turner 	device_t dev;
101644b781cfSAndrew Turner 
10177113afc8SEmmanuel Vadot 	/* Version related data */
10187113afc8SEmmanuel Vadot 	struct xgbe_version_data *vdata;
10197113afc8SEmmanuel Vadot 
102044b781cfSAndrew Turner 	/* ACPI or DT flag */
102144b781cfSAndrew Turner 	unsigned int use_acpi;
102244b781cfSAndrew Turner 
102344b781cfSAndrew Turner 	/* XGMAC/XPCS related mmio registers */
10249c6d6488SAndrew Turner 	struct resource *xgmac_res;	/* XGMAC CSRs */
10259c6d6488SAndrew Turner 	struct resource *xpcs_res;	/* XPCS MMD registers */
10269c6d6488SAndrew Turner 	struct resource *rxtx_res;	/* SerDes Rx/Tx CSRs */
10279c6d6488SAndrew Turner 	struct resource *sir0_res;	/* SerDes integration registers (1/2) */
10289c6d6488SAndrew Turner 	struct resource *sir1_res;	/* SerDes integration registers (2/2) */
102944b781cfSAndrew Turner 
10307113afc8SEmmanuel Vadot 	/* Port property registers */
10317113afc8SEmmanuel Vadot 	unsigned int pp0;
10327113afc8SEmmanuel Vadot 	unsigned int pp1;
10337113afc8SEmmanuel Vadot 	unsigned int pp2;
10347113afc8SEmmanuel Vadot 	unsigned int pp3;
10357113afc8SEmmanuel Vadot 	unsigned int pp4;
10367113afc8SEmmanuel Vadot 
10379c6d6488SAndrew Turner 	/* DMA tag */
10389c6d6488SAndrew Turner 	bus_dma_tag_t dmat;
103944b781cfSAndrew Turner 
104044b781cfSAndrew Turner 	/* XPCS indirect addressing lock */
104144b781cfSAndrew Turner 	spinlock_t xpcs_lock;
10427113afc8SEmmanuel Vadot 	unsigned int xpcs_window_def_reg;
10437113afc8SEmmanuel Vadot 	unsigned int xpcs_window_sel_reg;
10447113afc8SEmmanuel Vadot 	unsigned int xpcs_window;
10457113afc8SEmmanuel Vadot 	unsigned int xpcs_window_size;
10467113afc8SEmmanuel Vadot 	unsigned int xpcs_window_mask;
10477113afc8SEmmanuel Vadot 
10487113afc8SEmmanuel Vadot 	/* RSS addressing mutex */
10497113afc8SEmmanuel Vadot 	struct mtx rss_mutex;
105044b781cfSAndrew Turner 
105144b781cfSAndrew Turner 	/* Flags representing xgbe_state */
105244b781cfSAndrew Turner 	unsigned long dev_state;
105344b781cfSAndrew Turner 
10547113afc8SEmmanuel Vadot 	/* ECC support */
10557113afc8SEmmanuel Vadot 	unsigned long tx_sec_period;
10567113afc8SEmmanuel Vadot 	unsigned long tx_ded_period;
10577113afc8SEmmanuel Vadot 	unsigned long rx_sec_period;
10587113afc8SEmmanuel Vadot 	unsigned long rx_ded_period;
10597113afc8SEmmanuel Vadot 	unsigned long desc_sec_period;
10607113afc8SEmmanuel Vadot 	unsigned long desc_ded_period;
106144b781cfSAndrew Turner 
10627113afc8SEmmanuel Vadot 	unsigned int tx_sec_count;
10637113afc8SEmmanuel Vadot 	unsigned int tx_ded_count;
10647113afc8SEmmanuel Vadot 	unsigned int rx_sec_count;
10657113afc8SEmmanuel Vadot 	unsigned int rx_ded_count;
10667113afc8SEmmanuel Vadot 	unsigned int desc_ded_count;
10677113afc8SEmmanuel Vadot 	unsigned int desc_sec_count;
10687113afc8SEmmanuel Vadot 
10697113afc8SEmmanuel Vadot 	struct if_irq	dev_irq;
10707113afc8SEmmanuel Vadot 
10717113afc8SEmmanuel Vadot 	struct resource	*dev_irq_res;
10727113afc8SEmmanuel Vadot 	struct resource	*ecc_irq_res;
10737113afc8SEmmanuel Vadot 	struct resource	*i2c_irq_res;
10747113afc8SEmmanuel Vadot 	struct resource	*an_irq_res;
10757113afc8SEmmanuel Vadot 
10767113afc8SEmmanuel Vadot 	int ecc_rid;
10777113afc8SEmmanuel Vadot 	int i2c_rid;
10787113afc8SEmmanuel Vadot 	int an_rid;
10797113afc8SEmmanuel Vadot 
10807113afc8SEmmanuel Vadot 	void *dev_irq_tag;
10817113afc8SEmmanuel Vadot 	void *ecc_irq_tag;
10827113afc8SEmmanuel Vadot 	void *i2c_irq_tag;
10837113afc8SEmmanuel Vadot 	void *an_irq_tag;
10847113afc8SEmmanuel Vadot 
10857113afc8SEmmanuel Vadot 	struct resource *chan_irq_res[XGBE_MAX_DMA_CHANNELS];
10867113afc8SEmmanuel Vadot 
10877113afc8SEmmanuel Vadot 	unsigned int per_channel_irq;
10887113afc8SEmmanuel Vadot 	unsigned int irq_count;
10897113afc8SEmmanuel Vadot 	unsigned int channel_irq_count;
10907113afc8SEmmanuel Vadot 	unsigned int channel_irq_mode;
10917113afc8SEmmanuel Vadot 
10927113afc8SEmmanuel Vadot 	char ecc_name[IFNAMSIZ + 32];
10937113afc8SEmmanuel Vadot 
10947113afc8SEmmanuel Vadot 	unsigned int isr_as_tasklet;
109544b781cfSAndrew Turner 	struct xgbe_hw_if hw_if;
109644b781cfSAndrew Turner 	struct xgbe_phy_if phy_if;
109744b781cfSAndrew Turner 	struct xgbe_desc_if desc_if;
10987113afc8SEmmanuel Vadot 	struct xgbe_i2c_if i2c_if;
109944b781cfSAndrew Turner 
110044b781cfSAndrew Turner 	/* AXI DMA settings */
110144b781cfSAndrew Turner 	unsigned int coherent;
11027113afc8SEmmanuel Vadot 	unsigned int arcr;
11037113afc8SEmmanuel Vadot 	unsigned int awcr;
11047113afc8SEmmanuel Vadot 	unsigned int awarcr;
110544b781cfSAndrew Turner 
110644b781cfSAndrew Turner 	/* Service routine support */
11079c6d6488SAndrew Turner 	struct taskqueue *dev_workqueue;
11089c6d6488SAndrew Turner 	struct task service_work;
11099c6d6488SAndrew Turner 	struct callout service_timer;
11107113afc8SEmmanuel Vadot 	struct mtx timer_mutex;
111144b781cfSAndrew Turner 
111244b781cfSAndrew Turner 	/* Rings for Tx/Rx on a DMA channel */
11137113afc8SEmmanuel Vadot 	struct xgbe_channel *channel[XGBE_MAX_DMA_CHANNELS];
11147113afc8SEmmanuel Vadot 	unsigned int tx_max_channel_count;
11157113afc8SEmmanuel Vadot 	unsigned int rx_max_channel_count;
11167113afc8SEmmanuel Vadot 	unsigned int total_channel_count;
111744b781cfSAndrew Turner 	unsigned int channel_count;
111844b781cfSAndrew Turner 	unsigned int tx_ring_count;
111944b781cfSAndrew Turner 	unsigned int tx_desc_count;
112044b781cfSAndrew Turner 	unsigned int rx_ring_count;
112144b781cfSAndrew Turner 	unsigned int rx_desc_count;
112244b781cfSAndrew Turner 
11237113afc8SEmmanuel Vadot 	unsigned int new_tx_ring_count;
11247113afc8SEmmanuel Vadot 	unsigned int new_rx_ring_count;
11257113afc8SEmmanuel Vadot 
11267113afc8SEmmanuel Vadot 	unsigned int tx_max_q_count;
11277113afc8SEmmanuel Vadot 	unsigned int rx_max_q_count;
112844b781cfSAndrew Turner 	unsigned int tx_q_count;
112944b781cfSAndrew Turner 	unsigned int rx_q_count;
113044b781cfSAndrew Turner 
113144b781cfSAndrew Turner 	/* Tx/Rx common settings */
11327113afc8SEmmanuel Vadot 	unsigned int blen;
11337113afc8SEmmanuel Vadot 	unsigned int pbl;
11347113afc8SEmmanuel Vadot 	unsigned int aal;
11357113afc8SEmmanuel Vadot 	unsigned int rd_osr_limit;
11367113afc8SEmmanuel Vadot 	unsigned int wr_osr_limit;
113744b781cfSAndrew Turner 
113844b781cfSAndrew Turner 	/* Tx settings */
113944b781cfSAndrew Turner 	unsigned int tx_sf_mode;
114044b781cfSAndrew Turner 	unsigned int tx_threshold;
114144b781cfSAndrew Turner 	unsigned int tx_osp_mode;
11427113afc8SEmmanuel Vadot 	unsigned int tx_max_fifo_size;
114344b781cfSAndrew Turner 
114444b781cfSAndrew Turner 	/* Rx settings */
114544b781cfSAndrew Turner 	unsigned int rx_sf_mode;
114644b781cfSAndrew Turner 	unsigned int rx_threshold;
11477113afc8SEmmanuel Vadot 	unsigned int rx_max_fifo_size;
114844b781cfSAndrew Turner 
114944b781cfSAndrew Turner 	/* Tx coalescing settings */
115044b781cfSAndrew Turner 	unsigned int tx_usecs;
115144b781cfSAndrew Turner 	unsigned int tx_frames;
115244b781cfSAndrew Turner 
115344b781cfSAndrew Turner 	/* Rx coalescing settings */
115444b781cfSAndrew Turner 	unsigned int rx_riwt;
115544b781cfSAndrew Turner 	unsigned int rx_usecs;
115644b781cfSAndrew Turner 	unsigned int rx_frames;
115744b781cfSAndrew Turner 
115844b781cfSAndrew Turner 	/* Current Rx buffer size */
115944b781cfSAndrew Turner 	unsigned int rx_buf_size;
116044b781cfSAndrew Turner 
116144b781cfSAndrew Turner 	/* Flow control settings */
116244b781cfSAndrew Turner 	unsigned int pause_autoneg;
116344b781cfSAndrew Turner 	unsigned int tx_pause;
116444b781cfSAndrew Turner 	unsigned int rx_pause;
11657113afc8SEmmanuel Vadot 	unsigned int rx_rfa[XGBE_MAX_QUEUES];
11667113afc8SEmmanuel Vadot 	unsigned int rx_rfd[XGBE_MAX_QUEUES];
116744b781cfSAndrew Turner 
116844b781cfSAndrew Turner 	/* Receive Side Scaling settings */
11697113afc8SEmmanuel Vadot 	uint8_t rss_key[XGBE_RSS_HASH_KEY_SIZE];
11707113afc8SEmmanuel Vadot 	uint32_t rss_table[XGBE_RSS_MAX_TABLE_SIZE];
11717113afc8SEmmanuel Vadot 	uint32_t rss_options;
11727113afc8SEmmanuel Vadot 	unsigned int enable_rss;
11737113afc8SEmmanuel Vadot 
11747113afc8SEmmanuel Vadot 	/* VXLAN settings */
11757113afc8SEmmanuel Vadot 	unsigned int vxlan_port_set;
11767113afc8SEmmanuel Vadot 	unsigned int vxlan_offloads_set;
11777113afc8SEmmanuel Vadot 	unsigned int vxlan_force_disable;
11787113afc8SEmmanuel Vadot 	unsigned int vxlan_port_count;
11797113afc8SEmmanuel Vadot 	uint16_t vxlan_port;
11807113afc8SEmmanuel Vadot 	uint64_t vxlan_features;
118144b781cfSAndrew Turner 
118244b781cfSAndrew Turner 	/* Netdev related settings */
118344b781cfSAndrew Turner 	unsigned char mac_addr[ETH_ALEN];
11847113afc8SEmmanuel Vadot 	uint64_t netdev_features;
118544b781cfSAndrew Turner 	struct xgbe_mmc_stats mmc_stats;
118644b781cfSAndrew Turner 	struct xgbe_ext_stats ext_stats;
118744b781cfSAndrew Turner 
11887113afc8SEmmanuel Vadot 	/* Filtering support */
11897113afc8SEmmanuel Vadot 	bitstr_t *active_vlans;
11907113afc8SEmmanuel Vadot 	unsigned int num_active_vlans;
11917113afc8SEmmanuel Vadot 
119244b781cfSAndrew Turner 	/* Device clocks */
119344b781cfSAndrew Turner 	struct clk *sysclk;
119444b781cfSAndrew Turner 	unsigned long sysclk_rate;
119544b781cfSAndrew Turner 	struct clk *ptpclk;
119644b781cfSAndrew Turner 	unsigned long ptpclk_rate;
119744b781cfSAndrew Turner 
119844b781cfSAndrew Turner 	/* DCB support */
119944b781cfSAndrew Turner 	unsigned int q2tc_map[XGBE_MAX_QUEUES];
120044b781cfSAndrew Turner 	unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
120144b781cfSAndrew Turner 
120244b781cfSAndrew Turner 	/* Hardware features of the device */
120344b781cfSAndrew Turner 	struct xgbe_hw_features hw_feat;
120444b781cfSAndrew Turner 
12057113afc8SEmmanuel Vadot 	/* Device work structure */
12069c6d6488SAndrew Turner 	struct task restart_work;
12077113afc8SEmmanuel Vadot 	struct task stopdev_work;
120844b781cfSAndrew Turner 
120944b781cfSAndrew Turner 	/* Keeps track of power mode */
121044b781cfSAndrew Turner 	unsigned int power_down;
121144b781cfSAndrew Turner 
121244b781cfSAndrew Turner 	/* Network interface message level setting */
12137113afc8SEmmanuel Vadot 	uint32_t msg_enable;
121444b781cfSAndrew Turner 
121544b781cfSAndrew Turner 	/* Current PHY settings */
121644b781cfSAndrew Turner 	int phy_link;
121744b781cfSAndrew Turner 	int phy_speed;
121844b781cfSAndrew Turner 
121944b781cfSAndrew Turner 	/* MDIO/PHY related settings */
12207113afc8SEmmanuel Vadot 	unsigned int phy_started;
12217113afc8SEmmanuel Vadot 	void *phy_data;
122244b781cfSAndrew Turner 	struct xgbe_phy phy;
122344b781cfSAndrew Turner 	int mdio_mmd;
122444b781cfSAndrew Turner 	unsigned long link_check;
12257113afc8SEmmanuel Vadot 	struct mtx mdio_mutex;
12267113afc8SEmmanuel Vadot 	unsigned int mdio_addr;
12277113afc8SEmmanuel Vadot 
12287113afc8SEmmanuel Vadot 	unsigned int kr_redrv;
122944b781cfSAndrew Turner 
123044b781cfSAndrew Turner 	char an_name[IFNAMSIZ + 32];
12317113afc8SEmmanuel Vadot 	struct taskqueue *an_workqueue;
123244b781cfSAndrew Turner 
12337113afc8SEmmanuel Vadot 	struct task an_irq_work;
123444b781cfSAndrew Turner 
123544b781cfSAndrew Turner 	unsigned int speed_set;
123644b781cfSAndrew Turner 
123744b781cfSAndrew Turner 	/* SerDes UEFI configurable settings.
123844b781cfSAndrew Turner 	 *   Switching between modes/speeds requires new values for some
123944b781cfSAndrew Turner 	 *   SerDes settings.  The values can be supplied as device
124044b781cfSAndrew Turner 	 *   properties in array format.  The first array entry is for
124144b781cfSAndrew Turner 	 *   1GbE, second for 2.5GbE and third for 10GbE
124244b781cfSAndrew Turner 	 */
12437113afc8SEmmanuel Vadot 	uint32_t serdes_blwc[XGBE_SPEEDS];
12447113afc8SEmmanuel Vadot 	uint32_t serdes_cdr_rate[XGBE_SPEEDS];
12457113afc8SEmmanuel Vadot 	uint32_t serdes_pq_skew[XGBE_SPEEDS];
12467113afc8SEmmanuel Vadot 	uint32_t serdes_tx_amp[XGBE_SPEEDS];
12477113afc8SEmmanuel Vadot 	uint32_t serdes_dfe_tap_cfg[XGBE_SPEEDS];
12487113afc8SEmmanuel Vadot 	uint32_t serdes_dfe_tap_ena[XGBE_SPEEDS];
124944b781cfSAndrew Turner 
125044b781cfSAndrew Turner 	/* Auto-negotiation state machine support */
125144b781cfSAndrew Turner 	unsigned int an_int;
12527113afc8SEmmanuel Vadot 	unsigned int an_status;
12539c6d6488SAndrew Turner 	struct sx an_mutex;
125444b781cfSAndrew Turner 	enum xgbe_an an_result;
125544b781cfSAndrew Turner 	enum xgbe_an an_state;
125644b781cfSAndrew Turner 	enum xgbe_rx kr_state;
125744b781cfSAndrew Turner 	enum xgbe_rx kx_state;
12587113afc8SEmmanuel Vadot 	struct task an_work;
12597113afc8SEmmanuel Vadot 	unsigned int an_again;
126044b781cfSAndrew Turner 	unsigned int an_supported;
126144b781cfSAndrew Turner 	unsigned int parallel_detect;
126244b781cfSAndrew Turner 	unsigned int fec_ability;
126344b781cfSAndrew Turner 	unsigned long an_start;
12647113afc8SEmmanuel Vadot 	enum xgbe_an_mode an_mode;
12657113afc8SEmmanuel Vadot 
12667113afc8SEmmanuel Vadot 	/* I2C support */
12677113afc8SEmmanuel Vadot 	struct xgbe_i2c i2c;
12687113afc8SEmmanuel Vadot 	struct mtx i2c_mutex;
12697113afc8SEmmanuel Vadot 	bool i2c_complete;
127044b781cfSAndrew Turner 
127144b781cfSAndrew Turner 	unsigned int lpm_ctrl;		/* CTRL1 for resume */
12727113afc8SEmmanuel Vadot 	unsigned int an_cdr_track_early;
12737113afc8SEmmanuel Vadot 
12747113afc8SEmmanuel Vadot 	uint64_t features;
12757113afc8SEmmanuel Vadot 
12767113afc8SEmmanuel Vadot 	device_t axgbe_miibus;
12777113afc8SEmmanuel Vadot 	unsigned int sysctl_xgmac_reg;
12787113afc8SEmmanuel Vadot 	unsigned int sysctl_xpcs_mmd;
12797113afc8SEmmanuel Vadot 	unsigned int sysctl_xpcs_reg;
12807113afc8SEmmanuel Vadot 
12817113afc8SEmmanuel Vadot 	unsigned int sysctl_xprop_reg;
12827113afc8SEmmanuel Vadot 	unsigned int sysctl_xi2c_reg;
12837113afc8SEmmanuel Vadot 
12847113afc8SEmmanuel Vadot 	bool sysctl_an_cdr_workaround;
12857113afc8SEmmanuel Vadot 	bool sysctl_an_cdr_track_early;
12867113afc8SEmmanuel Vadot 
12877113afc8SEmmanuel Vadot 	int pcie_bus;    /* PCIe bus number */
12887113afc8SEmmanuel Vadot 	int pcie_device; /* PCIe device/slot number */
12897113afc8SEmmanuel Vadot 	int pcie_func;   /* PCIe function number */
12907113afc8SEmmanuel Vadot 
12917113afc8SEmmanuel Vadot 	void *sys_op;
12927113afc8SEmmanuel Vadot 	uint64_t use_adaptive_rx_coalesce;
12937113afc8SEmmanuel Vadot 	uint64_t use_adaptive_tx_coalesce;
12947113afc8SEmmanuel Vadot 	uint64_t rx_coalesce_usecs;
12957113afc8SEmmanuel Vadot 
12967113afc8SEmmanuel Vadot 	unsigned int debug_level;
12972968dde3SVincenzo Maffione 
12982968dde3SVincenzo Maffione 	/*
12992968dde3SVincenzo Maffione 	 * Toggles the split header feature.
13002968dde3SVincenzo Maffione 	 * This requires a complete restart.
13012968dde3SVincenzo Maffione 	 */
13022968dde3SVincenzo Maffione 	unsigned int sph_enable;
1303bfd75d45SVincenzo Maffione 	unsigned int link_workaround;
13047113afc8SEmmanuel Vadot };
13057113afc8SEmmanuel Vadot 
13067113afc8SEmmanuel Vadot struct axgbe_if_softc {
13077113afc8SEmmanuel Vadot 	struct xgbe_prv_data    pdata;
13087113afc8SEmmanuel Vadot 	if_softc_ctx_t	  scctx;
13097113afc8SEmmanuel Vadot 	if_shared_ctx_t	 sctx;
13107113afc8SEmmanuel Vadot 	if_ctx_t		ctx;
1311402810d3SJustin Hibbits 	if_t			ifp;
13127113afc8SEmmanuel Vadot 	struct ifmedia	  *media;
13137113afc8SEmmanuel Vadot 	unsigned int		link_status;
131444b781cfSAndrew Turner };
131544b781cfSAndrew Turner 
131644b781cfSAndrew Turner /* Function prototypes*/
131744b781cfSAndrew Turner void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
131844b781cfSAndrew Turner void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
13197113afc8SEmmanuel Vadot void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
13207113afc8SEmmanuel Vadot void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *);
132144b781cfSAndrew Turner void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
13227113afc8SEmmanuel Vadot void xgbe_init_function_ptrs_i2c(struct xgbe_i2c_if *);
132344b781cfSAndrew Turner void xgbe_get_all_hw_features(struct xgbe_prv_data *);
132444b781cfSAndrew Turner void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
132544b781cfSAndrew Turner void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
132644b781cfSAndrew Turner 
1327402810d3SJustin Hibbits int xgbe_calc_rx_buf_size(if_t netdev, unsigned int mtu);
13287113afc8SEmmanuel Vadot 
13297113afc8SEmmanuel Vadot void axgbe_sysctl_init(struct xgbe_prv_data *pdata);
13307113afc8SEmmanuel Vadot void axgbe_sysctl_exit(struct xgbe_prv_data *pdata);
13317113afc8SEmmanuel Vadot 
13327113afc8SEmmanuel Vadot int xgbe_phy_mii_write(struct xgbe_prv_data *pdata, int addr, int reg,
13337113afc8SEmmanuel Vadot     uint16_t val);
13347113afc8SEmmanuel Vadot int xgbe_phy_mii_read(struct xgbe_prv_data *pdata, int addr, int reg);
13357113afc8SEmmanuel Vadot 
13367113afc8SEmmanuel Vadot void xgbe_dump_i2c_registers(struct xgbe_prv_data *);
13377113afc8SEmmanuel Vadot 
13387113afc8SEmmanuel Vadot uint32_t bitrev32(uint32_t);
133944b781cfSAndrew Turner 
134044b781cfSAndrew Turner /* For debug prints */
134144b781cfSAndrew Turner #ifdef YDEBUG
13427113afc8SEmmanuel Vadot #define DBGPR(x...) device_printf(pdata->dev, x)
134344b781cfSAndrew Turner #else
134444b781cfSAndrew Turner #define DBGPR(x...) do { } while (0)
134544b781cfSAndrew Turner #endif
134644b781cfSAndrew Turner 
134744b781cfSAndrew Turner #ifdef YDEBUG_MDIO
13487113afc8SEmmanuel Vadot #define DBGPR_MDIO(x...) device_printf(pdata->dev, x)
134944b781cfSAndrew Turner #else
135044b781cfSAndrew Turner #define DBGPR_MDIO(x...) do { } while (0)
135144b781cfSAndrew Turner #endif
135244b781cfSAndrew Turner 
13537113afc8SEmmanuel Vadot #define axgbe_printf(lvl, ...) do {			\
13547113afc8SEmmanuel Vadot 	if (lvl <= pdata->debug_level)			\
13557113afc8SEmmanuel Vadot 		device_printf(pdata->dev, __VA_ARGS__);	\
13567113afc8SEmmanuel Vadot } while (0)
13577113afc8SEmmanuel Vadot 
13587113afc8SEmmanuel Vadot #define axgbe_error(...) do {		     \
13597113afc8SEmmanuel Vadot 	device_printf(pdata->dev, __VA_ARGS__);   \
13607113afc8SEmmanuel Vadot } while (0)
13617113afc8SEmmanuel Vadot 
13627113afc8SEmmanuel Vadot #endif /* __XGBE_H__ */
1363