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