Ignore:
File:
1 edited

Legend:

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

    rf300523 rb7fd2a0  
    3030#include <async.h>
    3131#include <errno.h>
     32#include <str_error.h>
    3233#include <align.h>
    3334#include <byteorder.h>
     
    5152FIBRIL_MUTEX_INITIALIZE(irq_reg_lock);
    5253
    53 static int rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr);
    54 static int rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info);
    55 static int rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state);
    56 static int rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
     54static errno_t rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr);
     55static errno_t rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info);
     56static errno_t rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state);
     57static errno_t rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
    5758    nic_channel_mode_t *duplex, nic_role_t *role);
    58 static int rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
     59static errno_t rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
    5960    nic_channel_mode_t duplex, nic_role_t role);
    60 static int rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
     61static errno_t rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
    6162    nic_result_t *we_receive, uint16_t *time);
    62 static int rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     63static errno_t rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
    6364    uint16_t time);
    64 static int rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement);
    65 static int rtl8169_autoneg_disable(ddf_fun_t *fun);
    66 static int rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
     65static errno_t rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement);
     66static errno_t rtl8169_autoneg_disable(ddf_fun_t *fun);
     67static errno_t rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
    6768    uint32_t *their_adv, nic_result_t *result, nic_result_t *their_result);
    68 static int rtl8169_autoneg_restart(ddf_fun_t *fun);
    69 static int rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode);
    70 static int rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode);
    71 static int rtl8169_on_activated(nic_t *nic_data);
    72 static int rtl8169_on_stopped(nic_t *nic_data);
     69static errno_t rtl8169_autoneg_restart(ddf_fun_t *fun);
     70static errno_t rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode);
     71static errno_t rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode);
     72static errno_t rtl8169_on_activated(nic_t *nic_data);
     73static errno_t rtl8169_on_stopped(nic_t *nic_data);
    7374static void rtl8169_send_frame(nic_t *nic_data, void *data, size_t size);
    7475static void rtl8169_irq_handler(ipc_call_t *icall, ddf_dev_t *dev);
    75 static inline int rtl8169_register_int_handler(nic_t *nic_data);
     76static inline errno_t rtl8169_register_int_handler(nic_t *nic_data, cap_handle_t *handle);
    7677static inline void rtl8169_get_hwaddr(rtl8169_t *rtl8169, nic_address_t *addr);
    7778static inline void rtl8169_set_hwaddr(rtl8169_t *rtl8169, const nic_address_t *addr);
    7879
    7980static void rtl8169_reset(rtl8169_t *rtl8169);
    80 static int rtl8169_get_resource_info(ddf_dev_t *dev);
    81 static int rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t *hw_resources);
     81static errno_t rtl8169_get_resource_info(ddf_dev_t *dev);
     82static errno_t rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t *hw_resources);
    8283static rtl8169_t *rtl8169_create_dev_data(ddf_dev_t *dev);
    8384
    84 static int rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
     85static errno_t rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
    8586    const nic_address_t *, size_t);
    86 static int rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
     87static errno_t rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
    8788    const nic_address_t *addr, size_t addr_count);
    88 static int rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode);
     89static errno_t rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode);
    8990
    9091static uint16_t rtl8169_mii_read(rtl8169_t *rtl8169, uint8_t addr);
     
    160161static ddf_dev_ops_t rtl8169_dev_ops;
    161162
    162 static int rtl8169_dev_add(ddf_dev_t *dev);
     163static errno_t rtl8169_dev_add(ddf_dev_t *dev);
    163164
    164165/** Basic driver operations for RTL8169 driver */
     
    173174};
    174175
    175 static int rtl8169_get_resource_info(ddf_dev_t *dev)
     176static errno_t rtl8169_get_resource_info(ddf_dev_t *dev)
    176177{
    177178        assert(dev);
     
    184185
    185186        /* Get hw resources form parent driver */
    186         int rc = nic_get_resources(nic_data, &hw_res_parsed);
     187        errno_t rc = nic_get_resources(nic_data, &hw_res_parsed);
    187188        if (rc != EOK)
    188189                return rc;
    189190
    190191        /* Fill resources information to the device */
    191         int ret = rtl8169_fill_resource_info(dev, &hw_res_parsed);
     192        errno_t ret = rtl8169_fill_resource_info(dev, &hw_res_parsed);
    192193        hw_res_list_parsed_clean(&hw_res_parsed);
    193194
     
    195196}
    196197
    197 static int rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t
     198static errno_t rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t
    198199    *hw_resources)
    199200{
     
    228229}
    229230
    230 static int rtl8169_allocate_buffers(rtl8169_t *rtl8169)
    231 {
    232         int rc;
     231static errno_t rtl8169_allocate_buffers(rtl8169_t *rtl8169)
     232{
     233        errno_t rc;
    233234
    234235        ddf_msg(LVL_DEBUG, "Allocating DMA buffer rings");
     
    333334}
    334335
    335 static int rtl8169_dev_initialize(ddf_dev_t *dev)
    336 {
    337         int ret;
     336static errno_t rtl8169_dev_initialize(ddf_dev_t *dev)
     337{
     338        errno_t ret;
    338339
    339340        rtl8169_t *rtl8169 = rtl8169_create_dev_data(dev);
     
    359360}
    360361
    361 inline static int rtl8169_register_int_handler(nic_t *nic_data)
     362inline static errno_t rtl8169_register_int_handler(nic_t *nic_data, cap_handle_t *handle)
    362363{
    363364        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     
    367368        rtl8169_irq_code.cmds[2].addr = rtl8169->regs + ISR;
    368369        rtl8169_irq_code.cmds[3].addr = rtl8169->regs + IMR;
    369         int irq_cap = register_interrupt_handler(nic_get_ddf_dev(nic_data),
    370             rtl8169->irq, rtl8169_irq_handler, &rtl8169_irq_code);
    371 
    372         return irq_cap;
    373 }
    374 
    375 static int rtl8169_dev_add(ddf_dev_t *dev)
     370        errno_t rc = register_interrupt_handler(nic_get_ddf_dev(nic_data),
     371            rtl8169->irq, rtl8169_irq_handler, &rtl8169_irq_code, handle);
     372
     373        return rc;
     374}
     375
     376static errno_t rtl8169_dev_add(ddf_dev_t *dev)
    376377{
    377378        ddf_fun_t *fun;
    378379        nic_address_t nic_addr;
    379         int rc;
     380        errno_t rc;
    380381
    381382        assert(dev);
     
    427428                goto err_pio;
    428429
    429         int irq_cap = rtl8169_register_int_handler(nic_data);
    430         if (irq_cap < 0) {
    431                 rc = irq_cap;
    432                 ddf_msg(LVL_ERROR, "Failed to register IRQ handler (%d)", rc);
     430        int irq_cap;
     431        rc = rtl8169_register_int_handler(nic_data, &irq_cap);
     432        if (rc != EOK) {
     433                ddf_msg(LVL_ERROR, "Failed to register IRQ handler (%s)", str_error_name(rc));
    433434                goto err_irq;
    434435        }
     
    480481}
    481482
    482 static int rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr)
     483static errno_t rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr)
    483484{
    484485        nic_t *nic_data = nic_get_from_ddf_fun(fun);
    485486        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    486         int rc;
     487        errno_t rc;
    487488
    488489        fibril_mutex_lock(&rtl8169->rx_lock);
     
    501502}
    502503
    503 static int rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
     504static errno_t rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
    504505{
    505506        nic_t *nic_data = nic_get_from_ddf_fun(fun);
     
    527528}
    528529
    529 static int rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state)
     530static errno_t rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state)
    530531{
    531532        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    540541}
    541542
    542 static int rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
     543static errno_t rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
    543544    nic_channel_mode_t *duplex, nic_role_t *role)
    544545{
     
    562563}
    563564
    564 static int rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
     565static errno_t rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
    565566    nic_channel_mode_t duplex, nic_role_t role)
    566567{
     
    593594}
    594595
    595 static int rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
     596static errno_t rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
    596597    nic_result_t *we_receive, uint16_t *time)
    597598{
     
    599600}
    600601
    601 static int rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     602static errno_t rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
    602603    uint16_t time)
    603604{
     
    605606}
    606607
    607 static int rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement)
     608static errno_t rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement)
    608609{
    609610        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    629630}
    630631
    631 static int rtl8169_autoneg_disable(ddf_fun_t *fun)
     632static errno_t rtl8169_autoneg_disable(ddf_fun_t *fun)
    632633{
    633634        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    640641}
    641642
    642 static int rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
     643static errno_t rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
    643644    uint32_t *their_adv, nic_result_t *result, nic_result_t *their_result)
    644645{
     
    646647}
    647648
    648 static int rtl8169_autoneg_restart(ddf_fun_t *fun)
     649static errno_t rtl8169_autoneg_restart(ddf_fun_t *fun)
    649650{
    650651        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    656657}
    657658
    658 static int rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode)
    659 {
    660         return EOK;
    661 }
    662 
    663 static int rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode)
     659static errno_t rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode)
     660{
     661        return EOK;
     662}
     663
     664static errno_t rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode)
    664665{
    665666        return EOK;
     
    690691}
    691692
    692 static int rtl8169_on_activated(nic_t *nic_data)
    693 {
    694         int rc;
     693static errno_t rtl8169_on_activated(nic_t *nic_data)
     694{
     695        errno_t rc;
    695696        uint64_t tmp;
    696697
     
    706707        rc = rtl8169_allocate_buffers(rtl8169);
    707708        if (rc != EOK) {
    708                 ddf_msg(LVL_ERROR, "Error allocating buffers: %d", rc);
     709                ddf_msg(LVL_ERROR, "Error allocating buffers: %s", str_error_name(rc));
    709710                return 0;
    710711        }
     
    752753}
    753754
    754 static int rtl8169_on_stopped(nic_t *nic_data)
     755static errno_t rtl8169_on_stopped(nic_t *nic_data)
    755756{
    756757        ddf_msg(LVL_NOTE, "Stopping device");
     
    818819}
    819820
    820 static int rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
     821static errno_t rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
    821822    const nic_address_t *addr, size_t addr_count)
    822823{
     
    870871}
    871872
    872 static int rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
     873static errno_t rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
    873874    const nic_address_t *addr, size_t addr_count)
    874875{
     
    914915}
    915916
    916 static int rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode)
     917static errno_t rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode)
    917918{
    918919        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     
    12071208int main(void)
    12081209{
    1209         int rc = nic_driver_init(NAME);
     1210        errno_t rc = nic_driver_init(NAME);
    12101211        if (rc != EOK)
    12111212                return rc;
Note: See TracChangeset for help on using the changeset viewer.