Blame SOURCES/0292-Fix-handling-of-split-transfers.patch

f96e0b
From 16e60d9443ebe87df0cecac9a22df6e0440b805d Mon Sep 17 00:00:00 2001
f96e0b
From: =?UTF-8?q?Ale=C5=A1=20Nesrsta?= <starous@volny.cz>
f96e0b
Date: Fri, 12 Apr 2013 20:42:46 +0200
f96e0b
Subject: [PATCH 292/482] 	Fix handling of split transfers.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                  |  4 ++++
f96e0b
 grub-core/bus/usb/ehci.c   | 25 ++++++++++-------------
f96e0b
 grub-core/bus/usb/usbhub.c | 50 +++++++++++++++++++++++++++++++++++++++-------
f96e0b
 include/grub/usb.h         |  4 ++--
f96e0b
 4 files changed, 59 insertions(+), 24 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 79563b8..e8e4569 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,7 @@
f96e0b
+2013-04-12  Aleš Nesrsta  <starous@volny.cz>
f96e0b
+
f96e0b
+	Fix handling of split transfers.
f96e0b
+
f96e0b
 2013-04-12  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* grub-core/net/http.c: Fix bad free.
f96e0b
diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c
f96e0b
index e902fcd..18b12b2 100644
f96e0b
--- a/grub-core/bus/usb/ehci.c
f96e0b
+++ b/grub-core/bus/usb/ehci.c
f96e0b
@@ -798,7 +798,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
f96e0b
   /* Set ownership of root hub ports to EHCI */
f96e0b
   grub_ehci_oper_write32 (e, GRUB_EHCI_CONFIG_FLAG, GRUB_EHCI_CF_EHCI_OWNER);
f96e0b
 
f96e0b
-  /* Enable asynchronous list */
f96e0b
+  /* Enable both lists */
f96e0b
   grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND,
f96e0b
 			  GRUB_EHCI_CMD_AS_ENABL
f96e0b
 			  | GRUB_EHCI_CMD_PS_ENABL
f96e0b
@@ -942,9 +942,9 @@ grub_ehci_setup_qh (grub_ehci_qh_t qh, grub_usb_transfer_t transfer)
f96e0b
    * SplitCompletionMask - AFAIK it is ignored in asynchronous list,
f96e0b
    * InterruptScheduleMask - AFAIK it should be zero in async. list */
f96e0b
   ep_cap |= GRUB_EHCI_MULT_THREE;
f96e0b
-  ep_cap |= (transfer->dev->port << GRUB_EHCI_DEVPORT_OFF)
f96e0b
+  ep_cap |= (transfer->dev->split_hubport << GRUB_EHCI_DEVPORT_OFF)
f96e0b
     & GRUB_EHCI_DEVPORT_MASK;
f96e0b
-  ep_cap |= (transfer->dev->hubaddr << GRUB_EHCI_HUBADDR_OFF)
f96e0b
+  ep_cap |= (transfer->dev->split_hubaddr << GRUB_EHCI_HUBADDR_OFF)
f96e0b
     & GRUB_EHCI_HUBADDR_MASK;
f96e0b
   if (transfer->dev->speed == GRUB_USB_SPEED_LOW
f96e0b
       && transfer->type != GRUB_USB_TRANSACTION_TYPE_CONTROL)
f96e0b
@@ -1261,16 +1261,6 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev,
f96e0b
     /* XXX: Fix it: Currently we don't do anything to restart EHCI */
f96e0b
     return GRUB_USB_ERR_INTERNAL;
f96e0b
 
f96e0b
-  /* Check if transfer is not high speed and connected to root hub.
f96e0b
-   * It should not happened but... */
f96e0b
-  if ((transfer->dev->speed != GRUB_USB_SPEED_HIGH)
f96e0b
-      && !transfer->dev->hubaddr)
f96e0b
-    {
f96e0b
-      grub_error (GRUB_USB_ERR_BADDEVICE,
f96e0b
-		  "FULL/LOW speed device on EHCI port!?!");
f96e0b
-      return GRUB_USB_ERR_BADDEVICE;
f96e0b
-    }
f96e0b
-
f96e0b
   /* Allocate memory for controller transfer data.  */
