/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72D src/bos/kernext/usb/common/usbdi.h 1.11.3.6                     */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2003,2016              */
/* 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                                                     */
/* @(#)05       1.11.3.6  src/bos/kernext/usb/common/usbdi.h, sysxusb, bos72D, d2016_21A3 5/19/16 04:17:06 */
#ifndef _H_USBDI
#define _H_USBDI

#include <sys/types.h>
#include <sys/intr.h>
#include <sys/stdint.h>

/*
 * USB handle 
 */
typedef void * USBhandle;             /* opaque handle                       */

/*
 * status 
 */
typedef int   USBstatus;

#define  MAX_USB_HC   16               /* Max.Number HC's allowed for         */
                                      /* Registration at a time              */   

/* USBstatus may be anything in errno.h as well as the following:            */
#define USBD_SUCCESS          0       /* successful operation                */
#define USBD_STALL           -1       /* pipe stalled                        */
#define USBD_HALTED          -2       /* pipe halted                         */
#define USBD_ACTIVE          -3       /* pipe active                         */
#define USBD_DISCONNECT      -4       /* device has been disconnected        */
#define USBD_ABORTING        -5       /* IRP is aborting                     */
#define USBD_ABORTED         -6       /* IRP has been aborted                */
#define USBD_PENDING         -7       /* IRP is pending                      */
#define USBD_BANDWIDTH       -8       /* pipe connect failed due to          */
                                      /*   bandwidth requirements            */
#define USBD_SPEED           -9       /* port failed to reset due to         */
                                      /*   device speed mismatch             */
#define USBD_POWER           -10      /* device exceeds power budget         */
#define USBD_DATA            -11      /* invalid response from device        */
#define USBD_ERROR           -12      /* non-specific error condition        */
#define USBD_BADHANDLE       -13      /* bad handle                          */
#define USBD_TIMEOUT         -14      /* I/O operation timed out             */

/* ---------------- */
/* Extended Status Codes */
#define USBD_X_CRC                 -15 /* data transmission error */
#define USBD_X_BitStuffing         -16 /* data encoding transmission error */
#define USBD_X_DataToggleMismatch  -17 /* a possible packet loss detected */
#define USBD_X_DeviceNotResponding -18 /* a device didn't respond promptly */
#define USBD_X_PIDCheckFailure     -19 /* Packet ID transmission error */
#define USBD_X_UnexpectedPID       -20 /* PID valid but not expected */
#define USBD_X_DataOverrun         -21 /* more data than expected on IN */
                /* or for isochronous ConditionCode a skipped last packet */
#define USBD_X_DataUnderrun        -22 /* less data than expected on IN */
#define USBD_X_BufferOverrun       -23 /* scheduling/bus contention on IN */
#define USBD_X_BufferUnderrun      -24 /* scheduling/bus contention on OUT */
#define USBD_X_NotAccessed         -25 /* skipped packet (isochronous) */
#define USBD_X_Unimplemented       -26 /* a service is not yet available */

/* Extended Status Codes, EHCI */
#define USBD_X_Babble              -27
#define USBD_X_TransactionError    -28
#define USBD_X_ERRHandshake        -29
#define USBD_X_MissedMicroFrame    -30

/*
 * USBD special file name 
 */
#ifdef AIX52
#define USBD_SPECIAL_FILE "/dev/usbpd0"
#else 
#define USBD_SPECIAL_FILE "/dev/usb0"
#endif

/*
 * device support query command (to client driver via sysconfig)
 */
#define USB_DVDR_QUERY            100

/*
 * device types
 */
