2 * USB device driver framework.
4 * This is in charge of providing access to actual HCIs
5 * and providing I/O to the various endpoints of devices.
6 * A separate user program (usbd) is in charge of
7 * enumerating the bus, setting up endpoints and
8 * starting devices (also user programs).
10 * The interface provided is a violation of the standard:
13 * The interface consists of a root directory with several files
14 * plus a directory (epN.M) with two files per endpoint.
15 * A device is represented by its first endpoint, which
16 * is a control endpoint automatically allocated for each device.
17 * Device control endpoints may be used to create new endpoints.
18 * Devices corresponding to hubs may also allocate new devices,
19 * perhaps also hubs. Initially, a hub device is allocated for
20 * each controller present, to represent its root hub. Those can
23 * All endpoints refer to the first endpoint (epN.0) of the device,
24 * which keeps per-device information, and also to the HCI used
25 * to reach them. Although all endpoints cache that information.
27 * epN.M/data files permit I/O and are considered DMEXCL.
28 * epN.M/ctl files provide status info and accept control requests.
30 * Endpoints may be given file names to be listed also at #u,
31 * for those drivers that have nothing to do after configuring the
32 * device and its endpoints.
34 * Drivers for different controllers are kept at usb[oue]hci.c
35 * It's likely we could factor out much from controllers into
36 * a generic controller driver, the problem is that details
37 * regarding how to handle toggles, tokens, Tds, etc. will
38 * get in the way. Thus, code is probably easier the way it is.
42 #include "../port/lib.h"
47 #include "../port/error.h"
48 #include "../port/usb.h"
50 typedef struct Hcitype Hcitype;
57 Qctl, /* #u/usb/ctl - control requests */
59 Qep0dir, /* #u/usb/ep0.0 - endpoint 0 dir */
60 Qep0io, /* #u/usb/ep0.0/data - endpoint 0 I/O */
61 Qep0ctl, /* #u/usb/ep0.0/ctl - endpoint 0 ctl. */
62 Qep0dummy, /* give 4 qids to each endpoint */
64 Qepdir = 0, /* (qid-qep0dir)&3 is one of these */
65 Qepio, /* to identify which file for the endpoint */
71 CMdebug = 0, /* debug on|off */
72 CMdump, /* dump (data structures for debug) */
75 CMnew = 0, /* new nb ctl|bulk|intr|iso r|w|rw (endpoint) */
76 CMnewdev, /* newdev full|low|high portnb (allocate new devices) */
77 CMhub, /* hub (set the device as a hub) */
78 CMspeed, /* speed full|low|high|no */
79 CMmaxpkt, /* maxpkt size */
80 CMntds, /* ntds nb (max nb. of tds per µframe) */
81 CMclrhalt, /* clrhalt (halt was cleared on endpoint) */
82 CMpollival, /* pollival interval (interrupt/iso) */
83 CMhz, /* hz n (samples/sec; iso) */
84 CMsamplesz, /* samplesz n (sample size; iso) */
85 CMinfo, /* info infostr (ke.ep info for humans) */
86 CMdetach, /* detach (abort I/O forever on this ep). */
87 CMaddress, /* address (address is assigned) */
88 CMdebugep, /* debug n (set/clear debug for this ep) */
89 CMname, /* name str (show up as #u/name as well) */
90 CMtmout, /* timeout n (activate timeouts for ep) */
91 CMsampledelay, /* maximum delay introduced by buffering (iso) */
92 CMpreset, /* reset the port */
94 /* Hub feature selectors */
106 #define QID(q) ((int)(q).path)
108 static char Edetach[] = "device is detached";
109 static char Enotconf[] = "endpoint not configured";
110 char Estalled[] = "endpoint stalled";
112 static Cmdtab usbctls[] =
114 {CMdebug, "debug", 2},
118 static Cmdtab epctls[] =
121 {CMnewdev, "newdev", 3},
123 {CMspeed, "speed", 2},
124 {CMmaxpkt, "maxpkt", 2},
126 {CMpollival, "pollival", 2},
127 {CMsamplesz, "samplesz", 2},
130 {CMdetach, "detach", 1},
131 {CMaddress, "address", 1},
132 {CMdebugep, "debug", 2},
133 {CMclrhalt, "clrhalt", 1},
135 {CMtmout, "timeout", 2},
136 {CMsampledelay, "sampledelay", 2},
137 {CMpreset, "reset", 1},
140 static Dirtab usbdir[] =
142 "ctl", {Qctl}, 0, 0666,
145 char *usbmodename[] =
152 static char *ttname[] =
161 static char *spname[] =
170 static Hcitype hcitypes[Nhcis];
171 static Hci* hcis[Nhcis];
172 static QLock epslck; /* add, del, lookup endpoints */
173 static Ep* eps[Neps]; /* all endpoints known */
174 static int epmax; /* 1 + last endpoint index used */
175 static int usbidgen; /* device address generator */
178 * Is there something like this in a library? should it be?
181 seprintdata(char *s, char *se, uchar *d, int n)
185 s = seprint(s, se, " %#p[%d]: ", d, n);
190 s = seprint(s, se, " %2.2ux", d[i]);
192 s = seprint(s, se, "...");
197 name2speed(char *name)
201 for(i = 0; i < nelem(spname); i++)
202 if(strcmp(name, spname[i]) == 0)
208 name2ttype(char *name)
212 for(i = 0; i < nelem(ttname); i++)
213 if(strcmp(name, ttname[i]) == 0)
215 /* may be a std. USB ep. type */
216 i = strtol(name, nil, 0);
229 name2mode(char *mode)
233 for(i = 0; i < nelem(usbmodename); i++)
234 if(strcmp(mode, usbmodename[i]) == 0)
243 if(q < 0 || q >= epmax || eps[q] == nil)
249 isqtype(int q, int type)
254 return (q & 3) == type;
258 addhcitype(char* t, int (*r)(Hci*))
263 panic("too many USB host interface types");
264 hcitypes[ntype].type = t;
265 hcitypes[ntype].reset = r;
270 seprintep(char *s, char *se, Ep *ep, int all)
272 static char* dsnames[] = { "config", "enabled", "detached", "reset" };
286 s = seprint(s, se, "dev %d ep %d ", di, ep->nb);
287 s = seprint(s, se, "%s", dsnames[ep->dev->state]);
288 s = seprint(s, se, " %s", ttname[ep->ttype]);
289 assert(ep->mode == OREAD || ep->mode == OWRITE || ep->mode == ORDWR);
290 s = seprint(s, se, " %s", usbmodename[ep->mode]);
291 s = seprint(s, se, " speed %s", spname[d->speed]);
292 s = seprint(s, se, " maxpkt %ld", ep->maxpkt);
293 s = seprint(s, se, " pollival %ld", ep->pollival);
294 s = seprint(s, se, " samplesz %ld", ep->samplesz);
295 s = seprint(s, se, " hz %ld", ep->hz);
296 s = seprint(s, se, " hub %d", ep->dev->hub);
297 s = seprint(s, se, " port %d", ep->dev->port);
299 s = seprint(s, se, " busy");
301 s = seprint(s, se, " idle");
303 s = seprint(s, se, " load %uld", ep->load);
304 s = seprint(s, se, " ref %ld addr %#p", ep->ref, ep);
305 s = seprint(s, se, " idx %d", ep->idx);
307 s = seprint(s, se, " name '%s'", ep->name);
309 s = seprint(s, se, " tmout");
311 s = seprint(s, se, " ctlrno %#x", ep->hp->ctlrno);
312 s = seprint(s, se, " eps:");
313 for(i = 0; i < nelem(d->eps); i++)
315 s = seprint(s, se, " ep%d.%d", di, i);
319 s = seprint(s, se, "\n%s %s\n", ep->info, ep->hp->type);
321 s = seprint(s, se, "\n");
333 ep = smalloc(sizeof(Ep));
336 for(i = 0; i < Neps; i++)
342 print("usb: bug: too few endpoints.\n");
352 ep->samplesz = ep->pollival = ep->hz = 0; /* make them void */
362 if(i < 0 || i >= epmax || eps[i] == nil)
377 if(ep != nil && decref(ep) == 0){
379 deprint("usb: ep%d.%d %#p released\n", d->nb, ep->nb, ep);
382 if(ep->idx == epmax-1)
384 if(ep == ep->ep0 && ep->dev != nil && ep->dev->nb == usbidgen)
389 d->eps[ep->nb] = nil;
406 static char buf[512];
411 print("usb dump eps: epmax %d Neps %d (ref=1+ for dump):\n", epmax, Neps);
412 for(i = 0; i < epmax; i++){
421 s = seprint(s, e, "ep%d.%d ", ep->dev->nb, ep->nb);
422 seprintep(s, e, ep, 1);
424 ep->hp->seprintep(buf, e, ep);
430 print("usb dump hcis:\n");
431 for(i = 0; i < Nhcis; i++)
433 hcis[i]->dump(hcis[i]);
444 print("#u: too many device addresses; reuse them more\n");
450 * Create endpoint 0 for a new device
453 newdev(Hci *hp, int ishub, int isroot)
459 d = ep->dev = smalloc(sizeof(Udev));
460 d->nb = newusbid(hp);
463 ep->toggle[0] = ep->toggle[1] = 0;
466 if(hp->highspeed != 0)
467 d->speed = Highspeed;
469 d->speed = Fullspeed;
470 d->state = Dconfig; /* address not yet set */
472 ep->ep0 = ep; /* no ref counted here */
474 ep->tmout = Xfertmout;
476 dprint("newdev %#p ep%d.%d %#p\n", d, d->nb, ep->nb, ep);
481 * Create a new endpoint for the device
482 * accessed via the given endpoint 0.
485 newdevep(Ep *ep, int i, int tt, int mode)
492 error("endpoint already in use");
493 nep = epalloc(ep->hp);
497 nep->toggle[0] = nep->toggle[1] = 0;
502 nep->debug = ep->debug;
506 nep->tmout = Xfertmout;
512 nep->tmout = Xfertmout;
518 deprint("newdevep ep%d.%d %#p\n", d->nb, nep->nb, nep);
539 usbgen(Chan *c, char *, Dirtab*, int, int s, Dir *dp)
549 if(0)ddprint("usbgen q %#x s %d...", QID(c->qid), s);
551 if(QID(c->qid) <= Qusbdir){
552 mkqid(&q, Qdir, 0, QTDIR);
553 devdir(c, q, "#u", 0, eve, 0555, dp);
555 mkqid(&q, Qusbdir, 0, QTDIR);
556 devdir(c, q, "usb", 0, eve, 0555, dp);
558 if(0)ddprint("ok\n");
563 case Qdir: /* list #u */
565 mkqid(&q, Qusbdir, 0, QTDIR);
566 devdir(c, q, "usb", 0, eve, 0555, dp);
567 if(0)ddprint("ok\n");
571 if(s < 0 || s >= epmax)
574 if(ep == nil || ep->name == nil){
577 if(0)ddprint("skip\n");
584 mkqid(&q, Qep0io+s*4, 0, QTFILE);
585 devdir(c, q, ep->name, 0, eve, epdataperm(ep->mode), dp);
588 if(0)ddprint("ok\n");
591 case Qusbdir: /* list #u/usb */
593 if(s < nelem(usbdir)){
595 mkqid(&q, dir->qid.path, 0, QTFILE);
596 devdir(c, q, dir->name, dir->length, eve, dir->perm, dp);
597 if(0)ddprint("ok\n");
601 if(s < 0 || s >= epmax)
605 if(0)ddprint("skip\n");
612 se = up->genbuf+sizeof(up->genbuf);
613 seprint(up->genbuf, se, "ep%d.%d", ep->dev->nb, ep->nb);
614 mkqid(&q, Qep0dir+4*s, 0, QTDIR);
617 devdir(c, q, up->genbuf, 0, eve, 0755, dp);
618 if(0)ddprint("ok\n");
625 default: /* list #u/usb/epN.M */
626 nb = qid2epidx(QID(c->qid));
632 if(isqtype(QID(c->qid), Qepdir)){
636 mkqid(&q, Qep0io+nb*4, 0, QTFILE);
637 perm = epdataperm(mode);
638 devdir(c, q, "data", 0, eve, perm, dp);
641 mkqid(&q, Qep0ctl+nb*4, 0, QTFILE);
642 devdir(c, q, "ctl", 0, eve, 0664, dp);
647 }else if(isqtype(QID(c->qid), Qepctl)){
654 if(0)ddprint("ok\n");
658 if(0)ddprint("fail\n");
663 hciprobe(int cardno, int ctlrno)
667 static int epnb = 1; /* guess the endpoint nb. for the controller */
669 ddprint("hciprobe %d %d\n", cardno, ctlrno);
670 hp = smalloc(sizeof(Hci));
672 hp->tbdf = BUSUNKNOWN;
675 if(isaconfig("usb", ctlrno, hp) == 0){
679 for(cardno = 0; cardno < Nhcis; cardno++){
680 if(hcitypes[cardno].type == nil)
683 if(type==nil || *type==0)
685 if(cistrcmp(hcitypes[cardno].type, type) == 0)
690 if(cardno >= Nhcis || hcitypes[cardno].type == nil){
694 dprint("%s...", hcitypes[cardno].type);
695 if(hcitypes[cardno].reset(hp) < 0){
701 * modern machines have too many usb controllers to list on
704 dprint("#u/usb/ep%d.0: %s: port 0x%luX irq %d\n",
705 epnb, hcitypes[cardno].type, hp->port, hp->irq);
716 if(getconf("*nousbprobe"))
718 dprint("usbreset\n");
720 for(ctlrno = 0; ctlrno < Nhcis; ctlrno++)
721 if((hp = hciprobe(-1, ctlrno)) != nil)
724 while(cardno < Nhcis && ctlrno < Nhcis && hcitypes[cardno].type != nil)
725 if(hcis[ctlrno] != nil)
728 hp = hciprobe(cardno, ctlrno);
733 if(hcis[Nhcis-1] != nil)
734 print("usbreset: bug: Nhcis (%d) too small\n", Nhcis);
746 for(ctlrno = 0; ctlrno < Nhcis; ctlrno++){
751 d = newdev(hp, 1, 1); /* new root hub */
752 d->dev->state = Denabled; /* although addr == 0 */
754 snprint(info, sizeof(info), "ports %d", hp->nports);
755 kstrdup(&d->info, info);
761 usbattach(char *spec)
763 return devattach(L'u', spec);
767 usbwalk(Chan *c, Chan *nc, char **name, int nname)
769 return devwalk(c, nc, name, nname, nil, 0, usbgen);
773 usbstat(Chan *c, uchar *db, int n)
775 return devstat(c, db, n, nil, 0, usbgen);
779 * µs for the given transfer, for bandwidth allocation.
780 * This is a very rough worst case for what 5.11.3
781 * of the usb 2.0 spec says.
782 * Also, we are using maxpkt and not actual transfer sizes.
783 * Only when we are sure we
784 * are not exceeding b/w might we consider adjusting it.
787 usbload(int speed, int maxpkt)
789 enum{ Hostns = 1000, Hubns = 333 };
797 l = 55*8*2 + 2 * (3 + bs) + Hostns;
800 l = 9107 + 84 * (4 + bs) + Hostns;
803 l = 64107 + 2 * Hubns + 667 * (3 + bs) + Hostns;
806 print("usbload: bad speed %d\n", speed);
809 return l / 1000UL; /* in µs */
813 usbopen(Chan *c, int omode)
819 mode = openmode(omode);
822 if(q >= Qep0dir && qid2epidx(q) < 0)
824 if(q < Qep0dir || isqtype(q, Qepctl) || isqtype(q, Qepdir))
825 return devopen(c, omode, nil, 0, usbgen);
827 ep = getep(qid2epidx(q));
830 deprint("usbopen q %#x fid %d omode %d\n", q, c->fid, mode);
846 if(mode != OREAD && ep->mode == OREAD)
848 if(mode != OWRITE && ep->mode == OWRITE)
850 if(ep->ttype == Tnone)
855 ep->load = usbload(ep->dev->speed, ep->maxpkt);
858 poperror(); /* ep->inuse */
859 poperror(); /* don't putep(): ref kept for fid using the ep. */
864 c->aux = nil; /* paranoia */
891 if(q < Qep0dir || isqtype(q, Qepctl) || isqtype(q, Qepdir))
894 ep = getep(qid2epidx(q));
897 deprint("usbclose q %#x fid %d ref %ld\n", q, c->fid, ep->ref);
906 putep(ep); /* release ref kept since usbopen */
914 ctlread(Chan *c, void *a, long n, vlong offset)
924 us = s = smalloc(READSTR);
931 for(i = 0; i < epmax; i++){
938 s = seprint(s, se, "ep%d.%d ", ep->dev->nb, ep->nb);
939 s = seprintep(s, se, ep, 0);
945 ep = getep(qid2epidx(q));
953 /* After a new endpoint request we read
954 * the new endpoint name back.
956 strecpy(s, se, c->aux);
960 seprintep(s, se, ep, 0);
964 n = readstr(offset, a, n, us);
971 * Fake root hub emulation.
974 rhubread(Ep *ep, void *a, long n)
978 if(ep->dev->isroot == 0 || ep->nb != 0 || n < 2)
991 rhubwrite(Ep *ep, void *a, long n)
999 if(ep->dev == nil || ep->dev->isroot == 0 || ep->nb != 0)
1002 error("root hub is a toy hub");
1005 if(s[Rtype] != (Rh2d|Rclass|Rother) && s[Rtype] != (Rd2h|Rclass|Rother))
1006 error("root hub is a toy hub");
1009 feature = GET2(s+Rvalue);
1010 port = GET2(s+Rindex);
1011 if(port < 1 || port > hp->nports)
1012 error("bad hub port number");
1015 ep->rhrepl = hp->portenable(hp, port, cmd == Rsetfeature);
1018 ep->rhrepl = hp->portreset(hp, port, cmd == Rsetfeature);
1021 ep->rhrepl = hp->portstatus(hp, port);
1030 usbread(Chan *c, void *a, long n, vlong offset)
1038 if(c->qid.type == QTDIR)
1039 return devdirread(c, a, n, nil, 0, usbgen);
1041 if(q == Qctl || isqtype(q, Qepctl))
1042 return ctlread(c, a, n, offset);
1044 ep = getep(qid2epidx(q));
1051 if(ep->dev->state == Ddetach)
1053 if(ep->mode == OWRITE || ep->inuse == 0)
1057 error("endpoint not configured");
1059 nr = rhubread(ep, a, n);
1066 ddeprint("\nusbread q %#x fid %d cnt %ld off %lld\n",q,c->fid,n,offset);
1067 n = ep->hp->epread(ep, a, n);
1082 setmaxpkt(Ep *ep, char* s)
1084 long spp; /* samples per packet */
1086 if(ep->dev->speed == Highspeed)
1087 spp = (ep->hz * ep->pollival * ep->ntds + 7999) / 8000;
1089 spp = (ep->hz * ep->pollival + 999) / 1000;
1090 ep->maxpkt = spp * ep->samplesz;
1091 deprint("usb: %s: setmaxpkt: hz %ld poll %ld"
1092 " ntds %d %s speed -> spp %ld maxpkt %ld\n", s,
1093 ep->hz, ep->pollival, ep->ntds, spname[ep->dev->speed],
1095 if(ep->maxpkt > 1024){
1096 print("usb: %s: maxpkt %ld > 1024. truncating\n", s, ep->maxpkt);
1102 * Many endpoint ctls. simply update the portable representation
1103 * of the endpoint. The actual controller driver will look
1104 * at them to setup the endpoints as dictated.
1107 epctl(Ep *ep, Chan *c, void *a, long n)
1109 int i, l, mode, nb, tt;
1115 static char *Info = "info ";
1119 cb = parsecmd(a, n);
1124 ct = lookupcmd(cb, epctls, nelem(epctls));
1128 if(i == CMnew || i == CMspeed || i == CMhub || i == CMpreset)
1130 error("allowed only on a setup endpoint");
1131 if(i != CMclrhalt && i != CMdetach && i != CMdebugep && i != CMname)
1132 if(ep != ep->ep0 && ep->inuse != 0)
1133 error("must configure before using");
1136 deprint("usb epctl %s\n", cb->f[0]);
1137 nb = strtol(cb->f[1], nil, 0);
1138 if(nb < 0 || nb >= Ndeveps)
1139 error("bad endpoint number");
1140 tt = name2ttype(cb->f[2]);
1142 error("unknown endpoint type");
1143 mode = name2mode(cb->f[3]);
1145 error("unknown i/o mode");
1146 newdevep(ep, nb, tt, mode);
1149 deprint("usb epctl %s\n", cb->f[0]);
1150 if(ep != ep->ep0 || d->ishub == 0)
1151 error("not a hub setup endpoint");
1152 l = name2speed(cb->f[1]);
1154 error("speed must be full|low|high");
1155 nep = newdev(ep->hp, 0, 0);
1156 nep->dev->speed = l;
1157 if(nep->dev->speed != Lowspeed)
1158 nep->maxpkt = 64; /* assume full speed */
1159 nep->dev->hub = d->nb;
1160 nep->dev->port = atoi(cb->f[2]);
1161 /* next read request will read
1162 * the name for the new endpoint
1164 l = sizeof(up->genbuf);
1165 snprint(up->genbuf, l, "ep%d.%d", nep->dev->nb, nep->nb);
1166 kstrdup(&c->aux, up->genbuf);
1169 deprint("usb epctl %s\n", cb->f[0]);
1173 l = name2speed(cb->f[1]);
1174 deprint("usb epctl %s %d\n", cb->f[0], l);
1176 error("speed must be full|low|high");
1182 l = strtoul(cb->f[1], nil, 0);
1183 deprint("usb epctl %s %d\n", cb->f[0], l);
1184 if(l < 1 || l > 1024)
1185 error("maxpkt not in [1:1024]");
1191 l = strtoul(cb->f[1], nil, 0);
1192 deprint("usb epctl %s %d\n", cb->f[0], l);
1194 error("ntds not in [1:3]");
1200 if(ep->ttype != Tintr && ep->ttype != Tiso)
1201 error("not an intr or iso endpoint");
1202 l = strtoul(cb->f[1], nil, 0);
1203 deprint("usb epctl %s %d\n", cb->f[0], l);
1204 if(ep->ttype == Tiso ||
1205 (ep->ttype == Tintr && ep->dev->speed == Highspeed)){
1207 error("pollival power not in [1:16]");
1210 if(l < 1 || l > 255)
1211 error("pollival not in [1:255]");
1214 if(ep->ttype == Tiso)
1215 setmaxpkt(ep, "pollival");
1219 if(ep->ttype != Tiso)
1220 error("not an iso endpoint");
1221 l = strtoul(cb->f[1], nil, 0);
1222 deprint("usb epctl %s %d\n", cb->f[0], l);
1224 error("samplesz not in [1:8]");
1227 setmaxpkt(ep, "samplesz");
1231 if(ep->ttype != Tiso)
1232 error("not an iso endpoint");
1233 l = strtoul(cb->f[1], nil, 0);
1234 deprint("usb epctl %s %d\n", cb->f[0], l);
1235 if(l <= 0 || l > 100000)
1236 error("hz not in [1:100000]");
1239 setmaxpkt(ep, "hz");
1244 deprint("usb epctl %s\n", cb->f[0]);
1249 deprint("usb epctl %s\n", cb->f[0]);
1252 if(n < l+2 || strncmp(Info, s, l) != 0)
1257 memmove(b, s+l, n-l);
1259 if(b[n-l-1] == '\n')
1267 deprint("usb epctl %s\n", cb->f[0]);
1268 ep->dev->state = Denabled;
1271 if(ep->dev->isroot != 0)
1272 error("can't detach a root hub");
1273 deprint("usb epctl %s ep%d.%d\n",
1274 cb->f[0], ep->dev->nb, ep->nb);
1275 ep->dev->state = Ddetach;
1276 /* Release file system ref. for its endpoints */
1277 for(i = 0; i < nelem(ep->dev->eps); i++)
1278 putep(ep->dev->eps[i]);
1281 if(strcmp(cb->f[1], "on") == 0)
1283 else if(strcmp(cb->f[1], "off") == 0)
1286 ep->debug = strtoul(cb->f[1], nil, 0);
1287 print("usb: ep%d.%d debug %d\n",
1288 ep->dev->nb, ep->nb, ep->debug);
1291 deprint("usb epctl %s %s\n", cb->f[0], cb->f[1]);
1292 validname(cb->f[1], 0);
1293 kstrdup(&ep->name, cb->f[1]);
1296 deprint("usb epctl %s\n", cb->f[0]);
1297 if(ep->ttype == Tiso || ep->ttype == Tctl)
1298 error("ctl ignored for this endpoint type");
1299 ep->tmout = strtoul(cb->f[1], nil, 0);
1300 if(ep->tmout != 0 && ep->tmout < Xfertmout)
1301 ep->tmout = Xfertmout;
1304 if(ep->ttype != Tiso)
1305 error("ctl ignored for this endpoint type");
1306 ep->sampledelay = strtoul(cb->f[1], nil, 0);
1309 deprint("usb epctl %s\n", cb->f[0]);
1310 if(ep->ttype != Tctl)
1311 error("not a control endpoint");
1312 if(ep->dev->state != Denabled)
1313 error("forbidden on devices not enabled");
1314 ep->dev->state = Dreset;
1317 panic("usb: unknown epctl %d", ct->index);
1325 usbctl(void *a, long n)
1332 cb = parsecmd(a, n);
1337 ct = lookupcmd(cb, usbctls, nelem(usbctls));
1338 dprint("usb ctl %s\n", cb->f[0]);
1341 if(strcmp(cb->f[1], "on") == 0)
1343 else if(strcmp(cb->f[1], "off") == 0)
1346 debug = strtol(cb->f[1], nil, 0);
1347 print("usb: debug %d\n", debug);
1348 for(i = 0; i < epmax; i++)
1349 if((ep = getep(i)) != nil){
1350 ep->hp->debug(ep->hp, debug);
1364 ctlwrite(Chan *c, void *a, long n)
1371 return usbctl(a, n);
1373 ep = getep(qid2epidx(q));
1380 if(ep->dev->state == Ddetach)
1382 if(isqtype(q, Qepctl) && c->aux != nil){
1383 /* Be sure we don't keep a cloned ep name */
1386 error("read, not write, expected");
1388 n = epctl(ep, c, a, n);
1395 usbwrite(Chan *c, void *a, long n, vlong off)
1400 if(c->qid.type == QTDIR)
1405 if(q == Qctl || isqtype(q, Qepctl))
1406 return ctlwrite(c, a, n);
1408 ep = getep(qid2epidx(q));
1415 if(ep->dev->state == Ddetach)
1417 if(ep->mode == OREAD || ep->inuse == 0)
1422 error("endpoint not configured");
1424 nr = rhubwrite(ep, a, n);
1431 ddeprint("\nusbwrite q %#x fid %d cnt %ld off %lld\n",q, c->fid, n, off);
1432 ep->hp->epwrite(ep, a, n);
1445 for(i = 0; i < Nhcis; i++){
1449 if(hp->shutdown == nil)
1450 print("#u: no shutdown function for %s\n", hp->type);