1/*-
2 * Copyright (c) 2005, M. Warner Losh
3 * All rights reserved.
4 * Copyright (c) 1995, David Greenman
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
12 * disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/ed/if_ed_novell.c 149840 2005-09-07 03:20:33Z imp $");
33
34#include "opt_ed.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sockio.h>
39#include <sys/mbuf.h>
40#include <sys/kernel.h>
41#include <sys/socket.h>
42#include <sys/syslog.h>
43
44#include <sys/bus.h>
45
46#include <machine/bus.h>
47#include <sys/rman.h>
48#include <machine/resource.h>
49
50#include <net/ethernet.h>
51#include <net/if.h>
52#include <net/if_arp.h>
53#include <net/if_dl.h>
54#include <net/if_mib.h>
55#include <net/if_media.h>
56
57#include <net/bpf.h>
58
59#include <dev/ed/if_edreg.h>
60#include <dev/ed/if_edvar.h>
61
62static int ed_probe_gwether(device_t);
63
64/*
65 * Probe and vendor-specific initialization routine for NE1000/2000 boards
66 */
67int
68ed_probe_Novell_generic(device_t dev, int flags)
69{
70 struct ed_softc *sc = device_get_softc(dev);
71 u_int memsize;
72 int error;
73 u_char tmp;
74 static char test_pattern[32] = "THIS is A memory TEST pattern";
75 char test_buffer[32];
76
77 /* Reset the board */
78 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) {
79 ed_asic_outb(sc, ED_NOVELL_RESET, 0);
80 DELAY(200);
81 }
82 tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
83
84 /*
85 * I don't know if this is necessary; probably cruft leftover from
86 * Clarkson packet driver code. Doesn't do a thing on the boards I've
87 * tested. -DG
88 */
89 ed_asic_outb(sc, ED_NOVELL_RESET, tmp);
90 DELAY(5000);
91
92 /*
93 * This is needed because some NE clones apparently don't reset the
94 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
95 * - this makes the probe invasive! ...Done against my better
96 * judgement. -DLG
97 */
98 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
99 DELAY(5000);
100
101 /* Make sure that we really have an 8390 based board */
102 if (!ed_probe_generic8390(sc))
103 return (ENXIO);
104
105 sc->vendor = ED_VENDOR_NOVELL;
106 sc->mem_shared = 0;
107 sc->cr_proto = ED_CR_RD2;
108
109 /*
110 * Test the ability to read and write to the NIC memory. This has the
111 * side affect of determining if this is an NE1000 or an NE2000.
112 */
113
114 /*
115 * This prevents packets from being stored in the NIC memory when the
116 * readmem routine turns on the start bit in the CR.
117 */
118 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_MON);
119
120 /* Temporarily initialize DCR for byte operations */
121 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
122
123 ed_nic_outb(sc, ED_P0_PSTART, 8192 / ED_PAGE_SIZE);
124 ed_nic_outb(sc, ED_P0_PSTOP, 16384 / ED_PAGE_SIZE);
125
126 sc->isa16bit = 0;
127
128 /*
129 * Write a test pattern in byte mode. If this fails, then there
130 * probably isn't any memory at 8k - which likely means that the board
131 * is an NE2000.
132 */
133 ed_pio_writemem(sc, test_pattern, 8192, sizeof(test_pattern));
134 ed_pio_readmem(sc, 8192, test_buffer, sizeof(test_pattern));
135
136 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) {
137 sc->type = ED_TYPE_NE1000;
138 sc->type_str = "NE1000";
139 } else {
140
141 /* Not an NE1000 - try NE2000 */
142 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
143 ed_nic_outb(sc, ED_P0_PSTART, 16384 / ED_PAGE_SIZE);
144 ed_nic_outb(sc, ED_P0_PSTOP, 32768 / ED_PAGE_SIZE);
145
146 sc->isa16bit = 1;
147
148 /*
149 * Write a test pattern in word mode. If this also fails, then
150 * we don't know what this board is.
151 */
152 ed_pio_writemem(sc, test_pattern, 16384, sizeof(test_pattern));
153 ed_pio_readmem(sc, 16384, test_buffer, sizeof(test_pattern));
154 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) {
155 sc->type = ED_TYPE_NE2000;
156 sc->type_str = "NE2000";
157 } else {
158 return (ENXIO);
159 }
160 }
161 sc->chip_type = ED_CHIP_TYPE_DP8390;
162
163 /* 8k of memory plus an additional 8k if 16bit */
164 memsize = 8192 + sc->isa16bit * 8192;
165 sc->mem_size = memsize;
166
167 /* NIC memory doesn't start at zero on an NE board */
168 /* The start address is tied to the bus width */
169 sc->mem_start = 8192 + sc->isa16bit * 8192;
170 sc->mem_end = sc->mem_start + memsize;
171 sc->tx_page_start = memsize / ED_PAGE_SIZE;
172
173 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) {
174 error = ed_probe_gwether(dev);
175 if (error)
176 return (error);
177 }
178
179 /*
180 * Use one xmit buffer if < 16k, two buffers otherwise (if not told
181 * otherwise).
182 */
183 if ((memsize < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING))
184 sc->txb_cnt = 1;
185 else
186 sc->txb_cnt = 2;
187
188 sc->rec_page_start = sc->tx_page_start + sc->txb_cnt * ED_TXBUF_SIZE;
189 sc->rec_page_stop = sc->tx_page_start + memsize / ED_PAGE_SIZE;
190
191 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
192 /* clear any pending interrupts that might have occurred above */
193 ed_nic_outb(sc, ED_P0_ISR, 0xff);
194
195 return (0);
196}
197
198int
199ed_probe_Novell(device_t dev, int port_rid, int flags)
200{
201 struct ed_softc *sc = device_get_softc(dev);
202 int error;
203
204 error = ed_alloc_port(dev, port_rid, ED_NOVELL_IO_PORTS);
205 if (error)
206 return (error);
207
208 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
209 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
210
211 return ed_probe_Novell_generic(dev, flags);
212}
213
214static int
215ed_probe_gwether(device_t dev)
216{
217 int x, i, msize = 0;
218 bus_size_t mstart = 0;
219 char pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE], tbuf[ED_PAGE_SIZE];
220 struct ed_softc *sc = device_get_softc(dev);
221
222 for (i = 0; i < ED_PAGE_SIZE; i++)
223 pbuf0[i] = 0;
224
225 /* Clear all the memory. */
226 for (x = 1; x < 256; x++)
227 ed_pio_writemem(sc, pbuf0, x * 256, ED_PAGE_SIZE);
228
229 /* Search for the start of RAM. */
230 for (x = 1; x < 256; x++) {
231 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
232 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
233 for (i = 0; i < ED_PAGE_SIZE; i++)
234 pbuf[i] = 255 - x;
235 ed_pio_writemem(sc, pbuf, x * 256, ED_PAGE_SIZE);
236 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
237 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) {
238 mstart = x * ED_PAGE_SIZE;
239 msize = ED_PAGE_SIZE;
240 break;
241 }
242 }
243 }
244 if (mstart == 0) {
245 device_printf(dev, "Cannot find start of RAM.\n");
246 return (ENXIO);
247 }
248
249 /* Probe the size of RAM. */
250 for (x = (mstart / ED_PAGE_SIZE) + 1; x < 256; x++) {
251 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
252 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
253 for (i = 0; i < ED_PAGE_SIZE; i++)
254 pbuf[i] = 255 - x;
255 ed_pio_writemem(sc, pbuf, x * 256, ED_PAGE_SIZE);
256 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
257 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0)
258 msize += ED_PAGE_SIZE;
259 else {
260 break;
261 }
262 } else {
263 break;
264 }
265 }
266
267 if (msize == 0) {
268 device_printf(dev,
269 "Cannot find any RAM, start : %d, x = %d.\n",
270 (int)mstart, x);
271 return (ENXIO);
272 }
273 if (bootverbose)
274 device_printf(dev,
275 "RAM start at %d, size : %d.\n", (int)mstart, msize);
276
277 sc->mem_size = msize;
278 sc->mem_start = mstart;
279 sc->mem_end = msize + mstart;
280 sc->tx_page_start = mstart / ED_PAGE_SIZE;
281 return 0;
282}
283
284void
285ed_Novell_read_mac(struct ed_softc *sc)
286{
287 int n;
288 uint8_t romdata[16];
289
290 /*
291 * Pull the MAC address out of the roms that are on the isa
292 * version of these cards.
293 */
294 ed_pio_readmem(sc, 0, romdata, 16);
295 for (n = 0; n < ETHER_ADDR_LEN; n++)
296 sc->enaddr[n] = romdata[n * (sc->isa16bit + 1)];
297}
2 * Copyright (c) 2005, M. Warner Losh
3 * All rights reserved.
4 * Copyright (c) 1995, David Greenman
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
12 * disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/ed/if_ed_novell.c 149840 2005-09-07 03:20:33Z imp $");
33
34#include "opt_ed.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sockio.h>
39#include <sys/mbuf.h>
40#include <sys/kernel.h>
41#include <sys/socket.h>
42#include <sys/syslog.h>
43
44#include <sys/bus.h>
45
46#include <machine/bus.h>
47#include <sys/rman.h>
48#include <machine/resource.h>
49
50#include <net/ethernet.h>
51#include <net/if.h>
52#include <net/if_arp.h>
53#include <net/if_dl.h>
54#include <net/if_mib.h>
55#include <net/if_media.h>
56
57#include <net/bpf.h>
58
59#include <dev/ed/if_edreg.h>
60#include <dev/ed/if_edvar.h>
61
62static int ed_probe_gwether(device_t);
63
64/*
65 * Probe and vendor-specific initialization routine for NE1000/2000 boards
66 */
67int
68ed_probe_Novell_generic(device_t dev, int flags)
69{
70 struct ed_softc *sc = device_get_softc(dev);
71 u_int memsize;
72 int error;
73 u_char tmp;
74 static char test_pattern[32] = "THIS is A memory TEST pattern";
75 char test_buffer[32];
76
77 /* Reset the board */
78 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) {
79 ed_asic_outb(sc, ED_NOVELL_RESET, 0);
80 DELAY(200);
81 }
82 tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
83
84 /*
85 * I don't know if this is necessary; probably cruft leftover from
86 * Clarkson packet driver code. Doesn't do a thing on the boards I've
87 * tested. -DG
88 */
89 ed_asic_outb(sc, ED_NOVELL_RESET, tmp);
90 DELAY(5000);
91
92 /*
93 * This is needed because some NE clones apparently don't reset the
94 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
95 * - this makes the probe invasive! ...Done against my better
96 * judgement. -DLG
97 */
98 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
99 DELAY(5000);
100
101 /* Make sure that we really have an 8390 based board */
102 if (!ed_probe_generic8390(sc))
103 return (ENXIO);
104
105 sc->vendor = ED_VENDOR_NOVELL;
106 sc->mem_shared = 0;
107 sc->cr_proto = ED_CR_RD2;
108
109 /*
110 * Test the ability to read and write to the NIC memory. This has the
111 * side affect of determining if this is an NE1000 or an NE2000.
112 */
113
114 /*
115 * This prevents packets from being stored in the NIC memory when the
116 * readmem routine turns on the start bit in the CR.
117 */
118 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_MON);
119
120 /* Temporarily initialize DCR for byte operations */
121 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
122
123 ed_nic_outb(sc, ED_P0_PSTART, 8192 / ED_PAGE_SIZE);
124 ed_nic_outb(sc, ED_P0_PSTOP, 16384 / ED_PAGE_SIZE);
125
126 sc->isa16bit = 0;
127
128 /*
129 * Write a test pattern in byte mode. If this fails, then there
130 * probably isn't any memory at 8k - which likely means that the board
131 * is an NE2000.
132 */
133 ed_pio_writemem(sc, test_pattern, 8192, sizeof(test_pattern));
134 ed_pio_readmem(sc, 8192, test_buffer, sizeof(test_pattern));
135
136 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) {
137 sc->type = ED_TYPE_NE1000;
138 sc->type_str = "NE1000";
139 } else {
140
141 /* Not an NE1000 - try NE2000 */
142 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
143 ed_nic_outb(sc, ED_P0_PSTART, 16384 / ED_PAGE_SIZE);
144 ed_nic_outb(sc, ED_P0_PSTOP, 32768 / ED_PAGE_SIZE);
145
146 sc->isa16bit = 1;
147
148 /*
149 * Write a test pattern in word mode. If this also fails, then
150 * we don't know what this board is.
151 */
152 ed_pio_writemem(sc, test_pattern, 16384, sizeof(test_pattern));
153 ed_pio_readmem(sc, 16384, test_buffer, sizeof(test_pattern));
154 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) {
155 sc->type = ED_TYPE_NE2000;
156 sc->type_str = "NE2000";
157 } else {
158 return (ENXIO);
159 }
160 }
161 sc->chip_type = ED_CHIP_TYPE_DP8390;
162
163 /* 8k of memory plus an additional 8k if 16bit */
164 memsize = 8192 + sc->isa16bit * 8192;
165 sc->mem_size = memsize;
166
167 /* NIC memory doesn't start at zero on an NE board */
168 /* The start address is tied to the bus width */
169 sc->mem_start = 8192 + sc->isa16bit * 8192;
170 sc->mem_end = sc->mem_start + memsize;
171 sc->tx_page_start = memsize / ED_PAGE_SIZE;
172
173 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) {
174 error = ed_probe_gwether(dev);
175 if (error)
176 return (error);
177 }
178
179 /*
180 * Use one xmit buffer if < 16k, two buffers otherwise (if not told
181 * otherwise).
182 */
183 if ((memsize < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING))
184 sc->txb_cnt = 1;
185 else
186 sc->txb_cnt = 2;
187
188 sc->rec_page_start = sc->tx_page_start + sc->txb_cnt * ED_TXBUF_SIZE;
189 sc->rec_page_stop = sc->tx_page_start + memsize / ED_PAGE_SIZE;
190
191 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
192 /* clear any pending interrupts that might have occurred above */
193 ed_nic_outb(sc, ED_P0_ISR, 0xff);
194
195 return (0);
196}
197
198int
199ed_probe_Novell(device_t dev, int port_rid, int flags)
200{
201 struct ed_softc *sc = device_get_softc(dev);
202 int error;
203
204 error = ed_alloc_port(dev, port_rid, ED_NOVELL_IO_PORTS);
205 if (error)
206 return (error);
207
208 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
209 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
210
211 return ed_probe_Novell_generic(dev, flags);
212}
213
214static int
215ed_probe_gwether(device_t dev)
216{
217 int x, i, msize = 0;
218 bus_size_t mstart = 0;
219 char pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE], tbuf[ED_PAGE_SIZE];
220 struct ed_softc *sc = device_get_softc(dev);
221
222 for (i = 0; i < ED_PAGE_SIZE; i++)
223 pbuf0[i] = 0;
224
225 /* Clear all the memory. */
226 for (x = 1; x < 256; x++)
227 ed_pio_writemem(sc, pbuf0, x * 256, ED_PAGE_SIZE);
228
229 /* Search for the start of RAM. */
230 for (x = 1; x < 256; x++) {
231 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
232 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
233 for (i = 0; i < ED_PAGE_SIZE; i++)
234 pbuf[i] = 255 - x;
235 ed_pio_writemem(sc, pbuf, x * 256, ED_PAGE_SIZE);
236 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
237 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) {
238 mstart = x * ED_PAGE_SIZE;
239 msize = ED_PAGE_SIZE;
240 break;
241 }
242 }
243 }
244 if (mstart == 0) {
245 device_printf(dev, "Cannot find start of RAM.\n");
246 return (ENXIO);
247 }
248
249 /* Probe the size of RAM. */
250 for (x = (mstart / ED_PAGE_SIZE) + 1; x < 256; x++) {
251 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
252 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
253 for (i = 0; i < ED_PAGE_SIZE; i++)
254 pbuf[i] = 255 - x;
255 ed_pio_writemem(sc, pbuf, x * 256, ED_PAGE_SIZE);
256 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
257 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0)
258 msize += ED_PAGE_SIZE;
259 else {
260 break;
261 }
262 } else {
263 break;
264 }
265 }
266
267 if (msize == 0) {
268 device_printf(dev,
269 "Cannot find any RAM, start : %d, x = %d.\n",
270 (int)mstart, x);
271 return (ENXIO);
272 }
273 if (bootverbose)
274 device_printf(dev,
275 "RAM start at %d, size : %d.\n", (int)mstart, msize);
276
277 sc->mem_size = msize;
278 sc->mem_start = mstart;
279 sc->mem_end = msize + mstart;
280 sc->tx_page_start = mstart / ED_PAGE_SIZE;
281 return 0;
282}
283
284void
285ed_Novell_read_mac(struct ed_softc *sc)
286{
287 int n;
288 uint8_t romdata[16];
289
290 /*
291 * Pull the MAC address out of the roms that are on the isa
292 * version of these cards.
293 */
294 ed_pio_readmem(sc, 0, romdata, 16);
295 for (n = 0; n < ETHER_ADDR_LEN; n++)
296 sc->enaddr[n] = romdata[n * (sc->isa16bit + 1)];
297}