1 |
|
/* |
2 |
|
* ether.cpp - SheepShaver Ethernet Device Driver (DLPI) |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2005 Marc Hellwig and Christian Bauer |
4 |
> |
* SheepShaver (C) 1997-2008 Marc Hellwig and Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
31 |
|
#include "ether.h" |
32 |
|
#include "ether_defs.h" |
33 |
|
#include "macos_util.h" |
34 |
– |
#include "emul_op.h" |
35 |
– |
#include "main.h" |
34 |
|
|
35 |
|
#define DEBUG 0 |
36 |
|
#include "debug.h" |
37 |
|
|
40 |
– |
#if DIRECT_ADDRESSING |
41 |
– |
#warning "This code is not direct addressing clean" |
42 |
– |
#endif |
43 |
– |
|
38 |
|
// Packet types |
39 |
|
enum { |
40 |
|
kPktDIX = 0, |
177 |
|
static uint32 allocb_tvect = 0; |
178 |
|
mblk_t *allocb(size_t arg1, int arg2) |
179 |
|
{ |
180 |
< |
return (mblk_t *)Mac2HostAddr(CallMacOS2(allocb_ptr, allocb_tvect, arg1, arg2)); |
180 |
> |
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS2(allocb_ptr, allocb_tvect, arg1, arg2)); |
181 |
|
} |
182 |
|
typedef void (*freeb_ptr)(mblk_t *); |
183 |
|
static uint32 freeb_tvect = 0; |
195 |
|
static uint32 copyb_tvect = 0; |
196 |
|
static inline mblk_t *copyb(mblk_t *arg1) |
197 |
|
{ |
198 |
< |
return (mblk_t *)Mac2HostAddr(CallMacOS1(copyb_ptr, copyb_tvect, arg1)); |
198 |
> |
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS1(copyb_ptr, copyb_tvect, arg1)); |
199 |
|
} |
200 |
|
typedef mblk_t *(*dupmsg_ptr)(mblk_t *); |
201 |
|
static uint32 dupmsg_tvect = 0; |
202 |
|
static inline mblk_t *dupmsg(mblk_t *arg1) |
203 |
|
{ |
204 |
< |
return (mblk_t *)Mac2HostAddr(CallMacOS1(dupmsg_ptr, dupmsg_tvect, arg1)); |
204 |
> |
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS1(dupmsg_ptr, dupmsg_tvect, arg1)); |
205 |
|
} |
206 |
|
typedef mblk_t *(*getq_ptr)(queue_t *); |
207 |
|
static uint32 getq_tvect = 0; |
208 |
|
static inline mblk_t *getq(queue_t *arg1) |
209 |
|
{ |
210 |
< |
return (mblk_t *)Mac2HostAddr(CallMacOS1(getq_ptr, getq_tvect, arg1)); |
210 |
> |
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS1(getq_ptr, getq_tvect, arg1)); |
211 |
|
} |
212 |
|
typedef int (*putq_ptr)(queue_t *, mblk_t *); |
213 |
|
static uint32 putq_tvect = 0; |
279 |
|
static uint32 mi_next_ptr_tvect = 0; |
280 |
|
static inline DLPIStream *mi_next_ptr(DLPIStream *arg1) |
281 |
|
{ |
282 |
< |
return (DLPIStream *)Mac2HostAddr(CallMacOS1(mi_next_ptr_ptr, mi_next_ptr_tvect, arg1)); |
282 |
> |
return (DLPIStream *)Mac2HostAddr((uint32)CallMacOS1(mi_next_ptr_ptr, mi_next_ptr_tvect, arg1)); |
283 |
|
} |
284 |
< |
|
284 |
> |
#ifdef USE_ETHER_FULL_DRIVER |
285 |
> |
typedef void (*ether_dispatch_packet_ptr)(uint32 p, uint32 size); |
286 |
> |
static uint32 ether_dispatch_packet_tvect = 0; |
287 |
> |
#endif |
288 |
|
|
289 |
|
// Prototypes |
290 |
|
static void ether_ioctl(DLPIStream *the_stream, queue_t* q, mblk_t* mp); |
308 |
|
* Initialize ethernet stream module |
309 |
|
*/ |
310 |
|
|
311 |
< |
uint8 InitStreamModule(void *theID) |
311 |
> |
static uint8 InitStreamModuleImpl(void *theID) |
312 |
|
{ |
313 |
|
D(bug("InitStreamModule\n")); |
314 |
|
|
391 |
|
if (mi_next_ptr_tvect == 0) |
392 |
|
return false; |
393 |
|
|
394 |
+ |
#ifndef USE_ETHER_FULL_DRIVER |
395 |
|
// Initialize stream list (which might be leftover) |
396 |
|
dlpi_stream_list = NULL; |
397 |
|
|
398 |
|
// Ask add-on for ethernet hardware address |
399 |
|
AO_get_ethernet_address(Host2MacAddr(hardware_address)); |
400 |
+ |
#endif |
401 |
|
|
402 |
|
// Yes, we're open |
403 |
|
ether_driver_opened = true; |
404 |
|
return true; |
405 |
|
} |
406 |
|
|
407 |
+ |
uint8 InitStreamModule(void *theID) |
408 |
+ |
{ |
409 |
+ |
// Common initialization code |
410 |
+ |
bool net_open = InitStreamModuleImpl(theID); |
411 |
+ |
|
412 |
+ |
// Call InitStreamModule() in native side |
413 |
+ |
#ifdef BUILD_ETHER_FULL_DRIVER |
414 |
+ |
extern bool NativeInitStreamModule(void *); |
415 |
+ |
if (!NativeInitStreamModule((void *)ether_dispatch_packet)) |
416 |
+ |
net_open = false; |
417 |
+ |
#endif |
418 |
+ |
|
419 |
+ |
// Import functions from the Ethernet driver |
420 |
+ |
#ifdef USE_ETHER_FULL_DRIVER |
421 |
+ |
ether_dispatch_packet_tvect = (uintptr)theID; |
422 |
+ |
D(bug("ether_dispatch_packet TVECT at %08lx\n", ether_dispatch_packet_tvect)); |
423 |
+ |
if (ether_dispatch_packet_tvect == 0) |
424 |
+ |
net_open = false; |
425 |
+ |
#endif |
426 |
+ |
|
427 |
+ |
return net_open; |
428 |
+ |
} |
429 |
+ |
|
430 |
|
|
431 |
|
/* |
432 |
|
* Terminate ethernet stream module |
433 |
|
*/ |
434 |
|
|
435 |
< |
void TerminateStreamModule(void) |
435 |
> |
static void TerminateStreamModuleImpl(void) |
436 |
|
{ |
437 |
|
D(bug("TerminateStreamModule\n")); |
438 |
|
|
439 |
+ |
#ifndef USE_ETHER_FULL_DRIVER |
440 |
|
// This happens sometimes. I don't know why. |
441 |
|
if (dlpi_stream_list != NULL) |
442 |
|
printf("FATAL: TerminateStreamModule() called, but streams still open\n"); |
443 |
+ |
#endif |
444 |
|
|
445 |
|
// Sorry, we're closed |
446 |
|
ether_driver_opened = false; |
447 |
|
} |
448 |
|
|
449 |
+ |
void TerminateStreamModule(void) |
450 |
+ |
{ |
451 |
+ |
// Common termination code |
452 |
+ |
TerminateStreamModuleImpl(); |
453 |
+ |
|
454 |
+ |
// Call TerminateStreamModule() in native side |
455 |
+ |
#ifdef BUILD_ETHER_FULL_DRIVER |
456 |
+ |
extern void NativeTerminateStreamModule(void); |
457 |
+ |
NativeTerminateStreamModule(); |
458 |
+ |
#endif |
459 |
+ |
} |
460 |
+ |
|
461 |
|
|
462 |
|
/* |
463 |
|
* Open new stream |
1139 |
|
|
1140 |
|
void ether_dispatch_packet(uint32 p, uint32 size) |
1141 |
|
{ |
1142 |
+ |
#ifdef USE_ETHER_FULL_DRIVER |
1143 |
+ |
// Call handler from the Ethernet driver |
1144 |
+ |
D(bug("ether_dispatch_packet\n")); |
1145 |
+ |
D(bug(" packet data at %p, %d bytes\n", p, size)); |
1146 |
+ |
CallMacOS2(ether_dispatch_packet_ptr, ether_dispatch_packet_tvect, p, size); |
1147 |
+ |
#else |
1148 |
|
// Wrap packet in message block |
1149 |
|
num_rx_packets++; |
1150 |
|
mblk_t *mp; |
1157 |
|
D(bug("WARNING: Cannot allocate mblk for received packet\n")); |
1158 |
|
num_rx_no_mem++; |
1159 |
|
} |
1160 |
+ |
#endif |
1161 |
|
} |
1162 |
|
|
1163 |
|
|