Changes in / [96e368a:cbfece7] in mainline


Ignore:
Location:
uspace
Files:
2 added
32 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nic/nic.c

    r96e368a rcbfece7  
    6060        printf("\taddr <mac_address> - set MAC address\n");
    6161        printf("\tspeed <10|100|1000> - set NIC speed\n");
    62         printf("\tduplex <half|full> - set duplex mode\n");
     62        printf("\tduplex <half|full|simplex> - set duplex mode\n");
     63        printf("\tauto - enable autonegotiation\n");
    6364}
    6465
     
    206207        }
    207208
    208         printf("[Service Name]\n");
     209        printf("[Index]: [Service Name]\n");
    209210        for (i = 0; i < count; i++) {
    210211                rc = loc_service_get_name(nics[i], &svc_name);
     
    320321
    321322        return nic_set_operation_mode(sess, oldspeed, duplex, oldrole);
     323}
     324
     325static int nic_set_autoneg(int i)
     326{
     327        async_sess_t *sess;
     328        int rc;
     329
     330        sess = get_nic_by_index(i);
     331        if (sess == NULL) {
     332                printf("Specified NIC doesn't exist or cannot connect to it.\n");
     333                return EINVAL;
     334        }
     335
     336        rc = nic_autoneg_restart(sess);
     337        if (rc != EOK) {
     338                printf("Error restarting NIC autonegotiation.\n");
     339                return EIO;
     340        }
     341
     342        return EOK;
    322343}
    323344
     
    376397                        return nic_set_duplex(index, argv[3]);
    377398
     399                if (!str_cmp(argv[2], "auto"))
     400                        return nic_set_autoneg(index);
     401
    378402        } else {
    379403                printf(NAME ": Invalid argument.\n");
  • uspace/drv/audio/sb16/mixer_iface.c

    r96e368a rcbfece7  
    3333 */
    3434
     35#include <ddf/driver.h>
    3536#include <errno.h>
    3637#include <audio_mixer_iface.h>
    3738
    3839#include "mixer.h"
     40#include "sb16.h"
     41
     42static sb_mixer_t *fun_to_mixer(ddf_fun_t *fun)
     43{
     44        sb16_t *sb = (sb16_t *)ddf_dev_data_get(ddf_fun_get_dev(fun));
     45        return &sb->mixer;
     46}
    3947
    4048static int sb_get_info(ddf_fun_t *fun, const char** name, unsigned *items)
    4149{
    42         assert(fun);
    43         const sb_mixer_t *mixer = ddf_fun_data_get(fun);
    44         assert(mixer);
     50        sb_mixer_t *mixer = fun_to_mixer(fun);
     51
    4552        if (name)
    4653                *name = sb_mixer_type_str(mixer->type);
     
    5461    unsigned *max_level)
    5562{
    56         assert(fun);
    57         const sb_mixer_t *mixer = ddf_fun_data_get(fun);
    58         assert(mixer);
    59         return
    60             sb_mixer_get_control_item_info(mixer, item, name, max_level);
     63        sb_mixer_t *mixer = fun_to_mixer(fun);
     64        return sb_mixer_get_control_item_info(mixer, item, name, max_level);
    6165}
    6266
    6367static int sb_set_item_level(ddf_fun_t *fun, unsigned item, unsigned value)
    6468{
    65         assert(fun);
    66         const sb_mixer_t *mixer = ddf_fun_data_get(fun);
    67         assert(mixer);
     69        sb_mixer_t *mixer = fun_to_mixer(fun);
    6870        return sb_mixer_set_control_item_value(mixer, item, value);
    6971}
     
    7173static int sb_get_item_level(ddf_fun_t *fun, unsigned item, unsigned *value)
    7274{
    73         assert(fun);
    74         const sb_mixer_t *mixer = ddf_fun_data_get(fun);
    75         assert(mixer);
     75        sb_mixer_t *mixer = fun_to_mixer(fun);
    7676        return sb_mixer_get_control_item_value(mixer, item, value);
    7777}
  • uspace/drv/audio/sb16/pcm_iface.c

    r96e368a rcbfece7  
    3939
    4040#include "dsp.h"
     41#include "sb16.h"
    4142
    42 static inline sb_dsp_t * fun_to_dsp(ddf_fun_t *fun)
     43static inline sb_dsp_t *fun_to_dsp(ddf_fun_t *fun)
    4344{
    44         assert(fun);
    45         sb_dsp_t *dsp = ddf_fun_data_get(fun);
    46         assert(dsp);
    47         return dsp;
     45        sb16_t *sb = (sb16_t *)ddf_dev_data_get(ddf_fun_get_dev(fun));
     46        return &sb->dsp;
    4847}
    4948
  • uspace/drv/audio/sb16/sb16.c

    r96e368a rcbfece7  
    2727 */
    2828
    29 #define _DDF_DATA_IMPLANT
    30 
    3129#include <errno.h>
    3230#include <str_error.h>
     
    121119                return ret;
    122120        }
    123         //TODO remove data implant
    124         ddf_fun_data_implant(dsp_fun, &sb->dsp);
     121
    125122        ddf_fun_set_ops(dsp_fun, &sb_pcm_ops);
    126123        ddf_log_note("Sound blaster DSP (%x.%x) initialized.",
     
    131128                ddf_log_error(
    132129                    "Failed to bind PCM function: %s.", str_error(ret));
    133                 // TODO implanted data
    134130                ddf_fun_destroy(dsp_fun);
    135131                return ret;
     
    141137                    str_error(ret));
    142138                ddf_fun_unbind(dsp_fun);
    143                 // TODO implanted data
    144139                ddf_fun_destroy(dsp_fun);
    145140                return ret;
     
    154149                ddf_log_error("Failed to create mixer function.");
    155150                ddf_fun_unbind(dsp_fun);
    156                 // TODO implanted data
    157151                ddf_fun_destroy(dsp_fun);
    158152                return ENOMEM;
     
    163157                    str_error(ret));
    164158                ddf_fun_unbind(dsp_fun);
    165                 // TODO implanted data
    166159                ddf_fun_destroy(dsp_fun);
    167160                ddf_fun_destroy(mixer_fun);
     
    171164        ddf_log_note("Initialized mixer: %s.",
    172165            sb_mixer_type_str(sb->mixer.type));
    173         ddf_fun_data_implant(mixer_fun, &sb->mixer);
    174166        ddf_fun_set_ops(mixer_fun, &sb_mixer_ops);
    175167
     
    178170                ddf_log_error(
    179171                    "Failed to bind mixer function: %s.", str_error(ret));
    180                 // TODO implanted data
    181172                ddf_fun_destroy(mixer_fun);
    182 
    183                 ddf_fun_unbind(dsp_fun);
    184                 // TODO implanted data
     173                ddf_fun_unbind(dsp_fun);
    185174                ddf_fun_destroy(dsp_fun);
    186175                return ret;
  • uspace/drv/block/ahci/ahci.c

    r96e368a rcbfece7  
    3838#include <device/hw_res_parsed.h>
    3939#include <pci_dev_iface.h>
    40 #include <sysinfo.h>
    41 #include <ipc/irc.h>
    42 #include <ns.h>
     40#include <irc.h>
    4341#include <ahci_iface.h>
    4442#include "ahci.h"
     
    129127
    130128static void ahci_get_model_name(uint16_t *, char *);
    131 static int ahci_enable_interrupt(int);
    132129
    133130static fibril_mutex_t sata_devices_count_lock;
     
    11951192        }
    11961193       
    1197         rc = ahci_enable_interrupt(hw_res_parsed.irqs.irqs[0]);
     1194        rc = irc_enable_interrupt(hw_res_parsed.irqs.irqs[0]);
    11981195        if (rc != EOK) {
    11991196                ddf_msg(LVL_ERROR, "Failed enable interupt.");
     
    13151312}
    13161313
    1317 /** Enable interrupt using SERVICE_IRC.
    1318  *
    1319  * @param irq Requested irq number.
    1320  *
    1321  * @return EOK if succeed, error code otherwise.
    1322  *
    1323  */
    1324 static int ahci_enable_interrupt(int irq)
    1325 {
    1326         async_sess_t *irc_sess = NULL;
    1327         irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_IRC, 0, 0);
    1328         if (!irc_sess)
    1329                 return EINTR;
    1330        
    1331         async_exch_t *exch = async_exchange_begin(irc_sess);
    1332         const int rc = async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
    1333         async_exchange_end(exch);
    1334        
    1335         async_hangup(irc_sess);
    1336         return rc;
    1337 }
    1338 
    13391314/*----------------------------------------------------------------------------*/
    13401315/*-- AHCI Main routine -------------------------------------------------------*/
  • uspace/drv/bus/isa/isa.c

    r96e368a rcbfece7  
    5454#include <ipc/irc.h>
    5555#include <ipc/services.h>
    56 #include <sysinfo.h>
    57 #include <ns.h>
    5856#include <sys/stat.h>
    59 #include <ipc/irc.h>
    60 #include <ipc/services.h>
    61 #include <sysinfo.h>
     57#include <irc.h>
    6258#include <ns.h>
    6359
     
    120116        assert(fun);
    121117
    122         sysarg_t apic;
    123         sysarg_t i8259;
    124 
    125         async_sess_t *irc_sess = NULL;
    126 
    127         if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
    128             || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
    129                 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
    130                     SERVICE_IRC, 0, 0);
    131         }
    132 
    133         if (!irc_sess)
    134                 return false;
    135 
    136118        const hw_resource_list_t *res = &fun->hw_resources;
    137119        assert(res);
    138120        for (size_t i = 0; i < res->count; ++i) {
    139121                if (res->resources[i].type == INTERRUPT) {
    140                         const int irq = res->resources[i].res.interrupt.irq;
    141 
    142                         async_exch_t *exch = async_exchange_begin(irc_sess);
    143                         const int rc =
    144                             async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
    145                         async_exchange_end(exch);
    146 
    147                         if (rc != EOK) {
    148                                 async_hangup(irc_sess);
     122                        int rc = irc_enable_interrupt(
     123                            res->resources[i].res.interrupt.irq);
     124
     125                        if (rc != EOK)
    149126                                return false;
    150                         }
    151                 }
    152         }
    153 
    154         async_hangup(irc_sess);
     127                }
     128        }
     129
    155130        return true;
    156131}
  • uspace/drv/bus/pci/pciintel/pci.c

    r96e368a rcbfece7  
    5151#include <ddf/log.h>
    5252#include <ipc/dev_iface.h>
    53 #include <ipc/irc.h>
    54 #include <ns.h>
    55 #include <ipc/services.h>
    56 #include <sysinfo.h>
     53#include <irc.h>
    5754#include <ops/hw_res.h>
    5855#include <device/hw_res.h>
     
    107104        pci_fun_t *dev_data = pci_fun(fnode);
    108105       
    109         sysarg_t apic;
    110         sysarg_t i8259;
    111        
    112         async_sess_t *irc_sess = NULL;
    113        
    114         if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
    115             || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
    116                 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
    117                     SERVICE_IRC, 0, 0);
    118         }
    119        
    120         if (!irc_sess)
    121                 return false;
    122        
    123106        size_t i = 0;
    124107        hw_resource_list_t *res = &dev_data->hw_resources;
    125108        for (; i < res->count; i++) {
    126109                if (res->resources[i].type == INTERRUPT) {
    127                         const int irq = res->resources[i].res.interrupt.irq;
    128                        
    129                         async_exch_t *exch = async_exchange_begin(irc_sess);
    130                         const int rc =
    131                             async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
    132                         async_exchange_end(exch);
    133                        
    134                         if (rc != EOK) {
    135                                 async_hangup(irc_sess);
     110                        int rc = irc_enable_interrupt(
     111                            res->resources[i].res.interrupt.irq);
     112                       
     113                        if (rc != EOK)
    136114                                return false;
    137                         }
    138115                }
    139116        }
    140117       
    141         async_hangup(irc_sess);
    142118        return true;
    143119}
  • uspace/drv/bus/usb/usbhid/generic/hiddev.c

    r96e368a rcbfece7  
    3535 */
    3636
    37 /* XXX Fix this */
    38 #define _DDF_DATA_IMPLANT
    39 
    4037#include <usb/debug.h>
    4138#include <usb/classes/classes.h>
  • uspace/drv/bus/usb/usbhid/kbd/kbddev.c

    r96e368a rcbfece7  
    3434 * USB HID keyboard device structure and API.
    3535 */
    36 
    37 /* XXX Fix this */
    38 #define _DDF_DATA_IMPLANT
    3936
    4037#include <errno.h>
     
    479476}
    480477
    481 /* HID/KBD structure manipulation                                             */
    482 
    483 static int usb_kbd_create_function(usb_kbd_t *kbd_dev)
    484 {
    485         assert(kbd_dev != NULL);
    486         assert(kbd_dev->hid_dev != NULL);
    487         assert(kbd_dev->hid_dev->usb_dev != NULL);
     478/* API functions                                                              */
     479
     480/**
     481 * Initialization of the USB/HID keyboard structure.
     482 *
     483 * This functions initializes required structures from the device's descriptors.
     484 *
     485 * During initialization, the keyboard is switched into boot protocol, the idle
     486 * rate is set to 0 (infinity), resulting in the keyboard only reporting event
     487 * when a key is pressed or released. Finally, the LED lights are turned on
     488 * according to the default setup of lock keys.
     489 *
     490 * @note By default, the keyboards is initialized with Num Lock turned on and
     491 *       other locks turned off.
     492 *
     493 * @param kbd_dev Keyboard device structure to be initialized.
     494 * @param dev DDF device structure of the keyboard.
     495 *
     496 * @retval EOK if successful.
     497 * @retval EINVAL if some parameter is not given.
     498 * @return Other value inherited from function usbhid_dev_init().
     499 */
     500int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data)
     501{
     502        ddf_fun_t *fun = NULL;
     503        usb_kbd_t *kbd_dev = NULL;
     504        usb_hid_report_path_t *path = NULL;
     505        bool bound = false;
     506        fid_t fid = 0;
     507        int rc;
     508
     509        usb_log_debug("Initializing HID/KBD structure...\n");
     510
     511        if (hid_dev == NULL) {
     512                usb_log_error(
     513                    "Failed to init keyboard structure: no structure given.\n");
     514                rc = EINVAL;
     515                goto error;
     516        }
    488517
    489518        /* Create the exposed function. */
    490519        usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME);
    491         ddf_fun_t *fun = ddf_fun_create(kbd_dev->hid_dev->usb_dev->ddf_dev,
    492             fun_exposed, HID_KBD_FUN_NAME);
     520        fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     521            HID_KBD_FUN_NAME);
    493522        if (fun == NULL) {
    494523                usb_log_error("Could not create DDF function node.\n");
    495                 return ENOMEM;
     524                rc = ENOMEM;
     525                goto error;
    496526        }
    497527
     
    499529         * to the DDF function. */
    500530        ddf_fun_set_ops(fun, &kbdops);
    501         ddf_fun_data_implant(fun, kbd_dev);
    502 
    503         int rc = ddf_fun_bind(fun);
     531
     532        kbd_dev = ddf_fun_data_alloc(fun, sizeof(usb_kbd_t));
     533        if (kbd_dev == NULL) {
     534                usb_log_error("Failed to allocate KBD device structure.\n");
     535                rc = ENOMEM;
     536                goto error;
     537        }
     538
     539        kbd_dev->fun = fun;
     540
     541        /* Default values */
     542        fibril_mutex_initialize(&kbd_dev->repeat_mtx);
     543        kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
     544
     545        /* Store link to HID device */
     546        kbd_dev->hid_dev = hid_dev;
     547
     548        /* Modifiers and locks */
     549        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
     550
     551        /* Autorepeat */
     552        kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
     553        kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
     554
     555        // TODO: make more general
     556        path = usb_hid_report_path();
     557        if (path == NULL) {
     558                usb_log_error("Failed to create kbd report path.\n");
     559                rc = ENOMEM;
     560                goto error;
     561        }
     562
     563        rc = usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
     564        if (rc != EOK) {
     565                usb_log_error("Failed to append item to kbd report path.\n");
     566                goto error;
     567        }
     568
     569        usb_hid_report_path_set_report_id(path, 0);
     570
     571        kbd_dev->key_count =
     572            usb_hid_report_size(&hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
     573
     574        usb_hid_report_path_free(path);
     575        path = NULL;
     576
     577        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
     578
     579        kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
     580        if (kbd_dev->keys == NULL) {
     581                usb_log_error("Failed to allocate key buffer.\n");
     582                rc = ENOMEM;
     583                goto error;
     584        }
     585
     586        kbd_dev->keys_old = calloc(kbd_dev->key_count, sizeof(int32_t));
     587        if (kbd_dev->keys_old == NULL) {
     588                usb_log_error("Failed to allocate old_key buffer.\n");
     589                rc = ENOMEM;
     590                goto error;
     591        }
     592
     593        /* Output report */
     594        kbd_dev->output_size = 0;
     595        kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
     596            &kbd_dev->output_size, 0);
     597        if (kbd_dev->output_buffer == NULL) {
     598                usb_log_error("Error creating output report buffer.\n");
     599                rc = ENOMEM;
     600                goto error;
     601        }
     602
     603        usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
     604
     605        kbd_dev->led_path = usb_hid_report_path();
     606        if (kbd_dev->led_path == NULL) {
     607                usb_log_error("Failed to create kbd led report path.\n");
     608                rc = ENOMEM;
     609                goto error;
     610        }
     611
     612        rc = usb_hid_report_path_append_item(
     613            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
     614        if (rc != EOK) {
     615                usb_log_error("Failed to append to kbd/led report path.\n");
     616                goto error;
     617        }
     618
     619        kbd_dev->led_output_size = usb_hid_report_size(
     620            &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
     621
     622        usb_log_debug("Output report size (in items): %zu\n",
     623            kbd_dev->led_output_size);
     624
     625        kbd_dev->led_data = calloc(kbd_dev->led_output_size, sizeof(int32_t));
     626        if (kbd_dev->led_data == NULL) {
     627                usb_log_error("Error creating buffer for LED output report.\n");
     628                rc = ENOMEM;
     629                goto error;
     630        }
     631
     632        /* Set LEDs according to initial setup.
     633         * Set Idle rate */
     634        usb_kbd_set_led(hid_dev, kbd_dev);
     635
     636        usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
     637            hid_dev->usb_dev->interface_no, IDLE_RATE);
     638
     639        /* Create new fibril for auto-repeat. */
     640        fid = fibril_create(usb_kbd_repeat_fibril, kbd_dev);
     641        if (fid == 0) {
     642                usb_log_error("Failed to start fibril for KBD auto-repeat");
     643                rc = ENOMEM;
     644                goto error;
     645        }
     646
     647        kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
     648        usb_log_debug("HID/KBD device structure initialized.\n");
     649
     650        rc = ddf_fun_bind(fun);
    504651        if (rc != EOK) {
    505652                usb_log_error("Could not bind DDF function: %s.\n",
    506653                    str_error(rc));
    507                 ddf_fun_destroy(fun);
    508                 return rc;
    509         }
     654                goto error;
     655        }
     656
     657        bound = true;
    510658
    511659        usb_log_debug("%s function created. Handle: %" PRIun "\n",
     
    519667                    "Could not add DDF function to category %s: %s.\n",
    520668                    HID_KBD_CATEGORY, str_error(rc));
    521                 if (ddf_fun_unbind(fun) == EOK) {
    522                         ddf_fun_destroy(fun);
    523                 } else {
    524                         usb_log_error(
    525                             "Failed to unbind `%s', will not destroy.\n",
    526                             ddf_fun_get_name(fun));
    527                 }
    528                 return rc;
    529         }
    530         kbd_dev->fun = fun;
    531 
    532         return EOK;
    533 }
    534 
    535 /* API functions                                                              */
    536 
    537 /**
    538  * Initialization of the USB/HID keyboard structure.
    539  *
    540  * This functions initializes required structures from the device's descriptors.
    541  *
    542  * During initialization, the keyboard is switched into boot protocol, the idle
    543  * rate is set to 0 (infinity), resulting in the keyboard only reporting event
    544  * when a key is pressed or released. Finally, the LED lights are turned on
    545  * according to the default setup of lock keys.
    546  *
    547  * @note By default, the keyboards is initialized with Num Lock turned on and
    548  *       other locks turned off.
    549  *
    550  * @param kbd_dev Keyboard device structure to be initialized.
    551  * @param dev DDF device structure of the keyboard.
    552  *
    553  * @retval EOK if successful.
    554  * @retval EINVAL if some parameter is not given.
    555  * @return Other value inherited from function usbhid_dev_init().
    556  */
    557 int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data)
    558 {
    559         usb_log_debug("Initializing HID/KBD structure...\n");
    560 
    561         if (hid_dev == NULL) {
    562                 usb_log_error(
    563                     "Failed to init keyboard structure: no structure given.\n");
    564                 return EINVAL;
    565         }
    566 
    567         usb_kbd_t *kbd_dev = calloc(1, sizeof(usb_kbd_t));
    568         if (kbd_dev == NULL) {
    569                 usb_log_error("Failed to allocate KBD device structure.\n");
    570                 return ENOMEM;
    571         }
    572         /* Default values */
    573         fibril_mutex_initialize(&kbd_dev->repeat_mtx);
    574         kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
    575 
    576         /* Store link to HID device */
    577         kbd_dev->hid_dev = hid_dev;
    578 
    579         /* Modifiers and locks */
    580         kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    581 
    582         /* Autorepeat */
    583         kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
    584         kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
    585 
    586 
    587         // TODO: make more general
    588         usb_hid_report_path_t *path = usb_hid_report_path();
    589         if (path == NULL) {
    590                 usb_log_error("Failed to create kbd report path.\n");
    591                 usb_kbd_destroy(kbd_dev);
    592                 return ENOMEM;
    593         }
    594 
    595         int ret =
    596             usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    597         if (ret != EOK) {
    598                 usb_log_error("Failed to append item to kbd report path.\n");
    599                 usb_hid_report_path_free(path);
    600                 usb_kbd_destroy(kbd_dev);
    601                 return ret;
    602         }
    603 
    604         usb_hid_report_path_set_report_id(path, 0);
    605 
    606         kbd_dev->key_count =
    607             usb_hid_report_size(&hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
    608 
    609         usb_hid_report_path_free(path);
    610 
    611         usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    612 
    613         kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
    614         if (kbd_dev->keys == NULL) {
    615                 usb_log_error("Failed to allocate key buffer.\n");
    616                 usb_kbd_destroy(kbd_dev);
    617                 return ENOMEM;
    618         }
    619 
    620         kbd_dev->keys_old = calloc(kbd_dev->key_count, sizeof(int32_t));
    621         if (kbd_dev->keys_old == NULL) {
    622                 usb_log_error("Failed to allocate old_key buffer.\n");
    623                 usb_kbd_destroy(kbd_dev);
    624                 return ENOMEM;
    625         }
    626 
    627         /* Output report */
    628         kbd_dev->output_size = 0;
    629         kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
    630             &kbd_dev->output_size, 0);
    631         if (kbd_dev->output_buffer == NULL) {
    632                 usb_log_error("Error creating output report buffer.\n");
    633                 usb_kbd_destroy(kbd_dev);
    634                 return ENOMEM;
    635         }
    636 
    637         usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
    638 
    639         kbd_dev->led_path = usb_hid_report_path();
    640         if (kbd_dev->led_path == NULL) {
    641                 usb_log_error("Failed to create kbd led report path.\n");
    642                 usb_kbd_destroy(kbd_dev);
    643                 return ENOMEM;
    644         }
    645 
    646         ret = usb_hid_report_path_append_item(
    647             kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
    648         if (ret != EOK) {
    649                 usb_log_error("Failed to append to kbd/led report path.\n");
    650                 usb_kbd_destroy(kbd_dev);
    651                 return ret;
    652         }
    653 
    654         kbd_dev->led_output_size = usb_hid_report_size(
    655             &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
    656 
    657         usb_log_debug("Output report size (in items): %zu\n",
    658             kbd_dev->led_output_size);
    659 
    660         kbd_dev->led_data = calloc(kbd_dev->led_output_size, sizeof(int32_t));
    661         if (kbd_dev->led_data == NULL) {
    662                 usb_log_error("Error creating buffer for LED output report.\n");
    663                 usb_kbd_destroy(kbd_dev);
    664                 return ENOMEM;
    665         }
    666 
    667         /* Set LEDs according to initial setup.
    668          * Set Idle rate */
    669         usb_kbd_set_led(hid_dev, kbd_dev);
    670 
    671         usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
    672             hid_dev->usb_dev->interface_no, IDLE_RATE);
     669                goto error;
     670        }
     671
     672        fibril_add_ready(fid);
    673673
    674674        /* Save the KBD device structure into the HID device structure. */
    675675        *data = kbd_dev;
    676676
    677         kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
    678         usb_log_debug("HID/KBD device structure initialized.\n");
    679 
    680         usb_log_debug("Creating KBD function...\n");
    681         ret = usb_kbd_create_function(kbd_dev);
    682         if (ret != EOK) {
    683                 usb_kbd_destroy(kbd_dev);
    684                 return ret;
    685         }
    686 
    687         /* Create new fibril for auto-repeat. */
    688         fid_t fid = fibril_create(usb_kbd_repeat_fibril, kbd_dev);
    689         if (fid == 0) {
    690                 usb_log_error("Failed to start fibril for KBD auto-repeat");
    691                 usb_kbd_destroy(kbd_dev);
    692                 return ENOMEM;
    693         }
    694         fibril_add_ready(fid);
    695 
    696677        return EOK;
     678error:
     679        if (bound)
     680                ddf_fun_unbind(fun);
     681        if (fid != 0)
     682                fibril_destroy(fid);
     683        if (kbd_dev != NULL) {
     684                free(kbd_dev->led_data);
     685                if (kbd_dev->led_path != NULL)
     686                        usb_hid_report_path_free(kbd_dev->led_path);
     687                if (kbd_dev->output_buffer != NULL)
     688                        usb_hid_report_output_free(kbd_dev->output_buffer);
     689                free(kbd_dev->keys_old);
     690                free(kbd_dev->keys);
     691        }
     692        if (path != NULL)
     693                usb_hid_report_path_free(path);
     694        if (fun != NULL)
     695                ddf_fun_destroy(fun);
     696        return rc;
    697697}
    698698
     
    749749        usb_hid_report_output_free(kbd_dev->output_buffer);
    750750
    751         if (kbd_dev->fun) {
    752                 if (ddf_fun_unbind(kbd_dev->fun) != EOK) {
    753                         usb_log_warning("Failed to unbind %s.\n",
    754                             ddf_fun_get_name(kbd_dev->fun));
    755                 } else {
    756                         usb_log_debug2("%s unbound.\n",
    757                             ddf_fun_get_name(kbd_dev->fun));
    758                         ddf_fun_destroy(kbd_dev->fun);
    759                 }
    760         }
     751        ddf_fun_unbind(kbd_dev->fun);
     752        ddf_fun_destroy(kbd_dev->fun);
    761753}
    762754
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r96e368a rcbfece7  
    3434 * USB Mouse driver API.
    3535 */
    36 
    37 /* XXX Fix this */
    38 #define _DDF_DATA_IMPLANT
    3936
    4037#include <usb/debug.h>
     
    249246}
    250247
    251 #define FUN_UNBIND_DESTROY(fun) \
    252 if (fun) { \
    253         if (ddf_fun_unbind((fun)) == EOK) { \
    254                 ddf_fun_destroy((fun)); \
    255         } else { \
    256                 usb_log_error("Could not unbind function `%s', it " \
    257                     "will not be destroyed.\n", ddf_fun_get_name(fun)); \
    258         } \
    259 } else (void)0
    260 
    261 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)
    262 {
    263         assert(hid_dev != NULL);
    264         assert(mouse != NULL);
    265 
    266         /* Create the exposed function. */
    267         usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
    268         ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    269             HID_MOUSE_FUN_NAME);
    270         if (fun == NULL) {
    271                 usb_log_error("Could not create DDF function node `%s'.\n",
    272                     HID_MOUSE_FUN_NAME);
    273                 return ENOMEM;
    274         }
    275 
    276         ddf_fun_set_ops(fun, &ops);
    277         ddf_fun_data_implant(fun, mouse);
    278 
    279         int rc = ddf_fun_bind(fun);
    280         if (rc != EOK) {
    281                 usb_log_error("Could not bind DDF function `%s': %s.\n",
    282                     ddf_fun_get_name(fun), str_error(rc));
    283                 ddf_fun_destroy(fun);
    284                 return rc;
    285         }
    286 
    287         usb_log_debug("Adding DDF function `%s' to category %s...\n",
    288             ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);
    289         rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
    290         if (rc != EOK) {
    291                 usb_log_error(
    292                     "Could not add DDF function to category %s: %s.\n",
    293                     HID_MOUSE_CATEGORY, str_error(rc));
    294                 FUN_UNBIND_DESTROY(fun);
    295                 return rc;
    296         }
    297         mouse->mouse_fun = fun;
    298         return EOK;
    299 }
    300 
    301248/** Get highest index of a button mentioned in given report.
    302249 *
     
    341288int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    342289{
     290        ddf_fun_t *fun = NULL;
     291        usb_mouse_t *mouse_dev = NULL;
     292        bool bound = false;
     293        int rc;
     294
    343295        usb_log_debug("Initializing HID/Mouse structure...\n");
    344296
     
    346298                usb_log_error("Failed to init mouse structure: no structure"
    347299                    " given.\n");
    348                 return EINVAL;
    349         }
    350 
    351         usb_mouse_t *mouse_dev = calloc(1, sizeof(usb_mouse_t));
     300                rc = EINVAL;
     301                goto error;
     302        }
     303
     304        /* Create the exposed function. */
     305        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
     306        fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     307            HID_MOUSE_FUN_NAME);
     308        if (fun == NULL) {
     309                usb_log_error("Could not create DDF function node `%s'.\n",
     310                    HID_MOUSE_FUN_NAME);
     311                rc = ENOMEM;
     312                goto error;
     313        }
     314
     315        ddf_fun_set_ops(fun, &ops);
     316
     317        mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t));
    352318        if (mouse_dev == NULL) {
    353319                usb_log_error("Error while creating USB/HID Mouse device "
    354320                    "structure.\n");
    355                 return ENOMEM;
     321                rc = ENOMEM;
     322                goto error;
    356323        }
    357324
     
    368335        if (mouse_dev->buttons == NULL) {
    369336                usb_log_error(NAME ": out of memory, giving up on device!\n");
    370                 free(mouse_dev);
    371                 return ENOMEM;
     337                rc = ENOMEM;
     338                goto error;
    372339        }
    373340
     
    376343            hid_dev->usb_dev->interface_no, IDLE_RATE);
    377344
    378         int rc = usb_mouse_create_function(hid_dev, mouse_dev);
     345        rc = ddf_fun_bind(fun);
    379346        if (rc != EOK) {
    380                 free(mouse_dev->buttons);
    381                 free(mouse_dev);
    382                 return rc;
    383         }
     347                usb_log_error("Could not bind DDF function `%s': %s.\n",
     348                    ddf_fun_get_name(fun), str_error(rc));
     349                goto error;
     350        }
     351
     352        bound = true;
     353
     354        usb_log_debug("Adding DDF function `%s' to category %s...\n",
     355            ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);
     356        rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
     357        if (rc != EOK) {
     358                usb_log_error("Could not add DDF function to category %s: "
     359                    "%s.\n", HID_MOUSE_CATEGORY, str_error(rc));
     360                goto error;
     361        }
     362
     363        mouse_dev->mouse_fun = fun;
    384364
    385365        /* Save the Mouse device structure into the HID device structure. */
    386366        *data = mouse_dev;
    387 
    388367        return EOK;
     368error:
     369        if (bound)
     370                ddf_fun_unbind(fun);
     371        if (mouse_dev != NULL)
     372                free(mouse_dev->buttons);
     373        if (fun != NULL)
     374                ddf_fun_destroy(fun);
     375        return rc;
    389376}
    390377
     
    417404        }
    418405
    419         FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
    420 
     406        ddf_fun_unbind(mouse_dev->mouse_fun);
    421407        free(mouse_dev->buttons);
     408        ddf_fun_destroy(mouse_dev->mouse_fun);
    422409}
    423410
  • uspace/drv/char/ns8250/ns8250.c

    r96e368a rcbfece7  
    5757#include <ops/char_dev.h>
    5858
    59 #include <ns.h>
    60 #include <ipc/services.h>
    61 #include <ipc/irc.h>
     59#include <irc.h>
    6260#include <device/hw_res.h>
    6361#include <ipc/serial_ctl.h>
     
    488486static int ns8250_interrupt_enable(ns8250_t *ns)
    489487{
    490         /*
    491          * Enable interrupt using IRC service.
    492          * TODO: This is a temporary solution until the device framework
    493          * takes care of this itself.
    494          */
    495         async_sess_t *irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
    496             SERVICE_IRC, 0, 0);
    497         if (!irc_sess) {
     488        /* Enable interrupt using IRC service. */
     489        int rc = irc_enable_interrupt(ns->irq);
     490        if (rc != EOK)
    498491                return EIO;
    499         }
    500 
    501         async_exch_t *exch = async_exchange_begin(irc_sess);
    502         if (!exch) {
    503                 return EIO;
    504         }
    505         async_msg_1(exch, IRC_ENABLE_INTERRUPT, ns->irq);
    506         async_exchange_end(exch);
    507 
     492       
    508493        /* Read LSR to clear possible previous LSR interrupt */
    509494        pio_read_8(&ns->regs->lsr);
    510 
     495       
    511496        /* Enable interrupt on the serial port. */
    512497        ns8250_port_interrupts_enable(ns->regs);
  • uspace/drv/nic/e1k/e1k.c

    r96e368a rcbfece7  
    3333 */
    3434
    35 /* XXX Fix this */
    36 #define _DDF_DATA_IMPLANT
    37 
    3835#include <assert.h>
    3936#include <stdio.h>
     
    4239#include <align.h>
    4340#include <byteorder.h>
    44 #include <sysinfo.h>
    45 #include <ipc/irc.h>
    46 #include <ipc/ns.h>
     41#include <irc.h>
     42#include <as.h>
    4743#include <ddi.h>
    48 #include <as.h>
    4944#include <ddf/log.h>
    5045#include <ddf/interrupt.h>
     
    17581753        e1000_enable_interrupts(e1000);
    17591754       
    1760         nic_enable_interrupt(nic, e1000->irq);
     1755        int rc = irc_enable_interrupt(e1000->irq);
     1756        if (rc != EOK) {
     1757                e1000_disable_interrupts(e1000);
     1758                fibril_mutex_unlock(&e1000->ctrl_lock);
     1759                fibril_mutex_unlock(&e1000->tx_lock);
     1760                fibril_mutex_unlock(&e1000->rx_lock);
     1761                return rc;
     1762        }
    17611763       
    17621764        e1000_clear_rx_ring(e1000);
     
    17961798        e1000_disable_rx(e1000);
    17971799       
    1798         nic_disable_interrupt(nic, e1000->irq);
     1800        irc_disable_interrupt(e1000->irq);
    17991801        e1000_disable_interrupts(e1000);
    18001802       
     
    21482150        nic_set_ddf_fun(nic, fun);
    21492151        ddf_fun_set_ops(fun, &e1000_dev_ops);
    2150         ddf_fun_data_implant(fun, nic);
    21512152       
    21522153        rc = e1000_register_int_handler(nic);
    21532154        if (rc != EOK)
    21542155                goto err_fun_create;
    2155        
    2156         rc = nic_connect_to_services(nic);
    2157         if (rc != EOK)
    2158                 goto err_irq;
    21592156       
    21602157        rc = e1000_initialize_rx_structure(nic);
     
    23792376int main(void)
    23802377{
    2381         int rc = nic_driver_init(NAME);
    2382         if (rc != EOK)
    2383                 return rc;
     2378        printf("%s: HelenOS E1000 network adapter driver\n", NAME);
     2379       
     2380        if (nic_driver_init(NAME) != EOK)
     2381                return 1;
    23842382       
    23852383        nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops,
     
    23872385       
    23882386        ddf_log_init(NAME);
    2389         ddf_msg(LVL_NOTE, "HelenOS E1000 driver started");
    23902387        return ddf_driver_main(&e1000_driver);
    23912388}
  • uspace/drv/nic/ne2k/ne2k.c

    r96e368a rcbfece7  
    3838 */
    3939
    40 /* XXX Fix this */
    41 #define _DDF_DATA_IMPLANT
    42 
    4340#include <stdio.h>
    4441#include <errno.h>
     42#include <irc.h>
    4543#include <stdlib.h>
    4644#include <str_error.h>
     
    256254        if (!ne2k->up) {
    257255                int rc = ne2k_up(ne2k);
     256                if (rc != EOK)
     257                        return rc;
     258
     259                rc = irc_enable_interrupt(ne2k->irq);
    258260                if (rc != EOK) {
     261                        ne2k_down(ne2k);
    259262                        return rc;
    260263                }
    261 
    262                 nic_enable_interrupt(nic_data, ne2k->irq);
    263264        }
    264265        return EOK;
     
    269270        ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
    270271
    271         nic_disable_interrupt(nic_data, ne2k->irq);
     272        (void) irc_disable_interrupt(ne2k->irq);
    272273        ne2k->receive_configuration = RCR_AB | RCR_AM;
    273274        ne2k_down(ne2k);
     
    396397        }
    397398       
    398         rc = nic_connect_to_services(nic_data);
    399         if (rc != EOK) {
    400                 ne2k_dev_cleanup(dev);
    401                 return rc;
    402         }
    403        
    404399        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
    405400        if (fun == NULL) {
     
    407402                return ENOMEM;
    408403        }
     404       
    409405        nic_set_ddf_fun(nic_data, fun);
    410406        ddf_fun_set_ops(fun, &ne2k_dev_ops);
    411         ddf_fun_data_implant(fun, nic_data);
    412407       
    413408        rc = ddf_fun_bind(fun);
     
    443438int main(int argc, char *argv[])
    444439{
     440        printf("%s: HelenOS NE 2000 network adapter driver\n", NAME);
     441       
    445442        nic_driver_init(NAME);
    446443        nic_driver_implement(&ne2k_driver_ops, &ne2k_dev_ops, &ne2k_nic_iface);
  • uspace/drv/nic/rtl8139/driver.c

    r96e368a rcbfece7  
    2727 */
    2828
    29 /* XXX Fix this */
    30 #define _DDF_DATA_IMPLANT
    31 
    3229#include <assert.h>
    3330#include <errno.h>
     
    3532#include <byteorder.h>
    3633#include <libarch/barrier.h>
    37 
    3834#include <as.h>
    3935#include <ddf/log.h>
     
    4238#include <nic.h>
    4339#include <pci_dev_iface.h>
    44 
    45 #include <ipc/irc.h>
    46 #include <sysinfo.h>
    47 #include <ipc/ns.h>
    48 
     40#include <irc.h>
     41#include <stdio.h>
    4942#include <str.h>
    5043
     
    960953        rtl8139->int_mask = RTL_DEFAULT_INTERRUPTS;
    961954        rtl8139_hw_int_enable(rtl8139);
    962         nic_enable_interrupt(nic_data, rtl8139->irq);
     955
     956        int rc = irc_enable_interrupt(rtl8139->irq);
     957        if (rc != EOK) {
     958                rtl8139_on_stopped(nic_data);
     959                return rc;
     960        }
    963961
    964962        ddf_msg(LVL_DEBUG, "Device activated, interrupt %d registered", rtl8139->irq);
     
    13251323                goto err_pio;
    13261324
    1327         rc = nic_connect_to_services(nic_data);
    1328         if (rc != EOK) {
    1329                 ddf_msg(LVL_ERROR, "Failed to connect to services (%d)", rc);
    1330                 goto err_irq;
    1331         }
    1332 
    13331325        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
    13341326        if (fun == NULL) {
     
    13361328                goto err_srv;
    13371329        }
     1330
    13381331        nic_set_ddf_fun(nic_data, fun);
    13391332        ddf_fun_set_ops(fun, &rtl8139_dev_ops);
    1340         ddf_fun_data_implant(fun, nic_data);
    13411333
    13421334        rc = ddf_fun_bind(fun);
     
    13611353        ddf_fun_destroy(fun);
    13621354err_srv:
    1363         /* XXX Disconnect from services */
    1364 err_irq:
    13651355        unregister_interrupt_handler(dev, rtl8139->irq);
    13661356err_pio:
     
    21802170int main(void)
    21812171{
     2172        printf("%s: HelenOS RTL8139 network adapter driver\n", NAME);
     2173
    21822174        int rc = nic_driver_init(NAME);
    21832175        if (rc != EOK)
    21842176                return rc;
    2185         nic_driver_implement(
    2186                 &rtl8139_driver_ops, &rtl8139_dev_ops, &rtl8139_nic_iface);
     2177
     2178        nic_driver_implement(&rtl8139_driver_ops, &rtl8139_dev_ops,
     2179            &rtl8139_nic_iface);
    21872180
    21882181        ddf_log_init(NAME);
    2189         ddf_msg(LVL_NOTE, "HelenOS RTL8139 driver started");
    21902182        return ddf_driver_main(&rtl8139_driver);
    21912183}
  • uspace/drv/nic/rtl8169/defs.h

    r96e368a rcbfece7  
    3939#include <sys/types.h>
    4040#include <ddi.h>
     41
     42#define PCI_VID_REALTEK         0x10ec
     43#define PCI_VID_DLINK           0x1186
    4144
    4245/** Size of RTL8169 registers address space */
  • uspace/drv/nic/rtl8169/driver.c

    r96e368a rcbfece7  
    3333#include <align.h>
    3434#include <byteorder.h>
     35#include <irc.h>
    3536#include <libarch/barrier.h>
    3637
     
    388389        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    389390
     391        /* Get PCI VID & PID */
     392        rc = pci_config_space_read_16(ddf_dev_parent_sess_get(dev),
     393            PCI_VENDOR_ID, &rtl8169->pci_vid);
     394        if (rc != EOK)
     395                return rc;
     396
     397        rc = pci_config_space_read_16(ddf_dev_parent_sess_get(dev),
     398            PCI_DEVICE_ID, &rtl8169->pci_pid);
     399        if (rc != EOK)
     400                return rc;
     401
    390402        /* Map register space */
    391403        rc = pio_enable(rtl8169->regs_phys, RTL8169_IO_SIZE, &rtl8169->regs);
     
    418430        uint8_t cr_value = pio_read_8(rtl8169->regs + CR);
    419431        pio_write_8(rtl8169->regs + CR, cr_value | CR_TE | CR_RE);
    420 
    421         rc = nic_connect_to_services(nic_data);
    422         if (rc != EOK) {
    423                 ddf_msg(LVL_ERROR, "Failed to connect to services (%d)", rc);
    424                 goto err_irq;
    425         }
    426432
    427433        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     
    473479        int rc;
    474480
    475         rtl8169_set_hwaddr(rtl8169, addr);
     481        fibril_mutex_lock(&rtl8169->rx_lock);
     482        fibril_mutex_lock(&rtl8169->tx_lock);
    476483
    477484        rc = nic_report_address(nic_data, addr);
     
    479486                return rc;
    480487
     488        rtl8169_set_hwaddr(rtl8169, addr);
     489
     490        fibril_mutex_unlock(&rtl8169->rx_lock);
     491        fibril_mutex_unlock(&rtl8169->tx_lock);
     492
    481493        return EOK;
    482494}
     
    484496static int rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
    485497{
    486 
    487         str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Realtek");
    488         str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8169");
     498        nic_t *nic_data = nic_get_from_ddf_fun(fun);
     499        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     500
     501        str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Unknown");
     502        str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "Unknown");
     503
     504        if (rtl8169->pci_vid == PCI_VID_REALTEK)
     505                str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Realtek");
     506       
     507        if (rtl8169->pci_vid == PCI_VID_DLINK)
     508                str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "D-Link");
     509       
     510        if (rtl8169->pci_pid == 0x8168)
     511                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8168");
     512       
     513        if (rtl8169->pci_pid == 0x8169)
     514                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8169");
     515
     516        if (rtl8169->pci_pid == 0x8110)
     517                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8110");
    489518
    490519        return EOK;
     
    541570        bmcr &= ~(BMCR_DUPLEX | BMCR_SPD_100 | BMCR_SPD_1000);
    542571       
     572        /* Disable autonegotiation */
     573        bmcr &= ~BMCR_AN_ENABLE;
     574
    543575        if (duplex == NIC_CM_FULL_DUPLEX)
    544576                bmcr |= BMCR_DUPLEX;
     
    609641static int rtl8169_autoneg_restart(ddf_fun_t *fun)
    610642{
     643        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     644        uint16_t bmcr = rtl8169_mii_read(rtl8169, MII_BMCR);
     645
     646        bmcr |= BMCR_AN_ENABLE;
     647        rtl8169_mii_write(rtl8169, MII_BMCR, bmcr);
    611648        return EOK;
    612649}
     
    706743
    707744        pio_write_16(rtl8169->regs + IMR, 0xffff);
    708         nic_enable_interrupt(nic_data, rtl8169->irq);
     745        irc_enable_interrupt(rtl8169->irq);
    709746
    710747        return EOK;
     
    888925                }
    889926
     927                /* Receive underrun */
     928                if (isr & INT_RXOVW) {
     929                        /* just ack.. */
     930                        pio_write_16(rtl8169->regs + ISR, INT_RXOVW);
     931                }
     932
    890933                if (isr & INT_SERR) {
    891934                        ddf_msg(LVL_ERROR, "System error interrupt");
  • uspace/drv/nic/rtl8169/driver.h

    r96e368a rcbfece7  
    5555        /** The irq assigned */
    5656        int irq;
     57        /** PCI Vendor and Product ids */
     58        uint16_t pci_vid;
     59        uint16_t pci_pid;
    5760        /** Mask of the turned interupts (IMR value) */
    5861        uint16_t int_mask;
  • uspace/lib/c/Makefile

    r96e368a rcbfece7  
    109109        generic/iplink.c \
    110110        generic/iplink_srv.c \
     111        generic/irc.c \
    111112        generic/ieee_double.c \
    112113        generic/power_of_ten.c \
  • uspace/lib/c/include/ipc/irc.h

    r96e368a rcbfece7  
    3333 */
    3434
    35 #ifndef LIBC_IRC_H_
    36 #define LIBC_IRC_H_
     35#ifndef LIBC_IPC_IRC_H_
     36#define LIBC_IPC_IRC_H_
    3737
    3838#include <ipc/common.h>
  • uspace/lib/drv/include/pci_dev_iface.h

    r96e368a rcbfece7  
    4040#include "ddf/driver.h"
    4141
     42#define PCI_VENDOR_ID  0x00
    4243#define PCI_DEVICE_ID  0x02
    4344
  • uspace/lib/nic/include/nic.h

    r96e368a rcbfece7  
    216216
    217217/* Functions called in add_device */
    218 extern int nic_connect_to_services(nic_t *);
    219218extern int nic_get_resources(nic_t *, hw_res_list_parsed_t *);
    220219extern void nic_set_specific(nic_t *, void *);
     
    245244extern void nic_received_frame(nic_t *, nic_frame_t *);
    246245extern void nic_received_frame_list(nic_t *, nic_frame_list_t *);
    247 extern void nic_disable_interrupt(nic_t *, int);
    248 extern void nic_enable_interrupt(nic_t *, int);
    249246extern nic_poll_mode_t nic_query_poll_mode(nic_t *, struct timeval *);
    250247
  • uspace/lib/nic/include/nic_driver.h

    r96e368a rcbfece7  
    8080        /** Client callback session */
    8181        async_sess_t *client_session;
    82         /** Phone to APIC or i8259 */
    83         async_sess_t *irc_session;
    8482        /** Current polling mode of the NIC */
    8583        nic_poll_mode_t poll_mode;
  • uspace/lib/nic/src/nic_driver.c

    r96e368a rcbfece7  
    4242#include <stdio.h>
    4343#include <str_error.h>
    44 #include <ipc/services.h>
    45 #include <ipc/ns.h>
    46 #include <ipc/irc.h>
    4744#include <sysinfo.h>
    4845#include <as.h>
     
    378375}
    379376
    380 
    381 /**
    382  * Enable interrupts for this driver.
    383  *
    384  * @param nic_data
    385  * @param irq                   The IRQ number for this device
    386  */
    387 void nic_enable_interrupt(nic_t *nic_data, int irq)
    388 {
    389         async_exch_t *exch = async_exchange_begin(nic_data->irc_session);
    390         async_msg_1(exch, IRC_ENABLE_INTERRUPT, irq);
    391         async_exchange_end(exch);
    392 }
    393 
    394 /**
    395  * Disable interrupts for this driver.
    396  *
    397  * @param nic_data
    398  * @param irq                   The IRQ number for this device
    399  */
    400 void nic_disable_interrupt(nic_t *nic_data, int irq)
    401 {
    402         async_exch_t *exch = async_exchange_begin(nic_data->irc_session);
    403         async_msg_1(exch, IRC_CLEAR_INTERRUPT, irq);
    404         async_exchange_end(exch);
    405 }
    406 
    407377/** Get the polling mode information from the device
    408378 *
     
    420390        return nic_data->poll_mode;
    421391};
    422 
    423 /**
    424  * Connect to IRC service. This function should be called only from
    425  * the add_device handler, thus no locking is required.
    426  *
    427  * @param nic_data
    428  *
    429  * @return EOK          If connection was successful.
    430  * @return EINVAL       If the IRC service cannot be determined.
    431  * @return EREFUSED     If IRC service cannot be connected.
    432  */
    433 int nic_connect_to_services(nic_t *nic_data)
    434 {
    435         /* IRC service */
    436         sysarg_t apic;
    437         sysarg_t i8259;
    438         services_t irc_service = -1;
    439         if (((sysinfo_get_value("apic", &apic) == EOK) && (apic)) ||
    440             ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)))
    441                 irc_service = SERVICE_IRC;
    442         else
    443                 return EINVAL;
    444        
    445         nic_data->irc_session = service_connect_blocking(EXCHANGE_SERIALIZE,
    446                 irc_service, 0, 0);
    447         if (nic_data->irc_session == NULL)
    448                 return errno;
    449        
    450         return EOK;
    451 }
    452392
    453393/** Inform the NICF about poll mode
     
    668608        nic_data->state = NIC_STATE_STOPPED;
    669609        nic_data->client_session = NULL;
    670         nic_data->irc_session = NULL;
    671610        nic_data->poll_mode = NIC_POLL_IMMEDIATE;
    672611        nic_data->default_poll_mode = NIC_POLL_IMMEDIATE;
     
    975914nic_t *nic_get_from_ddf_fun(ddf_fun_t *fun)
    976915{
    977         return (nic_t *) ddf_fun_data_get(fun);
     916        return (nic_t *) ddf_dev_data_get(ddf_fun_get_dev(fun));
    978917}
    979918
  • uspace/srv/net/ethip/arp.c

    r96e368a rcbfece7  
    119119                return rc;
    120120       
    121         (void) atrans_wait_timeout(ARP_REQUEST_TIMEOUT);
    122        
    123         return atrans_lookup(ip_addr, mac_addr);
     121        return atrans_lookup_timeout(ip_addr, ARP_REQUEST_TIMEOUT, mac_addr);
    124122}
    125123
  • uspace/srv/net/ethip/atrans.c

    r96e368a rcbfece7  
    103103}
    104104
    105 int atrans_lookup(addr32_t ip_addr, addr48_t mac_addr)
     105static int atrans_lookup_locked(addr32_t ip_addr, addr48_t mac_addr)
    106106{
    107         fibril_mutex_lock(&atrans_list_lock);
    108107        ethip_atrans_t *atrans = atrans_find(ip_addr);
    109         if (atrans == NULL) {
    110                 fibril_mutex_unlock(&atrans_list_lock);
     108        if (atrans == NULL)
    111109                return ENOENT;
    112         }
    113        
    114         fibril_mutex_unlock(&atrans_list_lock);
     110
    115111        addr48(atrans->mac_addr, mac_addr);
    116112        return EOK;
    117113}
    118114
    119 int atrans_wait_timeout(suseconds_t timeout)
     115int atrans_lookup(addr32_t ip_addr, addr48_t mac_addr)
    120116{
     117        int rc;
     118
    121119        fibril_mutex_lock(&atrans_list_lock);
    122         int rc = fibril_condvar_wait_timeout(&atrans_cv, &atrans_list_lock,
    123             timeout);
     120        rc = atrans_lookup_locked(ip_addr, mac_addr);
    124121        fibril_mutex_unlock(&atrans_list_lock);
    125        
     122
     123        return rc;
     124}
     125
     126static void atrans_lookup_timeout_handler(void *arg)
     127{
     128        bool *timedout = (bool *)arg;
     129
     130        fibril_mutex_lock(&atrans_list_lock);
     131        *timedout = true;
     132        fibril_mutex_unlock(&atrans_list_lock);
     133        fibril_condvar_broadcast(&atrans_cv);
     134}
     135
     136int atrans_lookup_timeout(addr32_t ip_addr, suseconds_t timeout,
     137    addr48_t mac_addr)
     138{
     139        fibril_timer_t *t;
     140        bool timedout;
     141        int rc;
     142
     143        t = fibril_timer_create(NULL);
     144        if (t == NULL)
     145                return ENOMEM;
     146
     147        timedout = false;
     148        fibril_timer_set(t, timeout, atrans_lookup_timeout_handler, &timedout);
     149
     150        fibril_mutex_lock(&atrans_list_lock);
     151
     152        while ((rc = atrans_lookup_locked(ip_addr, mac_addr)) == ENOENT &&
     153            !timedout) {
     154                fibril_condvar_wait(&atrans_cv, &atrans_list_lock);
     155        }
     156
     157        fibril_mutex_unlock(&atrans_list_lock);
     158        (void) fibril_timer_clear(t);
     159        fibril_timer_destroy(t);
     160
    126161        return rc;
    127162}
  • uspace/srv/net/ethip/atrans.h

    r96e368a rcbfece7  
    4545extern int atrans_remove(addr32_t);
    4646extern int atrans_lookup(addr32_t, addr48_t);
    47 extern int atrans_wait_timeout(suseconds_t);
     47extern int atrans_lookup_timeout(addr32_t, suseconds_t, addr48_t);
    4848
    4949#endif
  • uspace/srv/net/inetsrv/inet_link.c

    r96e368a rcbfece7  
    465465        list_foreach(inet_links, link_list, inet_link_t, ilink) {
    466466                id_list[i++] = ilink->svc_id;
    467                 log_msg(LOG_DEFAULT, LVL_NOTE, "add link to list");
    468467        }
    469468
    470469        fibril_mutex_unlock(&inet_links_lock);
    471470
    472         log_msg(LOG_DEFAULT, LVL_NOTE, "return %zu links", count);
    473471        *rid_list = id_list;
    474472        *rcount = count;
  • uspace/srv/net/inetsrv/pdu.c

    r96e368a rcbfece7  
    106106{
    107107        /* Upper bound for fragment offset field */
    108         size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l);
     108        size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l + 1);
    109109       
    110110        /* Verify that total size of datagram is within reasonable bounds */
    111         if (offs + packet->size > FRAG_OFFS_UNIT * fragoff_limit)
     111        if (packet->size > FRAG_OFFS_UNIT * fragoff_limit)
    112112                return ELIMIT;
    113113       
  • uspace/srv/net/inetsrv/reass.c

    r96e368a rcbfece7  
    196196                return ENOMEM;
    197197
     198        memcpy(data_copy, packet->data, packet->size);
     199
    198200        frag->packet = *packet;
    199201        frag->packet.data = data_copy;
     
    216218                        break;
    217219
    218                 link = link->next;
     220                link = list_next(link, &rdg->frags);
    219221        }
    220222
     
    240242        assert(!list_empty(&rdg->frags));
    241243
     244        link = list_first(&rdg->frags);
     245        assert(link != NULL);
     246
     247        frag = list_get_instance(link, reass_frag_t,
     248            dgram_link);
     249
    242250        /* First fragment must be at offset zero */
    243         frag = list_get_instance(list_first(&rdg->frags), reass_frag_t,
    244             dgram_link);
    245251        if (frag->packet.offs != 0)
    246252                return false;
    247253
    248254        prev = frag;
     255
    249256        while (true) {
    250                 link = frag->dgram_link.next;
     257                link = list_next(link, &rdg->frags);
    251258                if (link == NULL)
    252                         return false;
     259                        break;
    253260
    254261                /* Each next fragment must follow immediately or overlap */
     
    288295        uint8_t proto;
    289296        reass_frag_t *frag;
     297        int rc;
    290298
    291299        /*
     
    307315
    308316        /* Upper bound for fragment offset field */
    309         fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l);
     317        fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l + 1);
    310318
    311319        /* Verify that total size of datagram is within reasonable bounds */
     
    343351        }
    344352
    345         return inet_recv_dgram_local(&dgram, proto);
     353        rc = inet_recv_dgram_local(&dgram, proto);
     354        free(dgram.data);
     355        return rc;
    346356}
    347357
  • uspace/srv/net/tcp/tqueue.c

    r96e368a rcbfece7  
    5959static void tcp_tqueue_timer_clear(tcp_conn_t *conn);
    6060
    61 #include <stdio.h>
    6261int tcp_tqueue_init(tcp_tqueue_t *tqueue, tcp_conn_t *conn)
    6362{
    64         printf("tcp_tqueue_init\n");
    6563        tqueue->conn = conn;
    6664        tqueue->timer = fibril_timer_create(&conn->lock);
     
    8078void tcp_tqueue_fini(tcp_tqueue_t *tqueue)
    8179{
    82         printf("tcp_tqueue_fini\n");
    8380        if (tqueue->timer != NULL) {
    8481                fibril_timer_destroy(tqueue->timer);
  • uspace/srv/net/udp/assoc.c

    r96e368a rcbfece7  
    275275
    276276        rc = udp_transmit_pdu(pdu);
     277        udp_pdu_delete(pdu);
     278
    277279        if (rc != EOK)
    278280                return EIO;
    279 
    280         udp_pdu_delete(pdu);
    281281
    282282        return EOK;
     
    335335                /* XXX Generate ICMP error. */
    336336                /* XXX Might propagate error directly by error return. */
     337                udp_msg_delete(msg);
    337338                return;
    338339        }
  • uspace/srv/net/udp/udp_type.h

    r96e368a rcbfece7  
    4343#include <inet/addr.h>
    4444
    45 #define UDP_FRAGMENT_SIZE 4096
    46 
     45#define UDP_FRAGMENT_SIZE 65535
    4746
    4847typedef enum {
Note: See TracChangeset for help on using the changeset viewer.