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_generic_probe(dev);
235 bus_enumerate_hinted_children(dev);
236 err = bus_generic_attach(dev);
237 DPRINTF(dev, "%s: bus_generic_attach: err=%d\n", __func__, err);
238 if (err != 0)
239 return (err);
240
241 callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
242
243 MTKSWITCH_LOCK(sc);
244 mtkswitch_tick(sc);
245 MTKSWITCH_UNLOCK(sc);
246
247 return (0);
248 }
249
250 static int
mtkswitch_detach(device_t dev)251 mtkswitch_detach(device_t dev)
252 {
253 struct mtkswitch_softc *sc = device_get_softc(dev);
254 int phy;
255
256 callout_drain(&sc->callout_tick);
257
258 for (phy = 0; phy < MTKSWITCH_MAX_PHYS; phy++) {
259 if (sc->miibus[phy] != NULL)
260 device_delete_child(dev, sc->miibus[phy]);
261 if (sc->ifp[phy] != NULL)
262 if_free(sc->ifp[phy]);
263 free(sc->ifname[phy], M_DEVBUF);
264 }
265
266 bus_generic_detach(dev);
267 mtx_destroy(&sc->sc_mtx);
268
269 return (0);
270 }
271
272 /* PHY <-> port mapping is currently 1:1 */
273 static inline int
mtkswitch_portforphy(int phy)274 mtkswitch_portforphy(int phy)
275 {
276
277 return (phy);
278 }
279
280 static inline int
mtkswitch_phyforport(int port)281 mtkswitch_phyforport(int port)
282 {
283
284 return (port);
285 }
286
287 static inline struct mii_data *
mtkswitch_miiforport(struct mtkswitch_softc * sc,int port)288 mtkswitch_miiforport(struct mtkswitch_softc *sc, int port)
289 {
290 int phy = mtkswitch_phyforport(port);
291
292 if (phy < 0 || phy >= MTKSWITCH_MAX_PHYS || sc->miibus[phy] == NULL)
293 return (NULL);
294
295 return (device_get_softc(sc->miibus[phy]));
296 }
297
298 static inline if_t
mtkswitch_ifpforport(struct mtkswitch_softc * sc,int port)299 mtkswitch_ifpforport(struct mtkswitch_softc *sc, int port)
300 {
301 int phy = mtkswitch_phyforport(port);
302
303 if (phy < 0 || phy >= MTKSWITCH_MAX_PHYS)
304 return (NULL);
305
306 return (sc->ifp[phy]);
307 }
308
309 /*
310 * Convert port status to ifmedia.
311 */
312 static void
mtkswitch_update_ifmedia(uint32_t portstatus,u_int * media_status,u_int * media_active)313 mtkswitch_update_ifmedia(uint32_t portstatus, u_int *media_status,
314 u_int *media_active)
315 {
316 *media_active = IFM_ETHER;
317 *media_status = IFM_AVALID;
318
319 if ((portstatus & MTKSWITCH_LINK_UP) != 0)
320 *media_status |= IFM_ACTIVE;
321 else {
322 *media_active |= IFM_NONE;
323 return;
324 }
325
326 switch (portstatus & MTKSWITCH_SPEED_MASK) {
327 case MTKSWITCH_SPEED_10:
328 *media_active |= IFM_10_T;
329 break;
330 case MTKSWITCH_SPEED_100:
331 *media_active |= IFM_100_TX;
332 break;
333 case MTKSWITCH_SPEED_1000:
334 *media_active |= IFM_1000_T;
335 break;
336 }
337
338 if ((portstatus & MTKSWITCH_DUPLEX) != 0)
339 *media_active |= IFM_FDX;
340 else
341 *media_active |= IFM_HDX;
342
343 if ((portstatus & MTKSWITCH_TXFLOW) != 0)
344 *media_active |= IFM_ETH_TXPAUSE;
345 if ((portstatus & MTKSWITCH_RXFLOW) != 0)
346 *media_active |= IFM_ETH_RXPAUSE;
347 }
348
349 static void
mtkswitch_miipollstat(struct mtkswitch_softc * sc)350 mtkswitch_miipollstat(struct mtkswitch_softc *sc)
351 {
352 struct mii_data *mii;
353 struct mii_softc *miisc;
354 uint32_t portstatus;
355 int i, port_flap = 0;
356
357 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED);
358
359 for (i = 0; i < sc->numphys; i++) {
360 if (sc->miibus[i] == NULL)
361 continue;
362 mii = device_get_softc(sc->miibus[i]);
363 portstatus = sc->hal.mtkswitch_get_port_status(sc,
364 mtkswitch_portforphy(i));
365
366 /* If a port has flapped - mark it so we can flush the ATU */
367 if (((mii->mii_media_status & IFM_ACTIVE) == 0 &&
368 (portstatus & MTKSWITCH_LINK_UP) != 0) ||
369 ((mii->mii_media_status & IFM_ACTIVE) != 0 &&
370 (portstatus & MTKSWITCH_LINK_UP) == 0)) {
371 port_flap = 1;
372 }
373
374 mtkswitch_update_ifmedia(portstatus, &mii->mii_media_status,
375 &mii->mii_media_active);
376 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
377 if (IFM_INST(mii->mii_media.ifm_cur->ifm_media) !=
378 miisc->mii_inst)
379 continue;
380 mii_phy_update(miisc, MII_POLLSTAT);
381 }
382 }
383
384 if (port_flap)
385 sc->hal.mtkswitch_atu_flush(sc);
386 }
387
388 static void
mtkswitch_tick(void * arg)389 mtkswitch_tick(void *arg)
390 {
391 struct mtkswitch_softc *sc = arg;
392
393 mtkswitch_miipollstat(sc);
394 callout_reset(&sc->callout_tick, hz, mtkswitch_tick, sc);
395 }
396
397 static void
mtkswitch_lock(device_t dev)398 mtkswitch_lock(device_t dev)
399 {
400 struct mtkswitch_softc *sc = device_get_softc(dev);
401
402 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
403 MTKSWITCH_LOCK(sc);
404 }
405
406 static void
mtkswitch_unlock(device_t dev)407 mtkswitch_unlock(device_t dev)
408 {
409 struct mtkswitch_softc *sc = device_get_softc(dev);
410
411 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED);
412 MTKSWITCH_UNLOCK(sc);
413 }
414
415 static etherswitch_info_t *
mtkswitch_getinfo(device_t dev)416 mtkswitch_getinfo(device_t dev)
417 {
418 struct mtkswitch_softc *sc = device_get_softc(dev);
419
420 return (&sc->info);
421 }
422
423 static inline int
mtkswitch_is_cpuport(struct mtkswitch_softc * sc,int port)424 mtkswitch_is_cpuport(struct mtkswitch_softc *sc, int port)
425 {
426
427 return (sc->cpuport == port);
428 }
429
430 static int
mtkswitch_getport(device_t dev,etherswitch_port_t * p)431 mtkswitch_getport(device_t dev, etherswitch_port_t *p)
432 {
433 struct mtkswitch_softc *sc;
434 struct mii_data *mii;
435 struct ifmediareq *ifmr;
436 int err;
437
438 sc = device_get_softc(dev);
439 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
440 return (ENXIO);
441
442 err = sc->hal.mtkswitch_port_vlan_get(sc, p);
443 if (err != 0)
444 return (err);
445
446 mii = mtkswitch_miiforport(sc, p->es_port);
447 if (mtkswitch_is_cpuport(sc, p->es_port)) {
448 /* fill in fixed values for CPU port */
449 /* XXX is this valid in all cases? */
450 p->es_flags |= ETHERSWITCH_PORT_CPU;
451 ifmr = &p->es_ifmr;
452 ifmr->ifm_count = 0;
453 ifmr->ifm_current = ifmr->ifm_active =
454 IFM_ETHER | IFM_1000_T | IFM_FDX;
455 ifmr->ifm_mask = 0;
456 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID;
457 } else if (mii != NULL) {
458 err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr,
459 &mii->mii_media, SIOCGIFMEDIA);
460 if (err)
461 return (err);
462 } else {
463 ifmr = &p->es_ifmr;
464 ifmr->ifm_count = 0;
465 ifmr->ifm_current = ifmr->ifm_active = IFM_NONE;
466 ifmr->ifm_mask = 0;
467 ifmr->ifm_status = 0;
468 }
469 return (0);
470 }
471
472 static int
mtkswitch_setport(device_t dev,etherswitch_port_t * p)473 mtkswitch_setport(device_t dev, etherswitch_port_t *p)
474 {
475 int err;
476 struct mtkswitch_softc *sc;
477 struct ifmedia *ifm;
478 struct mii_data *mii;
479 if_t ifp;
480
481 sc = device_get_softc(dev);
482 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
483 return (ENXIO);
484
485 /* Port flags. */
486 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) {
487 err = sc->hal.mtkswitch_port_vlan_setup(sc, p);
488 if (err)
489 return (err);
490 }
491
492 /* Do not allow media changes on CPU port. */
493 if (mtkswitch_is_cpuport(sc, p->es_port))
494 return (0);
495
496 mii = mtkswitch_miiforport(sc, p->es_port);
497 if (mii == NULL)
498 return (ENXIO);
499
500 ifp = mtkswitch_ifpforport(sc, p->es_port);
501
502 ifm = &mii->mii_media;
503 return (ifmedia_ioctl(ifp, &p->es_ifr, ifm, SIOCSIFMEDIA));
504 }
505
506 static void
mtkswitch_statchg(device_t dev)507 mtkswitch_statchg(device_t dev)
508 {
509
510 DPRINTF(dev, "%s\n", __func__);
511 }
512
513 static int
mtkswitch_ifmedia_upd(if_t ifp)514 mtkswitch_ifmedia_upd(if_t ifp)
515 {
516 struct mtkswitch_softc *sc = if_getsoftc(ifp);
517 struct mii_data *mii = mtkswitch_miiforport(sc, if_getdunit(ifp));
518
519 if (mii == NULL)
520 return (ENXIO);
521 mii_mediachg(mii);
522 return (0);
523 }
524
525 static void
mtkswitch_ifmedia_sts(if_t ifp,struct ifmediareq * ifmr)526 mtkswitch_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr)
527 {
528 struct mtkswitch_softc *sc = if_getsoftc(ifp);
529 struct mii_data *mii = mtkswitch_miiforport(sc, if_getdunit(ifp));
530
531 DPRINTF(sc->sc_dev, "%s\n", __func__);
532
533 if (mii == NULL)
534 return;
535 mii_pollstat(mii);
536 ifmr->ifm_active = mii->mii_media_active;
537 ifmr->ifm_status = mii->mii_media_status;
538 }
539
540 static int
mtkswitch_getconf(device_t dev,etherswitch_conf_t * conf)541 mtkswitch_getconf(device_t dev, etherswitch_conf_t *conf)
542 {
543 struct mtkswitch_softc *sc;
544
545 sc = device_get_softc(dev);
546
547 /* Return the VLAN mode. */
548 conf->cmd = ETHERSWITCH_CONF_VLAN_MODE;
549 conf->vlan_mode = sc->vlan_mode;
550
551 return (0);
552 }
553
554 static int
mtkswitch_setconf(device_t dev,etherswitch_conf_t * conf)555 mtkswitch_setconf(device_t dev, etherswitch_conf_t *conf)
556 {
557 struct mtkswitch_softc *sc;
558 int err;
559
560 sc = device_get_softc(dev);
561
562 /* Set the VLAN mode. */
563 if (conf->cmd & ETHERSWITCH_CONF_VLAN_MODE) {
564 err = mtkswitch_set_vlan_mode(sc, conf->vlan_mode);
565 if (err != 0)
566 return (err);
567 }
568
569 return (0);
570 }
571
572 static int
mtkswitch_getvgroup(device_t dev,etherswitch_vlangroup_t * e)573 mtkswitch_getvgroup(device_t dev, etherswitch_vlangroup_t *e)
574 {
575 struct mtkswitch_softc *sc = device_get_softc(dev);
576
577 return (sc->hal.mtkswitch_vlan_getvgroup(sc, e));
578 }
579
580 static int
mtkswitch_setvgroup(device_t dev,etherswitch_vlangroup_t * e)581 mtkswitch_setvgroup(device_t dev, etherswitch_vlangroup_t *e)
582 {
583 struct mtkswitch_softc *sc = device_get_softc(dev);
584
585 return (sc->hal.mtkswitch_vlan_setvgroup(sc, e));
586 }
587
588 static int
mtkswitch_readphy(device_t dev,int phy,int reg)589 mtkswitch_readphy(device_t dev, int phy, int reg)
590 {
591 struct mtkswitch_softc *sc = device_get_softc(dev);
592
593 return (sc->hal.mtkswitch_phy_read(dev, phy, reg));
594 }
595
596 static int
mtkswitch_writephy(device_t dev,int phy,int reg,int val)597 mtkswitch_writephy(device_t dev, int phy, int reg, int val)
598 {
599 struct mtkswitch_softc *sc = device_get_softc(dev);
600
601 return (sc->hal.mtkswitch_phy_write(dev, phy, reg, val));
602 }
603
604 static int
mtkswitch_readreg(device_t dev,int addr)605 mtkswitch_readreg(device_t dev, int addr)
606 {
607 struct mtkswitch_softc *sc = device_get_softc(dev);
608
609 return (sc->hal.mtkswitch_reg_read(dev, addr));
610 }
611
612 static int
mtkswitch_writereg(device_t dev,int addr,int value)613 mtkswitch_writereg(device_t dev, int addr, int value)
614 {
615 struct mtkswitch_softc *sc = device_get_softc(dev);
616
617 return (sc->hal.mtkswitch_reg_write(dev, addr, value));
618 }
619
620 static device_method_t mtkswitch_methods[] = {
621 /* Device interface */
622 DEVMETHOD(device_probe, mtkswitch_probe),
623 DEVMETHOD(device_attach, mtkswitch_attach),
624 DEVMETHOD(device_detach, mtkswitch_detach),
625
626 /* bus interface */
627 DEVMETHOD(bus_add_child, device_add_child_ordered),
628
629 /* MII interface */
630 DEVMETHOD(miibus_readreg, mtkswitch_readphy),
631 DEVMETHOD(miibus_writereg, mtkswitch_writephy),
632 DEVMETHOD(miibus_statchg, mtkswitch_statchg),
633
634 /* MDIO interface */
635 DEVMETHOD(mdio_readreg, mtkswitch_readphy),
636 DEVMETHOD(mdio_writereg, mtkswitch_writephy),
637
638 /* ehterswitch interface */
639 DEVMETHOD(etherswitch_lock, mtkswitch_lock),
640 DEVMETHOD(etherswitch_unlock, mtkswitch_unlock),
641 DEVMETHOD(etherswitch_getinfo, mtkswitch_getinfo),
642 DEVMETHOD(etherswitch_readreg, mtkswitch_readreg),
643 DEVMETHOD(etherswitch_writereg, mtkswitch_writereg),
644 DEVMETHOD(etherswitch_readphyreg, mtkswitch_readphy),
645 DEVMETHOD(etherswitch_writephyreg, mtkswitch_writephy),
646 DEVMETHOD(etherswitch_getport, mtkswitch_getport),
647 DEVMETHOD(etherswitch_setport, mtkswitch_setport),
648 DEVMETHOD(etherswitch_getvgroup, mtkswitch_getvgroup),
649 DEVMETHOD(etherswitch_setvgroup, mtkswitch_setvgroup),
650 DEVMETHOD(etherswitch_getconf, mtkswitch_getconf),
651 DEVMETHOD(etherswitch_setconf, mtkswitch_setconf),
652
653 DEVMETHOD_END
654 };
655
656 DEFINE_CLASS_0(mtkswitch, mtkswitch_driver, mtkswitch_methods,
657 sizeof(struct mtkswitch_softc));
658
659 DRIVER_MODULE(mtkswitch, simplebus, mtkswitch_driver, 0, 0);
660 DRIVER_MODULE(miibus, mtkswitch, miibus_driver, 0, 0);
661 DRIVER_MODULE(mdio, mtkswitch, mdio_driver, 0, 0);
662 DRIVER_MODULE(etherswitch, mtkswitch, etherswitch_driver, 0, 0);
663 MODULE_VERSION(mtkswitch, 1);
664 MODULE_DEPEND(mtkswitch, miibus, 1, 1, 1);
665 MODULE_DEPEND(mtkswitch, etherswitch, 1, 1, 1);
666