#define DEVCLASS_NONE             0   /* Invalid Device Class                */
#define DEVCLASS_DISK             1   /* USB Disk Device Class               */
#define DEVCLASS_CDROM            2   /* USB CDROM Device Class              */
#define DEVCLASS_DVD              3   /* USB DVD Device Class                */
#define DEVCLASS_CD_WRIT          4   /* USB CD Writer Device Class          */
#define DEVCLASS_DVD_COMBO        5   /* USB DVD Combo Device Class          */
#define DEVCLASS_DVD_RAM          6   /* USB DVD RAM Device Class            */
#define DEVCLASS_3DX              8   /* HID devices from 3DConnexion        */
#define DEVCLASS_COM              9   /* USB Com Device Class                */
#define DEVCLASS_AUDIO         0x0a   /* USB Audio Device Class              */
#define DEVCLASS_FLASHDRV      0x0b   /* USB Flash Drive Device Class        */
#define DEVCLASS_TAPE          0x0c   /* USB Tape Device Class               */
#define DEVCLASS_BD            0x0d   /* USB BluRay Reader device Class      */
#define DEVCLASS_BD_COMBO      0x0e   /* USB BluRay Combo device Class       */
#define DEVCLASS_BD_REC        0x0f   /* USB BluRay Recorder device Class    */

/*
 * ioctl's
 */
#define USBD_REGISTER_SINGLE_HC   1   /* register a single hardware controller*/
#define USBD_ENUMERATE_DEVICE     2   /* enumerate connected USB devices     */
#define USBD_OPEN_DEVICE          3   /* open usb device                     */
#define USBD_ENUMERATE_ALL        4   /* enumerate USB devices incl hubs     */
#define USBD_GET_DESCRIPTORS      5   /* get device descriptors              */
#define USBD_OPEN_DEVICE_EXT      6   /* open usb device extended            */
#define USBD_REGISTER_MULTI_HC    7   /* register multiple hardware controllers*/
#define USBD_ALLOC_CLIENT         8   /* create a client for libusb */
#define USBD_DELETE_CLIENT        9   /* delete a client for libusb */
#define USBD_KERNEL_DRIVER_ACTIVE 10  /* check if client driver is active */
#define USBD_ENUMERATE_CFG      100   /* enumerate USB devices for config    */
#define USBD_CFG_CLIENT_UPDATE  101   /* update client info                  */
#define USBD_INFO_REQUEST       200   /* a request for device information    */
#define USBD_STATUS_FEED        201   /* a request for status change info    */


#define USBLIB_ENUMERATE_ALL      1   /* Enumerating all usb devices */
#define USBLIB_GET_DESCRIPTORS    2   /* Getting the usb descriptors */
#define USBLIB_PIPE_CONNECT       3   /* For pipe connect from libusb */
#define USBLIB_PIPE_IO            4   /* For submitting I/O */
#define USBLIB_PIPE_DISCONNECT    5   /* For pipe disconnect */
#define USBLIB_HALT_CLEAR         6   /* For clearing stall condition */
#define USBLIB_GETIRP_STATUS      7   /* For knowing I/O status */
#define USBLIB_SET_CONFIGURATION  8   /* Issue Set configuration */
#define USBLIB_CLAIM_INTERFACE    9   /* Get control of the usb device */
#define USBLIB_RELEASE_INTERFACE 10   /* release control of the usb device */
#define USBLIB_SET_ALT_INTFC     11   /* for setting alternate interface */
#define USBLIB_RESET_DEVICE      12   /* reset the device */
#define USBD_GET_DEV_DESCRIPTORS 13   /* getting client information */
#define USBLIB_ABORT_IO          14   /* cancel the I/O */
#define USBLIB_GET_CONFIG_DESC   15   /* read all config descriptors */
#define USBLIB_KERNEL_DRIVER_ACTIVE 16  /* check if client driver is active */

#define USBLIBKE_IOCTL_TOGGLE    1    /* find if toggle has to be sent */
#define USBLIBKE_IOCTL_LIBUSB    2    /* for detecting libusb's client */ 
/*
 * enumerate USB devices (USBD_ENUMERATE_DEVICE / USBD_ENUMERATE_ALL)
 */
#define USB_HUB_DEPTH       8         /* Maximum depth of hubs               */

