2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
34 * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD.
35 * Manuals, sample driver and firmware source kits are available
36 * from http://www.alteon.com/support/openkits.
38 * Written by Bill Paul <wpaul@ctr.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City
44 * The Alteon Networks Tigon chip contains an embedded R4000 CPU,
45 * gigabit MAC, dual DMA channels and a PCI interface unit. NICs
46 * using the Tigon may have anywhere from 512K to 2MB of SRAM. The
47 * Tigon supports hardware IP, TCP and UCP checksumming, multicast
48 * filtering and jumbo (9014 byte) frames. The hardware is largely
49 * controlled by firmware, which must be loaded into the NIC during
52 * The Tigon 2 contains 2 R4000 CPUs and requires a newer firmware
53 * revision, which supports new features such as extended commands,
54 * extended jumbo receive ring desciptors and a mini receive ring.
56 * Alteon Networks is to be commended for releasing such a vast amount
57 * of development material for the Tigon NIC without requiring an NDA
58 * (although they really should have done it a long time ago). With
59 * any luck, the other vendors will finally wise up and follow Alteon's
62 * The firmware for the Tigon 1 and 2 NICs is compiled directly into
63 * this driver by #including it as a C header file. This bloats the
64 * driver somewhat, but it's the easiest method considering that the
65 * driver code and firmware code need to be kept in sync. The source
66 * for the firmware is not provided with the FreeBSD distribution since
67 * compiling it requires a GNU toolchain targeted for mips-sgi-irix5.3.
69 * The following people deserve special thanks:
70 * - Terry Murphy of 3Com, for providing a 3c985 Tigon 1 board
72 * - Raymond Lee of Netgear, for providing a pair of Netgear
73 * GA620 Tigon 2 boards for testing
74 * - Ulf Zimmermann, for bringing the GA260 to my attention and
75 * convincing me to write this driver.
76 * - Andrew Gallatin for providing FreeBSD/Alpha support.
79 #include <sys/cdefs.h>
80 __FBSDID("$FreeBSD$");
84 #include <sys/param.h>
85 #include <sys/systm.h>
86 #include <sys/sockio.h>
88 #include <sys/malloc.h>
89 #include <sys/kernel.h>
90 #include <sys/module.h>
91 #include <sys/socket.h>
92 #include <sys/queue.h>
94 #include <sys/sf_buf.h>
97 #include <net/if_arp.h>
98 #include <net/ethernet.h>
99 #include <net/if_dl.h>
100 #include <net/if_media.h>
101 #include <net/if_types.h>
102 #include <net/if_vlan_var.h>
106 #include <netinet/in_systm.h>
107 #include <netinet/in.h>
108 #include <netinet/ip.h>
110 #include <machine/bus.h>
111 #include <machine/resource.h>
113 #include <sys/rman.h>
115 #ifdef TI_SF_BUF_JUMBO
117 #include <vm/vm_page.h>
120 #include <dev/pci/pcireg.h>
121 #include <dev/pci/pcivar.h>
123 #include <sys/tiio.h>
124 #include <dev/ti/if_tireg.h>
125 #include <dev/ti/ti_fw.h>
126 #include <dev/ti/ti_fw2.h>
128 #define TI_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_IP_FRAGS)
130 * We can only turn on header splitting if we're using extended receive
133 #if defined(TI_JUMBO_HDRSPLIT) && !defined(TI_SF_BUF_JUMBO)
134 #error "options TI_JUMBO_HDRSPLIT requires TI_SF_BUF_JUMBO"
135 #endif /* TI_JUMBO_HDRSPLIT && !TI_SF_BUF_JUMBO */
143 * Various supported device vendors/types and their names.
146 static const struct ti_type const ti_devs[] = {
147 { ALT_VENDORID, ALT_DEVICEID_ACENIC,
148 "Alteon AceNIC 1000baseSX Gigabit Ethernet" },
149 { ALT_VENDORID, ALT_DEVICEID_ACENIC_COPPER,
150 "Alteon AceNIC 1000baseT Gigabit Ethernet" },
151 { TC_VENDORID, TC_DEVICEID_3C985,
152 "3Com 3c985-SX Gigabit Ethernet" },
153 { NG_VENDORID, NG_DEVICEID_GA620,
154 "Netgear GA620 1000baseSX Gigabit Ethernet" },
155 { NG_VENDORID, NG_DEVICEID_GA620T,
156 "Netgear GA620 1000baseT Gigabit Ethernet" },
157 { SGI_VENDORID, SGI_DEVICEID_TIGON,
158 "Silicon Graphics Gigabit Ethernet" },
159 { DEC_VENDORID, DEC_DEVICEID_FARALLON_PN9000SX,
160 "Farallon PN9000SX Gigabit Ethernet" },
165 static d_open_t ti_open;
166 static d_close_t ti_close;
167 static d_ioctl_t ti_ioctl2;
169 static struct cdevsw ti_cdevsw = {
170 .d_version = D_VERSION,
174 .d_ioctl = ti_ioctl2,
178 static int ti_probe(device_t);
179 static int ti_attach(device_t);
180 static int ti_detach(device_t);
181 static void ti_txeof(struct ti_softc *);
182 static void ti_rxeof(struct ti_softc *);
184 static void ti_stats_update(struct ti_softc *);
185 static int ti_encap(struct ti_softc *, struct mbuf **);
187 static void ti_intr(void *);
188 static void ti_start(struct ifnet *);
189 static void ti_start_locked(struct ifnet *);
190 static int ti_ioctl(struct ifnet *, u_long, caddr_t);
191 static void ti_init(void *);
192 static void ti_init_locked(void *);
193 static void ti_init2(struct ti_softc *);
194 static void ti_stop(struct ti_softc *);
195 static void ti_watchdog(void *);
196 static int ti_shutdown(device_t);
197 static int ti_ifmedia_upd(struct ifnet *);
198 static int ti_ifmedia_upd_locked(struct ti_softc *);
199 static void ti_ifmedia_sts(struct ifnet *, struct ifmediareq *);
201 static uint32_t ti_eeprom_putbyte(struct ti_softc *, int);
202 static uint8_t ti_eeprom_getbyte(struct ti_softc *, int, uint8_t *);
203 static int ti_read_eeprom(struct ti_softc *, caddr_t, int, int);
205 static void ti_add_mcast(struct ti_softc *, struct ether_addr *);
206 static void ti_del_mcast(struct ti_softc *, struct ether_addr *);
207 static void ti_setmulti(struct ti_softc *);
209 static void ti_mem_read(struct ti_softc *, uint32_t, uint32_t, void *);
210 static void ti_mem_write(struct ti_softc *, uint32_t, uint32_t, void *);
211 static void ti_mem_zero(struct ti_softc *, uint32_t, uint32_t);
212 static int ti_copy_mem(struct ti_softc *, uint32_t, uint32_t, caddr_t, int,
214 static int ti_copy_scratch(struct ti_softc *, uint32_t, uint32_t, caddr_t,
216 static int ti_bcopy_swap(const void *, void *, size_t, ti_swap_type);
217 static void ti_loadfw(struct ti_softc *);
218 static void ti_cmd(struct ti_softc *, struct ti_cmd_desc *);
219 static void ti_cmd_ext(struct ti_softc *, struct ti_cmd_desc *, caddr_t, int);
220 static void ti_handle_events(struct ti_softc *);
221 static int ti_alloc_dmamaps(struct ti_softc *);
222 static void ti_free_dmamaps(struct ti_softc *);
223 static int ti_alloc_jumbo_mem(struct ti_softc *);
224 static int ti_newbuf_std(struct ti_softc *, int);
225 static int ti_newbuf_mini(struct ti_softc *, int);
226 static int ti_newbuf_jumbo(struct ti_softc *, int, struct mbuf *);
227 static int ti_init_rx_ring_std(struct ti_softc *);
228 static void ti_free_rx_ring_std(struct ti_softc *);
229 static int ti_init_rx_ring_jumbo(struct ti_softc *);
230 static void ti_free_rx_ring_jumbo(struct ti_softc *);
231 static int ti_init_rx_ring_mini(struct ti_softc *);
232 static void ti_free_rx_ring_mini(struct ti_softc *);
233 static void ti_free_tx_ring(struct ti_softc *);
234 static int ti_init_tx_ring(struct ti_softc *);
235 static void ti_discard_std(struct ti_softc *, int);
236 #ifndef TI_SF_BUF_JUMBO
237 static void ti_discard_jumbo(struct ti_softc *, int);
239 static void ti_discard_mini(struct ti_softc *, int);
241 static int ti_64bitslot_war(struct ti_softc *);
242 static int ti_chipinit(struct ti_softc *);
243 static int ti_gibinit(struct ti_softc *);
245 #ifdef TI_JUMBO_HDRSPLIT
246 static __inline void ti_hdr_split(struct mbuf *top, int hdr_len, int pkt_len,
248 #endif /* TI_JUMBO_HDRSPLIT */
250 static device_method_t ti_methods[] = {
251 /* Device interface */
252 DEVMETHOD(device_probe, ti_probe),
253 DEVMETHOD(device_attach, ti_attach),
254 DEVMETHOD(device_detach, ti_detach),
255 DEVMETHOD(device_shutdown, ti_shutdown),
259 static driver_t ti_driver = {
262 sizeof(struct ti_softc)
265 static devclass_t ti_devclass;
267 DRIVER_MODULE(ti, pci, ti_driver, ti_devclass, 0, 0);
268 MODULE_DEPEND(ti, pci, 1, 1, 1);
269 MODULE_DEPEND(ti, ether, 1, 1, 1);
272 * Send an instruction or address to the EEPROM, check for ACK.
275 ti_eeprom_putbyte(struct ti_softc *sc, int byte)
280 * Make sure we're in TX mode.
282 TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
285 * Feed in each bit and stobe the clock.
287 for (i = 0x80; i; i >>= 1) {
289 TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT);
291 TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT);
294 TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
296 TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
302 TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
307 TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
308 ack = CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN;
309 TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
315 * Read a byte of data stored in the EEPROM at address 'addr.'
316 * We have to send two address bytes since the EEPROM can hold
317 * more than 256 bytes of data.
320 ti_eeprom_getbyte(struct ti_softc *sc, int addr, uint8_t *dest)
328 * Send write control code to EEPROM.
330 if (ti_eeprom_putbyte(sc, EEPROM_CTL_WRITE)) {
331 device_printf(sc->ti_dev,
332 "failed to send write command, status: %x\n",
333 CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
338 * Send first byte of address of byte we want to read.
340 if (ti_eeprom_putbyte(sc, (addr >> 8) & 0xFF)) {
341 device_printf(sc->ti_dev, "failed to send address, status: %x\n",
342 CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
346 * Send second byte address of byte we want to read.
348 if (ti_eeprom_putbyte(sc, addr & 0xFF)) {
349 device_printf(sc->ti_dev, "failed to send address, status: %x\n",
350 CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
357 * Send read control code to EEPROM.
359 if (ti_eeprom_putbyte(sc, EEPROM_CTL_READ)) {
360 device_printf(sc->ti_dev,
361 "failed to send read command, status: %x\n",
362 CSR_READ_4(sc, TI_MISC_LOCAL_CTL));
367 * Start reading bits from EEPROM.
369 TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
370 for (i = 0x80; i; i >>= 1) {
371 TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
373 if (CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN)
375 TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK);
382 * No ACK generated for read, so just return byte.
391 * Read a sequence of bytes from the EEPROM.
394 ti_read_eeprom(struct ti_softc *sc, caddr_t dest, int off, int cnt)
399 for (i = 0; i < cnt; i++) {
400 err = ti_eeprom_getbyte(sc, off + i, &byte);
406 return (err ? 1 : 0);
410 * NIC memory read function.
411 * Can be used to copy data from NIC local memory.
414 ti_mem_read(struct ti_softc *sc, uint32_t addr, uint32_t len, void *buf)
416 int segptr, segsize, cnt;
427 segsize = TI_WINLEN - (segptr % TI_WINLEN);
428 CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
429 bus_space_read_region_4(sc->ti_btag, sc->ti_bhandle,
430 TI_WINDOW + (segptr & (TI_WINLEN - 1)), (uint32_t *)ptr,
440 * NIC memory write function.
441 * Can be used to copy data into NIC local memory.
444 ti_mem_write(struct ti_softc *sc, uint32_t addr, uint32_t len, void *buf)
446 int segptr, segsize, cnt;
457 segsize = TI_WINLEN - (segptr % TI_WINLEN);
458 CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
459 bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
460 TI_WINDOW + (segptr & (TI_WINLEN - 1)), (uint32_t *)ptr,
469 * NIC memory read function.
470 * Can be used to clear a section of NIC local memory.
473 ti_mem_zero(struct ti_softc *sc, uint32_t addr, uint32_t len)
475 int segptr, segsize, cnt;
484 segsize = TI_WINLEN - (segptr % TI_WINLEN);
485 CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
486 bus_space_set_region_4(sc->ti_btag, sc->ti_bhandle,
487 TI_WINDOW + (segptr & (TI_WINLEN - 1)), 0, segsize / 4);
494 ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
495 caddr_t buf, int useraddr, int readdata)
497 int segptr, segsize, cnt;
500 uint8_t tmparray[TI_WINLEN], tmparray2[TI_WINLEN];
507 * At the moment, we don't handle non-aligned cases, we just bail.
508 * If this proves to be a problem, it will be fixed.
511 && (tigon_addr & 0x3)) {
512 device_printf(sc->ti_dev, "%s: tigon address %#x isn't "
513 "word-aligned\n", __func__, tigon_addr);
514 device_printf(sc->ti_dev, "%s: unaligned writes aren't "
515 "yet supported\n", __func__);
519 segptr = tigon_addr & ~0x3;
520 segresid = tigon_addr - segptr;
523 * This is the non-aligned amount left over that we'll need to
528 /* Add in the left over amount at the front of the buffer */
533 * If resid + segresid is >= 4, add multiples of 4 to the count and
534 * decrease the residual by that much.
537 resid -= resid & ~0x3;
544 * Save the old window base value.
546 origwin = CSR_READ_4(sc, TI_WINBASE);
549 bus_size_t ti_offset;
554 segsize = TI_WINLEN - (segptr % TI_WINLEN);
555 CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
557 ti_offset = TI_WINDOW + (segptr & (TI_WINLEN -1));
561 bus_space_read_region_4(sc->ti_btag,
562 sc->ti_bhandle, ti_offset,
563 (uint32_t *)tmparray,
567 * Yeah, this is a little on the kludgy
568 * side, but at least this code is only
569 * used for debugging.
571 ti_bcopy_swap(tmparray, tmparray2, segsize,
576 copyout(&tmparray2[segresid], ptr,
580 copyout(tmparray2, ptr, segsize);
585 ti_bcopy_swap(tmparray, tmparray2,
586 segsize, TI_SWAP_NTOH);
588 bcopy(&tmparray2[segresid], ptr,
593 ti_bcopy_swap(tmparray, ptr, segsize,
600 copyin(ptr, tmparray2, segsize);
602 ti_bcopy_swap(tmparray2, tmparray, segsize,
605 ti_bcopy_swap(ptr, tmparray, segsize,
608 bus_space_write_region_4(sc->ti_btag,
609 sc->ti_bhandle, ti_offset,
610 (uint32_t *)tmparray,
619 * Handle leftover, non-word-aligned bytes.
622 uint32_t tmpval, tmpval2;
623 bus_size_t ti_offset;
626 * Set the segment pointer.
628 CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
630 ti_offset = TI_WINDOW + (segptr & (TI_WINLEN - 1));
633 * First, grab whatever is in our source/destination.
634 * We'll obviously need this for reads, but also for
635 * writes, since we'll be doing read/modify/write.
637 bus_space_read_region_4(sc->ti_btag, sc->ti_bhandle,
638 ti_offset, &tmpval, 1);
641 * Next, translate this from little-endian to big-endian
642 * (at least on i386 boxes).
644 tmpval2 = ntohl(tmpval);
648 * If we're reading, just copy the leftover number
649 * of bytes from the host byte order buffer to
654 copyout(&tmpval2, ptr, resid);
657 bcopy(&tmpval2, ptr, resid);
660 * If we're writing, first copy the bytes to be
661 * written into the network byte order buffer,
662 * leaving the rest of the buffer with whatever was
663 * originally in there. Then, swap the bytes
664 * around into host order and write them out.
666 * XXX KDM the read side of this has been verified
667 * to work, but the write side of it has not been
668 * verified. So user beware.
672 copyin(ptr, &tmpval2, resid);
675 bcopy(ptr, &tmpval2, resid);
677 tmpval = htonl(tmpval2);
679 bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
680 ti_offset, &tmpval, 1);
684 CSR_WRITE_4(sc, TI_WINBASE, origwin);
690 ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
691 caddr_t buf, int useraddr, int readdata, int cpu)
695 uint32_t tmpval, tmpval2;
701 * At the moment, we don't handle non-aligned cases, we just bail.
702 * If this proves to be a problem, it will be fixed.
704 if (tigon_addr & 0x3) {
705 device_printf(sc->ti_dev, "%s: tigon address %#x "
706 "isn't word-aligned\n", __func__, tigon_addr);
711 device_printf(sc->ti_dev, "%s: transfer length %d "
712 "isn't word-aligned\n", __func__, len);
721 CSR_WRITE_4(sc, CPU_REG(TI_SRAM_ADDR, cpu), segptr);
724 tmpval2 = CSR_READ_4(sc, CPU_REG(TI_SRAM_DATA, cpu));
726 tmpval = ntohl(tmpval2);
729 * Note: I've used this debugging interface
730 * extensively with Alteon's 12.3.15 firmware,
731 * compiled with GCC 2.7.2.1 and binutils 2.9.1.
733 * When you compile the firmware without
734 * optimization, which is necessary sometimes in
735 * order to properly step through it, you sometimes
736 * read out a bogus value of 0xc0017c instead of
737 * whatever was supposed to be in that scratchpad
738 * location. That value is on the stack somewhere,
739 * but I've never been able to figure out what was
740 * causing the problem.
742 * The address seems to pop up in random places,
743 * often not in the same place on two subsequent
746 * In any case, the underlying data doesn't seem
747 * to be affected, just the value read out.
752 if (tmpval2 == 0xc0017c)
753 device_printf(sc->ti_dev, "found 0xc0017c at "
754 "%#x (tmpval2)\n", segptr);
756 if (tmpval == 0xc0017c)
757 device_printf(sc->ti_dev, "found 0xc0017c at "
758 "%#x (tmpval)\n", segptr);
761 copyout(&tmpval, ptr, 4);
763 bcopy(&tmpval, ptr, 4);
766 copyin(ptr, &tmpval2, 4);
768 bcopy(ptr, &tmpval2, 4);
770 tmpval = htonl(tmpval2);
772 CSR_WRITE_4(sc, CPU_REG(TI_SRAM_DATA, cpu), tmpval);
784 ti_bcopy_swap(const void *src, void *dst, size_t len, ti_swap_type swap_type)
786 const uint8_t *tmpsrc;
791 printf("ti_bcopy_swap: length %zd isn't 32-bit aligned\n",
801 if (swap_type == TI_SWAP_NTOH)
802 *(uint32_t *)tmpdst =
803 ntohl(*(const uint32_t *)tmpsrc);
805 *(uint32_t *)tmpdst =
806 htonl(*(const uint32_t *)tmpsrc);
817 * Load firmware image into the NIC. Check that the firmware revision
818 * is acceptable and see if we want the firmware for the Tigon 1 or
822 ti_loadfw(struct ti_softc *sc)
827 switch (sc->ti_hwrev) {
829 if (tigonFwReleaseMajor != TI_FIRMWARE_MAJOR ||
830 tigonFwReleaseMinor != TI_FIRMWARE_MINOR ||
831 tigonFwReleaseFix != TI_FIRMWARE_FIX) {
832 device_printf(sc->ti_dev, "firmware revision mismatch; "
833 "want %d.%d.%d, got %d.%d.%d\n",
834 TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR,
835 TI_FIRMWARE_FIX, tigonFwReleaseMajor,
836 tigonFwReleaseMinor, tigonFwReleaseFix);
839 ti_mem_write(sc, tigonFwTextAddr, tigonFwTextLen, tigonFwText);
840 ti_mem_write(sc, tigonFwDataAddr, tigonFwDataLen, tigonFwData);
841 ti_mem_write(sc, tigonFwRodataAddr, tigonFwRodataLen,
843 ti_mem_zero(sc, tigonFwBssAddr, tigonFwBssLen);
844 ti_mem_zero(sc, tigonFwSbssAddr, tigonFwSbssLen);
845 CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigonFwStartAddr);
847 case TI_HWREV_TIGON_II:
848 if (tigon2FwReleaseMajor != TI_FIRMWARE_MAJOR ||
849 tigon2FwReleaseMinor != TI_FIRMWARE_MINOR ||
850 tigon2FwReleaseFix != TI_FIRMWARE_FIX) {
851 device_printf(sc->ti_dev, "firmware revision mismatch; "
852 "want %d.%d.%d, got %d.%d.%d\n",
853 TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR,
854 TI_FIRMWARE_FIX, tigon2FwReleaseMajor,
855 tigon2FwReleaseMinor, tigon2FwReleaseFix);
858 ti_mem_write(sc, tigon2FwTextAddr, tigon2FwTextLen,
860 ti_mem_write(sc, tigon2FwDataAddr, tigon2FwDataLen,
862 ti_mem_write(sc, tigon2FwRodataAddr, tigon2FwRodataLen,
864 ti_mem_zero(sc, tigon2FwBssAddr, tigon2FwBssLen);
865 ti_mem_zero(sc, tigon2FwSbssAddr, tigon2FwSbssLen);
866 CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigon2FwStartAddr);
869 device_printf(sc->ti_dev,
870 "can't load firmware: unknown hardware rev\n");
876 * Send the NIC a command via the command ring.
879 ti_cmd(struct ti_softc *sc, struct ti_cmd_desc *cmd)
883 index = sc->ti_cmd_saved_prodidx;
884 CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(uint32_t *)(cmd));
885 TI_INC(index, TI_CMD_RING_CNT);
886 CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index);
887 sc->ti_cmd_saved_prodidx = index;
891 * Send the NIC an extended command. The 'len' parameter specifies the
892 * number of command slots to include after the initial command.
895 ti_cmd_ext(struct ti_softc *sc, struct ti_cmd_desc *cmd, caddr_t arg, int len)
900 index = sc->ti_cmd_saved_prodidx;
901 CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(uint32_t *)(cmd));
902 TI_INC(index, TI_CMD_RING_CNT);
903 for (i = 0; i < len; i++) {
904 CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4),
905 *(uint32_t *)(&arg[i * 4]));
906 TI_INC(index, TI_CMD_RING_CNT);
908 CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index);
909 sc->ti_cmd_saved_prodidx = index;
913 * Handle events that have triggered interrupts.
916 ti_handle_events(struct ti_softc *sc)
918 struct ti_event_desc *e;
920 if (sc->ti_rdata->ti_event_ring == NULL)
923 while (sc->ti_ev_saved_considx != sc->ti_ev_prodidx.ti_idx) {
924 e = &sc->ti_rdata->ti_event_ring[sc->ti_ev_saved_considx];
925 switch (TI_EVENT_EVENT(e)) {
926 case TI_EV_LINKSTAT_CHANGED:
927 sc->ti_linkstat = TI_EVENT_CODE(e);
928 if (sc->ti_linkstat == TI_EV_CODE_LINK_UP) {
929 if_link_state_change(sc->ti_ifp, LINK_STATE_UP);
930 sc->ti_ifp->if_baudrate = IF_Mbps(100);
932 device_printf(sc->ti_dev,
934 } else if (sc->ti_linkstat == TI_EV_CODE_GIG_LINK_UP) {
935 if_link_state_change(sc->ti_ifp, LINK_STATE_UP);
936 sc->ti_ifp->if_baudrate = IF_Gbps(1UL);
938 device_printf(sc->ti_dev,
939 "gigabit link up\n");
940 } else if (sc->ti_linkstat == TI_EV_CODE_LINK_DOWN) {
941 if_link_state_change(sc->ti_ifp,
943 sc->ti_ifp->if_baudrate = 0;
945 device_printf(sc->ti_dev,
950 if (TI_EVENT_CODE(e) == TI_EV_CODE_ERR_INVAL_CMD)
951 device_printf(sc->ti_dev, "invalid command\n");
952 else if (TI_EVENT_CODE(e) == TI_EV_CODE_ERR_UNIMP_CMD)
953 device_printf(sc->ti_dev, "unknown command\n");
954 else if (TI_EVENT_CODE(e) == TI_EV_CODE_ERR_BADCFG)
955 device_printf(sc->ti_dev, "bad config data\n");
957 case TI_EV_FIRMWARE_UP:
960 case TI_EV_STATS_UPDATED:
963 case TI_EV_RESET_JUMBO_RING:
964 case TI_EV_MCAST_UPDATED:
968 device_printf(sc->ti_dev, "unknown event: %d\n",
972 /* Advance the consumer index. */
973 TI_INC(sc->ti_ev_saved_considx, TI_EVENT_RING_CNT);
974 CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, sc->ti_ev_saved_considx);
979 ti_alloc_dmamaps(struct ti_softc *sc)
983 for (i = 0; i < TI_TX_RING_CNT; i++) {
984 sc->ti_cdata.ti_txdesc[i].tx_m = NULL;
985 sc->ti_cdata.ti_txdesc[i].tx_dmamap = NULL;
986 if (bus_dmamap_create(sc->ti_mbuftx_dmat, 0,
987 &sc->ti_cdata.ti_txdesc[i].tx_dmamap)) {
988 device_printf(sc->ti_dev,
989 "cannot create DMA map for TX\n");
993 for (i = 0; i < TI_STD_RX_RING_CNT; i++) {
994 if (bus_dmamap_create(sc->ti_mbufrx_dmat, 0,
995 &sc->ti_cdata.ti_rx_std_maps[i])) {
996 device_printf(sc->ti_dev,
997 "cannot create DMA map for RX\n");
1001 if (bus_dmamap_create(sc->ti_mbufrx_dmat, 0,
1002 &sc->ti_cdata.ti_rx_std_sparemap)) {
1003 device_printf(sc->ti_dev,
1004 "cannot create spare DMA map for RX\n");
1008 for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
1009 if (bus_dmamap_create(sc->ti_jumbo_dmat, 0,
1010 &sc->ti_cdata.ti_rx_jumbo_maps[i])) {
1011 device_printf(sc->ti_dev,
1012 "cannot create DMA map for jumbo RX\n");
1016 if (bus_dmamap_create(sc->ti_jumbo_dmat, 0,
1017 &sc->ti_cdata.ti_rx_jumbo_sparemap)) {
1018 device_printf(sc->ti_dev,
1019 "cannot create spare DMA map for jumbo RX\n");
1023 /* Mini ring is not available on Tigon 1. */
1024 if (sc->ti_hwrev == TI_HWREV_TIGON)
1027 for (i = 0; i < TI_MINI_RX_RING_CNT; i++) {
1028 if (bus_dmamap_create(sc->ti_mbufrx_dmat, 0,
1029 &sc->ti_cdata.ti_rx_mini_maps[i])) {
1030 device_printf(sc->ti_dev,
1031 "cannot create DMA map for mini RX\n");
1035 if (bus_dmamap_create(sc->ti_mbufrx_dmat, 0,
1036 &sc->ti_cdata.ti_rx_mini_sparemap)) {
1037 device_printf(sc->ti_dev,
1038 "cannot create DMA map for mini RX\n");
1046 ti_free_dmamaps(struct ti_softc *sc)
1050 if (sc->ti_mbuftx_dmat) {
1051 for (i = 0; i < TI_TX_RING_CNT; i++) {
1052 if (sc->ti_cdata.ti_txdesc[i].tx_dmamap) {
1053 bus_dmamap_destroy(sc->ti_mbuftx_dmat,
1054 sc->ti_cdata.ti_txdesc[i].tx_dmamap);
1055 sc->ti_cdata.ti_txdesc[i].tx_dmamap = NULL;
1060 if (sc->ti_mbufrx_dmat) {
1061 for (i = 0; i < TI_STD_RX_RING_CNT; i++) {
1062 if (sc->ti_cdata.ti_rx_std_maps[i]) {
1063 bus_dmamap_destroy(sc->ti_mbufrx_dmat,
1064 sc->ti_cdata.ti_rx_std_maps[i]);
1065 sc->ti_cdata.ti_rx_std_maps[i] = NULL;
1068 if (sc->ti_cdata.ti_rx_std_sparemap) {
1069 bus_dmamap_destroy(sc->ti_mbufrx_dmat,
1070 sc->ti_cdata.ti_rx_std_sparemap);
1071 sc->ti_cdata.ti_rx_std_sparemap = NULL;
1075 if (sc->ti_jumbo_dmat) {
1076 for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
1077 if (sc->ti_cdata.ti_rx_jumbo_maps[i]) {
1078 bus_dmamap_destroy(sc->ti_jumbo_dmat,
1079 sc->ti_cdata.ti_rx_jumbo_maps[i]);
1080 sc->ti_cdata.ti_rx_jumbo_maps[i] = NULL;
1083 if (sc->ti_cdata.ti_rx_jumbo_sparemap) {
1084 bus_dmamap_destroy(sc->ti_jumbo_dmat,
1085 sc->ti_cdata.ti_rx_jumbo_sparemap);
1086 sc->ti_cdata.ti_rx_jumbo_sparemap = NULL;
1090 if (sc->ti_mbufrx_dmat) {
1091 for (i = 0; i < TI_MINI_RX_RING_CNT; i++) {
1092 if (sc->ti_cdata.ti_rx_mini_maps[i]) {
1093 bus_dmamap_destroy(sc->ti_mbufrx_dmat,
1094 sc->ti_cdata.ti_rx_mini_maps[i]);
1095 sc->ti_cdata.ti_rx_mini_maps[i] = NULL;
1098 if (sc->ti_cdata.ti_rx_mini_sparemap) {
1099 bus_dmamap_destroy(sc->ti_mbufrx_dmat,
1100 sc->ti_cdata.ti_rx_mini_sparemap);
1101 sc->ti_cdata.ti_rx_mini_sparemap = NULL;
1106 #ifndef TI_SF_BUF_JUMBO
1109 ti_alloc_jumbo_mem(struct ti_softc *sc)
1112 if (bus_dma_tag_create(sc->ti_parent_dmat, 1, 0, BUS_SPACE_MAXADDR,
1113 BUS_SPACE_MAXADDR, NULL, NULL, MJUM9BYTES, 1, MJUM9BYTES, 0, NULL,
1114 NULL, &sc->ti_jumbo_dmat) != 0) {
1115 device_printf(sc->ti_dev, "Failed to allocate jumbo dmat\n");
1124 ti_alloc_jumbo_mem(struct ti_softc *sc)
1128 * The VM system will take care of providing aligned pages. Alignment
1129 * is set to 1 here so that busdma resources won't be wasted.
1131 if (bus_dma_tag_create(sc->ti_parent_dmat, /* parent */
1132 1, 0, /* algnmnt, boundary */
1133 BUS_SPACE_MAXADDR, /* lowaddr */
1134 BUS_SPACE_MAXADDR, /* highaddr */
1135 NULL, NULL, /* filter, filterarg */
1136 PAGE_SIZE * 4 /*XXX*/, /* maxsize */
1138 PAGE_SIZE, /* maxsegsize */
1140 NULL, NULL, /* lockfunc, lockarg */
1141 &sc->ti_jumbo_dmat) != 0) {
1142 device_printf(sc->ti_dev, "Failed to allocate jumbo dmat\n");
1149 #endif /* TI_SF_BUF_JUMBO */
1152 * Intialize a standard receive ring descriptor.
1155 ti_newbuf_std(struct ti_softc *sc, int i)
1158 bus_dma_segment_t segs[1];
1160 struct ti_rx_desc *r;
1163 m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1166 m->m_len = m->m_pkthdr.len = MCLBYTES;
1167 m_adj(m, ETHER_ALIGN);
1169 error = bus_dmamap_load_mbuf_sg(sc->ti_mbufrx_dmat,
1170 sc->ti_cdata.ti_rx_std_sparemap, m, segs, &nsegs, 0);
1175 KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
1177 if (sc->ti_cdata.ti_rx_std_chain[i] != NULL) {
1178 bus_dmamap_sync(sc->ti_mbufrx_dmat,
1179 sc->ti_cdata.ti_rx_std_maps[i], BUS_DMASYNC_POSTREAD);
1180 bus_dmamap_unload(sc->ti_mbufrx_dmat,
1181 sc->ti_cdata.ti_rx_std_maps[i]);
1184 map = sc->ti_cdata.ti_rx_std_maps[i];
1185 sc->ti_cdata.ti_rx_std_maps[i] = sc->ti_cdata.ti_rx_std_sparemap;
1186 sc->ti_cdata.ti_rx_std_sparemap = map;
1187 sc->ti_cdata.ti_rx_std_chain[i] = m;
1189 r = &sc->ti_rdata->ti_rx_std_ring[i];
1190 ti_hostaddr64(&r->ti_addr, segs[0].ds_addr);
1191 r->ti_len = segs[0].ds_len;
1192 r->ti_type = TI_BDTYPE_RECV_BD;
1195 r->ti_tcp_udp_cksum = 0;
1196 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
1197 r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
1200 bus_dmamap_sync(sc->ti_mbufrx_dmat, sc->ti_cdata.ti_rx_std_maps[i],
1201 BUS_DMASYNC_PREREAD);
1206 * Intialize a mini receive ring descriptor. This only applies to
1210 ti_newbuf_mini(struct ti_softc *sc, int i)
1213 bus_dma_segment_t segs[1];
1215 struct ti_rx_desc *r;
1218 MGETHDR(m, M_DONTWAIT, MT_DATA);
1221 m->m_len = m->m_pkthdr.len = MHLEN;
1222 m_adj(m, ETHER_ALIGN);
1224 error = bus_dmamap_load_mbuf_sg(sc->ti_mbufrx_dmat,
1225 sc->ti_cdata.ti_rx_mini_sparemap, m, segs, &nsegs, 0);
1230 KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
1232 if (sc->ti_cdata.ti_rx_mini_chain[i] != NULL) {
1233 bus_dmamap_sync(sc->ti_mbufrx_dmat,
1234 sc->ti_cdata.ti_rx_mini_maps[i], BUS_DMASYNC_POSTREAD);
1235 bus_dmamap_unload(sc->ti_mbufrx_dmat,
1236 sc->ti_cdata.ti_rx_mini_maps[i]);
1239 map = sc->ti_cdata.ti_rx_mini_maps[i];
1240 sc->ti_cdata.ti_rx_mini_maps[i] = sc->ti_cdata.ti_rx_mini_sparemap;
1241 sc->ti_cdata.ti_rx_mini_sparemap = map;
1242 sc->ti_cdata.ti_rx_mini_chain[i] = m;
1244 r = &sc->ti_rdata->ti_rx_mini_ring[i];
1245 ti_hostaddr64(&r->ti_addr, segs[0].ds_addr);
1246 r->ti_len = segs[0].ds_len;
1247 r->ti_type = TI_BDTYPE_RECV_BD;
1248 r->ti_flags = TI_BDFLAG_MINI_RING;
1250 r->ti_tcp_udp_cksum = 0;
1251 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
1252 r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
1255 bus_dmamap_sync(sc->ti_mbufrx_dmat, sc->ti_cdata.ti_rx_mini_maps[i],
1256 BUS_DMASYNC_PREREAD);
1260 #ifndef TI_SF_BUF_JUMBO
1263 * Initialize a jumbo receive ring descriptor. This allocates
1264 * a jumbo buffer from the pool managed internally by the driver.
1267 ti_newbuf_jumbo(struct ti_softc *sc, int i, struct mbuf *dummy)
1270 bus_dma_segment_t segs[1];
1272 struct ti_rx_desc *r;
1277 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, MJUM9BYTES);
1280 m->m_len = m->m_pkthdr.len = MJUM9BYTES;
1281 m_adj(m, ETHER_ALIGN);
1283 error = bus_dmamap_load_mbuf_sg(sc->ti_jumbo_dmat,
1284 sc->ti_cdata.ti_rx_jumbo_sparemap, m, segs, &nsegs, 0);
1289 KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
1291 if (sc->ti_cdata.ti_rx_jumbo_chain[i] != NULL) {
1292 bus_dmamap_sync(sc->ti_jumbo_dmat,
1293 sc->ti_cdata.ti_rx_jumbo_maps[i], BUS_DMASYNC_POSTREAD);
1294 bus_dmamap_unload(sc->ti_jumbo_dmat,
1295 sc->ti_cdata.ti_rx_jumbo_maps[i]);
1298 map = sc->ti_cdata.ti_rx_jumbo_maps[i];
1299 sc->ti_cdata.ti_rx_jumbo_maps[i] = sc->ti_cdata.ti_rx_jumbo_sparemap;
1300 sc->ti_cdata.ti_rx_jumbo_sparemap = map;
1301 sc->ti_cdata.ti_rx_jumbo_chain[i] = m;
1303 r = &sc->ti_rdata->ti_rx_jumbo_ring[i];
1304 ti_hostaddr64(&r->ti_addr, segs[0].ds_addr);
1305 r->ti_len = segs[0].ds_len;
1306 r->ti_type = TI_BDTYPE_RECV_JUMBO_BD;
1307 r->ti_flags = TI_BDFLAG_JUMBO_RING;
1309 r->ti_tcp_udp_cksum = 0;
1310 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
1311 r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
1314 bus_dmamap_sync(sc->ti_jumbo_dmat, sc->ti_cdata.ti_rx_jumbo_maps[i],
1315 BUS_DMASYNC_PREREAD);
1321 #if (PAGE_SIZE == 4096)
1327 #define TCP_HDR_LEN (52 + sizeof(struct ether_header))
1328 #define UDP_HDR_LEN (28 + sizeof(struct ether_header))
1329 #define NFS_HDR_LEN (UDP_HDR_LEN)
1330 static int HDR_LEN = TCP_HDR_LEN;
1333 * Initialize a jumbo receive ring descriptor. This allocates
1334 * a jumbo buffer from the pool managed internally by the driver.
1337 ti_newbuf_jumbo(struct ti_softc *sc, int idx, struct mbuf *m_old)
1340 struct mbuf *cur, *m_new = NULL;
1341 struct mbuf *m[3] = {NULL, NULL, NULL};
1342 struct ti_rx_desc_ext *r;
1345 /* 1 extra buf to make nobufs easy*/
1346 struct sf_buf *sf[3] = {NULL, NULL, NULL};
1348 bus_dma_segment_t segs[4];
1351 if (m_old != NULL) {
1353 cur = m_old->m_next;
1354 for (i = 0; i <= NPAYLOAD; i++){
1359 /* Allocate the mbufs. */
1360 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
1361 if (m_new == NULL) {
1362 device_printf(sc->ti_dev, "mbuf allocation failed "
1363 "-- packet dropped!\n");
1366 MGET(m[NPAYLOAD], M_DONTWAIT, MT_DATA);
1367 if (m[NPAYLOAD] == NULL) {
1368 device_printf(sc->ti_dev, "cluster mbuf allocation "
1369 "failed -- packet dropped!\n");
1372 MCLGET(m[NPAYLOAD], M_DONTWAIT);
1373 if ((m[NPAYLOAD]->m_flags & M_EXT) == 0) {
1374 device_printf(sc->ti_dev, "mbuf allocation failed "
1375 "-- packet dropped!\n");
1378 m[NPAYLOAD]->m_len = MCLBYTES;
1380 for (i = 0; i < NPAYLOAD; i++){
1381 MGET(m[i], M_DONTWAIT, MT_DATA);
1383 device_printf(sc->ti_dev, "mbuf allocation "
1384 "failed -- packet dropped!\n");
1387 frame = vm_page_alloc(NULL, color++,
1388 VM_ALLOC_INTERRUPT | VM_ALLOC_NOOBJ |
1390 if (frame == NULL) {
1391 device_printf(sc->ti_dev, "buffer allocation "
1392 "failed -- packet dropped!\n");
1393 printf(" index %d page %d\n", idx, i);
1396 sf[i] = sf_buf_alloc(frame, SFB_NOWAIT);
1397 if (sf[i] == NULL) {
1398 vm_page_lock_queues();
1399 vm_page_unwire(frame, 0);
1400 vm_page_free(frame);
1401 vm_page_unlock_queues();
1402 device_printf(sc->ti_dev, "buffer allocation "
1403 "failed -- packet dropped!\n");
1404 printf(" index %d page %d\n", idx, i);
1408 for (i = 0; i < NPAYLOAD; i++){
1409 /* Attach the buffer to the mbuf. */
1410 m[i]->m_data = (void *)sf_buf_kva(sf[i]);
1411 m[i]->m_len = PAGE_SIZE;
1412 MEXTADD(m[i], sf_buf_kva(sf[i]), PAGE_SIZE,
1413 sf_buf_mext, (void*)sf_buf_kva(sf[i]), sf[i],
1415 m[i]->m_next = m[i+1];
1417 /* link the buffers to the header */
1418 m_new->m_next = m[0];
1419 m_new->m_data += ETHER_ALIGN;
1420 if (sc->ti_hdrsplit)
1421 m_new->m_len = MHLEN - ETHER_ALIGN;
1423 m_new->m_len = HDR_LEN;
1424 m_new->m_pkthdr.len = NPAYLOAD * PAGE_SIZE + m_new->m_len;
1427 /* Set up the descriptor. */
1428 r = &sc->ti_rdata->ti_rx_jumbo_ring[idx];
1429 sc->ti_cdata.ti_rx_jumbo_chain[idx] = m_new;
1430 map = sc->ti_cdata.ti_rx_jumbo_maps[i];
1431 if (bus_dmamap_load_mbuf_sg(sc->ti_jumbo_dmat, map, m_new, segs,
1434 if ((nsegs < 1) || (nsegs > 4))
1436 ti_hostaddr64(&r->ti_addr0, segs[0].ds_addr);
1437 r->ti_len0 = m_new->m_len;
1439 ti_hostaddr64(&r->ti_addr1, segs[1].ds_addr);
1440 r->ti_len1 = PAGE_SIZE;
1442 ti_hostaddr64(&r->ti_addr2, segs[2].ds_addr);
1443 r->ti_len2 = m[1]->m_ext.ext_size; /* could be PAGE_SIZE or MCLBYTES */
1445 if (PAGE_SIZE == 4096) {
1446 ti_hostaddr64(&r->ti_addr3, segs[3].ds_addr);
1447 r->ti_len3 = MCLBYTES;
1451 r->ti_type = TI_BDTYPE_RECV_JUMBO_BD;
1453 r->ti_flags = TI_BDFLAG_JUMBO_RING|TI_RCB_FLAG_USE_EXT_RX_BD;
1455 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
1456 r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
1460 bus_dmamap_sync(sc->ti_jumbo_dmat, map, BUS_DMASYNC_PREREAD);
1467 * This can only be called before the mbufs are strung together.
1468 * If the mbufs are strung together, m_freem() will free the chain,
1469 * so that the later mbufs will be freed multiple times.
1474 for (i = 0; i < 3; i++) {
1478 sf_buf_mext((void *)sf_buf_kva(sf[i]), sf[i]);
1485 * The standard receive ring has 512 entries in it. At 2K per mbuf cluster,
1486 * that's 1MB or memory, which is a lot. For now, we fill only the first
1487 * 256 ring entries and hope that our CPU is fast enough to keep up with
1491 ti_init_rx_ring_std(struct ti_softc *sc)
1494 struct ti_cmd_desc cmd;
1496 for (i = 0; i < TI_STD_RX_RING_CNT; i++) {
1497 if (ti_newbuf_std(sc, i) != 0)
1501 sc->ti_std = TI_STD_RX_RING_CNT - 1;
1502 TI_UPDATE_STDPROD(sc, TI_STD_RX_RING_CNT - 1);
1508 ti_free_rx_ring_std(struct ti_softc *sc)
1513 for (i = 0; i < TI_STD_RX_RING_CNT; i++) {
1514 if (sc->ti_cdata.ti_rx_std_chain[i] != NULL) {
1515 map = sc->ti_cdata.ti_rx_std_maps[i];
1516 bus_dmamap_sync(sc->ti_mbufrx_dmat, map,
1517 BUS_DMASYNC_POSTREAD);
1518 bus_dmamap_unload(sc->ti_mbufrx_dmat, map);
1519 m_freem(sc->ti_cdata.ti_rx_std_chain[i]);
1520 sc->ti_cdata.ti_rx_std_chain[i] = NULL;
1522 bzero((char *)&sc->ti_rdata->ti_rx_std_ring[i],
1523 sizeof(struct ti_rx_desc));
1528 ti_init_rx_ring_jumbo(struct ti_softc *sc)
1530 struct ti_cmd_desc cmd;
1533 for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
1534 if (ti_newbuf_jumbo(sc, i, NULL) != 0)
1538 sc->ti_jumbo = TI_JUMBO_RX_RING_CNT - 1;
1539 TI_UPDATE_JUMBOPROD(sc, TI_JUMBO_RX_RING_CNT - 1);
1545 ti_free_rx_ring_jumbo(struct ti_softc *sc)
1550 for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
1551 if (sc->ti_cdata.ti_rx_jumbo_chain[i] != NULL) {
1552 map = sc->ti_cdata.ti_rx_jumbo_maps[i];
1553 bus_dmamap_sync(sc->ti_jumbo_dmat, map,
1554 BUS_DMASYNC_POSTREAD);
1555 bus_dmamap_unload(sc->ti_jumbo_dmat, map);
1556 m_freem(sc->ti_cdata.ti_rx_jumbo_chain[i]);
1557 sc->ti_cdata.ti_rx_jumbo_chain[i] = NULL;
1559 bzero((char *)&sc->ti_rdata->ti_rx_jumbo_ring[i],
1560 sizeof(struct ti_rx_desc));
1565 ti_init_rx_ring_mini(struct ti_softc *sc)
1569 for (i = 0; i < TI_MINI_RX_RING_CNT; i++) {
1570 if (ti_newbuf_mini(sc, i) != 0)
1574 sc->ti_mini = TI_MINI_RX_RING_CNT - 1;
1575 TI_UPDATE_MINIPROD(sc, TI_MINI_RX_RING_CNT - 1);
1581 ti_free_rx_ring_mini(struct ti_softc *sc)
1586 for (i = 0; i < TI_MINI_RX_RING_CNT; i++) {
1587 if (sc->ti_cdata.ti_rx_mini_chain[i] != NULL) {
1588 map = sc->ti_cdata.ti_rx_mini_maps[i];
1589 bus_dmamap_sync(sc->ti_mbufrx_dmat, map,
1590 BUS_DMASYNC_POSTREAD);
1591 bus_dmamap_unload(sc->ti_mbufrx_dmat, map);
1592 m_freem(sc->ti_cdata.ti_rx_mini_chain[i]);
1593 sc->ti_cdata.ti_rx_mini_chain[i] = NULL;
1595 bzero((char *)&sc->ti_rdata->ti_rx_mini_ring[i],
1596 sizeof(struct ti_rx_desc));
1601 ti_free_tx_ring(struct ti_softc *sc)
1603 struct ti_txdesc *txd;
1606 if (sc->ti_rdata->ti_tx_ring == NULL)
1609 for (i = 0; i < TI_TX_RING_CNT; i++) {
1610 txd = &sc->ti_cdata.ti_txdesc[i];
1611 if (txd->tx_m != NULL) {
1612 bus_dmamap_sync(sc->ti_mbuftx_dmat, txd->tx_dmamap,
1613 BUS_DMASYNC_POSTWRITE);
1614 bus_dmamap_unload(sc->ti_mbuftx_dmat, txd->tx_dmamap);
1618 bzero((char *)&sc->ti_rdata->ti_tx_ring[i],
1619 sizeof(struct ti_tx_desc));
1624 ti_init_tx_ring(struct ti_softc *sc)
1626 struct ti_txdesc *txd;
1629 STAILQ_INIT(&sc->ti_cdata.ti_txfreeq);
1630 STAILQ_INIT(&sc->ti_cdata.ti_txbusyq);
1631 for (i = 0; i < TI_TX_RING_CNT; i++) {
1632 txd = &sc->ti_cdata.ti_txdesc[i];
1633 STAILQ_INSERT_TAIL(&sc->ti_cdata.ti_txfreeq, txd, tx_q);
1636 sc->ti_tx_saved_considx = 0;
1637 sc->ti_tx_saved_prodidx = 0;
1638 CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, 0);
1643 * The Tigon 2 firmware has a new way to add/delete multicast addresses,
1644 * but we have to support the old way too so that Tigon 1 cards will
1648 ti_add_mcast(struct ti_softc *sc, struct ether_addr *addr)
1650 struct ti_cmd_desc cmd;
1652 uint32_t ext[2] = {0, 0};
1654 m = (uint16_t *)&addr->octet[0];
1656 switch (sc->ti_hwrev) {
1657 case TI_HWREV_TIGON:
1658 CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0]));
1659 CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2]));
1660 TI_DO_CMD(TI_CMD_ADD_MCAST_ADDR, 0, 0);
1662 case TI_HWREV_TIGON_II:
1663 ext[0] = htons(m[0]);
1664 ext[1] = (htons(m[1]) << 16) | htons(m[2]);
1665 TI_DO_CMD_EXT(TI_CMD_EXT_ADD_MCAST, 0, 0, (caddr_t)&ext, 2);
1668 device_printf(sc->ti_dev, "unknown hwrev\n");
1674 ti_del_mcast(struct ti_softc *sc, struct ether_addr *addr)
1676 struct ti_cmd_desc cmd;
1678 uint32_t ext[2] = {0, 0};
1680 m = (uint16_t *)&addr->octet[0];
1682 switch (sc->ti_hwrev) {
1683 case TI_HWREV_TIGON:
1684 CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0]));
1685 CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2]));
1686 TI_DO_CMD(TI_CMD_DEL_MCAST_ADDR, 0, 0);
1688 case TI_HWREV_TIGON_II:
1689 ext[0] = htons(m[0]);
1690 ext[1] = (htons(m[1]) << 16) | htons(m[2]);
1691 TI_DO_CMD_EXT(TI_CMD_EXT_DEL_MCAST, 0, 0, (caddr_t)&ext, 2);
1694 device_printf(sc->ti_dev, "unknown hwrev\n");
1700 * Configure the Tigon's multicast address filter.
1702 * The actual multicast table management is a bit of a pain, thanks to
1703 * slight brain damage on the part of both Alteon and us. With our
1704 * multicast code, we are only alerted when the multicast address table
1705 * changes and at that point we only have the current list of addresses:
1706 * we only know the current state, not the previous state, so we don't
1707 * actually know what addresses were removed or added. The firmware has
1708 * state, but we can't get our grubby mits on it, and there is no 'delete
1709 * all multicast addresses' command. Hence, we have to maintain our own
1710 * state so we know what addresses have been programmed into the NIC at
1714 ti_setmulti(struct ti_softc *sc)
1717 struct ifmultiaddr *ifma;
1718 struct ti_cmd_desc cmd;
1719 struct ti_mc_entry *mc;
1726 if (ifp->if_flags & IFF_ALLMULTI) {
1727 TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_ENB, 0);
1730 TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_DIS, 0);
1733 /* Disable interrupts. */
1734 intrs = CSR_READ_4(sc, TI_MB_HOSTINTR);
1735 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
1737 /* First, zot all the existing filters. */
1738 while (SLIST_FIRST(&sc->ti_mc_listhead) != NULL) {
1739 mc = SLIST_FIRST(&sc->ti_mc_listhead);
1740 ti_del_mcast(sc, &mc->mc_addr);
1741 SLIST_REMOVE_HEAD(&sc->ti_mc_listhead, mc_entries);
1745 /* Now program new ones. */
1746 if_maddr_rlock(ifp);
1747 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1748 if (ifma->ifma_addr->sa_family != AF_LINK)
1750 mc = malloc(sizeof(struct ti_mc_entry), M_DEVBUF, M_NOWAIT);
1752 device_printf(sc->ti_dev,
1753 "no memory for mcast filter entry\n");
1756 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
1757 (char *)&mc->mc_addr, ETHER_ADDR_LEN);
1758 SLIST_INSERT_HEAD(&sc->ti_mc_listhead, mc, mc_entries);
1759 ti_add_mcast(sc, &mc->mc_addr);
1761 if_maddr_runlock(ifp);
1763 /* Re-enable interrupts. */
1764 CSR_WRITE_4(sc, TI_MB_HOSTINTR, intrs);
1768 * Check to see if the BIOS has configured us for a 64 bit slot when
1769 * we aren't actually in one. If we detect this condition, we can work
1770 * around it on the Tigon 2 by setting a bit in the PCI state register,
1771 * but for the Tigon 1 we must give up and abort the interface attach.
1773 static int ti_64bitslot_war(struct ti_softc *sc)
1776 if (!(CSR_READ_4(sc, TI_PCI_STATE) & TI_PCISTATE_32BIT_BUS)) {
1777 CSR_WRITE_4(sc, 0x600, 0);
1778 CSR_WRITE_4(sc, 0x604, 0);
1779 CSR_WRITE_4(sc, 0x600, 0x5555AAAA);
1780 if (CSR_READ_4(sc, 0x604) == 0x5555AAAA) {
1781 if (sc->ti_hwrev == TI_HWREV_TIGON)
1784 TI_SETBIT(sc, TI_PCI_STATE,
1785 TI_PCISTATE_32BIT_BUS);
1795 * Do endian, PCI and DMA initialization. Also check the on-board ROM
1796 * self-test results.
1799 ti_chipinit(struct ti_softc *sc)
1802 uint32_t pci_writemax = 0;
1805 /* Initialize link to down state. */
1806 sc->ti_linkstat = TI_EV_CODE_LINK_DOWN;
1808 /* Set endianness before we access any non-PCI registers. */
1809 #if 0 && BYTE_ORDER == BIG_ENDIAN
1810 CSR_WRITE_4(sc, TI_MISC_HOST_CTL,
1811 TI_MHC_BIGENDIAN_INIT | (TI_MHC_BIGENDIAN_INIT << 24));
1813 CSR_WRITE_4(sc, TI_MISC_HOST_CTL,
1814 TI_MHC_LITTLEENDIAN_INIT | (TI_MHC_LITTLEENDIAN_INIT << 24));
1817 /* Check the ROM failed bit to see if self-tests passed. */
1818 if (CSR_READ_4(sc, TI_CPU_STATE) & TI_CPUSTATE_ROMFAIL) {
1819 device_printf(sc->ti_dev, "board self-diagnostics failed!\n");
1824 TI_SETBIT(sc, TI_CPU_STATE, TI_CPUSTATE_HALT);
1826 /* Figure out the hardware revision. */
1827 switch (CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_CHIP_REV_MASK) {
1828 case TI_REV_TIGON_I:
1829 sc->ti_hwrev = TI_HWREV_TIGON;
1831 case TI_REV_TIGON_II:
1832 sc->ti_hwrev = TI_HWREV_TIGON_II;
1835 device_printf(sc->ti_dev, "unsupported chip revision\n");
1839 /* Do special setup for Tigon 2. */
1840 if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
1841 TI_SETBIT(sc, TI_CPU_CTL_B, TI_CPUSTATE_HALT);
1842 TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_SRAM_BANK_512K);
1843 TI_SETBIT(sc, TI_MISC_CONF, TI_MCR_SRAM_SYNCHRONOUS);
1847 * We don't have firmware source for the Tigon 1, so Tigon 1 boards
1848 * can't do header splitting.
1850 #ifdef TI_JUMBO_HDRSPLIT
1851 if (sc->ti_hwrev != TI_HWREV_TIGON)
1852 sc->ti_hdrsplit = 1;
1854 device_printf(sc->ti_dev,
1855 "can't do header splitting on a Tigon I board\n");
1856 #endif /* TI_JUMBO_HDRSPLIT */
1858 /* Set up the PCI state register. */
1859 CSR_WRITE_4(sc, TI_PCI_STATE, TI_PCI_READ_CMD|TI_PCI_WRITE_CMD);
1860 if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
1861 TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_USE_MEM_RD_MULT);
1864 /* Clear the read/write max DMA parameters. */
1865 TI_CLRBIT(sc, TI_PCI_STATE, (TI_PCISTATE_WRITE_MAXDMA|
1866 TI_PCISTATE_READ_MAXDMA));
1868 /* Get cache line size. */
1869 cacheline = CSR_READ_4(sc, TI_PCI_BIST) & 0xFF;
1872 * If the system has set enabled the PCI memory write
1873 * and invalidate command in the command register, set
1874 * the write max parameter accordingly. This is necessary
1875 * to use MWI with the Tigon 2.
1877 if (CSR_READ_4(sc, TI_PCI_CMDSTAT) & PCIM_CMD_MWIEN) {
1878 switch (cacheline) {
1887 /* Disable PCI memory write and invalidate. */
1889 device_printf(sc->ti_dev, "cache line size %d"
1890 " not supported; disabling PCI MWI\n",
1892 CSR_WRITE_4(sc, TI_PCI_CMDSTAT, CSR_READ_4(sc,
1893 TI_PCI_CMDSTAT) & ~PCIM_CMD_MWIEN);
1898 TI_SETBIT(sc, TI_PCI_STATE, pci_writemax);
1900 /* This sets the min dma param all the way up (0xff). */
1901 TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_MINDMA);
1903 if (sc->ti_hdrsplit)
1904 hdrsplit = TI_OPMODE_JUMBO_HDRSPLIT;
1908 /* Configure DMA variables. */
1909 #if BYTE_ORDER == BIG_ENDIAN
1910 CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_BD |
1911 TI_OPMODE_BYTESWAP_DATA | TI_OPMODE_WORDSWAP_BD |
1912 TI_OPMODE_WARN_ENB | TI_OPMODE_FATAL_ENB |
1913 TI_OPMODE_DONT_FRAG_JUMBO | hdrsplit);
1914 #else /* BYTE_ORDER */
1915 CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_DATA|
1916 TI_OPMODE_WORDSWAP_BD|TI_OPMODE_DONT_FRAG_JUMBO|
1917 TI_OPMODE_WARN_ENB|TI_OPMODE_FATAL_ENB | hdrsplit);
1918 #endif /* BYTE_ORDER */
1921 * Only allow 1 DMA channel to be active at a time.
1922 * I don't think this is a good idea, but without it
1923 * the firmware racks up lots of nicDmaReadRingFull
1924 * errors. This is not compatible with hardware checksums.
1926 if ((sc->ti_ifp->if_capenable & (IFCAP_TXCSUM | IFCAP_RXCSUM)) == 0)
1927 TI_SETBIT(sc, TI_GCR_OPMODE, TI_OPMODE_1_DMA_ACTIVE);
1929 /* Recommended settings from Tigon manual. */
1930 CSR_WRITE_4(sc, TI_GCR_DMA_WRITECFG, TI_DMA_STATE_THRESH_8W);
1931 CSR_WRITE_4(sc, TI_GCR_DMA_READCFG, TI_DMA_STATE_THRESH_8W);
1933 if (ti_64bitslot_war(sc)) {
1934 device_printf(sc->ti_dev, "bios thinks we're in a 64 bit slot, "
1943 * Initialize the general information block and firmware, and
1944 * start the CPU(s) running.
1947 ti_gibinit(struct ti_softc *sc)
1957 rdphys = sc->ti_rdata_phys;
1959 /* Disable interrupts for now. */
1960 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
1963 * Tell the chip where to find the general information block.
1964 * While this struct could go into >4GB memory, we allocate it in a
1965 * single slab with the other descriptors, and those don't seem to
1966 * support being located in a 64-bit region.
1968 CSR_WRITE_4(sc, TI_GCR_GENINFO_HI, 0);
1969 CSR_WRITE_4(sc, TI_GCR_GENINFO_LO, rdphys + TI_RD_OFF(ti_info));
1971 /* Load the firmware into SRAM. */
1974 /* Set up the contents of the general info and ring control blocks. */
1976 /* Set up the event ring and producer pointer. */
1977 rcb = &sc->ti_rdata->ti_info.ti_ev_rcb;
1979 TI_HOSTADDR(rcb->ti_hostaddr) = rdphys + TI_RD_OFF(ti_event_ring);
1981 TI_HOSTADDR(sc->ti_rdata->ti_info.ti_ev_prodidx_ptr) =
1982 rdphys + TI_RD_OFF(ti_ev_prodidx_r);
1983 sc->ti_ev_prodidx.ti_idx = 0;
1984 CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, 0);
1985 sc->ti_ev_saved_considx = 0;
1987 /* Set up the command ring and producer mailbox. */
1988 rcb = &sc->ti_rdata->ti_info.ti_cmd_rcb;
1990 TI_HOSTADDR(rcb->ti_hostaddr) = TI_GCR_NIC_ADDR(TI_GCR_CMDRING);
1992 rcb->ti_max_len = 0;
1993 for (i = 0; i < TI_CMD_RING_CNT; i++) {
1994 CSR_WRITE_4(sc, TI_GCR_CMDRING + (i * 4), 0);
1996 CSR_WRITE_4(sc, TI_GCR_CMDCONS_IDX, 0);
1997 CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, 0);
1998 sc->ti_cmd_saved_prodidx = 0;
2001 * Assign the address of the stats refresh buffer.
2002 * We re-use the current stats buffer for this to
2005 TI_HOSTADDR(sc->ti_rdata->ti_info.ti_refresh_stats_ptr) =
2006 rdphys + TI_RD_OFF(ti_info.ti_stats);
2008 /* Set up the standard receive ring. */
2009 rcb = &sc->ti_rdata->ti_info.ti_std_rx_rcb;
2010 TI_HOSTADDR(rcb->ti_hostaddr) = rdphys + TI_RD_OFF(ti_rx_std_ring);
2011 rcb->ti_max_len = TI_FRAMELEN;
2013 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
2014 rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
2015 TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
2016 if (sc->ti_ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
2017 rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
2019 /* Set up the jumbo receive ring. */
2020 rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
2021 TI_HOSTADDR(rcb->ti_hostaddr) = rdphys + TI_RD_OFF(ti_rx_jumbo_ring);
2023 #ifndef TI_SF_BUF_JUMBO
2024 rcb->ti_max_len = MJUM9BYTES - ETHER_ALIGN;
2027 rcb->ti_max_len = PAGE_SIZE;
2028 rcb->ti_flags = TI_RCB_FLAG_USE_EXT_RX_BD;
2030 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
2031 rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
2032 TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
2033 if (sc->ti_ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
2034 rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
2037 * Set up the mini ring. Only activated on the
2038 * Tigon 2 but the slot in the config block is
2039 * still there on the Tigon 1.
2041 rcb = &sc->ti_rdata->ti_info.ti_mini_rx_rcb;
2042 TI_HOSTADDR(rcb->ti_hostaddr) = rdphys + TI_RD_OFF(ti_rx_mini_ring);
2043 rcb->ti_max_len = MHLEN - ETHER_ALIGN;
2044 if (sc->ti_hwrev == TI_HWREV_TIGON)
2045 rcb->ti_flags = TI_RCB_FLAG_RING_DISABLED;
2048 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
2049 rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
2050 TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
2051 if (sc->ti_ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
2052 rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
2055 * Set up the receive return ring.
2057 rcb = &sc->ti_rdata->ti_info.ti_return_rcb;
2058 TI_HOSTADDR(rcb->ti_hostaddr) = rdphys + TI_RD_OFF(ti_rx_return_ring);
2060 rcb->ti_max_len = TI_RETURN_RING_CNT;
2061 TI_HOSTADDR(sc->ti_rdata->ti_info.ti_return_prodidx_ptr) =
2062 rdphys + TI_RD_OFF(ti_return_prodidx_r);
2065 * Set up the tx ring. Note: for the Tigon 2, we have the option
2066 * of putting the transmit ring in the host's address space and
2067 * letting the chip DMA it instead of leaving the ring in the NIC's
2068 * memory and accessing it through the shared memory region. We
2069 * do this for the Tigon 2, but it doesn't work on the Tigon 1,
2070 * so we have to revert to the shared memory scheme if we detect
2073 CSR_WRITE_4(sc, TI_WINBASE, TI_TX_RING_BASE);
2074 bzero((char *)sc->ti_rdata->ti_tx_ring,
2075 TI_TX_RING_CNT * sizeof(struct ti_tx_desc));
2076 rcb = &sc->ti_rdata->ti_info.ti_tx_rcb;
2077 if (sc->ti_hwrev == TI_HWREV_TIGON)
2080 rcb->ti_flags = TI_RCB_FLAG_HOST_RING;
2081 if (sc->ti_ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
2082 rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
2083 if (sc->ti_ifp->if_capenable & IFCAP_TXCSUM)
2084 rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
2085 TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
2086 rcb->ti_max_len = TI_TX_RING_CNT;
2087 if (sc->ti_hwrev == TI_HWREV_TIGON)
2088 TI_HOSTADDR(rcb->ti_hostaddr) = TI_TX_RING_BASE;
2090 TI_HOSTADDR(rcb->ti_hostaddr) = rdphys + TI_RD_OFF(ti_tx_ring);
2091 TI_HOSTADDR(sc->ti_rdata->ti_info.ti_tx_considx_ptr) =
2092 rdphys + TI_RD_OFF(ti_tx_considx_r);
2094 bus_dmamap_sync(sc->ti_rdata_dmat, sc->ti_rdata_dmamap,
2095 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
2097 /* Set up tuneables */
2099 if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
2100 CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS,
2101 (sc->ti_rx_coal_ticks / 10));
2104 CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS, sc->ti_rx_coal_ticks);
2105 CSR_WRITE_4(sc, TI_GCR_TX_COAL_TICKS, sc->ti_tx_coal_ticks);
2106 CSR_WRITE_4(sc, TI_GCR_STAT_TICKS, sc->ti_stat_ticks);
2107 CSR_WRITE_4(sc, TI_GCR_RX_MAX_COAL_BD, sc->ti_rx_max_coal_bds);
2108 CSR_WRITE_4(sc, TI_GCR_TX_MAX_COAL_BD, sc->ti_tx_max_coal_bds);
2109 CSR_WRITE_4(sc, TI_GCR_TX_BUFFER_RATIO, sc->ti_tx_buf_ratio);
2111 /* Turn interrupts on. */
2112 CSR_WRITE_4(sc, TI_GCR_MASK_INTRS, 0);
2113 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
2116 TI_CLRBIT(sc, TI_CPU_STATE, (TI_CPUSTATE_HALT|TI_CPUSTATE_STEP));
2122 ti_rdata_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2124 struct ti_softc *sc;
2127 if (error || nseg != 1)
2131 * All of the Tigon data structures need to live at <4GB. This
2132 * cast is fine since busdma was told about this constraint.
2134 sc->ti_rdata_phys = segs[0].ds_addr;
2139 * Probe for a Tigon chip. Check the PCI vendor and device IDs
2140 * against our list and return its name if we find a match.
2143 ti_probe(device_t dev)
2145 const struct ti_type *t;
2149 while (t->ti_name != NULL) {
2150 if ((pci_get_vendor(dev) == t->ti_vid) &&
2151 (pci_get_device(dev) == t->ti_did)) {
2152 device_set_desc(dev, t->ti_name);
2153 return (BUS_PROBE_DEFAULT);
2162 ti_attach(device_t dev)
2165 struct ti_softc *sc;
2169 sc = device_get_softc(dev);
2172 mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2174 callout_init_mtx(&sc->ti_watchdog, &sc->ti_mtx, 0);
2175 ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts);
2176 ifp = sc->ti_ifp = if_alloc(IFT_ETHER);
2178 device_printf(dev, "can not if_alloc()\n");
2182 sc->ti_ifp->if_hwassist = TI_CSUM_FEATURES;
2183 sc->ti_ifp->if_capabilities = IFCAP_TXCSUM | IFCAP_RXCSUM;
2184 sc->ti_ifp->if_capenable = sc->ti_ifp->if_capabilities;
2187 * Map control/status registers.
2189 pci_enable_busmaster(dev);
2192 sc->ti_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
2195 if (sc->ti_res == NULL) {
2196 device_printf(dev, "couldn't map memory\n");
2201 sc->ti_btag = rman_get_bustag(sc->ti_res);
2202 sc->ti_bhandle = rman_get_bushandle(sc->ti_res);
2204 /* Allocate interrupt */
2207 sc->ti_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2208 RF_SHAREABLE | RF_ACTIVE);
2210 if (sc->ti_irq == NULL) {
2211 device_printf(dev, "couldn't map interrupt\n");
2216 if (ti_chipinit(sc)) {
2217 device_printf(dev, "chip initialization failed\n");
2222 /* Zero out the NIC's on-board SRAM. */
2223 ti_mem_zero(sc, 0x2000, 0x100000 - 0x2000);
2225 /* Init again -- zeroing memory may have clobbered some registers. */
2226 if (ti_chipinit(sc)) {
2227 device_printf(dev, "chip initialization failed\n");
2233 * Get station address from the EEPROM. Note: the manual states
2234 * that the MAC address is at offset 0x8c, however the data is
2235 * stored as two longwords (since that's how it's loaded into
2236 * the NIC). This means the MAC address is actually preceded
2237 * by two zero bytes. We need to skip over those.
2239 if (ti_read_eeprom(sc, eaddr,
2240 TI_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) {
2241 device_printf(dev, "failed to read station address\n");
2246 /* Allocate the general information block and ring buffers. */
2247 if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
2248 1, 0, /* algnmnt, boundary */
2249 BUS_SPACE_MAXADDR, /* lowaddr */
2250 BUS_SPACE_MAXADDR, /* highaddr */
2251 NULL, NULL, /* filter, filterarg */
2252 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
2254 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
2256 NULL, NULL, /* lockfunc, lockarg */
2257 &sc->ti_parent_dmat) != 0) {
2258 device_printf(dev, "Failed to allocate parent dmat\n");
2263 if (bus_dma_tag_create(sc->ti_parent_dmat, /* parent */
2264 PAGE_SIZE, 0, /* algnmnt, boundary */
2265 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
2266 BUS_SPACE_MAXADDR, /* highaddr */
2267 NULL, NULL, /* filter, filterarg */
2268 sizeof(struct ti_ring_data), /* maxsize */
2270 sizeof(struct ti_ring_data), /* maxsegsize */
2272 NULL, NULL, /* lockfunc, lockarg */
2273 &sc->ti_rdata_dmat) != 0) {
2274 device_printf(dev, "Failed to allocate rdata dmat\n");
2279 if (bus_dmamem_alloc(sc->ti_rdata_dmat, (void**)&sc->ti_rdata,
2280 BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
2281 &sc->ti_rdata_dmamap) != 0) {
2282 device_printf(dev, "Failed to allocate rdata memory\n");
2287 if (bus_dmamap_load(sc->ti_rdata_dmat, sc->ti_rdata_dmamap,
2288 sc->ti_rdata, sizeof(struct ti_ring_data),
2289 ti_rdata_cb, sc, BUS_DMA_NOWAIT) != 0) {
2290 device_printf(dev, "Failed to load rdata segments\n");
2295 bzero(sc->ti_rdata, sizeof(struct ti_ring_data));
2297 /* Try to allocate memory for jumbo buffers. */
2298 if (ti_alloc_jumbo_mem(sc)) {
2299 device_printf(dev, "jumbo buffer allocation failed\n");
2304 if (bus_dma_tag_create(sc->ti_parent_dmat, /* parent */
2305 1, 0, /* algnmnt, boundary */
2306 BUS_SPACE_MAXADDR, /* lowaddr */
2307 BUS_SPACE_MAXADDR, /* highaddr */
2308 NULL, NULL, /* filter, filterarg */
2309 MCLBYTES * TI_MAXTXSEGS,/* maxsize */
2310 TI_MAXTXSEGS, /* nsegments */
2311 MCLBYTES, /* maxsegsize */
2313 NULL, NULL, /* lockfunc, lockarg */
2314 &sc->ti_mbuftx_dmat) != 0) {
2315 device_printf(dev, "Failed to allocate rdata dmat\n");
2320 if (bus_dma_tag_create(sc->ti_parent_dmat, /* parent */
2321 1, 0, /* algnmnt, boundary */
2322 BUS_SPACE_MAXADDR, /* lowaddr */
2323 BUS_SPACE_MAXADDR, /* highaddr */
2324 NULL, NULL, /* filter, filterarg */
2325 MCLBYTES, /* maxsize */
2327 MCLBYTES, /* maxsegsize */
2329 NULL, NULL, /* lockfunc, lockarg */
2330 &sc->ti_mbufrx_dmat) != 0) {
2331 device_printf(dev, "Failed to allocate rdata dmat\n");
2336 if (ti_alloc_dmamaps(sc)) {
2342 * We really need a better way to tell a 1000baseTX card
2343 * from a 1000baseSX one, since in theory there could be
2344 * OEMed 1000baseTX cards from lame vendors who aren't
2345 * clever enough to change the PCI ID. For the moment
2346 * though, the AceNIC is the only copper card available.
2348 if (pci_get_vendor(dev) == ALT_VENDORID &&
2349 pci_get_device(dev) == ALT_DEVICEID_ACENIC_COPPER)
2351 /* Ok, it's not the only copper card available. */
2352 if (pci_get_vendor(dev) == NG_VENDORID &&
2353 pci_get_device(dev) == NG_DEVICEID_GA620T)
2356 /* Set default tuneable values. */
2357 sc->ti_stat_ticks = 2 * TI_TICKS_PER_SEC;
2359 sc->ti_rx_coal_ticks = TI_TICKS_PER_SEC / 5000;
2361 sc->ti_rx_coal_ticks = 170;
2362 sc->ti_tx_coal_ticks = TI_TICKS_PER_SEC / 500;
2363 sc->ti_rx_max_coal_bds = 64;
2365 sc->ti_tx_max_coal_bds = 128;
2367 sc->ti_tx_max_coal_bds = 32;
2368 sc->ti_tx_buf_ratio = 21;
2370 /* Set up ifnet structure */
2372 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
2373 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2374 ifp->if_ioctl = ti_ioctl;
2375 ifp->if_start = ti_start;
2376 ifp->if_init = ti_init;
2377 ifp->if_baudrate = IF_Gbps(1UL);
2378 ifp->if_snd.ifq_drv_maxlen = TI_TX_RING_CNT - 1;
2379 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
2380 IFQ_SET_READY(&ifp->if_snd);
2382 /* Set up ifmedia support. */
2383 if (sc->ti_copper) {
2385 * Copper cards allow manual 10/100 mode selection,
2386 * but not manual 1000baseTX mode selection. Why?
2387 * Becuase currently there's no way to specify the
2388 * master/slave setting through the firmware interface,
2389 * so Alteon decided to just bag it and handle it
2390 * via autonegotiation.
2392 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
2393 ifmedia_add(&sc->ifmedia,
2394 IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);
2395 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL);
2396 ifmedia_add(&sc->ifmedia,
2397 IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL);
2398 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_T, 0, NULL);
2399 ifmedia_add(&sc->ifmedia,
2400 IFM_ETHER|IFM_1000_T|IFM_FDX, 0, NULL);
2402 /* Fiber cards don't support 10/100 modes. */
2403 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL);
2404 ifmedia_add(&sc->ifmedia,
2405 IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL);
2407 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
2408 ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO);
2411 * We're assuming here that card initialization is a sequential
2412 * thing. If it isn't, multiple cards probing at the same time
2413 * could stomp on the list of softcs here.
2416 /* Register the device */
2417 sc->dev = make_dev(&ti_cdevsw, device_get_unit(dev), UID_ROOT,
2418 GID_OPERATOR, 0600, "ti%d", device_get_unit(dev));
2419 sc->dev->si_drv1 = sc;
2422 * Call MI attach routine.
2424 ether_ifattach(ifp, eaddr);
2426 /* VLAN capability setup. */
2427 ifp->if_capabilities |= IFCAP_VLAN_MTU | IFCAP_VLAN_HWCSUM |
2428 IFCAP_VLAN_HWTAGGING;
2429 ifp->if_capenable = ifp->if_capabilities;
2430 /* Tell the upper layer we support VLAN over-sized frames. */
2431 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
2433 /* Driver supports link state tracking. */
2434 ifp->if_capabilities |= IFCAP_LINKSTATE;
2435 ifp->if_capenable |= IFCAP_LINKSTATE;
2437 /* Hook interrupt last to avoid having to lock softc */
2438 error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET|INTR_MPSAFE,
2439 NULL, ti_intr, sc, &sc->ti_intrhand);
2442 device_printf(dev, "couldn't set up irq\n");
2454 * Shutdown hardware and free up resources. This can be called any
2455 * time after the mutex has been initialized. It is called in both
2456 * the error case in attach and the normal detach case so it needs
2457 * to be careful about only freeing resources that have actually been
2461 ti_detach(device_t dev)
2463 struct ti_softc *sc;
2466 sc = device_get_softc(dev);
2468 destroy_dev(sc->dev);
2469 KASSERT(mtx_initialized(&sc->ti_mtx), ("ti mutex not initialized"));
2471 if (device_is_attached(dev)) {
2472 ether_ifdetach(ifp);
2478 /* These should only be active if attach succeeded */
2479 callout_drain(&sc->ti_watchdog);
2480 bus_generic_detach(dev);
2481 ti_free_dmamaps(sc);
2482 ifmedia_removeall(&sc->ifmedia);
2484 if (sc->ti_jumbo_dmat)
2485 bus_dma_tag_destroy(sc->ti_jumbo_dmat);
2486 if (sc->ti_mbuftx_dmat)
2487 bus_dma_tag_destroy(sc->ti_mbuftx_dmat);
2488 if (sc->ti_mbufrx_dmat)
2489 bus_dma_tag_destroy(sc->ti_mbufrx_dmat);
2490 if (sc->ti_rdata && sc->ti_rdata_dmamap)
2491 bus_dmamap_unload(sc->ti_rdata_dmat, sc->ti_rdata_dmamap);
2493 bus_dmamem_free(sc->ti_rdata_dmat, sc->ti_rdata,
2494 sc->ti_rdata_dmamap);
2495 if (sc->ti_rdata_dmat)
2496 bus_dma_tag_destroy(sc->ti_rdata_dmat);
2497 if (sc->ti_parent_dmat)
2498 bus_dma_tag_destroy(sc->ti_parent_dmat);
2499 if (sc->ti_intrhand)
2500 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2502 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2504 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
2510 mtx_destroy(&sc->ti_mtx);
2515 #ifdef TI_JUMBO_HDRSPLIT
2517 * If hdr_len is 0, that means that header splitting wasn't done on
2518 * this packet for some reason. The two most likely reasons are that
2519 * the protocol isn't a supported protocol for splitting, or this
2520 * packet had a fragment offset that wasn't 0.
2522 * The header length, if it is non-zero, will always be the length of
2523 * the headers on the packet, but that length could be longer than the
2524 * first mbuf. So we take the minimum of the two as the actual
2527 static __inline void
2528 ti_hdr_split(struct mbuf *top, int hdr_len, int pkt_len, int idx)
2531 int lengths[4] = {0, 0, 0, 0};
2532 struct mbuf *m, *mp;
2535 top->m_len = min(hdr_len, top->m_len);
2536 pkt_len -= top->m_len;
2537 lengths[i++] = top->m_len;
2540 for (m = top->m_next; m && pkt_len; m = m->m_next) {
2541 m->m_len = m->m_ext.ext_size = min(m->m_len, pkt_len);
2542 pkt_len -= m->m_len;
2543 lengths[i++] = m->m_len;
2549 printf("got split packet: ");
2551 printf("got non-split packet: ");
2553 printf("%d,%d,%d,%d = %d\n", lengths[0],
2554 lengths[1], lengths[2], lengths[3],
2555 lengths[0] + lengths[1] + lengths[2] +
2560 panic("header splitting didn't");
2567 if (mp->m_next != NULL)
2568 panic("ti_hdr_split: last mbuf in chain should be null");
2570 #endif /* TI_JUMBO_HDRSPLIT */
2573 ti_discard_std(struct ti_softc *sc, int i)
2576 struct ti_rx_desc *r;
2578 r = &sc->ti_rdata->ti_rx_std_ring[i];
2579 r->ti_len = MCLBYTES - ETHER_ALIGN;
2580 r->ti_type = TI_BDTYPE_RECV_BD;
2583 r->ti_tcp_udp_cksum = 0;
2584 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
2585 r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
2590 ti_discard_mini(struct ti_softc *sc, int i)
2593 struct ti_rx_desc *r;
2595 r = &sc->ti_rdata->ti_rx_mini_ring[i];
2596 r->ti_len = MHLEN - ETHER_ALIGN;
2597 r->ti_type = TI_BDTYPE_RECV_BD;
2598 r->ti_flags = TI_BDFLAG_MINI_RING;
2600 r->ti_tcp_udp_cksum = 0;
2601 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
2602 r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
2606 #ifndef TI_SF_BUF_JUMBO
2608 ti_discard_jumbo(struct ti_softc *sc, int i)
2611 struct ti_rx_desc *r;
2613 r = &sc->ti_rdata->ti_rx_mini_ring[i];
2614 r->ti_len = MJUM9BYTES - ETHER_ALIGN;
2615 r->ti_type = TI_BDTYPE_RECV_JUMBO_BD;
2616 r->ti_flags = TI_BDFLAG_JUMBO_RING;
2618 r->ti_tcp_udp_cksum = 0;
2619 if (sc->ti_ifp->if_capenable & IFCAP_RXCSUM)
2620 r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM;
2626 * Frame reception handling. This is called if there's a frame
2627 * on the receive return list.
2629 * Note: we have to be able to handle three possibilities here:
2630 * 1) the frame is from the mini receive ring (can only happen)
2631 * on Tigon 2 boards)
2632 * 2) the frame is from the jumbo recieve ring
2633 * 3) the frame is from the standard receive ring
2637 ti_rxeof(struct ti_softc *sc)
2640 #ifdef TI_SF_BUF_JUMBO
2643 struct ti_cmd_desc cmd;
2644 int jumbocnt, minicnt, stdcnt, ti_len;
2650 jumbocnt = minicnt = stdcnt = 0;
2651 while (sc->ti_rx_saved_considx != sc->ti_return_prodidx.ti_idx) {
2652 struct ti_rx_desc *cur_rx;
2654 struct mbuf *m = NULL;
2655 uint16_t vlan_tag = 0;
2659 &sc->ti_rdata->ti_rx_return_ring[sc->ti_rx_saved_considx];
2660 rxidx = cur_rx->ti_idx;
2661 ti_len = cur_rx->ti_len;
2662 TI_INC(sc->ti_rx_saved_considx, TI_RETURN_RING_CNT);
2664 if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) {
2666 vlan_tag = cur_rx->ti_vlan_tag;
2669 if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) {
2671 TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT);
2672 m = sc->ti_cdata.ti_rx_jumbo_chain[rxidx];
2673 #ifndef TI_SF_BUF_JUMBO
2674 if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
2676 ti_discard_jumbo(sc, rxidx);
2679 if (ti_newbuf_jumbo(sc, rxidx, NULL) != 0) {
2681 ti_discard_jumbo(sc, rxidx);
2685 #else /* !TI_SF_BUF_JUMBO */
2686 sc->ti_cdata.ti_rx_jumbo_chain[rxidx] = NULL;
2687 map = sc->ti_cdata.ti_rx_jumbo_maps[rxidx];
2688 bus_dmamap_sync(sc->ti_jumbo_dmat, map,
2689 BUS_DMASYNC_POSTREAD);
2690 bus_dmamap_unload(sc->ti_jumbo_dmat, map);
2691 if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
2693 ti_newbuf_jumbo(sc, sc->ti_jumbo, m);
2696 if (ti_newbuf_jumbo(sc, sc->ti_jumbo, NULL) == ENOBUFS) {
2698 ti_newbuf_jumbo(sc, sc->ti_jumbo, m);
2701 #ifdef TI_JUMBO_HDRSPLIT
2702 if (sc->ti_hdrsplit)
2703 ti_hdr_split(m, TI_HOSTADDR(cur_rx->ti_addr),
2706 #endif /* TI_JUMBO_HDRSPLIT */
2707 m_adj(m, ti_len - m->m_pkthdr.len);
2708 #endif /* TI_SF_BUF_JUMBO */
2709 } else if (cur_rx->ti_flags & TI_BDFLAG_MINI_RING) {
2711 TI_INC(sc->ti_mini, TI_MINI_RX_RING_CNT);
2712 m = sc->ti_cdata.ti_rx_mini_chain[rxidx];
2713 if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
2715 ti_discard_mini(sc, rxidx);
2718 if (ti_newbuf_mini(sc, rxidx) != 0) {
2720 ti_discard_mini(sc, rxidx);
2726 TI_INC(sc->ti_std, TI_STD_RX_RING_CNT);
2727 m = sc->ti_cdata.ti_rx_std_chain[rxidx];
2728 if (cur_rx->ti_flags & TI_BDFLAG_ERROR) {
2730 ti_discard_std(sc, rxidx);
2733 if (ti_newbuf_std(sc, rxidx) != 0) {
2735 ti_discard_std(sc, rxidx);
2741 m->m_pkthdr.len = ti_len;
2743 m->m_pkthdr.rcvif = ifp;
2745 if (ifp->if_capenable & IFCAP_RXCSUM) {
2746 if (cur_rx->ti_flags & TI_BDFLAG_IP_CKSUM) {
2747 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
2748 if ((cur_rx->ti_ip_cksum ^ 0xffff) == 0)
2749 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2751 if (cur_rx->ti_flags & TI_BDFLAG_TCP_UDP_CKSUM) {
2752 m->m_pkthdr.csum_data =
2753 cur_rx->ti_tcp_udp_cksum;
2754 m->m_pkthdr.csum_flags |= CSUM_DATA_VALID;
2759 * If we received a packet with a vlan tag,
2760 * tag it before passing the packet upward.
2763 m->m_pkthdr.ether_vtag = vlan_tag;
2764 m->m_flags |= M_VLANTAG;
2767 (*ifp->if_input)(ifp, m);
2771 /* Only necessary on the Tigon 1. */
2772 if (sc->ti_hwrev == TI_HWREV_TIGON)
2773 CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX,
2774 sc->ti_rx_saved_considx);
2777 TI_UPDATE_STDPROD(sc, sc->ti_std);
2779 TI_UPDATE_MINIPROD(sc, sc->ti_mini);
2781 TI_UPDATE_JUMBOPROD(sc, sc->ti_jumbo);
2785 ti_txeof(struct ti_softc *sc)
2787 struct ti_txdesc *txd;
2788 struct ti_tx_desc txdesc;
2789 struct ti_tx_desc *cur_tx = NULL;
2795 txd = STAILQ_FIRST(&sc->ti_cdata.ti_txbusyq);
2799 * Go through our tx ring and free mbufs for those
2800 * frames that have been sent.
2802 for (idx = sc->ti_tx_saved_considx; idx != sc->ti_tx_considx.ti_idx;
2803 TI_INC(idx, TI_TX_RING_CNT)) {
2804 if (sc->ti_hwrev == TI_HWREV_TIGON) {
2805 ti_mem_read(sc, TI_TX_RING_BASE + idx * sizeof(txdesc),
2806 sizeof(txdesc), &txdesc);
2809 cur_tx = &sc->ti_rdata->ti_tx_ring[idx];
2811 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2812 if ((cur_tx->ti_flags & TI_BDFLAG_END) == 0)
2814 bus_dmamap_sync(sc->ti_mbuftx_dmat, txd->tx_dmamap,
2815 BUS_DMASYNC_POSTWRITE);
2816 bus_dmamap_unload(sc->ti_mbuftx_dmat, txd->tx_dmamap);
2821 STAILQ_REMOVE_HEAD(&sc->ti_cdata.ti_txbusyq, tx_q);
2822 STAILQ_INSERT_TAIL(&sc->ti_cdata.ti_txfreeq, txd, tx_q);
2823 txd = STAILQ_FIRST(&sc->ti_cdata.ti_txbusyq);
2825 sc->ti_tx_saved_considx = idx;
2827 sc->ti_timer = sc->ti_txcnt > 0 ? 5 : 0;
2833 struct ti_softc *sc;
2841 /* Avoid this for now -- checking this register is expensive. */
2842 /* Make sure this is really our interrupt. */
2843 if (!(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_INTSTATE)) {
2849 /* Ack interrupt and stop others from occuring. */
2850 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
2852 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2853 /* Check RX return ring producer/consumer */
2856 /* Check TX ring producer/consumer */
2860 ti_handle_events(sc);
2862 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2863 /* Re-enable interrupts. */
2864 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
2865 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
2866 ti_start_locked(ifp);
2873 ti_stats_update(struct ti_softc *sc)
2879 bus_dmamap_sync(sc->ti_rdata_dmat, sc->ti_rdata_dmamap,
2880 BUS_DMASYNC_POSTREAD);
2882 ifp->if_collisions +=
2883 (sc->ti_rdata->ti_info.ti_stats.dot3StatsSingleCollisionFrames +
2884 sc->ti_rdata->ti_info.ti_stats.dot3StatsMultipleCollisionFrames +
2885 sc->ti_rdata->ti_info.ti_stats.dot3StatsExcessiveCollisions +
2886 sc->ti_rdata->ti_info.ti_stats.dot3StatsLateCollisions) -
2889 bus_dmamap_sync(sc->ti_rdata_dmat, sc->ti_rdata_dmamap,
2890 BUS_DMASYNC_PREREAD);
2894 * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data
2895 * pointers to descriptors.
2898 ti_encap(struct ti_softc *sc, struct mbuf **m_head)
2900 struct ti_txdesc *txd;
2901 struct ti_tx_desc *f;
2902 struct ti_tx_desc txdesc;
2904 bus_dma_segment_t txsegs[TI_MAXTXSEGS];
2905 uint16_t csum_flags;
2906 int error, frag, i, nseg;
2908 if ((txd = STAILQ_FIRST(&sc->ti_cdata.ti_txfreeq)) == NULL)
2911 error = bus_dmamap_load_mbuf_sg(sc->ti_mbuftx_dmat, txd->tx_dmamap,
2912 *m_head, txsegs, &nseg, 0);
2913 if (error == EFBIG) {
2914 m = m_defrag(*m_head, M_DONTWAIT);
2921 error = bus_dmamap_load_mbuf_sg(sc->ti_mbuftx_dmat,
2922 txd->tx_dmamap, *m_head, txsegs, &nseg, 0);
2928 } else if (error != 0)
2936 if (sc->ti_txcnt + nseg >= TI_TX_RING_CNT) {
2937 bus_dmamap_unload(sc->ti_mbuftx_dmat, txd->tx_dmamap);
2943 if (m->m_pkthdr.csum_flags) {
2944 if (m->m_pkthdr.csum_flags & CSUM_IP)
2945 csum_flags |= TI_BDFLAG_IP_CKSUM;
2946 if (m->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
2947 csum_flags |= TI_BDFLAG_TCP_UDP_CKSUM;
2948 if (m->m_flags & M_LASTFRAG)
2949 csum_flags |= TI_BDFLAG_IP_FRAG_END;
2950 else if (m->m_flags & M_FRAG)
2951 csum_flags |= TI_BDFLAG_IP_FRAG;
2954 bus_dmamap_sync(sc->ti_mbuftx_dmat, txd->tx_dmamap,
2955 BUS_DMASYNC_PREWRITE);
2956 bus_dmamap_sync(sc->ti_rdata_dmat, sc->ti_rdata_dmamap,
2957 BUS_DMASYNC_PREWRITE);
2959 frag = sc->ti_tx_saved_prodidx;
2960 for (i = 0; i < nseg; i++) {
2961 if (sc->ti_hwrev == TI_HWREV_TIGON) {
2962 bzero(&txdesc, sizeof(txdesc));
2965 f = &sc->ti_rdata->ti_tx_ring[frag];
2966 ti_hostaddr64(&f->ti_addr, txsegs[i].ds_addr);
2967 f->ti_len = txsegs[i].ds_len;
2968 f->ti_flags = csum_flags;
2969 if (m->m_flags & M_VLANTAG) {
2970 f->ti_flags |= TI_BDFLAG_VLAN_TAG;
2971 f->ti_vlan_tag = m->m_pkthdr.ether_vtag;
2976 if (sc->ti_hwrev == TI_HWREV_TIGON)
2977 ti_mem_write(sc, TI_TX_RING_BASE + frag *
2978 sizeof(txdesc), sizeof(txdesc), &txdesc);
2979 TI_INC(frag, TI_TX_RING_CNT);
2982 sc->ti_tx_saved_prodidx = frag;
2983 /* set TI_BDFLAG_END on the last descriptor */
2984 frag = (frag + TI_TX_RING_CNT - 1) % TI_TX_RING_CNT;
2985 if (sc->ti_hwrev == TI_HWREV_TIGON) {
2986 txdesc.ti_flags |= TI_BDFLAG_END;
2987 ti_mem_write(sc, TI_TX_RING_BASE + frag * sizeof(txdesc),
2988 sizeof(txdesc), &txdesc);
2990 sc->ti_rdata->ti_tx_ring[frag].ti_flags |= TI_BDFLAG_END;
2992 STAILQ_REMOVE_HEAD(&sc->ti_cdata.ti_txfreeq, tx_q);
2993 STAILQ_INSERT_TAIL(&sc->ti_cdata.ti_txbusyq, txd, tx_q);
2995 sc->ti_txcnt += nseg;
3001 ti_start(struct ifnet *ifp)
3003 struct ti_softc *sc;
3007 ti_start_locked(ifp);
3012 * Main transmit routine. To avoid having to do mbuf copies, we put pointers
3013 * to the mbuf data regions directly in the transmit descriptors.
3016 ti_start_locked(struct ifnet *ifp)
3018 struct ti_softc *sc;
3019 struct mbuf *m_head = NULL;
3024 for (; !IFQ_DRV_IS_EMPTY(&ifp->if_snd) &&
3025 sc->ti_txcnt < (TI_TX_RING_CNT - 16);) {
3026 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
3032 * safety overkill. If this is a fragmented packet chain
3033 * with delayed TCP/UDP checksums, then only encapsulate
3034 * it if we have enough descriptors to handle the entire
3036 * (paranoia -- may not actually be needed)
3038 if (m_head->m_flags & M_FIRSTFRAG &&
3039 m_head->m_pkthdr.csum_flags & (CSUM_DELAY_DATA)) {
3040 if ((TI_TX_RING_CNT - sc->ti_txcnt) <
3041 m_head->m_pkthdr.csum_data + 16) {
3042 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
3043 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
3049 * Pack the data into the transmit ring. If we
3050 * don't have room, set the OACTIVE flag and wait
3051 * for the NIC to drain the ring.
3053 if (ti_encap(sc, &m_head)) {
3056 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
3057 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
3063 * If there's a BPF listener, bounce a copy of this frame
3066 ETHER_BPF_MTAP(ifp, m_head);
3071 CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, sc->ti_tx_saved_prodidx);
3074 * Set a timeout in case the chip goes out to lunch.
3083 struct ti_softc *sc;
3092 ti_init_locked(void *xsc)
3094 struct ti_softc *sc = xsc;
3096 if (sc->ti_ifp->if_drv_flags & IFF_DRV_RUNNING)
3099 /* Cancel pending I/O and flush buffers. */
3102 /* Init the gen info block, ring control blocks and firmware. */
3103 if (ti_gibinit(sc)) {
3104 device_printf(sc->ti_dev, "initialization failure\n");
3109 static void ti_init2(struct ti_softc *sc)
3111 struct ti_cmd_desc cmd;
3114 struct ifmedia *ifm;
3121 /* Specify MTU and interface index. */
3122 CSR_WRITE_4(sc, TI_GCR_IFINDEX, device_get_unit(sc->ti_dev));
3123 CSR_WRITE_4(sc, TI_GCR_IFMTU, ifp->if_mtu +
3124 ETHER_HDR_LEN + ETHER_CRC_LEN + ETHER_VLAN_ENCAP_LEN);
3125 TI_DO_CMD(TI_CMD_UPDATE_GENCOM, 0, 0);
3127 /* Load our MAC address. */
3128 ea = IF_LLADDR(sc->ti_ifp);
3129 CSR_WRITE_4(sc, TI_GCR_PAR0, (ea[0] << 8) | ea[1]);
3130 CSR_WRITE_4(sc, TI_GCR_PAR1,
3131 (ea[2] << 24) | (ea[3] << 16) | (ea[4] << 8) | ea[5]);
3132 TI_DO_CMD(TI_CMD_SET_MAC_ADDR, 0, 0);
3134 /* Enable or disable promiscuous mode as needed. */
3135 if (ifp->if_flags & IFF_PROMISC) {
3136 TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_ENB, 0);
3138 TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_DIS, 0);
3141 /* Program multicast filter. */
3145 * If this is a Tigon 1, we should tell the
3146 * firmware to use software packet filtering.
3148 if (sc->ti_hwrev == TI_HWREV_TIGON) {
3149 TI_DO_CMD(TI_CMD_FDR_FILTERING, TI_CMD_CODE_FILT_ENB, 0);
3153 if (ti_init_rx_ring_std(sc) != 0) {
3155 device_printf(sc->ti_dev, "no memory for std Rx buffers.\n");
3159 /* Init jumbo RX ring. */
3160 if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) {
3161 if (ti_init_rx_ring_jumbo(sc) != 0) {
3163 device_printf(sc->ti_dev,
3164 "no memory for jumbo Rx buffers.\n");
3170 * If this is a Tigon 2, we can also configure the
3173 if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
3174 if (ti_init_rx_ring_mini(sc) != 0) {
3176 device_printf(sc->ti_dev,
3177 "no memory for mini Rx buffers.\n");
3182 CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX, 0);
3183 sc->ti_rx_saved_considx = 0;
3186 ti_init_tx_ring(sc);
3188 /* Tell firmware we're alive. */
3189 TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_UP, 0);
3191 /* Enable host interrupts. */
3192 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
3194 ifp->if_drv_flags |= IFF_DRV_RUNNING;
3195 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3196 callout_reset(&sc->ti_watchdog, hz, ti_watchdog, sc);
3199 * Make sure to set media properly. We have to do this
3200 * here since we have to issue commands in order to set
3201 * the link negotiation and we can't issue commands until
3202 * the firmware is running.
3205 tmp = ifm->ifm_media;
3206 ifm->ifm_media = ifm->ifm_cur->ifm_media;
3207 ti_ifmedia_upd_locked(sc);
3208 ifm->ifm_media = tmp;
3212 * Set media options.
3215 ti_ifmedia_upd(struct ifnet *ifp)
3217 struct ti_softc *sc;
3222 error = ti_ifmedia_upd(ifp);
3229 ti_ifmedia_upd_locked(struct ti_softc *sc)
3231 struct ifmedia *ifm;
3232 struct ti_cmd_desc cmd;
3237 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
3242 switch (IFM_SUBTYPE(ifm->ifm_media)) {
3245 * Transmit flow control doesn't work on the Tigon 1.
3247 flowctl = TI_GLNK_RX_FLOWCTL_Y;
3250 * Transmit flow control can also cause problems on the
3251 * Tigon 2, apparantly with both the copper and fiber
3252 * boards. The symptom is that the interface will just
3253 * hang. This was reproduced with Alteon 180 switches.
3256 if (sc->ti_hwrev != TI_HWREV_TIGON)
3257 flowctl |= TI_GLNK_TX_FLOWCTL_Y;
3260 CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB|
3261 TI_GLNK_FULL_DUPLEX| flowctl |
3262 TI_GLNK_AUTONEGENB|TI_GLNK_ENB);
3264 flowctl = TI_LNK_RX_FLOWCTL_Y;
3266 if (sc->ti_hwrev != TI_HWREV_TIGON)
3267 flowctl |= TI_LNK_TX_FLOWCTL_Y;
3270 CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_100MB|TI_LNK_10MB|
3271 TI_LNK_FULL_DUPLEX|TI_LNK_HALF_DUPLEX| flowctl |
3272 TI_LNK_AUTONEGENB|TI_LNK_ENB);
3273 TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
3274 TI_CMD_CODE_NEGOTIATE_BOTH, 0);
3278 flowctl = TI_GLNK_RX_FLOWCTL_Y;
3280 if (sc->ti_hwrev != TI_HWREV_TIGON)
3281 flowctl |= TI_GLNK_TX_FLOWCTL_Y;
3284 CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB|
3285 flowctl |TI_GLNK_ENB);
3286 CSR_WRITE_4(sc, TI_GCR_LINK, 0);
3287 if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) {
3288 TI_SETBIT(sc, TI_GCR_GLINK, TI_GLNK_FULL_DUPLEX);
3290 TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
3291 TI_CMD_CODE_NEGOTIATE_GIGABIT, 0);
3297 flowctl = TI_LNK_RX_FLOWCTL_Y;
3299 if (sc->ti_hwrev != TI_HWREV_TIGON)
3300 flowctl |= TI_LNK_TX_FLOWCTL_Y;
3303 CSR_WRITE_4(sc, TI_GCR_GLINK, 0);
3304 CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_ENB|TI_LNK_PREF|flowctl);
3305 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX ||
3306 IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) {
3307 TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_100MB);
3309 TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_10MB);
3311 if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) {
3312 TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_FULL_DUPLEX);
3314 TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_HALF_DUPLEX);
3316 TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
3317 TI_CMD_CODE_NEGOTIATE_10_100, 0);
3325 * Report current media status.
3328 ti_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
3330 struct ti_softc *sc;
3337 ifmr->ifm_status = IFM_AVALID;
3338 ifmr->ifm_active = IFM_ETHER;
3340 if (sc->ti_linkstat == TI_EV_CODE_LINK_DOWN) {
3345 ifmr->ifm_status |= IFM_ACTIVE;
3347 if (sc->ti_linkstat == TI_EV_CODE_GIG_LINK_UP) {
3348 media = CSR_READ_4(sc, TI_GCR_GLINK_STAT);
3350 ifmr->ifm_active |= IFM_1000_T;
3352 ifmr->ifm_active |= IFM_1000_SX;
3353 if (media & TI_GLNK_FULL_DUPLEX)
3354 ifmr->ifm_active |= IFM_FDX;
3356 ifmr->ifm_active |= IFM_HDX;
3357 } else if (sc->ti_linkstat == TI_EV_CODE_LINK_UP) {
3358 media = CSR_READ_4(sc, TI_GCR_LINK_STAT);
3359 if (sc->ti_copper) {
3360 if (media & TI_LNK_100MB)
3361 ifmr->ifm_active |= IFM_100_TX;
3362 if (media & TI_LNK_10MB)
3363 ifmr->ifm_active |= IFM_10_T;
3365 if (media & TI_LNK_100MB)
3366 ifmr->ifm_active |= IFM_100_FX;
3367 if (media & TI_LNK_10MB)
3368 ifmr->ifm_active |= IFM_10_FL;
3370 if (media & TI_LNK_FULL_DUPLEX)
3371 ifmr->ifm_active |= IFM_FDX;
3372 if (media & TI_LNK_HALF_DUPLEX)
3373 ifmr->ifm_active |= IFM_HDX;
3379 ti_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
3381 struct ti_softc *sc = ifp->if_softc;
3382 struct ifreq *ifr = (struct ifreq *) data;
3383 struct ti_cmd_desc cmd;
3384 int mask, error = 0;
3389 if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > TI_JUMBO_MTU)
3392 ifp->if_mtu = ifr->ifr_mtu;
3393 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
3394 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
3402 if (ifp->if_flags & IFF_UP) {
3404 * If only the state of the PROMISC flag changed,
3405 * then just use the 'set promisc mode' command
3406 * instead of reinitializing the entire NIC. Doing
3407 * a full re-init means reloading the firmware and
3408 * waiting for it to start up, which may take a
3411 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
3412 ifp->if_flags & IFF_PROMISC &&
3413 !(sc->ti_if_flags & IFF_PROMISC)) {
3414 TI_DO_CMD(TI_CMD_SET_PROMISC_MODE,
3415 TI_CMD_CODE_PROMISC_ENB, 0);
3416 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
3417 !(ifp->if_flags & IFF_PROMISC) &&
3418 sc->ti_if_flags & IFF_PROMISC) {
3419 TI_DO_CMD(TI_CMD_SET_PROMISC_MODE,
3420 TI_CMD_CODE_PROMISC_DIS, 0);
3424 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
3428 sc->ti_if_flags = ifp->if_flags;
3434 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
3440 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
3444 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
3445 if ((mask & IFCAP_TXCSUM) != 0 &&
3446 (ifp->if_capabilities & IFCAP_TXCSUM) != 0) {
3447 ifp->if_capenable ^= IFCAP_TXCSUM;
3448 if ((ifp->if_capenable & IFCAP_TXCSUM) != 0)
3449 ifp->if_hwassist |= TI_CSUM_FEATURES;
3451 ifp->if_hwassist &= ~TI_CSUM_FEATURES;
3453 if ((mask & IFCAP_RXCSUM) != 0 &&
3454 (ifp->if_capabilities & IFCAP_RXCSUM) != 0)
3455 ifp->if_capenable ^= IFCAP_RXCSUM;
3456 if ((mask & IFCAP_VLAN_HWTAGGING) != 0 &&
3457 (ifp->if_capabilities & IFCAP_VLAN_HWTAGGING) != 0)
3458 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
3459 if ((mask & IFCAP_VLAN_HWCSUM) != 0 &&
3460 (ifp->if_capabilities & IFCAP_VLAN_HWCSUM) != 0)
3461 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
3462 if ((mask & (IFCAP_TXCSUM | IFCAP_RXCSUM |
3463 IFCAP_VLAN_HWTAGGING)) != 0) {
3464 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
3465 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
3470 VLAN_CAPABILITIES(ifp);
3473 error = ether_ioctl(ifp, command, data);
3481 ti_open(struct cdev *dev, int flags, int fmt, struct thread *td)
3483 struct ti_softc *sc;
3490 sc->ti_flags |= TI_FLAG_DEBUGING;
3497 ti_close(struct cdev *dev, int flag, int fmt, struct thread *td)
3499 struct ti_softc *sc;
3506 sc->ti_flags &= ~TI_FLAG_DEBUGING;
3513 * This ioctl routine goes along with the Tigon character device.
3516 ti_ioctl2(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
3519 struct ti_softc *sc;
3531 struct ti_stats *outstats;
3533 outstats = (struct ti_stats *)addr;
3536 bcopy(&sc->ti_rdata->ti_info.ti_stats, outstats,
3537 sizeof(struct ti_stats));
3541 case TIIOCGETPARAMS:
3543 struct ti_params *params;
3545 params = (struct ti_params *)addr;
3548 params->ti_stat_ticks = sc->ti_stat_ticks;
3549 params->ti_rx_coal_ticks = sc->ti_rx_coal_ticks;
3550 params->ti_tx_coal_ticks = sc->ti_tx_coal_ticks;
3551 params->ti_rx_max_coal_bds = sc->ti_rx_max_coal_bds;
3552 params->ti_tx_max_coal_bds = sc->ti_tx_max_coal_bds;
3553 params->ti_tx_buf_ratio = sc->ti_tx_buf_ratio;
3554 params->param_mask = TI_PARAM_ALL;
3561 case TIIOCSETPARAMS:
3563 struct ti_params *params;
3565 params = (struct ti_params *)addr;
3568 if (params->param_mask & TI_PARAM_STAT_TICKS) {
3569 sc->ti_stat_ticks = params->ti_stat_ticks;
3570 CSR_WRITE_4(sc, TI_GCR_STAT_TICKS, sc->ti_stat_ticks);
3573 if (params->param_mask & TI_PARAM_RX_COAL_TICKS) {
3574 sc->ti_rx_coal_ticks = params->ti_rx_coal_ticks;
3575 CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS,
3576 sc->ti_rx_coal_ticks);
3579 if (params->param_mask & TI_PARAM_TX_COAL_TICKS) {
3580 sc->ti_tx_coal_ticks = params->ti_tx_coal_ticks;
3581 CSR_WRITE_4(sc, TI_GCR_TX_COAL_TICKS,
3582 sc->ti_tx_coal_ticks);
3585 if (params->param_mask & TI_PARAM_RX_COAL_BDS) {
3586 sc->ti_rx_max_coal_bds = params->ti_rx_max_coal_bds;
3587 CSR_WRITE_4(sc, TI_GCR_RX_MAX_COAL_BD,
3588 sc->ti_rx_max_coal_bds);
3591 if (params->param_mask & TI_PARAM_TX_COAL_BDS) {
3592 sc->ti_tx_max_coal_bds = params->ti_tx_max_coal_bds;
3593 CSR_WRITE_4(sc, TI_GCR_TX_MAX_COAL_BD,
3594 sc->ti_tx_max_coal_bds);
3597 if (params->param_mask & TI_PARAM_TX_BUF_RATIO) {
3598 sc->ti_tx_buf_ratio = params->ti_tx_buf_ratio;
3599 CSR_WRITE_4(sc, TI_GCR_TX_BUFFER_RATIO,
3600 sc->ti_tx_buf_ratio);
3608 case TIIOCSETTRACE: {
3609 ti_trace_type trace_type;
3611 trace_type = *(ti_trace_type *)addr;
3614 * Set tracing to whatever the user asked for. Setting
3615 * this register to 0 should have the effect of disabling
3618 CSR_WRITE_4(sc, TI_GCR_NIC_TRACING, trace_type);
3624 case TIIOCGETTRACE: {
3625 struct ti_trace_buf *trace_buf;
3626 uint32_t trace_start, cur_trace_ptr, trace_len;
3628 trace_buf = (struct ti_trace_buf *)addr;
3631 trace_start = CSR_READ_4(sc, TI_GCR_NICTRACE_START);
3632 cur_trace_ptr = CSR_READ_4(sc, TI_GCR_NICTRACE_PTR);
3633 trace_len = CSR_READ_4(sc, TI_GCR_NICTRACE_LEN);
3636 if_printf(sc->ti_ifp, "trace_start = %#x, cur_trace_ptr = %#x, "
3637 "trace_len = %d\n", trace_start,
3638 cur_trace_ptr, trace_len);
3639 if_printf(sc->ti_ifp, "trace_buf->buf_len = %d\n",
3640 trace_buf->buf_len);
3643 error = ti_copy_mem(sc, trace_start, min(trace_len,
3644 trace_buf->buf_len),
3645 (caddr_t)trace_buf->buf, 1, 1);
3648 trace_buf->fill_len = min(trace_len,
3649 trace_buf->buf_len);
3650 if (cur_trace_ptr < trace_start)
3651 trace_buf->cur_trace_ptr =
3652 trace_start - cur_trace_ptr;
3654 trace_buf->cur_trace_ptr =
3655 cur_trace_ptr - trace_start;
3657 trace_buf->fill_len = 0;
3664 * For debugging, five ioctls are needed:
3673 * From what I can tell, Alteon's Solaris Tigon driver
3674 * only has one character device, so you have to attach
3675 * to the Tigon board you're interested in. This seems
3676 * like a not-so-good way to do things, since unless you
3677 * subsequently specify the unit number of the device
3678 * you're interested in every ioctl, you'll only be
3679 * able to debug one board at a time.
3683 case ALT_READ_TG_MEM:
3684 case ALT_WRITE_TG_MEM:
3686 struct tg_mem *mem_param;
3687 uint32_t sram_end, scratch_end;
3689 mem_param = (struct tg_mem *)addr;
3691 if (sc->ti_hwrev == TI_HWREV_TIGON) {
3692 sram_end = TI_END_SRAM_I;
3693 scratch_end = TI_END_SCRATCH_I;
3695 sram_end = TI_END_SRAM_II;
3696 scratch_end = TI_END_SCRATCH_II;
3700 * For now, we'll only handle accessing regular SRAM,
3704 if ((mem_param->tgAddr >= TI_BEG_SRAM)
3705 && ((mem_param->tgAddr + mem_param->len) <= sram_end)) {
3707 * In this instance, we always copy to/from user
3708 * space, so the user space argument is set to 1.
3710 error = ti_copy_mem(sc, mem_param->tgAddr,
3712 mem_param->userAddr, 1,
3713 (cmd == ALT_READ_TG_MEM) ? 1 : 0);
3714 } else if ((mem_param->tgAddr >= TI_BEG_SCRATCH)
3715 && (mem_param->tgAddr <= scratch_end)) {
3716 error = ti_copy_scratch(sc, mem_param->tgAddr,
3718 mem_param->userAddr, 1,
3719 (cmd == ALT_READ_TG_MEM) ?
3720 1 : 0, TI_PROCESSOR_A);
3721 } else if ((mem_param->tgAddr >= TI_BEG_SCRATCH_B_DEBUG)
3722 && (mem_param->tgAddr <= TI_BEG_SCRATCH_B_DEBUG)) {
3723 if (sc->ti_hwrev == TI_HWREV_TIGON) {
3724 if_printf(sc->ti_ifp,
3725 "invalid memory range for Tigon I\n");
3729 error = ti_copy_scratch(sc, mem_param->tgAddr -
3730 TI_SCRATCH_DEBUG_OFF,
3732 mem_param->userAddr, 1,
3733 (cmd == ALT_READ_TG_MEM) ?
3734 1 : 0, TI_PROCESSOR_B);
3736 if_printf(sc->ti_ifp, "memory address %#x len %d is "
3737 "out of supported range\n",
3738 mem_param->tgAddr, mem_param->len);
3745 case ALT_READ_TG_REG:
3746 case ALT_WRITE_TG_REG:
3748 struct tg_reg *regs;
3751 regs = (struct tg_reg *)addr;
3754 * Make sure the address in question isn't out of range.
3756 if (regs->addr > TI_REG_MAX) {
3761 if (cmd == ALT_READ_TG_REG) {
3762 bus_space_read_region_4(sc->ti_btag, sc->ti_bhandle,
3763 regs->addr, &tmpval, 1);
3764 regs->data = ntohl(tmpval);
3766 if ((regs->addr == TI_CPU_STATE)
3767 || (regs->addr == TI_CPU_CTL_B)) {
3768 if_printf(sc->ti_ifp, "register %#x = %#x\n",
3769 regs->addr, tmpval);
3773 tmpval = htonl(regs->data);
3774 bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
3775 regs->addr, &tmpval, 1);
3789 ti_watchdog(void *arg)
3791 struct ti_softc *sc;
3796 callout_reset(&sc->ti_watchdog, hz, ti_watchdog, sc);
3797 if (sc->ti_timer == 0 || --sc->ti_timer > 0)
3801 * When we're debugging, the chip is often stopped for long periods
3802 * of time, and that would normally cause the watchdog timer to fire.
3803 * Since that impedes debugging, we don't want to do that.
3805 if (sc->ti_flags & TI_FLAG_DEBUGING)
3809 if_printf(ifp, "watchdog timeout -- resetting\n");
3810 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
3817 * Stop the adapter and free any mbufs allocated to the
3821 ti_stop(struct ti_softc *sc)
3824 struct ti_cmd_desc cmd;
3830 /* Disable host interrupts. */
3831 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
3833 * Tell firmware we're shutting down.
3835 TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_DOWN, 0);
3837 /* Halt and reinitialize. */
3838 if (ti_chipinit(sc) == 0) {
3839 ti_mem_zero(sc, 0x2000, 0x100000 - 0x2000);
3840 /* XXX ignore init errors. */
3844 /* Free the RX lists. */
3845 ti_free_rx_ring_std(sc);
3847 /* Free jumbo RX list. */
3848 ti_free_rx_ring_jumbo(sc);
3850 /* Free mini RX list. */
3851 ti_free_rx_ring_mini(sc);
3853 /* Free TX buffers. */
3854 ti_free_tx_ring(sc);
3856 sc->ti_ev_prodidx.ti_idx = 0;
3857 sc->ti_return_prodidx.ti_idx = 0;
3858 sc->ti_tx_considx.ti_idx = 0;
3859 sc->ti_tx_saved_considx = TI_TXCONS_UNSET;
3861 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
3862 callout_stop(&sc->ti_watchdog);
3866 * Stop all chip I/O so that the kernel's probe routines don't
3867 * get confused by errant DMAs when rebooting.
3870 ti_shutdown(device_t dev)
3872 struct ti_softc *sc;
3874 sc = device_get_softc(dev);