Changeset e86b8f0 in mainline for uspace/drv/nic/lo/lo.c


Ignore:
Timestamp:
2012-01-21T12:50:28Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
77a69ea, 86c71de
Parents:
3fe58d3c
Message:

Create DDF functions manually.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/lo/lo.c

    r3fe58d3c re86b8f0  
    8080static int lo_dev_add(ddf_dev_t *dev)
    8181{
    82         nic_t *nic_data = nic_create_and_bind(dev);
    83         if (nic_data == NULL) {
     82        ddf_fun_t *fun = NULL;
     83        bool bound = false;
     84       
     85        nic_t *nic = nic_create_and_bind(dev);
     86        if (nic == NULL) {
    8487                printf("%s: Failed to initialize\n", NAME);
    8588                return ENOMEM;
    8689        }
    8790       
    88         dev->driver_data = nic_data;
    89         nic_set_send_frame_handler(nic_data, lo_send_frame);
     91        dev->driver_data = nic;
     92        nic_set_send_frame_handler(nic, lo_send_frame);
    9093       
    91         int rc = nic_connect_to_services(nic_data);
     94        int rc = nic_connect_to_services(nic);
    9295        if (rc != EOK) {
    9396                printf("%s: Failed to connect to services\n", NAME);
    94                 nic_unbind_and_destroy(dev);
    95                 return rc;
     97                goto error;
    9698        }
    9799       
    98         rc = nic_register_as_ddf_fun(nic_data, &lo_dev_ops);
     100        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
     101        if (fun == NULL) {
     102                printf("%s: Failed creating function\n", NAME);
     103                rc = ENOMEM;
     104                goto error;
     105        }
     106        nic_set_ddf_fun(nic, fun);
     107        fun->ops = &lo_dev_ops;
     108        fun->driver_data = nic;
     109       
     110        rc = nic_report_address(nic, &lo_addr);
    99111        if (rc != EOK) {
    100                 printf("%s: Failed to register as DDF function\n", NAME);
    101                 nic_unbind_and_destroy(dev);
    102                 return rc;
     112                printf("%s: Failed to setup loopback address\n", NAME);
     113                goto error;
    103114        }
    104115       
    105         rc = nic_report_address(nic_data, &lo_addr);
     116        rc = ddf_fun_bind(fun);
    106117        if (rc != EOK) {
    107                 printf("%s: Failed to setup loopback address\n", NAME);
    108                 nic_unbind_and_destroy(dev);
    109                 return rc;
     118                printf("%s: Failed binding function\n", NAME);
     119                goto error;
    110120        }
     121        bound = true;
     122       
     123        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     124        if (rc != EOK)
     125                goto error;
    111126       
    112127        printf("%s: Adding loopback device '%s'\n", NAME, dev->name);
    113128        return EOK;
     129error:
     130        if (bound)
     131                ddf_fun_unbind(fun);
     132        if (fun != NULL)
     133                ddf_fun_destroy(fun);
     134       
     135        nic_unbind_and_destroy(dev);
     136        return rc;
    114137}
    115138
Note: See TracChangeset for help on using the changeset viewer.