Deleted Added
full compact
arswitch_vlans.c (257284) arswitch_vlans.c (262429)
1/*-
2 * Copyright (c) 2013 Luiz Otavio O Souza.
3 * Copyright (c) 2011-2012 Stefan Bethke.
4 * Copyright (c) 2012 Adrian Chadd.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
1/*-
2 * Copyright (c) 2013 Luiz Otavio O Souza.
3 * Copyright (c) 2011-2012 Stefan Bethke.
4 * Copyright (c) 2012 Adrian Chadd.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/dev/etherswitch/arswitch/arswitch_vlans.c 257284 2013-10-28 22:26:03Z glebius $
28 * $FreeBSD: head/sys/dev/etherswitch/arswitch/arswitch_vlans.c 262429 2014-02-24 04:44:28Z adrian $
29 */
30
31#include <sys/param.h>
32#include <sys/bus.h>
33#include <sys/errno.h>
34#include <sys/lock.h>
35#include <sys/kernel.h>
36#include <sys/mutex.h>

--- 129 unchanged lines hidden (view full) ---

166 return (err);
167 return (0);
168}
169
170/*
171 * Reset vlans to default state.
172 */
173void
29 */
30
31#include <sys/param.h>
32#include <sys/bus.h>
33#include <sys/errno.h>
34#include <sys/lock.h>
35#include <sys/kernel.h>
36#include <sys/mutex.h>

--- 129 unchanged lines hidden (view full) ---

166 return (err);
167 return (0);
168}
169
170/*
171 * Reset vlans to default state.
172 */
173void
174arswitch_reset_vlans(struct arswitch_softc *sc)
174ar8xxx_reset_vlans(struct arswitch_softc *sc)
175{
176 uint32_t ports;
177 int i, j;
178
179 ARSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
180
181 ARSWITCH_LOCK(sc);
182

--- 32 unchanged lines hidden (view full) ---

215
216 /*
217 * Setup vlan 1 as PVID for all switch ports. Add all ports
218 * as members of vlan 1.
219 */
220 sc->vid[0] = 1;
221 /* Set PVID for everyone. */
222 for (i = 0; i <= sc->numphys; i++)
175{
176 uint32_t ports;
177 int i, j;
178
179 ARSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
180
181 ARSWITCH_LOCK(sc);
182

--- 32 unchanged lines hidden (view full) ---

215
216 /*
217 * Setup vlan 1 as PVID for all switch ports. Add all ports
218 * as members of vlan 1.
219 */
220 sc->vid[0] = 1;
221 /* Set PVID for everyone. */
222 for (i = 0; i <= sc->numphys; i++)
223 arswitch_set_pvid(sc, i, sc->vid[0]);
223 sc->hal.arswitch_vlan_set_pvid(sc, i, sc->vid[0]);
224 ports = 0;
225 for (i = 0; i <= sc->numphys; i++)
226 ports |= (1 << i);
227 arswitch_set_dot1q_vlan(sc, ports, sc->vid[0]);
228 sc->vid[0] |= ETHERSWITCH_VID_VALID;
229 } else if (sc->vlan_mode == ETHERSWITCH_VLAN_PORT) {
230 /* Initialize the port based vlans. */
231 for (i = 0; i <= sc->numphys; i++) {

--- 22 unchanged lines hidden (view full) ---

254 AR8X16_PORT_VLAN_DEST_PORTS_SHIFT |
255 AR8X16_PORT_VLAN_MODE_SECURE <<
256 AR8X16_PORT_VLAN_MODE_PORT_ONLY);
257 }
258 ARSWITCH_UNLOCK(sc);
259}
260
261int
224 ports = 0;
225 for (i = 0; i <= sc->numphys; i++)
226 ports |= (1 << i);
227 arswitch_set_dot1q_vlan(sc, ports, sc->vid[0]);
228 sc->vid[0] |= ETHERSWITCH_VID_VALID;
229 } else if (sc->vlan_mode == ETHERSWITCH_VLAN_PORT) {
230 /* Initialize the port based vlans. */
231 for (i = 0; i <= sc->numphys; i++) {

--- 22 unchanged lines hidden (view full) ---

254 AR8X16_PORT_VLAN_DEST_PORTS_SHIFT |
255 AR8X16_PORT_VLAN_MODE_SECURE <<
256 AR8X16_PORT_VLAN_MODE_PORT_ONLY);
257 }
258 ARSWITCH_UNLOCK(sc);
259}
260
261int
262arswitch_getvgroup(device_t dev, etherswitch_vlangroup_t *vg)
262ar8xxx_getvgroup(struct arswitch_softc *sc, etherswitch_vlangroup_t *vg)
263{
263{
264 struct arswitch_softc *sc;
265 int err;
266
264 int err;
265
267 sc = device_get_softc(dev);
268 ARSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
269
270 if (vg->es_vlangroup > sc->info.es_nvlangroups)
271 return (EINVAL);
272
273 /* Reset the members ports. */
274 vg->es_untagged_ports = 0;
275 vg->es_member_ports = 0;

--- 24 unchanged lines hidden (view full) ---

300 err = -1;
301 }
302 ARSWITCH_UNLOCK(sc);
303 vg->es_untagged_ports = vg->es_member_ports;
304 return (err);
305}
306
307int
266 ARSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
267
268 if (vg->es_vlangroup > sc->info.es_nvlangroups)
269 return (EINVAL);
270
271 /* Reset the members ports. */
272 vg->es_untagged_ports = 0;
273 vg->es_member_ports = 0;

