if_ti.c revision 1.8 1 1.8 augustss /* $NetBSD: if_ti.c,v 1.8 2000/03/30 12:45:35 augustss Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1997, 1998, 1999
5 1.1 drochner * Bill Paul <wpaul (at) ctr.columbia.edu>. All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Redistribution and use in source and binary forms, with or without
8 1.1 drochner * modification, are permitted provided that the following conditions
9 1.1 drochner * are met:
10 1.1 drochner * 1. Redistributions of source code must retain the above copyright
11 1.1 drochner * notice, this list of conditions and the following disclaimer.
12 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 drochner * notice, this list of conditions and the following disclaimer in the
14 1.1 drochner * documentation and/or other materials provided with the distribution.
15 1.1 drochner * 3. All advertising materials mentioning features or use of this software
16 1.1 drochner * must display the following acknowledgement:
17 1.1 drochner * This product includes software developed by Bill Paul.
18 1.1 drochner * 4. Neither the name of the author nor the names of any co-contributors
19 1.1 drochner * may be used to endorse or promote products derived from this software
20 1.1 drochner * without specific prior written permission.
21 1.1 drochner *
22 1.1 drochner * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 1.1 drochner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 drochner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 drochner * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 1.1 drochner * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 drochner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 drochner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 drochner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 drochner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 drochner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 1.1 drochner * THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 drochner *
34 1.1 drochner * FreeBSD Id: if_ti.c,v 1.15 1999/08/14 15:45:03 wpaul Exp
35 1.1 drochner */
36 1.1 drochner
37 1.1 drochner /*
38 1.1 drochner * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD.
39 1.1 drochner * Manuals, sample driver and firmware source kits are available
40 1.1 drochner * from http://www.alteon.com/support/openkits.
41 1.1 drochner *
42 1.1 drochner * Written by Bill Paul <wpaul (at) ctr.columbia.edu>
43 1.1 drochner * Electrical Engineering Department
44 1.1 drochner * Columbia University, New York City
45 1.1 drochner */
46 1.1 drochner
47 1.1 drochner /*
48 1.1 drochner * The Alteon Networks Tigon chip contains an embedded R4000 CPU,
49 1.1 drochner * gigabit MAC, dual DMA channels and a PCI interface unit. NICs
50 1.1 drochner * using the Tigon may have anywhere from 512K to 2MB of SRAM. The
51 1.1 drochner * Tigon supports hardware IP, TCP and UCP checksumming, multicast
52 1.1 drochner * filtering and jumbo (9014 byte) frames. The hardware is largely
53 1.1 drochner * controlled by firmware, which must be loaded into the NIC during
54 1.1 drochner * initialization.
55 1.1 drochner *
56 1.1 drochner * The Tigon 2 contains 2 R4000 CPUs and requires a newer firmware
57 1.1 drochner * revision, which supports new features such as extended commands,
58 1.1 drochner * extended jumbo receive ring desciptors and a mini receive ring.
59 1.1 drochner *
60 1.1 drochner * Alteon Networks is to be commended for releasing such a vast amount
61 1.1 drochner * of development material for the Tigon NIC without requiring an NDA
62 1.1 drochner * (although they really should have done it a long time ago). With
63 1.1 drochner * any luck, the other vendors will finally wise up and follow Alteon's
64 1.1 drochner * stellar example.
65 1.1 drochner *
66 1.1 drochner * The firmware for the Tigon 1 and 2 NICs is compiled directly into
67 1.1 drochner * this driver by #including it as a C header file. This bloats the
68 1.1 drochner * driver somewhat, but it's the easiest method considering that the
69 1.1 drochner * driver code and firmware code need to be kept in sync. The source
70 1.1 drochner * for the firmware is not provided with the FreeBSD distribution since
71 1.1 drochner * compiling it requires a GNU toolchain targeted for mips-sgi-irix5.3.
72 1.1 drochner *
73 1.1 drochner * The following people deserve special thanks:
74 1.1 drochner * - Terry Murphy of 3Com, for providing a 3c985 Tigon 1 board
75 1.1 drochner * for testing
76 1.1 drochner * - Raymond Lee of Netgear, for providing a pair of Netgear
77 1.1 drochner * GA620 Tigon 2 boards for testing
78 1.3 thorpej * - Ulf Zimmermann, for bringing the GA620 to my attention and
79 1.1 drochner * convincing me to write this driver.
80 1.1 drochner * - Andrew Gallatin for providing FreeBSD/Alpha support.
81 1.1 drochner */
82 1.1 drochner
83 1.1 drochner #include "bpfilter.h"
84 1.1 drochner #include "opt_inet.h"
85 1.1 drochner #include "opt_ns.h"
86 1.1 drochner
87 1.1 drochner #include <sys/param.h>
88 1.1 drochner #include <sys/systm.h>
89 1.1 drochner #include <sys/sockio.h>
90 1.1 drochner #include <sys/mbuf.h>
91 1.1 drochner #include <sys/malloc.h>
92 1.1 drochner #include <sys/kernel.h>
93 1.1 drochner #include <sys/socket.h>
94 1.1 drochner #include <sys/queue.h>
95 1.1 drochner #include <sys/device.h>
96 1.1 drochner
97 1.1 drochner #include <net/if.h>
98 1.1 drochner #include <net/if_arp.h>
99 1.1 drochner #include <net/if_ether.h>
100 1.1 drochner #include <net/if_dl.h>
101 1.1 drochner #include <net/if_media.h>
102 1.1 drochner
103 1.1 drochner #if NBPFILTER > 0
104 1.1 drochner #include <net/bpf.h>
105 1.1 drochner #endif
106 1.1 drochner
107 1.1 drochner #ifdef INET
108 1.1 drochner #include <netinet/in.h>
109 1.1 drochner #include <netinet/if_inarp.h>
110 1.1 drochner #endif
111 1.1 drochner
112 1.2 drochner #ifdef NS
113 1.2 drochner #include <netns/ns.h>
114 1.2 drochner #include <netns/ns_if.h>
115 1.2 drochner #endif
116 1.2 drochner
117 1.1 drochner #include <machine/bus.h>
118 1.1 drochner
119 1.1 drochner #include <dev/pci/pcireg.h>
120 1.1 drochner #include <dev/pci/pcivar.h>
121 1.1 drochner #include <dev/pci/pcidevs.h>
122 1.1 drochner
123 1.1 drochner #include <dev/pci/if_tireg.h>
124 1.1 drochner #include <dev/pci/ti_fw.h>
125 1.1 drochner #include <dev/pci/ti_fw2.h>
126 1.1 drochner
127 1.1 drochner #ifdef M_HWCKSUM
128 1.1 drochner /*#define TI_CSUM_OFFLOAD*/
129 1.1 drochner #endif
130 1.1 drochner
131 1.1 drochner #define bootverbose 1
132 1.1 drochner
133 1.1 drochner /*
134 1.1 drochner * Various supported device vendors/types and their names.
135 1.1 drochner */
136 1.1 drochner
137 1.1 drochner static struct ti_type ti_devs[] = {
138 1.1 drochner { PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENIC,
139 1.1 drochner "Alteon AceNIC Gigabit Ethernet" },
140 1.1 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C985,
141 1.1 drochner "3Com 3c985-SX Gigabit Ethernet" },
142 1.1 drochner { PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620,
143 1.1 drochner "Netgear GA620 Gigabit Ethernet" },
144 1.1 drochner { PCI_VENDOR_SGI, PCI_PRODUCT_SGI_TIGON,
145 1.1 drochner "Silicon Graphics Gigabit Ethernet" },
146 1.1 drochner { 0, 0, NULL }
147 1.1 drochner };
148 1.1 drochner
149 1.6 bouyer static struct ti_type *ti_type_match __P((struct pci_attach_args *));
150 1.1 drochner static int ti_probe __P((struct device *, struct cfdata *, void *));
151 1.1 drochner static void ti_attach __P((struct device *, struct device *, void *));
152 1.6 bouyer static void ti_shutdown __P((void *));
153 1.1 drochner static void ti_txeof __P((struct ti_softc *));
154 1.1 drochner static void ti_rxeof __P((struct ti_softc *));
155 1.1 drochner
156 1.1 drochner static void ti_stats_update __P((struct ti_softc *));
157 1.1 drochner static int ti_encap __P((struct ti_softc *, struct mbuf *,
158 1.1 drochner u_int32_t *));
159 1.1 drochner
160 1.1 drochner static int ti_intr __P((void *));
161 1.1 drochner static void ti_start __P((struct ifnet *));
162 1.1 drochner static int ti_ioctl __P((struct ifnet *, u_long, caddr_t));
163 1.1 drochner static void ti_init __P((void *));
164 1.1 drochner static void ti_init2 __P((struct ti_softc *));
165 1.1 drochner static void ti_stop __P((struct ti_softc *));
166 1.1 drochner static void ti_watchdog __P((struct ifnet *));
167 1.1 drochner static int ti_ifmedia_upd __P((struct ifnet *));
168 1.1 drochner static void ti_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
169 1.1 drochner
170 1.1 drochner static u_int32_t ti_eeprom_putbyte __P((struct ti_softc *, int));
171 1.1 drochner static u_int8_t ti_eeprom_getbyte __P((struct ti_softc *,
172 1.1 drochner int, u_int8_t *));
173 1.1 drochner static int ti_read_eeprom __P((struct ti_softc *, caddr_t, int, int));
174 1.1 drochner
175 1.1 drochner static void ti_add_mcast __P((struct ti_softc *, struct ether_addr *));
176 1.1 drochner static void ti_del_mcast __P((struct ti_softc *, struct ether_addr *));
177 1.1 drochner static void ti_setmulti __P((struct ti_softc *));
178 1.1 drochner
179 1.1 drochner static void ti_mem __P((struct ti_softc *, u_int32_t,
180 1.1 drochner u_int32_t, caddr_t));
181 1.1 drochner static void ti_loadfw __P((struct ti_softc *));
182 1.1 drochner static void ti_cmd __P((struct ti_softc *, struct ti_cmd_desc *));
183 1.1 drochner static void ti_cmd_ext __P((struct ti_softc *, struct ti_cmd_desc *,
184 1.1 drochner caddr_t, int));
185 1.1 drochner static void ti_handle_events __P((struct ti_softc *));
186 1.1 drochner static int ti_alloc_jumbo_mem __P((struct ti_softc *));
187 1.1 drochner static void *ti_jalloc __P((struct ti_softc *));
188 1.1 drochner static void ti_jfree __P((caddr_t, u_int, void *));
189 1.1 drochner static int ti_newbuf_std __P((struct ti_softc *, int, struct mbuf *, bus_dmamap_t));
190 1.1 drochner static int ti_newbuf_mini __P((struct ti_softc *, int, struct mbuf *, bus_dmamap_t));
191 1.1 drochner static int ti_newbuf_jumbo __P((struct ti_softc *, int, struct mbuf *));
192 1.1 drochner static int ti_init_rx_ring_std __P((struct ti_softc *));
193 1.1 drochner static void ti_free_rx_ring_std __P((struct ti_softc *));
194 1.1 drochner static int ti_init_rx_ring_jumbo __P((struct ti_softc *));
195 1.1 drochner static void ti_free_rx_ring_jumbo __P((struct ti_softc *));
196 1.1 drochner static int ti_init_rx_ring_mini __P((struct ti_softc *));
197 1.1 drochner static void ti_free_rx_ring_mini __P((struct ti_softc *));
198 1.1 drochner static void ti_free_tx_ring __P((struct ti_softc *));
199 1.1 drochner static int ti_init_tx_ring __P((struct ti_softc *));
200 1.1 drochner
201 1.1 drochner static int ti_64bitslot_war __P((struct ti_softc *));
202 1.1 drochner static int ti_chipinit __P((struct ti_softc *));
203 1.1 drochner static int ti_gibinit __P((struct ti_softc *));
204 1.1 drochner
205 1.1 drochner static int ti_ether_ioctl __P((struct ifnet *, u_long, caddr_t));
206 1.1 drochner
207 1.1 drochner struct cfattach ti_ca = {
208 1.1 drochner sizeof(struct ti_softc), ti_probe, ti_attach
209 1.1 drochner };
210 1.1 drochner
211 1.1 drochner /*
212 1.1 drochner * Send an instruction or address to the EEPROM, check for ACK.
213 1.1 drochner */
214 1.1 drochner static u_int32_t ti_eeprom_putbyte(sc, byte)
215 1.1 drochner struct ti_softc *sc;
216 1.1 drochner int byte;
217 1.1 drochner {
218 1.8 augustss int i, ack = 0;
219 1.1 drochner
220 1.1 drochner /*
221 1.1 drochner * Make sure we're in TX mode.
222 1.1 drochner */
223 1.1 drochner TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
224 1.1 drochner
225 1.1 drochner /*
226 1.1 drochner * Feed in each bit and stobe the clock.
227 1.1 drochner */
228 1.1 drochner for (i = 0x80; i; i >>= 1) {
229 1.1 drochner if (byte & i) {
230 1.1 drochner TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT);
231 1.1 drochner } else {
232 1.1 drochner TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT);
233 1.1 drochner }
234 1.1 drochner DELAY(1);
235 1.1 drochner TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
236 1.1 drochner DELAY(1);
237 1.1 drochner TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
238 1.1 drochner }
239 1.1 drochner
240 1.1 drochner /*
241 1.1 drochner * Turn off TX mode.
242 1.1 drochner */
243 1.1 drochner TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
244 1.1 drochner
245 1.1 drochner /*
246 1.1 drochner * Check for ack.
247 1.1 drochner */
248 1.1 drochner TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
249 1.1 drochner ack = CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN;
250 1.1 drochner TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
251 1.1 drochner
252 1.1 drochner return(ack);
253 1.1 drochner }
254 1.1 drochner
255 1.1 drochner /*
256 1.1 drochner * Read a byte of data stored in the EEPROM at address 'addr.'
257 1.1 drochner * We have to send two address bytes since the EEPROM can hold
258 1.1 drochner * more than 256 bytes of data.
259 1.1 drochner */
260 1.1 drochner static u_int8_t ti_eeprom_getbyte(sc, addr, dest)
261 1.1 drochner struct ti_softc *sc;
262 1.1 drochner int addr;
263 1.1 drochner u_int8_t *dest;
264 1.1 drochner {
265 1.8 augustss int i;
266 1.1 drochner u_int8_t byte = 0;
267 1.1 drochner
268 1.1 drochner EEPROM_START;
269 1.1 drochner
270 1.1 drochner /*
271 1.1 drochner * Send write control code to EEPROM.
272 1.1 drochner */
273 1.1 drochner if (ti_eeprom_putbyte(sc, EEPROM_CTL_WRITE)) {
274 1.1 drochner printf("%s: failed to send write command, status: %x\n",
275 1.1 drochner sc->sc_dev.dv_xname, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
276 1.1 drochner return(1);
277 1.1 drochner }
278 1.1 drochner
279 1.1 drochner /*
280 1.1 drochner * Send first byte of address of byte we want to read.
281 1.1 drochner */
282 1.1 drochner if (ti_eeprom_putbyte(sc, (addr >> 8) & 0xFF)) {
283 1.1 drochner printf("%s: failed to send address, status: %x\n",
284 1.1 drochner sc->sc_dev.dv_xname, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
285 1.1 drochner return(1);
286 1.1 drochner }
287 1.1 drochner /*
288 1.1 drochner * Send second byte address of byte we want to read.
289 1.1 drochner */
290 1.1 drochner if (ti_eeprom_putbyte(sc, addr & 0xFF)) {
291 1.1 drochner printf("%s: failed to send address, status: %x\n",
292 1.1 drochner sc->sc_dev.dv_xname, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
293 1.1 drochner return(1);
294 1.1 drochner }
295 1.1 drochner
296 1.1 drochner EEPROM_STOP;
297 1.1 drochner EEPROM_START;
298 1.1 drochner /*
299 1.1 drochner * Send read control code to EEPROM.
300 1.1 drochner */
301 1.1 drochner if (ti_eeprom_putbyte(sc, EEPROM_CTL_READ)) {
302 1.1 drochner printf("%s: failed to send read command, status: %x\n",
303 1.1 drochner sc->sc_dev.dv_xname, CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
304 1.1 drochner return(1);
305 1.1 drochner }
306 1.1 drochner
307 1.1 drochner /*
308 1.1 drochner * Start reading bits from EEPROM.
309 1.1 drochner */
310 1.1 drochner TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
311 1.1 drochner for (i = 0x80; i; i >>= 1) {
312 1.1 drochner TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
313 1.1 drochner DELAY(1);
314 1.1 drochner if (CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN)
315 1.1 drochner byte |= i;
316 1.1 drochner TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
317 1.1 drochner DELAY(1);
318 1.1 drochner }
319 1.1 drochner
320 1.1 drochner EEPROM_STOP;
321 1.1 drochner
322 1.1 drochner /*
323 1.1 drochner * No ACK generated for read, so just return byte.
324 1.1 drochner */
325 1.1 drochner
326 1.1 drochner *dest = byte;
327 1.1 drochner
328 1.1 drochner return(0);
329 1.1 drochner }
330 1.1 drochner
331 1.1 drochner /*
332 1.1 drochner * Read a sequence of bytes from the EEPROM.
333 1.1 drochner */
334 1.1 drochner static int ti_read_eeprom(sc, dest, off, cnt)
335 1.1 drochner struct ti_softc *sc;
336 1.1 drochner caddr_t dest;
337 1.1 drochner int off;
338 1.1 drochner int cnt;
339 1.1 drochner {
340 1.1 drochner int err = 0, i;
341 1.1 drochner u_int8_t byte = 0;
342 1.1 drochner
343 1.1 drochner for (i = 0; i < cnt; i++) {
344 1.1 drochner err = ti_eeprom_getbyte(sc, off + i, &byte);
345 1.1 drochner if (err)
346 1.1 drochner break;
347 1.1 drochner *(dest + i) = byte;
348 1.1 drochner }
349 1.1 drochner
350 1.1 drochner return(err ? 1 : 0);
351 1.1 drochner }
352 1.1 drochner
353 1.1 drochner /*
354 1.1 drochner * NIC memory access function. Can be used to either clear a section
355 1.1 drochner * of NIC local memory or (if buf is non-NULL) copy data into it.
356 1.1 drochner */
357 1.1 drochner static void ti_mem(sc, addr, len, buf)
358 1.1 drochner struct ti_softc *sc;
359 1.1 drochner u_int32_t addr, len;
360 1.1 drochner caddr_t buf;
361 1.1 drochner {
362 1.1 drochner int segptr, segsize, cnt;
363 1.6 bouyer caddr_t ptr;
364 1.1 drochner
365 1.1 drochner segptr = addr;
366 1.1 drochner cnt = len;
367 1.1 drochner ptr = buf;
368 1.1 drochner
369 1.1 drochner while(cnt) {
370 1.1 drochner if (cnt < TI_WINLEN)
371 1.1 drochner segsize = cnt;
372 1.1 drochner else
373 1.1 drochner segsize = TI_WINLEN - (segptr % TI_WINLEN);
374 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
375 1.6 bouyer if (buf == NULL) {
376 1.6 bouyer bus_space_set_region_4(sc->ti_btag, sc->ti_bhandle,
377 1.6 bouyer TI_WINDOW + (segptr & (TI_WINLEN - 1)), 0,
378 1.6 bouyer segsize / 4);
379 1.6 bouyer } else {
380 1.6 bouyer bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
381 1.6 bouyer TI_WINDOW + (segptr & (TI_WINLEN - 1)),
382 1.6 bouyer (u_int32_t *)ptr, segsize / 4);
383 1.1 drochner ptr += segsize;
384 1.1 drochner }
385 1.1 drochner segptr += segsize;
386 1.1 drochner cnt -= segsize;
387 1.1 drochner }
388 1.1 drochner
389 1.1 drochner return;
390 1.1 drochner }
391 1.1 drochner
392 1.1 drochner /*
393 1.1 drochner * Load firmware image into the NIC. Check that the firmware revision
394 1.1 drochner * is acceptable and see if we want the firmware for the Tigon 1 or
395 1.1 drochner * Tigon 2.
396 1.1 drochner */
397 1.1 drochner static void ti_loadfw(sc)
398 1.1 drochner struct ti_softc *sc;
399 1.1 drochner {
400 1.1 drochner switch(sc->ti_hwrev) {
401 1.1 drochner case TI_HWREV_TIGON:
402 1.1 drochner if (tigonFwReleaseMajor != TI_FIRMWARE_MAJOR ||
403 1.1 drochner tigonFwReleaseMinor != TI_FIRMWARE_MINOR ||
404 1.1 drochner tigonFwReleaseFix != TI_FIRMWARE_FIX) {
405 1.1 drochner printf("%s: firmware revision mismatch; want "
406 1.1 drochner "%d.%d.%d, got %d.%d.%d\n", sc->sc_dev.dv_xname,
407 1.1 drochner TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR,
408 1.1 drochner TI_FIRMWARE_FIX, tigonFwReleaseMajor,
409 1.1 drochner tigonFwReleaseMinor, tigonFwReleaseFix);
410 1.1 drochner return;
411 1.1 drochner }
412 1.1 drochner ti_mem(sc, tigonFwTextAddr, tigonFwTextLen,
413 1.1 drochner (caddr_t)tigonFwText);
414 1.1 drochner ti_mem(sc, tigonFwDataAddr, tigonFwDataLen,
415 1.1 drochner (caddr_t)tigonFwData);
416 1.1 drochner ti_mem(sc, tigonFwRodataAddr, tigonFwRodataLen,
417 1.1 drochner (caddr_t)tigonFwRodata);
418 1.1 drochner ti_mem(sc, tigonFwBssAddr, tigonFwBssLen, NULL);
419 1.1 drochner ti_mem(sc, tigonFwSbssAddr, tigonFwSbssLen, NULL);
420 1.1 drochner CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigonFwStartAddr);
421 1.1 drochner break;
422 1.1 drochner case TI_HWREV_TIGON_II:
423 1.1 drochner if (tigon2FwReleaseMajor != TI_FIRMWARE_MAJOR ||
424 1.1 drochner tigon2FwReleaseMinor != TI_FIRMWARE_MINOR ||
425 1.1 drochner tigon2FwReleaseFix != TI_FIRMWARE_FIX) {
426 1.1 drochner printf("%s: firmware revision mismatch; want "
427 1.1 drochner "%d.%d.%d, got %d.%d.%d\n", sc->sc_dev.dv_xname,
428 1.1 drochner TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR,
429 1.1 drochner TI_FIRMWARE_FIX, tigon2FwReleaseMajor,
430 1.1 drochner tigon2FwReleaseMinor, tigon2FwReleaseFix);
431 1.1 drochner return;
432 1.1 drochner }
433 1.1 drochner ti_mem(sc, tigon2FwTextAddr, tigon2FwTextLen,
434 1.1 drochner (caddr_t)tigon2FwText);
435 1.1 drochner ti_mem(sc, tigon2FwDataAddr, tigon2FwDataLen,
436 1.1 drochner (caddr_t)tigon2FwData);
437 1.1 drochner ti_mem(sc, tigon2FwRodataAddr, tigon2FwRodataLen,
438 1.1 drochner (caddr_t)tigon2FwRodata);
439 1.1 drochner ti_mem(sc, tigon2FwBssAddr, tigon2FwBssLen, NULL);
440 1.1 drochner ti_mem(sc, tigon2FwSbssAddr, tigon2FwSbssLen, NULL);
441 1.1 drochner CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigon2FwStartAddr);
442 1.1 drochner break;
443 1.1 drochner default:
444 1.1 drochner printf("%s: can't load firmware: unknown hardware rev\n",
445 1.1 drochner sc->sc_dev.dv_xname);
446 1.1 drochner break;
447 1.1 drochner }
448 1.1 drochner
449 1.1 drochner return;
450 1.1 drochner }
451 1.1 drochner
452 1.1 drochner /*
453 1.1 drochner * Send the NIC a command via the command ring.
454 1.1 drochner */
455 1.1 drochner static void ti_cmd(sc, cmd)
456 1.1 drochner struct ti_softc *sc;
457 1.1 drochner struct ti_cmd_desc *cmd;
458 1.1 drochner {
459 1.1 drochner u_int32_t index;
460 1.1 drochner
461 1.1 drochner index = sc->ti_cmd_saved_prodidx;
462 1.1 drochner CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd));
463 1.1 drochner TI_INC(index, TI_CMD_RING_CNT);
464 1.1 drochner CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index);
465 1.1 drochner sc->ti_cmd_saved_prodidx = index;
466 1.1 drochner
467 1.1 drochner return;
468 1.1 drochner }
469 1.1 drochner
470 1.1 drochner /*
471 1.1 drochner * Send the NIC an extended command. The 'len' parameter specifies the
472 1.1 drochner * number of command slots to include after the initial command.
473 1.1 drochner */
474 1.1 drochner static void ti_cmd_ext(sc, cmd, arg, len)
475 1.1 drochner struct ti_softc *sc;
476 1.1 drochner struct ti_cmd_desc *cmd;
477 1.1 drochner caddr_t arg;
478 1.1 drochner int len;
479 1.1 drochner {
480 1.1 drochner u_int32_t index;
481 1.8 augustss int i;
482 1.1 drochner
483 1.1 drochner index = sc->ti_cmd_saved_prodidx;
484 1.1 drochner CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd));
485 1.1 drochner TI_INC(index, TI_CMD_RING_CNT);
486 1.1 drochner for (i = 0; i < len; i++) {
487 1.1 drochner CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4),
488 1.1 drochner *(u_int32_t *)(&arg[i * 4]));
489 1.1 drochner TI_INC(index, TI_CMD_RING_CNT);
490 1.1 drochner }
491 1.1 drochner CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index);
492 1.1 drochner sc->ti_cmd_saved_prodidx = index;
493 1.1 drochner
494 1.1 drochner return;
495 1.1 drochner }
496 1.1 drochner
497 1.1 drochner /*
498 1.1 drochner * Handle events that have triggered interrupts.
499 1.1 drochner */
500 1.1 drochner static void ti_handle_events(sc)
501 1.1 drochner struct ti_softc *sc;
502 1.1 drochner {
503 1.1 drochner struct ti_event_desc *e;
504 1.1 drochner
505 1.1 drochner if (sc->ti_rdata->ti_event_ring == NULL)
506 1.1 drochner return;
507 1.1 drochner
508 1.1 drochner while (sc->ti_ev_saved_considx != sc->ti_ev_prodidx.ti_idx) {
509 1.1 drochner e = &sc->ti_rdata->ti_event_ring[sc->ti_ev_saved_considx];
510 1.1 drochner switch(e->ti_event) {
511 1.1 drochner case TI_EV_LINKSTAT_CHANGED:
512 1.1 drochner sc->ti_linkstat = e->ti_code;
513 1.1 drochner if (e->ti_code == TI_EV_CODE_LINK_UP)
514 1.1 drochner printf("%s: 10/100 link up\n",
515 1.1 drochner sc->sc_dev.dv_xname);
516 1.1 drochner else if (e->ti_code == TI_EV_CODE_GIG_LINK_UP)
517 1.1 drochner printf("%s: gigabit link up\n",
518 1.1 drochner sc->sc_dev.dv_xname);
519 1.1 drochner else if (e->ti_code == TI_EV_CODE_LINK_DOWN)
520 1.1 drochner printf("%s: link down\n",
521 1.1 drochner sc->sc_dev.dv_xname);
522 1.1 drochner break;
523 1.1 drochner case TI_EV_ERROR:
524 1.1 drochner if (e->ti_code == TI_EV_CODE_ERR_INVAL_CMD)
525 1.1 drochner printf("%s: invalid command\n",
526 1.1 drochner sc->sc_dev.dv_xname);
527 1.1 drochner else if (e->ti_code == TI_EV_CODE_ERR_UNIMP_CMD)
528 1.1 drochner printf("%s: unknown command\n",
529 1.1 drochner sc->sc_dev.dv_xname);
530 1.1 drochner else if (e->ti_code == TI_EV_CODE_ERR_BADCFG)
531 1.1 drochner printf("%s: bad config data\n",
532 1.1 drochner sc->sc_dev.dv_xname);
533 1.1 drochner break;
534 1.1 drochner case TI_EV_FIRMWARE_UP:
535 1.1 drochner ti_init2(sc);
536 1.1 drochner break;
537 1.1 drochner case TI_EV_STATS_UPDATED:
538 1.1 drochner ti_stats_update(sc);
539 1.1 drochner break;
540 1.1 drochner case TI_EV_RESET_JUMBO_RING:
541 1.1 drochner case TI_EV_MCAST_UPDATED:
542 1.1 drochner /* Who cares. */
543 1.1 drochner break;
544 1.1 drochner default:
545 1.1 drochner printf("%s: unknown event: %d\n",
546 1.1 drochner sc->sc_dev.dv_xname, e->ti_event);
547 1.1 drochner break;
548 1.1 drochner }
549 1.1 drochner /* Advance the consumer index. */
550 1.1 drochner TI_INC(sc->ti_ev_saved_considx, TI_EVENT_RING_CNT);
551 1.1 drochner CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, sc->ti_ev_saved_considx);
552 1.1 drochner }
553 1.1 drochner
554 1.1 drochner return;
555 1.1 drochner }
556 1.1 drochner
557 1.1 drochner /*
558 1.1 drochner * Memory management for the jumbo receive ring is a pain in the
559 1.1 drochner * butt. We need to allocate at least 9018 bytes of space per frame,
560 1.1 drochner * _and_ it has to be contiguous (unless you use the extended
561 1.1 drochner * jumbo descriptor format). Using malloc() all the time won't
562 1.1 drochner * work: malloc() allocates memory in powers of two, which means we
563 1.1 drochner * would end up wasting a considerable amount of space by allocating
564 1.1 drochner * 9K chunks. We don't have a jumbo mbuf cluster pool. Thus, we have
565 1.1 drochner * to do our own memory management.
566 1.1 drochner *
567 1.1 drochner * The driver needs to allocate a contiguous chunk of memory at boot
568 1.1 drochner * time. We then chop this up ourselves into 9K pieces and use them
569 1.1 drochner * as external mbuf storage.
570 1.1 drochner *
571 1.1 drochner * One issue here is how much memory to allocate. The jumbo ring has
572 1.1 drochner * 256 slots in it, but at 9K per slot than can consume over 2MB of
573 1.1 drochner * RAM. This is a bit much, especially considering we also need
574 1.1 drochner * RAM for the standard ring and mini ring (on the Tigon 2). To
575 1.1 drochner * save space, we only actually allocate enough memory for 64 slots
576 1.1 drochner * by default, which works out to between 500 and 600K. This can
577 1.1 drochner * be tuned by changing a #define in if_tireg.h.
578 1.1 drochner */
579 1.1 drochner
580 1.1 drochner static int ti_alloc_jumbo_mem(sc)
581 1.1 drochner struct ti_softc *sc;
582 1.1 drochner {
583 1.1 drochner caddr_t ptr;
584 1.8 augustss int i;
585 1.1 drochner struct ti_jpool_entry *entry;
586 1.1 drochner bus_dma_segment_t dmaseg;
587 1.1 drochner int error, dmanseg;
588 1.1 drochner
589 1.1 drochner /* Grab a big chunk o' storage. */
590 1.1 drochner if ((error = bus_dmamem_alloc(sc->sc_dmat,
591 1.1 drochner TI_JMEM, NBPG, 0, &dmaseg, 1, &dmanseg,
592 1.1 drochner BUS_DMA_NOWAIT)) != 0) {
593 1.1 drochner printf("%s: can't allocate jumbo buffer, error = %d\n",
594 1.1 drochner sc->sc_dev.dv_xname, error);
595 1.1 drochner return (error);
596 1.1 drochner }
597 1.1 drochner
598 1.1 drochner if ((error = bus_dmamem_map(sc->sc_dmat, &dmaseg, dmanseg,
599 1.1 drochner TI_JMEM, (caddr_t *)&sc->ti_cdata.ti_jumbo_buf,
600 1.1 drochner BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
601 1.1 drochner printf("%s: can't map jumbo buffer, error = %d\n",
602 1.1 drochner sc->sc_dev.dv_xname, error);
603 1.1 drochner return (error);
604 1.1 drochner }
605 1.1 drochner
606 1.1 drochner if ((error = bus_dmamap_create(sc->sc_dmat,
607 1.1 drochner TI_JMEM, 1,
608 1.1 drochner TI_JMEM, 0, BUS_DMA_NOWAIT,
609 1.1 drochner &sc->jumbo_dmamap)) != 0) {
610 1.1 drochner printf("%s: can't create jumbo buffer DMA map, error = %d\n",
611 1.1 drochner sc->sc_dev.dv_xname, error);
612 1.1 drochner return (error);
613 1.1 drochner }
614 1.1 drochner
615 1.1 drochner if ((error = bus_dmamap_load(sc->sc_dmat, sc->jumbo_dmamap,
616 1.1 drochner sc->ti_cdata.ti_jumbo_buf, TI_JMEM, NULL,
617 1.1 drochner BUS_DMA_NOWAIT)) != 0) {
618 1.1 drochner printf("%s: can't load jumbo buffer DMA map, error = %d\n",
619 1.1 drochner sc->sc_dev.dv_xname, error);
620 1.1 drochner return (error);
621 1.1 drochner }
622 1.1 drochner sc->jumbo_dmaaddr = sc->jumbo_dmamap->dm_segs[0].ds_addr;
623 1.1 drochner
624 1.1 drochner SIMPLEQ_INIT(&sc->ti_jfree_listhead);
625 1.1 drochner SIMPLEQ_INIT(&sc->ti_jinuse_listhead);
626 1.1 drochner
627 1.1 drochner /*
628 1.1 drochner * Now divide it up into 9K pieces and save the addresses
629 1.1 drochner * in an array. Note that we play an evil trick here by using
630 1.1 drochner * the first few bytes in the buffer to hold the address
631 1.1 drochner * of the softc structure for this interface. This is because
632 1.1 drochner * ti_jfree() needs it, but it is called by the mbuf management
633 1.1 drochner * code which will not pass it to us explicitly.
634 1.1 drochner */
635 1.1 drochner ptr = sc->ti_cdata.ti_jumbo_buf;
636 1.1 drochner for (i = 0; i < TI_JSLOTS; i++) {
637 1.1 drochner u_int64_t **aptr;
638 1.1 drochner aptr = (u_int64_t **)ptr;
639 1.1 drochner aptr[0] = (u_int64_t *)sc;
640 1.1 drochner ptr += sizeof(u_int64_t);
641 1.1 drochner sc->ti_cdata.ti_jslots[i].ti_buf = ptr;
642 1.1 drochner sc->ti_cdata.ti_jslots[i].ti_inuse = 0;
643 1.1 drochner ptr += (TI_JLEN - sizeof(u_int64_t));
644 1.1 drochner entry = malloc(sizeof(struct ti_jpool_entry),
645 1.1 drochner M_DEVBUF, M_NOWAIT);
646 1.1 drochner if (entry == NULL) {
647 1.1 drochner free(sc->ti_cdata.ti_jumbo_buf, M_DEVBUF);
648 1.1 drochner sc->ti_cdata.ti_jumbo_buf = NULL;
649 1.1 drochner printf("%s: no memory for jumbo "
650 1.1 drochner "buffer queue!\n", sc->sc_dev.dv_xname);
651 1.1 drochner return(ENOBUFS);
652 1.1 drochner }
653 1.1 drochner entry->slot = i;
654 1.1 drochner SIMPLEQ_INSERT_HEAD(&sc->ti_jfree_listhead, entry,
655 1.1 drochner jpool_entries);
656 1.1 drochner }
657 1.1 drochner
658 1.1 drochner return(0);
659 1.1 drochner }
660 1.1 drochner
661 1.1 drochner /*
662 1.1 drochner * Allocate a jumbo buffer.
663 1.1 drochner */
664 1.1 drochner static void *ti_jalloc(sc)
665 1.1 drochner struct ti_softc *sc;
666 1.1 drochner {
667 1.1 drochner struct ti_jpool_entry *entry;
668 1.1 drochner
669 1.1 drochner entry = SIMPLEQ_FIRST(&sc->ti_jfree_listhead);
670 1.1 drochner
671 1.1 drochner if (entry == NULL) {
672 1.1 drochner printf("%s: no free jumbo buffers\n", sc->sc_dev.dv_xname);
673 1.1 drochner return(NULL);
674 1.1 drochner }
675 1.1 drochner
676 1.1 drochner SIMPLEQ_REMOVE_HEAD(&sc->ti_jfree_listhead, entry, jpool_entries);
677 1.1 drochner SIMPLEQ_INSERT_HEAD(&sc->ti_jinuse_listhead, entry, jpool_entries);
678 1.1 drochner sc->ti_cdata.ti_jslots[entry->slot].ti_inuse = 1;
679 1.1 drochner return(sc->ti_cdata.ti_jslots[entry->slot].ti_buf);
680 1.1 drochner }
681 1.1 drochner
682 1.1 drochner /*
683 1.1 drochner * Release a jumbo buffer.
684 1.1 drochner */
685 1.1 drochner static void ti_jfree(buf, size, arg)
686 1.1 drochner caddr_t buf;
687 1.1 drochner u_int size;
688 1.1 drochner void *arg; /* XXX NetBSD: we should really use it */
689 1.1 drochner {
690 1.1 drochner struct ti_softc *sc;
691 1.1 drochner u_int64_t **aptr;
692 1.1 drochner int i;
693 1.1 drochner struct ti_jpool_entry *entry;
694 1.1 drochner
695 1.1 drochner /* Extract the softc struct pointer. */
696 1.1 drochner aptr = (u_int64_t **)(buf - sizeof(u_int64_t));
697 1.1 drochner sc = (struct ti_softc *)(aptr[0]);
698 1.1 drochner
699 1.1 drochner if (sc == NULL)
700 1.1 drochner panic("ti_jfree: can't find softc pointer!");
701 1.1 drochner
702 1.1 drochner if (size != TI_JUMBO_FRAMELEN)
703 1.1 drochner panic("ti_jfree: freeing buffer of wrong size!");
704 1.1 drochner
705 1.1 drochner /* calculate the slot this buffer belongs to */
706 1.1 drochner
707 1.1 drochner i = ((caddr_t)aptr
708 1.1 drochner - (caddr_t)sc->ti_cdata.ti_jumbo_buf) / TI_JLEN;
709 1.1 drochner
710 1.1 drochner if ((i < 0) || (i >= TI_JSLOTS))
711 1.1 drochner panic("ti_jfree: asked to free buffer that we don't manage!");
712 1.1 drochner else if (sc->ti_cdata.ti_jslots[i].ti_inuse == 0)
713 1.1 drochner panic("ti_jfree: buffer already free!");
714 1.1 drochner else {
715 1.1 drochner sc->ti_cdata.ti_jslots[i].ti_inuse--;
716 1.1 drochner if(sc->ti_cdata.ti_jslots[i].ti_inuse == 0) {
717 1.1 drochner entry = SIMPLEQ_FIRST(&sc->ti_jinuse_listhead);
718 1.1 drochner if (entry == NULL)
719 1.1 drochner panic("ti_jfree: buffer not in use!");
720 1.1 drochner entry->slot = i;
721 1.1 drochner SIMPLEQ_REMOVE_HEAD(&sc->ti_jinuse_listhead,
722 1.1 drochner entry, jpool_entries);
723 1.1 drochner SIMPLEQ_INSERT_HEAD(&sc->ti_jfree_listhead,
724 1.1 drochner entry, jpool_entries);
725 1.1 drochner }
726 1.1 drochner }
727 1.1 drochner
728 1.1 drochner return;
729 1.1 drochner }
730 1.1 drochner
731 1.1 drochner
732 1.1 drochner /*
733 1.1 drochner * Intialize a standard receive ring descriptor.
734 1.1 drochner */
735 1.1 drochner static int ti_newbuf_std(sc, i, m, dmamap)
736 1.1 drochner struct ti_softc *sc;
737 1.1 drochner int i;
738 1.1 drochner struct mbuf *m;
739 1.1 drochner bus_dmamap_t dmamap; /* required if (m != NULL) */
740 1.1 drochner {
741 1.1 drochner struct mbuf *m_new = NULL;
742 1.1 drochner struct ti_rx_desc *r;
743 1.1 drochner int error;
744 1.1 drochner
745 1.1 drochner if (dmamap == NULL) {
746 1.1 drochner /* if (m) panic() */
747 1.1 drochner
748 1.1 drochner if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
749 1.1 drochner MCLBYTES, 0, BUS_DMA_NOWAIT,
750 1.1 drochner &dmamap)) != 0) {
751 1.1 drochner printf("%s: can't create recv map, error = %d\n",
752 1.1 drochner sc->sc_dev.dv_xname, error);
753 1.1 drochner return(ENOMEM);
754 1.1 drochner }
755 1.1 drochner }
756 1.1 drochner sc->std_dmamap[i] = dmamap;
757 1.1 drochner
758 1.1 drochner if (m == NULL) {
759 1.1 drochner MGETHDR(m_new, M_DONTWAIT, MT_DATA);
760 1.1 drochner if (m_new == NULL) {
761 1.1 drochner printf("%s: mbuf allocation failed "
762 1.1 drochner "-- packet dropped!\n", sc->sc_dev.dv_xname);
763 1.1 drochner return(ENOBUFS);
764 1.1 drochner }
765 1.1 drochner
766 1.1 drochner MCLGET(m_new, M_DONTWAIT);
767 1.1 drochner if (!(m_new->m_flags & M_EXT)) {
768 1.1 drochner printf("%s: cluster allocation failed "
769 1.1 drochner "-- packet dropped!\n", sc->sc_dev.dv_xname);
770 1.1 drochner m_freem(m_new);
771 1.1 drochner return(ENOBUFS);
772 1.1 drochner }
773 1.1 drochner m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
774 1.1 drochner m_adj(m_new, ETHER_ALIGN);
775 1.1 drochner
776 1.1 drochner if ((error = bus_dmamap_load(sc->sc_dmat, dmamap,
777 1.1 drochner mtod(m_new, caddr_t), m_new->m_len, NULL,
778 1.1 drochner BUS_DMA_NOWAIT)) != 0) {
779 1.1 drochner printf("%s: can't load recv map, error = %d\n",
780 1.1 drochner sc->sc_dev.dv_xname, error);
781 1.1 drochner return (ENOMEM);
782 1.1 drochner }
783 1.1 drochner } else {
784 1.1 drochner m_new = m;
785 1.1 drochner m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
786 1.1 drochner m_new->m_data = m_new->m_ext.ext_buf;
787 1.1 drochner m_adj(m_new, ETHER_ALIGN);
788 1.1 drochner
789 1.1 drochner /* reuse the dmamap */
790 1.1 drochner }
791 1.1 drochner
792 1.1 drochner sc->ti_cdata.ti_rx_std_chain[i] = m_new;
793 1.1 drochner r = &sc->ti_rdata->ti_rx_std_ring[i];
794 1.1 drochner TI_HOSTADDR(r->ti_addr) = dmamap->dm_segs[0].ds_addr;
795 1.1 drochner r->ti_type = TI_BDTYPE_RECV_BD;
796 1.1 drochner #ifdef TI_CSUM_OFFLOAD
797 1.1 drochner r->ti_flags = TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
798 1.1 drochner #else
799 1.1 drochner r->ti_flags = 0;
800 1.1 drochner #endif
801 1.1 drochner r->ti_len = m_new->m_len; /* == ds_len */
802 1.1 drochner r->ti_idx = i;
803 1.1 drochner
804 1.1 drochner return(0);
805 1.1 drochner }
806 1.1 drochner
807 1.1 drochner /*
808 1.1 drochner * Intialize a mini receive ring descriptor. This only applies to
809 1.1 drochner * the Tigon 2.
810 1.1 drochner */
811 1.1 drochner static int ti_newbuf_mini(sc, i, m, dmamap)
812 1.1 drochner struct ti_softc *sc;
813 1.1 drochner int i;
814 1.1 drochner struct mbuf *m;
815 1.1 drochner bus_dmamap_t dmamap; /* required if (m != NULL) */
816 1.1 drochner {
817 1.1 drochner struct mbuf *m_new = NULL;
818 1.1 drochner struct ti_rx_desc *r;
819 1.1 drochner int error;
820 1.1 drochner
821 1.1 drochner if (dmamap == NULL) {
822 1.1 drochner /* if (m) panic() */
823 1.1 drochner
824 1.1 drochner if ((error = bus_dmamap_create(sc->sc_dmat, MHLEN, 1,
825 1.1 drochner MHLEN, 0, BUS_DMA_NOWAIT,
826 1.1 drochner &dmamap)) != 0) {
827 1.1 drochner printf("%s: can't create recv map, error = %d\n",
828 1.1 drochner sc->sc_dev.dv_xname, error);
829 1.1 drochner return(ENOMEM);
830 1.1 drochner }
831 1.1 drochner }
832 1.1 drochner sc->mini_dmamap[i] = dmamap;
833 1.1 drochner
834 1.1 drochner if (m == NULL) {
835 1.1 drochner MGETHDR(m_new, M_DONTWAIT, MT_DATA);
836 1.1 drochner if (m_new == NULL) {
837 1.1 drochner printf("%s: mbuf allocation failed "
838 1.1 drochner "-- packet dropped!\n", sc->sc_dev.dv_xname);
839 1.1 drochner return(ENOBUFS);
840 1.1 drochner }
841 1.1 drochner m_new->m_len = m_new->m_pkthdr.len = MHLEN;
842 1.1 drochner m_adj(m_new, ETHER_ALIGN);
843 1.1 drochner
844 1.1 drochner if ((error = bus_dmamap_load(sc->sc_dmat, dmamap,
845 1.1 drochner mtod(m_new, caddr_t), m_new->m_len, NULL,
846 1.1 drochner BUS_DMA_NOWAIT)) != 0) {
847 1.1 drochner printf("%s: can't load recv map, error = %d\n",
848 1.1 drochner sc->sc_dev.dv_xname, error);
849 1.1 drochner return (ENOMEM);
850 1.1 drochner }
851 1.1 drochner } else {
852 1.1 drochner m_new = m;
853 1.1 drochner m_new->m_data = m_new->m_pktdat;
854 1.1 drochner m_new->m_len = m_new->m_pkthdr.len = MHLEN;
855 1.1 drochner m_adj(m_new, ETHER_ALIGN);
856 1.1 drochner
857 1.1 drochner /* reuse the dmamap */
858 1.1 drochner }
859 1.1 drochner
860 1.1 drochner r = &sc->ti_rdata->ti_rx_mini_ring[i];
861 1.1 drochner sc->ti_cdata.ti_rx_mini_chain[i] = m_new;
862 1.1 drochner TI_HOSTADDR(r->ti_addr) = dmamap->dm_segs[0].ds_addr;
863 1.1 drochner r->ti_type = TI_BDTYPE_RECV_BD;
864 1.1 drochner r->ti_flags = TI_BDFLAG_MINI_RING;
865 1.1 drochner #ifdef TI_CSUM_OFFLOAD
866 1.1 drochner r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
867 1.1 drochner #endif
868 1.1 drochner r->ti_len = m_new->m_len; /* == ds_len */
869 1.1 drochner r->ti_idx = i;
870 1.1 drochner
871 1.1 drochner return(0);
872 1.1 drochner }
873 1.1 drochner
874 1.1 drochner /*
875 1.1 drochner * Initialize a jumbo receive ring descriptor. This allocates
876 1.1 drochner * a jumbo buffer from the pool managed internally by the driver.
877 1.1 drochner */
878 1.1 drochner static int ti_newbuf_jumbo(sc, i, m)
879 1.1 drochner struct ti_softc *sc;
880 1.1 drochner int i;
881 1.1 drochner struct mbuf *m;
882 1.1 drochner {
883 1.1 drochner struct mbuf *m_new = NULL;
884 1.1 drochner struct ti_rx_desc *r;
885 1.1 drochner
886 1.1 drochner if (m == NULL) {
887 1.1 drochner caddr_t *buf = NULL;
888 1.1 drochner
889 1.1 drochner /* Allocate the mbuf. */
890 1.1 drochner MGETHDR(m_new, M_DONTWAIT, MT_DATA);
891 1.1 drochner if (m_new == NULL) {
892 1.1 drochner printf("%s: mbuf allocation failed "
893 1.1 drochner "-- packet dropped!\n", sc->sc_dev.dv_xname);
894 1.1 drochner return(ENOBUFS);
895 1.1 drochner }
896 1.1 drochner
897 1.1 drochner /* Allocate the jumbo buffer */
898 1.1 drochner buf = ti_jalloc(sc);
899 1.1 drochner if (buf == NULL) {
900 1.1 drochner m_freem(m_new);
901 1.1 drochner printf("%s: jumbo allocation failed "
902 1.1 drochner "-- packet dropped!\n", sc->sc_dev.dv_xname);
903 1.1 drochner return(ENOBUFS);
904 1.1 drochner }
905 1.1 drochner
906 1.1 drochner /* Attach the buffer to the mbuf. */
907 1.1 drochner m_new->m_data = m_new->m_ext.ext_buf = (void *)buf;
908 1.1 drochner m_new->m_flags |= M_EXT;
909 1.1 drochner m_new->m_len = m_new->m_pkthdr.len =
910 1.1 drochner m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
911 1.1 drochner m_new->m_ext.ext_free = ti_jfree;
912 1.1 drochner m_new->m_ext.ext_arg = sc;
913 1.1 drochner MCLINITREFERENCE(m_new);
914 1.1 drochner } else {
915 1.1 drochner m_new = m;
916 1.1 drochner m_new->m_data = m_new->m_ext.ext_buf;
917 1.1 drochner m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
918 1.1 drochner }
919 1.1 drochner
920 1.1 drochner m_adj(m_new, ETHER_ALIGN);
921 1.1 drochner /* Set up the descriptor. */
922 1.1 drochner r = &sc->ti_rdata->ti_rx_jumbo_ring[i];
923 1.1 drochner sc->ti_cdata.ti_rx_jumbo_chain[i] = m_new;
924 1.1 drochner TI_HOSTADDR(r->ti_addr) = sc->jumbo_dmaaddr +
925 1.1 drochner ((caddr_t)mtod(m_new, caddr_t)
926 1.1 drochner - (caddr_t)sc->ti_cdata.ti_jumbo_buf);
927 1.1 drochner r->ti_type = TI_BDTYPE_RECV_JUMBO_BD;
928 1.1 drochner r->ti_flags = TI_BDFLAG_JUMBO_RING;
929 1.1 drochner #ifdef TI_CSUM_OFFLOAD
930 1.1 drochner r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
931 1.1 drochner #endif
932 1.1 drochner r->ti_len = m_new->m_len;
933 1.1 drochner r->ti_idx = i;
934 1.1 drochner
935 1.1 drochner return(0);
936 1.1 drochner }
937 1.1 drochner
938 1.1 drochner /*
939 1.1 drochner * The standard receive ring has 512 entries in it. At 2K per mbuf cluster,
940 1.1 drochner * that's 1MB or memory, which is a lot. For now, we fill only the first
941 1.1 drochner * 256 ring entries and hope that our CPU is fast enough to keep up with
942 1.1 drochner * the NIC.
943 1.1 drochner */
944 1.1 drochner static int ti_init_rx_ring_std(sc)
945 1.1 drochner struct ti_softc *sc;
946 1.1 drochner {
947 1.8 augustss int i;
948 1.1 drochner struct ti_cmd_desc cmd;
949 1.1 drochner
950 1.1 drochner for (i = 0; i < TI_SSLOTS; i++) {
951 1.1 drochner if (ti_newbuf_std(sc, i, NULL, 0) == ENOBUFS)
952 1.1 drochner return(ENOBUFS);
953 1.1 drochner };
954 1.1 drochner
955 1.1 drochner TI_UPDATE_STDPROD(sc, i - 1);
956 1.1 drochner sc->ti_std = i - 1;
957 1.1 drochner
958 1.1 drochner return(0);
959 1.1 drochner }
960 1.1 drochner
961 1.1 drochner static void ti_free_rx_ring_std(sc)
962 1.1 drochner struct ti_softc *sc;
963 1.1 drochner {
964 1.8 augustss int i;
965 1.1 drochner
966 1.1 drochner for (i = 0; i < TI_STD_RX_RING_CNT; i++) {
967 1.1 drochner if (sc->ti_cdata.ti_rx_std_chain[i] != NULL) {
968 1.1 drochner m_freem(sc->ti_cdata.ti_rx_std_chain[i]);
969 1.1 drochner sc->ti_cdata.ti_rx_std_chain[i] = NULL;
970 1.1 drochner
971 1.1 drochner /* if (sc->std_dmamap[i] == 0) panic() */
972 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, sc->std_dmamap[i]);
973 1.1 drochner sc->std_dmamap[i] = 0;
974 1.1 drochner }
975 1.1 drochner bzero((char *)&sc->ti_rdata->ti_rx_std_ring[i],
976 1.1 drochner sizeof(struct ti_rx_desc));
977 1.1 drochner }
978 1.1 drochner
979 1.1 drochner return;
980 1.1 drochner }
981 1.1 drochner
982 1.1 drochner static int ti_init_rx_ring_jumbo(sc)
983 1.1 drochner struct ti_softc *sc;
984 1.1 drochner {
985 1.8 augustss int i;
986 1.1 drochner struct ti_cmd_desc cmd;
987 1.1 drochner
988 1.1 drochner for (i = 0; i < (TI_JSLOTS - 20); i++) {
989 1.1 drochner if (ti_newbuf_jumbo(sc, i, NULL) == ENOBUFS)
990 1.1 drochner return(ENOBUFS);
991 1.1 drochner };
992 1.1 drochner
993 1.1 drochner TI_UPDATE_JUMBOPROD(sc, i - 1);
994 1.1 drochner sc->ti_jumbo = i - 1;
995 1.1 drochner
996 1.1 drochner return(0);
997 1.1 drochner }
998 1.1 drochner
999 1.1 drochner static void ti_free_rx_ring_jumbo(sc)
1000 1.1 drochner struct ti_softc *sc;
1001 1.1 drochner {
1002 1.8 augustss int i;
1003 1.1 drochner
1004 1.1 drochner for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
1005 1.1 drochner if (sc->ti_cdata.ti_rx_jumbo_chain[i] != NULL) {
1006 1.1 drochner m_freem(sc->ti_cdata.ti_rx_jumbo_chain[i]);
1007 1.1 drochner sc->ti_cdata.ti_rx_jumbo_chain[i] = NULL;
1008 1.1 drochner }
1009 1.1 drochner bzero((char *)&sc->ti_rdata->ti_rx_jumbo_ring[i],
1010 1.1 drochner sizeof(struct ti_rx_desc));
1011 1.1 drochner }
1012 1.1 drochner
1013 1.1 drochner return;
1014 1.1 drochner }
1015 1.1 drochner
1016 1.1 drochner static int ti_init_rx_ring_mini(sc)
1017 1.1 drochner struct ti_softc *sc;
1018 1.1 drochner {
1019 1.8 augustss int i;
1020 1.1 drochner
1021 1.1 drochner for (i = 0; i < TI_MSLOTS; i++) {
1022 1.1 drochner if (ti_newbuf_mini(sc, i, NULL, 0) == ENOBUFS)
1023 1.1 drochner return(ENOBUFS);
1024 1.1 drochner };
1025 1.1 drochner
1026 1.1 drochner TI_UPDATE_MINIPROD(sc, i - 1);
1027 1.1 drochner sc->ti_mini = i - 1;
1028 1.1 drochner
1029 1.1 drochner return(0);
1030 1.1 drochner }
1031 1.1 drochner
1032 1.1 drochner static void ti_free_rx_ring_mini(sc)
1033 1.1 drochner struct ti_softc *sc;
1034 1.1 drochner {
1035 1.8 augustss int i;
1036 1.1 drochner
1037 1.1 drochner for (i = 0; i < TI_MINI_RX_RING_CNT; i++) {
1038 1.1 drochner if (sc->ti_cdata.ti_rx_mini_chain[i] != NULL) {
1039 1.1 drochner m_freem(sc->ti_cdata.ti_rx_mini_chain[i]);
1040 1.1 drochner sc->ti_cdata.ti_rx_mini_chain[i] = NULL;
1041 1.1 drochner
1042 1.1 drochner /* if (sc->mini_dmamap[i] == 0) panic() */
1043 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, sc->mini_dmamap[i]);
1044 1.1 drochner sc->mini_dmamap[i] = 0;
1045 1.1 drochner }
1046 1.1 drochner bzero((char *)&sc->ti_rdata->ti_rx_mini_ring[i],
1047 1.1 drochner sizeof(struct ti_rx_desc));
1048 1.1 drochner }
1049 1.1 drochner
1050 1.1 drochner return;
1051 1.1 drochner }
1052 1.1 drochner
1053 1.1 drochner static void ti_free_tx_ring(sc)
1054 1.1 drochner struct ti_softc *sc;
1055 1.1 drochner {
1056 1.8 augustss int i;
1057 1.1 drochner struct txdmamap_pool_entry *dma;
1058 1.1 drochner
1059 1.1 drochner if (sc->ti_rdata->ti_tx_ring == NULL)
1060 1.1 drochner return;
1061 1.1 drochner
1062 1.1 drochner for (i = 0; i < TI_TX_RING_CNT; i++) {
1063 1.1 drochner if (sc->ti_cdata.ti_tx_chain[i] != NULL) {
1064 1.1 drochner m_freem(sc->ti_cdata.ti_tx_chain[i]);
1065 1.1 drochner sc->ti_cdata.ti_tx_chain[i] = NULL;
1066 1.1 drochner
1067 1.1 drochner /* if (sc->txdma[i] == 0) panic() */
1068 1.1 drochner SIMPLEQ_INSERT_HEAD(&sc->txdma_list, sc->txdma[i],
1069 1.1 drochner link);
1070 1.1 drochner sc->txdma[i] = 0;
1071 1.1 drochner }
1072 1.1 drochner bzero((char *)&sc->ti_rdata->ti_tx_ring[i],
1073 1.1 drochner sizeof(struct ti_tx_desc));
1074 1.1 drochner }
1075 1.1 drochner
1076 1.1 drochner while ((dma = SIMPLEQ_FIRST(&sc->txdma_list))) {
1077 1.1 drochner SIMPLEQ_REMOVE_HEAD(&sc->txdma_list, dma, link);
1078 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, dma->dmamap);
1079 1.1 drochner free(dma, M_DEVBUF);
1080 1.1 drochner }
1081 1.1 drochner
1082 1.1 drochner return;
1083 1.1 drochner }
1084 1.1 drochner
1085 1.1 drochner static int ti_init_tx_ring(sc)
1086 1.1 drochner struct ti_softc *sc;
1087 1.1 drochner {
1088 1.1 drochner int i, error;
1089 1.1 drochner bus_dmamap_t dmamap;
1090 1.1 drochner struct txdmamap_pool_entry *dma;
1091 1.1 drochner
1092 1.1 drochner sc->ti_txcnt = 0;
1093 1.1 drochner sc->ti_tx_saved_considx = 0;
1094 1.1 drochner CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, 0);
1095 1.1 drochner
1096 1.1 drochner SIMPLEQ_INIT(&sc->txdma_list);
1097 1.1 drochner for (i = 0; i < TI_RSLOTS; i++) {
1098 1.1 drochner /* I've seen mbufs with 30 fragments. */
1099 1.1 drochner if ((error = bus_dmamap_create(sc->sc_dmat, TI_JUMBO_FRAMELEN,
1100 1.1 drochner 40, TI_JUMBO_FRAMELEN, 0,
1101 1.1 drochner BUS_DMA_NOWAIT, &dmamap)) != 0) {
1102 1.1 drochner printf("%s: can't create tx map, error = %d\n",
1103 1.1 drochner sc->sc_dev.dv_xname, error);
1104 1.1 drochner return(ENOMEM);
1105 1.1 drochner }
1106 1.1 drochner dma = malloc(sizeof(*dma), M_DEVBUF, M_NOWAIT);
1107 1.1 drochner if (!dma) {
1108 1.1 drochner printf("%s: can't alloc txdmamap_pool_entry\n",
1109 1.1 drochner sc->sc_dev.dv_xname);
1110 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, dmamap);
1111 1.1 drochner return (ENOMEM);
1112 1.1 drochner }
1113 1.1 drochner dma->dmamap = dmamap;
1114 1.1 drochner SIMPLEQ_INSERT_HEAD(&sc->txdma_list, dma, link);
1115 1.1 drochner }
1116 1.1 drochner
1117 1.1 drochner return(0);
1118 1.1 drochner }
1119 1.1 drochner
1120 1.1 drochner /*
1121 1.1 drochner * The Tigon 2 firmware has a new way to add/delete multicast addresses,
1122 1.1 drochner * but we have to support the old way too so that Tigon 1 cards will
1123 1.1 drochner * work.
1124 1.1 drochner */
1125 1.1 drochner void ti_add_mcast(sc, addr)
1126 1.1 drochner struct ti_softc *sc;
1127 1.1 drochner struct ether_addr *addr;
1128 1.1 drochner {
1129 1.1 drochner struct ti_cmd_desc cmd;
1130 1.1 drochner u_int16_t *m;
1131 1.1 drochner u_int32_t ext[2] = {0, 0};
1132 1.1 drochner
1133 1.1 drochner m = (u_int16_t *)&addr->ether_addr_octet[0]; /* XXX */
1134 1.1 drochner
1135 1.1 drochner switch(sc->ti_hwrev) {
1136 1.1 drochner case TI_HWREV_TIGON:
1137 1.1 drochner CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0]));
1138 1.1 drochner CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2]));
1139 1.1 drochner TI_DO_CMD(TI_CMD_ADD_MCAST_ADDR, 0, 0);
1140 1.1 drochner break;
1141 1.1 drochner case TI_HWREV_TIGON_II:
1142 1.1 drochner ext[0] = htons(m[0]);
1143 1.1 drochner ext[1] = (htons(m[1]) << 16) | htons(m[2]);
1144 1.1 drochner TI_DO_CMD_EXT(TI_CMD_EXT_ADD_MCAST, 0, 0, (caddr_t)&ext, 2);
1145 1.1 drochner break;
1146 1.1 drochner default:
1147 1.1 drochner printf("%s: unknown hwrev\n", sc->sc_dev.dv_xname);
1148 1.1 drochner break;
1149 1.1 drochner }
1150 1.1 drochner
1151 1.1 drochner return;
1152 1.1 drochner }
1153 1.1 drochner
1154 1.1 drochner void ti_del_mcast(sc, addr)
1155 1.1 drochner struct ti_softc *sc;
1156 1.1 drochner struct ether_addr *addr;
1157 1.1 drochner {
1158 1.1 drochner struct ti_cmd_desc cmd;
1159 1.1 drochner u_int16_t *m;
1160 1.1 drochner u_int32_t ext[2] = {0, 0};
1161 1.1 drochner
1162 1.1 drochner m = (u_int16_t *)&addr->ether_addr_octet[0]; /* XXX */
1163 1.1 drochner
1164 1.1 drochner switch(sc->ti_hwrev) {
1165 1.1 drochner case TI_HWREV_TIGON:
1166 1.1 drochner CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0]));
1167 1.1 drochner CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2]));
1168 1.1 drochner TI_DO_CMD(TI_CMD_DEL_MCAST_ADDR, 0, 0);
1169 1.1 drochner break;
1170 1.1 drochner case TI_HWREV_TIGON_II:
1171 1.1 drochner ext[0] = htons(m[0]);
1172 1.1 drochner ext[1] = (htons(m[1]) << 16) | htons(m[2]);
1173 1.1 drochner TI_DO_CMD_EXT(TI_CMD_EXT_DEL_MCAST, 0, 0, (caddr_t)&ext, 2);
1174 1.1 drochner break;
1175 1.1 drochner default:
1176 1.1 drochner printf("%s: unknown hwrev\n", sc->sc_dev.dv_xname);
1177 1.1 drochner break;
1178 1.1 drochner }
1179 1.1 drochner
1180 1.1 drochner return;
1181 1.1 drochner }
1182 1.1 drochner
1183 1.1 drochner /*
1184 1.1 drochner * Configure the Tigon's multicast address filter.
1185 1.1 drochner *
1186 1.1 drochner * The actual multicast table management is a bit of a pain, thanks to
1187 1.1 drochner * slight brain damage on the part of both Alteon and us. With our
1188 1.1 drochner * multicast code, we are only alerted when the multicast address table
1189 1.1 drochner * changes and at that point we only have the current list of addresses:
1190 1.1 drochner * we only know the current state, not the previous state, so we don't
1191 1.1 drochner * actually know what addresses were removed or added. The firmware has
1192 1.1 drochner * state, but we can't get our grubby mits on it, and there is no 'delete
1193 1.1 drochner * all multicast addresses' command. Hence, we have to maintain our own
1194 1.1 drochner * state so we know what addresses have been programmed into the NIC at
1195 1.1 drochner * any given time.
1196 1.1 drochner */
1197 1.1 drochner static void ti_setmulti(sc)
1198 1.1 drochner struct ti_softc *sc;
1199 1.1 drochner {
1200 1.1 drochner struct ifnet *ifp;
1201 1.1 drochner struct ti_cmd_desc cmd;
1202 1.1 drochner struct ti_mc_entry *mc;
1203 1.1 drochner u_int32_t intrs;
1204 1.1 drochner struct ether_multi *enm;
1205 1.1 drochner struct ether_multistep step;
1206 1.1 drochner
1207 1.1 drochner ifp = &sc->ethercom.ec_if;
1208 1.1 drochner
1209 1.1 drochner if (ifp->if_flags & IFF_ALLMULTI) {
1210 1.1 drochner TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_ENB, 0);
1211 1.1 drochner return;
1212 1.1 drochner } else {
1213 1.1 drochner TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_DIS, 0);
1214 1.1 drochner }
1215 1.1 drochner
1216 1.1 drochner /* Disable interrupts. */
1217 1.1 drochner intrs = CSR_READ_4(sc, TI_MB_HOSTINTR);
1218 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
1219 1.1 drochner
1220 1.1 drochner /* First, zot all the existing filters. */
1221 1.1 drochner while (SIMPLEQ_FIRST(&sc->ti_mc_listhead) != NULL) {
1222 1.1 drochner mc = SIMPLEQ_FIRST(&sc->ti_mc_listhead);
1223 1.1 drochner ti_del_mcast(sc, &mc->mc_addr);
1224 1.1 drochner SIMPLEQ_REMOVE_HEAD(&sc->ti_mc_listhead, mc, mc_entries);
1225 1.1 drochner free(mc, M_DEVBUF);
1226 1.1 drochner }
1227 1.1 drochner
1228 1.1 drochner /* Now program new ones. */
1229 1.1 drochner ETHER_FIRST_MULTI(step, &sc->ethercom, enm);
1230 1.1 drochner while (enm != NULL) {
1231 1.1 drochner mc = malloc(sizeof(struct ti_mc_entry), M_DEVBUF, M_NOWAIT);
1232 1.1 drochner bcopy(enm->enm_addrlo,
1233 1.1 drochner (char *)&mc->mc_addr, ETHER_ADDR_LEN);
1234 1.1 drochner SIMPLEQ_INSERT_HEAD(&sc->ti_mc_listhead, mc, mc_entries);
1235 1.1 drochner ti_add_mcast(sc, &mc->mc_addr);
1236 1.1 drochner ETHER_NEXT_MULTI(step, enm);
1237 1.1 drochner }
1238 1.1 drochner
1239 1.1 drochner /* Re-enable interrupts. */
1240 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, intrs);
1241 1.1 drochner
1242 1.1 drochner return;
1243 1.1 drochner }
1244 1.1 drochner
1245 1.1 drochner /*
1246 1.1 drochner * Check to see if the BIOS has configured us for a 64 bit slot when
1247 1.1 drochner * we aren't actually in one. If we detect this condition, we can work
1248 1.1 drochner * around it on the Tigon 2 by setting a bit in the PCI state register,
1249 1.1 drochner * but for the Tigon 1 we must give up and abort the interface attach.
1250 1.1 drochner */
1251 1.1 drochner static int ti_64bitslot_war(sc)
1252 1.1 drochner struct ti_softc *sc;
1253 1.1 drochner {
1254 1.1 drochner if (!(CSR_READ_4(sc, TI_PCI_STATE) & TI_PCISTATE_32BIT_BUS)) {
1255 1.1 drochner CSR_WRITE_4(sc, 0x600, 0);
1256 1.1 drochner CSR_WRITE_4(sc, 0x604, 0);
1257 1.1 drochner CSR_WRITE_4(sc, 0x600, 0x5555AAAA);
1258 1.1 drochner if (CSR_READ_4(sc, 0x604) == 0x5555AAAA) {
1259 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON)
1260 1.1 drochner return(EINVAL);
1261 1.1 drochner else {
1262 1.1 drochner TI_SETBIT(sc, TI_PCI_STATE,
1263 1.1 drochner TI_PCISTATE_32BIT_BUS);
1264 1.1 drochner return(0);
1265 1.1 drochner }
1266 1.1 drochner }
1267 1.1 drochner }
1268 1.1 drochner
1269 1.1 drochner return(0);
1270 1.1 drochner }
1271 1.1 drochner
1272 1.1 drochner /*
1273 1.1 drochner * Do endian, PCI and DMA initialization. Also check the on-board ROM
1274 1.1 drochner * self-test results.
1275 1.1 drochner */
1276 1.1 drochner static int ti_chipinit(sc)
1277 1.1 drochner struct ti_softc *sc;
1278 1.1 drochner {
1279 1.1 drochner u_int32_t cacheline;
1280 1.1 drochner u_int32_t pci_writemax = 0;
1281 1.1 drochner
1282 1.1 drochner /* Initialize link to down state. */
1283 1.1 drochner sc->ti_linkstat = TI_EV_CODE_LINK_DOWN;
1284 1.1 drochner
1285 1.1 drochner /* Set endianness before we access any non-PCI registers. */
1286 1.1 drochner #if BYTE_ORDER == BIG_ENDIAN
1287 1.1 drochner CSR_WRITE_4(sc, TI_MISC_HOST_CTL,
1288 1.1 drochner TI_MHC_BIGENDIAN_INIT | (TI_MHC_BIGENDIAN_INIT << 24));
1289 1.1 drochner #else
1290 1.1 drochner CSR_WRITE_4(sc, TI_MISC_HOST_CTL,
1291 1.1 drochner TI_MHC_LITTLEENDIAN_INIT | (TI_MHC_LITTLEENDIAN_INIT << 24));
1292 1.1 drochner #endif
1293 1.1 drochner
1294 1.1 drochner /* Check the ROM failed bit to see if self-tests passed. */
1295 1.1 drochner if (CSR_READ_4(sc, TI_CPU_STATE) & TI_CPUSTATE_ROMFAIL) {
1296 1.1 drochner printf("%s: board self-diagnostics failed!\n",
1297 1.1 drochner sc->sc_dev.dv_xname);
1298 1.1 drochner return(ENODEV);
1299 1.1 drochner }
1300 1.1 drochner
1301 1.1 drochner /* Halt the CPU. */
1302 1.1 drochner TI_SETBIT(sc, TI_CPU_STATE, TI_CPUSTATE_HALT);
1303 1.1 drochner
1304 1.1 drochner /* Figure out the hardware revision. */
1305 1.1 drochner switch(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_CHIP_REV_MASK) {
1306 1.1 drochner case TI_REV_TIGON_I:
1307 1.1 drochner sc->ti_hwrev = TI_HWREV_TIGON;
1308 1.1 drochner break;
1309 1.1 drochner case TI_REV_TIGON_II:
1310 1.1 drochner sc->ti_hwrev = TI_HWREV_TIGON_II;
1311 1.1 drochner break;
1312 1.1 drochner default:
1313 1.1 drochner printf("%s: unsupported chip revision\n", sc->sc_dev.dv_xname);
1314 1.1 drochner return(ENODEV);
1315 1.1 drochner }
1316 1.1 drochner
1317 1.1 drochner /* Do special setup for Tigon 2. */
1318 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
1319 1.1 drochner TI_SETBIT(sc, TI_CPU_CTL_B, TI_CPUSTATE_HALT);
1320 1.1 drochner TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_SRAM_BANK_256K);
1321 1.1 drochner TI_SETBIT(sc, TI_MISC_CONF, TI_MCR_SRAM_SYNCHRONOUS);
1322 1.1 drochner }
1323 1.1 drochner
1324 1.1 drochner /* Set up the PCI state register. */
1325 1.1 drochner CSR_WRITE_4(sc, TI_PCI_STATE, TI_PCI_READ_CMD|TI_PCI_WRITE_CMD);
1326 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
1327 1.1 drochner TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_USE_MEM_RD_MULT);
1328 1.1 drochner }
1329 1.1 drochner
1330 1.1 drochner /* Clear the read/write max DMA parameters. */
1331 1.1 drochner TI_CLRBIT(sc, TI_PCI_STATE, (TI_PCISTATE_WRITE_MAXDMA|
1332 1.1 drochner TI_PCISTATE_READ_MAXDMA));
1333 1.1 drochner
1334 1.1 drochner /* Get cache line size. */
1335 1.1 drochner cacheline = PCI_CACHELINE(CSR_READ_4(sc, PCI_BHLC_REG));
1336 1.1 drochner
1337 1.1 drochner /*
1338 1.1 drochner * If the system has set enabled the PCI memory write
1339 1.1 drochner * and invalidate command in the command register, set
1340 1.1 drochner * the write max parameter accordingly. This is necessary
1341 1.1 drochner * to use MWI with the Tigon 2.
1342 1.1 drochner */
1343 1.1 drochner if (CSR_READ_4(sc, PCI_COMMAND_STATUS_REG)
1344 1.1 drochner & PCI_COMMAND_INVALIDATE_ENABLE) {
1345 1.1 drochner switch(cacheline) {
1346 1.1 drochner case 1:
1347 1.1 drochner case 4:
1348 1.1 drochner case 8:
1349 1.1 drochner case 16:
1350 1.1 drochner case 32:
1351 1.1 drochner case 64:
1352 1.1 drochner break;
1353 1.1 drochner default:
1354 1.1 drochner /* Disable PCI memory write and invalidate. */
1355 1.1 drochner if (bootverbose)
1356 1.1 drochner printf("%s: cache line size %d not "
1357 1.1 drochner "supported; disabling PCI MWI\n",
1358 1.1 drochner sc->sc_dev.dv_xname, cacheline);
1359 1.1 drochner CSR_WRITE_4(sc, PCI_COMMAND_STATUS_REG,
1360 1.1 drochner CSR_READ_4(sc, PCI_COMMAND_STATUS_REG)
1361 1.1 drochner & ~PCI_COMMAND_INVALIDATE_ENABLE);
1362 1.1 drochner break;
1363 1.1 drochner }
1364 1.1 drochner }
1365 1.1 drochner
1366 1.1 drochner #ifdef __brokenalpha__
1367 1.1 drochner /*
1368 1.1 drochner * From the Alteon sample driver:
1369 1.1 drochner * Must insure that we do not cross an 8K (bytes) boundary
1370 1.1 drochner * for DMA reads. Our highest limit is 1K bytes. This is a
1371 1.1 drochner * restriction on some ALPHA platforms with early revision
1372 1.1 drochner * 21174 PCI chipsets, such as the AlphaPC 164lx
1373 1.1 drochner */
1374 1.1 drochner TI_SETBIT(sc, TI_PCI_STATE, pci_writemax|TI_PCI_READMAX_1024);
1375 1.1 drochner #else
1376 1.1 drochner TI_SETBIT(sc, TI_PCI_STATE, pci_writemax);
1377 1.1 drochner #endif
1378 1.1 drochner
1379 1.1 drochner /* This sets the min dma param all the way up (0xff). */
1380 1.1 drochner TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_MINDMA);
1381 1.1 drochner
1382 1.1 drochner /* Configure DMA variables. */
1383 1.1 drochner #if BYTE_ORDER == BIG_ENDIAN
1384 1.1 drochner CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_BD |
1385 1.1 drochner TI_OPMODE_BYTESWAP_DATA | TI_OPMODE_WORDSWAP_BD |
1386 1.1 drochner TI_OPMODE_WARN_ENB | TI_OPMODE_FATAL_ENB |
1387 1.1 drochner TI_OPMODE_DONT_FRAG_JUMBO);
1388 1.1 drochner #else
1389 1.1 drochner CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_DATA|
1390 1.1 drochner TI_OPMODE_WORDSWAP_BD|TI_OPMODE_DONT_FRAG_JUMBO|
1391 1.1 drochner TI_OPMODE_WARN_ENB|TI_OPMODE_FATAL_ENB);
1392 1.1 drochner #endif
1393 1.1 drochner
1394 1.1 drochner /*
1395 1.1 drochner * Only allow 1 DMA channel to be active at a time.
1396 1.1 drochner * I don't think this is a good idea, but without it
1397 1.1 drochner * the firmware racks up lots of nicDmaReadRingFull
1398 1.1 drochner * errors.
1399 1.1 drochner */
1400 1.1 drochner #ifndef TI_CSUM_OFFLOAD
1401 1.1 drochner TI_SETBIT(sc, TI_GCR_OPMODE, TI_OPMODE_1_DMA_ACTIVE);
1402 1.1 drochner #endif
1403 1.1 drochner
1404 1.1 drochner /* Recommended settings from Tigon manual. */
1405 1.1 drochner CSR_WRITE_4(sc, TI_GCR_DMA_WRITECFG, TI_DMA_STATE_THRESH_8W);
1406 1.1 drochner CSR_WRITE_4(sc, TI_GCR_DMA_READCFG, TI_DMA_STATE_THRESH_8W);
1407 1.1 drochner
1408 1.1 drochner if (ti_64bitslot_war(sc)) {
1409 1.1 drochner printf("%s: bios thinks we're in a 64 bit slot, "
1410 1.1 drochner "but we aren't", sc->sc_dev.dv_xname);
1411 1.1 drochner return(EINVAL);
1412 1.1 drochner }
1413 1.1 drochner
1414 1.1 drochner return(0);
1415 1.1 drochner }
1416 1.1 drochner
1417 1.1 drochner /*
1418 1.1 drochner * Initialize the general information block and firmware, and
1419 1.1 drochner * start the CPU(s) running.
1420 1.1 drochner */
1421 1.1 drochner static int ti_gibinit(sc)
1422 1.1 drochner struct ti_softc *sc;
1423 1.1 drochner {
1424 1.1 drochner struct ti_rcb *rcb;
1425 1.1 drochner int i;
1426 1.1 drochner struct ifnet *ifp;
1427 1.1 drochner
1428 1.1 drochner ifp = &sc->ethercom.ec_if;
1429 1.1 drochner
1430 1.1 drochner /* Disable interrupts for now. */
1431 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
1432 1.1 drochner
1433 1.1 drochner /* Tell the chip where to find the general information block. */
1434 1.1 drochner CSR_WRITE_4(sc, TI_GCR_GENINFO_HI, 0);
1435 1.1 drochner CSR_WRITE_4(sc, TI_GCR_GENINFO_LO, sc->info_dmaaddr +
1436 1.1 drochner ((caddr_t)&sc->ti_rdata->ti_info - (caddr_t)sc->ti_rdata));
1437 1.1 drochner
1438 1.1 drochner /* Load the firmware into SRAM. */
1439 1.1 drochner ti_loadfw(sc);
1440 1.1 drochner
1441 1.1 drochner /* Set up the contents of the general info and ring control blocks. */
1442 1.1 drochner
1443 1.1 drochner /* Set up the event ring and producer pointer. */
1444 1.1 drochner rcb = &sc->ti_rdata->ti_info.ti_ev_rcb;
1445 1.1 drochner
1446 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
1447 1.1 drochner ((caddr_t)&sc->ti_rdata->ti_event_ring - (caddr_t)sc->ti_rdata);
1448 1.1 drochner rcb->ti_flags = 0;
1449 1.1 drochner TI_HOSTADDR(sc->ti_rdata->ti_info.ti_ev_prodidx_ptr) =
1450 1.1 drochner sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_ev_prodidx_r
1451 1.1 drochner - (caddr_t)sc->ti_rdata);
1452 1.1 drochner sc->ti_ev_prodidx.ti_idx = 0;
1453 1.1 drochner CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, 0);
1454 1.1 drochner sc->ti_ev_saved_considx = 0;
1455 1.1 drochner
1456 1.1 drochner /* Set up the command ring and producer mailbox. */
1457 1.1 drochner rcb = &sc->ti_rdata->ti_info.ti_cmd_rcb;
1458 1.1 drochner
1459 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = TI_GCR_NIC_ADDR(TI_GCR_CMDRING);
1460 1.1 drochner rcb->ti_flags = 0;
1461 1.1 drochner rcb->ti_max_len = 0;
1462 1.1 drochner for (i = 0; i < TI_CMD_RING_CNT; i++) {
1463 1.1 drochner CSR_WRITE_4(sc, TI_GCR_CMDRING + (i * 4), 0);
1464 1.1 drochner }
1465 1.1 drochner CSR_WRITE_4(sc, TI_GCR_CMDCONS_IDX, 0);
1466 1.1 drochner CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, 0);
1467 1.1 drochner sc->ti_cmd_saved_prodidx = 0;
1468 1.1 drochner
1469 1.1 drochner /*
1470 1.1 drochner * Assign the address of the stats refresh buffer.
1471 1.1 drochner * We re-use the current stats buffer for this to
1472 1.1 drochner * conserve memory.
1473 1.1 drochner */
1474 1.1 drochner TI_HOSTADDR(sc->ti_rdata->ti_info.ti_refresh_stats_ptr) =
1475 1.1 drochner sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_info.ti_stats
1476 1.1 drochner - (caddr_t)sc->ti_rdata);
1477 1.1 drochner
1478 1.1 drochner /* Set up the standard receive ring. */
1479 1.1 drochner rcb = &sc->ti_rdata->ti_info.ti_std_rx_rcb;
1480 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
1481 1.1 drochner ((caddr_t)&sc->ti_rdata->ti_rx_std_ring
1482 1.1 drochner - (caddr_t)sc->ti_rdata);
1483 1.1 drochner rcb->ti_max_len = TI_FRAMELEN;
1484 1.1 drochner rcb->ti_flags = 0;
1485 1.1 drochner #ifdef TI_CSUM_OFFLOAD
1486 1.1 drochner rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;
1487 1.1 drochner #endif
1488 1.1 drochner #if NVLAN > 0
1489 1.1 drochner rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
1490 1.1 drochner #endif
1491 1.1 drochner
1492 1.1 drochner /* Set up the jumbo receive ring. */
1493 1.1 drochner rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
1494 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
1495 1.1 drochner ((caddr_t)&sc->ti_rdata->ti_rx_jumbo_ring - (caddr_t)sc->ti_rdata);
1496 1.1 drochner rcb->ti_max_len = TI_JUMBO_FRAMELEN;
1497 1.1 drochner rcb->ti_flags = 0;
1498 1.1 drochner #ifdef TI_CSUM_OFFLOAD
1499 1.1 drochner rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;
1500 1.1 drochner #endif
1501 1.1 drochner #if NVLAN > 0
1502 1.1 drochner rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
1503 1.1 drochner #endif
1504 1.1 drochner
1505 1.1 drochner /*
1506 1.1 drochner * Set up the mini ring. Only activated on the
1507 1.1 drochner * Tigon 2 but the slot in the config block is
1508 1.1 drochner * still there on the Tigon 1.
1509 1.1 drochner */
1510 1.1 drochner rcb = &sc->ti_rdata->ti_info.ti_mini_rx_rcb;
1511 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
1512 1.1 drochner ((caddr_t)&sc->ti_rdata->ti_rx_mini_ring - (caddr_t)sc->ti_rdata);
1513 1.2 drochner rcb->ti_max_len = MHLEN - ETHER_ALIGN;
1514 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON)
1515 1.1 drochner rcb->ti_flags = TI_RCB_FLAG_RING_DISABLED;
1516 1.1 drochner else
1517 1.1 drochner rcb->ti_flags = 0;
1518 1.1 drochner #ifdef TI_CSUM_OFFLOAD
1519 1.1 drochner rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;
1520 1.1 drochner #endif
1521 1.1 drochner #if NVLAN > 0
1522 1.1 drochner rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
1523 1.1 drochner #endif
1524 1.1 drochner
1525 1.1 drochner /*
1526 1.1 drochner * Set up the receive return ring.
1527 1.1 drochner */
1528 1.1 drochner rcb = &sc->ti_rdata->ti_info.ti_return_rcb;
1529 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
1530 1.1 drochner ((caddr_t)&sc->ti_rdata->ti_rx_return_ring - (caddr_t)sc->ti_rdata);
1531 1.1 drochner rcb->ti_flags = 0;
1532 1.1 drochner rcb->ti_max_len = TI_RETURN_RING_CNT;
1533 1.1 drochner TI_HOSTADDR(sc->ti_rdata->ti_info.ti_return_prodidx_ptr) =
1534 1.1 drochner sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_return_prodidx_r
1535 1.1 drochner - (caddr_t)sc->ti_rdata);
1536 1.1 drochner
1537 1.1 drochner /*
1538 1.1 drochner * Set up the tx ring. Note: for the Tigon 2, we have the option
1539 1.1 drochner * of putting the transmit ring in the host's address space and
1540 1.1 drochner * letting the chip DMA it instead of leaving the ring in the NIC's
1541 1.1 drochner * memory and accessing it through the shared memory region. We
1542 1.1 drochner * do this for the Tigon 2, but it doesn't work on the Tigon 1,
1543 1.1 drochner * so we have to revert to the shared memory scheme if we detect
1544 1.1 drochner * a Tigon 1 chip.
1545 1.1 drochner */
1546 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE, TI_TX_RING_BASE);
1547 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON) {
1548 1.1 drochner sc->ti_rdata->ti_tx_ring_nic =
1549 1.1 drochner (struct ti_tx_desc *)(sc->ti_vhandle + TI_WINDOW);
1550 1.1 drochner }
1551 1.1 drochner bzero((char *)sc->ti_rdata->ti_tx_ring,
1552 1.1 drochner TI_TX_RING_CNT * sizeof(struct ti_tx_desc));
1553 1.1 drochner rcb = &sc->ti_rdata->ti_info.ti_tx_rcb;
1554 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON)
1555 1.1 drochner rcb->ti_flags = 0;
1556 1.1 drochner else
1557 1.1 drochner rcb->ti_flags = TI_RCB_FLAG_HOST_RING;
1558 1.1 drochner #if NVLAN > 0
1559 1.1 drochner rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
1560 1.1 drochner #endif
1561 1.1 drochner rcb->ti_max_len = TI_TX_RING_CNT;
1562 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON)
1563 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = TI_TX_RING_BASE;
1564 1.1 drochner else
1565 1.1 drochner TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
1566 1.1 drochner ((caddr_t)&sc->ti_rdata->ti_tx_ring
1567 1.1 drochner - (caddr_t)sc->ti_rdata);
1568 1.1 drochner TI_HOSTADDR(sc->ti_rdata->ti_info.ti_tx_considx_ptr) =
1569 1.1 drochner sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_tx_considx_r
1570 1.1 drochner - (caddr_t)sc->ti_rdata);
1571 1.1 drochner
1572 1.1 drochner /* Set up tuneables */
1573 1.1 drochner if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
1574 1.1 drochner CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS,
1575 1.1 drochner (sc->ti_rx_coal_ticks / 10));
1576 1.1 drochner else
1577 1.1 drochner CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS, sc->ti_rx_coal_ticks);
1578 1.1 drochner CSR_WRITE_4(sc, TI_GCR_TX_COAL_TICKS, sc->ti_tx_coal_ticks);
1579 1.1 drochner CSR_WRITE_4(sc, TI_GCR_STAT_TICKS, sc->ti_stat_ticks);
1580 1.1 drochner CSR_WRITE_4(sc, TI_GCR_RX_MAX_COAL_BD, sc->ti_rx_max_coal_bds);
1581 1.1 drochner CSR_WRITE_4(sc, TI_GCR_TX_MAX_COAL_BD, sc->ti_tx_max_coal_bds);
1582 1.1 drochner CSR_WRITE_4(sc, TI_GCR_TX_BUFFER_RATIO, sc->ti_tx_buf_ratio);
1583 1.1 drochner
1584 1.1 drochner /* Turn interrupts on. */
1585 1.1 drochner CSR_WRITE_4(sc, TI_GCR_MASK_INTRS, 0);
1586 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
1587 1.1 drochner
1588 1.1 drochner /* Start CPU. */
1589 1.1 drochner TI_CLRBIT(sc, TI_CPU_STATE, (TI_CPUSTATE_HALT|TI_CPUSTATE_STEP));
1590 1.1 drochner
1591 1.1 drochner return(0);
1592 1.1 drochner }
1593 1.1 drochner
1594 1.1 drochner /*
1595 1.6 bouyer * look for id in the device list, returning the first match
1596 1.6 bouyer */
1597 1.6 bouyer static struct ti_type * ti_type_match(pa)
1598 1.6 bouyer struct pci_attach_args *pa;
1599 1.6 bouyer {
1600 1.6 bouyer struct ti_type *t;
1601 1.6 bouyer
1602 1.6 bouyer t = ti_devs;
1603 1.6 bouyer while(t->ti_name != NULL) {
1604 1.6 bouyer if ((PCI_VENDOR(pa->pa_id) == t->ti_vid) &&
1605 1.6 bouyer (PCI_PRODUCT(pa->pa_id) == t->ti_did)) {
1606 1.6 bouyer return (t);
1607 1.6 bouyer }
1608 1.6 bouyer t++;
1609 1.6 bouyer }
1610 1.6 bouyer
1611 1.6 bouyer return(NULL);
1612 1.6 bouyer }
1613 1.6 bouyer
1614 1.6 bouyer /*
1615 1.1 drochner * Probe for a Tigon chip. Check the PCI vendor and device IDs
1616 1.1 drochner * against our list and return its name if we find a match.
1617 1.1 drochner */
1618 1.1 drochner static int ti_probe(parent, match, aux)
1619 1.1 drochner struct device *parent;
1620 1.1 drochner struct cfdata *match;
1621 1.1 drochner void *aux;
1622 1.1 drochner {
1623 1.1 drochner struct pci_attach_args *pa = aux;
1624 1.1 drochner struct ti_type *t;
1625 1.1 drochner
1626 1.6 bouyer t = ti_type_match(pa);
1627 1.1 drochner
1628 1.6 bouyer return((t == NULL) ? 0 : 1);
1629 1.1 drochner }
1630 1.1 drochner
1631 1.1 drochner static void ti_attach(parent, self, aux)
1632 1.1 drochner struct device *parent, *self;
1633 1.1 drochner void *aux;
1634 1.1 drochner {
1635 1.1 drochner u_int32_t command;
1636 1.1 drochner struct ifnet *ifp;
1637 1.1 drochner struct ti_softc *sc;
1638 1.1 drochner u_char eaddr[ETHER_ADDR_LEN];
1639 1.1 drochner struct pci_attach_args *pa = aux;
1640 1.1 drochner pci_chipset_tag_t pc = pa->pa_pc;
1641 1.1 drochner pci_intr_handle_t ih;
1642 1.1 drochner const char *intrstr = NULL;
1643 1.1 drochner bus_dma_segment_t dmaseg;
1644 1.6 bouyer int error, dmanseg, nolinear;
1645 1.6 bouyer struct ti_type *t;
1646 1.6 bouyer
1647 1.6 bouyer t = ti_type_match(pa);
1648 1.6 bouyer if (t == NULL) {
1649 1.6 bouyer printf("ti_attach: were did the card go ?\n");
1650 1.6 bouyer return;
1651 1.6 bouyer }
1652 1.1 drochner
1653 1.6 bouyer printf(": %s (rev. 0x%02x)\n", t->ti_name, PCI_REVISION(pa->pa_class));
1654 1.1 drochner
1655 1.1 drochner sc = (struct ti_softc *)self;
1656 1.1 drochner
1657 1.1 drochner /*
1658 1.1 drochner * Map control/status registers.
1659 1.1 drochner */
1660 1.6 bouyer nolinear = 0;
1661 1.6 bouyer if (pci_mapreg_map(pa, 0x10,
1662 1.6 bouyer PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
1663 1.6 bouyer BUS_SPACE_MAP_LINEAR , &sc->ti_btag, &sc->ti_bhandle,
1664 1.6 bouyer NULL, NULL)) {
1665 1.6 bouyer nolinear = 1;
1666 1.6 bouyer if (pci_mapreg_map(pa, 0x10,
1667 1.6 bouyer PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
1668 1.6 bouyer 0 , &sc->ti_btag, &sc->ti_bhandle, NULL, NULL)) {
1669 1.6 bouyer printf(": can't map memory space\n");
1670 1.6 bouyer return;
1671 1.6 bouyer }
1672 1.1 drochner }
1673 1.6 bouyer if (nolinear == 0)
1674 1.6 bouyer sc->ti_vhandle = (void *)(sc->ti_bhandle); /* XXX XXX XXX */
1675 1.6 bouyer else
1676 1.6 bouyer sc->ti_vhandle = NULL;
1677 1.1 drochner
1678 1.1 drochner command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
1679 1.1 drochner command |= PCI_COMMAND_MASTER_ENABLE;
1680 1.1 drochner pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
1681 1.1 drochner
1682 1.1 drochner /* Allocate interrupt */
1683 1.1 drochner if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
1684 1.1 drochner pa->pa_intrline, &ih)) {
1685 1.1 drochner printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
1686 1.6 bouyer return;;
1687 1.1 drochner }
1688 1.1 drochner intrstr = pci_intr_string(pc, ih);
1689 1.1 drochner sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ti_intr, sc);
1690 1.1 drochner if (sc->sc_ih == NULL) {
1691 1.1 drochner printf("%s: couldn't establish interrupt",
1692 1.1 drochner sc->sc_dev.dv_xname);
1693 1.1 drochner if (intrstr != NULL)
1694 1.1 drochner printf(" at %s", intrstr);
1695 1.1 drochner printf("\n");
1696 1.6 bouyer return;;
1697 1.1 drochner }
1698 1.6 bouyer printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
1699 1.6 bouyer /*
1700 1.6 bouyer * Add shutdown hook so that DMA is disabled prior to reboot. Not
1701 1.6 bouyer * doing do could allow DMA to corrupt kernel memory during the
1702 1.6 bouyer * reboot before the driver initializes.
1703 1.6 bouyer */
1704 1.6 bouyer (void) shutdownhook_establish(ti_shutdown, sc);
1705 1.1 drochner
1706 1.1 drochner if (ti_chipinit(sc)) {
1707 1.1 drochner printf("%s: chip initialization failed\n", self->dv_xname);
1708 1.6 bouyer goto fail2;
1709 1.6 bouyer }
1710 1.6 bouyer if (sc->ti_hwrev == TI_HWREV_TIGON && nolinear == 1) {
1711 1.6 bouyer printf("%s: memory space not mapped linear\n", self->dv_xname);
1712 1.1 drochner }
1713 1.1 drochner
1714 1.1 drochner /* Zero out the NIC's on-board SRAM. */
1715 1.1 drochner ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL);
1716 1.1 drochner
1717 1.1 drochner /* Init again -- zeroing memory may have clobbered some registers. */
1718 1.1 drochner if (ti_chipinit(sc)) {
1719 1.1 drochner printf("%s: chip initialization failed\n", self->dv_xname);
1720 1.6 bouyer goto fail2;
1721 1.1 drochner }
1722 1.1 drochner
1723 1.1 drochner /*
1724 1.1 drochner * Get station address from the EEPROM. Note: the manual states
1725 1.1 drochner * that the MAC address is at offset 0x8c, however the data is
1726 1.1 drochner * stored as two longwords (since that's how it's loaded into
1727 1.1 drochner * the NIC). This means the MAC address is actually preceeded
1728 1.1 drochner * by two zero bytes. We need to skip over those.
1729 1.1 drochner */
1730 1.1 drochner if (ti_read_eeprom(sc, (caddr_t)&eaddr,
1731 1.1 drochner TI_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) {
1732 1.1 drochner printf("%s: failed to read station address\n", self->dv_xname);
1733 1.6 bouyer goto fail2;
1734 1.1 drochner }
1735 1.1 drochner
1736 1.1 drochner /*
1737 1.1 drochner * A Tigon chip was detected. Inform the world.
1738 1.1 drochner */
1739 1.1 drochner printf("%s: Ethernet address: %s\n", self->dv_xname,
1740 1.1 drochner ether_sprintf(eaddr));
1741 1.1 drochner
1742 1.1 drochner sc->sc_dmat = pa->pa_dmat;
1743 1.1 drochner
1744 1.1 drochner /* Allocate the general information block and ring buffers. */
1745 1.1 drochner if ((error = bus_dmamem_alloc(sc->sc_dmat,
1746 1.1 drochner sizeof(struct ti_ring_data), NBPG, 0, &dmaseg, 1, &dmanseg,
1747 1.1 drochner BUS_DMA_NOWAIT)) != 0) {
1748 1.1 drochner printf("%s: can't allocate ring buffer, error = %d\n",
1749 1.1 drochner sc->sc_dev.dv_xname, error);
1750 1.6 bouyer goto fail2;
1751 1.1 drochner }
1752 1.1 drochner
1753 1.1 drochner if ((error = bus_dmamem_map(sc->sc_dmat, &dmaseg, dmanseg,
1754 1.1 drochner sizeof(struct ti_ring_data), (caddr_t *)&sc->ti_rdata,
1755 1.1 drochner BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
1756 1.1 drochner printf("%s: can't map ring buffer, error = %d\n",
1757 1.1 drochner sc->sc_dev.dv_xname, error);
1758 1.6 bouyer goto fail2;
1759 1.1 drochner }
1760 1.1 drochner
1761 1.1 drochner if ((error = bus_dmamap_create(sc->sc_dmat,
1762 1.1 drochner sizeof(struct ti_ring_data), 1,
1763 1.1 drochner sizeof(struct ti_ring_data), 0, BUS_DMA_NOWAIT,
1764 1.1 drochner &sc->info_dmamap)) != 0) {
1765 1.1 drochner printf("%s: can't create ring buffer DMA map, error = %d\n",
1766 1.1 drochner sc->sc_dev.dv_xname, error);
1767 1.6 bouyer goto fail2;
1768 1.1 drochner }
1769 1.1 drochner
1770 1.1 drochner if ((error = bus_dmamap_load(sc->sc_dmat, sc->info_dmamap,
1771 1.1 drochner sc->ti_rdata, sizeof(struct ti_ring_data), NULL,
1772 1.1 drochner BUS_DMA_NOWAIT)) != 0) {
1773 1.1 drochner printf("%s: can't load ring buffer DMA map, error = %d\n",
1774 1.1 drochner sc->sc_dev.dv_xname, error);
1775 1.6 bouyer goto fail2;
1776 1.1 drochner }
1777 1.1 drochner
1778 1.1 drochner sc->info_dmaaddr = sc->info_dmamap->dm_segs[0].ds_addr;
1779 1.1 drochner
1780 1.1 drochner bzero(sc->ti_rdata, sizeof(struct ti_ring_data));
1781 1.1 drochner
1782 1.1 drochner /* Try to allocate memory for jumbo buffers. */
1783 1.1 drochner if (ti_alloc_jumbo_mem(sc)) {
1784 1.1 drochner printf("%s: jumbo buffer allocation failed\n", self->dv_xname);
1785 1.6 bouyer goto fail2;
1786 1.1 drochner }
1787 1.1 drochner
1788 1.1 drochner /* Set default tuneable values. */
1789 1.1 drochner sc->ti_stat_ticks = 2 * TI_TICKS_PER_SEC;
1790 1.1 drochner sc->ti_rx_coal_ticks = TI_TICKS_PER_SEC / 5000;
1791 1.1 drochner sc->ti_tx_coal_ticks = TI_TICKS_PER_SEC / 500;
1792 1.1 drochner sc->ti_rx_max_coal_bds = 64;
1793 1.1 drochner sc->ti_tx_max_coal_bds = 128;
1794 1.1 drochner sc->ti_tx_buf_ratio = 21;
1795 1.1 drochner
1796 1.1 drochner /* Set up ifnet structure */
1797 1.1 drochner ifp = &sc->ethercom.ec_if;
1798 1.1 drochner ifp->if_softc = sc;
1799 1.1 drochner bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
1800 1.1 drochner ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1801 1.1 drochner ifp->if_ioctl = ti_ioctl;
1802 1.1 drochner ifp->if_start = ti_start;
1803 1.1 drochner ifp->if_watchdog = ti_watchdog;
1804 1.1 drochner ifp->if_snd.ifq_maxlen = TI_TX_RING_CNT - 1;
1805 1.1 drochner
1806 1.1 drochner /* Set up ifmedia support. */
1807 1.1 drochner ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts);
1808 1.1 drochner ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_FL, 0, NULL);
1809 1.1 drochner ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_FL|IFM_FDX, 0, NULL);
1810 1.1 drochner ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_FX, 0, NULL);
1811 1.1 drochner ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_FX|IFM_FDX, 0, NULL);
1812 1.3 thorpej ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL);
1813 1.3 thorpej ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL);
1814 1.1 drochner ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
1815 1.1 drochner ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO);
1816 1.1 drochner
1817 1.1 drochner /*
1818 1.1 drochner * Call MI attach routines.
1819 1.1 drochner */
1820 1.1 drochner if_attach(ifp);
1821 1.1 drochner ether_ifattach(ifp, eaddr);
1822 1.1 drochner
1823 1.1 drochner #if NBPFILTER > 0
1824 1.1 drochner bpfattach(&sc->ethercom.ec_if.if_bpf, ifp, DLT_EN10MB,
1825 1.1 drochner sizeof(struct ether_header));
1826 1.1 drochner #endif
1827 1.1 drochner
1828 1.6 bouyer return;
1829 1.6 bouyer fail2:
1830 1.6 bouyer pci_intr_disestablish(pc, sc->sc_ih);
1831 1.6 bouyer return;
1832 1.1 drochner }
1833 1.1 drochner
1834 1.1 drochner /*
1835 1.1 drochner * Frame reception handling. This is called if there's a frame
1836 1.1 drochner * on the receive return list.
1837 1.1 drochner *
1838 1.1 drochner * Note: we have to be able to handle three possibilities here:
1839 1.1 drochner * 1) the frame is from the mini receive ring (can only happen)
1840 1.1 drochner * on Tigon 2 boards)
1841 1.1 drochner * 2) the frame is from the jumbo recieve ring
1842 1.1 drochner * 3) the frame is from the standard receive ring
1843 1.1 drochner */
1844 1.1 drochner
1845 1.1 drochner static void ti_rxeof(sc)
1846 1.1 drochner struct ti_softc *sc;
1847 1.1 drochner {
1848 1.1 drochner struct ifnet *ifp;
1849 1.1 drochner struct ti_cmd_desc cmd;
1850 1.1 drochner
1851 1.1 drochner ifp = &sc->ethercom.ec_if;
1852 1.1 drochner
1853 1.1 drochner while(sc->ti_rx_saved_considx != sc->ti_return_prodidx.ti_idx) {
1854 1.1 drochner struct ti_rx_desc *cur_rx;
1855 1.1 drochner u_int32_t rxidx;
1856 1.1 drochner struct ether_header *eh;
1857 1.1 drochner struct mbuf *m = NULL;
1858 1.1 drochner #if NVLAN > 0
1859 1.1 drochner u_int16_t vlan_tag = 0;
1860 1.1 drochner int have_tag = 0;
1861 1.1 drochner #endif
1862 1.1 drochner #ifdef TI_CSUM_OFFLOAD
1863 1.1 drochner struct ip *ip;
1864 1.1 drochner #endif
1865 1.1 drochner bus_dmamap_t dmamap;
1866 1.1 drochner
1867 1.1 drochner cur_rx =
1868 1.1 drochner &sc->ti_rdata->ti_rx_return_ring[sc->ti_rx_saved_considx];
1869 1.1 drochner rxidx = cur_rx->ti_idx;
1870 1.1 drochner TI_INC(sc->ti_rx_saved_considx, TI_RETURN_RING_CNT);
1871 1.1 drochner
1872 1.1 drochner #if NVLAN > 0
1873 1.1 drochner if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) {
1874 1.1 drochner have_tag = 1;
1875 1.1 drochner vlan_tag = cur_rx->ti_vlan_tag;
1876 1.1 drochner }
1877 1.1 drochner #endif
1878 1.1 drochner
1879 1.1 drochner if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) {
1880 1.1 drochner TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT);
1881 1.1 drochner m = sc->ti_cdata.ti_rx_jumbo_chain[rxidx];
1882 1.1 drochner sc->ti_cdata.ti_rx_jumbo_chain[rxidx] = NULL;
1883 1.1 drochner if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
1884 1.1 drochner ifp->if_ierrors++;
1885 1.1 drochner ti_newbuf_jumbo(sc, sc->ti_jumbo, m);
1886 1.1 drochner continue;
1887 1.1 drochner }
1888 1.1 drochner if (ti_newbuf_jumbo(sc, sc->ti_jumbo, NULL)
1889 1.1 drochner == ENOBUFS) {
1890 1.1 drochner ifp->if_ierrors++;
1891 1.1 drochner ti_newbuf_jumbo(sc, sc->ti_jumbo, m);
1892 1.1 drochner continue;
1893 1.1 drochner }
1894 1.1 drochner } else if (cur_rx->ti_flags & TI_BDFLAG_MINI_RING) {
1895 1.1 drochner TI_INC(sc->ti_mini, TI_MINI_RX_RING_CNT);
1896 1.1 drochner m = sc->ti_cdata.ti_rx_mini_chain[rxidx];
1897 1.1 drochner sc->ti_cdata.ti_rx_mini_chain[rxidx] = NULL;
1898 1.1 drochner dmamap = sc->mini_dmamap[rxidx];
1899 1.1 drochner sc->mini_dmamap[rxidx] = 0;
1900 1.1 drochner if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
1901 1.1 drochner ifp->if_ierrors++;
1902 1.1 drochner ti_newbuf_mini(sc, sc->ti_mini, m, dmamap);
1903 1.1 drochner continue;
1904 1.1 drochner }
1905 1.1 drochner if (ti_newbuf_mini(sc, sc->ti_mini, NULL, dmamap)
1906 1.1 drochner == ENOBUFS) {
1907 1.1 drochner ifp->if_ierrors++;
1908 1.1 drochner ti_newbuf_mini(sc, sc->ti_mini, m, dmamap);
1909 1.1 drochner continue;
1910 1.1 drochner }
1911 1.1 drochner } else {
1912 1.1 drochner TI_INC(sc->ti_std, TI_STD_RX_RING_CNT);
1913 1.1 drochner m = sc->ti_cdata.ti_rx_std_chain[rxidx];
1914 1.1 drochner sc->ti_cdata.ti_rx_std_chain[rxidx] = NULL;
1915 1.1 drochner dmamap = sc->std_dmamap[rxidx];
1916 1.1 drochner sc->std_dmamap[rxidx] = 0;
1917 1.1 drochner if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
1918 1.1 drochner ifp->if_ierrors++;
1919 1.1 drochner ti_newbuf_std(sc, sc->ti_std, m, dmamap);
1920 1.1 drochner continue;
1921 1.1 drochner }
1922 1.1 drochner if (ti_newbuf_std(sc, sc->ti_std, NULL, dmamap)
1923 1.1 drochner == ENOBUFS) {
1924 1.1 drochner ifp->if_ierrors++;
1925 1.1 drochner ti_newbuf_std(sc, sc->ti_std, m, dmamap);
1926 1.1 drochner continue;
1927 1.1 drochner }
1928 1.1 drochner }
1929 1.1 drochner
1930 1.1 drochner m->m_pkthdr.len = m->m_len = cur_rx->ti_len;
1931 1.1 drochner ifp->if_ipackets++;
1932 1.1 drochner eh = mtod(m, struct ether_header *);
1933 1.1 drochner m->m_pkthdr.rcvif = ifp;
1934 1.1 drochner
1935 1.1 drochner #if NBPFILTER > 0
1936 1.1 drochner /*
1937 1.1 drochner * Handle BPF listeners. Let the BPF user see the packet, but
1938 1.1 drochner * don't pass it up to the ether_input() layer unless it's
1939 1.1 drochner * a broadcast packet, multicast packet, matches our ethernet
1940 1.1 drochner * address or the interface is in promiscuous mode.
1941 1.1 drochner */
1942 1.1 drochner if (ifp->if_bpf) {
1943 1.1 drochner bpf_mtap(ifp->if_bpf, m);
1944 1.1 drochner if (ifp->if_flags & IFF_PROMISC &&
1945 1.1 drochner (bcmp(eh->ether_dhost, LLADDR(ifp->if_sadl),
1946 1.1 drochner ETHER_ADDR_LEN) &&
1947 1.1 drochner (eh->ether_dhost[0] & 1) == 0)) {
1948 1.1 drochner m_freem(m);
1949 1.1 drochner continue;
1950 1.1 drochner }
1951 1.1 drochner }
1952 1.1 drochner #endif
1953 1.1 drochner
1954 1.1 drochner #ifdef TI_CSUM_OFFLOAD /* XXX NetBSD: broken because m points to ether pkt */
1955 1.1 drochner ip = mtod(m, struct ip *);
1956 1.1 drochner if (!(cur_rx->ti_tcp_udp_cksum ^ 0xFFFF) &&
1957 1.1 drochner !(ip->ip_off & htons(IP_MF | IP_OFFMASK | IP_RF)))
1958 1.1 drochner m->m_flags |= M_HWCKSUM;
1959 1.1 drochner #endif
1960 1.1 drochner
1961 1.1 drochner #if NVLAN > 0 /* XXX NetBSD: broken because m points to ether pkt */
1962 1.1 drochner /*
1963 1.1 drochner * If we received a packet with a vlan tag, pass it
1964 1.1 drochner * to vlan_input() instead of ether_input().
1965 1.1 drochner */
1966 1.1 drochner if (have_tag) {
1967 1.1 drochner vlan_input_tag(eh, m, vlan_tag);
1968 1.1 drochner have_tag = vlan_tag = 0;
1969 1.1 drochner continue;
1970 1.1 drochner }
1971 1.1 drochner #endif
1972 1.1 drochner (*ifp->if_input)(ifp, m);
1973 1.1 drochner }
1974 1.1 drochner
1975 1.1 drochner /* Only necessary on the Tigon 1. */
1976 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON)
1977 1.1 drochner CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX,
1978 1.1 drochner sc->ti_rx_saved_considx);
1979 1.1 drochner
1980 1.1 drochner TI_UPDATE_STDPROD(sc, sc->ti_std);
1981 1.1 drochner TI_UPDATE_MINIPROD(sc, sc->ti_mini);
1982 1.1 drochner TI_UPDATE_JUMBOPROD(sc, sc->ti_jumbo);
1983 1.1 drochner
1984 1.1 drochner return;
1985 1.1 drochner }
1986 1.1 drochner
1987 1.1 drochner static void ti_txeof(sc)
1988 1.1 drochner struct ti_softc *sc;
1989 1.1 drochner {
1990 1.1 drochner struct ti_tx_desc *cur_tx = NULL;
1991 1.1 drochner struct ifnet *ifp;
1992 1.1 drochner
1993 1.1 drochner ifp = &sc->ethercom.ec_if;
1994 1.1 drochner
1995 1.1 drochner /*
1996 1.1 drochner * Go through our tx ring and free mbufs for those
1997 1.1 drochner * frames that have been sent.
1998 1.1 drochner */
1999 1.1 drochner while (sc->ti_tx_saved_considx != sc->ti_tx_considx.ti_idx) {
2000 1.1 drochner u_int32_t idx = 0;
2001 1.1 drochner
2002 1.1 drochner idx = sc->ti_tx_saved_considx;
2003 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON) {
2004 1.1 drochner if (idx > 383)
2005 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2006 1.1 drochner TI_TX_RING_BASE + 6144);
2007 1.1 drochner else if (idx > 255)
2008 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2009 1.1 drochner TI_TX_RING_BASE + 4096);
2010 1.1 drochner else if (idx > 127)
2011 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2012 1.1 drochner TI_TX_RING_BASE + 2048);
2013 1.1 drochner else
2014 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2015 1.1 drochner TI_TX_RING_BASE);
2016 1.1 drochner cur_tx = &sc->ti_rdata->ti_tx_ring_nic[idx % 128];
2017 1.1 drochner } else
2018 1.1 drochner cur_tx = &sc->ti_rdata->ti_tx_ring[idx];
2019 1.1 drochner if (cur_tx->ti_flags & TI_BDFLAG_END)
2020 1.1 drochner ifp->if_opackets++;
2021 1.1 drochner if (sc->ti_cdata.ti_tx_chain[idx] != NULL) {
2022 1.1 drochner m_freem(sc->ti_cdata.ti_tx_chain[idx]);
2023 1.1 drochner sc->ti_cdata.ti_tx_chain[idx] = NULL;
2024 1.1 drochner
2025 1.1 drochner /* if (sc->txdma[idx] == 0) panic() */
2026 1.1 drochner SIMPLEQ_INSERT_HEAD(&sc->txdma_list, sc->txdma[idx],
2027 1.1 drochner link);
2028 1.1 drochner sc->txdma[idx] = 0;
2029 1.1 drochner }
2030 1.1 drochner sc->ti_txcnt--;
2031 1.1 drochner TI_INC(sc->ti_tx_saved_considx, TI_TX_RING_CNT);
2032 1.1 drochner ifp->if_timer = 0;
2033 1.1 drochner }
2034 1.1 drochner
2035 1.1 drochner if (cur_tx != NULL)
2036 1.1 drochner ifp->if_flags &= ~IFF_OACTIVE;
2037 1.1 drochner
2038 1.1 drochner return;
2039 1.1 drochner }
2040 1.1 drochner
2041 1.1 drochner static int ti_intr(xsc)
2042 1.1 drochner void *xsc;
2043 1.1 drochner {
2044 1.1 drochner struct ti_softc *sc;
2045 1.1 drochner struct ifnet *ifp;
2046 1.1 drochner
2047 1.1 drochner sc = xsc;
2048 1.1 drochner ifp = &sc->ethercom.ec_if;
2049 1.1 drochner
2050 1.1 drochner #ifdef notdef
2051 1.1 drochner /* Avoid this for now -- checking this register is expensive. */
2052 1.1 drochner /* Make sure this is really our interrupt. */
2053 1.1 drochner if (!(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_INTSTATE))
2054 1.1 drochner return (0);
2055 1.1 drochner #endif
2056 1.1 drochner
2057 1.1 drochner /* Ack interrupt and stop others from occuring. */
2058 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
2059 1.1 drochner
2060 1.1 drochner if (ifp->if_flags & IFF_RUNNING) {
2061 1.1 drochner /* Check RX return ring producer/consumer */
2062 1.1 drochner ti_rxeof(sc);
2063 1.1 drochner
2064 1.1 drochner /* Check TX ring producer/consumer */
2065 1.1 drochner ti_txeof(sc);
2066 1.1 drochner }
2067 1.1 drochner
2068 1.1 drochner ti_handle_events(sc);
2069 1.1 drochner
2070 1.1 drochner /* Re-enable interrupts. */
2071 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
2072 1.1 drochner
2073 1.1 drochner if (ifp->if_flags & IFF_RUNNING && ifp->if_snd.ifq_head != NULL)
2074 1.1 drochner ti_start(ifp);
2075 1.1 drochner
2076 1.1 drochner return (1);
2077 1.1 drochner }
2078 1.1 drochner
2079 1.1 drochner static void ti_stats_update(sc)
2080 1.1 drochner struct ti_softc *sc;
2081 1.1 drochner {
2082 1.1 drochner struct ifnet *ifp;
2083 1.1 drochner
2084 1.1 drochner ifp = &sc->ethercom.ec_if;
2085 1.1 drochner
2086 1.1 drochner ifp->if_collisions +=
2087 1.1 drochner (sc->ti_rdata->ti_info.ti_stats.dot3StatsSingleCollisionFrames +
2088 1.1 drochner sc->ti_rdata->ti_info.ti_stats.dot3StatsMultipleCollisionFrames +
2089 1.1 drochner sc->ti_rdata->ti_info.ti_stats.dot3StatsExcessiveCollisions +
2090 1.1 drochner sc->ti_rdata->ti_info.ti_stats.dot3StatsLateCollisions) -
2091 1.1 drochner ifp->if_collisions;
2092 1.1 drochner
2093 1.1 drochner return;
2094 1.1 drochner }
2095 1.1 drochner
2096 1.1 drochner /*
2097 1.1 drochner * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data
2098 1.1 drochner * pointers to descriptors.
2099 1.1 drochner */
2100 1.1 drochner static int ti_encap(sc, m_head, txidx)
2101 1.1 drochner struct ti_softc *sc;
2102 1.1 drochner struct mbuf *m_head;
2103 1.1 drochner u_int32_t *txidx;
2104 1.1 drochner {
2105 1.1 drochner struct ti_tx_desc *f = NULL;
2106 1.1 drochner u_int32_t frag, cur, cnt = 0;
2107 1.1 drochner struct txdmamap_pool_entry *dma;
2108 1.1 drochner bus_dmamap_t dmamap;
2109 1.1 drochner int error, i;
2110 1.1 drochner #if NVLAN > 0
2111 1.1 drochner struct ifvlan *ifv = NULL;
2112 1.1 drochner
2113 1.1 drochner if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
2114 1.1 drochner m_head->m_pkthdr.rcvif != NULL &&
2115 1.1 drochner m_head->m_pkthdr.rcvif->if_type == IFT_8021_VLAN)
2116 1.1 drochner ifv = m_head->m_pkthdr.rcvif->if_softc;
2117 1.1 drochner #endif
2118 1.1 drochner
2119 1.1 drochner dma = SIMPLEQ_FIRST(&sc->txdma_list);
2120 1.6 bouyer if (dma == NULL) {
2121 1.6 bouyer return ENOMEM;
2122 1.6 bouyer }
2123 1.1 drochner dmamap = dma->dmamap;
2124 1.1 drochner
2125 1.1 drochner error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m_head, 0);
2126 1.1 drochner if (error) {
2127 1.1 drochner struct mbuf *m;
2128 1.1 drochner int i = 0;
2129 1.1 drochner for (m = m_head; m; m = m->m_next)
2130 1.1 drochner i++;
2131 1.1 drochner printf("ti_encap: bus_dmamap_load_mbuf (len %d, %d frags) "
2132 1.1 drochner "error %d\n", m_head->m_pkthdr.len, i, error);
2133 1.1 drochner return (ENOMEM);
2134 1.1 drochner }
2135 1.1 drochner
2136 1.1 drochner cur = frag = *txidx;
2137 1.1 drochner
2138 1.1 drochner /*
2139 1.1 drochner * Start packing the mbufs in this chain into
2140 1.1 drochner * the fragment pointers. Stop when we run out
2141 1.1 drochner * of fragments or hit the end of the mbuf chain.
2142 1.1 drochner */
2143 1.1 drochner for (i = 0; i < dmamap->dm_nsegs; i++) {
2144 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON) {
2145 1.1 drochner if (frag > 383)
2146 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2147 1.1 drochner TI_TX_RING_BASE + 6144);
2148 1.1 drochner else if (frag > 255)
2149 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2150 1.1 drochner TI_TX_RING_BASE + 4096);
2151 1.1 drochner else if (frag > 127)
2152 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2153 1.1 drochner TI_TX_RING_BASE + 2048);
2154 1.1 drochner else
2155 1.1 drochner CSR_WRITE_4(sc, TI_WINBASE,
2156 1.1 drochner TI_TX_RING_BASE);
2157 1.1 drochner f = &sc->ti_rdata->ti_tx_ring_nic[frag % 128];
2158 1.1 drochner } else
2159 1.1 drochner f = &sc->ti_rdata->ti_tx_ring[frag];
2160 1.1 drochner if (sc->ti_cdata.ti_tx_chain[frag] != NULL)
2161 1.1 drochner break;
2162 1.1 drochner TI_HOSTADDR(f->ti_addr) = dmamap->dm_segs[i].ds_addr;
2163 1.1 drochner f->ti_len = dmamap->dm_segs[i].ds_len;
2164 1.1 drochner f->ti_flags = 0;
2165 1.1 drochner #if NVLAN > 0
2166 1.1 drochner if (ifv != NULL) {
2167 1.1 drochner f->ti_flags |= TI_BDFLAG_VLAN_TAG;
2168 1.1 drochner f->ti_vlan_tag = ifv->ifv_tag;
2169 1.1 drochner } else {
2170 1.1 drochner f->ti_vlan_tag = 0;
2171 1.1 drochner }
2172 1.1 drochner #endif
2173 1.1 drochner /*
2174 1.1 drochner * Sanity check: avoid coming within 16 descriptors
2175 1.1 drochner * of the end of the ring.
2176 1.1 drochner */
2177 1.1 drochner if ((TI_TX_RING_CNT - (sc->ti_txcnt + cnt)) < 16)
2178 1.1 drochner return(ENOBUFS);
2179 1.1 drochner cur = frag;
2180 1.1 drochner TI_INC(frag, TI_TX_RING_CNT);
2181 1.1 drochner cnt++;
2182 1.1 drochner }
2183 1.1 drochner
2184 1.1 drochner if (i < dmamap->dm_nsegs)
2185 1.1 drochner return(ENOBUFS);
2186 1.1 drochner
2187 1.1 drochner if (frag == sc->ti_tx_saved_considx)
2188 1.1 drochner return(ENOBUFS);
2189 1.1 drochner
2190 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON)
2191 1.1 drochner sc->ti_rdata->ti_tx_ring_nic[cur % 128].ti_flags |=
2192 1.1 drochner TI_BDFLAG_END;
2193 1.1 drochner else
2194 1.1 drochner sc->ti_rdata->ti_tx_ring[cur].ti_flags |= TI_BDFLAG_END;
2195 1.1 drochner sc->ti_cdata.ti_tx_chain[cur] = m_head;
2196 1.1 drochner SIMPLEQ_REMOVE_HEAD(&sc->txdma_list, dma, link);
2197 1.1 drochner sc->txdma[cur] = dma;
2198 1.1 drochner sc->ti_txcnt += cnt;
2199 1.1 drochner
2200 1.1 drochner *txidx = frag;
2201 1.1 drochner
2202 1.1 drochner return(0);
2203 1.1 drochner }
2204 1.1 drochner
2205 1.1 drochner /*
2206 1.1 drochner * Main transmit routine. To avoid having to do mbuf copies, we put pointers
2207 1.1 drochner * to the mbuf data regions directly in the transmit descriptors.
2208 1.1 drochner */
2209 1.1 drochner static void ti_start(ifp)
2210 1.1 drochner struct ifnet *ifp;
2211 1.1 drochner {
2212 1.1 drochner struct ti_softc *sc;
2213 1.1 drochner struct mbuf *m_head = NULL;
2214 1.1 drochner u_int32_t prodidx = 0;
2215 1.1 drochner
2216 1.1 drochner sc = ifp->if_softc;
2217 1.1 drochner
2218 1.1 drochner prodidx = CSR_READ_4(sc, TI_MB_SENDPROD_IDX);
2219 1.1 drochner
2220 1.1 drochner while(sc->ti_cdata.ti_tx_chain[prodidx] == NULL) {
2221 1.1 drochner IF_DEQUEUE(&ifp->if_snd, m_head);
2222 1.1 drochner if (m_head == NULL)
2223 1.1 drochner break;
2224 1.1 drochner
2225 1.1 drochner /*
2226 1.1 drochner * Pack the data into the transmit ring. If we
2227 1.1 drochner * don't have room, set the OACTIVE flag and wait
2228 1.1 drochner * for the NIC to drain the ring.
2229 1.1 drochner */
2230 1.1 drochner if (ti_encap(sc, m_head, &prodidx)) {
2231 1.1 drochner IF_PREPEND(&ifp->if_snd, m_head);
2232 1.1 drochner ifp->if_flags |= IFF_OACTIVE;
2233 1.1 drochner break;
2234 1.1 drochner }
2235 1.1 drochner
2236 1.1 drochner /*
2237 1.1 drochner * If there's a BPF listener, bounce a copy of this frame
2238 1.1 drochner * to him.
2239 1.1 drochner */
2240 1.1 drochner #if NBPFILTER > 0
2241 1.1 drochner if (ifp->if_bpf)
2242 1.1 drochner bpf_mtap(ifp->if_bpf, m_head);
2243 1.1 drochner #endif
2244 1.1 drochner }
2245 1.1 drochner
2246 1.1 drochner /* Transmit */
2247 1.1 drochner CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, prodidx);
2248 1.1 drochner
2249 1.1 drochner /*
2250 1.1 drochner * Set a timeout in case the chip goes out to lunch.
2251 1.1 drochner */
2252 1.1 drochner ifp->if_timer = 5;
2253 1.1 drochner
2254 1.1 drochner return;
2255 1.1 drochner }
2256 1.1 drochner
2257 1.1 drochner static void ti_init(xsc)
2258 1.1 drochner void *xsc;
2259 1.1 drochner {
2260 1.1 drochner struct ti_softc *sc = xsc;
2261 1.1 drochner int s;
2262 1.1 drochner
2263 1.1 drochner s = splimp();
2264 1.1 drochner
2265 1.1 drochner /* Cancel pending I/O and flush buffers. */
2266 1.1 drochner ti_stop(sc);
2267 1.1 drochner
2268 1.1 drochner /* Init the gen info block, ring control blocks and firmware. */
2269 1.1 drochner if (ti_gibinit(sc)) {
2270 1.1 drochner printf("%s: initialization failure\n", sc->sc_dev.dv_xname);
2271 1.1 drochner splx(s);
2272 1.1 drochner return;
2273 1.1 drochner }
2274 1.1 drochner
2275 1.1 drochner splx(s);
2276 1.1 drochner
2277 1.1 drochner return;
2278 1.1 drochner }
2279 1.1 drochner
2280 1.1 drochner static void ti_init2(sc)
2281 1.1 drochner struct ti_softc *sc;
2282 1.1 drochner {
2283 1.1 drochner struct ti_cmd_desc cmd;
2284 1.1 drochner struct ifnet *ifp;
2285 1.1 drochner u_int8_t *m;
2286 1.1 drochner struct ifmedia *ifm;
2287 1.1 drochner int tmp;
2288 1.1 drochner
2289 1.1 drochner ifp = &sc->ethercom.ec_if;
2290 1.1 drochner
2291 1.1 drochner /* Specify MTU and interface index. */
2292 1.1 drochner CSR_WRITE_4(sc, TI_GCR_IFINDEX, sc->sc_dev.dv_unit); /* ??? */
2293 1.1 drochner CSR_WRITE_4(sc, TI_GCR_IFMTU, ifp->if_mtu +
2294 1.1 drochner ETHER_HDR_LEN + ETHER_CRC_LEN);
2295 1.1 drochner TI_DO_CMD(TI_CMD_UPDATE_GENCOM, 0, 0);
2296 1.1 drochner
2297 1.1 drochner /* Load our MAC address. */
2298 1.1 drochner m = (u_int8_t *)LLADDR(ifp->if_sadl);
2299 1.1 drochner CSR_WRITE_4(sc, TI_GCR_PAR0, (m[0] << 8) | m[1]);
2300 1.1 drochner CSR_WRITE_4(sc, TI_GCR_PAR1, (m[2] << 24) | (m[3] << 16)
2301 1.1 drochner | (m[4] << 8) | m[5]);
2302 1.1 drochner TI_DO_CMD(TI_CMD_SET_MAC_ADDR, 0, 0);
2303 1.1 drochner
2304 1.1 drochner /* Enable or disable promiscuous mode as needed. */
2305 1.1 drochner if (ifp->if_flags & IFF_PROMISC) {
2306 1.1 drochner TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_ENB, 0);
2307 1.1 drochner } else {
2308 1.1 drochner TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_DIS, 0);
2309 1.1 drochner }
2310 1.1 drochner
2311 1.1 drochner /* Program multicast filter. */
2312 1.1 drochner ti_setmulti(sc);
2313 1.1 drochner
2314 1.1 drochner /*
2315 1.1 drochner * If this is a Tigon 1, we should tell the
2316 1.1 drochner * firmware to use software packet filtering.
2317 1.1 drochner */
2318 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON) {
2319 1.1 drochner TI_DO_CMD(TI_CMD_FDR_FILTERING, TI_CMD_CODE_FILT_ENB, 0);
2320 1.1 drochner }
2321 1.1 drochner
2322 1.1 drochner /* Init RX ring. */
2323 1.1 drochner ti_init_rx_ring_std(sc);
2324 1.1 drochner
2325 1.1 drochner /* Init jumbo RX ring. */
2326 1.1 drochner if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
2327 1.1 drochner ti_init_rx_ring_jumbo(sc);
2328 1.1 drochner
2329 1.1 drochner /*
2330 1.1 drochner * If this is a Tigon 2, we can also configure the
2331 1.1 drochner * mini ring.
2332 1.1 drochner */
2333 1.1 drochner if (sc->ti_hwrev == TI_HWREV_TIGON_II)
2334 1.1 drochner ti_init_rx_ring_mini(sc);
2335 1.1 drochner
2336 1.1 drochner CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX, 0);
2337 1.1 drochner sc->ti_rx_saved_considx = 0;
2338 1.1 drochner
2339 1.1 drochner /* Init TX ring. */
2340 1.1 drochner ti_init_tx_ring(sc);
2341 1.1 drochner
2342 1.1 drochner /* Tell firmware we're alive. */
2343 1.1 drochner TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_UP, 0);
2344 1.1 drochner
2345 1.1 drochner /* Enable host interrupts. */
2346 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
2347 1.1 drochner
2348 1.1 drochner ifp->if_flags |= IFF_RUNNING;
2349 1.1 drochner ifp->if_flags &= ~IFF_OACTIVE;
2350 1.1 drochner
2351 1.1 drochner /*
2352 1.1 drochner * Make sure to set media properly. We have to do this
2353 1.1 drochner * here since we have to issue commands in order to set
2354 1.1 drochner * the link negotiation and we can't issue commands until
2355 1.1 drochner * the firmware is running.
2356 1.1 drochner */
2357 1.1 drochner ifm = &sc->ifmedia;
2358 1.1 drochner tmp = ifm->ifm_media;
2359 1.1 drochner ifm->ifm_media = ifm->ifm_cur->ifm_media;
2360 1.1 drochner ti_ifmedia_upd(ifp);
2361 1.1 drochner ifm->ifm_media = tmp;
2362 1.1 drochner
2363 1.1 drochner return;
2364 1.1 drochner }
2365 1.1 drochner
2366 1.1 drochner /*
2367 1.1 drochner * Set media options.
2368 1.1 drochner */
2369 1.1 drochner static int ti_ifmedia_upd(ifp)
2370 1.1 drochner struct ifnet *ifp;
2371 1.1 drochner {
2372 1.1 drochner struct ti_softc *sc;
2373 1.1 drochner struct ifmedia *ifm;
2374 1.1 drochner struct ti_cmd_desc cmd;
2375 1.1 drochner
2376 1.1 drochner sc = ifp->if_softc;
2377 1.1 drochner ifm = &sc->ifmedia;
2378 1.1 drochner
2379 1.1 drochner if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
2380 1.1 drochner return(EINVAL);
2381 1.1 drochner
2382 1.1 drochner switch(IFM_SUBTYPE(ifm->ifm_media)) {
2383 1.1 drochner case IFM_AUTO:
2384 1.1 drochner CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB|
2385 1.1 drochner TI_GLNK_FULL_DUPLEX|TI_GLNK_RX_FLOWCTL_Y|
2386 1.1 drochner TI_GLNK_AUTONEGENB|TI_GLNK_ENB);
2387 1.1 drochner CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_100MB|TI_LNK_10MB|
2388 1.1 drochner TI_LNK_FULL_DUPLEX|TI_LNK_HALF_DUPLEX|
2389 1.1 drochner TI_LNK_AUTONEGENB|TI_LNK_ENB);
2390 1.1 drochner TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
2391 1.1 drochner TI_CMD_CODE_NEGOTIATE_BOTH, 0);
2392 1.1 drochner break;
2393 1.3 thorpej case IFM_1000_SX:
2394 1.1 drochner CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB|
2395 1.1 drochner TI_GLNK_FULL_DUPLEX|TI_GLNK_RX_FLOWCTL_Y|TI_GLNK_ENB);
2396 1.1 drochner CSR_WRITE_4(sc, TI_GCR_LINK, 0);
2397 1.1 drochner TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
2398 1.1 drochner TI_CMD_CODE_NEGOTIATE_GIGABIT, 0);
2399 1.1 drochner break;
2400 1.1 drochner case IFM_100_FX:
2401 1.1 drochner case IFM_10_FL:
2402 1.1 drochner CSR_WRITE_4(sc, TI_GCR_GLINK, 0);
2403 1.1 drochner CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_ENB|TI_LNK_PREF);
2404 1.1 drochner if (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX) {
2405 1.1 drochner TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_100MB);
2406 1.1 drochner } else {
2407 1.1 drochner TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_10MB);
2408 1.1 drochner }
2409 1.1 drochner if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) {
2410 1.1 drochner TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_FULL_DUPLEX);
2411 1.1 drochner } else {
2412 1.1 drochner TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_HALF_DUPLEX);
2413 1.1 drochner }
2414 1.1 drochner TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
2415 1.1 drochner TI_CMD_CODE_NEGOTIATE_10_100, 0);
2416 1.1 drochner break;
2417 1.1 drochner }
2418 1.1 drochner
2419 1.5 thorpej sc->ethercom.ec_if.if_baudrate =
2420 1.5 thorpej ifmedia_baudrate(ifm->ifm_media);
2421 1.5 thorpej
2422 1.1 drochner return(0);
2423 1.1 drochner }
2424 1.1 drochner
2425 1.1 drochner /*
2426 1.1 drochner * Report current media status.
2427 1.1 drochner */
2428 1.1 drochner static void ti_ifmedia_sts(ifp, ifmr)
2429 1.1 drochner struct ifnet *ifp;
2430 1.1 drochner struct ifmediareq *ifmr;
2431 1.1 drochner {
2432 1.1 drochner struct ti_softc *sc;
2433 1.1 drochner
2434 1.1 drochner sc = ifp->if_softc;
2435 1.1 drochner
2436 1.1 drochner ifmr->ifm_status = IFM_AVALID;
2437 1.1 drochner ifmr->ifm_active = IFM_ETHER;
2438 1.1 drochner
2439 1.1 drochner if (sc->ti_linkstat == TI_EV_CODE_LINK_DOWN)
2440 1.1 drochner return;
2441 1.1 drochner
2442 1.1 drochner ifmr->ifm_status |= IFM_ACTIVE;
2443 1.1 drochner
2444 1.1 drochner if (sc->ti_linkstat == TI_EV_CODE_GIG_LINK_UP)
2445 1.3 thorpej ifmr->ifm_active |= IFM_1000_SX|IFM_FDX;
2446 1.1 drochner else if (sc->ti_linkstat == TI_EV_CODE_LINK_UP) {
2447 1.1 drochner u_int32_t media;
2448 1.1 drochner media = CSR_READ_4(sc, TI_GCR_LINK_STAT);
2449 1.1 drochner if (media & TI_LNK_100MB)
2450 1.1 drochner ifmr->ifm_active |= IFM_100_FX;
2451 1.1 drochner if (media & TI_LNK_10MB)
2452 1.1 drochner ifmr->ifm_active |= IFM_10_FL;
2453 1.1 drochner if (media & TI_LNK_FULL_DUPLEX)
2454 1.1 drochner ifmr->ifm_active |= IFM_FDX;
2455 1.1 drochner if (media & TI_LNK_HALF_DUPLEX)
2456 1.1 drochner ifmr->ifm_active |= IFM_HDX;
2457 1.1 drochner }
2458 1.5 thorpej
2459 1.5 thorpej sc->ethercom.ec_if.if_baudrate =
2460 1.5 thorpej ifmedia_baudrate(sc->ifmedia.ifm_media);
2461 1.5 thorpej
2462 1.1 drochner return;
2463 1.1 drochner }
2464 1.1 drochner
2465 1.1 drochner static int
2466 1.1 drochner ti_ether_ioctl(ifp, cmd, data)
2467 1.1 drochner struct ifnet *ifp;
2468 1.1 drochner u_long cmd;
2469 1.1 drochner caddr_t data;
2470 1.1 drochner {
2471 1.1 drochner struct ifaddr *ifa = (struct ifaddr *) data;
2472 1.1 drochner struct ti_softc *sc = ifp->if_softc;
2473 1.1 drochner
2474 1.1 drochner switch (cmd) {
2475 1.1 drochner case SIOCSIFADDR:
2476 1.1 drochner ifp->if_flags |= IFF_UP;
2477 1.1 drochner
2478 1.1 drochner switch (ifa->ifa_addr->sa_family) {
2479 1.1 drochner #ifdef INET
2480 1.1 drochner case AF_INET:
2481 1.1 drochner ti_init(sc);
2482 1.1 drochner arp_ifinit(ifp, ifa);
2483 1.1 drochner break;
2484 1.1 drochner #endif
2485 1.1 drochner #ifdef NS
2486 1.1 drochner case AF_NS:
2487 1.1 drochner {
2488 1.8 augustss struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
2489 1.1 drochner
2490 1.1 drochner if (ns_nullhost(*ina))
2491 1.1 drochner ina->x_host = *(union ns_host *)
2492 1.1 drochner LLADDR(ifp->if_sadl);
2493 1.1 drochner else
2494 1.1 drochner bcopy(ina->x_host.c_host, LLADDR(ifp->if_sadl),
2495 1.1 drochner ifp->if_addrlen);
2496 1.1 drochner /* Set new address. */
2497 1.1 drochner ti_init(sc);
2498 1.1 drochner break;
2499 1.1 drochner }
2500 1.1 drochner #endif
2501 1.1 drochner default:
2502 1.1 drochner ti_init(sc);
2503 1.1 drochner break;
2504 1.1 drochner }
2505 1.1 drochner break;
2506 1.1 drochner
2507 1.1 drochner default:
2508 1.1 drochner return (EINVAL);
2509 1.1 drochner }
2510 1.1 drochner
2511 1.1 drochner return (0);
2512 1.1 drochner }
2513 1.1 drochner
2514 1.1 drochner static int ti_ioctl(ifp, command, data)
2515 1.1 drochner struct ifnet *ifp;
2516 1.1 drochner u_long command;
2517 1.1 drochner caddr_t data;
2518 1.1 drochner {
2519 1.1 drochner struct ti_softc *sc = ifp->if_softc;
2520 1.1 drochner struct ifreq *ifr = (struct ifreq *) data;
2521 1.1 drochner int s, error = 0;
2522 1.1 drochner struct ti_cmd_desc cmd;
2523 1.1 drochner
2524 1.1 drochner s = splimp();
2525 1.1 drochner
2526 1.1 drochner switch(command) {
2527 1.1 drochner case SIOCSIFADDR:
2528 1.1 drochner case SIOCGIFADDR:
2529 1.1 drochner error = ti_ether_ioctl(ifp, command, data);
2530 1.1 drochner break;
2531 1.1 drochner case SIOCSIFMTU:
2532 1.1 drochner if (ifr->ifr_mtu > TI_JUMBO_MTU)
2533 1.1 drochner error = EINVAL;
2534 1.1 drochner else {
2535 1.1 drochner ifp->if_mtu = ifr->ifr_mtu;
2536 1.1 drochner ti_init(sc);
2537 1.1 drochner }
2538 1.1 drochner break;
2539 1.1 drochner case SIOCSIFFLAGS:
2540 1.1 drochner if (ifp->if_flags & IFF_UP) {
2541 1.1 drochner /*
2542 1.1 drochner * If only the state of the PROMISC flag changed,
2543 1.1 drochner * then just use the 'set promisc mode' command
2544 1.1 drochner * instead of reinitializing the entire NIC. Doing
2545 1.1 drochner * a full re-init means reloading the firmware and
2546 1.1 drochner * waiting for it to start up, which may take a
2547 1.1 drochner * second or two.
2548 1.1 drochner */
2549 1.1 drochner if (ifp->if_flags & IFF_RUNNING &&
2550 1.1 drochner ifp->if_flags & IFF_PROMISC &&
2551 1.1 drochner !(sc->ti_if_flags & IFF_PROMISC)) {
2552 1.1 drochner TI_DO_CMD(TI_CMD_SET_PROMISC_MODE,
2553 1.1 drochner TI_CMD_CODE_PROMISC_ENB, 0);
2554 1.1 drochner } else if (ifp->if_flags & IFF_RUNNING &&
2555 1.1 drochner !(ifp->if_flags & IFF_PROMISC) &&
2556 1.1 drochner sc->ti_if_flags & IFF_PROMISC) {
2557 1.1 drochner TI_DO_CMD(TI_CMD_SET_PROMISC_MODE,
2558 1.1 drochner TI_CMD_CODE_PROMISC_DIS, 0);
2559 1.1 drochner } else
2560 1.1 drochner ti_init(sc);
2561 1.1 drochner } else {
2562 1.1 drochner if (ifp->if_flags & IFF_RUNNING) {
2563 1.1 drochner ti_stop(sc);
2564 1.1 drochner }
2565 1.1 drochner }
2566 1.1 drochner sc->ti_if_flags = ifp->if_flags;
2567 1.1 drochner error = 0;
2568 1.1 drochner break;
2569 1.1 drochner case SIOCADDMULTI:
2570 1.1 drochner case SIOCDELMULTI:
2571 1.1 drochner if (ifp->if_flags & IFF_RUNNING) {
2572 1.1 drochner ti_setmulti(sc);
2573 1.1 drochner error = 0;
2574 1.1 drochner }
2575 1.1 drochner break;
2576 1.1 drochner case SIOCSIFMEDIA:
2577 1.1 drochner case SIOCGIFMEDIA:
2578 1.1 drochner error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
2579 1.1 drochner break;
2580 1.1 drochner default:
2581 1.1 drochner error = EINVAL;
2582 1.1 drochner break;
2583 1.1 drochner }
2584 1.1 drochner
2585 1.1 drochner (void)splx(s);
2586 1.1 drochner
2587 1.1 drochner return(error);
2588 1.1 drochner }
2589 1.1 drochner
2590 1.1 drochner static void ti_watchdog(ifp)
2591 1.1 drochner struct ifnet *ifp;
2592 1.1 drochner {
2593 1.1 drochner struct ti_softc *sc;
2594 1.1 drochner
2595 1.1 drochner sc = ifp->if_softc;
2596 1.1 drochner
2597 1.1 drochner printf("%s: watchdog timeout -- resetting\n", sc->sc_dev.dv_xname);
2598 1.1 drochner ti_stop(sc);
2599 1.1 drochner ti_init(sc);
2600 1.1 drochner
2601 1.1 drochner ifp->if_oerrors++;
2602 1.1 drochner
2603 1.1 drochner return;
2604 1.1 drochner }
2605 1.1 drochner
2606 1.1 drochner /*
2607 1.1 drochner * Stop the adapter and free any mbufs allocated to the
2608 1.1 drochner * RX and TX lists.
2609 1.1 drochner */
2610 1.1 drochner static void ti_stop(sc)
2611 1.1 drochner struct ti_softc *sc;
2612 1.1 drochner {
2613 1.1 drochner struct ifnet *ifp;
2614 1.1 drochner struct ti_cmd_desc cmd;
2615 1.1 drochner
2616 1.1 drochner ifp = &sc->ethercom.ec_if;
2617 1.1 drochner
2618 1.1 drochner /* Disable host interrupts. */
2619 1.1 drochner CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
2620 1.1 drochner /*
2621 1.1 drochner * Tell firmware we're shutting down.
2622 1.1 drochner */
2623 1.1 drochner TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_DOWN, 0);
2624 1.1 drochner
2625 1.1 drochner /* Halt and reinitialize. */
2626 1.1 drochner ti_chipinit(sc);
2627 1.1 drochner ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL);
2628 1.1 drochner ti_chipinit(sc);
2629 1.1 drochner
2630 1.1 drochner /* Free the RX lists. */
2631 1.1 drochner ti_free_rx_ring_std(sc);
2632 1.1 drochner
2633 1.1 drochner /* Free jumbo RX list. */
2634 1.1 drochner ti_free_rx_ring_jumbo(sc);
2635 1.1 drochner
2636 1.1 drochner /* Free mini RX list. */
2637 1.1 drochner ti_free_rx_ring_mini(sc);
2638 1.1 drochner
2639 1.1 drochner /* Free TX buffers. */
2640 1.1 drochner ti_free_tx_ring(sc);
2641 1.1 drochner
2642 1.1 drochner sc->ti_ev_prodidx.ti_idx = 0;
2643 1.1 drochner sc->ti_return_prodidx.ti_idx = 0;
2644 1.1 drochner sc->ti_tx_considx.ti_idx = 0;
2645 1.1 drochner sc->ti_tx_saved_considx = TI_TXCONS_UNSET;
2646 1.1 drochner
2647 1.1 drochner ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2648 1.1 drochner
2649 1.1 drochner return;
2650 1.1 drochner }
2651 1.1 drochner
2652 1.1 drochner /*
2653 1.1 drochner * Stop all chip I/O so that the kernel's probe routines don't
2654 1.1 drochner * get confused by errant DMAs when rebooting.
2655 1.1 drochner */
2656 1.6 bouyer static void ti_shutdown(v)
2657 1.6 bouyer void *v;
2658 1.1 drochner {
2659 1.6 bouyer struct ti_softc *sc = v;
2660 1.1 drochner
2661 1.1 drochner ti_chipinit(sc);
2662 1.1 drochner
2663 1.1 drochner return;
2664 1.1 drochner }
2665