2 * Copyright (c) 2011-2012 Stefan Bethke.
3 * Copyright (c) 2012 Adrian Chadd.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/param.h>
32 #include <sys/errno.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/module.h>
36 #include <sys/socket.h>
37 #include <sys/sockio.h>
38 #include <sys/sysctl.h>
39 #include <sys/systm.h>
42 #include <net/if_var.h>
43 #include <net/if_arp.h>
44 #include <net/ethernet.h>
45 #include <net/if_dl.h>
46 #include <net/if_media.h>
47 #include <net/if_types.h>
49 #include <machine/bus.h>
50 #include <dev/iicbus/iic.h>
51 #include <dev/iicbus/iiconf.h>
52 #include <dev/iicbus/iicbus.h>
53 #include <dev/mii/mii.h>
54 #include <dev/mii/miivar.h>
55 #include <dev/mdio/mdio.h>
57 #include <dev/etherswitch/etherswitch.h>
59 #include <dev/etherswitch/arswitch/arswitchreg.h>
60 #include <dev/etherswitch/arswitch/arswitchvar.h>
61 #include <dev/etherswitch/arswitch/arswitch_reg.h>
62 #include <dev/etherswitch/arswitch/arswitch_phy.h>
63 #include <dev/etherswitch/arswitch/arswitch_vlans.h>
65 #include <dev/etherswitch/arswitch/arswitch_7240.h>
66 #include <dev/etherswitch/arswitch/arswitch_8216.h>
67 #include <dev/etherswitch/arswitch/arswitch_8226.h>
68 #include <dev/etherswitch/arswitch/arswitch_8316.h>
69 #include <dev/etherswitch/arswitch/arswitch_8327.h>
70 #include <dev/etherswitch/arswitch/arswitch_9340.h>
73 #include "miibus_if.h"
74 #include "etherswitch_if.h"
77 static SYSCTL_NODE(_debug, OID_AUTO, arswitch, CTLFLAG_RD, 0, "arswitch");
80 static inline int arswitch_portforphy(int phy);
81 static void arswitch_tick(void *arg);
82 static int arswitch_ifmedia_upd(struct ifnet *);
83 static void arswitch_ifmedia_sts(struct ifnet *, struct ifmediareq *);
84 static int ar8xxx_port_vlan_setup(struct arswitch_softc *sc,
85 etherswitch_port_t *p);
86 static int ar8xxx_port_vlan_get(struct arswitch_softc *sc,
87 etherswitch_port_t *p);
90 arswitch_probe(device_t dev)
92 struct arswitch_softc *sc;
94 char *chipname, desc[256];
96 sc = device_get_softc(dev);
97 bzero(sc, sizeof(*sc));
101 if (ar7240_probe(dev) == 0) {
103 sc->sc_switchtype = AR8X16_SWITCH_AR7240;
104 sc->is_internal_switch = 1;
110 if (ar9340_probe(dev) == 0) {
112 sc->sc_switchtype = AR8X16_SWITCH_AR9340;
113 sc->is_internal_switch = 1;
119 id = arswitch_readreg(dev, AR8X16_REG_MASK_CTRL);
120 sc->chip_rev = (id & AR8X16_MASK_CTRL_REV_MASK);
121 sc->chip_ver = (id & AR8X16_MASK_CTRL_VER_MASK) > AR8X16_MASK_CTRL_VER_SHIFT;
122 switch (id & (AR8X16_MASK_CTRL_VER_MASK | AR8X16_MASK_CTRL_REV_MASK)) {
125 sc->sc_switchtype = AR8X16_SWITCH_AR8216;
129 sc->sc_switchtype = AR8X16_SWITCH_AR8226;
131 /* 0x0301 - AR8236 */
135 sc->sc_switchtype = AR8X16_SWITCH_AR8316;
140 sc->sc_switchtype = AR8X16_SWITCH_AR8327;
141 sc->mii_lo_first = 1;
149 DPRINTF(dev, "chipname=%s, id=%08x\n", chipname, id);
150 if (chipname != NULL) {
151 snprintf(desc, sizeof(desc),
152 "Atheros %s Ethernet Switch (ver %d rev %d)",
156 device_set_desc_copy(dev, desc);
157 return (BUS_PROBE_DEFAULT);
163 arswitch_attach_phys(struct arswitch_softc *sc)
168 /* PHYs need an interface, so we generate a dummy one */
169 snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->sc_dev));
170 for (phy = 0; phy < sc->numphys; phy++) {
171 sc->ifp[phy] = if_alloc(IFT_ETHER);
172 sc->ifp[phy]->if_softc = sc;
173 sc->ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST |
174 IFF_DRV_RUNNING | IFF_SIMPLEX;
175 sc->ifname[phy] = malloc(strlen(name)+1, M_DEVBUF, M_WAITOK);
176 bcopy(name, sc->ifname[phy], strlen(name)+1);
177 if_initname(sc->ifp[phy], sc->ifname[phy],
178 arswitch_portforphy(phy));
179 err = mii_attach(sc->sc_dev, &sc->miibus[phy], sc->ifp[phy],
180 arswitch_ifmedia_upd, arswitch_ifmedia_sts, \
181 BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
183 DPRINTF(sc->sc_dev, "%s attached to pseudo interface %s\n",
184 device_get_nameunit(sc->miibus[phy]),
185 sc->ifp[phy]->if_xname);
188 device_printf(sc->sc_dev,
189 "attaching PHY %d failed\n",
197 arswitch_reset(device_t dev)
200 arswitch_writereg(dev, AR8X16_REG_MASK_CTRL,
201 AR8X16_MASK_CTRL_SOFT_RESET);
203 if (arswitch_readreg(dev, AR8X16_REG_MASK_CTRL) &
204 AR8X16_MASK_CTRL_SOFT_RESET) {
205 device_printf(dev, "unable to reset switch\n");
212 arswitch_set_vlan_mode(struct arswitch_softc *sc, uint32_t mode)
215 /* Check for invalid modes. */
216 if ((mode & sc->info.es_vlan_caps) != mode)
220 case ETHERSWITCH_VLAN_DOT1Q:
221 sc->vlan_mode = ETHERSWITCH_VLAN_DOT1Q;
223 case ETHERSWITCH_VLAN_PORT:
224 sc->vlan_mode = ETHERSWITCH_VLAN_PORT;
231 sc->hal.arswitch_vlan_init_hw(sc);
237 ar8xxx_port_init(struct arswitch_softc *sc, int port)
241 if (port == AR8X16_PORT_CPU) {
242 arswitch_writereg(sc->sc_dev, AR8X16_REG_PORT_STS(0),
243 (AR8X16_IS_SWITCH(sc, AR8216) ?
244 AR8X16_PORT_STS_SPEED_100 : AR8X16_PORT_STS_SPEED_1000) |
245 (AR8X16_IS_SWITCH(sc, AR8216) ? 0 : AR8X16_PORT_STS_RXFLOW) |
246 (AR8X16_IS_SWITCH(sc, AR8216) ? 0 : AR8X16_PORT_STS_TXFLOW) |
247 AR8X16_PORT_STS_RXMAC |
248 AR8X16_PORT_STS_TXMAC |
249 AR8X16_PORT_STS_DUPLEX);
250 arswitch_writereg(sc->sc_dev, AR8X16_REG_PORT_CTRL(0),
251 arswitch_readreg(sc->sc_dev, AR8X16_REG_PORT_CTRL(0)) &
252 ~AR8X16_PORT_CTRL_HEADER);
254 /* Set ports to auto negotiation. */
255 arswitch_writereg(sc->sc_dev, AR8X16_REG_PORT_STS(port),
256 AR8X16_PORT_STS_LINK_AUTO);
257 arswitch_writereg(sc->sc_dev, AR8X16_REG_PORT_CTRL(port),
258 arswitch_readreg(sc->sc_dev, AR8X16_REG_PORT_CTRL(port)) &
259 ~AR8X16_PORT_CTRL_HEADER);
264 ar8xxx_atu_flush(struct arswitch_softc *sc)
268 ret = arswitch_waitreg(sc->sc_dev,
275 device_printf(sc->sc_dev, "%s: waitreg failed\n", __func__);
278 arswitch_writereg(sc->sc_dev,
280 AR8216_ATU_OP_FLUSH);
286 arswitch_attach(device_t dev)
288 struct arswitch_softc *sc;
292 sc = device_get_softc(dev);
294 /* sc->sc_switchtype is already decided in arswitch_probe() */
296 mtx_init(&sc->sc_mtx, "arswitch", NULL, MTX_DEF);
298 strlcpy(sc->info.es_name, device_get_desc(dev),
299 sizeof(sc->info.es_name));
301 /* Default HAL methods */
302 sc->hal.arswitch_port_init = ar8xxx_port_init;
303 sc->hal.arswitch_port_vlan_setup = ar8xxx_port_vlan_setup;
304 sc->hal.arswitch_port_vlan_get = ar8xxx_port_vlan_get;
305 sc->hal.arswitch_vlan_init_hw = ar8xxx_reset_vlans;
307 sc->hal.arswitch_vlan_getvgroup = ar8xxx_getvgroup;
308 sc->hal.arswitch_vlan_setvgroup = ar8xxx_setvgroup;
310 sc->hal.arswitch_vlan_get_pvid = ar8xxx_get_pvid;
311 sc->hal.arswitch_vlan_set_pvid = ar8xxx_set_pvid;
313 sc->hal.arswitch_get_dot1q_vlan = ar8xxx_get_dot1q_vlan;
314 sc->hal.arswitch_set_dot1q_vlan = ar8xxx_set_dot1q_vlan;
315 sc->hal.arswitch_flush_dot1q_vlan = ar8xxx_flush_dot1q_vlan;
316 sc->hal.arswitch_purge_dot1q_vlan = ar8xxx_purge_dot1q_vlan;
317 sc->hal.arswitch_get_port_vlan = ar8xxx_get_port_vlan;
318 sc->hal.arswitch_set_port_vlan = ar8xxx_set_port_vlan;
320 sc->hal.arswitch_atu_flush = ar8xxx_atu_flush;
322 sc->hal.arswitch_phy_read = arswitch_readphy_internal;
323 sc->hal.arswitch_phy_write = arswitch_writephy_internal;
327 * Attach switch related functions
329 if (AR8X16_IS_SWITCH(sc, AR7240))
331 else if (AR8X16_IS_SWITCH(sc, AR9340))
333 else if (AR8X16_IS_SWITCH(sc, AR8216))
335 else if (AR8X16_IS_SWITCH(sc, AR8226))
337 else if (AR8X16_IS_SWITCH(sc, AR8316))
339 else if (AR8X16_IS_SWITCH(sc, AR8327))
342 DPRINTF(dev, "%s: unknown switch (%d)?\n", __func__, sc->sc_switchtype);
346 /* Common defaults. */
347 sc->info.es_nports = 5; /* XXX technically 6, but 6th not used */
349 /* XXX Defaults for externally connected AR8316 */
356 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
357 "numphys", &sc->numphys);
358 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
359 "phy4cpu", &sc->phy4cpu);
360 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
361 "is_rgmii", &sc->is_rgmii);
362 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
363 "is_gmii", &sc->is_gmii);
364 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
365 "is_mii", &sc->is_mii);
367 if (sc->numphys > AR8X16_NUM_PHYS)
368 sc->numphys = AR8X16_NUM_PHYS;
370 /* Reset the switch. */
371 if (arswitch_reset(dev)) {
372 DPRINTF(dev, "%s: arswitch_reset: failed\n", __func__);
376 err = sc->hal.arswitch_hw_setup(sc);
377 DPRINTF(dev, "%s: hw_setup: err=%d\n", __func__, err);
381 err = sc->hal.arswitch_hw_global_setup(sc);
382 DPRINTF(dev, "%s: hw_global_setup: err=%d\n", __func__, err);
386 /* Initialize the switch ports. */
387 for (port = 0; port <= sc->numphys; port++) {
388 sc->hal.arswitch_port_init(sc, port);
392 * Attach the PHYs and complete the bus enumeration.
394 err = arswitch_attach_phys(sc);
395 DPRINTF(dev, "%s: attach_phys: err=%d\n", __func__, err);
399 /* Default to ingress filters off. */
400 err = arswitch_set_vlan_mode(sc, 0);
401 DPRINTF(dev, "%s: set_vlan_mode: err=%d\n", __func__, err);
405 bus_generic_probe(dev);
406 bus_enumerate_hinted_children(dev);
407 err = bus_generic_attach(dev);
408 DPRINTF(dev, "%s: bus_generic_attach: err=%d\n", __func__, err);
412 callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
422 arswitch_detach(device_t dev)
424 struct arswitch_softc *sc = device_get_softc(dev);
427 callout_drain(&sc->callout_tick);
429 for (i=0; i < sc->numphys; i++) {
430 if (sc->miibus[i] != NULL)
431 device_delete_child(dev, sc->miibus[i]);
432 if (sc->ifp[i] != NULL)
434 free(sc->ifname[i], M_DEVBUF);
437 bus_generic_detach(dev);
438 mtx_destroy(&sc->sc_mtx);
444 * Convert PHY number to port number. PHY0 is connected to port 1, PHY1 to
448 arswitch_portforphy(int phy)
453 static inline struct mii_data *
454 arswitch_miiforport(struct arswitch_softc *sc, int port)
458 if (phy < 0 || phy >= sc->numphys)
460 return (device_get_softc(sc->miibus[phy]));
463 static inline struct ifnet *
464 arswitch_ifpforport(struct arswitch_softc *sc, int port)
468 if (phy < 0 || phy >= sc->numphys)
470 return (sc->ifp[phy]);
474 * Convert port status to ifmedia.
477 arswitch_update_ifmedia(int portstatus, u_int *media_status, u_int *media_active)
479 *media_active = IFM_ETHER;
480 *media_status = IFM_AVALID;
482 if ((portstatus & AR8X16_PORT_STS_LINK_UP) != 0)
483 *media_status |= IFM_ACTIVE;
485 *media_active |= IFM_NONE;
488 switch (portstatus & AR8X16_PORT_STS_SPEED_MASK) {
489 case AR8X16_PORT_STS_SPEED_10:
490 *media_active |= IFM_10_T;
492 case AR8X16_PORT_STS_SPEED_100:
493 *media_active |= IFM_100_TX;
495 case AR8X16_PORT_STS_SPEED_1000:
496 *media_active |= IFM_1000_T;
499 if ((portstatus & AR8X16_PORT_STS_DUPLEX) == 0)
500 *media_active |= IFM_FDX;
502 *media_active |= IFM_HDX;
503 if ((portstatus & AR8X16_PORT_STS_TXFLOW) != 0)
504 *media_active |= IFM_ETH_TXPAUSE;
505 if ((portstatus & AR8X16_PORT_STS_RXFLOW) != 0)
506 *media_active |= IFM_ETH_RXPAUSE;
510 * Poll the status for all PHYs. We're using the switch port status because
511 * thats a lot quicker to read than talking to all the PHYs. Care must be
512 * taken that the resulting ifmedia_active is identical to what the PHY will
513 * compute, or gratuitous link status changes will occur whenever the PHYs
514 * update function is called.
517 arswitch_miipollstat(struct arswitch_softc *sc)
520 struct mii_data *mii;
521 struct mii_softc *miisc;
525 ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
527 for (i = 0; i < sc->numphys; i++) {
528 if (sc->miibus[i] == NULL)
530 mii = device_get_softc(sc->miibus[i]);
531 /* XXX This would be nice to have abstracted out to be per-chip */
532 /* AR8327/AR8337 has a different register base */
533 if (AR8X16_IS_SWITCH(sc, AR8327))
534 portstatus = arswitch_readreg(sc->sc_dev,
535 AR8327_REG_PORT_STATUS(arswitch_portforphy(i)));
537 portstatus = arswitch_readreg(sc->sc_dev,
538 AR8X16_REG_PORT_STS(arswitch_portforphy(i)));
540 DPRINTF(sc->sc_dev, "p[%d]=%b\n",
543 "\20\3TXMAC\4RXMAC\5TXFLOW\6RXFLOW\7"
544 "DUPLEX\11LINK_UP\12LINK_AUTO\13LINK_PAUSE");
547 * If the current status is down, but we have a link
548 * status showing up, we need to do an ATU flush.
550 if ((mii->mii_media_status & IFM_ACTIVE) == 0 &&
551 (portstatus & AR8X16_PORT_STS_LINK_UP) != 0) {
552 device_printf(sc->sc_dev, "%s: port %d: port -> UP\n",
558 * and maybe if a port goes up->down?
560 if ((mii->mii_media_status & IFM_ACTIVE) != 0 &&
561 (portstatus & AR8X16_PORT_STS_LINK_UP) == 0) {
562 device_printf(sc->sc_dev, "%s: port %d: port -> DOWN\n",
567 arswitch_update_ifmedia(portstatus, &mii->mii_media_status,
568 &mii->mii_media_active);
569 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
570 if (IFM_INST(mii->mii_media.ifm_cur->ifm_media) !=
573 mii_phy_update(miisc, MII_POLLSTAT);
577 /* If a port went from down->up, flush the ATU */
579 sc->hal.arswitch_atu_flush(sc);
583 arswitch_tick(void *arg)
585 struct arswitch_softc *sc = arg;
587 arswitch_miipollstat(sc);
588 callout_reset(&sc->callout_tick, hz, arswitch_tick, sc);
592 arswitch_lock(device_t dev)
594 struct arswitch_softc *sc = device_get_softc(dev);
596 ARSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
601 arswitch_unlock(device_t dev)
603 struct arswitch_softc *sc = device_get_softc(dev);
605 ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
609 static etherswitch_info_t *
610 arswitch_getinfo(device_t dev)
612 struct arswitch_softc *sc = device_get_softc(dev);
618 ar8xxx_port_vlan_get(struct arswitch_softc *sc, etherswitch_port_t *p)
624 /* Retrieve the PVID. */
625 sc->hal.arswitch_vlan_get_pvid(sc, p->es_port, &p->es_pvid);
628 reg = arswitch_readreg(sc->sc_dev, AR8X16_REG_PORT_CTRL(p->es_port));
629 if (reg & AR8X16_PORT_CTRL_DOUBLE_TAG)
630 p->es_flags |= ETHERSWITCH_PORT_DOUBLE_TAG;
631 reg >>= AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_SHIFT;
632 if ((reg & 0x3) == AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_ADD)
633 p->es_flags |= ETHERSWITCH_PORT_ADDTAG;
634 if ((reg & 0x3) == AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_STRIP)
635 p->es_flags |= ETHERSWITCH_PORT_STRIPTAG;
642 arswitch_is_cpuport(struct arswitch_softc *sc, int port)
645 return ((port == AR8X16_PORT_CPU) ||
646 ((AR8X16_IS_SWITCH(sc, AR8327) &&
647 port == AR8327_PORT_GMAC6)));
651 arswitch_getport(device_t dev, etherswitch_port_t *p)
653 struct arswitch_softc *sc;
654 struct mii_data *mii;
655 struct ifmediareq *ifmr;
658 sc = device_get_softc(dev);
659 /* XXX +1 is for AR8327; should make this configurable! */
660 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
663 err = sc->hal.arswitch_port_vlan_get(sc, p);
667 mii = arswitch_miiforport(sc, p->es_port);
668 if (arswitch_is_cpuport(sc, p->es_port)) {
669 /* fill in fixed values for CPU port */
670 /* XXX is this valid in all cases? */
671 p->es_flags |= ETHERSWITCH_PORT_CPU;
674 ifmr->ifm_current = ifmr->ifm_active =
675 IFM_ETHER | IFM_1000_T | IFM_FDX;
677 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID;
678 } else if (mii != NULL) {
679 err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr,
680 &mii->mii_media, SIOCGIFMEDIA);
690 ar8xxx_port_vlan_setup(struct arswitch_softc *sc, etherswitch_port_t *p)
699 sc->hal.arswitch_vlan_set_pvid(sc, p->es_port, p->es_pvid);
701 /* Mutually exclusive. */
702 if (p->es_flags & ETHERSWITCH_PORT_ADDTAG &&
703 p->es_flags & ETHERSWITCH_PORT_STRIPTAG) {
709 if (p->es_flags & ETHERSWITCH_PORT_DOUBLE_TAG)
710 reg |= AR8X16_PORT_CTRL_DOUBLE_TAG;
711 if (p->es_flags & ETHERSWITCH_PORT_ADDTAG)
712 reg |= AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_ADD <<
713 AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_SHIFT;
714 if (p->es_flags & ETHERSWITCH_PORT_STRIPTAG)
715 reg |= AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_STRIP <<
716 AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_SHIFT;
718 err = arswitch_modifyreg(sc->sc_dev,
719 AR8X16_REG_PORT_CTRL(p->es_port),
720 0x3 << AR8X16_PORT_CTRL_EGRESS_VLAN_MODE_SHIFT |
721 AR8X16_PORT_CTRL_DOUBLE_TAG, reg);
728 arswitch_setport(device_t dev, etherswitch_port_t *p)
731 struct arswitch_softc *sc;
733 struct mii_data *mii;
736 sc = device_get_softc(dev);
737 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
741 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) {
742 err = sc->hal.arswitch_port_vlan_setup(sc, p);
747 /* Do not allow media changes on CPU port. */
748 if (arswitch_is_cpuport(sc, p->es_port))
751 mii = arswitch_miiforport(sc, p->es_port);
755 ifp = arswitch_ifpforport(sc, p->es_port);
757 ifm = &mii->mii_media;
758 return (ifmedia_ioctl(ifp, &p->es_ifr, ifm, SIOCSIFMEDIA));
762 arswitch_statchg(device_t dev)
765 DPRINTF(dev, "%s\n", __func__);
769 arswitch_ifmedia_upd(struct ifnet *ifp)
771 struct arswitch_softc *sc = ifp->if_softc;
772 struct mii_data *mii = arswitch_miiforport(sc, ifp->if_dunit);
781 arswitch_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
783 struct arswitch_softc *sc = ifp->if_softc;
784 struct mii_data *mii = arswitch_miiforport(sc, ifp->if_dunit);
786 DPRINTF(sc->sc_dev, "%s\n", __func__);
791 ifmr->ifm_active = mii->mii_media_active;
792 ifmr->ifm_status = mii->mii_media_status;
796 arswitch_getconf(device_t dev, etherswitch_conf_t *conf)
798 struct arswitch_softc *sc;
800 sc = device_get_softc(dev);
802 /* Return the VLAN mode. */
803 conf->cmd = ETHERSWITCH_CONF_VLAN_MODE;
804 conf->vlan_mode = sc->vlan_mode;
810 arswitch_setconf(device_t dev, etherswitch_conf_t *conf)
812 struct arswitch_softc *sc;
815 sc = device_get_softc(dev);
817 /* Set the VLAN mode. */
818 if (conf->cmd & ETHERSWITCH_CONF_VLAN_MODE) {
819 err = arswitch_set_vlan_mode(sc, conf->vlan_mode);
828 arswitch_getvgroup(device_t dev, etherswitch_vlangroup_t *e)
830 struct arswitch_softc *sc = device_get_softc(dev);
832 return (sc->hal.arswitch_vlan_getvgroup(sc, e));
836 arswitch_setvgroup(device_t dev, etherswitch_vlangroup_t *e)
838 struct arswitch_softc *sc = device_get_softc(dev);
840 return (sc->hal.arswitch_vlan_setvgroup(sc, e));
844 arswitch_readphy(device_t dev, int phy, int reg)
846 struct arswitch_softc *sc = device_get_softc(dev);
848 return (sc->hal.arswitch_phy_read(dev, phy, reg));
852 arswitch_writephy(device_t dev, int phy, int reg, int val)
854 struct arswitch_softc *sc = device_get_softc(dev);
856 return (sc->hal.arswitch_phy_write(dev, phy, reg, val));
859 static device_method_t arswitch_methods[] = {
860 /* Device interface */
861 DEVMETHOD(device_probe, arswitch_probe),
862 DEVMETHOD(device_attach, arswitch_attach),
863 DEVMETHOD(device_detach, arswitch_detach),
866 DEVMETHOD(bus_add_child, device_add_child_ordered),
869 DEVMETHOD(miibus_readreg, arswitch_readphy),
870 DEVMETHOD(miibus_writereg, arswitch_writephy),
871 DEVMETHOD(miibus_statchg, arswitch_statchg),
874 DEVMETHOD(mdio_readreg, arswitch_readphy),
875 DEVMETHOD(mdio_writereg, arswitch_writephy),
877 /* etherswitch interface */
878 DEVMETHOD(etherswitch_lock, arswitch_lock),
879 DEVMETHOD(etherswitch_unlock, arswitch_unlock),
880 DEVMETHOD(etherswitch_getinfo, arswitch_getinfo),
881 DEVMETHOD(etherswitch_readreg, arswitch_readreg),
882 DEVMETHOD(etherswitch_writereg, arswitch_writereg),
883 DEVMETHOD(etherswitch_readphyreg, arswitch_readphy),
884 DEVMETHOD(etherswitch_writephyreg, arswitch_writephy),
885 DEVMETHOD(etherswitch_getport, arswitch_getport),
886 DEVMETHOD(etherswitch_setport, arswitch_setport),
887 DEVMETHOD(etherswitch_getvgroup, arswitch_getvgroup),
888 DEVMETHOD(etherswitch_setvgroup, arswitch_setvgroup),
889 DEVMETHOD(etherswitch_getconf, arswitch_getconf),
890 DEVMETHOD(etherswitch_setconf, arswitch_setconf),
895 DEFINE_CLASS_0(arswitch, arswitch_driver, arswitch_methods,
896 sizeof(struct arswitch_softc));
897 static devclass_t arswitch_devclass;
899 DRIVER_MODULE(arswitch, mdio, arswitch_driver, arswitch_devclass, 0, 0);
900 DRIVER_MODULE(miibus, arswitch, miibus_driver, miibus_devclass, 0, 0);
901 DRIVER_MODULE(mdio, arswitch, mdio_driver, mdio_devclass, 0, 0);
902 DRIVER_MODULE(etherswitch, arswitch, etherswitch_driver, etherswitch_devclass, 0, 0);
903 MODULE_VERSION(arswitch, 1);
904 MODULE_DEPEND(arswitch, miibus, 1, 1, 1); /* XXX which versions? */
905 MODULE_DEPEND(arswitch, etherswitch, 1, 1, 1); /* XXX which versions? */