xref: /netbsd-src/sys/arch/arm/imx/if_enetvar.h (revision 90313c06e62e910bf0d1bb24faa9d17dcefd0ab6)
1*90313c06Smsaitoh /*	$NetBSD: if_enetvar.h,v 1.9 2024/02/07 04:20:26 msaitoh Exp $	*/
2ec482321Sryo 
3ec482321Sryo /*
4*90313c06Smsaitoh  * Copyright (c) 2014 Ryo Shimizu
5ec482321Sryo  * All rights reserved.
6ec482321Sryo  *
7ec482321Sryo  * Redistribution and use in source and binary forms, with or without
8ec482321Sryo  * modification, are permitted provided that the following conditions
9ec482321Sryo  * are met:
10ec482321Sryo  * 1. Redistributions of source code must retain the above copyright
11ec482321Sryo  *    notice, this list of conditions and the following disclaimer.
12ec482321Sryo  * 2. Redistributions in binary form must reproduce the above copyright
13ec482321Sryo  *    notice, this list of conditions and the following disclaimer in the
14ec482321Sryo  *    documentation and/or other materials provided with the distribution.
15ec482321Sryo  *
16ec482321Sryo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17ec482321Sryo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18ec482321Sryo  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19ec482321Sryo  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20ec482321Sryo  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21ec482321Sryo  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22ec482321Sryo  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ec482321Sryo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24ec482321Sryo  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25ec482321Sryo  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26ec482321Sryo  * POSSIBILITY OF SUCH DAMAGE.
27ec482321Sryo  */
28ec482321Sryo 
29ec482321Sryo #ifndef _ARM_IMX_IF_ENETVAR_H_
30ec482321Sryo #define _ARM_IMX_IF_ENETVAR_H_
31ec482321Sryo 
32ec482321Sryo #include <sys/rndsource.h>
33ec482321Sryo #include <net/if.h>
34ec482321Sryo #include <net/if_media.h>
35ec482321Sryo #include <net/if_ether.h>
36ec482321Sryo #include <dev/mii/miivar.h>
37ec482321Sryo 
38ec482321Sryo #define ENET_TX_RING_CNT	256
39ec482321Sryo #define ENET_RX_RING_CNT	256
40ec482321Sryo 
41ec482321Sryo struct enet_txsoft {
42ec482321Sryo 	struct mbuf *txs_mbuf;		/* head of our mbuf chain */
43ec482321Sryo 	bus_dmamap_t txs_dmamap;	/* our DMA map */
44ec482321Sryo };
45ec482321Sryo 
46ec482321Sryo struct enet_rxsoft {
47ec482321Sryo 	struct mbuf *rxs_mbuf;		/* head of our mbuf chain */
48ec482321Sryo 	bus_dmamap_t rxs_dmamap;	/* our DMA map */
49ec482321Sryo };
50ec482321Sryo 
51ec482321Sryo struct enet_softc {
52ec482321Sryo 	device_t sc_dev;
53ec482321Sryo 
54ec482321Sryo 	bus_space_tag_t sc_iot;
55ec482321Sryo 	bus_space_handle_t sc_ioh;
56ec482321Sryo 	bus_dma_tag_t sc_dmat;
57ec482321Sryo 
58ec482321Sryo 	int sc_unit;
59ec482321Sryo 	int sc_imxtype;
60bf4c80a7Sryo 	int sc_rgmii;
6191882526Sjmcneill 	int sc_phyid;
62c372cef6Shkenken 	unsigned int sc_clock;
63ec482321Sryo 
64c372cef6Shkenken 	struct clk *sc_clk_ipg;
65f1a047b0Shkenken 	struct clk *sc_clk_enet;
66f1a047b0Shkenken 	struct clk *sc_clk_enet_ref;
67f1a047b0Shkenken 
68ec482321Sryo 	/* interrupts */
69ec482321Sryo 	void *sc_ih;
70ec482321Sryo 	void *sc_ih2;	/* for i.MX7 */
71ec482321Sryo 	void *sc_ih3;	/* for i.MX7 */
72ec482321Sryo 	callout_t sc_tick_ch;
73ec482321Sryo 	bool sc_stopping;
74ec482321Sryo 
75ec482321Sryo 	/* TX */
76ec482321Sryo 	struct enet_txdesc *sc_txdesc_ring;	/* [ENET_TX_RING_CNT] */
77ec482321Sryo 	bus_dmamap_t sc_txdesc_dmamap;
78ec482321Sryo 	struct enet_rxdesc *sc_rxdesc_ring;	/* [ENET_RX_RING_CNT] */
79ec482321Sryo 	bus_dmamap_t sc_rxdesc_dmamap;
80ec482321Sryo 	struct enet_txsoft sc_txsoft[ENET_TX_RING_CNT];
81ec482321Sryo 	int sc_tx_considx;
82ec482321Sryo 	int sc_tx_prodidx;
83ec482321Sryo 	int sc_tx_free;
844671cb20Sthorpej 	bool sc_txbusy;
85ec482321Sryo 
86ec482321Sryo 	/* RX */
87ec482321Sryo 	struct enet_rxsoft sc_rxsoft[ENET_RX_RING_CNT];
88ec482321Sryo 	int sc_rx_readidx;
89ec482321Sryo 
90ec482321Sryo 	/* misc */
9170b25bc9Smsaitoh 	u_short sc_if_flags;			/* local copy of if_flags */
92ec482321Sryo 	int sc_flowflags;			/* 802.3x flow control flags */
93ec482321Sryo 	struct ethercom sc_ethercom;		/* interface info */
94ec482321Sryo 	struct mii_data sc_mii;
95ec482321Sryo 	uint8_t sc_enaddr[ETHER_ADDR_LEN];
96ec482321Sryo 	krndsource_t sc_rnd_source;
97ec482321Sryo 
98ec482321Sryo #ifdef ENET_EVENT_COUNTER
99ec482321Sryo 	struct evcnt sc_ev_t_drop;
100ec482321Sryo 	struct evcnt sc_ev_t_packets;
101ec482321Sryo 	struct evcnt sc_ev_t_bc_pkt;
102ec482321Sryo 	struct evcnt sc_ev_t_mc_pkt;
103ec482321Sryo 	struct evcnt sc_ev_t_crc_align;
104ec482321Sryo 	struct evcnt sc_ev_t_undersize;
105ec482321Sryo 	struct evcnt sc_ev_t_oversize;
106ec482321Sryo 	struct evcnt sc_ev_t_frag;
107ec482321Sryo 	struct evcnt sc_ev_t_jab;
108ec482321Sryo 	struct evcnt sc_ev_t_col;
109ec482321Sryo 	struct evcnt sc_ev_t_p64;
110ec482321Sryo 	struct evcnt sc_ev_t_p65to127n;
111ec482321Sryo 	struct evcnt sc_ev_t_p128to255n;
112ec482321Sryo 	struct evcnt sc_ev_t_p256to511;
113ec482321Sryo 	struct evcnt sc_ev_t_p512to1023;
114ec482321Sryo 	struct evcnt sc_ev_t_p1024to2047;
115ec482321Sryo 	struct evcnt sc_ev_t_p_gte2048;
116ec482321Sryo 	struct evcnt sc_ev_t_octets;
117ec482321Sryo 	struct evcnt sc_ev_r_packets;
118ec482321Sryo 	struct evcnt sc_ev_r_bc_pkt;
119ec482321Sryo 	struct evcnt sc_ev_r_mc_pkt;
120ec482321Sryo 	struct evcnt sc_ev_r_crc_align;
121ec482321Sryo 	struct evcnt sc_ev_r_undersize;
122ec482321Sryo 	struct evcnt sc_ev_r_oversize;
123ec482321Sryo 	struct evcnt sc_ev_r_frag;
124ec482321Sryo 	struct evcnt sc_ev_r_jab;
125ec482321Sryo 	struct evcnt sc_ev_r_p64;
126ec482321Sryo 	struct evcnt sc_ev_r_p65to127;
127ec482321Sryo 	struct evcnt sc_ev_r_p128to255;
128ec482321Sryo 	struct evcnt sc_ev_r_p256to511;
129ec482321Sryo 	struct evcnt sc_ev_r_p512to1023;
130ec482321Sryo 	struct evcnt sc_ev_r_p1024to2047;
131ec482321Sryo 	struct evcnt sc_ev_r_p_gte2048;
132ec482321Sryo 	struct evcnt sc_ev_r_octets;
133ec482321Sryo #endif /* ENET_EVENT_COUNTER */
134ec482321Sryo };
135ec482321Sryo 
1360656a7fbShkenken int enet_attach_common(device_t);
137ec482321Sryo int enet_match(device_t, cfdata_t, void *);
138ec482321Sryo void enet_attach(device_t, device_t, void *);
139ec482321Sryo 
1400656a7fbShkenken int enet_intr(void *);
1410656a7fbShkenken 
142ec482321Sryo #endif /* _ARM_IMX_IF_ENETVAR_H_ */
143