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