^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Freescale QUICC Engine USB Host Controller Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) Freescale Semicondutor, Inc. 2006.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Shlomi Gridish <gridish@freescale.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Jerry Huang <Chang-Ming.Huang@freescale.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) Logic Product Development, Inc. 2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Peter Barada <peterb@logicpd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) MontaVista Software, Inc. 2008.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Anton Vorontsov <avorontsov@ru.mvista.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "fhci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static void init_td(struct td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) memset(td, 0, sizeof(*td));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) INIT_LIST_HEAD(&td->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) INIT_LIST_HEAD(&td->frame_lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static void init_ed(struct ed *ed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) memset(ed, 0, sizeof(*ed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) INIT_LIST_HEAD(&ed->td_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) INIT_LIST_HEAD(&ed->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static struct td *get_empty_td(struct fhci_hcd *fhci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (!list_empty(&fhci->empty_tds)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) td = list_entry(fhci->empty_tds.next, struct td, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) list_del(fhci->empty_tds.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) td = kmalloc(sizeof(*td), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) fhci_err(fhci, "No memory to allocate to TD\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) init_td(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) init_td(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) list_add(&td->node, &fhci->empty_tds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct ed *ed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (!list_empty(&fhci->empty_eds)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ed = list_entry(fhci->empty_eds.next, struct ed, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) list_del(fhci->empty_eds.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ed = kmalloc(sizeof(*ed), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!ed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) fhci_err(fhci, "No memory to allocate to ED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) init_ed(ed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return ed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) init_ed(ed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) list_add(&ed->node, &fhci->empty_eds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct urb_priv *urb_priv, struct ed *ed, u16 index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) enum fhci_ta_type type, int toggle, u8 *data, u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u16 interval, u16 start_frame, bool ioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct td *td = get_empty_td(fhci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) td->urb = urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) td->ed = ed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) td->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) td->toggle = toggle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) td->data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) td->len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) td->iso_index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) td->interval = interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) td->start_frame = start_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) td->ioc = ioc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) td->status = USB_TD_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) urb_priv->tds[index] = td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }