Changeset 8d7ec69d in mainline for uspace/lib


Ignore:
Timestamp:
2012-01-22T10:40:07Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c38e417, cf9cb36
Parents:
e98fe28c
Message:

NIC should talk to its client via a callback connection with NIC-defined
protocol (was using nil, was connecting via NS).

Location:
uspace/lib
Files:
2 added
12 edited

Legend:

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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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

    re98fe28c r8d7ec69d  
    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
Note: See TracChangeset for help on using the changeset viewer.