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