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