5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
285 lines
6.9 KiB
C
285 lines
6.9 KiB
C
/*
|
|
* Freescale QUICC Engine USB Host Controller Driver
|
|
*
|
|
* Copyright (c) Freescale Semicondutor, Inc. 2006.
|
|
* Shlomi Gridish <gridish@freescale.com>
|
|
* Jerry Huang <Chang-Ming.Huang@freescale.com>
|
|
* Copyright (c) Logic Product Development, Inc. 2007
|
|
* Peter Barada <peterb@logicpd.com>
|
|
* Copyright (c) MontaVista Software, Inc. 2008.
|
|
* Anton Vorontsov <avorontsov@ru.mvista.com>
|
|
*
|
|
* 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 <linux/kernel.h>
|
|
#include <linux/types.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/list.h>
|
|
#include <linux/usb.h>
|
|
#include "../core/hcd.h"
|
|
#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);
|
|
}
|
|
}
|