This patch (as946) eliminates many of the uses of urb->pipe in
usbcore.  Unfortunately there will have to be a significant API
change, affecting all USB drivers, before we can remove it entirely.
This patch contents itself with changing only the interface to
usb_buffer_map_sg() and friends: The pipe argument is replaced with a
direction flag.  That can be done easily because those routines get
used in only one place.

Signed-off-by: Alan Stern <[EMAIL PROTECTED]>

---

Index: usb-2.6/drivers/usb/core/hcd.c
===================================================================
--- usb-2.6.orig/drivers/usb/core/hcd.c
+++ usb-2.6/drivers/usb/core/hcd.c
@@ -635,9 +635,9 @@ static int rh_queue_status (struct usb_h
 
 static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
 {
-       if (usb_pipeint (urb->pipe))
+       if (usb_endpoint_xfer_int(&urb->ep->desc))
                return rh_queue_status (hcd, urb);
-       if (usb_pipecontrol (urb->pipe))
+       if (usb_endpoint_xfer_control(&urb->ep->desc))
                return rh_call_control (hcd, urb);
        return -EINVAL;
 }
@@ -651,7 +651,7 @@ static int usb_rh_urb_dequeue (struct us
 {
        unsigned long   flags;
 
-       if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */
+       if (usb_endpoint_num(&urb->ep->desc) == 0) {    /* Control URB */
                ;       /* Do nothing */
 
        } else {                                /* Status URB */
@@ -985,7 +985,7 @@ static void urb_unlink(struct usb_hcd *h
        spin_unlock_irqrestore(&hcd_urb_list_lock, flags);
 
        if (hcd->self.uses_dma && !is_root_hub(urb->dev)) {
-               if (usb_pipecontrol (urb->pipe)
+               if (usb_endpoint_xfer_control(&urb->ep->desc)
                        && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
                        dma_unmap_single (hcd->self.controller, urb->setup_dma,
                                        sizeof (struct usb_ctrlrequest),
@@ -1068,7 +1068,7 @@ int usb_hcd_submit_urb (struct urb *urb,
         * unless it uses pio or talks to another transport.
         */
        if (hcd->self.uses_dma) {
-               if (usb_pipecontrol (urb->pipe)
+               if (usb_endpoint_xfer_control(&urb->ep->desc)
                        && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
                        urb->setup_dma = dma_map_single (
                                        hcd->self.controller,
@@ -1268,11 +1268,13 @@ rescan:
        spin_lock(&hcd_urb_list_lock);
        list_for_each_entry (urb, &ep->urb_list, urb_list) {
                int     tmp;
+               int     is_in;
 
                /* the urb may already have been unlinked */
                if (urb->status != -EINPROGRESS)
                        continue;
                usb_get_urb (urb);
+               is_in = usb_urb_dir_in(urb);
                spin_unlock(&hcd_urb_list_lock);
 
                spin_lock (&urb->lock);
@@ -1283,19 +1285,25 @@ rescan:
 
                /* kick hcd unless it's already returning this */
                if (tmp == -EINPROGRESS) {
-                       tmp = urb->pipe;
                        unlink1 (hcd, urb);
                        dev_dbg (hcd->self.controller,
-                               "shutdown urb %p pipe %08x ep%d%s%s\n",
-                               urb, tmp, usb_pipeendpoint (tmp),
-                               (tmp & USB_DIR_IN) ? "in" : "out",
-                               ({ char *s; \
-                                switch (usb_pipetype (tmp)) { \
-                                case PIPE_CONTROL:     s = ""; break; \
-                                case PIPE_BULK:        s = "-bulk"; break; \
-                                case PIPE_INTERRUPT:   s = "-intr"; break; \
-                                default:               s = "-iso"; break; \
-                               }; s;}));
+                               "shutdown urb %p ep%d%s%s\n",
+                               urb, usb_endpoint_num(&ep->desc),
+                               is_in ? "in" : "out",
+                               ({      char *s;
+
+                                       switch (usb_endpoint_type(&ep->desc)) {
+                                       case USB_ENDPOINT_XFER_CONTROL:
+                                               s = ""; break;
+                                       case USB_ENDPOINT_XFER_BULK:
+                                               s = "-bulk"; break;
+                                       case USB_ENDPOINT_XFER_INT:
+                                               s = "-intr"; break;
+                                       default:
+                                               s = "-iso"; break;
+                                       };
+                                       s;
+                               }));
                }
                usb_put_urb (urb);
 
Index: usb-2.6/drivers/usb/core/message.c
===================================================================
--- usb-2.6.orig/drivers/usb/core/message.c
+++ usb-2.6/drivers/usb/core/message.c
@@ -59,8 +59,8 @@ static int usb_start_wait_urb(struct urb
                dev_dbg(&urb->dev->dev,
                        "%s timed out on ep%d%s len=%d/%d\n",
                        current->comm,
-                       usb_pipeendpoint(urb->pipe),
-                       usb_pipein(urb->pipe) ? "in" : "out",
+                       usb_endpoint_num(&urb->ep->desc),
+                       usb_urb_dir_in(urb) ? "in" : "out",
                        urb->actual_length,
                        urb->transfer_buffer_length);
        } else
@@ -250,7 +250,8 @@ static void sg_clean (struct usb_sg_requ
                io->urbs = NULL;
        }
        if (io->dev->dev.dma_mask != NULL)
-               usb_buffer_unmap_sg (io->dev, io->pipe, io->sg, io->nents);
+               usb_buffer_unmap_sg (io->dev, usb_pipein(io->pipe),
+                               io->sg, io->nents);
        io->dev = NULL;
 }
 
@@ -278,8 +279,8 @@ static void sg_complete (struct urb *urb
                dev_err (io->dev->bus->controller,
                        "dev %s ep%d%s scatterlist error %d/%d\n",
                        io->dev->devpath,
-                       usb_pipeendpoint (urb->pipe),
-                       usb_pipein (urb->pipe) ? "in" : "out",
+                       usb_endpoint_num(&urb->ep->desc),
+                       usb_urb_dir_in(urb) ? "in" : "out",
                        status, io->status);
                // BUG ();
        }
@@ -379,7 +380,8 @@ int usb_sg_init (
         */
        dma = (dev->dev.dma_mask != NULL);
        if (dma)
-               io->entries = usb_buffer_map_sg (dev, pipe, sg, nents);
+               io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe),
+                               sg, nents);
        else
                io->entries = nents;
 
Index: usb-2.6/drivers/usb/core/usb.c
===================================================================
--- usb-2.6.orig/drivers/usb/core/usb.c
+++ usb-2.6/drivers/usb/core/usb.c
@@ -766,7 +766,7 @@ void usb_buffer_unmap(struct urb *urb)
 /**
  * usb_buffer_map_sg - create scatterlist DMA mapping(s) for an endpoint
  * @dev: device to which the scatterlist will be mapped
- * @pipe: endpoint defining the mapping direction
+ * @is_in: mapping transfer direction
  * @sg: the scatterlist to map
  * @nents: the number of entries in the scatterlist
  *
@@ -789,14 +789,13 @@ void usb_buffer_unmap(struct urb *urb)
  *
  * Reverse the effect of this call with usb_buffer_unmap_sg().
  */
-int usb_buffer_map_sg(const struct usb_device *dev, unsigned pipe,
+int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
                      struct scatterlist *sg, int nents)
 {
        struct usb_bus          *bus;
        struct device           *controller;
 
        if (!dev
-                       || usb_pipecontrol(pipe)
                        || !(bus = dev->bus)
                        || !(controller = bus->controller)
                        || !controller->dma_mask)
@@ -804,7 +803,7 @@ int usb_buffer_map_sg(const struct usb_d
 
        // FIXME generic api broken like pci, can't report errors
        return dma_map_sg(controller, sg, nents,
-                       usb_pipein(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
+                       is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
 }
 
 /* XXX DISABLED, no users currently.  If you wish to re-enable this
@@ -817,14 +816,14 @@ int usb_buffer_map_sg(const struct usb_d
 /**
  * usb_buffer_dmasync_sg - synchronize DMA and CPU view of scatterlist 
buffer(s)
  * @dev: device to which the scatterlist will be mapped
- * @pipe: endpoint defining the mapping direction
+ * @is_in: mapping transfer direction
  * @sg: the scatterlist to synchronize
  * @n_hw_ents: the positive return value from usb_buffer_map_sg
  *
  * Use this when you are re-using a scatterlist's data buffers for
  * another USB request.
  */
-void usb_buffer_dmasync_sg(const struct usb_device *dev, unsigned pipe,
+void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
                           struct scatterlist *sg, int n_hw_ents)
 {
        struct usb_bus          *bus;
@@ -837,20 +836,20 @@ void usb_buffer_dmasync_sg(const struct 
                return;
 
        dma_sync_sg(controller, sg, n_hw_ents,
-                       usb_pipein(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
+                       is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
 }
 #endif
 
 /**
  * usb_buffer_unmap_sg - free DMA mapping(s) for a scatterlist
  * @dev: device to which the scatterlist will be mapped
- * @pipe: endpoint defining the mapping direction
+ * @is_in: mapping transfer direction
  * @sg: the scatterlist to unmap
  * @n_hw_ents: the positive return value from usb_buffer_map_sg
  *
  * Reverses the effect of usb_buffer_map_sg().
  */
-void usb_buffer_unmap_sg(const struct usb_device *dev, unsigned pipe,
+void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
                         struct scatterlist *sg, int n_hw_ents)
 {
        struct usb_bus          *bus;
@@ -863,7 +862,7 @@ void usb_buffer_unmap_sg(const struct us
                return;
 
        dma_unmap_sg(controller, sg, n_hw_ents,
-                       usb_pipein(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
+                       is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
 }
 
 /* format to disable USB on kernel command line is: nousb */
Index: usb-2.6/include/linux/usb.h
===================================================================
--- usb-2.6.orig/include/linux/usb.h
+++ usb-2.6/include/linux/usb.h
@@ -1429,13 +1429,13 @@ void usb_buffer_unmap (struct urb *urb);
 #endif
 
 struct scatterlist;
-int usb_buffer_map_sg(const struct usb_device *dev, unsigned pipe,
+int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
                      struct scatterlist *sg, int nents);
 #if 0
-void usb_buffer_dmasync_sg(const struct usb_device *dev, unsigned pipe,
+void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
                           struct scatterlist *sg, int n_hw_ents);
 #endif
-void usb_buffer_unmap_sg(const struct usb_device *dev, unsigned pipe,
+void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
                         struct scatterlist *sg, int n_hw_ents);
 
 /*-------------------------------------------------------------------*


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to