Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * xHCI host controller driver |
| 3 | * |
| 4 | * Copyright (C) 2008 Intel Corp. |
| 5 | * |
| 6 | * Author: Sarah Sharp |
| 7 | * Some code borrowed from the Linux EHCI driver. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | * for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software Foundation, |
| 20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/irq.h> |
| 24 | #include <linux/module.h> |
Sarah Sharp | b0567b3 | 2009-08-07 14:04:36 -0700 | [diff] [blame] | 25 | #include <linux/moduleparam.h> |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 26 | |
| 27 | #include "xhci.h" |
| 28 | |
| 29 | #define DRIVER_AUTHOR "Sarah Sharp" |
| 30 | #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" |
| 31 | |
Sarah Sharp | b0567b3 | 2009-08-07 14:04:36 -0700 | [diff] [blame] | 32 | /* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */ |
| 33 | static int link_quirk; |
| 34 | module_param(link_quirk, int, S_IRUGO | S_IWUSR); |
| 35 | MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB"); |
| 36 | |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 37 | /* TODO: copied from ehci-hcd.c - can this be refactored? */ |
| 38 | /* |
| 39 | * handshake - spin reading hc until handshake completes or fails |
| 40 | * @ptr: address of hc register to be read |
| 41 | * @mask: bits to look at in result of read |
| 42 | * @done: value of those bits when handshake succeeds |
| 43 | * @usec: timeout in microseconds |
| 44 | * |
| 45 | * Returns negative errno, or zero on success |
| 46 | * |
| 47 | * Success happens when the "mask" bits have the specified value (hardware |
| 48 | * handshake done). There are two failure modes: "usec" have passed (major |
| 49 | * hardware flakeout), or the register reads as all-ones (hardware removed). |
| 50 | */ |
| 51 | static int handshake(struct xhci_hcd *xhci, void __iomem *ptr, |
| 52 | u32 mask, u32 done, int usec) |
| 53 | { |
| 54 | u32 result; |
| 55 | |
| 56 | do { |
| 57 | result = xhci_readl(xhci, ptr); |
| 58 | if (result == ~(u32)0) /* card removed */ |
| 59 | return -ENODEV; |
| 60 | result &= mask; |
| 61 | if (result == done) |
| 62 | return 0; |
| 63 | udelay(1); |
| 64 | usec--; |
| 65 | } while (usec > 0); |
| 66 | return -ETIMEDOUT; |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Force HC into halt state. |
| 71 | * |
| 72 | * Disable any IRQs and clear the run/stop bit. |
| 73 | * HC will complete any current and actively pipelined transactions, and |
| 74 | * should halt within 16 microframes of the run/stop bit being cleared. |
| 75 | * Read HC Halted bit in the status register to see when the HC is finished. |
| 76 | * XXX: shouldn't we set HC_STATE_HALT here somewhere? |
| 77 | */ |
| 78 | int xhci_halt(struct xhci_hcd *xhci) |
| 79 | { |
| 80 | u32 halted; |
| 81 | u32 cmd; |
| 82 | u32 mask; |
| 83 | |
| 84 | xhci_dbg(xhci, "// Halt the HC\n"); |
| 85 | /* Disable all interrupts from the host controller */ |
| 86 | mask = ~(XHCI_IRQS); |
| 87 | halted = xhci_readl(xhci, &xhci->op_regs->status) & STS_HALT; |
| 88 | if (!halted) |
| 89 | mask &= ~CMD_RUN; |
| 90 | |
| 91 | cmd = xhci_readl(xhci, &xhci->op_regs->command); |
| 92 | cmd &= mask; |
| 93 | xhci_writel(xhci, cmd, &xhci->op_regs->command); |
| 94 | |
| 95 | return handshake(xhci, &xhci->op_regs->status, |
| 96 | STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Reset a halted HC, and set the internal HC state to HC_STATE_HALT. |
| 101 | * |
| 102 | * This resets pipelines, timers, counters, state machines, etc. |
| 103 | * Transactions will be terminated immediately, and operational registers |
| 104 | * will be set to their defaults. |
| 105 | */ |
| 106 | int xhci_reset(struct xhci_hcd *xhci) |
| 107 | { |
| 108 | u32 command; |
| 109 | u32 state; |
| 110 | |
| 111 | state = xhci_readl(xhci, &xhci->op_regs->status); |
Sarah Sharp | d3512f6 | 2009-07-27 12:03:50 -0700 | [diff] [blame] | 112 | if ((state & STS_HALT) == 0) { |
| 113 | xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); |
| 114 | return 0; |
| 115 | } |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 116 | |
| 117 | xhci_dbg(xhci, "// Reset the HC\n"); |
| 118 | command = xhci_readl(xhci, &xhci->op_regs->command); |
| 119 | command |= CMD_RESET; |
| 120 | xhci_writel(xhci, command, &xhci->op_regs->command); |
| 121 | /* XXX: Why does EHCI set this here? Shouldn't other code do this? */ |
| 122 | xhci_to_hcd(xhci)->state = HC_STATE_HALT; |
| 123 | |
| 124 | return handshake(xhci, &xhci->op_regs->command, CMD_RESET, 0, 250 * 1000); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Stop the HC from processing the endpoint queues. |
| 129 | */ |
| 130 | static void xhci_quiesce(struct xhci_hcd *xhci) |
| 131 | { |
| 132 | /* |
| 133 | * Queues are per endpoint, so we need to disable an endpoint or slot. |
| 134 | * |
| 135 | * To disable a slot, we need to insert a disable slot command on the |
| 136 | * command ring and ring the doorbell. This will also free any internal |
| 137 | * resources associated with the slot (which might not be what we want). |
| 138 | * |
| 139 | * A Release Endpoint command sounds better - doesn't free internal HC |
| 140 | * memory, but removes the endpoints from the schedule and releases the |
| 141 | * bandwidth, disables the doorbells, and clears the endpoint enable |
| 142 | * flag. Usually used prior to a set interface command. |
| 143 | * |
| 144 | * TODO: Implement after command ring code is done. |
| 145 | */ |
| 146 | BUG_ON(!HC_IS_RUNNING(xhci_to_hcd(xhci)->state)); |
| 147 | xhci_dbg(xhci, "Finished quiescing -- code not written yet\n"); |
| 148 | } |
| 149 | |
| 150 | #if 0 |
| 151 | /* Set up MSI-X table for entry 0 (may claim other entries later) */ |
| 152 | static int xhci_setup_msix(struct xhci_hcd *xhci) |
| 153 | { |
| 154 | int ret; |
| 155 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
| 156 | |
| 157 | xhci->msix_count = 0; |
| 158 | /* XXX: did I do this right? ixgbe does kcalloc for more than one */ |
| 159 | xhci->msix_entries = kmalloc(sizeof(struct msix_entry), GFP_KERNEL); |
| 160 | if (!xhci->msix_entries) { |
| 161 | xhci_err(xhci, "Failed to allocate MSI-X entries\n"); |
| 162 | return -ENOMEM; |
| 163 | } |
| 164 | xhci->msix_entries[0].entry = 0; |
| 165 | |
| 166 | ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count); |
| 167 | if (ret) { |
| 168 | xhci_err(xhci, "Failed to enable MSI-X\n"); |
| 169 | goto free_entries; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Pass the xhci pointer value as the request_irq "cookie". |
| 174 | * If more irqs are added, this will need to be unique for each one. |
| 175 | */ |
| 176 | ret = request_irq(xhci->msix_entries[0].vector, &xhci_irq, 0, |
| 177 | "xHCI", xhci_to_hcd(xhci)); |
| 178 | if (ret) { |
| 179 | xhci_err(xhci, "Failed to allocate MSI-X interrupt\n"); |
| 180 | goto disable_msix; |
| 181 | } |
| 182 | xhci_dbg(xhci, "Finished setting up MSI-X\n"); |
| 183 | return 0; |
| 184 | |
| 185 | disable_msix: |
| 186 | pci_disable_msix(pdev); |
| 187 | free_entries: |
| 188 | kfree(xhci->msix_entries); |
| 189 | xhci->msix_entries = NULL; |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | /* XXX: code duplication; can xhci_setup_msix call this? */ |
| 194 | /* Free any IRQs and disable MSI-X */ |
| 195 | static void xhci_cleanup_msix(struct xhci_hcd *xhci) |
| 196 | { |
| 197 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
| 198 | if (!xhci->msix_entries) |
| 199 | return; |
| 200 | |
| 201 | free_irq(xhci->msix_entries[0].vector, xhci); |
| 202 | pci_disable_msix(pdev); |
| 203 | kfree(xhci->msix_entries); |
| 204 | xhci->msix_entries = NULL; |
| 205 | xhci_dbg(xhci, "Finished cleaning up MSI-X\n"); |
| 206 | } |
| 207 | #endif |
| 208 | |
| 209 | /* |
| 210 | * Initialize memory for HCD and xHC (one-time init). |
| 211 | * |
| 212 | * Program the PAGESIZE register, initialize the device context array, create |
| 213 | * device contexts (?), set up a command ring segment (or two?), create event |
| 214 | * ring (one for now). |
| 215 | */ |
| 216 | int xhci_init(struct usb_hcd *hcd) |
| 217 | { |
| 218 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 219 | int retval = 0; |
| 220 | |
| 221 | xhci_dbg(xhci, "xhci_init\n"); |
| 222 | spin_lock_init(&xhci->lock); |
Sarah Sharp | b0567b3 | 2009-08-07 14:04:36 -0700 | [diff] [blame] | 223 | if (link_quirk) { |
| 224 | xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n"); |
| 225 | xhci->quirks |= XHCI_LINK_TRB_QUIRK; |
| 226 | } else { |
| 227 | xhci_dbg(xhci, "xHCI has no QUIRKS\n"); |
| 228 | } |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 229 | retval = xhci_mem_init(xhci, GFP_KERNEL); |
| 230 | xhci_dbg(xhci, "Finished xhci_init\n"); |
| 231 | |
| 232 | return retval; |
| 233 | } |
| 234 | |
| 235 | /* |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 236 | * Called in interrupt context when there might be work |
| 237 | * queued on the event ring |
| 238 | * |
| 239 | * xhci->lock must be held by caller. |
| 240 | */ |
| 241 | static void xhci_work(struct xhci_hcd *xhci) |
| 242 | { |
| 243 | u32 temp; |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 244 | u64 temp_64; |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 245 | |
| 246 | /* |
| 247 | * Clear the op reg interrupt status first, |
| 248 | * so we can receive interrupts from other MSI-X interrupters. |
| 249 | * Write 1 to clear the interrupt status. |
| 250 | */ |
| 251 | temp = xhci_readl(xhci, &xhci->op_regs->status); |
| 252 | temp |= STS_EINT; |
| 253 | xhci_writel(xhci, temp, &xhci->op_regs->status); |
| 254 | /* FIXME when MSI-X is supported and there are multiple vectors */ |
| 255 | /* Clear the MSI-X event interrupt status */ |
| 256 | |
| 257 | /* Acknowledge the interrupt */ |
| 258 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); |
| 259 | temp |= 0x3; |
| 260 | xhci_writel(xhci, temp, &xhci->ir_set->irq_pending); |
| 261 | /* Flush posted writes */ |
| 262 | xhci_readl(xhci, &xhci->ir_set->irq_pending); |
| 263 | |
| 264 | /* FIXME this should be a delayed service routine that clears the EHB */ |
Stephen Rothwell | b7258a4 | 2009-04-29 19:02:47 -0700 | [diff] [blame] | 265 | xhci_handle_event(xhci); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 266 | |
Sarah Sharp | 2d83109 | 2009-07-27 12:03:40 -0700 | [diff] [blame] | 267 | /* Clear the event handler busy flag (RW1C); the event ring should be empty. */ |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 268 | temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); |
Sarah Sharp | 2d83109 | 2009-07-27 12:03:40 -0700 | [diff] [blame] | 269 | xhci_write_64(xhci, temp_64 | ERST_EHB, &xhci->ir_set->erst_dequeue); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 270 | /* Flush posted writes -- FIXME is this necessary? */ |
| 271 | xhci_readl(xhci, &xhci->ir_set->irq_pending); |
| 272 | } |
| 273 | |
| 274 | /*-------------------------------------------------------------------------*/ |
| 275 | |
| 276 | /* |
| 277 | * xHCI spec says we can get an interrupt, and if the HC has an error condition, |
| 278 | * we might get bad data out of the event ring. Section 4.10.2.7 has a list of |
| 279 | * indicators of an event TRB error, but we check the status *first* to be safe. |
| 280 | */ |
| 281 | irqreturn_t xhci_irq(struct usb_hcd *hcd) |
| 282 | { |
| 283 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 284 | u32 temp, temp2; |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 285 | union xhci_trb *trb; |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 286 | |
| 287 | spin_lock(&xhci->lock); |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 288 | trb = xhci->event_ring->dequeue; |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 289 | /* Check if the xHC generated the interrupt, or the irq is shared */ |
| 290 | temp = xhci_readl(xhci, &xhci->op_regs->status); |
| 291 | temp2 = xhci_readl(xhci, &xhci->ir_set->irq_pending); |
Sarah Sharp | fcf8f57 | 2009-07-27 12:04:01 -0700 | [diff] [blame] | 292 | if (temp == 0xffffffff && temp2 == 0xffffffff) |
| 293 | goto hw_died; |
| 294 | |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 295 | if (!(temp & STS_EINT) && !ER_IRQ_PENDING(temp2)) { |
| 296 | spin_unlock(&xhci->lock); |
| 297 | return IRQ_NONE; |
| 298 | } |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 299 | xhci_dbg(xhci, "op reg status = %08x\n", temp); |
| 300 | xhci_dbg(xhci, "ir set irq_pending = %08x\n", temp2); |
| 301 | xhci_dbg(xhci, "Event ring dequeue ptr:\n"); |
| 302 | xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n", |
| 303 | (unsigned long long)xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb), |
| 304 | lower_32_bits(trb->link.segment_ptr), |
| 305 | upper_32_bits(trb->link.segment_ptr), |
| 306 | (unsigned int) trb->link.intr_target, |
| 307 | (unsigned int) trb->link.control); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 308 | |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 309 | if (temp & STS_FATAL) { |
| 310 | xhci_warn(xhci, "WARNING: Host System Error\n"); |
| 311 | xhci_halt(xhci); |
Sarah Sharp | fcf8f57 | 2009-07-27 12:04:01 -0700 | [diff] [blame] | 312 | hw_died: |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 313 | xhci_to_hcd(xhci)->state = HC_STATE_HALT; |
Sarah Sharp | c96a2b8 | 2009-04-29 19:05:40 -0700 | [diff] [blame] | 314 | spin_unlock(&xhci->lock); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 315 | return -ESHUTDOWN; |
| 316 | } |
| 317 | |
| 318 | xhci_work(xhci); |
| 319 | spin_unlock(&xhci->lock); |
| 320 | |
| 321 | return IRQ_HANDLED; |
| 322 | } |
| 323 | |
| 324 | #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 325 | void xhci_event_ring_work(unsigned long arg) |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 326 | { |
| 327 | unsigned long flags; |
| 328 | int temp; |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 329 | u64 temp_64; |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 330 | struct xhci_hcd *xhci = (struct xhci_hcd *) arg; |
| 331 | int i, j; |
| 332 | |
| 333 | xhci_dbg(xhci, "Poll event ring: %lu\n", jiffies); |
| 334 | |
| 335 | spin_lock_irqsave(&xhci->lock, flags); |
| 336 | temp = xhci_readl(xhci, &xhci->op_regs->status); |
| 337 | xhci_dbg(xhci, "op reg status = 0x%x\n", temp); |
| 338 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); |
| 339 | xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp); |
| 340 | xhci_dbg(xhci, "No-op commands handled = %d\n", xhci->noops_handled); |
| 341 | xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask); |
| 342 | xhci->error_bitmask = 0; |
| 343 | xhci_dbg(xhci, "Event ring:\n"); |
| 344 | xhci_debug_segment(xhci, xhci->event_ring->deq_seg); |
| 345 | xhci_dbg_ring_ptrs(xhci, xhci->event_ring); |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 346 | temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); |
| 347 | temp_64 &= ~ERST_PTR_MASK; |
| 348 | xhci_dbg(xhci, "ERST deq = 64'h%0lx\n", (long unsigned int) temp_64); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 349 | xhci_dbg(xhci, "Command ring:\n"); |
| 350 | xhci_debug_segment(xhci, xhci->cmd_ring->deq_seg); |
| 351 | xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); |
| 352 | xhci_dbg_cmd_ptrs(xhci); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 353 | for (i = 0; i < MAX_HC_SLOTS; ++i) { |
| 354 | if (xhci->devs[i]) { |
| 355 | for (j = 0; j < 31; ++j) { |
| 356 | if (xhci->devs[i]->ep_rings[j]) { |
| 357 | xhci_dbg(xhci, "Dev %d endpoint ring %d:\n", i, j); |
| 358 | xhci_debug_segment(xhci, xhci->devs[i]->ep_rings[j]->deq_seg); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | } |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 363 | |
| 364 | if (xhci->noops_submitted != NUM_TEST_NOOPS) |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 365 | if (xhci_setup_one_noop(xhci)) |
| 366 | xhci_ring_cmd_db(xhci); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 367 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 368 | |
| 369 | if (!xhci->zombie) |
| 370 | mod_timer(&xhci->event_ring_timer, jiffies + POLL_TIMEOUT * HZ); |
| 371 | else |
| 372 | xhci_dbg(xhci, "Quit polling the event ring.\n"); |
| 373 | } |
| 374 | #endif |
| 375 | |
| 376 | /* |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 377 | * Start the HC after it was halted. |
| 378 | * |
| 379 | * This function is called by the USB core when the HC driver is added. |
| 380 | * Its opposite is xhci_stop(). |
| 381 | * |
| 382 | * xhci_init() must be called once before this function can be called. |
| 383 | * Reset the HC, enable device slot contexts, program DCBAAP, and |
| 384 | * set command ring pointer and event ring pointer. |
| 385 | * |
| 386 | * Setup MSI-X vectors and enable interrupts. |
| 387 | */ |
| 388 | int xhci_run(struct usb_hcd *hcd) |
| 389 | { |
| 390 | u32 temp; |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 391 | u64 temp_64; |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 392 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 393 | void (*doorbell)(struct xhci_hcd *) = NULL; |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 394 | |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 395 | hcd->uses_new_polling = 1; |
| 396 | hcd->poll_rh = 0; |
| 397 | |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 398 | xhci_dbg(xhci, "xhci_run\n"); |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 399 | #if 0 /* FIXME: MSI not setup yet */ |
| 400 | /* Do this at the very last minute */ |
| 401 | ret = xhci_setup_msix(xhci); |
| 402 | if (!ret) |
| 403 | return ret; |
| 404 | |
| 405 | return -ENOSYS; |
| 406 | #endif |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 407 | #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING |
| 408 | init_timer(&xhci->event_ring_timer); |
| 409 | xhci->event_ring_timer.data = (unsigned long) xhci; |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 410 | xhci->event_ring_timer.function = xhci_event_ring_work; |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 411 | /* Poll the event ring */ |
| 412 | xhci->event_ring_timer.expires = jiffies + POLL_TIMEOUT * HZ; |
| 413 | xhci->zombie = 0; |
| 414 | xhci_dbg(xhci, "Setting event ring polling timer\n"); |
| 415 | add_timer(&xhci->event_ring_timer); |
| 416 | #endif |
| 417 | |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 418 | xhci_dbg(xhci, "Command ring memory map follows:\n"); |
| 419 | xhci_debug_ring(xhci, xhci->cmd_ring); |
| 420 | xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); |
| 421 | xhci_dbg_cmd_ptrs(xhci); |
| 422 | |
| 423 | xhci_dbg(xhci, "ERST memory map follows:\n"); |
| 424 | xhci_dbg_erst(xhci, &xhci->erst); |
| 425 | xhci_dbg(xhci, "Event ring:\n"); |
| 426 | xhci_debug_ring(xhci, xhci->event_ring); |
| 427 | xhci_dbg_ring_ptrs(xhci, xhci->event_ring); |
| 428 | temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); |
| 429 | temp_64 &= ~ERST_PTR_MASK; |
| 430 | xhci_dbg(xhci, "ERST deq = 64'h%0lx\n", (long unsigned int) temp_64); |
| 431 | |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 432 | xhci_dbg(xhci, "// Set the interrupt modulation register\n"); |
| 433 | temp = xhci_readl(xhci, &xhci->ir_set->irq_control); |
Sarah Sharp | a4d8830 | 2009-05-14 11:44:26 -0700 | [diff] [blame] | 434 | temp &= ~ER_IRQ_INTERVAL_MASK; |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 435 | temp |= (u32) 160; |
| 436 | xhci_writel(xhci, temp, &xhci->ir_set->irq_control); |
| 437 | |
| 438 | /* Set the HCD state before we enable the irqs */ |
| 439 | hcd->state = HC_STATE_RUNNING; |
| 440 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
| 441 | temp |= (CMD_EIE); |
| 442 | xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n", |
| 443 | temp); |
| 444 | xhci_writel(xhci, temp, &xhci->op_regs->command); |
| 445 | |
| 446 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 447 | xhci_dbg(xhci, "// Enabling event ring interrupter %p by writing 0x%x to irq_pending\n", |
| 448 | xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 449 | xhci_writel(xhci, ER_IRQ_ENABLE(temp), |
| 450 | &xhci->ir_set->irq_pending); |
| 451 | xhci_print_ir_set(xhci, xhci->ir_set, 0); |
| 452 | |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 453 | if (NUM_TEST_NOOPS > 0) |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 454 | doorbell = xhci_setup_one_noop(xhci); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 455 | |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 456 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
| 457 | temp |= (CMD_RUN); |
| 458 | xhci_dbg(xhci, "// Turn on HC, cmd = 0x%x.\n", |
| 459 | temp); |
| 460 | xhci_writel(xhci, temp, &xhci->op_regs->command); |
| 461 | /* Flush PCI posted writes */ |
| 462 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 463 | xhci_dbg(xhci, "// @%p = 0x%x\n", &xhci->op_regs->command, temp); |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 464 | if (doorbell) |
| 465 | (*doorbell)(xhci); |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 466 | |
| 467 | xhci_dbg(xhci, "Finished xhci_run\n"); |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Stop xHCI driver. |
| 473 | * |
| 474 | * This function is called by the USB core when the HC driver is removed. |
| 475 | * Its opposite is xhci_run(). |
| 476 | * |
| 477 | * Disable device contexts, disable IRQs, and quiesce the HC. |
| 478 | * Reset the HC, finish any completed transactions, and cleanup memory. |
| 479 | */ |
| 480 | void xhci_stop(struct usb_hcd *hcd) |
| 481 | { |
| 482 | u32 temp; |
| 483 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 484 | |
| 485 | spin_lock_irq(&xhci->lock); |
| 486 | if (HC_IS_RUNNING(hcd->state)) |
| 487 | xhci_quiesce(xhci); |
| 488 | xhci_halt(xhci); |
| 489 | xhci_reset(xhci); |
| 490 | spin_unlock_irq(&xhci->lock); |
| 491 | |
| 492 | #if 0 /* No MSI yet */ |
| 493 | xhci_cleanup_msix(xhci); |
| 494 | #endif |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 495 | #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING |
| 496 | /* Tell the event ring poll function not to reschedule */ |
| 497 | xhci->zombie = 1; |
| 498 | del_timer_sync(&xhci->event_ring_timer); |
| 499 | #endif |
| 500 | |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 501 | xhci_dbg(xhci, "// Disabling event ring interrupts\n"); |
| 502 | temp = xhci_readl(xhci, &xhci->op_regs->status); |
| 503 | xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status); |
| 504 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); |
| 505 | xhci_writel(xhci, ER_IRQ_DISABLE(temp), |
| 506 | &xhci->ir_set->irq_pending); |
| 507 | xhci_print_ir_set(xhci, xhci->ir_set, 0); |
| 508 | |
| 509 | xhci_dbg(xhci, "cleaning up memory\n"); |
| 510 | xhci_mem_cleanup(xhci); |
| 511 | xhci_dbg(xhci, "xhci_stop completed - status = %x\n", |
| 512 | xhci_readl(xhci, &xhci->op_regs->status)); |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Shutdown HC (not bus-specific) |
| 517 | * |
| 518 | * This is called when the machine is rebooting or halting. We assume that the |
| 519 | * machine will be powered off, and the HC's internal state will be reset. |
| 520 | * Don't bother to free memory. |
| 521 | */ |
| 522 | void xhci_shutdown(struct usb_hcd *hcd) |
| 523 | { |
| 524 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 525 | |
| 526 | spin_lock_irq(&xhci->lock); |
| 527 | xhci_halt(xhci); |
| 528 | spin_unlock_irq(&xhci->lock); |
| 529 | |
| 530 | #if 0 |
| 531 | xhci_cleanup_msix(xhci); |
| 532 | #endif |
| 533 | |
| 534 | xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n", |
| 535 | xhci_readl(xhci, &xhci->op_regs->status)); |
| 536 | } |
| 537 | |
Sarah Sharp | 7f84eef | 2009-04-27 19:53:56 -0700 | [diff] [blame] | 538 | /*-------------------------------------------------------------------------*/ |
| 539 | |
Sarah Sharp | d0e96f5a | 2009-04-27 19:58:01 -0700 | [diff] [blame] | 540 | /** |
| 541 | * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and |
| 542 | * HCDs. Find the index for an endpoint given its descriptor. Use the return |
| 543 | * value to right shift 1 for the bitmask. |
| 544 | * |
| 545 | * Index = (epnum * 2) + direction - 1, |
| 546 | * where direction = 0 for OUT, 1 for IN. |
| 547 | * For control endpoints, the IN index is used (OUT index is unused), so |
| 548 | * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2) |
| 549 | */ |
| 550 | unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc) |
| 551 | { |
| 552 | unsigned int index; |
| 553 | if (usb_endpoint_xfer_control(desc)) |
| 554 | index = (unsigned int) (usb_endpoint_num(desc)*2); |
| 555 | else |
| 556 | index = (unsigned int) (usb_endpoint_num(desc)*2) + |
| 557 | (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; |
| 558 | return index; |
| 559 | } |
| 560 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 561 | /* Find the flag for this endpoint (for use in the control context). Use the |
| 562 | * endpoint index to create a bitmask. The slot context is bit 0, endpoint 0 is |
| 563 | * bit 1, etc. |
| 564 | */ |
| 565 | unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc) |
| 566 | { |
| 567 | return 1 << (xhci_get_endpoint_index(desc) + 1); |
| 568 | } |
| 569 | |
| 570 | /* Compute the last valid endpoint context index. Basically, this is the |
| 571 | * endpoint index plus one. For slot contexts with more than valid endpoint, |
| 572 | * we find the most significant bit set in the added contexts flags. |
| 573 | * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000 |
| 574 | * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one. |
| 575 | */ |
| 576 | static inline unsigned int xhci_last_valid_endpoint(u32 added_ctxs) |
| 577 | { |
| 578 | return fls(added_ctxs) - 1; |
| 579 | } |
| 580 | |
Sarah Sharp | d0e96f5a | 2009-04-27 19:58:01 -0700 | [diff] [blame] | 581 | /* Returns 1 if the arguments are OK; |
| 582 | * returns 0 this is a root hub; returns -EINVAL for NULL pointers. |
| 583 | */ |
| 584 | int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev, |
| 585 | struct usb_host_endpoint *ep, int check_ep, const char *func) { |
| 586 | if (!hcd || (check_ep && !ep) || !udev) { |
| 587 | printk(KERN_DEBUG "xHCI %s called with invalid args\n", |
| 588 | func); |
| 589 | return -EINVAL; |
| 590 | } |
| 591 | if (!udev->parent) { |
| 592 | printk(KERN_DEBUG "xHCI %s called for root hub\n", |
| 593 | func); |
| 594 | return 0; |
| 595 | } |
| 596 | if (!udev->slot_id) { |
| 597 | printk(KERN_DEBUG "xHCI %s called with unaddressed device\n", |
| 598 | func); |
| 599 | return -EINVAL; |
| 600 | } |
| 601 | return 1; |
| 602 | } |
| 603 | |
| 604 | /* |
| 605 | * non-error returns are a promise to giveback() the urb later |
| 606 | * we drop ownership so next owner (or urb unlink) can get it |
| 607 | */ |
| 608 | int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) |
| 609 | { |
| 610 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 611 | unsigned long flags; |
| 612 | int ret = 0; |
| 613 | unsigned int slot_id, ep_index; |
| 614 | |
| 615 | if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) |
| 616 | return -EINVAL; |
| 617 | |
| 618 | slot_id = urb->dev->slot_id; |
| 619 | ep_index = xhci_get_endpoint_index(&urb->ep->desc); |
Sarah Sharp | d0e96f5a | 2009-04-27 19:58:01 -0700 | [diff] [blame] | 620 | |
| 621 | spin_lock_irqsave(&xhci->lock, flags); |
| 622 | if (!xhci->devs || !xhci->devs[slot_id]) { |
| 623 | if (!in_interrupt()) |
| 624 | dev_warn(&urb->dev->dev, "WARN: urb submitted for dev with no Slot ID\n"); |
Sarah Sharp | c7959fb | 2009-04-29 19:06:36 -0700 | [diff] [blame] | 625 | ret = -EINVAL; |
| 626 | goto exit; |
Sarah Sharp | d0e96f5a | 2009-04-27 19:58:01 -0700 | [diff] [blame] | 627 | } |
| 628 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { |
| 629 | if (!in_interrupt()) |
| 630 | xhci_dbg(xhci, "urb submitted during PCI suspend\n"); |
| 631 | ret = -ESHUTDOWN; |
| 632 | goto exit; |
| 633 | } |
Sarah Sharp | b10de14 | 2009-04-27 19:58:50 -0700 | [diff] [blame] | 634 | if (usb_endpoint_xfer_control(&urb->ep->desc)) |
Sarah Sharp | b11069f | 2009-07-27 12:03:23 -0700 | [diff] [blame] | 635 | /* We have a spinlock and interrupts disabled, so we must pass |
| 636 | * atomic context to this function, which may allocate memory. |
| 637 | */ |
| 638 | ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 639 | slot_id, ep_index); |
Sarah Sharp | b10de14 | 2009-04-27 19:58:50 -0700 | [diff] [blame] | 640 | else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) |
Sarah Sharp | b11069f | 2009-07-27 12:03:23 -0700 | [diff] [blame] | 641 | ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 642 | slot_id, ep_index); |
Sarah Sharp | b10de14 | 2009-04-27 19:58:50 -0700 | [diff] [blame] | 643 | else |
| 644 | ret = -EINVAL; |
Sarah Sharp | d0e96f5a | 2009-04-27 19:58:01 -0700 | [diff] [blame] | 645 | exit: |
| 646 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 647 | return ret; |
| 648 | } |
| 649 | |
Sarah Sharp | ae63674 | 2009-04-29 19:02:31 -0700 | [diff] [blame] | 650 | /* |
| 651 | * Remove the URB's TD from the endpoint ring. This may cause the HC to stop |
| 652 | * USB transfers, potentially stopping in the middle of a TRB buffer. The HC |
| 653 | * should pick up where it left off in the TD, unless a Set Transfer Ring |
| 654 | * Dequeue Pointer is issued. |
| 655 | * |
| 656 | * The TRBs that make up the buffers for the canceled URB will be "removed" from |
| 657 | * the ring. Since the ring is a contiguous structure, they can't be physically |
| 658 | * removed. Instead, there are two options: |
| 659 | * |
| 660 | * 1) If the HC is in the middle of processing the URB to be canceled, we |
| 661 | * simply move the ring's dequeue pointer past those TRBs using the Set |
| 662 | * Transfer Ring Dequeue Pointer command. This will be the common case, |
| 663 | * when drivers timeout on the last submitted URB and attempt to cancel. |
| 664 | * |
| 665 | * 2) If the HC is in the middle of a different TD, we turn the TRBs into a |
| 666 | * series of 1-TRB transfer no-op TDs. (No-ops shouldn't be chained.) The |
| 667 | * HC will need to invalidate the any TRBs it has cached after the stop |
| 668 | * endpoint command, as noted in the xHCI 0.95 errata. |
| 669 | * |
| 670 | * 3) The TD may have completed by the time the Stop Endpoint Command |
| 671 | * completes, so software needs to handle that case too. |
| 672 | * |
| 673 | * This function should protect against the TD enqueueing code ringing the |
| 674 | * doorbell while this code is waiting for a Stop Endpoint command to complete. |
| 675 | * It also needs to account for multiple cancellations on happening at the same |
| 676 | * time for the same endpoint. |
| 677 | * |
| 678 | * Note that this function can be called in any context, or so says |
| 679 | * usb_hcd_unlink_urb() |
Sarah Sharp | d0e96f5a | 2009-04-27 19:58:01 -0700 | [diff] [blame] | 680 | */ |
| 681 | int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
| 682 | { |
Sarah Sharp | ae63674 | 2009-04-29 19:02:31 -0700 | [diff] [blame] | 683 | unsigned long flags; |
| 684 | int ret; |
| 685 | struct xhci_hcd *xhci; |
| 686 | struct xhci_td *td; |
| 687 | unsigned int ep_index; |
| 688 | struct xhci_ring *ep_ring; |
| 689 | |
| 690 | xhci = hcd_to_xhci(hcd); |
| 691 | spin_lock_irqsave(&xhci->lock, flags); |
| 692 | /* Make sure the URB hasn't completed or been unlinked already */ |
| 693 | ret = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 694 | if (ret || !urb->hcpriv) |
| 695 | goto done; |
| 696 | |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 697 | xhci_dbg(xhci, "Cancel URB %p\n", urb); |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 698 | xhci_dbg(xhci, "Event ring:\n"); |
| 699 | xhci_debug_ring(xhci, xhci->event_ring); |
Sarah Sharp | ae63674 | 2009-04-29 19:02:31 -0700 | [diff] [blame] | 700 | ep_index = xhci_get_endpoint_index(&urb->ep->desc); |
| 701 | ep_ring = xhci->devs[urb->dev->slot_id]->ep_rings[ep_index]; |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 702 | xhci_dbg(xhci, "Endpoint ring:\n"); |
| 703 | xhci_debug_ring(xhci, ep_ring); |
Sarah Sharp | ae63674 | 2009-04-29 19:02:31 -0700 | [diff] [blame] | 704 | td = (struct xhci_td *) urb->hcpriv; |
| 705 | |
| 706 | ep_ring->cancels_pending++; |
| 707 | list_add_tail(&td->cancelled_td_list, &ep_ring->cancelled_td_list); |
| 708 | /* Queue a stop endpoint command, but only if this is |
| 709 | * the first cancellation to be handled. |
| 710 | */ |
| 711 | if (ep_ring->cancels_pending == 1) { |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 712 | xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index); |
| 713 | xhci_ring_cmd_db(xhci); |
Sarah Sharp | ae63674 | 2009-04-29 19:02:31 -0700 | [diff] [blame] | 714 | } |
| 715 | done: |
| 716 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 717 | return ret; |
Sarah Sharp | d0e96f5a | 2009-04-27 19:58:01 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 720 | /* Drop an endpoint from a new bandwidth configuration for this device. |
| 721 | * Only one call to this function is allowed per endpoint before |
| 722 | * check_bandwidth() or reset_bandwidth() must be called. |
| 723 | * A call to xhci_drop_endpoint() followed by a call to xhci_add_endpoint() will |
| 724 | * add the endpoint to the schedule with possibly new parameters denoted by a |
| 725 | * different endpoint descriptor in usb_host_endpoint. |
| 726 | * A call to xhci_add_endpoint() followed by a call to xhci_drop_endpoint() is |
| 727 | * not allowed. |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 728 | * |
| 729 | * The USB core will not allow URBs to be queued to an endpoint that is being |
| 730 | * disabled, so there's no need for mutual exclusion to protect |
| 731 | * the xhci->devs[slot_id] structure. |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 732 | */ |
| 733 | int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, |
| 734 | struct usb_host_endpoint *ep) |
| 735 | { |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 736 | struct xhci_hcd *xhci; |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 737 | struct xhci_container_ctx *in_ctx, *out_ctx; |
| 738 | struct xhci_input_control_ctx *ctrl_ctx; |
| 739 | struct xhci_slot_ctx *slot_ctx; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 740 | unsigned int last_ctx; |
| 741 | unsigned int ep_index; |
| 742 | struct xhci_ep_ctx *ep_ctx; |
| 743 | u32 drop_flag; |
| 744 | u32 new_add_flags, new_drop_flags, new_slot_info; |
| 745 | int ret; |
| 746 | |
| 747 | ret = xhci_check_args(hcd, udev, ep, 1, __func__); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 748 | if (ret <= 0) |
| 749 | return ret; |
| 750 | xhci = hcd_to_xhci(hcd); |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 751 | xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 752 | |
| 753 | drop_flag = xhci_get_endpoint_flag(&ep->desc); |
| 754 | if (drop_flag == SLOT_FLAG || drop_flag == EP0_FLAG) { |
| 755 | xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", |
| 756 | __func__, drop_flag); |
| 757 | return 0; |
| 758 | } |
| 759 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 760 | if (!xhci->devs || !xhci->devs[udev->slot_id]) { |
| 761 | xhci_warn(xhci, "xHCI %s called with unaddressed device\n", |
| 762 | __func__); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 763 | return -EINVAL; |
| 764 | } |
| 765 | |
| 766 | in_ctx = xhci->devs[udev->slot_id]->in_ctx; |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 767 | out_ctx = xhci->devs[udev->slot_id]->out_ctx; |
| 768 | ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 769 | ep_index = xhci_get_endpoint_index(&ep->desc); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 770 | ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 771 | /* If the HC already knows the endpoint is disabled, |
| 772 | * or the HCD has noted it is disabled, ignore this request |
| 773 | */ |
| 774 | if ((ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED || |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 775 | ctrl_ctx->drop_flags & xhci_get_endpoint_flag(&ep->desc)) { |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 776 | xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", |
| 777 | __func__, ep); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 778 | return 0; |
| 779 | } |
| 780 | |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 781 | ctrl_ctx->drop_flags |= drop_flag; |
| 782 | new_drop_flags = ctrl_ctx->drop_flags; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 783 | |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 784 | ctrl_ctx->add_flags = ~drop_flag; |
| 785 | new_add_flags = ctrl_ctx->add_flags; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 786 | |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 787 | last_ctx = xhci_last_valid_endpoint(ctrl_ctx->add_flags); |
| 788 | slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 789 | /* Update the last valid endpoint context, if we deleted the last one */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 790 | if ((slot_ctx->dev_info & LAST_CTX_MASK) > LAST_CTX(last_ctx)) { |
| 791 | slot_ctx->dev_info &= ~LAST_CTX_MASK; |
| 792 | slot_ctx->dev_info |= LAST_CTX(last_ctx); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 793 | } |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 794 | new_slot_info = slot_ctx->dev_info; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 795 | |
| 796 | xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); |
| 797 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 798 | xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", |
| 799 | (unsigned int) ep->desc.bEndpointAddress, |
| 800 | udev->slot_id, |
| 801 | (unsigned int) new_drop_flags, |
| 802 | (unsigned int) new_add_flags, |
| 803 | (unsigned int) new_slot_info); |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* Add an endpoint to a new possible bandwidth configuration for this device. |
| 808 | * Only one call to this function is allowed per endpoint before |
| 809 | * check_bandwidth() or reset_bandwidth() must be called. |
| 810 | * A call to xhci_drop_endpoint() followed by a call to xhci_add_endpoint() will |
| 811 | * add the endpoint to the schedule with possibly new parameters denoted by a |
| 812 | * different endpoint descriptor in usb_host_endpoint. |
| 813 | * A call to xhci_add_endpoint() followed by a call to xhci_drop_endpoint() is |
| 814 | * not allowed. |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 815 | * |
| 816 | * The USB core will not allow URBs to be queued to an endpoint until the |
| 817 | * configuration or alt setting is installed in the device, so there's no need |
| 818 | * for mutual exclusion to protect the xhci->devs[slot_id] structure. |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 819 | */ |
| 820 | int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, |
| 821 | struct usb_host_endpoint *ep) |
| 822 | { |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 823 | struct xhci_hcd *xhci; |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 824 | struct xhci_container_ctx *in_ctx, *out_ctx; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 825 | unsigned int ep_index; |
| 826 | struct xhci_ep_ctx *ep_ctx; |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 827 | struct xhci_slot_ctx *slot_ctx; |
| 828 | struct xhci_input_control_ctx *ctrl_ctx; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 829 | u32 added_ctxs; |
| 830 | unsigned int last_ctx; |
| 831 | u32 new_add_flags, new_drop_flags, new_slot_info; |
| 832 | int ret = 0; |
| 833 | |
| 834 | ret = xhci_check_args(hcd, udev, ep, 1, __func__); |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 835 | if (ret <= 0) { |
| 836 | /* So we won't queue a reset ep command for a root hub */ |
| 837 | ep->hcpriv = NULL; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 838 | return ret; |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 839 | } |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 840 | xhci = hcd_to_xhci(hcd); |
| 841 | |
| 842 | added_ctxs = xhci_get_endpoint_flag(&ep->desc); |
| 843 | last_ctx = xhci_last_valid_endpoint(added_ctxs); |
| 844 | if (added_ctxs == SLOT_FLAG || added_ctxs == EP0_FLAG) { |
| 845 | /* FIXME when we have to issue an evaluate endpoint command to |
| 846 | * deal with ep0 max packet size changing once we get the |
| 847 | * descriptors |
| 848 | */ |
| 849 | xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", |
| 850 | __func__, added_ctxs); |
| 851 | return 0; |
| 852 | } |
| 853 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 854 | if (!xhci->devs || !xhci->devs[udev->slot_id]) { |
| 855 | xhci_warn(xhci, "xHCI %s called with unaddressed device\n", |
| 856 | __func__); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 857 | return -EINVAL; |
| 858 | } |
| 859 | |
| 860 | in_ctx = xhci->devs[udev->slot_id]->in_ctx; |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 861 | out_ctx = xhci->devs[udev->slot_id]->out_ctx; |
| 862 | ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 863 | ep_index = xhci_get_endpoint_index(&ep->desc); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 864 | ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 865 | /* If the HCD has already noted the endpoint is enabled, |
| 866 | * ignore this request. |
| 867 | */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 868 | if (ctrl_ctx->add_flags & xhci_get_endpoint_flag(&ep->desc)) { |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 869 | xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", |
| 870 | __func__, ep); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 874 | /* |
| 875 | * Configuration and alternate setting changes must be done in |
| 876 | * process context, not interrupt context (or so documenation |
| 877 | * for usb_set_interface() and usb_set_configuration() claim). |
| 878 | */ |
| 879 | if (xhci_endpoint_init(xhci, xhci->devs[udev->slot_id], |
| 880 | udev, ep, GFP_KERNEL) < 0) { |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 881 | dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", |
| 882 | __func__, ep->desc.bEndpointAddress); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 883 | return -ENOMEM; |
| 884 | } |
| 885 | |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 886 | ctrl_ctx->add_flags |= added_ctxs; |
| 887 | new_add_flags = ctrl_ctx->add_flags; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 888 | |
| 889 | /* If xhci_endpoint_disable() was called for this endpoint, but the |
| 890 | * xHC hasn't been notified yet through the check_bandwidth() call, |
| 891 | * this re-adds a new state for the endpoint from the new endpoint |
| 892 | * descriptors. We must drop and re-add this endpoint, so we leave the |
| 893 | * drop flags alone. |
| 894 | */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 895 | new_drop_flags = ctrl_ctx->drop_flags; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 896 | |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 897 | slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 898 | /* Update the last valid endpoint context, if we just added one past */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 899 | if ((slot_ctx->dev_info & LAST_CTX_MASK) < LAST_CTX(last_ctx)) { |
| 900 | slot_ctx->dev_info &= ~LAST_CTX_MASK; |
| 901 | slot_ctx->dev_info |= LAST_CTX(last_ctx); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 902 | } |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 903 | new_slot_info = slot_ctx->dev_info; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 904 | |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 905 | /* Store the usb_device pointer for later use */ |
| 906 | ep->hcpriv = udev; |
| 907 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 908 | xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", |
| 909 | (unsigned int) ep->desc.bEndpointAddress, |
| 910 | udev->slot_id, |
| 911 | (unsigned int) new_drop_flags, |
| 912 | (unsigned int) new_add_flags, |
| 913 | (unsigned int) new_slot_info); |
| 914 | return 0; |
| 915 | } |
| 916 | |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 917 | static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev) |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 918 | { |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 919 | struct xhci_input_control_ctx *ctrl_ctx; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 920 | struct xhci_ep_ctx *ep_ctx; |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 921 | struct xhci_slot_ctx *slot_ctx; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 922 | int i; |
| 923 | |
| 924 | /* When a device's add flag and drop flag are zero, any subsequent |
| 925 | * configure endpoint command will leave that endpoint's state |
| 926 | * untouched. Make sure we don't leave any old state in the input |
| 927 | * endpoint contexts. |
| 928 | */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 929 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); |
| 930 | ctrl_ctx->drop_flags = 0; |
| 931 | ctrl_ctx->add_flags = 0; |
| 932 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); |
| 933 | slot_ctx->dev_info &= ~LAST_CTX_MASK; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 934 | /* Endpoint 0 is always valid */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 935 | slot_ctx->dev_info |= LAST_CTX(1); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 936 | for (i = 1; i < 31; ++i) { |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 937 | ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 938 | ep_ctx->ep_info = 0; |
| 939 | ep_ctx->ep_info2 = 0; |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 940 | ep_ctx->deq = 0; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 941 | ep_ctx->tx_info = 0; |
| 942 | } |
| 943 | } |
| 944 | |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 945 | /* Called after one or more calls to xhci_add_endpoint() or |
| 946 | * xhci_drop_endpoint(). If this call fails, the USB core is expected |
| 947 | * to call xhci_reset_bandwidth(). |
| 948 | * |
| 949 | * Since we are in the middle of changing either configuration or |
| 950 | * installing a new alt setting, the USB core won't allow URBs to be |
| 951 | * enqueued for any endpoint on the old config or interface. Nothing |
| 952 | * else should be touching the xhci->devs[slot_id] structure, so we |
| 953 | * don't need to take the xhci->lock for manipulating that. |
| 954 | */ |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 955 | int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) |
| 956 | { |
| 957 | int i; |
| 958 | int ret = 0; |
| 959 | int timeleft; |
| 960 | unsigned long flags; |
| 961 | struct xhci_hcd *xhci; |
| 962 | struct xhci_virt_device *virt_dev; |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 963 | struct xhci_input_control_ctx *ctrl_ctx; |
| 964 | struct xhci_slot_ctx *slot_ctx; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 965 | |
| 966 | ret = xhci_check_args(hcd, udev, NULL, 0, __func__); |
| 967 | if (ret <= 0) |
| 968 | return ret; |
| 969 | xhci = hcd_to_xhci(hcd); |
| 970 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 971 | if (!udev->slot_id || !xhci->devs || !xhci->devs[udev->slot_id]) { |
| 972 | xhci_warn(xhci, "xHCI %s called with unaddressed device\n", |
| 973 | __func__); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 974 | return -EINVAL; |
| 975 | } |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 976 | xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 977 | virt_dev = xhci->devs[udev->slot_id]; |
| 978 | |
| 979 | /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 980 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); |
| 981 | ctrl_ctx->add_flags |= SLOT_FLAG; |
| 982 | ctrl_ctx->add_flags &= ~EP0_FLAG; |
| 983 | ctrl_ctx->drop_flags &= ~SLOT_FLAG; |
| 984 | ctrl_ctx->drop_flags &= ~EP0_FLAG; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 985 | xhci_dbg(xhci, "New Input Control Context:\n"); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 986 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); |
| 987 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, |
| 988 | LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 989 | |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 990 | spin_lock_irqsave(&xhci->lock, flags); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 991 | ret = xhci_queue_configure_endpoint(xhci, virt_dev->in_ctx->dma, |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 992 | udev->slot_id); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 993 | if (ret < 0) { |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 994 | spin_unlock_irqrestore(&xhci->lock, flags); |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 995 | xhci_dbg(xhci, "FIXME allocate a new ring segment\n"); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 996 | return -ENOMEM; |
| 997 | } |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 998 | xhci_ring_cmd_db(xhci); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 999 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1000 | |
| 1001 | /* Wait for the configure endpoint command to complete */ |
| 1002 | timeleft = wait_for_completion_interruptible_timeout( |
| 1003 | &virt_dev->cmd_completion, |
| 1004 | USB_CTRL_SET_TIMEOUT); |
| 1005 | if (timeleft <= 0) { |
| 1006 | xhci_warn(xhci, "%s while waiting for configure endpoint command\n", |
| 1007 | timeleft == 0 ? "Timeout" : "Signal"); |
| 1008 | /* FIXME cancel the configure endpoint command */ |
| 1009 | return -ETIME; |
| 1010 | } |
| 1011 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1012 | switch (virt_dev->cmd_status) { |
| 1013 | case COMP_ENOMEM: |
| 1014 | dev_warn(&udev->dev, "Not enough host controller resources " |
| 1015 | "for new device state.\n"); |
| 1016 | ret = -ENOMEM; |
| 1017 | /* FIXME: can we allocate more resources for the HC? */ |
| 1018 | break; |
| 1019 | case COMP_BW_ERR: |
| 1020 | dev_warn(&udev->dev, "Not enough bandwidth " |
| 1021 | "for new device state.\n"); |
| 1022 | ret = -ENOSPC; |
| 1023 | /* FIXME: can we go back to the old state? */ |
| 1024 | break; |
| 1025 | case COMP_TRB_ERR: |
| 1026 | /* the HCD set up something wrong */ |
| 1027 | dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, add flag = 1, " |
| 1028 | "and endpoint is not disabled.\n"); |
| 1029 | ret = -EINVAL; |
| 1030 | break; |
| 1031 | case COMP_SUCCESS: |
| 1032 | dev_dbg(&udev->dev, "Successful Endpoint Configure command\n"); |
| 1033 | break; |
| 1034 | default: |
| 1035 | xhci_err(xhci, "ERROR: unexpected command completion " |
| 1036 | "code 0x%x.\n", virt_dev->cmd_status); |
| 1037 | ret = -EINVAL; |
| 1038 | break; |
| 1039 | } |
| 1040 | if (ret) { |
| 1041 | /* Callee should call reset_bandwidth() */ |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1042 | return ret; |
| 1043 | } |
| 1044 | |
| 1045 | xhci_dbg(xhci, "Output context after successful config ep cmd:\n"); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1046 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, |
| 1047 | LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1048 | |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1049 | xhci_zero_in_ctx(xhci, virt_dev); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1050 | /* Free any old rings */ |
| 1051 | for (i = 1; i < 31; ++i) { |
| 1052 | if (virt_dev->new_ep_rings[i]) { |
| 1053 | xhci_ring_free(xhci, virt_dev->ep_rings[i]); |
| 1054 | virt_dev->ep_rings[i] = virt_dev->new_ep_rings[i]; |
| 1055 | virt_dev->new_ep_rings[i] = NULL; |
| 1056 | } |
| 1057 | } |
| 1058 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1059 | return ret; |
| 1060 | } |
| 1061 | |
| 1062 | void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) |
| 1063 | { |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1064 | struct xhci_hcd *xhci; |
| 1065 | struct xhci_virt_device *virt_dev; |
| 1066 | int i, ret; |
| 1067 | |
| 1068 | ret = xhci_check_args(hcd, udev, NULL, 0, __func__); |
| 1069 | if (ret <= 0) |
| 1070 | return; |
| 1071 | xhci = hcd_to_xhci(hcd); |
| 1072 | |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1073 | if (!xhci->devs || !xhci->devs[udev->slot_id]) { |
| 1074 | xhci_warn(xhci, "xHCI %s called with unaddressed device\n", |
| 1075 | __func__); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1076 | return; |
| 1077 | } |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 1078 | xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1079 | virt_dev = xhci->devs[udev->slot_id]; |
| 1080 | /* Free any rings allocated for added endpoints */ |
| 1081 | for (i = 0; i < 31; ++i) { |
| 1082 | if (virt_dev->new_ep_rings[i]) { |
| 1083 | xhci_ring_free(xhci, virt_dev->new_ep_rings[i]); |
| 1084 | virt_dev->new_ep_rings[i] = NULL; |
| 1085 | } |
| 1086 | } |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1087 | xhci_zero_in_ctx(xhci, virt_dev); |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 1090 | /* Deal with stalled endpoints. The core should have sent the control message |
| 1091 | * to clear the halt condition. However, we need to make the xHCI hardware |
| 1092 | * reset its sequence number, since a device will expect a sequence number of |
| 1093 | * zero after the halt condition is cleared. |
| 1094 | * Context: in_interrupt |
| 1095 | */ |
| 1096 | void xhci_endpoint_reset(struct usb_hcd *hcd, |
| 1097 | struct usb_host_endpoint *ep) |
| 1098 | { |
| 1099 | struct xhci_hcd *xhci; |
| 1100 | struct usb_device *udev; |
| 1101 | unsigned int ep_index; |
| 1102 | unsigned long flags; |
| 1103 | int ret; |
Sarah Sharp | c92bcfa | 2009-07-27 12:05:21 -0700 | [diff] [blame] | 1104 | struct xhci_dequeue_state deq_state; |
| 1105 | struct xhci_ring *ep_ring; |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 1106 | |
| 1107 | xhci = hcd_to_xhci(hcd); |
| 1108 | udev = (struct usb_device *) ep->hcpriv; |
| 1109 | /* Called with a root hub endpoint (or an endpoint that wasn't added |
| 1110 | * with xhci_add_endpoint() |
| 1111 | */ |
| 1112 | if (!ep->hcpriv) |
| 1113 | return; |
| 1114 | ep_index = xhci_get_endpoint_index(&ep->desc); |
Sarah Sharp | c92bcfa | 2009-07-27 12:05:21 -0700 | [diff] [blame] | 1115 | ep_ring = xhci->devs[udev->slot_id]->ep_rings[ep_index]; |
| 1116 | if (!ep_ring->stopped_td) { |
| 1117 | xhci_dbg(xhci, "Endpoint 0x%x not halted, refusing to reset.\n", |
| 1118 | ep->desc.bEndpointAddress); |
| 1119 | return; |
| 1120 | } |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 1121 | |
| 1122 | xhci_dbg(xhci, "Queueing reset endpoint command\n"); |
| 1123 | spin_lock_irqsave(&xhci->lock, flags); |
| 1124 | ret = xhci_queue_reset_ep(xhci, udev->slot_id, ep_index); |
Sarah Sharp | c92bcfa | 2009-07-27 12:05:21 -0700 | [diff] [blame] | 1125 | /* |
| 1126 | * Can't change the ring dequeue pointer until it's transitioned to the |
| 1127 | * stopped state, which is only upon a successful reset endpoint |
| 1128 | * command. Better hope that last command worked! |
| 1129 | */ |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 1130 | if (!ret) { |
Sarah Sharp | c92bcfa | 2009-07-27 12:05:21 -0700 | [diff] [blame] | 1131 | xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n"); |
| 1132 | /* We need to move the HW's dequeue pointer past this TD, |
| 1133 | * or it will attempt to resend it on the next doorbell ring. |
| 1134 | */ |
| 1135 | xhci_find_new_dequeue_state(xhci, udev->slot_id, |
| 1136 | ep_index, ep_ring->stopped_td, &deq_state); |
| 1137 | xhci_dbg(xhci, "Queueing new dequeue state\n"); |
| 1138 | xhci_queue_new_dequeue_state(xhci, ep_ring, |
| 1139 | udev->slot_id, |
| 1140 | ep_index, &deq_state); |
| 1141 | kfree(ep_ring->stopped_td); |
Sarah Sharp | a1587d9 | 2009-07-27 12:03:15 -0700 | [diff] [blame] | 1142 | xhci_ring_cmd_db(xhci); |
| 1143 | } |
| 1144 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1145 | |
| 1146 | if (ret) |
| 1147 | xhci_warn(xhci, "FIXME allocate a new ring segment\n"); |
| 1148 | } |
| 1149 | |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1150 | /* |
| 1151 | * At this point, the struct usb_device is about to go away, the device has |
| 1152 | * disconnected, and all traffic has been stopped and the endpoints have been |
| 1153 | * disabled. Free any HC data structures associated with that device. |
| 1154 | */ |
| 1155 | void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) |
| 1156 | { |
| 1157 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 1158 | unsigned long flags; |
| 1159 | |
| 1160 | if (udev->slot_id == 0) |
| 1161 | return; |
| 1162 | |
| 1163 | spin_lock_irqsave(&xhci->lock, flags); |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 1164 | if (xhci_queue_slot_control(xhci, TRB_DISABLE_SLOT, udev->slot_id)) { |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1165 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1166 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); |
| 1167 | return; |
| 1168 | } |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 1169 | xhci_ring_cmd_db(xhci); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1170 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1171 | /* |
| 1172 | * Event command completion handler will free any data structures |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 1173 | * associated with the slot. XXX Can free sleep? |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1174 | */ |
| 1175 | } |
| 1176 | |
| 1177 | /* |
| 1178 | * Returns 0 if the xHC ran out of device slots, the Enable Slot command |
| 1179 | * timed out, or allocating memory failed. Returns 1 on success. |
| 1180 | */ |
| 1181 | int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) |
| 1182 | { |
| 1183 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 1184 | unsigned long flags; |
| 1185 | int timeleft; |
| 1186 | int ret; |
| 1187 | |
| 1188 | spin_lock_irqsave(&xhci->lock, flags); |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 1189 | ret = xhci_queue_slot_control(xhci, TRB_ENABLE_SLOT, 0); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1190 | if (ret) { |
| 1191 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1192 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); |
| 1193 | return 0; |
| 1194 | } |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 1195 | xhci_ring_cmd_db(xhci); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1196 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1197 | |
| 1198 | /* XXX: how much time for xHC slot assignment? */ |
| 1199 | timeleft = wait_for_completion_interruptible_timeout(&xhci->addr_dev, |
| 1200 | USB_CTRL_SET_TIMEOUT); |
| 1201 | if (timeleft <= 0) { |
| 1202 | xhci_warn(xhci, "%s while waiting for a slot\n", |
| 1203 | timeleft == 0 ? "Timeout" : "Signal"); |
| 1204 | /* FIXME cancel the enable slot request */ |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1208 | if (!xhci->slot_id) { |
| 1209 | xhci_err(xhci, "Error while assigning device slot ID\n"); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 1212 | /* xhci_alloc_virt_device() does not touch rings; no need to lock */ |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1213 | if (!xhci_alloc_virt_device(xhci, xhci->slot_id, udev, GFP_KERNEL)) { |
| 1214 | /* Disable slot, if we can do it without mem alloc */ |
| 1215 | xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 1216 | spin_lock_irqsave(&xhci->lock, flags); |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 1217 | if (!xhci_queue_slot_control(xhci, TRB_DISABLE_SLOT, udev->slot_id)) |
| 1218 | xhci_ring_cmd_db(xhci); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1219 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1220 | return 0; |
| 1221 | } |
| 1222 | udev->slot_id = xhci->slot_id; |
| 1223 | /* Is this a LS or FS device under a HS hub? */ |
| 1224 | /* Hub or peripherial? */ |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1225 | return 1; |
| 1226 | } |
| 1227 | |
| 1228 | /* |
| 1229 | * Issue an Address Device command (which will issue a SetAddress request to |
| 1230 | * the device). |
| 1231 | * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so |
| 1232 | * we should only issue and wait on one address command at the same time. |
| 1233 | * |
| 1234 | * We add one to the device address issued by the hardware because the USB core |
| 1235 | * uses address 1 for the root hubs (even though they're not really devices). |
| 1236 | */ |
| 1237 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) |
| 1238 | { |
| 1239 | unsigned long flags; |
| 1240 | int timeleft; |
| 1241 | struct xhci_virt_device *virt_dev; |
| 1242 | int ret = 0; |
| 1243 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1244 | struct xhci_slot_ctx *slot_ctx; |
| 1245 | struct xhci_input_control_ctx *ctrl_ctx; |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 1246 | u64 temp_64; |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1247 | |
| 1248 | if (!udev->slot_id) { |
| 1249 | xhci_dbg(xhci, "Bad Slot ID %d\n", udev->slot_id); |
| 1250 | return -EINVAL; |
| 1251 | } |
| 1252 | |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1253 | virt_dev = xhci->devs[udev->slot_id]; |
| 1254 | |
| 1255 | /* If this is a Set Address to an unconfigured device, setup ep 0 */ |
| 1256 | if (!udev->config) |
| 1257 | xhci_setup_addressable_virt_dev(xhci, udev); |
| 1258 | /* Otherwise, assume the core has the device configured how it wants */ |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 1259 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1260 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1261 | |
Sarah Sharp | f88ba78 | 2009-05-14 11:44:22 -0700 | [diff] [blame] | 1262 | spin_lock_irqsave(&xhci->lock, flags); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1263 | ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma, |
| 1264 | udev->slot_id); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1265 | if (ret) { |
| 1266 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1267 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); |
| 1268 | return ret; |
| 1269 | } |
Sarah Sharp | 23e3be1 | 2009-04-29 19:05:20 -0700 | [diff] [blame] | 1270 | xhci_ring_cmd_db(xhci); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1271 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 1272 | |
| 1273 | /* ctrl tx can take up to 5 sec; XXX: need more time for xHC? */ |
| 1274 | timeleft = wait_for_completion_interruptible_timeout(&xhci->addr_dev, |
| 1275 | USB_CTRL_SET_TIMEOUT); |
| 1276 | /* FIXME: From section 4.3.4: "Software shall be responsible for timing |
| 1277 | * the SetAddress() "recovery interval" required by USB and aborting the |
| 1278 | * command on a timeout. |
| 1279 | */ |
| 1280 | if (timeleft <= 0) { |
| 1281 | xhci_warn(xhci, "%s while waiting for a slot\n", |
| 1282 | timeleft == 0 ? "Timeout" : "Signal"); |
| 1283 | /* FIXME cancel the address device command */ |
| 1284 | return -ETIME; |
| 1285 | } |
| 1286 | |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1287 | switch (virt_dev->cmd_status) { |
| 1288 | case COMP_CTX_STATE: |
| 1289 | case COMP_EBADSLT: |
| 1290 | xhci_err(xhci, "Setup ERROR: address device command for slot %d.\n", |
| 1291 | udev->slot_id); |
| 1292 | ret = -EINVAL; |
| 1293 | break; |
| 1294 | case COMP_TX_ERR: |
| 1295 | dev_warn(&udev->dev, "Device not responding to set address.\n"); |
| 1296 | ret = -EPROTO; |
| 1297 | break; |
| 1298 | case COMP_SUCCESS: |
| 1299 | xhci_dbg(xhci, "Successful Address Device command\n"); |
| 1300 | break; |
| 1301 | default: |
| 1302 | xhci_err(xhci, "ERROR: unexpected command completion " |
| 1303 | "code 0x%x.\n", virt_dev->cmd_status); |
Sarah Sharp | 66e49d8 | 2009-07-27 12:03:46 -0700 | [diff] [blame] | 1304 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1305 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1306 | ret = -EINVAL; |
| 1307 | break; |
| 1308 | } |
| 1309 | if (ret) { |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1310 | return ret; |
| 1311 | } |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 1312 | temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); |
| 1313 | xhci_dbg(xhci, "Op regs DCBAA ptr = %#016llx\n", temp_64); |
| 1314 | xhci_dbg(xhci, "Slot ID %d dcbaa entry @%p = %#016llx\n", |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1315 | udev->slot_id, |
Sarah Sharp | 8e595a5 | 2009-07-27 12:03:31 -0700 | [diff] [blame] | 1316 | &xhci->dcbaa->dev_context_ptrs[udev->slot_id], |
| 1317 | (unsigned long long) |
| 1318 | xhci->dcbaa->dev_context_ptrs[udev->slot_id]); |
Greg Kroah-Hartman | 700e205 | 2009-04-29 19:14:08 -0700 | [diff] [blame] | 1319 | xhci_dbg(xhci, "Output Context DMA address = %#08llx\n", |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1320 | (unsigned long long)virt_dev->out_ctx->dma); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1321 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1322 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1323 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1324 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1325 | /* |
| 1326 | * USB core uses address 1 for the roothubs, so we add one to the |
| 1327 | * address given back to us by the HC. |
| 1328 | */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1329 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); |
| 1330 | udev->devnum = (slot_ctx->dev_state & DEV_ADDR_MASK) + 1; |
Sarah Sharp | f94e0186 | 2009-04-27 19:58:38 -0700 | [diff] [blame] | 1331 | /* Zero the input context control for later use */ |
John Youn | d115b04 | 2009-07-27 12:05:15 -0700 | [diff] [blame] | 1332 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); |
| 1333 | ctrl_ctx->add_flags = 0; |
| 1334 | ctrl_ctx->drop_flags = 0; |
Sarah Sharp | 3ffbba9 | 2009-04-27 19:57:38 -0700 | [diff] [blame] | 1335 | |
| 1336 | xhci_dbg(xhci, "Device address = %d\n", udev->devnum); |
| 1337 | /* XXX Meh, not sure if anyone else but choose_address uses this. */ |
| 1338 | set_bit(udev->devnum, udev->bus->devmap.devicemap); |
| 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 1343 | int xhci_get_frame(struct usb_hcd *hcd) |
| 1344 | { |
| 1345 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 1346 | /* EHCI mods by the periodic size. Why? */ |
| 1347 | return xhci_readl(xhci, &xhci->run_regs->microframe_index) >> 3; |
| 1348 | } |
| 1349 | |
| 1350 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1351 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1352 | MODULE_LICENSE("GPL"); |
| 1353 | |
| 1354 | static int __init xhci_hcd_init(void) |
| 1355 | { |
| 1356 | #ifdef CONFIG_PCI |
| 1357 | int retval = 0; |
| 1358 | |
| 1359 | retval = xhci_register_pci(); |
| 1360 | |
| 1361 | if (retval < 0) { |
| 1362 | printk(KERN_DEBUG "Problem registering PCI driver."); |
| 1363 | return retval; |
| 1364 | } |
| 1365 | #endif |
Sarah Sharp | 9844197 | 2009-05-14 11:44:18 -0700 | [diff] [blame] | 1366 | /* |
| 1367 | * Check the compiler generated sizes of structures that must be laid |
| 1368 | * out in specific ways for hardware access. |
| 1369 | */ |
| 1370 | BUILD_BUG_ON(sizeof(struct xhci_doorbell_array) != 256*32/8); |
| 1371 | BUILD_BUG_ON(sizeof(struct xhci_slot_ctx) != 8*32/8); |
| 1372 | BUILD_BUG_ON(sizeof(struct xhci_ep_ctx) != 8*32/8); |
| 1373 | /* xhci_device_control has eight fields, and also |
| 1374 | * embeds one xhci_slot_ctx and 31 xhci_ep_ctx |
| 1375 | */ |
Sarah Sharp | 9844197 | 2009-05-14 11:44:18 -0700 | [diff] [blame] | 1376 | BUILD_BUG_ON(sizeof(struct xhci_stream_ctx) != 4*32/8); |
| 1377 | BUILD_BUG_ON(sizeof(union xhci_trb) != 4*32/8); |
| 1378 | BUILD_BUG_ON(sizeof(struct xhci_erst_entry) != 4*32/8); |
| 1379 | BUILD_BUG_ON(sizeof(struct xhci_cap_regs) != 7*32/8); |
| 1380 | BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8*32/8); |
| 1381 | /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */ |
| 1382 | BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8); |
| 1383 | BUILD_BUG_ON(sizeof(struct xhci_doorbell_array) != 256*32/8); |
Sarah Sharp | 66d4ead | 2009-04-27 19:52:28 -0700 | [diff] [blame] | 1384 | return 0; |
| 1385 | } |
| 1386 | module_init(xhci_hcd_init); |
| 1387 | |
| 1388 | static void __exit xhci_hcd_cleanup(void) |
| 1389 | { |
| 1390 | #ifdef CONFIG_PCI |
| 1391 | xhci_unregister_pci(); |
| 1392 | #endif |
| 1393 | } |
| 1394 | module_exit(xhci_hcd_cleanup); |