Deleted Added
full compact
rtl8366rb.c (235288) rtl8366rb.c (249752)
1/*-
2 * Copyright (c) 2011-2012 Stefan Bethke.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

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

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/etherswitch/rtl8366/rtl8366rb.c 235288 2012-05-11 20:53:20Z adrian $
26 * $FreeBSD: head/sys/dev/etherswitch/rtl8366/rtl8366rb.c 249752 2013-04-22 05:52:18Z adrian $
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/module.h>
34#include <sys/socket.h>

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

58#include "etherswitch_if.h"
59
60
61struct rtl8366rb_softc {
62 struct mtx sc_mtx; /* serialize access to softc */
63 int smi_acquired; /* serialize access to SMI/I2C bus */
64 struct mtx callout_mtx; /* serialize callout */
65 device_t dev;
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/module.h>
34#include <sys/socket.h>

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

58#include "etherswitch_if.h"
59
60
61struct rtl8366rb_softc {
62 struct mtx sc_mtx; /* serialize access to softc */
63 int smi_acquired; /* serialize access to SMI/I2C bus */
64 struct mtx callout_mtx; /* serialize callout */
65 device_t dev;
66 int vid[RTL8366RB_NUM_VLANS];
66 char *ifname[RTL8366RB_NUM_PHYS];
67 device_t miibus[RTL8366RB_NUM_PHYS];
68 struct ifnet *ifp[RTL8366RB_NUM_PHYS];
69 struct callout callout_tick;
70};
71
72static etherswitch_info_t etherswitch_info = {
67 char *ifname[RTL8366RB_NUM_PHYS];
68 device_t miibus[RTL8366RB_NUM_PHYS];
69 struct ifnet *ifp[RTL8366RB_NUM_PHYS];
70 struct callout callout_tick;
71};
72
73static etherswitch_info_t etherswitch_info = {
73 .es_nports = 6,
74 .es_nvlangroups = 16,
74 .es_nports = RTL8366RB_NUM_PORTS,
75 .es_nvlangroups = RTL8366RB_NUM_VLANS,
75 .es_name = "Realtek RTL8366RB"
76};
77
78#define RTL_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
79#define RTL_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
80#define RTL_LOCK_ASSERT(_sc, _what) mtx_assert(&(_s)c->sc_mtx, (_what))
81#define RTL_TRYLOCK(_sc) mtx_trylock(&(_sc)->sc_mtx)
82

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

545static int
546rtl_getport(device_t dev, etherswitch_port_t *p)
547{
548 struct rtl8366rb_softc *sc;
549 struct ifmedia *ifm;
550 struct mii_data *mii;
551 struct ifmediareq *ifmr = &p->es_ifmr;
552 uint16_t v;
76 .es_name = "Realtek RTL8366RB"
77};
78
79#define RTL_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
80#define RTL_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
81#define RTL_LOCK_ASSERT(_sc, _what) mtx_assert(&(_s)c->sc_mtx, (_what))
82#define RTL_TRYLOCK(_sc) mtx_trylock(&(_sc)->sc_mtx)
83

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

546static int
547rtl_getport(device_t dev, etherswitch_port_t *p)
548{
549 struct rtl8366rb_softc *sc;
550 struct ifmedia *ifm;
551 struct mii_data *mii;
552 struct ifmediareq *ifmr = &p->es_ifmr;
553 uint16_t v;
553 int err;
554 int err, vlangroup;
554
555 if (p->es_port < 0 || p->es_port >= RTL8366RB_NUM_PORTS)
556 return (ENXIO);
555
556 if (p->es_port < 0 || p->es_port >= RTL8366RB_NUM_PORTS)
557 return (ENXIO);
557 p->es_vlangroup = RTL8366RB_PVCR_GET(p->es_port,
558 sc = device_get_softc(dev);
559 vlangroup = RTL8366RB_PVCR_GET(p->es_port,
558 rtl_readreg(dev, RTL8366RB_PVCR_REG(p->es_port)));
560 rtl_readreg(dev, RTL8366RB_PVCR_REG(p->es_port)));
561 p->es_pvid = sc->vid[vlangroup];
559
560 if (p->es_port < RTL8366RB_NUM_PHYS) {
562
563 if (p->es_port < RTL8366RB_NUM_PHYS) {
561 sc = device_get_softc(dev);
562 mii = device_get_softc(sc->miibus[p->es_port]);
563 ifm = &mii->mii_media;
564 err = ifmedia_ioctl(sc->ifp[p->es_port], &p->es_ifr, ifm, SIOCGIFMEDIA);
565 if (err)
566 return (err);
567 } else {
568 /* fill in fixed values for CPU port */
569 ifmr->ifm_count = 0;

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

575 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID;
576 }
577 return (0);
578}
579
580static int
581rtl_setport(device_t dev, etherswitch_port_t *p)
582{
564 mii = device_get_softc(sc->miibus[p->es_port]);
565 ifm = &mii->mii_media;
566 err = ifmedia_ioctl(sc->ifp[p->es_port], &p->es_ifr, ifm, SIOCGIFMEDIA);
567 if (err)
568 return (err);
569 } else {
570 /* fill in fixed values for CPU port */
571 ifmr->ifm_count = 0;

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

577 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID;
578 }
579 return (0);
580}
581
582static int
583rtl_setport(device_t dev, etherswitch_port_t *p)
584{
583 int err;
585 int i, err, vlangroup;
584 struct rtl8366rb_softc *sc;
585 struct ifmedia *ifm;
586 struct mii_data *mii;
587
588 if (p->es_port < 0 || p->es_port >= RTL8366RB_NUM_PHYS)
589 return (ENXIO);
586 struct rtl8366rb_softc *sc;
587 struct ifmedia *ifm;
588 struct mii_data *mii;
589
590 if (p->es_port < 0 || p->es_port >= RTL8366RB_NUM_PHYS)
591 return (ENXIO);
592 sc = device_get_softc(dev);
593 vlangroup = -1;
594 for (i = 0; i < RTL8366RB_NUM_VLANS; i++) {
595 if (sc->vid[i] == p->es_pvid) {
596 vlangroup = i;
597 break;
598 }
599 }
600 if (vlangroup == -1)
601 return (ENXIO);
590 err = smi_rmw(dev, RTL8366RB_PVCR_REG(p->es_port),
591 RTL8366RB_PVCR_VAL(p->es_port, RTL8366RB_PVCR_PORT_MASK),
602 err = smi_rmw(dev, RTL8366RB_PVCR_REG(p->es_port),
603 RTL8366RB_PVCR_VAL(p->es_port, RTL8366RB_PVCR_PORT_MASK),
592 RTL8366RB_PVCR_VAL(p->es_port, p->es_vlangroup), RTL_WAITOK);
604 RTL8366RB_PVCR_VAL(p->es_port, vlangroup), RTL_WAITOK);
593 if (err)
594 return (err);
605 if (err)
606 return (err);
595 sc = device_get_softc(dev);
596 mii = device_get_softc(sc->miibus[p->es_port]);
597 ifm = &mii->mii_media;
598 err = ifmedia_ioctl(sc->ifp[p->es_port], &p->es_ifr, ifm, SIOCSIFMEDIA);
599 return (err);
600}
601
602static int
603rtl_getvgroup(device_t dev, etherswitch_vlangroup_t *vg)

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

