Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Jan 2015 11:28:04 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r276965 - stable/10/sys/dev/usb/controller
Message-ID:  <201501111128.t0BBS43i062185@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Sun Jan 11 11:28:03 2015
New Revision: 276965
URL: https://svnweb.freebsd.org/changeset/base/276965

Log:
  MFC r276321, r276404, r276407 and r276799:
  Various XHCI fixes and improvements:
  - Improve and fix MSI interrupt allocation, setup and release.
  - Add missed flushing of data which can happen when "xhci_configure_mask()"
    is called from "xhci_configure_reset_endpoint()". Ensure the 3-strikes
    error feature is always enabled except for ISOCHRONOUS transfers.
  - Allow systems having a page size greater than 4K to use fewer
    scatter-gather XHCI TRB entries for its payload data. The XHCI
    controller can handle at least 65536 bytes per scatter-gather list
    entry.

Modified:
  stable/10/sys/dev/usb/controller/xhci.c
  stable/10/sys/dev/usb/controller/xhci.h
  stable/10/sys/dev/usb/controller/xhci_pci.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/usb/controller/xhci.c
==============================================================================
--- stable/10/sys/dev/usb/controller/xhci.c	Sun Jan 11 11:27:25 2015	(r276964)
+++ stable/10/sys/dev/usb/controller/xhci.c	Sun Jan 11 11:28:03 2015	(r276965)
@@ -2287,6 +2287,7 @@ xhci_configure_mask(struct usb_device *u
 		temp |= XHCI_SCTX_0_CTX_NUM_SET(x + 1);
 		xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx0, temp);
 	}
+	usb_pc_cpu_flush(&sc->sc_hw.devs[index].input_pc);
 	return (0);
 }
 
@@ -2391,10 +2392,14 @@ xhci_configure_endpoint(struct usb_devic
 	    XHCI_EPCTX_1_MAXB_SET(max_packet_count) |
 	    XHCI_EPCTX_1_MAXP_SIZE_SET(max_packet_size);
 
-	if ((udev->parent_hs_hub != NULL) || (udev->address != 0)) {
-		if (type != UE_ISOCHRONOUS)
-			temp |= XHCI_EPCTX_1_CERR_SET(3);
-	}
+	/*
+	 * Always enable the "three strikes and you are gone" feature
+	 * except for ISOCHRONOUS endpoints. This is suggested by
+	 * section 4.3.3 in the XHCI specification about device slot
+	 * initialisation.
+	 */
+	if (type != UE_ISOCHRONOUS)
+		temp |= XHCI_EPCTX_1_CERR_SET(3);
 
 	switch (type) {
 	case UE_CONTROL:

Modified: stable/10/sys/dev/usb/controller/xhci.h
==============================================================================
--- stable/10/sys/dev/usb/controller/xhci.h	Sun Jan 11 11:27:25 2015	(r276964)
+++ stable/10/sys/dev/usb/controller/xhci.h	Sun Jan 11 11:28:03 2015	(r276965)
@@ -320,11 +320,23 @@ struct xhci_dev_endpoint_trbs {
 	    XHCI_MAX_TRANSFERS) + XHCI_MAX_STREAMS];
 };
 
