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


Ignore:
Timestamp:
2011-07-12T03:00:14Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6817eba
Parents:
eca52a8 (diff), 026793d (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 mainline changes.

File:
1 edited

Legend:

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

    reca52a8 rf51f193  
    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  * @param[in] arg       Local argument.
     227 * @param[in]     iid   Message identifier.
     228 * @param[in,out] icall Message parameters.
     229 * @param[in]     arg   Local argument.
     230 *
    234231 */
    235232static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     
    241238                switch (IPC_GET_IMETHOD(*icall)) {
    242239                case NET_NIL_DEVICE_STATE:
    243                         nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall),
     240                        nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
    244241                            IPC_GET_STATE(*icall));
    245242                        async_answer_0(iid, EOK);
    246243                        break;
    247244                case NET_NIL_RECEIVED:
    248                         rc = packet_translate_remote(eth_globals.net_phone,
     245                        rc = packet_translate_remote(eth_globals.net_sess,
    249246                            &packet, IPC_GET_PACKET(*icall));
    250247                        if (rc == EOK)
    251                                 rc = nil_received_msg_local(0,
    252                                     IPC_GET_DEVICE(*icall), packet, 0);
     248                                rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
     249                                    packet, 0);
    253250                       
    254251                        async_answer_0(iid, (sysarg_t) rc);
     
    326323                        proto = eth_protos_get_index(&eth_globals.protos,
    327324                            index);
    328                         if (proto->phone) {
    329                                 il_mtu_changed_msg(proto->phone,
     325                        if (proto->sess) {
     326                                il_mtu_changed_msg(proto->sess,
    330327                                    device->device_id, device->mtu,
    331328                                    proto->service);
     
    351348
    352349        configuration = &names[0];
    353         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,
    354351            &configuration, count, &data);
    355352        if (rc != EOK) {
     
    380377       
    381378        /* Bind the device driver */
    382         device->phone = netif_bind_service(device->service, device->device_id,
     379        device->sess = netif_bind_service(device->service, device->device_id,
    383380            SERVICE_ETHERNET, eth_receiver);
    384         if (device->phone < 0) {
     381        if (device->sess == NULL) {
    385382                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    386383                free(device);
    387                 return device->phone;
     384                return ENOENT;
    388385        }
    389386       
    390387        /* Get hardware address */
    391         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,
    392389            &device->addr_data);
    393390        if (rc != EOK) {
     
    509506}
    510507
    511 int nil_received_msg_local(int nil_phone, device_id_t device_id,
    512     packet_t *packet, services_t target)
     508int nil_received_msg_local(device_id_t device_id, packet_t *packet,
     509    services_t target)
    513510{
    514511        eth_proto_t *proto;
     
    532529                proto = eth_process_packet(flags, packet);
    533530                if (proto) {
    534                         il_received_msg(proto->phone, device_id, packet,
     531                        il_received_msg(proto->sess, device_id, packet,
    535532                            proto->service);
    536533                } else {
    537534                        /* Drop invalid/unknown */
    538                         pq_release_remote(eth_globals.net_phone,
     535                        pq_release_remote(eth_globals.net_sess,
    539536                            packet_get_id(packet));
    540537                }
     
    615612}
    616613
    617 /** Registers receiving module service.
    618  *
    619  * Passes received packets for this service.
    620  *
    621  * @param[in] service   The module service.
    622  * @param[in] phone     The service phone.
    623  * @return              EOK on success.
    624  * @return              ENOENT if the service is not known.
    625  * @return              ENOMEM if there is not enough memory left.
    626  */
    627 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)
    628627{
    629628        eth_proto_t *proto;
     
    638637        proto = eth_protos_find(&eth_globals.protos, protocol);
    639638        if (proto) {
    640                 proto->phone = phone;
     639                proto->sess = sess;
    641640                fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    642641                return EOK;
     
    650649                proto->service = service;
    651650                proto->protocol = protocol;
    652                 proto->phone = phone;
     651                proto->sess = sess;
    653652
    654653                index = eth_protos_add(&eth_globals.protos, protocol, proto);
     
    660659        }
    661660       
    662         printf("%s: Protocol registered (protocol: %d, service: %d, phone: "
    663             "%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);
    664663       
    665664        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
     
    799798        ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
    800799        if (!ethertype) {
    801                 pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
     800                pq_release_remote(eth_globals.net_sess, packet_get_id(packet));
    802801                return EINVAL;
    803802        }
     
    820819                        if (next == packet)
    821820                                packet = tmp;
    822                         pq_release_remote(eth_globals.net_phone,
     821                        pq_release_remote(eth_globals.net_sess,
    823822                            packet_get_id(next));
    824823                        next = tmp;
     
    830829        /* Send packet queue */
    831830        if (packet) {
    832                 netif_send_msg(device->phone, device_id, packet,
     831                netif_send_msg(device->sess, device_id, packet,
    833832                    SERVICE_ETHERNET);
    834833        }
     
    854853                return EOK;
    855854       
     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       
    856860        switch (IPC_GET_IMETHOD(*call)) {
    857861        case NET_NIL_DEVICE:
     
    859863                    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
    860864        case NET_NIL_SEND:
    861                 rc = packet_translate_remote(eth_globals.net_phone, &packet,
     865                rc = packet_translate_remote(eth_globals.net_sess, &packet,
    862866                    IPC_GET_PACKET(*call));
    863867                if (rc != EOK)
     
    888892                        return EOK;
    889893                return measured_strings_reply(address, 1);
    890         case IPC_M_CONNECT_TO_ME:
    891                 return eth_register_message(NIL_GET_PROTO(*call),
    892                     IPC_GET_PHONE(*call));
    893894        }
    894895       
Note: See TracChangeset for help on using the changeset viewer.