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