2 * Copyright (c) 2011-2012 Stefan Bethke.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
28 #ifndef __ARSWITCHVAR_H__
29 #define __ARSWITCHVAR_H__
43 * XXX TODO: start using this where required
45 #define AR8X16_IS_SWITCH(_sc, _type) \
46 (!!((_sc)->sc_switchtype == AR8X16_SWITCH_ ## _type))
48 #define ARSWITCH_NUM_PORTS MAX(AR8327_NUM_PORTS, AR8X16_NUM_PORTS)
49 #define ARSWITCH_NUM_PHYS MAX(AR8327_NUM_PHYS, AR8X16_NUM_PHYS)
51 #define ARSWITCH_NUM_LEDS 3
53 struct arswitch_dev_led {
54 struct arswitch_softc *sc;
60 struct arswitch_softc {
61 struct mtx sc_mtx; /* serialize access to softc */
63 int phy4cpu; /* PHY4 is connected to the CPU */
64 int numphys; /* PHYs we manage */
65 int is_rgmii; /* PHY mode is RGMII (XXX which PHY?) */
66 int is_gmii; /* PHY mode is GMII (XXX which PHY?) */
67 int is_mii; /* PHY mode is MII (XXX which PHY?) */
69 int is_internal_switch;
72 int mii_lo_first; /* Send low data DWORD before high */
73 ar8x16_switch_type sc_switchtype;
74 /* should be the max of both pre-AR8327 and AR8327 ports */
75 char *ifname[ARSWITCH_NUM_PHYS];
76 device_t miibus[ARSWITCH_NUM_PHYS];
77 struct ifnet *ifp[ARSWITCH_NUM_PHYS];
78 struct arswitch_dev_led dev_led[ARSWITCH_NUM_PHYS][ARSWITCH_NUM_LEDS];
79 struct callout callout_tick;
80 etherswitch_info_t info;
85 int vid[AR8X16_MAX_VLANS];
90 int (* arswitch_hw_setup) (struct arswitch_softc *);
91 int (* arswitch_hw_global_setup) (struct arswitch_softc *);
94 void (* arswitch_port_init) (struct arswitch_softc *, int);
97 int (* arswitch_atu_flush) (struct arswitch_softc *);
100 int (* arswitch_port_vlan_setup) (struct arswitch_softc *,
101 etherswitch_port_t *);
102 int (* arswitch_port_vlan_get) (struct arswitch_softc *,
103 etherswitch_port_t *);
104 void (* arswitch_vlan_init_hw) (struct arswitch_softc *);
105 int (* arswitch_vlan_getvgroup) (struct arswitch_softc *,
106 etherswitch_vlangroup_t *);
107 int (* arswitch_vlan_setvgroup) (struct arswitch_softc *,
108 etherswitch_vlangroup_t *);
109 int (* arswitch_vlan_get_pvid) (struct arswitch_softc *, int,
111 int (* arswitch_vlan_set_pvid) (struct arswitch_softc *, int,
114 int (* arswitch_flush_dot1q_vlan) (struct arswitch_softc *sc);
115 int (* arswitch_purge_dot1q_vlan) (struct arswitch_softc *sc,
117 int (* arswitch_get_dot1q_vlan) (struct arswitch_softc *,
118 uint32_t *ports, uint32_t *untagged_ports, int vid);
119 int (* arswitch_set_dot1q_vlan) (struct arswitch_softc *sc,
120 uint32_t ports, uint32_t untagged_ports, int vid);
121 int (* arswitch_get_port_vlan) (struct arswitch_softc *sc,
122 uint32_t *ports, int vid);
123 int (* arswitch_set_port_vlan) (struct arswitch_softc *sc,
124 uint32_t ports, int vid);
127 int (* arswitch_phy_read) (device_t, int, int);
128 int (* arswitch_phy_write) (device_t, int, int, int);
132 uint32_t port0_status;
133 uint32_t port5_status;
134 uint32_t port6_status;
138 #define ARSWITCH_LOCK(_sc) \
139 mtx_lock(&(_sc)->sc_mtx)
140 #define ARSWITCH_UNLOCK(_sc) \
141 mtx_unlock(&(_sc)->sc_mtx)
142 #define ARSWITCH_LOCK_ASSERT(_sc, _what) \
143 mtx_assert(&(_sc)->sc_mtx, (_what))
144 #define ARSWITCH_TRYLOCK(_sc) \
145 mtx_trylock(&(_sc)->sc_mtx)
147 #define ARSWITCH_DBG_RESET 0x00000001
148 #define ARSWITCH_DBG_REGIO 0x00000002
149 #define ARSWITCH_DBG_PHYIO 0x00000004
150 #define ARSWITCH_DBG_POLL 0x00000008
151 #define ARSWITCH_DBG_VLAN 0x00000010
152 #define ARSWITCH_DBG_ANY 0xffffffff
155 #define DPRINTF(sc, dbg, args...) \
157 if (((sc)->sc_debug & (dbg)) || \
158 ((sc)->sc_debug == ARSWITCH_DBG_ANY)) { \
159 device_printf((sc)->sc_dev, args); \
162 #define DEVERR(dev, err, fmt, args...) do { \
163 if (err != 0) device_printf(dev, fmt, err, args); \
166 #define DPRINTF(dev, dbg, args...)
167 #define DEVERR(dev, err, fmt, args...)
170 #endif /* __ARSWITCHVAR_H__ */