| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_prom.c,v 1.7 2009/03/14 15:36:12 dsl Exp $ */ | | 1 | /* $NetBSD: if_prom.c,v 1.8 2011/01/09 16:28:40 tsutsui Exp $ */ |
2 | | | 2 | |
3 | /* Copyright (c) 1999 The NetBSD Foundation, Inc. | | 3 | /* Copyright (c) 1999 The NetBSD Foundation, Inc. |
4 | * All rights reserved. | | 4 | * All rights reserved. |
5 | * | | 5 | * |
6 | * This code is derived from software contributed to The NetBSD Foundation | | 6 | * This code is derived from software contributed to The NetBSD Foundation |
7 | * by Gregory McGarry. | | 7 | * by Gregory McGarry. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -113,58 +113,69 @@ prom_probe(struct netif *nif, void *mach | | | @@ -113,58 +113,69 @@ prom_probe(struct netif *nif, void *mach |
113 | | | 113 | |
114 | #ifdef NET_DEBUG | | 114 | #ifdef NET_DEBUG |
115 | printf("prom_probe: called\n"); | | 115 | printf("prom_probe: called\n"); |
116 | #endif | | 116 | #endif |
117 | return 0; | | 117 | return 0; |
118 | } | | 118 | } |
119 | | | 119 | |
120 | | | 120 | |
121 | void | | 121 | void |
122 | prom_init(struct iodesc *desc, void *machdep_hint) | | 122 | prom_init(struct iodesc *desc, void *machdep_hint) |
123 | { | | 123 | { |
124 | char *device = | | 124 | char *device = |
125 | ((struct netif *)desc->io_netif)->nif_driver->netif_bname; | | 125 | ((struct netif *)desc->io_netif)->nif_driver->netif_bname; |
126 | char *c, *enet; | | 126 | char *enet; |
127 | int i, j, num; | | 127 | uint8_t *cp, *dest; |
| | | 128 | int i; |
128 | | | 129 | |
129 | #ifdef NET_DEBUG | | 130 | #ifdef NET_DEBUG |
130 | printf("prom_init: called\n"); | | 131 | printf("prom_init: called\n"); |
131 | #endif | | 132 | #endif |
132 | | | 133 | |
133 | try_bootp = 1; | | 134 | try_bootp = 1; |
134 | | | 135 | |
135 | /* | | 136 | /* |
136 | * Get our hardware address (this prom call is one of the rare ones | | 137 | * Get our hardware address (this prom call is one of the rare ones |
137 | * which is the same for new and old proms) | | 138 | * which is the same for new and old proms) |
138 | */ | | 139 | */ |
139 | enet = (*callv->_getenv)("enet"); | | 140 | enet = (*callv->_getenv)("enet"); |
140 | | | 141 | |
| | | 142 | if (enet == NULL) { |
| | | 143 | printf("No `enet' environment variable found.\n" |
| | | 144 | "Set MAC address to `enet' manually by setenv command.\n"); |
| | | 145 | (*callv->_halt)((int *)0, 0); /* XXX */ |
| | | 146 | /* NOTREACHED */ |
| | | 147 | } |
| | | 148 | |
141 | #ifdef NET_DEBUG | | 149 | #ifdef NET_DEBUG |
142 | if (debug) | | 150 | if (debug) |
143 | printf("enet=%s\n", enet); | | 151 | printf("enet=%s\n", enet); |
144 | #endif | | 152 | #endif |
145 | | | 153 | |
146 | i=0; | | 154 | #define atox(c) (((c) < '9') ? ((c) - '0') : ((toupper(c) - 'A') + 10)) |
147 | c = enet; | | 155 | |
148 | for (i=0; i<6; i++) { | | 156 | cp = (uint8_t *)enet; |
149 | j = *c - '0'; | | 157 | dest = desc->myea; |
150 | num = (j<10?j:j-39); | | 158 | for (i = 0; i < 6; i++) { |
151 | num <<= 4; | | 159 | if (isxdigit(*cp)) { |
152 | c++; | | 160 | *dest = atox(*cp); |
153 | j = *c - '0'; | | 161 | cp++; |
154 | num += (j<10?j:j-39); | | 162 | if (isxdigit(*cp)) { |
155 | desc->myea[i] = num; | | 163 | *dest = (*dest << 4) | atox(*cp); |
156 | c++; | | 164 | cp++; |
157 | c++; /* skip '-' */ | | 165 | } |
| | | 166 | } |
| | | 167 | dest++; |
| | | 168 | cp++; /* skip '-' or ':' etc. */ |
158 | } | | 169 | } |
159 | | | 170 | |
160 | desc->xid = 0x66d30000; | | 171 | desc->xid = 0x66d30000; |
161 | | | 172 | |
162 | if (callv == &callvec) | | 173 | if (callv == &callvec) |
163 | sc_fd = prom_open(device, 0); | | 174 | sc_fd = prom_open(device, 0); |
164 | else | | 175 | else |
165 | sc_fd = (*callv->_bootinit)(device); | | 176 | sc_fd = (*callv->_bootinit)(device); |
166 | | | 177 | |
167 | if (sc_fd < 0) | | 178 | if (sc_fd < 0) |
168 | printf("problem initialising device\n"); | | 179 | printf("problem initialising device\n"); |
169 | } | | 180 | } |
170 | | | 181 | |