Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Host Controller Driver for the Elan Digital Systems U132 adapter |
| 4 | * |
| 5 | * Copyright(C) 2006 Elan Digital Systems Limited |
| 6 | * http://www.elandigitalsystems.com |
| 7 | * |
| 8 | * Author and Maintainer - Tony Olech - Elan Digital Systems |
| 9 | * tony.olech@elandigitalsystems.com |
| 10 | * |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 11 | * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com) |
| 12 | * based on various USB host drivers in the 2.6.15 linux kernel |
| 13 | * with constant reference to the 3rd Edition of Linux Device Drivers |
| 14 | * published by O'Reilly |
| 15 | * |
| 16 | * The U132 adapter is a USB to CardBus adapter specifically designed |
| 17 | * for PC cards that contain an OHCI host controller. Typical PC cards |
| 18 | * are the Orange Mobile 3G Option GlobeTrotter Fusion card. |
| 19 | * |
| 20 | * The U132 adapter will *NOT *work with PC cards that do not contain |
| 21 | * an OHCI controller. A simple way to test whether a PC card has an |
| 22 | * OHCI controller as an interface is to insert the PC card directly |
| 23 | * into a laptop(or desktop) with a CardBus slot and if "lspci" shows |
| 24 | * a new USB controller and "lsusb -v" shows a new OHCI Host Controller |
| 25 | * then there is a good chance that the U132 adapter will support the |
| 26 | * PC card.(you also need the specific client driver for the PC card) |
| 27 | * |
| 28 | * Please inform the Author and Maintainer about any PC cards that |
| 29 | * contain OHCI Host Controller and work when directly connected to |
| 30 | * an embedded CardBus slot but do not work when they are connected |
| 31 | * via an ELAN U132 adapter. |
| 32 | * |
| 33 | */ |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 34 | #include <linux/kernel.h> |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/moduleparam.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/ioport.h> |
Tony Olech | 4b87361 | 2006-12-06 13:16:22 +0000 | [diff] [blame] | 39 | #include <linux/pci_ids.h> |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 40 | #include <linux/sched.h> |
| 41 | #include <linux/slab.h> |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 42 | #include <linux/errno.h> |
| 43 | #include <linux/init.h> |
| 44 | #include <linux/timer.h> |
| 45 | #include <linux/list.h> |
| 46 | #include <linux/interrupt.h> |
| 47 | #include <linux/usb.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 48 | #include <linux/usb/hcd.h> |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 49 | #include <linux/workqueue.h> |
| 50 | #include <linux/platform_device.h> |
Matthias Kaehlcke | d2066eb | 2007-07-13 21:26:59 +0200 | [diff] [blame] | 51 | #include <linux/mutex.h> |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 52 | #include <asm/io.h> |
| 53 | #include <asm/irq.h> |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 54 | #include <asm/byteorder.h> |
David Brownell | 47f8468 | 2007-04-29 10:21:14 -0700 | [diff] [blame] | 55 | |
| 56 | /* FIXME ohci.h is ONLY for internal use by the OHCI driver. |
| 57 | * If you're going to try stuff like this, you need to split |
| 58 | * out shareable stuff (register declarations?) into its own |
| 59 | * file, maybe name <linux/usb/ohci.h> |
| 60 | */ |
| 61 | |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 62 | #include "ohci.h" |
| 63 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR |
| 64 | #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 65 | OHCI_INTR_WDH) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 66 | MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited"); |
| 67 | MODULE_DESCRIPTION("U132 USB Host Controller Driver"); |
| 68 | MODULE_LICENSE("GPL"); |
| 69 | #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444) |
| 70 | INT_MODULE_PARM(testing, 0); |
| 71 | /* Some boards misreport power switching/overcurrent*/ |
Geyslan G. Bem | 900937c | 2015-12-02 20:25:23 -0300 | [diff] [blame] | 72 | static bool distrust_firmware = true; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 73 | module_param(distrust_firmware, bool, 0); |
Colin Ian King | 8f9b622 | 2019-09-11 11:07:45 +0100 | [diff] [blame] | 74 | MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurrent" |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 75 | "t setup"); |
Adrian Bunk | 27a3de4 | 2006-11-20 03:23:54 +0100 | [diff] [blame] | 76 | static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 77 | /* |
| 78 | * u132_module_lock exists to protect access to global variables |
| 79 | * |
| 80 | */ |
Zheng Yongjun | 7c53624 | 2021-04-05 18:14:34 +0800 | [diff] [blame] | 81 | static DEFINE_MUTEX(u132_module_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 82 | static int u132_exiting; |
| 83 | static int u132_instances; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 84 | /* |
| 85 | * end of the global variables protected by u132_module_lock |
| 86 | */ |
| 87 | static struct workqueue_struct *workqueue; |
| 88 | #define MAX_U132_PORTS 7 |
| 89 | #define MAX_U132_ADDRS 128 |
| 90 | #define MAX_U132_UDEVS 4 |
| 91 | #define MAX_U132_ENDPS 100 |
| 92 | #define MAX_U132_RINGS 4 |
| 93 | static const char *cc_to_text[16] = { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 94 | "No Error ", |
| 95 | "CRC Error ", |
| 96 | "Bit Stuff ", |
| 97 | "Data Togg ", |
| 98 | "Stall ", |
| 99 | "DevNotResp ", |
| 100 | "PIDCheck ", |
| 101 | "UnExpPID ", |
| 102 | "DataOver ", |
| 103 | "DataUnder ", |
| 104 | "(for hw) ", |
| 105 | "(for hw) ", |
| 106 | "BufferOver ", |
| 107 | "BuffUnder ", |
| 108 | "(for HCD) ", |
| 109 | "(for HCD) " |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 110 | }; |
| 111 | struct u132_port { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 112 | struct u132 *u132; |
| 113 | int reset; |
| 114 | int enable; |
| 115 | int power; |
| 116 | int Status; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 117 | }; |
| 118 | struct u132_addr { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 119 | u8 address; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 120 | }; |
| 121 | struct u132_udev { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 122 | struct kref kref; |
| 123 | struct usb_device *usb_device; |
| 124 | u8 enumeration; |
| 125 | u8 udev_number; |
| 126 | u8 usb_addr; |
| 127 | u8 portnumber; |
| 128 | u8 endp_number_in[16]; |
| 129 | u8 endp_number_out[16]; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 130 | }; |
| 131 | #define ENDP_QUEUE_SHIFT 3 |
| 132 | #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT) |
| 133 | #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1) |
| 134 | struct u132_urbq { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 135 | struct list_head urb_more; |
| 136 | struct urb *urb; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 137 | }; |
| 138 | struct u132_spin { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 139 | spinlock_t slock; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 140 | }; |
| 141 | struct u132_endp { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 142 | struct kref kref; |
| 143 | u8 udev_number; |
| 144 | u8 endp_number; |
| 145 | u8 usb_addr; |
| 146 | u8 usb_endp; |
| 147 | struct u132 *u132; |
| 148 | struct list_head endp_ring; |
| 149 | struct u132_ring *ring; |
| 150 | unsigned toggle_bits:2; |
| 151 | unsigned active:1; |
| 152 | unsigned delayed:1; |
| 153 | unsigned input:1; |
| 154 | unsigned output:1; |
| 155 | unsigned pipetype:2; |
| 156 | unsigned dequeueing:1; |
| 157 | unsigned edset_flush:1; |
| 158 | unsigned spare_bits:14; |
| 159 | unsigned long jiffies; |
| 160 | struct usb_host_endpoint *hep; |
| 161 | struct u132_spin queue_lock; |
| 162 | u16 queue_size; |
| 163 | u16 queue_last; |
| 164 | u16 queue_next; |
| 165 | struct urb *urb_list[ENDP_QUEUE_SIZE]; |
| 166 | struct list_head urb_more; |
| 167 | struct delayed_work scheduler; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 168 | }; |
| 169 | struct u132_ring { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 170 | unsigned in_use:1; |
| 171 | unsigned length:7; |
| 172 | u8 number; |
| 173 | struct u132 *u132; |
| 174 | struct u132_endp *curr_endp; |
| 175 | struct delayed_work scheduler; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 176 | }; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 177 | struct u132 { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 178 | struct kref kref; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 179 | struct mutex sw_lock; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 180 | struct mutex scheduler_lock; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 181 | struct u132_platform_data *board; |
| 182 | struct platform_device *platform_dev; |
| 183 | struct u132_ring ring[MAX_U132_RINGS]; |
| 184 | int sequence_num; |
| 185 | int going; |
| 186 | int power; |
| 187 | int reset; |
| 188 | int num_ports; |
| 189 | u32 hc_control; |
| 190 | u32 hc_fminterval; |
| 191 | u32 hc_roothub_status; |
| 192 | u32 hc_roothub_a; |
| 193 | u32 hc_roothub_portstatus[MAX_ROOT_PORTS]; |
| 194 | int flags; |
| 195 | unsigned long next_statechange; |
| 196 | struct delayed_work monitor; |
| 197 | int num_endpoints; |
| 198 | struct u132_addr addr[MAX_U132_ADDRS]; |
| 199 | struct u132_udev udev[MAX_U132_UDEVS]; |
| 200 | struct u132_port port[MAX_U132_PORTS]; |
| 201 | struct u132_endp *endp[MAX_U132_ENDPS]; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 202 | }; |
Adrian Bunk | 9ce8540 | 2006-11-20 03:24:44 +0100 | [diff] [blame] | 203 | |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 204 | /* |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 205 | * these cannot be inlines because we need the structure offset!! |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 206 | * Does anyone have a better way????? |
| 207 | */ |
Tony Olech | 4b87361 | 2006-12-06 13:16:22 +0000 | [diff] [blame] | 208 | #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \ |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 209 | offsetof(struct ohci_regs, member), 0, data); |
Tony Olech | 4b87361 | 2006-12-06 13:16:22 +0000 | [diff] [blame] | 210 | #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \ |
Tom Rix | 21f5b2f | 2020-11-27 11:03:36 -0800 | [diff] [blame] | 211 | offsetof(struct ohci_regs, member), 0, data) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 212 | #define u132_read_pcimem(u132, member, data) \ |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 213 | usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \ |
Tom Rix | 21f5b2f | 2020-11-27 11:03:36 -0800 | [diff] [blame] | 214 | ohci_regs, member), 0, data) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 215 | #define u132_write_pcimem(u132, member, data) \ |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 216 | usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \ |
Tom Rix | 21f5b2f | 2020-11-27 11:03:36 -0800 | [diff] [blame] | 217 | ohci_regs, member), 0, data) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 218 | static inline struct u132 *udev_to_u132(struct u132_udev *udev) |
| 219 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 220 | u8 udev_number = udev->udev_number; |
| 221 | return container_of(udev, struct u132, udev[udev_number]); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd) |
| 225 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 226 | return (struct u132 *)(hcd->hcd_priv); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | static inline struct usb_hcd *u132_to_hcd(struct u132 *u132) |
| 230 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 231 | return container_of((void *)u132, struct usb_hcd, hcd_priv); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static inline void u132_disable(struct u132 *u132) |
| 235 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 236 | u132_to_hcd(u132)->state = HC_STATE_HALT; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
| 240 | #define kref_to_u132(d) container_of(d, struct u132, kref) |
| 241 | #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref) |
| 242 | #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref) |
| 243 | #include "../misc/usb_u132.h" |
| 244 | static const char hcd_name[] = "u132_hcd"; |
| 245 | #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \ |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 246 | USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \ |
| 247 | USB_PORT_STAT_C_RESET) << 16) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 248 | static void u132_hcd_delete(struct kref *kref) |
| 249 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 250 | struct u132 *u132 = kref_to_u132(kref); |
| 251 | struct platform_device *pdev = u132->platform_dev; |
| 252 | struct usb_hcd *hcd = u132_to_hcd(u132); |
| 253 | u132->going += 1; |
| 254 | mutex_lock(&u132_module_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 255 | u132_instances -= 1; |
| 256 | mutex_unlock(&u132_module_lock); |
| 257 | dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" |
| 258 | "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); |
| 259 | usb_put_hcd(hcd); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static inline void u132_u132_put_kref(struct u132 *u132) |
| 263 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 264 | kref_put(&u132->kref, u132_hcd_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static inline void u132_u132_init_kref(struct u132 *u132) |
| 268 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 269 | kref_init(&u132->kref); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static void u132_udev_delete(struct kref *kref) |
| 273 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 274 | struct u132_udev *udev = kref_to_u132_udev(kref); |
| 275 | udev->udev_number = 0; |
| 276 | udev->usb_device = NULL; |
| 277 | udev->usb_addr = 0; |
| 278 | udev->enumeration = 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev) |
| 282 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 283 | kref_put(&udev->kref, u132_udev_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev) |
| 287 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 288 | kref_get(&udev->kref); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | static inline void u132_udev_init_kref(struct u132 *u132, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 292 | struct u132_udev *udev) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 293 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 294 | kref_init(&udev->kref); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring) |
| 298 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 299 | kref_put(&u132->kref, u132_hcd_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 303 | unsigned int delta) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 304 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 305 | if (delta > 0) { |
| 306 | if (queue_delayed_work(workqueue, &ring->scheduler, delta)) |
| 307 | return; |
| 308 | } else if (queue_delayed_work(workqueue, &ring->scheduler, 0)) |
| 309 | return; |
| 310 | kref_put(&u132->kref, u132_hcd_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 314 | unsigned int delta) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 315 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 316 | kref_get(&u132->kref); |
| 317 | u132_ring_requeue_work(u132, ring, delta); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring) |
| 321 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 322 | if (cancel_delayed_work(&ring->scheduler)) |
| 323 | kref_put(&u132->kref, u132_hcd_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void u132_endp_delete(struct kref *kref) |
| 327 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 328 | struct u132_endp *endp = kref_to_u132_endp(kref); |
| 329 | struct u132 *u132 = endp->u132; |
| 330 | u8 usb_addr = endp->usb_addr; |
| 331 | u8 usb_endp = endp->usb_endp; |
| 332 | u8 address = u132->addr[usb_addr].address; |
| 333 | struct u132_udev *udev = &u132->udev[address]; |
| 334 | u8 endp_number = endp->endp_number; |
| 335 | struct usb_host_endpoint *hep = endp->hep; |
| 336 | struct u132_ring *ring = endp->ring; |
| 337 | struct list_head *head = &endp->endp_ring; |
| 338 | ring->length -= 1; |
| 339 | if (endp == ring->curr_endp) { |
| 340 | if (list_empty(head)) { |
| 341 | ring->curr_endp = NULL; |
| 342 | list_del(head); |
| 343 | } else { |
| 344 | struct u132_endp *next_endp = list_entry(head->next, |
| 345 | struct u132_endp, endp_ring); |
| 346 | ring->curr_endp = next_endp; |
| 347 | list_del(head); |
| 348 | } |
| 349 | } else |
| 350 | list_del(head); |
| 351 | if (endp->input) { |
| 352 | udev->endp_number_in[usb_endp] = 0; |
| 353 | u132_udev_put_kref(u132, udev); |
| 354 | } |
| 355 | if (endp->output) { |
| 356 | udev->endp_number_out[usb_endp] = 0; |
| 357 | u132_udev_put_kref(u132, udev); |
| 358 | } |
| 359 | u132->endp[endp_number - 1] = NULL; |
| 360 | hep->hcpriv = NULL; |
| 361 | kfree(endp); |
| 362 | u132_u132_put_kref(u132); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp) |
| 366 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 367 | kref_put(&endp->kref, u132_endp_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp) |
| 371 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 372 | kref_get(&endp->kref); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static inline void u132_endp_init_kref(struct u132 *u132, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 376 | struct u132_endp *endp) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 377 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 378 | kref_init(&endp->kref); |
| 379 | kref_get(&u132->kref); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 383 | unsigned int delta) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 384 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 385 | if (queue_delayed_work(workqueue, &endp->scheduler, delta)) |
| 386 | kref_get(&endp->kref); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp) |
| 390 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 391 | if (cancel_delayed_work(&endp->scheduler)) |
| 392 | kref_put(&endp->kref, u132_endp_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static inline void u132_monitor_put_kref(struct u132 *u132) |
| 396 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 397 | kref_put(&u132->kref, u132_hcd_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta) |
| 401 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 402 | if (queue_delayed_work(workqueue, &u132->monitor, delta)) |
| 403 | kref_get(&u132->kref); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta) |
| 407 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 408 | if (!queue_delayed_work(workqueue, &u132->monitor, delta)) |
| 409 | kref_put(&u132->kref, u132_hcd_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static void u132_monitor_cancel_work(struct u132 *u132) |
| 413 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 414 | if (cancel_delayed_work(&u132->monitor)) |
| 415 | kref_put(&u132->kref, u132_hcd_delete); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static int read_roothub_info(struct u132 *u132) |
| 419 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 420 | u32 revision; |
| 421 | int retval; |
| 422 | retval = u132_read_pcimem(u132, revision, &revision); |
| 423 | if (retval) { |
| 424 | dev_err(&u132->platform_dev->dev, "error %d accessing device co" |
| 425 | "ntrol\n", retval); |
| 426 | return retval; |
| 427 | } else if ((revision & 0xFF) == 0x10) { |
| 428 | } else if ((revision & 0xFF) == 0x11) { |
| 429 | } else { |
| 430 | dev_err(&u132->platform_dev->dev, "device revision is not valid" |
| 431 | " %08X\n", revision); |
| 432 | return -ENODEV; |
| 433 | } |
| 434 | retval = u132_read_pcimem(u132, control, &u132->hc_control); |
| 435 | if (retval) { |
| 436 | dev_err(&u132->platform_dev->dev, "error %d accessing device co" |
| 437 | "ntrol\n", retval); |
| 438 | return retval; |
| 439 | } |
| 440 | retval = u132_read_pcimem(u132, roothub.status, |
| 441 | &u132->hc_roothub_status); |
| 442 | if (retval) { |
| 443 | dev_err(&u132->platform_dev->dev, "error %d accessing device re" |
| 444 | "g roothub.status\n", retval); |
| 445 | return retval; |
| 446 | } |
| 447 | retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a); |
| 448 | if (retval) { |
| 449 | dev_err(&u132->platform_dev->dev, "error %d accessing device re" |
| 450 | "g roothub.a\n", retval); |
| 451 | return retval; |
| 452 | } |
| 453 | { |
| 454 | int I = u132->num_ports; |
| 455 | int i = 0; |
| 456 | while (I-- > 0) { |
| 457 | retval = u132_read_pcimem(u132, roothub.portstatus[i], |
| 458 | &u132->hc_roothub_portstatus[i]); |
| 459 | if (retval) { |
| 460 | dev_err(&u132->platform_dev->dev, "error %d acc" |
| 461 | "essing device roothub.portstatus[%d]\n" |
| 462 | , retval, i); |
| 463 | return retval; |
| 464 | } else |
| 465 | i += 1; |
| 466 | } |
| 467 | } |
| 468 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 469 | } |
| 470 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 471 | static void u132_hcd_monitor_work(struct work_struct *work) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 472 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 473 | struct u132 *u132 = container_of(work, struct u132, monitor.work); |
| 474 | if (u132->going > 1) { |
| 475 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 476 | , u132->going); |
| 477 | u132_monitor_put_kref(u132); |
| 478 | return; |
| 479 | } else if (u132->going > 0) { |
| 480 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 481 | u132_monitor_put_kref(u132); |
| 482 | return; |
| 483 | } else { |
| 484 | int retval; |
| 485 | mutex_lock(&u132->sw_lock); |
| 486 | retval = read_roothub_info(u132); |
| 487 | if (retval) { |
| 488 | struct usb_hcd *hcd = u132_to_hcd(u132); |
| 489 | u132_disable(u132); |
| 490 | u132->going = 1; |
| 491 | mutex_unlock(&u132->sw_lock); |
| 492 | usb_hc_died(hcd); |
| 493 | ftdi_elan_gone_away(u132->platform_dev); |
| 494 | u132_monitor_put_kref(u132); |
| 495 | return; |
| 496 | } else { |
| 497 | u132_monitor_requeue_work(u132, 500); |
| 498 | mutex_unlock(&u132->sw_lock); |
| 499 | return; |
| 500 | } |
| 501 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 505 | struct urb *urb, int status) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 506 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 507 | struct u132_ring *ring; |
| 508 | unsigned long irqs; |
| 509 | struct usb_hcd *hcd = u132_to_hcd(u132); |
| 510 | urb->error_count = 0; |
| 511 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 512 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 513 | endp->queue_next += 1; |
| 514 | if (ENDP_QUEUE_SIZE > --endp->queue_size) { |
| 515 | endp->active = 0; |
| 516 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 517 | } else { |
| 518 | struct list_head *next = endp->urb_more.next; |
| 519 | struct u132_urbq *urbq = list_entry(next, struct u132_urbq, |
| 520 | urb_more); |
| 521 | list_del(next); |
| 522 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = |
| 523 | urbq->urb; |
| 524 | endp->active = 0; |
| 525 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 526 | kfree(urbq); |
| 527 | } |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 528 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 529 | ring = endp->ring; |
| 530 | ring->in_use = 0; |
| 531 | u132_ring_cancel_work(u132, ring); |
| 532 | u132_ring_queue_work(u132, ring, 0); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 533 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 534 | u132_endp_put_kref(u132, endp); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 535 | usb_hcd_giveback_urb(hcd, urb, status); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 539 | struct urb *urb, int status) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 540 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 541 | u132_endp_put_kref(u132, endp); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 545 | struct urb *urb, int status) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 546 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 547 | unsigned long irqs; |
| 548 | struct usb_hcd *hcd = u132_to_hcd(u132); |
| 549 | urb->error_count = 0; |
| 550 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 551 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 552 | endp->queue_next += 1; |
| 553 | if (ENDP_QUEUE_SIZE > --endp->queue_size) { |
| 554 | endp->active = 0; |
| 555 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 556 | } else { |
| 557 | struct list_head *next = endp->urb_more.next; |
| 558 | struct u132_urbq *urbq = list_entry(next, struct u132_urbq, |
| 559 | urb_more); |
| 560 | list_del(next); |
| 561 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = |
| 562 | urbq->urb; |
| 563 | endp->active = 0; |
| 564 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 565 | kfree(urbq); |
Joe Perches | 7f26b3a | 2010-08-04 10:40:08 -0700 | [diff] [blame] | 566 | } |
| 567 | usb_hcd_giveback_urb(hcd, urb, status); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | static inline int edset_input(struct u132 *u132, struct u132_ring *ring, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 571 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, |
| 572 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
| 573 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
| 574 | int halted, int skipped, int actual, int non_null)) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 575 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 576 | return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp, |
| 577 | urb, address, endp->usb_endp, toggle_bits, callback); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static inline int edset_setup(struct u132 *u132, struct u132_ring *ring, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 581 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, |
| 582 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
| 583 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
| 584 | int halted, int skipped, int actual, int non_null)) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 585 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 586 | return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp, |
| 587 | urb, address, endp->usb_endp, toggle_bits, callback); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | static inline int edset_single(struct u132 *u132, struct u132_ring *ring, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 591 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, |
| 592 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
| 593 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
| 594 | int halted, int skipped, int actual, int non_null)) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 595 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 596 | return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number, |
| 597 | endp, urb, address, endp->usb_endp, toggle_bits, callback); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static inline int edset_output(struct u132 *u132, struct u132_ring *ring, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 601 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, |
| 602 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
| 603 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
| 604 | int halted, int skipped, int actual, int non_null)) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 605 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 606 | return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number, |
| 607 | endp, urb, address, endp->usb_endp, toggle_bits, callback); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | |
| 611 | /* |
| 612 | * must not LOCK sw_lock |
| 613 | * |
| 614 | */ |
| 615 | static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 616 | int len, int toggle_bits, int error_count, int condition_code, |
| 617 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 618 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 619 | struct u132_endp *endp = data; |
| 620 | struct u132 *u132 = endp->u132; |
| 621 | u8 address = u132->addr[endp->usb_addr].address; |
| 622 | struct u132_udev *udev = &u132->udev[address]; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 623 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 624 | if (u132->going > 1) { |
| 625 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 626 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 627 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 628 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 629 | return; |
| 630 | } else if (endp->dequeueing) { |
| 631 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 632 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 633 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 634 | return; |
| 635 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 636 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 637 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 638 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 639 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 640 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 641 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 642 | struct u132_ring *ring = endp->ring; |
| 643 | u8 *u = urb->transfer_buffer + urb->actual_length; |
| 644 | u8 *b = buf; |
| 645 | int L = len; |
| 646 | |
| 647 | while (L-- > 0) |
| 648 | *u++ = *b++; |
| 649 | |
| 650 | urb->actual_length += len; |
| 651 | if ((condition_code == TD_CC_NOERROR) && |
| 652 | (urb->transfer_buffer_length > urb->actual_length)) { |
| 653 | endp->toggle_bits = toggle_bits; |
| 654 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, |
| 655 | 1 & toggle_bits); |
| 656 | if (urb->actual_length > 0) { |
| 657 | int retval; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 658 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 659 | retval = edset_single(u132, ring, endp, urb, |
| 660 | address, endp->toggle_bits, |
| 661 | u132_hcd_interrupt_recv); |
| 662 | if (retval != 0) |
| 663 | u132_hcd_giveback_urb(u132, endp, urb, |
| 664 | retval); |
| 665 | } else { |
| 666 | ring->in_use = 0; |
| 667 | endp->active = 0; |
| 668 | endp->jiffies = jiffies + |
| 669 | msecs_to_jiffies(urb->interval); |
| 670 | u132_ring_cancel_work(u132, ring); |
| 671 | u132_ring_queue_work(u132, ring, 0); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 672 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 673 | u132_endp_put_kref(u132, endp); |
| 674 | } |
| 675 | return; |
| 676 | } else if ((condition_code == TD_DATAUNDERRUN) && |
| 677 | ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { |
| 678 | endp->toggle_bits = toggle_bits; |
| 679 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, |
| 680 | 1 & toggle_bits); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 681 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 682 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 683 | return; |
| 684 | } else { |
| 685 | if (condition_code == TD_CC_NOERROR) { |
| 686 | endp->toggle_bits = toggle_bits; |
| 687 | usb_settoggle(udev->usb_device, endp->usb_endp, |
| 688 | 0, 1 & toggle_bits); |
| 689 | } else if (condition_code == TD_CC_STALL) { |
| 690 | endp->toggle_bits = 0x2; |
| 691 | usb_settoggle(udev->usb_device, endp->usb_endp, |
| 692 | 0, 0); |
| 693 | } else { |
| 694 | endp->toggle_bits = 0x2; |
| 695 | usb_settoggle(udev->usb_device, endp->usb_endp, |
| 696 | 0, 0); |
| 697 | dev_err(&u132->platform_dev->dev, "urb=%p givin" |
| 698 | "g back INTERRUPT %s\n", urb, |
| 699 | cc_to_text[condition_code]); |
| 700 | } |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 701 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 702 | u132_hcd_giveback_urb(u132, endp, urb, |
| 703 | cc_to_error[condition_code]); |
| 704 | return; |
| 705 | } |
| 706 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 707 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 708 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 709 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 710 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 711 | return; |
| 712 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 716 | int len, int toggle_bits, int error_count, int condition_code, |
| 717 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 718 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 719 | struct u132_endp *endp = data; |
| 720 | struct u132 *u132 = endp->u132; |
| 721 | u8 address = u132->addr[endp->usb_addr].address; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 722 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 723 | if (u132->going > 1) { |
| 724 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 725 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 726 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 727 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 728 | return; |
| 729 | } else if (endp->dequeueing) { |
| 730 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 731 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 732 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 733 | return; |
| 734 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 735 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 736 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 737 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 738 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 739 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 740 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 741 | struct u132_ring *ring = endp->ring; |
| 742 | urb->actual_length += len; |
| 743 | endp->toggle_bits = toggle_bits; |
| 744 | if (urb->transfer_buffer_length > urb->actual_length) { |
| 745 | int retval; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 746 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 747 | retval = edset_output(u132, ring, endp, urb, address, |
| 748 | endp->toggle_bits, u132_hcd_bulk_output_sent); |
| 749 | if (retval != 0) |
| 750 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 751 | return; |
| 752 | } else { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 753 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 754 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 755 | return; |
| 756 | } |
| 757 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 758 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 759 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 760 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 761 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 762 | return; |
| 763 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 767 | int len, int toggle_bits, int error_count, int condition_code, |
| 768 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 769 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 770 | struct u132_endp *endp = data; |
| 771 | struct u132 *u132 = endp->u132; |
| 772 | u8 address = u132->addr[endp->usb_addr].address; |
| 773 | struct u132_udev *udev = &u132->udev[address]; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 774 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 775 | if (u132->going > 1) { |
| 776 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 777 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 778 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 779 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 780 | return; |
| 781 | } else if (endp->dequeueing) { |
| 782 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 783 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 784 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 785 | return; |
| 786 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 787 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 788 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 789 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 790 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 791 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 792 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 793 | struct u132_ring *ring = endp->ring; |
| 794 | u8 *u = urb->transfer_buffer + urb->actual_length; |
| 795 | u8 *b = buf; |
| 796 | int L = len; |
| 797 | |
| 798 | while (L-- > 0) |
| 799 | *u++ = *b++; |
| 800 | |
| 801 | urb->actual_length += len; |
| 802 | if ((condition_code == TD_CC_NOERROR) && |
| 803 | (urb->transfer_buffer_length > urb->actual_length)) { |
| 804 | int retval; |
| 805 | endp->toggle_bits = toggle_bits; |
| 806 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, |
| 807 | 1 & toggle_bits); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 808 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 809 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, |
| 810 | ring->number, endp, urb, address, |
| 811 | endp->usb_endp, endp->toggle_bits, |
| 812 | u132_hcd_bulk_input_recv); |
| 813 | if (retval != 0) |
| 814 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 815 | return; |
| 816 | } else if (condition_code == TD_CC_NOERROR) { |
| 817 | endp->toggle_bits = toggle_bits; |
| 818 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, |
| 819 | 1 & toggle_bits); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 820 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 821 | u132_hcd_giveback_urb(u132, endp, urb, |
| 822 | cc_to_error[condition_code]); |
| 823 | return; |
| 824 | } else if ((condition_code == TD_DATAUNDERRUN) && |
| 825 | ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { |
| 826 | endp->toggle_bits = toggle_bits; |
| 827 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, |
| 828 | 1 & toggle_bits); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 829 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 830 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 831 | return; |
| 832 | } else if (condition_code == TD_DATAUNDERRUN) { |
| 833 | endp->toggle_bits = toggle_bits; |
| 834 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, |
| 835 | 1 & toggle_bits); |
| 836 | dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK" |
| 837 | ") giving back BULK IN %s\n", urb, |
| 838 | cc_to_text[condition_code]); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 839 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 840 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 841 | return; |
| 842 | } else if (condition_code == TD_CC_STALL) { |
| 843 | endp->toggle_bits = 0x2; |
| 844 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 845 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 846 | u132_hcd_giveback_urb(u132, endp, urb, |
| 847 | cc_to_error[condition_code]); |
| 848 | return; |
| 849 | } else { |
| 850 | endp->toggle_bits = 0x2; |
| 851 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); |
| 852 | dev_err(&u132->platform_dev->dev, "urb=%p giving back B" |
| 853 | "ULK IN code=%d %s\n", urb, condition_code, |
| 854 | cc_to_text[condition_code]); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 855 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 856 | u132_hcd_giveback_urb(u132, endp, urb, |
| 857 | cc_to_error[condition_code]); |
| 858 | return; |
| 859 | } |
| 860 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 861 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 862 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 863 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 864 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 865 | return; |
| 866 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 870 | int len, int toggle_bits, int error_count, int condition_code, |
| 871 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 872 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 873 | struct u132_endp *endp = data; |
| 874 | struct u132 *u132 = endp->u132; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 875 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 876 | if (u132->going > 1) { |
| 877 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 878 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 879 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 880 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 881 | return; |
| 882 | } else if (endp->dequeueing) { |
| 883 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 884 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 885 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 886 | return; |
| 887 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 888 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 889 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 890 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 891 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 892 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 893 | } else if (!urb->unlinked) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 894 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 895 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 896 | return; |
| 897 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 898 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 899 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 900 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 901 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 902 | return; |
| 903 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 907 | int len, int toggle_bits, int error_count, int condition_code, |
| 908 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 909 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 910 | struct u132_endp *endp = data; |
| 911 | struct u132 *u132 = endp->u132; |
| 912 | u8 address = u132->addr[endp->usb_addr].address; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 913 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 914 | if (u132->going > 1) { |
| 915 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 916 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 917 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 918 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 919 | return; |
| 920 | } else if (endp->dequeueing) { |
| 921 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 922 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 923 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 924 | return; |
| 925 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 926 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 927 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 928 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 929 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 930 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 931 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 932 | struct u132_ring *ring = endp->ring; |
| 933 | u8 *u = urb->transfer_buffer; |
| 934 | u8 *b = buf; |
| 935 | int L = len; |
| 936 | |
| 937 | while (L-- > 0) |
| 938 | *u++ = *b++; |
| 939 | |
| 940 | urb->actual_length = len; |
| 941 | if ((condition_code == TD_CC_NOERROR) || ((condition_code == |
| 942 | TD_DATAUNDERRUN) && ((urb->transfer_flags & |
| 943 | URB_SHORT_NOT_OK) == 0))) { |
| 944 | int retval; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 945 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 946 | retval = usb_ftdi_elan_edset_empty(u132->platform_dev, |
| 947 | ring->number, endp, urb, address, |
| 948 | endp->usb_endp, 0x3, |
| 949 | u132_hcd_configure_empty_sent); |
| 950 | if (retval != 0) |
| 951 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 952 | return; |
| 953 | } else if (condition_code == TD_CC_STALL) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 954 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 955 | dev_warn(&u132->platform_dev->dev, "giving back SETUP I" |
| 956 | "NPUT STALL urb %p\n", urb); |
| 957 | u132_hcd_giveback_urb(u132, endp, urb, |
| 958 | cc_to_error[condition_code]); |
| 959 | return; |
| 960 | } else { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 961 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 962 | dev_err(&u132->platform_dev->dev, "giving back SETUP IN" |
| 963 | "PUT %s urb %p\n", cc_to_text[condition_code], |
| 964 | urb); |
| 965 | u132_hcd_giveback_urb(u132, endp, urb, |
| 966 | cc_to_error[condition_code]); |
| 967 | return; |
| 968 | } |
| 969 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 970 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 971 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 972 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 973 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 974 | return; |
| 975 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 979 | int len, int toggle_bits, int error_count, int condition_code, |
| 980 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 981 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 982 | struct u132_endp *endp = data; |
| 983 | struct u132 *u132 = endp->u132; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 984 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 985 | if (u132->going > 1) { |
| 986 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 987 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 988 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 989 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 990 | return; |
| 991 | } else if (endp->dequeueing) { |
| 992 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 993 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 994 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 995 | return; |
| 996 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 997 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 998 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 999 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1000 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 1001 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1002 | } else if (!urb->unlinked) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1003 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1004 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 1005 | return; |
| 1006 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1007 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 1008 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1009 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 1010 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1011 | return; |
| 1012 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1016 | int len, int toggle_bits, int error_count, int condition_code, |
| 1017 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1018 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1019 | struct u132_endp *endp = data; |
| 1020 | struct u132 *u132 = endp->u132; |
| 1021 | u8 address = u132->addr[endp->usb_addr].address; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1022 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1023 | if (u132->going > 1) { |
| 1024 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1025 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1026 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1027 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 1028 | return; |
| 1029 | } else if (endp->dequeueing) { |
| 1030 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1031 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1032 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 1033 | return; |
| 1034 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1035 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 1036 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1037 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1038 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 1039 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1040 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1041 | if (usb_pipein(urb->pipe)) { |
| 1042 | int retval; |
| 1043 | struct u132_ring *ring = endp->ring; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1044 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1045 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, |
| 1046 | ring->number, endp, urb, address, |
| 1047 | endp->usb_endp, 0, |
| 1048 | u132_hcd_configure_input_recv); |
| 1049 | if (retval != 0) |
| 1050 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1051 | return; |
| 1052 | } else { |
| 1053 | int retval; |
| 1054 | struct u132_ring *ring = endp->ring; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1055 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1056 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, |
| 1057 | ring->number, endp, urb, address, |
| 1058 | endp->usb_endp, 0, |
| 1059 | u132_hcd_configure_empty_recv); |
| 1060 | if (retval != 0) |
| 1061 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1062 | return; |
| 1063 | } |
| 1064 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1065 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 1066 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1067 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 1068 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1069 | return; |
| 1070 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1074 | u8 *buf, int len, int toggle_bits, int error_count, int condition_code, |
| 1075 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1076 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1077 | struct u132_endp *endp = data; |
| 1078 | struct u132 *u132 = endp->u132; |
| 1079 | u8 address = u132->addr[endp->usb_addr].address; |
| 1080 | struct u132_udev *udev = &u132->udev[address]; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1081 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1082 | if (u132->going > 1) { |
| 1083 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1084 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1085 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1086 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 1087 | return; |
| 1088 | } else if (endp->dequeueing) { |
| 1089 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1090 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1091 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 1092 | return; |
| 1093 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1094 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 1095 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1096 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1097 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 1098 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1099 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1100 | u132->addr[0].address = 0; |
| 1101 | endp->usb_addr = udev->usb_addr; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1102 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1103 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 1104 | return; |
| 1105 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1106 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 1107 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1108 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 1109 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1110 | return; |
| 1111 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1115 | u8 *buf, int len, int toggle_bits, int error_count, int condition_code, |
| 1116 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1117 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1118 | struct u132_endp *endp = data; |
| 1119 | struct u132 *u132 = endp->u132; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1120 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1121 | if (u132->going > 1) { |
| 1122 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1123 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1124 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1125 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 1126 | return; |
| 1127 | } else if (endp->dequeueing) { |
| 1128 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1129 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1130 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 1131 | return; |
| 1132 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1133 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 1134 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1135 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1136 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 1137 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1138 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1139 | int retval; |
| 1140 | struct u132_ring *ring = endp->ring; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1141 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1142 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, |
| 1143 | ring->number, endp, urb, 0, endp->usb_endp, 0, |
| 1144 | u132_hcd_enumeration_empty_recv); |
| 1145 | if (retval != 0) |
| 1146 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1147 | return; |
| 1148 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1149 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 1150 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1151 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 1152 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1153 | return; |
| 1154 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1158 | int len, int toggle_bits, int error_count, int condition_code, |
| 1159 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1160 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1161 | struct u132_endp *endp = data; |
| 1162 | struct u132 *u132 = endp->u132; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1163 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1164 | if (u132->going > 1) { |
| 1165 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1166 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1167 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1168 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 1169 | return; |
| 1170 | } else if (endp->dequeueing) { |
| 1171 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1172 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1173 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 1174 | return; |
| 1175 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1176 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 1177 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1178 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1179 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 1180 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1181 | } else if (!urb->unlinked) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1182 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1183 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
| 1184 | return; |
| 1185 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1186 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 1187 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1188 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 1189 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1190 | return; |
| 1191 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1195 | int len, int toggle_bits, int error_count, int condition_code, |
| 1196 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1197 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1198 | struct u132_endp *endp = data; |
| 1199 | struct u132 *u132 = endp->u132; |
| 1200 | u8 address = u132->addr[endp->usb_addr].address; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1201 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1202 | if (u132->going > 1) { |
| 1203 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1204 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1205 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1206 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 1207 | return; |
| 1208 | } else if (endp->dequeueing) { |
| 1209 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1210 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1211 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 1212 | return; |
| 1213 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1214 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 1215 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1216 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1217 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 1218 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1219 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1220 | int retval; |
| 1221 | struct u132_ring *ring = endp->ring; |
| 1222 | u8 *u = urb->transfer_buffer; |
| 1223 | u8 *b = buf; |
| 1224 | int L = len; |
| 1225 | |
| 1226 | while (L-- > 0) |
| 1227 | *u++ = *b++; |
| 1228 | |
| 1229 | urb->actual_length = len; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1230 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1231 | retval = usb_ftdi_elan_edset_empty(u132->platform_dev, |
| 1232 | ring->number, endp, urb, address, endp->usb_endp, 0x3, |
| 1233 | u132_hcd_initial_empty_sent); |
| 1234 | if (retval != 0) |
| 1235 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1236 | return; |
| 1237 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1238 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 1239 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1240 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 1241 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1242 | return; |
| 1243 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1247 | int len, int toggle_bits, int error_count, int condition_code, |
| 1248 | int repeat_number, int halted, int skipped, int actual, int non_null) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1249 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1250 | struct u132_endp *endp = data; |
| 1251 | struct u132 *u132 = endp->u132; |
| 1252 | u8 address = u132->addr[endp->usb_addr].address; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1253 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1254 | if (u132->going > 1) { |
| 1255 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1256 | , u132->going); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1257 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1258 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); |
| 1259 | return; |
| 1260 | } else if (endp->dequeueing) { |
| 1261 | endp->dequeueing = 0; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1262 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1263 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); |
| 1264 | return; |
| 1265 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1266 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 1267 | "urb=%p\n", urb); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1268 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1269 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); |
| 1270 | return; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1271 | } else if (!urb->unlinked) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1272 | int retval; |
| 1273 | struct u132_ring *ring = endp->ring; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1274 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1275 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, |
| 1276 | ring->number, endp, urb, address, endp->usb_endp, 0, |
| 1277 | u132_hcd_initial_input_recv); |
| 1278 | if (retval != 0) |
| 1279 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1280 | return; |
| 1281 | } else { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1282 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " |
| 1283 | "unlinked=%d\n", urb, urb->unlinked); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1284 | mutex_unlock(&u132->scheduler_lock); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 1285 | u132_hcd_giveback_urb(u132, endp, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1286 | return; |
| 1287 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1290 | /* |
| 1291 | * this work function is only executed from the work queue |
| 1292 | * |
| 1293 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1294 | static void u132_hcd_ring_work_scheduler(struct work_struct *work) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1295 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1296 | struct u132_ring *ring = |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1297 | container_of(work, struct u132_ring, scheduler.work); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1298 | struct u132 *u132 = ring->u132; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1299 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1300 | if (ring->in_use) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1301 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1302 | u132_ring_put_kref(u132, ring); |
| 1303 | return; |
| 1304 | } else if (ring->curr_endp) { |
Geliang Tang | 4e5d7a8 | 2015-12-19 00:34:29 +0800 | [diff] [blame] | 1305 | struct u132_endp *endp, *last_endp = ring->curr_endp; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1306 | unsigned long wakeup = 0; |
Geliang Tang | 4e5d7a8 | 2015-12-19 00:34:29 +0800 | [diff] [blame] | 1307 | list_for_each_entry(endp, &last_endp->endp_ring, endp_ring) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1308 | if (endp->queue_next == endp->queue_last) { |
| 1309 | } else if ((endp->delayed == 0) |
| 1310 | || time_after_eq(jiffies, endp->jiffies)) { |
| 1311 | ring->curr_endp = endp; |
| 1312 | u132_endp_cancel_work(u132, last_endp); |
| 1313 | u132_endp_queue_work(u132, last_endp, 0); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1314 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1315 | u132_ring_put_kref(u132, ring); |
| 1316 | return; |
| 1317 | } else { |
| 1318 | unsigned long delta = endp->jiffies - jiffies; |
| 1319 | if (delta > wakeup) |
| 1320 | wakeup = delta; |
| 1321 | } |
| 1322 | } |
| 1323 | if (last_endp->queue_next == last_endp->queue_last) { |
| 1324 | } else if ((last_endp->delayed == 0) || time_after_eq(jiffies, |
| 1325 | last_endp->jiffies)) { |
| 1326 | u132_endp_cancel_work(u132, last_endp); |
| 1327 | u132_endp_queue_work(u132, last_endp, 0); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1328 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1329 | u132_ring_put_kref(u132, ring); |
| 1330 | return; |
| 1331 | } else { |
| 1332 | unsigned long delta = last_endp->jiffies - jiffies; |
| 1333 | if (delta > wakeup) |
| 1334 | wakeup = delta; |
| 1335 | } |
| 1336 | if (wakeup > 0) { |
| 1337 | u132_ring_requeue_work(u132, ring, wakeup); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1338 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1339 | return; |
| 1340 | } else { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1341 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1342 | u132_ring_put_kref(u132, ring); |
| 1343 | return; |
| 1344 | } |
| 1345 | } else { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1346 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1347 | u132_ring_put_kref(u132, ring); |
| 1348 | return; |
| 1349 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1352 | static void u132_hcd_endp_work_scheduler(struct work_struct *work) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1353 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1354 | struct u132_ring *ring; |
| 1355 | struct u132_endp *endp = |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1356 | container_of(work, struct u132_endp, scheduler.work); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1357 | struct u132 *u132 = endp->u132; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1358 | mutex_lock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1359 | ring = endp->ring; |
| 1360 | if (endp->edset_flush) { |
| 1361 | endp->edset_flush = 0; |
| 1362 | if (endp->dequeueing) |
| 1363 | usb_ftdi_elan_edset_flush(u132->platform_dev, |
| 1364 | ring->number, endp); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1365 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1366 | u132_endp_put_kref(u132, endp); |
| 1367 | return; |
| 1368 | } else if (endp->active) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1369 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1370 | u132_endp_put_kref(u132, endp); |
| 1371 | return; |
| 1372 | } else if (ring->in_use) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1373 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1374 | u132_endp_put_kref(u132, endp); |
| 1375 | return; |
| 1376 | } else if (endp->queue_next == endp->queue_last) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1377 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1378 | u132_endp_put_kref(u132, endp); |
| 1379 | return; |
| 1380 | } else if (endp->pipetype == PIPE_INTERRUPT) { |
| 1381 | u8 address = u132->addr[endp->usb_addr].address; |
| 1382 | if (ring->in_use) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1383 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1384 | u132_endp_put_kref(u132, endp); |
| 1385 | return; |
| 1386 | } else { |
| 1387 | int retval; |
| 1388 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & |
| 1389 | endp->queue_next]; |
| 1390 | endp->active = 1; |
| 1391 | ring->curr_endp = endp; |
| 1392 | ring->in_use = 1; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1393 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1394 | retval = edset_single(u132, ring, endp, urb, address, |
| 1395 | endp->toggle_bits, u132_hcd_interrupt_recv); |
| 1396 | if (retval != 0) |
| 1397 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1398 | return; |
| 1399 | } |
| 1400 | } else if (endp->pipetype == PIPE_CONTROL) { |
| 1401 | u8 address = u132->addr[endp->usb_addr].address; |
| 1402 | if (ring->in_use) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1403 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1404 | u132_endp_put_kref(u132, endp); |
| 1405 | return; |
| 1406 | } else if (address == 0) { |
| 1407 | int retval; |
| 1408 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & |
| 1409 | endp->queue_next]; |
| 1410 | endp->active = 1; |
| 1411 | ring->curr_endp = endp; |
| 1412 | ring->in_use = 1; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1413 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1414 | retval = edset_setup(u132, ring, endp, urb, address, |
| 1415 | 0x2, u132_hcd_initial_setup_sent); |
| 1416 | if (retval != 0) |
| 1417 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1418 | return; |
| 1419 | } else if (endp->usb_addr == 0) { |
| 1420 | int retval; |
| 1421 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & |
| 1422 | endp->queue_next]; |
| 1423 | endp->active = 1; |
| 1424 | ring->curr_endp = endp; |
| 1425 | ring->in_use = 1; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1426 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1427 | retval = edset_setup(u132, ring, endp, urb, 0, 0x2, |
| 1428 | u132_hcd_enumeration_address_sent); |
| 1429 | if (retval != 0) |
| 1430 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1431 | return; |
| 1432 | } else { |
| 1433 | int retval; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1434 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & |
| 1435 | endp->queue_next]; |
Randy Dunlap | 1d6ec81 | 2010-05-06 16:46:03 -0700 | [diff] [blame] | 1436 | address = u132->addr[endp->usb_addr].address; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1437 | endp->active = 1; |
| 1438 | ring->curr_endp = endp; |
| 1439 | ring->in_use = 1; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1440 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1441 | retval = edset_setup(u132, ring, endp, urb, address, |
| 1442 | 0x2, u132_hcd_configure_setup_sent); |
| 1443 | if (retval != 0) |
| 1444 | u132_hcd_giveback_urb(u132, endp, urb, retval); |
| 1445 | return; |
| 1446 | } |
| 1447 | } else { |
| 1448 | if (endp->input) { |
| 1449 | u8 address = u132->addr[endp->usb_addr].address; |
| 1450 | if (ring->in_use) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1451 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1452 | u132_endp_put_kref(u132, endp); |
| 1453 | return; |
| 1454 | } else { |
| 1455 | int retval; |
| 1456 | struct urb *urb = endp->urb_list[ |
| 1457 | ENDP_QUEUE_MASK & endp->queue_next]; |
| 1458 | endp->active = 1; |
| 1459 | ring->curr_endp = endp; |
| 1460 | ring->in_use = 1; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1461 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1462 | retval = edset_input(u132, ring, endp, urb, |
| 1463 | address, endp->toggle_bits, |
| 1464 | u132_hcd_bulk_input_recv); |
| 1465 | if (retval == 0) { |
| 1466 | } else |
| 1467 | u132_hcd_giveback_urb(u132, endp, urb, |
| 1468 | retval); |
| 1469 | return; |
| 1470 | } |
| 1471 | } else { /* output pipe */ |
| 1472 | u8 address = u132->addr[endp->usb_addr].address; |
| 1473 | if (ring->in_use) { |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1474 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1475 | u132_endp_put_kref(u132, endp); |
| 1476 | return; |
| 1477 | } else { |
| 1478 | int retval; |
| 1479 | struct urb *urb = endp->urb_list[ |
| 1480 | ENDP_QUEUE_MASK & endp->queue_next]; |
| 1481 | endp->active = 1; |
| 1482 | ring->curr_endp = endp; |
| 1483 | ring->in_use = 1; |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 1484 | mutex_unlock(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1485 | retval = edset_output(u132, ring, endp, urb, |
| 1486 | address, endp->toggle_bits, |
| 1487 | u132_hcd_bulk_output_sent); |
| 1488 | if (retval == 0) { |
| 1489 | } else |
| 1490 | u132_hcd_giveback_urb(u132, endp, urb, |
| 1491 | retval); |
| 1492 | return; |
| 1493 | } |
| 1494 | } |
| 1495 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1496 | } |
Gabriel C | 5b570d4 | 2007-07-30 12:57:03 +0200 | [diff] [blame] | 1497 | #ifdef CONFIG_PM |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1498 | |
| 1499 | static void port_power(struct u132 *u132, int pn, int is_on) |
| 1500 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1501 | u132->port[pn].power = is_on; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1502 | } |
| 1503 | |
Gabriel C | 5b570d4 | 2007-07-30 12:57:03 +0200 | [diff] [blame] | 1504 | #endif |
| 1505 | |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1506 | static void u132_power(struct u132 *u132, int is_on) |
| 1507 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1508 | struct usb_hcd *hcd = u132_to_hcd(u132) |
| 1509 | ; /* hub is inactive unless the port is powered */ |
| 1510 | if (is_on) { |
| 1511 | if (u132->power) |
| 1512 | return; |
| 1513 | u132->power = 1; |
| 1514 | } else { |
| 1515 | u132->power = 0; |
| 1516 | hcd->state = HC_STATE_HALT; |
| 1517 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | static int u132_periodic_reinit(struct u132 *u132) |
| 1521 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1522 | int retval; |
| 1523 | u32 fi = u132->hc_fminterval & 0x03fff; |
| 1524 | u32 fit; |
| 1525 | u32 fminterval; |
| 1526 | retval = u132_read_pcimem(u132, fminterval, &fminterval); |
| 1527 | if (retval) |
| 1528 | return retval; |
| 1529 | fit = fminterval & FIT; |
| 1530 | retval = u132_write_pcimem(u132, fminterval, |
| 1531 | (fit ^ FIT) | u132->hc_fminterval); |
| 1532 | if (retval) |
| 1533 | return retval; |
Saurabh Karajgaonkar | 8602b08 | 2015-08-04 14:03:45 +0000 | [diff] [blame] | 1534 | return u132_write_pcimem(u132, periodicstart, |
| 1535 | ((9 * fi) / 10) & 0x3fff); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static char *hcfs2string(int state) |
| 1539 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1540 | switch (state) { |
| 1541 | case OHCI_USB_RESET: |
| 1542 | return "reset"; |
| 1543 | case OHCI_USB_RESUME: |
| 1544 | return "resume"; |
| 1545 | case OHCI_USB_OPER: |
| 1546 | return "operational"; |
| 1547 | case OHCI_USB_SUSPEND: |
| 1548 | return "suspend"; |
| 1549 | } |
| 1550 | return "?"; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1551 | } |
| 1552 | |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1553 | static int u132_init(struct u132 *u132) |
| 1554 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1555 | int retval; |
| 1556 | u32 control; |
| 1557 | u132_disable(u132); |
| 1558 | u132->next_statechange = jiffies; |
| 1559 | retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE); |
| 1560 | if (retval) |
| 1561 | return retval; |
| 1562 | retval = u132_read_pcimem(u132, control, &control); |
| 1563 | if (retval) |
| 1564 | return retval; |
| 1565 | if (u132->num_ports == 0) { |
| 1566 | u32 rh_a = -1; |
| 1567 | retval = u132_read_pcimem(u132, roothub.a, &rh_a); |
| 1568 | if (retval) |
| 1569 | return retval; |
| 1570 | u132->num_ports = rh_a & RH_A_NDP; |
| 1571 | retval = read_roothub_info(u132); |
| 1572 | if (retval) |
| 1573 | return retval; |
| 1574 | } |
| 1575 | if (u132->num_ports > MAX_U132_PORTS) |
| 1576 | return -EINVAL; |
| 1577 | |
| 1578 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | |
| 1582 | /* Start an OHCI controller, set the BUS operational |
| 1583 | * resets USB and controller |
| 1584 | * enable interrupts |
| 1585 | */ |
| 1586 | static int u132_run(struct u132 *u132) |
| 1587 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1588 | int retval; |
| 1589 | u32 control; |
| 1590 | u32 status; |
| 1591 | u32 fminterval; |
| 1592 | u32 periodicstart; |
| 1593 | u32 cmdstatus; |
| 1594 | u32 roothub_a; |
| 1595 | int mask = OHCI_INTR_INIT; |
| 1596 | int first = u132->hc_fminterval == 0; |
| 1597 | int sleep_time = 0; |
| 1598 | int reset_timeout = 30; /* ... allow extra time */ |
| 1599 | u132_disable(u132); |
| 1600 | if (first) { |
| 1601 | u32 temp; |
| 1602 | retval = u132_read_pcimem(u132, fminterval, &temp); |
| 1603 | if (retval) |
| 1604 | return retval; |
| 1605 | u132->hc_fminterval = temp & 0x3fff; |
| 1606 | u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16; |
| 1607 | } |
| 1608 | retval = u132_read_pcimem(u132, control, &u132->hc_control); |
| 1609 | if (retval) |
| 1610 | return retval; |
| 1611 | dev_info(&u132->platform_dev->dev, "resetting from state '%s', control " |
| 1612 | "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS), |
| 1613 | u132->hc_control); |
| 1614 | switch (u132->hc_control & OHCI_CTRL_HCFS) { |
| 1615 | case OHCI_USB_OPER: |
| 1616 | sleep_time = 0; |
| 1617 | break; |
| 1618 | case OHCI_USB_SUSPEND: |
| 1619 | case OHCI_USB_RESUME: |
| 1620 | u132->hc_control &= OHCI_CTRL_RWC; |
| 1621 | u132->hc_control |= OHCI_USB_RESUME; |
| 1622 | sleep_time = 10; |
| 1623 | break; |
| 1624 | default: |
| 1625 | u132->hc_control &= OHCI_CTRL_RWC; |
| 1626 | u132->hc_control |= OHCI_USB_RESET; |
| 1627 | sleep_time = 50; |
| 1628 | break; |
| 1629 | } |
| 1630 | retval = u132_write_pcimem(u132, control, u132->hc_control); |
| 1631 | if (retval) |
| 1632 | return retval; |
| 1633 | retval = u132_read_pcimem(u132, control, &control); |
| 1634 | if (retval) |
| 1635 | return retval; |
| 1636 | msleep(sleep_time); |
| 1637 | retval = u132_read_pcimem(u132, roothub.a, &roothub_a); |
| 1638 | if (retval) |
| 1639 | return retval; |
| 1640 | if (!(roothub_a & RH_A_NPS)) { |
| 1641 | int temp; /* power down each port */ |
| 1642 | for (temp = 0; temp < u132->num_ports; temp++) { |
| 1643 | retval = u132_write_pcimem(u132, |
| 1644 | roothub.portstatus[temp], RH_PS_LSDA); |
| 1645 | if (retval) |
| 1646 | return retval; |
| 1647 | } |
| 1648 | } |
| 1649 | retval = u132_read_pcimem(u132, control, &control); |
| 1650 | if (retval) |
| 1651 | return retval; |
| 1652 | retry: |
| 1653 | retval = u132_read_pcimem(u132, cmdstatus, &status); |
| 1654 | if (retval) |
| 1655 | return retval; |
| 1656 | retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR); |
| 1657 | if (retval) |
| 1658 | return retval; |
| 1659 | extra: { |
| 1660 | retval = u132_read_pcimem(u132, cmdstatus, &status); |
| 1661 | if (retval) |
| 1662 | return retval; |
| 1663 | if (0 != (status & OHCI_HCR)) { |
| 1664 | if (--reset_timeout == 0) { |
| 1665 | dev_err(&u132->platform_dev->dev, "USB HC reset" |
| 1666 | " timed out!\n"); |
| 1667 | return -ENODEV; |
| 1668 | } else { |
| 1669 | msleep(5); |
| 1670 | goto extra; |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | if (u132->flags & OHCI_QUIRK_INITRESET) { |
| 1675 | retval = u132_write_pcimem(u132, control, u132->hc_control); |
| 1676 | if (retval) |
| 1677 | return retval; |
| 1678 | retval = u132_read_pcimem(u132, control, &control); |
| 1679 | if (retval) |
| 1680 | return retval; |
| 1681 | } |
| 1682 | retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000); |
| 1683 | if (retval) |
| 1684 | return retval; |
| 1685 | retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000); |
| 1686 | if (retval) |
| 1687 | return retval; |
| 1688 | retval = u132_write_pcimem(u132, hcca, 0x00000000); |
| 1689 | if (retval) |
| 1690 | return retval; |
| 1691 | retval = u132_periodic_reinit(u132); |
| 1692 | if (retval) |
| 1693 | return retval; |
| 1694 | retval = u132_read_pcimem(u132, fminterval, &fminterval); |
| 1695 | if (retval) |
| 1696 | return retval; |
| 1697 | retval = u132_read_pcimem(u132, periodicstart, &periodicstart); |
| 1698 | if (retval) |
| 1699 | return retval; |
| 1700 | if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) { |
| 1701 | if (!(u132->flags & OHCI_QUIRK_INITRESET)) { |
| 1702 | u132->flags |= OHCI_QUIRK_INITRESET; |
| 1703 | goto retry; |
| 1704 | } else |
| 1705 | dev_err(&u132->platform_dev->dev, "init err(%08x %04x)" |
| 1706 | "\n", fminterval, periodicstart); |
| 1707 | } /* start controller operations */ |
| 1708 | u132->hc_control &= OHCI_CTRL_RWC; |
| 1709 | u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER; |
| 1710 | retval = u132_write_pcimem(u132, control, u132->hc_control); |
| 1711 | if (retval) |
| 1712 | return retval; |
| 1713 | retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF); |
| 1714 | if (retval) |
| 1715 | return retval; |
| 1716 | retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus); |
| 1717 | if (retval) |
| 1718 | return retval; |
| 1719 | retval = u132_read_pcimem(u132, control, &control); |
| 1720 | if (retval) |
| 1721 | return retval; |
| 1722 | u132_to_hcd(u132)->state = HC_STATE_RUNNING; |
| 1723 | retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE); |
| 1724 | if (retval) |
| 1725 | return retval; |
| 1726 | retval = u132_write_pcimem(u132, intrstatus, mask); |
| 1727 | if (retval) |
| 1728 | return retval; |
| 1729 | retval = u132_write_pcimem(u132, intrdisable, |
| 1730 | OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO | |
| 1731 | OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH | |
| 1732 | OHCI_INTR_SO); |
| 1733 | if (retval) |
| 1734 | return retval; /* handle root hub init quirks ... */ |
| 1735 | retval = u132_read_pcimem(u132, roothub.a, &roothub_a); |
| 1736 | if (retval) |
| 1737 | return retval; |
| 1738 | roothub_a &= ~(RH_A_PSM | RH_A_OCPM); |
| 1739 | if (u132->flags & OHCI_QUIRK_SUPERIO) { |
| 1740 | roothub_a |= RH_A_NOCP; |
| 1741 | roothub_a &= ~(RH_A_POTPGT | RH_A_NPS); |
| 1742 | retval = u132_write_pcimem(u132, roothub.a, roothub_a); |
| 1743 | if (retval) |
| 1744 | return retval; |
| 1745 | } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) { |
| 1746 | roothub_a |= RH_A_NPS; |
| 1747 | retval = u132_write_pcimem(u132, roothub.a, roothub_a); |
| 1748 | if (retval) |
| 1749 | return retval; |
| 1750 | } |
| 1751 | retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC); |
| 1752 | if (retval) |
| 1753 | return retval; |
| 1754 | retval = u132_write_pcimem(u132, roothub.b, |
| 1755 | (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM); |
| 1756 | if (retval) |
| 1757 | return retval; |
| 1758 | retval = u132_read_pcimem(u132, control, &control); |
| 1759 | if (retval) |
| 1760 | return retval; |
| 1761 | mdelay((roothub_a >> 23) & 0x1fe); |
| 1762 | u132_to_hcd(u132)->state = HC_STATE_RUNNING; |
| 1763 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | static void u132_hcd_stop(struct usb_hcd *hcd) |
| 1767 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1768 | struct u132 *u132 = hcd_to_u132(hcd); |
| 1769 | if (u132->going > 1) { |
| 1770 | dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b" |
| 1771 | "een removed %d\n", u132, hcd, u132->going); |
| 1772 | } else if (u132->going > 0) { |
| 1773 | dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" |
| 1774 | "ed\n", hcd); |
| 1775 | } else { |
| 1776 | mutex_lock(&u132->sw_lock); |
| 1777 | msleep(100); |
| 1778 | u132_power(u132, 0); |
| 1779 | mutex_unlock(&u132->sw_lock); |
| 1780 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static int u132_hcd_start(struct usb_hcd *hcd) |
| 1784 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1785 | struct u132 *u132 = hcd_to_u132(hcd); |
| 1786 | if (u132->going > 1) { |
| 1787 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1788 | , u132->going); |
| 1789 | return -ENODEV; |
| 1790 | } else if (u132->going > 0) { |
| 1791 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 1792 | return -ESHUTDOWN; |
| 1793 | } else if (hcd->self.controller) { |
| 1794 | int retval; |
| 1795 | struct platform_device *pdev = |
| 1796 | to_platform_device(hcd->self.controller); |
| 1797 | u16 vendor = ((struct u132_platform_data *) |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 1798 | dev_get_platdata(&pdev->dev))->vendor; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1799 | u16 device = ((struct u132_platform_data *) |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 1800 | dev_get_platdata(&pdev->dev))->device; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1801 | mutex_lock(&u132->sw_lock); |
| 1802 | msleep(10); |
| 1803 | if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) { |
| 1804 | u132->flags = OHCI_QUIRK_AMD756; |
| 1805 | } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) { |
| 1806 | dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar" |
| 1807 | "ounds unavailable\n"); |
| 1808 | } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8) |
| 1809 | u132->flags |= OHCI_QUIRK_ZFMICRO; |
| 1810 | retval = u132_run(u132); |
| 1811 | if (retval) { |
| 1812 | u132_disable(u132); |
| 1813 | u132->going = 1; |
| 1814 | } |
| 1815 | msleep(100); |
| 1816 | mutex_unlock(&u132->sw_lock); |
| 1817 | return retval; |
| 1818 | } else { |
| 1819 | dev_err(&u132->platform_dev->dev, "platform_device missing\n"); |
| 1820 | return -ENODEV; |
| 1821 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | static int u132_hcd_reset(struct usb_hcd *hcd) |
| 1825 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1826 | struct u132 *u132 = hcd_to_u132(hcd); |
| 1827 | if (u132->going > 1) { |
| 1828 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 1829 | , u132->going); |
| 1830 | return -ENODEV; |
| 1831 | } else if (u132->going > 0) { |
| 1832 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 1833 | return -ESHUTDOWN; |
| 1834 | } else { |
| 1835 | int retval; |
| 1836 | mutex_lock(&u132->sw_lock); |
| 1837 | retval = u132_init(u132); |
| 1838 | if (retval) { |
| 1839 | u132_disable(u132); |
| 1840 | u132->going = 1; |
| 1841 | } |
| 1842 | mutex_unlock(&u132->sw_lock); |
| 1843 | return retval; |
| 1844 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | static int create_endpoint_and_queue_int(struct u132 *u132, |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1848 | struct u132_udev *udev, struct urb *urb, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1849 | struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, |
| 1850 | gfp_t mem_flags) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 1851 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1852 | struct u132_ring *ring; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1853 | unsigned long irqs; |
| 1854 | int rc; |
| 1855 | u8 endp_number; |
| 1856 | struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); |
| 1857 | |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1858 | if (!endp) |
| 1859 | return -ENOMEM; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1860 | |
| 1861 | spin_lock_init(&endp->queue_lock.slock); |
| 1862 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); |
| 1863 | rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb); |
| 1864 | if (rc) { |
| 1865 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 1866 | kfree(endp); |
| 1867 | return rc; |
| 1868 | } |
| 1869 | |
| 1870 | endp_number = ++u132->num_endpoints; |
| 1871 | urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1872 | INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); |
| 1873 | INIT_LIST_HEAD(&endp->urb_more); |
| 1874 | ring = endp->ring = &u132->ring[0]; |
| 1875 | if (ring->curr_endp) { |
| 1876 | list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); |
| 1877 | } else { |
| 1878 | INIT_LIST_HEAD(&endp->endp_ring); |
| 1879 | ring->curr_endp = endp; |
| 1880 | } |
| 1881 | ring->length += 1; |
| 1882 | endp->dequeueing = 0; |
| 1883 | endp->edset_flush = 0; |
| 1884 | endp->active = 0; |
| 1885 | endp->delayed = 0; |
| 1886 | endp->endp_number = endp_number; |
| 1887 | endp->u132 = u132; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1888 | endp->hep = urb->ep; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 1889 | endp->pipetype = usb_pipetype(urb->pipe); |
| 1890 | u132_endp_init_kref(u132, endp); |
| 1891 | if (usb_pipein(urb->pipe)) { |
| 1892 | endp->toggle_bits = 0x2; |
| 1893 | usb_settoggle(udev->usb_device, usb_endp, 0, 0); |
| 1894 | endp->input = 1; |
| 1895 | endp->output = 0; |
| 1896 | udev->endp_number_in[usb_endp] = endp_number; |
| 1897 | u132_udev_get_kref(u132, udev); |
| 1898 | } else { |
| 1899 | endp->toggle_bits = 0x2; |
| 1900 | usb_settoggle(udev->usb_device, usb_endp, 1, 0); |
| 1901 | endp->input = 0; |
| 1902 | endp->output = 1; |
| 1903 | udev->endp_number_out[usb_endp] = endp_number; |
| 1904 | u132_udev_get_kref(u132, udev); |
| 1905 | } |
| 1906 | urb->hcpriv = u132; |
| 1907 | endp->delayed = 1; |
| 1908 | endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); |
| 1909 | endp->udev_number = address; |
| 1910 | endp->usb_addr = usb_addr; |
| 1911 | endp->usb_endp = usb_endp; |
| 1912 | endp->queue_size = 1; |
| 1913 | endp->queue_last = 0; |
| 1914 | endp->queue_next = 0; |
| 1915 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; |
| 1916 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 1917 | u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval)); |
| 1918 | return 0; |
| 1919 | } |
| 1920 | |
| 1921 | static int queue_int_on_old_endpoint(struct u132 *u132, |
| 1922 | struct u132_udev *udev, struct urb *urb, |
| 1923 | struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, |
| 1924 | u8 usb_endp, u8 address) |
| 1925 | { |
| 1926 | urb->hcpriv = u132; |
| 1927 | endp->delayed = 1; |
| 1928 | endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); |
| 1929 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { |
| 1930 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; |
| 1931 | } else { |
| 1932 | struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), |
| 1933 | GFP_ATOMIC); |
| 1934 | if (urbq == NULL) { |
| 1935 | endp->queue_size -= 1; |
| 1936 | return -ENOMEM; |
| 1937 | } else { |
| 1938 | list_add_tail(&urbq->urb_more, &endp->urb_more); |
| 1939 | urbq->urb = urb; |
| 1940 | } |
| 1941 | } |
| 1942 | return 0; |
| 1943 | } |
| 1944 | |
| 1945 | static int create_endpoint_and_queue_bulk(struct u132 *u132, |
| 1946 | struct u132_udev *udev, struct urb *urb, |
| 1947 | struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, |
| 1948 | gfp_t mem_flags) |
| 1949 | { |
| 1950 | int ring_number; |
| 1951 | struct u132_ring *ring; |
| 1952 | unsigned long irqs; |
| 1953 | int rc; |
| 1954 | u8 endp_number; |
| 1955 | struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); |
| 1956 | |
| 1957 | if (!endp) |
| 1958 | return -ENOMEM; |
| 1959 | |
| 1960 | spin_lock_init(&endp->queue_lock.slock); |
| 1961 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); |
| 1962 | rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb); |
| 1963 | if (rc) { |
| 1964 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 1965 | kfree(endp); |
| 1966 | return rc; |
| 1967 | } |
| 1968 | |
| 1969 | endp_number = ++u132->num_endpoints; |
| 1970 | urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; |
| 1971 | INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); |
| 1972 | INIT_LIST_HEAD(&endp->urb_more); |
| 1973 | endp->dequeueing = 0; |
| 1974 | endp->edset_flush = 0; |
| 1975 | endp->active = 0; |
| 1976 | endp->delayed = 0; |
| 1977 | endp->endp_number = endp_number; |
| 1978 | endp->u132 = u132; |
| 1979 | endp->hep = urb->ep; |
| 1980 | endp->pipetype = usb_pipetype(urb->pipe); |
| 1981 | u132_endp_init_kref(u132, endp); |
| 1982 | if (usb_pipein(urb->pipe)) { |
| 1983 | endp->toggle_bits = 0x2; |
| 1984 | usb_settoggle(udev->usb_device, usb_endp, 0, 0); |
| 1985 | ring_number = 3; |
| 1986 | endp->input = 1; |
| 1987 | endp->output = 0; |
| 1988 | udev->endp_number_in[usb_endp] = endp_number; |
| 1989 | u132_udev_get_kref(u132, udev); |
| 1990 | } else { |
| 1991 | endp->toggle_bits = 0x2; |
| 1992 | usb_settoggle(udev->usb_device, usb_endp, 1, 0); |
| 1993 | ring_number = 2; |
| 1994 | endp->input = 0; |
| 1995 | endp->output = 1; |
| 1996 | udev->endp_number_out[usb_endp] = endp_number; |
| 1997 | u132_udev_get_kref(u132, udev); |
| 1998 | } |
| 1999 | ring = endp->ring = &u132->ring[ring_number - 1]; |
| 2000 | if (ring->curr_endp) { |
| 2001 | list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); |
| 2002 | } else { |
| 2003 | INIT_LIST_HEAD(&endp->endp_ring); |
| 2004 | ring->curr_endp = endp; |
| 2005 | } |
| 2006 | ring->length += 1; |
| 2007 | urb->hcpriv = u132; |
| 2008 | endp->udev_number = address; |
| 2009 | endp->usb_addr = usb_addr; |
| 2010 | endp->usb_endp = usb_endp; |
| 2011 | endp->queue_size = 1; |
| 2012 | endp->queue_last = 0; |
| 2013 | endp->queue_next = 0; |
| 2014 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; |
| 2015 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2016 | u132_endp_queue_work(u132, endp, 0); |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
| 2020 | static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, |
| 2021 | struct urb *urb, |
| 2022 | struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, |
| 2023 | u8 usb_endp, u8 address) |
| 2024 | { |
| 2025 | urb->hcpriv = u132; |
| 2026 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { |
| 2027 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; |
| 2028 | } else { |
| 2029 | struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), |
| 2030 | GFP_ATOMIC); |
| 2031 | if (urbq == NULL) { |
| 2032 | endp->queue_size -= 1; |
| 2033 | return -ENOMEM; |
| 2034 | } else { |
| 2035 | list_add_tail(&urbq->urb_more, &endp->urb_more); |
| 2036 | urbq->urb = urb; |
| 2037 | } |
| 2038 | } |
| 2039 | return 0; |
| 2040 | } |
| 2041 | |
| 2042 | static int create_endpoint_and_queue_control(struct u132 *u132, |
| 2043 | struct urb *urb, |
| 2044 | struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, |
| 2045 | gfp_t mem_flags) |
| 2046 | { |
| 2047 | struct u132_ring *ring; |
| 2048 | unsigned long irqs; |
| 2049 | int rc; |
| 2050 | u8 endp_number; |
| 2051 | struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); |
| 2052 | |
| 2053 | if (!endp) |
| 2054 | return -ENOMEM; |
| 2055 | |
| 2056 | spin_lock_init(&endp->queue_lock.slock); |
| 2057 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); |
| 2058 | rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb); |
| 2059 | if (rc) { |
| 2060 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2061 | kfree(endp); |
| 2062 | return rc; |
| 2063 | } |
| 2064 | |
| 2065 | endp_number = ++u132->num_endpoints; |
| 2066 | urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; |
| 2067 | INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); |
| 2068 | INIT_LIST_HEAD(&endp->urb_more); |
| 2069 | ring = endp->ring = &u132->ring[0]; |
| 2070 | if (ring->curr_endp) { |
| 2071 | list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); |
| 2072 | } else { |
| 2073 | INIT_LIST_HEAD(&endp->endp_ring); |
| 2074 | ring->curr_endp = endp; |
| 2075 | } |
| 2076 | ring->length += 1; |
| 2077 | endp->dequeueing = 0; |
| 2078 | endp->edset_flush = 0; |
| 2079 | endp->active = 0; |
| 2080 | endp->delayed = 0; |
| 2081 | endp->endp_number = endp_number; |
| 2082 | endp->u132 = u132; |
| 2083 | endp->hep = urb->ep; |
| 2084 | u132_endp_init_kref(u132, endp); |
| 2085 | u132_endp_get_kref(u132, endp); |
| 2086 | if (usb_addr == 0) { |
| 2087 | u8 address = u132->addr[usb_addr].address; |
| 2088 | struct u132_udev *udev = &u132->udev[address]; |
| 2089 | endp->udev_number = address; |
| 2090 | endp->usb_addr = usb_addr; |
| 2091 | endp->usb_endp = usb_endp; |
| 2092 | endp->input = 1; |
| 2093 | endp->output = 1; |
| 2094 | endp->pipetype = usb_pipetype(urb->pipe); |
| 2095 | u132_udev_init_kref(u132, udev); |
| 2096 | u132_udev_get_kref(u132, udev); |
| 2097 | udev->endp_number_in[usb_endp] = endp_number; |
| 2098 | udev->endp_number_out[usb_endp] = endp_number; |
| 2099 | urb->hcpriv = u132; |
| 2100 | endp->queue_size = 1; |
| 2101 | endp->queue_last = 0; |
| 2102 | endp->queue_next = 0; |
| 2103 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; |
| 2104 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2105 | u132_endp_queue_work(u132, endp, 0); |
| 2106 | return 0; |
| 2107 | } else { /*(usb_addr > 0) */ |
| 2108 | u8 address = u132->addr[usb_addr].address; |
| 2109 | struct u132_udev *udev = &u132->udev[address]; |
| 2110 | endp->udev_number = address; |
| 2111 | endp->usb_addr = usb_addr; |
| 2112 | endp->usb_endp = usb_endp; |
| 2113 | endp->input = 1; |
| 2114 | endp->output = 1; |
| 2115 | endp->pipetype = usb_pipetype(urb->pipe); |
| 2116 | u132_udev_get_kref(u132, udev); |
| 2117 | udev->enumeration = 2; |
| 2118 | udev->endp_number_in[usb_endp] = endp_number; |
| 2119 | udev->endp_number_out[usb_endp] = endp_number; |
| 2120 | urb->hcpriv = u132; |
| 2121 | endp->queue_size = 1; |
| 2122 | endp->queue_last = 0; |
| 2123 | endp->queue_next = 0; |
| 2124 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; |
| 2125 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2126 | u132_endp_queue_work(u132, endp, 0); |
| 2127 | return 0; |
| 2128 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | static int queue_control_on_old_endpoint(struct u132 *u132, |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2132 | struct urb *urb, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2133 | struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, |
| 2134 | u8 usb_endp) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2135 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2136 | if (usb_addr == 0) { |
| 2137 | if (usb_pipein(urb->pipe)) { |
| 2138 | urb->hcpriv = u132; |
| 2139 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { |
| 2140 | endp->urb_list[ENDP_QUEUE_MASK & |
| 2141 | endp->queue_last++] = urb; |
| 2142 | } else { |
| 2143 | struct u132_urbq *urbq = |
| 2144 | kmalloc(sizeof(struct u132_urbq), |
| 2145 | GFP_ATOMIC); |
| 2146 | if (urbq == NULL) { |
| 2147 | endp->queue_size -= 1; |
| 2148 | return -ENOMEM; |
| 2149 | } else { |
| 2150 | list_add_tail(&urbq->urb_more, |
| 2151 | &endp->urb_more); |
| 2152 | urbq->urb = urb; |
| 2153 | } |
| 2154 | } |
| 2155 | return 0; |
| 2156 | } else { /* usb_pipeout(urb->pipe) */ |
| 2157 | struct u132_addr *addr = &u132->addr[usb_dev->devnum]; |
| 2158 | int I = MAX_U132_UDEVS; |
| 2159 | int i = 0; |
| 2160 | while (--I > 0) { |
| 2161 | struct u132_udev *udev = &u132->udev[++i]; |
| 2162 | if (udev->usb_device) { |
| 2163 | continue; |
| 2164 | } else { |
| 2165 | udev->enumeration = 1; |
| 2166 | u132->addr[0].address = i; |
| 2167 | endp->udev_number = i; |
| 2168 | udev->udev_number = i; |
| 2169 | udev->usb_addr = usb_dev->devnum; |
| 2170 | u132_udev_init_kref(u132, udev); |
| 2171 | udev->endp_number_in[usb_endp] = |
| 2172 | endp->endp_number; |
| 2173 | u132_udev_get_kref(u132, udev); |
| 2174 | udev->endp_number_out[usb_endp] = |
| 2175 | endp->endp_number; |
| 2176 | udev->usb_device = usb_dev; |
| 2177 | ((u8 *) (urb->setup_packet))[2] = |
| 2178 | addr->address = i; |
| 2179 | u132_udev_get_kref(u132, udev); |
| 2180 | break; |
| 2181 | } |
| 2182 | } |
| 2183 | if (I == 0) { |
| 2184 | dev_err(&u132->platform_dev->dev, "run out of d" |
| 2185 | "evice space\n"); |
| 2186 | return -EINVAL; |
| 2187 | } |
| 2188 | urb->hcpriv = u132; |
| 2189 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { |
| 2190 | endp->urb_list[ENDP_QUEUE_MASK & |
| 2191 | endp->queue_last++] = urb; |
| 2192 | } else { |
| 2193 | struct u132_urbq *urbq = |
| 2194 | kmalloc(sizeof(struct u132_urbq), |
| 2195 | GFP_ATOMIC); |
| 2196 | if (urbq == NULL) { |
| 2197 | endp->queue_size -= 1; |
| 2198 | return -ENOMEM; |
| 2199 | } else { |
| 2200 | list_add_tail(&urbq->urb_more, |
| 2201 | &endp->urb_more); |
| 2202 | urbq->urb = urb; |
| 2203 | } |
| 2204 | } |
| 2205 | return 0; |
| 2206 | } |
| 2207 | } else { /*(usb_addr > 0) */ |
| 2208 | u8 address = u132->addr[usb_addr].address; |
| 2209 | struct u132_udev *udev = &u132->udev[address]; |
| 2210 | urb->hcpriv = u132; |
| 2211 | if (udev->enumeration != 2) |
| 2212 | udev->enumeration = 2; |
| 2213 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { |
| 2214 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = |
| 2215 | urb; |
| 2216 | } else { |
| 2217 | struct u132_urbq *urbq = |
| 2218 | kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC); |
| 2219 | if (urbq == NULL) { |
| 2220 | endp->queue_size -= 1; |
| 2221 | return -ENOMEM; |
| 2222 | } else { |
| 2223 | list_add_tail(&urbq->urb_more, &endp->urb_more); |
| 2224 | urbq->urb = urb; |
| 2225 | } |
| 2226 | } |
| 2227 | return 0; |
| 2228 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2229 | } |
| 2230 | |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2231 | static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 2232 | gfp_t mem_flags) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2233 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2234 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2235 | if (irqs_disabled()) { |
Mel Gorman | d0164ad | 2015-11-06 16:28:21 -0800 | [diff] [blame] | 2236 | if (gfpflags_allow_blocking(mem_flags)) { |
Masanari Iida | d5f9e73 | 2015-09-30 12:51:51 +0900 | [diff] [blame] | 2237 | printk(KERN_ERR "invalid context for function that might sleep\n"); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2238 | return -EINVAL; |
| 2239 | } |
| 2240 | } |
| 2241 | if (u132->going > 1) { |
| 2242 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 2243 | , u132->going); |
| 2244 | return -ENODEV; |
| 2245 | } else if (u132->going > 0) { |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 2246 | dev_err(&u132->platform_dev->dev, "device is being removed " |
| 2247 | "urb=%p\n", urb); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2248 | return -ESHUTDOWN; |
| 2249 | } else { |
| 2250 | u8 usb_addr = usb_pipedevice(urb->pipe); |
| 2251 | u8 usb_endp = usb_pipeendpoint(urb->pipe); |
| 2252 | struct usb_device *usb_dev = urb->dev; |
| 2253 | if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { |
| 2254 | u8 address = u132->addr[usb_addr].address; |
| 2255 | struct u132_udev *udev = &u132->udev[address]; |
| 2256 | struct u132_endp *endp = urb->ep->hcpriv; |
| 2257 | urb->actual_length = 0; |
| 2258 | if (endp) { |
| 2259 | unsigned long irqs; |
| 2260 | int retval; |
| 2261 | spin_lock_irqsave(&endp->queue_lock.slock, |
| 2262 | irqs); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2263 | retval = usb_hcd_link_urb_to_ep(hcd, urb); |
| 2264 | if (retval == 0) { |
| 2265 | retval = queue_int_on_old_endpoint( |
| 2266 | u132, udev, urb, |
| 2267 | usb_dev, endp, |
| 2268 | usb_addr, usb_endp, |
| 2269 | address); |
| 2270 | if (retval) |
| 2271 | usb_hcd_unlink_urb_from_ep( |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2272 | hcd, urb); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2273 | } |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2274 | spin_unlock_irqrestore(&endp->queue_lock.slock, |
| 2275 | irqs); |
| 2276 | if (retval) { |
| 2277 | return retval; |
| 2278 | } else { |
| 2279 | u132_endp_queue_work(u132, endp, |
| 2280 | msecs_to_jiffies(urb->interval)) |
| 2281 | ; |
| 2282 | return 0; |
| 2283 | } |
| 2284 | } else if (u132->num_endpoints == MAX_U132_ENDPS) { |
| 2285 | return -EINVAL; |
| 2286 | } else { /*(endp == NULL) */ |
| 2287 | return create_endpoint_and_queue_int(u132, udev, |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2288 | urb, usb_dev, usb_addr, |
| 2289 | usb_endp, address, mem_flags); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2290 | } |
| 2291 | } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { |
| 2292 | dev_err(&u132->platform_dev->dev, "the hardware does no" |
| 2293 | "t support PIPE_ISOCHRONOUS\n"); |
| 2294 | return -EINVAL; |
| 2295 | } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { |
| 2296 | u8 address = u132->addr[usb_addr].address; |
| 2297 | struct u132_udev *udev = &u132->udev[address]; |
| 2298 | struct u132_endp *endp = urb->ep->hcpriv; |
| 2299 | urb->actual_length = 0; |
| 2300 | if (endp) { |
| 2301 | unsigned long irqs; |
| 2302 | int retval; |
| 2303 | spin_lock_irqsave(&endp->queue_lock.slock, |
| 2304 | irqs); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2305 | retval = usb_hcd_link_urb_to_ep(hcd, urb); |
| 2306 | if (retval == 0) { |
| 2307 | retval = queue_bulk_on_old_endpoint( |
| 2308 | u132, udev, urb, |
| 2309 | usb_dev, endp, |
| 2310 | usb_addr, usb_endp, |
| 2311 | address); |
| 2312 | if (retval) |
| 2313 | usb_hcd_unlink_urb_from_ep( |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2314 | hcd, urb); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2315 | } |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2316 | spin_unlock_irqrestore(&endp->queue_lock.slock, |
| 2317 | irqs); |
| 2318 | if (retval) { |
| 2319 | return retval; |
| 2320 | } else { |
| 2321 | u132_endp_queue_work(u132, endp, 0); |
| 2322 | return 0; |
| 2323 | } |
| 2324 | } else if (u132->num_endpoints == MAX_U132_ENDPS) { |
| 2325 | return -EINVAL; |
| 2326 | } else |
| 2327 | return create_endpoint_and_queue_bulk(u132, |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2328 | udev, urb, usb_dev, usb_addr, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2329 | usb_endp, address, mem_flags); |
| 2330 | } else { |
| 2331 | struct u132_endp *endp = urb->ep->hcpriv; |
| 2332 | u16 urb_size = 8; |
| 2333 | u8 *b = urb->setup_packet; |
| 2334 | int i = 0; |
| 2335 | char data[30 * 3 + 4]; |
| 2336 | char *d = data; |
| 2337 | int m = (sizeof(data) - 1) / 3; |
| 2338 | int l = 0; |
| 2339 | data[0] = 0; |
| 2340 | while (urb_size-- > 0) { |
| 2341 | if (i > m) { |
| 2342 | } else if (i++ < m) { |
| 2343 | int w = sprintf(d, " %02X", *b++); |
| 2344 | d += w; |
| 2345 | l += w; |
| 2346 | } else |
| 2347 | d += sprintf(d, " .."); |
| 2348 | } |
| 2349 | if (endp) { |
| 2350 | unsigned long irqs; |
| 2351 | int retval; |
| 2352 | spin_lock_irqsave(&endp->queue_lock.slock, |
| 2353 | irqs); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2354 | retval = usb_hcd_link_urb_to_ep(hcd, urb); |
| 2355 | if (retval == 0) { |
| 2356 | retval = queue_control_on_old_endpoint( |
| 2357 | u132, urb, usb_dev, |
| 2358 | endp, usb_addr, |
| 2359 | usb_endp); |
| 2360 | if (retval) |
| 2361 | usb_hcd_unlink_urb_from_ep( |
| 2362 | hcd, urb); |
| 2363 | } |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2364 | spin_unlock_irqrestore(&endp->queue_lock.slock, |
| 2365 | irqs); |
| 2366 | if (retval) { |
| 2367 | return retval; |
| 2368 | } else { |
| 2369 | u132_endp_queue_work(u132, endp, 0); |
| 2370 | return 0; |
| 2371 | } |
| 2372 | } else if (u132->num_endpoints == MAX_U132_ENDPS) { |
| 2373 | return -EINVAL; |
| 2374 | } else |
| 2375 | return create_endpoint_and_queue_control(u132, |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2376 | urb, usb_dev, usb_addr, usb_endp, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2377 | mem_flags); |
| 2378 | } |
| 2379 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | static int dequeue_from_overflow_chain(struct u132 *u132, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2383 | struct u132_endp *endp, struct urb *urb) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2384 | { |
Geliang Tang | 4e5d7a8 | 2015-12-19 00:34:29 +0800 | [diff] [blame] | 2385 | struct u132_urbq *urbq; |
| 2386 | |
| 2387 | list_for_each_entry(urbq, &endp->urb_more, urb_more) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2388 | if (urbq->urb == urb) { |
| 2389 | struct usb_hcd *hcd = u132_to_hcd(u132); |
Geliang Tang | 4e5d7a8 | 2015-12-19 00:34:29 +0800 | [diff] [blame] | 2390 | list_del(&urbq->urb_more); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2391 | endp->queue_size -= 1; |
| 2392 | urb->error_count = 0; |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 2393 | usb_hcd_giveback_urb(hcd, urb, 0); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2394 | return 0; |
Colin Ian King | d6963f2 | 2021-06-17 13:38:26 +0100 | [diff] [blame] | 2395 | } |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2396 | } |
| 2397 | dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring" |
| 2398 | "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X" |
| 2399 | "\n", urb, endp->endp_number, endp, endp->ring->number, |
| 2400 | endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', |
| 2401 | endp->usb_endp, endp->usb_addr, endp->queue_size, |
| 2402 | endp->queue_next, endp->queue_last); |
| 2403 | return -EINVAL; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp, |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2407 | struct urb *urb, int status) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2408 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2409 | unsigned long irqs; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2410 | int rc; |
| 2411 | |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2412 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2413 | rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status); |
| 2414 | if (rc) { |
| 2415 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2416 | return rc; |
| 2417 | } |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2418 | if (endp->queue_size == 0) { |
| 2419 | dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]" |
| 2420 | "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb, |
| 2421 | endp->endp_number, endp, endp->ring->number, |
| 2422 | endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', |
| 2423 | endp->usb_endp, endp->usb_addr); |
| 2424 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2425 | return -EINVAL; |
| 2426 | } |
| 2427 | if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) { |
| 2428 | if (endp->active) { |
| 2429 | endp->dequeueing = 1; |
| 2430 | endp->edset_flush = 1; |
| 2431 | u132_endp_queue_work(u132, endp, 0); |
| 2432 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2433 | return 0; |
| 2434 | } else { |
| 2435 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 2436 | u132_hcd_abandon_urb(u132, endp, urb, status); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2437 | return 0; |
| 2438 | } |
| 2439 | } else { |
| 2440 | u16 queue_list = 0; |
| 2441 | u16 queue_size = endp->queue_size; |
| 2442 | u16 queue_scan = endp->queue_next; |
| 2443 | struct urb **urb_slot = NULL; |
| 2444 | while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { |
| 2445 | if (urb == endp->urb_list[ENDP_QUEUE_MASK & |
| 2446 | ++queue_scan]) { |
| 2447 | urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & |
| 2448 | queue_scan]; |
| 2449 | break; |
Colin Ian King | d6963f2 | 2021-06-17 13:38:26 +0100 | [diff] [blame] | 2450 | } |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2451 | } |
| 2452 | while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { |
| 2453 | *urb_slot = endp->urb_list[ENDP_QUEUE_MASK & |
| 2454 | ++queue_scan]; |
| 2455 | urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & |
| 2456 | queue_scan]; |
| 2457 | } |
| 2458 | if (urb_slot) { |
| 2459 | struct usb_hcd *hcd = u132_to_hcd(u132); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2460 | |
| 2461 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2462 | endp->queue_size -= 1; |
| 2463 | if (list_empty(&endp->urb_more)) { |
| 2464 | spin_unlock_irqrestore(&endp->queue_lock.slock, |
| 2465 | irqs); |
| 2466 | } else { |
| 2467 | struct list_head *next = endp->urb_more.next; |
| 2468 | struct u132_urbq *urbq = list_entry(next, |
| 2469 | struct u132_urbq, urb_more); |
| 2470 | list_del(next); |
| 2471 | *urb_slot = urbq->urb; |
| 2472 | spin_unlock_irqrestore(&endp->queue_lock.slock, |
| 2473 | irqs); |
| 2474 | kfree(urbq); |
Colin Ian King | d1ab1b8 | 2019-01-04 17:43:49 +0000 | [diff] [blame] | 2475 | } |
| 2476 | urb->error_count = 0; |
Alan Stern | 4a00027 | 2007-08-24 15:42:24 -0400 | [diff] [blame] | 2477 | usb_hcd_giveback_urb(hcd, urb, status); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2478 | return 0; |
| 2479 | } else if (list_empty(&endp->urb_more)) { |
| 2480 | dev_err(&u132->platform_dev->dev, "urb=%p not found in " |
| 2481 | "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr" |
| 2482 | "=%d size=%d next=%04X last=%04X\n", urb, |
| 2483 | endp->endp_number, endp, endp->ring->number, |
| 2484 | endp->input ? 'I' : ' ', |
| 2485 | endp->output ? 'O' : ' ', endp->usb_endp, |
| 2486 | endp->usb_addr, endp->queue_size, |
| 2487 | endp->queue_next, endp->queue_last); |
| 2488 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2489 | return -EINVAL; |
| 2490 | } else { |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2491 | int retval; |
| 2492 | |
| 2493 | usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb); |
| 2494 | retval = dequeue_from_overflow_chain(u132, endp, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2495 | urb); |
| 2496 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); |
| 2497 | return retval; |
| 2498 | } |
| 2499 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2500 | } |
| 2501 | |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 2502 | static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2503 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2504 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2505 | if (u132->going > 2) { |
| 2506 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 2507 | , u132->going); |
| 2508 | return -ENODEV; |
| 2509 | } else { |
| 2510 | u8 usb_addr = usb_pipedevice(urb->pipe); |
| 2511 | u8 usb_endp = usb_pipeendpoint(urb->pipe); |
| 2512 | u8 address = u132->addr[usb_addr].address; |
| 2513 | struct u132_udev *udev = &u132->udev[address]; |
| 2514 | if (usb_pipein(urb->pipe)) { |
| 2515 | u8 endp_number = udev->endp_number_in[usb_endp]; |
| 2516 | struct u132_endp *endp = u132->endp[endp_number - 1]; |
| 2517 | return u132_endp_urb_dequeue(u132, endp, urb, status); |
| 2518 | } else { |
| 2519 | u8 endp_number = udev->endp_number_out[usb_endp]; |
| 2520 | struct u132_endp *endp = u132->endp[endp_number - 1]; |
| 2521 | return u132_endp_urb_dequeue(u132, endp, urb, status); |
| 2522 | } |
| 2523 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | static void u132_endpoint_disable(struct usb_hcd *hcd, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2527 | struct usb_host_endpoint *hep) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2528 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2529 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2530 | if (u132->going > 2) { |
| 2531 | dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p" |
| 2532 | ") has been removed %d\n", u132, hcd, hep, |
| 2533 | u132->going); |
| 2534 | } else { |
| 2535 | struct u132_endp *endp = hep->hcpriv; |
| 2536 | if (endp) |
| 2537 | u132_endp_put_kref(u132, endp); |
| 2538 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | static int u132_get_frame(struct usb_hcd *hcd) |
| 2542 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2543 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2544 | if (u132->going > 1) { |
| 2545 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 2546 | , u132->going); |
| 2547 | return -ENODEV; |
| 2548 | } else if (u132->going > 0) { |
| 2549 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 2550 | return -ESHUTDOWN; |
| 2551 | } else { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2552 | dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n"); |
Jia-Ju Bai | 6d4f268 | 2018-09-01 17:23:47 +0800 | [diff] [blame] | 2553 | mdelay(100); |
Hariprasad Kelam | 0e01624 | 2019-06-05 19:48:42 +0530 | [diff] [blame] | 2554 | return 0; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2555 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | static int u132_roothub_descriptor(struct u132 *u132, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2559 | struct usb_hub_descriptor *desc) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2560 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2561 | int retval; |
| 2562 | u16 temp; |
| 2563 | u32 rh_a = -1; |
| 2564 | u32 rh_b = -1; |
| 2565 | retval = u132_read_pcimem(u132, roothub.a, &rh_a); |
| 2566 | if (retval) |
| 2567 | return retval; |
Sergei Shtylyov | 0ce6fe9 | 2015-03-29 01:28:15 +0300 | [diff] [blame] | 2568 | desc->bDescriptorType = USB_DT_HUB; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2569 | desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24; |
| 2570 | desc->bHubContrCurrent = 0; |
| 2571 | desc->bNbrPorts = u132->num_ports; |
| 2572 | temp = 1 + (u132->num_ports / 8); |
| 2573 | desc->bDescLength = 7 + 2 * temp; |
Sergei Shtylyov | a7cf697 | 2015-01-19 01:49:59 +0300 | [diff] [blame] | 2574 | temp = HUB_CHAR_COMMON_LPSM | HUB_CHAR_COMMON_OCPM; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2575 | if (rh_a & RH_A_NPS) |
Sergei Shtylyov | a7cf697 | 2015-01-19 01:49:59 +0300 | [diff] [blame] | 2576 | temp |= HUB_CHAR_NO_LPSM; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2577 | if (rh_a & RH_A_PSM) |
Sergei Shtylyov | a7cf697 | 2015-01-19 01:49:59 +0300 | [diff] [blame] | 2578 | temp |= HUB_CHAR_INDV_PORT_LPSM; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2579 | if (rh_a & RH_A_NOCP) |
Sergei Shtylyov | a7cf697 | 2015-01-19 01:49:59 +0300 | [diff] [blame] | 2580 | temp |= HUB_CHAR_NO_OCPM; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2581 | else if (rh_a & RH_A_OCPM) |
Sergei Shtylyov | a7cf697 | 2015-01-19 01:49:59 +0300 | [diff] [blame] | 2582 | temp |= HUB_CHAR_INDV_PORT_OCPM; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2583 | desc->wHubCharacteristics = cpu_to_le16(temp); |
| 2584 | retval = u132_read_pcimem(u132, roothub.b, &rh_b); |
| 2585 | if (retval) |
| 2586 | return retval; |
John Youn | dbe79bb | 2001-09-17 00:00:00 -0700 | [diff] [blame] | 2587 | memset(desc->u.hs.DeviceRemovable, 0xff, |
| 2588 | sizeof(desc->u.hs.DeviceRemovable)); |
| 2589 | desc->u.hs.DeviceRemovable[0] = rh_b & RH_B_DR; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2590 | if (u132->num_ports > 7) { |
John Youn | dbe79bb | 2001-09-17 00:00:00 -0700 | [diff] [blame] | 2591 | desc->u.hs.DeviceRemovable[1] = (rh_b & RH_B_DR) >> 8; |
| 2592 | desc->u.hs.DeviceRemovable[2] = 0xff; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2593 | } else |
John Youn | dbe79bb | 2001-09-17 00:00:00 -0700 | [diff] [blame] | 2594 | desc->u.hs.DeviceRemovable[1] = 0xff; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2595 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | static int u132_roothub_status(struct u132 *u132, __le32 *desc) |
| 2599 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2600 | u32 rh_status = -1; |
| 2601 | int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status); |
| 2602 | *desc = cpu_to_le32(rh_status); |
| 2603 | return ret_status; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex) |
| 2607 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2608 | if (wIndex == 0 || wIndex > u132->num_ports) { |
| 2609 | return -EINVAL; |
| 2610 | } else { |
| 2611 | int port = wIndex - 1; |
| 2612 | u32 rh_portstatus = -1; |
| 2613 | int ret_portstatus = u132_read_pcimem(u132, |
| 2614 | roothub.portstatus[port], &rh_portstatus); |
| 2615 | *desc = cpu_to_le32(rh_portstatus); |
| 2616 | if (*(u16 *) (desc + 2)) { |
| 2617 | dev_info(&u132->platform_dev->dev, "Port %d Status Chan" |
| 2618 | "ge = %08X\n", port, *desc); |
| 2619 | } |
| 2620 | return ret_portstatus; |
| 2621 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | |
| 2625 | /* this timer value might be vendor-specific ... */ |
| 2626 | #define PORT_RESET_HW_MSEC 10 |
| 2627 | #define PORT_RESET_MSEC 10 |
| 2628 | /* wrap-aware logic morphed from <linux/jiffies.h> */ |
| 2629 | #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) |
| 2630 | static int u132_roothub_portreset(struct u132 *u132, int port_index) |
| 2631 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2632 | int retval; |
| 2633 | u32 fmnumber; |
| 2634 | u16 now; |
| 2635 | u16 reset_done; |
| 2636 | retval = u132_read_pcimem(u132, fmnumber, &fmnumber); |
| 2637 | if (retval) |
| 2638 | return retval; |
| 2639 | now = fmnumber; |
| 2640 | reset_done = now + PORT_RESET_MSEC; |
| 2641 | do { |
| 2642 | u32 portstat; |
| 2643 | do { |
| 2644 | retval = u132_read_pcimem(u132, |
| 2645 | roothub.portstatus[port_index], &portstat); |
| 2646 | if (retval) |
| 2647 | return retval; |
| 2648 | if (RH_PS_PRS & portstat) |
| 2649 | continue; |
| 2650 | else |
| 2651 | break; |
| 2652 | } while (tick_before(now, reset_done)); |
| 2653 | if (RH_PS_PRS & portstat) |
| 2654 | return -ENODEV; |
| 2655 | if (RH_PS_CCS & portstat) { |
| 2656 | if (RH_PS_PRSC & portstat) { |
| 2657 | retval = u132_write_pcimem(u132, |
| 2658 | roothub.portstatus[port_index], |
| 2659 | RH_PS_PRSC); |
| 2660 | if (retval) |
| 2661 | return retval; |
| 2662 | } |
| 2663 | } else |
| 2664 | break; /* start the next reset, |
| 2665 | sleep till it's probably done */ |
| 2666 | retval = u132_write_pcimem(u132, roothub.portstatus[port_index], |
| 2667 | RH_PS_PRS); |
| 2668 | if (retval) |
| 2669 | return retval; |
| 2670 | msleep(PORT_RESET_HW_MSEC); |
| 2671 | retval = u132_read_pcimem(u132, fmnumber, &fmnumber); |
| 2672 | if (retval) |
| 2673 | return retval; |
| 2674 | now = fmnumber; |
| 2675 | } while (tick_before(now, reset_done)); |
| 2676 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2680 | u16 wIndex) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2681 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2682 | if (wIndex == 0 || wIndex > u132->num_ports) { |
| 2683 | return -EINVAL; |
| 2684 | } else { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2685 | int port_index = wIndex - 1; |
| 2686 | struct u132_port *port = &u132->port[port_index]; |
| 2687 | port->Status &= ~(1 << wValue); |
| 2688 | switch (wValue) { |
| 2689 | case USB_PORT_FEAT_SUSPEND: |
Saurabh Karajgaonkar | 8602b08 | 2015-08-04 14:03:45 +0000 | [diff] [blame] | 2690 | return u132_write_pcimem(u132, |
| 2691 | roothub.portstatus[port_index], RH_PS_PSS); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2692 | case USB_PORT_FEAT_POWER: |
Saurabh Karajgaonkar | 8602b08 | 2015-08-04 14:03:45 +0000 | [diff] [blame] | 2693 | return u132_write_pcimem(u132, |
| 2694 | roothub.portstatus[port_index], RH_PS_PPS); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2695 | case USB_PORT_FEAT_RESET: |
Saurabh Karajgaonkar | 8602b08 | 2015-08-04 14:03:45 +0000 | [diff] [blame] | 2696 | return u132_roothub_portreset(u132, port_index); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2697 | default: |
| 2698 | return -EPIPE; |
| 2699 | } |
| 2700 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2704 | u16 wIndex) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2705 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2706 | if (wIndex == 0 || wIndex > u132->num_ports) { |
| 2707 | return -EINVAL; |
| 2708 | } else { |
| 2709 | int port_index = wIndex - 1; |
| 2710 | u32 temp; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2711 | struct u132_port *port = &u132->port[port_index]; |
| 2712 | port->Status &= ~(1 << wValue); |
| 2713 | switch (wValue) { |
| 2714 | case USB_PORT_FEAT_ENABLE: |
| 2715 | temp = RH_PS_CCS; |
| 2716 | break; |
| 2717 | case USB_PORT_FEAT_C_ENABLE: |
| 2718 | temp = RH_PS_PESC; |
| 2719 | break; |
| 2720 | case USB_PORT_FEAT_SUSPEND: |
| 2721 | temp = RH_PS_POCI; |
| 2722 | if ((u132->hc_control & OHCI_CTRL_HCFS) |
| 2723 | != OHCI_USB_OPER) { |
| 2724 | dev_err(&u132->platform_dev->dev, "TODO resume_" |
| 2725 | "root_hub\n"); |
| 2726 | } |
| 2727 | break; |
| 2728 | case USB_PORT_FEAT_C_SUSPEND: |
| 2729 | temp = RH_PS_PSSC; |
| 2730 | break; |
| 2731 | case USB_PORT_FEAT_POWER: |
| 2732 | temp = RH_PS_LSDA; |
| 2733 | break; |
| 2734 | case USB_PORT_FEAT_C_CONNECTION: |
| 2735 | temp = RH_PS_CSC; |
| 2736 | break; |
| 2737 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 2738 | temp = RH_PS_OCIC; |
| 2739 | break; |
| 2740 | case USB_PORT_FEAT_C_RESET: |
| 2741 | temp = RH_PS_PRSC; |
| 2742 | break; |
| 2743 | default: |
| 2744 | return -EPIPE; |
| 2745 | } |
Saurabh Karajgaonkar | 8602b08 | 2015-08-04 14:03:45 +0000 | [diff] [blame] | 2746 | return u132_write_pcimem(u132, roothub.portstatus[port_index], |
| 2747 | temp); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2748 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | |
| 2752 | /* the virtual root hub timer IRQ checks for hub status*/ |
| 2753 | static int u132_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 2754 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2755 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2756 | if (u132->going > 1) { |
| 2757 | dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov" |
| 2758 | "ed %d\n", hcd, u132->going); |
| 2759 | return -ENODEV; |
| 2760 | } else if (u132->going > 0) { |
| 2761 | dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" |
| 2762 | "ed\n", hcd); |
| 2763 | return -ESHUTDOWN; |
| 2764 | } else { |
| 2765 | int i, changed = 0, length = 1; |
| 2766 | if (u132->flags & OHCI_QUIRK_AMD756) { |
| 2767 | if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) { |
| 2768 | dev_err(&u132->platform_dev->dev, "bogus NDP, r" |
| 2769 | "ereads as NDP=%d\n", |
| 2770 | u132->hc_roothub_a & RH_A_NDP); |
| 2771 | goto done; |
| 2772 | } |
| 2773 | } |
| 2774 | if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) |
| 2775 | buf[0] = changed = 1; |
| 2776 | else |
| 2777 | buf[0] = 0; |
| 2778 | if (u132->num_ports > 7) { |
| 2779 | buf[1] = 0; |
| 2780 | length++; |
| 2781 | } |
| 2782 | for (i = 0; i < u132->num_ports; i++) { |
| 2783 | if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC | |
| 2784 | RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC | |
| 2785 | RH_PS_PRSC)) { |
| 2786 | changed = 1; |
| 2787 | if (i < 7) |
| 2788 | buf[0] |= 1 << (i + 1); |
| 2789 | else |
| 2790 | buf[1] |= 1 << (i - 7); |
| 2791 | continue; |
| 2792 | } |
| 2793 | if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) |
| 2794 | continue; |
| 2795 | |
| 2796 | if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) |
| 2797 | continue; |
| 2798 | } |
| 2799 | done: |
| 2800 | return changed ? length : 0; |
| 2801 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2805 | u16 wIndex, char *buf, u16 wLength) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2806 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2807 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2808 | if (u132->going > 1) { |
| 2809 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 2810 | , u132->going); |
| 2811 | return -ENODEV; |
| 2812 | } else if (u132->going > 0) { |
| 2813 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 2814 | return -ESHUTDOWN; |
| 2815 | } else { |
| 2816 | int retval = 0; |
| 2817 | mutex_lock(&u132->sw_lock); |
| 2818 | switch (typeReq) { |
| 2819 | case ClearHubFeature: |
| 2820 | switch (wValue) { |
| 2821 | case C_HUB_OVER_CURRENT: |
| 2822 | case C_HUB_LOCAL_POWER: |
| 2823 | break; |
| 2824 | default: |
| 2825 | goto stall; |
| 2826 | } |
| 2827 | break; |
| 2828 | case SetHubFeature: |
| 2829 | switch (wValue) { |
| 2830 | case C_HUB_OVER_CURRENT: |
| 2831 | case C_HUB_LOCAL_POWER: |
| 2832 | break; |
| 2833 | default: |
| 2834 | goto stall; |
| 2835 | } |
| 2836 | break; |
| 2837 | case ClearPortFeature:{ |
| 2838 | retval = u132_roothub_clearportfeature(u132, |
| 2839 | wValue, wIndex); |
| 2840 | if (retval) |
| 2841 | goto error; |
| 2842 | break; |
| 2843 | } |
| 2844 | case GetHubDescriptor:{ |
| 2845 | retval = u132_roothub_descriptor(u132, |
| 2846 | (struct usb_hub_descriptor *)buf); |
| 2847 | if (retval) |
| 2848 | goto error; |
| 2849 | break; |
| 2850 | } |
| 2851 | case GetHubStatus:{ |
| 2852 | retval = u132_roothub_status(u132, |
| 2853 | (__le32 *) buf); |
| 2854 | if (retval) |
| 2855 | goto error; |
| 2856 | break; |
| 2857 | } |
| 2858 | case GetPortStatus:{ |
| 2859 | retval = u132_roothub_portstatus(u132, |
| 2860 | (__le32 *) buf, wIndex); |
| 2861 | if (retval) |
| 2862 | goto error; |
| 2863 | break; |
| 2864 | } |
| 2865 | case SetPortFeature:{ |
| 2866 | retval = u132_roothub_setportfeature(u132, |
| 2867 | wValue, wIndex); |
| 2868 | if (retval) |
| 2869 | goto error; |
| 2870 | break; |
| 2871 | } |
| 2872 | default: |
| 2873 | goto stall; |
| 2874 | error: |
| 2875 | u132_disable(u132); |
| 2876 | u132->going = 1; |
| 2877 | break; |
| 2878 | stall: |
| 2879 | retval = -EPIPE; |
| 2880 | break; |
| 2881 | } |
| 2882 | mutex_unlock(&u132->sw_lock); |
| 2883 | return retval; |
| 2884 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num) |
| 2888 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2889 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2890 | if (u132->going > 1) { |
| 2891 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 2892 | , u132->going); |
| 2893 | return -ENODEV; |
| 2894 | } else if (u132->going > 0) { |
| 2895 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 2896 | return -ESHUTDOWN; |
| 2897 | } else |
| 2898 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2899 | } |
| 2900 | |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2901 | |
| 2902 | #ifdef CONFIG_PM |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2903 | static int u132_bus_suspend(struct usb_hcd *hcd) |
| 2904 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2905 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2906 | if (u132->going > 1) { |
| 2907 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 2908 | , u132->going); |
| 2909 | return -ENODEV; |
| 2910 | } else if (u132->going > 0) { |
| 2911 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 2912 | return -ESHUTDOWN; |
| 2913 | } else |
| 2914 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | static int u132_bus_resume(struct usb_hcd *hcd) |
| 2918 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2919 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2920 | if (u132->going > 1) { |
| 2921 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 2922 | , u132->going); |
| 2923 | return -ENODEV; |
| 2924 | } else if (u132->going > 0) { |
| 2925 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 2926 | return -ESHUTDOWN; |
| 2927 | } else |
| 2928 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | #else |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2932 | #define u132_bus_suspend NULL |
| 2933 | #define u132_bus_resume NULL |
| 2934 | #endif |
Julia Lawall | 0b88b1c | 2017-07-28 22:41:52 +0200 | [diff] [blame] | 2935 | static const struct hc_driver u132_hc_driver = { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2936 | .description = hcd_name, |
| 2937 | .hcd_priv_size = sizeof(struct u132), |
| 2938 | .irq = NULL, |
| 2939 | .flags = HCD_USB11 | HCD_MEMORY, |
| 2940 | .reset = u132_hcd_reset, |
| 2941 | .start = u132_hcd_start, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2942 | .stop = u132_hcd_stop, |
| 2943 | .urb_enqueue = u132_urb_enqueue, |
| 2944 | .urb_dequeue = u132_urb_dequeue, |
| 2945 | .endpoint_disable = u132_endpoint_disable, |
| 2946 | .get_frame_number = u132_get_frame, |
| 2947 | .hub_status_data = u132_hub_status_data, |
| 2948 | .hub_control = u132_hub_control, |
| 2949 | .bus_suspend = u132_bus_suspend, |
| 2950 | .bus_resume = u132_bus_resume, |
| 2951 | .start_port_reset = u132_start_port_reset, |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2952 | }; |
| 2953 | |
| 2954 | /* |
| 2955 | * This function may be called by the USB core whilst the "usb_all_devices_rwsem" |
| 2956 | * is held for writing, thus this module must not call usb_remove_hcd() |
| 2957 | * synchronously - but instead should immediately stop activity to the |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 2958 | * device and asynchronously call usb_remove_hcd() |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2959 | */ |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 2960 | static int u132_remove(struct platform_device *pdev) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2961 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2962 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 2963 | if (hcd) { |
| 2964 | struct u132 *u132 = hcd_to_u132(hcd); |
| 2965 | if (u132->going++ > 1) { |
| 2966 | dev_err(&u132->platform_dev->dev, "already being remove" |
Tony Olech | 4b87361 | 2006-12-06 13:16:22 +0000 | [diff] [blame] | 2967 | "d\n"); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2968 | return -ENODEV; |
| 2969 | } else { |
| 2970 | int rings = MAX_U132_RINGS; |
| 2971 | int endps = MAX_U132_ENDPS; |
| 2972 | dev_err(&u132->platform_dev->dev, "removing device u132" |
Tony Olech | 4b87361 | 2006-12-06 13:16:22 +0000 | [diff] [blame] | 2973 | ".%d\n", u132->sequence_num); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2974 | msleep(100); |
| 2975 | mutex_lock(&u132->sw_lock); |
| 2976 | u132_monitor_cancel_work(u132); |
| 2977 | while (rings-- > 0) { |
| 2978 | struct u132_ring *ring = &u132->ring[rings]; |
| 2979 | u132_ring_cancel_work(u132, ring); |
Colin Ian King | d1ab1b8 | 2019-01-04 17:43:49 +0000 | [diff] [blame] | 2980 | } |
| 2981 | while (endps-- > 0) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 2982 | struct u132_endp *endp = u132->endp[endps]; |
| 2983 | if (endp) |
| 2984 | u132_endp_cancel_work(u132, endp); |
| 2985 | } |
| 2986 | u132->going += 1; |
| 2987 | printk(KERN_INFO "removing device u132.%d\n", |
| 2988 | u132->sequence_num); |
| 2989 | mutex_unlock(&u132->sw_lock); |
| 2990 | usb_remove_hcd(hcd); |
| 2991 | u132_u132_put_kref(u132); |
| 2992 | return 0; |
| 2993 | } |
| 2994 | } else |
| 2995 | return 0; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | static void u132_initialise(struct u132 *u132, struct platform_device *pdev) |
| 2999 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3000 | int rings = MAX_U132_RINGS; |
| 3001 | int ports = MAX_U132_PORTS; |
| 3002 | int addrs = MAX_U132_ADDRS; |
| 3003 | int udevs = MAX_U132_UDEVS; |
| 3004 | int endps = MAX_U132_ENDPS; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 3005 | u132->board = dev_get_platdata(&pdev->dev); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3006 | u132->platform_dev = pdev; |
| 3007 | u132->power = 0; |
| 3008 | u132->reset = 0; |
| 3009 | mutex_init(&u132->sw_lock); |
Daniel Walker | 50d8ca9 | 2008-03-23 00:00:02 -0700 | [diff] [blame] | 3010 | mutex_init(&u132->scheduler_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3011 | while (rings-- > 0) { |
| 3012 | struct u132_ring *ring = &u132->ring[rings]; |
| 3013 | ring->u132 = u132; |
| 3014 | ring->number = rings + 1; |
| 3015 | ring->length = 0; |
| 3016 | ring->curr_endp = NULL; |
| 3017 | INIT_DELAYED_WORK(&ring->scheduler, |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3018 | u132_hcd_ring_work_scheduler); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3019 | } |
| 3020 | mutex_lock(&u132->sw_lock); |
| 3021 | INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work); |
| 3022 | while (ports-- > 0) { |
| 3023 | struct u132_port *port = &u132->port[ports]; |
| 3024 | port->u132 = u132; |
| 3025 | port->reset = 0; |
| 3026 | port->enable = 0; |
| 3027 | port->power = 0; |
| 3028 | port->Status = 0; |
| 3029 | } |
| 3030 | while (addrs-- > 0) { |
| 3031 | struct u132_addr *addr = &u132->addr[addrs]; |
| 3032 | addr->address = 0; |
| 3033 | } |
| 3034 | while (udevs-- > 0) { |
| 3035 | struct u132_udev *udev = &u132->udev[udevs]; |
| 3036 | int i = ARRAY_SIZE(udev->endp_number_in); |
| 3037 | int o = ARRAY_SIZE(udev->endp_number_out); |
| 3038 | udev->usb_device = NULL; |
| 3039 | udev->udev_number = 0; |
| 3040 | udev->usb_addr = 0; |
| 3041 | udev->portnumber = 0; |
| 3042 | while (i-- > 0) |
| 3043 | udev->endp_number_in[i] = 0; |
| 3044 | |
| 3045 | while (o-- > 0) |
| 3046 | udev->endp_number_out[o] = 0; |
| 3047 | |
| 3048 | } |
| 3049 | while (endps-- > 0) |
| 3050 | u132->endp[endps] = NULL; |
| 3051 | |
| 3052 | mutex_unlock(&u132->sw_lock); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3053 | } |
| 3054 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 3055 | static int u132_probe(struct platform_device *pdev) |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3056 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3057 | struct usb_hcd *hcd; |
| 3058 | int retval; |
| 3059 | u32 control; |
| 3060 | u32 rh_a = -1; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3061 | |
| 3062 | msleep(100); |
| 3063 | if (u132_exiting > 0) |
| 3064 | return -ENODEV; |
| 3065 | |
| 3066 | retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE); |
| 3067 | if (retval) |
| 3068 | return retval; |
| 3069 | retval = ftdi_read_pcimem(pdev, control, &control); |
| 3070 | if (retval) |
| 3071 | return retval; |
| 3072 | retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a); |
| 3073 | if (retval) |
| 3074 | return retval; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3075 | |
Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 3076 | hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, dev_name(&pdev->dev)); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3077 | if (!hcd) { |
| 3078 | printk(KERN_ERR "failed to create the usb hcd struct for U132\n" |
| 3079 | ); |
| 3080 | ftdi_elan_gone_away(pdev); |
| 3081 | return -ENOMEM; |
| 3082 | } else { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3083 | struct u132 *u132 = hcd_to_u132(hcd); |
Bill Pemberton | 6641445 | 2010-04-29 10:04:56 -0400 | [diff] [blame] | 3084 | retval = 0; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3085 | hcd->rsrc_start = 0; |
| 3086 | mutex_lock(&u132_module_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3087 | u132->sequence_num = ++u132_instances; |
| 3088 | mutex_unlock(&u132_module_lock); |
| 3089 | u132_u132_init_kref(u132); |
| 3090 | u132_initialise(u132, pdev); |
| 3091 | hcd->product_desc = "ELAN U132 Host Controller"; |
| 3092 | retval = usb_add_hcd(hcd, 0, 0); |
| 3093 | if (retval != 0) { |
| 3094 | dev_err(&u132->platform_dev->dev, "init error %d\n", |
| 3095 | retval); |
| 3096 | u132_u132_put_kref(u132); |
| 3097 | return retval; |
| 3098 | } else { |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 3099 | device_wakeup_enable(hcd->self.controller); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3100 | u132_monitor_queue_work(u132, 100); |
| 3101 | return 0; |
| 3102 | } |
| 3103 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | |
| 3107 | #ifdef CONFIG_PM |
Alan Stern | 84ebc10 | 2013-03-27 16:14:46 -0400 | [diff] [blame] | 3108 | /* |
| 3109 | * for this device there's no useful distinction between the controller |
Rafael J. Wysocki | ceb6c9c | 2014-11-29 23:47:05 +0100 | [diff] [blame] | 3110 | * and its root hub. |
Alan Stern | 84ebc10 | 2013-03-27 16:14:46 -0400 | [diff] [blame] | 3111 | */ |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3112 | static int u132_suspend(struct platform_device *pdev, pm_message_t state) |
| 3113 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3114 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 3115 | struct u132 *u132 = hcd_to_u132(hcd); |
| 3116 | if (u132->going > 1) { |
| 3117 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 3118 | , u132->going); |
| 3119 | return -ENODEV; |
| 3120 | } else if (u132->going > 0) { |
| 3121 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 3122 | return -ESHUTDOWN; |
| 3123 | } else { |
Mirco Tischler | 038eb0e | 2008-02-24 05:16:39 +0100 | [diff] [blame] | 3124 | int retval = 0, ports; |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 3125 | |
| 3126 | switch (state.event) { |
| 3127 | case PM_EVENT_FREEZE: |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3128 | retval = u132_bus_suspend(hcd); |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 3129 | break; |
| 3130 | case PM_EVENT_SUSPEND: |
| 3131 | case PM_EVENT_HIBERNATE: |
Mirco Tischler | 038eb0e | 2008-02-24 05:16:39 +0100 | [diff] [blame] | 3132 | ports = MAX_U132_PORTS; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3133 | while (ports-- > 0) { |
| 3134 | port_power(u132, ports, 0); |
| 3135 | } |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 3136 | break; |
| 3137 | } |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3138 | return retval; |
| 3139 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | static int u132_resume(struct platform_device *pdev) |
| 3143 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3144 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 3145 | struct u132 *u132 = hcd_to_u132(hcd); |
| 3146 | if (u132->going > 1) { |
| 3147 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" |
| 3148 | , u132->going); |
| 3149 | return -ENODEV; |
| 3150 | } else if (u132->going > 0) { |
| 3151 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); |
| 3152 | return -ESHUTDOWN; |
| 3153 | } else { |
| 3154 | int retval = 0; |
Alan Stern | 70a1c9e | 2008-03-06 17:00:58 -0500 | [diff] [blame] | 3155 | if (!u132->port[0].power) { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3156 | int ports = MAX_U132_PORTS; |
| 3157 | while (ports-- > 0) { |
| 3158 | port_power(u132, ports, 1); |
| 3159 | } |
| 3160 | retval = 0; |
| 3161 | } else { |
| 3162 | retval = u132_bus_resume(hcd); |
| 3163 | } |
| 3164 | return retval; |
| 3165 | } |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | #else |
| 3169 | #define u132_suspend NULL |
| 3170 | #define u132_resume NULL |
| 3171 | #endif |
| 3172 | /* |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 3173 | * this driver is loaded explicitly by ftdi_u132 |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3174 | * |
| 3175 | * the platform_driver struct is static because it is per type of module |
| 3176 | */ |
| 3177 | static struct platform_driver u132_platform_driver = { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3178 | .probe = u132_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 3179 | .remove = u132_remove, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3180 | .suspend = u132_suspend, |
| 3181 | .resume = u132_resume, |
| 3182 | .driver = { |
Geert Uytterhoeven | a458677 | 2013-11-12 20:07:25 +0100 | [diff] [blame] | 3183 | .name = hcd_name, |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3184 | }, |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3185 | }; |
| 3186 | static int __init u132_hcd_init(void) |
| 3187 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3188 | int retval; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3189 | u132_instances = 0; |
| 3190 | u132_exiting = 0; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3191 | if (usb_disabled()) |
| 3192 | return -ENODEV; |
Michal Marek | 654d121 | 2011-04-05 16:59:11 +0200 | [diff] [blame] | 3193 | printk(KERN_INFO "driver %s\n", hcd_name); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3194 | workqueue = create_singlethread_workqueue("u132"); |
Kangjie Lu | 3de3dbe | 2019-03-19 12:34:06 -0500 | [diff] [blame] | 3195 | if (!workqueue) |
| 3196 | return -ENOMEM; |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3197 | retval = platform_driver_register(&u132_platform_driver); |
Mukesh Ojha | f276e00 | 2019-03-26 13:42:22 +0530 | [diff] [blame] | 3198 | if (retval) |
| 3199 | destroy_workqueue(workqueue); |
| 3200 | |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3201 | return retval; |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | |
| 3205 | module_init(u132_hcd_init); |
| 3206 | static void __exit u132_hcd_exit(void) |
| 3207 | { |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3208 | mutex_lock(&u132_module_lock); |
| 3209 | u132_exiting += 1; |
| 3210 | mutex_unlock(&u132_module_lock); |
Daniel Walker | b40f8d3 | 2008-03-23 00:00:01 -0700 | [diff] [blame] | 3211 | platform_driver_unregister(&u132_platform_driver); |
| 3212 | printk(KERN_INFO "u132-hcd driver deregistered\n"); |
| 3213 | wait_event(u132_hcd_wait, u132_instances == 0); |
| 3214 | flush_workqueue(workqueue); |
| 3215 | destroy_workqueue(workqueue); |
Tony Olech | d774efe | 2006-09-13 11:27:35 +0100 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | |
| 3219 | module_exit(u132_hcd_exit); |
| 3220 | MODULE_LICENSE("GPL"); |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 3221 | MODULE_ALIAS("platform:u132_hcd"); |