if_ale.c revision 1.3.4.6 1 1.3.4.6 yamt /* $NetBSD: if_ale.c,v 1.3.4.6 2010/08/11 22:53:45 yamt Exp $ */
2 1.3.4.2 yamt
3 1.3.4.2 yamt /*-
4 1.3.4.2 yamt * Copyright (c) 2008, Pyun YongHyeon <yongari (at) FreeBSD.org>
5 1.3.4.2 yamt * All rights reserved.
6 1.3.4.2 yamt *
7 1.3.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.3.4.2 yamt * modification, are permitted provided that the following conditions
9 1.3.4.2 yamt * are met:
10 1.3.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.3.4.2 yamt * notice unmodified, this list of conditions, and the following
12 1.3.4.2 yamt * disclaimer.
13 1.3.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
14 1.3.4.2 yamt * notice, this list of conditions and the following disclaimer in the
15 1.3.4.2 yamt * documentation and/or other materials provided with the distribution.
16 1.3.4.2 yamt *
17 1.3.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 1.3.4.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.3.4.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.3.4.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 1.3.4.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.3.4.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.3.4.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.3.4.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.3.4.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.3.4.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.3.4.2 yamt * SUCH DAMAGE.
28 1.3.4.2 yamt *
29 1.3.4.2 yamt * $FreeBSD: src/sys/dev/ale/if_ale.c,v 1.3 2008/12/03 09:01:12 yongari Exp $
30 1.3.4.2 yamt */
31 1.3.4.2 yamt
32 1.3.4.2 yamt /* Driver for Atheros AR8121/AR8113/AR8114 PCIe Ethernet. */
33 1.3.4.2 yamt
34 1.3.4.2 yamt #include <sys/cdefs.h>
35 1.3.4.6 yamt __KERNEL_RCSID(0, "$NetBSD: if_ale.c,v 1.3.4.6 2010/08/11 22:53:45 yamt Exp $");
36 1.3.4.2 yamt
37 1.3.4.2 yamt #include "vlan.h"
38 1.3.4.2 yamt
39 1.3.4.2 yamt #include <sys/param.h>
40 1.3.4.2 yamt #include <sys/proc.h>
41 1.3.4.2 yamt #include <sys/endian.h>
42 1.3.4.2 yamt #include <sys/systm.h>
43 1.3.4.2 yamt #include <sys/types.h>
44 1.3.4.2 yamt #include <sys/sockio.h>
45 1.3.4.2 yamt #include <sys/mbuf.h>
46 1.3.4.2 yamt #include <sys/queue.h>
47 1.3.4.2 yamt #include <sys/kernel.h>
48 1.3.4.2 yamt #include <sys/device.h>
49 1.3.4.2 yamt #include <sys/callout.h>
50 1.3.4.2 yamt #include <sys/socket.h>
51 1.3.4.2 yamt
52 1.3.4.2 yamt #include <sys/bus.h>
53 1.3.4.2 yamt
54 1.3.4.2 yamt #include <net/if.h>
55 1.3.4.2 yamt #include <net/if_dl.h>
56 1.3.4.2 yamt #include <net/if_llc.h>
57 1.3.4.2 yamt #include <net/if_media.h>
58 1.3.4.2 yamt #include <net/if_ether.h>
59 1.3.4.2 yamt
60 1.3.4.2 yamt #ifdef INET
61 1.3.4.2 yamt #include <netinet/in.h>
62 1.3.4.2 yamt #include <netinet/in_systm.h>
63 1.3.4.2 yamt #include <netinet/in_var.h>
64 1.3.4.2 yamt #include <netinet/ip.h>
65 1.3.4.2 yamt #endif
66 1.3.4.2 yamt
67 1.3.4.2 yamt #include <net/if_types.h>
68 1.3.4.2 yamt #include <net/if_vlanvar.h>
69 1.3.4.2 yamt
70 1.3.4.2 yamt #include <net/bpf.h>
71 1.3.4.2 yamt
72 1.3.4.2 yamt #include <sys/rnd.h>
73 1.3.4.2 yamt
74 1.3.4.2 yamt #include <dev/mii/mii.h>
75 1.3.4.2 yamt #include <dev/mii/miivar.h>
76 1.3.4.2 yamt
77 1.3.4.2 yamt #include <dev/pci/pcireg.h>
78 1.3.4.2 yamt #include <dev/pci/pcivar.h>
79 1.3.4.2 yamt #include <dev/pci/pcidevs.h>
80 1.3.4.2 yamt
81 1.3.4.2 yamt #include <dev/pci/if_alereg.h>
82 1.3.4.2 yamt
83 1.3.4.2 yamt static int ale_match(device_t, cfdata_t, void *);
84 1.3.4.2 yamt static void ale_attach(device_t, device_t, void *);
85 1.3.4.2 yamt static int ale_detach(device_t, int);
86 1.3.4.2 yamt
87 1.3.4.2 yamt static int ale_miibus_readreg(device_t, int, int);
88 1.3.4.2 yamt static void ale_miibus_writereg(device_t, int, int, int);
89 1.3.4.2 yamt static void ale_miibus_statchg(device_t);
90 1.3.4.2 yamt
91 1.3.4.2 yamt static int ale_init(struct ifnet *);
92 1.3.4.2 yamt static void ale_start(struct ifnet *);
93 1.3.4.2 yamt static int ale_ioctl(struct ifnet *, u_long, void *);
94 1.3.4.2 yamt static void ale_watchdog(struct ifnet *);
95 1.3.4.2 yamt static int ale_mediachange(struct ifnet *);
96 1.3.4.2 yamt static void ale_mediastatus(struct ifnet *, struct ifmediareq *);
97 1.3.4.2 yamt
98 1.3.4.2 yamt static int ale_intr(void *);
99 1.3.4.2 yamt static int ale_rxeof(struct ale_softc *sc);
100 1.3.4.2 yamt static void ale_rx_update_page(struct ale_softc *, struct ale_rx_page **,
101 1.3.4.2 yamt uint32_t, uint32_t *);
102 1.3.4.2 yamt static void ale_rxcsum(struct ale_softc *, struct mbuf *, uint32_t);
103 1.3.4.2 yamt static void ale_txeof(struct ale_softc *);
104 1.3.4.2 yamt
105 1.3.4.2 yamt static int ale_dma_alloc(struct ale_softc *);
106 1.3.4.2 yamt static void ale_dma_free(struct ale_softc *);
107 1.3.4.2 yamt static int ale_encap(struct ale_softc *, struct mbuf **);
108 1.3.4.2 yamt static void ale_init_rx_pages(struct ale_softc *);
109 1.3.4.2 yamt static void ale_init_tx_ring(struct ale_softc *);
110 1.3.4.2 yamt
111 1.3.4.2 yamt static void ale_stop(struct ifnet *, int);
112 1.3.4.2 yamt static void ale_tick(void *);
113 1.3.4.2 yamt static void ale_get_macaddr(struct ale_softc *);
114 1.3.4.2 yamt static void ale_mac_config(struct ale_softc *);
115 1.3.4.2 yamt static void ale_phy_reset(struct ale_softc *);
116 1.3.4.2 yamt static void ale_reset(struct ale_softc *);
117 1.3.4.2 yamt static void ale_rxfilter(struct ale_softc *);
118 1.3.4.2 yamt static void ale_rxvlan(struct ale_softc *);
119 1.3.4.2 yamt static void ale_stats_clear(struct ale_softc *);
120 1.3.4.2 yamt static void ale_stats_update(struct ale_softc *);
121 1.3.4.2 yamt static void ale_stop_mac(struct ale_softc *);
122 1.3.4.2 yamt
123 1.3.4.2 yamt CFATTACH_DECL_NEW(ale, sizeof(struct ale_softc),
124 1.3.4.2 yamt ale_match, ale_attach, ale_detach, NULL);
125 1.3.4.2 yamt
126 1.3.4.2 yamt int aledebug = 0;
127 1.3.4.2 yamt #define DPRINTF(x) do { if (aledebug) printf x; } while (0)
128 1.3.4.2 yamt
129 1.3.4.2 yamt #define ETHER_ALIGN 2
130 1.3.4.2 yamt #define ALE_CSUM_FEATURES (M_CSUM_TCPv4 | M_CSUM_UDPv4)
131 1.3.4.2 yamt
132 1.3.4.2 yamt static int
133 1.3.4.2 yamt ale_miibus_readreg(device_t dev, int phy, int reg)
134 1.3.4.2 yamt {
135 1.3.4.2 yamt struct ale_softc *sc = device_private(dev);
136 1.3.4.2 yamt uint32_t v;
137 1.3.4.2 yamt int i;
138 1.3.4.2 yamt
139 1.3.4.2 yamt if (phy != sc->ale_phyaddr)
140 1.3.4.2 yamt return 0;
141 1.3.4.2 yamt
142 1.3.4.3 yamt if (sc->ale_flags & ALE_FLAG_FASTETHER) {
143 1.3.4.3 yamt switch (reg) {
144 1.3.4.3 yamt case MII_100T2CR:
145 1.3.4.3 yamt case MII_100T2SR:
146 1.3.4.3 yamt case MII_EXTSR:
147 1.3.4.3 yamt return 0;
148 1.3.4.3 yamt default:
149 1.3.4.3 yamt break;
150 1.3.4.3 yamt }
151 1.3.4.3 yamt }
152 1.3.4.3 yamt
153 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MDIO, MDIO_OP_EXECUTE | MDIO_OP_READ |
154 1.3.4.2 yamt MDIO_SUP_PREAMBLE | MDIO_CLK_25_4 | MDIO_REG_ADDR(reg));
155 1.3.4.2 yamt for (i = ALE_PHY_TIMEOUT; i > 0; i--) {
156 1.3.4.2 yamt DELAY(5);
157 1.3.4.2 yamt v = CSR_READ_4(sc, ALE_MDIO);
158 1.3.4.2 yamt if ((v & (MDIO_OP_EXECUTE | MDIO_OP_BUSY)) == 0)
159 1.3.4.2 yamt break;
160 1.3.4.2 yamt }
161 1.3.4.2 yamt
162 1.3.4.2 yamt if (i == 0) {
163 1.3.4.2 yamt printf("%s: phy read timeout: phy %d, reg %d\n",
164 1.3.4.2 yamt device_xname(sc->sc_dev), phy, reg);
165 1.3.4.2 yamt return 0;
166 1.3.4.2 yamt }
167 1.3.4.2 yamt
168 1.3.4.3 yamt return (v & MDIO_DATA_MASK) >> MDIO_DATA_SHIFT;
169 1.3.4.2 yamt }
170 1.3.4.2 yamt
171 1.3.4.2 yamt static void
172 1.3.4.2 yamt ale_miibus_writereg(device_t dev, int phy, int reg, int val)
173 1.3.4.2 yamt {
174 1.3.4.2 yamt struct ale_softc *sc = device_private(dev);
175 1.3.4.2 yamt uint32_t v;
176 1.3.4.2 yamt int i;
177 1.3.4.2 yamt
178 1.3.4.2 yamt if (phy != sc->ale_phyaddr)
179 1.3.4.2 yamt return;
180 1.3.4.2 yamt
181 1.3.4.3 yamt if (sc->ale_flags & ALE_FLAG_FASTETHER) {
182 1.3.4.3 yamt switch (reg) {
183 1.3.4.3 yamt case MII_100T2CR:
184 1.3.4.3 yamt case MII_100T2SR:
185 1.3.4.3 yamt case MII_EXTSR:
186 1.3.4.3 yamt return;
187 1.3.4.3 yamt default:
188 1.3.4.3 yamt break;
189 1.3.4.3 yamt }
190 1.3.4.3 yamt }
191 1.3.4.3 yamt
192 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MDIO, MDIO_OP_EXECUTE | MDIO_OP_WRITE |
193 1.3.4.2 yamt (val & MDIO_DATA_MASK) << MDIO_DATA_SHIFT |
194 1.3.4.2 yamt MDIO_SUP_PREAMBLE | MDIO_CLK_25_4 | MDIO_REG_ADDR(reg));
195 1.3.4.2 yamt for (i = ALE_PHY_TIMEOUT; i > 0; i--) {
196 1.3.4.2 yamt DELAY(5);
197 1.3.4.2 yamt v = CSR_READ_4(sc, ALE_MDIO);
198 1.3.4.2 yamt if ((v & (MDIO_OP_EXECUTE | MDIO_OP_BUSY)) == 0)
199 1.3.4.2 yamt break;
200 1.3.4.2 yamt }
201 1.3.4.2 yamt
202 1.3.4.2 yamt if (i == 0)
203 1.3.4.2 yamt printf("%s: phy write timeout: phy %d, reg %d\n",
204 1.3.4.2 yamt device_xname(sc->sc_dev), phy, reg);
205 1.3.4.2 yamt }
206 1.3.4.2 yamt
207 1.3.4.2 yamt static void
208 1.3.4.2 yamt ale_miibus_statchg(device_t dev)
209 1.3.4.2 yamt {
210 1.3.4.2 yamt struct ale_softc *sc = device_private(dev);
211 1.3.4.2 yamt struct ifnet *ifp = &sc->sc_ec.ec_if;
212 1.3.4.2 yamt struct mii_data *mii;
213 1.3.4.2 yamt uint32_t reg;
214 1.3.4.2 yamt
215 1.3.4.2 yamt if ((ifp->if_flags & IFF_RUNNING) == 0)
216 1.3.4.2 yamt return;
217 1.3.4.2 yamt
218 1.3.4.2 yamt mii = &sc->sc_miibus;
219 1.3.4.2 yamt
220 1.3.4.2 yamt sc->ale_flags &= ~ALE_FLAG_LINK;
221 1.3.4.2 yamt if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
222 1.3.4.2 yamt (IFM_ACTIVE | IFM_AVALID)) {
223 1.3.4.2 yamt switch (IFM_SUBTYPE(mii->mii_media_active)) {
224 1.3.4.2 yamt case IFM_10_T:
225 1.3.4.2 yamt case IFM_100_TX:
226 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_LINK;
227 1.3.4.2 yamt break;
228 1.3.4.2 yamt
229 1.3.4.2 yamt case IFM_1000_T:
230 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_FASTETHER) == 0)
231 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_LINK;
232 1.3.4.2 yamt break;
233 1.3.4.2 yamt
234 1.3.4.2 yamt default:
235 1.3.4.2 yamt break;
236 1.3.4.2 yamt }
237 1.3.4.2 yamt }
238 1.3.4.2 yamt
239 1.3.4.2 yamt /* Stop Rx/Tx MACs. */
240 1.3.4.2 yamt ale_stop_mac(sc);
241 1.3.4.2 yamt
242 1.3.4.2 yamt /* Program MACs with resolved speed/duplex/flow-control. */
243 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_LINK) != 0) {
244 1.3.4.2 yamt ale_mac_config(sc);
245 1.3.4.2 yamt /* Reenable Tx/Rx MACs. */
246 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_MAC_CFG);
247 1.3.4.2 yamt reg |= MAC_CFG_TX_ENB | MAC_CFG_RX_ENB;
248 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAC_CFG, reg);
249 1.3.4.2 yamt }
250 1.3.4.2 yamt }
251 1.3.4.2 yamt
252 1.3.4.2 yamt void
253 1.3.4.2 yamt ale_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
254 1.3.4.2 yamt {
255 1.3.4.2 yamt struct ale_softc *sc = ifp->if_softc;
256 1.3.4.2 yamt struct mii_data *mii = &sc->sc_miibus;
257 1.3.4.2 yamt
258 1.3.4.2 yamt mii_pollstat(mii);
259 1.3.4.2 yamt ifmr->ifm_status = mii->mii_media_status;
260 1.3.4.2 yamt ifmr->ifm_active = mii->mii_media_active;
261 1.3.4.2 yamt }
262 1.3.4.2 yamt
263 1.3.4.2 yamt int
264 1.3.4.2 yamt ale_mediachange(struct ifnet *ifp)
265 1.3.4.2 yamt {
266 1.3.4.2 yamt struct ale_softc *sc = ifp->if_softc;
267 1.3.4.2 yamt struct mii_data *mii = &sc->sc_miibus;
268 1.3.4.2 yamt int error;
269 1.3.4.2 yamt
270 1.3.4.2 yamt if (mii->mii_instance != 0) {
271 1.3.4.2 yamt struct mii_softc *miisc;
272 1.3.4.2 yamt
273 1.3.4.2 yamt LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
274 1.3.4.2 yamt mii_phy_reset(miisc);
275 1.3.4.2 yamt }
276 1.3.4.2 yamt error = mii_mediachg(mii);
277 1.3.4.2 yamt
278 1.3.4.2 yamt return error;
279 1.3.4.2 yamt }
280 1.3.4.2 yamt
281 1.3.4.2 yamt int
282 1.3.4.2 yamt ale_match(device_t dev, cfdata_t match, void *aux)
283 1.3.4.2 yamt {
284 1.3.4.2 yamt struct pci_attach_args *pa = aux;
285 1.3.4.2 yamt
286 1.3.4.2 yamt return (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ATTANSIC &&
287 1.3.4.2 yamt PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ATTANSIC_ETHERNET_L1E);
288 1.3.4.2 yamt }
289 1.3.4.2 yamt
290 1.3.4.2 yamt void
291 1.3.4.2 yamt ale_get_macaddr(struct ale_softc *sc)
292 1.3.4.2 yamt {
293 1.3.4.2 yamt uint32_t ea[2], reg;
294 1.3.4.2 yamt int i, vpdc;
295 1.3.4.2 yamt
296 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_SPI_CTRL);
297 1.3.4.2 yamt if ((reg & SPI_VPD_ENB) != 0) {
298 1.3.4.2 yamt reg &= ~SPI_VPD_ENB;
299 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_SPI_CTRL, reg);
300 1.3.4.2 yamt }
301 1.3.4.2 yamt
302 1.3.4.2 yamt if (pci_get_capability(sc->sc_pct, sc->sc_pcitag, PCI_CAP_VPD,
303 1.3.4.2 yamt &vpdc, NULL)) {
304 1.3.4.2 yamt /*
305 1.3.4.2 yamt * PCI VPD capability found, let TWSI reload EEPROM.
306 1.3.4.2 yamt * This will set ethernet address of controller.
307 1.3.4.2 yamt */
308 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TWSI_CTRL, CSR_READ_4(sc, ALE_TWSI_CTRL) |
309 1.3.4.2 yamt TWSI_CTRL_SW_LD_START);
310 1.3.4.2 yamt for (i = 100; i > 0; i--) {
311 1.3.4.2 yamt DELAY(1000);
312 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_TWSI_CTRL);
313 1.3.4.2 yamt if ((reg & TWSI_CTRL_SW_LD_START) == 0)
314 1.3.4.2 yamt break;
315 1.3.4.2 yamt }
316 1.3.4.2 yamt if (i == 0)
317 1.3.4.2 yamt printf("%s: reloading EEPROM timeout!\n",
318 1.3.4.2 yamt device_xname(sc->sc_dev));
319 1.3.4.2 yamt } else {
320 1.3.4.2 yamt if (aledebug)
321 1.3.4.2 yamt printf("%s: PCI VPD capability not found!\n",
322 1.3.4.2 yamt device_xname(sc->sc_dev));
323 1.3.4.2 yamt }
324 1.3.4.2 yamt
325 1.3.4.2 yamt ea[0] = CSR_READ_4(sc, ALE_PAR0);
326 1.3.4.2 yamt ea[1] = CSR_READ_4(sc, ALE_PAR1);
327 1.3.4.2 yamt sc->ale_eaddr[0] = (ea[1] >> 8) & 0xFF;
328 1.3.4.2 yamt sc->ale_eaddr[1] = (ea[1] >> 0) & 0xFF;
329 1.3.4.2 yamt sc->ale_eaddr[2] = (ea[0] >> 24) & 0xFF;
330 1.3.4.2 yamt sc->ale_eaddr[3] = (ea[0] >> 16) & 0xFF;
331 1.3.4.2 yamt sc->ale_eaddr[4] = (ea[0] >> 8) & 0xFF;
332 1.3.4.2 yamt sc->ale_eaddr[5] = (ea[0] >> 0) & 0xFF;
333 1.3.4.2 yamt }
334 1.3.4.2 yamt
335 1.3.4.2 yamt void
336 1.3.4.2 yamt ale_phy_reset(struct ale_softc *sc)
337 1.3.4.2 yamt {
338 1.3.4.2 yamt /* Reset magic from Linux. */
339 1.3.4.2 yamt CSR_WRITE_2(sc, ALE_GPHY_CTRL,
340 1.3.4.2 yamt GPHY_CTRL_HIB_EN | GPHY_CTRL_HIB_PULSE | GPHY_CTRL_SEL_ANA_RESET |
341 1.3.4.2 yamt GPHY_CTRL_PHY_PLL_ON);
342 1.3.4.2 yamt DELAY(1000);
343 1.3.4.2 yamt CSR_WRITE_2(sc, ALE_GPHY_CTRL,
344 1.3.4.2 yamt GPHY_CTRL_EXT_RESET | GPHY_CTRL_HIB_EN | GPHY_CTRL_HIB_PULSE |
345 1.3.4.2 yamt GPHY_CTRL_SEL_ANA_RESET | GPHY_CTRL_PHY_PLL_ON);
346 1.3.4.2 yamt DELAY(1000);
347 1.3.4.2 yamt
348 1.3.4.2 yamt #define ATPHY_DBG_ADDR 0x1D
349 1.3.4.2 yamt #define ATPHY_DBG_DATA 0x1E
350 1.3.4.2 yamt
351 1.3.4.2 yamt /* Enable hibernation mode. */
352 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
353 1.3.4.2 yamt ATPHY_DBG_ADDR, 0x0B);
354 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
355 1.3.4.2 yamt ATPHY_DBG_DATA, 0xBC00);
356 1.3.4.2 yamt /* Set Class A/B for all modes. */
357 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
358 1.3.4.2 yamt ATPHY_DBG_ADDR, 0x00);
359 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
360 1.3.4.2 yamt ATPHY_DBG_DATA, 0x02EF);
361 1.3.4.2 yamt /* Enable 10BT power saving. */
362 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
363 1.3.4.2 yamt ATPHY_DBG_ADDR, 0x12);
364 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
365 1.3.4.2 yamt ATPHY_DBG_DATA, 0x4C04);
366 1.3.4.2 yamt /* Adjust 1000T power. */
367 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
368 1.3.4.2 yamt ATPHY_DBG_ADDR, 0x04);
369 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
370 1.3.4.2 yamt ATPHY_DBG_ADDR, 0x8BBB);
371 1.3.4.2 yamt /* 10BT center tap voltage. */
372 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
373 1.3.4.2 yamt ATPHY_DBG_ADDR, 0x05);
374 1.3.4.2 yamt ale_miibus_writereg(sc->sc_dev, sc->ale_phyaddr,
375 1.3.4.2 yamt ATPHY_DBG_ADDR, 0x2C46);
376 1.3.4.2 yamt
377 1.3.4.2 yamt #undef ATPHY_DBG_ADDR
378 1.3.4.2 yamt #undef ATPHY_DBG_DATA
379 1.3.4.2 yamt DELAY(1000);
380 1.3.4.2 yamt }
381 1.3.4.2 yamt
382 1.3.4.2 yamt void
383 1.3.4.2 yamt ale_attach(device_t parent, device_t self, void *aux)
384 1.3.4.2 yamt {
385 1.3.4.2 yamt struct ale_softc *sc = device_private(self);
386 1.3.4.2 yamt struct pci_attach_args *pa = aux;
387 1.3.4.2 yamt pci_chipset_tag_t pc = pa->pa_pc;
388 1.3.4.2 yamt pci_intr_handle_t ih;
389 1.3.4.2 yamt const char *intrstr;
390 1.3.4.2 yamt struct ifnet *ifp;
391 1.3.4.2 yamt pcireg_t memtype;
392 1.3.4.3 yamt int mii_flags, error = 0;
393 1.3.4.2 yamt uint32_t rxf_len, txf_len;
394 1.3.4.3 yamt const char *chipname;
395 1.3.4.2 yamt
396 1.3.4.2 yamt aprint_naive("\n");
397 1.3.4.2 yamt aprint_normal(": Attansic/Atheros L1E Ethernet\n");
398 1.3.4.2 yamt
399 1.3.4.2 yamt sc->sc_dev = self;
400 1.3.4.2 yamt sc->sc_dmat = pa->pa_dmat;
401 1.3.4.2 yamt sc->sc_pct = pa->pa_pc;
402 1.3.4.2 yamt sc->sc_pcitag = pa->pa_tag;
403 1.3.4.2 yamt
404 1.3.4.2 yamt /*
405 1.3.4.2 yamt * Allocate IO memory
406 1.3.4.2 yamt */
407 1.3.4.2 yamt memtype = pci_mapreg_type(sc->sc_pct, sc->sc_pcitag, ALE_PCIR_BAR);
408 1.3.4.2 yamt switch (memtype) {
409 1.3.4.2 yamt case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
410 1.3.4.2 yamt case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT_1M:
411 1.3.4.2 yamt case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
412 1.3.4.2 yamt break;
413 1.3.4.2 yamt default:
414 1.3.4.2 yamt aprint_error_dev(self, "invalid base address register\n");
415 1.3.4.2 yamt break;
416 1.3.4.2 yamt }
417 1.3.4.2 yamt
418 1.3.4.2 yamt if (pci_mapreg_map(pa, ALE_PCIR_BAR, memtype, 0, &sc->sc_mem_bt,
419 1.3.4.2 yamt &sc->sc_mem_bh, NULL, &sc->sc_mem_size)) {
420 1.3.4.2 yamt aprint_error_dev(self, "could not map mem space\n");
421 1.3.4.2 yamt return;
422 1.3.4.2 yamt }
423 1.3.4.2 yamt
424 1.3.4.2 yamt if (pci_intr_map(pa, &ih) != 0) {
425 1.3.4.2 yamt aprint_error_dev(self, "could not map interrupt\n");
426 1.3.4.2 yamt goto fail;
427 1.3.4.2 yamt }
428 1.3.4.2 yamt
429 1.3.4.2 yamt /*
430 1.3.4.2 yamt * Allocate IRQ
431 1.3.4.2 yamt */
432 1.3.4.2 yamt intrstr = pci_intr_string(sc->sc_pct, ih);
433 1.3.4.2 yamt sc->sc_irq_handle = pci_intr_establish(pc, ih, IPL_NET, ale_intr, sc);
434 1.3.4.2 yamt if (sc->sc_irq_handle == NULL) {
435 1.3.4.2 yamt aprint_error_dev(self, "could not establish interrupt");
436 1.3.4.2 yamt if (intrstr != NULL)
437 1.3.4.2 yamt aprint_error(" at %s", intrstr);
438 1.3.4.2 yamt aprint_error("\n");
439 1.3.4.2 yamt goto fail;
440 1.3.4.2 yamt }
441 1.3.4.2 yamt
442 1.3.4.2 yamt /* Set PHY address. */
443 1.3.4.2 yamt sc->ale_phyaddr = ALE_PHY_ADDR;
444 1.3.4.2 yamt
445 1.3.4.2 yamt /* Reset PHY. */
446 1.3.4.2 yamt ale_phy_reset(sc);
447 1.3.4.2 yamt
448 1.3.4.2 yamt /* Reset the ethernet controller. */
449 1.3.4.2 yamt ale_reset(sc);
450 1.3.4.2 yamt
451 1.3.4.2 yamt /* Get PCI and chip id/revision. */
452 1.3.4.2 yamt sc->ale_rev = PCI_REVISION(pa->pa_class);
453 1.3.4.2 yamt if (sc->ale_rev >= 0xF0) {
454 1.3.4.2 yamt /* L2E Rev. B. AR8114 */
455 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_FASTETHER;
456 1.3.4.3 yamt chipname = "AR8114 (L2E RevB)";
457 1.3.4.2 yamt } else {
458 1.3.4.2 yamt if ((CSR_READ_4(sc, ALE_PHY_STATUS) & PHY_STATUS_100M) != 0) {
459 1.3.4.2 yamt /* L1E AR8121 */
460 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_JUMBO;
461 1.3.4.3 yamt chipname = "AR8121 (L1E)";
462 1.3.4.2 yamt } else {
463 1.3.4.2 yamt /* L2E Rev. A. AR8113 */
464 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_FASTETHER;
465 1.3.4.3 yamt chipname = "AR8113 (L2E RevA)";
466 1.3.4.2 yamt }
467 1.3.4.2 yamt }
468 1.3.4.3 yamt aprint_normal_dev(self, "%s, %s\n", chipname, intrstr);
469 1.3.4.2 yamt
470 1.3.4.2 yamt /*
471 1.3.4.2 yamt * All known controllers seems to require 4 bytes alignment
472 1.3.4.2 yamt * of Tx buffers to make Tx checksum offload with custom
473 1.3.4.2 yamt * checksum generation method work.
474 1.3.4.2 yamt */
475 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_TXCSUM_BUG;
476 1.3.4.2 yamt
477 1.3.4.2 yamt /*
478 1.3.4.2 yamt * All known controllers seems to have issues on Rx checksum
479 1.3.4.2 yamt * offload for fragmented IP datagrams.
480 1.3.4.2 yamt */
481 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_RXCSUM_BUG;
482 1.3.4.2 yamt
483 1.3.4.2 yamt /*
484 1.3.4.2 yamt * Don't use Tx CMB. It is known to cause RRS update failure
485 1.3.4.2 yamt * under certain circumstances. Typical phenomenon of the
486 1.3.4.2 yamt * issue would be unexpected sequence number encountered in
487 1.3.4.2 yamt * Rx handler.
488 1.3.4.2 yamt */
489 1.3.4.2 yamt sc->ale_flags |= ALE_FLAG_TXCMB_BUG;
490 1.3.4.2 yamt sc->ale_chip_rev = CSR_READ_4(sc, ALE_MASTER_CFG) >>
491 1.3.4.2 yamt MASTER_CHIP_REV_SHIFT;
492 1.3.4.2 yamt aprint_debug_dev(self, "PCI device revision : 0x%04x\n", sc->ale_rev);
493 1.3.4.2 yamt aprint_debug_dev(self, "Chip id/revision : 0x%04x\n", sc->ale_chip_rev);
494 1.3.4.2 yamt
495 1.3.4.2 yamt /*
496 1.3.4.2 yamt * Uninitialized hardware returns an invalid chip id/revision
497 1.3.4.2 yamt * as well as 0xFFFFFFFF for Tx/Rx fifo length.
498 1.3.4.2 yamt */
499 1.3.4.2 yamt txf_len = CSR_READ_4(sc, ALE_SRAM_TX_FIFO_LEN);
500 1.3.4.2 yamt rxf_len = CSR_READ_4(sc, ALE_SRAM_RX_FIFO_LEN);
501 1.3.4.2 yamt if (sc->ale_chip_rev == 0xFFFF || txf_len == 0xFFFFFFFF ||
502 1.3.4.2 yamt rxf_len == 0xFFFFFFF) {
503 1.3.4.2 yamt aprint_error_dev(self, "chip revision : 0x%04x, %u Tx FIFO "
504 1.3.4.2 yamt "%u Rx FIFO -- not initialized?\n",
505 1.3.4.2 yamt sc->ale_chip_rev, txf_len, rxf_len);
506 1.3.4.2 yamt goto fail;
507 1.3.4.2 yamt }
508 1.3.4.2 yamt
509 1.3.4.2 yamt if (aledebug) {
510 1.3.4.2 yamt printf("%s: %u Tx FIFO, %u Rx FIFO\n", device_xname(sc->sc_dev),
511 1.3.4.2 yamt txf_len, rxf_len);
512 1.3.4.2 yamt }
513 1.3.4.2 yamt
514 1.3.4.2 yamt /* Set max allowable DMA size. */
515 1.3.4.2 yamt sc->ale_dma_rd_burst = DMA_CFG_RD_BURST_128;
516 1.3.4.2 yamt sc->ale_dma_wr_burst = DMA_CFG_WR_BURST_128;
517 1.3.4.2 yamt
518 1.3.4.2 yamt callout_init(&sc->sc_tick_ch, 0);
519 1.3.4.2 yamt callout_setfunc(&sc->sc_tick_ch, ale_tick, sc);
520 1.3.4.2 yamt
521 1.3.4.2 yamt error = ale_dma_alloc(sc);
522 1.3.4.2 yamt if (error)
523 1.3.4.2 yamt goto fail;
524 1.3.4.2 yamt
525 1.3.4.2 yamt /* Load station address. */
526 1.3.4.2 yamt ale_get_macaddr(sc);
527 1.3.4.2 yamt
528 1.3.4.2 yamt aprint_normal_dev(self, "Ethernet address %s\n",
529 1.3.4.2 yamt ether_sprintf(sc->ale_eaddr));
530 1.3.4.2 yamt
531 1.3.4.2 yamt ifp = &sc->sc_ec.ec_if;
532 1.3.4.2 yamt ifp->if_softc = sc;
533 1.3.4.2 yamt ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
534 1.3.4.2 yamt ifp->if_init = ale_init;
535 1.3.4.2 yamt ifp->if_ioctl = ale_ioctl;
536 1.3.4.2 yamt ifp->if_start = ale_start;
537 1.3.4.2 yamt ifp->if_stop = ale_stop;
538 1.3.4.2 yamt ifp->if_watchdog = ale_watchdog;
539 1.3.4.2 yamt IFQ_SET_MAXLEN(&ifp->if_snd, ALE_TX_RING_CNT - 1);
540 1.3.4.2 yamt IFQ_SET_READY(&ifp->if_snd);
541 1.3.4.2 yamt strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
542 1.3.4.2 yamt
543 1.3.4.2 yamt sc->sc_ec.ec_capabilities = ETHERCAP_VLAN_MTU;
544 1.3.4.2 yamt
545 1.3.4.2 yamt #ifdef ALE_CHECKSUM
546 1.3.4.2 yamt ifp->if_capabilities |= IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx |
547 1.3.4.2 yamt IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
548 1.3.4.2 yamt IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_TCPv4_Rx;
549 1.3.4.2 yamt #endif
550 1.3.4.2 yamt
551 1.3.4.2 yamt #if NVLAN > 0
552 1.3.4.2 yamt sc->sc_ec.ec_capabilities |= ETHERCAP_VLAN_HWTAGGING;
553 1.3.4.2 yamt #endif
554 1.3.4.2 yamt
555 1.3.4.2 yamt /* Set up MII bus. */
556 1.3.4.2 yamt sc->sc_miibus.mii_ifp = ifp;
557 1.3.4.2 yamt sc->sc_miibus.mii_readreg = ale_miibus_readreg;
558 1.3.4.2 yamt sc->sc_miibus.mii_writereg = ale_miibus_writereg;
559 1.3.4.2 yamt sc->sc_miibus.mii_statchg = ale_miibus_statchg;
560 1.3.4.2 yamt
561 1.3.4.2 yamt sc->sc_ec.ec_mii = &sc->sc_miibus;
562 1.3.4.2 yamt ifmedia_init(&sc->sc_miibus.mii_media, 0, ale_mediachange,
563 1.3.4.2 yamt ale_mediastatus);
564 1.3.4.3 yamt mii_flags = 0;
565 1.3.4.3 yamt if ((sc->ale_flags & ALE_FLAG_JUMBO) != 0)
566 1.3.4.3 yamt mii_flags |= MIIF_DOPAUSE;
567 1.3.4.2 yamt mii_attach(self, &sc->sc_miibus, 0xffffffff, MII_PHY_ANY,
568 1.3.4.3 yamt MII_OFFSET_ANY, mii_flags);
569 1.3.4.2 yamt
570 1.3.4.2 yamt if (LIST_FIRST(&sc->sc_miibus.mii_phys) == NULL) {
571 1.3.4.2 yamt aprint_error_dev(self, "no PHY found!\n");
572 1.3.4.2 yamt ifmedia_add(&sc->sc_miibus.mii_media, IFM_ETHER | IFM_MANUAL,
573 1.3.4.2 yamt 0, NULL);
574 1.3.4.2 yamt ifmedia_set(&sc->sc_miibus.mii_media, IFM_ETHER | IFM_MANUAL);
575 1.3.4.2 yamt } else
576 1.3.4.2 yamt ifmedia_set(&sc->sc_miibus.mii_media, IFM_ETHER | IFM_AUTO);
577 1.3.4.2 yamt
578 1.3.4.2 yamt if_attach(ifp);
579 1.3.4.2 yamt ether_ifattach(ifp, sc->ale_eaddr);
580 1.3.4.2 yamt
581 1.3.4.4 yamt if (pmf_device_register(self, NULL, NULL))
582 1.3.4.2 yamt pmf_class_network_register(self, ifp);
583 1.3.4.4 yamt else
584 1.3.4.4 yamt aprint_error_dev(self, "couldn't establish power handler\n");
585 1.3.4.2 yamt
586 1.3.4.2 yamt return;
587 1.3.4.2 yamt fail:
588 1.3.4.2 yamt ale_dma_free(sc);
589 1.3.4.2 yamt if (sc->sc_irq_handle != NULL) {
590 1.3.4.2 yamt pci_intr_disestablish(pc, sc->sc_irq_handle);
591 1.3.4.2 yamt sc->sc_irq_handle = NULL;
592 1.3.4.2 yamt }
593 1.3.4.2 yamt if (sc->sc_mem_size) {
594 1.3.4.2 yamt bus_space_unmap(sc->sc_mem_bt, sc->sc_mem_bh, sc->sc_mem_size);
595 1.3.4.2 yamt sc->sc_mem_size = 0;
596 1.3.4.2 yamt }
597 1.3.4.2 yamt }
598 1.3.4.2 yamt
599 1.3.4.2 yamt static int
600 1.3.4.2 yamt ale_detach(device_t self, int flags)
601 1.3.4.2 yamt {
602 1.3.4.2 yamt struct ale_softc *sc = device_private(self);
603 1.3.4.2 yamt struct ifnet *ifp = &sc->sc_ec.ec_if;
604 1.3.4.2 yamt int s;
605 1.3.4.2 yamt
606 1.3.4.2 yamt pmf_device_deregister(self);
607 1.3.4.2 yamt s = splnet();
608 1.3.4.2 yamt ale_stop(ifp, 0);
609 1.3.4.2 yamt splx(s);
610 1.3.4.2 yamt
611 1.3.4.2 yamt mii_detach(&sc->sc_miibus, MII_PHY_ANY, MII_OFFSET_ANY);
612 1.3.4.2 yamt
613 1.3.4.2 yamt /* Delete all remaining media. */
614 1.3.4.2 yamt ifmedia_delete_instance(&sc->sc_miibus.mii_media, IFM_INST_ANY);
615 1.3.4.2 yamt
616 1.3.4.2 yamt ether_ifdetach(ifp);
617 1.3.4.2 yamt if_detach(ifp);
618 1.3.4.2 yamt ale_dma_free(sc);
619 1.3.4.2 yamt
620 1.3.4.2 yamt if (sc->sc_irq_handle != NULL) {
621 1.3.4.2 yamt pci_intr_disestablish(sc->sc_pct, sc->sc_irq_handle);
622 1.3.4.2 yamt sc->sc_irq_handle = NULL;
623 1.3.4.2 yamt }
624 1.3.4.2 yamt if (sc->sc_mem_size) {
625 1.3.4.2 yamt bus_space_unmap(sc->sc_mem_bt, sc->sc_mem_bh, sc->sc_mem_size);
626 1.3.4.2 yamt sc->sc_mem_size = 0;
627 1.3.4.2 yamt }
628 1.3.4.2 yamt
629 1.3.4.2 yamt return 0;
630 1.3.4.2 yamt }
631 1.3.4.2 yamt
632 1.3.4.2 yamt
633 1.3.4.2 yamt static int
634 1.3.4.2 yamt ale_dma_alloc(struct ale_softc *sc)
635 1.3.4.2 yamt {
636 1.3.4.2 yamt struct ale_txdesc *txd;
637 1.3.4.2 yamt int nsegs, error, guard_size, i;
638 1.3.4.2 yamt
639 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_JUMBO) != 0)
640 1.3.4.2 yamt guard_size = ALE_JUMBO_FRAMELEN;
641 1.3.4.2 yamt else
642 1.3.4.2 yamt guard_size = ALE_MAX_FRAMELEN;
643 1.3.4.2 yamt sc->ale_pagesize = roundup(guard_size + ALE_RX_PAGE_SZ,
644 1.3.4.2 yamt ALE_RX_PAGE_ALIGN);
645 1.3.4.2 yamt
646 1.3.4.2 yamt /*
647 1.3.4.2 yamt * Create DMA stuffs for TX ring
648 1.3.4.2 yamt */
649 1.3.4.2 yamt error = bus_dmamap_create(sc->sc_dmat, ALE_TX_RING_SZ, 1,
650 1.3.4.2 yamt ALE_TX_RING_SZ, 0, BUS_DMA_NOWAIT, &sc->ale_cdata.ale_tx_ring_map);
651 1.3.4.2 yamt if (error) {
652 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring_map = NULL;
653 1.3.4.2 yamt return ENOBUFS;
654 1.3.4.2 yamt }
655 1.3.4.2 yamt
656 1.3.4.2 yamt /* Allocate DMA'able memory for TX ring */
657 1.3.4.2 yamt error = bus_dmamem_alloc(sc->sc_dmat, ALE_TX_RING_SZ,
658 1.3.4.2 yamt 0, 0, &sc->ale_cdata.ale_tx_ring_seg, 1,
659 1.3.4.2 yamt &nsegs, BUS_DMA_WAITOK);
660 1.3.4.2 yamt if (error) {
661 1.3.4.2 yamt printf("%s: could not allocate DMA'able memory for Tx ring, "
662 1.3.4.2 yamt "error = %i\n", device_xname(sc->sc_dev), error);
663 1.3.4.2 yamt return error;
664 1.3.4.2 yamt }
665 1.3.4.2 yamt
666 1.3.4.2 yamt error = bus_dmamem_map(sc->sc_dmat, &sc->ale_cdata.ale_tx_ring_seg,
667 1.3.4.2 yamt nsegs, ALE_TX_RING_SZ, (void **)&sc->ale_cdata.ale_tx_ring,
668 1.3.4.2 yamt BUS_DMA_NOWAIT);
669 1.3.4.2 yamt if (error)
670 1.3.4.2 yamt return ENOBUFS;
671 1.3.4.2 yamt
672 1.3.4.2 yamt memset(sc->ale_cdata.ale_tx_ring, 0, ALE_TX_RING_SZ);
673 1.3.4.2 yamt
674 1.3.4.2 yamt /* Load the DMA map for Tx ring. */
675 1.3.4.2 yamt error = bus_dmamap_load(sc->sc_dmat, sc->ale_cdata.ale_tx_ring_map,
676 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring, ALE_TX_RING_SZ, NULL, BUS_DMA_WAITOK);
677 1.3.4.2 yamt if (error) {
678 1.3.4.2 yamt printf("%s: could not load DMA'able memory for Tx ring.\n",
679 1.3.4.2 yamt device_xname(sc->sc_dev));
680 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
681 1.3.4.2 yamt &sc->ale_cdata.ale_tx_ring_seg, 1);
682 1.3.4.2 yamt return error;
683 1.3.4.2 yamt }
684 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring_paddr =
685 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring_map->dm_segs[0].ds_addr;
686 1.3.4.2 yamt
687 1.3.4.2 yamt for (i = 0; i < ALE_RX_PAGES; i++) {
688 1.3.4.2 yamt /*
689 1.3.4.2 yamt * Create DMA stuffs for RX pages
690 1.3.4.2 yamt */
691 1.3.4.2 yamt error = bus_dmamap_create(sc->sc_dmat, sc->ale_pagesize, 1,
692 1.3.4.2 yamt sc->ale_pagesize, 0, BUS_DMA_NOWAIT,
693 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].page_map);
694 1.3.4.2 yamt if (error) {
695 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_map = NULL;
696 1.3.4.2 yamt return ENOBUFS;
697 1.3.4.2 yamt }
698 1.3.4.2 yamt
699 1.3.4.2 yamt /* Allocate DMA'able memory for RX pages */
700 1.3.4.2 yamt error = bus_dmamem_alloc(sc->sc_dmat, sc->ale_pagesize,
701 1.3.4.2 yamt ETHER_ALIGN, 0, &sc->ale_cdata.ale_rx_page[i].page_seg,
702 1.3.4.2 yamt 1, &nsegs, BUS_DMA_WAITOK);
703 1.3.4.2 yamt if (error) {
704 1.3.4.2 yamt printf("%s: could not allocate DMA'able memory for "
705 1.3.4.2 yamt "Rx ring.\n", device_xname(sc->sc_dev));
706 1.3.4.2 yamt return error;
707 1.3.4.2 yamt }
708 1.3.4.2 yamt error = bus_dmamem_map(sc->sc_dmat,
709 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].page_seg, nsegs,
710 1.3.4.2 yamt sc->ale_pagesize,
711 1.3.4.2 yamt (void **)&sc->ale_cdata.ale_rx_page[i].page_addr,
712 1.3.4.2 yamt BUS_DMA_NOWAIT);
713 1.3.4.2 yamt if (error)
714 1.3.4.2 yamt return ENOBUFS;
715 1.3.4.2 yamt
716 1.3.4.2 yamt memset(sc->ale_cdata.ale_rx_page[i].page_addr, 0,
717 1.3.4.2 yamt sc->ale_pagesize);
718 1.3.4.2 yamt
719 1.3.4.2 yamt /* Load the DMA map for Rx pages. */
720 1.3.4.2 yamt error = bus_dmamap_load(sc->sc_dmat,
721 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_map,
722 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_addr,
723 1.3.4.2 yamt sc->ale_pagesize, NULL, BUS_DMA_WAITOK);
724 1.3.4.2 yamt if (error) {
725 1.3.4.2 yamt printf("%s: could not load DMA'able memory for "
726 1.3.4.2 yamt "Rx pages.\n", device_xname(sc->sc_dev));
727 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
728 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].page_seg, 1);
729 1.3.4.2 yamt return error;
730 1.3.4.2 yamt }
731 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_paddr =
732 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_map->dm_segs[0].ds_addr;
733 1.3.4.2 yamt }
734 1.3.4.2 yamt
735 1.3.4.2 yamt /*
736 1.3.4.2 yamt * Create DMA stuffs for Tx CMB.
737 1.3.4.2 yamt */
738 1.3.4.2 yamt error = bus_dmamap_create(sc->sc_dmat, ALE_TX_CMB_SZ, 1,
739 1.3.4.2 yamt ALE_TX_CMB_SZ, 0, BUS_DMA_NOWAIT, &sc->ale_cdata.ale_tx_cmb_map);
740 1.3.4.2 yamt if (error) {
741 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb_map = NULL;
742 1.3.4.2 yamt return ENOBUFS;
743 1.3.4.2 yamt }
744 1.3.4.2 yamt
745 1.3.4.2 yamt /* Allocate DMA'able memory for Tx CMB. */
746 1.3.4.2 yamt error = bus_dmamem_alloc(sc->sc_dmat, ALE_TX_CMB_SZ, ETHER_ALIGN, 0,
747 1.3.4.2 yamt &sc->ale_cdata.ale_tx_cmb_seg, 1, &nsegs, BUS_DMA_WAITOK);
748 1.3.4.2 yamt
749 1.3.4.2 yamt if (error) {
750 1.3.4.2 yamt printf("%s: could not allocate DMA'able memory for Tx CMB.\n",
751 1.3.4.2 yamt device_xname(sc->sc_dev));
752 1.3.4.2 yamt return error;
753 1.3.4.2 yamt }
754 1.3.4.2 yamt
755 1.3.4.2 yamt error = bus_dmamem_map(sc->sc_dmat, &sc->ale_cdata.ale_tx_cmb_seg,
756 1.3.4.2 yamt nsegs, ALE_TX_CMB_SZ, (void **)&sc->ale_cdata.ale_tx_cmb,
757 1.3.4.2 yamt BUS_DMA_NOWAIT);
758 1.3.4.2 yamt if (error)
759 1.3.4.2 yamt return ENOBUFS;
760 1.3.4.2 yamt
761 1.3.4.2 yamt memset(sc->ale_cdata.ale_tx_cmb, 0, ALE_TX_CMB_SZ);
762 1.3.4.2 yamt
763 1.3.4.2 yamt /* Load the DMA map for Tx CMB. */
764 1.3.4.2 yamt error = bus_dmamap_load(sc->sc_dmat, sc->ale_cdata.ale_tx_cmb_map,
765 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb, ALE_TX_CMB_SZ, NULL, BUS_DMA_WAITOK);
766 1.3.4.2 yamt if (error) {
767 1.3.4.2 yamt printf("%s: could not load DMA'able memory for Tx CMB.\n",
768 1.3.4.2 yamt device_xname(sc->sc_dev));
769 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
770 1.3.4.2 yamt &sc->ale_cdata.ale_tx_cmb_seg, 1);
771 1.3.4.2 yamt return error;
772 1.3.4.2 yamt }
773 1.3.4.2 yamt
774 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb_paddr =
775 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb_map->dm_segs[0].ds_addr;
776 1.3.4.2 yamt
777 1.3.4.2 yamt for (i = 0; i < ALE_RX_PAGES; i++) {
778 1.3.4.2 yamt /*
779 1.3.4.2 yamt * Create DMA stuffs for Rx CMB.
780 1.3.4.2 yamt */
781 1.3.4.2 yamt error = bus_dmamap_create(sc->sc_dmat, ALE_RX_CMB_SZ, 1,
782 1.3.4.2 yamt ALE_RX_CMB_SZ, 0, BUS_DMA_NOWAIT,
783 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].cmb_map);
784 1.3.4.2 yamt if (error) {
785 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_map = NULL;
786 1.3.4.2 yamt return ENOBUFS;
787 1.3.4.2 yamt }
788 1.3.4.2 yamt
789 1.3.4.2 yamt /* Allocate DMA'able memory for Rx CMB */
790 1.3.4.2 yamt error = bus_dmamem_alloc(sc->sc_dmat, ALE_RX_CMB_SZ,
791 1.3.4.2 yamt ETHER_ALIGN, 0, &sc->ale_cdata.ale_rx_page[i].cmb_seg, 1,
792 1.3.4.2 yamt &nsegs, BUS_DMA_WAITOK);
793 1.3.4.2 yamt if (error) {
794 1.3.4.2 yamt printf("%s: could not allocate DMA'able memory for "
795 1.3.4.2 yamt "Rx CMB\n", device_xname(sc->sc_dev));
796 1.3.4.2 yamt return error;
797 1.3.4.2 yamt }
798 1.3.4.2 yamt error = bus_dmamem_map(sc->sc_dmat,
799 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].cmb_seg, nsegs,
800 1.3.4.2 yamt ALE_RX_CMB_SZ,
801 1.3.4.2 yamt (void **)&sc->ale_cdata.ale_rx_page[i].cmb_addr,
802 1.3.4.2 yamt BUS_DMA_NOWAIT);
803 1.3.4.2 yamt if (error)
804 1.3.4.2 yamt return ENOBUFS;
805 1.3.4.2 yamt
806 1.3.4.2 yamt memset(sc->ale_cdata.ale_rx_page[i].cmb_addr, 0, ALE_RX_CMB_SZ);
807 1.3.4.2 yamt
808 1.3.4.2 yamt /* Load the DMA map for Rx CMB */
809 1.3.4.2 yamt error = bus_dmamap_load(sc->sc_dmat,
810 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_map,
811 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_addr,
812 1.3.4.2 yamt ALE_RX_CMB_SZ, NULL, BUS_DMA_WAITOK);
813 1.3.4.2 yamt if (error) {
814 1.3.4.2 yamt printf("%s: could not load DMA'able memory for Rx CMB"
815 1.3.4.2 yamt "\n", device_xname(sc->sc_dev));
816 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
817 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].cmb_seg, 1);
818 1.3.4.2 yamt return error;
819 1.3.4.2 yamt }
820 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_paddr =
821 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_map->dm_segs[0].ds_addr;
822 1.3.4.2 yamt }
823 1.3.4.2 yamt
824 1.3.4.2 yamt
825 1.3.4.2 yamt /* Create DMA maps for Tx buffers. */
826 1.3.4.2 yamt for (i = 0; i < ALE_TX_RING_CNT; i++) {
827 1.3.4.2 yamt txd = &sc->ale_cdata.ale_txdesc[i];
828 1.3.4.2 yamt txd->tx_m = NULL;
829 1.3.4.2 yamt txd->tx_dmamap = NULL;
830 1.3.4.2 yamt error = bus_dmamap_create(sc->sc_dmat, ALE_TSO_MAXSIZE,
831 1.3.4.2 yamt ALE_MAXTXSEGS, ALE_TSO_MAXSEGSIZE, 0, BUS_DMA_NOWAIT,
832 1.3.4.2 yamt &txd->tx_dmamap);
833 1.3.4.2 yamt if (error) {
834 1.3.4.2 yamt txd->tx_dmamap = NULL;
835 1.3.4.2 yamt printf("%s: could not create Tx dmamap.\n",
836 1.3.4.2 yamt device_xname(sc->sc_dev));
837 1.3.4.2 yamt return error;
838 1.3.4.2 yamt }
839 1.3.4.2 yamt }
840 1.3.4.2 yamt
841 1.3.4.2 yamt return 0;
842 1.3.4.2 yamt }
843 1.3.4.2 yamt
844 1.3.4.2 yamt static void
845 1.3.4.2 yamt ale_dma_free(struct ale_softc *sc)
846 1.3.4.2 yamt {
847 1.3.4.2 yamt struct ale_txdesc *txd;
848 1.3.4.2 yamt int i;
849 1.3.4.2 yamt
850 1.3.4.2 yamt /* Tx buffers. */
851 1.3.4.2 yamt for (i = 0; i < ALE_TX_RING_CNT; i++) {
852 1.3.4.2 yamt txd = &sc->ale_cdata.ale_txdesc[i];
853 1.3.4.2 yamt if (txd->tx_dmamap != NULL) {
854 1.3.4.2 yamt bus_dmamap_destroy(sc->sc_dmat, txd->tx_dmamap);
855 1.3.4.2 yamt txd->tx_dmamap = NULL;
856 1.3.4.2 yamt }
857 1.3.4.2 yamt }
858 1.3.4.2 yamt
859 1.3.4.2 yamt /* Tx descriptor ring. */
860 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_ring_map != NULL)
861 1.3.4.2 yamt bus_dmamap_unload(sc->sc_dmat, sc->ale_cdata.ale_tx_ring_map);
862 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_ring_map != NULL &&
863 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring != NULL)
864 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
865 1.3.4.2 yamt &sc->ale_cdata.ale_tx_ring_seg, 1);
866 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring = NULL;
867 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring_map = NULL;
868 1.3.4.2 yamt
869 1.3.4.2 yamt /* Rx page block. */
870 1.3.4.2 yamt for (i = 0; i < ALE_RX_PAGES; i++) {
871 1.3.4.2 yamt if (sc->ale_cdata.ale_rx_page[i].page_map != NULL)
872 1.3.4.2 yamt bus_dmamap_unload(sc->sc_dmat,
873 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_map);
874 1.3.4.2 yamt if (sc->ale_cdata.ale_rx_page[i].page_map != NULL &&
875 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_addr != NULL)
876 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
877 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].page_seg, 1);
878 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_addr = NULL;
879 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].page_map = NULL;
880 1.3.4.2 yamt }
881 1.3.4.2 yamt
882 1.3.4.2 yamt /* Rx CMB. */
883 1.3.4.2 yamt for (i = 0; i < ALE_RX_PAGES; i++) {
884 1.3.4.2 yamt if (sc->ale_cdata.ale_rx_page[i].cmb_map != NULL)
885 1.3.4.2 yamt bus_dmamap_unload(sc->sc_dmat,
886 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_map);
887 1.3.4.2 yamt if (sc->ale_cdata.ale_rx_page[i].cmb_map != NULL &&
888 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_addr != NULL)
889 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
890 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[i].cmb_seg, 1);
891 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_addr = NULL;
892 1.3.4.2 yamt sc->ale_cdata.ale_rx_page[i].cmb_map = NULL;
893 1.3.4.2 yamt }
894 1.3.4.2 yamt
895 1.3.4.2 yamt /* Tx CMB. */
896 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_cmb_map != NULL)
897 1.3.4.2 yamt bus_dmamap_unload(sc->sc_dmat, sc->ale_cdata.ale_tx_cmb_map);
898 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_cmb_map != NULL &&
899 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb != NULL)
900 1.3.4.2 yamt bus_dmamem_free(sc->sc_dmat,
901 1.3.4.2 yamt &sc->ale_cdata.ale_tx_cmb_seg, 1);
902 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb = NULL;
903 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb_map = NULL;
904 1.3.4.2 yamt
905 1.3.4.2 yamt }
906 1.3.4.2 yamt
907 1.3.4.2 yamt static int
908 1.3.4.2 yamt ale_encap(struct ale_softc *sc, struct mbuf **m_head)
909 1.3.4.2 yamt {
910 1.3.4.2 yamt struct ale_txdesc *txd, *txd_last;
911 1.3.4.2 yamt struct tx_desc *desc;
912 1.3.4.2 yamt struct mbuf *m;
913 1.3.4.2 yamt bus_dmamap_t map;
914 1.3.4.2 yamt uint32_t cflags, poff, vtag;
915 1.3.4.2 yamt int error, i, nsegs, prod;
916 1.3.4.2 yamt #if NVLAN > 0
917 1.3.4.2 yamt struct m_tag *mtag;
918 1.3.4.2 yamt #endif
919 1.3.4.2 yamt
920 1.3.4.2 yamt m = *m_head;
921 1.3.4.2 yamt cflags = vtag = 0;
922 1.3.4.2 yamt poff = 0;
923 1.3.4.2 yamt
924 1.3.4.2 yamt prod = sc->ale_cdata.ale_tx_prod;
925 1.3.4.2 yamt txd = &sc->ale_cdata.ale_txdesc[prod];
926 1.3.4.2 yamt txd_last = txd;
927 1.3.4.2 yamt map = txd->tx_dmamap;
928 1.3.4.2 yamt
929 1.3.4.2 yamt error = bus_dmamap_load_mbuf(sc->sc_dmat, map, *m_head, BUS_DMA_NOWAIT);
930 1.3.4.2 yamt if (error == EFBIG) {
931 1.3.4.2 yamt error = 0;
932 1.3.4.2 yamt
933 1.3.4.5 yamt *m_head = m_pullup(*m_head, MHLEN);
934 1.3.4.5 yamt if (*m_head == NULL) {
935 1.3.4.2 yamt printf("%s: can't defrag TX mbuf\n",
936 1.3.4.2 yamt device_xname(sc->sc_dev));
937 1.3.4.2 yamt return ENOBUFS;
938 1.3.4.2 yamt }
939 1.3.4.2 yamt
940 1.3.4.2 yamt error = bus_dmamap_load_mbuf(sc->sc_dmat, map, *m_head,
941 1.3.4.2 yamt BUS_DMA_NOWAIT);
942 1.3.4.2 yamt
943 1.3.4.2 yamt if (error != 0) {
944 1.3.4.2 yamt printf("%s: could not load defragged TX mbuf\n",
945 1.3.4.2 yamt device_xname(sc->sc_dev));
946 1.3.4.2 yamt m_freem(*m_head);
947 1.3.4.2 yamt *m_head = NULL;
948 1.3.4.2 yamt return error;
949 1.3.4.2 yamt }
950 1.3.4.2 yamt } else if (error) {
951 1.3.4.2 yamt printf("%s: could not load TX mbuf\n", device_xname(sc->sc_dev));
952 1.3.4.2 yamt return error;
953 1.3.4.2 yamt }
954 1.3.4.2 yamt
955 1.3.4.2 yamt nsegs = map->dm_nsegs;
956 1.3.4.2 yamt
957 1.3.4.2 yamt if (nsegs == 0) {
958 1.3.4.2 yamt m_freem(*m_head);
959 1.3.4.2 yamt *m_head = NULL;
960 1.3.4.2 yamt return EIO;
961 1.3.4.2 yamt }
962 1.3.4.2 yamt
963 1.3.4.2 yamt /* Check descriptor overrun. */
964 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_cnt + nsegs >= ALE_TX_RING_CNT - 2) {
965 1.3.4.2 yamt bus_dmamap_unload(sc->sc_dmat, map);
966 1.3.4.2 yamt return ENOBUFS;
967 1.3.4.2 yamt }
968 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
969 1.3.4.2 yamt BUS_DMASYNC_PREWRITE);
970 1.3.4.2 yamt
971 1.3.4.2 yamt m = *m_head;
972 1.3.4.2 yamt /* Configure Tx checksum offload. */
973 1.3.4.2 yamt if ((m->m_pkthdr.csum_flags & ALE_CSUM_FEATURES) != 0) {
974 1.3.4.2 yamt /*
975 1.3.4.2 yamt * AR81xx supports Tx custom checksum offload feature
976 1.3.4.2 yamt * that offloads single 16bit checksum computation.
977 1.3.4.2 yamt * So you can choose one among IP, TCP and UDP.
978 1.3.4.2 yamt * Normally driver sets checksum start/insertion
979 1.3.4.2 yamt * position from the information of TCP/UDP frame as
980 1.3.4.2 yamt * TCP/UDP checksum takes more time than that of IP.
981 1.3.4.2 yamt * However it seems that custom checksum offload
982 1.3.4.2 yamt * requires 4 bytes aligned Tx buffers due to hardware
983 1.3.4.2 yamt * bug.
984 1.3.4.2 yamt * AR81xx also supports explicit Tx checksum computation
985 1.3.4.2 yamt * if it is told that the size of IP header and TCP
986 1.3.4.2 yamt * header(for UDP, the header size does not matter
987 1.3.4.2 yamt * because it's fixed length). However with this scheme
988 1.3.4.2 yamt * TSO does not work so you have to choose one either
989 1.3.4.2 yamt * TSO or explicit Tx checksum offload. I chosen TSO
990 1.3.4.2 yamt * plus custom checksum offload with work-around which
991 1.3.4.2 yamt * will cover most common usage for this consumer
992 1.3.4.2 yamt * ethernet controller. The work-around takes a lot of
993 1.3.4.2 yamt * CPU cycles if Tx buffer is not aligned on 4 bytes
994 1.3.4.2 yamt * boundary, though.
995 1.3.4.2 yamt */
996 1.3.4.2 yamt cflags |= ALE_TD_CXSUM;
997 1.3.4.2 yamt /* Set checksum start offset. */
998 1.3.4.2 yamt cflags |= (poff << ALE_TD_CSUM_PLOADOFFSET_SHIFT);
999 1.3.4.2 yamt }
1000 1.3.4.2 yamt
1001 1.3.4.2 yamt #if NVLAN > 0
1002 1.3.4.2 yamt /* Configure VLAN hardware tag insertion. */
1003 1.3.4.2 yamt if ((mtag = VLAN_OUTPUT_TAG(&sc->sc_ec, m))) {
1004 1.3.4.2 yamt vtag = ALE_TX_VLAN_TAG(htons(VLAN_TAG_VALUE(mtag)));
1005 1.3.4.2 yamt vtag = ((vtag << ALE_TD_VLAN_SHIFT) & ALE_TD_VLAN_MASK);
1006 1.3.4.2 yamt cflags |= ALE_TD_INSERT_VLAN_TAG;
1007 1.3.4.2 yamt }
1008 1.3.4.2 yamt #endif
1009 1.3.4.2 yamt
1010 1.3.4.2 yamt desc = NULL;
1011 1.3.4.2 yamt for (i = 0; i < nsegs; i++) {
1012 1.3.4.2 yamt desc = &sc->ale_cdata.ale_tx_ring[prod];
1013 1.3.4.2 yamt desc->addr = htole64(map->dm_segs[i].ds_addr);
1014 1.3.4.2 yamt desc->len =
1015 1.3.4.2 yamt htole32(ALE_TX_BYTES(map->dm_segs[i].ds_len) | vtag);
1016 1.3.4.2 yamt desc->flags = htole32(cflags);
1017 1.3.4.2 yamt sc->ale_cdata.ale_tx_cnt++;
1018 1.3.4.2 yamt ALE_DESC_INC(prod, ALE_TX_RING_CNT);
1019 1.3.4.2 yamt }
1020 1.3.4.2 yamt /* Update producer index. */
1021 1.3.4.2 yamt sc->ale_cdata.ale_tx_prod = prod;
1022 1.3.4.2 yamt
1023 1.3.4.2 yamt /* Finally set EOP on the last descriptor. */
1024 1.3.4.2 yamt prod = (prod + ALE_TX_RING_CNT - 1) % ALE_TX_RING_CNT;
1025 1.3.4.2 yamt desc = &sc->ale_cdata.ale_tx_ring[prod];
1026 1.3.4.2 yamt desc->flags |= htole32(ALE_TD_EOP);
1027 1.3.4.2 yamt
1028 1.3.4.2 yamt /* Swap dmamap of the first and the last. */
1029 1.3.4.2 yamt txd = &sc->ale_cdata.ale_txdesc[prod];
1030 1.3.4.2 yamt map = txd_last->tx_dmamap;
1031 1.3.4.2 yamt txd_last->tx_dmamap = txd->tx_dmamap;
1032 1.3.4.2 yamt txd->tx_dmamap = map;
1033 1.3.4.2 yamt txd->tx_m = m;
1034 1.3.4.2 yamt
1035 1.3.4.2 yamt /* Sync descriptors. */
1036 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, sc->ale_cdata.ale_tx_ring_map, 0,
1037 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1038 1.3.4.2 yamt
1039 1.3.4.2 yamt return 0;
1040 1.3.4.2 yamt }
1041 1.3.4.2 yamt
1042 1.3.4.2 yamt static void
1043 1.3.4.2 yamt ale_start(struct ifnet *ifp)
1044 1.3.4.2 yamt {
1045 1.3.4.2 yamt struct ale_softc *sc = ifp->if_softc;
1046 1.3.4.2 yamt struct mbuf *m_head;
1047 1.3.4.2 yamt int enq;
1048 1.3.4.2 yamt
1049 1.3.4.2 yamt if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
1050 1.3.4.2 yamt return;
1051 1.3.4.2 yamt
1052 1.3.4.2 yamt /* Reclaim transmitted frames. */
1053 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_cnt >= ALE_TX_DESC_HIWAT)
1054 1.3.4.2 yamt ale_txeof(sc);
1055 1.3.4.2 yamt
1056 1.3.4.2 yamt enq = 0;
1057 1.3.4.2 yamt for (;;) {
1058 1.3.4.2 yamt IFQ_DEQUEUE(&ifp->if_snd, m_head);
1059 1.3.4.2 yamt if (m_head == NULL)
1060 1.3.4.2 yamt break;
1061 1.3.4.2 yamt
1062 1.3.4.2 yamt /*
1063 1.3.4.2 yamt * Pack the data into the transmit ring. If we
1064 1.3.4.2 yamt * don't have room, set the OACTIVE flag and wait
1065 1.3.4.2 yamt * for the NIC to drain the ring.
1066 1.3.4.2 yamt */
1067 1.3.4.2 yamt if (ale_encap(sc, &m_head)) {
1068 1.3.4.2 yamt if (m_head == NULL)
1069 1.3.4.2 yamt break;
1070 1.3.4.5 yamt IF_PREPEND(&ifp->if_snd, m_head);
1071 1.3.4.2 yamt ifp->if_flags |= IFF_OACTIVE;
1072 1.3.4.2 yamt break;
1073 1.3.4.2 yamt }
1074 1.3.4.2 yamt enq = 1;
1075 1.3.4.2 yamt
1076 1.3.4.2 yamt /*
1077 1.3.4.2 yamt * If there's a BPF listener, bounce a copy of this frame
1078 1.3.4.2 yamt * to him.
1079 1.3.4.2 yamt */
1080 1.3.4.6 yamt bpf_mtap(ifp, m_head);
1081 1.3.4.2 yamt }
1082 1.3.4.2 yamt
1083 1.3.4.2 yamt if (enq) {
1084 1.3.4.2 yamt /* Kick. */
1085 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MBOX_TPD_PROD_IDX,
1086 1.3.4.2 yamt sc->ale_cdata.ale_tx_prod);
1087 1.3.4.2 yamt
1088 1.3.4.2 yamt /* Set a timeout in case the chip goes out to lunch. */
1089 1.3.4.2 yamt ifp->if_timer = ALE_TX_TIMEOUT;
1090 1.3.4.2 yamt }
1091 1.3.4.2 yamt }
1092 1.3.4.2 yamt
1093 1.3.4.2 yamt static void
1094 1.3.4.2 yamt ale_watchdog(struct ifnet *ifp)
1095 1.3.4.2 yamt {
1096 1.3.4.2 yamt struct ale_softc *sc = ifp->if_softc;
1097 1.3.4.2 yamt
1098 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_LINK) == 0) {
1099 1.3.4.2 yamt printf("%s: watchdog timeout (missed link)\n",
1100 1.3.4.2 yamt device_xname(sc->sc_dev));
1101 1.3.4.2 yamt ifp->if_oerrors++;
1102 1.3.4.2 yamt ale_init(ifp);
1103 1.3.4.2 yamt return;
1104 1.3.4.2 yamt }
1105 1.3.4.2 yamt
1106 1.3.4.2 yamt printf("%s: watchdog timeout\n", device_xname(sc->sc_dev));
1107 1.3.4.2 yamt ifp->if_oerrors++;
1108 1.3.4.2 yamt ale_init(ifp);
1109 1.3.4.2 yamt
1110 1.3.4.2 yamt if (!IFQ_IS_EMPTY(&ifp->if_snd))
1111 1.3.4.2 yamt ale_start(ifp);
1112 1.3.4.2 yamt }
1113 1.3.4.2 yamt
1114 1.3.4.2 yamt static int
1115 1.3.4.2 yamt ale_ioctl(struct ifnet *ifp, u_long cmd, void *data)
1116 1.3.4.2 yamt {
1117 1.3.4.2 yamt struct ale_softc *sc = ifp->if_softc;
1118 1.3.4.2 yamt int s, error;
1119 1.3.4.2 yamt
1120 1.3.4.2 yamt s = splnet();
1121 1.3.4.2 yamt
1122 1.3.4.2 yamt error = ether_ioctl(ifp, cmd, data);
1123 1.3.4.2 yamt if (error == ENETRESET) {
1124 1.3.4.2 yamt if (ifp->if_flags & IFF_RUNNING)
1125 1.3.4.2 yamt ale_rxfilter(sc);
1126 1.3.4.2 yamt error = 0;
1127 1.3.4.2 yamt }
1128 1.3.4.2 yamt
1129 1.3.4.2 yamt splx(s);
1130 1.3.4.2 yamt return error;
1131 1.3.4.2 yamt }
1132 1.3.4.2 yamt
1133 1.3.4.2 yamt static void
1134 1.3.4.2 yamt ale_mac_config(struct ale_softc *sc)
1135 1.3.4.2 yamt {
1136 1.3.4.2 yamt struct mii_data *mii;
1137 1.3.4.2 yamt uint32_t reg;
1138 1.3.4.2 yamt
1139 1.3.4.2 yamt mii = &sc->sc_miibus;
1140 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_MAC_CFG);
1141 1.3.4.2 yamt reg &= ~(MAC_CFG_FULL_DUPLEX | MAC_CFG_TX_FC | MAC_CFG_RX_FC |
1142 1.3.4.2 yamt MAC_CFG_SPEED_MASK);
1143 1.3.4.2 yamt
1144 1.3.4.2 yamt /* Reprogram MAC with resolved speed/duplex. */
1145 1.3.4.2 yamt switch (IFM_SUBTYPE(mii->mii_media_active)) {
1146 1.3.4.2 yamt case IFM_10_T:
1147 1.3.4.2 yamt case IFM_100_TX:
1148 1.3.4.2 yamt reg |= MAC_CFG_SPEED_10_100;
1149 1.3.4.2 yamt break;
1150 1.3.4.2 yamt case IFM_1000_T:
1151 1.3.4.2 yamt reg |= MAC_CFG_SPEED_1000;
1152 1.3.4.2 yamt break;
1153 1.3.4.2 yamt }
1154 1.3.4.2 yamt if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
1155 1.3.4.2 yamt reg |= MAC_CFG_FULL_DUPLEX;
1156 1.3.4.2 yamt if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
1157 1.3.4.2 yamt reg |= MAC_CFG_TX_FC;
1158 1.3.4.2 yamt if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
1159 1.3.4.2 yamt reg |= MAC_CFG_RX_FC;
1160 1.3.4.2 yamt }
1161 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAC_CFG, reg);
1162 1.3.4.2 yamt }
1163 1.3.4.2 yamt
1164 1.3.4.2 yamt static void
1165 1.3.4.2 yamt ale_stats_clear(struct ale_softc *sc)
1166 1.3.4.2 yamt {
1167 1.3.4.2 yamt struct smb sb;
1168 1.3.4.2 yamt uint32_t *reg;
1169 1.3.4.2 yamt int i;
1170 1.3.4.2 yamt
1171 1.3.4.2 yamt for (reg = &sb.rx_frames, i = 0; reg <= &sb.rx_pkts_filtered; reg++) {
1172 1.3.4.2 yamt CSR_READ_4(sc, ALE_RX_MIB_BASE + i);
1173 1.3.4.2 yamt i += sizeof(uint32_t);
1174 1.3.4.2 yamt }
1175 1.3.4.2 yamt /* Read Tx statistics. */
1176 1.3.4.2 yamt for (reg = &sb.tx_frames, i = 0; reg <= &sb.tx_mcast_bytes; reg++) {
1177 1.3.4.2 yamt CSR_READ_4(sc, ALE_TX_MIB_BASE + i);
1178 1.3.4.2 yamt i += sizeof(uint32_t);
1179 1.3.4.2 yamt }
1180 1.3.4.2 yamt }
1181 1.3.4.2 yamt
1182 1.3.4.2 yamt static void
1183 1.3.4.2 yamt ale_stats_update(struct ale_softc *sc)
1184 1.3.4.2 yamt {
1185 1.3.4.2 yamt struct ifnet *ifp = &sc->sc_ec.ec_if;
1186 1.3.4.2 yamt struct ale_hw_stats *stat;
1187 1.3.4.2 yamt struct smb sb, *smb;
1188 1.3.4.2 yamt uint32_t *reg;
1189 1.3.4.2 yamt int i;
1190 1.3.4.2 yamt
1191 1.3.4.2 yamt stat = &sc->ale_stats;
1192 1.3.4.2 yamt smb = &sb;
1193 1.3.4.2 yamt
1194 1.3.4.2 yamt /* Read Rx statistics. */
1195 1.3.4.2 yamt for (reg = &sb.rx_frames, i = 0; reg <= &sb.rx_pkts_filtered; reg++) {
1196 1.3.4.2 yamt *reg = CSR_READ_4(sc, ALE_RX_MIB_BASE + i);
1197 1.3.4.2 yamt i += sizeof(uint32_t);
1198 1.3.4.2 yamt }
1199 1.3.4.2 yamt /* Read Tx statistics. */
1200 1.3.4.2 yamt for (reg = &sb.tx_frames, i = 0; reg <= &sb.tx_mcast_bytes; reg++) {
1201 1.3.4.2 yamt *reg = CSR_READ_4(sc, ALE_TX_MIB_BASE + i);
1202 1.3.4.2 yamt i += sizeof(uint32_t);
1203 1.3.4.2 yamt }
1204 1.3.4.2 yamt
1205 1.3.4.2 yamt /* Rx stats. */
1206 1.3.4.2 yamt stat->rx_frames += smb->rx_frames;
1207 1.3.4.2 yamt stat->rx_bcast_frames += smb->rx_bcast_frames;
1208 1.3.4.2 yamt stat->rx_mcast_frames += smb->rx_mcast_frames;
1209 1.3.4.2 yamt stat->rx_pause_frames += smb->rx_pause_frames;
1210 1.3.4.2 yamt stat->rx_control_frames += smb->rx_control_frames;
1211 1.3.4.2 yamt stat->rx_crcerrs += smb->rx_crcerrs;
1212 1.3.4.2 yamt stat->rx_lenerrs += smb->rx_lenerrs;
1213 1.3.4.2 yamt stat->rx_bytes += smb->rx_bytes;
1214 1.3.4.2 yamt stat->rx_runts += smb->rx_runts;
1215 1.3.4.2 yamt stat->rx_fragments += smb->rx_fragments;
1216 1.3.4.2 yamt stat->rx_pkts_64 += smb->rx_pkts_64;
1217 1.3.4.2 yamt stat->rx_pkts_65_127 += smb->rx_pkts_65_127;
1218 1.3.4.2 yamt stat->rx_pkts_128_255 += smb->rx_pkts_128_255;
1219 1.3.4.2 yamt stat->rx_pkts_256_511 += smb->rx_pkts_256_511;
1220 1.3.4.2 yamt stat->rx_pkts_512_1023 += smb->rx_pkts_512_1023;
1221 1.3.4.2 yamt stat->rx_pkts_1024_1518 += smb->rx_pkts_1024_1518;
1222 1.3.4.2 yamt stat->rx_pkts_1519_max += smb->rx_pkts_1519_max;
1223 1.3.4.2 yamt stat->rx_pkts_truncated += smb->rx_pkts_truncated;
1224 1.3.4.2 yamt stat->rx_fifo_oflows += smb->rx_fifo_oflows;
1225 1.3.4.2 yamt stat->rx_rrs_errs += smb->rx_rrs_errs;
1226 1.3.4.2 yamt stat->rx_alignerrs += smb->rx_alignerrs;
1227 1.3.4.2 yamt stat->rx_bcast_bytes += smb->rx_bcast_bytes;
1228 1.3.4.2 yamt stat->rx_mcast_bytes += smb->rx_mcast_bytes;
1229 1.3.4.2 yamt stat->rx_pkts_filtered += smb->rx_pkts_filtered;
1230 1.3.4.2 yamt
1231 1.3.4.2 yamt /* Tx stats. */
1232 1.3.4.2 yamt stat->tx_frames += smb->tx_frames;
1233 1.3.4.2 yamt stat->tx_bcast_frames += smb->tx_bcast_frames;
1234 1.3.4.2 yamt stat->tx_mcast_frames += smb->tx_mcast_frames;
1235 1.3.4.2 yamt stat->tx_pause_frames += smb->tx_pause_frames;
1236 1.3.4.2 yamt stat->tx_excess_defer += smb->tx_excess_defer;
1237 1.3.4.2 yamt stat->tx_control_frames += smb->tx_control_frames;
1238 1.3.4.2 yamt stat->tx_deferred += smb->tx_deferred;
1239 1.3.4.2 yamt stat->tx_bytes += smb->tx_bytes;
1240 1.3.4.2 yamt stat->tx_pkts_64 += smb->tx_pkts_64;
1241 1.3.4.2 yamt stat->tx_pkts_65_127 += smb->tx_pkts_65_127;
1242 1.3.4.2 yamt stat->tx_pkts_128_255 += smb->tx_pkts_128_255;
1243 1.3.4.2 yamt stat->tx_pkts_256_511 += smb->tx_pkts_256_511;
1244 1.3.4.2 yamt stat->tx_pkts_512_1023 += smb->tx_pkts_512_1023;
1245 1.3.4.2 yamt stat->tx_pkts_1024_1518 += smb->tx_pkts_1024_1518;
1246 1.3.4.2 yamt stat->tx_pkts_1519_max += smb->tx_pkts_1519_max;
1247 1.3.4.2 yamt stat->tx_single_colls += smb->tx_single_colls;
1248 1.3.4.2 yamt stat->tx_multi_colls += smb->tx_multi_colls;
1249 1.3.4.2 yamt stat->tx_late_colls += smb->tx_late_colls;
1250 1.3.4.2 yamt stat->tx_excess_colls += smb->tx_excess_colls;
1251 1.3.4.2 yamt stat->tx_abort += smb->tx_abort;
1252 1.3.4.2 yamt stat->tx_underrun += smb->tx_underrun;
1253 1.3.4.2 yamt stat->tx_desc_underrun += smb->tx_desc_underrun;
1254 1.3.4.2 yamt stat->tx_lenerrs += smb->tx_lenerrs;
1255 1.3.4.2 yamt stat->tx_pkts_truncated += smb->tx_pkts_truncated;
1256 1.3.4.2 yamt stat->tx_bcast_bytes += smb->tx_bcast_bytes;
1257 1.3.4.2 yamt stat->tx_mcast_bytes += smb->tx_mcast_bytes;
1258 1.3.4.2 yamt
1259 1.3.4.2 yamt /* Update counters in ifnet. */
1260 1.3.4.2 yamt ifp->if_opackets += smb->tx_frames;
1261 1.3.4.2 yamt
1262 1.3.4.2 yamt ifp->if_collisions += smb->tx_single_colls +
1263 1.3.4.2 yamt smb->tx_multi_colls * 2 + smb->tx_late_colls +
1264 1.3.4.2 yamt smb->tx_abort * HDPX_CFG_RETRY_DEFAULT;
1265 1.3.4.2 yamt
1266 1.3.4.2 yamt /*
1267 1.3.4.2 yamt * XXX
1268 1.3.4.2 yamt * tx_pkts_truncated counter looks suspicious. It constantly
1269 1.3.4.2 yamt * increments with no sign of Tx errors. This may indicate
1270 1.3.4.2 yamt * the counter name is not correct one so I've removed the
1271 1.3.4.2 yamt * counter in output errors.
1272 1.3.4.2 yamt */
1273 1.3.4.2 yamt ifp->if_oerrors += smb->tx_abort + smb->tx_late_colls +
1274 1.3.4.2 yamt smb->tx_underrun;
1275 1.3.4.2 yamt
1276 1.3.4.2 yamt ifp->if_ipackets += smb->rx_frames;
1277 1.3.4.2 yamt
1278 1.3.4.2 yamt ifp->if_ierrors += smb->rx_crcerrs + smb->rx_lenerrs +
1279 1.3.4.2 yamt smb->rx_runts + smb->rx_pkts_truncated +
1280 1.3.4.2 yamt smb->rx_fifo_oflows + smb->rx_rrs_errs +
1281 1.3.4.2 yamt smb->rx_alignerrs;
1282 1.3.4.2 yamt }
1283 1.3.4.2 yamt
1284 1.3.4.2 yamt static int
1285 1.3.4.2 yamt ale_intr(void *xsc)
1286 1.3.4.2 yamt {
1287 1.3.4.2 yamt struct ale_softc *sc = xsc;
1288 1.3.4.2 yamt struct ifnet *ifp = &sc->sc_ec.ec_if;
1289 1.3.4.2 yamt uint32_t status;
1290 1.3.4.2 yamt
1291 1.3.4.2 yamt status = CSR_READ_4(sc, ALE_INTR_STATUS);
1292 1.3.4.2 yamt if ((status & ALE_INTRS) == 0)
1293 1.3.4.2 yamt return 0;
1294 1.3.4.2 yamt
1295 1.3.4.2 yamt /* Acknowledge and disable interrupts. */
1296 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_STATUS, status | INTR_DIS_INT);
1297 1.3.4.2 yamt
1298 1.3.4.2 yamt if (ifp->if_flags & IFF_RUNNING) {
1299 1.3.4.2 yamt int error;
1300 1.3.4.2 yamt
1301 1.3.4.2 yamt error = ale_rxeof(sc);
1302 1.3.4.2 yamt if (error) {
1303 1.3.4.2 yamt sc->ale_stats.reset_brk_seq++;
1304 1.3.4.2 yamt ale_init(ifp);
1305 1.3.4.2 yamt return 0;
1306 1.3.4.2 yamt }
1307 1.3.4.2 yamt
1308 1.3.4.2 yamt if (status & (INTR_DMA_RD_TO_RST | INTR_DMA_WR_TO_RST)) {
1309 1.3.4.2 yamt if (status & INTR_DMA_RD_TO_RST)
1310 1.3.4.2 yamt printf("%s: DMA read error! -- resetting\n",
1311 1.3.4.2 yamt device_xname(sc->sc_dev));
1312 1.3.4.2 yamt if (status & INTR_DMA_WR_TO_RST)
1313 1.3.4.2 yamt printf("%s: DMA write error! -- resetting\n",
1314 1.3.4.2 yamt device_xname(sc->sc_dev));
1315 1.3.4.2 yamt ale_init(ifp);
1316 1.3.4.2 yamt return 0;
1317 1.3.4.2 yamt }
1318 1.3.4.2 yamt
1319 1.3.4.2 yamt ale_txeof(sc);
1320 1.3.4.2 yamt if (!IFQ_IS_EMPTY(&ifp->if_snd))
1321 1.3.4.2 yamt ale_start(ifp);
1322 1.3.4.2 yamt }
1323 1.3.4.2 yamt
1324 1.3.4.2 yamt /* Re-enable interrupts. */
1325 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_STATUS, 0x7FFFFFFF);
1326 1.3.4.2 yamt return 1;
1327 1.3.4.2 yamt }
1328 1.3.4.2 yamt
1329 1.3.4.2 yamt static void
1330 1.3.4.2 yamt ale_txeof(struct ale_softc *sc)
1331 1.3.4.2 yamt {
1332 1.3.4.2 yamt struct ifnet *ifp = &sc->sc_ec.ec_if;
1333 1.3.4.2 yamt struct ale_txdesc *txd;
1334 1.3.4.2 yamt uint32_t cons, prod;
1335 1.3.4.2 yamt int prog;
1336 1.3.4.2 yamt
1337 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_cnt == 0)
1338 1.3.4.2 yamt return;
1339 1.3.4.2 yamt
1340 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, sc->ale_cdata.ale_tx_ring_map, 0,
1341 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
1342 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_TXCMB_BUG) == 0) {
1343 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, sc->ale_cdata.ale_tx_cmb_map, 0,
1344 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb_map->dm_mapsize,
1345 1.3.4.2 yamt BUS_DMASYNC_POSTREAD);
1346 1.3.4.2 yamt prod = *sc->ale_cdata.ale_tx_cmb & TPD_CNT_MASK;
1347 1.3.4.2 yamt } else
1348 1.3.4.2 yamt prod = CSR_READ_2(sc, ALE_TPD_CONS_IDX);
1349 1.3.4.2 yamt cons = sc->ale_cdata.ale_tx_cons;
1350 1.3.4.2 yamt /*
1351 1.3.4.2 yamt * Go through our Tx list and free mbufs for those
1352 1.3.4.2 yamt * frames which have been transmitted.
1353 1.3.4.2 yamt */
1354 1.3.4.2 yamt for (prog = 0; cons != prod; prog++,
1355 1.3.4.2 yamt ALE_DESC_INC(cons, ALE_TX_RING_CNT)) {
1356 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_cnt <= 0)
1357 1.3.4.2 yamt break;
1358 1.3.4.2 yamt prog++;
1359 1.3.4.2 yamt ifp->if_flags &= ~IFF_OACTIVE;
1360 1.3.4.2 yamt sc->ale_cdata.ale_tx_cnt--;
1361 1.3.4.2 yamt txd = &sc->ale_cdata.ale_txdesc[cons];
1362 1.3.4.2 yamt if (txd->tx_m != NULL) {
1363 1.3.4.2 yamt /* Reclaim transmitted mbufs. */
1364 1.3.4.2 yamt bus_dmamap_unload(sc->sc_dmat, txd->tx_dmamap);
1365 1.3.4.2 yamt m_freem(txd->tx_m);
1366 1.3.4.2 yamt txd->tx_m = NULL;
1367 1.3.4.2 yamt }
1368 1.3.4.2 yamt }
1369 1.3.4.2 yamt
1370 1.3.4.2 yamt if (prog > 0) {
1371 1.3.4.2 yamt sc->ale_cdata.ale_tx_cons = cons;
1372 1.3.4.2 yamt /*
1373 1.3.4.2 yamt * Unarm watchdog timer only when there is no pending
1374 1.3.4.2 yamt * Tx descriptors in queue.
1375 1.3.4.2 yamt */
1376 1.3.4.2 yamt if (sc->ale_cdata.ale_tx_cnt == 0)
1377 1.3.4.2 yamt ifp->if_timer = 0;
1378 1.3.4.2 yamt }
1379 1.3.4.2 yamt }
1380 1.3.4.2 yamt
1381 1.3.4.2 yamt static void
1382 1.3.4.2 yamt ale_rx_update_page(struct ale_softc *sc, struct ale_rx_page **page,
1383 1.3.4.2 yamt uint32_t length, uint32_t *prod)
1384 1.3.4.2 yamt {
1385 1.3.4.2 yamt struct ale_rx_page *rx_page;
1386 1.3.4.2 yamt
1387 1.3.4.2 yamt rx_page = *page;
1388 1.3.4.2 yamt /* Update consumer position. */
1389 1.3.4.2 yamt rx_page->cons += roundup(length + sizeof(struct rx_rs),
1390 1.3.4.2 yamt ALE_RX_PAGE_ALIGN);
1391 1.3.4.2 yamt if (rx_page->cons >= ALE_RX_PAGE_SZ) {
1392 1.3.4.2 yamt /*
1393 1.3.4.2 yamt * End of Rx page reached, let hardware reuse
1394 1.3.4.2 yamt * this page.
1395 1.3.4.2 yamt */
1396 1.3.4.2 yamt rx_page->cons = 0;
1397 1.3.4.2 yamt *rx_page->cmb_addr = 0;
1398 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, rx_page->cmb_map, 0,
1399 1.3.4.2 yamt rx_page->cmb_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1400 1.3.4.2 yamt CSR_WRITE_1(sc, ALE_RXF0_PAGE0 + sc->ale_cdata.ale_rx_curp,
1401 1.3.4.2 yamt RXF_VALID);
1402 1.3.4.2 yamt /* Switch to alternate Rx page. */
1403 1.3.4.2 yamt sc->ale_cdata.ale_rx_curp ^= 1;
1404 1.3.4.2 yamt rx_page = *page =
1405 1.3.4.2 yamt &sc->ale_cdata.ale_rx_page[sc->ale_cdata.ale_rx_curp];
1406 1.3.4.2 yamt /* Page flipped, sync CMB and Rx page. */
1407 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, rx_page->page_map, 0,
1408 1.3.4.2 yamt rx_page->page_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
1409 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, rx_page->cmb_map, 0,
1410 1.3.4.2 yamt rx_page->cmb_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
1411 1.3.4.2 yamt /* Sync completed, cache updated producer index. */
1412 1.3.4.2 yamt *prod = *rx_page->cmb_addr;
1413 1.3.4.2 yamt }
1414 1.3.4.2 yamt }
1415 1.3.4.2 yamt
1416 1.3.4.2 yamt
1417 1.3.4.2 yamt /*
1418 1.3.4.2 yamt * It seems that AR81xx controller can compute partial checksum.
1419 1.3.4.2 yamt * The partial checksum value can be used to accelerate checksum
1420 1.3.4.2 yamt * computation for fragmented TCP/UDP packets. Upper network stack
1421 1.3.4.2 yamt * already takes advantage of the partial checksum value in IP
1422 1.3.4.2 yamt * reassembly stage. But I'm not sure the correctness of the
1423 1.3.4.2 yamt * partial hardware checksum assistance due to lack of data sheet.
1424 1.3.4.2 yamt * In addition, the Rx feature of controller that requires copying
1425 1.3.4.2 yamt * for every frames effectively nullifies one of most nice offload
1426 1.3.4.2 yamt * capability of controller.
1427 1.3.4.2 yamt */
1428 1.3.4.2 yamt static void
1429 1.3.4.2 yamt ale_rxcsum(struct ale_softc *sc, struct mbuf *m, uint32_t status)
1430 1.3.4.2 yamt {
1431 1.3.4.2 yamt if (status & ALE_RD_IPCSUM_NOK)
1432 1.3.4.2 yamt m->m_pkthdr.csum_flags |= M_CSUM_IPv4_BAD;
1433 1.3.4.2 yamt
1434 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_RXCSUM_BUG) == 0) {
1435 1.3.4.2 yamt if (((status & ALE_RD_IPV4_FRAG) == 0) &&
1436 1.3.4.2 yamt ((status & (ALE_RD_TCP | ALE_RD_UDP)) != 0) &&
1437 1.3.4.2 yamt (status & ALE_RD_TCP_UDPCSUM_NOK))
1438 1.3.4.2 yamt {
1439 1.3.4.2 yamt m->m_pkthdr.csum_flags |= M_CSUM_TCP_UDP_BAD;
1440 1.3.4.2 yamt }
1441 1.3.4.2 yamt } else {
1442 1.3.4.2 yamt if ((status & (ALE_RD_TCP | ALE_RD_UDP)) != 0) {
1443 1.3.4.2 yamt if (status & ALE_RD_TCP_UDPCSUM_NOK) {
1444 1.3.4.2 yamt m->m_pkthdr.csum_flags |= M_CSUM_TCP_UDP_BAD;
1445 1.3.4.2 yamt }
1446 1.3.4.2 yamt }
1447 1.3.4.2 yamt }
1448 1.3.4.2 yamt /*
1449 1.3.4.2 yamt * Don't mark bad checksum for TCP/UDP frames
1450 1.3.4.2 yamt * as fragmented frames may always have set
1451 1.3.4.2 yamt * bad checksummed bit of frame status.
1452 1.3.4.2 yamt */
1453 1.3.4.2 yamt }
1454 1.3.4.2 yamt
1455 1.3.4.2 yamt /* Process received frames. */
1456 1.3.4.2 yamt static int
1457 1.3.4.2 yamt ale_rxeof(struct ale_softc *sc)
1458 1.3.4.2 yamt {
1459 1.3.4.2 yamt struct ifnet *ifp = &sc->sc_ec.ec_if;
1460 1.3.4.2 yamt struct ale_rx_page *rx_page;
1461 1.3.4.2 yamt struct rx_rs *rs;
1462 1.3.4.2 yamt struct mbuf *m;
1463 1.3.4.2 yamt uint32_t length, prod, seqno, status;
1464 1.3.4.2 yamt int prog;
1465 1.3.4.2 yamt
1466 1.3.4.2 yamt rx_page = &sc->ale_cdata.ale_rx_page[sc->ale_cdata.ale_rx_curp];
1467 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, rx_page->cmb_map, 0,
1468 1.3.4.2 yamt rx_page->cmb_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
1469 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, rx_page->page_map, 0,
1470 1.3.4.2 yamt rx_page->page_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
1471 1.3.4.2 yamt /*
1472 1.3.4.2 yamt * Don't directly access producer index as hardware may
1473 1.3.4.2 yamt * update it while Rx handler is in progress. It would
1474 1.3.4.2 yamt * be even better if there is a way to let hardware
1475 1.3.4.2 yamt * know how far driver processed its received frames.
1476 1.3.4.2 yamt * Alternatively, hardware could provide a way to disable
1477 1.3.4.2 yamt * CMB updates until driver acknowledges the end of CMB
1478 1.3.4.2 yamt * access.
1479 1.3.4.2 yamt */
1480 1.3.4.2 yamt prod = *rx_page->cmb_addr;
1481 1.3.4.2 yamt for (prog = 0; ; prog++) {
1482 1.3.4.2 yamt if (rx_page->cons >= prod)
1483 1.3.4.2 yamt break;
1484 1.3.4.2 yamt rs = (struct rx_rs *)(rx_page->page_addr + rx_page->cons);
1485 1.3.4.2 yamt seqno = ALE_RX_SEQNO(le32toh(rs->seqno));
1486 1.3.4.2 yamt if (sc->ale_cdata.ale_rx_seqno != seqno) {
1487 1.3.4.2 yamt /*
1488 1.3.4.2 yamt * Normally I believe this should not happen unless
1489 1.3.4.2 yamt * severe driver bug or corrupted memory. However
1490 1.3.4.2 yamt * it seems to happen under certain conditions which
1491 1.3.4.2 yamt * is triggered by abrupt Rx events such as initiation
1492 1.3.4.2 yamt * of bulk transfer of remote host. It's not easy to
1493 1.3.4.2 yamt * reproduce this and I doubt it could be related
1494 1.3.4.2 yamt * with FIFO overflow of hardware or activity of Tx
1495 1.3.4.2 yamt * CMB updates. I also remember similar behaviour
1496 1.3.4.2 yamt * seen on RealTek 8139 which uses resembling Rx
1497 1.3.4.2 yamt * scheme.
1498 1.3.4.2 yamt */
1499 1.3.4.2 yamt if (aledebug)
1500 1.3.4.2 yamt printf("%s: garbled seq: %u, expected: %u -- "
1501 1.3.4.2 yamt "resetting!\n", device_xname(sc->sc_dev),
1502 1.3.4.2 yamt seqno, sc->ale_cdata.ale_rx_seqno);
1503 1.3.4.2 yamt return EIO;
1504 1.3.4.2 yamt }
1505 1.3.4.2 yamt /* Frame received. */
1506 1.3.4.2 yamt sc->ale_cdata.ale_rx_seqno++;
1507 1.3.4.2 yamt length = ALE_RX_BYTES(le32toh(rs->length));
1508 1.3.4.2 yamt status = le32toh(rs->flags);
1509 1.3.4.2 yamt if (status & ALE_RD_ERROR) {
1510 1.3.4.2 yamt /*
1511 1.3.4.2 yamt * We want to pass the following frames to upper
1512 1.3.4.2 yamt * layer regardless of error status of Rx return
1513 1.3.4.2 yamt * status.
1514 1.3.4.2 yamt *
1515 1.3.4.2 yamt * o IP/TCP/UDP checksum is bad.
1516 1.3.4.2 yamt * o frame length and protocol specific length
1517 1.3.4.2 yamt * does not match.
1518 1.3.4.2 yamt */
1519 1.3.4.2 yamt if (status & (ALE_RD_CRC | ALE_RD_CODE |
1520 1.3.4.2 yamt ALE_RD_DRIBBLE | ALE_RD_RUNT | ALE_RD_OFLOW |
1521 1.3.4.2 yamt ALE_RD_TRUNC)) {
1522 1.3.4.2 yamt ale_rx_update_page(sc, &rx_page, length, &prod);
1523 1.3.4.2 yamt continue;
1524 1.3.4.2 yamt }
1525 1.3.4.2 yamt }
1526 1.3.4.2 yamt /*
1527 1.3.4.2 yamt * m_devget(9) is major bottle-neck of ale(4)(It comes
1528 1.3.4.2 yamt * from hardware limitation). For jumbo frames we could
1529 1.3.4.2 yamt * get a slightly better performance if driver use
1530 1.3.4.2 yamt * m_getjcl(9) with proper buffer size argument. However
1531 1.3.4.2 yamt * that would make code more complicated and I don't
1532 1.3.4.2 yamt * think users would expect good Rx performance numbers
1533 1.3.4.2 yamt * on these low-end consumer ethernet controller.
1534 1.3.4.2 yamt */
1535 1.3.4.2 yamt m = m_devget((char *)(rs + 1), length - ETHER_CRC_LEN,
1536 1.3.4.2 yamt 0, ifp, NULL);
1537 1.3.4.2 yamt if (m == NULL) {
1538 1.3.4.2 yamt ifp->if_iqdrops++;
1539 1.3.4.2 yamt ale_rx_update_page(sc, &rx_page, length, &prod);
1540 1.3.4.2 yamt continue;
1541 1.3.4.2 yamt }
1542 1.3.4.2 yamt if (status & ALE_RD_IPV4)
1543 1.3.4.2 yamt ale_rxcsum(sc, m, status);
1544 1.3.4.2 yamt #if NVLAN > 0
1545 1.3.4.2 yamt if (status & ALE_RD_VLAN) {
1546 1.3.4.2 yamt uint32_t vtags = ALE_RX_VLAN(le32toh(rs->vtags));
1547 1.3.4.2 yamt VLAN_INPUT_TAG(ifp, m, ALE_RX_VLAN_TAG(vtags), );
1548 1.3.4.2 yamt }
1549 1.3.4.2 yamt #endif
1550 1.3.4.2 yamt
1551 1.3.4.2 yamt
1552 1.3.4.6 yamt bpf_mtap(ifp, m);
1553 1.3.4.2 yamt
1554 1.3.4.2 yamt /* Pass it to upper layer. */
1555 1.3.4.2 yamt ether_input(ifp, m);
1556 1.3.4.2 yamt
1557 1.3.4.2 yamt ale_rx_update_page(sc, &rx_page, length, &prod);
1558 1.3.4.2 yamt }
1559 1.3.4.2 yamt
1560 1.3.4.2 yamt return 0;
1561 1.3.4.2 yamt }
1562 1.3.4.2 yamt
1563 1.3.4.2 yamt static void
1564 1.3.4.2 yamt ale_tick(void *xsc)
1565 1.3.4.2 yamt {
1566 1.3.4.2 yamt struct ale_softc *sc = xsc;
1567 1.3.4.2 yamt struct mii_data *mii = &sc->sc_miibus;
1568 1.3.4.2 yamt int s;
1569 1.3.4.2 yamt
1570 1.3.4.2 yamt s = splnet();
1571 1.3.4.2 yamt mii_tick(mii);
1572 1.3.4.2 yamt ale_stats_update(sc);
1573 1.3.4.2 yamt splx(s);
1574 1.3.4.2 yamt
1575 1.3.4.2 yamt callout_schedule(&sc->sc_tick_ch, hz);
1576 1.3.4.2 yamt }
1577 1.3.4.2 yamt
1578 1.3.4.2 yamt static void
1579 1.3.4.2 yamt ale_reset(struct ale_softc *sc)
1580 1.3.4.2 yamt {
1581 1.3.4.2 yamt uint32_t reg;
1582 1.3.4.2 yamt int i;
1583 1.3.4.2 yamt
1584 1.3.4.2 yamt /* Initialize PCIe module. From Linux. */
1585 1.3.4.2 yamt CSR_WRITE_4(sc, 0x1008, CSR_READ_4(sc, 0x1008) | 0x8000);
1586 1.3.4.2 yamt
1587 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MASTER_CFG, MASTER_RESET);
1588 1.3.4.2 yamt for (i = ALE_RESET_TIMEOUT; i > 0; i--) {
1589 1.3.4.2 yamt DELAY(10);
1590 1.3.4.2 yamt if ((CSR_READ_4(sc, ALE_MASTER_CFG) & MASTER_RESET) == 0)
1591 1.3.4.2 yamt break;
1592 1.3.4.2 yamt }
1593 1.3.4.2 yamt if (i == 0)
1594 1.3.4.2 yamt printf("%s: master reset timeout!\n", device_xname(sc->sc_dev));
1595 1.3.4.2 yamt
1596 1.3.4.2 yamt for (i = ALE_RESET_TIMEOUT; i > 0; i--) {
1597 1.3.4.2 yamt if ((reg = CSR_READ_4(sc, ALE_IDLE_STATUS)) == 0)
1598 1.3.4.2 yamt break;
1599 1.3.4.2 yamt DELAY(10);
1600 1.3.4.2 yamt }
1601 1.3.4.2 yamt
1602 1.3.4.2 yamt if (i == 0)
1603 1.3.4.2 yamt printf("%s: reset timeout(0x%08x)!\n", device_xname(sc->sc_dev),
1604 1.3.4.2 yamt reg);
1605 1.3.4.2 yamt }
1606 1.3.4.2 yamt
1607 1.3.4.2 yamt static int
1608 1.3.4.2 yamt ale_init(struct ifnet *ifp)
1609 1.3.4.2 yamt {
1610 1.3.4.2 yamt struct ale_softc *sc = ifp->if_softc;
1611 1.3.4.2 yamt struct mii_data *mii;
1612 1.3.4.2 yamt uint8_t eaddr[ETHER_ADDR_LEN];
1613 1.3.4.2 yamt bus_addr_t paddr;
1614 1.3.4.2 yamt uint32_t reg, rxf_hi, rxf_lo;
1615 1.3.4.2 yamt
1616 1.3.4.2 yamt /*
1617 1.3.4.2 yamt * Cancel any pending I/O.
1618 1.3.4.2 yamt */
1619 1.3.4.2 yamt ale_stop(ifp, 0);
1620 1.3.4.2 yamt
1621 1.3.4.2 yamt /*
1622 1.3.4.2 yamt * Reset the chip to a known state.
1623 1.3.4.2 yamt */
1624 1.3.4.2 yamt ale_reset(sc);
1625 1.3.4.2 yamt
1626 1.3.4.2 yamt /* Initialize Tx descriptors, DMA memory blocks. */
1627 1.3.4.2 yamt ale_init_rx_pages(sc);
1628 1.3.4.2 yamt ale_init_tx_ring(sc);
1629 1.3.4.2 yamt
1630 1.3.4.2 yamt /* Reprogram the station address. */
1631 1.3.4.2 yamt memcpy(eaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
1632 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_PAR0,
1633 1.3.4.2 yamt eaddr[2] << 24 | eaddr[3] << 16 | eaddr[4] << 8 | eaddr[5]);
1634 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_PAR1, eaddr[0] << 8 | eaddr[1]);
1635 1.3.4.2 yamt
1636 1.3.4.2 yamt /*
1637 1.3.4.2 yamt * Clear WOL status and disable all WOL feature as WOL
1638 1.3.4.2 yamt * would interfere Rx operation under normal environments.
1639 1.3.4.2 yamt */
1640 1.3.4.2 yamt CSR_READ_4(sc, ALE_WOL_CFG);
1641 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_WOL_CFG, 0);
1642 1.3.4.2 yamt
1643 1.3.4.2 yamt /*
1644 1.3.4.2 yamt * Set Tx descriptor/RXF0/CMB base addresses. They share
1645 1.3.4.2 yamt * the same high address part of DMAable region.
1646 1.3.4.2 yamt */
1647 1.3.4.2 yamt paddr = sc->ale_cdata.ale_tx_ring_paddr;
1648 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TPD_ADDR_HI, ALE_ADDR_HI(paddr));
1649 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TPD_ADDR_LO, ALE_ADDR_LO(paddr));
1650 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TPD_CNT,
1651 1.3.4.2 yamt (ALE_TX_RING_CNT << TPD_CNT_SHIFT) & TPD_CNT_MASK);
1652 1.3.4.2 yamt
1653 1.3.4.2 yamt /* Set Rx page base address, note we use single queue. */
1654 1.3.4.2 yamt paddr = sc->ale_cdata.ale_rx_page[0].page_paddr;
1655 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RXF0_PAGE0_ADDR_LO, ALE_ADDR_LO(paddr));
1656 1.3.4.2 yamt paddr = sc->ale_cdata.ale_rx_page[1].page_paddr;
1657 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RXF0_PAGE1_ADDR_LO, ALE_ADDR_LO(paddr));
1658 1.3.4.2 yamt
1659 1.3.4.2 yamt /* Set Tx/Rx CMB addresses. */
1660 1.3.4.2 yamt paddr = sc->ale_cdata.ale_tx_cmb_paddr;
1661 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TX_CMB_ADDR_LO, ALE_ADDR_LO(paddr));
1662 1.3.4.2 yamt paddr = sc->ale_cdata.ale_rx_page[0].cmb_paddr;
1663 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RXF0_CMB0_ADDR_LO, ALE_ADDR_LO(paddr));
1664 1.3.4.2 yamt paddr = sc->ale_cdata.ale_rx_page[1].cmb_paddr;
1665 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RXF0_CMB1_ADDR_LO, ALE_ADDR_LO(paddr));
1666 1.3.4.2 yamt
1667 1.3.4.2 yamt /* Mark RXF0 is valid. */
1668 1.3.4.2 yamt CSR_WRITE_1(sc, ALE_RXF0_PAGE0, RXF_VALID);
1669 1.3.4.2 yamt CSR_WRITE_1(sc, ALE_RXF0_PAGE1, RXF_VALID);
1670 1.3.4.2 yamt /*
1671 1.3.4.2 yamt * No need to initialize RFX1/RXF2/RXF3. We don't use
1672 1.3.4.2 yamt * multi-queue yet.
1673 1.3.4.2 yamt */
1674 1.3.4.2 yamt
1675 1.3.4.2 yamt /* Set Rx page size, excluding guard frame size. */
1676 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RXF_PAGE_SIZE, ALE_RX_PAGE_SZ);
1677 1.3.4.2 yamt
1678 1.3.4.2 yamt /* Tell hardware that we're ready to load DMA blocks. */
1679 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_DMA_BLOCK, DMA_BLOCK_LOAD);
1680 1.3.4.2 yamt
1681 1.3.4.2 yamt /* Set Rx/Tx interrupt trigger threshold. */
1682 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INT_TRIG_THRESH, (1 << INT_TRIG_RX_THRESH_SHIFT) |
1683 1.3.4.2 yamt (4 << INT_TRIG_TX_THRESH_SHIFT));
1684 1.3.4.2 yamt /*
1685 1.3.4.2 yamt * XXX
1686 1.3.4.2 yamt * Set interrupt trigger timer, its purpose and relation
1687 1.3.4.2 yamt * with interrupt moderation mechanism is not clear yet.
1688 1.3.4.2 yamt */
1689 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INT_TRIG_TIMER,
1690 1.3.4.2 yamt ((ALE_USECS(10) << INT_TRIG_RX_TIMER_SHIFT) |
1691 1.3.4.2 yamt (ALE_USECS(1000) << INT_TRIG_TX_TIMER_SHIFT)));
1692 1.3.4.2 yamt
1693 1.3.4.2 yamt /* Configure interrupt moderation timer. */
1694 1.3.4.2 yamt sc->ale_int_rx_mod = ALE_IM_RX_TIMER_DEFAULT;
1695 1.3.4.2 yamt sc->ale_int_tx_mod = ALE_IM_TX_TIMER_DEFAULT;
1696 1.3.4.2 yamt reg = ALE_USECS(sc->ale_int_rx_mod) << IM_TIMER_RX_SHIFT;
1697 1.3.4.2 yamt reg |= ALE_USECS(sc->ale_int_tx_mod) << IM_TIMER_TX_SHIFT;
1698 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_IM_TIMER, reg);
1699 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_MASTER_CFG);
1700 1.3.4.2 yamt reg &= ~(MASTER_CHIP_REV_MASK | MASTER_CHIP_ID_MASK);
1701 1.3.4.2 yamt reg &= ~(MASTER_IM_RX_TIMER_ENB | MASTER_IM_TX_TIMER_ENB);
1702 1.3.4.2 yamt if (ALE_USECS(sc->ale_int_rx_mod) != 0)
1703 1.3.4.2 yamt reg |= MASTER_IM_RX_TIMER_ENB;
1704 1.3.4.2 yamt if (ALE_USECS(sc->ale_int_tx_mod) != 0)
1705 1.3.4.2 yamt reg |= MASTER_IM_TX_TIMER_ENB;
1706 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MASTER_CFG, reg);
1707 1.3.4.2 yamt CSR_WRITE_2(sc, ALE_INTR_CLR_TIMER, ALE_USECS(1000));
1708 1.3.4.2 yamt
1709 1.3.4.2 yamt /* Set Maximum frame size of controller. */
1710 1.3.4.2 yamt if (ifp->if_mtu < ETHERMTU)
1711 1.3.4.2 yamt sc->ale_max_frame_size = ETHERMTU;
1712 1.3.4.2 yamt else
1713 1.3.4.2 yamt sc->ale_max_frame_size = ifp->if_mtu;
1714 1.3.4.2 yamt sc->ale_max_frame_size += ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + ETHER_CRC_LEN;
1715 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_FRAME_SIZE, sc->ale_max_frame_size);
1716 1.3.4.2 yamt
1717 1.3.4.2 yamt /* Configure IPG/IFG parameters. */
1718 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_IPG_IFG_CFG,
1719 1.3.4.2 yamt ((IPG_IFG_IPGT_DEFAULT << IPG_IFG_IPGT_SHIFT) & IPG_IFG_IPGT_MASK) |
1720 1.3.4.2 yamt ((IPG_IFG_MIFG_DEFAULT << IPG_IFG_MIFG_SHIFT) & IPG_IFG_MIFG_MASK) |
1721 1.3.4.2 yamt ((IPG_IFG_IPG1_DEFAULT << IPG_IFG_IPG1_SHIFT) & IPG_IFG_IPG1_MASK) |
1722 1.3.4.2 yamt ((IPG_IFG_IPG2_DEFAULT << IPG_IFG_IPG2_SHIFT) & IPG_IFG_IPG2_MASK));
1723 1.3.4.2 yamt
1724 1.3.4.2 yamt /* Set parameters for half-duplex media. */
1725 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_HDPX_CFG,
1726 1.3.4.2 yamt ((HDPX_CFG_LCOL_DEFAULT << HDPX_CFG_LCOL_SHIFT) &
1727 1.3.4.2 yamt HDPX_CFG_LCOL_MASK) |
1728 1.3.4.2 yamt ((HDPX_CFG_RETRY_DEFAULT << HDPX_CFG_RETRY_SHIFT) &
1729 1.3.4.2 yamt HDPX_CFG_RETRY_MASK) | HDPX_CFG_EXC_DEF_EN |
1730 1.3.4.2 yamt ((HDPX_CFG_ABEBT_DEFAULT << HDPX_CFG_ABEBT_SHIFT) &
1731 1.3.4.2 yamt HDPX_CFG_ABEBT_MASK) |
1732 1.3.4.2 yamt ((HDPX_CFG_JAMIPG_DEFAULT << HDPX_CFG_JAMIPG_SHIFT) &
1733 1.3.4.2 yamt HDPX_CFG_JAMIPG_MASK));
1734 1.3.4.2 yamt
1735 1.3.4.2 yamt /* Configure Tx jumbo frame parameters. */
1736 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_JUMBO) != 0) {
1737 1.3.4.2 yamt if (ifp->if_mtu < ETHERMTU)
1738 1.3.4.2 yamt reg = sc->ale_max_frame_size;
1739 1.3.4.2 yamt else if (ifp->if_mtu < 6 * 1024)
1740 1.3.4.2 yamt reg = (sc->ale_max_frame_size * 2) / 3;
1741 1.3.4.2 yamt else
1742 1.3.4.2 yamt reg = sc->ale_max_frame_size / 2;
1743 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TX_JUMBO_THRESH,
1744 1.3.4.2 yamt roundup(reg, TX_JUMBO_THRESH_UNIT) >>
1745 1.3.4.2 yamt TX_JUMBO_THRESH_UNIT_SHIFT);
1746 1.3.4.2 yamt }
1747 1.3.4.2 yamt
1748 1.3.4.2 yamt /* Configure TxQ. */
1749 1.3.4.2 yamt reg = (128 << (sc->ale_dma_rd_burst >> DMA_CFG_RD_BURST_SHIFT))
1750 1.3.4.2 yamt << TXQ_CFG_TX_FIFO_BURST_SHIFT;
1751 1.3.4.2 yamt reg |= (TXQ_CFG_TPD_BURST_DEFAULT << TXQ_CFG_TPD_BURST_SHIFT) &
1752 1.3.4.2 yamt TXQ_CFG_TPD_BURST_MASK;
1753 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TXQ_CFG, reg | TXQ_CFG_ENHANCED_MODE | TXQ_CFG_ENB);
1754 1.3.4.2 yamt
1755 1.3.4.2 yamt /* Configure Rx jumbo frame & flow control parameters. */
1756 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_JUMBO) != 0) {
1757 1.3.4.2 yamt reg = roundup(sc->ale_max_frame_size, RX_JUMBO_THRESH_UNIT);
1758 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RX_JUMBO_THRESH,
1759 1.3.4.2 yamt (((reg >> RX_JUMBO_THRESH_UNIT_SHIFT) <<
1760 1.3.4.2 yamt RX_JUMBO_THRESH_MASK_SHIFT) & RX_JUMBO_THRESH_MASK) |
1761 1.3.4.2 yamt ((RX_JUMBO_LKAH_DEFAULT << RX_JUMBO_LKAH_SHIFT) &
1762 1.3.4.2 yamt RX_JUMBO_LKAH_MASK));
1763 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_SRAM_RX_FIFO_LEN);
1764 1.3.4.2 yamt rxf_hi = (reg * 7) / 10;
1765 1.3.4.2 yamt rxf_lo = (reg * 3)/ 10;
1766 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RX_FIFO_PAUSE_THRESH,
1767 1.3.4.2 yamt ((rxf_lo << RX_FIFO_PAUSE_THRESH_LO_SHIFT) &
1768 1.3.4.2 yamt RX_FIFO_PAUSE_THRESH_LO_MASK) |
1769 1.3.4.2 yamt ((rxf_hi << RX_FIFO_PAUSE_THRESH_HI_SHIFT) &
1770 1.3.4.2 yamt RX_FIFO_PAUSE_THRESH_HI_MASK));
1771 1.3.4.2 yamt }
1772 1.3.4.2 yamt
1773 1.3.4.2 yamt /* Disable RSS. */
1774 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RSS_IDT_TABLE0, 0);
1775 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RSS_CPU, 0);
1776 1.3.4.2 yamt
1777 1.3.4.2 yamt /* Configure RxQ. */
1778 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RXQ_CFG,
1779 1.3.4.2 yamt RXQ_CFG_ALIGN_32 | RXQ_CFG_CUT_THROUGH_ENB | RXQ_CFG_ENB);
1780 1.3.4.2 yamt
1781 1.3.4.2 yamt /* Configure DMA parameters. */
1782 1.3.4.2 yamt reg = 0;
1783 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_TXCMB_BUG) == 0)
1784 1.3.4.2 yamt reg |= DMA_CFG_TXCMB_ENB;
1785 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_DMA_CFG,
1786 1.3.4.2 yamt DMA_CFG_OUT_ORDER | DMA_CFG_RD_REQ_PRI | DMA_CFG_RCB_64 |
1787 1.3.4.2 yamt sc->ale_dma_rd_burst | reg |
1788 1.3.4.2 yamt sc->ale_dma_wr_burst | DMA_CFG_RXCMB_ENB |
1789 1.3.4.2 yamt ((DMA_CFG_RD_DELAY_CNT_DEFAULT << DMA_CFG_RD_DELAY_CNT_SHIFT) &
1790 1.3.4.2 yamt DMA_CFG_RD_DELAY_CNT_MASK) |
1791 1.3.4.2 yamt ((DMA_CFG_WR_DELAY_CNT_DEFAULT << DMA_CFG_WR_DELAY_CNT_SHIFT) &
1792 1.3.4.2 yamt DMA_CFG_WR_DELAY_CNT_MASK));
1793 1.3.4.2 yamt
1794 1.3.4.2 yamt /*
1795 1.3.4.2 yamt * Hardware can be configured to issue SMB interrupt based
1796 1.3.4.2 yamt * on programmed interval. Since there is a callout that is
1797 1.3.4.2 yamt * invoked for every hz in driver we use that instead of
1798 1.3.4.2 yamt * relying on periodic SMB interrupt.
1799 1.3.4.2 yamt */
1800 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_SMB_STAT_TIMER, ALE_USECS(0));
1801 1.3.4.2 yamt
1802 1.3.4.2 yamt /* Clear MAC statistics. */
1803 1.3.4.2 yamt ale_stats_clear(sc);
1804 1.3.4.2 yamt
1805 1.3.4.2 yamt /*
1806 1.3.4.2 yamt * Configure Tx/Rx MACs.
1807 1.3.4.2 yamt * - Auto-padding for short frames.
1808 1.3.4.2 yamt * - Enable CRC generation.
1809 1.3.4.2 yamt * Actual reconfiguration of MAC for resolved speed/duplex
1810 1.3.4.2 yamt * is followed after detection of link establishment.
1811 1.3.4.2 yamt * AR81xx always does checksum computation regardless of
1812 1.3.4.2 yamt * MAC_CFG_RXCSUM_ENB bit. In fact, setting the bit will
1813 1.3.4.2 yamt * cause Rx handling issue for fragmented IP datagrams due
1814 1.3.4.2 yamt * to silicon bug.
1815 1.3.4.2 yamt */
1816 1.3.4.2 yamt reg = MAC_CFG_TX_CRC_ENB | MAC_CFG_TX_AUTO_PAD | MAC_CFG_FULL_DUPLEX |
1817 1.3.4.2 yamt ((MAC_CFG_PREAMBLE_DEFAULT << MAC_CFG_PREAMBLE_SHIFT) &
1818 1.3.4.2 yamt MAC_CFG_PREAMBLE_MASK);
1819 1.3.4.2 yamt if ((sc->ale_flags & ALE_FLAG_FASTETHER) != 0)
1820 1.3.4.2 yamt reg |= MAC_CFG_SPEED_10_100;
1821 1.3.4.2 yamt else
1822 1.3.4.2 yamt reg |= MAC_CFG_SPEED_1000;
1823 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAC_CFG, reg);
1824 1.3.4.2 yamt
1825 1.3.4.2 yamt /* Set up the receive filter. */
1826 1.3.4.2 yamt ale_rxfilter(sc);
1827 1.3.4.2 yamt ale_rxvlan(sc);
1828 1.3.4.2 yamt
1829 1.3.4.2 yamt /* Acknowledge all pending interrupts and clear it. */
1830 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_MASK, ALE_INTRS);
1831 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_STATUS, 0xFFFFFFFF);
1832 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_STATUS, 0);
1833 1.3.4.2 yamt
1834 1.3.4.2 yamt sc->ale_flags &= ~ALE_FLAG_LINK;
1835 1.3.4.2 yamt
1836 1.3.4.2 yamt /* Switch to the current media. */
1837 1.3.4.2 yamt mii = &sc->sc_miibus;
1838 1.3.4.2 yamt mii_mediachg(mii);
1839 1.3.4.2 yamt
1840 1.3.4.2 yamt callout_schedule(&sc->sc_tick_ch, hz);
1841 1.3.4.2 yamt
1842 1.3.4.2 yamt ifp->if_flags |= IFF_RUNNING;
1843 1.3.4.2 yamt ifp->if_flags &= ~IFF_OACTIVE;
1844 1.3.4.2 yamt
1845 1.3.4.2 yamt return 0;
1846 1.3.4.2 yamt }
1847 1.3.4.2 yamt
1848 1.3.4.2 yamt static void
1849 1.3.4.2 yamt ale_stop(struct ifnet *ifp, int disable)
1850 1.3.4.2 yamt {
1851 1.3.4.2 yamt struct ale_softc *sc = ifp->if_softc;
1852 1.3.4.2 yamt struct ale_txdesc *txd;
1853 1.3.4.2 yamt uint32_t reg;
1854 1.3.4.2 yamt int i;
1855 1.3.4.2 yamt
1856 1.3.4.2 yamt callout_stop(&sc->sc_tick_ch);
1857 1.3.4.2 yamt
1858 1.3.4.2 yamt /*
1859 1.3.4.2 yamt * Mark the interface down and cancel the watchdog timer.
1860 1.3.4.2 yamt */
1861 1.3.4.2 yamt ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1862 1.3.4.2 yamt ifp->if_timer = 0;
1863 1.3.4.2 yamt
1864 1.3.4.2 yamt sc->ale_flags &= ~ALE_FLAG_LINK;
1865 1.3.4.2 yamt
1866 1.3.4.2 yamt ale_stats_update(sc);
1867 1.3.4.2 yamt
1868 1.3.4.2 yamt mii_down(&sc->sc_miibus);
1869 1.3.4.2 yamt
1870 1.3.4.2 yamt /* Disable interrupts. */
1871 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_MASK, 0);
1872 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_STATUS, 0xFFFFFFFF);
1873 1.3.4.2 yamt
1874 1.3.4.2 yamt /* Disable queue processing and DMA. */
1875 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_TXQ_CFG);
1876 1.3.4.2 yamt reg &= ~TXQ_CFG_ENB;
1877 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_TXQ_CFG, reg);
1878 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_RXQ_CFG);
1879 1.3.4.2 yamt reg &= ~RXQ_CFG_ENB;
1880 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_RXQ_CFG, reg);
1881 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_DMA_CFG);
1882 1.3.4.2 yamt reg &= ~(DMA_CFG_TXCMB_ENB | DMA_CFG_RXCMB_ENB);
1883 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_DMA_CFG, reg);
1884 1.3.4.2 yamt DELAY(1000);
1885 1.3.4.2 yamt
1886 1.3.4.2 yamt /* Stop Rx/Tx MACs. */
1887 1.3.4.2 yamt ale_stop_mac(sc);
1888 1.3.4.2 yamt
1889 1.3.4.2 yamt /* Disable interrupts again? XXX */
1890 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_INTR_STATUS, 0xFFFFFFFF);
1891 1.3.4.2 yamt
1892 1.3.4.2 yamt /*
1893 1.3.4.2 yamt * Free TX mbufs still in the queues.
1894 1.3.4.2 yamt */
1895 1.3.4.2 yamt for (i = 0; i < ALE_TX_RING_CNT; i++) {
1896 1.3.4.2 yamt txd = &sc->ale_cdata.ale_txdesc[i];
1897 1.3.4.2 yamt if (txd->tx_m != NULL) {
1898 1.3.4.2 yamt bus_dmamap_unload(sc->sc_dmat, txd->tx_dmamap);
1899 1.3.4.2 yamt m_freem(txd->tx_m);
1900 1.3.4.2 yamt txd->tx_m = NULL;
1901 1.3.4.2 yamt }
1902 1.3.4.2 yamt }
1903 1.3.4.2 yamt }
1904 1.3.4.2 yamt
1905 1.3.4.2 yamt static void
1906 1.3.4.2 yamt ale_stop_mac(struct ale_softc *sc)
1907 1.3.4.2 yamt {
1908 1.3.4.2 yamt uint32_t reg;
1909 1.3.4.2 yamt int i;
1910 1.3.4.2 yamt
1911 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_MAC_CFG);
1912 1.3.4.2 yamt if ((reg & (MAC_CFG_TX_ENB | MAC_CFG_RX_ENB)) != 0) {
1913 1.3.4.2 yamt reg &= ~MAC_CFG_TX_ENB | MAC_CFG_RX_ENB;
1914 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAC_CFG, reg);
1915 1.3.4.2 yamt }
1916 1.3.4.2 yamt
1917 1.3.4.2 yamt for (i = ALE_TIMEOUT; i > 0; i--) {
1918 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_IDLE_STATUS);
1919 1.3.4.2 yamt if (reg == 0)
1920 1.3.4.2 yamt break;
1921 1.3.4.2 yamt DELAY(10);
1922 1.3.4.2 yamt }
1923 1.3.4.2 yamt if (i == 0)
1924 1.3.4.2 yamt printf("%s: could not disable Tx/Rx MAC(0x%08x)!\n",
1925 1.3.4.2 yamt device_xname(sc->sc_dev), reg);
1926 1.3.4.2 yamt }
1927 1.3.4.2 yamt
1928 1.3.4.2 yamt static void
1929 1.3.4.2 yamt ale_init_tx_ring(struct ale_softc *sc)
1930 1.3.4.2 yamt {
1931 1.3.4.2 yamt struct ale_txdesc *txd;
1932 1.3.4.2 yamt int i;
1933 1.3.4.2 yamt
1934 1.3.4.2 yamt sc->ale_cdata.ale_tx_prod = 0;
1935 1.3.4.2 yamt sc->ale_cdata.ale_tx_cons = 0;
1936 1.3.4.2 yamt sc->ale_cdata.ale_tx_cnt = 0;
1937 1.3.4.2 yamt
1938 1.3.4.2 yamt memset(sc->ale_cdata.ale_tx_ring, 0, ALE_TX_RING_SZ);
1939 1.3.4.2 yamt memset(sc->ale_cdata.ale_tx_cmb, 0, ALE_TX_CMB_SZ);
1940 1.3.4.2 yamt for (i = 0; i < ALE_TX_RING_CNT; i++) {
1941 1.3.4.2 yamt txd = &sc->ale_cdata.ale_txdesc[i];
1942 1.3.4.2 yamt txd->tx_m = NULL;
1943 1.3.4.2 yamt }
1944 1.3.4.2 yamt *sc->ale_cdata.ale_tx_cmb = 0;
1945 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, sc->ale_cdata.ale_tx_cmb_map, 0,
1946 1.3.4.2 yamt sc->ale_cdata.ale_tx_cmb_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1947 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, sc->ale_cdata.ale_tx_ring_map, 0,
1948 1.3.4.2 yamt sc->ale_cdata.ale_tx_ring_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1949 1.3.4.2 yamt }
1950 1.3.4.2 yamt
1951 1.3.4.2 yamt static void
1952 1.3.4.2 yamt ale_init_rx_pages(struct ale_softc *sc)
1953 1.3.4.2 yamt {
1954 1.3.4.2 yamt struct ale_rx_page *rx_page;
1955 1.3.4.2 yamt int i;
1956 1.3.4.2 yamt
1957 1.3.4.2 yamt sc->ale_cdata.ale_rx_seqno = 0;
1958 1.3.4.2 yamt sc->ale_cdata.ale_rx_curp = 0;
1959 1.3.4.2 yamt
1960 1.3.4.2 yamt for (i = 0; i < ALE_RX_PAGES; i++) {
1961 1.3.4.2 yamt rx_page = &sc->ale_cdata.ale_rx_page[i];
1962 1.3.4.2 yamt memset(rx_page->page_addr, 0, sc->ale_pagesize);
1963 1.3.4.2 yamt memset(rx_page->cmb_addr, 0, ALE_RX_CMB_SZ);
1964 1.3.4.2 yamt rx_page->cons = 0;
1965 1.3.4.2 yamt *rx_page->cmb_addr = 0;
1966 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, rx_page->page_map, 0,
1967 1.3.4.2 yamt rx_page->page_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1968 1.3.4.2 yamt bus_dmamap_sync(sc->sc_dmat, rx_page->cmb_map, 0,
1969 1.3.4.2 yamt rx_page->cmb_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1970 1.3.4.2 yamt }
1971 1.3.4.2 yamt }
1972 1.3.4.2 yamt
1973 1.3.4.2 yamt static void
1974 1.3.4.2 yamt ale_rxvlan(struct ale_softc *sc)
1975 1.3.4.2 yamt {
1976 1.3.4.2 yamt uint32_t reg;
1977 1.3.4.2 yamt
1978 1.3.4.2 yamt reg = CSR_READ_4(sc, ALE_MAC_CFG);
1979 1.3.4.2 yamt reg &= ~MAC_CFG_VLAN_TAG_STRIP;
1980 1.3.4.6 yamt if (sc->sc_ec.ec_capenable & ETHERCAP_VLAN_HWTAGGING)
1981 1.3.4.2 yamt reg |= MAC_CFG_VLAN_TAG_STRIP;
1982 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAC_CFG, reg);
1983 1.3.4.2 yamt }
1984 1.3.4.2 yamt
1985 1.3.4.2 yamt static void
1986 1.3.4.2 yamt ale_rxfilter(struct ale_softc *sc)
1987 1.3.4.2 yamt {
1988 1.3.4.2 yamt struct ethercom *ec = &sc->sc_ec;
1989 1.3.4.2 yamt struct ifnet *ifp = &ec->ec_if;
1990 1.3.4.2 yamt struct ether_multi *enm;
1991 1.3.4.2 yamt struct ether_multistep step;
1992 1.3.4.2 yamt uint32_t crc;
1993 1.3.4.2 yamt uint32_t mchash[2];
1994 1.3.4.2 yamt uint32_t rxcfg;
1995 1.3.4.2 yamt
1996 1.3.4.2 yamt rxcfg = CSR_READ_4(sc, ALE_MAC_CFG);
1997 1.3.4.2 yamt rxcfg &= ~(MAC_CFG_ALLMULTI | MAC_CFG_BCAST | MAC_CFG_PROMISC);
1998 1.3.4.3 yamt ifp->if_flags &= ~IFF_ALLMULTI;
1999 1.3.4.2 yamt
2000 1.3.4.2 yamt /*
2001 1.3.4.2 yamt * Always accept broadcast frames.
2002 1.3.4.2 yamt */
2003 1.3.4.2 yamt rxcfg |= MAC_CFG_BCAST;
2004 1.3.4.2 yamt
2005 1.3.4.3 yamt if (ifp->if_flags & IFF_PROMISC || ec->ec_multicnt > 0) {
2006 1.3.4.3 yamt ifp->if_flags |= IFF_ALLMULTI;
2007 1.3.4.2 yamt if (ifp->if_flags & IFF_PROMISC)
2008 1.3.4.2 yamt rxcfg |= MAC_CFG_PROMISC;
2009 1.3.4.2 yamt else
2010 1.3.4.2 yamt rxcfg |= MAC_CFG_ALLMULTI;
2011 1.3.4.2 yamt mchash[0] = mchash[1] = 0xFFFFFFFF;
2012 1.3.4.2 yamt } else {
2013 1.3.4.2 yamt /* Program new filter. */
2014 1.3.4.2 yamt memset(mchash, 0, sizeof(mchash));
2015 1.3.4.2 yamt
2016 1.3.4.2 yamt ETHER_FIRST_MULTI(step, ec, enm);
2017 1.3.4.2 yamt while (enm != NULL) {
2018 1.3.4.2 yamt crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
2019 1.3.4.2 yamt mchash[crc >> 31] |= 1 << ((crc >> 26) & 0x1f);
2020 1.3.4.2 yamt ETHER_NEXT_MULTI(step, enm);
2021 1.3.4.2 yamt }
2022 1.3.4.2 yamt }
2023 1.3.4.2 yamt
2024 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAR0, mchash[0]);
2025 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAR1, mchash[1]);
2026 1.3.4.2 yamt CSR_WRITE_4(sc, ALE_MAC_CFG, rxcfg);
2027 1.3.4.2 yamt }
2028