Changeset 50114ef in mainline


Ignore:
Timestamp:
2011-03-24T13:45:48Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
915a851
Parents:
5f80527 (diff), e18e0d6 (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:

Merge development/ changes

Files:
14 edited
8 moved

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    r5f80527 r50114ef  
    552552! CONFIG_RUN_VIRTUAL_USB_HC (n/y)
    553553
     554% Polling UHCI & OHCI (no interrupts)
     555! [PLATFORM=ia32|PLATFORM=amd64] CONFIG_USBHC_NO_INTERRUPTS (y/n)
  • uspace/drv/ohci/iface.c

    r5f80527 r50114ef  
    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/ohci/main.c

    r5f80527 r50114ef  
    149149        }
    150150
     151
    151152        bool interrupts = false;
     153#ifdef CONFIG_USBHC_NO_INTERRUPTS
     154        usb_log_warning("Interrupts disabled in OS config, " \
     155            "falling back to polling.\n");
     156#else
    152157        ret = pci_enable_interrupts(device);
    153158        if (ret != EOK) {
    154                 usb_log_warning(
    155                     "Failed(%d) to enable interrupts, fall back to polling.\n",
    156                     ret);
     159                usb_log_warning("Failed to enable interrupts: %s.\n",
     160                    str_error(ret));
     161                usb_log_info("HW interrupts not available, " \
     162                    "falling back to polling.\n");
    157163        } else {
    158164                usb_log_debug("Hw interrupts enabled.\n");
    159165                interrupts = true;
    160166        }
     167#endif
    161168
    162169        ret = hc_init(hcd, hc_fun, device, mem_reg_base, mem_reg_size, interrupts);
  • uspace/drv/uhci-hcd/Makefile

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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
     
    4948        qh_t *qh;
    5049        td_t *tds;
    51         size_t packets;
     50        size_t transfers;
    5251        usb_device_keeper_t *manager;
    5352} uhci_batch_t;
     
    6564 * @param[in] target Device and endpoint target of the transaction.
    6665 * @param[in] transfer_type Interrupt, Control or Bulk.
    67  * @param[in] max_packet_size maximum allowed size of data packets.
     66 * @param[in] max_packet_size maximum allowed size of data transfers.
    6867 * @param[in] speed Speed of the transaction.
    6968 * @param[in] buffer Data source/destination.
     
    7877 * NULL otherwise.
    7978 *
    80  * Determines the number of needed packets (TDs). Prepares a transport buffer
     79 * Determines the number of needed transfers (TDs). Prepares a transport buffer
    8180 * (that is accessible by the hardware). Initializes parameters needed for the
    8281 * transaction and callback.
     
    118117        instance->private_data = data;
    119118
    120         data->packets = (buffer_size + max_packet_size - 1) / max_packet_size;
     119        data->transfers = (buffer_size + max_packet_size - 1) / max_packet_size;
    121120        if (transfer_type == USB_TRANSFER_CONTROL) {
    122                 data->packets += 2;
    123         }
    124 
    125         data->tds = malloc32(sizeof(td_t) * data->packets);
     121                data->transfers += 2;
     122        }
     123
     124        data->tds = malloc32(sizeof(td_t) * data->transfers);
    126125        CHECK_NULL_DISPOSE_RETURN(
    127126            data->tds, "Failed to allocate transfer descriptors.\n");
    128         bzero(data->tds, sizeof(td_t) * data->packets);
     127        bzero(data->tds, sizeof(td_t) * data->transfers);
    129128
    130129        data->qh = malloc32(sizeof(qh_t));
     
    167166        assert(data);
    168167
    169         usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n",
    170             instance, data->packets);
     168        usb_log_debug2("Batch(%p) checking %d transfer(s) for completion.\n",
     169            instance, data->transfers);
    171170        instance->transfered_size = 0;
    172171        size_t i = 0;
    173         for (;i < data->packets; ++i) {
     172        for (;i < data->transfers; ++i) {
    174173                if (td_is_active(&data->tds[i])) {
    175174                        return false;
     
    299298 *
    300299 * @param[in] instance Batch structure to use.
    301  * @param[in] pid to use for data packets.
     300 * @param[in] pid Pid to use for data transfers.
    302301 *
    303302 * Packets with alternating toggle bit and supplied pid value.
    304  * The last packet is marked with IOC flag.
     303 * The last transfer is marked with IOC flag.
    305304 */
    306305void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid)
     
    315314        assert(toggle == 0 || toggle == 1);
    316315
    317         size_t packet = 0;
     316        size_t transfer = 0;
    318317        size_t remain_size = instance->buffer_size;
    319318        while (remain_size > 0) {
     
    326325                    remain_size : instance->max_packet_size;
    327326
    328                 td_t *next_packet = (packet + 1 < data->packets)
    329                     ? &data->tds[packet + 1] : NULL;
    330 
    331                 assert(packet < data->packets);
     327                td_t *next_transfer = (transfer + 1 < data->transfers)
     328                    ? &data->tds[transfer + 1] : NULL;
     329
     330                assert(transfer < data->transfers);
    332331                assert(packet_size <= remain_size);
    333332
    334333                td_init(
    335                     &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     334                    &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size,
    336335                    toggle, false, low_speed, instance->target, pid, trans_data,
    337                     next_packet);
     336                    next_transfer);
    338337
    339338
    340339                toggle = 1 - toggle;
    341340                remain_size -= packet_size;
    342                 ++packet;
    343         }
    344         td_set_ioc(&data->tds[packet - 1]);
     341                ++transfer;
     342        }
     343        td_set_ioc(&data->tds[transfer - 1]);
    345344        usb_device_keeper_set_toggle(data->manager, instance->target,
    346345            instance->direction, toggle);
     
    350349 *
    351350 * @param[in] instance Batch structure to use.
    352  * @param[in] data_stage to use for data packets.
    353  * @param[in] status_stage to use for data packets.
     351 * @param[in] data_stage Pid to use for data transfers.
     352 * @param[in] status_stage Pid to use for data transfers.
    354353 *
    355354 * Setup stage with toggle 0 and USB_PID_SETUP.
    356355 * Data stage with alternating toggle and pid supplied by parameter.
    357356 * Status stage with toggle 1 and pid supplied by parameter.
    358  * The last packet is marked with IOC.
     357 * The last transfer is marked with IOC.
    359358 */
    360359void batch_control(usb_transfer_batch_t *instance,
     
    364363        uhci_batch_t *data = instance->private_data;
    365364        assert(data);
    366         assert(data->packets >= 2);
     365        assert(data->transfers >= 2);
    367366
    368367        const bool low_speed = instance->speed == USB_SPEED_LOW;
     
    375374
    376375        /* data stage */
    377         size_t packet = 1;
     376        size_t transfer = 1;
    378377        size_t remain_size = instance->buffer_size;
    379378        while (remain_size > 0) {
     
    389388
    390389                td_init(
    391                     &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     390                    &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size,
    392391                    toggle, false, low_speed, instance->target, data_stage,
    393                     control_data, &data->tds[packet + 1]);
    394 
    395                 ++packet;
    396                 assert(packet < data->packets);
     392                    control_data, &data->tds[transfer + 1]);
     393
     394                ++transfer;
     395                assert(transfer < data->transfers);
    397396                assert(packet_size <= remain_size);
    398397                remain_size -= packet_size;
     
    400399
    401400        /* status stage */
    402         assert(packet == data->packets - 1);
     401        assert(transfer == data->transfers - 1);
    403402
    404403        td_init(
    405             &data->tds[packet], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
     404            &data->tds[transfer], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
    406405            instance->target, status_stage, NULL, NULL);
    407         td_set_ioc(&data->tds[packet]);
     406        td_set_ioc(&data->tds[transfer]);
    408407
    409408        usb_log_debug2("Control last TD status: %x.\n",
    410             data->tds[packet].status);
     409            data->tds[transfer].status);
    411410}
    412411/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-hcd/batch.h

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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);
    68 
    69 static bool allowed_usb_packet(
     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);
     68
     69static bool usb_is_allowed(
    7070    bool low_speed, usb_transfer_type_t transfer, size_t size);
    7171/*----------------------------------------------------------------------------*/
     
    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);
    322323        assert(batch);
    323324        const int low_speed = (batch->speed == USB_SPEED_LOW);
    324         if (!allowed_usb_packet(
     325        if (!usb_is_allowed(
    325326            low_speed, batch->transfer_type, batch->max_packet_size)) {
    326327                usb_log_warning(
    327                     "Invalid USB packet specified %s SPEED %d %zu.\n",
     328                    "Invalid USB transfer specified %s SPEED %d %zu.\n",
    328329                    low_speed ? "LOW" : "FULL" , batch->transfer_type,
    329330                    batch->max_packet_size);
     
    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
     
    470471}
    471472/*----------------------------------------------------------------------------*/
    472 /** Check transfer packets, for USB validity
     473/** Check transfers for USB validity
    473474 *
    474475 * @param[in] low_speed Transfer speed.
    475476 * @param[in] transfer Transer type
    476  * @param[in] size Maximum size of used packets
     477 * @param[in] size Size of data packets
    477478 * @return True if transaction is allowed by USB specs, false otherwise
    478479 */
    479 bool allowed_usb_packet(
     480bool usb_is_allowed(
    480481    bool low_speed, usb_transfer_type_t transfer, size_t size)
    481482{
  • uspace/drv/uhci-hcd/hc.h

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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/hw_struct/transfer_descriptor.h

    r5f80527 r50114ef  
    108108}
    109109/*----------------------------------------------------------------------------*/
    110 /** Check whether less than max data were recieved and packet is marked as SPD.
     110/** Check whether less than max data were received on SPD marked transfer.
    111111 *
    112112 * @param[in] instance TD structure to use.
    113  * @return True if packet is short (less than max bytes and SPD set), false
    114  *     otherwise.
     113 * @return True if data packet is short (less than max bytes and SPD set),
     114 * false otherwise.
    115115 */
    116116static inline bool td_is_short(td_t *instance)
  • uspace/drv/uhci-hcd/iface.c

    r5f80527 r50114ef  
    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/*----------------------------------------------------------------------------*/
     
    282279 * @param[in] target USB device to write to.
    283280 * @param[in] max_packet_size maximum size of data packet the device accepts.
    284  * @param[in] setup_data Data to send with SETUP packet.
    285  * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
     281 * @param[in] setup_data Data to send with SETUP transfer.
     282 * @param[in] setup_size Size of data to send with SETUP transfer (always 8B).
    286283 * @param[in] data Source of data.
    287284 * @param[in] size Size of data source.
     
    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

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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/*----------------------------------------------------------------------------*/
     
    9291 * The batch is added to the end of the list and queue.
    9392 */
    94 void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
     93void transfer_list_add_batch(
     94    transfer_list_t *instance, usb_transfer_batch_t *batch)
    9595{
    9696        assert(instance);
     
    9898        usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
    9999
    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 
    107100        fibril_mutex_lock(&instance->guard);
    108101
     102        qh_t *last_qh = NULL;
    109103        /* Add to the hardware queue. */
    110104        if (list_empty(&instance->batch_list)) {
    111105                /* There is nothing scheduled */
    112                 qh_t *qh = instance->queue_head;
    113                 assert(qh->element == qh->next);
    114                 qh_set_element_qh(qh, pa);
     106                last_qh = instance->queue_head;
    115107        } else {
    116108                /* There is something scheduled */
    117109                usb_transfer_batch_t *last = list_get_instance(
    118110                    instance->batch_list.prev, usb_transfer_batch_t, link);
    119                 qh_set_next_qh(batch_qh(last), pa);
    120         }
     111                last_qh = batch_qh(last);
     112        }
     113        const uint32_t pa = addr_to_phys(batch_qh(batch));
     114        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
     115
     116        /* keep link */
     117        batch_qh(batch)->next = last_qh->next;
     118        qh_set_next_qh(last_qh, pa);
     119
    121120        /* Add to the driver list */
    122121        list_append(&batch->link, &instance->batch_list);
     
    148147        while (current != &instance->batch_list) {
    149148                link_t *next = current->next;
    150                 usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
     149                usb_transfer_batch_t *batch =
     150                    list_get_instance(current, usb_transfer_batch_t, link);
    151151
    152152                if (batch_is_complete(batch)) {
     
    162162                link_t *item = done.next;
    163163                list_remove(item);
    164                 usb_transfer_batch_t *batch = list_get_instance(item, usb_transfer_batch_t, link);
     164                usb_transfer_batch_t *batch =
     165                    list_get_instance(item, usb_transfer_batch_t, link);
    165166                batch->next_step(batch);
    166167        }
     
    174175{
    175176        fibril_mutex_lock(&instance->guard);
    176         while (list_empty(&instance->batch_list)) {
     177        while (!list_empty(&instance->batch_list)) {
    177178                link_t *current = instance->batch_list.next;
    178                 usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
     179                usb_transfer_batch_t *batch =
     180                    list_get_instance(current, usb_transfer_batch_t, link);
    179181                transfer_list_remove_batch(instance, batch);
    180182                usb_transfer_batch_finish(batch, EIO);
     
    191193 * Does not lock the transfer list, caller is responsible for that.
    192194 */
    193 void transfer_list_remove_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
     195void transfer_list_remove_batch(
     196    transfer_list_t *instance, usb_transfer_batch_t *batch)
    194197{
    195198        assert(instance);
     
    197200        assert(batch);
    198201        assert(batch_qh(batch));
     202        assert(fibril_mutex_is_locked(&instance->guard));
     203
    199204        usb_log_debug2(
    200205            "Queue %s: removing batch(%p).\n", instance->name, batch);
    201206
    202         const char * pos = NULL;
     207        const char *qpos = NULL;
    203208        /* Remove from the hardware queue */
    204         if (batch->link.prev == &instance->batch_list) {
     209        if (instance->batch_list.next == &batch->link) {
    205210                /* I'm the first one here */
    206                 qh_set_element_qh(instance->queue_head, batch_qh(batch)->next);
    207                 pos = "FIRST";
     211                assert((instance->queue_head->next & LINK_POINTER_ADDRESS_MASK)
     212                    == addr_to_phys(batch_qh(batch)));
     213                instance->queue_head->next = batch_qh(batch)->next;
     214                qpos = "FIRST";
    208215        } else {
    209216                usb_transfer_batch_t *prev =
    210                     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 */
     217                    list_get_instance(
     218                        batch->link.prev, usb_transfer_batch_t, link);
     219                assert((batch_qh(prev)->next & LINK_POINTER_ADDRESS_MASK)
     220                    == addr_to_phys(batch_qh(batch)));
     221                batch_qh(prev)->next = batch_qh(batch)->next;
     222                qpos = "NOT FIRST";
     223        }
     224        /* Remove from the batch list */
    215225        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);
     226        usb_log_debug("Batch(%p) removed (%s) from %s, next %x.\n",
     227            batch, qpos, instance->name, batch_qh(batch)->next);
    218228}
    219229/**
  • uspace/drv/uhci-hcd/transfer_list.h

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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
     
    175175
    176176        bool interrupts = false;
     177#ifdef CONFIG_USBHC_NO_INTERRUPTS
     178        usb_log_warning("Interrupts disabled in OS config, " \
     179            "falling back to polling.\n");
     180#else
    177181        ret = pci_enable_interrupts(device);
    178182        if (ret != EOK) {
    179                 usb_log_warning(
    180                     "Failed(%d) to enable interrupts, fall back to polling.\n",
    181                     ret);
     183                usb_log_warning("Failed to enable interrupts: %s.\n",
     184                    str_error(ret));
     185                usb_log_info("HW interrupts not available, " \
     186                    "falling back to polling.\n");
    182187        } else {
    183188                usb_log_debug("Hw interrupts enabled.\n");
    184189                interrupts = true;
    185190        }
     191#endif
    186192
    187193        instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc");
     
    190196            "Failed(%d) to create HC function.\n", ret);
    191197
    192         ret = uhci_hc_init(&instance->hc, instance->hc_fun,
     198        ret = hc_init(&instance->hc, instance->hc_fun,
    193199            (void*)io_reg_base, io_reg_size, interrupts);
    194200        CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
    195         instance->hc_fun->ops = &uhci_hc_ops;
     201        instance->hc_fun->ops = &hc_ops;
    196202        instance->hc_fun->driver_data = &instance->hc;
    197203        ret = ddf_fun_bind(instance->hc_fun);
     
    208214        if (instance->rh_fun) \
    209215                ddf_fun_destroy(instance->rh_fun); \
    210         uhci_hc_fini(&instance->hc); \
     216        hc_fini(&instance->hc); \
    211217        return ret; \
    212218}
     
    223229            "Failed(%d) to create root hub function.\n", ret);
    224230
    225         ret = uhci_rh_init(&instance->rh, instance->rh_fun,
     231        ret = rh_init(&instance->rh, instance->rh_fun,
    226232            (uintptr_t)instance->hc.registers + 0x10, 4);
    227233        CHECK_RET_FINI_RETURN(ret,
    228234            "Failed(%d) to setup UHCI root hub.\n", ret);
    229235
    230         instance->rh_fun->ops = &uhci_rh_ops;
     236        instance->rh_fun->ops = &rh_ops;
    231237        instance->rh_fun->driver_data = &instance->rh;
    232238        ret = ddf_fun_bind(instance->rh_fun);
  • uspace/drv/uhci-hcd/uhci.h

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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

    r5f80527 r50114ef  
    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.