1 /*- 2 * Copyright (c) 2011-2012 Stefan Bethke. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 #ifndef __ARSWITCHVAR_H__ 29 #define __ARSWITCHVAR_H__ 30 31 typedef enum { 32 AR8X16_SWITCH_NONE, 33 AR8X16_SWITCH_AR7240, 34 AR8X16_SWITCH_AR8216, 35 AR8X16_SWITCH_AR8226, 36 AR8X16_SWITCH_AR8316, 37 AR8X16_SWITCH_AR9340, 38 } ar8x16_switch_type; 39 40 /* 41 * XXX TODO: start using this where required 42 */ 43 #define AR8X16_IS_SWITCH(_sc, _type) \ 44 (!!((_sc)->sc_switchtype == AR8X16_SWITCH_ ## _type)) 45 46 struct arswitch_softc { 47 struct mtx sc_mtx; /* serialize access to softc */ 48 device_t sc_dev; 49 int phy4cpu; /* PHY4 is connected to the CPU */ 50 int numphys; /* PHYs we manage */ 51 int is_rgmii; /* PHY mode is RGMII (XXX which PHY?) */ 52 int is_gmii; /* PHY mode is GMII (XXX which PHY?) */ 53 int is_mii; /* PHY mode is MII (XXX which PHY?) */ 54 int page; 55 int is_internal_switch; 56 ar8x16_switch_type sc_switchtype; 57 char *ifname[AR8X16_NUM_PHYS]; 58 device_t miibus[AR8X16_NUM_PHYS]; 59 struct ifnet *ifp[AR8X16_NUM_PHYS]; 60 struct callout callout_tick; 61 etherswitch_info_t info; 62 63 /* VLANs support */ 64 int vid[AR8X16_MAX_VLANS]; 65 uint32_t vlan_mode; 66 67 struct { 68 int (* arswitch_hw_setup) (struct arswitch_softc *); 69 int (* arswitch_hw_global_setup) (struct arswitch_softc *); 70 } hal; 71 }; 72 73 #define ARSWITCH_LOCK(_sc) \ 74 mtx_lock(&(_sc)->sc_mtx) 75 #define ARSWITCH_UNLOCK(_sc) \ 76 mtx_unlock(&(_sc)->sc_mtx) 77 #define ARSWITCH_LOCK_ASSERT(_sc, _what) \ 78 mtx_assert(&(_sc)->sc_mtx, (_what)) 79 #define ARSWITCH_TRYLOCK(_sc) \ 80 mtx_trylock(&(_sc)->sc_mtx) 81 82 #if defined(DEBUG) 83 #define DPRINTF(dev, args...) device_printf(dev, args) 84 #define DEVERR(dev, err, fmt, args...) do { \ 85 if (err != 0) device_printf(dev, fmt, err, args); \ 86 } while (0) 87 #define DEBUG_INCRVAR(var) do { \ 88 var++; \ 89 } while (0) 90 #else 91 #define DPRINTF(dev, args...) 92 #define DEVERR(dev, err, fmt, args...) 93 #define DEBUG_INCRVAR(var) 94 #endif 95 96 #endif /* __ARSWITCHVAR_H__ */ 97 98