Re: [RFC v2 2/2] xhci: refactor handle_cmd_completion() switch branches into functions

2013-08-22 Thread Sarah Sharp
On Thu, Aug 22, 2013 at 06:20:14PM +0300, Xenia Ragiadakou wrote:
 This patch refactors the switch statement in handle_cmd_completion() by
 creating a separate function for each branch, named 'xhci_handle_cmd_type'.
 
 Other changes introduced by this patch are:
 
 - Renaming the already existed functions by adding the prefix
   'xhci_handle_cmd_' for consistency. Also, for handle_stopped_endpoint()
   the order of arguments was changed too, so that the prototype of
   'xhci_handle_cmd_' be similar and easy to follow.
 - Additional local variables were added, such as cmd_trb, cmd_comp_code,
   cmd_type, add_flags and drop_flags, and the label 'update_ring',
   mainly to reduce code dublication and line length.
 - The variable ep_ring, that was assigned in the case TRB_CONFIG_EP
   but never used, was removed.

Can you break these changes into several patches, in order to make it
easier to review?  Something like:

1. Rename existing functions.
2. Change ordering of arguments for consistency.
3. Remove the unused variable from the TRB_CONFIG_EP case.
4. Several patches to refactor the code.

For the refactoring, break each refactoring into a separate patch.  I.e.
refactoring and creating xhci_handle_cmd_enable_slot goes in one patch,
xhci_handle_cmd_config_ep goes in another patch.

This patch is nearing the 400-line fatigue point of most reviewers, see
the article on Greg's google plus post for an interesting analysis:

https://plus.google.com/111049168280159033135/posts/2KcFNwzzEgC

Sarah Sharp

 
 Signed-off-by: Xenia Ragiadakou burzalod...@gmail.com
 ---
 
 Differences from version 1:
 
 Create separate functions for each switch case branch, instead of a single
 function holding the entire switch
 
  drivers/usb/host/xhci-ring.c | 310 
 ++-
  1 file changed, 185 insertions(+), 125 deletions(-)
 
 diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
 index ddbda35..bc9ce03 100644
 --- a/drivers/usb/host/xhci-ring.c
 +++ b/drivers/usb/host/xhci-ring.c
 @@ -755,8 +755,8 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd 
 *xhci,
   *  2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the 
 chain
   * bit cleared) so that the HW will skip over them.
   */
 -static void handle_stopped_endpoint(struct xhci_hcd *xhci,
 - union xhci_trb *trb, struct xhci_event_cmd *event)
 +static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci,
 + struct xhci_event_cmd *event, union xhci_trb *trb)
  {
   unsigned int slot_id;
   unsigned int ep_index;
 @@ -1063,9 +1063,8 @@ static void update_ring_for_set_deq_completion(struct 
 xhci_hcd *xhci,
   * endpoint doorbell to restart the ring, but only if there aren't more
   * cancellations pending.
   */
 -static void handle_set_deq_completion(struct xhci_hcd *xhci,
 - struct xhci_event_cmd *event,
 - union xhci_trb *trb)
 +static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci,
 + struct xhci_event_cmd *event, union xhci_trb *trb)
  {
   unsigned int slot_id;
   unsigned int ep_index;
 @@ -1157,9 +1156,8 @@ static void handle_set_deq_completion(struct xhci_hcd 
 *xhci,
   ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
  }
  
 -static void handle_reset_ep_completion(struct xhci_hcd *xhci,
 - struct xhci_event_cmd *event,
 - union xhci_trb *trb)
 +static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci,
 + struct xhci_event_cmd *event, union xhci_trb *trb)
  {
   int slot_id;
   unsigned int ep_index;
 @@ -1372,21 +1370,160 @@ static int handle_stopped_cmd_ring(struct xhci_hcd 
 *xhci,
   return cur_trb_is_good;
  }
  
 -static void handle_cmd_completion(struct xhci_hcd *xhci,
 +static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci,
 + struct xhci_event_cmd *event, u32 cmd_comp_code)
 +{
 + int slot_id;
 +
 + slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event-flags));
 + if (cmd_comp_code == COMP_SUCCESS)
 + xhci-slot_id = slot_id;
 + else
 + xhci-slot_id = 0;
 + complete(xhci-addr_dev);
 +}
 +
 +static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci,
   struct xhci_event_cmd *event)
  {
 - int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event-flags));
 - u64 cmd_dma;
 - dma_addr_t cmd_dequeue_dma;
 - struct xhci_input_control_ctx *ctrl_ctx;
 + int slot_id;
   struct xhci_virt_device *virt_dev;
 +
 + slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event-flags));
 + virt_dev = xhci-devs[slot_id];
 + if (!virt_dev)
 + return;
 + if (xhci-quirks  XHCI_EP_LIMIT_QUIRK)
 + /* Delete default control endpoint resources */
 + xhci_free_device_endpoint_resources(xhci, virt_dev, true);
 + xhci_free_virt_device(xhci, slot_id);
 +}
 +
 +static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci,
 + struct 

