1 /* $NetBSD: if_ne_intio.c,v 1.13 2009/01/18 04:48:53 isaki Exp $ */
4 * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Ethernet part of Nereid Ethernet/USB/Memory board
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: if_ne_intio.c,v 1.13 2009/01/18 04:48:53 isaki Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/socket.h>
45 #include <sys/select.h>
46 #include <sys/device.h>
49 #include <net/if_dl.h>
50 #include <net/if_ether.h>
51 #include <net/if_media.h>
54 #include <netinet/in.h>
55 #include <netinet/in_systm.h>
56 #include <netinet/in_var.h>
57 #include <netinet/ip.h>
58 #include <netinet/if_inarp.h>
63 #include <netns/ns_if.h>
68 #include <net/bpfdesc.h>
71 #include <machine/bus.h>
72 #include <machine/cpu.h>
74 #include <dev/ic/dp8390reg.h>
75 #include <dev/ic/dp8390var.h>
76 #include <dev/ic/ne2000reg.h>
77 #include <dev/ic/ne2000var.h>
78 #include <dev/ic/rtl80x9reg.h>
79 #include <dev/ic/rtl80x9var.h>
81 #include <arch/x68k/dev/intiovar.h>
83 #define NE_INTIO_ADDR (0xece300)
84 #define NE_INTIO_ADDR2 (0xeceb00)
85 #define NE_INTIO_INTR (0xf9)
86 #define NE_INTIO_INTR2 (0xf8)
88 static int ne_intio_match(device_t
, cfdata_t
, void *);
89 static void ne_intio_attach(device_t
, device_t
, void *);
91 #define ne_intio_softc ne2000_softc
93 CFATTACH_DECL_NEW(ne_intio
, sizeof(struct ne_intio_softc
),
94 ne_intio_match
, ne_intio_attach
, NULL
, NULL
);
97 ne_intio_match(device_t parent
, cfdata_t cf
, void *aux
)
99 struct intio_attach_args
*ia
= aux
;
100 bus_space_tag_t iot
= ia
->ia_bst
;
101 bus_space_handle_t ioh
;
102 bus_space_tag_t asict
;
103 bus_space_handle_t asich
;
106 if (ia
->ia_addr
== INTIOCF_ADDR_DEFAULT
)
107 ia
->ia_addr
= NE_INTIO_ADDR
;
108 if (ia
->ia_intr
== INTIOCF_INTR_DEFAULT
)
109 ia
->ia_intr
= NE_INTIO_INTR
;
111 /* fixed parameters */
112 if (!(ia
->ia_addr
== NE_INTIO_ADDR
&& ia
->ia_intr
== NE_INTIO_INTR
) &&
113 !(ia
->ia_addr
== NE_INTIO_ADDR2
&& ia
->ia_intr
== NE_INTIO_INTR2
) )
116 /* Make sure this is a valid NE2000 I/O address */
117 if ((ia
->ia_addr
& 0x1f) != 0)
120 /* Check whether the board is inserted or not */
121 if (badaddr((void *)IIOV(ia
->ia_addr
)))
125 if (bus_space_map(iot
, ia
->ia_addr
, NE2000_NPORTS
*2,
126 BUS_SPACE_MAP_SHIFTED_EVEN
, &ioh
))
130 if (bus_space_subregion(iot
, ioh
, NE2000_ASIC_OFFSET
*2,
131 NE2000_ASIC_NPORTS
*2, &asich
))
134 /* Look for an NE2000 compatible card */
135 rv
= ne2000_detect(iot
, ioh
, asict
, asich
);
138 bus_space_unmap(iot
, ioh
, NE2000_NPORTS
);
139 return (rv
!= 0) ? 1 : 0;
143 ne_intio_attach(device_t parent
, device_t self
, void *aux
)
145 struct ne_intio_softc
*sc
= device_private(self
);
146 struct dp8390_softc
*dsc
= &sc
->sc_dp8390
;
147 struct intio_attach_args
*ia
= aux
;
148 bus_space_tag_t iot
= ia
->ia_bst
;
149 bus_space_handle_t ioh
;
150 bus_space_tag_t asict
;
151 bus_space_handle_t asich
;
156 aprint_normal(": Nereid Ethernet\n");
159 if (bus_space_map(iot
, ia
->ia_addr
, NE2000_NPORTS
*2,
160 BUS_SPACE_MAP_SHIFTED_EVEN
, &ioh
)){
161 aprint_error_dev(self
, "can't map I/O space\n");
166 if (bus_space_subregion(iot
, ioh
, NE2000_ASIC_OFFSET
*2,
167 NE2000_ASIC_NPORTS
*2, &asich
)) {
168 aprint_error_dev(self
, "can't subregion I/O space\n");
175 sc
->sc_asict
= asict
;
176 sc
->sc_asich
= asich
;
179 * detect it again, so we can print some information about
181 * XXX: Should I check NE1000 or NE2000 for Nereid?
183 netype
= ne2000_detect(iot
, ioh
, asict
, asich
);
185 case NE2000_TYPE_NE1000
:
189 case NE2000_TYPE_NE2000
:
192 * Check for a Realtek 8019.
194 bus_space_write_1(iot
, ioh
, ED_P0_CR
,
195 ED_CR_PAGE_0
| ED_CR_STP
);
196 if (bus_space_read_1(iot
, ioh
, NERTL_RTL0_8019ID0
) ==
198 bus_space_read_1(iot
, ioh
, NERTL_RTL0_8019ID1
) ==
200 typestr
= "NE2000 (RTL8019)";
201 dsc
->sc_mediachange
= rtl80x9_mediachange
;
202 dsc
->sc_mediastatus
= rtl80x9_mediastatus
;
203 dsc
->init_card
= rtl80x9_init_card
;
204 dsc
->sc_media_init
= rtl80x9_media_init
;
209 aprint_error_dev(self
, "where did the card go?!\n");
213 aprint_normal_dev(self
, "%s Ethernet\n", typestr
);
215 /* This interface is always enabled */
219 * Do generic NE2000 attach.
220 * This will read the mac address from the EEPROM.
222 ne2000_attach(sc
, NULL
);
224 /* Establish the interrupt handler */
225 if (intio_intr_establish(ia
->ia_intr
, "ne", dp8390_intr
, dsc
))
226 aprint_error_dev(self
,
227 "couldn't establish interrupt handler\n");