typedef struct usb_devices{
    uint8_t  port[USB_HUB_DEPTH];     /* port traversal from head to device  */
    uint8_t  depth;                   /* topology depth                      */
    uint8_t  addr;                    /* physical device address.            */
    uint8_t  cfg;                     /* configuration number (1..?)         */
    uint8_t  intfc;                   /* interface index (0..?)              */
    uint8_t  usb_class;               /* interface class                     */
    uint8_t  usb_subclass;            /* interface subclass                  */
    uint8_t  usb_protocol;            /* interface protocol                  */
    uint8_t  device_type;             /* device type                         */
    uint8_t  num_interfaces;          /* config descriptor "bNumInterfaces"  */
    uint8_t  speed;                   /* device speed                        */
    uint8_t  reserved[7];
} usb_device_t;

typedef struct _USBENUM {
    dev32_t  devno;                   /* 32 bit devno of host controller     */
    int      buffSize;                /* number of bytes in devinfo array    */
    int      numDevDisc;              /* number of logical devices discovered*/
    int      numDevEnum;              /* number of logical devices enumerated*/
    usb_device_t devinfo[1];          /* device enumeration follows          */
} USBENUM, *PUSBENUM;

/*
 * USB device open  (USBD_OPEN_DEVICE)
 */
typedef struct _DEVSELECTOR {
    dev32_t  hcdevno;                 /* 32 bit devno of host controller     */
    uint     addr;                    /* USB device address                  */
    uint     cfg;                     /* configuration number (1-?)          */
    uint     intfc;                   /* interface index (0-?)               */
    uint     usb_class;               /* interface class                     */
    uint     usb_subclass;            /* interface subclass                  */
    uint     usb_protocol;            /* interface protocol                  */
    uint     device_type;             /* device type                         */
    uint8_t  speed;                    /* device speed                        */
} DEVSELECTOR, *PDEVSELECTOR;

typedef struct _DEVOPEN {
    PDEVSELECTOR pDevSel;             /* ptr to DEVSELECTOR structure        */
                                      /* ptr to disconnect callback routine  */
    void         (*disconnect)(USBhandle, void *);
                                      /* ptr to reconnect callback routine   */
    USBstatus    (*reconnect)(USBhandle, void *);
    void         *arg;                /* ptr to callback argument            */
    USBhandle    *hDev;               /* location to return device handle    */
} DEVOPEN, *PDEVOPEN;

/*
 * enumerate USB devices for configuration (USBD_ENUMERATE_CFG)
 *
 * WARNING: don't change USBENUMCFG unless you also change USBENUM  
 */
typedef struct _USBCFGINFO {
  usb_device_t devinfo;
  DEVSELECTOR  clientinfo;
} USBCFGINFO, *PUSBCFGINFO;

typedef struct _USBENUMCFG {
    dev32_t  devno;                   /* 32 bit devno of host controller     */
    int      buffSize;                /* number of bytes in devinfo array    */
    int      numDevDisc;              /* number of logical devices discovered*/
    int      numDevEnum;              /* number of logical devices enumerated*/
    USBCFGINFO devinfo[1];            /* device enumeration follows          */
} USBENUMCFG, *PUSBENUMCFG;

/*
 * update client information (USBD_CFG_CLIENT_UPDATE)
 */
typedef struct _CLIENTUPDATE {
  DEVSELECTOR  old;
  DEVSELECTOR  new;
} CLIENTUPDATE, *PCLIENTUPDATE;

/*
 * get device descriptors (USBD_GET_DESCRIPTORS)                      
 *
 * note: all returned descriptor(s) adhere to format specified by Universal
 *       Serial Bus Specification Revision 2.0 except for strings
 *       (see StringDesc structure)
 *
 *       upon return buffer points to DESCIDX followed by descriptors
 *       descriptors := LL TT vv vv vv LL TT vv vv vv 00
 *          where: LL := length of descriptor including length fld
 *                 TT := descriptor ID
 *                 vv := descriptor data
 *                 00 := end of descriptors indicator
 *
 */
typedef struct _USBDGD {        
    dev32_t  hcdevno;                 /* 32 bit devno of host controller     */
    uint     addr;                    /* USB device address                  */
    uint     cfg;                     /* configuration number (1-?)          */
    uint     intfc;                   /* interface index (0-?)               */
    int      bufferLength;            /* length of buffer (bytes)            */
    int      minBuffLength;           /* min. required buffer length (bytes) */
    caddr_t  buffer;                  /* pointer to buffer                   */
} USBDGD, *PUSBDGD;

