2 * Copyright (c) 2003-2012 Broadcom Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
32 #include <sys/systm.h>
34 #include <mips/nlm/hal/mips-extns.h>
35 #include <mips/nlm/hal/haldefs.h>
36 #include <mips/nlm/hal/iomap.h>
37 #include <mips/nlm/hal/sys.h>
38 #include <mips/nlm/hal/nae.h>
39 #include <mips/nlm/hal/mdio.h>
40 #include <mips/nlm/hal/sgmii.h>
43 nlm_configure_sgmii_interface(uint64_t nae_base, int block, int port,
44 int mtu, int loopback)
46 uint32_t data1, data2;
48 /* Apply a soft reset */
49 data1 = (0x1 << 31); /* soft reset */
52 data1 |= (0x01 << 2); /* Rx enable */
53 data1 |= 0x01; /* Tx enable */
54 nlm_write_nae_reg(nae_base, NAE_REG(block, port, MAC_CONF1), data1);
56 data2 = (0x7 << 12) | /* pre-amble length=7 */
57 (0x2 << 8) | /* byteMode */
59 nlm_write_nae_reg(nae_base, NAE_REG(block, port, MAC_CONF2), data2);
61 /* Remove a soft reset */
62 data1 &= ~(0x01 << 31);
63 nlm_write_nae_reg(nae_base, NAE_REG(block, port, MAC_CONF1), data1);
65 /* setup sgmii max frame length */
66 nlm_write_nae_reg(nae_base, SGMII_MAX_FRAME(block, port), mtu);
70 nlm_sgmii_pcs_init(uint64_t nae_base, uint32_t cplx_mask)
72 xlp_nae_config_lane_gmac(nae_base, cplx_mask);
76 nlm_nae_setup_mac(uint64_t nae_base, int nblock, int iface, int reset,
77 int rx_en, int tx_en, int speed, int duplex)
79 uint32_t mac_cfg1, mac_cfg2, netwk_inf;
81 mac_cfg1 = nlm_read_nae_reg(nae_base,
82 SGMII_MAC_CONF1(nblock,iface));
83 mac_cfg2 = nlm_read_nae_reg(nae_base,
84 SGMII_MAC_CONF2(nblock,iface));
85 netwk_inf = nlm_read_nae_reg(nae_base,
86 SGMII_NET_IFACE_CTRL(nblock, iface));
88 mac_cfg1 &= ~(0x1 << 31); /* remove reset */
89 mac_cfg1 &= ~(0x1 << 2); /* remove rx */
90 mac_cfg1 &= ~(0x1); /* remove tx */
91 mac_cfg2 &= ~(0x3 << 8); /* remove interface mode bits */
92 mac_cfg2 &= ~(0x1); /* remove duplex */
93 netwk_inf &= ~(0x1 << 2); /* remove tx */
94 netwk_inf &= ~(0x3); /* remove speed */
97 case NLM_SGMII_SPEED_10:
98 netwk_inf |= 0x0; /* 2.5 Mhz clock for 10 Mbps */
99 mac_cfg2 |= (0x1 << 8); /* enable 10/100 Mbps */
101 case NLM_SGMII_SPEED_100:
102 netwk_inf |= 0x1; /* 25 Mhz clock for 100 Mbps */
103 mac_cfg2 |= (0x1 << 8); /* enable 10/100 Mbps */
105 default: /* make it as 1G */
106 netwk_inf |= 0x2; /* 125 Mhz clock for 1G */
107 mac_cfg2 |= (0x2 << 8); /* enable 1G */
112 mac_cfg1 |= (0x1 << 31); /* set reset */
115 mac_cfg1 |= (0x1 << 2); /* set rx */
117 nlm_write_nae_reg(nae_base,
118 SGMII_NET_IFACE_CTRL(nblock, iface),
122 mac_cfg1 |= 0x1; /* set tx */
123 netwk_inf |= (0x1 << 2); /* set tx */
127 case NLM_SGMII_DUPLEX_HALF:
128 /* duplexity is already set to half duplex */
131 mac_cfg2 |= 0x1; /* set full duplex */
134 nlm_write_nae_reg(nae_base, SGMII_MAC_CONF1(nblock, iface), mac_cfg1);
135 nlm_write_nae_reg(nae_base, SGMII_MAC_CONF2(nblock, iface), mac_cfg2);
136 nlm_write_nae_reg(nae_base, SGMII_NET_IFACE_CTRL(nblock, iface),
141 nlm_nae_setup_rx_mode_sgmii(uint64_t base, int nblock, int iface, int port_type,
142 int broadcast_en, int multicast_en, int pause_en, int promisc_en)
146 /* bit[17] of vlan_typefilter - allows packet matching in MAC.
147 * When DA filtering is disabled, this bit and bit[16] should
149 * bit[16] of vlan_typefilter - Allows hash matching to be used
150 * for DA filtering. When DA filtering is disabled, this bit and
151 * bit[17] should be zero.
152 * Both bits have to be set only if you want to turn on both
155 if (promisc_en == 1) {
156 val = nlm_read_nae_reg(base,
157 SGMII_NETIOR_VLANTYPE_FILTER(nblock, iface));
158 val &= (~(0x3 << 16));
159 nlm_write_nae_reg(base,
160 SGMII_NETIOR_VLANTYPE_FILTER(nblock, iface), val);
162 val = nlm_read_nae_reg(base,
163 SGMII_NETIOR_VLANTYPE_FILTER(nblock, iface));
165 nlm_write_nae_reg(base,
166 SGMII_NETIOR_VLANTYPE_FILTER(nblock, iface), val);
169 val = ((broadcast_en & 0x1) << 10) |
170 ((pause_en & 0x1) << 9) |
171 ((multicast_en & 0x1) << 8) |
172 ((promisc_en & 0x1) << 7) | /* unicast_enable - enables promisc mode */
173 1; /* MAC address is always valid */
175 nlm_write_nae_reg(base, SGMII_MAC_FILTER_CONFIG(nblock, iface), val);
180 nlm_nae_setup_mac_addr_sgmii(uint64_t base, int nblock, int iface,
181 int port_type, uint8_t *mac_addr)
183 nlm_write_nae_reg(base,
184 SGMII_MAC_ADDR0_LO(nblock, iface),
185 (mac_addr[5] << 24) |
186 (mac_addr[4] << 16) |
190 nlm_write_nae_reg(base,
191 SGMII_MAC_ADDR0_HI(nblock, iface),
192 (mac_addr[1] << 24) |
193 (mac_addr[0] << 16));
195 nlm_write_nae_reg(base,
196 SGMII_MAC_ADDR_MASK0_LO(nblock, iface),
198 nlm_write_nae_reg(base,
199 SGMII_MAC_ADDR_MASK0_HI(nblock, iface),
202 nlm_nae_setup_rx_mode_sgmii(base, nblock, iface,
204 1, /* broadcast enabled */
205 1, /* multicast enabled */
206 0, /* do not accept pause frames */
207 0 /* promisc mode disabled */