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