📄 usbhubutility.c
字号:
/* usbHubUtility.c - Utility functions to provide the functionality of HUB class driver */
/* Copyright 2004-2005 Wind River Systems, Inc.
This software includes software licensed to Wind River Systems, Inc.
by Wipro, Ltd. Wind River licensees may use this software according
to the terms of their Wind River license agreement(s) applicable to
this software.
*/
/*
Modification history
--------------------
01j,06jan06,ami Check for multiple bus-powered hub incorporated (SPR #115386)
01i,18aug05,ami Fix for enumerating hubs with bcd version 0x101
01h,28mar05,pdg Allocation of hardware accessed memory changed
01g,23nov04,h_k fixed over writing read-only-data. (SPR #104386)
01f,15oct04,ami Refgen Changes
01e,11oct04,ami Apigen Changes
01d,07oct04,pdg SPR #100800 fix
01c,03aug04,mta coverity error fixes
01b,03aug04,ami Warning Messages Removed
01a,27jun03,nrv Changing the code to WRS standards
*/
/*
DESCRIPTION
This module provides the utility functions required for the functioning
of the USB Hub Class Driver.
INCLUDE FILES: usb2/usbOsal.h, usb2/usbHst.h, usb2/usbHubUtility.h,
usb2/usbHubGlobalVariables.h, usb2/usbHubBusManager.h,
usb2/usbHubEventHandler.h
*/
/*
INTERNAL
*******************************************************************************
* Filename : HUB_Utility.c
*
* Copyright :
*
* THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO
* LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING
* ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE
* 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY
* ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY
* PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE
* ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL.
* THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF
* THIS COPYRIGHT AS PER APPLICABLE LAWS.
*
*
* Description : This module provides the utility functions required for
* the functioning of the USB Hub Class Driver.
*
*
******************************************************************************/
/************************** INCLUDE FILES *************************************/
#include "usb2/usbOsal.h"
#include "usb2/usbHst.h"
#include "usb2/usbHubUtility.h"
#include "usb2/usbHubGlobalVariables.h"
#include "usb2/usbHubBusManager.h"
#include "usb2/usbHubEventHandler.h"
/****************** MODULE SPECIFIC FUNCTIONS DECLARATION *********************/
/*
* This function is used as a call back for the Reset. On failure, reset is
* retried for a maximum number of tries. If the maximum number of retries
* expires, the port is disabled.
*/
LOCAL USBHST_STATUS usbHubResetCallback ( pUSBHST_URB pResetURB);
/*
* This function is a general purpose call back function that can be used for
* issuing a blocking request.
*/
LOCAL USBHST_STATUS
usbHubBlockingCallback (pUSBHST_URB pUrb);
/*
* This function is the call back for the status change interrupt IN pipe
* completion.
*/
LOCAL USBHST_STATUS
usbHubInterruptRequestCallback (pUSBHST_URB pURB);
/*
* This Function is used to validate the Standard Descriptors
*/
LOCAL USBHST_STATUS usbHubValidateDescriptor (UINT8 * pDescriptor,
UINT16 uUsbDeviceVersion,UINT8 uDescriptorType);
/*
* This function is the call back function for the completion of a
* Clear TT request to a High Speed Hub.
*/
LOCAL USBHST_STATUS usbHubClearTTRequestCallback (pUSBHST_URB pURB);
/*
* This function is the call back function for the completion of a
* Reset TT request to a High Speed Hub.
*/
LOCAL USBHST_STATUS usbHubResetTTRequestCallback (pUSBHST_URB pURB);
/************************ GLOBAL FUNCTIONS DEFINITION *************************/
/***************************************************************************
*
* usbHubFindPortNumber - finds the port number of a device .
*
* This routine finds the port number of a device.
*
* RETURNS: port number, PORT_NUMBER_NOT_FOUND if the match was not
* found/invalid params.
*
* ERRNO: None
*
* \NOMANUAL
*/
LOCAL UINT8 usbHubFindPortNumber
(
pUSB_HUB_INFO pHub,
UINT32 uDeviceHandle
)
{
/* Counter for the port number */
UINT8 uPortCount = 0;
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,
"usbHubFindPortNumber:Called pHub=0x%x,devh=0x%x\n",
(UINT32)pHub,
uDeviceHandle,
0,
0);
/* If pHub is NULL then return PORT_NUMBER_NOT_FOUND*/
if (NULL == pHub)
{
/* Debug Message */
OS_LOG_MESSAGE_HIGH(
HUB,"usbHubFindPortNumber:pHub null \n",0,0,0,0);
return USB_PORT_NUMBER_NOT_FOUND;
}/* End of if (NULL==pHub) */
/*
* For all ports in the pHub::pPortList that are enabled
* i. Retrieve the HUB_PORT_INFO from pHub::pPortList[ port count ].
* ii. If the HUB_PORT_INFO::uDeviceHandle is equal to uDeviceHandle then
* return the portcount.
*/
for (uPortCount = 0;
uPortCount < pHub->HubDescriptor.bNbrPorts;
uPortCount++)
{
/* Retrieve the HUB_PORT_INFO structure */
pUSB_HUB_PORT_INFO pPort = pHub->pPortList[uPortCount];
/* Check if the port is enabled */
if (NULL != pPort)
{
/* Check for uDeviceHandle */
if ( uDeviceHandle == pPort->uDeviceHandle )
{
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,
"usbHubFindPortNumber:found %d\n",
uPortCount,
0,
0,
0);
return uPortCount;
}/* End of if (uDeviceHandle... */
} /* End of If (NULL != pPort) */
} /* End of for (uPortCount.... */
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,"usbHubFindPortNumber:Not Found\n",0,0,0,0);
/* Return PORT_NUMBER_NOT_FOUND.*/
return USB_PORT_NUMBER_NOT_FOUND;
}/* End of HUB_FindPortNumber() */
/***************************************************************************
*
* usbHubFindParentHubInBuses - searches for a parent hub.
*
* This routine searches for a parent hub.
*
* RETURNS: pointer to the PHUB_INFO, NULL if the match was not found/invalid
* params.
*
* ERRNO: None
*
* \NOMANUAL
*/
LOCAL pUSB_HUB_INFO usbHubFindParentHubInBuses
(
UINT32 uDeviceHandle
)
{
/* The bus List pointer to be used for browsing the list */
pUSB_HUB_BUS_INFO pBusList = gpGlobalBus;
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,
"usbHubFindParentHubInBuses:Called,devh=0x%x\n",
uDeviceHandle,
0,
0,
0);
/*
* For every bus in the gpGlobalBus do:
* i. Call HUB_FindParentHub () function to find the matching hub.
* If this returns a non NULL value, return the value.
*/
while (NULL != pBusList)
{
/* Find matching hub */
pUSB_HUB_INFO pHub =
usbHubFindParentHub(uDeviceHandle,pBusList->pRootHubInfo);
/* if found return the value */
if (NULL != pHub)
{
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,"usbHubFindParentHubInBuses:Found\n",0,0,0,0);
return pHub;
}/* End of if (NULL!=pHub) */
/* move the bus list pointer to the next bus pointer */
pBusList=pBusList->pNextBus;
}/* End of While (NULL != pBusList) */
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,"usbHubFindParentHubInBuses:Not Found\n",0,0,0,0);
/* Return NULL*/
return NULL;
} /* End of HUB_FindParentHubInBuses() */
/***************************************************************************
*
* usbHubFindParentHub - recursively searches for the parent hub.
*
* This routine recursively searches for the parent hub of the specified device.
*
* RETURNS: pointer to the PHUB_INFO, NULL if the match was not found/invalid
* params.
*
* ERRNO: None
*
* \NOMANUAL
*/
LOCAL pUSB_HUB_INFO usbHubFindParentHub
(
UINT32 uDeviceHandle ,
pUSB_HUB_INFO pHub
)
{
/* Counter for the port number */
UINT8 uPortCount = 0;
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,
"usbHubFindParentHub:Called uDevHandle=0x%x pHub=0x%x\n",
uDeviceHandle,
(UINT32)pHub,
0,
0);
/* If pHub is NULL then return NULL*/
if (NULL==pHub)
{
/* Debug Message */
OS_LOG_MESSAGE_MEDIUM(
HUB,"usbHubFindParentHub:pHub null \n",0,0,0,0);
return NULL;
}/* End of (NULL == pHub) */
/*
* For all ports in the pHub::pPortList that are not NULL
* i. Retrieve the HUB_PORT_INFO from pHub::pPortList[ port count]
* ii. If uDeviceHandle is same as HUB_PORT_INFO::uDeviceHandle then
* return pHub
*/
for (uPortCount = 0;
uPortCount < pHub->HubDescriptor.bNbrPorts;
uPortCount++)
{
/* Retrieve the HUB_PORT_INFO structure */
pUSB_HUB_PORT_INFO pPort = pHub->pPortList[uPortCount];
/* Check if the port is enabled */
if (NULL != pPort)
{
/* Check for uDeviceHandle */
if ( uDeviceHandle == pPort->uDeviceHandle )
{
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,"usbHubFindParentHub:found\n",0,0,0,0);
return pHub;
}/* End of if (uDeviceHandle... */
} /* End of If (NULL != pPort) */
} /* End of for (uPortCount.... */
/*
* For all ports in the pHub::pPortList that are not NULL
* i. Retrieve the HUB_PORT_INFO from pHub::pPortList[ port count]
* ii. If HUB_PORT_INFO::pHub is not NULL then:
* iii. Call HUB_FindParentHub () function to find the matching hub. If
* this
* returns a non NULL value, return the value.
*/
for (uPortCount = 0;
uPortCount < pHub->HubDescriptor.bNbrPorts;
uPortCount++)
{
/* Retrieve the HUB_PORT_INFO structure */
pUSB_HUB_PORT_INFO pPort = pHub->pPortList[uPortCount];
/* Check if the port is enabled */
if (NULL != pPort)
{
/* Check for Hub device */
if ( NULL != pPort->pHub)
{
/* storage for storing the result */
pUSB_HUB_INFO pResultHub ;
/* Call for matching hub in this sub tree. */
pResultHub = usbHubFindParentHub(uDeviceHandle,pPort->pHub);
/* Check if the hub was found */
if (NULL !=pResultHub)
{
return pResultHub;
}/* End of if (NULL != pResultHub ) */
}/* End of if (NULL != pPort->pHub) */
} /* End of If (NULL != pPort) */
} /* End of for (uPortCount.... */
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,"usbHUbFindParentHub:not found\n",0,0,0,0);
/* Return NULL*/
return NULL;
}/* End of HUB_FindParentHub() */
/***************************************************************************
*
* usbHubCreateBusStructure - Creates a bus structure .
*
* Creates a bus structure and connects the same to the global Bus list.
* This also launches a thread to handle the events occurring on the Bus.
*
* RETURNS: HUB_BUS_INFO, NULL .
*
* ERRNO: None
*
* \NOMANUAL
*/
LOCAL pUSB_HUB_BUS_INFO usbHubCreateBusStructure
(
UINT8 uBusHandle
)
{
char busManagerName [USB_BUSM_TASK_NAME_BASE_LEN];
pUSB_HUB_BUS_INFO pBusList = gpGlobalBus; /* Bus List pointer */
/* Set Bus Manager Thread Base Name */
strcpy ((char *) busManagerName, USB_BUSM_TASK_NAME_BASE);
/* Set the tag as the bus handle */
busManagerName [USB_BUSM_TASK_NAME_BASE_LEN - 2] = 'A' +(uBusHandle%26);
/* Debug Message */
OS_LOG_MESSAGE_LOW(
HUB,
"usbHubCreateBusStructure:Called 0x%x \n",
uBusHandle,
0,
0,
0);
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -