Changes in uspace/drv/nic/lo/lo.c [6d8455d:5cc9eba] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/lo/lo.c
r6d8455d r5cc9eba 42 42 #include <async.h> 43 43 #include <nic.h> 44 #include <packet_client.h>45 44 46 45 #define NAME "lo" … … 61 60 static void lo_send_frame(nic_t *nic_data, void *data, size_t size) 62 61 { 63 packet_t *packet;64 int rc;65 66 packet = nic_alloc_packet(nic_data, size);67 if (packet == NULL)68 return;69 70 rc = packet_copy_data(packet, data, size);71 if (rc != EOK)72 return;73 74 62 nic_report_send_ok(nic_data, 1, size); 75 nic_received_noneth_ packet(nic_data, packet);63 nic_received_noneth_frame(nic_data, data, size); 76 64 } 77 65 … … 92 80 static int lo_dev_add(ddf_dev_t *dev) 93 81 { 94 nic_t *nic_data = nic_create_and_bind(dev); 95 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) { 96 87 printf("%s: Failed to initialize\n", NAME); 97 88 return ENOMEM; 98 89 } 99 90 100 dev->driver_data = nic _data;101 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); 102 93 103 int rc = nic_connect_to_services(nic _data);94 int rc = nic_connect_to_services(nic); 104 95 if (rc != EOK) { 105 96 printf("%s: Failed to connect to services\n", NAME); 106 nic_unbind_and_destroy(dev); 107 return rc; 97 goto error; 108 98 } 109 99 110 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); 111 111 if (rc != EOK) { 112 printf("%s: Failed to register as DDF function\n", NAME); 113 nic_unbind_and_destroy(dev); 114 return rc; 112 printf("%s: Failed to setup loopback address\n", NAME); 113 goto error; 115 114 } 116 115 117 rc = nic_report_address(nic_data, &lo_addr);116 rc = ddf_fun_bind(fun); 118 117 if (rc != EOK) { 119 printf("%s: Failed to setup loopback address\n", NAME); 120 nic_unbind_and_destroy(dev); 121 return rc; 118 printf("%s: Failed binding function\n", NAME); 119 goto error; 122 120 } 121 bound = true; 122 123 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 124 if (rc != EOK) 125 goto error; 123 126 124 127 printf("%s: Adding loopback device '%s'\n", NAME, dev->name); 125 128 return EOK; 129 130 error: 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; 126 139 } 127 140
Note:
See TracChangeset
for help on using the changeset viewer.