Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3911 → Rev 3912

/branches/network/uspace/srv/net/netif/device.h
1,5 → 1,5
/*
* Copyright (c) 2008 Lukas Mejdrech
* Copyright (c) 2009 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
26,12 → 26,12
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup net
* @{
/** @addtogroup netif
* @{
*/
 
/**
* @file
/** @file
* Device identifier, state and usage statistics.
*/
 
#ifndef __NET_DEVICE_ID_TYPE_H__
42,51 → 42,119
#define DEVICE_MAP_DECLARE INT_MAP_DECLARE
#define DEVICE_MAP_IMPLEMENT INT_MAP_IMPLEMENT
 
/** Device identifier type.
*/
typedef int device_id_t;
 
/** Device state type.
*/
typedef enum device_state device_state_t;
 
/** Type definition of the device usage statistics.
* @see device_stats
*/
typedef struct device_stats device_stats_t;
 
/** Type definition of the device usage statistics pointer.
* @see device_stats
*/
typedef device_stats_t * device_stats_ref;
 
/** Device state.
*/
enum device_state{
/** Device not present or not initialized.
*/
NETIF_NULL = 0,
/** Device present and stopped.
*/
NETIF_STOPPED,
/** Device present and active.
*/
NETIF_ACTIVE,
/** Device present but unable to transmit.
*/
NETIF_CARRIER_LOST
};
 
// based on linux_kernel/include/linux/netdevice.h
 
/** Device usage statistics.
* Based on linux_kernel/include/linux/netdevice.h.
*/
struct device_stats{
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
unsigned long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long multicast; /* multicast packets received */
/** Total packets received.
*/
unsigned long rx_packets;
/** Total packets transmitted.
*/
unsigned long tx_packets;
/** Total bytes received.
*/
unsigned long rx_bytes;
/** Total bytes transmitted.
*/
unsigned long tx_bytes;
/** Bad packets received counter.
*/
unsigned long rx_errors;
/** Packet transmition problems counter.
*/
unsigned long tx_errors;
/** No space in buffers counter.
*/
unsigned long rx_dropped;
/** No space available counter.
*/
unsigned long tx_dropped;
/** Total multicast packets received.
*/
unsigned long multicast;
/** The number of collisions due to congestion on the medium.
*/
unsigned long collisions;
 
/* detailed rx_errors: */
/** Received packet length error counter.
*/
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/** Receiver buffer overflow counter.
*/
unsigned long rx_over_errors;
/** Received packet with crc error counter.
*/
unsigned long rx_crc_errors;
/** Received frame alignment error counter.
*/
unsigned long rx_frame_errors;
/** Receiver fifo overrun counter.
*/
unsigned long rx_fifo_errors;
/** Receiver missed packet counter.
*/
unsigned long rx_missed_errors;
 
/* detailed tx_errors */
/** Transmitter aborted counter.
*/
unsigned long tx_aborted_errors;
/** Transmitter carrier errors counter.
*/
unsigned long tx_carrier_errors;
/** Transmitter fifo overrun counter.
*/
unsigned long tx_fifo_errors;
/** Transmitter carrier errors counter.
*/
unsigned long tx_heartbeat_errors;
/** Transmitter window errors counter.
*/
unsigned long tx_window_errors;
 
/* for cslip etc */
/** Total compressed packets received.
*/
unsigned long rx_compressed;
/** Total compressed packet transmitted.
*/
unsigned long tx_compressed;
};
 
/branches/network/uspace/srv/net/netif/netif.c
1,5 → 1,5
/*
* Copyright (c) 2008 Lukas Mejdrech
* Copyright (c) 2009 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
26,8 → 26,8
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup net
* @{
/** @addtogroup netif
* @{
*/
 
/** @file
169,10 → 169,12
async_set_client_connection( client_connection );
netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
device_map_initialize( & netif_globals.device_map );
ERROR_PROPAGATE( pm_init());
ERROR_PROPAGATE( initialize());
ERROR_PROPAGATE( pm_init());
 
async_manager();
 
pm_destroy();
return EOK;
}
 
/branches/network/uspace/srv/net/netif/lo/lo.c
1,5 → 1,5
/*
* Copyright (c) 2008 Lukas Mejdrech
* Copyright (c) 2009 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
26,8 → 26,8
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup net
* @{
/** @addtogroup lo
* @{
*/
 
