Changes in / [eaa0c3f:c38e417] in mainline
- Location:
- uspace
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/nic.c
reaa0c3f rc38e417 73 73 } 74 74 75 /** Connect the driver to the NET and NIL services 76 * 77 * @param[in] dev_sess 78 * @param[in] nil_service Service identifier for the NIL service 75 /** Create callback connection from NIC service 76 * 77 * @param[in] dev_sess 79 78 * @param[in] device_id 80 79 * … … 82 81 * 83 82 */ 84 int nic_connect_to_nil(async_sess_t *dev_sess, services_t nil_service, 85 nic_device_id_t device_id) 86 { 87 async_exch_t *exch = async_exchange_begin(dev_sess); 88 int rc = async_req_3_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 89 NIC_CONNECT_TO_NIL, nil_service, device_id); 90 async_exchange_end(exch); 91 92 return rc; 83 int nic_callback_create(async_sess_t *dev_sess, nic_device_id_t device_id, 84 async_client_conn_t cfun, void *carg) 85 { 86 ipc_call_t answer; 87 int rc; 88 sysarg_t retval; 89 90 async_exch_t *exch = async_exchange_begin(dev_sess); 91 aid_t req = async_send_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 92 NIC_CALLBACK_CREATE, device_id, &answer); 93 94 rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg); 95 if (rc != EOK) { 96 async_wait_for(req, NULL); 97 return rc; 98 } 99 async_exchange_end(exch); 100 101 async_wait_for(req, &retval); 102 return (int) retval; 93 103 } 94 104 -
uspace/lib/c/include/device/nic.h
reaa0c3f rc38e417 39 39 #include <net/device.h> 40 40 #include <net/packet.h> 41 #include <ipc/common.h> 41 42 #include <ipc/services.h> 42 43 43 44 typedef enum { 44 45 NIC_SEND_MESSAGE = 0, 45 NIC_C ONNECT_TO_NIL,46 NIC_CALLBACK_CREATE, 46 47 NIC_GET_STATE, 47 48 NIC_SET_STATE, … … 85 86 } nic_funcs_t; 86 87 88 typedef enum { 89 NIC_EV_ADDR_CHANGED = IPC_FIRST_USER_METHOD, 90 NIC_EV_RECEIVED, 91 NIC_EV_DEVICE_STATE 92 } nic_event_t; 93 87 94 extern int nic_send_frame(async_sess_t *, void *, size_t); 88 extern int nic_connect_to_nil(async_sess_t *, services_t, nic_device_id_t); 95 extern int nic_callback_create(async_sess_t *, nic_device_id_t, 96 async_client_conn_t, void *); 89 97 extern int nic_get_state(async_sess_t *, nic_device_state_t *); 90 98 extern int nic_set_state(async_sess_t *, nic_device_state_t); -
uspace/lib/c/include/ipc/nil.h
reaa0c3f rc38e417 46 46 */ 47 47 NET_NIL_DEVICE = NET_NIL_FIRST, 48 /** New device state message.49 * @see nil_device_state_msg()50 */51 NET_NIL_DEVICE_STATE,52 /** Received packet queue message.53 * @see nil_received_msg()54 */55 NET_NIL_RECEIVED,56 48 /** Send packet queue message. 57 49 * @see nil_send_msg() … … 69 61 * @see nil_get_broadcast_addr() 70 62 */ 71 NET_NIL_BROADCAST_ADDR, 72 /** Device has changed address 73 * @see nil_addr_changed_msg() 74 */ 75 NET_NIL_ADDR_CHANGED 63 NET_NIL_BROADCAST_ADDR 76 64 } nil_messages; 77 65 -
uspace/lib/drv/generic/remote_nic.c
reaa0c3f rc38e417 63 63 } 64 64 65 static void remote_nic_connect_to_nil(ddf_fun_t *dev, void *iface, 66 ipc_callid_t callid, ipc_call_t *call) 67 { 68 nic_iface_t *nic_iface = (nic_iface_t *) iface; 69 assert(nic_iface->connect_to_nil); 70 71 services_t nil_service = (services_t) IPC_GET_ARG2(*call); 72 nic_device_id_t device_id = (nic_device_id_t) IPC_GET_ARG3(*call); 73 74 int rc = nic_iface->connect_to_nil(dev, nil_service, device_id); 65 static void remote_nic_callback_create(ddf_fun_t *dev, void *iface, 66 ipc_callid_t callid, ipc_call_t *call) 67 { 68 nic_iface_t *nic_iface = (nic_iface_t *) iface; 69 assert(nic_iface->callback_create); 70 71 nic_device_id_t device_id = (nic_device_id_t) IPC_GET_ARG2(*call); 72 73 int rc = nic_iface->callback_create(dev, device_id); 75 74 async_answer_0(callid, rc); 76 75 } … … 1203 1202 static remote_iface_func_ptr_t remote_nic_iface_ops[] = { 1204 1203 &remote_nic_send_frame, 1205 &remote_nic_c onnect_to_nil,1204 &remote_nic_callback_create, 1206 1205 &remote_nic_get_state, 1207 1206 &remote_nic_set_state, -
uspace/lib/drv/include/ops/nic.h
reaa0c3f rc38e417 46 46 /** Mandatory methods */ 47 47 int (*send_frame)(ddf_fun_t *, void *, size_t); 48 int (*c onnect_to_nil)(ddf_fun_t *, services_t, nic_device_id_t);48 int (*callback_create)(ddf_fun_t *, nic_device_id_t); 49 49 int (*get_state)(ddf_fun_t *, nic_device_state_t *); 50 50 int (*set_state)(ddf_fun_t *, nic_device_state_t); -
uspace/lib/net/include/nil_remote.h
reaa0c3f rc38e417 62 62 extern int nil_device_req(async_sess_t *, nic_device_id_t, devman_handle_t, 63 63 size_t); 64 extern int nil_device_state_msg(async_sess_t *, nic_device_id_t, sysarg_t);65 extern int nil_received_msg(async_sess_t *, nic_device_id_t, void *, size_t);66 extern int nil_addr_changed_msg(async_sess_t *, nic_device_id_t,67 const nic_address_t *);68 64 69 65 #endif -
uspace/lib/net/nil/nil_remote.c
reaa0c3f rc38e417 44 44 #include <ipc/nil.h> 45 45 46 /** Notify the network interface layer about the device state change.47 *48 * @param[in] sess Network interface layer session.49 * @param[in] device_id Device identifier.50 * @param[in] state New device state.51 *52 * @return EOK on success.53 * @return Other error codes as defined for each specific module54 * device state function.55 *56 */57 int nil_device_state_msg(async_sess_t *sess, nic_device_id_t device_id,58 sysarg_t state)59 {60 return generic_device_state_msg_remote(sess, NET_NIL_DEVICE_STATE,61 device_id, state, 0);62 }63 64 /** Pass the packet queue to the network interface layer.65 *66 * Process and redistribute the received packet queue to the registered67 * upper layers.68 *69 * @param[in] sess Network interface layer session.70 * @param[in] device_id Source device identifier.71 * @param[in] packet Received packet or the received packet queue.72 * @param[in] target Target service. Ignored parameter.73 *74 * @return EOK on success.75 * @return Other error codes as defined for each specific module76 * received function.77 *78 */79 int nil_received_msg(async_sess_t *sess, nic_device_id_t device_id,80 void *data, size_t size)81 {82 async_exch_t *exch = async_exchange_begin(sess);83 84 ipc_call_t answer;85 aid_t req = async_send_1(exch, NET_NIL_RECEIVED, (sysarg_t) device_id,86 &answer);87 sysarg_t retval = async_data_write_start(exch, data, size);88 89 async_exchange_end(exch);90 91 if (retval != EOK) {92 async_wait_for(req, NULL);93 return retval;94 }95 96 async_wait_for(req, &retval);97 return retval;98 }99 100 /** Notify upper layers that device address has changed101 *102 */103 int nil_addr_changed_msg(async_sess_t *sess, nic_device_id_t device_id,104 const nic_address_t *address)105 {106 assert(sess);107 108 async_exch_t *exch = async_exchange_begin(sess);109 110 aid_t message_id = async_send_1(exch, NET_NIL_ADDR_CHANGED,111 (sysarg_t) device_id, NULL);112 int rc = async_data_write_start(exch, address, sizeof (nic_address_t));113 114 async_exchange_end(exch);115 116 sysarg_t res;117 async_wait_for(message_id, &res);118 119 if (rc != EOK)120 return rc;121 122 return (int) res;123 }124 125 46 int nil_device_req(async_sess_t *sess, nic_device_id_t device_id, 126 47 service_id_t sid, size_t mtu) -
uspace/lib/nic/Makefile
reaa0c3f rc38e417 34 34 SOURCES = \ 35 35 src/nic_driver.c \ 36 src/nic_ev.c \ 36 37 src/nic_addr_db.c \ 37 38 src/nic_rx_control.c \ -
uspace/lib/nic/include/nic_driver.h
reaa0c3f rc38e417 80 80 /** Device's default MAC address (assigned the first time, used in STOP) */ 81 81 nic_address_t default_mac; 82 /** Session to SERVICE_ETHERNET or SERVICE_NILDUMMY*/83 async_sess_t * nil_session;82 /** Client callback session */ 83 async_sess_t *client_session; 84 84 /** Phone to APIC or i8259 */ 85 85 async_sess_t *irc_session; -
uspace/lib/nic/include/nic_impl.h
reaa0c3f rc38e417 49 49 extern int nic_get_address_impl(ddf_fun_t *dev_fun, nic_address_t *address); 50 50 extern int nic_send_frame_impl(ddf_fun_t *dev_fun, void *data, size_t size); 51 extern int nic_connect_to_nil_impl(ddf_fun_t *dev_fun, services_t nil_service, 52 int device_id); 51 extern int nic_callback_create_impl(ddf_fun_t *dev_fun, int device_id); 53 52 extern int nic_get_state_impl(ddf_fun_t *dev_fun, nic_device_state_t *state); 54 53 extern int nic_set_state_impl(ddf_fun_t *dev_fun, nic_device_state_t state); -
uspace/lib/nic/src/nic_driver.c
reaa0c3f rc38e417 53 53 54 54 #include "nic_driver.h" 55 #include "nic_ev.h" 55 56 #include "nic_impl.h" 56 57 … … 106 107 if (!iface->send_frame) 107 108 iface->send_frame = nic_send_frame_impl; 108 if (!iface->c onnect_to_nil)109 iface->c onnect_to_nil = nic_connect_to_nil_impl;109 if (!iface->callback_create) 110 iface->callback_create = nic_callback_create_impl; 110 111 if (!iface->get_address) 111 112 iface->get_address = nic_get_address_impl; … … 494 495 495 496 /* Notify NIL layer (and uppper) if bound - not in add_device */ 496 if (nic_data-> nil_session != NULL) {497 int rc = ni l_addr_changed_msg(nic_data->nil_session,497 if (nic_data->client_session != NULL) { 498 int rc = nic_ev_addr_changed(nic_data->client_session, 498 499 nic_data->device_id, address); 499 500 if (rc != EOK) { … … 603 604 } 604 605 fibril_rwlock_write_unlock(&nic_data->stats_lock); 605 ni l_received_msg(nic_data->nil_session, nic_data->device_id,606 nic_ev_received(nic_data->client_session, nic_data->device_id, 606 607 frame->data, frame->size); 607 608 } else { … … 638 639 fibril_rwlock_write_unlock(&nic_data->stats_lock); 639 640 640 ni l_received_msg(nic_data->nil_session, nic_data->device_id,641 nic_ev_received(nic_data->client_session, nic_data->device_id, 641 642 data, size); 642 643 } … … 692 693 nic_data->device_id = NIC_DEVICE_INVALID_ID; 693 694 nic_data->state = NIC_STATE_STOPPED; 694 nic_data-> nil_session = NULL;695 nic_data->client_session = NULL; 695 696 nic_data->irc_session = NULL; 696 697 nic_data->poll_mode = NIC_POLL_IMMEDIATE; … … 746 747 */ 747 748 static void nic_destroy(nic_t *nic_data) { 748 if (nic_data-> nil_session != NULL) {749 async_hangup(nic_data-> nil_session);749 if (nic_data->client_session != NULL) { 750 async_hangup(nic_data->client_session); 750 751 } 751 752 -
uspace/lib/nic/src/nic_impl.c
reaa0c3f rc38e417 40 40 #include <ns.h> 41 41 #include "nic_driver.h" 42 #include "nic_ev.h" 42 43 #include "nic_impl.h" 43 44 … … 85 86 } 86 87 if (state == NIC_STATE_ACTIVE) { 87 if (nic_data-> nil_session == NULL || nic_data->device_id < 0) {88 if (nic_data->client_session == NULL || nic_data->device_id < 0) { 88 89 fibril_rwlock_write_unlock(&nic_data->main_lock); 89 90 return EINVAL; … … 115 116 if (state == NIC_STATE_STOPPED) { 116 117 /* Notify upper layers that we are reseting the MAC */ 117 int rc = ni l_addr_changed_msg(nic_data->nil_session,118 int rc = nic_ev_addr_changed(nic_data->client_session, 118 119 nic_data->device_id, &nic_data->default_mac); 119 120 nic_data->poll_mode = nic_data->default_poll_mode; … … 148 149 nic_data->state = state; 149 150 150 ni l_device_state_msg(nic_data->nil_session, nic_data->device_id, state);151 nic_ev_device_state(nic_data->client_session, nic_data->device_id, state); 151 152 152 153 fibril_rwlock_write_unlock(&nic_data->main_lock); … … 181 182 182 183 /** 183 * Default implementation of the connect_ to_nilmethod.184 * C onnects the driver to the NIL service.184 * Default implementation of the connect_client method. 185 * Creates callback connection to the client. 185 186 * 186 187 * @param fun 187 * @param nil_service ID of the server implementing the NIL service188 188 * @param device_id ID of the device as used in higher layers 189 189 * 190 * @return EOK If the services were bound 191 * @return Negative error code from service_connect_blocking 192 */ 193 int nic_connect_to_nil_impl(ddf_fun_t *fun, services_t nil_service, 194 nic_device_id_t device_id) 195 { 196 nic_t *nic_data = (nic_t *) fun->driver_data; 197 fibril_rwlock_write_lock(&nic_data->main_lock); 190 * @return EOK On success, or negative error code. 191 */ 192 int nic_callback_create_impl(ddf_fun_t *fun, nic_device_id_t device_id) 193 { 194 nic_t *nic = (nic_t *) fun->driver_data; 195 fibril_rwlock_write_lock(&nic->main_lock); 198 196 199 nic _data->device_id = device_id;197 nic->device_id = device_id; 200 198 201 nic_data->nil_session = service_connect_blocking(EXCHANGE_SERIALIZE, 202 nil_service, 0, 0); 203 if (nic_data->nil_session != NULL) { 204 fibril_rwlock_write_unlock(&nic_data->main_lock); 205 return EOK; 199 nic->client_session = async_callback_receive(EXCHANGE_SERIALIZE); 200 if (nic->client_session == NULL) { 201 fibril_rwlock_write_unlock(&nic->main_lock); 202 return ENOMEM; 206 203 } 207 204 208 fibril_rwlock_write_unlock(&nic _data->main_lock);209 return E HANGUP;205 fibril_rwlock_write_unlock(&nic->main_lock); 206 return EOK; 210 207 } 211 208 -
uspace/srv/net/net/net.c
reaa0c3f rc38e417 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 * … … 363 364 break; 364 365 default: 366 printf("%s: Unknown service\n", NAME); 365 367 return ENOENT; 366 368 } -
uspace/srv/net/nil/eth/eth.c
reaa0c3f rc38e417 170 170 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t); 171 171 172 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(nic_device_id_t device_id, sysarg_t state) 173 176 { 174 177 int index; … … 344 347 } 345 348 346 nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id); 349 rc = nic_callback_create(device->sess, device_id, 350 eth_nic_cb_connection, NULL); 351 if (rc != EOK) { 352 fibril_rwlock_write_unlock(ð_globals.devices_lock); 353 async_hangup(device->sess); 354 free(device); 355 return EIO; 356 } 347 357 348 358 /* Get hardware address */ … … 822 832 823 833 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); 824 if (rc != EOK) 834 if (rc != EOK) { 835 printf("%s: data_write_accept() failed\n", NAME); 825 836 return rc; 837 } 826 838 827 839 packet_t *packet = packet_get_1_remote(eth_globals.net_sess, size); … … 943 955 944 956 return EOK; 945 case NET_NIL_DEVICE_STATE:946 nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call));947 async_answer_0(callid, EOK);948 return EOK;949 case NET_NIL_RECEIVED:950 rc = eth_received(IPC_GET_ARG1(*call));951 async_answer_0(callid, (sysarg_t) rc);952 return rc;953 case NET_NIL_ADDR_CHANGED:954 rc = eth_addr_changed(IPC_GET_DEVICE(*call));955 async_answer_0(callid, (sysarg_t) rc);956 return rc;957 957 } 958 958 959 959 return ENOTSUP; 960 } 961 962 static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 963 { 964 int rc; 965 966 async_answer_0(iid, EOK); 967 968 while (true) { 969 ipc_call_t call; 970 ipc_callid_t callid = async_get_call(&call); 971 972 if (!IPC_GET_IMETHOD(call)) 973 break; 974 975 switch (IPC_GET_IMETHOD(call)) { 976 case NIC_EV_DEVICE_STATE: 977 rc = eth_device_state(IPC_GET_ARG1(call), 978 IPC_GET_ARG2(call)); 979 async_answer_0(callid, (sysarg_t) rc); 980 break; 981 case NIC_EV_RECEIVED: 982 rc = eth_received(IPC_GET_ARG1(call)); 983 async_answer_0(callid, (sysarg_t) rc); 984 break; 985 case NIC_EV_ADDR_CHANGED: 986 rc = eth_addr_changed(IPC_GET_ARG1(call)); 987 async_answer_0(callid, (sysarg_t) rc); 988 break; 989 default: 990 async_answer_0(callid, ENOTSUP); 991 } 992 } 960 993 } 961 994 -
uspace/srv/net/nil/nildummy/nildummy.c
reaa0c3f rc38e417 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 * … … 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(nic_device_id_t device_id, sysarg_t state) 72 76 { 73 77 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); … … 78 82 79 83 return EOK; 84 } 85 86 static int nildummy_addr_changed(nic_device_id_t device_id) 87 { 88 return ENOTSUP; 80 89 } 81 90 … … 173 182 } 174 183 175 nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id); 184 int rc = nic_callback_create(device->sess, device_id, 185 nildummy_nic_cb_conn, NULL); 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); … … 445 460 *answer_count = 1; 446 461 return rc; 447 case NET_NIL_DEVICE_STATE:448 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call),449 IPC_GET_STATE(*call));450 async_answer_0(callid, (sysarg_t) rc);451 return rc;452 453 case NET_NIL_RECEIVED:454 rc = nildummy_received(IPC_GET_ARG1(*call));455 async_answer_0(callid, (sysarg_t) rc);456 return rc;457 462 } 458 463 459 464 return ENOTSUP; 460 465 } 466 467 static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 468 { 469 int rc; 470 471 async_answer_0(iid, EOK); 472 473 while (true) { 474 ipc_call_t call; 475 ipc_callid_t callid = async_get_call(&call); 476 477 if (!IPC_GET_IMETHOD(call)) 478 break; 479 480 switch (IPC_GET_IMETHOD(call)) { 481 case NIC_EV_DEVICE_STATE: 482 rc = nildummy_device_state(IPC_GET_ARG1(call), 483 IPC_GET_ARG2(call)); 484 async_answer_0(callid, (sysarg_t) rc); 485 break; 486 case NIC_EV_RECEIVED: 487 rc = nildummy_received(IPC_GET_ARG1(call)); 488 async_answer_0(callid, (sysarg_t) rc); 489 break; 490 case NIC_EV_ADDR_CHANGED: 491 rc = nildummy_addr_changed(IPC_GET_ARG1(call)); 492 async_answer_0(callid, (sysarg_t) rc); 493 break; 494 default: 495 async_answer_0(callid, ENOTSUP); 496 } 497 } 498 } 499 461 500 462 501 int main(int argc, char *argv[])
Note:
See TracChangeset
for help on using the changeset viewer.