#ifdef __64BIT_KERNEL
typedef struct _USBDGD_32 {        
    dev32_t  hcdevno;
    uint     addr;
    uint     cfg;
    uint     intfc;
    int      bufferLength;
    int      minBuffLength;
    __ptr32  buffer;
} USBDGD_32, *PUSBDGD_32;
#endif

/* index structure for descriptors                                           */
typedef struct _DESCIDX {           
    caddr_t                  pDesc;         /* start of descriptor strings   */
    struct _USBDevDesc      *pDevDesc;      /* start of std device descriptor*/
    struct _USBConfigDesc   *pConfigDesc;   /* start of config descriptor    */
    struct _USBIFDesc       *pIFDesc;       /* start of interface descrptor  */
    struct _USBEPDesc       *pEPDesc;       /* start of end point descrptors */
    struct _StringDesc      *pStringDesc;   /* start of string descriptors   */
    struct _HIDDesc         *pHIDDesc;      /* start HID descpt if HID device*/
    struct _HubDesc         *pHubDesc;      /* start HUB descriptor if HUB   */

    /* Index Structure for Super Speed Device descriptors                    */
    struct _USBBOSDesc          *pBOSDesc;       /* Super Speed BOS Desc.    */
    struct _USB20ExtDevCapDesc  *p20ExtDevCapDesc; /*USB 2.0 Ext DevCap Desc.*/
    struct _USBSSDevCapDesc     *pSSDevCapDesc; /* Super Speed DevCap Desc.  */
    struct _USBContIDDevCapDesc *pContIDDevCapDesc; /*Cont. ID DevCap Desc.  */
    struct _USBIFAssocDesc      *pIFAssocDesc; /* Interface Assoc. Desc.     */
    struct _USBSSEPCompDesc     *pEPCompDesc;  /* End Point Companion Desc.   */
    struct _SSHubDesc           *pSSHubDesc;  /* SS HUB Descriptor If SS HUB */
} DESCIDX, *PDESCIDX;                    

#ifdef __64BIT_KERNEL
typedef struct _DESCIDX_32 {           
    __ptr32  pDesc;
    __ptr32  pDevDesc;
    __ptr32  pConfigDesc;
    __ptr32  pIFDesc;
    __ptr32  pEPDesc;
    __ptr32  pStringDesc;
    __ptr32  pHIDDesc;
    __ptr32  pHubDesc;

    __ptr32  pBOSDesc;          /* Super Speed BOS Desc.       */
    __ptr32  p20ExtDevCapDesc;  /* USB 2.0 Ext DevCap Desc.    */
    __ptr32  pSSDevCapDesc;     /* Super Speed DevCap Desc.    */
    __ptr32  pContIDDevCapDesc; /* Cont. ID DevCap Desc.       */
    __ptr32  pIFAssocDesc;      /* Interface Assoc. Desc.      */
    __ptr32  pEPCompDesc;        /* End Point Companion Desc.   */
    __ptr32  pSSHubDesc;        /* SS HUB Descriptor If SS HUB */
} DESCIDX_32, *PDESCIDX_32;                    
#endif

/* formated string descriptor                                                */
typedef struct _StringDesc {           
  uint8_t    blength;                 /* length of descriptor                */
  uint8_t    bDescriptorType;         /* descriptor type (0x03)              */
  uint8_t    bindex;                  /* string index                        */
  uint8_t    bdesc[1];                /* NULL terminated ASCII string        */
} StringDesc, *PStringDesc;                    

/*
 * pipe policy
 */
typedef struct _PIPEPOLICY {
  int        maxNumIRP;               /* max number of outstanding IRP's     */
  int        maxPayloadSize;          /* maximum payload size in bytes       */
  int        serviceRate;             /* required service interval (ms)      */
} PIPEPOLICY, *PPIPEPOLICY;
/*
    serviceRate is not really used in usbd or hcds. It is
    maintained for compatability.  The actual service interval is
    taken from the bInterval value of the endpoint descriptor.
*/

