1 /* $NetBSD: if_mbe_g2.c,v 1.6 2007/03/12 14:03:48 tsutsui Exp $ */
4 * Copyright (c) 2002 Christian Groessler
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
34 * This software may be used, modified, copied, distributed, and sold, in
35 * both source and binary form provided that the above copyright, these
36 * terms and the following disclaimer are retained. The name of the author
37 * and/or the contributor may not be used to endorse or promote products
38 * derived from this software without specific prior written permission.
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * Portions copyright (C) 1993, David Greenman. This software may be used,
55 * modified, copied, distributed, and sold, in both source and binary form
56 * provided that the above copyright and these terms are retained. Under no
57 * circumstances is the author responsible for the proper functioning of this
58 * software, nor does the author assume any responsibility for damages
59 * incurred with its use.
63 * Driver for Sega LAN Adapter (HIT-0300)
66 #include <sys/cdefs.h>
67 __KERNEL_RCSID(0, "$NetBSD: if_mbe_g2.c,v 1.6 2007/03/12 14:03:48 tsutsui Exp $");
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/device.h>
74 #include <net/if_ether.h>
75 #include <net/if_media.h>
77 #include <machine/bus.h>
78 #include <machine/intr.h>
79 #include <machine/sysasicvar.h>
80 #include <machine/cpu.h>
82 #include <dev/ic/mb86960reg.h>
83 #include <dev/ic/mb86960var.h>
85 #include <dreamcast/dev/g2/g2busvar.h>
88 int mbe_g2_match(device_t
, cfdata_t
, void *);
89 void mbe_g2_attach(device_t
, device_t
, void *);
90 static int mbe_g2_detect(bus_space_tag_t
, bus_space_handle_t
, uint8_t *);
93 struct mb86960_softc sc_mb86960
; /* real "mb86960" softc */
96 CFATTACH_DECL_NEW(mbe_g2bus
, sizeof(struct mbe_g2_softc
),
97 mbe_g2_match
, mbe_g2_attach
, NULL
, NULL
);
99 #define LANA_NPORTS (0x20 * 4)
102 #define DPRINTF printf
104 #define DPRINTF while (/* CONSTCOND */0) printf
107 static struct dreamcast_bus_space mbe_g2_dbs
;
110 * Determine if the device is present.
113 mbe_g2_match(device_t parent
, cfdata_t cf
, void *aux
)
115 struct g2bus_attach_args
*ga
= aux
;
116 bus_space_handle_t memh
;
117 struct dreamcast_bus_space dbs
;
118 bus_space_tag_t memt
= &dbs
;
119 static int lanafound
;
121 uint8_t myea
[ETHER_ADDR_LEN
];
126 if (strcmp("mbe", cf
->cf_name
))
129 memcpy(memt
, ga
->ga_memt
, sizeof(struct dreamcast_bus_space
));
130 g2bus_set_bus_mem_sparse(memt
);
133 if (bus_space_map(memt
, 0x00600400, LANA_NPORTS
, 0, &memh
)) {
134 DPRINTF("%s: couldn't map iospace 0x%x\n",
135 __func__
, 0x00600400);
140 if (mbe_g2_detect(memt
, memh
, myea
) == 0) {
141 DPRINTF("%s: LAN Adapter detection failed\n", __func__
);
148 bus_space_unmap(memt
, memh
, LANA_NPORTS
);
154 * Determine type and ethernet address.
157 mbe_g2_detect(bus_space_tag_t iot
, bus_space_handle_t ioh
, uint8_t *enaddr
)
159 uint8_t eeprom
[FE_EEPROM_SIZE
];
161 /* Read the chip type */
162 if ((bus_space_read_1(iot
, ioh
, FE_DLCR7
) & FE_D7_IDENT
) !=
164 DPRINTF("%s: unknown chip type\n", __func__
);
168 memset(eeprom
, 0, FE_EEPROM_SIZE
);
170 /* Get our station address from EEPROM. */
171 mb86965_read_eeprom(iot
, ioh
, eeprom
);
172 memcpy(enaddr
, eeprom
, ETHER_ADDR_LEN
);
174 DPRINTF("Ethernet address: %s\n", ether_sprintf(enaddr
));
176 /* Make sure we got a valid station address. */
177 if ((enaddr
[0] & 0x03) != 0x00 ||
178 (enaddr
[0] == 0x00 && enaddr
[1] == 0x00 && enaddr
[2] == 0x00)) {
179 DPRINTF("%s: invalid ethernet address\n", __func__
);
187 mbe_g2_attach(device_t parent
, device_t self
, void *aux
)
189 struct mbe_g2_softc
*isc
= device_private(self
);
190 struct mb86960_softc
*sc
= &isc
->sc_mb86960
;
191 struct g2bus_attach_args
*ga
= aux
;
192 bus_space_tag_t memt
= &mbe_g2_dbs
;
193 bus_space_handle_t memh
;
194 uint8_t myea
[ETHER_ADDR_LEN
];
198 memcpy(memt
, ga
->ga_memt
, sizeof(struct dreamcast_bus_space
));
199 g2bus_set_bus_mem_sparse(memt
);
202 if (bus_space_map(memt
, 0x00600400, LANA_NPORTS
, 0, &memh
)) {
203 aprint_error(": can't map i/o space\n");
210 /* Determine the card type. */
211 if (mbe_g2_detect(memt
, memh
, myea
) == 0) {
212 aprint_error(": where did the card go?!\n");
213 panic("unknown card");
216 aprint_normal(": Sega LAN-Adapter Ethernet\n");
218 /* This interface is always enabled. */
219 sc
->sc_stat
|= FE_STAT_ENABLED
;
221 /* The LAN-Adapter uses 8 bit bus mode and slow SRAM. */
222 sc
->sc_flags
|= FE_FLAGS_SBW_BYTE
| FE_FLAGS_SRAM_150ns
;
225 * Do generic MB86960 attach.
227 mb86960_attach(sc
, myea
);
229 mb86960_config(sc
, NULL
, 0, 0);
231 sysasic_intr_establish(SYSASIC_EVENT_8BIT
, IPL_NET
, SYSASIC_IRL11
,