Home | History | Annotate | Line # | Download | only in isa
      1  1.19   thorpej /*	$NetBSD: elink.c,v 1.19 2022/09/25 17:11:48 thorpej 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  *
     19  1.12   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.12   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.12   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.12   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.12   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.12   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.12   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.12   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.12   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.12   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.12   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     30   1.2   mycroft  */
     31   1.2   mycroft 
     32   1.2   mycroft /*
     33   1.2   mycroft  * Common code for dealing with 3COM ethernet cards.
     34   1.2   mycroft  */
     35  1.14     lukem 
     36  1.14     lukem #include <sys/cdefs.h>
     37  1.19   thorpej __KERNEL_RCSID(0, "$NetBSD: elink.c,v 1.19 2022/09/25 17:11:48 thorpej Exp $");
     38   1.2   mycroft 
     39   1.8   thorpej #include <sys/param.h>
     40   1.9  christos #include <sys/systm.h>
     41  1.19   thorpej 
     42   1.8   thorpej #include <sys/queue.h>
     43  1.19   thorpej #include <sys/kmem.h>
     44  1.15        ad #include <sys/bus.h>
     45   1.8   thorpej 
     46   1.7       cgd #include <dev/isa/elink.h>
     47   1.1   mycroft 
     48   1.1   mycroft /*
     49   1.8   thorpej  * This list keeps track of which ISAs have gotten an elink_reset().
     50   1.8   thorpej  */
     51   1.8   thorpej struct elink_done_reset {
     52   1.8   thorpej 	LIST_ENTRY(elink_done_reset)	er_link;
     53   1.8   thorpej 	int				er_bus;
     54   1.8   thorpej };
     55   1.8   thorpej static LIST_HEAD(, elink_done_reset) elink_all_resets;
     56   1.8   thorpej static int elink_all_resets_initialized;
     57   1.8   thorpej 
     58   1.8   thorpej /*
     59   1.6   mycroft  * Issue a `global reset' to all cards, and reset the ID state machines.  We
     60   1.6   mycroft  * have to be careful to do the global reset only once during autoconfig, to
     61   1.6   mycroft  * prevent resetting boards that have already been configured.
     62   1.8   thorpej  *
     63   1.8   thorpej  * The "bus" argument here is the unit number of the ISA bus, e.g. "0"
     64   1.8   thorpej  * if the bus is "isa0".
     65   1.8   thorpej  *
     66  1.10   thorpej  * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
     67   1.1   mycroft  */
     68   1.1   mycroft void
     69  1.17       dsl elink_reset(bus_space_tag_t iot, bus_space_handle_t ioh, 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.19   thorpej 	er = kmem_alloc(sizeof(*er), KM_SLEEP);
     88   1.8   thorpej 	er->er_bus = bus;
     89   1.8   thorpej 	LIST_INSERT_HEAD(&elink_all_resets, er, er_link);
     90   1.8   thorpej 
     91   1.8   thorpej 	/* Haven't reset the cards on this bus, yet. */
     92  1.10   thorpej 	bus_space_write_1(iot, ioh, 0, ELINK_RESET);
     93   1.8   thorpej 
     94   1.8   thorpej  out:
     95  1.10   thorpej 	bus_space_write_1(iot, ioh, 0, 0x00);
     96  1.10   thorpej 	bus_space_write_1(iot, ioh, 0, 0x00);
     97   1.1   mycroft }
     98   1.1   mycroft 
     99   1.1   mycroft /*
    100   1.1   mycroft  * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
    101   1.2   mycroft  * bits are shifted in.  Different board types use different polynomials.
    102   1.8   thorpej  *
    103  1.10   thorpej  * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
    104   1.1   mycroft  */
    105   1.1   mycroft void
    106  1.17       dsl elink_idseq(bus_space_tag_t iot, bus_space_handle_t ioh, u_char p)
    107   1.1   mycroft {
    108  1.13  augustss 	int i;
    109  1.13  augustss 	u_char c;
    110   1.1   mycroft 
    111   1.1   mycroft 	c = 0xff;
    112   1.1   mycroft 	for (i = 255; i; i--) {
    113  1.10   thorpej 		bus_space_write_1(iot, ioh, 0, c);
    114   1.1   mycroft 		if (c & 0x80) {
    115   1.1   mycroft 			c <<= 1;
    116   1.1   mycroft 			c ^= p;
    117   1.1   mycroft 		} else
    118   1.1   mycroft 			c <<= 1;
    119   1.1   mycroft 	}
    120   1.1   mycroft }
    121