if_ie.c revision 1.6.8.2 1 1.6.8.2 nathanw /* $NetBSD: if_ie.c,v 1.6.8.2 2002/10/18 02:39:00 nathanw Exp $ */
2 1.6.8.2 nathanw
3 1.6.8.2 nathanw /*
4 1.6.8.2 nathanw * Copyright (c) 1995 Theo de Raadt
5 1.6.8.2 nathanw *
6 1.6.8.2 nathanw * Redistribution and use in source and binary forms, with or without
7 1.6.8.2 nathanw * modification, are permitted provided that the following conditions
8 1.6.8.2 nathanw * are met:
9 1.6.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
10 1.6.8.2 nathanw * notice, this list of conditions and the following disclaimer.
11 1.6.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
12 1.6.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
13 1.6.8.2 nathanw * documentation and/or other materials provided with the distribution.
14 1.6.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
15 1.6.8.2 nathanw * must display the following acknowledgement:
16 1.6.8.2 nathanw * This product includes software developed under OpenBSD by
17 1.6.8.2 nathanw * Theo de Raadt for Willowglen Singapore.
18 1.6.8.2 nathanw * 4. The name of the author may not be used to endorse or promote products
19 1.6.8.2 nathanw * derived from this software without specific prior written permission.
20 1.6.8.2 nathanw *
21 1.6.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 1.6.8.2 nathanw * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 1.6.8.2 nathanw * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.6.8.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 1.6.8.2 nathanw * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.6.8.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.6.8.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.6.8.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.6.8.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.6.8.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.6.8.2 nathanw * SUCH DAMAGE.
32 1.6.8.2 nathanw */
33 1.6.8.2 nathanw
34 1.6.8.2 nathanw #include <sys/param.h>
35 1.6.8.2 nathanw #include <sys/types.h>
36 1.6.8.2 nathanw #include <sys/socket.h>
37 1.6.8.2 nathanw
38 1.6.8.2 nathanw #include <netinet/in.h>
39 1.6.8.2 nathanw #include <netinet/in_systm.h>
40 1.6.8.2 nathanw
41 1.6.8.2 nathanw #include <net/if.h>
42 1.6.8.2 nathanw #include <net/if_ether.h>
43 1.6.8.2 nathanw
44 1.6.8.2 nathanw #include <lib/libkern/libkern.h>
45 1.6.8.2 nathanw #include <lib/libsa/stand.h>
46 1.6.8.2 nathanw #include <lib/libsa/net.h>
47 1.6.8.2 nathanw
48 1.6.8.2 nathanw #define NTXBUF 1
49 1.6.8.2 nathanw #define NRXBUF 16
50 1.6.8.2 nathanw #define IE_RBUF_SIZE ETHER_MAX_LEN
51 1.6.8.2 nathanw
52 1.6.8.2 nathanw #include <machine/prom.h>
53 1.6.8.2 nathanw
54 1.6.8.2 nathanw #include "libsa.h"
55 1.6.8.2 nathanw #include "netif.h"
56 1.6.8.2 nathanw #include "config.h"
57 1.6.8.2 nathanw #include "dev_net.h"
58 1.6.8.2 nathanw
59 1.6.8.2 nathanw #include "i82586.h"
60 1.6.8.2 nathanw #include "if_iereg.h"
61 1.6.8.2 nathanw
62 1.6.8.2 nathanw int ie_debug = 0;
63 1.6.8.2 nathanw
64 1.6.8.2 nathanw void ie_stop __P((struct netif *));
65 1.6.8.2 nathanw void ie_end __P((struct netif *));
66 1.6.8.2 nathanw void ie_error __P((struct netif *, char *, volatile struct iereg *));
67 1.6.8.2 nathanw int ie_get __P((struct iodesc *, void *, size_t, time_t));
68 1.6.8.2 nathanw void ie_init __P((struct iodesc *, void *));
69 1.6.8.2 nathanw int ie_match __P((struct netif *, void *));
70 1.6.8.2 nathanw int ie_poll __P((struct iodesc *, void *, int));
71 1.6.8.2 nathanw int ie_probe __P((struct netif *, void *));
72 1.6.8.2 nathanw int ie_put __P((struct iodesc *, void *, size_t));
73 1.6.8.2 nathanw void ie_reset __P((struct netif *, u_char *));
74 1.6.8.2 nathanw void ieack __P((volatile struct iereg *, struct iemem *));
75 1.6.8.2 nathanw
76 1.6.8.2 nathanw struct netif_stats ie_stats;
77 1.6.8.2 nathanw
78 1.6.8.2 nathanw struct netif_dif ie0_dif = {
79 1.6.8.2 nathanw 0, /* unit */
80 1.6.8.2 nathanw 1, /* nsel */
81 1.6.8.2 nathanw &ie_stats,
82 1.6.8.2 nathanw 0,
83 1.6.8.2 nathanw 0,
84 1.6.8.2 nathanw };
85 1.6.8.2 nathanw
86 1.6.8.2 nathanw struct netif_driver ie_driver = {
87 1.6.8.2 nathanw "ie", /* netif_bname */
88 1.6.8.2 nathanw ie_match, /* match */
89 1.6.8.2 nathanw ie_probe, /* probe */
90 1.6.8.2 nathanw ie_init, /* init */
91 1.6.8.2 nathanw ie_get, /* get */
92 1.6.8.2 nathanw ie_put, /* put */
93 1.6.8.2 nathanw ie_end, /* end */
94 1.6.8.2 nathanw &ie0_dif, /* netif_ifs */
95 1.6.8.2 nathanw 1, /* netif_nifs */
96 1.6.8.2 nathanw };
97 1.6.8.2 nathanw
98 1.6.8.2 nathanw struct ie_configuration {
99 1.6.8.2 nathanw u_int phys_addr;
100 1.6.8.2 nathanw int used;
101 1.6.8.2 nathanw } ie_config[] = {
102 1.6.8.2 nathanw { INTEL_REG_ADDR, 0 }
103 1.6.8.2 nathanw };
104 1.6.8.2 nathanw
105 1.6.8.2 nathanw int nie_config = sizeof(ie_config) / (sizeof(ie_config[0]));
106 1.6.8.2 nathanw
107 1.6.8.2 nathanw struct {
108 1.6.8.2 nathanw struct iereg *sc_reg; /* IE registers */
109 1.6.8.2 nathanw struct iemem *sc_mem; /* RAM */
110 1.6.8.2 nathanw } ie_softc;
111 1.6.8.2 nathanw
112 1.6.8.2 nathanw int
113 1.6.8.2 nathanw ie_match(nif, machdep_hint)
114 1.6.8.2 nathanw struct netif *nif;
115 1.6.8.2 nathanw void *machdep_hint;
116 1.6.8.2 nathanw {
117 1.6.8.2 nathanw char *name;
118 1.6.8.2 nathanw int i, val = 0;
119 1.6.8.2 nathanw
120 1.6.8.2 nathanw if (bugargs.cputyp == CPU_147)
121 1.6.8.2 nathanw return (0);
122 1.6.8.2 nathanw name = machdep_hint;
123 1.6.8.2 nathanw if (name && !memcmp(ie_driver.netif_bname, name, 2))
124 1.6.8.2 nathanw val += 10;
125 1.6.8.2 nathanw for (i = 0; i < nie_config; i++) {
126 1.6.8.2 nathanw if (ie_config[i].used)
127 1.6.8.2 nathanw continue;
128 1.6.8.2 nathanw if (ie_debug)
129 1.6.8.2 nathanw printf("ie%d: ie_match --> %d\n", i, val + 1);
130 1.6.8.2 nathanw ie_config[i].used++;
131 1.6.8.2 nathanw return (val + 1);
132 1.6.8.2 nathanw }
133 1.6.8.2 nathanw if (ie_debug)
134 1.6.8.2 nathanw printf("ie%d: ie_match --> 0\n", i);
135 1.6.8.2 nathanw return (0);
136 1.6.8.2 nathanw }
137 1.6.8.2 nathanw
138 1.6.8.2 nathanw int
139 1.6.8.2 nathanw ie_probe(nif, machdep_hint)
140 1.6.8.2 nathanw struct netif *nif;
141 1.6.8.2 nathanw void *machdep_hint;
142 1.6.8.2 nathanw {
143 1.6.8.2 nathanw
144 1.6.8.2 nathanw /* the set unit is the current unit */
145 1.6.8.2 nathanw if (ie_debug)
146 1.6.8.2 nathanw printf("ie%d: ie_probe called\n", nif->nif_unit);
147 1.6.8.2 nathanw
148 1.6.8.2 nathanw if (bugargs.cputyp != CPU_147)
149 1.6.8.2 nathanw return (0);
150 1.6.8.2 nathanw return (1);
151 1.6.8.2 nathanw }
152 1.6.8.2 nathanw
153 1.6.8.2 nathanw void
154 1.6.8.2 nathanw ie_error(nif, str, ier)
155 1.6.8.2 nathanw struct netif *nif;
156 1.6.8.2 nathanw char *str;
157 1.6.8.2 nathanw volatile struct iereg *ier;
158 1.6.8.2 nathanw {
159 1.6.8.2 nathanw panic("ie%d: unknown error", nif->nif_unit);
160 1.6.8.2 nathanw }
161 1.6.8.2 nathanw
162 1.6.8.2 nathanw void
163 1.6.8.2 nathanw ieack(ier, iem)
164 1.6.8.2 nathanw volatile struct iereg *ier;
165 1.6.8.2 nathanw struct iemem *iem;
166 1.6.8.2 nathanw {
167 1.6.8.2 nathanw /* ack the `interrupt' */
168 1.6.8.2 nathanw iem->im_scb.ie_command = iem->im_scb.ie_status & IE_ST_WHENCE;
169 1.6.8.2 nathanw ier->ie_attention = 1; /* chan attention! */
170 1.6.8.2 nathanw while (iem->im_scb.ie_command)
171 1.6.8.2 nathanw ;
172 1.6.8.2 nathanw }
173 1.6.8.2 nathanw
174 1.6.8.2 nathanw void
175 1.6.8.2 nathanw ie_reset(nif, myea)
176 1.6.8.2 nathanw struct netif *nif;
177 1.6.8.2 nathanw u_char *myea;
178 1.6.8.2 nathanw {
179 1.6.8.2 nathanw volatile struct iereg *ier = ie_softc.sc_reg;
180 1.6.8.2 nathanw struct iemem *iem = ie_softc.sc_mem;
181 1.6.8.2 nathanw int timo = 10000, i;
182 1.6.8.2 nathanw volatile int t;
183 1.6.8.2 nathanw u_int a;
184 1.6.8.2 nathanw
185 1.6.8.2 nathanw if (ie_debug)
186 1.6.8.2 nathanw printf("ie%d: ie_reset called\n", nif->nif_unit);
187 1.6.8.2 nathanw
188 1.6.8.2 nathanw /*printf("ier %x iem %x\n", ier, iem);*/
189 1.6.8.2 nathanw
190 1.6.8.2 nathanw *(u_char *)0xfff4202a = 0x40;
191 1.6.8.2 nathanw
192 1.6.8.2 nathanw memset(iem, 0, sizeof(*iem));
193 1.6.8.2 nathanw iem->im_scp.scp_sysbus = 0;
194 1.6.8.2 nathanw iem->im_scp.scp_iscp_low = (int) &iem->im_iscp & 0xffff;
195 1.6.8.2 nathanw iem->im_scp.scp_iscp_high = (int) &iem->im_iscp >> 16;
196 1.6.8.2 nathanw
197 1.6.8.2 nathanw iem->im_iscp.iscp_scboffset = (int) &iem->im_scb - (int) iem;
198 1.6.8.2 nathanw iem->im_iscp.iscp_busy = 1;
199 1.6.8.2 nathanw iem->im_iscp.iscp_base_low = (int) iem & 0xffff;
200 1.6.8.2 nathanw iem->im_iscp.iscp_base_high = (int) iem >> 16;
201 1.6.8.2 nathanw
202 1.6.8.2 nathanw /*
203 1.6.8.2 nathanw * completely and utterly unlike what i expected, the
204 1.6.8.2 nathanw * "write" order is:
205 1.6.8.2 nathanw * 1st: d15-d0 -> high address
206 1.6.8.2 nathanw * 2nd: d31-d16 -> low address
207 1.6.8.2 nathanw */
208 1.6.8.2 nathanw
209 1.6.8.2 nathanw /* reset chip */
210 1.6.8.2 nathanw a = IE_PORT_RESET;
211 1.6.8.2 nathanw ier->ie_porthigh = a & 0xffff;
212 1.6.8.2 nathanw t = 0;
213 1.6.8.2 nathanw t = 1;
214 1.6.8.2 nathanw ier->ie_portlow = a >> 16;
215 1.6.8.2 nathanw for (t = timo; t--;)
216 1.6.8.2 nathanw ;
217 1.6.8.2 nathanw
218 1.6.8.2 nathanw /* set new SCP pointer */
219 1.6.8.2 nathanw a = (int) &iem->im_scp | IE_PORT_NEWSCP;
220 1.6.8.2 nathanw ier->ie_porthigh = a & 0xffff;
221 1.6.8.2 nathanw t = 0;
222 1.6.8.2 nathanw t = 1;
223 1.6.8.2 nathanw ier->ie_portlow = a >> 16;
224 1.6.8.2 nathanw for (t = timo; t--;)
225 1.6.8.2 nathanw ;
226 1.6.8.2 nathanw
227 1.6.8.2 nathanw ier->ie_attention = 1; /* chan attention! */
228 1.6.8.2 nathanw for (t = timo * 10; t--;)
229 1.6.8.2 nathanw ;
230 1.6.8.2 nathanw
231 1.6.8.2 nathanw /* send CONFIGURE command */
232 1.6.8.2 nathanw iem->im_scb.ie_command = IE_CU_START;
233 1.6.8.2 nathanw iem->im_scb.ie_command_list = (int) &iem->im_cc - (int) iem;
234 1.6.8.2 nathanw iem->im_cc.com.ie_cmd_status = 0;
235 1.6.8.2 nathanw iem->im_cc.com.ie_cmd_cmd = IE_CMD_CONFIG | IE_CMD_LAST;
236 1.6.8.2 nathanw iem->im_cc.com.ie_cmd_link = 0xffff;
237 1.6.8.2 nathanw iem->im_cc.ie_config_count = 0x0c;
238 1.6.8.2 nathanw iem->im_cc.ie_fifo = 8;
239 1.6.8.2 nathanw iem->im_cc.ie_save_bad = 0x40;
240 1.6.8.2 nathanw iem->im_cc.ie_addr_len = 0x2e;
241 1.6.8.2 nathanw iem->im_cc.ie_priority = 0;
242 1.6.8.2 nathanw iem->im_cc.ie_ifs = 0x60;
243 1.6.8.2 nathanw iem->im_cc.ie_slot_low = 0;
244 1.6.8.2 nathanw iem->im_cc.ie_slot_high = 0xf2;
245 1.6.8.2 nathanw iem->im_cc.ie_promisc = 0;
246 1.6.8.2 nathanw iem->im_cc.ie_crs_cdt = 0;
247 1.6.8.2 nathanw iem->im_cc.ie_min_len = 64;
248 1.6.8.2 nathanw iem->im_cc.ie_junk = 0xff;
249 1.6.8.2 nathanw
250 1.6.8.2 nathanw ier->ie_attention = 1; /* chan attention! */
251 1.6.8.2 nathanw for (t = timo * 10; t--;)
252 1.6.8.2 nathanw ;
253 1.6.8.2 nathanw
254 1.6.8.2 nathanw ieack(ier, iem);
255 1.6.8.2 nathanw
256 1.6.8.2 nathanw /*printf("ic %x\n", &iem->im_ic);*/
257 1.6.8.2 nathanw /* send IASETUP command */
258 1.6.8.2 nathanw iem->im_scb.ie_command = IE_CU_START;
259 1.6.8.2 nathanw iem->im_scb.ie_command_list = (int) &iem->im_ic - (int) iem;
260 1.6.8.2 nathanw iem->im_ic.com.ie_cmd_status = 0;
261 1.6.8.2 nathanw iem->im_ic.com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST;
262 1.6.8.2 nathanw iem->im_ic.com.ie_cmd_link = 0xffff;
263 1.6.8.2 nathanw memcpy((void *)&iem->im_ic.ie_address, myea,
264 1.6.8.2 nathanw sizeof iem->im_ic.ie_address);
265 1.6.8.2 nathanw
266 1.6.8.2 nathanw ier->ie_attention = 1; /* chan attention! */
267 1.6.8.2 nathanw for (t = timo * 10; t--;)
268 1.6.8.2 nathanw ;
269 1.6.8.2 nathanw
270 1.6.8.2 nathanw ieack(ier, iem);
271 1.6.8.2 nathanw
272 1.6.8.2 nathanw /* setup buffers */
273 1.6.8.2 nathanw
274 1.6.8.2 nathanw for (i = 0; i < NRXBUF; i++) {
275 1.6.8.2 nathanw iem->im_rfd[i].ie_fd_next = (int) &iem->im_rfd[(i+1) % NRXBUF] -
276 1.6.8.2 nathanw (int) iem;
277 1.6.8.2 nathanw iem->im_rbd[i].ie_rbd_next = (int) &iem->im_rbd[(i+1) % NRXBUF] -
278 1.6.8.2 nathanw (int) iem;
279 1.6.8.2 nathanw a = (int) &iem->im_rxbuf[i * IE_RBUF_SIZE];
280 1.6.8.2 nathanw iem->im_rbd[i].ie_rbd_buffer_low = a & 0xffff;
281 1.6.8.2 nathanw iem->im_rbd[i].ie_rbd_buffer_high = a >> 16;
282 1.6.8.2 nathanw iem->im_rbd[i].ie_rbd_length = IE_RBUF_SIZE;
283 1.6.8.2 nathanw }
284 1.6.8.2 nathanw iem->im_rfd[NRXBUF-1].ie_fd_last |= IE_FD_LAST;
285 1.6.8.2 nathanw iem->im_rbd[NRXBUF-1].ie_rbd_length |= IE_RBD_LAST;
286 1.6.8.2 nathanw iem->im_rfd[0].ie_fd_buf_desc = (int) &iem->im_rbd[0] - (int) iem;
287 1.6.8.2 nathanw
288 1.6.8.2 nathanw /*printf("rfd[0] %x rbd[0] %x buf[0] %x\n", &iem->im_rfd, &iem->im_rbd,
289 1.6.8.2 nathanw &iem->im_rxbuf);*/
290 1.6.8.2 nathanw
291 1.6.8.2 nathanw /* send receiver start command */
292 1.6.8.2 nathanw iem->im_scb.ie_command = IE_RU_START;
293 1.6.8.2 nathanw iem->im_scb.ie_command_list = 0;
294 1.6.8.2 nathanw iem->im_scb.ie_recv_list = (int) &iem->im_rfd[0] - (int) iem;
295 1.6.8.2 nathanw ier->ie_attention = 1; /* chan attention! */
296 1.6.8.2 nathanw while (iem->im_scb.ie_command)
297 1.6.8.2 nathanw ;
298 1.6.8.2 nathanw
299 1.6.8.2 nathanw ieack(ier, iem);
300 1.6.8.2 nathanw }
301 1.6.8.2 nathanw
302 1.6.8.2 nathanw int
303 1.6.8.2 nathanw ie_poll(desc, pkt, len)
304 1.6.8.2 nathanw struct iodesc *desc;
305 1.6.8.2 nathanw void *pkt;
306 1.6.8.2 nathanw int len;
307 1.6.8.2 nathanw {
308 1.6.8.2 nathanw volatile struct iereg *ier = ie_softc.sc_reg;
309 1.6.8.2 nathanw struct iemem *iem = ie_softc.sc_mem;
310 1.6.8.2 nathanw static int slot;
311 1.6.8.2 nathanw int length = 0;
312 1.6.8.2 nathanw u_short status;
313 1.6.8.2 nathanw
314 1.6.8.2 nathanw asm(".word 0xf518\n");
315 1.6.8.2 nathanw status = iem->im_rfd[slot].ie_fd_status;
316 1.6.8.2 nathanw if (status & IE_FD_BUSY)
317 1.6.8.2 nathanw return (0);
318 1.6.8.2 nathanw
319 1.6.8.2 nathanw /* printf("slot %d: %x\n", slot, status); */
320 1.6.8.2 nathanw if ((status & (IE_FD_COMPLETE | IE_FD_OK)) == (IE_FD_COMPLETE | IE_FD_OK)) {
321 1.6.8.2 nathanw if (status & IE_FD_OK) {
322 1.6.8.2 nathanw length = iem->im_rbd[slot].ie_rbd_actual & 0x3fff;
323 1.6.8.2 nathanw if (length > len)
324 1.6.8.2 nathanw length = len;
325 1.6.8.2 nathanw memcpy(pkt, (void *)&iem->im_rxbuf[slot * IE_RBUF_SIZE],
326 1.6.8.2 nathanw length);
327 1.6.8.2 nathanw
328 1.6.8.2 nathanw iem->im_rfd[slot].ie_fd_status = 0;
329 1.6.8.2 nathanw iem->im_rfd[slot].ie_fd_last |= IE_FD_LAST;
330 1.6.8.2 nathanw iem->im_rfd[(slot+NRXBUF-1)%NRXBUF].ie_fd_last &=
331 1.6.8.2 nathanw ~IE_FD_LAST;
332 1.6.8.2 nathanw iem->im_rbd[slot].ie_rbd_actual = 0;
333 1.6.8.2 nathanw iem->im_rbd[slot].ie_rbd_length |= IE_RBD_LAST;
334 1.6.8.2 nathanw iem->im_rbd[(slot+NRXBUF-1)%NRXBUF].ie_rbd_length &=
335 1.6.8.2 nathanw ~IE_RBD_LAST;
336 1.6.8.2 nathanw /*printf("S%d\n", slot);*/
337 1.6.8.2 nathanw
338 1.6.8.2 nathanw } else {
339 1.6.8.2 nathanw printf("shit\n");
340 1.6.8.2 nathanw }
341 1.6.8.2 nathanw slot++;
342 1.6.8.2 nathanw /* should move descriptor onto end of queue... */
343 1.6.8.2 nathanw }
344 1.6.8.2 nathanw if ((iem->im_scb.ie_status & IE_RU_READY) == 0) {
345 1.6.8.2 nathanw printf("RR\n");
346 1.6.8.2 nathanw
347 1.6.8.2 nathanw for (slot = 0; slot < NRXBUF; slot++) {
348 1.6.8.2 nathanw iem->im_rbd[slot].ie_rbd_length &= ~IE_RBD_LAST;
349 1.6.8.2 nathanw iem->im_rfd[slot].ie_fd_last &= ~IE_FD_LAST;
350 1.6.8.2 nathanw }
351 1.6.8.2 nathanw iem->im_rbd[NRXBUF-1].ie_rbd_length |= IE_RBD_LAST;
352 1.6.8.2 nathanw iem->im_rfd[NRXBUF-1].ie_fd_last |= IE_FD_LAST;
353 1.6.8.2 nathanw
354 1.6.8.2 nathanw iem->im_rfd[0].ie_fd_buf_desc = (int)&iem->im_rbd[0] - (int)iem;
355 1.6.8.2 nathanw
356 1.6.8.2 nathanw iem->im_scb.ie_command = IE_RU_START;
357 1.6.8.2 nathanw iem->im_scb.ie_command_list = 0;
358 1.6.8.2 nathanw iem->im_scb.ie_recv_list = (int)&iem->im_rfd[0] - (int)iem;
359 1.6.8.2 nathanw ier->ie_attention = 1; /* chan attention! */
360 1.6.8.2 nathanw while (iem->im_scb.ie_command)
361 1.6.8.2 nathanw ;
362 1.6.8.2 nathanw slot = 0;
363 1.6.8.2 nathanw }
364 1.6.8.2 nathanw slot = slot % NRXBUF;
365 1.6.8.2 nathanw return (length);
366 1.6.8.2 nathanw }
367 1.6.8.2 nathanw
368 1.6.8.2 nathanw int
369 1.6.8.2 nathanw ie_put(desc, pkt, len)
370 1.6.8.2 nathanw struct iodesc *desc;
371 1.6.8.2 nathanw void *pkt;
372 1.6.8.2 nathanw size_t len;
373 1.6.8.2 nathanw {
374 1.6.8.2 nathanw volatile struct iereg *ier = ie_softc.sc_reg;
375 1.6.8.2 nathanw struct iemem *iem = ie_softc.sc_mem;
376 1.6.8.2 nathanw u_char *p = pkt;
377 1.6.8.2 nathanw u_int a;
378 1.6.8.2 nathanw int xx = 0;
379 1.6.8.2 nathanw
380 1.6.8.2 nathanw /* send transmit command */
381 1.6.8.2 nathanw
382 1.6.8.2 nathanw while (iem->im_scb.ie_command)
383 1.6.8.2 nathanw ;
384 1.6.8.2 nathanw
385 1.6.8.2 nathanw /* copy data */
386 1.6.8.2 nathanw memcpy((void *)&iem->im_txbuf[xx], p, len);
387 1.6.8.2 nathanw
388 1.6.8.2 nathanw len = MAX(len, ETHER_MIN_LEN);
389 1.6.8.2 nathanw
390 1.6.8.2 nathanw /* build transmit descriptor */
391 1.6.8.2 nathanw iem->im_xd[xx].ie_xmit_flags = len | IE_XMIT_LAST;
392 1.6.8.2 nathanw iem->im_xd[xx].ie_xmit_next = 0xffff;
393 1.6.8.2 nathanw a = (int) &iem->im_txbuf[xx];
394 1.6.8.2 nathanw iem->im_xd[xx].ie_xmit_buf_low = a & 0xffff;
395 1.6.8.2 nathanw iem->im_xd[xx].ie_xmit_buf_high = a >> 16;
396 1.6.8.2 nathanw
397 1.6.8.2 nathanw /* transmit command */
398 1.6.8.2 nathanw iem->im_xc[xx].com.ie_cmd_status = 0;
399 1.6.8.2 nathanw iem->im_xc[xx].com.ie_cmd_cmd = IE_CMD_XMIT | IE_CMD_LAST;
400 1.6.8.2 nathanw iem->im_xc[xx].com.ie_cmd_link = 0xffff;
401 1.6.8.2 nathanw iem->im_xc[xx].ie_xmit_desc = (int) &iem->im_xd[xx] - (int) iem;
402 1.6.8.2 nathanw iem->im_xc[xx].ie_xmit_length = len;
403 1.6.8.2 nathanw memcpy((void *)&iem->im_xc[xx].ie_xmit_addr, p,
404 1.6.8.2 nathanw sizeof iem->im_xc[xx].ie_xmit_addr);
405 1.6.8.2 nathanw
406 1.6.8.2 nathanw iem->im_scb.ie_command = IE_CU_START;
407 1.6.8.2 nathanw iem->im_scb.ie_command_list = (int) &iem->im_xc[xx] - (int) iem;
408 1.6.8.2 nathanw
409 1.6.8.2 nathanw ier->ie_attention = 1; /* chan attention! */
410 1.6.8.2 nathanw
411 1.6.8.2 nathanw if (ie_debug) {
412 1.6.8.2 nathanw printf("ie%d: send %d to %x:%x:%x:%x:%x:%x\n",
413 1.6.8.2 nathanw desc->io_netif->nif_unit, len,
414 1.6.8.2 nathanw p[0], p[1], p[2], p[3], p[4], p[5]);
415 1.6.8.2 nathanw }
416 1.6.8.2 nathanw return (len);
417 1.6.8.2 nathanw }
418 1.6.8.2 nathanw
419 1.6.8.2 nathanw int
420 1.6.8.2 nathanw ie_get(desc, pkt, len, timeout)
421 1.6.8.2 nathanw struct iodesc *desc;
422 1.6.8.2 nathanw void *pkt;
423 1.6.8.2 nathanw size_t len;
424 1.6.8.2 nathanw time_t timeout;
425 1.6.8.2 nathanw {
426 1.6.8.2 nathanw time_t t;
427 1.6.8.2 nathanw int cc;
428 1.6.8.2 nathanw
429 1.6.8.2 nathanw t = getsecs();
430 1.6.8.2 nathanw cc = 0;
431 1.6.8.2 nathanw while (((getsecs() - t) < timeout) && !cc) {
432 1.6.8.2 nathanw cc = ie_poll(desc, pkt, len);
433 1.6.8.2 nathanw }
434 1.6.8.2 nathanw return (cc);
435 1.6.8.2 nathanw }
436 1.6.8.2 nathanw /*
437 1.6.8.2 nathanw * init ie device. return 0 on failure, 1 if ok.
438 1.6.8.2 nathanw */
439 1.6.8.2 nathanw void
440 1.6.8.2 nathanw ie_init(desc, machdep_hint)
441 1.6.8.2 nathanw struct iodesc *desc;
442 1.6.8.2 nathanw void *machdep_hint;
443 1.6.8.2 nathanw {
444 1.6.8.2 nathanw struct netif *nif = desc->io_netif;
445 1.6.8.2 nathanw
446 1.6.8.2 nathanw if (ie_debug)
447 1.6.8.2 nathanw printf("ie%d: ie_init called\n", desc->io_netif->nif_unit);
448 1.6.8.2 nathanw machdep_common_ether(desc->myea);
449 1.6.8.2 nathanw memset(&ie_softc, 0, sizeof(ie_softc));
450 1.6.8.2 nathanw ie_softc.sc_reg =
451 1.6.8.2 nathanw (struct iereg *) ie_config[desc->io_netif->nif_unit].phys_addr;
452 1.6.8.2 nathanw ie_softc.sc_mem = (struct iemem *) 0x3e0000;
453 1.6.8.2 nathanw ie_reset(desc->io_netif, desc->myea);
454 1.6.8.2 nathanw printf("device: %s%d attached to %s\n", nif->nif_driver->netif_bname,
455 1.6.8.2 nathanw nif->nif_unit, ether_sprintf(desc->myea));
456 1.6.8.2 nathanw }
457 1.6.8.2 nathanw
458 1.6.8.2 nathanw void
459 1.6.8.2 nathanw ie_stop(nif)
460 1.6.8.2 nathanw struct netif *nif;
461 1.6.8.2 nathanw {
462 1.6.8.2 nathanw volatile struct iereg *ier = ie_softc.sc_reg;
463 1.6.8.2 nathanw struct iemem *iem = ie_softc.sc_mem;
464 1.6.8.2 nathanw int timo = 10000;
465 1.6.8.2 nathanw volatile int t;
466 1.6.8.2 nathanw u_int a;
467 1.6.8.2 nathanw
468 1.6.8.2 nathanw iem->im_iscp.iscp_busy = 1;
469 1.6.8.2 nathanw /* reset chip */
470 1.6.8.2 nathanw a = IE_PORT_RESET;
471 1.6.8.2 nathanw ier->ie_porthigh = a & 0xffff;
472 1.6.8.2 nathanw t = 0;
473 1.6.8.2 nathanw t = 1;
474 1.6.8.2 nathanw ier->ie_portlow = a >> 16;
475 1.6.8.2 nathanw for (t = timo; t--;)
476 1.6.8.2 nathanw ;
477 1.6.8.2 nathanw
478 1.6.8.2 nathanw /* reset chip again */
479 1.6.8.2 nathanw a = IE_PORT_RESET;
480 1.6.8.2 nathanw ier->ie_porthigh = a & 0xffff;
481 1.6.8.2 nathanw t = 0;
482 1.6.8.2 nathanw t = 1;
483 1.6.8.2 nathanw ier->ie_portlow = a >> 16;
484 1.6.8.2 nathanw for (t = timo; t--;)
485 1.6.8.2 nathanw ;
486 1.6.8.2 nathanw
487 1.6.8.2 nathanw /*printf("status %x busy %x\n", iem->im_scb.ie_status,
488 1.6.8.2 nathanw iem->im_iscp.iscp_busy);*/
489 1.6.8.2 nathanw }
490 1.6.8.2 nathanw
491 1.6.8.2 nathanw void
492 1.6.8.2 nathanw ie_end(nif)
493 1.6.8.2 nathanw struct netif *nif;
494 1.6.8.2 nathanw {
495 1.6.8.2 nathanw if (ie_debug)
496 1.6.8.2 nathanw printf("ie%d: ie_end called\n", nif->nif_unit);
497 1.6.8.2 nathanw
498 1.6.8.2 nathanw ie_stop(nif);
499 1.6.8.2 nathanw
500 1.6.8.2 nathanw /* *(u_char *) 0xfff42002 = 0; */
501 1.6.8.2 nathanw }
502