Changeset c38e417 in mainline


Ignore:
Timestamp:
2012-01-22T11:53:22Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b7e0260
Parents:
eaa0c3f (diff), 8d7ec69d (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 with mainline

Location:
uspace
Files:
2 added
15 edited

Legend:

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

    reaa0c3f rc38e417  
    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, 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;
    93103}
    94104
  • uspace/lib/c/include/device/nic.h

    reaa0c3f rc38e417  
    3939#include <net/device.h>
    4040#include <net/packet.h>
     41#include <ipc/common.h>
    4142#include <ipc/services.h>
    4243
    4344typedef enum {
    4445        NIC_SEND_MESSAGE = 0,
    45         NIC_CONNECT_TO_NIL,
     46        NIC_CALLBACK_CREATE,
    4647        NIC_GET_STATE,
    4748        NIC_SET_STATE,
     
    8586} nic_funcs_t;
    8687
     88typedef enum {
     89        NIC_EV_ADDR_CHANGED = IPC_FIRST_USER_METHOD,
     90        NIC_EV_RECEIVED,
     91        NIC_EV_DEVICE_STATE
     92} nic_event_t;
     93
    8794extern 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);
     95extern int nic_callback_create(async_sess_t *, nic_device_id_t,
     96    async_client_conn_t, void *);
    8997extern int nic_get_state(async_sess_t *, nic_device_state_t *);
    9098extern int nic_set_state(async_sess_t *, nic_device_state_t);
  • uspace/lib/c/include/ipc/nil.h

    reaa0c3f rc38e417  
    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/drv/generic/remote_nic.c

    reaa0c3f rc38e417  
    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        nic_device_id_t device_id = (nic_device_id_t) IPC_GET_ARG2(*call);
     72       
     73        int rc = nic_iface->callback_create(dev, device_id);
    7574        async_answer_0(callid, rc);
    7675}
     
    12031202static remote_iface_func_ptr_t remote_nic_iface_ops[] = {
    12041203        &remote_nic_send_frame,
    1205         &remote_nic_connect_to_nil,
     1204        &remote_nic_callback_create,
    12061205        &remote_nic_get_state,
    12071206        &remote_nic_set_state,
  • uspace/lib/drv/include/ops/nic.h

    reaa0c3f rc38e417  
    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 *, nic_device_id_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/net/include/nil_remote.h

    reaa0c3f rc38e417  
    6262extern int nil_device_req(async_sess_t *, nic_device_id_t, devman_handle_t,
    6363    size_t);
    64 extern int nil_device_state_msg(async_sess_t *, nic_device_id_t, sysarg_t);
    65 extern int nil_received_msg(async_sess_t *, nic_device_id_t, void *, size_t);
    66 extern int nil_addr_changed_msg(async_sess_t *, nic_device_id_t,
    67     const nic_address_t *);
    6864
    6965#endif
  • uspace/lib/net/nil/nil_remote.c

    reaa0c3f rc38e417  
    4444#include <ipc/nil.h>
    4545
    46 /** Notify the network interface layer about the device state change.
    47  *
    48  * @param[in] sess      Network interface layer session.
    49  * @param[in] device_id Device identifier.
    50  * @param[in] state     New device state.
    51  *
    52  * @return EOK on success.
    53  * @return Other error codes as defined for each specific module
    54  *         device state function.
    55  *
    56  */
    57 int nil_device_state_msg(async_sess_t *sess, nic_device_id_t device_id,
    58     sysarg_t state)
    59 {
    60         return generic_device_state_msg_remote(sess, NET_NIL_DEVICE_STATE,
    61             device_id, state, 0);
    62 }
    63 
    64 /** Pass the packet queue to the network interface layer.
    65  *
    66  * Process and redistribute the received packet queue to the registered
    67  * upper layers.
    68  *
    69  * @param[in] sess      Network interface layer session.
    70  * @param[in] device_id Source device identifier.
    71  * @param[in] packet    Received packet or the received packet queue.
    72  * @param[in] target    Target service. Ignored parameter.
    73  *
    74  * @return EOK on success.
    75  * @return Other error codes as defined for each specific module
    76  *         received function.
    77  *
    78  */
    79 int nil_received_msg(async_sess_t *sess, nic_device_id_t device_id,
    80     void *data, size_t size)
    81 {
    82         async_exch_t *exch = async_exchange_begin(sess);
    83 
    84         ipc_call_t answer;
    85         aid_t req = async_send_1(exch, NET_NIL_RECEIVED, (sysarg_t) device_id,
    86             &answer);
    87         sysarg_t retval = async_data_write_start(exch, data, size);
    88 
    89         async_exchange_end(exch);
    90 
    91         if (retval != EOK) {
    92                 async_wait_for(req, NULL);
    93                 return retval;
    94         }
    95 
    96         async_wait_for(req, &retval);
    97         return retval;
    98 }
    99 
    100 /** Notify upper layers that device address has changed
    101  *
    102  */
    103 int nil_addr_changed_msg(async_sess_t *sess, nic_device_id_t device_id,
    104     const nic_address_t *address)
    105 {
    106         assert(sess);
    107        
    108         async_exch_t *exch = async_exchange_begin(sess);
    109        
    110         aid_t message_id = async_send_1(exch, NET_NIL_ADDR_CHANGED,
    111             (sysarg_t) device_id, NULL);
    112         int rc = async_data_write_start(exch, address, sizeof (nic_address_t));
    113        
    114         async_exchange_end(exch);
    115        
    116         sysarg_t res;
    117     async_wait_for(message_id, &res);
    118        
    119     if (rc != EOK)
    120                 return rc;
    121        
    122     return (int) res;
    123 }
    124 
    12546int nil_device_req(async_sess_t *sess, nic_device_id_t device_id,
    12647    service_id_t sid, size_t mtu)
  • uspace/lib/nic/Makefile

    reaa0c3f rc38e417  
    3434SOURCES = \
    3535        src/nic_driver.c \
     36        src/nic_ev.c \
    3637        src/nic_addr_db.c \
    3738        src/nic_rx_control.c \
  • uspace/lib/nic/include/nic_driver.h

    reaa0c3f rc38e417  
    8080        /** Device's default MAC address (assigned the first time, used in STOP) */
    8181        nic_address_t default_mac;
    82         /** Session to SERVICE_ETHERNET or SERVICE_NILDUMMY */
    83         async_sess_t *nil_session;
     82        /** Client callback session */
     83        async_sess_t *client_session;
    8484        /** Phone to APIC or i8259 */
    8585        async_sess_t *irc_session;
  • uspace/lib/nic/include/nic_impl.h

    reaa0c3f rc38e417  
    4949extern int nic_get_address_impl(ddf_fun_t *dev_fun, nic_address_t *address);
    5050extern 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);
     51extern int nic_callback_create_impl(ddf_fun_t *dev_fun, int device_id);
    5352extern int nic_get_state_impl(ddf_fun_t *dev_fun, nic_device_state_t *state);
    5453extern int nic_set_state_impl(ddf_fun_t *dev_fun, nic_device_state_t state);
  • uspace/lib/nic/src/nic_driver.c

    reaa0c3f rc38e417  
    5353
    5454#include "nic_driver.h"
     55#include "nic_ev.h"
    5556#include "nic_impl.h"
    5657
     
    106107                if (!iface->send_frame)
    107108                        iface->send_frame = nic_send_frame_impl;
    108                 if (!iface->connect_to_nil)
    109                         iface->connect_to_nil = nic_connect_to_nil_impl;
     109                if (!iface->callback_create)
     110                        iface->callback_create = nic_callback_create_impl;
    110111                if (!iface->get_address)
    111112                        iface->get_address = nic_get_address_impl;
     
    494495       
    495496        /* Notify NIL layer (and uppper) if bound - not in add_device */
    496         if (nic_data->nil_session != NULL) {
    497                 int rc = nil_addr_changed_msg(nic_data->nil_session,
     497        if (nic_data->client_session != NULL) {
     498                int rc = nic_ev_addr_changed(nic_data->client_session,
    498499                    nic_data->device_id, address);
    499500                if (rc != EOK) {
     
    603604                }
    604605                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    605                 nil_received_msg(nic_data->nil_session, nic_data->device_id,
     606                nic_ev_received(nic_data->client_session, nic_data->device_id,
    606607                    frame->data, frame->size);
    607608        } else {
     
    638639        fibril_rwlock_write_unlock(&nic_data->stats_lock);
    639640       
    640         nil_received_msg(nic_data->nil_session, nic_data->device_id,
     641        nic_ev_received(nic_data->client_session, nic_data->device_id,
    641642            data, size);
    642643}
     
    692693        nic_data->device_id = NIC_DEVICE_INVALID_ID;
    693694        nic_data->state = NIC_STATE_STOPPED;
    694         nic_data->nil_session = NULL;
     695        nic_data->client_session = NULL;
    695696        nic_data->irc_session = NULL;
    696697        nic_data->poll_mode = NIC_POLL_IMMEDIATE;
     
    746747 */
    747748static void nic_destroy(nic_t *nic_data) {
    748         if (nic_data->nil_session != NULL) {
    749                 async_hangup(nic_data->nil_session);
     749        if (nic_data->client_session != NULL) {
     750                async_hangup(nic_data->client_session);
    750751        }
    751752
  • uspace/lib/nic/src/nic_impl.c

    reaa0c3f rc38e417  
    4040#include <ns.h>
    4141#include "nic_driver.h"
     42#include "nic_ev.h"
    4243#include "nic_impl.h"
    4344
     
    8586        }
    8687        if (state == NIC_STATE_ACTIVE) {
    87                 if (nic_data->nil_session == NULL || nic_data->device_id < 0) {
     88                if (nic_data->client_session == NULL || nic_data->device_id < 0) {
    8889                        fibril_rwlock_write_unlock(&nic_data->main_lock);
    8990                        return EINVAL;
     
    115116        if (state == NIC_STATE_STOPPED) {
    116117                /* Notify upper layers that we are reseting the MAC */
    117                 int rc = nil_addr_changed_msg(nic_data->nil_session,
     118                int rc = nic_ev_addr_changed(nic_data->client_session,
    118119                        nic_data->device_id, &nic_data->default_mac);
    119120                nic_data->poll_mode = nic_data->default_poll_mode;
     
    148149        nic_data->state = state;
    149150
    150         nil_device_state_msg(nic_data->nil_session, nic_data->device_id, state);
     151        nic_ev_device_state(nic_data->client_session, nic_data->device_id, state);
    151152
    152153        fibril_rwlock_write_unlock(&nic_data->main_lock);
     
    181182
    182183/**
    183  * Default implementation of the connect_to_nil method.
    184  * Connects the driver to the NIL service.
     184 * Default implementation of the connect_client method.
     185 * Creates callback connection to the client.
    185186 *
    186187 * @param       fun
    187  * @param       nil_service     ID of the server implementing the NIL service
    188188 * @param       device_id       ID of the device as used in higher layers
    189189 *
    190  * @return EOK          If the services were bound
    191  * @return                      Negative error code from service_connect_blocking
    192  */
    193 int nic_connect_to_nil_impl(ddf_fun_t *fun, services_t nil_service,
    194     nic_device_id_t device_id)
    195 {
    196         nic_t *nic_data = (nic_t *) fun->driver_data;
    197         fibril_rwlock_write_lock(&nic_data->main_lock);
     190 * @return EOK          On success, or negative error code.
     191 */
     192int nic_callback_create_impl(ddf_fun_t *fun, nic_device_id_t device_id)
     193{
     194        nic_t *nic = (nic_t *) fun->driver_data;
     195        fibril_rwlock_write_lock(&nic->main_lock);
    198196       
    199         nic_data->device_id = device_id;
     197        nic->device_id = device_id;
    200198       
    201         nic_data->nil_session = service_connect_blocking(EXCHANGE_SERIALIZE,
    202             nil_service, 0, 0);
    203         if (nic_data->nil_session != NULL) {
    204                 fibril_rwlock_write_unlock(&nic_data->main_lock);
    205                 return EOK;
     199        nic->client_session = async_callback_receive(EXCHANGE_SERIALIZE);
     200        if (nic->client_session == NULL) {
     201                fibril_rwlock_write_unlock(&nic->main_lock);
     202                return ENOMEM;
    206203        }
    207204       
    208         fibril_rwlock_write_unlock(&nic_data->main_lock);
    209         return EHANGUP;
     205        fibril_rwlock_write_unlock(&nic->main_lock);
     206        return EOK;
    210207}
    211208
  • uspace/srv/net/net/net.c

    reaa0c3f rc38e417  
    22 * Copyright (c) 2009 Lukas Mejdrech
    33 * Copyright (c) 2011 Radim Vansa
     4 * Copyright (c) 2011 Jiri Svoboda
    45 * All rights reserved.
    56 *
     
    363364                break;
    364365        default:
     366                printf("%s: Unknown service\n", NAME);
    365367                return ENOENT;
    366368        }
  • uspace/srv/net/nil/eth/eth.c

    reaa0c3f rc38e417  
    170170INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    171171
    172 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
     172static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall,
     173    void *arg);
     174
     175static int eth_device_state(nic_device_id_t device_id, sysarg_t state)
    173176{
    174177        int index;
     
    344347        }
    345348       
    346         nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id);
     349        rc = nic_callback_create(device->sess, device_id,
     350            eth_nic_cb_connection, NULL);
     351        if (rc != EOK) {
     352                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     353                async_hangup(device->sess);
     354                free(device);
     355                return EIO;
     356        }
    347357       
    348358        /* Get hardware address */
     
    822832       
    823833        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
    824         if (rc != EOK)
     834        if (rc != EOK) {
     835                printf("%s: data_write_accept() failed\n", NAME);
    825836                return rc;
     837        }
    826838       
    827839        packet_t *packet = packet_get_1_remote(eth_globals.net_sess, size);
     
    943955               
    944956                return EOK;
    945         case NET_NIL_DEVICE_STATE:
    946                 nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call));
    947                 async_answer_0(callid, EOK);
    948                 return EOK;
    949         case NET_NIL_RECEIVED:
    950                 rc = eth_received(IPC_GET_ARG1(*call));
    951                 async_answer_0(callid, (sysarg_t) rc);
    952                 return rc;
    953         case NET_NIL_ADDR_CHANGED:
    954                 rc = eth_addr_changed(IPC_GET_DEVICE(*call));
    955                 async_answer_0(callid, (sysarg_t) rc);
    956                 return rc;
    957957        }
    958958       
    959959        return ENOTSUP;
     960}
     961
     962static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     963{
     964        int rc;
     965       
     966        async_answer_0(iid, EOK);
     967       
     968        while (true) {
     969                ipc_call_t call;
     970                ipc_callid_t callid = async_get_call(&call);
     971               
     972                if (!IPC_GET_IMETHOD(call))
     973                        break;
     974               
     975                switch (IPC_GET_IMETHOD(call)) {
     976                case NIC_EV_DEVICE_STATE:
     977                        rc = eth_device_state(IPC_GET_ARG1(call),
     978                            IPC_GET_ARG2(call));
     979                        async_answer_0(callid, (sysarg_t) rc);
     980                        break;
     981                case NIC_EV_RECEIVED:
     982                        rc = eth_received(IPC_GET_ARG1(call));
     983                        async_answer_0(callid, (sysarg_t) rc);
     984                        break;
     985                case NIC_EV_ADDR_CHANGED:
     986                        rc = eth_addr_changed(IPC_GET_ARG1(call));
     987                        async_answer_0(callid, (sysarg_t) rc);
     988                        break;
     989                default:
     990                        async_answer_0(callid, ENOTSUP);
     991                }
     992        }
    960993}
    961994
  • uspace/srv/net/nil/nildummy/nildummy.c

    reaa0c3f rc38e417  
    22 * Copyright (c) 2009 Lukas Mejdrech
    33 * Copyright (c) 2011 Radim Vansa
     4 * Copyright (c) 2011 Jiri Svoboda
    45 * All rights reserved.
    56 *
     
    6970DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
    7071
    71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
     72static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall,
     73    void *arg);
     74
     75static int nildummy_device_state(nic_device_id_t device_id, sysarg_t state)
    7276{
    7377        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
     
    7882       
    7983        return EOK;
     84}
     85
     86static int nildummy_addr_changed(nic_device_id_t device_id)
     87{
     88        return ENOTSUP;
    8089}
    8190
     
    173182        }
    174183       
    175         nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id);
     184        int rc = nic_callback_create(device->sess, device_id,
     185            nildummy_nic_cb_conn, NULL);
     186        if (rc != EOK) {
     187                async_hangup(device->sess);
     188               
     189                return ENOENT;
     190        }
    176191       
    177192        /* Get hardware address */
    178         int rc = nic_get_address(device->sess, &device->addr);
     193        rc = nic_get_address(device->sess, &device->addr);
    179194        if (rc != EOK) {
    180195                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    445460                *answer_count = 1;
    446461                return rc;
    447         case NET_NIL_DEVICE_STATE:
    448                 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call),
    449                     IPC_GET_STATE(*call));
    450                 async_answer_0(callid, (sysarg_t) rc);
    451                 return rc;
    452        
    453         case NET_NIL_RECEIVED:
    454                 rc = nildummy_received(IPC_GET_ARG1(*call));
    455                 async_answer_0(callid, (sysarg_t) rc);
    456                 return rc;
    457462        }
    458463       
    459464        return ENOTSUP;
    460465}
     466
     467static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     468{
     469        int rc;
     470       
     471        async_answer_0(iid, EOK);
     472       
     473        while (true) {
     474                ipc_call_t call;
     475                ipc_callid_t callid = async_get_call(&call);
     476               
     477                if (!IPC_GET_IMETHOD(call))
     478                        break;
     479               
     480                switch (IPC_GET_IMETHOD(call)) {
     481                case NIC_EV_DEVICE_STATE:
     482                        rc = nildummy_device_state(IPC_GET_ARG1(call),
     483                            IPC_GET_ARG2(call));
     484                        async_answer_0(callid, (sysarg_t) rc);
     485                        break;
     486                case NIC_EV_RECEIVED:
     487                        rc = nildummy_received(IPC_GET_ARG1(call));
     488                        async_answer_0(callid, (sysarg_t) rc);
     489                        break;
     490                case NIC_EV_ADDR_CHANGED:
     491                        rc = nildummy_addr_changed(IPC_GET_ARG1(call));
     492                        async_answer_0(callid, (sysarg_t) rc);
     493                        break;
     494                default:
     495                        async_answer_0(callid, ENOTSUP);
     496                }
     497        }
     498}
     499
    461500
    462501int main(int argc, char *argv[])
Note: See TracChangeset for help on using the changeset viewer.