Changes in uspace/lib/nic/src/nic_driver.c [acdb5bac:9cd8165] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/nic/src/nic_driver.c
racdb5bac r9cd8165 47 47 #include <sysinfo.h> 48 48 #include <as.h> 49 #include <devman.h> 49 50 #include <ddf/interrupt.h> 50 51 #include <ops/nic.h> … … 78 79 } 79 80 80 /** Fill in the default implementations for device options and NIC interface. 81 /** 82 * Fill in the default implementations for device options and NIC interface. 81 83 * 82 84 * @param driver_ops … … 249 251 { 250 252 ddf_dev_t *dev = nic_data->dev; 251 async_sess_t *parent_sess;252 253 253 254 /* Connect to the parent's driver. */ 254 parent_sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE); 255 if (parent_sess == NULL) 255 dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE, 256 dev->handle, IPC_FLAG_BLOCKING); 257 if (dev->parent_sess == NULL) 256 258 return EPARTY; 257 259 258 return hw_res_get_list_parsed( parent_sess, resources, 0);260 return hw_res_get_list_parsed(nic_data->dev->parent_sess, resources, 0); 259 261 } 260 262 … … 622 624 623 625 /** 626 * This function is to be used only in the loopback driver. It's workaround 627 * for the situation when the frame does not contain ethernet address. 628 * The filtering is therefore not applied here. 629 * 630 * @param nic_data 631 * @param data Frame data 632 * @param size Frame size in bytes 633 */ 634 void nic_received_noneth_frame(nic_t *nic_data, void *data, size_t size) 635 { 636 fibril_rwlock_write_lock(&nic_data->stats_lock); 637 nic_data->stats.receive_packets++; 638 nic_data->stats.receive_bytes += size; 639 fibril_rwlock_write_unlock(&nic_data->stats_lock); 640 641 nic_ev_received(nic_data->client_session, data, size); 642 } 643 644 /** 624 645 * Some NICs can receive multiple frames during single interrupt. These can 625 646 * send them in whole list of frames (actually nic_frame_t structures), then … … 649 670 * 650 671 */ 651 static nic_t *nic_create( ddf_dev_t *dev)652 { 653 nic_t *nic_data = ddf_dev_data_alloc(dev,sizeof(nic_t));672 static nic_t *nic_create(void) 673 { 674 nic_t *nic_data = malloc(sizeof(nic_t)); 654 675 if (nic_data == NULL) 655 676 return NULL; 656 677 657 678 /* Force zero to all uninitialized fields (e.g. added in future) */ 679 bzero(nic_data, sizeof(nic_t)); 658 680 if (nic_rxc_init(&nic_data->rx_control) != EOK) { 681 free(nic_data); 659 682 return NULL; 660 683 } 661 684 662 685 if (nic_wol_virtues_init(&nic_data->wol_virtues) != EOK) { 686 free(nic_data); 663 687 return NULL; 664 688 } … … 682 706 fibril_rwlock_initialize(&nic_data->wv_lock); 683 707 684 memset(&nic_data->mac, 0, sizeof(nic_address_t));685 memset(&nic_data->default_mac, 0, sizeof(nic_address_t));686 memset(&nic_data->stats, 0, sizeof(nic_device_stats_t));708 bzero(&nic_data->mac, sizeof(nic_address_t)); 709 bzero(&nic_data->default_mac, sizeof(nic_address_t)); 710 bzero(&nic_data->stats, sizeof(nic_device_stats_t)); 687 711 688 712 return nic_data; … … 701 725 nic_t *nic_create_and_bind(ddf_dev_t *device) 702 726 { 703 nic_t *nic_data = nic_create(device); 727 assert(device); 728 assert(!device->driver_data); 729 730 nic_t *nic_data = nic_create(); 704 731 if (!nic_data) 705 732 return NULL; 706 733 707 734 nic_data->dev = device; 735 device->driver_data = nic_data; 708 736 709 737 return nic_data; … … 716 744 * @param data 717 745 */ 718 static void nic_destroy(nic_t *nic_data) 719 { 746 static void nic_destroy(nic_t *nic_data) { 747 if (nic_data->client_session != NULL) { 748 async_hangup(nic_data->client_session); 749 } 750 720 751 free(nic_data->specific); 752 free(nic_data); 721 753 } 722 754 … … 728 760 * @param device The NIC device structure 729 761 */ 730 void nic_unbind_and_destroy(ddf_dev_t *device) 731 { 732 nic_destroy(nic_get_from_ddf_dev(device)); 762 void nic_unbind_and_destroy(ddf_dev_t *device){ 763 if (!device) 764 return; 765 if (!device->driver_data) 766 return; 767 768 nic_destroy((nic_t *) device->driver_data); 769 device->driver_data = NULL; 733 770 return; 734 771 } … … 966 1003 nic_t *nic_get_from_ddf_dev(ddf_dev_t *dev) 967 1004 { 968 return (nic_t *) d df_dev_data_get(dev);969 } 1005 return (nic_t *) dev->driver_data; 1006 }; 970 1007 971 1008 /** … … 975 1012 nic_t *nic_get_from_ddf_fun(ddf_fun_t *fun) 976 1013 { 977 return (nic_t *) ddf_fun_data_get(fun);978 } 1014 return (nic_t *) fun->driver_data; 1015 }; 979 1016 980 1017 /**
Note:
See TracChangeset
for help on using the changeset viewer.