arswitchvar.h revision 262433
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: head/sys/dev/etherswitch/arswitch/arswitchvar.h 262433 2014-02-24 05:55:00Z adrian $ 27 */ 28#ifndef __ARSWITCHVAR_H__ 29#define __ARSWITCHVAR_H__ 30 31typedef 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_AR8327, 39 AR8X16_SWITCH_AR8337, 40} ar8x16_switch_type; 41 42/* 43 * XXX TODO: start using this where required 44 */ 45#define AR8X16_IS_SWITCH(_sc, _type) \ 46 (!!((_sc)->sc_switchtype == AR8X16_SWITCH_ ## _type)) 47 48#define ARSWITCH_NUM_PORTS MAX(AR8327_NUM_PORTS, AR8X16_NUM_PORTS) 49#define ARSWITCH_NUM_PHYS MAX(AR8327_NUM_PHYS, AR8X16_NUM_PHYS) 50 51struct arswitch_softc { 52 struct mtx sc_mtx; /* serialize access to softc */ 53 device_t sc_dev; 54 int phy4cpu; /* PHY4 is connected to the CPU */ 55 int numphys; /* PHYs we manage */ 56 int is_rgmii; /* PHY mode is RGMII (XXX which PHY?) */ 57 int is_gmii; /* PHY mode is GMII (XXX which PHY?) */ 58 int is_mii; /* PHY mode is MII (XXX which PHY?) */ 59 int page; 60 int is_internal_switch; 61 int chip_ver; 62 int chip_rev; 63 int mii_lo_first; 64 ar8x16_switch_type sc_switchtype; 65 /* should be the max of both pre-AR8327 and AR8327 ports */ 66 char *ifname[ARSWITCH_NUM_PHYS]; 67 device_t miibus[ARSWITCH_NUM_PHYS]; 68 struct ifnet *ifp[ARSWITCH_NUM_PHYS]; 69 struct callout callout_tick; 70 etherswitch_info_t info; 71 72 /* VLANs support */ 73 int vid[AR8X16_MAX_VLANS]; 74 uint32_t vlan_mode; 75 76 struct { 77 /* Global setup */ 78 int (* arswitch_hw_setup) (struct arswitch_softc *); 79 int (* arswitch_hw_global_setup) (struct arswitch_softc *); 80 81 /* Port functions */ 82 void (* arswitch_port_init) (struct arswitch_softc *, int); 83 84 /* VLAN functions */ 85 int (* arswitch_port_vlan_setup) (struct arswitch_softc *, 86 etherswitch_port_t *); 87 int (* arswitch_port_vlan_get) (struct arswitch_softc *, 88 etherswitch_port_t *); 89 void (* arswitch_vlan_init_hw) (struct arswitch_softc *); 90 int (* arswitch_vlan_getvgroup) (struct arswitch_softc *, 91 etherswitch_vlangroup_t *); 92 int (* arswitch_vlan_setvgroup) (struct arswitch_softc *, 93 etherswitch_vlangroup_t *); 94 int (* arswitch_vlan_get_pvid) (struct arswitch_softc *, int, 95 int *); 96 int (* arswitch_vlan_set_pvid) (struct arswitch_softc *, int, 97 int); 98 } hal; 99 100 struct { 101 uint32_t port0_status; 102 uint32_t port5_status; 103 uint32_t port6_status; 104 } ar8327; 105}; 106 107#define ARSWITCH_LOCK(_sc) \ 108 mtx_lock(&(_sc)->sc_mtx) 109#define ARSWITCH_UNLOCK(_sc) \ 110 mtx_unlock(&(_sc)->sc_mtx) 111#define ARSWITCH_LOCK_ASSERT(_sc, _what) \ 112 mtx_assert(&(_sc)->sc_mtx, (_what)) 113#define ARSWITCH_TRYLOCK(_sc) \ 114 mtx_trylock(&(_sc)->sc_mtx) 115 116#if defined(DEBUG) 117#define DPRINTF(dev, args...) device_printf(dev, args) 118#define DEVERR(dev, err, fmt, args...) do { \ 119 if (err != 0) device_printf(dev, fmt, err, args); \ 120 } while (0) 121#define DEBUG_INCRVAR(var) do { \ 122 var++; \ 123 } while (0) 124#else 125#define DPRINTF(dev, args...) 126#define DEVERR(dev, err, fmt, args...) 127#define DEBUG_INCRVAR(var) 128#endif 129 130#endif /* __ARSWITCHVAR_H__ */ 131 132