Ignore:
File:
1 edited

Legend:

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

    racdb5bac r9cd8165  
    4747#include <sysinfo.h>
    4848#include <as.h>
     49#include <devman.h>
    4950#include <ddf/interrupt.h>
    5051#include <ops/nic.h>
     
    7879}
    7980
    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.
    8183 *
    8284 * @param driver_ops
     
    249251{
    250252        ddf_dev_t *dev = nic_data->dev;
    251         async_sess_t *parent_sess;
    252253       
    253254        /* 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)
    256258                return EPARTY;
    257259       
    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);
    259261}
    260262
     
    622624
    623625/**
     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 */
     634void 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/**
    624645 * Some NICs can receive multiple frames during single interrupt. These can
    625646 * send them in whole list of frames (actually nic_frame_t structures), then
     
    649670 *
    650671 */
    651 static nic_t *nic_create(ddf_dev_t *dev)
    652 {
    653         nic_t *nic_data = ddf_dev_data_alloc(dev, sizeof(nic_t));
     672static nic_t *nic_create(void)
     673{
     674        nic_t *nic_data = malloc(sizeof(nic_t));
    654675        if (nic_data == NULL)
    655676                return NULL;
    656677       
    657678        /* Force zero to all uninitialized fields (e.g. added in future) */
     679        bzero(nic_data, sizeof(nic_t));
    658680        if (nic_rxc_init(&nic_data->rx_control) != EOK) {
     681                free(nic_data);
    659682                return NULL;
    660683        }
    661684       
    662685        if (nic_wol_virtues_init(&nic_data->wol_virtues) != EOK) {
     686                free(nic_data);
    663687                return NULL;
    664688        }
     
    682706        fibril_rwlock_initialize(&nic_data->wv_lock);
    683707       
    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));
    687711       
    688712        return nic_data;
     
    701725nic_t *nic_create_and_bind(ddf_dev_t *device)
    702726{
    703         nic_t *nic_data = nic_create(device);
     727        assert(device);
     728        assert(!device->driver_data);
     729       
     730        nic_t *nic_data = nic_create();
    704731        if (!nic_data)
    705732                return NULL;
    706733       
    707734        nic_data->dev = device;
     735        device->driver_data = nic_data;
    708736       
    709737        return nic_data;
     
    716744 * @param data
    717745 */
    718 static void nic_destroy(nic_t *nic_data)
    719 {
     746static void nic_destroy(nic_t *nic_data) {
     747        if (nic_data->client_session != NULL) {
     748                async_hangup(nic_data->client_session);
     749        }
     750
    720751        free(nic_data->specific);
     752        free(nic_data);
    721753}
    722754
     
    728760 * @param device The NIC device structure
    729761 */
    730 void nic_unbind_and_destroy(ddf_dev_t *device)
    731 {
    732         nic_destroy(nic_get_from_ddf_dev(device));
     762void 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;
    733770        return;
    734771}
     
    9661003nic_t *nic_get_from_ddf_dev(ddf_dev_t *dev)
    9671004{
    968         return (nic_t *) ddf_dev_data_get(dev);
    969 }
     1005        return (nic_t *) dev->driver_data;
     1006};
    9701007
    9711008/**
     
    9751012nic_t *nic_get_from_ddf_fun(ddf_fun_t *fun)
    9761013{
    977         return (nic_t *) ddf_fun_data_get(fun);
    978 }
     1014        return (nic_t *) fun->driver_data;
     1015};
    9791016
    9801017/**
Note: See TracChangeset for help on using the changeset viewer.