Changeset cfb79747 in mainline for uspace/srv
- Timestamp:
- 2012-02-14T22:06:15Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a31aad1
- Parents:
- 199112e4 (diff), e10d41a (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. - Location:
- uspace/srv
- Files:
-
- 13 edited
-
devman/devman.c (modified) (2 diffs)
-
hid/input/generic/input.c (modified) (3 diffs)
-
loc/loc.c (modified) (9 diffs)
-
net/cfg/e1k.nic (modified) (1 diff)
-
net/cfg/lo.nic (modified) (1 diff)
-
net/cfg/ne2k.nic (modified) (1 diff)
-
net/net/Makefile (modified) (1 diff)
-
net/net/net.c (modified) (13 diffs)
-
net/net/net.h (modified) (3 diffs)
-
net/nil/eth/eth.c (modified) (13 diffs)
-
net/nil/eth/eth.h (modified) (2 diffs)
-
net/nil/nildummy/nildummy.c (modified) (12 diffs)
-
net/nil/nildummy/nildummy.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r199112e4 rcfb79747 794 794 case EOK: 795 795 dev->state = DEVICE_USABLE; 796 exch = async_exchange_begin(drv->sess);797 async_msg_1(exch, DRIVER_DEV_ADDED, dev->handle);798 async_exchange_end(exch);799 796 break; 800 797 case ENOENT: … … 803 800 default: 804 801 dev->state = DEVICE_INVALID; 802 break; 805 803 } 806 804 -
uspace/srv/hid/input/generic/input.c
r199112e4 rcfb79747 39 39 #include <adt/list.h> 40 40 #include <bool.h> 41 #include <fibril_synch.h> 41 42 #include <ipc/services.h> 42 43 #include <ipc/input.h> … … 83 84 async_sess_t *irc_sess = NULL; 84 85 86 static FIBRIL_MUTEX_INITIALIZE(discovery_lock); 87 85 88 void kbd_push_data(kbd_dev_t *kdev, sysarg_t data) 86 89 { … … 593 596 int rc; 594 597 598 fibril_mutex_lock(&discovery_lock); 599 595 600 rc = dev_check_new_kbdevs(); 596 if (rc != EOK) 601 if (rc != EOK) { 602 fibril_mutex_unlock(&discovery_lock); 597 603 return rc; 604 } 598 605 599 606 rc = dev_check_new_mousedevs(); 600 if (rc != EOK) 607 if (rc != EOK) { 608 fibril_mutex_unlock(&discovery_lock); 601 609 return rc; 602 610 } 611 612 fibril_mutex_unlock(&discovery_lock); 613 603 614 return EOK; 604 615 } -
uspace/srv/loc/loc.c
r199112e4 rcfb79747 56 56 #define NULL_SERVICES 256 57 57 58 /** Callback session */ 59 typedef struct { 60 link_t cb_sess_list; 61 async_sess_t *sess; 62 } cb_sess_t; 63 58 64 LIST_INITIALIZE(services_list); 59 65 LIST_INITIALIZE(namespaces_list); … … 86 92 87 93 static FIBRIL_MUTEX_INITIALIZE(callback_sess_mutex); 88 static async_sess_t *callback_sess = NULL;94 static LIST_INITIALIZE(callback_sess_list); 89 95 90 96 service_id_t loc_create_id(void) … … 608 614 size_t act_size; 609 615 loc_service_t *svc; 616 char *fqn; 610 617 611 618 if (!async_data_read_receive(&callid, &size)) { … … 625 632 } 626 633 627 act_size = str_size(svc->name); 634 if (asprintf(&fqn, "%s/%s", svc->namespace->name, svc->name) < 0) { 635 fibril_mutex_unlock(&services_list_mutex); 636 async_answer_0(callid, ENOMEM); 637 async_answer_0(iid, ENOMEM); 638 return; 639 } 640 641 act_size = str_size(fqn); 628 642 if (act_size > size) { 643 free(fqn); 629 644 fibril_mutex_unlock(&services_list_mutex); 630 645 async_answer_0(callid, EOVERFLOW); … … 633 648 } 634 649 635 sysarg_t retval = async_data_read_finalize(callid, svc->name,650 sysarg_t retval = async_data_read_finalize(callid, fqn, 636 651 min(size, act_size)); 652 free(fqn); 637 653 638 654 fibril_mutex_unlock(&services_list_mutex); … … 790 806 } 791 807 792 /** Find ID for category specified by name. 793 * 794 * On success, answer will contain EOK int retval and service ID in arg1. 808 /** Create callback connection. 809 * 810 * Create callback connection which will be used to send category change 811 * events. 812 * 813 * On success, answer will contain EOK int retval. 795 814 * On failure, error code will be sent in retval. 796 815 * … … 798 817 static void loc_callback_create(ipc_callid_t iid, ipc_call_t *icall) 799 818 { 800 async_sess_t *cb_sess = async_callback_receive(EXCHANGE_SERIALIZE);819 cb_sess_t *cb_sess = calloc(1, sizeof(cb_sess_t)); 801 820 if (cb_sess == NULL) { 802 821 async_answer_0(iid, ENOMEM); … … 804 823 } 805 824 825 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 826 if (sess == NULL) { 827 free(cb_sess); 828 async_answer_0(iid, ENOMEM); 829 return; 830 } 831 832 cb_sess->sess = sess; 833 link_initialize(&cb_sess->cb_sess_list); 834 806 835 fibril_mutex_lock(&callback_sess_mutex); 807 if (callback_sess != NULL) { 808 fibril_mutex_unlock(&callback_sess_mutex); 809 async_answer_0(iid, EEXIST); 810 return; 811 } 812 813 callback_sess = cb_sess; 836 list_append(&cb_sess->cb_sess_list, &callback_sess_list); 814 837 fibril_mutex_unlock(&callback_sess_mutex); 815 838 … … 820 843 { 821 844 fibril_mutex_lock(&callback_sess_mutex); 822 823 if (callback_sess != NULL) { 824 async_exch_t *exch = async_exchange_begin(callback_sess); 845 846 list_foreach(callback_sess_list, link) { 847 cb_sess_t *cb_sess; 848 849 cb_sess = list_get_instance(link, cb_sess_t, cb_sess_list); 850 851 async_exch_t *exch = async_exchange_begin(cb_sess->sess); 825 852 async_msg_0(exch, LOC_EVENT_CAT_CHANGE); 826 853 async_exchange_end(exch); 827 854 } 828 855 829 856 fibril_mutex_unlock(&callback_sess_mutex); 830 857 } -
uspace/srv/net/cfg/e1k.nic
r199112e4 rcfb79747 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
r199112e4 rcfb79747 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
r199112e4 rcfb79747 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
r199112e4 rcfb79747 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
r199112e4 rcfb79747 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 3 * Copyright (c) 2011 Radim Vansa 4 * Copyright (c) 2011 Jiri Svoboda 4 5 * All rights reserved. 5 6 * … … 41 42 #include <stdio.h> 42 43 #include <str.h> 43 #include <devman.h>44 44 #include <str_error.h> 45 45 #include <ns.h> … … 56 56 #include <adt/measured_strings.h> 57 57 #include <adt/module_map.h> 58 #include <fibril_synch.h> 59 #include <loc.h> 60 #include <nic.h> 58 61 #include <nil_remote.h> 59 62 #include <net_interface.h> … … 73 76 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t); 74 77 DEVICE_MAP_IMPLEMENT(netifs, netif_t); 78 LIST_INITIALIZE(netif_list); 79 80 static FIBRIL_MUTEX_INITIALIZE(discovery_lock); 75 81 76 82 /** Add the configured setting to the configuration map. … … 287 293 * 288 294 */ 289 static int init_device(netif_t *netif, devman_handle_t handle)295 static int init_device(netif_t *netif, service_id_t sid) 290 296 { 291 297 printf("%s: Initializing device '%s'\n", NAME, netif->name); 292 298 293 netif-> handle = handle;294 netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle,299 netif->sid = sid; 300 netif->sess = loc_service_connect(EXCHANGE_SERIALIZE, netif->sid, 295 301 IPC_FLAG_BLOCKING); 296 302 if (netif->sess == NULL) { … … 337 343 strtol((const char *) setting->value, NULL, 10) : 0; 338 344 rc = nil_device_req(netif->nil->sess, netif->id, 339 netif-> handle, mtu);345 netif->sid, mtu); 340 346 if (rc != EOK) { 341 347 printf("%s: Unable to start network interface layer\n", … … 359 365 break; 360 366 default: 367 printf("%s: Unknown service\n", NAME); 361 368 return ENOENT; 362 369 } 363 370 364 371 printf("%s: Activating device '%s'\n", NAME, netif->name); 372 list_append(&netif->netif_list, &netif_list); 365 373 return nic_set_state(netif->sess, NIC_STATE_ACTIVE); 366 374 } 367 375 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) 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); 373 385 return EINVAL; 386 } 374 387 375 388 int index = char_map_find(&net_globals.netif_hwpaths, 376 389 (uint8_t *) hwpath, 0); 377 if (index == CHAR_MAP_NULL) 390 391 if (index == CHAR_MAP_NULL) { 392 printf("%s: Service '%s' not found in map.\n", NAME, hwpath); 393 free(hwpath); 378 394 return ENOENT; 395 } 396 397 free(hwpath); 379 398 380 399 netif_t *netif = netifs_get_index(&net_globals.netifs, index); … … 382 401 return ENOENT; 383 402 384 rc = init_device(netif, handle);403 rc = init_device(netif, sid); 385 404 if (rc != EOK) 386 405 return rc; … … 391 410 392 411 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 412 411 413 return EOK; … … 479 481 net_free_devices(strings, count); 480 482 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 483 default: 486 484 return ENOTSUP; … … 528 526 answer_call(callid, res, &answer, count); 529 527 } 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(); 530 595 } 531 596 … … 573 638 continue; 574 639 575 netif-> handle= -1;640 netif->sid = -1; 576 641 netif->sess = NULL; 577 642 … … 697 762 } 698 763 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 699 771 task_retval(0); 700 772 async_manager(); -
uspace/srv/net/net/net.h
r199112e4 rcfb79747 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*/99 async_sess_t *sess; /**< Driver session. */98 service_id_t sid; /**< Service ID */ 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
r199112e4 rcfb79747 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> … … 169 170 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t); 170 171 171 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 172 static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall, 173 void *arg); 174 175 static int eth_device_state(eth_device_t *device, sysarg_t state) 172 176 { 173 177 int index; … … 179 183 proto = eth_protos_get_index(ð_globals.protos, index); 180 184 if ((proto) && (proto->sess)) { 181 il_device_state_msg(proto->sess, device _id, state,182 proto->service);185 il_device_state_msg(proto->sess, device->device_id, 186 state, proto->service); 183 187 } 184 188 } … … 226 230 * 227 231 * @param[in] device_id New device identifier. 228 * @param[in] handle Device driver handle.232 * @param[in] sid NIC service ID. 229 233 * @param[in] mtu Device maximum transmission unit. 230 234 * … … 234 238 * 235 239 */ 236 static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle,240 static int eth_device_message(nic_device_id_t device_id, service_id_t sid, 237 241 size_t mtu) 238 242 { … … 259 263 device = eth_devices_find(ð_globals.devices, device_id); 260 264 if (device) { 261 if (device-> handle != handle) {265 if (device->sid != sid) { 262 266 printf("Device %d already exists\n", device->device_id); 263 267 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 298 302 299 303 device->device_id = device_id; 300 device-> handle = handle;304 device->sid = sid; 301 305 device->flags = 0; 302 306 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) … … 335 339 336 340 /* Bind the device driver */ 337 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,341 device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 338 342 IPC_FLAG_BLOCKING); 339 343 if (device->sess == NULL) { … … 343 347 } 344 348 345 nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id); 349 rc = nic_callback_create(device->sess, eth_nic_cb_connection, device); 350 if (rc != EOK) { 351 fibril_rwlock_write_unlock(ð_globals.devices_lock); 352 async_hangup(device->sess); 353 free(device); 354 return EIO; 355 } 346 356 347 357 /* Get hardware address */ … … 362 372 } 363 373 364 printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, "374 printf("%s: Device registered (id: %d, sid: %zu: mtu: %zu, " 365 375 "mac: " PRIMAC ", flags: 0x%x)\n", NAME, 366 device->device_id, device-> handle, device->mtu,376 device->device_id, device->sid, device->mtu, 367 377 ARGSMAC(device->addr.address), device->flags); 368 378 … … 814 824 } 815 825 816 static int eth_addr_changed(nic_device_id_t device_id) 826 static int eth_received(eth_device_t *device) 827 { 828 void *data; 829 size_t size; 830 int rc; 831 832 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); 833 if (rc != EOK) { 834 printf("%s: data_write_accept() failed\n", NAME); 835 return rc; 836 } 837 838 packet_t *packet = packet_get_1_remote(eth_globals.net_sess, size); 839 if (packet == NULL) 840 return ENOMEM; 841 842 void *pdata = packet_suffix(packet, size); 843 memcpy(pdata, data, size); 844 free(data); 845 846 return nil_received_msg_local(device->device_id, packet); 847 } 848 849 static int eth_addr_changed(eth_device_t *device) 817 850 { 818 851 nic_address_t address; … … 832 865 833 866 fibril_rwlock_write_lock(ð_globals.devices_lock); 834 /* An existing device? */ 835 eth_device_t *device = eth_devices_find(ð_globals.devices, device_id); 836 if (device) { 837 printf("Device %d changing address from " PRIMAC " to " PRIMAC "\n", 838 device_id, ARGSMAC(device->addr.address), ARGSMAC(address.address)); 839 memcpy(&device->addr, &address, sizeof (nic_address_t)); 840 fibril_rwlock_write_unlock(ð_globals.devices_lock); 841 842 /* Notify all upper layer modules */ 843 fibril_rwlock_read_lock(ð_globals.protos_lock); 844 int index; 845 for (index = 0; index < eth_protos_count(ð_globals.protos); index++) { 846 eth_proto_t *proto = eth_protos_get_index(ð_globals.protos, index); 847 if (proto->sess != NULL) { 848 il_addr_changed_msg(proto->sess, device->device_id, 849 ETH_ADDR, address.address); 850 } 851 } 852 853 fibril_rwlock_read_unlock(ð_globals.protos_lock); 854 return EOK; 855 } else { 856 return ENOENT; 857 } 867 868 printf("Device %d changing address from " PRIMAC " to " PRIMAC "\n", 869 device->device_id, ARGSMAC(device->addr.address), 870 ARGSMAC(address.address)); 871 memcpy(&device->addr, &address, sizeof (nic_address_t)); 872 fibril_rwlock_write_unlock(ð_globals.devices_lock); 873 874 /* Notify all upper layer modules */ 875 fibril_rwlock_read_lock(ð_globals.protos_lock); 876 int index; 877 for (index = 0; index < eth_protos_count(ð_globals.protos); index++) { 878 eth_proto_t *proto = eth_protos_get_index(ð_globals.protos, index); 879 if (proto->sess != NULL) { 880 il_addr_changed_msg(proto->sess, device->device_id, 881 ETH_ADDR, address.address); 882 } 883 } 884 885 fibril_rwlock_read_unlock(ð_globals.protos_lock); 886 return EOK; 858 887 } 859 888 … … 921 950 922 951 return EOK; 923 case NET_NIL_DEVICE_STATE:924 nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call));925 async_answer_0(callid, EOK);926 return EOK;927 case NET_NIL_RECEIVED:928 rc = packet_translate_remote(eth_globals.net_sess, &packet,929 IPC_GET_ARG2(*call));930 if (rc == EOK)931 rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);932 933 async_answer_0(callid, (sysarg_t) rc);934 return rc;935 case NET_NIL_ADDR_CHANGED:936 rc = eth_addr_changed(IPC_GET_DEVICE(*call));937 async_answer_0(callid, (sysarg_t) rc);938 return rc;939 952 } 940 953 941 954 return ENOTSUP; 955 } 956 957 static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 958 { 959 eth_device_t *device = (eth_device_t *)arg; 960 int rc; 961 962 async_answer_0(iid, EOK); 963 964 while (true) { 965 ipc_call_t call; 966 ipc_callid_t callid = async_get_call(&call); 967 968 if (!IPC_GET_IMETHOD(call)) 969 break; 970 971 switch (IPC_GET_IMETHOD(call)) { 972 case NIC_EV_DEVICE_STATE: 973 rc = eth_device_state(device, IPC_GET_ARG1(call)); 974 async_answer_0(callid, (sysarg_t) rc); 975 break; 976 case NIC_EV_RECEIVED: 977 rc = eth_received(device); 978 async_answer_0(callid, (sysarg_t) rc); 979 break; 980 case NIC_EV_ADDR_CHANGED: 981 rc = eth_addr_changed(device); 982 async_answer_0(callid, (sysarg_t) rc); 983 break; 984 default: 985 async_answer_0(callid, ENOTSUP); 986 } 987 } 942 988 } 943 989 -
uspace/srv/net/nil/eth/eth.h
r199112e4 rcfb79747 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
r199112e4 rcfb79747 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 3 * Copyright (c) 2011 Radim Vansa 4 * Copyright (c) 2011 Jiri Svoboda 4 5 * All rights reserved. 5 6 * … … 53 54 #include <packet_remote.h> 54 55 #include <packet_client.h> 55 #include <devman.h>56 56 #include <device/nic.h> 57 #include <loc.h> 57 58 #include <nil_skel.h> 58 59 #include "nildummy.h" … … 69 70 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t); 70 71 71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 72 static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, 73 void *arg); 74 75 static int nildummy_device_state(nildummy_device_t *device, sysarg_t state) 72 76 { 73 77 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 74 78 if (nildummy_globals.proto.sess) 75 il_device_state_msg(nildummy_globals.proto.sess, device_id,76 state, nildummy_globals.proto.service);79 il_device_state_msg(nildummy_globals.proto.sess, 80 device->device_id, state, nildummy_globals.proto.service); 77 81 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 78 82 79 83 return EOK; 84 } 85 86 static int nildummy_addr_changed(nildummy_device_t *device) 87 { 88 return ENOTSUP; 80 89 } 81 90 … … 115 124 */ 116 125 static int nildummy_device_message(nic_device_id_t device_id, 117 devman_handle_t handle, size_t mtu)126 service_id_t sid, size_t mtu) 118 127 { 119 128 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); … … 123 132 nildummy_devices_find(&nildummy_globals.devices, device_id); 124 133 if (device) { 125 if (device-> handle != handle) {134 if (device->sid != sid) { 126 135 printf("Device %d exists, handles do not match\n", 127 136 device->device_id); … … 158 167 159 168 device->device_id = device_id; 160 device-> handle = handle;169 device->sid = sid; 161 170 if (mtu > 0) 162 171 device->mtu = mtu; … … 165 174 166 175 /* Bind the device driver */ 167 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,176 device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 168 177 IPC_FLAG_BLOCKING); 169 178 if (device->sess == NULL) { … … 173 182 } 174 183 175 nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id); 184 int rc = nic_callback_create(device->sess, nildummy_nic_cb_conn, 185 device); 186 if (rc != EOK) { 187 async_hangup(device->sess); 188 189 return ENOENT; 190 } 176 191 177 192 /* Get hardware address */ 178 intrc = nic_get_address(device->sess, &device->addr);193 rc = nic_get_address(device->sess, &device->addr); 179 194 if (rc != EOK) { 180 195 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 345 360 services_t sender) 346 361 { 347 packet_t *p;348 349 362 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 350 363 … … 356 369 } 357 370 358 p = packet;371 packet_t *p = packet; 359 372 do { 360 373 nic_send_frame(device->sess, packet_get_data(p), … … 368 381 369 382 return EOK; 383 } 384 385 static int nildummy_received(nildummy_device_t *device) 386 { 387 void *data; 388 size_t size; 389 int rc; 390 391 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); 392 if (rc != EOK) 393 return rc; 394 395 packet_t *packet = packet_get_1_remote(nildummy_globals.net_sess, size); 396 if (packet == NULL) 397 return ENOMEM; 398 399 void *pdata = packet_suffix(packet, size); 400 memcpy(pdata, data, size); 401 free(pdata); 402 403 return nil_received_msg_local(device->device_id, packet); 370 404 } 371 405 … … 424 458 *answer_count = 1; 425 459 return rc; 426 case NET_NIL_DEVICE_STATE:427 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call),428 IPC_GET_STATE(*call));429 async_answer_0(callid, (sysarg_t) rc);430 return rc;431 432 case NET_NIL_RECEIVED:433 rc = packet_translate_remote(nildummy_globals.net_sess, &packet,434 IPC_GET_ARG2(*call));435 if (rc == EOK)436 rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);437 438 async_answer_0(callid, (sysarg_t) rc);439 return rc;440 460 } 441 461 442 462 return ENOTSUP; 443 463 } 464 465 static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 466 { 467 nildummy_device_t *device = (nildummy_device_t *)arg; 468 int rc; 469 470 async_answer_0(iid, EOK); 471 472 while (true) { 473 ipc_call_t call; 474 ipc_callid_t callid = async_get_call(&call); 475 476 if (!IPC_GET_IMETHOD(call)) 477 break; 478 479 switch (IPC_GET_IMETHOD(call)) { 480 case NIC_EV_DEVICE_STATE: 481 rc = nildummy_device_state(device, IPC_GET_ARG1(call)); 482 async_answer_0(callid, (sysarg_t) rc); 483 break; 484 case NIC_EV_RECEIVED: 485 rc = nildummy_received(device); 486 async_answer_0(callid, (sysarg_t) rc); 487 break; 488 case NIC_EV_ADDR_CHANGED: 489 rc = nildummy_addr_changed(device); 490 async_answer_0(callid, (sysarg_t) rc); 491 break; 492 default: 493 async_answer_0(callid, ENOTSUP); 494 } 495 } 496 } 497 444 498 445 499 int main(int argc, char *argv[]) -
uspace/srv/net/nil/nildummy/nildummy.h
r199112e4 rcfb79747 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.
