Changeset 1bc35b5 in mainline for uspace/lib/nic/src/nic_driver.c
- Timestamp:
- 2012-01-19T08:13:45Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d8da56b
- Parents:
- 3ea725e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.