1997-08-12 02:53:26 +04:00
|
|
|
/* $NetBSD: if_ae.c,v 1.65 1997/08/11 22:53:32 scottr Exp $ */
|
1994-10-26 11:45:48 +03:00
|
|
|
|
1993-11-29 03:32:22 +03:00
|
|
|
/*
|
1995-04-12 19:01:14 +04:00
|
|
|
* Device driver for National Semiconductor DS8390/WD83C690 based ethernet
|
|
|
|
* adapters.
|
1993-11-29 03:32:22 +03:00
|
|
|
*
|
1995-04-12 19:01:14 +04:00
|
|
|
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
|
1993-11-29 03:32:22 +03:00
|
|
|
*
|
1995-04-12 19:01:14 +04:00
|
|
|
* Copyright (C) 1993, David Greenman. This software may be used, modified,
|
|
|
|
* copied, distributed, and sold, in both source and binary form provided that
|
|
|
|
* the above copyright and these terms are retained. Under no circumstances is
|
|
|
|
* the author responsible for the proper functioning of this software, nor does
|
|
|
|
* the author assume any responsibility for damages incurred with its use.
|
1993-11-29 03:32:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
1994-02-27 06:40:26 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1997-04-29 08:40:22 +04:00
|
|
|
#include <sys/device.h>
|
1994-02-27 06:40:26 +03:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
1993-11-29 03:32:22 +03:00
|
|
|
|
1994-01-30 04:14:49 +03:00
|
|
|
#include <net/if.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
1993-11-29 03:32:22 +03:00
|
|
|
|
1997-02-22 05:17:40 +03:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
1995-06-28 08:30:30 +04:00
|
|
|
#include <dev/ic/dp8390reg.h>
|
1997-04-29 08:40:22 +04:00
|
|
|
#include <dev/ic/dp8390var.h>
|
1997-08-12 02:53:26 +04:00
|
|
|
#include <mac68k/dev/if_aevar.h>
|
1994-02-26 06:01:22 +03:00
|
|
|
|
1997-02-24 09:03:55 +03:00
|
|
|
struct cfdriver ae_cd = {
|
|
|
|
NULL, "ae", DV_IFNET
|
|
|
|
};
|
1994-12-04 02:30:45 +03:00
|
|
|
|
1997-02-24 09:03:55 +03:00
|
|
|
int
|
|
|
|
ae_size_card_memory(bst, bsh, ofs)
|
|
|
|
bus_space_tag_t bst;
|
|
|
|
bus_space_handle_t bsh;
|
|
|
|
int ofs;
|
1994-12-04 02:30:45 +03:00
|
|
|
{
|
1997-02-24 09:03:55 +03:00
|
|
|
int i1, i2, i3, i4;
|
1994-12-04 02:30:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* banks; also assume it will generally mirror in upper banks
|
|
|
|
* if not installed.
|
|
|
|
*/
|
1997-03-04 18:12:04 +03:00
|
|
|
i1 = (8192 * 0);
|
|
|
|
i2 = (8192 * 1);
|
|
|
|
i3 = (8192 * 2);
|
|
|
|
i4 = (8192 * 3);
|
1995-04-12 19:01:14 +04:00
|
|
|
|
1997-02-24 09:03:55 +03:00
|
|
|
bus_space_write_2(bst, bsh, ofs + i1, 0x1111);
|
|
|
|
bus_space_write_2(bst, bsh, ofs + i2, 0x2222);
|
|
|
|
bus_space_write_2(bst, bsh, ofs + i3, 0x3333);
|
|
|
|
bus_space_write_2(bst, bsh, ofs + i4, 0x4444);
|
1995-04-12 19:01:14 +04:00
|
|
|
|
1997-02-24 09:03:55 +03:00
|
|
|
if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
|
|
|
|
bus_space_read_2(bst, bsh, ofs + i2) == 0x2222 &&
|
|
|
|
bus_space_read_2(bst, bsh, ofs + i3) == 0x3333 &&
|
|
|
|
bus_space_read_2(bst, bsh, ofs + i4) == 0x4444)
|
1995-04-21 06:47:35 +04:00
|
|
|
return 8192 * 4;
|
1995-04-12 19:01:14 +04:00
|
|
|
|
1997-02-24 09:03:55 +03:00
|
|
|
if ((bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
|
|
|
|
bus_space_read_2(bst, bsh, ofs + i2) == 0x2222) ||
|
|
|
|
(bus_space_read_2(bst, bsh, ofs + i1) == 0x3333 &&
|
|
|
|
bus_space_read_2(bst, bsh, ofs + i2) == 0x4444))
|
1995-04-21 06:47:35 +04:00
|
|
|
return 8192 * 2;
|
1994-12-04 02:30:45 +03:00
|
|
|
|
1997-02-24 09:03:55 +03:00
|
|
|
if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 ||
|
|
|
|
bus_space_read_2(bst, bsh, ofs + i1) == 0x4444)
|
1995-04-12 19:01:14 +04:00
|
|
|
return 8192;
|
1994-12-04 02:30:45 +03:00
|
|
|
|
1995-04-12 19:01:14 +04:00
|
|
|
return 0;
|
1994-02-26 06:01:22 +03:00
|
|
|
}
|
|
|
|
|
1997-02-25 09:36:04 +03:00
|
|
|
/*
|
1997-04-29 08:40:22 +04:00
|
|
|
* Zero memory and verify that it is clear. The only difference between
|
|
|
|
* this and the default test_mem function is that the DP8390-based NuBus
|
|
|
|
* cards * apparently require word-wide writes and byte-wide reads, an
|
|
|
|
* `interesting' combination.
|
1997-02-25 09:36:04 +03:00
|
|
|
*/
|
1997-02-28 11:56:05 +03:00
|
|
|
int
|
1997-04-29 08:40:22 +04:00
|
|
|
ae_test_mem(sc)
|
|
|
|
struct dp8390_softc *sc;
|
1997-02-25 09:36:04 +03:00
|
|
|
{
|
1997-04-29 08:40:22 +04:00
|
|
|
bus_space_tag_t buft = sc->sc_buft;
|
|
|
|
bus_space_handle_t bufh = sc->sc_bufh;
|
1997-02-25 09:36:04 +03:00
|
|
|
int i;
|
|
|
|
|
1997-04-29 08:40:22 +04:00
|
|
|
bus_space_set_region_2(buft, bufh, sc->mem_start, 0,
|
|
|
|
sc->mem_size / 2);
|
1997-02-25 09:36:04 +03:00
|
|
|
|
1997-02-28 11:56:05 +03:00
|
|
|
for (i = 0; i < sc->mem_size; ++i) {
|
|
|
|
if (bus_space_read_1(sc->sc_buft, sc->sc_bufh, i)) {
|
1997-04-29 08:40:22 +04:00
|
|
|
printf(": failed to clear NIC buffer at offset %x - "
|
|
|
|
"check configuration\n", (sc->mem_start + i));
|
1997-02-28 11:56:05 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
1997-02-25 09:36:04 +03:00
|
|
|
|
1997-02-28 11:56:05 +03:00
|
|
|
return 0;
|
1997-02-25 09:36:04 +03:00
|
|
|
}
|
|
|
|
|
1993-11-29 03:32:22 +03:00
|
|
|
/*
|
1997-04-29 08:40:22 +04:00
|
|
|
* Copy packet from mbuf to the board memory Currently uses an extra
|
|
|
|
* buffer/extra memory copy, unless the whole packet fits in one mbuf.
|
1995-04-12 19:01:14 +04:00
|
|
|
*
|
1997-04-29 08:40:22 +04:00
|
|
|
* As in the test_mem function, we use word-wide writes.
|
1995-04-12 19:01:14 +04:00
|
|
|
*/
|
1997-02-24 09:03:55 +03:00
|
|
|
int
|
1997-04-29 08:40:22 +04:00
|
|
|
ae_write_mbuf(sc, m, buf)
|
|
|
|
struct dp8390_softc *sc;
|
1995-04-12 19:01:14 +04:00
|
|
|
struct mbuf *m;
|
1997-02-24 09:03:55 +03:00
|
|
|
int buf;
|
1995-04-12 19:01:14 +04:00
|
|
|
{
|
|
|
|
u_char *data, savebyte[2];
|
1997-02-24 09:03:55 +03:00
|
|
|
int len, wantbyte;
|
1995-04-21 06:47:35 +04:00
|
|
|
u_short totlen = 0;
|
1995-04-12 19:01:14 +04:00
|
|
|
|
|
|
|
wantbyte = 0;
|
|
|
|
|
1995-07-31 01:39:17 +04:00
|
|
|
for (; m ; m = m->m_next) {
|
1995-04-12 19:01:14 +04:00
|
|
|
data = mtod(m, u_char *);
|
|
|
|
len = m->m_len;
|
|
|
|
totlen += len;
|
|
|
|
if (len > 0) {
|
|
|
|
/* Finish the last word. */
|
|
|
|
if (wantbyte) {
|
|
|
|
savebyte[1] = *data;
|
1997-02-28 10:52:44 +03:00
|
|
|
bus_space_write_region_2(sc->sc_buft,
|
|
|
|
sc->sc_bufh, buf, savebyte, 1);
|
1995-04-12 19:01:14 +04:00
|
|
|
buf += 2;
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
wantbyte = 0;
|
|
|
|
}
|
|
|
|
/* Output contiguous words. */
|
|
|
|
if (len > 1) {
|
1997-02-28 10:52:44 +03:00
|
|
|
bus_space_write_region_2(sc->sc_buft,
|
|
|
|
sc->sc_bufh, buf, data, len >> 1);
|
1995-04-12 19:01:14 +04:00
|
|
|
buf += len & ~1;
|
|
|
|
data += len & ~1;
|
|
|
|
len &= 1;
|
|
|
|
}
|
|
|
|
/* Save last byte, if necessary. */
|
|
|
|
if (len == 1) {
|
|
|
|
savebyte[0] = *data;
|
|
|
|
wantbyte = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wantbyte) {
|
|
|
|
savebyte[1] = 0;
|
1997-02-28 10:52:44 +03:00
|
|
|
bus_space_write_region_2(sc->sc_buft, sc->sc_bufh,
|
1997-02-24 09:03:55 +03:00
|
|
|
buf, savebyte, 1);
|
1995-04-12 19:01:14 +04:00
|
|
|
}
|
|
|
|
return (totlen);
|
|
|
|
}
|