1 1.79 andvar /* $NetBSD: ne2000.c,v 1.79 2024/05/21 08:04:20 andvar Exp $ */ 2 1.2 thorpej 3 1.2 thorpej /*- 4 1.8 thorpej * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 1.2 thorpej * All rights reserved. 6 1.2 thorpej * 7 1.2 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.2 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 1.2 thorpej * NASA Ames Research Center. 10 1.2 thorpej * 11 1.2 thorpej * Redistribution and use in source and binary forms, with or without 12 1.2 thorpej * modification, are permitted provided that the following conditions 13 1.2 thorpej * are met: 14 1.2 thorpej * 1. Redistributions of source code must retain the above copyright 15 1.2 thorpej * notice, this list of conditions and the following disclaimer. 16 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright 17 1.2 thorpej * notice, this list of conditions and the following disclaimer in the 18 1.2 thorpej * documentation and/or other materials provided with the distribution. 19 1.2 thorpej * 20 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.2 thorpej * POSSIBILITY OF SUCH DAMAGE. 31 1.2 thorpej */ 32 1.2 thorpej 33 1.2 thorpej /* 34 1.2 thorpej * Device driver for National Semiconductor DS8390/WD83C690 based ethernet 35 1.2 thorpej * adapters. 36 1.2 thorpej * 37 1.2 thorpej * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. 38 1.2 thorpej * 39 1.2 thorpej * Copyright (C) 1993, David Greenman. This software may be used, modified, 40 1.2 thorpej * copied, distributed, and sold, in both source and binary form provided that 41 1.2 thorpej * the above copyright and these terms are retained. Under no circumstances is 42 1.2 thorpej * the author responsible for the proper functioning of this software, nor does 43 1.2 thorpej * the author assume any responsibility for damages incurred with its use. 44 1.2 thorpej */ 45 1.2 thorpej 46 1.2 thorpej /* 47 1.2 thorpej * Common code shared by all NE2000-compatible Ethernet interfaces. 48 1.2 thorpej */ 49 1.37 lukem 50 1.37 lukem #include <sys/cdefs.h> 51 1.79 andvar __KERNEL_RCSID(0, "$NetBSD: ne2000.c,v 1.79 2024/05/21 08:04:20 andvar Exp $"); 52 1.29 ws 53 1.68 tsutsui #include "rtl80x9.h" 54 1.68 tsutsui 55 1.2 thorpej #include <sys/param.h> 56 1.2 thorpej #include <sys/systm.h> 57 1.2 thorpej #include <sys/device.h> 58 1.2 thorpej #include <sys/socket.h> 59 1.2 thorpej #include <sys/mbuf.h> 60 1.2 thorpej #include <sys/syslog.h> 61 1.2 thorpej 62 1.2 thorpej #include <net/if.h> 63 1.2 thorpej #include <net/if_dl.h> 64 1.2 thorpej #include <net/if_types.h> 65 1.5 thorpej #include <net/if_media.h> 66 1.2 thorpej 67 1.2 thorpej #include <net/if_ether.h> 68 1.2 thorpej 69 1.48 dsl #include <sys/bswap.h> 70 1.55 ad #include <sys/bus.h> 71 1.2 thorpej 72 1.11 sakamoto #ifndef __BUS_SPACE_HAS_STREAM_METHODS 73 1.10 sakamoto #define bus_space_write_stream_2 bus_space_write_2 74 1.10 sakamoto #define bus_space_write_multi_stream_2 bus_space_write_multi_2 75 1.10 sakamoto #define bus_space_read_multi_stream_2 bus_space_read_multi_2 76 1.11 sakamoto #endif /* __BUS_SPACE_HAS_STREAM_METHODS */ 77 1.10 sakamoto 78 1.2 thorpej #include <dev/ic/dp8390reg.h> 79 1.2 thorpej #include <dev/ic/dp8390var.h> 80 1.2 thorpej 81 1.2 thorpej #include <dev/ic/ne2000reg.h> 82 1.2 thorpej #include <dev/ic/ne2000var.h> 83 1.17 mjacob 84 1.68 tsutsui #include <dev/ic/rtl80x9reg.h> 85 1.68 tsutsui #include <dev/ic/rtl80x9var.h> 86 1.68 tsutsui 87 1.36 enami #include <dev/ic/ax88190reg.h> 88 1.36 enami 89 1.70 tsutsui static int ne2000_write_mbuf(struct dp8390_softc *, struct mbuf *, int); 90 1.70 tsutsui static int ne2000_ring_copy(struct dp8390_softc *, int, void *, u_short); 91 1.70 tsutsui static void ne2000_read_hdr(struct dp8390_softc *, int, 92 1.70 tsutsui struct dp8390_ring *); 93 1.70 tsutsui static int ne2000_test_mem(struct dp8390_softc *); 94 1.70 tsutsui 95 1.70 tsutsui static void ne2000_writemem(bus_space_tag_t, bus_space_handle_t, 96 1.70 tsutsui bus_space_tag_t, bus_space_handle_t, const uint8_t *, int, 97 1.70 tsutsui size_t, int, int); 98 1.70 tsutsui static void ne2000_readmem(bus_space_tag_t, bus_space_handle_t, 99 1.70 tsutsui bus_space_tag_t, bus_space_handle_t, int, uint8_t *, 100 1.70 tsutsui size_t, int); 101 1.2 thorpej 102 1.68 tsutsui #ifdef NE2000_DETECT_8BIT 103 1.68 tsutsui static bool ne2000_detect_8bit(bus_space_tag_t, bus_space_handle_t, 104 1.68 tsutsui bus_space_tag_t, bus_space_handle_t); 105 1.68 tsutsui #endif 106 1.68 tsutsui 107 1.44 mycroft #define ASIC_BARRIER(asict, asich) \ 108 1.44 mycroft bus_space_barrier((asict), (asich), 0, 0x10, \ 109 1.44 mycroft BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE) 110 1.44 mycroft 111 1.26 enami int 112 1.69 tsutsui ne2000_attach(struct ne2000_softc *nsc, uint8_t *myea) 113 1.2 thorpej { 114 1.2 thorpej struct dp8390_softc *dsc = &nsc->sc_dp8390; 115 1.2 thorpej bus_space_tag_t nict = dsc->sc_regt; 116 1.2 thorpej bus_space_handle_t nich = dsc->sc_regh; 117 1.2 thorpej bus_space_tag_t asict = nsc->sc_asict; 118 1.2 thorpej bus_space_handle_t asich = nsc->sc_asich; 119 1.69 tsutsui uint8_t romdata[16]; 120 1.68 tsutsui int memstart, memsize, i, useword; 121 1.2 thorpej 122 1.2 thorpej /* 123 1.19 enami * Detect it again unless caller specified it; this gives us 124 1.19 enami * the memory size. 125 1.2 thorpej */ 126 1.42 mycroft if (nsc->sc_type == NE2000_TYPE_UNKNOWN) 127 1.19 enami nsc->sc_type = ne2000_detect(nict, nich, asict, asich); 128 1.42 mycroft 129 1.42 mycroft /* 130 1.42 mycroft * 8k of memory for NE1000, 16k for NE2000 and 24k for the 131 1.42 mycroft * card uses DL10019. 132 1.42 mycroft */ 133 1.42 mycroft switch (nsc->sc_type) { 134 1.42 mycroft case NE2000_TYPE_UNKNOWN: 135 1.42 mycroft default: 136 1.57 cube aprint_error_dev(dsc->sc_dev, "where did the card go?\n"); 137 1.69 tsutsui return 1; 138 1.42 mycroft case NE2000_TYPE_NE1000: 139 1.68 tsutsui memstart = 8192; 140 1.42 mycroft memsize = 8192; 141 1.42 mycroft useword = 0; 142 1.42 mycroft break; 143 1.42 mycroft case NE2000_TYPE_NE2000: 144 1.42 mycroft case NE2000_TYPE_AX88190: /* XXX really? */ 145 1.42 mycroft case NE2000_TYPE_AX88790: 146 1.74 rkujawa case NE2000_TYPE_AX88796: 147 1.68 tsutsui #if NRTL80X9 > 0 148 1.68 tsutsui case NE2000_TYPE_RTL8019: 149 1.68 tsutsui #endif 150 1.68 tsutsui memstart = 16384; 151 1.68 tsutsui memsize = 16384; 152 1.42 mycroft useword = 1; 153 1.74 rkujawa 154 1.68 tsutsui if ( 155 1.68 tsutsui #ifdef NE2000_DETECT_8BIT 156 1.68 tsutsui ne2000_detect_8bit(nict, nich, asict, asich) || 157 1.68 tsutsui #endif 158 1.68 tsutsui (nsc->sc_quirk & NE2000_QUIRK_8BIT) != 0) { 159 1.68 tsutsui /* in 8 bit mode, only 8KB memory can be used */ 160 1.68 tsutsui memsize = 8192; 161 1.68 tsutsui useword = 0; 162 1.68 tsutsui } 163 1.42 mycroft break; 164 1.42 mycroft case NE2000_TYPE_DL10019: 165 1.42 mycroft case NE2000_TYPE_DL10022: 166 1.68 tsutsui memstart = 8192 * 3; 167 1.42 mycroft memsize = 8192 * 3; 168 1.42 mycroft useword = 1; 169 1.42 mycroft break; 170 1.2 thorpej } 171 1.2 thorpej 172 1.42 mycroft nsc->sc_useword = useword; 173 1.68 tsutsui #if NRTL80X9 > 0 174 1.68 tsutsui if (nsc->sc_type == NE2000_TYPE_RTL8019) { 175 1.68 tsutsui dsc->init_card = rtl80x9_init_card; 176 1.68 tsutsui dsc->sc_media_init = rtl80x9_media_init; 177 1.68 tsutsui dsc->sc_mediachange = rtl80x9_mediachange; 178 1.68 tsutsui dsc->sc_mediastatus = rtl80x9_mediastatus; 179 1.68 tsutsui } 180 1.68 tsutsui #endif 181 1.2 thorpej 182 1.2 thorpej dsc->cr_proto = ED_CR_RD2; 183 1.39 christos if (nsc->sc_type == NE2000_TYPE_AX88190 || 184 1.39 christos nsc->sc_type == NE2000_TYPE_AX88790) { 185 1.27 enami dsc->rcr_proto = ED_RCR_INTT; 186 1.27 enami dsc->sc_flags |= DP8390_DO_AX88190_WORKAROUND; 187 1.27 enami } else 188 1.27 enami dsc->rcr_proto = 0; 189 1.2 thorpej 190 1.2 thorpej /* 191 1.2 thorpej * DCR gets: 192 1.2 thorpej * 193 1.2 thorpej * FIFO threshold to 8, No auto-init Remote DMA, 194 1.2 thorpej * byte order=80x86. 195 1.2 thorpej * 196 1.2 thorpej * NE1000 gets byte-wide DMA, NE2000 gets word-wide DMA. 197 1.2 thorpej */ 198 1.68 tsutsui dsc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS | (useword ? ED_DCR_WTS : 0); 199 1.2 thorpej 200 1.2 thorpej dsc->test_mem = ne2000_test_mem; 201 1.2 thorpej dsc->ring_copy = ne2000_ring_copy; 202 1.2 thorpej dsc->write_mbuf = ne2000_write_mbuf; 203 1.2 thorpej dsc->read_hdr = ne2000_read_hdr; 204 1.2 thorpej 205 1.2 thorpej /* Registers are linear. */ 206 1.2 thorpej for (i = 0; i < 16; i++) 207 1.2 thorpej dsc->sc_reg_map[i] = i; 208 1.2 thorpej 209 1.2 thorpej /* 210 1.77 andvar * NIC memory doesn't start at zero on an NE board. 211 1.2 thorpej * The start address is tied to the bus width. 212 1.2 thorpej */ 213 1.2 thorpej #ifdef GWETHER 214 1.2 thorpej { 215 1.68 tsutsui int x; 216 1.2 thorpej int8_t pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE], 217 1.2 thorpej tbuf[ED_PAGE_SIZE]; 218 1.2 thorpej 219 1.68 tsutsui memstart = 0; 220 1.2 thorpej for (i = 0; i < ED_PAGE_SIZE; i++) 221 1.2 thorpej pbuf0[i] = 0; 222 1.2 thorpej 223 1.2 thorpej /* Search for the start of RAM. */ 224 1.2 thorpej for (x = 1; x < 256; x++) { 225 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, pbuf0, 226 1.15 thorpej x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword, 0); 227 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, 228 1.2 thorpej x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword); 229 1.34 thorpej if (memcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) { 230 1.2 thorpej for (i = 0; i < ED_PAGE_SIZE; i++) 231 1.2 thorpej pbuf[i] = 255 - x; 232 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, 233 1.2 thorpej pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE, 234 1.15 thorpej useword, 0); 235 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, 236 1.2 thorpej x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, 237 1.2 thorpej useword); 238 1.34 thorpej if (memcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) { 239 1.68 tsutsui memstart = x << ED_PAGE_SHIFT; 240 1.2 thorpej memsize = ED_PAGE_SIZE; 241 1.2 thorpej break; 242 1.2 thorpej } 243 1.2 thorpej } 244 1.2 thorpej } 245 1.2 thorpej 246 1.68 tsutsui if (memstart == 0) { 247 1.73 chs aprint_error_dev(dsc->sc_dev, 248 1.69 tsutsui "cannot find start of RAM\n"); 249 1.69 tsutsui return 1; 250 1.2 thorpej } 251 1.2 thorpej 252 1.2 thorpej /* Search for the end of RAM. */ 253 1.2 thorpej for (++x; x < 256; x++) { 254 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, pbuf0, 255 1.15 thorpej x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword, 0); 256 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, 257 1.2 thorpej x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword); 258 1.34 thorpej if (memcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) { 259 1.2 thorpej for (i = 0; i < ED_PAGE_SIZE; i++) 260 1.2 thorpej pbuf[i] = 255 - x; 261 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, 262 1.2 thorpej pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE, 263 1.15 thorpej useword, 0); 264 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, 265 1.13 msaitoh x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, 266 1.2 thorpej useword); 267 1.34 thorpej if (memcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) 268 1.2 thorpej memsize += ED_PAGE_SIZE; 269 1.2 thorpej else 270 1.2 thorpej break; 271 1.2 thorpej } else 272 1.2 thorpej break; 273 1.2 thorpej } 274 1.2 thorpej 275 1.2 thorpej printf("%s: RAM start 0x%x, size %d\n", 276 1.73 chs device_xname(dsc->sc_dev), memstart, memsize); 277 1.2 thorpej } 278 1.2 thorpej #endif /* GWETHER */ 279 1.68 tsutsui dsc->mem_start = memstart; 280 1.2 thorpej 281 1.2 thorpej dsc->mem_size = memsize; 282 1.2 thorpej 283 1.2 thorpej if (myea == NULL) { 284 1.2 thorpej /* Read the station address. */ 285 1.39 christos if (nsc->sc_type == NE2000_TYPE_AX88190 || 286 1.74 rkujawa nsc->sc_type == NE2000_TYPE_AX88790 || 287 1.74 rkujawa nsc->sc_type == NE2000_TYPE_AX88796) { 288 1.27 enami /* Select page 0 registers. */ 289 1.28 ws NIC_BARRIER(nict, nich); 290 1.27 enami bus_space_write_1(nict, nich, ED_P0_CR, 291 1.27 enami ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 292 1.28 ws NIC_BARRIER(nict, nich); 293 1.27 enami /* Select word transfer. */ 294 1.62 nonaka bus_space_write_1(nict, nich, ED_P0_DCR, 295 1.68 tsutsui useword ? ED_DCR_WTS : 0); 296 1.28 ws NIC_BARRIER(nict, nich); 297 1.27 enami ne2000_readmem(nict, nich, asict, asich, 298 1.36 enami AX88190_NODEID_OFFSET, dsc->sc_enaddr, 299 1.27 enami ETHER_ADDR_LEN, useword); 300 1.27 enami } else { 301 1.68 tsutsui bool ne1000 = (nsc->sc_type == NE2000_TYPE_NE1000); 302 1.68 tsutsui 303 1.27 enami ne2000_readmem(nict, nich, asict, asich, 0, romdata, 304 1.27 enami sizeof(romdata), useword); 305 1.27 enami for (i = 0; i < ETHER_ADDR_LEN; i++) 306 1.27 enami dsc->sc_enaddr[i] = 307 1.68 tsutsui romdata[i * (ne1000 ? 1 : 2)]; 308 1.27 enami } 309 1.2 thorpej } else 310 1.35 thorpej memcpy(dsc->sc_enaddr, myea, sizeof(dsc->sc_enaddr)); 311 1.2 thorpej 312 1.2 thorpej /* Clear any pending interrupts that might have occurred above. */ 313 1.28 ws NIC_BARRIER(nict, nich); 314 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, 0xff); 315 1.28 ws NIC_BARRIER(nict, nich); 316 1.2 thorpej 317 1.32 thorpej if (dsc->sc_media_init == NULL) 318 1.32 thorpej dsc->sc_media_init = dp8390_media_init; 319 1.32 thorpej 320 1.32 thorpej if (dp8390_config(dsc)) { 321 1.57 cube aprint_error_dev(dsc->sc_dev, "setup failed\n"); 322 1.69 tsutsui return 1; 323 1.2 thorpej } 324 1.2 thorpej 325 1.69 tsutsui return 0; 326 1.2 thorpej } 327 1.2 thorpej 328 1.2 thorpej /* 329 1.2 thorpej * Detect an NE-2000 or compatible. Returns a model code. 330 1.2 thorpej */ 331 1.2 thorpej int 332 1.69 tsutsui ne2000_detect(bus_space_tag_t nict, bus_space_handle_t nich, 333 1.69 tsutsui bus_space_tag_t asict, bus_space_handle_t asich) 334 1.2 thorpej { 335 1.70 tsutsui const uint8_t test_pattern[32] = "THIS is A memory TEST pattern"; 336 1.69 tsutsui uint8_t test_buffer[32], tmp; 337 1.56 dholland int i, rv = NE2000_TYPE_UNKNOWN; 338 1.68 tsutsui int useword; 339 1.2 thorpej 340 1.2 thorpej /* Reset the board. */ 341 1.2 thorpej #ifdef GWETHER 342 1.2 thorpej bus_space_write_1(asict, asich, NE2000_ASIC_RESET, 0); 343 1.44 mycroft ASIC_BARRIER(asict, asich); 344 1.2 thorpej delay(200); 345 1.2 thorpej #endif /* GWETHER */ 346 1.2 thorpej tmp = bus_space_read_1(asict, asich, NE2000_ASIC_RESET); 347 1.44 mycroft ASIC_BARRIER(asict, asich); 348 1.2 thorpej delay(10000); 349 1.2 thorpej 350 1.2 thorpej /* 351 1.2 thorpej * I don't know if this is necessary; probably cruft leftover from 352 1.2 thorpej * Clarkson packet driver code. Doesn't do a thing on the boards I've 353 1.2 thorpej * tested. -DG [note that a outb(0x84, 0) seems to work here, and is 354 1.2 thorpej * non-invasive...but some boards don't seem to reset and I don't have 355 1.2 thorpej * complete documentation on what the 'right' thing to do is...so we do 356 1.2 thorpej * the invasive thing for now. Yuck.] 357 1.2 thorpej */ 358 1.2 thorpej bus_space_write_1(asict, asich, NE2000_ASIC_RESET, tmp); 359 1.44 mycroft ASIC_BARRIER(asict, asich); 360 1.2 thorpej delay(5000); 361 1.2 thorpej 362 1.2 thorpej /* 363 1.2 thorpej * This is needed because some NE clones apparently don't reset the 364 1.2 thorpej * NIC properly (or the NIC chip doesn't reset fully on power-up). 365 1.2 thorpej * XXX - this makes the probe invasive! Done against my better 366 1.2 thorpej * judgement. -DLG 367 1.2 thorpej */ 368 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR, 369 1.2 thorpej ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STP); 370 1.28 ws NIC_BARRIER(nict, nich); 371 1.2 thorpej 372 1.2 thorpej delay(5000); 373 1.2 thorpej 374 1.4 thorpej /* 375 1.41 wiz * Generic probe routine for testing for the existence of a DS8390. 376 1.79 andvar * Must be performed after the NIC has just been reset. This 377 1.4 thorpej * works by looking at certain register values that are guaranteed 378 1.4 thorpej * to be initialized a certain way after power-up or reset. 379 1.4 thorpej * 380 1.4 thorpej * Specifically: 381 1.4 thorpej * 382 1.4 thorpej * Register reset bits set bits 383 1.4 thorpej * -------- ---------- -------- 384 1.4 thorpej * CR TXP, STA RD2, STP 385 1.4 thorpej * ISR RST 386 1.4 thorpej * IMR <all> 387 1.4 thorpej * DCR LAS 388 1.4 thorpej * TCR LB1, LB0 389 1.4 thorpej * 390 1.4 thorpej * We only look at CR and ISR, however, since looking at the others 391 1.4 thorpej * would require changing register pages, which would be intrusive 392 1.4 thorpej * if this isn't an 8390. 393 1.4 thorpej */ 394 1.4 thorpej 395 1.2 thorpej tmp = bus_space_read_1(nict, nich, ED_P0_CR); 396 1.2 thorpej if ((tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) != 397 1.2 thorpej (ED_CR_RD2 | ED_CR_STP)) 398 1.4 thorpej goto out; 399 1.4 thorpej 400 1.4 thorpej tmp = bus_space_read_1(nict, nich, ED_P0_ISR); 401 1.4 thorpej if ((tmp & ED_ISR_RST) != ED_ISR_RST) 402 1.2 thorpej goto out; 403 1.2 thorpej 404 1.2 thorpej bus_space_write_1(nict, nich, 405 1.2 thorpej ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 406 1.28 ws NIC_BARRIER(nict, nich); 407 1.2 thorpej 408 1.2 thorpej for (i = 0; i < 100; i++) { 409 1.2 thorpej if ((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RST) == 410 1.2 thorpej ED_ISR_RST) { 411 1.2 thorpej /* Ack the reset bit. */ 412 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RST); 413 1.28 ws NIC_BARRIER(nict, nich); 414 1.2 thorpej break; 415 1.2 thorpej } 416 1.2 thorpej delay(100); 417 1.2 thorpej } 418 1.2 thorpej 419 1.2 thorpej #if 0 420 1.2 thorpej /* XXX */ 421 1.2 thorpej if (i == 100) 422 1.2 thorpej goto out; 423 1.2 thorpej #endif 424 1.2 thorpej 425 1.2 thorpej /* 426 1.2 thorpej * Test the ability to read and write to the NIC memory. This has 427 1.2 thorpej * the side effect of determining if this is an NE1000 or an NE2000. 428 1.2 thorpej */ 429 1.2 thorpej 430 1.2 thorpej /* 431 1.2 thorpej * This prevents packets from being stored in the NIC memory when 432 1.2 thorpej * the readmem routine turns on the start bit in the CR. 433 1.2 thorpej */ 434 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RCR, ED_RCR_MON); 435 1.28 ws NIC_BARRIER(nict, nich); 436 1.2 thorpej 437 1.2 thorpej /* Temporarily initialize DCR for byte operations. */ 438 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS); 439 1.2 thorpej 440 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_PSTART, 8192 >> ED_PAGE_SHIFT); 441 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_PSTOP, 16384 >> ED_PAGE_SHIFT); 442 1.2 thorpej 443 1.2 thorpej /* 444 1.2 thorpej * Write a test pattern in byte mode. If this fails, then there 445 1.2 thorpej * probably isn't any memory at 8k - which likely means that the 446 1.2 thorpej * board is an NE2000. 447 1.2 thorpej */ 448 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, test_pattern, 8192, 449 1.15 thorpej sizeof(test_pattern), 0, 1); 450 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, 8192, test_buffer, 451 1.2 thorpej sizeof(test_buffer), 0); 452 1.2 thorpej 453 1.68 tsutsui if (memcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) { 454 1.2 thorpej /* We're an NE1000. */ 455 1.2 thorpej rv = NE2000_TYPE_NE1000; 456 1.68 tsutsui goto out; 457 1.68 tsutsui } 458 1.68 tsutsui 459 1.68 tsutsui /* not an NE1000 - try NE2000 */ 460 1.68 tsutsui 461 1.68 tsutsui /* try 16 bit mode first */ 462 1.68 tsutsui useword = 1; 463 1.68 tsutsui 464 1.68 tsutsui #ifdef NE2000_DETECT_8BIT 465 1.68 tsutsui /* 466 1.68 tsutsui * Check bus type in EEPROM first because some NE2000 compatible wedges 467 1.68 tsutsui * on 16 bit DMA access if the chip is configured in 8 bit mode. 468 1.68 tsutsui */ 469 1.68 tsutsui if (ne2000_detect_8bit(nict, nich, asict, asich)) 470 1.68 tsutsui useword = 0; 471 1.68 tsutsui #endif 472 1.68 tsutsui again: 473 1.68 tsutsui bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS | 474 1.68 tsutsui (useword ? ED_DCR_WTS : 0)); 475 1.68 tsutsui bus_space_write_1(nict, nich, ED_P0_PSTART, 16384 >> ED_PAGE_SHIFT); 476 1.68 tsutsui bus_space_write_1(nict, nich, ED_P0_PSTOP, 477 1.68 tsutsui (16384 + (useword ? 16384 : 8192)) >> ED_PAGE_SHIFT); 478 1.68 tsutsui 479 1.68 tsutsui /* 480 1.68 tsutsui * Write the test pattern in word mode. If this also fails, 481 1.68 tsutsui * then we don't know what this board is. 482 1.68 tsutsui */ 483 1.68 tsutsui ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384, 484 1.72 tsutsui sizeof(test_pattern), useword, 1); 485 1.68 tsutsui ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer, 486 1.68 tsutsui sizeof(test_buffer), useword); 487 1.68 tsutsui 488 1.68 tsutsui if (memcmp(test_pattern, test_buffer, sizeof(test_pattern)) != 0) { 489 1.68 tsutsui if (useword == 1) { 490 1.68 tsutsui /* try 8 bit mode */ 491 1.68 tsutsui useword = 0; 492 1.68 tsutsui goto again; 493 1.68 tsutsui } 494 1.68 tsutsui return NE2000_TYPE_UNKNOWN; /* not an NE2000 either */ 495 1.2 thorpej } 496 1.2 thorpej 497 1.68 tsutsui rv = NE2000_TYPE_NE2000; 498 1.68 tsutsui 499 1.68 tsutsui #if NRTL80X9 > 0 500 1.68 tsutsui /* Check for a Realtek RTL8019. */ 501 1.68 tsutsui if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) == RTL0_8019ID0 && 502 1.68 tsutsui bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) == RTL0_8019ID1) 503 1.68 tsutsui rv = NE2000_TYPE_RTL8019; 504 1.68 tsutsui #endif 505 1.68 tsutsui 506 1.68 tsutsui out: 507 1.2 thorpej /* Clear any pending interrupts that might have occurred above. */ 508 1.28 ws NIC_BARRIER(nict, nich); 509 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, 0xff); 510 1.2 thorpej 511 1.69 tsutsui return rv; 512 1.2 thorpej } 513 1.2 thorpej 514 1.68 tsutsui #ifdef NE2000_DETECT_8BIT 515 1.68 tsutsui static bool 516 1.68 tsutsui ne2000_detect_8bit(bus_space_tag_t nict, bus_space_handle_t nich, 517 1.68 tsutsui bus_space_tag_t asict, bus_space_handle_t asich) 518 1.68 tsutsui { 519 1.68 tsutsui bool is8bit; 520 1.68 tsutsui uint8_t romdata[32]; 521 1.68 tsutsui 522 1.68 tsutsui is8bit = false; 523 1.68 tsutsui 524 1.68 tsutsui /* Set DCR for 8 bit DMA. */ 525 1.68 tsutsui bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS); 526 1.68 tsutsui /* Read PROM area. */ 527 1.68 tsutsui ne2000_readmem(nict, nich, asict, asich, 0, romdata, 528 1.68 tsutsui sizeof(romdata), 0); 529 1.68 tsutsui if (romdata[28] == 'B' && romdata[30] == 'B') { 530 1.68 tsutsui /* 'B' (0x42) in 8 bit mode, 'W' (0x57) in 16 bit mode */ 531 1.68 tsutsui is8bit = true; 532 1.68 tsutsui } 533 1.68 tsutsui if (!is8bit) { 534 1.68 tsutsui /* not in 8 bit mode; put back DCR setting for 16 bit DMA */ 535 1.68 tsutsui bus_space_write_1(nict, nich, ED_P0_DCR, 536 1.68 tsutsui ED_DCR_FT1 | ED_DCR_LS | ED_DCR_WTS); 537 1.68 tsutsui } 538 1.68 tsutsui 539 1.68 tsutsui return is8bit; 540 1.68 tsutsui } 541 1.68 tsutsui #endif 542 1.68 tsutsui 543 1.2 thorpej /* 544 1.2 thorpej * Write an mbuf chain to the destination NIC memory address using programmed 545 1.2 thorpej * I/O. 546 1.2 thorpej */ 547 1.2 thorpej int 548 1.60 dsl ne2000_write_mbuf(struct dp8390_softc *sc, struct mbuf *m, int buf) 549 1.2 thorpej { 550 1.2 thorpej struct ne2000_softc *nsc = (struct ne2000_softc *)sc; 551 1.2 thorpej bus_space_tag_t nict = sc->sc_regt; 552 1.2 thorpej bus_space_handle_t nich = sc->sc_regh; 553 1.2 thorpej bus_space_tag_t asict = nsc->sc_asict; 554 1.2 thorpej bus_space_handle_t asich = nsc->sc_asich; 555 1.38 bouyer int savelen, padlen; 556 1.2 thorpej int maxwait = 100; /* about 120us */ 557 1.2 thorpej 558 1.2 thorpej savelen = m->m_pkthdr.len; 559 1.38 bouyer if (savelen < ETHER_MIN_LEN - ETHER_CRC_LEN) { 560 1.38 bouyer padlen = ETHER_MIN_LEN - ETHER_CRC_LEN - savelen; 561 1.38 bouyer savelen = ETHER_MIN_LEN - ETHER_CRC_LEN; 562 1.38 bouyer } else 563 1.38 bouyer padlen = 0; 564 1.38 bouyer 565 1.2 thorpej 566 1.2 thorpej /* Select page 0 registers. */ 567 1.28 ws NIC_BARRIER(nict, nich); 568 1.3 enami bus_space_write_1(nict, nich, ED_P0_CR, 569 1.3 enami ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 570 1.28 ws NIC_BARRIER(nict, nich); 571 1.2 thorpej 572 1.2 thorpej /* Reset remote DMA complete flag. */ 573 1.3 enami bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC); 574 1.28 ws NIC_BARRIER(nict, nich); 575 1.2 thorpej 576 1.2 thorpej /* Set up DMA byte count. */ 577 1.3 enami bus_space_write_1(nict, nich, ED_P0_RBCR0, savelen); 578 1.3 enami bus_space_write_1(nict, nich, ED_P0_RBCR1, savelen >> 8); 579 1.2 thorpej 580 1.2 thorpej /* Set up destination address in NIC mem. */ 581 1.3 enami bus_space_write_1(nict, nich, ED_P0_RSAR0, buf); 582 1.3 enami bus_space_write_1(nict, nich, ED_P0_RSAR1, buf >> 8); 583 1.2 thorpej 584 1.2 thorpej /* Set remote DMA write. */ 585 1.28 ws NIC_BARRIER(nict, nich); 586 1.3 enami bus_space_write_1(nict, nich, 587 1.3 enami ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA); 588 1.28 ws NIC_BARRIER(nict, nich); 589 1.2 thorpej 590 1.2 thorpej /* 591 1.2 thorpej * Transfer the mbuf chain to the NIC memory. NE2000 cards 592 1.2 thorpej * require that data be transferred as words, and only words, 593 1.2 thorpej * so that case requires some extra code to patch over odd-length 594 1.2 thorpej * mbufs. 595 1.2 thorpej */ 596 1.68 tsutsui if (nsc->sc_useword == 0) { 597 1.68 tsutsui /* byte ops are easy. */ 598 1.69 tsutsui for (; m != NULL; m = m->m_next) { 599 1.2 thorpej if (m->m_len) { 600 1.2 thorpej bus_space_write_multi_1(asict, asich, 601 1.69 tsutsui NE2000_ASIC_DATA, mtod(m, uint8_t *), 602 1.2 thorpej m->m_len); 603 1.2 thorpej } 604 1.2 thorpej } 605 1.38 bouyer if (padlen) { 606 1.38 bouyer for(; padlen > 0; padlen--) 607 1.38 bouyer bus_space_write_1(asict, asich, 608 1.38 bouyer NE2000_ASIC_DATA, 0); 609 1.38 bouyer } 610 1.2 thorpej } else { 611 1.68 tsutsui /* word ops are a bit trickier. */ 612 1.69 tsutsui uint8_t *data, savebyte[2]; 613 1.12 thorpej int l, leftover; 614 1.12 thorpej #ifdef DIAGNOSTIC 615 1.69 tsutsui uint8_t *lim; 616 1.12 thorpej #endif 617 1.12 thorpej /* Start out with no leftover data. */ 618 1.12 thorpej leftover = 0; 619 1.12 thorpej savebyte[0] = savebyte[1] = 0; 620 1.2 thorpej 621 1.69 tsutsui for (; m != NULL; m = m->m_next) { 622 1.2 thorpej l = m->m_len; 623 1.2 thorpej if (l == 0) 624 1.2 thorpej continue; 625 1.69 tsutsui data = mtod(m, uint8_t *); 626 1.12 thorpej #ifdef DIAGNOSTIC 627 1.12 thorpej lim = data + l; 628 1.12 thorpej #endif 629 1.12 thorpej while (l > 0) { 630 1.12 thorpej if (leftover) { 631 1.12 thorpej /* 632 1.12 thorpej * Data left over (from mbuf or 633 1.12 thorpej * realignment). Buffer the next 634 1.12 thorpej * byte, and write it and the 635 1.12 thorpej * leftover data out. 636 1.12 thorpej */ 637 1.12 thorpej savebyte[1] = *data++; 638 1.12 thorpej l--; 639 1.12 thorpej bus_space_write_stream_2(asict, asich, 640 1.12 thorpej NE2000_ASIC_DATA, 641 1.69 tsutsui *(uint16_t *)savebyte); 642 1.12 thorpej leftover = 0; 643 1.18 drochner } else if (BUS_SPACE_ALIGNED_POINTER(data, 644 1.69 tsutsui uint16_t) == 0) { 645 1.12 thorpej /* 646 1.12 thorpej * Unaligned data; buffer the next 647 1.12 thorpej * byte. 648 1.12 thorpej */ 649 1.12 thorpej savebyte[0] = *data++; 650 1.12 thorpej l--; 651 1.12 thorpej leftover = 1; 652 1.12 thorpej } else { 653 1.12 thorpej /* 654 1.12 thorpej * Aligned data; output contiguous 655 1.12 thorpej * words as much as we can, then 656 1.12 thorpej * buffer the remaining byte, if any. 657 1.12 thorpej */ 658 1.12 thorpej leftover = l & 1; 659 1.12 thorpej l &= ~1; 660 1.12 thorpej bus_space_write_multi_stream_2(asict, 661 1.12 thorpej asich, NE2000_ASIC_DATA, 662 1.69 tsutsui (uint16_t *)data, l >> 1); 663 1.12 thorpej data += l; 664 1.12 thorpej if (leftover) 665 1.12 thorpej savebyte[0] = *data++; 666 1.12 thorpej l = 0; 667 1.12 thorpej } 668 1.2 thorpej } 669 1.12 thorpej if (l < 0) 670 1.12 thorpej panic("ne2000_write_mbuf: negative len"); 671 1.12 thorpej #ifdef DIAGNOSTIC 672 1.12 thorpej if (data != lim) 673 1.12 thorpej panic("ne2000_write_mbuf: data != lim"); 674 1.12 thorpej #endif 675 1.2 thorpej } 676 1.12 thorpej if (leftover) { 677 1.2 thorpej savebyte[1] = 0; 678 1.10 sakamoto bus_space_write_stream_2(asict, asich, NE2000_ASIC_DATA, 679 1.69 tsutsui *(uint16_t *)savebyte); 680 1.38 bouyer } 681 1.38 bouyer if (padlen) { 682 1.43 mycroft for(; padlen > 1; padlen -= 2) 683 1.38 bouyer bus_space_write_stream_2(asict, asich, 684 1.38 bouyer NE2000_ASIC_DATA, 0); 685 1.2 thorpej } 686 1.2 thorpej } 687 1.28 ws NIC_BARRIER(nict, nich); 688 1.2 thorpej 689 1.74 rkujawa /* some AX88796 doesn't seem to have remote DMA complete */ 690 1.46 bsh if (sc->sc_flags & DP8390_NO_REMOTE_DMA_COMPLETE) 691 1.69 tsutsui return savelen; 692 1.46 bsh 693 1.2 thorpej /* 694 1.2 thorpej * Wait for remote DMA to complete. This is necessary because on the 695 1.2 thorpej * transmit side, data is handled internally by the NIC in bursts, and 696 1.2 thorpej * we can't start another remote DMA until this one completes. Not 697 1.2 thorpej * waiting causes really bad things to happen - like the NIC wedging 698 1.2 thorpej * the bus. 699 1.2 thorpej */ 700 1.2 thorpej while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) != 701 1.28 ws ED_ISR_RDC) && --maxwait) { 702 1.49 christos (void)bus_space_read_1(nict, nich, ED_P0_CRDA1); 703 1.49 christos (void)bus_space_read_1(nict, nich, ED_P0_CRDA0); 704 1.28 ws NIC_BARRIER(nict, nich); 705 1.28 ws DELAY(1); 706 1.28 ws } 707 1.2 thorpej 708 1.2 thorpej if (maxwait == 0) { 709 1.2 thorpej log(LOG_WARNING, 710 1.2 thorpej "%s: remote transmit DMA failed to complete\n", 711 1.57 cube device_xname(sc->sc_dev)); 712 1.2 thorpej dp8390_reset(sc); 713 1.2 thorpej } 714 1.2 thorpej 715 1.69 tsutsui return savelen; 716 1.2 thorpej } 717 1.2 thorpej 718 1.2 thorpej /* 719 1.78 andvar * Given a source and destination address, copy 'amount' of a packet from 720 1.2 thorpej * the ring buffer into a linear destination buffer. Takes into account 721 1.2 thorpej * ring-wrap. 722 1.2 thorpej */ 723 1.2 thorpej int 724 1.60 dsl ne2000_ring_copy(struct dp8390_softc *sc, int src, void *dstv, u_short amount) 725 1.2 thorpej { 726 1.54 christos char *dst = dstv; 727 1.2 thorpej struct ne2000_softc *nsc = (struct ne2000_softc *)sc; 728 1.2 thorpej bus_space_tag_t nict = sc->sc_regt; 729 1.2 thorpej bus_space_handle_t nich = sc->sc_regh; 730 1.2 thorpej bus_space_tag_t asict = nsc->sc_asict; 731 1.2 thorpej bus_space_handle_t asich = nsc->sc_asich; 732 1.2 thorpej u_short tmp_amount; 733 1.42 mycroft int useword = nsc->sc_useword; 734 1.2 thorpej 735 1.2 thorpej /* Does copy wrap to lower addr in ring buffer? */ 736 1.2 thorpej if (src + amount > sc->mem_end) { 737 1.2 thorpej tmp_amount = sc->mem_end - src; 738 1.2 thorpej 739 1.2 thorpej /* Copy amount up to end of NIC memory. */ 740 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, src, 741 1.69 tsutsui (uint8_t *)dst, tmp_amount, useword); 742 1.2 thorpej 743 1.2 thorpej amount -= tmp_amount; 744 1.2 thorpej src = sc->mem_ring; 745 1.2 thorpej dst += tmp_amount; 746 1.2 thorpej } 747 1.2 thorpej 748 1.69 tsutsui ne2000_readmem(nict, nich, asict, asich, src, (uint8_t *)dst, 749 1.2 thorpej amount, useword); 750 1.2 thorpej 751 1.69 tsutsui return src + amount; 752 1.2 thorpej } 753 1.2 thorpej 754 1.2 thorpej void 755 1.60 dsl ne2000_read_hdr(struct dp8390_softc *sc, int buf, struct dp8390_ring *hdr) 756 1.2 thorpej { 757 1.2 thorpej struct ne2000_softc *nsc = (struct ne2000_softc *)sc; 758 1.2 thorpej 759 1.2 thorpej ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich, 760 1.69 tsutsui buf, (uint8_t *)hdr, sizeof(struct dp8390_ring), 761 1.42 mycroft nsc->sc_useword); 762 1.7 thorpej #if BYTE_ORDER == BIG_ENDIAN 763 1.7 thorpej hdr->count = bswap16(hdr->count); 764 1.7 thorpej #endif 765 1.2 thorpej } 766 1.2 thorpej 767 1.2 thorpej int 768 1.52 christos ne2000_test_mem(struct dp8390_softc *sc) 769 1.2 thorpej { 770 1.2 thorpej 771 1.2 thorpej /* Noop. */ 772 1.69 tsutsui return 0; 773 1.2 thorpej } 774 1.2 thorpej 775 1.2 thorpej /* 776 1.2 thorpej * Given a NIC memory source address and a host memory destination address, 777 1.2 thorpej * copy 'amount' from NIC to host using programmed i/o. The 'amount' is 778 1.2 thorpej * rounded up to a word - ok as long as mbufs are word sized. 779 1.2 thorpej */ 780 1.2 thorpej void 781 1.69 tsutsui ne2000_readmem(bus_space_tag_t nict, bus_space_handle_t nich, 782 1.69 tsutsui bus_space_tag_t asict, bus_space_handle_t asich, 783 1.69 tsutsui int src, uint8_t *dst, size_t amount, int useword) 784 1.2 thorpej { 785 1.2 thorpej 786 1.2 thorpej /* Select page 0 registers. */ 787 1.28 ws NIC_BARRIER(nict, nich); 788 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR, 789 1.2 thorpej ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 790 1.28 ws NIC_BARRIER(nict, nich); 791 1.2 thorpej 792 1.2 thorpej /* Round up to a word. */ 793 1.66 tsutsui amount = roundup2(amount, sizeof(uint16_t)); 794 1.2 thorpej 795 1.2 thorpej /* Set up DMA byte count. */ 796 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR0, amount); 797 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR1, amount >> 8); 798 1.2 thorpej 799 1.2 thorpej /* Set up source address in NIC mem. */ 800 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR0, src); 801 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR1, src >> 8); 802 1.2 thorpej 803 1.28 ws NIC_BARRIER(nict, nich); 804 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR, 805 1.2 thorpej ED_CR_RD0 | ED_CR_PAGE_0 | ED_CR_STA); 806 1.2 thorpej 807 1.44 mycroft ASIC_BARRIER(asict, asich); 808 1.2 thorpej if (useword) 809 1.10 sakamoto bus_space_read_multi_stream_2(asict, asich, NE2000_ASIC_DATA, 810 1.69 tsutsui (uint16_t *)dst, amount >> 1); 811 1.2 thorpej else 812 1.2 thorpej bus_space_read_multi_1(asict, asich, NE2000_ASIC_DATA, 813 1.2 thorpej dst, amount); 814 1.2 thorpej } 815 1.2 thorpej 816 1.2 thorpej /* 817 1.2 thorpej * Stripped down routine for writing a linear buffer to NIC memory. Only 818 1.2 thorpej * used in the probe routine to test the memory. 'len' must be even. 819 1.2 thorpej */ 820 1.2 thorpej void 821 1.69 tsutsui ne2000_writemem(bus_space_tag_t nict, bus_space_handle_t nich, 822 1.69 tsutsui bus_space_tag_t asict, bus_space_handle_t asich, 823 1.70 tsutsui const uint8_t *src, int dst, size_t len, int useword, int quiet) 824 1.2 thorpej { 825 1.2 thorpej int maxwait = 100; /* about 120us */ 826 1.2 thorpej 827 1.2 thorpej /* Select page 0 registers. */ 828 1.28 ws NIC_BARRIER(nict, nich); 829 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR, 830 1.2 thorpej ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 831 1.28 ws NIC_BARRIER(nict, nich); 832 1.2 thorpej 833 1.2 thorpej /* Reset remote DMA complete flag. */ 834 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC); 835 1.28 ws NIC_BARRIER(nict, nich); 836 1.2 thorpej 837 1.2 thorpej /* Set up DMA byte count. */ 838 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR0, len); 839 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR1, len >> 8); 840 1.2 thorpej 841 1.2 thorpej /* Set up destination address in NIC mem. */ 842 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR0, dst); 843 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR1, dst >> 8); 844 1.2 thorpej 845 1.2 thorpej /* Set remote DMA write. */ 846 1.28 ws NIC_BARRIER(nict, nich); 847 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR, 848 1.2 thorpej ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA); 849 1.44 mycroft NIC_BARRIER(nict, nich); 850 1.2 thorpej 851 1.44 mycroft ASIC_BARRIER(asict, asich); 852 1.2 thorpej if (useword) 853 1.10 sakamoto bus_space_write_multi_stream_2(asict, asich, NE2000_ASIC_DATA, 854 1.70 tsutsui (const uint16_t *)src, len >> 1); 855 1.2 thorpej else 856 1.2 thorpej bus_space_write_multi_1(asict, asich, NE2000_ASIC_DATA, 857 1.2 thorpej src, len); 858 1.44 mycroft ASIC_BARRIER(asict, asich); 859 1.2 thorpej 860 1.2 thorpej /* 861 1.2 thorpej * Wait for remote DMA to complete. This is necessary because on the 862 1.2 thorpej * transmit side, data is handled internally by the NIC in bursts, and 863 1.2 thorpej * we can't start another remote DMA until this one completes. Not 864 1.2 thorpej * waiting causes really bad things to happen - like the NIC wedging 865 1.2 thorpej * the bus. 866 1.2 thorpej */ 867 1.2 thorpej while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) != 868 1.28 ws ED_ISR_RDC) && --maxwait) 869 1.28 ws DELAY(1); 870 1.2 thorpej 871 1.15 thorpej if (!quiet && maxwait == 0) 872 1.2 thorpej printf("ne2000_writemem: failed to complete\n"); 873 1.24 itojun } 874 1.24 itojun 875 1.24 itojun int 876 1.60 dsl ne2000_detach(struct ne2000_softc *sc, int flags) 877 1.24 itojun { 878 1.26 enami 879 1.69 tsutsui return dp8390_detach(&sc->sc_dp8390, flags); 880 1.2 thorpej } 881 1.29 ws 882 1.61 uwe bool 883 1.67 dyoung ne2000_suspend(device_t self, const pmf_qual_t *qual) 884 1.61 uwe { 885 1.61 uwe struct ne2000_softc *sc = device_private(self); 886 1.61 uwe struct dp8390_softc *dsc = &sc->sc_dp8390; 887 1.61 uwe int s; 888 1.61 uwe 889 1.61 uwe s = splnet(); 890 1.61 uwe 891 1.61 uwe dp8390_stop(dsc); 892 1.61 uwe dp8390_disable(dsc); 893 1.61 uwe 894 1.61 uwe splx(s); 895 1.61 uwe return true; 896 1.61 uwe } 897 1.61 uwe 898 1.61 uwe bool 899 1.67 dyoung ne2000_resume(device_t self, const pmf_qual_t *qual) 900 1.61 uwe { 901 1.61 uwe struct ne2000_softc *sc = device_private(self); 902 1.61 uwe struct dp8390_softc *dsc = &sc->sc_dp8390; 903 1.61 uwe struct ifnet *ifp = &dsc->sc_ec.ec_if; 904 1.61 uwe int s; 905 1.61 uwe 906 1.61 uwe s = splnet(); 907 1.61 uwe 908 1.61 uwe if (ifp->if_flags & IFF_UP) { 909 1.61 uwe if (dp8390_enable(dsc) == 0) 910 1.61 uwe dp8390_init(dsc); 911 1.61 uwe } 912 1.61 uwe 913 1.61 uwe splx(s); 914 1.61 uwe return true; 915 1.61 uwe } 916