1660
1661 /* Begin sending SOFs */
1662 curr_control = Get_OpReg(hcr_control);
1663
1664 USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
1665 "ohci_init_ctlr: curr_control=0x%x", curr_control);
1666
1667 /* Set the state to operational */
1668 curr_control = (curr_control &
1669 (~HCR_CONTROL_HCFS)) | HCR_CONTROL_OPERAT;
1670
1671 Set_OpReg(hcr_control, curr_control);
1672
1673 ASSERT((Get_OpReg(hcr_control) &
1674 HCR_CONTROL_HCFS) == HCR_CONTROL_OPERAT);
1675
1676 /* Set host controller soft state to operational */
1677 ohcip->ohci_hc_soft_state = OHCI_CTLR_OPERATIONAL_STATE;
1678
1679 /* Get the number of clock ticks to wait */
1680 sof_time_wait = drv_usectohz(OHCI_MAX_SOF_TIMEWAIT * 1000000);
1681
1682 /* Clear ohci_sof_flag indicating waiting for SOF interrupt */
1683 ohcip->ohci_sof_flag = B_FALSE;
1684
1685 /* Enable the SOF interrupt */
1686 Set_OpReg(hcr_intr_enable, HCR_INTR_SOF);
1687
1688 ASSERT(Get_OpReg(hcr_intr_enable) & HCR_INTR_SOF);
1689
1690 (void) cv_reltimedwait(&ohcip->ohci_SOF_cv,
1691 &ohcip->ohci_int_mutex, sof_time_wait, TR_CLOCK_TICK);
1692
1693 /* Wait for the SOF or timeout event */
1694 if (ohcip->ohci_sof_flag == B_FALSE) {
1695
1696 /* Set host controller soft state to error */
1697 ohcip->ohci_hc_soft_state = OHCI_CTLR_ERROR_STATE;
1698
1699 USB_DPRINTF_L0(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
1700 "No SOF interrupts have been received, this USB OHCI host"
7495 /*
7496 * ohci_start_timer:
7497 *
7498 * Start the ohci timer
7499 */
7500 static void
7501 ohci_start_timer(ohci_state_t *ohcip)
7502 {
7503 USB_DPRINTF_L3(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
7504 "ohci_start_timer: ohcip = 0x%p", (void *)ohcip);
7505
7506 ASSERT(mutex_owned(&ohcip->ohci_int_mutex));
7507
7508 /*
7509 * Start the global timer only if currently timer is not
7510 * running and if there are any transfers on the timeout
7511 * list. This timer will be per USB Host Controller.
7512 */
7513 if ((!ohcip->ohci_timer_id) && (ohcip->ohci_timeout_list)) {
7514 ohcip->ohci_timer_id = timeout(ohci_xfer_timeout_handler,
7515 (void *)ohcip, drv_usectohz(1000000));
7516 }
7517 }
7518
7519
7520 /*
7521 * ohci_deallocate_tw_resources:
7522 * NOTE: This function is also called from POLLED MODE.
7523 *
7524 * Deallocate of a Transaction Wrapper (TW) and this involves the freeing of
7525 * of DMA resources.
7526 */
7527 void
7528 ohci_deallocate_tw_resources(
7529 ohci_state_t *ohcip,
7530 ohci_pipe_private_t *pp,
7531 ohci_trans_wrapper_t *tw)
7532 {
7533 ohci_trans_wrapper_t *prev, *next;
7534
7535 USB_DPRINTF_L4(PRINT_MASK_ALLOC, ohcip->ohci_log_hdl,
9934
9935 USB_DPRINTF_L2(PRINT_MASK_INTR, ohcip->ohci_log_hdl,
9936 "ohci_do_soft_reset: Soft reset failed");
9937
9938 return (USB_FAILURE);
9939 }
9940
9941 /* Start the timer for the root hub interrupt pipe polling */
9942 if (rh_timer_id) {
9943 ohcip->ohci_root_hub.rh_intr_pipe_timer_id =
9944 timeout(ohci_handle_root_hub_status_change,
9945 (void *)ohcip, drv_usectohz(OHCI_RH_POLL_TIME));
9946
9947 ohcip->ohci_root_hub.
9948 rh_intr_pipe_state = OHCI_PIPE_STATE_ACTIVE;
9949 }
9950
9951 /* Start the global timer */
9952 if (xfer_timer_id) {
9953 ohcip->ohci_timer_id = timeout(ohci_xfer_timeout_handler,
9954 (void *)ohcip, drv_usectohz(1000000));
9955 }
9956
9957 return (USB_SUCCESS);
9958 }
9959
9960
9961 /*
9962 * ohci_get_current_frame_number:
9963 *
9964 * Get the current software based usb frame number.
9965 */
9966 usb_frame_number_t
9967 ohci_get_current_frame_number(ohci_state_t *ohcip)
9968 {
9969 usb_frame_number_t usb_frame_number;
9970 usb_frame_number_t ohci_fno, frame_number;
9971 ohci_save_intr_sts_t *ohci_intr_sts =
9972 &ohcip->ohci_save_intr_sts;
9973
9974 ASSERT(mutex_owned(&ohcip->ohci_int_mutex));
10187 static int
10188 ohci_wait_for_sof(ohci_state_t *ohcip)
10189 {
10190 usb_frame_number_t before_frame_number, after_frame_number;
10191 clock_t sof_time_wait;
10192 int rval, sof_wait_count;
10193
10194 USB_DPRINTF_L4(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
10195 "ohci_wait_for_sof");
10196
10197 ASSERT(mutex_owned(&ohcip->ohci_int_mutex));
10198
10199 rval = ohci_state_is_operational(ohcip);
10200
10201 if (rval != USB_SUCCESS) {
10202
10203 return (rval);
10204 }
10205
10206 /* Get the number of clock ticks to wait */
10207 sof_time_wait = drv_usectohz(OHCI_MAX_SOF_TIMEWAIT * 1000000);
10208
10209 sof_wait_count = 0;
10210
10211 /*
10212 * Get the current usb frame number before waiting for the
10213 * SOF interrupt event.
10214 */
10215 before_frame_number = ohci_get_current_frame_number(ohcip);
10216
10217 while (sof_wait_count < MAX_SOF_WAIT_COUNT) {
10218 /* Enable the SOF interrupt */
10219 Set_OpReg(hcr_intr_enable, HCR_INTR_SOF);
10220
10221 ASSERT(Get_OpReg(hcr_intr_enable) & HCR_INTR_SOF);
10222
10223 /* Wait for the SOF or timeout event */
10224 rval = cv_reltimedwait(&ohcip->ohci_SOF_cv,
10225 &ohcip->ohci_int_mutex, sof_time_wait, TR_CLOCK_TICK);
10226
10227 /*
10471 }
10472
10473 next_td = ohci_td_iommu_to_cpu(ohcip,
10474 Get_TD(next_td->hctd_tw_next_td));
10475 }
10476 }
10477
10478 next_tw = next_tw->tw_next;
10479 }
10480
10481 USB_DPRINTF_L3(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
10482 "ohci_wait_for_transfers_completion: count_done_tds = 0x%x",
10483 pp->pp_count_done_tds);
10484
10485 if (!pp->pp_count_done_tds) {
10486
10487 return;
10488 }
10489
10490 (void) cv_reltimedwait(&pp->pp_xfer_cmpl_cv, &ohcip->ohci_int_mutex,
10491 drv_usectohz(OHCI_XFER_CMPL_TIMEWAIT * 1000000), TR_CLOCK_TICK);
10492
10493 if (pp->pp_count_done_tds) {
10494
10495 USB_DPRINTF_L2(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
10496 "ohci_wait_for_transfers_completion: No transfers "
10497 "completion confirmation received for 0x%x requests",
10498 pp->pp_count_done_tds);
10499 }
10500 }
10501
10502
10503 /*
10504 * ohci_check_for_transfers_completion:
10505 *
10506 * Check whether anybody is waiting for transfers completion event. If so, send
10507 * this event and also stop initiating any new transfers on this pipe.
10508 */
10509 static void
10510 ohci_check_for_transfers_completion(
10511 ohci_state_t *ohcip,
|
1660
1661 /* Begin sending SOFs */
1662 curr_control = Get_OpReg(hcr_control);
1663
1664 USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
1665 "ohci_init_ctlr: curr_control=0x%x", curr_control);
1666
1667 /* Set the state to operational */
1668 curr_control = (curr_control &
1669 (~HCR_CONTROL_HCFS)) | HCR_CONTROL_OPERAT;
1670
1671 Set_OpReg(hcr_control, curr_control);
1672
1673 ASSERT((Get_OpReg(hcr_control) &
1674 HCR_CONTROL_HCFS) == HCR_CONTROL_OPERAT);
1675
1676 /* Set host controller soft state to operational */
1677 ohcip->ohci_hc_soft_state = OHCI_CTLR_OPERATIONAL_STATE;
1678
1679 /* Get the number of clock ticks to wait */
1680 sof_time_wait = drv_sectohz(OHCI_MAX_SOF_TIMEWAIT);
1681
1682 /* Clear ohci_sof_flag indicating waiting for SOF interrupt */
1683 ohcip->ohci_sof_flag = B_FALSE;
1684
1685 /* Enable the SOF interrupt */
1686 Set_OpReg(hcr_intr_enable, HCR_INTR_SOF);
1687
1688 ASSERT(Get_OpReg(hcr_intr_enable) & HCR_INTR_SOF);
1689
1690 (void) cv_reltimedwait(&ohcip->ohci_SOF_cv,
1691 &ohcip->ohci_int_mutex, sof_time_wait, TR_CLOCK_TICK);
1692
1693 /* Wait for the SOF or timeout event */
1694 if (ohcip->ohci_sof_flag == B_FALSE) {
1695
1696 /* Set host controller soft state to error */
1697 ohcip->ohci_hc_soft_state = OHCI_CTLR_ERROR_STATE;
1698
1699 USB_DPRINTF_L0(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
1700 "No SOF interrupts have been received, this USB OHCI host"
7495 /*
7496 * ohci_start_timer:
7497 *
7498 * Start the ohci timer
7499 */
7500 static void
7501 ohci_start_timer(ohci_state_t *ohcip)
7502 {
7503 USB_DPRINTF_L3(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
7504 "ohci_start_timer: ohcip = 0x%p", (void *)ohcip);
7505
7506 ASSERT(mutex_owned(&ohcip->ohci_int_mutex));
7507
7508 /*
7509 * Start the global timer only if currently timer is not
7510 * running and if there are any transfers on the timeout
7511 * list. This timer will be per USB Host Controller.
7512 */
7513 if ((!ohcip->ohci_timer_id) && (ohcip->ohci_timeout_list)) {
7514 ohcip->ohci_timer_id = timeout(ohci_xfer_timeout_handler,
7515 (void *)ohcip, drv_sectohz(1));
7516 }
7517 }
7518
7519
7520 /*
7521 * ohci_deallocate_tw_resources:
7522 * NOTE: This function is also called from POLLED MODE.
7523 *
7524 * Deallocate of a Transaction Wrapper (TW) and this involves the freeing of
7525 * of DMA resources.
7526 */
7527 void
7528 ohci_deallocate_tw_resources(
7529 ohci_state_t *ohcip,
7530 ohci_pipe_private_t *pp,
7531 ohci_trans_wrapper_t *tw)
7532 {
7533 ohci_trans_wrapper_t *prev, *next;
7534
7535 USB_DPRINTF_L4(PRINT_MASK_ALLOC, ohcip->ohci_log_hdl,
9934
9935 USB_DPRINTF_L2(PRINT_MASK_INTR, ohcip->ohci_log_hdl,
9936 "ohci_do_soft_reset: Soft reset failed");
9937
9938 return (USB_FAILURE);
9939 }
9940
9941 /* Start the timer for the root hub interrupt pipe polling */
9942 if (rh_timer_id) {
9943 ohcip->ohci_root_hub.rh_intr_pipe_timer_id =
9944 timeout(ohci_handle_root_hub_status_change,
9945 (void *)ohcip, drv_usectohz(OHCI_RH_POLL_TIME));
9946
9947 ohcip->ohci_root_hub.
9948 rh_intr_pipe_state = OHCI_PIPE_STATE_ACTIVE;
9949 }
9950
9951 /* Start the global timer */
9952 if (xfer_timer_id) {
9953 ohcip->ohci_timer_id = timeout(ohci_xfer_timeout_handler,
9954 (void *)ohcip, drv_sectohz(1));
9955 }
9956
9957 return (USB_SUCCESS);
9958 }
9959
9960
9961 /*
9962 * ohci_get_current_frame_number:
9963 *
9964 * Get the current software based usb frame number.
9965 */
9966 usb_frame_number_t
9967 ohci_get_current_frame_number(ohci_state_t *ohcip)
9968 {
9969 usb_frame_number_t usb_frame_number;
9970 usb_frame_number_t ohci_fno, frame_number;
9971 ohci_save_intr_sts_t *ohci_intr_sts =
9972 &ohcip->ohci_save_intr_sts;
9973
9974 ASSERT(mutex_owned(&ohcip->ohci_int_mutex));
10187 static int
10188 ohci_wait_for_sof(ohci_state_t *ohcip)
10189 {
10190 usb_frame_number_t before_frame_number, after_frame_number;
10191 clock_t sof_time_wait;
10192 int rval, sof_wait_count;
10193
10194 USB_DPRINTF_L4(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
10195 "ohci_wait_for_sof");
10196
10197 ASSERT(mutex_owned(&ohcip->ohci_int_mutex));
10198
10199 rval = ohci_state_is_operational(ohcip);
10200
10201 if (rval != USB_SUCCESS) {
10202
10203 return (rval);
10204 }
10205
10206 /* Get the number of clock ticks to wait */
10207 sof_time_wait = drv_sectohz(OHCI_MAX_SOF_TIMEWAIT);
10208
10209 sof_wait_count = 0;
10210
10211 /*
10212 * Get the current usb frame number before waiting for the
10213 * SOF interrupt event.
10214 */
10215 before_frame_number = ohci_get_current_frame_number(ohcip);
10216
10217 while (sof_wait_count < MAX_SOF_WAIT_COUNT) {
10218 /* Enable the SOF interrupt */
10219 Set_OpReg(hcr_intr_enable, HCR_INTR_SOF);
10220
10221 ASSERT(Get_OpReg(hcr_intr_enable) & HCR_INTR_SOF);
10222
10223 /* Wait for the SOF or timeout event */
10224 rval = cv_reltimedwait(&ohcip->ohci_SOF_cv,
10225 &ohcip->ohci_int_mutex, sof_time_wait, TR_CLOCK_TICK);
10226
10227 /*
10471 }
10472
10473 next_td = ohci_td_iommu_to_cpu(ohcip,
10474 Get_TD(next_td->hctd_tw_next_td));
10475 }
10476 }
10477
10478 next_tw = next_tw->tw_next;
10479 }
10480
10481 USB_DPRINTF_L3(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
10482 "ohci_wait_for_transfers_completion: count_done_tds = 0x%x",
10483 pp->pp_count_done_tds);
10484
10485 if (!pp->pp_count_done_tds) {
10486
10487 return;
10488 }
10489
10490 (void) cv_reltimedwait(&pp->pp_xfer_cmpl_cv, &ohcip->ohci_int_mutex,
10491 drv_sectohz(OHCI_XFER_CMPL_TIMEWAIT), TR_CLOCK_TICK);
10492
10493 if (pp->pp_count_done_tds) {
10494
10495 USB_DPRINTF_L2(PRINT_MASK_LISTS, ohcip->ohci_log_hdl,
10496 "ohci_wait_for_transfers_completion: No transfers "
10497 "completion confirmation received for 0x%x requests",
10498 pp->pp_count_done_tds);
10499 }
10500 }
10501
10502
10503 /*
10504 * ohci_check_for_transfers_completion:
10505 *
10506 * Check whether anybody is waiting for transfers completion event. If so, send
10507 * this event and also stop initiating any new transfers on this pipe.
10508 */
10509 static void
10510 ohci_check_for_transfers_completion(
10511 ohci_state_t *ohcip,
|