Home | History | Annotate | Line # | Download | only in isa
elink.c revision 1.13.6.1
      1  1.13.6.1   nathanw /*	$NetBSD: elink.c,v 1.13.6.1 2001/11/14 19:14:45 nathanw Exp $	*/
      2       1.3       cgd 
      3      1.12   mycroft /*-
      4      1.12   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5      1.12   mycroft  * All rights reserved.
      6      1.12   mycroft  *
      7      1.12   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8      1.12   mycroft  * by Jason R. Thorpe and Charles M. Hannum.
      9       1.2   mycroft  *
     10       1.2   mycroft  * Redistribution and use in source and binary forms, with or without
     11       1.2   mycroft  * modification, are permitted provided that the following conditions
     12       1.2   mycroft  * are met:
     13       1.2   mycroft  * 1. Redistributions of source code must retain the above copyright
     14       1.2   mycroft  *    notice, this list of conditions and the following disclaimer.
     15       1.2   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.2   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17       1.2   mycroft  *    documentation and/or other materials provided with the distribution.
     18       1.2   mycroft  * 3. All advertising materials mentioning features or use of this software
     19       1.2   mycroft  *    must display the following acknowledgement:
     20      1.12   mycroft  *        This product includes software developed by the NetBSD
     21      1.12   mycroft  *        Foundation, Inc. and its contributors.
     22      1.12   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.12   mycroft  *    contributors may be used to endorse or promote products derived
     24      1.12   mycroft  *    from this software without specific prior written permission.
     25       1.2   mycroft  *
     26      1.12   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.12   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.12   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.12   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.12   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.12   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.12   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.12   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.12   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.12   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.12   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37       1.2   mycroft  */
     38       1.2   mycroft 
     39       1.2   mycroft /*
     40       1.2   mycroft  * Common code for dealing with 3COM ethernet cards.
     41       1.2   mycroft  */
     42  1.13.6.1   nathanw 
     43  1.13.6.1   nathanw #include <sys/cdefs.h>
     44  1.13.6.1   nathanw __KERNEL_RCSID(0, "$NetBSD: elink.c,v 1.13.6.1 2001/11/14 19:14:45 nathanw Exp $");
     45       1.2   mycroft 
     46       1.8   thorpej #include <sys/param.h>
     47       1.9  christos #include <sys/systm.h>
     48       1.8   thorpej #include <sys/malloc.h>
     49       1.8   thorpej #include <sys/queue.h>
     50       1.8   thorpej 
     51       1.8   thorpej #include <machine/bus.h>
     52       1.8   thorpej 
     53       1.7       cgd #include <dev/isa/elink.h>
     54       1.1   mycroft 
     55       1.1   mycroft /*
     56       1.8   thorpej  * This list keeps track of which ISAs have gotten an elink_reset().
     57       1.8   thorpej  */
     58       1.8   thorpej struct elink_done_reset {
     59       1.8   thorpej 	LIST_ENTRY(elink_done_reset)	er_link;
     60       1.8   thorpej 	int				er_bus;
     61       1.8   thorpej };
     62       1.8   thorpej static LIST_HEAD(, elink_done_reset) elink_all_resets;
     63       1.8   thorpej static int elink_all_resets_initialized;
     64       1.8   thorpej 
     65       1.8   thorpej /*
     66       1.6   mycroft  * Issue a `global reset' to all cards, and reset the ID state machines.  We
     67       1.6   mycroft  * have to be careful to do the global reset only once during autoconfig, to
     68       1.6   mycroft  * prevent resetting boards that have already been configured.
     69       1.8   thorpej  *
     70       1.8   thorpej  * The "bus" argument here is the unit number of the ISA bus, e.g. "0"
     71       1.8   thorpej  * if the bus is "isa0".
     72       1.8   thorpej  *
     73      1.10   thorpej  * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
     74       1.1   mycroft  */
     75       1.1   mycroft void
     76      1.10   thorpej elink_reset(iot, ioh, bus)
     77      1.10   thorpej 	bus_space_tag_t iot;
     78      1.10   thorpej 	bus_space_handle_t ioh;
     79       1.8   thorpej 	int bus;
     80       1.8   thorpej {
     81       1.8   thorpej 	struct elink_done_reset *er;
     82       1.8   thorpej 
     83       1.8   thorpej 	if (elink_all_resets_initialized == 0) {
     84       1.8   thorpej 		LIST_INIT(&elink_all_resets);
     85       1.8   thorpej 		elink_all_resets_initialized = 1;
     86       1.2   mycroft 	}
     87       1.8   thorpej 
     88       1.8   thorpej 	/*
     89       1.8   thorpej 	 * Reset these cards if we haven't done so already.
     90       1.8   thorpej 	 */
     91       1.8   thorpej 	for (er = elink_all_resets.lh_first; er != NULL;
     92       1.8   thorpej 	    er = er->er_link.le_next)
     93       1.8   thorpej 		if (er->er_bus == bus)
     94       1.8   thorpej 			goto out;
     95       1.8   thorpej 
     96       1.8   thorpej 	/* Mark this bus so we don't do it again. */
     97       1.8   thorpej 	er = (struct elink_done_reset *)malloc(sizeof(struct elink_done_reset),
     98       1.8   thorpej 	    M_DEVBUF, M_NOWAIT);
     99       1.8   thorpej 	if (er == NULL)
    100       1.8   thorpej 		panic("elink_reset: can't allocate state storage");
    101       1.8   thorpej 
    102       1.8   thorpej 	er->er_bus = bus;
    103       1.8   thorpej 	LIST_INSERT_HEAD(&elink_all_resets, er, er_link);
    104       1.8   thorpej 
    105       1.8   thorpej 	/* Haven't reset the cards on this bus, yet. */
    106      1.10   thorpej 	bus_space_write_1(iot, ioh, 0, ELINK_RESET);
    107       1.8   thorpej 
    108       1.8   thorpej  out:
    109      1.10   thorpej 	bus_space_write_1(iot, ioh, 0, 0x00);
    110      1.10   thorpej 	bus_space_write_1(iot, ioh, 0, 0x00);
    111       1.1   mycroft }
    112       1.1   mycroft 
    113       1.1   mycroft /*
    114       1.1   mycroft  * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
    115       1.2   mycroft  * bits are shifted in.  Different board types use different polynomials.
    116       1.8   thorpej  *
    117      1.10   thorpej  * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
    118       1.1   mycroft  */
    119       1.1   mycroft void
    120      1.10   thorpej elink_idseq(iot, ioh, p)
    121      1.10   thorpej 	bus_space_tag_t iot;
    122      1.10   thorpej 	bus_space_handle_t ioh;
    123      1.13  augustss 	u_char p;
    124       1.1   mycroft {
    125      1.13  augustss 	int i;
    126      1.13  augustss 	u_char c;
    127       1.1   mycroft 
    128       1.1   mycroft 	c = 0xff;
    129       1.1   mycroft 	for (i = 255; i; i--) {
    130      1.10   thorpej 		bus_space_write_1(iot, ioh, 0, c);
    131       1.1   mycroft 		if (c & 0x80) {
    132       1.1   mycroft 			c <<= 1;
    133       1.1   mycroft 			c ^= p;
    134       1.1   mycroft 		} else
    135       1.1   mycroft 			c <<= 1;
    136       1.1   mycroft 	}
    137       1.1   mycroft }
    138