usb_generic.c (184610) | usb_generic.c (185087) |
---|---|
1/* $FreeBSD: head/sys/dev/usb2/core/usb2_generic.c 184610 2008-11-04 02:31:03Z alfred $ */ | 1/* $FreeBSD: head/sys/dev/usb2/core/usb2_generic.c 185087 2008-11-19 08:56:35Z alfred $ */ |
2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. 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. --- 52 unchanged lines hidden (view full) --- 62static usb2_callback_t ugen_default_write_callback; 63static usb2_callback_t ugen_isoc_read_callback; 64static usb2_callback_t ugen_isoc_write_callback; 65static usb2_callback_t ugen_default_fs_callback; 66 67static usb2_fifo_open_t ugen_open; 68static usb2_fifo_close_t ugen_close; 69static usb2_fifo_ioctl_t ugen_ioctl; | 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. 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. --- 52 unchanged lines hidden (view full) --- 62static usb2_callback_t ugen_default_write_callback; 63static usb2_callback_t ugen_isoc_read_callback; 64static usb2_callback_t ugen_isoc_write_callback; 65static usb2_callback_t ugen_default_fs_callback; 66 67static usb2_fifo_open_t ugen_open; 68static usb2_fifo_close_t ugen_close; 69static usb2_fifo_ioctl_t ugen_ioctl; |
70static usb2_fifo_ioctl_t ugen_ioctl_post; |
|
70static usb2_fifo_cmd_t ugen_start_read; 71static usb2_fifo_cmd_t ugen_start_write; 72static usb2_fifo_cmd_t ugen_stop_io; 73 74static int ugen_transfer_setup(struct usb2_fifo *f, const struct usb2_config *setup, uint8_t n_setup); 75static int ugen_open_pipe_write(struct usb2_fifo *f); 76static int ugen_open_pipe_read(struct usb2_fifo *f); 77static int ugen_set_config(struct usb2_fifo *f, uint8_t index); 78static int ugen_set_interface(struct usb2_fifo *f, uint8_t iface_index, uint8_t alt_index); 79static int ugen_get_cdesc(struct usb2_fifo *f, struct usb2_gen_descriptor *pgd); 80static int ugen_get_sdesc(struct usb2_fifo *f, struct usb2_gen_descriptor *ugd); 81static int usb2_gen_fill_deviceinfo(struct usb2_fifo *f, struct usb2_device_info *di); 82static int ugen_re_enumerate(struct usb2_fifo *f); 83static int ugen_iface_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags); | 71static usb2_fifo_cmd_t ugen_start_read; 72static usb2_fifo_cmd_t ugen_start_write; 73static usb2_fifo_cmd_t ugen_stop_io; 74 75static int ugen_transfer_setup(struct usb2_fifo *f, const struct usb2_config *setup, uint8_t n_setup); 76static int ugen_open_pipe_write(struct usb2_fifo *f); 77static int ugen_open_pipe_read(struct usb2_fifo *f); 78static int ugen_set_config(struct usb2_fifo *f, uint8_t index); 79static int ugen_set_interface(struct usb2_fifo *f, uint8_t iface_index, uint8_t alt_index); 80static int ugen_get_cdesc(struct usb2_fifo *f, struct usb2_gen_descriptor *pgd); 81static int ugen_get_sdesc(struct usb2_fifo *f, struct usb2_gen_descriptor *ugd); 82static int usb2_gen_fill_deviceinfo(struct usb2_fifo *f, struct usb2_device_info *di); 83static int ugen_re_enumerate(struct usb2_fifo *f); 84static int ugen_iface_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags); |
84static int ugen_ctrl_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags); 85static int ugen_fs_uninit(struct usb2_fifo *f); | |
86static uint8_t ugen_fs_get_complete(struct usb2_fifo *f, uint8_t *pindex); 87 88 89/* structures */ 90 91struct usb2_fifo_methods usb2_ugen_methods = { 92 .f_open = &ugen_open, 93 .f_close = &ugen_close, 94 .f_ioctl = &ugen_ioctl, | 85static uint8_t ugen_fs_get_complete(struct usb2_fifo *f, uint8_t *pindex); 86 87 88/* structures */ 89 90struct usb2_fifo_methods usb2_ugen_methods = { 91 .f_open = &ugen_open, 92 .f_close = &ugen_close, 93 .f_ioctl = &ugen_ioctl, |
94 .f_ioctl_post = &ugen_ioctl_post, |
|
95 .f_start_read = &ugen_start_read, 96 .f_stop_read = &ugen_stop_io, 97 .f_start_write = &ugen_start_write, 98 .f_stop_write = &ugen_stop_io, 99}; 100 101#if USB_DEBUG 102static int ugen_debug = 0; --- 101 unchanged lines hidden (view full) --- 204 struct usb2_endpoint_descriptor *ed = pipe->edesc; 205 206 mtx_assert(f->priv_mtx, MA_OWNED); 207 208 if (f->xfer[0] || f->xfer[1]) { 209 /* transfers are already opened */ 210 return (0); 211 } | 95 .f_start_read = &ugen_start_read, 96 .f_stop_read = &ugen_stop_io, 97 .f_start_write = &ugen_start_write, 98 .f_stop_write = &ugen_stop_io, 99}; 100 101#if USB_DEBUG 102static int ugen_debug = 0; --- 101 unchanged lines hidden (view full) --- 204 struct usb2_endpoint_descriptor *ed = pipe->edesc; 205 206 mtx_assert(f->priv_mtx, MA_OWNED); 207 208 if (f->xfer[0] || f->xfer[1]) { 209 /* transfers are already opened */ 210 return (0); 211 } |
212 if (f->fs_xfer) { 213 /* should not happen */ 214 return (EINVAL); 215 } | |
216 bzero(usb2_config, sizeof(usb2_config)); 217 218 usb2_config[1].type = UE_CONTROL; 219 usb2_config[1].endpoint = 0; 220 usb2_config[1].direction = UE_DIR_ANY; 221 usb2_config[1].mh.timeout = 1000; /* 1 second */ 222 usb2_config[1].mh.interval = 50;/* 50 milliseconds */ 223 usb2_config[1].mh.bufsize = sizeof(struct usb2_device_request); --- 52 unchanged lines hidden (view full) --- 276 struct usb2_endpoint_descriptor *ed = pipe->edesc; 277 278 mtx_assert(f->priv_mtx, MA_OWNED); 279 280 if (f->xfer[0] || f->xfer[1]) { 281 /* transfers are already opened */ 282 return (0); 283 } | 212 bzero(usb2_config, sizeof(usb2_config)); 213 214 usb2_config[1].type = UE_CONTROL; 215 usb2_config[1].endpoint = 0; 216 usb2_config[1].direction = UE_DIR_ANY; 217 usb2_config[1].mh.timeout = 1000; /* 1 second */ 218 usb2_config[1].mh.interval = 50;/* 50 milliseconds */ 219 usb2_config[1].mh.bufsize = sizeof(struct usb2_device_request); --- 52 unchanged lines hidden (view full) --- 272 struct usb2_endpoint_descriptor *ed = pipe->edesc; 273 274 mtx_assert(f->priv_mtx, MA_OWNED); 275 276 if (f->xfer[0] || f->xfer[1]) { 277 /* transfers are already opened */ 278 return (0); 279 } |
284 if (f->fs_xfer) { 285 /* should not happen */ 286 return (EINVAL); 287 } | |
288 bzero(usb2_config, sizeof(usb2_config)); 289 290 usb2_config[1].type = UE_CONTROL; 291 usb2_config[1].endpoint = 0; 292 usb2_config[1].direction = UE_DIR_ANY; 293 usb2_config[1].mh.timeout = 1000; /* 1 second */ 294 usb2_config[1].mh.interval = 50;/* 50 milliseconds */ 295 usb2_config[1].mh.bufsize = sizeof(struct usb2_device_request); --- 290 unchanged lines hidden (view full) --- 586 return; 587} 588 589static int 590ugen_set_config(struct usb2_fifo *f, uint8_t index) 591{ 592 DPRINTFN(2, "index %u\n", index); 593 | 280 bzero(usb2_config, sizeof(usb2_config)); 281 282 usb2_config[1].type = UE_CONTROL; 283 usb2_config[1].endpoint = 0; 284 usb2_config[1].direction = UE_DIR_ANY; 285 usb2_config[1].mh.timeout = 1000; /* 1 second */ 286 usb2_config[1].mh.interval = 50;/* 50 milliseconds */ 287 usb2_config[1].mh.bufsize = sizeof(struct usb2_device_request); --- 290 unchanged lines hidden (view full) --- 578 return; 579} 580 581static int 582ugen_set_config(struct usb2_fifo *f, uint8_t index) 583{ 584 DPRINTFN(2, "index %u\n", index); 585 |
594 if (f->flag_no_uref) { 595 /* not the control endpoint - just forget it */ 596 return (EINVAL); 597 } | |
598 if (f->udev->flags.usb2_mode != USB_MODE_HOST) { 599 /* not possible in device side mode */ 600 return (ENOTTY); 601 } 602 if (f->udev->curr_config_index == index) { 603 /* no change needed */ 604 return (0); 605 } --- 9 unchanged lines hidden (view full) --- 615} 616 617static int 618ugen_set_interface(struct usb2_fifo *f, 619 uint8_t iface_index, uint8_t alt_index) 620{ 621 DPRINTFN(2, "%u, %u\n", iface_index, alt_index); 622 | 586 if (f->udev->flags.usb2_mode != USB_MODE_HOST) { 587 /* not possible in device side mode */ 588 return (ENOTTY); 589 } 590 if (f->udev->curr_config_index == index) { 591 /* no change needed */ 592 return (0); 593 } --- 9 unchanged lines hidden (view full) --- 603} 604 605static int 606ugen_set_interface(struct usb2_fifo *f, 607 uint8_t iface_index, uint8_t alt_index) 608{ 609 DPRINTFN(2, "%u, %u\n", iface_index, alt_index); 610 |
623 if (f->flag_no_uref) { 624 /* not the control endpoint - just forget it */ 625 return (EINVAL); 626 } | |
627 if (f->udev->flags.usb2_mode != USB_MODE_HOST) { 628 /* not possible in device side mode */ 629 return (ENOTTY); 630 } 631 /* change setting - will free generic FIFOs, if any */ 632 if (usb2_set_alt_interface_index(f->udev, iface_index, alt_index)) { 633 return (EIO); 634 } --- 16 unchanged lines hidden (view full) --- 651 struct usb2_config_descriptor *cdesc; 652 struct usb2_device *udev = f->udev; 653 int error; 654 uint16_t len; 655 uint8_t free_data; 656 657 DPRINTFN(6, "\n"); 658 | 611 if (f->udev->flags.usb2_mode != USB_MODE_HOST) { 612 /* not possible in device side mode */ 613 return (ENOTTY); 614 } 615 /* change setting - will free generic FIFOs, if any */ 616 if (usb2_set_alt_interface_index(f->udev, iface_index, alt_index)) { 617 return (EIO); 618 } --- 16 unchanged lines hidden (view full) --- 635 struct usb2_config_descriptor *cdesc; 636 struct usb2_device *udev = f->udev; 637 int error; 638 uint16_t len; 639 uint8_t free_data; 640 641 DPRINTFN(6, "\n"); 642 |
659 if (f->flag_no_uref) { 660 /* control endpoint only */ 661 return (EINVAL); 662 } | |
663 if (ugd->ugd_data == NULL) { 664 /* userland pointer should not be zero */ 665 return (EINVAL); 666 } 667 if ((ugd->ugd_config_index == USB_UNCONFIG_INDEX) || 668 (ugd->ugd_config_index == udev->curr_config_index)) { 669 cdesc = usb2_get_config_descriptor(udev); 670 if (cdesc == NULL) { --- 29 unchanged lines hidden (view full) --- 700 701static int 702ugen_get_sdesc(struct usb2_fifo *f, struct usb2_gen_descriptor *ugd) 703{ 704 void *ptr = f->udev->bus->scratch[0].data; 705 uint16_t size = sizeof(f->udev->bus->scratch[0].data); 706 int error; 707 | 643 if (ugd->ugd_data == NULL) { 644 /* userland pointer should not be zero */ 645 return (EINVAL); 646 } 647 if ((ugd->ugd_config_index == USB_UNCONFIG_INDEX) || 648 (ugd->ugd_config_index == udev->curr_config_index)) { 649 cdesc = usb2_get_config_descriptor(udev); 650 if (cdesc == NULL) { --- 29 unchanged lines hidden (view full) --- 680 681static int 682ugen_get_sdesc(struct usb2_fifo *f, struct usb2_gen_descriptor *ugd) 683{ 684 void *ptr = f->udev->bus->scratch[0].data; 685 uint16_t size = sizeof(f->udev->bus->scratch[0].data); 686 int error; 687 |
708 if (f->flag_no_uref) { 709 /* control endpoint only */ 710 return (EINVAL); 711 } | |
712 if (usb2_req_get_string_desc(f->udev, &Giant, ptr, 713 size, ugd->ugd_lang_id, ugd->ugd_string_index)) { 714 error = EINVAL; 715 } else { 716 717 if (size > ((uint8_t *)ptr)[0]) { 718 size = ((uint8_t *)ptr)[0]; 719 } --- 26 unchanged lines hidden (view full) --- 746 char *dst; 747 char buf[32]; 748 int error = 0; 749 int len; 750 int max_len; 751 uint8_t i; 752 uint8_t first = 1; 753 | 688 if (usb2_req_get_string_desc(f->udev, &Giant, ptr, 689 size, ugd->ugd_lang_id, ugd->ugd_string_index)) { 690 error = EINVAL; 691 } else { 692 693 if (size > ((uint8_t *)ptr)[0]) { 694 size = ((uint8_t *)ptr)[0]; 695 } --- 26 unchanged lines hidden (view full) --- 722 char *dst; 723 char buf[32]; 724 int error = 0; 725 int len; 726 int max_len; 727 uint8_t i; 728 uint8_t first = 1; 729 |
754 if (f->flag_no_uref) { 755 /* control endpoint only */ 756 return (EINVAL); 757 } | |
758 max_len = dn->udn_devnames_len; 759 dst = dn->udn_devnames_ptr; 760 761 if (max_len == 0) { 762 return (EINVAL); 763 } 764 /* put a zero there */ 765 error = copyout("", dst, 1); --- 42 unchanged lines hidden (view full) --- 808 * Else: Failure 809 *------------------------------------------------------------------------*/ 810static int 811usb2_gen_fill_deviceinfo(struct usb2_fifo *f, struct usb2_device_info *di) 812{ 813 struct usb2_device *udev; 814 struct usb2_device *hub; 815 | 730 max_len = dn->udn_devnames_len; 731 dst = dn->udn_devnames_ptr; 732 733 if (max_len == 0) { 734 return (EINVAL); 735 } 736 /* put a zero there */ 737 error = copyout("", dst, 1); --- 42 unchanged lines hidden (view full) --- 780 * Else: Failure 781 *------------------------------------------------------------------------*/ 782static int 783usb2_gen_fill_deviceinfo(struct usb2_fifo *f, struct usb2_device_info *di) 784{ 785 struct usb2_device *udev; 786 struct usb2_device *hub; 787 |
816 if (f->flag_no_uref) { 817 /* control endpoint only */ 818 return (EINVAL); 819 } | |
820 udev = f->udev; 821 822 bzero(di, sizeof(di[0])); 823 824 di->udi_bus = device_get_unit(udev->bus->bdev); 825 di->udi_addr = udev->address; 826 di->udi_index = udev->device_index; 827 strlcpy(di->udi_serial, udev->serial, --- 86 unchanged lines hidden (view full) --- 914 915int 916ugen_do_request(struct usb2_fifo *f, struct usb2_ctl_request *ur) 917{ 918 int error; 919 uint16_t len; 920 uint16_t actlen; 921 | 788 udev = f->udev; 789 790 bzero(di, sizeof(di[0])); 791 792 di->udi_bus = device_get_unit(udev->bus->bdev); 793 di->udi_addr = udev->address; 794 di->udi_index = udev->device_index; 795 strlcpy(di->udi_serial, udev->serial, --- 86 unchanged lines hidden (view full) --- 882 883int 884ugen_do_request(struct usb2_fifo *f, struct usb2_ctl_request *ur) 885{ 886 int error; 887 uint16_t len; 888 uint16_t actlen; 889 |
922 if (f->flag_no_uref) { 923 /* control endpoint only */ 924 return (EINVAL); 925 } | |
926 if (ugen_check_request(f->udev, &ur->ucr_request)) { 927 return (EPERM); 928 } 929 len = UGETW(ur->ucr_request.wLength); 930 931 /* check if "ucr_data" is valid */ 932 if (len != 0) { 933 if (ur->ucr_data == NULL) { --- 19 unchanged lines hidden (view full) --- 953 * ugen_re_enumerate 954 *------------------------------------------------------------------------*/ 955static int 956ugen_re_enumerate(struct usb2_fifo *f) 957{ 958 struct usb2_device *udev = f->udev; 959 int error; 960 | 890 if (ugen_check_request(f->udev, &ur->ucr_request)) { 891 return (EPERM); 892 } 893 len = UGETW(ur->ucr_request.wLength); 894 895 /* check if "ucr_data" is valid */ 896 if (len != 0) { 897 if (ur->ucr_data == NULL) { --- 19 unchanged lines hidden (view full) --- 917 * ugen_re_enumerate 918 *------------------------------------------------------------------------*/ 919static int 920ugen_re_enumerate(struct usb2_fifo *f) 921{ 922 struct usb2_device *udev = f->udev; 923 int error; 924 |
961 if (f->flag_no_uref) { 962 /* control endpoint only */ 963 return (EINVAL); 964 } | |
965 /* 966 * This request can be useful for testing USB drivers: 967 */ 968 error = priv_check(curthread, PRIV_DRIVER); 969 if (error) { 970 return (error); 971 } | 925 /* 926 * This request can be useful for testing USB drivers: 927 */ 928 error = priv_check(curthread, PRIV_DRIVER); 929 if (error) { 930 return (error); 931 } |
932 /* get the device unconfigured */ 933 error = ugen_set_config(f, USB_UNCONFIG_INDEX); 934 if (error) { 935 return (error); 936 } 937 /* do a bus-reset */ |
|
972 mtx_lock(f->priv_mtx); 973 error = usb2_req_re_enumerate(udev, f->priv_mtx); 974 mtx_unlock(f->priv_mtx); 975 976 if (error) { 977 return (ENXIO); 978 } | 938 mtx_lock(f->priv_mtx); 939 error = usb2_req_re_enumerate(udev, f->priv_mtx); 940 mtx_unlock(f->priv_mtx); 941 942 if (error) { 943 return (ENXIO); 944 } |
945 /* restore configuration to index 0 */ 946 error = ugen_set_config(f, 0); 947 if (error) { 948 return (error); 949 } |
|
979 return (0); 980} 981 | 950 return (0); 951} 952 |
982static int | 953int |
983ugen_fs_uninit(struct usb2_fifo *f) 984{ 985 if (f->fs_xfer == NULL) { 986 return (EINVAL); 987 } 988 usb2_transfer_unsetup(f->fs_xfer, f->fs_ep_max); 989 free(f->fs_xfer, M_USB); 990 f->fs_xfer = NULL; 991 f->fs_ep_max = 0; 992 f->fs_ep_ptr = NULL; 993 f->flag_iscomplete = 0; | 954ugen_fs_uninit(struct usb2_fifo *f) 955{ 956 if (f->fs_xfer == NULL) { 957 return (EINVAL); 958 } 959 usb2_transfer_unsetup(f->fs_xfer, f->fs_ep_max); 960 free(f->fs_xfer, M_USB); 961 f->fs_xfer = NULL; 962 f->fs_ep_max = 0; 963 f->fs_ep_ptr = NULL; 964 f->flag_iscomplete = 0; |
994 f->flag_no_uref = 0; /* restore operation */ | |
995 usb2_fifo_free_buffer(f); 996 return (0); 997} 998 999static uint8_t 1000ugen_fs_get_complete(struct usb2_fifo *f, uint8_t *pindex) 1001{ 1002 struct usb2_mbuf *m; --- 385 unchanged lines hidden (view full) --- 1388 if ((fflags & FWRITE) && f_tx && 1389 (f_tx->xfer[0] || f_tx->xfer[1])) { 1390 return (1); /* TX FIFO in use */ 1391 } 1392 return (0); /* not in use */ 1393} 1394 1395static int | 965 usb2_fifo_free_buffer(f); 966 return (0); 967} 968 969static uint8_t 970ugen_fs_get_complete(struct usb2_fifo *f, uint8_t *pindex) 971{ 972 struct usb2_mbuf *m; --- 385 unchanged lines hidden (view full) --- 1358 if ((fflags & FWRITE) && f_tx && 1359 (f_tx->xfer[0] || f_tx->xfer[1])) { 1360 return (1); /* TX FIFO in use */ 1361 } 1362 return (0); /* not in use */ 1363} 1364 1365static int |
1396ugen_fs_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags) | 1366ugen_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags, 1367 struct thread *td) |
1397{ 1398 struct usb2_config usb2_config[1]; 1399 struct usb2_device_request req; 1400 union { 1401 struct usb2_fs_complete *pcomp; 1402 struct usb2_fs_start *pstart; 1403 struct usb2_fs_stop *pstop; | 1368{ 1369 struct usb2_config usb2_config[1]; 1370 struct usb2_device_request req; 1371 union { 1372 struct usb2_fs_complete *pcomp; 1373 struct usb2_fs_start *pstart; 1374 struct usb2_fs_stop *pstop; |
1404 struct usb2_fs_init *pinit; 1405 struct usb2_fs_uninit *puninit; | |
1406 struct usb2_fs_open *popen; 1407 struct usb2_fs_close *pclose; 1408 struct usb2_fs_clear_stall_sync *pstall; 1409 void *addr; 1410 } u; 1411 struct usb2_pipe *pipe; 1412 struct usb2_endpoint_descriptor *ed; 1413 int error = 0; 1414 uint8_t iface_index; 1415 uint8_t isread; 1416 uint8_t ep_index; 1417 1418 u.addr = addr; 1419 | 1375 struct usb2_fs_open *popen; 1376 struct usb2_fs_close *pclose; 1377 struct usb2_fs_clear_stall_sync *pstall; 1378 void *addr; 1379 } u; 1380 struct usb2_pipe *pipe; 1381 struct usb2_endpoint_descriptor *ed; 1382 int error = 0; 1383 uint8_t iface_index; 1384 uint8_t isread; 1385 uint8_t ep_index; 1386 1387 u.addr = addr; 1388 |
1389 DPRINTFN(6, "cmd=0x%08lx\n", cmd); 1390 |
|
1420 switch (cmd) { 1421 case USB_FS_COMPLETE: 1422 mtx_lock(f->priv_mtx); 1423 error = ugen_fs_get_complete(f, &ep_index); 1424 mtx_unlock(f->priv_mtx); 1425 1426 if (error) { 1427 error = EBUSY; --- 18 unchanged lines hidden (view full) --- 1446 error = EINVAL; 1447 break; 1448 } 1449 mtx_lock(f->priv_mtx); 1450 usb2_transfer_stop(f->fs_xfer[u.pstop->ep_index]); 1451 mtx_unlock(f->priv_mtx); 1452 break; 1453 | 1391 switch (cmd) { 1392 case USB_FS_COMPLETE: 1393 mtx_lock(f->priv_mtx); 1394 error = ugen_fs_get_complete(f, &ep_index); 1395 mtx_unlock(f->priv_mtx); 1396 1397 if (error) { 1398 error = EBUSY; --- 18 unchanged lines hidden (view full) --- 1417 error = EINVAL; 1418 break; 1419 } 1420 mtx_lock(f->priv_mtx); 1421 usb2_transfer_stop(f->fs_xfer[u.pstop->ep_index]); 1422 mtx_unlock(f->priv_mtx); 1423 break; 1424 |
1454 case USB_FS_INIT: 1455 /* verify input parameters */ 1456 if (u.pinit->pEndpoints == NULL) { 1457 error = EINVAL; 1458 break; 1459 } 1460 if (u.pinit->ep_index_max > 127) { 1461 error = EINVAL; 1462 break; 1463 } 1464 if (u.pinit->ep_index_max == 0) { 1465 error = EINVAL; 1466 break; 1467 } 1468 if (f->fs_xfer != NULL) { 1469 error = EBUSY; 1470 break; 1471 } 1472 if (f->flag_no_uref) { 1473 error = EINVAL; 1474 break; 1475 } 1476 if (f->dev_ep_index != 0) { 1477 error = EINVAL; 1478 break; 1479 } 1480 if (ugen_fifo_in_use(f, fflags)) { 1481 error = EBUSY; 1482 break; 1483 } 1484 error = usb2_fifo_alloc_buffer(f, 1, u.pinit->ep_index_max); 1485 if (error) { 1486 break; 1487 } 1488 f->fs_xfer = malloc(sizeof(f->fs_xfer[0]) * 1489 u.pinit->ep_index_max, M_USB, M_WAITOK | M_ZERO); 1490 if (f->fs_xfer == NULL) { 1491 usb2_fifo_free_buffer(f); 1492 error = ENOMEM; 1493 break; 1494 } 1495 f->fs_ep_max = u.pinit->ep_index_max; 1496 f->fs_ep_ptr = u.pinit->pEndpoints; 1497 break; 1498 1499 case USB_FS_UNINIT: 1500 if (u.puninit->dummy != 0) { 1501 error = EINVAL; 1502 break; 1503 } 1504 error = ugen_fs_uninit(f); 1505 break; 1506 | |
1507 case USB_FS_OPEN: 1508 if (u.popen->ep_index >= f->fs_ep_max) { 1509 error = EINVAL; 1510 break; 1511 } 1512 if (f->fs_xfer[u.popen->ep_index] != NULL) { 1513 error = EBUSY; 1514 break; --- 71 unchanged lines hidden (view full) --- 1586 if (error == 0) { 1587 /* update maximums */ 1588 u.popen->max_packet_length = 1589 f->fs_xfer[u.popen->ep_index]->max_frame_size; 1590 u.popen->max_bufsize = 1591 f->fs_xfer[u.popen->ep_index]->max_data_length; 1592 f->fs_xfer[u.popen->ep_index]->priv_fifo = 1593 ((uint8_t *)0) + u.popen->ep_index; | 1425 case USB_FS_OPEN: 1426 if (u.popen->ep_index >= f->fs_ep_max) { 1427 error = EINVAL; 1428 break; 1429 } 1430 if (f->fs_xfer[u.popen->ep_index] != NULL) { 1431 error = EBUSY; 1432 break; --- 71 unchanged lines hidden (view full) --- 1504 if (error == 0) { 1505 /* update maximums */ 1506 u.popen->max_packet_length = 1507 f->fs_xfer[u.popen->ep_index]->max_frame_size; 1508 u.popen->max_bufsize = 1509 f->fs_xfer[u.popen->ep_index]->max_data_length; 1510 f->fs_xfer[u.popen->ep_index]->priv_fifo = 1511 ((uint8_t *)0) + u.popen->ep_index; |
1594 /* 1595 * Increase performance by dropping locks we 1596 * don't need: 1597 */ 1598 f->flag_no_uref = 1; | |
1599 } else { 1600 error = ENOMEM; 1601 } 1602 break; 1603 1604 case USB_FS_CLOSE: 1605 if (u.pclose->ep_index >= f->fs_ep_max) { 1606 error = EINVAL; --- 40 unchanged lines hidden (view full) --- 1647 if (error == 0) { 1648 usb2_clear_data_toggle(f->udev, pipe); 1649 } else { 1650 error = ENXIO; 1651 } 1652 break; 1653 1654 default: | 1512 } else { 1513 error = ENOMEM; 1514 } 1515 break; 1516 1517 case USB_FS_CLOSE: 1518 if (u.pclose->ep_index >= f->fs_ep_max) { 1519 error = EINVAL; --- 40 unchanged lines hidden (view full) --- 1560 if (error == 0) { 1561 usb2_clear_data_toggle(f->udev, pipe); 1562 } else { 1563 error = ENXIO; 1564 } 1565 break; 1566 1567 default: |
1655 error = ENOTTY; | 1568 error = ENOIOCTL; |
1656 break; 1657 } | 1569 break; 1570 } |
1571 1572 DPRINTFN(6, "error=%d\n", error); 1573 |
|
1658 return (error); 1659} 1660 1661static int 1662ugen_set_short_xfer(struct usb2_fifo *f, void *addr) 1663{ 1664 uint8_t t; 1665 --- 336 unchanged lines hidden (view full) --- 2002 2003 case USB_SET_TX_STALL_FLAG: 2004 if ((fflags & FWRITE) && (*(int *)addr)) { 2005 f_tx->flag_stall = 1; 2006 } 2007 break; 2008 2009 default: | 1574 return (error); 1575} 1576 1577static int 1578ugen_set_short_xfer(struct usb2_fifo *f, void *addr) 1579{ 1580 uint8_t t; 1581 --- 336 unchanged lines hidden (view full) --- 1918 1919 case USB_SET_TX_STALL_FLAG: 1920 if ((fflags & FWRITE) && (*(int *)addr)) { 1921 f_tx->flag_stall = 1; 1922 } 1923 break; 1924 1925 default: |
2010 error = ENOTTY; | 1926 error = ENOIOCTL; |
2011 break; 2012 } 2013 return (error); 2014} 2015 2016static int | 1927 break; 1928 } 1929 return (error); 1930} 1931 1932static int |
2017ugen_ctrl_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags) | 1933ugen_ioctl_post(struct usb2_fifo *f, u_long cmd, void *addr, int fflags, 1934 struct thread *td) |
2018{ 2019 union { 2020 struct usb2_interface_descriptor *idesc; 2021 struct usb2_alt_interface *ai; 2022 struct usb2_device_descriptor *ddesc; 2023 struct usb2_config_descriptor *cdesc; 2024 struct usb2_device_stats *stat; | 1935{ 1936 union { 1937 struct usb2_interface_descriptor *idesc; 1938 struct usb2_alt_interface *ai; 1939 struct usb2_device_descriptor *ddesc; 1940 struct usb2_config_descriptor *cdesc; 1941 struct usb2_device_stats *stat; |
1942 struct usb2_fs_init *pinit; 1943 struct usb2_fs_uninit *puninit; |
|
2025 uint32_t *ptime; 2026 void *addr; 2027 int *pint; 2028 } u; 2029 struct usb2_device_descriptor *dtemp; 2030 struct usb2_config_descriptor *ctemp; 2031 struct usb2_interface *iface; 2032 int error = 0; 2033 uint8_t n; 2034 2035 u.addr = addr; 2036 | 1944 uint32_t *ptime; 1945 void *addr; 1946 int *pint; 1947 } u; 1948 struct usb2_device_descriptor *dtemp; 1949 struct usb2_config_descriptor *ctemp; 1950 struct usb2_interface *iface; 1951 int error = 0; 1952 uint8_t n; 1953 1954 u.addr = addr; 1955 |
1956 DPRINTFN(6, "cmd=0x%08lx\n", cmd); 1957 |
|
2037 switch (cmd) { 2038 case USB_DISCOVER: 2039 usb2_needs_explore_all(); 2040 break; 2041 2042 case USB_SETDEBUG: 2043 if (!(fflags & FWRITE)) { 2044 error = EPERM; --- 128 unchanged lines hidden (view full) --- 2173 *u.pint, 1, UHF_PORT_ENABLE); 2174 break; 2175 2176 case USB_SET_PORT_DISABLE: 2177 error = ugen_do_port_feature(f, 2178 *u.pint, 0, UHF_PORT_ENABLE); 2179 break; 2180 | 1958 switch (cmd) { 1959 case USB_DISCOVER: 1960 usb2_needs_explore_all(); 1961 break; 1962 1963 case USB_SETDEBUG: 1964 if (!(fflags & FWRITE)) { 1965 error = EPERM; --- 128 unchanged lines hidden (view full) --- 2094 *u.pint, 1, UHF_PORT_ENABLE); 2095 break; 2096 2097 case USB_SET_PORT_DISABLE: 2098 error = ugen_do_port_feature(f, 2099 *u.pint, 0, UHF_PORT_ENABLE); 2100 break; 2101 |
2181 default: 2182 error = EINVAL; | 2102 case USB_FS_INIT: 2103 /* verify input parameters */ 2104 if (u.pinit->pEndpoints == NULL) { 2105 error = EINVAL; 2106 break; 2107 } 2108 if (u.pinit->ep_index_max > 127) { 2109 error = EINVAL; 2110 break; 2111 } 2112 if (u.pinit->ep_index_max == 0) { 2113 error = EINVAL; 2114 break; 2115 } 2116 if (f->fs_xfer != NULL) { 2117 error = EBUSY; 2118 break; 2119 } 2120 if (f->dev_ep_index != 0) { 2121 error = EINVAL; 2122 break; 2123 } 2124 if (ugen_fifo_in_use(f, fflags)) { 2125 error = EBUSY; 2126 break; 2127 } 2128 error = usb2_fifo_alloc_buffer(f, 1, u.pinit->ep_index_max); 2129 if (error) { 2130 break; 2131 } 2132 f->fs_xfer = malloc(sizeof(f->fs_xfer[0]) * 2133 u.pinit->ep_index_max, M_USB, M_WAITOK | M_ZERO); 2134 if (f->fs_xfer == NULL) { 2135 usb2_fifo_free_buffer(f); 2136 error = ENOMEM; 2137 break; 2138 } 2139 f->fs_ep_max = u.pinit->ep_index_max; 2140 f->fs_ep_ptr = u.pinit->pEndpoints; |
2183 break; | 2141 break; |
2184 } 2185 return (error); 2186} | |
2187 | 2142 |
2188static int 2189ugen_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags, 2190 struct thread *td) 2191{ 2192 int error; 2193 2194 DPRINTFN(6, "cmd=%08lx\n", cmd); 2195 error = ugen_fs_ioctl(f, cmd, addr, fflags); 2196 if (error == ENOTTY) { 2197 if (f->flag_no_uref) { 2198 mtx_lock(f->priv_mtx); 2199 error = ugen_iface_ioctl(f, cmd, addr, fflags); 2200 mtx_unlock(f->priv_mtx); 2201 } else { 2202 error = ugen_ctrl_ioctl(f, cmd, addr, fflags); | 2143 case USB_FS_UNINIT: 2144 if (u.puninit->dummy != 0) { 2145 error = EINVAL; 2146 break; |
2203 } | 2147 } |
2148 error = ugen_fs_uninit(f); 2149 break; 2150 2151 default: 2152 mtx_lock(f->priv_mtx); 2153 error = ugen_iface_ioctl(f, cmd, addr, fflags); 2154 mtx_unlock(f->priv_mtx); 2155 break; |
|
2204 } 2205 DPRINTFN(6, "error=%d\n", error); 2206 return (error); 2207} 2208 2209static void 2210ugen_default_fs_callback(struct usb2_xfer *xfer) 2211{ --- 15 unchanged lines hidden --- | 2156 } 2157 DPRINTFN(6, "error=%d\n", error); 2158 return (error); 2159} 2160 2161static void 2162ugen_default_fs_callback(struct usb2_xfer *xfer) 2163{ --- 15 unchanged lines hidden --- |