2 * Driver for the PLX NET2280 USB device controller.
3 * Specs and errata are available from <http://www.plxtech.com>.
5 * PLX Technology Inc. (formerly NetChip Technology) supported the
6 * development of this driver.
9 * CODE STATUS HIGHLIGHTS
11 * This driver should work well with most "gadget" drivers, including
12 * the Mass Storage, Serial, and Ethernet/RNDIS gadget drivers
13 * as well as Gadget Zero and Gadgetfs.
15 * DMA is enabled by default.
17 * MSI is enabled by default. The legacy IRQ is used if MSI couldn't
20 * Note that almost all the errata workarounds here are only needed for
21 * rev1 chips. Rev1a silicon (0110) fixes almost all of them.
25 * Copyright (C) 2003 David Brownell
26 * Copyright (C) 2003-2005 PLX Technology, Inc.
27 * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
32 * Modified Ricardo Ribalda Qtechnology AS to provide compatibility
33 * with usb 338x chip. Based on PLX driver
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
41 #include <linux/module.h>
42 #include <linux/pci.h>
43 #include <linux/dma-mapping.h>
44 #include <linux/kernel.h>
45 #include <linux/delay.h>
46 #include <linux/ioport.h>
47 #include <linux/slab.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/timer.h>
51 #include <linux/list.h>
52 #include <linux/interrupt.h>
53 #include <linux/moduleparam.h>
54 #include <linux/device.h>
55 #include <linux/usb/ch9.h>
56 #include <linux/usb/gadget.h>
57 #include <linux/prefetch.h>
60 #include <asm/byteorder.h>
62 #include <asm/unaligned.h>
64 #define DRIVER_DESC "PLX NET228x/USB338x USB Peripheral Controller"
65 #define DRIVER_VERSION "2005 Sept 27/v3.0"
67 #define EP_DONTUSE 13 /* nonzero */
69 #define USE_RDK_LEDS /* GPIO pins control three LEDs */
72 static const char driver_name
[] = "net2280";
73 static const char driver_desc
[] = DRIVER_DESC
;
75 static const u32 ep_bit
[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };
76 static const char ep0name
[] = "ep0";
77 static const char *const ep_name
[] = {
79 "ep-a", "ep-b", "ep-c", "ep-d",
80 "ep-e", "ep-f", "ep-g", "ep-h",
83 /* Endpoint names for usb3380 advance mode */
84 static const char *const ep_name_adv
[] = {
86 "ep1in", "ep2out", "ep3in", "ep4out",
87 "ep1out", "ep2in", "ep3out", "ep4in",
90 /* mode 0 == ep-{a,b,c,d} 1K fifo each
91 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
92 * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
94 static ushort fifo_mode
;
96 /* "modprobe net2280 fifo_mode=1" etc */
97 module_param(fifo_mode
, ushort
, 0644);
99 /* enable_suspend -- When enabled, the driver will respond to
100 * USB suspend requests by powering down the NET2280. Otherwise,
101 * USB suspend requests will be ignored. This is acceptable for
102 * self-powered devices
104 static bool enable_suspend
;
106 /* "modprobe net2280 enable_suspend=1" etc */
107 module_param(enable_suspend
, bool, 0444);
109 #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
111 static char *type_string(u8 bmAttributes
)
113 switch ((bmAttributes
) & USB_ENDPOINT_XFERTYPE_MASK
) {
114 case USB_ENDPOINT_XFER_BULK
: return "bulk";
115 case USB_ENDPOINT_XFER_ISOC
: return "iso";
116 case USB_ENDPOINT_XFER_INT
: return "intr";
123 #define valid_bit cpu_to_le32(BIT(VALID_BIT))
124 #define dma_done_ie cpu_to_le32(BIT(DMA_DONE_INTERRUPT_ENABLE))
126 static void ep_clear_seqnum(struct net2280_ep
*ep
);
127 static void stop_activity(struct net2280
*dev
,
128 struct usb_gadget_driver
*driver
);
129 static void ep0_start(struct net2280
*dev
);
131 /*-------------------------------------------------------------------------*/
132 static inline void enable_pciirqenb(struct net2280_ep
*ep
)
134 u32 tmp
= readl(&ep
->dev
->regs
->pciirqenb0
);
136 if (ep
->dev
->quirks
& PLX_LEGACY
)
139 tmp
|= BIT(ep_bit
[ep
->num
]);
140 writel(tmp
, &ep
->dev
->regs
->pciirqenb0
);
146 net2280_enable(struct usb_ep
*_ep
, const struct usb_endpoint_descriptor
*desc
)
149 struct net2280_ep
*ep
;
154 static const u32 ep_key
[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 };
157 ep
= container_of(_ep
, struct net2280_ep
, ep
);
158 if (!_ep
|| !desc
|| ep
->desc
|| _ep
->name
== ep0name
||
159 desc
->bDescriptorType
!= USB_DT_ENDPOINT
) {
160 pr_err("%s: failed at line=%d\n", __func__
, __LINE__
);
164 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
169 /* erratum 0119 workaround ties up an endpoint number */
170 if ((desc
->bEndpointAddress
& 0x0f) == EP_DONTUSE
) {
175 if (dev
->quirks
& PLX_SUPERSPEED
) {
176 if ((desc
->bEndpointAddress
& 0x0f) >= 0x0c) {
180 ep
->is_in
= !!usb_endpoint_dir_in(desc
);
181 if (dev
->enhanced_mode
&& ep
->is_in
&& ep_key
[ep
->num
]) {
187 /* sanity check ep-e/ep-f since their fifos are small */
188 max
= usb_endpoint_maxp(desc
) & 0x1fff;
189 if (ep
->num
> 4 && max
> 64 && (dev
->quirks
& PLX_LEGACY
)) {
194 spin_lock_irqsave(&dev
->lock
, flags
);
195 _ep
->maxpacket
= max
& 0x7ff;
198 /* ep_reset() has already been called */
201 ep
->out_overflow
= 0;
203 /* set speed-dependent max packet; may kick in high bandwidth */
204 set_max_speed(ep
, max
);
206 /* set type, direction, address; reset fifo counters */
207 writel(BIT(FIFO_FLUSH
), &ep
->regs
->ep_stat
);
209 if ((dev
->quirks
& PLX_SUPERSPEED
) && dev
->enhanced_mode
) {
210 tmp
= readl(&ep
->cfg
->ep_cfg
);
211 /* If USB ep number doesn't match hardware ep number */
212 if ((tmp
& 0xf) != usb_endpoint_num(desc
)) {
214 spin_unlock_irqrestore(&dev
->lock
, flags
);
218 tmp
&= ~USB3380_EP_CFG_MASK_IN
;
220 tmp
&= ~USB3380_EP_CFG_MASK_OUT
;
222 type
= (desc
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
);
223 if (type
== USB_ENDPOINT_XFER_INT
) {
224 /* erratum 0105 workaround prevents hs NYET */
225 if (dev
->chiprev
== 0100 &&
226 dev
->gadget
.speed
== USB_SPEED_HIGH
&&
227 !(desc
->bEndpointAddress
& USB_DIR_IN
))
228 writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE
),
230 } else if (type
== USB_ENDPOINT_XFER_BULK
) {
231 /* catch some particularly blatant driver bugs */
232 if ((dev
->gadget
.speed
== USB_SPEED_SUPER
&& max
!= 1024) ||
233 (dev
->gadget
.speed
== USB_SPEED_HIGH
&& max
!= 512) ||
234 (dev
->gadget
.speed
== USB_SPEED_FULL
&& max
> 64)) {
235 spin_unlock_irqrestore(&dev
->lock
, flags
);
240 ep
->is_iso
= (type
== USB_ENDPOINT_XFER_ISOC
);
241 /* Enable this endpoint */
242 if (dev
->quirks
& PLX_LEGACY
) {
243 tmp
|= type
<< ENDPOINT_TYPE
;
244 tmp
|= desc
->bEndpointAddress
;
245 /* default full fifo lines */
246 tmp
|= (4 << ENDPOINT_BYTE_COUNT
);
247 tmp
|= BIT(ENDPOINT_ENABLE
);
248 ep
->is_in
= (tmp
& USB_DIR_IN
) != 0;
250 /* In Legacy mode, only OUT endpoints are used */
251 if (dev
->enhanced_mode
&& ep
->is_in
) {
252 tmp
|= type
<< IN_ENDPOINT_TYPE
;
253 tmp
|= BIT(IN_ENDPOINT_ENABLE
);
255 tmp
|= type
<< OUT_ENDPOINT_TYPE
;
256 tmp
|= BIT(OUT_ENDPOINT_ENABLE
);
257 tmp
|= (ep
->is_in
<< ENDPOINT_DIRECTION
);
260 tmp
|= (4 << ENDPOINT_BYTE_COUNT
);
261 if (!dev
->enhanced_mode
)
262 tmp
|= usb_endpoint_num(desc
);
263 tmp
|= (ep
->ep
.maxburst
<< MAX_BURST_SIZE
);
266 /* Make sure all the registers are written before ep_rsp*/
269 /* for OUT transfers, block the rx fifo until a read is posted */
271 writel(BIT(SET_NAK_OUT_PACKETS
), &ep
->regs
->ep_rsp
);
272 else if (!(dev
->quirks
& PLX_2280
)) {
273 /* Added for 2282, Don't use nak packets on an in endpoint,
274 * this was ignored on 2280
276 writel(BIT(CLEAR_NAK_OUT_PACKETS
) |
277 BIT(CLEAR_NAK_OUT_PACKETS_MODE
), &ep
->regs
->ep_rsp
);
280 if (dev
->quirks
& PLX_SUPERSPEED
)
282 writel(tmp
, &ep
->cfg
->ep_cfg
);
285 if (!ep
->dma
) { /* pio, per-packet */
286 enable_pciirqenb(ep
);
288 tmp
= BIT(DATA_PACKET_RECEIVED_INTERRUPT_ENABLE
) |
289 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE
);
290 if (dev
->quirks
& PLX_2280
)
291 tmp
|= readl(&ep
->regs
->ep_irqenb
);
292 writel(tmp
, &ep
->regs
->ep_irqenb
);
293 } else { /* dma, per-request */
294 tmp
= BIT((8 + ep
->num
)); /* completion */
295 tmp
|= readl(&dev
->regs
->pciirqenb1
);
296 writel(tmp
, &dev
->regs
->pciirqenb1
);
298 /* for short OUT transfers, dma completions can't
299 * advance the queue; do it pio-style, by hand.
300 * NOTE erratum 0112 workaround #2
302 if ((desc
->bEndpointAddress
& USB_DIR_IN
) == 0) {
303 tmp
= BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE
);
304 writel(tmp
, &ep
->regs
->ep_irqenb
);
306 enable_pciirqenb(ep
);
310 tmp
= desc
->bEndpointAddress
;
311 ep_dbg(dev
, "enabled %s (ep%d%s-%s) %s max %04x\n",
312 _ep
->name
, tmp
& 0x0f, DIR_STRING(tmp
),
313 type_string(desc
->bmAttributes
),
314 ep
->dma
? "dma" : "pio", max
);
316 /* pci writes may still be posted */
317 spin_unlock_irqrestore(&dev
->lock
, flags
);
321 dev_err(&ep
->dev
->pdev
->dev
, "%s: error=%d\n", __func__
, ret
);
325 static int handshake(u32 __iomem
*ptr
, u32 mask
, u32 done
, int usec
)
331 if (result
== ~(u32
)0) /* "device unplugged" */
342 static const struct usb_ep_ops net2280_ep_ops
;
344 static void ep_reset_228x(struct net2280_regs __iomem
*regs
,
345 struct net2280_ep
*ep
)
350 INIT_LIST_HEAD(&ep
->queue
);
352 usb_ep_set_maxpacket_limit(&ep
->ep
, ~0);
353 ep
->ep
.ops
= &net2280_ep_ops
;
355 /* disable the dma, irqs, endpoint... */
357 writel(0, &ep
->dma
->dmactl
);
358 writel(BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT
) |
359 BIT(DMA_TRANSACTION_DONE_INTERRUPT
) |
363 tmp
= readl(®s
->pciirqenb0
);
364 tmp
&= ~BIT(ep
->num
);
365 writel(tmp
, ®s
->pciirqenb0
);
367 tmp
= readl(®s
->pciirqenb1
);
368 tmp
&= ~BIT((8 + ep
->num
)); /* completion */
369 writel(tmp
, ®s
->pciirqenb1
);
371 writel(0, &ep
->regs
->ep_irqenb
);
373 /* init to our chosen defaults, notably so that we NAK OUT
374 * packets until the driver queues a read (+note erratum 0112)
376 if (!ep
->is_in
|| (ep
->dev
->quirks
& PLX_2280
)) {
377 tmp
= BIT(SET_NAK_OUT_PACKETS_MODE
) |
378 BIT(SET_NAK_OUT_PACKETS
) |
379 BIT(CLEAR_EP_HIDE_STATUS_PHASE
) |
380 BIT(CLEAR_INTERRUPT_MODE
);
383 tmp
= BIT(CLEAR_NAK_OUT_PACKETS_MODE
) |
384 BIT(CLEAR_NAK_OUT_PACKETS
) |
385 BIT(CLEAR_EP_HIDE_STATUS_PHASE
) |
386 BIT(CLEAR_INTERRUPT_MODE
);
390 tmp
|= BIT(CLEAR_ENDPOINT_TOGGLE
) |
391 BIT(CLEAR_ENDPOINT_HALT
);
393 writel(tmp
, &ep
->regs
->ep_rsp
);
395 /* scrub most status bits, and flush any fifo state */
396 if (ep
->dev
->quirks
& PLX_2280
)
397 tmp
= BIT(FIFO_OVERFLOW
) |
402 writel(tmp
| BIT(TIMEOUT
) |
403 BIT(USB_STALL_SENT
) |
404 BIT(USB_IN_NAK_SENT
) |
405 BIT(USB_IN_ACK_RCVD
) |
406 BIT(USB_OUT_PING_NAK_SENT
) |
407 BIT(USB_OUT_ACK_SENT
) |
409 BIT(SHORT_PACKET_OUT_DONE_INTERRUPT
) |
410 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT
) |
411 BIT(DATA_PACKET_RECEIVED_INTERRUPT
) |
412 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT
) |
413 BIT(DATA_OUT_PING_TOKEN_INTERRUPT
) |
414 BIT(DATA_IN_TOKEN_INTERRUPT
),
417 /* fifo size is handled separately */
420 static void ep_reset_338x(struct net2280_regs __iomem
*regs
,
421 struct net2280_ep
*ep
)
426 INIT_LIST_HEAD(&ep
->queue
);
428 usb_ep_set_maxpacket_limit(&ep
->ep
, ~0);
429 ep
->ep
.ops
= &net2280_ep_ops
;
431 /* disable the dma, irqs, endpoint... */
433 writel(0, &ep
->dma
->dmactl
);
434 writel(BIT(DMA_ABORT_DONE_INTERRUPT
) |
435 BIT(DMA_PAUSE_DONE_INTERRUPT
) |
436 BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT
) |
437 BIT(DMA_TRANSACTION_DONE_INTERRUPT
),
438 /* | BIT(DMA_ABORT), */
441 dmastat
= readl(&ep
->dma
->dmastat
);
442 if (dmastat
== 0x5002) {
443 ep_warn(ep
->dev
, "The dmastat return = %x!!\n",
445 writel(0x5a, &ep
->dma
->dmastat
);
448 tmp
= readl(®s
->pciirqenb0
);
449 tmp
&= ~BIT(ep_bit
[ep
->num
]);
450 writel(tmp
, ®s
->pciirqenb0
);
453 tmp
= readl(®s
->pciirqenb1
);
454 tmp
&= ~BIT((8 + ep
->num
)); /* completion */
455 writel(tmp
, ®s
->pciirqenb1
);
458 writel(0, &ep
->regs
->ep_irqenb
);
460 writel(BIT(SHORT_PACKET_OUT_DONE_INTERRUPT
) |
461 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT
) |
463 BIT(DATA_PACKET_RECEIVED_INTERRUPT
) |
464 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT
) |
465 BIT(DATA_OUT_PING_TOKEN_INTERRUPT
) |
466 BIT(DATA_IN_TOKEN_INTERRUPT
), &ep
->regs
->ep_stat
);
468 tmp
= readl(&ep
->cfg
->ep_cfg
);
470 tmp
&= ~USB3380_EP_CFG_MASK_IN
;
472 tmp
&= ~USB3380_EP_CFG_MASK_OUT
;
473 writel(tmp
, &ep
->cfg
->ep_cfg
);
476 static void nuke(struct net2280_ep
*);
478 static int net2280_disable(struct usb_ep
*_ep
)
480 struct net2280_ep
*ep
;
483 ep
= container_of(_ep
, struct net2280_ep
, ep
);
484 if (!_ep
|| !ep
->desc
|| _ep
->name
== ep0name
) {
485 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__
, _ep
);
488 spin_lock_irqsave(&ep
->dev
->lock
, flags
);
491 if (ep
->dev
->quirks
& PLX_SUPERSPEED
)
492 ep_reset_338x(ep
->dev
->regs
, ep
);
494 ep_reset_228x(ep
->dev
->regs
, ep
);
496 ep_vdbg(ep
->dev
, "disabled %s %s\n",
497 ep
->dma
? "dma" : "pio", _ep
->name
);
499 /* synch memory views with the device */
500 (void)readl(&ep
->cfg
->ep_cfg
);
502 if (!ep
->dma
&& ep
->num
>= 1 && ep
->num
<= 4)
503 ep
->dma
= &ep
->dev
->dma
[ep
->num
- 1];
505 spin_unlock_irqrestore(&ep
->dev
->lock
, flags
);
509 /*-------------------------------------------------------------------------*/
511 static struct usb_request
512 *net2280_alloc_request(struct usb_ep
*_ep
, gfp_t gfp_flags
)
514 struct net2280_ep
*ep
;
515 struct net2280_request
*req
;
518 pr_err("%s: Invalid ep\n", __func__
);
521 ep
= container_of(_ep
, struct net2280_ep
, ep
);
523 req
= kzalloc(sizeof(*req
), gfp_flags
);
527 INIT_LIST_HEAD(&req
->queue
);
529 /* this dma descriptor may be swapped with the previous dummy */
531 struct net2280_dma
*td
;
533 td
= pci_pool_alloc(ep
->dev
->requests
, gfp_flags
,
539 td
->dmacount
= 0; /* not VALID */
540 td
->dmadesc
= td
->dmaaddr
;
546 static void net2280_free_request(struct usb_ep
*_ep
, struct usb_request
*_req
)
548 struct net2280_ep
*ep
;
549 struct net2280_request
*req
;
551 ep
= container_of(_ep
, struct net2280_ep
, ep
);
553 dev_err(&ep
->dev
->pdev
->dev
, "%s: Inavlid ep=%p or req=%p\n",
554 __func__
, _ep
, _req
);
558 req
= container_of(_req
, struct net2280_request
, req
);
559 WARN_ON(!list_empty(&req
->queue
));
561 pci_pool_free(ep
->dev
->requests
, req
->td
, req
->td_dma
);
565 /*-------------------------------------------------------------------------*/
567 /* load a packet into the fifo we use for usb IN transfers.
568 * works for all endpoints.
570 * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
571 * at a time, but this code is simpler because it knows it only writes
572 * one packet. ep-a..ep-d should use dma instead.
574 static void write_fifo(struct net2280_ep
*ep
, struct usb_request
*req
)
576 struct net2280_ep_regs __iomem
*regs
= ep
->regs
;
579 unsigned count
, total
;
581 /* INVARIANT: fifo is currently empty. (testable) */
584 buf
= req
->buf
+ req
->actual
;
586 total
= req
->length
- req
->actual
;
592 /* write just one packet at a time */
593 count
= ep
->ep
.maxpacket
;
594 if (count
> total
) /* min() cannot be used on a bitfield */
597 ep_vdbg(ep
->dev
, "write %s fifo (IN) %d bytes%s req %p\n",
599 (count
!= ep
->ep
.maxpacket
) ? " (short)" : "",
602 /* NOTE be careful if you try to align these. fifo lines
603 * should normally be full (4 bytes) and successive partial
604 * lines are ok only in certain cases.
606 tmp
= get_unaligned((u32
*)buf
);
608 writel(tmp
, ®s
->ep_data
);
613 /* last fifo entry is "short" unless we wrote a full packet.
614 * also explicitly validate last word in (periodic) transfers
615 * when maxpacket is not a multiple of 4 bytes.
617 if (count
|| total
< ep
->ep
.maxpacket
) {
618 tmp
= count
? get_unaligned((u32
*)buf
) : count
;
620 set_fifo_bytecount(ep
, count
& 0x03);
621 writel(tmp
, ®s
->ep_data
);
624 /* pci writes may still be posted */
627 /* work around erratum 0106: PCI and USB race over the OUT fifo.
628 * caller guarantees chiprev 0100, out endpoint is NAKing, and
629 * there's no real data in the fifo.
631 * NOTE: also used in cases where that erratum doesn't apply:
632 * where the host wrote "too much" data to us.
634 static void out_flush(struct net2280_ep
*ep
)
639 statp
= &ep
->regs
->ep_stat
;
642 if (tmp
& BIT(NAK_OUT_PACKETS
)) {
643 ep_dbg(ep
->dev
, "%s %s %08x !NAK\n",
644 ep
->ep
.name
, __func__
, tmp
);
645 writel(BIT(SET_NAK_OUT_PACKETS
), &ep
->regs
->ep_rsp
);
648 writel(BIT(DATA_OUT_PING_TOKEN_INTERRUPT
) |
649 BIT(DATA_PACKET_RECEIVED_INTERRUPT
),
651 writel(BIT(FIFO_FLUSH
), statp
);
652 /* Make sure that stap is written */
655 if (tmp
& BIT(DATA_OUT_PING_TOKEN_INTERRUPT
) &&
656 /* high speed did bulk NYET; fifo isn't filling */
657 ep
->dev
->gadget
.speed
== USB_SPEED_FULL
) {
660 usec
= 50; /* 64 byte bulk/interrupt */
661 handshake(statp
, BIT(USB_OUT_PING_NAK_SENT
),
662 BIT(USB_OUT_PING_NAK_SENT
), usec
);
663 /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
667 /* unload packet(s) from the fifo we use for usb OUT transfers.
668 * returns true iff the request completed, because of short packet
669 * or the request buffer having filled with full packets.
671 * for ep-a..ep-d this will read multiple packets out when they
672 * have been accepted.
674 static int read_fifo(struct net2280_ep
*ep
, struct net2280_request
*req
)
676 struct net2280_ep_regs __iomem
*regs
= ep
->regs
;
677 u8
*buf
= req
->req
.buf
+ req
->req
.actual
;
678 unsigned count
, tmp
, is_short
;
679 unsigned cleanup
= 0, prevent
= 0;
681 /* erratum 0106 ... packets coming in during fifo reads might
682 * be incompletely rejected. not all cases have workarounds.
684 if (ep
->dev
->chiprev
== 0x0100 &&
685 ep
->dev
->gadget
.speed
== USB_SPEED_FULL
) {
687 tmp
= readl(&ep
->regs
->ep_stat
);
688 if ((tmp
& BIT(NAK_OUT_PACKETS
)))
690 else if ((tmp
& BIT(FIFO_FULL
))) {
691 start_out_naking(ep
);
694 /* else: hope we don't see the problem */
697 /* never overflow the rx buffer. the fifo reads packets until
698 * it sees a short one; we might not be ready for them all.
701 count
= readl(®s
->ep_avail
);
702 if (unlikely(count
== 0)) {
704 tmp
= readl(&ep
->regs
->ep_stat
);
705 count
= readl(®s
->ep_avail
);
706 /* handled that data already? */
707 if (count
== 0 && (tmp
& BIT(NAK_OUT_PACKETS
)) == 0)
711 tmp
= req
->req
.length
- req
->req
.actual
;
713 /* as with DMA, data overflow gets flushed */
714 if ((tmp
% ep
->ep
.maxpacket
) != 0) {
716 "%s out fifo %d bytes, expected %d\n",
717 ep
->ep
.name
, count
, tmp
);
718 req
->req
.status
= -EOVERFLOW
;
720 /* NAK_OUT_PACKETS will be set, so flushing is safe;
721 * the next read will start with the next packet
723 } /* else it's a ZLP, no worries */
726 req
->req
.actual
+= count
;
728 is_short
= (count
== 0) || ((count
% ep
->ep
.maxpacket
) != 0);
730 ep_vdbg(ep
->dev
, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
731 ep
->ep
.name
, count
, is_short
? " (short)" : "",
732 cleanup
? " flush" : "", prevent
? " nak" : "",
733 req
, req
->req
.actual
, req
->req
.length
);
736 tmp
= readl(®s
->ep_data
);
738 put_unaligned(tmp
, (u32
*)buf
);
743 tmp
= readl(®s
->ep_data
);
744 /* LE conversion is implicit here: */
753 writel(BIT(CLEAR_NAK_OUT_PACKETS
), &ep
->regs
->ep_rsp
);
754 (void) readl(&ep
->regs
->ep_rsp
);
757 return is_short
|| ((req
->req
.actual
== req
->req
.length
) &&
761 /* fill out dma descriptor to match a given request */
762 static void fill_dma_desc(struct net2280_ep
*ep
,
763 struct net2280_request
*req
, int valid
)
765 struct net2280_dma
*td
= req
->td
;
766 u32 dmacount
= req
->req
.length
;
768 /* don't let DMA continue after a short OUT packet,
769 * so overruns can't affect the next transfer.
770 * in case of overruns on max-size packets, we can't
771 * stop the fifo from filling but we can flush it.
774 dmacount
|= BIT(DMA_DIRECTION
);
775 if ((!ep
->is_in
&& (dmacount
% ep
->ep
.maxpacket
) != 0) ||
776 !(ep
->dev
->quirks
& PLX_2280
))
777 dmacount
|= BIT(END_OF_CHAIN
);
781 dmacount
|= BIT(VALID_BIT
);
782 dmacount
|= BIT(DMA_DONE_INTERRUPT_ENABLE
);
784 /* td->dmadesc = previously set by caller */
785 td
->dmaaddr
= cpu_to_le32 (req
->req
.dma
);
787 /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
789 td
->dmacount
= cpu_to_le32(dmacount
);
792 static const u32 dmactl_default
=
793 BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT
) |
794 BIT(DMA_CLEAR_COUNT_ENABLE
) |
795 /* erratum 0116 workaround part 1 (use POLLING) */
796 (POLL_100_USEC
<< DESCRIPTOR_POLLING_RATE
) |
797 BIT(DMA_VALID_BIT_POLLING_ENABLE
) |
798 BIT(DMA_VALID_BIT_ENABLE
) |
799 BIT(DMA_SCATTER_GATHER_ENABLE
) |
800 /* erratum 0116 workaround part 2 (no AUTOSTART) */
803 static inline void spin_stop_dma(struct net2280_dma_regs __iomem
*dma
)
805 handshake(&dma
->dmactl
, BIT(DMA_ENABLE
), 0, 50);
808 static inline void stop_dma(struct net2280_dma_regs __iomem
*dma
)
810 writel(readl(&dma
->dmactl
) & ~BIT(DMA_ENABLE
), &dma
->dmactl
);
814 static void start_queue(struct net2280_ep
*ep
, u32 dmactl
, u32 td_dma
)
816 struct net2280_dma_regs __iomem
*dma
= ep
->dma
;
817 unsigned int tmp
= BIT(VALID_BIT
) | (ep
->is_in
<< DMA_DIRECTION
);
819 if (!(ep
->dev
->quirks
& PLX_2280
))
820 tmp
|= BIT(END_OF_CHAIN
);
822 writel(tmp
, &dma
->dmacount
);
823 writel(readl(&dma
->dmastat
), &dma
->dmastat
);
825 writel(td_dma
, &dma
->dmadesc
);
826 if (ep
->dev
->quirks
& PLX_SUPERSPEED
)
827 dmactl
|= BIT(DMA_REQUEST_OUTSTANDING
);
828 writel(dmactl
, &dma
->dmactl
);
830 /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
831 (void) readl(&ep
->dev
->pci
->pcimstctl
);
833 writel(BIT(DMA_START
), &dma
->dmastat
);
839 static void start_dma(struct net2280_ep
*ep
, struct net2280_request
*req
)
842 struct net2280_dma_regs __iomem
*dma
= ep
->dma
;
844 /* FIXME can't use DMA for ZLPs */
846 /* on this path we "know" there's no dma active (yet) */
847 WARN_ON(readl(&dma
->dmactl
) & BIT(DMA_ENABLE
));
848 writel(0, &ep
->dma
->dmactl
);
850 /* previous OUT packet might have been short */
851 if (!ep
->is_in
&& (readl(&ep
->regs
->ep_stat
) &
852 BIT(NAK_OUT_PACKETS
))) {
853 writel(BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT
),
856 tmp
= readl(&ep
->regs
->ep_avail
);
858 writel(readl(&dma
->dmastat
), &dma
->dmastat
);
860 /* transfer all/some fifo data */
861 writel(req
->req
.dma
, &dma
->dmaaddr
);
862 tmp
= min(tmp
, req
->req
.length
);
864 /* dma irq, faking scatterlist status */
865 req
->td
->dmacount
= cpu_to_le32(req
->req
.length
- tmp
);
866 writel(BIT(DMA_DONE_INTERRUPT_ENABLE
) | tmp
,
868 req
->td
->dmadesc
= 0;
871 writel(BIT(DMA_ENABLE
), &dma
->dmactl
);
872 writel(BIT(DMA_START
), &dma
->dmastat
);
877 tmp
= dmactl_default
;
879 /* force packet boundaries between dma requests, but prevent the
880 * controller from automagically writing a last "short" packet
881 * (zero length) unless the driver explicitly said to do that.
884 if (likely((req
->req
.length
% ep
->ep
.maxpacket
) ||
886 tmp
|= BIT(DMA_FIFO_VALIDATE
);
887 ep
->in_fifo_validate
= 1;
889 ep
->in_fifo_validate
= 0;
892 /* init req->td, pointing to the current dummy */
893 req
->td
->dmadesc
= cpu_to_le32 (ep
->td_dma
);
894 fill_dma_desc(ep
, req
, 1);
896 req
->td
->dmacount
|= cpu_to_le32(BIT(END_OF_CHAIN
));
898 start_queue(ep
, tmp
, req
->td_dma
);
902 queue_dma(struct net2280_ep
*ep
, struct net2280_request
*req
, int valid
)
904 struct net2280_dma
*end
;
907 /* swap new dummy for old, link; fill and maybe activate */
913 ep
->td_dma
= req
->td_dma
;
916 end
->dmadesc
= cpu_to_le32 (ep
->td_dma
);
918 fill_dma_desc(ep
, req
, valid
);
922 done(struct net2280_ep
*ep
, struct net2280_request
*req
, int status
)
925 unsigned stopped
= ep
->stopped
;
927 list_del_init(&req
->queue
);
929 if (req
->req
.status
== -EINPROGRESS
)
930 req
->req
.status
= status
;
932 status
= req
->req
.status
;
936 usb_gadget_unmap_request(&dev
->gadget
, &req
->req
, ep
->is_in
);
938 if (status
&& status
!= -ESHUTDOWN
)
939 ep_vdbg(dev
, "complete %s req %p stat %d len %u/%u\n",
940 ep
->ep
.name
, &req
->req
, status
,
941 req
->req
.actual
, req
->req
.length
);
943 /* don't modify queue heads during completion callback */
945 spin_unlock(&dev
->lock
);
946 usb_gadget_giveback_request(&ep
->ep
, &req
->req
);
947 spin_lock(&dev
->lock
);
948 ep
->stopped
= stopped
;
951 /*-------------------------------------------------------------------------*/
954 net2280_queue(struct usb_ep
*_ep
, struct usb_request
*_req
, gfp_t gfp_flags
)
956 struct net2280_request
*req
;
957 struct net2280_ep
*ep
;
962 /* we always require a cpu-view buffer, so that we can
963 * always use pio (as fallback or whatever).
965 ep
= container_of(_ep
, struct net2280_ep
, ep
);
966 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0)) {
967 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__
, _ep
);
970 req
= container_of(_req
, struct net2280_request
, req
);
971 if (!_req
|| !_req
->complete
|| !_req
->buf
||
972 !list_empty(&req
->queue
)) {
976 if (_req
->length
> (~0 & DMA_BYTE_COUNT_MASK
)) {
981 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
986 /* FIXME implement PIO fallback for ZLPs with DMA */
987 if (ep
->dma
&& _req
->length
== 0) {
992 /* set up dma mapping in case the caller didn't */
994 ret
= usb_gadget_map_request(&dev
->gadget
, _req
,
1000 ep_vdbg(dev
, "%s queue req %p, len %d buf %p\n",
1001 _ep
->name
, _req
, _req
->length
, _req
->buf
);
1003 spin_lock_irqsave(&dev
->lock
, flags
);
1005 _req
->status
= -EINPROGRESS
;
1008 /* kickstart this i/o queue? */
1009 if (list_empty(&ep
->queue
) && !ep
->stopped
&&
1010 !((dev
->quirks
& PLX_SUPERSPEED
) && ep
->dma
&&
1011 (readl(&ep
->regs
->ep_rsp
) & BIT(CLEAR_ENDPOINT_HALT
)))) {
1013 /* use DMA if the endpoint supports it, else pio */
1017 /* maybe there's no control data, just status ack */
1018 if (ep
->num
== 0 && _req
->length
== 0) {
1021 ep_vdbg(dev
, "%s status ack\n", ep
->ep
.name
);
1025 /* PIO ... stuff the fifo, or unblock it. */
1027 write_fifo(ep
, _req
);
1028 else if (list_empty(&ep
->queue
)) {
1031 /* OUT FIFO might have packet(s) buffered */
1032 s
= readl(&ep
->regs
->ep_stat
);
1033 if ((s
& BIT(FIFO_EMPTY
)) == 0) {
1034 /* note: _req->short_not_ok is
1035 * ignored here since PIO _always_
1036 * stops queue advance here, and
1037 * _req->status doesn't change for
1038 * short reads (only _req->actual)
1040 if (read_fifo(ep
, req
) &&
1044 /* don't queue it */
1046 } else if (read_fifo(ep
, req
) &&
1051 s
= readl(&ep
->regs
->ep_stat
);
1054 /* don't NAK, let the fifo fill */
1055 if (req
&& (s
& BIT(NAK_OUT_PACKETS
)))
1056 writel(BIT(CLEAR_NAK_OUT_PACKETS
),
1061 } else if (ep
->dma
) {
1067 /* preventing magic zlps is per-engine state, not
1068 * per-transfer; irq logic must recover hiccups.
1070 expect
= likely(req
->req
.zero
||
1071 (req
->req
.length
% ep
->ep
.maxpacket
));
1072 if (expect
!= ep
->in_fifo_validate
)
1075 queue_dma(ep
, req
, valid
);
1077 } /* else the irq handler advances the queue. */
1081 list_add_tail(&req
->queue
, &ep
->queue
);
1083 spin_unlock_irqrestore(&dev
->lock
, flags
);
1085 /* pci writes may still be posted */
1089 dev_err(&ep
->dev
->pdev
->dev
, "%s: error=%d\n", __func__
, ret
);
1094 dma_done(struct net2280_ep
*ep
, struct net2280_request
*req
, u32 dmacount
,
1097 req
->req
.actual
= req
->req
.length
- (DMA_BYTE_COUNT_MASK
& dmacount
);
1098 done(ep
, req
, status
);
1101 static void scan_dma_completions(struct net2280_ep
*ep
)
1103 /* only look at descriptors that were "naturally" retired,
1104 * so fifo and list head state won't matter
1106 while (!list_empty(&ep
->queue
)) {
1107 struct net2280_request
*req
;
1110 req
= list_entry(ep
->queue
.next
,
1111 struct net2280_request
, queue
);
1115 tmp
= le32_to_cpup(&req
->td
->dmacount
);
1116 if ((tmp
& BIT(VALID_BIT
)) != 0)
1119 /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
1120 * cases where DMA must be aborted; this code handles
1121 * all non-abort DMA completions.
1123 if (unlikely(req
->td
->dmadesc
== 0)) {
1125 tmp
= readl(&ep
->dma
->dmacount
);
1126 if (tmp
& DMA_BYTE_COUNT_MASK
)
1128 /* single transfer mode */
1129 dma_done(ep
, req
, tmp
, 0);
1131 } else if (!ep
->is_in
&&
1132 (req
->req
.length
% ep
->ep
.maxpacket
) &&
1133 !(ep
->dev
->quirks
& PLX_SUPERSPEED
)) {
1135 tmp
= readl(&ep
->regs
->ep_stat
);
1136 /* AVOID TROUBLE HERE by not issuing short reads from
1137 * your gadget driver. That helps avoids errata 0121,
1138 * 0122, and 0124; not all cases trigger the warning.
1140 if ((tmp
& BIT(NAK_OUT_PACKETS
)) == 0) {
1141 ep_warn(ep
->dev
, "%s lost packet sync!\n",
1143 req
->req
.status
= -EOVERFLOW
;
1145 tmp
= readl(&ep
->regs
->ep_avail
);
1147 /* fifo gets flushed later */
1148 ep
->out_overflow
= 1;
1150 "%s dma, discard %d len %d\n",
1153 req
->req
.status
= -EOVERFLOW
;
1157 dma_done(ep
, req
, tmp
, 0);
1161 static void restart_dma(struct net2280_ep
*ep
)
1163 struct net2280_request
*req
;
1167 req
= list_entry(ep
->queue
.next
, struct net2280_request
, queue
);
1172 static void abort_dma(struct net2280_ep
*ep
)
1174 /* abort the current transfer */
1175 if (likely(!list_empty(&ep
->queue
))) {
1176 /* FIXME work around errata 0121, 0122, 0124 */
1177 writel(BIT(DMA_ABORT
), &ep
->dma
->dmastat
);
1178 spin_stop_dma(ep
->dma
);
1181 scan_dma_completions(ep
);
1184 /* dequeue ALL requests */
1185 static void nuke(struct net2280_ep
*ep
)
1187 struct net2280_request
*req
;
1189 /* called with spinlock held */
1193 while (!list_empty(&ep
->queue
)) {
1194 req
= list_entry(ep
->queue
.next
,
1195 struct net2280_request
,
1197 done(ep
, req
, -ESHUTDOWN
);
1201 /* dequeue JUST ONE request */
1202 static int net2280_dequeue(struct usb_ep
*_ep
, struct usb_request
*_req
)
1204 struct net2280_ep
*ep
;
1205 struct net2280_request
*req
;
1206 unsigned long flags
;
1210 ep
= container_of(_ep
, struct net2280_ep
, ep
);
1211 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0) || !_req
) {
1212 pr_err("%s: Invalid ep=%p or ep->desc or req=%p\n",
1213 __func__
, _ep
, _req
);
1217 spin_lock_irqsave(&ep
->dev
->lock
, flags
);
1218 stopped
= ep
->stopped
;
1220 /* quiesce dma while we patch the queue */
1224 dmactl
= readl(&ep
->dma
->dmactl
);
1225 /* WARNING erratum 0127 may kick in ... */
1227 scan_dma_completions(ep
);
1230 /* make sure it's still queued on this endpoint */
1231 list_for_each_entry(req
, &ep
->queue
, queue
) {
1232 if (&req
->req
== _req
)
1235 if (&req
->req
!= _req
) {
1236 spin_unlock_irqrestore(&ep
->dev
->lock
, flags
);
1237 dev_err(&ep
->dev
->pdev
->dev
, "%s: Request mismatch\n",
1242 /* queue head may be partially complete. */
1243 if (ep
->queue
.next
== &req
->queue
) {
1245 ep_dbg(ep
->dev
, "unlink (%s) dma\n", _ep
->name
);
1246 _req
->status
= -ECONNRESET
;
1248 if (likely(ep
->queue
.next
== &req
->queue
)) {
1249 /* NOTE: misreports single-transfer mode*/
1250 req
->td
->dmacount
= 0; /* invalidate */
1252 readl(&ep
->dma
->dmacount
),
1256 ep_dbg(ep
->dev
, "unlink (%s) pio\n", _ep
->name
);
1257 done(ep
, req
, -ECONNRESET
);
1263 done(ep
, req
, -ECONNRESET
);
1264 ep
->stopped
= stopped
;
1267 /* turn off dma on inactive queues */
1268 if (list_empty(&ep
->queue
))
1270 else if (!ep
->stopped
) {
1271 /* resume current request, or start new one */
1273 writel(dmactl
, &ep
->dma
->dmactl
);
1275 start_dma(ep
, list_entry(ep
->queue
.next
,
1276 struct net2280_request
, queue
));
1280 spin_unlock_irqrestore(&ep
->dev
->lock
, flags
);
1284 /*-------------------------------------------------------------------------*/
1286 static int net2280_fifo_status(struct usb_ep
*_ep
);
1289 net2280_set_halt_and_wedge(struct usb_ep
*_ep
, int value
, int wedged
)
1291 struct net2280_ep
*ep
;
1292 unsigned long flags
;
1295 ep
= container_of(_ep
, struct net2280_ep
, ep
);
1296 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0)) {
1297 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__
, _ep
);
1300 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
1301 retval
= -ESHUTDOWN
;
1304 if (ep
->desc
/* not ep0 */ && (ep
->desc
->bmAttributes
& 0x03)
1305 == USB_ENDPOINT_XFER_ISOC
) {
1310 spin_lock_irqsave(&ep
->dev
->lock
, flags
);
1311 if (!list_empty(&ep
->queue
)) {
1314 } else if (ep
->is_in
&& value
&& net2280_fifo_status(_ep
) != 0) {
1318 ep_vdbg(ep
->dev
, "%s %s %s\n", _ep
->name
,
1319 value
? "set" : "clear",
1320 wedged
? "wedge" : "halt");
1321 /* set/clear, then synch memory views with the device */
1324 ep
->dev
->protocol_stall
= 1;
1331 if (ep
->dev
->quirks
& PLX_SUPERSPEED
&&
1332 !list_empty(&ep
->queue
) && ep
->td_dma
)
1336 (void) readl(&ep
->regs
->ep_rsp
);
1338 spin_unlock_irqrestore(&ep
->dev
->lock
, flags
);
1343 spin_unlock_irqrestore(&ep
->dev
->lock
, flags
);
1345 dev_err(&ep
->dev
->pdev
->dev
, "%s: error=%d\n", __func__
, retval
);
1349 static int net2280_set_halt(struct usb_ep
*_ep
, int value
)
1351 return net2280_set_halt_and_wedge(_ep
, value
, 0);
1354 static int net2280_set_wedge(struct usb_ep
*_ep
)
1356 if (!_ep
|| _ep
->name
== ep0name
) {
1357 pr_err("%s: Invalid ep=%p or ep0\n", __func__
, _ep
);
1360 return net2280_set_halt_and_wedge(_ep
, 1, 1);
1363 static int net2280_fifo_status(struct usb_ep
*_ep
)
1365 struct net2280_ep
*ep
;
1368 ep
= container_of(_ep
, struct net2280_ep
, ep
);
1369 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0)) {
1370 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__
, _ep
);
1373 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
1374 dev_err(&ep
->dev
->pdev
->dev
,
1375 "%s: Invalid driver=%p or speed=%d\n",
1376 __func__
, ep
->dev
->driver
, ep
->dev
->gadget
.speed
);
1380 avail
= readl(&ep
->regs
->ep_avail
) & (BIT(12) - 1);
1381 if (avail
> ep
->fifo_size
) {
1382 dev_err(&ep
->dev
->pdev
->dev
, "%s: Fifo overflow\n", __func__
);
1386 avail
= ep
->fifo_size
- avail
;
1390 static void net2280_fifo_flush(struct usb_ep
*_ep
)
1392 struct net2280_ep
*ep
;
1394 ep
= container_of(_ep
, struct net2280_ep
, ep
);
1395 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0)) {
1396 pr_err("%s: Invalid ep=%p or ep->desc\n", __func__
, _ep
);
1399 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
1400 dev_err(&ep
->dev
->pdev
->dev
,
1401 "%s: Invalid driver=%p or speed=%d\n",
1402 __func__
, ep
->dev
->driver
, ep
->dev
->gadget
.speed
);
1406 writel(BIT(FIFO_FLUSH
), &ep
->regs
->ep_stat
);
1407 (void) readl(&ep
->regs
->ep_rsp
);
1410 static const struct usb_ep_ops net2280_ep_ops
= {
1411 .enable
= net2280_enable
,
1412 .disable
= net2280_disable
,
1414 .alloc_request
= net2280_alloc_request
,
1415 .free_request
= net2280_free_request
,
1417 .queue
= net2280_queue
,
1418 .dequeue
= net2280_dequeue
,
1420 .set_halt
= net2280_set_halt
,
1421 .set_wedge
= net2280_set_wedge
,
1422 .fifo_status
= net2280_fifo_status
,
1423 .fifo_flush
= net2280_fifo_flush
,
1426 /*-------------------------------------------------------------------------*/
1428 static int net2280_get_frame(struct usb_gadget
*_gadget
)
1430 struct net2280
*dev
;
1431 unsigned long flags
;
1436 dev
= container_of(_gadget
, struct net2280
, gadget
);
1437 spin_lock_irqsave(&dev
->lock
, flags
);
1438 retval
= get_idx_reg(dev
->regs
, REG_FRAME
) & 0x03ff;
1439 spin_unlock_irqrestore(&dev
->lock
, flags
);
1443 static int net2280_wakeup(struct usb_gadget
*_gadget
)
1445 struct net2280
*dev
;
1447 unsigned long flags
;
1451 dev
= container_of(_gadget
, struct net2280
, gadget
);
1453 spin_lock_irqsave(&dev
->lock
, flags
);
1454 tmp
= readl(&dev
->usb
->usbctl
);
1455 if (tmp
& BIT(DEVICE_REMOTE_WAKEUP_ENABLE
))
1456 writel(BIT(GENERATE_RESUME
), &dev
->usb
->usbstat
);
1457 spin_unlock_irqrestore(&dev
->lock
, flags
);
1459 /* pci writes may still be posted */
1463 static int net2280_set_selfpowered(struct usb_gadget
*_gadget
, int value
)
1465 struct net2280
*dev
;
1467 unsigned long flags
;
1471 dev
= container_of(_gadget
, struct net2280
, gadget
);
1473 spin_lock_irqsave(&dev
->lock
, flags
);
1474 tmp
= readl(&dev
->usb
->usbctl
);
1476 tmp
|= BIT(SELF_POWERED_STATUS
);
1477 _gadget
->is_selfpowered
= 1;
1479 tmp
&= ~BIT(SELF_POWERED_STATUS
);
1480 _gadget
->is_selfpowered
= 0;
1482 writel(tmp
, &dev
->usb
->usbctl
);
1483 spin_unlock_irqrestore(&dev
->lock
, flags
);
1488 static int net2280_pullup(struct usb_gadget
*_gadget
, int is_on
)
1490 struct net2280
*dev
;
1492 unsigned long flags
;
1496 dev
= container_of(_gadget
, struct net2280
, gadget
);
1498 spin_lock_irqsave(&dev
->lock
, flags
);
1499 tmp
= readl(&dev
->usb
->usbctl
);
1500 dev
->softconnect
= (is_on
!= 0);
1503 writel(tmp
| BIT(USB_DETECT_ENABLE
), &dev
->usb
->usbctl
);
1505 writel(tmp
& ~BIT(USB_DETECT_ENABLE
), &dev
->usb
->usbctl
);
1506 stop_activity(dev
, dev
->driver
);
1509 spin_unlock_irqrestore(&dev
->lock
, flags
);
1514 static int net2280_start(struct usb_gadget
*_gadget
,
1515 struct usb_gadget_driver
*driver
);
1516 static int net2280_stop(struct usb_gadget
*_gadget
);
1518 static const struct usb_gadget_ops net2280_ops
= {
1519 .get_frame
= net2280_get_frame
,
1520 .wakeup
= net2280_wakeup
,
1521 .set_selfpowered
= net2280_set_selfpowered
,
1522 .pullup
= net2280_pullup
,
1523 .udc_start
= net2280_start
,
1524 .udc_stop
= net2280_stop
,
1527 /*-------------------------------------------------------------------------*/
1529 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1531 /* FIXME move these into procfs, and use seq_file.
1532 * Sysfs _still_ doesn't behave for arbitrarily sized files,
1533 * and also doesn't help products using this with 2.4 kernels.
1536 /* "function" sysfs attribute */
1537 static ssize_t
function_show(struct device
*_dev
, struct device_attribute
*attr
,
1540 struct net2280
*dev
= dev_get_drvdata(_dev
);
1542 if (!dev
->driver
|| !dev
->driver
->function
||
1543 strlen(dev
->driver
->function
) > PAGE_SIZE
)
1545 return scnprintf(buf
, PAGE_SIZE
, "%s\n", dev
->driver
->function
);
1547 static DEVICE_ATTR_RO(function
);
1549 static ssize_t
registers_show(struct device
*_dev
,
1550 struct device_attribute
*attr
, char *buf
)
1552 struct net2280
*dev
;
1555 unsigned long flags
;
1560 dev
= dev_get_drvdata(_dev
);
1563 spin_lock_irqsave(&dev
->lock
, flags
);
1566 s
= dev
->driver
->driver
.name
;
1570 /* Main Control Registers */
1571 t
= scnprintf(next
, size
, "%s version " DRIVER_VERSION
1572 ", chiprev %04x\n\n"
1573 "devinit %03x fifoctl %08x gadget '%s'\n"
1574 "pci irqenb0 %02x irqenb1 %08x "
1575 "irqstat0 %04x irqstat1 %08x\n",
1576 driver_name
, dev
->chiprev
,
1577 readl(&dev
->regs
->devinit
),
1578 readl(&dev
->regs
->fifoctl
),
1580 readl(&dev
->regs
->pciirqenb0
),
1581 readl(&dev
->regs
->pciirqenb1
),
1582 readl(&dev
->regs
->irqstat0
),
1583 readl(&dev
->regs
->irqstat1
));
1587 /* USB Control Registers */
1588 t1
= readl(&dev
->usb
->usbctl
);
1589 t2
= readl(&dev
->usb
->usbstat
);
1590 if (t1
& BIT(VBUS_PIN
)) {
1591 if (t2
& BIT(HIGH_SPEED
))
1593 else if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1597 /* full speed bit (6) not working?? */
1600 t
= scnprintf(next
, size
,
1601 "stdrsp %08x usbctl %08x usbstat %08x "
1602 "addr 0x%02x (%s)\n",
1603 readl(&dev
->usb
->stdrsp
), t1
, t2
,
1604 readl(&dev
->usb
->ouraddr
), s
);
1608 /* PCI Master Control Registers */
1610 /* DMA Control Registers */
1612 /* Configurable EP Control Registers */
1613 for (i
= 0; i
< dev
->n_ep
; i
++) {
1614 struct net2280_ep
*ep
;
1620 t1
= readl(&ep
->cfg
->ep_cfg
);
1621 t2
= readl(&ep
->regs
->ep_rsp
) & 0xff;
1622 t
= scnprintf(next
, size
,
1623 "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
1625 ep
->ep
.name
, t1
, t2
,
1626 (t2
& BIT(CLEAR_NAK_OUT_PACKETS
))
1628 (t2
& BIT(CLEAR_EP_HIDE_STATUS_PHASE
))
1630 (t2
& BIT(CLEAR_EP_FORCE_CRC_ERROR
))
1632 (t2
& BIT(CLEAR_INTERRUPT_MODE
))
1633 ? "interrupt " : "",
1634 (t2
& BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE
))
1636 (t2
& BIT(CLEAR_NAK_OUT_PACKETS_MODE
))
1638 (t2
& BIT(CLEAR_ENDPOINT_TOGGLE
))
1639 ? "DATA1 " : "DATA0 ",
1640 (t2
& BIT(CLEAR_ENDPOINT_HALT
))
1642 readl(&ep
->regs
->ep_irqenb
));
1646 t
= scnprintf(next
, size
,
1647 "\tstat %08x avail %04x "
1649 readl(&ep
->regs
->ep_stat
),
1650 readl(&ep
->regs
->ep_avail
),
1651 t1
& 0x0f, DIR_STRING(t1
),
1652 type_string(t1
>> 8),
1653 ep
->stopped
? "*" : "");
1660 t
= scnprintf(next
, size
,
1661 " dma\tctl %08x stat %08x count %08x\n"
1662 "\taddr %08x desc %08x\n",
1663 readl(&ep
->dma
->dmactl
),
1664 readl(&ep
->dma
->dmastat
),
1665 readl(&ep
->dma
->dmacount
),
1666 readl(&ep
->dma
->dmaaddr
),
1667 readl(&ep
->dma
->dmadesc
));
1673 /* Indexed Registers (none yet) */
1676 t
= scnprintf(next
, size
, "\nirqs: ");
1679 for (i
= 0; i
< dev
->n_ep
; i
++) {
1680 struct net2280_ep
*ep
;
1685 t
= scnprintf(next
, size
, " %s/%lu", ep
->ep
.name
, ep
->irqs
);
1690 t
= scnprintf(next
, size
, "\n");
1694 spin_unlock_irqrestore(&dev
->lock
, flags
);
1696 return PAGE_SIZE
- size
;
1698 static DEVICE_ATTR_RO(registers
);
1700 static ssize_t
queues_show(struct device
*_dev
, struct device_attribute
*attr
,
1703 struct net2280
*dev
;
1706 unsigned long flags
;
1709 dev
= dev_get_drvdata(_dev
);
1712 spin_lock_irqsave(&dev
->lock
, flags
);
1714 for (i
= 0; i
< dev
->n_ep
; i
++) {
1715 struct net2280_ep
*ep
= &dev
->ep
[i
];
1716 struct net2280_request
*req
;
1720 const struct usb_endpoint_descriptor
*d
;
1725 t
= d
->bEndpointAddress
;
1726 t
= scnprintf(next
, size
,
1727 "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
1728 ep
->ep
.name
, t
& USB_ENDPOINT_NUMBER_MASK
,
1729 (t
& USB_DIR_IN
) ? "in" : "out",
1730 type_string(d
->bmAttributes
),
1731 usb_endpoint_maxp(d
) & 0x1fff,
1732 ep
->dma
? "dma" : "pio", ep
->fifo_size
1734 } else /* ep0 should only have one transfer queued */
1735 t
= scnprintf(next
, size
, "ep0 max 64 pio %s\n",
1736 ep
->is_in
? "in" : "out");
1737 if (t
<= 0 || t
> size
)
1742 if (list_empty(&ep
->queue
)) {
1743 t
= scnprintf(next
, size
, "\t(nothing queued)\n");
1744 if (t
<= 0 || t
> size
)
1750 list_for_each_entry(req
, &ep
->queue
, queue
) {
1751 if (ep
->dma
&& req
->td_dma
== readl(&ep
->dma
->dmadesc
))
1752 t
= scnprintf(next
, size
,
1753 "\treq %p len %d/%d "
1754 "buf %p (dmacount %08x)\n",
1755 &req
->req
, req
->req
.actual
,
1756 req
->req
.length
, req
->req
.buf
,
1757 readl(&ep
->dma
->dmacount
));
1759 t
= scnprintf(next
, size
,
1760 "\treq %p len %d/%d buf %p\n",
1761 &req
->req
, req
->req
.actual
,
1762 req
->req
.length
, req
->req
.buf
);
1763 if (t
<= 0 || t
> size
)
1769 struct net2280_dma
*td
;
1772 t
= scnprintf(next
, size
, "\t td %08x "
1773 " count %08x buf %08x desc %08x\n",
1775 le32_to_cpu(td
->dmacount
),
1776 le32_to_cpu(td
->dmaaddr
),
1777 le32_to_cpu(td
->dmadesc
));
1778 if (t
<= 0 || t
> size
)
1787 spin_unlock_irqrestore(&dev
->lock
, flags
);
1788 return PAGE_SIZE
- size
;
1790 static DEVICE_ATTR_RO(queues
);
1795 #define device_create_file(a, b) (0)
1796 #define device_remove_file(a, b) do { } while (0)
1800 /*-------------------------------------------------------------------------*/
1802 /* another driver-specific mode might be a request type doing dma
1803 * to/from another device fifo instead of to/from memory.
1806 static void set_fifo_mode(struct net2280
*dev
, int mode
)
1808 /* keeping high bits preserves BAR2 */
1809 writel((0xffff << PCI_BASE2_RANGE
) | mode
, &dev
->regs
->fifoctl
);
1811 /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */
1812 INIT_LIST_HEAD(&dev
->gadget
.ep_list
);
1813 list_add_tail(&dev
->ep
[1].ep
.ep_list
, &dev
->gadget
.ep_list
);
1814 list_add_tail(&dev
->ep
[2].ep
.ep_list
, &dev
->gadget
.ep_list
);
1817 list_add_tail(&dev
->ep
[3].ep
.ep_list
, &dev
->gadget
.ep_list
);
1818 list_add_tail(&dev
->ep
[4].ep
.ep_list
, &dev
->gadget
.ep_list
);
1819 dev
->ep
[1].fifo_size
= dev
->ep
[2].fifo_size
= 1024;
1822 dev
->ep
[1].fifo_size
= dev
->ep
[2].fifo_size
= 2048;
1825 list_add_tail(&dev
->ep
[3].ep
.ep_list
, &dev
->gadget
.ep_list
);
1826 dev
->ep
[1].fifo_size
= 2048;
1827 dev
->ep
[2].fifo_size
= 1024;
1830 /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */
1831 list_add_tail(&dev
->ep
[5].ep
.ep_list
, &dev
->gadget
.ep_list
);
1832 list_add_tail(&dev
->ep
[6].ep
.ep_list
, &dev
->gadget
.ep_list
);
1835 static void defect7374_disable_data_eps(struct net2280
*dev
)
1838 * For Defect 7374, disable data EPs (and more):
1839 * - This phase undoes the earlier phase of the Defect 7374 workaround,
1840 * returing ep regs back to normal.
1842 struct net2280_ep
*ep
;
1844 unsigned char ep_sel
;
1847 for (i
= 1; i
< 5; i
++) {
1849 writel(0, &ep
->cfg
->ep_cfg
);
1852 /* CSROUT, CSRIN, PCIOUT, PCIIN, STATIN, RCIN */
1853 for (i
= 0; i
< 6; i
++)
1854 writel(0, &dev
->dep
[i
].dep_cfg
);
1856 for (ep_sel
= 0; ep_sel
<= 21; ep_sel
++) {
1857 /* Select an endpoint for subsequent operations: */
1858 tmp_reg
= readl(&dev
->plregs
->pl_ep_ctrl
);
1859 writel(((tmp_reg
& ~0x1f) | ep_sel
), &dev
->plregs
->pl_ep_ctrl
);
1861 if (ep_sel
< 2 || (ep_sel
> 9 && ep_sel
< 14) ||
1862 ep_sel
== 18 || ep_sel
== 20)
1865 /* Change settings on some selected endpoints */
1866 tmp_reg
= readl(&dev
->plregs
->pl_ep_cfg_4
);
1867 tmp_reg
&= ~BIT(NON_CTRL_IN_TOLERATE_BAD_DIR
);
1868 writel(tmp_reg
, &dev
->plregs
->pl_ep_cfg_4
);
1869 tmp_reg
= readl(&dev
->plregs
->pl_ep_ctrl
);
1870 tmp_reg
|= BIT(EP_INITIALIZED
);
1871 writel(tmp_reg
, &dev
->plregs
->pl_ep_ctrl
);
1875 static void defect7374_enable_data_eps_zero(struct net2280
*dev
)
1877 u32 tmp
= 0, tmp_reg
;
1880 unsigned char ep_sel
;
1882 scratch
= get_idx_reg(dev
->regs
, SCRATCH
);
1884 WARN_ON((scratch
& (0xf << DEFECT7374_FSM_FIELD
))
1885 == DEFECT7374_FSM_SS_CONTROL_READ
);
1887 scratch
&= ~(0xf << DEFECT7374_FSM_FIELD
);
1889 ep_warn(dev
, "Operate Defect 7374 workaround soft this time");
1890 ep_warn(dev
, "It will operate on cold-reboot and SS connect");
1893 tmp
= ((0 << ENDPOINT_NUMBER
) | BIT(ENDPOINT_DIRECTION
) |
1894 (2 << OUT_ENDPOINT_TYPE
) | (2 << IN_ENDPOINT_TYPE
) |
1895 ((dev
->enhanced_mode
) ?
1896 BIT(OUT_ENDPOINT_ENABLE
) | BIT(IN_ENDPOINT_ENABLE
) :
1897 BIT(ENDPOINT_ENABLE
)));
1899 for (i
= 1; i
< 5; i
++)
1900 writel(tmp
, &dev
->ep
[i
].cfg
->ep_cfg
);
1902 /* CSRIN, PCIIN, STATIN, RCIN*/
1903 tmp
= ((0 << ENDPOINT_NUMBER
) | BIT(ENDPOINT_ENABLE
));
1904 writel(tmp
, &dev
->dep
[1].dep_cfg
);
1905 writel(tmp
, &dev
->dep
[3].dep_cfg
);
1906 writel(tmp
, &dev
->dep
[4].dep_cfg
);
1907 writel(tmp
, &dev
->dep
[5].dep_cfg
);
1909 /*Implemented for development and debug.
1910 * Can be refined/tuned later.*/
1911 for (ep_sel
= 0; ep_sel
<= 21; ep_sel
++) {
1912 /* Select an endpoint for subsequent operations: */
1913 tmp_reg
= readl(&dev
->plregs
->pl_ep_ctrl
);
1914 writel(((tmp_reg
& ~0x1f) | ep_sel
),
1915 &dev
->plregs
->pl_ep_ctrl
);
1919 (readl(&dev
->plregs
->pl_ep_ctrl
) |
1920 BIT(CLEAR_ACK_ERROR_CODE
) | 0);
1921 writel(tmp
, &dev
->plregs
->pl_ep_ctrl
);
1925 if (ep_sel
== 0 || (ep_sel
> 9 && ep_sel
< 14) ||
1926 ep_sel
== 18 || ep_sel
== 20)
1929 tmp
= (readl(&dev
->plregs
->pl_ep_cfg_4
) |
1930 BIT(NON_CTRL_IN_TOLERATE_BAD_DIR
) | 0);
1931 writel(tmp
, &dev
->plregs
->pl_ep_cfg_4
);
1933 tmp
= readl(&dev
->plregs
->pl_ep_ctrl
) &
1934 ~BIT(EP_INITIALIZED
);
1935 writel(tmp
, &dev
->plregs
->pl_ep_ctrl
);
1939 /* Set FSM to focus on the first Control Read:
1940 * - Tip: Connection speed is known upon the first
1942 scratch
|= DEFECT7374_FSM_WAITING_FOR_CONTROL_READ
;
1943 set_idx_reg(dev
->regs
, SCRATCH
, scratch
);
1947 /* keeping it simple:
1948 * - one bus driver, initted first;
1949 * - one function driver, initted second
1951 * most of the work to support multiple net2280 controllers would
1952 * be to associate this gadget driver (yes?) with all of them, or
1953 * perhaps to bind specific drivers to specific devices.
1956 static void usb_reset_228x(struct net2280
*dev
)
1960 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1961 (void) readl(&dev
->usb
->usbctl
);
1963 net2280_led_init(dev
);
1965 /* disable automatic responses, and irqs */
1966 writel(0, &dev
->usb
->stdrsp
);
1967 writel(0, &dev
->regs
->pciirqenb0
);
1968 writel(0, &dev
->regs
->pciirqenb1
);
1970 /* clear old dma and irq state */
1971 for (tmp
= 0; tmp
< 4; tmp
++) {
1972 struct net2280_ep
*ep
= &dev
->ep
[tmp
+ 1];
1977 writel(~0, &dev
->regs
->irqstat0
),
1978 writel(~(u32
)BIT(SUSPEND_REQUEST_INTERRUPT
), &dev
->regs
->irqstat1
),
1980 /* reset, and enable pci */
1981 tmp
= readl(&dev
->regs
->devinit
) |
1983 BIT(FIFO_SOFT_RESET
) |
1984 BIT(USB_SOFT_RESET
) |
1986 writel(tmp
, &dev
->regs
->devinit
);
1988 /* standard fifo and endpoint allocations */
1989 set_fifo_mode(dev
, (fifo_mode
<= 2) ? fifo_mode
: 0);
1992 static void usb_reset_338x(struct net2280
*dev
)
1996 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1997 (void)readl(&dev
->usb
->usbctl
);
1999 net2280_led_init(dev
);
2001 if (dev
->bug7734_patched
) {
2002 /* disable automatic responses, and irqs */
2003 writel(0, &dev
->usb
->stdrsp
);
2004 writel(0, &dev
->regs
->pciirqenb0
);
2005 writel(0, &dev
->regs
->pciirqenb1
);
2008 /* clear old dma and irq state */
2009 for (tmp
= 0; tmp
< 4; tmp
++) {
2010 struct net2280_ep
*ep
= &dev
->ep
[tmp
+ 1];
2011 struct net2280_dma_regs __iomem
*dma
;
2016 dma
= &dev
->dma
[tmp
];
2017 writel(BIT(DMA_ABORT
), &dma
->dmastat
);
2018 writel(0, &dma
->dmactl
);
2022 writel(~0, &dev
->regs
->irqstat0
), writel(~0, &dev
->regs
->irqstat1
);
2024 if (dev
->bug7734_patched
) {
2025 /* reset, and enable pci */
2026 tmp
= readl(&dev
->regs
->devinit
) |
2028 BIT(FIFO_SOFT_RESET
) |
2029 BIT(USB_SOFT_RESET
) |
2032 writel(tmp
, &dev
->regs
->devinit
);
2035 /* always ep-{1,2,3,4} ... maybe not ep-3 or ep-4 */
2036 INIT_LIST_HEAD(&dev
->gadget
.ep_list
);
2038 for (tmp
= 1; tmp
< dev
->n_ep
; tmp
++)
2039 list_add_tail(&dev
->ep
[tmp
].ep
.ep_list
, &dev
->gadget
.ep_list
);
2043 static void usb_reset(struct net2280
*dev
)
2045 if (dev
->quirks
& PLX_LEGACY
)
2046 return usb_reset_228x(dev
);
2047 return usb_reset_338x(dev
);
2050 static void usb_reinit_228x(struct net2280
*dev
)
2054 /* basic endpoint init */
2055 for (tmp
= 0; tmp
< 7; tmp
++) {
2056 struct net2280_ep
*ep
= &dev
->ep
[tmp
];
2058 ep
->ep
.name
= ep_name
[tmp
];
2062 if (tmp
> 0 && tmp
<= 4) {
2063 ep
->fifo_size
= 1024;
2064 ep
->dma
= &dev
->dma
[tmp
- 1];
2067 ep
->regs
= &dev
->epregs
[tmp
];
2068 ep
->cfg
= &dev
->epregs
[tmp
];
2069 ep_reset_228x(dev
->regs
, ep
);
2071 usb_ep_set_maxpacket_limit(&dev
->ep
[0].ep
, 64);
2072 usb_ep_set_maxpacket_limit(&dev
->ep
[5].ep
, 64);
2073 usb_ep_set_maxpacket_limit(&dev
->ep
[6].ep
, 64);
2075 dev
->gadget
.ep0
= &dev
->ep
[0].ep
;
2076 dev
->ep
[0].stopped
= 0;
2077 INIT_LIST_HEAD(&dev
->gadget
.ep0
->ep_list
);
2079 /* we want to prevent lowlevel/insecure access from the USB host,
2080 * but erratum 0119 means this enable bit is ignored
2082 for (tmp
= 0; tmp
< 5; tmp
++)
2083 writel(EP_DONTUSE
, &dev
->dep
[tmp
].dep_cfg
);
2086 static void usb_reinit_338x(struct net2280
*dev
)
2090 static const u32 ne
[9] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };
2091 static const u32 ep_reg_addr
[9] = { 0x00, 0xC0, 0x00, 0xC0, 0x00,
2092 0x00, 0xC0, 0x00, 0xC0 };
2094 /* basic endpoint init */
2095 for (i
= 0; i
< dev
->n_ep
; i
++) {
2096 struct net2280_ep
*ep
= &dev
->ep
[i
];
2098 ep
->ep
.name
= dev
->enhanced_mode
? ep_name_adv
[i
] : ep_name
[i
];
2102 if (i
> 0 && i
<= 4)
2103 ep
->dma
= &dev
->dma
[i
- 1];
2105 if (dev
->enhanced_mode
) {
2106 ep
->cfg
= &dev
->epregs
[ne
[i
]];
2108 * Set USB endpoint number, hardware allows same number
2109 * in both directions.
2112 writel(ne
[i
], &ep
->cfg
->ep_cfg
);
2113 ep
->regs
= (struct net2280_ep_regs __iomem
*)
2114 (((void __iomem
*)&dev
->epregs
[ne
[i
]]) +
2117 ep
->cfg
= &dev
->epregs
[i
];
2118 ep
->regs
= &dev
->epregs
[i
];
2121 ep
->fifo_size
= (i
!= 0) ? 2048 : 512;
2123 ep_reset_338x(dev
->regs
, ep
);
2125 usb_ep_set_maxpacket_limit(&dev
->ep
[0].ep
, 512);
2127 dev
->gadget
.ep0
= &dev
->ep
[0].ep
;
2128 dev
->ep
[0].stopped
= 0;
2130 /* Link layer set up */
2131 if (dev
->bug7734_patched
) {
2132 tmp
= readl(&dev
->usb_ext
->usbctl2
) &
2133 ~(BIT(U1_ENABLE
) | BIT(U2_ENABLE
) | BIT(LTM_ENABLE
));
2134 writel(tmp
, &dev
->usb_ext
->usbctl2
);
2137 /* Hardware Defect and Workaround */
2138 val
= readl(&dev
->ll_lfps_regs
->ll_lfps_5
);
2139 val
&= ~(0xf << TIMER_LFPS_6US
);
2140 val
|= 0x5 << TIMER_LFPS_6US
;
2141 writel(val
, &dev
->ll_lfps_regs
->ll_lfps_5
);
2143 val
= readl(&dev
->ll_lfps_regs
->ll_lfps_6
);
2144 val
&= ~(0xffff << TIMER_LFPS_80US
);
2145 val
|= 0x0100 << TIMER_LFPS_80US
;
2146 writel(val
, &dev
->ll_lfps_regs
->ll_lfps_6
);
2149 * AA_AB Errata. Issue 4. Workaround for SuperSpeed USB
2150 * Hot Reset Exit Handshake may Fail in Specific Case using
2151 * Default Register Settings. Workaround for Enumeration test.
2153 val
= readl(&dev
->ll_tsn_regs
->ll_tsn_counters_2
);
2154 val
&= ~(0x1f << HOT_TX_NORESET_TS2
);
2155 val
|= 0x10 << HOT_TX_NORESET_TS2
;
2156 writel(val
, &dev
->ll_tsn_regs
->ll_tsn_counters_2
);
2158 val
= readl(&dev
->ll_tsn_regs
->ll_tsn_counters_3
);
2159 val
&= ~(0x1f << HOT_RX_RESET_TS2
);
2160 val
|= 0x3 << HOT_RX_RESET_TS2
;
2161 writel(val
, &dev
->ll_tsn_regs
->ll_tsn_counters_3
);
2164 * Set Recovery Idle to Recover bit:
2165 * - On SS connections, setting Recovery Idle to Recover Fmw improves
2166 * link robustness with various hosts and hubs.
2167 * - It is safe to set for all connection speeds; all chip revisions.
2168 * - R-M-W to leave other bits undisturbed.
2169 * - Reference PLX TT-7372
2171 val
= readl(&dev
->ll_chicken_reg
->ll_tsn_chicken_bit
);
2172 val
|= BIT(RECOVERY_IDLE_TO_RECOVER_FMW
);
2173 writel(val
, &dev
->ll_chicken_reg
->ll_tsn_chicken_bit
);
2175 INIT_LIST_HEAD(&dev
->gadget
.ep0
->ep_list
);
2177 /* disable dedicated endpoints */
2178 writel(0x0D, &dev
->dep
[0].dep_cfg
);
2179 writel(0x0D, &dev
->dep
[1].dep_cfg
);
2180 writel(0x0E, &dev
->dep
[2].dep_cfg
);
2181 writel(0x0E, &dev
->dep
[3].dep_cfg
);
2182 writel(0x0F, &dev
->dep
[4].dep_cfg
);
2183 writel(0x0C, &dev
->dep
[5].dep_cfg
);
2186 static void usb_reinit(struct net2280
*dev
)
2188 if (dev
->quirks
& PLX_LEGACY
)
2189 return usb_reinit_228x(dev
);
2190 return usb_reinit_338x(dev
);
2193 static void ep0_start_228x(struct net2280
*dev
)
2195 writel(BIT(CLEAR_EP_HIDE_STATUS_PHASE
) |
2196 BIT(CLEAR_NAK_OUT_PACKETS
) |
2197 BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE
),
2198 &dev
->epregs
[0].ep_rsp
);
2201 * hardware optionally handles a bunch of standard requests
2202 * that the API hides from drivers anyway. have it do so.
2203 * endpoint status/features are handled in software, to
2204 * help pass tests for some dubious behavior.
2206 writel(BIT(SET_TEST_MODE
) |
2208 BIT(DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP
) |
2209 BIT(GET_DEVICE_STATUS
) |
2210 BIT(GET_INTERFACE_STATUS
),
2212 writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE
) |
2213 BIT(SELF_POWERED_USB_DEVICE
) |
2214 BIT(REMOTE_WAKEUP_SUPPORT
) |
2215 (dev
->softconnect
<< USB_DETECT_ENABLE
) |
2216 BIT(SELF_POWERED_STATUS
),
2219 /* enable irqs so we can see ep0 and general operation */
2220 writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE
) |
2221 BIT(ENDPOINT_0_INTERRUPT_ENABLE
),
2222 &dev
->regs
->pciirqenb0
);
2223 writel(BIT(PCI_INTERRUPT_ENABLE
) |
2224 BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE
) |
2225 BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE
) |
2226 BIT(PCI_RETRY_ABORT_INTERRUPT_ENABLE
) |
2227 BIT(VBUS_INTERRUPT_ENABLE
) |
2228 BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE
) |
2229 BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE
),
2230 &dev
->regs
->pciirqenb1
);
2232 /* don't leave any writes posted */
2233 (void) readl(&dev
->usb
->usbctl
);
2236 static void ep0_start_338x(struct net2280
*dev
)
2239 if (dev
->bug7734_patched
)
2240 writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE
) |
2241 BIT(SET_EP_HIDE_STATUS_PHASE
),
2242 &dev
->epregs
[0].ep_rsp
);
2245 * hardware optionally handles a bunch of standard requests
2246 * that the API hides from drivers anyway. have it do so.
2247 * endpoint status/features are handled in software, to
2248 * help pass tests for some dubious behavior.
2250 writel(BIT(SET_ISOCHRONOUS_DELAY
) |
2252 BIT(SET_TEST_MODE
) |
2254 BIT(GET_INTERFACE_STATUS
) |
2255 BIT(GET_DEVICE_STATUS
),
2257 dev
->wakeup_enable
= 1;
2258 writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE
) |
2259 (dev
->softconnect
<< USB_DETECT_ENABLE
) |
2260 BIT(DEVICE_REMOTE_WAKEUP_ENABLE
),
2263 /* enable irqs so we can see ep0 and general operation */
2264 writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE
) |
2265 BIT(ENDPOINT_0_INTERRUPT_ENABLE
),
2266 &dev
->regs
->pciirqenb0
);
2267 writel(BIT(PCI_INTERRUPT_ENABLE
) |
2268 BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE
) |
2269 BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE
) |
2270 BIT(VBUS_INTERRUPT_ENABLE
),
2271 &dev
->regs
->pciirqenb1
);
2273 /* don't leave any writes posted */
2274 (void)readl(&dev
->usb
->usbctl
);
2277 static void ep0_start(struct net2280
*dev
)
2279 if (dev
->quirks
& PLX_LEGACY
)
2280 return ep0_start_228x(dev
);
2281 return ep0_start_338x(dev
);
2284 /* when a driver is successfully registered, it will receive
2285 * control requests including set_configuration(), which enables
2286 * non-control requests. then usb traffic follows until a
2287 * disconnect is reported. then a host may connect again, or
2288 * the driver might get unbound.
2290 static int net2280_start(struct usb_gadget
*_gadget
,
2291 struct usb_gadget_driver
*driver
)
2293 struct net2280
*dev
;
2297 /* insist on high speed support from the driver, since
2298 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
2299 * "must not be used in normal operation"
2301 if (!driver
|| driver
->max_speed
< USB_SPEED_HIGH
||
2305 dev
= container_of(_gadget
, struct net2280
, gadget
);
2307 for (i
= 0; i
< dev
->n_ep
; i
++)
2308 dev
->ep
[i
].irqs
= 0;
2310 /* hook up the driver ... */
2311 driver
->driver
.bus
= NULL
;
2312 dev
->driver
= driver
;
2314 retval
= device_create_file(&dev
->pdev
->dev
, &dev_attr_function
);
2317 retval
= device_create_file(&dev
->pdev
->dev
, &dev_attr_queues
);
2321 /* enable host detection and ep0; and we're ready
2322 * for set_configuration as well as eventual disconnect.
2324 net2280_led_active(dev
, 1);
2326 if ((dev
->quirks
& PLX_SUPERSPEED
) && !dev
->bug7734_patched
)
2327 defect7374_enable_data_eps_zero(dev
);
2331 /* pci writes may still be posted */
2335 device_remove_file(&dev
->pdev
->dev
, &dev_attr_function
);
2341 static void stop_activity(struct net2280
*dev
, struct usb_gadget_driver
*driver
)
2345 /* don't disconnect if it's not connected */
2346 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
2349 /* stop hardware; prevent new request submissions;
2350 * and kill any outstanding requests.
2353 for (i
= 0; i
< dev
->n_ep
; i
++)
2356 /* report disconnect; the driver is already quiesced */
2358 spin_unlock(&dev
->lock
);
2359 driver
->disconnect(&dev
->gadget
);
2360 spin_lock(&dev
->lock
);
2366 static int net2280_stop(struct usb_gadget
*_gadget
)
2368 struct net2280
*dev
;
2369 unsigned long flags
;
2371 dev
= container_of(_gadget
, struct net2280
, gadget
);
2373 spin_lock_irqsave(&dev
->lock
, flags
);
2374 stop_activity(dev
, NULL
);
2375 spin_unlock_irqrestore(&dev
->lock
, flags
);
2377 net2280_led_active(dev
, 0);
2379 device_remove_file(&dev
->pdev
->dev
, &dev_attr_function
);
2380 device_remove_file(&dev
->pdev
->dev
, &dev_attr_queues
);
2387 /*-------------------------------------------------------------------------*/
2389 /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
2390 * also works for dma-capable endpoints, in pio mode or just
2391 * to manually advance the queue after short OUT transfers.
2393 static void handle_ep_small(struct net2280_ep
*ep
)
2395 struct net2280_request
*req
;
2397 /* 0 error, 1 mid-data, 2 done */
2400 if (!list_empty(&ep
->queue
))
2401 req
= list_entry(ep
->queue
.next
,
2402 struct net2280_request
, queue
);
2406 /* ack all, and handle what we care about */
2407 t
= readl(&ep
->regs
->ep_stat
);
2410 ep_vdbg(ep
->dev
, "%s ack ep_stat %08x, req %p\n",
2411 ep
->ep
.name
, t
, req
? &req
->req
: NULL
);
2413 if (!ep
->is_in
|| (ep
->dev
->quirks
& PLX_2280
))
2414 writel(t
& ~BIT(NAK_OUT_PACKETS
), &ep
->regs
->ep_stat
);
2416 /* Added for 2282 */
2417 writel(t
, &ep
->regs
->ep_stat
);
2419 /* for ep0, monitor token irqs to catch data stage length errors
2420 * and to synchronize on status.
2422 * also, to defer reporting of protocol stalls ... here's where
2423 * data or status first appears, handling stalls here should never
2424 * cause trouble on the host side..
2426 * control requests could be slightly faster without token synch for
2427 * status, but status can jam up that way.
2429 if (unlikely(ep
->num
== 0)) {
2431 /* status; stop NAKing */
2432 if (t
& BIT(DATA_OUT_PING_TOKEN_INTERRUPT
)) {
2433 if (ep
->dev
->protocol_stall
) {
2440 /* reply to extra IN data tokens with a zlp */
2441 } else if (t
& BIT(DATA_IN_TOKEN_INTERRUPT
)) {
2442 if (ep
->dev
->protocol_stall
) {
2446 } else if (ep
->responded
&&
2447 !req
&& !ep
->stopped
)
2448 write_fifo(ep
, NULL
);
2451 /* status; stop NAKing */
2452 if (t
& BIT(DATA_IN_TOKEN_INTERRUPT
)) {
2453 if (ep
->dev
->protocol_stall
) {
2458 /* an extra OUT token is an error */
2459 } else if (((t
& BIT(DATA_OUT_PING_TOKEN_INTERRUPT
)) &&
2461 req
->req
.actual
== req
->req
.length
) ||
2462 (ep
->responded
&& !req
)) {
2463 ep
->dev
->protocol_stall
= 1;
2467 done(ep
, req
, -EOVERFLOW
);
2476 /* manual DMA queue advance after short OUT */
2477 if (likely(ep
->dma
)) {
2478 if (t
& BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT
)) {
2480 int stopped
= ep
->stopped
;
2482 /* TRANSFERRED works around OUT_DONE erratum 0112.
2483 * we expect (N <= maxpacket) bytes; host wrote M.
2484 * iff (M < N) we won't ever see a DMA interrupt.
2487 for (count
= 0; ; t
= readl(&ep
->regs
->ep_stat
)) {
2489 /* any preceding dma transfers must finish.
2490 * dma handles (M >= N), may empty the queue
2492 scan_dma_completions(ep
);
2493 if (unlikely(list_empty(&ep
->queue
) ||
2494 ep
->out_overflow
)) {
2498 req
= list_entry(ep
->queue
.next
,
2499 struct net2280_request
, queue
);
2501 /* here either (M < N), a "real" short rx;
2502 * or (M == N) and the queue didn't empty
2504 if (likely(t
& BIT(FIFO_EMPTY
))) {
2505 count
= readl(&ep
->dma
->dmacount
);
2506 count
&= DMA_BYTE_COUNT_MASK
;
2507 if (readl(&ep
->dma
->dmadesc
)
2515 /* stop DMA, leave ep NAKing */
2516 writel(BIT(DMA_ABORT
), &ep
->dma
->dmastat
);
2517 spin_stop_dma(ep
->dma
);
2520 req
->td
->dmacount
= 0;
2521 t
= readl(&ep
->regs
->ep_avail
);
2522 dma_done(ep
, req
, count
,
2523 (ep
->out_overflow
|| t
)
2527 /* also flush to prevent erratum 0106 trouble */
2528 if (unlikely(ep
->out_overflow
||
2529 (ep
->dev
->chiprev
== 0x0100 &&
2530 ep
->dev
->gadget
.speed
2531 == USB_SPEED_FULL
))) {
2533 ep
->out_overflow
= 0;
2536 /* (re)start dma if needed, stop NAKing */
2537 ep
->stopped
= stopped
;
2538 if (!list_empty(&ep
->queue
))
2541 ep_dbg(ep
->dev
, "%s dma ep_stat %08x ??\n",
2545 /* data packet(s) received (in the fifo, OUT) */
2546 } else if (t
& BIT(DATA_PACKET_RECEIVED_INTERRUPT
)) {
2547 if (read_fifo(ep
, req
) && ep
->num
!= 0)
2550 /* data packet(s) transmitted (IN) */
2551 } else if (t
& BIT(DATA_PACKET_TRANSMITTED_INTERRUPT
)) {
2554 len
= req
->req
.length
- req
->req
.actual
;
2555 if (len
> ep
->ep
.maxpacket
)
2556 len
= ep
->ep
.maxpacket
;
2557 req
->req
.actual
+= len
;
2559 /* if we wrote it all, we're usually done */
2560 /* send zlps until the status stage */
2561 if ((req
->req
.actual
== req
->req
.length
) &&
2562 (!req
->req
.zero
|| len
!= ep
->ep
.maxpacket
) && ep
->num
)
2565 /* there was nothing to do ... */
2566 } else if (mode
== 1)
2571 /* stream endpoints often resubmit/unlink in completion */
2574 /* maybe advance queue to next request */
2576 /* NOTE: net2280 could let gadget driver start the
2577 * status stage later. since not all controllers let
2578 * them control that, the api doesn't (yet) allow it.
2584 if (!list_empty(&ep
->queue
) && !ep
->stopped
)
2585 req
= list_entry(ep
->queue
.next
,
2586 struct net2280_request
, queue
);
2589 if (req
&& !ep
->is_in
)
2590 stop_out_naking(ep
);
2594 /* is there a buffer for the next packet?
2595 * for best streaming performance, make sure there is one.
2597 if (req
&& !ep
->stopped
) {
2599 /* load IN fifo with next packet (may be zlp) */
2600 if (t
& BIT(DATA_PACKET_TRANSMITTED_INTERRUPT
))
2601 write_fifo(ep
, &req
->req
);
2605 static struct net2280_ep
*get_ep_by_addr(struct net2280
*dev
, u16 wIndex
)
2607 struct net2280_ep
*ep
;
2609 if ((wIndex
& USB_ENDPOINT_NUMBER_MASK
) == 0)
2611 list_for_each_entry(ep
, &dev
->gadget
.ep_list
, ep
.ep_list
) {
2612 u8 bEndpointAddress
;
2616 bEndpointAddress
= ep
->desc
->bEndpointAddress
;
2617 if ((wIndex
^ bEndpointAddress
) & USB_DIR_IN
)
2619 if ((wIndex
& 0x0f) == (bEndpointAddress
& 0x0f))
2625 static void defect7374_workaround(struct net2280
*dev
, struct usb_ctrlrequest r
)
2627 u32 scratch
, fsmvalue
;
2628 u32 ack_wait_timeout
, state
;
2630 /* Workaround for Defect 7374 (U1/U2 erroneously rejected): */
2631 scratch
= get_idx_reg(dev
->regs
, SCRATCH
);
2632 fsmvalue
= scratch
& (0xf << DEFECT7374_FSM_FIELD
);
2633 scratch
&= ~(0xf << DEFECT7374_FSM_FIELD
);
2635 if (!((fsmvalue
== DEFECT7374_FSM_WAITING_FOR_CONTROL_READ
) &&
2636 (r
.bRequestType
& USB_DIR_IN
)))
2639 /* This is the first Control Read for this connection: */
2640 if (!(readl(&dev
->usb
->usbstat
) & BIT(SUPER_SPEED_MODE
))) {
2642 * Connection is NOT SS:
2643 * - Connection must be FS or HS.
2644 * - This FSM state should allow workaround software to
2645 * run after the next USB connection.
2647 scratch
|= DEFECT7374_FSM_NON_SS_CONTROL_READ
;
2648 dev
->bug7734_patched
= 1;
2649 goto restore_data_eps
;
2652 /* Connection is SS: */
2653 for (ack_wait_timeout
= 0;
2654 ack_wait_timeout
< DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS
;
2655 ack_wait_timeout
++) {
2657 state
= readl(&dev
->plregs
->pl_ep_status_1
)
2659 if ((state
>= (ACK_GOOD_NORMAL
<< STATE
)) &&
2660 (state
<= (ACK_GOOD_MORE_ACKS_TO_COME
<< STATE
))) {
2661 scratch
|= DEFECT7374_FSM_SS_CONTROL_READ
;
2662 dev
->bug7734_patched
= 1;
2667 * We have not yet received host's Data Phase ACK
2668 * - Wait and try again.
2670 udelay(DEFECT_7374_PROCESSOR_WAIT_TIME
);
2676 if (ack_wait_timeout
>= DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS
) {
2677 ep_err(dev
, "FAIL: Defect 7374 workaround waited but failed "
2678 "to detect SS host's data phase ACK.");
2679 ep_err(dev
, "PL_EP_STATUS_1(23:16):.Expected from 0x11 to 0x16"
2680 "got 0x%2.2x.\n", state
>> STATE
);
2682 ep_warn(dev
, "INFO: Defect 7374 workaround waited about\n"
2683 "%duSec for Control Read Data Phase ACK\n",
2684 DEFECT_7374_PROCESSOR_WAIT_TIME
* ack_wait_timeout
);
2689 * Restore data EPs to their pre-workaround settings (disabled,
2690 * initialized, and other details).
2692 defect7374_disable_data_eps(dev
);
2694 set_idx_reg(dev
->regs
, SCRATCH
, scratch
);
2699 static void ep_clear_seqnum(struct net2280_ep
*ep
)
2701 struct net2280
*dev
= ep
->dev
;
2703 static const u32 ep_pl
[9] = { 0, 3, 4, 7, 8, 2, 5, 6, 9 };
2705 val
= readl(&dev
->plregs
->pl_ep_ctrl
) & ~0x1f;
2706 val
|= ep_pl
[ep
->num
];
2707 writel(val
, &dev
->plregs
->pl_ep_ctrl
);
2708 val
|= BIT(SEQUENCE_NUMBER_RESET
);
2709 writel(val
, &dev
->plregs
->pl_ep_ctrl
);
2714 static void handle_stat0_irqs_superspeed(struct net2280
*dev
,
2715 struct net2280_ep
*ep
, struct usb_ctrlrequest r
)
2719 #define w_value le16_to_cpu(r.wValue)
2720 #define w_index le16_to_cpu(r.wIndex)
2721 #define w_length le16_to_cpu(r.wLength)
2723 switch (r
.bRequest
) {
2724 struct net2280_ep
*e
;
2727 case USB_REQ_SET_CONFIGURATION
:
2728 dev
->addressed_state
= !w_value
;
2731 case USB_REQ_GET_STATUS
:
2732 switch (r
.bRequestType
) {
2733 case (USB_DIR_IN
| USB_TYPE_STANDARD
| USB_RECIP_DEVICE
):
2734 status
= dev
->wakeup_enable
? 0x02 : 0x00;
2735 if (dev
->gadget
.is_selfpowered
)
2737 status
|= (dev
->u1_enable
<< 2 | dev
->u2_enable
<< 3 |
2738 dev
->ltm_enable
<< 4);
2739 writel(0, &dev
->epregs
[0].ep_irqenb
);
2740 set_fifo_bytecount(ep
, sizeof(status
));
2741 writel((__force u32
) status
, &dev
->epregs
[0].ep_data
);
2742 allow_status_338x(ep
);
2745 case (USB_DIR_IN
| USB_TYPE_STANDARD
| USB_RECIP_ENDPOINT
):
2746 e
= get_ep_by_addr(dev
, w_index
);
2749 status
= readl(&e
->regs
->ep_rsp
) &
2750 BIT(CLEAR_ENDPOINT_HALT
);
2751 writel(0, &dev
->epregs
[0].ep_irqenb
);
2752 set_fifo_bytecount(ep
, sizeof(status
));
2753 writel((__force u32
) status
, &dev
->epregs
[0].ep_data
);
2754 allow_status_338x(ep
);
2762 case USB_REQ_CLEAR_FEATURE
:
2763 switch (r
.bRequestType
) {
2764 case (USB_DIR_OUT
| USB_TYPE_STANDARD
| USB_RECIP_DEVICE
):
2765 if (!dev
->addressed_state
) {
2767 case USB_DEVICE_U1_ENABLE
:
2769 writel(readl(&dev
->usb_ext
->usbctl2
) &
2771 &dev
->usb_ext
->usbctl2
);
2772 allow_status_338x(ep
);
2773 goto next_endpoints3
;
2775 case USB_DEVICE_U2_ENABLE
:
2777 writel(readl(&dev
->usb_ext
->usbctl2
) &
2779 &dev
->usb_ext
->usbctl2
);
2780 allow_status_338x(ep
);
2781 goto next_endpoints3
;
2783 case USB_DEVICE_LTM_ENABLE
:
2784 dev
->ltm_enable
= 0;
2785 writel(readl(&dev
->usb_ext
->usbctl2
) &
2787 &dev
->usb_ext
->usbctl2
);
2788 allow_status_338x(ep
);
2789 goto next_endpoints3
;
2795 if (w_value
== USB_DEVICE_REMOTE_WAKEUP
) {
2796 dev
->wakeup_enable
= 0;
2797 writel(readl(&dev
->usb
->usbctl
) &
2798 ~BIT(DEVICE_REMOTE_WAKEUP_ENABLE
),
2800 allow_status_338x(ep
);
2805 case (USB_DIR_OUT
| USB_TYPE_STANDARD
| USB_RECIP_ENDPOINT
):
2806 e
= get_ep_by_addr(dev
, w_index
);
2809 if (w_value
!= USB_ENDPOINT_HALT
)
2811 ep_vdbg(dev
, "%s clear halt\n", e
->ep
.name
);
2813 * Workaround for SS SeqNum not cleared via
2814 * Endpoint Halt (Clear) bit. select endpoint
2818 if (!list_empty(&e
->queue
) && e
->td_dma
)
2828 case USB_REQ_SET_FEATURE
:
2829 switch (r
.bRequestType
) {
2830 case (USB_DIR_OUT
| USB_TYPE_STANDARD
| USB_RECIP_DEVICE
):
2831 if (!dev
->addressed_state
) {
2833 case USB_DEVICE_U1_ENABLE
:
2835 writel(readl(&dev
->usb_ext
->usbctl2
) |
2837 &dev
->usb_ext
->usbctl2
);
2838 allow_status_338x(ep
);
2839 goto next_endpoints3
;
2841 case USB_DEVICE_U2_ENABLE
:
2843 writel(readl(&dev
->usb_ext
->usbctl2
) |
2845 &dev
->usb_ext
->usbctl2
);
2846 allow_status_338x(ep
);
2847 goto next_endpoints3
;
2849 case USB_DEVICE_LTM_ENABLE
:
2850 dev
->ltm_enable
= 1;
2851 writel(readl(&dev
->usb_ext
->usbctl2
) |
2853 &dev
->usb_ext
->usbctl2
);
2854 allow_status_338x(ep
);
2855 goto next_endpoints3
;
2861 if (w_value
== USB_DEVICE_REMOTE_WAKEUP
) {
2862 dev
->wakeup_enable
= 1;
2863 writel(readl(&dev
->usb
->usbctl
) |
2864 BIT(DEVICE_REMOTE_WAKEUP_ENABLE
),
2866 allow_status_338x(ep
);
2871 case (USB_DIR_OUT
| USB_TYPE_STANDARD
| USB_RECIP_ENDPOINT
):
2872 e
= get_ep_by_addr(dev
, w_index
);
2873 if (!e
|| (w_value
!= USB_ENDPOINT_HALT
))
2877 ep
->dev
->protocol_stall
= 1;
2883 allow_status_338x(ep
);
2894 ep_vdbg(dev
, "setup %02x.%02x v%04x i%04x l%04x ep_cfg %08x\n",
2895 r
.bRequestType
, r
.bRequest
,
2896 w_value
, w_index
, w_length
,
2897 readl(&ep
->cfg
->ep_cfg
));
2900 spin_unlock(&dev
->lock
);
2901 tmp
= dev
->driver
->setup(&dev
->gadget
, &r
);
2902 spin_lock(&dev
->lock
);
2906 ep_vdbg(dev
, "req %02x.%02x protocol STALL; stat %d\n",
2907 r
.bRequestType
, r
.bRequest
, tmp
);
2908 dev
->protocol_stall
= 1;
2909 /* TD 9.9 Halt Endpoint test. TD 9.22 Set feature test */
2922 static void usb338x_handle_ep_intr(struct net2280
*dev
, u32 stat0
)
2927 for (index
= 0; index
< ARRAY_SIZE(ep_bit
); index
++) {
2928 bit
= BIT(ep_bit
[index
]);
2938 handle_ep_small(&dev
->ep
[index
]);
2942 static void handle_stat0_irqs(struct net2280
*dev
, u32 stat
)
2944 struct net2280_ep
*ep
;
2947 /* most of these don't need individual acks */
2948 stat
&= ~BIT(INTA_ASSERTED
);
2951 /* ep_dbg(dev, "irqstat0 %04x\n", stat); */
2953 /* starting a control request? */
2954 if (unlikely(stat
& BIT(SETUP_PACKET_INTERRUPT
))) {
2957 struct usb_ctrlrequest r
;
2960 struct net2280_request
*req
;
2962 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
2963 u32 val
= readl(&dev
->usb
->usbstat
);
2964 if (val
& BIT(SUPER_SPEED
)) {
2965 dev
->gadget
.speed
= USB_SPEED_SUPER
;
2966 usb_ep_set_maxpacket_limit(&dev
->ep
[0].ep
,
2967 EP0_SS_MAX_PACKET_SIZE
);
2968 } else if (val
& BIT(HIGH_SPEED
)) {
2969 dev
->gadget
.speed
= USB_SPEED_HIGH
;
2970 usb_ep_set_maxpacket_limit(&dev
->ep
[0].ep
,
2971 EP0_HS_MAX_PACKET_SIZE
);
2973 dev
->gadget
.speed
= USB_SPEED_FULL
;
2974 usb_ep_set_maxpacket_limit(&dev
->ep
[0].ep
,
2975 EP0_HS_MAX_PACKET_SIZE
);
2977 net2280_led_speed(dev
, dev
->gadget
.speed
);
2979 usb_speed_string(dev
->gadget
.speed
));
2985 /* make sure any leftover request state is cleared */
2986 stat
&= ~BIT(ENDPOINT_0_INTERRUPT
);
2987 while (!list_empty(&ep
->queue
)) {
2988 req
= list_entry(ep
->queue
.next
,
2989 struct net2280_request
, queue
);
2990 done(ep
, req
, (req
->req
.actual
== req
->req
.length
)
2994 dev
->protocol_stall
= 0;
2995 if (!(dev
->quirks
& PLX_SUPERSPEED
)) {
2996 if (ep
->dev
->quirks
& PLX_2280
)
2997 tmp
= BIT(FIFO_OVERFLOW
) |
2998 BIT(FIFO_UNDERFLOW
);
3002 writel(tmp
| BIT(TIMEOUT
) |
3003 BIT(USB_STALL_SENT
) |
3004 BIT(USB_IN_NAK_SENT
) |
3005 BIT(USB_IN_ACK_RCVD
) |
3006 BIT(USB_OUT_PING_NAK_SENT
) |
3007 BIT(USB_OUT_ACK_SENT
) |
3008 BIT(SHORT_PACKET_OUT_DONE_INTERRUPT
) |
3009 BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT
) |
3010 BIT(DATA_PACKET_RECEIVED_INTERRUPT
) |
3011 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT
) |
3012 BIT(DATA_OUT_PING_TOKEN_INTERRUPT
) |
3013 BIT(DATA_IN_TOKEN_INTERRUPT
),
3014 &ep
->regs
->ep_stat
);
3016 u
.raw
[0] = readl(&dev
->usb
->setup0123
);
3017 u
.raw
[1] = readl(&dev
->usb
->setup4567
);
3019 cpu_to_le32s(&u
.raw
[0]);
3020 cpu_to_le32s(&u
.raw
[1]);
3022 if ((dev
->quirks
& PLX_SUPERSPEED
) && !dev
->bug7734_patched
)
3023 defect7374_workaround(dev
, u
.r
);
3027 #define w_value le16_to_cpu(u.r.wValue)
3028 #define w_index le16_to_cpu(u.r.wIndex)
3029 #define w_length le16_to_cpu(u.r.wLength)
3032 writel(BIT(SETUP_PACKET_INTERRUPT
), &dev
->regs
->irqstat0
);
3033 stat
^= BIT(SETUP_PACKET_INTERRUPT
);
3035 /* watch control traffic at the token level, and force
3036 * synchronization before letting the status stage happen.
3037 * FIXME ignore tokens we'll NAK, until driver responds.
3038 * that'll mean a lot less irqs for some drivers.
3040 ep
->is_in
= (u
.r
.bRequestType
& USB_DIR_IN
) != 0;
3042 scratch
= BIT(DATA_PACKET_TRANSMITTED_INTERRUPT
) |
3043 BIT(DATA_OUT_PING_TOKEN_INTERRUPT
) |
3044 BIT(DATA_IN_TOKEN_INTERRUPT
);
3045 stop_out_naking(ep
);
3047 scratch
= BIT(DATA_PACKET_RECEIVED_INTERRUPT
) |
3048 BIT(DATA_OUT_PING_TOKEN_INTERRUPT
) |
3049 BIT(DATA_IN_TOKEN_INTERRUPT
);
3050 writel(scratch
, &dev
->epregs
[0].ep_irqenb
);
3052 /* we made the hardware handle most lowlevel requests;
3053 * everything else goes uplevel to the gadget code.
3057 if (dev
->gadget
.speed
== USB_SPEED_SUPER
) {
3058 handle_stat0_irqs_superspeed(dev
, ep
, u
.r
);
3059 goto next_endpoints
;
3062 switch (u
.r
.bRequest
) {
3063 case USB_REQ_GET_STATUS
: {
3064 struct net2280_ep
*e
;
3067 /* hw handles device and interface status */
3068 if (u
.r
.bRequestType
!= (USB_DIR_IN
|USB_RECIP_ENDPOINT
))
3070 e
= get_ep_by_addr(dev
, w_index
);
3071 if (!e
|| w_length
> 2)
3074 if (readl(&e
->regs
->ep_rsp
) & BIT(SET_ENDPOINT_HALT
))
3075 status
= cpu_to_le32(1);
3077 status
= cpu_to_le32(0);
3079 /* don't bother with a request object! */
3080 writel(0, &dev
->epregs
[0].ep_irqenb
);
3081 set_fifo_bytecount(ep
, w_length
);
3082 writel((__force u32
)status
, &dev
->epregs
[0].ep_data
);
3084 ep_vdbg(dev
, "%s stat %02x\n", ep
->ep
.name
, status
);
3085 goto next_endpoints
;
3088 case USB_REQ_CLEAR_FEATURE
: {
3089 struct net2280_ep
*e
;
3091 /* hw handles device features */
3092 if (u
.r
.bRequestType
!= USB_RECIP_ENDPOINT
)
3094 if (w_value
!= USB_ENDPOINT_HALT
|| w_length
!= 0)
3096 e
= get_ep_by_addr(dev
, w_index
);
3100 ep_vdbg(dev
, "%s wedged, halt not cleared\n",
3103 ep_vdbg(dev
, "%s clear halt\n", e
->ep
.name
);
3105 if ((ep
->dev
->quirks
& PLX_SUPERSPEED
) &&
3106 !list_empty(&e
->queue
) && e
->td_dma
)
3110 goto next_endpoints
;
3113 case USB_REQ_SET_FEATURE
: {
3114 struct net2280_ep
*e
;
3116 /* hw handles device features */
3117 if (u
.r
.bRequestType
!= USB_RECIP_ENDPOINT
)
3119 if (w_value
!= USB_ENDPOINT_HALT
|| w_length
!= 0)
3121 e
= get_ep_by_addr(dev
, w_index
);
3124 if (e
->ep
.name
== ep0name
)
3127 if ((dev
->quirks
& PLX_SUPERSPEED
) && e
->dma
)
3130 ep_vdbg(dev
, "%s set halt\n", ep
->ep
.name
);
3131 goto next_endpoints
;
3136 ep_vdbg(dev
, "setup %02x.%02x v%04x i%04x l%04x "
3138 u
.r
.bRequestType
, u
.r
.bRequest
,
3139 w_value
, w_index
, w_length
,
3140 readl(&ep
->cfg
->ep_cfg
));
3142 spin_unlock(&dev
->lock
);
3143 tmp
= dev
->driver
->setup(&dev
->gadget
, &u
.r
);
3144 spin_lock(&dev
->lock
);
3147 /* stall ep0 on error */
3150 ep_vdbg(dev
, "req %02x.%02x protocol STALL; stat %d\n",
3151 u
.r
.bRequestType
, u
.r
.bRequest
, tmp
);
3152 dev
->protocol_stall
= 1;
3155 /* some in/out token irq should follow; maybe stall then.
3156 * driver must queue a request (even zlp) or halt ep0
3157 * before the host times out.
3166 if ((dev
->quirks
& PLX_SUPERSPEED
) && dev
->enhanced_mode
) {
3167 u32 mask
= (BIT(ENDPOINT_0_INTERRUPT
) |
3168 USB3380_IRQSTAT0_EP_INTR_MASK_IN
|
3169 USB3380_IRQSTAT0_EP_INTR_MASK_OUT
);
3172 usb338x_handle_ep_intr(dev
, stat
& mask
);
3176 /* endpoint data irq ? */
3177 scratch
= stat
& 0x7f;
3179 for (num
= 0; scratch
; num
++) {
3182 /* do this endpoint's FIFO and queue need tending? */
3184 if ((scratch
& t
) == 0)
3189 handle_ep_small(ep
);
3194 ep_dbg(dev
, "unhandled irqstat0 %08x\n", stat
);
3197 #define DMA_INTERRUPTS (BIT(DMA_D_INTERRUPT) | \
3198 BIT(DMA_C_INTERRUPT) | \
3199 BIT(DMA_B_INTERRUPT) | \
3200 BIT(DMA_A_INTERRUPT))
3201 #define PCI_ERROR_INTERRUPTS ( \
3202 BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT) | \
3203 BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT) | \
3204 BIT(PCI_RETRY_ABORT_INTERRUPT))
3206 static void handle_stat1_irqs(struct net2280
*dev
, u32 stat
)
3207 __releases(dev
->lock
)
3208 __acquires(dev
->lock
)
3210 struct net2280_ep
*ep
;
3211 u32 tmp
, num
, mask
, scratch
;
3213 /* after disconnect there's nothing else to do! */
3214 tmp
= BIT(VBUS_INTERRUPT
) | BIT(ROOT_PORT_RESET_INTERRUPT
);
3215 mask
= BIT(SUPER_SPEED
) | BIT(HIGH_SPEED
) | BIT(FULL_SPEED
);
3217 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
3218 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and
3219 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
3220 * only indicates a change in the reset state).
3224 bool disconnect
= false;
3227 * Ignore disconnects and resets if the speed hasn't been set.
3228 * VBUS can bounce and there's always an initial reset.
3230 writel(tmp
, &dev
->regs
->irqstat1
);
3231 if (dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
) {
3232 if ((stat
& BIT(VBUS_INTERRUPT
)) &&
3233 (readl(&dev
->usb
->usbctl
) &
3234 BIT(VBUS_PIN
)) == 0) {
3236 ep_dbg(dev
, "disconnect %s\n",
3237 dev
->driver
->driver
.name
);
3238 } else if ((stat
& BIT(ROOT_PORT_RESET_INTERRUPT
)) &&
3239 (readl(&dev
->usb
->usbstat
) & mask
)
3242 ep_dbg(dev
, "reset %s\n",
3243 dev
->driver
->driver
.name
);
3246 if (disconnect
|| reset
) {
3247 stop_activity(dev
, dev
->driver
);
3249 spin_unlock(&dev
->lock
);
3251 usb_gadget_udc_reset
3252 (&dev
->gadget
, dev
->driver
);
3254 (dev
->driver
->disconnect
)
3256 spin_lock(&dev
->lock
);
3262 /* vBUS can bounce ... one of many reasons to ignore the
3263 * notion of hotplug events on bus connect/disconnect!
3269 /* NOTE: chip stays in PCI D0 state for now, but it could
3270 * enter D1 to save more power
3272 tmp
= BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT
);
3274 writel(tmp
, &dev
->regs
->irqstat1
);
3275 if (stat
& BIT(SUSPEND_REQUEST_INTERRUPT
)) {
3276 if (dev
->driver
->suspend
)
3277 dev
->driver
->suspend(&dev
->gadget
);
3278 if (!enable_suspend
)
3279 stat
&= ~BIT(SUSPEND_REQUEST_INTERRUPT
);
3281 if (dev
->driver
->resume
)
3282 dev
->driver
->resume(&dev
->gadget
);
3283 /* at high speed, note erratum 0133 */
3288 /* clear any other status/irqs */
3290 writel(stat
, &dev
->regs
->irqstat1
);
3292 /* some status we can just ignore */
3293 if (dev
->quirks
& PLX_2280
)
3294 stat
&= ~(BIT(CONTROL_STATUS_INTERRUPT
) |
3295 BIT(SUSPEND_REQUEST_INTERRUPT
) |
3296 BIT(RESUME_INTERRUPT
) |
3297 BIT(SOF_INTERRUPT
));
3299 stat
&= ~(BIT(CONTROL_STATUS_INTERRUPT
) |
3300 BIT(RESUME_INTERRUPT
) |
3301 BIT(SOF_DOWN_INTERRUPT
) |
3302 BIT(SOF_INTERRUPT
));
3306 /* ep_dbg(dev, "irqstat1 %08x\n", stat);*/
3308 /* DMA status, for ep-{a,b,c,d} */
3309 scratch
= stat
& DMA_INTERRUPTS
;
3310 stat
&= ~DMA_INTERRUPTS
;
3312 for (num
= 0; scratch
; num
++) {
3313 struct net2280_dma_regs __iomem
*dma
;
3316 if ((tmp
& scratch
) == 0)
3320 ep
= &dev
->ep
[num
+ 1];
3326 /* clear ep's dma status */
3327 tmp
= readl(&dma
->dmastat
);
3328 writel(tmp
, &dma
->dmastat
);
3331 if (dev
->quirks
& PLX_SUPERSPEED
) {
3332 u32 r_dmacount
= readl(&dma
->dmacount
);
3333 if (!ep
->is_in
&& (r_dmacount
& 0x00FFFFFF) &&
3334 (tmp
& BIT(DMA_TRANSACTION_DONE_INTERRUPT
)))
3338 if (!(tmp
& BIT(DMA_TRANSACTION_DONE_INTERRUPT
))) {
3339 ep_dbg(ep
->dev
, "%s no xact done? %08x\n",
3345 /* OUT transfers terminate when the data from the
3346 * host is in our memory. Process whatever's done.
3347 * On this path, we know transfer's last packet wasn't
3348 * less than req->length. NAK_OUT_PACKETS may be set,
3349 * or the FIFO may already be holding new packets.
3351 * IN transfers can linger in the FIFO for a very
3352 * long time ... we ignore that for now, accounting
3353 * precisely (like PIO does) needs per-packet irqs
3355 scan_dma_completions(ep
);
3357 /* disable dma on inactive queues; else maybe restart */
3358 if (!list_empty(&ep
->queue
)) {
3359 tmp
= readl(&dma
->dmactl
);
3365 /* NOTE: there are other PCI errors we might usefully notice.
3366 * if they appear very often, here's where to try recovering.
3368 if (stat
& PCI_ERROR_INTERRUPTS
) {
3369 ep_err(dev
, "pci dma error; stat %08x\n", stat
);
3370 stat
&= ~PCI_ERROR_INTERRUPTS
;
3371 /* these are fatal errors, but "maybe" they won't
3374 stop_activity(dev
, dev
->driver
);
3380 ep_dbg(dev
, "unhandled irqstat1 %08x\n", stat
);
3383 static irqreturn_t
net2280_irq(int irq
, void *_dev
)
3385 struct net2280
*dev
= _dev
;
3387 /* shared interrupt, not ours */
3388 if ((dev
->quirks
& PLX_LEGACY
) &&
3389 (!(readl(&dev
->regs
->irqstat0
) & BIT(INTA_ASSERTED
))))
3392 spin_lock(&dev
->lock
);
3394 /* handle disconnect, dma, and more */
3395 handle_stat1_irqs(dev
, readl(&dev
->regs
->irqstat1
));
3397 /* control requests and PIO */
3398 handle_stat0_irqs(dev
, readl(&dev
->regs
->irqstat0
));
3400 if (dev
->quirks
& PLX_SUPERSPEED
) {
3401 /* re-enable interrupt to trigger any possible new interrupt */
3402 u32 pciirqenb1
= readl(&dev
->regs
->pciirqenb1
);
3403 writel(pciirqenb1
& 0x7FFFFFFF, &dev
->regs
->pciirqenb1
);
3404 writel(pciirqenb1
, &dev
->regs
->pciirqenb1
);
3407 spin_unlock(&dev
->lock
);
3412 /*-------------------------------------------------------------------------*/
3414 static void gadget_release(struct device
*_dev
)
3416 struct net2280
*dev
= dev_get_drvdata(_dev
);
3421 /* tear down the binding between this driver and the pci device */
3423 static void net2280_remove(struct pci_dev
*pdev
)
3425 struct net2280
*dev
= pci_get_drvdata(pdev
);
3427 usb_del_gadget_udc(&dev
->gadget
);
3429 BUG_ON(dev
->driver
);
3431 /* then clean up the resources we allocated during probe() */
3432 net2280_led_shutdown(dev
);
3433 if (dev
->requests
) {
3435 for (i
= 1; i
< 5; i
++) {
3436 if (!dev
->ep
[i
].dummy
)
3438 pci_pool_free(dev
->requests
, dev
->ep
[i
].dummy
,
3441 pci_pool_destroy(dev
->requests
);
3444 free_irq(pdev
->irq
, dev
);
3445 if (dev
->quirks
& PLX_SUPERSPEED
)
3446 pci_disable_msi(pdev
);
3450 release_mem_region(pci_resource_start(pdev
, 0),
3451 pci_resource_len(pdev
, 0));
3453 pci_disable_device(pdev
);
3454 device_remove_file(&pdev
->dev
, &dev_attr_registers
);
3456 ep_info(dev
, "unbind\n");
3459 /* wrap this driver around the specified device, but
3460 * don't respond over USB until a gadget driver binds to us.
3463 static int net2280_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
3465 struct net2280
*dev
;
3466 unsigned long resource
, len
;
3467 void __iomem
*base
= NULL
;
3470 /* alloc, and start init */
3471 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
3477 pci_set_drvdata(pdev
, dev
);
3478 spin_lock_init(&dev
->lock
);
3479 dev
->quirks
= id
->driver_data
;
3481 dev
->gadget
.ops
= &net2280_ops
;
3482 dev
->gadget
.max_speed
= (dev
->quirks
& PLX_SUPERSPEED
) ?
3483 USB_SPEED_SUPER
: USB_SPEED_HIGH
;
3485 /* the "gadget" abstracts/virtualizes the controller */
3486 dev
->gadget
.name
= driver_name
;
3488 /* now all the pci goodies ... */
3489 if (pci_enable_device(pdev
) < 0) {
3495 /* BAR 0 holds all the registers
3496 * BAR 1 is 8051 memory; unused here (note erratum 0103)
3497 * BAR 2 is fifo memory; unused here
3499 resource
= pci_resource_start(pdev
, 0);
3500 len
= pci_resource_len(pdev
, 0);
3501 if (!request_mem_region(resource
, len
, driver_name
)) {
3502 ep_dbg(dev
, "controller already in use\n");
3508 /* FIXME provide firmware download interface to put
3509 * 8051 code into the chip, e.g. to turn on PCI PM.
3512 base
= ioremap_nocache(resource
, len
);
3514 ep_dbg(dev
, "can't map memory\n");
3518 dev
->regs
= (struct net2280_regs __iomem
*) base
;
3519 dev
->usb
= (struct net2280_usb_regs __iomem
*) (base
+ 0x0080);
3520 dev
->pci
= (struct net2280_pci_regs __iomem
*) (base
+ 0x0100);
3521 dev
->dma
= (struct net2280_dma_regs __iomem
*) (base
+ 0x0180);
3522 dev
->dep
= (struct net2280_dep_regs __iomem
*) (base
+ 0x0200);
3523 dev
->epregs
= (struct net2280_ep_regs __iomem
*) (base
+ 0x0300);
3525 if (dev
->quirks
& PLX_SUPERSPEED
) {
3528 dev
->usb_ext
= (struct usb338x_usb_ext_regs __iomem
*)
3530 dev
->llregs
= (struct usb338x_ll_regs __iomem
*)
3532 dev
->ll_lfps_regs
= (struct usb338x_ll_lfps_regs __iomem
*)
3534 dev
->ll_tsn_regs
= (struct usb338x_ll_tsn_regs __iomem
*)
3536 dev
->ll_chicken_reg
= (struct usb338x_ll_chi_regs __iomem
*)
3538 dev
->plregs
= (struct usb338x_pl_regs __iomem
*)
3540 usbstat
= readl(&dev
->usb
->usbstat
);
3541 dev
->enhanced_mode
= !!(usbstat
& BIT(11));
3542 dev
->n_ep
= (dev
->enhanced_mode
) ? 9 : 5;
3543 /* put into initial config, link up all endpoints */
3544 fsmvalue
= get_idx_reg(dev
->regs
, SCRATCH
) &
3545 (0xf << DEFECT7374_FSM_FIELD
);
3546 /* See if firmware needs to set up for workaround: */
3547 if (fsmvalue
== DEFECT7374_FSM_SS_CONTROL_READ
) {
3548 dev
->bug7734_patched
= 1;
3549 writel(0, &dev
->usb
->usbctl
);
3551 dev
->bug7734_patched
= 0;
3553 dev
->enhanced_mode
= 0;
3555 /* put into initial config, link up all endpoints */
3556 writel(0, &dev
->usb
->usbctl
);
3562 /* irq setup after old hardware is cleaned up */
3564 ep_err(dev
, "No IRQ. Check PCI setup!\n");
3569 if (dev
->quirks
& PLX_SUPERSPEED
)
3570 if (pci_enable_msi(pdev
))
3571 ep_err(dev
, "Failed to enable MSI mode\n");
3573 if (request_irq(pdev
->irq
, net2280_irq
, IRQF_SHARED
,
3574 driver_name
, dev
)) {
3575 ep_err(dev
, "request interrupt %d failed\n", pdev
->irq
);
3582 /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
3583 dev
->requests
= pci_pool_create("requests", pdev
,
3584 sizeof(struct net2280_dma
),
3585 0 /* no alignment requirements */,
3586 0 /* or page-crossing issues */);
3587 if (!dev
->requests
) {
3588 ep_dbg(dev
, "can't get request pool\n");
3592 for (i
= 1; i
< 5; i
++) {
3593 struct net2280_dma
*td
;
3595 td
= pci_pool_alloc(dev
->requests
, GFP_KERNEL
,
3596 &dev
->ep
[i
].td_dma
);
3598 ep_dbg(dev
, "can't get dummy %d\n", i
);
3602 td
->dmacount
= 0; /* not VALID */
3603 td
->dmadesc
= td
->dmaaddr
;
3604 dev
->ep
[i
].dummy
= td
;
3607 /* enable lower-overhead pci memory bursts during DMA */
3608 if (dev
->quirks
& PLX_LEGACY
)
3609 writel(BIT(DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE
) |
3611 * 256 write retries may not be enough...
3612 BIT(PCI_RETRY_ABORT_ENABLE) |
3614 BIT(DMA_READ_MULTIPLE_ENABLE
) |
3615 BIT(DMA_READ_LINE_ENABLE
),
3616 &dev
->pci
->pcimstctl
);
3617 /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
3618 pci_set_master(pdev
);
3619 pci_try_set_mwi(pdev
);
3621 /* ... also flushes any posted pci writes */
3622 dev
->chiprev
= get_idx_reg(dev
->regs
, REG_CHIPREV
) & 0xffff;
3625 ep_info(dev
, "%s\n", driver_desc
);
3626 ep_info(dev
, "irq %d, pci mem %p, chip rev %04x\n",
3627 pdev
->irq
, base
, dev
->chiprev
);
3628 ep_info(dev
, "version: " DRIVER_VERSION
"; %s\n",
3629 dev
->enhanced_mode
? "enhanced mode" : "legacy mode");
3630 retval
= device_create_file(&pdev
->dev
, &dev_attr_registers
);
3634 retval
= usb_add_gadget_udc_release(&pdev
->dev
, &dev
->gadget
,
3642 net2280_remove(pdev
);
3646 /* make sure the board is quiescent; otherwise it will continue
3647 * generating IRQs across the upcoming reboot.
3650 static void net2280_shutdown(struct pci_dev
*pdev
)
3652 struct net2280
*dev
= pci_get_drvdata(pdev
);
3655 writel(0, &dev
->regs
->pciirqenb0
);
3656 writel(0, &dev
->regs
->pciirqenb1
);
3658 /* disable the pullup so the host will think we're gone */
3659 writel(0, &dev
->usb
->usbctl
);
3664 /*-------------------------------------------------------------------------*/
3666 static const struct pci_device_id pci_ids
[] = { {
3667 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
3669 .vendor
= PCI_VENDOR_ID_PLX_LEGACY
,
3671 .subvendor
= PCI_ANY_ID
,
3672 .subdevice
= PCI_ANY_ID
,
3673 .driver_data
= PLX_LEGACY
| PLX_2280
,
3675 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
3677 .vendor
= PCI_VENDOR_ID_PLX_LEGACY
,
3679 .subvendor
= PCI_ANY_ID
,
3680 .subdevice
= PCI_ANY_ID
,
3681 .driver_data
= PLX_LEGACY
,
3684 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
3686 .vendor
= PCI_VENDOR_ID_PLX
,
3688 .subvendor
= PCI_ANY_ID
,
3689 .subdevice
= PCI_ANY_ID
,
3690 .driver_data
= PLX_SUPERSPEED
,
3693 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
3695 .vendor
= PCI_VENDOR_ID_PLX
,
3697 .subvendor
= PCI_ANY_ID
,
3698 .subdevice
= PCI_ANY_ID
,
3699 .driver_data
= PLX_SUPERSPEED
,
3701 { /* end: all zeroes */ }
3703 MODULE_DEVICE_TABLE(pci
, pci_ids
);
3705 /* pci driver glue; this is a "new style" PCI driver module */
3706 static struct pci_driver net2280_pci_driver
= {
3707 .name
= (char *) driver_name
,
3708 .id_table
= pci_ids
,
3710 .probe
= net2280_probe
,
3711 .remove
= net2280_remove
,
3712 .shutdown
= net2280_shutdown
,
3714 /* FIXME add power management support */
3717 module_pci_driver(net2280_pci_driver
);
3719 MODULE_DESCRIPTION(DRIVER_DESC
);
3720 MODULE_AUTHOR("David Brownell");
3721 MODULE_LICENSE("GPL");