/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos720 src/bos/kernext/usb/common/hubClass.h 1.2.2.2                   */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2003,2013              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)06	1.2.2.2  src/bos/kernext/usb/common/hubClass.h, sysxusb, bos720 10/9/13 09:11:53 */

#ifndef _H_HUBCLASS
#define _H_HUBCLASS

#include <sys/types.h>

/*
 * Refer to Universal Serial Bus Specification Revision 2.0, chapter 11
 * for information concerning the items in this header file
 *
 * NOTE: bit masks for 16 bit fields are big endian 
 */

/* feature selectors                                                        */
/* USB 2.0 Rev 2.0 Specification - Section 11.24.2 - Table 11-16            */
#define USB_HUB_FS_C_HUB_LOCAL_POWER         0
#define USB_HUB_FS_C_HUB_OVER_CURRENT        1
#define USB_HUB_FS_PORT_CONNECTION           0
#define USB_HUB_FS_PORT_ENABLE               1
#define USB_HUB_FS_PORT_SUSPEND              2
#define USB_HUB_FS_PORT_OVERCURRNT           3
#define USB_HUB_FS_PORT_RESET                4
#define USB_HUB_FS_PORT_POWER                8
#define USB_HUB_FS_PORT_LOW_SPEED            9
#define USB_HUB_FS_C_PORT_CONNECTION        16 
#define USB_HUB_FS_C_PORT_ENABLE            17
#define USB_HUB_FS_C_PORT_SUSPEND           18
#define USB_HUB_FS_C_PORT_OVER_CURRENT      19
#define USB_HUB_FS_C_PORT_RESET             20
#define USB_HUB_FS_PORT_TEST                21
#define USB_HUB_FS_PORT_INDICATOR           22

/* USB 3.0 Rev 1.0 Specification - Section 10.14.2 - Table 10-6             */
#define USB_HUB_FS_PORT_U1_TIMEOUT          23   
#define USB_HUB_FS_PORT_U2_TIMEOUT          24
#define USB_HUB_FS_PORT_LINK_STATE           5
#define USB_HUB_FS_C_PORT_LINK_STATE        25
#define USB_HUB_FS_C_PORT_CONFIG_ERROR      26
#define USB_HUB_FS_PORT_REMOTE_WAKE_MASK    27
#define USB_HUB_FS_BH_PORT_RESET            28
#define USB_HUB_FS_C_BH_PORT_RESET          29
#define USB_HUB_FS_FORCE_LINKPM_ACCEPT      30

/* class descriptor  (variable length based on number of ports)             */
/* USB 2.0 Rev 2.0 Specification - Section 11.23.2.1 - Table 11-13          */
typedef struct _HubDesc     {
  fld8_t      blength;
  fld8_t      bDescriptorType;
#define USB_DT_HUB                          0x29
  fld8_t      bNbrPorts;
  fld16_t     wHubCharacteristics;
#define USB_HUB_DC_POWERSW_MASK         (3<<0)     
#define USB_HUB_DC_POWERSW_GANGED         (0<<0)
#define USB_HUB_DC_POWERSW_SINGLE         (1<<0)
#define USB_HUB_DC_POWERSW_NONE           (2<<0)
#define USB_HUB_DC_OCURRENT_MASK       (3<<3)
#define USB_HUB_DC_OCURRENT_GLOBAL        (0<<3)
#define USB_HUB_DC_OCURRENT_SINGLE        (1<<3)
#define USB_HUB_DC_OCURRENT_NONE          (2<<3)
#define USB_HUB_DC_TTT_MASK            (3<<5)
#define USB_HUB_DC_TTT_8FS                (0)
#define USB_HUB_DC_TTT_16FS               (1)
#define USB_HUB_DC_TTT_24FS               (2)
#define USB_HUB_DC_TTT_32FS               (3)
#define USB_HUB_DC_INDICATORS          (1<<7)           
  fld8_t      bPwrOn2PwrGood;
  fld8_t      bHubContrCurrent;
  fld8_t      devRemovePortPwrCtrlMask[1];
} HubDesc, *PHubDesc;

/* Super Speed Hub Class Descriptor                                       */
/* USB 3.0 Rev 1.0 Specification - Section 10.13.2.1 - Table 10-3         */
typedef struct _SSHubDesc     {
  fld8_t      blength;
  fld8_t      bDescriptorType;
#define USB_DT_SS_HUB                   0x2A
  fld8_t      bNbrPorts;
  fld16_t     wHubCharacteristics;
#define USB_HUB_DC_POWERSW_MASK         (3<<0)
#define USB_HUB_DC_POWERSW_GANGED         (0<<0)
#define USB_HUB_DC_POWERSW_SINGLE         (1<<0)
#define USB_HUB_DC_POWERSW_NONE           (2<<0)
#define USB_HUB_DC_OCURRENT_MASK       (3<<3)
#define USB_HUB_DC_OCURRENT_GLOBAL        (0<<3)
#define USB_HUB_DC_OCURRENT_SINGLE        (1<<3)
#define USB_HUB_DC_OCURRENT_NONE          (2<<3)
#define USB_HUB_DC_INDICATORS          (1<<7)
  fld8_t      bPwrOn2PwrGood;
  fld8_t      bHubContrCurrent;
  fld8_t      bHubHdrDecLat;
  fld16_t     wHubDelay;
  fld16_t     DeviceRemovable;
} SSHubDesc, *PSSHubDesc;

