Mon Jan 10 13:29:29 2011 UTC ()
Use ether_aton_r() in sys/net/if_ethersubr.c instead of home grown copies.
Hint from ryo@.  Tested on IP32 mec(4).


(tsutsui)
diff -r1.36 -r1.37 src/sys/arch/sgimips/hpc/if_sq.c
diff -r1.2 -r1.3 src/sys/arch/sgimips/ioc/if_le_oioc.c
diff -r1.43 -r1.44 src/sys/arch/sgimips/mace/if_mec.c

cvs diff -r1.36 -r1.37 src/sys/arch/sgimips/hpc/if_sq.c (expand / switch to unified diff)

--- src/sys/arch/sgimips/hpc/if_sq.c 2010/04/05 07:19:31 1.36
+++ src/sys/arch/sgimips/hpc/if_sq.c 2011/01/10 13:29:29 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_sq.c,v 1.36 2010/04/05 07:19:31 joerg Exp $ */ 1/* $NetBSD: if_sq.c,v 1.37 2011/01/10 13:29:29 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Rafal K. Boni 4 * Copyright (c) 2001 Rafal K. Boni
5 * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. 5 * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Portions of this code are derived from software contributed to The 8 * Portions of this code are derived from software contributed to The
9 * NetBSD Foundation by Jason R. Thorpe of the Numerical Aerospace 9 * NetBSD Foundation by Jason R. Thorpe of the Numerical Aerospace
10 * Simulation Facility, NASA Ames Research Center. 10 * Simulation Facility, NASA Ames Research Center.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: if_sq.c,v 1.36 2010/04/05 07:19:31 joerg Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: if_sq.c,v 1.37 2011/01/10 13:29:29 tsutsui Exp $");
37 37
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/device.h> 41#include <sys/device.h>
42#include <sys/callout.h> 42#include <sys/callout.h>
43#include <sys/mbuf.h> 43#include <sys/mbuf.h>
44#include <sys/malloc.h> 44#include <sys/malloc.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/socket.h> 46#include <sys/socket.h>
47#include <sys/ioctl.h> 47#include <sys/ioctl.h>
48#include <sys/errno.h> 48#include <sys/errno.h>
49#include <sys/syslog.h> 49#include <sys/syslog.h>
@@ -108,28 +108,26 @@ static void sq_watchdog(struct ifnet *); @@ -108,28 +108,26 @@ static void sq_watchdog(struct ifnet *);
108static int sq_ioctl(struct ifnet *, u_long, void *); 108static int sq_ioctl(struct ifnet *, u_long, void *);
109 109
110static void sq_set_filter(struct sq_softc *); 110static void sq_set_filter(struct sq_softc *);
111static int sq_intr(void *); 111static int sq_intr(void *);
112static int sq_rxintr(struct sq_softc *); 112static int sq_rxintr(struct sq_softc *);
113static int sq_txintr(struct sq_softc *); 113static int sq_txintr(struct sq_softc *);
114static void sq_txring_hpc1(struct sq_softc *); 114static void sq_txring_hpc1(struct sq_softc *);
115static void sq_txring_hpc3(struct sq_softc *); 115static void sq_txring_hpc3(struct sq_softc *);
116static void sq_reset(struct sq_softc *); 116static void sq_reset(struct sq_softc *);
117static int sq_add_rxbuf(struct sq_softc *, int); 117static int sq_add_rxbuf(struct sq_softc *, int);
118static void sq_dump_buffer(paddr_t addr, psize_t len); 118static void sq_dump_buffer(paddr_t addr, psize_t len);
119static void sq_trace_dump(struct sq_softc *); 119static void sq_trace_dump(struct sq_softc *);
120 120
121static void enaddr_aton(const char*, u_int8_t*); 
122 
123CFATTACH_DECL(sq, sizeof(struct sq_softc), 121CFATTACH_DECL(sq, sizeof(struct sq_softc),
124 sq_match, sq_attach, NULL, NULL); 122 sq_match, sq_attach, NULL, NULL);
125 123
126#define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN) 124#define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
127 125
128#define sq_seeq_read(sc, off) \ 126#define sq_seeq_read(sc, off) \
129 bus_space_read_1(sc->sc_regt, sc->sc_regh, off) 127 bus_space_read_1(sc->sc_regt, sc->sc_regh, off)
130#define sq_seeq_write(sc, off, val) \ 128#define sq_seeq_write(sc, off, val) \
131 bus_space_write_1(sc->sc_regt, sc->sc_regh, off, val) 129 bus_space_write_1(sc->sc_regt, sc->sc_regh, off, val)
132 130
133#define sq_hpc_read(sc, off) \ 131#define sq_hpc_read(sc, off) \
134 bus_space_read_4(sc->sc_hpct, sc->sc_hpch, off)  132 bus_space_read_4(sc->sc_hpct, sc->sc_hpch, off)
135#define sq_hpc_write(sc, off, val) \ 133#define sq_hpc_write(sc, off, val) \
@@ -272,27 +270,27 @@ sq_attach(struct device *parent, struct  @@ -272,27 +270,27 @@ sq_attach(struct device *parent, struct
272 270
273 /* 271 /*
274 * If our mac address is bogus, obtain it from ARCBIOS. This will 272 * If our mac address is bogus, obtain it from ARCBIOS. This will
275 * be true of the onboard HPC3 on IP22, since there is no eeprom, 273 * be true of the onboard HPC3 on IP22, since there is no eeprom,
276 * but rather the DS1386 RTC's battery-backed ram is used. 274 * but rather the DS1386 RTC's battery-backed ram is used.
277 */ 275 */
278 if (sc->sc_enaddr[0] != SGI_OUI_0 || sc->sc_enaddr[1] != SGI_OUI_1 || 276 if (sc->sc_enaddr[0] != SGI_OUI_0 || sc->sc_enaddr[1] != SGI_OUI_1 ||
279 sc->sc_enaddr[2] != SGI_OUI_2) { 277 sc->sc_enaddr[2] != SGI_OUI_2) {
280 macaddr = ARCBIOS->GetEnvironmentVariable("eaddr"); 278 macaddr = ARCBIOS->GetEnvironmentVariable("eaddr");
281 if (macaddr == NULL) { 279 if (macaddr == NULL) {
282 printf(": unable to get MAC address!\n"); 280 printf(": unable to get MAC address!\n");
283 goto fail_6; 281 goto fail_6;
284 } 282 }
285 enaddr_aton(macaddr, sc->sc_enaddr); 283 ether_aton_r(sc->sc_enaddr, sizeof(sc->sc_enaddr), macaddr);
286 } 284 }
287 285
288 evcnt_attach_dynamic(&sc->sq_intrcnt, EVCNT_TYPE_INTR, NULL, 286 evcnt_attach_dynamic(&sc->sq_intrcnt, EVCNT_TYPE_INTR, NULL,
289 self->dv_xname, "intr"); 287 self->dv_xname, "intr");
290 288
291 if ((cpu_intr_establish(haa->ha_irq, IPL_NET, sq_intr, sc)) == NULL) { 289 if ((cpu_intr_establish(haa->ha_irq, IPL_NET, sq_intr, sc)) == NULL) {
292 printf(": unable to establish interrupt!\n"); 290 printf(": unable to establish interrupt!\n");
293 goto fail_6; 291 goto fail_6;
294 } 292 }
295 293
296 /* Reset the chip to a known state. */ 294 /* Reset the chip to a known state. */
297 sq_reset(sc); 295 sq_reset(sc);
298 296
@@ -1322,39 +1320,13 @@ sq_dump_buffer(paddr_t addr, psize_t len @@ -1322,39 +1320,13 @@ sq_dump_buffer(paddr_t addr, psize_t len
1322 if (len == 0) 1320 if (len == 0)
1323 return; 1321 return;
1324 1322
1325 printf("%p: ", physaddr); 1323 printf("%p: ", physaddr);
1326 1324
1327 for (i = 0; i < len; i++) { 1325 for (i = 0; i < len; i++) {
1328 printf("%02x ", *(physaddr + i) & 0xff); 1326 printf("%02x ", *(physaddr + i) & 0xff);
1329 if ((i % 16) == 15 && i != len - 1) 1327 if ((i % 16) == 15 && i != len - 1)
1330 printf("\n%p: ", physaddr + i); 1328 printf("\n%p: ", physaddr + i);
1331 } 1329 }
1332 1330
1333 printf("\n"); 1331 printf("\n");
1334} 1332}
1335 
1336void 
1337enaddr_aton(const char* str, u_int8_t* eaddr) 
1338{ 
1339 int i; 
1340 char c; 
1341 
1342 for (i = 0; i < ETHER_ADDR_LEN; i++) { 
1343 if (*str == ':') 
1344 str++; 
1345 
1346 c = *str++; 
1347 if (isdigit(c)) { 
1348 eaddr[i] = (c - '0'); 
1349 } else if (isxdigit(c)) { 
1350 eaddr[i] = (toupper(c) + 10 - 'A'); 
1351 } 
1352 
1353 c = *str++; 
1354 if (isdigit(c)) { 
1355 eaddr[i] = (eaddr[i] << 4) | (c - '0'); 
1356 } else if (isxdigit(c)) { 
1357 eaddr[i] = (eaddr[i] << 4) | (toupper(c) + 10 - 'A'); 
1358 } 
1359 } 
1360} 

