1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for the PLX NET2280 USB device controller.
4 * Specs and errata are available from <http://www.plxtech.com>.
6 * PLX Technology Inc. (formerly NetChip Technology) supported the
7 * development of this driver.
10 * CODE STATUS HIGHLIGHTS
12 * This driver should work well with most "gadget" drivers, including
13 * the Mass Storage, Serial, and Ethernet/RNDIS gadget drivers
14 * as well as Gadget Zero and Gadgetfs.
16 * DMA is enabled by default.
18 * MSI is enabled by default. The legacy IRQ is used if MSI couldn't
21 * Note that almost all the errata workarounds here are only needed for
22 * rev1 chips. Rev1a silicon (0110) fixes almost all of them.
26 * Copyright (C) 2003 David Brownell
27 * Copyright (C) 2003-2005 PLX Technology, Inc.
28 * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
30 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
33 * Modified Ricardo Ribalda Qtechnology AS to provide compatibility
34 * with usb 338x chip. Based on PLX driver
37 #include <linux/module.h>
38 #include <linux/pci.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/kernel.h>
41 #include <linux/delay.h>
42 #include <linux/ioport.h>
43 #include <linux/slab.h>
44 #include <linux/errno.h>
45 #include <linux/init.h>
46 #include <linux/timer.h>
47 #include <linux/list.h>
48 #include <linux/interrupt.h>
49 #include <linux/moduleparam.h>
50 #include <linux/device.h>
51 #include <linux/usb/ch9.h>
52 #include <linux/usb/gadget.h>
53 #include <linux/prefetch.h>
55 #include <linux/iopoll.h>
57 #include <asm/byteorder.h>
59 #include <asm/unaligned.h>
61 #define DRIVER_DESC "PLX NET228x/USB338x USB Peripheral Controller"
62 #define DRIVER_VERSION "2005 Sept 27/v3.0"
64 #define EP_DONTUSE 13 /* nonzero */
66 #define USE_RDK_LEDS /* GPIO pins control three LEDs */
69 static const char driver_name[] = "net2280";
70 static const char driver_desc[] = DRIVER_DESC;
72 static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };
73 static const char ep0name[] = "ep0";
75 #define EP_INFO(_name, _caps) \
83 const struct usb_ep_caps caps;
84 } ep_info_dft[] = { /* Default endpoint configuration */
86 USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
88 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
90 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
92 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
94 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
96 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
98 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
100 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
102 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
103 }, ep_info_adv[] = { /* Endpoints for usb3380 advance mode */
105 USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
107 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
109 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
111 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
113 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
115 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
117 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
119 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
121 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
126 /* mode 0 == ep-{a,b,c,d} 1K fifo each
127 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
128 * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
130 static ushort fifo_mode;
132 /* "modprobe net2280 fifo_mode=1" etc */
133 module_param(fifo_mode, ushort, 0644);
135 /* enable_suspend -- When enabled, the driver will respond to
136 * USB suspend requests by powering down the NET2280. Otherwise,
137 * USB suspend requests will be ignored. This is acceptable for
138 * self-powered devices
140 static bool enable_suspend;
142 /* "modprobe net2280 enable_suspend=1" etc */
143 module_param(enable_suspend, bool, 0444);
145 #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
147 static char *type_string(u8 bmAttributes)
149 switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
150 case USB_ENDPOINT_XFER_BULK: return "bulk";
151 case USB_ENDPOINT_XFER_ISOC: return "iso";
152 case USB_ENDPOINT_XFER_INT: return "intr";
159 #define valid_bit cpu_to_le32(BIT(VALID_BIT))
160 #define dma_done_ie cpu_to_le32(BIT(DMA_DONE_INTERRUPT_ENABLE))
162 static void ep_clear_seqnum(struct net2280_ep *ep);
163 static void stop_activity(struct net2280 *dev,
164 struct usb_gadget_driver *driver);
165 static void ep0_start(struct net2280 *dev);
167 /*-------------------------------------------------------------------------*/
168 static inline void enable_pciirqenb(struct net2280_ep *ep)
170 u32 tmp = readl(&ep->dev->regs->pciirqenb0);
172 if (ep->dev->quirks & PLX_LEGACY)
175 tmp |= BIT(ep_bit[ep->num]);
176 writel(tmp, &ep->dev->regs->pciirqenb0);
182 net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
185 struct net2280_ep *ep;
190 static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 };
193 ep = container_of(_ep, struct net2280_ep, ep);
194 if (!_ep || !desc || ep->desc || _ep->name == ep0name ||
195 desc->bDescriptorType != USB_DT_ENDPOINT) {
196 pr_err("%s: failed at line=%d\n", __func__, __LINE__);
200 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
205 /* erratum 0119 workaround ties up an endpoint number */
206 if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) {
211 if (dev->quirks & PLX_PCIE) {
212 if ((desc->bEndpointAddress & 0x0f) >= 0x0c) {
216 ep->is_in = !!usb_endpoint_dir_in(desc);
217 if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) {
223 /* sanity check ep-e/ep-f since their fifos are small */
224 max = usb_endpoint_maxp(desc);
225 if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) {
230 spin_lock_irqsave(&dev->lock, flags);
231 _ep->maxpacket = max;
234 /* ep_reset() has already been called */
237 ep->out_overflow = 0;
239 /* set speed-dependent max packet; may kick in high bandwidth */
240 set_max_speed(ep, max);
242 /* set type, direction, address; reset fifo counters */
243 writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
245 if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
246 tmp = readl(&ep->cfg->ep_cfg);
247 /* If USB ep number doesn't match hardware ep number */
248 if ((tmp & 0xf) != usb_endpoint_num(desc)) {
250 spin_unlock_irqrestore(&dev->lock, flags);
254 tmp &= ~USB3380_EP_CFG_MASK_IN;
256 tmp &= ~USB3380_EP_CFG_MASK_OUT;
258 type = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
259 if (type == USB_ENDPOINT_XFER_INT) {
260 /* erratum 0105 workaround prevents hs NYET */
261 if (dev->chiprev == 0100 &&
262 dev->gadget.speed == USB_SPEED_HIGH &&
263 !(desc->bEndpointAddress & USB_DIR_IN))
264 writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE),
266 } else if (type == USB_ENDPOINT_XFER_BULK) {
267 /* catch some particularly blatant driver bugs */
268 if ((dev->gadget.speed == USB_SPEED_SUPER && max != 1024) ||
269 (dev->gadget.speed == USB_SPEED_HIGH && max != 512) ||
270 (dev->gadget.speed == USB_SPEED_FULL && max > 64)) {
271 spin_unlock_irqrestore(&dev->lock, flags);
276 ep->is_iso = (type == USB_ENDPOINT_XFER_ISOC);
277 /* Enable this endpoint */
278 if (dev->quirks & PLX_LEGACY) {
279 tmp |= type << ENDPOINT_TYPE;
280 tmp |= desc->bEndpointAddress;
281 /* default full fifo lines */
282 tmp |= (4 << ENDPOINT_BYTE_COUNT);
283 tmp |= BIT(ENDPOINT_ENABLE);
284 ep->is_in = (tmp & USB_DIR_IN) != 0;
286 /* In Legacy mode, only OUT endpoints are used */
287 if (dev->enhanced_mode && ep->is_in) {
288 tmp |= type << IN_ENDPOINT_TYPE;
289 tmp |= BIT(IN_ENDPOINT_ENABLE);
291 tmp |= type << OUT_ENDPOINT_TYPE;
292 tmp |= BIT(OUT_ENDPOINT_ENABLE);
293 tmp |= (ep->is_in << ENDPOINT_DIRECTION);
296 tmp |= (4 << ENDPOINT_BYTE_COUNT);
297 if (!dev->enhanced_mode)
298 tmp |= usb_endpoint_num(desc);
299 tmp |= (ep->ep.maxburst << MAX_BURST_SIZE);
302 /* Make sure all the registers are written before ep_rsp*/
305 /* for OUT transfers, block the rx fifo until a read is posted */
307 writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
308 else if (!(dev->quirks & PLX_2280)) {
309 /* Added for 2282, Don't use nak packets on an in endpoint,
310 * this was ignored on 2280
312 writel(BIT(CLEAR_NAK_OUT_PACKETS) |
313 BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
316 if (dev->quirks & PLX_PCIE)
318 writel(tmp, &ep->cfg->ep_cfg);
321 if (!ep->dma) { /* pio, per-packet */
322 enable_pciirqenb(ep);
324 tmp = BIT(DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) |
325 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE);
326 if (dev->quirks & PLX_2280)
327 tmp |= readl(&ep->regs->ep_irqenb);
328 writel(tmp, &ep->regs->ep_irqenb);
329 } else { /* dma, per-request */
330 tmp = BIT((8 + ep->num)); /* completion */
331 tmp |= readl(&dev->regs->pciirqenb1);
332 writel(tmp, &dev->regs->pciirqenb1);
334 /* for short OUT transfers, dma completions can't
335 * advance the queue; do it pio-style, by hand.
336 * NOTE erratum 0112 workaround #2
338 if ((desc->bEndpointAddress & USB_DIR_IN) == 0) {
339 tmp = BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE);
340 writel(tmp, &ep->regs->ep_irqenb);
342 enable_pciirqenb(ep);
346 tmp = desc->bEndpointAddress;
347 ep_dbg(dev, "enabled %s (ep%d%s-%s) %s max %04x\n",
348 _ep->name, tmp & 0x0f, DIR_STRING(tmp),
349 type_string(desc->bmAttributes),
350 ep->dma ? "dma" : "pio", max);
352 /* pci writes may still be posted */
353 spin_unlock_irqrestore(&dev->lock, flags);
357 dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret);
361 static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec)
366 ret = readl_poll_timeout_atomic(ptr, result,
367 ((result & mask) == done ||
370 if (result == U32_MAX) /* device unplugged */
376 static const struct usb_ep_ops net2280_ep_ops;
378 static void ep_reset_228x(struct net2280_regs __iomem *regs,
379 struct net2280_ep *ep)
384 INIT_LIST_HEAD(&ep->queue);
386 usb_ep_set_maxpacket_limit(&ep->ep, ~0);
387 ep->ep.ops = &net2280_ep_ops;
389 /* disable the dma, irqs, endpoint... */
391 writel(0, &ep->dma->dmactl);
392 writel(BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
393 BIT(DMA_TRANSACTION_DONE_INTERRUPT) |
397 tmp = readl(®s->pciirqenb0);
398 tmp &= ~BIT(ep->num);
399 writel(tmp, ®s->pciirqenb0);
401 tmp = readl(®s->pciirqenb1);
402 tmp &= ~BIT((8 + ep->num)); /* completion */
403 writel(tmp, ®s->pciirqenb1);
405 writel(0, &ep->regs->ep_irqenb);
407 /* init to our chosen defaults, notably so that we NAK OUT
408 * packets until the driver queues a read (+note erratum 0112)
410 if (!ep->is_in || (ep->dev->quirks & PLX_2280)) {
411 tmp = BIT(SET_NAK_OUT_PACKETS_MODE) |
412 BIT(SET_NAK_OUT_PACKETS) |
413 BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
414 BIT(CLEAR_INTERRUPT_MODE);
417 tmp = BIT(CLEAR_NAK_OUT_PACKETS_MODE) |
418 BIT(CLEAR_NAK_OUT_PACKETS) |
419 BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
420 BIT(CLEAR_INTERRUPT_MODE);
424 tmp |= BIT(CLEAR_ENDPOINT_TOGGLE) |
425 BIT(CLEAR_ENDPOINT_HALT);
427 writel(tmp, &ep->regs->ep_rsp);
429 /* scrub most status bits, and flush any fifo state */
430 if (ep->dev->quirks & PLX_2280)
431 tmp = BIT(FIFO_OVERFLOW) |
436 writel(tmp | BIT(TIMEOUT) |
437 BIT(USB_STALL_SENT) |
438 BIT(USB_IN_NAK_SENT) |
439 BIT(USB_IN_ACK_RCVD) |
440 BIT(USB_OUT_PING_NAK_SENT) |
441 BIT(USB_OUT_ACK_SENT) |
443 BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
444 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
445 BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
446 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
447 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
448 BIT(DATA_IN_TOKEN_INTERRUPT),
451 /* fifo size is handled separately */
454 static void ep_reset_338x(struct net2280_regs __iomem *regs,
455 struct net2280_ep *ep)
460 INIT_LIST_HEAD(&ep->queue);
462 usb_ep_set_maxpacket_limit(&ep->ep, ~0);
463 ep->ep.ops = &net2280_ep_ops;
465 /* disable the dma, irqs, endpoint... */
467 writel(0, &ep->dma->dmactl);
468 writel(BIT(DMA_ABORT_DONE_INTERRUPT) |
469 BIT(DMA_PAUSE_DONE_INTERRUPT) |
470 BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
471 BIT(DMA_TRANSACTION_DONE_INTERRUPT),
472 /* | BIT(DMA_ABORT), */
475 dmastat = readl(&ep->dma->dmastat);
476 if (dmastat == 0x5002) {
477 ep_warn(ep->dev, "The dmastat return = %x!!\n",
479 writel(0x5a, &ep->dma->dmastat);
482 tmp = readl(®s->pciirqenb0);
483 tmp &= ~BIT(ep_bit[ep->num]);
484 writel(tmp, ®s->pciirqenb0);
487 tmp = readl(®s->pciirqenb1);
488 tmp &= ~BIT((8 + ep->num)); /* completion */
489 writel(tmp, ®s->pciirqenb1);
492 writel(0, &ep->regs->ep_irqenb);
494 writel(BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
495 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
497 BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
498 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
499 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
500 BIT(DATA_IN_TOKEN_INTERRUPT), &ep->regs->ep_stat);
502 tmp = readl(&ep->cfg->ep_cfg);
504 tmp &= ~USB3380_EP_CFG_MASK_IN;
506 tmp &= ~USB3380_EP_CFG_MASK_OUT;
507 writel(tmp, &ep->cfg->ep_cfg);
510 static void nuke(struct net2280_ep *);
512 static int net2280_disable(struct usb_ep *_ep)
514 struct net2280_ep *ep;
517 ep = container_of(_ep, struct net2280_ep, ep);
518 if (!_ep || _ep->name == ep0name) {
519 pr_err("%s: Invalid ep=%p\n", __func__, _ep);
522 spin_lock_irqsave(&ep->dev->lock, flags);
525 if (ep->dev->quirks & PLX_PCIE)
526 ep_reset_338x(ep->dev->regs, ep);
528 ep_reset_228x(ep->dev->regs, ep);
530 ep_vdbg(ep->dev, "disabled %s %s\n",
531 ep->dma ? "dma" : "pio", _ep->name);
533 /* synch memory views with the device */
534 (void)readl(&ep->cfg->ep_cfg);
536 if (!ep->dma && ep->num >= 1 && ep->num <= 4)
537 ep->dma = &ep->dev->dma[ep->num - 1];
539 spin_unlock_irqrestore(&ep->dev->lock, flags);
543 /*-------------------------------------------------------------------------*/
545 static struct usb_request
546 *net2280_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
548 struct net2280_ep *ep;
549 struct net2280_request *req;
552 pr_err("%s: Invalid ep\n", __func__);
555 ep = container_of(_ep, struct net2280_ep, ep);
557 req = kzalloc(sizeof(*req), gfp_flags);
561 INIT_LIST_HEAD(&req->queue);
563 /* this dma descriptor may be swapped with the previous dummy */
565 struct net2280_dma *td;
567 td = dma_pool_alloc(ep->dev->requests, gfp_flags,
573 td->dmacount = 0; /* not VALID */
574 td->dmadesc = td->dmaaddr;
580 static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req)
582 struct net2280_ep *ep;
583 struct net2280_request *req;
585 ep = container_of(_ep, struct net2280_ep, ep);
587 dev_err(&ep->dev->pdev->dev, "%s: Invalid ep=%p or req=%p\n",
588 __func__, _ep, _req);
592 req = container_of(_req, struct net2280_request, req);
593 WARN_ON(!list_empty(&req->queue));
595 dma_pool_free(ep->dev->requests, req->td, req->td_dma);
599 /*-------------------------------------------------------------------------*/
601 /* load a packet into the fifo we use for usb IN transfers.
602 * works for all endpoints.
604 * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
605 * at a time, but this code is simpler because it knows it only writes
606 * one packet. ep-a..ep-d should use dma instead.
608 static void write_fifo(struct net2280_ep *ep, struct usb_request *req)
610 struct net2280_ep_regs __iomem *regs = ep->regs;
613 unsigned count, total;
615 /* INVARIANT: fifo is currently empty. (testable) */
618 buf = req->buf + req->actual;
620 total = req->length - req->actual;
626 /* write just one packet at a time */
627 count = ep->ep.maxpacket;
628 if (count > total) /* min() cannot be used on a bitfield */
631 ep_vdbg(ep->dev, "write %s fifo (IN) %d bytes%s req %p\n",
633 (count != ep->ep.maxpacket) ? " (short)" : "",
636 /* NOTE be careful if you try to align these. fifo lines
637 * should normally be full (4 bytes) and successive partial
638 * lines are ok only in certain cases.
640 tmp = get_unaligned((u32 *)buf);
642 writel(tmp, ®s->ep_data);
647 /* last fifo entry is "short" unless we wrote a full packet.
648 * also explicitly validate last word in (periodic) transfers
649 * when maxpacket is not a multiple of 4 bytes.
651 if (count || total < ep->ep.maxpacket) {
652 tmp = count ? get_unaligned((u32 *)buf) : count;
654 set_fifo_bytecount(ep, count & 0x03);
655 writel(tmp, ®s->ep_data);
658 /* pci writes may still be posted */
661 /* work around erratum 0106: PCI and USB race over the OUT fifo.
662 * caller guarantees chiprev 0100, out endpoint is NAKing, and
663 * there's no real data in the fifo.
665 * NOTE: also used in cases where that erratum doesn't apply:
666 * where the host wrote "too much" data to us.
668 static void out_flush(struct net2280_ep *ep)
673 statp = &ep->regs->ep_stat;
676 if (tmp & BIT(NAK_OUT_PACKETS)) {
677 ep_dbg(ep->dev, "%s %s %08x !NAK\n",
678 ep->ep.name, __func__, tmp);
679 writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
682 writel(BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
683 BIT(DATA_PACKET_RECEIVED_INTERRUPT),
685 writel(BIT(FIFO_FLUSH), statp);
686 /* Make sure that stap is written */
689 if (tmp & BIT(DATA_OUT_PING_TOKEN_INTERRUPT) &&
690 /* high speed did bulk NYET; fifo isn't filling */
691 ep->dev->gadget.speed == USB_SPEED_FULL) {
694 usec = 50; /* 64 byte bulk/interrupt */
695 handshake(statp, BIT(USB_OUT_PING_NAK_SENT),
696 BIT(USB_OUT_PING_NAK_SENT), usec);
697 /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
701 /* unload packet(s) from the fifo we use for usb OUT transfers.
702 * returns true iff the request completed, because of short packet
703 * or the request buffer having filled with full packets.
705 * for ep-a..ep-d this will read multiple packets out when they
706 * have been accepted.
708 static int read_fifo(struct net2280_ep *ep, struct net2280_request *req)
710 struct net2280_ep_regs __iomem *regs = ep->regs;
711 u8 *buf = req->req.buf + req->req.actual;
712 unsigned count, tmp, is_short;
713 unsigned cleanup = 0, prevent = 0;
715 /* erratum 0106 ... packets coming in during fifo reads might
716 * be incompletely rejected. not all cases have workarounds.
718 if (ep->dev->chiprev == 0x0100 &&
719 ep->dev->gadget.speed == USB_SPEED_FULL) {
721 tmp = readl(&ep->regs->ep_stat);
722 if ((tmp & BIT(NAK_OUT_PACKETS)))
724 else if ((tmp & BIT(FIFO_FULL))) {
725 start_out_naking(ep);
728 /* else: hope we don't see the problem */
731 /* never overflow the rx buffer. the fifo reads packets until
732 * it sees a short one; we might not be ready for them all.
735 count = readl(®s->ep_avail);
736 if (unlikely(count == 0)) {
738 tmp = readl(&ep->regs->ep_stat);
739 count = readl(®s->ep_avail);
740 /* handled that data already? */
741 if (count == 0 && (tmp & BIT(NAK_OUT_PACKETS)) == 0)
745 tmp = req->req.length - req->req.actual;
747 /* as with DMA, data overflow gets flushed */
748 if ((tmp % ep->ep.maxpacket) != 0) {
750 "%s out fifo %d bytes, expected %d\n",
751 ep->ep.name, count, tmp);
752 req->req.status = -EOVERFLOW;
754 /* NAK_OUT_PACKETS will be set, so flushing is safe;
755 * the next read will start with the next packet
757 } /* else it's a ZLP, no worries */
760 req->req.actual += count;
762 is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0);
764 ep_vdbg(ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
765 ep->ep.name, count, is_short ? " (short)" : "",
766 cleanup ? " flush" : "", prevent ? " nak" : "",
767 req, req->req.actual, req->req.length);
770 tmp = readl(®s->ep_data);
772 put_unaligned(tmp, (u32 *)buf);
777 tmp = readl(®s->ep_data);
778 /* LE conversion is implicit here: */
787 writel(BIT(CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
788 (void) readl(&ep->regs->ep_rsp);
791 return is_short || req->req.actual == req->req.length;
794 /* fill out dma descriptor to match a given request */
795 static void fill_dma_desc(struct net2280_ep *ep,
796 struct net2280_request *req, int valid)
798 struct net2280_dma *td = req->td;
799 u32 dmacount = req->req.length;
801 /* don't let DMA continue after a short OUT packet,
802 * so overruns can't affect the next transfer.
803 * in case of overruns on max-size packets, we can't
804 * stop the fifo from filling but we can flush it.
807 dmacount |= BIT(DMA_DIRECTION);
808 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) ||
809 !(ep->dev->quirks & PLX_2280))
810 dmacount |= BIT(END_OF_CHAIN);
814 dmacount |= BIT(VALID_BIT);
815 dmacount |= BIT(DMA_DONE_INTERRUPT_ENABLE);
817 /* td->dmadesc = previously set by caller */
818 td->dmaaddr = cpu_to_le32 (req->req.dma);
820 /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
822 td->dmacount = cpu_to_le32(dmacount);
825 static const u32 dmactl_default =
826 BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
827 BIT(DMA_CLEAR_COUNT_ENABLE) |
828 /* erratum 0116 workaround part 1 (use POLLING) */
829 (POLL_100_USEC << DESCRIPTOR_POLLING_RATE) |
830 BIT(DMA_VALID_BIT_POLLING_ENABLE) |
831 BIT(DMA_VALID_BIT_ENABLE) |
832 BIT(DMA_SCATTER_GATHER_ENABLE) |
833 /* erratum 0116 workaround part 2 (no AUTOSTART) */
836 static inline void spin_stop_dma(struct net2280_dma_regs __iomem *dma)
838 handshake(&dma->dmactl, BIT(DMA_ENABLE), 0, 50);
841 static inline void stop_dma(struct net2280_dma_regs __iomem *dma)
843 writel(readl(&dma->dmactl) & ~BIT(DMA_ENABLE), &dma->dmactl);
847 static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma)
849 struct net2280_dma_regs __iomem *dma = ep->dma;
850 unsigned int tmp = BIT(VALID_BIT) | (ep->is_in << DMA_DIRECTION);
852 if (!(ep->dev->quirks & PLX_2280))
853 tmp |= BIT(END_OF_CHAIN);
855 writel(tmp, &dma->dmacount);
856 writel(readl(&dma->dmastat), &dma->dmastat);
858 writel(td_dma, &dma->dmadesc);
859 if (ep->dev->quirks & PLX_PCIE)
860 dmactl |= BIT(DMA_REQUEST_OUTSTANDING);
861 writel(dmactl, &dma->dmactl);
863 /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
864 (void) readl(&ep->dev->pci->pcimstctl);
866 writel(BIT(DMA_START), &dma->dmastat);
869 static void start_dma(struct net2280_ep *ep, struct net2280_request *req)
872 struct net2280_dma_regs __iomem *dma = ep->dma;
874 /* FIXME can't use DMA for ZLPs */
876 /* on this path we "know" there's no dma active (yet) */
877 WARN_ON(readl(&dma->dmactl) & BIT(DMA_ENABLE));
878 writel(0, &ep->dma->dmactl);
880 /* previous OUT packet might have been short */
881 if (!ep->is_in && (readl(&ep->regs->ep_stat) &
882 BIT(NAK_OUT_PACKETS))) {
883 writel(BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT),
886 tmp = readl(&ep->regs->ep_avail);
888 writel(readl(&dma->dmastat), &dma->dmastat);
890 /* transfer all/some fifo data */
891 writel(req->req.dma, &dma->dmaaddr);
892 tmp = min(tmp, req->req.length);
894 /* dma irq, faking scatterlist status */
895 req->td->dmacount = cpu_to_le32(req->req.length - tmp);
896 writel(BIT(DMA_DONE_INTERRUPT_ENABLE) | tmp,
898 req->td->dmadesc = 0;
901 writel(BIT(DMA_ENABLE), &dma->dmactl);
902 writel(BIT(DMA_START), &dma->dmastat);
908 tmp = dmactl_default;
910 /* force packet boundaries between dma requests, but prevent the
911 * controller from automagically writing a last "short" packet
912 * (zero length) unless the driver explicitly said to do that.
915 if (likely((req->req.length % ep->ep.maxpacket) ||
917 tmp |= BIT(DMA_FIFO_VALIDATE);
918 ep->in_fifo_validate = 1;
920 ep->in_fifo_validate = 0;
923 /* init req->td, pointing to the current dummy */
924 req->td->dmadesc = cpu_to_le32 (ep->td_dma);
925 fill_dma_desc(ep, req, 1);
927 req->td->dmacount |= cpu_to_le32(BIT(END_OF_CHAIN));
929 start_queue(ep, tmp, req->td_dma);
933 queue_dma(struct net2280_ep *ep, struct net2280_request *req, int valid)
935 struct net2280_dma *end;
938 /* swap new dummy for old, link; fill and maybe activate */
944 ep->td_dma = req->td_dma;
947 end->dmadesc = cpu_to_le32 (ep->td_dma);
949 fill_dma_desc(ep, req, valid);
953 done(struct net2280_ep *ep, struct net2280_request *req, int status)
956 unsigned stopped = ep->stopped;
958 list_del_init(&req->queue);
960 if (req->req.status == -EINPROGRESS)
961 req->req.status = status;
963 status = req->req.status;
967 usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in);
969 if (status && status != -ESHUTDOWN)
970 ep_vdbg(dev, "complete %s req %p stat %d len %u/%u\n",
971 ep->ep.name, &req->req, status,
972 req->req.actual, req->req.length);
974 /* don't modify queue heads during completion callback */
976 spin_unlock(&dev->lock);
977 usb_gadget_giveback_request(&ep->ep, &req->req);
978 spin_lock(&dev->lock);
979 ep->stopped = stopped;
982 /*-------------------------------------------------------------------------*/
985 net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
987 struct net2280_request *req;
988 struct net2280_ep *ep;
993 /* we always require a cpu-view buffer, so that we can
994 * always use pio (as fallback or whatever).
996 ep = container_of(_ep, struct net2280_ep, ep);
997 if (!_ep || (!ep->desc && ep->num != 0)) {
998 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1001 req = container_of(_req, struct net2280_request, req);
1002 if (!_req || !_req->complete || !_req->buf ||
1003 !list_empty(&req->queue)) {
1007 if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) {
1012 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
1017 /* FIXME implement PIO fallback for ZLPs with DMA */
1018 if (ep->dma && _req->length == 0) {
1023 /* set up dma mapping in case the caller didn't */
1025 ret = usb_gadget_map_request(&dev->gadget, _req,
1031 ep_vdbg(dev, "%s queue req %p, len %d buf %p\n",
1032 _ep->name, _req, _req->length, _req->buf);
1034 spin_lock_irqsave(&dev->lock, flags);
1036 _req->status = -EINPROGRESS;
1039 /* kickstart this i/o queue? */
1040 if (list_empty(&ep->queue) && !ep->stopped &&
1041 !((dev->quirks & PLX_PCIE) && ep->dma &&
1042 (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)))) {
1044 /* use DMA if the endpoint supports it, else pio */
1048 /* maybe there's no control data, just status ack */
1049 if (ep->num == 0 && _req->length == 0) {
1052 ep_vdbg(dev, "%s status ack\n", ep->ep.name);
1056 /* PIO ... stuff the fifo, or unblock it. */
1058 write_fifo(ep, _req);
1062 /* OUT FIFO might have packet(s) buffered */
1063 s = readl(&ep->regs->ep_stat);
1064 if ((s & BIT(FIFO_EMPTY)) == 0) {
1065 /* note: _req->short_not_ok is
1066 * ignored here since PIO _always_
1067 * stops queue advance here, and
1068 * _req->status doesn't change for
1069 * short reads (only _req->actual)
1071 if (read_fifo(ep, req) &&
1075 /* don't queue it */
1077 } else if (read_fifo(ep, req) &&
1082 s = readl(&ep->regs->ep_stat);
1085 /* don't NAK, let the fifo fill */
1086 if (req && (s & BIT(NAK_OUT_PACKETS)))
1087 writel(BIT(CLEAR_NAK_OUT_PACKETS),
1092 } else if (ep->dma) {
1098 /* preventing magic zlps is per-engine state, not
1099 * per-transfer; irq logic must recover hiccups.
1101 expect = likely(req->req.zero ||
1102 (req->req.length % ep->ep.maxpacket));
1103 if (expect != ep->in_fifo_validate)
1106 queue_dma(ep, req, valid);
1108 } /* else the irq handler advances the queue. */
1112 list_add_tail(&req->queue, &ep->queue);
1114 spin_unlock_irqrestore(&dev->lock, flags);
1116 /* pci writes may still be posted */
1120 dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret);
1125 dma_done(struct net2280_ep *ep, struct net2280_request *req, u32 dmacount,
1128 req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount);
1129 done(ep, req, status);
1132 static int scan_dma_completions(struct net2280_ep *ep)
1134 int num_completed = 0;
1136 /* only look at descriptors that were "naturally" retired,
1137 * so fifo and list head state won't matter
1139 while (!list_empty(&ep->queue)) {
1140 struct net2280_request *req;
1143 req = list_entry(ep->queue.next,
1144 struct net2280_request, queue);
1148 req_dma_count = le32_to_cpup(&req->td->dmacount);
1149 if ((req_dma_count & BIT(VALID_BIT)) != 0)
1152 /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
1153 * cases where DMA must be aborted; this code handles
1154 * all non-abort DMA completions.
1156 if (unlikely(req->td->dmadesc == 0)) {
1158 u32 const ep_dmacount = readl(&ep->dma->dmacount);
1160 if (ep_dmacount & DMA_BYTE_COUNT_MASK)
1162 /* single transfer mode */
1163 dma_done(ep, req, req_dma_count, 0);
1166 } else if (!ep->is_in &&
1167 (req->req.length % ep->ep.maxpacket) &&
1168 !(ep->dev->quirks & PLX_PCIE)) {
1170 u32 const ep_stat = readl(&ep->regs->ep_stat);
1171 /* AVOID TROUBLE HERE by not issuing short reads from
1172 * your gadget driver. That helps avoids errata 0121,
1173 * 0122, and 0124; not all cases trigger the warning.
1175 if ((ep_stat & BIT(NAK_OUT_PACKETS)) == 0) {
1176 ep_warn(ep->dev, "%s lost packet sync!\n",
1178 req->req.status = -EOVERFLOW;
1180 u32 const ep_avail = readl(&ep->regs->ep_avail);
1182 /* fifo gets flushed later */
1183 ep->out_overflow = 1;
1185 "%s dma, discard %d len %d\n",
1186 ep->ep.name, ep_avail,
1188 req->req.status = -EOVERFLOW;
1192 dma_done(ep, req, req_dma_count, 0);
1196 return num_completed;
1199 static void restart_dma(struct net2280_ep *ep)
1201 struct net2280_request *req;
1205 req = list_entry(ep->queue.next, struct net2280_request, queue);
1210 static void abort_dma(struct net2280_ep *ep)
1212 /* abort the current transfer */
1213 if (likely(!list_empty(&ep->queue))) {
1214 /* FIXME work around errata 0121, 0122, 0124 */
1215 writel(BIT(DMA_ABORT), &ep->dma->dmastat);
1216 spin_stop_dma(ep->dma);
1219 scan_dma_completions(ep);
1222 /* dequeue ALL requests */
1223 static void nuke(struct net2280_ep *ep)
1225 struct net2280_request *req;
1227 /* called with spinlock held */
1231 while (!list_empty(&ep->queue)) {
1232 req = list_entry(ep->queue.next,
1233 struct net2280_request,
1235 done(ep, req, -ESHUTDOWN);
1239 /* dequeue JUST ONE request */
1240 static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1242 struct net2280_ep *ep;
1243 struct net2280_request *req;
1244 unsigned long flags;
1248 ep = container_of(_ep, struct net2280_ep, ep);
1249 if (!_ep || (!ep->desc && ep->num != 0) || !_req) {
1250 pr_err("%s: Invalid ep=%p or ep->desc or req=%p\n",
1251 __func__, _ep, _req);
1255 spin_lock_irqsave(&ep->dev->lock, flags);
1256 stopped = ep->stopped;
1258 /* quiesce dma while we patch the queue */
1262 dmactl = readl(&ep->dma->dmactl);
1263 /* WARNING erratum 0127 may kick in ... */
1265 scan_dma_completions(ep);
1268 /* make sure it's still queued on this endpoint */
1269 list_for_each_entry(req, &ep->queue, queue) {
1270 if (&req->req == _req)
1273 if (&req->req != _req) {
1274 ep->stopped = stopped;
1275 spin_unlock_irqrestore(&ep->dev->lock, flags);
1276 ep_dbg(ep->dev, "%s: Request mismatch\n", __func__);
1280 /* queue head may be partially complete. */
1281 if (ep->queue.next == &req->queue) {
1283 ep_dbg(ep->dev, "unlink (%s) dma\n", _ep->name);
1284 _req->status = -ECONNRESET;
1286 if (likely(ep->queue.next == &req->queue)) {
1287 /* NOTE: misreports single-transfer mode*/
1288 req->td->dmacount = 0; /* invalidate */
1290 readl(&ep->dma->dmacount),
1294 ep_dbg(ep->dev, "unlink (%s) pio\n", _ep->name);
1295 done(ep, req, -ECONNRESET);
1301 done(ep, req, -ECONNRESET);
1302 ep->stopped = stopped;
1305 /* turn off dma on inactive queues */
1306 if (list_empty(&ep->queue))
1308 else if (!ep->stopped) {
1309 /* resume current request, or start new one */
1311 writel(dmactl, &ep->dma->dmactl);
1313 start_dma(ep, list_entry(ep->queue.next,
1314 struct net2280_request, queue));
1318 spin_unlock_irqrestore(&ep->dev->lock, flags);
1322 /*-------------------------------------------------------------------------*/
1324 static int net2280_fifo_status(struct usb_ep *_ep);
1327 net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
1329 struct net2280_ep *ep;
1330 unsigned long flags;
1333 ep = container_of(_ep, struct net2280_ep, ep);
1334 if (!_ep || (!ep->desc && ep->num != 0)) {
1335 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1338 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) {
1339 retval = -ESHUTDOWN;
1342 if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03)
1343 == USB_ENDPOINT_XFER_ISOC) {
1348 spin_lock_irqsave(&ep->dev->lock, flags);
1349 if (!list_empty(&ep->queue)) {
1352 } else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) {
1356 ep_vdbg(ep->dev, "%s %s %s\n", _ep->name,
1357 value ? "set" : "clear",
1358 wedged ? "wedge" : "halt");
1359 /* set/clear, then synch memory views with the device */
1362 ep->dev->protocol_stall = 1;
1369 if (ep->dev->quirks & PLX_PCIE &&
1370 !list_empty(&ep->queue) && ep->td_dma)
1374 (void) readl(&ep->regs->ep_rsp);
1376 spin_unlock_irqrestore(&ep->dev->lock, flags);
1381 spin_unlock_irqrestore(&ep->dev->lock, flags);
1383 dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, retval);
1387 static int net2280_set_halt(struct usb_ep *_ep, int value)
1389 return net2280_set_halt_and_wedge(_ep, value, 0);
1392 static int net2280_set_wedge(struct usb_ep *_ep)
1394 if (!_ep || _ep->name == ep0name) {
1395 pr_err("%s: Invalid ep=%p or ep0\n", __func__, _ep);
1398 return net2280_set_halt_and_wedge(_ep, 1, 1);
1401 static int net2280_fifo_status(struct usb_ep *_ep)
1403 struct net2280_ep *ep;
1406 ep = container_of(_ep, struct net2280_ep, ep);
1407 if (!_ep || (!ep->desc && ep->num != 0)) {
1408 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1411 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) {
1412 dev_err(&ep->dev->pdev->dev,
1413 "%s: Invalid driver=%p or speed=%d\n",
1414 __func__, ep->dev->driver, ep->dev->gadget.speed);
1418 avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1);
1419 if (avail > ep->fifo_size) {
1420 dev_err(&ep->dev->pdev->dev, "%s: Fifo overflow\n", __func__);
1424 avail = ep->fifo_size - avail;
1428 static void net2280_fifo_flush(struct usb_ep *_ep)
1430 struct net2280_ep *ep;
1432 ep = container_of(_ep, struct net2280_ep, ep);
1433 if (!_ep || (!ep->desc && ep->num != 0)) {
1434 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1437 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) {
1438 dev_err(&ep->dev->pdev->dev,
1439 "%s: Invalid driver=%p or speed=%d\n",
1440 __func__, ep->dev->driver, ep->dev->gadget.speed);
1444 writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
1445 (void) readl(&ep->regs->ep_rsp);
1448 static const struct usb_ep_ops net2280_ep_ops = {
1449 .enable = net2280_enable,
1450 .disable = net2280_disable,
1452 .alloc_request = net2280_alloc_request,
1453 .free_request = net2280_free_request,
1455 .queue = net2280_queue,
1456 .dequeue = net2280_dequeue,
1458 .set_halt = net2280_set_halt,
1459 .set_wedge = net2280_set_wedge,
1460 .fifo_status = net2280_fifo_status,
1461 .fifo_flush = net2280_fifo_flush,
1464 /*-------------------------------------------------------------------------*/
1466 static int net2280_get_frame(struct usb_gadget *_gadget)
1468 struct net2280 *dev;
1469 unsigned long flags;
1474 dev = container_of(_gadget, struct net2280, gadget);
1475 spin_lock_irqsave(&dev->lock, flags);
1476 retval = get_idx_reg(dev->regs, REG_FRAME) & 0x03ff;
1477 spin_unlock_irqrestore(&dev->lock, flags);
1481 static int net2280_wakeup(struct usb_gadget *_gadget)
1483 struct net2280 *dev;
1485 unsigned long flags;
1489 dev = container_of(_gadget, struct net2280, gadget);
1491 spin_lock_irqsave(&dev->lock, flags);
1492 tmp = readl(&dev->usb->usbctl);
1493 if (tmp & BIT(DEVICE_REMOTE_WAKEUP_ENABLE))
1494 writel(BIT(GENERATE_RESUME), &dev->usb->usbstat);
1495 spin_unlock_irqrestore(&dev->lock, flags);
1497 /* pci writes may still be posted */
1501 static int net2280_set_selfpowered(struct usb_gadget *_gadget, int value)
1503 struct net2280 *dev;
1505 unsigned long flags;
1509 dev = container_of(_gadget, struct net2280, gadget);
1511 spin_lock_irqsave(&dev->lock, flags);
1512 tmp = readl(&dev->usb->usbctl);
1514 tmp |= BIT(SELF_POWERED_STATUS);
1515 _gadget->is_selfpowered = 1;
1517 tmp &= ~BIT(SELF_POWERED_STATUS);
1518 _gadget->is_selfpowered = 0;
1520 writel(tmp, &dev->usb->usbctl);
1521 spin_unlock_irqrestore(&dev->lock, flags);
1526 static int net2280_pullup(struct usb_gadget *_gadget, int is_on)
1528 struct net2280 *dev;
1530 unsigned long flags;
1534 dev = container_of(_gadget, struct net2280, gadget);
1536 spin_lock_irqsave(&dev->lock, flags);
1537 tmp = readl(&dev->usb->usbctl);
1538 dev->softconnect = (is_on != 0);
1541 writel(tmp | BIT(USB_DETECT_ENABLE), &dev->usb->usbctl);
1543 writel(tmp & ~BIT(USB_DETECT_ENABLE), &dev->usb->usbctl);
1544 stop_activity(dev, NULL);
1547 spin_unlock_irqrestore(&dev->lock, flags);
1552 static struct usb_ep *net2280_match_ep(struct usb_gadget *_gadget,
1553 struct usb_endpoint_descriptor *desc,
1554 struct usb_ss_ep_comp_descriptor *ep_comp)
1559 if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT) {
1560 /* ep-e, ep-f are PIO with only 64 byte fifos */
1561 ep = gadget_find_ep_by_name(_gadget, "ep-e");
1562 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1564 ep = gadget_find_ep_by_name(_gadget, "ep-f");
1565 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1569 /* USB3380: Only first four endpoints have DMA channels. Allocate
1570 * slower interrupt endpoints from PIO hw endpoints, to allow bulk/isoc
1571 * endpoints use DMA hw endpoints.
1573 if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT &&
1574 usb_endpoint_dir_in(desc)) {
1575 ep = gadget_find_ep_by_name(_gadget, "ep2in");
1576 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1578 ep = gadget_find_ep_by_name(_gadget, "ep4in");
1579 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1581 } else if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT &&
1582 !usb_endpoint_dir_in(desc)) {
1583 ep = gadget_find_ep_by_name(_gadget, "ep1out");
1584 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1586 ep = gadget_find_ep_by_name(_gadget, "ep3out");
1587 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1589 } else if (usb_endpoint_type(desc) != USB_ENDPOINT_XFER_BULK &&
1590 usb_endpoint_dir_in(desc)) {
1591 ep = gadget_find_ep_by_name(_gadget, "ep1in");
1592 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1594 ep = gadget_find_ep_by_name(_gadget, "ep3in");
1595 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1597 } else if (usb_endpoint_type(desc) != USB_ENDPOINT_XFER_BULK &&
1598 !usb_endpoint_dir_in(desc)) {
1599 ep = gadget_find_ep_by_name(_gadget, "ep2out");
1600 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1602 ep = gadget_find_ep_by_name(_gadget, "ep4out");
1603 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1607 /* USB3380: use same address for usb and hardware endpoints */
1608 snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
1609 usb_endpoint_dir_in(desc) ? "in" : "out");
1610 ep = gadget_find_ep_by_name(_gadget, name);
1611 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1617 static int net2280_start(struct usb_gadget *_gadget,
1618 struct usb_gadget_driver *driver);
1619 static int net2280_stop(struct usb_gadget *_gadget);
1620 static void net2280_async_callbacks(struct usb_gadget *_gadget, bool enable);
1622 static const struct usb_gadget_ops net2280_ops = {
1623 .get_frame = net2280_get_frame,
1624 .wakeup = net2280_wakeup,
1625 .set_selfpowered = net2280_set_selfpowered,
1626 .pullup = net2280_pullup,
1627 .udc_start = net2280_start,
1628 .udc_stop = net2280_stop,
1629 .udc_async_callbacks = net2280_async_callbacks,
1630 .match_ep = net2280_match_ep,
1633 /*-------------------------------------------------------------------------*/
1635 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1637 /* FIXME move these into procfs, and use seq_file.
1638 * Sysfs _still_ doesn't behave for arbitrarily sized files,
1639 * and also doesn't help products using this with 2.4 kernels.
1642 /* "function" sysfs attribute */
1643 static ssize_t function_show(struct device *_dev, struct device_attribute *attr,
1646 struct net2280 *dev = dev_get_drvdata(_dev);
1648 if (!dev->driver || !dev->driver->function ||
1649 strlen(dev->driver->function) > PAGE_SIZE)
1651 return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->function);
1653 static DEVICE_ATTR_RO(function);
1655 static ssize_t registers_show(struct device *_dev,
1656 struct device_attribute *attr, char *buf)
1658 struct net2280 *dev;
1661 unsigned long flags;
1666 dev = dev_get_drvdata(_dev);
1669 spin_lock_irqsave(&dev->lock, flags);
1672 s = dev->driver->driver.name;
1676 /* Main Control Registers */
1677 t = scnprintf(next, size, "%s version " DRIVER_VERSION
1678 ", chiprev %04x\n\n"
1679 "devinit %03x fifoctl %08x gadget '%s'\n"
1680 "pci irqenb0 %02x irqenb1 %08x "
1681 "irqstat0 %04x irqstat1 %08x\n",
1682 driver_name, dev->chiprev,
1683 readl(&dev->regs->devinit),
1684 readl(&dev->regs->fifoctl),
1686 readl(&dev->regs->pciirqenb0),
1687 readl(&dev->regs->pciirqenb1),
1688 readl(&dev->regs->irqstat0),
1689 readl(&dev->regs->irqstat1));
1693 /* USB Control Registers */
1694 t1 = readl(&dev->usb->usbctl);
1695 t2 = readl(&dev->usb->usbstat);
1696 if (t1 & BIT(VBUS_PIN)) {
1697 if (t2 & BIT(HIGH_SPEED))
1699 else if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1703 /* full speed bit (6) not working?? */
1706 t = scnprintf(next, size,
1707 "stdrsp %08x usbctl %08x usbstat %08x "
1708 "addr 0x%02x (%s)\n",
1709 readl(&dev->usb->stdrsp), t1, t2,
1710 readl(&dev->usb->ouraddr), s);
1714 /* PCI Master Control Registers */
1716 /* DMA Control Registers */
1718 /* Configurable EP Control Registers */
1719 for (i = 0; i < dev->n_ep; i++) {
1720 struct net2280_ep *ep;
1726 t1 = readl(&ep->cfg->ep_cfg);
1727 t2 = readl(&ep->regs->ep_rsp) & 0xff;
1728 t = scnprintf(next, size,
1729 "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
1731 ep->ep.name, t1, t2,
1732 (t2 & BIT(CLEAR_NAK_OUT_PACKETS))
1734 (t2 & BIT(CLEAR_EP_HIDE_STATUS_PHASE))
1736 (t2 & BIT(CLEAR_EP_FORCE_CRC_ERROR))
1738 (t2 & BIT(CLEAR_INTERRUPT_MODE))
1739 ? "interrupt " : "",
1740 (t2 & BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE))
1742 (t2 & BIT(CLEAR_NAK_OUT_PACKETS_MODE))
1744 (t2 & BIT(CLEAR_ENDPOINT_TOGGLE))
1745 ? "DATA1 " : "DATA0 ",
1746 (t2 & BIT(CLEAR_ENDPOINT_HALT))
1748 readl(&ep->regs->ep_irqenb));
1752 t = scnprintf(next, size,
1753 "\tstat %08x avail %04x "
1755 readl(&ep->regs->ep_stat),
1756 readl(&ep->regs->ep_avail),
1757 t1 & 0x0f, DIR_STRING(t1),
1758 type_string(t1 >> 8),
1759 ep->stopped ? "*" : "");
1766 t = scnprintf(next, size,
1767 " dma\tctl %08x stat %08x count %08x\n"
1768 "\taddr %08x desc %08x\n",
1769 readl(&ep->dma->dmactl),
1770 readl(&ep->dma->dmastat),
1771 readl(&ep->dma->dmacount),
1772 readl(&ep->dma->dmaaddr),
1773 readl(&ep->dma->dmadesc));
1779 /* Indexed Registers (none yet) */
1782 t = scnprintf(next, size, "\nirqs: ");
1785 for (i = 0; i < dev->n_ep; i++) {
1786 struct net2280_ep *ep;
1791 t = scnprintf(next, size, " %s/%lu", ep->ep.name, ep->irqs);
1796 t = scnprintf(next, size, "\n");
1800 spin_unlock_irqrestore(&dev->lock, flags);
1802 return PAGE_SIZE - size;
1804 static DEVICE_ATTR_RO(registers);
1806 static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
1809 struct net2280 *dev;
1812 unsigned long flags;
1815 dev = dev_get_drvdata(_dev);
1818 spin_lock_irqsave(&dev->lock, flags);
1820 for (i = 0; i < dev->n_ep; i++) {
1821 struct net2280_ep *ep = &dev->ep[i];
1822 struct net2280_request *req;
1826 const struct usb_endpoint_descriptor *d;
1831 t = d->bEndpointAddress;
1832 t = scnprintf(next, size,
1833 "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
1834 ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK,
1835 (t & USB_DIR_IN) ? "in" : "out",
1836 type_string(d->bmAttributes),
1837 usb_endpoint_maxp(d),
1838 ep->dma ? "dma" : "pio", ep->fifo_size
1840 } else /* ep0 should only have one transfer queued */
1841 t = scnprintf(next, size, "ep0 max 64 pio %s\n",
1842 ep->is_in ? "in" : "out");
1843 if (t <= 0 || t > size)
1848 if (list_empty(&ep->queue)) {
1849 t = scnprintf(next, size, "\t(nothing queued)\n");
1850 if (t <= 0 || t > size)
1856 list_for_each_entry(req, &ep->queue, queue) {
1857 if (ep->dma && req->td_dma == readl(&ep->dma->dmadesc))
1858 t = scnprintf(next, size,
1859 "\treq %p len %d/%d "
1860 "buf %p (dmacount %08x)\n",
1861 &req->req, req->req.actual,
1862 req->req.length, req->req.buf,
1863 readl(&ep->dma->dmacount));
1865 t = scnprintf(next, size,
1866 "\treq %p len %d/%d buf %p\n",
1867 &req->req, req->req.actual,
1868 req->req.length, req->req.buf);
1869 if (t <= 0 || t > size)
1875 struct net2280_dma *td;
1878 t = scnprintf(next, size, "\t td %08x "
1879 " count %08x buf %08x desc %08x\n",
1881 le32_to_cpu(td->dmacount),
1882 le32_to_cpu(td->dmaaddr),
1883 le32_to_cpu(td->dmadesc));
1884 if (t <= 0 || t > size)
1893 spin_unlock_irqrestore(&dev->lock, flags);
1894 return PAGE_SIZE - size;
1896 static DEVICE_ATTR_RO(queues);
1901 #define device_create_file(a, b) (0)
1902 #define device_remove_file(a, b) do { } while (0)
1906 /*-------------------------------------------------------------------------*/
1908 /* another driver-specific mode might be a request type doing dma
1909 * to/from another device fifo instead of to/from memory.
1912 static void set_fifo_mode(struct net2280 *dev, int mode)
1914 /* keeping high bits preserves BAR2 */
1915 writel((0xffff << PCI_BASE2_RANGE) | mode, &dev->regs->fifoctl);
1917 /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */
1918 INIT_LIST_HEAD(&dev->gadget.ep_list);
1919 list_add_tail(&dev->ep[1].ep.ep_list, &dev->gadget.ep_list);
1920 list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list);
1923 list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list);
1924 list_add_tail(&dev->ep[4].ep.ep_list, &dev->gadget.ep_list);
1925 dev->ep[1].fifo_size = dev->ep[2].fifo_size = 1024;
1928 dev->ep[1].fifo_size = dev->ep[2].fifo_size = 2048;
1931 list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list);
1932 dev->ep[1].fifo_size = 2048;
1933 dev->ep[2].fifo_size = 1024;
1936 /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */
1937 list_add_tail(&dev->ep[5].ep.ep_list, &dev->gadget.ep_list);
1938 list_add_tail(&dev->ep[6].ep.ep_list, &dev->gadget.ep_list);
1941 static void defect7374_disable_data_eps(struct net2280 *dev)
1944 * For Defect 7374, disable data EPs (and more):
1945 * - This phase undoes the earlier phase of the Defect 7374 workaround,
1946 * returing ep regs back to normal.
1948 struct net2280_ep *ep;
1950 unsigned char ep_sel;
1953 for (i = 1; i < 5; i++) {
1955 writel(i, &ep->cfg->ep_cfg);
1958 /* CSROUT, CSRIN, PCIOUT, PCIIN, STATIN, RCIN */
1959 for (i = 0; i < 6; i++)
1960 writel(0, &dev->dep[i].dep_cfg);
1962 for (ep_sel = 0; ep_sel <= 21; ep_sel++) {
1963 /* Select an endpoint for subsequent operations: */
1964 tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1965 writel(((tmp_reg & ~0x1f) | ep_sel), &dev->plregs->pl_ep_ctrl);
1967 if (ep_sel < 2 || (ep_sel > 9 && ep_sel < 14) ||
1968 ep_sel == 18 || ep_sel == 20)
1971 /* Change settings on some selected endpoints */
1972 tmp_reg = readl(&dev->plregs->pl_ep_cfg_4);
1973 tmp_reg &= ~BIT(NON_CTRL_IN_TOLERATE_BAD_DIR);
1974 writel(tmp_reg, &dev->plregs->pl_ep_cfg_4);
1975 tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1976 tmp_reg |= BIT(EP_INITIALIZED);
1977 writel(tmp_reg, &dev->plregs->pl_ep_ctrl);
1981 static void defect7374_enable_data_eps_zero(struct net2280 *dev)
1983 u32 tmp = 0, tmp_reg;
1986 unsigned char ep_sel;
1988 scratch = get_idx_reg(dev->regs, SCRATCH);
1990 WARN_ON((scratch & (0xf << DEFECT7374_FSM_FIELD))
1991 == DEFECT7374_FSM_SS_CONTROL_READ);
1993 scratch &= ~(0xf << DEFECT7374_FSM_FIELD);
1995 ep_warn(dev, "Operate Defect 7374 workaround soft this time");
1996 ep_warn(dev, "It will operate on cold-reboot and SS connect");
1999 tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_DIRECTION) |
2000 (2 << OUT_ENDPOINT_TYPE) | (2 << IN_ENDPOINT_TYPE) |
2001 ((dev->enhanced_mode) ?
2002 BIT(OUT_ENDPOINT_ENABLE) | BIT(IN_ENDPOINT_ENABLE) :
2003 BIT(ENDPOINT_ENABLE)));
2005 for (i = 1; i < 5; i++)
2006 writel(tmp, &dev->ep[i].cfg->ep_cfg);
2008 /* CSRIN, PCIIN, STATIN, RCIN*/
2009 tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_ENABLE));
2010 writel(tmp, &dev->dep[1].dep_cfg);
2011 writel(tmp, &dev->dep[3].dep_cfg);
2012 writel(tmp, &dev->dep[4].dep_cfg);
2013 writel(tmp, &dev->dep[5].dep_cfg);
2015 /*Implemented for development and debug.
2016 * Can be refined/tuned later.*/
2017 for (ep_sel = 0; ep_sel <= 21; ep_sel++) {
2018 /* Select an endpoint for subsequent operations: */
2019 tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
2020 writel(((tmp_reg & ~0x1f) | ep_sel),
2021 &dev->plregs->pl_ep_ctrl);
2025 (readl(&dev->plregs->pl_ep_ctrl) |
2026 BIT(CLEAR_ACK_ERROR_CODE) | 0);
2027 writel(tmp, &dev->plregs->pl_ep_ctrl);
2031 if (ep_sel == 0 || (ep_sel > 9 && ep_sel < 14) ||
2032 ep_sel == 18 || ep_sel == 20)
2035 tmp = (readl(&dev->plregs->pl_ep_cfg_4) |
2036 BIT(NON_CTRL_IN_TOLERATE_BAD_DIR) | 0);
2037 writel(tmp, &dev->plregs->pl_ep_cfg_4);
2039 tmp = readl(&dev->plregs->pl_ep_ctrl) &
2040 ~BIT(EP_INITIALIZED);
2041 writel(tmp, &dev->plregs->pl_ep_ctrl);
2045 /* Set FSM to focus on the first Control Read:
2046 * - Tip: Connection speed is known upon the first
2048 scratch |= DEFECT7374_FSM_WAITING_FOR_CONTROL_READ;
2049 set_idx_reg(dev->regs, SCRATCH, scratch);
2053 /* keeping it simple:
2054 * - one bus driver, initted first;
2055 * - one function driver, initted second
2057 * most of the work to support multiple net2280 controllers would
2058 * be to associate this gadget driver (yes?) with all of them, or
2059 * perhaps to bind specific drivers to specific devices.
2062 static void usb_reset_228x(struct net2280 *dev)
2066 dev->gadget.speed = USB_SPEED_UNKNOWN;
2067 (void) readl(&dev->usb->usbctl);
2069 net2280_led_init(dev);
2071 /* disable automatic responses, and irqs */
2072 writel(0, &dev->usb->stdrsp);
2073 writel(0, &dev->regs->pciirqenb0);
2074 writel(0, &dev->regs->pciirqenb1);
2076 /* clear old dma and irq state */
2077 for (tmp = 0; tmp < 4; tmp++) {
2078 struct net2280_ep *ep = &dev->ep[tmp + 1];
2083 writel(~0, &dev->regs->irqstat0),
2084 writel(~(u32)BIT(SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1),
2086 /* reset, and enable pci */
2087 tmp = readl(&dev->regs->devinit) |
2089 BIT(FIFO_SOFT_RESET) |
2090 BIT(USB_SOFT_RESET) |
2092 writel(tmp, &dev->regs->devinit);
2094 /* standard fifo and endpoint allocations */
2095 set_fifo_mode(dev, (fifo_mode <= 2) ? fifo_mode : 0);
2098 static void usb_reset_338x(struct net2280 *dev)
2102 dev->gadget.speed = USB_SPEED_UNKNOWN;
2103 (void)readl(&dev->usb->usbctl);
2105 net2280_led_init(dev);
2107 if (dev->bug7734_patched) {
2108 /* disable automatic responses, and irqs */
2109 writel(0, &dev->usb->stdrsp);
2110 writel(0, &dev->regs->pciirqenb0);
2111 writel(0, &dev->regs->pciirqenb1);
2114 /* clear old dma and irq state */
2115 for (tmp = 0; tmp < 4; tmp++) {
2116 struct net2280_ep *ep = &dev->ep[tmp + 1];
2117 struct net2280_dma_regs __iomem *dma;
2122 dma = &dev->dma[tmp];
2123 writel(BIT(DMA_ABORT), &dma->dmastat);
2124 writel(0, &dma->dmactl);
2128 writel(~0, &dev->regs->irqstat0), writel(~0, &dev->regs->irqstat1);
2130 if (dev->bug7734_patched) {
2131 /* reset, and enable pci */
2132 tmp = readl(&dev->regs->devinit) |
2134 BIT(FIFO_SOFT_RESET) |
2135 BIT(USB_SOFT_RESET) |
2138 writel(tmp, &dev->regs->devinit);
2141 /* always ep-{1,2,3,4} ... maybe not ep-3 or ep-4 */
2142 INIT_LIST_HEAD(&dev->gadget.ep_list);
2144 for (tmp = 1; tmp < dev->n_ep; tmp++)
2145 list_add_tail(&dev->ep[tmp].ep.ep_list, &dev->gadget.ep_list);
2149 static void usb_reset(struct net2280 *dev)
2151 if (dev->quirks & PLX_LEGACY)
2152 return usb_reset_228x(dev);
2153 return usb_reset_338x(dev);
2156 static void usb_reinit_228x(struct net2280 *dev)
2160 /* basic endpoint init */
2161 for (tmp = 0; tmp < 7; tmp++) {
2162 struct net2280_ep *ep = &dev->ep[tmp];
2164 ep->ep.name = ep_info_dft[tmp].name;
2165 ep->ep.caps = ep_info_dft[tmp].caps;
2169 if (tmp > 0 && tmp <= 4) {
2170 ep->fifo_size = 1024;
2171 ep->dma = &dev->dma[tmp - 1];
2174 ep->regs = &dev->epregs[tmp];
2175 ep->cfg = &dev->epregs[tmp];
2176 ep_reset_228x(dev->regs, ep);
2178 usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64);
2179 usb_ep_set_maxpacket_limit(&dev->ep[5].ep, 64);
2180 usb_ep_set_maxpacket_limit(&dev->ep[6].ep, 64);
2182 dev->gadget.ep0 = &dev->ep[0].ep;
2183 dev->ep[0].stopped = 0;
2184 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
2186 /* we want to prevent lowlevel/insecure access from the USB host,
2187 * but erratum 0119 means this enable bit is ignored
2189 for (tmp = 0; tmp < 5; tmp++)
2190 writel(EP_DONTUSE, &dev->dep[tmp].dep_cfg);
2193 static void usb_reinit_338x(struct net2280 *dev)
2197 static const u32 ne[9] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };
2198 static const u32 ep_reg_addr[9] = { 0x00, 0xC0, 0x00, 0xC0, 0x00,
2199 0x00, 0xC0, 0x00, 0xC0 };
2201 /* basic endpoint init */
2202 for (i = 0; i < dev->n_ep; i++) {
2203 struct net2280_ep *ep = &dev->ep[i];
2205 ep->ep.name = dev->enhanced_mode ? ep_info_adv[i].name :
2206 ep_info_dft[i].name;
2207 ep->ep.caps = dev->enhanced_mode ? ep_info_adv[i].caps :
2208 ep_info_dft[i].caps;
2212 if (i > 0 && i <= 4)
2213 ep->dma = &dev->dma[i - 1];
2215 if (dev->enhanced_mode) {
2216 ep->cfg = &dev->epregs[ne[i]];
2218 * Set USB endpoint number, hardware allows same number
2219 * in both directions.
2222 writel(ne[i], &ep->cfg->ep_cfg);
2223 ep->regs = (struct net2280_ep_regs __iomem *)
2224 (((void __iomem *)&dev->epregs[ne[i]]) +
2227 ep->cfg = &dev->epregs[i];
2228 ep->regs = &dev->epregs[i];
2231 ep->fifo_size = (i != 0) ? 2048 : 512;
2233 ep_reset_338x(dev->regs, ep);
2235 usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 512);
2237 dev->gadget.ep0 = &dev->ep[0].ep;
2238 dev->ep[0].stopped = 0;
2240 /* Link layer set up */
2241 if (dev->bug7734_patched) {
2242 tmp = readl(&dev->usb_ext->usbctl2) &
2243 ~(BIT(U1_ENABLE) | BIT(U2_ENABLE) | BIT(LTM_ENABLE));
2244 writel(tmp, &dev->usb_ext->usbctl2);
2247 /* Hardware Defect and Workaround */
2248 val = readl(&dev->llregs->ll_lfps_5);
2249 val &= ~(0xf << TIMER_LFPS_6US);
2250 val |= 0x5 << TIMER_LFPS_6US;
2251 writel(val, &dev->llregs->ll_lfps_5);
2253 val = readl(&dev->llregs->ll_lfps_6);
2254 val &= ~(0xffff << TIMER_LFPS_80US);
2255 val |= 0x0100 << TIMER_LFPS_80US;
2256 writel(val, &dev->llregs->ll_lfps_6);
2259 * AA_AB Errata. Issue 4. Workaround for SuperSpeed USB
2260 * Hot Reset Exit Handshake may Fail in Specific Case using
2261 * Default Register Settings. Workaround for Enumeration test.
2263 val = readl(&dev->llregs->ll_tsn_counters_2);
2264 val &= ~(0x1f << HOT_TX_NORESET_TS2);
2265 val |= 0x10 << HOT_TX_NORESET_TS2;
2266 writel(val, &dev->llregs->ll_tsn_counters_2);
2268 val = readl(&dev->llregs->ll_tsn_counters_3);
2269 val &= ~(0x1f << HOT_RX_RESET_TS2);
2270 val |= 0x3 << HOT_RX_RESET_TS2;
2271 writel(val, &dev->llregs->ll_tsn_counters_3);
2274 * AB errata. Errata 11. Workaround for Default Duration of LFPS
2275 * Handshake Signaling for Device-Initiated U1 Exit is too short.
2276 * Without this, various enumeration failures observed with
2277 * modern superspeed hosts.
2279 val = readl(&dev->llregs->ll_lfps_timers_2);
2280 writel((val & 0xffff0000) | LFPS_TIMERS_2_WORKAROUND_VALUE,
2281 &dev->llregs->ll_lfps_timers_2);
2284 * Set Recovery Idle to Recover bit:
2285 * - On SS connections, setting Recovery Idle to Recover Fmw improves
2286 * link robustness with various hosts and hubs.
2287 * - It is safe to set for all connection speeds; all chip revisions.
2288 * - R-M-W to leave other bits undisturbed.
2289 * - Reference PLX TT-7372
2291 val = readl(&dev->llregs->ll_tsn_chicken_bit);
2292 val |= BIT(RECOVERY_IDLE_TO_RECOVER_FMW);
2293 writel(val, &dev->llregs->ll_tsn_chicken_bit);
2295 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
2297 /* disable dedicated endpoints */
2298 writel(0x0D, &dev->dep[0].dep_cfg);
2299 writel(0x0D, &dev->dep[1].dep_cfg);
2300 writel(0x0E, &dev->dep[2].dep_cfg);
2301 writel(0x0E, &dev->dep[3].dep_cfg);
2302 writel(0x0F, &dev->dep[4].dep_cfg);
2303 writel(0x0C, &dev->dep[5].dep_cfg);
2306 static void usb_reinit(struct net2280 *dev)
2308 if (dev->quirks & PLX_LEGACY)
2309 return usb_reinit_228x(dev);
2310 return usb_reinit_338x(dev);
2313 static void ep0_start_228x(struct net2280 *dev)
2315 writel(BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
2316 BIT(CLEAR_NAK_OUT_PACKETS) |
2317 BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE),
2318 &dev->epregs[0].ep_rsp);
2321 * hardware optionally handles a bunch of standard requests
2322 * that the API hides from drivers anyway. have it do so.
2323 * endpoint status/features are handled in software, to
2324 * help pass tests for some dubious behavior.
2326 writel(BIT(SET_TEST_MODE) |
2328 BIT(DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP) |
2329 BIT(GET_DEVICE_STATUS) |
2330 BIT(GET_INTERFACE_STATUS),
2332 writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) |
2333 BIT(SELF_POWERED_USB_DEVICE) |
2334 BIT(REMOTE_WAKEUP_SUPPORT) |
2335 (dev->softconnect << USB_DETECT_ENABLE) |
2336 BIT(SELF_POWERED_STATUS),
2339 /* enable irqs so we can see ep0 and general operation */
2340 writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) |
2341 BIT(ENDPOINT_0_INTERRUPT_ENABLE),
2342 &dev->regs->pciirqenb0);
2343 writel(BIT(PCI_INTERRUPT_ENABLE) |
2344 BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE) |
2345 BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE) |
2346 BIT(PCI_RETRY_ABORT_INTERRUPT_ENABLE) |
2347 BIT(VBUS_INTERRUPT_ENABLE) |
2348 BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) |
2349 BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE),
2350 &dev->regs->pciirqenb1);
2352 /* don't leave any writes posted */
2353 (void) readl(&dev->usb->usbctl);
2356 static void ep0_start_338x(struct net2280 *dev)
2359 if (dev->bug7734_patched)
2360 writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE) |
2361 BIT(SET_EP_HIDE_STATUS_PHASE),
2362 &dev->epregs[0].ep_rsp);
2365 * hardware optionally handles a bunch of standard requests
2366 * that the API hides from drivers anyway. have it do so.
2367 * endpoint status/features are handled in software, to
2368 * help pass tests for some dubious behavior.
2370 writel(BIT(SET_ISOCHRONOUS_DELAY) |
2372 BIT(SET_TEST_MODE) |
2374 BIT(GET_INTERFACE_STATUS) |
2375 BIT(GET_DEVICE_STATUS),
2377 dev->wakeup_enable = 1;
2378 writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) |
2379 (dev->softconnect << USB_DETECT_ENABLE) |
2380 BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
2383 /* enable irqs so we can see ep0 and general operation */
2384 writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) |
2385 BIT(ENDPOINT_0_INTERRUPT_ENABLE),
2386 &dev->regs->pciirqenb0);
2387 writel(BIT(PCI_INTERRUPT_ENABLE) |
2388 BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) |
2389 BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE) |
2390 BIT(VBUS_INTERRUPT_ENABLE),
2391 &dev->regs->pciirqenb1);
2393 /* don't leave any writes posted */
2394 (void)readl(&dev->usb->usbctl);
2397 static void ep0_start(struct net2280 *dev)
2399 if (dev->quirks & PLX_LEGACY)
2400 return ep0_start_228x(dev);
2401 return ep0_start_338x(dev);
2404 /* when a driver is successfully registered, it will receive
2405 * control requests including set_configuration(), which enables
2406 * non-control requests. then usb traffic follows until a
2407 * disconnect is reported. then a host may connect again, or
2408 * the driver might get unbound.
2410 static int net2280_start(struct usb_gadget *_gadget,
2411 struct usb_gadget_driver *driver)
2413 struct net2280 *dev;
2417 /* insist on high speed support from the driver, since
2418 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
2419 * "must not be used in normal operation"
2421 if (!driver || driver->max_speed < USB_SPEED_HIGH ||
2425 dev = container_of(_gadget, struct net2280, gadget);
2427 for (i = 0; i < dev->n_ep; i++)
2428 dev->ep[i].irqs = 0;
2430 /* hook up the driver ... */
2431 driver->driver.bus = NULL;
2432 dev->driver = driver;
2434 retval = device_create_file(&dev->pdev->dev, &dev_attr_function);
2437 retval = device_create_file(&dev->pdev->dev, &dev_attr_queues);
2441 /* enable host detection and ep0; and we're ready
2442 * for set_configuration as well as eventual disconnect.
2444 net2280_led_active(dev, 1);
2446 if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
2447 defect7374_enable_data_eps_zero(dev);
2451 /* pci writes may still be posted */
2455 device_remove_file(&dev->pdev->dev, &dev_attr_function);
2461 static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver)
2465 /* don't disconnect if it's not connected */
2466 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
2469 /* stop hardware; prevent new request submissions;
2470 * and kill any outstanding requests.
2473 for (i = 0; i < dev->n_ep; i++)
2476 /* report disconnect; the driver is already quiesced */
2477 if (dev->async_callbacks && driver) {
2478 spin_unlock(&dev->lock);
2479 driver->disconnect(&dev->gadget);
2480 spin_lock(&dev->lock);
2486 static int net2280_stop(struct usb_gadget *_gadget)
2488 struct net2280 *dev;
2489 unsigned long flags;
2491 dev = container_of(_gadget, struct net2280, gadget);
2493 spin_lock_irqsave(&dev->lock, flags);
2494 stop_activity(dev, NULL);
2495 spin_unlock_irqrestore(&dev->lock, flags);
2497 net2280_led_active(dev, 0);
2499 device_remove_file(&dev->pdev->dev, &dev_attr_function);
2500 device_remove_file(&dev->pdev->dev, &dev_attr_queues);
2507 static void net2280_async_callbacks(struct usb_gadget *_gadget, bool enable)
2509 struct net2280 *dev = container_of(_gadget, struct net2280, gadget);
2511 spin_lock_irq(&dev->lock);
2512 dev->async_callbacks = enable;
2513 spin_unlock_irq(&dev->lock);
2516 /*-------------------------------------------------------------------------*/
2518 /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
2519 * also works for dma-capable endpoints, in pio mode or just
2520 * to manually advance the queue after short OUT transfers.
2522 static void handle_ep_small(struct net2280_ep *ep)
2524 struct net2280_request *req;
2526 /* 0 error, 1 mid-data, 2 done */
2529 if (!list_empty(&ep->queue))
2530 req = list_entry(ep->queue.next,
2531 struct net2280_request, queue);
2535 /* ack all, and handle what we care about */
2536 t = readl(&ep->regs->ep_stat);
2539 ep_vdbg(ep->dev, "%s ack ep_stat %08x, req %p\n",
2540 ep->ep.name, t, req ? &req->req : NULL);
2542 if (!ep->is_in || (ep->dev->quirks & PLX_2280))
2543 writel(t & ~BIT(NAK_OUT_PACKETS), &ep->regs->ep_stat);
2545 /* Added for 2282 */
2546 writel(t, &ep->regs->ep_stat);
2548 /* for ep0, monitor token irqs to catch data stage length errors
2549 * and to synchronize on status.
2551 * also, to defer reporting of protocol stalls ... here's where
2552 * data or status first appears, handling stalls here should never
2553 * cause trouble on the host side..
2555 * control requests could be slightly faster without token synch for
2556 * status, but status can jam up that way.
2558 if (unlikely(ep->num == 0)) {
2560 /* status; stop NAKing */
2561 if (t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) {
2562 if (ep->dev->protocol_stall) {
2569 /* reply to extra IN data tokens with a zlp */
2570 } else if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) {
2571 if (ep->dev->protocol_stall) {
2575 } else if (ep->responded &&
2576 !req && !ep->stopped)
2577 write_fifo(ep, NULL);
2580 /* status; stop NAKing */
2581 if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) {
2582 if (ep->dev->protocol_stall) {
2587 /* an extra OUT token is an error */
2588 } else if (((t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) &&
2590 req->req.actual == req->req.length) ||
2591 (ep->responded && !req)) {
2592 ep->dev->protocol_stall = 1;
2596 done(ep, req, -EOVERFLOW);
2605 /* manual DMA queue advance after short OUT */
2606 if (likely(ep->dma)) {
2607 if (t & BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
2608 struct net2280_request *stuck_req = NULL;
2609 int stopped = ep->stopped;
2614 /* TRANSFERRED works around OUT_DONE erratum 0112.
2615 * we expect (N <= maxpacket) bytes; host wrote M.
2616 * iff (M < N) we won't ever see a DMA interrupt.
2619 for (count = 0; ; t = readl(&ep->regs->ep_stat)) {
2621 /* any preceding dma transfers must finish.
2622 * dma handles (M >= N), may empty the queue
2624 num_completed = scan_dma_completions(ep);
2625 if (unlikely(list_empty(&ep->queue) ||
2626 ep->out_overflow)) {
2630 req = list_entry(ep->queue.next,
2631 struct net2280_request, queue);
2633 /* here either (M < N), a "real" short rx;
2634 * or (M == N) and the queue didn't empty
2636 if (likely(t & BIT(FIFO_EMPTY))) {
2637 count = readl(&ep->dma->dmacount);
2638 count &= DMA_BYTE_COUNT_MASK;
2639 if (readl(&ep->dma->dmadesc)
2645 /* Escape loop if no dma transfers completed
2646 * after few retries.
2648 if (num_completed == 0) {
2649 if (stuck_req == req &&
2650 readl(&ep->dma->dmadesc) !=
2651 req->td_dma && stuck++ > 5) {
2653 &ep->dma->dmacount);
2654 count &= DMA_BYTE_COUNT_MASK;
2656 ep_dbg(ep->dev, "%s escape stuck %d, count %u\n",
2660 } else if (stuck_req != req) {
2672 /* stop DMA, leave ep NAKing */
2673 writel(BIT(DMA_ABORT), &ep->dma->dmastat);
2674 spin_stop_dma(ep->dma);
2677 req->td->dmacount = 0;
2678 t = readl(&ep->regs->ep_avail);
2679 dma_done(ep, req, count,
2680 (ep->out_overflow || t)
2684 /* also flush to prevent erratum 0106 trouble */
2685 if (unlikely(ep->out_overflow ||
2686 (ep->dev->chiprev == 0x0100 &&
2687 ep->dev->gadget.speed
2688 == USB_SPEED_FULL))) {
2690 ep->out_overflow = 0;
2693 /* (re)start dma if needed, stop NAKing */
2694 ep->stopped = stopped;
2695 if (!list_empty(&ep->queue))
2698 ep_dbg(ep->dev, "%s dma ep_stat %08x ??\n",
2702 /* data packet(s) received (in the fifo, OUT) */
2703 } else if (t & BIT(DATA_PACKET_RECEIVED_INTERRUPT)) {
2704 if (read_fifo(ep, req) && ep->num != 0)
2707 /* data packet(s) transmitted (IN) */
2708 } else if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT)) {
2711 len = req->req.length - req->req.actual;
2712 if (len > ep->ep.maxpacket)
2713 len = ep->ep.maxpacket;
2714 req->req.actual += len;
2716 /* if we wrote it all, we're usually done */
2717 /* send zlps until the status stage */
2718 if ((req->req.actual == req->req.length) &&
2719 (!req->req.zero || len != ep->ep.maxpacket) && ep->num)
2722 /* there was nothing to do ... */
2723 } else if (mode == 1)
2728 /* stream endpoints often resubmit/unlink in completion */
2731 /* maybe advance queue to next request */
2733 /* NOTE: net2280 could let gadget driver start the
2734 * status stage later. since not all controllers let
2735 * them control that, the api doesn't (yet) allow it.
2741 if (!list_empty(&ep->queue) && !ep->stopped)
2742 req = list_entry(ep->queue.next,
2743 struct net2280_request, queue);
2746 if (req && !ep->is_in)
2747 stop_out_naking(ep);
2751 /* is there a buffer for the next packet?
2752 * for best streaming performance, make sure there is one.
2754 if (req && !ep->stopped) {
2756 /* load IN fifo with next packet (may be zlp) */
2757 if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT))
2758 write_fifo(ep, &req->req);
2762 static struct net2280_ep *get_ep_by_addr(struct net2280 *dev, u16 wIndex)
2764 struct net2280_ep *ep;
2766 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
2768 list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) {
2769 u8 bEndpointAddress;
2773 bEndpointAddress = ep->desc->bEndpointAddress;
2774 if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
2776 if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f))
2782 static void defect7374_workaround(struct net2280 *dev, struct usb_ctrlrequest r)
2784 u32 scratch, fsmvalue;
2785 u32 ack_wait_timeout, state;
2787 /* Workaround for Defect 7374 (U1/U2 erroneously rejected): */
2788 scratch = get_idx_reg(dev->regs, SCRATCH);
2789 fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD);
2790 scratch &= ~(0xf << DEFECT7374_FSM_FIELD);
2792 if (!((fsmvalue == DEFECT7374_FSM_WAITING_FOR_CONTROL_READ) &&
2793 (r.bRequestType & USB_DIR_IN)))
2796 /* This is the first Control Read for this connection: */
2797 if (!(readl(&dev->usb->usbstat) & BIT(SUPER_SPEED_MODE))) {
2799 * Connection is NOT SS:
2800 * - Connection must be FS or HS.
2801 * - This FSM state should allow workaround software to
2802 * run after the next USB connection.
2804 scratch |= DEFECT7374_FSM_NON_SS_CONTROL_READ;
2805 dev->bug7734_patched = 1;
2806 goto restore_data_eps;
2809 /* Connection is SS: */
2810 for (ack_wait_timeout = 0;
2811 ack_wait_timeout < DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS;
2812 ack_wait_timeout++) {
2814 state = readl(&dev->plregs->pl_ep_status_1)
2816 if ((state >= (ACK_GOOD_NORMAL << STATE)) &&
2817 (state <= (ACK_GOOD_MORE_ACKS_TO_COME << STATE))) {
2818 scratch |= DEFECT7374_FSM_SS_CONTROL_READ;
2819 dev->bug7734_patched = 1;
2824 * We have not yet received host's Data Phase ACK
2825 * - Wait and try again.
2827 udelay(DEFECT_7374_PROCESSOR_WAIT_TIME);
2831 if (ack_wait_timeout >= DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS) {
2832 ep_err(dev, "FAIL: Defect 7374 workaround waited but failed "
2833 "to detect SS host's data phase ACK.");
2834 ep_err(dev, "PL_EP_STATUS_1(23:16):.Expected from 0x11 to 0x16"
2835 "got 0x%2.2x.\n", state >> STATE);
2837 ep_warn(dev, "INFO: Defect 7374 workaround waited about\n"
2838 "%duSec for Control Read Data Phase ACK\n",
2839 DEFECT_7374_PROCESSOR_WAIT_TIME * ack_wait_timeout);
2844 * Restore data EPs to their pre-workaround settings (disabled,
2845 * initialized, and other details).
2847 defect7374_disable_data_eps(dev);
2849 set_idx_reg(dev->regs, SCRATCH, scratch);
2854 static void ep_clear_seqnum(struct net2280_ep *ep)
2856 struct net2280 *dev = ep->dev;
2858 static const u32 ep_pl[9] = { 0, 3, 4, 7, 8, 2, 5, 6, 9 };
2860 val = readl(&dev->plregs->pl_ep_ctrl) & ~0x1f;
2861 val |= ep_pl[ep->num];
2862 writel(val, &dev->plregs->pl_ep_ctrl);
2863 val |= BIT(SEQUENCE_NUMBER_RESET);
2864 writel(val, &dev->plregs->pl_ep_ctrl);
2869 static void handle_stat0_irqs_superspeed(struct net2280 *dev,
2870 struct net2280_ep *ep, struct usb_ctrlrequest r)
2872 struct net2280_ep *e;
2876 #define w_value le16_to_cpu(r.wValue)
2877 #define w_index le16_to_cpu(r.wIndex)
2878 #define w_length le16_to_cpu(r.wLength)
2880 switch (r.bRequest) {
2881 case USB_REQ_SET_CONFIGURATION:
2882 dev->addressed_state = !w_value;
2885 case USB_REQ_GET_STATUS:
2886 switch (r.bRequestType) {
2887 case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2888 status = dev->wakeup_enable ? 0x02 : 0x00;
2889 if (dev->gadget.is_selfpowered)
2891 status |= (dev->u1_enable << 2 | dev->u2_enable << 3 |
2892 dev->ltm_enable << 4);
2893 writel(0, &dev->epregs[0].ep_irqenb);
2894 set_fifo_bytecount(ep, sizeof(status));
2895 writel((__force u32) status, &dev->epregs[0].ep_data);
2896 allow_status_338x(ep);
2899 case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2900 e = get_ep_by_addr(dev, w_index);
2903 status = readl(&e->regs->ep_rsp) &
2904 BIT(CLEAR_ENDPOINT_HALT);
2905 writel(0, &dev->epregs[0].ep_irqenb);
2906 set_fifo_bytecount(ep, sizeof(status));
2907 writel((__force u32) status, &dev->epregs[0].ep_data);
2908 allow_status_338x(ep);
2916 case USB_REQ_CLEAR_FEATURE:
2917 switch (r.bRequestType) {
2918 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2919 if (!dev->addressed_state) {
2921 case USB_DEVICE_U1_ENABLE:
2923 writel(readl(&dev->usb_ext->usbctl2) &
2925 &dev->usb_ext->usbctl2);
2926 allow_status_338x(ep);
2927 goto next_endpoints3;
2929 case USB_DEVICE_U2_ENABLE:
2931 writel(readl(&dev->usb_ext->usbctl2) &
2933 &dev->usb_ext->usbctl2);
2934 allow_status_338x(ep);
2935 goto next_endpoints3;
2937 case USB_DEVICE_LTM_ENABLE:
2938 dev->ltm_enable = 0;
2939 writel(readl(&dev->usb_ext->usbctl2) &
2941 &dev->usb_ext->usbctl2);
2942 allow_status_338x(ep);
2943 goto next_endpoints3;
2949 if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
2950 dev->wakeup_enable = 0;
2951 writel(readl(&dev->usb->usbctl) &
2952 ~BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
2954 allow_status_338x(ep);
2959 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2960 e = get_ep_by_addr(dev, w_index);
2963 if (w_value != USB_ENDPOINT_HALT)
2965 ep_vdbg(dev, "%s clear halt\n", e->ep.name);
2967 * Workaround for SS SeqNum not cleared via
2968 * Endpoint Halt (Clear) bit. select endpoint
2972 if (!list_empty(&e->queue) && e->td_dma)
2982 case USB_REQ_SET_FEATURE:
2983 switch (r.bRequestType) {
2984 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2985 if (!dev->addressed_state) {
2987 case USB_DEVICE_U1_ENABLE:
2989 writel(readl(&dev->usb_ext->usbctl2) |
2991 &dev->usb_ext->usbctl2);
2992 allow_status_338x(ep);
2993 goto next_endpoints3;
2995 case USB_DEVICE_U2_ENABLE:
2997 writel(readl(&dev->usb_ext->usbctl2) |
2999 &dev->usb_ext->usbctl2);
3000 allow_status_338x(ep);
3001 goto next_endpoints3;
3003 case USB_DEVICE_LTM_ENABLE:
3004 dev->ltm_enable = 1;
3005 writel(readl(&dev->usb_ext->usbctl2) |
3007 &dev->usb_ext->usbctl2);
3008 allow_status_338x(ep);
3009 goto next_endpoints3;
3015 if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
3016 dev->wakeup_enable = 1;
3017 writel(readl(&dev->usb->usbctl) |
3018 BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
3020 allow_status_338x(ep);
3025 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
3026 e = get_ep_by_addr(dev, w_index);
3027 if (!e || (w_value != USB_ENDPOINT_HALT))
3031 ep->dev->protocol_stall = 1;
3037 allow_status_338x(ep);
3048 ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x ep_cfg %08x\n",
3049 r.bRequestType, r.bRequest,
3050 w_value, w_index, w_length,
3051 readl(&ep->cfg->ep_cfg));
3054 if (dev->async_callbacks) {
3055 spin_unlock(&dev->lock);
3056 tmp = dev->driver->setup(&dev->gadget, &r);
3057 spin_lock(&dev->lock);
3062 ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n",
3063 r.bRequestType, r.bRequest, tmp);
3064 dev->protocol_stall = 1;
3065 /* TD 9.9 Halt Endpoint test. TD 9.22 Set feature test */
3078 static void usb338x_handle_ep_intr(struct net2280 *dev, u32 stat0)
3083 for (index = 0; index < ARRAY_SIZE(ep_bit); index++) {
3084 bit = BIT(ep_bit[index]);
3094 handle_ep_small(&dev->ep[index]);
3098 static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
3100 struct net2280_ep *ep;
3103 /* most of these don't need individual acks */
3104 stat &= ~BIT(INTA_ASSERTED);
3107 /* ep_dbg(dev, "irqstat0 %04x\n", stat); */
3109 /* starting a control request? */
3110 if (unlikely(stat & BIT(SETUP_PACKET_INTERRUPT))) {
3113 struct usb_ctrlrequest r;
3116 struct net2280_request *req;
3118 if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
3119 u32 val = readl(&dev->usb->usbstat);
3120 if (val & BIT(SUPER_SPEED)) {
3121 dev->gadget.speed = USB_SPEED_SUPER;
3122 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3123 EP0_SS_MAX_PACKET_SIZE);
3124 } else if (val & BIT(HIGH_SPEED)) {
3125 dev->gadget.speed = USB_SPEED_HIGH;
3126 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3127 EP0_HS_MAX_PACKET_SIZE);
3129 dev->gadget.speed = USB_SPEED_FULL;
3130 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3131 EP0_HS_MAX_PACKET_SIZE);
3133 net2280_led_speed(dev, dev->gadget.speed);
3135 usb_speed_string(dev->gadget.speed));
3141 /* make sure any leftover request state is cleared */
3142 stat &= ~BIT(ENDPOINT_0_INTERRUPT);
3143 while (!list_empty(&ep->queue)) {
3144 req = list_entry(ep->queue.next,
3145 struct net2280_request, queue);
3146 done(ep, req, (req->req.actual == req->req.length)
3150 dev->protocol_stall = 0;
3151 if (!(dev->quirks & PLX_PCIE)) {
3152 if (ep->dev->quirks & PLX_2280)
3153 tmp = BIT(FIFO_OVERFLOW) |
3154 BIT(FIFO_UNDERFLOW);
3158 writel(tmp | BIT(TIMEOUT) |
3159 BIT(USB_STALL_SENT) |
3160 BIT(USB_IN_NAK_SENT) |
3161 BIT(USB_IN_ACK_RCVD) |
3162 BIT(USB_OUT_PING_NAK_SENT) |
3163 BIT(USB_OUT_ACK_SENT) |
3164 BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
3165 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
3166 BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
3167 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
3168 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3169 BIT(DATA_IN_TOKEN_INTERRUPT),
3170 &ep->regs->ep_stat);
3172 u.raw[0] = readl(&dev->usb->setup0123);
3173 u.raw[1] = readl(&dev->usb->setup4567);
3175 cpu_to_le32s(&u.raw[0]);
3176 cpu_to_le32s(&u.raw[1]);
3178 if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
3179 defect7374_workaround(dev, u.r);
3183 #define w_value le16_to_cpu(u.r.wValue)
3184 #define w_index le16_to_cpu(u.r.wIndex)
3185 #define w_length le16_to_cpu(u.r.wLength)
3188 writel(BIT(SETUP_PACKET_INTERRUPT), &dev->regs->irqstat0);
3189 stat ^= BIT(SETUP_PACKET_INTERRUPT);
3191 /* watch control traffic at the token level, and force
3192 * synchronization before letting the status stage happen.
3193 * FIXME ignore tokens we'll NAK, until driver responds.
3194 * that'll mean a lot less irqs for some drivers.
3196 ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0;
3198 scratch = BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
3199 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3200 BIT(DATA_IN_TOKEN_INTERRUPT);
3201 stop_out_naking(ep);
3203 scratch = BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
3204 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3205 BIT(DATA_IN_TOKEN_INTERRUPT);
3206 writel(scratch, &dev->epregs[0].ep_irqenb);
3208 /* we made the hardware handle most lowlevel requests;
3209 * everything else goes uplevel to the gadget code.
3213 if (dev->gadget.speed == USB_SPEED_SUPER) {
3214 handle_stat0_irqs_superspeed(dev, ep, u.r);
3215 goto next_endpoints;
3218 switch (u.r.bRequest) {
3219 case USB_REQ_GET_STATUS: {
3220 struct net2280_ep *e;
3223 /* hw handles device and interface status */
3224 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
3226 e = get_ep_by_addr(dev, w_index);
3227 if (!e || w_length > 2)
3230 if (readl(&e->regs->ep_rsp) & BIT(SET_ENDPOINT_HALT))
3231 status = cpu_to_le32(1);
3233 status = cpu_to_le32(0);
3235 /* don't bother with a request object! */
3236 writel(0, &dev->epregs[0].ep_irqenb);
3237 set_fifo_bytecount(ep, w_length);
3238 writel((__force u32)status, &dev->epregs[0].ep_data);
3240 ep_vdbg(dev, "%s stat %02x\n", ep->ep.name, status);
3241 goto next_endpoints;
3244 case USB_REQ_CLEAR_FEATURE: {
3245 struct net2280_ep *e;
3247 /* hw handles device features */
3248 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
3250 if (w_value != USB_ENDPOINT_HALT || w_length != 0)
3252 e = get_ep_by_addr(dev, w_index);
3256 ep_vdbg(dev, "%s wedged, halt not cleared\n",
3259 ep_vdbg(dev, "%s clear halt\n", e->ep.name);
3261 if ((ep->dev->quirks & PLX_PCIE) &&
3262 !list_empty(&e->queue) && e->td_dma)
3266 goto next_endpoints;
3269 case USB_REQ_SET_FEATURE: {
3270 struct net2280_ep *e;
3272 /* hw handles device features */
3273 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
3275 if (w_value != USB_ENDPOINT_HALT || w_length != 0)
3277 e = get_ep_by_addr(dev, w_index);
3280 if (e->ep.name == ep0name)
3283 if ((dev->quirks & PLX_PCIE) && e->dma)
3286 ep_vdbg(dev, "%s set halt\n", ep->ep.name);
3287 goto next_endpoints;
3292 ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x "
3294 u.r.bRequestType, u.r.bRequest,
3295 w_value, w_index, w_length,
3296 readl(&ep->cfg->ep_cfg));
3298 if (dev->async_callbacks) {
3299 spin_unlock(&dev->lock);
3300 tmp = dev->driver->setup(&dev->gadget, &u.r);
3301 spin_lock(&dev->lock);
3305 /* stall ep0 on error */
3308 ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n",
3309 u.r.bRequestType, u.r.bRequest, tmp);
3310 dev->protocol_stall = 1;
3313 /* some in/out token irq should follow; maybe stall then.
3314 * driver must queue a request (even zlp) or halt ep0
3315 * before the host times out.
3324 if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
3325 u32 mask = (BIT(ENDPOINT_0_INTERRUPT) |
3326 USB3380_IRQSTAT0_EP_INTR_MASK_IN |
3327 USB3380_IRQSTAT0_EP_INTR_MASK_OUT);
3330 usb338x_handle_ep_intr(dev, stat & mask);
3334 /* endpoint data irq ? */
3335 scratch = stat & 0x7f;
3337 for (num = 0; scratch; num++) {
3340 /* do this endpoint's FIFO and queue need tending? */
3342 if ((scratch & t) == 0)
3347 handle_ep_small(ep);
3352 ep_dbg(dev, "unhandled irqstat0 %08x\n", stat);
3355 #define DMA_INTERRUPTS (BIT(DMA_D_INTERRUPT) | \
3356 BIT(DMA_C_INTERRUPT) | \
3357 BIT(DMA_B_INTERRUPT) | \
3358 BIT(DMA_A_INTERRUPT))
3359 #define PCI_ERROR_INTERRUPTS ( \
3360 BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT) | \
3361 BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT) | \
3362 BIT(PCI_RETRY_ABORT_INTERRUPT))
3364 static void handle_stat1_irqs(struct net2280 *dev, u32 stat)
3365 __releases(dev->lock)
3366 __acquires(dev->lock)
3368 struct net2280_ep *ep;
3369 u32 tmp, num, mask, scratch;
3371 /* after disconnect there's nothing else to do! */
3372 tmp = BIT(VBUS_INTERRUPT) | BIT(ROOT_PORT_RESET_INTERRUPT);
3373 mask = BIT(SUPER_SPEED) | BIT(HIGH_SPEED) | BIT(FULL_SPEED);
3375 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
3376 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and
3377 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
3378 * only indicates a change in the reset state).
3382 bool disconnect = false;
3385 * Ignore disconnects and resets if the speed hasn't been set.
3386 * VBUS can bounce and there's always an initial reset.
3388 writel(tmp, &dev->regs->irqstat1);
3389 if (dev->gadget.speed != USB_SPEED_UNKNOWN) {
3390 if ((stat & BIT(VBUS_INTERRUPT)) &&
3391 (readl(&dev->usb->usbctl) &
3392 BIT(VBUS_PIN)) == 0) {
3394 ep_dbg(dev, "disconnect %s\n",
3395 dev->driver->driver.name);
3396 } else if ((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) &&
3397 (readl(&dev->usb->usbstat) & mask)
3400 ep_dbg(dev, "reset %s\n",
3401 dev->driver->driver.name);
3404 if (disconnect || reset) {
3405 stop_activity(dev, dev->driver);
3407 if (dev->async_callbacks) {
3408 spin_unlock(&dev->lock);
3410 usb_gadget_udc_reset(&dev->gadget, dev->driver);
3412 (dev->driver->disconnect)(&dev->gadget);
3413 spin_lock(&dev->lock);
3420 /* vBUS can bounce ... one of many reasons to ignore the
3421 * notion of hotplug events on bus connect/disconnect!
3427 /* NOTE: chip stays in PCI D0 state for now, but it could
3428 * enter D1 to save more power
3430 tmp = BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT);
3432 writel(tmp, &dev->regs->irqstat1);
3433 spin_unlock(&dev->lock);
3434 if (stat & BIT(SUSPEND_REQUEST_INTERRUPT)) {
3435 if (dev->async_callbacks && dev->driver->suspend)
3436 dev->driver->suspend(&dev->gadget);
3437 if (!enable_suspend)
3438 stat &= ~BIT(SUSPEND_REQUEST_INTERRUPT);
3440 if (dev->async_callbacks && dev->driver->resume)
3441 dev->driver->resume(&dev->gadget);
3442 /* at high speed, note erratum 0133 */
3444 spin_lock(&dev->lock);
3448 /* clear any other status/irqs */
3450 writel(stat, &dev->regs->irqstat1);
3452 /* some status we can just ignore */
3453 if (dev->quirks & PLX_2280)
3454 stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) |
3455 BIT(SUSPEND_REQUEST_INTERRUPT) |
3456 BIT(RESUME_INTERRUPT) |
3457 BIT(SOF_INTERRUPT));
3459 stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) |
3460 BIT(RESUME_INTERRUPT) |
3461 BIT(SOF_DOWN_INTERRUPT) |
3462 BIT(SOF_INTERRUPT));
3466 /* ep_dbg(dev, "irqstat1 %08x\n", stat);*/
3468 /* DMA status, for ep-{a,b,c,d} */
3469 scratch = stat & DMA_INTERRUPTS;
3470 stat &= ~DMA_INTERRUPTS;
3472 for (num = 0; scratch; num++) {
3473 struct net2280_dma_regs __iomem *dma;
3476 if ((tmp & scratch) == 0)
3480 ep = &dev->ep[num + 1];
3486 /* clear ep's dma status */
3487 tmp = readl(&dma->dmastat);
3488 writel(tmp, &dma->dmastat);
3491 if (dev->quirks & PLX_PCIE) {
3492 u32 r_dmacount = readl(&dma->dmacount);
3493 if (!ep->is_in && (r_dmacount & 0x00FFFFFF) &&
3494 (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT)))
3498 if (!(tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) {
3499 ep_dbg(ep->dev, "%s no xact done? %08x\n",
3505 /* OUT transfers terminate when the data from the
3506 * host is in our memory. Process whatever's done.
3507 * On this path, we know transfer's last packet wasn't
3508 * less than req->length. NAK_OUT_PACKETS may be set,
3509 * or the FIFO may already be holding new packets.
3511 * IN transfers can linger in the FIFO for a very
3512 * long time ... we ignore that for now, accounting
3513 * precisely (like PIO does) needs per-packet irqs
3515 scan_dma_completions(ep);
3517 /* disable dma on inactive queues; else maybe restart */
3518 if (!list_empty(&ep->queue)) {
3519 tmp = readl(&dma->dmactl);
3525 /* NOTE: there are other PCI errors we might usefully notice.
3526 * if they appear very often, here's where to try recovering.
3528 if (stat & PCI_ERROR_INTERRUPTS) {
3529 ep_err(dev, "pci dma error; stat %08x\n", stat);
3530 stat &= ~PCI_ERROR_INTERRUPTS;
3531 /* these are fatal errors, but "maybe" they won't
3534 stop_activity(dev, dev->driver);
3540 ep_dbg(dev, "unhandled irqstat1 %08x\n", stat);
3543 static irqreturn_t net2280_irq(int irq, void *_dev)
3545 struct net2280 *dev = _dev;
3547 /* shared interrupt, not ours */
3548 if ((dev->quirks & PLX_LEGACY) &&
3549 (!(readl(&dev->regs->irqstat0) & BIT(INTA_ASSERTED))))
3552 spin_lock(&dev->lock);
3554 /* handle disconnect, dma, and more */
3555 handle_stat1_irqs(dev, readl(&dev->regs->irqstat1));
3557 /* control requests and PIO */
3558 handle_stat0_irqs(dev, readl(&dev->regs->irqstat0));
3560 if (dev->quirks & PLX_PCIE) {
3561 /* re-enable interrupt to trigger any possible new interrupt */
3562 u32 pciirqenb1 = readl(&dev->regs->pciirqenb1);
3563 writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1);
3564 writel(pciirqenb1, &dev->regs->pciirqenb1);
3567 spin_unlock(&dev->lock);
3572 /*-------------------------------------------------------------------------*/
3574 static void gadget_release(struct device *_dev)
3576 struct net2280 *dev = container_of(_dev, struct net2280, gadget.dev);
3581 /* tear down the binding between this driver and the pci device */
3583 static void net2280_remove(struct pci_dev *pdev)
3585 struct net2280 *dev = pci_get_drvdata(pdev);
3588 usb_del_gadget(&dev->gadget);
3590 BUG_ON(dev->driver);
3592 /* then clean up the resources we allocated during probe() */
3593 if (dev->requests) {
3595 for (i = 1; i < 5; i++) {
3596 if (!dev->ep[i].dummy)
3598 dma_pool_free(dev->requests, dev->ep[i].dummy,
3601 dma_pool_destroy(dev->requests);
3604 free_irq(pdev->irq, dev);
3605 if (dev->quirks & PLX_PCIE)
3606 pci_disable_msi(pdev);
3608 net2280_led_shutdown(dev);
3612 release_mem_region(pci_resource_start(pdev, 0),
3613 pci_resource_len(pdev, 0));
3615 pci_disable_device(pdev);
3616 device_remove_file(&pdev->dev, &dev_attr_registers);
3618 ep_info(dev, "unbind\n");
3619 usb_put_gadget(&dev->gadget);
3622 /* wrap this driver around the specified device, but
3623 * don't respond over USB until a gadget driver binds to us.
3626 static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)
3628 struct net2280 *dev;
3629 unsigned long resource, len;
3630 void __iomem *base = NULL;
3633 /* alloc, and start init */
3634 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
3640 pci_set_drvdata(pdev, dev);
3641 usb_initialize_gadget(&pdev->dev, &dev->gadget, gadget_release);
3642 spin_lock_init(&dev->lock);
3643 dev->quirks = id->driver_data;
3645 dev->gadget.ops = &net2280_ops;
3646 dev->gadget.max_speed = (dev->quirks & PLX_SUPERSPEED) ?
3647 USB_SPEED_SUPER : USB_SPEED_HIGH;
3649 /* the "gadget" abstracts/virtualizes the controller */
3650 dev->gadget.name = driver_name;
3652 /* now all the pci goodies ... */
3653 if (pci_enable_device(pdev) < 0) {
3659 /* BAR 0 holds all the registers
3660 * BAR 1 is 8051 memory; unused here (note erratum 0103)
3661 * BAR 2 is fifo memory; unused here
3663 resource = pci_resource_start(pdev, 0);
3664 len = pci_resource_len(pdev, 0);
3665 if (!request_mem_region(resource, len, driver_name)) {
3666 ep_dbg(dev, "controller already in use\n");
3672 /* FIXME provide firmware download interface to put
3673 * 8051 code into the chip, e.g. to turn on PCI PM.
3676 base = ioremap(resource, len);
3678 ep_dbg(dev, "can't map memory\n");
3682 dev->regs = (struct net2280_regs __iomem *) base;
3683 dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080);
3684 dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100);
3685 dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180);
3686 dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
3687 dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
3689 if (dev->quirks & PLX_PCIE) {
3692 dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *)
3694 dev->llregs = (struct usb338x_ll_regs __iomem *)
3696 dev->plregs = (struct usb338x_pl_regs __iomem *)
3698 usbstat = readl(&dev->usb->usbstat);
3699 dev->enhanced_mode = !!(usbstat & BIT(11));
3700 dev->n_ep = (dev->enhanced_mode) ? 9 : 5;
3701 /* put into initial config, link up all endpoints */
3702 fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
3703 (0xf << DEFECT7374_FSM_FIELD);
3704 /* See if firmware needs to set up for workaround: */
3705 if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ) {
3706 dev->bug7734_patched = 1;
3707 writel(0, &dev->usb->usbctl);
3709 dev->bug7734_patched = 0;
3711 dev->enhanced_mode = 0;
3713 /* put into initial config, link up all endpoints */
3714 writel(0, &dev->usb->usbctl);
3720 /* irq setup after old hardware is cleaned up */
3722 ep_err(dev, "No IRQ. Check PCI setup!\n");
3727 if (dev->quirks & PLX_PCIE)
3728 if (pci_enable_msi(pdev))
3729 ep_err(dev, "Failed to enable MSI mode\n");
3731 if (request_irq(pdev->irq, net2280_irq, IRQF_SHARED,
3732 driver_name, dev)) {
3733 ep_err(dev, "request interrupt %d failed\n", pdev->irq);
3740 /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
3741 dev->requests = dma_pool_create("requests", &pdev->dev,
3742 sizeof(struct net2280_dma),
3743 0 /* no alignment requirements */,
3744 0 /* or page-crossing issues */);
3745 if (!dev->requests) {
3746 ep_dbg(dev, "can't get request pool\n");
3750 for (i = 1; i < 5; i++) {
3751 struct net2280_dma *td;
3753 td = dma_pool_alloc(dev->requests, GFP_KERNEL,
3754 &dev->ep[i].td_dma);
3756 ep_dbg(dev, "can't get dummy %d\n", i);
3760 td->dmacount = 0; /* not VALID */
3761 td->dmadesc = td->dmaaddr;
3762 dev->ep[i].dummy = td;
3765 /* enable lower-overhead pci memory bursts during DMA */
3766 if (dev->quirks & PLX_LEGACY)
3767 writel(BIT(DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE) |
3769 * 256 write retries may not be enough...
3770 BIT(PCI_RETRY_ABORT_ENABLE) |
3772 BIT(DMA_READ_MULTIPLE_ENABLE) |
3773 BIT(DMA_READ_LINE_ENABLE),
3774 &dev->pci->pcimstctl);
3775 /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
3776 pci_set_master(pdev);
3777 pci_try_set_mwi(pdev);
3779 /* ... also flushes any posted pci writes */
3780 dev->chiprev = get_idx_reg(dev->regs, REG_CHIPREV) & 0xffff;
3783 ep_info(dev, "%s\n", driver_desc);
3784 ep_info(dev, "irq %d, pci mem %p, chip rev %04x\n",
3785 pdev->irq, base, dev->chiprev);
3786 ep_info(dev, "version: " DRIVER_VERSION "; %s\n",
3787 dev->enhanced_mode ? "enhanced mode" : "legacy mode");
3788 retval = device_create_file(&pdev->dev, &dev_attr_registers);
3792 retval = usb_add_gadget(&dev->gadget);
3800 net2280_remove(pdev);
3806 /* make sure the board is quiescent; otherwise it will continue
3807 * generating IRQs across the upcoming reboot.
3810 static void net2280_shutdown(struct pci_dev *pdev)
3812 struct net2280 *dev = pci_get_drvdata(pdev);
3815 writel(0, &dev->regs->pciirqenb0);
3816 writel(0, &dev->regs->pciirqenb1);
3818 /* disable the pullup so the host will think we're gone */
3819 writel(0, &dev->usb->usbctl);
3824 /*-------------------------------------------------------------------------*/
3826 static const struct pci_device_id pci_ids[] = { {
3827 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3829 .vendor = PCI_VENDOR_ID_PLX_LEGACY,
3831 .subvendor = PCI_ANY_ID,
3832 .subdevice = PCI_ANY_ID,
3833 .driver_data = PLX_LEGACY | PLX_2280,
3835 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3837 .vendor = PCI_VENDOR_ID_PLX_LEGACY,
3839 .subvendor = PCI_ANY_ID,
3840 .subdevice = PCI_ANY_ID,
3841 .driver_data = PLX_LEGACY,
3844 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3846 .vendor = PCI_VENDOR_ID_PLX,
3848 .subvendor = PCI_ANY_ID,
3849 .subdevice = PCI_ANY_ID,
3850 .driver_data = PLX_PCIE,
3853 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3855 .vendor = PCI_VENDOR_ID_PLX,
3857 .subvendor = PCI_ANY_ID,
3858 .subdevice = PCI_ANY_ID,
3859 .driver_data = PLX_PCIE | PLX_SUPERSPEED,
3862 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3864 .vendor = PCI_VENDOR_ID_PLX,
3866 .subvendor = PCI_ANY_ID,
3867 .subdevice = PCI_ANY_ID,
3868 .driver_data = PLX_PCIE | PLX_SUPERSPEED,
3870 { /* end: all zeroes */ }
3872 MODULE_DEVICE_TABLE(pci, pci_ids);
3874 /* pci driver glue; this is a "new style" PCI driver module */
3875 static struct pci_driver net2280_pci_driver = {
3876 .name = driver_name,
3877 .id_table = pci_ids,
3879 .probe = net2280_probe,
3880 .remove = net2280_remove,
3881 .shutdown = net2280_shutdown,
3883 /* FIXME add power management support */
3886 module_pci_driver(net2280_pci_driver);
3888 MODULE_DESCRIPTION(DRIVER_DESC);
3889 MODULE_AUTHOR("David Brownell");
3890 MODULE_LICENSE("GPL");