staging: octeon-usb: use list_for_each_entry_safe()
[deliverable/linux.git] / drivers / staging / octeon-usb / octeon-hcd.c
index b07425c890ac49732ebf5e3310a26f929c749656..8e0fcbd173f219ced4bbf0390e131cdc691a0173 100644 (file)
@@ -66,8 +66,7 @@
 #include <asm/octeon/cvmx-sysinfo.h>
 #include <asm/octeon/cvmx-helper-board.h>
 
-#include "cvmx-usbcx-defs.h"
-#include "cvmx-usbnx-defs.h"
+#include "octeon-hcd.h"
 
 /**
  * enum cvmx_usb_speed - the possible USB device speeds
@@ -235,8 +234,6 @@ enum cvmx_usb_initialize_flags {
 /**
  * enum cvmx_usb_pipe_flags - internal flags for a pipe.
  *
- * @__CVMX_USB_PIPE_FLAGS_OPEN:             Used internally to determine if a pipe is
- *                                  open. Do not use.
  * @__CVMX_USB_PIPE_FLAGS_SCHEDULED: Used internally to determine if a pipe is
  *                                  actively using hardware. Do not use.
  * @__CVMX_USB_PIPE_FLAGS_NEED_PING: Used internally to determine if a high
@@ -244,7 +241,6 @@ enum cvmx_usb_initialize_flags {
  *                                  use.
  */
 enum cvmx_usb_pipe_flags {
-       __CVMX_USB_PIPE_FLAGS_OPEN      = 1 << 16,
        __CVMX_USB_PIPE_FLAGS_SCHEDULED = 1 << 17,
        __CVMX_USB_PIPE_FLAGS_NEED_PING = 1 << 18,
 };