RE: [RFC v2 2/2] xhci: refactor handle_cmd_completion() switch branches into functions

2013-08-22 Thread Paul Zimmerman
 From: Xenia Ragiadakou
 Sent: Thursday, August 22, 2013 8:20 AM
 
 This patch refactors the switch statement in handle_cmd_completion() by
 creating a separate function for each branch, named 'xhci_handle_cmd_type'.
 
 Other changes introduced by this patch are:
 
 - Renaming the already existed functions by adding the prefix
   'xhci_handle_cmd_' for consistency. Also, for handle_stopped_endpoint()
   the order of arguments was changed too, so that the prototype of
   'xhci_handle_cmd_' be similar and easy to follow.
 - Additional local variables were added, such as cmd_trb, cmd_comp_code,
   cmd_type, add_flags and drop_flags, and the label 'update_ring',
   mainly to reduce code dublication and line length.
 - The variable ep_ring, that was assigned in the case TRB_CONFIG_EP
   but never used, was removed.

Just a small suggestion, I think it would be better to name these functions
to indicate they handle completion events, instead of commands. So maybe
xhci_handle_stop_ep_complete, xhci_handle_set_deq_complete,
xhci_handle_reset_ep_complete etc?

Feel free to ignore me if you disagree :)

-- 
Paul

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC v2 2/2] xhci: refactor handle_cmd_completion() switch branches into functions

2013-08-22 Thread Sarah Sharp
On Thu, Aug 22, 2013 at 08:06:17PM +, Paul Zimmerman wrote:
  From: Xenia Ragiadakou
  Sent: Thursday, August 22, 2013 8:20 AM
  
  This patch refactors the switch statement in handle_cmd_completion() by
  creating a separate function for each branch, named 
  'xhci_handle_cmd_type'.
  
  Other changes introduced by this patch are:
  
  - Renaming the already existed functions by adding the prefix
'xhci_handle_cmd_' for consistency. Also, for handle_stopped_endpoint()
the order of arguments was changed too, so that the prototype of
'xhci_handle_cmd_' be similar and easy to follow.
  - Additional local variables were added, such as cmd_trb, cmd_comp_code,
cmd_type, add_flags and drop_flags, and the label 'update_ring',
mainly to reduce code dublication and line length.
  - The variable ep_ring, that was assigned in the case TRB_CONFIG_EP
but never used, was removed.
 
 Just a small suggestion, I think it would be better to name these functions
 to indicate they handle completion events, instead of commands. So maybe
 xhci_handle_stop_ep_complete, xhci_handle_set_deq_complete,
 xhci_handle_reset_ep_complete etc?
 
 Feel free to ignore me if you disagree :)

I think that would be confusing, because some of the functions that
handle command _completion_ events then go on to _complete_ the
xhci_command-completion struct.

So let's just drop the word complete from the function names at all.
You queue xHCI commands with the xhci_queue_cmd functions, and you
handle the commands being done in xhci_handle_cmd_cmd functions.

Sarah Sharp
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html