613 vg->es_untagged_ports = RTL8366RB_VMCR_UNTAG(vmcr);
614 vg->es_fid = RTL8366RB_VMCR_FID(vmcr);
615 return (0);
616}
617
618static int
619rtl_setvgroup(device_t dev, etherswitch_vlangroup_t *vg)
620{
607 mii = device_get_softc(sc->miibus[p->es_port]);
608 ifm = &mii->mii_media;
609 err = ifmedia_ioctl(sc->ifp[p->es_port], &p->es_ifr, ifm, SIOCSIFMEDIA);
610 return (err);
611}
612
613static int
614rtl_getvgroup(device_t dev, etherswitch_vlangroup_t *vg)

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

624 vg->es_untagged_ports = RTL8366RB_VMCR_UNTAG(vmcr);
625 vg->es_fid = RTL8366RB_VMCR_FID(vmcr);
626 return (0);
627}
628
629static int
630rtl_setvgroup(device_t dev, etherswitch_vlangroup_t *vg)
631{
632 struct rtl8366rb_softc *sc;
621 int g = vg->es_vlangroup;
622
633 int g = vg->es_vlangroup;
634
635 sc = device_get_softc(dev);
636 sc->vid[g] = vg->es_vid;
623 rtl_writereg(dev, RTL8366RB_VMCR(RTL8366RB_VMCR_DOT1Q_REG, g),
624 (vg->es_vid << RTL8366RB_VMCR_DOT1Q_VID_SHIFT) & RTL8366RB_VMCR_DOT1Q_VID_MASK);
625 rtl_writereg(dev, RTL8366RB_VMCR(RTL8366RB_VMCR_MU_REG, g),
626 ((vg->es_member_ports << RTL8366RB_VMCR_MU_MEMBER_SHIFT) & RTL8366RB_VMCR_MU_MEMBER_MASK) |
627 ((vg->es_untagged_ports << RTL8366RB_VMCR_MU_UNTAG_SHIFT) & RTL8366RB_VMCR_MU_UNTAG_MASK));
628 rtl_writereg(dev, RTL8366RB_VMCR(RTL8366RB_VMCR_FID_REG, g),
629 vg->es_fid);
630 return (0);

--- 125 unchanged lines hidden ---
637 rtl_writereg(dev, RTL8366RB_VMCR(RTL8366RB_VMCR_DOT1Q_REG, g),
638 (vg->es_vid << RTL8366RB_VMCR_DOT1Q_VID_SHIFT) & RTL8366RB_VMCR_DOT1Q_VID_MASK);
639 rtl_writereg(dev, RTL8366RB_VMCR(RTL8366RB_VMCR_MU_REG, g),
640 ((vg->es_member_ports << RTL8366RB_VMCR_MU_MEMBER_SHIFT) & RTL8366RB_VMCR_MU_MEMBER_MASK) |
641 ((vg->es_untagged_ports << RTL8366RB_VMCR_MU_UNTAG_SHIFT) & RTL8366RB_VMCR_MU_UNTAG_MASK));
642 rtl_writereg(dev, RTL8366RB_VMCR(RTL8366RB_VMCR_FID_REG, g),
643 vg->es_fid);
644 return (0);

--- 125 unchanged lines hidden ---