1248dd603SAdrian Chadd /*- 2*718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*718cf2ccSPedro F. Giffuni * 4248dd603SAdrian Chadd * Copyright (c) 2013 Luiz Otavio O Souza. 5248dd603SAdrian Chadd * Copyright (c) 2011-2012 Stefan Bethke. 6248dd603SAdrian Chadd * Copyright (c) 2012 Adrian Chadd. 7248dd603SAdrian Chadd * All rights reserved. 8248dd603SAdrian Chadd * 9248dd603SAdrian Chadd * Redistribution and use in source and binary forms, with or without 10248dd603SAdrian Chadd * modification, are permitted provided that the following conditions 11248dd603SAdrian Chadd * are met: 12248dd603SAdrian Chadd * 1. Redistributions of source code must retain the above copyright 13248dd603SAdrian Chadd * notice, this list of conditions and the following disclaimer. 14248dd603SAdrian Chadd * 2. Redistributions in binary form must reproduce the above copyright 15248dd603SAdrian Chadd * notice, this list of conditions and the following disclaimer in the 16248dd603SAdrian Chadd * documentation and/or other materials provided with the distribution. 17248dd603SAdrian Chadd * 18248dd603SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19248dd603SAdrian Chadd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20248dd603SAdrian Chadd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21248dd603SAdrian Chadd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22248dd603SAdrian Chadd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23248dd603SAdrian Chadd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24248dd603SAdrian Chadd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25248dd603SAdrian Chadd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26248dd603SAdrian Chadd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27248dd603SAdrian Chadd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28248dd603SAdrian Chadd * SUCH DAMAGE. 29248dd603SAdrian Chadd * 30248dd603SAdrian Chadd * $FreeBSD$ 31248dd603SAdrian Chadd */ 32248dd603SAdrian Chadd 33248dd603SAdrian Chadd #ifndef __IP17X_VAR_H__ 34248dd603SAdrian Chadd #define __IP17X_VAR_H__ 35248dd603SAdrian Chadd 36248dd603SAdrian Chadd typedef enum { 37248dd603SAdrian Chadd IP17X_SWITCH_NONE, 38248dd603SAdrian Chadd IP17X_SWITCH_IP175A, 39248dd603SAdrian Chadd IP17X_SWITCH_IP175C, 40248dd603SAdrian Chadd IP17X_SWITCH_IP175D, 41248dd603SAdrian Chadd IP17X_SWITCH_IP178C, 42248dd603SAdrian Chadd } ip17x_switch_type; 43248dd603SAdrian Chadd 44248dd603SAdrian Chadd struct ip17x_vlan { 45248dd603SAdrian Chadd uint32_t ports; 46248dd603SAdrian Chadd int vlanid; 47248dd603SAdrian Chadd }; 48248dd603SAdrian Chadd 49248dd603SAdrian Chadd struct ip17x_softc { 50248dd603SAdrian Chadd device_t sc_dev; 51248dd603SAdrian Chadd int media; /* cpu port media */ 52248dd603SAdrian Chadd int cpuport; /* which PHY is connected to the CPU */ 53248dd603SAdrian Chadd int phymask; /* PHYs we manage */ 54248dd603SAdrian Chadd int phyport[MII_NPHY]; 55248dd603SAdrian Chadd int numports; /* number of ports */ 56248dd603SAdrian Chadd int *portphy; 57248dd603SAdrian Chadd device_t **miibus; 58a99badc2SAdrian Chadd int miipoll; 59248dd603SAdrian Chadd etherswitch_info_t info; 60248dd603SAdrian Chadd ip17x_switch_type sc_switchtype; 61248dd603SAdrian Chadd struct callout callout_tick; 62248dd603SAdrian Chadd struct ifnet **ifp; 63248dd603SAdrian Chadd struct mtx sc_mtx; /* serialize access to softc */ 64248dd603SAdrian Chadd 65248dd603SAdrian Chadd struct ip17x_vlan vlan[IP17X_MAX_VLANS]; 66248dd603SAdrian Chadd uint32_t *pvid; /* PVID */ 67248dd603SAdrian Chadd uint32_t addtag; /* per port add tag flag */ 68248dd603SAdrian Chadd uint32_t striptag; /* per port strip tag flag */ 69248dd603SAdrian Chadd uint32_t vlan_mode; /* VLAN mode */ 70248dd603SAdrian Chadd 71248dd603SAdrian Chadd struct { 72248dd603SAdrian Chadd int (* ip17x_reset) (struct ip17x_softc *); 73248dd603SAdrian Chadd int (* ip17x_hw_setup) (struct ip17x_softc *); 74248dd603SAdrian Chadd int (* ip17x_get_vlan_mode) (struct ip17x_softc *); 75248dd603SAdrian Chadd int (* ip17x_set_vlan_mode) (struct ip17x_softc *, uint32_t); 76248dd603SAdrian Chadd } hal; 77248dd603SAdrian Chadd }; 78248dd603SAdrian Chadd 79248dd603SAdrian Chadd #define IP17X_IS_SWITCH(_sc, _type) \ 80248dd603SAdrian Chadd (!!((_sc)->sc_switchtype == IP17X_SWITCH_ ## _type)) 81248dd603SAdrian Chadd 82248dd603SAdrian Chadd #define IP17X_LOCK(_sc) \ 83248dd603SAdrian Chadd mtx_lock(&(_sc)->sc_mtx) 84248dd603SAdrian Chadd #define IP17X_UNLOCK(_sc) \ 85248dd603SAdrian Chadd mtx_unlock(&(_sc)->sc_mtx) 86248dd603SAdrian Chadd #define IP17X_LOCK_ASSERT(_sc, _what) \ 87248dd603SAdrian Chadd mtx_assert(&(_sc)->sc_mtx, (_what)) 88248dd603SAdrian Chadd #define IP17X_TRYLOCK(_sc) \ 89248dd603SAdrian Chadd mtx_trylock(&(_sc)->sc_mtx) 90248dd603SAdrian Chadd 91248dd603SAdrian Chadd #if defined(DEBUG) 92248dd603SAdrian Chadd #define DPRINTF(dev, args...) device_printf(dev, args) 93248dd603SAdrian Chadd #else 94248dd603SAdrian Chadd #define DPRINTF(dev, args...) 95248dd603SAdrian Chadd #endif 96248dd603SAdrian Chadd 97248dd603SAdrian Chadd #endif /* __IP17X_VAR_H__ */ 98