static int ip175c_dot1q_vlan_setup(struct ip17x_softc *sc) { struct ip17x_vlan *v; uint32_t data; uint32_t vlans[IP17X_MAX_VLANS]; int i, j; KASSERT(sc->cpuport == 5, ("cpuport != 5 not supported for IP175C")); KASSERT(sc->numports == 6, ("numports != 6 not supported for IP175C")); /* Add and strip VLAN tags. */ data = (sc->addtag & ~(1 << IP175X_CPU_PORT)) << 11; data |= (sc->striptag & ~(1 << IP175X_CPU_PORT)) << 6; if (sc->addtag & (1 << IP175X_CPU_PORT)) data |= (1 << 1); if (sc->striptag & (1 << IP175X_CPU_PORT)) data |= (1 << 0); if (ip17x_writephy(sc->sc_dev, 29, 23, data)) return (-1); /* Set the VID_IDX_SEL to 0. */ if (ip17x_updatephy(sc->sc_dev, 30, 9, 0x70, 0)) return (-1); /* Calculate the port masks. */ memset(vlans, 0, sizeof(vlans)); for (i = 0; i < IP17X_MAX_VLANS; i++) { v = &sc->vlan[i]; if ((v->vlanid & ETHERSWITCH_VID_VALID) == 0) continue; vlans[v->vlanid & ETHERSWITCH_VID_MASK] = v->ports; } for (j = 0, i = 1; i <= IP17X_MAX_VLANS / 2; i++) { data = vlans[j++] & 0x3f; data |= (vlans[j++] & 0x3f) << 8; if (ip17x_writephy(sc->sc_dev, 30, i, data)) return (-1); } /* Port default VLAN ID. */ for (i = 0; i < sc->numports; i++) { if (i == IP175X_CPU_PORT) { if (ip17x_writephy(sc->sc_dev, 29, 30, sc->pvid[i])) return (-1); } else { if (ip17x_writephy(sc->sc_dev, 29, 24 + i, sc->pvid[i])) return (-1); } } return (0); }
/* * Reset the switch to default state. */ static int ip175d_reset(struct ip17x_softc *sc) { /* Reset all the switch settings. */ ip17x_writephy(sc->sc_dev, IP175D_RESET_PHY, IP175D_RESET_REG, 0x175d); DELAY(2); /* Disable the special tagging mode. */ ip17x_updatephy(sc->sc_dev, 21, 22, 0x3, 0x0); /* Set 802.1q protocol type. */ ip17x_writephy(sc->sc_dev, 22, 3, 0x8100); return (0); }
static int ip175c_port_vlan_setup(struct ip17x_softc *sc) { struct ip17x_vlan *v; uint32_t ports[IP175X_NUM_PORTS], reg[IP175X_NUM_PORTS/2]; int i, err, phy; KASSERT(sc->cpuport == 5, ("cpuport != 5 not supported for IP175C")); KASSERT(sc->numports == 6, ("numports != 6 not supported for IP175C")); /* Build the port access masks. */ memset(ports, 0, sizeof(ports)); for (i = 0; i < sc->info.es_nports; i++) { phy = sc->portphy[i]; v = &sc->vlan[i]; ports[phy] = v->ports; } /* Move the cpuport bit to its correct place. */ for (i = 0; i < sc->numports; i++) { if (ports[i] & (1 << sc->cpuport)) { ports[i] |= (1 << 7); ports[i] &= ~(1 << sc->cpuport); } } /* And now build the switch register data. */ memset(reg, 0, sizeof(reg)); for (i = 0; i < (sc->numports / 2); i++) reg[i] = ports[i * 2] << 8 | ports[i * 2 + 1]; /* Update the switch resgisters. */ err = ip17x_writephy(sc->sc_dev, 29, 19, reg[0]); if (err == 0) err = ip17x_writephy(sc->sc_dev, 29, 20, reg[1]); if (err == 0) err = ip17x_updatephy(sc->sc_dev, 29, 21, 0xff00, reg[2]); if (err == 0) err = ip17x_updatephy(sc->sc_dev, 30, 18, 0x00ff, reg[2]); return (err); }
/* * Reset the switch. */ static int ip175c_reset(struct ip17x_softc *sc) { uint32_t data; /* Reset all the switch settings. */ if (ip17x_writephy(sc->sc_dev, IP175C_RESET_PHY, IP175C_RESET_REG, 0x175c)) return (-1); DELAY(2000); /* Force IP175C mode. */ data = ip17x_readphy(sc->sc_dev, IP175C_MODE_PHY, IP175C_MODE_REG); if (data == 0x175a) { if (ip17x_writephy(sc->sc_dev, IP175C_MODE_PHY, IP175C_MODE_REG, 0x175c)) return (-1); } return (0); }
/* * Set the Switch configuration. */ static int ip175d_hw_setup(struct ip17x_softc *sc) { struct ip17x_vlan *v; uint32_t ports[IP17X_MAX_VLANS]; uint32_t addtag[IP17X_MAX_VLANS]; uint32_t striptag[IP17X_MAX_VLANS]; uint32_t vlan_mask; int i, j; vlan_mask = 0; for (i = 0; i < IP17X_MAX_VLANS; i++) { ports[i] = 0; addtag[i] = 0; striptag[i] = 0; v = &sc->vlan[i]; if ((v->vlanid & ETHERSWITCH_VID_VALID) == 0 || sc->vlan_mode == 0) { /* Vlangroup disabled. Reset the filter. */ ip17x_writephy(sc->sc_dev, 22, 14 + i, i + 1); ports[i] = 0x3f; continue; } vlan_mask |= (1 << i); ports[i] = v->ports; /* Setup the filter, write the VLAN id. */ ip17x_writephy(sc->sc_dev, 22, 14 + i, v->vlanid & ETHERSWITCH_VID_MASK); for (j = 0; j < MII_NPHY; j++) { if ((ports[i] & (1 << j)) == 0) continue; if (sc->addtag & (1 << j)) addtag[i] |= (1 << j); if (sc->striptag & (1 << j)) striptag[i] |= (1 << j); } } /* Write the port masks, tag adds and removals. */ for (i = 0; i < IP17X_MAX_VLANS / 2; i++) { ip17x_writephy(sc->sc_dev, 23, i, ports[2 * i] | (ports[2 * i + 1] << 8)); ip17x_writephy(sc->sc_dev, 23, i + 8, addtag[2 * i] | (addtag[2 * i + 1] << 8)); ip17x_writephy(sc->sc_dev, 23, i + 16, striptag[2 * i] | (striptag[2 * i + 1] << 8)); } /* Write the in use vlan mask. */ ip17x_writephy(sc->sc_dev, 22, 10, vlan_mask); /* Write the PVID of each port. */ for (i = 0; i < sc->numports; i++) ip17x_writephy(sc->sc_dev, 22, 4 + i, sc->pvid[i]); return (0); }