1e53470feSOleksandr Tymoshenko /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3af3dc4a7SPedro F. Giffuni * 4e53470feSOleksandr Tymoshenko * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org> 5e53470feSOleksandr Tymoshenko * All rights reserved. 6e53470feSOleksandr Tymoshenko * 7e53470feSOleksandr Tymoshenko * Redistribution and use in source and binary forms, with or without 8e53470feSOleksandr Tymoshenko * modification, are permitted provided that the following conditions 9e53470feSOleksandr Tymoshenko * are met: 10e53470feSOleksandr Tymoshenko * 1. Redistributions of source code must retain the above copyright 11e53470feSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer. 12e53470feSOleksandr Tymoshenko * 2. Redistributions in binary form must reproduce the above copyright 13e53470feSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer in the 14e53470feSOleksandr Tymoshenko * documentation and/or other materials provided with the distribution. 15e53470feSOleksandr Tymoshenko * 16e53470feSOleksandr Tymoshenko * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17e53470feSOleksandr Tymoshenko * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18e53470feSOleksandr Tymoshenko * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19e53470feSOleksandr Tymoshenko * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20e53470feSOleksandr Tymoshenko * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21e53470feSOleksandr Tymoshenko * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22e53470feSOleksandr Tymoshenko * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23e53470feSOleksandr Tymoshenko * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24e53470feSOleksandr Tymoshenko * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25e53470feSOleksandr Tymoshenko * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26e53470feSOleksandr Tymoshenko * SUCH DAMAGE. 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; 562c7bc0f5SJustin Hibbits if_t 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; 9223cd11b6SLuiz Otavio O Souza phandle_t node; 93ae6aefafSTim Kientzle struct bintime attach_uptime; /* system uptime when attach happened. */ 9423cd11b6SLuiz Otavio O Souza struct cpsw_port port[2]; 95feeb22f3SLuiz Otavio O Souza unsigned coal_us; 96ae6aefafSTim Kientzle 9723cd11b6SLuiz Otavio O Souza /* RX and TX buffer tracking */ 9823cd11b6SLuiz Otavio O Souza struct cpsw_queue rx, tx; 99ae6aefafSTim Kientzle 100ae6aefafSTim Kientzle /* We expect 1 memory resource and 4 interrupts from the device tree. */ 1015b03aba6SOleksandr Tymoshenko int mem_rid; 10223cd11b6SLuiz Otavio O Souza struct resource *mem_res; 1035b03aba6SOleksandr Tymoshenko struct resource *irq_res[CPSW_INTR_COUNT]; 10423cd11b6SLuiz Otavio O Souza void *ih_cookie[CPSW_INTR_COUNT]; 105e53470feSOleksandr Tymoshenko 106f3485573SLuiz Otavio O Souza /* A buffer full of nulls for TX padding. */ 107f3485573SLuiz Otavio O Souza void *nullpad; 108e53470feSOleksandr Tymoshenko 10923cd11b6SLuiz Otavio O Souza bus_dma_tag_t mbuf_dtag; 11023cd11b6SLuiz Otavio O Souza 11123cd11b6SLuiz Otavio O Souza struct { 11223cd11b6SLuiz Otavio O Souza int resets; 11323cd11b6SLuiz Otavio O Souza int timer; 11423cd11b6SLuiz Otavio O Souza struct callout callout; 11523cd11b6SLuiz Otavio O Souza } watchdog; 1165bf32555STim Kientzle 117ae6aefafSTim Kientzle /* 64-bit versions of 32-bit hardware statistics counters */ 118ae6aefafSTim Kientzle uint64_t shadow_stats[CPSW_SYSCTL_COUNT]; 119ae6aefafSTim Kientzle 120ae6aefafSTim Kientzle /* CPPI STATERAM has 512 slots for building TX/RX queues. */ 121ae6aefafSTim Kientzle /* TODO: Size here supposedly varies with different versions 122ae6aefafSTim Kientzle of the controller. Check DaVinci specs and find a good 123ae6aefafSTim Kientzle way to adjust this. One option is to have a separate 124ae6aefafSTim Kientzle Device Tree parameter for number slots; another option 125ae6aefafSTim Kientzle is to calculate it from the memory size in the device tree. */ 126ae6aefafSTim Kientzle struct cpsw_slot _slots[CPSW_CPPI_RAM_SIZE / sizeof(struct cpsw_cpdma_bd)]; 127ae6aefafSTim Kientzle struct cpsw_slots avail; 128e53470feSOleksandr Tymoshenko }; 129e53470feSOleksandr Tymoshenko 13023cd11b6SLuiz Otavio O Souza struct cpswp_softc { 13123cd11b6SLuiz Otavio O Souza device_t dev; 13223cd11b6SLuiz Otavio O Souza device_t miibus; 13323cd11b6SLuiz Otavio O Souza device_t pdev; 13423cd11b6SLuiz Otavio O Souza int media_status; 13523cd11b6SLuiz Otavio O Souza int unit; 13623cd11b6SLuiz Otavio O Souza int vlan; 13723cd11b6SLuiz Otavio O Souza struct bintime init_uptime; /* system uptime when init happened. */ 13823cd11b6SLuiz Otavio O Souza struct callout mii_callout; 13923cd11b6SLuiz Otavio O Souza struct cpsw_softc *swsc; 1402c7bc0f5SJustin Hibbits if_t ifp; 14123cd11b6SLuiz Otavio O Souza struct mii_data *mii; 14223cd11b6SLuiz Otavio O Souza struct mtx lock; 14323cd11b6SLuiz Otavio O Souza uint32_t if_flags; 14423cd11b6SLuiz Otavio O Souza uint32_t phy; 14523cd11b6SLuiz Otavio O Souza uint32_t phyaccess; 14623cd11b6SLuiz Otavio O Souza uint32_t physel; 14723cd11b6SLuiz Otavio O Souza }; 14823cd11b6SLuiz Otavio O Souza 149e53470feSOleksandr Tymoshenko #endif /*_IF_CPSWVAR_H */ 150