Changes in / [c38e417:eaa0c3f] in mainline
- Location:
- uspace
- Files:
-
- 2 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/nic.c
rc38e417 reaa0c3f 73 73 } 74 74 75 /** Create callback connection from NIC service 76 * 77 * @param[in] dev_sess 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 78 79 * @param[in] device_id 79 80 * … … 81 82 * 82 83 */ 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; 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; 103 93 } 104 94 -
uspace/lib/c/include/device/nic.h
rc38e417 reaa0c3f 39 39 #include <net/device.h> 40 40 #include <net/packet.h> 41 #include <ipc/common.h>42 41 #include <ipc/services.h> 43 42 44 43 typedef enum { 45 44 NIC_SEND_MESSAGE = 0, 46 NIC_C ALLBACK_CREATE,45 NIC_CONNECT_TO_NIL, 47 46 NIC_GET_STATE, 48 47 NIC_SET_STATE, … … 86 85 } nic_funcs_t; 87 86 88 typedef enum {89 NIC_EV_ADDR_CHANGED = IPC_FIRST_USER_METHOD,90 NIC_EV_RECEIVED,91 NIC_EV_DEVICE_STATE92 } nic_event_t;93 94 87 extern int nic_send_frame(async_sess_t *, void *, size_t); 95 extern int nic_callback_create(async_sess_t *, nic_device_id_t, 96 async_client_conn_t, void *); 88 extern int nic_connect_to_nil(async_sess_t *, services_t, nic_device_id_t); 97 89 extern int nic_get_state(async_sess_t *, nic_device_state_t *); 98 90 extern int nic_set_state(async_sess_t *, nic_device_state_t); -
uspace/lib/c/include/ipc/nil.h
rc38e417 reaa0c3f 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, 48 56 /** Send packet queue message. 49 57 * @see nil_send_msg() … … 61 69 * @see nil_get_broadcast_addr() 62 70 */ 63 NET_NIL_BROADCAST_ADDR 71 NET_NIL_BROADCAST_ADDR, 72 /** Device has changed address 73 * @see nil_addr_changed_msg() 74 */ 75 NET_NIL_ADDR_CHANGED 64 76 } nil_messages; 65 77 -
uspace/lib/drv/generic/remote_nic.c
rc38e417 reaa0c3f 63 63 } 64 64 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); 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); 74 75 async_answer_0(callid, rc); 75 76 } … … 1202 1203 static remote_iface_func_ptr_t remote_nic_iface_ops[] = { 1203 1204 &remote_nic_send_frame, 1204 &remote_nic_c allback_create,1205 &remote_nic_connect_to_nil, 1205 1206 &remote_nic_get_state, 1206 1207 &remote_nic_set_state, -
uspace/lib/drv/include/ops/nic.h
rc38e417 reaa0c3f 46 46 /** Mandatory methods */ 47 47 int (*send_frame)(ddf_fun_t *, void *, size_t); 48 int (*c allback_create)(ddf_fun_t *, nic_device_id_t);48 int (*connect_to_nil)(ddf_fun_t *, services_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
rc38e417 reaa0c3f 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 *); 64 68 65 69 #endif -
uspace/lib/net/nil/nil_remote.c
rc38e417 reaa0c3f 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 module 54 * 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 registered 67 * 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 module 76 * 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 changed 101 * 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 46 125 int nil_device_req(async_sess_t *sess, nic_device_id_t device_id, 47 126 service_id_t sid, size_t mtu) -
uspace/lib/nic/Makefile
rc38e417 reaa0c3f 34 34 SOURCES = \ 35 35 src/nic_driver.c \ 36 src/nic_ev.c \37 36 src/nic_addr_db.c \ 38 37 src/nic_rx_control.c \ -
uspace/lib/nic/include/nic_driver.h
rc38e417 reaa0c3f 80 80 /** Device's default MAC address (assigned the first time, used in STOP) */ 81 81 nic_address_t default_mac; 82 /** Client callback session*/83 async_sess_t * client_session;82 /** Session to SERVICE_ETHERNET or SERVICE_NILDUMMY */ 83 async_sess_t *nil_session; 84 84 /** Phone to APIC or i8259 */ 85 85 async_sess_t *irc_session; -
uspace/lib/nic/include/nic_impl.h
rc38e417 reaa0c3f 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_callback_create_impl(ddf_fun_t *dev_fun, int device_id); 51 extern int nic_connect_to_nil_impl(ddf_fun_t *dev_fun, services_t nil_service, 52 int device_id); 52 53 extern int nic_get_state_impl(ddf_fun_t *dev_fun, nic_device_state_t *state); 53 54 extern int nic_set_state_impl(ddf_fun_t *dev_fun, nic_device_state_t state); -
uspace/lib/nic/src/nic_driver.c
rc38e417 reaa0c3f 53 53 54 54 #include "nic_driver.h" 55 #include "nic_ev.h"56 55 #include "nic_impl.h" 57 56 … … 107 106 if (!iface->send_frame) 108 107 iface->send_frame = nic_send_frame_impl; 109 if (!iface->c allback_create)110 iface->c allback_create = nic_callback_create_impl;108 if (!iface->connect_to_nil) 109 iface->connect_to_nil = nic_connect_to_nil_impl; 111 110 if (!iface->get_address) 112 111 iface->get_address = nic_get_address_impl; … … 495 494 496 495 /* Notify NIL layer (and uppper) if bound - not in add_device */ 497 if (nic_data-> client_session != NULL) {498 int rc = ni c_ev_addr_changed(nic_data->client_session,496 if (nic_data->nil_session != NULL) { 497 int rc = nil_addr_changed_msg(nic_data->nil_session, 499 498 nic_data->device_id, address); 500 499 if (rc != EOK) { … … 604 603 } 605 604 fibril_rwlock_write_unlock(&nic_data->stats_lock); 606 ni c_ev_received(nic_data->client_session, nic_data->device_id,605 nil_received_msg(nic_data->nil_session, nic_data->device_id, 607 606 frame->data, frame->size); 608 607 } else { … … 639 638 fibril_rwlock_write_unlock(&nic_data->stats_lock); 640 639 641 ni c_ev_received(nic_data->client_session, nic_data->device_id,640 nil_received_msg(nic_data->nil_session, nic_data->device_id, 642 641 data, size); 643 642 } … … 693 692 nic_data->device_id = NIC_DEVICE_INVALID_ID; 694 693 nic_data->state = NIC_STATE_STOPPED; 695 nic_data-> client_session = NULL;694 nic_data->nil_session = NULL; 696 695 nic_data->irc_session = NULL; 697 696 nic_data->poll_mode = NIC_POLL_IMMEDIATE; … … 747 746 */ 748 747 static void nic_destroy(nic_t *nic_data) { 749 if (nic_data-> client_session != NULL) {750 async_hangup(nic_data-> client_session);748 if (nic_data->nil_session != NULL) { 749 async_hangup(nic_data->nil_session); 751 750 } 752 751 -
uspace/lib/nic/src/nic_impl.c
rc38e417 reaa0c3f 40 40 #include <ns.h> 41 41 #include "nic_driver.h" 42 #include "nic_ev.h"43 42 #include "nic_impl.h" 44 43 … … 86 85 } 87 86 if (state == NIC_STATE_ACTIVE) { 88 if (nic_data-> client_session == NULL || nic_data->device_id < 0) {87 if (nic_data->nil_session == NULL || nic_data->device_id < 0) { 89 88 fibril_rwlock_write_unlock(&nic_data->main_lock); 90 89 return EINVAL; … … 116 115 if (state == NIC_STATE_STOPPED) { 117 116 /* Notify upper layers that we are reseting the MAC */ 118 int rc = ni c_ev_addr_changed(nic_data->client_session,117 int rc = nil_addr_changed_msg(nic_data->nil_session, 119 118 nic_data->device_id, &nic_data->default_mac); 120 119 nic_data->poll_mode = nic_data->default_poll_mode; … … 149 148 nic_data->state = state; 150 149 151 ni c_ev_device_state(nic_data->client_session, nic_data->device_id, state);150 nil_device_state_msg(nic_data->nil_session, nic_data->device_id, state); 152 151 153 152 fibril_rwlock_write_unlock(&nic_data->main_lock); … … 182 181 183 182 /** 184 * Default implementation of the connect_ clientmethod.185 * C reates callback connection to the client.183 * Default implementation of the connect_to_nil method. 184 * Connects the driver to the NIL service. 186 185 * 187 186 * @param fun 187 * @param nil_service ID of the server implementing the NIL service 188 188 * @param device_id ID of the device as used in higher layers 189 189 * 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); 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); 196 198 197 nic ->device_id = device_id;199 nic_data->device_id = device_id; 198 200 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; 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; 203 206 } 204 207 205 fibril_rwlock_write_unlock(&nic ->main_lock);206 return E OK;208 fibril_rwlock_write_unlock(&nic_data->main_lock); 209 return EHANGUP; 207 210 } 208 211 -
uspace/srv/net/net/net.c
rc38e417 reaa0c3f 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 3 * Copyright (c) 2011 Radim Vansa 4 * Copyright (c) 2011 Jiri Svoboda5 4 * All rights reserved. 6 5 * … … 364 363 break; 365 364 default: 366 printf("%s: Unknown service\n", NAME);367 365 return ENOENT; 368 366 } -
uspace/srv/net/nil/eth/eth.c
rc38e417 reaa0c3f 170 170 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t); 171 171 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) 172 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 176 173 { 177 174 int index; … … 347 344 } 348 345 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 } 346 nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id); 357 347 358 348 /* Get hardware address */ … … 832 822 833 823 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); 834 if (rc != EOK) { 835 printf("%s: data_write_accept() failed\n", NAME); 824 if (rc != EOK) 836 825 return rc; 837 }838 826 839 827 packet_t *packet = packet_get_1_remote(eth_globals.net_sess, size); … … 955 943 956 944 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 }993 960 } 994 961 -
uspace/srv/net/nil/nildummy/nildummy.c
rc38e417 reaa0c3f 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 3 * Copyright (c) 2011 Radim Vansa 4 * Copyright (c) 2011 Jiri Svoboda5 4 * All rights reserved. 6 5 * … … 70 69 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t); 71 70 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) 71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 76 72 { 77 73 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); … … 82 78 83 79 return EOK; 84 }85 86 static int nildummy_addr_changed(nic_device_id_t device_id)87 {88 return ENOTSUP;89 80 } 90 81 … … 182 173 } 183 174 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 } 175 nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id); 191 176 192 177 /* Get hardware address */ 193 rc = nic_get_address(device->sess, &device->addr);178 int rc = nic_get_address(device->sess, &device->addr); 194 179 if (rc != EOK) { 195 180 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 460 445 *answer_count = 1; 461 446 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; 462 457 } 463 458 464 459 return ENOTSUP; 465 460 } 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 500 461 501 462 int main(int argc, char *argv[])
Note:
See TracChangeset
for help on using the changeset viewer.