Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: xhci: Always align output device contexts to 64 bytes.

Make sure the xHCI output device context is 64-byte aligned. Previous
code was using the same structure for both the output device context and
the input control context. Since the structure had 32 bytes of flags
before the device context, the output device context wouldn't be 64-byte
aligned. Define a new structure to use for the output device context and
clean up the debugging for these two structures.

The copy of the device context in the input control context does *not*
need to be 64-byte aligned.

Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Sarah Sharp and committed by
Greg Kroah-Hartman
28c2d2ef 254c80a3

+104 -68
+78 -53
drivers/usb/host/xhci-dbg.c
··· 393 393 upper_32_bits(val)); 394 394 } 395 395 396 - void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_device_control *ctx, dma_addr_t dma, unsigned int last_ep) 396 + dma_addr_t xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_slot_ctx *slot, dma_addr_t dma) 397 + { 398 + /* Fields are 32 bits wide, DMA addresses are in bytes */ 399 + int field_size = 32 / 8; 400 + int i; 401 + 402 + xhci_dbg(xhci, "Slot Context:\n"); 403 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_info\n", 404 + &slot->dev_info, 405 + (unsigned long long)dma, slot->dev_info); 406 + dma += field_size; 407 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_info2\n", 408 + &slot->dev_info2, 409 + (unsigned long long)dma, slot->dev_info2); 410 + dma += field_size; 411 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - tt_info\n", 412 + &slot->tt_info, 413 + (unsigned long long)dma, slot->tt_info); 414 + dma += field_size; 415 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_state\n", 416 + &slot->dev_state, 417 + (unsigned long long)dma, slot->dev_state); 418 + dma += field_size; 419 + for (i = 0; i < 4; ++i) { 420 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - rsvd[%d]\n", 421 + &slot->reserved[i], (unsigned long long)dma, 422 + slot->reserved[i], i); 423 + dma += field_size; 424 + } 425 + 426 + return dma; 427 + } 428 + 429 + dma_addr_t xhci_dbg_ep_ctx(struct xhci_hcd *xhci, struct xhci_ep_ctx *ep, dma_addr_t dma, unsigned int last_ep) 397 430 { 398 431 int i, j; 399 432 int last_ep_ctx = 31; 433 + /* Fields are 32 bits wide, DMA addresses are in bytes */ 434 + int field_size = 32 / 8; 435 + 436 + if (last_ep < 31) 437 + last_ep_ctx = last_ep + 1; 438 + for (i = 0; i < last_ep_ctx; ++i) { 439 + xhci_dbg(xhci, "Endpoint %02d Context:\n", i); 440 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n", 441 + &ep[i].ep_info, 442 + (unsigned long long)dma, ep[i].ep_info); 443 + dma += field_size; 444 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info2\n", 445 + &ep[i].ep_info2, 446 + (unsigned long long)dma, ep[i].ep_info2); 447 + dma += field_size; 448 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08llx - deq\n", 449 + &ep[i].deq, 450 + (unsigned long long)dma, ep[i].deq); 451 + dma += 2*field_size; 452 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - tx_info\n", 453 + &ep[i].tx_info, 454 + (unsigned long long)dma, ep[i].tx_info); 455 + dma += field_size; 456 + for (j = 0; j < 3; ++j) { 457 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - rsvd[%d]\n", 458 + &ep[i].reserved[j], 459 + (unsigned long long)dma, 460 + ep[i].reserved[j], j); 461 + dma += field_size; 462 + } 463 + } 464 + return dma; 465 + } 466 + 467 + void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_device_control *ctx, dma_addr_t dma, unsigned int last_ep) 468 + { 469 + int i; 400 470 /* Fields are 32 bits wide, DMA addresses are in bytes */ 401 471 int field_size = 32 / 8; 402 472 ··· 484 414 ctx->rsvd[i], i); 485 415 dma += field_size; 486 416 } 417 + dma = xhci_dbg_slot_ctx(xhci, &ctx->slot, dma); 418 + dma = xhci_dbg_ep_ctx(xhci, ctx->ep, dma, last_ep); 419 + } 487 420 488 - xhci_dbg(xhci, "Slot Context:\n"); 489 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_info\n", 490 - &ctx->slot.dev_info, 491 - (unsigned long long)dma, ctx->slot.dev_info); 492 - dma += field_size; 493 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_info2\n", 494 - &ctx->slot.dev_info2, 495 - (unsigned long long)dma, ctx->slot.dev_info2); 496 - dma += field_size; 497 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - tt_info\n", 498 - &ctx->slot.tt_info, 499 - (unsigned long long)dma, ctx->slot.tt_info); 500 - dma += field_size; 501 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_state\n", 502 - &ctx->slot.dev_state, 503 - (unsigned long long)dma, ctx->slot.dev_state); 504 - dma += field_size; 505 - for (i = 0; i < 4; ++i) { 506 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - rsvd[%d]\n", 507 - &ctx->slot.reserved[i], (unsigned long long)dma, 508 - ctx->slot.reserved[i], i); 509 - dma += field_size; 510 - } 511 - 512 - if (last_ep < 31) 513 - last_ep_ctx = last_ep + 1; 514 - for (i = 0; i < last_ep_ctx; ++i) { 515 - xhci_dbg(xhci, "Endpoint %02d Context:\n", i); 516 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n", 517 - &ctx->ep[i].ep_info, 518 - (unsigned long long)dma, ctx->ep[i].ep_info); 519 - dma += field_size; 520 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info2\n", 521 - &ctx->ep[i].ep_info2, 522 - (unsigned long long)dma, ctx->ep[i].ep_info2); 523 - dma += field_size; 524 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08llx - deq\n", 525 - &ctx->ep[i].deq, 526 - (unsigned long long)dma, ctx->ep[i].deq); 527 - dma += 2*field_size; 528 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - tx_info\n", 529 - &ctx->ep[i].tx_info, 530 - (unsigned long long)dma, ctx->ep[i].tx_info); 531 - dma += field_size; 532 - for (j = 0; j < 3; ++j) { 533 - xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - rsvd[%d]\n", 534 - &ctx->ep[i].reserved[j], 535 - (unsigned long long)dma, 536 - ctx->ep[i].reserved[j], j); 537 - dma += field_size; 538 - } 539 - } 421 + void xhci_dbg_device_ctx(struct xhci_hcd *xhci, struct xhci_device_ctx *ctx, dma_addr_t dma, unsigned int last_ep) 422 + { 423 + dma = xhci_dbg_slot_ctx(xhci, &ctx->slot, dma); 424 + dma = xhci_dbg_ep_ctx(xhci, ctx->ep, dma, last_ep); 540 425 }
+2 -5
drivers/usb/host/xhci-hcd.c
··· 1013 1013 } 1014 1014 1015 1015 xhci_dbg(xhci, "Output context after successful config ep cmd:\n"); 1016 - xhci_dbg_ctx(xhci, virt_dev->out_ctx, virt_dev->out_ctx_dma, 1016 + xhci_dbg_device_ctx(xhci, virt_dev->out_ctx, virt_dev->out_ctx_dma, 1017 1017 LAST_CTX_TO_EP_NUM(virt_dev->in_ctx->slot.dev_info)); 1018 1018 1019 1019 xhci_zero_in_ctx(virt_dev); ··· 1265 1265 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 1266 1266 xhci_dbg_ctx(xhci, virt_dev->in_ctx, virt_dev->in_ctx_dma, 2); 1267 1267 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); 1268 - xhci_dbg_ctx(xhci, virt_dev->out_ctx, virt_dev->out_ctx_dma, 2); 1268 + xhci_dbg_device_ctx(xhci, virt_dev->out_ctx, virt_dev->out_ctx_dma, 2); 1269 1269 /* 1270 1270 * USB core uses address 1 for the roothubs, so we add one to the 1271 1271 * address given back to us by the HC. ··· 1274 1274 /* Zero the input context control for later use */ 1275 1275 virt_dev->in_ctx->add_flags = 0; 1276 1276 virt_dev->in_ctx->drop_flags = 0; 1277 - /* Mirror flags in the output context for future ep enable/disable */ 1278 - virt_dev->out_ctx->add_flags = SLOT_FLAG | EP0_FLAG; 1279 - virt_dev->out_ctx->drop_flags = 0; 1280 1277 1281 1278 xhci_dbg(xhci, "Device address = %d\n", udev->devnum); 1282 1279 /* XXX Meh, not sure if anyone else but choose_address uses this. */
+7 -8
drivers/usb/host/xhci-mem.c
··· 235 235 return 0; 236 236 dev = xhci->devs[slot_id]; 237 237 238 - /* Allocate the (output) device context that will be used in the HC */ 238 + /* Allocate the (output) device context that will be used in the HC. 239 + * The structure is 32 bytes smaller than the input context, but that's 240 + * fine. 241 + */ 239 242 dev->out_ctx = dma_pool_alloc(xhci->device_pool, flags, &dma); 240 243 if (!dev->out_ctx) 241 244 goto fail; ··· 263 260 264 261 init_completion(&dev->cmd_completion); 265 262 266 - /* 267 - * Point to output device context in dcbaa; skip the output control 268 - * context, which is eight 32 bit fields (or 32 bytes long) 269 - */ 270 - xhci->dcbaa->dev_context_ptrs[slot_id] = 271 - (u32) dev->out_ctx_dma + (32); 263 + /* Point to output device context in dcbaa. */ 264 + xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx_dma; 272 265 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n", 273 266 slot_id, 274 267 &xhci->dcbaa->dev_context_ptrs[slot_id], 275 - (unsigned long long)dev->out_ctx_dma); 268 + (unsigned long long) xhci->dcbaa->dev_context_ptrs[slot_id]); 276 269 277 270 return 1; 278 271 fail:
+17 -2
drivers/usb/host/xhci.h
··· 584 584 585 585 /** 586 586 * struct xhci_device_control 587 - * Input/Output context; see section 6.2.5. 587 + * Input context; see section 6.2.5. 588 588 * 589 589 * @drop_context: set the bit of the endpoint context you want to disable 590 590 * @add_context: set the bit of the endpoint context you want to enable 591 591 */ 592 592 struct xhci_device_control { 593 + /* Input control context */ 593 594 u32 drop_flags; 594 595 u32 add_flags; 595 596 u32 rsvd[6]; 597 + /* Copy of device context */ 598 + struct xhci_slot_ctx slot; 599 + struct xhci_ep_ctx ep[31]; 600 + }; 601 + 602 + /** 603 + * struct xhci_device_ctx 604 + * Device context; see section 6.2.1. 605 + * 606 + * @slot: slot context for the device. 607 + * @ep: array of endpoint contexts for the device. 608 + */ 609 + struct xhci_device_ctx { 596 610 struct xhci_slot_ctx slot; 597 611 struct xhci_ep_ctx ep[31]; 598 612 }; ··· 626 612 * track of input and output contexts separately because 627 613 * these commands might fail and we don't trust the hardware. 628 614 */ 629 - struct xhci_device_control *out_ctx; 615 + struct xhci_device_ctx *out_ctx; 630 616 dma_addr_t out_ctx_dma; 631 617 /* Used for addressing devices and configuration changes */ 632 618 struct xhci_device_control *in_ctx; ··· 1140 1126 void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci); 1141 1127 void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring); 1142 1128 void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_device_control *ctx, dma_addr_t dma, unsigned int last_ep); 1129 + void xhci_dbg_device_ctx(struct xhci_hcd *xhci, struct xhci_device_ctx *ctx, dma_addr_t dma, unsigned int last_ep); 1143 1130 1144 1131 /* xHCI memory managment */ 1145 1132 void xhci_mem_cleanup(struct xhci_hcd *xhci);