]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/urio.c
Expand USB_ATTACH_{ERROR,SUCCESS}_RETURN inline and eliminate from
[FreeBSD/FreeBSD.git] / sys / dev / usb / urio.c
1 /*-
2  * Copyright (c) 2000 Iwasa Kazmi
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions, and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * This code is based on ugen.c and ulpt.c developed by Lennart Augustsson.
27  * This code includes software developed by the NetBSD Foundation, Inc. and
28  * its contributors.
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34
35 /*
36  * 2000/3/24  added NetBSD/OpenBSD support (from Alex Nemirovsky)
37  * 2000/3/07  use two bulk-pipe handles for read and write (Dirk)
38  * 2000/3/06  change major number(143), and copyright header
39  *            some fix for 4.0 (Dirk)
40  * 2000/3/05  codes for FreeBSD 4.x - CURRENT (Thanks to Dirk-Willem van Gulik)
41  * 2000/3/01  remove retry code from urioioctl()
42  *            change method of bulk transfer (no interrupt)
43  * 2000/2/28  small fixes for new rio_usb.h
44  * 2000/2/24  first version.
45  */
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
50 #include <sys/malloc.h>
51 #if defined(__NetBSD__)
52 #include <sys/device.h>
53 #include <sys/ioctl.h>
54 #elif defined(__FreeBSD__)
55 #include <sys/module.h>
56 #include <sys/bus.h>
57 #include <sys/ioccom.h>
58 #endif
59 #include <sys/fcntl.h>
60 #include <sys/filio.h>
61 #include <sys/conf.h>
62 #include <sys/uio.h>
63 #include <sys/tty.h>
64 #include <sys/file.h>
65 #include <sys/selinfo.h>
66 #include <sys/poll.h>
67 #include <sys/sysctl.h>
68 #include <sys/uio.h>
69
70 #include <dev/usb/usb.h>
71 #include <dev/usb/usbdi.h>
72 #include <dev/usb/usbdi_util.h>
73
74 #include "usbdevs.h"
75 #include <dev/usb/rio500_usb.h>
76
77 #ifdef USB_DEBUG
78 #define DPRINTF(x)      if (uriodebug) logprintf x
79 #define DPRINTFN(n,x)   if (uriodebug>(n)) logprintf x
80 int     uriodebug = 0;
81 SYSCTL_NODE(_hw_usb, OID_AUTO, urio, CTLFLAG_RW, 0, "USB urio");
82 SYSCTL_INT(_hw_usb_urio, OID_AUTO, debug, CTLFLAG_RW,
83            &uriodebug, 0, "urio debug level");
84 #else
85 #define DPRINTF(x)
86 #define DPRINTFN(n,x)
87 #endif
88
89 /* difference of usbd interface */
90 #define USBDI 1
91
92 #define RIO_OUT 0
93 #define RIO_IN  1
94 #define RIO_NODIR  2
95
96 #if defined(__NetBSD__)
97 int urioopen(dev_t, int, int, struct proc *);
98 int urioclose(dev_t, int, int, struct proc *p);
99 int urioread(dev_t, struct uio *uio, int);
100 int uriowrite(dev_t, struct uio *uio, int);
101 int urioioctl(dev_t, u_long, caddr_t, int, struct proc *);
102
103 cdev_decl(urio);
104 #define RIO_UE_GET_DIR(p) ((UE_GET_DIR(p) == UE_DIR_IN) ? RIO_IN :\
105                           ((UE_GET_DIR(p) == UE_DIR_OUT) ? RIO_OUT :\
106                                                            RIO_NODIR))
107 #elif defined(__FreeBSD__)
108 d_open_t  urioopen;
109 d_close_t urioclose;
110 d_read_t  urioread;
111 d_write_t uriowrite;
112 d_ioctl_t urioioctl;
113
114
115 static struct cdevsw urio_cdevsw = {
116         .d_version =    D_VERSION,
117         .d_flags =      D_NEEDGIANT,
118         .d_open =       urioopen,
119         .d_close =      urioclose,
120         .d_read =       urioread,
121         .d_write =      uriowrite,
122         .d_ioctl =      urioioctl,
123         .d_name =       "urio",
124 };
125 #define RIO_UE_GET_DIR(p) ((UE_GET_DIR(p) == UE_DIR_IN) ? RIO_IN :\
126                           ((UE_GET_DIR(p) == UE_DIR_OUT) ? RIO_OUT :\
127                                                            RIO_NODIR))
128 #endif  /*defined(__FreeBSD__)*/
129
130 #define URIO_BBSIZE     1024
131
132 struct urio_softc {
133         device_t sc_dev;
134         usbd_device_handle sc_udev;
135         usbd_interface_handle sc_iface;
136
137         int sc_opened;
138         usbd_pipe_handle sc_pipeh_in;
139         usbd_pipe_handle sc_pipeh_out;
140         int sc_epaddr[2];
141
142         int sc_refcnt;
143 #if defined(__FreeBSD__)
144         struct cdev *sc_dev_t;
145 #endif  /* defined(__FreeBSD__) */
146 #if defined(__NetBSD__) || defined(__OpenBSD__)
147         u_char sc_dying;
148 #endif
149 };
150
151 #define URIOUNIT(n) (minor(n))
152
153 #define RIO_RW_TIMEOUT 4000     /* ms */
154
155 USB_DECLARE_DRIVER(urio);
156
157 USB_MATCH(urio)
158 {
159         USB_MATCH_START(urio, uaa);
160         usb_device_descriptor_t *dd;
161
162         DPRINTFN(10,("urio_match\n"));
163         if (!uaa->iface)
164                 return UMATCH_NONE;
165
166         dd = usbd_get_device_descriptor(uaa->device);
167
168         if (dd &&
169             ((UGETW(dd->idVendor) == USB_VENDOR_DIAMOND &&
170             UGETW(dd->idProduct) == USB_PRODUCT_DIAMOND_RIO500USB) ||
171             (UGETW(dd->idVendor) == USB_VENDOR_DIAMOND2 &&
172               (UGETW(dd->idProduct) == USB_PRODUCT_DIAMOND2_RIO600USB ||
173               UGETW(dd->idProduct) == USB_PRODUCT_DIAMOND2_RIO800USB))))
174                 return UMATCH_VENDOR_PRODUCT;
175         else
176                 return UMATCH_NONE;
177 }
178
179 USB_ATTACH(urio)
180 {
181         USB_ATTACH_START(urio, sc, uaa);
182         usbd_device_handle udev;
183         usbd_interface_handle iface;
184         u_int8_t epcount;
185 #if defined(__NetBSD__) || defined(__OpenBSD__)
186         u_int8_t niface;
187 #endif
188         usbd_status r;
189         char * ermsg = "<none>";
190         int i;
191
192         DPRINTFN(10,("urio_attach: sc=%p\n", sc));
193         sc->sc_dev = self;
194         sc->sc_udev = udev = uaa->device;
195
196 #if defined(__FreeBSD__)
197         if ((!uaa->device) || (!uaa->iface)) {
198                 ermsg = "device or iface";
199                 goto nobulk;
200         }
201         sc->sc_iface = iface = uaa->iface;
202 #elif defined(__NetBSD__) || defined(__OpenBSD__)
203         if (!udev) {
204                 ermsg = "device";
205                 goto nobulk;
206         }
207         r = usbd_interface_count(udev, &niface);
208         if (r) {
209                 ermsg = "iface";
210                 goto nobulk;
211         }
212         r = usbd_device2interface_handle(udev, 0, &iface);
213         if (r) {
214                 ermsg = "iface";
215                 goto nobulk;
216         }
217         sc->sc_iface = iface;
218 #endif
219         sc->sc_opened = 0;
220         sc->sc_pipeh_in = 0;
221         sc->sc_pipeh_out = 0;
222         sc->sc_refcnt = 0;
223
224         r = usbd_endpoint_count(iface, &epcount);
225         if (r != USBD_NORMAL_COMPLETION) {
226                 ermsg = "endpoints";
227                 goto nobulk;
228         }
229
230         sc->sc_epaddr[RIO_OUT] = 0xff;
231         sc->sc_epaddr[RIO_IN] = 0x00;
232
233         for (i = 0; i < epcount; i++) {
234                 usb_endpoint_descriptor_t *edesc =
235                         usbd_interface2endpoint_descriptor(iface, i);
236                 int d;
237
238                 if (!edesc) {
239                         ermsg = "interface endpoint";
240                         goto nobulk;
241                 }
242
243                 d = RIO_UE_GET_DIR(edesc->bEndpointAddress);
244                 if (d != RIO_NODIR)
245                         sc->sc_epaddr[d] = edesc->bEndpointAddress;
246         }
247         if ( sc->sc_epaddr[RIO_OUT] == 0xff ||
248              sc->sc_epaddr[RIO_IN] == 0x00) {
249                 ermsg = "Rio I&O";
250                 goto nobulk;
251         }
252
253 #if defined(__FreeBSD__)
254         /* XXX no error trapping, no storing of struct cdev **/
255         sc->sc_dev_t = make_dev(&urio_cdevsw, device_get_unit(self),
256                         UID_ROOT, GID_OPERATOR,
257                         0644, "urio%d", device_get_unit(self));
258 #elif defined(__NetBSD__) || defined(__OpenBSD__)
259         usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
260                            USBDEV(sc->sc_dev));
261 #endif
262
263         DPRINTFN(10, ("urio_attach: %p\n", sc->sc_udev));
264
265         return 0;
266
267  nobulk:
268         printf("%s: could not find %s\n", device_get_nameunit(sc->sc_dev),ermsg);
269         return ENXIO;
270 }
271
272
273 int
274 urioopen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
275 {
276 #if (USBDI >= 1)
277         struct urio_softc * sc;
278 #endif
279         int unit = URIOUNIT(dev);
280         USB_GET_SC_OPEN(urio, unit, sc);
281
282         DPRINTFN(5, ("urioopen: flag=%d, mode=%d, unit=%d\n",
283                      flag, mode, unit));
284
285         if (sc->sc_opened)
286                 return EBUSY;
287
288         if ((flag & (FWRITE|FREAD)) != (FWRITE|FREAD))
289                 return EACCES;
290
291         sc->sc_opened = 1;
292         sc->sc_pipeh_in = 0;
293         sc->sc_pipeh_out = 0;
294         if (usbd_open_pipe(sc->sc_iface,
295                 sc->sc_epaddr[RIO_IN], 0, &sc->sc_pipeh_in)
296                         != USBD_NORMAL_COMPLETION)
297         {
298                         sc->sc_pipeh_in = 0;
299                         return EIO;
300         };
301         if (usbd_open_pipe(sc->sc_iface,
302                 sc->sc_epaddr[RIO_OUT], 0, &sc->sc_pipeh_out)
303                         != USBD_NORMAL_COMPLETION)
304         {
305                         usbd_close_pipe(sc->sc_pipeh_in);
306                         sc->sc_pipeh_in = 0;
307                         sc->sc_pipeh_out = 0;
308                         return EIO;
309         };
310         return 0;
311 }
312
313 int
314 urioclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
315 {
316 #if (USBDI >= 1)
317         struct urio_softc * sc;
318 #endif
319         int unit = URIOUNIT(dev);
320         USB_GET_SC(urio, unit, sc);
321
322         DPRINTFN(5, ("urioclose: flag=%d, mode=%d, unit=%d\n", flag, mode, unit));
323         if (sc->sc_pipeh_in)
324                 usbd_close_pipe(sc->sc_pipeh_in);
325
326         if (sc->sc_pipeh_out)
327                 usbd_close_pipe(sc->sc_pipeh_out);
328
329         sc->sc_pipeh_in = 0;
330         sc->sc_pipeh_out = 0;
331         sc->sc_opened = 0;
332         sc->sc_refcnt = 0;
333         return 0;
334 }
335
336 int
337 urioread(struct cdev *dev, struct uio *uio, int flag)
338 {
339 #if (USBDI >= 1)
340         struct urio_softc * sc;
341         usbd_xfer_handle reqh;
342 #else
343         usbd_request_handle reqh;
344         usbd_private_handle r_priv;
345         void *r_buff;
346         usbd_status r_status;
347 #endif
348         int unit = URIOUNIT(dev);
349         usbd_status r;
350         char buf[URIO_BBSIZE];
351         u_int32_t n, tn;
352         int error = 0;
353
354         USB_GET_SC(urio, unit, sc);
355
356         DPRINTFN(5, ("urioread: %d\n", unit));
357         if (!sc->sc_opened)
358                 return EIO;
359
360 #if (USBDI >= 1)
361         sc->sc_refcnt++;
362         reqh = usbd_alloc_xfer(sc->sc_udev);
363 #else
364         reqh = usbd_alloc_request();
365 #endif
366         if (reqh == 0)
367                 return ENOMEM;
368         while ((n = min(URIO_BBSIZE, uio->uio_resid)) != 0) {
369                 DPRINTFN(1, ("urioread: start transfer %d bytes\n", n));
370                 tn = n;
371 #if (USBDI >= 1)
372                 usbd_setup_xfer(reqh, sc->sc_pipeh_in, 0, buf, tn,
373                                        0, RIO_RW_TIMEOUT, 0);
374 #else
375                 r = usbd_setup_request(reqh, sc->sc_pipeh_in, 0, buf, tn,
376                                        0, RIO_RW_TIMEOUT, 0);
377                 if (r != USBD_NORMAL_COMPLETION) {
378                         error = EIO;
379                         break;
380                 }
381 #endif
382                 r = usbd_sync_transfer(reqh);
383                 if (r != USBD_NORMAL_COMPLETION) {
384                         DPRINTFN(1, ("urioread: error=%d\n", r));
385                         usbd_clear_endpoint_stall(sc->sc_pipeh_in);
386                         tn = 0;
387                         error = EIO;
388                         break;
389                 }
390 #if (USBDI >= 1)
391                 usbd_get_xfer_status(reqh, 0, 0, &tn, 0);
392 #else
393                 usbd_get_request_status(reqh, &r_priv, &r_buff, &tn, &r_status);
394 #endif
395
396                 DPRINTFN(1, ("urioread: got %d bytes\n", tn));
397                 error = uiomove(buf, tn, uio);
398                 if (error || tn < n)
399                         break;
400         }
401 #if (USBDI >= 1)
402         usbd_free_xfer(reqh);
403 #else
404         usbd_free_request(reqh);
405 #endif
406
407         return error;
408 }
409
410 int
411 uriowrite(struct cdev *dev, struct uio *uio, int flag)
412 {
413 #if (USBDI >= 1)
414         struct urio_softc * sc;
415         usbd_xfer_handle reqh;
416 #else
417         usbd_request_handle reqh;
418 #endif
419         int unit = URIOUNIT(dev);
420         usbd_status r;
421         char buf[URIO_BBSIZE];
422         u_int32_t n;
423         int error = 0;
424
425         USB_GET_SC(urio, unit, sc);
426
427         DPRINTFN(5, ("uriowrite: %d\n", unit));
428         if (!sc->sc_opened)
429                 return EIO;
430
431 #if (USBDI >= 1)
432         sc->sc_refcnt++;
433         reqh = usbd_alloc_xfer(sc->sc_udev);
434 #else
435         reqh = usbd_alloc_request();
436 #endif
437         if (reqh == 0)
438                 return EIO;
439         while ((n = min(URIO_BBSIZE, uio->uio_resid)) != 0) {
440                 error = uiomove(buf, n, uio);
441                 if (error)
442                         break;
443                 DPRINTFN(1, ("uriowrite: transfer %d bytes\n", n));
444 #if (USBDI >= 1)
445                 usbd_setup_xfer(reqh, sc->sc_pipeh_out, 0, buf, n,
446                                        0, RIO_RW_TIMEOUT, 0);
447 #else
448                 r = usbd_setup_request(reqh, sc->sc_pipeh_out, 0, buf, n,
449                                        0, RIO_RW_TIMEOUT, 0);
450                 if (r != USBD_NORMAL_COMPLETION) {
451                         error = EIO;
452                         break;
453                 }
454 #endif
455                 r = usbd_sync_transfer(reqh);
456                 if (r != USBD_NORMAL_COMPLETION) {
457                         DPRINTFN(1, ("uriowrite: error=%d\n", r));
458                         usbd_clear_endpoint_stall(sc->sc_pipeh_out);
459                         error = EIO;
460                         break;
461                 }
462 #if (USBDI >= 1)
463                 usbd_get_xfer_status(reqh, 0, 0, 0, 0);
464 #endif
465         }
466
467 #if (USBDI >= 1)
468         usbd_free_xfer(reqh);
469 #else
470         usbd_free_request(reqh);
471 #endif
472
473         return error;
474 }
475
476
477 int
478 urioioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p)
479 {
480 #if (USBDI >= 1)
481         struct urio_softc * sc;
482 #endif
483         int unit = URIOUNIT(dev);
484         struct RioCommand *rio_cmd;
485         int requesttype, len;
486         struct iovec iov;
487         struct uio uio;
488         usb_device_request_t req;
489         int req_flags = 0, req_actlen = 0;
490         void *ptr = 0;
491         int error = 0;
492         usbd_status r;
493
494         USB_GET_SC(urio, unit, sc);
495
496         switch (cmd) {
497         case RIO_RECV_COMMAND:
498                 if (!(flag & FWRITE))
499                         return EPERM;
500                 rio_cmd = (struct RioCommand *)addr;
501                 if (rio_cmd == NULL)
502                         return EINVAL;
503                 len = rio_cmd->length;
504
505                 requesttype = rio_cmd->requesttype | UT_READ_VENDOR_DEVICE;
506                 DPRINTFN(1,("sending command:reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
507                         requesttype, rio_cmd->request, rio_cmd->value, rio_cmd->index, len));
508                 break;
509
510         case RIO_SEND_COMMAND:
511                 if (!(flag & FWRITE))
512                         return EPERM;
513                 rio_cmd = (struct RioCommand *)addr;
514                 if (rio_cmd == NULL)
515                         return EINVAL;
516                 len = rio_cmd->length;
517
518                 requesttype = rio_cmd->requesttype | UT_WRITE_VENDOR_DEVICE;
519                 DPRINTFN(1,("sending command:reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
520                         requesttype, rio_cmd->request, rio_cmd->value, rio_cmd->index, len));
521                 break;
522
523         default:
524                 return EINVAL;
525                 break;
526         }
527
528         /* Send rio control message */
529         req.bmRequestType = requesttype;
530         req.bRequest = rio_cmd->request;
531         USETW(req.wValue, rio_cmd->value);
532         USETW(req.wIndex, rio_cmd->index);
533         USETW(req.wLength, len);
534
535         if (len < 0 || len > 32767)
536                 return EINVAL;
537         if (len != 0) {
538                 iov.iov_base = (caddr_t)rio_cmd->buffer;
539                 iov.iov_len = len;
540                 uio.uio_iov = &iov;
541                 uio.uio_iovcnt = 1;
542                 uio.uio_resid = len;
543                 uio.uio_offset = 0;
544                 uio.uio_segflg = UIO_USERSPACE;
545                 uio.uio_rw =
546                         req.bmRequestType & UT_READ ?
547                         UIO_READ : UIO_WRITE;
548                 uio.uio_td = p;
549                 ptr = malloc(len, M_TEMP, M_WAITOK);
550                 if (uio.uio_rw == UIO_WRITE) {
551                         error = uiomove(ptr, len, &uio);
552                         if (error)
553                                 goto ret;
554                 }
555         }
556
557         r = usbd_do_request_flags(sc->sc_udev, &req,
558                                   ptr, req_flags, &req_actlen,
559                                   USBD_DEFAULT_TIMEOUT);
560         if (r == USBD_NORMAL_COMPLETION) {
561                 error = 0;
562                 if (len != 0) {
563                         if (uio.uio_rw == UIO_READ) {
564                                 error = uiomove(ptr, len, &uio);
565                         }
566                 }
567         } else {
568                 error = EIO;
569         }
570
571 ret:
572         if (ptr)
573                 free(ptr, M_TEMP);
574         return error;
575 }
576
577
578 #if defined(__NetBSD__) || defined(__OpenBSD__)
579 int
580 urio_activate(device_t self, enum devact act)
581 {
582         struct urio_softc *sc = (struct urio_softc *)self;
583
584         switch (act) {
585         case DVACT_ACTIVATE:
586                 return (EOPNOTSUPP);
587                 break;
588
589         case DVACT_DEACTIVATE:
590                 sc->sc_dying = 1;
591                 break;
592         }
593         return (0);
594 }
595
596 USB_DETACH(urio)
597 {
598         USB_DETACH_START(urio, sc);
599         struct urio_endpoint *sce;
600         int i, dir;
601         int s;
602 #if defined(__NetBSD__) || defined(__OpenBSD__)
603         int maj, mn;
604
605         DPRINTF(("urio_detach: sc=%p flags=%d\n", sc, flags));
606 #elif defined(__FreeBSD__)
607         DPRINTF(("urio_detach: sc=%p\n", sc));
608 #endif
609
610         sc->sc_dying = 1;
611         /* Abort all pipes.  Causes processes waiting for transfer to wake. */
612 #if 0
613         for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
614                 for (dir = OUT; dir <= IN; dir++) {
615                         sce = &sc->sc_endpoints[i][dir];
616                         if (sce && sce->pipeh)
617                                 usbd_abort_pipe(sce->pipeh);
618                 }
619         }
620
621         s = splusb();
622         if (--sc->sc_refcnt >= 0) {
623                 /* Wake everyone */
624                 for (i = 0; i < USB_MAX_ENDPOINTS; i++)
625                         wakeup(&sc->sc_endpoints[i][IN]);
626                 /* Wait for processes to go away. */
627                 usb_detach_wait(USBDEV(sc->sc_dev));
628         }
629         splx(s);
630 #else
631         if (sc->sc_pipeh_in)
632                 usbd_abort_pipe(sc->sc_pipeh_in);
633
634         if (sc->sc_pipeh_out)
635                 usbd_abort_pipe(sc->sc_pipeh_out);
636
637         s = splusb();
638         if (--sc->sc_refcnt >= 0) {
639                 /* Wait for processes to go away. */
640                 usb_detach_wait(USBDEV(sc->sc_dev));
641         }
642         splx(s);
643 #endif
644
645 #if defined(__NetBSD__) || defined(__OpenBSD__)
646         /* locate the major number */
647         for (maj = 0; maj < nchrdev; maj++)
648                 if (cdevsw[maj].d_open == urioopen)
649                         break;
650
651         /* Nuke the vnodes for any open instances (calls close). */
652         mn = self->dv_unit * USB_MAX_ENDPOINTS;
653         vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);
654 #endif
655
656         usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
657                            USBDEV(sc->sc_dev));
658
659         return (0);
660 }
661 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
662
663 #if defined(__FreeBSD__)
664 static int
665 urio_detach(device_t self)
666 {
667         struct urio_softc *sc = device_get_softc(self);
668
669         DPRINTF(("%s: disconnected\n", device_get_nameunit(self)));
670         destroy_dev(sc->sc_dev_t);
671         /* XXX not implemented yet */
672         device_set_desc(self, NULL);
673         return 0;
674 }
675
676 DRIVER_MODULE(urio, uhub, urio_driver, urio_devclass, usbd_driver_load, 0);
677 #endif