-#define	XHCI_TD_PAGE_NBUF	17	/* units, room enough for 64Kbytes */
-#define	XHCI_TD_PAGE_SIZE	4096	/* bytes */
-#define	XHCI_TD_PAYLOAD_MAX	(XHCI_TD_PAGE_SIZE * (XHCI_TD_PAGE_NBUF - 1))
+#if (USB_PAGE_SIZE < 4096)
+#error "The XHCI driver needs a pagesize above or equal to 4K"
+#endif
+
+/* Define the maximum payload which we will handle in a single TRB */
+#define	XHCI_TD_PAYLOAD_MAX	65536	/* bytes */
+
+/* Define the maximum payload of a single scatter-gather list element */
+#define	XHCI_TD_PAGE_SIZE \
+  ((USB_PAGE_SIZE < XHCI_TD_PAYLOAD_MAX) ? USB_PAGE_SIZE : XHCI_TD_PAYLOAD_MAX)
+
+/* Define the maximum length of the scatter-gather list */
+#define	XHCI_TD_PAGE_NBUF \
+  (((XHCI_TD_PAYLOAD_MAX + XHCI_TD_PAGE_SIZE - 1) / XHCI_TD_PAGE_SIZE) + 1)
 
 struct xhci_td {
+	/* one LINK TRB has been added to the TRB array */
 	struct xhci_trb		td_trb[XHCI_TD_PAGE_NBUF + 1];
 
 /*
@@ -452,7 +464,6 @@ struct xhci_softc {
 
 	struct usb_device	*sc_devices[XHCI_MAX_DEVICES];
 	struct resource		*sc_io_res;
-	int			sc_irq_rid;
 	struct resource		*sc_irq_res;
 
 	void			*sc_intr_hdl;

Modified: stable/10/sys/dev/usb/controller/xhci_pci.c
==============================================================================
--- stable/10/sys/dev/usb/controller/xhci_pci.c	Sun Jan 11 11:27:25 2015	(r276964)
+++ stable/10/sys/dev/usb/controller/xhci_pci.c	Sun Jan 11 11:28:03 2015	(r276965)
@@ -201,21 +201,19 @@ xhci_pci_attach(device_t self)
 
 	usb_callout_init_mtx(&sc->sc_callout, &sc->sc_bus.bus_mtx, 0);
 
-	sc->sc_irq_rid = 0;
+	rid = 0;
 	if (xhci_use_msi) {
-		count = pci_msi_count(self);
-		if (count >= 1) {
-			count = 1;
-			if (pci_alloc_msi(self, &count) == 0) {
-				if (bootverbose)
-					device_printf(self, "MSI enabled\n");
-				sc->sc_irq_rid = 1;
-			}
+		count = 1;
+		if (pci_alloc_msi(self, &count) == 0) {
+			if (bootverbose)
+				device_printf(self, "MSI enabled\n");
+			rid = 1;
 		}
 	}
-	sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ,
-	    &sc->sc_irq_rid, RF_SHAREABLE | RF_ACTIVE);
+	sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid,
+	    RF_ACTIVE | (rid != 0 ? 0 : RF_SHAREABLE));
 	if (sc->sc_irq_res == NULL) {
+		pci_release_msi(self);
 		device_printf(self, "Could not allocate IRQ\n");
 		/* goto error; FALLTHROUGH - use polling */
 	}
@@ -232,16 +230,22 @@ xhci_pci_attach(device_t self)
 		err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
 		    NULL, (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl);
 		if (err != 0) {
+			bus_release_resource(self, SYS_RES_IRQ,
+			    rman_get_rid(sc->sc_irq_res), sc->sc_irq_res);
+			sc->sc_irq_res = NULL;
+			pci_release_msi(self);
 			device_printf(self, "Could not setup IRQ, err=%d\n", err);
 			sc->sc_intr_hdl = NULL;
 		}
 	}
-	if (sc->sc_irq_res == NULL || sc->sc_intr_hdl == NULL ||
-	    xhci_use_polling() != 0) {
-		device_printf(self, "Interrupt polling at %dHz\n", hz);
-		USB_BUS_LOCK(&sc->sc_bus);
-		xhci_interrupt_poll(sc);
-		USB_BUS_UNLOCK(&sc->sc_bus);
+	if (sc->sc_irq_res == NULL || sc->sc_intr_hdl == NULL) {
+		if (xhci_use_polling() != 0) {
+			device_printf(self, "Interrupt polling at %dHz\n", hz);
+			USB_BUS_LOCK(&sc->sc_bus);
+			xhci_interrupt_poll(sc);
+			USB_BUS_UNLOCK(&sc->sc_bus);
+		} else
+			goto error;
 	}
 
 	/* On Intel chipsets reroute ports from EHCI to XHCI controller. */
@@ -304,11 +308,10 @@ xhci_pci_detach(device_t self)
 		sc->sc_intr_hdl = NULL;
 	}
 	if (sc->sc_irq_res) {
-		if (sc->sc_irq_rid == 1)
-			pci_release_msi(self);
-		bus_release_resource(self, SYS_RES_IRQ, sc->sc_irq_rid,
-		    sc->sc_irq_res);
+		bus_release_resource(self, SYS_RES_IRQ,
+		    rman_get_rid(sc->sc_irq_res), sc->sc_irq_res);
 		sc->sc_irq_res = NULL;
+		pci_release_msi(self);
 	}
 	if (sc->sc_io_res) {
 		bus_release_resource(self, SYS_RES_MEMORY, PCI_XHCI_CBMEM,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201501111128.t0BBS43i062185>