xref: /netbsd-src/sys/arch/mac68k/dev/if_ae.c (revision 10fe49d72c585c6bba03f275c71b179a5d67a209)
1*10fe49d7Spooka /*	$NetBSD: if_ae.c,v 1.80 2010/01/19 22:06:20 pooka Exp $	*/
24fdae7a0Scgd 
3e99f003aSbriggs /*
42bc91b9cSbriggs  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
52bc91b9cSbriggs  * adapters.
6e99f003aSbriggs  *
72bc91b9cSbriggs  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
8e99f003aSbriggs  *
9e99f003aSbriggs  * Copyright (C) 1993, David Greenman.  This software may be used, modified,
102bc91b9cSbriggs  * copied, distributed, and sold, in both source and binary form provided that
112bc91b9cSbriggs  * the above copyright and these terms are retained.  Under no circumstances is
122bc91b9cSbriggs  * the author responsible for the proper functioning of this software, nor does
132bc91b9cSbriggs  * the author assume any responsibility for damages incurred with its use.
14d703fa05Sbriggs  */
15d703fa05Sbriggs 
164b2744bfSlukem #include <sys/cdefs.h>
17*10fe49d7Spooka __KERNEL_RCSID(0, "$NetBSD: if_ae.c,v 1.80 2010/01/19 22:06:20 pooka Exp $");
184b2744bfSlukem 
19e99f003aSbriggs 
2082a0604cSbriggs #include <sys/param.h>
2182a0604cSbriggs #include <sys/systm.h>
2263ac9ee6Sscottr #include <sys/device.h>
2382a0604cSbriggs #include <sys/mbuf.h>
2482a0604cSbriggs #include <sys/socket.h>
25e99f003aSbriggs 
26c86a4eb2Sbriggs #include <net/if.h>
277438e6c8Sthorpej #include <net/if_media.h>
2807b064e0Sis #include <net/if_ether.h>
29e99f003aSbriggs 
30db2ab09cSscottr #include <machine/bus.h>
31db2ab09cSscottr 
322b71eae2Scgd #include <dev/ic/dp8390reg.h>
3363ac9ee6Sscottr #include <dev/ic/dp8390var.h>
34c988c6f8Sscottr #include <mac68k/dev/if_aevar.h>
35e99f003aSbriggs 
3621d899a8Stsutsui #define ETHER_PAD_LEN	(ETHER_MIN_LEN - ETHER_CRC_LEN)
3721d899a8Stsutsui 
386b0774a8Sscottr int
ae_size_card_memory(bus_space_tag_t bst,bus_space_handle_t bsh,int ofs)397acd68b1Schs ae_size_card_memory(bus_space_tag_t bst, bus_space_handle_t bsh, int ofs)
40cd701f50Slkestel {
41e00ba8eeSjklos 	int i1, i2, i3, i4, i8;
42d703fa05Sbriggs 
43d703fa05Sbriggs 	/*
44d703fa05Sbriggs 	 * banks; also assume it will generally mirror in upper banks
45d703fa05Sbriggs 	 * if not installed.
46d703fa05Sbriggs 	 */
47fd81cf2bSscottr 	i1 = (8192 * 0);
48fd81cf2bSscottr 	i2 = (8192 * 1);
49fd81cf2bSscottr 	i3 = (8192 * 2);
50fd81cf2bSscottr 	i4 = (8192 * 3);
51d703fa05Sbriggs 
52e00ba8eeSjklos 	i8 = (8192 * 4);
53e00ba8eeSjklos 
54e00ba8eeSjklos 	bus_space_write_2(bst, bsh, ofs + i8, 0x8888);
556b0774a8Sscottr 	bus_space_write_2(bst, bsh, ofs + i4, 0x4444);
56e00ba8eeSjklos 	bus_space_write_2(bst, bsh, ofs + i3, 0x3333);
57e00ba8eeSjklos 	bus_space_write_2(bst, bsh, ofs + i2, 0x2222);
58e00ba8eeSjklos 	bus_space_write_2(bst, bsh, ofs + i1, 0x1111);
59e00ba8eeSjklos 
60e00ba8eeSjklos 	/*
61e00ba8eeSjklos 	* 1) If the memory range is decoded completely, it does not
62e00ba8eeSjklos 	*    matter what we write first: High tags written into
63e00ba8eeSjklos 	*    the void are lost.
64e00ba8eeSjklos 	* 2) If the memory range is not decoded completely (banks are
65e00ba8eeSjklos 	*    mirrored), high tags are overwritten by lower ones.
66e00ba8eeSjklos 	* 3) Lazy implementation of pathological cases - none found yet.
67e00ba8eeSjklos 	*/
68e00ba8eeSjklos 
69e00ba8eeSjklos 	if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
70e00ba8eeSjklos 	    bus_space_read_2(bst, bsh, ofs + i2) == 0x2222 &&
71e00ba8eeSjklos 	    bus_space_read_2(bst, bsh, ofs + i3) == 0x3333 &&
72e00ba8eeSjklos 	    bus_space_read_2(bst, bsh, ofs + i4) == 0x4444 &&
73e00ba8eeSjklos 	    bus_space_read_2(bst, bsh, ofs + i8) == 0x8888)
74e00ba8eeSjklos 		return 8192 * 8;
75d703fa05Sbriggs 
766b0774a8Sscottr 	if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
776b0774a8Sscottr 	    bus_space_read_2(bst, bsh, ofs + i2) == 0x2222 &&
786b0774a8Sscottr 	    bus_space_read_2(bst, bsh, ofs + i3) == 0x3333 &&
796b0774a8Sscottr 	    bus_space_read_2(bst, bsh, ofs + i4) == 0x4444)
802bc91b9cSbriggs 		return 8192 * 4;
812bc91b9cSbriggs 
826b0774a8Sscottr 	if ((bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
836b0774a8Sscottr 	    bus_space_read_2(bst, bsh, ofs + i2) == 0x2222) ||
846b0774a8Sscottr 	    (bus_space_read_2(bst, bsh, ofs + i1) == 0x3333 &&
856b0774a8Sscottr 	    bus_space_read_2(bst, bsh, ofs + i2) == 0x4444))
862bc91b9cSbriggs 		return 8192 * 2;
872bc91b9cSbriggs 
886b0774a8Sscottr 	if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 ||
896b0774a8Sscottr 	    bus_space_read_2(bst, bsh, ofs + i1) == 0x4444)
902bc91b9cSbriggs 		return 8192;
91d703fa05Sbriggs 
92d703fa05Sbriggs 	return 0;
933a18d3b2Sbriggs }
943a18d3b2Sbriggs 
95e99f003aSbriggs /*
9663ac9ee6Sscottr  * Zero memory and verify that it is clear.  The only difference between
9763ac9ee6Sscottr  * this and the default test_mem function is that the DP8390-based NuBus
9863ac9ee6Sscottr  * cards * apparently require word-wide writes and byte-wide reads, an
9963ac9ee6Sscottr  * `interesting' combination.
100a2a40938Sscottr  */
101705c6378Sscottr int
ae_test_mem(struct dp8390_softc * sc)1027acd68b1Schs ae_test_mem(struct dp8390_softc *sc)
103a2a40938Sscottr {
10463ac9ee6Sscottr 	bus_space_tag_t buft = sc->sc_buft;
10563ac9ee6Sscottr 	bus_space_handle_t bufh = sc->sc_bufh;
106a2a40938Sscottr 	int i;
107a2a40938Sscottr 
10863ac9ee6Sscottr 	bus_space_set_region_2(buft, bufh, sc->mem_start, 0,
10963ac9ee6Sscottr 	    sc->mem_size / 2);
110a2a40938Sscottr 
111705c6378Sscottr 	for (i = 0; i < sc->mem_size; ++i) {
112705c6378Sscottr 		if (bus_space_read_1(sc->sc_buft, sc->sc_bufh, i)) {
11363ac9ee6Sscottr 			printf(": failed to clear NIC buffer at offset %x - "
11463ac9ee6Sscottr 			    "check configuration\n", (sc->mem_start + i));
115705c6378Sscottr 			return 1;
116705c6378Sscottr 		}
117705c6378Sscottr 	}
118a2a40938Sscottr 
119705c6378Sscottr 	return 0;
120a2a40938Sscottr }
121a2a40938Sscottr 
122a2a40938Sscottr /*
12363ac9ee6Sscottr  * Copy packet from mbuf to the board memory Currently uses an extra
12463ac9ee6Sscottr  * buffer/extra memory copy, unless the whole packet fits in one mbuf.
125e99f003aSbriggs  *
12663ac9ee6Sscottr  * As in the test_mem function, we use word-wide writes.
127e99f003aSbriggs  */
128e99f003aSbriggs int
ae_write_mbuf(struct dp8390_softc * sc,struct mbuf * m,int buf)1297acd68b1Schs ae_write_mbuf(struct dp8390_softc *sc, struct mbuf *m, int buf)
1302bc91b9cSbriggs {
1312bc91b9cSbriggs 	u_char *data, savebyte[2];
1322bc91b9cSbriggs 	int len, wantbyte;
1332b1a13abSbriggs 	u_short totlen = 0;
1342bc91b9cSbriggs 
1352bc91b9cSbriggs 	wantbyte = 0;
1362bc91b9cSbriggs 
137fc873909Sbriggs 	for (; m ; m = m->m_next) {
1382bc91b9cSbriggs 		data = mtod(m, u_char *);
1392bc91b9cSbriggs 		len = m->m_len;
1402bc91b9cSbriggs 		totlen += len;
1412bc91b9cSbriggs 		if (len > 0) {
1422bc91b9cSbriggs 			/* Finish the last word. */
1432bc91b9cSbriggs 			if (wantbyte) {
1442bc91b9cSbriggs 				savebyte[1] = *data;
14517fdd597Sscottr 				bus_space_write_region_2(sc->sc_buft,
146ff213034Sscottr 				    sc->sc_bufh, buf, (u_int16_t *)savebyte, 1);
1472bc91b9cSbriggs 				buf += 2;
1482bc91b9cSbriggs 				data++;
1492bc91b9cSbriggs 				len--;
1502bc91b9cSbriggs 				wantbyte = 0;
1512bc91b9cSbriggs 			}
1522bc91b9cSbriggs 			/* Output contiguous words. */
1532bc91b9cSbriggs 			if (len > 1) {
154ff213034Sscottr 				bus_space_write_region_2(
155ff213034Sscottr 				    sc->sc_buft, sc->sc_bufh,
156ff213034Sscottr 				    buf, (u_int16_t *)data, len >> 1);
1572bc91b9cSbriggs 				buf += len & ~1;
1582bc91b9cSbriggs 				data += len & ~1;
1592bc91b9cSbriggs 				len &= 1;
1602bc91b9cSbriggs 			}
1612bc91b9cSbriggs 			/* Save last byte, if necessary. */
1622bc91b9cSbriggs 			if (len == 1) {
1632bc91b9cSbriggs 				savebyte[0] = *data;
1642bc91b9cSbriggs 				wantbyte = 1;
1652bc91b9cSbriggs 			}
1662bc91b9cSbriggs 		}
1672bc91b9cSbriggs 	}
1682bc91b9cSbriggs 
16921d899a8Stsutsui 	len = ETHER_PAD_LEN - totlen;
1702bc91b9cSbriggs 	if (wantbyte) {
1712bc91b9cSbriggs 		savebyte[1] = 0;
17217fdd597Sscottr 		bus_space_write_region_2(sc->sc_buft, sc->sc_bufh,
173ff213034Sscottr 		    buf, (u_int16_t *)savebyte, 1);
174bcae6871Sbouyer 		buf += 2;
17521d899a8Stsutsui 		totlen++;
17621d899a8Stsutsui 		len--;
177bcae6871Sbouyer 	}
17821d899a8Stsutsui 	/* if sent data is shorter than EHTER_PAD_LEN, put 0 to padding */
17921d899a8Stsutsui 	if (len > 0) {
1801c91f1dcSbouyer 		bus_space_set_region_2(sc->sc_buft, sc->sc_bufh, buf, 0,
18121d899a8Stsutsui 		    len >> 1);
18221d899a8Stsutsui 		totlen = ETHER_PAD_LEN;
1832bc91b9cSbriggs 	}
1842bc91b9cSbriggs 	return (totlen);
1852bc91b9cSbriggs }
186