📄 uhci-q.c
字号:
qh->iso_status = 0; } qh->skel = SKEL_ISO; if (!qh->bandwidth_reserved) uhci_reserve_bandwidth(uhci, qh); return 0;}static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb){ struct uhci_td *td, *tmp; struct urb_priv *urbp = urb->hcpriv; struct uhci_qh *qh = urbp->qh; list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { unsigned int ctrlstat; int status; int actlength; if (uhci_frame_before_eq(uhci->cur_iso_frame, qh->iso_frame)) return -EINPROGRESS; uhci_remove_tds_from_frame(uhci, qh->iso_frame); ctrlstat = td_status(td); if (ctrlstat & TD_CTRL_ACTIVE) { status = -EXDEV; /* TD was added too late? */ } else { status = uhci_map_status(uhci_status_bits(ctrlstat), usb_pipeout(urb->pipe)); actlength = uhci_actual_length(ctrlstat); urb->actual_length += actlength; qh->iso_packet_desc->actual_length = actlength; qh->iso_packet_desc->status = status; } if (status) { urb->error_count++; qh->iso_status = status; } uhci_remove_td_from_urbp(td); uhci_free_td(uhci, td); qh->iso_frame += qh->period; ++qh->iso_packet_desc; } return qh->iso_status;}static int uhci_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep, struct urb *urb, gfp_t mem_flags){ int ret; struct uhci_hcd *uhci = hcd_to_uhci(hcd); unsigned long flags; struct urb_priv *urbp; struct uhci_qh *qh; spin_lock_irqsave(&uhci->lock, flags); ret = urb->status; if (ret != -EINPROGRESS) /* URB already unlinked! */ goto done; ret = -ENOMEM; urbp = uhci_alloc_urb_priv(uhci, urb); if (!urbp) goto done; if (hep->hcpriv) qh = (struct uhci_qh *) hep->hcpriv; else { qh = uhci_alloc_qh(uhci, urb->dev, hep); if (!qh) goto err_no_qh; } urbp->qh = qh; switch (qh->type) { case USB_ENDPOINT_XFER_CONTROL: ret = uhci_submit_control(uhci, urb, qh); break; case USB_ENDPOINT_XFER_BULK: ret = uhci_submit_bulk(uhci, urb, qh); break; case USB_ENDPOINT_XFER_INT: ret = uhci_submit_interrupt(uhci, urb, qh); break; case USB_ENDPOINT_XFER_ISOC: urb->error_count = 0; ret = uhci_submit_isochronous(uhci, urb, qh); break; } if (ret != 0) goto err_submit_failed; /* Add this URB to the QH */ urbp->qh = qh; list_add_tail(&urbp->node, &qh->queue); /* If the new URB is the first and only one on this QH then either * the QH is new and idle or else it's unlinked and waiting to * become idle, so we can activate it right away. But only if the * queue isn't stopped. */ if (qh->queue.next == &urbp->node && !qh->is_stopped) { uhci_activate_qh(uhci, qh); uhci_urbp_wants_fsbr(uhci, urbp); } goto done;err_submit_failed: if (qh->state == QH_STATE_IDLE) uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */err_no_qh: uhci_free_urb_priv(uhci, urbp);done: spin_unlock_irqrestore(&uhci->lock, flags); return ret;}static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb){ struct uhci_hcd *uhci = hcd_to_uhci(hcd); unsigned long flags; struct urb_priv *urbp; struct uhci_qh *qh; spin_lock_irqsave(&uhci->lock, flags); urbp = urb->hcpriv; if (!urbp) /* URB was never linked! */ goto done; qh = urbp->qh; /* Remove Isochronous TDs from the frame list ASAP */ if (qh->type == USB_ENDPOINT_XFER_ISOC) { uhci_unlink_isochronous_tds(uhci, urb); mb(); /* If the URB has already started, update the QH unlink time */ uhci_get_current_frame_number(uhci); if (uhci_frame_before_eq(urb->start_frame, uhci->frame_number)) qh->unlink_frame = uhci->frame_number; } uhci_unlink_qh(uhci, qh);done: spin_unlock_irqrestore(&uhci->lock, flags); return 0;}/* * Finish unlinking an URB and give it back */static void uhci_giveback_urb(struct uhci_hcd *uhci, struct uhci_qh *qh, struct urb *urb)__releases(uhci->lock)__acquires(uhci->lock){ struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; /* When giving back the first URB in an Isochronous queue, * reinitialize the QH's iso-related members for the next URB. */ if (qh->type == USB_ENDPOINT_XFER_ISOC && urbp->node.prev == &qh->queue && urbp->node.next != &qh->queue) { struct urb *nurb = list_entry(urbp->node.next, struct urb_priv, node)->urb; qh->iso_packet_desc = &nurb->iso_frame_desc[0]; qh->iso_frame = nurb->start_frame; qh->iso_status = 0; } /* Take the URB off the QH's queue. If the queue is now empty, * this is a perfect time for a toggle fixup. */ list_del_init(&urbp->node); if (list_empty(&qh->queue) && qh->needs_fixup) { usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), qh->initial_toggle); qh->needs_fixup = 0; } uhci_free_urb_priv(uhci, urbp); spin_unlock(&uhci->lock); usb_hcd_giveback_urb(uhci_to_hcd(uhci), urb); spin_lock(&uhci->lock); /* If the queue is now empty, we can unlink the QH and give up its * reserved bandwidth. */ if (list_empty(&qh->queue)) { uhci_unlink_qh(uhci, qh); if (qh->bandwidth_reserved) uhci_release_bandwidth(uhci, qh); }}/* * Scan the URBs in a QH's queue */#define QH_FINISHED_UNLINKING(qh) \ (qh->state == QH_STATE_UNLINKING && \ uhci->frame_number + uhci->is_stopped != qh->unlink_frame)static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh){ struct urb_priv *urbp; struct urb *urb; int status; while (!list_empty(&qh->queue)) { urbp = list_entry(qh->queue.next, struct urb_priv, node); urb = urbp->urb; if (qh->type == USB_ENDPOINT_XFER_ISOC) status = uhci_result_isochronous(uhci, urb); else status = uhci_result_common(uhci, urb); if (status == -EINPROGRESS) break; spin_lock(&urb->lock); if (urb->status == -EINPROGRESS) /* Not dequeued */ urb->status = status; else status = ECONNRESET; /* Not -ECONNRESET */ spin_unlock(&urb->lock); /* Dequeued but completed URBs can't be given back unless * the QH is stopped or has finished unlinking. */ if (status == ECONNRESET) { if (QH_FINISHED_UNLINKING(qh)) qh->is_stopped = 1; else if (!qh->is_stopped) return; } uhci_giveback_urb(uhci, qh, urb); if (status < 0 && qh->type != USB_ENDPOINT_XFER_ISOC) break; } /* If the QH is neither stopped nor finished unlinking (normal case), * our work here is done. */ if (QH_FINISHED_UNLINKING(qh)) qh->is_stopped = 1; else if (!qh->is_stopped) return; /* Otherwise give back each of the dequeued URBs */restart: list_for_each_entry(urbp, &qh->queue, node) { urb = urbp->urb; if (urb->status != -EINPROGRESS) { /* Fix up the TD links and save the toggles for * non-Isochronous queues. For Isochronous queues, * test for too-recent dequeues. */ if (!uhci_cleanup_queue(uhci, qh, urb)) { qh->is_stopped = 0; return; } uhci_giveback_urb(uhci, qh, urb); goto restart; } } qh->is_stopped = 0; /* There are no more dequeued URBs. If there are still URBs on the * queue, the QH can now be re-activated. */ if (!list_empty(&qh->queue)) { if (qh->needs_fixup) uhci_fixup_toggles(qh, 0); /* If the first URB on the queue wants FSBR but its time * limit has expired, set the next TD to interrupt on * completion before reactivating the QH. */ urbp = list_entry(qh->queue.next, struct urb_priv, node); if (urbp->fsbr && qh->wait_expired) { struct uhci_td *td = list_entry(urbp->td_list.next, struct uhci_td, list); td->status |= __cpu_to_le32(TD_CTRL_IOC); } uhci_activate_qh(uhci, qh); } /* The queue is empty. The QH can become idle if it is fully * unlinked. */ else if (QH_FINISHED_UNLINKING(qh)) uhci_make_qh_idle(uhci, qh);}/* * Check for queues that have made some forward progress. * Returns 0 if the queue is not Isochronous, is ACTIVE, and * has not advanced since last examined; 1 otherwise. * * Early Intel controllers have a bug which causes qh->element sometimes * not to advance when a TD completes successfully. The queue remains * stuck on the inactive completed TD. We detect such cases and advance * the element pointer by hand. */static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh){ struct urb_priv *urbp = NULL; struct uhci_td *td; int ret = 1; unsigned status; if (qh->type == USB_ENDPOINT_XFER_ISOC) goto done; /* Treat an UNLINKING queue as though it hasn't advanced. * This is okay because reactivation will treat it as though * it has advanced, and if it is going to become IDLE then * this doesn't matter anyway. Furthermore it's possible * for an UNLINKING queue not to have any URBs at all, or * for its first URB not to have any TDs (if it was dequeued * just as it completed). So it's not easy in any case to * test whether such queues have advanced. */ if (qh->state != QH_STATE_ACTIVE) { urbp = NULL; status = 0; } else { urbp = list_entry(qh->queue.next, struct urb_priv, node); td = list_entry(urbp->td_list.next, struct uhci_td, list); status = td_status(td); if (!(status & TD_CTRL_ACTIVE)) { /* We're okay, the queue has advanced */ qh->wait_expired = 0; qh->advance_jiffies = jiffies; goto done; } ret = 0; } /* The queue hasn't advanced; check for timeout */ if (qh->wait_expired) goto done; if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { /* Detect the Intel bug and work around it */ if (qh->post_td && qh_element(qh) == LINK_TO_TD(qh->post_td)) { qh->element = qh->post_td->link; qh->advance_jiffies = jiffies; ret = 1; goto done; } qh->wait_expired = 1; /* If the current URB wants FSBR, unlink it temporarily * so that we can safely set the next TD to interrupt on * completion. That way we'll know as soon as the queue * starts moving again. */ if (urbp && urbp->fsbr && !(status & TD_CTRL_IOC)) uhci_unlink_qh(uhci, qh); } else { /* Unmoving but not-yet-expired queues keep FSBR alive */ if (urbp) uhci_urbp_wants_fsbr(uhci, urbp); }done: return ret;}/* * Process events in the schedule, but only in one thread at a time */static void uhci_scan_schedule(struct uhci_hcd *uhci){ int i; struct uhci_qh *qh; /* Don't allow re-entrant calls */ if (uhci->scan_in_progress) { uhci->need_rescan = 1; return; } uhci->scan_in_progress = 1;rescan: uhci->need_rescan = 0; uhci->fsbr_is_wanted = 0; uhci_clear_next_interrupt(uhci); uhci_get_current_frame_number(uhci); uhci->cur_iso_frame = uhci->frame_number; /* Go through all the QH queues and process the URBs in each one */ for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) { uhci->next_qh = list_entry(uhci->skelqh[i]->node.next, struct uhci_qh, node); while ((qh = uhci->next_qh) != uhci->skelqh[i]) { uhci->next_qh = list_entry(qh->node.next, struct uhci_qh, node); if (uhci_advance_check(uhci, qh)) { uhci_scan_qh(uhci, qh); if (qh->state == QH_STATE_ACTIVE) { uhci_urbp_wants_fsbr(uhci, list_entry(qh->queue.next, struct urb_priv, node)); } } } } uhci->last_iso_frame = uhci->cur_iso_frame; if (uhci->need_rescan) goto rescan; uhci->scan_in_progress = 0; if (uhci->fsbr_is_on && !uhci->fsbr_is_wanted && !uhci->fsbr_expiring) { uhci->fsbr_expiring = 1; mod_timer(&uhci->fsbr_timer, jiffies + FSBR_OFF_DELAY); } if (list_empty(&uhci->skel_unlink_qh->node)) uhci_clear_next_interrupt(uhci); else uhci_set_next_interrupt(uhci);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -