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