Ignore:
File:
1 edited

Legend:

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

    rb7fd2a0 rf300523  
    3030#include <async.h>
    3131#include <errno.h>
    32 #include <str_error.h>
    3332#include <align.h>
    3433#include <byteorder.h>
     
    5251FIBRIL_MUTEX_INITIALIZE(irq_reg_lock);
    5352
    54 static errno_t rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr);
    55 static errno_t rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info);
    56 static errno_t rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state);
    57 static errno_t rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
     53static int rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr);
     54static int rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info);
     55static int rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state);
     56static int rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
    5857    nic_channel_mode_t *duplex, nic_role_t *role);
    59 static errno_t rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
     58static int rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
    6059    nic_channel_mode_t duplex, nic_role_t role);
    61 static errno_t rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
     60static int rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
    6261    nic_result_t *we_receive, uint16_t *time);
    63 static errno_t rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     62static int rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
    6463    uint16_t time);
    65 static errno_t rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement);
    66 static errno_t rtl8169_autoneg_disable(ddf_fun_t *fun);
    67 static errno_t rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
     64static int rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement);
     65static int rtl8169_autoneg_disable(ddf_fun_t *fun);
     66static int rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
    6867    uint32_t *their_adv, nic_result_t *result, nic_result_t *their_result);
    69 static errno_t rtl8169_autoneg_restart(ddf_fun_t *fun);
    70 static errno_t rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode);
    71 static errno_t rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode);
    72 static errno_t rtl8169_on_activated(nic_t *nic_data);
    73 static errno_t rtl8169_on_stopped(nic_t *nic_data);
     68static int rtl8169_autoneg_restart(ddf_fun_t *fun);
     69static int rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode);
     70static int rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode);
     71static int rtl8169_on_activated(nic_t *nic_data);
     72static int rtl8169_on_stopped(nic_t *nic_data);
    7473static void rtl8169_send_frame(nic_t *nic_data, void *data, size_t size);
    7574static void rtl8169_irq_handler(ipc_call_t *icall, ddf_dev_t *dev);
    76 static inline errno_t rtl8169_register_int_handler(nic_t *nic_data, cap_handle_t *handle);
     75static inline int rtl8169_register_int_handler(nic_t *nic_data);
    7776static inline void rtl8169_get_hwaddr(rtl8169_t *rtl8169, nic_address_t *addr);
    7877static inline void rtl8169_set_hwaddr(rtl8169_t *rtl8169, const nic_address_t *addr);
    7978
    8079static void rtl8169_reset(rtl8169_t *rtl8169);
    81 static errno_t rtl8169_get_resource_info(ddf_dev_t *dev);
    82 static errno_t rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t *hw_resources);
     80static int rtl8169_get_resource_info(ddf_dev_t *dev);
     81static int rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t *hw_resources);
    8382static rtl8169_t *rtl8169_create_dev_data(ddf_dev_t *dev);
    8483
    85 static errno_t rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
     84static int rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
    8685    const nic_address_t *, size_t);
    87 static errno_t rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
     86static int rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
    8887    const nic_address_t *addr, size_t addr_count);
    89 static errno_t rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode);
     88static int rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode);
    9089
    9190static uint16_t rtl8169_mii_read(rtl8169_t *rtl8169, uint8_t addr);
     
    161160static ddf_dev_ops_t rtl8169_dev_ops;
    162161
    163 static errno_t rtl8169_dev_add(ddf_dev_t *dev);
     162static int rtl8169_dev_add(ddf_dev_t *dev);
    164163
    165164/** Basic driver operations for RTL8169 driver */
     
    174173};
    175174
    176 static errno_t rtl8169_get_resource_info(ddf_dev_t *dev)
     175static int rtl8169_get_resource_info(ddf_dev_t *dev)
    177176{
    178177        assert(dev);
     
    185184
    186185        /* Get hw resources form parent driver */
    187         errno_t rc = nic_get_resources(nic_data, &hw_res_parsed);
     186        int rc = nic_get_resources(nic_data, &hw_res_parsed);
    188187        if (rc != EOK)
    189188                return rc;
    190189
    191190        /* Fill resources information to the device */
    192         errno_t ret = rtl8169_fill_resource_info(dev, &hw_res_parsed);
     191        int ret = rtl8169_fill_resource_info(dev, &hw_res_parsed);
    193192        hw_res_list_parsed_clean(&hw_res_parsed);
    194193
     
    196195}
    197196
    198 static errno_t rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t
     197static int rtl8169_fill_resource_info(ddf_dev_t *dev, const hw_res_list_parsed_t
    199198    *hw_resources)
    200199{
     
    229228}
    230229
    231 static errno_t rtl8169_allocate_buffers(rtl8169_t *rtl8169)
    232 {
    233         errno_t rc;
     230static int rtl8169_allocate_buffers(rtl8169_t *rtl8169)
     231{
     232        int rc;
    234233
    235234        ddf_msg(LVL_DEBUG, "Allocating DMA buffer rings");
     
    334333}
    335334
    336 static errno_t rtl8169_dev_initialize(ddf_dev_t *dev)
    337 {
    338         errno_t ret;
     335static int rtl8169_dev_initialize(ddf_dev_t *dev)
     336{
     337        int ret;
    339338
    340339        rtl8169_t *rtl8169 = rtl8169_create_dev_data(dev);
     
    360359}
    361360
    362 inline static errno_t rtl8169_register_int_handler(nic_t *nic_data, cap_handle_t *handle)
     361inline static int rtl8169_register_int_handler(nic_t *nic_data)
    363362{
    364363        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     
    368367        rtl8169_irq_code.cmds[2].addr = rtl8169->regs + ISR;
    369368        rtl8169_irq_code.cmds[3].addr = rtl8169->regs + IMR;
    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 
    376 static errno_t rtl8169_dev_add(ddf_dev_t *dev)
     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
     375static int rtl8169_dev_add(ddf_dev_t *dev)
    377376{
    378377        ddf_fun_t *fun;
    379378        nic_address_t nic_addr;
    380         errno_t rc;
     379        int rc;
    381380
    382381        assert(dev);
     
    428427                goto err_pio;
    429428
    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));
     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);
    434433                goto err_irq;
    435434        }
     
    481480}
    482481
    483 static errno_t rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr)
     482static int rtl8169_set_addr(ddf_fun_t *fun, const nic_address_t *addr)
    484483{
    485484        nic_t *nic_data = nic_get_from_ddf_fun(fun);
    486485        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    487         errno_t rc;
     486        int rc;
    488487
    489488        fibril_mutex_lock(&rtl8169->rx_lock);
     
    502501}
    503502
    504 static errno_t rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
     503static int rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
    505504{
    506505        nic_t *nic_data = nic_get_from_ddf_fun(fun);
     
    528527}
    529528
    530 static errno_t rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state)
     529static int rtl8169_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state)
    531530{
    532531        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    541540}
    542541
    543 static errno_t rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
     542static int rtl8169_get_operation_mode(ddf_fun_t *fun, int *speed,
    544543    nic_channel_mode_t *duplex, nic_role_t *role)
    545544{
     
    563562}
    564563
    565 static errno_t rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
     564static int rtl8169_set_operation_mode(ddf_fun_t *fun, int speed,
    566565    nic_channel_mode_t duplex, nic_role_t role)
    567566{
     
    594593}
    595594
    596 static errno_t rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
     595static int rtl8169_pause_get(ddf_fun_t *fun, nic_result_t *we_send,
    597596    nic_result_t *we_receive, uint16_t *time)
    598597{
     
    600599}
    601600
    602 static errno_t rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     601static int rtl8169_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
    603602    uint16_t time)
    604603{
     
    606605}
    607606
    608 static errno_t rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement)
     607static int rtl8169_autoneg_enable(ddf_fun_t *fun, uint32_t advertisement)
    609608{
    610609        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    630629}
    631630
    632 static errno_t rtl8169_autoneg_disable(ddf_fun_t *fun)
     631static int rtl8169_autoneg_disable(ddf_fun_t *fun)
    633632{
    634633        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    641640}
    642641
    643 static errno_t rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
     642static int rtl8169_autoneg_probe(ddf_fun_t *fun, uint32_t *advertisement,
    644643    uint32_t *their_adv, nic_result_t *result, nic_result_t *their_result)
    645644{
     
    647646}
    648647
    649 static errno_t rtl8169_autoneg_restart(ddf_fun_t *fun)
     648static int rtl8169_autoneg_restart(ddf_fun_t *fun)
    650649{
    651650        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     
    657656}
    658657
    659 static errno_t rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode)
    660 {
    661         return EOK;
    662 }
    663 
    664 static errno_t rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode)
     658static int rtl8169_defective_get_mode(ddf_fun_t *fun, uint32_t *mode)
     659{
     660        return EOK;
     661}
     662
     663static int rtl8169_defective_set_mode(ddf_fun_t *fun, uint32_t mode)
    665664{
    666665        return EOK;
     
    691690}
    692691
    693 static errno_t rtl8169_on_activated(nic_t *nic_data)
    694 {
    695         errno_t rc;
     692static int rtl8169_on_activated(nic_t *nic_data)
     693{
     694        int rc;
    696695        uint64_t tmp;
    697696
     
    707706        rc = rtl8169_allocate_buffers(rtl8169);
    708707        if (rc != EOK) {
    709                 ddf_msg(LVL_ERROR, "Error allocating buffers: %s", str_error_name(rc));
     708                ddf_msg(LVL_ERROR, "Error allocating buffers: %d", rc);
    710709                return 0;
    711710        }
     
    753752}
    754753
    755 static errno_t rtl8169_on_stopped(nic_t *nic_data)
     754static int rtl8169_on_stopped(nic_t *nic_data)
    756755{
    757756        ddf_msg(LVL_NOTE, "Stopping device");
     
    819818}
    820819
    821 static errno_t rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
     820static int rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
    822821    const nic_address_t *addr, size_t addr_count)
    823822{
     
    871870}
    872871
    873 static errno_t rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
     872static int rtl8169_multicast_set(nic_t *nic_data, nic_multicast_mode_t mode,
    874873    const nic_address_t *addr, size_t addr_count)
    875874{
     
    915914}
    916915
    917 static errno_t rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode)
     916static int rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode)
    918917{
    919918        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     
    12081207int main(void)
    12091208{
    1210         errno_t rc = nic_driver_init(NAME);
     1209        int rc = nic_driver_init(NAME);
    12111210        if (rc != EOK)
    12121211                return rc;
Note: See TracChangeset for help on using the changeset viewer.