Rev 4192 | Rev 4307 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4163 | mejdrech | 1 | /* |
2 | * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
||
3 | * |
||
4 | * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
||
5 | * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
||
6 | * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission. |
||
7 | * * Any deviations from these conditions require written permission from the copyright holder in advance |
||
8 | * |
||
9 | * |
||
10 | * Disclaimer |
||
11 | * |
||
12 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR |
||
13 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
14 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
15 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
16 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
17 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
18 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
19 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
20 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
21 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
22 | * |
||
23 | * Changes: |
||
4192 | mejdrech | 24 | * 2009 Lukas Mejdrech ported to HelenOS |
4163 | mejdrech | 25 | */ |
26 | |||
27 | /** @addtogroup dp8390 |
||
28 | * @{ |
||
29 | */ |
||
30 | |||
31 | #include <assert.h> |
||
32 | #include <errno.h> |
||
33 | |||
34 | #include "../../include/byteorder.h" |
||
35 | |||
4192 | mejdrech | 36 | #include "../../structures/packet/packet.h" |
37 | #include "../../structures/packet/packet_client.h" |
||
38 | |||
39 | #include "../netif.h" |
||
40 | |||
4163 | mejdrech | 41 | #include "dp8390_drv.h" |
4192 | mejdrech | 42 | #include "dp8390_module.h" |
4163 | mejdrech | 43 | #include "dp8390_port.h" |
44 | |||
45 | /* |
||
46 | * dp8390.c |
||
47 | * |
||
48 | * Created: before Dec 28, 1992 by Philip Homburg <philip@f-mnx.phicoh.com> |
||
49 | * |
||
50 | * Modified Mar 10 1994 by Philip Homburg |
||
51 | * Become a generic dp8390 driver. |
||
52 | * |
||
53 | * Modified Dec 20 1996 by G. Falzoni <falzoni@marina.scn.de> |
||
54 | * Added support for 3c503 boards. |
||
55 | */ |
||
56 | |||
57 | #include "local.h" |
||
58 | #include "dp8390.h" |
||
59 | |||
4192 | mejdrech | 60 | int queue_packet( dpeth_t * dep, packet_t packet ); |
61 | static void outsb( port_t port, void * buf, size_t size ); |
||
62 | static void outsw( port_t port, void * buf, size_t size ); |
||
63 | |||
4163 | mejdrech | 64 | //static u16_t eth_ign_proto; |
65 | //static char *progname; |
||
66 | |||
67 | /* Configuration */ |
||
68 | /*typedef struct dp_conf |
||
69 | { |
||
70 | port_t dpc_port; |
||
71 | int dpc_irq; |
||
72 | phys_bytes dpc_mem; |
||
73 | char *dpc_envvar; |
||
74 | } dp_conf_t; |
||
75 | */ |
||
76 | //dp_conf_t dp_conf[]= /* Card addresses */ |
||
77 | //{ |
||
78 | /* I/O port, IRQ, Buffer address, Env. var. */ |
||
79 | /* { 0x280, 3, 0xD0000, "DPETH0" }, |
||
80 | { 0x300, 5, 0xC8000, "DPETH1" }, |
||
81 | { 0x380, 10, 0xD8000, "DPETH2" }, |
||
82 | }; |
||
83 | */ |
||
84 | /* Test if dp_conf has exactly DE_PORT_NR entries. If not then you will see |
||
85 | * the error: "array size is negative". |
||
86 | */ |
||
87 | //extern int ___dummy[DE_PORT_NR == sizeof(dp_conf)/sizeof(dp_conf[0]) ? 1 : -1]; |
||
88 | |||
89 | /* Card inits configured out? */ |
||
90 | #if !ENABLE_WDETH |
||
91 | #define wdeth_probe(dep) (0) |
||
92 | #endif |
||
93 | #if !ENABLE_NE2000 |
||
94 | #define ne_probe(dep) (0) |
||
95 | #endif |
||
96 | #if !ENABLE_3C503 |
||
97 | #define el2_probe(dep) (0) |
||
98 | #endif |
||
99 | |||
100 | /* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA |
||
101 | * on writes to the CR register. Additional CR_STAs do not appear to hurt |
||
102 | * genuine dp8390s |
||
103 | */ |
||
104 | #define CR_EXTRA CR_STA |
||
105 | |||
106 | //#if ENABLE_PCI |
||
107 | //_PROTOTYPE( static void pci_conf, (void) ); |
||
108 | //#endif |
||
109 | //_PROTOTYPE( static void do_vwrite, (message *mp, int from_int, |
||
110 | // int vectored) ); |
||
111 | //_PROTOTYPE( static void do_vwrite_s, (message *mp, int from_int) ); |
||
112 | //_PROTOTYPE( static void do_vread, (message *mp, int vectored) ); |
||
113 | //_PROTOTYPE( static void do_vread_s, (message *mp) ); |
||
114 | //_PROTOTYPE( static void do_init, (message *mp) ); |
||
115 | //_PROTOTYPE( static void do_int, (dpeth_t *dep) ); |
||
116 | //_PROTOTYPE( static void do_getstat, (message *mp) ); |
||
117 | //_PROTOTYPE( static void do_getstat_s, (message *mp) ); |
||
118 | //_PROTOTYPE( static void do_getname, (message *mp) ); |
||
119 | //_PROTOTYPE( static void do_stop, (message *mp) ); |
||
120 | _PROTOTYPE( static void dp_init, (dpeth_t *dep) ); |
||
121 | //_PROTOTYPE( static void dp_confaddr, (dpeth_t *dep) ); |
||
122 | _PROTOTYPE( static void dp_reinit, (dpeth_t *dep) ); |
||
123 | _PROTOTYPE( static void dp_reset, (dpeth_t *dep) ); |
||
124 | //_PROTOTYPE( static void dp_check_ints, (dpeth_t *dep) ); |
||
125 | _PROTOTYPE( static void dp_recv, (dpeth_t *dep) ); |
||
126 | _PROTOTYPE( static void dp_send, (dpeth_t *dep) ); |
||
127 | //_PROTOTYPE( static void dp8390_stop, (void) ); |
||
128 | _PROTOTYPE( static void dp_getblock, (dpeth_t *dep, int page, |
||
129 | size_t offset, size_t size, void *dst) ); |
||
4192 | mejdrech | 130 | _PROTOTYPE( static void dp_pio8_getblock, (dpeth_t *dep, int page, |
131 | size_t offset, size_t size, void *dst) ); |
||
132 | _PROTOTYPE( static void dp_pio16_getblock, (dpeth_t *dep, int page, |
||
133 | size_t offset, size_t size, void *dst) ); |
||
4163 | mejdrech | 134 | _PROTOTYPE( static int dp_pkt2user, (dpeth_t *dep, int page, |
135 | int length) ); |
||
136 | //_PROTOTYPE( static int dp_pkt2user_s, (dpeth_t *dep, int page, |
||
137 | // int length) ); |
||
4192 | mejdrech | 138 | _PROTOTYPE( static void dp_user2nic, (dpeth_t *dep, iovec_dat_t *iovp, |
139 | vir_bytes offset, int nic_addr, vir_bytes count) ); |
||
4163 | mejdrech | 140 | //_PROTOTYPE( static void dp_user2nic_s, (dpeth_t *dep, iovec_dat_s_t *iovp, |
141 | // vir_bytes offset, int nic_addr, vir_bytes count) ); |
||
4192 | mejdrech | 142 | _PROTOTYPE( static void dp_pio8_user2nic, (dpeth_t *dep, |
143 | iovec_dat_t *iovp, vir_bytes offset, |
||
144 | int nic_addr, vir_bytes count) ); |
||
4163 | mejdrech | 145 | //_PROTOTYPE( static void dp_pio8_user2nic_s, (dpeth_t *dep, |
146 | // iovec_dat_s_t *iovp, vir_bytes offset, |
||
147 | // int nic_addr, vir_bytes count) ); |
||
4192 | mejdrech | 148 | _PROTOTYPE( static void dp_pio16_user2nic, (dpeth_t *dep, |
149 | iovec_dat_t *iovp, vir_bytes offset, |
||
150 | int nic_addr, vir_bytes count) ); |
||
4163 | mejdrech | 151 | //_PROTOTYPE( static void dp_pio16_user2nic_s, (dpeth_t *dep, |
152 | // iovec_dat_s_t *iovp, vir_bytes offset, |
||
153 | // int nic_addr, vir_bytes count) ); |
||
154 | _PROTOTYPE( static void dp_nic2user, (dpeth_t *dep, int nic_addr, |
||
155 | iovec_dat_t *iovp, vir_bytes offset, vir_bytes count) ); |
||
156 | //_PROTOTYPE( static void dp_nic2user_s, (dpeth_t *dep, int nic_addr, |
||
157 | // iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) ); |
||
4192 | mejdrech | 158 | _PROTOTYPE( static void dp_pio8_nic2user, (dpeth_t *dep, int nic_addr, |
159 | iovec_dat_t *iovp, vir_bytes offset, vir_bytes count) ); |
||
4163 | mejdrech | 160 | //_PROTOTYPE( static void dp_pio8_nic2user_s, (dpeth_t *dep, int nic_addr, |
161 | // iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) ); |
||
4192 | mejdrech | 162 | _PROTOTYPE( static void dp_pio16_nic2user, (dpeth_t *dep, int nic_addr, |
163 | iovec_dat_t *iovp, vir_bytes offset, vir_bytes count) ); |
||
4163 | mejdrech | 164 | //_PROTOTYPE( static void dp_pio16_nic2user_s, (dpeth_t *dep, int nic_addr, |
165 | // iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) ); |
||
4192 | mejdrech | 166 | _PROTOTYPE( static void dp_next_iovec, (iovec_dat_t *iovp) ); |
4163 | mejdrech | 167 | //_PROTOTYPE( static void dp_next_iovec_s, (iovec_dat_s_t *iovp) ); |
168 | _PROTOTYPE( static void conf_hw, (dpeth_t *dep) ); |
||
169 | //_PROTOTYPE( static void update_conf, (dpeth_t *dep, dp_conf_t *dcp) ); |
||
170 | _PROTOTYPE( static void map_hw_buffer, (dpeth_t *dep) ); |
||
171 | //_PROTOTYPE( static int calc_iovec_size, (iovec_dat_t *iovp) ); |
||
172 | //_PROTOTYPE( static int calc_iovec_size_s, (iovec_dat_s_t *iovp) ); |
||
173 | _PROTOTYPE( static void reply, (dpeth_t *dep, int err, int may_block) ); |
||
174 | //_PROTOTYPE( static void mess_reply, (message *req, message *reply) ); |
||
4192 | mejdrech | 175 | _PROTOTYPE( static void get_userdata, (int user_proc, |
176 | vir_bytes user_addr, vir_bytes count, void *loc_addr) ); |
||
4163 | mejdrech | 177 | //_PROTOTYPE( static void get_userdata_s, (int user_proc, |
178 | // cp_grant_id_t grant, vir_bytes offset, vir_bytes count, |
||
179 | // void *loc_addr) ); |
||
180 | //_PROTOTYPE( static void put_userdata, (int user_proc, |
||
181 | // vir_bytes user_addr, vir_bytes count, void *loc_addr) ); |
||
182 | //_PROTOTYPE( static void put_userdata_s, (int user_proc, |
||
183 | // cp_grant_id_t grant, size_t count, void *loc_addr) ); |
||
4192 | mejdrech | 184 | _PROTOTYPE( static void insb, (port_t port, void *buf, size_t size) ); |
185 | _PROTOTYPE( static void insw, (port_t port, void *buf, size_t size) ); |
||
4163 | mejdrech | 186 | //_PROTOTYPE( static void do_vir_insb, (port_t port, int proc, |
187 | // vir_bytes buf, size_t size) ); |
||
188 | //_PROTOTYPE( static void do_vir_insw, (port_t port, int proc, |
||
189 | // vir_bytes buf, size_t size) ); |
||
190 | //_PROTOTYPE( static void do_vir_outsb, (port_t port, int proc, |
||
191 | // vir_bytes buf, size_t size) ); |
||
192 | //_PROTOTYPE( static void do_vir_outsw, (port_t port, int proc, |
||
193 | // vir_bytes buf, size_t size) ); |
||
194 | |||
195 | int do_probe( dpeth_t * dep ){ |
||
196 | /* This is the default, try to (re)locate the device. */ |
||
197 | conf_hw(dep); |
||
198 | if (dep->de_mode == DEM_DISABLED) |
||
199 | { |
||
200 | /* Probe failed, or the device is configured off. */ |
||
201 | return EXDEV;//ENXIO; |
||
202 | } |
||
203 | if (dep->de_mode == DEM_ENABLED) |
||
204 | dp_init(dep); |
||
205 | return EOK; |
||
206 | } |
||
207 | |||
208 | /*===========================================================================* |
||
209 | * do_init * |
||
210 | *===========================================================================*/ |
||
211 | int do_init( dpeth_t * dep, int mode ){ |
||
212 | if (dep->de_mode == DEM_DISABLED) |
||
213 | { |
||
214 | // might call do_probe() |
||
215 | return EXDEV; |
||
216 | } |
||
217 | |||
218 | if (dep->de_mode == DEM_SINK) |
||
219 | { |
||
220 | // strncpy((char *) dep->de_address.ea_addr, "ZDP", 6); |
||
221 | // dep->de_address.ea_addr[5] = port; |
||
222 | // dp_confaddr(dep); |
||
223 | //TODO ether address? |
||
224 | // reply_mess.m_type = DL_CONF_REPLY; |
||
225 | // reply_mess.m3_i1 = mp->DL_PORT; |
||
226 | // reply_mess.m3_i2 = DE_PORT_NR; |
||
227 | // *(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address; |
||
228 | // mess_reply(mp, &reply_mess); |
||
229 | // return; |
||
230 | return EOK; |
||
231 | } |
||
232 | //TODO assert? |
||
233 | assert(dep->de_mode == DEM_ENABLED); |
||
234 | assert(dep->de_flags & DEF_ENABLED); |
||
235 | |||
236 | dep->de_flags &= ~(DEF_PROMISC | DEF_MULTI | DEF_BROAD); |
||
237 | |||
238 | if (mode & DL_PROMISC_REQ) |
||
239 | dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD; |
||
240 | if (mode & DL_MULTI_REQ) |
||
241 | dep->de_flags |= DEF_MULTI; |
||
242 | if (mode & DL_BROAD_REQ) |
||
243 | dep->de_flags |= DEF_BROAD; |
||
244 | |||
245 | // dep->de_client = mp->m_source; |
||
246 | dp_reinit(dep); |
||
247 | |||
248 | //TODO ether address? |
||
249 | // reply_mess.m_type = DL_CONF_REPLY; |
||
250 | // reply_mess.m3_i1 = mp->DL_PORT; |
||
251 | // reply_mess.m3_i2 = DE_PORT_NR; |
||
252 | // *(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address; |
||
253 | |||
254 | // mess_reply(mp, &reply_mess); |
||
255 | return EOK; |
||
256 | } |
||
257 | |||
258 | /*===========================================================================* |
||
259 | * do_stop * |
||
260 | *===========================================================================*/ |
||
261 | void do_stop( dpeth_t * dep ){ |
||
262 | if(( dep->de_mode != DEM_SINK ) && ( dep->de_mode == DEM_ENABLED ) && ( dep->de_flags & DEF_ENABLED )){ |
||
263 | outb_reg0( dep, DP_CR, CR_STP | CR_DM_ABORT ); |
||
264 | ( dep->de_stopf )( dep ); |
||
265 | |||
266 | dep->de_flags = DEF_EMPTY; |
||
267 | } |
||
268 | } |
||
269 | |||
4192 | mejdrech | 270 | int queue_packet( dpeth_t * dep, packet_t packet ){ |
271 | packet_t tmp; |
||
272 | |||
273 | if( dep->packet_count > 1 ){ |
||
274 | if( ! pq_add( pq_previous( dep->packet_queue ), packet, 0, 0 )){ |
||
275 | return EINVAL; |
||
276 | } |
||
277 | }else{ |
||
278 | tmp = pq_add( dep->packet_queue, packet, 0, 0 ); |
||
279 | if( ! tmp ) return EINVAL; |
||
280 | dep->packet_queue = tmp; |
||
281 | } |
||
282 | ++ dep->packet_count; |
||
283 | return EBUSY; |
||
284 | } |
||
285 | |||
4163 | mejdrech | 286 | /*===========================================================================* |
4192 | mejdrech | 287 | * based on do_vwrite * |
288 | *===========================================================================*/ |
||
289 | int do_pwrite( dpeth_t * dep, packet_t packet, int from_int ) |
||
290 | { |
||
291 | // int port, count, size; |
||
292 | int size; |
||
293 | int sendq_head; |
||
294 | /* dpeth_t *dep; |
||
295 | |||
296 | port = mp->DL_PORT; |
||
297 | count = mp->DL_COUNT; |
||
298 | if (port < 0 || port >= DE_PORT_NR) |
||
299 | panic("", "dp8390: illegal port", port); |
||
300 | dep= &de_table[port]; |
||
301 | dep->de_client= mp->DL_PROC; |
||
302 | */ |
||
303 | if (dep->de_mode == DEM_SINK) |
||
304 | { |
||
305 | assert(!from_int); |
||
306 | dep->de_flags |= DEF_PACK_SEND; |
||
307 | reply(dep, OK, FALSE); |
||
308 | // return; |
||
309 | return EOK; |
||
310 | } |
||
311 | assert(dep->de_mode == DEM_ENABLED); |
||
312 | assert(dep->de_flags & DEF_ENABLED); |
||
313 | if (dep->de_flags & DEF_SEND_AVAIL){ |
||
314 | // panic("", "dp8390: send already in progress", NO_NUM); |
||
315 | return queue_packet( dep, packet ); |
||
316 | } |
||
317 | |||
318 | sendq_head= dep->de_sendq_head; |
||
319 | if (dep->de_sendq[sendq_head].sq_filled) |
||
320 | { |
||
321 | if (from_int) |
||
322 | panic("", "dp8390: should not be sending\n", NO_NUM); |
||
323 | // dep->de_sendmsg= *mp; |
||
324 | dep->de_flags |= DEF_SEND_AVAIL; |
||
325 | reply(dep, OK, FALSE); |
||
326 | // return; |
||
327 | return queue_packet( dep, packet ); |
||
328 | } |
||
329 | assert(!(dep->de_flags & DEF_PACK_SEND)); |
||
330 | |||
331 | /* if (vectored) |
||
332 | { |
||
333 | get_userdata(mp->DL_PROC, (vir_bytes) mp->DL_ADDR, |
||
334 | (count > IOVEC_NR ? IOVEC_NR : count) * |
||
335 | sizeof(iovec_t), dep->de_write_iovec.iod_iovec); |
||
336 | dep->de_write_iovec.iod_iovec_s = count; |
||
337 | dep->de_write_iovec.iod_proc_nr = mp->DL_PROC; |
||
338 | dep->de_write_iovec.iod_iovec_addr = (vir_bytes) mp->DL_ADDR; |
||
339 | |||
340 | dep->de_tmp_iovec = dep->de_write_iovec; |
||
341 | size = calc_iovec_size(&dep->de_tmp_iovec); |
||
342 | } |
||
343 | else |
||
344 | { |
||
345 | dep->de_write_iovec.iod_iovec[0].iov_addr = |
||
346 | (vir_bytes) mp->DL_ADDR; |
||
347 | dep->de_write_iovec.iod_iovec[0].iov_size = |
||
348 | mp->DL_COUNT; |
||
349 | dep->de_write_iovec.iod_iovec_s = 1; |
||
350 | dep->de_write_iovec.iod_proc_nr = mp->DL_PROC; |
||
351 | dep->de_write_iovec.iod_iovec_addr = 0; |
||
352 | size= mp->DL_COUNT; |
||
353 | } |
||
354 | */ |
||
355 | size = packet_get_data_length( packet ); |
||
356 | dep->de_write_iovec.iod_iovec[0].iov_addr = ( vir_bytes ) packet_get_data( packet ); |
||
357 | dep->de_write_iovec.iod_iovec[0].iov_size = size; |
||
358 | dep->de_write_iovec.iod_iovec_s = 1; |
||
359 | dep->de_write_iovec.iod_iovec_addr = NULL; |
||
360 | |||
361 | if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED) |
||
362 | { |
||
363 | panic("", "dp8390: invalid packet size", size); |
||
364 | return EINVAL; |
||
365 | } |
||
366 | (dep->de_user2nicf)(dep, &dep->de_write_iovec, 0, |
||
367 | dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE, |
||
368 | size); |
||
369 | dep->de_sendq[sendq_head].sq_filled= TRUE; |
||
370 | if (dep->de_sendq_tail == sendq_head) |
||
371 | { |
||
372 | outb_reg0(dep, DP_TPSR, dep->de_sendq[sendq_head].sq_sendpage); |
||
373 | outb_reg0(dep, DP_TBCR1, size >> 8); |
||
374 | outb_reg0(dep, DP_TBCR0, size & 0xff); |
||
375 | outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);/* there it goes.. */ |
||
376 | } |
||
377 | else |
||
378 | dep->de_sendq[sendq_head].sq_size= size; |
||
379 | |||
380 | if (++sendq_head == dep->de_sendq_nr) |
||
381 | sendq_head= 0; |
||
382 | assert(sendq_head < SENDQ_NR); |
||
383 | dep->de_sendq_head= sendq_head; |
||
384 | |||
385 | dep->de_flags |= DEF_PACK_SEND; |
||
386 | |||
387 | /* If the interrupt handler called, don't send a reply. The reply |
||
388 | * will be sent after all interrupts are handled. |
||
389 | */ |
||
390 | if (from_int) |
||
391 | return EOK; |
||
392 | reply(dep, OK, FALSE); |
||
393 | |||
394 | assert(dep->de_mode == DEM_ENABLED); |
||
395 | assert(dep->de_flags & DEF_ENABLED); |
||
396 | return EOK; |
||
397 | } |
||
398 | |||
399 | /*===========================================================================* |
||
4163 | mejdrech | 400 | * dp_init * |
401 | *===========================================================================*/ |
||
402 | void dp_init(dep) |
||
403 | dpeth_t *dep; |
||
404 | { |
||
405 | int dp_rcr_reg; |
||
406 | int i;//, r; |
||
407 | |||
408 | /* General initialization */ |
||
409 | dep->de_flags = DEF_EMPTY; |
||
410 | (*dep->de_initf)(dep); |
||
411 | |||
412 | // dp_confaddr(dep); |
||
413 | |||
414 | if (debug) |
||
415 | { |
||
416 | printf("%s: Ethernet address ", dep->de_name); |
||
417 | for (i= 0; i < 6; i++) |
||
418 | printf("%x%c", dep->de_address.ea_addr[i], |
||
419 | i < 5 ? ':' : '\n'); |
||
420 | } |
||
421 | |||
422 | /* Map buffer */ |
||
423 | map_hw_buffer(dep); |
||
424 | |||
425 | /* Initialization of the dp8390 following the mandatory procedure |
||
426 | * in reference manual ("DP8390D/NS32490D NIC Network Interface |
||
427 | * Controller", National Semiconductor, July 1995, Page 29). |
||
428 | */ |
||
429 | /* Step 1: */ |
||
430 | outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT); |
||
431 | /* Step 2: */ |
||
432 | if (dep->de_16bit) |
||
433 | outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS); |
||
434 | else |
||
435 | outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS); |
||
436 | /* Step 3: */ |
||
437 | outb_reg0(dep, DP_RBCR0, 0); |
||
438 | outb_reg0(dep, DP_RBCR1, 0); |
||
439 | /* Step 4: */ |
||
440 | dp_rcr_reg = 0; |
||
441 | if (dep->de_flags & DEF_PROMISC) |
||
442 | dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM; |
||
443 | if (dep->de_flags & DEF_BROAD) |
||
444 | dp_rcr_reg |= RCR_AB; |
||
445 | if (dep->de_flags & DEF_MULTI) |
||
446 | dp_rcr_reg |= RCR_AM; |
||
447 | outb_reg0(dep, DP_RCR, dp_rcr_reg); |
||
448 | /* Step 5: */ |
||
449 | outb_reg0(dep, DP_TCR, TCR_INTERNAL); |
||
450 | /* Step 6: */ |
||
451 | outb_reg0(dep, DP_BNRY, dep->de_startpage); |
||
452 | outb_reg0(dep, DP_PSTART, dep->de_startpage); |
||
453 | outb_reg0(dep, DP_PSTOP, dep->de_stoppage); |
||
454 | /* Step 7: */ |
||
455 | outb_reg0(dep, DP_ISR, 0xFF); |
||
456 | /* Step 8: */ |
||
457 | outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE | |
||
458 | IMR_OVWE | IMR_CNTE); |
||
459 | /* Step 9: */ |
||
460 | outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP); |
||
461 | |||
462 | outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]); |
||
463 | outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]); |
||
464 | outb_reg1(dep, DP_PAR2, dep->de_address.ea_addr[2]); |
||
465 | outb_reg1(dep, DP_PAR3, dep->de_address.ea_addr[3]); |
||
466 | outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]); |
||
467 | outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]); |
||
468 | |||
469 | outb_reg1(dep, DP_MAR0, 0xff); |
||
470 | outb_reg1(dep, DP_MAR1, 0xff); |
||
471 | outb_reg1(dep, DP_MAR2, 0xff); |
||
472 | outb_reg1(dep, DP_MAR3, 0xff); |
||
473 | outb_reg1(dep, DP_MAR4, 0xff); |
||
474 | outb_reg1(dep, DP_MAR5, 0xff); |
||
475 | outb_reg1(dep, DP_MAR6, 0xff); |
||
476 | outb_reg1(dep, DP_MAR7, 0xff); |
||
477 | |||
478 | outb_reg1(dep, DP_CURR, dep->de_startpage + 1); |
||
479 | /* Step 10: */ |
||
480 | outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA); |
||
481 | /* Step 11: */ |
||
482 | outb_reg0(dep, DP_TCR, TCR_NORMAL); |
||
483 | |||
484 | inb_reg0(dep, DP_CNTR0); /* reset counters by reading */ |
||
485 | inb_reg0(dep, DP_CNTR1); |
||
486 | inb_reg0(dep, DP_CNTR2); |
||
487 | |||
488 | /* Finish the initialization. */ |
||
489 | dep->de_flags |= DEF_ENABLED; |
||
490 | for (i= 0; i<dep->de_sendq_nr; i++) |
||
491 | dep->de_sendq[i].sq_filled= 0; |
||
492 | dep->de_sendq_head= 0; |
||
493 | dep->de_sendq_tail= 0; |
||
4192 | mejdrech | 494 | if (!dep->de_prog_IO) |
495 | { |
||
496 | dep->de_user2nicf= dp_user2nic; |
||
4163 | mejdrech | 497 | // dep->de_user2nicf_s= dp_user2nic_s; |
498 | dep->de_nic2userf= dp_nic2user; |
||
499 | // dep->de_nic2userf_s= dp_nic2user_s; |
||
500 | dep->de_getblockf= dp_getblock; |
||
4192 | mejdrech | 501 | } |
502 | else if (dep->de_16bit) |
||
503 | { |
||
504 | dep->de_user2nicf= dp_pio16_user2nic; |
||
4163 | mejdrech | 505 | // dep->de_user2nicf_s= dp_pio16_user2nic_s; |
4192 | mejdrech | 506 | dep->de_nic2userf= dp_pio16_nic2user; |
4163 | mejdrech | 507 | // dep->de_nic2userf_s= dp_pio16_nic2user_s; |
4192 | mejdrech | 508 | dep->de_getblockf= dp_pio16_getblock; |
509 | } |
||
510 | else |
||
511 | { |
||
512 | dep->de_user2nicf= dp_pio8_user2nic; |
||
4163 | mejdrech | 513 | // dep->de_user2nicf_s= dp_pio8_user2nic_s; |
4192 | mejdrech | 514 | dep->de_nic2userf= dp_pio8_nic2user; |
4163 | mejdrech | 515 | // dep->de_nic2userf_s= dp_pio8_nic2user_s; |
4192 | mejdrech | 516 | dep->de_getblockf= dp_pio8_getblock; |
517 | } |
||
4163 | mejdrech | 518 | |
519 | /* Set the interrupt handler and policy. Do not automatically |
||
520 | * reenable interrupts. Return the IRQ line number on interrupts. |
||
521 | */ |
||
522 | /* dep->de_hook = dep->de_irq; |
||
523 | r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook); |
||
524 | if (r != OK) |
||
525 | panic("DP8390", "sys_irqsetpolicy failed", r); |
||
526 | |||
527 | r= sys_irqenable(&dep->de_hook); |
||
528 | if (r != OK) |
||
529 | { |
||
530 | panic("DP8390", "unable enable interrupts", r); |
||
531 | } |
||
532 | */ |
||
533 | } |
||
534 | |||
535 | /*===========================================================================* |
||
536 | * dp_reinit * |
||
537 | *===========================================================================*/ |
||
538 | static void dp_reinit(dep) |
||
539 | dpeth_t *dep; |
||
540 | { |
||
541 | int dp_rcr_reg; |
||
542 | |||
543 | outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA); |
||
544 | |||
545 | dp_rcr_reg = 0; |
||
546 | if (dep->de_flags & DEF_PROMISC) |
||
547 | dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM; |
||
548 | if (dep->de_flags & DEF_BROAD) |
||
549 | dp_rcr_reg |= RCR_AB; |
||
550 | if (dep->de_flags & DEF_MULTI) |
||
551 | dp_rcr_reg |= RCR_AM; |
||
552 | outb_reg0(dep, DP_RCR, dp_rcr_reg); |
||
553 | } |
||
554 | |||
555 | /*===========================================================================* |
||
556 | * dp_reset * |
||
557 | *===========================================================================*/ |
||
558 | static void dp_reset(dep) |
||
559 | dpeth_t *dep; |
||
560 | { |
||
561 | int i; |
||
562 | |||
563 | /* Stop chip */ |
||
564 | outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT); |
||
565 | outb_reg0(dep, DP_RBCR0, 0); |
||
566 | outb_reg0(dep, DP_RBCR1, 0); |
||
567 | for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++) |
||
568 | ; /* Do nothing */ |
||
569 | outb_reg0(dep, DP_TCR, TCR_1EXTERNAL|TCR_OFST); |
||
570 | outb_reg0(dep, DP_CR, CR_STA|CR_DM_ABORT); |
||
571 | outb_reg0(dep, DP_TCR, TCR_NORMAL); |
||
572 | |||
573 | /* Acknowledge the ISR_RDC (remote dma) interrupt. */ |
||
574 | for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RDC) == 0); i++) |
||
575 | ; /* Do nothing */ |
||
576 | outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) & ~ISR_RDC); |
||
577 | |||
578 | /* Reset the transmit ring. If we were transmitting a packet, we |
||
579 | * pretend that the packet is processed. Higher layers will |
||
580 | * retransmit if the packet wasn't actually sent. |
||
581 | */ |
||
582 | dep->de_sendq_head= dep->de_sendq_tail= 0; |
||
583 | for (i= 0; i<dep->de_sendq_nr; i++) |
||
584 | dep->de_sendq[i].sq_filled= 0; |
||
585 | dp_send(dep); |
||
586 | dep->de_flags &= ~DEF_STOPPED; |
||
587 | } |
||
588 | |||
589 | /*===========================================================================* |
||
590 | * dp_check_ints * |
||
591 | *===========================================================================*/ |
||
592 | void dp_check_ints(dep) |
||
593 | dpeth_t *dep; |
||
594 | { |
||
595 | int isr, tsr; |
||
596 | int size, sendq_tail; |
||
597 | |||
598 | if (!(dep->de_flags & DEF_ENABLED)) |
||
599 | panic("", "dp8390: got premature interrupt", NO_NUM); |
||
600 | |||
601 | for(;;) |
||
602 | { |
||
603 | isr = inb_reg0(dep, DP_ISR); |
||
604 | if (!isr) |
||
605 | break; |
||
606 | outb_reg0(dep, DP_ISR, isr); |
||
607 | if (isr & (ISR_PTX|ISR_TXE)) |
||
608 | { |
||
609 | if (isr & ISR_TXE) |
||
610 | { |
||
611 | #if DEBUG |
||
612 | { printf("%s: got send Error\n", dep->de_name); } |
||
613 | #endif |
||
614 | dep->de_stat.ets_sendErr++; |
||
615 | } |
||
616 | else |
||
617 | { |
||
618 | tsr = inb_reg0(dep, DP_TSR); |
||
619 | |||
620 | if (tsr & TSR_PTX) dep->de_stat.ets_packetT++; |
||
621 | #if 0 /* Reserved in later manuals, should be ignored */ |
||
622 | if (!(tsr & TSR_DFR)) |
||
623 | { |
||
624 | /* In most (all?) implementations of |
||
625 | * the dp8390, this bit is set |
||
626 | * when the packet is not deferred |
||
627 | */ |
||
628 | dep->de_stat.ets_transDef++; |
||
629 | } |
||
630 | #endif |
||
631 | if (tsr & TSR_COL) dep->de_stat.ets_collision++; |
||
632 | if (tsr & TSR_ABT) dep->de_stat.ets_transAb++; |
||
633 | if (tsr & TSR_CRS) dep->de_stat.ets_carrSense++; |
||
634 | if (tsr & TSR_FU |
||
635 | && ++dep->de_stat.ets_fifoUnder <= 10) |
||
636 | { |
||
637 | printf("%s: fifo underrun\n", |
||
638 | dep->de_name); |
||
639 | } |
||
640 | if (tsr & TSR_CDH |
||
641 | && ++dep->de_stat.ets_CDheartbeat <= 10) |
||
642 | { |
||
643 | printf("%s: CD heart beat failure\n", |
||
644 | dep->de_name); |
||
645 | } |
||
646 | if (tsr & TSR_OWC) dep->de_stat.ets_OWC++; |
||
647 | } |
||
648 | sendq_tail= dep->de_sendq_tail; |
||
649 | |||
650 | if (!(dep->de_sendq[sendq_tail].sq_filled)) |
||
651 | { |
||
652 | /* Software bug? */ |
||
653 | assert(!debug); |
||
654 | |||
655 | /* Or hardware bug? */ |
||
656 | printf( |
||
657 | "%s: transmit interrupt, but not sending\n", |
||
658 | dep->de_name); |
||
659 | continue; |
||
660 | } |
||
661 | dep->de_sendq[sendq_tail].sq_filled= 0; |
||
662 | if (++sendq_tail == dep->de_sendq_nr) |
||
663 | sendq_tail= 0; |
||
664 | dep->de_sendq_tail= sendq_tail; |
||
665 | if (dep->de_sendq[sendq_tail].sq_filled) |
||
666 | { |
||
667 | size= dep->de_sendq[sendq_tail].sq_size; |
||
668 | outb_reg0(dep, DP_TPSR, |
||
669 | dep->de_sendq[sendq_tail].sq_sendpage); |
||
670 | outb_reg0(dep, DP_TBCR1, size >> 8); |
||
671 | outb_reg0(dep, DP_TBCR0, size & 0xff); |
||
672 | outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA); |
||
673 | } |
||
674 | if (dep->de_flags & DEF_SEND_AVAIL) |
||
675 | dp_send(dep); |
||
676 | } |
||
677 | |||
678 | if (isr & ISR_PRX) |
||
679 | { |
||
680 | /* Only call dp_recv if there is a read request */ |
||
681 | if (dep->de_flags & DEF_READING) |
||
682 | dp_recv(dep); |
||
683 | } |
||
684 | |||
685 | if (isr & ISR_RXE) dep->de_stat.ets_recvErr++; |
||
686 | if (isr & ISR_CNT) |
||
687 | { |
||
688 | dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0); |
||
689 | dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1); |
||
690 | dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2); |
||
691 | } |
||
692 | if (isr & ISR_OVW) |
||
693 | { |
||
694 | dep->de_stat.ets_OVW++; |
||
695 | #if 0 |
||
696 | { printW(); printf( |
||
697 | "%s: got overwrite warning\n", dep->de_name); } |
||
698 | #endif |
||
699 | if (dep->de_flags & DEF_READING) |
||
700 | { |
||
701 | printf( |
||
702 | "dp_check_ints: strange: overwrite warning and pending read request\n"); |
||
703 | dp_recv(dep); |
||
704 | } |
||
705 | } |
||
706 | if (isr & ISR_RDC) |
||
707 | { |
||
708 | /* Nothing to do */ |
||
709 | } |
||
710 | if (isr & ISR_RST) |
||
711 | { |
||
712 | /* this means we got an interrupt but the ethernet |
||
713 | * chip is shutdown. We set the flag DEF_STOPPED, |
||
714 | * and continue processing arrived packets. When the |
||
715 | * receive buffer is empty, we reset the dp8390. |
||
716 | */ |
||
717 | #if 0 |
||
718 | { printW(); printf( |
||
719 | "%s: NIC stopped\n", dep->de_name); } |
||
720 | #endif |
||
721 | dep->de_flags |= DEF_STOPPED; |
||
722 | break; |
||
723 | } |
||
724 | } |
||
725 | if ((dep->de_flags & (DEF_READING|DEF_STOPPED)) == |
||
726 | (DEF_READING|DEF_STOPPED)) |
||
727 | { |
||
728 | /* The chip is stopped, and all arrived packets are |
||
729 | * delivered. |
||
730 | */ |
||
731 | dp_reset(dep); |
||
732 | } |
||
733 | } |
||
734 | |||
735 | /*===========================================================================* |
||
736 | * dp_recv * |
||
737 | *===========================================================================*/ |
||
738 | static void dp_recv(dep) |
||
739 | dpeth_t *dep; |
||
740 | { |
||
741 | dp_rcvhdr_t header; |
||
742 | unsigned pageno, curr, next; |
||
743 | vir_bytes length; |
||
744 | int packet_processed, r; |
||
745 | u16_t eth_type; |
||
746 | |||
747 | packet_processed = FALSE; |
||
748 | pageno = inb_reg0(dep, DP_BNRY) + 1; |
||
749 | if (pageno == dep->de_stoppage) pageno = dep->de_startpage; |
||
750 | |||
751 | do |
||
752 | { |
||
753 | outb_reg0(dep, DP_CR, CR_PS_P1 | CR_EXTRA); |
||
754 | curr = inb_reg1(dep, DP_CURR); |
||
755 | outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA); |
||
756 | |||
757 | if (curr == pageno) break; |
||
758 | |||
759 | (dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header), |
||
760 | &header); |
||
761 | (dep->de_getblockf)(dep, pageno, sizeof(header) + |
||
762 | 2*sizeof(ether_addr_t), sizeof(eth_type), ð_type); |
||
763 | |||
764 | length = (header.dr_rbcl | (header.dr_rbch << 8)) - |
||
765 | sizeof(dp_rcvhdr_t); |
||
766 | next = header.dr_next; |
||
767 | if (length < ETH_MIN_PACK_SIZE || |
||
768 | length > ETH_MAX_PACK_SIZE_TAGGED) |
||
769 | { |
||
770 | printf("%s: packet with strange length arrived: %d\n", |
||
771 | dep->de_name, (int) length); |
||
772 | next= curr; |
||
773 | } |
||
774 | else if (next < dep->de_startpage || next >= dep->de_stoppage) |
||
775 | { |
||
776 | printf("%s: strange next page\n", dep->de_name); |
||
777 | next= curr; |
||
778 | } |
||
779 | /* else if (eth_type == eth_ign_proto) |
||
780 | { |
||
781 | */ /* Hack: ignore packets of a given protocol, useful |
||
782 | * if you share a net with 80 computers sending |
||
783 | * Amoeba FLIP broadcasts. (Protocol 0x8146.) |
||
784 | */ |
||
785 | /* static int first= 1; |
||
786 | if (first) |
||
787 | { |
||
788 | first= 0; |
||
789 | printf("%s: dropping proto 0x%04x packets\n", |
||
790 | dep->de_name, |
||
791 | ntohs(eth_ign_proto)); |
||
792 | } |
||
793 | dep->de_stat.ets_packetR++; |
||
794 | } |
||
795 | */ else if (header.dr_status & RSR_FO) |
||
796 | { |
||
797 | /* This is very serious, so we issue a warning and |
||
798 | * reset the buffers */ |
||
799 | printf("%s: fifo overrun, resetting receive buffer\n", |
||
800 | dep->de_name); |
||
801 | dep->de_stat.ets_fifoOver++; |
||
802 | next = curr; |
||
803 | } |
||
804 | else if ((header.dr_status & RSR_PRX) && |
||
805 | (dep->de_flags & DEF_ENABLED)) |
||
806 | { |
||
807 | // if (dep->de_safecopy_read) |
||
808 | // r = dp_pkt2user_s(dep, pageno, length); |
||
809 | // else |
||
810 | r = dp_pkt2user(dep, pageno, length); |
||
811 | if (r != OK) |
||
812 | return; |
||
813 | |||
814 | packet_processed = TRUE; |
||
815 | dep->de_stat.ets_packetR++; |
||
816 | } |
||
817 | if (next == dep->de_startpage) |
||
818 | outb_reg0(dep, DP_BNRY, dep->de_stoppage - 1); |
||
819 | else |
||
820 | outb_reg0(dep, DP_BNRY, next - 1); |
||
821 | |||
822 | pageno = next; |
||
823 | } |
||
824 | while (!packet_processed); |
||
825 | } |
||
826 | |||
827 | /*===========================================================================* |
||
828 | * dp_send * |
||
829 | *===========================================================================*/ |
||
830 | static void dp_send(dep) |
||
831 | dpeth_t *dep; |
||
832 | { |
||
4192 | mejdrech | 833 | packet_t packet; |
834 | |||
835 | if (!(dep->de_flags & DEF_SEND_AVAIL)) |
||
4163 | mejdrech | 836 | return; |
837 | |||
838 | dep->de_flags &= ~DEF_SEND_AVAIL; |
||
4192 | mejdrech | 839 | while( dep->packet_queue ){ |
840 | packet = dep->packet_queue; |
||
841 | dep->packet_queue = pq_detach( packet ); |
||
842 | do_pwrite( dep, packet, TRUE ); |
||
843 | netif_pq_release( packet_get_id( packet )); |
||
844 | -- dep->packet_count; |
||
845 | } |
||
846 | /* switch(dep->de_sendmsg.m_type) |
||
4163 | mejdrech | 847 | { |
848 | case DL_WRITE: do_vwrite(&dep->de_sendmsg, TRUE, FALSE); break; |
||
849 | case DL_WRITEV: do_vwrite(&dep->de_sendmsg, TRUE, TRUE); break; |
||
850 | case DL_WRITEV_S: do_vwrite_s(&dep->de_sendmsg, TRUE); break; |
||
851 | default: |
||
852 | panic("", "dp8390: wrong type", dep->de_sendmsg.m_type); |
||
853 | break; |
||
854 | } |
||
855 | */ |
||
856 | } |
||
857 | |||
858 | /*===========================================================================* |
||
859 | * dp_getblock * |
||
860 | *===========================================================================*/ |
||
861 | static void dp_getblock(dep, page, offset, size, dst) |
||
862 | dpeth_t *dep; |
||
863 | int page; |
||
864 | size_t offset; |
||
865 | size_t size; |
||
866 | void *dst; |
||
867 | { |
||
868 | // int r; |
||
869 | |||
870 | offset = page * DP_PAGESIZE + offset; |
||
871 | |||
872 | memcpy(dst, dep->de_locmem + offset, size); |
||
873 | } |
||
874 | |||
875 | /*===========================================================================* |
||
4192 | mejdrech | 876 | * dp_pio8_getblock * |
877 | *===========================================================================*/ |
||
878 | static void dp_pio8_getblock(dep, page, offset, size, dst) |
||
879 | dpeth_t *dep; |
||
880 | int page; |
||
881 | size_t offset; |
||
882 | size_t size; |
||
883 | void *dst; |
||
884 | { |
||
885 | offset = page * DP_PAGESIZE + offset; |
||
886 | outb_reg0(dep, DP_RBCR0, size & 0xFF); |
||
887 | outb_reg0(dep, DP_RBCR1, size >> 8); |
||
888 | outb_reg0(dep, DP_RSAR0, offset & 0xFF); |
||
889 | outb_reg0(dep, DP_RSAR1, offset >> 8); |
||
890 | outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); |
||
891 | |||
892 | insb(dep->de_data_port, dst, size); |
||
893 | } |
||
894 | |||
895 | /*===========================================================================* |
||
896 | * dp_pio16_getblock * |
||
897 | *===========================================================================*/ |
||
898 | static void dp_pio16_getblock(dep, page, offset, size, dst) |
||
899 | dpeth_t *dep; |
||
900 | int page; |
||
901 | size_t offset; |
||
902 | size_t size; |
||
903 | void *dst; |
||
904 | { |
||
905 | offset = page * DP_PAGESIZE + offset; |
||
906 | outb_reg0(dep, DP_RBCR0, size & 0xFF); |
||
907 | outb_reg0(dep, DP_RBCR1, size >> 8); |
||
908 | outb_reg0(dep, DP_RSAR0, offset & 0xFF); |
||
909 | outb_reg0(dep, DP_RSAR1, offset >> 8); |
||
910 | outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); |
||
911 | |||
912 | assert (!(size & 1)); |
||
913 | insw(dep->de_data_port, dst, size); |
||
914 | } |
||
915 | |||
916 | /*===========================================================================* |
||
4163 | mejdrech | 917 | * dp_pkt2user * |
918 | *===========================================================================*/ |
||
919 | static int dp_pkt2user(dep, page, length) |
||
920 | dpeth_t *dep; |
||
921 | int page, length; |
||
922 | { |
||
923 | int last, count; |
||
4192 | mejdrech | 924 | packet_t packet; |
4163 | mejdrech | 925 | |
926 | if (!(dep->de_flags & DEF_READING)) |
||
927 | return EGENERIC; |
||
928 | |||
4192 | mejdrech | 929 | packet = netif_packet_get_1( length ); |
930 | if( ! packet ) return ENOMEM; |
||
931 | dep->de_read_iovec.iod_iovec[0].iov_addr = ( vir_bytes ) packet_suffix( packet, length ); |
||
932 | dep->de_read_iovec.iod_iovec[0].iov_size = length; |
||
933 | dep->de_read_iovec.iod_iovec_s = 1; |
||
934 | dep->de_read_iovec.iod_iovec_addr = NULL; |
||
935 | |||
4163 | mejdrech | 936 | last = page + (length - 1) / DP_PAGESIZE; |
937 | if (last >= dep->de_stoppage) |
||
938 | { |
||
939 | count = (dep->de_stoppage - page) * DP_PAGESIZE - |
||
940 | sizeof(dp_rcvhdr_t); |
||
941 | |||
942 | /* Save read_iovec since we need it twice. */ |
||
943 | dep->de_tmp_iovec = dep->de_read_iovec; |
||
944 | (dep->de_nic2userf)(dep, page * DP_PAGESIZE + |
||
945 | sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec, 0, count); |
||
946 | (dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE, |
||
947 | &dep->de_read_iovec, count, length - count); |
||
948 | } |
||
949 | else |
||
950 | { |
||
951 | (dep->de_nic2userf)(dep, page * DP_PAGESIZE + |
||
952 | sizeof(dp_rcvhdr_t), &dep->de_read_iovec, 0, length); |
||
953 | } |
||
954 | |||
955 | dep->de_read_s = length; |
||
956 | dep->de_flags |= DEF_PACK_RECV; |
||
957 | dep->de_flags &= ~DEF_READING; |
||
958 | |||
4192 | mejdrech | 959 | if( netif_send_packet( dep, packet ) != EOK ){ |
960 | netif_pq_release( packet_get_id( packet )); |
||
961 | } |
||
4163 | mejdrech | 962 | return OK; |
963 | } |
||
964 | |||
965 | /*===========================================================================* |
||
4192 | mejdrech | 966 | * dp_user2nic * |
967 | *===========================================================================*/ |
||
968 | static void dp_user2nic(dep, iovp, offset, nic_addr, count) |
||
969 | dpeth_t *dep; |
||
970 | iovec_dat_t *iovp; |
||
971 | vir_bytes offset; |
||
972 | int nic_addr; |
||
973 | vir_bytes count; |
||
974 | { |
||
975 | vir_bytes vir_hw;//, vir_user; |
||
976 | int bytes, i, r; |
||
977 | |||
978 | vir_hw = (vir_bytes)dep->de_locmem + nic_addr; |
||
979 | |||
980 | i= 0; |
||
981 | while (count > 0) |
||
982 | { |
||
983 | if (i >= IOVEC_NR) |
||
984 | { |
||
985 | dp_next_iovec(iovp); |
||
986 | i= 0; |
||
987 | continue; |
||
988 | } |
||
989 | assert(i < iovp->iod_iovec_s); |
||
990 | if (offset >= iovp->iod_iovec[i].iov_size) |
||
991 | { |
||
992 | offset -= iovp->iod_iovec[i].iov_size; |
||
993 | i++; |
||
994 | continue; |
||
995 | } |
||
996 | bytes = iovp->iod_iovec[i].iov_size - offset; |
||
997 | if (bytes > count) |
||
998 | bytes = count; |
||
999 | |||
1000 | r= sys_vircopy(iovp->iod_proc_nr, D, |
||
1001 | iovp->iod_iovec[i].iov_addr + offset, |
||
1002 | SELF, D, vir_hw, bytes); |
||
1003 | if (r != OK) |
||
1004 | panic("DP8390", "dp_user2nic: sys_vircopy failed", r); |
||
1005 | |||
1006 | count -= bytes; |
||
1007 | vir_hw += bytes; |
||
1008 | offset += bytes; |
||
1009 | } |
||
1010 | assert(count == 0); |
||
1011 | } |
||
1012 | |||
1013 | /*===========================================================================* |
||
1014 | * dp_pio8_user2nic * |
||
1015 | *===========================================================================*/ |
||
1016 | static void dp_pio8_user2nic(dep, iovp, offset, nic_addr, count) |
||
1017 | dpeth_t *dep; |
||
1018 | iovec_dat_t *iovp; |
||
1019 | vir_bytes offset; |
||
1020 | int nic_addr; |
||
1021 | vir_bytes count; |
||
1022 | { |
||
1023 | // phys_bytes phys_user; |
||
1024 | int bytes, i; |
||
1025 | |||
1026 | outb_reg0(dep, DP_ISR, ISR_RDC); |
||
1027 | |||
1028 | outb_reg0(dep, DP_RBCR0, count & 0xFF); |
||
1029 | outb_reg0(dep, DP_RBCR1, count >> 8); |
||
1030 | outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF); |
||
1031 | outb_reg0(dep, DP_RSAR1, nic_addr >> 8); |
||
1032 | outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA); |
||
1033 | |||
1034 | i= 0; |
||
1035 | while (count > 0) |
||
1036 | { |
||
1037 | if (i >= IOVEC_NR) |
||
1038 | { |
||
1039 | dp_next_iovec(iovp); |
||
1040 | i= 0; |
||
1041 | continue; |
||
1042 | } |
||
1043 | assert(i < iovp->iod_iovec_s); |
||
1044 | if (offset >= iovp->iod_iovec[i].iov_size) |
||
1045 | { |
||
1046 | offset -= iovp->iod_iovec[i].iov_size; |
||
1047 | i++; |
||
1048 | continue; |
||
1049 | } |
||
1050 | bytes = iovp->iod_iovec[i].iov_size - offset; |
||
1051 | if (bytes > count) |
||
1052 | bytes = count; |
||
1053 | |||
1054 | do_vir_outsb(dep->de_data_port, iovp->iod_proc_nr, |
||
1055 | iovp->iod_iovec[i].iov_addr + offset, bytes); |
||
1056 | count -= bytes; |
||
1057 | offset += bytes; |
||
1058 | } |
||
1059 | assert(count == 0); |
||
1060 | |||
1061 | for (i= 0; i<100; i++) |
||
1062 | { |
||
1063 | if (inb_reg0(dep, DP_ISR) & ISR_RDC) |
||
1064 | break; |
||
1065 | } |
||
1066 | if (i == 100) |
||
1067 | { |
||
1068 | panic("", "dp8390: remote dma failed to complete", NO_NUM); |
||
1069 | } |
||
1070 | } |
||
1071 | |||
1072 | /*===========================================================================* |
||
1073 | * dp_pio16_user2nic * |
||
1074 | *===========================================================================*/ |
||
1075 | static void dp_pio16_user2nic(dep, iovp, offset, nic_addr, count) |
||
1076 | dpeth_t *dep; |
||
1077 | iovec_dat_t *iovp; |
||
1078 | vir_bytes offset; |
||
1079 | int nic_addr; |
||
1080 | vir_bytes count; |
||
1081 | { |
||
1082 | vir_bytes vir_user; |
||
1083 | vir_bytes ecount; |
||
1084 | int i, r, bytes, user_proc; |
||
1085 | u8_t two_bytes[2]; |
||
1086 | int odd_byte; |
||
1087 | |||
1088 | ecount= (count+1) & ~1; |
||
1089 | odd_byte= 0; |
||
1090 | |||
1091 | outb_reg0(dep, DP_ISR, ISR_RDC); |
||
1092 | outb_reg0(dep, DP_RBCR0, ecount & 0xFF); |
||
1093 | outb_reg0(dep, DP_RBCR1, ecount >> 8); |
||
1094 | outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF); |
||
1095 | outb_reg0(dep, DP_RSAR1, nic_addr >> 8); |
||
1096 | outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA); |
||
1097 | |||
1098 | i= 0; |
||
1099 | while (count > 0) |
||
1100 | { |
||
1101 | if (i >= IOVEC_NR) |
||
1102 | { |
||
1103 | dp_next_iovec(iovp); |
||
1104 | i= 0; |
||
1105 | continue; |
||
1106 | } |
||
1107 | assert(i < iovp->iod_iovec_s); |
||
1108 | if (offset >= iovp->iod_iovec[i].iov_size) |
||
1109 | { |
||
1110 | offset -= iovp->iod_iovec[i].iov_size; |
||
1111 | i++; |
||
1112 | continue; |
||
1113 | } |
||
1114 | bytes = iovp->iod_iovec[i].iov_size - offset; |
||
1115 | if (bytes > count) |
||
1116 | bytes = count; |
||
1117 | |||
1118 | user_proc= iovp->iod_proc_nr; |
||
1119 | vir_user= iovp->iod_iovec[i].iov_addr + offset; |
||
1120 | if (odd_byte) |
||
1121 | { |
||
1122 | r= sys_vircopy(user_proc, D, vir_user, |
||
1123 | SELF, D, (vir_bytes)&two_bytes[1], 1); |
||
1124 | if (r != OK) |
||
1125 | { |
||
1126 | panic("DP8390", |
||
1127 | "dp_pio16_user2nic: sys_vircopy failed", |
||
1128 | r); |
||
1129 | } |
||
1130 | outw(dep->de_data_port, *(u16_t *)two_bytes); |
||
1131 | count--; |
||
1132 | offset++; |
||
1133 | bytes--; |
||
1134 | vir_user++; |
||
1135 | odd_byte= 0; |
||
1136 | if (!bytes) |
||
1137 | continue; |
||
1138 | } |
||
1139 | ecount= bytes & ~1; |
||
1140 | if (ecount != 0) |
||
1141 | { |
||
1142 | do_vir_outsw(dep->de_data_port, user_proc, vir_user, |
||
1143 | ecount); |
||
1144 | count -= ecount; |
||
1145 | offset += ecount; |
||
1146 | bytes -= ecount; |
||
1147 | vir_user += ecount; |
||
1148 | } |
||
1149 | if (bytes) |
||
1150 | { |
||
1151 | assert(bytes == 1); |
||
1152 | r= sys_vircopy(user_proc, D, vir_user, |
||
1153 | SELF, D, (vir_bytes)&two_bytes[0], 1); |
||
1154 | if (r != OK) |
||
1155 | { |
||
1156 | panic("DP8390", |
||
1157 | "dp_pio16_user2nic: sys_vircopy failed", |
||
1158 | r); |
||
1159 | } |
||
1160 | count--; |
||
1161 | offset++; |
||
1162 | bytes--; |
||
1163 | vir_user++; |
||
1164 | odd_byte= 1; |
||
1165 | } |
||
1166 | } |
||
1167 | assert(count == 0); |
||
1168 | |||
1169 | if (odd_byte) |
||
1170 | outw(dep->de_data_port, *(u16_t *)two_bytes); |
||
1171 | |||
1172 | for (i= 0; i<100; i++) |
||
1173 | { |
||
1174 | if (inb_reg0(dep, DP_ISR) & ISR_RDC) |
||
1175 | break; |
||
1176 | } |
||
1177 | if (i == 100) |
||
1178 | { |
||
1179 | panic("", "dp8390: remote dma failed to complete", NO_NUM); |
||
1180 | } |
||
1181 | } |
||
1182 | |||
1183 | /*===========================================================================* |
||
4163 | mejdrech | 1184 | * dp_nic2user * |
1185 | *===========================================================================*/ |
||
1186 | static void dp_nic2user(dep, nic_addr, iovp, offset, count) |
||
1187 | dpeth_t *dep; |
||
1188 | int nic_addr; |
||
1189 | iovec_dat_t *iovp; |
||
1190 | vir_bytes offset; |
||
1191 | vir_bytes count; |
||
1192 | { |
||
4192 | mejdrech | 1193 | vir_bytes vir_hw;//, vir_user; |
4163 | mejdrech | 1194 | int bytes, i, r; |
1195 | |||
1196 | vir_hw = (vir_bytes)dep->de_locmem + nic_addr; |
||
1197 | |||
1198 | i= 0; |
||
1199 | while (count > 0) |
||
1200 | { |
||
1201 | if (i >= IOVEC_NR) |
||
1202 | { |
||
1203 | dp_next_iovec(iovp); |
||
1204 | i= 0; |
||
1205 | continue; |
||
1206 | } |
||
1207 | assert(i < iovp->iod_iovec_s); |
||
1208 | if (offset >= iovp->iod_iovec[i].iov_size) |
||
1209 | { |
||
1210 | offset -= iovp->iod_iovec[i].iov_size; |
||
1211 | i++; |
||
1212 | continue; |
||
1213 | } |
||
1214 | bytes = iovp->iod_iovec[i].iov_size - offset; |
||
1215 | if (bytes > count) |
||
1216 | bytes = count; |
||
1217 | |||
1218 | r= sys_vircopy(SELF, D, vir_hw, |
||
1219 | iovp->iod_proc_nr, D, |
||
1220 | iovp->iod_iovec[i].iov_addr + offset, bytes); |
||
1221 | if (r != OK) |
||
1222 | panic("DP8390", "dp_nic2user: sys_vircopy failed", r); |
||
1223 | |||
1224 | count -= bytes; |
||
1225 | vir_hw += bytes; |
||
1226 | offset += bytes; |
||
1227 | } |
||
1228 | assert(count == 0); |
||
1229 | } |
||
1230 | |||
1231 | /*===========================================================================* |
||
4192 | mejdrech | 1232 | * dp_pio8_nic2user * |
1233 | *===========================================================================*/ |
||
1234 | static void dp_pio8_nic2user(dep, nic_addr, iovp, offset, count) |
||
1235 | dpeth_t *dep; |
||
1236 | int nic_addr; |
||
1237 | iovec_dat_t *iovp; |
||
1238 | vir_bytes offset; |
||
1239 | vir_bytes count; |
||
1240 | { |
||
1241 | // phys_bytes phys_user; |
||
1242 | int bytes, i; |
||
1243 | |||
1244 | outb_reg0(dep, DP_RBCR0, count & 0xFF); |
||
1245 | outb_reg0(dep, DP_RBCR1, count >> 8); |
||
1246 | outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF); |
||
1247 | outb_reg0(dep, DP_RSAR1, nic_addr >> 8); |
||
1248 | outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); |
||
1249 | |||
1250 | i= 0; |
||
1251 | while (count > 0) |
||
1252 | { |
||
1253 | if (i >= IOVEC_NR) |
||
1254 | { |
||
1255 | dp_next_iovec(iovp); |
||
1256 | i= 0; |
||
1257 | continue; |
||
1258 | } |
||
1259 | assert(i < iovp->iod_iovec_s); |
||
1260 | if (offset >= iovp->iod_iovec[i].iov_size) |
||
1261 | { |
||
1262 | offset -= iovp->iod_iovec[i].iov_size; |
||
1263 | i++; |
||
1264 | continue; |
||
1265 | } |
||
1266 | bytes = iovp->iod_iovec[i].iov_size - offset; |
||
1267 | if (bytes > count) |
||
1268 | bytes = count; |
||
1269 | |||
1270 | do_vir_insb(dep->de_data_port, iovp->iod_proc_nr, |
||
1271 | iovp->iod_iovec[i].iov_addr + offset, bytes); |
||
1272 | count -= bytes; |
||
1273 | offset += bytes; |
||
1274 | } |
||
1275 | assert(count == 0); |
||
1276 | } |
||
1277 | |||
1278 | /*===========================================================================* |
||
1279 | * dp_pio16_nic2user * |
||
1280 | *===========================================================================*/ |
||
1281 | static void dp_pio16_nic2user(dep, nic_addr, iovp, offset, count) |
||
1282 | dpeth_t *dep; |
||
1283 | int nic_addr; |
||
1284 | iovec_dat_t *iovp; |
||
1285 | vir_bytes offset; |
||
1286 | vir_bytes count; |
||
1287 | { |
||
1288 | vir_bytes vir_user; |
||
1289 | vir_bytes ecount; |
||
1290 | int i, r, bytes, user_proc; |
||
1291 | u8_t two_bytes[2]; |
||
1292 | int odd_byte; |
||
1293 | |||
1294 | ecount= (count+1) & ~1; |
||
1295 | odd_byte= 0; |
||
1296 | |||
1297 | outb_reg0(dep, DP_RBCR0, ecount & 0xFF); |
||
1298 | outb_reg0(dep, DP_RBCR1, ecount >> 8); |
||
1299 | outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF); |
||
1300 | outb_reg0(dep, DP_RSAR1, nic_addr >> 8); |
||
1301 | outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); |
||
1302 | |||
1303 | i= 0; |
||
1304 | while (count > 0) |
||
1305 | { |
||
1306 | if (i >= IOVEC_NR) |
||
1307 | { |
||
1308 | dp_next_iovec(iovp); |
||
1309 | i= 0; |
||
1310 | continue; |
||
1311 | } |
||
1312 | assert(i < iovp->iod_iovec_s); |
||
1313 | if (offset >= iovp->iod_iovec[i].iov_size) |
||
1314 | { |
||
1315 | offset -= iovp->iod_iovec[i].iov_size; |
||
1316 | i++; |
||
1317 | continue; |
||
1318 | } |
||
1319 | bytes = iovp->iod_iovec[i].iov_size - offset; |
||
1320 | if (bytes > count) |
||
1321 | bytes = count; |
||
1322 | |||
1323 | user_proc= iovp->iod_proc_nr; |
||
1324 | vir_user= iovp->iod_iovec[i].iov_addr + offset; |
||
1325 | if (odd_byte) |
||
1326 | { |
||
1327 | r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[1], |
||
1328 | user_proc, D, vir_user, 1); |
||
1329 | if (r != OK) |
||
1330 | { |
||
1331 | panic("DP8390", |
||
1332 | "dp_pio16_nic2user: sys_vircopy failed", |
||
1333 | r); |
||
1334 | } |
||
1335 | count--; |
||
1336 | offset++; |
||
1337 | bytes--; |
||
1338 | vir_user++; |
||
1339 | odd_byte= 0; |
||
1340 | if (!bytes) |
||
1341 | continue; |
||
1342 | } |
||
1343 | ecount= bytes & ~1; |
||
1344 | if (ecount != 0) |
||
1345 | { |
||
1346 | do_vir_insw(dep->de_data_port, user_proc, vir_user, |
||
1347 | ecount); |
||
1348 | count -= ecount; |
||
1349 | offset += ecount; |
||
1350 | bytes -= ecount; |
||
1351 | vir_user += ecount; |
||
1352 | } |
||
1353 | if (bytes) |
||
1354 | { |
||
1355 | assert(bytes == 1); |
||
1356 | *(u16_t *)two_bytes= inw(dep->de_data_port); |
||
1357 | r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[0], |
||
1358 | user_proc, D, vir_user, 1); |
||
1359 | if (r != OK) |
||
1360 | { |
||
1361 | panic("DP8390", |
||
1362 | "dp_pio16_nic2user: sys_vircopy failed", |
||
1363 | r); |
||
1364 | } |
||
1365 | count--; |
||
1366 | offset++; |
||
1367 | bytes--; |
||
1368 | vir_user++; |
||
1369 | odd_byte= 1; |
||
1370 | } |
||
1371 | } |
||
1372 | assert(count == 0); |
||
1373 | } |
||
1374 | |||
1375 | /*===========================================================================* |
||
1376 | * dp_next_iovec * |
||
1377 | *===========================================================================*/ |
||
1378 | static void dp_next_iovec(iovp) |
||
1379 | iovec_dat_t *iovp; |
||
1380 | { |
||
1381 | assert(iovp->iod_iovec_s > IOVEC_NR); |
||
1382 | |||
1383 | iovp->iod_iovec_s -= IOVEC_NR; |
||
1384 | |||
1385 | iovp->iod_iovec_addr += IOVEC_NR * sizeof(iovec_t); |
||
1386 | |||
1387 | get_userdata(iovp->iod_proc_nr, iovp->iod_iovec_addr, |
||
1388 | (iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) * |
||
1389 | sizeof(iovec_t), iovp->iod_iovec); |
||
1390 | } |
||
1391 | |||
1392 | /*===========================================================================* |
||
4163 | mejdrech | 1393 | * conf_hw * |
1394 | *===========================================================================*/ |
||
1395 | static void conf_hw(dep) |
||
1396 | dpeth_t *dep; |
||
1397 | { |
||
1398 | // static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0 /* ,... */ }; |
||
1399 | |||
1400 | // int ifnr; |
||
1401 | // dp_conf_t *dcp; |
||
1402 | |||
1403 | // dep->de_mode= DEM_DISABLED; /* Superfluous */ |
||
1404 | // ifnr= dep-de_table; |
||
1405 | |||
1406 | // dcp= &dp_conf[ifnr]; |
||
1407 | // update_conf(dep, dcp); |
||
1408 | // if (dep->de_mode != DEM_ENABLED) |
||
1409 | // return; |
||
1410 | if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep)) |
||
1411 | { |
||
1412 | printf("%s: No ethernet card found at 0x%x\n", |
||
1413 | dep->de_name, dep->de_base_port); |
||
1414 | dep->de_mode= DEM_DISABLED; |
||
1415 | return; |
||
1416 | } |
||
1417 | |||
1418 | /* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000; |
||
1419 | |||
1420 | dep->de_mode = DEM_ENABLED; |
||
1421 | |||
1422 | dep->de_flags = DEF_EMPTY; |
||
1423 | // dep->de_stat = empty_stat; |
||
1424 | } |
||
1425 | |||
1426 | /*===========================================================================* |
||
1427 | * map_hw_buffer * |
||
1428 | *===========================================================================*/ |
||
1429 | static void map_hw_buffer(dep) |
||
1430 | dpeth_t *dep; |
||
1431 | { |
||
1432 | // int r; |
||
1433 | // size_t o, size; |
||
1434 | // char *buf, *abuf; |
||
1435 | |||
1436 | if (dep->de_prog_IO) |
||
1437 | { |
||
4192 | mejdrech | 1438 | #if 0 |
4163 | mejdrech | 1439 | if(debug){ |
1440 | printf( |
||
1441 | "map_hw_buffer: programmed I/O, no need to map buffer\n"); |
||
1442 | } |
||
4192 | mejdrech | 1443 | #endif |
4163 | mejdrech | 1444 | dep->de_locmem = (char *)-dep->de_ramsize; /* trap errors */ |
1445 | return; |
||
4192 | mejdrech | 1446 | }else{ |
1447 | printf( "map_hw_buffer: no buffer!" ); |
||
4163 | mejdrech | 1448 | } |
1449 | |||
1450 | // size = dep->de_ramsize + PAGE_SIZE; /* Add PAGE_SIZE for |
||
1451 | // * alignment |
||
1452 | // */ |
||
1453 | // buf= malloc(size); |
||
1454 | // if (buf == NULL) |
||
1455 | // panic(__FILE__, "map_hw_buffer: cannot malloc size", size); |
||
1456 | // o= PAGE_SIZE - ((vir_bytes)buf % PAGE_SIZE); |
||
1457 | // abuf= buf + o; |
||
1458 | // printf("buf at 0x%x, abuf at 0x%x\n", buf, abuf); |
||
1459 | |||
1460 | // r= sys_vm_map(SELF, 1 /* map */, (vir_bytes)abuf, |
||
1461 | // dep->de_ramsize, (phys_bytes)dep->de_linmem); |
||
1462 | // if (r != OK) |
||
1463 | // panic(__FILE__, "map_hw_buffer: sys_vm_map failed", r); |
||
1464 | // dep->de_locmem = abuf; |
||
1465 | } |
||
1466 | |||
1467 | /*===========================================================================* |
||
1468 | * reply * |
||
1469 | *===========================================================================*/ |
||
1470 | static void reply(dep, err, may_block) |
||
1471 | dpeth_t *dep; |
||
1472 | int err; |
||
1473 | int may_block; |
||
1474 | { |
||
1475 | /* message reply; |
||
1476 | int status; |
||
1477 | int r; |
||
1478 | |||
1479 | status = 0; |
||
1480 | if (dep->de_flags & DEF_PACK_SEND) |
||
1481 | status |= DL_PACK_SEND; |
||
1482 | if (dep->de_flags & DEF_PACK_RECV) |
||
1483 | status |= DL_PACK_RECV; |
||
1484 | |||
1485 | reply.m_type = DL_TASK_REPLY; |
||
1486 | reply.DL_PORT = dep - de_table; |
||
1487 | reply.DL_PROC = dep->de_client; |
||
1488 | reply.DL_STAT = status | ((u32_t) err << 16); |
||
1489 | reply.DL_COUNT = dep->de_read_s; |
||
1490 | reply.DL_CLCK = 0; *//* Don't know */ |
||
1491 | /* r= send(dep->de_client, &reply); |
||
1492 | |||
1493 | if (r == ELOCKED && may_block) |
||
1494 | { |
||
1495 | #if 0 |
||
1496 | printf("send locked\n"); |
||
1497 | #endif |
||
1498 | return; |
||
1499 | } |
||
1500 | |||
1501 | if (r < 0) |
||
1502 | panic("", "dp8390: send failed:", r); |
||
1503 | |||
1504 | dep->de_read_s = 0; |
||
1505 | */ dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV); |
||
1506 | } |
||
1507 | |||
4192 | mejdrech | 1508 | /*===========================================================================* |
1509 | * get_userdata * |
||
1510 | *===========================================================================*/ |
||
1511 | static void get_userdata(user_proc, user_addr, count, loc_addr) |
||
1512 | int user_proc; |
||
1513 | vir_bytes user_addr; |
||
1514 | vir_bytes count; |
||
1515 | void *loc_addr; |
||
1516 | { |
||
1517 | int r; |
||
1518 | |||
1519 | r= sys_vircopy(user_proc, D, user_addr, |
||
1520 | SELF, D, (vir_bytes)loc_addr, count); |
||
1521 | if (r != OK) |
||
1522 | panic("DP8390", "get_userdata: sys_vircopy failed", r); |
||
1523 | } |
||
1524 | |||
1525 | static void insb(port_t port, void *buf, size_t size) |
||
1526 | { |
||
4243 | mejdrech | 1527 | size_t i; |
4192 | mejdrech | 1528 | |
1529 | for( i = 0; i < size; ++ i ){ |
||
1530 | *(( uint8_t * )( buf + i )) = inb( port ); |
||
1531 | } |
||
1532 | } |
||
1533 | |||
1534 | static void insw(port_t port, void *buf, size_t size) |
||
1535 | { |
||
4243 | mejdrech | 1536 | size_t i; |
4192 | mejdrech | 1537 | |
1538 | for( i = 0; i < size; i += 2 ){ |
||
1539 | *(( uint16_t * )( buf + i )) = inw( port ); |
||
1540 | } |
||
1541 | } |
||
1542 | |||
1543 | static void outsb(port_t port, void *buf, size_t size) |
||
1544 | { |
||
4243 | mejdrech | 1545 | size_t i; |
4192 | mejdrech | 1546 | |
1547 | for( i = 0; i < size; ++ i ){ |
||
1548 | outb( port, *(( uint8_t * )( buf + i ))); |
||
1549 | } |
||
1550 | } |
||
1551 | |||
1552 | static void outsw(port_t port, void *buf, size_t size) |
||
1553 | { |
||
4243 | mejdrech | 1554 | size_t i; |
4192 | mejdrech | 1555 | |
1556 | for( i = 0; i < size; i += 2 ){ |
||
1557 | outw( port, *(( uint16_t * )( buf + i ))); |
||
1558 | } |
||
1559 | } |
||
1560 | |||
4163 | mejdrech | 1561 | /* |
1562 | * $PchId: dp8390.c,v 1.25 2005/02/10 17:32:07 philip Exp $ |
||
1563 | */ |
||
1564 | |||
1565 | /** @} |
||
1566 | */ |