#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ae.c,v 1.80 2010/01/19 22:06:20 pooka Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_media.h>
#include <net/if_ether.h>
#include <machine/bus.h>
#include <dev/ic/dp8390reg.h>
#include <dev/ic/dp8390var.h>
#include <mac68k/dev/if_aevar.h>
#define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
int
ae_size_card_memory(bus_space_tag_t bst, bus_space_handle_t bsh, int ofs)
{
int i1, i2, i3, i4, i8;
i1 = (8192 * 0);
i2 = (8192 * 1);
i3 = (8192 * 2);
i4 = (8192 * 3);
i8 = (8192 * 4);
bus_space_write_2(bst, bsh, ofs + i8, 0x8888);
bus_space_write_2(bst, bsh, ofs + i4, 0x4444);
bus_space_write_2(bst, bsh, ofs + i3, 0x3333);
bus_space_write_2(bst, bsh, ofs + i2, 0x2222);
bus_space_write_2(bst, bsh, ofs + i1, 0x1111);
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 &&
bus_space_read_2(bst, bsh, ofs + i8) == 0x8888)
return 8192 * 8;
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)
return 8192 * 4;
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))
return 8192 * 2;
if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 ||
bus_space_read_2(bst, bsh, ofs + i1) == 0x4444)
return 8192;
return 0;
}
int
ae_test_mem(struct dp8390_softc *sc)
{
bus_space_tag_t buft = sc->sc_buft;
bus_space_handle_t bufh = sc->sc_bufh;
int i;
bus_space_set_region_2(buft, bufh, sc->mem_start, 0,
sc->mem_size / 2);
for (i = 0; i < sc->mem_size; ++i) {
if (bus_space_read_1(sc->sc_buft, sc->sc_bufh, i)) {
printf(": failed to clear NIC buffer at offset %x - "
"check configuration\n", (sc->mem_start + i));
return 1;
}
}
return 0;
}
int
ae_write_mbuf(struct dp8390_softc *sc, struct mbuf *m, int buf)
{
u_char *data, savebyte[2];
int len, wantbyte;
u_short totlen = 0;
wantbyte = 0;
for (; m ; m = m->m_next) {
data = mtod(m, u_char *);
len = m->m_len;
totlen += len;
if (len > 0) {
if (wantbyte) {
savebyte[1] = *data;
bus_space_write_region_2(sc->sc_buft,
sc->sc_bufh, buf, (u_int16_t *)savebyte, 1);
buf += 2;
data++;
len--;
wantbyte = 0;
}
if (len > 1) {
bus_space_write_region_2(
sc->sc_buft, sc->sc_bufh,
buf, (u_int16_t *)data, len >> 1);
buf += len & ~1;
data += len & ~1;
len &= 1;
}
if (len == 1) {
savebyte[0] = *data;
wantbyte = 1;
}
}
}
len = ETHER_PAD_LEN - totlen;
if (wantbyte) {
savebyte[1] = 0;
bus_space_write_region_2(sc->sc_buft, sc->sc_bufh,
buf, (u_int16_t *)savebyte, 1);
buf += 2;
totlen++;
len--;
}
if (len > 0) {
bus_space_set_region_2(sc->sc_buft, sc->sc_bufh, buf, 0,
len >> 1);
totlen = ETHER_PAD_LEN;
}
return (totlen);
}