summaryrefslogtreecommitdiff
path: root/drivers/usb/host/xhci-ring.c
AgeCommit message (Collapse)Author
2013-10-16usb: xhci: kill a conditional when toggling cycleDan Williams
Perform an unconditional toggle of the cycle bit with 'xor'. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: replace 'event' with 'cmd_comp_code' in set_deq and reset_ep handlersXenia Ragiadakou
This patch replaces the 'event' argument of xhci_handle_cmd_set_deq() and xhci_handle_cmd_reset_ep(), which is used to retrieve the command completion status code, with the cmd_comp_code directly, since it is available. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: add argument 'slot_id' in stop_ep, set_deq and reset_ep cmd handlersXenia Ragiadakou
Since the Slot ID field in the command completion event matches the Slot ID field in the associated command TRB for the Stop Endpoint, Set Dequeue Pointer and Reset Endpoint commands, this patch adds in the handlers of their completion events a 'slot_id' argument and removes the slot id calculation in each of them. Also, a WARN_ON() was added in case the slot ids reported by command TRB and event TRB differ (although according to xhci spec rev1.0 that should not happen) Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: replace 'xhci->cmd_ring->dequeue' with 'trb' in stop_ep cmd handlerXenia Ragiadakou
This patch replaces 'xhci->cmd_ring->dequeue' with 'trb', the address of the command TRB, since it is available to reduce line length. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: add variable 'cmd_type' in handle_cmd_completion()Xenia Ragiadakou
This patch adds a new variable 'cmd_type' to hold the command type so that switch cases can be simplified by removing TRB_TYPE() macro improving code readability. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: add variable 'cmd_trb' in handle_cmd_completion()Xenia Ragiadakou
This patch adds a new variable 'cmd_trb' to hold the address of the command TRB, that is associated with the command completion event, and to replace repetitions of xhci->cmd_ring->dequeue into the code. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: add variable 'cmd_comp_code' in handle_cmd_completion()Xenia Ragiadakou
This patch adds a new variable 'cmd_comp_code' to hold the command completion status code aiming to reduce code duplication and to improve code readability. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: refactor TRB_CONFIG_EP case into functionXenia Ragiadakou
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_CONFIG_EP switch case, in handle_cmd_completion(), into a fuction named xhci_handle_cmd_config_ep(). There were added two additional variables, 'add_flags' and 'drop_flags', to reduce line length below 80 chars and improve code readability. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: remove unused 'ep_ring' variable in handle_cmd_completion()Xenia Ragiadakou
This patch removes the variable 'ep_ring' that is assigned in TRB_CONFIG_EP switch case but never used. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: refactor TRB_EVAL_CONTEXT case into functionXenia Ragiadakou
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_EVAL_CONTEXT switch case in handle_cmd_completion() into a fuction named xhci_handle_cmd_eval_ctx(). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: refactor TRB_NEC_GET_FW case into functionXenia Ragiadakou
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_NEC_GET_FW switch case in handle_cmd_completion() into a fuction named xhci_handle_cmd_nec_get_fw(). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: refactor TRB_RESET_DEV case into functionXenia Ragiadakou
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_RESET_DEV switch case in handle_cmd_completion() into a fuction named xhci_handle_cmd_reset_dev(). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: use completion event's slot id rather than dig it out of commandXenia Ragiadakou
Since the slot id retrieved from the Reset Device TRB matches the slot id in the command completion event, which is available, there is no need to determine it again. This patch removes the uneccessary reassignment to slot id and adds a WARN_ON in case the two Slot ID fields differ (although according xhci spec rev1.0 they should not differ). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: refactor TRB_ADDR_DEV case into functionXenia Ragiadakou
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_ADDR_DEV switch case in handle_cmd_completion() into a fuction named xhci_handle_cmd_addr_dev(). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: refactor TRB_DISABLE_SLOT case into functionXenia Ragiadakou
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_DISABLE_SLOT switch case in handle_cmd_completion() into a fuction named xhci_handle_cmd_disable_slot(). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: refactor TRB_ENABLE_SLOT case into functionXenia Ragiadakou
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_ENABLE_SLOT switch case in handle_cmd_completion() into a fuction named xhci_handle_cmd_enable_slot(). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: rename existing Command Completion Event handlersXenia Ragiadakou
This patch renames the function handlers of a triggered Command Completion Event that correspond to each command type into 'xhci_handle_cmd_<type>'. That is done to give a consistent naming space to all the functions that handle Command Completion Events and that will permit the code reader to reference to them more easily. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-10-16xhci: remove unused argument from xhci_giveback_urb_in_irq()Xenia Ragiadakou
This patch removes the "adjective" argument from xhci_giveback_urb_in_irq(), since it is not used in the function anymore. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-09-23xhci: Fix race between ep halt and URB cancellationFlorian Wolter
The halted state of a endpoint cannot be cleared over CLEAR_HALT from a user process, because the stopped_td variable was overwritten in the handle_stopped_endpoint() function. So the xhci_endpoint_reset() function will refuse the reset and communication with device can not run over this endpoint. https://bugzilla.kernel.org/show_bug.cgi?id=60699 Signed-off-by: Florian Wolter <wolly84@web.de> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-09-23usb: Fix xHCI host issues on remote wakeup.Sarah Sharp
When a device signals remote wakeup on a roothub, and the suspend change bit is set, the host controller driver must not give control back to the USB core until the port goes back into the active state. EHCI accomplishes this by waiting in the get port status function until the PORT_RESUME bit is cleared: /* stop resume signaling */ temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME); ehci_writel(ehci, temp, status_reg); clear_bit(wIndex, &ehci->resuming_ports); retval = ehci_handshake(ehci, status_reg, PORT_RESUME, 0, 2000 /* 2msec */); Similarly, the xHCI host should wait until the port goes into U0, before passing control up to the USB core. When the port transitions from the RExit state to U0, the xHCI driver will get a port status change event. We need to wait for that event before passing control up to the USB core. After the port transitions to the active state, the USB core should time a recovery interval before it talks to the device. The length of that recovery interval is TRSMRCY, 10 ms, mentioned in the USB 2.0 spec, section 7.1.7.7. The previous xHCI code (which did not wait for the port to go into U0) would cause the USB core to violate that recovery interval. This bug caused numerous USB device disconnects on remote wakeup under ChromeOS and a Lynx Point LP xHCI host that takes up to 20 ms to move from RExit to U0. ChromeOS is very aggressive about power savings, and sets the autosuspend_delay to 100 ms, and disables USB persist. I attempted to replicate this bug with Ubuntu 12.04, but could not. I used Ubuntu 12.04 on the same platform, with the same BIOS that the bug was triggered on ChromeOS with. I also changed the USB sysfs settings as described above, but still could not reproduce the bug under Ubuntu. It may be that ChromeOS userspace triggers this bug through additional settings. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-09-23xhci: Ensure a command structure points to the correct trb on the command ringMathias Nyman
If a command on the command ring needs to be cancelled before it is handled it can be turned to a no-op operation when the ring is stopped. We want to store the command ring enqueue pointer in the command structure when the command in enqueued for the cancellation case. Some commands used to store the command ring dequeue pointers instead of enqueue (these often worked because enqueue happends to equal dequeue quite often) Other commands correctly used the enqueue pointer but did not check if it pointed to a valid trb or a link trb, this caused for example stop endpoint command to timeout in xhci_stop_device() in about 2% of suspend/resume cases. This should also solve some weird behavior happening in command cancellation cases. This patch is based on a patch submitted by Sarah Sharp to linux-usb, but then forgotten: http://marc.info/?l=linux-usb&m=136269803207465&w=2 This patch should be backported to kernels as old as 3.7, that contain the commit b92cc66c047ff7cf587b318fe377061a353c120f "xHCI: add aborting command ring function" Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2013-09-23xhci: Fix oops happening after address device timeoutMathias Nyman
When a command times out, the command ring is first aborted, and then stopped. If the command ring is empty when it is stopped the stop event will point to next command which is not yet set. xHCI tries to handle this next event often causing an oops. Don't handle command completion events on stopped cmd ring if ring is empty. This patch should be backported to kernels as old as 3.7, that contain the commit b92cc66c047ff7cf587b318fe377061a353c120f "xHCI: add aborting command ring function" Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Reported-by: Giovanni <giovanni.nervi@yahoo.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2013-08-27xhci:prevent "callbacks suppressed" when debug is not enabledDmitry Kasatkin
When debug is not enabled and dev_dbg() will expand to nothing, log might be flooded with "callbacks suppressed". If it was not done on purpose, better to use dev_dbg_ratelimited() instead. Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-08-14xhci: trace debug statements related to ring expansionXenia Ragiadakou
This patch defines a new trace event, which is called xhci_dbg_ring_expansion and belongs to the event class xhci_log_msg, and adds tracepoints that trace the debug messages associated with the expansion of endpoint ring when there is not enough space allocated to hold all pending TRBs. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-08-14xhci: trace debug statements for urb cancellationXenia Ragiadakou
This patch defines a new trace event, which is called xhci_dbg_cancel_urb and belongs to the event class xhci_log_msg, and adds tracepoints that trace the debug messages related to the removal of a cancelled URB from the endpoint's transfer ring. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-08-13xhci: add xhci_cmd_completion trace eventXenia Ragiadakou
This patch creates a new event class, called xhci_log_event, and defines the xhci_cmd_completion trace event used for tracing the commands issued to xHC that generate a completion event in the event ring. This info can be used, later, to print, in a human readable way, the completion status and flags as well as the command's type and fields using the trace-cmd tool and the appropriate plugin. Also, a tracepoint is added in handle_cmd_completion(). Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-08-13xhci: add trace for debug messages related to endpoint resetXenia Ragiadakou
This patch defines a new trace event, which is called xhci_dbg_reset_ep and belongs in the event class xhci_log_msg, and adds tracepoints that trace the debug messages associated with resetting an endpoint after the reception of a STALL packet. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-08-13xhci: add trace for debug messages related to quirksXenia Ragiadakou
This patch defines a new trace event, which is called xhci_dbg_quirks and belongs in the event class xhci_log_msg, and adds tracepoints that trace the debug messages associated with xHCs' quirks. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-08-13xhci: add trace for debug messages related to changing contextsXenia Ragiadakou
This patch defines a new trace event, which is called xhci_dbg_context_change and belongs in the event class xhci_log_msg, and adds tracepoints for tracing the debug messages related to context updates performed with Configure Endpoint and Evaluate Context commands. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-07-25xhci: fix null pointer dereference on ring_doorbell_for_active_ringsOleksij Rempel
in some cases where device is attched to xhci port and do not responding, for example ath9k_htc with stalled firmware, kernel will crash on ring_doorbell_for_active_rings. This patch check if pointer exist before it is used. This patch should be backported to kernels as old as 2.6.35, that contain the commit e9df17eb1408cfafa3d1844bfc7f22c7237b31b8 "USB: xhci: Correct assumptions about number of rings per endpoint" Signed-off-by: Oleksij Rempel <linux@rempel-privat.de> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2013-06-14xhci: Remove BUG_ON in xhci_get_input_control_ctx.Sarah Sharp
Fail gracefully, instead of causing the kernel to panic, if the input control context doesn't have the right type (XHCI_CTX_TYPE_INPUT). Push finding the pointer to the input control context up into functions that can fail. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: John Youn <johnyoun@synopsys.com>
2013-06-05usb/xhci: unify parameter of xhci_msi_irqAlex Shi
According to Felipe and Alan's comments the second parameter of irq handler should be 'void *' not a specific structure pointer. So change it. Signed-off-by: Alex Shi <alex.shi@intel.com> Acked-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-03-25xhci: Don't warn on empty ring for suspended devices.Sarah Sharp
When a device attached to the roothub is suspended, the endpoint rings are stopped. The host may generate a completion event with the completion code set to 'Stopped' or 'Stopped Invalid' when the ring is halted. The current xHCI code prints a warning in that case, which can be really annoying if the USB device is coming into and out of suspend. Remove the unnecessary warning. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Tested-by: Stephen Hemminger <stephen@networkplumber.org>
2013-03-25usb: xhci: Fix TRB transfer length macro used for Event TRB.Vivek Gautam
Use proper macro while extracting TRB transfer length from Transfer event TRBs. Adding a macro EVENT_TRB_LEN (bits 0:23) for the same, and use it instead of TRB_LEN (bits 0:16) in case of event TRBs. This patch should be backported to kernels as old as 2.6.31, that contain the commit b10de142119a676552df3f0d2e3a9d647036c26a "USB: xhci: Bulk transfer support". This patch will have issues applying to older kernels. Signed-off-by: Vivek gautam <gautam.vivek@samsung.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2013-03-25usb: xhci: fix build warningPeter Chen
/home/b29397/work/code/git/linus/linux-2.6/drivers/usb/host/xhci-ring.c: In function ‘handle_port_status’: /home/b29397/work/code/git/linus/linux-2.6/drivers/usb/host/xhci-ring.c:1580: warning: ‘hcd’ may be used uninitialized in this function Signed-off-by: Peter Chen <peter.chen@freescale.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-02-08Merge usb-linus branch into usb-nextGreg Kroah-Hartman
This pulls in a bunch of fixes that are in Linus's tree because we need them here for testing and development. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-24USB: XHCI: fix memory leak of URB-private dataAlan Stern
This patch (as1640) fixes a memory leak in xhci-hcd. The urb_priv data structure isn't always deallocated in the handle_tx_event() routine for non-control transfers. The patch adds a kfree() call so that all paths end up freeing the memory properly. This patch should be backported to kernels as old as 2.6.36, that contain the commit 8e51adccd4c4b9ffcd509d7f2afce0a906139f75 "USB: xHCI: Introduce urb_priv structure" Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Reported-and-tested-by: Martin Mokrejs <mmokrejs@fold.natur.cuni.cz> CC: <stable@vger.kernel.org>
2013-01-24drivers: xhci: fix incorrect bit testNickolai Zeldovich
Fix incorrect bit test that originally showed up in 4ee823b83bc9851743fab756c76b27d6a1e2472b "USB/xHCI: Support device-initiated USB 3.0 resume." Use '&' instead of '&&'. This should be backported to kernels as old as 3.4. Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2013-01-24xhci: Fix TD size for isochronous URBs.Sarah Sharp
To calculate the TD size for a particular TRB in an isoc TD, we need know the endpoint's max packet size. Isochronous endpoints also encode the number of additional service opportunities in their wMaxPacketSize field. The TD size calculation did not mask off those bits before using the field. This resulted in incorrect TD size information for isochronous TRBs when an URB frame buffer crossed a 64KB boundary. For example: - an isoc endpoint has 2 additional service opportunites and a max packet size of 1020 bytes - a frame transfer buffer contains 3060 bytes - one frame buffer crosses a 64KB boundary, and must be split into one 1276 byte TRB, and one 1784 byte TRB. The TD size is is the number of packets that remain to be transferred for a TD after processing all the max packet sized packets in the current TRB and all previous TRBs. For this TD, the number of packets to be transferred is (3060 / 1020), or 3. The first TRB contains 1276 bytes, which means it contains one full packet, and a 256 byte remainder. After processing all the max packet-sized packets in the first TRB, the host will have 2 packets left to transfer. The old code would calculate the TD size for the first TRB as: total packet count = DIV_ROUND_UP (TD length / endpoint wMaxPacketSize) total packet count - (first TRB length / endpoint wMaxPacketSize) The math should have been: total packet count = DIV_ROUND_UP (3060 / 1020) = 3 3 - (1276 / 1020) = 2 Since the old code didn't mask off the additional service interval bits from the wMaxPacketSize field, the math ended up as total packet count = DIV_ROUND_UP (3060 / 5116) = 1 1 - (1276 / 5116) = 1 Fix this by masking off the number of additional service opportunities in the wMaxPacketSize field. This patch should be backported to stable kernels as old as 3.0, that contain the commit 4da6e6f247a2601ab9f1e63424e4d944ed4124f3 "xhci 1.0: Update TD size field format." It may not apply well to kernels older than 3.2 because of commit 29cc88979a8818cd8c5019426e945aed118b400e "USB: use usb_endpoint_maxp() instead of le16_to_cpu()". Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2013-01-24xhci: Fix isoc TD encoding.Sarah Sharp
An isochronous TD is comprised of one isochronous TRB chained to zero or more normal TRBs. Only the isoc TRB has the TBC and TLBPC fields. The normal TRBs must set those fields to zeroes. The code was setting the TBC and TLBPC fields for both isoc and normal TRBs. Fix this. This should be backported to stable kernels as old as 3.0, that contain the commit b61d378f2da41c748aba6ca19d77e1e1c02bcea5 " xhci 1.0: Set transfer burst last packet count field." Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2013-01-03usb: host: xhci: remove unused trb var in xhci_irq()Javier Martinez Canillas
The union xhci_trb *trb variable is defined and assigned inside the xHCI IRQ handler function but is never used. Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2013-01-03xhci: Avoid "dead ports", add roothub port polling.Sarah Sharp
The USB core hub thread (khubd) is designed with external USB hubs in mind. It expects that if a port status change bit is set, the hub will continue to send a notification through the hub status data transfer. Basically, it expects hub notifications to be level-triggered. The xHCI host controller is designed to be edge-triggered on the logical 'OR' of all the port status change bits. When all port status change bits are clear, and a new change bit is set, the xHC will generate a Port Status Change Event. If another change bit is set in the same port status register before the first bit is cleared, it will not send another event. This means that the hub code may lose port status changes because of race conditions between clearing change bits. The user sees this as a "dead port" that doesn't react to device connects. The fix is to turn on port polling whenever a new change bit is set. Once the USB core issues a hub status request that shows that no change bits are set in any USB ports, turn off port polling. We can't allow the USB core to poll the roothub for port events during host suspend because if the PCI host is in D3cold, the port registers will be all f's. Instead, stop the port polling timer, and unconditionally restart it when the host resumes. If there are no port change bits set after the resume, the first call to hub_status_data will disable polling. This patch should be backported to stable kernels with the first xHCI support, 2.6.31 and newer, that include the commit 0f2a79300a1471cf92ab43af165ea13555c8b0a5 "USB: xhci: Root hub support." There will be merge conflicts because the check for HC_STATE_SUSPENDED was moved into xhci_suspend in 3.8. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Cc: stable@vger.kernel.org
2012-11-12xHCI: Fix TD Size calculation on 1.0 hosts.Sarah Sharp
The xHCI 1.0 specification made a change to the TD Size field in TRBs. The value is now the number of packets that remain to be sent in the TD, not including this TRB. The TD Size value for the last TRB in a TD must always be zero. The xHCI function xhci_v1_0_td_remainder() attempts to calculate this, but it gets it wrong. First, it erroneously reuses the old xhci_td_remainder function, which will right shift the value by 10. The xHCI 1.0 spec as of June 2011 says nothing about right shifting by 10. Second, it does not set the TD size for the last TRB in a TD to zero. Third, it uses roundup instead of DIV_ROUND_UP. The total packet count is supposed to be the total number of bytes in this TD, divided by the max packet size, rounded up. DIV_ROUND_UP is the right function to use in that case. With the old code, a TD on an endpoint with max packet size 1024 would be set up like so: TRB 1, TRB length = 600 bytes, TD size = 0 TRB 1, TRB length = 200 bytes, TD size = 0 TRB 1, TRB length = 100 bytes, TD size = 0 With the new code, the TD would be set up like this: TRB 1, TRB length = 600 bytes, TD size = 1 TRB 1, TRB length = 200 bytes, TD size = 1 TRB 1, TRB length = 100 bytes, TD size = 0 This commit should be backported to kernels as old as 3.0, that contain the commit 4da6e6f247a2601ab9f1e63424e4d944ed4124f3 "xhci 1.0: Update TD size field format." Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Reported-by: Chintan Mehta <chintan.mehta@sibridgetech.com> Reported-by: Shimmer Huang <shimmering.h@gmail.com> Tested-by: Bhavik Kothari <bhavik.kothari@sibridgetech.com> Tested-by: Shimmer Huang <shimmering.h@gmail.com> Cc: stable@vger.kernel.org
2012-11-12xhci: Avoid global symbol pollution with handshake.Sarah Sharp
Non-static xHCI driver symbols should start with the "xhci_" prefix, in order to avoid namespace pollution. Rename the "handshake" function to "xhci_handshake". Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Reported-by: Ben Hutchings <ben@decadent.org.uk>
2012-10-25xhci: Fix potential NULL ptr deref in command cancellation.Sarah Sharp
The command cancellation code doesn't check whether find_trb_seg() couldn't find the segment that contains the TRB to be canceled. This could cause a NULL pointer deference later in the function when next_trb is called. It's unlikely to happen unless something is wrong with the command ring pointers, so add some debugging in case it happens. This patch should be backported to stable kernels as old as 3.0, that contain the commit b63f4053cc8aa22a98e3f9a97845afe6c15d0a0d "xHCI: handle command after aborting the command ring". Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2012-09-25xhci: Intel Panther Point BEI quirk.Sarah Sharp
When a device with an isochronous endpoint is behind a hub plugged into the Intel Panther Point xHCI host controller, and the driver submits multiple frames per URB, the xHCI driver will set the Block Event Interrupt (BEI) flag on all but the last TD for the URB. This causes the host controller to place an event on the event ring, but not send an interrupt. When the last TD for the URB completes, BEI is cleared, and we get an interrupt for the whole URB. However, under a Panther Point xHCI host controller, if the parent hub is unplugged when one or more events from transfers with BEI set are on the event ring, a port status change event is placed on the event ring, but no interrupt is generated. This means URBs stop completing, and the USB device disconnect is not noticed. Something like a USB headset will cause mplayer to hang when the device is disconnected. If another transfer is sent (such as running `sudo lsusb -v`), the next transfer event seems to "unstick" the event ring, the xHCI driver gets an interrupt, and the disconnect is reported to the USB core. The fix is not to use the BEI flag under the Panther Point xHCI host. This will impact power consumption and system responsiveness, because the xHCI driver will receive an interrupt for every frame in all isochronous URBs instead of once per URB. Intel chipset developers confirm that this bug will be hit if the BEI flag is used on any endpoint, not just ones that are behind a hub. This patch should be backported to kernels as old as 3.0, that contain the commit 69e848c2090aebba5698a1620604c7dccb448684 "Intel xhci: Support EHCI/xHCI port switching." Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Cc: stable@vger.kernel.org
2012-09-13drivers/usb/host/xhci-ring.c: removes unnecessary semicolonPeter Senna Tschudin
removes unnecessary semicolon Found by Coccinelle: http://coccinelle.lip6.fr/ Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-09-13usb: host: xhci: sparse fixesFelipe Balbi
drivers/usb/host/xhci.c:1826:14: warning: symbol 'xhci_get_block_size' was not declared. Should it be static? drivers/usb/host/xhci.c:1844:14: warning: symbol 'xhci_get_largest_overhead' was not declared. Should it be static? drivers/usb/host/xhci-ring.c:2304:36: warning: context imbalance in 'handle_tx_event' - unexpected unlock drivers/usb/host/xhci-hub.c:425:6: warning: symbol 'xhci_set_remote_wake_mask' was not declared. Should it be static? Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-09-13xHCI: handle command after aborting the command ringElric Fu
According to xHCI spec section 4.6.1.1 and section 4.6.1.2, after aborting a command on the command ring, xHC will generate a command completion event with its completion code set to Command Ring Stopped at least. If a command is currently executing at the time of aborting a command, xHC also generate a command completion event with its completion code set to Command Abort. When the command ring is stopped, software may remove, add, or rearrage Command Descriptors. To cancel a command, software will initialize a command descriptor for the cancel command, and add it into a cancel_cmd_list of xhci. When the command ring is stopped, software will find the command trbs described by command descriptors in cancel_cmd_list and modify it to No Op command. If software can't find the matched trbs, we can think it had been finished. This patch should be backported to kernels as old as 3.0, that contain the commit 7ed603ecf8b68ab81f4c83097d3063d43ec73bb8 "xhci: Add an assertion to check for virt_dev=0 bug." That commit papers over a NULL pointer dereference, and this patch fixes the underlying issue that caused the NULL pointer dereference. Signed-off-by: Elric Fu <elricfu1@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Tested-by: Miroslav Sabljic <miroslav.sabljic@avl.com> Cc: stable@vger.kernel.org
2012-09-13xHCI: add aborting command ring functionElric Fu
Software have to abort command ring and cancel command when a command is failed or hang. Otherwise, the command ring will hang up and can't handle the others. An example of a command that may hang is the Address Device Command, because waiting for a SET_ADDRESS request to be acknowledged by a USB device is outside of the xHC's ability to control. To cancel a command, software will initialize a command descriptor for the cancel command, and add it into a cancel_cmd_list of xhci. Sarah: Fixed missing newline on "Have the command ring been stopped?" debugging statement. This patch should be backported to kernels as old as 3.0, that contain the commit 7ed603ecf8b68ab81f4c83097d3063d43ec73bb8 "xhci: Add an assertion to check for virt_dev=0 bug." That commit papers over a NULL pointer dereference, and this patch fixes the underlying issue that caused the NULL pointer dereference. Signed-off-by: Elric Fu <elricfu1@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Tested-by: Miroslav Sabljic <miroslav.sabljic@avl.com> Cc: stable@vger.kernel.org