1 /*-
2 * Copyright (c) 2016 Stanislav Galabov.
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
9 * are met:
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.
15 *
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
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/bus.h>
31 #include <sys/errno.h>
32 #include <sys/kernel.h>
33 #include <sys/lock.h>
34 #include <sys/malloc.h>
35 #include <sys/module.h>
36 #include <sys/mutex.h>
37 #include <sys/socket.h>
38 #include <sys/sockio.h>
39 #include <sys/sysctl.h>
40 #include <sys/systm.h>
41
42 #include <net/if.h>
43 #include <net/if_var.h>
44 #include <net/ethernet.h>
45 #include <net/if_media.h>
46 #include <net/if_types.h>
47
48 #include <machine/bus.h>
49 #include <dev/mii/mii.h>
50 #include <dev/mii/miivar.h>
51 #include <dev/mdio/mdio.h>
52
53 #include <dev/etherswitch/etherswitch.h>
54 #include <dev/etherswitch/mtkswitch/mtkswitchvar.h>
55
56 #include <dev/ofw/ofw_bus_subr.h>
57
58 #include "mdio_if.h"
59 #include "miibus_if.h"
60 #include "etherswitch_if.h"
61
62 #define DEBUG
63
64 #if defined(DEBUG)
65 static SYSCTL_NODE(_debug, OID_AUTO, mtkswitch, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
66 "mtkswitch");
67 #endif
68
69 static inline int mtkswitch_portforphy(int phy);
70 static int mtkswitch_ifmedia_upd(if_t ifp);
71 static void mtkswitch_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr);
72 static void mtkswitch_tick(void *arg);
73
74 static const struct ofw_compat_data compat_data[] = {
75 { "ralink,rt3050-esw", MTK_SWITCH_RT3050 },
76 { "ralink,rt3352-esw", MTK_SWITCH_RT3352 },
77 { "ralink,rt5350-esw", MTK_SWITCH_RT5350 },
78 { "mediatek,mt7620-gsw", MTK_SWITCH_MT7620 },
79 { "mediatek,mt7621-gsw", MTK_SWITCH_MT7621 },
80 { "mediatek,mt7628-esw", MTK_SWITCH_MT7628 },
81
82 /* Sentinel */
83 { NULL, MTK_SWITCH_NONE }
84 };
85
86 static int
mtkswitch_probe(device_t dev)87 mtkswitch_probe(device_t dev)
88 {
89 struct mtkswitch_softc *sc;
90 mtk_switch_type switch_type;
91
92 if (!ofw_bus_status_okay(dev))
93 return (ENXIO);
94
95 switch_type = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
96 if (switch_type == MTK_SWITCH_NONE)
97 return (ENXIO);
98
99 sc = device_get_softc(dev);
100 bzero(sc, sizeof(*sc));
101 sc->sc_switchtype = switch_type;
102
103 device_set_desc(dev, "MTK Switch Driver");
104
105 return (0);
106 }
107
108 static int
mtkswitch_attach_phys(struct mtkswitch_softc * sc)109 mtkswitch_attach_phys(struct mtkswitch_softc *sc)
110 {
111 int phy, err = 0;
112 char name[IFNAMSIZ];
113
114 /* PHYs need an interface, so we generate a dummy one */
115 snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->sc_dev));
116 for (phy = 0; phy < sc->numphys; phy++) {
117 if ((sc->phymap & (1u << phy)) == 0) {
118 sc->ifp[phy] = NULL;
119 sc->ifname[phy] = NULL;
120 sc->miibus[phy] = NULL;
121 continue;
122 }
123 sc->ifp[phy] = if_alloc(IFT_ETHER);
124 sc->ifp[phy]->if_softc = sc;
125 sc->ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST |
126 IFF_DRV_RUNNING | IFF_SIMPLEX;
127 sc->ifname[phy] = malloc(strlen(name) + 1, M_DEVBUF, M_WAITOK);
128 bcopy(name, sc->ifname[phy], strlen(name) + 1);
129 if_initname(sc->ifp[phy], sc->ifname[phy],
130 mtkswitch_portforphy(phy));
131 err = mii_attach(sc->sc_dev, &sc->miibus[phy], sc->ifp[phy],
132 mtkswitch_ifmedia_upd, mtkswitch_ifmedia_sts,
133 BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
134 if (err != 0) {
135 device_printf(sc->sc_dev,
136 "attaching PHY %d failed\n",
137 phy);
138 } else {
139 DPRINTF(sc->sc_dev, "%s attached to pseudo interface "
140 "%s\n", device_get_nameunit(sc->miibus[phy]),
141 sc->ifp[phy]->if_xname);
142 }
143 }
144 return (err);
145 }
146
147 static int
mtkswitch_set_vlan_mode(struct mtkswitch_softc * sc,uint32_t mode)148 mtkswitch_set_vlan_mode(struct mtkswitch_softc *sc, uint32_t mode)
149 {
150
151 /* Check for invalid modes. */
152 if ((mode & sc->info.es_vlan_caps) != mode)
153 return (EINVAL);
154
155 sc->vlan_mode = mode;
156
157 /* Reset VLANs. */
158 sc->hal.mtkswitch_vlan_init_hw(sc);
159
160 return (0);
161 }
162
163 static int
mtkswitch_attach(device_t dev)164 mtkswitch_attach(device_t dev)
165 {
166 struct mtkswitch_softc *sc;
167 int err = 0;
168 int port, rid;
169
170 sc = device_get_softc(dev);
171
172 /* sc->sc_switchtype is already decided in mtkswitch_probe() */
173 sc->numports = MTKSWITCH_MAX_PORTS;
174 sc->numphys = MTKSWITCH_MAX_PHYS;
175 sc->cpuport = MTKSWITCH_CPU_PORT;
176 sc->sc_dev = dev;
177
178 /* Attach switch related functions */
179 if (sc->sc_switchtype == MTK_SWITCH_NONE) {
180 device_printf(dev, "Unknown switch type\n");
181 return (ENXIO);
182 }
183
184 if (sc->sc_switchtype == MTK_SWITCH_MT7620 ||
185 sc->sc_switchtype == MTK_SWITCH_MT7621)
186 mtk_attach_switch_mt7620(sc);
187 else
188 mtk_attach_switch_rt3050(sc);
189
190 /* Allocate resources */
191 rid = 0;
192 sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
193 RF_ACTIVE);
194 if (sc->sc_res == NULL) {
195 device_printf(dev, "could not map memory\n");
196 return (ENXIO);
197 }
198
199 mtx_init(&sc->sc_mtx, "mtkswitch", NULL, MTX_DEF);
200
201 /* Reset the switch */
202 if (sc->hal.mtkswitch_reset(sc)) {
203 DPRINTF(dev, "%s: mtkswitch_reset: failed\n", __func__);
204 return (ENXIO);
205 }
206
207 err = sc->hal.mtkswitch_hw_setup(sc);
208 DPRINTF(dev, "%s: hw_setup: err=%d\n", __func__, err);
209 if (err != 0)
210 return (err);
211
212 err = sc->hal.mtkswitch_hw_global_setup(sc);
213 DPRINTF(dev, "%s: hw_global_setup: err=%d\n", __func__, err);
214 if (err != 0)
215 return (err);
216
217 /* Initialize the switch ports */
218 for (port = 0; port < sc->numports; port++) {
219 sc->hal.mtkswitch_port_init(sc, port);
220 }
221
222 /* Attach the PHYs and complete the bus enumeration */
223 err = mtkswitch_attach_phys(sc);
224 DPRINTF(dev, "%s: attach_phys: err=%d\n", __func__, err);
225 if (err != 0)
226 return (err);
227
228 /* Default to ingress filters off. */
229 err = mtkswitch_set_vlan_mode(sc, ETHERSWITCH_VLAN_DOT1Q);
230 DPRINTF(dev, "%s: set_vlan_mode: err=%d\n", __func__, err);
231 if (err != 0)
232 return (err);
233
234 bus_identify_children(dev);
235 bus_enumerate_hinted_children(dev);
236 bus_attach_children(dev);
237
238 callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
239
240 MTKSWITCH_LOCK(sc);
241 mtkswitch_tick(sc);
242 MTKSWITCH_UNLOCK(sc);
243
244 return (0);
245 }
246
247 static int
mtkswitch_detach(device_t dev)248 mtkswitch_detach(device_t dev)
249 {
250 struct mtkswitch_softc *sc = device_get_softc(dev);
251 int error, phy;
252
253 error = bus_generic_detach(dev);
254 if (error != 0)
255 return (error);
256
257 callout_drain(&sc->callout_tick);
258
259 for (phy = 0; phy < MTKSWITCH_MAX_PHYS; phy++) {
260 if (sc->ifp[phy] != NULL)
261 if_free(sc->ifp[phy]);
262 free(sc->ifname[phy], M_DEVBUF);
263 }
264
265 mtx_destroy(&sc->sc_mtx);
266
267 return (0);
268 }
269
270 /* PHY <-> port mapping is currently 1:1 */
271 static inline int
mtkswitch_portforphy(int phy)272 mtkswitch_portforphy(int phy)
273 {
274
275 return (phy);
276 }
277
278 static inline int
mtkswitch_phyforport(int port)279 mtkswitch_phyforport(int port)
280 {
281
282 return (port);
283 }
284
285 static inline struct mii_data *
mtkswitch_miiforport(struct mtkswitch_softc * sc,int port)286 mtkswitch_miiforport(struct mtkswitch_softc *sc, int port)
287 {
288 int phy = mtkswitch_phyforport(port);
289
290 if (phy < 0 || phy >= MTKSWITCH_MAX_PHYS || sc->miibus[phy] == NULL)
291 return (NULL);
292
293 return (device_get_softc(sc->miibus[phy]));
294 }
295
296 static inline if_t
mtkswitch_ifpforport(struct mtkswitch_softc * sc,int port)297 mtkswitch_ifpforport(struct mtkswitch_softc *sc, int port)
298 {
299 int phy = mtkswitch_phyforport(port);
300
301 if (phy < 0 || phy >= MTKSWITCH_MAX_PHYS)
302 return (NULL);
303
304 return (sc->ifp[phy]);
305 }
306
307 /*
308 * Convert port status to ifmedia.
309 */
310 static void
mtkswitch_update_ifmedia(uint32_t portstatus,u_int * media_status,u_int * media_active)311 mtkswitch_update_ifmedia(uint32_t portstatus, u_int *media_status,
312 u_int *media_active)
313 {
314 *media_active = IFM_ETHER;
315 *media_status = IFM_AVALID;
316
317 if ((portstatus & MTKSWITCH_LINK_UP) != 0)
318 *media_status |= IFM_ACTIVE;
319 else {
320 *media_active |= IFM_NONE;
321 return;
322 }
323
324 switch (portstatus & MTKSWITCH_SPEED_MASK) {
325 case MTKSWITCH_SPEED_10:
326 *media_active |= IFM_10_T;
327 break;
328 case MTKSWITCH_SPEED_100:
329 *media_active |= IFM_100_TX;
330 break;
331 case MTKSWITCH_SPEED_1000:
332 *media_active |= IFM_1000_T;
333 break;
334 }
335
336 if ((portstatus & MTKSWITCH_DUPLEX) != 0)
337 *media_active |= IFM_FDX;
338 else
339 *media_active |= IFM_HDX;
340
341 if ((portstatus & MTKSWITCH_TXFLOW) != 0)
342 *media_active |= IFM_ETH_TXPAUSE;
343 if ((portstatus & MTKSWITCH_RXFLOW) != 0)
344 *media_active |= IFM_ETH_RXPAUSE;
345 }
346
347 static void
mtkswitch_miipollstat(struct mtkswitch_softc * sc)348 mtkswitch_miipollstat(struct mtkswitch_softc *sc)
349 {
350 struct mii_data *mii;
351 struct mii_softc *miisc;
352 uint32_t portstatus;
353 int i, port_flap = 0;
354
355 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED);
356
357 for (i = 0; i < sc->numphys; i++) {
358 if (sc->miibus[i] == NULL)
359 continue;
360 mii = device_get_softc(sc->miibus[i]);
361 portstatus = sc->hal.mtkswitch_get_port_status(sc,
362 mtkswitch_portforphy(i));
363
364 /* If a port has flapped - mark it so we can flush the ATU */
365 if (((mii->mii_media_status & IFM_ACTIVE) == 0 &&
366 (portstatus & MTKSWITCH_LINK_UP) != 0) ||
367 ((mii->mii_media_status & IFM_ACTIVE) != 0 &&
368 (portstatus & MTKSWITCH_LINK_UP) == 0)) {
369 port_flap = 1;
370 }
371
372 mtkswitch_update_ifmedia(portstatus, &mii->mii_media_status,
373 &mii->mii_media_active);
374 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
375 if (IFM_INST(mii->mii_media.ifm_cur->ifm_media) !=
376 miisc->mii_inst)
377 continue;
378 mii_phy_update(miisc, MII_POLLSTAT);
379 }
380 }
381
382 if (port_flap)
383 sc->hal.mtkswitch_atu_flush(sc);
384 }
385
386 static void
mtkswitch_tick(void * arg)387 mtkswitch_tick(void *arg)
388 {
389 struct mtkswitch_softc *sc = arg;
390
391 mtkswitch_miipollstat(sc);
392 callout_reset(&sc->callout_tick, hz, mtkswitch_tick, sc);
393 }
394
395 static void
mtkswitch_lock(device_t dev)396 mtkswitch_lock(device_t dev)
397 {
398 struct mtkswitch_softc *sc = device_get_softc(dev);
399
400 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
401 MTKSWITCH_LOCK(sc);
402 }
403
404 static void
mtkswitch_unlock(device_t dev)405 mtkswitch_unlock(device_t dev)
406 {
407 struct mtkswitch_softc *sc = device_get_softc(dev);
408
409 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED);
410 MTKSWITCH_UNLOCK(sc);
411 }
412
413 static etherswitch_info_t *
mtkswitch_getinfo(device_t dev)414 mtkswitch_getinfo(device_t dev)
415 {
416 struct mtkswitch_softc *sc = device_get_softc(dev);
417
418 return (&sc->info);
419 }
420
421 static inline int
mtkswitch_is_cpuport(struct mtkswitch_softc * sc,int port)422 mtkswitch_is_cpuport(struct mtkswitch_softc *sc, int port)
423 {
424
425 return (sc->cpuport == port);
426 }
427
428 static int
mtkswitch_getport(device_t dev,etherswitch_port_t * p)429 mtkswitch_getport(device_t dev, etherswitch_port_t *p)
430 {
431 struct mtkswitch_softc *sc;
432 struct mii_data *mii;
433 struct ifmediareq *ifmr;
434 int err;
435
436 sc = device_get_softc(dev);
437 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
438 return (ENXIO);
439
440 err = sc->hal.mtkswitch_port_vlan_get(sc, p);
441 if (err != 0)
442 return (err);
443
444 mii = mtkswitch_miiforport(sc, p->es_port);
445 if (mtkswitch_is_cpuport(sc, p->es_port)) {
446 /* fill in fixed values for CPU port */
447 /* XXX is this valid in all cases? */
448 p->es_flags |= ETHERSWITCH_PORT_CPU;
449 ifmr = &p->es_ifmr;
450 ifmr->ifm_count = 0;
451 ifmr->ifm_current = ifmr->ifm_active =
452 IFM_ETHER | IFM_1000_T | IFM_FDX;
453 ifmr->ifm_mask = 0;
454 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID;
455 } else if (mii != NULL) {
456 err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr,
457 &mii->mii_media, SIOCGIFMEDIA);
458 if (err)
459 return (err);
460 } else {
461 ifmr = &p->es_ifmr;
462 ifmr->ifm_count = 0;
463 ifmr->ifm_current = ifmr->ifm_active = IFM_NONE;
464 ifmr->ifm_mask = 0;
465 ifmr->ifm_status = 0;
466 }
467 return (0);
468 }
469
470 static int
mtkswitch_setport(device_t dev,etherswitch_port_t * p)471 mtkswitch_setport(device_t dev, etherswitch_port_t *p)
472 {
473 int err;
474 struct mtkswitch_softc *sc;
475 struct ifmedia *ifm;
476 struct mii_data *mii;
477 if_t ifp;
478
479 sc = device_get_softc(dev);
480 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
481 return (ENXIO);
482
483 /* Port flags. */
484 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) {
485 err = sc->hal.mtkswitch_port_vlan_setup(sc, p);
486 if (err)
487 return (err);
488 }
489
490 /* Do not allow media changes on CPU port. */
491 if (mtkswitch_is_cpuport(sc, p->es_port))
492 return (0);
493
494 mii = mtkswitch_miiforport(sc, p->es_port);
495 if (mii == NULL)
496 return (ENXIO);
497
498 ifp = mtkswitch_ifpforport(sc, p->es_port);
499
500 ifm = &mii->mii_media;
501 return (ifmedia_ioctl(ifp, &p->es_ifr, ifm, SIOCSIFMEDIA));
502 }
503
504 static void
mtkswitch_statchg(device_t dev)505 mtkswitch_statchg(device_t dev)
506 {
507
508 DPRINTF(dev, "%s\n", __func__);
509 }
510
511 static int
mtkswitch_ifmedia_upd(if_t ifp)512 mtkswitch_ifmedia_upd(if_t ifp)
513 {
514 struct mtkswitch_softc *sc = if_getsoftc(ifp);
515 struct mii_data *mii = mtkswitch_miiforport(sc, if_getdunit(ifp));
516
517 if (mii == NULL)
518 return (ENXIO);
519 mii_mediachg(mii);
520 return (0);
521 }
522
523 static void
mtkswitch_ifmedia_sts(if_t ifp,struct ifmediareq * ifmr)524 mtkswitch_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr)
525 {
526 struct mtkswitch_softc *sc = if_getsoftc(ifp);
527 struct mii_data *mii = mtkswitch_miiforport(sc, if_getdunit(ifp));
528
529 DPRINTF(sc->sc_dev, "%s\n", __func__);
530
531 if (mii == NULL)
532 return;
533 mii_pollstat(mii);
534 ifmr->ifm_active = mii->mii_media_active;
535 ifmr->ifm_status = mii->mii_media_status;
536 }
537
538 static int
mtkswitch_getconf(device_t dev,etherswitch_conf_t * conf)539 mtkswitch_getconf(device_t dev, etherswitch_conf_t *conf)
540 {
541 struct mtkswitch_softc *sc;
542
543 sc = device_get_softc(dev);
544
545 /* Return the VLAN mode. */
546 conf->cmd = ETHERSWITCH_CONF_VLAN_MODE;
547 conf->vlan_mode = sc->vlan_mode;
548
549 return (0);
550 }
551
552 static int
mtkswitch_setconf(device_t dev,etherswitch_conf_t * conf)553 mtkswitch_setconf(device_t dev, etherswitch_conf_t *conf)
554 {
555 struct mtkswitch_softc *sc;
556 int err;
557
558 sc = device_get_softc(dev);
559
560 /* Set the VLAN mode. */
561 if (conf->cmd & ETHERSWITCH_CONF_VLAN_MODE) {
562 err = mtkswitch_set_vlan_mode(sc, conf->vlan_mode);
563 if (err != 0)
564 return (err);
565 }
566
567 return (0);
568 }
569
570 static int
mtkswitch_getvgroup(device_t dev,etherswitch_vlangroup_t * e)571 mtkswitch_getvgroup(device_t dev, etherswitch_vlangroup_t *e)
572 {
573 struct mtkswitch_softc *sc = device_get_softc(dev);
574
575 return (sc->hal.mtkswitch_vlan_getvgroup(sc, e));
576 }
577
578 static int
mtkswitch_setvgroup(device_t dev,etherswitch_vlangroup_t * e)579 mtkswitch_setvgroup(device_t dev, etherswitch_vlangroup_t *e)
580 {
581 struct mtkswitch_softc *sc = device_get_softc(dev);
582
583 return (sc->hal.mtkswitch_vlan_setvgroup(sc, e));
584 }
585
586 static int
mtkswitch_readphy(device_t dev,int phy,int reg)587 mtkswitch_readphy(device_t dev, int phy, int reg)
588 {
589 struct mtkswitch_softc *sc = device_get_softc(dev);
590
591 return (sc->hal.mtkswitch_phy_read(dev, phy, reg));
592 }
593
594 static int
mtkswitch_writephy(device_t dev,int phy,int reg,int val)595 mtkswitch_writephy(device_t dev, int phy, int reg, int val)
596 {
597 struct mtkswitch_softc *sc = device_get_softc(dev);
598
599 return (sc->hal.mtkswitch_phy_write(dev, phy, reg, val));
600 }
601
602 static int
mtkswitch_readreg(device_t dev,int addr)603 mtkswitch_readreg(device_t dev, int addr)
604 {
605 struct mtkswitch_softc *sc = device_get_softc(dev);
606
607 return (sc->hal.mtkswitch_reg_read(dev, addr));
608 }
609
610 static int
mtkswitch_writereg(device_t dev,int addr,int value)611 mtkswitch_writereg(device_t dev, int addr, int value)
612 {
613 struct mtkswitch_softc *sc = device_get_softc(dev);
614
615 return (sc->hal.mtkswitch_reg_write(dev, addr, value));
616 }
617
618 static device_method_t mtkswitch_methods[] = {
619 /* Device interface */
620 DEVMETHOD(device_probe, mtkswitch_probe),
621 DEVMETHOD(device_attach, mtkswitch_attach),
622 DEVMETHOD(device_detach, mtkswitch_detach),
623
624 /* bus interface */
625 DEVMETHOD(bus_add_child, device_add_child_ordered),
626
627 /* MII interface */
628 DEVMETHOD(miibus_readreg, mtkswitch_readphy),
629 DEVMETHOD(miibus_writereg, mtkswitch_writephy),
630 DEVMETHOD(miibus_statchg, mtkswitch_statchg),
631
632 /* MDIO interface */
633 DEVMETHOD(mdio_readreg, mtkswitch_readphy),
634 DEVMETHOD(mdio_writereg, mtkswitch_writephy),
635
636 /* ehterswitch interface */
637 DEVMETHOD(etherswitch_lock, mtkswitch_lock),
638 DEVMETHOD(etherswitch_unlock, mtkswitch_unlock),
639 DEVMETHOD(etherswitch_getinfo, mtkswitch_getinfo),
640 DEVMETHOD(etherswitch_readreg, mtkswitch_readreg),
641 DEVMETHOD(etherswitch_writereg, mtkswitch_writereg),
642 DEVMETHOD(etherswitch_readphyreg, mtkswitch_readphy),
643 DEVMETHOD(etherswitch_writephyreg, mtkswitch_writephy),
644 DEVMETHOD(etherswitch_getport, mtkswitch_getport),
645 DEVMETHOD(etherswitch_setport, mtkswitch_setport),
646 DEVMETHOD(etherswitch_getvgroup, mtkswitch_getvgroup),
647 DEVMETHOD(etherswitch_setvgroup, mtkswitch_setvgroup),
648 DEVMETHOD(etherswitch_getconf, mtkswitch_getconf),
649 DEVMETHOD(etherswitch_setconf, mtkswitch_setconf),
650
651 DEVMETHOD_END
652 };
653
654 DEFINE_CLASS_0(mtkswitch, mtkswitch_driver, mtkswitch_methods,
655 sizeof(struct mtkswitch_softc));
656
657 DRIVER_MODULE(mtkswitch, simplebus, mtkswitch_driver, 0, 0);
658 DRIVER_MODULE(miibus, mtkswitch, miibus_driver, 0, 0);
659 DRIVER_MODULE(mdio, mtkswitch, mdio_driver, 0, 0);
660 DRIVER_MODULE(etherswitch, mtkswitch, etherswitch_driver, 0, 0);
661 MODULE_VERSION(mtkswitch, 1);
662 MODULE_DEPEND(mtkswitch, miibus, 1, 1, 1);
663 MODULE_DEPEND(mtkswitch, etherswitch, 1, 1, 1);
664