Changeset 1bc35b5 in mainline for uspace/lib
- Timestamp:
- 2012-01-19T08:13:45Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d8da56b
- Parents:
- 3ea725e
- Location:
- uspace/lib
- Files:
-
- 6 edited
-
net/include/nil_remote.h (modified) (2 diffs)
-
net/nil/nil_remote.c (modified) (1 diff)
-
nic/include/nic.h (modified) (2 diffs)
-
nic/include/nic_rx_control.h (modified) (1 diff)
-
nic/src/nic_driver.c (modified) (9 diffs)
-
nic/src/nic_rx_control.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/include/nil_remote.h
r3ea725e r1bc35b5 39 39 #include <generic.h> 40 40 #include <async.h> 41 #include <sys/types.h> 41 42 42 43 #define nil_bind_service(service, device_id, me, receiver) \ … … 61 62 size_t); 62 63 extern int nil_device_state_msg(async_sess_t *, nic_device_id_t, sysarg_t); 63 extern int nil_received_msg(async_sess_t *, nic_device_id_t, packet_id_t);64 extern int nil_received_msg(async_sess_t *, nic_device_id_t, void *, size_t); 64 65 extern int nil_addr_changed_msg(async_sess_t *, nic_device_id_t, 65 66 const nic_address_t *); -
uspace/lib/net/nil/nil_remote.c
r3ea725e r1bc35b5 77 77 */ 78 78 int nil_received_msg(async_sess_t *sess, nic_device_id_t device_id, 79 packet_id_t packet_id)79 void *data, size_t size) 80 80 { 81 return generic_received_msg_remote(sess, NET_NIL_RECEIVED, 82 device_id, packet_id, 0, 0); 81 async_exch_t *exch = async_exchange_begin(sess); 82 83 ipc_call_t answer; 84 aid_t req = async_send_1(exch, NET_NIL_RECEIVED, (sysarg_t) device_id, 85 &answer); 86 sysarg_t retval = async_data_write_start(exch, data, size); 87 88 async_exchange_end(exch); 89 90 if (retval != EOK) { 91 async_wait_for(req, NULL); 92 return retval; 93 } 94 95 async_wait_for(req, &retval); 96 return retval; 83 97 } 84 98 -
uspace/lib/nic/include/nic.h
r3ea725e r1bc35b5 61 61 62 62 /** 63 * Simple structure for sending the allocated frames (packets) in a list.63 * Simple structure for sending lists of frames. 64 64 */ 65 65 typedef struct { 66 66 link_t link; 67 packet_t *packet; 67 void *data; 68 size_t size; 68 69 } nic_frame_t; 69 70 … … 233 234 extern int nic_report_poll_mode(nic_t *, nic_poll_mode_t, struct timeval *); 234 235 extern void nic_query_address(nic_t *, nic_address_t *); 235 extern void nic_received_packet(nic_t *, packet_t *);236 236 extern void nic_received_noneth_packet(nic_t *, packet_t *); 237 237 extern void nic_received_frame(nic_t *, nic_frame_t *); -
uspace/lib/nic/include/nic_rx_control.h
r3ea725e r1bc35b5 120 120 const nic_address_t *prev_addr, const nic_address_t *curr_addr); 121 121 extern int nic_rxc_check(const nic_rxc_t *rxc, 122 const packet_t *packet, nic_frame_type_t *frame_type);122 const void *data, size_t size, nic_frame_type_t *frame_type); 123 123 extern void nic_rxc_hw_filtering(nic_rxc_t *rxc, 124 124 int unicast_exact, int multicast_exact, int vlan_exact); -
uspace/lib/nic/src/nic_driver.c
r3ea725e r1bc35b5 290 290 * 291 291 * @param nic_data The NIC driver data 292 * @param packet_size Size of packet 293 * @param offload_size Size of packet offload 292 * @param size Frame size in bytes 294 293 * @return pointer to allocated frame if success, NULL otherwise 295 294 */ 296 nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t packet_size)295 nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t size) 297 296 { 298 297 nic_frame_t *frame; … … 313 312 } 314 313 315 packet_t *packet = nic_alloc_packet(nic_data, packet_size);316 if ( !packet) {314 frame->data = malloc(size); 315 if (frame->data == NULL) { 317 316 free(frame); 318 317 return NULL; 319 318 } 320 319 321 frame-> packet = packet;320 frame->size = size; 322 321 return frame; 323 322 } … … 332 331 if (!frame) 333 332 return; 334 if (frame->packet != NULL) { 335 nic_release_packet(nic_data, frame->packet); 336 } 333 334 if (frame->data != NULL) { 335 free(frame->data); 336 frame->data = NULL; 337 frame->size = 0; 338 } 339 337 340 fibril_mutex_lock(&nic_globals.lock); 338 341 if (nic_globals.frame_cache_size >= NIC_GLOBALS_MAX_CACHE_SIZE) { … … 622 625 623 626 /** 624 * Provided for correct naming conventions.625 * The packetis checked by filters and then sent up to the NIL layer or626 * discarded , the frame is released.627 * 628 * @param nic_data 629 * @param frame The frame containing received packet627 * This is the function that the driver should call when it receives a frame. 628 * The frame is checked by filters and then sent up to the NIL layer or 629 * discarded. The frame is released. 630 * 631 * @param nic_data 632 * @param frame The received frame 630 633 */ 631 634 void nic_received_frame(nic_t *nic_data, nic_frame_t *frame) 632 {633 nic_received_packet(nic_data, frame->packet);634 frame->packet = NULL;635 nic_release_frame(nic_data, frame);636 }637 638 /**639 * This is the function that the driver should call when it receives a packet.640 * The packet is checked by filters and then sent up to the NIL layer or641 * discarded.642 *643 * @param nic_data644 * @param packet The received packet645 */646 void nic_received_packet(nic_t *nic_data, packet_t *packet)647 635 { 648 636 /* Note: this function must not lock main lock, because loopback driver 649 637 * calls it inside write_packet handler (with locked main lock) */ 650 packet_id_t pid = packet_get_id(packet);651 652 638 fibril_rwlock_read_lock(&nic_data->rxc_lock); 653 639 nic_frame_type_t frame_type; 654 int check = nic_rxc_check(&nic_data->rx_control, packet, &frame_type); 640 int check = nic_rxc_check(&nic_data->rx_control, frame->data, 641 frame->size, &frame_type); 655 642 fibril_rwlock_read_unlock(&nic_data->rxc_lock); 656 643 /* Update statistics */ … … 659 646 if (nic_data->state == NIC_STATE_ACTIVE && check) { 660 647 nic_data->stats.receive_packets++; 661 nic_data->stats.receive_bytes += packet_get_data_length(packet);648 nic_data->stats.receive_bytes += frame->size; 662 649 switch (frame_type) { 663 650 case NIC_FRAME_MULTICAST: … … 671 658 } 672 659 fibril_rwlock_write_unlock(&nic_data->stats_lock); 673 nil_received_msg(nic_data->nil_session, nic_data->device_id, pid); 660 nil_received_msg(nic_data->nil_session, nic_data->device_id, 661 frame->data, frame->size); 674 662 } else { 675 663 switch (frame_type) { … … 685 673 } 686 674 fibril_rwlock_write_unlock(&nic_data->stats_lock); 687 nic_release_packet(nic_data, packet);688 }675 } 676 nic_release_frame(nic_data, frame); 689 677 } 690 678 … … 705 693 706 694 nil_received_msg(nic_data->nil_session, nic_data->device_id, 707 packet_get_ id(packet));695 packet_get_data(packet), packet_get_data_length(packet)); 708 696 } 709 697 … … 726 714 727 715 list_remove(&frame->link); 728 nic_received_packet(nic_data, frame->packet); 729 frame->packet = NULL; 730 nic_release_frame(nic_data, frame); 716 nic_received_frame(nic_data, frame); 731 717 } 732 718 nic_driver_release_frame_list(frames); -
uspace/lib/nic/src/nic_rx_control.c
r3ea725e r1bc35b5 392 392 * 393 393 * @param rxc 394 * @param packetThe probed frame394 * @param frame The probed frame 395 395 * 396 396 * @return True if the frame passes, false if it does not 397 397 */ 398 int nic_rxc_check(const nic_rxc_t *rxc, const packet_t *packet,398 int nic_rxc_check(const nic_rxc_t *rxc, const void *data, size_t size, 399 399 nic_frame_type_t *frame_type) 400 400 { 401 401 assert(frame_type != NULL); 402 uint8_t *dest_addr = (uint8_t *) packet + packet->data_start;402 uint8_t *dest_addr = (uint8_t *) data; 403 403 uint8_t *src_addr = dest_addr + ETH_ADDR; 404 405 if (size < 2 * ETH_ADDR) 406 return false; 404 407 405 408 if (dest_addr[0] & 1) { … … 448 451 if (!rxc->vlan_exact && rxc->vlan_mask != NULL) { 449 452 vlan_header_t *vlan_header = (vlan_header_t *) 450 ((uint8_t *) packet + packet->data_start+ 2 * ETH_ADDR);453 ((uint8_t *) data + 2 * ETH_ADDR); 451 454 if (vlan_header->tpid_upper == VLAN_TPID_UPPER && 452 455 vlan_header->tpid_lower == VLAN_TPID_LOWER) {
Note:
See TracChangeset
for help on using the changeset viewer.
