1 /* $OpenBSD: if_txp.c,v 1.48 2001/06/27 06:34:50 kjc Exp $ */
2 /* $FreeBSD: src/sys/dev/txp/if_txp.c,v 1.4.2.4 2001/12/14 19:50:43 jlemon Exp $ */
3 /* $DragonFly: src/sys/dev/netif/txp/if_txp.c,v 1.12 2004/07/02 17:42:20 joerg Exp $ */
7 * Jason L. Wright <jason@thought.net>, Theo de Raadt, and
8 * Aaron Campbell <aaron@monkey.org>. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Jason L. Wright,
21 * Theo de Raadt and Aaron Campbell.
22 * 4. Neither the name of the author nor the names of any co-contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36 * THE POSSIBILITY OF SUCH DAMAGE.
38 * $FreeBSD: src/sys/dev/txp/if_txp.c,v 1.4.2.4 2001/12/14 19:50:43 jlemon Exp $
42 * Driver for 3c990 (Typhoon) Ethernet ASIC
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/sockio.h>
49 #include <sys/malloc.h>
50 #include <sys/kernel.h>
51 #include <sys/socket.h>
54 #include <net/if_arp.h>
55 #include <net/ethernet.h>
56 #include <net/if_dl.h>
57 #include <net/if_types.h>
58 #include <net/vlan/if_vlan_var.h>
60 #include <netinet/in.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/in_var.h>
63 #include <netinet/ip.h>
64 #include <netinet/if_ether.h>
65 #include <sys/in_cksum.h>
67 #include <net/if_media.h>
71 #include <vm/vm.h> /* for vtophys */
72 #include <vm/pmap.h> /* for vtophys */
73 #include <machine/clock.h> /* for DELAY */
74 #include <machine/bus_pio.h>
75 #include <machine/bus_memio.h>
76 #include <machine/bus.h>
77 #include <machine/resource.h>
81 #include "../mii_layer/mii.h"
82 #include "../mii_layer/miivar.h"
83 #include <bus/pci/pcireg.h>
84 #include <bus/pci/pcivar.h>
86 #define TXP_USEIOSPACE
87 #define __STRICT_ALIGNMENT
89 #include "if_txpreg.h"
93 * Various supported device vendors/types and their names.
95 static struct txp_type txp_devs[] = {
96 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990_TX_95,
97 "3Com 3cR990-TX-95 Etherlink with 3XP Processor" },
98 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990_TX_97,
99 "3Com 3cR990-TX-97 Etherlink with 3XP Processor" },
100 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990B_TXM,
101 "3Com 3cR990B-TXM Etherlink with 3XP Processor" },
102 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990_SRV_95,
103 "3Com 3cR990-SRV-95 Etherlink Server with 3XP Processor" },
104 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990_SRV_97,
105 "3Com 3cR990-SRV-97 Etherlink Server with 3XP Processor" },
106 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990B_SRV,
107 "3Com 3cR990B-SRV Etherlink Server with 3XP Processor" },
111 static int txp_probe (device_t);
112 static int txp_attach (device_t);
113 static int txp_detach (device_t);
114 static void txp_intr (void *);
115 static void txp_tick (void *);
116 static int txp_shutdown (device_t);
117 static int txp_ioctl (struct ifnet *, u_long, caddr_t, struct ucred *);
118 static void txp_start (struct ifnet *);
119 static void txp_stop (struct txp_softc *);
120 static void txp_init (void *);
121 static void txp_watchdog (struct ifnet *);
123 static void txp_release_resources (struct txp_softc *);
124 static int txp_chip_init (struct txp_softc *);
125 static int txp_reset_adapter (struct txp_softc *);
126 static int txp_download_fw (struct txp_softc *);
127 static int txp_download_fw_wait (struct txp_softc *);
128 static int txp_download_fw_section (struct txp_softc *,
129 struct txp_fw_section_header *, int);
130 static int txp_alloc_rings (struct txp_softc *);
131 static int txp_rxring_fill (struct txp_softc *);
132 static void txp_rxring_empty (struct txp_softc *);
133 static void txp_set_filter (struct txp_softc *);
135 static int txp_cmd_desc_numfree (struct txp_softc *);
136 static int txp_command (struct txp_softc *, u_int16_t, u_int16_t, u_int32_t,
137 u_int32_t, u_int16_t *, u_int32_t *, u_int32_t *, int);
138 static int txp_command2 (struct txp_softc *, u_int16_t, u_int16_t,
139 u_int32_t, u_int32_t, struct txp_ext_desc *, u_int8_t,
140 struct txp_rsp_desc **, int);
141 static int txp_response (struct txp_softc *, u_int32_t, u_int16_t, u_int16_t,
142 struct txp_rsp_desc **);
143 static void txp_rsp_fixup (struct txp_softc *, struct txp_rsp_desc *,
144 struct txp_rsp_desc *);
145 static void txp_capabilities (struct txp_softc *);
147 static void txp_ifmedia_sts (struct ifnet *, struct ifmediareq *);
148 static int txp_ifmedia_upd (struct ifnet *);
150 static void txp_show_descriptor (void *);
152 static void txp_tx_reclaim (struct txp_softc *, struct txp_tx_ring *);
153 static void txp_rxbuf_reclaim (struct txp_softc *);
154 static void txp_rx_reclaim (struct txp_softc *, struct txp_rx_ring *);
156 #ifdef TXP_USEIOSPACE
157 #define TXP_RES SYS_RES_IOPORT
158 #define TXP_RID TXP_PCI_LOIO
160 #define TXP_RES SYS_RES_MEMORY
161 #define TXP_RID TXP_PCI_LOMEM
164 static device_method_t txp_methods[] = {
165 /* Device interface */
166 DEVMETHOD(device_probe, txp_probe),
167 DEVMETHOD(device_attach, txp_attach),
168 DEVMETHOD(device_detach, txp_detach),
169 DEVMETHOD(device_shutdown, txp_shutdown),
173 static driver_t txp_driver = {
176 sizeof(struct txp_softc)
179 static devclass_t txp_devclass;
181 DECLARE_DUMMY_MODULE(if_txp);
182 DRIVER_MODULE(if_txp, pci, txp_driver, txp_devclass, 0, 0);
192 while(t->txp_name != NULL) {
193 if ((pci_get_vendor(dev) == t->txp_vid) &&
194 (pci_get_device(dev) == t->txp_did)) {
195 device_set_desc(dev, t->txp_name);
208 struct txp_softc *sc;
213 int unit, error = 0, rid;
215 sc = device_get_softc(dev);
216 unit = device_get_unit(dev);
221 * Map control/status registers.
223 command = pci_read_config(dev, PCIR_COMMAND, 4);
224 command |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
225 pci_write_config(dev, PCIR_COMMAND, command, 4);
226 command = pci_read_config(dev, PCIR_COMMAND, 4);
228 #ifdef TXP_USEIOSPACE
229 if (!(command & PCIM_CMD_PORTEN)) {
230 device_printf(dev, "failed to enable I/O ports!\n");
235 if (!(command & PCIM_CMD_MEMEN)) {
236 device_printf(dev, "failed to enable memory mapping!\n");
243 sc->sc_res = bus_alloc_resource(dev, TXP_RES, &rid,
244 0, ~0, 1, RF_ACTIVE);
246 if (sc->sc_res == NULL) {
247 device_printf(dev, "couldn't map ports/memory\n");
252 sc->sc_bt = rman_get_bustag(sc->sc_res);
253 sc->sc_bh = rman_get_bushandle(sc->sc_res);
255 /* Allocate interrupt */
257 sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
258 RF_SHAREABLE | RF_ACTIVE);
260 if (sc->sc_irq == NULL) {
261 device_printf(dev, "couldn't map interrupt\n");
262 txp_release_resources(sc);
267 error = bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_NET,
268 txp_intr, sc, &sc->sc_intrhand);
271 txp_release_resources(sc);
272 device_printf(dev, "couldn't set up irq\n");
276 if (txp_chip_init(sc)) {
277 txp_release_resources(sc);
281 sc->sc_fwbuf = contigmalloc(32768, M_DEVBUF,
282 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
283 error = txp_download_fw(sc);
284 contigfree(sc->sc_fwbuf, 32768, M_DEVBUF);
288 txp_release_resources(sc);
292 sc->sc_ldata = contigmalloc(sizeof(struct txp_ldata), M_DEVBUF,
293 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
294 bzero(sc->sc_ldata, sizeof(struct txp_ldata));
296 if (txp_alloc_rings(sc)) {
297 txp_release_resources(sc);
301 if (txp_command(sc, TXP_CMD_MAX_PKT_SIZE_WRITE, TXP_MAX_PKTLEN, 0, 0,
302 NULL, NULL, NULL, 1)) {
303 txp_release_resources(sc);
307 if (txp_command(sc, TXP_CMD_STATION_ADDRESS_READ, 0, 0, 0,
308 &p1, &p2, NULL, 1)) {
309 txp_release_resources(sc);
315 sc->sc_arpcom.ac_enaddr[0] = ((uint8_t *)&p1)[1];
316 sc->sc_arpcom.ac_enaddr[1] = ((uint8_t *)&p1)[0];
317 sc->sc_arpcom.ac_enaddr[2] = ((uint8_t *)&p2)[3];
318 sc->sc_arpcom.ac_enaddr[3] = ((uint8_t *)&p2)[2];
319 sc->sc_arpcom.ac_enaddr[4] = ((uint8_t *)&p2)[1];
320 sc->sc_arpcom.ac_enaddr[5] = ((uint8_t *)&p2)[0];
324 ifmedia_init(&sc->sc_ifmedia, 0, txp_ifmedia_upd, txp_ifmedia_sts);
325 ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
326 ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_10_T|IFM_HDX, 0, NULL);
327 ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);
328 ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL);
329 ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_100_TX|IFM_HDX, 0, NULL);
330 ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL);
331 ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
333 sc->sc_xcvr = TXP_XCVR_AUTO;
334 txp_command(sc, TXP_CMD_XCVR_SELECT, TXP_XCVR_AUTO, 0, 0,
335 NULL, NULL, NULL, 0);
336 ifmedia_set(&sc->sc_ifmedia, IFM_ETHER|IFM_AUTO);
338 ifp = &sc->sc_arpcom.ac_if;
340 if_initname(ifp, "txp", unit);
341 ifp->if_mtu = ETHERMTU;
342 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
343 ifp->if_ioctl = txp_ioctl;
344 ifp->if_output = ether_output;
345 ifp->if_start = txp_start;
346 ifp->if_watchdog = txp_watchdog;
347 ifp->if_init = txp_init;
348 ifp->if_baudrate = 100000000;
349 ifp->if_snd.ifq_maxlen = TX_ENTRIES;
350 ifp->if_hwassist = 0;
351 txp_capabilities(sc);
354 * Attach us everywhere
356 ether_ifattach(ifp, sc->sc_arpcom.ac_enaddr);
357 callout_handle_init(&sc->sc_tick);
361 txp_release_resources(sc);
369 struct txp_softc *sc;
373 sc = device_get_softc(dev);
374 ifp = &sc->sc_arpcom.ac_if;
379 ifmedia_removeall(&sc->sc_ifmedia);
382 for (i = 0; i < RXBUF_ENTRIES; i++)
383 free(sc->sc_rxbufs[i].rb_sd, M_DEVBUF);
385 txp_release_resources(sc);
391 txp_release_resources(sc)
392 struct txp_softc *sc;
398 if (sc->sc_intrhand != NULL)
399 bus_teardown_intr(dev, sc->sc_irq, sc->sc_intrhand);
401 if (sc->sc_irq != NULL)
402 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq);
404 if (sc->sc_res != NULL)
405 bus_release_resource(dev, TXP_RES, TXP_RID, sc->sc_res);
407 if (sc->sc_ldata != NULL)
408 contigfree(sc->sc_ldata, sizeof(struct txp_ldata), M_DEVBUF);
415 struct txp_softc *sc;
417 /* disable interrupts */
418 WRITE_REG(sc, TXP_IER, 0);
419 WRITE_REG(sc, TXP_IMR,
420 TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
421 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
424 /* ack all interrupts */
425 WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
426 TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
427 TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
428 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
429 TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
431 if (txp_reset_adapter(sc))
434 /* disable interrupts */
435 WRITE_REG(sc, TXP_IER, 0);
436 WRITE_REG(sc, TXP_IMR,
437 TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
438 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
441 /* ack all interrupts */
442 WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
443 TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
444 TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
445 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
446 TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
452 txp_reset_adapter(sc)
453 struct txp_softc *sc;
458 WRITE_REG(sc, TXP_SRR, TXP_SRR_ALL);
460 WRITE_REG(sc, TXP_SRR, 0);
462 /* Should wait max 6 seconds */
463 for (i = 0; i < 6000; i++) {
464 r = READ_REG(sc, TXP_A2H_0);
465 if (r == STAT_WAITING_FOR_HOST_REQUEST)
470 if (r != STAT_WAITING_FOR_HOST_REQUEST) {
471 device_printf(sc->sc_dev, "reset hung\n");
480 struct txp_softc *sc;
482 struct txp_fw_file_header *fileheader;
483 struct txp_fw_section_header *secthead;
485 u_int32_t r, i, ier, imr;
487 ier = READ_REG(sc, TXP_IER);
488 WRITE_REG(sc, TXP_IER, ier | TXP_INT_A2H_0);
490 imr = READ_REG(sc, TXP_IMR);
491 WRITE_REG(sc, TXP_IMR, imr | TXP_INT_A2H_0);
493 for (i = 0; i < 10000; i++) {
494 r = READ_REG(sc, TXP_A2H_0);
495 if (r == STAT_WAITING_FOR_HOST_REQUEST)
499 if (r != STAT_WAITING_FOR_HOST_REQUEST) {
500 device_printf(sc->sc_dev, "not waiting for host request\n");
505 WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
507 fileheader = (struct txp_fw_file_header *)tc990image;
508 if (bcmp("TYPHOON", fileheader->magicid, sizeof(fileheader->magicid))) {
509 device_printf(sc->sc_dev, "fw invalid magic\n");
513 /* Tell boot firmware to get ready for image */
514 WRITE_REG(sc, TXP_H2A_1, fileheader->addr);
515 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_RUNTIME_IMAGE);
517 if (txp_download_fw_wait(sc)) {
518 device_printf(sc->sc_dev, "fw wait failed, initial\n");
522 secthead = (struct txp_fw_section_header *)(((u_int8_t *)tc990image) +
523 sizeof(struct txp_fw_file_header));
525 for (sect = 0; sect < fileheader->nsections; sect++) {
526 if (txp_download_fw_section(sc, secthead, sect))
528 secthead = (struct txp_fw_section_header *)
529 (((u_int8_t *)secthead) + secthead->nbytes +
533 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_DOWNLOAD_COMPLETE);
535 for (i = 0; i < 10000; i++) {
536 r = READ_REG(sc, TXP_A2H_0);
537 if (r == STAT_WAITING_FOR_BOOT)
541 if (r != STAT_WAITING_FOR_BOOT) {
542 device_printf(sc->sc_dev, "not waiting for boot\n");
546 WRITE_REG(sc, TXP_IER, ier);
547 WRITE_REG(sc, TXP_IMR, imr);
553 txp_download_fw_wait(sc)
554 struct txp_softc *sc;
558 for (i = 0; i < 10000; i++) {
559 r = READ_REG(sc, TXP_ISR);
560 if (r & TXP_INT_A2H_0)
565 if (!(r & TXP_INT_A2H_0)) {
566 device_printf(sc->sc_dev, "fw wait failed comm0\n");
570 WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
572 r = READ_REG(sc, TXP_A2H_0);
573 if (r != STAT_WAITING_FOR_SEGMENT) {
574 device_printf(sc->sc_dev, "fw not waiting for segment\n");
581 txp_download_fw_section(sc, sect, sectnum)
582 struct txp_softc *sc;
583 struct txp_fw_section_header *sect;
591 /* Skip zero length sections */
592 if (sect->nbytes == 0)
595 /* Make sure we aren't past the end of the image */
596 rseg = ((u_int8_t *)sect) - ((u_int8_t *)tc990image);
597 if (rseg >= sizeof(tc990image)) {
598 device_printf(sc->sc_dev, "fw invalid section address, "
599 "section %d\n", sectnum);
603 /* Make sure this section doesn't go past the end */
604 rseg += sect->nbytes;
605 if (rseg >= sizeof(tc990image)) {
606 device_printf(sc->sc_dev, "fw truncated section %d\n",
611 bcopy(((u_int8_t *)sect) + sizeof(*sect), sc->sc_fwbuf, sect->nbytes);
612 dma = vtophys(sc->sc_fwbuf);
615 * dummy up mbuf and verify section checksum
618 m.m_next = m.m_nextpkt = NULL;
619 m.m_len = sect->nbytes;
620 m.m_data = sc->sc_fwbuf;
622 csum = in_cksum(&m, sect->nbytes);
623 if (csum != sect->cksum) {
624 device_printf(sc->sc_dev, "fw section %d, bad "
625 "cksum (expected 0x%x got 0x%x)\n",
626 sectnum, sect->cksum, csum);
631 WRITE_REG(sc, TXP_H2A_1, sect->nbytes);
632 WRITE_REG(sc, TXP_H2A_2, sect->cksum);
633 WRITE_REG(sc, TXP_H2A_3, sect->addr);
634 WRITE_REG(sc, TXP_H2A_4, 0);
635 WRITE_REG(sc, TXP_H2A_5, dma & 0xffffffff);
636 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_SEGMENT_AVAILABLE);
638 if (txp_download_fw_wait(sc)) {
639 device_printf(sc->sc_dev, "fw wait failed, "
640 "section %d\n", sectnum);
652 struct txp_softc *sc = vsc;
653 struct txp_hostvar *hv = sc->sc_hostvar;
656 /* mask all interrupts */
657 WRITE_REG(sc, TXP_IMR, TXP_INT_RESERVED | TXP_INT_SELF |
658 TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
659 TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
660 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
661 TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT | TXP_INT_LATCH);
663 isr = READ_REG(sc, TXP_ISR);
665 WRITE_REG(sc, TXP_ISR, isr);
667 if ((*sc->sc_rxhir.r_roff) != (*sc->sc_rxhir.r_woff))
668 txp_rx_reclaim(sc, &sc->sc_rxhir);
669 if ((*sc->sc_rxlor.r_roff) != (*sc->sc_rxlor.r_woff))
670 txp_rx_reclaim(sc, &sc->sc_rxlor);
672 if (hv->hv_rx_buf_write_idx == hv->hv_rx_buf_read_idx)
673 txp_rxbuf_reclaim(sc);
675 if (sc->sc_txhir.r_cnt && (sc->sc_txhir.r_cons !=
676 TXP_OFFSET2IDX(*(sc->sc_txhir.r_off))))
677 txp_tx_reclaim(sc, &sc->sc_txhir);
679 if (sc->sc_txlor.r_cnt && (sc->sc_txlor.r_cons !=
680 TXP_OFFSET2IDX(*(sc->sc_txlor.r_off))))
681 txp_tx_reclaim(sc, &sc->sc_txlor);
683 isr = READ_REG(sc, TXP_ISR);
686 /* unmask all interrupts */
687 WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
689 txp_start(&sc->sc_arpcom.ac_if);
695 txp_rx_reclaim(sc, r)
696 struct txp_softc *sc;
697 struct txp_rx_ring *r;
699 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
700 struct txp_rx_desc *rxd;
702 struct txp_swdesc *sd = NULL;
703 u_int32_t roff, woff;
704 struct ether_header *eh = NULL;
708 rxd = r->r_desc + (roff / sizeof(struct txp_rx_desc));
710 while (roff != woff) {
712 if (rxd->rx_flags & RX_FLAGS_ERROR) {
713 device_printf(sc->sc_dev, "error 0x%x\n",
719 /* retrieve stashed pointer */
725 m->m_pkthdr.len = m->m_len = rxd->rx_len;
727 #ifdef __STRICT_ALIGNMENT
730 * XXX Nice chip, except it won't accept "off by 2"
731 * buffers, so we're force to copy. Supposedly
732 * this will be fixed in a newer firmware rev
733 * and this will be temporary.
737 MGETHDR(mnew, MB_DONTWAIT, MT_DATA);
742 if (m->m_len > (MHLEN - 2)) {
743 MCLGET(mnew, MB_DONTWAIT);
744 if (!(mnew->m_flags & M_EXT)) {
750 mnew->m_pkthdr.rcvif = ifp;
752 mnew->m_pkthdr.len = mnew->m_len = m->m_len;
753 m_copydata(m, 0, m->m_pkthdr.len, mtod(mnew, caddr_t));
759 if (rxd->rx_stat & RX_STAT_IPCKSUMBAD)
760 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
761 else if (rxd->rx_stat & RX_STAT_IPCKSUMGOOD)
762 m->m_pkthdr.csum_flags |=
763 CSUM_IP_CHECKED|CSUM_IP_VALID;
765 if ((rxd->rx_stat & RX_STAT_TCPCKSUMGOOD) ||
766 (rxd->rx_stat & RX_STAT_UDPCKSUMGOOD)) {
767 m->m_pkthdr.csum_flags |=
768 CSUM_DATA_VALID|CSUM_PSEUDO_HDR;
769 m->m_pkthdr.csum_data = 0xffff;
772 eh = mtod(m, struct ether_header *);
773 /* Remove header from mbuf and pass it on. */
774 m_adj(m, sizeof(struct ether_header));
776 if (rxd->rx_stat & RX_STAT_VLAN) {
777 VLAN_INPUT_TAG(eh, m, htons(rxd->rx_vlan >> 16));
781 ether_input(ifp, eh, m);
785 roff += sizeof(struct txp_rx_desc);
786 if (roff == (RX_ENTRIES * sizeof(struct txp_rx_desc))) {
800 txp_rxbuf_reclaim(sc)
801 struct txp_softc *sc;
803 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
804 struct txp_hostvar *hv = sc->sc_hostvar;
805 struct txp_rxbuf_desc *rbd;
806 struct txp_swdesc *sd;
809 if (!(ifp->if_flags & IFF_RUNNING))
812 i = sc->sc_rxbufprod;
813 rbd = sc->sc_rxbufs + i;
817 if (sd->sd_mbuf != NULL)
820 MGETHDR(sd->sd_mbuf, MB_DONTWAIT, MT_DATA);
821 if (sd->sd_mbuf == NULL)
824 MCLGET(sd->sd_mbuf, MB_DONTWAIT);
825 if ((sd->sd_mbuf->m_flags & M_EXT) == 0)
827 sd->sd_mbuf->m_pkthdr.rcvif = ifp;
828 sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
830 rbd->rb_paddrlo = vtophys(mtod(sd->sd_mbuf, vm_offset_t))
834 hv->hv_rx_buf_write_idx = TXP_IDX2OFFSET(i);
836 if (++i == RXBUF_ENTRIES) {
843 sc->sc_rxbufprod = i;
848 m_freem(sd->sd_mbuf);
854 * Reclaim mbufs and entries from a transmit ring.
857 txp_tx_reclaim(sc, r)
858 struct txp_softc *sc;
859 struct txp_tx_ring *r;
861 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
862 u_int32_t idx = TXP_OFFSET2IDX(*(r->r_off));
863 u_int32_t cons = r->r_cons, cnt = r->r_cnt;
864 struct txp_tx_desc *txd = r->r_desc + cons;
865 struct txp_swdesc *sd = sc->sc_txd + cons;
868 while (cons != idx) {
872 if ((txd->tx_flags & TX_FLAGS_TYPE_M) ==
873 TX_FLAGS_TYPE_DATA) {
882 ifp->if_flags &= ~IFF_OACTIVE;
884 if (++cons == TX_ENTRIES) {
906 struct txp_softc *sc;
908 sc = device_get_softc(dev);
910 /* mask all interrupts */
911 WRITE_REG(sc, TXP_IMR,
912 TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
913 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
916 txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
917 txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
918 txp_command(sc, TXP_CMD_HALT, 0, 0, 0, NULL, NULL, NULL, 0);
925 struct txp_softc *sc;
927 struct txp_boot_record *boot;
928 struct txp_ldata *ld;
933 boot = &ld->txp_boot;
939 bzero(&ld->txp_hostvar, sizeof(struct txp_hostvar));
940 boot->br_hostvar_lo = vtophys(&ld->txp_hostvar);
941 boot->br_hostvar_hi = 0;
942 sc->sc_hostvar = (struct txp_hostvar *)&ld->txp_hostvar;
944 /* hi priority tx ring */
945 boot->br_txhipri_lo = vtophys(&ld->txp_txhiring);;
946 boot->br_txhipri_hi = 0;
947 boot->br_txhipri_siz = TX_ENTRIES * sizeof(struct txp_tx_desc);
948 sc->sc_txhir.r_reg = TXP_H2A_1;
949 sc->sc_txhir.r_desc = (struct txp_tx_desc *)&ld->txp_txhiring;
950 sc->sc_txhir.r_cons = sc->sc_txhir.r_prod = sc->sc_txhir.r_cnt = 0;
951 sc->sc_txhir.r_off = &sc->sc_hostvar->hv_tx_hi_desc_read_idx;
953 /* lo priority tx ring */
954 boot->br_txlopri_lo = vtophys(&ld->txp_txloring);
955 boot->br_txlopri_hi = 0;
956 boot->br_txlopri_siz = TX_ENTRIES * sizeof(struct txp_tx_desc);
957 sc->sc_txlor.r_reg = TXP_H2A_3;
958 sc->sc_txlor.r_desc = (struct txp_tx_desc *)&ld->txp_txloring;
959 sc->sc_txlor.r_cons = sc->sc_txlor.r_prod = sc->sc_txlor.r_cnt = 0;
960 sc->sc_txlor.r_off = &sc->sc_hostvar->hv_tx_lo_desc_read_idx;
962 /* high priority rx ring */
963 boot->br_rxhipri_lo = vtophys(&ld->txp_rxhiring);
964 boot->br_rxhipri_hi = 0;
965 boot->br_rxhipri_siz = RX_ENTRIES * sizeof(struct txp_rx_desc);
966 sc->sc_rxhir.r_desc = (struct txp_rx_desc *)&ld->txp_rxhiring;
967 sc->sc_rxhir.r_roff = &sc->sc_hostvar->hv_rx_hi_read_idx;
968 sc->sc_rxhir.r_woff = &sc->sc_hostvar->hv_rx_hi_write_idx;
970 /* low priority rx ring */
971 boot->br_rxlopri_lo = vtophys(&ld->txp_rxloring);
972 boot->br_rxlopri_hi = 0;
973 boot->br_rxlopri_siz = RX_ENTRIES * sizeof(struct txp_rx_desc);
974 sc->sc_rxlor.r_desc = (struct txp_rx_desc *)&ld->txp_rxloring;
975 sc->sc_rxlor.r_roff = &sc->sc_hostvar->hv_rx_lo_read_idx;
976 sc->sc_rxlor.r_woff = &sc->sc_hostvar->hv_rx_lo_write_idx;
979 bzero(&ld->txp_cmdring, sizeof(struct txp_cmd_desc) * CMD_ENTRIES);
980 boot->br_cmd_lo = vtophys(&ld->txp_cmdring);
982 boot->br_cmd_siz = CMD_ENTRIES * sizeof(struct txp_cmd_desc);
983 sc->sc_cmdring.base = (struct txp_cmd_desc *)&ld->txp_cmdring;
984 sc->sc_cmdring.size = CMD_ENTRIES * sizeof(struct txp_cmd_desc);
985 sc->sc_cmdring.lastwrite = 0;
988 bzero(&ld->txp_rspring, sizeof(struct txp_rsp_desc) * RSP_ENTRIES);
989 boot->br_resp_lo = vtophys(&ld->txp_rspring);
990 boot->br_resp_hi = 0;
991 boot->br_resp_siz = CMD_ENTRIES * sizeof(struct txp_rsp_desc);
992 sc->sc_rspring.base = (struct txp_rsp_desc *)&ld->txp_rspring;
993 sc->sc_rspring.size = RSP_ENTRIES * sizeof(struct txp_rsp_desc);
994 sc->sc_rspring.lastwrite = 0;
996 /* receive buffer ring */
997 boot->br_rxbuf_lo = vtophys(&ld->txp_rxbufs);
998 boot->br_rxbuf_hi = 0;
999 boot->br_rxbuf_siz = RXBUF_ENTRIES * sizeof(struct txp_rxbuf_desc);
1000 sc->sc_rxbufs = (struct txp_rxbuf_desc *)&ld->txp_rxbufs;
1002 for (i = 0; i < RXBUF_ENTRIES; i++) {
1003 struct txp_swdesc *sd;
1004 if (sc->sc_rxbufs[i].rb_sd != NULL)
1006 sc->sc_rxbufs[i].rb_sd = malloc(sizeof(struct txp_swdesc),
1007 M_DEVBUF, M_WAITOK);
1008 if (sc->sc_rxbufs[i].rb_sd == NULL)
1010 sd = sc->sc_rxbufs[i].rb_sd;
1013 sc->sc_rxbufprod = 0;
1016 bzero(&ld->txp_zero, sizeof(u_int32_t));
1017 boot->br_zero_lo = vtophys(&ld->txp_zero);
1018 boot->br_zero_hi = 0;
1020 /* See if it's waiting for boot, and try to boot it */
1021 for (i = 0; i < 10000; i++) {
1022 r = READ_REG(sc, TXP_A2H_0);
1023 if (r == STAT_WAITING_FOR_BOOT)
1028 if (r != STAT_WAITING_FOR_BOOT) {
1029 device_printf(sc->sc_dev, "not waiting for boot\n");
1033 WRITE_REG(sc, TXP_H2A_2, 0);
1034 WRITE_REG(sc, TXP_H2A_1, vtophys(sc->sc_boot));
1035 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_REGISTER_BOOT_RECORD);
1037 /* See if it booted */
1038 for (i = 0; i < 10000; i++) {
1039 r = READ_REG(sc, TXP_A2H_0);
1040 if (r == STAT_RUNNING)
1044 if (r != STAT_RUNNING) {
1045 device_printf(sc->sc_dev, "fw not running\n");
1049 /* Clear TX and CMD ring write registers */
1050 WRITE_REG(sc, TXP_H2A_1, TXP_BOOTCMD_NULL);
1051 WRITE_REG(sc, TXP_H2A_2, TXP_BOOTCMD_NULL);
1052 WRITE_REG(sc, TXP_H2A_3, TXP_BOOTCMD_NULL);
1053 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_NULL);
1059 txp_ioctl(ifp, command, data, cr)
1065 struct txp_softc *sc = ifp->if_softc;
1066 struct ifreq *ifr = (struct ifreq *)data;
1071 if ((error = ether_ioctl(ifp, command, data)) > 0) {
1080 error = ether_ioctl(ifp, command, data);
1083 if (ifp->if_flags & IFF_UP) {
1086 if (ifp->if_flags & IFF_RUNNING)
1093 * Multicast list has changed; set the hardware
1094 * filter accordingly.
1101 error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, command);
1115 struct txp_softc *sc;
1119 struct txp_swdesc *sd;
1121 ifp = &sc->sc_arpcom.ac_if;
1123 for (i = 0; i < RXBUF_ENTRIES; i++) {
1124 sd = sc->sc_rxbufs[i].rb_sd;
1125 MGETHDR(sd->sd_mbuf, MB_DONTWAIT, MT_DATA);
1126 if (sd->sd_mbuf == NULL)
1129 MCLGET(sd->sd_mbuf, MB_DONTWAIT);
1130 if ((sd->sd_mbuf->m_flags & M_EXT) == 0) {
1131 m_freem(sd->sd_mbuf);
1134 sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
1135 sd->sd_mbuf->m_pkthdr.rcvif = ifp;
1137 sc->sc_rxbufs[i].rb_paddrlo =
1138 vtophys(mtod(sd->sd_mbuf, vm_offset_t));
1139 sc->sc_rxbufs[i].rb_paddrhi = 0;
1142 sc->sc_hostvar->hv_rx_buf_write_idx = (RXBUF_ENTRIES - 1) *
1143 sizeof(struct txp_rxbuf_desc);
1149 txp_rxring_empty(sc)
1150 struct txp_softc *sc;
1153 struct txp_swdesc *sd;
1155 if (sc->sc_rxbufs == NULL)
1158 for (i = 0; i < RXBUF_ENTRIES; i++) {
1159 if (&sc->sc_rxbufs[i] == NULL)
1161 sd = sc->sc_rxbufs[i].rb_sd;
1164 if (sd->sd_mbuf != NULL) {
1165 m_freem(sd->sd_mbuf);
1177 struct txp_softc *sc;
1184 ifp = &sc->sc_arpcom.ac_if;
1186 if (ifp->if_flags & IFF_RUNNING)
1193 txp_command(sc, TXP_CMD_MAX_PKT_SIZE_WRITE, TXP_MAX_PKTLEN, 0, 0,
1194 NULL, NULL, NULL, 1);
1196 /* Set station address. */
1197 ((u_int8_t *)&p1)[1] = sc->sc_arpcom.ac_enaddr[0];
1198 ((u_int8_t *)&p1)[0] = sc->sc_arpcom.ac_enaddr[1];
1199 ((u_int8_t *)&p2)[3] = sc->sc_arpcom.ac_enaddr[2];
1200 ((u_int8_t *)&p2)[2] = sc->sc_arpcom.ac_enaddr[3];
1201 ((u_int8_t *)&p2)[1] = sc->sc_arpcom.ac_enaddr[4];
1202 ((u_int8_t *)&p2)[0] = sc->sc_arpcom.ac_enaddr[5];
1203 txp_command(sc, TXP_CMD_STATION_ADDRESS_WRITE, p1, p2, 0,
1204 NULL, NULL, NULL, 1);
1208 txp_rxring_fill(sc);
1210 txp_command(sc, TXP_CMD_TX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1211 txp_command(sc, TXP_CMD_RX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1213 WRITE_REG(sc, TXP_IER, TXP_INT_RESERVED | TXP_INT_SELF |
1214 TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
1215 TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
1216 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
1217 TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT | TXP_INT_LATCH);
1218 WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
1220 ifp->if_flags |= IFF_RUNNING;
1221 ifp->if_flags &= ~IFF_OACTIVE;
1224 sc->sc_tick = timeout(txp_tick, sc, hz);
1233 struct txp_softc *sc = vsc;
1234 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
1235 struct txp_rsp_desc *rsp = NULL;
1236 struct txp_ext_desc *ext;
1240 txp_rxbuf_reclaim(sc);
1242 if (txp_command2(sc, TXP_CMD_READ_STATISTICS, 0, 0, 0, NULL, 0,
1245 if (rsp->rsp_numdesc != 6)
1247 if (txp_command(sc, TXP_CMD_CLEAR_STATISTICS, 0, 0, 0,
1248 NULL, NULL, NULL, 1))
1250 ext = (struct txp_ext_desc *)(rsp + 1);
1252 ifp->if_ierrors += ext[3].ext_2 + ext[3].ext_3 + ext[3].ext_4 +
1253 ext[4].ext_1 + ext[4].ext_4;
1254 ifp->if_oerrors += ext[0].ext_1 + ext[1].ext_1 + ext[1].ext_4 +
1256 ifp->if_collisions += ext[0].ext_2 + ext[0].ext_3 + ext[1].ext_2 +
1258 ifp->if_opackets += rsp->rsp_par2;
1259 ifp->if_ipackets += ext[2].ext_3;
1263 free(rsp, M_DEVBUF);
1266 sc->sc_tick = timeout(txp_tick, sc, hz);
1275 struct txp_softc *sc = ifp->if_softc;
1276 struct txp_tx_ring *r = &sc->sc_txhir;
1277 struct txp_tx_desc *txd;
1278 struct txp_frag_desc *fxd;
1279 struct mbuf *m, *m0;
1280 struct txp_swdesc *sd;
1281 u_int32_t firstprod, firstcnt, prod, cnt;
1284 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
1291 IF_DEQUEUE(&ifp->if_snd, m);
1298 sd = sc->sc_txd + prod;
1301 if ((TX_ENTRIES - cnt) < 4)
1304 txd = r->r_desc + prod;
1306 txd->tx_flags = TX_FLAGS_TYPE_DATA;
1307 txd->tx_numdesc = 0;
1313 if (++prod == TX_ENTRIES)
1316 if (++cnt >= (TX_ENTRIES - 4))
1319 if ((m->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
1320 m->m_pkthdr.rcvif != NULL) {
1321 ifv = m->m_pkthdr.rcvif->if_softc;
1322 txd->tx_pflags = TX_PFLAGS_VLAN |
1323 (htons(ifv->ifv_tag) << TX_PFLAGS_VLANTAG_S);
1326 if (m->m_pkthdr.csum_flags & CSUM_IP)
1327 txd->tx_pflags |= TX_PFLAGS_IPCKSUM;
1330 if (m->m_pkthdr.csum_flags & CSUM_TCP)
1331 txd->tx_pflags |= TX_PFLAGS_TCPCKSUM;
1332 if (m->m_pkthdr.csum_flags & CSUM_UDP)
1333 txd->tx_pflags |= TX_PFLAGS_UDPCKSUM;
1336 fxd = (struct txp_frag_desc *)(r->r_desc + prod);
1337 for (m0 = m; m0 != NULL; m0 = m0->m_next) {
1340 if (++cnt >= (TX_ENTRIES - 4))
1345 fxd->frag_flags = FRAG_FLAGS_TYPE_FRAG;
1346 fxd->frag_rsvd1 = 0;
1347 fxd->frag_len = m0->m_len;
1348 fxd->frag_addrlo = vtophys(mtod(m0, vm_offset_t));
1349 fxd->frag_addrhi = 0;
1350 fxd->frag_rsvd2 = 0;
1352 if (++prod == TX_ENTRIES) {
1353 fxd = (struct txp_frag_desc *)r->r_desc;
1364 WRITE_REG(sc, r->r_reg, TXP_IDX2OFFSET(prod));
1372 ifp->if_flags |= IFF_OACTIVE;
1373 r->r_prod = firstprod;
1374 r->r_cnt = firstcnt;
1375 IF_PREPEND(&ifp->if_snd, m);
1380 * Handle simple commands sent to the typhoon
1383 txp_command(sc, id, in1, in2, in3, out1, out2, out3, wait)
1384 struct txp_softc *sc;
1385 u_int16_t id, in1, *out1;
1386 u_int32_t in2, in3, *out2, *out3;
1389 struct txp_rsp_desc *rsp = NULL;
1391 if (txp_command2(sc, id, in1, in2, in3, NULL, 0, &rsp, wait))
1398 *out1 = rsp->rsp_par1;
1400 *out2 = rsp->rsp_par2;
1402 *out3 = rsp->rsp_par3;
1403 free(rsp, M_DEVBUF);
1408 txp_command2(sc, id, in1, in2, in3, in_extp, in_extn, rspp, wait)
1409 struct txp_softc *sc;
1412 struct txp_ext_desc *in_extp;
1414 struct txp_rsp_desc **rspp;
1417 struct txp_hostvar *hv = sc->sc_hostvar;
1418 struct txp_cmd_desc *cmd;
1419 struct txp_ext_desc *ext;
1423 if (txp_cmd_desc_numfree(sc) < (in_extn + 1)) {
1424 device_printf(sc->sc_dev, "no free cmd descriptors\n");
1428 idx = sc->sc_cmdring.lastwrite;
1429 cmd = (struct txp_cmd_desc *)(((u_int8_t *)sc->sc_cmdring.base) + idx);
1430 bzero(cmd, sizeof(*cmd));
1432 cmd->cmd_numdesc = in_extn;
1433 cmd->cmd_seq = seq = sc->sc_seq++;
1435 cmd->cmd_par1 = in1;
1436 cmd->cmd_par2 = in2;
1437 cmd->cmd_par3 = in3;
1438 cmd->cmd_flags = CMD_FLAGS_TYPE_CMD |
1439 (wait ? CMD_FLAGS_RESP : 0) | CMD_FLAGS_VALID;
1441 idx += sizeof(struct txp_cmd_desc);
1442 if (idx == sc->sc_cmdring.size)
1445 for (i = 0; i < in_extn; i++) {
1446 ext = (struct txp_ext_desc *)(((u_int8_t *)sc->sc_cmdring.base) + idx);
1447 bcopy(in_extp, ext, sizeof(struct txp_ext_desc));
1449 idx += sizeof(struct txp_cmd_desc);
1450 if (idx == sc->sc_cmdring.size)
1454 sc->sc_cmdring.lastwrite = idx;
1456 WRITE_REG(sc, TXP_H2A_2, sc->sc_cmdring.lastwrite);
1461 for (i = 0; i < 10000; i++) {
1462 idx = hv->hv_resp_read_idx;
1463 if (idx != hv->hv_resp_write_idx) {
1465 if (txp_response(sc, idx, id, seq, rspp))
1472 if (i == 1000 || (*rspp) == NULL) {
1473 device_printf(sc->sc_dev, "0x%x command failed\n", id);
1481 txp_response(sc, ridx, id, seq, rspp)
1482 struct txp_softc *sc;
1486 struct txp_rsp_desc **rspp;
1488 struct txp_hostvar *hv = sc->sc_hostvar;
1489 struct txp_rsp_desc *rsp;
1491 while (ridx != hv->hv_resp_write_idx) {
1492 rsp = (struct txp_rsp_desc *)(((u_int8_t *)sc->sc_rspring.base) + ridx);
1494 if (id == rsp->rsp_id && rsp->rsp_seq == seq) {
1495 *rspp = (struct txp_rsp_desc *)malloc(
1496 sizeof(struct txp_rsp_desc) * (rsp->rsp_numdesc + 1),
1497 M_DEVBUF, M_INTWAIT);
1498 if ((*rspp) == NULL)
1500 txp_rsp_fixup(sc, rsp, *rspp);
1504 if (rsp->rsp_flags & RSP_FLAGS_ERROR) {
1505 device_printf(sc->sc_dev, "response error!\n");
1506 txp_rsp_fixup(sc, rsp, NULL);
1507 ridx = hv->hv_resp_read_idx;
1511 switch (rsp->rsp_id) {
1512 case TXP_CMD_CYCLE_STATISTICS:
1513 case TXP_CMD_MEDIA_STATUS_READ:
1515 case TXP_CMD_HELLO_RESPONSE:
1516 device_printf(sc->sc_dev, "hello\n");
1519 device_printf(sc->sc_dev, "unknown id(0x%x)\n",
1523 txp_rsp_fixup(sc, rsp, NULL);
1524 ridx = hv->hv_resp_read_idx;
1525 hv->hv_resp_read_idx = ridx;
1532 txp_rsp_fixup(sc, rsp, dst)
1533 struct txp_softc *sc;
1534 struct txp_rsp_desc *rsp, *dst;
1536 struct txp_rsp_desc *src = rsp;
1537 struct txp_hostvar *hv = sc->sc_hostvar;
1540 ridx = hv->hv_resp_read_idx;
1542 for (i = 0; i < rsp->rsp_numdesc + 1; i++) {
1544 bcopy(src, dst++, sizeof(struct txp_rsp_desc));
1545 ridx += sizeof(struct txp_rsp_desc);
1546 if (ridx == sc->sc_rspring.size) {
1547 src = sc->sc_rspring.base;
1551 sc->sc_rspring.lastwrite = hv->hv_resp_read_idx = ridx;
1554 hv->hv_resp_read_idx = ridx;
1558 txp_cmd_desc_numfree(sc)
1559 struct txp_softc *sc;
1561 struct txp_hostvar *hv = sc->sc_hostvar;
1562 struct txp_boot_record *br = sc->sc_boot;
1563 u_int32_t widx, ridx, nfree;
1565 widx = sc->sc_cmdring.lastwrite;
1566 ridx = hv->hv_cmd_read_idx;
1569 /* Ring is completely free */
1570 nfree = br->br_cmd_siz - sizeof(struct txp_cmd_desc);
1573 nfree = br->br_cmd_siz -
1574 (widx - ridx + sizeof(struct txp_cmd_desc));
1576 nfree = ridx - widx - sizeof(struct txp_cmd_desc);
1579 return (nfree / sizeof(struct txp_cmd_desc));
1584 struct txp_softc *sc;
1588 ifp = &sc->sc_arpcom.ac_if;
1590 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1592 untimeout(txp_tick, sc, sc->sc_tick);
1594 txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1595 txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1597 txp_rxring_empty(sc);
1610 txp_ifmedia_upd(ifp)
1613 struct txp_softc *sc = ifp->if_softc;
1614 struct ifmedia *ifm = &sc->sc_ifmedia;
1617 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1620 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_10_T) {
1621 if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
1622 new_xcvr = TXP_XCVR_10_FDX;
1624 new_xcvr = TXP_XCVR_10_HDX;
1625 } else if (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) {
1626 if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
1627 new_xcvr = TXP_XCVR_100_FDX;
1629 new_xcvr = TXP_XCVR_100_HDX;
1630 } else if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) {
1631 new_xcvr = TXP_XCVR_AUTO;
1636 if (sc->sc_xcvr == new_xcvr)
1639 txp_command(sc, TXP_CMD_XCVR_SELECT, new_xcvr, 0, 0,
1640 NULL, NULL, NULL, 0);
1641 sc->sc_xcvr = new_xcvr;
1647 txp_ifmedia_sts(ifp, ifmr)
1649 struct ifmediareq *ifmr;
1651 struct txp_softc *sc = ifp->if_softc;
1652 struct ifmedia *ifm = &sc->sc_ifmedia;
1653 u_int16_t bmsr, bmcr, anlpar;
1655 ifmr->ifm_status = IFM_AVALID;
1656 ifmr->ifm_active = IFM_ETHER;
1658 if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
1659 &bmsr, NULL, NULL, 1))
1661 if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
1662 &bmsr, NULL, NULL, 1))
1665 if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMCR, 0,
1666 &bmcr, NULL, NULL, 1))
1669 if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_ANLPAR, 0,
1670 &anlpar, NULL, NULL, 1))
1673 if (bmsr & BMSR_LINK)
1674 ifmr->ifm_status |= IFM_ACTIVE;
1676 if (bmcr & BMCR_ISO) {
1677 ifmr->ifm_active |= IFM_NONE;
1678 ifmr->ifm_status = 0;
1682 if (bmcr & BMCR_LOOP)
1683 ifmr->ifm_active |= IFM_LOOP;
1685 if (bmcr & BMCR_AUTOEN) {
1686 if ((bmsr & BMSR_ACOMP) == 0) {
1687 ifmr->ifm_active |= IFM_NONE;
1691 if (anlpar & ANLPAR_T4)
1692 ifmr->ifm_active |= IFM_100_T4;
1693 else if (anlpar & ANLPAR_TX_FD)
1694 ifmr->ifm_active |= IFM_100_TX|IFM_FDX;
1695 else if (anlpar & ANLPAR_TX)
1696 ifmr->ifm_active |= IFM_100_TX;
1697 else if (anlpar & ANLPAR_10_FD)
1698 ifmr->ifm_active |= IFM_10_T|IFM_FDX;
1699 else if (anlpar & ANLPAR_10)
1700 ifmr->ifm_active |= IFM_10_T;
1702 ifmr->ifm_active |= IFM_NONE;
1704 ifmr->ifm_active = ifm->ifm_cur->ifm_media;
1708 ifmr->ifm_active |= IFM_NONE;
1709 ifmr->ifm_status &= ~IFM_AVALID;
1714 txp_show_descriptor(d)
1717 struct txp_cmd_desc *cmd = d;
1718 struct txp_rsp_desc *rsp = d;
1719 struct txp_tx_desc *txd = d;
1720 struct txp_frag_desc *frgd = d;
1722 switch (cmd->cmd_flags & CMD_FLAGS_TYPE_M) {
1723 case CMD_FLAGS_TYPE_CMD:
1724 /* command descriptor */
1725 printf("[cmd flags 0x%x num %d id %d seq %d par1 0x%x par2 0x%x par3 0x%x]\n",
1726 cmd->cmd_flags, cmd->cmd_numdesc, cmd->cmd_id, cmd->cmd_seq,
1727 cmd->cmd_par1, cmd->cmd_par2, cmd->cmd_par3);
1729 case CMD_FLAGS_TYPE_RESP:
1730 /* response descriptor */
1731 printf("[rsp flags 0x%x num %d id %d seq %d par1 0x%x par2 0x%x par3 0x%x]\n",
1732 rsp->rsp_flags, rsp->rsp_numdesc, rsp->rsp_id, rsp->rsp_seq,
1733 rsp->rsp_par1, rsp->rsp_par2, rsp->rsp_par3);
1735 case CMD_FLAGS_TYPE_DATA:
1736 /* data header (assuming tx for now) */
1737 printf("[data flags 0x%x num %d totlen %d addr 0x%x/0x%x pflags 0x%x]",
1738 txd->tx_flags, txd->tx_numdesc, txd->tx_totlen,
1739 txd->tx_addrlo, txd->tx_addrhi, txd->tx_pflags);
1741 case CMD_FLAGS_TYPE_FRAG:
1742 /* fragment descriptor */
1743 printf("[frag flags 0x%x rsvd1 0x%x len %d addr 0x%x/0x%x rsvd2 0x%x]",
1744 frgd->frag_flags, frgd->frag_rsvd1, frgd->frag_len,
1745 frgd->frag_addrlo, frgd->frag_addrhi, frgd->frag_rsvd2);
1748 printf("[unknown(%x) flags 0x%x num %d id %d seq %d par1 0x%x par2 0x%x par3 0x%x]\n",
1749 cmd->cmd_flags & CMD_FLAGS_TYPE_M,
1750 cmd->cmd_flags, cmd->cmd_numdesc, cmd->cmd_id, cmd->cmd_seq,
1751 cmd->cmd_par1, cmd->cmd_par2, cmd->cmd_par3);
1759 struct txp_softc *sc;
1761 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
1762 u_int32_t crc, carry, hashbit, hash[2];
1766 struct ifmultiaddr *ifma;
1769 if (ifp->if_flags & IFF_PROMISC) {
1770 filter = TXP_RXFILT_PROMISC;
1774 filter = TXP_RXFILT_DIRECT;
1776 if (ifp->if_flags & IFF_BROADCAST)
1777 filter |= TXP_RXFILT_BROADCAST;
1779 if (ifp->if_flags & IFF_ALLMULTI)
1780 filter |= TXP_RXFILT_ALLMULTI;
1782 hash[0] = hash[1] = 0;
1784 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
1785 ifma = ifma->ifma_link.le_next) {
1786 if (ifma->ifma_addr->sa_family != AF_LINK)
1789 enm = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
1793 for (i = 0; i < ETHER_ADDR_LEN; i++) {
1795 for (j = 0; j < 8; j++) {
1796 carry = ((crc & 0x80000000) ? 1 : 0) ^
1801 crc = (crc ^ TXP_POLYNOMIAL) |
1805 hashbit = (u_int16_t)(crc & (64 - 1));
1806 hash[hashbit / 32] |= (1 << hashbit % 32);
1810 filter |= TXP_RXFILT_HASHMULTI;
1811 txp_command(sc, TXP_CMD_MCAST_HASH_MASK_WRITE,
1812 2, hash[0], hash[1], NULL, NULL, NULL, 0);
1818 txp_command(sc, TXP_CMD_RX_FILTER_WRITE, filter, 0, 0,
1819 NULL, NULL, NULL, 1);
1825 txp_capabilities(sc)
1826 struct txp_softc *sc;
1828 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
1829 struct txp_rsp_desc *rsp = NULL;
1830 struct txp_ext_desc *ext;
1832 if (txp_command2(sc, TXP_CMD_OFFLOAD_READ, 0, 0, 0, NULL, 0, &rsp, 1))
1835 if (rsp->rsp_numdesc != 1)
1837 ext = (struct txp_ext_desc *)(rsp + 1);
1839 sc->sc_tx_capability = ext->ext_1 & OFFLOAD_MASK;
1840 sc->sc_rx_capability = ext->ext_2 & OFFLOAD_MASK;
1841 ifp->if_capabilities = 0;
1843 if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_VLAN) {
1844 sc->sc_tx_capability |= OFFLOAD_VLAN;
1845 sc->sc_rx_capability |= OFFLOAD_VLAN;
1850 if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPSEC) {
1851 sc->sc_tx_capability |= OFFLOAD_IPSEC;
1852 sc->sc_rx_capability |= OFFLOAD_IPSEC;
1853 ifp->if_capabilities |= IFCAP_IPSEC;
1857 if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPCKSUM) {
1858 sc->sc_tx_capability |= OFFLOAD_IPCKSUM;
1859 sc->sc_rx_capability |= OFFLOAD_IPCKSUM;
1860 ifp->if_capabilities |= IFCAP_HWCSUM;
1861 ifp->if_hwassist |= CSUM_IP;
1864 if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_TCPCKSUM) {
1866 sc->sc_tx_capability |= OFFLOAD_TCPCKSUM;
1868 sc->sc_rx_capability |= OFFLOAD_TCPCKSUM;
1869 ifp->if_capabilities |= IFCAP_HWCSUM;
1872 if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_UDPCKSUM) {
1874 sc->sc_tx_capability |= OFFLOAD_UDPCKSUM;
1876 sc->sc_rx_capability |= OFFLOAD_UDPCKSUM;
1877 ifp->if_capabilities |= IFCAP_HWCSUM;
1879 ifp->if_capenable = ifp->if_capabilities;
1881 if (txp_command(sc, TXP_CMD_OFFLOAD_WRITE, 0,
1882 sc->sc_tx_capability, sc->sc_rx_capability, NULL, NULL, NULL, 1))
1887 free(rsp, M_DEVBUF);