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