2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012, 2013 Bjoern A. Zeeb
5 * Copyright (c) 2014 Robert N. M. Watson
6 * Copyright (c) 2016-2017 Ruslan Bukin <br@bsdpad.com>
9 * This software was developed by SRI International and the University of
10 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-11-C-0249)
11 * ("MRC2"), as part of the DARPA MRC research programme.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Altera Triple-Speed Ethernet MegaCore, Function User Guide
36 * UG-01008-3.0, Software Version: 12.0, June 2012.
37 * Available at the time of writing at:
38 * http://www.altera.com/literature/ug/ug_ethernet.pdf
40 * We are using an Marvell E1111 (Alaska) PHY on the DE4. See mii/e1000phy.c.
44 * - ifOutBroadcastPkts are only counted if both ether dst and src are all-1s;
45 * seems an IP core bug, they count ether broadcasts as multicast. Is this
47 * - figure out why the TX FIFO fill status and intr did not work as expected.
48 * - test 100Mbit/s and 10Mbit/s
49 * - blacklist the one special factory programmed ethernet address (for now
50 * hardcoded, later from loader?)
51 * - resolve all XXX, left as reminders to shake out details later
52 * - Jumbo frame support
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
58 #include "opt_device_polling.h"
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/kernel.h>
64 #include <sys/endian.h>
67 #include <sys/module.h>
68 #include <sys/mutex.h>
70 #include <sys/socket.h>
71 #include <sys/sockio.h>
72 #include <sys/types.h>
74 #include <net/ethernet.h>
76 #include <net/if_var.h>
77 #include <net/if_dl.h>
78 #include <net/if_media.h>
79 #include <net/if_types.h>
80 #include <net/if_vlan_var.h>
84 #include <machine/bus.h>
85 #include <machine/resource.h>
88 #include <dev/mii/mii.h>
89 #include <dev/mii/miivar.h>
91 #include <dev/altera/atse/if_atsereg.h>
92 #include <dev/xdma/xdma.h>
94 #define RX_QUEUE_SIZE 4096
95 #define TX_QUEUE_SIZE 4096
96 #define NUM_RX_MBUF 512
97 #define BUFRING_SIZE 8192
99 #include <machine/cache.h>
101 /* XXX once we'd do parallel attach, we need a global lock for this. */
102 #define ATSE_ETHERNET_OPTION_BITS_UNDEF 0
103 #define ATSE_ETHERNET_OPTION_BITS_READ 1
104 static int atse_ethernet_option_bits_flag = ATSE_ETHERNET_OPTION_BITS_UNDEF;
105 static uint8_t atse_ethernet_option_bits[ALTERA_ETHERNET_OPTION_BITS_LEN];
108 * Softc and critical resource locking.
110 #define ATSE_LOCK(_sc) mtx_lock(&(_sc)->atse_mtx)
111 #define ATSE_UNLOCK(_sc) mtx_unlock(&(_sc)->atse_mtx)
112 #define ATSE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->atse_mtx, MA_OWNED)
118 #define DPRINTF(format, ...) printf(format, __VA_ARGS__)
120 #define DPRINTF(format, ...)
124 * Register space access macros.
127 csr_write_4(struct atse_softc *sc, uint32_t reg, uint32_t val4,
128 const char *f, const int l)
131 val4 = htole32(val4);
132 DPRINTF("[%s:%d] CSR W %s 0x%08x (0x%08x) = 0x%08x\n", f, l,
133 "atse_mem_res", reg, reg * 4, val4);
134 bus_write_4(sc->atse_mem_res, reg * 4, val4);
137 static inline uint32_t
138 csr_read_4(struct atse_softc *sc, uint32_t reg, const char *f, const int l)
142 val4 = le32toh(bus_read_4(sc->atse_mem_res, reg * 4));
143 DPRINTF("[%s:%d] CSR R %s 0x%08x (0x%08x) = 0x%08x\n", f, l,
144 "atse_mem_res", reg, reg * 4, val4);
150 * See page 5-2 that it's all dword offsets and the MS 16 bits need to be zero
151 * on write and ignored on read.
154 pxx_write_2(struct atse_softc *sc, bus_addr_t bmcr, uint32_t reg, uint16_t val,
155 const char *f, const int l, const char *s)
159 val4 = htole32(val & 0x0000ffff);
160 DPRINTF("[%s:%d] %s W %s 0x%08x (0x%08jx) = 0x%08x\n", f, l, s,
161 "atse_mem_res", reg, (bmcr + reg) * 4, val4);
162 bus_write_4(sc->atse_mem_res, (bmcr + reg) * 4, val4);
165 static inline uint16_t
166 pxx_read_2(struct atse_softc *sc, bus_addr_t bmcr, uint32_t reg, const char *f,
167 const int l, const char *s)
172 val4 = bus_read_4(sc->atse_mem_res, (bmcr + reg) * 4);
173 val = le32toh(val4) & 0x0000ffff;
174 DPRINTF("[%s:%d] %s R %s 0x%08x (0x%08jx) = 0x%04x\n", f, l, s,
175 "atse_mem_res", reg, (bmcr + reg) * 4, val);
180 #define CSR_WRITE_4(sc, reg, val) \
181 csr_write_4((sc), (reg), (val), __func__, __LINE__)
182 #define CSR_READ_4(sc, reg) \
183 csr_read_4((sc), (reg), __func__, __LINE__)
184 #define PCS_WRITE_2(sc, reg, val) \
185 pxx_write_2((sc), sc->atse_bmcr0, (reg), (val), __func__, __LINE__, \
187 #define PCS_READ_2(sc, reg) \
188 pxx_read_2((sc), sc->atse_bmcr0, (reg), __func__, __LINE__, "PCS")
189 #define PHY_WRITE_2(sc, reg, val) \
190 pxx_write_2((sc), sc->atse_bmcr1, (reg), (val), __func__, __LINE__, \
192 #define PHY_READ_2(sc, reg) \
193 pxx_read_2((sc), sc->atse_bmcr1, (reg), __func__, __LINE__, "PHY")
195 static void atse_tick(void *);
196 static int atse_detach(device_t);
198 devclass_t atse_devclass;
201 atse_rx_enqueue(struct atse_softc *sc, uint32_t n)
206 for (i = 0; i < n; i++) {
207 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
209 device_printf(sc->dev,
210 "%s: Can't alloc rx mbuf\n", __func__);
214 m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
215 xdma_enqueue_mbuf(sc->xchan_rx, &m, 0, 4, 4, XDMA_DEV_TO_MEM);
222 atse_xdma_tx_intr(void *arg, xdma_transfer_status_t *status)
224 xdma_transfer_status_t st;
225 struct atse_softc *sc;
237 err = xdma_dequeue_mbuf(sc->xchan_tx, &m, &st);
243 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
250 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
258 atse_xdma_rx_intr(void *arg, xdma_transfer_status_t *status)
260 xdma_transfer_status_t st;
261 struct atse_softc *sc;
265 uint32_t cnt_processed;
275 err = xdma_dequeue_mbuf(sc->xchan_rx, &m, &st);
282 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
287 m->m_pkthdr.len = m->m_len = st.transferred;
288 m->m_pkthdr.rcvif = ifp;
289 m_adj(m, ETHER_ALIGN);
291 (*ifp->if_input)(ifp, m);
295 atse_rx_enqueue(sc, cnt_processed);
303 atse_transmit_locked(struct ifnet *ifp)
305 struct atse_softc *sc;
316 while ((m = drbr_peek(ifp, br)) != NULL) {
317 error = xdma_enqueue_mbuf(sc->xchan_tx, &m, 0, 4, 4, XDMA_MEM_TO_DEV);
319 /* No space in request queue available yet. */
320 drbr_putback(ifp, br, m);
324 drbr_advance(ifp, br);
329 /* If anyone is interested give them a copy. */
330 ETHER_BPF_MTAP(ifp, m);
334 xdma_queue_submit(sc->xchan_tx);
340 atse_transmit(struct ifnet *ifp, struct mbuf *m)
342 struct atse_softc *sc;
351 mtx_lock(&sc->br_mtx);
353 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING) {
354 error = drbr_enqueue(ifp, sc->br, m);
355 mtx_unlock(&sc->br_mtx);
360 if ((sc->atse_flags & ATSE_FLAGS_LINK) == 0) {
361 error = drbr_enqueue(ifp, sc->br, m);
362 mtx_unlock(&sc->br_mtx);
367 error = drbr_enqueue(ifp, br, m);
369 mtx_unlock(&sc->br_mtx);
373 error = atse_transmit_locked(ifp);
375 mtx_unlock(&sc->br_mtx);
382 atse_qflush(struct ifnet *ifp)
384 struct atse_softc *sc;
388 printf("%s\n", __func__);
392 atse_stop_locked(struct atse_softc *sc)
398 ATSE_LOCK_ASSERT(sc);
400 callout_stop(&sc->atse_tick);
403 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
405 /* Disable MAC transmit and receive datapath. */
406 mask = BASE_CFG_COMMAND_CONFIG_TX_ENA|BASE_CFG_COMMAND_CONFIG_RX_ENA;
407 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
409 CSR_WRITE_4(sc, BASE_CFG_COMMAND_CONFIG, val4);
411 /* Wait for bits to be cleared; i=100 is excessive. */
412 for (i = 0; i < 100; i++) {
413 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
414 if ((val4 & mask) == 0) {
420 if ((val4 & mask) != 0) {
421 device_printf(sc->atse_dev, "Disabling MAC TX/RX timed out.\n");
425 sc->atse_flags &= ~ATSE_FLAGS_LINK;
431 atse_mchash(struct atse_softc *sc __unused, const uint8_t *addr)
437 for (i = 0; i < ETHER_ADDR_LEN; i++) {
439 for (j = 1; j < 8; j++)
440 y ^= (addr[i] >> j) & 0x01;
448 atse_rxfilter_locked(struct atse_softc *sc)
450 struct ifmultiaddr *ifma;
455 /* XXX-BZ can we find out if we have the MHASH synthesized? */
456 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
457 /* For simplicity always hash full 48 bits of addresses. */
458 if ((val4 & BASE_CFG_COMMAND_CONFIG_MHASH_SEL) != 0)
459 val4 &= ~BASE_CFG_COMMAND_CONFIG_MHASH_SEL;
462 if (ifp->if_flags & IFF_PROMISC) {
463 val4 |= BASE_CFG_COMMAND_CONFIG_PROMIS_EN;
465 val4 &= ~BASE_CFG_COMMAND_CONFIG_PROMIS_EN;
468 CSR_WRITE_4(sc, BASE_CFG_COMMAND_CONFIG, val4);
470 if (ifp->if_flags & IFF_ALLMULTI) {
471 /* Accept all multicast addresses. */
472 for (i = 0; i <= MHASH_LEN; i++)
473 CSR_WRITE_4(sc, MHASH_START + i, 0x1);
476 * Can hold MHASH_LEN entries.
477 * XXX-BZ bitstring.h would be more general.
483 * Re-build and re-program hash table. First build the
484 * bit-field "yes" or "no" for each slot per address, then
485 * do all the programming afterwards.
488 CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
489 if (ifma->ifma_addr->sa_family != AF_LINK) {
493 h |= (1 << atse_mchash(sc,
494 LLADDR((struct sockaddr_dl *)ifma->ifma_addr)));
496 if_maddr_runlock(ifp);
497 for (i = 0; i <= MHASH_LEN; i++) {
498 CSR_WRITE_4(sc, MHASH_START + i,
499 (h & (1 << i)) ? 0x01 : 0x00);
507 atse_ethernet_option_bits_read_fdt(device_t dev)
509 struct resource *res;
513 if (atse_ethernet_option_bits_flag & ATSE_ETHERNET_OPTION_BITS_READ) {
517 fdev = device_find_child(device_get_parent(dev), "cfi", 0);
523 res = bus_alloc_resource_any(fdev, SYS_RES_MEMORY, &rid,
524 RF_ACTIVE | RF_SHAREABLE);
529 for (i = 0; i < ALTERA_ETHERNET_OPTION_BITS_LEN; i++) {
530 atse_ethernet_option_bits[i] = bus_read_1(res,
531 ALTERA_ETHERNET_OPTION_BITS_OFF + i);
534 bus_release_resource(fdev, SYS_RES_MEMORY, rid, res);
535 atse_ethernet_option_bits_flag |= ATSE_ETHERNET_OPTION_BITS_READ;
541 atse_ethernet_option_bits_read(device_t dev)
545 error = atse_ethernet_option_bits_read_fdt(dev);
549 device_printf(dev, "Cannot read Ethernet addresses from flash.\n");
555 atse_get_eth_address(struct atse_softc *sc)
557 unsigned long hostid;
562 * Make sure to only ever do this once. Otherwise a reset would
563 * possibly change our ethernet address, which is not good at all.
565 if (sc->atse_eth_addr[0] != 0x00 || sc->atse_eth_addr[1] != 0x00 ||
566 sc->atse_eth_addr[2] != 0x00) {
570 if ((atse_ethernet_option_bits_flag &
571 ATSE_ETHERNET_OPTION_BITS_READ) == 0) {
575 val4 = atse_ethernet_option_bits[0] << 24;
576 val4 |= atse_ethernet_option_bits[1] << 16;
577 val4 |= atse_ethernet_option_bits[2] << 8;
578 val4 |= atse_ethernet_option_bits[3];
579 /* They chose "safe". */
580 if (val4 != le32toh(0x00005afe)) {
581 device_printf(sc->atse_dev, "Magic '5afe' is not safe: 0x%08x. "
582 "Falling back to random numbers for hardware address.\n",
587 sc->atse_eth_addr[0] = atse_ethernet_option_bits[4];
588 sc->atse_eth_addr[1] = atse_ethernet_option_bits[5];
589 sc->atse_eth_addr[2] = atse_ethernet_option_bits[6];
590 sc->atse_eth_addr[3] = atse_ethernet_option_bits[7];
591 sc->atse_eth_addr[4] = atse_ethernet_option_bits[8];
592 sc->atse_eth_addr[5] = atse_ethernet_option_bits[9];
594 /* Handle factory default ethernet addresss: 00:07:ed:ff:ed:15 */
595 if (sc->atse_eth_addr[0] == 0x00 && sc->atse_eth_addr[1] == 0x07 &&
596 sc->atse_eth_addr[2] == 0xed && sc->atse_eth_addr[3] == 0xff &&
597 sc->atse_eth_addr[4] == 0xed && sc->atse_eth_addr[5] == 0x15) {
599 device_printf(sc->atse_dev, "Factory programmed Ethernet "
600 "hardware address blacklisted. Falling back to random "
601 "address to avoid collisions.\n");
602 device_printf(sc->atse_dev, "Please re-program your flash.\n");
606 if (sc->atse_eth_addr[0] == 0x00 && sc->atse_eth_addr[1] == 0x00 &&
607 sc->atse_eth_addr[2] == 0x00 && sc->atse_eth_addr[3] == 0x00 &&
608 sc->atse_eth_addr[4] == 0x00 && sc->atse_eth_addr[5] == 0x00) {
609 device_printf(sc->atse_dev, "All zero's Ethernet hardware "
610 "address blacklisted. Falling back to random address.\n");
611 device_printf(sc->atse_dev, "Please re-program your flash.\n");
615 if (ETHER_IS_MULTICAST(sc->atse_eth_addr)) {
616 device_printf(sc->atse_dev, "Multicast Ethernet hardware "
617 "address blacklisted. Falling back to random address.\n");
618 device_printf(sc->atse_dev, "Please re-program your flash.\n");
623 * If we find an Altera prefixed address with a 0x0 ending
624 * adjust by device unit. If not and this is not the first
625 * Ethernet, go to random.
627 unit = device_get_unit(sc->atse_dev);
633 device_printf(sc->atse_dev, "We do not support Ethernet "
634 "addresses for more than 16 MACs. Falling back to "
635 "random hadware address.\n");
638 if ((sc->atse_eth_addr[0] & ~0x2) != 0 ||
639 sc->atse_eth_addr[1] != 0x07 || sc->atse_eth_addr[2] != 0xed ||
640 (sc->atse_eth_addr[5] & 0x0f) != 0x0) {
641 device_printf(sc->atse_dev, "Ethernet address not meeting our "
642 "multi-MAC standards. Falling back to random hadware "
646 sc->atse_eth_addr[5] |= (unit & 0x0f);
652 * Fall back to random code we also use on bridge(4).
654 getcredhostid(curthread->td_ucred, &hostid);
656 arc4rand(sc->atse_eth_addr, ETHER_ADDR_LEN, 1);
657 sc->atse_eth_addr[0] &= ~1;/* clear multicast bit */
658 sc->atse_eth_addr[0] |= 2; /* set the LAA bit */
660 sc->atse_eth_addr[0] = 0x2;
661 sc->atse_eth_addr[1] = (hostid >> 24) & 0xff;
662 sc->atse_eth_addr[2] = (hostid >> 16) & 0xff;
663 sc->atse_eth_addr[3] = (hostid >> 8 ) & 0xff;
664 sc->atse_eth_addr[4] = hostid & 0xff;
665 sc->atse_eth_addr[5] = sc->atse_unit & 0xff;
672 atse_set_eth_address(struct atse_softc *sc, int n)
676 v0 = (sc->atse_eth_addr[3] << 24) | (sc->atse_eth_addr[2] << 16) |
677 (sc->atse_eth_addr[1] << 8) | sc->atse_eth_addr[0];
678 v1 = (sc->atse_eth_addr[5] << 8) | sc->atse_eth_addr[4];
680 if (n & ATSE_ETH_ADDR_DEF) {
681 CSR_WRITE_4(sc, BASE_CFG_MAC_0, v0);
682 CSR_WRITE_4(sc, BASE_CFG_MAC_1, v1);
684 if (n & ATSE_ETH_ADDR_SUPP1) {
685 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_0_0, v0);
686 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_0_1, v1);
688 if (n & ATSE_ETH_ADDR_SUPP2) {
689 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_1_0, v0);
690 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_1_1, v1);
692 if (n & ATSE_ETH_ADDR_SUPP3) {
693 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_2_0, v0);
694 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_2_1, v1);
696 if (n & ATSE_ETH_ADDR_SUPP4) {
697 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_3_0, v0);
698 CSR_WRITE_4(sc, SUPPL_ADDR_SMAC_3_1, v1);
705 atse_reset(struct atse_softc *sc)
711 /* 1. External PHY Initialization using MDIO. */
713 * We select the right MDIO space in atse_attach() and let MII do
717 /* 2. PCS Configuration Register Initialization. */
718 /* a. Set auto negotiation link timer to 1.6ms for SGMII. */
719 PCS_WRITE_2(sc, PCS_EXT_LINK_TIMER_0, 0x0D40);
720 PCS_WRITE_2(sc, PCS_EXT_LINK_TIMER_1, 0x0003);
722 /* b. Configure SGMII. */
723 val = PCS_EXT_IF_MODE_SGMII_ENA|PCS_EXT_IF_MODE_USE_SGMII_AN;
724 PCS_WRITE_2(sc, PCS_EXT_IF_MODE, val);
726 /* c. Enable auto negotiation. */
727 /* Ignore Bits 6,8,13; should be set,set,unset. */
728 val = PCS_READ_2(sc, PCS_CONTROL);
729 val &= ~(PCS_CONTROL_ISOLATE|PCS_CONTROL_POWERDOWN);
730 val &= ~PCS_CONTROL_LOOPBACK; /* Make this a -link1 option? */
731 val |= PCS_CONTROL_AUTO_NEGOTIATION_ENABLE;
732 PCS_WRITE_2(sc, PCS_CONTROL, val);
735 val = PCS_READ_2(sc, PCS_CONTROL);
736 val |= PCS_CONTROL_RESET;
737 PCS_WRITE_2(sc, PCS_CONTROL, val);
739 /* Wait for reset bit to clear; i=100 is excessive. */
740 for (i = 0; i < 100; i++) {
741 val = PCS_READ_2(sc, PCS_CONTROL);
742 if ((val & PCS_CONTROL_RESET) == 0) {
748 if ((val & PCS_CONTROL_RESET) != 0) {
749 device_printf(sc->atse_dev, "PCS reset timed out.\n");
753 /* 3. MAC Configuration Register Initialization. */
754 /* a. Disable MAC transmit and receive datapath. */
755 mask = BASE_CFG_COMMAND_CONFIG_TX_ENA|BASE_CFG_COMMAND_CONFIG_RX_ENA;
756 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
758 /* Samples in the manual do have the SW_RESET bit set here, why? */
759 CSR_WRITE_4(sc, BASE_CFG_COMMAND_CONFIG, val4);
760 /* Wait for bits to be cleared; i=100 is excessive. */
761 for (i = 0; i < 100; i++) {
762 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
763 if ((val4 & mask) == 0) {
768 if ((val4 & mask) != 0) {
769 device_printf(sc->atse_dev, "Disabling MAC TX/RX timed out.\n");
772 /* b. MAC FIFO configuration. */
773 CSR_WRITE_4(sc, BASE_CFG_TX_SECTION_EMPTY, FIFO_DEPTH_TX - 16);
774 CSR_WRITE_4(sc, BASE_CFG_TX_ALMOST_FULL, 3);
775 CSR_WRITE_4(sc, BASE_CFG_TX_ALMOST_EMPTY, 8);
776 CSR_WRITE_4(sc, BASE_CFG_RX_SECTION_EMPTY, FIFO_DEPTH_RX - 16);
777 CSR_WRITE_4(sc, BASE_CFG_RX_ALMOST_FULL, 8);
778 CSR_WRITE_4(sc, BASE_CFG_RX_ALMOST_EMPTY, 8);
780 CSR_WRITE_4(sc, BASE_CFG_TX_SECTION_FULL, 16);
781 CSR_WRITE_4(sc, BASE_CFG_RX_SECTION_FULL, 16);
783 /* For store-and-forward mode, set this threshold to 0. */
784 CSR_WRITE_4(sc, BASE_CFG_TX_SECTION_FULL, 0);
785 CSR_WRITE_4(sc, BASE_CFG_RX_SECTION_FULL, 0);
787 /* c. MAC address configuration. */
788 /* Also intialize supplementary addresses to our primary one. */
789 /* XXX-BZ FreeBSD really needs to grow and API for using these. */
790 atse_get_eth_address(sc);
791 atse_set_eth_address(sc, ATSE_ETH_ADDR_ALL);
793 /* d. MAC function configuration. */
794 CSR_WRITE_4(sc, BASE_CFG_FRM_LENGTH, 1518); /* Default. */
795 CSR_WRITE_4(sc, BASE_CFG_TX_IPG_LENGTH, 12);
796 CSR_WRITE_4(sc, BASE_CFG_PAUSE_QUANT, 0xFFFF);
798 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
800 * If 1000BASE-X/SGMII PCS is initialized, set the ETH_SPEED (bit 3)
801 * and ENA_10 (bit 25) in command_config register to 0. If half duplex
802 * is reported in the PHY/PCS status register, set the HD_ENA (bit 10)
803 * to 1 in command_config register.
804 * BZ: We shoot for 1000 instead.
807 val4 |= BASE_CFG_COMMAND_CONFIG_ETH_SPEED;
809 val4 &= ~BASE_CFG_COMMAND_CONFIG_ETH_SPEED;
811 val4 &= ~BASE_CFG_COMMAND_CONFIG_ENA_10;
814 * We do not want to set this, otherwise, we could not even send
815 * random raw ethernet frames for various other research. By default
816 * FreeBSD will use the right ether source address.
818 val4 |= BASE_CFG_COMMAND_CONFIG_TX_ADDR_INS;
820 val4 |= BASE_CFG_COMMAND_CONFIG_PAD_EN;
821 val4 &= ~BASE_CFG_COMMAND_CONFIG_CRC_FWD;
823 val4 |= BASE_CFG_COMMAND_CONFIG_CNTL_FRM_ENA;
826 val4 |= BASE_CFG_COMMAND_CONFIG_RX_ERR_DISC;
828 val &= ~BASE_CFG_COMMAND_CONFIG_LOOP_ENA; /* link0? */
829 CSR_WRITE_4(sc, BASE_CFG_COMMAND_CONFIG, val4);
832 * Make sure we do not enable 32bit alignment; FreeBSD cannot
833 * cope with the additional padding (though we should!?).
834 * Also make sure we get the CRC appended.
836 val4 = CSR_READ_4(sc, TX_CMD_STAT);
837 val4 &= ~(TX_CMD_STAT_OMIT_CRC|TX_CMD_STAT_TX_SHIFT16);
838 CSR_WRITE_4(sc, TX_CMD_STAT, val4);
840 val4 = CSR_READ_4(sc, RX_CMD_STAT);
841 val4 &= ~RX_CMD_STAT_RX_SHIFT16;
842 val4 |= RX_CMD_STAT_RX_SHIFT16;
843 CSR_WRITE_4(sc, RX_CMD_STAT, val4);
846 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
847 val4 |= BASE_CFG_COMMAND_CONFIG_SW_RESET;
848 CSR_WRITE_4(sc, BASE_CFG_COMMAND_CONFIG, val4);
849 /* Wait for bits to be cleared; i=100 is excessive. */
850 for (i = 0; i < 100; i++) {
851 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
852 if ((val4 & BASE_CFG_COMMAND_CONFIG_SW_RESET) == 0) {
857 if ((val4 & BASE_CFG_COMMAND_CONFIG_SW_RESET) != 0) {
858 device_printf(sc->atse_dev, "MAC reset timed out.\n");
862 /* f. Enable MAC transmit and receive datapath. */
863 mask = BASE_CFG_COMMAND_CONFIG_TX_ENA|BASE_CFG_COMMAND_CONFIG_RX_ENA;
864 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
866 CSR_WRITE_4(sc, BASE_CFG_COMMAND_CONFIG, val4);
867 /* Wait for bits to be cleared; i=100 is excessive. */
868 for (i = 0; i < 100; i++) {
869 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
870 if ((val4 & mask) == mask) {
875 if ((val4 & mask) != mask) {
876 device_printf(sc->atse_dev, "Enabling MAC TX/RX timed out.\n");
884 atse_init_locked(struct atse_softc *sc)
887 struct mii_data *mii;
890 ATSE_LOCK_ASSERT(sc);
893 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
898 * Must update the ether address if changed. Given we do not handle
899 * in atse_ioctl() but it's in the general framework, just always
900 * do it here before atse_reset().
902 eaddr = IF_LLADDR(sc->atse_ifp);
903 bcopy(eaddr, &sc->atse_eth_addr, ETHER_ADDR_LEN);
905 /* Make things frind to halt, cleanup, ... */
906 atse_stop_locked(sc);
910 /* ... and fire up the engine again. */
911 atse_rxfilter_locked(sc);
913 sc->atse_flags &= ATSE_FLAGS_LINK; /* Preserve. */
915 mii = device_get_softc(sc->atse_miibus);
917 sc->atse_flags &= ~ATSE_FLAGS_LINK;
920 ifp->if_drv_flags |= IFF_DRV_RUNNING;
921 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
923 callout_reset(&sc->atse_tick, hz, atse_tick, sc);
929 struct atse_softc *sc;
932 * XXXRW: There is some argument that we should immediately do RX
933 * processing after enabling interrupts, or one may not fire if there
934 * are buffered packets.
936 sc = (struct atse_softc *)xsc;
938 atse_init_locked(sc);
943 atse_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
945 struct atse_softc *sc;
951 ifr = (struct ifreq *)data;
956 if (ifp->if_flags & IFF_UP) {
957 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0 &&
958 ((ifp->if_flags ^ sc->atse_if_flags) &
959 (IFF_PROMISC | IFF_ALLMULTI)) != 0)
960 atse_rxfilter_locked(sc);
962 atse_init_locked(sc);
963 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING)
964 atse_stop_locked(sc);
965 sc->atse_if_flags = ifp->if_flags;
970 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
976 atse_rxfilter_locked(sc);
982 struct mii_data *mii;
985 mii = device_get_softc(sc->atse_miibus);
986 ifr = (struct ifreq *)data;
987 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
991 error = ether_ioctl(ifp, command, data);
1001 struct atse_softc *sc;
1002 struct mii_data *mii;
1005 sc = (struct atse_softc *)xsc;
1006 ATSE_LOCK_ASSERT(sc);
1009 mii = device_get_softc(sc->atse_miibus);
1011 if ((sc->atse_flags & ATSE_FLAGS_LINK) == 0) {
1012 atse_miibus_statchg(sc->atse_dev);
1015 callout_reset(&sc->atse_tick, hz, atse_tick, sc);
1019 * Set media options.
1022 atse_ifmedia_upd(struct ifnet *ifp)
1024 struct atse_softc *sc;
1025 struct mii_data *mii;
1026 struct mii_softc *miisc;
1032 mii = device_get_softc(sc->atse_miibus);
1033 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
1036 error = mii_mediachg(mii);
1043 * Report current media status.
1046 atse_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1048 struct atse_softc *sc;
1049 struct mii_data *mii;
1054 mii = device_get_softc(sc->atse_miibus);
1056 ifmr->ifm_active = mii->mii_media_active;
1057 ifmr->ifm_status = mii->mii_media_status;
1061 static struct atse_mac_stats_regs {
1063 const char *descr; /* Mostly copied from Altera datasheet. */
1064 } atse_mac_stats_regs[] = {
1066 { "aFramesTransmittedOK",
1067 "The number of frames that are successfully transmitted including "
1068 "the pause frames." },
1069 { "aFramesReceivedOK",
1070 "The number of frames that are successfully received including the "
1072 { "aFrameCheckSequenceErrors",
1073 "The number of receive frames with CRC error." },
1074 { "aAlignmentErrors",
1075 "The number of receive frames with alignment error." },
1076 { "aOctetsTransmittedOK",
1077 "The lower 32 bits of the number of data and padding octets that "
1078 "are successfully transmitted." },
1079 { "aOctetsReceivedOK",
1080 "The lower 32 bits of the number of data and padding octets that "
1081 " are successfully received." },
1082 { "aTxPAUSEMACCtrlFrames",
1083 "The number of pause frames transmitted." },
1084 { "aRxPAUSEMACCtrlFrames",
1085 "The number received pause frames received." },
1087 "The number of errored frames received." },
1089 "The number of transmit frames with either a FIFO overflow error, "
1090 "a FIFO underflow error, or a error defined by the user "
1093 "The number of valid unicast frames received." },
1094 { "ifInMulticastPkts",
1095 "The number of valid multicast frames received. The count does "
1096 "not include pause frames." },
1097 { "ifInBroadcastPkts",
1098 "The number of valid broadcast frames received." },
1100 "This statistics counter is not in use. The MAC function does not "
1101 "discard frames that are written to the FIFO buffer by the user "
1104 "The number of valid unicast frames transmitted." },
1105 { "ifOutMulticastPkts",
1106 "The number of valid multicast frames transmitted, excluding pause "
1108 { "ifOutBroadcastPkts",
1109 "The number of valid broadcast frames transmitted." },
1110 { "etherStatsDropEvents",
1111 "The number of frames that are dropped due to MAC internal errors "
1112 "when FIFO buffer overflow persists." },
1113 { "etherStatsOctets",
1114 "The lower 32 bits of the total number of octets received. This "
1115 "count includes both good and errored frames." },
1117 "The total number of good and errored frames received." },
1118 { "etherStatsUndersizePkts",
1119 "The number of frames received with length less than 64 bytes. "
1120 "This count does not include errored frames." },
1121 { "etherStatsOversizePkts",
1122 "The number of frames received that are longer than the value "
1123 "configured in the frm_length register. This count does not "
1124 "include errored frames." },
1125 { "etherStatsPkts64Octets",
1126 "The number of 64-byte frames received. This count includes good "
1127 "and errored frames." },
1128 { "etherStatsPkts65to127Octets",
1129 "The number of received good and errored frames between the length "
1130 "of 65 and 127 bytes." },
1131 { "etherStatsPkts128to255Octets",
1132 "The number of received good and errored frames between the length "
1133 "of 128 and 255 bytes." },
1134 { "etherStatsPkts256to511Octets",
1135 "The number of received good and errored frames between the length "
1136 "of 256 and 511 bytes." },
1137 { "etherStatsPkts512to1023Octets",
1138 "The number of received good and errored frames between the length "
1139 "of 512 and 1023 bytes." },
1140 { "etherStatsPkts1024to1518Octets",
1141 "The number of received good and errored frames between the length "
1142 "of 1024 and 1518 bytes." },
1143 { "etherStatsPkts1519toXOctets",
1144 "The number of received good and errored frames between the length "
1145 "of 1519 and the maximum frame length configured in the frm_length "
1147 { "etherStatsJabbers",
1148 "Too long frames with CRC error." },
1149 { "etherStatsFragments",
1150 "Too short frames with CRC error." },
1151 /* 0x39 unused, 0x3a/b non-stats. */
1153 /* Extended Statistics Counters */
1154 { "msb_aOctetsTransmittedOK",
1155 "Upper 32 bits of the number of data and padding octets that are "
1156 "successfully transmitted." },
1157 { "msb_aOctetsReceivedOK",
1158 "Upper 32 bits of the number of data and padding octets that are "
1159 "successfully received." },
1160 { "msb_etherStatsOctets",
1161 "Upper 32 bits of the total number of octets received. This count "
1162 "includes both good and errored frames." }
1166 sysctl_atse_mac_stats_proc(SYSCTL_HANDLER_ARGS)
1168 struct atse_softc *sc;
1169 int error, offset, s;
1174 s = CSR_READ_4(sc, offset);
1175 error = sysctl_handle_int(oidp, &s, 0, req);
1176 if (error || !req->newptr) {
1183 static struct atse_rx_err_stats_regs {
1186 } atse_rx_err_stats_regs[] = {
1188 #define ATSE_RX_ERR_FIFO_THRES_EOP 0 /* FIFO threshold reached, on EOP. */
1189 #define ATSE_RX_ERR_ELEN 1 /* Frame/payload length not valid. */
1190 #define ATSE_RX_ERR_CRC32 2 /* CRC-32 error. */
1191 #define ATSE_RX_ERR_FIFO_THRES_TRUNC 3 /* FIFO thresh., truncated frame. */
1192 #define ATSE_RX_ERR_4 4 /* ? */
1193 #define ATSE_RX_ERR_5 5 /* / */
1195 { "rx_err_fifo_thres_eop",
1196 "FIFO threshold reached, reported on EOP." },
1197 { "rx_err_fifo_elen",
1198 "Frame or payload length not valid." },
1199 { "rx_err_fifo_crc32",
1201 { "rx_err_fifo_thres_trunc",
1202 "FIFO threshold reached, truncated frame" },
1210 sysctl_atse_rx_err_stats_proc(SYSCTL_HANDLER_ARGS)
1212 struct atse_softc *sc;
1213 int error, offset, s;
1218 s = sc->atse_rx_err[offset];
1219 error = sysctl_handle_int(oidp, &s, 0, req);
1220 if (error || !req->newptr) {
1228 atse_sysctl_stats_attach(device_t dev)
1230 struct sysctl_ctx_list *sctx;
1231 struct sysctl_oid *soid;
1232 struct atse_softc *sc;
1235 sc = device_get_softc(dev);
1236 sctx = device_get_sysctl_ctx(dev);
1237 soid = device_get_sysctl_tree(dev);
1239 /* MAC statistics. */
1240 for (i = 0; i < nitems(atse_mac_stats_regs); i++) {
1241 if (atse_mac_stats_regs[i].name == NULL ||
1242 atse_mac_stats_regs[i].descr == NULL) {
1246 SYSCTL_ADD_PROC(sctx, SYSCTL_CHILDREN(soid), OID_AUTO,
1247 atse_mac_stats_regs[i].name, CTLTYPE_UINT|CTLFLAG_RD,
1248 sc, i, sysctl_atse_mac_stats_proc, "IU",
1249 atse_mac_stats_regs[i].descr);
1253 for (i = 0; i < ATSE_RX_ERR_MAX; i++) {
1254 if (atse_rx_err_stats_regs[i].name == NULL ||
1255 atse_rx_err_stats_regs[i].descr == NULL) {
1259 SYSCTL_ADD_PROC(sctx, SYSCTL_CHILDREN(soid), OID_AUTO,
1260 atse_rx_err_stats_regs[i].name, CTLTYPE_UINT|CTLFLAG_RD,
1261 sc, i, sysctl_atse_rx_err_stats_proc, "IU",
1262 atse_rx_err_stats_regs[i].descr);
1267 * Generic device handling routines.
1270 atse_attach(device_t dev)
1272 struct atse_softc *sc;
1277 sc = device_get_softc(dev);
1280 /* Get xDMA controller */
1281 sc->xdma_tx = xdma_ofw_get(sc->dev, "tx");
1282 if (sc->xdma_tx == NULL) {
1283 device_printf(dev, "Can't find DMA controller.\n");
1288 * Only final (EOP) write can be less than "symbols per beat" value
1289 * so we have to defrag mbuf chain.
1290 * Chapter 15. On-Chip FIFO Memory Core.
1291 * Embedded Peripherals IP User Guide.
1293 caps = XCHAN_CAP_BUSDMA_NOSEG;
1295 /* Alloc xDMA virtual channel. */
1296 sc->xchan_tx = xdma_channel_alloc(sc->xdma_tx, caps);
1297 if (sc->xchan_tx == NULL) {
1298 device_printf(dev, "Can't alloc virtual DMA channel.\n");
1302 /* Setup interrupt handler. */
1303 error = xdma_setup_intr(sc->xchan_tx, atse_xdma_tx_intr, sc, &sc->ih_tx);
1305 device_printf(sc->dev,
1306 "Can't setup xDMA interrupt handler.\n");
1310 xdma_prep_sg(sc->xchan_tx,
1311 TX_QUEUE_SIZE, /* xchan requests queue size */
1312 MCLBYTES, /* maxsegsize */
1316 BUS_SPACE_MAXADDR_32BIT,
1319 /* Get RX xDMA controller */
1320 sc->xdma_rx = xdma_ofw_get(sc->dev, "rx");
1321 if (sc->xdma_rx == NULL) {
1322 device_printf(dev, "Can't find DMA controller.\n");
1326 /* Alloc xDMA virtual channel. */
1327 sc->xchan_rx = xdma_channel_alloc(sc->xdma_rx, caps);
1328 if (sc->xchan_rx == NULL) {
1329 device_printf(dev, "Can't alloc virtual DMA channel.\n");
1333 /* Setup interrupt handler. */
1334 error = xdma_setup_intr(sc->xchan_rx, atse_xdma_rx_intr, sc, &sc->ih_rx);
1336 device_printf(sc->dev,
1337 "Can't setup xDMA interrupt handler.\n");
1341 xdma_prep_sg(sc->xchan_rx,
1342 RX_QUEUE_SIZE, /* xchan requests queue size */
1343 MCLBYTES, /* maxsegsize */
1347 BUS_SPACE_MAXADDR_32BIT,
1350 mtx_init(&sc->br_mtx, "buf ring mtx", NULL, MTX_DEF);
1351 sc->br = buf_ring_alloc(BUFRING_SIZE, M_DEVBUF,
1352 M_NOWAIT, &sc->br_mtx);
1353 if (sc->br == NULL) {
1357 atse_ethernet_option_bits_read(dev);
1359 mtx_init(&sc->atse_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
1362 callout_init_mtx(&sc->atse_tick, &sc->atse_mtx, 0);
1365 * We are only doing single-PHY with this driver currently. The
1366 * defaults would be right so that BASE_CFG_MDIO_ADDR0 points to the
1367 * 1st PHY address (0) apart from the fact that BMCR0 is always
1368 * the PCS mapping, so we always use BMCR1. See Table 5-1 0xA0-0xBF.
1370 #if 0 /* Always PCS. */
1371 sc->atse_bmcr0 = MDIO_0_START;
1372 CSR_WRITE_4(sc, BASE_CFG_MDIO_ADDR0, 0x00);
1374 /* Always use matching PHY for atse[0..]. */
1375 sc->atse_phy_addr = device_get_unit(dev);
1376 sc->atse_bmcr1 = MDIO_1_START;
1377 CSR_WRITE_4(sc, BASE_CFG_MDIO_ADDR1, sc->atse_phy_addr);
1379 /* Reset the adapter. */
1382 /* Setup interface. */
1383 ifp = sc->atse_ifp = if_alloc(IFT_ETHER);
1385 device_printf(dev, "if_alloc() failed\n");
1390 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1391 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1392 ifp->if_ioctl = atse_ioctl;
1393 ifp->if_transmit = atse_transmit;
1394 ifp->if_qflush = atse_qflush;
1395 ifp->if_init = atse_init;
1396 IFQ_SET_MAXLEN(&ifp->if_snd, ATSE_TX_LIST_CNT - 1);
1397 ifp->if_snd.ifq_drv_maxlen = ATSE_TX_LIST_CNT - 1;
1398 IFQ_SET_READY(&ifp->if_snd);
1401 error = mii_attach(dev, &sc->atse_miibus, ifp, atse_ifmedia_upd,
1402 atse_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
1404 device_printf(dev, "attaching PHY failed: %d\n", error);
1408 /* Call media-indepedent attach routine. */
1409 ether_ifattach(ifp, sc->atse_eth_addr);
1411 /* Tell the upper layer(s) about vlan mtu support. */
1412 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
1413 ifp->if_capabilities |= IFCAP_VLAN_MTU;
1414 ifp->if_capenable = ifp->if_capabilities;
1422 atse_sysctl_stats_attach(dev);
1425 atse_rx_enqueue(sc, NUM_RX_MBUF);
1426 xdma_queue_submit(sc->xchan_rx);
1432 atse_detach(device_t dev)
1434 struct atse_softc *sc;
1437 sc = device_get_softc(dev);
1438 KASSERT(mtx_initialized(&sc->atse_mtx), ("%s: mutex not initialized",
1439 device_get_nameunit(dev)));
1442 /* Only cleanup if attach succeeded. */
1443 if (device_is_attached(dev)) {
1445 atse_stop_locked(sc);
1447 callout_drain(&sc->atse_tick);
1448 ether_ifdetach(ifp);
1450 if (sc->atse_miibus != NULL) {
1451 device_delete_child(dev, sc->atse_miibus);
1458 mtx_destroy(&sc->atse_mtx);
1463 /* Shared between nexus and fdt implementation. */
1465 atse_detach_resources(device_t dev)
1467 struct atse_softc *sc;
1469 sc = device_get_softc(dev);
1471 if (sc->atse_mem_res != NULL) {
1472 bus_release_resource(dev, SYS_RES_MEMORY, sc->atse_mem_rid,
1474 sc->atse_mem_res = NULL;
1479 atse_detach_dev(device_t dev)
1483 error = atse_detach(dev);
1485 /* We are basically in undefined state now. */
1486 device_printf(dev, "atse_detach() failed: %d\n", error);
1490 atse_detach_resources(dev);
1496 atse_miibus_readreg(device_t dev, int phy, int reg)
1498 struct atse_softc *sc;
1501 sc = device_get_softc(dev);
1504 * We currently do not support re-mapping of MDIO space on-the-fly
1505 * but de-facto hard-code the phy#.
1507 if (phy != sc->atse_phy_addr) {
1511 val = PHY_READ_2(sc, reg);
1517 atse_miibus_writereg(device_t dev, int phy, int reg, int data)
1519 struct atse_softc *sc;
1521 sc = device_get_softc(dev);
1524 * We currently do not support re-mapping of MDIO space on-the-fly
1525 * but de-facto hard-code the phy#.
1527 if (phy != sc->atse_phy_addr) {
1531 PHY_WRITE_2(sc, reg, data);
1536 atse_miibus_statchg(device_t dev)
1538 struct atse_softc *sc;
1539 struct mii_data *mii;
1543 sc = device_get_softc(dev);
1544 ATSE_LOCK_ASSERT(sc);
1546 mii = device_get_softc(sc->atse_miibus);
1548 if (mii == NULL || ifp == NULL ||
1549 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
1553 val4 = CSR_READ_4(sc, BASE_CFG_COMMAND_CONFIG);
1555 /* Assume no link. */
1556 sc->atse_flags &= ~ATSE_FLAGS_LINK;
1558 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
1559 (IFM_ACTIVE | IFM_AVALID)) {
1561 switch (IFM_SUBTYPE(mii->mii_media_active)) {
1563 val4 |= BASE_CFG_COMMAND_CONFIG_ENA_10;
1564 val4 &= ~BASE_CFG_COMMAND_CONFIG_ETH_SPEED;
1565 sc->atse_flags |= ATSE_FLAGS_LINK;
1568 val4 &= ~BASE_CFG_COMMAND_CONFIG_ENA_10;
1569 val4 &= ~BASE_CFG_COMMAND_CONFIG_ETH_SPEED;
1570 sc->atse_flags |= ATSE_FLAGS_LINK;
1573 val4 &= ~BASE_CFG_COMMAND_CONFIG_ENA_10;
1574 val4 |= BASE_CFG_COMMAND_CONFIG_ETH_SPEED;
1575 sc->atse_flags |= ATSE_FLAGS_LINK;
1582 if ((sc->atse_flags & ATSE_FLAGS_LINK) == 0) {
1583 /* Need to stop the MAC? */
1587 if (IFM_OPTIONS(mii->mii_media_active & IFM_FDX) != 0) {
1588 val4 &= ~BASE_CFG_COMMAND_CONFIG_HD_ENA;
1590 val4 |= BASE_CFG_COMMAND_CONFIG_HD_ENA;
1595 /* Make sure the MAC is activated. */
1596 val4 |= BASE_CFG_COMMAND_CONFIG_TX_ENA;
1597 val4 |= BASE_CFG_COMMAND_CONFIG_RX_ENA;
1599 CSR_WRITE_4(sc, BASE_CFG_COMMAND_CONFIG, val4);
1602 MODULE_DEPEND(atse, ether, 1, 1, 1);
1603 MODULE_DEPEND(atse, miibus, 1, 1, 1);