/*
 * pipe status  
 */
typedef struct _PIPESTATUS {
  USBstatus  hostStatus;              /* host status of pipe                 */
  USBstatus  numIRPs;                 /* number of outstanding IRP's         */
} PIPESTATUS, *PPIPESTATUS; 

/*
 * I/O request packet
 */
typedef struct _IRP {
  struct  _IRP  *pNext;               /* pointer to next IRP                 */
  USBhandle      hPipe;               /* pipe handle                         */
  caddr_t        pBuffer;             /* virtual address of buffer           */
  void           *hmem;               /* bus map handle or xmem struct ptr   */
                                      /* call back notification              */
  void         (*IOCompleteCallBack)(USBhandle, struct _IRP *);
  void          *clientPriv;          /* pointer to client defined data      */
  int            transSize;           /* length of transaction (bytes)       */
  struct {                            /* flags:                              */
    unsigned       shortOK:1;         /*  short transfer from device ok      */
    unsigned       busMapped:1;       /*  buffer already bus mapped          */
  }              flags;
  volatile USBstatus status;          /* completion status                   */
/* ---------------- difference between versions 1 and 2 -------------------- */
  volatile USBstatus xstatus;         /* extended completion status          */
  uint16_t       frame;               /* requested frame number (isochronous)*/
} IRP, *PIRP;

/*
 * USB Device Driver Interface (USBDI) vectors
 * 
 * note: do not use directly, use macros below
 */
typedef struct _USBDI {
  USBstatus   (*closeDevice)(USBhandle);
  USBstatus   (*resetDevice)(USBhandle);
  USBstatus   (*pipeConnect)(USBhandle, uint, PPIPEPOLICY, USBhandle *);
  USBstatus   (*pipeDisconnect)(USBhandle, USBhandle);
  USBstatus   (*pipeIO)(USBhandle, PIRP);
  USBstatus   (*pipeIOWait)(USBhandle, PIRP, int);
  USBstatus   (*pipeStatus)(USBhandle, USBhandle, PPIPESTATUS);
  USBstatus   (*pipeAbort)(USBhandle, PIRP);
  USBstatus   (*pipeClear)(USBhandle, USBhandle);
  USBstatus   (*mapMemory)(USBhandle, caddr_t, int, uint, USBhandle *);
  USBstatus   (*unmapMemory)(USBhandle, USBhandle);
  USBstatus   (*getDescriptors)(USBhandle, PDESCIDX *);
  USBstatus   (*getDevselector)(USBhandle, PDEVSELECTOR);
/* ---------------- difference between versions 1 and 2 -------------------- */
  uint32_t    structure_size;
  uint16_t    structure_version;
  USBstatus   (*getFrame)(USBhandle h, uint16_t *pFrame, uint8_t *pSpeed);
  USBstatus   (*setInterface)(USBhandle h, uint8_t alternate);
} USBDI, *PUSBDI;

#define USBDI_structure_version  2

/*
 * highest interrupt priority caller may have when calling USBD
 * from interrupt environment 
 */
#define USBDINTRLEVEL INTOFFL3

/*
 * USB Device Driver Interface (USBDI) macros
 */

/* close USB logical device (interface)                                      */
/*   call: device handle                                                     */
/*   return: status                                                          */
#define usbdCloseDevice(_a) \
            ((PUSBDI)(_a))->closeDevice(_a)

/* reset device                                                              */
/*   call: device handle                                                     */
/*   return: status                                                          */
#define usbdResetDevice(_a) \
            ((PUSBDI)(_a))->resetDevice(_a)

/* connect to pipe (endpoint)                                                */
/*   call: device handle, endpoint addr, pointer to PIPEPOLICY struct,       */
/*         location to return pipe handle                                    */
/*   return: status                                                          */
#define usbdPipeConnect(_a,_b,_c,_d) \
            ((PUSBDI)(_a))->pipeConnect(_a,_b,_c,_d)

/* disconnect from pipe (endpoint)                                           */
/*   call: device handle, pipe handle                                        */
/*   return: status                                                          */
#define usbdPipeDisconnect(_a,_b) \
            ((PUSBDI)(_a))->pipeDisconnect(_a,_b)

