Pull USB / Thunderbolt fixes from Greg KH: "Here are some USB fixes for 6.4-rc3, as well as a driver core fix that resolves a memory leak that shows up in USB devices easier than other subsystems. Included in here are: - driver core memory leak as reported and tested by syzbot and developers - dwc3 driver fixes for reported problems - xhci driver fixes for reported problems - USB gadget driver reverts to resolve regressions - usbtmc driver fix for syzbot reported problem - thunderbolt driver fixes for reported issues - other small USB fixes All of these, except for the driver core fix, have been in linux-next with no reported problems. The driver core fix was tested and verified to solve the issue by syzbot and the original reporter" * tag 'usb-6.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: driver core: class: properly reference count class_dev_iter() xhci: Fix incorrect tracking of free space on transfer rings xhci-pci: Only run d3cold avoidance quirk for s2idle usb-storage: fix deadlock when a scsi command timeouts more than once usb: dwc3: fix a test for error in dwc3_core_init() usb: typec: tps6598x: Fix fault at module removal usb: gadget: u_ether: Fix host MAC address case usb: typec: altmodes/displayport: fix pin_assignment_show Revert "usb: gadget: udc: core: Invoke usb_gadget_connect only when started" Revert "usb: gadget: udc: core: Prevent redundant calls to pullup" usb: gadget: drop superfluous ':' in doc string usb: dwc3: debugfs: Resume dwc3 before accessing registers USB: UHCI: adjust zhaoxin UHCI controllers OverCurrent bit value usb: dwc3: fix gadget mode suspend interrupt handler issue usb: dwc3: gadget: Improve dwc3_gadget_suspend() and dwc3_gadget_resume() USB: usbtmc: Fix direction for 0-length ioctl control messages thunderbolt: Clear registers properly when auto clear isn't in use
Unified · Split
| @@ -320,6 +320,7 @@ void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class, · 319 unmodified lines | ||
| 320 | 320 | start_knode = &start->p->knode_class; |
| 321 | 321 | klist_iter_init_node(&sp->klist_devices, &iter->ki, start_knode); |
| 322 | 322 | iter->type = type; |
| 323 | + iter->sp = sp; | |
| 323 | 324 | } |
| 324 | 325 | EXPORT_SYMBOL_GPL(class_dev_iter_init); |
| 325 | 326 | |
| @@ -361,6 +362,7 @@ EXPORT_SYMBOL_GPL(class_dev_iter_next); · 35 unmodified lines | ||
| 361 | 362 | void class_dev_iter_exit(struct class_dev_iter *iter) |
| 362 | 363 | { |
| 363 | 364 | klist_iter_exit(&iter->ki); |
| 365 | + subsys_put(iter->sp); | |
| 364 | 366 | } |
| 365 | 367 | EXPORT_SYMBOL_GPL(class_dev_iter_exit); |
| 366 | 368 | |
| @@ -54,6 +54,21 @@ static int ring_interrupt_index(const struct tb_ring *ring) · 53 unmodified lines | ||
| 54 | 54 | return bit; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | +static void nhi_mask_interrupt(struct tb_nhi *nhi, int mask, int ring) | |
| 58 | +{ | |
| 59 | + if (nhi->quirks & QUIRK_AUTO_CLEAR_INT) | |
| 60 | + return; | |
| 61 | + iowrite32(mask, nhi->iobase + REG_RING_INTERRUPT_MASK_CLEAR_BASE + ring); | |
| 62 | +} | |
| 63 | + | |
| 64 | +static void nhi_clear_interrupt(struct tb_nhi *nhi, int ring) | |
| 65 | +{ | |
| 66 | + if (nhi->quirks & QUIRK_AUTO_CLEAR_INT) | |
| 67 | + ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + ring); | |
| 68 | + else | |
| 69 | + iowrite32(~0, nhi->iobase + REG_RING_INT_CLEAR + ring); | |
| 70 | +} | |
| 71 | + | |
| 57 | 72 | /* |
| 58 | 73 | * ring_interrupt_active() - activate/deactivate interrupts for a single ring |
| 59 | 74 | * |
| @@ -61,8 +76,8 @@ static int ring_interrupt_index(const struct tb_ring *ring) · 1 unmodified line | ||
| 61 | 76 | */ |
| 62 | 77 | static void ring_interrupt_active(struct tb_ring *ring, bool active) |
| 63 | 78 | { |
| 64 | − int reg = REG_RING_INTERRUPT_BASE + | |
| 65 | − ring_interrupt_index(ring) / 32 * 4; | |
| 79 | + int index = ring_interrupt_index(ring) / 32 * 4; | |
| 80 | + int reg = REG_RING_INTERRUPT_BASE + index; | |
| 66 | 81 | int interrupt_bit = ring_interrupt_index(ring) & 31; |
| 67 | 82 | int mask = 1 << interrupt_bit; |
| 68 | 83 | u32 old, new; |
| @@ -123,7 +138,11 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active) · 54 unmodified lines | ||
| 123 | 138 | "interrupt for %s %d is already %s\n", |
| 124 | 139 | RING_TYPE(ring), ring->hop, |
| 125 | 140 | active ? "enabled" : "disabled"); |
| 126 | − iowrite32(new, ring->nhi->iobase + reg); | |
| 141 | + | |
| 142 | + if (active) | |
| 143 | + iowrite32(new, ring->nhi->iobase + reg); | |
| 144 | + else | |
| 145 | + nhi_mask_interrupt(ring->nhi, mask, index); | |
| 127 | 146 | } |
| 128 | 147 | |
| 129 | 148 | /* |
| @@ -136,11 +155,11 @@ static void nhi_disable_interrupts(struct tb_nhi *nhi) · 6 unmodified lines | ||
| 136 | 155 | int i = 0; |
| 137 | 156 | /* disable interrupts */ |
| 138 | 157 | for (i = 0; i < RING_INTERRUPT_REG_COUNT(nhi); i++) |
| 139 | − iowrite32(0, nhi->iobase + REG_RING_INTERRUPT_BASE + 4 * i); | |
| 158 | + nhi_mask_interrupt(nhi, ~0, 4 * i); | |
| 140 | 159 | |
| 141 | 160 | /* clear interrupt status bits */ |
| 142 | 161 | for (i = 0; i < RING_NOTIFY_REG_COUNT(nhi); i++) |
| 143 | − ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + 4 * i); | |
| 162 | + nhi_clear_interrupt(nhi, 4 * i); | |
| 144 | 163 | } |
| 145 | 164 | |
| 146 | 165 | /* ring helper methods */ |
| @@ -93,6 +93,8 @@ struct ring_desc { · 92 unmodified lines | ||
| 93 | 93 | #define REG_RING_INTERRUPT_BASE 0x38200 |
| 94 | 94 | #define RING_INTERRUPT_REG_COUNT(nhi) ((31 + 2 * nhi->hop_count) / 32) |
| 95 | 95 | |
| 96 | +#define REG_RING_INTERRUPT_MASK_CLEAR_BASE 0x38208 | |
| 97 | + | |
| 96 | 98 | #define REG_INT_THROTTLING_RATE 0x38c00 |
| 97 | 99 | |
| 98 | 100 | /* Interrupt Vector Allocation */ |
| @@ -1928,6 +1928,8 @@ static int usbtmc_ioctl_request(struct usbtmc_device_data *data, · 1927 unmodified lines | ||
| 1928 | 1928 | |
| 1929 | 1929 | if (request.req.wLength > USBTMC_BUFSIZE) |
| 1930 | 1930 | return -EMSGSIZE; |
| 1931 | + if (request.req.wLength == 0) /* Length-0 requests are never IN */ | |
| 1932 | + request.req.bRequestType &= ~USB_DIR_IN; | |
| 1931 | 1933 | |
| 1932 | 1934 | is_in = request.req.bRequestType & USB_DIR_IN; |
| 1933 | 1935 | |
| @@ -1137,7 +1137,7 @@ static int dwc3_core_init(struct dwc3 *dwc) · 1136 unmodified lines | ||
| 1137 | 1137 | |
| 1138 | 1138 | dwc3_set_incr_burst_type(dwc); |
| 1139 | 1139 | |
| 1140 | − dwc3_phy_power_on(dwc); | |
| 1140 | + ret = dwc3_phy_power_on(dwc); | |
| 1141 | 1141 | if (ret) |
| 1142 | 1142 | goto err_exit_phy; |
| 1143 | 1143 | |
| @@ -1116,6 +1116,7 @@ struct dwc3_scratchpad_array { · 1115 unmodified lines | ||
| 1116 | 1116 | * @dis_metastability_quirk: set to disable metastability quirk. |
| 1117 | 1117 | * @dis_split_quirk: set to disable split boundary. |
| 1118 | 1118 | * @wakeup_configured: set if the device is configured for remote wakeup. |
| 1119 | + * @suspended: set to track suspend event due to U3/L2. | |
| 1119 | 1120 | * @imod_interval: set the interrupt moderation interval in 250ns |
| 1120 | 1121 | * increments or 0 to disable. |
| 1121 | 1122 | * @max_cfg_eps: current max number of IN eps used across all USB configs. |
| @@ -1332,6 +1333,7 @@ struct dwc3 { · 210 unmodified lines | ||
| 1332 | 1333 | unsigned dis_split_quirk:1; |
| 1333 | 1334 | unsigned async_callbacks:1; |
| 1334 | 1335 | unsigned wakeup_configured:1; |
| 1336 | + unsigned suspended:1; | |
| 1335 | 1337 | |
| 1336 | 1338 | u16 imod_interval; |
| 1337 | 1339 | |
| @@ -332,6 +332,11 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused) · 331 unmodified lines | ||
| 332 | 332 | unsigned int current_mode; |
| 333 | 333 | unsigned long flags; |
| 334 | 334 | u32 reg; |
| 335 | + int ret; | |
| 336 | + | |
| 337 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 338 | + if (ret < 0) | |
| 339 | + return ret; | |
| 335 | 340 | |
| 336 | 341 | spin_lock_irqsave(&dwc->lock, flags); |
| 337 | 342 | reg = dwc3_readl(dwc->regs, DWC3_GSTS); |
| @@ -350,6 +355,8 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused) · 12 unmodified lines | ||
| 350 | 355 | } |
| 351 | 356 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 352 | 357 | |
| 358 | + pm_runtime_put_sync(dwc->dev); | |
| 359 | + | |
| 353 | 360 | return 0; |
| 354 | 361 | } |
| 355 | 362 | |
| @@ -395,6 +402,11 @@ static int dwc3_mode_show(struct seq_file *s, void *unused) · 39 unmodified lines | ||
| 395 | 402 | struct dwc3 *dwc = s->private; |
| 396 | 403 | unsigned long flags; |
| 397 | 404 | u32 reg; |
| 405 | + int ret; | |
| 406 | + | |
| 407 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 408 | + if (ret < 0) | |
| 409 | + return ret; | |
| 398 | 410 | |
| 399 | 411 | spin_lock_irqsave(&dwc->lock, flags); |
| 400 | 412 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
| @@ -414,6 +426,8 @@ static int dwc3_mode_show(struct seq_file *s, void *unused) · 13 unmodified lines | ||
| 414 | 426 | seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg)); |
| 415 | 427 | } |
| 416 | 428 | |
| 429 | + pm_runtime_put_sync(dwc->dev); | |
| 430 | + | |
| 417 | 431 | return 0; |
| 418 | 432 | } |
| 419 | 433 | |
| @@ -463,6 +477,11 @@ static int dwc3_testmode_show(struct seq_file *s, void *unused) · 43 unmodified lines | ||
| 463 | 477 | struct dwc3 *dwc = s->private; |
| 464 | 478 | unsigned long flags; |
| 465 | 479 | u32 reg; |
| 480 | + int ret; | |
| 481 | + | |
| 482 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 483 | + if (ret < 0) | |
| 484 | + return ret; | |
| 466 | 485 | |
| 467 | 486 | spin_lock_irqsave(&dwc->lock, flags); |
| 468 | 487 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| @@ -493,6 +512,8 @@ static int dwc3_testmode_show(struct seq_file *s, void *unused) · 24 unmodified lines | ||
| 493 | 512 | seq_printf(s, "UNKNOWN %d\n", reg); |
| 494 | 513 | } |
| 495 | 514 | |
| 515 | + pm_runtime_put_sync(dwc->dev); | |
| 516 | + | |
| 496 | 517 | return 0; |
| 497 | 518 | } |
| 498 | 519 | |
| @@ -509,6 +530,7 @@ static ssize_t dwc3_testmode_write(struct file *file, · 10 unmodified lines | ||
| 509 | 530 | unsigned long flags; |
| 510 | 531 | u32 testmode = 0; |
| 511 | 532 | char buf[32]; |
| 533 | + int ret; | |
| 512 | 534 | |
| 513 | 535 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 514 | 536 | return -EFAULT; |
| @@ -526,10 +548,16 @@ static ssize_t dwc3_testmode_write(struct file *file, · 11 unmodified lines | ||
| 526 | 548 | else |
| 527 | 549 | testmode = 0; |
| 528 | 550 | |
| 551 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 552 | + if (ret < 0) | |
| 553 | + return ret; | |
| 554 | + | |
| 529 | 555 | spin_lock_irqsave(&dwc->lock, flags); |
| 530 | 556 | dwc3_gadget_set_test_mode(dwc, testmode); |
| 531 | 557 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 532 | 558 | |
| 559 | + pm_runtime_put_sync(dwc->dev); | |
| 560 | + | |
| 533 | 561 | return count; |
| 534 | 562 | } |
| 535 | 563 | |
| @@ -548,12 +576,18 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused) · 12 unmodified lines | ||
| 548 | 576 | enum dwc3_link_state state; |
| 549 | 577 | u32 reg; |
| 550 | 578 | u8 speed; |
| 579 | + int ret; | |
| 580 | + | |
| 581 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 582 | + if (ret < 0) | |
| 583 | + return ret; | |
| 551 | 584 | |
| 552 | 585 | spin_lock_irqsave(&dwc->lock, flags); |
| 553 | 586 | reg = dwc3_readl(dwc->regs, DWC3_GSTS); |
| 554 | 587 | if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) { |
| 555 | 588 | seq_puts(s, "Not available\n"); |
| 556 | 589 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 590 | + pm_runtime_put_sync(dwc->dev); | |
| 557 | 591 | return 0; |
| 558 | 592 | } |
| 559 | 593 | |
| @@ -566,6 +600,8 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused) · 6 unmodified lines | ||
| 566 | 600 | dwc3_gadget_hs_link_string(state)); |
| 567 | 601 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 568 | 602 | |
| 603 | + pm_runtime_put_sync(dwc->dev); | |
| 604 | + | |
| 569 | 605 | return 0; |
| 570 | 606 | } |
| 571 | 607 | |
| @@ -584,6 +620,7 @@ static ssize_t dwc3_link_state_write(struct file *file, · 12 unmodified lines | ||
| 584 | 620 | char buf[32]; |
| 585 | 621 | u32 reg; |
| 586 | 622 | u8 speed; |
| 623 | + int ret; | |
| 587 | 624 | |
| 588 | 625 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 589 | 626 | return -EFAULT; |
| @@ -603,10 +640,15 @@ static ssize_t dwc3_link_state_write(struct file *file, · 13 unmodified lines | ||
| 603 | 640 | else |
| 604 | 641 | return -EINVAL; |
| 605 | 642 | |
| 643 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 644 | + if (ret < 0) | |
| 645 | + return ret; | |
| 646 | + | |
| 606 | 647 | spin_lock_irqsave(&dwc->lock, flags); |
| 607 | 648 | reg = dwc3_readl(dwc->regs, DWC3_GSTS); |
| 608 | 649 | if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) { |
| 609 | 650 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 651 | + pm_runtime_put_sync(dwc->dev); | |
| 610 | 652 | return -EINVAL; |
| 611 | 653 | } |
| 612 | 654 | |
| @@ -616,12 +658,15 @@ static ssize_t dwc3_link_state_write(struct file *file, · 3 unmodified lines | ||
| 616 | 658 | if (speed < DWC3_DSTS_SUPERSPEED && |
| 617 | 659 | state != DWC3_LINK_STATE_RECOV) { |
| 618 | 660 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 661 | + pm_runtime_put_sync(dwc->dev); | |
| 619 | 662 | return -EINVAL; |
| 620 | 663 | } |
| 621 | 664 | |
| 622 | 665 | dwc3_gadget_set_link_state(dwc, state); |
| 623 | 666 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 624 | 667 | |
| 668 | + pm_runtime_put_sync(dwc->dev); | |
| 669 | + | |
| 625 | 670 | return count; |
| 626 | 671 | } |
| 627 | 672 | |
| @@ -645,6 +690,11 @@ static int dwc3_tx_fifo_size_show(struct seq_file *s, void *unused) · 17 unmodified lines | ||
| 645 | 690 | unsigned long flags; |
| 646 | 691 | u32 mdwidth; |
| 647 | 692 | u32 val; |
| 693 | + int ret; | |
| 694 | + | |
| 695 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 696 | + if (ret < 0) | |
| 697 | + return ret; | |
| 648 | 698 | |
| 649 | 699 | spin_lock_irqsave(&dwc->lock, flags); |
| 650 | 700 | val = dwc3_core_fifo_space(dep, DWC3_TXFIFO); |
| @@ -657,6 +707,8 @@ static int dwc3_tx_fifo_size_show(struct seq_file *s, void *unused) · 6 unmodified lines | ||
| 657 | 707 | seq_printf(s, "%u\n", val); |
| 658 | 708 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 659 | 709 | |
| 710 | + pm_runtime_put_sync(dwc->dev); | |
| 711 | + | |
| 660 | 712 | return 0; |
| 661 | 713 | } |
| 662 | 714 | |
| @@ -667,6 +719,11 @@ static int dwc3_rx_fifo_size_show(struct seq_file *s, void *unused) · 4 unmodified lines | ||
| 667 | 719 | unsigned long flags; |
| 668 | 720 | u32 mdwidth; |
| 669 | 721 | u32 val; |
| 722 | + int ret; | |
| 723 | + | |
| 724 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 725 | + if (ret < 0) | |
| 726 | + return ret; | |
| 670 | 727 | |
| 671 | 728 | spin_lock_irqsave(&dwc->lock, flags); |
| 672 | 729 | val = dwc3_core_fifo_space(dep, DWC3_RXFIFO); |
| @@ -679,6 +736,8 @@ static int dwc3_rx_fifo_size_show(struct seq_file *s, void *unused) · 6 unmodified lines | ||
| 679 | 736 | seq_printf(s, "%u\n", val); |
| 680 | 737 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 681 | 738 | |
| 739 | + pm_runtime_put_sync(dwc->dev); | |
| 740 | + | |
| 682 | 741 | return 0; |
| 683 | 742 | } |
| 684 | 743 | |
| @@ -688,12 +747,19 @@ static int dwc3_tx_request_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines | ||
| 688 | 747 | struct dwc3 *dwc = dep->dwc; |
| 689 | 748 | unsigned long flags; |
| 690 | 749 | u32 val; |
| 750 | + int ret; | |
| 751 | + | |
| 752 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 753 | + if (ret < 0) | |
| 754 | + return ret; | |
| 691 | 755 | |
| 692 | 756 | spin_lock_irqsave(&dwc->lock, flags); |
| 693 | 757 | val = dwc3_core_fifo_space(dep, DWC3_TXREQQ); |
| 694 | 758 | seq_printf(s, "%u\n", val); |
| 695 | 759 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 696 | 760 | |
| 761 | + pm_runtime_put_sync(dwc->dev); | |
| 762 | + | |
| 697 | 763 | return 0; |
| 698 | 764 | } |
| 699 | 765 | |
| @@ -703,12 +769,19 @@ static int dwc3_rx_request_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines | ||
| 703 | 769 | struct dwc3 *dwc = dep->dwc; |
| 704 | 770 | unsigned long flags; |
| 705 | 771 | u32 val; |
| 772 | + int ret; | |
| 773 | + | |
| 774 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 775 | + if (ret < 0) | |
| 776 | + return ret; | |
| 706 | 777 | |
| 707 | 778 | spin_lock_irqsave(&dwc->lock, flags); |
| 708 | 779 | val = dwc3_core_fifo_space(dep, DWC3_RXREQQ); |
| 709 | 780 | seq_printf(s, "%u\n", val); |
| 710 | 781 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 711 | 782 | |
| 783 | + pm_runtime_put_sync(dwc->dev); | |
| 784 | + | |
| 712 | 785 | return 0; |
| 713 | 786 | } |
| 714 | 787 | |
| @@ -718,12 +791,19 @@ static int dwc3_rx_info_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines | ||
| 718 | 791 | struct dwc3 *dwc = dep->dwc; |
| 719 | 792 | unsigned long flags; |
| 720 | 793 | u32 val; |
| 794 | + int ret; | |
| 795 | + | |
| 796 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 797 | + if (ret < 0) | |
| 798 | + return ret; | |
| 721 | 799 | |
| 722 | 800 | spin_lock_irqsave(&dwc->lock, flags); |
| 723 | 801 | val = dwc3_core_fifo_space(dep, DWC3_RXINFOQ); |
| 724 | 802 | seq_printf(s, "%u\n", val); |
| 725 | 803 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 726 | 804 | |
| 805 | + pm_runtime_put_sync(dwc->dev); | |
| 806 | + | |
| 727 | 807 | return 0; |
| 728 | 808 | } |
| 729 | 809 | |
| @@ -733,12 +813,19 @@ static int dwc3_descriptor_fetch_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines | ||
| 733 | 813 | struct dwc3 *dwc = dep->dwc; |
| 734 | 814 | unsigned long flags; |
| 735 | 815 | u32 val; |
| 816 | + int ret; | |
| 817 | + | |
| 818 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 819 | + if (ret < 0) | |
| 820 | + return ret; | |
| 736 | 821 | |
| 737 | 822 | spin_lock_irqsave(&dwc->lock, flags); |
| 738 | 823 | val = dwc3_core_fifo_space(dep, DWC3_DESCFETCHQ); |
| 739 | 824 | seq_printf(s, "%u\n", val); |
| 740 | 825 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 741 | 826 | |
| 827 | + pm_runtime_put_sync(dwc->dev); | |
| 828 | + | |
| 742 | 829 | return 0; |
| 743 | 830 | } |
| 744 | 831 | |
| @@ -748,12 +835,19 @@ static int dwc3_event_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines | ||
| 748 | 835 | struct dwc3 *dwc = dep->dwc; |
| 749 | 836 | unsigned long flags; |
| 750 | 837 | u32 val; |
| 838 | + int ret; | |
| 839 | + | |
| 840 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 841 | + if (ret < 0) | |
| 842 | + return ret; | |
| 751 | 843 | |
| 752 | 844 | spin_lock_irqsave(&dwc->lock, flags); |
| 753 | 845 | val = dwc3_core_fifo_space(dep, DWC3_EVENTQ); |
| 754 | 846 | seq_printf(s, "%u\n", val); |
| 755 | 847 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 756 | 848 | |
| 849 | + pm_runtime_put_sync(dwc->dev); | |
| 850 | + | |
| 757 | 851 | return 0; |
| 758 | 852 | } |
| 759 | 853 | |
| @@ -798,6 +892,11 @@ static int dwc3_trb_ring_show(struct seq_file *s, void *unused) · 38 unmodified lines | ||
| 798 | 892 | struct dwc3 *dwc = dep->dwc; |
| 799 | 893 | unsigned long flags; |
| 800 | 894 | int i; |
| 895 | + int ret; | |
| 896 | + | |
| 897 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 898 | + if (ret < 0) | |
| 899 | + return ret; | |
| 801 | 900 | |
| 802 | 901 | spin_lock_irqsave(&dwc->lock, flags); |
| 803 | 902 | if (dep->number <= 1) { |
| @@ -827,6 +926,8 @@ static int dwc3_trb_ring_show(struct seq_file *s, void *unused) · 23 unmodified lines | ||
| 827 | 926 | out: |
| 828 | 927 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 829 | 928 | |
| 929 | + pm_runtime_put_sync(dwc->dev); | |
| 930 | + | |
| 830 | 931 | return 0; |
| 831 | 932 | } |
| 832 | 933 | |
| @@ -839,6 +940,11 @@ static int dwc3_ep_info_register_show(struct seq_file *s, void *unused) · 6 unmodified lines | ||
| 839 | 940 | u32 lower_32_bits; |
| 840 | 941 | u32 upper_32_bits; |
| 841 | 942 | u32 reg; |
| 943 | + int ret; | |
| 944 | + | |
| 945 | + ret = pm_runtime_resume_and_get(dwc->dev); | |
| 946 | + if (ret < 0) | |
| 947 | + return ret; | |
| 842 | 948 | |
| 843 | 949 | spin_lock_irqsave(&dwc->lock, flags); |
| 844 | 950 | reg = DWC3_GDBGLSPMUX_EPSELECT(dep->number); |
| @@ -851,6 +957,8 @@ static int dwc3_ep_info_register_show(struct seq_file *s, void *unused) · 6 unmodified lines | ||
| 851 | 957 | seq_printf(s, "0x%016llx\n", ep_info); |
| 852 | 958 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 853 | 959 | |
| 960 | + pm_runtime_put_sync(dwc->dev); | |
| 961 | + | |
| 854 | 962 | return 0; |
| 855 | 963 | } |
| 856 | 964 | |
| @@ -910,6 +1018,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc) · 53 unmodified lines | ||
| 910 | 1018 | dwc->regset->regs = dwc3_regs; |
| 911 | 1019 | dwc->regset->nregs = ARRAY_SIZE(dwc3_regs); |
| 912 | 1020 | dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; |
| 1021 | + dwc->regset->dev = dwc->dev; | |
| 913 | 1022 | |
| 914 | 1023 | root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); |
| 915 | 1024 | dwc->debug_root = root; |
| @@ -2440,6 +2440,7 @@ static int dwc3_gadget_func_wakeup(struct usb_gadget *g, int intf_id) · 2439 unmodified lines | ||
| 2440 | 2440 | return -EINVAL; |
| 2441 | 2441 | } |
| 2442 | 2442 | dwc3_resume_gadget(dwc); |
| 2443 | + dwc->suspended = false; | |
| 2443 | 2444 | dwc->link_state = DWC3_LINK_STATE_U0; |
| 2444 | 2445 | } |
| 2445 | 2446 | |
| @@ -2699,6 +2700,21 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) · 253 unmodified lines | ||
| 2699 | 2700 | return ret; |
| 2700 | 2701 | } |
| 2701 | 2702 | |
| 2703 | +static int dwc3_gadget_soft_connect(struct dwc3 *dwc) | |
| 2704 | +{ | |
| 2705 | + /* | |
| 2706 | + * In the Synopsys DWC_usb31 1.90a programming guide section | |
| 2707 | + * 4.1.9, it specifies that for a reconnect after a | |
| 2708 | + * device-initiated disconnect requires a core soft reset | |
| 2709 | + * (DCTL.CSftRst) before enabling the run/stop bit. | |
| 2710 | + */ | |
| 2711 | + dwc3_core_soft_reset(dwc); | |
| 2712 | + | |
| 2713 | + dwc3_event_buffers_setup(dwc); | |
| 2714 | + __dwc3_gadget_start(dwc); | |
| 2715 | + return dwc3_gadget_run_stop(dwc, true); | |
| 2716 | +} | |
| 2717 | + | |
| 2702 | 2718 | static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) |
| 2703 | 2719 | { |
| 2704 | 2720 | struct dwc3 *dwc = gadget_to_dwc(g); |
| @@ -2737,21 +2753,10 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) · 32 unmodified lines | ||
| 2737 | 2753 | |
| 2738 | 2754 | synchronize_irq(dwc->irq_gadget); |
| 2739 | 2755 | |
| 2740 | − if (!is_on) { | |
| 2756 | + if (!is_on) | |
| 2741 | 2757 | ret = dwc3_gadget_soft_disconnect(dwc); |
| 2742 | − } else { | |
| 2743 | − /* | |
| 2744 | − * In the Synopsys DWC_usb31 1.90a programming guide section | |
| 2745 | − * 4.1.9, it specifies that for a reconnect after a | |
| 2746 | − * device-initiated disconnect requires a core soft reset | |
| 2747 | − * (DCTL.CSftRst) before enabling the run/stop bit. | |
| 2748 | − */ | |
| 2749 | − dwc3_core_soft_reset(dwc); | |
| 2750 | − | |
| 2751 | − dwc3_event_buffers_setup(dwc); | |
| 2752 | − __dwc3_gadget_start(dwc); | |
| 2753 | − ret = dwc3_gadget_run_stop(dwc, true); | |
| 2754 | − } | |
| 2758 | + else | |
| 2759 | + ret = dwc3_gadget_soft_connect(dwc); | |
| 2755 | 2760 | |
| 2756 | 2761 | pm_runtime_put(dwc->dev); |
| 2757 | 2762 | |
| @@ -3938,6 +3943,8 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) · 1180 unmodified lines | ||
| 3938 | 3943 | { |
| 3939 | 3944 | int reg; |
| 3940 | 3945 | |
| 3946 | + dwc->suspended = false; | |
| 3947 | + | |
| 3941 | 3948 | dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); |
| 3942 | 3949 | |
| 3943 | 3950 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| @@ -3962,6 +3969,8 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) · 18 unmodified lines | ||
| 3962 | 3969 | { |
| 3963 | 3970 | u32 reg; |
| 3964 | 3971 | |
| 3972 | + dwc->suspended = false; | |
| 3973 | + | |
| 3965 | 3974 | /* |
| 3966 | 3975 | * Ideally, dwc3_reset_gadget() would trigger the function |
| 3967 | 3976 | * drivers to stop any active transfers through ep disable. |
| @@ -4180,6 +4189,8 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) · 212 unmodified lines | ||
| 4180 | 4189 | |
| 4181 | 4190 | static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc, unsigned int evtinfo) |
| 4182 | 4191 | { |
| 4192 | + dwc->suspended = false; | |
| 4193 | + | |
| 4183 | 4194 | /* |
| 4184 | 4195 | * TODO take core out of low power mode when that's |
| 4185 | 4196 | * implemented. |
| @@ -4277,6 +4288,7 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, · 91 unmodified lines | ||
| 4277 | 4288 | if (dwc->gadget->wakeup_armed) { |
| 4278 | 4289 | dwc3_gadget_enable_linksts_evts(dwc, false); |
| 4279 | 4290 | dwc3_resume_gadget(dwc); |
| 4291 | + dwc->suspended = false; | |
| 4280 | 4292 | } |
| 4281 | 4293 | break; |
| 4282 | 4294 | case DWC3_LINK_STATE_U1: |
| @@ -4303,8 +4315,10 @@ static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, · 20 unmodified lines | ||
| 4303 | 4315 | { |
| 4304 | 4316 | enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK; |
| 4305 | 4317 | |
| 4306 | − if (dwc->link_state != next && next == DWC3_LINK_STATE_U3) | |
| 4318 | + if (!dwc->suspended && next == DWC3_LINK_STATE_U3) { | |
| 4319 | + dwc->suspended = true; | |
| 4307 | 4320 | dwc3_suspend_gadget(dwc); |
| 4321 | + } | |
| 4308 | 4322 | |
| 4309 | 4323 | dwc->link_state = next; |
| 4310 | 4324 | } |
| @@ -4655,42 +4669,39 @@ void dwc3_gadget_exit(struct dwc3 *dwc) · 344 unmodified lines | ||
| 4655 | 4669 | int dwc3_gadget_suspend(struct dwc3 *dwc) |
| 4656 | 4670 | { |
| 4657 | 4671 | unsigned long flags; |
| 4672 | + int ret; | |
| 4658 | 4673 | |
| 4659 | 4674 | if (!dwc->gadget_driver) |
| 4660 | 4675 | return 0; |
| 4661 | 4676 | |
| 4662 | − dwc3_gadget_run_stop(dwc, false); | |
| 4677 | + ret = dwc3_gadget_soft_disconnect(dwc); | |
| 4678 | + if (ret) | |
| 4679 | + goto err; | |
| 4663 | 4680 | |
| 4664 | 4681 | spin_lock_irqsave(&dwc->lock, flags); |
| 4665 | 4682 | dwc3_disconnect_gadget(dwc); |
| 4666 | − __dwc3_gadget_stop(dwc); | |
| 4667 | 4683 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 4668 | 4684 | |
| 4669 | 4685 | return 0; |
| 4686 | + | |
| 4687 | +err: | |
| 4688 | + /* | |
| 4689 | + * Attempt to reset the controller's state. Likely no | |
| 4690 | + * communication can be established until the host | |
| 4691 | + * performs a port reset. | |
| 4692 | + */ | |
| 4693 | + if (dwc->softconnect) | |
| 4694 | + dwc3_gadget_soft_connect(dwc); | |
| 4695 | + | |
| 4696 | + return ret; | |
| 4670 | 4697 | } |
| 4671 | 4698 | |
| 4672 | 4699 | int dwc3_gadget_resume(struct dwc3 *dwc) |
| 4673 | 4700 | { |
| 4674 | − int ret; | |
| 4675 | − | |
| 4676 | 4701 | if (!dwc->gadget_driver || !dwc->softconnect) |
| 4677 | 4702 | return 0; |
| 4678 | 4703 | |
| 4679 | − ret = __dwc3_gadget_start(dwc); | |
| 4680 | − if (ret < 0) | |
| 4681 | − goto err0; | |
| 4682 | − | |
| 4683 | − ret = dwc3_gadget_run_stop(dwc, true); | |
| 4684 | − if (ret < 0) | |
| 4685 | − goto err1; | |
| 4686 | − | |
| 4687 | − return 0; | |
| 4688 | − | |
| 4689 | −err1: | |
| 4690 | − __dwc3_gadget_stop(dwc); | |
| 4691 | − | |
| 4692 | −err0: | |
| 4693 | − return ret; | |
| 4704 | + return dwc3_gadget_soft_connect(dwc); | |
| 4694 | 4705 | } |
| 4695 | 4706 | |
| 4696 | 4707 | void dwc3_gadget_process_pending_events(struct dwc3 *dwc) |
| @@ -17,6 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <linux/etherdevice.h> |
| 18 | 18 | #include <linux/ethtool.h> |
| 19 | 19 | #include <linux/if_vlan.h> |
| 20 | +#include <linux/string_helpers.h> | |
| 20 | 21 | #include <linux/usb/composite.h> |
| 21 | 22 | |
| 22 | 23 | #include "u_ether.h" |
| @@ -965,6 +966,8 @@ int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len) · 942 unmodified lines | ||
| 965 | 966 | dev = netdev_priv(net); |
| 966 | 967 | snprintf(host_addr, len, "%pm", dev->host_mac); |
| 967 | 968 | |
| 969 | + string_upper(host_addr, host_addr); | |
| 970 | + | |
| 968 | 971 | return strlen(host_addr); |
| 969 | 972 | } |
| 970 | 973 | EXPORT_SYMBOL_GPL(gether_get_host_addr_cdc); |
| @@ -37,10 +37,6 @@ static const struct bus_type gadget_bus_type; · 36 unmodified lines | ||
| 37 | 37 | * @vbus: for udcs who care about vbus status, this value is real vbus status; |
| 38 | 38 | * for udcs who do not care about vbus status, this value is always true |
| 39 | 39 | * @started: the UDC's started state. True if the UDC had started. |
| 40 | − * @connect_lock: protects udc->vbus, udc->started, gadget->connect, gadget->deactivate related | |
| 41 | − * functions. usb_gadget_connect_locked, usb_gadget_disconnect_locked, | |
| 42 | − * usb_udc_connect_control_locked, usb_gadget_udc_start_locked, usb_gadget_udc_stop_locked are | |
| 43 | − * called with this lock held. | |
| 44 | 40 | * |
| 45 | 41 | * This represents the internal data structure which is used by the UDC-class |
| 46 | 42 | * to hold information about udc driver and gadget together. |
| @@ -52,7 +48,6 @@ struct usb_udc { · 5 unmodified lines | ||
| 52 | 48 | struct list_head list; |
| 53 | 49 | bool vbus; |
| 54 | 50 | bool started; |
| 55 | − struct mutex connect_lock; | |
| 56 | 51 | }; |
| 57 | 52 | |
| 58 | 53 | static struct class *udc_class; |
| @@ -692,9 +687,17 @@ out: · 633 unmodified lines | ||
| 692 | 687 | } |
| 693 | 688 | EXPORT_SYMBOL_GPL(usb_gadget_vbus_disconnect); |
| 694 | 689 | |
| 695 | −/* Internal version of usb_gadget_connect needs to be called with connect_lock held. */ | |
| 696 | −static int usb_gadget_connect_locked(struct usb_gadget *gadget) | |
| 697 | − __must_hold(&gadget->udc->connect_lock) | |
| 690 | +/** | |
| 691 | + * usb_gadget_connect - software-controlled connect to USB host | |
| 692 | + * @gadget:the peripheral being connected | |
| 693 | + * | |
| 694 | + * Enables the D+ (or potentially D-) pullup. The host will start | |
| 695 | + * enumerating this gadget when the pullup is active and a VBUS session | |
| 696 | + * is active (the link is powered). | |
| 697 | + * | |
| 698 | + * Returns zero on success, else negative errno. | |
| 699 | + */ | |
| 700 | +int usb_gadget_connect(struct usb_gadget *gadget) | |
| 698 | 701 | { |
| 699 | 702 | int ret = 0; |
| 700 | 703 | |
| @@ -703,15 +706,10 @@ static int usb_gadget_connect_locked(struct usb_gadget *gadget) · 2 unmodified lines | ||
| 703 | 706 | goto out; |
| 704 | 707 | } |
| 705 | 708 | |
| 706 | − if (gadget->connected) | |
| 707 | − goto out; | |
| 708 | − | |
| 709 | − if (gadget->deactivated || !gadget->udc->started) { | |
| 709 | + if (gadget->deactivated) { | |
| 710 | 710 | /* |
| 711 | 711 | * If gadget is deactivated we only save new state. |
| 712 | 712 | * Gadget will be connected automatically after activation. |
| 713 | − * | |
| 714 | − * udc first needs to be started before gadget can be pulled up. | |
| 715 | 713 | */ |
| 716 | 714 | gadget->connected = true; |
| 717 | 715 | goto out; |
| @@ -726,32 +724,22 @@ out: · 8 unmodified lines | ||
| 726 | 724 | |
| 727 | 725 | return ret; |
| 728 | 726 | } |
| 727 | +EXPORT_SYMBOL_GPL(usb_gadget_connect); | |
| 729 | 728 | |
| 730 | 729 | /** |
| 731 | − * usb_gadget_connect - software-controlled connect to USB host | |
| 732 | − * @gadget:the peripheral being connected | |
| 730 | + * usb_gadget_disconnect - software-controlled disconnect from USB host | |
| 731 | + * @gadget:the peripheral being disconnected | |
| 733 | 732 | * |
| 734 | − * Enables the D+ (or potentially D-) pullup. The host will start | |
| 735 | − * enumerating this gadget when the pullup is active and a VBUS session | |
| 736 | − * is active (the link is powered). | |
| 733 | + * Disables the D+ (or potentially D-) pullup, which the host may see | |
| 734 | + * as a disconnect (when a VBUS session is active). Not all systems | |
| 735 | + * support software pullup controls. | |
| 736 | + * | |
| 737 | + * Following a successful disconnect, invoke the ->disconnect() callback | |
| 738 | + * for the current gadget driver so that UDC drivers don't need to. | |
| 737 | 739 | * |
| 738 | 740 | * Returns zero on success, else negative errno. |
| 739 | 741 | */ |
| 740 | −int usb_gadget_connect(struct usb_gadget *gadget) | |
| 741 | −{ | |
| 742 | − int ret; | |
| 743 | − | |
| 744 | − mutex_lock(&gadget->udc->connect_lock); | |
| 745 | − ret = usb_gadget_connect_locked(gadget); | |
| 746 | − mutex_unlock(&gadget->udc->connect_lock); | |
| 747 | − | |
| 748 | − return ret; | |
| 749 | −} | |
| 750 | −EXPORT_SYMBOL_GPL(usb_gadget_connect); | |
| 751 | − | |
| 752 | −/* Internal version of usb_gadget_disconnect needs to be called with connect_lock held. */ | |
| 753 | −static int usb_gadget_disconnect_locked(struct usb_gadget *gadget) | |
| 754 | − __must_hold(&gadget->udc->connect_lock) | |
| 742 | +int usb_gadget_disconnect(struct usb_gadget *gadget) | |
| 755 | 743 | { |
| 756 | 744 | int ret = 0; |
| 757 | 745 | |
| @@ -763,12 +751,10 @@ static int usb_gadget_disconnect_locked(struct usb_gadget *gadget) · 5 unmodified lines | ||
| 763 | 751 | if (!gadget->connected) |
| 764 | 752 | goto out; |
| 765 | 753 | |
| 766 | − if (gadget->deactivated || !gadget->udc->started) { | |
| 754 | + if (gadget->deactivated) { | |
| 767 | 755 | /* |
| 768 | 756 | * If gadget is deactivated we only save new state. |
| 769 | 757 | * Gadget will stay disconnected after activation. |
| 770 | − * | |
| 771 | − * udc should have been started before gadget being pulled down. | |
| 772 | 758 | */ |
| 773 | 759 | gadget->connected = false; |
| 774 | 760 | goto out; |
| @@ -788,30 +774,6 @@ out: · 13 unmodified lines | ||
| 788 | 774 | |
| 789 | 775 | return ret; |
| 790 | 776 | } |
| 791 | − | |
| 792 | −/** | |
| 793 | − * usb_gadget_disconnect - software-controlled disconnect from USB host | |
| 794 | − * @gadget:the peripheral being disconnected | |
| 795 | − * | |
| 796 | − * Disables the D+ (or potentially D-) pullup, which the host may see | |
| 797 | − * as a disconnect (when a VBUS session is active). Not all systems | |
| 798 | − * support software pullup controls. | |
| 799 | − * | |
| 800 | − * Following a successful disconnect, invoke the ->disconnect() callback | |
| 801 | − * for the current gadget driver so that UDC drivers don't need to. | |
| 802 | − * | |
| 803 | − * Returns zero on success, else negative errno. | |
| 804 | − */ | |
| 805 | −int usb_gadget_disconnect(struct usb_gadget *gadget) | |
| 806 | −{ | |
| 807 | − int ret; | |
| 808 | − | |
| 809 | − mutex_lock(&gadget->udc->connect_lock); | |
| 810 | − ret = usb_gadget_disconnect_locked(gadget); | |
| 811 | − mutex_unlock(&gadget->udc->connect_lock); | |
| 812 | − | |
| 813 | − return ret; | |
| 814 | −} | |
| 815 | 777 | EXPORT_SYMBOL_GPL(usb_gadget_disconnect); |
| 816 | 778 | |
| 817 | 779 | /** |
| @@ -832,11 +794,10 @@ int usb_gadget_deactivate(struct usb_gadget *gadget) · 14 unmodified lines | ||
| 832 | 794 | if (gadget->deactivated) |
| 833 | 795 | goto out; |
| 834 | 796 | |
| 835 | − mutex_lock(&gadget->udc->connect_lock); | |
| 836 | 797 | if (gadget->connected) { |
| 837 | − ret = usb_gadget_disconnect_locked(gadget); | |
| 798 | + ret = usb_gadget_disconnect(gadget); | |
| 838 | 799 | if (ret) |
| 839 | − goto unlock; | |
| 800 | + goto out; | |
| 840 | 801 | |
| 841 | 802 | /* |
| 842 | 803 | * If gadget was being connected before deactivation, we want |
| @@ -846,8 +807,6 @@ int usb_gadget_deactivate(struct usb_gadget *gadget) · 3 unmodified lines | ||
| 846 | 807 | } |
| 847 | 808 | gadget->deactivated = true; |
| 848 | 809 | |
| 849 | −unlock: | |
| 850 | − mutex_unlock(&gadget->udc->connect_lock); | |
| 851 | 810 | out: |
| 852 | 811 | trace_usb_gadget_deactivate(gadget, ret); |
| 853 | 812 | |
| @@ -871,7 +830,6 @@ int usb_gadget_activate(struct usb_gadget *gadget) · 17 unmodified lines | ||
| 871 | 830 | if (!gadget->deactivated) |
| 872 | 831 | goto out; |
| 873 | 832 | |
| 874 | − mutex_lock(&gadget->udc->connect_lock); | |
| 875 | 833 | gadget->deactivated = false; |
| 876 | 834 | |
| 877 | 835 | /* |
| @@ -879,8 +837,7 @@ int usb_gadget_activate(struct usb_gadget *gadget) · 1 unmodified line | ||
| 879 | 837 | * while it was being deactivated, we call usb_gadget_connect(). |
| 880 | 838 | */ |
| 881 | 839 | if (gadget->connected) |
| 882 | − ret = usb_gadget_connect_locked(gadget); | |
| 883 | − mutex_unlock(&gadget->udc->connect_lock); | |
| 840 | + ret = usb_gadget_connect(gadget); | |
| 884 | 841 | |
| 885 | 842 | out: |
| 886 | 843 | trace_usb_gadget_activate(gadget, ret); |
| @@ -1121,13 +1078,12 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state); · 234 unmodified lines | ||
| 1121 | 1078 | |
| 1122 | 1079 | /* ------------------------------------------------------------------------- */ |
| 1123 | 1080 | |
| 1124 | −/* Acquire connect_lock before calling this function. */ | |
| 1125 | −static void usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc->connect_lock) | |
| 1081 | +static void usb_udc_connect_control(struct usb_udc *udc) | |
| 1126 | 1082 | { |
| 1127 | − if (udc->vbus && udc->started) | |
| 1128 | − usb_gadget_connect_locked(udc->gadget); | |
| 1083 | + if (udc->vbus) | |
| 1084 | + usb_gadget_connect(udc->gadget); | |
| 1129 | 1085 | else |
| 1130 | − usb_gadget_disconnect_locked(udc->gadget); | |
| 1086 | + usb_gadget_disconnect(udc->gadget); | |
| 1131 | 1087 | } |
| 1132 | 1088 | |
| 1133 | 1089 | /** |
| @@ -1143,12 +1099,10 @@ void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) · 9 unmodified lines | ||
| 1143 | 1099 | { |
| 1144 | 1100 | struct usb_udc *udc = gadget->udc; |
| 1145 | 1101 | |
| 1146 | − mutex_lock(&udc->connect_lock); | |
| 1147 | 1102 | if (udc) { |
| 1148 | 1103 | udc->vbus = status; |
| 1149 | − usb_udc_connect_control_locked(udc); | |
| 1104 | + usb_udc_connect_control(udc); | |
| 1150 | 1105 | } |
| 1151 | − mutex_unlock(&udc->connect_lock); | |
| 1152 | 1106 | } |
| 1153 | 1107 | EXPORT_SYMBOL_GPL(usb_udc_vbus_handler); |
| 1154 | 1108 | |
| @@ -1170,7 +1124,7 @@ void usb_gadget_udc_reset(struct usb_gadget *gadget, · 15 unmodified lines | ||
| 1170 | 1124 | EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); |
| 1171 | 1125 | |
| 1172 | 1126 | /** |
| 1173 | − * usb_gadget_udc_start_locked - tells usb device controller to start up | |
| 1127 | + * usb_gadget_udc_start - tells usb device controller to start up | |
| 1174 | 1128 | * @udc: The UDC to be started |
| 1175 | 1129 | * |
| 1176 | 1130 | * This call is issued by the UDC Class driver when it's about |
| @@ -1181,11 +1135,8 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); · 4 unmodified lines | ||
| 1181 | 1135 | * necessary to have it powered on. |
| 1182 | 1136 | * |
| 1183 | 1137 | * Returns zero on success, else negative errno. |
| 1184 | − * | |
| 1185 | − * Caller should acquire connect_lock before invoking this function. | |
| 1186 | 1138 | */ |
| 1187 | −static inline int usb_gadget_udc_start_locked(struct usb_udc *udc) | |
| 1188 | − __must_hold(&udc->connect_lock) | |
| 1139 | +static inline int usb_gadget_udc_start(struct usb_udc *udc) | |
| 1189 | 1140 | { |
| 1190 | 1141 | int ret; |
| 1191 | 1142 | |
| @@ -1202,7 +1153,7 @@ static inline int usb_gadget_udc_start_locked(struct usb_udc *udc) · 10 unmodified lines | ||
| 1202 | 1153 | } |
| 1203 | 1154 | |
| 1204 | 1155 | /** |
| 1205 | − * usb_gadget_udc_stop_locked - tells usb device controller we don't need it anymore | |
| 1156 | + * usb_gadget_udc_stop - tells usb device controller we don't need it anymore | |
| 1206 | 1157 | * @udc: The UDC to be stopped |
| 1207 | 1158 | * |
| 1208 | 1159 | * This call is issued by the UDC Class driver after calling |
| @@ -1211,11 +1162,8 @@ static inline int usb_gadget_udc_start_locked(struct usb_udc *udc) · 2 unmodified lines | ||
| 1211 | 1162 | * The details are implementation specific, but it can go as |
| 1212 | 1163 | * far as powering off UDC completely and disable its data |
| 1213 | 1164 | * line pullups. |
| 1214 | − * | |
| 1215 | − * Caller should acquire connect lock before invoking this function. | |
| 1216 | 1165 | */ |
| 1217 | −static inline void usb_gadget_udc_stop_locked(struct usb_udc *udc) | |
| 1218 | − __must_hold(&udc->connect_lock) | |
| 1166 | +static inline void usb_gadget_udc_stop(struct usb_udc *udc) | |
| 1219 | 1167 | { |
| 1220 | 1168 | if (!udc->started) { |
| 1221 | 1169 | dev_err(&udc->dev, "UDC had already stopped\n"); |
| @@ -1374,7 +1322,6 @@ int usb_add_gadget(struct usb_gadget *gadget) · 152 unmodified lines | ||
| 1374 | 1322 | |
| 1375 | 1323 | udc->gadget = gadget; |
| 1376 | 1324 | gadget->udc = udc; |
| 1377 | − mutex_init(&udc->connect_lock); | |
| 1378 | 1325 | |
| 1379 | 1326 | udc->started = false; |
| 1380 | 1327 | |
| @@ -1576,15 +1523,11 @@ static int gadget_bind_driver(struct device *dev) · 195 unmodified lines | ||
| 1576 | 1523 | if (ret) |
| 1577 | 1524 | goto err_bind; |
| 1578 | 1525 | |
| 1579 | − mutex_lock(&udc->connect_lock); | |
| 1580 | − ret = usb_gadget_udc_start_locked(udc); | |
| 1581 | − if (ret) { | |
| 1582 | − mutex_unlock(&udc->connect_lock); | |
| 1526 | + ret = usb_gadget_udc_start(udc); | |
| 1527 | + if (ret) | |
| 1583 | 1528 | goto err_start; |
| 1584 | − } | |
| 1585 | 1529 | usb_gadget_enable_async_callbacks(udc); |
| 1586 | − usb_udc_connect_control_locked(udc); | |
| 1587 | − mutex_unlock(&udc->connect_lock); | |
| 1530 | + usb_udc_connect_control(udc); | |
| 1588 | 1531 | |
| 1589 | 1532 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
| 1590 | 1533 | return 0; |
| @@ -1615,14 +1558,12 @@ static void gadget_unbind_driver(struct device *dev) · 24 unmodified lines | ||
| 1615 | 1558 | |
| 1616 | 1559 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
| 1617 | 1560 | |
| 1618 | − mutex_lock(&udc->connect_lock); | |
| 1619 | − usb_gadget_disconnect_locked(gadget); | |
| 1561 | + usb_gadget_disconnect(gadget); | |
| 1620 | 1562 | usb_gadget_disable_async_callbacks(udc); |
| 1621 | 1563 | if (gadget->irq) |
| 1622 | 1564 | synchronize_irq(gadget->irq); |
| 1623 | 1565 | udc->driver->unbind(gadget); |
| 1624 | − usb_gadget_udc_stop_locked(udc); | |
| 1625 | − mutex_unlock(&udc->connect_lock); | |
| 1566 | + usb_gadget_udc_stop(udc); | |
| 1626 | 1567 | |
| 1627 | 1568 | mutex_lock(&udc_lock); |
| 1628 | 1569 | driver->is_bound = false; |
| @@ -1708,15 +1649,11 @@ static ssize_t soft_connect_store(struct device *dev, · 79 unmodified lines | ||
| 1708 | 1649 | } |
| 1709 | 1650 | |
| 1710 | 1651 | if (sysfs_streq(buf, "connect")) { |
| 1711 | − mutex_lock(&udc->connect_lock); | |
| 1712 | − usb_gadget_udc_start_locked(udc); | |
| 1713 | − usb_gadget_connect_locked(udc->gadget); | |
| 1714 | − mutex_unlock(&udc->connect_lock); | |
| 1652 | + usb_gadget_udc_start(udc); | |
| 1653 | + usb_gadget_connect(udc->gadget); | |
| 1715 | 1654 | } else if (sysfs_streq(buf, "disconnect")) { |
| 1716 | − mutex_lock(&udc->connect_lock); | |
| 1717 | − usb_gadget_disconnect_locked(udc->gadget); | |
| 1718 | − usb_gadget_udc_stop_locked(udc); | |
| 1719 | − mutex_unlock(&udc->connect_lock); | |
| 1655 | + usb_gadget_disconnect(udc->gadget); | |
| 1656 | + usb_gadget_udc_stop(udc); | |
| 1720 | 1657 | } else { |
| 1721 | 1658 | dev_err(dev, "unsupported command '%s'\n", buf); |
| 1722 | 1659 | ret = -EINVAL; |
| @@ -119,11 +119,13 @@ static int uhci_pci_init(struct usb_hcd *hcd) · 118 unmodified lines | ||
| 119 | 119 | |
| 120 | 120 | uhci->rh_numports = uhci_count_ports(hcd); |
| 121 | 121 | |
| 122 | − /* Intel controllers report the OverCurrent bit active on. | |
| 123 | − * VIA controllers report it active off, so we'll adjust the | |
| 124 | − * bit value. (It's not standardized in the UHCI spec.) | |
| 122 | + /* | |
| 123 | + * Intel controllers report the OverCurrent bit active on. VIA | |
| 124 | + * and ZHAOXIN controllers report it active off, so we'll adjust | |
| 125 | + * the bit value. (It's not standardized in the UHCI spec.) | |
| 125 | 126 | */ |
| 126 | − if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_VIA) | |
| 127 | + if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_VIA || | |
| 128 | + to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_ZHAOXIN) | |
| 127 | 129 | uhci->oc_low = 1; |
| 128 | 130 | |
| 129 | 131 | /* HP's server management chip requires a longer port reset delay. */ |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | #include <linux/module.h> |
| 14 | 14 | #include <linux/acpi.h> |
| 15 | 15 | #include <linux/reset.h> |
| 16 | +#include <linux/suspend.h> | |
| 16 | 17 | |
| 17 | 18 | #include "xhci.h" |
| 18 | 19 | #include "xhci-trace.h" |
| @@ -387,7 +388,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) · 368 unmodified lines | ||
| 387 | 388 | |
| 388 | 389 | if (pdev->vendor == PCI_VENDOR_ID_AMD && |
| 389 | 390 | pdev->device == PCI_DEVICE_ID_AMD_RENOIR_XHCI) |
| 390 | − xhci->quirks |= XHCI_BROKEN_D3COLD; | |
| 391 | + xhci->quirks |= XHCI_BROKEN_D3COLD_S2I; | |
| 391 | 392 | |
| 392 | 393 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) { |
| 393 | 394 | xhci->quirks |= XHCI_LPM_SUPPORT; |
| @@ -801,9 +802,16 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) · 407 unmodified lines | ||
| 801 | 802 | * Systems with the TI redriver that loses port status change events |
| 802 | 803 | * need to have the registers polled during D3, so avoid D3cold. |
| 803 | 804 | */ |
| 804 | − if (xhci->quirks & (XHCI_COMP_MODE_QUIRK | XHCI_BROKEN_D3COLD)) | |
| 805 | + if (xhci->quirks & XHCI_COMP_MODE_QUIRK) | |
| 805 | 806 | pci_d3cold_disable(pdev); |
| 806 | 807 | |
| 808 | +#ifdef CONFIG_SUSPEND | |
| 809 | + /* d3cold is broken, but only when s2idle is used */ | |
| 810 | + if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE && | |
| 811 | + xhci->quirks & (XHCI_BROKEN_D3COLD_S2I)) | |
| 812 | + pci_d3cold_disable(pdev); | |
| 813 | +#endif | |
| 814 | + | |
| 807 | 815 | if (xhci->quirks & XHCI_PME_STUCK_QUIRK) |
| 808 | 816 | xhci_pme_quirk(hcd); |
| 809 | 817 | |
| @@ -276,6 +276,26 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, · 275 unmodified lines | ||
| 276 | 276 | trace_xhci_inc_enq(ring); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | +static int xhci_num_trbs_to(struct xhci_segment *start_seg, union xhci_trb *start, | |
| 280 | + struct xhci_segment *end_seg, union xhci_trb *end, | |
| 281 | + unsigned int num_segs) | |
| 282 | +{ | |
| 283 | + union xhci_trb *last_on_seg; | |
| 284 | + int num = 0; | |
| 285 | + int i = 0; | |
| 286 | + | |
| 287 | + do { | |
| 288 | + if (start_seg == end_seg && end >= start) | |
| 289 | + return num + (end - start); | |
| 290 | + last_on_seg = &start_seg->trbs[TRBS_PER_SEGMENT - 1]; | |
| 291 | + num += last_on_seg - start; | |
| 292 | + start_seg = start_seg->next; | |
| 293 | + start = start_seg->trbs; | |
| 294 | + } while (i++ <= num_segs); | |
| 295 | + | |
| 296 | + return -EINVAL; | |
| 297 | +} | |
| 298 | + | |
| 279 | 299 | /* |
| 280 | 300 | * Check to see if there's room to enqueue num_trbs on the ring and make sure |
| 281 | 301 | * enqueue pointer will not advance into dequeue segment. See rules above. |
| @@ -2140,6 +2160,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 1858 unmodified lines | ||
| 2140 | 2160 | u32 trb_comp_code) |
| 2141 | 2161 | { |
| 2142 | 2162 | struct xhci_ep_ctx *ep_ctx; |
| 2163 | + int trbs_freed; | |
| 2143 | 2164 | |
| 2144 | 2165 | ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); |
| 2145 | 2166 | |
| @@ -2209,9 +2230,15 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 63 unmodified lines | ||
| 2209 | 2230 | } |
| 2210 | 2231 | |
| 2211 | 2232 | /* Update ring dequeue pointer */ |
| 2233 | + trbs_freed = xhci_num_trbs_to(ep_ring->deq_seg, ep_ring->dequeue, | |
| 2234 | + td->last_trb_seg, td->last_trb, | |
| 2235 | + ep_ring->num_segs); | |
| 2236 | + if (trbs_freed < 0) | |
| 2237 | + xhci_dbg(xhci, "Failed to count freed trbs at TD finish\n"); | |
| 2238 | + else | |
| 2239 | + ep_ring->num_trbs_free += trbs_freed; | |
| 2212 | 2240 | ep_ring->dequeue = td->last_trb; |
| 2213 | 2241 | ep_ring->deq_seg = td->last_trb_seg; |
| 2214 | − ep_ring->num_trbs_free += td->num_trbs - 1; | |
| 2215 | 2242 | inc_deq(xhci, ep_ring); |
| 2216 | 2243 | |
| 2217 | 2244 | return xhci_td_cleanup(xhci, td, ep_ring, td->status); |
| @@ -1901,7 +1901,7 @@ struct xhci_hcd { · 1900 unmodified lines | ||
| 1901 | 1901 | #define XHCI_DISABLE_SPARSE BIT_ULL(38) |
| 1902 | 1902 | #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39) |
| 1903 | 1903 | #define XHCI_NO_SOFT_RETRY BIT_ULL(40) |
| 1904 | −#define XHCI_BROKEN_D3COLD BIT_ULL(41) | |
| 1904 | +#define XHCI_BROKEN_D3COLD_S2I BIT_ULL(41) | |
| 1905 | 1905 | #define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42) |
| 1906 | 1906 | #define XHCI_SUSPEND_RESUME_CLKS BIT_ULL(43) |
| 1907 | 1907 | #define XHCI_RESET_TO_DEFAULT BIT_ULL(44) |
| @@ -406,22 +406,25 @@ static DEF_SCSI_QCMD(queuecommand) · 405 unmodified lines | ||
| 406 | 406 | ***********************************************************************/ |
| 407 | 407 | |
| 408 | 408 | /* Command timeout and abort */ |
| 409 | −static int command_abort(struct scsi_cmnd *srb) | |
| 409 | +static int command_abort_matching(struct us_data *us, struct scsi_cmnd *srb_match) | |
| 410 | 410 | { |
| 411 | − struct us_data *us = host_to_us(srb->device->host); | |
| 412 | − | |
| 413 | − usb_stor_dbg(us, "%s called\n", __func__); | |
| 414 | − | |
| 415 | 411 | /* |
| 416 | 412 | * us->srb together with the TIMED_OUT, RESETTING, and ABORTING |
| 417 | 413 | * bits are protected by the host lock. |
| 418 | 414 | */ |
| 419 | 415 | scsi_lock(us_to_host(us)); |
| 420 | 416 | |
| 421 | − /* Is this command still active? */ | |
| 422 | − if (us->srb != srb) { | |
| 417 | + /* is there any active pending command to abort ? */ | |
| 418 | + if (!us->srb) { | |
| 423 | 419 | scsi_unlock(us_to_host(us)); |
| 424 | 420 | usb_stor_dbg(us, "-- nothing to abort\n"); |
| 421 | + return SUCCESS; | |
| 422 | + } | |
| 423 | + | |
| 424 | + /* Does the command match the passed srb if any ? */ | |
| 425 | + if (srb_match && us->srb != srb_match) { | |
| 426 | + scsi_unlock(us_to_host(us)); | |
| 427 | + usb_stor_dbg(us, "-- pending command mismatch\n"); | |
| 425 | 428 | return FAILED; |
| 426 | 429 | } |
| 427 | 430 | |
| @@ -444,6 +447,14 @@ static int command_abort(struct scsi_cmnd *srb) · 16 unmodified lines | ||
| 444 | 447 | return SUCCESS; |
| 445 | 448 | } |
| 446 | 449 | |
| 450 | +static int command_abort(struct scsi_cmnd *srb) | |
| 451 | +{ | |
| 452 | + struct us_data *us = host_to_us(srb->device->host); | |
| 453 | + | |
| 454 | + usb_stor_dbg(us, "%s called\n", __func__); | |
| 455 | + return command_abort_matching(us, srb); | |
| 456 | +} | |
| 457 | + | |
| 447 | 458 | /* |
| 448 | 459 | * This invokes the transport reset mechanism to reset the state of the |
| 449 | 460 | * device |
| @@ -455,6 +466,9 @@ static int device_reset(struct scsi_cmnd *srb) · 5 unmodified lines | ||
| 455 | 466 | |
| 456 | 467 | usb_stor_dbg(us, "%s called\n", __func__); |
| 457 | 468 | |
| 469 | + /* abort any pending command before reset */ | |
| 470 | + command_abort_matching(us, NULL); | |
| 471 | + | |
| 458 | 472 | /* lock the device pointers and do the reset */ |
| 459 | 473 | mutex_lock(&(us->dev_mutex)); |
| 460 | 474 | result = us->transport_reset(us); |
| @@ -516,6 +516,10 @@ static ssize_t pin_assignment_show(struct device *dev, · 515 unmodified lines | ||
| 516 | 516 | |
| 517 | 517 | mutex_unlock(&dp->lock); |
| 518 | 518 | |
| 519 | + /* get_current_pin_assignments can return 0 when no matching pin assignments are found */ | |
| 520 | + if (len == 0) | |
| 521 | + len++; | |
| 522 | + | |
| 519 | 523 | buf[len - 1] = '\n'; |
| 520 | 524 | return len; |
| 521 | 525 | } |
| @@ -886,6 +886,9 @@ static void tps6598x_remove(struct i2c_client *client) · 885 unmodified lines | ||
| 886 | 886 | { |
| 887 | 887 | struct tps6598x *tps = i2c_get_clientdata(client); |
| 888 | 888 | |
| 889 | + if (!client->irq) | |
| 890 | + cancel_delayed_work_sync(&tps->wq_poll); | |
| 891 | + | |
| 889 | 892 | tps6598x_disconnect(tps, 0); |
| 890 | 893 | typec_unregister_port(tps->port); |
| 891 | 894 | usb_role_switch_put(tps->role_sw); |
| @@ -74,6 +74,7 @@ struct class { · 73 unmodified lines | ||
| 74 | 74 | struct class_dev_iter { |
| 75 | 75 | struct klist_iter ki; |
| 76 | 76 | const struct device_type *type; |
| 77 | + struct subsys_private *sp; | |
| 77 | 78 | }; |
| 78 | 79 | |
| 79 | 80 | int __must_check class_register(const struct class *class); |
| @@ -443,7 +443,7 @@ static inline struct usb_composite_driver *to_cdriver( · 442 unmodified lines | ||
| 443 | 443 | * @bcd_webusb_version: 0x0100 by default, WebUSB specification version |
| 444 | 444 | * @b_webusb_vendor_code: 0x0 by default, vendor code for WebUSB |
| 445 | 445 | * @landing_page: empty by default, landing page to announce in WebUSB |
| 446 | − * @use_webusb:: false by default, interested gadgets set it | |
| 446 | + * @use_webusb: false by default, interested gadgets set it | |
| 447 | 447 | * @os_desc_config: the configuration to be used with OS descriptors |
| 448 | 448 | * @setup_pending: true when setup request is queued but not completed |
| 449 | 449 | * @os_desc_pending: true when os_desc request is queued but not completed |