Changes in uspace/drv/nic/rtl8139/driver.c [582a0b8:d51838f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/rtl8139/driver.c
r582a0b8 rd51838f 36 36 #include <ddf/log.h> 37 37 #include <ddf/interrupt.h> 38 #include <device/hw_res.h> 38 39 #include <io/log.h> 39 40 #include <nic.h> 40 41 #include <pci_dev_iface.h> 41 #include <irc.h>42 42 #include <stdio.h> 43 43 #include <str.h> … … 125 125 126 126 127 /** Disableinterrupts on controller127 /** Set interrupts on controller 128 128 * 129 129 * @param rtl8139 The card private structure 130 130 */ 131 inline static void rtl8139_hw_int_disable(rtl8139_t *rtl8139) 132 { 133 pio_write_16(rtl8139->io_port + IMR, 0x0); 134 } 135 /** Enable interrupts on controller 136 * 137 * @param rtl8139 The card private structure 138 */ 139 inline static void rtl8139_hw_int_enable(rtl8139_t *rtl8139) 131 inline static void rtl8139_hw_int_set(rtl8139_t *rtl8139) 140 132 { 141 133 pio_write_16(rtl8139->io_port + IMR, rtl8139->int_mask); … … 274 266 } 275 267 276 /** Provide OR in the 32bit register (set selected bits to 1)277 *278 * @param rtl8139 The rtl8139 structure279 * @param reg_offset Register offset in the device IO space280 * @param bits_add The value to or281 */282 inline static void rtl8139_hw_reg_add_32(rtl8139_t * rtl8139, size_t reg_offset,283 uint32_t bits_add)284 {285 uint32_t value = pio_read_32(rtl8139->io_port + reg_offset);286 value |= bits_add;287 pio_write_32(rtl8139->io_port + reg_offset, value);288 }289 290 268 /** Unset selected bits in 8bit register 291 269 * … … 301 279 pio_write_8(rtl8139->io_port + reg_offset, value); 302 280 } 303 304 /** Unset selected bits in 32bit register305 *306 * @param rtl8139 The rtl8139 structure307 * @param reg_offset Register offset in the device IO space308 * @param bits_add The mask of bits to remove309 */310 inline static void rtl8139_hw_reg_rem_32(rtl8139_t * rtl8139, size_t reg_offset,311 uint32_t bits_add)312 {313 uint32_t value = pio_read_32(rtl8139->io_port + reg_offset);314 value &= ~bits_add;315 pio_write_32(rtl8139->io_port + reg_offset, value);316 }317 318 281 319 282 static int rtl8139_set_addr(ddf_fun_t *fun, const nic_address_t *); … … 871 834 872 835 /* Turn the interrupts on again */ 873 rtl8139_hw_int_ enable(rtl8139);836 rtl8139_hw_int_set(rtl8139); 874 837 }; 875 838 … … 881 844 * @param nic_data The driver data 882 845 * 883 * @return EOK if the handler was registered, negative error code otherwise 846 * @return IRQ capability handle if the handler was registered. 847 * @return Negative error code otherwise. 884 848 */ 885 849 inline static int rtl8139_register_int_handler(nic_t *nic_data) … … 894 858 rtl8139_irq_code.cmds[2].addr = rtl8139->io_addr + ISR; 895 859 rtl8139_irq_code.cmds[3].addr = rtl8139->io_addr + IMR; 896 int rc= register_interrupt_handler(nic_get_ddf_dev(nic_data),860 int cap = register_interrupt_handler(nic_get_ddf_dev(nic_data), 897 861 rtl8139->irq, rtl8139_interrupt_handler, &rtl8139_irq_code); 898 862 899 863 RTL8139_IRQ_STRUCT_UNLOCK(); 900 864 901 return rc;865 return cap; 902 866 } 903 867 … … 954 918 955 919 rtl8139->int_mask = RTL_DEFAULT_INTERRUPTS; 956 rtl8139_hw_int_ enable(rtl8139);957 958 int rc = irc_enable_interrupt(rtl8139->irq);920 rtl8139_hw_int_set(rtl8139); 921 922 int rc = hw_res_enable_interrupt(rtl8139->parent_sess, rtl8139->irq); 959 923 if (rc != EOK) { 960 924 rtl8139_on_stopped(nic_data); … … 1012 976 return NULL; 1013 977 1014 rtl8139_t *rtl8139 = malloc(sizeof(rtl8139_t));978 rtl8139_t *rtl8139 = calloc(1, sizeof(rtl8139_t)); 1015 979 if (!rtl8139) { 1016 980 nic_unbind_and_destroy(dev); … … 1018 982 } 1019 983 1020 memset(rtl8139, 0, sizeof(rtl8139_t));984 rtl8139->dev = dev; 1021 985 1022 986 rtl8139->nic_data = nic_data; … … 1202 1166 1203 1167 ddf_msg(LVL_DEBUG, "rtl8139: dev_data created"); 1168 rtl8139->parent_sess = ddf_dev_parent_sess_get(dev); 1169 if (rtl8139->parent_sess == NULL) { 1170 ddf_msg(LVL_ERROR, "Error connecting parent device."); 1171 return EIO; 1172 } 1204 1173 1205 1174 /* Obtain and fill hardware resources info and connect to parent */ … … 1294 1263 ddf_fun_t *fun; 1295 1264 1296 assert(dev);1297 1265 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %zu)", 1298 1266 ddf_dev_get_name(dev), ddf_dev_get_handle(dev)); … … 1321 1289 1322 1290 /* Register interrupt handler */ 1323 rc = rtl8139_register_int_handler(nic_data); 1324 if (rc != EOK) 1291 int irq_cap = rtl8139_register_int_handler(nic_data); 1292 if (irq_cap < 0) { 1293 rc = irq_cap; 1325 1294 goto err_pio; 1295 } 1326 1296 1327 1297 fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0"); … … 1355 1325 ddf_fun_destroy(fun); 1356 1326 err_srv: 1357 unregister_interrupt_handler(dev, rtl8139->irq);1327 unregister_interrupt_handler(dev, irq_cap); 1358 1328 err_pio: 1359 1329 // rtl8139_pio_disable(dev); … … 2117 2087 /* Disable timer interrupts while working with timer-related data */ 2118 2088 rtl8139->int_mask = 0; 2119 rtl8139_hw_int_ enable(rtl8139);2089 rtl8139_hw_int_set(rtl8139); 2120 2090 2121 2091 rtl8139->poll_timer = new_timer; … … 2140 2110 } 2141 2111 2142 rtl8139_hw_int_ enable(rtl8139);2112 rtl8139_hw_int_set(rtl8139); 2143 2113 2144 2114 fibril_mutex_unlock(&rtl8139->rx_lock);
Note:
See TracChangeset
for help on using the changeset viewer.