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>
56 #include <asm/byteorder.h>
58 #include <asm/unaligned.h>
60 #define DRIVER_DESC "PLX NET228x/USB338x USB Peripheral Controller"
61 #define DRIVER_VERSION "2005 Sept 27/v3.0"
63 #define EP_DONTUSE 13 /* nonzero */
65 #define USE_RDK_LEDS /* GPIO pins control three LEDs */
68 static const char driver_name[] = "net2280";
69 static const char driver_desc[] = DRIVER_DESC;
71 static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };
72 static const char ep0name[] = "ep0";
74 #define EP_INFO(_name, _caps) \
82 const struct usb_ep_caps caps;
83 } ep_info_dft[] = { /* Default endpoint configuration */
85 USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
87 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
89 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
91 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
93 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
95 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
97 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
99 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
101 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
102 }, ep_info_adv[] = { /* Endpoints for usb3380 advance mode */
104 USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
106 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
108 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
110 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
112 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
114 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
116 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
118 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
120 USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
125 /* mode 0 == ep-{a,b,c,d} 1K fifo each
126 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
127 * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
129 static ushort fifo_mode;
131 /* "modprobe net2280 fifo_mode=1" etc */
132 module_param(fifo_mode, ushort, 0644);
134 /* enable_suspend -- When enabled, the driver will respond to
135 * USB suspend requests by powering down the NET2280. Otherwise,
136 * USB suspend requests will be ignored. This is acceptable for
137 * self-powered devices
139 static bool enable_suspend;
141 /* "modprobe net2280 enable_suspend=1" etc */
142 module_param(enable_suspend, bool, 0444);
144 #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
146 static char *type_string(u8 bmAttributes)
148 switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
149 case USB_ENDPOINT_XFER_BULK: return "bulk";
150 case USB_ENDPOINT_XFER_ISOC: return "iso";
151 case USB_ENDPOINT_XFER_INT: return "intr";
158 #define valid_bit cpu_to_le32(BIT(VALID_BIT))
159 #define dma_done_ie cpu_to_le32(BIT(DMA_DONE_INTERRUPT_ENABLE))
161 static void ep_clear_seqnum(struct net2280_ep *ep);
162 static void stop_activity(struct net2280 *dev,
163 struct usb_gadget_driver *driver);
164 static void ep0_start(struct net2280 *dev);
166 /*-------------------------------------------------------------------------*/
167 static inline void enable_pciirqenb(struct net2280_ep *ep)
169 u32 tmp = readl(&ep->dev->regs->pciirqenb0);
171 if (ep->dev->quirks & PLX_LEGACY)
174 tmp |= BIT(ep_bit[ep->num]);
175 writel(tmp, &ep->dev->regs->pciirqenb0);
181 net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
184 struct net2280_ep *ep;
189 static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 };
192 ep = container_of(_ep, struct net2280_ep, ep);
193 if (!_ep || !desc || ep->desc || _ep->name == ep0name ||
194 desc->bDescriptorType != USB_DT_ENDPOINT) {
195 pr_err("%s: failed at line=%d\n", __func__, __LINE__);
199 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
204 /* erratum 0119 workaround ties up an endpoint number */
205 if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) {
210 if (dev->quirks & PLX_PCIE) {
211 if ((desc->bEndpointAddress & 0x0f) >= 0x0c) {
215 ep->is_in = !!usb_endpoint_dir_in(desc);
216 if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) {
222 /* sanity check ep-e/ep-f since their fifos are small */
223 max = usb_endpoint_maxp(desc);
224 if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) {
229 spin_lock_irqsave(&dev->lock, flags);
230 _ep->maxpacket = max;
233 /* ep_reset() has already been called */
236 ep->out_overflow = 0;
238 /* set speed-dependent max packet; may kick in high bandwidth */
239 set_max_speed(ep, max);
241 /* set type, direction, address; reset fifo counters */
242 writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
244 if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
245 tmp = readl(&ep->cfg->ep_cfg);
246 /* If USB ep number doesn't match hardware ep number */
247 if ((tmp & 0xf) != usb_endpoint_num(desc)) {
249 spin_unlock_irqrestore(&dev->lock, flags);
253 tmp &= ~USB3380_EP_CFG_MASK_IN;
255 tmp &= ~USB3380_EP_CFG_MASK_OUT;
257 type = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
258 if (type == USB_ENDPOINT_XFER_INT) {
259 /* erratum 0105 workaround prevents hs NYET */
260 if (dev->chiprev == 0100 &&
261 dev->gadget.speed == USB_SPEED_HIGH &&
262 !(desc->bEndpointAddress & USB_DIR_IN))
263 writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE),
265 } else if (type == USB_ENDPOINT_XFER_BULK) {
266 /* catch some particularly blatant driver bugs */
267 if ((dev->gadget.speed == USB_SPEED_SUPER && max != 1024) ||
268 (dev->gadget.speed == USB_SPEED_HIGH && max != 512) ||
269 (dev->gadget.speed == USB_SPEED_FULL && max > 64)) {
270 spin_unlock_irqrestore(&dev->lock, flags);
275 ep->is_iso = (type == USB_ENDPOINT_XFER_ISOC);
276 /* Enable this endpoint */
277 if (dev->quirks & PLX_LEGACY) {
278 tmp |= type << ENDPOINT_TYPE;
279 tmp |= desc->bEndpointAddress;
280 /* default full fifo lines */
281 tmp |= (4 << ENDPOINT_BYTE_COUNT);
282 tmp |= BIT(ENDPOINT_ENABLE);
283 ep->is_in = (tmp & USB_DIR_IN) != 0;
285 /* In Legacy mode, only OUT endpoints are used */
286 if (dev->enhanced_mode && ep->is_in) {
287 tmp |= type << IN_ENDPOINT_TYPE;
288 tmp |= BIT(IN_ENDPOINT_ENABLE);
290 tmp |= type << OUT_ENDPOINT_TYPE;
291 tmp |= BIT(OUT_ENDPOINT_ENABLE);
292 tmp |= (ep->is_in << ENDPOINT_DIRECTION);
295 tmp |= (4 << ENDPOINT_BYTE_COUNT);
296 if (!dev->enhanced_mode)
297 tmp |= usb_endpoint_num(desc);
298 tmp |= (ep->ep.maxburst << MAX_BURST_SIZE);
301 /* Make sure all the registers are written before ep_rsp*/
304 /* for OUT transfers, block the rx fifo until a read is posted */
306 writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
307 else if (!(dev->quirks & PLX_2280)) {
308 /* Added for 2282, Don't use nak packets on an in endpoint,
309 * this was ignored on 2280
311 writel(BIT(CLEAR_NAK_OUT_PACKETS) |
312 BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
315 if (dev->quirks & PLX_PCIE)
317 writel(tmp, &ep->cfg->ep_cfg);
320 if (!ep->dma) { /* pio, per-packet */
321 enable_pciirqenb(ep);
323 tmp = BIT(DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) |
324 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE);
325 if (dev->quirks & PLX_2280)
326 tmp |= readl(&ep->regs->ep_irqenb);
327 writel(tmp, &ep->regs->ep_irqenb);
328 } else { /* dma, per-request */
329 tmp = BIT((8 + ep->num)); /* completion */
330 tmp |= readl(&dev->regs->pciirqenb1);
331 writel(tmp, &dev->regs->pciirqenb1);
333 /* for short OUT transfers, dma completions can't
334 * advance the queue; do it pio-style, by hand.
335 * NOTE erratum 0112 workaround #2
337 if ((desc->bEndpointAddress & USB_DIR_IN) == 0) {
338 tmp = BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE);
339 writel(tmp, &ep->regs->ep_irqenb);
341 enable_pciirqenb(ep);
345 tmp = desc->bEndpointAddress;
346 ep_dbg(dev, "enabled %s (ep%d%s-%s) %s max %04x\n",
347 _ep->name, tmp & 0x0f, DIR_STRING(tmp),
348 type_string(desc->bmAttributes),
349 ep->dma ? "dma" : "pio", max);
351 /* pci writes may still be posted */
352 spin_unlock_irqrestore(&dev->lock, flags);
356 dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret);
360 static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec)
366 if (result == ~(u32)0) /* "device unplugged" */
377 static const struct usb_ep_ops net2280_ep_ops;
379 static void ep_reset_228x(struct net2280_regs __iomem *regs,
380 struct net2280_ep *ep)
385 INIT_LIST_HEAD(&ep->queue);
387 usb_ep_set_maxpacket_limit(&ep->ep, ~0);
388 ep->ep.ops = &net2280_ep_ops;
390 /* disable the dma, irqs, endpoint... */
392 writel(0, &ep->dma->dmactl);
393 writel(BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
394 BIT(DMA_TRANSACTION_DONE_INTERRUPT) |
398 tmp = readl(®s->pciirqenb0);
399 tmp &= ~BIT(ep->num);
400 writel(tmp, ®s->pciirqenb0);
402 tmp = readl(®s->pciirqenb1);
403 tmp &= ~BIT((8 + ep->num)); /* completion */
404 writel(tmp, ®s->pciirqenb1);
406 writel(0, &ep->regs->ep_irqenb);
408 /* init to our chosen defaults, notably so that we NAK OUT
409 * packets until the driver queues a read (+note erratum 0112)
411 if (!ep->is_in || (ep->dev->quirks & PLX_2280)) {
412 tmp = BIT(SET_NAK_OUT_PACKETS_MODE) |
413 BIT(SET_NAK_OUT_PACKETS) |
414 BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
415 BIT(CLEAR_INTERRUPT_MODE);
418 tmp = BIT(CLEAR_NAK_OUT_PACKETS_MODE) |
419 BIT(CLEAR_NAK_OUT_PACKETS) |
420 BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
421 BIT(CLEAR_INTERRUPT_MODE);
425 tmp |= BIT(CLEAR_ENDPOINT_TOGGLE) |
426 BIT(CLEAR_ENDPOINT_HALT);
428 writel(tmp, &ep->regs->ep_rsp);
430 /* scrub most status bits, and flush any fifo state */
431 if (ep->dev->quirks & PLX_2280)
432 tmp = BIT(FIFO_OVERFLOW) |
437 writel(tmp | BIT(TIMEOUT) |
438 BIT(USB_STALL_SENT) |
439 BIT(USB_IN_NAK_SENT) |
440 BIT(USB_IN_ACK_RCVD) |
441 BIT(USB_OUT_PING_NAK_SENT) |
442 BIT(USB_OUT_ACK_SENT) |
444 BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
445 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
446 BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
447 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
448 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
449 BIT(DATA_IN_TOKEN_INTERRUPT),
452 /* fifo size is handled separately */
455 static void ep_reset_338x(struct net2280_regs __iomem *regs,
456 struct net2280_ep *ep)
461 INIT_LIST_HEAD(&ep->queue);
463 usb_ep_set_maxpacket_limit(&ep->ep, ~0);
464 ep->ep.ops = &net2280_ep_ops;
466 /* disable the dma, irqs, endpoint... */
468 writel(0, &ep->dma->dmactl);
469 writel(BIT(DMA_ABORT_DONE_INTERRUPT) |
470 BIT(DMA_PAUSE_DONE_INTERRUPT) |
471 BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
472 BIT(DMA_TRANSACTION_DONE_INTERRUPT),
473 /* | BIT(DMA_ABORT), */
476 dmastat = readl(&ep->dma->dmastat);
477 if (dmastat == 0x5002) {
478 ep_warn(ep->dev, "The dmastat return = %x!!\n",
480 writel(0x5a, &ep->dma->dmastat);
483 tmp = readl(®s->pciirqenb0);
484 tmp &= ~BIT(ep_bit[ep->num]);
485 writel(tmp, ®s->pciirqenb0);
488 tmp = readl(®s->pciirqenb1);
489 tmp &= ~BIT((8 + ep->num)); /* completion */
490 writel(tmp, ®s->pciirqenb1);
493 writel(0, &ep->regs->ep_irqenb);
495 writel(BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
496 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
498 BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
499 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
500 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
501 BIT(DATA_IN_TOKEN_INTERRUPT), &ep->regs->ep_stat);
503 tmp = readl(&ep->cfg->ep_cfg);
505 tmp &= ~USB3380_EP_CFG_MASK_IN;
507 tmp &= ~USB3380_EP_CFG_MASK_OUT;
508 writel(tmp, &ep->cfg->ep_cfg);
511 static void nuke(struct net2280_ep *);
513 static int net2280_disable(struct usb_ep *_ep)
515 struct net2280_ep *ep;
518 ep = container_of(_ep, struct net2280_ep, ep);
519 if (!_ep || _ep->name == ep0name) {
520 pr_err("%s: Invalid ep=%p\n", __func__, _ep);
523 spin_lock_irqsave(&ep->dev->lock, flags);
526 if (ep->dev->quirks & PLX_PCIE)
527 ep_reset_338x(ep->dev->regs, ep);
529 ep_reset_228x(ep->dev->regs, ep);
531 ep_vdbg(ep->dev, "disabled %s %s\n",
532 ep->dma ? "dma" : "pio", _ep->name);
534 /* synch memory views with the device */
535 (void)readl(&ep->cfg->ep_cfg);
537 if (!ep->dma && ep->num >= 1 && ep->num <= 4)
538 ep->dma = &ep->dev->dma[ep->num - 1];
540 spin_unlock_irqrestore(&ep->dev->lock, flags);
544 /*-------------------------------------------------------------------------*/
546 static struct usb_request
547 *net2280_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
549 struct net2280_ep *ep;
550 struct net2280_request *req;
553 pr_err("%s: Invalid ep\n", __func__);
556 ep = container_of(_ep, struct net2280_ep, ep);
558 req = kzalloc(sizeof(*req), gfp_flags);
562 INIT_LIST_HEAD(&req->queue);
564 /* this dma descriptor may be swapped with the previous dummy */
566 struct net2280_dma *td;
568 td = dma_pool_alloc(ep->dev->requests, gfp_flags,
574 td->dmacount = 0; /* not VALID */
575 td->dmadesc = td->dmaaddr;
581 static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req)
583 struct net2280_ep *ep;
584 struct net2280_request *req;
586 ep = container_of(_ep, struct net2280_ep, ep);
588 dev_err(&ep->dev->pdev->dev, "%s: Invalid ep=%p or req=%p\n",
589 __func__, _ep, _req);
593 req = container_of(_req, struct net2280_request, req);
594 WARN_ON(!list_empty(&req->queue));
596 dma_pool_free(ep->dev->requests, req->td, req->td_dma);
600 /*-------------------------------------------------------------------------*/
602 /* load a packet into the fifo we use for usb IN transfers.
603 * works for all endpoints.
605 * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
606 * at a time, but this code is simpler because it knows it only writes
607 * one packet. ep-a..ep-d should use dma instead.
609 static void write_fifo(struct net2280_ep *ep, struct usb_request *req)
611 struct net2280_ep_regs __iomem *regs = ep->regs;
614 unsigned count, total;
616 /* INVARIANT: fifo is currently empty. (testable) */
619 buf = req->buf + req->actual;
621 total = req->length - req->actual;
627 /* write just one packet at a time */
628 count = ep->ep.maxpacket;
629 if (count > total) /* min() cannot be used on a bitfield */
632 ep_vdbg(ep->dev, "write %s fifo (IN) %d bytes%s req %p\n",
634 (count != ep->ep.maxpacket) ? " (short)" : "",
637 /* NOTE be careful if you try to align these. fifo lines
638 * should normally be full (4 bytes) and successive partial
639 * lines are ok only in certain cases.
641 tmp = get_unaligned((u32 *)buf);
643 writel(tmp, ®s->ep_data);
648 /* last fifo entry is "short" unless we wrote a full packet.
649 * also explicitly validate last word in (periodic) transfers
650 * when maxpacket is not a multiple of 4 bytes.
652 if (count || total < ep->ep.maxpacket) {
653 tmp = count ? get_unaligned((u32 *)buf) : count;
655 set_fifo_bytecount(ep, count & 0x03);
656 writel(tmp, ®s->ep_data);
659 /* pci writes may still be posted */
662 /* work around erratum 0106: PCI and USB race over the OUT fifo.
663 * caller guarantees chiprev 0100, out endpoint is NAKing, and
664 * there's no real data in the fifo.
666 * NOTE: also used in cases where that erratum doesn't apply:
667 * where the host wrote "too much" data to us.
669 static void out_flush(struct net2280_ep *ep)
674 statp = &ep->regs->ep_stat;
677 if (tmp & BIT(NAK_OUT_PACKETS)) {
678 ep_dbg(ep->dev, "%s %s %08x !NAK\n",
679 ep->ep.name, __func__, tmp);
680 writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
683 writel(BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
684 BIT(DATA_PACKET_RECEIVED_INTERRUPT),
686 writel(BIT(FIFO_FLUSH), statp);
687 /* Make sure that stap is written */
690 if (tmp & BIT(DATA_OUT_PING_TOKEN_INTERRUPT) &&
691 /* high speed did bulk NYET; fifo isn't filling */
692 ep->dev->gadget.speed == USB_SPEED_FULL) {
695 usec = 50; /* 64 byte bulk/interrupt */
696 handshake(statp, BIT(USB_OUT_PING_NAK_SENT),
697 BIT(USB_OUT_PING_NAK_SENT), usec);
698 /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
702 /* unload packet(s) from the fifo we use for usb OUT transfers.
703 * returns true iff the request completed, because of short packet
704 * or the request buffer having filled with full packets.
706 * for ep-a..ep-d this will read multiple packets out when they
707 * have been accepted.
709 static int read_fifo(struct net2280_ep *ep, struct net2280_request *req)
711 struct net2280_ep_regs __iomem *regs = ep->regs;
712 u8 *buf = req->req.buf + req->req.actual;
713 unsigned count, tmp, is_short;
714 unsigned cleanup = 0, prevent = 0;
716 /* erratum 0106 ... packets coming in during fifo reads might
717 * be incompletely rejected. not all cases have workarounds.
719 if (ep->dev->chiprev == 0x0100 &&
720 ep->dev->gadget.speed == USB_SPEED_FULL) {
722 tmp = readl(&ep->regs->ep_stat);
723 if ((tmp & BIT(NAK_OUT_PACKETS)))
725 else if ((tmp & BIT(FIFO_FULL))) {
726 start_out_naking(ep);
729 /* else: hope we don't see the problem */
732 /* never overflow the rx buffer. the fifo reads packets until
733 * it sees a short one; we might not be ready for them all.
736 count = readl(®s->ep_avail);
737 if (unlikely(count == 0)) {
739 tmp = readl(&ep->regs->ep_stat);
740 count = readl(®s->ep_avail);
741 /* handled that data already? */
742 if (count == 0 && (tmp & BIT(NAK_OUT_PACKETS)) == 0)
746 tmp = req->req.length - req->req.actual;
748 /* as with DMA, data overflow gets flushed */
749 if ((tmp % ep->ep.maxpacket) != 0) {
751 "%s out fifo %d bytes, expected %d\n",
752 ep->ep.name, count, tmp);
753 req->req.status = -EOVERFLOW;
755 /* NAK_OUT_PACKETS will be set, so flushing is safe;
756 * the next read will start with the next packet
758 } /* else it's a ZLP, no worries */
761 req->req.actual += count;
763 is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0);
765 ep_vdbg(ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
766 ep->ep.name, count, is_short ? " (short)" : "",
767 cleanup ? " flush" : "", prevent ? " nak" : "",
768 req, req->req.actual, req->req.length);
771 tmp = readl(®s->ep_data);
773 put_unaligned(tmp, (u32 *)buf);
778 tmp = readl(®s->ep_data);
779 /* LE conversion is implicit here: */
788 writel(BIT(CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
789 (void) readl(&ep->regs->ep_rsp);
792 return is_short || ((req->req.actual == req->req.length) &&
796 /* fill out dma descriptor to match a given request */
797 static void fill_dma_desc(struct net2280_ep *ep,
798 struct net2280_request *req, int valid)
800 struct net2280_dma *td = req->td;
801 u32 dmacount = req->req.length;
803 /* don't let DMA continue after a short OUT packet,
804 * so overruns can't affect the next transfer.
805 * in case of overruns on max-size packets, we can't
806 * stop the fifo from filling but we can flush it.
809 dmacount |= BIT(DMA_DIRECTION);
810 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) ||
811 !(ep->dev->quirks & PLX_2280))
812 dmacount |= BIT(END_OF_CHAIN);
816 dmacount |= BIT(VALID_BIT);
817 dmacount |= BIT(DMA_DONE_INTERRUPT_ENABLE);
819 /* td->dmadesc = previously set by caller */
820 td->dmaaddr = cpu_to_le32 (req->req.dma);
822 /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
824 td->dmacount = cpu_to_le32(dmacount);
827 static const u32 dmactl_default =
828 BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
829 BIT(DMA_CLEAR_COUNT_ENABLE) |
830 /* erratum 0116 workaround part 1 (use POLLING) */
831 (POLL_100_USEC << DESCRIPTOR_POLLING_RATE) |
832 BIT(DMA_VALID_BIT_POLLING_ENABLE) |
833 BIT(DMA_VALID_BIT_ENABLE) |
834 BIT(DMA_SCATTER_GATHER_ENABLE) |
835 /* erratum 0116 workaround part 2 (no AUTOSTART) */
838 static inline void spin_stop_dma(struct net2280_dma_regs __iomem *dma)
840 handshake(&dma->dmactl, BIT(DMA_ENABLE), 0, 50);
843 static inline void stop_dma(struct net2280_dma_regs __iomem *dma)
845 writel(readl(&dma->dmactl) & ~BIT(DMA_ENABLE), &dma->dmactl);
849 static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma)
851 struct net2280_dma_regs __iomem *dma = ep->dma;
852 unsigned int tmp = BIT(VALID_BIT) | (ep->is_in << DMA_DIRECTION);
854 if (!(ep->dev->quirks & PLX_2280))
855 tmp |= BIT(END_OF_CHAIN);
857 writel(tmp, &dma->dmacount);
858 writel(readl(&dma->dmastat), &dma->dmastat);
860 writel(td_dma, &dma->dmadesc);
861 if (ep->dev->quirks & PLX_PCIE)
862 dmactl |= BIT(DMA_REQUEST_OUTSTANDING);
863 writel(dmactl, &dma->dmactl);
865 /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
866 (void) readl(&ep->dev->pci->pcimstctl);
868 writel(BIT(DMA_START), &dma->dmastat);
871 static void start_dma(struct net2280_ep *ep, struct net2280_request *req)
874 struct net2280_dma_regs __iomem *dma = ep->dma;
876 /* FIXME can't use DMA for ZLPs */
878 /* on this path we "know" there's no dma active (yet) */
879 WARN_ON(readl(&dma->dmactl) & BIT(DMA_ENABLE));
880 writel(0, &ep->dma->dmactl);
882 /* previous OUT packet might have been short */
883 if (!ep->is_in && (readl(&ep->regs->ep_stat) &
884 BIT(NAK_OUT_PACKETS))) {
885 writel(BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT),
888 tmp = readl(&ep->regs->ep_avail);
890 writel(readl(&dma->dmastat), &dma->dmastat);
892 /* transfer all/some fifo data */
893 writel(req->req.dma, &dma->dmaaddr);
894 tmp = min(tmp, req->req.length);
896 /* dma irq, faking scatterlist status */
897 req->td->dmacount = cpu_to_le32(req->req.length - tmp);
898 writel(BIT(DMA_DONE_INTERRUPT_ENABLE) | tmp,
900 req->td->dmadesc = 0;
903 writel(BIT(DMA_ENABLE), &dma->dmactl);
904 writel(BIT(DMA_START), &dma->dmastat);
910 tmp = dmactl_default;
912 /* force packet boundaries between dma requests, but prevent the
913 * controller from automagically writing a last "short" packet
914 * (zero length) unless the driver explicitly said to do that.
917 if (likely((req->req.length % ep->ep.maxpacket) ||
919 tmp |= BIT(DMA_FIFO_VALIDATE);
920 ep->in_fifo_validate = 1;
922 ep->in_fifo_validate = 0;
925 /* init req->td, pointing to the current dummy */
926 req->td->dmadesc = cpu_to_le32 (ep->td_dma);
927 fill_dma_desc(ep, req, 1);
929 req->td->dmacount |= cpu_to_le32(BIT(END_OF_CHAIN));
931 start_queue(ep, tmp, req->td_dma);
935 queue_dma(struct net2280_ep *ep, struct net2280_request *req, int valid)
937 struct net2280_dma *end;
940 /* swap new dummy for old, link; fill and maybe activate */
946 ep->td_dma = req->td_dma;
949 end->dmadesc = cpu_to_le32 (ep->td_dma);
951 fill_dma_desc(ep, req, valid);
955 done(struct net2280_ep *ep, struct net2280_request *req, int status)
958 unsigned stopped = ep->stopped;
960 list_del_init(&req->queue);
962 if (req->req.status == -EINPROGRESS)
963 req->req.status = status;
965 status = req->req.status;
969 usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in);
971 if (status && status != -ESHUTDOWN)
972 ep_vdbg(dev, "complete %s req %p stat %d len %u/%u\n",
973 ep->ep.name, &req->req, status,
974 req->req.actual, req->req.length);
976 /* don't modify queue heads during completion callback */
978 spin_unlock(&dev->lock);
979 usb_gadget_giveback_request(&ep->ep, &req->req);
980 spin_lock(&dev->lock);
981 ep->stopped = stopped;
984 /*-------------------------------------------------------------------------*/
987 net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
989 struct net2280_request *req;
990 struct net2280_ep *ep;
995 /* we always require a cpu-view buffer, so that we can
996 * always use pio (as fallback or whatever).
998 ep = container_of(_ep, struct net2280_ep, ep);
999 if (!_ep || (!ep->desc && ep->num != 0)) {
1000 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1003 req = container_of(_req, struct net2280_request, req);
1004 if (!_req || !_req->complete || !_req->buf ||
1005 !list_empty(&req->queue)) {
1009 if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) {
1014 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
1019 /* FIXME implement PIO fallback for ZLPs with DMA */
1020 if (ep->dma && _req->length == 0) {
1025 /* set up dma mapping in case the caller didn't */
1027 ret = usb_gadget_map_request(&dev->gadget, _req,
1033 ep_vdbg(dev, "%s queue req %p, len %d buf %p\n",
1034 _ep->name, _req, _req->length, _req->buf);
1036 spin_lock_irqsave(&dev->lock, flags);
1038 _req->status = -EINPROGRESS;
1041 /* kickstart this i/o queue? */
1042 if (list_empty(&ep->queue) && !ep->stopped &&
1043 !((dev->quirks & PLX_PCIE) && ep->dma &&
1044 (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)))) {
1046 /* use DMA if the endpoint supports it, else pio */
1050 /* maybe there's no control data, just status ack */
1051 if (ep->num == 0 && _req->length == 0) {
1054 ep_vdbg(dev, "%s status ack\n", ep->ep.name);
1058 /* PIO ... stuff the fifo, or unblock it. */
1060 write_fifo(ep, _req);
1064 /* OUT FIFO might have packet(s) buffered */
1065 s = readl(&ep->regs->ep_stat);
1066 if ((s & BIT(FIFO_EMPTY)) == 0) {
1067 /* note: _req->short_not_ok is
1068 * ignored here since PIO _always_
1069 * stops queue advance here, and
1070 * _req->status doesn't change for
1071 * short reads (only _req->actual)
1073 if (read_fifo(ep, req) &&
1077 /* don't queue it */
1079 } else if (read_fifo(ep, req) &&
1084 s = readl(&ep->regs->ep_stat);
1087 /* don't NAK, let the fifo fill */
1088 if (req && (s & BIT(NAK_OUT_PACKETS)))
1089 writel(BIT(CLEAR_NAK_OUT_PACKETS),
1094 } else if (ep->dma) {
1100 /* preventing magic zlps is per-engine state, not
1101 * per-transfer; irq logic must recover hiccups.
1103 expect = likely(req->req.zero ||
1104 (req->req.length % ep->ep.maxpacket));
1105 if (expect != ep->in_fifo_validate)
1108 queue_dma(ep, req, valid);
1110 } /* else the irq handler advances the queue. */
1114 list_add_tail(&req->queue, &ep->queue);
1116 spin_unlock_irqrestore(&dev->lock, flags);
1118 /* pci writes may still be posted */
1122 dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret);
1127 dma_done(struct net2280_ep *ep, struct net2280_request *req, u32 dmacount,
1130 req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount);
1131 done(ep, req, status);
1134 static int scan_dma_completions(struct net2280_ep *ep)
1136 int num_completed = 0;
1138 /* only look at descriptors that were "naturally" retired,
1139 * so fifo and list head state won't matter
1141 while (!list_empty(&ep->queue)) {
1142 struct net2280_request *req;
1145 req = list_entry(ep->queue.next,
1146 struct net2280_request, queue);
1150 req_dma_count = le32_to_cpup(&req->td->dmacount);
1151 if ((req_dma_count & BIT(VALID_BIT)) != 0)
1154 /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
1155 * cases where DMA must be aborted; this code handles
1156 * all non-abort DMA completions.
1158 if (unlikely(req->td->dmadesc == 0)) {
1160 u32 const ep_dmacount = readl(&ep->dma->dmacount);
1162 if (ep_dmacount & DMA_BYTE_COUNT_MASK)
1164 /* single transfer mode */
1165 dma_done(ep, req, req_dma_count, 0);
1168 } else if (!ep->is_in &&
1169 (req->req.length % ep->ep.maxpacket) &&
1170 !(ep->dev->quirks & PLX_PCIE)) {
1172 u32 const ep_stat = readl(&ep->regs->ep_stat);
1173 /* AVOID TROUBLE HERE by not issuing short reads from
1174 * your gadget driver. That helps avoids errata 0121,
1175 * 0122, and 0124; not all cases trigger the warning.
1177 if ((ep_stat & BIT(NAK_OUT_PACKETS)) == 0) {
1178 ep_warn(ep->dev, "%s lost packet sync!\n",
1180 req->req.status = -EOVERFLOW;
1182 u32 const ep_avail = readl(&ep->regs->ep_avail);
1184 /* fifo gets flushed later */
1185 ep->out_overflow = 1;
1187 "%s dma, discard %d len %d\n",
1188 ep->ep.name, ep_avail,
1190 req->req.status = -EOVERFLOW;
1194 dma_done(ep, req, req_dma_count, 0);
1198 return num_completed;
1201 static void restart_dma(struct net2280_ep *ep)
1203 struct net2280_request *req;
1207 req = list_entry(ep->queue.next, struct net2280_request, queue);
1212 static void abort_dma(struct net2280_ep *ep)
1214 /* abort the current transfer */
1215 if (likely(!list_empty(&ep->queue))) {
1216 /* FIXME work around errata 0121, 0122, 0124 */
1217 writel(BIT(DMA_ABORT), &ep->dma->dmastat);
1218 spin_stop_dma(ep->dma);
1221 scan_dma_completions(ep);
1224 /* dequeue ALL requests */
1225 static void nuke(struct net2280_ep *ep)
1227 struct net2280_request *req;
1229 /* called with spinlock held */
1233 while (!list_empty(&ep->queue)) {
1234 req = list_entry(ep->queue.next,
1235 struct net2280_request,
1237 done(ep, req, -ESHUTDOWN);
1241 /* dequeue JUST ONE request */
1242 static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1244 struct net2280_ep *ep;
1245 struct net2280_request *req;
1246 unsigned long flags;
1250 ep = container_of(_ep, struct net2280_ep, ep);
1251 if (!_ep || (!ep->desc && ep->num != 0) || !_req) {
1252 pr_err("%s: Invalid ep=%p or ep->desc or req=%p\n",
1253 __func__, _ep, _req);
1257 spin_lock_irqsave(&ep->dev->lock, flags);
1258 stopped = ep->stopped;
1260 /* quiesce dma while we patch the queue */
1264 dmactl = readl(&ep->dma->dmactl);
1265 /* WARNING erratum 0127 may kick in ... */
1267 scan_dma_completions(ep);
1270 /* make sure it's still queued on this endpoint */
1271 list_for_each_entry(req, &ep->queue, queue) {
1272 if (&req->req == _req)
1275 if (&req->req != _req) {
1276 ep->stopped = stopped;
1277 spin_unlock_irqrestore(&ep->dev->lock, flags);
1278 ep_dbg(ep->dev, "%s: Request mismatch\n", __func__);
1282 /* queue head may be partially complete. */
1283 if (ep->queue.next == &req->queue) {
1285 ep_dbg(ep->dev, "unlink (%s) dma\n", _ep->name);
1286 _req->status = -ECONNRESET;
1288 if (likely(ep->queue.next == &req->queue)) {
1289 /* NOTE: misreports single-transfer mode*/
1290 req->td->dmacount = 0; /* invalidate */
1292 readl(&ep->dma->dmacount),
1296 ep_dbg(ep->dev, "unlink (%s) pio\n", _ep->name);
1297 done(ep, req, -ECONNRESET);
1303 done(ep, req, -ECONNRESET);
1304 ep->stopped = stopped;
1307 /* turn off dma on inactive queues */
1308 if (list_empty(&ep->queue))
1310 else if (!ep->stopped) {
1311 /* resume current request, or start new one */
1313 writel(dmactl, &ep->dma->dmactl);
1315 start_dma(ep, list_entry(ep->queue.next,
1316 struct net2280_request, queue));
1320 spin_unlock_irqrestore(&ep->dev->lock, flags);
1324 /*-------------------------------------------------------------------------*/
1326 static int net2280_fifo_status(struct usb_ep *_ep);
1329 net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
1331 struct net2280_ep *ep;
1332 unsigned long flags;
1335 ep = container_of(_ep, struct net2280_ep, ep);
1336 if (!_ep || (!ep->desc && ep->num != 0)) {
1337 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1340 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) {
1341 retval = -ESHUTDOWN;
1344 if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03)
1345 == USB_ENDPOINT_XFER_ISOC) {
1350 spin_lock_irqsave(&ep->dev->lock, flags);
1351 if (!list_empty(&ep->queue)) {
1354 } else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) {
1358 ep_vdbg(ep->dev, "%s %s %s\n", _ep->name,
1359 value ? "set" : "clear",
1360 wedged ? "wedge" : "halt");
1361 /* set/clear, then synch memory views with the device */
1364 ep->dev->protocol_stall = 1;
1371 if (ep->dev->quirks & PLX_PCIE &&
1372 !list_empty(&ep->queue) && ep->td_dma)
1376 (void) readl(&ep->regs->ep_rsp);
1378 spin_unlock_irqrestore(&ep->dev->lock, flags);
1383 spin_unlock_irqrestore(&ep->dev->lock, flags);
1385 dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, retval);
1389 static int net2280_set_halt(struct usb_ep *_ep, int value)
1391 return net2280_set_halt_and_wedge(_ep, value, 0);
1394 static int net2280_set_wedge(struct usb_ep *_ep)
1396 if (!_ep || _ep->name == ep0name) {
1397 pr_err("%s: Invalid ep=%p or ep0\n", __func__, _ep);
1400 return net2280_set_halt_and_wedge(_ep, 1, 1);
1403 static int net2280_fifo_status(struct usb_ep *_ep)
1405 struct net2280_ep *ep;
1408 ep = container_of(_ep, struct net2280_ep, ep);
1409 if (!_ep || (!ep->desc && ep->num != 0)) {
1410 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1413 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) {
1414 dev_err(&ep->dev->pdev->dev,
1415 "%s: Invalid driver=%p or speed=%d\n",
1416 __func__, ep->dev->driver, ep->dev->gadget.speed);
1420 avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1);
1421 if (avail > ep->fifo_size) {
1422 dev_err(&ep->dev->pdev->dev, "%s: Fifo overflow\n", __func__);
1426 avail = ep->fifo_size - avail;
1430 static void net2280_fifo_flush(struct usb_ep *_ep)
1432 struct net2280_ep *ep;
1434 ep = container_of(_ep, struct net2280_ep, ep);
1435 if (!_ep || (!ep->desc && ep->num != 0)) {
1436 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep);
1439 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) {
1440 dev_err(&ep->dev->pdev->dev,
1441 "%s: Invalid driver=%p or speed=%d\n",
1442 __func__, ep->dev->driver, ep->dev->gadget.speed);
1446 writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
1447 (void) readl(&ep->regs->ep_rsp);
1450 static const struct usb_ep_ops net2280_ep_ops = {
1451 .enable = net2280_enable,
1452 .disable = net2280_disable,
1454 .alloc_request = net2280_alloc_request,
1455 .free_request = net2280_free_request,
1457 .queue = net2280_queue,
1458 .dequeue = net2280_dequeue,
1460 .set_halt = net2280_set_halt,
1461 .set_wedge = net2280_set_wedge,
1462 .fifo_status = net2280_fifo_status,
1463 .fifo_flush = net2280_fifo_flush,
1466 /*-------------------------------------------------------------------------*/
1468 static int net2280_get_frame(struct usb_gadget *_gadget)
1470 struct net2280 *dev;
1471 unsigned long flags;
1476 dev = container_of(_gadget, struct net2280, gadget);
1477 spin_lock_irqsave(&dev->lock, flags);
1478 retval = get_idx_reg(dev->regs, REG_FRAME) & 0x03ff;
1479 spin_unlock_irqrestore(&dev->lock, flags);
1483 static int net2280_wakeup(struct usb_gadget *_gadget)
1485 struct net2280 *dev;
1487 unsigned long flags;
1491 dev = container_of(_gadget, struct net2280, gadget);
1493 spin_lock_irqsave(&dev->lock, flags);
1494 tmp = readl(&dev->usb->usbctl);
1495 if (tmp & BIT(DEVICE_REMOTE_WAKEUP_ENABLE))
1496 writel(BIT(GENERATE_RESUME), &dev->usb->usbstat);
1497 spin_unlock_irqrestore(&dev->lock, flags);
1499 /* pci writes may still be posted */
1503 static int net2280_set_selfpowered(struct usb_gadget *_gadget, int value)
1505 struct net2280 *dev;
1507 unsigned long flags;
1511 dev = container_of(_gadget, struct net2280, gadget);
1513 spin_lock_irqsave(&dev->lock, flags);
1514 tmp = readl(&dev->usb->usbctl);
1516 tmp |= BIT(SELF_POWERED_STATUS);
1517 _gadget->is_selfpowered = 1;
1519 tmp &= ~BIT(SELF_POWERED_STATUS);
1520 _gadget->is_selfpowered = 0;
1522 writel(tmp, &dev->usb->usbctl);
1523 spin_unlock_irqrestore(&dev->lock, flags);
1528 static int net2280_pullup(struct usb_gadget *_gadget, int is_on)
1530 struct net2280 *dev;
1532 unsigned long flags;
1536 dev = container_of(_gadget, struct net2280, gadget);
1538 spin_lock_irqsave(&dev->lock, flags);
1539 tmp = readl(&dev->usb->usbctl);
1540 dev->softconnect = (is_on != 0);
1543 writel(tmp | BIT(USB_DETECT_ENABLE), &dev->usb->usbctl);
1545 writel(tmp & ~BIT(USB_DETECT_ENABLE), &dev->usb->usbctl);
1546 stop_activity(dev, NULL);
1549 spin_unlock_irqrestore(&dev->lock, flags);
1554 static struct usb_ep *net2280_match_ep(struct usb_gadget *_gadget,
1555 struct usb_endpoint_descriptor *desc,
1556 struct usb_ss_ep_comp_descriptor *ep_comp)
1561 if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT) {
1562 /* ep-e, ep-f are PIO with only 64 byte fifos */
1563 ep = gadget_find_ep_by_name(_gadget, "ep-e");
1564 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1566 ep = gadget_find_ep_by_name(_gadget, "ep-f");
1567 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1571 /* USB3380: Only first four endpoints have DMA channels. Allocate
1572 * slower interrupt endpoints from PIO hw endpoints, to allow bulk/isoc
1573 * endpoints use DMA hw endpoints.
1575 if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT &&
1576 usb_endpoint_dir_in(desc)) {
1577 ep = gadget_find_ep_by_name(_gadget, "ep2in");
1578 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1580 ep = gadget_find_ep_by_name(_gadget, "ep4in");
1581 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1583 } else if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT &&
1584 !usb_endpoint_dir_in(desc)) {
1585 ep = gadget_find_ep_by_name(_gadget, "ep1out");
1586 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1588 ep = gadget_find_ep_by_name(_gadget, "ep3out");
1589 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1591 } else if (usb_endpoint_type(desc) != USB_ENDPOINT_XFER_BULK &&
1592 usb_endpoint_dir_in(desc)) {
1593 ep = gadget_find_ep_by_name(_gadget, "ep1in");
1594 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1596 ep = gadget_find_ep_by_name(_gadget, "ep3in");
1597 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1599 } else if (usb_endpoint_type(desc) != USB_ENDPOINT_XFER_BULK &&
1600 !usb_endpoint_dir_in(desc)) {
1601 ep = gadget_find_ep_by_name(_gadget, "ep2out");
1602 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1604 ep = gadget_find_ep_by_name(_gadget, "ep4out");
1605 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1609 /* USB3380: use same address for usb and hardware endpoints */
1610 snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
1611 usb_endpoint_dir_in(desc) ? "in" : "out");
1612 ep = gadget_find_ep_by_name(_gadget, name);
1613 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1619 static int net2280_start(struct usb_gadget *_gadget,
1620 struct usb_gadget_driver *driver);
1621 static int net2280_stop(struct usb_gadget *_gadget);
1623 static const struct usb_gadget_ops net2280_ops = {
1624 .get_frame = net2280_get_frame,
1625 .wakeup = net2280_wakeup,
1626 .set_selfpowered = net2280_set_selfpowered,
1627 .pullup = net2280_pullup,
1628 .udc_start = net2280_start,
1629 .udc_stop = net2280_stop,
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->ll_lfps_regs->ll_lfps_5);
2249 val &= ~(0xf << TIMER_LFPS_6US);
2250 val |= 0x5 << TIMER_LFPS_6US;
2251 writel(val, &dev->ll_lfps_regs->ll_lfps_5);
2253 val = readl(&dev->ll_lfps_regs->ll_lfps_6);
2254 val &= ~(0xffff << TIMER_LFPS_80US);
2255 val |= 0x0100 << TIMER_LFPS_80US;
2256 writel(val, &dev->ll_lfps_regs->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->ll_tsn_regs->ll_tsn_counters_2);
2264 val &= ~(0x1f << HOT_TX_NORESET_TS2);
2265 val |= 0x10 << HOT_TX_NORESET_TS2;
2266 writel(val, &dev->ll_tsn_regs->ll_tsn_counters_2);
2268 val = readl(&dev->ll_tsn_regs->ll_tsn_counters_3);
2269 val &= ~(0x1f << HOT_RX_RESET_TS2);
2270 val |= 0x3 << HOT_RX_RESET_TS2;
2271 writel(val, &dev->ll_tsn_regs->ll_tsn_counters_3);
2274 * Set Recovery Idle to Recover bit:
2275 * - On SS connections, setting Recovery Idle to Recover Fmw improves
2276 * link robustness with various hosts and hubs.
2277 * - It is safe to set for all connection speeds; all chip revisions.
2278 * - R-M-W to leave other bits undisturbed.
2279 * - Reference PLX TT-7372
2281 val = readl(&dev->ll_chicken_reg->ll_tsn_chicken_bit);
2282 val |= BIT(RECOVERY_IDLE_TO_RECOVER_FMW);
2283 writel(val, &dev->ll_chicken_reg->ll_tsn_chicken_bit);
2285 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
2287 /* disable dedicated endpoints */
2288 writel(0x0D, &dev->dep[0].dep_cfg);
2289 writel(0x0D, &dev->dep[1].dep_cfg);
2290 writel(0x0E, &dev->dep[2].dep_cfg);
2291 writel(0x0E, &dev->dep[3].dep_cfg);
2292 writel(0x0F, &dev->dep[4].dep_cfg);
2293 writel(0x0C, &dev->dep[5].dep_cfg);
2296 static void usb_reinit(struct net2280 *dev)
2298 if (dev->quirks & PLX_LEGACY)
2299 return usb_reinit_228x(dev);
2300 return usb_reinit_338x(dev);
2303 static void ep0_start_228x(struct net2280 *dev)
2305 writel(BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
2306 BIT(CLEAR_NAK_OUT_PACKETS) |
2307 BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE),
2308 &dev->epregs[0].ep_rsp);
2311 * hardware optionally handles a bunch of standard requests
2312 * that the API hides from drivers anyway. have it do so.
2313 * endpoint status/features are handled in software, to
2314 * help pass tests for some dubious behavior.
2316 writel(BIT(SET_TEST_MODE) |
2318 BIT(DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP) |
2319 BIT(GET_DEVICE_STATUS) |
2320 BIT(GET_INTERFACE_STATUS),
2322 writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) |
2323 BIT(SELF_POWERED_USB_DEVICE) |
2324 BIT(REMOTE_WAKEUP_SUPPORT) |
2325 (dev->softconnect << USB_DETECT_ENABLE) |
2326 BIT(SELF_POWERED_STATUS),
2329 /* enable irqs so we can see ep0 and general operation */
2330 writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) |
2331 BIT(ENDPOINT_0_INTERRUPT_ENABLE),
2332 &dev->regs->pciirqenb0);
2333 writel(BIT(PCI_INTERRUPT_ENABLE) |
2334 BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE) |
2335 BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE) |
2336 BIT(PCI_RETRY_ABORT_INTERRUPT_ENABLE) |
2337 BIT(VBUS_INTERRUPT_ENABLE) |
2338 BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) |
2339 BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE),
2340 &dev->regs->pciirqenb1);
2342 /* don't leave any writes posted */
2343 (void) readl(&dev->usb->usbctl);
2346 static void ep0_start_338x(struct net2280 *dev)
2349 if (dev->bug7734_patched)
2350 writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE) |
2351 BIT(SET_EP_HIDE_STATUS_PHASE),
2352 &dev->epregs[0].ep_rsp);
2355 * hardware optionally handles a bunch of standard requests
2356 * that the API hides from drivers anyway. have it do so.
2357 * endpoint status/features are handled in software, to
2358 * help pass tests for some dubious behavior.
2360 writel(BIT(SET_ISOCHRONOUS_DELAY) |
2362 BIT(SET_TEST_MODE) |
2364 BIT(GET_INTERFACE_STATUS) |
2365 BIT(GET_DEVICE_STATUS),
2367 dev->wakeup_enable = 1;
2368 writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) |
2369 (dev->softconnect << USB_DETECT_ENABLE) |
2370 BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
2373 /* enable irqs so we can see ep0 and general operation */
2374 writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) |
2375 BIT(ENDPOINT_0_INTERRUPT_ENABLE),
2376 &dev->regs->pciirqenb0);
2377 writel(BIT(PCI_INTERRUPT_ENABLE) |
2378 BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) |
2379 BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE) |
2380 BIT(VBUS_INTERRUPT_ENABLE),
2381 &dev->regs->pciirqenb1);
2383 /* don't leave any writes posted */
2384 (void)readl(&dev->usb->usbctl);
2387 static void ep0_start(struct net2280 *dev)
2389 if (dev->quirks & PLX_LEGACY)
2390 return ep0_start_228x(dev);
2391 return ep0_start_338x(dev);
2394 /* when a driver is successfully registered, it will receive
2395 * control requests including set_configuration(), which enables
2396 * non-control requests. then usb traffic follows until a
2397 * disconnect is reported. then a host may connect again, or
2398 * the driver might get unbound.
2400 static int net2280_start(struct usb_gadget *_gadget,
2401 struct usb_gadget_driver *driver)
2403 struct net2280 *dev;
2407 /* insist on high speed support from the driver, since
2408 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
2409 * "must not be used in normal operation"
2411 if (!driver || driver->max_speed < USB_SPEED_HIGH ||
2415 dev = container_of(_gadget, struct net2280, gadget);
2417 for (i = 0; i < dev->n_ep; i++)
2418 dev->ep[i].irqs = 0;
2420 /* hook up the driver ... */
2421 driver->driver.bus = NULL;
2422 dev->driver = driver;
2424 retval = device_create_file(&dev->pdev->dev, &dev_attr_function);
2427 retval = device_create_file(&dev->pdev->dev, &dev_attr_queues);
2431 /* enable host detection and ep0; and we're ready
2432 * for set_configuration as well as eventual disconnect.
2434 net2280_led_active(dev, 1);
2436 if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
2437 defect7374_enable_data_eps_zero(dev);
2441 /* pci writes may still be posted */
2445 device_remove_file(&dev->pdev->dev, &dev_attr_function);
2451 static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver)
2455 /* don't disconnect if it's not connected */
2456 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
2459 /* stop hardware; prevent new request submissions;
2460 * and kill any outstanding requests.
2463 for (i = 0; i < dev->n_ep; i++)
2466 /* report disconnect; the driver is already quiesced */
2468 spin_unlock(&dev->lock);
2469 driver->disconnect(&dev->gadget);
2470 spin_lock(&dev->lock);
2476 static int net2280_stop(struct usb_gadget *_gadget)
2478 struct net2280 *dev;
2479 unsigned long flags;
2481 dev = container_of(_gadget, struct net2280, gadget);
2483 spin_lock_irqsave(&dev->lock, flags);
2484 stop_activity(dev, NULL);
2485 spin_unlock_irqrestore(&dev->lock, flags);
2487 net2280_led_active(dev, 0);
2489 device_remove_file(&dev->pdev->dev, &dev_attr_function);
2490 device_remove_file(&dev->pdev->dev, &dev_attr_queues);
2497 /*-------------------------------------------------------------------------*/
2499 /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
2500 * also works for dma-capable endpoints, in pio mode or just
2501 * to manually advance the queue after short OUT transfers.
2503 static void handle_ep_small(struct net2280_ep *ep)
2505 struct net2280_request *req;
2507 /* 0 error, 1 mid-data, 2 done */
2510 if (!list_empty(&ep->queue))
2511 req = list_entry(ep->queue.next,
2512 struct net2280_request, queue);
2516 /* ack all, and handle what we care about */
2517 t = readl(&ep->regs->ep_stat);
2520 ep_vdbg(ep->dev, "%s ack ep_stat %08x, req %p\n",
2521 ep->ep.name, t, req ? &req->req : NULL);
2523 if (!ep->is_in || (ep->dev->quirks & PLX_2280))
2524 writel(t & ~BIT(NAK_OUT_PACKETS), &ep->regs->ep_stat);
2526 /* Added for 2282 */
2527 writel(t, &ep->regs->ep_stat);
2529 /* for ep0, monitor token irqs to catch data stage length errors
2530 * and to synchronize on status.
2532 * also, to defer reporting of protocol stalls ... here's where
2533 * data or status first appears, handling stalls here should never
2534 * cause trouble on the host side..
2536 * control requests could be slightly faster without token synch for
2537 * status, but status can jam up that way.
2539 if (unlikely(ep->num == 0)) {
2541 /* status; stop NAKing */
2542 if (t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) {
2543 if (ep->dev->protocol_stall) {
2550 /* reply to extra IN data tokens with a zlp */
2551 } else if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) {
2552 if (ep->dev->protocol_stall) {
2556 } else if (ep->responded &&
2557 !req && !ep->stopped)
2558 write_fifo(ep, NULL);
2561 /* status; stop NAKing */
2562 if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) {
2563 if (ep->dev->protocol_stall) {
2568 /* an extra OUT token is an error */
2569 } else if (((t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) &&
2571 req->req.actual == req->req.length) ||
2572 (ep->responded && !req)) {
2573 ep->dev->protocol_stall = 1;
2577 done(ep, req, -EOVERFLOW);
2586 /* manual DMA queue advance after short OUT */
2587 if (likely(ep->dma)) {
2588 if (t & BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
2589 struct net2280_request *stuck_req = NULL;
2590 int stopped = ep->stopped;
2595 /* TRANSFERRED works around OUT_DONE erratum 0112.
2596 * we expect (N <= maxpacket) bytes; host wrote M.
2597 * iff (M < N) we won't ever see a DMA interrupt.
2600 for (count = 0; ; t = readl(&ep->regs->ep_stat)) {
2602 /* any preceding dma transfers must finish.
2603 * dma handles (M >= N), may empty the queue
2605 num_completed = scan_dma_completions(ep);
2606 if (unlikely(list_empty(&ep->queue) ||
2607 ep->out_overflow)) {
2611 req = list_entry(ep->queue.next,
2612 struct net2280_request, queue);
2614 /* here either (M < N), a "real" short rx;
2615 * or (M == N) and the queue didn't empty
2617 if (likely(t & BIT(FIFO_EMPTY))) {
2618 count = readl(&ep->dma->dmacount);
2619 count &= DMA_BYTE_COUNT_MASK;
2620 if (readl(&ep->dma->dmadesc)
2626 /* Escape loop if no dma transfers completed
2627 * after few retries.
2629 if (num_completed == 0) {
2630 if (stuck_req == req &&
2631 readl(&ep->dma->dmadesc) !=
2632 req->td_dma && stuck++ > 5) {
2634 &ep->dma->dmacount);
2635 count &= DMA_BYTE_COUNT_MASK;
2637 ep_dbg(ep->dev, "%s escape stuck %d, count %u\n",
2641 } else if (stuck_req != req) {
2653 /* stop DMA, leave ep NAKing */
2654 writel(BIT(DMA_ABORT), &ep->dma->dmastat);
2655 spin_stop_dma(ep->dma);
2658 req->td->dmacount = 0;
2659 t = readl(&ep->regs->ep_avail);
2660 dma_done(ep, req, count,
2661 (ep->out_overflow || t)
2665 /* also flush to prevent erratum 0106 trouble */
2666 if (unlikely(ep->out_overflow ||
2667 (ep->dev->chiprev == 0x0100 &&
2668 ep->dev->gadget.speed
2669 == USB_SPEED_FULL))) {
2671 ep->out_overflow = 0;
2674 /* (re)start dma if needed, stop NAKing */
2675 ep->stopped = stopped;
2676 if (!list_empty(&ep->queue))
2679 ep_dbg(ep->dev, "%s dma ep_stat %08x ??\n",
2683 /* data packet(s) received (in the fifo, OUT) */
2684 } else if (t & BIT(DATA_PACKET_RECEIVED_INTERRUPT)) {
2685 if (read_fifo(ep, req) && ep->num != 0)
2688 /* data packet(s) transmitted (IN) */
2689 } else if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT)) {
2692 len = req->req.length - req->req.actual;
2693 if (len > ep->ep.maxpacket)
2694 len = ep->ep.maxpacket;
2695 req->req.actual += len;
2697 /* if we wrote it all, we're usually done */
2698 /* send zlps until the status stage */
2699 if ((req->req.actual == req->req.length) &&
2700 (!req->req.zero || len != ep->ep.maxpacket) && ep->num)
2703 /* there was nothing to do ... */
2704 } else if (mode == 1)
2709 /* stream endpoints often resubmit/unlink in completion */
2712 /* maybe advance queue to next request */
2714 /* NOTE: net2280 could let gadget driver start the
2715 * status stage later. since not all controllers let
2716 * them control that, the api doesn't (yet) allow it.
2722 if (!list_empty(&ep->queue) && !ep->stopped)
2723 req = list_entry(ep->queue.next,
2724 struct net2280_request, queue);
2727 if (req && !ep->is_in)
2728 stop_out_naking(ep);
2732 /* is there a buffer for the next packet?
2733 * for best streaming performance, make sure there is one.
2735 if (req && !ep->stopped) {
2737 /* load IN fifo with next packet (may be zlp) */
2738 if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT))
2739 write_fifo(ep, &req->req);
2743 static struct net2280_ep *get_ep_by_addr(struct net2280 *dev, u16 wIndex)
2745 struct net2280_ep *ep;
2747 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
2749 list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) {
2750 u8 bEndpointAddress;
2754 bEndpointAddress = ep->desc->bEndpointAddress;
2755 if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
2757 if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f))
2763 static void defect7374_workaround(struct net2280 *dev, struct usb_ctrlrequest r)
2765 u32 scratch, fsmvalue;
2766 u32 ack_wait_timeout, state;
2768 /* Workaround for Defect 7374 (U1/U2 erroneously rejected): */
2769 scratch = get_idx_reg(dev->regs, SCRATCH);
2770 fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD);
2771 scratch &= ~(0xf << DEFECT7374_FSM_FIELD);
2773 if (!((fsmvalue == DEFECT7374_FSM_WAITING_FOR_CONTROL_READ) &&
2774 (r.bRequestType & USB_DIR_IN)))
2777 /* This is the first Control Read for this connection: */
2778 if (!(readl(&dev->usb->usbstat) & BIT(SUPER_SPEED_MODE))) {
2780 * Connection is NOT SS:
2781 * - Connection must be FS or HS.
2782 * - This FSM state should allow workaround software to
2783 * run after the next USB connection.
2785 scratch |= DEFECT7374_FSM_NON_SS_CONTROL_READ;
2786 dev->bug7734_patched = 1;
2787 goto restore_data_eps;
2790 /* Connection is SS: */
2791 for (ack_wait_timeout = 0;
2792 ack_wait_timeout < DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS;
2793 ack_wait_timeout++) {
2795 state = readl(&dev->plregs->pl_ep_status_1)
2797 if ((state >= (ACK_GOOD_NORMAL << STATE)) &&
2798 (state <= (ACK_GOOD_MORE_ACKS_TO_COME << STATE))) {
2799 scratch |= DEFECT7374_FSM_SS_CONTROL_READ;
2800 dev->bug7734_patched = 1;
2805 * We have not yet received host's Data Phase ACK
2806 * - Wait and try again.
2808 udelay(DEFECT_7374_PROCESSOR_WAIT_TIME);
2814 if (ack_wait_timeout >= DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS) {
2815 ep_err(dev, "FAIL: Defect 7374 workaround waited but failed "
2816 "to detect SS host's data phase ACK.");
2817 ep_err(dev, "PL_EP_STATUS_1(23:16):.Expected from 0x11 to 0x16"
2818 "got 0x%2.2x.\n", state >> STATE);
2820 ep_warn(dev, "INFO: Defect 7374 workaround waited about\n"
2821 "%duSec for Control Read Data Phase ACK\n",
2822 DEFECT_7374_PROCESSOR_WAIT_TIME * ack_wait_timeout);
2827 * Restore data EPs to their pre-workaround settings (disabled,
2828 * initialized, and other details).
2830 defect7374_disable_data_eps(dev);
2832 set_idx_reg(dev->regs, SCRATCH, scratch);
2837 static void ep_clear_seqnum(struct net2280_ep *ep)
2839 struct net2280 *dev = ep->dev;
2841 static const u32 ep_pl[9] = { 0, 3, 4, 7, 8, 2, 5, 6, 9 };
2843 val = readl(&dev->plregs->pl_ep_ctrl) & ~0x1f;
2844 val |= ep_pl[ep->num];
2845 writel(val, &dev->plregs->pl_ep_ctrl);
2846 val |= BIT(SEQUENCE_NUMBER_RESET);
2847 writel(val, &dev->plregs->pl_ep_ctrl);
2852 static void handle_stat0_irqs_superspeed(struct net2280 *dev,
2853 struct net2280_ep *ep, struct usb_ctrlrequest r)
2857 #define w_value le16_to_cpu(r.wValue)
2858 #define w_index le16_to_cpu(r.wIndex)
2859 #define w_length le16_to_cpu(r.wLength)
2861 switch (r.bRequest) {
2862 struct net2280_ep *e;
2865 case USB_REQ_SET_CONFIGURATION:
2866 dev->addressed_state = !w_value;
2869 case USB_REQ_GET_STATUS:
2870 switch (r.bRequestType) {
2871 case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2872 status = dev->wakeup_enable ? 0x02 : 0x00;
2873 if (dev->gadget.is_selfpowered)
2875 status |= (dev->u1_enable << 2 | dev->u2_enable << 3 |
2876 dev->ltm_enable << 4);
2877 writel(0, &dev->epregs[0].ep_irqenb);
2878 set_fifo_bytecount(ep, sizeof(status));
2879 writel((__force u32) status, &dev->epregs[0].ep_data);
2880 allow_status_338x(ep);
2883 case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2884 e = get_ep_by_addr(dev, w_index);
2887 status = readl(&e->regs->ep_rsp) &
2888 BIT(CLEAR_ENDPOINT_HALT);
2889 writel(0, &dev->epregs[0].ep_irqenb);
2890 set_fifo_bytecount(ep, sizeof(status));
2891 writel((__force u32) status, &dev->epregs[0].ep_data);
2892 allow_status_338x(ep);
2900 case USB_REQ_CLEAR_FEATURE:
2901 switch (r.bRequestType) {
2902 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2903 if (!dev->addressed_state) {
2905 case USB_DEVICE_U1_ENABLE:
2907 writel(readl(&dev->usb_ext->usbctl2) &
2909 &dev->usb_ext->usbctl2);
2910 allow_status_338x(ep);
2911 goto next_endpoints3;
2913 case USB_DEVICE_U2_ENABLE:
2915 writel(readl(&dev->usb_ext->usbctl2) &
2917 &dev->usb_ext->usbctl2);
2918 allow_status_338x(ep);
2919 goto next_endpoints3;
2921 case USB_DEVICE_LTM_ENABLE:
2922 dev->ltm_enable = 0;
2923 writel(readl(&dev->usb_ext->usbctl2) &
2925 &dev->usb_ext->usbctl2);
2926 allow_status_338x(ep);
2927 goto next_endpoints3;
2933 if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
2934 dev->wakeup_enable = 0;
2935 writel(readl(&dev->usb->usbctl) &
2936 ~BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
2938 allow_status_338x(ep);
2943 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2944 e = get_ep_by_addr(dev, w_index);
2947 if (w_value != USB_ENDPOINT_HALT)
2949 ep_vdbg(dev, "%s clear halt\n", e->ep.name);
2951 * Workaround for SS SeqNum not cleared via
2952 * Endpoint Halt (Clear) bit. select endpoint
2956 if (!list_empty(&e->queue) && e->td_dma)
2966 case USB_REQ_SET_FEATURE:
2967 switch (r.bRequestType) {
2968 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2969 if (!dev->addressed_state) {
2971 case USB_DEVICE_U1_ENABLE:
2973 writel(readl(&dev->usb_ext->usbctl2) |
2975 &dev->usb_ext->usbctl2);
2976 allow_status_338x(ep);
2977 goto next_endpoints3;
2979 case USB_DEVICE_U2_ENABLE:
2981 writel(readl(&dev->usb_ext->usbctl2) |
2983 &dev->usb_ext->usbctl2);
2984 allow_status_338x(ep);
2985 goto next_endpoints3;
2987 case USB_DEVICE_LTM_ENABLE:
2988 dev->ltm_enable = 1;
2989 writel(readl(&dev->usb_ext->usbctl2) |
2991 &dev->usb_ext->usbctl2);
2992 allow_status_338x(ep);
2993 goto next_endpoints3;
2999 if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
3000 dev->wakeup_enable = 1;
3001 writel(readl(&dev->usb->usbctl) |
3002 BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
3004 allow_status_338x(ep);
3009 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
3010 e = get_ep_by_addr(dev, w_index);
3011 if (!e || (w_value != USB_ENDPOINT_HALT))
3015 ep->dev->protocol_stall = 1;
3021 allow_status_338x(ep);
3032 ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x ep_cfg %08x\n",
3033 r.bRequestType, r.bRequest,
3034 w_value, w_index, w_length,
3035 readl(&ep->cfg->ep_cfg));
3038 spin_unlock(&dev->lock);
3039 tmp = dev->driver->setup(&dev->gadget, &r);
3040 spin_lock(&dev->lock);
3044 ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n",
3045 r.bRequestType, r.bRequest, tmp);
3046 dev->protocol_stall = 1;
3047 /* TD 9.9 Halt Endpoint test. TD 9.22 Set feature test */
3060 static void usb338x_handle_ep_intr(struct net2280 *dev, u32 stat0)
3065 for (index = 0; index < ARRAY_SIZE(ep_bit); index++) {
3066 bit = BIT(ep_bit[index]);
3076 handle_ep_small(&dev->ep[index]);
3080 static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
3082 struct net2280_ep *ep;
3085 /* most of these don't need individual acks */
3086 stat &= ~BIT(INTA_ASSERTED);
3089 /* ep_dbg(dev, "irqstat0 %04x\n", stat); */
3091 /* starting a control request? */
3092 if (unlikely(stat & BIT(SETUP_PACKET_INTERRUPT))) {
3095 struct usb_ctrlrequest r;
3098 struct net2280_request *req;
3100 if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
3101 u32 val = readl(&dev->usb->usbstat);
3102 if (val & BIT(SUPER_SPEED)) {
3103 dev->gadget.speed = USB_SPEED_SUPER;
3104 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3105 EP0_SS_MAX_PACKET_SIZE);
3106 } else if (val & BIT(HIGH_SPEED)) {
3107 dev->gadget.speed = USB_SPEED_HIGH;
3108 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3109 EP0_HS_MAX_PACKET_SIZE);
3111 dev->gadget.speed = USB_SPEED_FULL;
3112 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3113 EP0_HS_MAX_PACKET_SIZE);
3115 net2280_led_speed(dev, dev->gadget.speed);
3117 usb_speed_string(dev->gadget.speed));
3123 /* make sure any leftover request state is cleared */
3124 stat &= ~BIT(ENDPOINT_0_INTERRUPT);
3125 while (!list_empty(&ep->queue)) {
3126 req = list_entry(ep->queue.next,
3127 struct net2280_request, queue);
3128 done(ep, req, (req->req.actual == req->req.length)
3132 dev->protocol_stall = 0;
3133 if (!(dev->quirks & PLX_PCIE)) {
3134 if (ep->dev->quirks & PLX_2280)
3135 tmp = BIT(FIFO_OVERFLOW) |
3136 BIT(FIFO_UNDERFLOW);
3140 writel(tmp | BIT(TIMEOUT) |
3141 BIT(USB_STALL_SENT) |
3142 BIT(USB_IN_NAK_SENT) |
3143 BIT(USB_IN_ACK_RCVD) |
3144 BIT(USB_OUT_PING_NAK_SENT) |
3145 BIT(USB_OUT_ACK_SENT) |
3146 BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
3147 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
3148 BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
3149 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
3150 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3151 BIT(DATA_IN_TOKEN_INTERRUPT),
3152 &ep->regs->ep_stat);
3154 u.raw[0] = readl(&dev->usb->setup0123);
3155 u.raw[1] = readl(&dev->usb->setup4567);
3157 cpu_to_le32s(&u.raw[0]);
3158 cpu_to_le32s(&u.raw[1]);
3160 if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
3161 defect7374_workaround(dev, u.r);
3165 #define w_value le16_to_cpu(u.r.wValue)
3166 #define w_index le16_to_cpu(u.r.wIndex)
3167 #define w_length le16_to_cpu(u.r.wLength)
3170 writel(BIT(SETUP_PACKET_INTERRUPT), &dev->regs->irqstat0);
3171 stat ^= BIT(SETUP_PACKET_INTERRUPT);
3173 /* watch control traffic at the token level, and force
3174 * synchronization before letting the status stage happen.
3175 * FIXME ignore tokens we'll NAK, until driver responds.
3176 * that'll mean a lot less irqs for some drivers.
3178 ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0;
3180 scratch = BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
3181 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3182 BIT(DATA_IN_TOKEN_INTERRUPT);
3183 stop_out_naking(ep);
3185 scratch = BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
3186 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3187 BIT(DATA_IN_TOKEN_INTERRUPT);
3188 writel(scratch, &dev->epregs[0].ep_irqenb);
3190 /* we made the hardware handle most lowlevel requests;
3191 * everything else goes uplevel to the gadget code.
3195 if (dev->gadget.speed == USB_SPEED_SUPER) {
3196 handle_stat0_irqs_superspeed(dev, ep, u.r);
3197 goto next_endpoints;
3200 switch (u.r.bRequest) {
3201 case USB_REQ_GET_STATUS: {
3202 struct net2280_ep *e;
3205 /* hw handles device and interface status */
3206 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
3208 e = get_ep_by_addr(dev, w_index);
3209 if (!e || w_length > 2)
3212 if (readl(&e->regs->ep_rsp) & BIT(SET_ENDPOINT_HALT))
3213 status = cpu_to_le32(1);
3215 status = cpu_to_le32(0);
3217 /* don't bother with a request object! */
3218 writel(0, &dev->epregs[0].ep_irqenb);
3219 set_fifo_bytecount(ep, w_length);
3220 writel((__force u32)status, &dev->epregs[0].ep_data);
3222 ep_vdbg(dev, "%s stat %02x\n", ep->ep.name, status);
3223 goto next_endpoints;
3226 case USB_REQ_CLEAR_FEATURE: {
3227 struct net2280_ep *e;
3229 /* hw handles device features */
3230 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
3232 if (w_value != USB_ENDPOINT_HALT || w_length != 0)
3234 e = get_ep_by_addr(dev, w_index);
3238 ep_vdbg(dev, "%s wedged, halt not cleared\n",
3241 ep_vdbg(dev, "%s clear halt\n", e->ep.name);
3243 if ((ep->dev->quirks & PLX_PCIE) &&
3244 !list_empty(&e->queue) && e->td_dma)
3248 goto next_endpoints;
3251 case USB_REQ_SET_FEATURE: {
3252 struct net2280_ep *e;
3254 /* hw handles device features */
3255 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
3257 if (w_value != USB_ENDPOINT_HALT || w_length != 0)
3259 e = get_ep_by_addr(dev, w_index);
3262 if (e->ep.name == ep0name)
3265 if ((dev->quirks & PLX_PCIE) && e->dma)
3268 ep_vdbg(dev, "%s set halt\n", ep->ep.name);
3269 goto next_endpoints;
3274 ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x "
3276 u.r.bRequestType, u.r.bRequest,
3277 w_value, w_index, w_length,
3278 readl(&ep->cfg->ep_cfg));
3280 spin_unlock(&dev->lock);
3281 tmp = dev->driver->setup(&dev->gadget, &u.r);
3282 spin_lock(&dev->lock);
3285 /* stall ep0 on error */
3288 ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n",
3289 u.r.bRequestType, u.r.bRequest, tmp);
3290 dev->protocol_stall = 1;
3293 /* some in/out token irq should follow; maybe stall then.
3294 * driver must queue a request (even zlp) or halt ep0
3295 * before the host times out.
3304 if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
3305 u32 mask = (BIT(ENDPOINT_0_INTERRUPT) |
3306 USB3380_IRQSTAT0_EP_INTR_MASK_IN |
3307 USB3380_IRQSTAT0_EP_INTR_MASK_OUT);
3310 usb338x_handle_ep_intr(dev, stat & mask);
3314 /* endpoint data irq ? */
3315 scratch = stat & 0x7f;
3317 for (num = 0; scratch; num++) {
3320 /* do this endpoint's FIFO and queue need tending? */
3322 if ((scratch & t) == 0)
3327 handle_ep_small(ep);
3332 ep_dbg(dev, "unhandled irqstat0 %08x\n", stat);
3335 #define DMA_INTERRUPTS (BIT(DMA_D_INTERRUPT) | \
3336 BIT(DMA_C_INTERRUPT) | \
3337 BIT(DMA_B_INTERRUPT) | \
3338 BIT(DMA_A_INTERRUPT))
3339 #define PCI_ERROR_INTERRUPTS ( \
3340 BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT) | \
3341 BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT) | \
3342 BIT(PCI_RETRY_ABORT_INTERRUPT))
3344 static void handle_stat1_irqs(struct net2280 *dev, u32 stat)
3345 __releases(dev->lock)
3346 __acquires(dev->lock)
3348 struct net2280_ep *ep;
3349 u32 tmp, num, mask, scratch;
3351 /* after disconnect there's nothing else to do! */
3352 tmp = BIT(VBUS_INTERRUPT) | BIT(ROOT_PORT_RESET_INTERRUPT);
3353 mask = BIT(SUPER_SPEED) | BIT(HIGH_SPEED) | BIT(FULL_SPEED);
3355 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
3356 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and
3357 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
3358 * only indicates a change in the reset state).
3362 bool disconnect = false;
3365 * Ignore disconnects and resets if the speed hasn't been set.
3366 * VBUS can bounce and there's always an initial reset.
3368 writel(tmp, &dev->regs->irqstat1);
3369 if (dev->gadget.speed != USB_SPEED_UNKNOWN) {
3370 if ((stat & BIT(VBUS_INTERRUPT)) &&
3371 (readl(&dev->usb->usbctl) &
3372 BIT(VBUS_PIN)) == 0) {
3374 ep_dbg(dev, "disconnect %s\n",
3375 dev->driver->driver.name);
3376 } else if ((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) &&
3377 (readl(&dev->usb->usbstat) & mask)
3380 ep_dbg(dev, "reset %s\n",
3381 dev->driver->driver.name);
3384 if (disconnect || reset) {
3385 stop_activity(dev, dev->driver);
3387 spin_unlock(&dev->lock);
3389 usb_gadget_udc_reset
3390 (&dev->gadget, dev->driver);
3392 (dev->driver->disconnect)
3394 spin_lock(&dev->lock);
3400 /* vBUS can bounce ... one of many reasons to ignore the
3401 * notion of hotplug events on bus connect/disconnect!
3407 /* NOTE: chip stays in PCI D0 state for now, but it could
3408 * enter D1 to save more power
3410 tmp = BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT);
3412 writel(tmp, &dev->regs->irqstat1);
3413 spin_unlock(&dev->lock);
3414 if (stat & BIT(SUSPEND_REQUEST_INTERRUPT)) {
3415 if (dev->driver->suspend)
3416 dev->driver->suspend(&dev->gadget);
3417 if (!enable_suspend)
3418 stat &= ~BIT(SUSPEND_REQUEST_INTERRUPT);
3420 if (dev->driver->resume)
3421 dev->driver->resume(&dev->gadget);
3422 /* at high speed, note erratum 0133 */
3424 spin_lock(&dev->lock);
3428 /* clear any other status/irqs */
3430 writel(stat, &dev->regs->irqstat1);
3432 /* some status we can just ignore */
3433 if (dev->quirks & PLX_2280)
3434 stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) |
3435 BIT(SUSPEND_REQUEST_INTERRUPT) |
3436 BIT(RESUME_INTERRUPT) |
3437 BIT(SOF_INTERRUPT));
3439 stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) |
3440 BIT(RESUME_INTERRUPT) |
3441 BIT(SOF_DOWN_INTERRUPT) |
3442 BIT(SOF_INTERRUPT));
3446 /* ep_dbg(dev, "irqstat1 %08x\n", stat);*/
3448 /* DMA status, for ep-{a,b,c,d} */
3449 scratch = stat & DMA_INTERRUPTS;
3450 stat &= ~DMA_INTERRUPTS;
3452 for (num = 0; scratch; num++) {
3453 struct net2280_dma_regs __iomem *dma;
3456 if ((tmp & scratch) == 0)
3460 ep = &dev->ep[num + 1];
3466 /* clear ep's dma status */
3467 tmp = readl(&dma->dmastat);
3468 writel(tmp, &dma->dmastat);
3471 if (dev->quirks & PLX_PCIE) {
3472 u32 r_dmacount = readl(&dma->dmacount);
3473 if (!ep->is_in && (r_dmacount & 0x00FFFFFF) &&
3474 (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT)))
3478 if (!(tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) {
3479 ep_dbg(ep->dev, "%s no xact done? %08x\n",
3485 /* OUT transfers terminate when the data from the
3486 * host is in our memory. Process whatever's done.
3487 * On this path, we know transfer's last packet wasn't
3488 * less than req->length. NAK_OUT_PACKETS may be set,
3489 * or the FIFO may already be holding new packets.
3491 * IN transfers can linger in the FIFO for a very
3492 * long time ... we ignore that for now, accounting
3493 * precisely (like PIO does) needs per-packet irqs
3495 scan_dma_completions(ep);
3497 /* disable dma on inactive queues; else maybe restart */
3498 if (!list_empty(&ep->queue)) {
3499 tmp = readl(&dma->dmactl);
3505 /* NOTE: there are other PCI errors we might usefully notice.
3506 * if they appear very often, here's where to try recovering.
3508 if (stat & PCI_ERROR_INTERRUPTS) {
3509 ep_err(dev, "pci dma error; stat %08x\n", stat);
3510 stat &= ~PCI_ERROR_INTERRUPTS;
3511 /* these are fatal errors, but "maybe" they won't
3514 stop_activity(dev, dev->driver);
3520 ep_dbg(dev, "unhandled irqstat1 %08x\n", stat);
3523 static irqreturn_t net2280_irq(int irq, void *_dev)
3525 struct net2280 *dev = _dev;
3527 /* shared interrupt, not ours */
3528 if ((dev->quirks & PLX_LEGACY) &&
3529 (!(readl(&dev->regs->irqstat0) & BIT(INTA_ASSERTED))))
3532 spin_lock(&dev->lock);
3534 /* handle disconnect, dma, and more */
3535 handle_stat1_irqs(dev, readl(&dev->regs->irqstat1));
3537 /* control requests and PIO */
3538 handle_stat0_irqs(dev, readl(&dev->regs->irqstat0));
3540 if (dev->quirks & PLX_PCIE) {
3541 /* re-enable interrupt to trigger any possible new interrupt */
3542 u32 pciirqenb1 = readl(&dev->regs->pciirqenb1);
3543 writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1);
3544 writel(pciirqenb1, &dev->regs->pciirqenb1);
3547 spin_unlock(&dev->lock);
3552 /*-------------------------------------------------------------------------*/
3554 static void gadget_release(struct device *_dev)
3556 struct net2280 *dev = dev_get_drvdata(_dev);
3561 /* tear down the binding between this driver and the pci device */
3563 static void net2280_remove(struct pci_dev *pdev)
3565 struct net2280 *dev = pci_get_drvdata(pdev);
3567 usb_del_gadget_udc(&dev->gadget);
3569 BUG_ON(dev->driver);
3571 /* then clean up the resources we allocated during probe() */
3572 if (dev->requests) {
3574 for (i = 1; i < 5; i++) {
3575 if (!dev->ep[i].dummy)
3577 dma_pool_free(dev->requests, dev->ep[i].dummy,
3580 dma_pool_destroy(dev->requests);
3583 free_irq(pdev->irq, dev);
3584 if (dev->quirks & PLX_PCIE)
3585 pci_disable_msi(pdev);
3587 net2280_led_shutdown(dev);
3591 release_mem_region(pci_resource_start(pdev, 0),
3592 pci_resource_len(pdev, 0));
3594 pci_disable_device(pdev);
3595 device_remove_file(&pdev->dev, &dev_attr_registers);
3597 ep_info(dev, "unbind\n");
3600 /* wrap this driver around the specified device, but
3601 * don't respond over USB until a gadget driver binds to us.
3604 static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)
3606 struct net2280 *dev;
3607 unsigned long resource, len;
3608 void __iomem *base = NULL;
3611 /* alloc, and start init */
3612 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
3618 pci_set_drvdata(pdev, dev);
3619 spin_lock_init(&dev->lock);
3620 dev->quirks = id->driver_data;
3622 dev->gadget.ops = &net2280_ops;
3623 dev->gadget.max_speed = (dev->quirks & PLX_SUPERSPEED) ?
3624 USB_SPEED_SUPER : USB_SPEED_HIGH;
3626 /* the "gadget" abstracts/virtualizes the controller */
3627 dev->gadget.name = driver_name;
3629 /* now all the pci goodies ... */
3630 if (pci_enable_device(pdev) < 0) {
3636 /* BAR 0 holds all the registers
3637 * BAR 1 is 8051 memory; unused here (note erratum 0103)
3638 * BAR 2 is fifo memory; unused here
3640 resource = pci_resource_start(pdev, 0);
3641 len = pci_resource_len(pdev, 0);
3642 if (!request_mem_region(resource, len, driver_name)) {
3643 ep_dbg(dev, "controller already in use\n");
3649 /* FIXME provide firmware download interface to put
3650 * 8051 code into the chip, e.g. to turn on PCI PM.
3653 base = ioremap_nocache(resource, len);
3655 ep_dbg(dev, "can't map memory\n");
3659 dev->regs = (struct net2280_regs __iomem *) base;
3660 dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080);
3661 dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100);
3662 dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180);
3663 dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
3664 dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
3666 if (dev->quirks & PLX_PCIE) {
3669 dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *)
3671 dev->llregs = (struct usb338x_ll_regs __iomem *)
3673 dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *)
3675 dev->ll_tsn_regs = (struct usb338x_ll_tsn_regs __iomem *)
3677 dev->ll_chicken_reg = (struct usb338x_ll_chi_regs __iomem *)
3679 dev->plregs = (struct usb338x_pl_regs __iomem *)
3681 usbstat = readl(&dev->usb->usbstat);
3682 dev->enhanced_mode = !!(usbstat & BIT(11));
3683 dev->n_ep = (dev->enhanced_mode) ? 9 : 5;
3684 /* put into initial config, link up all endpoints */
3685 fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
3686 (0xf << DEFECT7374_FSM_FIELD);
3687 /* See if firmware needs to set up for workaround: */
3688 if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ) {
3689 dev->bug7734_patched = 1;
3690 writel(0, &dev->usb->usbctl);
3692 dev->bug7734_patched = 0;
3694 dev->enhanced_mode = 0;
3696 /* put into initial config, link up all endpoints */
3697 writel(0, &dev->usb->usbctl);
3703 /* irq setup after old hardware is cleaned up */
3705 ep_err(dev, "No IRQ. Check PCI setup!\n");
3710 if (dev->quirks & PLX_PCIE)
3711 if (pci_enable_msi(pdev))
3712 ep_err(dev, "Failed to enable MSI mode\n");
3714 if (request_irq(pdev->irq, net2280_irq, IRQF_SHARED,
3715 driver_name, dev)) {
3716 ep_err(dev, "request interrupt %d failed\n", pdev->irq);
3723 /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
3724 dev->requests = dma_pool_create("requests", &pdev->dev,
3725 sizeof(struct net2280_dma),
3726 0 /* no alignment requirements */,
3727 0 /* or page-crossing issues */);
3728 if (!dev->requests) {
3729 ep_dbg(dev, "can't get request pool\n");
3733 for (i = 1; i < 5; i++) {
3734 struct net2280_dma *td;
3736 td = dma_pool_alloc(dev->requests, GFP_KERNEL,
3737 &dev->ep[i].td_dma);
3739 ep_dbg(dev, "can't get dummy %d\n", i);
3743 td->dmacount = 0; /* not VALID */
3744 td->dmadesc = td->dmaaddr;
3745 dev->ep[i].dummy = td;
3748 /* enable lower-overhead pci memory bursts during DMA */
3749 if (dev->quirks & PLX_LEGACY)
3750 writel(BIT(DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE) |
3752 * 256 write retries may not be enough...
3753 BIT(PCI_RETRY_ABORT_ENABLE) |
3755 BIT(DMA_READ_MULTIPLE_ENABLE) |
3756 BIT(DMA_READ_LINE_ENABLE),
3757 &dev->pci->pcimstctl);
3758 /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
3759 pci_set_master(pdev);
3760 pci_try_set_mwi(pdev);
3762 /* ... also flushes any posted pci writes */
3763 dev->chiprev = get_idx_reg(dev->regs, REG_CHIPREV) & 0xffff;
3766 ep_info(dev, "%s\n", driver_desc);
3767 ep_info(dev, "irq %d, pci mem %p, chip rev %04x\n",
3768 pdev->irq, base, dev->chiprev);
3769 ep_info(dev, "version: " DRIVER_VERSION "; %s\n",
3770 dev->enhanced_mode ? "enhanced mode" : "legacy mode");
3771 retval = device_create_file(&pdev->dev, &dev_attr_registers);
3775 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
3783 net2280_remove(pdev);
3787 /* make sure the board is quiescent; otherwise it will continue
3788 * generating IRQs across the upcoming reboot.
3791 static void net2280_shutdown(struct pci_dev *pdev)
3793 struct net2280 *dev = pci_get_drvdata(pdev);
3796 writel(0, &dev->regs->pciirqenb0);
3797 writel(0, &dev->regs->pciirqenb1);
3799 /* disable the pullup so the host will think we're gone */
3800 writel(0, &dev->usb->usbctl);
3805 /*-------------------------------------------------------------------------*/
3807 static const struct pci_device_id pci_ids[] = { {
3808 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3810 .vendor = PCI_VENDOR_ID_PLX_LEGACY,
3812 .subvendor = PCI_ANY_ID,
3813 .subdevice = PCI_ANY_ID,
3814 .driver_data = PLX_LEGACY | PLX_2280,
3816 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3818 .vendor = PCI_VENDOR_ID_PLX_LEGACY,
3820 .subvendor = PCI_ANY_ID,
3821 .subdevice = PCI_ANY_ID,
3822 .driver_data = PLX_LEGACY,
3825 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3827 .vendor = PCI_VENDOR_ID_PLX,
3829 .subvendor = PCI_ANY_ID,
3830 .subdevice = PCI_ANY_ID,
3831 .driver_data = PLX_PCIE,
3834 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3836 .vendor = PCI_VENDOR_ID_PLX,
3838 .subvendor = PCI_ANY_ID,
3839 .subdevice = PCI_ANY_ID,
3840 .driver_data = PLX_PCIE | PLX_SUPERSPEED,
3843 .class = PCI_CLASS_SERIAL_USB_DEVICE,
3845 .vendor = PCI_VENDOR_ID_PLX,
3847 .subvendor = PCI_ANY_ID,
3848 .subdevice = PCI_ANY_ID,
3849 .driver_data = PLX_PCIE | PLX_SUPERSPEED,
3851 { /* end: all zeroes */ }
3853 MODULE_DEVICE_TABLE(pci, pci_ids);
3855 /* pci driver glue; this is a "new style" PCI driver module */
3856 static struct pci_driver net2280_pci_driver = {
3857 .name = (char *) driver_name,
3858 .id_table = pci_ids,
3860 .probe = net2280_probe,
3861 .remove = net2280_remove,
3862 .shutdown = net2280_shutdown,
3864 /* FIXME add power management support */
3867 module_pci_driver(net2280_pci_driver);
3869 MODULE_DESCRIPTION(DRIVER_DESC);
3870 MODULE_AUTHOR("David Brownell");
3871 MODULE_LICENSE("GPL");