Changeset e4f8c77 in mainline for uspace/srv/net/nil/eth/eth.c


Ignore:
Timestamp:
2011-07-13T22:39:18Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e6910c8
Parents:
5974661 (diff), 8ecef91 (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 libposix.

File:
1 edited

Legend:

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

    r5974661 re4f8c77  
    5959#include <packet_remote.h>
    6060#include <nil_skel.h>
    61 
    62 // FIXME: remove this header
    63 #include <kernel/ipc/ipc_methods.h>
    64 
    6561#include "eth.h"
    6662
     
    171167INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    172168
    173 int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
     169int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
    174170{
    175171        int index;
     
    180176            index--) {
    181177                proto = eth_protos_get_index(&eth_globals.protos, index);
    182                 if (proto && proto->phone) {
    183                         il_device_state_msg(proto->phone, device_id, state,
     178                if ((proto) && (proto->sess)) {
     179                        il_device_state_msg(proto->sess, device_id, state,
    184180                            proto->service);
    185181                }
     
    190186}
    191187
    192 int nil_initialize(int net_phone)
     188int nil_initialize(async_sess_t *sess)
    193189{
    194190        int rc;
     
    199195        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    200196        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    201         eth_globals.net_phone = net_phone;
     197        eth_globals.net_sess = sess;
    202198
    203199        eth_globals.broadcast_addr =
     
    226222}
    227223
    228 /** Processes IPC messages from the registered device driver modules in an
     224/** Process IPC messages from the registered device driver modules in an
    229225 * infinite loop.
    230226 *
    231  * @param[in] iid       The message identifier.
    232  * @param[in,out] icall The message parameters.
    233  */
    234 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall)
     227 * @param[in]     iid   Message identifier.
     228 * @param[in,out] icall Message parameters.
     229 * @param[in]     arg   Local argument.
     230 *
     231 */
     232static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    235233{
    236234        packet_t *packet;
     
    240238                switch (IPC_GET_IMETHOD(*icall)) {
    241239                case NET_NIL_DEVICE_STATE:
    242                         nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall),
     240                        nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
    243241                            IPC_GET_STATE(*icall));
    244242                        async_answer_0(iid, EOK);
    245243                        break;
    246244                case NET_NIL_RECEIVED:
    247                         rc = packet_translate_remote(eth_globals.net_phone,
     245                        rc = packet_translate_remote(eth_globals.net_sess,
    248246                            &packet, IPC_GET_PACKET(*icall));
    249247                        if (rc == EOK)
    250                                 rc = nil_received_msg_local(0,
    251                                     IPC_GET_DEVICE(*icall), packet, 0);
     248                                rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
     249                                    packet, 0);
    252250                       
    253251                        async_answer_0(iid, (sysarg_t) rc);
     
    325323                        proto = eth_protos_get_index(&eth_globals.protos,
    326324                            index);
    327                         if (proto->phone) {
    328                                 il_mtu_changed_msg(proto->phone,
     325                        if (proto->sess) {
     326                                il_mtu_changed_msg(proto->sess,
    329327                                    device->device_id, device->mtu,
    330328                                    proto->service);
     
    350348
    351349        configuration = &names[0];
    352         rc = net_get_device_conf_req(eth_globals.net_phone, device->device_id,
     350        rc = net_get_device_conf_req(eth_globals.net_sess, device->device_id,
    353351            &configuration, count, &data);
    354352        if (rc != EOK) {
     
    379377       
    380378        /* Bind the device driver */
    381         device->phone = netif_bind_service(device->service, device->device_id,
     379        device->sess = netif_bind_service(device->service, device->device_id,
    382380            SERVICE_ETHERNET, eth_receiver);
    383         if (device->phone < 0) {
     381        if (device->sess == NULL) {
    384382                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    385383                free(device);
    386                 return device->phone;
     384                return ENOENT;
    387385        }
    388386       
    389387        /* Get hardware address */
    390         rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
     388        rc = netif_get_addr_req(device->sess, device->device_id, &device->addr,
    391389            &device->addr_data);
    392390        if (rc != EOK) {
     
    508506}
    509507
    510 int nil_received_msg_local(int nil_phone, device_id_t device_id,
    511     packet_t *packet, services_t target)
     508int nil_received_msg_local(device_id_t device_id, packet_t *packet,
     509    services_t target)
    512510{
    513511        eth_proto_t *proto;
     
    531529                proto = eth_process_packet(flags, packet);
    532530                if (proto) {
    533                         il_received_msg(proto->phone, device_id, packet,
     531                        il_received_msg(proto->sess, device_id, packet,
    534532                            proto->service);
    535533                } else {
    536534                        /* Drop invalid/unknown */
    537                         pq_release_remote(eth_globals.net_phone,
     535                        pq_release_remote(eth_globals.net_sess,
    538536                            packet_get_id(packet));
    539537                }
     
    614612}
    615613
    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  */
    626 static int eth_register_message(services_t service, int phone)
     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 */
     626static int eth_register_message(services_t service, async_sess_t *sess)
    627627{
    628628        eth_proto_t *proto;
     
    637637        proto = eth_protos_find(&eth_globals.protos, protocol);
    638638        if (proto) {
    639                 proto->phone = phone;
     639                proto->sess = sess;
    640640                fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    641641                return EOK;
     
    649649                proto->service = service;
    650650                proto->protocol = protocol;
    651                 proto->phone = phone;
     651                proto->sess = sess;
    652652
    653653                index = eth_protos_add(&eth_globals.protos, protocol, proto);
     
    659659        }
    660660       
    661         printf("%s: Protocol registered (protocol: %d, service: %d, phone: "
    662             "%d)\n", NAME, proto->protocol, proto->service, proto->phone);
     661        printf("%s: Protocol registered (protocol: %d, service: %d)\n",
     662            NAME, proto->protocol, proto->service);
    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_phone, packet_get_id(packet));
     800                pq_release_remote(eth_globals.net_sess, packet_get_id(packet));
    801801                return EINVAL;
    802802        }
     
    819819                        if (next == packet)
    820820                                packet = tmp;
    821                         pq_release_remote(eth_globals.net_phone,
     821                        pq_release_remote(eth_globals.net_sess,
    822822                            packet_get_id(next));
    823823                        next = tmp;
     
    829829        /* Send packet queue */
    830830        if (packet) {
    831                 netif_send_msg(device->phone, device_id, packet,
     831                netif_send_msg(device->sess, 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       
    855860        switch (IPC_GET_IMETHOD(*call)) {
    856861        case NET_NIL_DEVICE:
     
    858863                    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
    859864        case NET_NIL_SEND:
    860                 rc = packet_translate_remote(eth_globals.net_phone, &packet,
     865                rc = packet_translate_remote(eth_globals.net_sess, &packet,
    861866                    IPC_GET_PACKET(*call));
    862867                if (rc != EOK)
     
    887892                        return EOK;
    888893                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));
    892894        }
    893895       
Note: See TracChangeset for help on using the changeset viewer.