Lines Matching refs:qh
249 struct uhci_qh *qh;
251 qh = dma_pool_zalloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle);
252 if (!qh)
255 qh->dma_handle = dma_handle;
257 qh->element = UHCI_PTR_TERM(uhci);
258 qh->link = UHCI_PTR_TERM(uhci);
260 INIT_LIST_HEAD(&qh->queue);
261 INIT_LIST_HEAD(&qh->node);
264 qh->type = usb_endpoint_type(&hep->desc);
265 if (qh->type != USB_ENDPOINT_XFER_ISOC) {
266 qh->dummy_td = uhci_alloc_td(uhci);
267 if (!qh->dummy_td) {
268 dma_pool_free(uhci->qh_pool, qh, dma_handle);
272 qh->state = QH_STATE_IDLE;
273 qh->hep = hep;
274 qh->udev = udev;
275 hep->hcpriv = qh;
277 if (qh->type == USB_ENDPOINT_XFER_INT ||
278 qh->type == USB_ENDPOINT_XFER_ISOC)
279 qh->load = usb_calc_bus_time(udev->speed,
281 qh->type == USB_ENDPOINT_XFER_ISOC,
286 qh->state = QH_STATE_ACTIVE;
287 qh->type = -1;
289 return qh;
292 static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
294 WARN_ON(qh->state != QH_STATE_IDLE && qh->udev);
295 if (!list_empty(&qh->queue))
296 dev_WARN(uhci_dev(uhci), "qh %p list not empty!\n", qh);
298 list_del(&qh->node);
299 if (qh->udev) {
300 qh->hep->hcpriv = NULL;
301 if (qh->dummy_td)
302 uhci_free_td(uhci, qh->dummy_td);
304 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle);
314 static int uhci_cleanup_queue(struct uhci_hcd *uhci, struct uhci_qh *qh,
325 if (qh->type == USB_ENDPOINT_XFER_ISOC) {
327 qh->unlink_frame);
334 if (qh->queue.next != &urbp->node) {
350 if (qh_element(qh) == UHCI_PTR_TERM(uhci))
352 qh->element = UHCI_PTR_TERM(uhci);
355 if (qh->type == USB_ENDPOINT_XFER_CONTROL)
361 qh->needs_fixup = 1;
362 qh->initial_toggle = uhci_toggle(td_token(uhci, td));
372 static void uhci_fixup_toggles(struct uhci_hcd *uhci, struct uhci_qh *qh,
377 unsigned int toggle = qh->initial_toggle;
383 urbp = list_entry(qh->queue.next, struct urb_priv, node);
387 else if (qh_element(qh) != UHCI_PTR_TERM(uhci))
393 urbp = list_prepare_entry(urbp, &qh->queue, node);
394 list_for_each_entry_continue(urbp, &qh->queue, node) {
415 pipe = list_entry(qh->queue.next, struct urb_priv, node)->urb->pipe;
416 usb_settoggle(qh->udev, usb_pipeendpoint(pipe),
418 qh->needs_fixup = 0;
424 static inline void link_iso(struct uhci_hcd *uhci, struct uhci_qh *qh)
426 list_add_tail(&qh->node, &uhci->skel_iso_qh->node);
435 static void link_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh)
439 list_add_tail(&qh->node, &uhci->skelqh[qh->skel]->node);
441 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
442 qh->link = pqh->link;
444 pqh->link = LINK_TO_QH(uhci, qh);
451 static void link_async(struct uhci_hcd *uhci, struct uhci_qh *qh)
460 if (pqh->skel <= qh->skel)
463 list_add(&qh->node, &pqh->node);
466 qh->link = pqh->link;
468 link_to_new_qh = LINK_TO_QH(uhci, qh);
473 if (pqh->skel < SKEL_FSBR && qh->skel >= SKEL_FSBR)
480 static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
482 WARN_ON(list_empty(&qh->queue));
486 if (qh_element(qh) == UHCI_PTR_TERM(uhci)) {
487 struct urb_priv *urbp = list_entry(qh->queue.next,
492 qh->element = LINK_TO_TD(uhci, td);
496 qh->wait_expired = 0;
497 qh->advance_jiffies = jiffies;
499 if (qh->state == QH_STATE_ACTIVE)
501 qh->state = QH_STATE_ACTIVE;
505 if (qh == uhci->next_qh)
506 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh,
508 list_del(&qh->node);
510 if (qh->skel == SKEL_ISO)
511 link_iso(uhci, qh);
512 else if (qh->skel < SKEL_ASYNC)
513 link_interrupt(uhci, qh);
515 link_async(uhci, qh);
521 static void unlink_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh)
525 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
526 pqh->link = qh->link;
533 static void unlink_async(struct uhci_hcd *uhci, struct uhci_qh *qh)
536 __hc32 link_to_next_qh = qh->link;
538 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
543 if (pqh->skel < SKEL_FSBR && qh->skel >= SKEL_FSBR)
551 static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
553 if (qh->state == QH_STATE_UNLINKING)
555 WARN_ON(qh->state != QH_STATE_ACTIVE || !qh->udev);
556 qh->state = QH_STATE_UNLINKING;
559 if (qh->skel == SKEL_ISO)
561 else if (qh->skel < SKEL_ASYNC)
562 unlink_interrupt(uhci, qh);
564 unlink_async(uhci, qh);
567 qh->unlink_frame = uhci->frame_number;
574 if (qh == uhci->next_qh)
575 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh,
577 list_move_tail(&qh->node, &uhci->skel_unlink_qh->node);
586 static void uhci_make_qh_idle(struct uhci_hcd *uhci, struct uhci_qh *qh)
588 WARN_ON(qh->state == QH_STATE_ACTIVE);
590 if (qh == uhci->next_qh)
591 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh,
593 list_move(&qh->node, &uhci->idle_qh_list);
594 qh->state = QH_STATE_IDLE;
597 if (qh->post_td) {
598 uhci_free_td(uhci, qh->post_td);
599 qh->post_td = NULL;
620 * Set qh->phase to the optimal phase for a periodic transfer and
623 static int uhci_check_bandwidth(struct uhci_hcd *uhci, struct uhci_qh *qh)
629 if (qh->phase >= 0)
630 minimax_load = uhci_highest_load(uhci, qh->phase, qh->period);
633 int max_phase = min_t(int, MAX_PHASE, qh->period);
635 qh->phase = 0;
636 minimax_load = uhci_highest_load(uhci, qh->phase, qh->period);
638 load = uhci_highest_load(uhci, phase, qh->period);
641 qh->phase = phase;
647 if (minimax_load + qh->load > 900) {
650 qh->period, qh->phase, minimax_load, qh->load);
659 static void uhci_reserve_bandwidth(struct uhci_hcd *uhci, struct uhci_qh *qh)
662 int load = qh->load;
665 for (i = qh->phase; i < MAX_PHASE; i += qh->period) {
671 switch (qh->type) {
681 qh->bandwidth_reserved = 1;
684 "reserve", qh->udev->devnum,
685 qh->hep->desc.bEndpointAddress, p,
686 qh->period, qh->phase, load);
692 static void uhci_release_bandwidth(struct uhci_hcd *uhci, struct uhci_qh *qh)
695 int load = qh->load;
698 for (i = qh->phase; i < MAX_PHASE; i += qh->period) {
704 switch (qh->type) {
714 qh->bandwidth_reserved = 0;
717 "release", qh->udev->devnum,
718 qh->hep->desc.bEndpointAddress, p,
719 qh->period, qh->phase, load);
790 struct uhci_qh *qh)
794 int maxsze = usb_endpoint_maxp(&qh->hep->desc);
812 td = qh->dummy_td;
888 qh->dummy_td->status |= cpu_to_hc32(uhci, TD_CTRL_ACTIVE);
889 qh->dummy_td = td;
902 if (qh->state != QH_STATE_ACTIVE)
903 qh->skel = skel;
908 uhci_remove_td_from_urbp(qh->dummy_td);
916 struct uhci_qh *qh)
920 int maxsze = usb_endpoint_maxp(&qh->hep->desc);
963 td = qh->dummy_td;
1043 qh->dummy_td->status |= cpu_to_hc32(uhci, TD_CTRL_ACTIVE);
1044 qh->dummy_td = td;
1052 uhci_remove_td_from_urbp(qh->dummy_td);
1057 struct uhci_qh *qh)
1065 if (qh->state != QH_STATE_ACTIVE)
1066 qh->skel = SKEL_BULK;
1067 ret = uhci_submit_common(uhci, urb, qh);
1074 struct uhci_qh *qh)
1083 if (!qh->bandwidth_reserved) {
1096 qh->period = 1 << exponent;
1097 qh->skel = SKEL_INDEX(exponent);
1102 qh->phase = (qh->period / 2) & (MAX_PHASE - 1);
1103 ret = uhci_check_bandwidth(uhci, qh);
1107 } else if (qh->period > urb->interval)
1110 ret = uhci_submit_common(uhci, urb, qh);
1112 urb->interval = qh->period;
1113 if (!qh->bandwidth_reserved)
1114 uhci_reserve_bandwidth(uhci, qh);
1123 struct uhci_qh *qh, struct urb_priv *urbp)
1130 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1136 qh->element = LINK_TO_TD(uhci, td);
1145 qh->initial_toggle =
1146 uhci_toggle(td_token(uhci, qh->post_td)) ^ 1;
1147 uhci_fixup_toggles(uhci, qh, 1);
1150 td = qh->post_td;
1151 qh->element = td->link;
1173 struct uhci_qh *qh = urbp->qh;
1201 uhci_show_qh(uhci, urbp->qh, errbuf,
1212 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1227 if (qh->post_td)
1228 uhci_free_td(uhci, qh->post_td);
1229 qh->post_td = td;
1240 qh->element = UHCI_PTR_TERM(uhci);
1241 qh->is_stopped = 1;
1242 qh->needs_fixup = (qh->type != USB_ENDPOINT_XFER_CONTROL);
1243 qh->initial_toggle = uhci_toggle(td_token(uhci, td)) ^
1247 ret = uhci_fixup_short_transfer(uhci, qh, urbp);
1255 struct uhci_qh *qh)
1271 if (!qh->bandwidth_reserved) {
1272 qh->period = urb->interval;
1273 qh->phase = -1; /* Find the best phase */
1274 i = uhci_check_bandwidth(uhci, qh);
1280 frame = qh->phase;
1283 frame += (next - frame + qh->period - 1) & -qh->period;
1285 } else if (qh->period != urb->interval) {
1292 if (list_empty(&qh->queue)) {
1293 frame = qh->iso_frame;
1297 lurb = list_entry(qh->queue.prev,
1309 frame += (next - frame + qh->period - 1) &
1310 -qh->period;
1318 qh->period))
1322 qh->period,
1355 frame += qh->period;
1358 if (list_empty(&qh->queue)) {
1359 qh->iso_packet_desc = &urb->iso_frame_desc[0];
1360 qh->iso_frame = urb->start_frame;
1363 qh->skel = SKEL_ISO;
1364 if (!qh->bandwidth_reserved)
1365 uhci_reserve_bandwidth(uhci, qh);
1373 struct uhci_qh *qh = urbp->qh;
1380 if (uhci_frame_before_eq(uhci->cur_iso_frame, qh->iso_frame))
1383 uhci_remove_tds_from_frame(uhci, qh->iso_frame);
1394 qh->iso_packet_desc->actual_length = actlength;
1395 qh->iso_packet_desc->status = status;
1402 qh->iso_frame += qh->period;
1403 ++qh->iso_packet_desc;
1415 struct uhci_qh *qh;
1429 qh = urb->ep->hcpriv;
1431 qh = uhci_alloc_qh(uhci, urb->dev, urb->ep);
1432 if (!qh)
1435 urbp->qh = qh;
1437 switch (qh->type) {
1439 ret = uhci_submit_control(uhci, urb, qh);
1442 ret = uhci_submit_bulk(uhci, urb, qh);
1445 ret = uhci_submit_interrupt(uhci, urb, qh);
1449 ret = uhci_submit_isochronous(uhci, urb, qh);
1456 list_add_tail(&urbp->node, &qh->queue);
1462 if (qh->queue.next == &urbp->node && !qh->is_stopped) {
1463 uhci_activate_qh(uhci, qh);
1469 if (qh->state == QH_STATE_IDLE)
1470 uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */
1485 struct uhci_qh *qh;
1493 qh = ((struct urb_priv *) urb->hcpriv)->qh;
1496 if (qh->type == USB_ENDPOINT_XFER_ISOC) {
1503 qh->unlink_frame = uhci->frame_number;
1506 uhci_unlink_qh(uhci, qh);
1516 static void uhci_giveback_urb(struct uhci_hcd *uhci, struct uhci_qh *qh,
1523 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1533 else if (qh->type == USB_ENDPOINT_XFER_ISOC &&
1534 urbp->node.prev == &qh->queue &&
1535 urbp->node.next != &qh->queue) {
1539 qh->iso_packet_desc = &nurb->iso_frame_desc[0];
1540 qh->iso_frame = nurb->start_frame;
1546 if (list_empty(&qh->queue) && qh->needs_fixup) {
1548 usb_pipeout(urb->pipe), qh->initial_toggle);
1549 qh->needs_fixup = 0;
1561 if (list_empty(&qh->queue)) {
1562 uhci_unlink_qh(uhci, qh);
1563 if (qh->bandwidth_reserved)
1564 uhci_release_bandwidth(uhci, qh);
1571 #define QH_FINISHED_UNLINKING(qh) \
1572 (qh->state == QH_STATE_UNLINKING && \
1573 uhci->frame_number + uhci->is_stopped != qh->unlink_frame)
1575 static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
1581 while (!list_empty(&qh->queue)) {
1582 urbp = list_entry(qh->queue.next, struct urb_priv, node);
1585 if (qh->type == USB_ENDPOINT_XFER_ISOC)
1595 if (QH_FINISHED_UNLINKING(qh))
1596 qh->is_stopped = 1;
1597 else if (!qh->is_stopped)
1601 uhci_giveback_urb(uhci, qh, urb, status);
1608 if (QH_FINISHED_UNLINKING(qh))
1609 qh->is_stopped = 1;
1610 else if (!qh->is_stopped)
1615 list_for_each_entry(urbp, &qh->queue, node) {
1622 if (!uhci_cleanup_queue(uhci, qh, urb)) {
1623 qh->is_stopped = 0;
1626 uhci_giveback_urb(uhci, qh, urb, 0);
1630 qh->is_stopped = 0;
1634 if (!list_empty(&qh->queue)) {
1635 if (qh->needs_fixup)
1636 uhci_fixup_toggles(uhci, qh, 0);
1641 urbp = list_entry(qh->queue.next, struct urb_priv, node);
1642 if (urbp->fsbr && qh->wait_expired) {
1649 uhci_activate_qh(uhci, qh);
1654 else if (QH_FINISHED_UNLINKING(qh))
1655 uhci_make_qh_idle(uhci, qh);
1663 * Early Intel controllers have a bug which causes qh->element sometimes
1668 static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh)
1675 if (qh->type == USB_ENDPOINT_XFER_ISOC)
1686 if (qh->state != QH_STATE_ACTIVE) {
1691 urbp = list_entry(qh->queue.next, struct urb_priv, node);
1697 qh->wait_expired = 0;
1698 qh->advance_jiffies = jiffies;
1705 if (qh->wait_expired)
1708 if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) {
1711 if (qh->post_td && qh_element(qh) ==
1712 LINK_TO_TD(uhci, qh->post_td)) {
1713 qh->element = qh->post_td->link;
1714 qh->advance_jiffies = jiffies;
1719 qh->wait_expired = 1;
1726 uhci_unlink_qh(uhci, qh);
1744 struct uhci_qh *qh;
1764 while ((qh = uhci->next_qh) != uhci->skelqh[i]) {
1765 uhci->next_qh = list_entry(qh->node.next,
1768 if (uhci_advance_check(uhci, qh)) {
1769 uhci_scan_qh(uhci, qh);
1770 if (qh->state == QH_STATE_ACTIVE) {
1772 list_entry(qh->queue.next, struct urb_priv, node));