@@ -255,12 +251,6 @@ enum cvmx_usb_pipe_flags {
 /* Maximum number of times to retry failed transactions */
 #define MAX_RETRIES            3
 
-/* Maximum number of pipes that can be open at once */
-#define MAX_PIPES              32
-
-/* Maximum number of outstanding transactions across all pipes */
-#define MAX_TRANSACTIONS       256
-
 /* Maximum number of hardware channels supported by the USB block */
 #define MAX_CHANNELS           8
 
@@ -285,10 +275,6 @@ enum cvmx_usb_pipe_flags {
  */
 #define MAX_TRANSFER_PACKETS   ((1<<10)-1)
 
-enum cvmx_usb_transaction_flags {
-       __CVMX_USB_TRANSACTION_FLAGS_IN_USE = 1<<16,
-};
-
 enum {
        USB_CLOCK_TYPE_REF_12,
        USB_CLOCK_TYPE_REF_24,
@@ -340,7 +326,6 @@ struct cvmx_usb_transaction {
        struct cvmx_usb_transaction *prev;
        struct cvmx_usb_transaction *next;
        enum cvmx_usb_transfer type;
-       enum cvmx_usb_transaction_flags flags;
        uint64_t buffer;
        int buffer_length;
        uint64_t control_header;
@@ -435,13 +420,9 @@ struct cvmx_usb_tx_fifo {
  * usbcx_hprt:            Stored port status so we don't need to read a CSR to
  *                        determine splits.
  * pipe_for_channel:      Map channels to pipes.
- * free_transaction_head:  List of free transactions head.
- * free_transaction_tail:  List of free transactions tail.
  * pipe:                  Storage for pipes.
- * transaction:                   Storage for transactions.
  * indent:                Used by debug output to indent functions.
  * port_status:                   Last port status used for change notification.
- * free_pipes:            List of all pipes that are currently closed.
  * idle_pipes:            List of open pipes that have no transactions.
  * active_pipes:          Active pipes indexed by transfer type.
  * frame_number:          Increments every SOF interrupt for time keeping.
@@ -453,13 +434,8 @@ struct cvmx_usb_state {
        int idle_hardware_channels;
        union cvmx_usbcx_hprt usbcx_hprt;
        struct cvmx_usb_pipe *pipe_for_channel[MAX_CHANNELS];
-       struct cvmx_usb_transaction *free_transaction_head;
-       struct cvmx_usb_transaction *free_transaction_tail;
-       struct cvmx_usb_pipe pipe[MAX_PIPES];
-       struct cvmx_usb_transaction transaction[MAX_TRANSACTIONS];
        int indent;
        struct cvmx_usb_port_status port_status;
-       struct cvmx_usb_pipe_list free_pipes;
        struct cvmx_usb_pipe_list idle_pipes;
        struct cvmx_usb_pipe_list active_pipes[4];
        uint64_t frame_number;
@@ -602,7 +578,8 @@ static inline void __cvmx_usb_write_csr64(struct cvmx_usb_state *usb,
 static inline int __cvmx_usb_pipe_needs_split(struct cvmx_usb_state *usb,
                                              struct cvmx_usb_pipe *pipe)
 {
-       return ((pipe->device_speed != CVMX_USB_SPEED_HIGH) && (usb->usbcx_hprt.s.prtspd == CVMX_USB_SPEED_HIGH));
+       return pipe->device_speed != CVMX_USB_SPEED_HIGH &&
+              usb->usbcx_hprt.s.prtspd == CVMX_USB_SPEED_HIGH;
 }
 
 
@@ -652,54 +629,6 @@ static int cvmx_usb_get_num_ports(void)
        return arch_ports;
 }
 
-
-/**
- * Allocate a usb transaction for use
- *
- * @usb:        USB device state populated by
- *              cvmx_usb_initialize().
- *
- * Returns: Transaction or NULL
- */
-static inline struct cvmx_usb_transaction *__cvmx_usb_alloc_transaction(struct cvmx_usb_state *usb)
-{
-       struct cvmx_usb_transaction *t;
-       t = usb->free_transaction_head;
-       if (t) {
-               usb->free_transaction_head = t->next;
-               if (!usb->free_transaction_head)
-                       usb->free_transaction_tail = NULL;
-       }
-       if (t) {
-               memset(t, 0, sizeof(*t));
-               t->flags = __CVMX_USB_TRANSACTION_FLAGS_IN_USE;
-       }
-       return t;
-}
-
-
-/**
- * Free a usb transaction
- *
- * @usb:        USB device state populated by
- *              cvmx_usb_initialize().
- * @transaction:
- *              Transaction to free
- */
-static inline void __cvmx_usb_free_transaction(struct cvmx_usb_state *usb,
-                                              struct cvmx_usb_transaction *transaction)
-{
-       transaction->flags = 0;
-       transaction->prev = NULL;
-       transaction->next = NULL;
-       if (usb->free_transaction_tail)
-               usb->free_transaction_tail->next = transaction;
-       else
-               usb->free_transaction_head = transaction;
-       usb->free_transaction_tail = transaction;
-}
-
-
 /**
  * Add a pipe to the tail of a list
  * @list:   List to add pipe to
@@ -798,18 +727,7 @@ static int cvmx_usb_initialize(struct cvmx_usb_state *usb,
        usb->init_flags = flags;
 
        /* Initialize the USB state structure */
-       {
-               int i;
-               usb->index = usb_port_number;
-
-               /* Initialize the transaction double linked list */
-               usb->free_transaction_head = NULL;
-               usb->free_transaction_tail = NULL;
-               for (i = 0; i < MAX_TRANSACTIONS; i++)
-                       __cvmx_usb_free_transaction(usb, usb->transaction + i);
-               for (i = 0; i < MAX_PIPES; i++)
-                       __cvmx_usb_append_pipe(&usb->free_pipes, usb->pipe + i);
-       }
+       usb->index = usb_port_number;
 
        /*
         * Power On Reset and PHY Initialization
@@ -835,16 +753,14 @@ static int cvmx_usb_initialize(struct cvmx_usb_state *usb,
                 * source at USB_XO. USB_XI should be tied to GND.
                 * Most Octeon evaluation boards require this setting
                 */
-               if (OCTEON_IS_MODEL(OCTEON_CN3XXX)) {
-                       /* From CN31XX,CN30XX manual */
-                       usbn_clk_ctl.cn31xx.p_rclk  = 1;
-                       usbn_clk_ctl.cn31xx.p_xenbn = 0;
-               } else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN50XX))
-                       /* From CN56XX,CN50XX manual */
-                       usbn_clk_ctl.cn56xx.p_rtype = 2;
+               if (OCTEON_IS_MODEL(OCTEON_CN3XXX) ||
+                   OCTEON_IS_MODEL(OCTEON_CN56XX) ||
+                   OCTEON_IS_MODEL(OCTEON_CN50XX))
+                       /* From CN56XX,CN50XX,CN31XX,CN30XX manuals */
+                       usbn_clk_ctl.s.p_rtype = 2; /* p_rclk=1 & p_xenbn=0 */
                else
                        /* From CN52XX manual */
-                       usbn_clk_ctl.cn52xx.p_rtype = 1;
+                       usbn_clk_ctl.s.p_rtype = 1;
 
                switch (flags & CVMX_USB_INITIALIZE_FLAGS_CLOCK_MHZ_MASK) {
                case CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ:
@@ -862,16 +778,12 @@ static int cvmx_usb_initialize(struct cvmx_usb_state *usb,
                 * The USB port uses a 12MHz crystal as clock source
                 * at USB_XO and USB_XI
                 */
-               if (OCTEON_IS_MODEL(OCTEON_CN3XXX)) {
+               if (OCTEON_IS_MODEL(OCTEON_CN3XXX))
                        /* From CN31XX,CN30XX manual */
-                       usbn_clk_ctl.cn31xx.p_rclk  = 1;
-                       usbn_clk_ctl.cn31xx.p_xenbn = 1;
-               } else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN50XX))
-                       /* From CN56XX,CN50XX manual */
-                       usbn_clk_ctl.cn56xx.p_rtype = 0;
+                       usbn_clk_ctl.s.p_rtype = 3; /* p_rclk=1 & p_xenbn=1 */
                else
-                       /* From CN52XX manual */
-                       usbn_clk_ctl.cn52xx.p_rtype = 0;
+                       /* From CN56XX,CN52XX,CN50XX manuals. */
+                       usbn_clk_ctl.s.p_rtype = 0;
 
                usbn_clk_ctl.s.p_c_sel = 0;
        }
@@ -1251,22 +1163,6 @@ static struct cvmx_usb_port_status cvmx_usb_get_status(struct cvmx_usb_state *us
        return result;
 }
 
-/**
- * Convert a USB transaction into a handle
- *
- * @usb:        USB device state populated by cvmx_usb_initialize().
- * @transaction:
- *              Transaction to get handle for
- *
- * Returns: Handle
- */
-static inline int __cvmx_usb_get_submit_handle(struct cvmx_usb_state *usb,
-                                              struct cvmx_usb_transaction *transaction)
-{
-       return ((unsigned long)transaction - (unsigned long)usb->transaction) /
-                       sizeof(*transaction);
-}
-
 /**
  * Open a virtual pipe between the host and a USB device. A pipe
  * must be opened before data can be transferred between a device
@@ -1362,12 +1258,9 @@ static struct cvmx_usb_pipe *cvmx_usb_open_pipe(struct cvmx_usb_state *usb,
        if (unlikely((hub_port < 0) || (hub_port > MAX_USB_HUB_PORT)))
                return NULL;
 
-       /* Find a free pipe */
-       pipe = usb->free_pipes.head;
+       pipe = kzalloc(sizeof(*pipe), GFP_ATOMIC);
        if (!pipe)
                return NULL;
-       __cvmx_usb_remove_pipe(&usb->free_pipes, pipe);
-       pipe->flags = __CVMX_USB_PIPE_FLAGS_OPEN;
        if ((device_speed == CVMX_USB_SPEED_HIGH) &&
                (transfer_dir == CVMX_USB_DIRECTION_OUT) &&
                (transfer_type == CVMX_USB_TRANSFER_BULK))
@@ -2131,7 +2024,8 @@ static inline struct usb_hcd *octeon_to_hcd(struct octeon_hcd *p)
 static void octeon_usb_urb_complete_callback(struct cvmx_usb_state *usb,
                                             enum cvmx_usb_complete status,
                                             struct cvmx_usb_pipe *pipe,
-                                            int submit_handle,
+                                            struct cvmx_usb_transaction
+                                               *transaction,
                                             int bytes_transferred,
                                             struct urb *urb)
 {
@@ -2142,17 +2036,14 @@ static void octeon_usb_urb_complete_callback(struct cvmx_usb_state *usb,
        urb->actual_length = bytes_transferred;
        urb->hcpriv = NULL;
 
-       if (!list_empty(&urb->urb_list)) {
+       if (!list_empty(&urb->urb_list))
                /*
                 * It is on the dequeue_list, but we are going to call
                 * usb_hcd_giveback_urb(), so we must clear it from
                 * the list.  We got to it before the
                 * octeon_usb_urb_dequeue_work() tasklet did.
                 */
-               list_del(&urb->urb_list);
-               /* No longer on the dequeue_list. */
-               INIT_LIST_HEAD(&urb->urb_list);
-       }
+               list_del_init(&urb->urb_list);
 
        /* For Isochronous transactions we need to update the URB packet status
           list from data in our private copy */
@@ -2172,10 +2063,10 @@ static void octeon_usb_urb_complete_callback(struct cvmx_usb_state *usb,
                                urb->iso_frame_desc[i].actual_length = iso_packet[i].length;
                                urb->actual_length += urb->iso_frame_desc[i].actual_length;
                        } else {
-                               dev_dbg(dev, "ISOCHRONOUS packet=%d of %d status=%d pipe=%p submit=%d size=%d\n",
+                               dev_dbg(dev, "ISOCHRONOUS packet=%d of %d status=%d pipe=%p transaction=%p size=%d\n",
                                        i, urb->number_of_packets,
                                        iso_packet[i].status, pipe,
-                                       submit_handle, iso_packet[i].length);
+                                       transaction, iso_packet[i].length);
                                urb->iso_frame_desc[i].status = -EREMOTEIO;
                        }
                }
@@ -2193,26 +2084,26 @@ static void octeon_usb_urb_complete_callback(struct cvmx_usb_state *usb,
                        urb->status = -ENOENT;
                break;
        case CVMX_USB_COMPLETE_STALL:
-               dev_dbg(dev, "status=stall pipe=%p submit=%d size=%d\n",
-                       pipe, submit_handle, bytes_transferred);
+               dev_dbg(dev, "status=stall pipe=%p transaction=%p size=%d\n",
+                       pipe, transaction, bytes_transferred);
                urb->status = -EPIPE;
                break;
        case CVMX_USB_COMPLETE_BABBLEERR:
-               dev_dbg(dev, "status=babble pipe=%p submit=%d size=%d\n",
-                       pipe, submit_handle, bytes_transferred);
+               dev_dbg(dev, "status=babble pipe=%p transaction=%p size=%d\n",
+                       pipe, transaction, bytes_transferred);
                urb->status = -EPIPE;
                break;
        case CVMX_USB_COMPLETE_SHORT:
-               dev_dbg(dev, "status=short pipe=%p submit=%d size=%d\n",
-                       pipe, submit_handle, bytes_transferred);
+               dev_dbg(dev, "status=short pipe=%p transaction=%p size=%d\n",
+                       pipe, transaction, bytes_transferred);
                urb->status = -EREMOTEIO;
                break;
        case CVMX_USB_COMPLETE_ERROR:
        case CVMX_USB_COMPLETE_XACTERR:
        case CVMX_USB_COMPLETE_DATATGLERR:
        case CVMX_USB_COMPLETE_FRAMEERR:
-               dev_dbg(dev, "status=%d pipe=%p submit=%d size=%d\n",
-                       status, pipe, submit_handle, bytes_transferred);
+               dev_dbg(dev, "status=%d pipe=%p transaction=%p size=%d\n",
+                       status, pipe, transaction, bytes_transferred);
                urb->status = -EPROTO;
                break;
        }
@@ -2237,8 +2128,6 @@ static void __cvmx_usb_perform_complete(struct cvmx_usb_state *usb,
                                        struct cvmx_usb_transaction *transaction,
                                        enum cvmx_usb_complete complete_code)
 {
-       int submit_handle;
-
        /* If this was a split then clear our split in progress marker */
        if (usb->active_split == transaction)
                usb->active_split = NULL;
@@ -2282,12 +2171,11 @@ static void __cvmx_usb_perform_complete(struct cvmx_usb_state *usb,
                __cvmx_usb_append_pipe(&usb->idle_pipes, pipe);
 
        }
-       submit_handle = __cvmx_usb_get_submit_handle(usb, transaction);
        octeon_usb_urb_complete_callback(usb, complete_code, pipe,
-                                        submit_handle,
+                                        transaction,
                                         transaction->actual_bytes,
                                         transaction->urb);
-       __cvmx_usb_free_transaction(usb, transaction);
+       kfree(transaction);
 done:
        return;
 }
@@ -2313,32 +2201,27 @@ done:
  *                 A description of each ISO packet
  * @urb:           URB for the callback
  *
- * Returns: Submit handle or negative on failure. Matches the result
- *         in the external API.
+ * Returns: Transaction or NULL on failure.
  */
-static int __cvmx_usb_submit_transaction(struct cvmx_usb_state *usb,
-                                        struct cvmx_usb_pipe *pipe,
-                                        enum cvmx_usb_transfer type,
-                                        uint64_t buffer,
-                                        int buffer_length,
-                                        uint64_t control_header,
-                                        int iso_start_frame,
-                                        int iso_number_packets,
-                                        struct cvmx_usb_iso_packet *iso_packets,
-                                        struct urb *urb)
+static struct cvmx_usb_transaction *__cvmx_usb_submit_transaction(struct cvmx_usb_state *usb,
+                                                                 struct cvmx_usb_pipe *pipe,
+                                                                 enum cvmx_usb_transfer type,
+                                                                 uint64_t buffer,
+                                                                 int buffer_length,
+                                                                 uint64_t control_header,
+                                                                 int iso_start_frame,
+                                                                 int iso_number_packets,
+                                                                 struct cvmx_usb_iso_packet *iso_packets,
+                                                                 struct urb *urb)
 {
-       int submit_handle;
        struct cvmx_usb_transaction *transaction;
 
-       /* Fail if the pipe isn't open */
-       if (unlikely((pipe->flags & __CVMX_USB_PIPE_FLAGS_OPEN) == 0))
-               return -EINVAL;
        if (unlikely(pipe->transfer_type != type))
-               return -EINVAL;
+               return NULL;
 
-       transaction = __cvmx_usb_alloc_transaction(usb);
+       transaction = kzalloc(sizeof(*transaction), GFP_ATOMIC);
        if (unlikely(!transaction))
-               return -ENOMEM;
+               return NULL;
 
        transaction->type = type;
        transaction->buffer = buffer;
@@ -2369,13 +2252,11 @@ static int __cvmx_usb_submit_transaction(struct cvmx_usb_state *usb,
        }
        pipe->tail = transaction;
 
-       submit_handle = __cvmx_usb_get_submit_handle(usb, transaction);
-
        /* We may need to schedule the pipe if this was the head of the pipe */
        if (!transaction->prev)
                __cvmx_usb_schedule(usb, 0);
 
-       return submit_handle;
+       return transaction;
 }
 
 
@@ -2386,25 +2267,20 @@ static int __cvmx_usb_submit_transaction(struct cvmx_usb_state *usb,
  * @pipe:          Handle to the pipe for the transfer.
  * @urb:           URB.
  *
- * Returns: A submitted transaction handle or negative on
- *         failure. Negative values are error codes.
+ * Returns: A submitted transaction or NULL on failure.
  */
-static int cvmx_usb_submit_bulk(struct cvmx_usb_state *usb,
-                               struct cvmx_usb_pipe *pipe,
-                               struct urb *urb)
+static struct cvmx_usb_transaction *cvmx_usb_submit_bulk(struct cvmx_usb_state *usb,
+                                                        struct cvmx_usb_pipe *pipe,
+                                                        struct urb *urb)
 {
-       int submit_handle;
-
-       submit_handle = __cvmx_usb_submit_transaction(usb, pipe,
-                                                     CVMX_USB_TRANSFER_BULK,
-                                                     urb->transfer_dma,
-                                                     urb->transfer_buffer_length,
-                                                     0, /* control_header */
-                                                     0, /* iso_start_frame */
-                                                     0, /* iso_number_packets */
-                                                     NULL, /* iso_packets */
-                                                     urb);
-       return submit_handle;
+       return __cvmx_usb_submit_transaction(usb, pipe, CVMX_USB_TRANSFER_BULK,
+                                            urb->transfer_dma,
+                                            urb->transfer_buffer_length,
+                                            0, /* control_header */
+                                            0, /* iso_start_frame */
+                                            0, /* iso_number_packets */
+                                            NULL, /* iso_packets */
+                                            urb);
 }
 
 
@@ -2415,25 +2291,21 @@ static int cvmx_usb_submit_bulk(struct cvmx_usb_state *usb,
  * @pipe:          Handle to the pipe for the transfer.
  * @urb:           URB returned when the callback is called.
  *
- * Returns: A submitted transaction handle or negative on
- *         failure. Negative values are error codes.
+ * Returns: A submitted transaction or NULL on failure.
  */
-static int cvmx_usb_submit_interrupt(struct cvmx_usb_state *usb,
-                                    struct cvmx_usb_pipe *pipe,
-                                    struct urb *urb)
+static struct cvmx_usb_transaction *cvmx_usb_submit_interrupt(struct cvmx_usb_state *usb,
+                                                             struct cvmx_usb_pipe *pipe,
+                                                             struct urb *urb)
 {
-       int submit_handle;
-
-       submit_handle = __cvmx_usb_submit_transaction(usb, pipe,
-                                                     CVMX_USB_TRANSFER_INTERRUPT,
-                                                     urb->transfer_dma,
-                                                     urb->transfer_buffer_length,
-                                                     0, /* control_header */
-                                                     0, /* iso_start_frame */
-                                                     0, /* iso_number_packets */
-                                                     NULL, /* iso_packets */
-                                                     urb);
-       return submit_handle;
+       return __cvmx_usb_submit_transaction(usb, pipe,
+                                            CVMX_USB_TRANSFER_INTERRUPT,
+                                            urb->transfer_dma,
+                                            urb->transfer_buffer_length,
+                                            0, /* control_header */
+                                            0, /* iso_start_frame */
+                                            0, /* iso_number_packets */
+                                            NULL, /* iso_packets */
+                                            urb);
 }
 
 
@@ -2444,14 +2316,12 @@ static int cvmx_usb_submit_interrupt(struct cvmx_usb_state *usb,
  * @pipe:          Handle to the pipe for the transfer.
  * @urb:           URB.
  *
- * Returns: A submitted transaction handle or negative on
- *         failure. Negative values are error codes.
+ * Returns: A submitted transaction or NULL on failure.
  */
-static int cvmx_usb_submit_control(struct cvmx_usb_state *usb,
-                                  struct cvmx_usb_pipe *pipe,
-                                  struct urb *urb)
+static struct cvmx_usb_transaction *cvmx_usb_submit_control(struct cvmx_usb_state *usb,
+                                                           struct cvmx_usb_pipe *pipe,
+                                                           struct urb *urb)
 {
-       int submit_handle;
        int buffer_length = urb->transfer_buffer_length;
        uint64_t control_header = urb->setup_dma;
        union cvmx_usb_control_header *header =
@@ -2460,16 +2330,14 @@ static int cvmx_usb_submit_control(struct cvmx_usb_state *usb,
        if ((header->s.request_type & 0x80) == 0)
                buffer_length = le16_to_cpu(header->s.length);
 
-       submit_handle = __cvmx_usb_submit_transaction(usb, pipe,
-                                                     CVMX_USB_TRANSFER_CONTROL,
-                                                     urb->transfer_dma,
-                                                     buffer_length,
-                                                     control_header,
-                                                     0, /* iso_start_frame */
-                                                     0, /* iso_number_packets */
-                                                     NULL, /* iso_packets */
-                                                     urb);
-       return submit_handle;
+       return __cvmx_usb_submit_transaction(usb, pipe,
+                                            CVMX_USB_TRANSFER_CONTROL,
+                                            urb->transfer_dma, buffer_length,
+                                            control_header,
+                                            0, /* iso_start_frame */
+                                            0, /* iso_number_packets */
+                                            NULL, /* iso_packets */
+                                            urb);
 }
 
 
@@ -2480,27 +2348,23 @@ static int cvmx_usb_submit_control(struct cvmx_usb_state *usb,
  * @pipe:          Handle to the pipe for the transfer.
  * @urb:           URB returned when the callback is called.
  *
- * Returns: A submitted transaction handle or negative on
- *         failure. Negative values are error codes.
+ * Returns: A submitted transaction or NULL on failure.
  */
-static int cvmx_usb_submit_isochronous(struct cvmx_usb_state *usb,
-                                      struct cvmx_usb_pipe *pipe,
-                                      struct urb *urb)
+static struct cvmx_usb_transaction *cvmx_usb_submit_isochronous(struct cvmx_usb_state *usb,
+                                                               struct cvmx_usb_pipe *pipe,
+                                                               struct urb *urb)
 {
-       int submit_handle;
        struct cvmx_usb_iso_packet *packets;
 
        packets = (struct cvmx_usb_iso_packet *) urb->setup_packet;
-       submit_handle = __cvmx_usb_submit_transaction(usb, pipe,
-                                                     CVMX_USB_TRANSFER_ISOCHRONOUS,
-                                                     urb->transfer_dma,
-                                                     urb->transfer_buffer_length,
-                                                     0, /* control_header */
-                                                     urb->start_frame,
-                                                     urb->number_of_packets,
-                                                     packets,
-                                                     urb);
-       return submit_handle;
+       return __cvmx_usb_submit_transaction(usb, pipe,
+                                            CVMX_USB_TRANSFER_ISOCHRONOUS,
+                                            urb->transfer_dma,
+                                            urb->transfer_buffer_length,
+                                            0, /* control_header */
+                                            urb->start_frame,
+                                            urb->number_of_packets,
+                                            packets, urb);
 }
 
 
@@ -2513,31 +2377,14 @@ static int cvmx_usb_submit_isochronous(struct cvmx_usb_state *usb,
  *
  * @usb:        USB device state populated by cvmx_usb_initialize().
  * @pipe:       Pipe to cancel requests in.
- * @submit_handle:
- *              Handle to transaction to cancel, returned by the submit
- *              function.
+ * @transaction: Transaction to cancel, returned by the submit function.
  *
  * Returns: 0 or a negative error code.
  */
 static int cvmx_usb_cancel(struct cvmx_usb_state *usb,
                           struct cvmx_usb_pipe *pipe,
-                          int submit_handle)
+                          struct cvmx_usb_transaction *transaction)
 {
-       struct cvmx_usb_transaction *transaction;
-
-       if (unlikely((submit_handle < 0) || (submit_handle >= MAX_TRANSACTIONS)))
-               return -EINVAL;
-
-       /* Fail if the pipe isn't open */
-       if (unlikely((pipe->flags & __CVMX_USB_PIPE_FLAGS_OPEN) == 0))
-               return -EINVAL;
-
-       transaction = usb->transaction + submit_handle;
-
-       /* Fail if this transaction already completed */
-       if (unlikely((transaction->flags & __CVMX_USB_TRANSACTION_FLAGS_IN_USE) == 0))
-               return -EINVAL;
-
        /*
         * If the transaction is the HEAD of the queue and scheduled. We need to
         * treat it special
@@ -2578,14 +2425,9 @@ static int cvmx_usb_cancel(struct cvmx_usb_state *usb,
 static int cvmx_usb_cancel_all(struct cvmx_usb_state *usb,
                               struct cvmx_usb_pipe *pipe)
 {
-       /* Fail if the pipe isn't open */
-       if (unlikely((pipe->flags & __CVMX_USB_PIPE_FLAGS_OPEN) == 0))
-               return -EINVAL;
-
        /* Simply loop through and attempt to cancel each transaction */
        while (pipe->head) {
-               int result = cvmx_usb_cancel(usb, pipe,
-                       __cvmx_usb_get_submit_handle(usb, pipe->head));
+               int result = cvmx_usb_cancel(usb, pipe, pipe->head);
                if (unlikely(result != 0))
                        return result;
        }
@@ -2605,17 +2447,12 @@ static int cvmx_usb_cancel_all(struct cvmx_usb_state *usb,
 static int cvmx_usb_close_pipe(struct cvmx_usb_state *usb,
                               struct cvmx_usb_pipe *pipe)
 {
-       /* Fail if the pipe isn't open */
-       if (unlikely((pipe->flags & __CVMX_USB_PIPE_FLAGS_OPEN) == 0))
-               return -EINVAL;
-
        /* Fail if the pipe has pending transactions */
        if (unlikely(pipe->head))
                return -EBUSY;
 
-       pipe->flags = 0;
        __cvmx_usb_remove_pipe(&usb->idle_pipes, pipe);
-       __cvmx_usb_append_pipe(&usb->free_pipes, pipe);
+       kfree(pipe);
 
        return 0;
 }
@@ -3231,7 +3068,7 @@ static int octeon_usb_urb_enqueue(struct usb_hcd *hcd,
 {
        struct octeon_hcd *priv = hcd_to_octeon(hcd);
        struct device *dev = hcd->self.controller;
-       int submit_handle = -1;
+       struct cvmx_usb_transaction *transaction = NULL;
        struct cvmx_usb_pipe *pipe;
        unsigned long flags;
        struct cvmx_usb_iso_packet *iso_packet;
@@ -3346,13 +3183,13 @@ static int octeon_usb_urb_enqueue(struct usb_hcd *hcd,
                         * this saves us a bunch of logic.
                         */
                        urb->setup_packet = (char *)iso_packet;
-                       submit_handle = cvmx_usb_submit_isochronous(&priv->usb,
-                                                                   pipe, urb);
+                       transaction = cvmx_usb_submit_isochronous(&priv->usb,
+                                                                 pipe, urb);
                        /*
                         * If submit failed we need to free our private packet
                         * list.
                         */
-                       if (submit_handle < 0) {
+                       if (!transaction) {
                                urb->setup_packet = NULL;
                                kfree(iso_packet);
                        }
@@ -3361,45 +3198,41 @@ static int octeon_usb_urb_enqueue(struct usb_hcd *hcd,
        case PIPE_INTERRUPT:
                dev_dbg(dev, "Submit interrupt to %d.%d\n",
                        usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe));
-               submit_handle = cvmx_usb_submit_interrupt(&priv->usb, pipe,
-                                                         urb);
+               transaction = cvmx_usb_submit_interrupt(&priv->usb, pipe, urb);
                break;
        case PIPE_CONTROL:
                dev_dbg(dev, "Submit control to %d.%d\n",
                        usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe));
-               submit_handle = cvmx_usb_submit_control(&priv->usb, pipe, urb);
+               transaction = cvmx_usb_submit_control(&priv->usb, pipe, urb);
                break;
        case PIPE_BULK:
                dev_dbg(dev, "Submit bulk to %d.%d\n",
                        usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe));
-               submit_handle = cvmx_usb_submit_bulk(&priv->usb, pipe, urb);
+               transaction = cvmx_usb_submit_bulk(&priv->usb, pipe, urb);
                break;
        }
-       if (submit_handle < 0) {
+       if (!transaction) {
                spin_unlock_irqrestore(&priv->lock, flags);
                dev_dbg(dev, "Failed to submit\n");
                return -ENOMEM;
        }
-       urb->hcpriv = (void *)(long)submit_handle;
+       urb->hcpriv = transaction;
        spin_unlock_irqrestore(&priv->lock, flags);
        return 0;
 }
 
 static void octeon_usb_urb_dequeue_work(unsigned long arg)
 {
+       struct urb *urb;
+       struct urb *next;
        unsigned long flags;
        struct octeon_hcd *priv = (struct octeon_hcd *)arg;
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       while (!list_empty(&priv->dequeue_list)) {
-               int submit_handle;
-               struct urb *urb = container_of(priv->dequeue_list.next, struct urb, urb_list);
-               list_del(&urb->urb_list);
-               /* not enqueued on dequeue_list */
-               INIT_LIST_HEAD(&urb->urb_list);
-               submit_handle = (long)urb->hcpriv;
-               cvmx_usb_cancel(&priv->usb, urb->ep->hcpriv, submit_handle);
+       list_for_each_entry_safe(urb, next, &priv->dequeue_list, urb_list) {
+               list_del_init(&urb->urb_list);
+               cvmx_usb_cancel(&priv->usb, urb->ep->hcpriv, urb->hcpriv);
        }
 
        spin_unlock_irqrestore(&priv->lock, flags);
This page took 0.039548 seconds and 5 git commands to generate.