Changeset 2fa43d1 in mainline for uspace/drv/bus/usb/xhci/commands.c


Ignore:
Timestamp:
2017-07-24T13:08:00Z (7 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b78a7c1
Parents:
3dc519f
Message:

Command handling is now less error prone as we search the list of commands for such tht has trb physical address equal to that of the command completion event trb. This will protect us from out of order event handling and also from crashes caused by CS/CA events, since those do not have command structs in the list.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/commands.c

    r3dc519f r2fa43d1  
    105105}
    106106
    107 static inline xhci_cmd_t *get_next_command(xhci_hc_t *hc)
     107static inline xhci_cmd_t *get_command(xhci_hc_t *hc, uint64_t phys)
    108108{
    109109        link_t *cmd_link = list_first(&hc->commands);
     110
     111        while (cmd_link != NULL) {
     112                xhci_cmd_t *cmd = list_get_instance(cmd_link, xhci_cmd_t, link);
     113
     114                if (addr_to_phys(cmd->trb) == phys)
     115                        break;
     116
     117                cmd_link = list_next(cmd_link, &hc->commands);
     118        }
    110119
    111120        if (cmd_link != NULL) {
     
    420429        assert(trb);
    421430
    422         // TODO: STOP & ABORT may not have command structs in the list!
    423 
    424431        usb_log_debug("HC(%p) Command completed.", hc);
    425432
    426433        int code;
    427434        uint32_t slot_id;
     435        uint64_t phys;
    428436        xhci_cmd_t *command;
    429437        xhci_trb_t *command_trb;
    430438
    431         command = get_next_command(hc);
    432         assert(command);
     439        code = XHCI_DWORD_EXTRACT(trb->status, 31, 24);
     440        phys = XHCI_QWORD_EXTRACT(trb->parameter, 63, 4) << 4;
     441        command = get_command(hc, phys);
     442        if (command == NULL) {
     443                // TODO: STOP & ABORT may not have command structs in the list!
     444                usb_log_error("No command struct for this completion event");
     445
     446                if (code != XHCI_TRBC_SUCCESS)
     447                        report_error(code);
     448
     449                return EOK;
     450        }
    433451
    434452        command_trb = command->trb;
    435453
    436         code = XHCI_DWORD_EXTRACT(trb->status, 31, 24);
    437454        command->status = code;
    438455
Note: See TracChangeset for help on using the changeset viewer.