Changes in uspace/srv/net/nil/eth/eth.c [6d8455d:9cd8165] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/eth/eth.c
r6d8455d r9cd8165 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
Note:
See TracChangeset
for help on using the changeset viewer.