Changeset 64ce0c1 in mainline for uspace/drv
- Timestamp:
- 2018-02-02T10:13:55Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 961a5ee
- Parents:
- e67c50a (diff), 290338b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/drv/bus/usb
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbdiag/device.c
re67c50a r64ce0c1 46 46 47 47 static usbdiag_iface_t diag_interface = { 48 .burst_intr_in = usbdiag_burst_test_intr_in, 49 .burst_intr_out = usbdiag_burst_test_intr_out, 50 .burst_bulk_in = usbdiag_burst_test_bulk_in, 51 .burst_bulk_out = usbdiag_burst_test_bulk_out, 52 .burst_isoch_in = usbdiag_burst_test_isoch_in, 53 .burst_isoch_out = usbdiag_burst_test_isoch_out, 54 .data_intr_in = usbdiag_data_test_intr_in, 55 .data_intr_out = usbdiag_data_test_intr_out, 56 .data_bulk_in = usbdiag_data_test_bulk_in, 57 .data_bulk_out = usbdiag_data_test_bulk_out, 58 .data_isoch_in = usbdiag_data_test_isoch_in, 59 .data_isoch_out = usbdiag_data_test_isoch_out 48 .test_in = usbdiag_dev_test_in, 49 .test_out = usbdiag_dev_test_out, 60 50 }; 61 51 … … 86 76 } while (0); 87 77 88 _MAP_EP(dev->intr_in, INTR_IN); 89 _MAP_EP(dev->intr_out, INTR_OUT); 90 _MAP_EP(dev->bulk_in, BULK_IN); 91 _MAP_EP(dev->bulk_out, BULK_OUT); 92 _MAP_EP(dev->isoch_in, ISOCH_IN); 93 _MAP_EP(dev->isoch_out, ISOCH_OUT); 78 _MAP_EP(dev->burst_intr_in, BURST_INTR_IN); 79 _MAP_EP(dev->burst_intr_out, BURST_INTR_OUT); 80 _MAP_EP(dev->burst_bulk_in, BURST_BULK_IN); 81 _MAP_EP(dev->burst_bulk_out, BURST_BULK_OUT); 82 _MAP_EP(dev->burst_isoch_in, BURST_ISOCH_IN); 83 _MAP_EP(dev->burst_isoch_out, BURST_ISOCH_OUT); 84 _MAP_EP(dev->data_intr_in, DATA_INTR_IN); 85 _MAP_EP(dev->data_intr_out, DATA_INTR_OUT); 86 _MAP_EP(dev->data_bulk_in, DATA_BULK_IN); 87 _MAP_EP(dev->data_bulk_out, DATA_BULK_OUT); 88 _MAP_EP(dev->data_isoch_in, DATA_ISOCH_IN); 89 _MAP_EP(dev->data_isoch_out, DATA_ISOCH_OUT); 94 90 95 91 #undef _MAP_EP -
uspace/drv/bus/usb/usbdiag/device.h
re67c50a r64ce0c1 40 40 #include <usb/dev/driver.h> 41 41 42 #define USBDIAG_EP_INTR_IN 1 43 #define USBDIAG_EP_INTR_OUT 2 44 #define USBDIAG_EP_BULK_IN 3 45 #define USBDIAG_EP_BULK_OUT 4 46 #define USBDIAG_EP_ISOCH_IN 5 47 #define USBDIAG_EP_ISOCH_OUT 6 42 #define USBDIAG_EP_BURST_INTR_IN 1 43 #define USBDIAG_EP_BURST_INTR_OUT 2 44 #define USBDIAG_EP_BURST_BULK_IN 3 45 #define USBDIAG_EP_BURST_BULK_OUT 4 46 #define USBDIAG_EP_BURST_ISOCH_IN 5 47 #define USBDIAG_EP_BURST_ISOCH_OUT 6 48 49 #define USBDIAG_EP_DATA_INTR_IN 7 50 #define USBDIAG_EP_DATA_INTR_OUT 8 51 #define USBDIAG_EP_DATA_BULK_IN 9 52 #define USBDIAG_EP_DATA_BULK_OUT 10 53 #define USBDIAG_EP_DATA_ISOCH_IN 11 54 #define USBDIAG_EP_DATA_ISOCH_OUT 12 48 55 49 56 /** … … 53 60 usb_device_t *usb_dev; 54 61 ddf_fun_t *fun; 55 usb_pipe_t *intr_in; 56 usb_pipe_t *intr_out; 57 usb_pipe_t *bulk_in; 58 usb_pipe_t *bulk_out; 59 usb_pipe_t *isoch_in; 60 usb_pipe_t *isoch_out; 62 63 usb_pipe_t *burst_intr_in; 64 usb_pipe_t *burst_intr_out; 65 usb_pipe_t *burst_bulk_in; 66 usb_pipe_t *burst_bulk_out; 67 usb_pipe_t *burst_isoch_in; 68 usb_pipe_t *burst_isoch_out; 69 70 usb_pipe_t *data_intr_in; 71 usb_pipe_t *data_intr_out; 72 usb_pipe_t *data_bulk_in; 73 usb_pipe_t *data_bulk_out; 74 usb_pipe_t *data_isoch_in; 75 usb_pipe_t *data_isoch_out; 76 61 77 } usbdiag_dev_t; 62 78 -
uspace/drv/bus/usb/usbdiag/main.c
re67c50a r64ce0c1 139 139 } 140 140 141 static const usb_endpoint_description_t intr_in_ep = { 142 .transfer_type = USB_TRANSFER_INTERRUPT, 143 .direction = USB_DIRECTION_IN, 144 .interface_class = USB_CLASS_DIAGNOSTIC, 145 .interface_subclass = 0x00, 146 .interface_protocol = 0x01, 147 .flags = 0 148 }; 149 static const usb_endpoint_description_t intr_out_ep = { 150 .transfer_type = USB_TRANSFER_INTERRUPT, 151 .direction = USB_DIRECTION_OUT, 152 .interface_class = USB_CLASS_DIAGNOSTIC, 153 .interface_subclass = 0x00, 154 .interface_protocol = 0x01, 155 .flags = 0 156 }; 157 static const usb_endpoint_description_t bulk_in_ep = { 158 .transfer_type = USB_TRANSFER_BULK, 159 .direction = USB_DIRECTION_IN, 160 .interface_class = USB_CLASS_DIAGNOSTIC, 161 .interface_subclass = 0x00, 162 .interface_protocol = 0x01, 163 .flags = 0 164 }; 165 static const usb_endpoint_description_t bulk_out_ep = { 166 .transfer_type = USB_TRANSFER_BULK, 167 .direction = USB_DIRECTION_OUT, 168 .interface_class = USB_CLASS_DIAGNOSTIC, 169 .interface_subclass = 0x00, 170 .interface_protocol = 0x01, 171 .flags = 0 172 }; 173 static const usb_endpoint_description_t isoch_in_ep = { 174 .transfer_type = USB_TRANSFER_ISOCHRONOUS, 175 .direction = USB_DIRECTION_IN, 176 .interface_class = USB_CLASS_DIAGNOSTIC, 177 .interface_subclass = 0x00, 178 .interface_protocol = 0x01, 179 .flags = 0 180 }; 181 static const usb_endpoint_description_t isoch_out_ep = { 141 static const usb_endpoint_description_t burst_intr_in_ep = { 142 .transfer_type = USB_TRANSFER_INTERRUPT, 143 .direction = USB_DIRECTION_IN, 144 .interface_class = USB_CLASS_DIAGNOSTIC, 145 .interface_subclass = 0x00, 146 .interface_protocol = 0x01, 147 .flags = 0 148 }; 149 static const usb_endpoint_description_t burst_intr_out_ep = { 150 .transfer_type = USB_TRANSFER_INTERRUPT, 151 .direction = USB_DIRECTION_OUT, 152 .interface_class = USB_CLASS_DIAGNOSTIC, 153 .interface_subclass = 0x00, 154 .interface_protocol = 0x01, 155 .flags = 0 156 }; 157 static const usb_endpoint_description_t burst_bulk_in_ep = { 158 .transfer_type = USB_TRANSFER_BULK, 159 .direction = USB_DIRECTION_IN, 160 .interface_class = USB_CLASS_DIAGNOSTIC, 161 .interface_subclass = 0x00, 162 .interface_protocol = 0x01, 163 .flags = 0 164 }; 165 static const usb_endpoint_description_t burst_bulk_out_ep = { 166 .transfer_type = USB_TRANSFER_BULK, 167 .direction = USB_DIRECTION_OUT, 168 .interface_class = USB_CLASS_DIAGNOSTIC, 169 .interface_subclass = 0x00, 170 .interface_protocol = 0x01, 171 .flags = 0 172 }; 173 static const usb_endpoint_description_t burst_isoch_in_ep = { 174 .transfer_type = USB_TRANSFER_ISOCHRONOUS, 175 .direction = USB_DIRECTION_IN, 176 .interface_class = USB_CLASS_DIAGNOSTIC, 177 .interface_subclass = 0x00, 178 .interface_protocol = 0x01, 179 .flags = 0 180 }; 181 static const usb_endpoint_description_t burst_isoch_out_ep = { 182 .transfer_type = USB_TRANSFER_ISOCHRONOUS, 183 .direction = USB_DIRECTION_OUT, 184 .interface_class = USB_CLASS_DIAGNOSTIC, 185 .interface_subclass = 0x00, 186 .interface_protocol = 0x01, 187 .flags = 0 188 }; 189 static const usb_endpoint_description_t data_intr_in_ep = { 190 .transfer_type = USB_TRANSFER_INTERRUPT, 191 .direction = USB_DIRECTION_IN, 192 .interface_class = USB_CLASS_DIAGNOSTIC, 193 .interface_subclass = 0x00, 194 .interface_protocol = 0x01, 195 .flags = 0 196 }; 197 static const usb_endpoint_description_t data_intr_out_ep = { 198 .transfer_type = USB_TRANSFER_INTERRUPT, 199 .direction = USB_DIRECTION_OUT, 200 .interface_class = USB_CLASS_DIAGNOSTIC, 201 .interface_subclass = 0x00, 202 .interface_protocol = 0x01, 203 .flags = 0 204 }; 205 static const usb_endpoint_description_t data_bulk_in_ep = { 206 .transfer_type = USB_TRANSFER_BULK, 207 .direction = USB_DIRECTION_IN, 208 .interface_class = USB_CLASS_DIAGNOSTIC, 209 .interface_subclass = 0x00, 210 .interface_protocol = 0x01, 211 .flags = 0 212 }; 213 static const usb_endpoint_description_t data_bulk_out_ep = { 214 .transfer_type = USB_TRANSFER_BULK, 215 .direction = USB_DIRECTION_OUT, 216 .interface_class = USB_CLASS_DIAGNOSTIC, 217 .interface_subclass = 0x00, 218 .interface_protocol = 0x01, 219 .flags = 0 220 }; 221 static const usb_endpoint_description_t data_isoch_in_ep = { 222 .transfer_type = USB_TRANSFER_ISOCHRONOUS, 223 .direction = USB_DIRECTION_IN, 224 .interface_class = USB_CLASS_DIAGNOSTIC, 225 .interface_subclass = 0x00, 226 .interface_protocol = 0x01, 227 .flags = 0 228 }; 229 static const usb_endpoint_description_t data_isoch_out_ep = { 182 230 .transfer_type = USB_TRANSFER_ISOCHRONOUS, 183 231 .direction = USB_DIRECTION_OUT, … … 189 237 190 238 static const usb_endpoint_description_t *diag_endpoints[] = { 191 [USBDIAG_EP_INTR_IN] = &intr_in_ep, 192 [USBDIAG_EP_INTR_OUT] = &intr_out_ep, 193 [USBDIAG_EP_BULK_IN] = &bulk_in_ep, 194 [USBDIAG_EP_BULK_OUT] = &bulk_out_ep, 195 [USBDIAG_EP_ISOCH_IN] = &isoch_in_ep, 196 [USBDIAG_EP_ISOCH_OUT] = &isoch_out_ep, 239 [USBDIAG_EP_BURST_INTR_IN] = &burst_intr_in_ep, 240 [USBDIAG_EP_BURST_INTR_OUT] = &burst_intr_out_ep, 241 [USBDIAG_EP_BURST_BULK_IN] = &burst_bulk_in_ep, 242 [USBDIAG_EP_BURST_BULK_OUT] = &burst_bulk_out_ep, 243 [USBDIAG_EP_BURST_ISOCH_IN] = &burst_isoch_in_ep, 244 [USBDIAG_EP_BURST_ISOCH_OUT] = &burst_isoch_out_ep, 245 [USBDIAG_EP_DATA_INTR_IN] = &data_intr_in_ep, 246 [USBDIAG_EP_DATA_INTR_OUT] = &data_intr_out_ep, 247 [USBDIAG_EP_DATA_BULK_IN] = &data_bulk_in_ep, 248 [USBDIAG_EP_DATA_BULK_OUT] = &data_bulk_out_ep, 249 [USBDIAG_EP_DATA_ISOCH_IN] = &data_isoch_in_ep, 250 [USBDIAG_EP_DATA_ISOCH_OUT] = &data_isoch_out_ep, 197 251 NULL 198 252 }; -
uspace/drv/bus/usb/usbdiag/tests.c
re67c50a r64ce0c1 44 44 #define NAME "usbdiag" 45 45 46 static int burst_in_test(usb_pipe_t *pipe, int cycles, size_t size, usbdiag_dur_t *duration) 46 static const uint32_t test_data_src = 0xDEADBEEF; 47 48 static int test_in(usb_pipe_t *pipe, const usbdiag_test_params_t *params, usbdiag_test_results_t *results) 47 49 { 48 50 if (!pipe) 49 51 return EBADMEM; 50 52 51 char *buffer = usb_pipe_alloc_buffer(pipe, size); 53 bool validate = params->validate_data; 54 size_t size = params->transfer_size; 55 if (!size) 56 size = pipe->desc.max_transfer_size; 57 58 const uint32_t test_data = uint32_host2usb(test_data_src); 59 if (validate && size % sizeof(test_data)) 60 return EINVAL; 61 62 size_t test_data_size = size / sizeof(test_data); 63 char *buffer = (char *) malloc(size); 52 64 if (!buffer) 53 65 return ENOMEM; … … 55 67 // TODO: Are we sure that no other test is running on this endpoint? 56 68 57 usb_log_info("Performing %s IN burst test.", usb_str_transfer_type(pipe->desc.transfer_type));69 usb_log_info("Performing %s IN test with duration %ld ms.", usb_str_transfer_type(pipe->desc.transfer_type), params->min_duration); 58 70 59 71 int rc = EOK; 60 struct timeval start_time; 72 uint32_t transfer_count = 0; 73 74 struct timeval start_time, final_time, stop_time; 61 75 gettimeofday(&start_time, NULL); 62 63 for (int i = 0; i < cycles; ++i) { 76 gettimeofday(&stop_time, NULL); 77 78 tv_add_diff(&stop_time, params->min_duration * 1000); 79 gettimeofday(&final_time, NULL); 80 81 while (!tv_gt(&final_time, &stop_time)) { 82 ++transfer_count; 83 64 84 // Read device's response. 65 85 size_t remaining = size; … … 83 103 if (rc) 84 104 break; 85 } 86 87 struct timeval final_time; 88 gettimeofday(&final_time, NULL); 105 106 if (validate) { 107 uint32_t *beef_buffer = (uint32_t *) buffer; 108 109 /* Check if the beef is really dead. */ 110 for (size_t i = 0; i < test_data_size; ++i) { 111 if (beef_buffer[i] != test_data) { 112 usb_log_error("Read of %s IN endpoint returned " 113 "invalid data at address %zu. [ 0x%X != 0x%X ]", 114 usb_str_transfer_type(pipe->desc.transfer_type), i * sizeof(test_data), beef_buffer[i], test_data); 115 rc = EINVAL; 116 } 117 } 118 119 if (rc) 120 break; 121 } 122 123 gettimeofday(&final_time, NULL); 124 } 125 89 126 usbdiag_dur_t in_duration = ((final_time.tv_usec - start_time.tv_usec) / 1000) + 90 127 ((final_time.tv_sec - start_time.tv_sec) * 1000); 91 128 92 usb_log_info("Burst test on %s IN endpoint completed in %lu ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration); 93 94 usb_pipe_free_buffer(pipe, buffer); 95 if (duration) 96 *duration = in_duration; 129 usb_log_info("Test on %s IN endpoint completed in %lu ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration); 130 131 results->act_duration = in_duration; 132 results->transfer_count = transfer_count; 133 results->transfer_size = size; 134 135 free(buffer); 97 136 98 137 return rc; 99 138 } 100 139 101 static int burst_out_test(usb_pipe_t *pipe, int cycles, size_t size, usbdiag_dur_t *duration)140 static int test_out(usb_pipe_t *pipe, const usbdiag_test_params_t *params, usbdiag_test_results_t *results) 102 141 { 103 142 if (!pipe) 104 143 return EBADMEM; 144 145 bool validate = params->validate_data; 146 size_t size = params->transfer_size; 147 if (!size) 148 size = pipe->desc.max_transfer_size; 149 150 const uint32_t test_data = uint32_host2usb(test_data_src); 151 152 if (validate && size % sizeof(test_data)) 153 return EINVAL; 105 154 106 155 char *buffer = usb_pipe_alloc_buffer(pipe, size); … … 108 157 return ENOMEM; 109 158 110 memset(buffer, 42, size); 159 if (validate) { 160 for (size_t i = 0; i < size; i += sizeof(test_data)) { 161 memcpy(buffer + i, &test_data, sizeof(test_data)); 162 } 163 } 111 164 112 165 // TODO: Are we sure that no other test is running on this endpoint? 113 166 114 usb_log_info("Performing %s OUT bursttest.", usb_str_transfer_type(pipe->desc.transfer_type));167 usb_log_info("Performing %s OUT test.", usb_str_transfer_type(pipe->desc.transfer_type)); 115 168 116 169 int rc = EOK; 117 struct timeval start_time; 170 uint32_t transfer_count = 0; 171 172 struct timeval start_time, final_time, stop_time; 118 173 gettimeofday(&start_time, NULL); 119 120 for (int i = 0; i < cycles; ++i) { 174 gettimeofday(&stop_time, NULL); 175 176 tv_add_diff(&stop_time, params->min_duration * 1000); 177 gettimeofday(&final_time, NULL); 178 179 while (!tv_gt(&final_time, &stop_time)) { 180 ++transfer_count; 181 121 182 // Write buffer to device. 122 183 if ((rc = usb_pipe_write_dma(pipe, buffer, size))) { … … 124 185 break; 125 186 } 126 } 127 128 struct timeval final_time;129 gettimeofday(&final_time, NULL); 187 188 gettimeofday(&final_time, NULL); 189 } 190 130 191 usbdiag_dur_t in_duration = ((final_time.tv_usec - start_time.tv_usec) / 1000) + 131 192 ((final_time.tv_sec - start_time.tv_sec) * 1000); 132 193 133 usb_log_info("Burst test on %s OUT endpoint completed in %ld ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration); 134 135 usb_pipe_free_buffer(pipe, buffer); 136 if (duration) 137 *duration = in_duration; 194 usb_log_info("Test on %s OUT endpoint completed in %ld ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration); 195 196 results->act_duration = in_duration; 197 results->transfer_count = transfer_count; 198 results->transfer_size = size; 199 200 free(buffer); 138 201 139 202 return rc; 140 203 } 141 204 142 static const uint32_t test_data_src = 0xDEADBEEF; 143 144 static int data_in_test(usb_pipe_t *pipe, int cycles, size_t size, usbdiag_dur_t *duration) 145 { 146 if (!pipe) 147 return EBADMEM; 148 149 const uint32_t test_data = uint32_host2usb(test_data_src); 150 151 if (size % sizeof(test_data)) 152 return EINVAL; 153 154 char *buffer = usb_pipe_alloc_buffer(pipe, size); 155 if (!buffer) 156 return ENOMEM; 157 158 // TODO: Are we sure that no other test is running on this endpoint? 159 160 usb_log_info("Performing %s IN data test.", usb_str_transfer_type(pipe->desc.transfer_type)); 161 162 int rc = EOK; 163 struct timeval start_time; 164 gettimeofday(&start_time, NULL); 165 166 for (int i = 0; i < cycles; ++i) { 167 // Read device's response. 168 size_t remaining = size; 169 size_t transferred; 170 171 while (remaining > 0) { 172 if ((rc = usb_pipe_read_dma(pipe, buffer + size - remaining, remaining, &transferred))) { 173 usb_log_error("Read of %s IN endpoint failed with error: %s", usb_str_transfer_type(pipe->desc.transfer_type), str_error(rc)); 174 break; 175 } 176 177 if (transferred > remaining) { 178 usb_log_error("Read of %s IN endpoint returned more data than expected.", usb_str_transfer_type(pipe->desc.transfer_type)); 179 rc = EINVAL; 180 break; 181 } 182 183 remaining -= transferred; 184 } 185 186 if (rc) 187 break; 188 189 for (size_t i = 0; i < size; i += sizeof(test_data)) { 190 if (*(uint32_t *)(buffer + i) != test_data) { 191 usb_log_error("Read of %s IN endpoint returned " 192 "invald data at address %zu.", 193 usb_str_transfer_type(pipe->desc.transfer_type), i); 194 rc = EINVAL; 195 break; 196 } 197 } 198 199 if (rc) 200 break; 201 } 202 203 struct timeval final_time; 204 gettimeofday(&final_time, NULL); 205 usbdiag_dur_t in_duration = ((final_time.tv_usec - start_time.tv_usec) / 1000) + 206 ((final_time.tv_sec - start_time.tv_sec) * 1000); 207 208 usb_log_info("Data test on %s IN endpoint completed in %lu ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration); 209 210 usb_pipe_free_buffer(pipe, buffer); 211 if (duration) 212 *duration = in_duration; 213 214 return rc; 215 } 216 217 static int data_out_test(usb_pipe_t *pipe, int cycles, size_t size, usbdiag_dur_t *duration) 218 { 219 if (!pipe) 220 return EBADMEM; 221 222 const uint32_t test_data = uint32_host2usb(test_data_src); 223 224 if (size % sizeof(test_data)) 225 return EINVAL; 226 227 char *buffer = usb_pipe_alloc_buffer(pipe, size); 228 if (!buffer) 229 return ENOMEM; 230 231 for (size_t i = 0; i < size; i += sizeof(test_data)) { 232 memcpy(buffer + i, &test_data, sizeof(test_data)); 233 } 234 235 // TODO: Are we sure that no other test is running on this endpoint? 236 237 usb_log_info("Performing %s OUT data test.", usb_str_transfer_type(pipe->desc.transfer_type)); 238 239 int rc = EOK; 240 struct timeval start_time; 241 gettimeofday(&start_time, NULL); 242 243 for (int i = 0; i < cycles; ++i) { 244 // Write buffer to device. 245 if ((rc = usb_pipe_write_dma(pipe, buffer, size))) { 246 usb_log_error("Write to %s OUT endpoint failed with error: %s", usb_str_transfer_type(pipe->desc.transfer_type), str_error(rc)); 247 break; 248 } 249 } 250 251 struct timeval final_time; 252 gettimeofday(&final_time, NULL); 253 usbdiag_dur_t in_duration = ((final_time.tv_usec - start_time.tv_usec) / 1000) + 254 ((final_time.tv_sec - start_time.tv_sec) * 1000); 255 256 usb_log_info("Data test on %s OUT endpoint completed in %ld ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration); 257 258 usb_pipe_free_buffer(pipe, buffer); 259 if (duration) 260 *duration = in_duration; 261 262 return rc; 263 } 264 265 int usbdiag_burst_test_intr_in(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 205 int usbdiag_dev_test_in(ddf_fun_t *fun, const usbdiag_test_params_t *params, usbdiag_test_results_t *results) 266 206 { 267 207 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); … … 269 209 return EBADMEM; 270 210 271 return burst_in_test(dev->intr_in, cycles, size, duration); 272 } 273 274 int usbdiag_burst_test_intr_out(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 211 usb_pipe_t *pipe; 212 213 switch (params->transfer_type) { 214 case USB_TRANSFER_INTERRUPT: 215 pipe = params->validate_data ? dev->data_intr_in : dev->burst_intr_in; 216 break; 217 case USB_TRANSFER_BULK: 218 pipe = params->validate_data ? dev->data_bulk_in : dev->burst_bulk_in; 219 break; 220 case USB_TRANSFER_ISOCHRONOUS: 221 pipe = params->validate_data ? dev->data_isoch_in : dev->burst_isoch_in; 222 break; 223 default: 224 return ENOTSUP; 225 } 226 227 return test_in(pipe, params, results); 228 } 229 230 int usbdiag_dev_test_out(ddf_fun_t *fun, const usbdiag_test_params_t *params, usbdiag_test_results_t *results) 275 231 { 276 232 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); … … 278 234 return EBADMEM; 279 235 280 return burst_out_test(dev->intr_out, cycles, size, duration); 281 } 282 283 int usbdiag_burst_test_bulk_in(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 284 { 285 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 286 if (!dev) 287 return EBADMEM; 288 289 return burst_in_test(dev->bulk_in, cycles, size, duration); 290 } 291 292 int usbdiag_burst_test_bulk_out(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 293 { 294 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 295 if (!dev) 296 return EBADMEM; 297 298 return burst_out_test(dev->bulk_out, cycles, size, duration); 299 } 300 301 int usbdiag_burst_test_isoch_in(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 302 { 303 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 304 if (!dev) 305 return EBADMEM; 306 307 return burst_in_test(dev->isoch_in, cycles, size, duration); 308 } 309 310 int usbdiag_burst_test_isoch_out(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 311 { 312 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 313 if (!dev) 314 return EBADMEM; 315 316 return burst_out_test(dev->isoch_out, cycles, size, duration); 317 } 318 319 int usbdiag_data_test_intr_in(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 320 { 321 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 322 if (!dev) 323 return EBADMEM; 324 325 return data_in_test(dev->intr_in, cycles, size, duration); 326 } 327 328 int usbdiag_data_test_intr_out(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 329 { 330 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 331 if (!dev) 332 return EBADMEM; 333 334 return data_out_test(dev->intr_out, cycles, size, duration); 335 } 336 337 int usbdiag_data_test_bulk_in(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 338 { 339 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 340 if (!dev) 341 return EBADMEM; 342 343 return data_in_test(dev->bulk_in, cycles, size, duration); 344 } 345 346 int usbdiag_data_test_bulk_out(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 347 { 348 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 349 if (!dev) 350 return EBADMEM; 351 352 return data_out_test(dev->bulk_out, cycles, size, duration); 353 } 354 355 int usbdiag_data_test_isoch_in(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 356 { 357 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 358 if (!dev) 359 return EBADMEM; 360 361 return data_in_test(dev->isoch_in, cycles, size, duration); 362 } 363 364 int usbdiag_data_test_isoch_out(ddf_fun_t *fun, int cycles, size_t size, usbdiag_dur_t *duration) 365 { 366 usbdiag_dev_t *dev = ddf_fun_to_usbdiag_dev(fun); 367 if (!dev) 368 return EBADMEM; 369 370 return data_out_test(dev->isoch_out, cycles, size, duration); 236 usb_pipe_t *pipe; 237 238 switch (params->transfer_type) { 239 case USB_TRANSFER_INTERRUPT: 240 pipe = params->validate_data ? dev->data_intr_out : dev->burst_intr_out; 241 break; 242 case USB_TRANSFER_BULK: 243 pipe = params->validate_data ? dev->data_bulk_out : dev->burst_bulk_out; 244 break; 245 case USB_TRANSFER_ISOCHRONOUS: 246 pipe = params->validate_data ? dev->data_isoch_out : dev->burst_isoch_out; 247 break; 248 default: 249 return ENOTSUP; 250 } 251 252 return test_out(pipe, params, results); 371 253 } 372 254 -
uspace/drv/bus/usb/usbdiag/tests.h
re67c50a r64ce0c1 39 39 #include <ddf/driver.h> 40 40 41 int usbdiag_burst_test_intr_in(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 42 int usbdiag_burst_test_intr_out(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 43 int usbdiag_burst_test_bulk_in(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 44 int usbdiag_burst_test_bulk_out(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 45 int usbdiag_burst_test_isoch_in(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 46 int usbdiag_burst_test_isoch_out(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 47 48 int usbdiag_data_test_intr_in(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 49 int usbdiag_data_test_intr_out(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 50 int usbdiag_data_test_bulk_in(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 51 int usbdiag_data_test_bulk_out(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 52 int usbdiag_data_test_isoch_in(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 53 int usbdiag_data_test_isoch_out(ddf_fun_t *, int, size_t, usbdiag_dur_t *); 41 int usbdiag_dev_test_in(ddf_fun_t *, const usbdiag_test_params_t *, usbdiag_test_results_t *); 42 int usbdiag_dev_test_out(ddf_fun_t *, const usbdiag_test_params_t *, usbdiag_test_results_t *); 54 43 55 44 #endif /* USBDIAG_TESTS_H_ */ -
uspace/drv/bus/usb/xhci/endpoint.c
re67c50a r64ce0c1 88 88 if (dev->speed >= USB_SPEED_SUPER) { 89 89 ep->packets_per_uframe = xhci_ep->max_burst * xhci_ep->mult; 90 ep->max_transfer_size = ep->max_packet_size * ep->packets_per_uframe; 90 if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS 91 || ep->transfer_type == USB_TRANSFER_INTERRUPT) { 92 ep->max_transfer_size = ep->max_packet_size * ep->packets_per_uframe; 93 } 94 else { 95 ep->max_transfer_size = 200 * PAGE_SIZE; 96 } 91 97 } 92 98 -
uspace/drv/bus/usb/xhci/transfers.c
re67c50a r64ce0c1 126 126 } 127 127 128 static int calculate_trb_count(xhci_transfer_t *transfer) 129 { 130 const size_t size = transfer->batch.buffer_size; 131 return (size + PAGE_SIZE - 1 )/ PAGE_SIZE; 132 } 133 134 static void trb_set_buffer(xhci_transfer_t *transfer, xhci_trb_t *trb, 135 size_t i, size_t total, size_t *remaining) 136 { 137 const uintptr_t ptr = dma_buffer_phys(&transfer->hc_buffer, 138 transfer->hc_buffer.virt + i * PAGE_SIZE); 139 140 trb->parameter = host2xhci(64, ptr); 141 TRB_CTRL_SET_TD_SIZE(*trb, max(31, total - i - 1)); 142 if (*remaining > PAGE_SIZE) { 143 TRB_CTRL_SET_XFER_LEN(*trb, PAGE_SIZE); 144 *remaining -= PAGE_SIZE; 145 } 146 else { 147 TRB_CTRL_SET_XFER_LEN(*trb, *remaining); 148 *remaining = 0; 149 } 150 } 151 128 152 static int schedule_control(xhci_hc_t* hc, xhci_transfer_t* transfer) 129 153 { … … 133 157 usb_device_request_setup_packet_t* setup = &batch->setup.packet; 134 158 135 xhci_trb_t trbs[3]; 136 int trbs_used = 0; 137 138 xhci_trb_t *trb_setup = trbs + trbs_used++; 159 size_t buffer_count = 0; 160 if (setup->length > 0) { 161 buffer_count = calculate_trb_count(transfer); 162 } 163 164 xhci_trb_t trbs[buffer_count + 2]; 165 166 xhci_trb_t *trb_setup = trbs; 139 167 xhci_trb_clean(trb_setup); 140 168 … … 155 183 156 184 /* Data stage */ 157 xhci_trb_t *trb_data = NULL;158 185 if (setup->length > 0) { 159 trb_data = trbs + trbs_used++;160 xhci_trb_clean(trb_data);161 162 trb_data->parameter = host2xhci(64, transfer->hc_buffer.phys);163 164 // data size (sent for OUT, or buffer size)165 TRB_CTRL_SET_XFER_LEN(*trb_data, batch->buffer_size);166 // FIXME: TD size 4.11.2.4167 TRB_CTRL_SET_TD_SIZE(*trb_data, 1);168 169 // Some more fields here, no idea what they mean170 TRB_CTRL_SET_TRB_TYPE(*trb_data, XHCI_TRB_TYPE_DATA_STAGE);171 172 186 int stage_dir = REQUEST_TYPE_IS_DEVICE_TO_HOST(setup->request_type) 173 187 ? STAGE_IN : STAGE_OUT; 174 TRB_CTRL_SET_DIR(*trb_data, stage_dir); 188 size_t remaining = transfer->batch.buffer_size; 189 190 for (size_t i = 0; i < buffer_count; ++i) { 191 xhci_trb_clean(&trbs[i + 1]); 192 trb_set_buffer(transfer, &trbs[i + 1], i, buffer_count, &remaining); 193 194 TRB_CTRL_SET_DIR(trbs[i + 1], stage_dir); 195 TRB_CTRL_SET_TRB_TYPE(trbs[i + 1], XHCI_TRB_TYPE_DATA_STAGE); 196 197 if (i == buffer_count - 1) break; 198 199 /* Set the chain bit as this is not the last TRB */ 200 TRB_CTRL_SET_CHAIN(trbs[i], 1); 201 } 175 202 } 176 203 177 204 /* Status stage */ 178 xhci_trb_t *trb_status = trbs + trbs_used++;205 xhci_trb_t *trb_status = trbs + buffer_count + 1; 179 206 xhci_trb_clean(trb_status); 180 207 … … 192 219 193 220 return xhci_trb_ring_enqueue_multiple(get_ring(transfer), trbs, 194 trbs_used, &transfer->interrupt_trb_phys);221 buffer_count + 2, &transfer->interrupt_trb_phys); 195 222 } 196 223 197 224 static int schedule_bulk(xhci_hc_t* hc, xhci_transfer_t *transfer) 198 225 { 199 xhci_trb_t trb;200 xhci_trb_clean(&trb);201 trb.parameter = host2xhci(64, transfer->hc_buffer.phys);202 203 // data size (sent for OUT, or buffer size)204 TRB_CTRL_SET_XFER_LEN(trb, transfer->batch.buffer_size);205 206 226 /* The stream-enabled endpoints need to chain ED trb */ 207 227 xhci_endpoint_t *ep = xhci_endpoint_get(transfer->batch.ep); 208 228 if (!ep->primary_stream_data_size) { 209 // FIXME: TD size 4.11.2.4 210 TRB_CTRL_SET_TD_SIZE(trb, 1); 211 212 // we want an interrupt after this td is done 213 TRB_CTRL_SET_IOC(trb, 1); 214 TRB_CTRL_SET_TRB_TYPE(trb, XHCI_TRB_TYPE_NORMAL); 229 const size_t buffer_count = calculate_trb_count(transfer); 230 xhci_trb_t trbs[buffer_count]; 231 size_t remaining = transfer->batch.buffer_size; 232 233 for (size_t i = 0; i < buffer_count; ++i) { 234 xhci_trb_clean(&trbs[i]); 235 trb_set_buffer(transfer, &trbs[i], i, buffer_count, &remaining); 236 TRB_CTRL_SET_TRB_TYPE(trbs[i], XHCI_TRB_TYPE_NORMAL); 237 238 if (i == buffer_count - 1) break; 239 240 /* Set the chain bit as this is not the last TRB */ 241 TRB_CTRL_SET_CHAIN(trbs[i], 1); 242 } 243 /* Set the interrupt bit for last TRB */ 244 TRB_CTRL_SET_IOC(trbs[buffer_count - 1], 1); 215 245 216 246 xhci_trb_ring_t* ring = get_ring(transfer); 217 return xhci_trb_ring_enqueue(ring, &trb, &transfer->interrupt_trb_phys); 247 return xhci_trb_ring_enqueue_multiple(ring, &trbs[0], buffer_count, 248 &transfer->interrupt_trb_phys); 218 249 } 219 250 else { 220 TRB_CTRL_SET_TD_SIZE(trb, 2);221 TRB_CTRL_SET_TRB_TYPE(trb, XHCI_TRB_TYPE_NORMAL);222 TRB_CTRL_SET_CHAIN(trb, 1);223 TRB_CTRL_SET_ENT(trb, 1);224 225 251 xhci_trb_ring_t* ring = get_ring(transfer); 226 252 if (!ring) { … … 228 254 } 229 255 230 int err = xhci_trb_ring_enqueue(ring, &trb, &transfer->interrupt_trb_phys); 231 232 if (err) { 233 return err; 234 } 235 236 xhci_trb_clean(&trb); 237 trb.parameter = host2xhci(64, (uintptr_t) transfer); 238 TRB_CTRL_SET_TRB_TYPE(trb, XHCI_TRB_TYPE_EVENT_DATA); 239 TRB_CTRL_SET_IOC(trb, 1); 240 241 return xhci_trb_ring_enqueue(ring, &trb, &transfer->interrupt_trb_phys); 256 const size_t buffer_count = calculate_trb_count(transfer); 257 xhci_trb_t trbs[buffer_count + 1]; 258 size_t remaining = transfer->batch.buffer_size; 259 260 for (size_t i = 0; i < buffer_count; ++i) { 261 xhci_trb_clean(&trbs[i]); 262 trb_set_buffer(transfer, &trbs[i], i, buffer_count + 1, &remaining); 263 TRB_CTRL_SET_TRB_TYPE(trbs[i], XHCI_TRB_TYPE_NORMAL); 264 TRB_CTRL_SET_CHAIN(trbs[i], 1); 265 } 266 TRB_CTRL_SET_ENT(trbs[buffer_count - 1], 1); 267 268 xhci_trb_clean(&trbs[buffer_count]); 269 trbs[buffer_count].parameter = host2xhci(64, (uintptr_t) transfer); 270 TRB_CTRL_SET_TRB_TYPE(trbs[buffer_count], XHCI_TRB_TYPE_EVENT_DATA); 271 TRB_CTRL_SET_IOC(trbs[buffer_count], 1); 272 273 return xhci_trb_ring_enqueue_multiple(ring, &trbs[0], buffer_count + 1, 274 &transfer->interrupt_trb_phys); 242 275 } 243 276 } … … 245 278 static int schedule_interrupt(xhci_hc_t* hc, xhci_transfer_t* transfer) 246 279 { 247 xhci_trb_t trb; 248 xhci_trb_clean(&trb); 249 trb.parameter = host2xhci(64, transfer->hc_buffer.phys); 250 251 // data size (sent for OUT, or buffer size) 252 TRB_CTRL_SET_XFER_LEN(trb, transfer->batch.buffer_size); 253 // FIXME: TD size 4.11.2.4 254 TRB_CTRL_SET_TD_SIZE(trb, 1); 255 256 // we want an interrupt after this td is done 257 TRB_CTRL_SET_IOC(trb, 1); 258 259 TRB_CTRL_SET_TRB_TYPE(trb, XHCI_TRB_TYPE_NORMAL); 280 const size_t buffer_count = calculate_trb_count(transfer); 281 xhci_trb_t trbs[buffer_count]; 282 size_t remaining = transfer->batch.buffer_size; 283 284 for (size_t i = 0; i < buffer_count; ++i) { 285 xhci_trb_clean(&trbs[i]); 286 trb_set_buffer(transfer, &trbs[i], i, buffer_count, &remaining); 287 TRB_CTRL_SET_TRB_TYPE(trbs[i], XHCI_TRB_TYPE_NORMAL); 288 289 if (i == buffer_count - 1) break; 290 291 /* Set the chain bit as this is not the last TRB */ 292 TRB_CTRL_SET_CHAIN(trbs[i], 1); 293 } 294 /* Set the interrupt bit for last TRB */ 295 TRB_CTRL_SET_IOC(trbs[buffer_count - 1], 1); 260 296 261 297 xhci_trb_ring_t* ring = get_ring(transfer); 262 263 return xhci_trb_ring_enqueue(ring, &trb,&transfer->interrupt_trb_phys);298 return xhci_trb_ring_enqueue_multiple(ring, &trbs[0], buffer_count, 299 &transfer->interrupt_trb_phys); 264 300 } 265 301
Note:
See TracChangeset
for help on using the changeset viewer.