2 * Copyright (c) 2013 Luiz Otavio O Souza.
3 * Copyright (c) 2011-2012 Stefan Bethke.
4 * Copyright (c) 2012 Adrian Chadd.
5 * Copyright (C) 2008 Patrick Horn.
6 * Copyright (C) 2008, 2010 Martin Mares.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
35 #include <sys/kernel.h>
37 #include <sys/mutex.h>
38 #include <sys/systm.h>
39 #include <sys/socket.h>
43 #include <dev/mii/mii.h>
45 #include <dev/etherswitch/etherswitch.h>
46 #include <dev/etherswitch/ip17x/ip17x_phy.h>
47 #include <dev/etherswitch/ip17x/ip17x_reg.h>
48 #include <dev/etherswitch/ip17x/ip17x_var.h>
49 #include <dev/etherswitch/ip17x/ip17x_vlans.h>
50 #include <dev/etherswitch/ip17x/ip175d.h>
53 * IP175D specific functions.
57 * Reset the switch to default state.
60 ip175d_reset(struct ip17x_softc *sc)
63 /* Reset all the switch settings. */
64 ip17x_writephy(sc->sc_dev, IP175D_RESET_PHY, IP175D_RESET_REG, 0x175d);
67 /* Disable the special tagging mode. */
68 ip17x_updatephy(sc->sc_dev, 21, 22, 0x3, 0x0);
70 /* Set 802.1q protocol type. */
71 ip17x_writephy(sc->sc_dev, 22, 3, 0x8100);
77 * Set the Switch configuration.
80 ip175d_hw_setup(struct ip17x_softc *sc)
83 uint32_t ports[IP17X_MAX_VLANS];
84 uint32_t addtag[IP17X_MAX_VLANS];
85 uint32_t striptag[IP17X_MAX_VLANS];
90 for (i = 0; i < IP17X_MAX_VLANS; i++) {
97 if ((v->vlanid & ETHERSWITCH_VID_VALID) == 0 ||
99 /* Vlangroup disabled. Reset the filter. */
100 ip17x_writephy(sc->sc_dev, 22, 14 + i, i + 1);
105 vlan_mask |= (1 << i);
108 /* Setup the filter, write the VLAN id. */
109 ip17x_writephy(sc->sc_dev, 22, 14 + i,
110 v->vlanid & ETHERSWITCH_VID_MASK);
112 for (j = 0; j < MII_NPHY; j++) {
113 if ((ports[i] & (1 << j)) == 0)
115 if (sc->addtag & (1 << j))
116 addtag[i] |= (1 << j);
117 if (sc->striptag & (1 << j))
118 striptag[i] |= (1 << j);
122 /* Write the port masks, tag adds and removals. */
123 for (i = 0; i < IP17X_MAX_VLANS / 2; i++) {
124 ip17x_writephy(sc->sc_dev, 23, i,
125 ports[2 * i] | (ports[2 * i + 1] << 8));
126 ip17x_writephy(sc->sc_dev, 23, i + 8,
127 addtag[2 * i] | (addtag[2 * i + 1] << 8));
128 ip17x_writephy(sc->sc_dev, 23, i + 16,
129 striptag[2 * i] | (striptag[2 * i + 1] << 8));
132 /* Write the in use vlan mask. */
133 ip17x_writephy(sc->sc_dev, 22, 10, vlan_mask);
135 /* Write the PVID of each port. */
136 for (i = 0; i < sc->numports; i++)
137 ip17x_writephy(sc->sc_dev, 22, 4 + i, sc->pvid[i]);
143 * Set the switch VLAN mode.
146 ip175d_set_vlan_mode(struct ip17x_softc *sc, uint32_t mode)
150 case ETHERSWITCH_VLAN_DOT1Q:
152 * VLAN classification rules: tag-based VLANs,
153 * use VID to classify, drop packets that cannot
156 ip17x_updatephy(sc->sc_dev, 22, 0, 0x3fff, 0x003f);
157 sc->vlan_mode = mode;
159 case ETHERSWITCH_VLAN_PORT:
160 sc->vlan_mode = mode;
164 * VLAN classification rules: everything off &
167 ip17x_updatephy(sc->sc_dev, 22, 0, 0xbfff, 0x8000);
172 if (sc->vlan_mode != 0) {
174 * Ingress rules: CFI=1 dropped, null VID is untagged, VID=1 passed,
175 * VID=0xfff discarded, admin both tagged and untagged, ingress
178 ip17x_updatephy(sc->sc_dev, 22, 1, 0x0fff, 0x0c3f);
180 /* Egress rules: IGMP processing off, keep VLAN header off. */
181 ip17x_updatephy(sc->sc_dev, 22, 2, 0x0fff, 0x0000);
183 ip17x_updatephy(sc->sc_dev, 22, 1, 0x0fff, 0x043f);
184 ip17x_updatephy(sc->sc_dev, 22, 2, 0x0fff, 0x0020);
188 ip17x_reset_vlans(sc, sc->vlan_mode);
190 /* Update switch configuration. */
197 * Get the switch VLAN mode.
200 ip175d_get_vlan_mode(struct ip17x_softc *sc)
203 return (sc->vlan_mode);
207 ip175d_attach(struct ip17x_softc *sc)
210 sc->hal.ip17x_reset = ip175d_reset;
211 sc->hal.ip17x_hw_setup = ip175d_hw_setup;
212 sc->hal.ip17x_get_vlan_mode = ip175d_get_vlan_mode;
213 sc->hal.ip17x_set_vlan_mode = ip175d_set_vlan_mode;
215 /* Defaults for IP175C. */
216 sc->cpuport = IP175X_CPU_PORT;
217 sc->numports = IP175X_NUM_PORTS;
218 sc->info.es_vlan_caps = ETHERSWITCH_VLAN_DOT1Q;
220 device_printf(sc->sc_dev, "type: IP175D\n");