Home | History | Annotate | Line # | Download | only in pci
if_txp.c revision 1.76
      1  1.76  riastrad /* $NetBSD: if_txp.c,v 1.76 2024/06/29 12:11:12 riastradh Exp $ */
      2   1.1  drochner 
      3   1.1  drochner /*
      4   1.1  drochner  * Copyright (c) 2001
      5   1.1  drochner  *	Jason L. Wright <jason (at) thought.net>, Theo de Raadt, and
      6   1.1  drochner  *	Aaron Campbell <aaron (at) monkey.org>.  All rights reserved.
      7   1.1  drochner  *
      8   1.1  drochner  * Redistribution and use in source and binary forms, with or without
      9   1.1  drochner  * modification, are permitted provided that the following conditions
     10   1.1  drochner  * are met:
     11   1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     12   1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     13   1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     15   1.1  drochner  *    documentation and/or other materials provided with the distribution.
     16   1.1  drochner  *
     17   1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     18   1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19   1.1  drochner  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20   1.1  drochner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR THE VOICES IN THEIR HEADS
     21   1.1  drochner  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22   1.1  drochner  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23   1.1  drochner  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24   1.1  drochner  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25   1.1  drochner  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26   1.1  drochner  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     27   1.1  drochner  * THE POSSIBILITY OF SUCH DAMAGE.
     28   1.1  drochner  */
     29   1.1  drochner 
     30   1.1  drochner /*
     31   1.1  drochner  * Driver for 3c990 (Typhoon) Ethernet ASIC
     32   1.1  drochner  */
     33   1.3     lukem 
     34   1.3     lukem #include <sys/cdefs.h>
     35  1.76  riastrad __KERNEL_RCSID(0, "$NetBSD: if_txp.c,v 1.76 2024/06/29 12:11:12 riastradh Exp $");
     36   1.1  drochner 
     37   1.1  drochner #include "opt_inet.h"
     38   1.1  drochner 
     39   1.1  drochner #include <sys/param.h>
     40   1.1  drochner #include <sys/systm.h>
     41   1.1  drochner #include <sys/sockio.h>
     42   1.1  drochner #include <sys/mbuf.h>
     43   1.1  drochner #include <sys/kernel.h>
     44   1.1  drochner #include <sys/socket.h>
     45   1.1  drochner #include <sys/device.h>
     46   1.1  drochner #include <sys/callout.h>
     47  1.53   msaitoh #include <sys/bus.h>
     48   1.1  drochner 
     49   1.1  drochner #include <net/if.h>
     50   1.1  drochner #include <net/if_dl.h>
     51   1.1  drochner #include <net/if_types.h>
     52   1.1  drochner #include <net/if_ether.h>
     53   1.1  drochner #include <net/if_arp.h>
     54  1.53   msaitoh #include <net/if_media.h>
     55  1.53   msaitoh #include <net/bpf.h>
     56   1.1  drochner 
     57   1.1  drochner #ifdef INET
     58   1.1  drochner #include <netinet/in.h>
     59   1.1  drochner #include <netinet/in_systm.h>
     60   1.1  drochner #include <netinet/in_var.h>
     61   1.1  drochner #include <netinet/ip.h>
     62   1.1  drochner #include <netinet/if_inarp.h>
     63   1.1  drochner #endif
     64   1.1  drochner 
     65   1.1  drochner #include <dev/mii/mii.h>
     66   1.1  drochner #include <dev/mii/miivar.h>
     67   1.1  drochner #include <dev/pci/pcireg.h>
     68   1.1  drochner #include <dev/pci/pcivar.h>
     69   1.1  drochner #include <dev/pci/pcidevs.h>
     70   1.1  drochner 
     71   1.1  drochner #include <dev/pci/if_txpreg.h>
     72   1.1  drochner 
     73   1.1  drochner #include <dev/microcode/typhoon/3c990img.h>
     74   1.1  drochner 
     75   1.1  drochner /*
     76   1.1  drochner  * These currently break the 3c990 firmware, hopefully will be resolved
     77   1.1  drochner  * at some point.
     78   1.1  drochner  */
     79   1.1  drochner #undef	TRY_TX_UDP_CSUM
     80   1.1  drochner #undef	TRY_TX_TCP_CSUM
     81   1.1  drochner 
     82  1.62      maxv static int txp_probe(device_t, cfdata_t, void *);
     83  1.62      maxv static void txp_attach(device_t, device_t, void *);
     84  1.62      maxv static int txp_intr(void *);
     85  1.62      maxv static void txp_tick(void *);
     86  1.62      maxv static bool txp_shutdown(device_t, int);
     87  1.62      maxv static int txp_ioctl(struct ifnet *, u_long, void *);
     88  1.62      maxv static void txp_start(struct ifnet *);
     89  1.62      maxv static void txp_stop(struct txp_softc *);
     90  1.62      maxv static void txp_init(struct txp_softc *);
     91  1.62      maxv static void txp_watchdog(struct ifnet *);
     92  1.62      maxv 
     93  1.62      maxv static int txp_chip_init(struct txp_softc *);
     94  1.62      maxv static int txp_reset_adapter(struct txp_softc *);
     95  1.62      maxv static int txp_download_fw(struct txp_softc *);
     96  1.62      maxv static int txp_download_fw_wait(struct txp_softc *);
     97  1.62      maxv static int txp_download_fw_section(struct txp_softc *,
     98  1.12       chs     const struct txp_fw_section_header *, int);
     99  1.62      maxv static int txp_alloc_rings(struct txp_softc *);
    100  1.62      maxv static void txp_dma_free(struct txp_softc *, struct txp_dma_alloc *);
    101  1.62      maxv static int txp_dma_malloc(struct txp_softc *, bus_size_t, struct txp_dma_alloc *, int);
    102  1.62      maxv static void txp_set_filter(struct txp_softc *);
    103   1.1  drochner 
    104  1.62      maxv static int txp_cmd_desc_numfree(struct txp_softc *);
    105  1.62      maxv static int txp_command(struct txp_softc *, uint16_t, uint16_t, uint32_t,
    106  1.53   msaitoh     uint32_t, uint16_t *, uint32_t *, uint32_t *, int);
    107  1.62      maxv static int txp_command2(struct txp_softc *, uint16_t, uint16_t,
    108  1.53   msaitoh     uint32_t, uint32_t, struct txp_ext_desc *, uint8_t,
    109   1.1  drochner     struct txp_rsp_desc **, int);
    110  1.62      maxv static int txp_response(struct txp_softc *, uint32_t, uint16_t, uint16_t,
    111   1.1  drochner     struct txp_rsp_desc **);
    112  1.62      maxv static void txp_rsp_fixup(struct txp_softc *, struct txp_rsp_desc *,
    113   1.1  drochner     struct txp_rsp_desc *);
    114  1.62      maxv static void txp_capabilities(struct txp_softc *);
    115   1.1  drochner 
    116  1.62      maxv static void txp_ifmedia_sts(struct ifnet *, struct ifmediareq *);
    117  1.62      maxv static int txp_ifmedia_upd(struct ifnet *);
    118  1.62      maxv static void txp_tx_reclaim(struct txp_softc *, struct txp_tx_ring *,
    119   1.1  drochner     struct txp_dma_alloc *);
    120  1.62      maxv static void txp_rxbuf_reclaim(struct txp_softc *);
    121  1.62      maxv static void txp_rx_reclaim(struct txp_softc *, struct txp_rx_ring *,
    122   1.1  drochner     struct txp_dma_alloc *);
    123   1.1  drochner 
    124  1.69   thorpej static void txp_rxd_free(struct txp_softc *, struct txp_swdesc *);
    125  1.69   thorpej static struct txp_swdesc *txp_rxd_alloc(struct txp_softc *);
    126  1.69   thorpej 
    127  1.39       chs CFATTACH_DECL_NEW(txp, sizeof(struct txp_softc), txp_probe, txp_attach,
    128   1.2  drochner 	      NULL, NULL);
    129   1.2  drochner 
    130  1.62      maxv static const struct txp_pci_match {
    131   1.2  drochner 	int vid, did, flags;
    132   1.2  drochner } txp_devices[] = {
    133   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990, 0 },
    134   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990TX95, 0 },
    135   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990TX97, 0 },
    136   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990SVR95, TXP_SERVERVERSION },
    137   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990SVR97, TXP_SERVERVERSION },
    138   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C990B, TXP_USESUBSYSTEM },
    139   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C990BSVR, TXP_SERVERVERSION },
    140   1.2  drochner 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990FX, TXP_USESUBSYSTEM },
    141   1.1  drochner };
    142   1.1  drochner 
    143   1.2  drochner static const struct txp_pci_match *txp_pcilookup(pcireg_t);
    144   1.2  drochner 
    145   1.2  drochner static const struct {
    146  1.53   msaitoh 	uint16_t mask, value;
    147   1.2  drochner 	int flags;
    148   1.2  drochner } txp_subsysinfo[] = {
    149   1.2  drochner 	{0xf000, 0x2000, TXP_SERVERVERSION},
    150   1.2  drochner 	{0x0100, 0x0100, TXP_FIBER},
    151   1.2  drochner #if 0 /* information from 3com header, unused */
    152   1.2  drochner 	{0x0010, 0x0010, /* secured firmware */},
    153   1.2  drochner 	{0x0003, 0x0000, /* variable DES */},
    154   1.2  drochner 	{0x0003, 0x0001, /* single DES - "95" */},
    155   1.2  drochner 	{0x0003, 0x0002, /* triple DES - "97" */},
    156   1.2  drochner #endif
    157   1.1  drochner };
    158   1.1  drochner 
    159   1.2  drochner static const struct txp_pci_match *
    160  1.25    dyoung txp_pcilookup(pcireg_t id)
    161   1.2  drochner {
    162   1.2  drochner 	int i;
    163   1.2  drochner 
    164  1.25    dyoung 	for (i = 0; i < __arraycount(txp_devices); i++)
    165  1.25    dyoung 		if (PCI_VENDOR(id) == txp_devices[i].vid &&
    166  1.25    dyoung 		    PCI_PRODUCT(id) == txp_devices[i].did)
    167  1.25    dyoung 			return &txp_devices[i];
    168   1.2  drochner 	return (0);
    169   1.2  drochner }
    170   1.2  drochner 
    171  1.62      maxv static int
    172  1.25    dyoung txp_probe(device_t parent, cfdata_t match, void *aux)
    173   1.1  drochner {
    174   1.1  drochner 	struct pci_attach_args *pa = aux;
    175   1.1  drochner 
    176   1.2  drochner 	if (txp_pcilookup(pa->pa_id))
    177   1.1  drochner 			return (1);
    178   1.1  drochner 	return (0);
    179   1.1  drochner }
    180   1.1  drochner 
    181  1.62      maxv static void
    182  1.25    dyoung txp_attach(device_t parent, device_t self, void *aux)
    183   1.1  drochner {
    184  1.25    dyoung 	struct txp_softc *sc = device_private(self);
    185   1.1  drochner 	struct pci_attach_args *pa = aux;
    186   1.1  drochner 	pci_chipset_tag_t pc = pa->pa_pc;
    187   1.1  drochner 	pci_intr_handle_t ih;
    188   1.1  drochner 	const char *intrstr = NULL;
    189   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
    190  1.53   msaitoh 	uint32_t command;
    191  1.53   msaitoh 	uint16_t p1;
    192  1.53   msaitoh 	uint32_t p2;
    193   1.1  drochner 	u_char enaddr[6];
    194  1.24    dyoung 	const struct txp_pci_match *match;
    195  1.53   msaitoh 	uint16_t subsys;
    196   1.2  drochner 	int i, flags;
    197   1.2  drochner 	char devinfo[256];
    198  1.40  christos 	char intrbuf[PCI_INTRSTR_LEN];
    199   1.1  drochner 
    200  1.39       chs 	sc->sc_dev = self;
    201   1.1  drochner 	sc->sc_cold = 1;
    202   1.1  drochner 
    203  1.24    dyoung 	match = txp_pcilookup(pa->pa_id);
    204  1.24    dyoung 	flags = match->flags;
    205  1.24    dyoung 	if (match->flags & TXP_USESUBSYSTEM) {
    206   1.2  drochner 		subsys = PCI_PRODUCT(pci_conf_read(pc, pa->pa_tag,
    207   1.2  drochner 						   PCI_SUBSYS_ID_REG));
    208   1.2  drochner 		for (i = 0;
    209   1.2  drochner 		     i < sizeof(txp_subsysinfo)/sizeof(txp_subsysinfo[0]);
    210   1.2  drochner 		     i++)
    211   1.2  drochner 			if ((subsys & txp_subsysinfo[i].mask) ==
    212   1.2  drochner 			    txp_subsysinfo[i].value)
    213   1.2  drochner 				flags |= txp_subsysinfo[i].flags;
    214   1.2  drochner 	}
    215   1.2  drochner 	sc->sc_flags = flags;
    216   1.2  drochner 
    217  1.44   msaitoh 	aprint_naive("\n");
    218   1.6    itojun 	pci_devinfo(pa->pa_id, 0, 0, devinfo, sizeof(devinfo));
    219  1.53   msaitoh #define TXP_EXTRAINFO ((flags & (TXP_USESUBSYSTEM | TXP_SERVERVERSION)) == \
    220  1.53   msaitoh   (TXP_USESUBSYSTEM | TXP_SERVERVERSION) ? " (SVR)" : "")
    221  1.44   msaitoh 	aprint_normal(": %s%s\n%s", devinfo, TXP_EXTRAINFO,
    222  1.44   msaitoh 	    device_xname(sc->sc_dev));
    223   1.2  drochner 
    224   1.1  drochner 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    225   1.1  drochner 
    226   1.1  drochner 	if (!(command & PCI_COMMAND_MASTER_ENABLE)) {
    227  1.44   msaitoh 		aprint_error(": failed to enable bus mastering\n");
    228   1.1  drochner 		return;
    229   1.1  drochner 	}
    230   1.1  drochner 
    231   1.1  drochner 	if (!(command & PCI_COMMAND_MEM_ENABLE)) {
    232  1.44   msaitoh 		aprint_error(": failed to enable memory mapping\n");
    233   1.1  drochner 		return;
    234   1.1  drochner 	}
    235   1.1  drochner 	if (pci_mapreg_map(pa, TXP_PCI_LOMEM, PCI_MAPREG_TYPE_MEM, 0,
    236   1.1  drochner 	    &sc->sc_bt, &sc->sc_bh, NULL, NULL)) {
    237  1.44   msaitoh 		aprint_error(": can't map mem space %d\n", 0);
    238   1.1  drochner 		return;
    239   1.1  drochner 	}
    240   1.1  drochner 
    241  1.64   thorpej 	if (pci_dma64_available(pa))
    242  1.64   thorpej 		sc->sc_dmat = pa->pa_dmat64;
    243  1.64   thorpej 	else
    244  1.64   thorpej 		sc->sc_dmat = pa->pa_dmat;
    245   1.1  drochner 
    246   1.1  drochner 	/*
    247   1.1  drochner 	 * Allocate our interrupt.
    248   1.1  drochner 	 */
    249   1.1  drochner 	if (pci_intr_map(pa, &ih)) {
    250  1.44   msaitoh 		aprint_error(": couldn't map interrupt\n");
    251   1.1  drochner 		return;
    252   1.1  drochner 	}
    253   1.1  drochner 
    254  1.40  christos 	intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf));
    255  1.51  jdolecek 	sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_NET, txp_intr, sc,
    256  1.51  jdolecek 	    device_xname(self));
    257   1.1  drochner 	if (sc->sc_ih == NULL) {
    258  1.44   msaitoh 		aprint_error(": couldn't establish interrupt");
    259   1.1  drochner 		if (intrstr != NULL)
    260  1.45   msaitoh 			aprint_normal(" at %s", intrstr);
    261  1.45   msaitoh 		aprint_normal("\n");
    262   1.1  drochner 		return;
    263   1.1  drochner 	}
    264  1.54   msaitoh 	aprint_normal(": interrupting at %s\n", intrstr);
    265   1.1  drochner 
    266   1.1  drochner 	if (txp_chip_init(sc))
    267   1.7        is 		goto cleanupintr;
    268   1.1  drochner 
    269   1.1  drochner 	if (txp_download_fw(sc))
    270   1.7        is 		goto cleanupintr;
    271   1.1  drochner 
    272   1.1  drochner 	if (txp_alloc_rings(sc))
    273   1.7        is 		goto cleanupintr;
    274   1.1  drochner 
    275   1.1  drochner 	if (txp_command(sc, TXP_CMD_MAX_PKT_SIZE_WRITE, TXP_MAX_PKTLEN, 0, 0,
    276   1.1  drochner 	    NULL, NULL, NULL, 1))
    277   1.7        is 		goto cleanupintr;
    278   1.1  drochner 
    279   1.1  drochner 	if (txp_command(sc, TXP_CMD_STATION_ADDRESS_READ, 0, 0, 0,
    280   1.1  drochner 	    &p1, &p2, NULL, 1))
    281   1.7        is 		goto cleanupintr;
    282   1.1  drochner 
    283   1.1  drochner 	p1 = htole16(p1);
    284  1.53   msaitoh 	enaddr[0] = ((uint8_t *)&p1)[1];
    285  1.53   msaitoh 	enaddr[1] = ((uint8_t *)&p1)[0];
    286   1.1  drochner 	p2 = htole32(p2);
    287  1.53   msaitoh 	enaddr[2] = ((uint8_t *)&p2)[3];
    288  1.53   msaitoh 	enaddr[3] = ((uint8_t *)&p2)[2];
    289  1.53   msaitoh 	enaddr[4] = ((uint8_t *)&p2)[1];
    290  1.53   msaitoh 	enaddr[5] = ((uint8_t *)&p2)[0];
    291   1.1  drochner 
    292  1.44   msaitoh 	aprint_normal_dev(self, "Ethernet address %s\n",
    293  1.44   msaitoh 	    ether_sprintf(enaddr));
    294   1.1  drochner 	sc->sc_cold = 0;
    295   1.1  drochner 
    296  1.57   msaitoh 	/* Initialize ifmedia structures. */
    297  1.57   msaitoh 	sc->sc_arpcom.ec_ifmedia = &sc->sc_ifmedia;
    298   1.1  drochner 	ifmedia_init(&sc->sc_ifmedia, 0, txp_ifmedia_upd, txp_ifmedia_sts);
    299   1.2  drochner 	if (flags & TXP_FIBER) {
    300  1.53   msaitoh 		ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_FX,
    301   1.2  drochner 			    0, NULL);
    302  1.53   msaitoh 		ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_FX | IFM_FDX,
    303   1.2  drochner 			    0, NULL);
    304   1.2  drochner 	} else {
    305  1.53   msaitoh 		ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T,
    306   1.2  drochner 			    0, NULL);
    307  1.53   msaitoh 		ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T | IFM_FDX,
    308   1.2  drochner 			    0, NULL);
    309  1.53   msaitoh 		ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_TX,
    310   1.2  drochner 			    0, NULL);
    311  1.53   msaitoh 		ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_TX | IFM_FDX,
    312   1.2  drochner 			    0, NULL);
    313   1.2  drochner 	}
    314  1.55   msaitoh 	ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL);
    315   1.1  drochner 
    316   1.1  drochner 	sc->sc_xcvr = TXP_XCVR_AUTO;
    317   1.1  drochner 	txp_command(sc, TXP_CMD_XCVR_SELECT, TXP_XCVR_AUTO, 0, 0,
    318   1.1  drochner 	    NULL, NULL, NULL, 0);
    319  1.53   msaitoh 	ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO);
    320   1.1  drochner 
    321   1.1  drochner 	ifp->if_softc = sc;
    322   1.1  drochner 	ifp->if_mtu = ETHERMTU;
    323   1.1  drochner 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    324   1.1  drochner 	ifp->if_ioctl = txp_ioctl;
    325   1.1  drochner 	ifp->if_start = txp_start;
    326   1.1  drochner 	ifp->if_watchdog = txp_watchdog;
    327   1.1  drochner 	ifp->if_baudrate = 10000000;
    328   1.1  drochner 	IFQ_SET_MAXLEN(&ifp->if_snd, TX_ENTRIES);
    329   1.1  drochner 	IFQ_SET_READY(&ifp->if_snd);
    330   1.1  drochner 	ifp->if_capabilities = 0;
    331  1.39       chs 	strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
    332   1.1  drochner 
    333   1.1  drochner 	txp_capabilities(sc);
    334   1.1  drochner 
    335  1.20        ad 	callout_init(&sc->sc_tick, 0);
    336   1.1  drochner 	callout_setfunc(&sc->sc_tick, txp_tick, sc);
    337   1.1  drochner 
    338   1.1  drochner 	/*
    339   1.1  drochner 	 * Attach us everywhere
    340   1.1  drochner 	 */
    341   1.1  drochner 	if_attach(ifp);
    342  1.46     ozaki 	if_deferred_start_init(ifp, NULL);
    343   1.1  drochner 	ether_ifattach(ifp, enaddr);
    344   1.1  drochner 
    345  1.72   thorpej 	/*
    346  1.72   thorpej 	 * XXX Because we allocate Rx buffers in txp_alloc_rings(),
    347  1.72   thorpej 	 * XXX we have to go back and claim them now that our mowners
    348  1.72   thorpej 	 * XXX have been initialized (in ether_ifattach()).
    349  1.72   thorpej 	 *
    350  1.72   thorpej 	 * XXX FIXME by allocating Rx buffers only when interface is
    351  1.72   thorpej 	 * XXX running, like other drivers do.
    352  1.72   thorpej 	 */
    353  1.72   thorpej 	for (i = 0; i < RXBUF_ENTRIES; i++) {
    354  1.72   thorpej 		KASSERT(sc->sc_rxd[i].sd_mbuf != NULL);
    355  1.72   thorpej 		MCLAIM(sc->sc_rxd[i].sd_mbuf, &sc->sc_arpcom.ec_rx_mowner);
    356  1.72   thorpej 	}
    357  1.72   thorpej 
    358  1.35   tsutsui 	if (pmf_device_register1(self, NULL, NULL, txp_shutdown))
    359  1.35   tsutsui 		pmf_class_network_register(self, ifp);
    360  1.35   tsutsui 	else
    361  1.35   tsutsui 		aprint_error_dev(self, "couldn't establish power handler\n");
    362   1.7        is 
    363   1.7        is 	return;
    364   1.7        is 
    365   1.7        is cleanupintr:
    366  1.55   msaitoh 	pci_intr_disestablish(pc, sc->sc_ih);
    367   1.7        is 
    368   1.7        is 	return;
    369   1.7        is 
    370   1.1  drochner }
    371   1.1  drochner 
    372  1.62      maxv static int
    373  1.29       dsl txp_chip_init(struct txp_softc *sc)
    374   1.1  drochner {
    375   1.1  drochner 	/* disable interrupts */
    376   1.1  drochner 	WRITE_REG(sc, TXP_IER, 0);
    377   1.1  drochner 	WRITE_REG(sc, TXP_IMR,
    378   1.1  drochner 	    TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
    379   1.1  drochner 	    TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
    380   1.1  drochner 	    TXP_INT_LATCH);
    381   1.1  drochner 
    382   1.1  drochner 	/* ack all interrupts */
    383   1.1  drochner 	WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
    384   1.1  drochner 	    TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
    385   1.1  drochner 	    TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
    386   1.1  drochner 	    TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
    387   1.1  drochner 	    TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
    388   1.1  drochner 
    389   1.1  drochner 	if (txp_reset_adapter(sc))
    390   1.1  drochner 		return (-1);
    391   1.1  drochner 
    392   1.1  drochner 	/* disable interrupts */
    393   1.1  drochner 	WRITE_REG(sc, TXP_IER, 0);
    394   1.1  drochner 	WRITE_REG(sc, TXP_IMR,
    395   1.1  drochner 	    TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
    396   1.1  drochner 	    TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
    397   1.1  drochner 	    TXP_INT_LATCH);
    398   1.1  drochner 
    399   1.1  drochner 	/* ack all interrupts */
    400   1.1  drochner 	WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
    401   1.1  drochner 	    TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
    402   1.1  drochner 	    TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
    403   1.1  drochner 	    TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
    404   1.1  drochner 	    TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
    405   1.1  drochner 
    406   1.1  drochner 	return (0);
    407   1.1  drochner }
    408   1.1  drochner 
    409  1.62      maxv static int
    410  1.29       dsl txp_reset_adapter(struct txp_softc *sc)
    411   1.1  drochner {
    412  1.53   msaitoh 	uint32_t r;
    413   1.1  drochner 	int i;
    414   1.1  drochner 
    415   1.1  drochner 	WRITE_REG(sc, TXP_SRR, TXP_SRR_ALL);
    416   1.1  drochner 	DELAY(1000);
    417   1.1  drochner 	WRITE_REG(sc, TXP_SRR, 0);
    418   1.1  drochner 
    419   1.1  drochner 	/* Should wait max 6 seconds */
    420   1.1  drochner 	for (i = 0; i < 6000; i++) {
    421   1.1  drochner 		r = READ_REG(sc, TXP_A2H_0);
    422   1.1  drochner 		if (r == STAT_WAITING_FOR_HOST_REQUEST)
    423   1.1  drochner 			break;
    424   1.1  drochner 		DELAY(1000);
    425   1.1  drochner 	}
    426   1.1  drochner 
    427   1.1  drochner 	if (r != STAT_WAITING_FOR_HOST_REQUEST) {
    428   1.1  drochner 		printf("%s: reset hung\n", TXP_DEVNAME(sc));
    429   1.1  drochner 		return (-1);
    430   1.1  drochner 	}
    431   1.1  drochner 
    432   1.1  drochner 	return (0);
    433   1.1  drochner }
    434   1.1  drochner 
    435  1.62      maxv static int
    436  1.29       dsl txp_download_fw(struct txp_softc *sc)
    437   1.1  drochner {
    438  1.12       chs 	const struct txp_fw_file_header *fileheader;
    439  1.12       chs 	const struct txp_fw_section_header *secthead;
    440   1.1  drochner 	int sect;
    441  1.53   msaitoh 	uint32_t r, i, ier, imr;
    442   1.1  drochner 
    443   1.1  drochner 	ier = READ_REG(sc, TXP_IER);
    444   1.1  drochner 	WRITE_REG(sc, TXP_IER, ier | TXP_INT_A2H_0);
    445   1.1  drochner 
    446   1.1  drochner 	imr = READ_REG(sc, TXP_IMR);
    447   1.1  drochner 	WRITE_REG(sc, TXP_IMR, imr | TXP_INT_A2H_0);
    448   1.1  drochner 
    449   1.1  drochner 	for (i = 0; i < 10000; i++) {
    450   1.1  drochner 		r = READ_REG(sc, TXP_A2H_0);
    451   1.1  drochner 		if (r == STAT_WAITING_FOR_HOST_REQUEST)
    452   1.1  drochner 			break;
    453   1.1  drochner 		DELAY(50);
    454   1.1  drochner 	}
    455   1.1  drochner 	if (r != STAT_WAITING_FOR_HOST_REQUEST) {
    456   1.1  drochner 		printf(": not waiting for host request\n");
    457   1.1  drochner 		return (-1);
    458   1.1  drochner 	}
    459   1.1  drochner 
    460   1.1  drochner 	/* Ack the status */
    461   1.1  drochner 	WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
    462   1.1  drochner 
    463  1.12       chs 	fileheader = (const struct txp_fw_file_header *)tc990image;
    464  1.44   msaitoh 	if (memcmp("TYPHOON", fileheader->magicid,
    465  1.44   msaitoh 	    sizeof(fileheader->magicid))) {
    466   1.1  drochner 		printf(": fw invalid magic\n");
    467   1.1  drochner 		return (-1);
    468   1.1  drochner 	}
    469   1.1  drochner 
    470   1.1  drochner 	/* Tell boot firmware to get ready for image */
    471   1.1  drochner 	WRITE_REG(sc, TXP_H2A_1, le32toh(fileheader->addr));
    472  1.67   thorpej 	WRITE_REG(sc, TXP_H2A_2, le32toh(fileheader->hmac[0]));
    473  1.67   thorpej 	WRITE_REG(sc, TXP_H2A_3, le32toh(fileheader->hmac[1]));
    474  1.67   thorpej 	WRITE_REG(sc, TXP_H2A_4, le32toh(fileheader->hmac[2]));
    475  1.67   thorpej 	WRITE_REG(sc, TXP_H2A_5, le32toh(fileheader->hmac[3]));
    476  1.67   thorpej 	WRITE_REG(sc, TXP_H2A_6, le32toh(fileheader->hmac[4]));
    477   1.1  drochner 	WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_RUNTIME_IMAGE);
    478   1.1  drochner 
    479   1.1  drochner 	if (txp_download_fw_wait(sc)) {
    480  1.44   msaitoh 		printf("%s: fw wait failed, initial\n",
    481  1.44   msaitoh 		    device_xname(sc->sc_dev));
    482   1.1  drochner 		return (-1);
    483   1.1  drochner 	}
    484   1.1  drochner 
    485  1.12       chs 	secthead = (const struct txp_fw_section_header *)
    486  1.53   msaitoh 		(((const uint8_t *)tc990image) +
    487  1.12       chs 		 sizeof(struct txp_fw_file_header));
    488   1.1  drochner 
    489   1.1  drochner 	for (sect = 0; sect < le32toh(fileheader->nsections); sect++) {
    490   1.1  drochner 		if (txp_download_fw_section(sc, secthead, sect))
    491   1.1  drochner 			return (-1);
    492  1.12       chs 		secthead = (const struct txp_fw_section_header *)
    493  1.53   msaitoh 		    (((const uint8_t *)secthead) + le32toh(secthead->nbytes) +
    494   1.1  drochner 			sizeof(*secthead));
    495   1.1  drochner 	}
    496   1.1  drochner 
    497   1.1  drochner 	WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_DOWNLOAD_COMPLETE);
    498   1.1  drochner 
    499   1.1  drochner 	for (i = 0; i < 10000; i++) {
    500   1.1  drochner 		r = READ_REG(sc, TXP_A2H_0);
    501   1.1  drochner 		if (r == STAT_WAITING_FOR_BOOT)
    502   1.1  drochner 			break;
    503   1.1  drochner 		DELAY(50);
    504   1.1  drochner 	}
    505   1.1  drochner 	if (r != STAT_WAITING_FOR_BOOT) {
    506   1.1  drochner 		printf(": not waiting for boot\n");
    507   1.1  drochner 		return (-1);
    508   1.1  drochner 	}
    509   1.1  drochner 
    510   1.1  drochner 	WRITE_REG(sc, TXP_IER, ier);
    511   1.1  drochner 	WRITE_REG(sc, TXP_IMR, imr);
    512   1.1  drochner 
    513   1.1  drochner 	return (0);
    514   1.1  drochner }
    515   1.1  drochner 
    516  1.62      maxv static int
    517  1.29       dsl txp_download_fw_wait(struct txp_softc *sc)
    518   1.1  drochner {
    519  1.53   msaitoh 	uint32_t i, r;
    520   1.1  drochner 
    521   1.1  drochner 	for (i = 0; i < 10000; i++) {
    522   1.1  drochner 		r = READ_REG(sc, TXP_ISR);
    523   1.1  drochner 		if (r & TXP_INT_A2H_0)
    524   1.1  drochner 			break;
    525   1.1  drochner 		DELAY(50);
    526   1.1  drochner 	}
    527   1.1  drochner 
    528   1.1  drochner 	if (!(r & TXP_INT_A2H_0)) {
    529   1.1  drochner 		printf(": fw wait failed comm0\n");
    530   1.1  drochner 		return (-1);
    531   1.1  drochner 	}
    532   1.1  drochner 
    533   1.1  drochner 	WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
    534   1.1  drochner 
    535   1.1  drochner 	r = READ_REG(sc, TXP_A2H_0);
    536   1.1  drochner 	if (r != STAT_WAITING_FOR_SEGMENT) {
    537   1.1  drochner 		printf(": fw not waiting for segment\n");
    538   1.1  drochner 		return (-1);
    539   1.1  drochner 	}
    540   1.1  drochner 	return (0);
    541   1.1  drochner }
    542   1.1  drochner 
    543  1.62      maxv static int
    544  1.44   msaitoh txp_download_fw_section(struct txp_softc *sc,
    545  1.44   msaitoh     const struct txp_fw_section_header *sect, int sectnum)
    546   1.1  drochner {
    547   1.1  drochner 	struct txp_dma_alloc dma;
    548   1.1  drochner 	int rseg, err = 0;
    549   1.1  drochner 	struct mbuf m;
    550  1.14  christos #ifdef INET
    551  1.53   msaitoh 	uint16_t csum;
    552  1.14  christos #endif
    553   1.1  drochner 
    554   1.1  drochner 	/* Skip zero length sections */
    555   1.1  drochner 	if (sect->nbytes == 0)
    556   1.1  drochner 		return (0);
    557   1.1  drochner 
    558   1.1  drochner 	/* Make sure we aren't past the end of the image */
    559  1.53   msaitoh 	rseg = ((const uint8_t *)sect) - ((const uint8_t *)tc990image);
    560   1.1  drochner 	if (rseg >= sizeof(tc990image)) {
    561   1.1  drochner 		printf(": fw invalid section address, section %d\n", sectnum);
    562   1.1  drochner 		return (-1);
    563   1.1  drochner 	}
    564   1.1  drochner 
    565   1.1  drochner 	/* Make sure this section doesn't go past the end */
    566   1.1  drochner 	rseg += le32toh(sect->nbytes);
    567   1.1  drochner 	if (rseg >= sizeof(tc990image)) {
    568   1.1  drochner 		printf(": fw truncated section %d\n", sectnum);
    569   1.1  drochner 		return (-1);
    570   1.1  drochner 	}
    571   1.1  drochner 
    572   1.1  drochner 	/* map a buffer, copy segment to it, get physaddr */
    573   1.1  drochner 	if (txp_dma_malloc(sc, le32toh(sect->nbytes), &dma, 0)) {
    574   1.1  drochner 		printf(": fw dma malloc failed, section %d\n", sectnum);
    575   1.1  drochner 		return (-1);
    576   1.1  drochner 	}
    577   1.1  drochner 
    578  1.53   msaitoh 	memcpy(dma.dma_vaddr, ((const uint8_t *)sect) + sizeof(*sect),
    579   1.1  drochner 	    le32toh(sect->nbytes));
    580   1.1  drochner 
    581   1.1  drochner 	/*
    582   1.1  drochner 	 * dummy up mbuf and verify section checksum
    583   1.1  drochner 	 */
    584   1.1  drochner 	m.m_type = MT_DATA;
    585   1.1  drochner 	m.m_next = m.m_nextpkt = NULL;
    586  1.50   msaitoh 	m.m_owner = NULL;
    587   1.1  drochner 	m.m_len = le32toh(sect->nbytes);
    588   1.1  drochner 	m.m_data = dma.dma_vaddr;
    589   1.1  drochner 	m.m_flags = 0;
    590  1.14  christos #ifdef INET
    591   1.1  drochner 	csum = in_cksum(&m, le32toh(sect->nbytes));
    592   1.1  drochner 	if (csum != sect->cksum) {
    593   1.1  drochner 		printf(": fw section %d, bad cksum (expected 0x%x got 0x%x)\n",
    594   1.1  drochner 		    sectnum, sect->cksum, csum);
    595  1.14  christos 		txp_dma_free(sc, &dma);
    596  1.14  christos 		return -1;
    597   1.1  drochner 	}
    598  1.14  christos #endif
    599   1.1  drochner 
    600   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, dma.dma_map, 0,
    601   1.1  drochner 	    dma.dma_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
    602   1.1  drochner 
    603   1.1  drochner 	WRITE_REG(sc, TXP_H2A_1, le32toh(sect->nbytes));
    604   1.1  drochner 	WRITE_REG(sc, TXP_H2A_2, le32toh(sect->cksum));
    605   1.1  drochner 	WRITE_REG(sc, TXP_H2A_3, le32toh(sect->addr));
    606  1.65   thorpej 	WRITE_REG(sc, TXP_H2A_4, BUS_ADDR_HI32(dma.dma_paddr));
    607  1.65   thorpej 	WRITE_REG(sc, TXP_H2A_5, BUS_ADDR_LO32(dma.dma_paddr));
    608   1.1  drochner 	WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_SEGMENT_AVAILABLE);
    609   1.1  drochner 
    610   1.1  drochner 	if (txp_download_fw_wait(sc)) {
    611   1.1  drochner 		printf("%s: fw wait failed, section %d\n",
    612  1.39       chs 		    device_xname(sc->sc_dev), sectnum);
    613   1.1  drochner 		err = -1;
    614   1.1  drochner 	}
    615   1.1  drochner 
    616   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, dma.dma_map, 0,
    617   1.1  drochner 	    dma.dma_map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
    618   1.1  drochner 
    619   1.1  drochner 	txp_dma_free(sc, &dma);
    620   1.1  drochner 	return (err);
    621   1.1  drochner }
    622   1.1  drochner 
    623  1.62      maxv static int
    624  1.29       dsl txp_intr(void *vsc)
    625   1.1  drochner {
    626   1.1  drochner 	struct txp_softc *sc = vsc;
    627   1.1  drochner 	struct txp_hostvar *hv = sc->sc_hostvar;
    628  1.53   msaitoh 	uint32_t isr;
    629   1.1  drochner 	int claimed = 0;
    630   1.1  drochner 
    631   1.1  drochner 	/* mask all interrupts */
    632   1.1  drochner 	WRITE_REG(sc, TXP_IMR, TXP_INT_RESERVED | TXP_INT_SELF |
    633   1.1  drochner 	    TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
    634   1.1  drochner 	    TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
    635   1.1  drochner 	    TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
    636   1.1  drochner 	    TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |  TXP_INT_LATCH);
    637   1.1  drochner 
    638   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
    639  1.53   msaitoh 	    sizeof(struct txp_hostvar),
    640  1.53   msaitoh 	    BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
    641   1.1  drochner 
    642   1.1  drochner 	isr = READ_REG(sc, TXP_ISR);
    643   1.1  drochner 	while (isr) {
    644   1.1  drochner 		claimed = 1;
    645   1.1  drochner 		WRITE_REG(sc, TXP_ISR, isr);
    646   1.1  drochner 
    647   1.1  drochner 		if ((*sc->sc_rxhir.r_roff) != (*sc->sc_rxhir.r_woff))
    648   1.1  drochner 			txp_rx_reclaim(sc, &sc->sc_rxhir, &sc->sc_rxhiring_dma);
    649   1.1  drochner 		if ((*sc->sc_rxlor.r_roff) != (*sc->sc_rxlor.r_woff))
    650   1.1  drochner 			txp_rx_reclaim(sc, &sc->sc_rxlor, &sc->sc_rxloring_dma);
    651   1.1  drochner 
    652   1.1  drochner 		if (hv->hv_rx_buf_write_idx == hv->hv_rx_buf_read_idx)
    653   1.1  drochner 			txp_rxbuf_reclaim(sc);
    654   1.1  drochner 
    655   1.1  drochner 		if (sc->sc_txhir.r_cnt && (sc->sc_txhir.r_cons !=
    656   1.1  drochner 		    TXP_OFFSET2IDX(le32toh(*(sc->sc_txhir.r_off)))))
    657   1.1  drochner 			txp_tx_reclaim(sc, &sc->sc_txhir, &sc->sc_txhiring_dma);
    658   1.1  drochner 
    659   1.1  drochner 		if (sc->sc_txlor.r_cnt && (sc->sc_txlor.r_cons !=
    660   1.1  drochner 		    TXP_OFFSET2IDX(le32toh(*(sc->sc_txlor.r_off)))))
    661   1.1  drochner 			txp_tx_reclaim(sc, &sc->sc_txlor, &sc->sc_txloring_dma);
    662   1.1  drochner 
    663   1.1  drochner 		isr = READ_REG(sc, TXP_ISR);
    664   1.1  drochner 	}
    665   1.1  drochner 
    666   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
    667  1.53   msaitoh 	    sizeof(struct txp_hostvar),
    668  1.53   msaitoh 	    BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
    669   1.1  drochner 
    670   1.1  drochner 	/* unmask all interrupts */
    671   1.1  drochner 	WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
    672   1.1  drochner 
    673  1.46     ozaki 	if_schedule_deferred_start(&sc->sc_arpcom.ec_if);
    674   1.1  drochner 
    675   1.1  drochner 	return (claimed);
    676   1.1  drochner }
    677   1.1  drochner 
    678  1.69   thorpej static struct txp_swdesc *
    679  1.69   thorpej txp_rxd_alloc(struct txp_softc *sc)
    680  1.69   thorpej {
    681  1.69   thorpej 	if (sc->sc_txd_pool_ptr == 0)
    682  1.69   thorpej 		return NULL;
    683  1.69   thorpej 	return sc->sc_rxd_pool[--sc->sc_txd_pool_ptr];
    684  1.69   thorpej }
    685  1.69   thorpej 
    686  1.69   thorpej static void
    687  1.69   thorpej txp_rxd_free(struct txp_softc *sc, struct txp_swdesc *sd)
    688  1.69   thorpej {
    689  1.69   thorpej 	KASSERT(sc->sc_txd_pool_ptr < RXBUF_ENTRIES);
    690  1.69   thorpej 	sc->sc_rxd_pool[sc->sc_txd_pool_ptr++] = sd;
    691  1.69   thorpej }
    692  1.69   thorpej 
    693  1.70   thorpej static inline uint32_t
    694  1.70   thorpej txp_rxd_idx(struct txp_softc *sc, struct txp_swdesc *sd)
    695  1.70   thorpej {
    696  1.70   thorpej 	KASSERT(sd >= &sc->sc_rxd[0] && sd < &sc->sc_rxd[RXBUF_ENTRIES]);
    697  1.70   thorpej 	return (uint32_t)(sd - &sc->sc_rxd[0]);
    698  1.70   thorpej }
    699  1.70   thorpej 
    700  1.72   thorpej static inline uint32_t
    701  1.72   thorpej txp_txd_idx(struct txp_softc *sc, struct txp_swdesc *sd)
    702  1.72   thorpej {
    703  1.72   thorpej 	KASSERT(sd >= &sc->sc_txd[0] && sd < &sc->sc_txd[TX_ENTRIES]);
    704  1.72   thorpej 	return (uint32_t)(sd - &sc->sc_txd[0]);
    705  1.72   thorpej }
    706  1.72   thorpej 
    707  1.62      maxv static void
    708  1.44   msaitoh txp_rx_reclaim(struct txp_softc *sc, struct txp_rx_ring *r,
    709  1.44   msaitoh     struct txp_dma_alloc *dma)
    710   1.1  drochner {
    711   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
    712   1.1  drochner 	struct txp_rx_desc *rxd;
    713   1.1  drochner 	struct mbuf *m;
    714   1.1  drochner 	struct txp_swdesc *sd;
    715  1.53   msaitoh 	uint32_t roff, woff;
    716  1.73   thorpej 	uint16_t len;
    717   1.1  drochner 	int sumflags = 0;
    718   1.1  drochner 	int idx;
    719   1.1  drochner 
    720   1.1  drochner 	roff = le32toh(*r->r_roff);
    721   1.1  drochner 	woff = le32toh(*r->r_woff);
    722   1.1  drochner 	idx = roff / sizeof(struct txp_rx_desc);
    723   1.1  drochner 	rxd = r->r_desc + idx;
    724   1.1  drochner 
    725   1.1  drochner 	while (roff != woff) {
    726   1.1  drochner 
    727   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
    728  1.44   msaitoh 		    idx * sizeof(struct txp_rx_desc),
    729  1.44   msaitoh 		    sizeof(struct txp_rx_desc), BUS_DMASYNC_POSTREAD);
    730   1.1  drochner 
    731   1.1  drochner 		if (rxd->rx_flags & RX_FLAGS_ERROR) {
    732  1.39       chs 			printf("%s: error 0x%x\n", device_xname(sc->sc_dev),
    733   1.1  drochner 			    le32toh(rxd->rx_stat));
    734  1.63   thorpej 			if_statinc(ifp, if_ierrors);
    735   1.1  drochner 			goto next;
    736   1.1  drochner 		}
    737   1.1  drochner 
    738   1.1  drochner 		/* retrieve stashed pointer */
    739  1.71   thorpej 		KASSERT(rxd->rx_vaddrlo < RXBUF_ENTRIES);
    740  1.70   thorpej 		sd = &sc->sc_rxd[rxd->rx_vaddrlo];
    741   1.1  drochner 
    742   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
    743   1.1  drochner 		    sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
    744  1.73   thorpej 
    745  1.73   thorpej 		len = le16toh(rxd->rx_len);
    746  1.73   thorpej 
    747  1.73   thorpej #ifdef __NO_STRICT_ALIGNMENT
    748   1.1  drochner 		bus_dmamap_unload(sc->sc_dmat, sd->sd_map);
    749   1.1  drochner 		m = sd->sd_mbuf;
    750  1.72   thorpej 		sd->sd_mbuf = NULL;
    751  1.69   thorpej 		txp_rxd_free(sc, sd);
    752  1.73   thorpej #else
    753  1.73   thorpej 		/*
    754  1.73   thorpej 		 * The Typhoon's receive buffers must be 4-byte aligned.
    755  1.73   thorpej 		 * But this means the data after the Ethernet header
    756  1.73   thorpej 		 * is misaligned.  We must allocate a new buffer and
    757  1.73   thorpej 		 * copy the data, shifted forward 2 bytes.
    758  1.73   thorpej 		 */
    759  1.73   thorpej 		MGETHDR(m, M_DONTWAIT, MT_DATA);
    760  1.73   thorpej 		if (m == NULL) {
    761  1.73   thorpej  dropit:
    762  1.73   thorpej 			if_statinc(ifp, if_ierrors);
    763  1.73   thorpej 			txp_rxd_free(sc, sd);
    764  1.73   thorpej 			goto next;
    765  1.73   thorpej 		}
    766  1.73   thorpej 		MCLAIM(m, &sc->sc_arpcom.ec_rx_mowner);
    767  1.73   thorpej 		if (len > (MHLEN - ETHER_ALIGN)) {
    768  1.73   thorpej 			MCLGET(m, M_DONTWAIT);
    769  1.73   thorpej 			if ((m->m_flags & M_EXT) == 0) {
    770   1.1  drochner 				m_freem(m);
    771  1.73   thorpej 				goto dropit;
    772   1.1  drochner 			}
    773   1.1  drochner 		}
    774  1.73   thorpej 		m_set_rcvif(m, ifp);
    775  1.73   thorpej 		m->m_data += ETHER_ALIGN;
    776  1.73   thorpej 		memcpy(mtod(m, void *), mtod(sd->sd_mbuf, void *), len);
    777  1.73   thorpej 		txp_rxd_free(sc, sd);
    778  1.73   thorpej #endif /* __NO_STRICT_ALIGNMENT */
    779  1.73   thorpej 
    780  1.73   thorpej 		m->m_pkthdr.len = m->m_len = len;
    781   1.1  drochner 
    782   1.1  drochner 		if (rxd->rx_stat & htole32(RX_STAT_IPCKSUMBAD))
    783  1.53   msaitoh 			sumflags |= (M_CSUM_IPv4 | M_CSUM_IPv4_BAD);
    784   1.1  drochner 		else if (rxd->rx_stat & htole32(RX_STAT_IPCKSUMGOOD))
    785   1.2  drochner 			sumflags |= M_CSUM_IPv4;
    786   1.1  drochner 
    787   1.1  drochner 		if (rxd->rx_stat & htole32(RX_STAT_TCPCKSUMBAD))
    788  1.53   msaitoh 			sumflags |= (M_CSUM_TCPv4 | M_CSUM_TCP_UDP_BAD);
    789   1.1  drochner 		else if (rxd->rx_stat & htole32(RX_STAT_TCPCKSUMGOOD))
    790   1.2  drochner 			sumflags |= M_CSUM_TCPv4;
    791   1.1  drochner 
    792   1.1  drochner 		if (rxd->rx_stat & htole32(RX_STAT_UDPCKSUMBAD))
    793  1.53   msaitoh 			sumflags |= (M_CSUM_UDPv4 | M_CSUM_TCP_UDP_BAD);
    794   1.1  drochner 		else if (rxd->rx_stat & htole32(RX_STAT_UDPCKSUMGOOD))
    795   1.2  drochner 			sumflags |= M_CSUM_UDPv4;
    796   1.1  drochner 
    797   1.2  drochner 		m->m_pkthdr.csum_flags = sumflags;
    798   1.1  drochner 
    799   1.1  drochner 		if (rxd->rx_stat & htole32(RX_STAT_VLAN)) {
    800  1.48  knakahar 			vlan_set_tag(m, htons(rxd->rx_vlan >> 16));
    801   1.1  drochner 		}
    802   1.1  drochner 
    803  1.42     ozaki 		if_percpuq_enqueue(ifp->if_percpuq, m);
    804   1.1  drochner 
    805   1.1  drochner next:
    806   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
    807  1.44   msaitoh 		    idx * sizeof(struct txp_rx_desc),
    808  1.44   msaitoh 		    sizeof(struct txp_rx_desc), BUS_DMASYNC_PREREAD);
    809   1.1  drochner 
    810   1.1  drochner 		roff += sizeof(struct txp_rx_desc);
    811   1.1  drochner 		if (roff == (RX_ENTRIES * sizeof(struct txp_rx_desc))) {
    812   1.1  drochner 			idx = 0;
    813   1.1  drochner 			roff = 0;
    814   1.1  drochner 			rxd = r->r_desc;
    815   1.1  drochner 		} else {
    816   1.1  drochner 			idx++;
    817   1.1  drochner 			rxd++;
    818   1.1  drochner 		}
    819   1.1  drochner 		woff = le32toh(*r->r_woff);
    820   1.1  drochner 	}
    821   1.1  drochner 
    822   1.1  drochner 	*r->r_roff = htole32(woff);
    823   1.1  drochner }
    824   1.1  drochner 
    825  1.62      maxv static void
    826  1.29       dsl txp_rxbuf_reclaim(struct txp_softc *sc)
    827   1.1  drochner {
    828   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
    829   1.1  drochner 	struct txp_hostvar *hv = sc->sc_hostvar;
    830   1.1  drochner 	struct txp_rxbuf_desc *rbd;
    831   1.1  drochner 	struct txp_swdesc *sd;
    832  1.53   msaitoh 	uint32_t i, end;
    833   1.1  drochner 
    834   1.1  drochner 	end = TXP_OFFSET2IDX(le32toh(hv->hv_rx_buf_read_idx));
    835   1.1  drochner 	i = TXP_OFFSET2IDX(le32toh(hv->hv_rx_buf_write_idx));
    836   1.1  drochner 
    837   1.1  drochner 	if (++i == RXBUF_ENTRIES)
    838   1.1  drochner 		i = 0;
    839   1.1  drochner 
    840   1.1  drochner 	rbd = sc->sc_rxbufs + i;
    841   1.1  drochner 
    842   1.1  drochner 	while (i != end) {
    843  1.69   thorpej 		sd = txp_rxd_alloc(sc);
    844   1.1  drochner 		if (sd == NULL)
    845   1.1  drochner 			break;
    846   1.1  drochner 
    847  1.73   thorpej 		/* We might already have a buffer allocated. */
    848  1.73   thorpej 		if (sd->sd_mbuf == NULL) {
    849  1.73   thorpej 			MGETHDR(sd->sd_mbuf, M_DONTWAIT, MT_DATA);
    850  1.73   thorpej 			if (sd->sd_mbuf == NULL)
    851  1.73   thorpej 				goto err_sd;
    852  1.73   thorpej 			MCLAIM(sd->sd_mbuf, &sc->sc_arpcom.ec_rx_mowner);
    853  1.73   thorpej 
    854  1.73   thorpej 			MCLGET(sd->sd_mbuf, M_DONTWAIT);
    855  1.73   thorpej 			if ((sd->sd_mbuf->m_flags & M_EXT) == 0)
    856  1.73   thorpej 				goto err_mbuf;
    857  1.73   thorpej 			m_set_rcvif(sd->sd_mbuf, ifp);
    858  1.73   thorpej 			sd->sd_mbuf->m_pkthdr.len =
    859  1.73   thorpej 			    sd->sd_mbuf->m_len = MCLBYTES;
    860  1.73   thorpej 			if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map,
    861  1.73   thorpej 			    sd->sd_mbuf, BUS_DMA_NOWAIT)) {
    862  1.73   thorpej 				goto err_mbuf;
    863  1.73   thorpej 			}
    864   1.1  drochner 		}
    865   1.1  drochner 
    866   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
    867   1.1  drochner 		    i * sizeof(struct txp_rxbuf_desc),
    868   1.1  drochner 		    sizeof(struct txp_rxbuf_desc), BUS_DMASYNC_POSTWRITE);
    869  1.10     perry 
    870   1.1  drochner 		/* stash away pointer */
    871  1.70   thorpej 		rbd->rb_vaddrlo = txp_rxd_idx(sc, sd);
    872   1.1  drochner 
    873  1.65   thorpej 		rbd->rb_paddrlo =
    874  1.65   thorpej 		    htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[0].ds_addr));
    875  1.65   thorpej 		rbd->rb_paddrhi =
    876  1.65   thorpej 		    htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[0].ds_addr));
    877   1.1  drochner 
    878   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
    879   1.1  drochner 		    sd->sd_map->dm_mapsize, BUS_DMASYNC_PREREAD);
    880   1.1  drochner 
    881   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
    882   1.1  drochner 		    i * sizeof(struct txp_rxbuf_desc),
    883   1.1  drochner 		    sizeof(struct txp_rxbuf_desc), BUS_DMASYNC_PREWRITE);
    884   1.1  drochner 
    885   1.1  drochner 		hv->hv_rx_buf_write_idx = htole32(TXP_IDX2OFFSET(i));
    886   1.1  drochner 
    887   1.1  drochner 		if (++i == RXBUF_ENTRIES) {
    888   1.1  drochner 			i = 0;
    889   1.1  drochner 			rbd = sc->sc_rxbufs;
    890   1.1  drochner 		} else
    891   1.1  drochner 			rbd++;
    892   1.1  drochner 	}
    893   1.1  drochner 	return;
    894   1.1  drochner 
    895   1.1  drochner err_mbuf:
    896   1.1  drochner 	m_freem(sd->sd_mbuf);
    897  1.72   thorpej 	sd->sd_mbuf = NULL;
    898   1.1  drochner err_sd:
    899  1.69   thorpej 	txp_rxd_free(sc, sd);
    900   1.1  drochner }
    901   1.1  drochner 
    902   1.1  drochner /*
    903   1.1  drochner  * Reclaim mbufs and entries from a transmit ring.
    904   1.1  drochner  */
    905  1.62      maxv static void
    906  1.44   msaitoh txp_tx_reclaim(struct txp_softc *sc, struct txp_tx_ring *r,
    907  1.44   msaitoh     struct txp_dma_alloc *dma)
    908   1.1  drochner {
    909   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
    910  1.53   msaitoh 	uint32_t idx = TXP_OFFSET2IDX(le32toh(*(r->r_off)));
    911  1.53   msaitoh 	uint32_t cons = r->r_cons, cnt = r->r_cnt;
    912   1.1  drochner 	struct txp_tx_desc *txd = r->r_desc + cons;
    913  1.72   thorpej 	struct txp_swdesc *sd;
    914   1.1  drochner 	struct mbuf *m;
    915   1.1  drochner 
    916   1.1  drochner 	while (cons != idx) {
    917   1.1  drochner 		if (cnt == 0)
    918   1.1  drochner 			break;
    919   1.1  drochner 
    920   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
    921   1.1  drochner 		    cons * sizeof(struct txp_tx_desc),
    922   1.1  drochner 		    sizeof(struct txp_tx_desc),
    923   1.1  drochner 		    BUS_DMASYNC_POSTWRITE);
    924   1.1  drochner 
    925   1.1  drochner 		if ((txd->tx_flags & TX_FLAGS_TYPE_M) ==
    926   1.1  drochner 		    TX_FLAGS_TYPE_DATA) {
    927  1.72   thorpej 			KASSERT(txd->tx_addrlo < TX_ENTRIES);
    928  1.72   thorpej 			sd = &sc->sc_txd[txd->tx_addrlo];
    929   1.1  drochner 			m = sd->sd_mbuf;
    930  1.72   thorpej 			sd->sd_mbuf = NULL;
    931   1.1  drochner 			if (m != NULL) {
    932  1.72   thorpej 				bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
    933  1.72   thorpej 				    sd->sd_map->dm_mapsize,
    934  1.72   thorpej 				    BUS_DMASYNC_POSTWRITE);
    935  1.72   thorpej 				bus_dmamap_unload(sc->sc_dmat, sd->sd_map);
    936   1.1  drochner 				m_freem(m);
    937   1.1  drochner 				txd->tx_addrlo = 0;
    938   1.1  drochner 				txd->tx_addrhi = 0;
    939  1.63   thorpej 				if_statinc(ifp, if_opackets);
    940   1.1  drochner 			}
    941   1.1  drochner 		}
    942   1.1  drochner 		ifp->if_flags &= ~IFF_OACTIVE;
    943   1.1  drochner 
    944   1.1  drochner 		if (++cons == TX_ENTRIES) {
    945   1.1  drochner 			txd = r->r_desc;
    946   1.1  drochner 			cons = 0;
    947  1.72   thorpej 		} else
    948   1.1  drochner 			txd++;
    949   1.1  drochner 
    950   1.1  drochner 		cnt--;
    951   1.1  drochner 	}
    952   1.1  drochner 
    953   1.1  drochner 	r->r_cons = cons;
    954   1.1  drochner 	r->r_cnt = cnt;
    955   1.1  drochner 	if (cnt == 0)
    956   1.1  drochner 		ifp->if_timer = 0;
    957   1.1  drochner }
    958   1.1  drochner 
    959  1.62      maxv static bool
    960  1.35   tsutsui txp_shutdown(device_t self, int howto)
    961   1.1  drochner {
    962  1.35   tsutsui 	struct txp_softc *sc;
    963  1.35   tsutsui 
    964  1.35   tsutsui 	sc = device_private(self);
    965   1.1  drochner 
    966   1.1  drochner 	/* mask all interrupts */
    967   1.1  drochner 	WRITE_REG(sc, TXP_IMR,
    968   1.1  drochner 	    TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
    969   1.1  drochner 	    TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
    970   1.1  drochner 	    TXP_INT_LATCH);
    971   1.1  drochner 
    972   1.1  drochner 	txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
    973   1.1  drochner 	txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
    974   1.1  drochner 	txp_command(sc, TXP_CMD_HALT, 0, 0, 0, NULL, NULL, NULL, 0);
    975  1.35   tsutsui 
    976  1.35   tsutsui 	return true;
    977   1.1  drochner }
    978   1.1  drochner 
    979  1.62      maxv static int
    980  1.29       dsl txp_alloc_rings(struct txp_softc *sc)
    981   1.1  drochner {
    982   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
    983   1.1  drochner 	struct txp_boot_record *boot;
    984   1.1  drochner 	struct txp_swdesc *sd;
    985  1.53   msaitoh 	uint32_t r;
    986  1.15  christos 	int i, j, nb;
    987   1.1  drochner 
    988   1.1  drochner 	/* boot record */
    989  1.44   msaitoh 	if (txp_dma_malloc(sc, sizeof(struct txp_boot_record),
    990  1.44   msaitoh 	    &sc->sc_boot_dma, BUS_DMA_COHERENT)) {
    991   1.1  drochner 		printf(": can't allocate boot record\n");
    992   1.1  drochner 		return (-1);
    993   1.1  drochner 	}
    994   1.1  drochner 	boot = (struct txp_boot_record *)sc->sc_boot_dma.dma_vaddr;
    995  1.32    cegger 	memset(boot, 0, sizeof(*boot));
    996   1.1  drochner 	sc->sc_boot = boot;
    997   1.1  drochner 
    998   1.1  drochner 	/* host variables */
    999   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_hostvar), &sc->sc_host_dma,
   1000   1.1  drochner 	    BUS_DMA_COHERENT)) {
   1001   1.1  drochner 		printf(": can't allocate host ring\n");
   1002   1.1  drochner 		goto bail_boot;
   1003   1.1  drochner 	}
   1004  1.32    cegger 	memset(sc->sc_host_dma.dma_vaddr, 0, sizeof(struct txp_hostvar));
   1005  1.65   thorpej 	boot->br_hostvar_lo = htole32(BUS_ADDR_LO32(sc->sc_host_dma.dma_paddr));
   1006  1.65   thorpej 	boot->br_hostvar_hi = htole32(BUS_ADDR_HI32(sc->sc_host_dma.dma_paddr));
   1007   1.1  drochner 	sc->sc_hostvar = (struct txp_hostvar *)sc->sc_host_dma.dma_vaddr;
   1008   1.1  drochner 
   1009   1.1  drochner 	/* high priority tx ring */
   1010   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_tx_desc) * TX_ENTRIES,
   1011   1.1  drochner 	    &sc->sc_txhiring_dma, BUS_DMA_COHERENT)) {
   1012   1.1  drochner 		printf(": can't allocate high tx ring\n");
   1013   1.1  drochner 		goto bail_host;
   1014   1.1  drochner 	}
   1015  1.44   msaitoh 	memset(sc->sc_txhiring_dma.dma_vaddr, 0,
   1016  1.44   msaitoh 	    sizeof(struct txp_tx_desc) * TX_ENTRIES);
   1017  1.65   thorpej 	boot->br_txhipri_lo =
   1018  1.65   thorpej 	    htole32(BUS_ADDR_LO32(sc->sc_txhiring_dma.dma_paddr));
   1019  1.65   thorpej 	boot->br_txhipri_hi =
   1020  1.65   thorpej 	    htole32(BUS_ADDR_HI32(sc->sc_txhiring_dma.dma_paddr));
   1021   1.1  drochner 	boot->br_txhipri_siz = htole32(TX_ENTRIES * sizeof(struct txp_tx_desc));
   1022   1.1  drochner 	sc->sc_txhir.r_reg = TXP_H2A_1;
   1023  1.65   thorpej 	sc->sc_txhir.r_desc =
   1024  1.65   thorpej 	    (struct txp_tx_desc *)sc->sc_txhiring_dma.dma_vaddr;
   1025   1.1  drochner 	sc->sc_txhir.r_cons = sc->sc_txhir.r_prod = sc->sc_txhir.r_cnt = 0;
   1026   1.1  drochner 	sc->sc_txhir.r_off = &sc->sc_hostvar->hv_tx_hi_desc_read_idx;
   1027   1.1  drochner 	for (i = 0; i < TX_ENTRIES; i++) {
   1028   1.1  drochner 		if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN,
   1029  1.68   thorpej 		    TXP_MAXTXSEGS, TXP_MAX_SEGLEN, 0, BUS_DMA_NOWAIT,
   1030  1.68   thorpej 		    &sc->sc_txd[i].sd_map) != 0) {
   1031   1.1  drochner 			for (j = 0; j < i; j++) {
   1032   1.1  drochner 				bus_dmamap_destroy(sc->sc_dmat,
   1033   1.1  drochner 				    sc->sc_txd[j].sd_map);
   1034   1.1  drochner 				sc->sc_txd[j].sd_map = NULL;
   1035   1.1  drochner 			}
   1036   1.1  drochner 			goto bail_txhiring;
   1037   1.1  drochner 		}
   1038   1.1  drochner 	}
   1039   1.1  drochner 
   1040   1.1  drochner 	/* low priority tx ring */
   1041   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_tx_desc) * TX_ENTRIES,
   1042   1.1  drochner 	    &sc->sc_txloring_dma, BUS_DMA_COHERENT)) {
   1043   1.1  drochner 		printf(": can't allocate low tx ring\n");
   1044   1.1  drochner 		goto bail_txhiring;
   1045   1.1  drochner 	}
   1046  1.44   msaitoh 	memset(sc->sc_txloring_dma.dma_vaddr, 0,
   1047  1.44   msaitoh 	    sizeof(struct txp_tx_desc) * TX_ENTRIES);
   1048  1.65   thorpej 	boot->br_txlopri_lo =
   1049  1.65   thorpej 	    htole32(BUS_ADDR_LO32(sc->sc_txloring_dma.dma_paddr));
   1050  1.65   thorpej 	boot->br_txlopri_hi =
   1051  1.65   thorpej 	    htole32(BUS_ADDR_HI32(sc->sc_txloring_dma.dma_paddr));
   1052   1.1  drochner 	boot->br_txlopri_siz = htole32(TX_ENTRIES * sizeof(struct txp_tx_desc));
   1053   1.1  drochner 	sc->sc_txlor.r_reg = TXP_H2A_3;
   1054  1.65   thorpej 	sc->sc_txlor.r_desc =
   1055  1.65   thorpej 	    (struct txp_tx_desc *)sc->sc_txloring_dma.dma_vaddr;
   1056   1.1  drochner 	sc->sc_txlor.r_cons = sc->sc_txlor.r_prod = sc->sc_txlor.r_cnt = 0;
   1057   1.1  drochner 	sc->sc_txlor.r_off = &sc->sc_hostvar->hv_tx_lo_desc_read_idx;
   1058   1.1  drochner 
   1059   1.1  drochner 	/* high priority rx ring */
   1060   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_rx_desc) * RX_ENTRIES,
   1061   1.1  drochner 	    &sc->sc_rxhiring_dma, BUS_DMA_COHERENT)) {
   1062   1.1  drochner 		printf(": can't allocate high rx ring\n");
   1063   1.1  drochner 		goto bail_txloring;
   1064   1.1  drochner 	}
   1065  1.44   msaitoh 	memset(sc->sc_rxhiring_dma.dma_vaddr, 0,
   1066  1.44   msaitoh 	    sizeof(struct txp_rx_desc) * RX_ENTRIES);
   1067  1.65   thorpej 	boot->br_rxhipri_lo =
   1068  1.65   thorpej 	    htole32(BUS_ADDR_LO32(sc->sc_rxhiring_dma.dma_paddr));
   1069  1.65   thorpej 	boot->br_rxhipri_hi =
   1070  1.65   thorpej 	    htole32(BUS_ADDR_HI32(sc->sc_rxhiring_dma.dma_paddr));
   1071   1.1  drochner 	boot->br_rxhipri_siz = htole32(RX_ENTRIES * sizeof(struct txp_rx_desc));
   1072   1.1  drochner 	sc->sc_rxhir.r_desc =
   1073   1.1  drochner 	    (struct txp_rx_desc *)sc->sc_rxhiring_dma.dma_vaddr;
   1074   1.1  drochner 	sc->sc_rxhir.r_roff = &sc->sc_hostvar->hv_rx_hi_read_idx;
   1075   1.1  drochner 	sc->sc_rxhir.r_woff = &sc->sc_hostvar->hv_rx_hi_write_idx;
   1076   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, sc->sc_rxhiring_dma.dma_map,
   1077   1.1  drochner 	    0, sc->sc_rxhiring_dma.dma_map->dm_mapsize, BUS_DMASYNC_PREREAD);
   1078   1.1  drochner 
   1079   1.1  drochner 	/* low priority ring */
   1080   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_rx_desc) * RX_ENTRIES,
   1081   1.1  drochner 	    &sc->sc_rxloring_dma, BUS_DMA_COHERENT)) {
   1082   1.1  drochner 		printf(": can't allocate low rx ring\n");
   1083   1.1  drochner 		goto bail_rxhiring;
   1084   1.1  drochner 	}
   1085  1.44   msaitoh 	memset(sc->sc_rxloring_dma.dma_vaddr, 0,
   1086  1.44   msaitoh 	    sizeof(struct txp_rx_desc) * RX_ENTRIES);
   1087  1.65   thorpej 	boot->br_rxlopri_lo =
   1088  1.65   thorpej 	    htole32(BUS_ADDR_LO32(sc->sc_rxloring_dma.dma_paddr));
   1089  1.65   thorpej 	boot->br_rxlopri_hi =
   1090  1.65   thorpej 	    htole32(BUS_ADDR_HI32(sc->sc_rxloring_dma.dma_paddr));
   1091   1.1  drochner 	boot->br_rxlopri_siz = htole32(RX_ENTRIES * sizeof(struct txp_rx_desc));
   1092   1.1  drochner 	sc->sc_rxlor.r_desc =
   1093   1.1  drochner 	    (struct txp_rx_desc *)sc->sc_rxloring_dma.dma_vaddr;
   1094   1.1  drochner 	sc->sc_rxlor.r_roff = &sc->sc_hostvar->hv_rx_lo_read_idx;
   1095   1.1  drochner 	sc->sc_rxlor.r_woff = &sc->sc_hostvar->hv_rx_lo_write_idx;
   1096   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, sc->sc_rxloring_dma.dma_map,
   1097   1.1  drochner 	    0, sc->sc_rxloring_dma.dma_map->dm_mapsize, BUS_DMASYNC_PREREAD);
   1098   1.1  drochner 
   1099   1.1  drochner 	/* command ring */
   1100   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_cmd_desc) * CMD_ENTRIES,
   1101   1.1  drochner 	    &sc->sc_cmdring_dma, BUS_DMA_COHERENT)) {
   1102   1.1  drochner 		printf(": can't allocate command ring\n");
   1103   1.1  drochner 		goto bail_rxloring;
   1104   1.1  drochner 	}
   1105  1.44   msaitoh 	memset(sc->sc_cmdring_dma.dma_vaddr, 0,
   1106  1.44   msaitoh 	    sizeof(struct txp_cmd_desc) * CMD_ENTRIES);
   1107  1.65   thorpej 	boot->br_cmd_lo = htole32(BUS_ADDR_LO32(sc->sc_cmdring_dma.dma_paddr));
   1108  1.65   thorpej 	boot->br_cmd_hi = htole32(BUS_ADDR_HI32(sc->sc_cmdring_dma.dma_paddr));
   1109   1.1  drochner 	boot->br_cmd_siz = htole32(CMD_ENTRIES * sizeof(struct txp_cmd_desc));
   1110   1.1  drochner 	sc->sc_cmdring.base = (struct txp_cmd_desc *)sc->sc_cmdring_dma.dma_vaddr;
   1111   1.1  drochner 	sc->sc_cmdring.size = CMD_ENTRIES * sizeof(struct txp_cmd_desc);
   1112   1.1  drochner 	sc->sc_cmdring.lastwrite = 0;
   1113   1.1  drochner 
   1114   1.1  drochner 	/* response ring */
   1115   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_rsp_desc) * RSP_ENTRIES,
   1116   1.1  drochner 	    &sc->sc_rspring_dma, BUS_DMA_COHERENT)) {
   1117   1.1  drochner 		printf(": can't allocate response ring\n");
   1118   1.1  drochner 		goto bail_cmdring;
   1119   1.1  drochner 	}
   1120  1.44   msaitoh 	memset(sc->sc_rspring_dma.dma_vaddr, 0,
   1121  1.44   msaitoh 	    sizeof(struct txp_rsp_desc) * RSP_ENTRIES);
   1122  1.65   thorpej 	boot->br_resp_lo = htole32(BUS_ADDR_LO32(sc->sc_rspring_dma.dma_paddr));
   1123  1.65   thorpej 	boot->br_resp_hi = htole32(BUS_ADDR_HI32(sc->sc_rspring_dma.dma_paddr));
   1124   1.1  drochner 	boot->br_resp_siz = htole32(CMD_ENTRIES * sizeof(struct txp_rsp_desc));
   1125   1.1  drochner 	sc->sc_rspring.base = (struct txp_rsp_desc *)sc->sc_rspring_dma.dma_vaddr;
   1126   1.1  drochner 	sc->sc_rspring.size = RSP_ENTRIES * sizeof(struct txp_rsp_desc);
   1127   1.1  drochner 	sc->sc_rspring.lastwrite = 0;
   1128   1.1  drochner 
   1129   1.1  drochner 	/* receive buffer ring */
   1130   1.1  drochner 	if (txp_dma_malloc(sc, sizeof(struct txp_rxbuf_desc) * RXBUF_ENTRIES,
   1131   1.1  drochner 	    &sc->sc_rxbufring_dma, BUS_DMA_COHERENT)) {
   1132   1.1  drochner 		printf(": can't allocate rx buffer ring\n");
   1133   1.1  drochner 		goto bail_rspring;
   1134   1.1  drochner 	}
   1135  1.44   msaitoh 	memset(sc->sc_rxbufring_dma.dma_vaddr, 0,
   1136  1.44   msaitoh 	    sizeof(struct txp_rxbuf_desc) * RXBUF_ENTRIES);
   1137  1.65   thorpej 	boot->br_rxbuf_lo = htole32(BUS_ADDR_LO32(sc->sc_rxbufring_dma.dma_paddr));
   1138  1.65   thorpej 	boot->br_rxbuf_hi = htole32(BUS_ADDR_HI32(sc->sc_rxbufring_dma.dma_paddr));
   1139   1.1  drochner 	boot->br_rxbuf_siz = htole32(RXBUF_ENTRIES * sizeof(struct txp_rxbuf_desc));
   1140   1.1  drochner 	sc->sc_rxbufs = (struct txp_rxbuf_desc *)sc->sc_rxbufring_dma.dma_vaddr;
   1141  1.15  christos 	for (nb = 0; nb < RXBUF_ENTRIES; nb++) {
   1142  1.69   thorpej 		sd = &sc->sc_rxd[nb];
   1143  1.70   thorpej 
   1144  1.15  christos 		/* stash away pointer */
   1145  1.70   thorpej 		sc->sc_rxbufs[nb].rb_vaddrlo = txp_rxd_idx(sc, sd);
   1146   1.1  drochner 
   1147  1.69   thorpej 		MGETHDR(sd->sd_mbuf, M_WAIT, MT_DATA);
   1148   1.1  drochner 		if (sd->sd_mbuf == NULL) {
   1149   1.1  drochner 			goto bail_rxbufring;
   1150   1.1  drochner 		}
   1151   1.1  drochner 
   1152  1.69   thorpej 		MCLGET(sd->sd_mbuf, M_WAIT);
   1153   1.1  drochner 		if ((sd->sd_mbuf->m_flags & M_EXT) == 0) {
   1154   1.1  drochner 			goto bail_rxbufring;
   1155   1.1  drochner 		}
   1156   1.1  drochner 		sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
   1157  1.43     ozaki 		m_set_rcvif(sd->sd_mbuf, ifp);
   1158   1.1  drochner 		if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN, 1,
   1159  1.69   thorpej 		    TXP_MAX_PKTLEN, 0, BUS_DMA_WAITOK, &sd->sd_map)) {
   1160   1.1  drochner 			goto bail_rxbufring;
   1161   1.1  drochner 		}
   1162   1.1  drochner 		if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, sd->sd_mbuf,
   1163  1.69   thorpej 		    BUS_DMA_WAITOK)) {
   1164   1.1  drochner 			bus_dmamap_destroy(sc->sc_dmat, sd->sd_map);
   1165   1.1  drochner 			goto bail_rxbufring;
   1166   1.1  drochner 		}
   1167   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
   1168   1.1  drochner 		    sd->sd_map->dm_mapsize, BUS_DMASYNC_PREREAD);
   1169   1.1  drochner 
   1170  1.15  christos 		sc->sc_rxbufs[nb].rb_paddrlo =
   1171  1.65   thorpej 		    htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[0].ds_addr));
   1172  1.15  christos 		sc->sc_rxbufs[nb].rb_paddrhi =
   1173  1.65   thorpej 		    htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[0].ds_addr));
   1174   1.1  drochner 	}
   1175   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
   1176   1.1  drochner 	    0, sc->sc_rxbufring_dma.dma_map->dm_mapsize,
   1177   1.1  drochner 	    BUS_DMASYNC_PREWRITE);
   1178   1.1  drochner 	sc->sc_hostvar->hv_rx_buf_write_idx = htole32((RXBUF_ENTRIES - 1) *
   1179   1.1  drochner 	    sizeof(struct txp_rxbuf_desc));
   1180   1.1  drochner 
   1181   1.1  drochner 	/* zero dma */
   1182  1.53   msaitoh 	if (txp_dma_malloc(sc, sizeof(uint32_t), &sc->sc_zero_dma,
   1183   1.1  drochner 	    BUS_DMA_COHERENT)) {
   1184   1.1  drochner 		printf(": can't allocate response ring\n");
   1185   1.1  drochner 		goto bail_rxbufring;
   1186   1.1  drochner 	}
   1187  1.53   msaitoh 	memset(sc->sc_zero_dma.dma_vaddr, 0, sizeof(uint32_t));
   1188  1.65   thorpej 	boot->br_zero_lo = htole32(BUS_ADDR_LO32(sc->sc_zero_dma.dma_paddr));
   1189  1.65   thorpej 	boot->br_zero_hi = htole32(BUS_ADDR_HI32(sc->sc_zero_dma.dma_paddr));
   1190   1.1  drochner 
   1191   1.1  drochner 	/* See if it's waiting for boot, and try to boot it */
   1192   1.1  drochner 	for (i = 0; i < 10000; i++) {
   1193   1.1  drochner 		r = READ_REG(sc, TXP_A2H_0);
   1194   1.1  drochner 		if (r == STAT_WAITING_FOR_BOOT)
   1195   1.1  drochner 			break;
   1196   1.1  drochner 		DELAY(50);
   1197   1.1  drochner 	}
   1198   1.1  drochner 	if (r != STAT_WAITING_FOR_BOOT) {
   1199   1.1  drochner 		printf(": not waiting for boot\n");
   1200   1.1  drochner 		goto bail;
   1201   1.1  drochner 	}
   1202  1.65   thorpej 	WRITE_REG(sc, TXP_H2A_2, BUS_ADDR_HI32(sc->sc_boot_dma.dma_paddr));
   1203  1.65   thorpej 	WRITE_REG(sc, TXP_H2A_1, BUS_ADDR_LO32(sc->sc_boot_dma.dma_paddr));
   1204   1.1  drochner 	WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_REGISTER_BOOT_RECORD);
   1205   1.1  drochner 
   1206   1.1  drochner 	/* See if it booted */
   1207   1.1  drochner 	for (i = 0; i < 10000; i++) {
   1208   1.1  drochner 		r = READ_REG(sc, TXP_A2H_0);
   1209   1.1  drochner 		if (r == STAT_RUNNING)
   1210   1.1  drochner 			break;
   1211   1.1  drochner 		DELAY(50);
   1212   1.1  drochner 	}
   1213   1.1  drochner 	if (r != STAT_RUNNING) {
   1214   1.1  drochner 		printf(": fw not running\n");
   1215   1.1  drochner 		goto bail;
   1216   1.1  drochner 	}
   1217   1.1  drochner 
   1218   1.1  drochner 	/* Clear TX and CMD ring write registers */
   1219   1.1  drochner 	WRITE_REG(sc, TXP_H2A_1, TXP_BOOTCMD_NULL);
   1220   1.1  drochner 	WRITE_REG(sc, TXP_H2A_2, TXP_BOOTCMD_NULL);
   1221   1.1  drochner 	WRITE_REG(sc, TXP_H2A_3, TXP_BOOTCMD_NULL);
   1222   1.1  drochner 	WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_NULL);
   1223   1.1  drochner 
   1224   1.1  drochner 	return (0);
   1225   1.1  drochner 
   1226   1.1  drochner bail:
   1227   1.1  drochner 	txp_dma_free(sc, &sc->sc_zero_dma);
   1228   1.1  drochner bail_rxbufring:
   1229  1.15  christos 	if (nb == RXBUF_ENTRIES)
   1230  1.15  christos 		nb--;
   1231  1.15  christos 	for (i = 0; i <= nb; i++) {
   1232  1.34   tsutsui 		memcpy(&sd, __UNVOLATILE(&sc->sc_rxbufs[i].rb_vaddrlo),
   1233  1.15  christos 		    sizeof(sd));
   1234  1.69   thorpej 		/* XXXJRT */
   1235  1.15  christos 	}
   1236   1.1  drochner 	txp_dma_free(sc, &sc->sc_rxbufring_dma);
   1237   1.1  drochner bail_rspring:
   1238   1.1  drochner 	txp_dma_free(sc, &sc->sc_rspring_dma);
   1239   1.1  drochner bail_cmdring:
   1240   1.1  drochner 	txp_dma_free(sc, &sc->sc_cmdring_dma);
   1241   1.1  drochner bail_rxloring:
   1242   1.1  drochner 	txp_dma_free(sc, &sc->sc_rxloring_dma);
   1243   1.1  drochner bail_rxhiring:
   1244   1.1  drochner 	txp_dma_free(sc, &sc->sc_rxhiring_dma);
   1245   1.1  drochner bail_txloring:
   1246   1.1  drochner 	txp_dma_free(sc, &sc->sc_txloring_dma);
   1247   1.1  drochner bail_txhiring:
   1248   1.1  drochner 	txp_dma_free(sc, &sc->sc_txhiring_dma);
   1249   1.1  drochner bail_host:
   1250   1.1  drochner 	txp_dma_free(sc, &sc->sc_host_dma);
   1251   1.1  drochner bail_boot:
   1252   1.1  drochner 	txp_dma_free(sc, &sc->sc_boot_dma);
   1253   1.1  drochner 	return (-1);
   1254   1.1  drochner }
   1255   1.1  drochner 
   1256  1.62      maxv static int
   1257  1.44   msaitoh txp_dma_malloc(struct txp_softc *sc, bus_size_t size,
   1258  1.44   msaitoh     struct txp_dma_alloc *dma, int mapflags)
   1259   1.1  drochner {
   1260   1.1  drochner 	int r;
   1261   1.1  drochner 
   1262   1.1  drochner 	if ((r = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0,
   1263   1.1  drochner 	    &dma->dma_seg, 1, &dma->dma_nseg, 0)) != 0)
   1264   1.1  drochner 		goto fail_0;
   1265   1.1  drochner 
   1266   1.1  drochner 	if ((r = bus_dmamem_map(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg,
   1267   1.1  drochner 	    size, &dma->dma_vaddr, mapflags | BUS_DMA_NOWAIT)) != 0)
   1268   1.1  drochner 		goto fail_1;
   1269   1.1  drochner 
   1270   1.1  drochner 	if ((r = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
   1271   1.1  drochner 	    BUS_DMA_NOWAIT, &dma->dma_map)) != 0)
   1272   1.1  drochner 		goto fail_2;
   1273   1.1  drochner 
   1274   1.1  drochner 	if ((r = bus_dmamap_load(sc->sc_dmat, dma->dma_map, dma->dma_vaddr,
   1275   1.1  drochner 	    size, NULL, BUS_DMA_NOWAIT)) != 0)
   1276   1.1  drochner 		goto fail_3;
   1277   1.1  drochner 
   1278   1.1  drochner 	dma->dma_paddr = dma->dma_map->dm_segs[0].ds_addr;
   1279   1.1  drochner 	return (0);
   1280   1.1  drochner 
   1281   1.1  drochner fail_3:
   1282   1.1  drochner 	bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
   1283   1.1  drochner fail_2:
   1284   1.1  drochner 	bus_dmamem_unmap(sc->sc_dmat, dma->dma_vaddr, size);
   1285   1.1  drochner fail_1:
   1286   1.1  drochner 	bus_dmamem_free(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg);
   1287   1.1  drochner fail_0:
   1288   1.1  drochner 	return (r);
   1289   1.1  drochner }
   1290   1.1  drochner 
   1291  1.62      maxv static void
   1292  1.29       dsl txp_dma_free(struct txp_softc *sc, struct txp_dma_alloc *dma)
   1293   1.1  drochner {
   1294  1.54   msaitoh 	bus_size_t mapsize = dma->dma_map->dm_mapsize;
   1295  1.54   msaitoh 
   1296   1.1  drochner 	bus_dmamap_unload(sc->sc_dmat, dma->dma_map);
   1297  1.54   msaitoh 	bus_dmamem_unmap(sc->sc_dmat, dma->dma_vaddr, mapsize);
   1298   1.1  drochner 	bus_dmamem_free(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg);
   1299   1.1  drochner 	bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
   1300   1.1  drochner }
   1301   1.1  drochner 
   1302  1.62      maxv static int
   1303  1.27    dyoung txp_ioctl(struct ifnet *ifp, u_long command, void *data)
   1304   1.1  drochner {
   1305   1.1  drochner 	struct txp_softc *sc = ifp->if_softc;
   1306   1.1  drochner 	struct ifaddr *ifa = (struct ifaddr *)data;
   1307   1.1  drochner 	int s, error = 0;
   1308   1.1  drochner 
   1309   1.1  drochner 	s = splnet();
   1310   1.1  drochner 
   1311   1.1  drochner #if 0
   1312   1.1  drochner 	if ((error = ether_ioctl(ifp, &sc->sc_arpcom, command, data)) > 0) {
   1313   1.1  drochner 		splx(s);
   1314   1.1  drochner 		return error;
   1315   1.1  drochner 	}
   1316   1.1  drochner #endif
   1317   1.1  drochner 
   1318  1.55   msaitoh 	switch (command) {
   1319  1.27    dyoung 	case SIOCINITIFADDR:
   1320   1.1  drochner 		ifp->if_flags |= IFF_UP;
   1321  1.27    dyoung 		txp_init(sc);
   1322   1.1  drochner 		switch (ifa->ifa_addr->sa_family) {
   1323   1.1  drochner #ifdef INET
   1324   1.1  drochner 		case AF_INET:
   1325   1.1  drochner 			arp_ifinit(ifp, ifa);
   1326   1.1  drochner 			break;
   1327   1.1  drochner #endif /* INET */
   1328   1.1  drochner 		default:
   1329   1.1  drochner 			break;
   1330   1.1  drochner 		}
   1331   1.1  drochner 		break;
   1332   1.1  drochner 	case SIOCSIFFLAGS:
   1333  1.27    dyoung 		if ((error = ifioctl_common(ifp, command, data)) != 0)
   1334  1.27    dyoung 			break;
   1335   1.1  drochner 		if (ifp->if_flags & IFF_UP) {
   1336   1.1  drochner 			txp_init(sc);
   1337   1.1  drochner 		} else {
   1338   1.1  drochner 			if (ifp->if_flags & IFF_RUNNING)
   1339   1.1  drochner 				txp_stop(sc);
   1340   1.1  drochner 		}
   1341   1.1  drochner 		break;
   1342   1.1  drochner 	case SIOCADDMULTI:
   1343   1.1  drochner 	case SIOCDELMULTI:
   1344  1.23    dyoung 		if ((error = ether_ioctl(ifp, command, data)) != ENETRESET)
   1345  1.23    dyoung 			break;
   1346  1.23    dyoung 
   1347  1.23    dyoung 		error = 0;
   1348  1.23    dyoung 
   1349  1.23    dyoung 		if (command != SIOCADDMULTI && command != SIOCDELMULTI)
   1350  1.23    dyoung 			;
   1351  1.23    dyoung 		else if (ifp->if_flags & IFF_RUNNING) {
   1352   1.1  drochner 			/*
   1353   1.1  drochner 			 * Multicast list has changed; set the hardware
   1354   1.1  drochner 			 * filter accordingly.
   1355   1.1  drochner 			 */
   1356  1.23    dyoung 			txp_set_filter(sc);
   1357   1.1  drochner 		}
   1358   1.1  drochner 		break;
   1359   1.1  drochner 	default:
   1360  1.27    dyoung 		error = ether_ioctl(ifp, command, data);
   1361   1.1  drochner 		break;
   1362   1.1  drochner 	}
   1363   1.1  drochner 
   1364   1.1  drochner 	splx(s);
   1365   1.1  drochner 
   1366  1.55   msaitoh 	return (error);
   1367   1.1  drochner }
   1368   1.1  drochner 
   1369  1.62      maxv static void
   1370  1.29       dsl txp_init(struct txp_softc *sc)
   1371   1.1  drochner {
   1372   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
   1373   1.1  drochner 	int s;
   1374   1.1  drochner 
   1375   1.1  drochner 	txp_stop(sc);
   1376   1.1  drochner 
   1377   1.1  drochner 	s = splnet();
   1378   1.1  drochner 
   1379   1.1  drochner 	txp_set_filter(sc);
   1380   1.1  drochner 
   1381   1.1  drochner 	txp_command(sc, TXP_CMD_TX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
   1382   1.1  drochner 	txp_command(sc, TXP_CMD_RX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
   1383   1.1  drochner 
   1384   1.1  drochner 	WRITE_REG(sc, TXP_IER, TXP_INT_RESERVED | TXP_INT_SELF |
   1385   1.1  drochner 	    TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
   1386   1.1  drochner 	    TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
   1387   1.1  drochner 	    TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
   1388   1.1  drochner 	    TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |  TXP_INT_LATCH);
   1389   1.1  drochner 	WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
   1390   1.1  drochner 
   1391   1.1  drochner 	ifp->if_flags |= IFF_RUNNING;
   1392   1.1  drochner 	ifp->if_flags &= ~IFF_OACTIVE;
   1393   1.1  drochner 	ifp->if_timer = 0;
   1394   1.1  drochner 
   1395   1.1  drochner 	if (!callout_pending(&sc->sc_tick))
   1396   1.1  drochner 		callout_schedule(&sc->sc_tick, hz);
   1397   1.1  drochner 
   1398   1.1  drochner 	splx(s);
   1399   1.1  drochner }
   1400   1.1  drochner 
   1401  1.62      maxv static void
   1402  1.29       dsl txp_tick(void *vsc)
   1403   1.1  drochner {
   1404   1.1  drochner 	struct txp_softc *sc = vsc;
   1405   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
   1406   1.1  drochner 	struct txp_rsp_desc *rsp = NULL;
   1407   1.1  drochner 	struct txp_ext_desc *ext;
   1408   1.1  drochner 	int s;
   1409   1.1  drochner 
   1410   1.1  drochner 	s = splnet();
   1411   1.1  drochner 	txp_rxbuf_reclaim(sc);
   1412   1.1  drochner 
   1413   1.1  drochner 	if (txp_command2(sc, TXP_CMD_READ_STATISTICS, 0, 0, 0, NULL, 0,
   1414   1.1  drochner 	    &rsp, 1))
   1415   1.1  drochner 		goto out;
   1416   1.1  drochner 	if (rsp->rsp_numdesc != 6)
   1417   1.1  drochner 		goto out;
   1418   1.1  drochner 	if (txp_command(sc, TXP_CMD_CLEAR_STATISTICS, 0, 0, 0,
   1419   1.1  drochner 	    NULL, NULL, NULL, 1))
   1420   1.1  drochner 		goto out;
   1421   1.1  drochner 	ext = (struct txp_ext_desc *)(rsp + 1);
   1422   1.1  drochner 
   1423  1.63   thorpej 	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
   1424  1.76  riastrad 	if_statadd_ref(ifp, nsr, if_ierrors,
   1425  1.63   thorpej 	    ext[3].ext_2 + ext[3].ext_3 + ext[3].ext_4 +
   1426  1.63   thorpej 	    ext[4].ext_1 + ext[4].ext_4);
   1427  1.76  riastrad 	if_statadd_ref(ifp, nsr, if_oerrors,
   1428  1.63   thorpej 	    ext[0].ext_1 + ext[1].ext_1 + ext[1].ext_4 + ext[2].ext_1);
   1429  1.76  riastrad 	if_statadd_ref(ifp, nsr, if_collisions,
   1430  1.63   thorpej 	    ext[0].ext_2 + ext[0].ext_3 + ext[1].ext_2 + ext[1].ext_3);
   1431  1.76  riastrad 	if_statadd_ref(ifp, nsr, if_opackets, rsp->rsp_par2);
   1432  1.63   thorpej 	IF_STAT_PUTREF(ifp);
   1433   1.1  drochner 
   1434   1.1  drochner out:
   1435   1.1  drochner 	if (rsp != NULL)
   1436   1.1  drochner 		free(rsp, M_DEVBUF);
   1437   1.1  drochner 
   1438   1.1  drochner 	splx(s);
   1439   1.1  drochner 	callout_schedule(&sc->sc_tick, hz);
   1440   1.1  drochner }
   1441   1.1  drochner 
   1442  1.62      maxv static void
   1443  1.29       dsl txp_start(struct ifnet *ifp)
   1444   1.1  drochner {
   1445   1.1  drochner 	struct txp_softc *sc = ifp->if_softc;
   1446   1.1  drochner 	struct txp_tx_ring *r = &sc->sc_txhir;
   1447   1.1  drochner 	struct txp_tx_desc *txd;
   1448   1.1  drochner 	int txdidx;
   1449   1.1  drochner 	struct txp_frag_desc *fxd;
   1450   1.1  drochner 	struct mbuf *m, *mnew;
   1451   1.1  drochner 	struct txp_swdesc *sd;
   1452  1.68   thorpej 	uint32_t prod, cnt, i;
   1453  1.68   thorpej 	int error;
   1454   1.1  drochner 
   1455   1.1  drochner 	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
   1456   1.1  drochner 		return;
   1457   1.1  drochner 
   1458   1.1  drochner 	prod = r->r_prod;
   1459   1.1  drochner 	cnt = r->r_cnt;
   1460   1.1  drochner 
   1461   1.1  drochner 	while (1) {
   1462  1.68   thorpej 		if (cnt >= TX_ENTRIES - TXP_MAXTXSEGS - 4) {
   1463  1.68   thorpej 			ifp->if_flags |= IFF_OACTIVE;
   1464  1.68   thorpej 			break;
   1465  1.68   thorpej 		}
   1466  1.68   thorpej 
   1467   1.1  drochner 		IFQ_POLL(&ifp->if_snd, m);
   1468   1.1  drochner 		if (m == NULL)
   1469   1.1  drochner 			break;
   1470   1.1  drochner 		mnew = NULL;
   1471   1.1  drochner 
   1472   1.1  drochner 		sd = sc->sc_txd + prod;
   1473   1.1  drochner 
   1474  1.68   thorpej 		/*
   1475  1.68   thorpej 		 * Load the DMA map.  If this fails, the packet either
   1476  1.75    andvar 		 * didn't fit in the allotted number of segments, or we
   1477  1.68   thorpej 		 * were short on resources.  In this case, we'll copy
   1478  1.68   thorpej 		 * and try again.
   1479  1.68   thorpej 		 */
   1480   1.1  drochner 		if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, m,
   1481  1.68   thorpej 		    BUS_DMA_NOWAIT) != 0) {
   1482   1.1  drochner 			MGETHDR(mnew, M_DONTWAIT, MT_DATA);
   1483  1.68   thorpej 			if (mnew == NULL) {
   1484  1.68   thorpej 				printf("%s: unable to allocate Tx mbuf\n",
   1485  1.68   thorpej 				    device_xname(sc->sc_dev));
   1486  1.68   thorpej 				break;
   1487  1.68   thorpej 			}
   1488  1.72   thorpej 			MCLAIM(mnew, &sc->sc_arpcom.ec_tx_mowner);
   1489   1.1  drochner 			if (m->m_pkthdr.len > MHLEN) {
   1490   1.1  drochner 				MCLGET(mnew, M_DONTWAIT);
   1491   1.1  drochner 				if ((mnew->m_flags & M_EXT) == 0) {
   1492  1.68   thorpej 					printf("%s: unable to allocate Tx "
   1493  1.68   thorpej 					    "cluster\n",
   1494  1.68   thorpej 					    device_xname(sc->sc_dev));
   1495   1.1  drochner 					m_freem(mnew);
   1496  1.68   thorpej 					break;
   1497   1.1  drochner 				}
   1498   1.1  drochner 			}
   1499  1.19  christos 			m_copydata(m, 0, m->m_pkthdr.len, mtod(mnew, void *));
   1500   1.1  drochner 			mnew->m_pkthdr.len = mnew->m_len = m->m_pkthdr.len;
   1501  1.68   thorpej 			error = bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map,
   1502  1.68   thorpej 			    mnew, BUS_DMA_NOWAIT);
   1503  1.68   thorpej 			if (error) {
   1504  1.68   thorpej 				printf("%s: unable to load Tx buffer, "
   1505  1.68   thorpej 				    "error = %d\n", device_xname(sc->sc_dev),
   1506  1.68   thorpej 				    error);
   1507  1.68   thorpej 				m_freem(mnew);
   1508  1.68   thorpej 				break;
   1509  1.68   thorpej 			}
   1510  1.68   thorpej 		}
   1511  1.68   thorpej 
   1512  1.68   thorpej 		IFQ_DEQUEUE(&ifp->if_snd, m);
   1513  1.68   thorpej 		if (mnew != NULL) {
   1514   1.1  drochner 			m_freem(m);
   1515   1.1  drochner 			m = mnew;
   1516   1.1  drochner 		}
   1517   1.1  drochner 
   1518  1.68   thorpej 		/*
   1519  1.68   thorpej 		 * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
   1520  1.68   thorpej 		 */
   1521  1.68   thorpej 
   1522  1.68   thorpej 		sd->sd_mbuf = m;
   1523   1.1  drochner 
   1524   1.1  drochner 		txd = r->r_desc + prod;
   1525   1.1  drochner 		txdidx = prod;
   1526   1.1  drochner 		txd->tx_flags = TX_FLAGS_TYPE_DATA;
   1527   1.1  drochner 		txd->tx_numdesc = 0;
   1528  1.72   thorpej 		txd->tx_addrlo = txp_txd_idx(sc, sd);
   1529   1.1  drochner 		txd->tx_addrhi = 0;
   1530   1.1  drochner 		txd->tx_totlen = m->m_pkthdr.len;
   1531   1.1  drochner 		txd->tx_pflags = 0;
   1532   1.1  drochner 		txd->tx_numdesc = sd->sd_map->dm_nsegs;
   1533   1.1  drochner 
   1534   1.1  drochner 		if (++prod == TX_ENTRIES)
   1535   1.1  drochner 			prod = 0;
   1536  1.72   thorpej 		cnt++;
   1537   1.1  drochner 
   1538  1.48  knakahar 		if (vlan_has_tag(m))
   1539   1.1  drochner 			txd->tx_pflags = TX_PFLAGS_VLAN |
   1540  1.48  knakahar 			  (htons(vlan_get_tag(m)) << TX_PFLAGS_VLANTAG_S);
   1541   1.1  drochner 
   1542   1.2  drochner 		if (m->m_pkthdr.csum_flags & M_CSUM_IPv4)
   1543   1.1  drochner 			txd->tx_pflags |= TX_PFLAGS_IPCKSUM;
   1544   1.1  drochner #ifdef TRY_TX_TCP_CSUM
   1545   1.2  drochner 		if (m->m_pkthdr.csum_flags & M_CSUM_TCPv4)
   1546   1.1  drochner 			txd->tx_pflags |= TX_PFLAGS_TCPCKSUM;
   1547   1.1  drochner #endif
   1548   1.1  drochner #ifdef TRY_TX_UDP_CSUM
   1549   1.2  drochner 		if (m->m_pkthdr.csum_flags & M_CSUM_UDPv4)
   1550   1.1  drochner 			txd->tx_pflags |= TX_PFLAGS_UDPCKSUM;
   1551   1.1  drochner #endif
   1552   1.1  drochner 
   1553   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
   1554   1.1  drochner 		    sd->sd_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
   1555   1.1  drochner 
   1556   1.1  drochner 		fxd = (struct txp_frag_desc *)(r->r_desc + prod);
   1557   1.1  drochner 		for (i = 0; i < sd->sd_map->dm_nsegs; i++) {
   1558   1.1  drochner 			fxd->frag_flags = FRAG_FLAGS_TYPE_FRAG |
   1559   1.1  drochner 			    FRAG_FLAGS_VALID;
   1560   1.1  drochner 			fxd->frag_rsvd1 = 0;
   1561  1.65   thorpej 			fxd->frag_len = htole16(sd->sd_map->dm_segs[i].ds_len);
   1562   1.1  drochner 			fxd->frag_addrlo =
   1563  1.65   thorpej 			    htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[i].ds_addr));
   1564   1.1  drochner 			fxd->frag_addrhi =
   1565  1.65   thorpej 			    htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[i].ds_addr));
   1566   1.1  drochner 			fxd->frag_rsvd2 = 0;
   1567   1.1  drochner 
   1568   1.1  drochner 			bus_dmamap_sync(sc->sc_dmat,
   1569   1.1  drochner 			    sc->sc_txhiring_dma.dma_map,
   1570   1.1  drochner 			    prod * sizeof(struct txp_frag_desc),
   1571   1.1  drochner 			    sizeof(struct txp_frag_desc), BUS_DMASYNC_PREWRITE);
   1572   1.1  drochner 
   1573   1.1  drochner 			if (++prod == TX_ENTRIES) {
   1574   1.1  drochner 				fxd = (struct txp_frag_desc *)r->r_desc;
   1575   1.1  drochner 				prod = 0;
   1576   1.1  drochner 			} else
   1577   1.1  drochner 				fxd++;
   1578  1.72   thorpej 			cnt++;
   1579   1.1  drochner 		}
   1580   1.1  drochner 
   1581   1.1  drochner 		ifp->if_timer = 5;
   1582   1.1  drochner 
   1583  1.49   msaitoh 		bpf_mtap(ifp, m, BPF_D_OUT);
   1584   1.1  drochner 
   1585   1.1  drochner 		txd->tx_flags |= TX_FLAGS_VALID;
   1586   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sc->sc_txhiring_dma.dma_map,
   1587   1.1  drochner 		    txdidx * sizeof(struct txp_tx_desc),
   1588   1.1  drochner 		    sizeof(struct txp_tx_desc), BUS_DMASYNC_PREWRITE);
   1589   1.1  drochner 
   1590   1.1  drochner #if 0
   1591   1.1  drochner 		{
   1592   1.1  drochner 			struct mbuf *mx;
   1593   1.1  drochner 			int i;
   1594   1.1  drochner 
   1595   1.1  drochner 			printf("txd: flags 0x%x ndesc %d totlen %d pflags 0x%x\n",
   1596   1.1  drochner 			    txd->tx_flags, txd->tx_numdesc, txd->tx_totlen,
   1597   1.1  drochner 			    txd->tx_pflags);
   1598   1.1  drochner 			for (mx = m; mx != NULL; mx = mx->m_next) {
   1599   1.1  drochner 				for (i = 0; i < mx->m_len; i++) {
   1600   1.1  drochner 					printf(":%02x",
   1601  1.53   msaitoh 					    (uint8_t)m->m_data[i]);
   1602   1.1  drochner 				}
   1603   1.1  drochner 			}
   1604   1.1  drochner 			printf("\n");
   1605   1.1  drochner 		}
   1606   1.1  drochner #endif
   1607   1.1  drochner 
   1608   1.1  drochner 		WRITE_REG(sc, r->r_reg, TXP_IDX2OFFSET(prod));
   1609   1.1  drochner 	}
   1610   1.1  drochner 
   1611   1.1  drochner 	r->r_prod = prod;
   1612   1.1  drochner 	r->r_cnt = cnt;
   1613   1.1  drochner }
   1614   1.1  drochner 
   1615   1.1  drochner /*
   1616   1.1  drochner  * Handle simple commands sent to the typhoon
   1617   1.1  drochner  */
   1618  1.62      maxv static int
   1619  1.53   msaitoh txp_command(struct txp_softc *sc, uint16_t id, uint16_t in1, uint32_t in2,
   1620  1.53   msaitoh     uint32_t in3, uint16_t *out1, uint32_t *out2, uint32_t *out3, int wait)
   1621   1.1  drochner {
   1622   1.1  drochner 	struct txp_rsp_desc *rsp = NULL;
   1623   1.1  drochner 
   1624   1.1  drochner 	if (txp_command2(sc, id, in1, in2, in3, NULL, 0, &rsp, wait))
   1625   1.1  drochner 		return (-1);
   1626   1.1  drochner 
   1627   1.1  drochner 	if (!wait)
   1628   1.1  drochner 		return (0);
   1629   1.1  drochner 
   1630   1.1  drochner 	if (out1 != NULL)
   1631   1.1  drochner 		*out1 = le16toh(rsp->rsp_par1);
   1632   1.1  drochner 	if (out2 != NULL)
   1633   1.1  drochner 		*out2 = le32toh(rsp->rsp_par2);
   1634   1.1  drochner 	if (out3 != NULL)
   1635   1.1  drochner 		*out3 = le32toh(rsp->rsp_par3);
   1636   1.1  drochner 	free(rsp, M_DEVBUF);
   1637   1.1  drochner 	return (0);
   1638   1.1  drochner }
   1639   1.1  drochner 
   1640  1.62      maxv static int
   1641  1.53   msaitoh txp_command2(struct txp_softc *sc, uint16_t id, uint16_t in1, uint32_t in2,
   1642  1.53   msaitoh     uint32_t in3, struct txp_ext_desc *in_extp, uint8_t in_extn,
   1643  1.44   msaitoh     struct txp_rsp_desc **rspp, int wait)
   1644   1.1  drochner {
   1645   1.1  drochner 	struct txp_hostvar *hv = sc->sc_hostvar;
   1646   1.1  drochner 	struct txp_cmd_desc *cmd;
   1647   1.1  drochner 	struct txp_ext_desc *ext;
   1648  1.53   msaitoh 	uint32_t idx, i;
   1649  1.53   msaitoh 	uint16_t seq;
   1650   1.1  drochner 
   1651   1.1  drochner 	if (txp_cmd_desc_numfree(sc) < (in_extn + 1)) {
   1652   1.1  drochner 		printf("%s: no free cmd descriptors\n", TXP_DEVNAME(sc));
   1653   1.1  drochner 		return (-1);
   1654   1.1  drochner 	}
   1655   1.1  drochner 
   1656   1.1  drochner 	idx = sc->sc_cmdring.lastwrite;
   1657  1.53   msaitoh 	cmd = (struct txp_cmd_desc *)(((uint8_t *)sc->sc_cmdring.base) + idx);
   1658  1.32    cegger 	memset(cmd, 0, sizeof(*cmd));
   1659   1.1  drochner 
   1660   1.1  drochner 	cmd->cmd_numdesc = in_extn;
   1661   1.1  drochner 	seq = sc->sc_seq++;
   1662   1.1  drochner 	cmd->cmd_seq = htole16(seq);
   1663   1.1  drochner 	cmd->cmd_id = htole16(id);
   1664   1.1  drochner 	cmd->cmd_par1 = htole16(in1);
   1665   1.1  drochner 	cmd->cmd_par2 = htole32(in2);
   1666   1.1  drochner 	cmd->cmd_par3 = htole32(in3);
   1667   1.1  drochner 	cmd->cmd_flags = CMD_FLAGS_TYPE_CMD |
   1668   1.1  drochner 	    (wait ? CMD_FLAGS_RESP : 0) | CMD_FLAGS_VALID;
   1669   1.1  drochner 
   1670   1.1  drochner 	idx += sizeof(struct txp_cmd_desc);
   1671   1.1  drochner 	if (idx == sc->sc_cmdring.size)
   1672   1.1  drochner 		idx = 0;
   1673   1.1  drochner 
   1674   1.1  drochner 	for (i = 0; i < in_extn; i++) {
   1675  1.53   msaitoh 		ext = (struct txp_ext_desc *)(((uint8_t *)sc->sc_cmdring.base) + idx);
   1676  1.34   tsutsui 		memcpy(ext, in_extp, sizeof(struct txp_ext_desc));
   1677   1.1  drochner 		in_extp++;
   1678   1.1  drochner 		idx += sizeof(struct txp_cmd_desc);
   1679   1.1  drochner 		if (idx == sc->sc_cmdring.size)
   1680   1.1  drochner 			idx = 0;
   1681   1.1  drochner 	}
   1682   1.1  drochner 
   1683   1.1  drochner 	sc->sc_cmdring.lastwrite = idx;
   1684   1.1  drochner 
   1685   1.1  drochner 	WRITE_REG(sc, TXP_H2A_2, sc->sc_cmdring.lastwrite);
   1686   1.1  drochner 	bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
   1687   1.1  drochner 	    sizeof(struct txp_hostvar), BUS_DMASYNC_PREREAD);
   1688   1.1  drochner 
   1689   1.1  drochner 	if (!wait)
   1690   1.1  drochner 		return (0);
   1691   1.1  drochner 
   1692   1.1  drochner 	for (i = 0; i < 10000; i++) {
   1693   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
   1694   1.1  drochner 		    sizeof(struct txp_hostvar), BUS_DMASYNC_POSTREAD);
   1695   1.1  drochner 		idx = le32toh(hv->hv_resp_read_idx);
   1696   1.1  drochner 		if (idx != le32toh(hv->hv_resp_write_idx)) {
   1697   1.1  drochner 			*rspp = NULL;
   1698   1.1  drochner 			if (txp_response(sc, idx, id, seq, rspp))
   1699   1.1  drochner 				return (-1);
   1700   1.1  drochner 			if (*rspp != NULL)
   1701   1.1  drochner 				break;
   1702   1.1  drochner 		}
   1703   1.1  drochner 		bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
   1704   1.1  drochner 		    sizeof(struct txp_hostvar), BUS_DMASYNC_PREREAD);
   1705   1.1  drochner 		DELAY(50);
   1706   1.1  drochner 	}
   1707   1.1  drochner 	if (i == 1000 || (*rspp) == NULL) {
   1708   1.1  drochner 		printf("%s: 0x%x command failed\n", TXP_DEVNAME(sc), id);
   1709   1.1  drochner 		return (-1);
   1710   1.1  drochner 	}
   1711   1.1  drochner 
   1712   1.1  drochner 	return (0);
   1713   1.1  drochner }
   1714   1.1  drochner 
   1715  1.62      maxv static int
   1716  1.53   msaitoh txp_response(struct txp_softc *sc, uint32_t ridx, uint16_t id, uint16_t seq,
   1717  1.44   msaitoh     struct txp_rsp_desc **rspp)
   1718   1.1  drochner {
   1719   1.1  drochner 	struct txp_hostvar *hv = sc->sc_hostvar;
   1720   1.1  drochner 	struct txp_rsp_desc *rsp;
   1721   1.1  drochner 
   1722   1.1  drochner 	while (ridx != le32toh(hv->hv_resp_write_idx)) {
   1723  1.53   msaitoh 		rsp = (struct txp_rsp_desc *)(((uint8_t *)sc->sc_rspring.base) + ridx);
   1724   1.1  drochner 
   1725   1.1  drochner 		if (id == le16toh(rsp->rsp_id) && le16toh(rsp->rsp_seq) == seq) {
   1726   1.1  drochner 			*rspp = (struct txp_rsp_desc *)malloc(
   1727   1.1  drochner 			    sizeof(struct txp_rsp_desc) * (rsp->rsp_numdesc + 1),
   1728   1.1  drochner 			    M_DEVBUF, M_NOWAIT);
   1729   1.1  drochner 			if ((*rspp) == NULL)
   1730   1.1  drochner 				return (-1);
   1731   1.1  drochner 			txp_rsp_fixup(sc, rsp, *rspp);
   1732   1.1  drochner 			return (0);
   1733   1.1  drochner 		}
   1734   1.1  drochner 
   1735   1.1  drochner 		if (rsp->rsp_flags & RSP_FLAGS_ERROR) {
   1736   1.1  drochner 			printf("%s: response error: id 0x%x\n",
   1737   1.1  drochner 			    TXP_DEVNAME(sc), le16toh(rsp->rsp_id));
   1738   1.1  drochner 			txp_rsp_fixup(sc, rsp, NULL);
   1739   1.1  drochner 			ridx = le32toh(hv->hv_resp_read_idx);
   1740   1.1  drochner 			continue;
   1741   1.1  drochner 		}
   1742   1.1  drochner 
   1743   1.1  drochner 		switch (le16toh(rsp->rsp_id)) {
   1744   1.1  drochner 		case TXP_CMD_CYCLE_STATISTICS:
   1745   1.1  drochner 		case TXP_CMD_MEDIA_STATUS_READ:
   1746   1.1  drochner 			break;
   1747   1.1  drochner 		case TXP_CMD_HELLO_RESPONSE:
   1748   1.1  drochner 			printf("%s: hello\n", TXP_DEVNAME(sc));
   1749   1.1  drochner 			break;
   1750   1.1  drochner 		default:
   1751   1.1  drochner 			printf("%s: unknown id(0x%x)\n", TXP_DEVNAME(sc),
   1752   1.1  drochner 			    le16toh(rsp->rsp_id));
   1753   1.1  drochner 		}
   1754   1.1  drochner 
   1755   1.1  drochner 		txp_rsp_fixup(sc, rsp, NULL);
   1756   1.1  drochner 		ridx = le32toh(hv->hv_resp_read_idx);
   1757   1.1  drochner 		hv->hv_resp_read_idx = le32toh(ridx);
   1758   1.1  drochner 	}
   1759   1.1  drochner 
   1760   1.1  drochner 	return (0);
   1761   1.1  drochner }
   1762   1.1  drochner 
   1763  1.62      maxv static void
   1764  1.44   msaitoh txp_rsp_fixup(struct txp_softc *sc, struct txp_rsp_desc *rsp,
   1765  1.44   msaitoh     struct txp_rsp_desc *dst)
   1766   1.1  drochner {
   1767   1.1  drochner 	struct txp_rsp_desc *src = rsp;
   1768   1.1  drochner 	struct txp_hostvar *hv = sc->sc_hostvar;
   1769  1.53   msaitoh 	uint32_t i, ridx;
   1770   1.1  drochner 
   1771   1.1  drochner 	ridx = le32toh(hv->hv_resp_read_idx);
   1772   1.1  drochner 
   1773   1.1  drochner 	for (i = 0; i < rsp->rsp_numdesc + 1; i++) {
   1774   1.1  drochner 		if (dst != NULL)
   1775  1.34   tsutsui 			memcpy(dst++, src, sizeof(struct txp_rsp_desc));
   1776   1.1  drochner 		ridx += sizeof(struct txp_rsp_desc);
   1777   1.1  drochner 		if (ridx == sc->sc_rspring.size) {
   1778   1.1  drochner 			src = sc->sc_rspring.base;
   1779   1.1  drochner 			ridx = 0;
   1780   1.1  drochner 		} else
   1781   1.1  drochner 			src++;
   1782   1.1  drochner 		sc->sc_rspring.lastwrite = ridx;
   1783   1.1  drochner 		hv->hv_resp_read_idx = htole32(ridx);
   1784   1.1  drochner 	}
   1785  1.10     perry 
   1786   1.1  drochner 	hv->hv_resp_read_idx = htole32(ridx);
   1787   1.1  drochner }
   1788   1.1  drochner 
   1789  1.62      maxv static int
   1790  1.29       dsl txp_cmd_desc_numfree(struct txp_softc *sc)
   1791   1.1  drochner {
   1792   1.1  drochner 	struct txp_hostvar *hv = sc->sc_hostvar;
   1793   1.1  drochner 	struct txp_boot_record *br = sc->sc_boot;
   1794  1.53   msaitoh 	uint32_t widx, ridx, nfree;
   1795   1.1  drochner 
   1796   1.1  drochner 	widx = sc->sc_cmdring.lastwrite;
   1797   1.1  drochner 	ridx = le32toh(hv->hv_cmd_read_idx);
   1798   1.1  drochner 
   1799   1.1  drochner 	if (widx == ridx) {
   1800   1.1  drochner 		/* Ring is completely free */
   1801   1.1  drochner 		nfree = le32toh(br->br_cmd_siz) - sizeof(struct txp_cmd_desc);
   1802   1.1  drochner 	} else {
   1803   1.1  drochner 		if (widx > ridx)
   1804   1.1  drochner 			nfree = le32toh(br->br_cmd_siz) -
   1805   1.1  drochner 			    (widx - ridx + sizeof(struct txp_cmd_desc));
   1806   1.1  drochner 		else
   1807   1.1  drochner 			nfree = ridx - widx - sizeof(struct txp_cmd_desc);
   1808   1.1  drochner 	}
   1809   1.1  drochner 
   1810   1.1  drochner 	return (nfree / sizeof(struct txp_cmd_desc));
   1811   1.1  drochner }
   1812   1.1  drochner 
   1813  1.62      maxv static void
   1814  1.29       dsl txp_stop(struct txp_softc *sc)
   1815   1.1  drochner {
   1816   1.1  drochner 	txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
   1817   1.1  drochner 	txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
   1818   1.1  drochner 
   1819   1.1  drochner 	if (callout_pending(&sc->sc_tick))
   1820   1.1  drochner 		callout_stop(&sc->sc_tick);
   1821   1.1  drochner }
   1822   1.1  drochner 
   1823  1.62      maxv static void
   1824  1.18  christos txp_watchdog(struct ifnet *ifp)
   1825   1.1  drochner {
   1826   1.1  drochner }
   1827   1.1  drochner 
   1828  1.62      maxv static int
   1829  1.29       dsl txp_ifmedia_upd(struct ifnet *ifp)
   1830   1.1  drochner {
   1831   1.1  drochner 	struct txp_softc *sc = ifp->if_softc;
   1832   1.1  drochner 	struct ifmedia *ifm = &sc->sc_ifmedia;
   1833  1.53   msaitoh 	uint16_t new_xcvr;
   1834   1.1  drochner 
   1835   1.1  drochner 	if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
   1836   1.1  drochner 		return (EINVAL);
   1837   1.1  drochner 
   1838   1.1  drochner 	if (IFM_SUBTYPE(ifm->ifm_media) == IFM_10_T) {
   1839  1.52   msaitoh 		if ((ifm->ifm_media & IFM_FDX) != 0)
   1840   1.1  drochner 			new_xcvr = TXP_XCVR_10_FDX;
   1841   1.1  drochner 		else
   1842   1.1  drochner 			new_xcvr = TXP_XCVR_10_HDX;
   1843   1.2  drochner 	} else if ((IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) ||
   1844   1.2  drochner 		   (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX)) {
   1845  1.52   msaitoh 		if ((ifm->ifm_media & IFM_FDX) != 0)
   1846   1.1  drochner 			new_xcvr = TXP_XCVR_100_FDX;
   1847   1.1  drochner 		else
   1848   1.1  drochner 			new_xcvr = TXP_XCVR_100_HDX;
   1849   1.1  drochner 	} else if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) {
   1850   1.1  drochner 		new_xcvr = TXP_XCVR_AUTO;
   1851   1.1  drochner 	} else
   1852   1.1  drochner 		return (EINVAL);
   1853   1.1  drochner 
   1854   1.1  drochner 	/* nothing to do */
   1855   1.1  drochner 	if (sc->sc_xcvr == new_xcvr)
   1856   1.1  drochner 		return (0);
   1857   1.1  drochner 
   1858   1.1  drochner 	txp_command(sc, TXP_CMD_XCVR_SELECT, new_xcvr, 0, 0,
   1859   1.1  drochner 	    NULL, NULL, NULL, 0);
   1860   1.1  drochner 	sc->sc_xcvr = new_xcvr;
   1861   1.1  drochner 
   1862   1.1  drochner 	return (0);
   1863   1.1  drochner }
   1864   1.1  drochner 
   1865  1.62      maxv static void
   1866  1.29       dsl txp_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
   1867   1.1  drochner {
   1868   1.1  drochner 	struct txp_softc *sc = ifp->if_softc;
   1869   1.1  drochner 	struct ifmedia *ifm = &sc->sc_ifmedia;
   1870  1.53   msaitoh 	uint16_t bmsr, bmcr, anlpar;
   1871   1.1  drochner 
   1872   1.1  drochner 	ifmr->ifm_status = IFM_AVALID;
   1873   1.1  drochner 	ifmr->ifm_active = IFM_ETHER;
   1874   1.1  drochner 
   1875   1.1  drochner 	if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
   1876   1.1  drochner 	    &bmsr, NULL, NULL, 1))
   1877   1.1  drochner 		goto bail;
   1878   1.1  drochner 	if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
   1879   1.1  drochner 	    &bmsr, NULL, NULL, 1))
   1880   1.1  drochner 		goto bail;
   1881   1.1  drochner 
   1882   1.1  drochner 	if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMCR, 0,
   1883   1.1  drochner 	    &bmcr, NULL, NULL, 1))
   1884   1.1  drochner 		goto bail;
   1885   1.1  drochner 
   1886   1.1  drochner 	if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_ANLPAR, 0,
   1887   1.1  drochner 	    &anlpar, NULL, NULL, 1))
   1888   1.1  drochner 		goto bail;
   1889   1.1  drochner 
   1890   1.1  drochner 	if (bmsr & BMSR_LINK)
   1891   1.1  drochner 		ifmr->ifm_status |= IFM_ACTIVE;
   1892   1.1  drochner 
   1893   1.1  drochner 	if (bmcr & BMCR_ISO) {
   1894   1.1  drochner 		ifmr->ifm_active |= IFM_NONE;
   1895   1.1  drochner 		ifmr->ifm_status = 0;
   1896   1.1  drochner 		return;
   1897   1.1  drochner 	}
   1898   1.1  drochner 
   1899   1.1  drochner 	if (bmcr & BMCR_LOOP)
   1900   1.1  drochner 		ifmr->ifm_active |= IFM_LOOP;
   1901   1.1  drochner 
   1902   1.2  drochner 	if (!(sc->sc_flags & TXP_FIBER) && (bmcr & BMCR_AUTOEN)) {
   1903   1.1  drochner 		if ((bmsr & BMSR_ACOMP) == 0) {
   1904   1.1  drochner 			ifmr->ifm_active |= IFM_NONE;
   1905   1.1  drochner 			return;
   1906   1.1  drochner 		}
   1907   1.1  drochner 
   1908  1.28    cegger 		if (anlpar & ANLPAR_TX_FD)
   1909  1.53   msaitoh 			ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
   1910  1.28    cegger 		else if (anlpar & ANLPAR_T4)
   1911  1.53   msaitoh 			ifmr->ifm_active |= IFM_100_T4 | IFM_HDX;
   1912   1.1  drochner 		else if (anlpar & ANLPAR_TX)
   1913  1.53   msaitoh 			ifmr->ifm_active |= IFM_100_TX | IFM_HDX;
   1914   1.1  drochner 		else if (anlpar & ANLPAR_10_FD)
   1915  1.53   msaitoh 			ifmr->ifm_active |= IFM_10_T | IFM_FDX;
   1916   1.1  drochner 		else if (anlpar & ANLPAR_10)
   1917  1.53   msaitoh 			ifmr->ifm_active |= IFM_10_T | IFM_HDX;
   1918   1.1  drochner 		else
   1919   1.1  drochner 			ifmr->ifm_active |= IFM_NONE;
   1920   1.1  drochner 	} else
   1921   1.1  drochner 		ifmr->ifm_active = ifm->ifm_cur->ifm_media;
   1922   1.1  drochner 	return;
   1923   1.1  drochner 
   1924   1.1  drochner bail:
   1925   1.1  drochner 	ifmr->ifm_active |= IFM_NONE;
   1926   1.1  drochner 	ifmr->ifm_status &= ~IFM_AVALID;
   1927   1.1  drochner }
   1928   1.1  drochner 
   1929  1.62      maxv #if 0 /* XXX XXX XXX UNUSED */
   1930  1.62      maxv static void
   1931  1.29       dsl txp_show_descriptor(void *d)
   1932   1.1  drochner {
   1933   1.1  drochner 	struct txp_cmd_desc *cmd = d;
   1934   1.1  drochner 	struct txp_rsp_desc *rsp = d;
   1935   1.1  drochner 	struct txp_tx_desc *txd = d;
   1936   1.1  drochner 	struct txp_frag_desc *frgd = d;
   1937   1.1  drochner 
   1938   1.1  drochner 	switch (cmd->cmd_flags & CMD_FLAGS_TYPE_M) {
   1939   1.1  drochner 	case CMD_FLAGS_TYPE_CMD:
   1940   1.1  drochner 		/* command descriptor */
   1941  1.53   msaitoh 		printf("[cmd flags 0x%x num %d id %d seq %d par1 0x%x par2 "
   1942  1.53   msaitoh 		    "0x%x par3 0x%x]\n",
   1943   1.1  drochner 		    cmd->cmd_flags, cmd->cmd_numdesc, le16toh(cmd->cmd_id),
   1944   1.1  drochner 		    le16toh(cmd->cmd_seq), le16toh(cmd->cmd_par1),
   1945   1.1  drochner 		    le32toh(cmd->cmd_par2), le32toh(cmd->cmd_par3));
   1946   1.1  drochner 		break;
   1947   1.1  drochner 	case CMD_FLAGS_TYPE_RESP:
   1948   1.1  drochner 		/* response descriptor */
   1949  1.53   msaitoh 		printf("[rsp flags 0x%x num %d id %d seq %d par1 0x%x par2 "
   1950  1.53   msaitoh 		    "0x%x par3 0x%x]\n",
   1951   1.1  drochner 		    rsp->rsp_flags, rsp->rsp_numdesc, le16toh(rsp->rsp_id),
   1952   1.1  drochner 		    le16toh(rsp->rsp_seq), le16toh(rsp->rsp_par1),
   1953   1.1  drochner 		    le32toh(rsp->rsp_par2), le32toh(rsp->rsp_par3));
   1954   1.1  drochner 		break;
   1955   1.1  drochner 	case CMD_FLAGS_TYPE_DATA:
   1956   1.1  drochner 		/* data header (assuming tx for now) */
   1957  1.53   msaitoh 		printf("[data flags 0x%x num %d totlen %d addr 0x%x/0x%x "
   1958  1.53   msaitoh 		    "pflags 0x%x]",
   1959   1.1  drochner 		    txd->tx_flags, txd->tx_numdesc, txd->tx_totlen,
   1960   1.1  drochner 		    txd->tx_addrlo, txd->tx_addrhi, txd->tx_pflags);
   1961   1.1  drochner 		break;
   1962   1.1  drochner 	case CMD_FLAGS_TYPE_FRAG:
   1963   1.1  drochner 		/* fragment descriptor */
   1964  1.53   msaitoh 		printf("[frag flags 0x%x rsvd1 0x%x len %d addr 0x%x/0x%x "
   1965  1.53   msaitoh 		    "rsvd2 0x%x]",
   1966   1.1  drochner 		    frgd->frag_flags, frgd->frag_rsvd1, frgd->frag_len,
   1967   1.1  drochner 		    frgd->frag_addrlo, frgd->frag_addrhi, frgd->frag_rsvd2);
   1968   1.1  drochner 		break;
   1969   1.1  drochner 	default:
   1970  1.53   msaitoh 		printf("[unknown(%x) flags 0x%x num %d id %d seq %d par1 "
   1971  1.53   msaitoh 		    "0x%x par2 0x%x par3 0x%x]\n",
   1972   1.1  drochner 		    cmd->cmd_flags & CMD_FLAGS_TYPE_M,
   1973   1.1  drochner 		    cmd->cmd_flags, cmd->cmd_numdesc, le16toh(cmd->cmd_id),
   1974   1.1  drochner 		    le16toh(cmd->cmd_seq), le16toh(cmd->cmd_par1),
   1975   1.1  drochner 		    le32toh(cmd->cmd_par2), le32toh(cmd->cmd_par3));
   1976   1.1  drochner 		break;
   1977   1.1  drochner 	}
   1978   1.1  drochner }
   1979  1.62      maxv #endif
   1980   1.1  drochner 
   1981  1.62      maxv static void
   1982  1.29       dsl txp_set_filter(struct txp_softc *sc)
   1983   1.1  drochner {
   1984  1.55   msaitoh 	struct ethercom *ec = &sc->sc_arpcom;
   1985   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
   1986  1.53   msaitoh 	uint32_t crc, carry, hashbit, hash[2];
   1987  1.53   msaitoh 	uint16_t filter;
   1988  1.53   msaitoh 	uint8_t octet;
   1989   1.1  drochner 	int i, j, mcnt = 0;
   1990   1.1  drochner 	struct ether_multi *enm;
   1991   1.1  drochner 	struct ether_multistep step;
   1992   1.1  drochner 
   1993   1.1  drochner 	if (ifp->if_flags & IFF_PROMISC) {
   1994   1.1  drochner 		filter = TXP_RXFILT_PROMISC;
   1995   1.1  drochner 		goto setit;
   1996   1.1  drochner 	}
   1997   1.1  drochner 
   1998   1.1  drochner again:
   1999   1.1  drochner 	filter = TXP_RXFILT_DIRECT;
   2000   1.1  drochner 
   2001   1.1  drochner 	if (ifp->if_flags & IFF_BROADCAST)
   2002   1.1  drochner 		filter |= TXP_RXFILT_BROADCAST;
   2003   1.1  drochner 
   2004   1.1  drochner 	if (ifp->if_flags & IFF_ALLMULTI)
   2005   1.1  drochner 		filter |= TXP_RXFILT_ALLMULTI;
   2006   1.1  drochner 	else {
   2007   1.1  drochner 		hash[0] = hash[1] = 0;
   2008   1.1  drochner 
   2009  1.56   msaitoh 		ETHER_LOCK(ec);
   2010  1.55   msaitoh 		ETHER_FIRST_MULTI(step, ec, enm);
   2011   1.1  drochner 		while (enm != NULL) {
   2012  1.44   msaitoh 			if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
   2013  1.44   msaitoh 			    ETHER_ADDR_LEN)) {
   2014   1.1  drochner 				/*
   2015   1.1  drochner 				 * We must listen to a range of multicast
   2016   1.1  drochner 				 * addresses.  For now, just accept all
   2017   1.1  drochner 				 * multicasts, rather than trying to set only
   2018   1.1  drochner 				 * those filter bits needed to match the range.
   2019   1.1  drochner 				 * (At this time, the only use of address
   2020   1.1  drochner 				 * ranges is for IP multicast routing, for
   2021   1.1  drochner 				 * which the range is big enough to require
   2022   1.1  drochner 				 * all bits set.)
   2023   1.1  drochner 				 */
   2024   1.1  drochner 				ifp->if_flags |= IFF_ALLMULTI;
   2025  1.56   msaitoh 				ETHER_UNLOCK(ec);
   2026   1.1  drochner 				goto again;
   2027   1.1  drochner 			}
   2028   1.1  drochner 
   2029   1.1  drochner 			mcnt++;
   2030   1.1  drochner 			crc = 0xffffffff;
   2031   1.1  drochner 
   2032   1.1  drochner 			for (i = 0; i < ETHER_ADDR_LEN; i++) {
   2033   1.1  drochner 				octet = enm->enm_addrlo[i];
   2034   1.1  drochner 				for (j = 0; j < 8; j++) {
   2035   1.1  drochner 					carry = ((crc & 0x80000000) ? 1 : 0) ^
   2036   1.1  drochner 					    (octet & 1);
   2037   1.1  drochner 					crc <<= 1;
   2038   1.1  drochner 					octet >>= 1;
   2039   1.1  drochner 					if (carry)
   2040   1.1  drochner 						crc = (crc ^ TXP_POLYNOMIAL) |
   2041   1.1  drochner 						    carry;
   2042   1.1  drochner 				}
   2043   1.1  drochner 			}
   2044  1.53   msaitoh 			hashbit = (uint16_t)(crc & (64 - 1));
   2045   1.1  drochner 			hash[hashbit / 32] |= (1 << hashbit % 32);
   2046   1.1  drochner 			ETHER_NEXT_MULTI(step, enm);
   2047   1.1  drochner 		}
   2048  1.56   msaitoh 		ETHER_UNLOCK(ec);
   2049   1.1  drochner 
   2050   1.1  drochner 		if (mcnt > 0) {
   2051   1.1  drochner 			filter |= TXP_RXFILT_HASHMULTI;
   2052   1.1  drochner 			txp_command(sc, TXP_CMD_MCAST_HASH_MASK_WRITE,
   2053   1.1  drochner 			    2, hash[0], hash[1], NULL, NULL, NULL, 0);
   2054   1.1  drochner 		}
   2055   1.1  drochner 	}
   2056   1.1  drochner 
   2057   1.1  drochner setit:
   2058   1.1  drochner 	txp_command(sc, TXP_CMD_RX_FILTER_WRITE, filter, 0, 0,
   2059   1.1  drochner 	    NULL, NULL, NULL, 1);
   2060   1.1  drochner }
   2061   1.1  drochner 
   2062  1.62      maxv static void
   2063  1.29       dsl txp_capabilities(struct txp_softc *sc)
   2064   1.1  drochner {
   2065   1.1  drochner 	struct ifnet *ifp = &sc->sc_arpcom.ec_if;
   2066   1.1  drochner 	struct txp_rsp_desc *rsp = NULL;
   2067   1.1  drochner 	struct txp_ext_desc *ext;
   2068   1.1  drochner 
   2069   1.1  drochner 	if (txp_command2(sc, TXP_CMD_OFFLOAD_READ, 0, 0, 0, NULL, 0, &rsp, 1))
   2070   1.1  drochner 		goto out;
   2071   1.1  drochner 
   2072   1.1  drochner 	if (rsp->rsp_numdesc != 1)
   2073   1.1  drochner 		goto out;
   2074   1.1  drochner 	ext = (struct txp_ext_desc *)(rsp + 1);
   2075   1.1  drochner 
   2076   1.1  drochner 	sc->sc_tx_capability = ext->ext_1 & OFFLOAD_MASK;
   2077   1.1  drochner 	sc->sc_rx_capability = ext->ext_2 & OFFLOAD_MASK;
   2078   1.1  drochner 
   2079   1.4  drochner 	sc->sc_arpcom.ec_capabilities |= ETHERCAP_VLAN_MTU;
   2080   1.1  drochner 	if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_VLAN) {
   2081   1.1  drochner 		sc->sc_tx_capability |= OFFLOAD_VLAN;
   2082   1.1  drochner 		sc->sc_rx_capability |= OFFLOAD_VLAN;
   2083   1.4  drochner 		sc->sc_arpcom.ec_capabilities |= ETHERCAP_VLAN_HWTAGGING;
   2084  1.59   msaitoh 		sc->sc_arpcom.ec_capenable |= ETHERCAP_VLAN_HWTAGGING;
   2085   1.1  drochner 	}
   2086   1.1  drochner 
   2087   1.1  drochner #if 0
   2088   1.1  drochner 	/* not ready yet */
   2089   1.1  drochner 	if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPSEC) {
   2090   1.1  drochner 		sc->sc_tx_capability |= OFFLOAD_IPSEC;
   2091   1.1  drochner 		sc->sc_rx_capability |= OFFLOAD_IPSEC;
   2092   1.1  drochner 		ifp->if_capabilities |= IFCAP_IPSEC;
   2093   1.1  drochner 	}
   2094   1.1  drochner #endif
   2095   1.1  drochner 
   2096   1.1  drochner 	if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPCKSUM) {
   2097   1.1  drochner 		sc->sc_tx_capability |= OFFLOAD_IPCKSUM;
   2098   1.1  drochner 		sc->sc_rx_capability |= OFFLOAD_IPCKSUM;
   2099  1.11      yamt 		ifp->if_capabilities |= IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx;
   2100   1.1  drochner 	}
   2101   1.1  drochner 
   2102   1.1  drochner 	if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_TCPCKSUM) {
   2103   1.1  drochner 		sc->sc_rx_capability |= OFFLOAD_TCPCKSUM;
   2104   1.1  drochner #ifdef TRY_TX_TCP_CSUM
   2105   1.1  drochner 		sc->sc_tx_capability |= OFFLOAD_TCPCKSUM;
   2106  1.11      yamt 		ifp->if_capabilities |=
   2107  1.11      yamt 		    IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx;
   2108   1.1  drochner #endif
   2109   1.1  drochner 	}
   2110   1.1  drochner 
   2111   1.1  drochner 	if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_UDPCKSUM) {
   2112   1.1  drochner 		sc->sc_rx_capability |= OFFLOAD_UDPCKSUM;
   2113   1.1  drochner #ifdef TRY_TX_UDP_CSUM
   2114   1.1  drochner 		sc->sc_tx_capability |= OFFLOAD_UDPCKSUM;
   2115  1.11      yamt 		ifp->if_capabilities |=
   2116  1.11      yamt 		    IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx;
   2117   1.1  drochner #endif
   2118   1.1  drochner 	}
   2119   1.1  drochner 
   2120   1.1  drochner 	if (txp_command(sc, TXP_CMD_OFFLOAD_WRITE, 0,
   2121   1.1  drochner 	    sc->sc_tx_capability, sc->sc_rx_capability, NULL, NULL, NULL, 1))
   2122   1.1  drochner 		goto out;
   2123   1.1  drochner 
   2124   1.1  drochner out:
   2125   1.1  drochner 	if (rsp != NULL)
   2126   1.1  drochner 		free(rsp, M_DEVBUF);
   2127   1.1  drochner }
   2128