Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/nil/eth/eth.c

    r6b82009 r79ae36dd  
    5959#include <packet_remote.h>
    6060#include <nil_skel.h>
     61
     62// FIXME: remove this header
     63#include <kernel/ipc/ipc_methods.h>
     64
    6165#include "eth.h"
    6266
     
    167171INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    168172
    169 int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
     173int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
    170174{
    171175        int index;
     
    176180            index--) {
    177181                proto = eth_protos_get_index(&eth_globals.protos, index);
    178                 if ((proto) && (proto->sess)) {
    179                         il_device_state_msg(proto->sess, device_id, state,
     182                if (proto && proto->phone) {
     183                        il_device_state_msg(proto->phone, device_id, state,
    180184                            proto->service);
    181185                }
     
    186190}
    187191
    188 int nil_initialize(async_sess_t *sess)
     192int nil_initialize(int net_phone)
    189193{
    190194        int rc;
     
    195199        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    196200        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    197         eth_globals.net_sess = sess;
     201        eth_globals.net_phone = net_phone;
    198202
    199203        eth_globals.broadcast_addr =
     
    222226}
    223227
    224 /** Process IPC messages from the registered device driver modules in an
     228/** Processes IPC messages from the registered device driver modules in an
    225229 * infinite loop.
    226230 *
    227  * @param[in]     iid   Message identifier.
    228  * @param[in,out] icall Message parameters.
    229  * @param[in]     arg   Local argument.
    230  *
    231  */
    232 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     231 * @param[in] iid       The message identifier.
     232 * @param[in,out] icall The message parameters.
     233 */
     234static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall)
    233235{
    234236        packet_t *packet;
     
    238240                switch (IPC_GET_IMETHOD(*icall)) {
    239241                case NET_NIL_DEVICE_STATE:
    240                         nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
     242                        nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall),
    241243                            IPC_GET_STATE(*icall));
    242244                        async_answer_0(iid, EOK);
    243245                        break;
    244246                case NET_NIL_RECEIVED:
    245                         rc = packet_translate_remote(eth_globals.net_sess,
     247                        rc = packet_translate_remote(eth_globals.net_phone,
    246248                            &packet, IPC_GET_PACKET(*icall));
    247249                        if (rc == EOK)
    248                                 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
    249                                     packet, 0);
     250                                rc = nil_received_msg_local(0,
     251                                    IPC_GET_DEVICE(*icall), packet, 0);
    250252                       
    251253                        async_answer_0(iid, (sysarg_t) rc);
     
    323325                        proto = eth_protos_get_index(&eth_globals.protos,
    324326                            index);
    325                         if (proto->sess) {
    326                                 il_mtu_changed_msg(proto->sess,
     327                        if (proto->phone) {
     328                                il_mtu_changed_msg(proto->phone,
    327329                                    device->device_id, device->mtu,
    328330                                    proto->service);
     
    348350
    349351        configuration = &names[0];
    350         rc = net_get_device_conf_req(eth_globals.net_sess, device->device_id,
     352        rc = net_get_device_conf_req(eth_globals.net_phone, device->device_id,
    351353            &configuration, count, &data);
    352354        if (rc != EOK) {
     
    377379       
    378380        /* Bind the device driver */
    379         device->sess = netif_bind_service(device->service, device->device_id,
     381        device->phone = netif_bind_service(device->service, device->device_id,
    380382            SERVICE_ETHERNET, eth_receiver);
    381         if (device->sess == NULL) {
     383        if (device->phone < 0) {
    382384                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    383385                free(device);
    384                 return ENOENT;
     386                return device->phone;
    385387        }
    386388       
    387389        /* Get hardware address */
    388         rc = netif_get_addr_req(device->sess, device->device_id, &device->addr,
     390        rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    389391            &device->addr_data);
    390392        if (rc != EOK) {
     
    506508}
    507509
    508 int nil_received_msg_local(device_id_t device_id, packet_t *packet,
    509     services_t target)
     510int nil_received_msg_local(int nil_phone, device_id_t device_id,
     511    packet_t *packet, services_t target)
    510512{
    511513        eth_proto_t *proto;
     
    529531                proto = eth_process_packet(flags, packet);
    530532                if (proto) {
    531                         il_received_msg(proto->sess, device_id, packet,
     533                        il_received_msg(proto->phone, device_id, packet,
    532534                            proto->service);
    533535                } else {
    534536                        /* Drop invalid/unknown */
    535                         pq_release_remote(eth_globals.net_sess,
     537                        pq_release_remote(eth_globals.net_phone,
    536538                            packet_get_id(packet));
    537539                }
     
    612614}
    613615
    614 /** Register receiving module service.
    615  *
    616  * Pass received packets for this service.
    617  *
    618  * @param[in] service Module service.
    619  * @param[in] sess    Service session.
    620  *
    621  * @return EOK on success.
    622  * @return ENOENT if the service is not known.
    623  * @return ENOMEM if there is not enough memory left.
    624  *
    625  */
    626 static int eth_register_message(services_t service, async_sess_t *sess)
     616/** Registers receiving module service.
     617 *
     618 * Passes received packets for this service.
     619 *
     620 * @param[in] service   The module service.
     621 * @param[in] phone     The service phone.
     622 * @return              EOK on success.
     623 * @return              ENOENT if the service is not known.
     624 * @return              ENOMEM if there is not enough memory left.
     625 */
     626static int eth_register_message(services_t service, int phone)
    627627{
    628628        eth_proto_t *proto;
     
    637637        proto = eth_protos_find(&eth_globals.protos, protocol);
    638638        if (proto) {
    639                 proto->sess = sess;
     639                proto->phone = phone;
    640640                fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    641641                return EOK;
     
    649649                proto->service = service;
    650650                proto->protocol = protocol;
    651                 proto->sess = sess;
     651                proto->phone = phone;
    652652
    653653                index = eth_protos_add(&eth_globals.protos, protocol, proto);
     
    659659        }
    660660       
    661         printf("%s: Protocol registered (protocol: %d, service: %d)\n",
    662             NAME, proto->protocol, proto->service);
     661        printf("%s: Protocol registered (protocol: %d, service: %d, phone: "
     662            "%d)\n", NAME, proto->protocol, proto->service, proto->phone);
    663663       
    664664        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
     
    798798        ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
    799799        if (!ethertype) {
    800                 pq_release_remote(eth_globals.net_sess, packet_get_id(packet));
     800                pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
    801801                return EINVAL;
    802802        }
     
    819819                        if (next == packet)
    820820                                packet = tmp;
    821                         pq_release_remote(eth_globals.net_sess,
     821                        pq_release_remote(eth_globals.net_phone,
    822822                            packet_get_id(next));
    823823                        next = tmp;
     
    829829        /* Send packet queue */
    830830        if (packet) {
    831                 netif_send_msg(device->sess, device_id, packet,
     831                netif_send_msg(device->phone, device_id, packet,
    832832                    SERVICE_ETHERNET);
    833833        }
     
    853853                return EOK;
    854854       
    855         async_sess_t *callback =
    856             async_callback_receive_start(EXCHANGE_SERIALIZE, call);
    857         if (callback)
    858                 return eth_register_message(NIL_GET_PROTO(*call), callback);
    859        
    860855        switch (IPC_GET_IMETHOD(*call)) {
    861856        case NET_NIL_DEVICE:
     
    863858                    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
    864859        case NET_NIL_SEND:
    865                 rc = packet_translate_remote(eth_globals.net_sess, &packet,
     860                rc = packet_translate_remote(eth_globals.net_phone, &packet,
    866861                    IPC_GET_PACKET(*call));
    867862                if (rc != EOK)
     
    892887                        return EOK;
    893888                return measured_strings_reply(address, 1);
     889        case IPC_M_CONNECT_TO_ME:
     890                return eth_register_message(NIL_GET_PROTO(*call),
     891                    IPC_GET_PHONE(*call));
    894892        }
    895893       
Note: See TracChangeset for help on using the changeset viewer.