Changes in uspace/srv/net/nil/eth/eth.c [9cd8165:6d8455d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/eth/eth.c
r9cd8165 r6d8455d 48 48 #include <ipc/net.h> 49 49 #include <ipc/services.h> 50 #include <loc.h>51 50 #include <net/modules.h> 52 51 #include <net_checksum.h> … … 170 169 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t); 171 170 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) 171 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 176 172 { 177 173 int index; … … 183 179 proto = eth_protos_get_index(ð_globals.protos, index); 184 180 if ((proto) && (proto->sess)) { 185 il_device_state_msg(proto->sess, device ->device_id,186 state,proto->service);181 il_device_state_msg(proto->sess, device_id, state, 182 proto->service); 187 183 } 188 184 } … … 230 226 * 231 227 * @param[in] device_id New device identifier. 232 * @param[in] sid NIC service ID.228 * @param[in] handle Device driver handle. 233 229 * @param[in] mtu Device maximum transmission unit. 234 230 * … … 238 234 * 239 235 */ 240 static int eth_device_message(nic_device_id_t device_id, service_id_t sid,236 static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle, 241 237 size_t mtu) 242 238 { … … 263 259 device = eth_devices_find(ð_globals.devices, device_id); 264 260 if (device) { 265 if (device-> sid != sid) {261 if (device->handle != handle) { 266 262 printf("Device %d already exists\n", device->device_id); 267 263 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 302 298 303 299 device->device_id = device_id; 304 device-> sid = sid;300 device->handle = handle; 305 301 device->flags = 0; 306 302 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) … … 339 335 340 336 /* Bind the device driver */ 341 device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid,337 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 342 338 IPC_FLAG_BLOCKING); 343 339 if (device->sess == NULL) { … … 347 343 } 348 344 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 } 345 nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id); 356 346 357 347 /* Get hardware address */ … … 372 362 } 373 363 374 printf("%s: Device registered (id: %d, sid: %zu: mtu: %zu, "364 printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, " 375 365 "mac: " PRIMAC ", flags: 0x%x)\n", NAME, 376 device->device_id, device-> sid, device->mtu,366 device->device_id, device->handle, device->mtu, 377 367 ARGSMAC(device->addr.address), device->flags); 378 368 … … 824 814 } 825 815 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) 816 static int eth_addr_changed(nic_device_id_t device_id) 850 817 { 851 818 nic_address_t address; … … 865 832 866 833 fibril_rwlock_write_lock(ð_globals.devices_lock); 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; 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 } 887 858 } 888 859 … … 950 921 951 922 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; 952 939 } 953 940 954 941 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 }988 942 } 989 943
Note:
See TracChangeset
for help on using the changeset viewer.