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