Changeset 56fd7cf in mainline for uspace/drv/nic
- Timestamp:
- 2012-08-17T11:37:03Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d5a540
- Parents:
- be2a38ad
- Location:
- uspace/drv/nic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/e1k/e1k.c
rbe2a38ad r56fd7cf 32 32 * 33 33 */ 34 35 /* XXX Fix this */ 36 #define _DDF_DATA_IMPLANT 34 37 35 38 #include <assert.h> … … 71 74 ((e1000_t *) nic_get_specific(nic)) 72 75 73 /** device_t* -> nic_driver_data_t* cast */ 76 /** ddf_fun_t * -> nic_driver_data_t* cast */ 77 #define NIC_DATA_FUN(fun) \ 78 ((nic_t *) ddf_fun_data_get(fun)) 79 80 /** ddf_dev_t * -> nic_driver_data_t* cast */ 74 81 #define NIC_DATA_DEV(dev) \ 75 ((nic_t *) ((dev)->driver_data))76 77 /** d evice_t* -> e1000_t* cast */82 ((nic_t *) ddf_dev_data_get(dev)) 83 84 /** ddf_dev_t * -> e1000_t* cast */ 78 85 #define DRIVER_DATA_DEV(dev) \ 79 86 (DRIVER_DATA_NIC(NIC_DATA_DEV(dev))) 87 88 /** ddf_fun_t * -> e1000_t* cast */ 89 #define DRIVER_DATA_FUN(fun) \ 90 (DRIVER_DATA_NIC(NIC_DATA_FUN(fun))) 80 91 81 92 /** Cast pointer to uint64_t … … 305 316 * 306 317 */ 307 static int e1000_get_cable_state(ddf_fun_t *dev, nic_cable_state_t *state) 308 { 309 assert(dev); 310 assert(DRIVER_DATA_DEV(dev)); 311 assert(state); 312 313 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 318 static int e1000_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state) 319 { 320 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 314 321 if (E1000_REG_READ(e1000, E1000_STATUS) & (STATUS_LU)) 315 322 *state = NIC_CS_PLUGGED; … … 328 335 * 329 336 */ 330 static int e1000_get_operation_mode(ddf_fun_t * dev, int *speed,337 static int e1000_get_operation_mode(ddf_fun_t *fun, int *speed, 331 338 nic_channel_mode_t *duplex, nic_role_t *role) 332 339 { 333 e1000_t *e1000 = DRIVER_DATA_ DEV(dev);340 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 334 341 uint32_t status = E1000_REG_READ(e1000, E1000_STATUS); 335 342 … … 376 383 * 377 384 */ 378 static int e1000_set_operation_mode(ddf_fun_t * dev, int speed,385 static int e1000_set_operation_mode(ddf_fun_t *fun, int speed, 379 386 nic_channel_mode_t duplex, nic_role_t role) 380 387 { … … 385 392 return EINVAL; 386 393 387 e1000_t *e1000 = DRIVER_DATA_ DEV(dev);394 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 388 395 389 396 fibril_mutex_lock(&e1000->ctrl_lock); … … 424 431 * 425 432 */ 426 static int e1000_autoneg_enable(ddf_fun_t * dev, uint32_t advertisement)427 { 428 e1000_t *e1000 = DRIVER_DATA_ DEV(dev);433 static int e1000_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement) 434 { 435 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 429 436 430 437 fibril_mutex_lock(&e1000->ctrl_lock); … … 452 459 * 453 460 */ 454 static int e1000_autoneg_disable(ddf_fun_t * dev)455 { 456 e1000_t *e1000 = DRIVER_DATA_ DEV(dev);461 static int e1000_autoneg_disable(ddf_fun_t *fun) 462 { 463 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 457 464 458 465 fibril_mutex_lock(&e1000->ctrl_lock); … … 491 498 * 492 499 */ 493 static int e1000_defective_get_mode(ddf_fun_t * device, uint32_t *mode)494 { 495 e1000_t *e1000 = DRIVER_DATA_ DEV(device);500 static int e1000_defective_get_mode(ddf_fun_t *fun, uint32_t *mode) 501 { 502 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 496 503 497 504 *mode = 0; … … 512 519 * 513 520 */ 514 static int e1000_defective_set_mode(ddf_fun_t * device, uint32_t mode)515 { 516 e1000_t *e1000 = DRIVER_DATA_ DEV(device);521 static int e1000_defective_set_mode(ddf_fun_t *fun, uint32_t mode) 522 { 523 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 517 524 int rc = EOK; 518 525 … … 1038 1045 * 1039 1046 */ 1040 static int e1000_vlan_set_tag(ddf_fun_t * device, uint16_t tag, bool add,1047 static int e1000_vlan_set_tag(ddf_fun_t *fun, uint16_t tag, bool add, 1041 1048 bool strip) 1042 1049 { … … 1052 1059 return ENOTSUP; 1053 1060 1054 e1000_t *e1000 = DRIVER_DATA_ DEV(device);1061 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 1055 1062 1056 1063 e1000->vlan_tag = tag; … … 1855 1862 static e1000_t *e1000_create_dev_data(ddf_dev_t *dev) 1856 1863 { 1857 assert(dev);1858 assert(!dev->driver_data);1859 1860 1864 nic_t *nic = nic_create_and_bind(dev); 1861 1865 if (!nic) … … 1896 1900 assert(dev); 1897 1901 1898 if (d ev->driver_data!= NULL)1902 if (ddf_dev_data_get(dev) != NULL) 1899 1903 nic_unbind_and_destroy(dev); 1900 1904 } … … 1910 1914 1911 1915 e1000_delete_dev_data(dev); 1912 1913 if (dev->parent_sess != NULL) {1914 async_hangup(dev->parent_sess);1915 dev->parent_sess = NULL;1916 }1917 1916 } 1918 1917 … … 1931 1930 const hw_res_list_parsed_t *hw_resources) 1932 1931 { 1933 assert(dev != NULL);1934 assert(hw_resources != NULL);1935 assert(dev->driver_data != NULL);1936 1937 1932 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 1938 1933 … … 2003 1998 2004 1999 uint16_t device_id; 2005 rc = pci_config_space_read_16(d ev->parent_sess, PCI_DEVICE_ID,2000 rc = pci_config_space_read_16(ddf_dev_parent_sess_get(dev), PCI_DEVICE_ID, 2006 2001 &device_id); 2007 2002 if (rc != EOK) { … … 2121 2116 2122 2117 /* Device initialization */ 2123 nic_t *nic = d ev->driver_data;2118 nic_t *nic = ddf_dev_data_get(dev); 2124 2119 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 2125 2120 … … 2147 2142 goto err_tx_structure; 2148 2143 nic_set_ddf_fun(nic, fun); 2149 fun->ops = &e1000_dev_ops;2150 fun->driver_data = nic;2144 ddf_fun_set_ops(fun, &e1000_dev_ops); 2145 ddf_fun_data_implant(fun, nic); 2151 2146 2152 2147 rc = e1000_register_int_handler(nic); … … 2278 2273 * @return Negative error code otherwise 2279 2274 */ 2280 static int e1000_set_addr(ddf_fun_t * dev, const nic_address_t *addr)2281 { 2282 nic_t *nic = NIC_DATA_ DEV(dev);2275 static int e1000_set_addr(ddf_fun_t *fun, const nic_address_t *addr) 2276 { 2277 nic_t *nic = NIC_DATA_FUN(fun); 2283 2278 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 2284 2279 -
uspace/drv/nic/ne2k/ne2k.c
rbe2a38ad r56fd7cf 38 38 */ 39 39 40 /* XXX Fix this */ 41 #define _DDF_DATA_IMPLANT 42 40 43 #include <stdio.h> 41 44 #include <errno.h> … … 61 64 #define IRQ_GET_TSR(call) ((int) IPC_GET_ARG3(call)) 62 65 63 #define DRIVER_DATA(dev) ((nic_t *) ((dev)->driver_data))66 #define DRIVER_DATA(dev) ((nic_t *) ddf_dev_data_get(dev)) 64 67 #define NE2K(device) ((ne2k_t *) nic_get_specific(DRIVER_DATA(device))) 65 68 … … 169 172 static void ne2k_dev_cleanup(ddf_dev_t *dev) 170 173 { 171 if (d ev->driver_data!= NULL) {174 if (ddf_dev_data_get(dev) != NULL) { 172 175 ne2k_t *ne2k = NE2K(dev); 173 176 if (ne2k) { … … 177 180 nic_unbind_and_destroy(dev); 178 181 } 179 if (dev->parent_sess != NULL) {180 async_hangup(dev->parent_sess);181 dev->parent_sess = NULL;182 }183 182 } 184 183 … … 279 278 static int ne2k_set_address(ddf_fun_t *fun, const nic_address_t *address) 280 279 { 281 nic_t *nic_data = DRIVER_DATA( fun);280 nic_t *nic_data = DRIVER_DATA(ddf_fun_get_dev(fun)); 282 281 int rc = nic_report_address(nic_data, address); 283 282 if (rc != EOK) { … … 410 409 } 411 410 nic_set_ddf_fun(nic_data, fun); 412 fun->ops = &ne2k_dev_ops;413 fun->driver_data = nic_data;411 ddf_fun_set_ops(fun, &ne2k_dev_ops); 412 ddf_fun_data_implant(fun, nic_data); 414 413 415 414 rc = ddf_fun_bind(fun); -
uspace/drv/nic/rtl8139/driver.c
rbe2a38ad r56fd7cf 27 27 */ 28 28 29 /* XXX Fix this */ 30 #define _DDF_DATA_IMPLANT 31 29 32 #include <assert.h> 30 33 #include <errno.h> … … 212 215 rtl8139_regs_lock(rtl8139->io_port); 213 216 217 async_sess_t *pci_sess = 218 ddf_dev_parent_sess_get(nic_get_ddf_dev(rtl8139->nic_data)); 219 214 220 if (bit_val) { 215 async_sess_t *pci_sess =216 nic_get_ddf_dev(rtl8139->nic_data)->parent_sess;217 221 uint8_t pmen; 218 222 pci_config_space_read_8(pci_sess, 0x55, &pmen); 219 223 pci_config_space_write_8(pci_sess, 0x55, pmen | 1 | (1 << 7)); 220 224 } else { 221 async_sess_t *pci_sess =222 nic_get_ddf_dev(rtl8139->nic_data)->parent_sess;223 225 uint8_t pmen; 224 226 pci_config_space_read_8(pci_sess, 0x55, &pmen); … … 1052 1054 assert(dev); 1053 1055 1054 if (d ev->driver_data)1056 if (ddf_dev_data_get(dev)) 1055 1057 nic_unbind_and_destroy(dev); 1056 1057 if (dev->parent_sess != NULL) {1058 async_hangup(dev->parent_sess);1059 dev->parent_sess = NULL;1060 }1061 1058 } 1062 1059 … … 1080 1077 1081 1078 if (hw_resources->irqs.count != 1) { 1082 ddf_msg(LVL_ERROR, "%s device: unexpected irq count", d ev->name);1079 ddf_msg(LVL_ERROR, "%s device: unexpected irq count", ddf_dev_get_name(dev)); 1083 1080 return EINVAL; 1084 1081 }; 1085 1082 if (hw_resources->io_ranges.count != 1) { 1086 ddf_msg(LVL_ERROR, "%s device: unexpected io ranges count", d ev->name);1083 ddf_msg(LVL_ERROR, "%s device: unexpected io ranges count", ddf_dev_get_name(dev)); 1087 1084 return EINVAL; 1088 1085 } 1089 1086 1090 1087 rtl8139->irq = hw_resources->irqs.irqs[0]; 1091 ddf_msg(LVL_DEBUG, "%s device: irq 0x%x assigned", d ev->name, rtl8139->irq);1088 ddf_msg(LVL_DEBUG, "%s device: irq 0x%x assigned", ddf_dev_get_name(dev), rtl8139->irq); 1092 1089 1093 1090 rtl8139->io_addr = IOADDR_TO_PTR(hw_resources->io_ranges.ranges[0].address); 1094 1091 if (hw_resources->io_ranges.ranges[0].size < RTL8139_IO_SIZE) { 1095 1092 ddf_msg(LVL_ERROR, "i/o range assigned to the device " 1096 "%s is too small.", d ev->name);1093 "%s is too small.", ddf_dev_get_name(dev)); 1097 1094 return EINVAL; 1098 1095 } 1099 ddf_msg(LVL_DEBUG, "%s device: i/o addr %p assigned.", d ev->name, rtl8139->io_addr);1096 ddf_msg(LVL_DEBUG, "%s device: i/o addr %p assigned.", ddf_dev_get_name(dev), rtl8139->io_addr); 1100 1097 1101 1098 return EOK; … … 1192 1189 static int rtl8139_device_initialize(ddf_dev_t *dev) 1193 1190 { 1194 ddf_msg(LVL_DEBUG, "rtl8139_dev_initialize %s", d ev->name);1191 ddf_msg(LVL_DEBUG, "rtl8139_dev_initialize %s", ddf_dev_get_name(dev)); 1195 1192 1196 1193 int ret = EOK; … … 1201 1198 rtl8139_t *rtl8139 = rtl8139_create_dev_data(dev); 1202 1199 if (rtl8139 == NULL) { 1203 ddf_msg(LVL_ERROR, "Not enough memory for initializing %s.", d ev->name);1200 ddf_msg(LVL_ERROR, "Not enough memory for initializing %s.", ddf_dev_get_name(dev)); 1204 1201 return ENOMEM; 1205 1202 } … … 1246 1243 static int rtl8139_pio_enable(ddf_dev_t *dev) 1247 1244 { 1248 ddf_msg(LVL_DEBUG, NAME ": rtl8139_pio_enable %s", d ev->name);1245 ddf_msg(LVL_DEBUG, NAME ": rtl8139_pio_enable %s", ddf_dev_get_name(dev)); 1249 1246 1250 1247 rtl8139_t *rtl8139 = nic_get_specific(nic_get_from_ddf_dev(dev)); … … 1253 1250 if (pio_enable(rtl8139->io_addr, RTL8139_IO_SIZE, &rtl8139->io_port)) { 1254 1251 ddf_msg(LVL_ERROR, "Cannot gain the port %lx for device %s.", rtl8139->io_addr, 1255 d ev->name);1252 ddf_dev_get_name(dev)); 1256 1253 return EADDRNOTAVAIL; 1257 1254 } … … 1299 1296 1300 1297 assert(dev); 1301 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); 1298 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", 1299 ddf_dev_get_name(dev), ddf_dev_get_handle(dev)); 1302 1300 1303 1301 /* Init device structure for rtl8139 */ … … 1340 1338 } 1341 1339 nic_set_ddf_fun(nic_data, fun); 1342 fun->ops = &rtl8139_dev_ops;1343 fun->driver_data = nic_data;1340 ddf_fun_set_ops(fun, &rtl8139_dev_ops); 1341 ddf_fun_data_implant(fun, nic_data); 1344 1342 1345 1343 rc = ddf_fun_bind(fun); … … 1355 1353 1356 1354 ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.", 1357 d ev->name);1355 ddf_dev_get_name(dev)); 1358 1356 1359 1357 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.