Lines Matching +full:conf +full:- +full:mdio

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
148 felix_pci_ids, nitems(felix_pci_ids) - 1);
157 sc->dev = dev; in felix_probe()
159 for (id = felix_pci_ids; id->vendor != 0; ++id) { in felix_probe()
160 if (pci_get_device(dev) != id->device || in felix_probe()
161 pci_get_vendor(dev) != id->vendor) in felix_probe()
164 device_set_desc(dev, id->desc); in felix_probe()
179 device_printf(sc->dev, "Port node doesn't have reg property\n"); in felix_parse_port_fdt()
187 sc->ports[port].cpu_port = false; in felix_parse_port_fdt()
189 sc->ports[port].cpu_port = true; in felix_parse_port_fdt()
191 node = ofw_bus_find_child(child, "fixed-link"); in felix_parse_port_fdt()
193 sc->ports[port].fixed_port = false; in felix_parse_port_fdt()
197 sc->ports[port].fixed_port = true; in felix_parse_port_fdt()
200 device_printf(sc->dev, in felix_parse_port_fdt()
201 "Port has fixed-link node without link speed specified\n"); in felix_parse_port_fdt()
219 device_printf(sc->dev, in felix_parse_port_fdt()
225 if (OF_hasprop(node, "full-duplex")) in felix_parse_port_fdt()
231 sc->ports[port].fixed_link_status = status; in felix_parse_port_fdt()
240 snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->dev)); in felix_init_interface()
242 sc->ports[port].ifp = if_alloc(IFT_ETHER); in felix_init_interface()
243 if_setsoftc(sc->ports[port].ifp, sc); in felix_init_interface()
244 if_setflags(sc->ports[port].ifp, IFF_UP | IFF_BROADCAST | IFF_MULTICAST | in felix_init_interface()
246 sc->ports[port].ifname = malloc(strlen(name) + 1, M_FELIX, M_NOWAIT); in felix_init_interface()
247 if (sc->ports[port].ifname == NULL) { in felix_init_interface()
248 if_free(sc->ports[port].ifp); in felix_init_interface()
252 memcpy(sc->ports[port].ifname, name, strlen(name) + 1); in felix_init_interface()
253 if_initname(sc->ports[port].ifp, sc->ports[port].ifname, port); in felix_init_interface()
288 /* Trigger soft reset, bit is self-clearing, with 5s timeout. */ in felix_setup()
296 } while (timeout-- > 0); in felix_setup()
298 device_printf(sc->dev, in felix_setup()
310 } while (timeout-- > 0); in felix_setup()
312 device_printf(sc->dev, in felix_setup()
319 for (i = 0; i < sc->info.es_nports; i++) in felix_setup()
333 old = value = sc->timer_ticks; in felix_timer_rate()
335 if (error != 0 || req->newptr == NULL) in felix_timer_rate()
345 sc->timer_ticks = value; in felix_timer_rate()
346 callout_reset(&sc->tick_callout, sc->timer_ticks, felix_tick, sc); in felix_timer_rate()
362 sc->info.es_nports = 0; in felix_attach()
363 sc->info.es_vlan_caps = ETHERSWITCH_VLAN_DOT1Q; in felix_attach()
364 strlcpy(sc->info.es_name, "Felix TSN Switch", sizeof(sc->info.es_name)); in felix_attach()
367 sc->mdio = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in felix_attach()
369 if (sc->mdio == NULL) { in felix_attach()
370 device_printf(dev, "Failed to allocate MDIO registers.\n"); in felix_attach()
375 sc->regs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in felix_attach()
377 if (sc->regs == NULL) { in felix_attach()
383 mtx_init(&sc->mtx, "felix lock", NULL, MTX_DEF); in felix_attach()
384 callout_init_mtx(&sc->tick_callout, &sc->mtx, 0); in felix_attach()
411 device_printf(sc->dev, in felix_attach()
416 if (sc->ports[port].fixed_port) { in felix_attach()
417 sc->info.es_nports++; in felix_attach()
421 size = OF_getencprop(child, "phy-handle", &node, sizeof(node)); in felix_attach()
423 device_printf(sc->dev, in felix_attach()
432 device_printf(sc->dev, in felix_attach()
438 sc->ports[port].phyaddr = phy_addr; in felix_attach()
439 sc->ports[port].miibus = NULL; in felix_attach()
440 error = mii_attach(dev, &sc->ports[port].miibus, sc->ports[port].ifp, in felix_attach()
446 sc->info.es_nports++; in felix_attach()
453 sc->timer_ticks = hz; /* Default to 1s. */ in felix_attach()
487 mtx_lock(&sc->mtx); in felix_detach()
488 callout_stop(&sc->tick_callout); in felix_detach()
489 mtx_unlock(&sc->mtx); in felix_detach()
490 mtx_destroy(&sc->mtx); in felix_detach()
499 for (i = 0; i < sc->info.es_nports; i++) { in felix_detach()
500 if (sc->ports[i].miibus != NULL) in felix_detach()
501 device_delete_child(dev, sc->ports[i].miibus); in felix_detach()
502 if (sc->ports[i].ifp != NULL) in felix_detach()
503 if_free(sc->ports[i].ifp); in felix_detach()
504 if (sc->ports[i].ifname != NULL) in felix_detach()
505 free(sc->ports[i].ifname, M_FELIX); in felix_detach()
508 if (sc->regs != NULL) in felix_detach()
509 error = bus_release_resource(sc->dev, SYS_RES_MEMORY, in felix_detach()
510 rman_get_rid(sc->regs), sc->regs); in felix_detach()
512 if (sc->mdio != NULL) in felix_detach()
513 error = bus_release_resource(sc->dev, SYS_RES_MEMORY, in felix_detach()
514 rman_get_rid(sc->mdio), sc->mdio); in felix_detach()
525 return (&sc->info); in felix_getinfo()
529 felix_getconf(device_t dev, etherswitch_conf_t *conf) in felix_getconf() argument
536 conf->cmd = ETHERSWITCH_CONF_VLAN_MODE; in felix_getconf()
537 conf->vlan_mode = sc->vlan_mode; in felix_getconf()
555 } while (timeout-- > 0); in felix_init_vlan()
557 device_printf(sc->dev, in felix_init_vlan()
563 for (i = 0; i < sc->info.es_nvlangroups; i++) in felix_init_vlan()
564 sc->vlans[i] = 0; in felix_init_vlan()
572 for (i = 0; i < sc->info.es_nports; i++) { in felix_init_vlan()
584 felix_setconf(device_t dev, etherswitch_conf_t *conf) in felix_setconf() argument
593 if (conf->cmd & ETHERSWITCH_CONF_VLAN_MODE) { in felix_setconf()
594 switch (conf->vlan_mode) { in felix_setconf()
596 sc->vlan_mode = ETHERSWITCH_VLAN_DOT1Q; in felix_setconf()
597 sc->info.es_nvlangroups = FELIX_NUM_VLANS; in felix_setconf()
633 p->es_flags = 0; in felix_get_port_cfg()
635 reg = FELIX_ANA_PORT_RD4(sc, p->es_port, FELIX_ANA_PORT_DROP_CFG); in felix_get_port_cfg()
637 p->es_flags |= ETHERSWITCH_PORT_DROPTAGGED; in felix_get_port_cfg()
640 p->es_flags |= ETHERSWITCH_PORT_DROPUNTAGGED; in felix_get_port_cfg()
642 reg = FELIX_DEVGMII_PORT_RD4(sc, p->es_port, FELIX_DEVGMII_VLAN_CFG); in felix_get_port_cfg()
644 p->es_flags |= ETHERSWITCH_PORT_DOUBLE_TAG; in felix_get_port_cfg()
646 reg = FELIX_REW_PORT_RD4(sc, p->es_port, FELIX_REW_PORT_TAG_CFG); in felix_get_port_cfg()
648 p->es_flags |= ETHERSWITCH_PORT_ADDTAG; in felix_get_port_cfg()
650 reg = FELIX_ANA_PORT_RD4(sc, p->es_port, FELIX_ANA_PORT_VLAN_CFG); in felix_get_port_cfg()
652 p->es_flags |= ETHERSWITCH_PORT_STRIPTAGINGRESS; in felix_get_port_cfg()
654 p->es_pvid = reg & FELIX_ANA_PORT_VLAN_CFG_VID_MASK; in felix_get_port_cfg()
669 if (p->es_port >= sc->info.es_nports || p->es_port < 0) in felix_getport()
674 if (sc->ports[p->es_port].fixed_port) { in felix_getport()
675 ifmr = &p->es_ifmr; in felix_getport()
676 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID; in felix_getport()
677 ifmr->ifm_count = 0; in felix_getport()
678 ifmr->ifm_active = sc->ports[p->es_port].fixed_link_status; in felix_getport()
679 ifmr->ifm_current = ifmr->ifm_active; in felix_getport()
680 ifmr->ifm_mask = 0; in felix_getport()
682 mii = felix_miiforport(sc, p->es_port); in felix_getport()
683 error = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr, in felix_getport()
684 &mii->mii_media, SIOCGIFMEDIA); in felix_getport()
695 reg = FELIX_ANA_PORT_RD4(sc, p->es_port, FELIX_ANA_PORT_DROP_CFG); in felix_set_port_cfg()
696 if (p->es_flags & ETHERSWITCH_PORT_DROPTAGGED) in felix_set_port_cfg()
701 if (p->es_flags & ETHERSWITCH_PORT_DROPUNTAGGED) in felix_set_port_cfg()
706 FELIX_ANA_PORT_WR4(sc, p->es_port, FELIX_ANA_PORT_DROP_CFG, reg); in felix_set_port_cfg()
708 reg = FELIX_REW_PORT_RD4(sc, p->es_port, FELIX_REW_PORT_TAG_CFG); in felix_set_port_cfg()
709 if (p->es_flags & ETHERSWITCH_PORT_ADDTAG) in felix_set_port_cfg()
714 FELIX_REW_PORT_WR4(sc, p->es_port, FELIX_REW_PORT_TAG_CFG, reg); in felix_set_port_cfg()
716 reg = FELIX_ANA_PORT_RD4(sc, p->es_port, FELIX_ANA_PORT_VLAN_CFG); in felix_set_port_cfg()
717 if (p->es_flags & ETHERSWITCH_PORT_STRIPTAGINGRESS) in felix_set_port_cfg()
723 reg |= p->es_pvid & FELIX_ANA_PORT_VLAN_CFG_VID_MASK; in felix_set_port_cfg()
730 if (p->es_pvid != 0) in felix_set_port_cfg()
735 FELIX_ANA_PORT_WR4(sc, p->es_port, FELIX_ANA_PORT_VLAN_CFG, reg); in felix_set_port_cfg()
749 if (p->es_port >= sc->info.es_nports || p->es_port < 0) in felix_setport()
754 if (felix_is_phyport(sc, p->es_port)) { in felix_setport()
755 mii = felix_miiforport(sc, p->es_port); in felix_setport()
756 error = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr, &mii->mii_media, in felix_setport()
770 if (addr_reg > rman_get_size(sc->regs)) in felix_readreg_wrapper()
782 if (addr_reg > rman_get_size(sc->regs)) in felix_writereg_wrapper()
796 return (enetc_mdio_read(sc->mdio, FELIX_MDIO_BASE, phy, reg)); in felix_readphy()
806 return (enetc_mdio_write(sc->mdio, FELIX_MDIO_BASE, phy, reg, data)); in felix_writephy()
815 vid = vg->es_vid & ETHERSWITCH_VID_MASK; in felix_set_dot1q_vlan()
818 if (vg->es_member_ports != vg->es_untagged_ports) in felix_set_dot1q_vlan()
827 FELIX_WR4(sc, FELIX_ANA_VTIDX, sc->vlans[vg->es_vlangroup]); in felix_set_dot1q_vlan()
829 sc->vlans[vg->es_vlangroup] = 0; in felix_set_dot1q_vlan()
834 for (i = 0; i < sc->info.es_nvlangroups; i++) in felix_set_dot1q_vlan()
835 if (i != vg->es_vlangroup && vid == sc->vlans[i]) in felix_set_dot1q_vlan()
839 if (sc->vlans[vg->es_vlangroup] != 0 && in felix_set_dot1q_vlan()
840 sc->vlans[vg->es_vlangroup] != vid) in felix_set_dot1q_vlan()
843 sc->vlans[vg->es_vlangroup] = vid; in felix_set_dot1q_vlan()
846 reg = vg->es_member_ports & FELIX_ANA_VT_PORTMASK_MASK; in felix_set_dot1q_vlan()
876 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) in felix_setvgroup()
891 vid = sc->vlans[vg->es_vlangroup]; in felix_get_dot1q_vlan()
913 vg->es_untagged_ports = vg->es_member_ports = reg; in felix_get_dot1q_vlan()
914 vg->es_fid = 0; in felix_get_dot1q_vlan()
915 vg->es_vid = vid | ETHERSWITCH_VID_VALID; in felix_get_dot1q_vlan()
928 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) in felix_getvgroup()
948 for (port = 0; port < sc->info.es_nports; port++) { in felix_tick()
956 if (sc->timer_ticks != 0) in felix_tick()
957 callout_reset(&sc->tick_callout, sc->timer_ticks, felix_tick, sc); in felix_tick()
987 ifmr->ifm_active = mii->mii_media_active; in felix_ifmedia_sts()
988 ifmr->ifm_status = mii->mii_media_status; in felix_ifmedia_sts()
995 return (!sc->ports[port].fixed_port); in felix_is_phyport()
1005 return (device_get_softc(sc->ports[port].miibus)); in felix_miiforport()