f96e0b
   cdata = grub_malloc (sizeof (*cdata));
f96e0b
   if (!cdata)
f96e0b
@@ -1887,13 +1877,18 @@ grub_ehci_fini_hw (int noreturn __attribute__ ((unused)))
f96e0b
   /* We should disable all EHCI HW to prevent any DMA access etc. */
f96e0b
   for (e = ehci; e; e = e->next)
f96e0b
     {
f96e0b
+      /* Disable both lists */
f96e0b
+      grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND,
f96e0b
+        ~(GRUB_EHCI_CMD_AS_ENABL | GRUB_EHCI_CMD_PS_ENABL)
f96e0b
+        & grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
f96e0b
+
f96e0b
       /* Check if EHCI is halted and halt it if not */
f96e0b
       if (grub_ehci_halt (e) != GRUB_USB_ERR_NONE)
f96e0b
-	grub_error (GRUB_ERR_TIMEOUT, "restore_hw: EHCI halt timeout");
f96e0b
+	grub_error (GRUB_ERR_TIMEOUT, "fini_hw: EHCI halt timeout");
f96e0b
 
f96e0b
       /* Reset EHCI */
f96e0b
       if (grub_ehci_reset (e) != GRUB_USB_ERR_NONE)
f96e0b
-	grub_error (GRUB_ERR_TIMEOUT, "restore_hw: EHCI reset timeout");
f96e0b
+	grub_error (GRUB_ERR_TIMEOUT, "fini_hw: EHCI reset timeout");
f96e0b
     }
f96e0b
 
f96e0b
   return GRUB_USB_ERR_NONE;
f96e0b
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
f96e0b
index 6fc9d02..e3b7d40 100644
f96e0b
--- a/grub-core/bus/usb/usbhub.c
f96e0b
+++ b/grub-core/bus/usb/usbhub.c
f96e0b
@@ -49,7 +49,7 @@ static grub_usb_controller_dev_t grub_usb_list;
f96e0b
 static grub_usb_device_t
