Changeset 6b82009 in mainline for uspace/lib/net/netif


Ignore:
Timestamp:
2011-06-22T20:41:41Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ef09a7a
Parents:
55091847
Message:

networking stack: convert to the new async framework

Location:
uspace/lib/net/netif
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/netif/netif_remote.c

    r55091847 r6b82009  
    3838#include <packet_client.h>
    3939#include <generic.h>
    40 #include <async_obsolete.h>
    4140#include <ipc/services.h>
    4241#include <ipc/netif.h>
    43 
    4442#include <net/modules.h>
    4543#include <adt/measured_strings.h>
     
    4947/** Return the device local hardware address.
    5048 *
    51  * @param[in]  netif_phone Network interface phone.
    52  * @param[in]  device_id   Device identifier.
    53  * @param[out] address     Device local hardware address.
    54  * @param[out] data        Address data.
     49 * @param[in]  sess      Network interface session.
     50 * @param[in]  device_id Device identifier.
     51 * @param[out] address   Device local hardware address.
     52 * @param[out] data      Address data.
    5553 *
    5654 * @return EOK on success.
     
    6159 *
    6260 */
    63 int netif_get_addr_req(int netif_phone, device_id_t device_id,
     61int netif_get_addr_req(async_sess_t *sess, device_id_t device_id,
    6462    measured_string_t **address, uint8_t **data)
    6563{
    66         return generic_get_addr_req(netif_phone, NET_NETIF_GET_ADDR, device_id,
     64        return generic_get_addr_req(sess, NET_NETIF_GET_ADDR, device_id,
    6765            address, data);
    6866}
     
    7068/** Probe the existence of the device.
    7169 *
    72  * @param[in] netif_phone Network interface phone.
    73  * @param[in] device_id   Device identifier.
    74  * @param[in] irq         Device interrupt number.
    75  * @param[in] io          Device input/output address.
     70 * @param[in] sess      Network interface session.
     71 * @param[in] device_id Device identifier.
     72 * @param[in] irq       Device interrupt number.
     73 * @param[in] io        Device input/output address.
    7674 *
    7775 * @return EOK on success.
     
    8078 *
    8179 */
    82 int netif_probe_req(int netif_phone, device_id_t device_id, int irq, void *io)
     80int netif_probe_req(async_sess_t *sess, device_id_t device_id, int irq, void *io)
    8381{
    84         return async_obsolete_req_3_0(netif_phone, NET_NETIF_PROBE, device_id, irq,
     82        async_exch_t *exch = async_exchange_begin(sess);
     83        int rc = async_req_3_0(exch, NET_NETIF_PROBE, device_id, (sysarg_t) irq,
    8584            (sysarg_t) io);
     85        async_exchange_end(exch);
     86       
     87        return rc;
    8688}
    8789
    8890/** Send the packet queue.
    8991 *
    90  * @param[in] netif_phone Network interface phone.
    91  * @param[in] device_id   Device identifier.
    92  * @param[in] packet      Packet queue.
    93  * @param[in] sender      Sending module service.
     92 * @param[in] sess      Network interface session.
     93 * @param[in] device_id Device identifier.
     94 * @param[in] packet    Packet queue.
     95 * @param[in] sender    Sending module service.
    9496 *
    9597 * @return EOK on success.
     
    98100 *
    99101 */
    100 int netif_send_msg(int netif_phone, device_id_t device_id, packet_t *packet,
     102int netif_send_msg(async_sess_t *sess, device_id_t device_id, packet_t *packet,
    101103    services_t sender)
    102104{
    103         return generic_send_msg_remote(netif_phone, NET_NETIF_SEND, device_id,
     105        return generic_send_msg_remote(sess, NET_NETIF_SEND, device_id,
    104106            packet_get_id(packet), sender, 0);
    105107}
     
    107109/** Start the device.
    108110 *
    109  * @param[in] netif_phone Network interface phone.
    110  * @param[in] device_id   Device identifier.
     111 * @param[in] sess      Network interface session.
     112 * @param[in] device_id Device identifier.
    111113 *
    112114 * @return EOK on success.
     
    117119 *
    118120 */
    119 int netif_start_req(int netif_phone, device_id_t device_id)
     121int netif_start_req(async_sess_t *sess, device_id_t device_id)
    120122{
    121         return async_obsolete_req_1_0(netif_phone, NET_NETIF_START, device_id);
     123        async_exch_t *exch = async_exchange_begin(sess);
     124        int rc = async_req_1_0(exch, NET_NETIF_START, device_id);
     125        async_exchange_end(exch);
     126       
     127        return rc;
    122128}
    123129
    124130/** Stop the device.
    125131 *
    126  * @param[in] netif_phone Network interface phone.
    127  * @param[in] device_id   Device identifier.
     132 * @param[in] sess      Network interface session.
     133 * @param[in] device_id Device identifier.
    128134 *
    129135 * @return EOK on success.
     
    134140 *
    135141 */
    136 int netif_stop_req(int netif_phone, device_id_t device_id)
     142int netif_stop_req(async_sess_t *sess, device_id_t device_id)
    137143{
    138         return async_obsolete_req_1_0(netif_phone, NET_NETIF_STOP, device_id);
     144        async_exch_t *exch = async_exchange_begin(sess);
     145        int rc = async_req_1_0(exch, NET_NETIF_STOP, device_id);
     146        async_exchange_end(exch);
     147       
     148        return rc;
    139149}
    140150
    141151/** Return the device usage statistics.
    142152 *
    143  * @param[in] netif_phone Network interface phone.
    144  * @param[in] device_id  Device identifier.
    145  * @param[out] stats      Device usage statistics.
     153 * @param[in]  sess      Network interface session.
     154 * @param[in]  device_id Device identifier.
     155 * @param[out] stats     Device usage statistics.
    146156 *
    147157 * @return EOK on success.
    148158 *
    149159 */
    150 int netif_stats_req(int netif_phone, device_id_t device_id,
     160int netif_stats_req(async_sess_t *sess, device_id_t device_id,
    151161    device_stats_t *stats)
    152162{
     
    154164                return EBADMEM;
    155165       
    156         aid_t message_id = async_obsolete_send_1(netif_phone, NET_NETIF_STATS,
     166        async_exch_t *exch = async_exchange_begin(sess);
     167        aid_t message_id = async_send_1(exch, NET_NETIF_STATS,
    157168            (sysarg_t) device_id, NULL);
    158         async_obsolete_data_read_start(netif_phone, stats, sizeof(*stats));
     169        async_data_read_start(exch, stats, sizeof(*stats));
     170        async_exchange_end(exch);
    159171       
    160172        sysarg_t result;
     
    169181 * register the message receiver.
    170182 *
    171  * @param[in] service   The network interface module service.
    172  * @param[in] device_id The device identifier.
    173  * @param[in] me        The requesting module service.
    174  * @param[in] receiver  The message receiver.
     183 * @param[in] service   Network interface module service.
     184 * @param[in] device_id Device identifier.
     185 * @param[in] me        Requesting module service.
     186 * @param[in] receiver  Message receiver.
    175187 *
    176  * @return The phone of the needed service.
    177  * @return EOK on success.
    178  * @return Other error codes as defined for the bind_service()
    179  *         function.
     188 * @return Session to the needed service.
     189 * @return NULL on failure.
    180190 *
    181191 */
    182 int netif_bind_service(services_t service, device_id_t device_id,
     192async_sess_t *netif_bind_service(services_t service, device_id_t device_id,
    183193    services_t me, async_client_conn_t receiver)
    184194{
  • uspace/lib/net/netif/netif_skel.c

    r55091847 r6b82009  
    5454#include <nil_remote.h>
    5555
    56 // FIXME: remove this header
    57 #include <kernel/ipc/ipc_methods.h>
    58 
    5956DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t);
    6057
     
    6461/** Probe the existence of the device.
    6562 *
    66  * @param[in] netif_phone Network interface phone.
    6763 * @param[in] device_id   Device identifier.
    6864 * @param[in] irq         Device interrupt number.
     
    7470 *
    7571 */
    76 static int netif_probe_req_local(int netif_phone, device_id_t device_id,
    77     int irq, void *io)
     72static int netif_probe_req_local(device_id_t device_id, int irq, void *io)
    7873{
    7974        fibril_rwlock_write_lock(&netif_globals.lock);
     
    8681/** Send the packet queue.
    8782 *
    88  * @param[in] netif_phone Network interface phone.
    8983 * @param[in] device_id   Device identifier.
    9084 * @param[in] packet      Packet queue.
     
    9690 *
    9791 */
    98 static int netif_send_msg_local(int netif_phone, device_id_t device_id,
    99     packet_t *packet, services_t sender)
     92static int netif_send_msg_local(device_id_t device_id, packet_t *packet,
     93    services_t sender)
    10094{
    10195        fibril_rwlock_write_lock(&netif_globals.lock);
     
    108102/** Start the device.
    109103 *
    110  * @param[in] netif_phone Network interface phone.
    111104 * @param[in] device_id   Device identifier.
    112105 *
     
    118111 *
    119112 */
    120 static int netif_start_req_local(int netif_phone, device_id_t device_id)
     113static int netif_start_req_local(device_id_t device_id)
    121114{
    122115        fibril_rwlock_write_lock(&netif_globals.lock);
     
    131124        int result = netif_start_message(device);
    132125        if (result > NETIF_NULL) {
    133                 int phone = device->nil_phone;
    134                 nil_device_state_msg(phone, device_id, result);
     126                nil_device_state_msg(netif_globals.nil_sess, device_id, result);
    135127                fibril_rwlock_write_unlock(&netif_globals.lock);
    136128                return EOK;
     
    144136/** Stop the device.
    145137 *
    146  * @param[in] netif_phone Network interface phone.
    147138 * @param[in] device_id   Device identifier.
    148139 *
     
    154145 *
    155146 */
    156 static int netif_stop_req_local(int netif_phone, device_id_t device_id)
     147static int netif_stop_req_local(device_id_t device_id)
    157148{
    158149        fibril_rwlock_write_lock(&netif_globals.lock);
     
    167158        int result = netif_stop_message(device);
    168159        if (result > NETIF_NULL) {
    169                 int phone = device->nil_phone;
    170                 nil_device_state_msg(phone, device_id, result);
     160                nil_device_state_msg(netif_globals.nil_sess, device_id, result);
    171161                fibril_rwlock_write_unlock(&netif_globals.lock);
    172162                return EOK;
     
    222212void netif_pq_release(packet_id_t packet_id)
    223213{
    224         pq_release_remote(netif_globals.net_phone, packet_id);
     214        pq_release_remote(netif_globals.sess, packet_id);
    225215}
    226216
     
    235225packet_t *netif_packet_get_1(size_t content)
    236226{
    237         return packet_get_1_remote(netif_globals.net_phone, content);
    238 }
    239 
    240 /** Register the device notification receiver,
    241  *
    242  * Register a  network interface layer module as the device
    243  * notification receiver.
    244  *
    245  * @param[in] device_id Device identifier.
    246  * @param[in] phone     Network interface layer module phone.
    247  *
    248  * @return EOK on success.
    249  * @return ENOENT if there is no such device.
    250  * @return ELIMIT if there is another module registered.
    251  *
    252  */
    253 static int register_message(device_id_t device_id, int phone)
    254 {
    255         netif_device_t *device;
    256         int rc = find_device(device_id, &device);
    257         if (rc != EOK)
    258                 return rc;
    259        
    260         if (device->nil_phone >= 0)
    261                 return ELIMIT;
    262        
    263         device->nil_phone = phone;
    264         return EOK;
     227        return packet_get_1_remote(netif_globals.sess, content);
    265228}
    266229
     
    296259        switch (IPC_GET_IMETHOD(*call)) {
    297260        case NET_NETIF_PROBE:
    298                 return netif_probe_req_local(0, IPC_GET_DEVICE(*call),
     261                return netif_probe_req_local(IPC_GET_DEVICE(*call),
    299262                    NETIF_GET_IRQ(*call), NETIF_GET_IO(*call));
    300263       
    301         case IPC_M_CONNECT_TO_ME:
    302                 fibril_rwlock_write_lock(&netif_globals.lock);
    303                
    304                 rc = register_message(IPC_GET_DEVICE(*call), IPC_GET_PHONE(*call));
    305                
    306                 fibril_rwlock_write_unlock(&netif_globals.lock);
    307                 return rc;
    308        
    309264        case NET_NETIF_SEND:
    310                 rc = packet_translate_remote(netif_globals.net_phone, &packet,
     265                rc = packet_translate_remote(netif_globals.sess, &packet,
    311266                    IPC_GET_PACKET(*call));
    312267                if (rc != EOK)
    313268                        return rc;
    314269               
    315                 return netif_send_msg_local(0, IPC_GET_DEVICE(*call), packet,
     270                return netif_send_msg_local(IPC_GET_DEVICE(*call), packet,
    316271                    IPC_GET_SENDER(*call));
    317272       
    318273        case NET_NETIF_START:
    319                 return netif_start_req_local(0, IPC_GET_DEVICE(*call));
     274                return netif_start_req_local(IPC_GET_DEVICE(*call));
    320275       
    321276        case NET_NETIF_STATS:
     
    343298       
    344299        case NET_NETIF_STOP:
    345                 return netif_stop_req_local(0, IPC_GET_DEVICE(*call));
     300                return netif_stop_req_local(IPC_GET_DEVICE(*call));
    346301       
    347302        case NET_NETIF_GET_ADDR:
     
    403358 * messages in an infinite loop.
    404359 *
     360 * @param[in] nil_service Network interface layer service.
     361 *
    405362 * @return EOK on success.
    406363 * @return Other error codes as defined for each specific module
     
    408365 *
    409366 */
    410 int netif_module_start(void)
     367int netif_module_start(sysarg_t nil_service)
    411368{
    412369        async_set_client_connection(netif_client_connection);
    413370       
    414         netif_globals.net_phone = connect_to_service(SERVICE_NETWORKING);
     371        netif_globals.sess = connect_to_service(SERVICE_NETWORKING);
     372        netif_globals.nil_sess = connect_to_service(nil_service);
    415373        netif_device_map_initialize(&netif_globals.device_map);
    416374       
Note: See TracChangeset for help on using the changeset viewer.