Home | History | Annotate | Line # | Download | only in isa
elink.c revision 1.8
      1 /*	$NetBSD: elink.c,v 1.8 1996/04/30 22:16:27 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/malloc.h>
     39 #include <sys/queue.h>
     40 
     41 #include <machine/bus.h>
     42 
     43 #include <dev/isa/elink.h>
     44 
     45 /*
     46  * This list keeps track of which ISAs have gotten an elink_reset().
     47  */
     48 struct elink_done_reset {
     49 	LIST_ENTRY(elink_done_reset)	er_link;
     50 	int				er_bus;
     51 };
     52 static LIST_HEAD(, elink_done_reset) elink_all_resets;
     53 static int elink_all_resets_initialized;
     54 
     55 /*
     56  * Issue a `global reset' to all cards, and reset the ID state machines.  We
     57  * have to be careful to do the global reset only once during autoconfig, to
     58  * prevent resetting boards that have already been configured.
     59  *
     60  * The "bus" argument here is the unit number of the ISA bus, e.g. "0"
     61  * if the bus is "isa0".
     62  *
     63  * NOTE: the caller MUST provide an i/o handle for ELINK_ID_PORT!
     64  */
     65 void
     66 elink_reset(bc, ioh, bus)
     67 	bus_chipset_tag_t bc;
     68 	bus_io_handle_t ioh;
     69 	int bus;
     70 {
     71 	struct elink_done_reset *er;
     72 
     73 	if (elink_all_resets_initialized == 0) {
     74 		LIST_INIT(&elink_all_resets);
     75 		elink_all_resets_initialized = 1;
     76 	}
     77 
     78 	/*
     79 	 * Reset these cards if we haven't done so already.
     80 	 */
     81 	for (er = elink_all_resets.lh_first; er != NULL;
     82 	    er = er->er_link.le_next)
     83 		if (er->er_bus == bus)
     84 			goto out;
     85 
     86 	/* Mark this bus so we don't do it again. */
     87 	er = (struct elink_done_reset *)malloc(sizeof(struct elink_done_reset),
     88 	    M_DEVBUF, M_NOWAIT);
     89 	if (er == NULL)
     90 		panic("elink_reset: can't allocate state storage");
     91 
     92 	er->er_bus = bus;
     93 	LIST_INSERT_HEAD(&elink_all_resets, er, er_link);
     94 
     95 	/* Haven't reset the cards on this bus, yet. */
     96 	bus_io_write_1(bc, ioh, 0, ELINK_RESET);
     97 
     98  out:
     99 	bus_io_write_1(bc, ioh, 0, 0x00);
    100 	bus_io_write_1(bc, ioh, 0, 0x00);
    101 }
    102 
    103 /*
    104  * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
    105  * bits are shifted in.  Different board types use different polynomials.
    106  *
    107  * NOTE: the caller MUST provide an i/o handle for ELINK_ID_PORT!
    108  */
    109 void
    110 elink_idseq(bc, ioh, p)
    111 	bus_chipset_tag_t bc;
    112 	bus_io_handle_t ioh;
    113 	register u_char p;
    114 {
    115 	register int i;
    116 	register u_char c;
    117 
    118 	c = 0xff;
    119 	for (i = 255; i; i--) {
    120 		bus_io_write_1(bc, ioh, 0, c);
    121 		if (c & 0x80) {
    122 			c <<= 1;
    123 			c ^= p;
    124 		} else
    125 			c <<= 1;
    126 	}
    127 }
    128