1e388de98SAdrian Chadd /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3e388de98SAdrian Chadd *
4e388de98SAdrian Chadd * Copyright (c) 2022 Adrian Chadd <adrian@FreeBSD.org>.
5e388de98SAdrian Chadd *
6e388de98SAdrian Chadd * Redistribution and use in source and binary forms, with or without
7e388de98SAdrian Chadd * modification, are permitted provided that the following conditions
8e388de98SAdrian Chadd * are met:
9e388de98SAdrian Chadd * 1. Redistributions of source code must retain the above copyright
10e388de98SAdrian Chadd * notice, this list of conditions and the following disclaimer.
11e388de98SAdrian Chadd * 2. Redistributions in binary form must reproduce the above copyright
12e388de98SAdrian Chadd * notice, this list of conditions and the following disclaimer in the
13e388de98SAdrian Chadd * documentation and/or other materials provided with the distribution.
14e388de98SAdrian Chadd *
15e388de98SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16e388de98SAdrian Chadd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17e388de98SAdrian Chadd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18e388de98SAdrian Chadd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19e388de98SAdrian Chadd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20e388de98SAdrian Chadd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21e388de98SAdrian Chadd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22e388de98SAdrian Chadd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23e388de98SAdrian Chadd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24e388de98SAdrian Chadd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25e388de98SAdrian Chadd * SUCH DAMAGE.
26e388de98SAdrian Chadd */
27e388de98SAdrian Chadd
28e388de98SAdrian Chadd #include <sys/param.h>
29e388de98SAdrian Chadd #include <sys/bus.h>
30e388de98SAdrian Chadd #include <sys/errno.h>
31e388de98SAdrian Chadd #include <sys/kernel.h>
32e388de98SAdrian Chadd #include <sys/malloc.h>
33e388de98SAdrian Chadd #include <sys/module.h>
34e388de98SAdrian Chadd #include <sys/socket.h>
35e388de98SAdrian Chadd #include <sys/sockio.h>
36e388de98SAdrian Chadd #include <sys/sysctl.h>
37e388de98SAdrian Chadd #include <sys/systm.h>
38e388de98SAdrian Chadd
39e388de98SAdrian Chadd #include <net/if.h>
40e388de98SAdrian Chadd #include <net/if_var.h>
41e388de98SAdrian Chadd #include <net/if_arp.h>
42e388de98SAdrian Chadd #include <net/ethernet.h>
43e388de98SAdrian Chadd #include <net/if_dl.h>
44e388de98SAdrian Chadd #include <net/if_media.h>
45e388de98SAdrian Chadd #include <net/if_types.h>
46e388de98SAdrian Chadd
47e388de98SAdrian Chadd #include <machine/bus.h>
48e388de98SAdrian Chadd #include <dev/iicbus/iic.h>
49e388de98SAdrian Chadd #include <dev/iicbus/iiconf.h>
50e388de98SAdrian Chadd #include <dev/iicbus/iicbus.h>
51e388de98SAdrian Chadd #include <dev/mii/mii.h>
52e388de98SAdrian Chadd #include <dev/mii/miivar.h>
53e388de98SAdrian Chadd #include <dev/mdio/mdio.h>
54be82b3a0SEmmanuel Vadot #include <dev/clk/clk.h>
55*1f469a9fSEmmanuel Vadot #include <dev/hwreset/hwreset.h>
56e388de98SAdrian Chadd
57e388de98SAdrian Chadd #include <dev/fdt/fdt_common.h>
58e388de98SAdrian Chadd #include <dev/ofw/ofw_bus.h>
59e388de98SAdrian Chadd #include <dev/ofw/ofw_bus_subr.h>
60e388de98SAdrian Chadd
61e388de98SAdrian Chadd #include <dev/etherswitch/etherswitch.h>
62e388de98SAdrian Chadd
63e388de98SAdrian Chadd #include <dev/etherswitch/ar40xx/ar40xx_var.h>
64e388de98SAdrian Chadd #include <dev/etherswitch/ar40xx/ar40xx_reg.h>
65e388de98SAdrian Chadd #include <dev/etherswitch/ar40xx/ar40xx_hw.h>
66e388de98SAdrian Chadd #include <dev/etherswitch/ar40xx/ar40xx_debug.h>
67e388de98SAdrian Chadd
68e388de98SAdrian Chadd /*
69e388de98SAdrian Chadd * XXX these are here for now; move the code using these
70e388de98SAdrian Chadd * into main.c once this is all done!
71e388de98SAdrian Chadd */
72e388de98SAdrian Chadd #include <dev/etherswitch/ar40xx/ar40xx_hw_vtu.h>
73e388de98SAdrian Chadd #include <dev/etherswitch/ar40xx/ar40xx_hw_port.h>
74e388de98SAdrian Chadd #include <dev/etherswitch/ar40xx/ar40xx_hw_mirror.h>
75e388de98SAdrian Chadd
76e388de98SAdrian Chadd #include "mdio_if.h"
77e388de98SAdrian Chadd #include "miibus_if.h"
78e388de98SAdrian Chadd #include "etherswitch_if.h"
79e388de98SAdrian Chadd
80e388de98SAdrian Chadd /*
81e388de98SAdrian Chadd * Reset the ESS switch. This also resets the ESS ethernet
82e388de98SAdrian Chadd * and PSGMII block.
83e388de98SAdrian Chadd */
84e388de98SAdrian Chadd int
ar40xx_hw_ess_reset(struct ar40xx_softc * sc)85e388de98SAdrian Chadd ar40xx_hw_ess_reset(struct ar40xx_softc *sc)
86e388de98SAdrian Chadd {
87e388de98SAdrian Chadd int ret;
88e388de98SAdrian Chadd
89e388de98SAdrian Chadd AR40XX_DPRINTF(sc, AR40XX_DBG_HW_RESET, "%s: called\n", __func__);
90e388de98SAdrian Chadd
91e388de98SAdrian Chadd ret = hwreset_assert(sc->sc_ess_rst);
92e388de98SAdrian Chadd if (ret != 0) {
93e388de98SAdrian Chadd device_printf(sc->sc_dev, "ERROR: failed to assert reset\n");
94e388de98SAdrian Chadd return ret;
95e388de98SAdrian Chadd }
96e388de98SAdrian Chadd DELAY(10*1000);
97e388de98SAdrian Chadd
98e388de98SAdrian Chadd ret = hwreset_deassert(sc->sc_ess_rst);
99e388de98SAdrian Chadd if (ret != 0) {
100e388de98SAdrian Chadd device_printf(sc->sc_dev,
101e388de98SAdrian Chadd "ERROR: failed to deassert reset\n");
102e388de98SAdrian Chadd return ret;
103e388de98SAdrian Chadd }
104e388de98SAdrian Chadd
105e388de98SAdrian Chadd DELAY(10*1000);
106e388de98SAdrian Chadd
107e388de98SAdrian Chadd return (0);
108e388de98SAdrian Chadd }
109e388de98SAdrian Chadd
110e388de98SAdrian Chadd int
ar40xx_hw_init_globals(struct ar40xx_softc * sc)111e388de98SAdrian Chadd ar40xx_hw_init_globals(struct ar40xx_softc *sc)
112e388de98SAdrian Chadd {
113e388de98SAdrian Chadd uint32_t reg;
114e388de98SAdrian Chadd
115e388de98SAdrian Chadd AR40XX_DPRINTF(sc, AR40XX_DBG_HW_INIT, "%s: called\n", __func__);
116e388de98SAdrian Chadd
117e388de98SAdrian Chadd /* enable CPU port and disable mirror port */
118e388de98SAdrian Chadd reg = AR40XX_FWD_CTRL0_CPU_PORT_EN
119e388de98SAdrian Chadd | AR40XX_FWD_CTRL0_MIRROR_PORT;
120e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_FWD_CTRL0, reg);
121e388de98SAdrian Chadd
122e388de98SAdrian Chadd /* forward multicast and broadcast frames to CPU */
123e388de98SAdrian Chadd reg = (AR40XX_PORTS_ALL << AR40XX_FWD_CTRL1_UC_FLOOD_S)
124e388de98SAdrian Chadd | (AR40XX_PORTS_ALL << AR40XX_FWD_CTRL1_MC_FLOOD_S)
125e388de98SAdrian Chadd | (AR40XX_PORTS_ALL << AR40XX_FWD_CTRL1_BC_FLOOD_S);
126e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_FWD_CTRL1, reg);
127e388de98SAdrian Chadd
128e388de98SAdrian Chadd /* enable jumbo frames */
129e388de98SAdrian Chadd reg = AR40XX_REG_READ(sc, AR40XX_REG_MAX_FRAME_SIZE);
130e388de98SAdrian Chadd reg &= ~AR40XX_MAX_FRAME_SIZE_MTU;
131e388de98SAdrian Chadd reg |= 9018 + 8 + 2;
132e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_MAX_FRAME_SIZE, reg);
133e388de98SAdrian Chadd
134e388de98SAdrian Chadd /* Enable MIB counters */
135e388de98SAdrian Chadd reg = AR40XX_REG_READ(sc, AR40XX_REG_MODULE_EN);
136e388de98SAdrian Chadd reg |= AR40XX_MODULE_EN_MIB;
137e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_MODULE_EN, reg);
138e388de98SAdrian Chadd
139e388de98SAdrian Chadd /* Disable AZ */
140e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_EEE_CTRL, 0);
141e388de98SAdrian Chadd
142e388de98SAdrian Chadd /* set flowctrl thershold for cpu port */
143e388de98SAdrian Chadd reg = (AR40XX_PORT0_FC_THRESH_ON_DFLT << 16)
144e388de98SAdrian Chadd | AR40XX_PORT0_FC_THRESH_OFF_DFLT;
145e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_PORT_FLOWCTRL_THRESH(0), reg);
146e388de98SAdrian Chadd
147e388de98SAdrian Chadd AR40XX_REG_BARRIER_WRITE(sc);
148e388de98SAdrian Chadd
149e388de98SAdrian Chadd return (0);
150e388de98SAdrian Chadd }
151e388de98SAdrian Chadd
152e388de98SAdrian Chadd int
ar40xx_hw_vlan_init(struct ar40xx_softc * sc)153e388de98SAdrian Chadd ar40xx_hw_vlan_init(struct ar40xx_softc *sc)
154e388de98SAdrian Chadd {
155e388de98SAdrian Chadd int i;
156e388de98SAdrian Chadd
157e388de98SAdrian Chadd AR40XX_DPRINTF(sc, AR40XX_DBG_HW_INIT, "%s: called\n", __func__);
158e388de98SAdrian Chadd
159e388de98SAdrian Chadd /* Enable VLANs by default */
160e388de98SAdrian Chadd sc->sc_vlan.vlan = 1;
161e388de98SAdrian Chadd
162e388de98SAdrian Chadd /* Configure initial LAN/WAN bitmap and include CPU port as tagged */
163e388de98SAdrian Chadd sc->sc_vlan.vlan_id[AR40XX_LAN_VLAN] = AR40XX_LAN_VLAN
164e388de98SAdrian Chadd | ETHERSWITCH_VID_VALID;
165e388de98SAdrian Chadd sc->sc_vlan.vlan_id[AR40XX_WAN_VLAN] = AR40XX_WAN_VLAN
166e388de98SAdrian Chadd | ETHERSWITCH_VID_VALID;
167e388de98SAdrian Chadd
168e388de98SAdrian Chadd sc->sc_vlan.vlan_ports[AR40XX_LAN_VLAN] =
169e388de98SAdrian Chadd sc->sc_config.switch_cpu_bmp | sc->sc_config.switch_lan_bmp;
170e388de98SAdrian Chadd sc->sc_vlan.vlan_untagged[AR40XX_LAN_VLAN] =
171e388de98SAdrian Chadd sc->sc_config.switch_lan_bmp;
172e388de98SAdrian Chadd
173e388de98SAdrian Chadd sc->sc_vlan.vlan_ports[AR40XX_WAN_VLAN] =
174e388de98SAdrian Chadd sc->sc_config.switch_cpu_bmp | sc->sc_config.switch_wan_bmp;
175e388de98SAdrian Chadd sc->sc_vlan.vlan_untagged[AR40XX_WAN_VLAN] =
176e388de98SAdrian Chadd sc->sc_config.switch_wan_bmp;
177e388de98SAdrian Chadd
178e388de98SAdrian Chadd /* Populate the per-port PVID - pvid[] is an index into vlan_id[] */
179e388de98SAdrian Chadd for (i = 0; i < AR40XX_NUM_PORTS; i++) {
180e388de98SAdrian Chadd if (sc->sc_config.switch_lan_bmp & (1U << i))
181e388de98SAdrian Chadd sc->sc_vlan.pvid[i] = AR40XX_LAN_VLAN;
182e388de98SAdrian Chadd if (sc->sc_config.switch_wan_bmp & (1U << i))
183e388de98SAdrian Chadd sc->sc_vlan.pvid[i] = AR40XX_WAN_VLAN;
184e388de98SAdrian Chadd }
185e388de98SAdrian Chadd
186e388de98SAdrian Chadd return (0);
187e388de98SAdrian Chadd }
188e388de98SAdrian Chadd
189e388de98SAdrian Chadd /*
190e388de98SAdrian Chadd * Apply the per-port and global configuration from software.
191e388de98SAdrian Chadd *
192e388de98SAdrian Chadd * This is useful if we ever start doing the linux switch framework
193e388de98SAdrian Chadd * thing of updating the config in one hit and pushing it to the
194e388de98SAdrian Chadd * hardware. For now it's just used in the reset path.
195e388de98SAdrian Chadd */
196e388de98SAdrian Chadd int
ar40xx_hw_sw_hw_apply(struct ar40xx_softc * sc)197e388de98SAdrian Chadd ar40xx_hw_sw_hw_apply(struct ar40xx_softc *sc)
198e388de98SAdrian Chadd {
199e388de98SAdrian Chadd uint8_t portmask[AR40XX_NUM_PORTS];
200e388de98SAdrian Chadd int i, j, ret;
201e388de98SAdrian Chadd
202e388de98SAdrian Chadd AR40XX_DPRINTF(sc, AR40XX_DBG_HW_INIT, "%s: called\n", __func__);
203e388de98SAdrian Chadd
204e388de98SAdrian Chadd /*
205e388de98SAdrian Chadd * Flush the VTU configuration.
206e388de98SAdrian Chadd */
207e388de98SAdrian Chadd ret = ar40xx_hw_vtu_flush(sc);
208e388de98SAdrian Chadd if (ret != 0) {
209e388de98SAdrian Chadd device_printf(sc->sc_dev,
210e388de98SAdrian Chadd "ERROR: couldn't apply config; vtu flush failed (%d)\n",
211e388de98SAdrian Chadd ret);
212e388de98SAdrian Chadd return (ret);
213e388de98SAdrian Chadd }
214e388de98SAdrian Chadd
215e388de98SAdrian Chadd memset(portmask, 0, sizeof(portmask));
216e388de98SAdrian Chadd
217e388de98SAdrian Chadd /*
218e388de98SAdrian Chadd * Configure the ports based on whether it's 802.1q
219e388de98SAdrian Chadd * VLANs, or just straight up per-port VLANs.
220e388de98SAdrian Chadd */
221e388de98SAdrian Chadd if (sc->sc_vlan.vlan) {
222e388de98SAdrian Chadd device_printf(sc->sc_dev, "%s: configuring 802.1q VLANs\n",
223e388de98SAdrian Chadd __func__);
224e388de98SAdrian Chadd for (j = 0; j < AR40XX_NUM_VTU_ENTRIES; j++) {
225e388de98SAdrian Chadd uint8_t vp = sc->sc_vlan.vlan_ports[j];
226e388de98SAdrian Chadd
227e388de98SAdrian Chadd if (!vp)
228e388de98SAdrian Chadd continue;
229e388de98SAdrian Chadd if ((sc->sc_vlan.vlan_id[j]
230e388de98SAdrian Chadd & ETHERSWITCH_VID_VALID) == 0)
231e388de98SAdrian Chadd continue;
232e388de98SAdrian Chadd
233e388de98SAdrian Chadd for (i = 0; i < AR40XX_NUM_PORTS; i++) {
234e388de98SAdrian Chadd uint8_t mask = (1U << i);
235e388de98SAdrian Chadd
236e388de98SAdrian Chadd if (vp & mask)
237e388de98SAdrian Chadd portmask[i] |= vp & ~mask;
238e388de98SAdrian Chadd }
239e388de98SAdrian Chadd
240e388de98SAdrian Chadd ar40xx_hw_vtu_load_vlan(sc,
241e388de98SAdrian Chadd sc->sc_vlan.vlan_id[j] & ETHERSWITCH_VID_MASK,
242e388de98SAdrian Chadd sc->sc_vlan.vlan_ports[j],
243e388de98SAdrian Chadd sc->sc_vlan.vlan_untagged[j]);
244e388de98SAdrian Chadd }
245e388de98SAdrian Chadd } else {
246e388de98SAdrian Chadd device_printf(sc->sc_dev, "%s: configuring per-port VLANs\n",
247e388de98SAdrian Chadd __func__);
248e388de98SAdrian Chadd for (i = 0; i < AR40XX_NUM_PORTS; i++) {
249e388de98SAdrian Chadd if (i == AR40XX_PORT_CPU)
250e388de98SAdrian Chadd continue;
251e388de98SAdrian Chadd
252e388de98SAdrian Chadd portmask[i] = (1U << AR40XX_PORT_CPU);
253e388de98SAdrian Chadd portmask[AR40XX_PORT_CPU] |= (1U << i);
254e388de98SAdrian Chadd }
255e388de98SAdrian Chadd }
256e388de98SAdrian Chadd
257e388de98SAdrian Chadd /*
258e388de98SAdrian Chadd * Update per-port destination mask, vlan tag settings
259e388de98SAdrian Chadd */
260e388de98SAdrian Chadd for (i = 0; i < AR40XX_NUM_PORTS; i++)
261e388de98SAdrian Chadd (void) ar40xx_hw_port_setup(sc, i, portmask[i]);
262e388de98SAdrian Chadd
263e388de98SAdrian Chadd /* Set the mirror register config */
264e388de98SAdrian Chadd ret = ar40xx_hw_mirror_set_registers(sc);
265e388de98SAdrian Chadd if (ret != 0) {
266e388de98SAdrian Chadd device_printf(sc->sc_dev,
267e388de98SAdrian Chadd "ERROR: couldn't apply config; mirror config failed"
268e388de98SAdrian Chadd " (%d)\n",
269e388de98SAdrian Chadd ret);
270e388de98SAdrian Chadd return (ret);
271e388de98SAdrian Chadd }
272e388de98SAdrian Chadd
273e388de98SAdrian Chadd return (0);
274e388de98SAdrian Chadd }
275e388de98SAdrian Chadd
276e388de98SAdrian Chadd int
ar40xx_hw_wait_bit(struct ar40xx_softc * sc,int reg,uint32_t mask,uint32_t val)277e388de98SAdrian Chadd ar40xx_hw_wait_bit(struct ar40xx_softc *sc, int reg, uint32_t mask,
278e388de98SAdrian Chadd uint32_t val)
279e388de98SAdrian Chadd {
280e388de98SAdrian Chadd int timeout = 20;
281e388de98SAdrian Chadd uint32_t t;
282e388de98SAdrian Chadd
283e388de98SAdrian Chadd while (true) {
284e388de98SAdrian Chadd AR40XX_REG_BARRIER_READ(sc);
285e388de98SAdrian Chadd t = AR40XX_REG_READ(sc, reg);
286e388de98SAdrian Chadd if ((t & mask) == val)
287e388de98SAdrian Chadd return 0;
288e388de98SAdrian Chadd
289e388de98SAdrian Chadd if (timeout-- <= 0)
290e388de98SAdrian Chadd break;
291e388de98SAdrian Chadd
292e388de98SAdrian Chadd DELAY(20);
293e388de98SAdrian Chadd }
294e388de98SAdrian Chadd
295e388de98SAdrian Chadd device_printf(sc->sc_dev, "ERROR: timeout for reg "
296e388de98SAdrian Chadd "%08x: %08x & %08x != %08x\n",
297e388de98SAdrian Chadd (unsigned int)reg, t, mask, val);
298e388de98SAdrian Chadd return (ETIMEDOUT);
299e388de98SAdrian Chadd }
300e388de98SAdrian Chadd
301e388de98SAdrian Chadd /*
302e388de98SAdrian Chadd * Read the switch MAC address.
303e388de98SAdrian Chadd */
304e388de98SAdrian Chadd int
ar40xx_hw_read_switch_mac_address(struct ar40xx_softc * sc,struct ether_addr * ea)305e388de98SAdrian Chadd ar40xx_hw_read_switch_mac_address(struct ar40xx_softc *sc,
306e388de98SAdrian Chadd struct ether_addr *ea)
307e388de98SAdrian Chadd {
308e388de98SAdrian Chadd uint32_t ret0, ret1;
309e388de98SAdrian Chadd char *s;
310e388de98SAdrian Chadd
311e388de98SAdrian Chadd s = (void *) ea;
312e388de98SAdrian Chadd
313e388de98SAdrian Chadd AR40XX_LOCK_ASSERT(sc);
314e388de98SAdrian Chadd
315e388de98SAdrian Chadd AR40XX_REG_BARRIER_READ(sc);
316e388de98SAdrian Chadd ret0 = AR40XX_REG_READ(sc, AR40XX_REG_SW_MAC_ADDR0);
317e388de98SAdrian Chadd ret1 = AR40XX_REG_READ(sc, AR40XX_REG_SW_MAC_ADDR1);
318e388de98SAdrian Chadd
319e388de98SAdrian Chadd s[5] = MS(ret0, AR40XX_REG_SW_MAC_ADDR0_BYTE5);
320e388de98SAdrian Chadd s[4] = MS(ret0, AR40XX_REG_SW_MAC_ADDR0_BYTE4);
321e388de98SAdrian Chadd s[3] = MS(ret1, AR40XX_REG_SW_MAC_ADDR1_BYTE3);
322e388de98SAdrian Chadd s[2] = MS(ret1, AR40XX_REG_SW_MAC_ADDR1_BYTE2);
323e388de98SAdrian Chadd s[1] = MS(ret1, AR40XX_REG_SW_MAC_ADDR1_BYTE1);
324e388de98SAdrian Chadd s[0] = MS(ret1, AR40XX_REG_SW_MAC_ADDR1_BYTE0);
325e388de98SAdrian Chadd
326e388de98SAdrian Chadd return (0);
327e388de98SAdrian Chadd }
328e388de98SAdrian Chadd
329e388de98SAdrian Chadd /*
330e388de98SAdrian Chadd * Set the switch MAC address.
331e388de98SAdrian Chadd */
332e388de98SAdrian Chadd int
ar40xx_hw_write_switch_mac_address(struct ar40xx_softc * sc,struct ether_addr * ea)333e388de98SAdrian Chadd ar40xx_hw_write_switch_mac_address(struct ar40xx_softc *sc,
334e388de98SAdrian Chadd struct ether_addr *ea)
335e388de98SAdrian Chadd {
336e388de98SAdrian Chadd uint32_t ret0 = 0, ret1 = 0;
337e388de98SAdrian Chadd char *s;
338e388de98SAdrian Chadd
339e388de98SAdrian Chadd s = (void *) ea;
340e388de98SAdrian Chadd
341e388de98SAdrian Chadd AR40XX_LOCK_ASSERT(sc);
342e388de98SAdrian Chadd
343e388de98SAdrian Chadd ret0 |= SM(s[5], AR40XX_REG_SW_MAC_ADDR0_BYTE5);
344e388de98SAdrian Chadd ret0 |= SM(s[4], AR40XX_REG_SW_MAC_ADDR0_BYTE4);
345e388de98SAdrian Chadd
346e388de98SAdrian Chadd ret1 |= SM(s[3], AR40XX_REG_SW_MAC_ADDR1_BYTE3);
347e388de98SAdrian Chadd ret1 |= SM(s[2], AR40XX_REG_SW_MAC_ADDR1_BYTE2);
348e388de98SAdrian Chadd ret1 |= SM(s[1], AR40XX_REG_SW_MAC_ADDR1_BYTE1);
349e388de98SAdrian Chadd ret1 |= SM(s[0], AR40XX_REG_SW_MAC_ADDR1_BYTE0);
350e388de98SAdrian Chadd
351e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_SW_MAC_ADDR0, ret0);
352e388de98SAdrian Chadd AR40XX_REG_WRITE(sc, AR40XX_REG_SW_MAC_ADDR1, ret1);
353e388de98SAdrian Chadd
354e388de98SAdrian Chadd AR40XX_REG_BARRIER_WRITE(sc);
355e388de98SAdrian Chadd
356e388de98SAdrian Chadd return (0);
357e388de98SAdrian Chadd }
358