aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci.h
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2009-04-27 22:52:34 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-06-16 00:44:48 -0400
commit0ebbab37422315a5d0cb29792271085bafdf38c0 (patch)
treeb638a71f004c27b49ea09f64ed80596078cc6167 /drivers/usb/host/xhci.h
parent66d4eadd8d067269ea8fead1a50fe87c2979a80d (diff)
USB: xhci: Ring allocation and initialization.
Allocate basic xHCI host controller data structures. For every xHC, there is a command ring, an event ring, and a doorbell array. The doorbell array is used to notify the host controller that work has been enqueued onto one of the rings. The host controller driver enqueues commands on the command ring. The HW enqueues command completion events on the event ring and interrupts the system (currently using PCI interrupts, although the xHCI HW will use MSI interrupts eventually). All rings and the doorbell array must be allocated by the xHCI host controller driver. Each ring is comprised of one or more segments, which consists of 16-byte Transfer Request Blocks (TRBs) that can be chained to form a Transfer Descriptor (TD) that represents a multiple-buffer request. Segments are linked into a ring using Link TRBs, which means they are dynamically growable. The producer of the ring enqueues a TD by writing one or more TRBs in the ring and toggling the TRB cycle bit for each TRB. The consumer knows it can process the TRB when the cycle bit matches its internal consumer cycle state for the ring. The consumer cycle state is toggled an odd amount of times in the ring. An example ring (a ring must have a minimum of 16 TRBs on it, but that's too big to draw in ASCII art): chain cycle bit bit ------------------------ | TD A TRB 1 | 1 | 1 |<------------- <-- consumer dequeue ptr ------------------------ | consumer cycle state = 1 | TD A TRB 2 | 1 | 1 | | ------------------------ | | TD A TRB 3 | 0 | 1 | segment 1 | ------------------------ | | TD B TRB 1 | 1 | 1 | | ------------------------ | | TD B TRB 2 | 0 | 1 | | ------------------------ | | Link TRB | 0 | 1 |----- | ------------------------ | | | | chain cycle | | bit bit | | ------------------------ | | | TD C TRB 1 | 0 | 1 |<---- | ------------------------ | | TD D TRB 1 | 1 | 1 | | ------------------------ | | TD D TRB 2 | 1 | 1 | segment 2 | ------------------------ | | TD D TRB 3 | 1 | 1 | | ------------------------ | | TD D TRB 4 | 1 | 1 | | ------------------------ | | Link TRB | 1 | 1 |----- | ------------------------ | | | | chain cycle | | bit bit | | ------------------------ | | | TD D TRB 5 | 1 | 1 |<---- | ------------------------ | | TD D TRB 6 | 0 | 1 | | ------------------------ | | TD E TRB 1 | 0 | 1 | segment 3 | ------------------------ | | | 0 | 0 | | <-- producer enqueue ptr ------------------------ | | | 0 | 0 | | ------------------------ | | Link TRB | 0 | 0 |--------------- ------------------------ Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/xhci.h')
-rw-r--r--drivers/usb/host/xhci.h296
1 files changed, 296 insertions, 0 deletions
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 59fae2e5ea59..ed331310f1a8 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -241,6 +241,18 @@ struct xhci_op_regs {
241 */ 241 */
242#define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1) 242#define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1)
243 243
244/* CRCR - Command Ring Control Register - cmd_ring bitmasks */
245/* bit 0 is the command ring cycle state */
246/* stop ring operation after completion of the currently executing command */
247#define CMD_RING_PAUSE (1 << 1)
248/* stop ring immediately - abort the currently executing command */
249#define CMD_RING_ABORT (1 << 2)
250/* true: command ring is running */
251#define CMD_RING_RUNNING (1 << 3)
252/* bits 4:5 reserved and should be preserved */
253/* Command Ring pointer - bit mask for the lower 32 bits. */
254#define CMD_RING_ADDR_MASK (0xffffffc0)
255
244/* CONFIG - Configure Register - config_reg bitmasks */ 256/* CONFIG - Configure Register - config_reg bitmasks */
245/* bits 0:7 - maximum number of device slots enabled (NumSlotsEn) */ 257/* bits 0:7 - maximum number of device slots enabled (NumSlotsEn) */
246#define MAX_DEVS(p) ((p) & 0xff) 258#define MAX_DEVS(p) ((p) & 0xff)
@@ -391,6 +403,7 @@ struct intr_reg {
391 * a work queue (or delayed service routine)? 403 * a work queue (or delayed service routine)?
392 */ 404 */
393#define ERST_EHB (1 << 3) 405#define ERST_EHB (1 << 3)
406#define ERST_PTR_MASK (0xf)
394 407
395/** 408/**
396 * struct xhci_run_regs 409 * struct xhci_run_regs
@@ -407,6 +420,275 @@ struct xhci_run_regs {
407 struct intr_reg ir_set[128]; 420 struct intr_reg ir_set[128];
408} __attribute__ ((packed)); 421} __attribute__ ((packed));
409 422
423/**
424 * struct doorbell_array
425 *
426 * Section 5.6
427 */
428struct xhci_doorbell_array {
429 u32 doorbell[256];
430} __attribute__ ((packed));
431
432#define DB_TARGET_MASK 0xFFFFFF00
433#define DB_STREAM_ID_MASK 0x0000FFFF
434#define DB_TARGET_HOST 0x0
435#define DB_STREAM_ID_HOST 0x0
436#define DB_MASK (0xff << 8)
437
438
439struct xhci_transfer_event {
440 /* 64-bit buffer address, or immediate data */
441 u32 buffer[2];
442 u32 transfer_len;
443 /* This field is interpreted differently based on the type of TRB */
444 u32 flags;
445} __attribute__ ((packed));
446
447/* Completion Code - only applicable for some types of TRBs */
448#define COMP_CODE_MASK (0xff << 24)
449#define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
450#define COMP_SUCCESS 1
451/* Data Buffer Error */
452#define COMP_DB_ERR 2
453/* Babble Detected Error */
454#define COMP_BABBLE 3
455/* USB Transaction Error */
456#define COMP_TX_ERR 4
457/* TRB Error - some TRB field is invalid */
458#define COMP_TRB_ERR 5
459/* Stall Error - USB device is stalled */
460#define COMP_STALL 6
461/* Resource Error - HC doesn't have memory for that device configuration */
462#define COMP_ENOMEM 7
463/* Bandwidth Error - not enough room in schedule for this dev config */
464#define COMP_BW_ERR 8
465/* No Slots Available Error - HC ran out of device slots */
466#define COMP_ENOSLOTS 9
467/* Invalid Stream Type Error */
468#define COMP_STREAM_ERR 10
469/* Slot Not Enabled Error - doorbell rung for disabled device slot */
470#define COMP_EBADSLT 11
471/* Endpoint Not Enabled Error */
472#define COMP_EBADEP 12
473/* Short Packet */
474#define COMP_SHORT_TX 13
475/* Ring Underrun - doorbell rung for an empty isoc OUT ep ring */
476#define COMP_UNDERRUN 14
477/* Ring Overrun - isoc IN ep ring is empty when ep is scheduled to RX */
478#define COMP_OVERRUN 15
479/* Virtual Function Event Ring Full Error */
480#define COMP_VF_FULL 16
481/* Parameter Error - Context parameter is invalid */
482#define COMP_EINVAL 17
483/* Bandwidth Overrun Error - isoc ep exceeded its allocated bandwidth */
484#define COMP_BW_OVER 18
485/* Context State Error - illegal context state transition requested */
486#define COMP_CTX_STATE 19
487/* No Ping Response Error - HC didn't get PING_RESPONSE in time to TX */
488#define COMP_PING_ERR 20
489/* Event Ring is full */
490#define COMP_ER_FULL 21
491/* Missed Service Error - HC couldn't service an isoc ep within interval */
492#define COMP_MISSED_INT 23
493/* Successfully stopped command ring */
494#define COMP_CMD_STOP 24
495/* Successfully aborted current command and stopped command ring */
496#define COMP_CMD_ABORT 25
497/* Stopped - transfer was terminated by a stop endpoint command */
498#define COMP_STOP 26
499/* Same as COMP_EP_STOPPED, but the transfered length in the event is invalid */
500#define COMP_STOP_INVAL 27
501/* Control Abort Error - Debug Capability - control pipe aborted */
502#define COMP_DBG_ABORT 28
503/* TRB type 29 and 30 reserved */
504/* Isoc Buffer Overrun - an isoc IN ep sent more data than could fit in TD */
505#define COMP_BUFF_OVER 31
506/* Event Lost Error - xHC has an "internal event overrun condition" */
507#define COMP_ISSUES 32
508/* Undefined Error - reported when other error codes don't apply */
509#define COMP_UNKNOWN 33
510/* Invalid Stream ID Error */
511#define COMP_STRID_ERR 34
512/* Secondary Bandwidth Error - may be returned by a Configure Endpoint cmd */
513/* FIXME - check for this */
514#define COMP_2ND_BW_ERR 35
515/* Split Transaction Error */
516#define COMP_SPLIT_ERR 36
517
518struct xhci_link_trb {
519 /* 64-bit segment pointer*/
520 u32 segment_ptr[2];
521 u32 intr_target;
522 u32 control;
523} __attribute__ ((packed));
524
525/* control bitfields */
526#define LINK_TOGGLE (0x1<<1)
527
528
529union xhci_trb {
530 struct xhci_link_trb link;
531 struct xhci_transfer_event trans_event;
532};
533
534/* Normal TRB fields */
535/* transfer_len bitmasks - bits 0:16 */
536#define TRB_LEN(p) ((p) & 0x1ffff)
537/* TD size - number of bytes remaining in the TD (including this TRB):
538 * bits 17 - 21. Shift the number of bytes by 10. */
539#define TD_REMAINDER(p) ((((p) >> 10) & 0x1f) << 17)
540/* Interrupter Target - which MSI-X vector to target the completion event at */
541#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
542#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
543
544/* Cycle bit - indicates TRB ownership by HC or HCD */
545#define TRB_CYCLE (1<<0)
546/*
547 * Force next event data TRB to be evaluated before task switch.
548 * Used to pass OS data back after a TD completes.
549 */
550#define TRB_ENT (1<<1)
551/* Interrupt on short packet */
552#define TRB_ISP (1<<2)
553/* Set PCIe no snoop attribute */
554#define TRB_NO_SNOOP (1<<3)
555/* Chain multiple TRBs into a TD */
556#define TRB_CHAIN (1<<4)
557/* Interrupt on completion */
558#define TRB_IOC (1<<5)
559/* The buffer pointer contains immediate data */
560#define TRB_IDT (1<<6)
561
562
563/* Control transfer TRB specific fields */
564#define TRB_DIR_IN (1<<16)
565
566/* TRB bit mask */
567#define TRB_TYPE_BITMASK (0xfc00)
568#define TRB_TYPE(p) ((p) << 10)
569/* TRB type IDs */
570/* bulk, interrupt, isoc scatter/gather, and control data stage */
571#define TRB_NORMAL 1
572/* setup stage for control transfers */
573#define TRB_SETUP 2
574/* data stage for control transfers */
575#define TRB_DATA 3
576/* status stage for control transfers */
577#define TRB_STATUS 4
578/* isoc transfers */
579#define TRB_ISOC 5
580/* TRB for linking ring segments */
581#define TRB_LINK 6
582#define TRB_EVENT_DATA 7
583/* Transfer Ring No-op (not for the command ring) */
584#define TRB_TR_NOOP 8
585/* Command TRBs */
586/* Enable Slot Command */
587#define TRB_ENABLE_SLOT 9
588/* Disable Slot Command */
589#define TRB_DISABLE_SLOT 10
590/* Address Device Command */
591#define TRB_ADDR_DEV 11
592/* Configure Endpoint Command */
593#define TRB_CONFIG_EP 12
594/* Evaluate Context Command */
595#define TRB_EVAL_CONTEXT 13
596/* Reset Transfer Ring Command */
597#define TRB_RESET_RING 14
598/* Stop Transfer Ring Command */
599#define TRB_STOP_RING 15
600/* Set Transfer Ring Dequeue Pointer Command */
601#define TRB_SET_DEQ 16
602/* Reset Device Command */
603#define TRB_RESET_DEV 17
604/* Force Event Command (opt) */
605#define TRB_FORCE_EVENT 18
606/* Negotiate Bandwidth Command (opt) */
607#define TRB_NEG_BANDWIDTH 19
608/* Set Latency Tolerance Value Command (opt) */
609#define TRB_SET_LT 20
610/* Get port bandwidth Command */
611#define TRB_GET_BW 21
612/* Force Header Command - generate a transaction or link management packet */
613#define TRB_FORCE_HEADER 22
614/* No-op Command - not for transfer rings */
615#define TRB_CMD_NOOP 23
616/* TRB IDs 24-31 reserved */
617/* Event TRBS */
618/* Transfer Event */
619#define TRB_TRANSFER 32
620/* Command Completion Event */
621#define TRB_COMPLETION 33
622/* Port Status Change Event */
623#define TRB_PORT_STATUS 34
624/* Bandwidth Request Event (opt) */
625#define TRB_BANDWIDTH_EVENT 35
626/* Doorbell Event (opt) */
627#define TRB_DOORBELL 36
628/* Host Controller Event */
629#define TRB_HC_EVENT 37
630/* Device Notification Event - device sent function wake notification */
631#define TRB_DEV_NOTE 38
632/* MFINDEX Wrap Event - microframe counter wrapped */
633#define TRB_MFINDEX_WRAP 39
634/* TRB IDs 40-47 reserved, 48-63 is vendor-defined */
635
636/*
637 * TRBS_PER_SEGMENT must be a multiple of 4,
638 * since the command ring is 64-byte aligned.
639 * It must also be greater than 16.
640 */
641#define TRBS_PER_SEGMENT 64
642#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
643
644struct xhci_segment {
645 union xhci_trb *trbs;
646 /* private to HCD */
647 struct xhci_segment *next;
648 dma_addr_t dma;
649} __attribute__ ((packed));
650
651struct xhci_ring {
652 struct xhci_segment *first_seg;
653 union xhci_trb *enqueue;
654 union xhci_trb *dequeue;
655 /*
656 * Write the cycle state into the TRB cycle field to give ownership of
657 * the TRB to the host controller (if we are the producer), or to check
658 * if we own the TRB (if we are the consumer). See section 4.9.1.
659 */
660 u32 cycle_state;
661};
662
663struct xhci_erst_entry {
664 /* 64-bit event ring segment address */
665 u32 seg_addr[2];
666 u32 seg_size;
667 /* Set to zero */
668 u32 rsvd;
669} __attribute__ ((packed));
670
671struct xhci_erst {
672 struct xhci_erst_entry *entries;
673 unsigned int num_entries;
674 /* xhci->event_ring keeps track of segment dma addresses */
675 dma_addr_t erst_dma_addr;
676 /* Num entries the ERST can contain */
677 unsigned int erst_size;
678};
679
680/*
681 * Each segment table entry is 4*32bits long. 1K seems like an ok size:
682 * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
683 * meaning 64 ring segments.
684 * Initial allocated size of the ERST, in number of entries */
685#define ERST_NUM_SEGS 1
686/* Initial allocated size of the ERST, in number of entries */
687#define ERST_SIZE 64
688/* Initial number of event segment rings allocated */
689#define ERST_ENTRIES 1
690/* XXX: Make these module parameters */
691
410 692
411/* There is one ehci_hci structure per controller */ 693/* There is one ehci_hci structure per controller */
412struct xhci_hcd { 694struct xhci_hcd {
@@ -414,6 +696,7 @@ struct xhci_hcd {
414 struct xhci_cap_regs __iomem *cap_regs; 696 struct xhci_cap_regs __iomem *cap_regs;
415 struct xhci_op_regs __iomem *op_regs; 697 struct xhci_op_regs __iomem *op_regs;
416 struct xhci_run_regs __iomem *run_regs; 698 struct xhci_run_regs __iomem *run_regs;
699 struct xhci_doorbell_array __iomem *dba;
417 /* Our HCD's current interrupter register set */ 700 /* Our HCD's current interrupter register set */
418 struct intr_reg __iomem *ir_set; 701 struct intr_reg __iomem *ir_set;
419 702
@@ -441,6 +724,14 @@ struct xhci_hcd {
441 /* only one MSI vector for now, but might need more later */ 724 /* only one MSI vector for now, but might need more later */
442 int msix_count; 725 int msix_count;
443 struct msix_entry *msix_entries; 726 struct msix_entry *msix_entries;
727 /* data structures */
728 struct xhci_ring *cmd_ring;
729 struct xhci_ring *event_ring;
730 struct xhci_erst erst;
731
732 /* DMA pools */
733 struct dma_pool *device_pool;
734 struct dma_pool *segment_pool;
444}; 735};
445 736
446/* convert between an HCD pointer and the corresponding EHCI_HCD */ 737/* convert between an HCD pointer and the corresponding EHCI_HCD */
@@ -488,6 +779,11 @@ static inline void xhci_writel(const struct xhci_hcd *xhci,
488/* xHCI debugging */ 779/* xHCI debugging */
489void xhci_print_ir_set(struct xhci_hcd *xhci, struct intr_reg *ir_set, int set_num); 780void xhci_print_ir_set(struct xhci_hcd *xhci, struct intr_reg *ir_set, int set_num);
490void xhci_print_registers(struct xhci_hcd *xhci); 781void xhci_print_registers(struct xhci_hcd *xhci);
782void xhci_dbg_regs(struct xhci_hcd *xhci);
783void xhci_print_run_regs(struct xhci_hcd *xhci);
784void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring);
785void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
786void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
491 787
492/* xHCI memory managment */ 788/* xHCI memory managment */
493void xhci_mem_cleanup(struct xhci_hcd *xhci); 789void xhci_mem_cleanup(struct xhci_hcd *xhci);