/* * Freescale QUICC Engine USB Host Controller Driver * * Copyright (c) Freescale Semicondutor, Inc. 2006. * Shlomi Gridish * Jerry Huang * Copyright (c) Logic Product Development, Inc. 2007 * Peter Barada * Copyright (c) MontaVista Software, Inc. 2008. * Anton Vorontsov * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. */ #include #include #include #include #include #include #include #include #include "fhci.h" /* maps the hardware error code to the USB error code */ static int status_to_error(u32 status) { if (status == USB_TD_OK) return 0; else if (status & USB_TD_RX_ER_CRC) return -EILSEQ; else if (status & USB_TD_RX_ER_NONOCT) return -EPROTO; else if (status & USB_TD_RX_ER_OVERUN) return -ECOMM; else if (status & USB_TD_RX_ER_BITSTUFF) return -EPROTO; else if (status & USB_TD_RX_ER_PID) return -EILSEQ; else if (status & (USB_TD_TX_ER_NAK | USB_TD_TX_ER_TIMEOUT)) return -ETIMEDOUT; else if (status & USB_TD_TX_ER_STALL) return -EPIPE; else if (status & USB_TD_TX_ER_UNDERUN) return -ENOSR; else if (status & USB_TD_RX_DATA_UNDERUN) return -EREMOTEIO; else if (status & USB_TD_RX_DATA_OVERUN) return -EOVERFLOW; else return -EINVAL; } void fhci_add_td_to_frame(struct fhci_time_frame *frame, struct td *td) { list_add_tail(&td->frame_lh, &frame->tds_list); } void fhci_add_tds_to_ed(struct ed *ed, struct td **td_list, int number) { int i; for (i = 0; i < number; i++) { struct td *td = td_list[i]; list_add_tail(&td->node, &ed->td_list); } if (ed->td_head == NULL) ed->td_head = td_list[0]; } static struct td *peek_td_from_ed(struct ed *ed) { struct td *td; if (!list_empty(&ed->td_list)) td = list_entry(ed->td_list.next, struct td, node); else td = NULL; return td; } struct td *fhci_remove_td_from_frame(struct fhci_time_frame *frame) { struct td *td; if (!list_empty(&frame->tds_list)) { td = list_entry(frame->tds_list.next, struct td, frame_lh); list_del_init(frame->tds_list.next); } else td = NULL; return td; } struct td *fhci_peek_td_from_frame(struct fhci_time_frame *frame) { struct td *td; if (!list_empty(&frame->tds_list)) td = list_entry(frame->tds_list.next, struct td, frame_lh); else td = NULL; return td; } struct td *fhci_remove_td_from_ed(struct ed *ed) { struct td *td; if (!list_empty(&ed->td_list)) { td = list_entry(ed->td_list.next, struct td, node); list_del_init(ed->td_list.next); /* if this TD was the ED's head, find next TD */ if (!list_empty(&ed->td_list)) ed->td_head = list_entry(ed->td_list.next, struct td, node); else ed->td_head = NULL; } else td = NULL; return td; } struct td *fhci_remove_td_from_done_list(struct fhci_controller_list *p_list) { struct td *td; if (!list_empty(&p_list->done_list)) { td = list_entry(p_list->done_list.next, struct td, node); list_del_init(p_list->done_list.next); } else td = NULL; return td; } void fhci_move_td_from_ed_to_done_list(struct fhci_usb *usb, struct ed *ed) { struct td *td; td = ed->td_head; list_del_init(&td->node); /* If this TD was the ED's head,find next TD */ if (!list_empty(&ed->td_list)) ed->td_head = list_entry(ed->td_list.next, struct td, node); else { ed->td_head = NULL; ed->state = FHCI_ED_SKIP; } ed->toggle_carry = td->toggle; list_add_tail(&td->node, &usb->hc_list->done_list); if (td->ioc) usb->transfer_confirm(usb->fhci); } /* free done FHCI URB resource such as ED and TD */ static void free_urb_priv(struct fhci_hcd *fhci, struct urb *urb) { int i; struct urb_priv *urb_priv = urb->hcpriv; struct ed *ed = urb_priv->ed; for (i = 0; i < urb_priv->num_of_tds; i++) { list_del_init(&urb_priv->tds[i]->node); fhci_recycle_empty_td(fhci, urb_priv->tds[i]); } /* if this TD was the ED's head,find the next TD */ if (!list_empty(&ed->td_list)) ed->td_head = list_entry(ed->td_list.next, struct td, node); else ed->td_head = NULL; kfree(urb_priv->tds); kfree(urb_priv); urb->hcpriv = NULL; /* if this TD was the ED's head,find next TD */ if (ed->td_head == NULL) list_del_init(&ed->node); fhci->active_urbs--; } /* this routine called to complete and free done URB */ void fhci_urb_complete_free(struct fhci_hcd *fhci, struct urb *urb) { free_urb_priv(fhci, urb); if (urb->status == -EINPROGRESS) { if (urb->actual_length != urb->transfer_buffer_length && urb->transfer_flags & URB_SHORT_NOT_OK) urb->status = -EREMOTEIO; else urb->status = 0; } usb_hcd_unlink_urb_from_ep(fhci_to_hcd(fhci), urb); spin_unlock(&fhci->lock); usb_hcd_giveback_urb(fhci_to_hcd(fhci), urb, urb->status); spin_lock(&fhci->lock); } /* * caculate transfer length/stats and update the urb * Precondition: irqsafe(only for urb-?status locking) */ void fhci_done_td(struct urb *urb, struct td *td) { struct ed *ed = td->ed; u32 cc = td->status; /* ISO...drivers see per-TD length/status */ if (ed->mode == FHCI_TF_ISO) { u32 len; if (!(urb->transfer_flags & URB_SHORT_NOT_OK && cc == USB_TD_RX_DATA_UNDERUN)) cc = USB_TD_OK; if (usb_pipeout(urb->pipe)) len = urb->iso_frame_desc[td->iso_index].length; else len = td->actual_len; urb->actual_length += len; urb->iso_frame_desc[td->iso_index].actual_length = len; urb->iso_frame_desc[td->iso_index].status = status_to_error(cc); } /* BULK,INT,CONTROL... drivers see aggregate length/status, * except that "setup" bytes aren't counted and "short" transfers * might not be reported as errors. */ else { if (td->error_cnt >= 3) urb->error_count = 3; /* control endpoint only have soft stalls */ /* update packet status if needed(short may be ok) */ if (!(urb->transfer_flags & URB_SHORT_NOT_OK) && cc == USB_TD_RX_DATA_UNDERUN) { ed->state = FHCI_ED_OPER; cc = USB_TD_OK; } if (cc != USB_TD_OK) { if (urb->status == -EINPROGRESS) urb->status = status_to_error(cc); } /* count all non-empty packets except control SETUP packet */ if (td->type != FHCI_TA_SETUP || td->iso_index != 0) urb->actual_length += td->actual_len; } } /* there are some pedning request to unlink */ void fhci_del_ed_list(struct fhci_hcd *fhci, struct ed *ed) { struct td *td = peek_td_from_ed(ed); struct urb *urb = td->urb; struct urb_priv *urb_priv = urb->hcpriv; if (urb_priv->state == URB_DEL) { td = fhci_remove_td_from_ed(ed); /* HC may have partly processed this TD */ if (td->status != USB_TD_INPROGRESS) fhci_done_td(urb, td); /* URB is done;clean up */ if (++(urb_priv->tds_cnt) == urb_priv->num_of_tds) fhci_urb_complete_free(fhci, urb); } } harmonize_features(), from Eric Dumazet. 7) Fix RTNL deadlock wrt. lwtunnel module loading, from David Ahern. 8) tcp_fastopen_create_child() needs to setup tp->max_window, from Alexey Kodanev. 9) Missing kmemdup() failure check in ipv6 segment routing code, from Eric Dumazet. 10) Don't execute unix_bind() under the bindlock, otherwise we deadlock with splice. From WANG Cong. 11) ip6_tnl_parse_tlv_enc_lim() potentially reallocates the skb buffer, therefore callers must reload cached header pointers into that skb. Fix from Eric Dumazet. 12) Fix various bugs in legacy IRQ fallback handling in alx driver, from Tobias Regnery. 13) Do not allow lwtunnel drivers to be unloaded while they are referenced by active instances, from Robert Shearman. 14) Fix truncated PHY LED trigger names, from Geert Uytterhoeven. 15) Fix a few regressions from virtio_net XDP support, from John Fastabend and Jakub Kicinski. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: (102 commits) ISDN: eicon: silence misleading array-bounds warning net: phy: micrel: add support for KSZ8795 gtp: fix cross netns recv on gtp socket gtp: clear DF bit on GTP packet tx gtp: add genl family modules alias tcp: don't annotate mark on control socket from tcp_v6_send_response() ravb: unmap descriptors when freeing rings virtio_net: reject XDP programs using header adjustment virtio_net: use dev_kfree_skb for small buffer XDP receive r8152: check rx after napi is enabled r8152: re-schedule napi for tx r8152: avoid start_xmit to schedule napi when napi is disabled r8152: avoid start_xmit to call napi_schedule during autosuspend net: dsa: Bring back device detaching in dsa_slave_suspend() net: phy: leds: Fix truncated LED trigger names net: phy: leds: Break dependency of phy.h on phy_led_triggers.h net: phy: leds: Clear phy_num_led_triggers on failure to avoid crash net-next: ethernet: mediatek: change the compatible string Documentation: devicetree: change the mediatek ethernet compatible string bnxt_en: Fix RTNL lock usage on bnxt_get_port_module_status(). ...
Diffstat (limited to 'drivers/usb/storage/debug.h')