1 /* $NetBSD: elink.c,v 1.16 2008/04/28 20:23:52 martin Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe and Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Common code for dealing with 3COM ethernet cards.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: elink.c,v 1.16 2008/04/28 20:23:52 martin Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/malloc.h>
42 #include <sys/queue.h>
46 #include <dev/isa/elink.h>
49 * This list keeps track of which ISAs have gotten an elink_reset().
51 struct elink_done_reset
{
52 LIST_ENTRY(elink_done_reset
) er_link
;
55 static LIST_HEAD(, elink_done_reset
) elink_all_resets
;
56 static int elink_all_resets_initialized
;
59 * Issue a `global reset' to all cards, and reset the ID state machines. We
60 * have to be careful to do the global reset only once during autoconfig, to
61 * prevent resetting boards that have already been configured.
63 * The "bus" argument here is the unit number of the ISA bus, e.g. "0"
64 * if the bus is "isa0".
66 * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
69 elink_reset(bus_space_tag_t iot
, bus_space_handle_t ioh
, int bus
)
71 struct elink_done_reset
*er
;
73 if (elink_all_resets_initialized
== 0) {
74 LIST_INIT(&elink_all_resets
);
75 elink_all_resets_initialized
= 1;
79 * Reset these cards if we haven't done so already.
81 for (er
= elink_all_resets
.lh_first
; er
!= NULL
;
82 er
= er
->er_link
.le_next
)
83 if (er
->er_bus
== bus
)
86 /* Mark this bus so we don't do it again. */
87 er
= (struct elink_done_reset
*)malloc(sizeof(struct elink_done_reset
),
90 panic("elink_reset: can't allocate state storage");
93 LIST_INSERT_HEAD(&elink_all_resets
, er
, er_link
);
95 /* Haven't reset the cards on this bus, yet. */
96 bus_space_write_1(iot
, ioh
, 0, ELINK_RESET
);
99 bus_space_write_1(iot
, ioh
, 0, 0x00);
100 bus_space_write_1(iot
, ioh
, 0, 0x00);
104 * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
105 * bits are shifted in. Different board types use different polynomials.
107 * NOTE: the caller MUST provide an access handle for ELINK_ID_PORT!
110 elink_idseq(bus_space_tag_t iot
, bus_space_handle_t ioh
, u_char p
)
116 for (i
= 255; i
; i
--) {
117 bus_space_write_1(iot
, ioh
, 0, c
);