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