Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the PLX NET2280 USB device controller. |
| 3 | * Specs and errata are available from <http://www.plxtech.com>. |
| 4 | * |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 5 | * PLX Technology Inc. (formerly NetChip Technology) supported the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * development of this driver. |
| 7 | * |
| 8 | * |
| 9 | * CODE STATUS HIGHLIGHTS |
| 10 | * |
| 11 | * This driver should work well with most "gadget" drivers, including |
Michal Nazarewicz | fa06920 | 2012-11-06 22:52:36 +0100 | [diff] [blame] | 12 | * the Mass Storage, Serial, and Ethernet/RNDIS gadget drivers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * as well as Gadget Zero and Gadgetfs. |
| 14 | * |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 15 | * DMA is enabled by default. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 17 | * MSI is enabled by default. The legacy IRQ is used if MSI couldn't |
| 18 | * be enabled. |
| 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * Note that almost all the errata workarounds here are only needed for |
| 21 | * rev1 chips. Rev1a silicon (0110) fixes almost all of them. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Copyright (C) 2003 David Brownell |
| 26 | * Copyright (C) 2003-2005 PLX Technology, Inc. |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 27 | * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 29 | * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility |
| 30 | * with 2282 chip |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 31 | * |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 32 | * Modified Ricardo Ribalda Qtechnology AS to provide compatibility |
| 33 | * with usb 338x chip. Based on PLX driver |
| 34 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * This program is free software; you can redistribute it and/or modify |
| 36 | * it under the terms of the GNU General Public License as published by |
| 37 | * the Free Software Foundation; either version 2 of the License, or |
| 38 | * (at your option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | */ |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/module.h> |
| 42 | #include <linux/pci.h> |
David Brownell | 682d4c8 | 2006-01-18 23:55:08 -0800 | [diff] [blame] | 43 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/kernel.h> |
| 45 | #include <linux/delay.h> |
| 46 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/errno.h> |
| 49 | #include <linux/init.h> |
| 50 | #include <linux/timer.h> |
| 51 | #include <linux/list.h> |
| 52 | #include <linux/interrupt.h> |
| 53 | #include <linux/moduleparam.h> |
| 54 | #include <linux/device.h> |
David Brownell | 5f84813 | 2006-12-16 15:34:53 -0800 | [diff] [blame] | 55 | #include <linux/usb/ch9.h> |
David Brownell | 9454a57 | 2007-10-04 18:05:17 -0700 | [diff] [blame] | 56 | #include <linux/usb/gadget.h> |
Bryan Wu | b38b03b | 2011-06-02 12:51:29 +0800 | [diff] [blame] | 57 | #include <linux/prefetch.h> |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 58 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <asm/unaligned.h> |
| 63 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 64 | #define DRIVER_DESC "PLX NET228x/USB338x USB Peripheral Controller" |
| 65 | #define DRIVER_VERSION "2005 Sept 27/v3.0" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define EP_DONTUSE 13 /* nonzero */ |
| 68 | |
| 69 | #define USE_RDK_LEDS /* GPIO pins control three LEDs */ |
| 70 | |
| 71 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 72 | static const char driver_name[] = "net2280"; |
| 73 | static const char driver_desc[] = DRIVER_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 75 | static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 }; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 76 | static const char ep0name[] = "ep0"; |
| 77 | static const char *const ep_name[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | ep0name, |
| 79 | "ep-a", "ep-b", "ep-c", "ep-d", |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 80 | "ep-e", "ep-f", "ep-g", "ep-h", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Mian Yousaf Kaukab | a285f40 | 2015-02-02 10:55:23 +0100 | [diff] [blame] | 83 | /* Endpoint names for usb3380 advance mode */ |
| 84 | static const char *const ep_name_adv[] = { |
| 85 | ep0name, |
| 86 | "ep1in", "ep2out", "ep3in", "ep4out", |
| 87 | "ep1out", "ep2in", "ep3out", "ep4in", |
| 88 | }; |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* mode 0 == ep-{a,b,c,d} 1K fifo each |
| 91 | * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable |
| 92 | * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable |
| 93 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 94 | static ushort fifo_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* "modprobe net2280 fifo_mode=1" etc */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 97 | module_param(fifo_mode, ushort, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* enable_suspend -- When enabled, the driver will respond to |
| 100 | * USB suspend requests by powering down the NET2280. Otherwise, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 101 | * USB suspend requests will be ignored. This is acceptable for |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 102 | * self-powered devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | */ |
Ricardo Ribalda Delgado | 00d4db0 | 2014-05-20 18:30:06 +0200 | [diff] [blame] | 104 | static bool enable_suspend; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* "modprobe net2280 enable_suspend=1" etc */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 107 | module_param(enable_suspend, bool, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") |
| 110 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 111 | static char *type_string(u8 bmAttributes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { |
| 114 | case USB_ENDPOINT_XFER_BULK: return "bulk"; |
| 115 | case USB_ENDPOINT_XFER_ISOC: return "iso"; |
| 116 | case USB_ENDPOINT_XFER_INT: return "intr"; |
Joe Perches | 2b84f92 | 2013-10-08 16:01:37 -0700 | [diff] [blame] | 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | return "control"; |
| 119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | #include "net2280.h" |
| 122 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 123 | #define valid_bit cpu_to_le32(BIT(VALID_BIT)) |
| 124 | #define dma_done_ie cpu_to_le32(BIT(DMA_DONE_INTERRUPT_ENABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Mian Yousaf Kaukab | e6ac4bb | 2015-05-16 22:33:31 +0200 | [diff] [blame] | 126 | static void ep_clear_seqnum(struct net2280_ep *ep); |
Mian Yousaf Kaukab | 11bece5 | 2015-05-16 22:33:39 +0200 | [diff] [blame] | 127 | static void stop_activity(struct net2280 *dev, |
| 128 | struct usb_gadget_driver *driver); |
| 129 | static void ep0_start(struct net2280 *dev); |
Mian Yousaf Kaukab | e6ac4bb | 2015-05-16 22:33:31 +0200 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /*-------------------------------------------------------------------------*/ |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 132 | static inline void enable_pciirqenb(struct net2280_ep *ep) |
| 133 | { |
| 134 | u32 tmp = readl(&ep->dev->regs->pciirqenb0); |
| 135 | |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 136 | if (ep->dev->quirks & PLX_LEGACY) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 137 | tmp |= BIT(ep->num); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 138 | else |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 139 | tmp |= BIT(ep_bit[ep->num]); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 140 | writel(tmp, &ep->dev->regs->pciirqenb0); |
| 141 | |
| 142 | return; |
| 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | static int |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 146 | net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | struct net2280 *dev; |
| 149 | struct net2280_ep *ep; |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 150 | u32 max; |
| 151 | u32 tmp = 0; |
| 152 | u32 type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | unsigned long flags; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 154 | static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 }; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 155 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 157 | ep = container_of(_ep, struct net2280_ep, ep); |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 158 | if (!_ep || !desc || ep->desc || _ep->name == ep0name || |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 159 | desc->bDescriptorType != USB_DT_ENDPOINT) { |
| 160 | pr_err("%s: failed at line=%d\n", __func__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return -EINVAL; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | dev = ep->dev; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 164 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { |
| 165 | ret = -ESHUTDOWN; |
| 166 | goto print_err; |
| 167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | /* erratum 0119 workaround ties up an endpoint number */ |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 170 | if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) { |
| 171 | ret = -EDOM; |
| 172 | goto print_err; |
| 173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 175 | if (dev->quirks & PLX_SUPERSPEED) { |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 176 | if ((desc->bEndpointAddress & 0x0f) >= 0x0c) { |
| 177 | ret = -EDOM; |
| 178 | goto print_err; |
| 179 | } |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 180 | ep->is_in = !!usb_endpoint_dir_in(desc); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 181 | if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) { |
| 182 | ret = -EINVAL; |
| 183 | goto print_err; |
| 184 | } |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* sanity check ep-e/ep-f since their fifos are small */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 188 | max = usb_endpoint_maxp(desc) & 0x1fff; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 189 | if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) { |
| 190 | ret = -ERANGE; |
| 191 | goto print_err; |
| 192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 194 | spin_lock_irqsave(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | _ep->maxpacket = max & 0x7ff; |
| 196 | ep->desc = desc; |
| 197 | |
| 198 | /* ep_reset() has already been called */ |
| 199 | ep->stopped = 0; |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 200 | ep->wedged = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | ep->out_overflow = 0; |
| 202 | |
| 203 | /* set speed-dependent max packet; may kick in high bandwidth */ |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 204 | set_max_speed(ep, max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | /* set type, direction, address; reset fifo counters */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 207 | writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 208 | |
| 209 | if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) { |
| 210 | tmp = readl(&ep->cfg->ep_cfg); |
| 211 | /* If USB ep number doesn't match hardware ep number */ |
| 212 | if ((tmp & 0xf) != usb_endpoint_num(desc)) { |
| 213 | ret = -EINVAL; |
| 214 | spin_unlock_irqrestore(&dev->lock, flags); |
| 215 | goto print_err; |
| 216 | } |
| 217 | if (ep->is_in) |
| 218 | tmp &= ~USB3380_EP_CFG_MASK_IN; |
| 219 | else |
| 220 | tmp &= ~USB3380_EP_CFG_MASK_OUT; |
| 221 | } |
| 222 | type = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); |
| 223 | if (type == USB_ENDPOINT_XFER_INT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | /* erratum 0105 workaround prevents hs NYET */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 225 | if (dev->chiprev == 0100 && |
| 226 | dev->gadget.speed == USB_SPEED_HIGH && |
| 227 | !(desc->bEndpointAddress & USB_DIR_IN)) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 228 | writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | &ep->regs->ep_rsp); |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 230 | } else if (type == USB_ENDPOINT_XFER_BULK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | /* catch some particularly blatant driver bugs */ |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 232 | if ((dev->gadget.speed == USB_SPEED_SUPER && max != 1024) || |
| 233 | (dev->gadget.speed == USB_SPEED_HIGH && max != 512) || |
| 234 | (dev->gadget.speed == USB_SPEED_FULL && max > 64)) { |
| 235 | spin_unlock_irqrestore(&dev->lock, flags); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 236 | ret = -ERANGE; |
| 237 | goto print_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 240 | ep->is_iso = (type == USB_ENDPOINT_XFER_ISOC); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 241 | /* Enable this endpoint */ |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 242 | if (dev->quirks & PLX_LEGACY) { |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 243 | tmp |= type << ENDPOINT_TYPE; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 244 | tmp |= desc->bEndpointAddress; |
| 245 | /* default full fifo lines */ |
| 246 | tmp |= (4 << ENDPOINT_BYTE_COUNT); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 247 | tmp |= BIT(ENDPOINT_ENABLE); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 248 | ep->is_in = (tmp & USB_DIR_IN) != 0; |
| 249 | } else { |
| 250 | /* In Legacy mode, only OUT endpoints are used */ |
| 251 | if (dev->enhanced_mode && ep->is_in) { |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 252 | tmp |= type << IN_ENDPOINT_TYPE; |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 253 | tmp |= BIT(IN_ENDPOINT_ENABLE); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 254 | } else { |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 255 | tmp |= type << OUT_ENDPOINT_TYPE; |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 256 | tmp |= BIT(OUT_ENDPOINT_ENABLE); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 257 | tmp |= (ep->is_in << ENDPOINT_DIRECTION); |
| 258 | } |
| 259 | |
Mian Yousaf Kaukab | 463e104 | 2015-05-16 22:33:34 +0200 | [diff] [blame] | 260 | tmp |= (4 << ENDPOINT_BYTE_COUNT); |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 261 | if (!dev->enhanced_mode) |
| 262 | tmp |= usb_endpoint_num(desc); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 263 | tmp |= (ep->ep.maxburst << MAX_BURST_SIZE); |
| 264 | } |
| 265 | |
| 266 | /* Make sure all the registers are written before ep_rsp*/ |
| 267 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | /* for OUT transfers, block the rx fifo until a read is posted */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (!ep->is_in) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 271 | writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 272 | else if (!(dev->quirks & PLX_2280)) { |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 273 | /* Added for 2282, Don't use nak packets on an in endpoint, |
| 274 | * this was ignored on 2280 |
| 275 | */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 276 | writel(BIT(CLEAR_NAK_OUT_PACKETS) | |
| 277 | BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Mian Yousaf Kaukab | e6ac4bb | 2015-05-16 22:33:31 +0200 | [diff] [blame] | 280 | if (dev->quirks & PLX_SUPERSPEED) |
| 281 | ep_clear_seqnum(ep); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 282 | writel(tmp, &ep->cfg->ep_cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | /* enable irqs */ |
| 285 | if (!ep->dma) { /* pio, per-packet */ |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 286 | enable_pciirqenb(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 288 | tmp = BIT(DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) | |
| 289 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE); |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 290 | if (dev->quirks & PLX_2280) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 291 | tmp |= readl(&ep->regs->ep_irqenb); |
| 292 | writel(tmp, &ep->regs->ep_irqenb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } else { /* dma, per-request */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 294 | tmp = BIT((8 + ep->num)); /* completion */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 295 | tmp |= readl(&dev->regs->pciirqenb1); |
| 296 | writel(tmp, &dev->regs->pciirqenb1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | /* for short OUT transfers, dma completions can't |
| 299 | * advance the queue; do it pio-style, by hand. |
| 300 | * NOTE erratum 0112 workaround #2 |
| 301 | */ |
| 302 | if ((desc->bEndpointAddress & USB_DIR_IN) == 0) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 303 | tmp = BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 304 | writel(tmp, &ep->regs->ep_irqenb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 306 | enable_pciirqenb(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
| 310 | tmp = desc->bEndpointAddress; |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 311 | ep_dbg(dev, "enabled %s (ep%d%s-%s) %s max %04x\n", |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 312 | _ep->name, tmp & 0x0f, DIR_STRING(tmp), |
| 313 | type_string(desc->bmAttributes), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | ep->dma ? "dma" : "pio", max); |
| 315 | |
| 316 | /* pci writes may still be posted */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 317 | spin_unlock_irqrestore(&dev->lock, flags); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 318 | return ret; |
| 319 | |
| 320 | print_err: |
| 321 | dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret); |
| 322 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 325 | static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
| 327 | u32 result; |
| 328 | |
| 329 | do { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 330 | result = readl(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (result == ~(u32)0) /* "device unplugged" */ |
| 332 | return -ENODEV; |
| 333 | result &= mask; |
| 334 | if (result == done) |
| 335 | return 0; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 336 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | usec--; |
| 338 | } while (usec > 0); |
| 339 | return -ETIMEDOUT; |
| 340 | } |
| 341 | |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 342 | static const struct usb_ep_ops net2280_ep_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 344 | static void ep_reset_228x(struct net2280_regs __iomem *regs, |
| 345 | struct net2280_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
| 347 | u32 tmp; |
| 348 | |
| 349 | ep->desc = NULL; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 350 | INIT_LIST_HEAD(&ep->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Robert Baldyga | e117e74 | 2013-12-13 12:23:38 +0100 | [diff] [blame] | 352 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | ep->ep.ops = &net2280_ep_ops; |
| 354 | |
| 355 | /* disable the dma, irqs, endpoint... */ |
| 356 | if (ep->dma) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 357 | writel(0, &ep->dma->dmactl); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 358 | writel(BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) | |
| 359 | BIT(DMA_TRANSACTION_DONE_INTERRUPT) | |
| 360 | BIT(DMA_ABORT), |
| 361 | &ep->dma->dmastat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 363 | tmp = readl(®s->pciirqenb0); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 364 | tmp &= ~BIT(ep->num); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 365 | writel(tmp, ®s->pciirqenb0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } else { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 367 | tmp = readl(®s->pciirqenb1); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 368 | tmp &= ~BIT((8 + ep->num)); /* completion */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 369 | writel(tmp, ®s->pciirqenb1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 371 | writel(0, &ep->regs->ep_irqenb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | /* init to our chosen defaults, notably so that we NAK OUT |
| 374 | * packets until the driver queues a read (+note erratum 0112) |
| 375 | */ |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 376 | if (!ep->is_in || (ep->dev->quirks & PLX_2280)) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 377 | tmp = BIT(SET_NAK_OUT_PACKETS_MODE) | |
| 378 | BIT(SET_NAK_OUT_PACKETS) | |
| 379 | BIT(CLEAR_EP_HIDE_STATUS_PHASE) | |
| 380 | BIT(CLEAR_INTERRUPT_MODE); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 381 | } else { |
| 382 | /* added for 2282 */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 383 | tmp = BIT(CLEAR_NAK_OUT_PACKETS_MODE) | |
| 384 | BIT(CLEAR_NAK_OUT_PACKETS) | |
| 385 | BIT(CLEAR_EP_HIDE_STATUS_PHASE) | |
| 386 | BIT(CLEAR_INTERRUPT_MODE); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | if (ep->num != 0) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 390 | tmp |= BIT(CLEAR_ENDPOINT_TOGGLE) | |
| 391 | BIT(CLEAR_ENDPOINT_HALT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 393 | writel(tmp, &ep->regs->ep_rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | /* scrub most status bits, and flush any fifo state */ |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 396 | if (ep->dev->quirks & PLX_2280) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 397 | tmp = BIT(FIFO_OVERFLOW) | |
| 398 | BIT(FIFO_UNDERFLOW); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 399 | else |
| 400 | tmp = 0; |
| 401 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 402 | writel(tmp | BIT(TIMEOUT) | |
| 403 | BIT(USB_STALL_SENT) | |
| 404 | BIT(USB_IN_NAK_SENT) | |
| 405 | BIT(USB_IN_ACK_RCVD) | |
| 406 | BIT(USB_OUT_PING_NAK_SENT) | |
| 407 | BIT(USB_OUT_ACK_SENT) | |
| 408 | BIT(FIFO_FLUSH) | |
| 409 | BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) | |
| 410 | BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) | |
| 411 | BIT(DATA_PACKET_RECEIVED_INTERRUPT) | |
| 412 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | |
| 413 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 414 | BIT(DATA_IN_TOKEN_INTERRUPT), |
| 415 | &ep->regs->ep_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | /* fifo size is handled separately */ |
| 418 | } |
| 419 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 420 | static void ep_reset_338x(struct net2280_regs __iomem *regs, |
| 421 | struct net2280_ep *ep) |
| 422 | { |
| 423 | u32 tmp, dmastat; |
| 424 | |
| 425 | ep->desc = NULL; |
| 426 | INIT_LIST_HEAD(&ep->queue); |
| 427 | |
| 428 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
| 429 | ep->ep.ops = &net2280_ep_ops; |
| 430 | |
| 431 | /* disable the dma, irqs, endpoint... */ |
| 432 | if (ep->dma) { |
| 433 | writel(0, &ep->dma->dmactl); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 434 | writel(BIT(DMA_ABORT_DONE_INTERRUPT) | |
| 435 | BIT(DMA_PAUSE_DONE_INTERRUPT) | |
| 436 | BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 437 | BIT(DMA_TRANSACTION_DONE_INTERRUPT), |
| 438 | /* | BIT(DMA_ABORT), */ |
| 439 | &ep->dma->dmastat); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 440 | |
| 441 | dmastat = readl(&ep->dma->dmastat); |
| 442 | if (dmastat == 0x5002) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 443 | ep_warn(ep->dev, "The dmastat return = %x!!\n", |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 444 | dmastat); |
| 445 | writel(0x5a, &ep->dma->dmastat); |
| 446 | } |
| 447 | |
| 448 | tmp = readl(®s->pciirqenb0); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 449 | tmp &= ~BIT(ep_bit[ep->num]); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 450 | writel(tmp, ®s->pciirqenb0); |
| 451 | } else { |
| 452 | if (ep->num < 5) { |
| 453 | tmp = readl(®s->pciirqenb1); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 454 | tmp &= ~BIT((8 + ep->num)); /* completion */ |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 455 | writel(tmp, ®s->pciirqenb1); |
| 456 | } |
| 457 | } |
| 458 | writel(0, &ep->regs->ep_irqenb); |
| 459 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 460 | writel(BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) | |
| 461 | BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) | |
| 462 | BIT(FIFO_OVERFLOW) | |
| 463 | BIT(DATA_PACKET_RECEIVED_INTERRUPT) | |
| 464 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | |
| 465 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | |
| 466 | BIT(DATA_IN_TOKEN_INTERRUPT), &ep->regs->ep_stat); |
Mian Yousaf Kaukab | 971fe65 | 2015-05-16 22:33:38 +0200 | [diff] [blame] | 467 | |
| 468 | tmp = readl(&ep->cfg->ep_cfg); |
| 469 | if (ep->is_in) |
| 470 | tmp &= ~USB3380_EP_CFG_MASK_IN; |
| 471 | else |
| 472 | tmp &= ~USB3380_EP_CFG_MASK_OUT; |
| 473 | writel(tmp, &ep->cfg->ep_cfg); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 474 | } |
| 475 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 476 | static void nuke(struct net2280_ep *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 478 | static int net2280_disable(struct usb_ep *_ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | struct net2280_ep *ep; |
| 481 | unsigned long flags; |
| 482 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 483 | ep = container_of(_ep, struct net2280_ep, ep); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 484 | if (!_ep || !ep->desc || _ep->name == ep0name) { |
| 485 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | return -EINVAL; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 487 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 488 | spin_lock_irqsave(&ep->dev->lock, flags); |
| 489 | nuke(ep); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 490 | |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 491 | if (ep->dev->quirks & PLX_SUPERSPEED) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 492 | ep_reset_338x(ep->dev->regs, ep); |
| 493 | else |
| 494 | ep_reset_228x(ep->dev->regs, ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 496 | ep_vdbg(ep->dev, "disabled %s %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | ep->dma ? "dma" : "pio", _ep->name); |
| 498 | |
| 499 | /* synch memory views with the device */ |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 500 | (void)readl(&ep->cfg->ep_cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Ricardo Ribalda Delgado | d588ff5 | 2014-11-28 14:50:49 +0100 | [diff] [blame] | 502 | if (!ep->dma && ep->num >= 1 && ep->num <= 4) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 503 | ep->dma = &ep->dev->dma[ep->num - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 505 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | /*-------------------------------------------------------------------------*/ |
| 510 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 511 | static struct usb_request |
| 512 | *net2280_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
| 514 | struct net2280_ep *ep; |
| 515 | struct net2280_request *req; |
| 516 | |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 517 | if (!_ep) { |
| 518 | pr_err("%s: Invalid ep\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | return NULL; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 520 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 521 | ep = container_of(_ep, struct net2280_ep, ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Eric Sesterhenn | 7039f42 | 2006-02-27 13:34:10 -0800 | [diff] [blame] | 523 | req = kzalloc(sizeof(*req), gfp_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (!req) |
| 525 | return NULL; |
| 526 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 527 | INIT_LIST_HEAD(&req->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | /* this dma descriptor may be swapped with the previous dummy */ |
| 530 | if (ep->dma) { |
| 531 | struct net2280_dma *td; |
| 532 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 533 | td = pci_pool_alloc(ep->dev->requests, gfp_flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | &req->td_dma); |
| 535 | if (!td) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 536 | kfree(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return NULL; |
| 538 | } |
| 539 | td->dmacount = 0; /* not VALID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | td->dmadesc = td->dmaaddr; |
| 541 | req->td = td; |
| 542 | } |
| 543 | return &req->req; |
| 544 | } |
| 545 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 546 | static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
| 548 | struct net2280_ep *ep; |
| 549 | struct net2280_request *req; |
| 550 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 551 | ep = container_of(_ep, struct net2280_ep, ep); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 552 | if (!_ep || !_req) { |
| 553 | dev_err(&ep->dev->pdev->dev, "%s: Inavlid ep=%p or req=%p\n", |
| 554 | __func__, _ep, _req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | return; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 558 | req = container_of(_req, struct net2280_request, req); |
| 559 | WARN_ON(!list_empty(&req->queue)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | if (req->td) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 561 | pci_pool_free(ep->dev->requests, req->td, req->td_dma); |
| 562 | kfree(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /*-------------------------------------------------------------------------*/ |
| 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | /* load a packet into the fifo we use for usb IN transfers. |
| 568 | * works for all endpoints. |
| 569 | * |
| 570 | * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo |
| 571 | * at a time, but this code is simpler because it knows it only writes |
| 572 | * one packet. ep-a..ep-d should use dma instead. |
| 573 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 574 | static void write_fifo(struct net2280_ep *ep, struct usb_request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
| 576 | struct net2280_ep_regs __iomem *regs = ep->regs; |
| 577 | u8 *buf; |
| 578 | u32 tmp; |
| 579 | unsigned count, total; |
| 580 | |
| 581 | /* INVARIANT: fifo is currently empty. (testable) */ |
| 582 | |
| 583 | if (req) { |
| 584 | buf = req->buf + req->actual; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 585 | prefetch(buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | total = req->length - req->actual; |
| 587 | } else { |
| 588 | total = 0; |
| 589 | buf = NULL; |
| 590 | } |
| 591 | |
| 592 | /* write just one packet at a time */ |
| 593 | count = ep->ep.maxpacket; |
| 594 | if (count > total) /* min() cannot be used on a bitfield */ |
| 595 | count = total; |
| 596 | |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 597 | ep_vdbg(ep->dev, "write %s fifo (IN) %d bytes%s req %p\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | ep->ep.name, count, |
| 599 | (count != ep->ep.maxpacket) ? " (short)" : "", |
| 600 | req); |
| 601 | while (count >= 4) { |
| 602 | /* NOTE be careful if you try to align these. fifo lines |
| 603 | * should normally be full (4 bytes) and successive partial |
| 604 | * lines are ok only in certain cases. |
| 605 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 606 | tmp = get_unaligned((u32 *)buf); |
| 607 | cpu_to_le32s(&tmp); |
| 608 | writel(tmp, ®s->ep_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | buf += 4; |
| 610 | count -= 4; |
| 611 | } |
| 612 | |
| 613 | /* last fifo entry is "short" unless we wrote a full packet. |
| 614 | * also explicitly validate last word in (periodic) transfers |
| 615 | * when maxpacket is not a multiple of 4 bytes. |
| 616 | */ |
| 617 | if (count || total < ep->ep.maxpacket) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 618 | tmp = count ? get_unaligned((u32 *)buf) : count; |
| 619 | cpu_to_le32s(&tmp); |
| 620 | set_fifo_bytecount(ep, count & 0x03); |
| 621 | writel(tmp, ®s->ep_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /* pci writes may still be posted */ |
| 625 | } |
| 626 | |
| 627 | /* work around erratum 0106: PCI and USB race over the OUT fifo. |
| 628 | * caller guarantees chiprev 0100, out endpoint is NAKing, and |
| 629 | * there's no real data in the fifo. |
| 630 | * |
| 631 | * NOTE: also used in cases where that erratum doesn't apply: |
| 632 | * where the host wrote "too much" data to us. |
| 633 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 634 | static void out_flush(struct net2280_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { |
| 636 | u32 __iomem *statp; |
| 637 | u32 tmp; |
| 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | statp = &ep->regs->ep_stat; |
Ricardo Ribalda Delgado | d82f3db | 2014-11-28 14:51:01 +0100 | [diff] [blame] | 640 | |
| 641 | tmp = readl(statp); |
| 642 | if (tmp & BIT(NAK_OUT_PACKETS)) { |
| 643 | ep_dbg(ep->dev, "%s %s %08x !NAK\n", |
| 644 | ep->ep.name, __func__, tmp); |
| 645 | writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); |
| 646 | } |
| 647 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 648 | writel(BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 649 | BIT(DATA_PACKET_RECEIVED_INTERRUPT), |
| 650 | statp); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 651 | writel(BIT(FIFO_FLUSH), statp); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 652 | /* Make sure that stap is written */ |
| 653 | mb(); |
| 654 | tmp = readl(statp); |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 655 | if (tmp & BIT(DATA_OUT_PING_TOKEN_INTERRUPT) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | /* high speed did bulk NYET; fifo isn't filling */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 657 | ep->dev->gadget.speed == USB_SPEED_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | unsigned usec; |
| 659 | |
| 660 | usec = 50; /* 64 byte bulk/interrupt */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 661 | handshake(statp, BIT(USB_OUT_PING_NAK_SENT), |
| 662 | BIT(USB_OUT_PING_NAK_SENT), usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */ |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /* unload packet(s) from the fifo we use for usb OUT transfers. |
| 668 | * returns true iff the request completed, because of short packet |
| 669 | * or the request buffer having filled with full packets. |
| 670 | * |
| 671 | * for ep-a..ep-d this will read multiple packets out when they |
| 672 | * have been accepted. |
| 673 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 674 | static int read_fifo(struct net2280_ep *ep, struct net2280_request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
| 676 | struct net2280_ep_regs __iomem *regs = ep->regs; |
| 677 | u8 *buf = req->req.buf + req->req.actual; |
| 678 | unsigned count, tmp, is_short; |
| 679 | unsigned cleanup = 0, prevent = 0; |
| 680 | |
| 681 | /* erratum 0106 ... packets coming in during fifo reads might |
| 682 | * be incompletely rejected. not all cases have workarounds. |
| 683 | */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 684 | if (ep->dev->chiprev == 0x0100 && |
| 685 | ep->dev->gadget.speed == USB_SPEED_FULL) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 686 | udelay(1); |
| 687 | tmp = readl(&ep->regs->ep_stat); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 688 | if ((tmp & BIT(NAK_OUT_PACKETS))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | cleanup = 1; |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 690 | else if ((tmp & BIT(FIFO_FULL))) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 691 | start_out_naking(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | prevent = 1; |
| 693 | } |
| 694 | /* else: hope we don't see the problem */ |
| 695 | } |
| 696 | |
| 697 | /* never overflow the rx buffer. the fifo reads packets until |
| 698 | * it sees a short one; we might not be ready for them all. |
| 699 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 700 | prefetchw(buf); |
| 701 | count = readl(®s->ep_avail); |
| 702 | if (unlikely(count == 0)) { |
| 703 | udelay(1); |
| 704 | tmp = readl(&ep->regs->ep_stat); |
| 705 | count = readl(®s->ep_avail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | /* handled that data already? */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 707 | if (count == 0 && (tmp & BIT(NAK_OUT_PACKETS)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | tmp = req->req.length - req->req.actual; |
| 712 | if (count > tmp) { |
| 713 | /* as with DMA, data overflow gets flushed */ |
| 714 | if ((tmp % ep->ep.maxpacket) != 0) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 715 | ep_err(ep->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | "%s out fifo %d bytes, expected %d\n", |
| 717 | ep->ep.name, count, tmp); |
| 718 | req->req.status = -EOVERFLOW; |
| 719 | cleanup = 1; |
| 720 | /* NAK_OUT_PACKETS will be set, so flushing is safe; |
| 721 | * the next read will start with the next packet |
| 722 | */ |
| 723 | } /* else it's a ZLP, no worries */ |
| 724 | count = tmp; |
| 725 | } |
| 726 | req->req.actual += count; |
| 727 | |
| 728 | is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0); |
| 729 | |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 730 | ep_vdbg(ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | ep->ep.name, count, is_short ? " (short)" : "", |
| 732 | cleanup ? " flush" : "", prevent ? " nak" : "", |
| 733 | req, req->req.actual, req->req.length); |
| 734 | |
| 735 | while (count >= 4) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 736 | tmp = readl(®s->ep_data); |
| 737 | cpu_to_le32s(&tmp); |
| 738 | put_unaligned(tmp, (u32 *)buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | buf += 4; |
| 740 | count -= 4; |
| 741 | } |
| 742 | if (count) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 743 | tmp = readl(®s->ep_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | /* LE conversion is implicit here: */ |
| 745 | do { |
| 746 | *buf++ = (u8) tmp; |
| 747 | tmp >>= 8; |
| 748 | } while (--count); |
| 749 | } |
| 750 | if (cleanup) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 751 | out_flush(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | if (prevent) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 753 | writel(BIT(CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 754 | (void) readl(&ep->regs->ep_rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 757 | return is_short || ((req->req.actual == req->req.length) && |
| 758 | !req->req.zero); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /* fill out dma descriptor to match a given request */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 762 | static void fill_dma_desc(struct net2280_ep *ep, |
| 763 | struct net2280_request *req, int valid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
| 765 | struct net2280_dma *td = req->td; |
| 766 | u32 dmacount = req->req.length; |
| 767 | |
| 768 | /* don't let DMA continue after a short OUT packet, |
| 769 | * so overruns can't affect the next transfer. |
| 770 | * in case of overruns on max-size packets, we can't |
| 771 | * stop the fifo from filling but we can flush it. |
| 772 | */ |
| 773 | if (ep->is_in) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 774 | dmacount |= BIT(DMA_DIRECTION); |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 775 | if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) || |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 776 | !(ep->dev->quirks & PLX_2280)) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 777 | dmacount |= BIT(END_OF_CHAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | req->valid = valid; |
| 780 | if (valid) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 781 | dmacount |= BIT(VALID_BIT); |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 782 | dmacount |= BIT(DMA_DONE_INTERRUPT_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
| 784 | /* td->dmadesc = previously set by caller */ |
| 785 | td->dmaaddr = cpu_to_le32 (req->req.dma); |
| 786 | |
| 787 | /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 788 | wmb(); |
Harvey Harrison | da2bbdc | 2008-10-29 14:25:51 -0700 | [diff] [blame] | 789 | td->dmacount = cpu_to_le32(dmacount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static const u32 dmactl_default = |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 793 | BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) | |
| 794 | BIT(DMA_CLEAR_COUNT_ENABLE) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | /* erratum 0116 workaround part 1 (use POLLING) */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 796 | (POLL_100_USEC << DESCRIPTOR_POLLING_RATE) | |
| 797 | BIT(DMA_VALID_BIT_POLLING_ENABLE) | |
| 798 | BIT(DMA_VALID_BIT_ENABLE) | |
| 799 | BIT(DMA_SCATTER_GATHER_ENABLE) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | /* erratum 0116 workaround part 2 (no AUTOSTART) */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 801 | BIT(DMA_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 803 | static inline void spin_stop_dma(struct net2280_dma_regs __iomem *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 805 | handshake(&dma->dmactl, BIT(DMA_ENABLE), 0, 50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 808 | static inline void stop_dma(struct net2280_dma_regs __iomem *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 810 | writel(readl(&dma->dmactl) & ~BIT(DMA_ENABLE), &dma->dmactl); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 811 | spin_stop_dma(dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 814 | static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
| 816 | struct net2280_dma_regs __iomem *dma = ep->dma; |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 817 | unsigned int tmp = BIT(VALID_BIT) | (ep->is_in << DMA_DIRECTION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 819 | if (!(ep->dev->quirks & PLX_2280)) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 820 | tmp |= BIT(END_OF_CHAIN); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 821 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 822 | writel(tmp, &dma->dmacount); |
| 823 | writel(readl(&dma->dmastat), &dma->dmastat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 825 | writel(td_dma, &dma->dmadesc); |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 826 | if (ep->dev->quirks & PLX_SUPERSPEED) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 827 | dmactl |= BIT(DMA_REQUEST_OUTSTANDING); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 828 | writel(dmactl, &dma->dmactl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | /* erratum 0116 workaround part 3: pci arbiter away from net2280 */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 831 | (void) readl(&ep->dev->pci->pcimstctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 833 | writel(BIT(DMA_START), &dma->dmastat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 835 | if (!ep->is_in) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 836 | stop_out_naking(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 839 | static void start_dma(struct net2280_ep *ep, struct net2280_request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | { |
| 841 | u32 tmp; |
| 842 | struct net2280_dma_regs __iomem *dma = ep->dma; |
| 843 | |
| 844 | /* FIXME can't use DMA for ZLPs */ |
| 845 | |
| 846 | /* on this path we "know" there's no dma active (yet) */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 847 | WARN_ON(readl(&dma->dmactl) & BIT(DMA_ENABLE)); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 848 | writel(0, &ep->dma->dmactl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | /* previous OUT packet might have been short */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 851 | if (!ep->is_in && (readl(&ep->regs->ep_stat) & |
| 852 | BIT(NAK_OUT_PACKETS))) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 853 | writel(BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | &ep->regs->ep_stat); |
| 855 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 856 | tmp = readl(&ep->regs->ep_avail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | if (tmp) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 858 | writel(readl(&dma->dmastat), &dma->dmastat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
| 860 | /* transfer all/some fifo data */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 861 | writel(req->req.dma, &dma->dmaaddr); |
| 862 | tmp = min(tmp, req->req.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | /* dma irq, faking scatterlist status */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 865 | req->td->dmacount = cpu_to_le32(req->req.length - tmp); |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 866 | writel(BIT(DMA_DONE_INTERRUPT_ENABLE) | tmp, |
| 867 | &dma->dmacount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | req->td->dmadesc = 0; |
| 869 | req->valid = 1; |
| 870 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 871 | writel(BIT(DMA_ENABLE), &dma->dmactl); |
| 872 | writel(BIT(DMA_START), &dma->dmastat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | return; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | tmp = dmactl_default; |
| 878 | |
| 879 | /* force packet boundaries between dma requests, but prevent the |
| 880 | * controller from automagically writing a last "short" packet |
| 881 | * (zero length) unless the driver explicitly said to do that. |
| 882 | */ |
| 883 | if (ep->is_in) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 884 | if (likely((req->req.length % ep->ep.maxpacket) || |
| 885 | req->req.zero)){ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 886 | tmp |= BIT(DMA_FIFO_VALIDATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | ep->in_fifo_validate = 1; |
| 888 | } else |
| 889 | ep->in_fifo_validate = 0; |
| 890 | } |
| 891 | |
| 892 | /* init req->td, pointing to the current dummy */ |
| 893 | req->td->dmadesc = cpu_to_le32 (ep->td_dma); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 894 | fill_dma_desc(ep, req, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 896 | req->td->dmacount |= cpu_to_le32(BIT(END_OF_CHAIN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 898 | start_queue(ep, tmp, req->td_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static inline void |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 902 | queue_dma(struct net2280_ep *ep, struct net2280_request *req, int valid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
| 904 | struct net2280_dma *end; |
| 905 | dma_addr_t tmp; |
| 906 | |
| 907 | /* swap new dummy for old, link; fill and maybe activate */ |
| 908 | end = ep->dummy; |
| 909 | ep->dummy = req->td; |
| 910 | req->td = end; |
| 911 | |
| 912 | tmp = ep->td_dma; |
| 913 | ep->td_dma = req->td_dma; |
| 914 | req->td_dma = tmp; |
| 915 | |
| 916 | end->dmadesc = cpu_to_le32 (ep->td_dma); |
| 917 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 918 | fill_dma_desc(ep, req, valid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | static void |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 922 | done(struct net2280_ep *ep, struct net2280_request *req, int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
| 924 | struct net2280 *dev; |
| 925 | unsigned stopped = ep->stopped; |
| 926 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 927 | list_del_init(&req->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | if (req->req.status == -EINPROGRESS) |
| 930 | req->req.status = status; |
| 931 | else |
| 932 | status = req->req.status; |
| 933 | |
| 934 | dev = ep->dev; |
Felipe Balbi | ae4d793 | 2011-12-19 12:09:56 +0200 | [diff] [blame] | 935 | if (ep->dma) |
| 936 | usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
| 938 | if (status && status != -ESHUTDOWN) |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 939 | ep_vdbg(dev, "complete %s req %p stat %d len %u/%u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | ep->ep.name, &req->req, status, |
| 941 | req->req.actual, req->req.length); |
| 942 | |
| 943 | /* don't modify queue heads during completion callback */ |
| 944 | ep->stopped = 1; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 945 | spin_unlock(&dev->lock); |
Michal Sojka | 304f7e5 | 2014-09-24 22:43:19 +0200 | [diff] [blame] | 946 | usb_gadget_giveback_request(&ep->ep, &req->req); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 947 | spin_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | ep->stopped = stopped; |
| 949 | } |
| 950 | |
| 951 | /*-------------------------------------------------------------------------*/ |
| 952 | |
| 953 | static int |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 954 | net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
| 956 | struct net2280_request *req; |
| 957 | struct net2280_ep *ep; |
| 958 | struct net2280 *dev; |
| 959 | unsigned long flags; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 960 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | /* we always require a cpu-view buffer, so that we can |
| 963 | * always use pio (as fallback or whatever). |
| 964 | */ |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 965 | ep = container_of(_ep, struct net2280_ep, ep); |
| 966 | if (!_ep || (!ep->desc && ep->num != 0)) { |
| 967 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); |
| 968 | return -EINVAL; |
| 969 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 970 | req = container_of(_req, struct net2280_request, req); |
| 971 | if (!_req || !_req->complete || !_req->buf || |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 972 | !list_empty(&req->queue)) { |
| 973 | ret = -EINVAL; |
| 974 | goto print_err; |
| 975 | } |
| 976 | if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) { |
| 977 | ret = -EDOM; |
| 978 | goto print_err; |
| 979 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | dev = ep->dev; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 981 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { |
| 982 | ret = -ESHUTDOWN; |
| 983 | goto print_err; |
| 984 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
| 986 | /* FIXME implement PIO fallback for ZLPs with DMA */ |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 987 | if (ep->dma && _req->length == 0) { |
| 988 | ret = -EOPNOTSUPP; |
| 989 | goto print_err; |
| 990 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
| 992 | /* set up dma mapping in case the caller didn't */ |
Felipe Balbi | ae4d793 | 2011-12-19 12:09:56 +0200 | [diff] [blame] | 993 | if (ep->dma) { |
Felipe Balbi | ae4d793 | 2011-12-19 12:09:56 +0200 | [diff] [blame] | 994 | ret = usb_gadget_map_request(&dev->gadget, _req, |
| 995 | ep->is_in); |
| 996 | if (ret) |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 997 | goto print_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 1000 | ep_vdbg(dev, "%s queue req %p, len %d buf %p\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | _ep->name, _req, _req->length, _req->buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1003 | spin_lock_irqsave(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
| 1005 | _req->status = -EINPROGRESS; |
| 1006 | _req->actual = 0; |
| 1007 | |
| 1008 | /* kickstart this i/o queue? */ |
Ricardo Ribalda Delgado | 485f44d | 2014-11-28 14:50:56 +0100 | [diff] [blame] | 1009 | if (list_empty(&ep->queue) && !ep->stopped && |
| 1010 | !((dev->quirks & PLX_SUPERSPEED) && ep->dma && |
| 1011 | (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)))) { |
| 1012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | /* use DMA if the endpoint supports it, else pio */ |
Ricardo Ribalda Delgado | 485f44d | 2014-11-28 14:50:56 +0100 | [diff] [blame] | 1014 | if (ep->dma) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1015 | start_dma(ep, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | else { |
| 1017 | /* maybe there's no control data, just status ack */ |
| 1018 | if (ep->num == 0 && _req->length == 0) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1019 | allow_status(ep); |
| 1020 | done(ep, req, 0); |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 1021 | ep_vdbg(dev, "%s status ack\n", ep->ep.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | goto done; |
| 1023 | } |
| 1024 | |
| 1025 | /* PIO ... stuff the fifo, or unblock it. */ |
| 1026 | if (ep->is_in) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1027 | write_fifo(ep, _req); |
| 1028 | else if (list_empty(&ep->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | u32 s; |
| 1030 | |
| 1031 | /* OUT FIFO might have packet(s) buffered */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1032 | s = readl(&ep->regs->ep_stat); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1033 | if ((s & BIT(FIFO_EMPTY)) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | /* note: _req->short_not_ok is |
| 1035 | * ignored here since PIO _always_ |
| 1036 | * stops queue advance here, and |
| 1037 | * _req->status doesn't change for |
| 1038 | * short reads (only _req->actual) |
| 1039 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1040 | if (read_fifo(ep, req) && |
| 1041 | ep->num == 0) { |
| 1042 | done(ep, req, 0); |
| 1043 | allow_status(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | /* don't queue it */ |
| 1045 | req = NULL; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1046 | } else if (read_fifo(ep, req) && |
| 1047 | ep->num != 0) { |
| 1048 | done(ep, req, 0); |
| 1049 | req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | } else |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1051 | s = readl(&ep->regs->ep_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /* don't NAK, let the fifo fill */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1055 | if (req && (s & BIT(NAK_OUT_PACKETS))) |
| 1056 | writel(BIT(CLEAR_NAK_OUT_PACKETS), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | &ep->regs->ep_rsp); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | } else if (ep->dma) { |
| 1062 | int valid = 1; |
| 1063 | |
| 1064 | if (ep->is_in) { |
| 1065 | int expect; |
| 1066 | |
| 1067 | /* preventing magic zlps is per-engine state, not |
| 1068 | * per-transfer; irq logic must recover hiccups. |
| 1069 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1070 | expect = likely(req->req.zero || |
| 1071 | (req->req.length % ep->ep.maxpacket)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | if (expect != ep->in_fifo_validate) |
| 1073 | valid = 0; |
| 1074 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1075 | queue_dma(ep, req, valid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
| 1077 | } /* else the irq handler advances the queue. */ |
| 1078 | |
Alan Stern | 1f26e28 | 2006-11-16 10:16:00 -0500 | [diff] [blame] | 1079 | ep->responded = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | if (req) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1081 | list_add_tail(&req->queue, &ep->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | done: |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1083 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
| 1085 | /* pci writes may still be posted */ |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1086 | return ret; |
| 1087 | |
| 1088 | print_err: |
| 1089 | dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret); |
| 1090 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static inline void |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1094 | dma_done(struct net2280_ep *ep, struct net2280_request *req, u32 dmacount, |
| 1095 | int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | { |
| 1097 | req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1098 | done(ep, req, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1101 | static void scan_dma_completions(struct net2280_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | { |
| 1103 | /* only look at descriptors that were "naturally" retired, |
| 1104 | * so fifo and list head state won't matter |
| 1105 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1106 | while (!list_empty(&ep->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | struct net2280_request *req; |
| 1108 | u32 tmp; |
| 1109 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1110 | req = list_entry(ep->queue.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | struct net2280_request, queue); |
| 1112 | if (!req->valid) |
| 1113 | break; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1114 | rmb(); |
| 1115 | tmp = le32_to_cpup(&req->td->dmacount); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1116 | if ((tmp & BIT(VALID_BIT)) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | break; |
| 1118 | |
| 1119 | /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short" |
| 1120 | * cases where DMA must be aborted; this code handles |
| 1121 | * all non-abort DMA completions. |
| 1122 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1123 | if (unlikely(req->td->dmadesc == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | /* paranoia */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1125 | tmp = readl(&ep->dma->dmacount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | if (tmp & DMA_BYTE_COUNT_MASK) |
| 1127 | break; |
| 1128 | /* single transfer mode */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1129 | dma_done(ep, req, tmp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | break; |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 1131 | } else if (!ep->is_in && |
Ricardo Ribalda Delgado | 43780aa | 2014-11-28 14:51:00 +0100 | [diff] [blame] | 1132 | (req->req.length % ep->ep.maxpacket) && |
| 1133 | !(ep->dev->quirks & PLX_SUPERSPEED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
Mario Schuknecht | 18a4e65 | 2014-11-16 21:21:45 +0100 | [diff] [blame] | 1135 | tmp = readl(&ep->regs->ep_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | /* AVOID TROUBLE HERE by not issuing short reads from |
| 1137 | * your gadget driver. That helps avoids errata 0121, |
| 1138 | * 0122, and 0124; not all cases trigger the warning. |
| 1139 | */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1140 | if ((tmp & BIT(NAK_OUT_PACKETS)) == 0) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 1141 | ep_warn(ep->dev, "%s lost packet sync!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | ep->ep.name); |
| 1143 | req->req.status = -EOVERFLOW; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1144 | } else { |
| 1145 | tmp = readl(&ep->regs->ep_avail); |
| 1146 | if (tmp) { |
| 1147 | /* fifo gets flushed later */ |
| 1148 | ep->out_overflow = 1; |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 1149 | ep_dbg(ep->dev, |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1150 | "%s dma, discard %d len %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | ep->ep.name, tmp, |
| 1152 | req->req.length); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1153 | req->req.status = -EOVERFLOW; |
| 1154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } |
| 1156 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1157 | dma_done(ep, req, tmp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1161 | static void restart_dma(struct net2280_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
| 1163 | struct net2280_request *req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
| 1165 | if (ep->stopped) |
| 1166 | return; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1167 | req = list_entry(ep->queue.next, struct net2280_request, queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 1169 | start_dma(ep, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Ricardo Ribalda Delgado | e721c45 | 2014-11-28 14:50:55 +0100 | [diff] [blame] | 1172 | static void abort_dma(struct net2280_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | { |
| 1174 | /* abort the current transfer */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1175 | if (likely(!list_empty(&ep->queue))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | /* FIXME work around errata 0121, 0122, 0124 */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1177 | writel(BIT(DMA_ABORT), &ep->dma->dmastat); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1178 | spin_stop_dma(ep->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | } else |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1180 | stop_dma(ep->dma); |
| 1181 | scan_dma_completions(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /* dequeue ALL requests */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1185 | static void nuke(struct net2280_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | { |
| 1187 | struct net2280_request *req; |
| 1188 | |
| 1189 | /* called with spinlock held */ |
| 1190 | ep->stopped = 1; |
| 1191 | if (ep->dma) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1192 | abort_dma(ep); |
| 1193 | while (!list_empty(&ep->queue)) { |
| 1194 | req = list_entry(ep->queue.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | struct net2280_request, |
| 1196 | queue); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1197 | done(ep, req, -ESHUTDOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | /* dequeue JUST ONE request */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1202 | static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { |
| 1204 | struct net2280_ep *ep; |
| 1205 | struct net2280_request *req; |
| 1206 | unsigned long flags; |
| 1207 | u32 dmactl; |
| 1208 | int stopped; |
| 1209 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1210 | ep = container_of(_ep, struct net2280_ep, ep); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1211 | if (!_ep || (!ep->desc && ep->num != 0) || !_req) { |
| 1212 | pr_err("%s: Invalid ep=%p or ep->desc or req=%p\n", |
| 1213 | __func__, _ep, _req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | return -EINVAL; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1217 | spin_lock_irqsave(&ep->dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | stopped = ep->stopped; |
| 1219 | |
| 1220 | /* quiesce dma while we patch the queue */ |
| 1221 | dmactl = 0; |
| 1222 | ep->stopped = 1; |
| 1223 | if (ep->dma) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1224 | dmactl = readl(&ep->dma->dmactl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | /* WARNING erratum 0127 may kick in ... */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1226 | stop_dma(ep->dma); |
| 1227 | scan_dma_completions(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | /* make sure it's still queued on this endpoint */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1231 | list_for_each_entry(req, &ep->queue, queue) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | if (&req->req == _req) |
| 1233 | break; |
| 1234 | } |
| 1235 | if (&req->req != _req) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1236 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1237 | dev_err(&ep->dev->pdev->dev, "%s: Request mismatch\n", |
| 1238 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | return -EINVAL; |
| 1240 | } |
| 1241 | |
| 1242 | /* queue head may be partially complete. */ |
| 1243 | if (ep->queue.next == &req->queue) { |
| 1244 | if (ep->dma) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 1245 | ep_dbg(ep->dev, "unlink (%s) dma\n", _ep->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | _req->status = -ECONNRESET; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1247 | abort_dma(ep); |
| 1248 | if (likely(ep->queue.next == &req->queue)) { |
| 1249 | /* NOTE: misreports single-transfer mode*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | req->td->dmacount = 0; /* invalidate */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1251 | dma_done(ep, req, |
| 1252 | readl(&ep->dma->dmacount), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | -ECONNRESET); |
| 1254 | } |
| 1255 | } else { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 1256 | ep_dbg(ep->dev, "unlink (%s) pio\n", _ep->name); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1257 | done(ep, req, -ECONNRESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | } |
| 1259 | req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | if (req) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1263 | done(ep, req, -ECONNRESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | ep->stopped = stopped; |
| 1265 | |
| 1266 | if (ep->dma) { |
| 1267 | /* turn off dma on inactive queues */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1268 | if (list_empty(&ep->queue)) |
| 1269 | stop_dma(ep->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | else if (!ep->stopped) { |
| 1271 | /* resume current request, or start new one */ |
| 1272 | if (req) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1273 | writel(dmactl, &ep->dma->dmactl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | else |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1275 | start_dma(ep, list_entry(ep->queue.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | struct net2280_request, queue)); |
| 1277 | } |
| 1278 | } |
| 1279 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1280 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | /*-------------------------------------------------------------------------*/ |
| 1285 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1286 | static int net2280_fifo_status(struct usb_ep *_ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
| 1288 | static int |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1289 | net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | { |
| 1291 | struct net2280_ep *ep; |
| 1292 | unsigned long flags; |
| 1293 | int retval = 0; |
| 1294 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1295 | ep = container_of(_ep, struct net2280_ep, ep); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1296 | if (!_ep || (!ep->desc && ep->num != 0)) { |
| 1297 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | return -EINVAL; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1299 | } |
| 1300 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { |
| 1301 | retval = -ESHUTDOWN; |
| 1302 | goto print_err; |
| 1303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03) |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1305 | == USB_ENDPOINT_XFER_ISOC) { |
| 1306 | retval = -EINVAL; |
| 1307 | goto print_err; |
| 1308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1310 | spin_lock_irqsave(&ep->dev->lock, flags); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1311 | if (!list_empty(&ep->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | retval = -EAGAIN; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1313 | goto print_unlock; |
| 1314 | } else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | retval = -EAGAIN; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1316 | goto print_unlock; |
| 1317 | } else { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 1318 | ep_vdbg(ep->dev, "%s %s %s\n", _ep->name, |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1319 | value ? "set" : "clear", |
| 1320 | wedged ? "wedge" : "halt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | /* set/clear, then synch memory views with the device */ |
| 1322 | if (value) { |
| 1323 | if (ep->num == 0) |
| 1324 | ep->dev->protocol_stall = 1; |
| 1325 | else |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1326 | set_halt(ep); |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1327 | if (wedged) |
| 1328 | ep->wedged = 1; |
| 1329 | } else { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1330 | clear_halt(ep); |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 1331 | if (ep->dev->quirks & PLX_SUPERSPEED && |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1332 | !list_empty(&ep->queue) && ep->td_dma) |
| 1333 | restart_dma(ep); |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1334 | ep->wedged = 0; |
| 1335 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1336 | (void) readl(&ep->regs->ep_rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1338 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | |
| 1340 | return retval; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1341 | |
| 1342 | print_unlock: |
| 1343 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
| 1344 | print_err: |
| 1345 | dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, retval); |
| 1346 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1349 | static int net2280_set_halt(struct usb_ep *_ep, int value) |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1350 | { |
| 1351 | return net2280_set_halt_and_wedge(_ep, value, 0); |
| 1352 | } |
| 1353 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1354 | static int net2280_set_wedge(struct usb_ep *_ep) |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1355 | { |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1356 | if (!_ep || _ep->name == ep0name) { |
| 1357 | pr_err("%s: Invalid ep=%p or ep0\n", __func__, _ep); |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1358 | return -EINVAL; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1359 | } |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1360 | return net2280_set_halt_and_wedge(_ep, 1, 1); |
| 1361 | } |
| 1362 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1363 | static int net2280_fifo_status(struct usb_ep *_ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | { |
| 1365 | struct net2280_ep *ep; |
| 1366 | u32 avail; |
| 1367 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1368 | ep = container_of(_ep, struct net2280_ep, ep); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1369 | if (!_ep || (!ep->desc && ep->num != 0)) { |
| 1370 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | return -ENODEV; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1372 | } |
| 1373 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { |
| 1374 | dev_err(&ep->dev->pdev->dev, |
| 1375 | "%s: Invalid driver=%p or speed=%d\n", |
| 1376 | __func__, ep->dev->driver, ep->dev->gadget.speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | return -ESHUTDOWN; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1380 | avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1381 | if (avail > ep->fifo_size) { |
| 1382 | dev_err(&ep->dev->pdev->dev, "%s: Fifo overflow\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | return -EOVERFLOW; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | if (ep->is_in) |
| 1386 | avail = ep->fifo_size - avail; |
| 1387 | return avail; |
| 1388 | } |
| 1389 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1390 | static void net2280_fifo_flush(struct usb_ep *_ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | { |
| 1392 | struct net2280_ep *ep; |
| 1393 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1394 | ep = container_of(_ep, struct net2280_ep, ep); |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1395 | if (!_ep || (!ep->desc && ep->num != 0)) { |
| 1396 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | return; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1398 | } |
| 1399 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { |
| 1400 | dev_err(&ep->dev->pdev->dev, |
| 1401 | "%s: Invalid driver=%p or speed=%d\n", |
| 1402 | __func__, ep->dev->driver, ep->dev->gadget.speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | return; |
Mian Yousaf Kaukab | 9ceafcc | 2015-02-02 10:55:25 +0100 | [diff] [blame] | 1404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1406 | writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1407 | (void) readl(&ep->regs->ep_rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 1410 | static const struct usb_ep_ops net2280_ep_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | .enable = net2280_enable, |
| 1412 | .disable = net2280_disable, |
| 1413 | |
| 1414 | .alloc_request = net2280_alloc_request, |
| 1415 | .free_request = net2280_free_request, |
| 1416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | .queue = net2280_queue, |
| 1418 | .dequeue = net2280_dequeue, |
| 1419 | |
| 1420 | .set_halt = net2280_set_halt, |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 1421 | .set_wedge = net2280_set_wedge, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | .fifo_status = net2280_fifo_status, |
| 1423 | .fifo_flush = net2280_fifo_flush, |
| 1424 | }; |
| 1425 | |
| 1426 | /*-------------------------------------------------------------------------*/ |
| 1427 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1428 | static int net2280_get_frame(struct usb_gadget *_gadget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | { |
| 1430 | struct net2280 *dev; |
| 1431 | unsigned long flags; |
| 1432 | u16 retval; |
| 1433 | |
| 1434 | if (!_gadget) |
| 1435 | return -ENODEV; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1436 | dev = container_of(_gadget, struct net2280, gadget); |
| 1437 | spin_lock_irqsave(&dev->lock, flags); |
| 1438 | retval = get_idx_reg(dev->regs, REG_FRAME) & 0x03ff; |
| 1439 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | return retval; |
| 1441 | } |
| 1442 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1443 | static int net2280_wakeup(struct usb_gadget *_gadget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
| 1445 | struct net2280 *dev; |
| 1446 | u32 tmp; |
| 1447 | unsigned long flags; |
| 1448 | |
| 1449 | if (!_gadget) |
| 1450 | return 0; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1451 | dev = container_of(_gadget, struct net2280, gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1453 | spin_lock_irqsave(&dev->lock, flags); |
| 1454 | tmp = readl(&dev->usb->usbctl); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1455 | if (tmp & BIT(DEVICE_REMOTE_WAKEUP_ENABLE)) |
| 1456 | writel(BIT(GENERATE_RESUME), &dev->usb->usbstat); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1457 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
| 1459 | /* pci writes may still be posted */ |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1463 | static int net2280_set_selfpowered(struct usb_gadget *_gadget, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | { |
| 1465 | struct net2280 *dev; |
| 1466 | u32 tmp; |
| 1467 | unsigned long flags; |
| 1468 | |
| 1469 | if (!_gadget) |
| 1470 | return 0; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1471 | dev = container_of(_gadget, struct net2280, gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1473 | spin_lock_irqsave(&dev->lock, flags); |
| 1474 | tmp = readl(&dev->usb->usbctl); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1475 | if (value) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1476 | tmp |= BIT(SELF_POWERED_STATUS); |
Peter Chen | c8678d9 | 2015-01-28 16:32:35 +0800 | [diff] [blame] | 1477 | _gadget->is_selfpowered = 1; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1478 | } else { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1479 | tmp &= ~BIT(SELF_POWERED_STATUS); |
Peter Chen | c8678d9 | 2015-01-28 16:32:35 +0800 | [diff] [blame] | 1480 | _gadget->is_selfpowered = 0; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1481 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1482 | writel(tmp, &dev->usb->usbctl); |
| 1483 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
| 1485 | return 0; |
| 1486 | } |
| 1487 | |
| 1488 | static int net2280_pullup(struct usb_gadget *_gadget, int is_on) |
| 1489 | { |
| 1490 | struct net2280 *dev; |
| 1491 | u32 tmp; |
| 1492 | unsigned long flags; |
| 1493 | |
| 1494 | if (!_gadget) |
| 1495 | return -ENODEV; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1496 | dev = container_of(_gadget, struct net2280, gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1498 | spin_lock_irqsave(&dev->lock, flags); |
| 1499 | tmp = readl(&dev->usb->usbctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | dev->softconnect = (is_on != 0); |
Mian Yousaf Kaukab | 11bece5 | 2015-05-16 22:33:39 +0200 | [diff] [blame] | 1501 | if (is_on) { |
| 1502 | ep0_start(dev); |
| 1503 | writel(tmp | BIT(USB_DETECT_ENABLE), &dev->usb->usbctl); |
| 1504 | } else { |
| 1505 | writel(tmp & ~BIT(USB_DETECT_ENABLE), &dev->usb->usbctl); |
| 1506 | stop_activity(dev, dev->driver); |
| 1507 | } |
| 1508 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1509 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
Felipe Balbi | 4cf5e00 | 2011-10-10 10:37:17 +0300 | [diff] [blame] | 1514 | static int net2280_start(struct usb_gadget *_gadget, |
| 1515 | struct usb_gadget_driver *driver); |
Felipe Balbi | 22835b8 | 2014-10-17 12:05:12 -0500 | [diff] [blame] | 1516 | static int net2280_stop(struct usb_gadget *_gadget); |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | static const struct usb_gadget_ops net2280_ops = { |
| 1519 | .get_frame = net2280_get_frame, |
| 1520 | .wakeup = net2280_wakeup, |
| 1521 | .set_selfpowered = net2280_set_selfpowered, |
| 1522 | .pullup = net2280_pullup, |
Felipe Balbi | 4cf5e00 | 2011-10-10 10:37:17 +0300 | [diff] [blame] | 1523 | .udc_start = net2280_start, |
| 1524 | .udc_stop = net2280_stop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | }; |
| 1526 | |
| 1527 | /*-------------------------------------------------------------------------*/ |
| 1528 | |
Ricardo Ribalda Delgado | b99b406 | 2014-07-04 11:27:03 +0200 | [diff] [blame] | 1529 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | |
| 1531 | /* FIXME move these into procfs, and use seq_file. |
| 1532 | * Sysfs _still_ doesn't behave for arbitrarily sized files, |
| 1533 | * and also doesn't help products using this with 2.4 kernels. |
| 1534 | */ |
| 1535 | |
| 1536 | /* "function" sysfs attribute */ |
Greg Kroah-Hartman | ce26bd2 | 2013-08-23 16:34:43 -0700 | [diff] [blame] | 1537 | static ssize_t function_show(struct device *_dev, struct device_attribute *attr, |
| 1538 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1540 | struct net2280 *dev = dev_get_drvdata(_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1542 | if (!dev->driver || !dev->driver->function || |
| 1543 | strlen(dev->driver->function) > PAGE_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | return 0; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1545 | return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | } |
Greg Kroah-Hartman | ce26bd2 | 2013-08-23 16:34:43 -0700 | [diff] [blame] | 1547 | static DEVICE_ATTR_RO(function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
Greg Kroah-Hartman | ce26bd2 | 2013-08-23 16:34:43 -0700 | [diff] [blame] | 1549 | static ssize_t registers_show(struct device *_dev, |
| 1550 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | { |
| 1552 | struct net2280 *dev; |
| 1553 | char *next; |
| 1554 | unsigned size, t; |
| 1555 | unsigned long flags; |
| 1556 | int i; |
| 1557 | u32 t1, t2; |
Andrew Morton | 30e6959 | 2005-06-26 17:18:46 -0700 | [diff] [blame] | 1558 | const char *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1560 | dev = dev_get_drvdata(_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | next = buf; |
| 1562 | size = PAGE_SIZE; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1563 | spin_lock_irqsave(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | |
| 1565 | if (dev->driver) |
| 1566 | s = dev->driver->driver.name; |
| 1567 | else |
| 1568 | s = "(none)"; |
| 1569 | |
| 1570 | /* Main Control Registers */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1571 | t = scnprintf(next, size, "%s version " DRIVER_VERSION |
Ricardo Ribalda Delgado | d588ff5 | 2014-11-28 14:50:49 +0100 | [diff] [blame] | 1572 | ", chiprev %04x\n\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | "devinit %03x fifoctl %08x gadget '%s'\n" |
| 1574 | "pci irqenb0 %02x irqenb1 %08x " |
| 1575 | "irqstat0 %04x irqstat1 %08x\n", |
| 1576 | driver_name, dev->chiprev, |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1577 | readl(&dev->regs->devinit), |
| 1578 | readl(&dev->regs->fifoctl), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | s, |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1580 | readl(&dev->regs->pciirqenb0), |
| 1581 | readl(&dev->regs->pciirqenb1), |
| 1582 | readl(&dev->regs->irqstat0), |
| 1583 | readl(&dev->regs->irqstat1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | size -= t; |
| 1585 | next += t; |
| 1586 | |
| 1587 | /* USB Control Registers */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1588 | t1 = readl(&dev->usb->usbctl); |
| 1589 | t2 = readl(&dev->usb->usbstat); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1590 | if (t1 & BIT(VBUS_PIN)) { |
| 1591 | if (t2 & BIT(HIGH_SPEED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | s = "high speed"; |
| 1593 | else if (dev->gadget.speed == USB_SPEED_UNKNOWN) |
| 1594 | s = "powered"; |
| 1595 | else |
| 1596 | s = "full speed"; |
| 1597 | /* full speed bit (6) not working?? */ |
| 1598 | } else |
| 1599 | s = "not attached"; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1600 | t = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | "stdrsp %08x usbctl %08x usbstat %08x " |
| 1602 | "addr 0x%02x (%s)\n", |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1603 | readl(&dev->usb->stdrsp), t1, t2, |
| 1604 | readl(&dev->usb->ouraddr), s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | size -= t; |
| 1606 | next += t; |
| 1607 | |
| 1608 | /* PCI Master Control Registers */ |
| 1609 | |
| 1610 | /* DMA Control Registers */ |
| 1611 | |
| 1612 | /* Configurable EP Control Registers */ |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1613 | for (i = 0; i < dev->n_ep; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | struct net2280_ep *ep; |
| 1615 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1616 | ep = &dev->ep[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | if (i && !ep->desc) |
| 1618 | continue; |
| 1619 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1620 | t1 = readl(&ep->cfg->ep_cfg); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1621 | t2 = readl(&ep->regs->ep_rsp) & 0xff; |
| 1622 | t = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s" |
| 1624 | "irqenb %02x\n", |
| 1625 | ep->ep.name, t1, t2, |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1626 | (t2 & BIT(CLEAR_NAK_OUT_PACKETS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | ? "NAK " : "", |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1628 | (t2 & BIT(CLEAR_EP_HIDE_STATUS_PHASE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | ? "hide " : "", |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1630 | (t2 & BIT(CLEAR_EP_FORCE_CRC_ERROR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | ? "CRC " : "", |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1632 | (t2 & BIT(CLEAR_INTERRUPT_MODE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | ? "interrupt " : "", |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1634 | (t2 & BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | ? "status " : "", |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1636 | (t2 & BIT(CLEAR_NAK_OUT_PACKETS_MODE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | ? "NAKmode " : "", |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1638 | (t2 & BIT(CLEAR_ENDPOINT_TOGGLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | ? "DATA1 " : "DATA0 ", |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1640 | (t2 & BIT(CLEAR_ENDPOINT_HALT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | ? "HALT " : "", |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1642 | readl(&ep->regs->ep_irqenb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | size -= t; |
| 1644 | next += t; |
| 1645 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1646 | t = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | "\tstat %08x avail %04x " |
| 1648 | "(ep%d%s-%s)%s\n", |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1649 | readl(&ep->regs->ep_stat), |
| 1650 | readl(&ep->regs->ep_avail), |
| 1651 | t1 & 0x0f, DIR_STRING(t1), |
| 1652 | type_string(t1 >> 8), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | ep->stopped ? "*" : ""); |
| 1654 | size -= t; |
| 1655 | next += t; |
| 1656 | |
| 1657 | if (!ep->dma) |
| 1658 | continue; |
| 1659 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1660 | t = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | " dma\tctl %08x stat %08x count %08x\n" |
| 1662 | "\taddr %08x desc %08x\n", |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1663 | readl(&ep->dma->dmactl), |
| 1664 | readl(&ep->dma->dmastat), |
| 1665 | readl(&ep->dma->dmacount), |
| 1666 | readl(&ep->dma->dmaaddr), |
| 1667 | readl(&ep->dma->dmadesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | size -= t; |
| 1669 | next += t; |
| 1670 | |
| 1671 | } |
| 1672 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1673 | /* Indexed Registers (none yet) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
| 1675 | /* Statistics */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1676 | t = scnprintf(next, size, "\nirqs: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | size -= t; |
| 1678 | next += t; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1679 | for (i = 0; i < dev->n_ep; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | struct net2280_ep *ep; |
| 1681 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1682 | ep = &dev->ep[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | if (i && !ep->irqs) |
| 1684 | continue; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1685 | t = scnprintf(next, size, " %s/%lu", ep->ep.name, ep->irqs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | size -= t; |
| 1687 | next += t; |
| 1688 | |
| 1689 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1690 | t = scnprintf(next, size, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | size -= t; |
| 1692 | next += t; |
| 1693 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1694 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
| 1696 | return PAGE_SIZE - size; |
| 1697 | } |
Greg Kroah-Hartman | ce26bd2 | 2013-08-23 16:34:43 -0700 | [diff] [blame] | 1698 | static DEVICE_ATTR_RO(registers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | |
Greg Kroah-Hartman | ce26bd2 | 2013-08-23 16:34:43 -0700 | [diff] [blame] | 1700 | static ssize_t queues_show(struct device *_dev, struct device_attribute *attr, |
| 1701 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | { |
| 1703 | struct net2280 *dev; |
| 1704 | char *next; |
| 1705 | unsigned size; |
| 1706 | unsigned long flags; |
| 1707 | int i; |
| 1708 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1709 | dev = dev_get_drvdata(_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | next = buf; |
| 1711 | size = PAGE_SIZE; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1712 | spin_lock_irqsave(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1714 | for (i = 0; i < dev->n_ep; i++) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1715 | struct net2280_ep *ep = &dev->ep[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | struct net2280_request *req; |
| 1717 | int t; |
| 1718 | |
| 1719 | if (i != 0) { |
| 1720 | const struct usb_endpoint_descriptor *d; |
| 1721 | |
| 1722 | d = ep->desc; |
| 1723 | if (!d) |
| 1724 | continue; |
| 1725 | t = d->bEndpointAddress; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1726 | t = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | "\n%s (ep%d%s-%s) max %04x %s fifo %d\n", |
| 1728 | ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK, |
| 1729 | (t & USB_DIR_IN) ? "in" : "out", |
Ricardo Ribalda Delgado | a27f37a | 2014-05-20 18:30:08 +0200 | [diff] [blame] | 1730 | type_string(d->bmAttributes), |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1731 | usb_endpoint_maxp(d) & 0x1fff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | ep->dma ? "dma" : "pio", ep->fifo_size |
| 1733 | ); |
| 1734 | } else /* ep0 should only have one transfer queued */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1735 | t = scnprintf(next, size, "ep0 max 64 pio %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | ep->is_in ? "in" : "out"); |
| 1737 | if (t <= 0 || t > size) |
| 1738 | goto done; |
| 1739 | size -= t; |
| 1740 | next += t; |
| 1741 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1742 | if (list_empty(&ep->queue)) { |
| 1743 | t = scnprintf(next, size, "\t(nothing queued)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | if (t <= 0 || t > size) |
| 1745 | goto done; |
| 1746 | size -= t; |
| 1747 | next += t; |
| 1748 | continue; |
| 1749 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1750 | list_for_each_entry(req, &ep->queue, queue) { |
| 1751 | if (ep->dma && req->td_dma == readl(&ep->dma->dmadesc)) |
| 1752 | t = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | "\treq %p len %d/%d " |
| 1754 | "buf %p (dmacount %08x)\n", |
| 1755 | &req->req, req->req.actual, |
| 1756 | req->req.length, req->req.buf, |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1757 | readl(&ep->dma->dmacount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | else |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1759 | t = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | "\treq %p len %d/%d buf %p\n", |
| 1761 | &req->req, req->req.actual, |
| 1762 | req->req.length, req->req.buf); |
| 1763 | if (t <= 0 || t > size) |
| 1764 | goto done; |
| 1765 | size -= t; |
| 1766 | next += t; |
| 1767 | |
| 1768 | if (ep->dma) { |
| 1769 | struct net2280_dma *td; |
| 1770 | |
| 1771 | td = req->td; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1772 | t = scnprintf(next, size, "\t td %08x " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | " count %08x buf %08x desc %08x\n", |
| 1774 | (u32) req->td_dma, |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1775 | le32_to_cpu(td->dmacount), |
| 1776 | le32_to_cpu(td->dmaaddr), |
| 1777 | le32_to_cpu(td->dmadesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | if (t <= 0 || t > size) |
| 1779 | goto done; |
| 1780 | size -= t; |
| 1781 | next += t; |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | done: |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1787 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | return PAGE_SIZE - size; |
| 1789 | } |
Greg Kroah-Hartman | ce26bd2 | 2013-08-23 16:34:43 -0700 | [diff] [blame] | 1790 | static DEVICE_ATTR_RO(queues); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
| 1792 | |
| 1793 | #else |
| 1794 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1795 | #define device_create_file(a, b) (0) |
| 1796 | #define device_remove_file(a, b) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
| 1798 | #endif |
| 1799 | |
| 1800 | /*-------------------------------------------------------------------------*/ |
| 1801 | |
| 1802 | /* another driver-specific mode might be a request type doing dma |
| 1803 | * to/from another device fifo instead of to/from memory. |
| 1804 | */ |
| 1805 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1806 | static void set_fifo_mode(struct net2280 *dev, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
| 1808 | /* keeping high bits preserves BAR2 */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1809 | writel((0xffff << PCI_BASE2_RANGE) | mode, &dev->regs->fifoctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
| 1811 | /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1812 | INIT_LIST_HEAD(&dev->gadget.ep_list); |
| 1813 | list_add_tail(&dev->ep[1].ep.ep_list, &dev->gadget.ep_list); |
| 1814 | list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | switch (mode) { |
| 1816 | case 0: |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1817 | list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list); |
| 1818 | list_add_tail(&dev->ep[4].ep.ep_list, &dev->gadget.ep_list); |
| 1819 | dev->ep[1].fifo_size = dev->ep[2].fifo_size = 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | break; |
| 1821 | case 1: |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1822 | dev->ep[1].fifo_size = dev->ep[2].fifo_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | break; |
| 1824 | case 2: |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1825 | list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list); |
| 1826 | dev->ep[1].fifo_size = 2048; |
| 1827 | dev->ep[2].fifo_size = 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | break; |
| 1829 | } |
| 1830 | /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1831 | list_add_tail(&dev->ep[5].ep.ep_list, &dev->gadget.ep_list); |
| 1832 | list_add_tail(&dev->ep[6].ep.ep_list, &dev->gadget.ep_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1835 | static void defect7374_disable_data_eps(struct net2280 *dev) |
| 1836 | { |
| 1837 | /* |
| 1838 | * For Defect 7374, disable data EPs (and more): |
| 1839 | * - This phase undoes the earlier phase of the Defect 7374 workaround, |
| 1840 | * returing ep regs back to normal. |
| 1841 | */ |
| 1842 | struct net2280_ep *ep; |
| 1843 | int i; |
| 1844 | unsigned char ep_sel; |
| 1845 | u32 tmp_reg; |
| 1846 | |
| 1847 | for (i = 1; i < 5; i++) { |
| 1848 | ep = &dev->ep[i]; |
| 1849 | writel(0, &ep->cfg->ep_cfg); |
| 1850 | } |
| 1851 | |
| 1852 | /* CSROUT, CSRIN, PCIOUT, PCIIN, STATIN, RCIN */ |
| 1853 | for (i = 0; i < 6; i++) |
| 1854 | writel(0, &dev->dep[i].dep_cfg); |
| 1855 | |
| 1856 | for (ep_sel = 0; ep_sel <= 21; ep_sel++) { |
| 1857 | /* Select an endpoint for subsequent operations: */ |
| 1858 | tmp_reg = readl(&dev->plregs->pl_ep_ctrl); |
| 1859 | writel(((tmp_reg & ~0x1f) | ep_sel), &dev->plregs->pl_ep_ctrl); |
| 1860 | |
| 1861 | if (ep_sel < 2 || (ep_sel > 9 && ep_sel < 14) || |
| 1862 | ep_sel == 18 || ep_sel == 20) |
| 1863 | continue; |
| 1864 | |
| 1865 | /* Change settings on some selected endpoints */ |
| 1866 | tmp_reg = readl(&dev->plregs->pl_ep_cfg_4); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1867 | tmp_reg &= ~BIT(NON_CTRL_IN_TOLERATE_BAD_DIR); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1868 | writel(tmp_reg, &dev->plregs->pl_ep_cfg_4); |
| 1869 | tmp_reg = readl(&dev->plregs->pl_ep_ctrl); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1870 | tmp_reg |= BIT(EP_INITIALIZED); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1871 | writel(tmp_reg, &dev->plregs->pl_ep_ctrl); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | static void defect7374_enable_data_eps_zero(struct net2280 *dev) |
| 1876 | { |
| 1877 | u32 tmp = 0, tmp_reg; |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1878 | u32 scratch; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1879 | int i; |
| 1880 | unsigned char ep_sel; |
| 1881 | |
| 1882 | scratch = get_idx_reg(dev->regs, SCRATCH); |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1883 | |
| 1884 | WARN_ON((scratch & (0xf << DEFECT7374_FSM_FIELD)) |
| 1885 | == DEFECT7374_FSM_SS_CONTROL_READ); |
| 1886 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1887 | scratch &= ~(0xf << DEFECT7374_FSM_FIELD); |
| 1888 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1889 | ep_warn(dev, "Operate Defect 7374 workaround soft this time"); |
| 1890 | ep_warn(dev, "It will operate on cold-reboot and SS connect"); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1891 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1892 | /*GPEPs:*/ |
| 1893 | tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_DIRECTION) | |
| 1894 | (2 << OUT_ENDPOINT_TYPE) | (2 << IN_ENDPOINT_TYPE) | |
| 1895 | ((dev->enhanced_mode) ? |
Mian Yousaf Kaukab | 25d40ee | 2015-05-16 22:33:30 +0200 | [diff] [blame] | 1896 | BIT(OUT_ENDPOINT_ENABLE) | BIT(IN_ENDPOINT_ENABLE) : |
| 1897 | BIT(ENDPOINT_ENABLE))); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1898 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1899 | for (i = 1; i < 5; i++) |
| 1900 | writel(tmp, &dev->ep[i].cfg->ep_cfg); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1901 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1902 | /* CSRIN, PCIIN, STATIN, RCIN*/ |
| 1903 | tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_ENABLE)); |
| 1904 | writel(tmp, &dev->dep[1].dep_cfg); |
| 1905 | writel(tmp, &dev->dep[3].dep_cfg); |
| 1906 | writel(tmp, &dev->dep[4].dep_cfg); |
| 1907 | writel(tmp, &dev->dep[5].dep_cfg); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1908 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1909 | /*Implemented for development and debug. |
| 1910 | * Can be refined/tuned later.*/ |
| 1911 | for (ep_sel = 0; ep_sel <= 21; ep_sel++) { |
| 1912 | /* Select an endpoint for subsequent operations: */ |
| 1913 | tmp_reg = readl(&dev->plregs->pl_ep_ctrl); |
| 1914 | writel(((tmp_reg & ~0x1f) | ep_sel), |
| 1915 | &dev->plregs->pl_ep_ctrl); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1916 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1917 | if (ep_sel == 1) { |
| 1918 | tmp = |
| 1919 | (readl(&dev->plregs->pl_ep_ctrl) | |
| 1920 | BIT(CLEAR_ACK_ERROR_CODE) | 0); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1921 | writel(tmp, &dev->plregs->pl_ep_ctrl); |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1922 | continue; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1923 | } |
| 1924 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1925 | if (ep_sel == 0 || (ep_sel > 9 && ep_sel < 14) || |
| 1926 | ep_sel == 18 || ep_sel == 20) |
| 1927 | continue; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1928 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1929 | tmp = (readl(&dev->plregs->pl_ep_cfg_4) | |
| 1930 | BIT(NON_CTRL_IN_TOLERATE_BAD_DIR) | 0); |
| 1931 | writel(tmp, &dev->plregs->pl_ep_cfg_4); |
| 1932 | |
| 1933 | tmp = readl(&dev->plregs->pl_ep_ctrl) & |
| 1934 | ~BIT(EP_INITIALIZED); |
| 1935 | writel(tmp, &dev->plregs->pl_ep_ctrl); |
| 1936 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1937 | } |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 1938 | |
| 1939 | /* Set FSM to focus on the first Control Read: |
| 1940 | * - Tip: Connection speed is known upon the first |
| 1941 | * setup request.*/ |
| 1942 | scratch |= DEFECT7374_FSM_WAITING_FOR_CONTROL_READ; |
| 1943 | set_idx_reg(dev->regs, SCRATCH, scratch); |
| 1944 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1945 | } |
| 1946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | /* keeping it simple: |
| 1948 | * - one bus driver, initted first; |
| 1949 | * - one function driver, initted second |
| 1950 | * |
| 1951 | * most of the work to support multiple net2280 controllers would |
| 1952 | * be to associate this gadget driver (yes?) with all of them, or |
| 1953 | * perhaps to bind specific drivers to specific devices. |
| 1954 | */ |
| 1955 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1956 | static void usb_reset_228x(struct net2280 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | { |
| 1958 | u32 tmp; |
| 1959 | |
| 1960 | dev->gadget.speed = USB_SPEED_UNKNOWN; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1961 | (void) readl(&dev->usb->usbctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1963 | net2280_led_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | |
| 1965 | /* disable automatic responses, and irqs */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1966 | writel(0, &dev->usb->stdrsp); |
| 1967 | writel(0, &dev->regs->pciirqenb0); |
| 1968 | writel(0, &dev->regs->pciirqenb1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | |
| 1970 | /* clear old dma and irq state */ |
| 1971 | for (tmp = 0; tmp < 4; tmp++) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1972 | struct net2280_ep *ep = &dev->ep[tmp + 1]; |
Greg Kroah-Hartman | 357d596e | 2014-05-28 11:35:41 -0700 | [diff] [blame] | 1973 | if (ep->dma) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1974 | abort_dma(ep); |
Greg Kroah-Hartman | 357d596e | 2014-05-28 11:35:41 -0700 | [diff] [blame] | 1975 | } |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1976 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1977 | writel(~0, &dev->regs->irqstat0), |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1978 | writel(~(u32)BIT(SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
| 1980 | /* reset, and enable pci */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 1981 | tmp = readl(&dev->regs->devinit) | |
| 1982 | BIT(PCI_ENABLE) | |
| 1983 | BIT(FIFO_SOFT_RESET) | |
| 1984 | BIT(USB_SOFT_RESET) | |
| 1985 | BIT(M8051_RESET); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1986 | writel(tmp, &dev->regs->devinit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | |
| 1988 | /* standard fifo and endpoint allocations */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 1989 | set_fifo_mode(dev, (fifo_mode <= 2) ? fifo_mode : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1992 | static void usb_reset_338x(struct net2280 *dev) |
| 1993 | { |
| 1994 | u32 tmp; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 1995 | |
| 1996 | dev->gadget.speed = USB_SPEED_UNKNOWN; |
| 1997 | (void)readl(&dev->usb->usbctl); |
| 1998 | |
| 1999 | net2280_led_init(dev); |
| 2000 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 2001 | if (dev->bug7734_patched) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2002 | /* disable automatic responses, and irqs */ |
| 2003 | writel(0, &dev->usb->stdrsp); |
| 2004 | writel(0, &dev->regs->pciirqenb0); |
| 2005 | writel(0, &dev->regs->pciirqenb1); |
| 2006 | } |
| 2007 | |
| 2008 | /* clear old dma and irq state */ |
| 2009 | for (tmp = 0; tmp < 4; tmp++) { |
| 2010 | struct net2280_ep *ep = &dev->ep[tmp + 1]; |
Mian Yousaf Kaukab | 3fc0a7c | 2015-05-16 22:33:32 +0200 | [diff] [blame] | 2011 | struct net2280_dma_regs __iomem *dma; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2012 | |
Mian Yousaf Kaukab | 3fc0a7c | 2015-05-16 22:33:32 +0200 | [diff] [blame] | 2013 | if (ep->dma) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2014 | abort_dma(ep); |
Mian Yousaf Kaukab | 3fc0a7c | 2015-05-16 22:33:32 +0200 | [diff] [blame] | 2015 | } else { |
| 2016 | dma = &dev->dma[tmp]; |
| 2017 | writel(BIT(DMA_ABORT), &dma->dmastat); |
| 2018 | writel(0, &dma->dmactl); |
| 2019 | } |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | writel(~0, &dev->regs->irqstat0), writel(~0, &dev->regs->irqstat1); |
| 2023 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 2024 | if (dev->bug7734_patched) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2025 | /* reset, and enable pci */ |
| 2026 | tmp = readl(&dev->regs->devinit) | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2027 | BIT(PCI_ENABLE) | |
| 2028 | BIT(FIFO_SOFT_RESET) | |
| 2029 | BIT(USB_SOFT_RESET) | |
| 2030 | BIT(M8051_RESET); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2031 | |
| 2032 | writel(tmp, &dev->regs->devinit); |
| 2033 | } |
| 2034 | |
| 2035 | /* always ep-{1,2,3,4} ... maybe not ep-3 or ep-4 */ |
| 2036 | INIT_LIST_HEAD(&dev->gadget.ep_list); |
| 2037 | |
| 2038 | for (tmp = 1; tmp < dev->n_ep; tmp++) |
| 2039 | list_add_tail(&dev->ep[tmp].ep.ep_list, &dev->gadget.ep_list); |
| 2040 | |
| 2041 | } |
| 2042 | |
| 2043 | static void usb_reset(struct net2280 *dev) |
| 2044 | { |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 2045 | if (dev->quirks & PLX_LEGACY) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2046 | return usb_reset_228x(dev); |
| 2047 | return usb_reset_338x(dev); |
| 2048 | } |
| 2049 | |
| 2050 | static void usb_reinit_228x(struct net2280 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | { |
| 2052 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | |
| 2054 | /* basic endpoint init */ |
| 2055 | for (tmp = 0; tmp < 7; tmp++) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2056 | struct net2280_ep *ep = &dev->ep[tmp]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2058 | ep->ep.name = ep_name[tmp]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | ep->dev = dev; |
| 2060 | ep->num = tmp; |
| 2061 | |
| 2062 | if (tmp > 0 && tmp <= 4) { |
| 2063 | ep->fifo_size = 1024; |
Ricardo Ribalda Delgado | d588ff5 | 2014-11-28 14:50:49 +0100 | [diff] [blame] | 2064 | ep->dma = &dev->dma[tmp - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | } else |
| 2066 | ep->fifo_size = 64; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2067 | ep->regs = &dev->epregs[tmp]; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2068 | ep->cfg = &dev->epregs[tmp]; |
| 2069 | ep_reset_228x(dev->regs, ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2071 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64); |
| 2072 | usb_ep_set_maxpacket_limit(&dev->ep[5].ep, 64); |
| 2073 | usb_ep_set_maxpacket_limit(&dev->ep[6].ep, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2075 | dev->gadget.ep0 = &dev->ep[0].ep; |
| 2076 | dev->ep[0].stopped = 0; |
| 2077 | INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | |
| 2079 | /* we want to prevent lowlevel/insecure access from the USB host, |
| 2080 | * but erratum 0119 means this enable bit is ignored |
| 2081 | */ |
| 2082 | for (tmp = 0; tmp < 5; tmp++) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2083 | writel(EP_DONTUSE, &dev->dep[tmp].dep_cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2086 | static void usb_reinit_338x(struct net2280 *dev) |
| 2087 | { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2088 | int i; |
| 2089 | u32 tmp, val; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2090 | static const u32 ne[9] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 }; |
| 2091 | static const u32 ep_reg_addr[9] = { 0x00, 0xC0, 0x00, 0xC0, 0x00, |
| 2092 | 0x00, 0xC0, 0x00, 0xC0 }; |
| 2093 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2094 | /* basic endpoint init */ |
| 2095 | for (i = 0; i < dev->n_ep; i++) { |
| 2096 | struct net2280_ep *ep = &dev->ep[i]; |
| 2097 | |
Mian Yousaf Kaukab | a285f40 | 2015-02-02 10:55:23 +0100 | [diff] [blame] | 2098 | ep->ep.name = dev->enhanced_mode ? ep_name_adv[i] : ep_name[i]; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2099 | ep->dev = dev; |
| 2100 | ep->num = i; |
| 2101 | |
Ricardo Ribalda Delgado | d588ff5 | 2014-11-28 14:50:49 +0100 | [diff] [blame] | 2102 | if (i > 0 && i <= 4) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2103 | ep->dma = &dev->dma[i - 1]; |
| 2104 | |
| 2105 | if (dev->enhanced_mode) { |
| 2106 | ep->cfg = &dev->epregs[ne[i]]; |
Mian Yousaf Kaukab | c65c4f0 | 2015-05-16 22:33:36 +0200 | [diff] [blame] | 2107 | /* |
| 2108 | * Set USB endpoint number, hardware allows same number |
| 2109 | * in both directions. |
| 2110 | */ |
| 2111 | if (i > 0 && i < 5) |
| 2112 | writel(ne[i], &ep->cfg->ep_cfg); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2113 | ep->regs = (struct net2280_ep_regs __iomem *) |
Felipe Balbi | c43e97b | 2014-07-16 12:20:25 -0500 | [diff] [blame] | 2114 | (((void __iomem *)&dev->epregs[ne[i]]) + |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2115 | ep_reg_addr[i]); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2116 | } else { |
| 2117 | ep->cfg = &dev->epregs[i]; |
| 2118 | ep->regs = &dev->epregs[i]; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | ep->fifo_size = (i != 0) ? 2048 : 512; |
| 2122 | |
| 2123 | ep_reset_338x(dev->regs, ep); |
| 2124 | } |
| 2125 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 512); |
| 2126 | |
| 2127 | dev->gadget.ep0 = &dev->ep[0].ep; |
| 2128 | dev->ep[0].stopped = 0; |
| 2129 | |
| 2130 | /* Link layer set up */ |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 2131 | if (dev->bug7734_patched) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2132 | tmp = readl(&dev->usb_ext->usbctl2) & |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2133 | ~(BIT(U1_ENABLE) | BIT(U2_ENABLE) | BIT(LTM_ENABLE)); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2134 | writel(tmp, &dev->usb_ext->usbctl2); |
| 2135 | } |
| 2136 | |
| 2137 | /* Hardware Defect and Workaround */ |
| 2138 | val = readl(&dev->ll_lfps_regs->ll_lfps_5); |
| 2139 | val &= ~(0xf << TIMER_LFPS_6US); |
| 2140 | val |= 0x5 << TIMER_LFPS_6US; |
| 2141 | writel(val, &dev->ll_lfps_regs->ll_lfps_5); |
| 2142 | |
| 2143 | val = readl(&dev->ll_lfps_regs->ll_lfps_6); |
| 2144 | val &= ~(0xffff << TIMER_LFPS_80US); |
| 2145 | val |= 0x0100 << TIMER_LFPS_80US; |
| 2146 | writel(val, &dev->ll_lfps_regs->ll_lfps_6); |
| 2147 | |
| 2148 | /* |
| 2149 | * AA_AB Errata. Issue 4. Workaround for SuperSpeed USB |
| 2150 | * Hot Reset Exit Handshake may Fail in Specific Case using |
| 2151 | * Default Register Settings. Workaround for Enumeration test. |
| 2152 | */ |
| 2153 | val = readl(&dev->ll_tsn_regs->ll_tsn_counters_2); |
| 2154 | val &= ~(0x1f << HOT_TX_NORESET_TS2); |
| 2155 | val |= 0x10 << HOT_TX_NORESET_TS2; |
| 2156 | writel(val, &dev->ll_tsn_regs->ll_tsn_counters_2); |
| 2157 | |
| 2158 | val = readl(&dev->ll_tsn_regs->ll_tsn_counters_3); |
| 2159 | val &= ~(0x1f << HOT_RX_RESET_TS2); |
| 2160 | val |= 0x3 << HOT_RX_RESET_TS2; |
| 2161 | writel(val, &dev->ll_tsn_regs->ll_tsn_counters_3); |
| 2162 | |
| 2163 | /* |
| 2164 | * Set Recovery Idle to Recover bit: |
| 2165 | * - On SS connections, setting Recovery Idle to Recover Fmw improves |
| 2166 | * link robustness with various hosts and hubs. |
| 2167 | * - It is safe to set for all connection speeds; all chip revisions. |
| 2168 | * - R-M-W to leave other bits undisturbed. |
| 2169 | * - Reference PLX TT-7372 |
| 2170 | */ |
| 2171 | val = readl(&dev->ll_chicken_reg->ll_tsn_chicken_bit); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2172 | val |= BIT(RECOVERY_IDLE_TO_RECOVER_FMW); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2173 | writel(val, &dev->ll_chicken_reg->ll_tsn_chicken_bit); |
| 2174 | |
| 2175 | INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); |
| 2176 | |
| 2177 | /* disable dedicated endpoints */ |
| 2178 | writel(0x0D, &dev->dep[0].dep_cfg); |
| 2179 | writel(0x0D, &dev->dep[1].dep_cfg); |
| 2180 | writel(0x0E, &dev->dep[2].dep_cfg); |
| 2181 | writel(0x0E, &dev->dep[3].dep_cfg); |
| 2182 | writel(0x0F, &dev->dep[4].dep_cfg); |
| 2183 | writel(0x0C, &dev->dep[5].dep_cfg); |
| 2184 | } |
| 2185 | |
| 2186 | static void usb_reinit(struct net2280 *dev) |
| 2187 | { |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 2188 | if (dev->quirks & PLX_LEGACY) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2189 | return usb_reinit_228x(dev); |
| 2190 | return usb_reinit_338x(dev); |
| 2191 | } |
| 2192 | |
| 2193 | static void ep0_start_228x(struct net2280 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2195 | writel(BIT(CLEAR_EP_HIDE_STATUS_PHASE) | |
| 2196 | BIT(CLEAR_NAK_OUT_PACKETS) | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 2197 | BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE), |
| 2198 | &dev->epregs[0].ep_rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | |
| 2200 | /* |
| 2201 | * hardware optionally handles a bunch of standard requests |
| 2202 | * that the API hides from drivers anyway. have it do so. |
| 2203 | * endpoint status/features are handled in software, to |
| 2204 | * help pass tests for some dubious behavior. |
| 2205 | */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2206 | writel(BIT(SET_TEST_MODE) | |
| 2207 | BIT(SET_ADDRESS) | |
| 2208 | BIT(DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP) | |
| 2209 | BIT(GET_DEVICE_STATUS) | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 2210 | BIT(GET_INTERFACE_STATUS), |
| 2211 | &dev->usb->stdrsp); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2212 | writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) | |
| 2213 | BIT(SELF_POWERED_USB_DEVICE) | |
| 2214 | BIT(REMOTE_WAKEUP_SUPPORT) | |
| 2215 | (dev->softconnect << USB_DETECT_ENABLE) | |
| 2216 | BIT(SELF_POWERED_STATUS), |
| 2217 | &dev->usb->usbctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | |
| 2219 | /* enable irqs so we can see ep0 and general operation */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2220 | writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) | |
| 2221 | BIT(ENDPOINT_0_INTERRUPT_ENABLE), |
| 2222 | &dev->regs->pciirqenb0); |
| 2223 | writel(BIT(PCI_INTERRUPT_ENABLE) | |
| 2224 | BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE) | |
| 2225 | BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE) | |
| 2226 | BIT(PCI_RETRY_ABORT_INTERRUPT_ENABLE) | |
| 2227 | BIT(VBUS_INTERRUPT_ENABLE) | |
| 2228 | BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) | |
| 2229 | BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE), |
| 2230 | &dev->regs->pciirqenb1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | |
| 2232 | /* don't leave any writes posted */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2233 | (void) readl(&dev->usb->usbctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2236 | static void ep0_start_338x(struct net2280 *dev) |
| 2237 | { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2238 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 2239 | if (dev->bug7734_patched) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2240 | writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE) | |
| 2241 | BIT(SET_EP_HIDE_STATUS_PHASE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2242 | &dev->epregs[0].ep_rsp); |
| 2243 | |
| 2244 | /* |
| 2245 | * hardware optionally handles a bunch of standard requests |
| 2246 | * that the API hides from drivers anyway. have it do so. |
| 2247 | * endpoint status/features are handled in software, to |
| 2248 | * help pass tests for some dubious behavior. |
| 2249 | */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2250 | writel(BIT(SET_ISOCHRONOUS_DELAY) | |
| 2251 | BIT(SET_SEL) | |
| 2252 | BIT(SET_TEST_MODE) | |
| 2253 | BIT(SET_ADDRESS) | |
| 2254 | BIT(GET_INTERFACE_STATUS) | |
| 2255 | BIT(GET_DEVICE_STATUS), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2256 | &dev->usb->stdrsp); |
| 2257 | dev->wakeup_enable = 1; |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2258 | writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2259 | (dev->softconnect << USB_DETECT_ENABLE) | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2260 | BIT(DEVICE_REMOTE_WAKEUP_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2261 | &dev->usb->usbctl); |
| 2262 | |
| 2263 | /* enable irqs so we can see ep0 and general operation */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2264 | writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 2265 | BIT(ENDPOINT_0_INTERRUPT_ENABLE), |
| 2266 | &dev->regs->pciirqenb0); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2267 | writel(BIT(PCI_INTERRUPT_ENABLE) | |
| 2268 | BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) | |
| 2269 | BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE) | |
| 2270 | BIT(VBUS_INTERRUPT_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2271 | &dev->regs->pciirqenb1); |
| 2272 | |
| 2273 | /* don't leave any writes posted */ |
| 2274 | (void)readl(&dev->usb->usbctl); |
| 2275 | } |
| 2276 | |
| 2277 | static void ep0_start(struct net2280 *dev) |
| 2278 | { |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 2279 | if (dev->quirks & PLX_LEGACY) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2280 | return ep0_start_228x(dev); |
| 2281 | return ep0_start_338x(dev); |
| 2282 | } |
| 2283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | /* when a driver is successfully registered, it will receive |
| 2285 | * control requests including set_configuration(), which enables |
| 2286 | * non-control requests. then usb traffic follows until a |
| 2287 | * disconnect is reported. then a host may connect again, or |
| 2288 | * the driver might get unbound. |
| 2289 | */ |
Felipe Balbi | 4cf5e00 | 2011-10-10 10:37:17 +0300 | [diff] [blame] | 2290 | static int net2280_start(struct usb_gadget *_gadget, |
| 2291 | struct usb_gadget_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | { |
Felipe Balbi | 4cf5e00 | 2011-10-10 10:37:17 +0300 | [diff] [blame] | 2293 | struct net2280 *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | int retval; |
| 2295 | unsigned i; |
| 2296 | |
| 2297 | /* insist on high speed support from the driver, since |
| 2298 | * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) |
| 2299 | * "must not be used in normal operation" |
| 2300 | */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 2301 | if (!driver || driver->max_speed < USB_SPEED_HIGH || |
| 2302 | !driver->setup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | return -EINVAL; |
Felipe Balbi | 4cf5e00 | 2011-10-10 10:37:17 +0300 | [diff] [blame] | 2304 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2305 | dev = container_of(_gadget, struct net2280, gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2307 | for (i = 0; i < dev->n_ep; i++) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2308 | dev->ep[i].irqs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
| 2310 | /* hook up the driver ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | driver->driver.bus = NULL; |
| 2312 | dev->driver = driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2314 | retval = device_create_file(&dev->pdev->dev, &dev_attr_function); |
| 2315 | if (retval) |
| 2316 | goto err_unbind; |
| 2317 | retval = device_create_file(&dev->pdev->dev, &dev_attr_queues); |
| 2318 | if (retval) |
| 2319 | goto err_func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
Ricardo Ribalda Delgado | 7a74c48 | 2014-11-28 14:50:47 +0100 | [diff] [blame] | 2321 | /* enable host detection and ep0; and we're ready |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | * for set_configuration as well as eventual disconnect. |
| 2323 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2324 | net2280_led_active(dev, 1); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2325 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 2326 | if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2327 | defect7374_enable_data_eps_zero(dev); |
| 2328 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2329 | ep0_start(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | /* pci writes may still be posted */ |
| 2332 | return 0; |
Jeff Garzik | b3899da | 2006-10-11 21:50:24 -0400 | [diff] [blame] | 2333 | |
| 2334 | err_func: |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2335 | device_remove_file(&dev->pdev->dev, &dev_attr_function); |
Jeff Garzik | b3899da | 2006-10-11 21:50:24 -0400 | [diff] [blame] | 2336 | err_unbind: |
Jeff Garzik | b3899da | 2006-10-11 21:50:24 -0400 | [diff] [blame] | 2337 | dev->driver = NULL; |
| 2338 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2341 | static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | { |
| 2343 | int i; |
| 2344 | |
| 2345 | /* don't disconnect if it's not connected */ |
| 2346 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) |
| 2347 | driver = NULL; |
| 2348 | |
| 2349 | /* stop hardware; prevent new request submissions; |
| 2350 | * and kill any outstanding requests. |
| 2351 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2352 | usb_reset(dev); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2353 | for (i = 0; i < dev->n_ep; i++) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2354 | nuke(&dev->ep[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | |
Felipe Balbi | 699412d | 2013-03-18 10:14:47 +0200 | [diff] [blame] | 2356 | /* report disconnect; the driver is already quiesced */ |
| 2357 | if (driver) { |
| 2358 | spin_unlock(&dev->lock); |
| 2359 | driver->disconnect(&dev->gadget); |
| 2360 | spin_lock(&dev->lock); |
| 2361 | } |
| 2362 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2363 | usb_reinit(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Felipe Balbi | 22835b8 | 2014-10-17 12:05:12 -0500 | [diff] [blame] | 2366 | static int net2280_stop(struct usb_gadget *_gadget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | { |
Felipe Balbi | 4cf5e00 | 2011-10-10 10:37:17 +0300 | [diff] [blame] | 2368 | struct net2280 *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | unsigned long flags; |
| 2370 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2371 | dev = container_of(_gadget, struct net2280, gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2373 | spin_lock_irqsave(&dev->lock, flags); |
Felipe Balbi | bfd0ed5 | 2014-10-17 11:23:33 -0500 | [diff] [blame] | 2374 | stop_activity(dev, NULL); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2375 | spin_unlock_irqrestore(&dev->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2377 | net2280_led_active(dev, 0); |
Alan Stern | 2f07607 | 2013-01-30 16:40:14 -0500 | [diff] [blame] | 2378 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2379 | device_remove_file(&dev->pdev->dev, &dev_attr_function); |
| 2380 | device_remove_file(&dev->pdev->dev, &dev_attr_queues); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | |
Felipe Balbi | bfd0ed5 | 2014-10-17 11:23:33 -0500 | [diff] [blame] | 2382 | dev->driver = NULL; |
Ricardo Ribalda Delgado | 84237bf | 2014-05-15 14:28:45 +0200 | [diff] [blame] | 2383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | return 0; |
| 2385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
| 2387 | /*-------------------------------------------------------------------------*/ |
| 2388 | |
| 2389 | /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq. |
| 2390 | * also works for dma-capable endpoints, in pio mode or just |
| 2391 | * to manually advance the queue after short OUT transfers. |
| 2392 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2393 | static void handle_ep_small(struct net2280_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | { |
| 2395 | struct net2280_request *req; |
| 2396 | u32 t; |
| 2397 | /* 0 error, 1 mid-data, 2 done */ |
| 2398 | int mode = 1; |
| 2399 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2400 | if (!list_empty(&ep->queue)) |
| 2401 | req = list_entry(ep->queue.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | struct net2280_request, queue); |
| 2403 | else |
| 2404 | req = NULL; |
| 2405 | |
| 2406 | /* ack all, and handle what we care about */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2407 | t = readl(&ep->regs->ep_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | ep->irqs++; |
Ricardo Ribalda Delgado | cb442ee | 2014-11-28 14:51:02 +0100 | [diff] [blame] | 2409 | |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2410 | ep_vdbg(ep->dev, "%s ack ep_stat %08x, req %p\n", |
Ricardo Ribalda Delgado | fc12c68 | 2015-01-13 10:54:58 +0100 | [diff] [blame] | 2411 | ep->ep.name, t, req ? &req->req : NULL); |
Ricardo Ribalda Delgado | cb442ee | 2014-11-28 14:51:02 +0100 | [diff] [blame] | 2412 | |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 2413 | if (!ep->is_in || (ep->dev->quirks & PLX_2280)) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2414 | writel(t & ~BIT(NAK_OUT_PACKETS), &ep->regs->ep_stat); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 2415 | else |
| 2416 | /* Added for 2282 */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2417 | writel(t, &ep->regs->ep_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | |
| 2419 | /* for ep0, monitor token irqs to catch data stage length errors |
| 2420 | * and to synchronize on status. |
| 2421 | * |
| 2422 | * also, to defer reporting of protocol stalls ... here's where |
| 2423 | * data or status first appears, handling stalls here should never |
| 2424 | * cause trouble on the host side.. |
| 2425 | * |
| 2426 | * control requests could be slightly faster without token synch for |
| 2427 | * status, but status can jam up that way. |
| 2428 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2429 | if (unlikely(ep->num == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | if (ep->is_in) { |
| 2431 | /* status; stop NAKing */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2432 | if (t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | if (ep->dev->protocol_stall) { |
| 2434 | ep->stopped = 1; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2435 | set_halt(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | } |
| 2437 | if (!req) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2438 | allow_status(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | mode = 2; |
| 2440 | /* reply to extra IN data tokens with a zlp */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2441 | } else if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | if (ep->dev->protocol_stall) { |
| 2443 | ep->stopped = 1; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2444 | set_halt(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | mode = 2; |
Alan Stern | 1f26e28 | 2006-11-16 10:16:00 -0500 | [diff] [blame] | 2446 | } else if (ep->responded && |
| 2447 | !req && !ep->stopped) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2448 | write_fifo(ep, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | } |
| 2450 | } else { |
| 2451 | /* status; stop NAKing */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2452 | if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | if (ep->dev->protocol_stall) { |
| 2454 | ep->stopped = 1; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2455 | set_halt(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | } |
| 2457 | mode = 2; |
| 2458 | /* an extra OUT token is an error */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 2459 | } else if (((t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) && |
| 2460 | req && |
| 2461 | req->req.actual == req->req.length) || |
| 2462 | (ep->responded && !req)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | ep->dev->protocol_stall = 1; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2464 | set_halt(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | ep->stopped = 1; |
| 2466 | if (req) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2467 | done(ep, req, -EOVERFLOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | req = NULL; |
| 2469 | } |
| 2470 | } |
| 2471 | } |
| 2472 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2473 | if (unlikely(!req)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | return; |
| 2475 | |
| 2476 | /* manual DMA queue advance after short OUT */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2477 | if (likely(ep->dma)) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2478 | if (t & BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | u32 count; |
| 2480 | int stopped = ep->stopped; |
| 2481 | |
| 2482 | /* TRANSFERRED works around OUT_DONE erratum 0112. |
| 2483 | * we expect (N <= maxpacket) bytes; host wrote M. |
| 2484 | * iff (M < N) we won't ever see a DMA interrupt. |
| 2485 | */ |
| 2486 | ep->stopped = 1; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2487 | for (count = 0; ; t = readl(&ep->regs->ep_stat)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | |
| 2489 | /* any preceding dma transfers must finish. |
| 2490 | * dma handles (M >= N), may empty the queue |
| 2491 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2492 | scan_dma_completions(ep); |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 2493 | if (unlikely(list_empty(&ep->queue) || |
| 2494 | ep->out_overflow)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | req = NULL; |
| 2496 | break; |
| 2497 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2498 | req = list_entry(ep->queue.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | struct net2280_request, queue); |
| 2500 | |
| 2501 | /* here either (M < N), a "real" short rx; |
| 2502 | * or (M == N) and the queue didn't empty |
| 2503 | */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2504 | if (likely(t & BIT(FIFO_EMPTY))) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2505 | count = readl(&ep->dma->dmacount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | count &= DMA_BYTE_COUNT_MASK; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2507 | if (readl(&ep->dma->dmadesc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | != req->td_dma) |
| 2509 | req = NULL; |
| 2510 | break; |
| 2511 | } |
| 2512 | udelay(1); |
| 2513 | } |
| 2514 | |
| 2515 | /* stop DMA, leave ep NAKing */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2516 | writel(BIT(DMA_ABORT), &ep->dma->dmastat); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2517 | spin_stop_dma(ep->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2519 | if (likely(req)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | req->td->dmacount = 0; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2521 | t = readl(&ep->regs->ep_avail); |
| 2522 | dma_done(ep, req, count, |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 2523 | (ep->out_overflow || t) |
| 2524 | ? -EOVERFLOW : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | /* also flush to prevent erratum 0106 trouble */ |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 2528 | if (unlikely(ep->out_overflow || |
| 2529 | (ep->dev->chiprev == 0x0100 && |
| 2530 | ep->dev->gadget.speed |
| 2531 | == USB_SPEED_FULL))) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2532 | out_flush(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | ep->out_overflow = 0; |
| 2534 | } |
| 2535 | |
| 2536 | /* (re)start dma if needed, stop NAKing */ |
| 2537 | ep->stopped = stopped; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2538 | if (!list_empty(&ep->queue)) |
| 2539 | restart_dma(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | } else |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2541 | ep_dbg(ep->dev, "%s dma ep_stat %08x ??\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | ep->ep.name, t); |
| 2543 | return; |
| 2544 | |
| 2545 | /* data packet(s) received (in the fifo, OUT) */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2546 | } else if (t & BIT(DATA_PACKET_RECEIVED_INTERRUPT)) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2547 | if (read_fifo(ep, req) && ep->num != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | mode = 2; |
| 2549 | |
| 2550 | /* data packet(s) transmitted (IN) */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2551 | } else if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | unsigned len; |
| 2553 | |
| 2554 | len = req->req.length - req->req.actual; |
| 2555 | if (len > ep->ep.maxpacket) |
| 2556 | len = ep->ep.maxpacket; |
| 2557 | req->req.actual += len; |
| 2558 | |
| 2559 | /* if we wrote it all, we're usually done */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2560 | /* send zlps until the status stage */ |
| 2561 | if ((req->req.actual == req->req.length) && |
| 2562 | (!req->req.zero || len != ep->ep.maxpacket) && ep->num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | mode = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | |
| 2565 | /* there was nothing to do ... */ |
| 2566 | } else if (mode == 1) |
| 2567 | return; |
| 2568 | |
| 2569 | /* done */ |
| 2570 | if (mode == 2) { |
| 2571 | /* stream endpoints often resubmit/unlink in completion */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2572 | done(ep, req, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | |
| 2574 | /* maybe advance queue to next request */ |
| 2575 | if (ep->num == 0) { |
| 2576 | /* NOTE: net2280 could let gadget driver start the |
| 2577 | * status stage later. since not all controllers let |
| 2578 | * them control that, the api doesn't (yet) allow it. |
| 2579 | */ |
| 2580 | if (!ep->stopped) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2581 | allow_status(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | req = NULL; |
| 2583 | } else { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2584 | if (!list_empty(&ep->queue) && !ep->stopped) |
| 2585 | req = list_entry(ep->queue.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | struct net2280_request, queue); |
| 2587 | else |
| 2588 | req = NULL; |
| 2589 | if (req && !ep->is_in) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2590 | stop_out_naking(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | /* is there a buffer for the next packet? |
| 2595 | * for best streaming performance, make sure there is one. |
| 2596 | */ |
| 2597 | if (req && !ep->stopped) { |
| 2598 | |
| 2599 | /* load IN fifo with next packet (may be zlp) */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2600 | if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT)) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2601 | write_fifo(ep, &req->req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | } |
| 2603 | } |
| 2604 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2605 | static struct net2280_ep *get_ep_by_addr(struct net2280 *dev, u16 wIndex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | { |
| 2607 | struct net2280_ep *ep; |
| 2608 | |
| 2609 | if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2610 | return &dev->ep[0]; |
| 2611 | list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | u8 bEndpointAddress; |
| 2613 | |
| 2614 | if (!ep->desc) |
| 2615 | continue; |
| 2616 | bEndpointAddress = ep->desc->bEndpointAddress; |
| 2617 | if ((wIndex ^ bEndpointAddress) & USB_DIR_IN) |
| 2618 | continue; |
| 2619 | if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f)) |
| 2620 | return ep; |
| 2621 | } |
| 2622 | return NULL; |
| 2623 | } |
| 2624 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2625 | static void defect7374_workaround(struct net2280 *dev, struct usb_ctrlrequest r) |
| 2626 | { |
| 2627 | u32 scratch, fsmvalue; |
| 2628 | u32 ack_wait_timeout, state; |
| 2629 | |
| 2630 | /* Workaround for Defect 7374 (U1/U2 erroneously rejected): */ |
| 2631 | scratch = get_idx_reg(dev->regs, SCRATCH); |
| 2632 | fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD); |
| 2633 | scratch &= ~(0xf << DEFECT7374_FSM_FIELD); |
| 2634 | |
| 2635 | if (!((fsmvalue == DEFECT7374_FSM_WAITING_FOR_CONTROL_READ) && |
| 2636 | (r.bRequestType & USB_DIR_IN))) |
| 2637 | return; |
| 2638 | |
| 2639 | /* This is the first Control Read for this connection: */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2640 | if (!(readl(&dev->usb->usbstat) & BIT(SUPER_SPEED_MODE))) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2641 | /* |
| 2642 | * Connection is NOT SS: |
| 2643 | * - Connection must be FS or HS. |
| 2644 | * - This FSM state should allow workaround software to |
| 2645 | * run after the next USB connection. |
| 2646 | */ |
| 2647 | scratch |= DEFECT7374_FSM_NON_SS_CONTROL_READ; |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 2648 | dev->bug7734_patched = 1; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2649 | goto restore_data_eps; |
| 2650 | } |
| 2651 | |
| 2652 | /* Connection is SS: */ |
| 2653 | for (ack_wait_timeout = 0; |
| 2654 | ack_wait_timeout < DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS; |
| 2655 | ack_wait_timeout++) { |
| 2656 | |
| 2657 | state = readl(&dev->plregs->pl_ep_status_1) |
| 2658 | & (0xff << STATE); |
| 2659 | if ((state >= (ACK_GOOD_NORMAL << STATE)) && |
| 2660 | (state <= (ACK_GOOD_MORE_ACKS_TO_COME << STATE))) { |
| 2661 | scratch |= DEFECT7374_FSM_SS_CONTROL_READ; |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 2662 | dev->bug7734_patched = 1; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2663 | break; |
| 2664 | } |
| 2665 | |
| 2666 | /* |
| 2667 | * We have not yet received host's Data Phase ACK |
| 2668 | * - Wait and try again. |
| 2669 | */ |
| 2670 | udelay(DEFECT_7374_PROCESSOR_WAIT_TIME); |
| 2671 | |
| 2672 | continue; |
| 2673 | } |
| 2674 | |
| 2675 | |
| 2676 | if (ack_wait_timeout >= DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2677 | ep_err(dev, "FAIL: Defect 7374 workaround waited but failed " |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2678 | "to detect SS host's data phase ACK."); |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2679 | ep_err(dev, "PL_EP_STATUS_1(23:16):.Expected from 0x11 to 0x16" |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2680 | "got 0x%2.2x.\n", state >> STATE); |
| 2681 | } else { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2682 | ep_warn(dev, "INFO: Defect 7374 workaround waited about\n" |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2683 | "%duSec for Control Read Data Phase ACK\n", |
| 2684 | DEFECT_7374_PROCESSOR_WAIT_TIME * ack_wait_timeout); |
| 2685 | } |
| 2686 | |
| 2687 | restore_data_eps: |
| 2688 | /* |
| 2689 | * Restore data EPs to their pre-workaround settings (disabled, |
| 2690 | * initialized, and other details). |
| 2691 | */ |
| 2692 | defect7374_disable_data_eps(dev); |
| 2693 | |
| 2694 | set_idx_reg(dev->regs, SCRATCH, scratch); |
| 2695 | |
| 2696 | return; |
| 2697 | } |
| 2698 | |
Ricardo Ribalda Delgado | e0cbb04 | 2014-11-28 14:50:54 +0100 | [diff] [blame] | 2699 | static void ep_clear_seqnum(struct net2280_ep *ep) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2700 | { |
| 2701 | struct net2280 *dev = ep->dev; |
| 2702 | u32 val; |
| 2703 | static const u32 ep_pl[9] = { 0, 3, 4, 7, 8, 2, 5, 6, 9 }; |
| 2704 | |
Ricardo Ribalda Delgado | e0cbb04 | 2014-11-28 14:50:54 +0100 | [diff] [blame] | 2705 | val = readl(&dev->plregs->pl_ep_ctrl) & ~0x1f; |
| 2706 | val |= ep_pl[ep->num]; |
| 2707 | writel(val, &dev->plregs->pl_ep_ctrl); |
| 2708 | val |= BIT(SEQUENCE_NUMBER_RESET); |
| 2709 | writel(val, &dev->plregs->pl_ep_ctrl); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2710 | |
Ricardo Ribalda Delgado | e0cbb04 | 2014-11-28 14:50:54 +0100 | [diff] [blame] | 2711 | return; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2712 | } |
| 2713 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2714 | static void handle_stat0_irqs_superspeed(struct net2280 *dev, |
| 2715 | struct net2280_ep *ep, struct usb_ctrlrequest r) |
| 2716 | { |
| 2717 | int tmp = 0; |
| 2718 | |
| 2719 | #define w_value le16_to_cpu(r.wValue) |
| 2720 | #define w_index le16_to_cpu(r.wIndex) |
| 2721 | #define w_length le16_to_cpu(r.wLength) |
| 2722 | |
| 2723 | switch (r.bRequest) { |
| 2724 | struct net2280_ep *e; |
| 2725 | u16 status; |
| 2726 | |
| 2727 | case USB_REQ_SET_CONFIGURATION: |
| 2728 | dev->addressed_state = !w_value; |
| 2729 | goto usb3_delegate; |
| 2730 | |
| 2731 | case USB_REQ_GET_STATUS: |
| 2732 | switch (r.bRequestType) { |
| 2733 | case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE): |
| 2734 | status = dev->wakeup_enable ? 0x02 : 0x00; |
Peter Chen | c8678d9 | 2015-01-28 16:32:35 +0800 | [diff] [blame] | 2735 | if (dev->gadget.is_selfpowered) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2736 | status |= BIT(0); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2737 | status |= (dev->u1_enable << 2 | dev->u2_enable << 3 | |
| 2738 | dev->ltm_enable << 4); |
| 2739 | writel(0, &dev->epregs[0].ep_irqenb); |
| 2740 | set_fifo_bytecount(ep, sizeof(status)); |
| 2741 | writel((__force u32) status, &dev->epregs[0].ep_data); |
| 2742 | allow_status_338x(ep); |
| 2743 | break; |
| 2744 | |
| 2745 | case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT): |
| 2746 | e = get_ep_by_addr(dev, w_index); |
| 2747 | if (!e) |
| 2748 | goto do_stall3; |
| 2749 | status = readl(&e->regs->ep_rsp) & |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2750 | BIT(CLEAR_ENDPOINT_HALT); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2751 | writel(0, &dev->epregs[0].ep_irqenb); |
| 2752 | set_fifo_bytecount(ep, sizeof(status)); |
| 2753 | writel((__force u32) status, &dev->epregs[0].ep_data); |
| 2754 | allow_status_338x(ep); |
| 2755 | break; |
| 2756 | |
| 2757 | default: |
| 2758 | goto usb3_delegate; |
| 2759 | } |
| 2760 | break; |
| 2761 | |
| 2762 | case USB_REQ_CLEAR_FEATURE: |
| 2763 | switch (r.bRequestType) { |
| 2764 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE): |
| 2765 | if (!dev->addressed_state) { |
| 2766 | switch (w_value) { |
| 2767 | case USB_DEVICE_U1_ENABLE: |
| 2768 | dev->u1_enable = 0; |
| 2769 | writel(readl(&dev->usb_ext->usbctl2) & |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2770 | ~BIT(U1_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2771 | &dev->usb_ext->usbctl2); |
| 2772 | allow_status_338x(ep); |
| 2773 | goto next_endpoints3; |
| 2774 | |
| 2775 | case USB_DEVICE_U2_ENABLE: |
| 2776 | dev->u2_enable = 0; |
| 2777 | writel(readl(&dev->usb_ext->usbctl2) & |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2778 | ~BIT(U2_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2779 | &dev->usb_ext->usbctl2); |
| 2780 | allow_status_338x(ep); |
| 2781 | goto next_endpoints3; |
| 2782 | |
| 2783 | case USB_DEVICE_LTM_ENABLE: |
| 2784 | dev->ltm_enable = 0; |
| 2785 | writel(readl(&dev->usb_ext->usbctl2) & |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2786 | ~BIT(LTM_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2787 | &dev->usb_ext->usbctl2); |
| 2788 | allow_status_338x(ep); |
| 2789 | goto next_endpoints3; |
| 2790 | |
| 2791 | default: |
| 2792 | break; |
| 2793 | } |
| 2794 | } |
| 2795 | if (w_value == USB_DEVICE_REMOTE_WAKEUP) { |
| 2796 | dev->wakeup_enable = 0; |
| 2797 | writel(readl(&dev->usb->usbctl) & |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2798 | ~BIT(DEVICE_REMOTE_WAKEUP_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2799 | &dev->usb->usbctl); |
| 2800 | allow_status_338x(ep); |
| 2801 | break; |
| 2802 | } |
| 2803 | goto usb3_delegate; |
| 2804 | |
| 2805 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT): |
| 2806 | e = get_ep_by_addr(dev, w_index); |
| 2807 | if (!e) |
| 2808 | goto do_stall3; |
| 2809 | if (w_value != USB_ENDPOINT_HALT) |
| 2810 | goto do_stall3; |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2811 | ep_vdbg(dev, "%s clear halt\n", e->ep.name); |
Ricardo Ribalda Delgado | e0cbb04 | 2014-11-28 14:50:54 +0100 | [diff] [blame] | 2812 | /* |
| 2813 | * Workaround for SS SeqNum not cleared via |
| 2814 | * Endpoint Halt (Clear) bit. select endpoint |
| 2815 | */ |
| 2816 | ep_clear_seqnum(e); |
| 2817 | clear_halt(e); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2818 | if (!list_empty(&e->queue) && e->td_dma) |
| 2819 | restart_dma(e); |
| 2820 | allow_status(ep); |
| 2821 | ep->stopped = 1; |
| 2822 | break; |
| 2823 | |
| 2824 | default: |
| 2825 | goto usb3_delegate; |
| 2826 | } |
| 2827 | break; |
| 2828 | case USB_REQ_SET_FEATURE: |
| 2829 | switch (r.bRequestType) { |
| 2830 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE): |
| 2831 | if (!dev->addressed_state) { |
| 2832 | switch (w_value) { |
| 2833 | case USB_DEVICE_U1_ENABLE: |
| 2834 | dev->u1_enable = 1; |
| 2835 | writel(readl(&dev->usb_ext->usbctl2) | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2836 | BIT(U1_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2837 | &dev->usb_ext->usbctl2); |
| 2838 | allow_status_338x(ep); |
| 2839 | goto next_endpoints3; |
| 2840 | |
| 2841 | case USB_DEVICE_U2_ENABLE: |
| 2842 | dev->u2_enable = 1; |
| 2843 | writel(readl(&dev->usb_ext->usbctl2) | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2844 | BIT(U2_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2845 | &dev->usb_ext->usbctl2); |
| 2846 | allow_status_338x(ep); |
| 2847 | goto next_endpoints3; |
| 2848 | |
| 2849 | case USB_DEVICE_LTM_ENABLE: |
| 2850 | dev->ltm_enable = 1; |
| 2851 | writel(readl(&dev->usb_ext->usbctl2) | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2852 | BIT(LTM_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2853 | &dev->usb_ext->usbctl2); |
| 2854 | allow_status_338x(ep); |
| 2855 | goto next_endpoints3; |
| 2856 | default: |
| 2857 | break; |
| 2858 | } |
| 2859 | } |
| 2860 | |
| 2861 | if (w_value == USB_DEVICE_REMOTE_WAKEUP) { |
| 2862 | dev->wakeup_enable = 1; |
| 2863 | writel(readl(&dev->usb->usbctl) | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2864 | BIT(DEVICE_REMOTE_WAKEUP_ENABLE), |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2865 | &dev->usb->usbctl); |
| 2866 | allow_status_338x(ep); |
| 2867 | break; |
| 2868 | } |
| 2869 | goto usb3_delegate; |
| 2870 | |
| 2871 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT): |
| 2872 | e = get_ep_by_addr(dev, w_index); |
| 2873 | if (!e || (w_value != USB_ENDPOINT_HALT)) |
| 2874 | goto do_stall3; |
Ricardo Ribalda Delgado | cf8b1cd | 2014-11-28 14:50:52 +0100 | [diff] [blame] | 2875 | ep->stopped = 1; |
| 2876 | if (ep->num == 0) |
| 2877 | ep->dev->protocol_stall = 1; |
| 2878 | else { |
| 2879 | if (ep->dma) |
Ricardo Ribalda Delgado | e721c45 | 2014-11-28 14:50:55 +0100 | [diff] [blame] | 2880 | abort_dma(ep); |
Ricardo Ribalda Delgado | e0cbb04 | 2014-11-28 14:50:54 +0100 | [diff] [blame] | 2881 | set_halt(ep); |
Ricardo Ribalda Delgado | cf8b1cd | 2014-11-28 14:50:52 +0100 | [diff] [blame] | 2882 | } |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2883 | allow_status_338x(ep); |
| 2884 | break; |
| 2885 | |
| 2886 | default: |
| 2887 | goto usb3_delegate; |
| 2888 | } |
| 2889 | |
| 2890 | break; |
| 2891 | default: |
| 2892 | |
| 2893 | usb3_delegate: |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2894 | ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x ep_cfg %08x\n", |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2895 | r.bRequestType, r.bRequest, |
| 2896 | w_value, w_index, w_length, |
| 2897 | readl(&ep->cfg->ep_cfg)); |
| 2898 | |
| 2899 | ep->responded = 0; |
| 2900 | spin_unlock(&dev->lock); |
| 2901 | tmp = dev->driver->setup(&dev->gadget, &r); |
| 2902 | spin_lock(&dev->lock); |
| 2903 | } |
| 2904 | do_stall3: |
| 2905 | if (tmp < 0) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2906 | ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n", |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2907 | r.bRequestType, r.bRequest, tmp); |
| 2908 | dev->protocol_stall = 1; |
| 2909 | /* TD 9.9 Halt Endpoint test. TD 9.22 Set feature test */ |
Ricardo Ribalda Delgado | e0cbb04 | 2014-11-28 14:50:54 +0100 | [diff] [blame] | 2910 | set_halt(ep); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | next_endpoints3: |
| 2914 | |
| 2915 | #undef w_value |
| 2916 | #undef w_index |
| 2917 | #undef w_length |
| 2918 | |
| 2919 | return; |
| 2920 | } |
| 2921 | |
Mian Yousaf Kaukab | a09e23f | 2015-05-16 22:33:35 +0200 | [diff] [blame] | 2922 | static void usb338x_handle_ep_intr(struct net2280 *dev, u32 stat0) |
| 2923 | { |
| 2924 | u32 index; |
| 2925 | u32 bit; |
| 2926 | |
| 2927 | for (index = 0; index < ARRAY_SIZE(ep_bit); index++) { |
| 2928 | bit = BIT(ep_bit[index]); |
| 2929 | |
| 2930 | if (!stat0) |
| 2931 | break; |
| 2932 | |
| 2933 | if (!(stat0 & bit)) |
| 2934 | continue; |
| 2935 | |
| 2936 | stat0 &= ~bit; |
| 2937 | |
| 2938 | handle_ep_small(&dev->ep[index]); |
| 2939 | } |
| 2940 | } |
| 2941 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2942 | static void handle_stat0_irqs(struct net2280 *dev, u32 stat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | { |
| 2944 | struct net2280_ep *ep; |
| 2945 | u32 num, scratch; |
| 2946 | |
| 2947 | /* most of these don't need individual acks */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2948 | stat &= ~BIT(INTA_ASSERTED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | if (!stat) |
| 2950 | return; |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2951 | /* ep_dbg(dev, "irqstat0 %04x\n", stat); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | |
| 2953 | /* starting a control request? */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2954 | if (unlikely(stat & BIT(SETUP_PACKET_INTERRUPT))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | union { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2956 | u32 raw[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | struct usb_ctrlrequest r; |
| 2958 | } u; |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 2959 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | struct net2280_request *req; |
| 2961 | |
| 2962 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2963 | u32 val = readl(&dev->usb->usbstat); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2964 | if (val & BIT(SUPER_SPEED)) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2965 | dev->gadget.speed = USB_SPEED_SUPER; |
| 2966 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, |
| 2967 | EP0_SS_MAX_PACKET_SIZE); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2968 | } else if (val & BIT(HIGH_SPEED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | dev->gadget.speed = USB_SPEED_HIGH; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2970 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, |
| 2971 | EP0_HS_MAX_PACKET_SIZE); |
| 2972 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | dev->gadget.speed = USB_SPEED_FULL; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2974 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, |
| 2975 | EP0_HS_MAX_PACKET_SIZE); |
| 2976 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2977 | net2280_led_speed(dev, dev->gadget.speed); |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 2978 | ep_dbg(dev, "%s\n", |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2979 | usb_speed_string(dev->gadget.speed)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2982 | ep = &dev->ep[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | ep->irqs++; |
| 2984 | |
| 2985 | /* make sure any leftover request state is cleared */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2986 | stat &= ~BIT(ENDPOINT_0_INTERRUPT); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2987 | while (!list_empty(&ep->queue)) { |
| 2988 | req = list_entry(ep->queue.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | struct net2280_request, queue); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 2990 | done(ep, req, (req->req.actual == req->req.length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | ? 0 : -EPROTO); |
| 2992 | } |
| 2993 | ep->stopped = 0; |
| 2994 | dev->protocol_stall = 0; |
Ricardo Ribalda Delgado | 5d1b684 | 2014-11-28 14:50:53 +0100 | [diff] [blame] | 2995 | if (!(dev->quirks & PLX_SUPERSPEED)) { |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 2996 | if (ep->dev->quirks & PLX_2280) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 2997 | tmp = BIT(FIFO_OVERFLOW) | |
| 2998 | BIT(FIFO_UNDERFLOW); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 2999 | else |
| 3000 | tmp = 0; |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 3001 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3002 | writel(tmp | BIT(TIMEOUT) | |
| 3003 | BIT(USB_STALL_SENT) | |
| 3004 | BIT(USB_IN_NAK_SENT) | |
| 3005 | BIT(USB_IN_ACK_RCVD) | |
| 3006 | BIT(USB_OUT_PING_NAK_SENT) | |
| 3007 | BIT(USB_OUT_ACK_SENT) | |
| 3008 | BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) | |
| 3009 | BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) | |
| 3010 | BIT(DATA_PACKET_RECEIVED_INTERRUPT) | |
| 3011 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | |
| 3012 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 3013 | BIT(DATA_IN_TOKEN_INTERRUPT), |
| 3014 | &ep->regs->ep_stat); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3015 | } |
| 3016 | u.raw[0] = readl(&dev->usb->setup0123); |
| 3017 | u.raw[1] = readl(&dev->usb->setup4567); |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 3018 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3019 | cpu_to_le32s(&u.raw[0]); |
| 3020 | cpu_to_le32s(&u.raw[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 3022 | if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3023 | defect7374_workaround(dev, u.r); |
| 3024 | |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 3025 | tmp = 0; |
| 3026 | |
David Brownell | 01ee7d7 | 2007-05-25 20:40:14 -0700 | [diff] [blame] | 3027 | #define w_value le16_to_cpu(u.r.wValue) |
| 3028 | #define w_index le16_to_cpu(u.r.wIndex) |
| 3029 | #define w_length le16_to_cpu(u.r.wLength) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
| 3031 | /* ack the irq */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3032 | writel(BIT(SETUP_PACKET_INTERRUPT), &dev->regs->irqstat0); |
| 3033 | stat ^= BIT(SETUP_PACKET_INTERRUPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | |
| 3035 | /* watch control traffic at the token level, and force |
| 3036 | * synchronization before letting the status stage happen. |
| 3037 | * FIXME ignore tokens we'll NAK, until driver responds. |
| 3038 | * that'll mean a lot less irqs for some drivers. |
| 3039 | */ |
| 3040 | ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0; |
| 3041 | if (ep->is_in) { |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3042 | scratch = BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | |
| 3043 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | |
| 3044 | BIT(DATA_IN_TOKEN_INTERRUPT); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3045 | stop_out_naking(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | } else |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3047 | scratch = BIT(DATA_PACKET_RECEIVED_INTERRUPT) | |
| 3048 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | |
| 3049 | BIT(DATA_IN_TOKEN_INTERRUPT); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3050 | writel(scratch, &dev->epregs[0].ep_irqenb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | |
| 3052 | /* we made the hardware handle most lowlevel requests; |
| 3053 | * everything else goes uplevel to the gadget code. |
| 3054 | */ |
Alan Stern | 1f26e28 | 2006-11-16 10:16:00 -0500 | [diff] [blame] | 3055 | ep->responded = 1; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3056 | |
| 3057 | if (dev->gadget.speed == USB_SPEED_SUPER) { |
| 3058 | handle_stat0_irqs_superspeed(dev, ep, u.r); |
| 3059 | goto next_endpoints; |
| 3060 | } |
| 3061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | switch (u.r.bRequest) { |
| 3063 | case USB_REQ_GET_STATUS: { |
| 3064 | struct net2280_ep *e; |
David Brownell | 320f345 | 2005-05-07 13:05:18 -0700 | [diff] [blame] | 3065 | __le32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | |
| 3067 | /* hw handles device and interface status */ |
| 3068 | if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) |
| 3069 | goto delegate; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3070 | e = get_ep_by_addr(dev, w_index); |
| 3071 | if (!e || w_length > 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | goto do_stall; |
| 3073 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3074 | if (readl(&e->regs->ep_rsp) & BIT(SET_ENDPOINT_HALT)) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3075 | status = cpu_to_le32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | else |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3077 | status = cpu_to_le32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | |
| 3079 | /* don't bother with a request object! */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3080 | writel(0, &dev->epregs[0].ep_irqenb); |
| 3081 | set_fifo_bytecount(ep, w_length); |
| 3082 | writel((__force u32)status, &dev->epregs[0].ep_data); |
| 3083 | allow_status(ep); |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3084 | ep_vdbg(dev, "%s stat %02x\n", ep->ep.name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | goto next_endpoints; |
| 3086 | } |
| 3087 | break; |
| 3088 | case USB_REQ_CLEAR_FEATURE: { |
| 3089 | struct net2280_ep *e; |
| 3090 | |
| 3091 | /* hw handles device features */ |
| 3092 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) |
| 3093 | goto delegate; |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 3094 | if (w_value != USB_ENDPOINT_HALT || w_length != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | goto do_stall; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3096 | e = get_ep_by_addr(dev, w_index); |
| 3097 | if (!e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | goto do_stall; |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 3099 | if (e->wedged) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3100 | ep_vdbg(dev, "%s wedged, halt not cleared\n", |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 3101 | ep->ep.name); |
| 3102 | } else { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3103 | ep_vdbg(dev, "%s clear halt\n", e->ep.name); |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 3104 | clear_halt(e); |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3105 | if ((ep->dev->quirks & PLX_SUPERSPEED) && |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3106 | !list_empty(&e->queue) && e->td_dma) |
| 3107 | restart_dma(e); |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 3108 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3109 | allow_status(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | goto next_endpoints; |
| 3111 | } |
| 3112 | break; |
| 3113 | case USB_REQ_SET_FEATURE: { |
| 3114 | struct net2280_ep *e; |
| 3115 | |
| 3116 | /* hw handles device features */ |
| 3117 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) |
| 3118 | goto delegate; |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 3119 | if (w_value != USB_ENDPOINT_HALT || w_length != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | goto do_stall; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3121 | e = get_ep_by_addr(dev, w_index); |
| 3122 | if (!e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | goto do_stall; |
Alan Stern | 8066134 | 2008-08-14 15:49:11 -0400 | [diff] [blame] | 3124 | if (e->ep.name == ep0name) |
| 3125 | goto do_stall; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3126 | set_halt(e); |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3127 | if ((dev->quirks & PLX_SUPERSPEED) && e->dma) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3128 | abort_dma(e); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3129 | allow_status(ep); |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3130 | ep_vdbg(dev, "%s set halt\n", ep->ep.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | goto next_endpoints; |
| 3132 | } |
| 3133 | break; |
| 3134 | default: |
| 3135 | delegate: |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3136 | ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | "ep_cfg %08x\n", |
| 3138 | u.r.bRequestType, u.r.bRequest, |
David Brownell | 320f345 | 2005-05-07 13:05:18 -0700 | [diff] [blame] | 3139 | w_value, w_index, w_length, |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3140 | readl(&ep->cfg->ep_cfg)); |
Alan Stern | 1f26e28 | 2006-11-16 10:16:00 -0500 | [diff] [blame] | 3141 | ep->responded = 0; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3142 | spin_unlock(&dev->lock); |
| 3143 | tmp = dev->driver->setup(&dev->gadget, &u.r); |
| 3144 | spin_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | /* stall ep0 on error */ |
| 3148 | if (tmp < 0) { |
| 3149 | do_stall: |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3150 | ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | u.r.bRequestType, u.r.bRequest, tmp); |
| 3152 | dev->protocol_stall = 1; |
| 3153 | } |
| 3154 | |
| 3155 | /* some in/out token irq should follow; maybe stall then. |
| 3156 | * driver must queue a request (even zlp) or halt ep0 |
| 3157 | * before the host times out. |
| 3158 | */ |
| 3159 | } |
| 3160 | |
David Brownell | 320f345 | 2005-05-07 13:05:18 -0700 | [diff] [blame] | 3161 | #undef w_value |
| 3162 | #undef w_index |
| 3163 | #undef w_length |
| 3164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | next_endpoints: |
Mian Yousaf Kaukab | a09e23f | 2015-05-16 22:33:35 +0200 | [diff] [blame] | 3166 | if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) { |
| 3167 | u32 mask = (BIT(ENDPOINT_0_INTERRUPT) | |
| 3168 | USB3380_IRQSTAT0_EP_INTR_MASK_IN | |
| 3169 | USB3380_IRQSTAT0_EP_INTR_MASK_OUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | |
Mian Yousaf Kaukab | a09e23f | 2015-05-16 22:33:35 +0200 | [diff] [blame] | 3171 | if (stat & mask) { |
| 3172 | usb338x_handle_ep_intr(dev, stat & mask); |
| 3173 | stat &= ~mask; |
| 3174 | } |
| 3175 | } else { |
| 3176 | /* endpoint data irq ? */ |
| 3177 | scratch = stat & 0x7f; |
| 3178 | stat &= ~0x7f; |
| 3179 | for (num = 0; scratch; num++) { |
| 3180 | u32 t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | |
Mian Yousaf Kaukab | a09e23f | 2015-05-16 22:33:35 +0200 | [diff] [blame] | 3182 | /* do this endpoint's FIFO and queue need tending? */ |
| 3183 | t = BIT(num); |
| 3184 | if ((scratch & t) == 0) |
| 3185 | continue; |
| 3186 | scratch ^= t; |
| 3187 | |
| 3188 | ep = &dev->ep[num]; |
| 3189 | handle_ep_small(ep); |
| 3190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | if (stat) |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3194 | ep_dbg(dev, "unhandled irqstat0 %08x\n", stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3197 | #define DMA_INTERRUPTS (BIT(DMA_D_INTERRUPT) | \ |
| 3198 | BIT(DMA_C_INTERRUPT) | \ |
| 3199 | BIT(DMA_B_INTERRUPT) | \ |
| 3200 | BIT(DMA_A_INTERRUPT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | #define PCI_ERROR_INTERRUPTS ( \ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3202 | BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT) | \ |
| 3203 | BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT) | \ |
| 3204 | BIT(PCI_RETRY_ABORT_INTERRUPT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3206 | static void handle_stat1_irqs(struct net2280 *dev, u32 stat) |
Felipe Balbi | ccf5fb6 | 2015-02-27 09:44:51 -0600 | [diff] [blame] | 3207 | __releases(dev->lock) |
| 3208 | __acquires(dev->lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | { |
| 3210 | struct net2280_ep *ep; |
| 3211 | u32 tmp, num, mask, scratch; |
| 3212 | |
| 3213 | /* after disconnect there's nothing else to do! */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3214 | tmp = BIT(VBUS_INTERRUPT) | BIT(ROOT_PORT_RESET_INTERRUPT); |
| 3215 | mask = BIT(SUPER_SPEED) | BIT(HIGH_SPEED) | BIT(FULL_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
| 3217 | /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set. |
Vitaliy Ivanov | fb914eb | 2011-06-23 20:01:55 +0300 | [diff] [blame] | 3218 | * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 3219 | * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | * only indicates a change in the reset state). |
| 3221 | */ |
| 3222 | if (stat & tmp) { |
Alan Stern | b611e42 | 2014-11-06 14:27:56 +0800 | [diff] [blame] | 3223 | bool reset = false; |
| 3224 | bool disconnect = false; |
| 3225 | |
| 3226 | /* |
| 3227 | * Ignore disconnects and resets if the speed hasn't been set. |
| 3228 | * VBUS can bounce and there's always an initial reset. |
| 3229 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3230 | writel(tmp, &dev->regs->irqstat1); |
Alan Stern | b611e42 | 2014-11-06 14:27:56 +0800 | [diff] [blame] | 3231 | if (dev->gadget.speed != USB_SPEED_UNKNOWN) { |
| 3232 | if ((stat & BIT(VBUS_INTERRUPT)) && |
| 3233 | (readl(&dev->usb->usbctl) & |
| 3234 | BIT(VBUS_PIN)) == 0) { |
| 3235 | disconnect = true; |
| 3236 | ep_dbg(dev, "disconnect %s\n", |
| 3237 | dev->driver->driver.name); |
| 3238 | } else if ((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) && |
| 3239 | (readl(&dev->usb->usbstat) & mask) |
| 3240 | == 0) { |
| 3241 | reset = true; |
| 3242 | ep_dbg(dev, "reset %s\n", |
| 3243 | dev->driver->driver.name); |
| 3244 | } |
| 3245 | |
| 3246 | if (disconnect || reset) { |
| 3247 | stop_activity(dev, dev->driver); |
| 3248 | ep0_start(dev); |
| 3249 | spin_unlock(&dev->lock); |
| 3250 | if (reset) |
| 3251 | usb_gadget_udc_reset |
| 3252 | (&dev->gadget, dev->driver); |
| 3253 | else |
| 3254 | (dev->driver->disconnect) |
| 3255 | (&dev->gadget); |
| 3256 | spin_lock(&dev->lock); |
| 3257 | return; |
| 3258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | } |
| 3260 | stat &= ~tmp; |
| 3261 | |
| 3262 | /* vBUS can bounce ... one of many reasons to ignore the |
| 3263 | * notion of hotplug events on bus connect/disconnect! |
| 3264 | */ |
| 3265 | if (!stat) |
| 3266 | return; |
| 3267 | } |
| 3268 | |
| 3269 | /* NOTE: chip stays in PCI D0 state for now, but it could |
| 3270 | * enter D1 to save more power |
| 3271 | */ |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3272 | tmp = BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | if (stat & tmp) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3274 | writel(tmp, &dev->regs->irqstat1); |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3275 | if (stat & BIT(SUSPEND_REQUEST_INTERRUPT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | if (dev->driver->suspend) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3277 | dev->driver->suspend(&dev->gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | if (!enable_suspend) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3279 | stat &= ~BIT(SUSPEND_REQUEST_INTERRUPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } else { |
| 3281 | if (dev->driver->resume) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3282 | dev->driver->resume(&dev->gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | /* at high speed, note erratum 0133 */ |
| 3284 | } |
| 3285 | stat &= ~tmp; |
| 3286 | } |
| 3287 | |
| 3288 | /* clear any other status/irqs */ |
| 3289 | if (stat) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3290 | writel(stat, &dev->regs->irqstat1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | |
| 3292 | /* some status we can just ignore */ |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3293 | if (dev->quirks & PLX_2280) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3294 | stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) | |
| 3295 | BIT(SUSPEND_REQUEST_INTERRUPT) | |
| 3296 | BIT(RESUME_INTERRUPT) | |
| 3297 | BIT(SOF_INTERRUPT)); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 3298 | else |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3299 | stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) | |
| 3300 | BIT(RESUME_INTERRUPT) | |
| 3301 | BIT(SOF_DOWN_INTERRUPT) | |
| 3302 | BIT(SOF_INTERRUPT)); |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 3303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | if (!stat) |
| 3305 | return; |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3306 | /* ep_dbg(dev, "irqstat1 %08x\n", stat);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | |
| 3308 | /* DMA status, for ep-{a,b,c,d} */ |
| 3309 | scratch = stat & DMA_INTERRUPTS; |
| 3310 | stat &= ~DMA_INTERRUPTS; |
| 3311 | scratch >>= 9; |
| 3312 | for (num = 0; scratch; num++) { |
| 3313 | struct net2280_dma_regs __iomem *dma; |
| 3314 | |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3315 | tmp = BIT(num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | if ((tmp & scratch) == 0) |
| 3317 | continue; |
| 3318 | scratch ^= tmp; |
| 3319 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3320 | ep = &dev->ep[num + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | dma = ep->dma; |
| 3322 | |
| 3323 | if (!dma) |
| 3324 | continue; |
| 3325 | |
| 3326 | /* clear ep's dma status */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3327 | tmp = readl(&dma->dmastat); |
| 3328 | writel(tmp, &dma->dmastat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3330 | /* dma sync*/ |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3331 | if (dev->quirks & PLX_SUPERSPEED) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3332 | u32 r_dmacount = readl(&dma->dmacount); |
| 3333 | if (!ep->is_in && (r_dmacount & 0x00FFFFFF) && |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3334 | (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3335 | continue; |
| 3336 | } |
| 3337 | |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 3338 | if (!(tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) { |
| 3339 | ep_dbg(ep->dev, "%s no xact done? %08x\n", |
| 3340 | ep->ep.name, tmp); |
| 3341 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | } |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 3343 | stop_dma(ep->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | |
| 3345 | /* OUT transfers terminate when the data from the |
| 3346 | * host is in our memory. Process whatever's done. |
| 3347 | * On this path, we know transfer's last packet wasn't |
| 3348 | * less than req->length. NAK_OUT_PACKETS may be set, |
| 3349 | * or the FIFO may already be holding new packets. |
| 3350 | * |
| 3351 | * IN transfers can linger in the FIFO for a very |
| 3352 | * long time ... we ignore that for now, accounting |
| 3353 | * precisely (like PIO does) needs per-packet irqs |
| 3354 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3355 | scan_dma_completions(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | |
| 3357 | /* disable dma on inactive queues; else maybe restart */ |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 3358 | if (!list_empty(&ep->queue)) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3359 | tmp = readl(&dma->dmactl); |
Ricardo Ribalda Delgado | 9066419 | 2014-11-28 14:50:46 +0100 | [diff] [blame] | 3360 | restart_dma(ep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | } |
| 3362 | ep->irqs++; |
| 3363 | } |
| 3364 | |
| 3365 | /* NOTE: there are other PCI errors we might usefully notice. |
| 3366 | * if they appear very often, here's where to try recovering. |
| 3367 | */ |
| 3368 | if (stat & PCI_ERROR_INTERRUPTS) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3369 | ep_err(dev, "pci dma error; stat %08x\n", stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | stat &= ~PCI_ERROR_INTERRUPTS; |
| 3371 | /* these are fatal errors, but "maybe" they won't |
| 3372 | * happen again ... |
| 3373 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3374 | stop_activity(dev, dev->driver); |
| 3375 | ep0_start(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | stat = 0; |
| 3377 | } |
| 3378 | |
| 3379 | if (stat) |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3380 | ep_dbg(dev, "unhandled irqstat1 %08x\n", stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3383 | static irqreturn_t net2280_irq(int irq, void *_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | { |
| 3385 | struct net2280 *dev = _dev; |
| 3386 | |
Alan Stern | 658ad5e | 2006-04-14 16:44:11 -0400 | [diff] [blame] | 3387 | /* shared interrupt, not ours */ |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3388 | if ((dev->quirks & PLX_LEGACY) && |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3389 | (!(readl(&dev->regs->irqstat0) & BIT(INTA_ASSERTED)))) |
Alan Stern | 658ad5e | 2006-04-14 16:44:11 -0400 | [diff] [blame] | 3390 | return IRQ_NONE; |
| 3391 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3392 | spin_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | |
| 3394 | /* handle disconnect, dma, and more */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3395 | handle_stat1_irqs(dev, readl(&dev->regs->irqstat1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | |
| 3397 | /* control requests and PIO */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3398 | handle_stat0_irqs(dev, readl(&dev->regs->irqstat0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3400 | if (dev->quirks & PLX_SUPERSPEED) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3401 | /* re-enable interrupt to trigger any possible new interrupt */ |
| 3402 | u32 pciirqenb1 = readl(&dev->regs->pciirqenb1); |
| 3403 | writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1); |
| 3404 | writel(pciirqenb1, &dev->regs->pciirqenb1); |
| 3405 | } |
| 3406 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3407 | spin_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | |
| 3409 | return IRQ_HANDLED; |
| 3410 | } |
| 3411 | |
| 3412 | /*-------------------------------------------------------------------------*/ |
| 3413 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3414 | static void gadget_release(struct device *_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3416 | struct net2280 *dev = dev_get_drvdata(_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3418 | kfree(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | /* tear down the binding between this driver and the pci device */ |
| 3422 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3423 | static void net2280_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3425 | struct net2280 *dev = pci_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3427 | usb_del_gadget_udc(&dev->gadget); |
| 3428 | |
David Brownell | 6bea476 | 2006-12-05 03:15:33 -0800 | [diff] [blame] | 3429 | BUG_ON(dev->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | |
| 3431 | /* then clean up the resources we allocated during probe() */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3432 | net2280_led_shutdown(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | if (dev->requests) { |
| 3434 | int i; |
| 3435 | for (i = 1; i < 5; i++) { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3436 | if (!dev->ep[i].dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | continue; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3438 | pci_pool_free(dev->requests, dev->ep[i].dummy, |
| 3439 | dev->ep[i].td_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | } |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3441 | pci_pool_destroy(dev->requests); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | } |
| 3443 | if (dev->got_irq) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3444 | free_irq(pdev->irq, dev); |
Ricardo Ribalda Delgado | 9c864c2 | 2014-11-28 14:50:48 +0100 | [diff] [blame] | 3445 | if (dev->quirks & PLX_SUPERSPEED) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3446 | pci_disable_msi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | if (dev->regs) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3448 | iounmap(dev->regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | if (dev->region) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3450 | release_mem_region(pci_resource_start(pdev, 0), |
| 3451 | pci_resource_len(pdev, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | if (dev->enabled) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3453 | pci_disable_device(pdev); |
| 3454 | device_remove_file(&pdev->dev, &dev_attr_registers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3456 | ep_info(dev, "unbind\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | /* wrap this driver around the specified device, but |
| 3460 | * don't respond over USB until a gadget driver binds to us. |
| 3461 | */ |
| 3462 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3463 | static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | { |
| 3465 | struct net2280 *dev; |
| 3466 | unsigned long resource, len; |
| 3467 | void __iomem *base = NULL; |
| 3468 | int retval, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | /* alloc, and start init */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3471 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 3472 | if (dev == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | retval = -ENOMEM; |
| 3474 | goto done; |
| 3475 | } |
| 3476 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3477 | pci_set_drvdata(pdev, dev); |
| 3478 | spin_lock_init(&dev->lock); |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3479 | dev->quirks = id->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | dev->pdev = pdev; |
| 3481 | dev->gadget.ops = &net2280_ops; |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3482 | dev->gadget.max_speed = (dev->quirks & PLX_SUPERSPEED) ? |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3483 | USB_SPEED_SUPER : USB_SPEED_HIGH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | |
| 3485 | /* the "gadget" abstracts/virtualizes the controller */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | dev->gadget.name = driver_name; |
| 3487 | |
| 3488 | /* now all the pci goodies ... */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3489 | if (pci_enable_device(pdev) < 0) { |
| 3490 | retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | goto done; |
| 3492 | } |
| 3493 | dev->enabled = 1; |
| 3494 | |
| 3495 | /* BAR 0 holds all the registers |
| 3496 | * BAR 1 is 8051 memory; unused here (note erratum 0103) |
| 3497 | * BAR 2 is fifo memory; unused here |
| 3498 | */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3499 | resource = pci_resource_start(pdev, 0); |
| 3500 | len = pci_resource_len(pdev, 0); |
| 3501 | if (!request_mem_region(resource, len, driver_name)) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3502 | ep_dbg(dev, "controller already in use\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | retval = -EBUSY; |
| 3504 | goto done; |
| 3505 | } |
| 3506 | dev->region = 1; |
| 3507 | |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 3508 | /* FIXME provide firmware download interface to put |
| 3509 | * 8051 code into the chip, e.g. to turn on PCI PM. |
| 3510 | */ |
| 3511 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3512 | base = ioremap_nocache(resource, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | if (base == NULL) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3514 | ep_dbg(dev, "can't map memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | retval = -EFAULT; |
| 3516 | goto done; |
| 3517 | } |
| 3518 | dev->regs = (struct net2280_regs __iomem *) base; |
| 3519 | dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080); |
| 3520 | dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100); |
| 3521 | dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180); |
| 3522 | dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200); |
| 3523 | dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300); |
| 3524 | |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3525 | if (dev->quirks & PLX_SUPERSPEED) { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3526 | u32 fsmvalue; |
| 3527 | u32 usbstat; |
| 3528 | dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *) |
| 3529 | (base + 0x00b4); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3530 | dev->llregs = (struct usb338x_ll_regs __iomem *) |
| 3531 | (base + 0x0700); |
| 3532 | dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *) |
| 3533 | (base + 0x0748); |
| 3534 | dev->ll_tsn_regs = (struct usb338x_ll_tsn_regs __iomem *) |
| 3535 | (base + 0x077c); |
| 3536 | dev->ll_chicken_reg = (struct usb338x_ll_chi_regs __iomem *) |
| 3537 | (base + 0x079c); |
| 3538 | dev->plregs = (struct usb338x_pl_regs __iomem *) |
| 3539 | (base + 0x0800); |
| 3540 | usbstat = readl(&dev->usb->usbstat); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3541 | dev->enhanced_mode = !!(usbstat & BIT(11)); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3542 | dev->n_ep = (dev->enhanced_mode) ? 9 : 5; |
| 3543 | /* put into initial config, link up all endpoints */ |
| 3544 | fsmvalue = get_idx_reg(dev->regs, SCRATCH) & |
| 3545 | (0xf << DEFECT7374_FSM_FIELD); |
| 3546 | /* See if firmware needs to set up for workaround: */ |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 3547 | if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ) { |
| 3548 | dev->bug7734_patched = 1; |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3549 | writel(0, &dev->usb->usbctl); |
Ricardo Ribalda Delgado | 5517525 | 2014-11-28 14:50:57 +0100 | [diff] [blame] | 3550 | } else |
| 3551 | dev->bug7734_patched = 0; |
| 3552 | } else { |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3553 | dev->enhanced_mode = 0; |
| 3554 | dev->n_ep = 7; |
| 3555 | /* put into initial config, link up all endpoints */ |
| 3556 | writel(0, &dev->usb->usbctl); |
| 3557 | } |
| 3558 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3559 | usb_reset(dev); |
| 3560 | usb_reinit(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | |
| 3562 | /* irq setup after old hardware is cleaned up */ |
| 3563 | if (!pdev->irq) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3564 | ep_err(dev, "No IRQ. Check PCI setup!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | retval = -ENODEV; |
| 3566 | goto done; |
| 3567 | } |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 3568 | |
Ricardo Ribalda Delgado | 9c864c2 | 2014-11-28 14:50:48 +0100 | [diff] [blame] | 3569 | if (dev->quirks & PLX_SUPERSPEED) |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3570 | if (pci_enable_msi(pdev)) |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3571 | ep_err(dev, "Failed to enable MSI mode\n"); |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3572 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3573 | if (request_irq(pdev->irq, net2280_irq, IRQF_SHARED, |
| 3574 | driver_name, dev)) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3575 | ep_err(dev, "request interrupt %d failed\n", pdev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | retval = -EBUSY; |
| 3577 | goto done; |
| 3578 | } |
| 3579 | dev->got_irq = 1; |
| 3580 | |
| 3581 | /* DMA setup */ |
| 3582 | /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3583 | dev->requests = pci_pool_create("requests", pdev, |
| 3584 | sizeof(struct net2280_dma), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | 0 /* no alignment requirements */, |
| 3586 | 0 /* or page-crossing issues */); |
| 3587 | if (!dev->requests) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3588 | ep_dbg(dev, "can't get request pool\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | retval = -ENOMEM; |
| 3590 | goto done; |
| 3591 | } |
| 3592 | for (i = 1; i < 5; i++) { |
| 3593 | struct net2280_dma *td; |
| 3594 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3595 | td = pci_pool_alloc(dev->requests, GFP_KERNEL, |
| 3596 | &dev->ep[i].td_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | if (!td) { |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3598 | ep_dbg(dev, "can't get dummy %d\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | retval = -ENOMEM; |
| 3600 | goto done; |
| 3601 | } |
| 3602 | td->dmacount = 0; /* not VALID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | td->dmadesc = td->dmaaddr; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3604 | dev->ep[i].dummy = td; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | /* enable lower-overhead pci memory bursts during DMA */ |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3608 | if (dev->quirks & PLX_LEGACY) |
Ricardo Ribalda Delgado | 3e76fdc | 2014-05-20 18:30:05 +0200 | [diff] [blame] | 3609 | writel(BIT(DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE) | |
| 3610 | /* |
| 3611 | * 256 write retries may not be enough... |
| 3612 | BIT(PCI_RETRY_ABORT_ENABLE) | |
| 3613 | */ |
| 3614 | BIT(DMA_READ_MULTIPLE_ENABLE) | |
| 3615 | BIT(DMA_READ_LINE_ENABLE), |
| 3616 | &dev->pci->pcimstctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3618 | pci_set_master(pdev); |
| 3619 | pci_try_set_mwi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | |
| 3621 | /* ... also flushes any posted pci writes */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3622 | dev->chiprev = get_idx_reg(dev->regs, REG_CHIPREV) & 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | |
| 3624 | /* done */ |
Ricardo Ribalda Delgado | e56e69c | 2014-05-20 18:30:11 +0200 | [diff] [blame] | 3625 | ep_info(dev, "%s\n", driver_desc); |
| 3626 | ep_info(dev, "irq %d, pci mem %p, chip rev %04x\n", |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 3627 | pdev->irq, base, dev->chiprev); |
Ricardo Ribalda Delgado | d588ff5 | 2014-11-28 14:50:49 +0100 | [diff] [blame] | 3628 | ep_info(dev, "version: " DRIVER_VERSION "; %s\n", |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3629 | dev->enhanced_mode ? "enhanced mode" : "legacy mode"); |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3630 | retval = device_create_file(&pdev->dev, &dev_attr_registers); |
| 3631 | if (retval) |
| 3632 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | |
Felipe Balbi | 2901df6 | 2013-02-26 15:15:27 +0200 | [diff] [blame] | 3634 | retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, |
| 3635 | gadget_release); |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3636 | if (retval) |
| 3637 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | return 0; |
| 3639 | |
| 3640 | done: |
| 3641 | if (dev) |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3642 | net2280_remove(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | return retval; |
| 3644 | } |
| 3645 | |
Alan Stern | 2d61bde | 2006-05-05 16:23:42 -0400 | [diff] [blame] | 3646 | /* make sure the board is quiescent; otherwise it will continue |
| 3647 | * generating IRQs across the upcoming reboot. |
| 3648 | */ |
| 3649 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3650 | static void net2280_shutdown(struct pci_dev *pdev) |
Alan Stern | 2d61bde | 2006-05-05 16:23:42 -0400 | [diff] [blame] | 3651 | { |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3652 | struct net2280 *dev = pci_get_drvdata(pdev); |
Alan Stern | 2d61bde | 2006-05-05 16:23:42 -0400 | [diff] [blame] | 3653 | |
| 3654 | /* disable IRQs */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3655 | writel(0, &dev->regs->pciirqenb0); |
| 3656 | writel(0, &dev->regs->pciirqenb1); |
Alan Stern | 2d61bde | 2006-05-05 16:23:42 -0400 | [diff] [blame] | 3657 | |
| 3658 | /* disable the pullup so the host will think we're gone */ |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3659 | writel(0, &dev->usb->usbctl); |
Alan Stern | 2f07607 | 2013-01-30 16:40:14 -0500 | [diff] [blame] | 3660 | |
Alan Stern | 2d61bde | 2006-05-05 16:23:42 -0400 | [diff] [blame] | 3661 | } |
| 3662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | |
| 3664 | /*-------------------------------------------------------------------------*/ |
| 3665 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3666 | static const struct pci_device_id pci_ids[] = { { |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 3667 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), |
| 3668 | .class_mask = ~0, |
Ricardo Ribalda Delgado | c2db8a8 | 2014-05-20 18:30:04 +0200 | [diff] [blame] | 3669 | .vendor = PCI_VENDOR_ID_PLX_LEGACY, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | .device = 0x2280, |
| 3671 | .subvendor = PCI_ANY_ID, |
| 3672 | .subdevice = PCI_ANY_ID, |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3673 | .driver_data = PLX_LEGACY | PLX_2280, |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 3674 | }, { |
David Brownell | 901b3d7 | 2006-09-02 03:13:45 -0700 | [diff] [blame] | 3675 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), |
| 3676 | .class_mask = ~0, |
Ricardo Ribalda Delgado | c2db8a8 | 2014-05-20 18:30:04 +0200 | [diff] [blame] | 3677 | .vendor = PCI_VENDOR_ID_PLX_LEGACY, |
Guennadi Liakhovetski | 950ee4c | 2006-03-19 20:49:14 +0100 | [diff] [blame] | 3678 | .device = 0x2282, |
| 3679 | .subvendor = PCI_ANY_ID, |
| 3680 | .subdevice = PCI_ANY_ID, |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3681 | .driver_data = PLX_LEGACY, |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 3682 | }, |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3683 | { |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 3684 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), |
| 3685 | .class_mask = ~0, |
| 3686 | .vendor = PCI_VENDOR_ID_PLX, |
| 3687 | .device = 0x3380, |
| 3688 | .subvendor = PCI_ANY_ID, |
| 3689 | .subdevice = PCI_ANY_ID, |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3690 | .driver_data = PLX_SUPERSPEED, |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3691 | }, |
| 3692 | { |
Ricardo Ribalda Delgado | ae8e530 | 2014-05-20 18:30:10 +0200 | [diff] [blame] | 3693 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), |
| 3694 | .class_mask = ~0, |
| 3695 | .vendor = PCI_VENDOR_ID_PLX, |
| 3696 | .device = 0x3382, |
| 3697 | .subvendor = PCI_ANY_ID, |
| 3698 | .subdevice = PCI_ANY_ID, |
Ricardo Ribalda Delgado | 2eeb001 | 2014-05-20 18:30:12 +0200 | [diff] [blame] | 3699 | .driver_data = PLX_SUPERSPEED, |
Ricardo Ribalda Delgado | adc82f7 | 2014-05-20 18:30:03 +0200 | [diff] [blame] | 3700 | }, |
| 3701 | { /* end: all zeroes */ } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | }; |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3703 | MODULE_DEVICE_TABLE(pci, pci_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | |
| 3705 | /* pci driver glue; this is a "new style" PCI driver module */ |
| 3706 | static struct pci_driver net2280_pci_driver = { |
| 3707 | .name = (char *) driver_name, |
| 3708 | .id_table = pci_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | |
| 3710 | .probe = net2280_probe, |
| 3711 | .remove = net2280_remove, |
Alan Stern | 2d61bde | 2006-05-05 16:23:42 -0400 | [diff] [blame] | 3712 | .shutdown = net2280_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | |
| 3714 | /* FIXME add power management support */ |
| 3715 | }; |
| 3716 | |
Ricardo Ribalda Delgado | 9a028e4 | 2014-05-20 18:30:07 +0200 | [diff] [blame] | 3717 | module_pci_driver(net2280_pci_driver); |
| 3718 | |
Ricardo Ribalda Delgado | fae3c15 | 2014-05-20 18:30:09 +0200 | [diff] [blame] | 3719 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 3720 | MODULE_AUTHOR("David Brownell"); |
| 3721 | MODULE_LICENSE("GPL"); |