Changeset cfb79747 in mainline for uspace/lib


Ignore:
Timestamp:
2012-02-14T22:06:15Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a31aad1
Parents:
199112e4 (diff), e10d41a (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:

Merge mainline changes.

Location:
uspace/lib
Files:
4 added
32 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/device/nic.c

    r199112e4 rcfb79747  
    7373}
    7474
    75 /** Connect the driver to the NET and NIL services
    76  *
    77  * @param[in] dev_sess
    78  * @param[in] nil_service Service identifier for the NIL service
     75/** Create callback connection from NIC service
     76 *
     77 * @param[in] dev_sess
    7978 * @param[in] device_id
    8079 *
     
    8281 *
    8382 */
    84 int nic_connect_to_nil(async_sess_t *dev_sess, services_t nil_service,
    85     nic_device_id_t device_id)
    86 {
    87         async_exch_t *exch = async_exchange_begin(dev_sess);
    88         int rc = async_req_3_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    89             NIC_CONNECT_TO_NIL, nil_service, device_id);
    90         async_exchange_end(exch);
    91        
    92         return rc;
     83int nic_callback_create(async_sess_t *dev_sess, async_client_conn_t cfun,
     84    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_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     92            NIC_CALLBACK_CREATE, &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;
    93103}
    94104
     
    335345 * it can never force the NIC to advertise unsupported modes.
    336346 *
    337  * 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.
    338348 *
    339349 * @param[in] dev_sess
     
    372382/** Probe current state of auto-negotiation.
    373383 *
    374  * 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.
    375385 *
    376386 * @param[in]  dev_sess
  • uspace/lib/c/generic/loc.c

    r199112e4 rcfb79747  
    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
     
    795788    sysarg_t **data, size_t *count)
    796789{
    797         service_id_t *ids;
    798         size_t act_size;
    799         size_t alloc_size;
    800         int rc;
    801 
    802790        *data = NULL;
    803         act_size = 0;   /* silence warning */
    804 
    805         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,
    806795            &act_size);
    807796        if (rc != EOK)
    808797                return rc;
    809 
    810         alloc_size = act_size;
    811         ids = malloc(alloc_size);
     798       
     799        size_t alloc_size = act_size;
     800        service_id_t *ids = malloc(alloc_size);
    812801        if (ids == NULL)
    813802                return ENOMEM;
    814 
     803       
    815804        while (true) {
    816805                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    818807                if (rc != EOK)
    819808                        return rc;
    820 
     809               
    821810                if (act_size <= alloc_size)
    822811                        break;
    823 
    824                 alloc_size *= 2;
    825                 free(ids);
    826 
    827                 ids = malloc(alloc_size);
     812               
     813                alloc_size = act_size;
     814                ids = realloc(ids, alloc_size);
    828815                if (ids == NULL)
    829816                        return ENOMEM;
    830817        }
    831 
     818       
    832819        *count = act_size / sizeof(category_id_t);
    833820        *data = ids;
     
    867854int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    868855{
    869         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);
    870859                return EIO;
    871 
     860        }
     861       
    872862        cat_change_cb = cb_fun;
     863        fibril_mutex_unlock(&loc_callback_mutex);
     864       
    873865        return EOK;
    874866}
  • uspace/lib/c/include/device/nic.h

    r199112e4 rcfb79747  
    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
     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
    8792extern int nic_send_frame(async_sess_t *, void *, size_t);
    88 extern int nic_connect_to_nil(async_sess_t *, services_t, nic_device_id_t);
     93extern int nic_callback_create(async_sess_t *, async_client_conn_t, void *);
    8994extern int nic_get_state(async_sess_t *, nic_device_state_t *);
    9095extern int nic_set_state(async_sess_t *, nic_device_state_t);
  • uspace/lib/c/include/ipc/devman.h

    r199112e4 rcfb79747  
    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

    r199112e4 rcfb79747  
    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

    r199112e4 rcfb79747  
    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

    r199112e4 rcfb79747  
    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/net/device.h

    r199112e4 rcfb79747  
    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
     49/** Device identifier type. */
     50typedef int nic_device_id_t;
    7151
    7252/** Invalid device identifier. */
    7353#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 }
    48454
    48555#endif
  • uspace/lib/c/include/nic/eth_phys.h

    r199112e4 rcfb79747  
    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>
  • uspace/lib/drv/Makefile

    r199112e4 rcfb79747  
    3535        generic/driver.c \
    3636        generic/dev_iface.c \
     37        generic/interrupt.c \
    3738        generic/log.c \
    3839        generic/logbuf.c \
  • uspace/lib/drv/generic/driver.c

    r199112e4 rcfb79747  
    7070FIBRIL_MUTEX_INITIALIZE(functions_mutex);
    7171
    72 /** Interrupts */
    73 static interrupt_context_list_t interrupt_contexts;
    74 
    75 static irq_cmd_t default_cmds[] = {
    76         {
    77                 .cmd = CMD_ACCEPT
    78         }
    79 };
    80 
    81 static irq_code_t default_pseudocode = {
    82         0,
    83         NULL,
    84         sizeof(default_cmds) / sizeof(irq_cmd_t),
    85         default_cmds
    86 };
    87 
    8872static ddf_dev_t *create_device(void);
    8973static void delete_device(ddf_dev_t *);
     
    9579static void *function_get_ops(ddf_fun_t *, dev_inferface_idx_t);
    9680
    97 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
    98 {
    99         int id = (int)IPC_GET_IMETHOD(*icall);
    100         interrupt_context_t *ctx;
    101        
    102         ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
    103         if (ctx != NULL && ctx->handler != NULL)
    104                 (*ctx->handler)(ctx->dev, iid, icall);
    105 }
    106 
    107 interrupt_context_t *create_interrupt_context(void)
    108 {
    109         interrupt_context_t *ctx;
    110        
    111         ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
    112         if (ctx != NULL)
    113                 memset(ctx, 0, sizeof(interrupt_context_t));
    114        
    115         return ctx;
    116 }
    117 
    118 void delete_interrupt_context(interrupt_context_t *ctx)
    119 {
    120         if (ctx != NULL)
    121                 free(ctx);
    122 }
    123 
    124 void init_interrupt_context_list(interrupt_context_list_t *list)
    125 {
    126         memset(list, 0, sizeof(interrupt_context_list_t));
    127         fibril_mutex_initialize(&list->mutex);
    128         list_initialize(&list->contexts);
    129 }
    130 
    131 void
    132 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
    133 {
    134         fibril_mutex_lock(&list->mutex);
    135         ctx->id = list->curr_id++;
    136         list_append(&ctx->link, &list->contexts);
    137         fibril_mutex_unlock(&list->mutex);
    138 }
    139 
    140 void remove_interrupt_context(interrupt_context_list_t *list,
    141     interrupt_context_t *ctx)
    142 {
    143         fibril_mutex_lock(&list->mutex);
    144         list_remove(&ctx->link);
    145         fibril_mutex_unlock(&list->mutex);
    146 }
    147 
    148 interrupt_context_t *
    149 find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    150 {
    151         interrupt_context_t *ctx;
    152        
    153         fibril_mutex_lock(&list->mutex);
    154        
    155         list_foreach(list->contexts, link) {
    156                 ctx = list_get_instance(link, interrupt_context_t, link);
    157                 if (ctx->id == id) {
    158                         fibril_mutex_unlock(&list->mutex);
    159                         return ctx;
    160                 }
    161         }
    162        
    163         fibril_mutex_unlock(&list->mutex);
    164         return NULL;
    165 }
    166 
    167 interrupt_context_t *
    168 find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    169 {
    170         interrupt_context_t *ctx;
    171        
    172         fibril_mutex_lock(&list->mutex);
    173        
    174         list_foreach(list->contexts, link) {
    175                 ctx = list_get_instance(link, interrupt_context_t, link);
    176                 if (ctx->irq == irq && ctx->dev == dev) {
    177                         fibril_mutex_unlock(&list->mutex);
    178                         return ctx;
    179                 }
    180         }
    181        
    182         fibril_mutex_unlock(&list->mutex);
    183         return NULL;
    184 }
    185 
    186 
    187 int
    188 register_interrupt_handler(ddf_dev_t *dev, int irq, interrupt_handler_t *handler,
    189     irq_code_t *pseudocode)
    190 {
    191         interrupt_context_t *ctx = create_interrupt_context();
    192        
    193         ctx->dev = dev;
    194         ctx->irq = irq;
    195         ctx->handler = handler;
    196        
    197         add_interrupt_context(&interrupt_contexts, ctx);
    198        
    199         if (pseudocode == NULL)
    200                 pseudocode = &default_pseudocode;
    201        
    202         int res = irq_register(irq, dev->handle, ctx->id, pseudocode);
    203         if (res != EOK) {
    204                 remove_interrupt_context(&interrupt_contexts, ctx);
    205                 delete_interrupt_context(ctx);
    206         }
    207 
    208         return res;
    209 }
    210 
    211 int unregister_interrupt_handler(ddf_dev_t *dev, int irq)
    212 {
    213         interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
    214             dev, irq);
    215         int res = irq_unregister(irq, dev->handle);
    216        
    217         if (ctx != NULL) {
    218                 remove_interrupt_context(&interrupt_contexts, ctx);
    219                 delete_interrupt_context(ctx);
    220         }
    221        
    222         return res;
    223 }
    224 
    22581static void add_to_functions_list(ddf_fun_t *fun)
    22682{
     
    303159       
    304160        async_answer_0(iid, res);
    305 }
    306 
    307 static void driver_dev_added(ipc_callid_t iid, ipc_call_t *icall)
    308 {
    309         fibril_mutex_lock(&devices_mutex);
    310         ddf_dev_t *dev = driver_get_device(IPC_GET_ARG1(*icall));
    311         fibril_mutex_unlock(&devices_mutex);
    312        
    313         if (dev != NULL && driver->driver_ops->device_added != NULL)
    314                 driver->driver_ops->device_added(dev);
    315161}
    316162
     
    462308                case DRIVER_DEV_ADD:
    463309                        driver_dev_add(callid, &call);
    464                         break;
    465                 case DRIVER_DEV_ADDED:
    466                         async_answer_0(callid, EOK);
    467                         driver_dev_added(callid, &call);
    468310                        break;
    469311                case DRIVER_DEV_REMOVE:
     
    753595
    754596/** Allocate driver-specific device data. */
    755 extern void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
     597void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
    756598{
    757599        void *data;
     
    815657
    816658/** Allocate driver-specific function data. */
    817 extern void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
     659void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
    818660{
    819661        void *data;
     
    1008850        driver = drv;
    1009851       
    1010         /* Initialize the list of interrupt contexts. */
    1011         init_interrupt_context_list(&interrupt_contexts);
    1012        
    1013         /* Set generic interrupt handler. */
    1014         async_set_interrupt_received(driver_irq_handler);
     852        /* Initialize interrupt module */
     853        interrupt_init();
    1015854       
    1016855        /*
  • uspace/lib/drv/generic/remote_nic.c

    r199112e4 rcfb79747  
    6363}
    6464
    65 static void remote_nic_connect_to_nil(ddf_fun_t *dev, void *iface,
    66     ipc_callid_t callid, ipc_call_t *call)
    67 {
    68         nic_iface_t *nic_iface = (nic_iface_t *) iface;
    69         assert(nic_iface->connect_to_nil);
    70        
    71         services_t nil_service = (services_t) IPC_GET_ARG2(*call);
    72         nic_device_id_t device_id = (nic_device_id_t) IPC_GET_ARG3(*call);
    73        
    74         int rc = nic_iface->connect_to_nil(dev, nil_service, device_id);
     65static void remote_nic_callback_create(ddf_fun_t *dev, void *iface,
     66    ipc_callid_t callid, ipc_call_t *call)
     67{
     68        nic_iface_t *nic_iface = (nic_iface_t *) iface;
     69        assert(nic_iface->callback_create);
     70       
     71        int rc = nic_iface->callback_create(dev);
    7572        async_answer_0(callid, rc);
    7673}
     
    12031200static remote_iface_func_ptr_t remote_nic_iface_ops[] = {
    12041201        &remote_nic_send_frame,
    1205         &remote_nic_connect_to_nil,
     1202        &remote_nic_callback_create,
    12061203        &remote_nic_get_state,
    12071204        &remote_nic_set_state,
  • uspace/lib/drv/include/ddf/driver.h

    r199112e4 rcfb79747  
    145145        /** Ask driver to offline a specific function */
    146146        int (*fun_offline)(ddf_fun_t *);
    147 
    148         /**
    149          * Notification that the device was succesfully added.
    150          * The driver can do any blocking operation without
    151          * blocking the device manager.
    152          *
    153          * XXX REMOVE THIS
    154          */
    155         void (*device_added)(ddf_dev_t *dev);
    156147} driver_ops_t;
    157148
  • uspace/lib/drv/include/ddf/interrupt.h

    r199112e4 rcfb79747  
    6464} interrupt_context_list_t;
    6565
    66 extern interrupt_context_t *create_interrupt_context(void);
    67 extern void delete_interrupt_context(interrupt_context_t *);
    68 extern void init_interrupt_context_list(interrupt_context_list_t *);
    69 extern void add_interrupt_context(interrupt_context_list_t *,
    70     interrupt_context_t *);
    71 extern void remove_interrupt_context(interrupt_context_list_t *,
    72     interrupt_context_t *);
    73 extern interrupt_context_t *find_interrupt_context_by_id(
    74     interrupt_context_list_t *, int);
    75 extern interrupt_context_t *find_interrupt_context(
    76     interrupt_context_list_t *, ddf_dev_t *, int);
    77 
     66extern void interrupt_init(void);
    7867extern int register_interrupt_handler(ddf_dev_t *, int, interrupt_handler_t *,
    7968    irq_code_t *);
  • uspace/lib/drv/include/ops/nic.h

    r199112e4 rcfb79747  
    3838
    3939#include <ipc/services.h>
    40 #include <net/device.h>
     40#include <nic/nic.h>
    4141#include <sys/time.h>
    4242
     
    4646        /** Mandatory methods */
    4747        int (*send_frame)(ddf_fun_t *, void *, size_t);
    48         int (*connect_to_nil)(ddf_fun_t *, services_t, nic_device_id_t);
     48        int (*callback_create)(ddf_fun_t *);
    4949        int (*get_state)(ddf_fun_t *, nic_device_state_t *);
    5050        int (*set_state)(ddf_fun_t *, nic_device_state_t);
  • uspace/lib/drv/include/usbhc_iface.h

    r199112e4 rcfb79747  
    2727 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828 */
     29
    2930/** @addtogroup libdrv
    3031 * @addtogroup usb
    3132 * @{
    3233 */
     34
    3335/** @file
    3436 * @brief USB host controller interface definition.
  • uspace/lib/net/generic/net_checksum.c

    r199112e4 rcfb79747  
    4545#define CRC_DIVIDER_LE  0xedb88320
    4646
    47 /** Polynomial used in multicast address hashing */
    48 #define CRC_MCAST_POLYNOMIAL  0x04c11db6
    49 
    5047/** Compacts the computed checksum to the 16 bit number adding the carries.
    5148 *
     
    224221}
    225222
    226 /** Compute the standard hash from MAC
    227  *
    228  * Hashing MAC into 64 possible values and using the value as index to
    229  * 64bit number.
    230  *
    231  * The code is copied from qemu-0.13's implementation of ne2000 and rt8139
    232  * drivers, but according to documentation there it originates in FreeBSD.
    233  *
    234  * @param[in] addr The 6-byte MAC address to be hashed
    235  *
    236  * @return 64-bit number with only single bit set to 1
    237  *
    238  */
    239 uint64_t multicast_hash(const uint8_t addr[6])
    240 {
    241         uint32_t crc;
    242     int carry, i, j;
    243     uint8_t b;
    244 
    245     crc = 0xffffffff;
    246     for (i = 0; i < 6; i++) {
    247         b = addr[i];
    248         for (j = 0; j < 8; j++) {
    249             carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
    250             crc <<= 1;
    251             b >>= 1;
    252             if (carry)
    253                 crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry);
    254         }
    255     }
    256        
    257     uint64_t one64 = 1;
    258     return one64 << (crc >> 26);
    259 }
    260 
    261223/** @}
    262224 */
  • uspace/lib/net/generic/net_remote.c

    r199112e4 rcfb79747  
    167167}
    168168
    169 int net_driver_ready(async_sess_t *sess, devman_handle_t handle)
    170 {
    171         async_exch_t *exch = async_exchange_begin(sess);
    172         int rc = async_req_1_0(exch, NET_NET_DRIVER_READY, handle);
    173         async_exchange_end(exch);
    174        
    175         return rc;
    176 }
    177 
    178169/** @}
    179170 */
  • uspace/lib/net/include/net_checksum.h

    r199112e4 rcfb79747  
    6767extern uint16_t flip_checksum(uint16_t);
    6868extern uint16_t ip_checksum(uint8_t *, size_t);
    69 extern uint64_t multicast_hash(const uint8_t addr[6]);
    7069
    7170#endif
  • uspace/lib/net/include/net_interface.h

    r199112e4 rcfb79747  
    5252extern int net_get_devices_req(async_sess_t *, measured_string_t **, size_t *,
    5353    uint8_t **);
    54 extern int net_driver_ready(async_sess_t *, devman_handle_t);
    5554extern async_sess_t *net_connect_module(void);
    5655
  • uspace/lib/net/include/nil_remote.h

    r199112e4 rcfb79747  
    3434#define __NET_NIL_REMOTE_H__
    3535
     36#include <ipc/loc.h>
    3637#include <net/device.h>
    3738#include <net/packet.h>
     
    3940#include <generic.h>
    4041#include <async.h>
     42#include <sys/types.h>
    4143
    4244#define nil_bind_service(service, device_id, me, receiver) \
     
    6062extern int nil_device_req(async_sess_t *, nic_device_id_t, devman_handle_t,
    6163    size_t);
    62 extern int nil_device_state_msg(async_sess_t *, nic_device_id_t, sysarg_t);
    63 extern int nil_received_msg(async_sess_t *, nic_device_id_t, packet_id_t);
    64 extern int nil_addr_changed_msg(async_sess_t *, nic_device_id_t,
    65     const nic_address_t *);
    6664
    6765#endif
  • uspace/lib/net/nil/nil_remote.c

    r199112e4 rcfb79747  
    3636 */
    3737
     38#include <ipc/loc.h>
    3839#include <nil_remote.h>
    3940#include <generic.h>
     
    4344#include <ipc/nil.h>
    4445
    45 /** Notify the network interface layer about the device state change.
    46  *
    47  * @param[in] sess      Network interface layer session.
    48  * @param[in] device_id Device identifier.
    49  * @param[in] state     New device state.
    50  *
    51  * @return EOK on success.
    52  * @return Other error codes as defined for each specific module
    53  *         device state function.
    54  *
    55  */
    56 int nil_device_state_msg(async_sess_t *sess, nic_device_id_t device_id,
    57     sysarg_t state)
    58 {
    59         return generic_device_state_msg_remote(sess, NET_NIL_DEVICE_STATE,
    60             device_id, state, 0);
    61 }
    62 
    63 /** Pass the packet queue to the network interface layer.
    64  *
    65  * Process and redistribute the received packet queue to the registered
    66  * upper layers.
    67  *
    68  * @param[in] sess      Network interface layer session.
    69  * @param[in] device_id Source device identifier.
    70  * @param[in] packet    Received packet or the received packet queue.
    71  * @param[in] target    Target service. Ignored parameter.
    72  *
    73  * @return EOK on success.
    74  * @return Other error codes as defined for each specific module
    75  *         received function.
    76  *
    77  */
    78 int nil_received_msg(async_sess_t *sess, nic_device_id_t device_id,
    79     packet_id_t packet_id)
    80 {
    81         return generic_received_msg_remote(sess, NET_NIL_RECEIVED,
    82             device_id, packet_id, 0, 0);
    83 }
    84 
    85 /** Notify upper layers that device address has changed
    86  *
    87  */
    88 int nil_addr_changed_msg(async_sess_t *sess, nic_device_id_t device_id,
    89     const nic_address_t *address)
    90 {
    91         assert(sess);
    92        
    93         async_exch_t *exch = async_exchange_begin(sess);
    94        
    95         aid_t message_id = async_send_1(exch, NET_NIL_ADDR_CHANGED,
    96             (sysarg_t) device_id, NULL);
    97         int rc = async_data_write_start(exch, address, sizeof (nic_address_t));
    98        
    99         async_exchange_end(exch);
    100        
    101         sysarg_t res;
    102     async_wait_for(message_id, &res);
    103        
    104     if (rc != EOK)
    105                 return rc;
    106        
    107     return (int) res;
    108 }
    109 
    11046int nil_device_req(async_sess_t *sess, nic_device_id_t device_id,
    111     devman_handle_t handle, size_t mtu)
     47    service_id_t sid, size_t mtu)
    11248{
    11349        async_exch_t *exch = async_exchange_begin(sess);
    11450        int rc = async_req_3_0(exch, NET_NIL_DEVICE, (sysarg_t) device_id,
    115             (sysarg_t) handle, (sysarg_t) mtu);
     51            (sysarg_t) sid, (sysarg_t) mtu);
    11652        async_exchange_end(exch);
    11753        return rc;
  • uspace/lib/nic/Makefile

    r199112e4 rcfb79747  
    2929USPACE_PREFIX = ../..
    3030LIBRARY = libnic
    31 LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBNET_PREFIX)/libnet.a
    32 EXTRA_CFLAGS += -DLIBNIC_INTERNAL -Iinclude -I$(LIBDRV_PREFIX)/include -I$(LIBNET_PREFIX)/include
     31EXTRA_CFLAGS += -DLIBNIC_INTERNAL -Iinclude -I$(LIBDRV_PREFIX)/include
    3332
    3433SOURCES = \
    3534        src/nic_driver.c \
     35        src/nic_ev.c \
    3636        src/nic_addr_db.c \
    3737        src/nic_rx_control.c \
  • uspace/lib/nic/include/nic.h

    r199112e4 rcfb79747  
    4242#include <ddf/driver.h>
    4343#include <device/hw_res_parsed.h>
    44 #include <net/packet.h>
    4544#include <ops/nic.h>
     45
     46#define DEVICE_CATEGORY_NIC "nic"
    4647
    4748struct nic;
     
    6162
    6263/**
    63  * Simple structure for sending the allocated frames (packets) in a list.
     64 * Simple structure for sending lists of frames.
    6465 */
    6566typedef struct {
    6667        link_t link;
    67         packet_t *packet;
     68        void *data;
     69        size_t size;
    6870} nic_frame_t;
    6971
     
    7173
    7274/**
    73  * Handler for writing packet data to the NIC device.
    74  * The function is responsible for releasing the packet.
     75 * Handler for writing frame data to the NIC device.
     76 * The function is responsible for releasing the frame.
    7577 * It does not return anything, if some error is detected the function just
    7678 * silently fails (logging on debug level is suggested).
     
    158160 * @return ENOTSUP      If this filter cannot work on this NIC (e.g. the NIC
    159161 *                                      cannot run in promiscuous node or the limit of WOL
    160  *                                      packets' specifications was reached).
     162 *                                      frames' specifications was reached).
    161163 * @return ELIMIT       If this filter must implemented in HW but currently the
    162164 *                                      limit of these HW filters was reached.
     
    204206/* Functions called in add_device */
    205207extern int nic_connect_to_services(nic_t *);
    206 extern int nic_register_as_ddf_fun(nic_t *, ddf_dev_ops_t *);
    207208extern int nic_get_resources(nic_t *, hw_res_list_parsed_t *);
    208209extern void nic_set_specific(nic_t *, void *);
     
    219220        poll_mode_change_handler, poll_request_handler);
    220221
    221 /* Functions called in device_added */
    222 extern int nic_ready(nic_t *);
    223 
    224222/* General driver functions */
    225223extern ddf_dev_t *nic_get_ddf_dev(nic_t *);
    226224extern ddf_fun_t *nic_get_ddf_fun(nic_t *);
     225extern void nic_set_ddf_fun(nic_t *, ddf_fun_t *);
    227226extern nic_t *nic_get_from_ddf_dev(ddf_dev_t *);
    228227extern nic_t *nic_get_from_ddf_fun(ddf_fun_t *);
     
    233232extern int nic_report_poll_mode(nic_t *, nic_poll_mode_t, struct timeval *);
    234233extern void nic_query_address(nic_t *, nic_address_t *);
    235 extern void nic_received_packet(nic_t *, packet_t *);
    236 extern void nic_received_noneth_packet(nic_t *, packet_t *);
     234extern void nic_received_noneth_frame(nic_t *, void *, size_t);
    237235extern void nic_received_frame(nic_t *, nic_frame_t *);
    238236extern void nic_received_frame_list(nic_t *, nic_frame_list_t *);
     
    248246extern void nic_report_collisions(nic_t *, unsigned);
    249247
    250 /* Packet / frame / frame list allocation and deallocation */
    251 extern packet_t *nic_alloc_packet(nic_t *, size_t);
    252 extern void nic_release_packet(nic_t *, packet_t *);
     248/* Frame / frame list allocation and deallocation */
    253249extern nic_frame_t *nic_alloc_frame(nic_t *, size_t);
    254250extern nic_frame_list_t *nic_alloc_frame_list(void);
     
    275271extern void nic_sw_period_stop(nic_t *);
    276272
    277 /* Packet DMA lock */
    278 extern int nic_dma_lock_packet(packet_t *, size_t, void **);
    279 extern int nic_dma_unlock_packet(packet_t *, size_t);
    280 
    281273#endif // __NIC_H__
    282274
  • uspace/lib/nic/include/nic_driver.h

    r199112e4 rcfb79747  
    4444
    4545#include <fibril_synch.h>
    46 #include <net/device.h>
     46#include <nic/nic.h>
    4747#include <async.h>
    4848
     
    5050#include "nic_rx_control.h"
    5151#include "nic_wol_virtues.h"
    52 
    53 #define DEVICE_CATEGORY_NIC "nic"
    5452
    5553struct sw_poll_info {
     
    7270         */
    7371        ddf_fun_t *fun;
    74         /** Identifier for higher network stack layers */
    75         nic_device_id_t device_id;
    7672        /** Current state of the device */
    7773        nic_device_state_t state;
     
    8278        /** Device's default MAC address (assigned the first time, used in STOP) */
    8379        nic_address_t default_mac;
    84         /** Session to SERVICE_NETWORKING */
    85         async_sess_t *net_session;
    86         /** Session to SERVICE_ETHERNET or SERVICE_NILDUMMY */
    87         async_sess_t *nil_session;
     80        /** Client callback session */
     81        async_sess_t *client_session;
    8882        /** Phone to APIC or i8259 */
    8983        async_sess_t *irc_session;
  • uspace/lib/nic/include/nic_impl.h

    r199112e4 rcfb79747  
    4040
    4141#include <assert.h>
    42 #include <net/device.h>
     42#include <nic/nic.h>
    4343#include <ddf/driver.h>
    44 #include <nil_remote.h>
    4544
    4645/* Inclusion of this file is not prohibited, because drivers could want to
     
    4948extern int nic_get_address_impl(ddf_fun_t *dev_fun, nic_address_t *address);
    5049extern int nic_send_frame_impl(ddf_fun_t *dev_fun, void *data, size_t size);
    51 extern int nic_connect_to_nil_impl(ddf_fun_t *dev_fun, services_t nil_service,
    52         int device_id);
     50extern int nic_callback_create_impl(ddf_fun_t *dev_fun);
    5351extern int nic_get_state_impl(ddf_fun_t *dev_fun, nic_device_state_t *state);
    5452extern int nic_set_state_impl(ddf_fun_t *dev_fun, nic_device_state_t state);
  • uspace/lib/nic/include/nic_rx_control.h

    r199112e4 rcfb79747  
    4545#include <adt/hash_table.h>
    4646#include <fibril_synch.h>
    47 #include <net/device.h>
    48 #include <net/packet_header.h>
     47#include <nic/nic.h>
    4948
    5049#include "nic_addr_db.h"
     
    120119        const nic_address_t *prev_addr, const nic_address_t *curr_addr);
    121120extern int nic_rxc_check(const nic_rxc_t *rxc,
    122         const packet_t *packet, nic_frame_type_t *frame_type);
     121        const void *data, size_t size, nic_frame_type_t *frame_type);
    123122extern void nic_rxc_hw_filtering(nic_rxc_t *rxc,
    124123        int unicast_exact, int multicast_exact, int vlan_exact);
  • uspace/lib/nic/include/nic_wol_virtues.h

    r199112e4 rcfb79747  
    4343#endif
    4444
    45 #include <net/device.h>
     45#include <nic/nic.h>
    4646#include <adt/hash_table.h>
    4747#include "nic.h"
  • uspace/lib/nic/src/nic_driver.c

    r199112e4 rcfb79747  
    4949#include <devman.h>
    5050#include <ddf/interrupt.h>
    51 #include <net_interface.h>
    5251#include <ops/nic.h>
    53 #include <packet_client.h>
    54 #include <packet_remote.h>
    55 #include <net/packet_header.h>
    5652#include <errno.h>
    5753
    5854#include "nic_driver.h"
     55#include "nic_ev.h"
    5956#include "nic_impl.h"
    6057
     
    6461
    6562/**
    66  * Initializes libraries required for NIC framework - logger, packet manager
     63 * Initializes libraries required for NIC framework - logger
    6764 *
    6865 * @param name  Name of the device/driver (used in logging)
     
    7976        snprintf(buffer, 256, "drv/" DEVICE_CATEGORY_NIC "/%s", name);
    8077       
    81         /* Initialize packet manager */
    82         return pm_init();
     78        return EOK;
    8379}
    8480
     
    9389    nic_iface_t *iface)
    9490{
    95         if (driver_ops) {
    96                 if (!driver_ops->device_added)
    97                         driver_ops->device_added = nic_device_added_impl;
    98         }
    99 
    10091        if (dev_ops) {
    10192                if (!dev_ops->open)
     
    116107                if (!iface->send_frame)
    117108                        iface->send_frame = nic_send_frame_impl;
    118                 if (!iface->connect_to_nil)
    119                         iface->connect_to_nil = nic_connect_to_nil_impl;
     109                if (!iface->callback_create)
     110                        iface->callback_create = nic_callback_create_impl;
    120111                if (!iface->get_address)
    121112                        iface->get_address = nic_get_address_impl;
     
    162153
    163154/**
    164  * Setup write packet handler. This MUST be called in the add_device handler
     155 * Setup send frame handler. This MUST be called in the add_device handler
    165156 * if the nic_send_message_impl function is used for sending messages (filled
    166157 * as send_message member of the nic_iface_t structure). The function must not
     
    270261}
    271262
    272 /**
    273  * Just a wrapper over the packet_get_1_remote function
    274  */
    275 packet_t *nic_alloc_packet(nic_t *nic_data, size_t data_size)
    276 {
    277         return packet_get_1_remote(nic_data->net_session, data_size);
    278 }
    279 
    280 
    281 /**
    282  * Just a wrapper over the pq_release_remote function
    283  */
    284 void nic_release_packet(nic_t *nic_data, packet_t *packet)
    285 {
    286         pq_release_remote(nic_data->net_session, packet_get_id(packet));
    287 }
    288 
    289 /** Allocate frame and packet
     263/** Allocate frame
    290264 *
    291265 *  @param nic_data     The NIC driver data
    292  *  @param packet_size  Size of packet
    293  *  @param offload_size Size of packet offload
     266 *  @param size         Frame size in bytes
    294267 *  @return pointer to allocated frame if success, NULL otherwise
    295268 */
    296 nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t packet_size)
     269nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t size)
    297270{
    298271        nic_frame_t *frame;
     
    313286        }
    314287
    315         packet_t *packet = nic_alloc_packet(nic_data, packet_size);
    316         if (!packet) {
     288        frame->data = malloc(size);
     289        if (frame->data == NULL) {
    317290                free(frame);
    318291                return NULL;
    319292        }
    320293
    321         frame->packet = packet;
     294        frame->size = size;
    322295        return frame;
    323296}
     
    332305        if (!frame)
    333306                return;
    334         if (frame->packet != NULL) {
    335                 nic_release_packet(nic_data, frame->packet);
    336         }
     307
     308        if (frame->data != NULL) {
     309                free(frame->data);
     310                frame->data = NULL;
     311                frame->size = 0;
     312        }
     313
    337314        fibril_mutex_lock(&nic_globals.lock);
    338315        if (nic_globals.frame_cache_size >= NIC_GLOBALS_MAX_CACHE_SIZE) {
     
    447424
    448425/**
    449  * Connect to the NET and IRQ services. This function should be called only from
     426 * Connect to IRC service. This function should be called only from
    450427 * the add_device handler, thus no locking is required.
    451428 *
     
    454431 * @return EOK          If connection was successful.
    455432 * @return EINVAL       If the IRC service cannot be determined.
    456  * @return EREFUSED     If NET or IRC service cannot be connected.
     433 * @return EREFUSED     If IRC service cannot be connected.
    457434 */
    458435int nic_connect_to_services(nic_t *nic_data)
    459436{
    460         /* NET service */
    461         nic_data->net_session = service_connect_blocking(EXCHANGE_SERIALIZE,
    462                 SERVICE_NETWORKING, 0, 0);
    463         if (nic_data->net_session == NULL)
    464                 return errno;
    465        
    466437        /* IRC service */
    467438        sysarg_t apic;
     
    480451       
    481452        return EOK;
    482 }
    483 
    484 /** Notify the NET service that the device is ready
    485  *
    486  * @param nic NICF structure
    487  *
    488  * @return EOK on success
    489  *
    490  */
    491 int nic_ready(nic_t *nic)
    492 {
    493         fibril_rwlock_read_lock(&nic->main_lock);
    494        
    495         async_sess_t *session = nic->net_session;
    496         devman_handle_t handle = nic->dev->handle;
    497        
    498         fibril_rwlock_read_unlock(&nic->main_lock);
    499        
    500         if (session == NULL)
    501                 return EINVAL;
    502        
    503         return net_driver_ready(session, handle);
    504453}
    505454
     
    546495       
    547496        /* Notify NIL layer (and uppper) if bound - not in add_device */
    548         if (nic_data->nil_session != NULL) {
    549                 int rc = nil_addr_changed_msg(nic_data->nil_session,
    550                     nic_data->device_id, address);
     497        if (nic_data->client_session != NULL) {
     498                int rc = nic_ev_addr_changed(nic_data->client_session,
     499                    address);
    551500                if (rc != EOK) {
    552501                        fibril_rwlock_write_unlock(&nic_data->main_lock);
     
    604553
    605554/**
    606  * The busy flag can be set to 1 only in the write_packet handler, to 0 it can
     555 * The busy flag can be set to 1 only in the send_frame handler, to 0 it can
    607556 * be set anywhere.
    608557 *
     
    613562{
    614563        /*
    615          * When the function is called in write_packet handler the main lock is
     564         * When the function is called in send_frame handler the main lock is
    616565         * locked so no race can happen.
    617566         * Otherwise, when it is unexpectedly set to 0 (even with main lock held
     
    622571
    623572/**
    624  * Provided for correct naming conventions.
    625  * The packet is checked by filters and then sent up to the NIL layer or
    626  * discarded, the frame is released.
    627  *
    628  * @param nic_data
    629  * @param frame         The frame containing received packet
     573 * This is the function that the driver should call when it receives a frame.
     574 * The frame is checked by filters and then sent up to the NIL layer or
     575 * discarded. The frame is released.
     576 *
     577 * @param nic_data
     578 * @param frame         The received frame
    630579 */
    631580void nic_received_frame(nic_t *nic_data, nic_frame_t *frame)
    632581{
    633         nic_received_packet(nic_data, frame->packet);
    634         frame->packet = NULL;
    635         nic_release_frame(nic_data, frame);
    636 }
    637 
    638 /**
    639  * This is the function that the driver should call when it receives a packet.
    640  * The packet is checked by filters and then sent up to the NIL layer or
    641  * discarded.
    642  *
    643  * @param nic_data
    644  * @param packet                The received packet
    645  */
    646 void nic_received_packet(nic_t *nic_data, packet_t *packet)
    647 {
    648582        /* Note: this function must not lock main lock, because loopback driver
    649          *               calls it inside write_packet handler (with locked main lock) */
    650         packet_id_t pid = packet_get_id(packet);
    651        
     583         *               calls it inside send_frame handler (with locked main lock) */
    652584        fibril_rwlock_read_lock(&nic_data->rxc_lock);
    653585        nic_frame_type_t frame_type;
    654         int check = nic_rxc_check(&nic_data->rx_control, packet, &frame_type);
     586        int check = nic_rxc_check(&nic_data->rx_control, frame->data,
     587            frame->size, &frame_type);
    655588        fibril_rwlock_read_unlock(&nic_data->rxc_lock);
    656589        /* Update statistics */
    657590        fibril_rwlock_write_lock(&nic_data->stats_lock);
    658         /* Both sending message up and releasing packet are atomic IPC calls */
     591
    659592        if (nic_data->state == NIC_STATE_ACTIVE && check) {
    660593                nic_data->stats.receive_packets++;
    661                 nic_data->stats.receive_bytes += packet_get_data_length(packet);
     594                nic_data->stats.receive_bytes += frame->size;
    662595                switch (frame_type) {
    663596                case NIC_FRAME_MULTICAST:
     
    671604                }
    672605                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    673                 nil_received_msg(nic_data->nil_session, nic_data->device_id, pid);
     606                nic_ev_received(nic_data->client_session, frame->data,
     607                    frame->size);
    674608        } else {
    675609                switch (frame_type) {
     
    685619                }
    686620                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    687                 nic_release_packet(nic_data, packet);
    688         }
     621        }
     622        nic_release_frame(nic_data, frame);
    689623}
    690624
    691625/**
    692626 * This function is to be used only in the loopback driver. It's workaround
    693  * for the situation when the packet does not contain ethernet address.
     627 * for the situation when the frame does not contain ethernet address.
    694628 * The filtering is therefore not applied here.
    695629 *
    696630 * @param nic_data
    697  * @param packet
    698  */
    699 void nic_received_noneth_packet(nic_t *nic_data, packet_t *packet)
     631 * @param data          Frame data
     632 * @param size          Frame size in bytes
     633 */
     634void nic_received_noneth_frame(nic_t *nic_data, void *data, size_t size)
    700635{
    701636        fibril_rwlock_write_lock(&nic_data->stats_lock);
    702637        nic_data->stats.receive_packets++;
    703         nic_data->stats.receive_bytes += packet_get_data_length(packet);
     638        nic_data->stats.receive_bytes += size;
    704639        fibril_rwlock_write_unlock(&nic_data->stats_lock);
    705640       
    706         nil_received_msg(nic_data->nil_session, nic_data->device_id,
    707             packet_get_id(packet));
    708 }
    709 
    710 /**
    711  * Some NICs can receive multiple packets during single interrupt. These can
     641        nic_ev_received(nic_data->client_session, data, size);
     642}
     643
     644/**
     645 * Some NICs can receive multiple frames during single interrupt. These can
    712646 * send them in whole list of frames (actually nic_frame_t structures), then
    713  * the list is deallocated and each packet is passed to the
     647 * the list is deallocated and each frame is passed to the
    714648 * nic_received_packet function.
    715649 *
     
    726660
    727661                list_remove(&frame->link);
    728                 nic_received_packet(nic_data, frame->packet);
    729                 frame->packet = NULL;
    730                 nic_release_frame(nic_data, frame);
     662                nic_received_frame(nic_data, frame);
    731663        }
    732664        nic_driver_release_frame_list(frames);
     
    758690        nic_data->dev = NULL;
    759691        nic_data->fun = NULL;
    760         nic_data->device_id = NIC_DEVICE_INVALID_ID;
    761692        nic_data->state = NIC_STATE_STOPPED;
    762         nic_data->net_session = NULL;
    763         nic_data->nil_session = NULL;
     693        nic_data->client_session = NULL;
    764694        nic_data->irc_session = NULL;
    765695        nic_data->poll_mode = NIC_POLL_IMMEDIATE;
     
    815745 */
    816746static void nic_destroy(nic_t *nic_data) {
    817         if (nic_data->net_session != NULL) {
    818                 async_hangup(nic_data->net_session);
    819         }
    820 
    821         if (nic_data->nil_session != NULL) {
    822                 async_hangup(nic_data->nil_session);
     747        if (nic_data->client_session != NULL) {
     748                async_hangup(nic_data->client_session);
    823749        }
    824750
     
    846772
    847773/**
    848  * Creates an exposed DDF function for the device, named "port0".
    849  * Device options are set as this function's options. The function is bound
    850  * (see ddf_fun_bind) and then registered to the DEVICE_CATEGORY_NIC class.
    851  * Note: this function should be called only from add_device handler, therefore
    852  * we don't need to use locks.
    853  *
    854  * @param nic_data      The NIC structure
    855  * @param ops           Device options for the DDF function.
    856  */
    857 int nic_register_as_ddf_fun(nic_t *nic_data, ddf_dev_ops_t *ops)
    858 {
    859         int rc;
    860         assert(nic_data);
    861 
    862         nic_data->fun = ddf_fun_create(nic_data->dev, fun_exposed, "port0");
    863         if (nic_data->fun == NULL)
    864                 return ENOMEM;
    865        
    866         nic_data->fun->ops = ops;
    867         nic_data->fun->driver_data = nic_data;
    868 
    869         rc = ddf_fun_bind(nic_data->fun);
    870         if (rc != EOK) {
    871                 ddf_fun_destroy(nic_data->fun);
    872                 return rc;
    873         }
    874 
    875         rc = ddf_fun_add_to_category(nic_data->fun, DEVICE_CATEGORY_NIC);
    876         if (rc != EOK) {
    877                 ddf_fun_destroy(nic_data->fun);
    878                 return rc;
    879         }
    880        
    881         return EOK;
    882 }
    883 
    884 /**
    885774 * Set information about current HW filtering.
    886775 *  1 ...       Only those frames we want to receive are passed through HW
     
    1097986{
    1098987        return nic_data->fun;
     988}
     989
     990/**
     991 * @param nic_data
     992 * @param fun
     993 */
     994void nic_set_ddf_fun(nic_t *nic_data, ddf_fun_t *fun)
     995{
     996        nic_data->fun = fun;
    1099997}
    1100998
     
    13291227}
    13301228
    1331 /** Lock packet for DMA usage
    1332  *
    1333  * @param packet
    1334  * @return physical address of packet
    1335  */
    1336 int nic_dma_lock_packet(packet_t *packet, size_t size, void **phys)
    1337 {
    1338         return dmamem_map(packet, SIZE2PAGES(size), 0, 0, phys);
    1339 }
    1340 
    1341 /** Unlock packet after DMA usage
    1342  *
    1343  * @param packet
    1344  */
    1345 int nic_dma_unlock_packet(packet_t *packet, size_t size)
    1346 {
    1347         return dmamem_unmap(packet, size);
    1348 }
    1349 
    13501229/** @}
    13511230 */
  • uspace/lib/nic/src/nic_impl.c

    r199112e4 rcfb79747  
    3636 */
    3737
     38#include <errno.h>
    3839#include <str_error.h>
    3940#include <ipc/services.h>
    4041#include <ns.h>
    4142#include "nic_driver.h"
     43#include "nic_ev.h"
    4244#include "nic_impl.h"
    4345
     
    8587        }
    8688        if (state == NIC_STATE_ACTIVE) {
    87                 if (nic_data->nil_session == NULL || nic_data->net_session == NULL
    88                     || nic_data->device_id < 0) {
     89                if (nic_data->client_session == NULL) {
    8990                        fibril_rwlock_write_unlock(&nic_data->main_lock);
    9091                        return EINVAL;
     
    116117        if (state == NIC_STATE_STOPPED) {
    117118                /* Notify upper layers that we are reseting the MAC */
    118                 int rc = nil_addr_changed_msg(nic_data->nil_session,
    119                         nic_data->device_id, &nic_data->default_mac);
     119                int rc = nic_ev_addr_changed(nic_data->client_session,
     120                        &nic_data->default_mac);
    120121                nic_data->poll_mode = nic_data->default_poll_mode;
    121122                memcpy(&nic_data->poll_period, &nic_data->default_poll_period,
     
    149150        nic_data->state = state;
    150151
    151         nil_device_state_msg(nic_data->nil_session, nic_data->device_id, state);
     152        nic_ev_device_state(nic_data->client_session, state);
    152153
    153154        fibril_rwlock_write_unlock(&nic_data->main_lock);
     
    182183
    183184/**
    184  * Default implementation of the connect_to_nil method.
    185  * Connects the driver to the NIL service.
     185 * Default implementation of the connect_client method.
     186 * Creates callback connection to the client.
    186187 *
    187188 * @param       fun
    188  * @param       nil_service     ID of the server implementing the NIL service
    189  * @param       device_id       ID of the device as used in higher layers
    190  *
    191  * @return EOK          If the services were bound
    192  * @return                      Negative error code from service_connect_blocking
    193  */
    194 int nic_connect_to_nil_impl(ddf_fun_t *fun, services_t nil_service,
    195     nic_device_id_t device_id)
    196 {
    197         nic_t *nic_data = (nic_t *) fun->driver_data;
    198         fibril_rwlock_write_lock(&nic_data->main_lock);
     189 *
     190 * @return EOK          On success, or negative error code.
     191 */
     192int nic_callback_create_impl(ddf_fun_t *fun)
     193{
     194        nic_t *nic = (nic_t *) fun->driver_data;
     195        fibril_rwlock_write_lock(&nic->main_lock);
    199196       
    200         nic_data->device_id = device_id;
     197        nic->client_session = async_callback_receive(EXCHANGE_SERIALIZE);
     198        if (nic->client_session == NULL) {
     199                fibril_rwlock_write_unlock(&nic->main_lock);
     200                return ENOMEM;
     201        }
    201202       
    202         nic_data->nil_session = service_connect_blocking(EXCHANGE_SERIALIZE,
    203             nil_service, 0, 0);
    204         if (nic_data->nil_session != NULL) {
    205                 fibril_rwlock_write_unlock(&nic_data->main_lock);
    206                 return EOK;
    207         }
    208        
    209         fibril_rwlock_write_unlock(&nic_data->main_lock);
    210         return EHANGUP;
     203        fibril_rwlock_write_unlock(&nic->main_lock);
     204        return EOK;
    211205}
    212206
     
    805799}
    806800
    807 /** Default implementation of the device_added method
    808  *
    809  * Just calls nic_ready.
    810  *
    811  * @param dev
    812  *
    813  */
    814 void nic_device_added_impl(ddf_dev_t *dev)
    815 {
    816         nic_ready((nic_t *) dev->driver_data);
    817 }
    818 
    819801/**
    820802 * Default handler for unknown methods (outside of the NIC interface).
  • uspace/lib/nic/src/nic_rx_control.c

    r199112e4 rcfb79747  
    4040#include <bool.h>
    4141#include <errno.h>
    42 #include <net/device.h>
    43 #include <net_checksum.h>
    44 #include <packet_client.h>
     42#include <mem.h>
     43#include <nic/nic.h>
    4544#include "nic_rx_control.h"
    4645
     
    392391 *
    393392 * @param rxc
    394  * @param packet        The probed frame
     393 * @param frame     The probed frame
    395394 *
    396395 * @return True if the frame passes, false if it does not
    397396 */
    398 int nic_rxc_check(const nic_rxc_t *rxc, const packet_t *packet,
     397int nic_rxc_check(const nic_rxc_t *rxc, const void *data, size_t size,
    399398        nic_frame_type_t *frame_type)
    400399{
    401400        assert(frame_type != NULL);
    402         uint8_t *dest_addr = (uint8_t *) packet + packet->data_start;
     401        uint8_t *dest_addr = (uint8_t *) data;
    403402        uint8_t *src_addr = dest_addr + ETH_ADDR;
     403
     404        if (size < 2 * ETH_ADDR)
     405                return false;
    404406
    405407        if (dest_addr[0] & 1) {
     
    448450        if (!rxc->vlan_exact && rxc->vlan_mask != NULL) {
    449451                vlan_header_t *vlan_header = (vlan_header_t *)
    450                         ((uint8_t *) packet + packet->data_start + 2 * ETH_ADDR);
     452                        ((uint8_t *) data + 2 * ETH_ADDR);
    451453                if (vlan_header->tpid_upper == VLAN_TPID_UPPER &&
    452454                        vlan_header->tpid_lower == VLAN_TPID_LOWER) {
     
    484486                rxc->vlan_exact = vlan_exact;
    485487}
     488
     489/** Polynomial used in multicast address hashing */
     490#define CRC_MCAST_POLYNOMIAL  0x04c11db6
     491
     492/** Compute the standard hash from MAC
     493 *
     494 * Hashing MAC into 64 possible values and using the value as index to
     495 * 64bit number.
     496 *
     497 * The code is copied from qemu-0.13's implementation of ne2000 and rt8139
     498 * drivers, but according to documentation there it originates in FreeBSD.
     499 *
     500 * @param[in] addr The 6-byte MAC address to be hashed
     501 *
     502 * @return 64-bit number with only single bit set to 1
     503 *
     504 */
     505static uint64_t multicast_hash(const uint8_t addr[6])
     506{
     507        uint32_t crc;
     508    int carry, i, j;
     509    uint8_t b;
     510
     511    crc = 0xffffffff;
     512    for (i = 0; i < 6; i++) {
     513        b = addr[i];
     514        for (j = 0; j < 8; j++) {
     515            carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
     516            crc <<= 1;
     517            b >>= 1;
     518            if (carry)
     519                crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry);
     520        }
     521    }
     522       
     523    uint64_t one64 = 1;
     524    return one64 << (crc >> 26);
     525}
     526
    486527
    487528/**
  • uspace/lib/nic/src/nic_wol_virtues.c

    r199112e4 rcfb79747  
    3838#include "nic_wol_virtues.h"
    3939#include <assert.h>
     40#include <errno.h>
    4041
    4142#define NIC_WV_HASH_COUNT 32
  • uspace/lib/posix/ctype.c

    r199112e4 rcfb79747  
    112112 * @return Non-zero if character match the definition, zero otherwise.
    113113 */
    114 extern int posix_isascii(int c)
     114int posix_isascii(int c)
    115115{
    116116        return c >= 0 && c < 128;
     
    123123 * @return Coverted character.
    124124 */
    125 extern int posix_toascii(int c)
     125int posix_toascii(int c)
    126126{
    127127        return c & 0x7F;
Note: See TracChangeset for help on using the changeset viewer.