xref: /freebsd/sys/dev/dwc/if_dwcvar.h (revision 5d88a52be44a98e2b49db7ead317b2d0b2ef9eaa)
1 /*-
2  * Copyright (c) 2014 Ruslan Bukin <br@bsdpad.com>
3  *
4  * This software was developed by SRI International and the University of
5  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
6  * ("CTSRD"), as part of the DARPA CRASH research programme.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 /*
31  * Ethernet media access controller (EMAC)
32  * Chapter 17, Altera Cyclone V Device Handbook (CV-5V2 2014.07.22)
33  *
34  * EMAC is an instance of the Synopsys DesignWare 3504-0
35  * Universal 10/100/1000 Ethernet MAC (DWC_gmac).
36  */
37 
38 #ifndef	__IF_DWCVAR_H__
39 #define	__IF_DWCVAR_H__
40 
41 /*
42  * Driver data and defines.
43  */
44 #define	RX_DESC_COUNT	1024
45 #define	RX_DESC_SIZE	(sizeof(struct dwc_hwdesc) * RX_DESC_COUNT)
46 #define	TX_DESC_COUNT	1024
47 #define	TX_MAP_COUNT	TX_DESC_COUNT
48 #define	TX_DESC_SIZE	(sizeof(struct dwc_hwdesc) * TX_DESC_COUNT)
49 #define	TX_MAP_MAX_SEGS	32
50 
51 struct dwc_bufmap {
52 	bus_dmamap_t		map;
53 	struct mbuf		*mbuf;
54 	/* Only used for TX descirptors */
55 	int			last_desc_idx;
56 };
57 
58 struct dwc_softc {
59 	struct resource		*res[2];
60 	device_t		dev;
61 	phandle_t		node;
62 	int			mactype;
63 	int			mii_clk;
64 	device_t		miibus;
65 	struct mii_data *	mii_softc;
66 	if_t			ifp;
67 	int			if_flags;
68 	struct mtx		mtx;
69 	void *			intr_cookie;
70 	struct callout		dwc_callout;
71 	bool			link_is_up;
72 	bool			is_attached;
73 	bool			is_detaching;
74 	int			tx_watchdog_count;
75 	int			stats_harvest_count;
76 	int			phy_mode;
77 
78 	/* clocks and reset */
79 	clk_t			clk_stmmaceth;
80 	clk_t			clk_pclk;
81 	hwreset_t		rst_stmmaceth;
82 	hwreset_t		rst_ahb;
83 
84 	/* DMA config */
85 	uint32_t		txpbl;	/* TX Burst lenght */
86 	uint32_t		rxpbl;	/* RX Burst lenght */
87 	bool			nopblx8;
88 	bool			fixed_burst;
89 	bool			mixed_burst;
90 	bool			aal;
91 
92 	/* RX */
93 	bus_dma_tag_t		rxdesc_tag;
94 	bus_dmamap_t		rxdesc_map;
95 	struct dwc_hwdesc	*rxdesc_ring;
96 	bus_addr_t		rxdesc_ring_paddr;
97 	bus_dma_tag_t		rxbuf_tag;
98 	struct dwc_bufmap	rxbuf_map[RX_DESC_COUNT];
99 	uint32_t		rx_idx;
100 
101 	/* TX */
102 	bus_dma_tag_t		txdesc_tag;
103 	bus_dmamap_t		txdesc_map;
104 	struct dwc_hwdesc	*txdesc_ring;
105 	bus_addr_t		txdesc_ring_paddr;
106 	bus_dma_tag_t		txbuf_tag;
107 	struct dwc_bufmap	txbuf_map[TX_DESC_COUNT];
108 	uint32_t		tx_desc_head;
109 	uint32_t		tx_desc_tail;
110 	uint32_t		tx_map_head;
111 	uint32_t		tx_map_tail;
112 	int			tx_desccount;
113 	int			tx_mapcount;
114 };
115 
116 #define	READ4(_sc, _reg) \
117 	bus_read_4((_sc)->res[0], _reg)
118 #define	WRITE4(_sc, _reg, _val) \
119 	bus_write_4((_sc)->res[0], _reg, _val)
120 
121 #define	DWC_LOCK(sc)			mtx_lock(&(sc)->mtx)
122 #define	DWC_UNLOCK(sc)			mtx_unlock(&(sc)->mtx)
123 #define	DWC_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->mtx, MA_OWNED)
124 #define	DWC_ASSERT_UNLOCKED(sc)		mtx_assert(&(sc)->mtx, MA_NOTOWNED)
125 
126 #endif	/* __IF_DWCVAR_H__ */
127