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