Changeset 665bf3c in mainline


Ignore:
Timestamp:
2017-07-13T18:28:19Z (7 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c9ce62a
Parents:
8db42f7
Message:

Added a function that sends the configure endpoint command. Refactored the command completion handling code.

Location:
uspace/drv/bus/usb/xhci
Files:
2 edited

Legend:

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

    r8db42f7 r665bf3c  
    126126}
    127127
     128int xhci_send_configure_endpoint_command(xhci_hc_t *hc, uint32_t slot_id,
     129                                         xhci_input_ctx_t *ictx)
     130{
     131        xhci_trb_t trb;
     132        memset(&trb, 0, sizeof(trb));
     133
     134        uint64_t phys_addr = (uint64_t) addr_to_phys(ictx);
     135        trb.parameter = host2xhci(32, phys_addr & 0xFFFFFFFFFFFFFFF0);
     136
     137        trb.control = host2xhci(32, XHCI_TRB_TYPE_CONFIGURE_ENDPOINT_CMD << 10);
     138        trb.control |= host2xhci(32, hc->command_ring.pcs);
     139        trb.control |= host2xhci(32, slot_id << 24);
     140
     141        return enqueue_trb(hc, &trb, 0, 0);
     142}
     143
     144static int report_error(int code)
     145{
     146        // TODO: Order these by their value.
     147        switch (code) {
     148        case XHCI_TRBC_NO_SLOTS_ERROR:
     149                usb_log_error("Device slot not available.");
     150                break;
     151        case XHCI_TRBC_SLOT_NOT_ENABLE_ERROR:
     152                usb_log_error("Slot ID is not enabled.");
     153                break;
     154        case XHCI_TRBC_CONTEXT_STATE_ERROR:
     155                usb_log_error("Slot is not in enabled or default state.");
     156                break;
     157        case XHCI_TRBC_TRANSACTION_ERROR:
     158                usb_log_error("Request to the USB device failed.");
     159                break;
     160        case XHCI_TRBC_BANDWIDTH_ERROR:
     161                usb_log_error("Bandwidth required is not available.");
     162                break;
     163        case XHCI_TRBC_SECONDARY_BANDWIDTH_ERROR:
     164                usb_log_error("Bandwidth error encountered in secondary domain.");
     165                break;
     166        case XHCI_TRBC_RESOURCE_ERROR:
     167                usb_log_error("Resource required is not available.");
     168                break;
     169        case XHCI_TRBC_PARAMETER_ERROR:
     170                usb_log_error("Parameter given is invalid.");
     171                break;
     172        default:
     173                usb_log_error("Unknown error code.");
     174                break;
     175        }
     176        return ENAK;
     177}
     178
    128179int xhci_handle_command_completion(xhci_hc_t *hc, xhci_trb_t *trb)
    129180{
     
    138189        command = (xhci_trb_t *) XHCI_QWORD_EXTRACT(trb->parameter, 63, 4);
    139190        slot_id = XHCI_DWORD_EXTRACT(trb->control, 31, 24);
    140         (void) slot_id;
     191
     192        if (TRB_TYPE(*command) != XHCI_TRB_TYPE_NO_OP_CMD) {
     193                if (code != XHCI_TRBC_SUCCESS) {
     194                        usb_log_debug2("Command resulted in failure.");
     195                        xhci_dump_trb(command);
     196                }
     197        }
    141198
    142199        switch (TRB_TYPE(*command)) {
    143200        case XHCI_TRB_TYPE_NO_OP_CMD:
    144                 assert(code == XHCI_TRBC_TRB_ERROR);
    145                 break;
     201                assert(code = XHCI_TRBC_TRB_ERROR);
     202                return EOK;
    146203        case XHCI_TRB_TYPE_ENABLE_SLOT_CMD:
    147                 // TODO: Call a device addition callback once it's implemented.
    148                 break;
     204                return EOK;
    149205        case XHCI_TRB_TYPE_DISABLE_SLOT_CMD:
    150                 if (code == XHCI_TRBC_SLOT_NOT_ENABLED_ERROR)
    151                         usb_log_debug2("Slot ID to be disabled was not enabled.");
    152                 // TODO: Call a device removal callback that will deallocate associated
    153                 //       data structures once it's implemented.
    154                 break;
     206                return EOK;
    155207        case XHCI_TRB_TYPE_ADDRESS_DEVICE_CMD:
    156                 if (code == XHCI_TRBC_SLOT_NOT_ENABLED_ERROR)
    157                         usb_log_debug2("Slot to be addressed was not enabled.");
    158                 else if (code == XHCI_TRBC_CONTEXT_STATE_ERROR)
    159                         usb_log_debug2("Slot to be addressed is not in enabled or default state.");
    160                 else if (code == XHCI_TRBC_USB_TRANSACTION_ERROR)
    161                         usb_log_debug2("SET_ADDRESS request to the USB device failed.");
    162                 // TODO: Call set address callback when it's implemented.
    163                 break;
     208                return EOK;
     209        case XHCI_TRB_TYPE_CONFIGURE_ENDPOINT_CMD:
     210                return EOK;
    164211        default:
    165212                usb_log_debug2("Unsupported command trb.");
    166213                xhci_dump_trb(command);
    167                 break;
     214                return ENAK;
    168215        }
    169 
    170         return EOK;
    171216}
    172217
  • uspace/drv/bus/usb/xhci/commands.h

    r8db42f7 r665bf3c  
    4545int xhci_send_disable_slot_command(xhci_hc_t *, uint32_t);
    4646int xhci_send_address_device_command(xhci_hc_t *, uint32_t, xhci_input_ctx_t *);
     47int xhci_send_configure_endpoint_command(xhci_hc_t *, uint32_t, xhci_input_ctx_t *);
    4748
    4849int xhci_handle_command_completion(xhci_hc_t *, xhci_trb_t *);
Note: See TracChangeset for help on using the changeset viewer.