/* start I/O on pipe                                                         */
/*   call: device handle, pointer to IRP structure                           */
/*   return: status                                                          */
#define usbdPipeIO(_a,_b) \
            ((PUSBDI)(_a))->pipeIO(_a,_b)

/* wait for I/O on pipe to complete                                          */ 
/*   call: device handle, pointer to IRP structure, time out in ms           */
/*   return: status                                                          */
#define usbdPipeIOWait(_a,_b,_c) \
            ((PUSBDI)(_a))->pipeIOWait(_a,_b,_c)

/* get pipe status                                                           */
/*   call: device handle, pipe handle, addr of status structure              */
/*   return: status                                                          */
#define usbdPipeStatus(_a,_b,_c) \
            ((PUSBDI)(_a))->pipeStatus(_a,_b,_c)

/* cancel previously started I/O                                             */
/*   call: device handle, pointer to IRP struct                              */
/*   return: status                                                          */
#define usbdPipeAbort(_a,_b) \
            ((PUSBDI)(_a))->pipeAbort(_a,_b)

/* resume a halted pipe                                                      */
/*   call: device handle, pipe handle                                        */
/*   return: status                                                          */
#define usbdPipeClear(_a,_b) \
            ((PUSBDI)(_a))->pipeClear(_a,_b)

/* condition main memory for bus mastering (map)                             */
/*   call: device handle, virtual address, length in bytes,                  */
/*         flags, location to return map handle                              */
/*   return: status                                                          */
#define usbdMapMemory(_a,_b,_c,_d,_e) \
            ((PUSBDI)(_a))->mapMemory(_a,_b,_c,_d,_e)

                                      /* flags:                              */
#define USBDMAP_USER      1           /*   memory is in user space           */
#define USBDMAP_READ      2           /*   data xfer'ed from device to memory*/
#define USBDMAP_PIN       4           /*   pin memory before mapping         */

/* free up resources used to condition memory for bus mastered I/O (unmap)   */
/*   call: device handle, map handle                                         */
/*   return: status                                                          */
#define usbdUnmapMemory(_a,_b) \
            ((PUSBDI)(_a))->unmapMemory(_a,_b)

/* get device descriptors                                                    */
/*   call: device handle, location to return pointer to descriptors          */
/*   return: status                                                          */
#define usbdGetDescriptors(_a,_b) \
            ((PUSBDI)(_a))->getDescriptors(_a,_b)

/* get new devselctor after a reconnect                                      */
/*   call: device handle, location to return pointer to devselector          */
/*   return: status                                                          */
#define usbdGetDevselector(_a,_b) \
            ((PUSBDI)(_a))->getDevselector(_a,_b)

/* get USBDI structure size                                                  */
/*   call: device handle                                                     */
/*   return: structure size                                                  */
#define usbdGetSize(_a) \
            (((PUSBDI)(_a))->structure_size)

/* get USBDI structure version                                               */
/*   call: device handle                                                     */
/*   return: structure version                                               */
#define usbdGetVersion(_a) \
            (((PUSBDI)(_a))->structure_version)

/* compare USBDI structure size and version                                  */
/*   call: device handle                                                     */
/*   return: true if the USBDI structure can be used, false otherwise        */
#define usbdCompareSizeAndVersion(_a) \
            ((usbdGetSize(_a)>=sizeof(USBDI)) \
                && (usbdGetVersion(_a)>=USBDI_structure_version))

/* get the current frame number                                              */
/*   call: device handle, pointer to frame, pointer to speed                 */
/*   return: status                                                          */
#define usbdGetFrame(_a,_b,_c) \
            ((PUSBDI)(_a))->getFrame(_a,_b,_c)

   /* value returned as speed. These must match fullSpeed and highSpeed. */
#define USBD_FULL_SPEED      2  /* 1.000 millisecond frame (OHCI controller) */
#define USBD_HIGH_SPEED      4  /* 0.125 millisecond frame (EHCI controller) */

