Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/batch.c

    r17ceb72 ra7e2f0d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver USB transaction structure
     32 * @brief UHCI driver
    3333 */
    3434#include <errno.h>
     
    4040#include "batch.h"
    4141#include "transfer_list.h"
    42 #include "uhci_hc.h"
     42#include "uhci.h"
    4343#include "utils/malloc32.h"
    4444
    4545#define DEFAULT_ERROR_COUNT 3
     46
     47static int batch_schedule(batch_t *instance);
    4648
    4749static void batch_control(batch_t *instance,
     
    5254static void batch_call_in_and_dispose(batch_t *instance);
    5355static void batch_call_out_and_dispose(batch_t *instance);
    54 
    55 
    56 /** Allocate memory and initialize internal data structure.
     56static void batch_dispose(batch_t *instance);
     57
     58
     59/** Allocates memory and initializes internal data structures.
    5760 *
    5861 * @param[in] fun DDF function to pass to callback.
     
    6972 * @param[in] arg additional parameter to func_in or func_out
    7073 * @param[in] manager Pointer to toggle management structure.
    71  * @return Valid pointer if all substructures were successfully created,
    72  * NULL otherwise.
    73  *
    74  * Determines the number of needed packets (TDs). Prepares a transport buffer
    75  * (that is accessible by the hardware). Initializes parameters needed for the
    76  * transaction and callback.
     74 * @return False, if there is an active TD, true otherwise.
    7775 */
    7876batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     
    102100        bzero(instance, sizeof(batch_t));
    103101
    104         instance->qh = malloc32(sizeof(qh_t));
     102        instance->qh = malloc32(sizeof(queue_head_t));
    105103        CHECK_NULL_DISPOSE_RETURN(instance->qh,
    106104            "Failed to allocate batch queue head.\n");
    107         qh_init(instance->qh);
     105        queue_head_init(instance->qh);
    108106
    109107        instance->packets = (size + max_packet_size - 1) / max_packet_size;
     
    116114            instance->tds, "Failed to allocate transfer descriptors.\n");
    117115        bzero(instance->tds, sizeof(td_t) * instance->packets);
     116
     117//      const size_t transport_size = max_packet_size * instance->packets;
    118118
    119119        if (size > 0) {
     
    143143        instance->speed = speed;
    144144        instance->manager = manager;
    145         instance->callback_out = func_out;
    146         instance->callback_in = func_in;
    147 
    148         qh_set_element_td(instance->qh, addr_to_phys(instance->tds));
     145
     146        if (func_out)
     147                instance->callback_out = func_out;
     148        if (func_in)
     149                instance->callback_in = func_in;
     150
     151        queue_head_set_element_td(instance->qh, addr_to_phys(instance->tds));
    149152
    150153        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
     
    153156}
    154157/*----------------------------------------------------------------------------*/
    155 /** Check batch TDs for activity.
     158/** Checks batch TDs for activity.
    156159 *
    157160 * @param[in] instance Batch structure to use.
    158161 * @return False, if there is an active TD, true otherwise.
    159  *
    160  * Walk all TDs. Stop with false if there is an active one (it is to be
    161  * processed). Stop with true if an error is found. Return true if the last TS
    162  * is reached.
    163162 */
    164163bool batch_is_complete(batch_t *instance)
     
    178177                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
    179178                            instance, i, instance->tds[i].status);
    180                         td_print_status(&instance->tds[i]);
    181179
    182180                        device_keeper_set_toggle(instance->manager,
     
    199197 *
    200198 * @param[in] instance Batch structure to use.
    201  *
    202  * Uses genercir control function with pids OUT and IN.
    203199 */
    204200void batch_control_write(batch_t *instance)
    205201{
    206202        assert(instance);
    207         /* We are data out, we are supposed to provide data */
     203        /* we are data out, we are supposed to provide data */
    208204        memcpy(instance->transport_buffer, instance->buffer,
    209205            instance->buffer_size);
     
    211207        instance->next_step = batch_call_out_and_dispose;
    212208        usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
     209        batch_schedule(instance);
    213210}
    214211/*----------------------------------------------------------------------------*/
     
    216213 *
    217214 * @param[in] instance Batch structure to use.
    218  *
    219  * Uses generic control with pids IN and OUT.
    220215 */
    221216void batch_control_read(batch_t *instance)
     
    225220        instance->next_step = batch_call_in_and_dispose;
    226221        usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
    227 }
    228 /*----------------------------------------------------------------------------*/
    229 /** Prepare interrupt in transaction.
    230  *
    231  * @param[in] instance Batch structure to use.
    232  *
    233  * Data transaction with PID_IN.
     222        batch_schedule(instance);
     223}
     224/*----------------------------------------------------------------------------*/
     225/** Prepares interrupt in transaction.
     226 *
     227 * @param[in] instance Batch structure to use.
    234228 */
    235229void batch_interrupt_in(batch_t *instance)
     
    239233        instance->next_step = batch_call_in_and_dispose;
    240234        usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    241 }
    242 /*----------------------------------------------------------------------------*/
    243 /** Prepare interrupt out transaction.
    244  *
    245  * @param[in] instance Batch structure to use.
    246  *
    247  * Data transaction with PID_OUT.
     235        batch_schedule(instance);
     236}
     237/*----------------------------------------------------------------------------*/
     238/** Prepares interrupt out transaction.
     239 *
     240 * @param[in] instance Batch structure to use.
    248241 */
    249242void batch_interrupt_out(batch_t *instance)
    250243{
    251244        assert(instance);
    252         /* We are data out, we are supposed to provide data */
     245        /* we are data out, we are supposed to provide data */
    253246        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    254247        batch_data(instance, USB_PID_OUT);
    255248        instance->next_step = batch_call_out_and_dispose;
    256249        usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
    257 }
    258 /*----------------------------------------------------------------------------*/
    259 /** Prepare bulk in transaction.
    260  *
    261  * @param[in] instance Batch structure to use.
    262  *
    263  * Data transaction with PID_IN.
     250        batch_schedule(instance);
     251}
     252/*----------------------------------------------------------------------------*/
     253/** Prepares bulk in transaction.
     254 *
     255 * @param[in] instance Batch structure to use.
    264256 */
    265257void batch_bulk_in(batch_t *instance)
     
    269261        instance->next_step = batch_call_in_and_dispose;
    270262        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    271 }
    272 /*----------------------------------------------------------------------------*/
    273 /** Prepare bulk out transaction.
    274  *
    275  * @param[in] instance Batch structure to use.
    276  *
    277  * Data transaction with PID_OUT.
     263        batch_schedule(instance);
     264}
     265/*----------------------------------------------------------------------------*/
     266/** Prepares bulk out transaction.
     267 *
     268 * @param[in] instance Batch structure to use.
    278269 */
    279270void batch_bulk_out(batch_t *instance)
    280271{
    281272        assert(instance);
    282         /* We are data out, we are supposed to provide data */
    283273        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    284274        batch_data(instance, USB_PID_OUT);
    285275        instance->next_step = batch_call_out_and_dispose;
    286276        usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance);
    287 }
    288 /*----------------------------------------------------------------------------*/
    289 /** Prepare generic data transaction
     277        batch_schedule(instance);
     278}
     279/*----------------------------------------------------------------------------*/
     280/** Prepares generic data transaction
    290281 *
    291282 * @param[in] instance Batch structure to use.
    292283 * @param[in] pid to use for data packets.
    293  *
    294  * Packets with alternating toggle bit and supplied pid value.
    295  * The last packet is marked with IOC flag.
    296284 */
    297285void batch_data(batch_t *instance, usb_packet_id pid)
     
    330318                ++packet;
    331319        }
    332         td_set_ioc(&instance->tds[packet - 1]);
    333320        device_keeper_set_toggle(instance->manager, instance->target, toggle);
    334321}
    335322/*----------------------------------------------------------------------------*/
    336 /** Prepare generic control transaction
     323/** Prepares generic control transaction
    337324 *
    338325 * @param[in] instance Batch structure to use.
    339326 * @param[in] data_stage to use for data packets.
    340327 * @param[in] status_stage to use for data packets.
    341  *
    342  * Setup stage with toggle 0 and USB_PID_SETUP.
    343  * Data stage with alternating toggle and pid supplied by parameter.
    344  * Status stage with toggle 1 and pid supplied by parameter.
    345  * The last packet is marked with IOC.
    346328 */
    347329void batch_control(batch_t *instance,
     
    387369            0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
    388370
    389         td_set_ioc(&instance->tds[packet]);
     371
     372        instance->tds[packet].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
    390373        usb_log_debug2("Control last TD status: %x.\n",
    391374            instance->tds[packet].status);
    392375}
    393376/*----------------------------------------------------------------------------*/
    394 /** Prepare data, get error status and call callback in.
    395  *
    396  * @param[in] instance Batch structure to use.
    397  * Copies data from transport buffer, and calls callback with appropriate
    398  * parameters.
     377/** Prepares data, gets error status and calls callback in.
     378 *
     379 * @param[in] instance Batch structure to use.
    399380 */
    400381void batch_call_in(batch_t *instance)
     
    403384        assert(instance->callback_in);
    404385
    405         /* We are data in, we need data */
     386        /* we are data in, we need data */
    406387        memcpy(instance->buffer, instance->transport_buffer,
    407388            instance->buffer_size);
     
    416397}
    417398/*----------------------------------------------------------------------------*/
    418 /** Get error status and call callback out.
     399/** Gets error status and calls callback out.
    419400 *
    420401 * @param[in] instance Batch structure to use.
     
    432413}
    433414/*----------------------------------------------------------------------------*/
    434 /** Helper function calls callback and correctly disposes of batch structure.
     415/** Prepares data, gets error status, calls callback in and dispose.
    435416 *
    436417 * @param[in] instance Batch structure to use.
     
    443424}
    444425/*----------------------------------------------------------------------------*/
    445 /** Helper function calls callback and correctly disposes of batch structure.
     426/** Gets error status, calls callback out and dispose.
    446427 *
    447428 * @param[in] instance Batch structure to use.
     
    454435}
    455436/*----------------------------------------------------------------------------*/
    456 /** Correctly dispose all used data structures.
     437/** Correctly disposes all used data structures.
    457438 *
    458439 * @param[in] instance Batch structure to use.
     
    469450        free(instance);
    470451}
     452/*----------------------------------------------------------------------------*/
     453int batch_schedule(batch_t *instance)
     454{
     455        assert(instance);
     456        uhci_t *hc = fun_to_uhci(instance->fun);
     457        assert(hc);
     458        return uhci_schedule(hc, instance);
     459}
    471460/**
    472461 * @}
Note: See TracChangeset for help on using the changeset viewer.