Changeset e86b8f0 in mainline
- Timestamp:
- 2012-01-21T12:50:28Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 77a69ea, 86c71de
- Parents:
- 3fe58d3c
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/e1k/e1k.c
r3fe58d3c re86b8f0 2097 2097 int e1000_dev_add(ddf_dev_t *dev) 2098 2098 { 2099 ddf_fun_t *fun; 2099 2100 assert(dev); 2100 2101 … … 2127 2128 e1000_initialize_vlan(e1000); 2128 2129 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) 2131 2132 goto err_tx_structure; 2133 nic_set_ddf_fun(nic, fun); 2134 fun->ops = &e1000_dev_ops; 2135 fun->driver_data = nic; 2132 2136 2133 2137 rc = e1000_register_int_handler(nic); 2134 2138 if (rc != EOK) 2135 goto err_ tx_structure;2139 goto err_fun_create; 2136 2140 2137 2141 rc = nic_connect_to_services(nic); … … 2156 2160 goto err_rx_structure; 2157 2161 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 2158 2170 return EOK; 2159 2171 2172 err_add_to_cat: 2173 ddf_fun_unbind(fun); 2174 err_fun_bind: 2160 2175 err_rx_structure: 2161 2176 e1000_uninitialize_rx_structure(nic); 2162 2177 err_irq: 2163 2178 unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq); 2179 err_fun_create: 2180 ddf_fun_destroy(fun); 2181 nic_set_ddf_fun(nic, NULL); 2164 2182 err_tx_structure: 2165 2183 e1000_uninitialize_tx_structure(e1000); -
uspace/drv/nic/lo/lo.c
r3fe58d3c re86b8f0 80 80 static int lo_dev_add(ddf_dev_t *dev) 81 81 { 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) { 84 87 printf("%s: Failed to initialize\n", NAME); 85 88 return ENOMEM; 86 89 } 87 90 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); 90 93 91 int rc = nic_connect_to_services(nic _data);94 int rc = nic_connect_to_services(nic); 92 95 if (rc != EOK) { 93 96 printf("%s: Failed to connect to services\n", NAME); 94 nic_unbind_and_destroy(dev); 95 return rc; 97 goto error; 96 98 } 97 99 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); 99 111 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; 103 114 } 104 115 105 rc = nic_report_address(nic_data, &lo_addr);116 rc = ddf_fun_bind(fun); 106 117 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; 110 120 } 121 bound = true; 122 123 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 124 if (rc != EOK) 125 goto error; 111 126 112 127 printf("%s: Adding loopback device '%s'\n", NAME, dev->name); 113 128 return EOK; 129 error: 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; 114 137 } 115 138 -
uspace/drv/nic/ne2k/ne2k.c
r3fe58d3c re86b8f0 338 338 static int ne2k_dev_add(ddf_dev_t *dev) 339 339 { 340 ddf_fun_t *fun; 341 340 342 /* Allocate driver data for the device. */ 341 343 nic_t *nic_data = nic_create_and_bind(dev); … … 371 373 } 372 374 373 rc = nic_ register_as_ddf_fun(nic_data, &ne2k_dev_ops);375 rc = nic_connect_to_services(nic_data); 374 376 if (rc != EOK) { 375 377 ne2k_dev_cleanup(dev); … … 377 379 } 378 380 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) { 381 383 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); 382 401 return rc; 383 402 } -
uspace/drv/nic/rtl8139/driver.c
r3fe58d3c re86b8f0 1280 1280 int rtl8139_dev_add(ddf_dev_t *dev) 1281 1281 { 1282 ddf_fun_t *fun; 1283 1282 1284 assert(dev); 1283 1285 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); … … 1316 1318 } 1317 1319 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); 1319 1330 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; 1322 1338 } 1323 1339 … … 1327 1343 return EOK; 1328 1344 1345 err_fun_bind: 1346 ddf_fun_unbind(fun); 1347 err_fun_create: 1348 ddf_fun_destroy(fun); 1349 err_srv: 1350 /* XXX Disconnect from services */ 1329 1351 err_irq: 1330 1352 unregister_interrupt_handler(dev, rtl8139->irq); -
uspace/lib/nic/include/nic.h
r3fe58d3c re86b8f0 44 44 #include <ops/nic.h> 45 45 46 #define DEVICE_CATEGORY_NIC "nic" 47 46 48 struct nic; 47 49 typedef struct nic nic_t; … … 204 206 /* Functions called in add_device */ 205 207 extern int nic_connect_to_services(nic_t *); 206 extern int nic_register_as_ddf_fun(nic_t *, ddf_dev_ops_t *);207 208 extern int nic_get_resources(nic_t *, hw_res_list_parsed_t *); 208 209 extern void nic_set_specific(nic_t *, void *); … … 225 226 extern ddf_dev_t *nic_get_ddf_dev(nic_t *); 226 227 extern ddf_fun_t *nic_get_ddf_fun(nic_t *); 228 extern void nic_set_ddf_fun(nic_t *, ddf_fun_t *); 227 229 extern nic_t *nic_get_from_ddf_dev(ddf_dev_t *); 228 230 extern nic_t *nic_get_from_ddf_fun(ddf_fun_t *); -
uspace/lib/nic/include/nic_driver.h
r3fe58d3c re86b8f0 50 50 #include "nic_rx_control.h" 51 51 #include "nic_wol_virtues.h" 52 53 #define DEVICE_CATEGORY_NIC "nic"54 52 55 53 struct sw_poll_info { -
uspace/lib/nic/src/nic_driver.c
r3fe58d3c re86b8f0 812 812 813 813 /** 814 * Creates an exposed DDF function for the device, named "port0".815 * Device options are set as this function's options. The function is bound816 * (see ddf_fun_bind) and then registered to the DEVICE_CATEGORY_NIC class.817 * Note: this function should be called only from add_device handler, therefore818 * we don't need to use locks.819 *820 * @param nic_data The NIC structure821 * @param ops Device options for the DDF function.822 */823 int nic_register_as_ddf_fun(nic_t *nic_data, ddf_dev_ops_t *ops)824 {825 int rc;826 assert(nic_data);827 828 nic_data->fun = ddf_fun_create(nic_data->dev, fun_exposed, "port0");829 if (nic_data->fun == NULL)830 return ENOMEM;831 832 nic_data->fun->ops = ops;833 nic_data->fun->driver_data = nic_data;834 835 rc = ddf_fun_bind(nic_data->fun);836 if (rc != EOK) {837 ddf_fun_destroy(nic_data->fun);838 return rc;839 }840 841 rc = ddf_fun_add_to_category(nic_data->fun, DEVICE_CATEGORY_NIC);842 if (rc != EOK) {843 ddf_fun_destroy(nic_data->fun);844 return rc;845 }846 847 return EOK;848 }849 850 /**851 814 * Set information about current HW filtering. 852 815 * 1 ... Only those frames we want to receive are passed through HW … … 1063 1026 { 1064 1027 return nic_data->fun; 1028 } 1029 1030 /** 1031 * @param nic_data 1032 * @param fun 1033 */ 1034 void nic_set_ddf_fun(nic_t *nic_data, ddf_fun_t *fun) 1035 { 1036 nic_data->fun = fun; 1065 1037 } 1066 1038
Note:
See TracChangeset
for help on using the changeset viewer.