Changeset 609243f4 in mainline for uspace/lib/c


Ignore:
Timestamp:
2011-10-07T15:46:01Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2c50e1
Parents:
f51b1d3
Message:

cherrypick general networking improvements from lp:~helenos-nicf/helenos/nicf (after sanitization)
remove obsolete networking drivers
this renders the networking non-functional for the time being

Location:
uspace/lib/c
Files:
3 added
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    rf51b1d3 r609243f4  
    6868        generic/device/hw_res.c \
    6969        generic/device/char_dev.c \
     70        generic/device/nic.c \
    7071        generic/elf/elf_load.c \
    7172        generic/event.c \
  • uspace/lib/c/generic/net/packet.c

    rf51b1d3 r609243f4  
    3636 */
    3737
     38#include <assert.h>
    3839#include <malloc.h>
    3940#include <mem.h>
     
    4445#include <sys/mman.h>
    4546
    46 #include <adt/generic_field.h>
     47#include <adt/hash_table.h>
    4748#include <net/packet.h>
    4849#include <net/packet_header.h>
    4950
    50 /** Packet map page size. */
    51 #define PACKET_MAP_SIZE 100
    52 
    53 /** Returns the packet map page index.
    54  * @param[in] packet_id The packet identifier.
    55  */
    56 #define PACKET_MAP_PAGE(packet_id)      (((packet_id) - 1) / PACKET_MAP_SIZE)
    57 
    58 /** Returns the packet index in the corresponding packet map page.
    59  *  @param[in] packet_id The packet identifier.
    60  */
    61 #define PACKET_MAP_INDEX(packet_id)     (((packet_id) - 1) % PACKET_MAP_SIZE)
    62 
    63 /** Type definition of the packet map page. */
    64 typedef packet_t *packet_map_t[PACKET_MAP_SIZE];
    65 
    66 /** Packet map.
    67  * Maps packet identifiers to the packet references.
    68  * @see generic_field.h
    69  */
    70 GENERIC_FIELD_DECLARE(gpm, packet_map_t);
     51/** Packet hash table size. */
     52#define PACKET_HASH_TABLE_SIZE  128
    7153
    7254/** Packet map global data. */
     
    7557        fibril_rwlock_t lock;
    7658        /** Packet map. */
    77         gpm_t packet_map;
     59        hash_table_t packet_map;
     60        /** Packet map operations */
     61        hash_table_operations_t operations;
    7862} pm_globals;
    7963
    80 GENERIC_FIELD_IMPLEMENT(gpm, packet_map_t);
     64typedef struct {
     65        link_t link;
     66        packet_t *packet;
     67} pm_entry_t;
     68
     69/**
     70 * Hash function for the packet mapping hash table
     71 */
     72static hash_index_t pm_hash(unsigned long key[])
     73{
     74        return (hash_index_t) key[0] % PACKET_HASH_TABLE_SIZE;
     75}
     76
     77/**
     78 * Key compare function for the packet mapping hash table
     79 */
     80static int pm_compare(unsigned long key[], hash_count_t keys, link_t *link)
     81{
     82        pm_entry_t *entry = list_get_instance(link, pm_entry_t, link);
     83        return entry->packet->packet_id == key[0];
     84}
     85
     86/**
     87 * Remove callback for the packet mapping hash table
     88 */
     89static void pm_remove_callback(link_t *link)
     90{
     91        pm_entry_t *entry = list_get_instance(link, pm_entry_t, link);
     92        free(entry);
     93}
     94
     95/**
     96 * Wrapper used when destroying the whole table
     97 */
     98static void pm_free_wrapper(link_t *link, void *ignored)
     99{
     100        pm_entry_t *entry = list_get_instance(link, pm_entry_t, link);
     101        free(entry);
     102}
     103
    81104
    82105/** Initializes the packet map.
     
    87110int pm_init(void)
    88111{
    89         int rc;
     112        int rc = EOK;
    90113
    91114        fibril_rwlock_initialize(&pm_globals.lock);
    92115       
    93116        fibril_rwlock_write_lock(&pm_globals.lock);
    94         rc = gpm_initialize(&pm_globals.packet_map);
     117       
     118        pm_globals.operations.hash = pm_hash;
     119        pm_globals.operations.compare = pm_compare;
     120        pm_globals.operations.remove_callback = pm_remove_callback;
     121
     122        if (!hash_table_create(&pm_globals.packet_map, PACKET_HASH_TABLE_SIZE, 1,
     123            &pm_globals.operations))
     124                rc = ENOMEM;
     125       
    95126        fibril_rwlock_write_unlock(&pm_globals.lock);
    96127       
     
    100131/** Finds the packet mapping.
    101132 *
    102  * @param[in] packet_id The packet identifier to be found.
    103  * @return              The found packet reference.
    104  * @return              NULL if the mapping does not exist.
     133 * @param[in] packet_id Packet identifier to be found.
     134 *
     135 * @return The found packet reference.
     136 * @return NULL if the mapping does not exist.
     137 *
    105138 */
    106139packet_t *pm_find(packet_id_t packet_id)
    107140{
    108         packet_map_t *map;
    109141        packet_t *packet;
    110 
    111142        if (!packet_id)
    112143                return NULL;
    113144
    114145        fibril_rwlock_read_lock(&pm_globals.lock);
    115         if (packet_id > PACKET_MAP_SIZE * gpm_count(&pm_globals.packet_map)) {
    116                 fibril_rwlock_read_unlock(&pm_globals.lock);
    117                 return NULL;
    118         }
    119         map = gpm_get_index(&pm_globals.packet_map, PACKET_MAP_PAGE(packet_id));
    120         if (!map) {
    121                 fibril_rwlock_read_unlock(&pm_globals.lock);
    122                 return NULL;
    123         }
    124         packet = (*map) [PACKET_MAP_INDEX(packet_id)];
     146        link_t *link =
     147            hash_table_find(&pm_globals.packet_map, &packet_id);
     148        if (link != NULL) {
     149                pm_entry_t *entry =
     150                    hash_table_get_instance(link, pm_entry_t, link);
     151                packet = entry->packet;
     152        } else
     153                packet = NULL;
     154       
    125155        fibril_rwlock_read_unlock(&pm_globals.lock);
    126156        return packet;
     
    129159/** Adds the packet mapping.
    130160 *
    131  * @param[in] packet    The packet to be remembered.
    132  * @return              EOK on success.
    133  * @return              EINVAL if the packet is not valid.
    134  * @return              EINVAL if the packet map is not initialized.
    135  * @return              ENOMEM if there is not enough memory left.
     161 * @param[in] packet Packet to be remembered.
     162 *
     163 * @return EOK on success.
     164 * @return EINVAL if the packet is not valid.
     165 * @return ENOMEM if there is not enough memory left.
     166 *
    136167 */
    137168int pm_add(packet_t *packet)
    138169{
    139         packet_map_t *map;
    140         int rc;
    141 
    142170        if (!packet_is_valid(packet))
    143171                return EINVAL;
    144 
     172       
    145173        fibril_rwlock_write_lock(&pm_globals.lock);
    146 
    147         if (PACKET_MAP_PAGE(packet->packet_id) <
    148             gpm_count(&pm_globals.packet_map)) {
    149                 map = gpm_get_index(&pm_globals.packet_map,
    150                     PACKET_MAP_PAGE(packet->packet_id));
    151         } else {
    152                 do {
    153                         map = (packet_map_t *) malloc(sizeof(packet_map_t));
    154                         if (!map) {
    155                                 fibril_rwlock_write_unlock(&pm_globals.lock);
    156                                 return ENOMEM;
    157                         }
    158                         bzero(map, sizeof(packet_map_t));
    159                         rc = gpm_add(&pm_globals.packet_map, map);
    160                         if (rc < 0) {
    161                                 fibril_rwlock_write_unlock(&pm_globals.lock);
    162                                 free(map);
    163                                 return rc;
    164                         }
    165                 } while (PACKET_MAP_PAGE(packet->packet_id) >=
    166                     gpm_count(&pm_globals.packet_map));
     174        pm_entry_t *entry = malloc(sizeof (pm_entry_t));
     175        if (entry == NULL) {
     176                fibril_rwlock_write_unlock(&pm_globals.lock);
     177                return ENOMEM;
    167178        }
    168 
    169         (*map) [PACKET_MAP_INDEX(packet->packet_id)] = packet;
     179       
     180        entry->packet = packet;
     181        hash_table_insert(&pm_globals.packet_map, &packet->packet_id,
     182            &entry->link);
    170183        fibril_rwlock_write_unlock(&pm_globals.lock);
    171184        return EOK;
    172185}
    173186
    174 /** Releases the packet map. */
     187/** Remove the packet mapping
     188 *
     189 * @param[in] packet The packet to be removed
     190 *
     191 */
     192void pm_remove(packet_t *packet)
     193{
     194        assert(packet_is_valid(packet));
     195       
     196        fibril_rwlock_write_lock(&pm_globals.lock);
     197        hash_table_remove(&pm_globals.packet_map, &packet->packet_id, 1);
     198        fibril_rwlock_write_unlock(&pm_globals.lock);
     199}
     200
     201/** Release the packet map. */
    175202void pm_destroy(void)
    176203{
    177         int count;
    178         int index;
    179         packet_map_t *map;
    180         packet_t *packet;
    181 
    182204        fibril_rwlock_write_lock(&pm_globals.lock);
    183         count = gpm_count(&pm_globals.packet_map);
    184         while (count > 0) {
    185                 map = gpm_get_index(&pm_globals.packet_map, count - 1);
    186                 for (index = PACKET_MAP_SIZE - 1; index >= 0; --index) {
    187                         packet = (*map)[index];
    188                         if (packet_is_valid(packet))
    189                                 munmap(packet, packet->length);
    190                 }
    191         }
    192         gpm_destroy(&pm_globals.packet_map, free);
    193         /* leave locked */
     205        hash_table_apply(&pm_globals.packet_map, pm_free_wrapper, NULL);
     206        hash_table_destroy(&pm_globals.packet_map);
     207        /* Leave locked */
    194208}
    195209
     
    199213 * The packet is inserted right before the packets of the same order value.
    200214 *
    201  * @param[in,out] first The first packet of the queue. Sets the first packet of
    202  *                      the queue. The original first packet may be shifted by
    203  *                      the new packet.
    204  * @param[in] packet    The packet to be added.
    205  * @param[in] order     The packet order value.
    206  * @param[in] metric    The metric value of the packet.
    207  * @return              EOK on success.
    208  * @return              EINVAL if the first parameter is NULL.
    209  * @return              EINVAL if the packet is not valid.
     215 * @param[in,out] first First packet of the queue. Sets the first
     216 *                      packet of the queue. The original first packet
     217 *                      may be shifted by the new packet.
     218 * @param[in] packet    Packet to be added.
     219 * @param[in] order     Packet order value.
     220 * @param[in] metric    Metric value of the packet.
     221 *
     222 * @return EOK on success.
     223 * @return EINVAL if the first parameter is NULL.
     224 * @return EINVAL if the packet is not valid.
     225 *
    210226 */
    211227int pq_add(packet_t **first, packet_t *packet, size_t order, size_t metric)
    212228{
    213         packet_t *item;
    214 
    215         if (!first || !packet_is_valid(packet))
     229        if ((!first) || (!packet_is_valid(packet)))
    216230                return EINVAL;
    217 
     231       
    218232        pq_set_order(packet, order, metric);
    219233        if (packet_is_valid(*first)) {
    220                 item = * first;
     234                packet_t *cur = *first;
     235               
    221236                do {
    222                         if (item->order < order) {
    223                                 if (item->next) {
    224                                         item = pm_find(item->next);
    225                                 } else {
    226                                         item->next = packet->packet_id;
    227                                         packet->previous = item->packet_id;
     237                        if (cur->order < order) {
     238                                if (cur->next)
     239                                        cur = pm_find(cur->next);
     240                                else {
     241                                        cur->next = packet->packet_id;
     242                                        packet->previous = cur->packet_id;
     243                                       
    228244                                        return EOK;
    229245                                }
    230246                        } else {
    231                                 packet->previous = item->previous;
    232                                 packet->next = item->packet_id;
    233                                 item->previous = packet->packet_id;
    234                                 item = pm_find(packet->previous);
    235                                 if (item)
    236                                         item->next = packet->packet_id;
     247                                packet->previous = cur->previous;
     248                                packet->next = cur->packet_id;
     249                               
     250                                cur->previous = packet->packet_id;
     251                                cur = pm_find(packet->previous);
     252                               
     253                                if (cur)
     254                                        cur->next = packet->packet_id;
    237255                                else
    238256                                        *first = packet;
     257                               
    239258                                return EOK;
    240259                        }
    241                 } while (packet_is_valid(item));
     260                } while (packet_is_valid(cur));
    242261        }
     262       
    243263        *first = packet;
    244264        return EOK;
     
    312332
    313333        next = pm_find(packet->next);
    314         if (next) {
     334        if (next)
    315335                next->previous = packet->previous;
    316                 previous = pm_find(next->previous);
    317                 if (previous)
    318                         previous->next = next->packet_id;
    319         }
     336       
     337        previous = pm_find(packet->previous);
     338        if (previous)
     339                previous->next = packet->next ;
     340       
    320341        packet->previous = 0;
    321342        packet->next = 0;
  • uspace/lib/c/include/ipc/dev_iface.h

    rf51b1d3 r609243f4  
    3636typedef enum {
    3737        HW_RES_DEV_IFACE = 0,
     38        /** Character device interface */
    3839        CHAR_DEV_IFACE,
    39 
     40       
     41        /** Network interface controller interface */
     42        NIC_DEV_IFACE,
     43       
    4044        /** Interface provided by any PCI device. */
    4145        PCI_DEV_IFACE,
  • uspace/lib/c/include/ipc/devman.h

    rf51b1d3 r609243f4  
    146146typedef enum {
    147147        DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
     148        DRIVER_DEV_ADDED,
    148149        DRIVER_DEV_REMOVE,
    149150        DRIVER_DEV_GONE,
  • uspace/lib/c/include/ipc/il.h

    rf51b1d3 r609243f4  
    5454        NET_IL_MTU_CHANGED,
    5555       
     56        /**
     57         * Device address changed message
     58         * @see il_addr_changed_msg()
     59         */
     60        NET_IL_ADDR_CHANGED,
     61
    5662        /** Packet received message.
    5763         * @see il_received_msg()
  • uspace/lib/c/include/ipc/net.h

    rf51b1d3 r609243f4  
    277277 *
    278278 */
    279 #define IPC_GET_DEVICE(call)  ((device_id_t) IPC_GET_ARG1(call))
     279#define IPC_GET_DEVICE(call)  ((nic_device_id_t) IPC_GET_ARG1(call))
    280280
    281281/** Return the packet identifier message argument.
     
    298298 *
    299299 */
    300 #define IPC_GET_STATE(call)  ((device_state_t) IPC_GET_ARG2(call))
     300#define IPC_GET_STATE(call)  ((nic_device_state_t) IPC_GET_ARG2(call))
     301
     302/** Return the device handle argument
     303 *
     304 * @param[in] call Message call structure
     305 *
     306 */
     307#define IPC_GET_DEVICE_HANDLE(call) ((devman_handle_t) IPC_GET_ARG2(call))
     308
     309/** Return the device driver service message argument.
     310 *
     311 * @param[in] call Message call structure.
     312 *
     313 */
     314#define IPC_GET_SERVICE(call)  ((services_t) IPC_GET_ARG3(call))
     315
     316/** Return the target service message argument.
     317 *
     318 * @param[in] call Message call structure.
     319 *
     320 */
     321#define IPC_GET_TARGET(call)  ((services_t) IPC_GET_ARG3(call))
     322
     323/** Return the sender service message argument.
     324 *
     325 * @param[in] call Message call structure.
     326 *
     327 */
     328#define IPC_GET_SENDER(call)  ((services_t) IPC_GET_ARG3(call))
    301329
    302330/** Return the maximum transmission unit message argument.
     
    305333 *
    306334 */
    307 #define IPC_GET_MTU(call)  ((size_t) IPC_GET_ARG2(call))
    308 
    309 /** Return the device driver service message argument.
    310  *
    311  * @param[in] call Message call structure.
    312  *
    313  */
    314 #define IPC_GET_SERVICE(call)  ((services_t) IPC_GET_ARG3(call))
    315 
    316 /** Return the target service message argument.
    317  *
    318  * @param[in] call Message call structure.
    319  *
    320  */
    321 #define IPC_GET_TARGET(call)  ((services_t) IPC_GET_ARG3(call))
    322 
    323 /** Return the sender service message argument.
    324  *
    325  * @param[in] call Message call structure.
    326  *
    327  */
    328 #define IPC_GET_SENDER(call)  ((services_t) IPC_GET_ARG3(call))
     335#define IPC_GET_MTU(call)  ((size_t) IPC_GET_ARG3(call))
    329336
    330337/** Return the error service message argument.
  • uspace/lib/c/include/ipc/net_net.h

    rf51b1d3 r609243f4  
    4343/** Networking subsystem central module messages. */
    4444typedef enum {
    45         /** Returns the general configuration
     45        /** Return general configuration
    4646         * @see net_get_conf_req()
    4747         */
    4848        NET_NET_GET_CONF = NET_FIRST,
    49         /** Returns the device specific configuration
     49        /** Return device specific configuration
    5050         * @see net_get_device_conf_req()
    5151         */
    5252        NET_NET_GET_DEVICE_CONF,
    53         /** Starts the networking stack. */
    54         NET_NET_STARTUP,
     53        /** Return number of mastered devices */
     54        NET_NET_GET_DEVICES_COUNT,
     55        /** Return names and device IDs of all devices */
     56        NET_NET_GET_DEVICES,
     57        /** Notify the networking service about a ready device */
     58        NET_NET_DRIVER_READY
    5559} net_messages;
    5660
  • uspace/lib/c/include/ipc/nil.h

    rf51b1d3 r609243f4  
    7070         */
    7171        NET_NIL_BROADCAST_ADDR,
     72        /** Device has changed address
     73         * @see nil_addr_changed_msg()
     74         */
     75        NET_NIL_ADDR_CHANGED
    7276} nil_messages;
    7377
  • uspace/lib/c/include/ipc/services.h

    rf51b1d3 r609243f4  
    4949        SERVICE_CLIPBOARD  = FOURCC('c', 'l', 'i', 'p'),
    5050        SERVICE_NETWORKING = FOURCC('n', 'e', 't', ' '),
    51         SERVICE_LO         = FOURCC('l', 'o', ' ', ' '),
    52         SERVICE_NE2000     = FOURCC('n', 'e', '2', 'k'),
    5351        SERVICE_ETHERNET   = FOURCC('e', 't', 'h', ' '),
    5452        SERVICE_NILDUMMY   = FOURCC('n', 'i', 'l', 'd'),
  • uspace/lib/c/include/net/device.h

    rf51b1d3 r609243f4  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    3940
    4041#include <adt/int_map.h>
     42#include <net/eth_phys.h>
     43
     44/** Ethernet address length. */
     45#define ETH_ADDR  6
     46
     47/** MAC printing format */
     48#define PRIMAC  "%02x:%02x:%02x:%02x:%02x:%02x"
     49
     50/** MAC arguments */
     51#define ARGSMAC(__a) \
     52        (__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5]
    4153
    4254/** Device identifier to generic type map declaration. */
    43 #define DEVICE_MAP_DECLARE      INT_MAP_DECLARE
     55#define DEVICE_MAP_DECLARE  INT_MAP_DECLARE
    4456
    4557/** Device identifier to generic type map implementation. */
    46 #define DEVICE_MAP_IMPLEMENT    INT_MAP_IMPLEMENT
     58#define DEVICE_MAP_IMPLEMENT  INT_MAP_IMPLEMENT
     59
     60/** Max length of any hw nic address (currently only eth) */
     61#define NIC_MAX_ADDRESS_LENGTH  16
    4762
    4863/** Invalid device identifier. */
    49 #define DEVICE_INVALID_ID       (-1)
     64#define NIC_DEVICE_INVALID_ID  (-1)
     65
     66#define NIC_VENDOR_MAX_LENGTH         64
     67#define NIC_MODEL_MAX_LENGTH          64
     68#define NIC_PART_NUMBER_MAX_LENGTH    64
     69#define NIC_SERIAL_NUMBER_MAX_LENGTH  64
     70
     71/**
     72 * The bitmap uses single bit for each of the 2^12 = 4096 possible VLAN tags.
     73 * This means its size is 4096/8 = 512 bytes.
     74 */
     75#define NIC_VLAN_BITMAP_SIZE  512
     76
     77#define NIC_DEVICE_PRINT_FMT  "%x"
    5078
    5179/** Device identifier type. */
    52 typedef int device_id_t;
    53 
    54 /** Device state type. */
    55 typedef enum device_state device_state_t;
    56 
    57 /** Type definition of the device usage statistics.
    58  * @see device_stats
    59  */
    60 typedef struct device_stats device_stats_t;
     80typedef int nic_device_id_t;
     81
     82/**
     83 * Structure covering the MAC address.
     84 */
     85typedef struct nic_address {
     86        uint8_t address[ETH_ADDR];
     87} nic_address_t;
    6188
    6289/** Device state. */
    63 enum device_state {
    64         /** Device not present or not initialized. */
    65         NETIF_NULL = 0,
    66         /** Device present and stopped. */
    67         NETIF_STOPPED,
    68         /** Device present and active. */
    69         NETIF_ACTIVE,
    70         /** Device present but unable to transmit. */
    71         NETIF_CARRIER_LOST
    72 };
     90typedef enum nic_device_state {
     91        /**
     92         * Device present and stopped. Moving device to this state means to discard
     93         * all settings and WOL virtues, rebooting the NIC to state as if the
     94         * computer just booted (or the NIC was just inserted in case of removable
     95         * NIC).
     96         */
     97        NIC_STATE_STOPPED,
     98        /**
     99         * If the NIC is in this state no packets (frames) are transmitted nor
     100         * received. However, the settings are not restarted. You can use this state
     101         * to temporarily disable transmition/reception or atomically (with respect
     102         * to incoming/outcoming packets) change frames acceptance etc.
     103         */
     104        NIC_STATE_DOWN,
     105        /** Device is normally operating. */
     106        NIC_STATE_ACTIVE,
     107        /** Just a constant to limit the state numbers */
     108        NIC_STATE_MAX,
     109} nic_device_state_t;
     110
     111/**
     112 * Channel operating mode used on the medium.
     113 */
     114typedef enum {
     115        NIC_CM_UNKNOWN,
     116        NIC_CM_FULL_DUPLEX,
     117        NIC_CM_HALF_DUPLEX,
     118        NIC_CM_SIMPLEX
     119} nic_channel_mode_t;
     120
     121/**
     122 * Role for the device (used e.g. for 1000Gb ethernet)
     123 */
     124typedef enum {
     125        NIC_ROLE_UNKNOWN,
     126        NIC_ROLE_AUTO,
     127        NIC_ROLE_MASTER,
     128        NIC_ROLE_SLAVE
     129} nic_role_t;
     130
     131/**
     132 * Current state of the cable in the device
     133 */
     134typedef enum {
     135        NIC_CS_UNKNOWN,
     136        NIC_CS_PLUGGED,
     137        NIC_CS_UNPLUGGED
     138} nic_cable_state_t;
     139
     140/**
     141 * Result of the requested operation
     142 */
     143typedef enum {
     144        /** Successfully disabled */
     145        NIC_RESULT_DISABLED,
     146        /** Successfully enabled */
     147        NIC_RESULT_ENABLED,
     148        /** Not supported at all */
     149        NIC_RESULT_NOT_SUPPORTED,
     150        /** Temporarily not available */
     151        NIC_RESULT_NOT_AVAILABLE,
     152        /** Result extensions */
     153        NIC_RESULT_FIRST_EXTENSION
     154} nic_result_t;
    73155
    74156/** Device usage statistics. */
    75 struct device_stats {
    76         /** Total packets received. */
     157typedef struct nic_device_stats {
     158        /** Total packets received (accepted). */
    77159        unsigned long receive_packets;
    78160        /** Total packets transmitted. */
    79161        unsigned long send_packets;
    80         /** Total bytes received. */
     162        /** Total bytes received (accepted). */
    81163        unsigned long receive_bytes;
    82164        /** Total bytes transmitted. */
     
    86168        /** Packet transmition problems counter. */
    87169        unsigned long send_errors;
    88         /** No space in buffers counter. */
     170        /** Number of frames dropped due to insufficient space in RX buffers */
    89171        unsigned long receive_dropped;
    90         /** No space available counter. */
     172        /** Number of frames dropped due to insufficient space in TX buffers */
    91173        unsigned long send_dropped;
    92         /** Total multicast packets received. */
    93         unsigned long multicast;
     174        /** Total multicast packets received (accepted). */
     175        unsigned long receive_multicast;
     176        /** Total broadcast packets received (accepted). */
     177        unsigned long receive_broadcast;
    94178        /** The number of collisions due to congestion on the medium. */
    95179        unsigned long collisions;
     180        /** Unicast packets received but not accepted (filtered) */
     181        unsigned long receive_filtered_unicast;
     182        /** Multicast packets received but not accepted (filtered) */
     183        unsigned long receive_filtered_multicast;
     184        /** Broadcast packets received but not accepted (filtered) */
     185        unsigned long receive_filtered_broadcast;
    96186
    97187        /* detailed receive_errors */
     
    129219        /** Total compressed packet transmitted. */
    130220        unsigned long send_compressed;
    131 };
     221} nic_device_stats_t;
     222
     223/**
     224 * Information about the NIC that never changes - name, vendor, model,
     225 * capabilites and so on.
     226 */
     227typedef struct nic_device_info {
     228        /* Device identification */
     229        char vendor_name[NIC_VENDOR_MAX_LENGTH];
     230        char model_name[NIC_MODEL_MAX_LENGTH];
     231        char part_number[NIC_PART_NUMBER_MAX_LENGTH];
     232        char serial_number[NIC_SERIAL_NUMBER_MAX_LENGTH];
     233        uint16_t vendor_id;
     234        uint16_t device_id;
     235        uint16_t subsystem_vendor_id;
     236        uint16_t subsystem_id;
     237        /* Device capabilities */
     238        uint16_t ethernet_support[ETH_PHYS_LAYERS];
     239
     240        /** The mask of all modes which the device can advertise
     241         *
     242         *  see ETH_AUTONEG_ macros in net/eth_phys.h of libc
     243         */
     244        uint32_t autoneg_support;
     245} nic_device_info_t;
     246
     247/**
     248 * Specifies which unicast frames is the NIC receiving.
     249 */
     250typedef enum nic_unicast_mode {
     251        NIC_UNICAST_UNKNOWN,
     252        /** No unicast frames are received */
     253        NIC_UNICAST_BLOCKED,
     254        /** Only the frames with this NIC's MAC as destination are received */
     255        NIC_UNICAST_DEFAULT,
     256        /**
     257         * Both frames with this NIC's MAC and those specified in the list are
     258         * received
     259         */
     260        NIC_UNICAST_LIST,
     261        /** All unicast frames are received */
     262        NIC_UNICAST_PROMISC
     263} nic_unicast_mode_t;
     264
     265typedef enum nic_multicast_mode {
     266        NIC_MULTICAST_UNKNOWN,
     267        /** No multicast frames are received */
     268        NIC_MULTICAST_BLOCKED,
     269        /** Frames with multicast addresses specified in this list are received */
     270        NIC_MULTICAST_LIST,
     271        /** All multicast frames are received */
     272        NIC_MULTICAST_PROMISC
     273} nic_multicast_mode_t;
     274
     275typedef enum nic_broadcast_mode {
     276        NIC_BROADCAST_UNKNOWN,
     277        /** Broadcast frames are dropped */
     278        NIC_BROADCAST_BLOCKED,
     279        /** Broadcast frames are received */
     280        NIC_BROADCAST_ACCEPTED
     281} nic_broadcast_mode_t;
     282
     283/**
     284 * Structure covering the bitmap with VLAN tags.
     285 */
     286typedef struct nic_vlan_mask {
     287        uint8_t bitmap[NIC_VLAN_BITMAP_SIZE];
     288} nic_vlan_mask_t;
     289
     290/* WOL virtue identifier */
     291typedef unsigned int nic_wv_id_t;
     292
     293/**
     294 * WOL virtue types defining the interpretation of data passed to the virtue.
     295 * Those tagged with S can have only single virtue active at one moment, those
     296 * tagged with M can have multiple ones.
     297 */
     298typedef enum nic_wv_type {
     299        /**
     300         * Used for deletion of the virtue - in this case the mask, data and length
     301         * arguments are ignored.
     302         */
     303        NIC_WV_NONE,
     304        /** S
     305         * Enabled <=> wakeup upon link change
     306         */
     307        NIC_WV_LINK_CHANGE,
     308        /** S
     309         * If this virtue is set up, wakeup can be issued by a magic packet frame.
     310         * If the data argument is not NULL, it must contain
     311         * nic_wv_magic_packet_data structure with the SecureOn password.
     312         */
     313        NIC_WV_MAGIC_PACKET,
     314        /** M
     315         * If the virtue is set up, wakeup can be issued by a frame targeted to
     316         * device with MAC address specified in data. The data must contain
     317         * nic_address_t structure.
     318         */
     319        NIC_WV_DESTINATION,
     320        /** S
     321         * Enabled <=> wakeup upon receiving broadcast frame
     322         */
     323        NIC_WV_BROADCAST,
     324        /** S
     325         * Enabled <=> wakeup upon receiving ARP Request
     326         */
     327        NIC_WV_ARP_REQUEST,
     328        /** M
     329         * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet
     330         * with IPv4 address specified in data. The data must contain
     331         * nic_wv_ipv4_data structure.
     332         */
     333        NIC_WV_DIRECTED_IPV4,
     334        /** M
     335         * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet
     336         * with IPv6 address specified in data. The data must contain
     337         * nic_wv_ipv6_data structure.
     338         */
     339        NIC_WV_DIRECTED_IPV6,
     340        /** M
     341         * First length/2 bytes in the argument are interpreted as mask, second
     342         * length/2 bytes are interpreted as content.
     343         * If enabled, the wakeup is issued upon receiving frame where the bytes
     344         * with non-zero value in the mask equal to those in the content.
     345         */
     346        NIC_WV_FULL_MATCH,
     347        /**
     348         * Dummy value, do not use.
     349         */
     350        NIC_WV_MAX
     351} nic_wv_type_t;
     352
     353/**
     354 * Specifies the interrupt/polling mode used by the driver and NIC
     355 */
     356typedef enum nic_poll_mode {
     357        /**
     358         * NIC issues interrupts upon events.
     359         */
     360        NIC_POLL_IMMEDIATE,
     361        /**
     362         * Some uspace app calls nic_poll_now(...) in order to check the NIC state
     363         * - no interrupts are received from the NIC.
     364         */
     365        NIC_POLL_ON_DEMAND,
     366        /**
     367         * The driver itself issues a poll request in a periodic manner. It is
     368         * allowed to use hardware timer if the NIC supports it.
     369         */
     370        NIC_POLL_PERIODIC,
     371        /**
     372         * The driver itself issued a poll request in a periodic manner. The driver
     373         * must create software timer, internal hardware timer of NIC must not be
     374         * used even if the NIC supports it.
     375         */
     376        NIC_POLL_SOFTWARE_PERIODIC
     377} nic_poll_mode_t;
     378
     379static inline const char *nic_device_state_to_string(nic_device_state_t state)
     380{
     381        switch (state) {
     382        case NIC_STATE_STOPPED:
     383                return "stopped";
     384        case NIC_STATE_DOWN:
     385                return "down";
     386        case NIC_STATE_ACTIVE:
     387                return "active";
     388        default:
     389                return "undefined";
     390        }
     391}
    132392
    133393#endif
  • uspace/lib/c/include/net/packet.h

    rf51b1d3 r609243f4  
    4141 * Value zero is used as an invalid identifier.
    4242 */
    43 typedef int packet_id_t;
     43typedef unsigned long packet_id_t;
    4444
    4545/** Type definition of the packet.
     
    7171extern packet_t *pm_find(packet_id_t);
    7272extern int pm_add(packet_t *);
     73extern void pm_remove(packet_t *);
    7374extern int pm_init(void);
    7475extern void pm_destroy(void);
  • uspace/lib/c/include/net/packet_header.h

    rf51b1d3 r609243f4  
    6161#define PACKET_MAGIC_VALUE      0x11227788
    6262
     63/** Maximum total length of the packet */
     64#define PACKET_MAX_LENGTH  65536
     65
    6366/** Packet header. */
    6467struct packet {
     
    8588         */
    8689        size_t length;
     90
     91        /** Offload info provided by the NIC */
     92        uint32_t offload_info;
     93
     94        /** Mask which bits in offload info are valid */
     95        uint32_t offload_mask;
    8796
    8897        /** Stored source and destination addresses length. */
Note: See TracChangeset for help on using the changeset viewer.