ed = td->ed; if (ed->mode == FHCI_TF_ISO) { if (ed->td_list.next->next != &ed->td_list) { struct td *td_next =
list_entry(ed->td_list.next->next, struct td,
node);
td_next->start_frame = usb->actual_frame->frame_num;
}
td->actual_len = trans_len;
td_done = true;
} elseif ((td->status & USB_TD_ERROR) &&
!(td->status & USB_TD_TX_ER_NAK)) { /* * There was an error on the transaction (but not NAK). * If it is fatal error (data underrun, stall, bad pid or 3 * errors exceeded), mark this TD as done.
*/ if ((td->status & USB_TD_RX_DATA_UNDERUN) ||
(td->status & USB_TD_TX_ER_STALL) ||
(td->status & USB_TD_RX_ER_PID) ||
(++td->error_cnt >= 3)) {
ed->state = FHCI_ED_HALTED;
td_done = true;
if (td->status & USB_TD_RX_DATA_UNDERUN) {
fhci_dbg(usb->fhci, "td err fu\n");
td->toggle = !td->toggle;
td->actual_len += trans_len;
} else {
fhci_dbg(usb->fhci, "td err f!u\n");
}
} else {
fhci_dbg(usb->fhci, "td err !f\n"); /* it is not a fatal error -retry this transaction */
td->nak_cnt = 0;
td->error_cnt++;
td->status = USB_TD_OK;
}
} elseif (td->status & USB_TD_TX_ER_NAK) { /* there was a NAK response */
fhci_vdbg(usb->fhci, "td nack\n");
td->nak_cnt++;
td->error_cnt = 0;
td->status = USB_TD_OK;
} else { /* there was no error on transaction */
td->error_cnt = 0;
td->nak_cnt = 0;
td->toggle = !td->toggle;
td->actual_len += trans_len;
if (td->len == td->actual_len)
td_done = true;
}
if (td_done)
fhci_move_td_from_ed_to_done_list(usb, ed);
}
/* * Flush all transmitted packets from BDs * This routine is called when disabling the USB port to flush all * transmissions that are already scheduled in the BDs
*/ void fhci_flush_all_transmissions(struct fhci_usb *usb)
{
u8 mode; struct td *td;
/* reset the event register */
out_be16(&usb->fhci->regs->usb_usber, 0xffff); /* enable the USB controller */
out_8(&usb->fhci->regs->usb_usmod, mode | USB_MODE_EN);
}
/* * This function forms the packet and transmit the packet. This function * will handle all endpoint type:ISO,interrupt,control and bulk
*/ staticint add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
{
u32 fw_transaction_time, len = 0; struct packet *pkt;
u8 *data = NULL;
/* calculate data address,len and toggle and then add the transaction */ if (td->toggle == USB_TD_TOGGLE_CARRY)
td->toggle = ed->toggle_carry;
switch (ed->mode) { case FHCI_TF_ISO:
len = td->len; if (td->type != FHCI_TA_IN)
data = td->data; break; case FHCI_TF_CTRL: case FHCI_TF_BULK:
len = min(td->len - td->actual_len, ed->max_pkt_size); if (!((td->type == FHCI_TA_IN) &&
((len + td->actual_len) == td->len)))
data = td->data + td->actual_len; break; case FHCI_TF_INTR:
len = min(td->len, ed->max_pkt_size); if (!((td->type == FHCI_TA_IN) &&
((td->len + CRC_SIZE) >= ed->max_pkt_size)))
data = td->data; break; default: break;
}
/* check if there's enough space in this frame to submit this TD */ if (usb->actual_frame->total_bytes + len + PROTOCOL_OVERHEAD >=
usb->max_bytes_per_frame) {
fhci_vdbg(usb->fhci, "not enough space in this frame: " "%d %d %d\n", usb->actual_frame->total_bytes, len,
usb->max_bytes_per_frame); return -1;
}
/* check if there's enough time in this frame to submit this TD */ if (usb->actual_frame->frame_status != FRAME_IS_PREPARED &&
(usb->actual_frame->frame_status & FRAME_END_TRANSMISSION ||
(fw_transaction_time + usb->sw_transaction_time >=
1000 - fhci_get_sof_timer_count(usb)))) {
fhci_dbg(usb->fhci, "not enough time in this frame\n"); return -1;
}
/* update frame object fields before transmitting */
pkt = cq_get(&usb->ep0->empty_frame_Q); if (!pkt) {
fhci_dbg(usb->fhci, "there is no empty frame\n"); return -1;
}
td->pkt = pkt;
pkt->info = 0; if (data == NULL) {
data = cq_get(&usb->ep0->dummy_packets_Q);
BUG_ON(!data);
pkt->info = PKT_DUMMY_PACKET;
}
pkt->data = data;
pkt->len = len;
pkt->status = USB_TD_OK; /* update TD status field before transmitting */
td->status = USB_TD_INPROGRESS; /* update actual frame time object with the actual transmission */
usb->actual_frame->total_bytes += (len + PROTOCOL_OVERHEAD);
fhci_add_td_to_frame(usb->actual_frame, td);
/* * if it isn't interrupt pipe or it is not iso pipe and the * interval time passed
*/ if ((list_type == FHCI_TF_INTR || list_type == FHCI_TF_ISO) &&
(((usb->actual_frame->frame_num -
td->start_frame) & 0x7ff) < td->interval)) continue;
if (add_packet(usb, ed, td) < 0) continue;
/* update time stamps in the TD */
td->start_frame = usb->actual_frame->frame_num;
usb->sw_transaction_time += save_transaction_time;
if (usb->actual_frame->total_bytes >=
usb->max_bytes_per_frame) {
usb->actual_frame->frame_status =
FRAME_DATA_END_TRANSMISSION;
fhci_push_dummy_bd(usb->ep0);
ans = 0; break;
}
if (usb->actual_frame->total_bytes >= frame_part[list_type]) break;
}
/* be fair to each ED(move list head around) */
move_head_to_tail(list);
usb->sw_transaction_time = save_transaction_time;
/* * This function schedule the USB transaction and will process the * endpoint in the following order: iso, interrupt, control and bulk.
*/ void fhci_schedule_transactions(struct fhci_usb *usb)
{ int left = 1;
if (usb->actual_frame->frame_status & FRAME_END_TRANSMISSION) if (rotate_frames(usb) != 0) return;
if (usb->actual_frame->frame_status & FRAME_END_TRANSMISSION) return;
if (usb->actual_frame->total_bytes == 0) { /* * schedule the next available ISO transfer *or next stage of the ISO transfer
*/
scan_ed_list(usb, &usb->hc_list->iso_list, FHCI_TF_ISO);
/* * schedule the next available interrupt transfer or * the next stage of the interrupt transfer
*/
scan_ed_list(usb, &usb->hc_list->intr_list, FHCI_TF_INTR);
/* * schedule the next available control transfer * or the next stage of the control transfer
*/
left = scan_ed_list(usb, &usb->hc_list->ctrl_list,
FHCI_TF_CTRL);
}
/* * schedule the next available bulk transfer or the next stage of the * bulk transfer
*/ if (left > 0)
scan_ed_list(usb, &usb->hc_list->bulk_list, FHCI_TF_BULK);
}
/* Enable IDLE since we want to know if something comes along */
usb->saved_msk |= USB_E_IDLE_MASK;
out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
/* detect a new device connected on the USB port */ void fhci_device_connected_interrupt(struct fhci_hcd *fhci)
{
struct fhci_usb *usb = fhci->usb_lld; int state; int ret;
fhci_dbg(fhci, "-> %s\n", __func__);
fhci_usb_disable_interrupt(usb);
state = fhci_ioports_check_bus_state(fhci);
/* low-speed device was connected to the USB port */ if (state == 1) {
ret = qe_usb_clock_set(fhci->lowspeed_clk, USB_CLOCK >> 3); if (ret) {
fhci_warn(fhci, "Low-Speed device is not supported, " "try use BRGx\n"); goto out;
}
usb->port_status = FHCI_PORT_LOW;
setbits8(&usb->fhci->regs->usb_usmod, USB_MODE_LSS);
usb->vroot_hub->port.wPortStatus |=
(USB_PORT_STAT_LOW_SPEED |
USB_PORT_STAT_CONNECTION);
usb->vroot_hub->port.wPortChange |=
USB_PORT_STAT_C_CONNECTION;
usb->max_bytes_per_frame =
(MAX_BYTES_PER_FRAME >> 3) - 7;
fhci_port_enable(usb);
} elseif (state == 2) {
ret = qe_usb_clock_set(fhci->fullspeed_clk, USB_CLOCK); if (ret) {
fhci_warn(fhci, "Full-Speed device is not supported, " "try use CLKx\n"); goto out;
}
/* * Process normal completions(error or success) and clean the schedule. * * This is the main path for handing urbs back to drivers. The only other patth * is process_del_list(),which unlinks URBs by scanning EDs,instead of scanning * the (re-reversed) done list as this does.
*/ staticvoid process_done_list(unsignedlong data)
{ struct urb *urb; struct ed *ed; struct td *td; struct urb_priv *urb_priv; struct fhci_hcd *fhci = (struct fhci_hcd *)data;
td = fhci_remove_td_from_done_list(fhci->hc_list); while (td != NULL) {
urb = td->urb;
urb_priv = urb->hcpriv;
ed = td->ed;
/* update URB's length and status from TD */
fhci_done_td(urb, td);
urb_priv->tds_cnt++;
/* * if all this urb's TDs are done, call complete() * Interrupt transfers are the onley special case: * they are reissued,until "deleted" by usb_unlink_urb * (real work done in a SOF intr, by process_del_list)
*/ if (urb_priv->tds_cnt == urb_priv->num_of_tds) {
fhci_urb_complete_free(fhci, urb);
} elseif (urb_priv->state == URB_DEL &&
ed->state == FHCI_ED_SKIP) {
fhci_del_ed_list(fhci, ed);
ed->state = FHCI_ED_OPER;
} elseif (ed->state == FHCI_ED_HALTED) {
urb_priv->state = URB_DEL;
ed->state = FHCI_ED_URB_DEL;
fhci_del_ed_list(fhci, ed);
ed->state = FHCI_ED_OPER;
}
/* transfer completed callback */
u32 fhci_transfer_confirm_callback(struct fhci_hcd *fhci)
{ if (!fhci->process_done_task->state)
tasklet_schedule(fhci->process_done_task); return 0;
}
/* * adds urb to the endpoint descriptor list * arguments: * fhci data structure for the Low level host controller * ep USB Host endpoint data structure * urb USB request block data structure
*/ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)
{ struct ed *ed = urb->ep->hcpriv; struct urb_priv *urb_priv = urb->hcpriv;
u32 data_len = urb->transfer_buffer_length; int urb_state = 0; int toggle = 0;
u8 *data;
u16 cnt = 0;
if (ed == NULL) {
ed = fhci_get_empty_ed(fhci);
ed->dev_addr = usb_pipedevice(urb->pipe);
ed->ep_addr = usb_pipeendpoint(urb->pipe); switch (usb_pipetype(urb->pipe)) { case PIPE_CONTROL:
ed->mode = FHCI_TF_CTRL; break; case PIPE_BULK:
ed->mode = FHCI_TF_BULK; break; case PIPE_INTERRUPT:
ed->mode = FHCI_TF_INTR; break; case PIPE_ISOCHRONOUS:
ed->mode = FHCI_TF_ISO; break; default: break;
}
ed->speed = (urb->dev->speed == USB_SPEED_LOW) ?
FHCI_LOW_SPEED : FHCI_FULL_SPEED;
ed->max_pkt_size = usb_endpoint_maxp(&urb->ep->desc);
urb->ep->hcpriv = ed;
fhci_dbg(fhci, "new ep speed=%d max_pkt_size=%d\n",
ed->speed, ed->max_pkt_size);
}
/* for ISO transfer calculate start frame index */ if (ed->mode == FHCI_TF_ISO) { /* Ignore the possibility of underruns */
urb->start_frame = ed->td_head ? ed->next_iso :
get_frame_num(fhci);
ed->next_iso = (urb->start_frame + urb->interval *
urb->number_of_packets) & 0x07ff;
}
/* * OHCI handles the DATA toggle itself,we just use the USB * toggle bits
*/ if (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
usb_pipeout(urb->pipe)))
toggle = USB_TD_TOGGLE_CARRY; else {
toggle = USB_TD_TOGGLE_DATA0;
usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
usb_pipeout(urb->pipe), 1);
}
urb_priv->tds_cnt = 0;
urb_priv->ed = ed; if (data_len > 0)
data = urb->transfer_buffer; else
data = NULL;
urb_state = US_CTRL_SETUP; break; case FHCI_TF_ISO: for (cnt = 0; cnt < urb->number_of_packets; cnt++) {
u16 frame = urb->start_frame;
/* * FIXME scheduling should handle frame counter * roll-around ... exotic case (and OHCI has * a 2^16 iso range, vs other HCs max of 2^10)
*/
frame += cnt * urb->interval;
frame &= 0x07ff;
fhci_td_fill(fhci, urb, urb_priv, ed, cnt,
usb_pipeout(urb->pipe) ? FHCI_TA_OUT :
FHCI_TA_IN,
USB_TD_TOGGLE_DATA0,
data + urb->iso_frame_desc[cnt].offset,
urb->iso_frame_desc[cnt].length,
urb->interval, frame, true);
} break; default: break;
}
/* * set the state of URB * control pipe:3 states -- setup,data,status * interrupt and bulk pipe:1 state -- data
*/
urb->pipe &= ~0x1f;
urb->pipe |= urb_state & 0x1f;
urb_priv->state = URB_INPROGRESS;
if (!ed->td_head) {
ed->state = FHCI_ED_OPER; switch (ed->mode) { case FHCI_TF_CTRL:
list_add(&ed->node, &fhci->hc_list->ctrl_list); break; case FHCI_TF_BULK:
list_add(&ed->node, &fhci->hc_list->bulk_list); break; case FHCI_TF_INTR:
list_add(&ed->node, &fhci->hc_list->intr_list); break; case FHCI_TF_ISO:
list_add(&ed->node, &fhci->hc_list->iso_list); break; default: break;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.