Changeset 6d8455d in mainline for uspace/lib/nic
- 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/nic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
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.