f96e0b
 grub_usb_hub_add_dev (grub_usb_controller_t controller,
f96e0b
                       grub_usb_speed_t speed,
f96e0b
-                      int port, int hubaddr)
f96e0b
+                      int split_hubport, int split_hubaddr)
f96e0b
 {
f96e0b
   grub_usb_device_t dev;
f96e0b
   int i;
f96e0b
@@ -63,8 +63,8 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
f96e0b
 
f96e0b
   dev->controller = *controller;
f96e0b
   dev->speed = speed;
f96e0b
-  dev->port = port;
f96e0b
-  dev->hubaddr = hubaddr;
f96e0b
+  dev->split_hubport = split_hubport;
f96e0b
+  dev->split_hubaddr = split_hubaddr;
f96e0b
 
f96e0b
   err = grub_usb_device_initialize (dev);
f96e0b
   if (err)
f96e0b
@@ -108,8 +108,8 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
f96e0b
 
f96e0b
   grub_dprintf ("usb", "Added new usb device: %p, addr=%d\n",
f96e0b
 		dev, i);
f96e0b
-  grub_dprintf ("usb", "speed=%d, port=%d, hubaddr=%d\n",
f96e0b
-		speed, port, hubaddr);
f96e0b
+  grub_dprintf ("usb", "speed=%d, split_hubport=%d, split_hubaddr=%d\n",
f96e0b
+		speed, split_hubport, split_hubaddr);
f96e0b
 
f96e0b
   /* Wait "recovery interval", spec. says 2ms */
f96e0b
   grub_millisleep (2);
f96e0b
@@ -219,7 +219,12 @@ attach_root_port (struct grub_usb_hub *hub, int portno,
f96e0b
   grub_boot_time ("Port enabled");
f96e0b
 
f96e0b
   /* Enable the port and create a device.  */
f96e0b
-  dev = grub_usb_hub_add_dev (hub->controller, speed, portno, 0);
f96e0b
+  /* High speed device needs not transaction translation
f96e0b
+     and full/low speed device cannot be connected to EHCI root hub
f96e0b
+     and full/low speed device connected to OHCI/UHCI needs not
f96e0b
+     transaction translation - e.g. hubport and hubaddr should be
f96e0b
+     always none (zero) for any device connected to any root hub. */
f96e0b
+  dev = grub_usb_hub_add_dev (hub->controller, speed, 0, 0);
f96e0b
   hub->controller->dev->pending_reset = 0;
f96e0b
   npending--;
f96e0b
   if (! dev)
f96e0b
@@ -593,6 +598,8 @@ poll_nonroot_hub (grub_usb_device_t dev)
f96e0b
 	    {
f96e0b
 	      grub_usb_speed_t speed;
f96e0b
 	      grub_usb_device_t next_dev;
f96e0b
+	      int split_hubport = 0;
f96e0b
+	      int split_hubaddr = 0;
f96e0b
 
f96e0b
 	      /* Determine the device speed.  */
f96e0b
 	      if (status & GRUB_USB_HUB_STATUS_PORT_LOWSPEED)
f96e0b
@@ -608,8 +615,37 @@ poll_nonroot_hub (grub_usb_device_t dev)
f96e0b
 	      /* Wait a recovery time after reset, spec. says 10ms */
f96e0b
 	      grub_millisleep (10);
f96e0b
 
f96e0b
+              /* Find correct values for SPLIT hubport and hubaddr */
f96e0b
+	      if (speed == GRUB_USB_SPEED_HIGH)
f96e0b
+	        {
f96e0b
+		  /* HIGH speed device needs not transaction translation */
f96e0b
+		  split_hubport = 0;
f96e0b
+		  split_hubaddr = 0;
f96e0b
+		}
f96e0b
+	      else
f96e0b
+	        /* FULL/LOW device needs hub port and hub address
f96e0b
+		   for transaction translation (if connected to EHCI) */
f96e0b
+	        if (dev->speed == GRUB_USB_SPEED_HIGH)
f96e0b
+	          {
f96e0b
+		    /* This port is the first FULL/LOW speed port
f96e0b
+		       in the chain from root hub. Attached device
f96e0b
+		       should use its port number and hub address */
f96e0b
+		    split_hubport = i;
f96e0b
+		    split_hubaddr = dev->addr;
f96e0b
+		  }
f96e0b
+	        else
f96e0b
+	          {
f96e0b
+		    /* This port is NOT the first FULL/LOW speed port
f96e0b
+		       in the chain from root hub. Attached device
f96e0b
+		       should use values inherited from some parent
f96e0b
+		       HIGH speed hub - if any. */
f96e0b
+		    split_hubport = dev->split_hubport;
f96e0b
+		    split_hubaddr = dev->split_hubaddr;
f96e0b
+		  }
f96e0b
+		
f96e0b
 	      /* Add the device and assign a device address to it.  */
f96e0b
-	      next_dev = grub_usb_hub_add_dev (&dev->controller, speed, i, dev->addr);
f96e0b
+	      next_dev = grub_usb_hub_add_dev (&dev->controller, speed,
f96e0b
+					       split_hubport, split_hubaddr);
f96e0b
 	      if (dev->controller.dev->pending_reset)
f96e0b
 		{
f96e0b
 		  dev->controller.dev->pending_reset = 0;
f96e0b
diff --git a/include/grub/usb.h b/include/grub/usb.h
f96e0b
index 9e2c221..1cc9942 100644
f96e0b
--- a/include/grub/usb.h
f96e0b
+++ b/include/grub/usb.h
f96e0b
@@ -225,9 +225,9 @@ struct grub_usb_device
f96e0b
   struct grub_usb_desc_endp *hub_endpoint;
f96e0b
 
f96e0b
   /* EHCI Split Transfer information */
f96e0b
-  int port;
f96e0b
+  int split_hubport;
f96e0b
 
f96e0b
-  int hubaddr;
f96e0b
+  int split_hubaddr;
f96e0b
 };
f96e0b
 
f96e0b
 
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b