1 typedef struct Hub Hub; 2 typedef struct Port Port; 3 typedef struct DHub DHub; 4 typedef struct DSSHub DSSHub; 5 typedef struct Devtab Devtab; 6 typedef struct Usbfs Usbfs; 7 8 enum 9 { 10 Stack = 32*1024, 11 12 Dhub = 0x29, /* hub descriptor type */ 13 Dhublen = 9, /* hub descriptor length */ 14 Dsshub = 0x2A, /* superspeed hub descriptor type */ 15 Dsshublen = 12, /* superspeed hub descriptor length */ 16 17 /* hub class feature selectors */ 18 Fhublocalpower = 0, 19 Fhubovercurrent = 1, 20 21 Fportconnection = 0, 22 Fportenable = 1, 23 Fportsuspend = 2, 24 Fportovercurrent = 3, 25 Fportreset = 4, 26 Fportpower = 8, 27 Fportlowspeed = 9, 28 Fcportconnection = 16, 29 Fcportenable = 17, 30 Fcportsuspend = 18, 31 Fcportovercurrent= 19, 32 Fcportreset = 20, 33 Fportindicator = 22, 34 35 /* Port status and status change bits 36 * Constants at /sys/src/9/pc/usb.h starting with HP- 37 * must have the same values or root hubs won't work. 38 */ 39 PSpresent = 0x0001, 40 PSenable = 0x0002, 41 PSsuspend = 0x0004, 42 PSovercurrent = 0x0008, 43 PSreset = 0x0010, 44 PSpower = 0x0100, 45 PSslow = 0x0200, 46 PShigh = 0x0400, 47 48 PSstatuschg = 0x10000, /* PSpresent changed */ 49 PSchange = 0x20000, /* PSenable changed */ 50 51 52 /* port/device state */ 53 Pdisabled = 0, /* must be 0 */ 54 Pattached, 55 Pconfiged, 56 57 /* Delays, timeouts (ms) */ 58 Spawndelay = 100, /* how often may we re-spawn a driver */ 59 Connectdelay = 500, /* how much to wait after a connect */ 60 Resetdelay = 20, /* how much to wait after a reset */ 61 Enabledelay = 20, /* how much to wait after an enable */ 62 Powerdelay = 100, /* after powering up ports */ 63 Pollms = 250, /* port poll interval */ 64 Chgdelay = 100, /* waiting for port become stable */ 65 Chgtmout = 1000, /* ...but at most this much */ 66 67 /* 68 * device tab for embedded usb drivers. 69 */ 70 DCL = 0x01000000, /* csp identifies just class */ 71 DSC = 0x02000000, /* csp identifies just subclass */ 72 DPT = 0x04000000, /* csp identifies just proto */ 73 74 }; 75 76 struct Hub 77 { 78 uchar pwrmode; 79 uchar compound; 80 uchar pwrms; /* time to wait in ms */ 81 uchar maxcurrent; /* after powering port*/ 82 int leds; /* has port indicators? */ 83 int maxpkt; 84 uchar nport; 85 Port *port; 86 int failed; /* I/O error while enumerating */ 87 int isroot; /* set if root hub */ 88 Dev *dev; /* for this hub */ 89 Hub *next; /* in list of hubs */ 90 }; 91 92 struct Port 93 { 94 int state; /* state of the device */ 95 int sts; /* old port status */ 96 uchar removable; 97 uchar pwrctl; 98 Dev *dev; /* attached device (if non-nil) */ 99 Hub *hub; /* non-nil if hub attached */ 100 int devnb; /* device number */ 101 uvlong *devmaskp; /* ptr to dev mask */ 102 }; 103 104 105 /* USB HUB descriptor */ 106 struct DHub 107 { 108 uchar bLength; 109 uchar bDescriptorType; 110 uchar bNbrPorts; 111 uchar wHubCharacteristics[2]; 112 uchar bPwrOn2PwrGood; 113 uchar bHubContrCurrent; 114 uchar DeviceRemovable[1]; /* variable length */ 115 }; 116 117 /* Superspeed HUB descriptor */ 118 struct DSSHub 119 { 120 uchar bLength; 121 uchar bDescriptorType; 122 uchar bNbrPorts; 123 uchar wHubCharacteristics[2]; 124 uchar bPwrOn2PwrGood; 125 uchar bHubContrCurrent; 126 uchar bHubHdrDecLat; 127 uchar wHubDelay[2]; 128 uchar DeviceRemovable[1]; /* variable length */ 129 }; 130 131 struct Devtab 132 { 133 char *name; 134 int (*init)(Dev*, int, char**); /* nil if external */ 135 int csps[4]; 136 int vid; 137 int did; 138 char *args; 139 uvlong devmask; 140 int noauto; 141 }; 142 143 144 Hub* newhub(char *fn, Dev *d); 145 int startdev(Port *pp); 146 int getdevnb(uvlong *maskp); 147 void putdevnb(uvlong *maskp, int nb); 148 void threadmain(int argc, char **argv); 149 150 extern Usbfs usbdfsops; 151