hme.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: hme.c,v 1.1.2.2 1999/07/01 23:32:27 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*-
4 1.1.2.2 thorpej * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1.2.2 thorpej * All rights reserved.
6 1.1.2.2 thorpej *
7 1.1.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 thorpej * by Paul Kranenburg.
9 1.1.2.2 thorpej *
10 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.1.2.2 thorpej * are met:
13 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 thorpej * must display the following acknowledgement:
20 1.1.2.2 thorpej * This product includes software developed by the NetBSD
21 1.1.2.2 thorpej * Foundation, Inc. and its contributors.
22 1.1.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 thorpej * contributors may be used to endorse or promote products derived
24 1.1.2.2 thorpej * from this software without specific prior written permission.
25 1.1.2.2 thorpej *
26 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 thorpej */
38 1.1.2.2 thorpej
39 1.1.2.2 thorpej /*
40 1.1.2.2 thorpej * HME Ethernet module driver.
41 1.1.2.2 thorpej */
42 1.1.2.2 thorpej
43 1.1.2.2 thorpej #define HMEDEBUG
44 1.1.2.2 thorpej
45 1.1.2.2 thorpej #include "opt_inet.h"
46 1.1.2.2 thorpej #include "opt_ccitt.h"
47 1.1.2.2 thorpej #include "opt_llc.h"
48 1.1.2.2 thorpej #include "opt_ns.h"
49 1.1.2.2 thorpej #include "bpfilter.h"
50 1.1.2.2 thorpej #include "rnd.h"
51 1.1.2.2 thorpej
52 1.1.2.2 thorpej #include <sys/param.h>
53 1.1.2.2 thorpej #include <sys/systm.h>
54 1.1.2.2 thorpej #include <sys/mbuf.h>
55 1.1.2.2 thorpej #include <sys/syslog.h>
56 1.1.2.2 thorpej #include <sys/socket.h>
57 1.1.2.2 thorpej #include <sys/device.h>
58 1.1.2.2 thorpej #include <sys/malloc.h>
59 1.1.2.2 thorpej #include <sys/ioctl.h>
60 1.1.2.2 thorpej #include <sys/errno.h>
61 1.1.2.2 thorpej #if NRND > 0
62 1.1.2.2 thorpej #include <sys/rnd.h>
63 1.1.2.2 thorpej #endif
64 1.1.2.2 thorpej
65 1.1.2.2 thorpej #include <net/if.h>
66 1.1.2.2 thorpej #include <net/if_dl.h>
67 1.1.2.2 thorpej #include <net/if_ether.h>
68 1.1.2.2 thorpej #include <net/if_media.h>
69 1.1.2.2 thorpej
70 1.1.2.2 thorpej #ifdef INET
71 1.1.2.2 thorpej #include <netinet/in.h>
72 1.1.2.2 thorpej #include <netinet/if_inarp.h>
73 1.1.2.2 thorpej #include <netinet/in_systm.h>
74 1.1.2.2 thorpej #include <netinet/in_var.h>
75 1.1.2.2 thorpej #include <netinet/ip.h>
76 1.1.2.2 thorpej #endif
77 1.1.2.2 thorpej
78 1.1.2.2 thorpej #ifdef NS
79 1.1.2.2 thorpej #include <netns/ns.h>
80 1.1.2.2 thorpej #include <netns/ns_if.h>
81 1.1.2.2 thorpej #endif
82 1.1.2.2 thorpej
83 1.1.2.2 thorpej #if NBPFILTER > 0
84 1.1.2.2 thorpej #include <net/bpf.h>
85 1.1.2.2 thorpej #include <net/bpfdesc.h>
86 1.1.2.2 thorpej #endif
87 1.1.2.2 thorpej
88 1.1.2.2 thorpej #include <dev/mii/mii.h>
89 1.1.2.2 thorpej #include <dev/mii/miivar.h>
90 1.1.2.2 thorpej
91 1.1.2.2 thorpej #include <machine/bus.h>
92 1.1.2.2 thorpej
93 1.1.2.2 thorpej #include <dev/ic/hmereg.h>
94 1.1.2.2 thorpej #include <dev/ic/hmevar.h>
95 1.1.2.2 thorpej
96 1.1.2.2 thorpej void hme_start __P((struct ifnet *));
97 1.1.2.2 thorpej void hme_stop __P((struct hme_softc *));
98 1.1.2.2 thorpej int hme_ioctl __P((struct ifnet *, u_long, caddr_t));
99 1.1.2.2 thorpej void hme_watchdog __P((struct ifnet *));
100 1.1.2.2 thorpej void hme_shutdown __P((void *));
101 1.1.2.2 thorpej void hme_init __P((struct hme_softc *));
102 1.1.2.2 thorpej void hme_meminit __P((struct hme_softc *));
103 1.1.2.2 thorpej void hme_reset __P((struct hme_softc *));
104 1.1.2.2 thorpej void hme_setladrf __P((struct hme_softc *));
105 1.1.2.2 thorpej
106 1.1.2.2 thorpej /* MII methods & callbacks */
107 1.1.2.2 thorpej static int hme_mii_readreg __P((struct device *, int, int));
108 1.1.2.2 thorpej static void hme_mii_writereg __P((struct device *, int, int, int));
109 1.1.2.2 thorpej static void hme_mii_statchg __P((struct device *));
110 1.1.2.2 thorpej
111 1.1.2.2 thorpej int hme_mediachange __P((struct ifnet *));
112 1.1.2.2 thorpej void hme_mediastatus __P((struct ifnet *, struct ifmediareq *));
113 1.1.2.2 thorpej
114 1.1.2.2 thorpej struct mbuf *hme_get __P((struct hme_softc *, int, int));
115 1.1.2.2 thorpej int hme_put __P((struct hme_softc *, int, struct mbuf *));
116 1.1.2.2 thorpej void hme_read __P((struct hme_softc *, int, int));
117 1.1.2.2 thorpej int hme_eint __P((struct hme_softc *, u_int));
118 1.1.2.2 thorpej int hme_rint __P((struct hme_softc *));
119 1.1.2.2 thorpej int hme_tint __P((struct hme_softc *));
120 1.1.2.2 thorpej
121 1.1.2.2 thorpej static int ether_cmp __P((u_char *, u_char *));
122 1.1.2.2 thorpej
123 1.1.2.2 thorpej /* Default buffer copy routines */
124 1.1.2.2 thorpej void hme_copytobuf_contig __P((struct hme_softc *, void *, int, int));
125 1.1.2.2 thorpej void hme_copyfrombuf_contig __P((struct hme_softc *, void *, int, int));
126 1.1.2.2 thorpej void hme_zerobuf_contig __P((struct hme_softc *, int, int));
127 1.1.2.2 thorpej
128 1.1.2.2 thorpej
129 1.1.2.2 thorpej void
130 1.1.2.2 thorpej hme_config(sc)
131 1.1.2.2 thorpej struct hme_softc *sc;
132 1.1.2.2 thorpej {
133 1.1.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
134 1.1.2.2 thorpej struct mii_data *mii = &sc->sc_mii;
135 1.1.2.2 thorpej bus_dma_segment_t seg;
136 1.1.2.2 thorpej bus_size_t size;
137 1.1.2.2 thorpej int rseg, error;
138 1.1.2.2 thorpej
139 1.1.2.2 thorpej /*
140 1.1.2.2 thorpej * HME common initialization.
141 1.1.2.2 thorpej *
142 1.1.2.2 thorpej * hme_softc fields that must be initialized by the front-end:
143 1.1.2.2 thorpej *
144 1.1.2.2 thorpej * the bus tag:
145 1.1.2.2 thorpej * sc_bustag
146 1.1.2.2 thorpej *
147 1.1.2.2 thorpej * the dma bus tag:
148 1.1.2.2 thorpej * sc_dmatag
149 1.1.2.2 thorpej *
150 1.1.2.2 thorpej * the bus handles:
151 1.1.2.2 thorpej * sc_seb (Shared Ethernet Block registers)
152 1.1.2.2 thorpej * sc_erx (Receiver Unit registers)
153 1.1.2.2 thorpej * sc_etx (Transmitter Unit registers)
154 1.1.2.2 thorpej * sc_mac (MAC registers)
155 1.1.2.2 thorpej * sc_mif (Managment Interface registers)
156 1.1.2.2 thorpej *
157 1.1.2.2 thorpej * the maximum bus burst size:
158 1.1.2.2 thorpej * sc_burst
159 1.1.2.2 thorpej *
160 1.1.2.2 thorpej * (notyet:DMA capable memory for the ring descriptors & packet buffers:
161 1.1.2.2 thorpej * rb_membase, rb_dmabase)
162 1.1.2.2 thorpej *
163 1.1.2.2 thorpej * the local Ethernet address:
164 1.1.2.2 thorpej * sc_enaddr
165 1.1.2.2 thorpej *
166 1.1.2.2 thorpej */
167 1.1.2.2 thorpej
168 1.1.2.2 thorpej /* Make sure the chip is stopped. */
169 1.1.2.2 thorpej hme_stop(sc);
170 1.1.2.2 thorpej
171 1.1.2.2 thorpej
172 1.1.2.2 thorpej /*
173 1.1.2.2 thorpej * Allocate descriptors and buffers
174 1.1.2.2 thorpej * XXX - do all this differently.. and more configurably,
175 1.1.2.2 thorpej * eg. use things as `dma_load_mbuf()' on transmit,
176 1.1.2.2 thorpej * and a pool of `EXTMEM' mbufs (with buffers DMA-mapped
177 1.1.2.2 thorpej * all the time) on the reveiver side.
178 1.1.2.2 thorpej */
179 1.1.2.2 thorpej #define _HME_NDESC 32
180 1.1.2.2 thorpej #define _HME_BUFSZ 32
181 1.1.2.2 thorpej
182 1.1.2.2 thorpej /* Note: the # of descriptors must be a multiple of 16 */
183 1.1.2.2 thorpej sc->sc_rb.rb_ntbuf = _HME_NDESC;
184 1.1.2.2 thorpej sc->sc_rb.rb_nrbuf = _HME_NDESC;
185 1.1.2.2 thorpej
186 1.1.2.2 thorpej /*
187 1.1.2.2 thorpej * Allocate DMA capable memory
188 1.1.2.2 thorpej * Buffer descriptors must be aligned on a 2048 byte boundary;
189 1.1.2.2 thorpej * take this into account when calculating the size. Note that
190 1.1.2.2 thorpej * the maximum number of descriptors (256) occupies 2048 bytes,
191 1.1.2.2 thorpej * so we allocate that much regardless of _HME_NDESC.
192 1.1.2.2 thorpej */
193 1.1.2.2 thorpej size = 2048 + /* TX descriptors */
194 1.1.2.2 thorpej 2048 + /* RX descriptors */
195 1.1.2.2 thorpej sc->sc_rb.rb_ntbuf * _HME_BUFSZ + /* TX buffers */
196 1.1.2.2 thorpej sc->sc_rb.rb_nrbuf * _HME_BUFSZ; /* TX buffers */
197 1.1.2.2 thorpej if ((error = bus_dmamem_alloc(sc->sc_dmatag, size,
198 1.1.2.2 thorpej 2048, 0,
199 1.1.2.2 thorpej &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
200 1.1.2.2 thorpej printf("%s: DMA buffer alloc error %d\n",
201 1.1.2.2 thorpej sc->sc_dev.dv_xname, error);
202 1.1.2.2 thorpej }
203 1.1.2.2 thorpej sc->sc_rb.rb_dmabase = seg.ds_addr;
204 1.1.2.2 thorpej
205 1.1.2.2 thorpej /* Map DMA memory in CPU adressable space */
206 1.1.2.2 thorpej if ((error = bus_dmamem_map(sc->sc_dmatag, &seg, rseg, size,
207 1.1.2.2 thorpej &sc->sc_rb.rb_membase,
208 1.1.2.2 thorpej BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
209 1.1.2.2 thorpej printf("%s: DMA buffer map error %d\n",
210 1.1.2.2 thorpej sc->sc_dev.dv_xname, error);
211 1.1.2.2 thorpej bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
212 1.1.2.2 thorpej return;
213 1.1.2.2 thorpej }
214 1.1.2.2 thorpej
215 1.1.2.2 thorpej #if 0
216 1.1.2.2 thorpej /*
217 1.1.2.2 thorpej * Install default copy routines if not supplied.
218 1.1.2.2 thorpej */
219 1.1.2.2 thorpej if (sc->sc_copytobuf == NULL)
220 1.1.2.2 thorpej sc->sc_copytobuf = hme_copytobuf_contig;
221 1.1.2.2 thorpej
222 1.1.2.2 thorpej if (sc->sc_copyfrombuf == NULL)
223 1.1.2.2 thorpej sc->sc_copyfrombuf = hme_copyfrombuf_contig;
224 1.1.2.2 thorpej #endif
225 1.1.2.2 thorpej
226 1.1.2.2 thorpej /* Initialize ifnet structure. */
227 1.1.2.2 thorpej bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
228 1.1.2.2 thorpej ifp->if_softc = sc;
229 1.1.2.2 thorpej ifp->if_start = hme_start;
230 1.1.2.2 thorpej ifp->if_ioctl = hme_ioctl;
231 1.1.2.2 thorpej ifp->if_watchdog = hme_watchdog;
232 1.1.2.2 thorpej ifp->if_flags =
233 1.1.2.2 thorpej IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
234 1.1.2.2 thorpej
235 1.1.2.2 thorpej /* Initialize ifmedia structures and MII info */
236 1.1.2.2 thorpej mii->mii_ifp = ifp;
237 1.1.2.2 thorpej mii->mii_readreg = hme_mii_readreg;
238 1.1.2.2 thorpej mii->mii_writereg = hme_mii_writereg;
239 1.1.2.2 thorpej mii->mii_statchg = hme_mii_statchg;
240 1.1.2.2 thorpej
241 1.1.2.2 thorpej ifmedia_init(&mii->mii_media, 0, hme_mediachange, hme_mediastatus);
242 1.1.2.2 thorpej
243 1.1.2.2 thorpej if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
244 1.1.2.2 thorpej /* No PHY attached */
245 1.1.2.2 thorpej ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
246 1.1.2.2 thorpej ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
247 1.1.2.2 thorpej } else {
248 1.1.2.2 thorpej /*
249 1.1.2.2 thorpej * XXX - we can really do the following ONLY if the
250 1.1.2.2 thorpej * phy indeed has the auto negotiation capability!!
251 1.1.2.2 thorpej */
252 1.1.2.2 thorpej ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_AUTO);
253 1.1.2.2 thorpej }
254 1.1.2.2 thorpej
255 1.1.2.2 thorpej /* Attach the interface. */
256 1.1.2.2 thorpej if_attach(ifp);
257 1.1.2.2 thorpej ether_ifattach(ifp, sc->sc_enaddr);
258 1.1.2.2 thorpej
259 1.1.2.2 thorpej #if NBPFILTER > 0
260 1.1.2.2 thorpej bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
261 1.1.2.2 thorpej #endif
262 1.1.2.2 thorpej
263 1.1.2.2 thorpej printf(": address %s\n", ether_sprintf(sc->sc_enaddr));
264 1.1.2.2 thorpej
265 1.1.2.2 thorpej sc->sc_sh = shutdownhook_establish(hme_shutdown, sc);
266 1.1.2.2 thorpej if (sc->sc_sh == NULL)
267 1.1.2.2 thorpej panic("hme_config: can't establish shutdownhook");
268 1.1.2.2 thorpej
269 1.1.2.2 thorpej #if 0
270 1.1.2.2 thorpej printf("%s: %d receive buffers, %d transmit buffers\n",
271 1.1.2.2 thorpej sc->sc_dev.dv_xname, sc->sc_nrbuf, sc->sc_ntbuf);
272 1.1.2.2 thorpej sc->sc_rbufaddr = malloc(sc->sc_nrbuf * sizeof(int), M_DEVBUF,
273 1.1.2.2 thorpej M_WAITOK);
274 1.1.2.2 thorpej sc->sc_tbufaddr = malloc(sc->sc_ntbuf * sizeof(int), M_DEVBUF,
275 1.1.2.2 thorpej M_WAITOK);
276 1.1.2.2 thorpej #endif
277 1.1.2.2 thorpej
278 1.1.2.2 thorpej #if NRND > 0
279 1.1.2.2 thorpej rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
280 1.1.2.2 thorpej RND_TYPE_NET, 0);
281 1.1.2.2 thorpej #endif
282 1.1.2.2 thorpej }
283 1.1.2.2 thorpej
284 1.1.2.2 thorpej void
285 1.1.2.2 thorpej hme_reset(sc)
286 1.1.2.2 thorpej struct hme_softc *sc;
287 1.1.2.2 thorpej {
288 1.1.2.2 thorpej int s;
289 1.1.2.2 thorpej
290 1.1.2.2 thorpej s = splnet();
291 1.1.2.2 thorpej hme_init(sc);
292 1.1.2.2 thorpej splx(s);
293 1.1.2.2 thorpej }
294 1.1.2.2 thorpej
295 1.1.2.2 thorpej void
296 1.1.2.2 thorpej hme_stop(sc)
297 1.1.2.2 thorpej struct hme_softc *sc;
298 1.1.2.2 thorpej {
299 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
300 1.1.2.2 thorpej bus_space_handle_t seb = sc->sc_seb;
301 1.1.2.2 thorpej int n;
302 1.1.2.2 thorpej
303 1.1.2.2 thorpej /* Reset transmitter and receiver */
304 1.1.2.2 thorpej bus_space_write_4(t, seb, HME_SEBI_RESET,
305 1.1.2.2 thorpej (HME_SEB_RESET_ETX | HME_SEB_RESET_ERX));
306 1.1.2.2 thorpej
307 1.1.2.2 thorpej for (n = 0; n < 20; n++) {
308 1.1.2.2 thorpej u_int32_t v = bus_space_read_4(t, seb, HME_SEBI_RESET);
309 1.1.2.2 thorpej if ((v & (HME_SEB_RESET_ETX | HME_SEB_RESET_ERX)) == 0)
310 1.1.2.2 thorpej return;
311 1.1.2.2 thorpej DELAY(20);
312 1.1.2.2 thorpej }
313 1.1.2.2 thorpej
314 1.1.2.2 thorpej printf("%s: hme_stop: reset failed\n", sc->sc_dev.dv_xname);
315 1.1.2.2 thorpej }
316 1.1.2.2 thorpej
317 1.1.2.2 thorpej void
318 1.1.2.2 thorpej hme_meminit(sc)
319 1.1.2.2 thorpej struct hme_softc *sc;
320 1.1.2.2 thorpej {
321 1.1.2.2 thorpej bus_addr_t txbufdma, rxbufdma;
322 1.1.2.2 thorpej bus_addr_t dma;
323 1.1.2.2 thorpej caddr_t p;
324 1.1.2.2 thorpej unsigned int ntbuf, nrbuf, i;
325 1.1.2.2 thorpej struct hme_ring *hr = &sc->sc_rb;
326 1.1.2.2 thorpej
327 1.1.2.2 thorpej p = hr->rb_membase;
328 1.1.2.2 thorpej dma = hr->rb_dmabase;
329 1.1.2.2 thorpej
330 1.1.2.2 thorpej ntbuf = hr->rb_ntbuf;
331 1.1.2.2 thorpej nrbuf = hr->rb_nrbuf;
332 1.1.2.2 thorpej
333 1.1.2.2 thorpej /*
334 1.1.2.2 thorpej * Allocate transmit descriptors
335 1.1.2.2 thorpej */
336 1.1.2.2 thorpej hr->rb_txd = p;
337 1.1.2.2 thorpej hr->rb_txddma = dma;
338 1.1.2.2 thorpej p += ntbuf * HME_XD_SIZE;
339 1.1.2.2 thorpej dma += ntbuf * HME_XD_SIZE;
340 1.1.2.2 thorpej
341 1.1.2.2 thorpej /*
342 1.1.2.2 thorpej * Allocate receive descriptors
343 1.1.2.2 thorpej * Buffer descriptors must be aligned on a 2048 byte boundary.
344 1.1.2.2 thorpej */
345 1.1.2.2 thorpej dma = (bus_addr_t)roundup((long)dma, 2048);
346 1.1.2.2 thorpej p = (caddr_t)roundup((long)p, 2048);
347 1.1.2.2 thorpej hr->rb_rxd = p;
348 1.1.2.2 thorpej hr->rb_rxddma = dma;
349 1.1.2.2 thorpej p += nrbuf * HME_XD_SIZE;
350 1.1.2.2 thorpej dma += nrbuf * HME_XD_SIZE;
351 1.1.2.2 thorpej
352 1.1.2.2 thorpej
353 1.1.2.2 thorpej /*
354 1.1.2.2 thorpej * Allocate transmit buffers
355 1.1.2.2 thorpej */
356 1.1.2.2 thorpej hr->rb_txbuf = p;
357 1.1.2.2 thorpej txbufdma = dma;
358 1.1.2.2 thorpej p += ntbuf * _HME_BUFSZ;
359 1.1.2.2 thorpej dma += ntbuf * _HME_BUFSZ;
360 1.1.2.2 thorpej
361 1.1.2.2 thorpej /*
362 1.1.2.2 thorpej * Allocate receive buffers
363 1.1.2.2 thorpej */
364 1.1.2.2 thorpej hr->rb_rxbuf = p;
365 1.1.2.2 thorpej rxbufdma = dma;
366 1.1.2.2 thorpej p += nrbuf * _HME_BUFSZ;
367 1.1.2.2 thorpej dma += nrbuf * _HME_BUFSZ;
368 1.1.2.2 thorpej
369 1.1.2.2 thorpej /*
370 1.1.2.2 thorpej * Initialize transmit buffer descriptors
371 1.1.2.2 thorpej */
372 1.1.2.2 thorpej for (i = 0; i < ntbuf; i++) {
373 1.1.2.2 thorpej HME_XD_SETADDR(hr->rb_txd, i, txbufdma + i * _HME_BUFSZ);
374 1.1.2.2 thorpej HME_XD_SETFLAGS(hr->rb_txd, i, 0);
375 1.1.2.2 thorpej }
376 1.1.2.2 thorpej
377 1.1.2.2 thorpej /*
378 1.1.2.2 thorpej * Initialize receive buffer descriptors
379 1.1.2.2 thorpej */
380 1.1.2.2 thorpej for (i = 0; i < nrbuf; i++) {
381 1.1.2.2 thorpej HME_XD_SETADDR(hr->rb_txd, i, rxbufdma + i * _HME_BUFSZ);
382 1.1.2.2 thorpej HME_XD_SETFLAGS(hr->rb_txd, i,
383 1.1.2.2 thorpej HME_XD_OWN | HME_XD_ENCODE_RSIZE(_HME_BUFSZ));
384 1.1.2.2 thorpej }
385 1.1.2.2 thorpej
386 1.1.2.2 thorpej hr->rb_tdhead = hr->rb_tdtail = 0;
387 1.1.2.2 thorpej hr->rb_td_nbusy = 0;
388 1.1.2.2 thorpej hr->rb_rdtail = 0;
389 1.1.2.2 thorpej }
390 1.1.2.2 thorpej
391 1.1.2.2 thorpej /*
392 1.1.2.2 thorpej * Initialization of interface; set up initialization block
393 1.1.2.2 thorpej * and transmit/receive descriptor rings.
394 1.1.2.2 thorpej */
395 1.1.2.2 thorpej void
396 1.1.2.2 thorpej hme_init(sc)
397 1.1.2.2 thorpej struct hme_softc *sc;
398 1.1.2.2 thorpej {
399 1.1.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
400 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
401 1.1.2.2 thorpej bus_space_handle_t seb = sc->sc_seb;
402 1.1.2.2 thorpej bus_space_handle_t etx = sc->sc_etx;
403 1.1.2.2 thorpej bus_space_handle_t erx = sc->sc_erx;
404 1.1.2.2 thorpej bus_space_handle_t mac = sc->sc_mac;
405 1.1.2.2 thorpej bus_space_handle_t mif = sc->sc_mif;
406 1.1.2.2 thorpej u_int8_t *ea;
407 1.1.2.2 thorpej u_int32_t v;
408 1.1.2.2 thorpej
409 1.1.2.2 thorpej /*
410 1.1.2.2 thorpej * Initialization sequence. The numbered steps below correspond
411 1.1.2.2 thorpej * to the sequence outlined in section 6.3.5.1 in the Ethernet
412 1.1.2.2 thorpej * Channel Engine manual (part of the PCIO manual).
413 1.1.2.2 thorpej * See also the STP2002-STQ document from Sun Microsystems.
414 1.1.2.2 thorpej */
415 1.1.2.2 thorpej
416 1.1.2.2 thorpej /* step 1 & 2. Reset the Ethernet Channel */
417 1.1.2.2 thorpej hme_stop(sc);
418 1.1.2.2 thorpej
419 1.1.2.2 thorpej /* Call MI reset function if any */
420 1.1.2.2 thorpej if (sc->sc_hwreset)
421 1.1.2.2 thorpej (*sc->sc_hwreset)(sc);
422 1.1.2.2 thorpej
423 1.1.2.2 thorpej #if 0
424 1.1.2.2 thorpej /* Mask all MIF interrupts, just in case */
425 1.1.2.2 thorpej bus_space_write_4(t, mif, HME_MIFI_IMASK, 0xffff);
426 1.1.2.2 thorpej #endif
427 1.1.2.2 thorpej
428 1.1.2.2 thorpej /* step 3. Setup data structures in host memory */
429 1.1.2.2 thorpej hme_meminit(sc);
430 1.1.2.2 thorpej
431 1.1.2.2 thorpej /* step 4. TX MAC registers & counters */
432 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_NCCNT, 0);
433 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_FCCNT, 0);
434 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_EXCNT, 0);
435 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_LTCNT, 0);
436 1.1.2.2 thorpej
437 1.1.2.2 thorpej /* Load station MAC address */
438 1.1.2.2 thorpej ea = sc->sc_enaddr;
439 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_MACADDR0, (ea[0] << 8) | ea[1]);
440 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_MACADDR1, (ea[2] << 8) | ea[3]);
441 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_MACADDR2, (ea[4] << 8) | ea[5]);
442 1.1.2.2 thorpej
443 1.1.2.2 thorpej /*
444 1.1.2.2 thorpej * Init seed for backoff
445 1.1.2.2 thorpej * (source suggested by manual: low 10 bits of MAC address)
446 1.1.2.2 thorpej */
447 1.1.2.2 thorpej v = ((ea[4] << 8) | ea[5]) & 0x3fff;
448 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_RANDSEED, v);
449 1.1.2.2 thorpej
450 1.1.2.2 thorpej
451 1.1.2.2 thorpej /* Note: Accepting power-on default for other MAC registers here.. */
452 1.1.2.2 thorpej
453 1.1.2.2 thorpej
454 1.1.2.2 thorpej /* step 5. RX MAC registers & counters */
455 1.1.2.2 thorpej hme_setladrf(sc);
456 1.1.2.2 thorpej
457 1.1.2.2 thorpej /* step 6 & 7. Program Descriptor Ring Base Addresses */
458 1.1.2.2 thorpej bus_space_write_4(t, etx, HME_ETXI_RING, sc->sc_rb.rb_txddma);
459 1.1.2.2 thorpej bus_space_write_4(t, etx, HME_ETXI_RSIZE, sc->sc_rb.rb_ntbuf);
460 1.1.2.2 thorpej
461 1.1.2.2 thorpej bus_space_write_4(t, erx, HME_ERXI_RING, sc->sc_rb.rb_rxddma);
462 1.1.2.2 thorpej
463 1.1.2.2 thorpej
464 1.1.2.2 thorpej /* step 8. Global Configuration & Interrupt Mask */
465 1.1.2.2 thorpej bus_space_write_4(t, seb, HME_SEBI_IMASK,
466 1.1.2.2 thorpej HME_SEB_STAT_SENTFRAME | HME_SEB_STAT_TXPERR |
467 1.1.2.2 thorpej HME_SEB_STAT_GOTFRAME | HME_SEB_STAT_RCNTEXP);
468 1.1.2.2 thorpej
469 1.1.2.2 thorpej switch (sc->sc_burst) {
470 1.1.2.2 thorpej default:
471 1.1.2.2 thorpej v = 0;
472 1.1.2.2 thorpej break;
473 1.1.2.2 thorpej case 16:
474 1.1.2.2 thorpej v = HME_SEB_CFG_BURST16;
475 1.1.2.2 thorpej break;
476 1.1.2.2 thorpej case 32:
477 1.1.2.2 thorpej v = HME_SEB_CFG_BURST32;
478 1.1.2.2 thorpej break;
479 1.1.2.2 thorpej case 64:
480 1.1.2.2 thorpej v = HME_SEB_CFG_BURST64;
481 1.1.2.2 thorpej break;
482 1.1.2.2 thorpej }
483 1.1.2.2 thorpej bus_space_write_4(t, seb, HME_SEBI_CFG, v);
484 1.1.2.2 thorpej
485 1.1.2.2 thorpej /* step 9. ETX Configuration: use mostly default values */
486 1.1.2.2 thorpej
487 1.1.2.2 thorpej /* Enable DMA */
488 1.1.2.2 thorpej v = bus_space_read_4(t, erx, HME_ETXI_CFG);
489 1.1.2.2 thorpej v |= HME_ETX_CFG_DMAENABLE;
490 1.1.2.2 thorpej bus_space_write_4(t, erx, HME_ETXI_CFG, v);
491 1.1.2.2 thorpej
492 1.1.2.2 thorpej /* Descriptor ring size: in increments of 16 */
493 1.1.2.2 thorpej bus_space_write_4(t, erx, HME_ETXI_RSIZE, _HME_NDESC / 16);
494 1.1.2.2 thorpej
495 1.1.2.2 thorpej
496 1.1.2.2 thorpej /* step 10. ERX Configuration: use default values; enable DMA */
497 1.1.2.2 thorpej v = bus_space_read_4(t, etx, HME_ERXI_CFG);
498 1.1.2.2 thorpej v |= HME_ERX_CFG_DMAENABLE;
499 1.1.2.2 thorpej bus_space_write_4(t, etx, HME_ERXI_CFG, v);
500 1.1.2.2 thorpej
501 1.1.2.2 thorpej /* step 11. XIF Configuration */
502 1.1.2.2 thorpej v = bus_space_read_4(t, mac, HME_MACI_XIF);
503 1.1.2.2 thorpej v |= HME_MAC_XIF_OE;
504 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_XIF, v);
505 1.1.2.2 thorpej
506 1.1.2.2 thorpej /* step 12. RX_MAC Configuration Register */
507 1.1.2.2 thorpej v = bus_space_read_4(t, mac, HME_MACI_RXCFG);
508 1.1.2.2 thorpej v |= HME_MAC_RXCFG_ENABLE;
509 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_RXCFG, v);
510 1.1.2.2 thorpej
511 1.1.2.2 thorpej /* step 13. TX_MAC Configuration Register */
512 1.1.2.2 thorpej v = bus_space_read_4(t, mac, HME_MACI_TXCFG);
513 1.1.2.2 thorpej v |= HME_MAC_TXCFG_ENABLE;
514 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_TXCFG, v);
515 1.1.2.2 thorpej
516 1.1.2.2 thorpej /* step 14. Issue Transmit Pending command */
517 1.1.2.2 thorpej
518 1.1.2.2 thorpej /*
519 1.1.2.2 thorpej * Put MIF in frame mode
520 1.1.2.2 thorpej * XXX - do bit-bang mode later
521 1.1.2.2 thorpej */
522 1.1.2.2 thorpej v = bus_space_read_4(t, mif, HME_MIFI_CFG);
523 1.1.2.2 thorpej v &= ~HME_MIF_CFG_BBMODE;
524 1.1.2.2 thorpej bus_space_write_4(t, mif, HME_MIFI_CFG, v);
525 1.1.2.2 thorpej
526 1.1.2.2 thorpej /* Call MI initialization function if any */
527 1.1.2.2 thorpej if (sc->sc_hwinit)
528 1.1.2.2 thorpej (*sc->sc_hwinit)(sc);
529 1.1.2.2 thorpej
530 1.1.2.2 thorpej ifp->if_flags |= IFF_RUNNING;
531 1.1.2.2 thorpej ifp->if_flags &= ~IFF_OACTIVE;
532 1.1.2.2 thorpej ifp->if_timer = 0;
533 1.1.2.2 thorpej hme_start(ifp);
534 1.1.2.2 thorpej }
535 1.1.2.2 thorpej
536 1.1.2.2 thorpej /*
537 1.1.2.2 thorpej * Compare two Ether/802 addresses for equality, inlined and unrolled for
538 1.1.2.2 thorpej * speed.
539 1.1.2.2 thorpej */
540 1.1.2.2 thorpej static __inline__ int
541 1.1.2.2 thorpej ether_cmp(a, b)
542 1.1.2.2 thorpej u_char *a, *b;
543 1.1.2.2 thorpej {
544 1.1.2.2 thorpej
545 1.1.2.2 thorpej if (a[5] != b[5] || a[4] != b[4] || a[3] != b[3] ||
546 1.1.2.2 thorpej a[2] != b[2] || a[1] != b[1] || a[0] != b[0])
547 1.1.2.2 thorpej return (0);
548 1.1.2.2 thorpej return (1);
549 1.1.2.2 thorpej }
550 1.1.2.2 thorpej
551 1.1.2.2 thorpej
552 1.1.2.2 thorpej /*
553 1.1.2.2 thorpej * Routine to copy from mbuf chain to transmit buffer in
554 1.1.2.2 thorpej * network buffer memory.
555 1.1.2.2 thorpej * Returns the amount of data copied.
556 1.1.2.2 thorpej */
557 1.1.2.2 thorpej int
558 1.1.2.2 thorpej hme_put(sc, ri, m)
559 1.1.2.2 thorpej struct hme_softc *sc;
560 1.1.2.2 thorpej int ri; /* Ring index */
561 1.1.2.2 thorpej struct mbuf *m;
562 1.1.2.2 thorpej {
563 1.1.2.2 thorpej struct mbuf *n;
564 1.1.2.2 thorpej int len, tlen = 0;
565 1.1.2.2 thorpej caddr_t bp;
566 1.1.2.2 thorpej
567 1.1.2.2 thorpej bp = sc->sc_rb.rb_txbuf + (ri % sc->sc_rb.rb_ntbuf) * _HME_BUFSZ;
568 1.1.2.2 thorpej for (; m; m = n) {
569 1.1.2.2 thorpej len = m->m_len;
570 1.1.2.2 thorpej if (len == 0) {
571 1.1.2.2 thorpej MFREE(m, n);
572 1.1.2.2 thorpej continue;
573 1.1.2.2 thorpej }
574 1.1.2.2 thorpej bcopy(mtod(m, caddr_t), bp, len);
575 1.1.2.2 thorpej bp += len;
576 1.1.2.2 thorpej tlen += len;
577 1.1.2.2 thorpej MFREE(m, n);
578 1.1.2.2 thorpej }
579 1.1.2.2 thorpej return (tlen);
580 1.1.2.2 thorpej }
581 1.1.2.2 thorpej
582 1.1.2.2 thorpej /*
583 1.1.2.2 thorpej * Pull data off an interface.
584 1.1.2.2 thorpej * Len is length of data, with local net header stripped.
585 1.1.2.2 thorpej * We copy the data into mbufs. When full cluster sized units are present
586 1.1.2.2 thorpej * we copy into clusters.
587 1.1.2.2 thorpej */
588 1.1.2.2 thorpej struct mbuf *
589 1.1.2.2 thorpej hme_get(sc, ri, totlen)
590 1.1.2.2 thorpej struct hme_softc *sc;
591 1.1.2.2 thorpej int ri, totlen;
592 1.1.2.2 thorpej {
593 1.1.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
594 1.1.2.2 thorpej struct mbuf *m, *m0, *newm;
595 1.1.2.2 thorpej caddr_t bp;
596 1.1.2.2 thorpej int len;
597 1.1.2.2 thorpej
598 1.1.2.2 thorpej MGETHDR(m0, M_DONTWAIT, MT_DATA);
599 1.1.2.2 thorpej if (m0 == 0)
600 1.1.2.2 thorpej return (0);
601 1.1.2.2 thorpej m0->m_pkthdr.rcvif = ifp;
602 1.1.2.2 thorpej m0->m_pkthdr.len = totlen;
603 1.1.2.2 thorpej len = MHLEN;
604 1.1.2.2 thorpej m = m0;
605 1.1.2.2 thorpej
606 1.1.2.2 thorpej bp = sc->sc_rb.rb_rxbuf + (ri % sc->sc_rb.rb_nrbuf) * _HME_BUFSZ;
607 1.1.2.2 thorpej
608 1.1.2.2 thorpej while (totlen > 0) {
609 1.1.2.2 thorpej if (totlen >= MINCLSIZE) {
610 1.1.2.2 thorpej MCLGET(m, M_DONTWAIT);
611 1.1.2.2 thorpej if ((m->m_flags & M_EXT) == 0)
612 1.1.2.2 thorpej goto bad;
613 1.1.2.2 thorpej len = MCLBYTES;
614 1.1.2.2 thorpej }
615 1.1.2.2 thorpej
616 1.1.2.2 thorpej if (m == m0) {
617 1.1.2.2 thorpej caddr_t newdata = (caddr_t)
618 1.1.2.2 thorpej ALIGN(m->m_data + sizeof(struct ether_header)) -
619 1.1.2.2 thorpej sizeof(struct ether_header);
620 1.1.2.2 thorpej len -= newdata - m->m_data;
621 1.1.2.2 thorpej m->m_data = newdata;
622 1.1.2.2 thorpej }
623 1.1.2.2 thorpej
624 1.1.2.2 thorpej m->m_len = len = min(totlen, len);
625 1.1.2.2 thorpej bcopy(bp, mtod(m, caddr_t), len);
626 1.1.2.2 thorpej bp += len;
627 1.1.2.2 thorpej
628 1.1.2.2 thorpej totlen -= len;
629 1.1.2.2 thorpej if (totlen > 0) {
630 1.1.2.2 thorpej MGET(newm, M_DONTWAIT, MT_DATA);
631 1.1.2.2 thorpej if (newm == 0)
632 1.1.2.2 thorpej goto bad;
633 1.1.2.2 thorpej len = MLEN;
634 1.1.2.2 thorpej m = m->m_next = newm;
635 1.1.2.2 thorpej }
636 1.1.2.2 thorpej }
637 1.1.2.2 thorpej
638 1.1.2.2 thorpej return (m0);
639 1.1.2.2 thorpej
640 1.1.2.2 thorpej bad:
641 1.1.2.2 thorpej m_freem(m0);
642 1.1.2.2 thorpej return (0);
643 1.1.2.2 thorpej }
644 1.1.2.2 thorpej
645 1.1.2.2 thorpej /*
646 1.1.2.2 thorpej * Pass a packet to the higher levels.
647 1.1.2.2 thorpej */
648 1.1.2.2 thorpej void
649 1.1.2.2 thorpej hme_read(sc, ix, len)
650 1.1.2.2 thorpej struct hme_softc *sc;
651 1.1.2.2 thorpej int ix, len;
652 1.1.2.2 thorpej {
653 1.1.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
654 1.1.2.2 thorpej struct mbuf *m;
655 1.1.2.2 thorpej struct ether_header *eh;
656 1.1.2.2 thorpej
657 1.1.2.2 thorpej if (len <= sizeof(struct ether_header) ||
658 1.1.2.2 thorpej len > ETHERMTU + sizeof(struct ether_header)) {
659 1.1.2.2 thorpej #ifdef HMEDEBUG
660 1.1.2.2 thorpej printf("%s: invalid packet size %d; dropping\n",
661 1.1.2.2 thorpej sc->sc_dev.dv_xname, len);
662 1.1.2.2 thorpej #endif
663 1.1.2.2 thorpej ifp->if_ierrors++;
664 1.1.2.2 thorpej return;
665 1.1.2.2 thorpej }
666 1.1.2.2 thorpej
667 1.1.2.2 thorpej /* Pull packet off interface. */
668 1.1.2.2 thorpej m = hme_get(sc, ix, len);
669 1.1.2.2 thorpej if (m == 0) {
670 1.1.2.2 thorpej ifp->if_ierrors++;
671 1.1.2.2 thorpej return;
672 1.1.2.2 thorpej }
673 1.1.2.2 thorpej
674 1.1.2.2 thorpej ifp->if_ipackets++;
675 1.1.2.2 thorpej
676 1.1.2.2 thorpej /* We assume that the header fit entirely in one mbuf. */
677 1.1.2.2 thorpej eh = mtod(m, struct ether_header *);
678 1.1.2.2 thorpej
679 1.1.2.2 thorpej #if NBPFILTER > 0
680 1.1.2.2 thorpej /*
681 1.1.2.2 thorpej * Check if there's a BPF listener on this interface.
682 1.1.2.2 thorpej * If so, hand off the raw packet to BPF.
683 1.1.2.2 thorpej */
684 1.1.2.2 thorpej if (ifp->if_bpf) {
685 1.1.2.2 thorpej bpf_mtap(ifp->if_bpf, m);
686 1.1.2.2 thorpej
687 1.1.2.2 thorpej /*
688 1.1.2.2 thorpej * Note that the interface cannot be in promiscuous mode if
689 1.1.2.2 thorpej * there are no BPF listeners. And if we are in promiscuous
690 1.1.2.2 thorpej * mode, we have to check if this packet is really ours.
691 1.1.2.2 thorpej */
692 1.1.2.2 thorpej if ((ifp->if_flags & IFF_PROMISC) != 0 &&
693 1.1.2.2 thorpej (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
694 1.1.2.2 thorpej ether_cmp(eh->ether_dhost, sc->sc_enaddr)) {
695 1.1.2.2 thorpej m_freem(m);
696 1.1.2.2 thorpej return;
697 1.1.2.2 thorpej }
698 1.1.2.2 thorpej }
699 1.1.2.2 thorpej #endif
700 1.1.2.2 thorpej
701 1.1.2.2 thorpej /* Pass the packet up. */
702 1.1.2.2 thorpej (*ifp->if_input)(ifp, m);
703 1.1.2.2 thorpej }
704 1.1.2.2 thorpej
705 1.1.2.2 thorpej void
706 1.1.2.2 thorpej hme_start(ifp)
707 1.1.2.2 thorpej struct ifnet *ifp;
708 1.1.2.2 thorpej {
709 1.1.2.2 thorpej struct hme_softc *sc = (struct hme_softc *)ifp->if_softc;
710 1.1.2.2 thorpej caddr_t txd = sc->sc_rb.rb_txd;
711 1.1.2.2 thorpej struct mbuf *m;
712 1.1.2.2 thorpej unsigned int ri, len;
713 1.1.2.2 thorpej unsigned int ntbuf = sc->sc_rb.rb_ntbuf;
714 1.1.2.2 thorpej
715 1.1.2.2 thorpej if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
716 1.1.2.2 thorpej return;
717 1.1.2.2 thorpej
718 1.1.2.2 thorpej ri = sc->sc_rb.rb_tdhead;
719 1.1.2.2 thorpej
720 1.1.2.2 thorpej for (;;) {
721 1.1.2.2 thorpej IF_DEQUEUE(&ifp->if_snd, m);
722 1.1.2.2 thorpej if (m == 0)
723 1.1.2.2 thorpej break;
724 1.1.2.2 thorpej
725 1.1.2.2 thorpej #if NBPFILTER > 0
726 1.1.2.2 thorpej /*
727 1.1.2.2 thorpej * If BPF is listening on this interface, let it see the
728 1.1.2.2 thorpej * packet before we commit it to the wire.
729 1.1.2.2 thorpej */
730 1.1.2.2 thorpej if (ifp->if_bpf)
731 1.1.2.2 thorpej bpf_mtap(ifp->if_bpf, m);
732 1.1.2.2 thorpej #endif
733 1.1.2.2 thorpej
734 1.1.2.2 thorpej /*
735 1.1.2.2 thorpej * Copy the mbuf chain into the transmit buffer.
736 1.1.2.2 thorpej */
737 1.1.2.2 thorpej len = hme_put(sc, ri, m);
738 1.1.2.2 thorpej
739 1.1.2.2 thorpej /*
740 1.1.2.2 thorpej * Initialize transmit registers and start transmission
741 1.1.2.2 thorpej */
742 1.1.2.2 thorpej HME_XD_SETFLAGS(txd, ri,
743 1.1.2.2 thorpej HME_XD_OWN | HME_XD_SOP | HME_XD_EOP |
744 1.1.2.2 thorpej HME_XD_ENCODE_TSIZE(len));
745 1.1.2.2 thorpej
746 1.1.2.2 thorpej bus_space_write_4(sc->sc_bustag, sc->sc_etx, HME_ETXI_PENDING,
747 1.1.2.2 thorpej HME_ETX_TP_DMAWAKEUP);
748 1.1.2.2 thorpej
749 1.1.2.2 thorpej if (++ri == ntbuf)
750 1.1.2.2 thorpej ri = 0;
751 1.1.2.2 thorpej
752 1.1.2.2 thorpej if (++sc->sc_rb.rb_td_nbusy == ntbuf) {
753 1.1.2.2 thorpej ifp->if_flags |= IFF_OACTIVE;
754 1.1.2.2 thorpej break;
755 1.1.2.2 thorpej }
756 1.1.2.2 thorpej }
757 1.1.2.2 thorpej
758 1.1.2.2 thorpej sc->sc_rb.rb_tdhead = ri;
759 1.1.2.2 thorpej }
760 1.1.2.2 thorpej
761 1.1.2.2 thorpej /*
762 1.1.2.2 thorpej * Transmit interrupt.
763 1.1.2.2 thorpej */
764 1.1.2.2 thorpej int
765 1.1.2.2 thorpej hme_tint(sc)
766 1.1.2.2 thorpej struct hme_softc *sc;
767 1.1.2.2 thorpej {
768 1.1.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
769 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
770 1.1.2.2 thorpej bus_space_handle_t mac = sc->sc_mac;
771 1.1.2.2 thorpej unsigned int ri, txflags;
772 1.1.2.2 thorpej
773 1.1.2.2 thorpej /*
774 1.1.2.2 thorpej * Unload collision counters
775 1.1.2.2 thorpej */
776 1.1.2.2 thorpej ifp->if_collisions +=
777 1.1.2.2 thorpej bus_space_read_4(t, mac, HME_MACI_NCCNT) +
778 1.1.2.2 thorpej bus_space_read_4(t, mac, HME_MACI_FCCNT) +
779 1.1.2.2 thorpej bus_space_read_4(t, mac, HME_MACI_EXCNT) +
780 1.1.2.2 thorpej bus_space_read_4(t, mac, HME_MACI_LTCNT);
781 1.1.2.2 thorpej
782 1.1.2.2 thorpej /*
783 1.1.2.2 thorpej * then clear the hardware counters.
784 1.1.2.2 thorpej */
785 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_NCCNT, 0);
786 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_FCCNT, 0);
787 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_EXCNT, 0);
788 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_LTCNT, 0);
789 1.1.2.2 thorpej
790 1.1.2.2 thorpej /* Fetch current position in the transmit ring */
791 1.1.2.2 thorpej ri = sc->sc_rb.rb_tdtail;
792 1.1.2.2 thorpej
793 1.1.2.2 thorpej for (;;) {
794 1.1.2.2 thorpej if (sc->sc_rb.rb_td_nbusy <= 0)
795 1.1.2.2 thorpej break;
796 1.1.2.2 thorpej
797 1.1.2.2 thorpej txflags = HME_XD_GETFLAGS(sc->sc_rb.rb_txd, ri);
798 1.1.2.2 thorpej
799 1.1.2.2 thorpej if (txflags & HME_XD_OWN)
800 1.1.2.2 thorpej break;
801 1.1.2.2 thorpej
802 1.1.2.2 thorpej ifp->if_flags &= ~IFF_OACTIVE;
803 1.1.2.2 thorpej ifp->if_opackets++;
804 1.1.2.2 thorpej
805 1.1.2.2 thorpej if (++ri == sc->sc_rb.rb_nrbuf)
806 1.1.2.2 thorpej ri = 0;
807 1.1.2.2 thorpej
808 1.1.2.2 thorpej --sc->sc_rb.rb_td_nbusy;
809 1.1.2.2 thorpej }
810 1.1.2.2 thorpej
811 1.1.2.2 thorpej sc->sc_rb.rb_tdtail = ri;
812 1.1.2.2 thorpej
813 1.1.2.2 thorpej hme_start(ifp);
814 1.1.2.2 thorpej
815 1.1.2.2 thorpej if (sc->sc_rb.rb_td_nbusy == 0)
816 1.1.2.2 thorpej ifp->if_timer = 0;
817 1.1.2.2 thorpej
818 1.1.2.2 thorpej return (1);
819 1.1.2.2 thorpej }
820 1.1.2.2 thorpej
821 1.1.2.2 thorpej /*
822 1.1.2.2 thorpej * Receive interrupt.
823 1.1.2.2 thorpej */
824 1.1.2.2 thorpej int
825 1.1.2.2 thorpej hme_rint(sc)
826 1.1.2.2 thorpej struct hme_softc *sc;
827 1.1.2.2 thorpej {
828 1.1.2.2 thorpej caddr_t xdr = sc->sc_rb.rb_rxd;
829 1.1.2.2 thorpej unsigned int nrbuf = sc->sc_rb.rb_nrbuf;
830 1.1.2.2 thorpej unsigned int ri, len;
831 1.1.2.2 thorpej u_int32_t flags;
832 1.1.2.2 thorpej
833 1.1.2.2 thorpej ri = sc->sc_rb.rb_rdtail;
834 1.1.2.2 thorpej
835 1.1.2.2 thorpej /*
836 1.1.2.2 thorpej * Process all buffers with valid data.
837 1.1.2.2 thorpej */
838 1.1.2.2 thorpej for (;;) {
839 1.1.2.2 thorpej flags = HME_XD_GETFLAGS(xdr, ri);
840 1.1.2.2 thorpej if (flags & HME_XD_OWN)
841 1.1.2.2 thorpej break;
842 1.1.2.2 thorpej
843 1.1.2.2 thorpej len = HME_XD_DECODE_RSIZE(flags);
844 1.1.2.2 thorpej hme_read(sc, ri, len);
845 1.1.2.2 thorpej
846 1.1.2.2 thorpej /* This buffer can be used by the hardware again */
847 1.1.2.2 thorpej HME_XD_SETFLAGS(xdr, ri,
848 1.1.2.2 thorpej HME_XD_OWN | HME_XD_ENCODE_RSIZE(_HME_BUFSZ));
849 1.1.2.2 thorpej
850 1.1.2.2 thorpej if (++ri == nrbuf)
851 1.1.2.2 thorpej ri = 0;
852 1.1.2.2 thorpej }
853 1.1.2.2 thorpej
854 1.1.2.2 thorpej sc->sc_rb.rb_rdtail = ri;
855 1.1.2.2 thorpej
856 1.1.2.2 thorpej return (1);
857 1.1.2.2 thorpej }
858 1.1.2.2 thorpej
859 1.1.2.2 thorpej int
860 1.1.2.2 thorpej hme_eint(sc, status)
861 1.1.2.2 thorpej struct hme_softc *sc;
862 1.1.2.2 thorpej u_int status;
863 1.1.2.2 thorpej {
864 1.1.2.2 thorpej char bits[128];
865 1.1.2.2 thorpej
866 1.1.2.2 thorpej if ((status & HME_SEB_STAT_MIFIRQ) != 0) {
867 1.1.2.2 thorpej printf("%s: XXXlink status changed\n", sc->sc_dev.dv_xname);
868 1.1.2.2 thorpej return (1);
869 1.1.2.2 thorpej }
870 1.1.2.2 thorpej
871 1.1.2.2 thorpej printf("%s: status=%s\n", sc->sc_dev.dv_xname,
872 1.1.2.2 thorpej bitmask_snprintf(status, HME_SEB_STAT_BITS, bits,sizeof(bits)));
873 1.1.2.2 thorpej return (1);
874 1.1.2.2 thorpej }
875 1.1.2.2 thorpej
876 1.1.2.2 thorpej int
877 1.1.2.2 thorpej hme_intr(v)
878 1.1.2.2 thorpej void *v;
879 1.1.2.2 thorpej {
880 1.1.2.2 thorpej struct hme_softc *sc = (struct hme_softc *)v;
881 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
882 1.1.2.2 thorpej bus_space_handle_t seb = sc->sc_seb;
883 1.1.2.2 thorpej u_int32_t status;
884 1.1.2.2 thorpej int r = 0;
885 1.1.2.2 thorpej
886 1.1.2.2 thorpej status = bus_space_read_4(t, seb, HME_SEBI_STAT);
887 1.1.2.2 thorpej
888 1.1.2.2 thorpej if ((status & HME_SEB_STAT_ALL_ERRORS) != 0)
889 1.1.2.2 thorpej r |= hme_eint(sc, status);
890 1.1.2.2 thorpej
891 1.1.2.2 thorpej if ((status & (HME_SEB_STAT_TXALL | HME_SEB_STAT_HOSTTOTX)) != 0)
892 1.1.2.2 thorpej r |= hme_tint(sc);
893 1.1.2.2 thorpej
894 1.1.2.2 thorpej if ((status & HME_SEB_STAT_RXTOHOST) != 0)
895 1.1.2.2 thorpej r |= hme_rint(sc);
896 1.1.2.2 thorpej
897 1.1.2.2 thorpej return (r);
898 1.1.2.2 thorpej }
899 1.1.2.2 thorpej
900 1.1.2.2 thorpej
901 1.1.2.2 thorpej void
902 1.1.2.2 thorpej hme_watchdog(ifp)
903 1.1.2.2 thorpej struct ifnet *ifp;
904 1.1.2.2 thorpej {
905 1.1.2.2 thorpej struct hme_softc *sc = ifp->if_softc;
906 1.1.2.2 thorpej
907 1.1.2.2 thorpej log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
908 1.1.2.2 thorpej ++ifp->if_oerrors;
909 1.1.2.2 thorpej
910 1.1.2.2 thorpej hme_reset(sc);
911 1.1.2.2 thorpej }
912 1.1.2.2 thorpej
913 1.1.2.2 thorpej /*
914 1.1.2.2 thorpej * MII interface
915 1.1.2.2 thorpej */
916 1.1.2.2 thorpej static int
917 1.1.2.2 thorpej hme_mii_readreg(self, phy, reg)
918 1.1.2.2 thorpej struct device *self;
919 1.1.2.2 thorpej int phy, reg;
920 1.1.2.2 thorpej {
921 1.1.2.2 thorpej struct hme_softc *sc = (void *)self;
922 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
923 1.1.2.2 thorpej bus_space_handle_t mif = sc->sc_mif;
924 1.1.2.2 thorpej int n;
925 1.1.2.2 thorpej u_int32_t v;
926 1.1.2.2 thorpej
927 1.1.2.2 thorpej /* Construct the frame command */
928 1.1.2.2 thorpej v = (MII_COMMAND_START << HME_MIF_FO_ST_SHIFT) |
929 1.1.2.2 thorpej HME_MIF_FO_TAMSB |
930 1.1.2.2 thorpej (MII_COMMAND_READ << HME_MIF_FO_OPC_SHIFT) |
931 1.1.2.2 thorpej (phy << HME_MIF_FO_PHYAD_SHIFT) |
932 1.1.2.2 thorpej (reg << HME_MIF_FO_REGAD_SHIFT);
933 1.1.2.2 thorpej
934 1.1.2.2 thorpej bus_space_write_4(t, mif, HME_MIFI_FO, v);
935 1.1.2.2 thorpej for (n = 0; n < 100; n++) {
936 1.1.2.2 thorpej v = bus_space_read_4(t, mif, HME_MIFI_FO);
937 1.1.2.2 thorpej if (v & HME_MIF_FO_TALSB)
938 1.1.2.2 thorpej return (v & HME_MIF_FO_DATA);
939 1.1.2.2 thorpej }
940 1.1.2.2 thorpej
941 1.1.2.2 thorpej printf("%s: mii_read timeout\n", sc->sc_dev.dv_xname);
942 1.1.2.2 thorpej return (0);
943 1.1.2.2 thorpej }
944 1.1.2.2 thorpej
945 1.1.2.2 thorpej static void
946 1.1.2.2 thorpej hme_mii_writereg(self, phy, reg, val)
947 1.1.2.2 thorpej struct device *self;
948 1.1.2.2 thorpej int phy, reg, val;
949 1.1.2.2 thorpej {
950 1.1.2.2 thorpej struct hme_softc *sc = (void *)self;
951 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
952 1.1.2.2 thorpej bus_space_handle_t mif = sc->sc_mif;
953 1.1.2.2 thorpej int n;
954 1.1.2.2 thorpej u_int32_t v;
955 1.1.2.2 thorpej
956 1.1.2.2 thorpej /* Construct the frame command */
957 1.1.2.2 thorpej v = (MII_COMMAND_START << HME_MIF_FO_ST_SHIFT) |
958 1.1.2.2 thorpej HME_MIF_FO_TAMSB |
959 1.1.2.2 thorpej (MII_COMMAND_WRITE << HME_MIF_FO_OPC_SHIFT) |
960 1.1.2.2 thorpej (phy << HME_MIF_FO_PHYAD_SHIFT) |
961 1.1.2.2 thorpej (reg << HME_MIF_FO_REGAD_SHIFT) |
962 1.1.2.2 thorpej (val & HME_MIF_FO_DATA);
963 1.1.2.2 thorpej
964 1.1.2.2 thorpej bus_space_write_4(t, mif, HME_MIFI_FO, v);
965 1.1.2.2 thorpej for (n = 0; n < 100; n++) {
966 1.1.2.2 thorpej v = bus_space_read_4(t, mif, HME_MIFI_FO);
967 1.1.2.2 thorpej if (v & HME_MIF_FO_TALSB)
968 1.1.2.2 thorpej return;
969 1.1.2.2 thorpej }
970 1.1.2.2 thorpej
971 1.1.2.2 thorpej printf("%s: mii_read timeout\n", sc->sc_dev.dv_xname);
972 1.1.2.2 thorpej }
973 1.1.2.2 thorpej
974 1.1.2.2 thorpej static void
975 1.1.2.2 thorpej hme_mii_statchg(dev)
976 1.1.2.2 thorpej struct device *dev;
977 1.1.2.2 thorpej {
978 1.1.2.2 thorpej }
979 1.1.2.2 thorpej
980 1.1.2.2 thorpej int
981 1.1.2.2 thorpej hme_mediachange(ifp)
982 1.1.2.2 thorpej struct ifnet *ifp;
983 1.1.2.2 thorpej {
984 1.1.2.2 thorpej struct hme_softc *sc = ifp->if_softc;
985 1.1.2.2 thorpej struct ifmedia *ifm = &sc->sc_media;
986 1.1.2.2 thorpej int newmedia = ifm->ifm_media;
987 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
988 1.1.2.2 thorpej bus_space_handle_t mac = sc->sc_mac;
989 1.1.2.2 thorpej u_int32_t v;
990 1.1.2.2 thorpej int error;
991 1.1.2.2 thorpej
992 1.1.2.2 thorpej if (IFM_TYPE(newmedia) != IFM_ETHER)
993 1.1.2.2 thorpej return (EINVAL);
994 1.1.2.2 thorpej
995 1.1.2.2 thorpej if ((ifp->if_flags & IFF_UP) == 0)
996 1.1.2.2 thorpej return (0);
997 1.1.2.2 thorpej
998 1.1.2.2 thorpej if ((error = mii_mediachg(&sc->sc_mii)) != 0)
999 1.1.2.2 thorpej return (error);
1000 1.1.2.2 thorpej
1001 1.1.2.2 thorpej v = bus_space_read_4(t, mac, HME_MACI_TXCFG);
1002 1.1.2.2 thorpej if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0)
1003 1.1.2.2 thorpej v |= HME_MAC_TXCFG_FULLDPLX;
1004 1.1.2.2 thorpej else
1005 1.1.2.2 thorpej v &= ~HME_MAC_TXCFG_FULLDPLX;
1006 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_TXCFG, v);
1007 1.1.2.2 thorpej
1008 1.1.2.2 thorpej return (0);
1009 1.1.2.2 thorpej }
1010 1.1.2.2 thorpej
1011 1.1.2.2 thorpej void
1012 1.1.2.2 thorpej hme_mediastatus(ifp, ifmr)
1013 1.1.2.2 thorpej struct ifnet *ifp;
1014 1.1.2.2 thorpej struct ifmediareq *ifmr;
1015 1.1.2.2 thorpej {
1016 1.1.2.2 thorpej struct hme_softc *sc = ifp->if_softc;
1017 1.1.2.2 thorpej
1018 1.1.2.2 thorpej if ((ifp->if_flags & IFF_UP) == 0)
1019 1.1.2.2 thorpej return;
1020 1.1.2.2 thorpej
1021 1.1.2.2 thorpej mii_pollstat(&sc->sc_mii);
1022 1.1.2.2 thorpej ifmr->ifm_active = sc->sc_mii.mii_media_active;
1023 1.1.2.2 thorpej ifmr->ifm_status = sc->sc_mii.mii_media_status;
1024 1.1.2.2 thorpej }
1025 1.1.2.2 thorpej
1026 1.1.2.2 thorpej /*
1027 1.1.2.2 thorpej * Process an ioctl request.
1028 1.1.2.2 thorpej */
1029 1.1.2.2 thorpej int
1030 1.1.2.2 thorpej hme_ioctl(ifp, cmd, data)
1031 1.1.2.2 thorpej struct ifnet *ifp;
1032 1.1.2.2 thorpej u_long cmd;
1033 1.1.2.2 thorpej caddr_t data;
1034 1.1.2.2 thorpej {
1035 1.1.2.2 thorpej struct hme_softc *sc = ifp->if_softc;
1036 1.1.2.2 thorpej struct ifaddr *ifa = (struct ifaddr *)data;
1037 1.1.2.2 thorpej struct ifreq *ifr = (struct ifreq *)data;
1038 1.1.2.2 thorpej int s, error = 0;
1039 1.1.2.2 thorpej
1040 1.1.2.2 thorpej s = splnet();
1041 1.1.2.2 thorpej
1042 1.1.2.2 thorpej switch (cmd) {
1043 1.1.2.2 thorpej
1044 1.1.2.2 thorpej case SIOCSIFADDR:
1045 1.1.2.2 thorpej ifp->if_flags |= IFF_UP;
1046 1.1.2.2 thorpej
1047 1.1.2.2 thorpej switch (ifa->ifa_addr->sa_family) {
1048 1.1.2.2 thorpej #ifdef INET
1049 1.1.2.2 thorpej case AF_INET:
1050 1.1.2.2 thorpej hme_init(sc);
1051 1.1.2.2 thorpej arp_ifinit(ifp, ifa);
1052 1.1.2.2 thorpej break;
1053 1.1.2.2 thorpej #endif
1054 1.1.2.2 thorpej #ifdef NS
1055 1.1.2.2 thorpej case AF_NS:
1056 1.1.2.2 thorpej {
1057 1.1.2.2 thorpej struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
1058 1.1.2.2 thorpej
1059 1.1.2.2 thorpej if (ns_nullhost(*ina))
1060 1.1.2.2 thorpej ina->x_host =
1061 1.1.2.2 thorpej *(union ns_host *)LLADDR(ifp->if_sadl);
1062 1.1.2.2 thorpej else {
1063 1.1.2.2 thorpej bcopy(ina->x_host.c_host,
1064 1.1.2.2 thorpej LLADDR(ifp->if_sadl),
1065 1.1.2.2 thorpej sizeof(sc->sc_enaddr));
1066 1.1.2.2 thorpej }
1067 1.1.2.2 thorpej /* Set new address. */
1068 1.1.2.2 thorpej hme_init(sc);
1069 1.1.2.2 thorpej break;
1070 1.1.2.2 thorpej }
1071 1.1.2.2 thorpej #endif
1072 1.1.2.2 thorpej default:
1073 1.1.2.2 thorpej hme_init(sc);
1074 1.1.2.2 thorpej break;
1075 1.1.2.2 thorpej }
1076 1.1.2.2 thorpej break;
1077 1.1.2.2 thorpej
1078 1.1.2.2 thorpej case SIOCSIFFLAGS:
1079 1.1.2.2 thorpej if ((ifp->if_flags & IFF_UP) == 0 &&
1080 1.1.2.2 thorpej (ifp->if_flags & IFF_RUNNING) != 0) {
1081 1.1.2.2 thorpej /*
1082 1.1.2.2 thorpej * If interface is marked down and it is running, then
1083 1.1.2.2 thorpej * stop it.
1084 1.1.2.2 thorpej */
1085 1.1.2.2 thorpej hme_stop(sc);
1086 1.1.2.2 thorpej ifp->if_flags &= ~IFF_RUNNING;
1087 1.1.2.2 thorpej } else if ((ifp->if_flags & IFF_UP) != 0 &&
1088 1.1.2.2 thorpej (ifp->if_flags & IFF_RUNNING) == 0) {
1089 1.1.2.2 thorpej /*
1090 1.1.2.2 thorpej * If interface is marked up and it is stopped, then
1091 1.1.2.2 thorpej * start it.
1092 1.1.2.2 thorpej */
1093 1.1.2.2 thorpej hme_init(sc);
1094 1.1.2.2 thorpej } else if ((ifp->if_flags & IFF_UP) != 0) {
1095 1.1.2.2 thorpej /*
1096 1.1.2.2 thorpej * Reset the interface to pick up changes in any other
1097 1.1.2.2 thorpej * flags that affect hardware registers.
1098 1.1.2.2 thorpej */
1099 1.1.2.2 thorpej /*hme_stop(sc);*/
1100 1.1.2.2 thorpej hme_init(sc);
1101 1.1.2.2 thorpej }
1102 1.1.2.2 thorpej #ifdef HMEDEBUG
1103 1.1.2.2 thorpej sc->sc_debug = (ifp->if_flags & IFF_DEBUG) != 0 ? 1 : 0;
1104 1.1.2.2 thorpej #endif
1105 1.1.2.2 thorpej break;
1106 1.1.2.2 thorpej
1107 1.1.2.2 thorpej case SIOCADDMULTI:
1108 1.1.2.2 thorpej case SIOCDELMULTI:
1109 1.1.2.2 thorpej error = (cmd == SIOCADDMULTI) ?
1110 1.1.2.2 thorpej ether_addmulti(ifr, &sc->sc_ethercom) :
1111 1.1.2.2 thorpej ether_delmulti(ifr, &sc->sc_ethercom);
1112 1.1.2.2 thorpej
1113 1.1.2.2 thorpej if (error == ENETRESET) {
1114 1.1.2.2 thorpej /*
1115 1.1.2.2 thorpej * Multicast list has changed; set the hardware filter
1116 1.1.2.2 thorpej * accordingly.
1117 1.1.2.2 thorpej */
1118 1.1.2.2 thorpej hme_setladrf(sc);
1119 1.1.2.2 thorpej error = 0;
1120 1.1.2.2 thorpej }
1121 1.1.2.2 thorpej break;
1122 1.1.2.2 thorpej
1123 1.1.2.2 thorpej case SIOCGIFMEDIA:
1124 1.1.2.2 thorpej case SIOCSIFMEDIA:
1125 1.1.2.2 thorpej error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
1126 1.1.2.2 thorpej break;
1127 1.1.2.2 thorpej
1128 1.1.2.2 thorpej default:
1129 1.1.2.2 thorpej error = EINVAL;
1130 1.1.2.2 thorpej break;
1131 1.1.2.2 thorpej }
1132 1.1.2.2 thorpej
1133 1.1.2.2 thorpej splx(s);
1134 1.1.2.2 thorpej return (error);
1135 1.1.2.2 thorpej }
1136 1.1.2.2 thorpej
1137 1.1.2.2 thorpej void
1138 1.1.2.2 thorpej hme_shutdown(arg)
1139 1.1.2.2 thorpej void *arg;
1140 1.1.2.2 thorpej {
1141 1.1.2.2 thorpej
1142 1.1.2.2 thorpej hme_stop((struct hme_softc *)arg);
1143 1.1.2.2 thorpej }
1144 1.1.2.2 thorpej
1145 1.1.2.2 thorpej /*
1146 1.1.2.2 thorpej * Set up the logical address filter.
1147 1.1.2.2 thorpej */
1148 1.1.2.2 thorpej void
1149 1.1.2.2 thorpej hme_setladrf(sc)
1150 1.1.2.2 thorpej struct hme_softc *sc;
1151 1.1.2.2 thorpej {
1152 1.1.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1153 1.1.2.2 thorpej struct ether_multi *enm;
1154 1.1.2.2 thorpej struct ether_multistep step;
1155 1.1.2.2 thorpej struct ethercom *ec = &sc->sc_ethercom;
1156 1.1.2.2 thorpej bus_space_tag_t t = sc->sc_bustag;
1157 1.1.2.2 thorpej bus_space_handle_t mac = sc->sc_mac;
1158 1.1.2.2 thorpej u_char *cp;
1159 1.1.2.2 thorpej u_int32_t crc;
1160 1.1.2.2 thorpej u_int32_t hash[4];
1161 1.1.2.2 thorpej int len;
1162 1.1.2.2 thorpej
1163 1.1.2.2 thorpej /*
1164 1.1.2.2 thorpej * Set up multicast address filter by passing all multicast addresses
1165 1.1.2.2 thorpej * through a crc generator, and then using the high order 6 bits as an
1166 1.1.2.2 thorpej * index into the 64 bit logical address filter. The high order bit
1167 1.1.2.2 thorpej * selects the word, while the rest of the bits select the bit within
1168 1.1.2.2 thorpej * the word.
1169 1.1.2.2 thorpej */
1170 1.1.2.2 thorpej
1171 1.1.2.2 thorpej if ((ifp->if_flags & IFF_PROMISC) != 0) {
1172 1.1.2.2 thorpej u_int32_t v = bus_space_read_4(t, mac, HME_MACI_RXCFG);
1173 1.1.2.2 thorpej v |= HME_MAC_RXCFG_PMISC;
1174 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_RXCFG, v);
1175 1.1.2.2 thorpej goto allmulti;
1176 1.1.2.2 thorpej }
1177 1.1.2.2 thorpej
1178 1.1.2.2 thorpej /* Clear hash table */
1179 1.1.2.2 thorpej hash[3] = hash[2] = hash[1] = hash[0] = 0;
1180 1.1.2.2 thorpej ETHER_FIRST_MULTI(step, ec, enm);
1181 1.1.2.2 thorpej while (enm != NULL) {
1182 1.1.2.2 thorpej if (ether_cmp(enm->enm_addrlo, enm->enm_addrhi)) {
1183 1.1.2.2 thorpej /*
1184 1.1.2.2 thorpej * We must listen to a range of multicast addresses.
1185 1.1.2.2 thorpej * For now, just accept all multicasts, rather than
1186 1.1.2.2 thorpej * trying to set only those filter bits needed to match
1187 1.1.2.2 thorpej * the range. (At this time, the only use of address
1188 1.1.2.2 thorpej * ranges is for IP multicast routing, for which the
1189 1.1.2.2 thorpej * range is big enough to require all bits set.)
1190 1.1.2.2 thorpej */
1191 1.1.2.2 thorpej goto allmulti;
1192 1.1.2.2 thorpej }
1193 1.1.2.2 thorpej
1194 1.1.2.2 thorpej cp = enm->enm_addrlo;
1195 1.1.2.2 thorpej crc = 0xffffffff;
1196 1.1.2.2 thorpej for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
1197 1.1.2.2 thorpej int octet = *cp++;
1198 1.1.2.2 thorpej int i;
1199 1.1.2.2 thorpej
1200 1.1.2.2 thorpej #define MC_POLY_LE 0xedb88320UL /* mcast crc, little endian */
1201 1.1.2.2 thorpej for (i = 0; i < 8; i++) {
1202 1.1.2.2 thorpej if ((crc & 1) ^ (octet & 1)) {
1203 1.1.2.2 thorpej crc >>= 1;
1204 1.1.2.2 thorpej crc ^= MC_POLY_LE;
1205 1.1.2.2 thorpej } else {
1206 1.1.2.2 thorpej crc >>= 1;
1207 1.1.2.2 thorpej }
1208 1.1.2.2 thorpej octet >>= 1;
1209 1.1.2.2 thorpej }
1210 1.1.2.2 thorpej }
1211 1.1.2.2 thorpej /* Just want the 6 most significant bits. */
1212 1.1.2.2 thorpej crc >>= 26;
1213 1.1.2.2 thorpej
1214 1.1.2.2 thorpej /* Set the corresponding bit in the filter. */
1215 1.1.2.2 thorpej hash[crc >> 4] |= 1 << (crc & 0xf);
1216 1.1.2.2 thorpej
1217 1.1.2.2 thorpej ETHER_NEXT_MULTI(step, enm);
1218 1.1.2.2 thorpej }
1219 1.1.2.2 thorpej
1220 1.1.2.2 thorpej /* Now load the hash table onto the chip */
1221 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB0, hash[0]);
1222 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB1, hash[1]);
1223 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB2, hash[2]);
1224 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB3, hash[3]);
1225 1.1.2.2 thorpej
1226 1.1.2.2 thorpej ifp->if_flags &= ~IFF_ALLMULTI;
1227 1.1.2.2 thorpej return;
1228 1.1.2.2 thorpej
1229 1.1.2.2 thorpej allmulti:
1230 1.1.2.2 thorpej ifp->if_flags |= IFF_ALLMULTI;
1231 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB0, 0xffff);
1232 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB1, 0xffff);
1233 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB2, 0xffff);
1234 1.1.2.2 thorpej bus_space_write_4(t, mac, HME_MACI_HASHTAB3, 0xffff);
1235 1.1.2.2 thorpej }
1236 1.1.2.2 thorpej
1237 1.1.2.2 thorpej /*
1238 1.1.2.2 thorpej * Routines for accessing the transmit and receive buffers.
1239 1.1.2.2 thorpej * The various CPU and adapter configurations supported by this
1240 1.1.2.2 thorpej * driver require three different access methods for buffers
1241 1.1.2.2 thorpej * and descriptors:
1242 1.1.2.2 thorpej * (1) contig (contiguous data; no padding),
1243 1.1.2.2 thorpej * (2) gap2 (two bytes of data followed by two bytes of padding),
1244 1.1.2.2 thorpej * (3) gap16 (16 bytes of data followed by 16 bytes of padding).
1245 1.1.2.2 thorpej */
1246 1.1.2.2 thorpej
1247 1.1.2.2 thorpej #if 0
1248 1.1.2.2 thorpej /*
1249 1.1.2.2 thorpej * contig: contiguous data with no padding.
1250 1.1.2.2 thorpej *
1251 1.1.2.2 thorpej * Buffers may have any alignment.
1252 1.1.2.2 thorpej */
1253 1.1.2.2 thorpej
1254 1.1.2.2 thorpej void
1255 1.1.2.2 thorpej hme_copytobuf_contig(sc, from, ri, len)
1256 1.1.2.2 thorpej struct hme_softc *sc;
1257 1.1.2.2 thorpej void *from;
1258 1.1.2.2 thorpej int ri, len;
1259 1.1.2.2 thorpej {
1260 1.1.2.2 thorpej volatile caddr_t buf = sc->sc_rb.rb_txbuf + (ri * _HME_BUFSZ);
1261 1.1.2.2 thorpej
1262 1.1.2.2 thorpej /*
1263 1.1.2.2 thorpej * Just call bcopy() to do the work.
1264 1.1.2.2 thorpej */
1265 1.1.2.2 thorpej bcopy(from, buf, len);
1266 1.1.2.2 thorpej }
1267 1.1.2.2 thorpej
1268 1.1.2.2 thorpej void
1269 1.1.2.2 thorpej hme_copyfrombuf_contig(sc, to, boff, len)
1270 1.1.2.2 thorpej struct hme_softc *sc;
1271 1.1.2.2 thorpej void *to;
1272 1.1.2.2 thorpej int boff, len;
1273 1.1.2.2 thorpej {
1274 1.1.2.2 thorpej volatile caddr_t buf = sc->sc_rb.rb_rxbuf + (ri * _HME_BUFSZ);
1275 1.1.2.2 thorpej
1276 1.1.2.2 thorpej /*
1277 1.1.2.2 thorpej * Just call bcopy() to do the work.
1278 1.1.2.2 thorpej */
1279 1.1.2.2 thorpej bcopy(buf, to, len);
1280 1.1.2.2 thorpej }
1281 1.1.2.2 thorpej #endif
1282