Ignore:
File:
1 edited

Legend:

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

    r0d4b110 r9d58539  
    3232 * @brief OHCI driver USB transaction structure
    3333 */
    34 
    35 #include <assert.h>
    3634#include <errno.h>
     35#include <str_error.h>
    3736#include <macros.h>
    38 #include <mem.h>
    39 #include <stdbool.h>
    4037
    4138#include <usb/usb.h>
     
    4744
    4845static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t);
    49 
     46/*----------------------------------------------------------------------------*/
    5047/** Safely destructs ohci_transfer_batch_t structure
    5148 *
     
    7067        free(ohci_batch);
    7168}
    72 
     69/*----------------------------------------------------------------------------*/
    7370/** Finishes usb_transfer_batch and destroys the structure.
    7471 *
     
    8380        ohci_transfer_batch_dispose(ohci_batch);
    8481}
    85 
     82/*----------------------------------------------------------------------------*/
    8683/** Allocate memory and initialize internal data structure.
    8784 *
     
    161158#undef CHECK_NULL_DISPOSE_RET
    162159}
    163 
     160/*----------------------------------------------------------------------------*/
    164161/** Check batch TDs' status.
    165162 *
     
    202199                    ohci_batch->tds[i]->next, ohci_batch->tds[i]->be);
    203200
     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
    204215                ohci_batch->usb_batch->error = td_error(ohci_batch->tds[i]);
    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 {
     216                if (ohci_batch->usb_batch->error != EOK) {
    221217                        usb_log_debug("Batch %p found error TD(%zu):%08x.\n",
    222218                            ohci_batch->usb_batch, i,
     
    235231
    236232                        /* Check TD assumption */
    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 */
     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
    241238                        ed_set_tail_td(ohci_batch->ed,
    242239                            ohci_batch->tds[leave_td]);
    243240
    244241                        /* Clear possible ED HALT */
    245                         ed_clear_halt(ohci_batch->ed);
     242                        ohci_batch->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG;
    246243                        break;
    247244                }
     
    256253
    257254        /* Make sure that we are leaving the right TD behind */
    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));
     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));
    260258
    261259        return true;
    262260}
    263 
     261/*----------------------------------------------------------------------------*/
    264262/** Starts execution of the TD list
    265263 *
     
    271269        ed_set_tail_td(ohci_batch->ed, ohci_batch->tds[ohci_batch->td_count]);
    272270}
    273 
     271/*----------------------------------------------------------------------------*/
    274272/** Prepare generic control transfer
    275273 *
     
    347345            USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch));
    348346}
    349 
     347/*----------------------------------------------------------------------------*/
    350348/** Prepare generic data transfer
    351349 *
     
    394392            USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch));
    395393}
    396 
     394/*----------------------------------------------------------------------------*/
    397395/** Transfer setup table. */
    398396static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t) =
Note: See TracChangeset for help on using the changeset viewer.