Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r9d58539 r0d4b110  
    3232 * @brief OHCI driver USB transaction structure
    3333 */
     34
     35#include <assert.h>
    3436#include <errno.h>
    35 #include <str_error.h>
    3637#include <macros.h>
     38#include <mem.h>
     39#include <stdbool.h>
    3740
    3841#include <usb/usb.h>
     
    4447
    4548static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t);
    46 /*----------------------------------------------------------------------------*/
     49
    4750/** Safely destructs ohci_transfer_batch_t structure
    4851 *
     
    6770        free(ohci_batch);
    6871}
    69 /*----------------------------------------------------------------------------*/
     72
    7073/** Finishes usb_transfer_batch and destroys the structure.
    7174 *
     
    8083        ohci_transfer_batch_dispose(ohci_batch);
    8184}
    82 /*----------------------------------------------------------------------------*/
     85
    8386/** Allocate memory and initialize internal data structure.
    8487 *
     
    158161#undef CHECK_NULL_DISPOSE_RET
    159162}
    160 /*----------------------------------------------------------------------------*/
     163
    161164/** Check batch TDs' status.
    162165 *
     
    199202                    ohci_batch->tds[i]->next, ohci_batch->tds[i]->be);
    200203
    201                 /* If the TD got all its data through, it will report 0 bytes
    202                  * remain, the sole exception is INPUT with data rounding flag
    203                  * (short), i.e. every INPUT. Nice thing is that short packets
    204                  * will correctly report remaining data, thus making
    205                  * this computation correct (short packets need to be produced
    206                  * by the last TD)
    207                  * NOTE: This also works for CONTROL transfer as
    208                  * the first TD will return 0 remain.
    209                  * NOTE: Short packets don't break the assumption that
    210                  * we leave the very last(unused) TD behind.
    211                  */
    212                 ohci_batch->usb_batch->transfered_size
    213                     -= td_remain_size(ohci_batch->tds[i]);
    214 
    215204                ohci_batch->usb_batch->error = td_error(ohci_batch->tds[i]);
    216                 if (ohci_batch->usb_batch->error != EOK) {
     205                if (ohci_batch->usb_batch->error == EOK) {
     206                        /* If the TD got all its data through, it will report
     207                         * 0 bytes remain, the sole exception is INPUT with
     208                         * data rounding flag (short), i.e. every INPUT.
     209                         * Nice thing is that short packets will correctly
     210                         * report remaining data, thus making this computation
     211                         * correct (short packets need to be produced by the
     212                         * last TD)
     213                         * NOTE: This also works for CONTROL transfer as
     214                         * the first TD will return 0 remain.
     215                         * NOTE: Short packets don't break the assumption that
     216                         * we leave the very last(unused) TD behind.
     217                         */
     218                        ohci_batch->usb_batch->transfered_size
     219                            -= td_remain_size(ohci_batch->tds[i]);
     220                } else {
    217221                        usb_log_debug("Batch %p found error TD(%zu):%08x.\n",
    218222                            ohci_batch->usb_batch, i,
     
    231235
    232236                        /* Check TD assumption */
    233                         const uint32_t pa =
    234                             addr_to_phys(ohci_batch->tds[leave_td]);
    235                         assert((ohci_batch->ed->td_head & ED_TDHEAD_PTR_MASK)
    236                             == pa);
    237 
     237                        assert(ed_head_td(ohci_batch->ed) ==
     238                            addr_to_phys(ohci_batch->tds[leave_td]));
     239
     240                        /* Set tail to the same TD */
    238241                        ed_set_tail_td(ohci_batch->ed,
    239242                            ohci_batch->tds[leave_td]);
    240243
    241244                        /* Clear possible ED HALT */
    242                         ohci_batch->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG;
     245                        ed_clear_halt(ohci_batch->ed);
    243246                        break;
    244247                }
     
    253256
    254257        /* Make sure that we are leaving the right TD behind */
    255         const uint32_t pa = addr_to_phys(ohci_ep->td);
    256         assert(pa == (ohci_batch->ed->td_head & ED_TDHEAD_PTR_MASK));
    257         assert(pa == (ohci_batch->ed->td_tail & ED_TDTAIL_PTR_MASK));
     258        assert(addr_to_phys(ohci_ep->td) == ed_head_td(ohci_batch->ed));
     259        assert(addr_to_phys(ohci_ep->td) == ed_tail_td(ohci_batch->ed));
    258260
    259261        return true;
    260262}
    261 /*----------------------------------------------------------------------------*/
     263
    262264/** Starts execution of the TD list
    263265 *
     
    269271        ed_set_tail_td(ohci_batch->ed, ohci_batch->tds[ohci_batch->td_count]);
    270272}
    271 /*----------------------------------------------------------------------------*/
     273
    272274/** Prepare generic control transfer
    273275 *
     
    345347            USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch));
    346348}
    347 /*----------------------------------------------------------------------------*/
     349
    348350/** Prepare generic data transfer
    349351 *
     
    392394            USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch));
    393395}
    394 /*----------------------------------------------------------------------------*/
     396
    395397/** Transfer setup table. */
    396398static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t) =
Note: See TracChangeset for help on using the changeset viewer.