/* request an interface alternate setting                                    */
/*   call: device handle, requested interface alternate setting              */
/*   return: status                                                          */
#define usbdSetInterface(_a,_b) \
            ((PUSBDI)(_a))->setInterface(_a,_b)


/*
   Structures used by USBD_INFO_REQUEST a request for device information.
   All unused fields should be set to zero.
*/

/* These defines specify the type of request. They go in request_id. */
#define USBD_IR_NOOP                         (0)
#define USBD_IR_DEVICE_COUNT                 (1)
#define USBD_IR_DEVICE_LIST                  (2)
#define USBD_IR_DEVICE_ATTRIBUTES            (3)

/* See if this ioctl() is supprted by the driver. */
typedef struct
{
    uint32_t request_id;
    uint32_t size;
}
usbd_ir_noop_t;

/* Request the number of devices managed by the USB system driver. */
typedef struct
{
    uint32_t request_id;
    uint32_t size;
    uint64_t count;
}
usbd_ir_device_count_t;

/* Request the list of devices managed by the USB system driver. */
typedef struct
{
    uint32_t request_id;
    uint32_t size; /* size of this structure only. */
    uint64_t count; /* returned as the number of devices listed */
    uint64_t size2; /* Size of this structure + buffer in bytes. */

    /* Buffer is returned as list of {hcdevno, addr, cfg, intfc}. */
}
usbd_ir_device_list_t;

/* This is for requesting the attributes of a specific device. */
typedef struct
{
    uint32_t request_id;
    uint32_t size;

    dev64_t hcdevno; /* The 64 bit devno of the host controller */
                     /* handling communication for the device. */
    uint8_t addr; /* The bus address of the device. */
    uint8_t cfg; /* The configuration number of the device. */
    uint8_t intfc; /* The interface number of the device. */

#define USBD_IR_DA_STATUS_OK            (0)
#define USBD_IR_DA_STATUS_NOT_PRESENT   (1)  /* Device is no longer */
                                       /* present or never existed. */
    uint8_t status;

    uint8_t intfc_alt;
    uint8_t usb_class;
    uint8_t usb_subclass;
    uint8_t usb_protocol;
    uint8_t device_type;
#define USBD_IR_F_lowSpeed                  0x0000000000000001
#define USBD_IR_F_fullSpeed                 0x0000000000000002
#define USBD_IR_F_highSpeed                 0x0000000000000004
#define USBD_IR_F_OPEN                      0x0000000000000008
#define USBD_IR_F_BUS_POWERED               0x0000000000000010
#define USBD_IR_F_SELF_POWERED              0x0000000000000020
#define USBD_IR_F_LOW_POWER                 0x0000000000000040
#define USBD_IR_F_HIGH_POWER                0x0000000000000080
#define USBD_IR_F_HUB                       0x0000000000000100
#define USBD_IR_F_superSpeed                0x0000000000000200
    uint64_t flags;

    uint16_t current_ma;  /* current draw in milliampers */

    uint8_t parent_addr;  /* zero for root hub */
    uint8_t parent_cfg;
    uint8_t parent_intfc;
    uint8_t parent_port;

    uint8_t split_addr;  /* zero for no split hub */
    uint8_t split_cfg;
    uint8_t split_intfc;
    uint8_t split_port;

    uint8_t ports; /* if hub */
}
usbd_ir_device_attributes_t;

/* This is a general purpose data transfer structure. */
typedef struct
{
    uint32_t request_id;
    uint32_t size;

    uint8_t gpa; /* general purpose register a */
    uint16_t length; /* amount of data in data_block[] */
    uint32_t gpb; /* general purpose register b */
    uint64_t offset; /* the starting byte offset of the first byte */
                     /* of data_block[] */
    uint8_t data_block[1024];
}
usbd_ir_data_t;


/*
   Structures used by USBD_STATUS_FEED a request for status change info.
   All unused fields should be set to zero.
*/
typedef struct
{
#define USBD_SF_NOOP                           (0)
#define USBD_SF_START_FEED                     (1)
#define USBD_SF_STOP_FEED                      (2)
#define USBD_SF_REQUEST_NO_WAIT                (3)
#define USBD_SF_REQUEST_WAIT                   (4)
#define USBD_SF_REQUEST_WITH_TIMEOUT           (5)
    uint32_t request_id;
    uint32_t size;
}
usbd_sf_noop_t;

