Changeset 4fec9ee in mainline for uspace/drv
- Timestamp:
- 2011-03-18T16:17:24Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 00b13408
- Parents:
- 4f66cc7b (diff), d8e61b0d (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
- Files:
-
- 14 edited
-
uhci-hcd/batch.c (modified) (3 diffs)
-
uhci-hcd/batch.h (modified) (1 diff)
-
uhci-hcd/transfer_list.c (modified) (2 diffs)
-
uhci-hcd/transfer_list.h (modified) (1 diff)
-
uhci-hcd/uhci_hc.c (modified) (4 diffs)
-
uhci-hcd/uhci_hc.h (modified) (2 diffs)
-
uhci-hcd/uhci_struct/transfer_descriptor.c (modified) (1 diff)
-
usbhid/hiddev.c (modified) (4 diffs)
-
usbhid/hiddev.h (modified) (1 diff)
-
usbhid/kbddev.c (modified) (13 diffs)
-
usbhid/kbddev.h (modified) (1 diff)
-
usbhub/port_status.h (modified) (1 diff)
-
usbhub/usbhub.c (modified) (38 diffs)
-
usbhub/usbhub.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
r4f66cc7b r4fec9ee 153 153 } 154 154 /*----------------------------------------------------------------------------*/ 155 /** Mark batch as failed and continue with next step. 156 * 157 * @param[in] instance Batch structure to use. 158 * 159 */ 160 void batch_abort(batch_t *instance) 161 { 162 assert(instance); 163 instance->error = EIO; 164 instance->next_step(instance); 165 } 166 /*----------------------------------------------------------------------------*/ 155 167 /** Check batch TDs for activity. 156 168 * … … 251 263 assert(instance); 252 264 /* We are data out, we are supposed to provide data */ 253 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 265 memcpy(instance->transport_buffer, instance->buffer, 266 instance->buffer_size); 254 267 batch_data(instance, USB_PID_OUT); 255 268 instance->next_step = batch_call_out_and_dispose; … … 281 294 assert(instance); 282 295 /* We are data out, we are supposed to provide data */ 283 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 296 memcpy(instance->transport_buffer, instance->buffer, 297 instance->buffer_size); 284 298 batch_data(instance, USB_PID_OUT); 285 299 instance->next_step = batch_call_out_and_dispose; -
uspace/drv/uhci-hcd/batch.h
r4f66cc7b r4fec9ee 69 69 } batch_t; 70 70 71 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 72 usb_transfer_type_t transfer_type, size_t max_packet_size, 73 usb_speed_t speed, char *buffer, size_t size, 74 char *setup_buffer, size_t setup_size, 71 batch_t * batch_get( 72 ddf_fun_t *fun, 73 usb_target_t target, 74 usb_transfer_type_t transfer_type, 75 size_t max_packet_size, 76 usb_speed_t speed, 77 char *buffer, 78 size_t size, 79 char *setup_buffer, 80 size_t setup_size, 75 81 usbhc_iface_transfer_in_callback_t func_in, 76 usbhc_iface_transfer_out_callback_t func_out, void *arg, 82 usbhc_iface_transfer_out_callback_t func_out, 83 void *arg, 77 84 device_keeper_t *manager 78 85 ); 79 86 80 87 void batch_dispose(batch_t *instance); 88 89 void batch_abort(batch_t *instance); 81 90 82 91 bool batch_is_complete(batch_t *instance); -
uspace/drv/uhci-hcd/transfer_list.c
r4f66cc7b r4fec9ee 129 129 } 130 130 /*----------------------------------------------------------------------------*/ 131 /** Check list for finished batches. 132 * 133 * @param[in] instance List to use. 134 * @return Error code 135 * 136 * Creates a local list of finished batches and calls next_step on each and 137 * every one. This is safer because next_step may theoretically access 138 * this transfer list leading to the deadlock if its done inline. 139 */ 140 void transfer_list_remove_finished(transfer_list_t *instance) 141 { 142 assert(instance); 143 144 LIST_INITIALIZE(done); 145 146 fibril_mutex_lock(&instance->guard); 147 link_t *current = instance->batch_list.next; 148 while (current != &instance->batch_list) { 149 link_t *next = current->next; 150 batch_t *batch = list_get_instance(current, batch_t, link); 151 152 if (batch_is_complete(batch)) { 153 /* Save for post-processing */ 154 transfer_list_remove_batch(instance, batch); 155 list_append(current, &done); 156 } 157 current = next; 158 } 159 fibril_mutex_unlock(&instance->guard); 160 161 while (!list_empty(&done)) { 162 link_t *item = done.next; 163 list_remove(item); 164 batch_t *batch = list_get_instance(item, batch_t, link); 165 batch->next_step(batch); 166 } 167 } 168 /*----------------------------------------------------------------------------*/ 169 /** Walk the list and abort all batches. 170 * 171 * @param[in] instance List to use. 172 */ 173 void transfer_list_abort_all(transfer_list_t *instance) 174 { 175 fibril_mutex_lock(&instance->guard); 176 while (list_empty(&instance->batch_list)) { 177 link_t *current = instance->batch_list.next; 178 batch_t *batch = list_get_instance(current, batch_t, link); 179 transfer_list_remove_batch(instance, batch); 180 batch_abort(batch); 181 } 182 fibril_mutex_unlock(&instance->guard); 183 } 184 /*----------------------------------------------------------------------------*/ 131 185 /** Remove a transfer batch from the list and queue. 132 186 * … … 163 217 batch, pos, instance->name, batch->qh->next); 164 218 } 165 /*----------------------------------------------------------------------------*/166 /** Check list for finished batches.167 *168 * @param[in] instance List to use.169 * @return Error code170 *171 * Creates a local list of finished batches and calls next_step on each and172 * every one. This is safer because next_step may theoretically access173 * this transfer list leading to the deadlock if its done inline.174 */175 void transfer_list_remove_finished(transfer_list_t *instance)176 {177 assert(instance);178 179 LIST_INITIALIZE(done);180 181 fibril_mutex_lock(&instance->guard);182 link_t *current = instance->batch_list.next;183 while (current != &instance->batch_list) {184 link_t *next = current->next;185 batch_t *batch = list_get_instance(current, batch_t, link);186 187 if (batch_is_complete(batch)) {188 /* Save for post-processing */189 transfer_list_remove_batch(instance, batch);190 list_append(current, &done);191 }192 current = next;193 }194 fibril_mutex_unlock(&instance->guard);195 196 while (!list_empty(&done)) {197 link_t *item = done.next;198 list_remove(item);199 batch_t *batch = list_get_instance(item, batch_t, link);200 batch->next_step(batch);201 }202 }203 219 /** 204 220 * @} -
uspace/drv/uhci-hcd/transfer_list.h
r4f66cc7b r4fec9ee 66 66 void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next); 67 67 68 void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch); 69 68 70 void transfer_list_remove_finished(transfer_list_t *instance); 69 71 70 void transfer_list_a dd_batch(transfer_list_t *instance, batch_t *batch);72 void transfer_list_abort_all(transfer_list_t *instance); 71 73 #endif 72 74 /** -
uspace/drv/uhci-hcd/uhci_hc.c
r4f66cc7b r4fec9ee 97 97 98 98 instance->hw_interrupts = interrupts; 99 instance->hw_failures = 0; 100 99 101 /* Setup UHCI function. */ 100 102 instance->ddf_instance = fun; … … 149 151 while ((pio_read_16(®isters->usbcmd) & UHCI_CMD_HCRESET) != 0); 150 152 151 /* Set framelist pointer */ 153 /* Set frame to exactly 1ms */ 154 pio_write_8(®isters->sofmod, 64); 155 156 /* Set frame list pointer */ 152 157 const uint32_t pa = addr_to_phys(instance->frame_list); 153 158 pio_write_32(®isters->flbaseadd, pa); … … 347 352 { 348 353 assert(instance); 349 /* TODO: Check interrupt cause here*/354 /* TODO: Resume interrupts are not supported */ 350 355 /* Lower 2 bits are transaction error and transaction complete */ 351 356 if (status & 0x3) { … … 354 359 transfer_list_remove_finished(&instance->transfers_control_full); 355 360 transfer_list_remove_finished(&instance->transfers_bulk_full); 361 } 362 /* bits 4 and 5 indicate hc error */ 363 if (status & 0x18) { 364 usb_log_error("UHCI hardware failure!.\n"); 365 ++instance->hw_failures; 366 transfer_list_abort_all(&instance->transfers_interrupt); 367 transfer_list_abort_all(&instance->transfers_control_slow); 368 transfer_list_abort_all(&instance->transfers_control_full); 369 transfer_list_abort_all(&instance->transfers_bulk_full); 370 371 if (instance->hw_failures < UHCI_ALLOWED_HW_FAIL) { 372 /* reinitialize hw, this triggers virtual disconnect*/ 373 uhci_hc_init_hw(instance); 374 } else { 375 usb_log_fatal("Too many UHCI hardware failures!.\n"); 376 uhci_hc_fini(instance); 377 } 356 378 } 357 379 } -
uspace/drv/uhci-hcd/uhci_hc.h
r4f66cc7b r4fec9ee 80 80 #define UHCI_CLEANER_TIMEOUT 10000 81 81 #define UHCI_DEBUGER_TIMEOUT 5000000 82 #define UHCI_ALLOWED_HW_FAIL 5 82 83 83 84 typedef struct uhci_hc { … … 100 101 fid_t debug_checker; 101 102 bool hw_interrupts; 103 unsigned hw_failures; 102 104 103 105 ddf_fun_t *ddf_instance; -
uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c
r4f66cc7b r4fec9ee 159 159 (s & TD_STATUS_ERROR_BIT_STUFF) ? " BIT_STUFF," : "", 160 160 (s & TD_STATUS_ERROR_RESERVED) ? " RESERVED," : "", 161 (s >> TD_STATUS_ACTLEN_POS) & TD_STATUS_ACTLEN_MASK161 td_act_size(instance) 162 162 ); 163 163 } -
uspace/drv/usbhid/hiddev.c
r4f66cc7b r4fec9ee 158 158 } 159 159 160 hid_dev->report_desc_size = length; 161 160 162 usb_log_debug("Done.\n"); 161 163 … … 262 264 263 265 if (rc != EOK) { 264 usb_log_warning("Problem with parsing Report descriptor: %s.\n", 265 str_error(rc)); 266 return rc; 267 } 266 usb_log_warning("Problem with getting Report descriptor: %s.\n", 267 str_error(rc)); 268 return rc; 269 } 270 271 rc = usb_hid_parse_report_descriptor(hid_dev->parser, 272 hid_dev->report_desc, hid_dev->report_desc_size); 273 if (rc != EOK) { 274 usb_log_warning("Problem parsing Report descriptor: %s.\n", 275 str_error(rc)); 276 return rc; 277 } 278 279 usb_hid_descriptor_print(hid_dev->parser); 268 280 269 281 return EOK; … … 289 301 290 302 memset(dev, 0, sizeof(usbhid_dev_t)); 303 304 dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof( 305 usb_hid_report_parser_t))); 306 if (dev->parser == NULL) { 307 usb_log_fatal("No memory!\n"); 308 free(dev); 309 return NULL; 310 } 291 311 292 312 dev->initialized = 0; … … 399 419 400 420 /* 421 * Initialize the report parser. 422 */ 423 rc = usb_hid_parser_init(hid_dev->parser); 424 if (rc != EOK) { 425 usb_log_error("Failed to initialize report parser.\n"); 426 return rc; 427 } 428 429 /* 401 430 * Get descriptors, parse descriptors and save endpoints. 402 431 */ -
uspace/drv/usbhid/hiddev.h
r4f66cc7b r4fec9ee 75 75 /** Report descriptor. */ 76 76 uint8_t *report_desc; 77 78 size_t report_desc_size; 79 77 80 /** HID Report parser. */ 78 81 usb_hid_report_parser_t *parser; -
uspace/drv/usbhid/kbddev.c
r4f66cc7b r4fec9ee 51 51 #include <usb/classes/hidparser.h> 52 52 #include <usb/classes/classes.h> 53 #include <usb/classes/hidut.h> 53 54 54 55 #include "kbddev.h" … … 122 123 KC_RALT, /* USB_HID_MOD_RALT */ 123 124 0, /* USB_HID_MOD_RGUI */ 125 }; 126 127 typedef enum usbhid_lock_code { 128 USBHID_LOCK_NUM = 0x53, 129 USBHID_LOCK_CAPS = 0x39, 130 USBHID_LOCK_SCROLL = 0x47, 131 USBHID_LOCK_COUNT = 3 132 } usbhid_lock_code; 133 134 static const usbhid_lock_code usbhid_lock_codes[USBHID_LOCK_COUNT] = { 135 USBHID_LOCK_NUM, 136 USBHID_LOCK_CAPS, 137 USBHID_LOCK_SCROLL 124 138 }; 125 139 … … 346 360 * @sa usbhid_kbd_push_ev() 347 361 */ 348 static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev, 349 uint8_t modifiers) 350 { 351 /* 352 * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK 353 * both as modifiers and as keys with their own scancodes??? 354 * 355 * modifiers should be sent as normal keys to usbhid_parse_scancode()!! 356 * so maybe it would be better if I received it from report parser in 357 * that way 358 */ 359 360 int i; 361 for (i = 0; i < USB_HID_MOD_COUNT; ++i) { 362 if ((modifiers & usb_hid_modifiers_consts[i]) && 363 !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) { 364 // modifier pressed 365 if (usbhid_modifiers_keycodes[i] != 0) { 366 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, 367 usbhid_modifiers_keycodes[i]); 368 } 369 } else if (!(modifiers & usb_hid_modifiers_consts[i]) && 370 (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) { 371 // modifier released 372 if (usbhid_modifiers_keycodes[i] != 0) { 373 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, 374 usbhid_modifiers_keycodes[i]); 375 } 376 } // no change 377 } 378 379 kbd_dev->modifiers = modifiers; 362 //static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev, 363 // const uint8_t *key_codes, size_t count) 364 //{ 365 // /* 366 // * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK 367 // * both as modifiers and as keyUSB_HID_LOCK_COUNTs with their own scancodes??? 368 // * 369 // * modifiers should be sent as normal keys to usbhid_parse_scancode()!! 370 // * so maybe it would be better if I received it from report parser in 371 // * that way 372 // */ 373 374 // int i; 375 // for (i = 0; i < count; ++i) { 376 // if ((modifiers & usb_hid_modifiers_consts[i]) && 377 // !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) { 378 // // modifier pressed 379 // if (usbhid_modifiers_keycodes[i] != 0) { 380 // usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, 381 // usbhid_modifiers_keycodes[i]); 382 // } 383 // } else if (!(modifiers & usb_hid_modifiers_consts[i]) && 384 // (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) { 385 // // modifier released 386 // if (usbhid_modifiers_keycodes[i] != 0) { 387 // usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, 388 // usbhid_modifiers_keycodes[i]); 389 // } 390 // } // no change 391 // } 392 393 // kbd_dev->modifiers = modifiers; 394 //} 395 396 /*----------------------------------------------------------------------------*/ 397 398 static inline int usbhid_kbd_is_lock(unsigned int key_code) 399 { 400 return (key_code == KC_NUM_LOCK 401 || key_code == KC_SCROLL_LOCK 402 || key_code == KC_CAPS_LOCK); 380 403 } 381 404 … … 404 427 /* 405 428 * First of all, check if the kbd have reported phantom state. 429 * 430 * TODO: this must be changed as we don't know which keys are modifiers 431 * and which are regular keys. 406 432 */ 407 433 i = 0; … … 434 460 // not found, i.e. the key was released 435 461 key = usbhid_parse_scancode(kbd_dev->keys[j]); 436 usbhid_kbd_repeat_stop(kbd_dev, key); 462 if (!usbhid_kbd_is_lock(key)) { 463 usbhid_kbd_repeat_stop(kbd_dev, key); 464 } 437 465 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key); 438 466 usb_log_debug2("Key released: %d\n", key); … … 458 486 key_codes[i]); 459 487 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); 460 usbhid_kbd_repeat_start(kbd_dev, key); 488 if (!usbhid_kbd_is_lock(key)) { 489 usbhid_kbd_repeat_start(kbd_dev, key); 490 } 461 491 } else { 462 492 // found, nothing happens … … 502 532 503 533 usb_log_debug("Got keys from parser: %s\n", 504 usb_debug_str_buffer(key_codes, kbd_dev->key_count, 0));534 usb_debug_str_buffer(key_codes, count, 0)); 505 535 506 536 if (count != kbd_dev->key_count) { … … 510 540 } 511 541 512 usbhid_kbd_check_modifier_changes(kbd_dev, modifiers);542 ///usbhid_kbd_check_modifier_changes(kbd_dev, key_codes, count); 513 543 usbhid_kbd_check_key_changes(kbd_dev, key_codes, count); 514 544 } … … 535 565 uint8_t *buffer, size_t actual_size) 536 566 { 567 assert(kbd_dev->initialized); 568 assert(kbd_dev->hid_dev->parser != NULL); 569 537 570 usb_hid_report_in_callbacks_t *callbacks = 538 571 (usb_hid_report_in_callbacks_t *)malloc( … … 541 574 callbacks->keyboard = usbhid_kbd_process_keycodes; 542 575 543 usb_log_debug("Calling usb_hid_ boot_keyboard_input_report() with "576 usb_log_debug("Calling usb_hid_parse_report() with " 544 577 "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0)); 545 578 546 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 547 callbacks, kbd_dev); 579 // int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 580 // callbacks, kbd_dev); 581 int rc = usb_hid_parse_report(kbd_dev->hid_dev->parser, buffer, 582 actual_size, callbacks, kbd_dev); 548 583 549 584 if (rc != EOK) { … … 614 649 free((*kbd_dev)->repeat_mtx); 615 650 } 616 651 617 652 free(*kbd_dev); 618 653 *kbd_dev = NULL; … … 674 709 675 710 // save the size of the report (boot protocol report by default) 676 kbd_dev->key_count = BOOTP_REPORT_SIZE; 711 // kbd_dev->key_count = BOOTP_REPORT_SIZE; 712 713 usb_hid_report_path_t path; 714 path.usage_page = USB_HIDUT_PAGE_KEYBOARD; 715 kbd_dev->key_count = usb_hid_report_input_length( 716 kbd_dev->hid_dev->parser, &path); 717 718 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 719 677 720 kbd_dev->keys = (uint8_t *)calloc( 678 721 kbd_dev->key_count, sizeof(uint8_t)); … … 709 752 assert(kbd_dev->hid_dev != NULL); 710 753 assert(kbd_dev->hid_dev->initialized); 711 usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);754 //usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT); 712 755 713 756 usbhid_kbd_set_led(kbd_dev); -
uspace/drv/usbhid/kbddev.h
r4f66cc7b r4fec9ee 42 42 43 43 #include <usb/classes/hid.h> 44 #include <usb/classes/hidparser.h> 44 45 #include <ddf/driver.h> 45 46 #include <usb/pipes.h> -
uspace/drv/usbhub/port_status.h
r4f66cc7b r4fec9ee 270 270 } 271 271 272 //low speed device attached 273 static inline bool usb_port_high_speed(usb_port_status_t * status){ 274 return usb_port_get_bit(status,10); 275 } 276 277 static inline void usb_port_set_high_speed(usb_port_status_t * status,bool high_speed){ 278 usb_port_set_bit(status,10,high_speed); 279 } 280 281 static inline usb_speed_t usb_port_speed(usb_port_status_t * status){ 282 if(usb_port_low_speed(status)) 283 return USB_SPEED_LOW; 284 if(usb_port_high_speed(status)) 285 return USB_SPEED_HIGH; 286 return USB_SPEED_FULL; 287 } 288 272 289 273 290 //connect change -
uspace/drv/usbhub/usbhub.c
r4f66cc7b r4fec9ee 78 78 async_usleep(1000 * 1000 );/// \TODO proper number once 79 79 } 80 dprintf(USB_LOG_LEVEL_ERROR,81 "something in ctrl loop went wrong, errno %d",errorCode); 80 usb_log_error("something in ctrl loop went wrong, errno %d",errorCode); 81 82 82 return 0; 83 83 } … … 104 104 hub->device); 105 105 if(opResult != EOK){ 106 dprintf(USB_LOG_LEVEL_ERROR, 107 "could not initialize connection to hc, errno %d",opResult); 106 usb_log_error("could not initialize connection to hc, errno %d",opResult); 108 107 return opResult; 109 108 } … … 112 111 hub->device); 113 112 if(opResult != EOK){ 114 dprintf(USB_LOG_LEVEL_ERROR,115 "could not initialize connection to device, errno %d",opResult);113 usb_log_error("could not initialize connection to device, errno %d", 114 opResult); 116 115 return opResult; 117 116 } … … 120 119 &hub->device_connection); 121 120 if(opResult != EOK){ 122 dprintf(USB_LOG_LEVEL_ERROR,123 "could not initialize connection to device endpoint, errno %d",opResult);121 usb_log_error("could not initialize connection to device endpoint, errno %d", 122 opResult); 124 123 return opResult; 125 124 } … … 127 126 opResult = usb_endpoint_pipe_probe_default_control(&hub->endpoints.control); 128 127 if (opResult != EOK) { 129 dprintf(USB_LOG_LEVEL_ERROR,"failed probing endpoint 0, %d", opResult);128 usb_log_error("failed probing endpoint 0, %d", opResult); 130 129 return opResult; 131 130 } … … 151 150 &std_descriptor); 152 151 if(opResult!=EOK){ 153 dprintf(USB_LOG_LEVEL_ERROR,"could not get device descriptor, %d",opResult);154 return opResult; 155 } 156 dprintf(USB_LOG_LEVEL_INFO,"hub has %d configurations",152 usb_log_error("could not get device descriptor, %d",opResult); 153 return opResult; 154 } 155 usb_log_info("hub has %d configurations", 157 156 std_descriptor.configuration_count); 158 157 if(std_descriptor.configuration_count<1){ 159 dprintf(USB_LOG_LEVEL_ERROR,"THERE ARE NO CONFIGURATIONS AVAILABLE");158 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE"); 160 159 //shouldn`t I return? 161 160 } … … 184 183 return opResult; 185 184 } 186 dprintf(USB_LOG_LEVEL_DEBUG,"\tused configuration %d",185 usb_log_debug("\tused configuration %d", 187 186 config_descriptor->configuration_number); 188 187 … … 200 199 &hub->device_connection); 201 200 if (opResult != EOK) { 202 dprintf(USB_LOG_LEVEL_ERROR, 203 "Failed to initialize status change pipe: %s", 201 usb_log_error("Failed to initialize status change pipe: %s", 204 202 str_error(opResult)); 205 203 return opResult; 206 204 } 207 205 if (!endpoint_mapping[0].present) { 208 dprintf(USB_LOG_LEVEL_ERROR,"Not accepting device, " \206 usb_log_error("Not accepting device, " \ 209 207 "cannot understand what is happenning"); 210 208 return EREFUSED; … … 235 233 result->port_count = -1; 236 234 result->device = device; 235 result->is_default_address_used = false; 237 236 238 237 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); … … 240 239 241 240 // get hub descriptor 242 dprintf(USB_LOG_LEVEL_DEBUG,"creating serialized descripton");241 usb_log_debug("creating serialized descripton"); 243 242 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 244 243 usb_hub_descriptor_t * descriptor; 245 dprintf(USB_LOG_LEVEL_DEBUG,"starting control transaction");244 usb_log_debug("starting control transaction"); 246 245 usb_endpoint_pipe_start_session(&result->endpoints.control); 247 246 opResult = usb_request_set_configuration(&result->endpoints.control, 1); … … 256 255 257 256 if (opResult != EOK) { 258 dprintf(USB_LOG_LEVEL_ERROR, "failed when receiving hub descriptor, badcode = %d",opResult); 257 usb_log_error("failed when receiving hub descriptor, badcode = %d", 258 opResult); 259 259 free(serialized_descriptor); 260 260 free(result); 261 261 return NULL; 262 262 } 263 dprintf(USB_LOG_LEVEL_DEBUG2,"deserializing descriptor");263 usb_log_debug2("deserializing descriptor"); 264 264 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 265 265 if(descriptor==NULL){ 266 dprintf(USB_LOG_LEVEL_WARNING,"could not deserialize descriptor ");266 usb_log_warning("could not deserialize descriptor "); 267 267 free(result); 268 268 return NULL; 269 269 } 270 270 271 dprintf(USB_LOG_LEVEL_INFO,"setting port count to %d",descriptor->ports_count);271 usb_log_info("setting port count to %d",descriptor->ports_count); 272 272 result->port_count = descriptor->ports_count; 273 273 result->attached_devs = (usb_hc_attached_device_t*) … … 278 278 result->attached_devs[i].address=0; 279 279 } 280 dprintf(USB_LOG_LEVEL_DEBUG2,"freeing data");280 usb_log_debug2("freeing data"); 281 281 free(serialized_descriptor); 282 282 free(descriptor->devices_removable); … … 285 285 //finish 286 286 287 dprintf(USB_LOG_LEVEL_INFO,"hub info created");287 usb_log_info("hub info created"); 288 288 289 289 return result; … … 296 296 */ 297 297 int usb_add_hub_device(ddf_dev_t *dev) { 298 dprintf(USB_LOG_LEVEL_INFO,"add_hub_device(handle=%d)", (int) dev->handle);298 usb_log_info("add_hub_device(handle=%d)", (int) dev->handle); 299 299 300 300 //dev->ops = &hub_device_ops; … … 313 313 opResult = usb_hub_process_configuration_descriptors(hub_info); 314 314 if(opResult != EOK){ 315 dprintf(USB_LOG_LEVEL_ERROR,"could not get configuration descriptors, %d",315 usb_log_error("could not get configuration descriptors, %d", 316 316 opResult); 317 317 return opResult; … … 324 324 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 325 325 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 326 dprintf(USB_LOG_LEVEL_INFO,"powering port %d",port);326 usb_log_info("powering port %d",port); 327 327 if (opResult != EOK) { 328 dprintf(USB_LOG_LEVEL_WARNING,"something went wrong when setting hub`s %dth port", port);328 usb_log_warning("something went wrong when setting hub`s %dth port", port); 329 329 } 330 330 } … … 337 337 usb_lst_append(&usb_hub_list, hub_info); 338 338 fibril_mutex_unlock(&usb_hub_list_lock); 339 dprintf(USB_LOG_LEVEL_DEBUG,"hub info added to list");340 341 dprintf(USB_LOG_LEVEL_DEBUG,"adding to ddf");339 usb_log_debug("hub info added to list"); 340 341 usb_log_debug("adding to ddf"); 342 342 ddf_fun_t *hub_fun = ddf_fun_create(dev, fun_exposed, "hub"); 343 343 assert(hub_fun != NULL); … … 351 351 fid_t fid = fibril_create(usb_hub_control_loop, hub_info); 352 352 if (fid == 0) { 353 dprintf(USB_LOG_LEVEL_ERROR, 354 ": failed to start monitoring fibril for new hub"); 353 usb_log_error("failed to start monitoring fibril for new hub"); 355 354 return ENOMEM; 356 355 } 357 356 fibril_add_ready(fid); 358 357 359 dprintf(USB_LOG_LEVEL_DEBUG,"hub fibril created");358 usb_log_debug("hub fibril created"); 360 359 //(void)hub_info; 361 360 //usb_hub_check_hub_changes(); 362 361 363 dprintf(USB_LOG_LEVEL_INFO,"hub dev added");362 usb_log_info("hub dev added"); 364 363 //address is lost... 365 dprintf(USB_LOG_LEVEL_DEBUG,"\taddress %d, has %d ports ",364 usb_log_debug("\taddress %d, has %d ports ", 366 365 //hub_info->endpoints.control., 367 366 hub_info->port_count); … … 379 378 380 379 /** 380 * release default address used by given hub 381 * 382 * Also unsets hub->is_default_address_used. Convenience wrapper function. 383 * @note hub->connection MUST be open for communication 384 * @param hub hub representation 385 * @return error code 386 */ 387 static int usb_hub_release_default_address(usb_hub_info_t * hub){ 388 int opResult = usb_hc_release_default_address(&hub->connection); 389 if(opResult!=EOK){ 390 usb_log_error("could not release default address, errno %d",opResult); 391 return opResult; 392 } 393 hub->is_default_address_used = false; 394 return EOK; 395 } 396 397 /** 381 398 * Reset the port with new device and reserve the default address. 382 399 * @param hc … … 385 402 */ 386 403 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 387 bool isLowSpeed) { 404 usb_speed_t speed) { 405 //if this hub already uses default address, it cannot request it once more 406 if(hub->is_default_address_used) return; 407 388 408 usb_device_request_setup_packet_t request; 389 409 int opResult; 390 dprintf(USB_LOG_LEVEL_INFO,"some connection changed");410 usb_log_info("some connection changed"); 391 411 assert(hub->endpoints.control.hc_phone); 392 412 //get default address 393 usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL;394 413 opResult = usb_hc_reserve_default_address(&hub->connection, speed); 395 414 396 415 if (opResult != EOK) { 397 dprintf(USB_LOG_LEVEL_WARNING, 398 "cannot assign default address, it is probably used %d",opResult); 399 return; 400 } 416 usb_log_warning("cannot assign default address, it is probably used %d", 417 opResult); 418 return; 419 } 420 hub->is_default_address_used = true; 401 421 //reset port 402 422 usb_hub_set_reset_port_request(&request, port); … … 407 427 ); 408 428 if (opResult != EOK) { 409 dprintf(USB_LOG_LEVEL_ERROR, 410 "something went wrong when reseting a port %d",opResult); 429 usb_log_error("something went wrong when reseting a port %d",opResult); 411 430 //usb_hub_release_default_address(hc); 412 usb_h c_release_default_address(&hub->connection);431 usb_hub_release_default_address(hub); 413 432 } 414 433 } … … 424 443 425 444 int opResult; 426 dprintf(USB_LOG_LEVEL_INFO,"finalizing add device");445 usb_log_info("finalizing add device"); 427 446 opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 428 447 port, USB_HUB_FEATURE_C_PORT_RESET); 429 448 430 449 if (opResult != EOK) { 431 dprintf(USB_LOG_LEVEL_ERROR,"failed to clear port reset feature");432 usb_h c_release_default_address(&hub->connection);450 usb_log_error("failed to clear port reset feature"); 451 usb_hub_release_default_address(hub); 433 452 return; 434 453 } … … 454 473 ); 455 474 if (new_device_address < 0) { 456 dprintf(USB_LOG_LEVEL_ERROR,"failed to get free USB address");475 usb_log_error("failed to get free USB address"); 457 476 opResult = new_device_address; 458 usb_h c_release_default_address(&hub->connection);459 return; 460 } 461 dprintf(USB_LOG_LEVEL_INFO,"setting new address %d",new_device_address);477 usb_hub_release_default_address(hub); 478 return; 479 } 480 usb_log_info("setting new address %d",new_device_address); 462 481 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 463 482 // new_device_address); … … 466 485 usb_endpoint_pipe_end_session(&new_device_pipe); 467 486 if (opResult != EOK) { 468 dprintf(USB_LOG_LEVEL_ERROR, 469 "could not set address for new device %d",opResult); 470 usb_hc_release_default_address(&hub->connection); 487 usb_log_error("could not set address for new device %d",opResult); 488 usb_hub_release_default_address(hub); 471 489 return; 472 490 } … … 474 492 475 493 //opResult = usb_hub_release_default_address(hc); 476 opResult = usb_h c_release_default_address(&hub->connection);494 opResult = usb_hub_release_default_address(hub); 477 495 if(opResult!=EOK){ 478 496 return; … … 486 504 487 505 if (opResult != EOK) { 488 dprintf(USB_LOG_LEVEL_ERROR, 489 "could not start driver for new device %d",opResult); 506 usb_log_error("could not start driver for new device %d",opResult); 490 507 return; 491 508 } … … 498 515 &hub->attached_devs[port]); 499 516 if (opResult != EOK) { 500 dprintf(USB_LOG_LEVEL_ERROR, 501 "could not assign address of device in hcd %d",opResult); 502 return; 503 } 504 dprintf(USB_LOG_LEVEL_INFO, "new device address %d, handle %zu", 517 usb_log_error("could not assign address of device in hcd %d",opResult); 518 return; 519 } 520 usb_log_info("new device address %d, handle %zu", 505 521 new_device_address, child_handle); 506 522 … … 533 549 */ 534 550 }else{ 535 dprintf(USB_LOG_LEVEL_WARNING,"this is strange, disconnected device had no address");551 usb_log_warning("this is strange, disconnected device had no address"); 536 552 //device was disconnected before it`s port was reset - return default address 537 //usb_drv_release_default_address(hc); 538 usb_hc_release_default_address(&hub->connection); 539 } 540 } 541 542 543 /** 544 *Process over current condition on port. 553 usb_hub_release_default_address(hub); 554 } 555 } 556 557 558 /** 559 * Process over current condition on port. 545 560 * 546 561 * Turn off the power on the port. … … 555 570 port, USB_HUB_FEATURE_PORT_POWER); 556 571 if(opResult!=EOK){ 557 dprintf(USB_LOG_LEVEL_ERROR,"cannot power off port %d; %d",572 usb_log_error("cannot power off port %d; %d", 558 573 port, opResult); 559 574 } … … 568 583 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 569 584 uint16_t port) { 570 dprintf(USB_LOG_LEVEL_DEBUG,"interrupt at port %d", port);585 usb_log_debug("interrupt at port %d", port); 571 586 //determine type of change 572 587 usb_endpoint_pipe_t *pipe = &hub->endpoints.control; … … 587 602 ); 588 603 if (opResult != EOK) { 589 dprintf(USB_LOG_LEVEL_ERROR,"could not get port status");604 usb_log_error("could not get port status"); 590 605 return; 591 606 } 592 607 if (rcvd_size != sizeof (usb_port_status_t)) { 593 dprintf(USB_LOG_LEVEL_ERROR,"received status has incorrect size");608 usb_log_error("received status has incorrect size"); 594 609 return; 595 610 } … … 600 615 // TODO: check opResult 601 616 if (usb_port_dev_connected(&status)) { 602 dprintf(USB_LOG_LEVEL_INFO,"some connection changed");603 usb_hub_init_add_device(hub, port, usb_port_ low_speed(&status));617 usb_log_info("some connection changed"); 618 usb_hub_init_add_device(hub, port, usb_port_speed(&status)); 604 619 } else { 605 620 usb_hub_removed_device(hub, port); … … 612 627 usb_hub_over_current(hub,port); 613 628 }else{ 614 dprintf(USB_LOG_LEVEL_INFO,615 "over current condition was auto-resolved on port %d",port);629 usb_log_info("over current condition was auto-resolved on port %d", 630 port); 616 631 } 617 632 } 618 633 //port reset 619 634 if (usb_port_reset_completed(&status)) { 620 dprintf(USB_LOG_LEVEL_INFO,"port reset complete");635 usb_log_info("port reset complete"); 621 636 if (usb_port_enabled(&status)) { 622 637 usb_hub_finalize_add_device(hub, port, usb_port_low_speed(&status)); 623 638 } else { 624 dprintf(USB_LOG_LEVEL_WARNING,"port reset, but port still not enabled");639 usb_log_warning("port reset, but port still not enabled"); 625 640 } 626 641 } … … 631 646 usb_port_set_dev_connected(&status, false); 632 647 if (status>>16) { 633 dprintf(USB_LOG_LEVEL_INFO, "there was some unsupported change on port %d: %X",port,status); 634 635 } 636 /// \TODO handle other changes 648 usb_log_info("there was some unsupported change on port %d: %X", 649 port,status); 650 651 } 652 /// \TODO handle other changes - is there any? 637 653 } 638 654 … … 647 663 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 648 664 if(opResult != EOK){ 649 dprintf(USB_LOG_LEVEL_ERROR,650 "could not initialize communication for hub; %d",opResult);665 usb_log_error("could not initialize communication for hub; %d", 666 opResult); 651 667 return opResult; 652 668 } … … 669 685 if (opResult != EOK) { 670 686 free(change_bitmap); 671 dprintf(USB_LOG_LEVEL_WARNING,"something went wrong while getting status of hub");687 usb_log_warning("something went wrong while getting status of hub"); 672 688 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 673 689 return opResult; … … 676 692 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 677 693 if(opResult!=EOK){ 678 dprintf(USB_LOG_LEVEL_ERROR, "could not start control pipe session %d", 679 opResult); 694 usb_log_error("could not start control pipe session %d", opResult); 680 695 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 681 696 return opResult; … … 683 698 opResult = usb_hc_connection_open(&hub_info->connection); 684 699 if(opResult!=EOK){ 685 dprintf(USB_LOG_LEVEL_ERROR,"could not start host controller session %d",700 usb_log_error("could not start host controller session %d", 686 701 opResult); 687 702 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); -
uspace/drv/usbhub/usbhub.h
r4f66cc7b r4fec9ee 71 71 /** hub endpoints */ 72 72 usb_hub_endpoints_t endpoints; 73 74 bool is_default_address_used; 73 75 } usb_hub_info_t; 74 76
Note:
See TracChangeset
for help on using the changeset viewer.
