/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Device driver for National Semiconductor DS8390/WD83C690 based ethernet
* adapters.
*
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
*
* Copyright (C) 1993, David Greenman. This software may be used, modified,
* copied, distributed, and sold, in both source and binary form provided that
* the above copyright and these terms are retained. Under no circumstances is
* the author responsible for the proper functioning of this software, nor does
* the author assume any responsibility for damages incurred with its use.
*/
/*
* Device driver for the Western Digital/SMC 8003 and 8013 series,
* and the SMC Elite Ultra (8216).
*/
/* Get station address from EEPROM. */
for (i = 0; i < ETHER_ADDR_LEN; i++)
sc->sc_enaddr[i] =
bus_space_read_1(wsc->sc_asict, wsc->sc_asich, WE_PROM + i);
sc->mem_start = 0;
/* sc->mem_size has to be set by frontend */
sc->sc_flags = device_cfdata(self)->cf_flags;
/* Do generic parts of attach. */
if (wsc->sc_type & WE_SOFTCONFIG)
sc->sc_media_init = we_media_init;
else
sc->sc_media_init = dp8390_media_init;
if (dp8390_config(sc)) {
aprint_error_dev(self, "configuration failed\n");
return 1;
}
/*
* Disable 16-bit access to shared memory - we leave it disabled
* so that:
*
* (1) machines reboot properly when the board is set to
* 16-bit mode and there are conflicting 8-bit devices
* within the same 128k address space as this board's
* shared memory, and
*
* (2) so that other 8-bit devices with shared memory
* in this same 128k address space will work.
*/
WE_MEM_DISABLE(wsc);
if (wsc->sc_flags & WE_16BIT_ENABLE) {
for (i = 0; i < memsize; i += 2) {
if (bus_space_read_2(memt, memh, i) != 0)
goto fail;
}
} else {
for (i = 0; i < memsize; i++) {
if (bus_space_read_1(memt, memh, i) != 0)
goto fail;
}
}
return 0;
fail:
aprint_error_dev(sc->sc_dev,
"failed to clear shared memory at offset 0x%x\n", i);
WE_MEM_DISABLE(wsc);
return 1;
}
/*
* Given a NIC memory source address and a host memory destination address,
* copy 'len' from NIC to host using shared memory. The 'len' is rounded
* up to a word - ok as long as mbufs are word-sized.
*/
static inline void
we_readmem(struct we_softc *wsc, int from, uint8_t *to, int len)
{
bus_space_tag_t memt = wsc->sc_dp8390.sc_buft;
bus_space_handle_t memh = wsc->sc_dp8390.sc_bufh;
if (len & 1)
++len;
if (wsc->sc_flags & WE_16BIT_ENABLE)
bus_space_read_region_stream_2(memt, memh, from,
(uint16_t *)to, len >> 1);
else
bus_space_read_region_1(memt, memh, from,
to, len);
}
static int
we_mediachange(struct dp8390_softc *sc)
{
/*
* Current media is already set up. Just reset the interface
* to let the new value take hold. The new media will be
* set up in we_init_card() called via dp8390_init().
*/
dp8390_reset(sc);
return 0;
}