1996-10-22 02:34:38 +04:00
|
|
|
/* $NetBSD: elink.c,v 1.10 1996/10/21 22:40:39 thorpej Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1994-02-16 22:28:19 +03:00
|
|
|
/*
|
1996-05-01 02:16:27 +04:00
|
|
|
* Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
|
1995-01-08 00:37:54 +03:00
|
|
|
* Copyright (c) 1994, 1995 Charles Hannum. All rights reserved.
|
1994-02-16 22:28:19 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles Hannum.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for dealing with 3COM ethernet cards.
|
|
|
|
*/
|
|
|
|
|
1996-05-01 02:16:27 +04:00
|
|
|
#include <sys/param.h>
|
1996-05-03 23:06:25 +04:00
|
|
|
#include <sys/systm.h>
|
1996-05-01 02:16:27 +04:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
1995-01-29 10:36:54 +03:00
|
|
|
#include <dev/isa/elink.h>
|
1994-02-16 20:59:11 +03:00
|
|
|
|
1996-05-01 02:16:27 +04:00
|
|
|
/*
|
|
|
|
* This list keeps track of which ISAs have gotten an elink_reset().
|
|
|
|
*/
|
|
|
|
struct elink_done_reset {
|
|
|
|
LIST_ENTRY(elink_done_reset) er_link;
|
|
|
|
int er_bus;
|
|
|
|
};
|
|
|
|
static LIST_HEAD(, elink_done_reset) elink_all_resets;
|
|
|
|
static int elink_all_resets_initialized;
|
|
|
|
|
1994-02-16 20:59:11 +03:00
|
|
|
/*
|
1995-01-08 00:37:54 +03:00
|
|
|
* Issue a `global reset' to all cards, and reset the ID state machines. We
|
|
|
|
* have to be careful to do the global reset only once during autoconfig, to
|
|
|
|
* prevent resetting boards that have already been configured.
|
1996-05-01 02:16:27 +04:00
|
|
|
*
|
|
|
|
* The "bus" argument here is the unit number of the ISA bus, e.g. "0"
|
|
|
|
* if the bus is "isa0".
|
|
|
|
*
|
1996-10-22 02:34:38 +04:00
|
|
|
* NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
|
1994-02-16 20:59:11 +03:00
|
|
|
*/
|
|
|
|
void
|
1996-10-22 02:34:38 +04:00
|
|
|
elink_reset(iot, ioh, bus)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
1996-05-01 02:16:27 +04:00
|
|
|
int bus;
|
|
|
|
{
|
|
|
|
struct elink_done_reset *er;
|
1994-02-16 20:59:11 +03:00
|
|
|
|
1996-05-01 02:16:27 +04:00
|
|
|
if (elink_all_resets_initialized == 0) {
|
|
|
|
LIST_INIT(&elink_all_resets);
|
|
|
|
elink_all_resets_initialized = 1;
|
1994-02-16 22:28:19 +03:00
|
|
|
}
|
1996-05-01 02:16:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset these cards if we haven't done so already.
|
|
|
|
*/
|
|
|
|
for (er = elink_all_resets.lh_first; er != NULL;
|
|
|
|
er = er->er_link.le_next)
|
|
|
|
if (er->er_bus == bus)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Mark this bus so we don't do it again. */
|
|
|
|
er = (struct elink_done_reset *)malloc(sizeof(struct elink_done_reset),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (er == NULL)
|
|
|
|
panic("elink_reset: can't allocate state storage");
|
|
|
|
|
|
|
|
er->er_bus = bus;
|
|
|
|
LIST_INSERT_HEAD(&elink_all_resets, er, er_link);
|
|
|
|
|
|
|
|
/* Haven't reset the cards on this bus, yet. */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, 0, ELINK_RESET);
|
1996-05-01 02:16:27 +04:00
|
|
|
|
|
|
|
out:
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, 0, 0x00);
|
|
|
|
bus_space_write_1(iot, ioh, 0, 0x00);
|
1994-02-16 20:59:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
|
1994-02-16 22:28:19 +03:00
|
|
|
* bits are shifted in. Different board types use different polynomials.
|
1996-05-01 02:16:27 +04:00
|
|
|
*
|
1996-10-22 02:34:38 +04:00
|
|
|
* NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
|
1994-02-16 20:59:11 +03:00
|
|
|
*/
|
|
|
|
void
|
1996-10-22 02:34:38 +04:00
|
|
|
elink_idseq(iot, ioh, p)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
1994-02-16 20:59:11 +03:00
|
|
|
register u_char p;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
register u_char c;
|
|
|
|
|
|
|
|
c = 0xff;
|
|
|
|
for (i = 255; i; i--) {
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, 0, c);
|
1994-02-16 20:59:11 +03:00
|
|
|
if (c & 0x80) {
|
|
|
|
c <<= 1;
|
|
|
|
c ^= p;
|
|
|
|
} else
|
|
|
|
c <<= 1;
|
|
|
|
}
|
|
|
|
}
|