usb_transfer.c (246363) | usb_transfer.c (246616) |
---|---|
1/* $FreeBSD: head/sys/dev/usb/usb_transfer.c 246363 2013-02-05 14:44:25Z hselasky $ */ | 1/* $FreeBSD: head/sys/dev/usb/usb_transfer.c 246616 2013-02-10 10:56:13Z hselasky $ */ |
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. --- 7 unchanged lines hidden (view full) --- 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR 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. | 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. --- 7 unchanged lines hidden (view full) --- 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR 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 */ | 25 */ |
26 27#ifdef USB_GLOBAL_INCLUDE_FILE 28#include USB_GLOBAL_INCLUDE_FILE 29#else 30#include <sys/stdint.h> 31#include <sys/stddef.h> 32#include <sys/param.h> 33#include <sys/queue.h> --- 816 unchanged lines hidden (view full) --- 850 * Else: Failure 851 *------------------------------------------------------------------------*/ 852usb_error_t 853usbd_transfer_setup(struct usb_device *udev, 854 const uint8_t *ifaces, struct usb_xfer **ppxfer, 855 const struct usb_config *setup_start, uint16_t n_setup, 856 void *priv_sc, struct mtx *xfer_mtx) 857{ | 26 27#ifdef USB_GLOBAL_INCLUDE_FILE 28#include USB_GLOBAL_INCLUDE_FILE 29#else 30#include <sys/stdint.h> 31#include <sys/stddef.h> 32#include <sys/param.h> 33#include <sys/queue.h> --- 816 unchanged lines hidden (view full) --- 850 * Else: Failure 851 *------------------------------------------------------------------------*/ 852usb_error_t 853usbd_transfer_setup(struct usb_device *udev, 854 const uint8_t *ifaces, struct usb_xfer **ppxfer, 855 const struct usb_config *setup_start, uint16_t n_setup, 856 void *priv_sc, struct mtx *xfer_mtx) 857{ |
858 struct usb_xfer dummy; 859 struct usb_setup_params parm; | |
860 const struct usb_config *setup_end = setup_start + n_setup; 861 const struct usb_config *setup; | 858 const struct usb_config *setup_end = setup_start + n_setup; 859 const struct usb_config *setup; |
860 struct usb_setup_params *parm; |
|
862 struct usb_endpoint *ep; 863 struct usb_xfer_root *info; 864 struct usb_xfer *xfer; 865 void *buf = NULL; | 861 struct usb_endpoint *ep; 862 struct usb_xfer_root *info; 863 struct usb_xfer *xfer; 864 void *buf = NULL; |
865 usb_error_t error = 0; |
|
866 uint16_t n; 867 uint16_t refcount; | 866 uint16_t n; 867 uint16_t refcount; |
868 uint8_t do_unlock; |
|
868 | 869 |
869 parm.err = 0; 870 refcount = 0; 871 info = NULL; 872 | |
873 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 874 "usbd_transfer_setup can sleep!"); 875 876 /* do some checking first */ 877 878 if (n_setup == 0) { 879 DPRINTFN(6, "setup array has zero length!\n"); 880 return (USB_ERR_INVAL); 881 } 882 if (ifaces == 0) { 883 DPRINTFN(6, "ifaces array is NULL!\n"); 884 return (USB_ERR_INVAL); 885 } 886 if (xfer_mtx == NULL) { 887 DPRINTFN(6, "using global lock\n"); 888 xfer_mtx = &Giant; 889 } | 870 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 871 "usbd_transfer_setup can sleep!"); 872 873 /* do some checking first */ 874 875 if (n_setup == 0) { 876 DPRINTFN(6, "setup array has zero length!\n"); 877 return (USB_ERR_INVAL); 878 } 879 if (ifaces == 0) { 880 DPRINTFN(6, "ifaces array is NULL!\n"); 881 return (USB_ERR_INVAL); 882 } 883 if (xfer_mtx == NULL) { 884 DPRINTFN(6, "using global lock\n"); 885 xfer_mtx = &Giant; 886 } |
890 /* sanity checks */ | 887 888 /* more sanity checks */ 889 |
891 for (setup = setup_start, n = 0; 892 setup != setup_end; setup++, n++) { 893 if (setup->bufsize == (usb_frlength_t)-1) { | 890 for (setup = setup_start, n = 0; 891 setup != setup_end; setup++, n++) { 892 if (setup->bufsize == (usb_frlength_t)-1) { |
894 parm.err = USB_ERR_BAD_BUFSIZE; | 893 error = USB_ERR_BAD_BUFSIZE; |
895 DPRINTF("invalid bufsize\n"); 896 } 897 if (setup->callback == NULL) { | 894 DPRINTF("invalid bufsize\n"); 895 } 896 if (setup->callback == NULL) { |
898 parm.err = USB_ERR_NO_CALLBACK; | 897 error = USB_ERR_NO_CALLBACK; |
899 DPRINTF("no callback\n"); 900 } 901 ppxfer[n] = NULL; 902 } 903 | 898 DPRINTF("no callback\n"); 899 } 900 ppxfer[n] = NULL; 901 } 902 |
904 if (parm.err) { 905 goto done; 906 } 907 memset(&parm, 0, sizeof(parm)); | 903 if (error) 904 return (error); |
908 | 905 |
909 parm.udev = udev; 910 parm.speed = usbd_get_speed(udev); 911 parm.hc_max_packet_count = 1; | 906 /* Protect scratch area */ 907 do_unlock = usbd_enum_lock(udev); |
912 | 908 |
913 if (parm.speed >= USB_SPEED_MAX) { 914 parm.err = USB_ERR_INVAL; | 909 refcount = 0; 910 info = NULL; 911 912 parm = &udev->scratch.xfer_setup[0].parm; 913 memset(parm, 0, sizeof(*parm)); 914 915 parm->udev = udev; 916 parm->speed = usbd_get_speed(udev); 917 parm->hc_max_packet_count = 1; 918 919 if (parm->speed >= USB_SPEED_MAX) { 920 parm->err = USB_ERR_INVAL; |
915 goto done; 916 } 917 /* setup all transfers */ 918 919 while (1) { 920 921 if (buf) { 922 /* 923 * Initialize the "usb_xfer_root" structure, 924 * which is common for all our USB transfers. 925 */ 926 info = USB_ADD_BYTES(buf, 0); 927 928 info->memory_base = buf; | 921 goto done; 922 } 923 /* setup all transfers */ 924 925 while (1) { 926 927 if (buf) { 928 /* 929 * Initialize the "usb_xfer_root" structure, 930 * which is common for all our USB transfers. 931 */ 932 info = USB_ADD_BYTES(buf, 0); 933 934 info->memory_base = buf; |
929 info->memory_size = parm.size[0]; | 935 info->memory_size = parm->size[0]; |
930 931#if USB_HAVE_BUSDMA | 936 937#if USB_HAVE_BUSDMA |
932 info->dma_page_cache_start = USB_ADD_BYTES(buf, parm.size[4]); 933 info->dma_page_cache_end = USB_ADD_BYTES(buf, parm.size[5]); | 938 info->dma_page_cache_start = USB_ADD_BYTES(buf, parm->size[4]); 939 info->dma_page_cache_end = USB_ADD_BYTES(buf, parm->size[5]); |
934#endif | 940#endif |
935 info->xfer_page_cache_start = USB_ADD_BYTES(buf, parm.size[5]); 936 info->xfer_page_cache_end = USB_ADD_BYTES(buf, parm.size[2]); | 941 info->xfer_page_cache_start = USB_ADD_BYTES(buf, parm->size[5]); 942 info->xfer_page_cache_end = USB_ADD_BYTES(buf, parm->size[2]); |
937 938 cv_init(&info->cv_drain, "WDRAIN"); 939 940 info->xfer_mtx = xfer_mtx; 941#if USB_HAVE_BUSDMA 942 usb_dma_tag_setup(&info->dma_parent_tag, | 943 944 cv_init(&info->cv_drain, "WDRAIN"); 945 946 info->xfer_mtx = xfer_mtx; 947#if USB_HAVE_BUSDMA 948 usb_dma_tag_setup(&info->dma_parent_tag, |
943 parm.dma_tag_p, udev->bus->dma_parent_tag[0].tag, 944 xfer_mtx, &usb_bdma_done_event, 32, parm.dma_tag_max); | 949 parm->dma_tag_p, udev->bus->dma_parent_tag[0].tag, 950 xfer_mtx, &usb_bdma_done_event, 32, parm->dma_tag_max); |
945#endif 946 947 info->bus = udev->bus; 948 info->udev = udev; 949 950 TAILQ_INIT(&info->done_q.head); 951 info->done_q.command = &usbd_callback_wrapper; 952#if USB_HAVE_BUSDMA --- 18 unchanged lines hidden (view full) --- 971 info->done_p = 972 USB_BUS_GIANT_PROC(udev->bus); 973 else 974 info->done_p = 975 USB_BUS_NON_GIANT_PROC(udev->bus); 976 } 977 /* reset sizes */ 978 | 951#endif 952 953 info->bus = udev->bus; 954 info->udev = udev; 955 956 TAILQ_INIT(&info->done_q.head); 957 info->done_q.command = &usbd_callback_wrapper; 958#if USB_HAVE_BUSDMA --- 18 unchanged lines hidden (view full) --- 977 info->done_p = 978 USB_BUS_GIANT_PROC(udev->bus); 979 else 980 info->done_p = 981 USB_BUS_NON_GIANT_PROC(udev->bus); 982 } 983 /* reset sizes */ 984 |
979 parm.size[0] = 0; 980 parm.buf = buf; 981 parm.size[0] += sizeof(info[0]); | 985 parm->size[0] = 0; 986 parm->buf = buf; 987 parm->size[0] += sizeof(info[0]); |
982 983 for (setup = setup_start, n = 0; 984 setup != setup_end; setup++, n++) { 985 986 /* skip USB transfers without callbacks: */ 987 if (setup->callback == NULL) { 988 continue; 989 } --- 15 unchanged lines hidden (view full) --- 1005 (setup->stream_id != 0 && 1006 (setup->stream_id >= USB_MAX_EP_STREAMS || 1007 (ep->ep_mode != USB_EP_MODE_STREAMS)))) { 1008 if (setup->flags.no_pipe_ok) 1009 continue; 1010 if ((setup->usb_mode != USB_MODE_DUAL) && 1011 (setup->usb_mode != udev->flags.usb_mode)) 1012 continue; | 988 989 for (setup = setup_start, n = 0; 990 setup != setup_end; setup++, n++) { 991 992 /* skip USB transfers without callbacks: */ 993 if (setup->callback == NULL) { 994 continue; 995 } --- 15 unchanged lines hidden (view full) --- 1011 (setup->stream_id != 0 && 1012 (setup->stream_id >= USB_MAX_EP_STREAMS || 1013 (ep->ep_mode != USB_EP_MODE_STREAMS)))) { 1014 if (setup->flags.no_pipe_ok) 1015 continue; 1016 if ((setup->usb_mode != USB_MODE_DUAL) && 1017 (setup->usb_mode != udev->flags.usb_mode)) 1018 continue; |
1013 parm.err = USB_ERR_NO_PIPE; | 1019 parm->err = USB_ERR_NO_PIPE; |
1014 goto done; 1015 } 1016 1017 /* align data properly */ | 1020 goto done; 1021 } 1022 1023 /* align data properly */ |
1018 parm.size[0] += ((-parm.size[0]) & (USB_HOST_ALIGN - 1)); | 1024 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1)); |
1019 1020 /* store current setup pointer */ | 1025 1026 /* store current setup pointer */ |
1021 parm.curr_setup = setup; | 1027 parm->curr_setup = setup; |
1022 1023 if (buf) { 1024 /* 1025 * Common initialization of the 1026 * "usb_xfer" structure. 1027 */ | 1028 1029 if (buf) { 1030 /* 1031 * Common initialization of the 1032 * "usb_xfer" structure. 1033 */ |
1028 xfer = USB_ADD_BYTES(buf, parm.size[0]); | 1034 xfer = USB_ADD_BYTES(buf, parm->size[0]); |
1029 xfer->address = udev->address; 1030 xfer->priv_sc = priv_sc; 1031 xfer->xroot = info; 1032 1033 usb_callout_init_mtx(&xfer->timeout_handle, 1034 &udev->bus->bus_mtx, 0); 1035 } else { 1036 /* 1037 * Setup a dummy xfer, hence we are 1038 * writing to the "usb_xfer" 1039 * structure pointed to by "xfer" 1040 * before we have allocated any 1041 * memory: 1042 */ | 1035 xfer->address = udev->address; 1036 xfer->priv_sc = priv_sc; 1037 xfer->xroot = info; 1038 1039 usb_callout_init_mtx(&xfer->timeout_handle, 1040 &udev->bus->bus_mtx, 0); 1041 } else { 1042 /* 1043 * Setup a dummy xfer, hence we are 1044 * writing to the "usb_xfer" 1045 * structure pointed to by "xfer" 1046 * before we have allocated any 1047 * memory: 1048 */ |
1043 xfer = &dummy; 1044 memset(&dummy, 0, sizeof(dummy)); | 1049 xfer = &udev->scratch.xfer_setup[0].dummy; 1050 memset(xfer, 0, sizeof(*xfer)); |
1045 refcount++; 1046 } 1047 1048 /* set transfer endpoint pointer */ 1049 xfer->endpoint = ep; 1050 1051 /* set transfer stream ID */ 1052 xfer->stream_id = setup->stream_id; 1053 | 1051 refcount++; 1052 } 1053 1054 /* set transfer endpoint pointer */ 1055 xfer->endpoint = ep; 1056 1057 /* set transfer stream ID */ 1058 xfer->stream_id = setup->stream_id; 1059 |
1054 parm.size[0] += sizeof(xfer[0]); 1055 parm.methods = xfer->endpoint->methods; 1056 parm.curr_xfer = xfer; | 1060 parm->size[0] += sizeof(xfer[0]); 1061 parm->methods = xfer->endpoint->methods; 1062 parm->curr_xfer = xfer; |
1057 1058 /* 1059 * Call the Host or Device controller transfer 1060 * setup routine: 1061 */ | 1063 1064 /* 1065 * Call the Host or Device controller transfer 1066 * setup routine: 1067 */ |
1062 (udev->bus->methods->xfer_setup) (&parm); | 1068 (udev->bus->methods->xfer_setup) (parm); |
1063 1064 /* check for error */ | 1069 1070 /* check for error */ |
1065 if (parm.err) | 1071 if (parm->err) |
1066 goto done; 1067 1068 if (buf) { 1069 /* 1070 * Increment the endpoint refcount. This 1071 * basically prevents setting a new 1072 * configuration and alternate setting 1073 * when USB transfers are in use on 1074 * the given interface. Search the USB 1075 * code for "endpoint->refcount_alloc" if you 1076 * want more information. 1077 */ 1078 USB_BUS_LOCK(info->bus); 1079 if (xfer->endpoint->refcount_alloc >= USB_EP_REF_MAX) | 1072 goto done; 1073 1074 if (buf) { 1075 /* 1076 * Increment the endpoint refcount. This 1077 * basically prevents setting a new 1078 * configuration and alternate setting 1079 * when USB transfers are in use on 1080 * the given interface. Search the USB 1081 * code for "endpoint->refcount_alloc" if you 1082 * want more information. 1083 */ 1084 USB_BUS_LOCK(info->bus); 1085 if (xfer->endpoint->refcount_alloc >= USB_EP_REF_MAX) |
1080 parm.err = USB_ERR_INVAL; | 1086 parm->err = USB_ERR_INVAL; |
1081 1082 xfer->endpoint->refcount_alloc++; 1083 1084 if (xfer->endpoint->refcount_alloc == 0) 1085 panic("usbd_transfer_setup(): Refcount wrapped to zero\n"); 1086 USB_BUS_UNLOCK(info->bus); 1087 1088 /* --- 6 unchanged lines hidden (view full) --- 1095 /* 1096 * Transfer is successfully setup and 1097 * can be used: 1098 */ 1099 ppxfer[n] = xfer; 1100 } 1101 1102 /* check for error */ | 1087 1088 xfer->endpoint->refcount_alloc++; 1089 1090 if (xfer->endpoint->refcount_alloc == 0) 1091 panic("usbd_transfer_setup(): Refcount wrapped to zero\n"); 1092 USB_BUS_UNLOCK(info->bus); 1093 1094 /* --- 6 unchanged lines hidden (view full) --- 1101 /* 1102 * Transfer is successfully setup and 1103 * can be used: 1104 */ 1105 ppxfer[n] = xfer; 1106 } 1107 1108 /* check for error */ |
1103 if (parm.err) | 1109 if (parm->err) |
1104 goto done; 1105 } 1106 | 1110 goto done; 1111 } 1112 |
1107 if (buf || parm.err) { | 1113 if (buf != NULL || parm->err != 0) |
1108 goto done; | 1114 goto done; |
1109 } 1110 if (refcount == 0) { 1111 /* no transfers - nothing to do ! */ | 1115 1116 /* if no transfers, nothing to do */ 1117 if (refcount == 0) |
1112 goto done; | 1118 goto done; |
1113 } | 1119 |
1114 /* align data properly */ | 1120 /* align data properly */ |
1115 parm.size[0] += ((-parm.size[0]) & (USB_HOST_ALIGN - 1)); | 1121 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1)); |
1116 1117 /* store offset temporarily */ | 1122 1123 /* store offset temporarily */ |
1118 parm.size[1] = parm.size[0]; | 1124 parm->size[1] = parm->size[0]; |
1119 1120 /* 1121 * The number of DMA tags required depends on 1122 * the number of endpoints. The current estimate 1123 * for maximum number of DMA tags per endpoint 1124 * is three: 1125 * 1) for loading memory 1126 * 2) for allocating memory 1127 * 3) for fixing memory [UHCI] 1128 */ | 1125 1126 /* 1127 * The number of DMA tags required depends on 1128 * the number of endpoints. The current estimate 1129 * for maximum number of DMA tags per endpoint 1130 * is three: 1131 * 1) for loading memory 1132 * 2) for allocating memory 1133 * 3) for fixing memory [UHCI] 1134 */ |
1129 parm.dma_tag_max += 3 * MIN(n_setup, USB_EP_MAX); | 1135 parm->dma_tag_max += 3 * MIN(n_setup, USB_EP_MAX); |
1130 1131 /* 1132 * DMA tags for QH, TD, Data and more. 1133 */ | 1136 1137 /* 1138 * DMA tags for QH, TD, Data and more. 1139 */ |
1134 parm.dma_tag_max += 8; | 1140 parm->dma_tag_max += 8; |
1135 | 1141 |
1136 parm.dma_tag_p += parm.dma_tag_max; | 1142 parm->dma_tag_p += parm->dma_tag_max; |
1137 | 1143 |
1138 parm.size[0] += ((uint8_t *)parm.dma_tag_p) - | 1144 parm->size[0] += ((uint8_t *)parm->dma_tag_p) - |
1139 ((uint8_t *)0); 1140 1141 /* align data properly */ | 1145 ((uint8_t *)0); 1146 1147 /* align data properly */ |
1142 parm.size[0] += ((-parm.size[0]) & (USB_HOST_ALIGN - 1)); | 1148 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1)); |
1143 1144 /* store offset temporarily */ | 1149 1150 /* store offset temporarily */ |
1145 parm.size[3] = parm.size[0]; | 1151 parm->size[3] = parm->size[0]; |
1146 | 1152 |
1147 parm.size[0] += ((uint8_t *)parm.dma_page_ptr) - | 1153 parm->size[0] += ((uint8_t *)parm->dma_page_ptr) - |
1148 ((uint8_t *)0); 1149 1150 /* align data properly */ | 1154 ((uint8_t *)0); 1155 1156 /* align data properly */ |
1151 parm.size[0] += ((-parm.size[0]) & (USB_HOST_ALIGN - 1)); | 1157 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1)); |
1152 1153 /* store offset temporarily */ | 1158 1159 /* store offset temporarily */ |
1154 parm.size[4] = parm.size[0]; | 1160 parm->size[4] = parm->size[0]; |
1155 | 1161 |
1156 parm.size[0] += ((uint8_t *)parm.dma_page_cache_ptr) - | 1162 parm->size[0] += ((uint8_t *)parm->dma_page_cache_ptr) - |
1157 ((uint8_t *)0); 1158 1159 /* store end offset temporarily */ | 1163 ((uint8_t *)0); 1164 1165 /* store end offset temporarily */ |
1160 parm.size[5] = parm.size[0]; | 1166 parm->size[5] = parm->size[0]; |
1161 | 1167 |
1162 parm.size[0] += ((uint8_t *)parm.xfer_page_cache_ptr) - | 1168 parm->size[0] += ((uint8_t *)parm->xfer_page_cache_ptr) - |
1163 ((uint8_t *)0); 1164 1165 /* store end offset temporarily */ 1166 | 1169 ((uint8_t *)0); 1170 1171 /* store end offset temporarily */ 1172 |
1167 parm.size[2] = parm.size[0]; | 1173 parm->size[2] = parm->size[0]; |
1168 1169 /* align data properly */ | 1174 1175 /* align data properly */ |
1170 parm.size[0] += ((-parm.size[0]) & (USB_HOST_ALIGN - 1)); | 1176 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1)); |
1171 | 1177 |
1172 parm.size[6] = parm.size[0]; | 1178 parm->size[6] = parm->size[0]; |
1173 | 1179 |
1174 parm.size[0] += ((uint8_t *)parm.xfer_length_ptr) - | 1180 parm->size[0] += ((uint8_t *)parm->xfer_length_ptr) - |
1175 ((uint8_t *)0); 1176 1177 /* align data properly */ | 1181 ((uint8_t *)0); 1182 1183 /* align data properly */ |
1178 parm.size[0] += ((-parm.size[0]) & (USB_HOST_ALIGN - 1)); | 1184 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1)); |
1179 1180 /* allocate zeroed memory */ | 1185 1186 /* allocate zeroed memory */ |
1181 buf = malloc(parm.size[0], M_USB, M_WAITOK | M_ZERO); | 1187 buf = malloc(parm->size[0], M_USB, M_WAITOK | M_ZERO); |
1182 1183 if (buf == NULL) { | 1188 1189 if (buf == NULL) { |
1184 parm.err = USB_ERR_NOMEM; | 1190 parm->err = USB_ERR_NOMEM; |
1185 DPRINTFN(0, "cannot allocate memory block for " 1186 "configuration (%d bytes)\n", | 1191 DPRINTFN(0, "cannot allocate memory block for " 1192 "configuration (%d bytes)\n", |
1187 parm.size[0]); | 1193 parm->size[0]); |
1188 goto done; 1189 } | 1194 goto done; 1195 } |
1190 parm.dma_tag_p = USB_ADD_BYTES(buf, parm.size[1]); 1191 parm.dma_page_ptr = USB_ADD_BYTES(buf, parm.size[3]); 1192 parm.dma_page_cache_ptr = USB_ADD_BYTES(buf, parm.size[4]); 1193 parm.xfer_page_cache_ptr = USB_ADD_BYTES(buf, parm.size[5]); 1194 parm.xfer_length_ptr = USB_ADD_BYTES(buf, parm.size[6]); | 1196 parm->dma_tag_p = USB_ADD_BYTES(buf, parm->size[1]); 1197 parm->dma_page_ptr = USB_ADD_BYTES(buf, parm->size[3]); 1198 parm->dma_page_cache_ptr = USB_ADD_BYTES(buf, parm->size[4]); 1199 parm->xfer_page_cache_ptr = USB_ADD_BYTES(buf, parm->size[5]); 1200 parm->xfer_length_ptr = USB_ADD_BYTES(buf, parm->size[6]); |
1195 } 1196 1197done: 1198 if (buf) { 1199 if (info->setup_refcount == 0) { 1200 /* 1201 * "usbd_transfer_unsetup_sub" will unlock 1202 * the bus mutex before returning ! 1203 */ 1204 USB_BUS_LOCK(info->bus); 1205 1206 /* something went wrong */ 1207 usbd_transfer_unsetup_sub(info, 0); 1208 } 1209 } | 1201 } 1202 1203done: 1204 if (buf) { 1205 if (info->setup_refcount == 0) { 1206 /* 1207 * "usbd_transfer_unsetup_sub" will unlock 1208 * the bus mutex before returning ! 1209 */ 1210 USB_BUS_LOCK(info->bus); 1211 1212 /* something went wrong */ 1213 usbd_transfer_unsetup_sub(info, 0); 1214 } 1215 } |
1210 if (parm.err) { | 1216 1217 /* check if any errors happened */ 1218 if (parm->err) |
1211 usbd_transfer_unsetup(ppxfer, n_setup); | 1219 usbd_transfer_unsetup(ppxfer, n_setup); |
1212 } 1213 return (parm.err); | 1220 1221 error = parm->err; 1222 1223 if (do_unlock) 1224 usbd_enum_unlock(udev); 1225 1226 return (error); |
1214} 1215 1216/*------------------------------------------------------------------------* 1217 * usbd_transfer_unsetup_sub - factored out code 1218 *------------------------------------------------------------------------*/ 1219static void 1220usbd_transfer_unsetup_sub(struct usb_xfer_root *info, uint8_t needs_delay) 1221{ --- 2182 unchanged lines hidden --- | 1227} 1228 1229/*------------------------------------------------------------------------* 1230 * usbd_transfer_unsetup_sub - factored out code 1231 *------------------------------------------------------------------------*/ 1232static void 1233usbd_transfer_unsetup_sub(struct usb_xfer_root *info, uint8_t needs_delay) 1234{ --- 2182 unchanged lines hidden --- |