Changeset 77a69ea in mainline for uspace/srv/net
- Timestamp:
- 2012-01-21T15:06:51Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ce7676c
- Parents:
- e86b8f0
- Location:
- uspace/srv/net
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/cfg/e1k.nic
re86b8f0 r77a69ea 3 3 NAME=e1k 4 4 5 HWPATH= /hw/pci0/00:03.0/port05 HWPATH=devices/\hw\pci0\00:03.0\port0 6 6 NIL=eth 7 7 IL=ip -
uspace/srv/net/cfg/lo.nic
re86b8f0 r77a69ea 3 3 NAME=lo 4 4 5 HWPATH= /virt/lo/port05 HWPATH=devices/\virt\lo\port0 6 6 NIL=nildummy 7 7 IL=ip -
uspace/srv/net/cfg/ne2k.nic
re86b8f0 r77a69ea 3 3 NAME=ne2k 4 4 5 HWPATH= /hw/pci0/00:01.0/ne2k/port05 HWPATH=devices/\hw\pci0\00:01.0\ne2k\port0 6 6 NIL=eth 7 7 IL=ip -
uspace/srv/net/net/Makefile
re86b8f0 r77a69ea 31 31 ROOT_PATH = $(USPACE_PREFIX)/.. 32 32 LIBS = $(LIBNET_PREFIX)/libnet.a 33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include 33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBNIC_PREFIX)/include \ 34 -I$(LIBDRV_PREFIX)/include 34 35 35 36 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common -
uspace/srv/net/net/net.c
re86b8f0 r77a69ea 41 41 #include <stdio.h> 42 42 #include <str.h> 43 #include <devman.h>44 43 #include <str_error.h> 45 44 #include <ns.h> … … 56 55 #include <adt/measured_strings.h> 57 56 #include <adt/module_map.h> 57 #include <loc.h> 58 #include <nic.h> 58 59 #include <nil_remote.h> 59 60 #include <net_interface.h> … … 73 74 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t); 74 75 DEVICE_MAP_IMPLEMENT(netifs, netif_t); 76 LIST_INITIALIZE(netif_list); 75 77 76 78 /** Add the configured setting to the configuration map. … … 287 289 * 288 290 */ 289 static int init_device(netif_t *netif, devman_handle_t handle)291 static int init_device(netif_t *netif, service_id_t sid) 290 292 { 291 293 printf("%s: Initializing device '%s'\n", NAME, netif->name); 292 294 293 netif->handle = handle; 294 netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle, 295 link_initialize(&netif->netif_list); 296 297 netif->sid = sid; 298 netif->sess = loc_service_connect(EXCHANGE_SERIALIZE, netif->sid, 295 299 IPC_FLAG_BLOCKING); 296 300 if (netif->sess == NULL) { … … 337 341 strtol((const char *) setting->value, NULL, 10) : 0; 338 342 rc = nil_device_req(netif->nil->sess, netif->id, 339 netif-> handle, mtu);343 netif->sid, mtu); 340 344 if (rc != EOK) { 341 345 printf("%s: Unable to start network interface layer\n", … … 363 367 364 368 printf("%s: Activating device '%s'\n", NAME, netif->name); 369 list_append(&netif->netif_list, &netif_list); 365 370 return nic_set_state(netif->sess, NIC_STATE_ACTIVE); 366 371 } 367 372 368 static 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) 373 static int net_nic_ready(service_id_t sid) 374 { 375 int rc; 376 char *hwpath; 377 378 rc = loc_service_get_name(sid, &hwpath); 379 if (rc != EOK) { 380 printf("%s: Failed getting name of service '%u'\n", 381 NAME, (unsigned) sid); 373 382 return EINVAL; 383 } 374 384 375 385 int index = char_map_find(&net_globals.netif_hwpaths, 376 386 (uint8_t *) hwpath, 0); 377 if (index == CHAR_MAP_NULL) 387 388 if (index == CHAR_MAP_NULL) { 389 printf("%s: Service '%s' not found in map.\n", NAME, hwpath); 390 free(hwpath); 378 391 return ENOENT; 392 } 393 394 free(hwpath); 379 395 380 396 netif_t *netif = netifs_get_index(&net_globals.netifs, index); … … 382 398 return ENOENT; 383 399 384 rc = init_device(netif, handle);400 rc = init_device(netif, sid); 385 401 if (rc != EOK) 386 402 return rc; … … 391 407 392 408 netif->il->usage++; 393 394 return EOK;395 }396 397 static 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 }410 409 411 410 return EOK; … … 479 478 net_free_devices(strings, count); 480 479 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;485 480 default: 486 481 return ENOTSUP; … … 528 523 answer_call(callid, res, &answer, count); 529 524 } 525 } 526 527 static int nic_check_new(void) 528 { 529 category_id_t nic_cat; 530 service_id_t *svcs; 531 size_t count, i; 532 bool already_known; 533 int rc; 534 535 rc = loc_category_get_id(DEVICE_CATEGORY_NIC, &nic_cat, IPC_FLAG_BLOCKING); 536 if (rc != EOK) { 537 printf("%s: Failed resolving category '%s'.\n", NAME, 538 DEVICE_CATEGORY_NIC); 539 return ENOENT; 540 } 541 542 rc = loc_category_get_svcs(nic_cat, &svcs, &count); 543 if (rc != EOK) { 544 printf("%s: Failed getting list of NIC devices.\n", NAME); 545 return EIO; 546 } 547 548 for (i = 0; i < count; i++) { 549 already_known = false; 550 551 list_foreach(netif_list, link) { 552 netif_t *netif = list_get_instance(link, netif_t, netif_list); 553 if (netif->sid == svcs[i]) { 554 already_known = true; 555 break; 556 } 557 } 558 559 if (!already_known) { 560 rc = net_nic_ready(svcs[i]); 561 if (rc != EOK) { 562 printf("%s: Failed adding NIC device #%u.\n", 563 NAME, (unsigned) svcs[i]); 564 } 565 } 566 } 567 568 free(svcs); 569 return EOK; 570 } 571 572 static void cat_change_cb(void) 573 { 574 (void) nic_check_new(); 575 } 576 577 static int net_start_nic_discovery(void) 578 { 579 int rc; 580 581 rc = loc_register_cat_change_cb(cat_change_cb); 582 if (rc != EOK) { 583 printf("%s: Failed registering callback for device discovery (%d).\n", 584 NAME, rc); 585 return rc; 586 } 587 588 return nic_check_new(); 530 589 } 531 590 … … 573 632 continue; 574 633 575 netif-> handle= -1;634 netif->sid = -1; 576 635 netif->sess = NULL; 577 636 … … 697 756 } 698 757 758 rc = net_start_nic_discovery(); 759 if (rc != EOK) { 760 printf("%s: Error starting NIC discovery\n", NAME); 761 pm_destroy(); 762 return rc; 763 } 764 699 765 task_retval(0); 700 766 async_manager(); -
uspace/srv/net/net/net.h
re86b8f0 r77a69ea 35 35 #define NET_NET_H_ 36 36 37 #include <ipc/loc.h> 37 38 #include <net/device.h> 38 39 #include <adt/char_map.h> … … 41 42 #include <adt/module_map.h> 42 43 #include <net/packet.h> 43 #include <devman.h>44 44 45 45 #define NAME "net" … … 96 96 97 97 /** Serving network interface driver module index. */ 98 devman_handle_t handle; /**< Handle for devman*/98 service_id_t sid; /**< Service ID */ 99 99 async_sess_t *sess; /**< Driver session. */ 100 100 101 101 module_t *nil; /**< Serving link layer module index. */ 102 102 module_t *il; /**< Serving internet layer module index. */ 103 104 link_t netif_list; 103 105 } netif_t; 104 106 -
uspace/srv/net/nil/eth/eth.c
re86b8f0 r77a69ea 48 48 #include <ipc/net.h> 49 49 #include <ipc/services.h> 50 #include <loc.h> 50 51 #include <net/modules.h> 51 52 #include <net_checksum.h> … … 226 227 * 227 228 * @param[in] device_id New device identifier. 228 * @param[in] handle Device driver handle.229 * @param[in] sid NIC service ID. 229 230 * @param[in] mtu Device maximum transmission unit. 230 231 * … … 234 235 * 235 236 */ 236 static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle,237 static int eth_device_message(nic_device_id_t device_id, service_id_t sid, 237 238 size_t mtu) 238 239 { … … 259 260 device = eth_devices_find(ð_globals.devices, device_id); 260 261 if (device) { 261 if (device-> handle != handle) {262 if (device->sid != sid) { 262 263 printf("Device %d already exists\n", device->device_id); 263 264 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 298 299 299 300 device->device_id = device_id; 300 device-> handle = handle;301 device->sid = sid; 301 302 device->flags = 0; 302 303 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) … … 335 336 336 337 /* Bind the device driver */ 337 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,338 device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 338 339 IPC_FLAG_BLOCKING); 339 340 if (device->sess == NULL) { … … 362 363 } 363 364 364 printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, "365 printf("%s: Device registered (id: %d, sid: %zu: mtu: %zu, " 365 366 "mac: " PRIMAC ", flags: 0x%x)\n", NAME, 366 device->device_id, device-> handle, device->mtu,367 device->device_id, device->sid, device->mtu, 367 368 ARGSMAC(device->addr.address), device->flags); 368 369 -
uspace/srv/net/nil/eth/eth.h
re86b8f0 r77a69ea 41 41 #include <async.h> 42 42 #include <fibril_synch.h> 43 #include <ipc/loc.h> 43 44 #include <ipc/services.h> 44 45 #include <net/device.h> 45 46 #include <adt/measured_strings.h> 46 #include <devman.h>47 47 48 48 /** Ethernet address length. */ … … 224 224 nic_device_id_t device_id; 225 225 /** Device handle */ 226 devman_handle_t handle;226 service_id_t sid; 227 227 /** Driver session. */ 228 228 async_sess_t *sess; -
uspace/srv/net/nil/nildummy/nildummy.c
re86b8f0 r77a69ea 53 53 #include <packet_remote.h> 54 54 #include <packet_client.h> 55 #include <devman.h>56 55 #include <device/nic.h> 56 #include <loc.h> 57 57 #include <nil_skel.h> 58 58 #include "nildummy.h" … … 115 115 */ 116 116 static int nildummy_device_message(nic_device_id_t device_id, 117 devman_handle_t handle, size_t mtu)117 service_id_t sid, size_t mtu) 118 118 { 119 119 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); … … 123 123 nildummy_devices_find(&nildummy_globals.devices, device_id); 124 124 if (device) { 125 if (device-> handle != handle) {125 if (device->sid != sid) { 126 126 printf("Device %d exists, handles do not match\n", 127 127 device->device_id); … … 158 158 159 159 device->device_id = device_id; 160 device-> handle = handle;160 device->sid = sid; 161 161 if (mtu > 0) 162 162 device->mtu = mtu; … … 165 165 166 166 /* Bind the device driver */ 167 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,167 device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 168 168 IPC_FLAG_BLOCKING); 169 169 if (device->sess == NULL) { -
uspace/srv/net/nil/nildummy/nildummy.h
re86b8f0 r77a69ea 41 41 #include <async.h> 42 42 #include <fibril_synch.h> 43 #include <ipc/loc.h> 43 44 #include <ipc/services.h> 44 #include <ipc/devman.h>45 45 #include <net/device.h> 46 46 … … 78 78 /** Device identifier. */ 79 79 nic_device_id_t device_id; 80 /** Device driver handle. */81 devman_handle_t handle;80 /** Device service ID. */ 81 service_id_t sid; 82 82 /** Driver session. */ 83 83 async_sess_t *sess;
Note:
See TracChangeset
for help on using the changeset viewer.