typedef struct
{
    uint32_t request_id;
    uint32_t size;
    uint32_t seconds; /* seconds to wait before timing out */
    uint16_t feed_id;

#define USBD_SF_ST_NOOP                           (0)
#define USBD_SF_ST_LOST                           (1)
#define USBD_SF_ST_TIMEOUT                        (2)
#define USBD_SF_ST_USBD_EXITING                   (3)
#define USBD_SF_ST_DEVICE_ATTACH                  (4)
#define USBD_SF_ST_DEVICE_DETACH                  (5)
#define USBD_SF_ST_CLIENT_CONNECT_TO_USBD         (6)
#define USBD_SF_ST_CLIENT_DISCONNECT_FROM_USBD    (7)
#define USBD_SF_ST_CLIENT_LINK_TO_DEV             (8)
#define USBD_SF_ST_CLIENT_UNLINK_FROM_DEV         (9)
#define USBD_SF_ST_DEVICE_ALT_SETTING_CHANGE      (10)
#define USBD_SF_ST_DEVICE_NOT_LINKED              (11)
    uint16_t status_id;

    dev64_t hcdevno; /* The 64 bit devno of the host controller */
                     /* handling communication for the device. */
    uint8_t addr; /* The bus address of the device. */
    uint8_t cfg; /* The configuration number of the device. */
    uint8_t intfc; /* The interface number of the device. */

    uint8_t intfc_alt;
    uint8_t usb_class;
    uint8_t usb_subclass;
    uint8_t usb_protocol;
    uint8_t device_type;

    uint64_t client_id;

    uint64_t flags;

    uint64_t t_seconds;
    uint32_t t_nanoseconds;
}
usbd_sf_status_t;

typedef struct usbhc_cudv_info
{
        char    name[16];  /*name of controller          */
        dev32_t devno;
        int     errno;    /* error upon registration     */
                          /* or power up of a controller */ 
}usbhc_cudv_info_t;

/*
Structure is used for Registration or powerup of hub ports
of a controllers at a time.
*/

typedef struct usb_adapterhc_info
{
        usbhc_cudv_info_t hc_info[MAX_USB_HC];
        int               hc_count;
}usb_adapterhc_info_t;

extern struct usb_adapterhc_info;

/*
 * The following structures are used only by
 * libusb client driver
 */  

typedef struct aix_pipe {
       DEVSELECTOR devsel;
       int endpoint;
       PIPEPOLICY policy;
}AIXPIPE;

/*
 * This structure is used by libusb client
 * to pass/get data through various ioctls.
 * Some fields may be NULL depending on ioctl
 */


typedef struct aix_pipeio {
       DEVSELECTOR devsel;
       int endpoint;
       int transSize;
       int status;
       char *pBuffer;
       char *clientPriv;
}AIXPIPEIO;

#ifdef _KERNEL

/*
 * This structure is used for the libusb driver
 * to copyin/copyout data of 32-bit libusb
 * applications
 */

typedef struct aix_pipeio32 {
       DEVSELECTOR devsel;
       int endpoint;
       int transSize;
       int status;
       __ptr32 pBuffer;
       __ptr32 clientPriv;
}AIXPIPEIO32;

/*
 * This structure is used for the libusb driver
 * to copyin/copyout data of 64-bit libusb
 * applications
 */

typedef struct aix_pipeio64{
       DEVSELECTOR devsel;
       int endpoint;
       int transSize;
       int status;
       __ptr64  pBuffer;
       __ptr64  clientPriv;
}AIXPIPEIO64;

typedef struct confdesc64 {
        int len;
        int numconfig;
        __ptr64 buf;
}confdesc64;

#endif /*_KERNEL */ 

typedef struct confdesc {
        int len;
        int numconfig;
        char * buf;
}confdesc;

struct aix_interface_alt {
        int interface;
        int alt_setting;
}AIXINTALT;

#endif /* _H_USBDI */