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


Ignore:
Timestamp:
2011-07-08T17:01:01Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cc1a727
Parents:
4e36219 (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

    r4e36219 rc028b22  
    5959#include <packet_remote.h>
    6060#include <nil_skel.h>
    61 
    6261#include "eth.h"
    6362
     
    168167INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    169168
    170 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)
    171170{
    172171        int index;
     
    177176            index--) {
    178177                proto = eth_protos_get_index(&eth_globals.protos, index);
    179                 if (proto && proto->phone) {
    180                         il_device_state_msg(proto->phone, device_id, state,
     178                if ((proto) && (proto->sess)) {
     179                        il_device_state_msg(proto->sess, device_id, state,
    181180                            proto->service);
    182181                }
     
    187186}
    188187
    189 int nil_initialize(int net_phone)
     188int nil_initialize(async_sess_t *sess)
    190189{
    191190        int rc;
     
    196195        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    197196        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    198         eth_globals.net_phone = net_phone;
     197        eth_globals.net_sess = sess;
    199198
    200199        eth_globals.broadcast_addr =
     
    223222}
    224223
    225 /** Processes IPC messages from the registered device driver modules in an
     224/** Process IPC messages from the registered device driver modules in an
    226225 * infinite loop.
    227226 *
    228  * @param[in] iid       The message identifier.
    229  * @param[in,out] icall The message parameters.
    230  */
    231 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)
    232233{
    233234        packet_t *packet;
     
    237238                switch (IPC_GET_IMETHOD(*icall)) {
    238239                case NET_NIL_DEVICE_STATE:
    239                         nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall),
     240                        nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
    240241                            IPC_GET_STATE(*icall));
    241242                        async_answer_0(iid, EOK);
    242243                        break;
    243244                case NET_NIL_RECEIVED:
    244                         rc = packet_translate_remote(eth_globals.net_phone,
     245                        rc = packet_translate_remote(eth_globals.net_sess,
    245246                            &packet, IPC_GET_PACKET(*icall));
    246247                        if (rc == EOK)
    247                                 rc = nil_received_msg_local(0,
    248                                     IPC_GET_DEVICE(*icall), packet, 0);
     248                                rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
     249                                    packet, 0);
    249250                       
    250251                        async_answer_0(iid, (sysarg_t) rc);
     
    322323                        proto = eth_protos_get_index(&eth_globals.protos,
    323324                            index);
    324                         if (proto->phone) {
    325                                 il_mtu_changed_msg(proto->phone,
     325                        if (proto->sess) {
     326                                il_mtu_changed_msg(proto->sess,
    326327                                    device->device_id, device->mtu,
    327328                                    proto->service);
     
    347348
    348349        configuration = &names[0];
    349         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,
    350351            &configuration, count, &data);
    351352        if (rc != EOK) {
     
    376377       
    377378        /* Bind the device driver */
    378         device->phone = netif_bind_service(device->service, device->device_id,
     379        device->sess = netif_bind_service(device->service, device->device_id,
    379380            SERVICE_ETHERNET, eth_receiver);
    380         if (device->phone < 0) {
     381        if (device->sess == NULL) {
    381382                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    382383                free(device);
    383                 return device->phone;
     384                return ENOENT;
    384385        }
    385386       
    386387        /* Get hardware address */
    387         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,
    388389            &device->addr_data);
    389390        if (rc != EOK) {
     
    505506}
    506507
    507 int nil_received_msg_local(int nil_phone, device_id_t device_id,
    508     packet_t *packet, services_t target)
     508int nil_received_msg_local(device_id_t device_id, packet_t *packet,
     509    services_t target)
    509510{
    510511        eth_proto_t *proto;
     
    528529                proto = eth_process_packet(flags, packet);
    529530                if (proto) {
    530                         il_received_msg(proto->phone, device_id, packet,
     531                        il_received_msg(proto->sess, device_id, packet,
    531532                            proto->service);
    532533                } else {
    533534                        /* Drop invalid/unknown */
    534                         pq_release_remote(eth_globals.net_phone,
     535                        pq_release_remote(eth_globals.net_sess,
    535536                            packet_get_id(packet));
    536537                }
     
    611612}
    612613
    613 /** Registers receiving module service.
    614  *
    615  * Passes received packets for this service.
    616  *
    617  * @param[in] service   The module service.
    618  * @param[in] phone     The service phone.
    619  * @return              EOK on success.
    620  * @return              ENOENT if the service is not known.
    621  * @return              ENOMEM if there is not enough memory left.
    622  */
    623 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)
    624627{
    625628        eth_proto_t *proto;
     
    634637        proto = eth_protos_find(&eth_globals.protos, protocol);
    635638        if (proto) {
    636                 proto->phone = phone;
     639                proto->sess = sess;
    637640                fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    638641                return EOK;
     
    646649                proto->service = service;
    647650                proto->protocol = protocol;
    648                 proto->phone = phone;
     651                proto->sess = sess;
    649652
    650653                index = eth_protos_add(&eth_globals.protos, protocol, proto);
     
    656659        }
    657660       
    658         printf("%s: Protocol registered (protocol: %d, service: %d, phone: "
    659             "%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);
    660663       
    661664        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
     
    795798        ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
    796799        if (!ethertype) {
    797                 pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
     800                pq_release_remote(eth_globals.net_sess, packet_get_id(packet));
    798801                return EINVAL;
    799802        }
     
    816819                        if (next == packet)
    817820                                packet = tmp;
    818                         pq_release_remote(eth_globals.net_phone,
     821                        pq_release_remote(eth_globals.net_sess,
    819822                            packet_get_id(next));
    820823                        next = tmp;
     
    826829        /* Send packet queue */
    827830        if (packet) {
    828                 netif_send_msg(device->phone, device_id, packet,
     831                netif_send_msg(device->sess, device_id, packet,
    829832                    SERVICE_ETHERNET);
    830833        }
     
    846849       
    847850        *answer_count = 0;
     851       
     852        if (!IPC_GET_IMETHOD(*call))
     853                return EOK;
     854       
     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       
    848860        switch (IPC_GET_IMETHOD(*call)) {
    849         case IPC_M_PHONE_HUNGUP:
    850                 return EOK;
    851        
    852861        case NET_NIL_DEVICE:
    853862                return eth_device_message(IPC_GET_DEVICE(*call),
    854863                    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
    855864        case NET_NIL_SEND:
    856                 rc = packet_translate_remote(eth_globals.net_phone, &packet,
     865                rc = packet_translate_remote(eth_globals.net_sess, &packet,
    857866                    IPC_GET_PACKET(*call));
    858867                if (rc != EOK)
     
    883892                        return EOK;
    884893                return measured_strings_reply(address, 1);
    885         case IPC_M_CONNECT_TO_ME:
    886                 return eth_register_message(NIL_GET_PROTO(*call),
    887                     IPC_GET_PHONE(*call));
    888894        }
    889895       
Note: See TracChangeset for help on using the changeset viewer.