--- 24 unchanged lines hidden (view full) ---

298 err = -1;
299 }
300 ARSWITCH_UNLOCK(sc);
301 vg->es_untagged_ports = vg->es_member_ports;
302 return (err);
303}
304
305int
308arswitch_setvgroup(device_t dev, etherswitch_vlangroup_t *vg)
306ar8xxx_setvgroup(struct arswitch_softc *sc, etherswitch_vlangroup_t *vg)
309{
307{
310 struct arswitch_softc *sc;
311 int err, vid;
312
308 int err, vid;
309
313 sc = device_get_softc(dev);
314 ARSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
315
316 /* Check VLAN mode. */
317 if (sc->vlan_mode == 0)
318 return (EINVAL);
319
320 /*
321 * Check if we are changing the vlanid for an already used vtu entry.

--- 35 unchanged lines hidden (view full) ---

357 default:
358 err = -1;
359 }
360 ARSWITCH_UNLOCK(sc);
361 return (err);
362}
363
364int
310 ARSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
311
312 /* Check VLAN mode. */
313 if (sc->vlan_mode == 0)
314 return (EINVAL);
315
316 /*
317 * Check if we are changing the vlanid for an already used vtu entry.

--- 35 unchanged lines hidden (view full) ---

353 default:
354 err = -1;
355 }
356 ARSWITCH_UNLOCK(sc);
357 return (err);
358}
359
360int
365arswitch_get_pvid(struct arswitch_softc *sc, int port, int *pvid)
361ar8xxx_get_pvid(struct arswitch_softc *sc, int port, int *pvid)
366{
367 uint32_t reg;
368
369 ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
370 reg = arswitch_readreg(sc->sc_dev, AR8X16_REG_PORT_VLAN(port));
371 *pvid = reg & 0xfff;
372 return (0);
373}
374
375int
362{
363 uint32_t reg;
364
365 ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
366 reg = arswitch_readreg(sc->sc_dev, AR8X16_REG_PORT_VLAN(port));
367 *pvid = reg & 0xfff;
368 return (0);
369}
370
371int
376arswitch_set_pvid(struct arswitch_softc *sc, int port, int pvid)
372ar8xxx_set_pvid(struct arswitch_softc *sc, int port, int pvid)
377{
378
379 ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
380 return (arswitch_modifyreg(sc->sc_dev,
381 AR8X16_REG_PORT_VLAN(port), 0xfff, pvid));
382}
373{
374
375 ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
376 return (arswitch_modifyreg(sc->sc_dev,
377 AR8X16_REG_PORT_VLAN(port), 0xfff, pvid));
378}