cvs diff -r1.2 -r1.3 src/sys/arch/sgimips/ioc/if_le_oioc.c (expand / switch to unified diff)

--- src/sys/arch/sgimips/ioc/if_le_oioc.c 2010/01/19 22:06:22 1.2
+++ src/sys/arch/sgimips/ioc/if_le_oioc.c 2011/01/10 13:29:29 1.3
@@ -1,41 +1,41 @@ @@ -1,41 +1,41 @@
1/* $NetBSD: if_le_oioc.c,v 1.2 2010/01/19 22:06:22 pooka Exp $ */ 1/* $NetBSD: if_le_oioc.c,v 1.3 2011/01/10 13:29:29 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009 Stephen M. Rumble 4 * Copyright (c) 2009 Stephen M. Rumble
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products 12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission. 13 * derived from this software without specific prior written permission.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27#include <sys/cdefs.h> 27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: if_le_oioc.c,v 1.2 2010/01/19 22:06:22 pooka Exp $"); 28__KERNEL_RCSID(0, "$NetBSD: if_le_oioc.c,v 1.3 2011/01/10 13:29:29 tsutsui Exp $");
29 29
30#include "opt_inet.h" 30#include "opt_inet.h"
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/mbuf.h> 34#include <sys/mbuf.h>
35#include <sys/syslog.h> 35#include <sys/syslog.h>
36#include <sys/socket.h> 36#include <sys/socket.h>
37#include <sys/device.h> 37#include <sys/device.h>
38 38
39#include <uvm/uvm.h> // for uvm_pglistalloc 39#include <uvm/uvm.h> // for uvm_pglistalloc
40 40
41#include <net/if.h> 41#include <net/if.h>
@@ -103,27 +103,26 @@ struct le_softc { @@ -103,27 +103,26 @@ struct le_softc {
103 103
104static int le_match(device_t, cfdata_t, void *); 104static int le_match(device_t, cfdata_t, void *);
105static void le_attach(device_t, device_t, void *); 105static void le_attach(device_t, device_t, void *);
106 106
107CFATTACH_DECL_NEW(le, sizeof(struct le_softc), 107CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
108 le_match, le_attach, NULL, NULL); 108 le_match, le_attach, NULL, NULL);
109 109
110#if defined(_KERNEL_OPT) 110#if defined(_KERNEL_OPT)
111#include "opt_ddb.h" 111#include "opt_ddb.h"
112#endif 112#endif
113 113
114static void lewrcsr(struct lance_softc *, uint16_t, uint16_t); 114static void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
115static uint16_t lerdcsr(struct lance_softc *, uint16_t);  115static uint16_t lerdcsr(struct lance_softc *, uint16_t);
116static void enaddr_aton(const char *, u_int8_t *); 
117 116
118static void 117static void
119lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 118lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
120{ 119{
121 struct le_softc *lesc = (struct le_softc *)sc; 120 struct le_softc *lesc = (struct le_softc *)sc;
122 bus_space_write_2(lesc->sc_st, lesc->sc_raph, 0, port); 121 bus_space_write_2(lesc->sc_st, lesc->sc_raph, 0, port);
123 bus_space_write_2(lesc->sc_st, lesc->sc_rdph, 0, val); 122 bus_space_write_2(lesc->sc_st, lesc->sc_rdph, 0, val);
124} 123}
125 124
126static uint16_t 125static uint16_t
127lerdcsr(struct lance_softc *sc, uint16_t port) 126lerdcsr(struct lance_softc *sc, uint16_t port)
128{ 127{
129 struct le_softc *lesc = (struct le_softc *)sc; 128 struct le_softc *lesc = (struct le_softc *)sc;
@@ -148,27 +147,27 @@ le_match(device_t parent, cfdata_t cf, v @@ -148,27 +147,27 @@ le_match(device_t parent, cfdata_t cf, v
148 return (0); 147 return (0);
149} 148}
150 149
151void 150void
152le_attach(device_t parent, device_t self, void *aux) 151le_attach(device_t parent, device_t self, void *aux)
153{ 152{
154 extern paddr_t avail_start, avail_end; 153 extern paddr_t avail_start, avail_end;
155 154
156 struct le_softc *lesc = device_private(self); 155 struct le_softc *lesc = device_private(self);
157 struct lance_softc *sc = &lesc->sc_am7990.lsc; 156 struct lance_softc *sc = &lesc->sc_am7990.lsc;
158 struct oioc_attach_args *oa = aux; 157 struct oioc_attach_args *oa = aux;
159 struct pglist mlist; 158 struct pglist mlist;
160 const char *enaddrstr; 159 const char *enaddrstr;
161 char enaddr[6]; 160 char enaddr[ETHER_ADDR_LEN];
162 char pbuf[9]; 161 char pbuf[9];
163 int i, error; 162 int i, error;
164 163
165 sc->sc_dev = self; 164 sc->sc_dev = self;
166 lesc->sc_st = oa->oa_st; 165 lesc->sc_st = oa->oa_st;
167 166
168 enaddrstr = ARCBIOS->GetEnvironmentVariable("eaddr"); 167 enaddrstr = ARCBIOS->GetEnvironmentVariable("eaddr");
169 if (enaddrstr == NULL) { 168 if (enaddrstr == NULL) {
170 aprint_error(": failed to obtain MAC address\n"); 169 aprint_error(": failed to obtain MAC address\n");
171 return; 170 return;
172 } 171 }
173 172
174 if ((error = bus_space_subregion(oa->oa_st, oa->oa_sh, OIOC_LANCE_RDP, 173 if ((error = bus_space_subregion(oa->oa_st, oa->oa_sh, OIOC_LANCE_RDP,
@@ -201,27 +200,27 @@ le_attach(device_t parent, device_t self @@ -201,27 +200,27 @@ le_attach(device_t parent, device_t self
201 /* Use IOC to map the physical memory into the Ethernet chip's space. */ 200 /* Use IOC to map the physical memory into the Ethernet chip's space. */
202 for (i = 0; i < OIOC_LANCE_NPAGES; i++) { 201 for (i = 0; i < OIOC_LANCE_NPAGES; i++) {
203 bus_space_write_2(lesc->sc_st,lesc->sc_maph, 202 bus_space_write_2(lesc->sc_st,lesc->sc_maph,
204 OIOC_ENET_PGMAP_OFF(i), 203 OIOC_ENET_PGMAP_OFF(i),
205 (VM_PAGE_TO_PHYS(mlist.tqh_first) >> PAGE_SHIFT) + i); 204 (VM_PAGE_TO_PHYS(mlist.tqh_first) >> PAGE_SHIFT) + i);
206 } 205 }
207 206
208 sc->sc_mem = (void *)MIPS_PHYS_TO_KSEG1( 207 sc->sc_mem = (void *)MIPS_PHYS_TO_KSEG1(
209 (uint32_t)VM_PAGE_TO_PHYS(mlist.tqh_first)); 208 (uint32_t)VM_PAGE_TO_PHYS(mlist.tqh_first));
210 sc->sc_memsize = OIOC_LANCE_NPAGES * PAGE_SIZE; 209 sc->sc_memsize = OIOC_LANCE_NPAGES * PAGE_SIZE;
211 sc->sc_addr = 0; 210 sc->sc_addr = 0;
212 sc->sc_conf3 = LE_C3_BSWP; 211 sc->sc_conf3 = LE_C3_BSWP;
213 212
214 enaddr_aton(enaddrstr, enaddr); 213 ether_aton_r(enaddr, sizeof(enaddr), enaddrstr);
215 memcpy(sc->sc_enaddr, enaddr, sizeof(sc->sc_enaddr)); 214 memcpy(sc->sc_enaddr, enaddr, sizeof(sc->sc_enaddr));
216 215
217 if (cpu_intr_establish(oa->oa_irq, IPL_NET, am7990_intr, sc) == NULL) { 216 if (cpu_intr_establish(oa->oa_irq, IPL_NET, am7990_intr, sc) == NULL) {
218 aprint_error(": failed to establish interrupt %d\n",oa->oa_irq); 217 aprint_error(": failed to establish interrupt %d\n",oa->oa_irq);
219 goto fail_4; 218 goto fail_4;
220 } 219 }
221 220
222 sc->sc_copytodesc = lance_copytobuf_contig; 221 sc->sc_copytodesc = lance_copytobuf_contig;
223 sc->sc_copyfromdesc = lance_copyfrombuf_contig; 222 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
224 sc->sc_copytobuf = lance_copytobuf_contig; 223 sc->sc_copytobuf = lance_copytobuf_contig;
225 sc->sc_copyfrombuf = lance_copyfrombuf_contig; 224 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
226 sc->sc_zerobuf = lance_zerobuf_contig; 225 sc->sc_zerobuf = lance_zerobuf_contig;
227 226
@@ -238,40 +237,13 @@ le_attach(device_t parent, device_t self @@ -238,40 +237,13 @@ le_attach(device_t parent, device_t self
238 return; 237 return;
239 238
240fail_4: 239fail_4:
241 uvm_pglistfree(&mlist); 240 uvm_pglistfree(&mlist);
242fail_3: 241fail_3:
243 bus_space_unmap(oa->oa_st, oa->oa_sh, lesc->sc_maph); 242 bus_space_unmap(oa->oa_st, oa->oa_sh, lesc->sc_maph);
244fail_2: 243fail_2:
245 bus_space_unmap(oa->oa_st, oa->oa_sh, lesc->sc_raph); 244 bus_space_unmap(oa->oa_st, oa->oa_sh, lesc->sc_raph);
246fail_1: 245fail_1:
247 bus_space_unmap(oa->oa_st, oa->oa_sh, lesc->sc_rdph); 246 bus_space_unmap(oa->oa_st, oa->oa_sh, lesc->sc_rdph);
248fail_0: 247fail_0:
249 return; 248 return;
250} 249}
251 
252/* stolen from sgimips/hpc/if_sq.c */ 
253static void 
254enaddr_aton(const char *str, u_int8_t *eaddr) 
255{ 
256 int i; 
257 char c; 
258 
259 for (i = 0; i < ETHER_ADDR_LEN; i++) { 
260 if (*str == ':') 
261 str++; 
262 
263 c = *str++; 
264 if (isdigit(c)) { 
265 eaddr[i] = (c - '0'); 
266 } else if (isxdigit(c)) { 
267 eaddr[i] = (toupper(c) + 10 - 'A'); 
268 } 
269 
270 c = *str++; 
271 if (isdigit(c)) { 
272 eaddr[i] = (eaddr[i] << 4) | (c - '0'); 
273 } else if (isxdigit(c)) { 
274 eaddr[i] = (eaddr[i] << 4) | (toupper(c) + 10 - 'A'); 
275 } 
276 } 
277} 

