Changeset 948911d in mainline for uspace/lib/c


Ignore:
Timestamp:
2012-01-24T02:27:43Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
230385c
Parents:
8afeb04 (diff), 2df6f6fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Mainline changes.

Location:
uspace/lib/c
Files:
1 added
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    r8afeb04 r948911d  
    257257void async_set_client_data_constructor(async_client_data_ctor_t ctor)
    258258{
     259        assert(async_client_data_create == default_client_data_constructor);
    259260        async_client_data_create = ctor;
    260261}
     
    262263void async_set_client_data_destructor(async_client_data_dtor_t dtor)
    263264{
     265        assert(async_client_data_destroy == default_client_data_destructor);
    264266        async_client_data_destroy = dtor;
    265267}
     
    303305void async_set_client_connection(async_client_conn_t conn)
    304306{
     307        assert(client_connection == default_client_connection);
    305308        client_connection = conn;
    306309}
  • uspace/lib/c/generic/device/nic.c

    r8afeb04 r948911d  
    4444#include <ipc/services.h>
    4545
    46 /** Send a packet through the device
    47  *
    48  * @param[in] dev_sess
    49  * @param[in] packet_id Id of the sent packet
    50  *
    51  * @return EOK If the operation was successfully completed
    52  *
    53  */
    54 int nic_send_message(async_sess_t *dev_sess, packet_id_t packet_id)
    55 {
    56         async_exch_t *exch = async_exchange_begin(dev_sess);
    57         int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    58             NIC_SEND_MESSAGE, packet_id);
    59         async_exchange_end(exch);
    60        
    61         return rc;
    62 }
    63 
    64 /** Connect the driver to the NET and NIL services
    65  *
    66  * @param[in] dev_sess
    67  * @param[in] nil_service Service identifier for the NIL service
     46/** Send frame from NIC
     47 *
     48 * @param[in] dev_sess
     49 * @param[in] data     Frame data
     50 * @param[in] size     Frame size in bytes
     51 *
     52 * @return EOK If the operation was successfully completed
     53 *
     54 */
     55int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size)
     56{
     57        async_exch_t *exch = async_exchange_begin(dev_sess);
     58       
     59        ipc_call_t answer;
     60        aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     61            NIC_SEND_MESSAGE, &answer);
     62        sysarg_t retval = async_data_write_start(exch, data, size);
     63       
     64        async_exchange_end(exch);
     65       
     66        if (retval != EOK) {
     67                async_wait_for(req, NULL);
     68                return retval;
     69        }
     70
     71        async_wait_for(req, &retval);
     72        return retval;
     73}
     74
     75/** Create callback connection from NIC service
     76 *
     77 * @param[in] dev_sess
    6878 * @param[in] device_id
    6979 *
     
    7181 *
    7282 */
    73 int nic_connect_to_nil(async_sess_t *dev_sess, services_t nil_service,
    74     nic_device_id_t device_id)
    75 {
    76         async_exch_t *exch = async_exchange_begin(dev_sess);
    77         int rc = async_req_3_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    78             NIC_CONNECT_TO_NIL, nil_service, device_id);
    79         async_exchange_end(exch);
    80        
    81         return rc;
     83int nic_callback_create(async_sess_t *dev_sess, nic_device_id_t device_id,
     84    async_client_conn_t cfun, void *carg)
     85{
     86        ipc_call_t answer;
     87        int rc;
     88        sysarg_t retval;
     89       
     90        async_exch_t *exch = async_exchange_begin(dev_sess);
     91        aid_t req = async_send_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     92            NIC_CALLBACK_CREATE, device_id, &answer);
     93       
     94        rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg);
     95        if (rc != EOK) {
     96                async_wait_for(req, NULL);
     97                return rc;
     98        }
     99        async_exchange_end(exch);
     100       
     101        async_wait_for(req, &retval);
     102        return (int) retval;
    82103}
    83104
     
    324345 * it can never force the NIC to advertise unsupported modes.
    325346 *
    326  * The allowed modes are defined in "net/eth_phys.h" in the C library.
     347 * The allowed modes are defined in "nic/eth_phys.h" in the C library.
    327348 *
    328349 * @param[in] dev_sess
     
    361382/** Probe current state of auto-negotiation.
    362383 *
    363  * Modes are defined in the "net/eth_phys.h" in the C library.
     384 * Modes are defined in the "nic/eth_phys.h" in the C library.
    364385 *
    365386 * @param[in]  dev_sess
  • uspace/lib/c/generic/devman.c

    r8afeb04 r948911d  
    177177
    178178/** Register running driver with device manager. */
    179 int devman_driver_register(const char *name, async_client_conn_t conn)
     179int devman_driver_register(const char *name)
    180180{
    181181        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     
    192192        }
    193193       
    194         async_set_client_connection(conn);
    195        
    196194        exch = devman_exchange_begin(DEVMAN_DRIVER);
    197         async_connect_to_me(exch, 0, 0, 0, conn, NULL);
     195        async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
    198196        devman_exchange_end(exch);
    199197       
  • uspace/lib/c/generic/loc.c

    r8afeb04 r948911d  
    4747static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
    4848static bool loc_callback_created = false;
     49static loc_cat_change_cb_t cat_change_cb = NULL;
    4950
    5051static async_sess_t *loc_supp_block_sess = NULL;
     
    5455static async_sess_t *loc_consumer_sess = NULL;
    5556
    56 static loc_cat_change_cb_t cat_change_cb = NULL;
    57 
    5857static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    5958{
    60         loc_cat_change_cb_t cb_fun;
    61        
    6259        while (true) {
    6360                ipc_call_t call;
     
    6966                }
    7067               
    71                 int retval;
    72                
    7368                switch (IPC_GET_IMETHOD(call)) {
    7469                case LOC_EVENT_CAT_CHANGE:
    7570                        fibril_mutex_lock(&loc_callback_mutex);
    76                         cb_fun = cat_change_cb;
    77                         if (cb_fun != NULL) {
     71                        loc_cat_change_cb_t cb_fun = cat_change_cb;
     72                        fibril_mutex_unlock(&loc_callback_mutex);
     73                       
     74                        async_answer_0(callid, EOK);
     75                       
     76                        if (cb_fun != NULL)
    7877                                (*cb_fun)();
    79                         }
    80                         fibril_mutex_unlock(&loc_callback_mutex);
    81                         retval = 0;
     78                       
    8279                        break;
    8380                default:
    84                         retval = ENOTSUP;
     81                        async_answer_0(callid, ENOTSUP);
    8582                }
    86                
    87                 async_answer_0(callid, retval);
    8883        }
    8984}
     
    10196}
    10297
     98/** Create callback
     99 *
     100 * Must be called with loc_callback_mutex locked.
     101 *
     102 * @return EOK on success.
     103 *
     104 */
    103105static int loc_callback_create(void)
    104106{
    105         async_exch_t *exch;
    106         sysarg_t retval;
    107         int rc = EOK;
    108 
    109         fibril_mutex_lock(&loc_callback_mutex);
    110        
    111107        if (!loc_callback_created) {
    112                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     108                async_exch_t *exch =
     109                    loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
    113110               
    114111                ipc_call_t answer;
    115112                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
    116                 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     113                int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
    117114                loc_exchange_end(exch);
    118115               
     116                if (rc != EOK)
     117                        return rc;
     118               
     119                sysarg_t retval;
    119120                async_wait_for(req, &retval);
    120                 if (rc != EOK)
    121                         goto done;
    122                
    123                 if (retval != EOK) {
    124                         rc = retval;
    125                         goto done;
    126                 }
     121                if (retval != EOK)
     122                        return retval;
    127123               
    128124                loc_callback_created = true;
    129125        }
    130126       
    131         rc = EOK;
    132 done:
    133         fibril_mutex_unlock(&loc_callback_mutex);
    134         return rc;
     127        return EOK;
    135128}
    136129
     
    242235
    243236/** Register new driver with loc. */
    244 int loc_server_register(const char *name, async_client_conn_t conn)
     237int loc_server_register(const char *name)
    245238{
    246239        async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     
    256249                return retval;
    257250        }
    258        
    259         async_set_client_connection(conn);
    260251       
    261252        exch = loc_exchange_begin(LOC_PORT_SUPPLIER);
     
    797788    sysarg_t **data, size_t *count)
    798789{
    799         service_id_t *ids;
    800         size_t act_size;
    801         size_t alloc_size;
    802         int rc;
    803 
    804790        *data = NULL;
    805         act_size = 0;   /* silence warning */
    806 
    807         rc = loc_category_get_ids_once(method, arg1, NULL, 0,
     791        *count = 0;
     792       
     793        size_t act_size = 0;
     794        int rc = loc_category_get_ids_once(method, arg1, NULL, 0,
    808795            &act_size);
    809796        if (rc != EOK)
    810797                return rc;
    811 
    812         alloc_size = act_size;
    813         ids = malloc(alloc_size);
     798       
     799        size_t alloc_size = act_size;
     800        service_id_t *ids = malloc(alloc_size);
    814801        if (ids == NULL)
    815802                return ENOMEM;
    816 
     803       
    817804        while (true) {
    818805                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    820807                if (rc != EOK)
    821808                        return rc;
    822 
     809               
    823810                if (act_size <= alloc_size)
    824811                        break;
    825 
    826                 alloc_size *= 2;
    827                 free(ids);
    828 
    829                 ids = malloc(alloc_size);
     812               
     813                alloc_size = act_size;
     814                ids = realloc(ids, alloc_size);
    830815                if (ids == NULL)
    831816                        return ENOMEM;
    832817        }
    833 
     818       
    834819        *count = act_size / sizeof(category_id_t);
    835820        *data = ids;
     
    869854int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    870855{
    871         if (loc_callback_create() != EOK)
     856        fibril_mutex_lock(&loc_callback_mutex);
     857        if (loc_callback_create() != EOK) {
     858                fibril_mutex_unlock(&loc_callback_mutex);
    872859                return EIO;
    873 
     860        }
     861       
    874862        cat_change_cb = cb_fun;
     863        fibril_mutex_unlock(&loc_callback_mutex);
     864       
    875865        return EOK;
    876866}
  • uspace/lib/c/include/device/nic.h

    r8afeb04 r948911d  
    3737
    3838#include <async.h>
    39 #include <net/device.h>
    40 #include <net/packet.h>
    41 #include <ipc/services.h>
     39#include <nic/nic.h>
     40#include <ipc/common.h>
    4241
    4342typedef enum {
    4443        NIC_SEND_MESSAGE = 0,
    45         NIC_CONNECT_TO_NIL,
     44        NIC_CALLBACK_CREATE,
    4645        NIC_GET_STATE,
    4746        NIC_SET_STATE,
     
    8584} nic_funcs_t;
    8685
    87 extern int nic_send_message(async_sess_t *, packet_id_t);
    88 extern int nic_connect_to_nil(async_sess_t *, services_t, nic_device_id_t);
     86typedef enum {
     87        NIC_EV_ADDR_CHANGED = IPC_FIRST_USER_METHOD,
     88        NIC_EV_RECEIVED,
     89        NIC_EV_DEVICE_STATE
     90} nic_event_t;
     91
     92extern int nic_send_frame(async_sess_t *, void *, size_t);
     93extern int nic_callback_create(async_sess_t *, nic_device_id_t,
     94    async_client_conn_t, void *);
    8995extern int nic_get_state(async_sess_t *, nic_device_state_t *);
    9096extern int nic_set_state(async_sess_t *, nic_device_state_t);
  • uspace/lib/c/include/devman.h

    r8afeb04 r948911d  
    4646extern void devman_exchange_end(async_exch_t *);
    4747
    48 extern int devman_driver_register(const char *, async_client_conn_t);
     48extern int devman_driver_register(const char *);
    4949extern int devman_add_function(const char *, fun_type_t, match_id_list_t *,
    5050    devman_handle_t, devman_handle_t *);
  • uspace/lib/c/include/ipc/devman.h

    r8afeb04 r948911d  
    146146typedef enum {
    147147        DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
    148         DRIVER_DEV_ADDED,
    149148        DRIVER_DEV_REMOVE,
    150149        DRIVER_DEV_GONE,
  • uspace/lib/c/include/ipc/net.h

    r8afeb04 r948911d  
    305305 *
    306306 */
    307 #define IPC_GET_DEVICE_HANDLE(call)  ((devman_handle_t) IPC_GET_ARG2(call))
     307#define IPC_GET_DEVICE_HANDLE(call)  ((service_id_t) IPC_GET_ARG2(call))
    308308
    309309/** Return the device driver service message argument.
  • uspace/lib/c/include/ipc/net_net.h

    r8afeb04 r948911d  
    5454        NET_NET_GET_DEVICES_COUNT,
    5555        /** 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
     56        NET_NET_GET_DEVICES
    5957} net_messages;
    6058
  • uspace/lib/c/include/ipc/nil.h

    r8afeb04 r948911d  
    4646         */
    4747        NET_NIL_DEVICE = NET_NIL_FIRST,
    48         /** New device state message.
    49          * @see nil_device_state_msg()
    50          */
    51         NET_NIL_DEVICE_STATE,
    52         /** Received packet queue message.
    53          * @see nil_received_msg()
    54          */
    55         NET_NIL_RECEIVED,
    5648        /** Send packet queue message.
    5749         * @see nil_send_msg()
     
    6961         * @see nil_get_broadcast_addr()
    7062         */
    71         NET_NIL_BROADCAST_ADDR,
    72         /** Device has changed address
    73          * @see nil_addr_changed_msg()
    74          */
    75         NET_NIL_ADDR_CHANGED
     63        NET_NIL_BROADCAST_ADDR
    7664} nil_messages;
    7765
  • uspace/lib/c/include/loc.h

    r8afeb04 r948911d  
    4646extern void loc_exchange_end(async_exch_t *);
    4747
    48 extern int loc_server_register(const char *, async_client_conn_t);
     48extern int loc_server_register(const char *);
    4949extern int loc_service_register(const char *, service_id_t *);
    5050extern int loc_service_register_with_iface(const char *, service_id_t *,
  • uspace/lib/c/include/net/device.h

    r8afeb04 r948911d  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
    3  * Copyright (c) 2011 Radim Vansa
    43 * All rights reserved.
    54 *
     
    3332
    3433/** @file
    35  * Device identifier, state and usage statistics.
     34 * Network device.
    3635 */
    3736
    38 #ifndef LIBC_DEVICE_ID_TYPE_H_
    39 #define LIBC_DEVICE_ID_TYPE_H_
     37#ifndef LIBC_NET_DEVICE_H_
     38#define LIBC_NET_DEVICE_H_
    4039
    4140#include <adt/int_map.h>
    42 #include <net/eth_phys.h>
    43 #include <bool.h>
    44 
    45 /** Ethernet address length. */
    46 #define ETH_ADDR  6
    47 
    48 /** MAC printing format */
    49 #define PRIMAC  "%02x:%02x:%02x:%02x:%02x:%02x"
    50 
    51 /** MAC arguments */
    52 #define ARGSMAC(__a) \
    53         (__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5]
    54 
    55 /* Compare MAC address with specific value */
    56 #define MAC_EQUALS_VALUE(__a, __a0, __a1, __a2, __a3, __a4, __a5) \
    57         ((__a)[0] == (__a0) && (__a)[1] == (__a1) && (__a)[2] == (__a2) \
    58         && (__a)[3] == (__a3) && (__a)[4] == (__a4) && (__a)[5] == (__a5))
    59 
    60 #define MAC_IS_ZERO(__x) \
    61         MAC_EQUALS_VALUE(__x, 0, 0, 0, 0, 0, 0)
     41#include <nic/nic.h>
    6242
    6343/** Device identifier to generic type map declaration. */
     
    6747#define DEVICE_MAP_IMPLEMENT  INT_MAP_IMPLEMENT
    6848
    69 /** Max length of any hw nic address (currently only eth) */
    70 #define NIC_MAX_ADDRESS_LENGTH  16
    71 
    72 /** Invalid device identifier. */
    73 #define NIC_DEVICE_INVALID_ID  (-1)
    74 
    75 #define NIC_VENDOR_MAX_LENGTH         64
    76 #define NIC_MODEL_MAX_LENGTH          64
    77 #define NIC_PART_NUMBER_MAX_LENGTH    64
    78 #define NIC_SERIAL_NUMBER_MAX_LENGTH  64
    79 
    80 #define NIC_DEFECTIVE_LONG               0x0001
    81 #define NIC_DEFECTIVE_SHORT              0x0002
    82 #define NIC_DEFECTIVE_BAD_CRC            0x0010
    83 #define NIC_DEFECTIVE_BAD_IPV4_CHECKSUM  0x0020
    84 #define NIC_DEFECTIVE_BAD_IPV6_CHECKSUM  0x0040
    85 #define NIC_DEFECTIVE_BAD_TCP_CHECKSUM   0x0080
    86 #define NIC_DEFECTIVE_BAD_UDP_CHECKSUM   0x0100
    87 
    88 /**
    89  * The bitmap uses single bit for each of the 2^12 = 4096 possible VLAN tags.
    90  * This means its size is 4096/8 = 512 bytes.
    91  */
    92 #define NIC_VLAN_BITMAP_SIZE  512
    93 
    94 #define NIC_DEVICE_PRINT_FMT  "%x"
    95 
    96 /** Device identifier type. */
    97 typedef int nic_device_id_t;
    98 
    99 /**
    100  * Structure covering the MAC address.
    101  */
    102 typedef struct nic_address {
    103         uint8_t address[ETH_ADDR];
    104 } nic_address_t;
    105 
    106 /** Device state. */
    107 typedef enum nic_device_state {
    108         /**
    109          * Device present and stopped. Moving device to this state means to discard
    110          * all settings and WOL virtues, rebooting the NIC to state as if the
    111          * computer just booted (or the NIC was just inserted in case of removable
    112          * NIC).
    113          */
    114         NIC_STATE_STOPPED,
    115         /**
    116          * If the NIC is in this state no packets (frames) are transmitted nor
    117          * received. However, the settings are not restarted. You can use this state
    118          * to temporarily disable transmition/reception or atomically (with respect
    119          * to incoming/outcoming packets) change frames acceptance etc.
    120          */
    121         NIC_STATE_DOWN,
    122         /** Device is normally operating. */
    123         NIC_STATE_ACTIVE,
    124         /** Just a constant to limit the state numbers */
    125         NIC_STATE_MAX,
    126 } nic_device_state_t;
    127 
    128 /**
    129  * Channel operating mode used on the medium.
    130  */
    131 typedef enum {
    132         NIC_CM_UNKNOWN,
    133         NIC_CM_FULL_DUPLEX,
    134         NIC_CM_HALF_DUPLEX,
    135         NIC_CM_SIMPLEX
    136 } nic_channel_mode_t;
    137 
    138 /**
    139  * Role for the device (used e.g. for 1000Gb ethernet)
    140  */
    141 typedef enum {
    142         NIC_ROLE_UNKNOWN,
    143         NIC_ROLE_AUTO,
    144         NIC_ROLE_MASTER,
    145         NIC_ROLE_SLAVE
    146 } nic_role_t;
    147 
    148 /**
    149  * Current state of the cable in the device
    150  */
    151 typedef enum {
    152         NIC_CS_UNKNOWN,
    153         NIC_CS_PLUGGED,
    154         NIC_CS_UNPLUGGED
    155 } nic_cable_state_t;
    156 
    157 /**
    158  * Result of the requested operation
    159  */
    160 typedef enum {
    161         /** Successfully disabled */
    162         NIC_RESULT_DISABLED,
    163         /** Successfully enabled */
    164         NIC_RESULT_ENABLED,
    165         /** Not supported at all */
    166         NIC_RESULT_NOT_SUPPORTED,
    167         /** Temporarily not available */
    168         NIC_RESULT_NOT_AVAILABLE,
    169         /** Result extensions */
    170         NIC_RESULT_FIRST_EXTENSION
    171 } nic_result_t;
    172 
    173 /** Device usage statistics. */
    174 typedef struct nic_device_stats {
    175         /** Total packets received (accepted). */
    176         unsigned long receive_packets;
    177         /** Total packets transmitted. */
    178         unsigned long send_packets;
    179         /** Total bytes received (accepted). */
    180         unsigned long receive_bytes;
    181         /** Total bytes transmitted. */
    182         unsigned long send_bytes;
    183         /** Bad packets received counter. */
    184         unsigned long receive_errors;
    185         /** Packet transmition problems counter. */
    186         unsigned long send_errors;
    187         /** Number of frames dropped due to insufficient space in RX buffers */
    188         unsigned long receive_dropped;
    189         /** Number of frames dropped due to insufficient space in TX buffers */
    190         unsigned long send_dropped;
    191         /** Total multicast packets received (accepted). */
    192         unsigned long receive_multicast;
    193         /** Total broadcast packets received (accepted). */
    194         unsigned long receive_broadcast;
    195         /** The number of collisions due to congestion on the medium. */
    196         unsigned long collisions;
    197         /** Unicast packets received but not accepted (filtered) */
    198         unsigned long receive_filtered_unicast;
    199         /** Multicast packets received but not accepted (filtered) */
    200         unsigned long receive_filtered_multicast;
    201         /** Broadcast packets received but not accepted (filtered) */
    202         unsigned long receive_filtered_broadcast;
    203 
    204         /* detailed receive_errors */
    205 
    206         /** Received packet length error counter. */
    207         unsigned long receive_length_errors;
    208         /** Receiver buffer overflow counter. */
    209         unsigned long receive_over_errors;
    210         /** Received packet with crc error counter. */
    211         unsigned long receive_crc_errors;
    212         /** Received frame alignment error counter. */
    213         unsigned long receive_frame_errors;
    214         /** Receiver fifo overrun counter. */
    215         unsigned long receive_fifo_errors;
    216         /** Receiver missed packet counter. */
    217         unsigned long receive_missed_errors;
    218 
    219         /* detailed send_errors */
    220 
    221         /** Transmitter aborted counter. */
    222         unsigned long send_aborted_errors;
    223         /** Transmitter carrier errors counter. */
    224         unsigned long send_carrier_errors;
    225         /** Transmitter fifo overrun counter. */
    226         unsigned long send_fifo_errors;
    227         /** Transmitter carrier errors counter. */
    228         unsigned long send_heartbeat_errors;
    229         /** Transmitter window errors counter. */
    230         unsigned long send_window_errors;
    231 
    232         /* for cslip etc */
    233        
    234         /** Total compressed packets received. */
    235         unsigned long receive_compressed;
    236         /** Total compressed packet transmitted. */
    237         unsigned long send_compressed;
    238 } nic_device_stats_t;
    239 
    240 /** Errors corresponding to those in the nic_device_stats_t */
    241 typedef enum {
    242         NIC_SEC_BUFFER_FULL,
    243         NIC_SEC_ABORTED,
    244         NIC_SEC_CARRIER_LOST,
    245         NIC_SEC_FIFO_OVERRUN,
    246         NIC_SEC_HEARTBEAT,
    247         NIC_SEC_WINDOW_ERROR,
    248         /* Error encountered during TX but with other type of error */
    249         NIC_SEC_OTHER
    250 } nic_send_error_cause_t;
    251 
    252 /** Errors corresponding to those in the nic_device_stats_t */
    253 typedef enum {
    254         NIC_REC_BUFFER_FULL,
    255         NIC_REC_LENGTH,
    256         NIC_REC_BUFFER_OVERFLOW,
    257         NIC_REC_CRC,
    258         NIC_REC_FRAME_ALIGNMENT,
    259         NIC_REC_FIFO_OVERRUN,
    260         NIC_REC_MISSED,
    261         /* Error encountered during RX but with other type of error */
    262         NIC_REC_OTHER
    263 } nic_receive_error_cause_t;
    264 
    265 /**
    266  * Information about the NIC that never changes - name, vendor, model,
    267  * capabilites and so on.
    268  */
    269 typedef struct nic_device_info {
    270         /* Device identification */
    271         char vendor_name[NIC_VENDOR_MAX_LENGTH];
    272         char model_name[NIC_MODEL_MAX_LENGTH];
    273         char part_number[NIC_PART_NUMBER_MAX_LENGTH];
    274         char serial_number[NIC_SERIAL_NUMBER_MAX_LENGTH];
    275         uint16_t vendor_id;
    276         uint16_t device_id;
    277         uint16_t subsystem_vendor_id;
    278         uint16_t subsystem_id;
    279         /* Device capabilities */
    280         uint16_t ethernet_support[ETH_PHYS_LAYERS];
    281 
    282         /** The mask of all modes which the device can advertise
    283          *
    284          *  see ETH_AUTONEG_ macros in net/eth_phys.h of libc
    285          */
    286         uint32_t autoneg_support;
    287 } nic_device_info_t;
    288 
    289 /**
    290  * Type of the ethernet frame
    291  */
    292 typedef enum nic_frame_type {
    293         NIC_FRAME_UNICAST,
    294         NIC_FRAME_MULTICAST,
    295         NIC_FRAME_BROADCAST
    296 } nic_frame_type_t;
    297 
    298 /**
    299  * Specifies which unicast frames is the NIC receiving.
    300  */
    301 typedef enum nic_unicast_mode {
    302         NIC_UNICAST_UNKNOWN,
    303         /** No unicast frames are received */
    304         NIC_UNICAST_BLOCKED,
    305         /** Only the frames with this NIC's MAC as destination are received */
    306         NIC_UNICAST_DEFAULT,
    307         /**
    308          * Both frames with this NIC's MAC and those specified in the list are
    309          * received
    310          */
    311         NIC_UNICAST_LIST,
    312         /** All unicast frames are received */
    313         NIC_UNICAST_PROMISC
    314 } nic_unicast_mode_t;
    315 
    316 typedef enum nic_multicast_mode {
    317         NIC_MULTICAST_UNKNOWN,
    318         /** No multicast frames are received */
    319         NIC_MULTICAST_BLOCKED,
    320         /** Frames with multicast addresses specified in this list are received */
    321         NIC_MULTICAST_LIST,
    322         /** All multicast frames are received */
    323         NIC_MULTICAST_PROMISC
    324 } nic_multicast_mode_t;
    325 
    326 typedef enum nic_broadcast_mode {
    327         NIC_BROADCAST_UNKNOWN,
    328         /** Broadcast frames are dropped */
    329         NIC_BROADCAST_BLOCKED,
    330         /** Broadcast frames are received */
    331         NIC_BROADCAST_ACCEPTED
    332 } nic_broadcast_mode_t;
    333 
    334 /**
    335  * Structure covering the bitmap with VLAN tags.
    336  */
    337 typedef struct nic_vlan_mask {
    338         uint8_t bitmap[NIC_VLAN_BITMAP_SIZE];
    339 } nic_vlan_mask_t;
    340 
    341 /* WOL virtue identifier */
    342 typedef unsigned int nic_wv_id_t;
    343 
    344 /**
    345  * Structure passed as argument for virtue NIC_WV_MAGIC_PACKET.
    346  */
    347 typedef struct nic_wv_magic_packet_data {
    348         uint8_t password[6];
    349 } nic_wv_magic_packet_data_t;
    350 
    351 /**
    352  * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV4
    353  */
    354 typedef struct nic_wv_ipv4_data {
    355         uint8_t address[4];
    356 } nic_wv_ipv4_data_t;
    357 
    358 /**
    359  * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV6
    360  */
    361 typedef struct nic_wv_ipv6_data {
    362         uint8_t address[16];
    363 } nic_wv_ipv6_data_t;
    364 
    365 /**
    366  * WOL virtue types defining the interpretation of data passed to the virtue.
    367  * Those tagged with S can have only single virtue active at one moment, those
    368  * tagged with M can have multiple ones.
    369  */
    370 typedef enum nic_wv_type {
    371         /**
    372          * Used for deletion of the virtue - in this case the mask, data and length
    373          * arguments are ignored.
    374          */
    375         NIC_WV_NONE,
    376         /** S
    377          * Enabled <=> wakeup upon link change
    378          */
    379         NIC_WV_LINK_CHANGE,
    380         /** S
    381          * If this virtue is set up, wakeup can be issued by a magic packet frame.
    382          * If the data argument is not NULL, it must contain
    383          * nic_wv_magic_packet_data structure with the SecureOn password.
    384          */
    385         NIC_WV_MAGIC_PACKET,
    386         /** M
    387          * If the virtue is set up, wakeup can be issued by a frame targeted to
    388          * device with MAC address specified in data. The data must contain
    389          * nic_address_t structure.
    390          */
    391         NIC_WV_DESTINATION,
    392         /** S
    393          * Enabled <=> wakeup upon receiving broadcast frame
    394          */
    395         NIC_WV_BROADCAST,
    396         /** S
    397          * Enabled <=> wakeup upon receiving ARP Request
    398          */
    399         NIC_WV_ARP_REQUEST,
    400         /** M
    401          * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet
    402          * with IPv4 address specified in data. The data must contain
    403          * nic_wv_ipv4_data structure.
    404          */
    405         NIC_WV_DIRECTED_IPV4,
    406         /** M
    407          * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet
    408          * with IPv6 address specified in data. The data must contain
    409          * nic_wv_ipv6_data structure.
    410          */
    411         NIC_WV_DIRECTED_IPV6,
    412         /** M
    413          * First length/2 bytes in the argument are interpreted as mask, second
    414          * length/2 bytes are interpreted as content.
    415          * If enabled, the wakeup is issued upon receiving frame where the bytes
    416          * with non-zero value in the mask equal to those in the content.
    417          */
    418         NIC_WV_FULL_MATCH,
    419         /**
    420          * Dummy value, do not use.
    421          */
    422         NIC_WV_MAX
    423 } nic_wv_type_t;
    424 
    425 /**
    426  * Specifies the interrupt/polling mode used by the driver and NIC
    427  */
    428 typedef enum nic_poll_mode {
    429         /**
    430          * NIC issues interrupts upon events.
    431          */
    432         NIC_POLL_IMMEDIATE,
    433         /**
    434          * Some uspace app calls nic_poll_now(...) in order to check the NIC state
    435          * - no interrupts are received from the NIC.
    436          */
    437         NIC_POLL_ON_DEMAND,
    438         /**
    439          * The driver itself issues a poll request in a periodic manner. It is
    440          * allowed to use hardware timer if the NIC supports it.
    441          */
    442         NIC_POLL_PERIODIC,
    443         /**
    444          * The driver itself issued a poll request in a periodic manner. The driver
    445          * must create software timer, internal hardware timer of NIC must not be
    446          * used even if the NIC supports it.
    447          */
    448         NIC_POLL_SOFTWARE_PERIODIC
    449 } nic_poll_mode_t;
    450 
    451 /**
    452  * Says if this virtue type is a multi-virtue (there can be multiple virtues of
    453  * this type at once).
    454  *
    455  * @param type
    456  *
    457  * @return true or false
    458  */
    459 static inline int nic_wv_is_multi(nic_wv_type_t type) {
    460         switch (type) {
    461         case NIC_WV_FULL_MATCH:
    462         case NIC_WV_DESTINATION:
    463         case NIC_WV_DIRECTED_IPV4:
    464         case NIC_WV_DIRECTED_IPV6:
    465                 return true;
    466         default:
    467                 return false;
    468         }
    469 }
    470 
    471 static inline const char *nic_device_state_to_string(nic_device_state_t state)
    472 {
    473         switch (state) {
    474         case NIC_STATE_STOPPED:
    475                 return "stopped";
    476         case NIC_STATE_DOWN:
    477                 return "down";
    478         case NIC_STATE_ACTIVE:
    479                 return "active";
    480         default:
    481                 return "undefined";
    482         }
    483 }
    484 
    48549#endif
    48650
  • uspace/lib/c/include/nic/eth_phys.h

    r8afeb04 r948911d  
    2828 */
    2929
    30 #ifndef LIBC_NET_ETH_PHYS_H_
    31 #define LIBC_NET_ETH_PHYS_H_
     30#ifndef LIBC_NIC_ETH_PHYS_H_
     31#define LIBC_NIC_ETH_PHYS_H_
    3232
    3333#include <sys/types.h>
Note: See TracChangeset for help on using the changeset viewer.