PERFORCE change 182091 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Sun Aug 8 16:07:33 UTC 2010
http://p4web.freebsd.org/@@182091?ac=10
Change 182091 by hselasky at hselasky_laptop001 on 2010/08/08 16:06:33
USB controller (XHCI):
- fix some final configuration details according to spec.
- disable debugging prints by default.
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb/controller/xhci.c#18 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb/controller/xhci.c#18 (text+ko) ====
@@ -85,7 +85,7 @@
((uint8_t *)&(((struct xhci_softc *)0)->sc_bus))))
#ifdef USB_DEBUG
-static int xhcidebug = 17;
+static int xhcidebug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, xhci, CTLFLAG_RW, 0, "USB XHCI");
SYSCTL_INT(_hw_usb_xhci, OID_AUTO, debug, CTLFLAG_RW,
@@ -124,6 +124,7 @@
static usb_error_t xhci_configure_device(struct usb_device *);
static usb_error_t xhci_configure_endpoint(struct usb_device *, struct usb_endpoint_descriptor *, uint64_t, uint16_t, uint8_t, uint16_t, uint16_t);
static usb_error_t xhci_configure_mask(struct usb_device *, uint32_t, uint8_t);
+static usb_error_t xhci_cmd_evaluate_ctx(struct xhci_softc *, uint64_t, uint8_t);
extern struct usb_bus_methods xhci_bus_methods;
@@ -1045,8 +1046,13 @@
static usb_error_t
xhci_set_address(struct usb_device *udev, struct mtx *mtx, uint16_t address)
{
+ struct usb_page_search buf_inp;
+ struct usb_page_search buf_dev;
struct xhci_softc *sc = XHCI_BUS2SC(udev->bus);
struct xhci_hw_dev *hdev;
+ struct xhci_dev_ctx *pdev;
+ struct xhci_endpoint_ext *pepext;
+ uint16_t mps;
usb_error_t err;
uint8_t index;
@@ -1084,55 +1090,78 @@
/* configure input slot context structure */
err = xhci_configure_device(udev);
+ if (err != 0) {
+ DPRINTF("Could not configure device\n");
+ break;
+ }
+
/* configure input endpoint context structure */
- if (err == 0) {
- struct xhci_endpoint_ext *pepext;
- uint16_t mps;
+
+ switch (udev->speed) {
+ case USB_SPEED_LOW:
+ case USB_SPEED_FULL:
+ mps = 8;
+ break;
+ case USB_SPEED_HIGH:
+ mps = 64;
+ break;
+ default:
+ mps = 512;
+ break;
+ }
- switch (udev->speed) {
- case USB_SPEED_LOW:
- case USB_SPEED_FULL:
- mps = 8;
- break;
- case USB_SPEED_HIGH:
- mps = 64;
- break;
- default:
- mps = 512;
- break;
- }
+ pepext = xhci_get_endpoint_ext(udev,
+ &udev->ctrl_ep_desc);
+ err = xhci_configure_endpoint(udev,
+ &udev->ctrl_ep_desc, pepext->physaddr,
+ 0, 1, mps, mps);
- pepext = xhci_get_endpoint_ext(udev,
- &udev->ctrl_ep_desc);
- err = xhci_configure_endpoint(udev,
- &udev->ctrl_ep_desc, pepext->physaddr,
- 0, 1, mps, mps);
+ if (err != 0) {
+ DPRINTF("Could not configure default endpoint\n");
+ break;
}
/* execute set address command */
- if (err == 0) {
- struct usb_page_search buf_inp;
+ usbd_get_page(&hdev->input_pc, 0, &buf_inp);
- usbd_get_page(&hdev->input_pc, 0, &buf_inp);
+ err = xhci_cmd_set_address(sc, buf_inp.physaddr,
+ (address == 0), index);
- err = xhci_cmd_set_address(sc, buf_inp.physaddr,
- (address == 0), index);
+ if (err != 0) {
+ DPRINTF("Could not set address\n");
+ break;
}
- /* update device address and state to new value */
- if (err == 0) {
- struct usb_page_search buf_dev;
- struct xhci_dev_ctx *pdev;
+ /* update device address to new value */
+
+ usbd_get_page(&hdev->device_pc, 0, &buf_dev);
+ pdev = buf_dev.buffer;
+ usb_pc_cpu_invalidate(&hdev->device_pc);
+ udev->address = XHCI_SCTX_3_DEV_ADDR_GET(pdev->ctx_slot.dwSctx3);
+
+ /* update device state to new value */
+
+ if (address != 0) {
+
+ /* we skip the addressed state */
+ hdev->state = XHCI_ST_CONFIGURED;
+
+ xhci_configure_mask(udev, 1, 0);
+
+ err = xhci_configure_device(udev);
+ if (err != 0) {
+ DPRINTF("Could not configure device\n");
+ break;
+ }
- if (address == 0)
- hdev->state = XHCI_ST_DEFAULT;
- else
- hdev->state = XHCI_ST_ADDRESSED;
+ err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index);
- usbd_get_page(&hdev->device_pc, 0, &buf_dev);
- pdev = buf_dev.buffer;
- usb_pc_cpu_invalidate(&hdev->device_pc);
- udev->address = XHCI_SCTX_3_DEV_ADDR_GET(pdev->ctx_slot.dwSctx3);
+ if (err != 0) {
+ DPRINTF("Could not evaluate device context\n");
+ break;
+ }
+ } else {
+ hdev->state = XHCI_ST_DEFAULT;
}
break;
@@ -3228,69 +3257,52 @@
err = xhci_configure_endpoint_by_xfer(xfer);
- if (err == 0) {
+ if (err != 0) {
+ XHCI_CMD_UNLOCK(sc);
+ return (err);
+ }
- err = xhci_cmd_reset_ep(sc, 0, epno, index);
+ /*
+ * Get the endpoint into the stopped state according to the
+ * endpoint context state diagram in the XHCI specification:
+ */
- if (err != 0)
- DPRINTF("Could not reset endpoint %u\n", epno);
+ err = xhci_cmd_stop_ep(sc, 0, epno, index);
- if (epno > 1) {
+ if (err != 0)
+ DPRINTF("Could not stop endpoint %u\n", epno);
- err = xhci_cmd_stop_ep(sc, 0, epno, index);
+ err = xhci_cmd_reset_ep(sc, 0, epno, index);
- if (err != 0)
- DPRINTF("Could not stop endpoint %u\n", epno);
+ if (err != 0)
+ DPRINTF("Could not reset endpoint %u\n", epno);
- if (sc->sc_hw.devs[index].state != XHCI_ST_CONFIGURED) {
- sc->sc_hw.devs[index].state = XHCI_ST_CONFIGURED;
+ err = xhci_cmd_set_tr_dequeue_ptr(sc, pepext->physaddr |
+ XHCI_EPCTX_2_DCS_SET(1), 0, epno, index);
- xhci_configure_mask(udev, 1, 0);
+ if (err != 0)
+ DPRINTF("Could not set dequeue ptr for endpoint %u\n", epno);
- err = xhci_configure_device(udev);
+ /*
+ * Get the endpoint into the running state according to the
+ * endpoint context state diagram in the XHCI specification:
+ */
- if (err != 0)
- DPRINTF("Could not deconfigure device\n");
+ xhci_configure_mask(udev, 1U << epno, 0);
- err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index);
+ err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index);
- if (err != 0)
- DPRINTF("Could not evaluate device\n");
- }
+ if (err != 0)
+ DPRINTF("Could not configure endpoint %u\n", epno);
- xhci_configure_mask(udev, 1U << epno, 1);
+ err = xhci_cmd_configure_ep(sc, buf_inp.physaddr, 0, index);
- err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index);
-
- if (err != 0)
- DPRINTF("Could not deconfigure endpoint %u\n", epno);
- }
-
- xhci_configure_mask(udev, 1U << epno, 0);
-
- err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index);
-
- if (err != 0)
- DPRINTF("Could not configure endpoint %u\n", epno);
-
- err = xhci_cmd_configure_ep(sc, buf_inp.physaddr, 0, index);
-
- if (err != 0)
- DPRINTF("Could not configure endpoint %u\n", epno);
- }
-
- /* reset endpoint */
+ if (err != 0)
+ DPRINTF("Could not configure endpoint %u\n", epno);
- if (err == 0) {
- err = xhci_cmd_set_tr_dequeue_ptr(sc, pepext->physaddr |
- XHCI_EPCTX_2_DCS_SET(1), 0, epno, index);
-
- if (err != 0)
- DPRINTF("Could not set dequeue ptr for endpoint %u\n", epno);
- }
XHCI_CMD_UNLOCK(sc);
- return (err);
+ return (0);
}
static void
@@ -3513,10 +3525,11 @@
if (index <= sc->sc_noslot) {
xhci_cmd_disable_slot(sc, index);
sc->sc_hw.devs[index].state = XHCI_ST_DISABLED;
+
+ /* free device extension */
+ xhci_free_device_ext(udev);
}
- xhci_free_device_ext(udev);
-
XHCI_CMD_UNLOCK(sc);
}
More information about the p4-projects
mailing list