/** @file
73,7 → 73,7
ERROR_PROPAGATE( find_device( device_id, & device ));
if( device->state != state ){
device->state = state;
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL, NULL, NULL, NULL );
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL );
}
return EOK;
}
93,7 → 93,7
( ** device ).state = NETIF_STOPPED;
( ** device ).flags = NULL;
( ** device ).mtu = DEFAULT_MTU;
if( ERROR_OCCURED( device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ))){
if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ))){
free( * device );
* device = NULL;
return ERROR_CODE;
138,8 → 138,8
// get configuration
message = async_send_2( netif_globals.networking_phone, NET_NET_GET_DEVICE_CONF, device->device_id, count, & answer );
// send names and get settings
if( ERROR_OCCURED( measured_strings_send( netif_globals.networking_phone, configuration, count ))
|| ERROR_OCCURED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){
if( ERROR_OCCURRED( measured_strings_send( netif_globals.networking_phone, configuration, count ))
|| ERROR_OCCURRED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){
async_wait_for( message, NULL );
return ERROR_CODE;
}
178,9 → 178,9
++ device->stats.rx_dropped;
return EOK;
}
async_msg_2( device->nil_phone, NET_NIL_RECEIVED, device_id, packet_get_id( received ));
nil_message( device, NET_NIL_RECEIVED, packet_get_id( received ), NULL );
// message = async_send_1( device->nil_phone, NET_NIL_RECEIVED, ( device_id ), & answer );
// if( ERROR_OCCURED( packet_send( received, device->nil_phone ))){
// if( ERROR_OCCURRED( packet_send( received, device->nil_phone ))){
// ++ device->stats.rx_dropped;
// }
// if( result != EOK ) ++ device->stats.rx_dropped;
/branches/network/uspace/srv/net/netif/netif.h
1,5 → 1,5
/*
* Copyright (c) 2008 Lukas Mejdrech
* Copyright (c) 2009 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
26,12 → 26,12
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup net
* @{
/** @addtogroup netif
* @{
*/
 
/**
* @file
/** @file
* Network interface module skeleton.
*/
 
#ifndef __NET_NETIF_H__
39,31 → 39,88
 
#include "device.h"
 
#define nil_message( device, message, arg2, arg3, result1, result2, result3 ) \
/** Sends the notification message to the registered network interface layer module.
* Wrapper of the async_msg_3().
* The first message argument is always the device identifier.
* @param device The device specific data. Input parameter.
* @param message The message to be sent. Input parameter.
* @param arg2 The second message argument. Input parameter.
* @param arg3 The third message argument. Input parameter.
*/
#define nil_message( device, message, arg2, arg3 ) \
if(( device )->nil_phone >= 0 ) async_msg_3(( device )->nil_phone, ( message ), ( device )->device_id, arg2, arg3 )
 
typedef struct device device_t;
typedef device_t * device_ref;
/** Network interface module skeleton global data.
*/
typedef struct netif_globals netif_globals_t;
 
/** Type definition of the device specific data.
* @see netif_device
*/
typedef struct netif_device device_t;
 
/** Type definition of the device specific data pointer.
* @see netif_device
*/
typedef device_t * device_ref;
 
/** Device map.
* Maps device identifiers to the network interface device specific data.
* @see device.h
*/
DEVICE_MAP_DECLARE( device_map, device_t );
 
struct device{
/** Network interface device specific data.
*/
struct netif_device{
/** Device identifier.
*/
device_id_t device_id;
/** Receiving network interface layer phone.
*/
int nil_phone;
/** Usage statistics.
*/
device_stats_t stats;
/** Actual device state.
*/
device_state_t state;
// TODO needed?
/** Various device flags.
*/
int flags;
/** Maximum transmission unit.
* The maximum packet content to be transmited.
*/
size_t mtu;
/** Driver specific data.
*/
void * specific;
};
 
/** Network interface module skeleton global data.
*/
struct netif_globals{
/** Networking module phone.
*/
int networking_phone;
/** Device map.
*/
device_map_t device_map;
};
 
/** Finds the device specific data.
* @param device_id The device identifier. Input parameter.
* @param device The device specific data. Output parameter.
* @returns EOK on success.
* @returns ENOENT if device is not found.
* @returns EPERM if the device is not initialized.
*/
int find_device( device_id_t device_id, device_ref * device );
 
/** Clears the usage statistics.
* @param stats The usage statistics. Input parameter.
*/
void null_device_stats( device_stats_ref stats );
 
#endif