/* Create the descriptor for port with the highest revision */ for (i = 0; i < xhci->num_port_caps; i++) {
u8 major = xhci->port_caps[i].maj_rev;
u8 minor = xhci->port_caps[i].min_rev;
u16 rev = (major << 8) | minor;
if (i == 0 || bcdUSB < rev) {
bcdUSB = rev;
port_cap = &xhci->port_caps[i];
}
}
if (bcdUSB >= 0x0310) { if (port_cap->psi_count) {
u8 num_sym_ssa = 0;
for (i = 0; i < port_cap->psi_count; i++) { if ((port_cap->psi[i] & PLT_MASK) == PLT_SYM)
num_sym_ssa++;
}
desc->bNbrPorts = ports;
temp = 0; /* Bits 1:0 - support per-port power switching, or power always on */ if (HCC_PPC(xhci->hcc_params))
temp |= HUB_CHAR_INDV_PORT_LPSM; else
temp |= HUB_CHAR_NO_LPSM; /* Bit 2 - root hubs are not part of a compound device */ /* Bits 4:3 - individual port over current protection */
temp |= HUB_CHAR_INDV_PORT_OCPM; /* Bits 6:5 - no TTs in root ports */ /* Bit 7 - no port indicators */
desc->wHubCharacteristics = cpu_to_le16(temp);
}
/* Fill in the USB 2.0 roothub descriptor */ staticvoid xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, struct usb_hub_descriptor *desc)
{ int ports;
u16 temp;
__u8 port_removable[(USB_MAXCHILDREN + 1 + 7) / 8];
u32 portsc; unsignedint i; struct xhci_hub *rhub;
/* The Device Removable bits are reported on a byte granularity. *Iftheportdoesn'texistwithinthatbyte,thebitissetto0.
*/
memset(port_removable, 0, sizeof(port_removable)); for (i = 0; i < ports; i++) {
portsc = readl(rhub->ports[i]->addr); /* If a device is removable, PORTSC reports a 0, same as in the *hubdescriptorDeviceRemovablebits.
*/ if (portsc & PORT_DEV_REMOVE) /* This math is hairy because bit 0 of DeviceRemovable *isreserved,andbit1isforport1,etc.
*/
port_removable[(i + 1) / 8] |= 1 << ((i + 1) % 8);
}
/* ch11.h defines a hub descriptor that has room for USB_MAXCHILDREN *portsonit.TheUSB2.0specificationsaysthattherearetwo *variablelengthfieldsattheendofthehubdescriptor: *DeviceRemovableandPortPwrCtrlMask.Butsincewecanhavelessthan *USB_MAXCHILDRENports,wemayneedtousetheDeviceRemovablearray *tosetPortPwrCtrlMaskbits.PortPwrCtrlMaskmustalwaysbesetto *0xFF,soweinitializethebotharrays(DeviceRemovableand *PortPwrCtrlMask)to0xFF.ThenwesettheDeviceRemovableforeach *setofportsthatactuallyexist.
*/
memset(desc->u.hs.DeviceRemovable, 0xff, sizeof(desc->u.hs.DeviceRemovable));
memset(desc->u.hs.PortPwrCtrlMask, 0xff, sizeof(desc->u.hs.PortPwrCtrlMask));
for (i = 0; i < (ports + 1 + 7) / 8; i++)
memset(&desc->u.hs.DeviceRemovable[i], port_removable[i], sizeof(__u8));
}
/* Fill in the USB 3.0 roothub descriptor */ staticvoid xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, struct usb_hub_descriptor *desc)
{ int ports;
u16 port_removable;
u32 portsc; unsignedint i; struct xhci_hub *rhub;
rhub = &xhci->usb3_rhub;
ports = rhub->num_ports;
xhci_common_hub_descriptor(xhci, desc, ports);
desc->bDescriptorType = USB_DT_SS_HUB;
desc->bDescLength = USB_DT_SS_HUB_SIZE;
desc->bPwrOn2PwrGood = 50; /* usb 3.1 may fail if less than 100ms */
/* header decode latency should be zero for roothubs, *seesection4.23.5.2.
*/
desc->u.ss.bHubHdrDecLat = 0;
desc->u.ss.wHubDelay = 0;
port_removable = 0; /* bit 0 is reserved, bit 1 is for port 1, etc. */ for (i = 0; i < ports; i++) {
portsc = readl(rhub->ports[i]->addr); if (portsc & PORT_DEV_REMOVE)
port_removable |= 1 << (i + 1);
}
u32 xhci_port_state_to_neutral(u32 state)
{ /* Save read-only status and port state */ return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS);
}
EXPORT_SYMBOL_GPL(xhci_port_state_to_neutral);
/* *Stopdevice *ItissuesstopendpointcommandforEP0to30.Andwaitthelastcommand *tocomplete. *suspendwillsetto1,ifsuspendbitneedtosetincommand.
*/ staticint xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
{ struct xhci_virt_device *virt_dev; struct xhci_command *cmd; unsignedlong flags; int ret; int i;
ret = 0;
virt_dev = xhci->devs[slot_id]; if (!virt_dev) return -ENODEV;
trace_xhci_stop_device(virt_dev);
cmd = xhci_alloc_command(xhci, true, GFP_NOIO); if (!cmd) return -ENOMEM;
spin_lock_irqsave(&xhci->lock, flags); for (i = LAST_EP_INDEX; i > 0; i--) { if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { struct xhci_ep_ctx *ep_ctx; struct xhci_command *command;
/* *Ringdevice,itringsthealldoorbellsunconditionally.
*/ void xhci_ring_device(struct xhci_hcd *xhci, int slot_id)
{ int i, s; struct xhci_virt_ep *ep;
for (i = 0; i < LAST_EP_INDEX + 1; i++) {
ep = &xhci->devs[slot_id]->eps[i];
if (ep->ep_state & EP_HAS_STREAMS) { for (s = 1; s < ep->stream_info->num_streams; s++)
xhci_ring_ep_doorbell(xhci, slot_id, i, s);
} elseif (ep->ring && ep->ring->dequeue) {
xhci_ring_ep_doorbell(xhci, slot_id, i, 0);
}
}
/* Don't allow the USB core to disable SuperSpeed ports. */ if (hcd->speed >= HCD_USB3) {
xhci_dbg(xhci, "Ignoring request to disable SuperSpeed port.\n"); return;
}
if (xhci->quirks & XHCI_BROKEN_PORT_PED) {
xhci_dbg(xhci, "Broken Port Enabled/Disabled, ignoring port disable request.\n"); return;
}
switch (wValue) { case USB_PORT_FEAT_C_RESET:
status = PORT_RC;
port_change_bit = "reset"; break; case USB_PORT_FEAT_C_BH_PORT_RESET:
status = PORT_WRC;
port_change_bit = "warm(BH) reset"; break; case USB_PORT_FEAT_C_CONNECTION:
status = PORT_CSC;
port_change_bit = "connect"; break; case USB_PORT_FEAT_C_OVER_CURRENT:
status = PORT_OCC;
port_change_bit = "over-current"; break; case USB_PORT_FEAT_C_ENABLE:
status = PORT_PEC;
port_change_bit = "enable/disable"; break; case USB_PORT_FEAT_C_SUSPEND:
status = PORT_PLC;
port_change_bit = "suspend/resume"; break; case USB_PORT_FEAT_C_PORT_LINK_STATE:
status = PORT_PLC;
port_change_bit = "link state"; break; case USB_PORT_FEAT_C_PORT_CONFIG_ERROR:
status = PORT_CEC;
port_change_bit = "config error"; break; default: /* Should never happen */ return;
} /* Change bits are all write 1 to clear */
writel(port_status | status, addr);
port_status = readl(addr);
/* xhci only supports test mode for usb2 ports */
port = xhci->usb2_rhub.ports[wIndex];
temp = readl(port->addr + PORTPMSC);
temp |= test_mode << PORT_TEST_MODE_SHIFT;
writel(temp, port->addr + PORTPMSC);
xhci->test_mode = test_mode; if (test_mode == USB_TEST_FORCE_ENABLE)
xhci_start(xhci);
}
staticint xhci_enter_test_mode(struct xhci_hcd *xhci,
u16 test_mode, u16 wIndex, unsignedlong *flags)
__must_hold(&xhci->lock)
{ int i, retval;
/* Disable all Device Slots */
xhci_dbg(xhci, "Disable all slots\n");
spin_unlock_irqrestore(&xhci->lock, *flags); for (i = 1; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { if (!xhci->devs[i]) continue;
retval = xhci_disable_and_free_slot(xhci, i); if (retval)
xhci_err(xhci, "Failed to disable slot %d, %d. Enter test mode anyway\n",
i, retval);
}
spin_lock_irqsave(&xhci->lock, *flags); /* Put all ports to the Disable state by clear PP */
xhci_dbg(xhci, "Disable all port (PP = 0)\n"); /* Power off USB3 ports*/ for (i = 0; i < xhci->usb3_rhub.num_ports; i++)
xhci_set_port_power(xhci, xhci->usb3_rhub.ports[i], false, flags); /* Power off USB2 ports*/ for (i = 0; i < xhci->usb2_rhub.num_ports; i++)
xhci_set_port_power(xhci, xhci->usb2_rhub.ports[i], false, flags); /* Stop the controller */
xhci_dbg(xhci, "Stop controller\n");
retval = xhci_halt(xhci); if (retval) return retval; /* Disable runtime PM for test mode */
pm_runtime_forbid(xhci_to_hcd(xhci)->self.controller); /* Set PORTPMSC.PTC field to enter selected test mode */ /* Port is selected by wIndex. port_id = wIndex + 1 */
xhci_dbg(xhci, "Enter Test Mode: %d, Port_id=%d\n",
test_mode, wIndex + 1);
xhci_port_set_test_mode(xhci, test_mode, wIndex); return retval;
}
staticint xhci_exit_test_mode(struct xhci_hcd *xhci)
{ int retval;
if (!xhci->test_mode) {
xhci_err(xhci, "Not in test mode, do nothing.\n"); return0;
} if (xhci->test_mode == USB_TEST_FORCE_ENABLE &&
!(xhci->xhc_state & XHCI_STATE_HALTED)) {
retval = xhci_halt(xhci); if (retval) return retval;
}
pm_runtime_allow(xhci_to_hcd(xhci)->self.controller);
xhci->test_mode = 0; return xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
}
/* Updates Link Status for super Speed port */ staticvoid xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci,
u32 *status, u32 status_reg)
{
u32 pls = status_reg & PORT_PLS_MASK;
/* When the CAS bit is set then warm reset *shouldbeperformedonport
*/ if (status_reg & PORT_CAS) { /* The CAS bit can be set while the port is *inanylinkstate. *OnlyroothubshaveCASbit,sowe *pretendtobeincompliancemode *unlesswe'realreadyincompliance *ortheinactivestate.
*/ if (pls != USB_SS_PORT_LS_COMP_MOD &&
pls != USB_SS_PORT_LS_SS_INACTIVE) {
pls = USB_SS_PORT_LS_COMP_MOD;
} /* Return also connection bit - *hubstatemachineresetsport *whenthisbitisset.
*/
pls |= USB_PORT_STAT_CONNECTION;
} else { /* *ResumestateisanxHCIinternalstate.Donotreportitto *usbcore,instead,pretendtobeU3,thususbcoreknows *it'snotreadyfortransfer.
*/ if (pls == XDEV_RESUME) {
*status |= USB_SS_PORT_LS_U3; return;
}
if ((portsc & PORT_RESET) || !(portsc & PORT_PE)) { return -EINVAL;
} /* did port event handler already start resume timing? */ if (!port->resume_timestamp) { /* If not, maybe we are in a host initiated resume? */ if (test_bit(wIndex, &bus_state->resuming_ports)) { /* Host initiated resume doesn't time the resume *signallingusingresume_done[]. *ItmanuallysetsRESUMEstate,sleeps20ms *andsetsU0state.Thisshouldprobablybe *changed,butnotrightnow.
*/
} else { /* port resume was discovered now and here, *startresumetiming
*/ unsignedlong timeout = jiffies +
msecs_to_jiffies(USB_RESUME_TIMEOUT);
set_bit(wIndex, &bus_state->resuming_ports);
port->resume_timestamp = timeout;
mod_timer(&hcd->rh_timer, timeout);
usb_hcd_start_port_resume(&hcd->self, wIndex);
} /* Has resume been signalled for USB_RESUME_TIME yet? */
} elseif (time_after_eq(jiffies, port->resume_timestamp)) { int time_left;
xhci_dbg(xhci, "resume USB2 port %d-%d\n",
hcd->self.busnum, wIndex + 1);
/* only support rx and tx lane counts of 1 in usb3.1 spec */
speed_id = DEV_PORT_SPEED(raw_port_status);
ext_stat |= speed_id; /* bits 3:0, RX speed id */
ext_stat |= speed_id << 4; /* bits 7:4, TX speed id */
rhub = xhci_get_rhub(hcd);
port = rhub->ports[wIndex];
/* common wPortChange bits */ if (raw_port_status & PORT_CSC)
status |= USB_PORT_STAT_C_CONNECTION << 16; if (raw_port_status & PORT_PEC)
status |= USB_PORT_STAT_C_ENABLE << 16; if ((raw_port_status & PORT_OCC))
status |= USB_PORT_STAT_C_OVERCURRENT << 16; if ((raw_port_status & PORT_RC))
status |= USB_PORT_STAT_C_RESET << 16;
/* common wPortStatus bits */ if (raw_port_status & PORT_CONNECT) {
status |= USB_PORT_STAT_CONNECTION;
status |= xhci_port_speed(raw_port_status);
} if (raw_port_status & PORT_PE)
status |= USB_PORT_STAT_ENABLE; if (raw_port_status & PORT_OC)
status |= USB_PORT_STAT_OVERCURRENT; if (raw_port_status & PORT_RESET)
status |= USB_PORT_STAT_RESET;
/* USB2 and USB3 specific bits, including Port Link State */ if (hcd->speed >= HCD_USB3)
xhci_get_usb3_port_status(port, &status, raw_port_status); else
xhci_get_usb2_port_status(port, &status, raw_port_status,
flags);
if (bus_state->port_c_suspend & (1 << wIndex))
status |= USB_PORT_STAT_C_SUSPEND << 16;
port = ports[portnum1 - 1];
wIndex--;
temp = readl(port->addr); if (temp == ~(u32)0) {
xhci_hc_died(xhci);
retval = -ENODEV; break;
}
temp = xhci_port_state_to_neutral(temp); /* FIXME: What new port features do we need to support? */ switch (wValue) { case USB_PORT_FEAT_SUSPEND:
temp = readl(port->addr); if ((temp & PORT_PLS_MASK) != XDEV_U0) { /* Resume the port to U0 first */
xhci_set_link_state(xhci, port, XDEV_U0);
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(10);
spin_lock_irqsave(&xhci->lock, flags);
} /* In spec software should not attempt to suspend *aportunlesstheportreportsthatitisinthe *enabled(PED=‘1’,PLS<‘3’)state.
*/
temp = readl(port->addr); if ((temp & PORT_PE) == 0 || (temp & PORT_RESET)
|| (temp & PORT_PLS_MASK) >= XDEV_U3) {
xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n",
hcd->self.busnum, portnum1); goto error;
}
if (!port->slot_id) {
xhci_warn(xhci, "slot_id is zero\n"); goto error;
} /* unlock to execute stop endpoint commands */
spin_unlock_irqrestore(&xhci->lock, flags);
xhci_stop_device(xhci, port->slot_id, 1);
spin_lock_irqsave(&xhci->lock, flags);
xhci_set_link_state(xhci, port, XDEV_U3);
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(10); /* wait device to enter */
spin_lock_irqsave(&xhci->lock, flags);
/* Put link in RxDetect (enable port) */ if (link_state == USB_SS_PORT_LS_RX_DETECT) {
xhci_dbg(xhci, "Enable port %d-%d\n",
hcd->self.busnum, portnum1);
xhci_set_link_state(xhci, port, link_state);
temp = readl(port->addr); break;
}
/* *ForxHCI1.1accordingtosection4.19.1.2.4.1a *roothubport'stransitiontocompliancemodeupon *detectingLFPStimeoutmaybecontrolledbyan *ComplianceTransitionEnabled(CTE)flag(not *softwarevisible).Thisflagissetbywriting0xA *toPORTSCPLSfieldwhichwillallowtransitionto *compliancemodethenexttimeLFPStimeoutis *encountered.Awarmresetwillclearit. * *TheCTEflagisonlysupportediftheHCCPARAMS2CTC *flagisset,otherwise,thecompliancesubstateis *automaticallyenteredason1.0andprior.
*/ if (link_state == USB_SS_PORT_LS_COMP_MOD) { if (!HCC2_CTC(xhci->hcc_params2)) {
xhci_dbg(xhci, "CTC flag is 0, port already supports entering compliance mode\n"); break;
}
if ((temp & PORT_CONNECT)) {
xhci_warn(xhci, "Can't set compliance mode when port is connected\n"); goto error;
}
xhci_dbg(xhci, "Enable compliance mode transition for port %d-%d\n",
hcd->self.busnum, portnum1);
xhci_set_link_state(xhci, port, link_state);
temp = readl(port->addr); break;
} /* Port must be enabled */ if (!(temp & PORT_PE)) {
retval = -ENODEV; break;
} /* Can't set port link state above '3' (U3) */ if (link_state > USB_SS_PORT_LS_U3) {
xhci_warn(xhci, "Cannot set port %d-%d link state %d\n",
hcd->self.busnum, portnum1, link_state); goto error;
}
/* For each port, did anything change? If so, set that bit in buf. */ for (i = 0; i < max_ports; i++) {
temp = readl(ports[i]->addr); if (temp == ~(u32)0) {
xhci_hc_died(xhci);
retval = -ENODEV; break;
}
trace_xhci_hub_status_data(ports[i], temp);
if ((temp & mask) != 0 ||
(bus_state->port_c_suspend & 1 << i) ||
(ports[i]->resume_timestamp && time_after_eq(
jiffies, ports[i]->resume_timestamp))) {
buf[(i + 1) / 8] |= 1 << (i + 1) % 8;
status = 1;
} if ((temp & PORT_RC))
reset_change = true; if (temp & PORT_OC)
status = 1;
} if (!status && !reset_change) {
xhci_dbg(xhci, "%s: stopping usb%d port polling\n",
__func__, hcd->self.busnum);
clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
}
spin_unlock_irqrestore(&xhci->lock, flags); return status ? retval : 0;
}
if (time_before(jiffies, bus_state->next_statechange))
msleep(5);
spin_lock_irqsave(&xhci->lock, flags); if (!HCD_HW_ACCESSIBLE(hcd)) {
spin_unlock_irqrestore(&xhci->lock, flags); return -ESHUTDOWN;
}
/* bus specific resume for ports we suspended at bus_suspend */ if (hcd->speed >= HCD_USB3) {
next_state = XDEV_U0;
} else {
next_state = XDEV_RESUME; if (bus_state->bus_suspended) { /* *preventporteventinterruptsfrominterfering *withusb2portresumeprocess
*/
xhci_disable_interrupter(xhci, xhci->interrupters[0]);
disabled_irq = true;
}
}
port_index = max_ports; while (port_index--) {
portsc = readl(ports[port_index]->addr);
/* warm reset CAS limited ports stuck in polling/compliance */ if ((xhci->quirks & XHCI_MISSING_CAS) &&
(hcd->speed >= HCD_USB3) &&
xhci_port_missing_cas_quirk(ports[port_index])) {
xhci_dbg(xhci, "reset stuck port %d-%d\n",
hcd->self.busnum, port_index + 1);
clear_bit(port_index, &bus_state->bus_suspended); continue;
} /* resume if we suspended the link, and it is still suspended */ if (test_bit(port_index, &bus_state->bus_suspended)) switch (portsc & PORT_PLS_MASK) { case XDEV_U3:
portsc = xhci_port_state_to_neutral(portsc);
portsc &= ~PORT_PLS_MASK;
portsc |= PORT_LINK_STROBE | next_state; break; case XDEV_RESUME: /* resume already initiated */ break; default: /* not in a resumable state, ignore it */
clear_bit(port_index,
&bus_state->bus_suspended); break;
} /* disable wake for all ports, write new link state if needed */
portsc &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
writel(portsc, ports[port_index]->addr);
}
/* USB2 specific resume signaling delay and U0 link state transition */ if (hcd->speed < HCD_USB3) { if (bus_state->bus_suspended) {
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(USB_RESUME_TIMEOUT);
spin_lock_irqsave(&xhci->lock, flags);
}
for_each_set_bit(port_index, &bus_state->bus_suspended,
BITS_PER_LONG) { /* Clear PLC to poll it later for U0 transition */
xhci_test_and_clear_bit(xhci, ports[port_index],
PORT_PLC);
xhci_set_link_state(xhci, ports[port_index], XDEV_U0);
}
}
/* poll for U0 link state complete, both USB2 and USB3 */
for_each_set_bit(port_index, &bus_state->bus_suspended, BITS_PER_LONG) {
sret = xhci_handshake(ports[port_index]->addr, PORT_PLC,
PORT_PLC, 10 * 1000); if (sret) {
xhci_warn(xhci, "port %d-%d resume PLC timeout\n",
hcd->self.busnum, port_index + 1); continue;
}
xhci_test_and_clear_bit(xhci, ports[port_index], PORT_PLC); if (ports[port_index]->slot_id)
xhci_ring_device(xhci, ports[port_index]->slot_id);
}
(void) readl(&xhci->op_regs->command);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.