Changeset e86b8f0 in mainline for uspace/drv/nic


Ignore:
Timestamp:
2012-01-21T12:50:28Z (14 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.

Location:
uspace/drv/nic
Files:
4 edited

Legend:

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

    r3fe58d3c re86b8f0  
    20972097int e1000_dev_add(ddf_dev_t *dev)
    20982098{
     2099        ddf_fun_t *fun;
    20992100        assert(dev);
    21002101       
     
    21272128        e1000_initialize_vlan(e1000);
    21282129       
    2129         rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops);
    2130         if (rc != EOK)
     2130        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
     2131        if (fun == NULL)
    21312132                goto err_tx_structure;
     2133        nic_set_ddf_fun(nic, fun);
     2134        fun->ops = &e1000_dev_ops;
     2135        fun->driver_data = nic;
    21322136       
    21332137        rc = e1000_register_int_handler(nic);
    21342138        if (rc != EOK)
    2135                 goto err_tx_structure;
     2139                goto err_fun_create;
    21362140       
    21372141        rc = nic_connect_to_services(nic);
     
    21562160                goto err_rx_structure;
    21572161       
     2162        rc = ddf_fun_bind(fun);
     2163        if (rc != EOK)
     2164                goto err_fun_bind;
     2165       
     2166        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     2167        if (rc != EOK)
     2168                goto err_add_to_cat;
     2169       
    21582170        return EOK;
    21592171       
     2172err_add_to_cat:
     2173        ddf_fun_unbind(fun);
     2174err_fun_bind:
    21602175err_rx_structure:
    21612176        e1000_uninitialize_rx_structure(nic);
    21622177err_irq:
    21632178        unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq);
     2179err_fun_create:
     2180        ddf_fun_destroy(fun);
     2181        nic_set_ddf_fun(nic, NULL);
    21642182err_tx_structure:
    21652183        e1000_uninitialize_tx_structure(e1000);
  • 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
  • uspace/drv/nic/ne2k/ne2k.c

    r3fe58d3c re86b8f0  
    338338static int ne2k_dev_add(ddf_dev_t *dev)
    339339{
     340        ddf_fun_t *fun;
     341       
    340342        /* Allocate driver data for the device. */
    341343        nic_t *nic_data = nic_create_and_bind(dev);
     
    371373        }
    372374       
    373         rc = nic_register_as_ddf_fun(nic_data, &ne2k_dev_ops);
     375        rc = nic_connect_to_services(nic_data);
    374376        if (rc != EOK) {
    375377                ne2k_dev_cleanup(dev);
     
    377379        }
    378380       
    379         rc = nic_connect_to_services(nic_data);
    380         if (rc != EOK) {
     381        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     382        if (fun == NULL) {
    381383                ne2k_dev_cleanup(dev);
     384                return ENOMEM;
     385        }
     386        nic_set_ddf_fun(nic_data, fun);
     387        fun->ops = &ne2k_dev_ops;
     388        fun->driver_data = nic_data;
     389       
     390        rc = ddf_fun_bind(fun);
     391        if (rc != EOK) {
     392                ddf_fun_destroy(fun);
     393                ne2k_dev_cleanup(dev);
     394                return rc;
     395        }
     396       
     397        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     398        if (rc != EOK) {
     399                ddf_fun_unbind(fun);
     400                ddf_fun_destroy(fun);
    382401                return rc;
    383402        }
  • uspace/drv/nic/rtl8139/driver.c

    r3fe58d3c re86b8f0  
    12801280int rtl8139_dev_add(ddf_dev_t *dev)
    12811281{
     1282        ddf_fun_t *fun;
     1283
    12821284        assert(dev);
    12831285        ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle);
     
    13161318        }
    13171319
    1318         rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops);
     1320        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     1321        if (fun == NULL) {
     1322                ddf_msg(LVL_ERROR, "Failed creating device function");
     1323                goto err_srv;
     1324        }
     1325        nic_set_ddf_fun(nic_data, fun);
     1326        fun->ops = &rtl8139_dev_ops;
     1327        fun->driver_data = nic_data;
     1328
     1329        rc = ddf_fun_bind(fun);
    13191330        if (rc != EOK) {
    1320                 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc);
    1321                 goto err_irq;
     1331                ddf_msg(LVL_ERROR, "Failed binding device function");
     1332                goto err_fun_create;
     1333        }
     1334        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     1335        if (rc != EOK) {
     1336                ddf_msg(LVL_ERROR, "Failed adding function to category");
     1337                goto err_fun_bind;
    13221338        }
    13231339
     
    13271343        return EOK;
    13281344
     1345err_fun_bind:
     1346        ddf_fun_unbind(fun);
     1347err_fun_create:
     1348        ddf_fun_destroy(fun);
     1349err_srv:
     1350        /* XXX Disconnect from services */
    13291351err_irq:
    13301352        unregister_interrupt_handler(dev, rtl8139->irq);
Note: See TracChangeset for help on using the changeset viewer.