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