Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/rtl8139/driver.c

    rd51838f r582a0b8  
    3636#include <ddf/log.h>
    3737#include <ddf/interrupt.h>
    38 #include <device/hw_res.h>
    3938#include <io/log.h>
    4039#include <nic.h>
    4140#include <pci_dev_iface.h>
     41#include <irc.h>
    4242#include <stdio.h>
    4343#include <str.h>
     
    125125
    126126
    127 /** Set interrupts on controller
     127/** Disable interrupts on controller
    128128 *
    129129 *  @param rtl8139  The card private structure
    130130 */
    131 inline static void rtl8139_hw_int_set(rtl8139_t *rtl8139)
     131inline 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 */
     139inline static void rtl8139_hw_int_enable(rtl8139_t *rtl8139)
    132140{
    133141        pio_write_16(rtl8139->io_port + IMR, rtl8139->int_mask);
     
    266274}
    267275
     276/**  Provide OR in the 32bit register (set selected bits to 1)
     277 *
     278 *   @param rtl8139     The rtl8139 structure
     279 *   @param reg_offset  Register offset in the device IO space
     280 *   @param bits_add    The value to or
     281 */
     282inline 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
    268290/**  Unset selected bits in 8bit register
    269291 *
     
    279301        pio_write_8(rtl8139->io_port + reg_offset, value);
    280302}
     303
     304/**  Unset selected bits in 32bit register
     305 *
     306 *   @param rtl8139     The rtl8139 structure
     307 *   @param reg_offset  Register offset in the device IO space
     308 *   @param bits_add    The mask of bits to remove
     309 */
     310inline 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
    281318
    282319static int rtl8139_set_addr(ddf_fun_t *fun, const nic_address_t *);
     
    834871
    835872        /* Turn the interrupts on again */
    836         rtl8139_hw_int_set(rtl8139);
     873        rtl8139_hw_int_enable(rtl8139);
    837874};
    838875
     
    844881 *  @param nic_data  The driver data
    845882 *
    846  *  @return IRQ capability handle if the handler was registered.
    847  *  @return Negative error code otherwise.
     883 *  @return EOK if the handler was registered, negative error code otherwise
    848884 */
    849885inline static int rtl8139_register_int_handler(nic_t *nic_data)
     
    858894        rtl8139_irq_code.cmds[2].addr = rtl8139->io_addr + ISR;
    859895        rtl8139_irq_code.cmds[3].addr = rtl8139->io_addr + IMR;
    860         int cap = register_interrupt_handler(nic_get_ddf_dev(nic_data),
     896        int rc = register_interrupt_handler(nic_get_ddf_dev(nic_data),
    861897            rtl8139->irq, rtl8139_interrupt_handler, &rtl8139_irq_code);
    862898
    863899        RTL8139_IRQ_STRUCT_UNLOCK();
    864900
    865         return cap;
     901        return rc;
    866902}
    867903
     
    918954
    919955        rtl8139->int_mask = RTL_DEFAULT_INTERRUPTS;
    920         rtl8139_hw_int_set(rtl8139);
    921 
    922         int rc = hw_res_enable_interrupt(rtl8139->parent_sess, rtl8139->irq);
     956        rtl8139_hw_int_enable(rtl8139);
     957
     958        int rc = irc_enable_interrupt(rtl8139->irq);
    923959        if (rc != EOK) {
    924960                rtl8139_on_stopped(nic_data);
     
    9761012                return NULL;
    9771013
    978         rtl8139_t *rtl8139 = calloc(1, sizeof(rtl8139_t));
     1014        rtl8139_t *rtl8139 = malloc(sizeof(rtl8139_t));
    9791015        if (!rtl8139) {
    9801016                nic_unbind_and_destroy(dev);
     
    9821018        }
    9831019
    984         rtl8139->dev = dev;
     1020        memset(rtl8139, 0, sizeof(rtl8139_t));
    9851021
    9861022        rtl8139->nic_data = nic_data;
     
    11661202
    11671203        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         }
    11731204
    11741205        /* Obtain and fill hardware resources info and connect to parent */
     
    12631294        ddf_fun_t *fun;
    12641295
     1296        assert(dev);
    12651297        ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %zu)",
    12661298            ddf_dev_get_name(dev), ddf_dev_get_handle(dev));
     
    12891321
    12901322        /* Register interrupt handler */
    1291         int irq_cap = rtl8139_register_int_handler(nic_data);
    1292         if (irq_cap < 0) {
    1293                 rc = irq_cap;
     1323        rc = rtl8139_register_int_handler(nic_data);
     1324        if (rc != EOK)
    12941325                goto err_pio;
    1295         }
    12961326
    12971327        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     
    13251355        ddf_fun_destroy(fun);
    13261356err_srv:
    1327         unregister_interrupt_handler(dev, irq_cap);
     1357        unregister_interrupt_handler(dev, rtl8139->irq);
    13281358err_pio:
    13291359        // rtl8139_pio_disable(dev);
     
    20872117                /* Disable timer interrupts while working with timer-related data */
    20882118                rtl8139->int_mask = 0;
    2089                 rtl8139_hw_int_set(rtl8139);
     2119                rtl8139_hw_int_enable(rtl8139);
    20902120
    20912121                rtl8139->poll_timer = new_timer;
     
    21102140        }
    21112141
    2112         rtl8139_hw_int_set(rtl8139);
     2142        rtl8139_hw_int_enable(rtl8139);
    21132143
    21142144        fibril_mutex_unlock(&rtl8139->rx_lock);
Note: See TracChangeset for help on using the changeset viewer.