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


Ignore:
Timestamp:
2012-02-09T20:35:12Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
591762c6
Parents:
7cede12c (diff), 3d4750f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    r7cede12c rb7068da  
    4242#include <async.h>
    4343#include <nic.h>
    44 #include <packet_client.h>
    4544
    4645#define NAME  "lo"
     
    5958};
    6059
    61 static void lo_write_packet(nic_t *nic_data, packet_t *packet)
     60static void lo_send_frame(nic_t *nic_data, void *data, size_t size)
    6261{
    63         nic_report_send_ok(nic_data, 1, packet_get_data_length(packet));
    64         nic_received_noneth_packet(nic_data, packet);
     62        nic_report_send_ok(nic_data, 1, size);
     63        nic_received_noneth_frame(nic_data, data, size);
    6564}
    6665
     
    8180static int lo_dev_add(ddf_dev_t *dev)
    8281{
    83         nic_t *nic_data = nic_create_and_bind(dev);
    84         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) {
    8587                printf("%s: Failed to initialize\n", NAME);
    8688                return ENOMEM;
    8789        }
    8890       
    89         dev->driver_data = nic_data;
    90         nic_set_write_packet_handler(nic_data, lo_write_packet);
     91        dev->driver_data = nic;
     92        nic_set_send_frame_handler(nic, lo_send_frame);
    9193       
    92         int rc = nic_connect_to_services(nic_data);
     94        int rc = nic_connect_to_services(nic);
    9395        if (rc != EOK) {
    9496                printf("%s: Failed to connect to services\n", NAME);
    95                 nic_unbind_and_destroy(dev);
    96                 return rc;
     97                goto error;
    9798        }
    9899       
    99         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);
    100111        if (rc != EOK) {
    101                 printf("%s: Failed to register as DDF function\n", NAME);
    102                 nic_unbind_and_destroy(dev);
    103                 return rc;
     112                printf("%s: Failed to setup loopback address\n", NAME);
     113                goto error;
    104114        }
    105115       
    106         rc = nic_report_address(nic_data, &lo_addr);
     116        rc = ddf_fun_bind(fun);
    107117        if (rc != EOK) {
    108                 printf("%s: Failed to setup loopback address\n", NAME);
    109                 nic_unbind_and_destroy(dev);
    110                 return rc;
     118                printf("%s: Failed binding function\n", NAME);
     119                goto error;
    111120        }
     121        bound = true;
     122       
     123        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     124        if (rc != EOK)
     125                goto error;
    112126       
    113127        printf("%s: Adding loopback device '%s'\n", NAME, dev->name);
    114128        return EOK;
     129       
     130error:
     131        if (bound)
     132                ddf_fun_unbind(fun);
     133       
     134        if (fun != NULL)
     135                ddf_fun_destroy(fun);
     136       
     137        nic_unbind_and_destroy(dev);
     138        return rc;
    115139}
    116140
Note: See TracChangeset for help on using the changeset viewer.