1 /* $NetBSD: if_ae.c,v 1.70 2000/09/13 05:21:16 scottr Exp $ */ 2 3 /* 4 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet 5 * adapters. 6 * 7 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. 8 * 9 * Copyright (C) 1993, David Greenman. This software may be used, modified, 10 * copied, distributed, and sold, in both source and binary form provided that 11 * the above copyright and these terms are retained. Under no circumstances is 12 * the author responsible for the proper functioning of this software, nor does 13 * the author assume any responsibility for damages incurred with its use. 14 */ 15 16 #include "bpfilter.h" 17 18 #include <sys/param.h> 19 #include <sys/systm.h> 20 #include <sys/device.h> 21 #include <sys/mbuf.h> 22 #include <sys/socket.h> 23 24 #include <net/if.h> 25 #include <net/if_media.h> 26 #include <net/if_ether.h> 27 28 #include <machine/bus.h> 29 30 #include <dev/ic/dp8390reg.h> 31 #include <dev/ic/dp8390var.h> 32 #include <mac68k/dev/if_aevar.h> 33 34 int 35 ae_size_card_memory(bst, bsh, ofs) 36 bus_space_tag_t bst; 37 bus_space_handle_t bsh; 38 int ofs; 39 { 40 int i1, i2, i3, i4; 41 42 /* 43 * banks; also assume it will generally mirror in upper banks 44 * if not installed. 45 */ 46 i1 = (8192 * 0); 47 i2 = (8192 * 1); 48 i3 = (8192 * 2); 49 i4 = (8192 * 3); 50 51 bus_space_write_2(bst, bsh, ofs + i1, 0x1111); 52 bus_space_write_2(bst, bsh, ofs + i2, 0x2222); 53 bus_space_write_2(bst, bsh, ofs + i3, 0x3333); 54 bus_space_write_2(bst, bsh, ofs + i4, 0x4444); 55 56 if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 && 57 bus_space_read_2(bst, bsh, ofs + i2) == 0x2222 && 58 bus_space_read_2(bst, bsh, ofs + i3) == 0x3333 && 59 bus_space_read_2(bst, bsh, ofs + i4) == 0x4444) 60 return 8192 * 4; 61 62 if ((bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 && 63 bus_space_read_2(bst, bsh, ofs + i2) == 0x2222) || 64 (bus_space_read_2(bst, bsh, ofs + i1) == 0x3333 && 65 bus_space_read_2(bst, bsh, ofs + i2) == 0x4444)) 66 return 8192 * 2; 67 68 if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 || 69 bus_space_read_2(bst, bsh, ofs + i1) == 0x4444) 70 return 8192; 71 72 return 0; 73 } 74 75 /* 76 * Zero memory and verify that it is clear. The only difference between 77 * this and the default test_mem function is that the DP8390-based NuBus 78 * cards * apparently require word-wide writes and byte-wide reads, an 79 * `interesting' combination. 80 */ 81 int 82 ae_test_mem(sc) 83 struct dp8390_softc *sc; 84 { 85 bus_space_tag_t buft = sc->sc_buft; 86 bus_space_handle_t bufh = sc->sc_bufh; 87 int i; 88 89 bus_space_set_region_2(buft, bufh, sc->mem_start, 0, 90 sc->mem_size / 2); 91 92 for (i = 0; i < sc->mem_size; ++i) { 93 if (bus_space_read_1(sc->sc_buft, sc->sc_bufh, i)) { 94 printf(": failed to clear NIC buffer at offset %x - " 95 "check configuration\n", (sc->mem_start + i)); 96 return 1; 97 } 98 } 99 100 return 0; 101 } 102 103 /* 104 * Copy packet from mbuf to the board memory Currently uses an extra 105 * buffer/extra memory copy, unless the whole packet fits in one mbuf. 106 * 107 * As in the test_mem function, we use word-wide writes. 108 */ 109 int 110 ae_write_mbuf(sc, m, buf) 111 struct dp8390_softc *sc; 112 struct mbuf *m; 113 int buf; 114 { 115 u_char *data, savebyte[2]; 116 int len, wantbyte; 117 u_short totlen = 0; 118 119 wantbyte = 0; 120 121 for (; m ; m = m->m_next) { 122 data = mtod(m, u_char *); 123 len = m->m_len; 124 totlen += len; 125 if (len > 0) { 126 /* Finish the last word. */ 127 if (wantbyte) { 128 savebyte[1] = *data; 129 bus_space_write_region_2(sc->sc_buft, 130 sc->sc_bufh, buf, (u_int16_t *)savebyte, 1); 131 buf += 2; 132 data++; 133 len--; 134 wantbyte = 0; 135 } 136 /* Output contiguous words. */ 137 if (len > 1) { 138 bus_space_write_region_2( 139 sc->sc_buft, sc->sc_bufh, 140 buf, (u_int16_t *)data, len >> 1); 141 buf += len & ~1; 142 data += len & ~1; 143 len &= 1; 144 } 145 /* Save last byte, if necessary. */ 146 if (len == 1) { 147 savebyte[0] = *data; 148 wantbyte = 1; 149 } 150 } 151 } 152 153 if (wantbyte) { 154 savebyte[1] = 0; 155 bus_space_write_region_2(sc->sc_buft, sc->sc_bufh, 156 buf, (u_int16_t *)savebyte, 1); 157 } 158 return (totlen); 159 } 160