Changeset 0764cc8a in mainline for uspace/drv/nic/rtl8169/driver.c


Ignore:
Timestamp:
2014-05-26T20:52:46Z (11 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
59b3095
Parents:
f1ac202
Message:

Add more function stubs to allow proper driver attaching, add code for
allocating DMA ring buffers. Interrupt handler and status notifications
work!

File:
1 edited

Legend:

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

    rf1ac202 r0764cc8a  
    8787static rtl8169_t *rtl8169_create_dev_data(ddf_dev_t *dev);
    8888
     89static int rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
     90    const nic_address_t *, size_t);
     91static int rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
     92    const nic_address_t *addr, size_t addr_count);
     93static int rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode);
     94
     95
    8996/** Network interface options for RTL8169 card driver */
    9097static nic_iface_t rtl8169_nic_iface = {
     
    221228}
    222229
     230static int rtl8169_allocate_buffers(rtl8169_t *rtl8169)
     231{
     232        int rc;
     233
     234        ddf_msg(LVL_DEBUG, "Allocating DMA buffer rings");
     235
     236        /* Allocate TX ring */
     237        rc = dmamem_map_anonymous(TX_RING_SIZE, DMAMEM_4GiB,
     238            AS_AREA_READ | AS_AREA_WRITE, 0, &rtl8169->tx_ring_phys,
     239            &rtl8169->tx_ring_virt);
     240
     241        if (rc != EOK)
     242                return rc;
     243
     244        /* Allocate RX ring */
     245        rc = dmamem_map_anonymous(RX_RING_SIZE, DMAMEM_4GiB,
     246            AS_AREA_READ | AS_AREA_WRITE, 0, &rtl8169->rx_ring_phys,
     247            &rtl8169->rx_ring_virt);
     248
     249        if (rc != EOK)
     250                return rc;
     251
     252        /* Allocate TX buffers */
     253        rc = dmamem_map_anonymous(TX_BUFFERS_SIZE, DMAMEM_4GiB,
     254            AS_AREA_READ | AS_AREA_WRITE, 0, &rtl8169->tx_buff_phys,
     255            &rtl8169->tx_buff_virt);
     256
     257        if (rc != EOK)
     258                return rc;
     259
     260        /* Allocate RX buffers */
     261        rc = dmamem_map_anonymous(RX_BUFFERS_SIZE, DMAMEM_4GiB,
     262            AS_AREA_READ | AS_AREA_WRITE, 0, &rtl8169->rx_buff_phys,
     263            &rtl8169->rx_buff_virt);
     264
     265        if (rc != EOK)
     266                return rc;
     267}
     268
    223269static rtl8169_t *rtl8169_create_dev_data(ddf_dev_t *dev)
    224270{
     
    244290                rtl8169_on_activated, NULL, rtl8169_on_stopped);
    245291        nic_set_filtering_change_handlers(nic_data,
    246                 NULL, NULL, NULL, NULL, NULL);
     292                rtl8169_unicast_set, rtl8169_multicast_set, rtl8169_broadcast_set,
     293                NULL, NULL);
    247294
    248295        fibril_mutex_initialize(&rtl8169->rx_lock);
     
    255302        return rtl8169;
    256303}
    257 
    258304
    259305static int rtl8169_dev_initialize(ddf_dev_t *dev)
     
    344390        ddf_msg(LVL_DEBUG, "Interrupt handler installed");
    345391
    346         rtl8169_reset(rtl8169);
    347         pio_write_16(rtl8169->regs + IMR, 0xffff);
    348 
    349392        uint8_t cr_value = pio_read_8(rtl8169->regs + CR);
    350393        pio_write_8(rtl8169->regs + CR, cr_value | CR_TE | CR_RE);
     
    377420                goto err_fun_bind;
    378421        }
    379 
     422       
    380423        ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.",
    381424            ddf_dev_get_name(dev));
     
    474517        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    475518
     519        /* Reset card */
     520        pio_write_8(rtl8169->regs + CONFIG0, 0);
     521        rtl8169_reset(rtl8169);
     522
     523        /* Enable TX and RX */
     524        uint8_t cr = pio_read_8(rtl8169->regs + CR);
     525        cr |= CR_TE | CR_RE;
     526        pio_write_8(rtl8169->regs + CR, cr);
     527
    476528        pio_write_16(rtl8169->regs + IMR, 0xffff);
     529        nic_enable_interrupt(nic_data, rtl8169->irq);
    477530
    478531        return EOK;
     
    481534static int rtl8169_on_stopped(nic_t *nic_data)
    482535{
     536        ddf_msg(LVL_NOTE, "Stopping device");
    483537        return EOK;
    484538}
     
    522576
    523577}
     578
     579static int rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
     580    const nic_address_t *addr, size_t addr_count)
     581{
     582        return EOK;
     583}
     584
     585static int rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
     586    const nic_address_t *addr, size_t addr_count)
     587{
     588        return EOK;
     589}
     590
     591static int rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode)
     592{
     593        return EOK;
     594}
     595
     596
    524597
    525598static void rtl8169_irq_handler(ddf_dev_t *dev, ipc_callid_t iid,
Note: See TracChangeset for help on using the changeset viewer.