Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/nic/src/nic_driver.c

    r9cd8165 racdb5bac  
    4747#include <sysinfo.h>
    4848#include <as.h>
    49 #include <devman.h>
    5049#include <ddf/interrupt.h>
    5150#include <ops/nic.h>
     
    7978}
    8079
    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.
    8381 *
    8482 * @param driver_ops
     
    251249{
    252250        ddf_dev_t *dev = nic_data->dev;
     251        async_sess_t *parent_sess;
    253252       
    254253        /* 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)
    258256                return EPARTY;
    259257       
    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);
    261259}
    262260
     
    624622
    625623/**
    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 /**
    645624 * Some NICs can receive multiple frames during single interrupt. These can
    646625 * send them in whole list of frames (actually nic_frame_t structures), then
     
    670649 *
    671650 */
    672 static nic_t *nic_create(void)
    673 {
    674         nic_t *nic_data = malloc(sizeof(nic_t));
     651static nic_t *nic_create(ddf_dev_t *dev)
     652{
     653        nic_t *nic_data = ddf_dev_data_alloc(dev, sizeof(nic_t));
    675654        if (nic_data == NULL)
    676655                return NULL;
    677656       
    678657        /* Force zero to all uninitialized fields (e.g. added in future) */
    679         bzero(nic_data, sizeof(nic_t));
    680658        if (nic_rxc_init(&nic_data->rx_control) != EOK) {
    681                 free(nic_data);
    682659                return NULL;
    683660        }
    684661       
    685662        if (nic_wol_virtues_init(&nic_data->wol_virtues) != EOK) {
    686                 free(nic_data);
    687663                return NULL;
    688664        }
     
    706682        fibril_rwlock_initialize(&nic_data->wv_lock);
    707683       
    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));
    711687       
    712688        return nic_data;
     
    725701nic_t *nic_create_and_bind(ddf_dev_t *device)
    726702{
    727         assert(device);
    728         assert(!device->driver_data);
    729        
    730         nic_t *nic_data = nic_create();
     703        nic_t *nic_data = nic_create(device);
    731704        if (!nic_data)
    732705                return NULL;
    733706       
    734707        nic_data->dev = device;
    735         device->driver_data = nic_data;
    736708       
    737709        return nic_data;
     
    744716 * @param data
    745717 */
    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 
     718static void nic_destroy(nic_t *nic_data)
     719{
    751720        free(nic_data->specific);
    752         free(nic_data);
    753721}
    754722
     
    760728 * @param device The NIC device structure
    761729 */
    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;
     730void nic_unbind_and_destroy(ddf_dev_t *device)
     731{
     732        nic_destroy(nic_get_from_ddf_dev(device));
    770733        return;
    771734}
     
    1003966nic_t *nic_get_from_ddf_dev(ddf_dev_t *dev)
    1004967{
    1005         return (nic_t *) dev->driver_data;
    1006 };
     968        return (nic_t *) ddf_dev_data_get(dev);
     969}
    1007970
    1008971/**
     
    1012975nic_t *nic_get_from_ddf_fun(ddf_fun_t *fun)
    1013976{
    1014         return (nic_t *) fun->driver_data;
    1015 };
     977        return (nic_t *) ddf_fun_data_get(fun);
     978}
    1016979
    1017980/**
Note: See TracChangeset for help on using the changeset viewer.