elink.c revision 1.12 1 1.12 mycroft /* $NetBSD: elink.c,v 1.12 1998/08/15 03:51:31 mycroft 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 * 3. All advertising materials mentioning features or use of this software
19 1.2 mycroft * must display the following acknowledgement:
20 1.12 mycroft * This product includes software developed by the NetBSD
21 1.12 mycroft * Foundation, Inc. and its contributors.
22 1.12 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.12 mycroft * contributors may be used to endorse or promote products derived
24 1.12 mycroft * from this software without specific prior written permission.
25 1.2 mycroft *
26 1.12 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.12 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.12 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.12 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.12 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.12 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.12 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.12 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.12 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.12 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.12 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.2 mycroft */
38 1.2 mycroft
39 1.2 mycroft /*
40 1.2 mycroft * Common code for dealing with 3COM ethernet cards.
41 1.2 mycroft */
42 1.2 mycroft
43 1.8 thorpej #include <sys/param.h>
44 1.9 christos #include <sys/systm.h>
45 1.8 thorpej #include <sys/malloc.h>
46 1.8 thorpej #include <sys/queue.h>
47 1.8 thorpej
48 1.8 thorpej #include <machine/bus.h>
49 1.8 thorpej
50 1.7 cgd #include <dev/isa/elink.h>
51 1.1 mycroft
52 1.1 mycroft /*
53 1.8 thorpej * This list keeps track of which ISAs have gotten an elink_reset().
54 1.8 thorpej */
55 1.8 thorpej struct elink_done_reset {
56 1.8 thorpej LIST_ENTRY(elink_done_reset) er_link;
57 1.8 thorpej int er_bus;
58 1.8 thorpej };
59 1.8 thorpej static LIST_HEAD(, elink_done_reset) elink_all_resets;
60 1.8 thorpej static int elink_all_resets_initialized;
61 1.8 thorpej
62 1.8 thorpej /*
63 1.6 mycroft * Issue a `global reset' to all cards, and reset the ID state machines. We
64 1.6 mycroft * have to be careful to do the global reset only once during autoconfig, to
65 1.6 mycroft * prevent resetting boards that have already been configured.
66 1.8 thorpej *
67 1.8 thorpej * The "bus" argument here is the unit number of the ISA bus, e.g. "0"
68 1.8 thorpej * if the bus is "isa0".
69 1.8 thorpej *
70 1.10 thorpej * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
71 1.1 mycroft */
72 1.1 mycroft void
73 1.10 thorpej elink_reset(iot, ioh, bus)
74 1.10 thorpej bus_space_tag_t iot;
75 1.10 thorpej bus_space_handle_t ioh;
76 1.8 thorpej int bus;
77 1.8 thorpej {
78 1.8 thorpej struct elink_done_reset *er;
79 1.8 thorpej
80 1.8 thorpej if (elink_all_resets_initialized == 0) {
81 1.8 thorpej LIST_INIT(&elink_all_resets);
82 1.8 thorpej elink_all_resets_initialized = 1;
83 1.2 mycroft }
84 1.8 thorpej
85 1.8 thorpej /*
86 1.8 thorpej * Reset these cards if we haven't done so already.
87 1.8 thorpej */
88 1.8 thorpej for (er = elink_all_resets.lh_first; er != NULL;
89 1.8 thorpej er = er->er_link.le_next)
90 1.8 thorpej if (er->er_bus == bus)
91 1.8 thorpej goto out;
92 1.8 thorpej
93 1.8 thorpej /* Mark this bus so we don't do it again. */
94 1.8 thorpej er = (struct elink_done_reset *)malloc(sizeof(struct elink_done_reset),
95 1.8 thorpej M_DEVBUF, M_NOWAIT);
96 1.8 thorpej if (er == NULL)
97 1.8 thorpej panic("elink_reset: can't allocate state storage");
98 1.8 thorpej
99 1.8 thorpej er->er_bus = bus;
100 1.8 thorpej LIST_INSERT_HEAD(&elink_all_resets, er, er_link);
101 1.8 thorpej
102 1.8 thorpej /* Haven't reset the cards on this bus, yet. */
103 1.10 thorpej bus_space_write_1(iot, ioh, 0, ELINK_RESET);
104 1.8 thorpej
105 1.8 thorpej out:
106 1.10 thorpej bus_space_write_1(iot, ioh, 0, 0x00);
107 1.10 thorpej bus_space_write_1(iot, ioh, 0, 0x00);
108 1.1 mycroft }
109 1.1 mycroft
110 1.1 mycroft /*
111 1.1 mycroft * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
112 1.2 mycroft * bits are shifted in. Different board types use different polynomials.
113 1.8 thorpej *
114 1.10 thorpej * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
115 1.1 mycroft */
116 1.1 mycroft void
117 1.10 thorpej elink_idseq(iot, ioh, p)
118 1.10 thorpej bus_space_tag_t iot;
119 1.10 thorpej bus_space_handle_t ioh;
120 1.1 mycroft register u_char p;
121 1.1 mycroft {
122 1.1 mycroft register int i;
123 1.1 mycroft register u_char c;
124 1.1 mycroft
125 1.1 mycroft c = 0xff;
126 1.1 mycroft for (i = 255; i; i--) {
127 1.10 thorpej bus_space_write_1(iot, ioh, 0, c);
128 1.1 mycroft if (c & 0x80) {
129 1.1 mycroft c <<= 1;
130 1.1 mycroft c ^= p;
131 1.1 mycroft } else
132 1.1 mycroft c <<= 1;
133 1.1 mycroft }
134 1.1 mycroft }
135