Changeset 6d8455d in mainline for uspace/lib
- Timestamp:
- 2012-01-14T11:07:34Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f302586
- Parents:
- f991b6b
- Location:
- uspace/lib
- Files:
-
- 9 edited
-
c/generic/device/nic.c (modified) (1 diff)
-
c/include/device/nic.h (modified) (1 diff)
-
drv/generic/remote_nic.c (modified) (2 diffs)
-
drv/include/ops/nic.h (modified) (2 diffs)
-
nic/include/nic.h (modified) (2 diffs)
-
nic/include/nic_driver.h (modified) (1 diff)
-
nic/include/nic_impl.h (modified) (1 diff)
-
nic/src/nic_driver.c (modified) (3 diffs)
-
nic/src/nic_impl.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/nic.c
rf991b6b r6d8455d 44 44 #include <ipc/services.h> 45 45 46 /** Send a packet through the device 47 * 48 * @param[in] dev_sess 49 * @param[in] packet_id Id of the sent packet 50 * 51 * @return EOK If the operation was successfully completed 52 * 53 */ 54 int nic_send_message(async_sess_t *dev_sess, packet_id_t packet_id) 55 { 56 async_exch_t *exch = async_exchange_begin(dev_sess); 57 int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 58 NIC_SEND_MESSAGE, packet_id); 59 async_exchange_end(exch); 60 61 return rc; 46 /** Send frame from NIC 47 * 48 * @param[in] dev_sess 49 * @param[in] data Frame data 50 * @param[in] size Frame size in bytes 51 * 52 * @return EOK If the operation was successfully completed 53 * 54 */ 55 int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size) 56 { 57 async_exch_t *exch = async_exchange_begin(dev_sess); 58 59 ipc_call_t answer; 60 aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 61 NIC_SEND_MESSAGE, &answer); 62 sysarg_t retval = async_data_write_start(exch, data, size); 63 64 async_exchange_end(exch); 65 66 if (retval != EOK) { 67 async_wait_for(req, NULL); 68 return retval; 69 } 70 71 async_wait_for(req, &retval); 72 return retval; 62 73 } 63 74 -
uspace/lib/c/include/device/nic.h
rf991b6b r6d8455d 85 85 } nic_funcs_t; 86 86 87 extern int nic_send_ message(async_sess_t *, packet_id_t);87 extern int nic_send_frame(async_sess_t *, void *, size_t); 88 88 extern int nic_connect_to_nil(async_sess_t *, services_t, nic_device_id_t); 89 89 extern int nic_get_state(async_sess_t *, nic_device_state_t *); -
uspace/lib/drv/generic/remote_nic.c
rf991b6b r6d8455d 39 39 #include <errno.h> 40 40 #include <ipc/services.h> 41 #include <adt/measured_strings.h>42 41 #include <sys/time.h> 43 42 #include "ops/nic.h" 44 43 45 static void remote_nic_send_message(ddf_fun_t *dev, void *iface, 46 ipc_callid_t callid, ipc_call_t *call) 47 { 48 nic_iface_t *nic_iface = (nic_iface_t *) iface; 49 assert(nic_iface->send_message); 50 51 packet_id_t packet_id = (packet_id_t) IPC_GET_ARG2(*call); 52 53 int rc = nic_iface->send_message(dev, packet_id); 54 async_answer_0(callid, rc); 44 static void remote_nic_send_frame(ddf_fun_t *dev, void *iface, 45 ipc_callid_t callid, ipc_call_t *call) 46 { 47 nic_iface_t *nic_iface = (nic_iface_t *) iface; 48 assert(nic_iface->send_frame); 49 50 void *data; 51 size_t size; 52 int rc; 53 54 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); 55 if (rc != EOK) { 56 async_answer_0(callid, EINVAL); 57 return; 58 } 59 60 rc = nic_iface->send_frame(dev, data, size); 61 async_answer_0(callid, rc); 62 free(data); 55 63 } 56 64 … … 1194 1202 */ 1195 1203 static remote_iface_func_ptr_t remote_nic_iface_ops[] = { 1196 &remote_nic_send_ message,1204 &remote_nic_send_frame, 1197 1205 &remote_nic_connect_to_nil, 1198 1206 &remote_nic_get_state, -
uspace/lib/drv/include/ops/nic.h
rf991b6b r6d8455d 37 37 #define LIBDRV_OPS_NIC_H_ 38 38 39 #include <net/packet.h>40 39 #include <ipc/services.h> 41 40 #include <net/device.h> … … 46 45 typedef struct nic_iface { 47 46 /** Mandatory methods */ 48 int (*send_ message)(ddf_fun_t *, packet_id_t);47 int (*send_frame)(ddf_fun_t *, void *, size_t); 49 48 int (*connect_to_nil)(ddf_fun_t *, services_t, nic_device_id_t); 50 49 int (*get_state)(ddf_fun_t *, nic_device_state_t *); -
uspace/lib/nic/include/nic.h
rf991b6b r6d8455d 77 77 * 78 78 * @param nic_data 79 * @param packet Pointer to the packet to be sent 80 */ 81 typedef void (*write_packet_handler)(nic_t *, packet_t *); 79 * @param data Pointer to frame data 80 * @param size Size of frame data in bytes 81 */ 82 typedef void (*send_frame_handler)(nic_t *, void *, size_t); 82 83 /** 83 84 * The handler for transitions between driver states. … … 206 207 extern int nic_get_resources(nic_t *, hw_res_list_parsed_t *); 207 208 extern void nic_set_specific(nic_t *, void *); 208 extern void nic_set_ write_packet_handler(nic_t *, write_packet_handler);209 extern void nic_set_send_frame_handler(nic_t *, send_frame_handler); 209 210 extern void nic_set_state_change_handlers(nic_t *, 210 211 state_change_handler, state_change_handler, state_change_handler); -
uspace/lib/nic/include/nic_driver.h
rf991b6b r6d8455d 134 134 * Called with the main_lock locked for reading. 135 135 */ 136 write_packet_handler write_packet;136 send_frame_handler send_frame; 137 137 /** 138 138 * Event handler called when device goes to the ACTIVE state. -
uspace/lib/nic/include/nic_impl.h
rf991b6b r6d8455d 48 48 49 49 extern int nic_get_address_impl(ddf_fun_t *dev_fun, nic_address_t *address); 50 extern int nic_send_ message_impl(ddf_fun_t *dev_fun, packet_id_t packet_id);50 extern int nic_send_frame_impl(ddf_fun_t *dev_fun, void *data, size_t size); 51 51 extern int nic_connect_to_nil_impl(ddf_fun_t *dev_fun, services_t nil_service, 52 52 int device_id); -
uspace/lib/nic/src/nic_driver.c
rf991b6b r6d8455d 114 114 if (!iface->set_state) 115 115 iface->set_state = nic_set_state_impl; 116 if (!iface->send_ message)117 iface->send_ message = nic_send_message_impl;116 if (!iface->send_frame) 117 iface->send_frame = nic_send_frame_impl; 118 118 if (!iface->connect_to_nil) 119 119 iface->connect_to_nil = nic_connect_to_nil_impl; … … 168 168 * 169 169 * @param nic_data 170 * @param wpfunc Function handling the write_packetrequest171 */ 172 void nic_set_ write_packet_handler(nic_t *nic_data, write_packet_handler wpfunc)173 { 174 nic_data-> write_packet = wpfunc;170 * @param sffunc Function handling the send_frame request 171 */ 172 void nic_set_send_frame_handler(nic_t *nic_data, send_frame_handler sffunc) 173 { 174 nic_data->send_frame = sffunc; 175 175 } 176 176 … … 765 765 nic_data->poll_mode = NIC_POLL_IMMEDIATE; 766 766 nic_data->default_poll_mode = NIC_POLL_IMMEDIATE; 767 nic_data-> write_packet= NULL;767 nic_data->send_frame = NULL; 768 768 nic_data->on_activating = NULL; 769 769 nic_data->on_going_down = NULL; -
uspace/lib/nic/src/nic_impl.c
rf991b6b r6d8455d 39 39 #include <ipc/services.h> 40 40 #include <ns.h> 41 #include <packet_client.h>42 #include <packet_remote.h>43 41 #include "nic_driver.h" 44 42 #include "nic_impl.h" … … 159 157 160 158 /** 161 * Default implementation of the send_ message method.159 * Default implementation of the send_frame method. 162 160 * Send messages to the network. 163 161 * 164 162 * @param fun 165 * @param packet_id ID of the first packet in a queue of sent packets 163 * @param data Frame data 164 * @param size Frame size in bytes 166 165 * 167 166 * @return EOK If the message was sent 168 * @return EBUSY If the device is not in state when the packet can be set. 169 * @return EINVAL If the packet ID is invalid 170 */ 171 int nic_send_message_impl(ddf_fun_t *fun, packet_id_t packet_id) 172 { 173 nic_t *nic_data = (nic_t *) fun->driver_data; 174 packet_t *packet, *next; 167 * @return EBUSY If the device is not in state when the frame can be sent. 168 */ 169 int nic_send_frame_impl(ddf_fun_t *fun, void *data, size_t size) 170 { 171 nic_t *nic_data = (nic_t *) fun->driver_data; 175 172 176 173 fibril_rwlock_read_lock(&nic_data->main_lock); 177 174 if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) { 178 175 fibril_rwlock_read_unlock(&nic_data->main_lock); 179 pq_release_remote(nic_data->net_session, packet_id);180 176 return EBUSY; 181 177 } 182 178 183 int rc = packet_translate_remote(nic_data->net_session, &packet, packet_id); 184 185 if (rc != EOK) { 186 fibril_rwlock_read_unlock(&nic_data->main_lock); 187 return EINVAL; 188 } 189 190 /* 191 * Process the packet queue. Each sent packet must be detached from the 192 * queue and destroyed. This is why the cycle differs from loopback's 193 * cycle, where the packets are immediately used in upper layers and 194 * therefore they must not be destroyed (released). 195 */ 196 assert(nic_data->write_packet != NULL); 197 do { 198 next = pq_detach(packet); 199 nic_data->write_packet(nic_data, packet); 200 packet = next; 201 } while (packet); 202 fibril_rwlock_read_unlock(&nic_data->main_lock); 179 nic_data->send_frame(nic_data, data, size); 203 180 return EOK; 204 181 }
Note:
See TracChangeset
for help on using the changeset viewer.
