Changes in / [00db345a:7ac73a4] in mainline
- Location:
- uspace
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
r00db345a r7ac73a4 47 47 static int batch_schedule(batch_t *instance); 48 48 49 static void batch_control(batch_t *instance, 50 usb_packet_id data_stage, usb_packet_id status_stage); 51 static void batch_data(batch_t *instance, usb_packet_id pid); 49 static void batch_control( 50 batch_t *instance, int data_stage, int status_stage); 52 51 static void batch_call_in(batch_t *instance); 53 52 static void batch_call_out(batch_t *instance); … … 84 83 } 85 84 86 instance->tds = malloc32(sizeof(t d_t) * instance->packets);85 instance->tds = malloc32(sizeof(transfer_descriptor_t) * instance->packets); 87 86 if (instance->tds == NULL) { 88 87 usb_log_error("Failed to allocate transfer descriptors.\n"); … … 91 90 return NULL; 92 91 } 93 bzero(instance->tds, sizeof(t d_t) * instance->packets);92 bzero(instance->tds, sizeof(transfer_descriptor_t) * instance->packets); 94 93 95 94 const size_t transport_size = max_packet_size * instance->packets; … … 152 151 size_t i = 0; 153 152 for (;i < instance->packets; ++i) { 154 if (t d_is_active(&instance->tds[i])) {153 if (transfer_descriptor_is_active(&instance->tds[i])) { 155 154 return false; 156 155 } 157 158 instance->error = td_status(&instance->tds[i]); 156 instance->error = transfer_descriptor_status(&instance->tds[i]); 159 157 if (instance->error != EOK) { 158 if (i > 0) 159 instance->transfered_size -= instance->setup_size; 160 160 usb_log_debug("Batch(%p) found error TD(%d):%x.\n", 161 instance, i, instance->tds[i].status); 162 if (i > 0) 163 goto substract_ret; 161 instance, i, instance->tds[i].status); 164 162 return true; 165 163 } 166 167 instance->transfered_size += td_act_size(&instance->tds[i]); 168 if (td_is_short(&instance->tds[i])) 169 goto substract_ret; 170 } 171 substract_ret: 164 instance->transfered_size += 165 transfer_descriptor_actual_size(&instance->tds[i]); 166 } 172 167 instance->transfered_size -= instance->setup_size; 173 168 return true; … … 197 192 { 198 193 assert(instance); 199 batch_data(instance, USB_PID_IN); 194 195 const bool low_speed = instance->speed == USB_SPEED_LOW; 196 int toggle = 1; 197 size_t i = 0; 198 for (;i < instance->packets; ++i) { 199 char *data = 200 instance->transport_buffer + (i * instance->max_packet_size); 201 transfer_descriptor_t *next = (i + 1) < instance->packets ? 202 &instance->tds[i + 1] : NULL; 203 toggle = 1 - toggle; 204 205 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 206 instance->max_packet_size, toggle, false, low_speed, 207 instance->target, USB_PID_IN, data, next); 208 } 209 210 instance->tds[i - 1].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 211 200 212 instance->next_step = batch_call_in_and_dispose; 201 213 usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance); … … 207 219 assert(instance); 208 220 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 209 batch_data(instance, USB_PID_OUT); 221 222 const bool low_speed = instance->speed == USB_SPEED_LOW; 223 int toggle = 1; 224 size_t i = 0; 225 for (;i < instance->packets; ++i) { 226 char *data = 227 instance->transport_buffer + (i * instance->max_packet_size); 228 transfer_descriptor_t *next = (i + 1) < instance->packets ? 229 &instance->tds[i + 1] : NULL; 230 toggle = 1 - toggle; 231 232 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 233 instance->max_packet_size, toggle++, false, low_speed, 234 instance->target, USB_PID_OUT, data, next); 235 } 236 237 instance->tds[i - 1].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 238 210 239 instance->next_step = batch_call_out_and_dispose; 211 240 usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance); … … 213 242 } 214 243 /*----------------------------------------------------------------------------*/ 215 void batch_bulk_in(batch_t *instance) 216 { 217 assert(instance); 218 batch_data(instance, USB_PID_IN); 219 instance->next_step = batch_call_in_and_dispose; 220 usb_log_debug("Batch(%p) BULK IN initialized.\n", instance); 221 batch_schedule(instance); 222 } 223 /*----------------------------------------------------------------------------*/ 224 void batch_bulk_out(batch_t *instance) 225 { 226 assert(instance); 227 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 228 batch_data(instance, USB_PID_OUT); 229 instance->next_step = batch_call_out_and_dispose; 230 usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance); 231 batch_schedule(instance); 232 } 233 /*----------------------------------------------------------------------------*/ 234 static void batch_data(batch_t *instance, usb_packet_id pid) 235 { 236 assert(instance); 237 const bool low_speed = instance->speed == USB_SPEED_LOW; 238 int toggle = 1; 239 240 size_t packet = 0; 241 size_t remain_size = instance->buffer_size; 242 while (remain_size > 0) { 243 char *data = 244 instance->transport_buffer + instance->buffer_size 245 - remain_size; 246 247 toggle = 1 - toggle; 248 249 const size_t packet_size = 250 (instance->max_packet_size > remain_size) ? 251 remain_size : instance->max_packet_size; 252 253 td_init(&instance->tds[packet], 254 DEFAULT_ERROR_COUNT, packet_size, toggle, false, low_speed, 255 instance->target, pid, data, 256 &instance->tds[packet + 1]); 257 258 ++packet; 259 assert(packet <= instance->packets); 260 assert(packet_size <= remain_size); 261 remain_size -= packet_size; 262 } 263 264 instance->tds[packet - 1].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 265 instance->tds[packet - 1].next = 0 | LINK_POINTER_TERMINATE_FLAG; 266 } 267 /*----------------------------------------------------------------------------*/ 268 static void batch_control(batch_t *instance, 269 usb_packet_id data_stage, usb_packet_id status_stage) 244 static void batch_control( 245 batch_t *instance, int data_stage, int status_stage) 270 246 { 271 247 assert(instance); … … 274 250 int toggle = 0; 275 251 /* setup stage */ 276 t d_init(instance->tds, DEFAULT_ERROR_COUNT,252 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 277 253 instance->setup_size, toggle, false, low_speed, instance->target, 278 254 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); … … 292 268 remain_size : instance->max_packet_size; 293 269 294 t d_init(&instance->tds[packet],270 transfer_descriptor_init(&instance->tds[packet], 295 271 DEFAULT_ERROR_COUNT, packet_size, toggle, false, low_speed, 296 272 instance->target, data_stage, data, … … 305 281 /* status stage */ 306 282 assert(packet == instance->packets - 1); 307 t d_init(&instance->tds[packet], DEFAULT_ERROR_COUNT,283 transfer_descriptor_init(&instance->tds[packet], DEFAULT_ERROR_COUNT, 308 284 0, 1, false, low_speed, instance->target, status_stage, NULL, NULL); 309 285 -
uspace/drv/uhci-hcd/batch.h
r00db345a r7ac73a4 65 65 ddf_fun_t *fun; 66 66 queue_head_t *qh; 67 t d_t *tds;67 transfer_descriptor_t *tds; 68 68 void (*next_step)(struct batch*); 69 69 } batch_t; … … 86 86 void batch_interrupt_out(batch_t *instance); 87 87 88 void batch_bulk_in(batch_t *instance); 88 /* DEPRECATED FUNCTIONS NEEDED BY THE OLD API */ 89 void batch_control_setup_old(batch_t *instance); 89 90 90 void batch_bulk_out(batch_t *instance); 91 void batch_control_write_data_old(batch_t *instance); 92 93 void batch_control_read_data_old(batch_t *instance); 94 95 void batch_control_write_status_old(batch_t *instance); 96 97 void batch_control_read_status_old(batch_t *instance); 91 98 #endif 92 99 /** -
uspace/drv/uhci-hcd/iface.c
r00db345a r7ac73a4 140 140 } 141 141 /*----------------------------------------------------------------------------*/ 142 static int bulk_out(ddf_fun_t *fun, usb_target_t target,143 size_t max_packet_size, void *data, size_t size,144 usbhc_iface_transfer_out_callback_t callback, void *arg)145 {146 assert(fun);147 uhci_t *hc = fun_to_uhci(fun);148 assert(hc);149 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);150 151 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",152 target.address, target.endpoint, size, max_packet_size);153 154 batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,155 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);156 if (!batch)157 return ENOMEM;158 batch_bulk_out(batch);159 return EOK;160 }161 /*----------------------------------------------------------------------------*/162 static int bulk_in(ddf_fun_t *fun, usb_target_t target,163 size_t max_packet_size, void *data, size_t size,164 usbhc_iface_transfer_in_callback_t callback, void *arg)165 {166 assert(fun);167 uhci_t *hc = fun_to_uhci(fun);168 assert(hc);169 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);170 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",171 target.address, target.endpoint, size, max_packet_size);172 173 batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,174 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);175 if (!batch)176 return ENOMEM;177 batch_bulk_in(batch);178 return EOK;179 }180 /*----------------------------------------------------------------------------*/181 142 static int control_write(ddf_fun_t *fun, usb_target_t target, 182 143 size_t max_packet_size, … … 220 181 return EOK; 221 182 } 183 184 222 185 /*----------------------------------------------------------------------------*/ 223 186 usbhc_iface_t uhci_iface = { … … 231 194 .interrupt_in = interrupt_in, 232 195 233 .bulk_in = bulk_in,234 .bulk_out = bulk_out,235 236 196 .control_read = control_read, 237 197 .control_write = control_write, -
uspace/drv/uhci-hcd/uhci.c
r00db345a r7ac73a4 336 336 uhci_interrupt(instance, status); 337 337 pio_write_16(&instance->registers->usbsts, 0x1f); 338 async_usleep(UHCI_CLEANER_TIMEOUT );338 async_usleep(UHCI_CLEANER_TIMEOUT * 5); 339 339 } 340 340 return EOK; -
uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c
r00db345a r7ac73a4 38 38 #include "utils/malloc32.h" 39 39 40 void td_init(td_t *instance, int err_count, size_t size, bool toggle, bool iso, 41 bool low_speed, usb_target_t target, usb_packet_id pid, void *buffer, td_t *next) 40 void transfer_descriptor_init(transfer_descriptor_t *instance, 41 int error_count, size_t size, bool toggle, bool isochronous, bool low_speed, 42 usb_target_t target, int pid, void *buffer, transfer_descriptor_t *next) 42 43 { 43 44 assert(instance); 44 assert(size < 1024);45 assert((pid == USB_PID_SETUP) || (pid == USB_PID_IN) || (pid == USB_PID_OUT));46 45 47 46 instance->next = 0 … … 50 49 51 50 instance->status = 0 52 | ((err_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS) 53 | (low_speed ? TD_STATUS_LOW_SPEED_FLAG : 0) 54 | (iso ? TD_STATUS_ISOCHRONOUS_FLAG : 0) 55 | TD_STATUS_ERROR_ACTIVE; 51 | ((error_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS) 52 | (low_speed ? TD_STATUS_LOW_SPEED_FLAG : 0) 53 | TD_STATUS_ERROR_ACTIVE; 56 54 57 if (pid == USB_PID_IN && !iso) { 58 instance->status |= TD_STATUS_SPD_FLAG; 59 } 60 55 assert(size < 1024); 61 56 instance->device = 0 62 63 64 65 66 57 | (((size - 1) & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS) 58 | (toggle ? TD_DEVICE_DATA_TOGGLE_ONE_FLAG : 0) 59 | ((target.address & TD_DEVICE_ADDRESS_MASK) << TD_DEVICE_ADDRESS_POS) 60 | ((target.endpoint & TD_DEVICE_ENDPOINT_MASK) << TD_DEVICE_ENDPOINT_POS) 61 | ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS); 67 62 68 63 instance->buffer_ptr = 0; … … 73 68 74 69 usb_log_debug2("Created TD: %X:%X:%X:%X(%p).\n", 75 76 70 instance->next, instance->status, instance->device, 71 instance->buffer_ptr, buffer); 77 72 } 78 73 /*----------------------------------------------------------------------------*/ 79 int t d_status(td_t *instance)74 int transfer_descriptor_status(transfer_descriptor_t *instance) 80 75 { 81 76 assert(instance); -
uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h
r00db345a r7ac73a4 88 88 * we don't use it anyway 89 89 */ 90 } __attribute__((packed)) t d_t;90 } __attribute__((packed)) transfer_descriptor_t; 91 91 92 92 93 void t d_init(td_t *instance, int error_count, size_t size, bool toggle, bool iso,94 bool low_speed, usb_target_t target, usb_packet_id pid, void *buffer,95 td_t *next);93 void transfer_descriptor_init(transfer_descriptor_t *instance, 94 int error_count, size_t size, bool toggle, bool isochronous, bool low_speed, 95 usb_target_t target, int pid, void *buffer, transfer_descriptor_t * next); 96 96 97 int t d_status(td_t *instance);97 int transfer_descriptor_status(transfer_descriptor_t *instance); 98 98 99 static inline size_t td_act_size(td_t *instance) 99 static inline size_t transfer_descriptor_actual_size( 100 transfer_descriptor_t *instance) 100 101 { 101 102 assert(instance); 102 103 return 103 ((instance->status >> TD_STATUS_ACTLEN_POS) + 1) 104 & TD_STATUS_ACTLEN_MASK; 104 ((instance->status >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK; 105 105 } 106 106 107 static inline bool td_is_short(td_t *instance) 108 { 109 const size_t act_size = td_act_size(instance); 110 const size_t max_size = 111 ((instance->device >> TD_DEVICE_MAXLEN_POS) + 1) 112 & TD_DEVICE_MAXLEN_MASK; 113 return 114 (instance->status | TD_STATUS_SPD_FLAG) && act_size < max_size; 115 } 116 117 static inline bool td_is_active(td_t *instance) 107 static inline bool transfer_descriptor_is_active( 108 transfer_descriptor_t *instance) 118 109 { 119 110 assert(instance); -
uspace/drv/usbhub/usbhub.c
r00db345a r7ac73a4 233 233 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 234 234 usb_endpoint_pipe_start_session(&result->endpoints.control); 235 opResult = usb_request_set_configuration(&result->endpoints.control, 1);236 assert(opResult == EOK);237 238 235 opResult = usb_request_get_descriptor(&result->endpoints.control, 239 236 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, … … 246 243 dprintf(USB_LOG_LEVEL_ERROR, "failed when receiving hub descriptor, badcode = %d",opResult); 247 244 free(serialized_descriptor); 248 free(result); 249 return NULL; 245 return result; 250 246 } 251 247 dprintf(USB_LOG_LEVEL_DEBUG2, "deserializing descriptor"); … … 253 249 if(descriptor==NULL){ 254 250 dprintf(USB_LOG_LEVEL_WARNING, "could not deserialize descriptor "); 255 free(result);256 return NULL;251 result->port_count = 1;///\TODO this code is only for debug!!! 252 return result; 257 253 } 258 254 … … 290 286 291 287 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 292 if(!hub_info){293 return EINTR;294 }295 288 296 289 int opResult; … … 301 294 opResult = usb_hub_process_configuration_descriptors(hub_info); 302 295 if(opResult != EOK){ 303 dprintf(USB_LOG_LEVEL_ERROR,"could not get con figuration descriptors, %d",296 dprintf(USB_LOG_LEVEL_ERROR,"could not get condiguration descriptors, %d", 304 297 opResult); 305 298 return opResult; -
uspace/drv/usbmouse/main.c
r00db345a r7ac73a4 74 74 int main(int argc, char *argv[]) 75 75 { 76 usb_log_enable(USB_LOG_LEVEL_DEBUG 2, NAME);76 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 77 77 78 78 return ddf_driver_main(&mouse_driver); -
uspace/drv/usbmouse/mouse.c
r00db345a r7ac73a4 37 37 #include <usb/debug.h> 38 38 #include <errno.h> 39 #include <str_error.h>40 39 #include <ipc/mouse.h> 41 40 … … 65 64 66 65 size_t actual_size; 67 int rc;68 66 69 /* 70 * Error checking note: 71 * - failure when starting a session is considered 72 * temporary (e.g. out of phones, next try might succeed) 73 * - failure of transfer considered fatal (probably the 74 * device was unplugged) 75 * - session closing not checked (shall not fail anyway) 76 */ 67 /* FIXME: check for errors. */ 68 usb_endpoint_pipe_start_session(&mouse->poll_pipe); 77 69 78 rc = usb_endpoint_pipe_start_session(&mouse->poll_pipe); 79 if (rc != EOK) { 80 usb_log_warning("Failed to start session, will try again: %s.\n", 81 str_error(rc)); 82 continue; 83 } 84 85 rc = usb_endpoint_pipe_read(&mouse->poll_pipe, 70 usb_endpoint_pipe_read(&mouse->poll_pipe, 86 71 buffer, buffer_size, &actual_size); 87 72 88 73 usb_endpoint_pipe_end_session(&mouse->poll_pipe); 89 90 if (rc != EOK) {91 usb_log_error("Failed reading mouse input: %s.\n",92 str_error(rc));93 break;94 }95 96 usb_log_debug2("got buffer: %s.\n",97 usb_debug_str_buffer(buffer, buffer_size, 0));98 74 99 75 uint8_t butt = buffer[0]; … … 139 115 } 140 116 141 /*142 * Device was probably unplugged.143 * Hang-up the phone to the console.144 * FIXME: release allocated memory.145 */146 async_hangup(mouse->console_phone);147 mouse->console_phone = -1;148 149 usb_log_error("Mouse polling fibril terminated.\n");150 151 117 return EOK; 152 118 } -
uspace/lib/usb/include/usb/debug.h
r00db345a r7ac73a4 79 79 usb_log_printf(USB_LOG_LEVEL_DEBUG2, format, ##__VA_ARGS__) 80 80 81 const char *usb_debug_str_buffer(uint8_t *, size_t, size_t);82 81 83 82 -
uspace/lib/usb/src/debug.c
r00db345a r7ac73a4 252 252 } 253 253 254 255 #define REMAINDER_STR_FMT " (%zu)..."256 /* string + terminator + number width (enough for 4GB)*/257 #define REMAINDER_STR_LEN (5 + 1 + 10)258 #define BUFFER_DUMP_GROUP_SIZE 4259 #define BUFFER_DUMP_LEN 240 /* Ought to be enough for everybody ;-). */260 static fibril_local char buffer_dump[BUFFER_DUMP_LEN];261 262 /** Dump buffer into string.263 *264 * The function dumps given buffer into hexadecimal format and stores it265 * in a static fibril local string.266 * That means that you do not have to deallocate the string (actually, you267 * can not do that) and you do not have to save it agains concurrent268 * calls to it.269 * The only limitation is that each call rewrites the buffer again.270 * Thus, it is necessary to copy the buffer elsewhere (that includes printing271 * to screen or writing to file).272 * Since this function is expected to be used for debugging prints only,273 * that is not a big limitation.274 *275 * @warning You cannot use this function twice in the same printf276 * (see detailed explanation).277 *278 * @param buffer Buffer to be printed (can be NULL).279 * @param size Size of the buffer in bytes (can be zero).280 * @param dumped_size How many bytes to actually dump (zero means all).281 * @return Dumped buffer as a static (but fibril local) string.282 */283 const char *usb_debug_str_buffer(uint8_t *buffer, size_t size,284 size_t dumped_size)285 {286 /*287 * Remove previous string (that might also reveal double usage of288 * this function).289 */290 bzero(buffer_dump, BUFFER_DUMP_LEN);291 292 if (buffer == NULL) {293 return "(null)";294 }295 if (size == 0) {296 return "(empty)";297 }298 if ((dumped_size == 0) || (dumped_size > size)) {299 dumped_size = size;300 }301 302 /* How many bytes are available in the output buffer. */303 size_t buffer_remaining_size = BUFFER_DUMP_LEN - 1 - REMAINDER_STR_LEN;304 char *it = buffer_dump;305 306 size_t index = 0;307 308 while (index < size) {309 /* Determine space before the number. */310 const char *space_before;311 if (index == 0) {312 space_before = "";313 } else if ((index % BUFFER_DUMP_GROUP_SIZE) == 0) {314 space_before = " ";315 } else {316 space_before = " ";317 }318 319 /*320 * Add the byte as a hexadecimal number plus the space.321 * We do it into temporary buffer to ensure that always322 * the whole byte is printed.323 */324 int val = buffer[index];325 char current_byte[16];326 int printed = snprintf(current_byte, 16,327 "%s%02x", space_before, val);328 if (printed < 0) {329 break;330 }331 332 if ((size_t) printed > buffer_remaining_size) {333 break;334 }335 336 /* We can safely add 1, because space for end 0 is reserved. */337 str_append(it, buffer_remaining_size + 1, current_byte);338 339 buffer_remaining_size -= printed;340 /* Point at the terminator 0. */341 it += printed;342 index++;343 344 if (index >= dumped_size) {345 break;346 }347 }348 349 /* Add how many bytes were not printed. */350 if (index < size) {351 snprintf(it, REMAINDER_STR_LEN,352 REMAINDER_STR_FMT, size - index);353 }354 355 return buffer_dump;356 }357 358 359 254 /** 360 255 * @}
Note:
See TracChangeset
for help on using the changeset viewer.