1e53470feSOleksandr Tymoshenko /*- 2e53470feSOleksandr Tymoshenko * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org> 3e53470feSOleksandr Tymoshenko * All rights reserved. 4e53470feSOleksandr Tymoshenko * 5e53470feSOleksandr Tymoshenko * Redistribution and use in source and binary forms, with or without 6e53470feSOleksandr Tymoshenko * modification, are permitted provided that the following conditions 7e53470feSOleksandr Tymoshenko * are met: 8e53470feSOleksandr Tymoshenko * 1. Redistributions of source code must retain the above copyright 9e53470feSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer. 10e53470feSOleksandr Tymoshenko * 2. Redistributions in binary form must reproduce the above copyright 11e53470feSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer in the 12e53470feSOleksandr Tymoshenko * documentation and/or other materials provided with the distribution. 13e53470feSOleksandr Tymoshenko * 14e53470feSOleksandr Tymoshenko * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15e53470feSOleksandr Tymoshenko * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16e53470feSOleksandr Tymoshenko * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17e53470feSOleksandr Tymoshenko * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18e53470feSOleksandr Tymoshenko * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19e53470feSOleksandr Tymoshenko * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20e53470feSOleksandr Tymoshenko * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21e53470feSOleksandr Tymoshenko * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22e53470feSOleksandr Tymoshenko * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23e53470feSOleksandr Tymoshenko * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24e53470feSOleksandr Tymoshenko * SUCH DAMAGE. 25e53470feSOleksandr Tymoshenko * 26e53470feSOleksandr Tymoshenko * $FreeBSD$ 27e53470feSOleksandr Tymoshenko */ 28e53470feSOleksandr Tymoshenko 29e53470feSOleksandr Tymoshenko #ifndef _IF_CPSWVAR_H 30e53470feSOleksandr Tymoshenko #define _IF_CPSWVAR_H 31e53470feSOleksandr Tymoshenko 3223cd11b6SLuiz Otavio O Souza #define CPSW_PORTS 2 33e53470feSOleksandr Tymoshenko #define CPSW_INTR_COUNT 4 34e53470feSOleksandr Tymoshenko 35e53470feSOleksandr Tymoshenko /* MII BUS */ 367f676140SLuiz Otavio O Souza #define CPSW_MIIBUS_RETRIES 20 377f676140SLuiz Otavio O Souza #define CPSW_MIIBUS_DELAY 100 38e53470feSOleksandr Tymoshenko 39e53470feSOleksandr Tymoshenko #define CPSW_MAX_ALE_ENTRIES 1024 40e53470feSOleksandr Tymoshenko 41ae6aefafSTim Kientzle #define CPSW_SYSCTL_COUNT 34 42ae6aefafSTim Kientzle 43a2c46b94SLuiz Otavio O Souza #ifdef CPSW_ETHERSWITCH 44a2c46b94SLuiz Otavio O Souza #define CPSW_CPU_PORT 0 45a2c46b94SLuiz Otavio O Souza #define CPSW_PORTS_MASK 0x7 46a2c46b94SLuiz Otavio O Souza #define CPSW_VLANS 128 /* Arbitrary number. */ 47a2c46b94SLuiz Otavio O Souza 48a2c46b94SLuiz Otavio O Souza struct cpsw_vlangroups { 49a2c46b94SLuiz Otavio O Souza int vid; 50a2c46b94SLuiz Otavio O Souza }; 51a2c46b94SLuiz Otavio O Souza #endif 52a2c46b94SLuiz Otavio O Souza 535bf32555STim Kientzle struct cpsw_slot { 54ae6aefafSTim Kientzle uint32_t bd_offset; /* Offset of corresponding BD within CPPI RAM. */ 555bf32555STim Kientzle bus_dmamap_t dmamap; 569c2deddeSLuiz Otavio O Souza struct ifnet *ifp; 575bf32555STim Kientzle struct mbuf *mbuf; 585bf32555STim Kientzle STAILQ_ENTRY(cpsw_slot) next; 595bf32555STim Kientzle }; 60ae6aefafSTim Kientzle STAILQ_HEAD(cpsw_slots, cpsw_slot); 61ae6aefafSTim Kientzle 62ae6aefafSTim Kientzle struct cpsw_queue { 63ae6aefafSTim Kientzle struct mtx lock; 64ae6aefafSTim Kientzle int running; 65ba14258fSLuiz Otavio O Souza int teardown; 66ae6aefafSTim Kientzle struct cpsw_slots active; 67ae6aefafSTim Kientzle struct cpsw_slots avail; 68ae6aefafSTim Kientzle uint32_t queue_adds; /* total bufs added */ 69ae6aefafSTim Kientzle uint32_t queue_removes; /* total bufs removed */ 70ae6aefafSTim Kientzle uint32_t queue_removes_at_last_tick; /* Used by watchdog */ 71ba14258fSLuiz Otavio O Souza uint32_t queue_restart; 72ae6aefafSTim Kientzle int queue_slots; 73ae6aefafSTim Kientzle int active_queue_len; 74ae6aefafSTim Kientzle int max_active_queue_len; 75ae6aefafSTim Kientzle int avail_queue_len; 76ae6aefafSTim Kientzle int max_avail_queue_len; 77ae6aefafSTim Kientzle int longest_chain; /* Largest # segments in a single packet. */ 78ae6aefafSTim Kientzle int hdp_offset; 79ae6aefafSTim Kientzle }; 805bf32555STim Kientzle 8123cd11b6SLuiz Otavio O Souza struct cpsw_port { 82e53470feSOleksandr Tymoshenko device_t dev; 8323cd11b6SLuiz Otavio O Souza int phy; 8423cd11b6SLuiz Otavio O Souza int vlan; 8523cd11b6SLuiz Otavio O Souza }; 8623cd11b6SLuiz Otavio O Souza 8723cd11b6SLuiz Otavio O Souza struct cpsw_softc { 8823cd11b6SLuiz Otavio O Souza device_t dev; 8923cd11b6SLuiz Otavio O Souza int active_slave; 9023cd11b6SLuiz Otavio O Souza int debug; 9123cd11b6SLuiz Otavio O Souza int dualemac; 92ba14258fSLuiz Otavio O Souza int rx_batch; 9323cd11b6SLuiz Otavio O Souza phandle_t node; 94ae6aefafSTim Kientzle struct bintime attach_uptime; /* system uptime when attach happened. */ 9523cd11b6SLuiz Otavio O Souza struct cpsw_port port[2]; 96feeb22f3SLuiz Otavio O Souza unsigned coal_us; 97ae6aefafSTim Kientzle 9823cd11b6SLuiz Otavio O Souza /* RX and TX buffer tracking */ 9923cd11b6SLuiz Otavio O Souza struct cpsw_queue rx, tx; 100ae6aefafSTim Kientzle 101ae6aefafSTim Kientzle /* We expect 1 memory resource and 4 interrupts from the device tree. */ 1025b03aba6SOleksandr Tymoshenko int mem_rid; 10323cd11b6SLuiz Otavio O Souza struct resource *mem_res; 1045b03aba6SOleksandr Tymoshenko struct resource *irq_res[CPSW_INTR_COUNT]; 10523cd11b6SLuiz Otavio O Souza void *ih_cookie[CPSW_INTR_COUNT]; 106e53470feSOleksandr Tymoshenko 107*f3485573SLuiz Otavio O Souza /* A buffer full of nulls for TX padding. */ 108*f3485573SLuiz Otavio O Souza void *nullpad; 109e53470feSOleksandr Tymoshenko 11023cd11b6SLuiz Otavio O Souza bus_dma_tag_t mbuf_dtag; 11123cd11b6SLuiz Otavio O Souza 11223cd11b6SLuiz Otavio O Souza struct { 11323cd11b6SLuiz Otavio O Souza int resets; 11423cd11b6SLuiz Otavio O Souza int timer; 11523cd11b6SLuiz Otavio O Souza struct callout callout; 11623cd11b6SLuiz Otavio O Souza } watchdog; 1175bf32555STim Kientzle 118ae6aefafSTim Kientzle /* 64-bit versions of 32-bit hardware statistics counters */ 119ae6aefafSTim Kientzle uint64_t shadow_stats[CPSW_SYSCTL_COUNT]; 120ae6aefafSTim Kientzle 121ae6aefafSTim Kientzle /* CPPI STATERAM has 512 slots for building TX/RX queues. */ 122ae6aefafSTim Kientzle /* TODO: Size here supposedly varies with different versions 123ae6aefafSTim Kientzle of the controller. Check DaVinci specs and find a good 124ae6aefafSTim Kientzle way to adjust this. One option is to have a separate 125ae6aefafSTim Kientzle Device Tree parameter for number slots; another option 126ae6aefafSTim Kientzle is to calculate it from the memory size in the device tree. */ 127ae6aefafSTim Kientzle struct cpsw_slot _slots[CPSW_CPPI_RAM_SIZE / sizeof(struct cpsw_cpdma_bd)]; 128ae6aefafSTim Kientzle struct cpsw_slots avail; 129e53470feSOleksandr Tymoshenko }; 130e53470feSOleksandr Tymoshenko 13123cd11b6SLuiz Otavio O Souza struct cpswp_softc { 13223cd11b6SLuiz Otavio O Souza device_t dev; 13323cd11b6SLuiz Otavio O Souza device_t miibus; 13423cd11b6SLuiz Otavio O Souza device_t pdev; 13523cd11b6SLuiz Otavio O Souza int media_status; 13623cd11b6SLuiz Otavio O Souza int unit; 13723cd11b6SLuiz Otavio O Souza int vlan; 13823cd11b6SLuiz Otavio O Souza struct bintime init_uptime; /* system uptime when init happened. */ 13923cd11b6SLuiz Otavio O Souza struct callout mii_callout; 14023cd11b6SLuiz Otavio O Souza struct cpsw_softc *swsc; 14123cd11b6SLuiz Otavio O Souza struct ifnet *ifp; 14223cd11b6SLuiz Otavio O Souza struct mii_data *mii; 14323cd11b6SLuiz Otavio O Souza struct mtx lock; 14423cd11b6SLuiz Otavio O Souza uint32_t if_flags; 14523cd11b6SLuiz Otavio O Souza uint32_t phy; 14623cd11b6SLuiz Otavio O Souza uint32_t phyaccess; 14723cd11b6SLuiz Otavio O Souza uint32_t physel; 14823cd11b6SLuiz Otavio O Souza }; 14923cd11b6SLuiz Otavio O Souza 150e53470feSOleksandr Tymoshenko #endif /*_IF_CPSWVAR_H */ 151