elink.c revision 1.16 1 1.16 martin /* $NetBSD: elink.c,v 1.16 2008/04/28 20:23:52 martin 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.16 martin __KERNEL_RCSID(0, "$NetBSD: elink.c,v 1.16 2008/04/28 20:23:52 martin Exp $");
38 1.2 mycroft
39 1.8 thorpej #include <sys/param.h>
40 1.9 christos #include <sys/systm.h>
41 1.8 thorpej #include <sys/malloc.h>
42 1.8 thorpej #include <sys/queue.h>
43 1.8 thorpej
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.10 thorpej elink_reset(iot, ioh, bus)
70 1.10 thorpej bus_space_tag_t iot;
71 1.10 thorpej bus_space_handle_t ioh;
72 1.8 thorpej int bus;
73 1.8 thorpej {
74 1.8 thorpej struct elink_done_reset *er;
75 1.8 thorpej
76 1.8 thorpej if (elink_all_resets_initialized == 0) {
77 1.8 thorpej LIST_INIT(&elink_all_resets);
78 1.8 thorpej elink_all_resets_initialized = 1;
79 1.2 mycroft }
80 1.8 thorpej
81 1.8 thorpej /*
82 1.8 thorpej * Reset these cards if we haven't done so already.
83 1.8 thorpej */
84 1.8 thorpej for (er = elink_all_resets.lh_first; er != NULL;
85 1.8 thorpej er = er->er_link.le_next)
86 1.8 thorpej if (er->er_bus == bus)
87 1.8 thorpej goto out;
88 1.8 thorpej
89 1.8 thorpej /* Mark this bus so we don't do it again. */
90 1.8 thorpej er = (struct elink_done_reset *)malloc(sizeof(struct elink_done_reset),
91 1.8 thorpej M_DEVBUF, M_NOWAIT);
92 1.8 thorpej if (er == NULL)
93 1.8 thorpej panic("elink_reset: can't allocate state storage");
94 1.8 thorpej
95 1.8 thorpej er->er_bus = bus;
96 1.8 thorpej LIST_INSERT_HEAD(&elink_all_resets, er, er_link);
97 1.8 thorpej
98 1.8 thorpej /* Haven't reset the cards on this bus, yet. */
99 1.10 thorpej bus_space_write_1(iot, ioh, 0, ELINK_RESET);
100 1.8 thorpej
101 1.8 thorpej out:
102 1.10 thorpej bus_space_write_1(iot, ioh, 0, 0x00);
103 1.10 thorpej bus_space_write_1(iot, ioh, 0, 0x00);
104 1.1 mycroft }
105 1.1 mycroft
106 1.1 mycroft /*
107 1.1 mycroft * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
108 1.2 mycroft * bits are shifted in. Different board types use different polynomials.
109 1.8 thorpej *
110 1.10 thorpej * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
111 1.1 mycroft */
112 1.1 mycroft void
113 1.10 thorpej elink_idseq(iot, ioh, p)
114 1.10 thorpej bus_space_tag_t iot;
115 1.10 thorpej bus_space_handle_t ioh;
116 1.13 augustss u_char p;
117 1.1 mycroft {
118 1.13 augustss int i;
119 1.13 augustss u_char c;
120 1.1 mycroft
121 1.1 mycroft c = 0xff;
122 1.1 mycroft for (i = 255; i; i--) {
123 1.10 thorpej bus_space_write_1(iot, ioh, 0, c);
124 1.1 mycroft if (c & 0x80) {
125 1.1 mycroft c <<= 1;
126 1.1 mycroft c ^= p;
127 1.1 mycroft } else
128 1.1 mycroft c <<= 1;
129 1.1 mycroft }
130 1.1 mycroft }
131