ohci_hub.c revision 112116d842e816e29d26a8fe28ed25d201063169
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Open Host Controller Driver (OHCI)
*
* The USB Open Host Controller driver is a software driver which interfaces
* to the Universal Serial Bus layer (USBA) and the USB Open Host Controller.
* The interface to USB Open Host Controller is defined by the OpenHCI Host
* Controller Interface.
*
* This module contains the code for root hub related functions.
*
* Note: ONE_XFER is not supported on root hub interrupt polling.
*/
/* static function prototypes */
static int ohci_handle_set_clear_port_feature(
static void ohci_handle_clrchng_port_enable(
static void ohci_handle_clrchng_port_suspend(
static void ohci_handle_complete_port_reset(
static void ohci_handle_clear_port_connection(
static void ohci_handle_clrchng_port_over_current(
static void ohci_handle_get_port_status(
static int ohci_handle_set_clear_hub_feature(
static void ohci_handle_clrchng_hub_over_current(
static void ohci_handle_get_hub_descriptor(
static void ohci_handle_get_hub_status(
static void ohci_handle_get_device_status(
static int ohci_root_hub_allocate_intr_pipe_resource(
static void ohci_root_hub_intr_pipe_cleanup(
static void ohci_root_hub_hcdi_callback(
/*
* ohci_init_root_hub:
*
* Initialize the root hub
*/
int
{
int i, length;
"ohci_init_root_hub:");
/* Read the descriptor registers */
/* Obtain the root hub status */
/*
* Build the hub descriptor based on HcRhDescriptorA and
* HcRhDescriptorB
*/
"ohci_init_root_hub:" "Invalid no of root hub ports 0x%x",
des_A & HCR_RHA_NDP);
return (USB_FAILURE);
}
/* Obtain the number of downstream ports */
if (length) {
} else {
}
/* Determine the Power Switching Mode */
if (!(des_A & HCR_RHA_NPS)) {
/*
* The ports are power switched. Check for either individual
* or gang power switching.
*/
/* each port is powered individually */
} else {
/* the ports are gang powered */
}
/* Each port will start off in the POWERED_OFF mode */
} else {
/* The ports are powered when the ctlr is powered */
}
/* The root hub should never be a compound device */
/* Determine the Over-current Protection Mode */
if (des_A & HCR_RHA_NOCP) {
/* No over current protection */
} else {
/* See if over current protection is provided */
if (des_A & HCR_RHA_OCPM) {
/* reported on a per port basis */
}
}
/* Obtain the power on to power good time of the ports */
/* Indicate if the device is removable */
/*
* Fill in the port power control mask:
* Each bit in the PortPowerControlMask
* should be set. Refer to USB 2.0, table 11-13
*/
/* Set the state of each port and initialize the status */
for (i = 0; i < root_hub_descr->bNbrPorts; i++) {
/* Turn off the power on each port for now */
/*
* Initialize each of the root hub port status
* equal to zero. This initialization makes sure
* that all devices connected to root hub will
* enumerates when the first RHSC interrupt occurs
* since definitely there will be changes in
* the root hub port status.
*/
}
return (USB_SUCCESS);
}
/*
* ohci_load_root_hub_driver:
*
* Attach the root hub
*/
static usb_dev_descr_t ohci_root_hub_device_descriptor = {
0x12, /* bLength */
0x01, /* bDescriptorType, Device */
0x110, /* bcdUSB, v1.1 */
0x09, /* bDeviceClass */
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
0x08, /* bMaxPacketSize0 */
0x00, /* idVendor */
0x00, /* idProduct */
0x00, /* bcdDevice */
0x00, /* iManufacturer */
0x00, /* iProduct */
0x00, /* iSerialNumber */
0x01 /* bNumConfigurations */
};
static uchar_t ohci_root_hub_config_descriptor[] = {
/* One configuartion */
0x09, /* bLength */
0x02, /* bDescriptorType, Configuartion */
0x19, 0x00, /* wTotalLength */
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
0x40, /* bmAttributes */
0x00, /* MaxPower */
/* One Interface */
0x09, /* bLength */
0x04, /* bDescriptorType, Interface */
0x00, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x01, /* bNumEndpoints */
0x09, /* bInterfaceClass */
0x01, /* bInterfaceSubClass */
0x00, /* bInterfaceProtocol */
0x00, /* iInterface */
/* One Endpoint (status change endpoint) */
0x07, /* bLength */
0x05, /* bDescriptorType, Endpoint */
0x81, /* bEndpointAddress */
0x03, /* bmAttributes */
0x01, 0x00, /* wMaxPacketSize, 1 + (OHCI_MAX_RH_PORTS / 8) */
0xff /* bInterval */
};
int
{
"ohci_load_root_hub_driver:");
sizeof (ohci_root_hub_config_descriptor),
}
/*
* ohci_unload_root_hub_driver:
*/
int
{
"ohci_unload_root_hub_driver:");
}
/*
* ohci_handle_root_hub_pipe_open:
*
* Handle opening of control and interrupt pipes on root hub.
*/
/* ARGSUSED */
int
{
"ohci_handle_root_hub_pipe_open: Root hub pipe open");
case USB_EP_ATTR_CONTROL:
/* Save control pipe handle */
/* Set state of the root hub control pipe as idle */
"ohci_handle_root_hub_pipe_open: Root hub control "
"pipe open succeeded");
break;
case USB_EP_ATTR_INTR:
/* Save interrupt pipe handle */
/* Set state of the root hub interrupt pipe as idle */
"ohci_handle_root_hub_pipe_open: Root hub interrupt "
"pipe open succeeded");
break;
default:
"ohci_handle_root_hub_pipe_open: Root hub pipe open"
"failed");
return (USB_FAILURE);
}
return (USB_SUCCESS);
}
/*
* ohci_handle_root_hub_pipe_close:
*
* Handle closing of control and interrupt pipes on root hub.
*/
/* ARGSUSED */
int
{
"ohci_handle_root_hub_pipe_close: Root hub pipe close");
case USB_EP_ATTR_CONTROL:
/* Set state of the root hub control pipe as close */
/* Set root hub control pipe handle to null */
"ohci_handle_root_hub_pipe_close: "
"Root hub control pipe close succeeded");
break;
case USB_EP_ATTR_INTR:
/* Set state of the root hub interrupt pipe as close */
/* Do interrupt pipe cleanup */
/* Set root hub interrupt pipe handle to null */
"ohci_handle_root_hub_pipe_close: "
"Root hub interrupt pipe close succeeded");
break;
default:
"ohci_handle_root_hub_pipe_close: "
"Root hub pipe close failed");
return (USB_FAILURE);
}
return (USB_SUCCESS);
}
/*
* ohci_handle_root_hub_pipe_reset:
*
* Handle resetting of control and interrupt pipes on root hub.
*/
/* ARGSUSED */
int
{
int error = USB_SUCCESS;
"ohci_handle_root_hub_pipe_reset: Root hub pipe reset");
case USB_EP_ATTR_CONTROL:
"ohci_handle_root_hub_pipe_reset: Pipe reset"
"for the root hub control pipe successful");
break;
case USB_EP_ATTR_INTR:
/* Do interrupt pipe cleanup */
}
"ohci_handle_root_hub_pipe_reset: "
"Pipe reset for root hub interrupt pipe successful");
break;
default:
"ohci_handle_root_hub_pipe_reset: "
"Root hub pipe reset failed");
error = USB_FAILURE;
break;
}
return (error);
}
/*
* ohci_handle_root_hub_request:
*
* Intercept a root hub request. Handle the root hub request through the
* registers
*/
/* ARGSUSED */
int
{
int error = USB_SUCCESS;
"ohci_handle_root_hub_request: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%p",
"ohci_handle_root_hub_request: Pipe is not idle");
return (USB_FAILURE);
}
/* Save the current control request pointer */
/* Set pipe state to active */
switch (bmRequestType) {
break;
break;
case HUB_GET_PORT_STATUS_TYPE:
break;
case HUB_CLASS_REQ_TYPE:
switch (bRequest) {
case USB_REQ_GET_STATUS:
break;
case USB_REQ_GET_DESCR:
break;
default:
"ohci_handle_root_hub_request:"
"Unsupported request 0x%x", bRequest);
error = USB_FAILURE;
break;
}
break;
break;
default:
"ohci_handle_root_hub_request: "
"Unsupported request 0x%x", bmRequestType);
error = USB_FAILURE;
break;
}
"ohci_handle_root_hub_request: error = %d", error);
return (USB_SUCCESS);
}
/*
* ohci_handle_set_clear_port_feature:
*/
static int
{
int error = USB_SUCCESS;
"ohci_handle_set_clear_port_feature: 0x%x 0x%x 0x%x",
switch (bRequest) {
case USB_REQ_SET_FEATURE:
switch (wValue) {
case CFS_PORT_ENABLE:
break;
case CFS_PORT_SUSPEND:
break;
case CFS_PORT_RESET:
break;
case CFS_PORT_POWER:
break;
default:
"ohci_handle_set_clear_port_feature: "
error = USB_FAILURE;
break;
}
break;
case USB_REQ_CLEAR_FEATURE:
switch (wValue) {
case CFS_PORT_ENABLE:
break;
case CFS_C_PORT_ENABLE:
break;
case CFS_PORT_SUSPEND:
break;
case CFS_C_PORT_SUSPEND:
break;
case CFS_C_PORT_RESET:
break;
case CFS_PORT_POWER:
break;
case CFS_C_PORT_CONNECTION:
break;
case CFS_C_PORT_OVER_CURRENT:
break;
default:
"ohci_handle_set_clear_port_feature: "
error = USB_FAILURE;
break;
}
break;
default:
"ohci_handle_set_clear_port_feature: "
error = USB_FAILURE;
break;
}
return (error);
}
/*
* ohci_handle_port_power:
*
* Turn on a root hub port.
*/
static void
{
uint_t p;
"ohci_handle_port_power: port = 0x%x status = 0x%x on = %d",
if (on) {
/*
* If the port power is ganged, enable the power through
* the status registers, else enable the port power.
*/
if ((hub_descr->wHubCharacteristics &
rh->rh_port_status[p] = 0;
}
} else {
/* See if the port power is already on */
if (!(port_status & HCR_PORT_PPS)) {
/* Turn the port on */
}
}
} else {
/*
* If the port power is ganged, disable the power through
* the status registers, else disable the port power.
*/
if ((hub_descr->wHubCharacteristics &
rh->rh_port_status[p] = 0;
}
} else {
/* See if the port power is already OFF */
if ((port_status & HCR_PORT_PPS)) {
/* Turn the port OFF by writing LSSA bit */
}
}
}
"ohci_handle_port_power done: "
"port = 0x%x status = 0x%x on = %d",
}
/*
* ohci_handle_port_enable:
*
* Handle port enable request.
*/
static void
{
"ohci_handle_port_enable: port = 0x%x, status = 0x%x",
port, port_status);
if (on) {
/* See if the port enable is already on */
if (!(port_status & HCR_PORT_PES)) {
/* Enable the port */
}
} else {
/* See if the port enable is already off */
if (port_status & HCR_PORT_PES) {
/* disable the port by writing CCS bit */
}
}
}
/*
* ohci_handle_clrchng_port_enable:
*
* Handle clear port enable change bit.
*/
static void
{
"ohci_handle_port_enable: port = 0x%x, status = 0x%x",
port, port_status);
/* Clear the PortEnableStatusChange Bit */
}
/*
* ohci_handle_port_suspend:
*
*/
static void
{
"ohci_handle_port_suspend: port = 0x%x, status = 0x%x",
port, port_status);
if (on) {
/* Suspend the port */
} else {
/* To Resume, we write the POCI bit */
}
}
/*
* ohci_handle_clrchng_port_suspend:
*
* Handle port clear port suspend change bit.
*/
static void
{
"ohci_handle_clrchng_port_suspend: port = 0x%x, status = 0x%x",
port, port_status);
}
/*
* ohci_handle_port_reset:
*
* Perform a port reset.
*/
static void
{
"ohci_handle_port_reset: port = 0x%x status = 0x%x",
port, port_status);
if (!(port_status & HCR_PORT_CCS)) {
"port_status & HCR_PORT_CCS == 0: "
}
}
/*
* ohci_handle_complete_port_reset:
*
* Perform a port reset change.
*/
static void
{
"ohci_handle_complete_port_reset: port = 0x%x status = 0x%x",
port, port_status);
if (!(port_status & HCR_PORT_CCS)) {
"port_status & HCR_PORT_CCS == 0: "
}
}
/*
* ohci_handle_clear_port_connection:
*
* Perform a clear port connection.
*/
static void
{
"ohci_handle_clear_port_connection: port = 0x%x"
/* Clear CSC bit */
}
/*
* ohci_handle_clrchng_port_over_current:
*
* Perform a clear over current condition.
*/
static void
{
"ohci_handle_clrchng_port_over_current: port = 0x%x"
}
/*
* ohci_handle_get_port_status:
*
* Handle a get port status request.
*/
static void
{
/* Read the current port status and return it */
"ohci_handle_get_port_status: port = %d new status = 0x%x"
/* Save the data in control request */
}
/*
* ohci_handle_set_clear_hub_feature:
*
* OHCI only implements clearing C_HUB_OVER_CURRENT feature now.
* Other hub requests of this bmRequestType are either not
* supported by hardware or never used.
*/
static int
{
int error = USB_SUCCESS;
"ohci_handle_set_clear_hub_feature: 0x%x 0x%x",
switch (bRequest) {
case USB_REQ_CLEAR_FEATURE:
if (wValue == CFS_C_HUB_OVER_CURRENT) {
} else {
"ohci_handle_set_clear_hub_feature: "
error = USB_FAILURE;
}
break;
case USB_REQ_SET_FEATURE:
default:
"ohci_handle_set_clear_hub_feature: "
error = USB_FAILURE;
break;
}
return (error);
}
/*
* ohci_handle_clrchng_hub_over_current:
*
* Clear over current indicator change bit on the root hub.
*/
static void
{
"ohci_handle_clrchng_hub_over_current: "
"status = 0x%x", hub_status);
}
/*
* ohci_handle_get_hub_descriptor:
*/
static void
{
"ohci_handle_get_hub_descriptor: Ctrl Req = 0x%p",
(void *)ctrl_reqp);
/* Save the data in control request */
}
/*
* ohci_handle_get_hub_status:
*
* Handle a get hub status request.
*/
static void
{
"ohci_handle_get_hub_status: new root hub status = 0x%x",
/* Save the data in control request */
}
/*
* ohci_handle_get_device_status:
*
* Handle a get device status request.
*/
static void
{
/*
* OHCI doesn't have device status information.
* Simply return what is desired for the request.
*/
"ohci_handle_get_device_status: device status = 0x%x",
/* Save the data in control request */
}
/*
* ohci_handle_root_hub_pipe_start_intr_polling:
*
* Handle start polling on root hub interrupt pipe.
*/
/* ARGSUSED */
int
{
int error = USB_SUCCESS;
"ohci_handle_root_hub_pipe_start_intr_polling: "
"Root hub pipe start polling");
/* ONE_XFER not supported for root hub interrupt pipe */
/* Get root hub intr pipe state */
switch (pipe_state) {
case OHCI_PIPE_STATE_IDLE:
/*
* Save the Original Client's Interrupt IN request
* information. We use this for final callback
*/
if (error != USB_SUCCESS) {
/* Reset client interrupt request pointer */
"ohci_handle_root_hub_pipe_start_intr_polling: "
"No Resources");
return (error);
}
"ohci_handle_root_hub_pipe_start_intr_polling: "
"Start polling for root hub successful");
break;
case OHCI_PIPE_STATE_ACTIVE:
"ohci_handle_root_hub_pipe_start_intr_polling: "
"Polling for root hub is already in progress");
break;
default:
"ohci_handle_root_hub_pipe_start_intr_polling: "
"Pipe is in error state 0x%x", pipe_state);
error = USB_FAILURE;
break;
}
return (error);
}
/*
* ohci_handle_root_hub_pipe_stop_intr_polling:
*
* Handle stop polling on root hub intr pipe.
*/
/* ARGSUSED */
void
{
"ohci_handle_root_hub_pipe_stop_intr_polling: "
"Root hub pipe stop polling");
/* Do interrupt pipe cleanup */
"ohci_hcdi_pipe_stop_intr_polling: Stop polling for root"
"hub successful");
} else {
"ohci_hcdi_pipe_stop_intr_polling: "
"Polling for root hub is already stopped");
}
}
/*
* ohci_root_hub_allocate_intr_pipe_resource:
*
* Allocate interrupt requests and initialize them.
*/
static int
{
"ohci_root_hub_allocate_intr_pipe_resource");
/* Get the interrupt pipe handle */
/* Get the current interrupt request pointer */
/*
* If current interrupt request pointer is null,
* allocate new interrupt request.
*/
if (curr_intr_reqp == NULL) {
/* Get the length of interrupt transfer */
if (curr_intr_reqp == NULL) {
"ohci_root_hub_allocate_intr_pipe_resource:"
"Interrupt request structure allocation failed");
return (USB_NO_RESOURCES);
}
ph->p_req_count++;
}
/* Start the timer for the root hub interrupt pipe polling */
}
return (USB_SUCCESS);
}
/*
* ohci_root_hub_intr_pipe_cleanup:
*
* Deallocate all interrupt requests and do callback
* the original client interrupt request.
*/
static void
{
"ohci_root_hub_intr_pipe_cleanup");
/* Get the interrupt pipe handle */
/* Get the interrupt timerid */
/* Stop the root hub interrupt timer */
if (timer_id) {
/* Reset the timer id to zero */
}
/* Reset the current interrupt request pointer */
/* Deallocate uncompleted interrupt request */
if (curr_intr_reqp) {
ph->p_req_count--;
}
/* Callback for original client interrupt request */
if (client_intr_reqp) {
}
}
/*
* ohci_handle_root_hub_status_change:
*
* A root hub status change interrupt will occur any time there is a change
* in the root hub status register or one of the port status registers.
*/
void
{
int i;
"ohci_handle_root_hub_status_change: state = %d",
/* Get the pointer to root hub descriptor */
/* Get the current interrupt request pointer */
/* Check whether timeout handler is valid */
/* Check host controller is in operational state */
/* Reset the timer id */
/* Do interrupt pipe cleanup */
return;
}
} else {
return;
}
/* See if the root hub status has changed */
if (new_root_hub_status & HCR_RH_CHNG_MASK) {
"ohci_handle_root_hub_status_change: "
"Root hub status has changed!");
all_ports_status = 1;
/* Update root hub status */
}
/* Check each port */
/*
* If there is change in the port status then set
* the bit in the bitmap of changes and inform hub
* driver about these changes. Hub driver will take
* care of these changes.
*/
if (change_status) {
if (change_status & HCR_PORT_CSC) {
/*
* Update the state depending on whether
* the port was attached or detached.
*/
if (new_port_status & HCR_PORT_CCS) {
rh_port_state[i] = DISABLED;
"Port %d connected", i+1);
} else {
rh_port_state[i] = DISCONNECTED;
"Port %d disconnected", i+1);
}
}
/* See if port enable status changed */
if (change_status & HCR_PORT_PESC) {
/*
* Update the state depending on whether
* the port was enabled or disabled.
*/
if (new_port_status & HCR_PORT_PES) {
rh_port_state[i] = ENABLED;
"Port %d enabled", i+1);
} else {
rh_port_state[i] = DISABLED;
"Port %d disabled", i+1);
}
}
/* Update the status */
}
}
/* Get the message block */
do {
/*
* check that mblk is big enough when we
* are writing bytes into it
*/
"ohci_handle_root_hub_status_change: "
"mblk data overflow.");
break;
}
all_ports_status >>= 8;
} while (all_ports_status != 0);
}
/* Reset the timer id */
/*
* If needed, allocate new interrupt request. Also
* start the timer for the root hub interrupt polling.
*/
ohcip, 0)) != USB_SUCCESS) {
"ohci_handle_root_hub_status_change: No Resources");
/* Do interrupt pipe cleanup */
}
}
}
/*
* ohci_root_hub_hcdi_callback()
*
* Convenience wrapper around usba_hcdi_cb() for the root hub.
*/
static void
{
uint_t pipe_state = 0;
"ohci_root_hub_hcdi_callback: ph = 0x%p, cr = 0x%x",
(void *)ph, completion_reason);
/* Set the pipe state as per completion reason */
switch (completion_reason) {
case USB_CR_OK:
switch (attributes) {
case USB_EP_ATTR_CONTROL:
break;
case USB_EP_ATTR_INTR:
break;
}
break;
case USB_CR_NO_RESOURCES:
case USB_CR_NOT_SUPPORTED:
case USB_CR_STOPPED_POLLING:
case USB_CR_PIPE_RESET:
case USB_CR_HC_HARDWARE_ERR:
/* Set pipe state to idle */
break;
case USB_CR_PIPE_CLOSING:
break;
default:
/* Set pipe state to error */
break;
}
switch (attributes) {
case USB_EP_ATTR_CONTROL:
break;
case USB_EP_ATTR_INTR:
/* if curr_intr_reqp available then use this request */
} else {
/* no current request, use client's request */
}
break;
}
}