2 * Copyright (c) 2015 Semihalf
3 * Copyright (c) 2015 Stormshield
4 * Copyright (c) 2018-2019, Rubicon Communications, LLC (Netgate)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
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
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/errno.h>
35 #include <sys/kernel.h>
36 #include <sys/kthread.h>
37 #include <sys/module.h>
38 #include <sys/socket.h>
39 #include <sys/sockio.h>
42 #include <net/if_media.h>
43 #include <net/if_types.h>
45 #include <dev/etherswitch/etherswitch.h>
46 #include <dev/mii/mii.h>
47 #include <dev/mii/miivar.h>
49 #include <dev/ofw/ofw_bus.h>
50 #include <dev/ofw/ofw_bus_subr.h>
52 #include "e6000swreg.h"
53 #include "etherswitch_if.h"
54 #include "miibus_if.h"
57 MALLOC_DECLARE(M_E6000SW);
58 MALLOC_DEFINE(M_E6000SW, "e6000sw", "e6000sw switch");
60 #define E6000SW_LOCK(_sc) sx_xlock(&(_sc)->sx)
61 #define E6000SW_UNLOCK(_sc) sx_unlock(&(_sc)->sx)
62 #define E6000SW_LOCK_ASSERT(_sc, _what) sx_assert(&(_sc)->sx, (_what))
63 #define E6000SW_TRYLOCK(_sc) sx_tryxlock(&(_sc)->sx)
64 #define E6000SW_WAITREADY(_sc, _reg, _bit) \
65 e6000sw_waitready((_sc), REG_GLOBAL, (_reg), (_bit))
66 #define E6000SW_WAITREADY2(_sc, _reg, _bit) \
67 e6000sw_waitready((_sc), REG_GLOBAL2, (_reg), (_bit))
68 #define MDIO_READ(dev, addr, reg) \
69 MDIO_READREG(device_get_parent(dev), (addr), (reg))
70 #define MDIO_WRITE(dev, addr, reg, val) \
71 MDIO_WRITEREG(device_get_parent(dev), (addr), (reg), (val))
74 typedef struct e6000sw_softc {
79 struct ifnet *ifp[E6000SW_MAX_PORTS];
80 char *ifname[E6000SW_MAX_PORTS];
81 device_t miibus[E6000SW_MAX_PORTS];
84 int vlans[E6000SW_NUM_VLANS];
87 uint32_t cpuports_mask;
89 uint32_t fixed25_mask;
96 static etherswitch_info_t etherswitch_info = {
99 .es_vlan_caps = ETHERSWITCH_VLAN_PORT | ETHERSWITCH_VLAN_DOT1Q,
100 .es_name = "Marvell 6000 series switch"
103 static void e6000sw_identify(driver_t *, device_t);
104 static int e6000sw_probe(device_t);
105 static int e6000sw_parse_fixed_link(e6000sw_softc_t *, phandle_t, uint32_t);
106 static int e6000sw_parse_ethernet(e6000sw_softc_t *, phandle_t, uint32_t);
107 static int e6000sw_attach(device_t);
108 static int e6000sw_detach(device_t);
109 static int e6000sw_readphy(device_t, int, int);
110 static int e6000sw_writephy(device_t, int, int, int);
111 static etherswitch_info_t* e6000sw_getinfo(device_t);
112 static int e6000sw_getconf(device_t, etherswitch_conf_t *);
113 static int e6000sw_setconf(device_t, etherswitch_conf_t *);
114 static void e6000sw_lock(device_t);
115 static void e6000sw_unlock(device_t);
116 static int e6000sw_getport(device_t, etherswitch_port_t *);
117 static int e6000sw_setport(device_t, etherswitch_port_t *);
118 static int e6000sw_set_vlan_mode(e6000sw_softc_t *, uint32_t);
119 static int e6000sw_readreg_wrapper(device_t, int);
120 static int e6000sw_writereg_wrapper(device_t, int, int);
121 static int e6000sw_readphy_wrapper(device_t, int, int);
122 static int e6000sw_writephy_wrapper(device_t, int, int, int);
123 static int e6000sw_getvgroup_wrapper(device_t, etherswitch_vlangroup_t *);
124 static int e6000sw_setvgroup_wrapper(device_t, etherswitch_vlangroup_t *);
125 static int e6000sw_setvgroup(device_t, etherswitch_vlangroup_t *);
126 static int e6000sw_getvgroup(device_t, etherswitch_vlangroup_t *);
127 static void e6000sw_setup(device_t, e6000sw_softc_t *);
128 static void e6000sw_tick(void *);
129 static void e6000sw_set_atustat(device_t, e6000sw_softc_t *, int, int);
130 static int e6000sw_atu_flush(device_t, e6000sw_softc_t *, int);
131 static int e6000sw_vtu_flush(e6000sw_softc_t *);
132 static int e6000sw_vtu_update(e6000sw_softc_t *, int, int, int, int, int);
133 static __inline void e6000sw_writereg(e6000sw_softc_t *, int, int, int);
134 static __inline uint32_t e6000sw_readreg(e6000sw_softc_t *, int, int);
135 static int e6000sw_ifmedia_upd(struct ifnet *);
136 static void e6000sw_ifmedia_sts(struct ifnet *, struct ifmediareq *);
137 static int e6000sw_atu_mac_table(device_t, e6000sw_softc_t *, struct atu_opt *,
139 static int e6000sw_get_pvid(e6000sw_softc_t *, int, int *);
140 static void e6000sw_set_pvid(e6000sw_softc_t *, int, int);
141 static __inline bool e6000sw_is_cpuport(e6000sw_softc_t *, int);
142 static __inline bool e6000sw_is_fixedport(e6000sw_softc_t *, int);
143 static __inline bool e6000sw_is_fixed25port(e6000sw_softc_t *, int);
144 static __inline bool e6000sw_is_phyport(e6000sw_softc_t *, int);
145 static __inline bool e6000sw_is_portenabled(e6000sw_softc_t *, int);
146 static __inline struct mii_data *e6000sw_miiforphy(e6000sw_softc_t *,
149 static device_method_t e6000sw_methods[] = {
150 /* device interface */
151 DEVMETHOD(device_identify, e6000sw_identify),
152 DEVMETHOD(device_probe, e6000sw_probe),
153 DEVMETHOD(device_attach, e6000sw_attach),
154 DEVMETHOD(device_detach, e6000sw_detach),
157 DEVMETHOD(bus_add_child, device_add_child_ordered),
160 DEVMETHOD(miibus_readreg, e6000sw_readphy),
161 DEVMETHOD(miibus_writereg, e6000sw_writephy),
163 /* etherswitch interface */
164 DEVMETHOD(etherswitch_getinfo, e6000sw_getinfo),
165 DEVMETHOD(etherswitch_getconf, e6000sw_getconf),
166 DEVMETHOD(etherswitch_setconf, e6000sw_setconf),
167 DEVMETHOD(etherswitch_lock, e6000sw_lock),
168 DEVMETHOD(etherswitch_unlock, e6000sw_unlock),
169 DEVMETHOD(etherswitch_getport, e6000sw_getport),
170 DEVMETHOD(etherswitch_setport, e6000sw_setport),
171 DEVMETHOD(etherswitch_readreg, e6000sw_readreg_wrapper),
172 DEVMETHOD(etherswitch_writereg, e6000sw_writereg_wrapper),
173 DEVMETHOD(etherswitch_readphyreg, e6000sw_readphy_wrapper),
174 DEVMETHOD(etherswitch_writephyreg, e6000sw_writephy_wrapper),
175 DEVMETHOD(etherswitch_setvgroup, e6000sw_setvgroup_wrapper),
176 DEVMETHOD(etherswitch_getvgroup, e6000sw_getvgroup_wrapper),
181 static devclass_t e6000sw_devclass;
183 DEFINE_CLASS_0(e6000sw, e6000sw_driver, e6000sw_methods,
184 sizeof(e6000sw_softc_t));
186 DRIVER_MODULE(e6000sw, mdio, e6000sw_driver, e6000sw_devclass, 0, 0);
187 DRIVER_MODULE(etherswitch, e6000sw, etherswitch_driver, etherswitch_devclass, 0,
189 DRIVER_MODULE(miibus, e6000sw, miibus_driver, miibus_devclass, 0, 0);
190 MODULE_DEPEND(e6000sw, mdio, 1, 1, 1);
194 e6000sw_identify(driver_t *driver, device_t parent)
197 if (device_find_child(parent, "e6000sw", -1) == NULL)
198 BUS_ADD_CHILD(parent, 0, "e6000sw", -1);
202 e6000sw_probe(device_t dev)
205 const char *description;
206 phandle_t switch_node;
208 switch_node = ofw_bus_find_compatible(OF_finddevice("/"),
209 "marvell,mv88e6085");
211 if (switch_node == 0)
215 device_printf(dev, "Found switch_node: 0x%x\n", switch_node);
217 sc = device_get_softc(dev);
219 sc->node = switch_node;
221 if (OF_getencprop(sc->node, "reg", &sc->sw_addr,
222 sizeof(sc->sw_addr)) < 0)
224 if (sc->sw_addr < 0 || sc->sw_addr > 32)
228 * Create temporary lock, just to satisfy assertions,
229 * when obtaining the switch ID. Destroy immediately afterwards.
231 sx_init(&sc->sx, "e6000sw_tmp");
233 sc->swid = e6000sw_readreg(sc, REG_PORT(0), SWITCH_ID) & 0xfff0;
239 description = "Marvell 88E6141";
244 description = "Marvell 88E6341";
249 description = "Marvell 88E6352";
253 description = "Marvell 88E6172";
257 description = "Marvell 88E6176";
261 device_printf(dev, "Unrecognized device, id 0x%x.\n", sc->swid);
265 device_set_desc(dev, description);
267 return (BUS_PROBE_DEFAULT);
271 e6000sw_parse_fixed_link(e6000sw_softc_t *sc, phandle_t node, uint32_t port)
274 phandle_t fixed_link;
276 fixed_link = ofw_bus_find_child(node, "fixed-link");
278 if (fixed_link != 0) {
279 sc->fixed_mask |= (1 << port);
281 if (OF_getencprop(fixed_link, "speed", &speed, sizeof(speed))> 0) {
283 (MVSWITCH(sc, MV88E6141) ||
284 MVSWITCH(sc, MV88E6341)))
285 sc->fixed25_mask |= (1 << port);
287 device_printf(sc->dev,
288 "Port %d has a fixed-link node without a speed "
299 e6000sw_parse_ethernet(e6000sw_softc_t *sc, phandle_t port_handle, uint32_t port) {
300 phandle_t switch_eth, switch_eth_handle;
302 if (OF_getencprop(port_handle, "ethernet", (void*)&switch_eth_handle,
303 sizeof(switch_eth_handle)) > 0) {
304 if (switch_eth_handle > 0) {
305 switch_eth = OF_node_from_xref(switch_eth_handle);
307 device_printf(sc->dev, "CPU port at %d\n", port);
308 sc->cpuports_mask |= (1 << port);
310 return (e6000sw_parse_fixed_link(sc, switch_eth, port));
312 device_printf(sc->dev,
313 "Port %d has ethernet property but it points "
314 "to an invalid location\n", port);
321 e6000sw_parse_child_fdt(e6000sw_softc_t *sc, phandle_t child, int *pport)
328 if (OF_getencprop(child, "reg", (void *)&port, sizeof(port)) < 0)
330 if (port >= sc->num_ports)
334 if (e6000sw_parse_fixed_link(sc, child, port) != 0)
337 if (e6000sw_parse_ethernet(sc, child, port) != 0)
340 if ((sc->fixed_mask & (1 << port)) != 0)
341 device_printf(sc->dev, "fixed port at %d\n", port);
343 device_printf(sc->dev, "PHY at port %d\n", port);
349 e6000sw_init_interface(e6000sw_softc_t *sc, int port)
353 snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->dev));
355 sc->ifp[port] = if_alloc(IFT_ETHER);
356 if (sc->ifp[port] == NULL)
358 sc->ifp[port]->if_softc = sc;
359 sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
360 IFF_DRV_RUNNING | IFF_SIMPLEX;
361 sc->ifname[port] = malloc(strlen(name) + 1, M_E6000SW, M_NOWAIT);
362 if (sc->ifname[port] == NULL) {
363 if_free(sc->ifp[port]);
366 memcpy(sc->ifname[port], name, strlen(name) + 1);
367 if_initname(sc->ifp[port], sc->ifname[port], port);
373 e6000sw_attach_miibus(e6000sw_softc_t *sc, int port)
377 err = mii_attach(sc->dev, &sc->miibus[port], sc->ifp[port],
378 e6000sw_ifmedia_upd, e6000sw_ifmedia_sts, BMSR_DEFCAPMASK,
379 port + sc->phy_base, MII_OFFSET_ANY, 0);
387 e6000sw_attach(device_t dev)
390 phandle_t child, ports;
395 sc = device_get_softc(dev);
398 * According to the Linux source code, all of the Switch IDs we support
399 * are multi_chip capable, and should go into multi-chip mode if the
402 if (MVSWITCH_MULTICHIP(sc))
403 device_printf(dev, "multi-chip addressing mode (%#x)\n",
406 device_printf(dev, "single-chip addressing mode\n");
408 sx_init(&sc->sx, "e6000sw");
411 e6000sw_setup(dev, sc);
413 ports = ofw_bus_find_child(sc->node, "ports");
416 device_printf(dev, "failed to parse DTS: no ports found for "
421 for (child = OF_child(ports); child != 0; child = OF_peer(child)) {
422 err = e6000sw_parse_child_fdt(sc, child, &port);
424 device_printf(sc->dev, "failed to parse DTS\n");
428 /* Port is in use. */
429 sc->ports_mask |= (1 << port);
431 err = e6000sw_init_interface(sc, port);
433 device_printf(sc->dev, "failed to init interface\n");
437 if (e6000sw_is_fixedport(sc, port)) {
438 /* Link must be down to change speed force value. */
439 reg = e6000sw_readreg(sc, REG_PORT(port), PSC_CONTROL);
440 reg &= ~PSC_CONTROL_LINK_UP;
441 reg |= PSC_CONTROL_FORCED_LINK;
442 e6000sw_writereg(sc, REG_PORT(port), PSC_CONTROL, reg);
445 * Force speed, full-duplex, EEE off and flow-control
448 reg &= ~(PSC_CONTROL_SPD2500 | PSC_CONTROL_ALT_SPD |
449 PSC_CONTROL_FORCED_EEE);
450 if (e6000sw_is_fixed25port(sc, port))
451 reg |= PSC_CONTROL_SPD2500;
453 reg |= PSC_CONTROL_SPD1000;
454 reg |= PSC_CONTROL_FORCED_DPX | PSC_CONTROL_FULLDPX |
455 PSC_CONTROL_FORCED_LINK | PSC_CONTROL_LINK_UP |
456 PSC_CONTROL_FORCED_FC | PSC_CONTROL_FC_ON |
457 PSC_CONTROL_FORCED_SPD;
458 if (MVSWITCH(sc, MV88E6141) || MVSWITCH(sc, MV88E6341))
459 reg |= PSC_CONTROL_FORCED_EEE;
460 e6000sw_writereg(sc, REG_PORT(port), PSC_CONTROL, reg);
463 /* Don't attach miibus at CPU/fixed ports */
464 if (!e6000sw_is_phyport(sc, port))
467 err = e6000sw_attach_miibus(sc, port);
469 device_printf(sc->dev, "failed to attach miibus\n");
474 etherswitch_info.es_nports = sc->num_ports;
476 /* Default to port vlan. */
477 e6000sw_set_vlan_mode(sc, ETHERSWITCH_VLAN_PORT);
479 reg = e6000sw_readreg(sc, REG_GLOBAL, SWITCH_GLOBAL_STATUS);
480 if (reg & SWITCH_GLOBAL_STATUS_IR)
481 device_printf(dev, "switch is ready.\n");
484 bus_generic_probe(dev);
485 bus_generic_attach(dev);
487 kproc_create(e6000sw_tick, sc, &sc->kproc, 0, 0, "e6000sw tick kproc");
499 e6000sw_waitready(e6000sw_softc_t *sc, uint32_t phy, uint32_t reg,
504 for (i = 0; i < E6000SW_RETRIES; i++) {
505 if ((e6000sw_readreg(sc, phy, reg) & busybit) == 0)
514 * PHY registers are paged. Put page index in reg 22 (accessible from every
515 * page), then access specific register.
518 e6000sw_readphy(device_t dev, int phy, int reg)
523 sc = device_get_softc(dev);
524 if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) {
525 device_printf(dev, "Wrong register address.\n");
529 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
530 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
531 device_printf(dev, "Timeout while waiting for switch\n");
535 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
536 SMI_CMD_OP_C22_READ | (reg & SMI_CMD_REG_ADDR_MASK) |
537 ((phy << SMI_CMD_DEV_ADDR) & SMI_CMD_DEV_ADDR_MASK));
538 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
539 device_printf(dev, "Timeout while waiting for switch\n");
543 val = e6000sw_readreg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG);
545 return (val & PHY_DATA_MASK);
549 e6000sw_writephy(device_t dev, int phy, int reg, int data)
553 sc = device_get_softc(dev);
554 if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) {
555 device_printf(dev, "Wrong register address.\n");
559 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
560 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
561 device_printf(dev, "Timeout while waiting for switch\n");
565 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG,
566 data & PHY_DATA_MASK);
567 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
568 SMI_CMD_OP_C22_WRITE | (reg & SMI_CMD_REG_ADDR_MASK) |
569 ((phy << SMI_CMD_DEV_ADDR) & SMI_CMD_DEV_ADDR_MASK));
575 e6000sw_detach(device_t dev)
580 sc = device_get_softc(dev);
581 bus_generic_detach(dev);
583 for (phy = 0; phy < sc->num_ports; phy++) {
584 if (sc->miibus[phy] != NULL)
585 device_delete_child(dev, sc->miibus[phy]);
586 if (sc->ifp[phy] != NULL)
587 if_free(sc->ifp[phy]);
588 if (sc->ifname[phy] != NULL)
589 free(sc->ifname[phy], M_E6000SW);
595 static etherswitch_info_t*
596 e6000sw_getinfo(device_t dev)
599 return (ðerswitch_info);
603 e6000sw_getconf(device_t dev, etherswitch_conf_t *conf)
605 struct e6000sw_softc *sc;
607 /* Return the VLAN mode. */
608 sc = device_get_softc(dev);
609 conf->cmd = ETHERSWITCH_CONF_VLAN_MODE;
610 conf->vlan_mode = sc->vlan_mode;
616 e6000sw_setconf(device_t dev, etherswitch_conf_t *conf)
618 struct e6000sw_softc *sc;
620 /* Set the VLAN mode. */
621 sc = device_get_softc(dev);
622 if (conf->cmd & ETHERSWITCH_CONF_VLAN_MODE) {
624 e6000sw_set_vlan_mode(sc, conf->vlan_mode);
632 e6000sw_lock(device_t dev)
634 struct e6000sw_softc *sc;
636 sc = device_get_softc(dev);
638 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
643 e6000sw_unlock(device_t dev)
645 struct e6000sw_softc *sc;
647 sc = device_get_softc(dev);
649 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
654 e6000sw_getport(device_t dev, etherswitch_port_t *p)
656 struct mii_data *mii;
658 struct ifmediareq *ifmr;
661 e6000sw_softc_t *sc = device_get_softc(dev);
662 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
664 if (p->es_port >= sc->num_ports || p->es_port < 0)
666 if (!e6000sw_is_portenabled(sc, p->es_port))
670 e6000sw_get_pvid(sc, p->es_port, &p->es_pvid);
673 reg = e6000sw_readreg(sc, REG_PORT(p->es_port), PORT_CONTROL2);
674 if (reg & PORT_CONTROL2_DISC_TAGGED)
675 p->es_flags |= ETHERSWITCH_PORT_DROPTAGGED;
676 if (reg & PORT_CONTROL2_DISC_UNTAGGED)
677 p->es_flags |= ETHERSWITCH_PORT_DROPUNTAGGED;
680 if (e6000sw_is_fixedport(sc, p->es_port)) {
681 if (e6000sw_is_cpuport(sc, p->es_port))
682 p->es_flags |= ETHERSWITCH_PORT_CPU;
684 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID;
686 if (e6000sw_is_fixed25port(sc, p->es_port))
687 ifmr->ifm_active = IFM_2500_T;
689 ifmr->ifm_active = IFM_1000_T;
690 ifmr->ifm_active |= IFM_ETHER | IFM_FDX;
691 ifmr->ifm_current = ifmr->ifm_active;
694 mii = e6000sw_miiforphy(sc, p->es_port);
695 err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr,
696 &mii->mii_media, SIOCGIFMEDIA);
704 e6000sw_setport(device_t dev, etherswitch_port_t *p)
708 struct mii_data *mii;
711 sc = device_get_softc(dev);
712 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
714 if (p->es_port >= sc->num_ports || p->es_port < 0)
716 if (!e6000sw_is_portenabled(sc, p->es_port))
720 reg = e6000sw_readreg(sc, REG_PORT(p->es_port), PORT_CONTROL2);
721 if (p->es_flags & ETHERSWITCH_PORT_DROPTAGGED)
722 reg |= PORT_CONTROL2_DISC_TAGGED;
724 reg &= ~PORT_CONTROL2_DISC_TAGGED;
725 if (p->es_flags & ETHERSWITCH_PORT_DROPUNTAGGED)
726 reg |= PORT_CONTROL2_DISC_UNTAGGED;
728 reg &= ~PORT_CONTROL2_DISC_UNTAGGED;
729 e6000sw_writereg(sc, REG_PORT(p->es_port), PORT_CONTROL2, reg);
734 e6000sw_set_pvid(sc, p->es_port, p->es_pvid);
735 if (e6000sw_is_phyport(sc, p->es_port)) {
736 mii = e6000sw_miiforphy(sc, p->es_port);
737 err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr, &mii->mii_media,
746 e6000sw_port_vlan_assign(e6000sw_softc_t *sc, int port, uint32_t fid,
751 reg = e6000sw_readreg(sc, REG_PORT(port), PORT_VLAN_MAP);
752 reg &= ~(PORT_MASK(sc) | PORT_VLAN_MAP_FID_MASK);
753 reg |= members & PORT_MASK(sc) & ~(1 << port);
754 reg |= (fid << PORT_VLAN_MAP_FID) & PORT_VLAN_MAP_FID_MASK;
755 e6000sw_writereg(sc, REG_PORT(port), PORT_VLAN_MAP, reg);
756 reg = e6000sw_readreg(sc, REG_PORT(port), PORT_CONTROL1);
757 reg &= ~PORT_CONTROL1_FID_MASK;
758 reg |= (fid >> 4) & PORT_CONTROL1_FID_MASK;
759 e6000sw_writereg(sc, REG_PORT(port), PORT_CONTROL1, reg);
763 e6000sw_init_vlan(struct e6000sw_softc *sc)
768 /* Disable all ports */
769 for (port = 0; port < sc->num_ports; port++) {
770 ret = e6000sw_readreg(sc, REG_PORT(port), PORT_CONTROL);
771 e6000sw_writereg(sc, REG_PORT(port), PORT_CONTROL,
772 (ret & ~PORT_CONTROL_ENABLE));
776 e6000sw_vtu_flush(sc);
778 for (port = 0; port < sc->num_ports; port++) {
779 /* Reset the egress and frame mode. */
780 ret = e6000sw_readreg(sc, REG_PORT(port), PORT_CONTROL);
781 ret &= ~(PORT_CONTROL_EGRESS | PORT_CONTROL_FRAME);
782 e6000sw_writereg(sc, REG_PORT(port), PORT_CONTROL, ret);
784 /* Set the the 802.1q mode. */
785 ret = e6000sw_readreg(sc, REG_PORT(port), PORT_CONTROL2);
786 ret &= ~PORT_CONTROL2_DOT1Q;
787 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
788 ret |= PORT_CONTROL2_DOT1Q;
789 e6000sw_writereg(sc, REG_PORT(port), PORT_CONTROL2, ret);
792 for (port = 0; port < sc->num_ports; port++) {
793 if (!e6000sw_is_portenabled(sc, port))
796 ret = e6000sw_readreg(sc, REG_PORT(port), PORT_VID);
798 /* Set port priority */
799 ret &= ~PORT_VID_PRIORITY_MASK;
802 ret &= ~PORT_VID_DEF_VID_MASK;
803 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
807 e6000sw_writereg(sc, REG_PORT(port), PORT_VID, ret);
810 /* Assign the member ports to each origin port. */
811 for (port = 0; port < sc->num_ports; port++) {
813 if (e6000sw_is_portenabled(sc, port)) {
814 for (i = 0; i < sc->num_ports; i++) {
815 if (i == port || !e6000sw_is_portenabled(sc, i))
820 /* Default to FID 0. */
821 e6000sw_port_vlan_assign(sc, port, 0, members);
824 /* Reset internal VLAN table. */
825 for (i = 0; i < nitems(sc->vlans); i++)
828 /* Create default VLAN (1). */
829 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) {
831 e6000sw_vtu_update(sc, 0, sc->vlans[0], 1, 0, sc->ports_mask);
834 /* Enable all ports */
835 for (port = 0; port < sc->num_ports; port++) {
836 if (!e6000sw_is_portenabled(sc, port))
838 ret = e6000sw_readreg(sc, REG_PORT(port), PORT_CONTROL);
839 e6000sw_writereg(sc, REG_PORT(port), PORT_CONTROL,
840 (ret | PORT_CONTROL_ENABLE));
847 e6000sw_set_vlan_mode(struct e6000sw_softc *sc, uint32_t mode)
850 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
852 case ETHERSWITCH_VLAN_PORT:
853 sc->vlan_mode = ETHERSWITCH_VLAN_PORT;
854 etherswitch_info.es_nvlangroups = sc->num_ports;
855 return (e6000sw_init_vlan(sc));
857 case ETHERSWITCH_VLAN_DOT1Q:
858 sc->vlan_mode = ETHERSWITCH_VLAN_DOT1Q;
859 etherswitch_info.es_nvlangroups = E6000SW_NUM_VLANS;
860 return (e6000sw_init_vlan(sc));
868 * Registers in this switch are divided into sections, specified in
869 * documentation. So as to access any of them, section index and reg index
870 * is necessary. etherswitchcfg uses only one variable, so indexes were
871 * compressed into addr_reg: 32 * section_index + reg_index.
874 e6000sw_readreg_wrapper(device_t dev, int addr_reg)
877 if ((addr_reg > (REG_GLOBAL2 * 32 + REG_NUM_MAX)) ||
878 (addr_reg < (REG_PORT(0) * 32))) {
879 device_printf(dev, "Wrong register address.\n");
883 return (e6000sw_readreg(device_get_softc(dev), addr_reg / 32,
888 e6000sw_writereg_wrapper(device_t dev, int addr_reg, int val)
891 if ((addr_reg > (REG_GLOBAL2 * 32 + REG_NUM_MAX)) ||
892 (addr_reg < (REG_PORT(0) * 32))) {
893 device_printf(dev, "Wrong register address.\n");
896 e6000sw_writereg(device_get_softc(dev), addr_reg / 5,
903 * These wrappers are necessary because PHY accesses from etherswitchcfg
904 * need to be synchronized with locks, while miibus PHY accesses do not.
907 e6000sw_readphy_wrapper(device_t dev, int phy, int reg)
912 sc = device_get_softc(dev);
913 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
916 ret = e6000sw_readphy(dev, phy, reg);
923 e6000sw_writephy_wrapper(device_t dev, int phy, int reg, int data)
928 sc = device_get_softc(dev);
929 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
932 ret = e6000sw_writephy(dev, phy, reg, data);
939 * setvgroup/getvgroup called from etherswitchfcg need to be locked,
940 * while internal calls do not.
943 e6000sw_setvgroup_wrapper(device_t dev, etherswitch_vlangroup_t *vg)
948 sc = device_get_softc(dev);
949 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
952 ret = e6000sw_setvgroup(dev, vg);
959 e6000sw_getvgroup_wrapper(device_t dev, etherswitch_vlangroup_t *vg)
964 sc = device_get_softc(dev);
965 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
968 ret = e6000sw_getvgroup(dev, vg);
975 e6000sw_set_port_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg)
979 port = vg->es_vlangroup;
980 if (port > sc->num_ports)
983 if (vg->es_member_ports != vg->es_untagged_ports) {
984 device_printf(sc->dev, "Tagged ports not supported.\n");
988 e6000sw_port_vlan_assign(sc, port, 0, vg->es_untagged_ports);
989 vg->es_vid = port | ETHERSWITCH_VID_VALID;
995 e6000sw_set_dot1q_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg)
999 vlan = vg->es_vid & ETHERSWITCH_VID_MASK;
1001 /* Set VLAN to '0' removes it from table. */
1003 e6000sw_vtu_update(sc, VTU_PURGE,
1004 sc->vlans[vg->es_vlangroup], 0, 0, 0);
1005 sc->vlans[vg->es_vlangroup] = 0;
1009 /* Is this VLAN already in table ? */
1010 for (i = 0; i < etherswitch_info.es_nvlangroups; i++)
1011 if (i != vg->es_vlangroup && vlan == sc->vlans[i])
1014 sc->vlans[vg->es_vlangroup] = vlan;
1015 e6000sw_vtu_update(sc, 0, vlan, vg->es_vlangroup + 1,
1016 vg->es_member_ports & sc->ports_mask,
1017 vg->es_untagged_ports & sc->ports_mask);
1023 e6000sw_setvgroup(device_t dev, etherswitch_vlangroup_t *vg)
1025 e6000sw_softc_t *sc;
1027 sc = device_get_softc(dev);
1028 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1030 if (sc->vlan_mode == ETHERSWITCH_VLAN_PORT)
1031 return (e6000sw_set_port_vlan(sc, vg));
1032 else if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
1033 return (e6000sw_set_dot1q_vlan(sc, vg));
1039 e6000sw_get_port_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg)
1043 port = vg->es_vlangroup;
1044 if (port > sc->num_ports)
1047 if (!e6000sw_is_portenabled(sc, port)) {
1052 reg = e6000sw_readreg(sc, REG_PORT(port), PORT_VLAN_MAP);
1053 vg->es_untagged_ports = vg->es_member_ports = reg & PORT_MASK(sc);
1054 vg->es_vid = port | ETHERSWITCH_VID_VALID;
1055 vg->es_fid = (reg & PORT_VLAN_MAP_FID_MASK) >> PORT_VLAN_MAP_FID;
1056 reg = e6000sw_readreg(sc, REG_PORT(port), PORT_CONTROL1);
1057 vg->es_fid |= (reg & PORT_CONTROL1_FID_MASK) << 4;
1063 e6000sw_get_dot1q_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg)
1069 vg->es_vid = sc->vlans[vg->es_vlangroup];
1070 vg->es_untagged_ports = vg->es_member_ports = 0;
1071 if (vg->es_vid == 0)
1074 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1075 device_printf(sc->dev, "VTU unit is busy, cannot access\n");
1079 e6000sw_writereg(sc, REG_GLOBAL, VTU_VID, vg->es_vid - 1);
1081 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_OPERATION);
1082 reg &= ~VTU_OP_MASK;
1083 reg |= VTU_GET_NEXT | VTU_BUSY;
1084 e6000sw_writereg(sc, REG_GLOBAL, VTU_OPERATION, reg);
1085 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1086 device_printf(sc->dev, "Timeout while reading\n");
1090 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_VID);
1091 if (reg == VTU_VID_MASK || (reg & VTU_VID_VALID) == 0)
1093 if ((reg & VTU_VID_MASK) != vg->es_vid)
1096 vg->es_vid |= ETHERSWITCH_VID_VALID;
1097 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_DATA);
1098 for (i = 0; i < sc->num_ports; i++) {
1099 if (i == VTU_PPREG(sc))
1100 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_DATA2);
1101 port = (reg >> VTU_PORT(sc, i)) & VTU_PORT_MASK;
1102 if (port == VTU_PORT_UNTAGGED) {
1103 vg->es_untagged_ports |= (1 << i);
1104 vg->es_member_ports |= (1 << i);
1105 } else if (port == VTU_PORT_TAGGED)
1106 vg->es_member_ports |= (1 << i);
1113 e6000sw_getvgroup(device_t dev, etherswitch_vlangroup_t *vg)
1115 e6000sw_softc_t *sc;
1117 sc = device_get_softc(dev);
1118 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1120 if (sc->vlan_mode == ETHERSWITCH_VLAN_PORT)
1121 return (e6000sw_get_port_vlan(sc, vg));
1122 else if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
1123 return (e6000sw_get_dot1q_vlan(sc, vg));
1128 static __inline struct mii_data*
1129 e6000sw_miiforphy(e6000sw_softc_t *sc, unsigned int phy)
1132 if (!e6000sw_is_phyport(sc, phy))
1135 return (device_get_softc(sc->miibus[phy]));
1139 e6000sw_ifmedia_upd(struct ifnet *ifp)
1141 e6000sw_softc_t *sc;
1142 struct mii_data *mii;
1145 mii = e6000sw_miiforphy(sc, ifp->if_dunit);
1154 e6000sw_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1156 e6000sw_softc_t *sc;
1157 struct mii_data *mii;
1160 mii = e6000sw_miiforphy(sc, ifp->if_dunit);
1166 ifmr->ifm_active = mii->mii_media_active;
1167 ifmr->ifm_status = mii->mii_media_status;
1171 e6000sw_smi_waitready(e6000sw_softc_t *sc, int phy)
1175 for (i = 0; i < E6000SW_SMI_TIMEOUT; i++) {
1176 if ((MDIO_READ(sc->dev, phy, SMI_CMD) & SMI_CMD_BUSY) == 0)
1184 static __inline uint32_t
1185 e6000sw_readreg(e6000sw_softc_t *sc, int addr, int reg)
1188 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1190 if (!MVSWITCH_MULTICHIP(sc))
1191 return (MDIO_READ(sc->dev, addr, reg) & 0xffff);
1193 if (e6000sw_smi_waitready(sc, sc->sw_addr)) {
1194 printf("e6000sw: readreg timeout\n");
1197 MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD,
1198 SMI_CMD_OP_C22_READ | (reg & SMI_CMD_REG_ADDR_MASK) |
1199 ((addr << SMI_CMD_DEV_ADDR) & SMI_CMD_DEV_ADDR_MASK));
1200 if (e6000sw_smi_waitready(sc, sc->sw_addr)) {
1201 printf("e6000sw: readreg timeout\n");
1205 return (MDIO_READ(sc->dev, sc->sw_addr, SMI_DATA) & 0xffff);
1208 static __inline void
1209 e6000sw_writereg(e6000sw_softc_t *sc, int addr, int reg, int val)
1212 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1214 if (!MVSWITCH_MULTICHIP(sc)) {
1215 MDIO_WRITE(sc->dev, addr, reg, val);
1219 if (e6000sw_smi_waitready(sc, sc->sw_addr)) {
1220 printf("e6000sw: readreg timeout\n");
1223 MDIO_WRITE(sc->dev, sc->sw_addr, SMI_DATA, val);
1224 MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD,
1225 SMI_CMD_OP_C22_WRITE | (reg & SMI_CMD_REG_ADDR_MASK) |
1226 ((addr << SMI_CMD_DEV_ADDR) & SMI_CMD_DEV_ADDR_MASK));
1229 static __inline bool
1230 e6000sw_is_cpuport(e6000sw_softc_t *sc, int port)
1233 return ((sc->cpuports_mask & (1 << port)) ? true : false);
1236 static __inline bool
1237 e6000sw_is_fixedport(e6000sw_softc_t *sc, int port)
1240 return ((sc->fixed_mask & (1 << port)) ? true : false);
1243 static __inline bool
1244 e6000sw_is_fixed25port(e6000sw_softc_t *sc, int port)
1247 return ((sc->fixed25_mask & (1 << port)) ? true : false);
1250 static __inline bool
1251 e6000sw_is_phyport(e6000sw_softc_t *sc, int port)
1254 phy_mask = ~(sc->fixed_mask | sc->cpuports_mask);
1256 return ((phy_mask & (1 << port)) ? true : false);
1259 static __inline bool
1260 e6000sw_is_portenabled(e6000sw_softc_t *sc, int port)
1263 return ((sc->ports_mask & (1 << port)) ? true : false);
1266 static __inline void
1267 e6000sw_set_pvid(e6000sw_softc_t *sc, int port, int pvid)
1271 reg = e6000sw_readreg(sc, REG_PORT(port), PORT_VID);
1272 reg &= ~PORT_VID_DEF_VID_MASK;
1273 reg |= (pvid & PORT_VID_DEF_VID_MASK);
1274 e6000sw_writereg(sc, REG_PORT(port), PORT_VID, reg);
1278 e6000sw_get_pvid(e6000sw_softc_t *sc, int port, int *pvid)
1284 *pvid = e6000sw_readreg(sc, REG_PORT(port), PORT_VID) &
1285 PORT_VID_DEF_VID_MASK;
1291 * Convert port status to ifmedia.
1294 e6000sw_update_ifmedia(uint16_t portstatus, u_int *media_status, u_int *media_active)
1296 *media_active = IFM_ETHER;
1297 *media_status = IFM_AVALID;
1299 if ((portstatus & PORT_STATUS_LINK_MASK) != 0)
1300 *media_status |= IFM_ACTIVE;
1302 *media_active |= IFM_NONE;
1306 switch (portstatus & PORT_STATUS_SPEED_MASK) {
1307 case PORT_STATUS_SPEED_10:
1308 *media_active |= IFM_10_T;
1310 case PORT_STATUS_SPEED_100:
1311 *media_active |= IFM_100_TX;
1313 case PORT_STATUS_SPEED_1000:
1314 *media_active |= IFM_1000_T;
1318 if ((portstatus & PORT_STATUS_DUPLEX_MASK) == 0)
1319 *media_active |= IFM_FDX;
1321 *media_active |= IFM_HDX;
1325 e6000sw_tick(void *arg)
1327 e6000sw_softc_t *sc;
1328 struct mii_data *mii;
1329 struct mii_softc *miisc;
1330 uint16_t portstatus;
1335 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
1339 for (port = 0; port < sc->num_ports; port++) {
1340 /* Tick only on PHY ports */
1341 if (!e6000sw_is_portenabled(sc, port) ||
1342 !e6000sw_is_phyport(sc, port))
1345 mii = e6000sw_miiforphy(sc, port);
1349 portstatus = e6000sw_readreg(sc, REG_PORT(port),
1352 e6000sw_update_ifmedia(portstatus,
1353 &mii->mii_media_status, &mii->mii_media_active);
1355 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
1356 if (IFM_INST(mii->mii_media.ifm_cur->ifm_media)
1359 mii_phy_update(miisc, MII_POLLSTAT);
1363 pause("e6000sw tick", 1000);
1368 e6000sw_setup(device_t dev, e6000sw_softc_t *sc)
1372 /* Set aging time. */
1373 atu_ctrl = e6000sw_readreg(sc, REG_GLOBAL, ATU_CONTROL);
1374 atu_ctrl &= ~ATU_CONTROL_AGETIME_MASK;
1375 atu_ctrl |= E6000SW_DEFAULT_AGETIME << ATU_CONTROL_AGETIME;
1376 e6000sw_writereg(sc, REG_GLOBAL, ATU_CONTROL, atu_ctrl);
1378 /* Send all with specific mac address to cpu port */
1379 e6000sw_writereg(sc, REG_GLOBAL2, MGMT_EN_2x, MGMT_EN_ALL);
1380 e6000sw_writereg(sc, REG_GLOBAL2, MGMT_EN_0x, MGMT_EN_ALL);
1382 /* Disable Remote Management */
1383 e6000sw_writereg(sc, REG_GLOBAL, SWITCH_GLOBAL_CONTROL2, 0);
1385 /* Disable loopback filter and flow control messages */
1386 e6000sw_writereg(sc, REG_GLOBAL2, SWITCH_MGMT,
1387 SWITCH_MGMT_PRI_MASK |
1388 (1 << SWITCH_MGMT_RSVD2CPU) |
1389 SWITCH_MGMT_FC_PRI_MASK |
1390 (1 << SWITCH_MGMT_FORCEFLOW));
1392 e6000sw_atu_flush(dev, sc, NO_OPERATION);
1393 e6000sw_atu_mac_table(dev, sc, NULL, NO_OPERATION);
1394 e6000sw_set_atustat(dev, sc, 0, COUNT_ALL);
1398 e6000sw_set_atustat(device_t dev, e6000sw_softc_t *sc, int bin, int flag)
1402 ret = e6000sw_readreg(sc, REG_GLOBAL2, ATU_STATS);
1403 e6000sw_writereg(sc, REG_GLOBAL2, ATU_STATS, (bin << ATU_STATS_BIN ) |
1404 (flag << ATU_STATS_FLAG));
1408 e6000sw_atu_mac_table(device_t dev, e6000sw_softc_t *sc, struct atu_opt *atu,
1414 if (flag == NO_OPERATION)
1416 else if ((flag & (LOAD_FROM_FIB | PURGE_FROM_FIB | GET_NEXT_IN_FIB |
1417 GET_VIOLATION_DATA | CLEAR_VIOLATION_DATA)) == 0) {
1418 device_printf(dev, "Wrong Opcode for ATU operation\n");
1422 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY)) {
1423 device_printf(dev, "ATU unit is busy, cannot access\n");
1427 ret_opt = e6000sw_readreg(sc, REG_GLOBAL, ATU_OPERATION);
1428 if (flag & LOAD_FROM_FIB) {
1429 ret_data = e6000sw_readreg(sc, REG_GLOBAL, ATU_DATA);
1430 e6000sw_writereg(sc, REG_GLOBAL2, ATU_DATA, (ret_data &
1433 e6000sw_writereg(sc, REG_GLOBAL, ATU_MAC_ADDR01, atu->mac_01);
1434 e6000sw_writereg(sc, REG_GLOBAL, ATU_MAC_ADDR23, atu->mac_23);
1435 e6000sw_writereg(sc, REG_GLOBAL, ATU_MAC_ADDR45, atu->mac_45);
1436 e6000sw_writereg(sc, REG_GLOBAL, ATU_FID, atu->fid);
1438 e6000sw_writereg(sc, REG_GLOBAL, ATU_OPERATION,
1439 (ret_opt | ATU_UNIT_BUSY | flag));
1441 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY))
1442 device_printf(dev, "Timeout while waiting ATU\n");
1443 else if (flag & GET_NEXT_IN_FIB) {
1444 atu->mac_01 = e6000sw_readreg(sc, REG_GLOBAL,
1446 atu->mac_23 = e6000sw_readreg(sc, REG_GLOBAL,
1448 atu->mac_45 = e6000sw_readreg(sc, REG_GLOBAL,
1456 e6000sw_atu_flush(device_t dev, e6000sw_softc_t *sc, int flag)
1460 if (flag == NO_OPERATION)
1463 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY)) {
1464 device_printf(dev, "ATU unit is busy, cannot access\n");
1467 reg = e6000sw_readreg(sc, REG_GLOBAL, ATU_OPERATION);
1468 e6000sw_writereg(sc, REG_GLOBAL, ATU_OPERATION,
1469 (reg | ATU_UNIT_BUSY | flag));
1470 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY))
1471 device_printf(dev, "Timeout while flushing ATU\n");
1477 e6000sw_vtu_flush(e6000sw_softc_t *sc)
1480 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1481 device_printf(sc->dev, "VTU unit is busy, cannot access\n");
1485 e6000sw_writereg(sc, REG_GLOBAL, VTU_OPERATION, VTU_FLUSH | VTU_BUSY);
1486 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1487 device_printf(sc->dev, "Timeout while flushing VTU\n");
1495 e6000sw_vtu_update(e6000sw_softc_t *sc, int purge, int vid, int fid,
1496 int members, int untagged)
1501 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1502 device_printf(sc->dev, "VTU unit is busy, cannot access\n");
1506 *data = (vid & VTU_VID_MASK);
1508 *data |= VTU_VID_VALID;
1509 e6000sw_writereg(sc, REG_GLOBAL, VTU_VID, *data);
1514 for (i = 0; i < sc->num_ports; i++) {
1515 if ((untagged & (1 << i)) != 0)
1516 data[i / VTU_PPREG(sc)] |=
1517 VTU_PORT_UNTAGGED << VTU_PORT(sc, i);
1518 else if ((members & (1 << i)) != 0)
1519 data[i / VTU_PPREG(sc)] |=
1520 VTU_PORT_TAGGED << VTU_PORT(sc, i);
1522 data[i / VTU_PPREG(sc)] |=
1523 VTU_PORT_DISCARD << VTU_PORT(sc, i);
1525 e6000sw_writereg(sc, REG_GLOBAL, VTU_DATA, data[0]);
1526 e6000sw_writereg(sc, REG_GLOBAL, VTU_DATA2, data[1]);
1527 e6000sw_writereg(sc, REG_GLOBAL, VTU_FID,
1528 fid & VTU_FID_MASK(sc));
1533 e6000sw_writereg(sc, REG_GLOBAL, VTU_OPERATION, op | VTU_BUSY);
1534 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1535 device_printf(sc->dev, "Timeout while flushing VTU\n");