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