Home | History | Annotate | Line # | Download | only in isa
if_ec.c revision 1.34
      1  1.34    plunky /*	$NetBSD: if_ec.c,v 1.34 2011/04/24 18:54:41 plunky Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*-
      4   1.5   thorpej  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9   1.1   thorpej  * NASA Ames Research Center.
     10   1.1   thorpej  *
     11   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     12   1.1   thorpej  * modification, are permitted provided that the following conditions
     13   1.1   thorpej  * are met:
     14   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     15   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     16   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     19   1.1   thorpej  *
     20   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21   1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23   1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24   1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31   1.1   thorpej  */
     32   1.1   thorpej 
     33   1.1   thorpej /*
     34   1.1   thorpej  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
     35   1.1   thorpej  * adapters.
     36   1.1   thorpej  *
     37   1.1   thorpej  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
     38   1.1   thorpej  *
     39   1.1   thorpej  * Copyright (C) 1993, David Greenman.  This software may be used, modified,
     40   1.1   thorpej  * copied, distributed, and sold, in both source and binary form provided that
     41   1.1   thorpej  * the above copyright and these terms are retained.  Under no circumstances is
     42   1.1   thorpej  * the author responsible for the proper functioning of this software, nor does
     43   1.1   thorpej  * the author assume any responsibility for damages incurred with its use.
     44   1.1   thorpej  */
     45   1.1   thorpej 
     46   1.1   thorpej /*
     47   1.1   thorpej  * Device driver for the 3Com Etherlink II (3c503).
     48   1.1   thorpej  */
     49  1.15     lukem 
     50  1.15     lukem #include <sys/cdefs.h>
     51  1.34    plunky __KERNEL_RCSID(0, "$NetBSD: if_ec.c,v 1.34 2011/04/24 18:54:41 plunky Exp $");
     52   1.1   thorpej 
     53   1.1   thorpej #include <sys/param.h>
     54   1.1   thorpej #include <sys/systm.h>
     55   1.1   thorpej #include <sys/device.h>
     56   1.1   thorpej #include <sys/socket.h>
     57   1.1   thorpej #include <sys/mbuf.h>
     58   1.1   thorpej #include <sys/syslog.h>
     59   1.1   thorpej 
     60   1.1   thorpej #include <net/if.h>
     61   1.1   thorpej #include <net/if_dl.h>
     62   1.1   thorpej #include <net/if_types.h>
     63   1.1   thorpej #include <net/if_media.h>
     64   1.1   thorpej 
     65   1.1   thorpej #include <net/if_ether.h>
     66   1.1   thorpej 
     67  1.31        ad #include <sys/bus.h>
     68  1.31        ad #include <sys/intr.h>
     69   1.1   thorpej 
     70   1.1   thorpej #include <dev/isa/isareg.h>
     71   1.1   thorpej #include <dev/isa/isavar.h>
     72   1.1   thorpej 
     73   1.1   thorpej #include <dev/ic/dp8390reg.h>
     74   1.1   thorpej #include <dev/ic/dp8390var.h>
     75   1.1   thorpej 
     76   1.1   thorpej #include <dev/isa/if_ecreg.h>
     77   1.1   thorpej 
     78   1.1   thorpej struct ec_softc {
     79   1.1   thorpej 	struct dp8390_softc sc_dp8390;
     80   1.1   thorpej 
     81   1.1   thorpej 	bus_space_tag_t sc_asict;	/* space tag for ASIC */
     82   1.1   thorpej 	bus_space_handle_t sc_asich;	/* space handle for ASIC */
     83   1.1   thorpej 
     84   1.1   thorpej 	int sc_16bitp;			/* are we 16 bit? */
     85   1.1   thorpej 
     86   1.1   thorpej 	void *sc_ih;			/* interrupt handle */
     87   1.1   thorpej };
     88   1.1   thorpej 
     89  1.32      cube int	ec_probe(device_t, cfdata_t, void *);
     90  1.32      cube void	ec_attach(device_t, device_t, void *);
     91   1.1   thorpej 
     92  1.32      cube CFATTACH_DECL_NEW(ec, sizeof(struct ec_softc),
     93  1.19   thorpej     ec_probe, ec_attach, NULL, NULL);
     94   1.1   thorpej 
     95  1.23     perry int	ec_set_media(struct ec_softc *, int);
     96   1.1   thorpej 
     97  1.23     perry void	ec_media_init(struct dp8390_softc *);
     98  1.12   thorpej 
     99  1.23     perry int	ec_mediachange(struct dp8390_softc *);
    100  1.23     perry void	ec_mediastatus(struct dp8390_softc *, struct ifmediareq *);
    101   1.1   thorpej 
    102  1.23     perry void	ec_init_card(struct dp8390_softc *);
    103  1.23     perry int	ec_write_mbuf(struct dp8390_softc *, struct mbuf *, int);
    104  1.30  christos int	ec_ring_copy(struct dp8390_softc *, int, void *, u_short);
    105  1.23     perry void	ec_read_hdr(struct dp8390_softc *, int, struct dp8390_ring *);
    106  1.23     perry int	ec_fake_test_mem(struct dp8390_softc *);
    107  1.23     perry int	ec_test_mem(struct dp8390_softc *);
    108   1.1   thorpej 
    109   1.1   thorpej static const int ec_iobase[] = {
    110   1.1   thorpej 	0x2e0, 0x2a0, 0x280, 0x250, 0x350, 0x330, 0x310, 0x300,
    111   1.1   thorpej };
    112   1.1   thorpej #define	NEC_IOBASE	(sizeof(ec_iobase) / sizeof(ec_iobase[0]))
    113   1.1   thorpej 
    114   1.1   thorpej static const int ec_membase[] = {
    115  1.22  drochner 	-1, -1, -1, -1,
    116  1.22  drochner 	0xc8000, 0xcc000, 0xd8000, 0xdc000,
    117   1.1   thorpej };
    118   1.1   thorpej #define	NEC_MEMBASE	(sizeof(ec_membase) / sizeof(ec_membase[0]))
    119   1.1   thorpej 
    120   1.1   thorpej int
    121  1.32      cube ec_probe(device_t parent, cfdata_t match, void *aux)
    122   1.1   thorpej {
    123   1.1   thorpej 	struct isa_attach_args *ia = aux;
    124   1.1   thorpej 	bus_space_tag_t nict, asict, memt;
    125   1.1   thorpej 	bus_space_handle_t nich, asich, memh;
    126   1.1   thorpej 	bus_size_t memsize;
    127   1.1   thorpej 	int nich_valid, asich_valid, memh_valid;
    128   1.1   thorpej 	int i, rv = 0;
    129   1.1   thorpej 	u_int8_t x;
    130   1.1   thorpej 
    131   1.1   thorpej 	nict = asict = ia->ia_iot;
    132   1.1   thorpej 	memt = ia->ia_memt;
    133   1.1   thorpej 
    134   1.1   thorpej 	nich_valid = asich_valid = memh_valid = 0;
    135   1.1   thorpej 
    136   1.1   thorpej 	/*
    137   1.1   thorpej 	 * Hmm, a 16-bit card has 16k of memory, but only an 8k window
    138   1.1   thorpej 	 * to it.
    139   1.1   thorpej 	 */
    140   1.1   thorpej 	memsize = 8192;
    141   1.1   thorpej 
    142  1.16   thorpej 	if (ia->ia_nio < 1)
    143  1.16   thorpej 		return (0);
    144  1.16   thorpej 	if (ia->ia_niomem < 1)
    145  1.16   thorpej 		return (0);
    146  1.16   thorpej 	if (ia->ia_nirq < 1)
    147  1.16   thorpej 		return (0);
    148  1.16   thorpej 
    149  1.16   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    150  1.16   thorpej 		return (0);
    151  1.16   thorpej 
    152   1.1   thorpej 	/* Disallow wildcarded i/o addresses. */
    153  1.22  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    154   1.1   thorpej 		return (0);
    155   1.1   thorpej 
    156   1.1   thorpej 	/* Disallow wildcarded mem address. */
    157  1.22  drochner 	if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
    158   1.1   thorpej 		return (0);
    159   1.1   thorpej 
    160   1.1   thorpej 	/* Validate the i/o base. */
    161   1.1   thorpej 	for (i = 0; i < NEC_IOBASE; i++)
    162  1.16   thorpej 		if (ia->ia_io[0].ir_addr == ec_iobase[i])
    163   1.1   thorpej 			break;
    164   1.1   thorpej 	if (i == NEC_IOBASE)
    165   1.1   thorpej 		return (0);
    166   1.1   thorpej 
    167   1.1   thorpej 	/* Validate the mem base. */
    168   1.1   thorpej 	for (i = 0; i < NEC_MEMBASE; i++) {
    169  1.22  drochner 		if (ec_membase[i] == -1)
    170   1.1   thorpej 			continue;
    171  1.16   thorpej 		if (ia->ia_iomem[0].ir_addr == ec_membase[i])
    172   1.1   thorpej 			break;
    173   1.1   thorpej 	}
    174   1.1   thorpej 	if (i == NEC_MEMBASE)
    175   1.1   thorpej 		return (0);
    176   1.1   thorpej 
    177   1.1   thorpej 	/* Attempt to map the NIC space. */
    178  1.16   thorpej 	if (bus_space_map(nict, ia->ia_io[0].ir_addr + ELINK2_NIC_OFFSET,
    179   1.1   thorpej 	    ELINK2_NIC_PORTS, 0, &nich))
    180   1.1   thorpej 		goto out;
    181   1.1   thorpej 	nich_valid = 1;
    182   1.1   thorpej 
    183   1.1   thorpej 	/* Attempt to map the ASIC space. */
    184  1.16   thorpej 	if (bus_space_map(asict, ia->ia_io[0].ir_addr + ELINK2_ASIC_OFFSET,
    185   1.1   thorpej 	    ELINK2_ASIC_PORTS, 0, &asich))
    186   1.1   thorpej 		goto out;
    187   1.1   thorpej 	asich_valid = 1;
    188   1.1   thorpej 
    189   1.1   thorpej 	/* Attempt to map the memory space. */
    190  1.16   thorpej 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr, memsize, 0, &memh))
    191   1.1   thorpej 		goto out;
    192   1.1   thorpej 	memh_valid = 1;
    193   1.1   thorpej 
    194   1.1   thorpej 	/*
    195   1.1   thorpej 	 * Verify that the kernel configured I/O address matches the
    196   1.1   thorpej 	 * board configured I/O address.
    197   1.1   thorpej 	 *
    198   1.1   thorpej 	 * This is really only useful to see if something that looks like
    199   1.1   thorpej 	 * the board is there; after all, we're already talking to it at
    200   1.1   thorpej 	 * this point.
    201   1.1   thorpej 	 */
    202   1.1   thorpej 	x = bus_space_read_1(asict, asich, ELINK2_BCFR);
    203   1.1   thorpej 	if (x == 0 || (x & (x - 1)) != 0)
    204   1.1   thorpej 		goto out;
    205   1.1   thorpej 	i = ffs(x) - 1;
    206  1.16   thorpej 	if (ia->ia_io[0].ir_addr != ec_iobase[i])
    207   1.1   thorpej 		goto out;
    208   1.1   thorpej 
    209   1.1   thorpej 	/*
    210   1.1   thorpej 	 * ...and for the memory address.  Note we do not support
    211   1.1   thorpej 	 * cards configured with shared memory disabled.
    212   1.1   thorpej 	 */
    213   1.1   thorpej 	x = bus_space_read_1(asict, asich, ELINK2_PCFR);
    214   1.1   thorpej 	if (x == 0 || (x & (x - 1)) != 0)
    215   1.1   thorpej 		goto out;
    216   1.1   thorpej 	i = ffs(x) - 1;
    217  1.16   thorpej 	if (ia->ia_iomem[0].ir_addr != ec_membase[i])
    218   1.1   thorpej 		goto out;
    219   1.1   thorpej 
    220   1.1   thorpej 	/* So, we say we've found it! */
    221  1.16   thorpej 	ia->ia_nio = 1;		/* XXX Really 2! */
    222  1.16   thorpej 	ia->ia_io[0].ir_size = ELINK2_NIC_PORTS;
    223  1.16   thorpej 
    224  1.16   thorpej 	ia->ia_niomem = 1;
    225  1.16   thorpej 	ia->ia_iomem[0].ir_size = memsize;
    226  1.16   thorpej 
    227  1.16   thorpej 	ia->ia_nirq = 1;
    228  1.16   thorpej 
    229  1.16   thorpej 	ia->ia_ndrq = 0;
    230  1.16   thorpej 
    231   1.1   thorpej 	rv = 1;
    232   1.1   thorpej 
    233   1.1   thorpej  out:
    234   1.1   thorpej 	if (nich_valid)
    235   1.1   thorpej 		bus_space_unmap(nict, nich, ELINK2_NIC_PORTS);
    236   1.1   thorpej 	if (asich_valid)
    237   1.1   thorpej 		bus_space_unmap(asict, asich, ELINK2_ASIC_PORTS);
    238   1.1   thorpej 	if (memh_valid)
    239   1.1   thorpej 		bus_space_unmap(memt, memh, memsize);
    240   1.1   thorpej 	return (rv);
    241   1.1   thorpej }
    242   1.1   thorpej 
    243   1.1   thorpej void
    244  1.32      cube ec_attach(device_t parent, device_t self, void *aux)
    245   1.1   thorpej {
    246  1.32      cube 	struct ec_softc *esc = device_private(self);
    247   1.1   thorpej 	struct dp8390_softc *sc = &esc->sc_dp8390;
    248   1.1   thorpej 	struct isa_attach_args *ia = aux;
    249   1.1   thorpej 	bus_space_tag_t nict, asict, memt;
    250   1.1   thorpej 	bus_space_handle_t nich, asich, memh;
    251   1.1   thorpej 	bus_size_t memsize;
    252   1.1   thorpej 	u_int8_t tmp;
    253   1.1   thorpej 	int i;
    254   1.1   thorpej 
    255  1.32      cube 	sc->sc_dev = self;
    256  1.32      cube 	aprint_normal("\n");
    257   1.1   thorpej 
    258   1.1   thorpej 	nict = asict = ia->ia_iot;
    259   1.1   thorpej 	memt = ia->ia_memt;
    260   1.1   thorpej 
    261   1.1   thorpej 	/*
    262   1.1   thorpej 	 * Hmm, a 16-bit card has 16k of memory, but only an 8k window
    263   1.1   thorpej 	 * to it.
    264   1.1   thorpej 	 */
    265  1.16   thorpej 	memsize = ia->ia_iomem[0].ir_size;
    266   1.1   thorpej 
    267   1.1   thorpej 	/* Map the NIC space. */
    268  1.16   thorpej 	if (bus_space_map(nict, ia->ia_io[0].ir_addr + ELINK2_NIC_OFFSET,
    269   1.1   thorpej 	    ELINK2_NIC_PORTS, 0, &nich)) {
    270  1.32      cube 		aprint_error_dev(self, "can't map nic i/o space\n");
    271   1.1   thorpej 		return;
    272   1.1   thorpej 	}
    273   1.1   thorpej 
    274   1.1   thorpej 	/* Map the ASIC space. */
    275  1.16   thorpej 	if (bus_space_map(asict, ia->ia_io[0].ir_addr + ELINK2_ASIC_OFFSET,
    276   1.1   thorpej 	    ELINK2_ASIC_PORTS, 0, &asich)) {
    277  1.32      cube 		aprint_error_dev(self, "can't map asic i/o space\n");
    278   1.1   thorpej 		return;
    279   1.1   thorpej 	}
    280   1.1   thorpej 
    281   1.1   thorpej 	/* Map the memory space. */
    282  1.16   thorpej 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr, memsize, 0, &memh)) {
    283  1.32      cube 		aprint_error_dev(self, "can't map shared memory\n");
    284   1.1   thorpej 		return;
    285   1.1   thorpej 	}
    286   1.1   thorpej 
    287   1.1   thorpej 	esc->sc_asict = asict;
    288   1.1   thorpej 	esc->sc_asich = asich;
    289   1.1   thorpej 
    290   1.1   thorpej 	sc->sc_regt = nict;
    291   1.1   thorpej 	sc->sc_regh = nich;
    292   1.1   thorpej 
    293   1.1   thorpej 	sc->sc_buft = memt;
    294   1.1   thorpej 	sc->sc_bufh = memh;
    295   1.1   thorpej 
    296   1.1   thorpej 	/* Interface is always enabled. */
    297   1.1   thorpej 	sc->sc_enabled = 1;
    298   1.1   thorpej 
    299   1.1   thorpej 	/* Registers are linear. */
    300   1.1   thorpej 	for (i = 0; i < 16; i++)
    301   1.1   thorpej 		sc->sc_reg_map[i] = i;
    302   1.1   thorpej 
    303   1.1   thorpej 	/* Now we can use the NIC_{GET,PUT}() macros. */
    304   1.1   thorpej 
    305   1.1   thorpej 	/*
    306   1.1   thorpej 	 * Reset NIC and ASIC.  Enable on-board transeiver throughout
    307   1.1   thorpej 	 * reset sequence since it will lock up if the cable isn't
    308   1.1   thorpej 	 * connected if we don't.
    309   1.1   thorpej 	 */
    310   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_CR,
    311   1.1   thorpej 	    ELINK2_CR_RST | ELINK2_CR_XSEL);
    312   1.1   thorpej 
    313   1.1   thorpej 	/* Wait for a while, then un-reset it. */
    314   1.1   thorpej 	delay(50);
    315   1.1   thorpej 
    316   1.1   thorpej 	/*
    317   1.1   thorpej 	 * The 3Com ASIC defaults to rather strange settings for the CR
    318   1.1   thorpej 	 * after a reset.  It's important to set it again after the
    319   1.1   thorpej 	 * following write (this is done when we map the PROM below).
    320   1.1   thorpej 	 */
    321   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_CR, ELINK2_CR_XSEL);
    322   1.1   thorpej 
    323   1.1   thorpej 	/* Wait a bit for the NIC to recover from the reset. */
    324   1.1   thorpej 	delay(5000);
    325   1.1   thorpej 
    326   1.1   thorpej 	/*
    327   1.1   thorpej 	 * Get the station address from on-board ROM.
    328   1.1   thorpej 	 *
    329   1.1   thorpej 	 * First, map Ethernet address PROM over the top of where the NIC
    330   1.1   thorpej 	 * registers normally appear.
    331   1.1   thorpej 	 */
    332   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_CR,
    333   1.1   thorpej 	    ELINK2_CR_XSEL | ELINK2_CR_EALO);
    334   1.1   thorpej 
    335   1.1   thorpej 	for (i = 0; i < ETHER_ADDR_LEN; i++)
    336   1.1   thorpej 		sc->sc_enaddr[i] = NIC_GET(nict, nich, i);
    337   1.1   thorpej 
    338   1.1   thorpej 	/*
    339   1.1   thorpej 	 * Unmap PROM - select NIC registers.  The proper setting of the
    340  1.13       wiz 	 * transceiver is set in later in ec_init_card() via dp8390_init().
    341   1.1   thorpej 	 */
    342   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_CR, ELINK2_CR_XSEL);
    343   1.1   thorpej 
    344   1.1   thorpej 	/* Determine if this is an 8-bit or 16-bit board. */
    345   1.1   thorpej 
    346   1.1   thorpej 	/* Select page 0 registers. */
    347   1.1   thorpej 	NIC_PUT(nict, nich, ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STP);
    348   1.1   thorpej 
    349   1.1   thorpej 	/*
    350   1.1   thorpej 	 * Attempt to clear WTS.  If it doesn't clear, then this is a
    351   1.1   thorpej 	 * 16-bit board.
    352   1.1   thorpej 	 */
    353   1.1   thorpej 	NIC_PUT(nict, nich, ED_P0_DCR, 0);
    354   1.1   thorpej 
    355   1.1   thorpej 	/* Select page 2 registers. */
    356   1.1   thorpej 	NIC_PUT(nict, nich, ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_2 | ED_CR_STP);
    357   1.1   thorpej 
    358   1.1   thorpej 	/* The 3c503 forces the WTS bit to a one if this is a 16-bit board. */
    359   1.1   thorpej 	if (NIC_GET(nict, nich, ED_P2_DCR) & ED_DCR_WTS)
    360   1.1   thorpej 		esc->sc_16bitp = 1;
    361   1.1   thorpej 	else
    362   1.1   thorpej 		esc->sc_16bitp = 0;
    363   1.1   thorpej 
    364  1.32      cube 	aprint_normal_dev(self, "3Com 3c503 Ethernet (%s-bit)\n",
    365  1.32      cube 	    esc->sc_16bitp ? "16" : "8");
    366   1.1   thorpej 
    367   1.1   thorpej 	/* Select page 0 registers. */
    368   1.1   thorpej 	NIC_PUT(nict, nich, ED_P2_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STP);
    369   1.1   thorpej 
    370   1.1   thorpej 	sc->cr_proto = ED_CR_RD2;
    371   1.1   thorpej 
    372   1.1   thorpej 	/*
    373   1.1   thorpej 	 * DCR gets:
    374   1.1   thorpej 	 *
    375   1.1   thorpej 	 *	FIFO threshold to 8, No auto-init Remote DMA,
    376   1.1   thorpej 	 *	byte order=80x86.
    377   1.1   thorpej 	 *
    378   1.1   thorpej 	 * 16-bit cards also get word-wide DMA transfers.
    379   1.1   thorpej 	 */
    380   1.1   thorpej 	sc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS |
    381   1.1   thorpej 	    (esc->sc_16bitp ? ED_DCR_WTS : 0);
    382   1.1   thorpej 
    383   1.1   thorpej 	sc->test_mem = ec_fake_test_mem;
    384   1.1   thorpej 	sc->ring_copy = ec_ring_copy;
    385   1.1   thorpej 	sc->write_mbuf = ec_write_mbuf;
    386   1.1   thorpej 	sc->read_hdr = ec_read_hdr;
    387  1.10   thorpej 	sc->init_card = ec_init_card;
    388   1.1   thorpej 
    389  1.12   thorpej 	sc->sc_media_init = ec_media_init;
    390  1.12   thorpej 
    391   1.1   thorpej 	sc->sc_mediachange = ec_mediachange;
    392   1.1   thorpej 	sc->sc_mediastatus = ec_mediastatus;
    393   1.1   thorpej 
    394   1.1   thorpej 	sc->mem_start = 0;
    395   1.1   thorpej 	sc->mem_size = memsize;
    396   1.1   thorpej 
    397   1.1   thorpej 	/* Do generic parts of attach. */
    398  1.12   thorpej 	if (dp8390_config(sc)) {
    399  1.32      cube 		aprint_error_dev(self, " configuration failed\n");
    400   1.1   thorpej 		return;
    401   1.1   thorpej 	}
    402   1.1   thorpej 
    403   1.1   thorpej 	/*
    404   1.1   thorpej 	 * We need to override the way dp8390_config() set up our
    405   1.1   thorpej 	 * shared memory.
    406   1.1   thorpej 	 *
    407   1.1   thorpej 	 * We have an entire 8k window to put the transmit buffers on the
    408   1.1   thorpej 	 * 16-bit boards.  But since the 16bit 3c503's shared memory is only
    409   1.1   thorpej 	 * fast enough to overlap the loading of one full-size packet, trying
    410   1.1   thorpej 	 * to load more than 2 buffers can actually leave the transmitter idle
    411   1.1   thorpej 	 * during the load.  So 2 seems the best value.  (Although a mix of
    412   1.1   thorpej 	 * variable-sized packets might change this assumption.  Nonetheless,
    413   1.1   thorpej 	 * we optimize for linear transfers of same-size packets.)
    414   1.1   thorpej 	 */
    415   1.1   thorpej 	if (esc->sc_16bitp) {
    416  1.32      cube 		if (device_cfdata(sc->sc_dev)->cf_flags &
    417  1.27   thorpej 		    DP8390_NO_MULTI_BUFFERING)
    418   1.1   thorpej 			sc->txb_cnt = 1;
    419   1.1   thorpej 		else
    420   1.1   thorpej 			sc->txb_cnt = 2;
    421   1.1   thorpej 
    422   1.1   thorpej 		sc->tx_page_start = ELINK2_TX_PAGE_OFFSET_16BIT;
    423   1.1   thorpej 		sc->rec_page_start = ELINK2_RX_PAGE_OFFSET_16BIT;
    424  1.24     perry 		sc->rec_page_stop = (memsize >> ED_PAGE_SHIFT) +
    425   1.1   thorpej 		    sc->rec_page_start;
    426   1.1   thorpej 		sc->mem_ring = sc->mem_start;
    427   1.1   thorpej 	} else {
    428   1.1   thorpej 		sc->txb_cnt = 1;
    429   1.1   thorpej 		sc->tx_page_start = ELINK2_TX_PAGE_OFFSET_8BIT;
    430   1.1   thorpej 		sc->rec_page_start = sc->tx_page_start + ED_TXBUF_SIZE;
    431   1.1   thorpej 		sc->rec_page_stop = (memsize >> ED_PAGE_SHIFT) +
    432   1.1   thorpej 		    sc->tx_page_start;
    433   1.1   thorpej 		sc->mem_ring = sc->mem_start +
    434   1.1   thorpej 		    (ED_TXBUF_SIZE << ED_PAGE_SHIFT);
    435   1.1   thorpej 	}
    436   1.1   thorpej 
    437   1.1   thorpej 	/*
    438   1.1   thorpej 	 * Initialize CA page start/stop registers.  Probably only needed
    439   1.1   thorpej 	 * if doing DMA, but what the Hell.
    440   1.1   thorpej 	 */
    441   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_PSTR, sc->rec_page_start);
    442   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_PSPR, sc->rec_page_stop);
    443   1.1   thorpej 
    444   1.1   thorpej 	/*
    445   1.1   thorpej 	 * Program the IRQ.
    446   1.1   thorpej 	 */
    447  1.16   thorpej 	switch (ia->ia_irq[0].ir_irq) {
    448   1.1   thorpej 	case 9:	tmp = ELINK2_IDCFR_IRQ2; break;
    449   1.1   thorpej 	case 3:	tmp = ELINK2_IDCFR_IRQ3; break;
    450   1.1   thorpej 	case 4:	tmp = ELINK2_IDCFR_IRQ4; break;
    451   1.1   thorpej 	case 5:	tmp = ELINK2_IDCFR_IRQ5; break;
    452   1.1   thorpej 		break;
    453   1.1   thorpej 
    454  1.22  drochner 	case ISA_UNKNOWN_IRQ:
    455  1.32      cube 		aprint_error_dev(self, "wildcarded IRQ is not allowed\n");
    456   1.1   thorpej 		return;
    457   1.1   thorpej 
    458   1.1   thorpej 	default:
    459  1.32      cube 		aprint_error_dev(self, "invalid IRQ %d, must be 3, 4, 5, "
    460  1.32      cube 		    "or 9\n", ia->ia_irq[0].ir_irq);
    461   1.1   thorpej 		return;
    462   1.1   thorpej 	}
    463   1.1   thorpej 
    464   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_IDCFR, tmp);
    465   1.1   thorpej 
    466   1.1   thorpej 	/*
    467   1.1   thorpej 	 * Initialize the GA configuration register.  Set bank and enable
    468   1.1   thorpej 	 * shared memory.
    469   1.1   thorpej 	 */
    470   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_GACFR,
    471   1.1   thorpej 	    ELINK2_GACFR_RSEL | ELINK2_GACFR_MBS0);
    472   1.1   thorpej 
    473   1.1   thorpej 	/*
    474   1.1   thorpej 	 * Intialize "Vector Pointer" registers.  These gawd-awful things
    475   1.1   thorpej 	 * are compared to 20 bits of the address on the ISA, and if they
    476  1.21       wiz 	 * match, the shared memory is disabled.  We set them to 0xffff0...
    477   1.1   thorpej 	 * allegedly the reset vector.
    478   1.1   thorpej 	 */
    479   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_VPTR2, 0xff);
    480   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_VPTR1, 0xff);
    481   1.1   thorpej 	bus_space_write_1(asict, asich, ELINK2_VPTR0, 0x00);
    482   1.1   thorpej 
    483   1.1   thorpej 	/*
    484   1.1   thorpej 	 * Now run the real memory test.
    485   1.1   thorpej 	 */
    486   1.1   thorpej 	if (ec_test_mem(sc)) {
    487  1.32      cube 		aprint_error_dev(self, "memory test failed\n");
    488   1.1   thorpej 		return;
    489   1.1   thorpej 	}
    490   1.1   thorpej 
    491   1.1   thorpej 	/* Establish interrupt handler. */
    492  1.16   thorpej 	esc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    493  1.16   thorpej 	    IST_EDGE, IPL_NET, dp8390_intr, sc);
    494   1.1   thorpej 	if (esc->sc_ih == NULL)
    495  1.32      cube 		aprint_error_dev(self, "can't establish interrupt\n");
    496   1.1   thorpej }
    497   1.1   thorpej 
    498   1.1   thorpej int
    499  1.29  christos ec_fake_test_mem(struct dp8390_softc *sc)
    500   1.1   thorpej {
    501   1.1   thorpej 
    502   1.1   thorpej 	/*
    503   1.1   thorpej 	 * We have to do this after we initialize the GA, but we
    504   1.1   thorpej 	 * have to do that after calling dp8390_config(), which
    505   1.1   thorpej 	 * wants to test memory.  Put this noop here, and then
    506   1.1   thorpej 	 * actually test memory later.
    507   1.1   thorpej 	 */
    508   1.1   thorpej 	return (0);
    509   1.1   thorpej }
    510   1.1   thorpej 
    511   1.1   thorpej int
    512  1.32      cube ec_test_mem(struct dp8390_softc *sc)
    513   1.1   thorpej {
    514   1.1   thorpej 	struct ec_softc *esc = (struct ec_softc *)sc;
    515   1.1   thorpej 	bus_space_tag_t memt = sc->sc_buft;
    516   1.1   thorpej 	bus_space_handle_t memh = sc->sc_bufh;
    517   1.1   thorpej 	bus_size_t memsize = sc->mem_size;
    518   1.1   thorpej 	int i;
    519   1.1   thorpej 
    520   1.1   thorpej 	if (esc->sc_16bitp)
    521   1.1   thorpej 		bus_space_set_region_2(memt, memh, 0, 0, memsize >> 1);
    522   1.1   thorpej 	else
    523   1.1   thorpej 		bus_space_set_region_1(memt, memh, 0, 0, memsize);
    524   1.1   thorpej 
    525   1.1   thorpej 	if (esc->sc_16bitp) {
    526   1.1   thorpej 		for (i = 0; i < memsize; i += 2) {
    527   1.1   thorpej 			if (bus_space_read_2(memt, memh, i) != 0)
    528   1.1   thorpej 				goto fail;
    529   1.1   thorpej 		}
    530   1.1   thorpej 	} else {
    531   1.1   thorpej 		for (i = 0; i < memsize; i++) {
    532   1.1   thorpej 			if (bus_space_read_1(memt, memh, i) != 0)
    533   1.1   thorpej 				goto fail;
    534   1.1   thorpej 		}
    535   1.1   thorpej 	}
    536   1.1   thorpej 
    537   1.1   thorpej 	return (0);
    538   1.1   thorpej 
    539   1.1   thorpej  fail:
    540  1.32      cube 	aprint_error_dev(sc->sc_dev,
    541  1.32      cube 	    "failed to clear shared memory at offset 0x%x\n", i);
    542   1.1   thorpej 	return (1);
    543   1.1   thorpej }
    544   1.1   thorpej 
    545   1.7   thorpej /*
    546   1.7   thorpej  * Given a NIC memory source address and a host memory destination address,
    547   1.7   thorpej  * copy 'len' from NIC to host using shared memory.  The 'len' is rounded
    548   1.7   thorpej  * up to a word - ok as long as mbufs are word-sized.
    549   1.7   thorpej  */
    550  1.34    plunky static inline void
    551  1.32      cube ec_readmem(struct ec_softc *esc, int from, uint8_t *to, int len)
    552   1.1   thorpej {
    553   1.1   thorpej 	bus_space_tag_t memt = esc->sc_dp8390.sc_buft;
    554   1.1   thorpej 	bus_space_handle_t memh = esc->sc_dp8390.sc_bufh;
    555   1.1   thorpej 
    556   1.7   thorpej 	if (len & 1)
    557   1.7   thorpej 		++len;
    558   1.7   thorpej 
    559   1.7   thorpej 	if (esc->sc_16bitp)
    560   1.1   thorpej 		bus_space_read_region_2(memt, memh, from, (u_int16_t *)to,
    561   1.1   thorpej 		    len >> 1);
    562   1.7   thorpej 	else
    563   1.1   thorpej 		bus_space_read_region_1(memt, memh, from, to, len);
    564   1.1   thorpej }
    565   1.1   thorpej 
    566   1.1   thorpej int
    567  1.32      cube ec_write_mbuf(struct dp8390_softc *sc, struct mbuf *m, int buf)
    568   1.1   thorpej {
    569   1.1   thorpej 	struct ec_softc *esc = (struct ec_softc *)sc;
    570   1.1   thorpej 	bus_space_tag_t asict = esc->sc_asict;
    571   1.1   thorpej 	bus_space_handle_t asich = esc->sc_asich;
    572   1.7   thorpej 	bus_space_tag_t memt = esc->sc_dp8390.sc_buft;
    573   1.7   thorpej 	bus_space_handle_t memh = esc->sc_dp8390.sc_bufh;
    574   1.7   thorpej 	u_int8_t *data, savebyte[2];
    575   1.7   thorpej 	int savelen, len, leftover;
    576   1.7   thorpej #ifdef DIAGNOSTIC
    577   1.7   thorpej 	u_int8_t *lim;
    578   1.7   thorpej #endif
    579   1.1   thorpej 
    580   1.1   thorpej 	savelen = m->m_pkthdr.len;
    581   1.1   thorpej 
    582   1.1   thorpej 	/*
    583   1.7   thorpej 	 * 8-bit boards are simple: we're already in the correct
    584   1.7   thorpej 	 * page, and no alignment tricks are necessary.
    585   1.7   thorpej 	 */
    586   1.7   thorpej 	if (esc->sc_16bitp == 0) {
    587   1.7   thorpej 		for (; m != NULL; buf += m->m_len, m = m->m_next)
    588   1.7   thorpej 			bus_space_write_region_1(memt, memh, buf,
    589   1.7   thorpej 			    mtod(m, u_int8_t *), m->m_len);
    590  1.20    bouyer 		if (savelen < ETHER_MIN_LEN - ETHER_CRC_LEN) {
    591  1.20    bouyer 			bus_space_set_region_1(memt, memh, buf,
    592  1.20    bouyer 			    0, ETHER_MIN_LEN - ETHER_CRC_LEN - savelen);
    593  1.20    bouyer 			savelen = ETHER_MIN_LEN - ETHER_CRC_LEN;
    594  1.20    bouyer 		}
    595   1.7   thorpej 		return (savelen);
    596   1.7   thorpej 	}
    597   1.7   thorpej 
    598   1.7   thorpej 	/*
    599   1.1   thorpej 	 * If it's a 16-bit board, we have transmit buffers
    600   1.1   thorpej 	 * in a different page; switch to it.
    601   1.1   thorpej 	 */
    602   1.1   thorpej 	if (esc->sc_16bitp)
    603   1.1   thorpej 		bus_space_write_1(asict, asich, ELINK2_GACFR,
    604   1.1   thorpej 		    ELINK2_GACFR_RSEL);
    605   1.1   thorpej 
    606   1.7   thorpej 	/* Start out with no leftover data. */
    607   1.7   thorpej 	leftover = 0;
    608   1.7   thorpej 	savebyte[0] = savebyte[1] = 0;
    609   1.7   thorpej 
    610   1.7   thorpej 	for (; m != NULL; m = m->m_next) {
    611   1.7   thorpej 		len = m->m_len;
    612   1.7   thorpej 		if (len == 0)
    613   1.7   thorpej 			continue;
    614   1.7   thorpej 		data = mtod(m, u_int8_t *);
    615   1.7   thorpej #ifdef DIAGNOSTIC
    616   1.7   thorpej 		lim = data + len;
    617   1.7   thorpej #endif
    618   1.7   thorpej 		while (len > 0) {
    619   1.7   thorpej 			if (leftover) {
    620   1.7   thorpej 				/*
    621   1.7   thorpej 				 * Data left over (from mbuf or realignment).
    622   1.7   thorpej 				 * Buffer the next byte, and write it and
    623   1.7   thorpej 				 * the leftover data out.
    624   1.7   thorpej 				 */
    625   1.7   thorpej 				savebyte[1] = *data++;
    626   1.7   thorpej 				len--;
    627   1.7   thorpej 				bus_space_write_2(memt, memh, buf,
    628   1.7   thorpej 				    *(u_int16_t *)savebyte);
    629   1.7   thorpej 				buf += 2;
    630   1.7   thorpej 				leftover = 0;
    631  1.11  drochner 			} else if (BUS_SPACE_ALIGNED_POINTER(data, u_int16_t)
    632  1.11  drochner 				   == 0) {
    633   1.7   thorpej 				/*
    634   1.7   thorpej 				 * Unaligned data; buffer the next byte.
    635   1.7   thorpej 				 */
    636   1.7   thorpej 				savebyte[0] = *data++;
    637   1.7   thorpej 				len--;
    638   1.7   thorpej 				leftover = 1;
    639   1.7   thorpej 			} else {
    640   1.7   thorpej 				/*
    641   1.7   thorpej 				 * Aligned data; output contiguous words as
    642   1.7   thorpej 				 * much as we can, then buffer the remaining
    643   1.7   thorpej 				 * byte, if any.
    644   1.7   thorpej 				 */
    645   1.7   thorpej 				leftover = len & 1;
    646   1.7   thorpej 				len &= ~1;
    647   1.7   thorpej 				bus_space_write_region_2(memt, memh, buf,
    648   1.7   thorpej 				    (u_int16_t *)data, len >> 1);
    649   1.7   thorpej 				data += len;
    650   1.7   thorpej 				buf += len;
    651   1.7   thorpej 				if (leftover)
    652   1.7   thorpej 					savebyte[0] = *data++;
    653   1.7   thorpej 				len = 0;
    654   1.7   thorpej 			}
    655   1.7   thorpej 		}
    656   1.7   thorpej 		if (len < 0)
    657   1.7   thorpej 			panic("ec_write_mbuf: negative len");
    658   1.7   thorpej #ifdef DIAGNOSTIC
    659   1.7   thorpej 		if (data != lim)
    660   1.7   thorpej 			panic("ec_write_mbuf: data != lim");
    661   1.7   thorpej #endif
    662   1.7   thorpej 	}
    663   1.7   thorpej 	if (leftover) {
    664   1.7   thorpej 		savebyte[1] = 0;
    665   1.7   thorpej 		bus_space_write_2(memt, memh, buf, *(u_int16_t *)savebyte);
    666  1.20    bouyer 		buf += 2;
    667  1.20    bouyer 	}
    668  1.20    bouyer 	if (savelen < ETHER_MIN_LEN - ETHER_CRC_LEN) {
    669  1.20    bouyer 		bus_space_set_region_2(memt, memh, buf,
    670  1.20    bouyer 		    0, (ETHER_MIN_LEN - ETHER_CRC_LEN - savelen) >> 1);
    671  1.20    bouyer 		savelen = ETHER_MIN_LEN - ETHER_CRC_LEN;
    672   1.7   thorpej 	}
    673   1.1   thorpej 
    674   1.1   thorpej 	/*
    675   1.1   thorpej 	 * Switch back to receive page.
    676   1.1   thorpej 	 */
    677   1.1   thorpej 	if (esc->sc_16bitp)
    678   1.1   thorpej 		bus_space_write_1(asict, asich, ELINK2_GACFR,
    679   1.1   thorpej 		    ELINK2_GACFR_RSEL | ELINK2_GACFR_MBS0);
    680  1.24     perry 
    681   1.1   thorpej 	return (savelen);
    682   1.1   thorpej }
    683   1.1   thorpej 
    684   1.1   thorpej int
    685  1.32      cube ec_ring_copy(struct dp8390_softc *sc, int src, void *dst, u_short amount)
    686   1.1   thorpej {
    687   1.1   thorpej 	struct ec_softc *esc = (struct ec_softc *)sc;
    688   1.1   thorpej 	u_short tmp_amount;
    689   1.1   thorpej 
    690   1.1   thorpej 	/* Does copy wrap to lower addr in ring buffer? */
    691   1.1   thorpej 	if (src + amount > sc->mem_end) {
    692   1.1   thorpej 		tmp_amount = sc->mem_end - src;
    693   1.1   thorpej 
    694   1.1   thorpej 		/* Copy amount up to end of NIC memory. */
    695   1.1   thorpej 		ec_readmem(esc, src, dst, tmp_amount);
    696   1.1   thorpej 
    697   1.1   thorpej 		amount -= tmp_amount;
    698   1.1   thorpej 		src = sc->mem_ring;
    699  1.30  christos 		dst = (char *)dst + tmp_amount;
    700   1.1   thorpej 	}
    701   1.1   thorpej 
    702   1.1   thorpej 	ec_readmem(esc, src, dst, amount);
    703   1.1   thorpej 
    704   1.1   thorpej 	return (src + amount);
    705   1.1   thorpej }
    706   1.1   thorpej 
    707   1.1   thorpej void
    708  1.32      cube ec_read_hdr(struct dp8390_softc *sc, int packet_ptr,
    709  1.32      cube     struct dp8390_ring *packet_hdrp)
    710   1.1   thorpej {
    711   1.1   thorpej 	struct ec_softc *esc = (struct ec_softc *)sc;
    712   1.1   thorpej 
    713   1.1   thorpej 	ec_readmem(esc, packet_ptr, (u_int8_t *)packet_hdrp,
    714   1.1   thorpej 	    sizeof(struct dp8390_ring));
    715   1.4   thorpej #if BYTE_ORDER == BIG_ENDIAN
    716   1.4   thorpej 	packet_hdrp->count = bswap16(packet_hdrp->count);
    717   1.4   thorpej #endif
    718  1.12   thorpej }
    719  1.12   thorpej 
    720  1.12   thorpej void
    721  1.12   thorpej ec_media_init(struct dp8390_softc *sc)
    722  1.12   thorpej {
    723  1.12   thorpej 
    724  1.12   thorpej 	ifmedia_init(&sc->sc_media, 0, dp8390_mediachange, dp8390_mediastatus);
    725  1.12   thorpej 	ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_10_2, 0, NULL);
    726  1.12   thorpej 	ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_10_5, 0, NULL);
    727  1.12   thorpej 	ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_10_2);
    728   1.1   thorpej }
    729   1.1   thorpej 
    730   1.1   thorpej int
    731  1.32      cube ec_mediachange(struct dp8390_softc *sc)
    732   1.1   thorpej {
    733   1.1   thorpej 	struct ec_softc *esc = (struct ec_softc *)sc;
    734   1.1   thorpej 	struct ifmedia *ifm = &sc->sc_media;
    735   1.1   thorpej 
    736   1.1   thorpej 	return (ec_set_media(esc, ifm->ifm_media));
    737   1.1   thorpej }
    738   1.1   thorpej 
    739   1.1   thorpej void
    740  1.32      cube ec_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr)
    741   1.1   thorpej {
    742   1.1   thorpej 	struct ifmedia *ifm = &sc->sc_media;
    743   1.1   thorpej 
    744   1.1   thorpej 	/*
    745   1.1   thorpej 	 * The currently selected media is always the active media.
    746   1.1   thorpej 	 */
    747   1.1   thorpej 	ifmr->ifm_active = ifm->ifm_cur->ifm_media;
    748   1.1   thorpej }
    749   1.1   thorpej 
    750   1.1   thorpej void
    751  1.32      cube ec_init_card(struct dp8390_softc *sc)
    752   1.1   thorpej {
    753   1.1   thorpej 	struct ec_softc *esc = (struct ec_softc *)sc;
    754   1.1   thorpej 	struct ifmedia *ifm = &sc->sc_media;
    755   1.1   thorpej 
    756   1.1   thorpej 	(void) ec_set_media(esc, ifm->ifm_cur->ifm_media);
    757   1.1   thorpej }
    758   1.1   thorpej 
    759   1.1   thorpej int
    760  1.32      cube ec_set_media(struct ec_softc *esc, int media)
    761   1.1   thorpej {
    762   1.1   thorpej 	u_int8_t new;
    763   1.1   thorpej 
    764   1.1   thorpej 	if (IFM_TYPE(media) != IFM_ETHER)
    765   1.1   thorpej 		return (EINVAL);
    766   1.1   thorpej 
    767   1.1   thorpej 	switch (IFM_SUBTYPE(media)) {
    768   1.1   thorpej 	case IFM_10_2:
    769   1.1   thorpej 		new = ELINK2_CR_XSEL;
    770   1.1   thorpej 		break;
    771   1.1   thorpej 
    772   1.1   thorpej 	case IFM_10_5:
    773   1.1   thorpej 		new = 0;
    774   1.1   thorpej 		break;
    775   1.1   thorpej 
    776   1.1   thorpej 	default:
    777   1.1   thorpej 		return (EINVAL);
    778   1.1   thorpej 	}
    779   1.1   thorpej 
    780   1.1   thorpej 	bus_space_write_1(esc->sc_asict, esc->sc_asich, ELINK2_CR, new);
    781   1.1   thorpej 	return (0);
    782   1.1   thorpej }
    783