xref: /freebsd-src/sys/dev/mgb/if_mgb.h (revision dab59af3bcc7cb7ba01569d3044894b3e860ad56)
18890ab77SEd Maste /*-
28890ab77SEd Maste  * SPDX-License-Identifier: BSD-2-Clause
38890ab77SEd Maste  *
4*dab59af3SLi-Wen Hsu  * Copyright (c) 2019 The FreeBSD Foundation
58890ab77SEd Maste  *
68890ab77SEd Maste  * This driver was written by Gerald ND Aryeetey <gndaryee@uwaterloo.ca>
78890ab77SEd Maste  * under sponsorship from the FreeBSD Foundation.
88890ab77SEd Maste  *
98890ab77SEd Maste  * Redistribution and use in source and binary forms, with or without
108890ab77SEd Maste  * modification, are permitted provided that the following conditions
118890ab77SEd Maste  * are met:
128890ab77SEd Maste  * 1. Redistributions of source code must retain the above copyright
138890ab77SEd Maste  *    notice, this list of conditions and the following disclaimer.
148890ab77SEd Maste  * 2. Redistributions in binary form must reproduce the above copyright
158890ab77SEd Maste  *    notice, this list of conditions and the following disclaimer in the
168890ab77SEd Maste  *    documentation and/or other materials provided with the distribution.
178890ab77SEd Maste  *
188890ab77SEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
198890ab77SEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
208890ab77SEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
218890ab77SEd Maste  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
228890ab77SEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
238890ab77SEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
248890ab77SEd Maste  * OR SERVICES; LOSS OF USE DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
258890ab77SEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
268890ab77SEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
278890ab77SEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
288890ab77SEd Maste  * SUCH DAMAGE.
298890ab77SEd Maste  */
308890ab77SEd Maste #ifndef _IF_MGB_H_
318890ab77SEd Maste #define _IF_MGB_H_
328890ab77SEd Maste 
338890ab77SEd Maste #define MGB_MICROCHIP_VENDOR_ID		0x1055
348890ab77SEd Maste #define MGB_LAN7430_DEVICE_ID		0x7430
358890ab77SEd Maste #define MGB_LAN7431_DEVICE_ID		0x7431
368890ab77SEd Maste 
378890ab77SEd Maste #define MGB_TIMEOUT			(500)
388890ab77SEd Maste 
398890ab77SEd Maste /** Control/Status Registers **/
408890ab77SEd Maste #define MGB_BAR				0 /* PCI Base Address */
418890ab77SEd Maste 
428890ab77SEd Maste /** Reset **/
438890ab77SEd Maste #define MGB_HW_CFG			0x10 /** H/W Configuration Register **/
448890ab77SEd Maste #define MGB_LITE_RESET 			0x2
458890ab77SEd Maste 
468890ab77SEd Maste /** MAC **/
478890ab77SEd Maste #define MGB_MAC_CR			0x0100 /** MAC Crontrol Register **/
488890ab77SEd Maste #define MGB_MAC_ADD_ENBL		0x1000 /* Automatic Duplex Detection */
498890ab77SEd Maste #define MGB_MAC_ASD_ENBL		0x0800 /* Automatic Speed Detection */
508890ab77SEd Maste 
518890ab77SEd Maste #define MGB_MAC_ADDR_BASE_L		0x11C /** MAC address lower 4 bytes (read) register **/
528890ab77SEd Maste #define MGB_MAC_ADDR_BASE_H		0x118 /** MAC address upper 2 bytes (read) register **/
538890ab77SEd Maste 
548890ab77SEd Maste #define MGB_MAC_TX			0x0104
558890ab77SEd Maste #define MGB_MAC_RX			0x0108
568890ab77SEd Maste #define MGB_MAC_ENBL			(1 << 0)
578890ab77SEd Maste #define MGB_MAC_DSBL			(1 << 1)
588890ab77SEd Maste 
598890ab77SEd Maste /** MAC Statistics **/
608890ab77SEd Maste #define MGB_MAC_STAT_RX_FCS_ERR_CNT	0x1200
618890ab77SEd Maste #define MGB_MAC_STAT_RX_ALIGN_ERR_CNT	0x1204
628890ab77SEd Maste #define MGB_MAC_STAT_RX_FRAG_ERR_CNT	0x1208
638890ab77SEd Maste #define MGB_MAC_STAT_RX_JABBER_ERR_CNT	0x120C
648890ab77SEd Maste #define MGB_MAC_STAT_RX_UNDER_ERR_CNT	0x1210
658890ab77SEd Maste #define MGB_MAC_STAT_RX_OVER_ERR_CNT	0x1214
668890ab77SEd Maste #define MGB_MAC_STAT_RX_DROPPED_CNT	0x1218
678890ab77SEd Maste #define MGB_MAC_STAT_RX_BROADCAST_CNT1	0x1220
688890ab77SEd Maste #define MGB_MAC_STAT_RX_BROADCAST_CNT	0x122C
698890ab77SEd Maste #define MGB_MAC_STAT_RX_FRAME_CNT	0x1254
708890ab77SEd Maste #define MGB_MAC_STAT_RX_DROPPED_CNT	0x1218
718890ab77SEd Maste #define MGB_MAC_STAT_RX_BROADCAST_CNT1	0x1220
728890ab77SEd Maste #define MGB_MAC_STAT_RX_BROADCAST_CNT	0x122C
738890ab77SEd Maste #define MGB_MAC_STAT_RX_FRAME_CNT	0x1254
748890ab77SEd Maste /* etc. */
758890ab77SEd Maste 
76fcb71d3fSEd Maste /** Receive Filtering Engine **/
778890ab77SEd Maste #define MGB_RFE_CTL			0x508
788890ab77SEd Maste #define MGB_RFE_ALLOW_BROADCAST		(1 << 10)
798890ab77SEd Maste #define MGB_RFE_ALLOW_MULTICAST		(1 << 9)
808890ab77SEd Maste #define MGB_RFE_ALLOW_UNICAST		(1 << 8)
818890ab77SEd Maste #define MGB_RFE_ALLOW_PERFECT_FILTER	(1 << 1)
828890ab77SEd Maste 
838890ab77SEd Maste /** PHY Reset (via power management control) **/
848890ab77SEd Maste #define MGB_PMT_CTL			0x14 /** Power Management Control Register **/
858890ab77SEd Maste #define MGB_PHY_RESET			0x10
868890ab77SEd Maste #define MGB_PHY_READY			0x80
878890ab77SEd Maste 
888890ab77SEd Maste /** FIFO Controller **/
898890ab77SEd Maste #define MGB_FCT_TX_CTL			0xC4
908890ab77SEd Maste #define MGB_FCT_RX_CTL			0xAC
918890ab77SEd Maste #define MGB_FCT_ENBL(_channel)		(1 << (28 + (_channel)))
928890ab77SEd Maste #define MGB_FCT_DSBL(_channel)		(1 << (24 + (_channel)))
938890ab77SEd Maste #define MGB_FCT_RESET(_channel)		(1 << (20 + (_channel)))
948890ab77SEd Maste 
958890ab77SEd Maste /** DMA Controller **/
968890ab77SEd Maste #define MGB_DMAC_CMD			0xC0C
978890ab77SEd Maste #define MGB_DMAC_RESET			(1 << 31)
988890ab77SEd Maste #define MGB_DMAC_TX_START		16
998890ab77SEd Maste #define MGB_DMAC_RX_START		0
1008890ab77SEd Maste #define MGB_DMAC_CMD_VAL(s, o, ch)	(1 << ((s) + (o) + (ch)))
1018890ab77SEd Maste #define MGB_DMAC_CMD_RESET(_s, _ch)	MGB_DMAC_CMD_VAL(_s, 8, _ch)
1028890ab77SEd Maste #define MGB_DMAC_CMD_START(_s, _ch)	MGB_DMAC_CMD_VAL(_s, 4, _ch)
1038890ab77SEd Maste #define MGB_DMAC_CMD_STOP( _s, _ch)	MGB_DMAC_CMD_VAL(_s, 0, _ch)
1048890ab77SEd Maste #define MGB_DMAC_STATE(_start, _stop)	\
1058890ab77SEd Maste 	(((_start) ? 2 : 0) | ((_stop) ? 1 : 0))
1068890ab77SEd Maste #define MGB_DMAC_STATE_INITIAL		MGB_DMAC_STATE(0, 0)
1078890ab77SEd Maste #define MGB_DMAC_STATE_STARTED		MGB_DMAC_STATE(1, 0)
1088890ab77SEd Maste #define MGB_DMAC_STATE_STOP_PENDING	MGB_DMAC_STATE(1, 1)
1098890ab77SEd Maste #define MGB_DMAC_STATE_STOPPED		MGB_DMAC_STATE(0, 1)
1108890ab77SEd Maste #define MGB_DMAC_CMD_STATE(sc, _s, _ch)				\
1118890ab77SEd Maste 	(MGB_DMAC_STATE(					\
1128890ab77SEd Maste 	    CSR_READ_REG(sc, MGB_DMAC_CMD) & MGB_DMAC_CMD_START(_s, _ch),	\
1138890ab77SEd Maste 	    CSR_READ_REG(sc, MGB_DMAC_CMD) & MGB_DMAC_CMD_STOP(_s, _ch)))
1148890ab77SEd Maste #define MGB_DMAC_STATE_IS_INITIAL(sc, _s, _ch)			\
1158890ab77SEd Maste 	(MGB_DMAC_CMD_STATE(sc, _s, _ch) == MGB_DMAC_STATE_INITIAL)
1168890ab77SEd Maste 
1178890ab77SEd Maste #define MGB_DMAC_INTR_STS		0xC10
1188890ab77SEd Maste #define MGB_DMAC_INTR_ENBL_SET		0xC14
1198890ab77SEd Maste #define MGB_DMAC_INTR_ENBL_CLR		0xC18
1208890ab77SEd Maste #define MGB_DMAC_TX_INTR_ENBL(_ch)	(1 << (_ch))
1218890ab77SEd Maste #define MGB_DMAC_RX_INTR_ENBL(_ch)	(1 << (16 + (_ch)))
1228890ab77SEd Maste 
1238890ab77SEd Maste /** DMA Rings **/
1248890ab77SEd Maste /**
1258890ab77SEd Maste  * Page size is 256 bytes
1268890ab77SEd Maste  *
1278890ab77SEd Maste  * Ring size, however, these could be tunable (for RX & TX)
1288890ab77SEd Maste  * to be a multiple of 4 (max is 65532)
1298890ab77SEd Maste  *
1308890ab77SEd Maste  **/
1318890ab77SEd Maste /* In linux driver these numbers are 50 and 65 for tx and rx .... */
1328890ab77SEd Maste #define MGB_DMA_RING_SIZE		16 /* in programming guide, this number is 100 */
1338890ab77SEd Maste #define MGB_DMA_MAXSEGS			32
1348890ab77SEd Maste #define MGB_DMA_REG(reg, _channel)	((reg) | ((_channel) << 6))
1358890ab77SEd Maste #define MGB_DMA_RING_LIST_SIZE		\
1368890ab77SEd Maste 	(sizeof(struct mgb_ring_desc) * MGB_DMA_RING_SIZE)
1378890ab77SEd Maste #define MGB_DMA_RING_INFO_SIZE		\
1388890ab77SEd Maste 	(sizeof(uint32_t) + MGB_DMA_RING_LIST_SIZE)
1398890ab77SEd Maste 
1408890ab77SEd Maste #define MGB_DMA_TX_CONFIG0(_channel)	MGB_DMA_REG(0x0D40, _channel)
1418890ab77SEd Maste #define MGB_DMA_TX_CONFIG1(_channel)	MGB_DMA_REG(0x0D44, _channel)
1428890ab77SEd Maste #define MGB_DMA_TX_BASE_H(_channel)	MGB_DMA_REG(0x0D48, _channel)
1438890ab77SEd Maste #define MGB_DMA_TX_BASE_L(_channel)	MGB_DMA_REG(0x0D4C, _channel)
1448890ab77SEd Maste #define MGB_DMA_TX_HEAD_WB_H(_channel)	MGB_DMA_REG(0x0D50, _channel) /* head Writeback */
1458890ab77SEd Maste #define MGB_DMA_TX_HEAD_WB_L(_channel)	MGB_DMA_REG(0x0D54, _channel)
1468890ab77SEd Maste #define MGB_DMA_TX_HEAD(_channel)	MGB_DMA_REG(0x0D58, _channel)
1478890ab77SEd Maste #define MGB_DMA_TX_TAIL(_channel)	MGB_DMA_REG(0x0D5C, _channel)
1488890ab77SEd Maste 
1498890ab77SEd Maste #define MGB_DMA_RX_CONFIG0(_channel)	MGB_DMA_REG(0x0C40, _channel)
1508890ab77SEd Maste #define MGB_DMA_RX_CONFIG1(_channel)	MGB_DMA_REG(0x0C44, _channel)
1518890ab77SEd Maste #define MGB_DMA_RX_BASE_H(_channel)	MGB_DMA_REG(0x0C48, _channel)
1528890ab77SEd Maste #define MGB_DMA_RX_BASE_L(_channel)	MGB_DMA_REG(0x0C4C, _channel)
1538890ab77SEd Maste #define MGB_DMA_RX_HEAD_WB_H(_channel)	MGB_DMA_REG(0x0C50, _channel) /* head Writeback */
1548890ab77SEd Maste #define MGB_DMA_RX_HEAD_WB_L(_channel)	MGB_DMA_REG(0x0C54, _channel)
1558890ab77SEd Maste #define MGB_DMA_RX_HEAD(_channel)	MGB_DMA_REG(0x0C58, _channel)
1568890ab77SEd Maste #define MGB_DMA_RX_TAIL(_channel)	MGB_DMA_REG(0x0C5C, _channel)
1578890ab77SEd Maste 
1588890ab77SEd Maste #define MGB_DMA_RING_LEN_MASK		0xFFFF
1598890ab77SEd Maste #define MGB_DMA_IOC_ENBL		0x10000000
1608890ab77SEd Maste #define MGB_DMA_HEAD_WB_LS_ENBL		0x20000000
1618890ab77SEd Maste #define MGB_DMA_HEAD_WB_ENBL		(1 << 5)
1628890ab77SEd Maste #define MGB_DMA_RING_PAD_MASK		0x03000000
1638890ab77SEd Maste #define MGB_DMA_RING_PAD_0		0x00000000
1648890ab77SEd Maste #define MGB_DMA_RING_PAD_2		0x02000000
1658890ab77SEd Maste 
1668890ab77SEd Maste #define MGB_DESC_CTL_OWN		(1 << 15)
1678890ab77SEd Maste #define MGB_DESC_CTL_FCS		(1 << 17)
1688890ab77SEd Maste #define MGB_DESC_CTL_IOC		(1 << 26)
1698890ab77SEd Maste #define MGB_TX_DESC_CTL_LS		(1 << 28)
1708890ab77SEd Maste #define MGB_TX_DESC_CTL_FS		(1 << 29)
1718890ab77SEd Maste #define MGB_RX_DESC_CTL_LS		(1 << 30)
1728890ab77SEd Maste #define MGB_RX_DESC_CTL_FS		(1 << 31)
1738890ab77SEd Maste #define MGB_DESC_CTL_BUFLEN_MASK	(0x0000FFFF)
1748890ab77SEd Maste #define MGB_DESC_STS_BUFLEN_MASK	(0x00003FFF)
1758890ab77SEd Maste #define MGB_DESC_FRAME_LEN_MASK		(0x3FFF0000)
1768890ab77SEd Maste #define MGB_DESC_GET_FRAME_LEN(_desc)	\
1778890ab77SEd Maste 	(((_desc)->ctl & MGB_DESC_FRAME_LEN_MASK) >> 16)
1788890ab77SEd Maste 
17949492b21SEd Maste #define MGB_NEXT_RING_IDX(_idx)		(((_idx) == MGB_DMA_RING_SIZE - 1) ? 0 : ((_idx) + 1))
18049492b21SEd Maste #define MGB_PREV_RING_IDX(_idx)		(((_idx) == 0) ? (MGB_DMA_RING_SIZE - 1) : ((_idx) - 1))
1818890ab77SEd Maste #define MGB_RING_SPACE(_sc)		\
1828890ab77SEd Maste 	((((_sc)->tx_ring_data.last_head - (_sc)->tx_ring_data.last_tail - 1) \
1838890ab77SEd Maste 	 + MGB_DMA_RING_SIZE ) % MGB_DMA_RING_SIZE )
1848890ab77SEd Maste 
1858890ab77SEd Maste /** PHY **/
1868890ab77SEd Maste #define MGB_MII_ACCESS			0x120
1878890ab77SEd Maste #define MGB_MII_DATA			0x124
1888890ab77SEd Maste #define MGB_MII_PHY_ADDR_MASK		0x1F
1898890ab77SEd Maste #define MGB_MII_PHY_ADDR_SHIFT		11
1908890ab77SEd Maste #define MGB_MII_REG_ADDR_MASK		0x1F
1918890ab77SEd Maste #define MGB_MII_REG_ADDR_SHIFT		6
1928890ab77SEd Maste #define MGB_MII_READ			0x0
1938890ab77SEd Maste #define MGB_MII_WRITE			0x2
1948890ab77SEd Maste #define MGB_MII_BUSY			0x1
1958890ab77SEd Maste 
1968890ab77SEd Maste /** Interrupt registers **/
1978890ab77SEd Maste #define MGB_INTR_STS			0x780
1988890ab77SEd Maste #define MGB_INTR_SET			0x784 /* This triggers a particular interrupt */
1998890ab77SEd Maste #define MGB_INTR_ENBL_SET		0x788
2008890ab77SEd Maste #define MGB_INTR_STS_ANY		(0x1)
2018890ab77SEd Maste #define MGB_INTR_STS_RX(_channel)	(1 << (24 + (_channel)))
2028890ab77SEd Maste #define MGB_INTR_STS_RX_ANY		(0xF << 24)
2038890ab77SEd Maste #define MGB_INTR_STS_TX(_channel)	(1 << (16 + (_channel)))
2048890ab77SEd Maste #define MGB_INTR_STS_TX_ANY		(0xF << 16)
2058890ab77SEd Maste #define MGB_INTR_STS_TEST		(1 << 9)
2068890ab77SEd Maste #define MGB_INTR_ENBL_CLR		0x78C
2078890ab77SEd Maste 
2088890ab77SEd Maste #define MGB_INTR_VEC_ENBL_SET		0x794
2098890ab77SEd Maste #define MGB_INTR_VEC_ENBL_CLR		0x798
2108890ab77SEd Maste #define MGB_INTR_VEC_ENBL_AUTO_CLR	0x79C
2118890ab77SEd Maste #define MGB_INTR_VEC_RX_MAP		0x7A0
2128890ab77SEd Maste #define MGB_INTR_VEC_TX_MAP		0x7A4
2138890ab77SEd Maste #define MGB_INTR_VEC_OTHER_MAP		0x7A8
2148890ab77SEd Maste #define MGB_INTR_VEC_MAP(_vsts, _ch)	((_vsts) << ((_ch) << 2))
2158890ab77SEd Maste #define MGB_INTR_VEC_STS(_v)		(1 << (_v))
2168890ab77SEd Maste #define MGB_INTR_RX_VEC_STS(_qid)	MGB_INTR_VEC_STS((_qid) + 1)
2178890ab77SEd Maste 
2188890ab77SEd Maste #define MGB_STS_OK			( 0 )
2198890ab77SEd Maste #define MGB_STS_TIMEOUT 		(-1 )
2208890ab77SEd Maste 
2218890ab77SEd Maste #define CSR_READ_BYTE(sc, reg)		\
2228890ab77SEd Maste 	bus_read_1((sc)->regs, reg)
2238890ab77SEd Maste 
2248890ab77SEd Maste #define CSR_WRITE_BYTE(sc, reg, val)	\
2258890ab77SEd Maste 	bus_write_1((sc)->regs, reg, val)
2268890ab77SEd Maste 
2278890ab77SEd Maste #define CSR_UPDATE_BYTE(sc, reg, val)	\
2288890ab77SEd Maste 	CSR_WRITE_BYTE(sc, reg, CSR_READ_BYTE(sc, reg) | (val))
2298890ab77SEd Maste 
2308890ab77SEd Maste #define CSR_READ_REG(sc, reg)		\
2318890ab77SEd Maste 	bus_read_4((sc)->regs, reg)
2328890ab77SEd Maste 
2338890ab77SEd Maste #define CSR_WRITE_REG(sc, reg, val)	\
2348890ab77SEd Maste 	bus_write_4((sc)->regs, reg, val)
2358890ab77SEd Maste 
2368890ab77SEd Maste #define CSR_CLEAR_REG(sc, reg, bits)	\
2378890ab77SEd Maste 	CSR_WRITE_REG(sc, reg, CSR_READ_REG(sc, reg) & ~(bits))
2388890ab77SEd Maste 
2398890ab77SEd Maste #define CSR_UPDATE_REG(sc, reg, val)	\
2408890ab77SEd Maste 	CSR_WRITE_REG(sc, reg, CSR_READ_REG(sc, reg) | (val))
2418890ab77SEd Maste 
2428890ab77SEd Maste #define CSR_READ_2_BYTES(sc, reg)	\
2438890ab77SEd Maste 	bus_read_2((sc)->regs, reg)
2448890ab77SEd Maste 
2458890ab77SEd Maste #define CSR_READ_REG_BYTES(sc, reg, dest, cnt)	\
2468890ab77SEd Maste 	bus_read_region_1((sc)->regs, reg, dest, cnt)
2478890ab77SEd Maste 
2488890ab77SEd Maste #define CSR_TRANSLATE_ADDR_LOW32(addr)		((uint64_t) (addr) & 0xFFFFFFFF)
2498890ab77SEd Maste #define CSR_TRANSLATE_ADDR_HIGH32(addr)		((uint64_t) (addr) >> 32)
2508890ab77SEd Maste 
2518890ab77SEd Maste struct mgb_irq {
2528890ab77SEd Maste 	struct resource			*res;
2538890ab77SEd Maste 	void				*handler;
2548890ab77SEd Maste };
2558890ab77SEd Maste 
2568890ab77SEd Maste enum mgb_dmac_cmd { DMAC_RESET, DMAC_START, DMAC_STOP };
2578890ab77SEd Maste enum mgb_fct_cmd { FCT_RESET, FCT_ENABLE, FCT_DISABLE };
2588890ab77SEd Maste 
2598890ab77SEd Maste struct mgb_ring_desc_addr {
2608890ab77SEd Maste 	uint32_t				low;
2618890ab77SEd Maste 	uint32_t				high;
2628890ab77SEd Maste } __packed;
2638890ab77SEd Maste 
2648890ab77SEd Maste /* TODO: With descriptor bit information
2658890ab77SEd Maste  * this could be done without masks etc.
2668890ab77SEd Maste  * (using bitwise structs like vmx,
2678890ab77SEd Maste  * would have to separate rx/tx ring desc
2688890ab77SEd Maste  * definitions)
2698890ab77SEd Maste  */
2708890ab77SEd Maste struct mgb_ring_desc {
2718890ab77SEd Maste 	uint32_t				ctl; /* data0 */
2728890ab77SEd Maste 	struct mgb_ring_desc_addr		addr; /* data(1|2) */
2738890ab77SEd Maste 	uint32_t				sts; /* data3 */
2748890ab77SEd Maste } __packed;
2758890ab77SEd Maste 
2768890ab77SEd Maste #if 0
2778890ab77SEd Maste struct mgb_ring_info {
2788890ab77SEd Maste 	uint32_t				head_wb;
2798890ab77SEd Maste 	struct mgb_ring_desc			*ring;
2808890ab77SEd Maste }
2818890ab77SEd Maste #endif
2828890ab77SEd Maste #define MGB_HEAD_WB_PTR(_ring_info_ptr)		\
2838890ab77SEd Maste 	((uint32_t *)(_ring_info_ptr))
2848890ab77SEd Maste 
2858890ab77SEd Maste #define MGB_RING_PTR(_ring_info_ptr)		\
2868890ab77SEd Maste 	((struct mgb_ring_desc *)(MGB_HEAD_WB_PTR(_ring_info_ptr) + 1))
2878890ab77SEd Maste 
2888890ab77SEd Maste struct mgb_ring_data {
2898890ab77SEd Maste 	uint32_t			*head_wb;
2908890ab77SEd Maste 	struct mgb_ring_desc		*ring;
2918890ab77SEd Maste 
2928890ab77SEd Maste 	bus_addr_t			 head_wb_bus_addr;
2938890ab77SEd Maste 	bus_addr_t			 ring_bus_addr;
2948890ab77SEd Maste 
2958890ab77SEd Maste 	uint32_t			 last_head;
2968890ab77SEd Maste 	uint32_t			 last_tail;
2978890ab77SEd Maste };
2988890ab77SEd Maste 
2998890ab77SEd Maste struct mgb_softc {
3008890ab77SEd Maste 	if_ctx_t			 ctx;
3018890ab77SEd Maste 	device_t			 dev;
3028890ab77SEd Maste 
3038890ab77SEd Maste 	struct resource			*regs;
3048890ab77SEd Maste 
3058890ab77SEd Maste 	struct resource			*pba;
3068890ab77SEd Maste 	struct if_irq			 admin_irq;
3078890ab77SEd Maste 	struct if_irq			 rx_irq;
3088890ab77SEd Maste 
3098890ab77SEd Maste 	bool 				 isr_test_flag;
3108890ab77SEd Maste 
3118890ab77SEd Maste 	device_t			 miibus;
3128890ab77SEd Maste 	int				 link_state;
3138890ab77SEd Maste 	int				 baudrate;
3148890ab77SEd Maste 
3158890ab77SEd Maste 	int				 if_flags;
3168890ab77SEd Maste 	int				 ethaddr;
3178890ab77SEd Maste 	int				 flags;
3188890ab77SEd Maste 
3198890ab77SEd Maste 	struct mtx			 mtx;
3208890ab77SEd Maste 	struct callout			 watchdog;
3218890ab77SEd Maste 	int				 timer;
3228890ab77SEd Maste 
3238890ab77SEd Maste 	bus_dma_tag_t			 dma_parent_tag;
3248890ab77SEd Maste 	struct mgb_ring_data		 rx_ring_data;
3258890ab77SEd Maste 	struct mgb_ring_data		 tx_ring_data;
3268890ab77SEd Maste 
3278890ab77SEd Maste };
3288890ab77SEd Maste 
3298890ab77SEd Maste #endif /* _IF_MGB_H_ */
330