cvs diff -r1.43 -r1.44 src/sys/arch/sgimips/mace/if_mec.c (expand / switch to unified diff)

--- src/sys/arch/sgimips/mace/if_mec.c 2010/04/05 07:19:32 1.43
+++ src/sys/arch/sgimips/mace/if_mec.c 2011/01/10 13:29:29 1.44
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_mec.c,v 1.43 2010/04/05 07:19:32 joerg Exp $ */ 1/* $NetBSD: if_mec.c,v 1.44 2011/01/10 13:29:29 tsutsui Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004, 2008 Izumi Tsutsui. All rights reserved. 4 * Copyright (c) 2004, 2008 Izumi Tsutsui. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -51,27 +51,27 @@ @@ -51,27 +51,27 @@
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 */ 57 */
58 58
59/* 59/*
60 * MACE MAC-110 Ethernet driver 60 * MACE MAC-110 Ethernet driver
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64__KERNEL_RCSID(0, "$NetBSD: if_mec.c,v 1.43 2010/04/05 07:19:32 joerg Exp $"); 64__KERNEL_RCSID(0, "$NetBSD: if_mec.c,v 1.44 2011/01/10 13:29:29 tsutsui Exp $");
65 65
66#include "opt_ddb.h" 66#include "opt_ddb.h"
67#include "rnd.h" 67#include "rnd.h"
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/systm.h> 70#include <sys/systm.h>
71#include <sys/device.h> 71#include <sys/device.h>
72#include <sys/callout.h> 72#include <sys/callout.h>
73#include <sys/mbuf.h> 73#include <sys/mbuf.h>
74#include <sys/malloc.h> 74#include <sys/malloc.h>
75#include <sys/kernel.h> 75#include <sys/kernel.h>
76#include <sys/socket.h> 76#include <sys/socket.h>
77#include <sys/ioctl.h> 77#include <sys/ioctl.h>
@@ -387,28 +387,26 @@ struct mec_softc { @@ -387,28 +387,26 @@ struct mec_softc {
387 387
388/* XXX these values should be moved to <net/if_ether.h> ? */ 388/* XXX these values should be moved to <net/if_ether.h> ? */
389#define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN) 389#define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
390#define MEC_ETHER_ALIGN 2 390#define MEC_ETHER_ALIGN 2
391 391
392static int mec_match(device_t, cfdata_t, void *); 392static int mec_match(device_t, cfdata_t, void *);
393static void mec_attach(device_t, device_t, void *); 393static void mec_attach(device_t, device_t, void *);
394 394
395static int mec_mii_readreg(device_t, int, int); 395static int mec_mii_readreg(device_t, int, int);
396static void mec_mii_writereg(device_t, int, int, int); 396static void mec_mii_writereg(device_t, int, int, int);
397static int mec_mii_wait(struct mec_softc *); 397static int mec_mii_wait(struct mec_softc *);
398static void mec_statchg(device_t); 398static void mec_statchg(device_t);
399 399
400static void enaddr_aton(const char *, uint8_t *); 
401 
402static int mec_init(struct ifnet * ifp); 400static int mec_init(struct ifnet * ifp);
403static void mec_start(struct ifnet *); 401static void mec_start(struct ifnet *);
404static void mec_watchdog(struct ifnet *); 402static void mec_watchdog(struct ifnet *);
405static void mec_tick(void *); 403static void mec_tick(void *);
406static int mec_ioctl(struct ifnet *, u_long, void *); 404static int mec_ioctl(struct ifnet *, u_long, void *);
407static void mec_reset(struct mec_softc *); 405static void mec_reset(struct mec_softc *);
408static void mec_setfilter(struct mec_softc *); 406static void mec_setfilter(struct mec_softc *);
409static int mec_intr(void *arg); 407static int mec_intr(void *arg);
410static void mec_stop(struct ifnet *, int); 408static void mec_stop(struct ifnet *, int);
411static void mec_rxintr(struct mec_softc *); 409static void mec_rxintr(struct mec_softc *);
412static void mec_rxcsum(struct mec_softc *, struct mbuf *, uint16_t, 410static void mec_rxcsum(struct mec_softc *, struct mbuf *, uint16_t,
413 uint32_t); 411 uint32_t);
414static void mec_txintr(struct mec_softc *, uint32_t); 412static void mec_txintr(struct mec_softc *, uint32_t);
@@ -541,27 +539,27 @@ mec_attach(device_t parent, device_t sel @@ -541,27 +539,27 @@ mec_attach(device_t parent, device_t sel
541 if (*netaddr >= '0' && *netaddr <= '9') 539 if (*netaddr >= '0' && *netaddr <= '9')
542 v = v*10 + (*netaddr - '0'); 540 v = v*10 + (*netaddr - '0');
543 netaddr++; 541 netaddr++;
544 } 542 }
545 ui <<= 8; 543 ui <<= 8;
546 ui |= v; 544 ui |= v;
547 if (*netaddr == '.') 545 if (*netaddr == '.')
548 netaddr++; 546 netaddr++;
549 } 547 }
550 } 548 }
551 memcpy(sc->sc_enaddr+3, ((uint8_t *)&ui)+1, 3); 549 memcpy(sc->sc_enaddr+3, ((uint8_t *)&ui)+1, 3);
552 } 550 }
553 if (!mac_is_fake) 551 if (!mac_is_fake)
554 enaddr_aton(macaddr, sc->sc_enaddr); 552 ether_aton_r(sc->sc_enaddr, sizeof(sc->sc_enaddr), macaddr);
555 553
556 /* set the Ethernet address */ 554 /* set the Ethernet address */
557 address = 0; 555 address = 0;
558 for (i = 0; i < ETHER_ADDR_LEN; i++) { 556 for (i = 0; i < ETHER_ADDR_LEN; i++) {
559 address = address << 8; 557 address = address << 8;
560 address |= sc->sc_enaddr[i]; 558 address |= sc->sc_enaddr[i];
561 } 559 }
562 bus_space_write_8(sc->sc_st, sc->sc_sh, MEC_STATION, address); 560 bus_space_write_8(sc->sc_st, sc->sc_sh, MEC_STATION, address);
563 561
564 /* reset device */ 562 /* reset device */
565 mec_reset(sc); 563 mec_reset(sc);
566 564
567 command = bus_space_read_8(sc->sc_st, sc->sc_sh, MEC_MAC_CONTROL); 565 command = bus_space_read_8(sc->sc_st, sc->sc_sh, MEC_MAC_CONTROL);
@@ -844,56 +842,26 @@ mec_statchg(device_t self) @@ -844,56 +842,26 @@ mec_statchg(device_t self)
844 MEC_MAC_FULL_DUPLEX | MEC_MAC_SPEED_SELECT); 842 MEC_MAC_FULL_DUPLEX | MEC_MAC_SPEED_SELECT);
845 843
846 /* must also set IPG here for duplex stuff ... */ 844 /* must also set IPG here for duplex stuff ... */
847 if ((sc->sc_mii.mii_media_active & IFM_FDX) != 0) { 845 if ((sc->sc_mii.mii_media_active & IFM_FDX) != 0) {
848 control |= MEC_MAC_FULL_DUPLEX; 846 control |= MEC_MAC_FULL_DUPLEX;
849 } else { 847 } else {
850 /* set IPG */ 848 /* set IPG */
851 control |= MEC_MAC_IPG_DEFAULT; 849 control |= MEC_MAC_IPG_DEFAULT;
852 } 850 }
853 851
854 bus_space_write_8(st, sh, MEC_MAC_CONTROL, control); 852 bus_space_write_8(st, sh, MEC_MAC_CONTROL, control);
855} 853}
856 854
857/* 
858 * XXX 
859 * maybe this function should be moved to common part 
860 * (sgimips/machdep.c or elsewhere) for all on-board network devices. 
861 */ 
862static void 
863enaddr_aton(const char *str, uint8_t *eaddr) 
864{ 
865 int i; 
866 char c; 
867 
868 for (i = 0; i < ETHER_ADDR_LEN; i++) { 
869 if (*str == ':') 
870 str++; 
871 
872 c = *str++; 
873 if (isdigit(c)) { 
874 eaddr[i] = (c - '0'); 
875 } else if (isxdigit(c)) { 
876 eaddr[i] = (toupper(c) + 10 - 'A'); 
877 } 
878 c = *str++; 
879 if (isdigit(c)) { 
880 eaddr[i] = (eaddr[i] << 4) | (c - '0'); 
881 } else if (isxdigit(c)) { 
882 eaddr[i] = (eaddr[i] << 4) | (toupper(c) + 10 - 'A'); 
883 } 
884 } 
885} 
886 
887static int 855static int
888mec_init(struct ifnet *ifp) 856mec_init(struct ifnet *ifp)
889{ 857{
890 struct mec_softc *sc = ifp->if_softc; 858 struct mec_softc *sc = ifp->if_softc;
891 bus_space_tag_t st = sc->sc_st; 859 bus_space_tag_t st = sc->sc_st;
892 bus_space_handle_t sh = sc->sc_sh; 860 bus_space_handle_t sh = sc->sc_sh;
893 struct mec_rxdesc *rxd; 861 struct mec_rxdesc *rxd;
894 int i, rc; 862 int i, rc;
895 863
896 /* cancel any pending I/O */ 864 /* cancel any pending I/O */
897 mec_stop(ifp, 0); 865 mec_stop(ifp, 0);
898 866
899 /* reset device */ 867 /* reset device */