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