/* port status                           */
typedef struct _PortStatus {
  fld16_t     wStatus;
#define USB_HUB_PS_DEV_PRESENT            (1<<0)
#define USB_HUB_PS_ENABLED                (1<<1)
#define USB_HUB_PS_SUSPENDED              (1<<2)
#define USB_HUB_PS_OVER_CURRENT           (1<<3)
#define USB_HUB_PS_RESETTING              (1<<4)
#define USB_HUB_PS_POWERED_ON             (1<<8)
#define USB_HUB_PS_LOW_SPEED              (1<<9)
#define USB_HUB_PS_HIGH_SPEED             (1<<10)
#define USB_HUB_PS_TEST_MODE              (1<<11)
#define USB_HUB_PS_SOFT_COLORS            (1<<12)

/* Super Speed Port Status Defines - Table 10-10 USB 3.0 Rev 1.0 */
#define USB_SS_HUB_PS_DEV_PRESENT         (1<<0)
#define USB_SS_HUB_PS_ENABLED             (1<<1)
#define USB_SS_HUB_PS_OVER_CURRENT        (1<<3)
#define USB_SS_HUB_PS_PORT_RESET          (1<<4)

#define USB_SS_HUB_PS_PLS_MASK            (15<<5)
#define USB_SS_HUB_PS_PORT_LINK_U0            0x00
#define USB_SS_HUB_PS_PORT_LINK_U1            0x01
#define USB_SS_HUB_PS_PORT_LINK_U2            0x02
#define USB_SS_HUB_PS_PORT_LINK_U3            0x03
#define USB_SS_HUB_PS_PORT_LINK_SS_DISABLED   0x04
#define USB_SS_HUB_PS_PORT_LINK_RX_DETECT     0x05
#define USB_SS_HUB_PS_PORT_LINK_SS_INACTIVE   0x06
#define USB_SS_HUB_PS_PORT_LINK_POLLING       0x07
#define USB_SS_HUB_PS_PORT_LINK_RECOVERY      0x08
#define USB_SS_HUB_PS_PORT_LINK_HOT_RESET     0x09
#define USB_SS_HUB_PS_PORT_LINK_COMPLIANCE    0x0A
#define USB_SS_HUB_PS_PORT_LINK_LOOPBACK      0x0B

#define USB_SS_HUB_PS_PORT_POWER              (1<<9)
#define USB_SS_HUB_PS_PORT_SPEED_MASK         (7<<10)
#define USB_SS_HUB_PS_PORT_SPEED_5GBPS        0x0
  fld16_t     wChgStatus;
#define USB_HUB_PC_CONNECTION             (1<<0)
#define USB_HUB_PC_ENABLE                 (1<<1)
#define USB_HUB_PC_SUSPEND                (1<<2)
#define USB_HUB_PC_OVER_CURRENT           (1<<3)
#define USB_HUB_PC_RESET                  (1<<4)
/* Super Speed Port Change Status Defines - Table 10-11 USB 3.0 Rev 1.0 */
#define USB_SS_HUB_PC_CONN_STAT           (1<<0)
#define USB_SS_HUB_PC_OVER_CURRENT        (1<<3)
#define USB_SS_HUB_PC_RESET_CHANGE        (1<<4)
#define USB_SS_HUB_PC_BH_RESET_CHANGE     (1<<5)
#define USB_SS_HUB_PC_PORT_LINK_STATE     (1<<6)
#define USB_SS_HUB_PC_PORT_CONFIG_ERR     (1<<7)
} PortStatus, *PPortStatus;

/* hub status                            */
typedef struct _HubStatus {
  fld16_t     wStatus;
#define USB_HUB_HS_NO_LOCAL_POWER         (1<<0)
#define USB_HUB_HS_OVER_CURRENT           (1<<1)
  fld16_t     wChgStatus;
#define USB_HUB_HC_POWER                  (1<<0)
#define USB_HUB_HC_OVER_CURRENT           (1<<1)
} HubStatus, *PHubStatus;

/* interface timings                                                        */
/* USB 2.0 spec, page 150. */

/* t2: The original value is 100ms. The extra 100ms is to allow out-of-spec */
/* devices a chance to configure. */
#define USB_HUB_POR_RECOVERY_TIME  (100+100)    /* power on recovery (t2..100ms)  */

/* t3: The original value is 100ms. The extra 900ms is to allow out-of-spec */
/* devices a chance to configure. There is one device in particular that */
/* needs 810ms. */
#define USB_HUB_DEV_CONNECT_TIME   (100+900)    /* connection recovery (t3.100ms) */
                                                /* max reset time for non-root    */

#define USB_HUB_PORT_RESET_TIME     30    /* hub port (t5+t6....30ms)       */

/* power specifications                                                     */
                                          /* power available per port on    */
#define USB_HUB_PORT_POWER_SP      500    /* self powered hubs (ma)         */
                                          /* power available per port on    */
#define USB_HUB_PORT_POWER_BP      100    /* bus powered hubs  (ma)         */

#define USB_SS_HUB_PORT_POWER_SP   900   /* power available per port on    */
                                         /* self power SuperSpeed hubs(ma) */
#define USB_SS_HUB_PORT_POWER_BP   150   /* bus powered SuperSpeed hubs(ma)*/
/* bRequest field, hub class private request codes, table 11-16, USB 2.0.   */
#define USB_CLEAR_TT_BUFFER     8
#define USB_RESET_TT            9
#define USB_GET_TT_STATE        10 
#define USB_STOP_TT             11

/* Super Speed Hub Class Request Code, Table 10-6, USB 3.0 Rev 1.0          */
#define USB_SS_SET_HUB_DEPTH       12
#endif /* _H_HUBCLASS  */
