34,16 → 34,12 |
*/ |
|
#include <assert.h> |
//#include <async.h> |
#include <ddi.h> |
#include <errno.h> |
#include <malloc.h> |
#include <mem.h> |
//#include <stdio.h> |
//#include <sysinfo.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/types.h> |
|
#include "../../err.h" |
#include "../../messages.h" |
52,19 → 48,18 |
#include "../../structures/packet/packet_client.h" |
#include "../../structures/measured_strings.h" |
|
#include "../device.h" |
#include "../netif.h" |
#include "../netif_interface.h" |
|
#include "dp8390.h" |
#include "dp8390_drv.h" |
#include "dp8390_module.h" |
#include "dp8390_port.h" |
//#include "local.h" |
#include "../device.h" |
#include "../netif.h" |
|
//TODO sync stats |
|
#define NAME "dp8390 network interface" |
|
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
#define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
|
static irq_cmd_t dp8390_cmds[] = { |
77,10 → 72,9 |
.value = 2, |
.srcarg = 2 |
}, |
{//TODO remember device_id |
.cmd = CMD_ACCEPT, |
.value = 0, |
.dstarg = 1, |
{ .cmd = CMD_PIO_WRITE_8, |
.addr = NULL, |
.srcarg = 2 |
}, |
{ |
.cmd = CMD_ACCEPT |
94,58 → 88,84 |
|
netif_globals_t netif_globals; |
|
void netif_print_name( void ); |
int initialize( void ); |
int probe_auto_message( void ); |
int probe_message( device_id_t device_id, int irq, int io ); |
int send_message( device_id_t device_id, packet_t packet ); |
int start_message( device_id_t device_id ); |
int stop_message( device_id_t device_id ); |
measured_string_ref get_addr_message( device_id_t device_id ); |
void netif_print_name( void ); |
|
static void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
void change_state( device_ref device, device_state_t state ); |
|
int specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
return ENOTSUP; |
} |
|
int get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
ERROR_DECLARE; |
|
device_ref device; |
eth_stat_t * de_stat; |
|
if( ! stats ) return EBADMEM; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
de_stat = & (( dpeth_t * ) device->specific )->de_stat; |
null_device_stats( stats ); |
stats->rx_errors = de_stat->ets_recvErr; |
stats->tx_errors = de_stat->ets_sendErr; |
stats->rx_crc_errors = de_stat->ets_CRCerr; |
stats->rx_frame_errors = de_stat->ets_frameAll; |
stats->rx_missed_errors = de_stat->ets_missedP; |
stats->rx_packets = de_stat->ets_packetR; |
stats->tx_packets = de_stat->ets_packetT; |
stats->collisions = de_stat->ets_collision; |
stats->tx_aborted_errors = de_stat->ets_transAb; |
stats->tx_carrier_errors = de_stat->ets_carrSense; |
stats->tx_heartbeat_errors = de_stat->ets_CDheartbeat; |
stats->tx_window_errors = de_stat->ets_OWC; |
return EOK; |
} |
|
void netif_print_name( void ){ |
printf( NAME ); |
} |
|
measured_string_ref get_addr_message( device_id_t device_id ){ |
int get_addr_message( device_id_t device_id, measured_string_ref address ){ |
ERROR_DECLARE; |
|
device_ref device; |
|
if( ERROR_OCCURRED( find_device( device_id, & device ))) return NULL; |
return (( dp_device_ref )( device->specific ))->addr; |
if( ! address ) return EBADMEM; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
address->value = ( char * ) ( & (( dpeth_t * ) device->specific )->de_address ); |
address->length = CONVERT_SIZE( ether_addr_t, char, 1 ); |
return EOK; |
} |
|
static void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
{ |
// int irq; |
device_ref device; |
dpeth_t * dep; |
|
if( find_device( IPC_GET_DEVICE( call ), & device ) == EOK ){ |
dep = & (( dp_device_ref ) device->specific )->dep; |
printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
if ( dep->de_mode != DEM_ENABLED) |
// continue; |
return; |
assert( dep->de_flags & DEF_ENABLED); |
// irq= dep.de_irq; |
// assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
if ( dep->de_int_pending || 1) |
printf( "\ndevice %d - irq %x", IPC_GET_DEVICE( call ), IPC_GET_ISR( call )); |
if( find_device( IPC_GET_DEVICE( call ), & device ) != EOK ) return; |
dep = ( dpeth_t * ) device->specific; |
printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
if ( dep->de_mode != DEM_ENABLED) |
// continue; |
return; |
assert( dep->de_flags & DEF_ENABLED); |
// irq= dep.de_irq; |
// assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
// if ( dep->de_int_pending || 1) |
// { |
dep->de_int_pending= 0; |
dp_check_ints( dep ); |
// do_int(dep); |
/* r= sys_irqenable(&dep->de_hook); |
if (r != OK) |
{ |
dep->de_int_pending= 0; |
dp_check_ints( dep ); |
// do_int(dep); |
/* r= sys_irqenable(&dep->de_hook); |
if (r != OK) |
{ |
panic("DP8390", |
"unable enable interrupts", r); |
} |
*/ } |
} |
panic("DP8390", |
"unable enable interrupts", r); |
} |
*/// } |
} |
|
int probe_auto_message( void ){ |
155,42 → 175,35 |
int probe_message( device_id_t device_id, int irq, int io ){ |
ERROR_DECLARE; |
|
device_ref device; |
dp_device_ref dp_device; |
device_ref device; |
dpeth_t * dep; |
|
printf( "\n" ); |
device = ( device_ref ) malloc( sizeof( device_t )); |
if( ! device ) return ENOMEM; |
dp_device = ( dp_device_ref ) malloc( sizeof( dp_device_t )); |
if( ! dp_device ){ |
dep = ( dpeth_t * ) malloc( sizeof( dpeth_t )); |
if( ! dep ){ |
free( device ); |
return ENOMEM; |
} |
bzero( device, sizeof( device_t )); |
bzero( dp_device, sizeof( dp_device_t )); |
bzero( dep, sizeof( dpeth_t )); |
device->device_id = device_id; |
device->nil_phone = -1; |
device->specific = ( void * ) dp_device; |
device->state = NETIF_ACTIVE; |
dp_device->dep.de_irq = irq; |
// dp_device->dep.de_base_port = io; |
dp_device->dep.de_mode = DEM_DISABLED; |
device->specific = ( void * ) dep; |
device->state = NETIF_STOPPED; |
dep->parent = device; |
dep->de_irq = irq; |
dep->de_mode = DEM_DISABLED; |
//TODO address? |
if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dp_device->dep.de_base_port )) |
|| ERROR_OCCURRED( do_probe( & dp_device->dep ))){ |
free( dp_device ); |
if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dep->de_base_port )) |
|| ERROR_OCCURRED( do_probe( dep ))){ |
free( dep ); |
free( device ); |
return ERROR_CODE; |
} |
dp_device->addr = measured_string_create_bulk(( char * ) & dp_device->dep.de_address, CONVERT_SIZE( ether_addr_t, char, 1 )); |
if( ! dp_device->addr ){ |
free( dp_device ); |
free( device ); |
return ENOMEM; |
} |
if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, device->device_id, device ))){ |
free( dp_device->addr ); |
free( dp_device ); |
free( dep ); |
free( device ); |
return ERROR_CODE; |
} |
198,8 → 211,23 |
} |
|
int send_message( device_id_t device_id, packet_t packet ){ |
// TODO send message |
return ENOTSUP; |
ERROR_DECLARE; |
|
device_ref device; |
dpeth_t * dep; |
packet_t next; |
|
ERROR_PROPAGATE( find_device( IPC_GET_DEVICE( call ), & device )); |
dep = ( dpeth_t * ) device->specific; |
// process packet queue |
do{ |
next = pq_detach( packet ); |
if( do_pwrite( dep, packet, FALSE ) != EBUSY ){ |
netif_pq_release( packet_get_id( packet )); |
} |
packet = next; |
}while( packet ); |
return EOK; |
} |
|
int start_message( device_id_t device_id ){ |
210,16 → 238,15 |
|
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != NETIF_ACTIVE ){ |
dep = & (( dp_device_ref ) device->specific )->dep; |
dep = ( dpeth_t * ) device->specific; |
dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
dp8390_cmds[ 2 ].value = device->device_id; |
ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, 0, & dp8390_code )); |
dp8390_cmds[ 2 ].addr = dp8390_cmds[ 0 ].addr; |
ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, device->device_id, & dp8390_code )); |
if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
ipc_unregister_irq( dep->de_irq, device->device_id ); |
return ERROR_CODE; |
} |
device->state = NETIF_ACTIVE; |
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
change_state( device, NETIF_ACTIVE ); |
} |
return EOK; |
} |
232,15 → 259,20 |
|
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != NETIF_STOPPED ){ |
dep = & (( dp_device_ref ) device->specific )->dep; |
dep = ( dpeth_t * ) device->specific; |
do_stop( dep ); |
ipc_unregister_irq( dep->de_irq, device->device_id ); |
device->state = NETIF_STOPPED; |
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
change_state( device, NETIF_STOPPED ); |
} |
return EOK; |
} |
|
void change_state( device_ref device, device_state_t state ){ |
device->state = state; |
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
} |
|
int initialize( void ){ |
ipcarg_t phonehash; |
|
249,5 → 281,11 |
return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
} |
|
int netif_send_packet( dpeth_t * dep, packet_t packet ){ |
if( !( dep && dep->parent )) return EINVAL; |
nil_message(( device_ref ) dep->parent, NET_NIL_RECEIVED, packet_get_id( packet ), 0 ); |
return EOK; |
} |
|
/** @} |
*/ |