Ignore:
File:
1 edited

Legend:

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

    r10a5479d r00d7e1b  
    22 * Copyright (c) 2009 Lukas Mejdrech
    33 * Copyright (c) 2011 Radim Vansa
    4  * Copyright (c) 2011 Jiri Svoboda
    54 * All rights reserved.
    65 *
     
    4241#include <stdio.h>
    4342#include <str.h>
     43#include <devman.h>
    4444#include <str_error.h>
    4545#include <ns.h>
     
    5656#include <adt/measured_strings.h>
    5757#include <adt/module_map.h>
    58 #include <fibril_synch.h>
    59 #include <loc.h>
    60 #include <nic.h>
    6158#include <nil_remote.h>
    6259#include <net_interface.h>
     
    7673GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
    7774DEVICE_MAP_IMPLEMENT(netifs, netif_t);
    78 LIST_INITIALIZE(netif_list);
    79 
    80 static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
    8175
    8276/** Add the configured setting to the configuration map.
     
    293287 *
    294288 */
    295 static int init_device(netif_t *netif, service_id_t sid)
     289static int init_device(netif_t *netif, devman_handle_t handle)
    296290{
    297291        printf("%s: Initializing device '%s'\n", NAME, netif->name);
    298292       
    299         netif->sid = sid;
    300         netif->sess = loc_service_connect(EXCHANGE_SERIALIZE, netif->sid,
     293        netif->handle = handle;
     294        netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle,
    301295            IPC_FLAG_BLOCKING);
    302296        if (netif->sess == NULL) {
     
    343337                    strtol((const char *) setting->value, NULL, 10) : 0;
    344338                rc = nil_device_req(netif->nil->sess, netif->id,
    345                     netif->sid, mtu);
     339                    netif->handle, mtu);
    346340                if (rc != EOK) {
    347341                        printf("%s: Unable to start network interface layer\n",
     
    365359                break;
    366360        default:
    367                 printf("%s: Unknown service\n", NAME);
    368361                return ENOENT;
    369362        }
    370363       
    371364        printf("%s: Activating device '%s'\n", NAME, netif->name);
    372         list_append(&netif->netif_list, &netif_list);
    373365        return nic_set_state(netif->sess, NIC_STATE_ACTIVE);
    374366}
    375367
    376 static int net_nic_ready(service_id_t sid)
    377 {
    378         int rc;
    379         char *hwpath;
    380        
    381         rc = loc_service_get_name(sid, &hwpath);
    382         if (rc != EOK) {
    383                 printf("%s: Failed getting name of service '%u'\n",
    384                     NAME, (unsigned) sid);
     368static int net_port_ready(devman_handle_t handle)
     369{
     370        char hwpath[MAX_PATH_LENGTH];
     371        int rc = devman_fun_get_path(handle, hwpath, MAX_PATH_LENGTH);
     372        if (rc != EOK)
    385373                return EINVAL;
    386         }
    387374       
    388375        int index = char_map_find(&net_globals.netif_hwpaths,
    389376            (uint8_t *) hwpath, 0);
    390        
    391         if (index == CHAR_MAP_NULL) {
    392                 printf("%s: Service '%s' not found in map.\n", NAME, hwpath);
    393                 free(hwpath);
     377        if (index == CHAR_MAP_NULL)
    394378                return ENOENT;
    395         }
    396        
    397         free(hwpath);
    398379       
    399380        netif_t *netif = netifs_get_index(&net_globals.netifs, index);
     
    401382                return ENOENT;
    402383       
    403         rc = init_device(netif, sid);
     384        rc = init_device(netif, handle);
    404385        if (rc != EOK)
    405386                return rc;
     
    410391       
    411392        netif->il->usage++;
     393       
     394        return EOK;
     395}
     396
     397static int net_driver_ready_local(devman_handle_t handle)
     398{
     399        devman_handle_t *funs;
     400        size_t count;
     401        int rc = devman_dev_get_functions(handle, &funs, &count);
     402        if (rc != EOK)
     403                return rc;
     404       
     405        for (size_t i = 0; i < count; i++) {
     406                rc = net_port_ready(funs[i]);
     407                if (rc != EOK)
     408                        return rc;
     409        }
    412410       
    413411        return EOK;
     
    481479                net_free_devices(strings, count);
    482480                return rc;
     481        case NET_NET_DRIVER_READY:
     482                rc = net_driver_ready_local(IPC_GET_ARG1(*call));
     483                *answer_count = 0;
     484                return rc;
    483485        default:
    484486                return ENOTSUP;
     
    526528                answer_call(callid, res, &answer, count);
    527529        }
    528 }
    529 
    530 static int nic_check_new(void)
    531 {
    532         category_id_t nic_cat;
    533         service_id_t *svcs;
    534         size_t count, i;
    535         bool already_known;
    536         int rc;
    537 
    538         fibril_mutex_lock(&discovery_lock);
    539 
    540         rc = loc_category_get_id(DEVICE_CATEGORY_NIC, &nic_cat, IPC_FLAG_BLOCKING);
    541         if (rc != EOK) {
    542                 printf("%s: Failed resolving category '%s'.\n", NAME,
    543                     DEVICE_CATEGORY_NIC);
    544                 return ENOENT;
    545         }
    546 
    547         rc = loc_category_get_svcs(nic_cat, &svcs, &count);
    548         if (rc != EOK) {
    549                 printf("%s: Failed getting list of NIC devices.\n", NAME);
    550                 return EIO;
    551         }
    552 
    553         for (i = 0; i < count; i++) {
    554                 already_known = false;
    555 
    556                 list_foreach(netif_list, link) {
    557                         netif_t *netif = list_get_instance(link, netif_t, netif_list);
    558                         if (netif->sid == svcs[i]) {
    559                                 already_known = true;
    560                                 break;
    561                         }
    562                 }
    563 
    564                 if (!already_known) {
    565                         rc = net_nic_ready(svcs[i]);
    566                         if (rc != EOK) {
    567                                 printf("%s: Failed adding NIC device #%u.\n",
    568                                     NAME, (unsigned) svcs[i]);
    569                         }
    570                 }
    571         }
    572 
    573         free(svcs);
    574         fibril_mutex_unlock(&discovery_lock);
    575         return EOK;
    576 }
    577 
    578 static void cat_change_cb(void)
    579 {
    580         (void) nic_check_new();
    581 }
    582 
    583 static int net_start_nic_discovery(void)
    584 {
    585         int rc;
    586 
    587         rc = loc_register_cat_change_cb(cat_change_cb);
    588         if (rc != EOK) {
    589                 printf("%s: Failed registering callback for device discovery (%d).\n",
    590                     NAME, rc);
    591                 return rc;
    592         }
    593 
    594         return nic_check_new();
    595530}
    596531
     
    638573                                continue;
    639574                       
    640                         netif->sid = -1;
     575                        netif->handle = -1;
    641576                        netif->sess = NULL;
    642577                       
     
    762697        }
    763698       
    764         rc = net_start_nic_discovery();
    765         if (rc != EOK) {
    766                 printf("%s: Error starting NIC discovery\n", NAME);
    767                 pm_destroy();
    768                 return rc;
    769         }
    770        
    771699        task_retval(0);
    772700        async_manager();
Note: See TracChangeset for help on using the changeset viewer.