Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Freescale QUICC Engine USB Host Controller Driver
0004  *
0005  * Copyright (c) Freescale Semicondutor, Inc. 2006.
0006  *               Shlomi Gridish <gridish@freescale.com>
0007  *               Jerry Huang <Chang-Ming.Huang@freescale.com>
0008  * Copyright (c) Logic Product Development, Inc. 2007
0009  *               Peter Barada <peterb@logicpd.com>
0010  * Copyright (c) MontaVista Software, Inc. 2008.
0011  *               Anton Vorontsov <avorontsov@ru.mvista.com>
0012  */
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/types.h>
0016 #include <linux/delay.h>
0017 #include <linux/slab.h>
0018 #include <linux/list.h>
0019 #include <linux/usb.h>
0020 #include <linux/usb/hcd.h>
0021 #include "fhci.h"
0022 
0023 static void init_td(struct td *td)
0024 {
0025     memset(td, 0, sizeof(*td));
0026     INIT_LIST_HEAD(&td->node);
0027     INIT_LIST_HEAD(&td->frame_lh);
0028 }
0029 
0030 static void init_ed(struct ed *ed)
0031 {
0032     memset(ed, 0, sizeof(*ed));
0033     INIT_LIST_HEAD(&ed->td_list);
0034     INIT_LIST_HEAD(&ed->node);
0035 }
0036 
0037 static struct td *get_empty_td(struct fhci_hcd *fhci)
0038 {
0039     struct td *td;
0040 
0041     if (!list_empty(&fhci->empty_tds)) {
0042         td = list_entry(fhci->empty_tds.next, struct td, node);
0043         list_del(fhci->empty_tds.next);
0044     } else {
0045         td = kmalloc(sizeof(*td), GFP_ATOMIC);
0046         if (!td)
0047             fhci_err(fhci, "No memory to allocate to TD\n");
0048         else
0049             init_td(td);
0050     }
0051 
0052     return td;
0053 }
0054 
0055 void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td)
0056 {
0057     init_td(td);
0058     list_add(&td->node, &fhci->empty_tds);
0059 }
0060 
0061 struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci)
0062 {
0063     struct ed *ed;
0064 
0065     if (!list_empty(&fhci->empty_eds)) {
0066         ed = list_entry(fhci->empty_eds.next, struct ed, node);
0067         list_del(fhci->empty_eds.next);
0068     } else {
0069         ed = kmalloc(sizeof(*ed), GFP_ATOMIC);
0070         if (!ed)
0071             fhci_err(fhci, "No memory to allocate to ED\n");
0072         else
0073             init_ed(ed);
0074     }
0075 
0076     return ed;
0077 }
0078 
0079 void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed)
0080 {
0081     init_ed(ed);
0082     list_add(&ed->node, &fhci->empty_eds);
0083 }
0084 
0085 struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
0086             struct urb_priv *urb_priv, struct ed *ed, u16 index,
0087             enum fhci_ta_type type, int toggle, u8 *data, u32 len,
0088             u16 interval, u16 start_frame, bool ioc)
0089 {
0090     struct td *td = get_empty_td(fhci);
0091 
0092     if (!td)
0093         return NULL;
0094 
0095     td->urb = urb;
0096     td->ed = ed;
0097     td->type = type;
0098     td->toggle = toggle;
0099     td->data = data;
0100     td->len = len;
0101     td->iso_index = index;
0102     td->interval = interval;
0103     td->start_frame = start_frame;
0104     td->ioc = ioc;
0105     td->status = USB_TD_OK;
0106 
0107     urb_priv->tds[index] = td;
0108 
0109     return td;
0110 }