if_le_ibus.c revision 1.5 1 /* $NetBSD: if_le_ibus.c,v 1.5 2002/09/26 20:36:51 thorpej Exp $ */
2
3 /*
4 * Copyright 1996 The Board of Trustees of The Leland Stanford
5 * Junior University. All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and distribute this
8 * software and its documentation for any purpose and without
9 * fee is hereby granted, provided that the above copyright
10 * notice appear in all copies. Stanford University
11 * makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without
13 * express or implied warranty.
14 *
15 * This driver was contributed by Jonathan Stone.
16 */
17
18 /*
19 * LANCE on Decstation kn01/kn220(?) baseboard.
20 */
21 #include "opt_inet.h"
22
23 #include <sys/param.h>
24 #include <sys/socket.h>
25 #include <sys/systm.h>
26
27 #include <net/if.h>
28 #include <net/if_ether.h>
29 #include <net/if_media.h>
30
31 #ifdef INET
32 #include <netinet/in.h>
33 #include <netinet/if_inarp.h>
34 #endif
35
36 #include <dev/ic/lancevar.h>
37 #include <dev/ic/am7990var.h>
38
39 #include <dev/tc/if_levar.h>
40 #include <pmax/ibus/ibusvar.h>
41 #include <pmax/pmax/kn01.h>
42
43 static void le_dec_copyfrombuf_gap2(struct lance_softc *, void *, int, int);
44 static void le_dec_copytobuf_gap2(struct lance_softc *, void *, int, int);
45 static void le_dec_zerobuf_gap2(struct lance_softc *, int, int);
46
47
48 static int le_pmax_match(struct device *, struct cfdata *, void *);
49 static void le_pmax_attach(struct device *, struct device *, void *);
50
51 struct cfattach le_pmax_ca = {
52 sizeof(struct le_softc), le_pmax_match, le_pmax_attach
53 };
54
55 int
56 le_pmax_match(struct device *parent, struct cfdata *match, void *aux)
57 {
58 struct ibus_attach_args *d = aux;
59
60 if (strcmp("lance", d->ia_name) != 0)
61 return (0);
62 return (1);
63 }
64
65 void
66 le_pmax_attach(struct device *parent, struct device *self, void *aux)
67 {
68 struct le_softc *lesc = (void *)self;
69 struct lance_softc *sc = &lesc->sc_am7990.lsc;
70 u_char *cp;
71 struct ibus_attach_args *ia = aux;
72
73 /*
74 * It's on the baseboard, with a dedicated interrupt line.
75 */
76 lesc->sc_r1 = (struct lereg1 *)(ia->ia_addr);
77 sc->sc_mem = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_LANCE_B_START);
78 cp = (u_char *)(MIPS_PHYS_TO_KSEG1(KN01_SYS_CLOCK) + 1);
79
80 sc->sc_copytodesc = le_dec_copytobuf_gap2;
81 sc->sc_copyfromdesc = le_dec_copyfrombuf_gap2;
82 sc->sc_copytobuf = le_dec_copytobuf_gap2;
83 sc->sc_copyfrombuf = le_dec_copyfrombuf_gap2;
84 sc->sc_zerobuf = le_dec_zerobuf_gap2;
85
86 dec_le_common_attach(&lesc->sc_am7990, cp);
87
88 ibus_intr_establish(parent, (void*)ia->ia_cookie, IPL_NET,
89 am7990_intr, sc);
90 }
91
92 /*
93 * gap2: two bytes of data followed by two bytes of pad.
94 *
95 * Buffers must be 4-byte aligned. The code doesn't worry about
96 * doing an extra byte.
97 */
98
99 void
100 le_dec_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len)
101 {
102 volatile caddr_t buf = sc->sc_mem;
103 caddr_t from = fromv;
104 volatile u_int16_t *bptr;
105
106 if (boff & 0x1) {
107 /* handle unaligned first byte */
108 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
109 *bptr = (*from++ << 8) | (*bptr & 0xff);
110 bptr += 2;
111 len--;
112 } else
113 bptr = ((volatile u_int16_t *)buf) + boff;
114 while (len > 1) {
115 *bptr = (from[1] << 8) | (from[0] & 0xff);
116 bptr += 2;
117 from += 2;
118 len -= 2;
119 }
120 if (len == 1)
121 *bptr = (u_int16_t)*from;
122 }
123
124 void
125 le_dec_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len)
126 {
127 volatile caddr_t buf = sc->sc_mem;
128 caddr_t to = tov;
129 volatile u_int16_t *bptr;
130 u_int16_t tmp;
131
132 if (boff & 0x1) {
133 /* handle unaligned first byte */
134 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
135 *to++ = (*bptr >> 8) & 0xff;
136 bptr += 2;
137 len--;
138 } else
139 bptr = ((volatile u_int16_t *)buf) + boff;
140 while (len > 1) {
141 tmp = *bptr;
142 *to++ = tmp & 0xff;
143 *to++ = (tmp >> 8) & 0xff;
144 bptr += 2;
145 len -= 2;
146 }
147 if (len == 1)
148 *to = *bptr & 0xff;
149 }
150
151 static void
152 le_dec_zerobuf_gap2(struct lance_softc *sc, int boff, int len)
153 {
154 volatile caddr_t buf = sc->sc_mem;
155 volatile u_int16_t *bptr;
156
157 if ((unsigned)boff & 0x1) {
158 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
159 *bptr &= 0xff;
160 bptr += 2;
161 len--;
162 } else
163 bptr = ((volatile u_int16_t *)buf) + boff;
164 while (len > 0) {
165 *bptr = 0;
166 bptr += 2;
167 len -= 2;
168 }
169 }
170