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