1 /* $OpenBSD: elink.c,v 1.5 1997/11/07 08:06:45 niklas 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(iot, ioh, bus) 69 bus_space_tag_t iot; 70 bus_space_handle_t ioh; 71 int bus; 72 { 73 struct elink_done_reset *er; 74 75 if (elink_all_resets_initialized == 0) { 76 LIST_INIT(&elink_all_resets); 77 elink_all_resets_initialized = 1; 78 } 79 80 /* 81 * Reset these cards if we haven't done so already. 82 */ 83 for (er = elink_all_resets.lh_first; er != NULL; 84 er = er->er_link.le_next) 85 if (er->er_bus == bus) 86 goto out; 87 88 /* Mark this bus so we don't do it again. */ 89 er = (struct elink_done_reset *)malloc(sizeof(struct elink_done_reset), 90 M_DEVBUF, M_NOWAIT); 91 if (er == NULL) 92 panic("elink_reset: can't allocate state storage"); 93 94 er->er_bus = bus; 95 LIST_INSERT_HEAD(&elink_all_resets, er, er_link); 96 97 /* Haven't reset the cards on this bus, yet. */ 98 bus_space_write_1(iot, ioh, 0, ELINK_RESET); 99 100 out: 101 bus_space_write_1(iot, ioh, 0, 0x00); 102 bus_space_write_1(iot, ioh, 0, 0x00); 103 } 104 105 /* 106 * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0 107 * bits are shifted in. Different board types use different polynomials. 108 * 109 * NOTE: the caller MUST provide an i/o handle for ELINK_ID_PORT! 110 */ 111 void 112 elink_idseq(iot, ioh, p) 113 bus_space_tag_t iot; 114 bus_space_handle_t ioh; 115 register u_char p; 116 { 117 register int i; 118 register u_char c; 119 120 c = 0xff; 121 for (i = 255; i; i--) { 122 bus_space_write_1(iot, ioh, 0, c); 123 if (c & 0x80) { 124 c <<= 1; 125 c ^= p; 126 } else 127 c <<= 1; 128 } 129 } 130