1 1.66 thorpej /* $NetBSD: if_bm.c,v 1.66 2025/10/04 04:44:20 thorpej Exp $ */ 2 1.1 tsubai 3 1.1 tsubai /*- 4 1.4 tsubai * Copyright (C) 1998, 1999, 2000 Tsubai Masanari. All rights reserved. 5 1.1 tsubai * 6 1.1 tsubai * Redistribution and use in source and binary forms, with or without 7 1.1 tsubai * modification, are permitted provided that the following conditions 8 1.1 tsubai * are met: 9 1.1 tsubai * 1. Redistributions of source code must retain the above copyright 10 1.1 tsubai * notice, this list of conditions and the following disclaimer. 11 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 tsubai * notice, this list of conditions and the following disclaimer in the 13 1.1 tsubai * documentation and/or other materials provided with the distribution. 14 1.1 tsubai * 3. The name of the author may not be used to endorse or promote products 15 1.1 tsubai * derived from this software without specific prior written permission. 16 1.1 tsubai * 17 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 1.1 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 1.1 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 1.1 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 1.1 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 1.1 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 1.1 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 1.1 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 1.1 tsubai */ 28 1.21 lukem 29 1.21 lukem #include <sys/cdefs.h> 30 1.66 thorpej __KERNEL_RCSID(0, "$NetBSD: if_bm.c,v 1.66 2025/10/04 04:44:20 thorpej Exp $"); 31 1.1 tsubai 32 1.1 tsubai #include "opt_inet.h" 33 1.1 tsubai 34 1.1 tsubai #include <sys/param.h> 35 1.1 tsubai #include <sys/device.h> 36 1.1 tsubai #include <sys/ioctl.h> 37 1.4 tsubai #include <sys/kernel.h> 38 1.1 tsubai #include <sys/mbuf.h> 39 1.1 tsubai #include <sys/socket.h> 40 1.1 tsubai #include <sys/systm.h> 41 1.7 thorpej #include <sys/callout.h> 42 1.1 tsubai 43 1.10 mrg #include <uvm/uvm_extern.h> 44 1.4 tsubai 45 1.1 tsubai #include <net/if.h> 46 1.22 matt #include <net/if_dl.h> 47 1.1 tsubai #include <net/if_ether.h> 48 1.1 tsubai #include <net/if_media.h> 49 1.1 tsubai 50 1.1 tsubai #include <net/bpf.h> 51 1.1 tsubai 52 1.4 tsubai #ifdef INET 53 1.4 tsubai #include <netinet/in.h> 54 1.4 tsubai #include <netinet/if_inarp.h> 55 1.4 tsubai #endif 56 1.1 tsubai 57 1.22 matt 58 1.1 tsubai #include <dev/ofw/openfirm.h> 59 1.1 tsubai 60 1.4 tsubai #include <dev/mii/mii.h> 61 1.4 tsubai #include <dev/mii/miivar.h> 62 1.4 tsubai #include <dev/mii/mii_bitbang.h> 63 1.4 tsubai 64 1.24 kleink #include <powerpc/spr.h> 65 1.42 matt #include <powerpc/oea/spr.h> 66 1.24 kleink 67 1.1 tsubai #include <machine/autoconf.h> 68 1.1 tsubai #include <machine/pio.h> 69 1.1 tsubai 70 1.1 tsubai #include <macppc/dev/dbdma.h> 71 1.1 tsubai #include <macppc/dev/if_bmreg.h> 72 1.37 macallan #include <macppc/dev/obiovar.h> 73 1.1 tsubai 74 1.1 tsubai #define BMAC_TXBUFS 2 75 1.1 tsubai #define BMAC_RXBUFS 16 76 1.1 tsubai #define BMAC_BUFLEN 2048 77 1.1 tsubai 78 1.1 tsubai struct bmac_softc { 79 1.44 matt device_t sc_dev; 80 1.1 tsubai struct ethercom sc_ethercom; 81 1.1 tsubai #define sc_if sc_ethercom.ec_if 82 1.7 thorpej struct callout sc_tick_ch; 83 1.34 garbled bus_space_tag_t sc_iot; 84 1.34 garbled bus_space_handle_t sc_ioh; 85 1.1 tsubai dbdma_regmap_t *sc_txdma; 86 1.1 tsubai dbdma_regmap_t *sc_rxdma; 87 1.1 tsubai dbdma_command_t *sc_txcmd; 88 1.1 tsubai dbdma_command_t *sc_rxcmd; 89 1.30 christos void *sc_txbuf; 90 1.30 christos void *sc_rxbuf; 91 1.1 tsubai int sc_rxlast; 92 1.1 tsubai int sc_flags; 93 1.65 thorpej bool sc_txbusy; 94 1.4 tsubai struct mii_data sc_mii; 95 1.1 tsubai u_char sc_enaddr[6]; 96 1.1 tsubai }; 97 1.1 tsubai 98 1.1 tsubai #define BMAC_BMACPLUS 0x01 99 1.4 tsubai #define BMAC_DEBUGFLAG 0x02 100 1.1 tsubai 101 1.44 matt int bmac_match(device_t, cfdata_t, void *); 102 1.44 matt void bmac_attach(device_t, device_t, void *); 103 1.35 dyoung void bmac_reset_chip(struct bmac_softc *); 104 1.35 dyoung void bmac_init(struct bmac_softc *); 105 1.35 dyoung void bmac_init_dma(struct bmac_softc *); 106 1.35 dyoung int bmac_intr(void *); 107 1.35 dyoung int bmac_rint(void *); 108 1.35 dyoung void bmac_reset(struct bmac_softc *); 109 1.35 dyoung void bmac_stop(struct bmac_softc *); 110 1.35 dyoung void bmac_start(struct ifnet *); 111 1.35 dyoung void bmac_transmit_packet(struct bmac_softc *, void *, int); 112 1.35 dyoung int bmac_put(struct bmac_softc *, void *, struct mbuf *); 113 1.35 dyoung struct mbuf *bmac_get(struct bmac_softc *, void *, int); 114 1.35 dyoung void bmac_watchdog(struct ifnet *); 115 1.35 dyoung int bmac_ioctl(struct ifnet *, u_long, void *); 116 1.35 dyoung void bmac_setladrf(struct bmac_softc *); 117 1.35 dyoung 118 1.56 msaitoh int bmac_mii_readreg(device_t, int, int, uint16_t *); 119 1.56 msaitoh int bmac_mii_writereg(device_t, int, int, uint16_t); 120 1.46 matt void bmac_mii_statchg(struct ifnet *); 121 1.35 dyoung void bmac_mii_tick(void *); 122 1.59 msaitoh uint32_t bmac_mbo_read(device_t); 123 1.59 msaitoh void bmac_mbo_write(device_t, uint32_t); 124 1.1 tsubai 125 1.44 matt CFATTACH_DECL_NEW(bm, sizeof(struct bmac_softc), 126 1.19 thorpej bmac_match, bmac_attach, NULL, NULL); 127 1.1 tsubai 128 1.34 garbled const struct mii_bitbang_ops bmac_mbo = { 129 1.4 tsubai bmac_mbo_read, bmac_mbo_write, 130 1.4 tsubai { MIFDO, MIFDI, MIFDC, MIFDIR, 0 } 131 1.4 tsubai }; 132 1.4 tsubai 133 1.34 garbled static inline uint16_t 134 1.34 garbled bmac_read_reg(struct bmac_softc *sc, bus_size_t off) 135 1.1 tsubai { 136 1.34 garbled return bus_space_read_2(sc->sc_iot, sc->sc_ioh, off); 137 1.1 tsubai } 138 1.1 tsubai 139 1.34 garbled static inline void 140 1.34 garbled bmac_write_reg(struct bmac_softc *sc, bus_size_t off, uint16_t val) 141 1.1 tsubai { 142 1.34 garbled bus_space_write_2(sc->sc_iot, sc->sc_ioh, off, val); 143 1.1 tsubai } 144 1.1 tsubai 145 1.34 garbled static inline void 146 1.34 garbled bmac_set_bits(struct bmac_softc *sc, bus_size_t off, uint16_t val) 147 1.1 tsubai { 148 1.1 tsubai val |= bmac_read_reg(sc, off); 149 1.1 tsubai bmac_write_reg(sc, off, val); 150 1.1 tsubai } 151 1.1 tsubai 152 1.34 garbled static inline void 153 1.34 garbled bmac_reset_bits(struct bmac_softc *sc, bus_size_t off, uint16_t val) 154 1.1 tsubai { 155 1.1 tsubai bmac_write_reg(sc, off, bmac_read_reg(sc, off) & ~val); 156 1.1 tsubai } 157 1.1 tsubai 158 1.1 tsubai int 159 1.44 matt bmac_match(device_t parent, cfdata_t cf, void *aux) 160 1.1 tsubai { 161 1.1 tsubai struct confargs *ca = aux; 162 1.1 tsubai 163 1.1 tsubai if (ca->ca_nreg < 24 || ca->ca_nintr < 12) 164 1.1 tsubai return 0; 165 1.1 tsubai 166 1.1 tsubai if (strcmp(ca->ca_name, "bmac") == 0) /* bmac */ 167 1.1 tsubai return 1; 168 1.1 tsubai if (strcmp(ca->ca_name, "ethernet") == 0) /* bmac+ */ 169 1.1 tsubai return 1; 170 1.1 tsubai 171 1.1 tsubai return 0; 172 1.1 tsubai } 173 1.1 tsubai 174 1.1 tsubai void 175 1.44 matt bmac_attach(device_t parent, device_t self, void *aux) 176 1.1 tsubai { 177 1.1 tsubai struct confargs *ca = aux; 178 1.44 matt struct bmac_softc *sc = device_private(self); 179 1.1 tsubai struct ifnet *ifp = &sc->sc_if; 180 1.4 tsubai struct mii_data *mii = &sc->sc_mii; 181 1.1 tsubai u_char laddr[6]; 182 1.64 rin char intr_xname[INTRDEVNAMEBUF]; 183 1.1 tsubai 184 1.32 ad callout_init(&sc->sc_tick_ch, 0); 185 1.7 thorpej 186 1.44 matt sc->sc_dev = self; 187 1.44 matt sc->sc_flags = 0; 188 1.3 tsubai if (strcmp(ca->ca_name, "ethernet") == 0) { 189 1.3 tsubai char name[64]; 190 1.3 tsubai 191 1.16 wiz memset(name, 0, 64); 192 1.3 tsubai OF_package_to_path(ca->ca_node, name, sizeof(name)); 193 1.3 tsubai OF_open(name); 194 1.1 tsubai sc->sc_flags |= BMAC_BMACPLUS; 195 1.3 tsubai } 196 1.1 tsubai 197 1.1 tsubai ca->ca_reg[0] += ca->ca_baseaddr; 198 1.1 tsubai ca->ca_reg[2] += ca->ca_baseaddr; 199 1.1 tsubai ca->ca_reg[4] += ca->ca_baseaddr; 200 1.1 tsubai 201 1.34 garbled sc->sc_iot = ca->ca_tag; 202 1.34 garbled if (bus_space_map(sc->sc_iot, ca->ca_reg[0], ca->ca_reg[1], 0, 203 1.34 garbled &sc->sc_ioh) != 0) { 204 1.34 garbled aprint_error(": couldn't map %#x", ca->ca_reg[0]); 205 1.34 garbled return; 206 1.34 garbled } 207 1.1 tsubai 208 1.1 tsubai bmac_write_reg(sc, INTDISABLE, NoEventsMask); 209 1.1 tsubai 210 1.66 thorpej if (! ether_getaddr(self, laddr)) { 211 1.44 matt aprint_error(": cannot get mac-address\n"); 212 1.1 tsubai return; 213 1.1 tsubai } 214 1.16 wiz memcpy(sc->sc_enaddr, laddr, 6); 215 1.1 tsubai 216 1.45 matt sc->sc_txdma = mapiodev(ca->ca_reg[2], PAGE_SIZE, false); 217 1.45 matt sc->sc_rxdma = mapiodev(ca->ca_reg[4], PAGE_SIZE, false); 218 1.49 macallan sc->sc_txcmd = dbdma_alloc(BMAC_TXBUFS * sizeof(dbdma_command_t), NULL); 219 1.49 macallan sc->sc_rxcmd = dbdma_alloc((BMAC_RXBUFS + 1) * sizeof(dbdma_command_t), 220 1.49 macallan NULL); 221 1.61 chs sc->sc_txbuf = malloc(BMAC_BUFLEN * BMAC_TXBUFS, M_DEVBUF, M_WAITOK); 222 1.61 chs sc->sc_rxbuf = malloc(BMAC_BUFLEN * BMAC_RXBUFS, M_DEVBUF, M_WAITOK); 223 1.1 tsubai 224 1.44 matt aprint_normal(" irq %d,%d: address %s\n", 225 1.44 matt ca->ca_intr[0], ca->ca_intr[2], 226 1.44 matt ether_sprintf(laddr)); 227 1.1 tsubai 228 1.64 rin snprintf(intr_xname, sizeof(intr_xname), "%s tx", device_xname(self)); 229 1.64 rin intr_establish_xname(ca->ca_intr[0], IST_EDGE, IPL_NET, bmac_intr, sc, 230 1.64 rin intr_xname); 231 1.64 rin 232 1.64 rin snprintf(intr_xname, sizeof(intr_xname), "%s rx", device_xname(self)); 233 1.64 rin intr_establish_xname(ca->ca_intr[2], IST_EDGE, IPL_NET, bmac_rint, sc, 234 1.64 rin intr_xname); 235 1.1 tsubai 236 1.44 matt memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); 237 1.1 tsubai ifp->if_softc = sc; 238 1.1 tsubai ifp->if_ioctl = bmac_ioctl; 239 1.1 tsubai ifp->if_start = bmac_start; 240 1.57 msaitoh ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 241 1.1 tsubai ifp->if_watchdog = bmac_watchdog; 242 1.17 itojun IFQ_SET_READY(&ifp->if_snd); 243 1.1 tsubai 244 1.4 tsubai mii->mii_ifp = ifp; 245 1.4 tsubai mii->mii_readreg = bmac_mii_readreg; 246 1.4 tsubai mii->mii_writereg = bmac_mii_writereg; 247 1.4 tsubai mii->mii_statchg = bmac_mii_statchg; 248 1.4 tsubai 249 1.36 dyoung sc->sc_ethercom.ec_mii = mii; 250 1.36 dyoung ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus); 251 1.44 matt mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0); 252 1.4 tsubai 253 1.4 tsubai /* Choose a default media. */ 254 1.4 tsubai if (LIST_FIRST(&mii->mii_phys) == NULL) { 255 1.59 msaitoh ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_10_T, 0, NULL); 256 1.59 msaitoh ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_10_T); 257 1.4 tsubai } else 258 1.59 msaitoh ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); 259 1.1 tsubai 260 1.1 tsubai bmac_reset_chip(sc); 261 1.1 tsubai 262 1.1 tsubai if_attach(ifp); 263 1.52 ozaki if_deferred_start_init(ifp, NULL); 264 1.1 tsubai ether_ifattach(ifp, sc->sc_enaddr); 265 1.1 tsubai } 266 1.1 tsubai 267 1.1 tsubai /* 268 1.1 tsubai * Reset and enable bmac by heathrow FCR. 269 1.1 tsubai */ 270 1.1 tsubai void 271 1.39 dsl bmac_reset_chip(struct bmac_softc *sc) 272 1.1 tsubai { 273 1.1 tsubai u_int v; 274 1.1 tsubai 275 1.1 tsubai dbdma_reset(sc->sc_txdma); 276 1.1 tsubai dbdma_reset(sc->sc_rxdma); 277 1.1 tsubai 278 1.37 macallan v = obio_read_4(HEATHROW_FCR); 279 1.1 tsubai 280 1.1 tsubai v |= EnetEnable; 281 1.37 macallan obio_write_4(HEATHROW_FCR, v); 282 1.1 tsubai delay(50000); 283 1.1 tsubai 284 1.1 tsubai v |= ResetEnetCell; 285 1.37 macallan obio_write_4(HEATHROW_FCR, v); 286 1.1 tsubai delay(50000); 287 1.1 tsubai 288 1.1 tsubai v &= ~ResetEnetCell; 289 1.37 macallan obio_write_4(HEATHROW_FCR, v); 290 1.1 tsubai delay(50000); 291 1.1 tsubai 292 1.37 macallan obio_write_4(HEATHROW_FCR, v); 293 1.1 tsubai } 294 1.1 tsubai 295 1.1 tsubai void 296 1.39 dsl bmac_init(struct bmac_softc *sc) 297 1.1 tsubai { 298 1.1 tsubai struct ifnet *ifp = &sc->sc_if; 299 1.1 tsubai struct ether_header *eh; 300 1.30 christos void *data; 301 1.56 msaitoh int i, tb; 302 1.56 msaitoh uint16_t bmcr; 303 1.1 tsubai u_short *p; 304 1.1 tsubai 305 1.1 tsubai bmac_reset_chip(sc); 306 1.1 tsubai 307 1.4 tsubai /* XXX */ 308 1.56 msaitoh bmac_mii_readreg(sc->sc_dev, 0, MII_BMCR, &bmcr); 309 1.4 tsubai bmcr &= ~BMCR_ISO; 310 1.44 matt bmac_mii_writereg(sc->sc_dev, 0, MII_BMCR, bmcr); 311 1.4 tsubai 312 1.1 tsubai bmac_write_reg(sc, RXRST, RxResetValue); 313 1.1 tsubai bmac_write_reg(sc, TXRST, TxResetBit); 314 1.1 tsubai 315 1.1 tsubai /* Wait for reset completion. */ 316 1.4 tsubai for (i = 1000; i > 0; i -= 10) { 317 1.4 tsubai if ((bmac_read_reg(sc, TXRST) & TxResetBit) == 0) 318 1.4 tsubai break; 319 1.4 tsubai delay(10); 320 1.4 tsubai } 321 1.4 tsubai if (i <= 0) 322 1.4 tsubai printf("%s: reset timeout\n", ifp->if_xname); 323 1.1 tsubai 324 1.1 tsubai if (! (sc->sc_flags & BMAC_BMACPLUS)) 325 1.59 msaitoh bmac_set_bits(sc, XCVRIF, ClkBit | SerialMode | COLActiveLow); 326 1.1 tsubai 327 1.24 kleink if ((mfpvr() >> 16) == MPC601) 328 1.24 kleink tb = mfrtcl(); 329 1.24 kleink else 330 1.24 kleink tb = mftbl(); 331 1.1 tsubai bmac_write_reg(sc, RSEED, tb); 332 1.1 tsubai bmac_set_bits(sc, XIFC, TxOutputEnable); 333 1.1 tsubai bmac_read_reg(sc, PAREG); 334 1.1 tsubai 335 1.1 tsubai /* Reset various counters. */ 336 1.1 tsubai bmac_write_reg(sc, NCCNT, 0); 337 1.1 tsubai bmac_write_reg(sc, NTCNT, 0); 338 1.1 tsubai bmac_write_reg(sc, EXCNT, 0); 339 1.1 tsubai bmac_write_reg(sc, LTCNT, 0); 340 1.1 tsubai bmac_write_reg(sc, FRCNT, 0); 341 1.1 tsubai bmac_write_reg(sc, LECNT, 0); 342 1.1 tsubai bmac_write_reg(sc, AECNT, 0); 343 1.1 tsubai bmac_write_reg(sc, FECNT, 0); 344 1.1 tsubai bmac_write_reg(sc, RXCV, 0); 345 1.1 tsubai 346 1.1 tsubai /* Set tx fifo information. */ 347 1.1 tsubai bmac_write_reg(sc, TXTH, 4); /* 4 octets before tx starts */ 348 1.1 tsubai 349 1.1 tsubai bmac_write_reg(sc, TXFIFOCSR, 0); 350 1.1 tsubai bmac_write_reg(sc, TXFIFOCSR, TxFIFOEnable); 351 1.1 tsubai 352 1.1 tsubai /* Set rx fifo information. */ 353 1.1 tsubai bmac_write_reg(sc, RXFIFOCSR, 0); 354 1.1 tsubai bmac_write_reg(sc, RXFIFOCSR, RxFIFOEnable); 355 1.1 tsubai 356 1.1 tsubai /* Clear status register. */ 357 1.1 tsubai bmac_read_reg(sc, STATUS); 358 1.1 tsubai 359 1.1 tsubai bmac_write_reg(sc, HASH3, 0); 360 1.1 tsubai bmac_write_reg(sc, HASH2, 0); 361 1.1 tsubai bmac_write_reg(sc, HASH1, 0); 362 1.1 tsubai bmac_write_reg(sc, HASH0, 0); 363 1.1 tsubai 364 1.1 tsubai /* Set MAC address. */ 365 1.1 tsubai p = (u_short *)sc->sc_enaddr; 366 1.1 tsubai bmac_write_reg(sc, MADD0, *p++); 367 1.1 tsubai bmac_write_reg(sc, MADD1, *p++); 368 1.1 tsubai bmac_write_reg(sc, MADD2, *p); 369 1.1 tsubai 370 1.1 tsubai bmac_write_reg(sc, RXCFG, 371 1.1 tsubai RxCRCEnable | RxHashFilterEnable | RxRejectOwnPackets); 372 1.1 tsubai 373 1.1 tsubai if (ifp->if_flags & IFF_PROMISC) 374 1.1 tsubai bmac_set_bits(sc, RXCFG, RxPromiscEnable); 375 1.1 tsubai 376 1.1 tsubai bmac_init_dma(sc); 377 1.1 tsubai 378 1.1 tsubai /* Enable TX/RX */ 379 1.1 tsubai bmac_set_bits(sc, RXCFG, RxMACEnable); 380 1.1 tsubai bmac_set_bits(sc, TXCFG, TxMACEnable); 381 1.1 tsubai 382 1.1 tsubai bmac_write_reg(sc, INTDISABLE, NormalIntEvents); 383 1.1 tsubai 384 1.1 tsubai ifp->if_flags |= IFF_RUNNING; 385 1.65 thorpej sc->sc_txbusy = false; 386 1.1 tsubai ifp->if_timer = 0; 387 1.1 tsubai 388 1.1 tsubai data = sc->sc_txbuf; 389 1.1 tsubai eh = (struct ether_header *)data; 390 1.1 tsubai 391 1.16 wiz memset(data, 0, sizeof(eh) + ETHERMIN); 392 1.16 wiz memcpy(eh->ether_dhost, sc->sc_enaddr, ETHER_ADDR_LEN); 393 1.16 wiz memcpy(eh->ether_shost, sc->sc_enaddr, ETHER_ADDR_LEN); 394 1.1 tsubai bmac_transmit_packet(sc, data, sizeof(eh) + ETHERMIN); 395 1.1 tsubai 396 1.1 tsubai bmac_start(ifp); 397 1.4 tsubai 398 1.7 thorpej callout_reset(&sc->sc_tick_ch, hz, bmac_mii_tick, sc); 399 1.1 tsubai } 400 1.1 tsubai 401 1.1 tsubai void 402 1.39 dsl bmac_init_dma(struct bmac_softc *sc) 403 1.1 tsubai { 404 1.1 tsubai dbdma_command_t *cmd = sc->sc_rxcmd; 405 1.1 tsubai int i; 406 1.1 tsubai 407 1.1 tsubai dbdma_reset(sc->sc_txdma); 408 1.1 tsubai dbdma_reset(sc->sc_rxdma); 409 1.1 tsubai 410 1.16 wiz memset(sc->sc_txcmd, 0, BMAC_TXBUFS * sizeof(dbdma_command_t)); 411 1.16 wiz memset(sc->sc_rxcmd, 0, (BMAC_RXBUFS + 1) * sizeof(dbdma_command_t)); 412 1.1 tsubai 413 1.1 tsubai for (i = 0; i < BMAC_RXBUFS; i++) { 414 1.1 tsubai DBDMA_BUILD(cmd, DBDMA_CMD_IN_LAST, 0, BMAC_BUFLEN, 415 1.8 tsubai vtophys((vaddr_t)sc->sc_rxbuf + BMAC_BUFLEN * i), 416 1.1 tsubai DBDMA_INT_ALWAYS, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER); 417 1.1 tsubai cmd++; 418 1.1 tsubai } 419 1.1 tsubai DBDMA_BUILD(cmd, DBDMA_CMD_NOP, 0, 0, 0, 420 1.1 tsubai DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_ALWAYS); 421 1.34 garbled out32rb(&cmd->d_cmddep, vtophys((vaddr_t)sc->sc_rxcmd)); 422 1.1 tsubai 423 1.1 tsubai sc->sc_rxlast = 0; 424 1.1 tsubai 425 1.1 tsubai dbdma_start(sc->sc_rxdma, sc->sc_rxcmd); 426 1.1 tsubai } 427 1.1 tsubai 428 1.1 tsubai int 429 1.39 dsl bmac_intr(void *v) 430 1.1 tsubai { 431 1.1 tsubai struct bmac_softc *sc = v; 432 1.1 tsubai int stat; 433 1.1 tsubai 434 1.1 tsubai stat = bmac_read_reg(sc, STATUS); 435 1.1 tsubai if (stat == 0) 436 1.1 tsubai return 0; 437 1.1 tsubai 438 1.1 tsubai #ifdef BMAC_DEBUG 439 1.1 tsubai printf("bmac_intr status = 0x%x\n", stat); 440 1.1 tsubai #endif 441 1.1 tsubai 442 1.1 tsubai if (stat & IntFrameSent) { 443 1.65 thorpej sc->sc_txbusy = false; 444 1.1 tsubai sc->sc_if.if_timer = 0; 445 1.63 martin if_statinc(&sc->sc_if, if_opackets); 446 1.52 ozaki if_schedule_deferred_start(&sc->sc_if); 447 1.1 tsubai } 448 1.1 tsubai 449 1.1 tsubai /* XXX should do more! */ 450 1.1 tsubai 451 1.1 tsubai return 1; 452 1.1 tsubai } 453 1.1 tsubai 454 1.1 tsubai int 455 1.39 dsl bmac_rint(void *v) 456 1.1 tsubai { 457 1.1 tsubai struct bmac_softc *sc = v; 458 1.1 tsubai struct ifnet *ifp = &sc->sc_if; 459 1.1 tsubai struct mbuf *m; 460 1.1 tsubai dbdma_command_t *cmd; 461 1.1 tsubai int status, resid, count, datalen; 462 1.1 tsubai int i, n; 463 1.1 tsubai void *data; 464 1.1 tsubai 465 1.1 tsubai i = sc->sc_rxlast; 466 1.1 tsubai for (n = 0; n < BMAC_RXBUFS; n++, i++) { 467 1.1 tsubai if (i == BMAC_RXBUFS) 468 1.1 tsubai i = 0; 469 1.1 tsubai cmd = &sc->sc_rxcmd[i]; 470 1.34 garbled status = in16rb(&cmd->d_status); 471 1.34 garbled resid = in16rb(&cmd->d_resid); 472 1.1 tsubai 473 1.1 tsubai #ifdef BMAC_DEBUG 474 1.1 tsubai if (status != 0 && status != 0x8440 && status != 0x9440) 475 1.1 tsubai printf("bmac_rint status = 0x%x\n", status); 476 1.1 tsubai #endif 477 1.1 tsubai 478 1.1 tsubai if ((status & DBDMA_CNTRL_ACTIVE) == 0) /* 0x9440 | 0x8440 */ 479 1.1 tsubai continue; 480 1.34 garbled count = in16rb(&cmd->d_count); 481 1.12 tsubai datalen = count - resid - 2; /* 2 == framelen */ 482 1.1 tsubai if (datalen < sizeof(struct ether_header)) { 483 1.1 tsubai printf("%s: short packet len = %d\n", 484 1.1 tsubai ifp->if_xname, datalen); 485 1.1 tsubai goto next; 486 1.1 tsubai } 487 1.1 tsubai DBDMA_BUILD_CMD(cmd, DBDMA_CMD_STOP, 0, 0, 0, 0); 488 1.31 macallan data = (char *)sc->sc_rxbuf + BMAC_BUFLEN * i; 489 1.12 tsubai 490 1.12 tsubai /* XXX Sometimes bmac reads one extra byte. */ 491 1.12 tsubai if (datalen == ETHER_MAX_LEN + 1) 492 1.12 tsubai datalen--; 493 1.25 thorpej 494 1.25 thorpej /* Trim the CRC. */ 495 1.25 thorpej datalen -= ETHER_CRC_LEN; 496 1.25 thorpej 497 1.1 tsubai m = bmac_get(sc, data, datalen); 498 1.1 tsubai if (m == NULL) { 499 1.62 skrll if_statinc(ifp, if_ierrors); 500 1.1 tsubai goto next; 501 1.1 tsubai } 502 1.1 tsubai 503 1.47 ozaki if_percpuq_enqueue(ifp->if_percpuq, m); 504 1.1 tsubai 505 1.1 tsubai next: 506 1.1 tsubai DBDMA_BUILD_CMD(cmd, DBDMA_CMD_IN_LAST, 0, DBDMA_INT_ALWAYS, 507 1.1 tsubai DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER); 508 1.1 tsubai 509 1.1 tsubai cmd->d_status = 0; 510 1.1 tsubai cmd->d_resid = 0; 511 1.1 tsubai sc->sc_rxlast = i + 1; 512 1.1 tsubai } 513 1.36 dyoung ether_mediachange(ifp); 514 1.29 jklos 515 1.1 tsubai dbdma_continue(sc->sc_rxdma); 516 1.1 tsubai 517 1.1 tsubai return 1; 518 1.1 tsubai } 519 1.1 tsubai 520 1.1 tsubai void 521 1.39 dsl bmac_reset(struct bmac_softc *sc) 522 1.1 tsubai { 523 1.1 tsubai int s; 524 1.1 tsubai 525 1.1 tsubai s = splnet(); 526 1.1 tsubai bmac_init(sc); 527 1.1 tsubai splx(s); 528 1.1 tsubai } 529 1.1 tsubai 530 1.1 tsubai void 531 1.39 dsl bmac_stop(struct bmac_softc *sc) 532 1.1 tsubai { 533 1.1 tsubai struct ifnet *ifp = &sc->sc_if; 534 1.1 tsubai int s; 535 1.1 tsubai 536 1.1 tsubai s = splnet(); 537 1.1 tsubai 538 1.7 thorpej callout_stop(&sc->sc_tick_ch); 539 1.4 tsubai mii_down(&sc->sc_mii); 540 1.4 tsubai 541 1.1 tsubai /* Disable TX/RX. */ 542 1.1 tsubai bmac_reset_bits(sc, TXCFG, TxMACEnable); 543 1.1 tsubai bmac_reset_bits(sc, RXCFG, RxMACEnable); 544 1.1 tsubai 545 1.1 tsubai /* Disable all interrupts. */ 546 1.1 tsubai bmac_write_reg(sc, INTDISABLE, NoEventsMask); 547 1.1 tsubai 548 1.1 tsubai dbdma_stop(sc->sc_txdma); 549 1.1 tsubai dbdma_stop(sc->sc_rxdma); 550 1.1 tsubai 551 1.1 tsubai ifp->if_flags &= ~(IFF_UP | IFF_RUNNING); 552 1.1 tsubai ifp->if_timer = 0; 553 1.1 tsubai 554 1.1 tsubai splx(s); 555 1.1 tsubai } 556 1.1 tsubai 557 1.1 tsubai void 558 1.39 dsl bmac_start(struct ifnet *ifp) 559 1.1 tsubai { 560 1.1 tsubai struct bmac_softc *sc = ifp->if_softc; 561 1.1 tsubai struct mbuf *m; 562 1.1 tsubai int tlen; 563 1.1 tsubai 564 1.65 thorpej if ((ifp->if_flags & IFF_RUNNING) == 0) 565 1.1 tsubai return; 566 1.1 tsubai 567 1.65 thorpej while (!sc->sc_txbusy) { 568 1.17 itojun IFQ_DEQUEUE(&ifp->if_snd, m); 569 1.1 tsubai if (m == 0) 570 1.1 tsubai break; 571 1.1 tsubai /* 572 1.1 tsubai * If BPF is listening on this interface, let it see the 573 1.1 tsubai * packet before we commit it to the wire. 574 1.1 tsubai */ 575 1.54 msaitoh bpf_mtap(ifp, m, BPF_D_OUT); 576 1.1 tsubai 577 1.65 thorpej sc->sc_txbusy = true; 578 1.1 tsubai tlen = bmac_put(sc, sc->sc_txbuf, m); 579 1.1 tsubai 580 1.1 tsubai /* 5 seconds to watch for failing to transmit */ 581 1.1 tsubai ifp->if_timer = 5; 582 1.62 skrll if_statinc(ifp, if_opackets); /* # of pkts */ 583 1.1 tsubai 584 1.1 tsubai bmac_transmit_packet(sc, sc->sc_txbuf, tlen); 585 1.1 tsubai } 586 1.1 tsubai } 587 1.1 tsubai 588 1.1 tsubai void 589 1.39 dsl bmac_transmit_packet(struct bmac_softc *sc, void *buff, int len) 590 1.1 tsubai { 591 1.1 tsubai dbdma_command_t *cmd = sc->sc_txcmd; 592 1.1 tsubai vaddr_t va = (vaddr_t)buff; 593 1.1 tsubai 594 1.1 tsubai #ifdef BMAC_DEBUG 595 1.1 tsubai if (vtophys(va) + len - 1 != vtophys(va + len - 1)) 596 1.1 tsubai panic("bmac_transmit_packet"); 597 1.1 tsubai #endif 598 1.1 tsubai 599 1.1 tsubai DBDMA_BUILD(cmd, DBDMA_CMD_OUT_LAST, 0, len, vtophys(va), 600 1.1 tsubai DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER); 601 1.1 tsubai cmd++; 602 1.1 tsubai DBDMA_BUILD(cmd, DBDMA_CMD_STOP, 0, 0, 0, 603 1.1 tsubai DBDMA_INT_ALWAYS, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER); 604 1.1 tsubai 605 1.1 tsubai dbdma_start(sc->sc_txdma, sc->sc_txcmd); 606 1.1 tsubai } 607 1.1 tsubai 608 1.1 tsubai int 609 1.39 dsl bmac_put(struct bmac_softc *sc, void *buff, struct mbuf *m) 610 1.1 tsubai { 611 1.1 tsubai struct mbuf *n; 612 1.1 tsubai int len, tlen = 0; 613 1.1 tsubai 614 1.1 tsubai for (; m; m = n) { 615 1.1 tsubai len = m->m_len; 616 1.1 tsubai if (len == 0) { 617 1.51 ozaki n = m_free(m); 618 1.1 tsubai continue; 619 1.1 tsubai } 620 1.30 christos memcpy(buff, mtod(m, void *), len); 621 1.31 macallan buff = (char *)buff + len; 622 1.1 tsubai tlen += len; 623 1.50 christos n = m_free(m); 624 1.1 tsubai } 625 1.20 thorpej if (tlen > PAGE_SIZE) 626 1.44 matt panic("%s: putpacket packet overflow", 627 1.44 matt device_xname(sc->sc_dev)); 628 1.1 tsubai 629 1.1 tsubai return tlen; 630 1.1 tsubai } 631 1.1 tsubai 632 1.1 tsubai struct mbuf * 633 1.39 dsl bmac_get(struct bmac_softc *sc, void *pkt, int totlen) 634 1.1 tsubai { 635 1.1 tsubai struct mbuf *m; 636 1.1 tsubai struct mbuf *top, **mp; 637 1.1 tsubai int len; 638 1.1 tsubai 639 1.1 tsubai MGETHDR(m, M_DONTWAIT, MT_DATA); 640 1.1 tsubai if (m == 0) 641 1.1 tsubai return 0; 642 1.48 ozaki m_set_rcvif(m, &sc->sc_if); 643 1.1 tsubai m->m_pkthdr.len = totlen; 644 1.1 tsubai len = MHLEN; 645 1.1 tsubai top = 0; 646 1.1 tsubai mp = ⊤ 647 1.1 tsubai 648 1.1 tsubai while (totlen > 0) { 649 1.1 tsubai if (top) { 650 1.1 tsubai MGET(m, M_DONTWAIT, MT_DATA); 651 1.1 tsubai if (m == 0) { 652 1.1 tsubai m_freem(top); 653 1.1 tsubai return 0; 654 1.1 tsubai } 655 1.1 tsubai len = MLEN; 656 1.1 tsubai } 657 1.1 tsubai if (totlen >= MINCLSIZE) { 658 1.1 tsubai MCLGET(m, M_DONTWAIT); 659 1.1 tsubai if ((m->m_flags & M_EXT) == 0) { 660 1.1 tsubai m_free(m); 661 1.1 tsubai m_freem(top); 662 1.1 tsubai return 0; 663 1.1 tsubai } 664 1.1 tsubai len = MCLBYTES; 665 1.1 tsubai } 666 1.55 riastrad m->m_len = len = uimin(totlen, len); 667 1.30 christos memcpy(mtod(m, void *), pkt, len); 668 1.31 macallan pkt = (char *)pkt + len; 669 1.1 tsubai totlen -= len; 670 1.1 tsubai *mp = m; 671 1.1 tsubai mp = &m->m_next; 672 1.1 tsubai } 673 1.1 tsubai 674 1.1 tsubai return top; 675 1.1 tsubai } 676 1.1 tsubai 677 1.1 tsubai void 678 1.39 dsl bmac_watchdog(struct ifnet *ifp) 679 1.1 tsubai { 680 1.1 tsubai struct bmac_softc *sc = ifp->if_softc; 681 1.1 tsubai 682 1.1 tsubai bmac_reset_bits(sc, RXCFG, RxMACEnable); 683 1.1 tsubai bmac_reset_bits(sc, TXCFG, TxMACEnable); 684 1.1 tsubai 685 1.1 tsubai printf("%s: device timeout\n", ifp->if_xname); 686 1.62 skrll if_statinc(ifp, if_oerrors); 687 1.1 tsubai 688 1.1 tsubai bmac_reset(sc); 689 1.1 tsubai } 690 1.1 tsubai 691 1.1 tsubai int 692 1.38 dyoung bmac_ioctl(struct ifnet *ifp, unsigned long cmd, void *data) 693 1.1 tsubai { 694 1.1 tsubai struct bmac_softc *sc = ifp->if_softc; 695 1.1 tsubai struct ifaddr *ifa = (struct ifaddr *)data; 696 1.1 tsubai int s, error = 0; 697 1.1 tsubai 698 1.1 tsubai s = splnet(); 699 1.1 tsubai 700 1.1 tsubai switch (cmd) { 701 1.1 tsubai 702 1.38 dyoung case SIOCINITIFADDR: 703 1.1 tsubai ifp->if_flags |= IFF_UP; 704 1.1 tsubai 705 1.38 dyoung bmac_init(sc); 706 1.1 tsubai switch (ifa->ifa_addr->sa_family) { 707 1.1 tsubai #ifdef INET 708 1.1 tsubai case AF_INET: 709 1.1 tsubai arp_ifinit(ifp, ifa); 710 1.1 tsubai break; 711 1.1 tsubai #endif 712 1.1 tsubai default: 713 1.1 tsubai break; 714 1.1 tsubai } 715 1.1 tsubai break; 716 1.1 tsubai 717 1.1 tsubai case SIOCSIFFLAGS: 718 1.38 dyoung if ((error = ifioctl_common(ifp, cmd, data)) != 0) 719 1.38 dyoung break; 720 1.38 dyoung /* XXX see the comment in ed_ioctl() about code re-use */ 721 1.1 tsubai if ((ifp->if_flags & IFF_UP) == 0 && 722 1.1 tsubai (ifp->if_flags & IFF_RUNNING) != 0) { 723 1.1 tsubai /* 724 1.1 tsubai * If interface is marked down and it is running, then 725 1.1 tsubai * stop it. 726 1.1 tsubai */ 727 1.1 tsubai bmac_stop(sc); 728 1.1 tsubai ifp->if_flags &= ~IFF_RUNNING; 729 1.1 tsubai } else if ((ifp->if_flags & IFF_UP) != 0 && 730 1.1 tsubai (ifp->if_flags & IFF_RUNNING) == 0) { 731 1.1 tsubai /* 732 1.1 tsubai * If interface is marked up and it is stopped, then 733 1.1 tsubai * start it. 734 1.1 tsubai */ 735 1.1 tsubai bmac_init(sc); 736 1.1 tsubai } else { 737 1.1 tsubai /* 738 1.1 tsubai * Reset the interface to pick up changes in any other 739 1.1 tsubai * flags that affect hardware registers. 740 1.1 tsubai */ 741 1.1 tsubai /*bmac_stop(sc);*/ 742 1.1 tsubai bmac_init(sc); 743 1.1 tsubai } 744 1.1 tsubai #ifdef BMAC_DEBUG 745 1.1 tsubai if (ifp->if_flags & IFF_DEBUG) 746 1.4 tsubai sc->sc_flags |= BMAC_DEBUGFLAG; 747 1.1 tsubai #endif 748 1.1 tsubai break; 749 1.1 tsubai 750 1.58 msaitoh default: 751 1.33 dyoung if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) { 752 1.1 tsubai /* 753 1.1 tsubai * Multicast list has changed; set the hardware filter 754 1.1 tsubai * accordingly. 755 1.1 tsubai */ 756 1.23 thorpej if (ifp->if_flags & IFF_RUNNING) { 757 1.23 thorpej bmac_init(sc); 758 1.23 thorpej bmac_setladrf(sc); 759 1.23 thorpej } 760 1.1 tsubai error = 0; 761 1.1 tsubai } 762 1.1 tsubai break; 763 1.1 tsubai } 764 1.1 tsubai 765 1.1 tsubai splx(s); 766 1.1 tsubai return error; 767 1.1 tsubai } 768 1.1 tsubai 769 1.1 tsubai /* 770 1.1 tsubai * Set up the logical address filter. 771 1.1 tsubai */ 772 1.1 tsubai void 773 1.39 dsl bmac_setladrf(struct bmac_softc *sc) 774 1.1 tsubai { 775 1.60 msaitoh struct ethercom *ec = &sc->sc_ethercom; 776 1.1 tsubai struct ifnet *ifp = &sc->sc_if; 777 1.1 tsubai struct ether_multi *enm; 778 1.1 tsubai struct ether_multistep step; 779 1.59 msaitoh uint32_t crc; 780 1.59 msaitoh uint16_t hash[4]; 781 1.11 tsubai int x; 782 1.1 tsubai 783 1.1 tsubai /* 784 1.1 tsubai * Set up multicast address filter by passing all multicast addresses 785 1.1 tsubai * through a crc generator, and then using the high order 6 bits as an 786 1.1 tsubai * index into the 64 bit logical address filter. The high order bit 787 1.1 tsubai * selects the word, while the rest of the bits select the bit within 788 1.1 tsubai * the word. 789 1.1 tsubai */ 790 1.1 tsubai 791 1.1 tsubai if (ifp->if_flags & IFF_PROMISC) { 792 1.1 tsubai bmac_set_bits(sc, RXCFG, RxPromiscEnable); 793 1.9 tsubai return; 794 1.9 tsubai } 795 1.9 tsubai 796 1.9 tsubai if (ifp->if_flags & IFF_ALLMULTI) { 797 1.9 tsubai hash[3] = hash[2] = hash[1] = hash[0] = 0xffff; 798 1.9 tsubai goto chipit; 799 1.1 tsubai } 800 1.1 tsubai 801 1.1 tsubai hash[3] = hash[2] = hash[1] = hash[0] = 0; 802 1.9 tsubai 803 1.60 msaitoh ETHER_LOCK(ec); 804 1.60 msaitoh ETHER_FIRST_MULTI(step, ec, enm); 805 1.1 tsubai while (enm != NULL) { 806 1.16 wiz if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) { 807 1.1 tsubai /* 808 1.1 tsubai * We must listen to a range of multicast addresses. 809 1.1 tsubai * For now, just accept all multicasts, rather than 810 1.1 tsubai * trying to set only those filter bits needed to match 811 1.1 tsubai * the range. (At this time, the only use of address 812 1.1 tsubai * ranges is for IP multicast routing, for which the 813 1.1 tsubai * range is big enough to require all bits set.) 814 1.1 tsubai */ 815 1.9 tsubai hash[3] = hash[2] = hash[1] = hash[0] = 0xffff; 816 1.9 tsubai ifp->if_flags |= IFF_ALLMULTI; 817 1.60 msaitoh ETHER_UNLOCK(ec); 818 1.9 tsubai goto chipit; 819 1.1 tsubai } 820 1.1 tsubai 821 1.9 tsubai crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN); 822 1.1 tsubai 823 1.1 tsubai /* Just want the 6 most significant bits. */ 824 1.1 tsubai crc >>= 26; 825 1.1 tsubai 826 1.1 tsubai /* Set the corresponding bit in the filter. */ 827 1.1 tsubai hash[crc >> 4] |= 1 << (crc & 0xf); 828 1.1 tsubai 829 1.1 tsubai ETHER_NEXT_MULTI(step, enm); 830 1.1 tsubai } 831 1.60 msaitoh ETHER_UNLOCK(ec); 832 1.9 tsubai 833 1.1 tsubai ifp->if_flags &= ~IFF_ALLMULTI; 834 1.1 tsubai 835 1.9 tsubai chipit: 836 1.9 tsubai bmac_write_reg(sc, HASH0, hash[0]); 837 1.9 tsubai bmac_write_reg(sc, HASH1, hash[1]); 838 1.9 tsubai bmac_write_reg(sc, HASH2, hash[2]); 839 1.9 tsubai bmac_write_reg(sc, HASH3, hash[3]); 840 1.11 tsubai x = bmac_read_reg(sc, RXCFG); 841 1.11 tsubai x &= ~RxPromiscEnable; 842 1.11 tsubai x |= RxHashFilterEnable; 843 1.11 tsubai bmac_write_reg(sc, RXCFG, x); 844 1.4 tsubai } 845 1.4 tsubai 846 1.4 tsubai int 847 1.56 msaitoh bmac_mii_readreg(device_t self, int phy, int reg, uint16_t *val) 848 1.4 tsubai { 849 1.56 msaitoh return mii_bitbang_readreg(self, &bmac_mbo, phy, reg, val); 850 1.4 tsubai } 851 1.4 tsubai 852 1.56 msaitoh int 853 1.56 msaitoh bmac_mii_writereg(device_t self, int phy, int reg, uint16_t val) 854 1.4 tsubai { 855 1.56 msaitoh return mii_bitbang_writereg(self, &bmac_mbo, phy, reg, val); 856 1.4 tsubai } 857 1.4 tsubai 858 1.59 msaitoh uint32_t 859 1.44 matt bmac_mbo_read(device_t self) 860 1.4 tsubai { 861 1.44 matt struct bmac_softc *sc = device_private(self); 862 1.4 tsubai 863 1.4 tsubai return bmac_read_reg(sc, MIFCSR); 864 1.4 tsubai } 865 1.4 tsubai 866 1.4 tsubai void 867 1.59 msaitoh bmac_mbo_write(device_t self, uint32_t val) 868 1.4 tsubai { 869 1.44 matt struct bmac_softc *sc = device_private(self); 870 1.4 tsubai 871 1.4 tsubai bmac_write_reg(sc, MIFCSR, val); 872 1.4 tsubai } 873 1.4 tsubai 874 1.4 tsubai void 875 1.46 matt bmac_mii_statchg(struct ifnet *ifp) 876 1.4 tsubai { 877 1.46 matt struct bmac_softc *sc = ifp->if_softc; 878 1.4 tsubai int x; 879 1.4 tsubai 880 1.4 tsubai /* Update duplex mode in TX configuration */ 881 1.4 tsubai x = bmac_read_reg(sc, TXCFG); 882 1.4 tsubai if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0) 883 1.4 tsubai x |= TxFullDuplex; 884 1.4 tsubai else 885 1.4 tsubai x &= ~TxFullDuplex; 886 1.4 tsubai bmac_write_reg(sc, TXCFG, x); 887 1.4 tsubai 888 1.4 tsubai #ifdef BMAC_DEBUG 889 1.4 tsubai printf("bmac_mii_statchg 0x%x\n", 890 1.4 tsubai IFM_OPTIONS(sc->sc_mii.mii_media_active)); 891 1.4 tsubai #endif 892 1.4 tsubai } 893 1.4 tsubai 894 1.4 tsubai void 895 1.39 dsl bmac_mii_tick(void *v) 896 1.4 tsubai { 897 1.4 tsubai struct bmac_softc *sc = v; 898 1.4 tsubai int s; 899 1.4 tsubai 900 1.4 tsubai s = splnet(); 901 1.4 tsubai mii_tick(&sc->sc_mii); 902 1.4 tsubai splx(s); 903 1.4 tsubai 904 1.7 thorpej callout_reset(&sc->sc_tick_ch, hz, bmac_mii_tick, sc); 905 1.1 tsubai } 906