Changeset b01995b in mainline


Ignore:
Timestamp:
2011-03-21T23:42:08Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
11dd29b, 62f4212
Parents:
31b568e (diff), 87644b4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Fixes selecting a new USB address when max address has been reached.

Whitespace and code-style fixes, renames

Location:
uspace
Files:
12 edited
8 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/iface.c

    r31b568e rb01995b  
    3333 */
    3434#include <ddf/driver.h>
    35 #include <ddf/interrupt.h>
    36 #include <device/hw_res.h>
    3735#include <errno.h>
    38 #include <str_error.h>
    39 
    40 #include <usb_iface.h>
    41 #include <usb/ddfiface.h>
     36
    4237#include <usb/debug.h>
    4338
     
    6055static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
    6156{
    62   assert(fun);
    63   hc_t *hc = fun_to_hc(fun);
    64   assert(hc);
    65   usb_log_debug("Default address request with speed %d.\n", speed);
    66   usb_device_keeper_reserve_default_address(&hc->manager, speed);
    67   return EOK;
     57        assert(fun);
     58        hc_t *hc = fun_to_hc(fun);
     59        assert(hc);
     60        usb_log_debug("Default address request with speed %d.\n", speed);
     61        usb_device_keeper_reserve_default_address(&hc->manager, speed);
     62        return EOK;
    6863}
    6964/*----------------------------------------------------------------------------*/
     
    7570static int release_default_address(ddf_fun_t *fun)
    7671{
    77   assert(fun);
    78   hc_t *hc = fun_to_hc(fun);
    79   assert(hc);
    80   usb_log_debug("Default address release.\n");
    81   usb_device_keeper_release_default_address(&hc->manager);
    82   return EOK;
     72        assert(fun);
     73        hc_t *hc = fun_to_hc(fun);
     74        assert(hc);
     75        usb_log_debug("Default address release.\n");
     76        usb_device_keeper_release_default_address(&hc->manager);
     77        return EOK;
    8378}
    8479/*----------------------------------------------------------------------------*/
     
    9085 * @return Error code.
    9186 */
    92 static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    93     usb_address_t *address)
    94 {
    95   assert(fun);
    96   hc_t *hc = fun_to_hc(fun);
    97   assert(hc);
    98   assert(address);
    99 
    100   usb_log_debug("Address request with speed %d.\n", speed);
    101   *address = device_keeper_get_free_address(&hc->manager, speed);
    102   usb_log_debug("Address request with result: %d.\n", *address);
    103   if (*address <= 0)
    104     return *address;
    105   return EOK;
     87static int request_address(
     88    ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
     89{
     90        assert(fun);
     91        hc_t *hc = fun_to_hc(fun);
     92        assert(hc);
     93        assert(address);
     94
     95        usb_log_debug("Address request with speed %d.\n", speed);
     96        *address = device_keeper_get_free_address(&hc->manager, speed);
     97        usb_log_debug("Address request with result: %d.\n", *address);
     98        if (*address <= 0)
     99                return *address;
     100        return EOK;
    106101}
    107102/*----------------------------------------------------------------------------*/
     
    113108 * @return Error code.
    114109 */
    115 static int bind_address(ddf_fun_t *fun,
    116     usb_address_t address, devman_handle_t handle)
    117 {
    118   assert(fun);
    119   hc_t *hc = fun_to_hc(fun);
    120   assert(hc);
    121   usb_log_debug("Address bind %d-%d.\n", address, handle);
    122   usb_device_keeper_bind(&hc->manager, address, handle);
    123   return EOK;
     110static int bind_address(
     111    ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
     112{
     113        assert(fun);
     114        hc_t *hc = fun_to_hc(fun);
     115        assert(hc);
     116        usb_log_debug("Address bind %d-%d.\n", address, handle);
     117        usb_device_keeper_bind(&hc->manager, address, handle);
     118        return EOK;
    124119}
    125120/*----------------------------------------------------------------------------*/
     
    132127static int release_address(ddf_fun_t *fun, usb_address_t address)
    133128{
    134   assert(fun);
    135   hc_t *hc = fun_to_hc(fun);
    136   assert(hc);
    137   usb_log_debug("Address release %d.\n", address);
    138   usb_device_keeper_release(&hc->manager, address);
    139   return EOK;
    140 }
    141 
     129        assert(fun);
     130        hc_t *hc = fun_to_hc(fun);
     131        assert(hc);
     132        usb_log_debug("Address release %d.\n", address);
     133        usb_device_keeper_release(&hc->manager, address);
     134        return EOK;
     135}
     136/*----------------------------------------------------------------------------*/
    142137/** Register endpoint for bandwidth reservation.
    143138 *
     
    151146 * @return Error code.
    152147 */
    153 static int register_endpoint(ddf_fun_t *fun,
    154     usb_address_t address, usb_endpoint_t endpoint,
     148static int register_endpoint(
     149    ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
    155150    usb_transfer_type_t transfer_type, usb_direction_t direction,
    156151    size_t max_packet_size, unsigned int interval)
     
    160155        return ENOTSUP;
    161156}
    162 
     157/*----------------------------------------------------------------------------*/
    163158/** Unregister endpoint (free some bandwidth reservation).
    164159 *
     
    169164 * @return Error code.
    170165 */
    171 static int unregister_endpoint(ddf_fun_t *fun, usb_address_t address,
     166static int unregister_endpoint(
     167    ddf_fun_t *fun, usb_address_t address,
    172168    usb_endpoint_t endpoint, usb_direction_t direction)
    173169{
     
    194190 * @return Error code.
    195191 */
    196 static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    197     size_t max_packet_size, void *data, size_t size,
    198     usbhc_iface_transfer_out_callback_t callback, void *arg)
    199 {
    200   hc_t *hc = fun_to_hc(fun);
    201   assert(hc);
    202   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    203 
    204   usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    205       target.address, target.endpoint, size, max_packet_size);
    206 
    207   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    208       max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    209       &hc->manager);
    210   if (!batch)
    211     return ENOMEM;
    212   batch_interrupt_out(batch);
    213   const int ret = hc_schedule(hc, batch);
    214   if (ret != EOK) {
    215     batch_dispose(batch);
    216     return ret;
    217   }
    218   return EOK;
     192static int interrupt_out(
     193    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     194    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     195{
     196        assert(fun);
     197        hc_t *hc = fun_to_hc(fun);
     198        assert(hc);
     199        usb_speed_t speed =
     200            usb_device_keeper_get_speed(&hc->manager, target.address);
     201
     202        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
     203            target.address, target.endpoint, size, max_packet_size);
     204
     205        usb_transfer_batch_t *batch =
     206            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     207                speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     208        if (!batch)
     209                return ENOMEM;
     210        batch_interrupt_out(batch);
     211        const int ret = hc_schedule(hc, batch);
     212        if (ret != EOK) {
     213                batch_dispose(batch);
     214        }
     215        return ret;
    219216}
    220217/*----------------------------------------------------------------------------*/
     
    236233 * @return Error code.
    237234 */
    238 static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    239     size_t max_packet_size, void *data, size_t size,
    240     usbhc_iface_transfer_in_callback_t callback, void *arg)
    241 {
    242   assert(fun);
    243   hc_t *hc = fun_to_hc(fun);
    244   assert(hc);
    245   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    246   usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    247       target.address, target.endpoint, size, max_packet_size);
    248 
    249   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    250       max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    251       &hc->manager);
    252   if (!batch)
    253     return ENOMEM;
    254   batch_interrupt_in(batch);
    255   const int ret = hc_schedule(hc, batch);
    256   if (ret != EOK) {
    257     batch_dispose(batch);
    258     return ret;
    259   }
    260   return EOK;
     235static int interrupt_in(
     236    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     237    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     238{
     239        assert(fun);
     240        hc_t *hc = fun_to_hc(fun);
     241        assert(hc);
     242        usb_speed_t speed =
     243            usb_device_keeper_get_speed(&hc->manager, target.address);
     244        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
     245            target.address, target.endpoint, size, max_packet_size);
     246
     247        usb_transfer_batch_t *batch =
     248            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     249                speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     250        if (!batch)
     251                return ENOMEM;
     252        batch_interrupt_in(batch);
     253        const int ret = hc_schedule(hc, batch);
     254        if (ret != EOK) {
     255                batch_dispose(batch);
     256        }
     257        return ret;
    261258}
    262259/*----------------------------------------------------------------------------*/
     
    278275 * @return Error code.
    279276 */
    280 static int bulk_out(ddf_fun_t *fun, usb_target_t target,
    281     size_t max_packet_size, void *data, size_t size,
    282     usbhc_iface_transfer_out_callback_t callback, void *arg)
    283 {
    284   assert(fun);
    285   hc_t *hc = fun_to_hc(fun);
    286   assert(hc);
    287   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    288 
    289   usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    290       target.address, target.endpoint, size, max_packet_size);
    291 
    292   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    293       max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    294       &hc->manager);
    295   if (!batch)
    296     return ENOMEM;
    297   batch_bulk_out(batch);
    298   const int ret = hc_schedule(hc, batch);
    299   if (ret != EOK) {
    300     batch_dispose(batch);
    301     return ret;
    302   }
    303   return EOK;
    304 
     277static int bulk_out(
     278    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     279    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     280{
     281        assert(fun);
     282        hc_t *hc = fun_to_hc(fun);
     283        assert(hc);
     284        usb_speed_t speed =
     285            usb_device_keeper_get_speed(&hc->manager, target.address);
     286
     287        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
     288            target.address, target.endpoint, size, max_packet_size);
     289
     290        usb_transfer_batch_t *batch =
     291            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     292                data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     293        if (!batch)
     294                return ENOMEM;
     295        batch_bulk_out(batch);
     296        const int ret = hc_schedule(hc, batch);
     297        if (ret != EOK) {
     298                batch_dispose(batch);
     299        }
     300        return ret;
    305301}
    306302/*----------------------------------------------------------------------------*/
     
    322318 * @return Error code.
    323319 */
    324 static int bulk_in(ddf_fun_t *fun, usb_target_t target,
    325     size_t max_packet_size, void *data, size_t size,
    326     usbhc_iface_transfer_in_callback_t callback, void *arg)
    327 {
    328   assert(fun);
    329   hc_t *hc = fun_to_hc(fun);
    330   assert(hc);
    331   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    332   usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    333       target.address, target.endpoint, size, max_packet_size);
    334 
    335   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    336       max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    337       &hc->manager);
    338   if (!batch)
    339     return ENOMEM;
    340   batch_bulk_in(batch);
    341   const int ret = hc_schedule(hc, batch);
    342   if (ret != EOK) {
    343     batch_dispose(batch);
    344     return ret;
    345   }
    346   return EOK;
     320static int bulk_in(
     321    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     322    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     323{
     324        assert(fun);
     325        hc_t *hc = fun_to_hc(fun);
     326        assert(hc);
     327        usb_speed_t speed =
     328            usb_device_keeper_get_speed(&hc->manager, target.address);
     329        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
     330            target.address, target.endpoint, size, max_packet_size);
     331
     332        usb_transfer_batch_t *batch =
     333            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     334                data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     335        if (!batch)
     336                return ENOMEM;
     337        batch_bulk_in(batch);
     338        const int ret = hc_schedule(hc, batch);
     339        if (ret != EOK) {
     340                batch_dispose(batch);
     341        }
     342        return ret;
    347343}
    348344/*----------------------------------------------------------------------------*/
     
    367363 * @return Error code.
    368364 */
    369 static int control_write(ddf_fun_t *fun, usb_target_t target,
    370     size_t max_packet_size,
    371     void *setup_data, size_t setup_size,
    372     void *data, size_t size,
     365static int control_write(
     366    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
     367    void *setup_data, size_t setup_size, void *data, size_t size,
    373368    usbhc_iface_transfer_out_callback_t callback, void *arg)
    374369{
    375   assert(fun);
    376   hc_t *hc = fun_to_hc(fun);
    377   assert(hc);
    378   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    379   usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    380       speed, target.address, target.endpoint, size, max_packet_size);
    381 
    382   if (setup_size != 8)
    383     return EINVAL;
    384 
    385   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    386       max_packet_size, speed, data, size, setup_data, setup_size,
    387       NULL, callback, arg, &hc->manager);
    388   if (!batch)
    389     return ENOMEM;
    390   usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
    391   batch_control_write(batch);
    392   const int ret = hc_schedule(hc, batch);
    393   if (ret != EOK) {
    394     batch_dispose(batch);
    395     return ret;
    396   }
    397   return EOK;
     370        assert(fun);
     371        hc_t *hc = fun_to_hc(fun);
     372        assert(hc);
     373        usb_speed_t speed =
     374            usb_device_keeper_get_speed(&hc->manager, target.address);
     375        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
     376            speed, target.address, target.endpoint, size, max_packet_size);
     377
     378        if (setup_size != 8)
     379                return EINVAL;
     380
     381        usb_transfer_batch_t *batch =
     382            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size,
     383                speed, data, size, setup_data, setup_size, NULL, callback, arg,
     384                &hc->manager);
     385        if (!batch)
     386                return ENOMEM;
     387        usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
     388        batch_control_write(batch);
     389        const int ret = hc_schedule(hc, batch);
     390        if (ret != EOK) {
     391                batch_dispose(batch);
     392        }
     393        return ret;
    398394}
    399395/*----------------------------------------------------------------------------*/
     
    418414 * @return Error code.
    419415 */
    420 static int control_read(ddf_fun_t *fun, usb_target_t target,
    421     size_t max_packet_size,
    422     void *setup_data, size_t setup_size,
    423     void *data, size_t size,
     416static int control_read(
     417    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
     418    void *setup_data, size_t setup_size, void *data, size_t size,
    424419    usbhc_iface_transfer_in_callback_t callback, void *arg)
    425420{
    426   assert(fun);
    427   hc_t *hc = fun_to_hc(fun);
    428   assert(hc);
    429   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    430 
    431   usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    432       speed, target.address, target.endpoint, size, max_packet_size);
    433   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    434       max_packet_size, speed, data, size, setup_data, setup_size, callback,
    435       NULL, arg, &hc->manager);
    436   if (!batch)
    437     return ENOMEM;
    438   batch_control_read(batch);
    439   const int ret = hc_schedule(hc, batch);
    440   if (ret != EOK) {
    441     batch_dispose(batch);
    442     return ret;
    443   }
    444   return EOK;
     421        assert(fun);
     422        hc_t *hc = fun_to_hc(fun);
     423        assert(hc);
     424        usb_speed_t speed =
     425            usb_device_keeper_get_speed(&hc->manager, target.address);
     426
     427        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
     428            speed, target.address, target.endpoint, size, max_packet_size);
     429        usb_transfer_batch_t *batch =
     430            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size,
     431                speed, data, size, setup_data, setup_size, callback, NULL, arg,
     432                &hc->manager);
     433        if (!batch)
     434                return ENOMEM;
     435        batch_control_read(batch);
     436        const int ret = hc_schedule(hc, batch);
     437        if (ret != EOK) {
     438                batch_dispose(batch);
     439        }
     440        return ret;
    445441}
    446442/*----------------------------------------------------------------------------*/
     
    463459
    464460        .control_write = control_write,
    465         .control_read = control_read
     461        .control_read = control_read,
    466462};
    467463
  • uspace/drv/uhci-hcd/Makefile

    r31b568e rb01995b  
    3737        transfer_list.c \
    3838        uhci.c \
    39         uhci_hc.c \
    40         uhci_rh.c \
    41         uhci_struct/transfer_descriptor.c \
     39        hc.c \
     40        root_hub.c \
     41        hw_struct/transfer_descriptor.c \
    4242        pci.c \
    4343        batch.c
  • uspace/drv/uhci-hcd/batch.c

    r31b568e rb01995b  
    4040#include "batch.h"
    4141#include "transfer_list.h"
    42 #include "uhci_hc.h"
     42#include "hw_struct/transfer_descriptor.h"
    4343#include "utils/malloc32.h"
    44 #include "uhci_struct/transfer_descriptor.h"
    4544
    4645#define DEFAULT_ERROR_COUNT 3
  • uspace/drv/uhci-hcd/batch.h

    r31b568e rb01995b  
    4242#include <usb/host/batch.h>
    4343
    44 #include "uhci_struct/queue_head.h"
     44#include "hw_struct/queue_head.h"
    4545
    4646usb_transfer_batch_t * batch_get(
  • uspace/drv/uhci-hcd/hc.c

    r31b568e rb01995b  
    4242#include <usb_iface.h>
    4343
    44 #include "uhci_hc.h"
     44#include "hc.h"
    4545
    4646static irq_cmd_t uhci_cmds[] = {
     
    6060};
    6161/*----------------------------------------------------------------------------*/
    62 static int uhci_hc_init_transfer_lists(uhci_hc_t *instance);
    63 static int uhci_hc_init_mem_structures(uhci_hc_t *instance);
    64 static void uhci_hc_init_hw(uhci_hc_t *instance);
    65 
    66 static int uhci_hc_interrupt_emulator(void *arg);
    67 static int uhci_hc_debug_checker(void *arg);
     62static int hc_init_transfer_lists(hc_t *instance);
     63static int hc_init_mem_structures(hc_t *instance);
     64static void hc_init_hw(hc_t *instance);
     65
     66static int hc_interrupt_emulator(void *arg);
     67static int hc_debug_checker(void *arg);
    6868
    6969static bool allowed_usb_packet(
     
    8282 * interrupt fibrils.
    8383 */
    84 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,
     84int hc_init(hc_t *instance, ddf_fun_t *fun,
    8585    void *regs, size_t reg_size, bool interrupts)
    8686{
     
    112112            io, reg_size);
    113113
    114         ret = uhci_hc_init_mem_structures(instance);
     114        ret = hc_init_mem_structures(instance);
    115115        CHECK_RET_DEST_FUN_RETURN(ret,
    116116            "Failed to initialize UHCI memory structures.\n");
    117117
    118         uhci_hc_init_hw(instance);
     118        hc_init_hw(instance);
    119119        if (!interrupts) {
    120120                instance->cleaner =
    121                     fibril_create(uhci_hc_interrupt_emulator, instance);
     121                    fibril_create(hc_interrupt_emulator, instance);
    122122                fibril_add_ready(instance->cleaner);
    123123        } else {
     
    125125        }
    126126
    127         instance->debug_checker = fibril_create(uhci_hc_debug_checker, instance);
    128         fibril_add_ready(instance->debug_checker);
     127        instance->debug_checker =
     128            fibril_create(hc_debug_checker, instance);
     129//      fibril_add_ready(instance->debug_checker);
    129130
    130131        return EOK;
     
    137138 * For magic values see UHCI Design Guide
    138139 */
    139 void uhci_hc_init_hw(uhci_hc_t *instance)
     140void hc_init_hw(hc_t *instance)
    140141{
    141142        assert(instance);
     
    185186 *  - frame list page (needs to be one UHCI hw accessible 4K page)
    186187 */
    187 int uhci_hc_init_mem_structures(uhci_hc_t *instance)
     188int hc_init_mem_structures(hc_t *instance)
    188189{
    189190        assert(instance);
     
    214215
    215216        /* Init transfer lists */
    216         ret = uhci_hc_init_transfer_lists(instance);
     217        ret = hc_init_transfer_lists(instance);
    217218        CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n");
    218219        usb_log_debug("Initialized transfer lists.\n");
     
    235236
    236237        /* Init device keeper*/
    237         usb_device_keeper_init(&instance->device_manager);
     238        usb_device_keeper_init(&instance->manager);
    238239        usb_log_debug("Initialized device manager.\n");
    239240
     
    251252 * USB scheduling. Sets pointer table for quick access.
    252253 */
    253 int uhci_hc_init_transfer_lists(uhci_hc_t *instance)
     254int hc_init_transfer_lists(hc_t *instance)
    254255{
    255256        assert(instance);
     
    317318 * Checks for bandwidth availability and appends the batch to the proper queue.
    318319 */
    319 int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch)
     320int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch)
    320321{
    321322        assert(instance);
     
    350351 * - resume from suspend state (not implemented)
    351352 */
    352 void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status)
     353void hc_interrupt(hc_t *instance, uint16_t status)
    353354{
    354355        assert(instance);
     
    372373                if (instance->hw_failures < UHCI_ALLOWED_HW_FAIL) {
    373374                        /* reinitialize hw, this triggers virtual disconnect*/
    374                         uhci_hc_init_hw(instance);
     375                        hc_init_hw(instance);
    375376                } else {
    376377                        usb_log_fatal("Too many UHCI hardware failures!.\n");
    377                         uhci_hc_fini(instance);
     378                        hc_fini(instance);
    378379                }
    379380        }
     
    385386 * @return EOK (should never return)
    386387 */
    387 int uhci_hc_interrupt_emulator(void* arg)
     388int hc_interrupt_emulator(void* arg)
    388389{
    389390        usb_log_debug("Started interrupt emulator.\n");
    390         uhci_hc_t *instance = (uhci_hc_t*)arg;
     391        hc_t *instance = (hc_t*)arg;
    391392        assert(instance);
    392393
     
    397398                if (status != 0)
    398399                        usb_log_debug2("UHCI status: %x.\n", status);
    399                 uhci_hc_interrupt(instance, status);
     400                hc_interrupt(instance, status);
    400401                async_usleep(UHCI_CLEANER_TIMEOUT);
    401402        }
     
    408409 * @return EOK (should never return)
    409410 */
    410 int uhci_hc_debug_checker(void *arg)
    411 {
    412         uhci_hc_t *instance = (uhci_hc_t*)arg;
     411int hc_debug_checker(void *arg)
     412{
     413        hc_t *instance = (hc_t*)arg;
    413414        assert(instance);
    414415
  • uspace/drv/uhci-hcd/hc.h

    r31b568e rb01995b  
    8282#define UHCI_ALLOWED_HW_FAIL 5
    8383
    84 typedef struct uhci_hc {
    85         usb_device_keeper_t device_manager;
     84typedef struct hc {
     85        usb_device_keeper_t manager;
    8686
    8787        regs_t *registers;
     
    104104
    105105        ddf_fun_t *ddf_instance;
    106 } uhci_hc_t;
     106} hc_t;
    107107
    108 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,
     108int hc_init(hc_t *instance, ddf_fun_t *fun,
    109109    void *regs, size_t reg_size, bool interupts);
    110110
    111 int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch);
     111int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch);
    112112
    113 void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);
     113void hc_interrupt(hc_t *instance, uint16_t status);
    114114
    115115/** Safely dispose host controller internal structures
     
    117117 * @param[in] instance Host controller structure to use.
    118118 */
    119 static inline void uhci_hc_fini(uhci_hc_t *instance) { /* TODO: implement*/ };
     119static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ };
    120120
    121121/** Get and cast pointer to the driver data
     
    124124 * @return cast pointer to driver_data
    125125 */
    126 static inline uhci_hc_t * fun_to_uhci_hc(ddf_fun_t *fun)
    127         { return (uhci_hc_t*)fun->driver_data; }
     126static inline hc_t * fun_to_hc(ddf_fun_t *fun)
     127        { return (hc_t*)fun->driver_data; }
    128128#endif
    129129/**
  • uspace/drv/uhci-hcd/hw_struct/link_pointer.h

    r31b568e rb01995b  
    4949        ((address & LINK_POINTER_ADDRESS_MASK) | LINK_POINTER_QUEUE_HEAD_FLAG)
    5050
     51#define LINK_POINTER_TD(address) \
     52        (address & LINK_POINTER_ADDRESS_MASK)
     53
     54#define LINK_POINTER_TERM \
     55        ((link_pointer_t)LINK_POINTER_TERMINATE_FLAG)
     56
    5157#endif
    5258/**
  • uspace/drv/uhci-hcd/hw_struct/queue_head.h

    r31b568e rb01995b  
    7272        /* Address is valid and not terminal */
    7373        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    74                 instance->next = (pa & LINK_POINTER_ADDRESS_MASK)
    75                     | LINK_POINTER_QUEUE_HEAD_FLAG;
     74                instance->next = LINK_POINTER_QH(pa);
    7675        } else {
    77                 instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;
     76                instance->next = LINK_POINTER_TERM;
    7877        }
    7978}
     
    9190        /* Address is valid and not terminal */
    9291        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    93                 instance->element = (pa & LINK_POINTER_ADDRESS_MASK)
    94                     | LINK_POINTER_QUEUE_HEAD_FLAG;
     92                instance->element = LINK_POINTER_QH(pa);
    9593        } else {
    96                 instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
     94                instance->element = LINK_POINTER_TERM;
    9795        }
    9896}
     
    109107{
    110108        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    111                 instance->element = (pa & LINK_POINTER_ADDRESS_MASK);
     109                instance->element = LINK_POINTER_TD(pa);
    112110        } else {
    113                 instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
     111                instance->element = LINK_POINTER_TERM;
    114112        }
    115113}
  • uspace/drv/uhci-hcd/hw_struct/transfer_descriptor.c

    r31b568e rb01995b  
    6969            || (pid == USB_PID_OUT));
    7070
     71        const uint32_t next_pa = addr_to_phys(next);
     72        assert((next_pa & LINK_POINTER_ADDRESS_MASK) == next_pa);
     73
    7174        instance->next = 0
    7275            | LINK_POINTER_VERTICAL_FLAG
    73             | ((next != NULL) ? addr_to_phys(next) : LINK_POINTER_TERMINATE_FLAG);
     76            | (next_pa ? next_pa : LINK_POINTER_TERMINATE_FLAG);
    7477
    7578        instance->status = 0
     
    9093            | ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS);
    9194
    92         instance->buffer_ptr = 0;
    93 
    94         if (size) {
    95                 instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer);
    96         }
     95        instance->buffer_ptr = addr_to_phys(buffer);
    9796
    9897        usb_log_debug2("Created TD(%p): %X:%X:%X:%X(%p).\n",
     
    115114        assert(instance);
    116115
    117         if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
    118                 return ESTALL;
     116        /* this is hc internal error it should never be reported */
     117        if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0)
     118                return EAGAIN;
    119119
     120        /* CRC or timeout error, like device not present or bad data,
     121         * it won't be reported unless err count reached zero */
    120122        if ((instance->status & TD_STATUS_ERROR_CRC) != 0)
    121123                return EBADCHECKSUM;
    122124
    123         if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
     125        /* hc does not end transaction on these, it should never be reported */
     126        if ((instance->status & TD_STATUS_ERROR_NAK) != 0)
    124127                return EAGAIN;
    125128
     129        /* buffer overrun or underrun */
     130        if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
     131                return ERANGE;
     132
     133        /* device babble is something serious */
    126134        if ((instance->status & TD_STATUS_ERROR_BABBLE) != 0)
    127135                return EIO;
    128136
    129         if ((instance->status & TD_STATUS_ERROR_NAK) != 0)
    130                 return EAGAIN;
    131 
    132         if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0)
    133                 return EAGAIN;
     137        /* stall might represent err count reaching zero or stall response from
     138         * the device, is err count reached zero, one of the above is reported*/
     139        if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
     140                return ESTALL;
    134141
    135142        return EOK;
  • uspace/drv/uhci-hcd/iface.c

    r31b568e rb01995b  
    3333 */
    3434#include <ddf/driver.h>
    35 #include <remote_usbhc.h>
     35#include <errno.h>
    3636
    3737#include <usb/debug.h>
    3838
    39 #include <errno.h>
    40 
    4139#include "iface.h"
    42 #include "uhci_hc.h"
     40#include "hc.h"
    4341
    4442/** Reserve default address interface function
     
    4846 * @return Error code.
    4947 */
    50 /*----------------------------------------------------------------------------*/
    5148static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
    5249{
    5350        assert(fun);
    54         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     51        hc_t *hc = fun_to_hc(fun);
    5552        assert(hc);
    5653        usb_log_debug("Default address request with speed %d.\n", speed);
    57         usb_device_keeper_reserve_default_address(&hc->device_manager, speed);
     54        usb_device_keeper_reserve_default_address(&hc->manager, speed);
    5855        return EOK;
    5956}
     
    6764{
    6865        assert(fun);
    69         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     66        hc_t *hc = fun_to_hc(fun);
    7067        assert(hc);
    7168        usb_log_debug("Default address release.\n");
    72         usb_device_keeper_release_default_address(&hc->device_manager);
     69        usb_device_keeper_release_default_address(&hc->manager);
    7370        return EOK;
    7471}
     
    8178 * @return Error code.
    8279 */
    83 static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    84     usb_address_t *address)
    85 {
    86         assert(fun);
    87         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     80static int request_address(
     81    ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
     82{
     83        assert(fun);
     84        hc_t *hc = fun_to_hc(fun);
    8885        assert(hc);
    8986        assert(address);
    9087
    9188        usb_log_debug("Address request with speed %d.\n", speed);
    92         *address = device_keeper_get_free_address(&hc->device_manager, speed);
     89        *address = device_keeper_get_free_address(&hc->manager, speed);
    9390        usb_log_debug("Address request with result: %d.\n", *address);
    9491        if (*address <= 0)
    95           return *address;
     92                return *address;
    9693        return EOK;
    9794}
     
    108105{
    109106        assert(fun);
    110         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     107        hc_t *hc = fun_to_hc(fun);
    111108        assert(hc);
    112109        usb_log_debug("Address bind %d-%d.\n", address, handle);
    113         usb_device_keeper_bind(&hc->device_manager, address, handle);
     110        usb_device_keeper_bind(&hc->manager, address, handle);
    114111        return EOK;
    115112}
     
    124121{
    125122        assert(fun);
    126         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     123        hc_t *hc = fun_to_hc(fun);
    127124        assert(hc);
    128125        usb_log_debug("Address release %d.\n", address);
    129         usb_device_keeper_release(&hc->device_manager, address);
     126        usb_device_keeper_release(&hc->manager, address);
    130127        return EOK;
    131128}
     
    142139 * @return Error code.
    143140 */
    144 static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    145     size_t max_packet_size, void *data, size_t size,
    146     usbhc_iface_transfer_out_callback_t callback, void *arg)
    147 {
    148         assert(fun);
    149         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    150         assert(hc);
    151         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     141static int interrupt_out(
     142    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     143    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     144{
     145        assert(fun);
     146        hc_t *hc = fun_to_hc(fun);
     147        assert(hc);
     148        usb_speed_t speed =
     149            usb_device_keeper_get_speed(&hc->manager, target.address);
    152150
    153151        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    154152            target.address, target.endpoint, size, max_packet_size);
    155153
    156         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    157             max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    158             &hc->device_manager);
     154        usb_transfer_batch_t *batch =
     155            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     156                speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);
    159157        if (!batch)
    160158                return ENOMEM;
    161159        batch_interrupt_out(batch);
    162         const int ret = uhci_hc_schedule(hc, batch);
    163         if (ret != EOK) {
    164                 batch_dispose(batch);
    165                 return ret;
    166         }
    167         return EOK;
     160        const int ret = hc_schedule(hc, batch);
     161        if (ret != EOK) {
     162                batch_dispose(batch);
     163        }
     164        return ret;
    168165}
    169166/*----------------------------------------------------------------------------*/
     
    179176 * @return Error code.
    180177 */
    181 static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    182     size_t max_packet_size, void *data, size_t size,
    183     usbhc_iface_transfer_in_callback_t callback, void *arg)
    184 {
    185         assert(fun);
    186         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    187         assert(hc);
    188         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     178static int interrupt_in(
     179    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     180    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     181{
     182        assert(fun);
     183        hc_t *hc = fun_to_hc(fun);
     184        assert(hc);
     185        usb_speed_t speed =
     186            usb_device_keeper_get_speed(&hc->manager, target.address);
    189187        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    190188            target.address, target.endpoint, size, max_packet_size);
    191189
    192         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    193             max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    194                         &hc->device_manager);
     190        usb_transfer_batch_t *batch =
     191            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     192                speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);
    195193        if (!batch)
    196194                return ENOMEM;
    197195        batch_interrupt_in(batch);
    198         const int ret = uhci_hc_schedule(hc, batch);
    199         if (ret != EOK) {
    200                 batch_dispose(batch);
    201                 return ret;
    202         }
    203         return EOK;
     196        const int ret = hc_schedule(hc, batch);
     197        if (ret != EOK) {
     198                batch_dispose(batch);
     199        }
     200        return ret;
    204201}
    205202/*----------------------------------------------------------------------------*/
     
    215212 * @return Error code.
    216213 */
    217 static int bulk_out(ddf_fun_t *fun, usb_target_t target,
    218     size_t max_packet_size, void *data, size_t size,
    219     usbhc_iface_transfer_out_callback_t callback, void *arg)
    220 {
    221         assert(fun);
    222         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    223         assert(hc);
    224         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     214static int bulk_out(
     215    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     216    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     217{
     218        assert(fun);
     219        hc_t *hc = fun_to_hc(fun);
     220        assert(hc);
     221        usb_speed_t speed =
     222            usb_device_keeper_get_speed(&hc->manager, target.address);
    225223
    226224        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    227225            target.address, target.endpoint, size, max_packet_size);
    228226
    229         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    230             max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    231             &hc->device_manager);
     227        usb_transfer_batch_t *batch =
     228            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     229                data, size, NULL, 0, NULL, callback, arg, &hc->manager);
    232230        if (!batch)
    233231                return ENOMEM;
    234232        batch_bulk_out(batch);
    235         const int ret = uhci_hc_schedule(hc, batch);
    236         if (ret != EOK) {
    237                 batch_dispose(batch);
    238                 return ret;
    239         }
    240         return EOK;
     233        const int ret = hc_schedule(hc, batch);
     234        if (ret != EOK) {
     235                batch_dispose(batch);
     236        }
     237        return ret;
    241238}
    242239/*----------------------------------------------------------------------------*/
     
    252249 * @return Error code.
    253250 */
    254 static int bulk_in(ddf_fun_t *fun, usb_target_t target,
    255     size_t max_packet_size, void *data, size_t size,
    256     usbhc_iface_transfer_in_callback_t callback, void *arg)
    257 {
    258         assert(fun);
    259         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    260         assert(hc);
    261         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     251static int bulk_in(
     252    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     253    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     254{
     255        assert(fun);
     256        hc_t *hc = fun_to_hc(fun);
     257        assert(hc);
     258        usb_speed_t speed =
     259            usb_device_keeper_get_speed(&hc->manager, target.address);
    262260        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    263261            target.address, target.endpoint, size, max_packet_size);
    264262
    265         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    266             max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    267             &hc->device_manager);
     263        usb_transfer_batch_t *batch =
     264            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     265                data, size, NULL, 0, callback, NULL, arg, &hc->manager);
    268266        if (!batch)
    269267                return ENOMEM;
    270268        batch_bulk_in(batch);
    271         const int ret = uhci_hc_schedule(hc, batch);
    272         if (ret != EOK) {
    273                 batch_dispose(batch);
    274                 return ret;
    275         }
    276         return EOK;
     269        const int ret = hc_schedule(hc, batch);
     270        if (ret != EOK) {
     271                batch_dispose(batch);
     272        }
     273        return ret;
    277274}
    278275/*----------------------------------------------------------------------------*/
     
    290287 * @return Error code.
    291288 */
    292 static int control_write(ddf_fun_t *fun, usb_target_t target,
    293     size_t max_packet_size,
     289static int control_write(
     290    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
    294291    void *setup_data, size_t setup_size, void *data, size_t size,
    295292    usbhc_iface_transfer_out_callback_t callback, void *arg)
    296293{
    297294        assert(fun);
    298         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    299         assert(hc);
    300         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     295        hc_t *hc = fun_to_hc(fun);
     296        assert(hc);
     297        usb_speed_t speed =
     298            usb_device_keeper_get_speed(&hc->manager, target.address);
    301299        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    302300            speed, target.address, target.endpoint, size, max_packet_size);
     
    305303                return EINVAL;
    306304
    307         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    308             max_packet_size, speed, data, size, setup_data, setup_size,
    309             NULL, callback, arg, &hc->device_manager);
    310         if (!batch)
    311                 return ENOMEM;
    312         usb_device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
     305        usb_transfer_batch_t *batch =
     306            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
     307                data, size, setup_data, setup_size, NULL, callback, arg,
     308                &hc->manager);
     309        if (!batch)
     310                return ENOMEM;
     311        usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
    313312        batch_control_write(batch);
    314         const int ret = uhci_hc_schedule(hc, batch);
    315         if (ret != EOK) {
    316                 batch_dispose(batch);
    317                 return ret;
    318         }
    319         return EOK;
     313        const int ret = hc_schedule(hc, batch);
     314        if (ret != EOK) {
     315                batch_dispose(batch);
     316        }
     317        return ret;
    320318}
    321319/*----------------------------------------------------------------------------*/
     
    333331 * @return Error code.
    334332 */
    335 static int control_read(ddf_fun_t *fun, usb_target_t target,
    336     size_t max_packet_size,
     333static int control_read(
     334    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
    337335    void *setup_data, size_t setup_size, void *data, size_t size,
    338336    usbhc_iface_transfer_in_callback_t callback, void *arg)
    339337{
    340338        assert(fun);
    341         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    342         assert(hc);
    343         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     339        hc_t *hc = fun_to_hc(fun);
     340        assert(hc);
     341        usb_speed_t speed =
     342            usb_device_keeper_get_speed(&hc->manager, target.address);
    344343
    345344        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    346345            speed, target.address, target.endpoint, size, max_packet_size);
    347         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    348             max_packet_size, speed, data, size, setup_data, setup_size, callback,
    349             NULL, arg, &hc->device_manager);
     346        usb_transfer_batch_t *batch =
     347            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
     348                data, size, setup_data, setup_size, callback, NULL, arg,
     349                &hc->manager);
    350350        if (!batch)
    351351                return ENOMEM;
    352352        batch_control_read(batch);
    353         const int ret = uhci_hc_schedule(hc, batch);
    354         if (ret != EOK) {
    355                 batch_dispose(batch);
    356                 return ret;
    357         }
    358         return EOK;
    359 }
    360 /*----------------------------------------------------------------------------*/
    361 usbhc_iface_t uhci_hc_iface = {
     353        const int ret = hc_schedule(hc, batch);
     354        if (ret != EOK) {
     355                batch_dispose(batch);
     356        }
     357        return ret;
     358}
     359/*----------------------------------------------------------------------------*/
     360usbhc_iface_t hc_iface = {
    362361        .reserve_default_address = reserve_default_address,
    363362        .release_default_address = release_default_address,
     
    369368        .interrupt_in = interrupt_in,
    370369
     370        .bulk_out = bulk_out,
    371371        .bulk_in = bulk_in,
    372         .bulk_out = bulk_out,
    373 
     372
     373        .control_write = control_write,
    374374        .control_read = control_read,
    375         .control_write = control_write,
    376375};
    377376/**
  • uspace/drv/uhci-hcd/iface.h

    r31b568e rb01995b  
    3838#include <usbhc_iface.h>
    3939
    40 extern usbhc_iface_t uhci_hc_iface;
     40extern usbhc_iface_t hc_iface;
    4141
    4242#endif
  • uspace/drv/uhci-hcd/root_hub.c

    r31b568e rb01995b  
    3939#include <usb/debug.h>
    4040
    41 #include "uhci_rh.h"
    42 #include "uhci_hc.h"
     41#include "root_hub.h"
    4342
    4443/** Root hub initialization
     
    4948 * @return Error code.
    5049 */
    51 int uhci_rh_init(
    52     uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
     50int rh_init(
     51    rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
    5352{
    5453        assert(fun);
  • uspace/drv/uhci-hcd/root_hub.h

    r31b568e rb01995b  
    3939#include <ops/hw_res.h>
    4040
    41 typedef struct uhci_rh {
     41typedef struct rh {
    4242        hw_resource_list_t resource_list;
    4343        hw_resource_t io_regs;
    44 } uhci_rh_t;
     44} rh_t;
    4545
    46 int uhci_rh_init(
    47     uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size);
     46int rh_init(
     47    rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size);
    4848
    4949#endif
  • uspace/drv/uhci-hcd/transfer_list.c

    r31b568e rb01995b  
    7979        if (!instance->queue_head)
    8080                return;
    81         /* Set both next and element to point to the same QH */
     81        /* Set both queue_head.next to point to the follower */
    8282        qh_set_next_qh(instance->queue_head, next->queue_head_pa);
    83         qh_set_element_qh(instance->queue_head, next->queue_head_pa);
    8483}
    8584/*----------------------------------------------------------------------------*/
     
    9897        usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
    9998
    100         const uint32_t pa = addr_to_phys(batch_qh(batch));
    101         assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
    102 
    103         /* New batch will be added to the end of the current list
    104          * so set the link accordingly */
    105         qh_set_next_qh(batch_qh(batch), instance->queue_head->next);
    106 
    10799        fibril_mutex_lock(&instance->guard);
    108100
     101        qh_t *last_qh = NULL;
    109102        /* Add to the hardware queue. */
    110103        if (list_empty(&instance->batch_list)) {
    111104                /* There is nothing scheduled */
    112                 qh_t *qh = instance->queue_head;
    113                 assert(qh->element == qh->next);
    114                 qh_set_element_qh(qh, pa);
     105                last_qh = instance->queue_head;
    115106        } else {
    116107                /* There is something scheduled */
    117108                usb_transfer_batch_t *last = list_get_instance(
    118109                    instance->batch_list.prev, usb_transfer_batch_t, link);
    119                 qh_set_next_qh(batch_qh(last), pa);
    120         }
     110                last_qh = batch_qh(last);
     111        }
     112        const uint32_t pa = addr_to_phys(batch_qh(batch));
     113        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
     114
     115        /* keep link */
     116        batch_qh(batch)->next = last_qh->next;
     117        qh_set_next_qh(last_qh, pa);
     118
    121119        /* Add to the driver list */
    122120        list_append(&batch->link, &instance->batch_list);
     
    174172{
    175173        fibril_mutex_lock(&instance->guard);
    176         while (list_empty(&instance->batch_list)) {
     174        while (!list_empty(&instance->batch_list)) {
    177175                link_t *current = instance->batch_list.next;
    178176                usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
     
    197195        assert(batch);
    198196        assert(batch_qh(batch));
     197        assert(fibril_mutex_is_locked(&instance->guard));
     198
    199199        usb_log_debug2(
    200200            "Queue %s: removing batch(%p).\n", instance->name, batch);
    201201
    202         const char * pos = NULL;
     202        const char *qpos = NULL;
    203203        /* Remove from the hardware queue */
    204         if (batch->link.prev == &instance->batch_list) {
     204        if (instance->batch_list.next == &batch->link) {
    205205                /* I'm the first one here */
    206                 qh_set_element_qh(instance->queue_head, batch_qh(batch)->next);
    207                 pos = "FIRST";
     206                assert((instance->queue_head->next & LINK_POINTER_ADDRESS_MASK)
     207                    == addr_to_phys(batch_qh(batch)));
     208                instance->queue_head->next = batch_qh(batch)->next;
     209                qpos = "FIRST";
    208210        } else {
    209211                usb_transfer_batch_t *prev =
    210212                    list_get_instance(batch->link.prev, usb_transfer_batch_t, link);
    211                 qh_set_next_qh(batch_qh(prev), batch_qh(batch)->next);
    212                 pos = "NOT FIRST";
    213         }
    214         /* Remove from the driver list */
     213                assert((batch_qh(prev)->next & LINK_POINTER_ADDRESS_MASK)
     214                    == addr_to_phys(batch_qh(batch)));
     215                batch_qh(prev)->next = batch_qh(batch)->next;
     216                qpos = "NOT FIRST";
     217        }
     218        /* Remove from the batch list */
    215219        list_remove(&batch->link);
    216         usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
    217             batch, pos, instance->name, batch_qh(batch)->next);
     220        usb_log_debug("Batch(%p) removed (%s) from %s, next %x.\n",
     221            batch, qpos, instance->name, batch_qh(batch)->next);
    218222}
    219223/**
  • uspace/drv/uhci-hcd/transfer_list.h

    r31b568e rb01995b  
    3737#include <fibril_synch.h>
    3838
    39 #include "uhci_struct/queue_head.h"
    40 
    4139#include "batch.h"
     40#include "hw_struct/queue_head.h"
    4241
    4342typedef struct transfer_list
  • uspace/drv/uhci-hcd/uhci.c

    r31b568e rb01995b  
    5454{
    5555        assert(dev);
    56         uhci_hc_t *hc = &((uhci_t*)dev->driver_data)->hc;
     56        hc_t *hc = &((uhci_t*)dev->driver_data)->hc;
    5757        uint16_t status = IPC_GET_ARG1(*call);
    5858        assert(hc);
    59         uhci_hc_interrupt(hc, status);
     59        hc_interrupt(hc, status);
    6060}
    6161/*----------------------------------------------------------------------------*/
     
    7070{
    7171        assert(fun);
    72         usb_device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
     72        usb_device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.manager;
    7373
    7474        usb_address_t addr = usb_device_keeper_find(manager, handle);
     
    107107};
    108108/*----------------------------------------------------------------------------*/
    109 static ddf_dev_ops_t uhci_hc_ops = {
     109static ddf_dev_ops_t hc_ops = {
    110110        .interfaces[USB_DEV_IFACE] = &usb_iface,
    111         .interfaces[USBHC_DEV_IFACE] = &uhci_hc_iface, /* see iface.h/c */
     111        .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
    112112};
    113113/*----------------------------------------------------------------------------*/
     
    120120{
    121121        assert(fun);
    122         return &((uhci_rh_t*)fun->driver_data)->resource_list;
     122        return &((rh_t*)fun->driver_data)->resource_list;
    123123}
    124124/*----------------------------------------------------------------------------*/
     
    128128};
    129129/*----------------------------------------------------------------------------*/
    130 static ddf_dev_ops_t uhci_rh_ops = {
     130static ddf_dev_ops_t rh_ops = {
    131131        .interfaces[USB_DEV_IFACE] = &usb_iface,
    132132        .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
     
    190190            "Failed(%d) to create HC function.\n", ret);
    191191
    192         ret = uhci_hc_init(&instance->hc, instance->hc_fun,
     192        ret = hc_init(&instance->hc, instance->hc_fun,
    193193            (void*)io_reg_base, io_reg_size, interrupts);
    194194        CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
    195         instance->hc_fun->ops = &uhci_hc_ops;
     195        instance->hc_fun->ops = &hc_ops;
    196196        instance->hc_fun->driver_data = &instance->hc;
    197197        ret = ddf_fun_bind(instance->hc_fun);
     
    208208        if (instance->rh_fun) \
    209209                ddf_fun_destroy(instance->rh_fun); \
    210         uhci_hc_fini(&instance->hc); \
     210        hc_fini(&instance->hc); \
    211211        return ret; \
    212212}
     
    223223            "Failed(%d) to create root hub function.\n", ret);
    224224
    225         ret = uhci_rh_init(&instance->rh, instance->rh_fun,
     225        ret = rh_init(&instance->rh, instance->rh_fun,
    226226            (uintptr_t)instance->hc.registers + 0x10, 4);
    227227        CHECK_RET_FINI_RETURN(ret,
    228228            "Failed(%d) to setup UHCI root hub.\n", ret);
    229229
    230         instance->rh_fun->ops = &uhci_rh_ops;
     230        instance->rh_fun->ops = &rh_ops;
    231231        instance->rh_fun->driver_data = &instance->rh;
    232232        ret = ddf_fun_bind(instance->rh_fun);
  • uspace/drv/uhci-hcd/uhci.h

    r31b568e rb01995b  
    3838#include <ddf/driver.h>
    3939
    40 #include "uhci_hc.h"
    41 #include "uhci_rh.h"
     40#include "hc.h"
     41#include "root_hub.h"
    4242
    4343typedef struct uhci {
     
    4545        ddf_fun_t *rh_fun;
    4646
    47         uhci_hc_t hc;
    48         uhci_rh_t rh;
     47        hc_t hc;
     48        rh_t rh;
    4949} uhci_t;
    5050
  • uspace/drv/uhci-hcd/utils/malloc32.h

    r31b568e rb01995b  
    5050static inline uintptr_t addr_to_phys(void *addr)
    5151{
     52        if (addr == NULL)
     53                return 0;
     54
    5255        uintptr_t result;
    5356        int ret = as_get_physical_mapping(addr, &result);
  • uspace/lib/usb/src/host/device_keeper.c

    r31b568e rb01995b  
    214214        fibril_mutex_lock(&instance->guard);
    215215
    216         usb_address_t new_address = instance->last_address + 1;
    217         while (instance->devices[new_address].occupied) {
     216        usb_address_t new_address = instance->last_address;
     217        do {
     218                ++new_address;
     219                if (new_address > USB11_ADDRESS_MAX)
     220                        new_address = 1;
    218221                if (new_address == instance->last_address) {
    219222                        fibril_mutex_unlock(&instance->guard);
    220223                        return ENOSPC;
    221224                }
    222                 if (new_address == USB11_ADDRESS_MAX)
    223                         new_address = 1;
    224                 ++new_address;
    225         }
     225        } while (instance->devices[new_address].occupied);
    226226
    227227        assert(new_address != USB_ADDRESS_DEFAULT);
Note: See TracChangeset for help on using the changeset viewer.