/* SPDX-License-Identifier: GPL-2.0 */ /* * Cadence CDNSP DRD Driver. * * Copyright (C) 2020 Cadence. * * Author: Pawel Laszczak <[email protected]> * * Code based on Linux XHCI driver. * Origin: Copyright (C) 2008 Intel Corp. */ #ifndef __LINUX_CDNSP_GADGET_H #define __LINUX_CDNSP_GADGET_H #include <linux/io-64-nonatomic-lo-hi.h> #include <linux/usb/gadget.h> #include <linux/irq.h> /* Max number slots - only 1 is allowed. */ #define CDNSP_DEV_MAX_SLOTS … #define CDNSP_EP0_SETUP_SIZE … /* One control and 15 for in and 15 for out endpoints. */ #define CDNSP_ENDPOINTS_NUM … /* Best Effort Service Latency. */ #define CDNSP_DEFAULT_BESL … /* Device Controller command default timeout value in us */ #define CDNSP_CMD_TIMEOUT … /* Up to 16 ms to halt an device controller */ #define CDNSP_MAX_HALT_USEC … #define CDNSP_CTX_SIZE … /* * Controller register interface. */ /** * struct cdnsp_cap_regs - CDNSP Registers. * @hc_capbase: Length of the capabilities register and controller * version number * @hcs_params1: HCSPARAMS1 - Structural Parameters 1 * @hcs_params2: HCSPARAMS2 - Structural Parameters 2 * @hcs_params3: HCSPARAMS3 - Structural Parameters 3 * @hcc_params: HCCPARAMS - Capability Parameters * @db_off: DBOFF - Doorbell array offset * @run_regs_off: RTSOFF - Runtime register space offset * @hcc_params2: HCCPARAMS2 Capability Parameters 2, */ struct cdnsp_cap_regs { … }; /* hc_capbase bitmasks. */ /* bits 7:0 - how long is the Capabilities register. */ #define HC_LENGTH(p) … /* bits 31:16 */ #define HC_VERSION(p) … /* HCSPARAMS1 - hcs_params1 - bitmasks */ /* bits 0:7, Max Device Endpoints */ #define HCS_ENDPOINTS_MASK … #define HCS_ENDPOINTS(p) … /* HCCPARAMS offset from PCI base address */ #define HCC_PARAMS_OFFSET … /* HCCPARAMS - hcc_params - bitmasks */ /* 1: device controller can use 64-bit address pointers. */ #define HCC_64BIT_ADDR(p) … /* 1: device controller uses 64-byte Device Context structures. */ #define HCC_64BYTE_CONTEXT(p) … /* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15. */ #define HCC_MAX_PSA(p) … /* Extended Capabilities pointer from PCI base. */ #define HCC_EXT_CAPS(p) … #define CTX_SIZE(_hcc) … /* db_off bitmask - bits 0:1 reserved. */ #define DBOFF_MASK … /* run_regs_off bitmask - bits 0:4 reserved. */ #define RTSOFF_MASK … /** * 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 { … }; /* Number of registers per port. */ #define NUM_PORT_REGS … /** * 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 { … }; /* * 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 … /* * 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 … /* * 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 … /* USBCMD - USB command - bitmasks. */ /* Run/Stop, controller execution - do not write unless controller is halted.*/ #define CMD_R_S … /* * Reset device controller - resets internal controller state machine and all * registers (except PCI config regs). */ #define CMD_RESET … /* Event Interrupt Enable - a '1' allows interrupts from the controller. */ #define CMD_INTE … /* * Device System Error Interrupt Enable - get out-of-band signal for * controller errors. */ #define CMD_DSEIE … /* device controller save/restore state. */ #define CMD_CSS … #define CMD_CRS … /* * Enable Wrap Event - '1' means device controller generates an event * when MFINDEX wraps. */ #define CMD_EWE … /* 1: device enabled */ #define CMD_DEVEN … /* bits 18:31 are reserved (and should be preserved on writes). */ /* Command register values to disable interrupts. */ #define CDNSP_IRQS … /* USBSTS - USB status - bitmasks */ /* controller not running - set to 1 when run/stop bit is cleared. */ #define STS_HALT … /* * serious error, e.g. PCI parity error. The controller will clear * the run/stop bit. */ #define STS_FATAL … /* event interrupt - clear this prior to clearing any IP flags in IR set.*/ #define STS_EINT … /* port change detect */ #define STS_PCD … /* save state status - '1' means device controller is saving state. */ #define STS_SSS … /* restore state status - '1' means controllers is restoring state. */ #define STS_RSS … /* 1: save or restore error */ #define STS_SRE … /* 1: device Not Ready to accept doorbell or op reg writes after reset. */ #define STS_CNR … /* 1: internal Device Controller Error.*/ #define STS_HCE … /* CRCR - Command Ring Control Register - cmd_ring bitmasks. */ /* bit 0 is the command ring cycle state. */ #define CMD_RING_CS … /* stop ring immediately - abort the currently executing command. */ #define CMD_RING_ABORT … /* * 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) … /* 1: command ring is running */ #define CMD_RING_RUNNING … /* Command Ring pointer - bit mask for the lower 32 bits. */ #define CMD_RING_RSVD_BITS … /* CONFIG - Configure Register - config_reg bitmasks. */ /* bits 0:7 - maximum number of device slots enabled. */ #define MAX_DEVS … /* bit 8: U3 Entry Enabled, assert PLC when controller enters U3. */ #define CONFIG_U3E … /* PORTSC - Port Status and Control Register - port_reg_base bitmasks */ /* 1: device connected. */ #define PORT_CONNECT … /* 1: port enabled. */ #define PORT_PED … /* 1: port reset signaling asserted. */ #define PORT_RESET … /* * 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 … #define XDEV_U0 … #define XDEV_U1 … #define XDEV_U2 … #define XDEV_U3 … #define XDEV_DISABLED … #define XDEV_RXDETECT … #define XDEV_INACTIVE … #define XDEV_POLLING … #define XDEV_RECOVERY … #define XDEV_HOT_RESET … #define XDEV_COMP_MODE … #define XDEV_TEST_MODE … #define XDEV_RESUME … /* 1: port has power. */ #define PORT_POWER … /* * 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 … #define XDEV_FS … #define XDEV_HS … #define XDEV_SS … #define XDEV_SSP … #define DEV_UNDEFSPEED(p) … #define DEV_FULLSPEED(p) … #define DEV_HIGHSPEED(p) … #define DEV_SUPERSPEED(p) … #define DEV_SUPERSPEEDPLUS(p) … #define DEV_SUPERSPEED_ANY(p) … #define DEV_PORT_SPEED(p) … /* Port Link State Write Strobe - set this when changing link state */ #define PORT_LINK_STROBE … /* 1: connect status change */ #define PORT_CSC … /* 1: warm reset for a USB 3.0 device is done. */ #define PORT_WRC … /* 1: reset change - 1 to 0 transition of PORT_RESET */ #define PORT_RC … /* * 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 … /* Port configure error change - port failed to configure its link partner. */ #define PORT_CEC … /* Wake on connect (enable). */ #define PORT_WKCONN_E … /* Wake on disconnect (enable). */ #define PORT_WKDISC_E … /* Indicates if Warm Reset is being received. */ #define PORT_WR … #define PORT_CHANGE_BITS … /* PORTPMSCUSB3 - Port Power Management Status and Control - bitmasks. */ /* Enables U1 entry. */ #define PORT_U1_TIMEOUT_MASK … #define PORT_U1_TIMEOUT(p) … /* Enables U2 entry .*/ #define PORT_U2_TIMEOUT_MASK … #define PORT_U2_TIMEOUT(p) … /* PORTPMSCUSB2 - Port Power Management Status and Control - bitmasks. */ #define PORT_L1S_MASK … #define PORT_L1S(p) … #define PORT_L1S_ACK … #define PORT_L1S_NYET … #define PORT_L1S_STALL … #define PORT_L1S_TIMEOUT … /* Remote Wake Enable. */ #define PORT_RWE … /* Best Effort Service Latency (BESL). */ #define PORT_BESL(p) … /* Hardware LPM Enable (HLE). */ #define PORT_HLE … /* Received Best Effort Service Latency (BESL). */ #define PORT_RRBESL(p) … /* Port Test Control. */ #define PORT_TEST_MODE_MASK … #define PORT_TEST_MODE(p) … /** * 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 { … }; /* IMAN - Interrupt Management Register - irq_pending bitmasks l. */ #define IMAN_IE … #define IMAN_IP … /* bits 2:31 need to be preserved */ #define IMAN_IE_SET(p) … #define IMAN_IE_CLEAR(p) … /* 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 … /* Counter used to count down the time to the next interrupt - HW use only */ #define IMOD_COUNTER_MASK … #define IMOD_DEFAULT_INTERVAL … /* erst_size bitmasks. */ /* Preserve bits 16:31 of erst_size. */ #define ERST_SIZE_MASK … /* 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 … /* Event Handler Busy (EHB) - is the event ring scheduled to be serviced. */ #define ERST_EHB … #define ERST_PTR_MASK … /** * 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 { … }; /** * USB2.0 Port Peripheral Configuration Registers. * @ext_cap: Header register for Extended Capability. * @port_reg1: Timer Configuration Register. * @port_reg2: Timer Configuration Register. * @port_reg3: Timer Configuration Register. * @port_reg4: Timer Configuration Register. * @port_reg5: Timer Configuration Register. * @port_reg6: Chicken bits for USB20PPP. */ struct cdnsp_20port_cap { … }; /* Extended capability register fields */ #define EXT_CAPS_ID(p) … #define EXT_CAPS_NEXT(p) … /* Extended capability IDs - ID 0 reserved */ #define EXT_CAPS_PROTOCOL … /* USB 2.0 Port Peripheral Configuration Extended Capability */ #define EXT_CAP_CFG_DEV_20PORT_CAP_ID … /* * 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 … /* * Setting this bit to '1' forces Full Speed when USBSSP operates in USB2.0 * mode (disables High Speed). */ #define PORT_REG6_FORCE_FS … /** * USB3.x Port Peripheral Configuration Registers. * @ext_cap: Header register for Extended Capability. * @mode_addr: Miscellaneous 3xPORT operation mode configuration register. * @mode_2: 3x Port Control Register 2. */ struct cdnsp_3xport_cap { … }; /* Extended Capability Header for 3XPort Configuration Registers. */ #define D_XEC_CFG_3XPORT_CAP … #define CFG_3XPORT_SSP_SUPPORT … #define CFG_3XPORT_U1_PIPE_CLK_GATE_EN … /* Revision Extended Capability ID */ #define RTL_REV_CAP … #define RTL_REV_CAP_RX_BUFF_CMD_SIZE … #define RTL_REV_CAP_RX_BUFF_SIZE … #define RTL_REV_CAP_TX_BUFF_CMD_SIZE … #define RTL_REV_CAP_TX_BUFF_SIZE … #define CDNSP_VER_1 … #define CDNSP_VER_2 … #define CDNSP_IF_EP_EXIST(pdev, ep_num, dir) … /** * struct cdnsp_rev_cap - controller capabilities. * @ext_cap: Header for RTL Revision Extended Capability. * @rtl_revision: RTL revision. * @rx_buff_size: Rx buffer sizes. * @tx_buff_size: Tx buffer sizes. * @ep_supported: Supported endpoints. * @ctrl_revision: Controller revision ID. */ struct cdnsp_rev_cap { … }; /* USB2.0 Port Peripheral Configuration Registers. */ #define D_XEC_PRE_REGS_CAP … #define REG_CHICKEN_BITS_2_OFFSET … #define CHICKEN_XDMA_2_TP_CACHE_DIS … /* XBUF Extended Capability ID. */ #define XBUF_CAP_ID … #define XBUF_RX_TAG_MASK_0_OFFSET … #define XBUF_RX_TAG_MASK_1_OFFSET … #define XBUF_TX_CMD_OFFSET … /** * struct cdnsp_doorbell_array. * @cmd_db: Command ring doorbell register. * @ep_db: Endpoint ring doorbell register. * Bits 0 - 7: Endpoint target. * Bits 8 - 15: RsvdZ. * Bits 16 - 31: Stream ID. */ struct cdnsp_doorbell_array { … }; #define DB_VALUE(ep, stream) … #define DB_VALUE_EP0_OUT(ep, stream) … #define DB_VALUE_CMD … /** * 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 { … }; /** * 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 { … }; /* Bits 20:23 in the Slot Context are the speed for the device. */ #define SLOT_SPEED_FS … #define SLOT_SPEED_HS … #define SLOT_SPEED_SS … #define SLOT_SPEED_SSP … /* dev_info bitmasks. */ /* Device speed - values defined by PORTSC Device Speed field - 20:23. */ #define DEV_SPEED … #define GET_DEV_SPEED(n) … /* Index of the last valid endpoint context in this device context - 27:31. */ #define LAST_CTX_MASK … #define LAST_CTX(p) … #define LAST_CTX_TO_EP_NUM(p) … #define SLOT_FLAG … #define EP0_FLAG … /* dev_port bitmasks */ /* Device port number that is needed to access the USB device. */ #define DEV_PORT(p) … /* dev_state bitmasks */ /* USB device address - assigned by the controller. */ #define DEV_ADDR_MASK … /* Slot state */ #define SLOT_STATE … #define GET_SLOT_STATE(p) … #define SLOT_STATE_DISABLED … #define SLOT_STATE_ENABLED … #define SLOT_STATE_DEFAULT … #define SLOT_STATE_ADDRESSED … #define SLOT_STATE_CONFIGURED … /** * 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 { … }; /* ep_info bitmasks. */ /* * Endpoint State - bits 0:2: * 0 - disabled * 1 - running * 2 - halted due to halt condition * 3 - stopped * 4 - TRB error * 5-7 - reserved */ #define EP_STATE_MASK … #define EP_STATE_DISABLED … #define EP_STATE_RUNNING … #define EP_STATE_HALTED … #define EP_STATE_STOPPED … #define EP_STATE_ERROR … #define GET_EP_CTX_STATE(ctx) … /* Mult - Max number of burst within an interval, in EP companion desc. */ #define EP_MULT(p) … #define CTX_TO_EP_MULT(p) … /* bits 10:14 are Max Primary Streams. */ /* bit 15 is Linear Stream Array. */ /* Interval - period between requests to an endpoint - 125u increments. */ #define EP_INTERVAL(p) … #define EP_INTERVAL_TO_UFRAMES(p) … #define CTX_TO_EP_INTERVAL(p) … #define EP_MAXPSTREAMS_MASK … #define EP_MAXPSTREAMS(p) … #define CTX_TO_EP_MAXPSTREAMS(p) … /* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ #define EP_HAS_LSA … /* ep_info2 bitmasks */ #define ERROR_COUNT(p) … #define CTX_TO_EP_TYPE(p) … #define EP_TYPE(p) … #define ISOC_OUT_EP … #define BULK_OUT_EP … #define INT_OUT_EP … #define CTRL_EP … #define ISOC_IN_EP … #define BULK_IN_EP … #define INT_IN_EP … /* bit 6 reserved. */ /* bit 7 is Device Initiate Disable - for disabling stream selection. */ #define MAX_BURST(p) … #define CTX_TO_MAX_BURST(p) … #define MAX_PACKET(p) … #define MAX_PACKET_MASK … #define MAX_PACKET_DECODED(p) … /* tx_info bitmasks. */ #define EP_AVG_TRB_LENGTH(p) … #define EP_MAX_ESIT_PAYLOAD_LO(p) … #define EP_MAX_ESIT_PAYLOAD_HI(p) … #define CTX_TO_MAX_ESIT_PAYLOAD_LO(p) … #define CTX_TO_MAX_ESIT_PAYLOAD_HI(p) … /* deq bitmasks. */ #define EP_CTX_CYCLE_MASK … #define CTX_DEQ_MASK … /** * 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 { … }; /** * 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 { … }; /** * Stream context structure. * * @stream_ring: 64-bit stream ring address, cycle state, and stream type. * @reserved: offset 0x14 - 0x1f reserved for controller internal use. */ struct cdnsp_stream_ctx { … }; /* Stream Context Types - bits 3:1 of stream ctx deq ptr. */ #define SCT_FOR_CTX(p) … /* Secondary stream array type, dequeue pointer is to a transfer ring. */ #define SCT_SEC_TR … /* Primary stream array type, dequeue pointer is to a transfer ring. */ #define SCT_PRI_TR … /** * 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 { … }; #define STREAM_LOG_STREAMS … #define STREAM_NUM_STREAMS … #if STREAM_LOG_STREAMS > 16 && STREAM_LOG_STREAMS < 1 #error "Not suupported stream value" #endif /** * 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. */ struct cdnsp_ep { … }; /** * struct cdnsp_device_context_array * @dev_context_ptr: Array of 64-bit DMA addresses for device contexts. * @dma: DMA address for device contexts structure. */ struct cdnsp_device_context_array { … }; /** * 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 { … }; /* Invalidate event after disabling endpoint. */ #define TRB_EVENT_INVALIDATE … /* Transfer event TRB length bit mask. */ /* bits 0:23 */ #define EVENT_TRB_LEN(p) … /* Completion Code - only applicable for some types of TRBs */ #define COMP_CODE_MASK … #define GET_COMP_CODE(p) … #define COMP_INVALID … #define COMP_SUCCESS … #define COMP_DATA_BUFFER_ERROR … #define COMP_BABBLE_DETECTED_ERROR … #define COMP_TRB_ERROR … #define COMP_RESOURCE_ERROR … #define COMP_NO_SLOTS_AVAILABLE_ERROR … #define COMP_INVALID_STREAM_TYPE_ERROR … #define COMP_SLOT_NOT_ENABLED_ERROR … #define COMP_ENDPOINT_NOT_ENABLED_ERROR … #define COMP_SHORT_PACKET … #define COMP_RING_UNDERRUN … #define COMP_RING_OVERRUN … #define COMP_VF_EVENT_RING_FULL_ERROR … #define COMP_PARAMETER_ERROR … #define COMP_CONTEXT_STATE_ERROR … #define COMP_EVENT_RING_FULL_ERROR … #define COMP_INCOMPATIBLE_DEVICE_ERROR … #define COMP_MISSED_SERVICE_ERROR … #define COMP_COMMAND_RING_STOPPED … #define COMP_COMMAND_ABORTED … #define COMP_STOPPED … #define COMP_STOPPED_LENGTH_INVALID … #define COMP_STOPPED_SHORT_PACKET … #define COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR … #define COMP_ISOCH_BUFFER_OVERRUN … #define COMP_EVENT_LOST_ERROR … #define COMP_UNDEFINED_ERROR … #define COMP_INVALID_STREAM_ID_ERROR … /*Transfer Event NRDY bit fields */ #define TRB_TO_DEV_STREAM(p) … #define TRB_TO_HOST_STREAM(p) … #define STREAM_PRIME_ACK … #define STREAM_REJECTED … /** Transfer Event bit fields **/ #define TRB_TO_EP_ID(p) … /** * struct cdnsp_link_trb * @segment_ptr: 64-bit segment pointer. * @intr_target: Interrupter target. * @control: Flags. */ struct cdnsp_link_trb { … }; /* control bitfields */ #define LINK_TOGGLE … /** * struct cdnsp_event_cmd - Command completion event TRB. * cmd_trb: Pointer to command TRB, or the value passed by the event data trb * status: Command completion parameters and error code. * flags: Flags. */ struct cdnsp_event_cmd { … }; /* flags bitmasks */ /* Address device - disable SetAddress. */ #define TRB_BSR … /* Configure Endpoint - Deconfigure. */ #define TRB_DC … /* Force Header */ #define TRB_FH_TO_PACKET_TYPE(p) … #define TRB_FH_TR_PACKET … #define TRB_FH_TO_DEVICE_ADDRESS(p) … #define TRB_FH_TR_PACKET_DEV_NOT … #define TRB_FH_TO_NOT_TYPE(p) … #define TRB_FH_TR_PACKET_FUNCTION_WAKE … #define TRB_FH_TO_INTERFACE(p) … enum cdnsp_setup_dev { … }; /* bits 24:31 are the slot ID. */ #define TRB_TO_SLOT_ID(p) … #define SLOT_ID_FOR_TRB(p) … /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB. */ #define TRB_TO_EP_INDEX(p) … #define EP_ID_FOR_TRB(p) … #define SUSPEND_PORT_FOR_TRB(p) … #define TRB_TO_SUSPEND_PORT(p) … #define LAST_EP_INDEX … /* Set TR Dequeue Pointer command TRB fields. */ #define TRB_TO_STREAM_ID(p) … #define STREAM_ID_FOR_TRB(p) … #define SCT_FOR_TRB(p) … /* Link TRB specific fields. */ #define TRB_TC … /* Port Status Change Event TRB fields. */ /* Port ID - bits 31:24. */ #define GET_PORT_ID(p) … #define SET_PORT_ID(p) … #define EVENT_DATA … /* Normal TRB fields. */ /* transfer_len bitmasks - bits 0:16. */ #define TRB_LEN(p) … /* TD Size, packets remaining in this TD, bits 21:17 (5 bits, so max 31). */ #define TRB_TD_SIZE(p) … #define GET_TD_SIZE(p) … /* * Controller uses the TD_SIZE field for TBC if Extended TBC * is enabled (ETE). */ #define TRB_TD_SIZE_TBC(p) … /* Interrupter Target - which MSI-X vector to target the completion event at. */ #define TRB_INTR_TARGET(p) … #define GET_INTR_TARGET(p) … /* * Total burst count field, Rsvdz on controller with Extended TBC * enabled (ETE). */ #define TRB_TBC(p) … #define TRB_TLBPC(p) … /* Cycle bit - indicates TRB ownership by driver or driver.*/ #define TRB_CYCLE … /* * Force next event data TRB to be evaluated before task switch. * Used to pass OS data back after a TD completes. */ #define TRB_ENT … /* Interrupt on short packet. */ #define TRB_ISP … /* Set PCIe no snoop attribute. */ #define TRB_NO_SNOOP … /* Chain multiple TRBs into a TD. */ #define TRB_CHAIN … /* Interrupt on completion. */ #define TRB_IOC … /* The buffer pointer contains immediate data. */ #define TRB_IDT … /* 0 - NRDY during data stage, 1 - NRDY during status stage (only control). */ #define TRB_STAT … /* Block Event Interrupt. */ #define TRB_BEI … /* Control transfer TRB specific fields. */ #define TRB_DIR_IN … /* TRB bit mask in Data Stage TRB */ #define TRB_SETUPID_BITMASK … #define TRB_SETUPID(p) … #define TRB_SETUPID_TO_TYPE(p) … #define TRB_SETUP_SPEEDID_USB3 … #define TRB_SETUP_SPEEDID_USB2 … #define TRB_SETUP_SPEEDID(p) … #define TRB_SETUPSTAT_ACK … #define TRB_SETUPSTAT_STALL … #define TRB_SETUPSTAT(p) … /* Isochronous TRB specific fields */ #define TRB_SIA … #define TRB_FRAME_ID(p) … struct cdnsp_generic_trb { … }; cdnsp_trb; /* TRB bit mask. */ #define TRB_TYPE_BITMASK … #define TRB_TYPE(p) … #define TRB_FIELD_TO_TYPE(p) … /* TRB type IDs. */ /* bulk, interrupt, isoc scatter/gather, and control data stage. */ #define TRB_NORMAL … /* Setup Stage for control transfers. */ #define TRB_SETUP … /* Data Stage for control transfers. */ #define TRB_DATA … /* Status Stage for control transfers. */ #define TRB_STATUS … /* ISOC transfers. */ #define TRB_ISOC … /* TRB for linking ring segments. */ #define TRB_LINK … #define TRB_EVENT_DATA … /* Transfer Ring No-op (not for the command ring). */ #define TRB_TR_NOOP … /* Command TRBs */ /* Enable Slot Command. */ #define TRB_ENABLE_SLOT … /* Disable Slot Command. */ #define TRB_DISABLE_SLOT … /* Address Device Command. */ #define TRB_ADDR_DEV … /* Configure Endpoint Command. */ #define TRB_CONFIG_EP … /* Evaluate Context Command. */ #define TRB_EVAL_CONTEXT … /* Reset Endpoint Command. */ #define TRB_RESET_EP … /* Stop Transfer Ring Command. */ #define TRB_STOP_RING … /* Set Transfer Ring Dequeue Pointer Command. */ #define TRB_SET_DEQ … /* Reset Device Command. */ #define TRB_RESET_DEV … /* Force Event Command (opt). */ #define TRB_FORCE_EVENT … /* Force Header Command - generate a transaction or link management packet. */ #define TRB_FORCE_HEADER … /* No-op Command - not for transfer rings. */ #define TRB_CMD_NOOP … /* TRB IDs 24-31 reserved. */ /* Event TRBS. */ /* Transfer Event. */ #define TRB_TRANSFER … /* Command Completion Event. */ #define TRB_COMPLETION … /* Port Status Change Event. */ #define TRB_PORT_STATUS … /* Device Controller Event. */ #define TRB_HC_EVENT … /* MFINDEX Wrap Event - microframe counter wrapped. */ #define TRB_MFINDEX_WRAP … /* TRB IDs 40-47 reserved. */ /* Endpoint Not Ready Event. */ #define TRB_ENDPOINT_NRDY … /* TRB IDs 49-53 reserved. */ /* Halt Endpoint Command. */ #define TRB_HALT_ENDPOINT … /* Doorbell Overflow Event. */ #define TRB_DRB_OVERFLOW … #define TRB_TYPE_LINK(x) … #define TRB_TYPE_LINK_LE32(x) … #define TRB_TYPE_NOOP_LE32(x) … /* * 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 … #define TRBS_PER_EVENT_SEGMENT … #define TRBS_PER_EV_DEQ_UPDATE … #define TRB_SEGMENT_SIZE … #define TRB_SEGMENT_SHIFT … /* TRB buffer pointers can't cross 64KB boundaries. */ #define TRB_MAX_BUFF_SHIFT … #define TRB_MAX_BUFF_SIZE … /* How much data is left before the 64KB boundary? */ #define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) … /** * 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 { … }; /** * 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 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 { … }; enum cdnsp_ring_type { … }; /** * 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_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 { … }; /** * 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_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 { … }; #define ERST_NUM_SEGS … /* Stages used during enumeration process.*/ enum cdnsp_ep0_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 { … }; #define CDNSP_EXT_PORT_MAJOR(x) … #define CDNSP_EXT_PORT_MINOR(x) … #define CDNSP_EXT_PORT_OFF(x) … #define CDNSP_EXT_PORT_COUNT(x) … /** * 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 * @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 { … }; /* * 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. */ static inline u64 cdnsp_read_64(__le64 __iomem *regs) { … } static inline void cdnsp_write_64(const u64 val, __le64 __iomem *regs) { … } /* CDNSP memory management functions. */ void cdnsp_mem_cleanup(struct cdnsp_device *pdev); int cdnsp_mem_init(struct cdnsp_device *pdev); int cdnsp_setup_addressable_priv_dev(struct cdnsp_device *pdev); void cdnsp_copy_ep0_dequeue_into_input_ctx(struct cdnsp_device *pdev); void cdnsp_endpoint_zero(struct cdnsp_device *pdev, struct cdnsp_ep *ep); int cdnsp_endpoint_init(struct cdnsp_device *pdev, struct cdnsp_ep *pep, gfp_t mem_flags); int cdnsp_ring_expansion(struct cdnsp_device *pdev, struct cdnsp_ring *ring, unsigned int num_trbs, gfp_t flags); struct cdnsp_ring *cdnsp_dma_to_transfer_ring(struct cdnsp_ep *ep, u64 address); int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, struct cdnsp_ep *pep, unsigned int num_stream_ctxs, unsigned int num_streams); int cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep); void cdnsp_free_endpoint_rings(struct cdnsp_device *pdev, struct cdnsp_ep *pep); /* Device controller glue. */ int cdnsp_find_next_ext_cap(void __iomem *base, u32 start, int id); int cdnsp_halt(struct cdnsp_device *pdev); void cdnsp_died(struct cdnsp_device *pdev); int cdnsp_reset(struct cdnsp_device *pdev); irqreturn_t cdnsp_irq_handler(int irq, void *priv); int cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup); void cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *usbsssp_data, struct usb_request *req, int enable); irqreturn_t cdnsp_thread_irq_handler(int irq, void *data); /* Ring, segment, TRB, and TD functions. */ dma_addr_t cdnsp_trb_virt_to_dma(struct cdnsp_segment *seg, union cdnsp_trb *trb); bool cdnsp_last_trb_on_seg(struct cdnsp_segment *seg, union cdnsp_trb *trb); bool cdnsp_last_trb_on_ring(struct cdnsp_ring *ring, struct cdnsp_segment *seg, union cdnsp_trb *trb); int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev); void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, union cdnsp_trb *event_ring_deq, u8 clear_ehb); void cdnsp_initialize_ring_info(struct cdnsp_ring *ring); void cdnsp_ring_cmd_db(struct cdnsp_device *pdev); void cdnsp_queue_slot_control(struct cdnsp_device *pdev, u32 trb_type); void cdnsp_queue_address_device(struct cdnsp_device *pdev, dma_addr_t in_ctx_ptr, enum cdnsp_setup_dev setup); void cdnsp_queue_stop_endpoint(struct cdnsp_device *pdev, unsigned int ep_index); int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq); int cdnsp_queue_bulk_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq); int cdnsp_queue_isoc_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq); void cdnsp_queue_configure_endpoint(struct cdnsp_device *pdev, dma_addr_t in_ctx_ptr); void cdnsp_queue_reset_ep(struct cdnsp_device *pdev, unsigned int ep_index); void cdnsp_queue_halt_endpoint(struct cdnsp_device *pdev, unsigned int ep_index); void cdnsp_force_header_wakeup(struct cdnsp_device *pdev, int intf_num); void cdnsp_queue_reset_device(struct cdnsp_device *pdev); void cdnsp_queue_new_dequeue_state(struct cdnsp_device *pdev, struct cdnsp_ep *pep, struct cdnsp_dequeue_state *deq_state); void cdnsp_ring_doorbell_for_active_rings(struct cdnsp_device *pdev, struct cdnsp_ep *pep); void cdnsp_inc_deq(struct cdnsp_device *pdev, struct cdnsp_ring *ring); void cdnsp_set_link_state(struct cdnsp_device *pdev, __le32 __iomem *port_regs, u32 link_state); u32 cdnsp_port_state_to_neutral(u32 state); /* CDNSP device controller contexts. */ int cdnsp_enable_slot(struct cdnsp_device *pdev); int cdnsp_disable_slot(struct cdnsp_device *pdev); struct cdnsp_input_control_ctx *cdnsp_get_input_control_ctx(struct cdnsp_container_ctx *ctx); struct cdnsp_slot_ctx *cdnsp_get_slot_ctx(struct cdnsp_container_ctx *ctx); struct cdnsp_ep_ctx *cdnsp_get_ep_ctx(struct cdnsp_container_ctx *ctx, unsigned int ep_index); /* CDNSP gadget interface. */ void cdnsp_suspend_gadget(struct cdnsp_device *pdev); void cdnsp_resume_gadget(struct cdnsp_device *pdev); void cdnsp_disconnect_gadget(struct cdnsp_device *pdev); void cdnsp_gadget_giveback(struct cdnsp_ep *pep, struct cdnsp_request *preq, int status); int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq); int cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq); unsigned int cdnsp_port_speed(unsigned int port_status); void cdnsp_irq_reset(struct cdnsp_device *pdev); int cdnsp_halt_endpoint(struct cdnsp_device *pdev, struct cdnsp_ep *pep, int value); int cdnsp_cmd_stop_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep); void cdnsp_setup_analyze(struct cdnsp_device *pdev); int cdnsp_status_stage(struct cdnsp_device *pdev); int cdnsp_reset_device(struct cdnsp_device *pdev); /** * 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. */ static inline struct cdnsp_request *next_request(struct list_head *list) { … } #define to_cdnsp_ep(ep) … #define gadget_to_cdnsp(g) … #define request_to_cdnsp_request(r) … #define to_cdnsp_request(r) … int cdnsp_remove_request(struct cdnsp_device *pdev, struct cdnsp_request *preq, struct cdnsp_ep *pep); #endif /* __LINUX_CDNSP_GADGET_H */