/** * struct cdnsp_op_regs - Device Controller Operational Registers. * @command: USBCMD - Controller command register. * @status: USBSTS - Controller status register. * @page_size: This indicates the page size that the device controller supports. * If bit n is set, the controller supports a page size of 2^(n+12), * up to a 128MB page size. 4K is the minimum page size. * @dnctrl: DNCTRL - Device notification control register. * @cmd_ring: CRP - 64-bit Command Ring Pointer. * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer. * @config_reg: CONFIG - Configure Register * @port_reg_base: PORTSCn - base address for Port Status and Control * Each port has a Port Status and Control register, * followed by a Port Power Management Status and Control * register, a Port Link Info register, and a reserved * register.
*/ struct cdnsp_op_regs {
__le32 command;
__le32 status;
__le32 page_size;
__le32 reserved1;
__le32 reserved2;
__le32 dnctrl;
__le64 cmd_ring; /* rsvd: offset 0x20-2F. */
__le32 reserved3[4];
__le64 dcbaa_ptr;
__le32 config_reg; /* rsvd: offset 0x3C-3FF. */
__le32 reserved4[241]; /* port 1 registers, which serve as a base address for other ports. */
__le32 port_reg_base;
};
/* Number of registers per port. */ #define NUM_PORT_REGS 4
/** * struct cdnsp_port_regs - Port Registers. * @portsc: PORTSC - Port Status and Control Register. * @portpmsc: PORTPMSC - Port Power Managements Status and Control Register. * @portli: PORTLI - Port Link Info register.
*/ struct cdnsp_port_regs {
__le32 portsc;
__le32 portpmsc;
__le32 portli;
__le32 reserved;
};
/* * These bits are Read Only (RO) and should be saved and written to the * registers: 0 (connect status) and 10:13 (port speed). * These bits are also sticky - meaning they're in the AUX well and they aren't * changed by a hot and warm.
*/ #define CDNSP_PORT_RO (PORT_CONNECT | DEV_SPEED_MASK)
/* * These bits are RW; writing a 0 clears the bit, writing a 1 sets the bit: * bits 5:8 (link state), 25:26 ("wake on" enable state)
*/ #define CDNSP_PORT_RWS (PORT_PLS_MASK | PORT_WKCONN_E | PORT_WKDISC_E)
/* * These bits are RW; writing a 1 clears the bit, writing a 0 has no effect: * bits 1 (port enable/disable), 17 ( connect changed), * 21 (port reset changed) , 22 (Port Link State Change),
*/ #define CDNSP_PORT_RW1CS (PORT_PED | PORT_CSC | PORT_RC | PORT_PLC)
/* USBCMD - USB command - bitmasks. */ /* Run/Stop, controller execution - do not write unless controller is halted.*/ #define CMD_R_S BIT(0) /* * Reset device controller - resets internal controller state machine and all * registers (except PCI config regs).
*/ #define CMD_RESET BIT(1) /* Event Interrupt Enable - a '1' allows interrupts from the controller. */ #define CMD_INTE BIT(2) /* * Device System Error Interrupt Enable - get out-of-band signal for * controller errors.
*/ #define CMD_DSEIE BIT(3) /* device controller save/restore state. */ #define CMD_CSS BIT(8) #define CMD_CRS BIT(9) /* * Enable Wrap Event - '1' means device controller generates an event * when MFINDEX wraps.
*/ #define CMD_EWE BIT(10) /* 1: device enabled */ #define CMD_DEVEN BIT(17) /* bits 18:31 are reserved (and should be preserved on writes). */
/* USBSTS - USB status - bitmasks */ /* controller not running - set to 1 when run/stop bit is cleared. */ #define STS_HALT BIT(0) /* * serious error, e.g. PCI parity error. The controller will clear * the run/stop bit.
*/ #define STS_FATAL BIT(2) /* event interrupt - clear this prior to clearing any IP flags in IR set.*/ #define STS_EINT BIT(3) /* port change detect */ #define STS_PCD BIT(4) /* save state status - '1' means device controller is saving state. */ #define STS_SSS BIT(8) /* restore state status - '1' means controllers is restoring state. */ #define STS_RSS BIT(9) /* 1: save or restore error */ #define STS_SRE BIT(10) /* 1: device Not Ready to accept doorbell or op reg writes after reset. */ #define STS_CNR BIT(11) /* 1: internal Device Controller Error.*/ #define STS_HCE BIT(12)
/* CRCR - Command Ring Control Register - cmd_ring bitmasks. */ /* bit 0 is the command ring cycle state. */ #define CMD_RING_CS BIT(0) /* stop ring immediately - abort the currently executing command. */ #define CMD_RING_ABORT BIT(2) /* * Command Ring Busy. * Set when Doorbell register is written with DB for command and cleared when * the controller reached end of CR.
*/ #define CMD_RING_BUSY(p) ((p) & BIT(4)) /* 1: command ring is running */ #define CMD_RING_RUNNING BIT(3) /* Command Ring pointer - bit mask for the lower 32 bits. */ #define CMD_RING_RSVD_BITS GENMASK(5, 0)
/* CONFIG - Configure Register - config_reg bitmasks. */ /* bits 0:7 - maximum number of device slots enabled. */ #define MAX_DEVS GENMASK(7, 0) /* bit 8: U3 Entry Enabled, assert PLC when controller enters U3. */ #define CONFIG_U3E BIT(8)
/* PORTSC - Port Status and Control Register - port_reg_base bitmasks */ /* 1: device connected. */ #define PORT_CONNECT BIT(0) /* 1: port enabled. */ #define PORT_PED BIT(1) /* 1: port reset signaling asserted. */ #define PORT_RESET BIT(4) /* * Port Link State - bits 5:8 * A read gives the current link PM state of the port, * a write with Link State Write Strobe sets the link state.
*/ #define PORT_PLS_MASK GENMASK(8, 5) #define XDEV_U0 (0x0 << 5) #define XDEV_U1 (0x1 << 5) #define XDEV_U2 (0x2 << 5) #define XDEV_U3 (0x3 << 5) #define XDEV_DISABLED (0x4 << 5) #define XDEV_RXDETECT (0x5 << 5) #define XDEV_INACTIVE (0x6 << 5) #define XDEV_POLLING (0x7 << 5) #define XDEV_RECOVERY (0x8 << 5) #define XDEV_HOT_RESET (0x9 << 5) #define XDEV_COMP_MODE (0xa << 5) #define XDEV_TEST_MODE (0xb << 5) #define XDEV_RESUME (0xf << 5) /* 1: port has power. */ #define PORT_POWER BIT(9) /* * bits 10:13 indicate device speed: * 0 - undefined speed - port hasn't be initialized by a reset yet * 1 - full speed * 2 - Reserved (Low Speed not supported * 3 - high speed * 4 - super speed * 5 - super speed * 6-15 reserved
*/ #define DEV_SPEED_MASK GENMASK(13, 10) #define XDEV_FS (0x1 << 10) #define XDEV_HS (0x3 << 10) #define XDEV_SS (0x4 << 10) #define XDEV_SSP (0x5 << 10) #define XDEV_SSP1x2 (0x6 << 10) #define XDEV_SSP2x2 (0x7 << 10) #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0 << 10)) #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS) #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS) #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS) #define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP) #define DEV_SSP_GEN1x2(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP1x2) #define DEV_SSP_GEN2x2(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP2x2) #define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS) #define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f) /* Port Link State Write Strobe - set this when changing link state */ #define PORT_LINK_STROBE BIT(16) /* 1: connect status change */ #define PORT_CSC BIT(17) /* 1: warm reset for a USB 3.0 device is done. */ #define PORT_WRC BIT(19) /* 1: reset change - 1 to 0 transition of PORT_RESET */ #define PORT_RC BIT(21) /* * port link status change - set on some port link state transitions: * Transition Reason * ---------------------------------------------------------------------------- * - U3 to Resume Wakeup signaling from a device * - Resume to Recovery to U0 USB 3.0 device resume * - Resume to U0 USB 2.0 device resume * - U3 to Recovery to U0 Software resume of USB 3.0 device complete * - U3 to U0 Software resume of USB 2.0 device complete * - U2 to U0 L1 resume of USB 2.1 device complete * - U0 to U0 L1 entry rejection by USB 2.1 device * - U0 to disabled L1 entry error with USB 2.1 device * - Any state to inactive Error on USB 3.0 port
*/ #define PORT_PLC BIT(22) /* Port configure error change - port failed to configure its link partner. */ #define PORT_CEC BIT(23) /* Wake on connect (enable). */ #define PORT_WKCONN_E BIT(25) /* Wake on disconnect (enable). */ #define PORT_WKDISC_E BIT(26) /* Indicates if Warm Reset is being received. */ #define PORT_WR BIT(31)
/* PORTPMSCUSB3 - Port Power Management Status and Control - bitmasks. */ /* Enables U1 entry. */ #define PORT_U1_TIMEOUT_MASK GENMASK(7, 0) #define PORT_U1_TIMEOUT(p) ((p) & PORT_U1_TIMEOUT_MASK) /* Enables U2 entry .*/ #define PORT_U2_TIMEOUT_MASK GENMASK(14, 8) #define PORT_U2_TIMEOUT(p) (((p) << 8) & PORT_U2_TIMEOUT_MASK)
/* PORTPMSCUSB2 - Port Power Management Status and Control - bitmasks. */ #define PORT_L1S_MASK GENMASK(2, 0) #define PORT_L1S(p) ((p) & PORT_L1S_MASK) #define PORT_L1S_ACK PORT_L1S(1) #define PORT_L1S_NYET PORT_L1S(2) #define PORT_L1S_STALL PORT_L1S(3) #define PORT_L1S_TIMEOUT PORT_L1S(4) /* Remote Wake Enable. */ #define PORT_RWE BIT(3) /* Best Effort Service Latency (BESL). */ #define PORT_BESL(p) (((p) << 4) & GENMASK(7, 4)) /* Hardware LPM Enable (HLE). */ #define PORT_HLE BIT(16) /* Received Best Effort Service Latency (BESL). */ #define PORT_RRBESL(p) (((p) & GENMASK(20, 17)) >> 17) /* Port Test Control. */ #define PORT_TEST_MODE_MASK GENMASK(31, 28) #define PORT_TEST_MODE(p) (((p) << 28) & PORT_TEST_MODE_MASK)
/** * struct cdnsp_intr_reg - Interrupt Register Set. * @irq_pending: IMAN - Interrupt Management Register. Used to enable * interrupts and check for pending interrupts. * @irq_control: IMOD - Interrupt Moderation Register. * Used to throttle interrupts. * @erst_size: Number of segments in the Event Ring Segment Table (ERST). * @erst_base: ERST base address. * @erst_dequeue: Event ring dequeue pointer. * * Each interrupter (defined by a MSI-X vector) has an event ring and an Event * Ring Segment Table (ERST) associated with it. The event ring is comprised of * multiple segments of the same size. The controller places events on the ring * and "updates the Cycle bit in the TRBs to indicate to software the current * position of the Enqueue Pointer." The driver processes those events and * updates the dequeue pointer.
*/ struct cdnsp_intr_reg {
__le32 irq_pending;
__le32 irq_control;
__le32 erst_size;
__le32 rsvd;
__le64 erst_base;
__le64 erst_dequeue;
};
/* IMAN - Interrupt Management Register - irq_pending bitmasks l. */ #define IMAN_IE BIT(1) #define IMAN_IP BIT(0) /* bits 2:31 need to be preserved */ #define IMAN_IE_SET(p) ((p) | IMAN_IE) #define IMAN_IE_CLEAR(p) ((p) & ~IMAN_IE)
/* IMOD - Interrupter Moderation Register - irq_control bitmasks. */ /* * Minimum interval between interrupts (in 250ns intervals). The interval * between interrupts will be longer if there are no events on the event ring. * Default is 4000 (1 ms).
*/ #define IMOD_INTERVAL_MASK GENMASK(15, 0) /* Counter used to count down the time to the next interrupt - HW use only */ #define IMOD_COUNTER_MASK GENMASK(31, 16) #define IMOD_DEFAULT_INTERVAL 0
/* erst_dequeue bitmasks. */ /* * Dequeue ERST Segment Index (DESI) - Segment number (or alias) * where the current dequeue pointer lies. This is an optional HW hint.
*/ #define ERST_DESI_MASK GENMASK(2, 0) /* Event Handler Busy (EHB) - is the event ring scheduled to be serviced. */ #define ERST_EHB BIT(3) #define ERST_PTR_MASK GENMASK(3, 0)
/** * struct cdnsp_run_regs * @microframe_index: MFINDEX - current microframe number. * @ir_set: Array of Interrupter registers. * * Device Controller Runtime Registers: * "Software should read and write these registers using only Dword (32 bit) * or larger accesses"
*/ struct cdnsp_run_regs {
__le32 microframe_index;
__le32 rsvd[7]; struct cdnsp_intr_reg ir_set[128];
};
/* USB 2.0 Port Peripheral Configuration Extended Capability */ #define EXT_CAP_CFG_DEV_20PORT_CAP_ID 0xC1 /* * Setting this bit to '1' enables automatic wakeup from L1 state on transfer * TRB prepared when USBSSP operates in USB2.0 mode.
*/ #define PORT_REG6_L1_L0_HW_EN BIT(1) /* * Setting this bit to '1' forces Full Speed when USBSSP operates in USB2.0 * mode (disables High Speed).
*/ #define PORT_REG6_FORCE_FS BIT(0)
/** * struct cdnsp_container_ctx. * @type: Type of context. Used to calculated offsets to contained contexts. * @size: Size of the context data. * @ctx_size: context data structure size - 64 or 32 bits. * @dma: dma address of the bytes. * @bytes: The raw context data given to HW. * * Represents either a Device or Input context. Holds a pointer to the raw * memory used for the context (bytes) and dma address of it (dma).
*/ struct cdnsp_container_ctx { unsignedint type; #define CDNSP_CTX_TYPE_DEVICE 0x1 #define CDNSP_CTX_TYPE_INPUT 0x2 int size; int ctx_size;
dma_addr_t dma;
u8 *bytes;
};
/** * struct cdnsp_slot_ctx * @dev_info: Device speed, and last valid endpoint. * @dev_port: Device port number that is needed to access the USB device. * @int_target: Interrupter target number. * @dev_state: Slot state and device address. * * Slot Context - This assumes the controller uses 32-byte context * structures. If the controller uses 64-byte contexts, there is an additional * 32 bytes reserved at the end of the slot context for controller internal use.
*/ struct cdnsp_slot_ctx {
__le32 dev_info;
__le32 dev_port;
__le32 int_target;
__le32 dev_state; /* offset 0x10 to 0x1f reserved for controller internal use. */
__le32 reserved[4];
};
/* Bits 20:23 in the Slot Context are the speed for the device. */ #define SLOT_SPEED_FS (XDEV_FS << 10) #define SLOT_SPEED_HS (XDEV_HS << 10) #define SLOT_SPEED_SS (XDEV_SS << 10) #define SLOT_SPEED_SSP (XDEV_SSP << 10)
/* dev_info bitmasks. */ /* Device speed - values defined by PORTSC Device Speed field - 20:23. */ #define DEV_SPEED GENMASK(23, 20) #define GET_DEV_SPEED(n) (((n) & DEV_SPEED) >> 20) /* Index of the last valid endpoint context in this device context - 27:31. */ #define LAST_CTX_MASK ((unsignedint)GENMASK(31, 27)) #define LAST_CTX(p) ((p) << 27) #define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1) #define SLOT_FLAG BIT(0) #define EP0_FLAG BIT(1)
/* dev_port bitmasks */ /* Device port number that is needed to access the USB device. */ #define DEV_PORT(p) (((p) & 0xff) << 16)
/* dev_state bitmasks */ /* USB device address - assigned by the controller. */ #define DEV_ADDR_MASK GENMASK(7, 0) /* Slot state */ #define SLOT_STATE GENMASK(31, 27) #define GET_SLOT_STATE(p) (((p) & SLOT_STATE) >> 27)
/** * struct cdnsp_ep_ctx. * @ep_info: Endpoint state, streams, mult, and interval information. * @ep_info2: Information on endpoint type, max packet size, max burst size, * error count, and whether the controller will force an event for * all transactions. * @deq: 64-bit ring dequeue pointer address. If the endpoint only * defines one stream, this points to the endpoint transfer ring. * Otherwise, it points to a stream context array, which has a * ring pointer for each flow. * @tx_info: Average TRB lengths for the endpoint ring and * max payload within an Endpoint Service Interval Time (ESIT). * * Endpoint Context - This assumes the controller uses 32-byte context * structures. If the controller uses 64-byte contexts, there is an additional * 32 bytes reserved at the end of the endpoint context for controller internal * use.
*/ struct cdnsp_ep_ctx {
__le32 ep_info;
__le32 ep_info2;
__le64 deq;
__le32 tx_info; /* offset 0x14 - 0x1f reserved for controller internal use. */
__le32 reserved[3];
};
/** * struct cdnsp_input_control_context * Input control context; * * @drop_context: Set the bit of the endpoint context you want to disable. * @add_context: Set the bit of the endpoint context you want to enable.
*/ struct cdnsp_input_control_ctx {
__le32 drop_flags;
__le32 add_flags;
__le32 rsvd2[6];
};
/** * Represents everything that is needed to issue a command on the command ring. * * @in_ctx: Pointer to input context structure. * @status: Command Completion Code for last command. * @command_trb: Pointer to command TRB.
*/ struct cdnsp_command { /* Input context for changing device state. */ struct cdnsp_container_ctx *in_ctx;
u32 status; union cdnsp_trb *command_trb;
};
/* Stream Context Types - bits 3:1 of stream ctx deq ptr. */ #define SCT_FOR_CTX(p) (((p) << 1) & GENMASK(3, 1)) /* Secondary stream array type, dequeue pointer is to a transfer ring. */ #define SCT_SEC_TR 0 /* Primary stream array type, dequeue pointer is to a transfer ring. */ #define SCT_PRI_TR 1
/** * struct cdnsp_stream_info: Representing everything that is needed to * supports stream capable endpoints. * @stream_rings: Array of pointers containing Transfer rings for all * supported streams. * @num_streams: Number of streams, including stream 0. * @stream_ctx_array: The stream context array may be bigger than the number * of streams the driver asked for. * @num_stream_ctxs: Number of streams. * @ctx_array_dma: Dma address of Context Stream Array. * @trb_address_map: For mapping physical TRB addresses to segments in * stream rings. * @td_count: Number of TDs associated with endpoint. * @first_prime_det: First PRIME packet detected. * @drbls_count: Number of allowed doorbells.
*/ struct cdnsp_stream_info { struct cdnsp_ring **stream_rings; unsignedint num_streams; struct cdnsp_stream_ctx *stream_ctx_array; unsignedint num_stream_ctxs;
dma_addr_t ctx_array_dma; struct radix_tree_root trb_address_map; int td_count;
u8 first_prime_det; #define STREAM_DRBL_FIFO_DEPTH 2
u8 drbls_count;
};
/** * struct cdnsp_ep - extended device side representation of USB endpoint. * @endpoint: usb endpoint * @pending_req_list: List of requests queuing on transfer ring. * @pdev: Device associated with this endpoint. * @number: Endpoint number (1 - 15). * idx: The device context index (DCI). * interval: Interval between packets used for ISOC endpoint. * @name: A human readable name e.g. ep1out. * @direction: Endpoint direction. * @buffering: Number of on-chip buffers related to endpoint. * @buffering_period; Number of on-chip buffers related to periodic endpoint. * @in_ctx: Pointer to input endpoint context structure. * @out_ctx: Pointer to output endpoint context structure. * @ring: Pointer to transfer ring. * @stream_info: Hold stream information. * @ep_state: Current state of endpoint. * @skip: Sometimes the controller can not process isochronous endpoint ring * quickly enough, and it will miss some isoc tds on the ring and * generate Missed Service Error Event. * Set skip flag when receive a Missed Service Error Event and * process the missed tds on the endpoint ring. * @wa1_nop_trb: hold pointer to NOP trb.
*/ struct cdnsp_ep { struct usb_ep endpoint; struct list_head pending_list; struct cdnsp_device *pdev;
u8 number;
u8 idx;
u32 interval; char name[20];
u8 direction;
u8 buffering;
u8 buffering_period; struct cdnsp_ep_ctx *in_ctx; struct cdnsp_ep_ctx *out_ctx; struct cdnsp_ring *ring; struct cdnsp_stream_info stream_info; unsignedint ep_state; #define EP_ENABLED BIT(0) #define EP_DIS_IN_RROGRESS BIT(1) #define EP_HALTED BIT(2) #define EP_STOPPED BIT(3) #define EP_WEDGE BIT(4) #define EP0_HALTED_STATUS BIT(5) #define EP_HAS_STREAMS BIT(6) #define EP_UNCONFIGURED BIT(7)
/** * struct cdnsp_transfer_event. * @buffer: 64-bit buffer address, or immediate data. * @transfer_len: Data length transferred. * @flags: Field is interpreted differently based on the type of TRB.
*/ struct cdnsp_transfer_event {
__le64 buffer;
__le32 transfer_len;
__le32 flags;
};
/* Invalidate event after disabling endpoint. */ #define TRB_EVENT_INVALIDATE 8
/* * Halt Endpoint Command TRB field. * The ESP bit only exists in the SSP2 controller.
*/ #define TRB_ESP BIT(9)
/* Link TRB specific fields. */ #define TRB_TC BIT(1)
/* Port Status Change Event TRB fields. */ /* Port ID - bits 31:24. */ #define GET_PORT_ID(p) (((p) & GENMASK(31, 24)) >> 24) #define SET_PORT_ID(p) (((p) << 24) & GENMASK(31, 24)) #define EVENT_DATA BIT(2)
/* Normal TRB fields. */ /* transfer_len bitmasks - bits 0:16. */ #define TRB_LEN(p) ((p) & GENMASK(16, 0)) /* TD Size, packets remaining in this TD, bits 21:17 (5 bits, so max 31). */ #define TRB_TD_SIZE(p) (min((p), (u32)31) << 17) #define GET_TD_SIZE(p) (((p) & GENMASK(21, 17)) >> 17) /* * Controller uses the TD_SIZE field for TBC if Extended TBC * is enabled (ETE).
*/ #define TRB_TD_SIZE_TBC(p) (min((p), (u32)31) << 17) /* Interrupter Target - which MSI-X vector to target the completion event at. */ #define TRB_INTR_TARGET(p) (((p) << 22) & GENMASK(31, 22)) #define GET_INTR_TARGET(p) (((p) & GENMASK(31, 22)) >> 22) /* * Total burst count field, Rsvdz on controller with Extended TBC * enabled (ETE).
*/ #define TRB_TBC(p) (((p) & 0x3) << 7) #define TRB_TLBPC(p) (((p) & 0xf) << 16)
/* Cycle bit - indicates TRB ownership by driver or driver.*/ #define TRB_CYCLE BIT(0) /* * Force next event data TRB to be evaluated before task switch. * Used to pass OS data back after a TD completes.
*/ #define TRB_ENT BIT(1) /* Interrupt on short packet. */ #define TRB_ISP BIT(2) /* Set PCIe no snoop attribute. */ #define TRB_NO_SNOOP BIT(3) /* Chain multiple TRBs into a TD. */ #define TRB_CHAIN BIT(4) /* Interrupt on completion. */ #define TRB_IOC BIT(5) /* The buffer pointer contains immediate data. */ #define TRB_IDT BIT(6) /* 0 - NRDY during data stage, 1 - NRDY during status stage (only control). */ #define TRB_STAT BIT(7) /* Block Event Interrupt. */ #define TRB_BEI BIT(9)
/* Control transfer TRB specific fields. */ #define TRB_DIR_IN BIT(16)
/* TRB bit mask in Data Stage TRB */ #define TRB_SETUPID_BITMASK GENMASK(9, 8) #define TRB_SETUPID(p) ((p) << 8) #define TRB_SETUPID_TO_TYPE(p) (((p) & TRB_SETUPID_BITMASK) >> 8)
/* TRB type IDs. */ /* bulk, interrupt, isoc scatter/gather, and control data stage. */ #define TRB_NORMAL 1 /* Setup Stage for control transfers. */ #define TRB_SETUP 2 /* Data Stage for control transfers. */ #define TRB_DATA 3 /* Status Stage for control transfers. */ #define TRB_STATUS 4 /* ISOC transfers. */ #define TRB_ISOC 5 /* TRB for linking ring segments. */ #define TRB_LINK 6 #define TRB_EVENT_DATA 7 /* Transfer Ring No-op (not for the command ring). */ #define TRB_TR_NOOP 8
/* Command TRBs */ /* Enable Slot Command. */ #define TRB_ENABLE_SLOT 9 /* Disable Slot Command. */ #define TRB_DISABLE_SLOT 10 /* Address Device Command. */ #define TRB_ADDR_DEV 11 /* Configure Endpoint Command. */ #define TRB_CONFIG_EP 12 /* Evaluate Context Command. */ #define TRB_EVAL_CONTEXT 13 /* Reset Endpoint Command. */ #define TRB_RESET_EP 14 /* Stop Transfer Ring Command. */ #define TRB_STOP_RING 15 /* Set Transfer Ring Dequeue Pointer Command. */ #define TRB_SET_DEQ 16 /* Reset Device Command. */ #define TRB_RESET_DEV 17 /* Force Event Command (opt). */ #define TRB_FORCE_EVENT 18 /* Force Header Command - generate a transaction or link management packet. */ #define TRB_FORCE_HEADER 22 /* No-op Command - not for transfer rings. */ #define TRB_CMD_NOOP 23 /* TRB IDs 24-31 reserved. */
/* * TRBS_PER_SEGMENT must be a multiple of 4. * The command ring is 64-byte aligned, so it must also be greater than 16.
*/ #define TRBS_PER_SEGMENT 256 #define TRBS_PER_EVENT_SEGMENT 256 #define TRBS_PER_EV_DEQ_UPDATE 100 #define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT * 16) #define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE)) /* TRB buffer pointers can't cross 64KB boundaries. */ #define TRB_MAX_BUFF_SHIFT 16 #define TRB_MAX_BUFF_SIZE BIT(TRB_MAX_BUFF_SHIFT) /* How much data is left before the 64KB boundary? */ #define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \
((addr) & (TRB_MAX_BUFF_SIZE - 1)))
/** * struct cdnsp_segment - segment related data. * @trbs: Array of Transfer Request Blocks. * @next: Pointer to the next segment. * @dma: DMA address of current segment. * @bounce_dma: Bounce buffer DMA address . * @bounce_buf: Bounce buffer virtual address. * bounce_offs: Bounce buffer offset. * bounce_len: Bounce buffer length.
*/ struct cdnsp_segment { union cdnsp_trb *trbs; struct cdnsp_segment *next;
dma_addr_t dma; /* Max packet sized bounce buffer for td-fragmant alignment */
dma_addr_t bounce_dma; void *bounce_buf; unsignedint bounce_offs; unsignedint bounce_len;
};
/** * struct cdnsp_td - Transfer Descriptor object. * @td_list: Used for binding TD with ep_ring->td_list. * @preq: Request associated with this TD * @start_seg: Segment containing the first_trb in TD. * @first_trb: First TRB for this TD. * @last_trb: Last TRB related with TD. * @bounce_seg: Bounce segment for this TD. * @request_length_set: actual_length of the request has already been set. * @drbl - TD has been added to HW scheduler - only for stream capable * endpoints.
*/ struct cdnsp_td { struct list_head td_list; struct cdnsp_request *preq; struct cdnsp_segment *start_seg; union cdnsp_trb *first_trb; union cdnsp_trb *last_trb; struct cdnsp_segment *bounce_seg; bool request_length_set; bool drbl;
};
/** * struct cdnsp_dequeue_state - New dequeue pointer for Transfer Ring. * @new_deq_seg: New dequeue segment. * @new_deq_ptr: New dequeue pointer. * @new_cycle_state: New cycle state. * @stream_id: stream id for which new dequeue pointer has been selected.
*/ struct cdnsp_dequeue_state { struct cdnsp_segment *new_deq_seg; union cdnsp_trb *new_deq_ptr; int new_cycle_state; unsignedint stream_id;
};
/** * struct cdnsp_ring - information describing transfer, command or event ring. * @first_seg: First segment on transfer ring. * @last_seg: Last segment on transfer ring. * @enqueue: SW enqueue pointer address. * @enq_seg: SW enqueue segment address. * @dequeue: SW dequeue pointer address. * @deq_seg: SW dequeue segment address. * @td_list: transfer descriptor list associated with this ring. * @cycle_state: Current cycle bit. Write the cycle state into the TRB cycle * field to give ownership of the TRB to the device controller * (if we are the producer) or to check if we own the TRB * (if we are the consumer). * @stream_id: Stream id * @stream_active: Stream is active - PRIME packet has been detected. * @stream_rejected: This ring has been rejected by host. * @num_tds: Number of TDs associated with ring. * @num_segs: Number of segments. * @num_trbs_free: Number of free TRBs on the ring. * @bounce_buf_len: Length of bounce buffer. * @type: Ring type - event, transfer, or command ring. * @last_td_was_short - TD is short TD. * @trb_address_map: For mapping physical TRB addresses to segments in * stream rings.
*/ struct cdnsp_ring { struct cdnsp_segment *first_seg; struct cdnsp_segment *last_seg; union cdnsp_trb *enqueue; struct cdnsp_segment *enq_seg; union cdnsp_trb *dequeue; struct cdnsp_segment *deq_seg; struct list_head td_list;
u32 cycle_state; unsignedint stream_id; unsignedint stream_active; unsignedint stream_rejected; int num_tds; unsignedint num_segs; unsignedint num_trbs_free; unsignedint bounce_buf_len; enum cdnsp_ring_type type; bool last_td_was_short; struct radix_tree_root *trb_address_map;
};
/** * struct cdnsp_erst_entry - even ring segment table entry object. * @seg_addr: 64-bit event ring segment address. * seg_size: Number of TRBs in segment.;
*/ struct cdnsp_erst_entry {
__le64 seg_addr;
__le32 seg_size; /* Set to zero */
__le32 rsvd;
};
/** * struct cdnsp_erst - even ring segment table for event ring. * @entries: Array of event ring segments * @num_entries: Number of segments in entries array. * @erst_dma_addr: DMA address for entries array.
*/ struct cdnsp_erst { struct cdnsp_erst_entry *entries; unsignedint num_entries;
dma_addr_t erst_dma_addr;
};
/** * struct cdnsp_request - extended device side representation of usb_request * object . * @td: Transfer descriptor associated with this request. * @request: Generic usb_request object describing single I/O request. * @list: Used to adding request to endpoint pending_list. * @pep: Extended representation of usb_ep object * @epnum: Endpoint number associated with usb request. * @direction: Endpoint direction for usb request.
*/ struct cdnsp_request { struct cdnsp_td td; struct usb_request request; struct list_head list; struct cdnsp_ep *pep;
u8 epnum; unsigned direction:1;
};
#define ERST_NUM_SEGS 1
/* Stages used during enumeration process.*/ enum cdnsp_ep0_stage {
CDNSP_SETUP_STAGE,
CDNSP_DATA_STAGE,
CDNSP_STATUS_STAGE,
};
/** * struct cdnsp_port - holds information about detected ports. * @port_num: Port number. * @exist: Indicate if port exist. * maj_rev: Major revision. * min_rev: Minor revision.
*/ struct cdnsp_port { struct cdnsp_port_regs __iomem *regs;
u8 port_num;
u8 exist;
u8 maj_rev;
u8 min_rev;
};
/** * struct cdnsp_device - represent USB device. * @dev: Pointer to device structure associated whit this controller. * @gadget: Device side representation of the peripheral controller. * @gadget_driver: Pointer to the gadget driver. * @irq: IRQ line number used by device side. * @regs:IO device memory. * @cap_regs: Capability registers. * @op_regs: Operational registers. * @run_regs: Runtime registers. * @dba: Device base address register. * @ir_set: Current interrupter register set. * @port20_regs: Port 2.0 Peripheral Configuration Registers. * @port3x_regs: USB3.x Port Peripheral Configuration Registers. * @rev_cap: Controller Capabilities Registers. * @hcs_params1: Cached register copies of read-only HCSPARAMS1 * @hcc_params: Cached register copies of read-only HCCPARAMS1 * @rtl_revision: Cached controller rtl revision. * @setup: Temporary buffer for setup packet. * @ep0_preq: Internal allocated request used during enumeration. * @ep0_stage: ep0 stage during enumeration process. * @three_stage_setup: Three state or two state setup. * @ep0_expect_in: Data IN expected for control transfer. * @setup_id: Setup identifier. * @setup_speed - Speed detected for current SETUP packet. * @setup_buf: Buffer for SETUP packet. * @device_address: Current device address. * @may_wakeup: remote wakeup enabled/disabled. * @lock: Lock used in interrupt thread context. * @hci_version: device controller version. * @dcbaa: Device context base address array. * @cmd_ring: Command ring. * @cmd: Represent all what is needed to issue command on Command Ring. * @event_ring: Event ring. * @erst: Event Ring Segment table * @slot_id: Current Slot ID. Should be 0 or 1. * @out_ctx: Output context. * @in_ctx: Input context. * @eps: array of endpoints object associated with device. * @usb2_hw_lpm_capable: hardware lpm is enabled; * @u1_allowed: Allow device transition to U1 state. * @u2_allowed: Allow device transition to U2 state * @device_pool: DMA pool for allocating input and output context. * @segment_pool: DMA pool for allocating new segments. * @cdnsp_state: Current state of controller. * @link_state: Current link state. * @usb2_port - Port USB 2.0. * @usb3_port - Port USB 3.0. * @active_port - Current selected Port. * @test_mode: selected Test Mode.
*/ struct cdnsp_device { struct device *dev; struct usb_gadget gadget; struct usb_gadget_driver *gadget_driver; unsignedint irq; void __iomem *regs;
/* * Commands to the hardware are passed an "input context" that * tells the hardware what to change in its data structures. * The hardware will return changes in an "output context" that * software must allocate for the hardware. .
*/ struct cdnsp_container_ctx out_ctx; struct cdnsp_container_ctx in_ctx; struct cdnsp_ep eps[CDNSP_ENDPOINTS_NUM];
u8 usb2_hw_lpm_capable:1;
u8 u1_allowed:1;
u8 u2_allowed:1;
/* * Registers should always be accessed with double word or quad word accesses. * * Registers with 64-bit address pointers should be written to with * dword accesses by writing the low dword first (ptr[0]), then the high dword * (ptr[1]) second. controller implementations that do not support 64-bit * address pointers will ignore the high dword, and write order is irrelevant.
*/ staticinline u64 cdnsp_read_64(__le64 __iomem *regs)
{ return lo_hi_readq(regs);
}
/** * next_request - gets the next request on the given list * @list: the request list to operate on * * Caller should take care of locking. This function return NULL or the first * request available on list.
*/ staticinlinestruct cdnsp_request *next_request(struct list_head *list)
{ return list_first_entry_or_null(list, struct cdnsp_request, list);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.