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