162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Cadence CDNSP DRD Driver. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2020 Cadence. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Author: Pawel Laszczak <pawell@cadence.com> 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Code based on Linux XHCI driver. 1062306a36Sopenharmony_ci * Origin: Copyright (C) 2008 Intel Corp. 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci#ifndef __LINUX_CDNSP_GADGET_H 1362306a36Sopenharmony_ci#define __LINUX_CDNSP_GADGET_H 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/io-64-nonatomic-lo-hi.h> 1662306a36Sopenharmony_ci#include <linux/usb/gadget.h> 1762306a36Sopenharmony_ci#include <linux/irq.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* Max number slots - only 1 is allowed. */ 2062306a36Sopenharmony_ci#define CDNSP_DEV_MAX_SLOTS 1 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#define CDNSP_EP0_SETUP_SIZE 512 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* One control and 15 for in and 15 for out endpoints. */ 2562306a36Sopenharmony_ci#define CDNSP_ENDPOINTS_NUM 31 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* Best Effort Service Latency. */ 2862306a36Sopenharmony_ci#define CDNSP_DEFAULT_BESL 0 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/* Device Controller command default timeout value in us */ 3162306a36Sopenharmony_ci#define CDNSP_CMD_TIMEOUT (15 * 1000) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/* Up to 16 ms to halt an device controller */ 3462306a36Sopenharmony_ci#define CDNSP_MAX_HALT_USEC (16 * 1000) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#define CDNSP_CTX_SIZE 2112 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* 3962306a36Sopenharmony_ci * Controller register interface. 4062306a36Sopenharmony_ci */ 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci/** 4362306a36Sopenharmony_ci * struct cdnsp_cap_regs - CDNSP Registers. 4462306a36Sopenharmony_ci * @hc_capbase: Length of the capabilities register and controller 4562306a36Sopenharmony_ci * version number 4662306a36Sopenharmony_ci * @hcs_params1: HCSPARAMS1 - Structural Parameters 1 4762306a36Sopenharmony_ci * @hcs_params2: HCSPARAMS2 - Structural Parameters 2 4862306a36Sopenharmony_ci * @hcs_params3: HCSPARAMS3 - Structural Parameters 3 4962306a36Sopenharmony_ci * @hcc_params: HCCPARAMS - Capability Parameters 5062306a36Sopenharmony_ci * @db_off: DBOFF - Doorbell array offset 5162306a36Sopenharmony_ci * @run_regs_off: RTSOFF - Runtime register space offset 5262306a36Sopenharmony_ci * @hcc_params2: HCCPARAMS2 Capability Parameters 2, 5362306a36Sopenharmony_ci */ 5462306a36Sopenharmony_cistruct cdnsp_cap_regs { 5562306a36Sopenharmony_ci __le32 hc_capbase; 5662306a36Sopenharmony_ci __le32 hcs_params1; 5762306a36Sopenharmony_ci __le32 hcs_params2; 5862306a36Sopenharmony_ci __le32 hcs_params3; 5962306a36Sopenharmony_ci __le32 hcc_params; 6062306a36Sopenharmony_ci __le32 db_off; 6162306a36Sopenharmony_ci __le32 run_regs_off; 6262306a36Sopenharmony_ci __le32 hcc_params2; 6362306a36Sopenharmony_ci /* Reserved up to (CAPLENGTH - 0x1C) */ 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* hc_capbase bitmasks. */ 6762306a36Sopenharmony_ci/* bits 7:0 - how long is the Capabilities register. */ 6862306a36Sopenharmony_ci#define HC_LENGTH(p) (((p) >> 00) & GENMASK(7, 0)) 6962306a36Sopenharmony_ci/* bits 31:16 */ 7062306a36Sopenharmony_ci#define HC_VERSION(p) (((p) >> 16) & GENMASK(15, 1)) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* HCSPARAMS1 - hcs_params1 - bitmasks */ 7362306a36Sopenharmony_ci/* bits 0:7, Max Device Endpoints */ 7462306a36Sopenharmony_ci#define HCS_ENDPOINTS_MASK GENMASK(7, 0) 7562306a36Sopenharmony_ci#define HCS_ENDPOINTS(p) (((p) & HCS_ENDPOINTS_MASK) >> 0) 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* HCCPARAMS offset from PCI base address */ 7862306a36Sopenharmony_ci#define HCC_PARAMS_OFFSET 0x10 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/* HCCPARAMS - hcc_params - bitmasks */ 8162306a36Sopenharmony_ci/* 1: device controller can use 64-bit address pointers. */ 8262306a36Sopenharmony_ci#define HCC_64BIT_ADDR(p) ((p) & BIT(0)) 8362306a36Sopenharmony_ci/* 1: device controller uses 64-byte Device Context structures. */ 8462306a36Sopenharmony_ci#define HCC_64BYTE_CONTEXT(p) ((p) & BIT(2)) 8562306a36Sopenharmony_ci/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15. */ 8662306a36Sopenharmony_ci#define HCC_MAX_PSA(p) ((((p) >> 12) & 0xf) + 1) 8762306a36Sopenharmony_ci/* Extended Capabilities pointer from PCI base. */ 8862306a36Sopenharmony_ci#define HCC_EXT_CAPS(p) (((p) & GENMASK(31, 16)) >> 16) 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32) 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/* db_off bitmask - bits 0:1 reserved. */ 9362306a36Sopenharmony_ci#define DBOFF_MASK GENMASK(31, 2) 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci/* run_regs_off bitmask - bits 0:4 reserved. */ 9662306a36Sopenharmony_ci#define RTSOFF_MASK GENMASK(31, 5) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci/** 9962306a36Sopenharmony_ci * struct cdnsp_op_regs - Device Controller Operational Registers. 10062306a36Sopenharmony_ci * @command: USBCMD - Controller command register. 10162306a36Sopenharmony_ci * @status: USBSTS - Controller status register. 10262306a36Sopenharmony_ci * @page_size: This indicates the page size that the device controller supports. 10362306a36Sopenharmony_ci * If bit n is set, the controller supports a page size of 2^(n+12), 10462306a36Sopenharmony_ci * up to a 128MB page size. 4K is the minimum page size. 10562306a36Sopenharmony_ci * @dnctrl: DNCTRL - Device notification control register. 10662306a36Sopenharmony_ci * @cmd_ring: CRP - 64-bit Command Ring Pointer. 10762306a36Sopenharmony_ci * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer. 10862306a36Sopenharmony_ci * @config_reg: CONFIG - Configure Register 10962306a36Sopenharmony_ci * @port_reg_base: PORTSCn - base address for Port Status and Control 11062306a36Sopenharmony_ci * Each port has a Port Status and Control register, 11162306a36Sopenharmony_ci * followed by a Port Power Management Status and Control 11262306a36Sopenharmony_ci * register, a Port Link Info register, and a reserved 11362306a36Sopenharmony_ci * register. 11462306a36Sopenharmony_ci */ 11562306a36Sopenharmony_cistruct cdnsp_op_regs { 11662306a36Sopenharmony_ci __le32 command; 11762306a36Sopenharmony_ci __le32 status; 11862306a36Sopenharmony_ci __le32 page_size; 11962306a36Sopenharmony_ci __le32 reserved1; 12062306a36Sopenharmony_ci __le32 reserved2; 12162306a36Sopenharmony_ci __le32 dnctrl; 12262306a36Sopenharmony_ci __le64 cmd_ring; 12362306a36Sopenharmony_ci /* rsvd: offset 0x20-2F. */ 12462306a36Sopenharmony_ci __le32 reserved3[4]; 12562306a36Sopenharmony_ci __le64 dcbaa_ptr; 12662306a36Sopenharmony_ci __le32 config_reg; 12762306a36Sopenharmony_ci /* rsvd: offset 0x3C-3FF. */ 12862306a36Sopenharmony_ci __le32 reserved4[241]; 12962306a36Sopenharmony_ci /* port 1 registers, which serve as a base address for other ports. */ 13062306a36Sopenharmony_ci __le32 port_reg_base; 13162306a36Sopenharmony_ci}; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci/* Number of registers per port. */ 13462306a36Sopenharmony_ci#define NUM_PORT_REGS 4 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci/** 13762306a36Sopenharmony_ci * struct cdnsp_port_regs - Port Registers. 13862306a36Sopenharmony_ci * @portsc: PORTSC - Port Status and Control Register. 13962306a36Sopenharmony_ci * @portpmsc: PORTPMSC - Port Power Managements Status and Control Register. 14062306a36Sopenharmony_ci * @portli: PORTLI - Port Link Info register. 14162306a36Sopenharmony_ci */ 14262306a36Sopenharmony_cistruct cdnsp_port_regs { 14362306a36Sopenharmony_ci __le32 portsc; 14462306a36Sopenharmony_ci __le32 portpmsc; 14562306a36Sopenharmony_ci __le32 portli; 14662306a36Sopenharmony_ci __le32 reserved; 14762306a36Sopenharmony_ci}; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci/* 15062306a36Sopenharmony_ci * These bits are Read Only (RO) and should be saved and written to the 15162306a36Sopenharmony_ci * registers: 0 (connect status) and 10:13 (port speed). 15262306a36Sopenharmony_ci * These bits are also sticky - meaning they're in the AUX well and they aren't 15362306a36Sopenharmony_ci * changed by a hot and warm. 15462306a36Sopenharmony_ci */ 15562306a36Sopenharmony_ci#define CDNSP_PORT_RO (PORT_CONNECT | DEV_SPEED_MASK) 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/* 15862306a36Sopenharmony_ci * These bits are RW; writing a 0 clears the bit, writing a 1 sets the bit: 15962306a36Sopenharmony_ci * bits 5:8 (link state), 25:26 ("wake on" enable state) 16062306a36Sopenharmony_ci */ 16162306a36Sopenharmony_ci#define CDNSP_PORT_RWS (PORT_PLS_MASK | PORT_WKCONN_E | PORT_WKDISC_E) 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci/* 16462306a36Sopenharmony_ci * These bits are RW; writing a 1 clears the bit, writing a 0 has no effect: 16562306a36Sopenharmony_ci * bits 1 (port enable/disable), 17 ( connect changed), 16662306a36Sopenharmony_ci * 21 (port reset changed) , 22 (Port Link State Change), 16762306a36Sopenharmony_ci */ 16862306a36Sopenharmony_ci#define CDNSP_PORT_RW1CS (PORT_PED | PORT_CSC | PORT_RC | PORT_PLC) 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci/* USBCMD - USB command - bitmasks. */ 17162306a36Sopenharmony_ci/* Run/Stop, controller execution - do not write unless controller is halted.*/ 17262306a36Sopenharmony_ci#define CMD_R_S BIT(0) 17362306a36Sopenharmony_ci/* 17462306a36Sopenharmony_ci * Reset device controller - resets internal controller state machine and all 17562306a36Sopenharmony_ci * registers (except PCI config regs). 17662306a36Sopenharmony_ci */ 17762306a36Sopenharmony_ci#define CMD_RESET BIT(1) 17862306a36Sopenharmony_ci/* Event Interrupt Enable - a '1' allows interrupts from the controller. */ 17962306a36Sopenharmony_ci#define CMD_INTE BIT(2) 18062306a36Sopenharmony_ci/* 18162306a36Sopenharmony_ci * Device System Error Interrupt Enable - get out-of-band signal for 18262306a36Sopenharmony_ci * controller errors. 18362306a36Sopenharmony_ci */ 18462306a36Sopenharmony_ci#define CMD_DSEIE BIT(3) 18562306a36Sopenharmony_ci/* device controller save/restore state. */ 18662306a36Sopenharmony_ci#define CMD_CSS BIT(8) 18762306a36Sopenharmony_ci#define CMD_CRS BIT(9) 18862306a36Sopenharmony_ci/* 18962306a36Sopenharmony_ci * Enable Wrap Event - '1' means device controller generates an event 19062306a36Sopenharmony_ci * when MFINDEX wraps. 19162306a36Sopenharmony_ci */ 19262306a36Sopenharmony_ci#define CMD_EWE BIT(10) 19362306a36Sopenharmony_ci/* 1: device enabled */ 19462306a36Sopenharmony_ci#define CMD_DEVEN BIT(17) 19562306a36Sopenharmony_ci/* bits 18:31 are reserved (and should be preserved on writes). */ 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci/* Command register values to disable interrupts. */ 19862306a36Sopenharmony_ci#define CDNSP_IRQS (CMD_INTE | CMD_DSEIE | CMD_EWE) 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci/* USBSTS - USB status - bitmasks */ 20162306a36Sopenharmony_ci/* controller not running - set to 1 when run/stop bit is cleared. */ 20262306a36Sopenharmony_ci#define STS_HALT BIT(0) 20362306a36Sopenharmony_ci/* 20462306a36Sopenharmony_ci * serious error, e.g. PCI parity error. The controller will clear 20562306a36Sopenharmony_ci * the run/stop bit. 20662306a36Sopenharmony_ci */ 20762306a36Sopenharmony_ci#define STS_FATAL BIT(2) 20862306a36Sopenharmony_ci/* event interrupt - clear this prior to clearing any IP flags in IR set.*/ 20962306a36Sopenharmony_ci#define STS_EINT BIT(3) 21062306a36Sopenharmony_ci/* port change detect */ 21162306a36Sopenharmony_ci#define STS_PCD BIT(4) 21262306a36Sopenharmony_ci/* save state status - '1' means device controller is saving state. */ 21362306a36Sopenharmony_ci#define STS_SSS BIT(8) 21462306a36Sopenharmony_ci/* restore state status - '1' means controllers is restoring state. */ 21562306a36Sopenharmony_ci#define STS_RSS BIT(9) 21662306a36Sopenharmony_ci/* 1: save or restore error */ 21762306a36Sopenharmony_ci#define STS_SRE BIT(10) 21862306a36Sopenharmony_ci/* 1: device Not Ready to accept doorbell or op reg writes after reset. */ 21962306a36Sopenharmony_ci#define STS_CNR BIT(11) 22062306a36Sopenharmony_ci/* 1: internal Device Controller Error.*/ 22162306a36Sopenharmony_ci#define STS_HCE BIT(12) 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci/* CRCR - Command Ring Control Register - cmd_ring bitmasks. */ 22462306a36Sopenharmony_ci/* bit 0 is the command ring cycle state. */ 22562306a36Sopenharmony_ci#define CMD_RING_CS BIT(0) 22662306a36Sopenharmony_ci/* stop ring immediately - abort the currently executing command. */ 22762306a36Sopenharmony_ci#define CMD_RING_ABORT BIT(2) 22862306a36Sopenharmony_ci/* 22962306a36Sopenharmony_ci * Command Ring Busy. 23062306a36Sopenharmony_ci * Set when Doorbell register is written with DB for command and cleared when 23162306a36Sopenharmony_ci * the controller reached end of CR. 23262306a36Sopenharmony_ci */ 23362306a36Sopenharmony_ci#define CMD_RING_BUSY(p) ((p) & BIT(4)) 23462306a36Sopenharmony_ci/* 1: command ring is running */ 23562306a36Sopenharmony_ci#define CMD_RING_RUNNING BIT(3) 23662306a36Sopenharmony_ci/* Command Ring pointer - bit mask for the lower 32 bits. */ 23762306a36Sopenharmony_ci#define CMD_RING_RSVD_BITS GENMASK(5, 0) 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci/* CONFIG - Configure Register - config_reg bitmasks. */ 24062306a36Sopenharmony_ci/* bits 0:7 - maximum number of device slots enabled. */ 24162306a36Sopenharmony_ci#define MAX_DEVS GENMASK(7, 0) 24262306a36Sopenharmony_ci/* bit 8: U3 Entry Enabled, assert PLC when controller enters U3. */ 24362306a36Sopenharmony_ci#define CONFIG_U3E BIT(8) 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci/* PORTSC - Port Status and Control Register - port_reg_base bitmasks */ 24662306a36Sopenharmony_ci/* 1: device connected. */ 24762306a36Sopenharmony_ci#define PORT_CONNECT BIT(0) 24862306a36Sopenharmony_ci/* 1: port enabled. */ 24962306a36Sopenharmony_ci#define PORT_PED BIT(1) 25062306a36Sopenharmony_ci/* 1: port reset signaling asserted. */ 25162306a36Sopenharmony_ci#define PORT_RESET BIT(4) 25262306a36Sopenharmony_ci/* 25362306a36Sopenharmony_ci * Port Link State - bits 5:8 25462306a36Sopenharmony_ci * A read gives the current link PM state of the port, 25562306a36Sopenharmony_ci * a write with Link State Write Strobe sets the link state. 25662306a36Sopenharmony_ci */ 25762306a36Sopenharmony_ci#define PORT_PLS_MASK GENMASK(8, 5) 25862306a36Sopenharmony_ci#define XDEV_U0 (0x0 << 5) 25962306a36Sopenharmony_ci#define XDEV_U1 (0x1 << 5) 26062306a36Sopenharmony_ci#define XDEV_U2 (0x2 << 5) 26162306a36Sopenharmony_ci#define XDEV_U3 (0x3 << 5) 26262306a36Sopenharmony_ci#define XDEV_DISABLED (0x4 << 5) 26362306a36Sopenharmony_ci#define XDEV_RXDETECT (0x5 << 5) 26462306a36Sopenharmony_ci#define XDEV_INACTIVE (0x6 << 5) 26562306a36Sopenharmony_ci#define XDEV_POLLING (0x7 << 5) 26662306a36Sopenharmony_ci#define XDEV_RECOVERY (0x8 << 5) 26762306a36Sopenharmony_ci#define XDEV_HOT_RESET (0x9 << 5) 26862306a36Sopenharmony_ci#define XDEV_COMP_MODE (0xa << 5) 26962306a36Sopenharmony_ci#define XDEV_TEST_MODE (0xb << 5) 27062306a36Sopenharmony_ci#define XDEV_RESUME (0xf << 5) 27162306a36Sopenharmony_ci/* 1: port has power. */ 27262306a36Sopenharmony_ci#define PORT_POWER BIT(9) 27362306a36Sopenharmony_ci/* 27462306a36Sopenharmony_ci * bits 10:13 indicate device speed: 27562306a36Sopenharmony_ci * 0 - undefined speed - port hasn't be initialized by a reset yet 27662306a36Sopenharmony_ci * 1 - full speed 27762306a36Sopenharmony_ci * 2 - Reserved (Low Speed not supported 27862306a36Sopenharmony_ci * 3 - high speed 27962306a36Sopenharmony_ci * 4 - super speed 28062306a36Sopenharmony_ci * 5 - super speed 28162306a36Sopenharmony_ci * 6-15 reserved 28262306a36Sopenharmony_ci */ 28362306a36Sopenharmony_ci#define DEV_SPEED_MASK GENMASK(13, 10) 28462306a36Sopenharmony_ci#define XDEV_FS (0x1 << 10) 28562306a36Sopenharmony_ci#define XDEV_HS (0x3 << 10) 28662306a36Sopenharmony_ci#define XDEV_SS (0x4 << 10) 28762306a36Sopenharmony_ci#define XDEV_SSP (0x5 << 10) 28862306a36Sopenharmony_ci#define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0 << 10)) 28962306a36Sopenharmony_ci#define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS) 29062306a36Sopenharmony_ci#define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS) 29162306a36Sopenharmony_ci#define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS) 29262306a36Sopenharmony_ci#define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP) 29362306a36Sopenharmony_ci#define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS) 29462306a36Sopenharmony_ci#define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f) 29562306a36Sopenharmony_ci/* Port Link State Write Strobe - set this when changing link state */ 29662306a36Sopenharmony_ci#define PORT_LINK_STROBE BIT(16) 29762306a36Sopenharmony_ci/* 1: connect status change */ 29862306a36Sopenharmony_ci#define PORT_CSC BIT(17) 29962306a36Sopenharmony_ci/* 1: warm reset for a USB 3.0 device is done. */ 30062306a36Sopenharmony_ci#define PORT_WRC BIT(19) 30162306a36Sopenharmony_ci/* 1: reset change - 1 to 0 transition of PORT_RESET */ 30262306a36Sopenharmony_ci#define PORT_RC BIT(21) 30362306a36Sopenharmony_ci/* 30462306a36Sopenharmony_ci * port link status change - set on some port link state transitions: 30562306a36Sopenharmony_ci * Transition Reason 30662306a36Sopenharmony_ci * ---------------------------------------------------------------------------- 30762306a36Sopenharmony_ci * - U3 to Resume Wakeup signaling from a device 30862306a36Sopenharmony_ci * - Resume to Recovery to U0 USB 3.0 device resume 30962306a36Sopenharmony_ci * - Resume to U0 USB 2.0 device resume 31062306a36Sopenharmony_ci * - U3 to Recovery to U0 Software resume of USB 3.0 device complete 31162306a36Sopenharmony_ci * - U3 to U0 Software resume of USB 2.0 device complete 31262306a36Sopenharmony_ci * - U2 to U0 L1 resume of USB 2.1 device complete 31362306a36Sopenharmony_ci * - U0 to U0 L1 entry rejection by USB 2.1 device 31462306a36Sopenharmony_ci * - U0 to disabled L1 entry error with USB 2.1 device 31562306a36Sopenharmony_ci * - Any state to inactive Error on USB 3.0 port 31662306a36Sopenharmony_ci */ 31762306a36Sopenharmony_ci#define PORT_PLC BIT(22) 31862306a36Sopenharmony_ci/* Port configure error change - port failed to configure its link partner. */ 31962306a36Sopenharmony_ci#define PORT_CEC BIT(23) 32062306a36Sopenharmony_ci/* Wake on connect (enable). */ 32162306a36Sopenharmony_ci#define PORT_WKCONN_E BIT(25) 32262306a36Sopenharmony_ci/* Wake on disconnect (enable). */ 32362306a36Sopenharmony_ci#define PORT_WKDISC_E BIT(26) 32462306a36Sopenharmony_ci/* Indicates if Warm Reset is being received. */ 32562306a36Sopenharmony_ci#define PORT_WR BIT(31) 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci#define PORT_CHANGE_BITS (PORT_CSC | PORT_WRC | PORT_RC | PORT_PLC | PORT_CEC) 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci/* PORTPMSCUSB3 - Port Power Management Status and Control - bitmasks. */ 33062306a36Sopenharmony_ci/* Enables U1 entry. */ 33162306a36Sopenharmony_ci#define PORT_U1_TIMEOUT_MASK GENMASK(7, 0) 33262306a36Sopenharmony_ci#define PORT_U1_TIMEOUT(p) ((p) & PORT_U1_TIMEOUT_MASK) 33362306a36Sopenharmony_ci/* Enables U2 entry .*/ 33462306a36Sopenharmony_ci#define PORT_U2_TIMEOUT_MASK GENMASK(14, 8) 33562306a36Sopenharmony_ci#define PORT_U2_TIMEOUT(p) (((p) << 8) & PORT_U2_TIMEOUT_MASK) 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci/* PORTPMSCUSB2 - Port Power Management Status and Control - bitmasks. */ 33862306a36Sopenharmony_ci#define PORT_L1S_MASK GENMASK(2, 0) 33962306a36Sopenharmony_ci#define PORT_L1S(p) ((p) & PORT_L1S_MASK) 34062306a36Sopenharmony_ci#define PORT_L1S_ACK PORT_L1S(1) 34162306a36Sopenharmony_ci#define PORT_L1S_NYET PORT_L1S(2) 34262306a36Sopenharmony_ci#define PORT_L1S_STALL PORT_L1S(3) 34362306a36Sopenharmony_ci#define PORT_L1S_TIMEOUT PORT_L1S(4) 34462306a36Sopenharmony_ci/* Remote Wake Enable. */ 34562306a36Sopenharmony_ci#define PORT_RWE BIT(3) 34662306a36Sopenharmony_ci/* Best Effort Service Latency (BESL). */ 34762306a36Sopenharmony_ci#define PORT_BESL(p) (((p) << 4) & GENMASK(7, 4)) 34862306a36Sopenharmony_ci/* Hardware LPM Enable (HLE). */ 34962306a36Sopenharmony_ci#define PORT_HLE BIT(16) 35062306a36Sopenharmony_ci/* Received Best Effort Service Latency (BESL). */ 35162306a36Sopenharmony_ci#define PORT_RRBESL(p) (((p) & GENMASK(20, 17)) >> 17) 35262306a36Sopenharmony_ci/* Port Test Control. */ 35362306a36Sopenharmony_ci#define PORT_TEST_MODE_MASK GENMASK(31, 28) 35462306a36Sopenharmony_ci#define PORT_TEST_MODE(p) (((p) << 28) & PORT_TEST_MODE_MASK) 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ci/** 35762306a36Sopenharmony_ci * struct cdnsp_intr_reg - Interrupt Register Set. 35862306a36Sopenharmony_ci * @irq_pending: IMAN - Interrupt Management Register. Used to enable 35962306a36Sopenharmony_ci * interrupts and check for pending interrupts. 36062306a36Sopenharmony_ci * @irq_control: IMOD - Interrupt Moderation Register. 36162306a36Sopenharmony_ci * Used to throttle interrupts. 36262306a36Sopenharmony_ci * @erst_size: Number of segments in the Event Ring Segment Table (ERST). 36362306a36Sopenharmony_ci * @erst_base: ERST base address. 36462306a36Sopenharmony_ci * @erst_dequeue: Event ring dequeue pointer. 36562306a36Sopenharmony_ci * 36662306a36Sopenharmony_ci * Each interrupter (defined by a MSI-X vector) has an event ring and an Event 36762306a36Sopenharmony_ci * Ring Segment Table (ERST) associated with it. The event ring is comprised of 36862306a36Sopenharmony_ci * multiple segments of the same size. The controller places events on the ring 36962306a36Sopenharmony_ci * and "updates the Cycle bit in the TRBs to indicate to software the current 37062306a36Sopenharmony_ci * position of the Enqueue Pointer." The driver processes those events and 37162306a36Sopenharmony_ci * updates the dequeue pointer. 37262306a36Sopenharmony_ci */ 37362306a36Sopenharmony_cistruct cdnsp_intr_reg { 37462306a36Sopenharmony_ci __le32 irq_pending; 37562306a36Sopenharmony_ci __le32 irq_control; 37662306a36Sopenharmony_ci __le32 erst_size; 37762306a36Sopenharmony_ci __le32 rsvd; 37862306a36Sopenharmony_ci __le64 erst_base; 37962306a36Sopenharmony_ci __le64 erst_dequeue; 38062306a36Sopenharmony_ci}; 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci/* IMAN - Interrupt Management Register - irq_pending bitmasks l. */ 38362306a36Sopenharmony_ci#define IMAN_IE BIT(1) 38462306a36Sopenharmony_ci#define IMAN_IP BIT(0) 38562306a36Sopenharmony_ci/* bits 2:31 need to be preserved */ 38662306a36Sopenharmony_ci#define IMAN_IE_SET(p) ((p) | IMAN_IE) 38762306a36Sopenharmony_ci#define IMAN_IE_CLEAR(p) ((p) & ~IMAN_IE) 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci/* IMOD - Interrupter Moderation Register - irq_control bitmasks. */ 39062306a36Sopenharmony_ci/* 39162306a36Sopenharmony_ci * Minimum interval between interrupts (in 250ns intervals). The interval 39262306a36Sopenharmony_ci * between interrupts will be longer if there are no events on the event ring. 39362306a36Sopenharmony_ci * Default is 4000 (1 ms). 39462306a36Sopenharmony_ci */ 39562306a36Sopenharmony_ci#define IMOD_INTERVAL_MASK GENMASK(15, 0) 39662306a36Sopenharmony_ci/* Counter used to count down the time to the next interrupt - HW use only */ 39762306a36Sopenharmony_ci#define IMOD_COUNTER_MASK GENMASK(31, 16) 39862306a36Sopenharmony_ci#define IMOD_DEFAULT_INTERVAL 0 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_ci/* erst_size bitmasks. */ 40162306a36Sopenharmony_ci/* Preserve bits 16:31 of erst_size. */ 40262306a36Sopenharmony_ci#define ERST_SIZE_MASK GENMASK(31, 16) 40362306a36Sopenharmony_ci 40462306a36Sopenharmony_ci/* erst_dequeue bitmasks. */ 40562306a36Sopenharmony_ci/* 40662306a36Sopenharmony_ci * Dequeue ERST Segment Index (DESI) - Segment number (or alias) 40762306a36Sopenharmony_ci * where the current dequeue pointer lies. This is an optional HW hint. 40862306a36Sopenharmony_ci */ 40962306a36Sopenharmony_ci#define ERST_DESI_MASK GENMASK(2, 0) 41062306a36Sopenharmony_ci/* Event Handler Busy (EHB) - is the event ring scheduled to be serviced. */ 41162306a36Sopenharmony_ci#define ERST_EHB BIT(3) 41262306a36Sopenharmony_ci#define ERST_PTR_MASK GENMASK(3, 0) 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci/** 41562306a36Sopenharmony_ci * struct cdnsp_run_regs 41662306a36Sopenharmony_ci * @microframe_index: MFINDEX - current microframe number. 41762306a36Sopenharmony_ci * @ir_set: Array of Interrupter registers. 41862306a36Sopenharmony_ci * 41962306a36Sopenharmony_ci * Device Controller Runtime Registers: 42062306a36Sopenharmony_ci * "Software should read and write these registers using only Dword (32 bit) 42162306a36Sopenharmony_ci * or larger accesses" 42262306a36Sopenharmony_ci */ 42362306a36Sopenharmony_cistruct cdnsp_run_regs { 42462306a36Sopenharmony_ci __le32 microframe_index; 42562306a36Sopenharmony_ci __le32 rsvd[7]; 42662306a36Sopenharmony_ci struct cdnsp_intr_reg ir_set[128]; 42762306a36Sopenharmony_ci}; 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci/** 43062306a36Sopenharmony_ci * USB2.0 Port Peripheral Configuration Registers. 43162306a36Sopenharmony_ci * @ext_cap: Header register for Extended Capability. 43262306a36Sopenharmony_ci * @port_reg1: Timer Configuration Register. 43362306a36Sopenharmony_ci * @port_reg2: Timer Configuration Register. 43462306a36Sopenharmony_ci * @port_reg3: Timer Configuration Register. 43562306a36Sopenharmony_ci * @port_reg4: Timer Configuration Register. 43662306a36Sopenharmony_ci * @port_reg5: Timer Configuration Register. 43762306a36Sopenharmony_ci * @port_reg6: Chicken bits for USB20PPP. 43862306a36Sopenharmony_ci */ 43962306a36Sopenharmony_cistruct cdnsp_20port_cap { 44062306a36Sopenharmony_ci __le32 ext_cap; 44162306a36Sopenharmony_ci __le32 port_reg1; 44262306a36Sopenharmony_ci __le32 port_reg2; 44362306a36Sopenharmony_ci __le32 port_reg3; 44462306a36Sopenharmony_ci __le32 port_reg4; 44562306a36Sopenharmony_ci __le32 port_reg5; 44662306a36Sopenharmony_ci __le32 port_reg6; 44762306a36Sopenharmony_ci}; 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci/* Extended capability register fields */ 45062306a36Sopenharmony_ci#define EXT_CAPS_ID(p) (((p) >> 0) & GENMASK(7, 0)) 45162306a36Sopenharmony_ci#define EXT_CAPS_NEXT(p) (((p) >> 8) & GENMASK(7, 0)) 45262306a36Sopenharmony_ci/* Extended capability IDs - ID 0 reserved */ 45362306a36Sopenharmony_ci#define EXT_CAPS_PROTOCOL 2 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci/* USB 2.0 Port Peripheral Configuration Extended Capability */ 45662306a36Sopenharmony_ci#define EXT_CAP_CFG_DEV_20PORT_CAP_ID 0xC1 45762306a36Sopenharmony_ci/* 45862306a36Sopenharmony_ci * Setting this bit to '1' enables automatic wakeup from L1 state on transfer 45962306a36Sopenharmony_ci * TRB prepared when USBSSP operates in USB2.0 mode. 46062306a36Sopenharmony_ci */ 46162306a36Sopenharmony_ci#define PORT_REG6_L1_L0_HW_EN BIT(1) 46262306a36Sopenharmony_ci/* 46362306a36Sopenharmony_ci * Setting this bit to '1' forces Full Speed when USBSSP operates in USB2.0 46462306a36Sopenharmony_ci * mode (disables High Speed). 46562306a36Sopenharmony_ci */ 46662306a36Sopenharmony_ci#define PORT_REG6_FORCE_FS BIT(0) 46762306a36Sopenharmony_ci 46862306a36Sopenharmony_ci/** 46962306a36Sopenharmony_ci * USB3.x Port Peripheral Configuration Registers. 47062306a36Sopenharmony_ci * @ext_cap: Header register for Extended Capability. 47162306a36Sopenharmony_ci * @mode_addr: Miscellaneous 3xPORT operation mode configuration register. 47262306a36Sopenharmony_ci * @mode_2: 3x Port Control Register 2. 47362306a36Sopenharmony_ci */ 47462306a36Sopenharmony_cistruct cdnsp_3xport_cap { 47562306a36Sopenharmony_ci __le32 ext_cap; 47662306a36Sopenharmony_ci __le32 mode_addr; 47762306a36Sopenharmony_ci __le32 reserved[52]; 47862306a36Sopenharmony_ci __le32 mode_2; 47962306a36Sopenharmony_ci}; 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci/* Extended Capability Header for 3XPort Configuration Registers. */ 48262306a36Sopenharmony_ci#define D_XEC_CFG_3XPORT_CAP 0xC0 48362306a36Sopenharmony_ci#define CFG_3XPORT_SSP_SUPPORT BIT(31) 48462306a36Sopenharmony_ci#define CFG_3XPORT_U1_PIPE_CLK_GATE_EN BIT(0) 48562306a36Sopenharmony_ci 48662306a36Sopenharmony_ci/* Revision Extended Capability ID */ 48762306a36Sopenharmony_ci#define RTL_REV_CAP 0xC4 48862306a36Sopenharmony_ci#define RTL_REV_CAP_RX_BUFF_CMD_SIZE BITMASK(31, 24) 48962306a36Sopenharmony_ci#define RTL_REV_CAP_RX_BUFF_SIZE BITMASK(15, 0) 49062306a36Sopenharmony_ci#define RTL_REV_CAP_TX_BUFF_CMD_SIZE BITMASK(31, 24) 49162306a36Sopenharmony_ci#define RTL_REV_CAP_TX_BUFF_SIZE BITMASK(15, 0) 49262306a36Sopenharmony_ci 49362306a36Sopenharmony_ci#define CDNSP_VER_1 0x00000000 49462306a36Sopenharmony_ci#define CDNSP_VER_2 0x10000000 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_ci#define CDNSP_IF_EP_EXIST(pdev, ep_num, dir) \ 49762306a36Sopenharmony_ci (readl(&(pdev)->rev_cap->ep_supported) & \ 49862306a36Sopenharmony_ci (BIT(ep_num) << ((dir) ? 0 : 16))) 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci/** 50162306a36Sopenharmony_ci * struct cdnsp_rev_cap - controller capabilities. 50262306a36Sopenharmony_ci * @ext_cap: Header for RTL Revision Extended Capability. 50362306a36Sopenharmony_ci * @rtl_revision: RTL revision. 50462306a36Sopenharmony_ci * @rx_buff_size: Rx buffer sizes. 50562306a36Sopenharmony_ci * @tx_buff_size: Tx buffer sizes. 50662306a36Sopenharmony_ci * @ep_supported: Supported endpoints. 50762306a36Sopenharmony_ci * @ctrl_revision: Controller revision ID. 50862306a36Sopenharmony_ci */ 50962306a36Sopenharmony_cistruct cdnsp_rev_cap { 51062306a36Sopenharmony_ci __le32 ext_cap; 51162306a36Sopenharmony_ci __le32 rtl_revision; 51262306a36Sopenharmony_ci __le32 rx_buff_size; 51362306a36Sopenharmony_ci __le32 tx_buff_size; 51462306a36Sopenharmony_ci __le32 ep_supported; 51562306a36Sopenharmony_ci __le32 ctrl_revision; 51662306a36Sopenharmony_ci}; 51762306a36Sopenharmony_ci 51862306a36Sopenharmony_ci/* USB2.0 Port Peripheral Configuration Registers. */ 51962306a36Sopenharmony_ci#define D_XEC_PRE_REGS_CAP 0xC8 52062306a36Sopenharmony_ci#define REG_CHICKEN_BITS_2_OFFSET 0x48 52162306a36Sopenharmony_ci#define CHICKEN_XDMA_2_TP_CACHE_DIS BIT(28) 52262306a36Sopenharmony_ci 52362306a36Sopenharmony_ci/* XBUF Extended Capability ID. */ 52462306a36Sopenharmony_ci#define XBUF_CAP_ID 0xCB 52562306a36Sopenharmony_ci#define XBUF_RX_TAG_MASK_0_OFFSET 0x1C 52662306a36Sopenharmony_ci#define XBUF_RX_TAG_MASK_1_OFFSET 0x24 52762306a36Sopenharmony_ci#define XBUF_TX_CMD_OFFSET 0x2C 52862306a36Sopenharmony_ci 52962306a36Sopenharmony_ci/** 53062306a36Sopenharmony_ci * struct cdnsp_doorbell_array. 53162306a36Sopenharmony_ci * @cmd_db: Command ring doorbell register. 53262306a36Sopenharmony_ci * @ep_db: Endpoint ring doorbell register. 53362306a36Sopenharmony_ci * Bits 0 - 7: Endpoint target. 53462306a36Sopenharmony_ci * Bits 8 - 15: RsvdZ. 53562306a36Sopenharmony_ci * Bits 16 - 31: Stream ID. 53662306a36Sopenharmony_ci */ 53762306a36Sopenharmony_cistruct cdnsp_doorbell_array { 53862306a36Sopenharmony_ci __le32 cmd_db; 53962306a36Sopenharmony_ci __le32 ep_db; 54062306a36Sopenharmony_ci}; 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_ci#define DB_VALUE(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16)) 54362306a36Sopenharmony_ci#define DB_VALUE_EP0_OUT(ep, stream) ((ep) & 0xff) 54462306a36Sopenharmony_ci#define DB_VALUE_CMD 0x00000000 54562306a36Sopenharmony_ci 54662306a36Sopenharmony_ci/** 54762306a36Sopenharmony_ci * struct cdnsp_container_ctx. 54862306a36Sopenharmony_ci * @type: Type of context. Used to calculated offsets to contained contexts. 54962306a36Sopenharmony_ci * @size: Size of the context data. 55062306a36Sopenharmony_ci * @ctx_size: context data structure size - 64 or 32 bits. 55162306a36Sopenharmony_ci * @dma: dma address of the bytes. 55262306a36Sopenharmony_ci * @bytes: The raw context data given to HW. 55362306a36Sopenharmony_ci * 55462306a36Sopenharmony_ci * Represents either a Device or Input context. Holds a pointer to the raw 55562306a36Sopenharmony_ci * memory used for the context (bytes) and dma address of it (dma). 55662306a36Sopenharmony_ci */ 55762306a36Sopenharmony_cistruct cdnsp_container_ctx { 55862306a36Sopenharmony_ci unsigned int type; 55962306a36Sopenharmony_ci#define CDNSP_CTX_TYPE_DEVICE 0x1 56062306a36Sopenharmony_ci#define CDNSP_CTX_TYPE_INPUT 0x2 56162306a36Sopenharmony_ci int size; 56262306a36Sopenharmony_ci int ctx_size; 56362306a36Sopenharmony_ci dma_addr_t dma; 56462306a36Sopenharmony_ci u8 *bytes; 56562306a36Sopenharmony_ci}; 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci/** 56862306a36Sopenharmony_ci * struct cdnsp_slot_ctx 56962306a36Sopenharmony_ci * @dev_info: Device speed, and last valid endpoint. 57062306a36Sopenharmony_ci * @dev_port: Device port number that is needed to access the USB device. 57162306a36Sopenharmony_ci * @int_target: Interrupter target number. 57262306a36Sopenharmony_ci * @dev_state: Slot state and device address. 57362306a36Sopenharmony_ci * 57462306a36Sopenharmony_ci * Slot Context - This assumes the controller uses 32-byte context 57562306a36Sopenharmony_ci * structures. If the controller uses 64-byte contexts, there is an additional 57662306a36Sopenharmony_ci * 32 bytes reserved at the end of the slot context for controller internal use. 57762306a36Sopenharmony_ci */ 57862306a36Sopenharmony_cistruct cdnsp_slot_ctx { 57962306a36Sopenharmony_ci __le32 dev_info; 58062306a36Sopenharmony_ci __le32 dev_port; 58162306a36Sopenharmony_ci __le32 int_target; 58262306a36Sopenharmony_ci __le32 dev_state; 58362306a36Sopenharmony_ci /* offset 0x10 to 0x1f reserved for controller internal use. */ 58462306a36Sopenharmony_ci __le32 reserved[4]; 58562306a36Sopenharmony_ci}; 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ci/* Bits 20:23 in the Slot Context are the speed for the device. */ 58862306a36Sopenharmony_ci#define SLOT_SPEED_FS (XDEV_FS << 10) 58962306a36Sopenharmony_ci#define SLOT_SPEED_HS (XDEV_HS << 10) 59062306a36Sopenharmony_ci#define SLOT_SPEED_SS (XDEV_SS << 10) 59162306a36Sopenharmony_ci#define SLOT_SPEED_SSP (XDEV_SSP << 10) 59262306a36Sopenharmony_ci 59362306a36Sopenharmony_ci/* dev_info bitmasks. */ 59462306a36Sopenharmony_ci/* Device speed - values defined by PORTSC Device Speed field - 20:23. */ 59562306a36Sopenharmony_ci#define DEV_SPEED GENMASK(23, 20) 59662306a36Sopenharmony_ci#define GET_DEV_SPEED(n) (((n) & DEV_SPEED) >> 20) 59762306a36Sopenharmony_ci/* Index of the last valid endpoint context in this device context - 27:31. */ 59862306a36Sopenharmony_ci#define LAST_CTX_MASK ((unsigned int)GENMASK(31, 27)) 59962306a36Sopenharmony_ci#define LAST_CTX(p) ((p) << 27) 60062306a36Sopenharmony_ci#define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1) 60162306a36Sopenharmony_ci#define SLOT_FLAG BIT(0) 60262306a36Sopenharmony_ci#define EP0_FLAG BIT(1) 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ci/* dev_port bitmasks */ 60562306a36Sopenharmony_ci/* Device port number that is needed to access the USB device. */ 60662306a36Sopenharmony_ci#define DEV_PORT(p) (((p) & 0xff) << 16) 60762306a36Sopenharmony_ci 60862306a36Sopenharmony_ci/* dev_state bitmasks */ 60962306a36Sopenharmony_ci/* USB device address - assigned by the controller. */ 61062306a36Sopenharmony_ci#define DEV_ADDR_MASK GENMASK(7, 0) 61162306a36Sopenharmony_ci/* Slot state */ 61262306a36Sopenharmony_ci#define SLOT_STATE GENMASK(31, 27) 61362306a36Sopenharmony_ci#define GET_SLOT_STATE(p) (((p) & SLOT_STATE) >> 27) 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ci#define SLOT_STATE_DISABLED 0 61662306a36Sopenharmony_ci#define SLOT_STATE_ENABLED SLOT_STATE_DISABLED 61762306a36Sopenharmony_ci#define SLOT_STATE_DEFAULT 1 61862306a36Sopenharmony_ci#define SLOT_STATE_ADDRESSED 2 61962306a36Sopenharmony_ci#define SLOT_STATE_CONFIGURED 3 62062306a36Sopenharmony_ci 62162306a36Sopenharmony_ci/** 62262306a36Sopenharmony_ci * struct cdnsp_ep_ctx. 62362306a36Sopenharmony_ci * @ep_info: Endpoint state, streams, mult, and interval information. 62462306a36Sopenharmony_ci * @ep_info2: Information on endpoint type, max packet size, max burst size, 62562306a36Sopenharmony_ci * error count, and whether the controller will force an event for 62662306a36Sopenharmony_ci * all transactions. 62762306a36Sopenharmony_ci * @deq: 64-bit ring dequeue pointer address. If the endpoint only 62862306a36Sopenharmony_ci * defines one stream, this points to the endpoint transfer ring. 62962306a36Sopenharmony_ci * Otherwise, it points to a stream context array, which has a 63062306a36Sopenharmony_ci * ring pointer for each flow. 63162306a36Sopenharmony_ci * @tx_info: Average TRB lengths for the endpoint ring and 63262306a36Sopenharmony_ci * max payload within an Endpoint Service Interval Time (ESIT). 63362306a36Sopenharmony_ci * 63462306a36Sopenharmony_ci * Endpoint Context - This assumes the controller uses 32-byte context 63562306a36Sopenharmony_ci * structures. If the controller uses 64-byte contexts, there is an additional 63662306a36Sopenharmony_ci * 32 bytes reserved at the end of the endpoint context for controller internal 63762306a36Sopenharmony_ci * use. 63862306a36Sopenharmony_ci */ 63962306a36Sopenharmony_cistruct cdnsp_ep_ctx { 64062306a36Sopenharmony_ci __le32 ep_info; 64162306a36Sopenharmony_ci __le32 ep_info2; 64262306a36Sopenharmony_ci __le64 deq; 64362306a36Sopenharmony_ci __le32 tx_info; 64462306a36Sopenharmony_ci /* offset 0x14 - 0x1f reserved for controller internal use. */ 64562306a36Sopenharmony_ci __le32 reserved[3]; 64662306a36Sopenharmony_ci}; 64762306a36Sopenharmony_ci 64862306a36Sopenharmony_ci/* ep_info bitmasks. */ 64962306a36Sopenharmony_ci/* 65062306a36Sopenharmony_ci * Endpoint State - bits 0:2: 65162306a36Sopenharmony_ci * 0 - disabled 65262306a36Sopenharmony_ci * 1 - running 65362306a36Sopenharmony_ci * 2 - halted due to halt condition 65462306a36Sopenharmony_ci * 3 - stopped 65562306a36Sopenharmony_ci * 4 - TRB error 65662306a36Sopenharmony_ci * 5-7 - reserved 65762306a36Sopenharmony_ci */ 65862306a36Sopenharmony_ci#define EP_STATE_MASK GENMASK(3, 0) 65962306a36Sopenharmony_ci#define EP_STATE_DISABLED 0 66062306a36Sopenharmony_ci#define EP_STATE_RUNNING 1 66162306a36Sopenharmony_ci#define EP_STATE_HALTED 2 66262306a36Sopenharmony_ci#define EP_STATE_STOPPED 3 66362306a36Sopenharmony_ci#define EP_STATE_ERROR 4 66462306a36Sopenharmony_ci#define GET_EP_CTX_STATE(ctx) (le32_to_cpu((ctx)->ep_info) & EP_STATE_MASK) 66562306a36Sopenharmony_ci 66662306a36Sopenharmony_ci/* Mult - Max number of burst within an interval, in EP companion desc. */ 66762306a36Sopenharmony_ci#define EP_MULT(p) (((p) << 8) & GENMASK(9, 8)) 66862306a36Sopenharmony_ci#define CTX_TO_EP_MULT(p) (((p) & GENMASK(9, 8)) >> 8) 66962306a36Sopenharmony_ci/* bits 10:14 are Max Primary Streams. */ 67062306a36Sopenharmony_ci/* bit 15 is Linear Stream Array. */ 67162306a36Sopenharmony_ci/* Interval - period between requests to an endpoint - 125u increments. */ 67262306a36Sopenharmony_ci#define EP_INTERVAL(p) (((p) << 16) & GENMASK(23, 16)) 67362306a36Sopenharmony_ci#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) & GENMASK(23, 16)) >> 16)) 67462306a36Sopenharmony_ci#define CTX_TO_EP_INTERVAL(p) (((p) & GENMASK(23, 16)) >> 16) 67562306a36Sopenharmony_ci#define EP_MAXPSTREAMS_MASK GENMASK(14, 10) 67662306a36Sopenharmony_ci#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) 67762306a36Sopenharmony_ci#define CTX_TO_EP_MAXPSTREAMS(p) (((p) & EP_MAXPSTREAMS_MASK) >> 10) 67862306a36Sopenharmony_ci/* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ 67962306a36Sopenharmony_ci#define EP_HAS_LSA BIT(15) 68062306a36Sopenharmony_ci 68162306a36Sopenharmony_ci/* ep_info2 bitmasks */ 68262306a36Sopenharmony_ci#define ERROR_COUNT(p) (((p) & 0x3) << 1) 68362306a36Sopenharmony_ci#define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7) 68462306a36Sopenharmony_ci#define EP_TYPE(p) ((p) << 3) 68562306a36Sopenharmony_ci#define ISOC_OUT_EP 1 68662306a36Sopenharmony_ci#define BULK_OUT_EP 2 68762306a36Sopenharmony_ci#define INT_OUT_EP 3 68862306a36Sopenharmony_ci#define CTRL_EP 4 68962306a36Sopenharmony_ci#define ISOC_IN_EP 5 69062306a36Sopenharmony_ci#define BULK_IN_EP 6 69162306a36Sopenharmony_ci#define INT_IN_EP 7 69262306a36Sopenharmony_ci/* bit 6 reserved. */ 69362306a36Sopenharmony_ci/* bit 7 is Device Initiate Disable - for disabling stream selection. */ 69462306a36Sopenharmony_ci#define MAX_BURST(p) (((p) << 8) & GENMASK(15, 8)) 69562306a36Sopenharmony_ci#define CTX_TO_MAX_BURST(p) (((p) & GENMASK(15, 8)) >> 8) 69662306a36Sopenharmony_ci#define MAX_PACKET(p) (((p) << 16) & GENMASK(31, 16)) 69762306a36Sopenharmony_ci#define MAX_PACKET_MASK GENMASK(31, 16) 69862306a36Sopenharmony_ci#define MAX_PACKET_DECODED(p) (((p) & GENMASK(31, 16)) >> 16) 69962306a36Sopenharmony_ci 70062306a36Sopenharmony_ci/* tx_info bitmasks. */ 70162306a36Sopenharmony_ci#define EP_AVG_TRB_LENGTH(p) ((p) & GENMASK(15, 0)) 70262306a36Sopenharmony_ci#define EP_MAX_ESIT_PAYLOAD_LO(p) (((p) << 16) & GENMASK(31, 16)) 70362306a36Sopenharmony_ci#define EP_MAX_ESIT_PAYLOAD_HI(p) ((((p) & GENMASK(23, 16)) >> 16) << 24) 70462306a36Sopenharmony_ci#define CTX_TO_MAX_ESIT_PAYLOAD_LO(p) (((p) & GENMASK(31, 16)) >> 16) 70562306a36Sopenharmony_ci#define CTX_TO_MAX_ESIT_PAYLOAD_HI(p) (((p) & GENMASK(31, 24)) >> 24) 70662306a36Sopenharmony_ci 70762306a36Sopenharmony_ci/* deq bitmasks. */ 70862306a36Sopenharmony_ci#define EP_CTX_CYCLE_MASK BIT(0) 70962306a36Sopenharmony_ci#define CTX_DEQ_MASK (~0xfL) 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci/** 71262306a36Sopenharmony_ci * struct cdnsp_input_control_context 71362306a36Sopenharmony_ci * Input control context; 71462306a36Sopenharmony_ci * 71562306a36Sopenharmony_ci * @drop_context: Set the bit of the endpoint context you want to disable. 71662306a36Sopenharmony_ci * @add_context: Set the bit of the endpoint context you want to enable. 71762306a36Sopenharmony_ci */ 71862306a36Sopenharmony_cistruct cdnsp_input_control_ctx { 71962306a36Sopenharmony_ci __le32 drop_flags; 72062306a36Sopenharmony_ci __le32 add_flags; 72162306a36Sopenharmony_ci __le32 rsvd2[6]; 72262306a36Sopenharmony_ci}; 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_ci/** 72562306a36Sopenharmony_ci * Represents everything that is needed to issue a command on the command ring. 72662306a36Sopenharmony_ci * 72762306a36Sopenharmony_ci * @in_ctx: Pointer to input context structure. 72862306a36Sopenharmony_ci * @status: Command Completion Code for last command. 72962306a36Sopenharmony_ci * @command_trb: Pointer to command TRB. 73062306a36Sopenharmony_ci */ 73162306a36Sopenharmony_cistruct cdnsp_command { 73262306a36Sopenharmony_ci /* Input context for changing device state. */ 73362306a36Sopenharmony_ci struct cdnsp_container_ctx *in_ctx; 73462306a36Sopenharmony_ci u32 status; 73562306a36Sopenharmony_ci union cdnsp_trb *command_trb; 73662306a36Sopenharmony_ci}; 73762306a36Sopenharmony_ci 73862306a36Sopenharmony_ci/** 73962306a36Sopenharmony_ci * Stream context structure. 74062306a36Sopenharmony_ci * 74162306a36Sopenharmony_ci * @stream_ring: 64-bit stream ring address, cycle state, and stream type. 74262306a36Sopenharmony_ci * @reserved: offset 0x14 - 0x1f reserved for controller internal use. 74362306a36Sopenharmony_ci */ 74462306a36Sopenharmony_cistruct cdnsp_stream_ctx { 74562306a36Sopenharmony_ci __le64 stream_ring; 74662306a36Sopenharmony_ci __le32 reserved[2]; 74762306a36Sopenharmony_ci}; 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ci/* Stream Context Types - bits 3:1 of stream ctx deq ptr. */ 75062306a36Sopenharmony_ci#define SCT_FOR_CTX(p) (((p) << 1) & GENMASK(3, 1)) 75162306a36Sopenharmony_ci/* Secondary stream array type, dequeue pointer is to a transfer ring. */ 75262306a36Sopenharmony_ci#define SCT_SEC_TR 0 75362306a36Sopenharmony_ci/* Primary stream array type, dequeue pointer is to a transfer ring. */ 75462306a36Sopenharmony_ci#define SCT_PRI_TR 1 75562306a36Sopenharmony_ci 75662306a36Sopenharmony_ci/** 75762306a36Sopenharmony_ci * struct cdnsp_stream_info: Representing everything that is needed to 75862306a36Sopenharmony_ci * supports stream capable endpoints. 75962306a36Sopenharmony_ci * @stream_rings: Array of pointers containing Transfer rings for all 76062306a36Sopenharmony_ci * supported streams. 76162306a36Sopenharmony_ci * @num_streams: Number of streams, including stream 0. 76262306a36Sopenharmony_ci * @stream_ctx_array: The stream context array may be bigger than the number 76362306a36Sopenharmony_ci * of streams the driver asked for. 76462306a36Sopenharmony_ci * @num_stream_ctxs: Number of streams. 76562306a36Sopenharmony_ci * @ctx_array_dma: Dma address of Context Stream Array. 76662306a36Sopenharmony_ci * @trb_address_map: For mapping physical TRB addresses to segments in 76762306a36Sopenharmony_ci * stream rings. 76862306a36Sopenharmony_ci * @td_count: Number of TDs associated with endpoint. 76962306a36Sopenharmony_ci * @first_prime_det: First PRIME packet detected. 77062306a36Sopenharmony_ci * @drbls_count: Number of allowed doorbells. 77162306a36Sopenharmony_ci */ 77262306a36Sopenharmony_cistruct cdnsp_stream_info { 77362306a36Sopenharmony_ci struct cdnsp_ring **stream_rings; 77462306a36Sopenharmony_ci unsigned int num_streams; 77562306a36Sopenharmony_ci struct cdnsp_stream_ctx *stream_ctx_array; 77662306a36Sopenharmony_ci unsigned int num_stream_ctxs; 77762306a36Sopenharmony_ci dma_addr_t ctx_array_dma; 77862306a36Sopenharmony_ci struct radix_tree_root trb_address_map; 77962306a36Sopenharmony_ci int td_count; 78062306a36Sopenharmony_ci u8 first_prime_det; 78162306a36Sopenharmony_ci#define STREAM_DRBL_FIFO_DEPTH 2 78262306a36Sopenharmony_ci u8 drbls_count; 78362306a36Sopenharmony_ci}; 78462306a36Sopenharmony_ci 78562306a36Sopenharmony_ci#define STREAM_LOG_STREAMS 4 78662306a36Sopenharmony_ci#define STREAM_NUM_STREAMS BIT(STREAM_LOG_STREAMS) 78762306a36Sopenharmony_ci 78862306a36Sopenharmony_ci#if STREAM_LOG_STREAMS > 16 && STREAM_LOG_STREAMS < 1 78962306a36Sopenharmony_ci#error "Not suupported stream value" 79062306a36Sopenharmony_ci#endif 79162306a36Sopenharmony_ci 79262306a36Sopenharmony_ci/** 79362306a36Sopenharmony_ci * struct cdnsp_ep - extended device side representation of USB endpoint. 79462306a36Sopenharmony_ci * @endpoint: usb endpoint 79562306a36Sopenharmony_ci * @pending_req_list: List of requests queuing on transfer ring. 79662306a36Sopenharmony_ci * @pdev: Device associated with this endpoint. 79762306a36Sopenharmony_ci * @number: Endpoint number (1 - 15). 79862306a36Sopenharmony_ci * idx: The device context index (DCI). 79962306a36Sopenharmony_ci * interval: Interval between packets used for ISOC endpoint. 80062306a36Sopenharmony_ci * @name: A human readable name e.g. ep1out. 80162306a36Sopenharmony_ci * @direction: Endpoint direction. 80262306a36Sopenharmony_ci * @buffering: Number of on-chip buffers related to endpoint. 80362306a36Sopenharmony_ci * @buffering_period; Number of on-chip buffers related to periodic endpoint. 80462306a36Sopenharmony_ci * @in_ctx: Pointer to input endpoint context structure. 80562306a36Sopenharmony_ci * @out_ctx: Pointer to output endpoint context structure. 80662306a36Sopenharmony_ci * @ring: Pointer to transfer ring. 80762306a36Sopenharmony_ci * @stream_info: Hold stream information. 80862306a36Sopenharmony_ci * @ep_state: Current state of endpoint. 80962306a36Sopenharmony_ci * @skip: Sometimes the controller can not process isochronous endpoint ring 81062306a36Sopenharmony_ci * quickly enough, and it will miss some isoc tds on the ring and 81162306a36Sopenharmony_ci * generate Missed Service Error Event. 81262306a36Sopenharmony_ci * Set skip flag when receive a Missed Service Error Event and 81362306a36Sopenharmony_ci * process the missed tds on the endpoint ring. 81462306a36Sopenharmony_ci */ 81562306a36Sopenharmony_cistruct cdnsp_ep { 81662306a36Sopenharmony_ci struct usb_ep endpoint; 81762306a36Sopenharmony_ci struct list_head pending_list; 81862306a36Sopenharmony_ci struct cdnsp_device *pdev; 81962306a36Sopenharmony_ci u8 number; 82062306a36Sopenharmony_ci u8 idx; 82162306a36Sopenharmony_ci u32 interval; 82262306a36Sopenharmony_ci char name[20]; 82362306a36Sopenharmony_ci u8 direction; 82462306a36Sopenharmony_ci u8 buffering; 82562306a36Sopenharmony_ci u8 buffering_period; 82662306a36Sopenharmony_ci struct cdnsp_ep_ctx *in_ctx; 82762306a36Sopenharmony_ci struct cdnsp_ep_ctx *out_ctx; 82862306a36Sopenharmony_ci struct cdnsp_ring *ring; 82962306a36Sopenharmony_ci struct cdnsp_stream_info stream_info; 83062306a36Sopenharmony_ci unsigned int ep_state; 83162306a36Sopenharmony_ci#define EP_ENABLED BIT(0) 83262306a36Sopenharmony_ci#define EP_DIS_IN_RROGRESS BIT(1) 83362306a36Sopenharmony_ci#define EP_HALTED BIT(2) 83462306a36Sopenharmony_ci#define EP_STOPPED BIT(3) 83562306a36Sopenharmony_ci#define EP_WEDGE BIT(4) 83662306a36Sopenharmony_ci#define EP0_HALTED_STATUS BIT(5) 83762306a36Sopenharmony_ci#define EP_HAS_STREAMS BIT(6) 83862306a36Sopenharmony_ci#define EP_UNCONFIGURED BIT(7) 83962306a36Sopenharmony_ci 84062306a36Sopenharmony_ci bool skip; 84162306a36Sopenharmony_ci}; 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci/** 84462306a36Sopenharmony_ci * struct cdnsp_device_context_array 84562306a36Sopenharmony_ci * @dev_context_ptr: Array of 64-bit DMA addresses for device contexts. 84662306a36Sopenharmony_ci * @dma: DMA address for device contexts structure. 84762306a36Sopenharmony_ci */ 84862306a36Sopenharmony_cistruct cdnsp_device_context_array { 84962306a36Sopenharmony_ci __le64 dev_context_ptrs[CDNSP_DEV_MAX_SLOTS + 1]; 85062306a36Sopenharmony_ci dma_addr_t dma; 85162306a36Sopenharmony_ci}; 85262306a36Sopenharmony_ci 85362306a36Sopenharmony_ci/** 85462306a36Sopenharmony_ci * struct cdnsp_transfer_event. 85562306a36Sopenharmony_ci * @buffer: 64-bit buffer address, or immediate data. 85662306a36Sopenharmony_ci * @transfer_len: Data length transferred. 85762306a36Sopenharmony_ci * @flags: Field is interpreted differently based on the type of TRB. 85862306a36Sopenharmony_ci */ 85962306a36Sopenharmony_cistruct cdnsp_transfer_event { 86062306a36Sopenharmony_ci __le64 buffer; 86162306a36Sopenharmony_ci __le32 transfer_len; 86262306a36Sopenharmony_ci __le32 flags; 86362306a36Sopenharmony_ci}; 86462306a36Sopenharmony_ci 86562306a36Sopenharmony_ci/* Invalidate event after disabling endpoint. */ 86662306a36Sopenharmony_ci#define TRB_EVENT_INVALIDATE 8 86762306a36Sopenharmony_ci 86862306a36Sopenharmony_ci/* Transfer event TRB length bit mask. */ 86962306a36Sopenharmony_ci/* bits 0:23 */ 87062306a36Sopenharmony_ci#define EVENT_TRB_LEN(p) ((p) & GENMASK(23, 0)) 87162306a36Sopenharmony_ci/* Completion Code - only applicable for some types of TRBs */ 87262306a36Sopenharmony_ci#define COMP_CODE_MASK (0xff << 24) 87362306a36Sopenharmony_ci#define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24) 87462306a36Sopenharmony_ci#define COMP_INVALID 0 87562306a36Sopenharmony_ci#define COMP_SUCCESS 1 87662306a36Sopenharmony_ci#define COMP_DATA_BUFFER_ERROR 2 87762306a36Sopenharmony_ci#define COMP_BABBLE_DETECTED_ERROR 3 87862306a36Sopenharmony_ci#define COMP_TRB_ERROR 5 87962306a36Sopenharmony_ci#define COMP_RESOURCE_ERROR 7 88062306a36Sopenharmony_ci#define COMP_NO_SLOTS_AVAILABLE_ERROR 9 88162306a36Sopenharmony_ci#define COMP_INVALID_STREAM_TYPE_ERROR 10 88262306a36Sopenharmony_ci#define COMP_SLOT_NOT_ENABLED_ERROR 11 88362306a36Sopenharmony_ci#define COMP_ENDPOINT_NOT_ENABLED_ERROR 12 88462306a36Sopenharmony_ci#define COMP_SHORT_PACKET 13 88562306a36Sopenharmony_ci#define COMP_RING_UNDERRUN 14 88662306a36Sopenharmony_ci#define COMP_RING_OVERRUN 15 88762306a36Sopenharmony_ci#define COMP_VF_EVENT_RING_FULL_ERROR 16 88862306a36Sopenharmony_ci#define COMP_PARAMETER_ERROR 17 88962306a36Sopenharmony_ci#define COMP_CONTEXT_STATE_ERROR 19 89062306a36Sopenharmony_ci#define COMP_EVENT_RING_FULL_ERROR 21 89162306a36Sopenharmony_ci#define COMP_INCOMPATIBLE_DEVICE_ERROR 22 89262306a36Sopenharmony_ci#define COMP_MISSED_SERVICE_ERROR 23 89362306a36Sopenharmony_ci#define COMP_COMMAND_RING_STOPPED 24 89462306a36Sopenharmony_ci#define COMP_COMMAND_ABORTED 25 89562306a36Sopenharmony_ci#define COMP_STOPPED 26 89662306a36Sopenharmony_ci#define COMP_STOPPED_LENGTH_INVALID 27 89762306a36Sopenharmony_ci#define COMP_STOPPED_SHORT_PACKET 28 89862306a36Sopenharmony_ci#define COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR 29 89962306a36Sopenharmony_ci#define COMP_ISOCH_BUFFER_OVERRUN 31 90062306a36Sopenharmony_ci#define COMP_EVENT_LOST_ERROR 32 90162306a36Sopenharmony_ci#define COMP_UNDEFINED_ERROR 33 90262306a36Sopenharmony_ci#define COMP_INVALID_STREAM_ID_ERROR 34 90362306a36Sopenharmony_ci 90462306a36Sopenharmony_ci/*Transfer Event NRDY bit fields */ 90562306a36Sopenharmony_ci#define TRB_TO_DEV_STREAM(p) ((p) & GENMASK(16, 0)) 90662306a36Sopenharmony_ci#define TRB_TO_HOST_STREAM(p) ((p) & GENMASK(16, 0)) 90762306a36Sopenharmony_ci#define STREAM_PRIME_ACK 0xFFFE 90862306a36Sopenharmony_ci#define STREAM_REJECTED 0xFFFF 90962306a36Sopenharmony_ci 91062306a36Sopenharmony_ci/** Transfer Event bit fields **/ 91162306a36Sopenharmony_ci#define TRB_TO_EP_ID(p) (((p) & GENMASK(20, 16)) >> 16) 91262306a36Sopenharmony_ci 91362306a36Sopenharmony_ci/** 91462306a36Sopenharmony_ci * struct cdnsp_link_trb 91562306a36Sopenharmony_ci * @segment_ptr: 64-bit segment pointer. 91662306a36Sopenharmony_ci * @intr_target: Interrupter target. 91762306a36Sopenharmony_ci * @control: Flags. 91862306a36Sopenharmony_ci */ 91962306a36Sopenharmony_cistruct cdnsp_link_trb { 92062306a36Sopenharmony_ci __le64 segment_ptr; 92162306a36Sopenharmony_ci __le32 intr_target; 92262306a36Sopenharmony_ci __le32 control; 92362306a36Sopenharmony_ci}; 92462306a36Sopenharmony_ci 92562306a36Sopenharmony_ci/* control bitfields */ 92662306a36Sopenharmony_ci#define LINK_TOGGLE BIT(1) 92762306a36Sopenharmony_ci 92862306a36Sopenharmony_ci/** 92962306a36Sopenharmony_ci * struct cdnsp_event_cmd - Command completion event TRB. 93062306a36Sopenharmony_ci * cmd_trb: Pointer to command TRB, or the value passed by the event data trb 93162306a36Sopenharmony_ci * status: Command completion parameters and error code. 93262306a36Sopenharmony_ci * flags: Flags. 93362306a36Sopenharmony_ci */ 93462306a36Sopenharmony_cistruct cdnsp_event_cmd { 93562306a36Sopenharmony_ci __le64 cmd_trb; 93662306a36Sopenharmony_ci __le32 status; 93762306a36Sopenharmony_ci __le32 flags; 93862306a36Sopenharmony_ci}; 93962306a36Sopenharmony_ci 94062306a36Sopenharmony_ci/* flags bitmasks */ 94162306a36Sopenharmony_ci 94262306a36Sopenharmony_ci/* Address device - disable SetAddress. */ 94362306a36Sopenharmony_ci#define TRB_BSR BIT(9) 94462306a36Sopenharmony_ci 94562306a36Sopenharmony_ci/* Configure Endpoint - Deconfigure. */ 94662306a36Sopenharmony_ci#define TRB_DC BIT(9) 94762306a36Sopenharmony_ci 94862306a36Sopenharmony_ci/* Force Header */ 94962306a36Sopenharmony_ci#define TRB_FH_TO_PACKET_TYPE(p) ((p) & GENMASK(4, 0)) 95062306a36Sopenharmony_ci#define TRB_FH_TR_PACKET 0x4 95162306a36Sopenharmony_ci#define TRB_FH_TO_DEVICE_ADDRESS(p) (((p) << 25) & GENMASK(31, 25)) 95262306a36Sopenharmony_ci#define TRB_FH_TR_PACKET_DEV_NOT 0x6 95362306a36Sopenharmony_ci#define TRB_FH_TO_NOT_TYPE(p) (((p) << 4) & GENMASK(7, 4)) 95462306a36Sopenharmony_ci#define TRB_FH_TR_PACKET_FUNCTION_WAKE 0x1 95562306a36Sopenharmony_ci#define TRB_FH_TO_INTERFACE(p) (((p) << 8) & GENMASK(15, 8)) 95662306a36Sopenharmony_ci 95762306a36Sopenharmony_cienum cdnsp_setup_dev { 95862306a36Sopenharmony_ci SETUP_CONTEXT_ONLY, 95962306a36Sopenharmony_ci SETUP_CONTEXT_ADDRESS, 96062306a36Sopenharmony_ci}; 96162306a36Sopenharmony_ci 96262306a36Sopenharmony_ci/* bits 24:31 are the slot ID. */ 96362306a36Sopenharmony_ci#define TRB_TO_SLOT_ID(p) (((p) & GENMASK(31, 24)) >> 24) 96462306a36Sopenharmony_ci#define SLOT_ID_FOR_TRB(p) (((p) << 24) & GENMASK(31, 24)) 96562306a36Sopenharmony_ci 96662306a36Sopenharmony_ci/* Stop Endpoint TRB - ep_index to endpoint ID for this TRB. */ 96762306a36Sopenharmony_ci#define TRB_TO_EP_INDEX(p) (((p) >> 16) & 0x1f) 96862306a36Sopenharmony_ci 96962306a36Sopenharmony_ci#define EP_ID_FOR_TRB(p) ((((p) + 1) << 16) & GENMASK(20, 16)) 97062306a36Sopenharmony_ci 97162306a36Sopenharmony_ci#define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23) 97262306a36Sopenharmony_ci#define TRB_TO_SUSPEND_PORT(p) (((p) >> 23) & 0x1) 97362306a36Sopenharmony_ci#define LAST_EP_INDEX 30 97462306a36Sopenharmony_ci 97562306a36Sopenharmony_ci/* Set TR Dequeue Pointer command TRB fields. */ 97662306a36Sopenharmony_ci#define TRB_TO_STREAM_ID(p) ((((p) & GENMASK(31, 16)) >> 16)) 97762306a36Sopenharmony_ci#define STREAM_ID_FOR_TRB(p) ((((p)) << 16) & GENMASK(31, 16)) 97862306a36Sopenharmony_ci#define SCT_FOR_TRB(p) (((p) << 1) & 0x7) 97962306a36Sopenharmony_ci 98062306a36Sopenharmony_ci/* Link TRB specific fields. */ 98162306a36Sopenharmony_ci#define TRB_TC BIT(1) 98262306a36Sopenharmony_ci 98362306a36Sopenharmony_ci/* Port Status Change Event TRB fields. */ 98462306a36Sopenharmony_ci/* Port ID - bits 31:24. */ 98562306a36Sopenharmony_ci#define GET_PORT_ID(p) (((p) & GENMASK(31, 24)) >> 24) 98662306a36Sopenharmony_ci#define SET_PORT_ID(p) (((p) << 24) & GENMASK(31, 24)) 98762306a36Sopenharmony_ci#define EVENT_DATA BIT(2) 98862306a36Sopenharmony_ci 98962306a36Sopenharmony_ci/* Normal TRB fields. */ 99062306a36Sopenharmony_ci/* transfer_len bitmasks - bits 0:16. */ 99162306a36Sopenharmony_ci#define TRB_LEN(p) ((p) & GENMASK(16, 0)) 99262306a36Sopenharmony_ci/* TD Size, packets remaining in this TD, bits 21:17 (5 bits, so max 31). */ 99362306a36Sopenharmony_ci#define TRB_TD_SIZE(p) (min((p), (u32)31) << 17) 99462306a36Sopenharmony_ci#define GET_TD_SIZE(p) (((p) & GENMASK(21, 17)) >> 17) 99562306a36Sopenharmony_ci/* 99662306a36Sopenharmony_ci * Controller uses the TD_SIZE field for TBC if Extended TBC 99762306a36Sopenharmony_ci * is enabled (ETE). 99862306a36Sopenharmony_ci */ 99962306a36Sopenharmony_ci#define TRB_TD_SIZE_TBC(p) (min((p), (u32)31) << 17) 100062306a36Sopenharmony_ci/* Interrupter Target - which MSI-X vector to target the completion event at. */ 100162306a36Sopenharmony_ci#define TRB_INTR_TARGET(p) (((p) << 22) & GENMASK(31, 22)) 100262306a36Sopenharmony_ci#define GET_INTR_TARGET(p) (((p) & GENMASK(31, 22)) >> 22) 100362306a36Sopenharmony_ci/* 100462306a36Sopenharmony_ci * Total burst count field, Rsvdz on controller with Extended TBC 100562306a36Sopenharmony_ci * enabled (ETE). 100662306a36Sopenharmony_ci */ 100762306a36Sopenharmony_ci#define TRB_TBC(p) (((p) & 0x3) << 7) 100862306a36Sopenharmony_ci#define TRB_TLBPC(p) (((p) & 0xf) << 16) 100962306a36Sopenharmony_ci 101062306a36Sopenharmony_ci/* Cycle bit - indicates TRB ownership by driver or driver.*/ 101162306a36Sopenharmony_ci#define TRB_CYCLE BIT(0) 101262306a36Sopenharmony_ci/* 101362306a36Sopenharmony_ci * Force next event data TRB to be evaluated before task switch. 101462306a36Sopenharmony_ci * Used to pass OS data back after a TD completes. 101562306a36Sopenharmony_ci */ 101662306a36Sopenharmony_ci#define TRB_ENT BIT(1) 101762306a36Sopenharmony_ci/* Interrupt on short packet. */ 101862306a36Sopenharmony_ci#define TRB_ISP BIT(2) 101962306a36Sopenharmony_ci/* Set PCIe no snoop attribute. */ 102062306a36Sopenharmony_ci#define TRB_NO_SNOOP BIT(3) 102162306a36Sopenharmony_ci/* Chain multiple TRBs into a TD. */ 102262306a36Sopenharmony_ci#define TRB_CHAIN BIT(4) 102362306a36Sopenharmony_ci/* Interrupt on completion. */ 102462306a36Sopenharmony_ci#define TRB_IOC BIT(5) 102562306a36Sopenharmony_ci/* The buffer pointer contains immediate data. */ 102662306a36Sopenharmony_ci#define TRB_IDT BIT(6) 102762306a36Sopenharmony_ci/* 0 - NRDY during data stage, 1 - NRDY during status stage (only control). */ 102862306a36Sopenharmony_ci#define TRB_STAT BIT(7) 102962306a36Sopenharmony_ci/* Block Event Interrupt. */ 103062306a36Sopenharmony_ci#define TRB_BEI BIT(9) 103162306a36Sopenharmony_ci 103262306a36Sopenharmony_ci/* Control transfer TRB specific fields. */ 103362306a36Sopenharmony_ci#define TRB_DIR_IN BIT(16) 103462306a36Sopenharmony_ci 103562306a36Sopenharmony_ci/* TRB bit mask in Data Stage TRB */ 103662306a36Sopenharmony_ci#define TRB_SETUPID_BITMASK GENMASK(9, 8) 103762306a36Sopenharmony_ci#define TRB_SETUPID(p) ((p) << 8) 103862306a36Sopenharmony_ci#define TRB_SETUPID_TO_TYPE(p) (((p) & TRB_SETUPID_BITMASK) >> 8) 103962306a36Sopenharmony_ci 104062306a36Sopenharmony_ci#define TRB_SETUP_SPEEDID_USB3 0x1 104162306a36Sopenharmony_ci#define TRB_SETUP_SPEEDID_USB2 0x0 104262306a36Sopenharmony_ci#define TRB_SETUP_SPEEDID(p) ((p) & (1 << 7)) 104362306a36Sopenharmony_ci 104462306a36Sopenharmony_ci#define TRB_SETUPSTAT_ACK 0x1 104562306a36Sopenharmony_ci#define TRB_SETUPSTAT_STALL 0x0 104662306a36Sopenharmony_ci#define TRB_SETUPSTAT(p) ((p) << 6) 104762306a36Sopenharmony_ci 104862306a36Sopenharmony_ci/* Isochronous TRB specific fields */ 104962306a36Sopenharmony_ci#define TRB_SIA BIT(31) 105062306a36Sopenharmony_ci#define TRB_FRAME_ID(p) (((p) << 20) & GENMASK(30, 20)) 105162306a36Sopenharmony_ci 105262306a36Sopenharmony_cistruct cdnsp_generic_trb { 105362306a36Sopenharmony_ci __le32 field[4]; 105462306a36Sopenharmony_ci}; 105562306a36Sopenharmony_ci 105662306a36Sopenharmony_ciunion cdnsp_trb { 105762306a36Sopenharmony_ci struct cdnsp_link_trb link; 105862306a36Sopenharmony_ci struct cdnsp_transfer_event trans_event; 105962306a36Sopenharmony_ci struct cdnsp_event_cmd event_cmd; 106062306a36Sopenharmony_ci struct cdnsp_generic_trb generic; 106162306a36Sopenharmony_ci}; 106262306a36Sopenharmony_ci 106362306a36Sopenharmony_ci/* TRB bit mask. */ 106462306a36Sopenharmony_ci#define TRB_TYPE_BITMASK GENMASK(15, 10) 106562306a36Sopenharmony_ci#define TRB_TYPE(p) ((p) << 10) 106662306a36Sopenharmony_ci#define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10) 106762306a36Sopenharmony_ci 106862306a36Sopenharmony_ci/* TRB type IDs. */ 106962306a36Sopenharmony_ci/* bulk, interrupt, isoc scatter/gather, and control data stage. */ 107062306a36Sopenharmony_ci#define TRB_NORMAL 1 107162306a36Sopenharmony_ci/* Setup Stage for control transfers. */ 107262306a36Sopenharmony_ci#define TRB_SETUP 2 107362306a36Sopenharmony_ci/* Data Stage for control transfers. */ 107462306a36Sopenharmony_ci#define TRB_DATA 3 107562306a36Sopenharmony_ci/* Status Stage for control transfers. */ 107662306a36Sopenharmony_ci#define TRB_STATUS 4 107762306a36Sopenharmony_ci/* ISOC transfers. */ 107862306a36Sopenharmony_ci#define TRB_ISOC 5 107962306a36Sopenharmony_ci/* TRB for linking ring segments. */ 108062306a36Sopenharmony_ci#define TRB_LINK 6 108162306a36Sopenharmony_ci#define TRB_EVENT_DATA 7 108262306a36Sopenharmony_ci/* Transfer Ring No-op (not for the command ring). */ 108362306a36Sopenharmony_ci#define TRB_TR_NOOP 8 108462306a36Sopenharmony_ci 108562306a36Sopenharmony_ci/* Command TRBs */ 108662306a36Sopenharmony_ci/* Enable Slot Command. */ 108762306a36Sopenharmony_ci#define TRB_ENABLE_SLOT 9 108862306a36Sopenharmony_ci/* Disable Slot Command. */ 108962306a36Sopenharmony_ci#define TRB_DISABLE_SLOT 10 109062306a36Sopenharmony_ci/* Address Device Command. */ 109162306a36Sopenharmony_ci#define TRB_ADDR_DEV 11 109262306a36Sopenharmony_ci/* Configure Endpoint Command. */ 109362306a36Sopenharmony_ci#define TRB_CONFIG_EP 12 109462306a36Sopenharmony_ci/* Evaluate Context Command. */ 109562306a36Sopenharmony_ci#define TRB_EVAL_CONTEXT 13 109662306a36Sopenharmony_ci/* Reset Endpoint Command. */ 109762306a36Sopenharmony_ci#define TRB_RESET_EP 14 109862306a36Sopenharmony_ci/* Stop Transfer Ring Command. */ 109962306a36Sopenharmony_ci#define TRB_STOP_RING 15 110062306a36Sopenharmony_ci/* Set Transfer Ring Dequeue Pointer Command. */ 110162306a36Sopenharmony_ci#define TRB_SET_DEQ 16 110262306a36Sopenharmony_ci/* Reset Device Command. */ 110362306a36Sopenharmony_ci#define TRB_RESET_DEV 17 110462306a36Sopenharmony_ci/* Force Event Command (opt). */ 110562306a36Sopenharmony_ci#define TRB_FORCE_EVENT 18 110662306a36Sopenharmony_ci/* Force Header Command - generate a transaction or link management packet. */ 110762306a36Sopenharmony_ci#define TRB_FORCE_HEADER 22 110862306a36Sopenharmony_ci/* No-op Command - not for transfer rings. */ 110962306a36Sopenharmony_ci#define TRB_CMD_NOOP 23 111062306a36Sopenharmony_ci/* TRB IDs 24-31 reserved. */ 111162306a36Sopenharmony_ci 111262306a36Sopenharmony_ci/* Event TRBS. */ 111362306a36Sopenharmony_ci/* Transfer Event. */ 111462306a36Sopenharmony_ci#define TRB_TRANSFER 32 111562306a36Sopenharmony_ci/* Command Completion Event. */ 111662306a36Sopenharmony_ci#define TRB_COMPLETION 33 111762306a36Sopenharmony_ci/* Port Status Change Event. */ 111862306a36Sopenharmony_ci#define TRB_PORT_STATUS 34 111962306a36Sopenharmony_ci/* Device Controller Event. */ 112062306a36Sopenharmony_ci#define TRB_HC_EVENT 37 112162306a36Sopenharmony_ci/* MFINDEX Wrap Event - microframe counter wrapped. */ 112262306a36Sopenharmony_ci#define TRB_MFINDEX_WRAP 39 112362306a36Sopenharmony_ci/* TRB IDs 40-47 reserved. */ 112462306a36Sopenharmony_ci/* Endpoint Not Ready Event. */ 112562306a36Sopenharmony_ci#define TRB_ENDPOINT_NRDY 48 112662306a36Sopenharmony_ci/* TRB IDs 49-53 reserved. */ 112762306a36Sopenharmony_ci/* Halt Endpoint Command. */ 112862306a36Sopenharmony_ci#define TRB_HALT_ENDPOINT 54 112962306a36Sopenharmony_ci/* Doorbell Overflow Event. */ 113062306a36Sopenharmony_ci#define TRB_DRB_OVERFLOW 57 113162306a36Sopenharmony_ci/* Flush Endpoint Command. */ 113262306a36Sopenharmony_ci#define TRB_FLUSH_ENDPOINT 58 113362306a36Sopenharmony_ci 113462306a36Sopenharmony_ci#define TRB_TYPE_LINK(x) (((x) & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK)) 113562306a36Sopenharmony_ci#define TRB_TYPE_LINK_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \ 113662306a36Sopenharmony_ci cpu_to_le32(TRB_TYPE(TRB_LINK))) 113762306a36Sopenharmony_ci#define TRB_TYPE_NOOP_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \ 113862306a36Sopenharmony_ci cpu_to_le32(TRB_TYPE(TRB_TR_NOOP))) 113962306a36Sopenharmony_ci 114062306a36Sopenharmony_ci/* 114162306a36Sopenharmony_ci * TRBS_PER_SEGMENT must be a multiple of 4. 114262306a36Sopenharmony_ci * The command ring is 64-byte aligned, so it must also be greater than 16. 114362306a36Sopenharmony_ci */ 114462306a36Sopenharmony_ci#define TRBS_PER_SEGMENT 256 114562306a36Sopenharmony_ci#define TRBS_PER_EVENT_SEGMENT 256 114662306a36Sopenharmony_ci#define TRBS_PER_EV_DEQ_UPDATE 100 114762306a36Sopenharmony_ci#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT * 16) 114862306a36Sopenharmony_ci#define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE)) 114962306a36Sopenharmony_ci/* TRB buffer pointers can't cross 64KB boundaries. */ 115062306a36Sopenharmony_ci#define TRB_MAX_BUFF_SHIFT 16 115162306a36Sopenharmony_ci#define TRB_MAX_BUFF_SIZE BIT(TRB_MAX_BUFF_SHIFT) 115262306a36Sopenharmony_ci/* How much data is left before the 64KB boundary? */ 115362306a36Sopenharmony_ci#define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \ 115462306a36Sopenharmony_ci ((addr) & (TRB_MAX_BUFF_SIZE - 1))) 115562306a36Sopenharmony_ci 115662306a36Sopenharmony_ci/** 115762306a36Sopenharmony_ci * struct cdnsp_segment - segment related data. 115862306a36Sopenharmony_ci * @trbs: Array of Transfer Request Blocks. 115962306a36Sopenharmony_ci * @next: Pointer to the next segment. 116062306a36Sopenharmony_ci * @dma: DMA address of current segment. 116162306a36Sopenharmony_ci * @bounce_dma: Bounce buffer DMA address . 116262306a36Sopenharmony_ci * @bounce_buf: Bounce buffer virtual address. 116362306a36Sopenharmony_ci * bounce_offs: Bounce buffer offset. 116462306a36Sopenharmony_ci * bounce_len: Bounce buffer length. 116562306a36Sopenharmony_ci */ 116662306a36Sopenharmony_cistruct cdnsp_segment { 116762306a36Sopenharmony_ci union cdnsp_trb *trbs; 116862306a36Sopenharmony_ci struct cdnsp_segment *next; 116962306a36Sopenharmony_ci dma_addr_t dma; 117062306a36Sopenharmony_ci /* Max packet sized bounce buffer for td-fragmant alignment */ 117162306a36Sopenharmony_ci dma_addr_t bounce_dma; 117262306a36Sopenharmony_ci void *bounce_buf; 117362306a36Sopenharmony_ci unsigned int bounce_offs; 117462306a36Sopenharmony_ci unsigned int bounce_len; 117562306a36Sopenharmony_ci}; 117662306a36Sopenharmony_ci 117762306a36Sopenharmony_ci/** 117862306a36Sopenharmony_ci * struct cdnsp_td - Transfer Descriptor object. 117962306a36Sopenharmony_ci * @td_list: Used for binding TD with ep_ring->td_list. 118062306a36Sopenharmony_ci * @preq: Request associated with this TD 118162306a36Sopenharmony_ci * @start_seg: Segment containing the first_trb in TD. 118262306a36Sopenharmony_ci * @first_trb: First TRB for this TD. 118362306a36Sopenharmony_ci * @last_trb: Last TRB related with TD. 118462306a36Sopenharmony_ci * @bounce_seg: Bounce segment for this TD. 118562306a36Sopenharmony_ci * @request_length_set: actual_length of the request has already been set. 118662306a36Sopenharmony_ci * @drbl - TD has been added to HW scheduler - only for stream capable 118762306a36Sopenharmony_ci * endpoints. 118862306a36Sopenharmony_ci */ 118962306a36Sopenharmony_cistruct cdnsp_td { 119062306a36Sopenharmony_ci struct list_head td_list; 119162306a36Sopenharmony_ci struct cdnsp_request *preq; 119262306a36Sopenharmony_ci struct cdnsp_segment *start_seg; 119362306a36Sopenharmony_ci union cdnsp_trb *first_trb; 119462306a36Sopenharmony_ci union cdnsp_trb *last_trb; 119562306a36Sopenharmony_ci struct cdnsp_segment *bounce_seg; 119662306a36Sopenharmony_ci bool request_length_set; 119762306a36Sopenharmony_ci bool drbl; 119862306a36Sopenharmony_ci}; 119962306a36Sopenharmony_ci 120062306a36Sopenharmony_ci/** 120162306a36Sopenharmony_ci * struct cdnsp_dequeue_state - New dequeue pointer for Transfer Ring. 120262306a36Sopenharmony_ci * @new_deq_seg: New dequeue segment. 120362306a36Sopenharmony_ci * @new_deq_ptr: New dequeue pointer. 120462306a36Sopenharmony_ci * @new_cycle_state: New cycle state. 120562306a36Sopenharmony_ci * @stream_id: stream id for which new dequeue pointer has been selected. 120662306a36Sopenharmony_ci */ 120762306a36Sopenharmony_cistruct cdnsp_dequeue_state { 120862306a36Sopenharmony_ci struct cdnsp_segment *new_deq_seg; 120962306a36Sopenharmony_ci union cdnsp_trb *new_deq_ptr; 121062306a36Sopenharmony_ci int new_cycle_state; 121162306a36Sopenharmony_ci unsigned int stream_id; 121262306a36Sopenharmony_ci}; 121362306a36Sopenharmony_ci 121462306a36Sopenharmony_cienum cdnsp_ring_type { 121562306a36Sopenharmony_ci TYPE_CTRL = 0, 121662306a36Sopenharmony_ci TYPE_ISOC, 121762306a36Sopenharmony_ci TYPE_BULK, 121862306a36Sopenharmony_ci TYPE_INTR, 121962306a36Sopenharmony_ci TYPE_STREAM, 122062306a36Sopenharmony_ci TYPE_COMMAND, 122162306a36Sopenharmony_ci TYPE_EVENT, 122262306a36Sopenharmony_ci}; 122362306a36Sopenharmony_ci 122462306a36Sopenharmony_ci/** 122562306a36Sopenharmony_ci * struct cdnsp_ring - information describing transfer, command or event ring. 122662306a36Sopenharmony_ci * @first_seg: First segment on transfer ring. 122762306a36Sopenharmony_ci * @last_seg: Last segment on transfer ring. 122862306a36Sopenharmony_ci * @enqueue: SW enqueue pointer address. 122962306a36Sopenharmony_ci * @enq_seg: SW enqueue segment address. 123062306a36Sopenharmony_ci * @dequeue: SW dequeue pointer address. 123162306a36Sopenharmony_ci * @deq_seg: SW dequeue segment address. 123262306a36Sopenharmony_ci * @td_list: transfer descriptor list associated with this ring. 123362306a36Sopenharmony_ci * @cycle_state: Current cycle bit. Write the cycle state into the TRB cycle 123462306a36Sopenharmony_ci * field to give ownership of the TRB to the device controller 123562306a36Sopenharmony_ci * (if we are the producer) or to check if we own the TRB 123662306a36Sopenharmony_ci * (if we are the consumer). 123762306a36Sopenharmony_ci * @stream_id: Stream id 123862306a36Sopenharmony_ci * @stream_active: Stream is active - PRIME packet has been detected. 123962306a36Sopenharmony_ci * @stream_rejected: This ring has been rejected by host. 124062306a36Sopenharmony_ci * @num_tds: Number of TDs associated with ring. 124162306a36Sopenharmony_ci * @num_segs: Number of segments. 124262306a36Sopenharmony_ci * @num_trbs_free: Number of free TRBs on the ring. 124362306a36Sopenharmony_ci * @bounce_buf_len: Length of bounce buffer. 124462306a36Sopenharmony_ci * @type: Ring type - event, transfer, or command ring. 124562306a36Sopenharmony_ci * @last_td_was_short - TD is short TD. 124662306a36Sopenharmony_ci * @trb_address_map: For mapping physical TRB addresses to segments in 124762306a36Sopenharmony_ci * stream rings. 124862306a36Sopenharmony_ci */ 124962306a36Sopenharmony_cistruct cdnsp_ring { 125062306a36Sopenharmony_ci struct cdnsp_segment *first_seg; 125162306a36Sopenharmony_ci struct cdnsp_segment *last_seg; 125262306a36Sopenharmony_ci union cdnsp_trb *enqueue; 125362306a36Sopenharmony_ci struct cdnsp_segment *enq_seg; 125462306a36Sopenharmony_ci union cdnsp_trb *dequeue; 125562306a36Sopenharmony_ci struct cdnsp_segment *deq_seg; 125662306a36Sopenharmony_ci struct list_head td_list; 125762306a36Sopenharmony_ci u32 cycle_state; 125862306a36Sopenharmony_ci unsigned int stream_id; 125962306a36Sopenharmony_ci unsigned int stream_active; 126062306a36Sopenharmony_ci unsigned int stream_rejected; 126162306a36Sopenharmony_ci int num_tds; 126262306a36Sopenharmony_ci unsigned int num_segs; 126362306a36Sopenharmony_ci unsigned int num_trbs_free; 126462306a36Sopenharmony_ci unsigned int bounce_buf_len; 126562306a36Sopenharmony_ci enum cdnsp_ring_type type; 126662306a36Sopenharmony_ci bool last_td_was_short; 126762306a36Sopenharmony_ci struct radix_tree_root *trb_address_map; 126862306a36Sopenharmony_ci}; 126962306a36Sopenharmony_ci 127062306a36Sopenharmony_ci/** 127162306a36Sopenharmony_ci * struct cdnsp_erst_entry - even ring segment table entry object. 127262306a36Sopenharmony_ci * @seg_addr: 64-bit event ring segment address. 127362306a36Sopenharmony_ci * seg_size: Number of TRBs in segment.; 127462306a36Sopenharmony_ci */ 127562306a36Sopenharmony_cistruct cdnsp_erst_entry { 127662306a36Sopenharmony_ci __le64 seg_addr; 127762306a36Sopenharmony_ci __le32 seg_size; 127862306a36Sopenharmony_ci /* Set to zero */ 127962306a36Sopenharmony_ci __le32 rsvd; 128062306a36Sopenharmony_ci}; 128162306a36Sopenharmony_ci 128262306a36Sopenharmony_ci/** 128362306a36Sopenharmony_ci * struct cdnsp_erst - even ring segment table for event ring. 128462306a36Sopenharmony_ci * @entries: Array of event ring segments 128562306a36Sopenharmony_ci * @num_entries: Number of segments in entries array. 128662306a36Sopenharmony_ci * @erst_dma_addr: DMA address for entries array. 128762306a36Sopenharmony_ci */ 128862306a36Sopenharmony_cistruct cdnsp_erst { 128962306a36Sopenharmony_ci struct cdnsp_erst_entry *entries; 129062306a36Sopenharmony_ci unsigned int num_entries; 129162306a36Sopenharmony_ci dma_addr_t erst_dma_addr; 129262306a36Sopenharmony_ci}; 129362306a36Sopenharmony_ci 129462306a36Sopenharmony_ci/** 129562306a36Sopenharmony_ci * struct cdnsp_request - extended device side representation of usb_request 129662306a36Sopenharmony_ci * object . 129762306a36Sopenharmony_ci * @td: Transfer descriptor associated with this request. 129862306a36Sopenharmony_ci * @request: Generic usb_request object describing single I/O request. 129962306a36Sopenharmony_ci * @list: Used to adding request to endpoint pending_list. 130062306a36Sopenharmony_ci * @pep: Extended representation of usb_ep object 130162306a36Sopenharmony_ci * @epnum: Endpoint number associated with usb request. 130262306a36Sopenharmony_ci * @direction: Endpoint direction for usb request. 130362306a36Sopenharmony_ci */ 130462306a36Sopenharmony_cistruct cdnsp_request { 130562306a36Sopenharmony_ci struct cdnsp_td td; 130662306a36Sopenharmony_ci struct usb_request request; 130762306a36Sopenharmony_ci struct list_head list; 130862306a36Sopenharmony_ci struct cdnsp_ep *pep; 130962306a36Sopenharmony_ci u8 epnum; 131062306a36Sopenharmony_ci unsigned direction:1; 131162306a36Sopenharmony_ci}; 131262306a36Sopenharmony_ci 131362306a36Sopenharmony_ci#define ERST_NUM_SEGS 1 131462306a36Sopenharmony_ci 131562306a36Sopenharmony_ci/* Stages used during enumeration process.*/ 131662306a36Sopenharmony_cienum cdnsp_ep0_stage { 131762306a36Sopenharmony_ci CDNSP_SETUP_STAGE, 131862306a36Sopenharmony_ci CDNSP_DATA_STAGE, 131962306a36Sopenharmony_ci CDNSP_STATUS_STAGE, 132062306a36Sopenharmony_ci}; 132162306a36Sopenharmony_ci 132262306a36Sopenharmony_ci/** 132362306a36Sopenharmony_ci * struct cdnsp_port - holds information about detected ports. 132462306a36Sopenharmony_ci * @port_num: Port number. 132562306a36Sopenharmony_ci * @exist: Indicate if port exist. 132662306a36Sopenharmony_ci * maj_rev: Major revision. 132762306a36Sopenharmony_ci * min_rev: Minor revision. 132862306a36Sopenharmony_ci */ 132962306a36Sopenharmony_cistruct cdnsp_port { 133062306a36Sopenharmony_ci struct cdnsp_port_regs __iomem *regs; 133162306a36Sopenharmony_ci u8 port_num; 133262306a36Sopenharmony_ci u8 exist; 133362306a36Sopenharmony_ci u8 maj_rev; 133462306a36Sopenharmony_ci u8 min_rev; 133562306a36Sopenharmony_ci}; 133662306a36Sopenharmony_ci 133762306a36Sopenharmony_ci#define CDNSP_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff) 133862306a36Sopenharmony_ci#define CDNSP_EXT_PORT_MINOR(x) (((x) >> 16) & 0xff) 133962306a36Sopenharmony_ci#define CDNSP_EXT_PORT_OFF(x) ((x) & 0xff) 134062306a36Sopenharmony_ci#define CDNSP_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff) 134162306a36Sopenharmony_ci 134262306a36Sopenharmony_ci/** 134362306a36Sopenharmony_ci * struct cdnsp_device - represent USB device. 134462306a36Sopenharmony_ci * @dev: Pointer to device structure associated whit this controller. 134562306a36Sopenharmony_ci * @gadget: Device side representation of the peripheral controller. 134662306a36Sopenharmony_ci * @gadget_driver: Pointer to the gadget driver. 134762306a36Sopenharmony_ci * @irq: IRQ line number used by device side. 134862306a36Sopenharmony_ci * @regs:IO device memory. 134962306a36Sopenharmony_ci * @cap_regs: Capability registers. 135062306a36Sopenharmony_ci * @op_regs: Operational registers. 135162306a36Sopenharmony_ci * @run_regs: Runtime registers. 135262306a36Sopenharmony_ci * @dba: Device base address register. 135362306a36Sopenharmony_ci * @ir_set: Current interrupter register set. 135462306a36Sopenharmony_ci * @port20_regs: Port 2.0 Peripheral Configuration Registers. 135562306a36Sopenharmony_ci * @port3x_regs: USB3.x Port Peripheral Configuration Registers. 135662306a36Sopenharmony_ci * @rev_cap: Controller Capabilities Registers. 135762306a36Sopenharmony_ci * @hcs_params1: Cached register copies of read-only HCSPARAMS1 135862306a36Sopenharmony_ci * @hcc_params: Cached register copies of read-only HCCPARAMS1 135962306a36Sopenharmony_ci * @setup: Temporary buffer for setup packet. 136062306a36Sopenharmony_ci * @ep0_preq: Internal allocated request used during enumeration. 136162306a36Sopenharmony_ci * @ep0_stage: ep0 stage during enumeration process. 136262306a36Sopenharmony_ci * @three_stage_setup: Three state or two state setup. 136362306a36Sopenharmony_ci * @ep0_expect_in: Data IN expected for control transfer. 136462306a36Sopenharmony_ci * @setup_id: Setup identifier. 136562306a36Sopenharmony_ci * @setup_speed - Speed detected for current SETUP packet. 136662306a36Sopenharmony_ci * @setup_buf: Buffer for SETUP packet. 136762306a36Sopenharmony_ci * @device_address: Current device address. 136862306a36Sopenharmony_ci * @may_wakeup: remote wakeup enabled/disabled. 136962306a36Sopenharmony_ci * @lock: Lock used in interrupt thread context. 137062306a36Sopenharmony_ci * @hci_version: device controller version. 137162306a36Sopenharmony_ci * @dcbaa: Device context base address array. 137262306a36Sopenharmony_ci * @cmd_ring: Command ring. 137362306a36Sopenharmony_ci * @cmd: Represent all what is needed to issue command on Command Ring. 137462306a36Sopenharmony_ci * @event_ring: Event ring. 137562306a36Sopenharmony_ci * @erst: Event Ring Segment table 137662306a36Sopenharmony_ci * @slot_id: Current Slot ID. Should be 0 or 1. 137762306a36Sopenharmony_ci * @out_ctx: Output context. 137862306a36Sopenharmony_ci * @in_ctx: Input context. 137962306a36Sopenharmony_ci * @eps: array of endpoints object associated with device. 138062306a36Sopenharmony_ci * @usb2_hw_lpm_capable: hardware lpm is enabled; 138162306a36Sopenharmony_ci * @u1_allowed: Allow device transition to U1 state. 138262306a36Sopenharmony_ci * @u2_allowed: Allow device transition to U2 state 138362306a36Sopenharmony_ci * @device_pool: DMA pool for allocating input and output context. 138462306a36Sopenharmony_ci * @segment_pool: DMA pool for allocating new segments. 138562306a36Sopenharmony_ci * @cdnsp_state: Current state of controller. 138662306a36Sopenharmony_ci * @link_state: Current link state. 138762306a36Sopenharmony_ci * @usb2_port - Port USB 2.0. 138862306a36Sopenharmony_ci * @usb3_port - Port USB 3.0. 138962306a36Sopenharmony_ci * @active_port - Current selected Port. 139062306a36Sopenharmony_ci * @test_mode: selected Test Mode. 139162306a36Sopenharmony_ci */ 139262306a36Sopenharmony_cistruct cdnsp_device { 139362306a36Sopenharmony_ci struct device *dev; 139462306a36Sopenharmony_ci struct usb_gadget gadget; 139562306a36Sopenharmony_ci struct usb_gadget_driver *gadget_driver; 139662306a36Sopenharmony_ci unsigned int irq; 139762306a36Sopenharmony_ci void __iomem *regs; 139862306a36Sopenharmony_ci 139962306a36Sopenharmony_ci /* Registers map */ 140062306a36Sopenharmony_ci struct cdnsp_cap_regs __iomem *cap_regs; 140162306a36Sopenharmony_ci struct cdnsp_op_regs __iomem *op_regs; 140262306a36Sopenharmony_ci struct cdnsp_run_regs __iomem *run_regs; 140362306a36Sopenharmony_ci struct cdnsp_doorbell_array __iomem *dba; 140462306a36Sopenharmony_ci struct cdnsp_intr_reg __iomem *ir_set; 140562306a36Sopenharmony_ci struct cdnsp_20port_cap __iomem *port20_regs; 140662306a36Sopenharmony_ci struct cdnsp_3xport_cap __iomem *port3x_regs; 140762306a36Sopenharmony_ci struct cdnsp_rev_cap __iomem *rev_cap; 140862306a36Sopenharmony_ci 140962306a36Sopenharmony_ci /* Cached register copies of read-only CDNSP data */ 141062306a36Sopenharmony_ci __u32 hcs_params1; 141162306a36Sopenharmony_ci __u32 hcs_params3; 141262306a36Sopenharmony_ci __u32 hcc_params; 141362306a36Sopenharmony_ci /* Lock used in interrupt thread context. */ 141462306a36Sopenharmony_ci spinlock_t lock; 141562306a36Sopenharmony_ci struct usb_ctrlrequest setup; 141662306a36Sopenharmony_ci struct cdnsp_request ep0_preq; 141762306a36Sopenharmony_ci enum cdnsp_ep0_stage ep0_stage; 141862306a36Sopenharmony_ci u8 three_stage_setup; 141962306a36Sopenharmony_ci u8 ep0_expect_in; 142062306a36Sopenharmony_ci u8 setup_id; 142162306a36Sopenharmony_ci u8 setup_speed; 142262306a36Sopenharmony_ci void *setup_buf; 142362306a36Sopenharmony_ci u8 device_address; 142462306a36Sopenharmony_ci int may_wakeup; 142562306a36Sopenharmony_ci u16 hci_version; 142662306a36Sopenharmony_ci 142762306a36Sopenharmony_ci /* data structures */ 142862306a36Sopenharmony_ci struct cdnsp_device_context_array *dcbaa; 142962306a36Sopenharmony_ci struct cdnsp_ring *cmd_ring; 143062306a36Sopenharmony_ci struct cdnsp_command cmd; 143162306a36Sopenharmony_ci struct cdnsp_ring *event_ring; 143262306a36Sopenharmony_ci struct cdnsp_erst erst; 143362306a36Sopenharmony_ci int slot_id; 143462306a36Sopenharmony_ci 143562306a36Sopenharmony_ci /* 143662306a36Sopenharmony_ci * Commands to the hardware are passed an "input context" that 143762306a36Sopenharmony_ci * tells the hardware what to change in its data structures. 143862306a36Sopenharmony_ci * The hardware will return changes in an "output context" that 143962306a36Sopenharmony_ci * software must allocate for the hardware. . 144062306a36Sopenharmony_ci */ 144162306a36Sopenharmony_ci struct cdnsp_container_ctx out_ctx; 144262306a36Sopenharmony_ci struct cdnsp_container_ctx in_ctx; 144362306a36Sopenharmony_ci struct cdnsp_ep eps[CDNSP_ENDPOINTS_NUM]; 144462306a36Sopenharmony_ci u8 usb2_hw_lpm_capable:1; 144562306a36Sopenharmony_ci u8 u1_allowed:1; 144662306a36Sopenharmony_ci u8 u2_allowed:1; 144762306a36Sopenharmony_ci 144862306a36Sopenharmony_ci /* DMA pools */ 144962306a36Sopenharmony_ci struct dma_pool *device_pool; 145062306a36Sopenharmony_ci struct dma_pool *segment_pool; 145162306a36Sopenharmony_ci 145262306a36Sopenharmony_ci#define CDNSP_STATE_HALTED BIT(1) 145362306a36Sopenharmony_ci#define CDNSP_STATE_DYING BIT(2) 145462306a36Sopenharmony_ci#define CDNSP_STATE_DISCONNECT_PENDING BIT(3) 145562306a36Sopenharmony_ci#define CDNSP_WAKEUP_PENDING BIT(4) 145662306a36Sopenharmony_ci unsigned int cdnsp_state; 145762306a36Sopenharmony_ci unsigned int link_state; 145862306a36Sopenharmony_ci 145962306a36Sopenharmony_ci struct cdnsp_port usb2_port; 146062306a36Sopenharmony_ci struct cdnsp_port usb3_port; 146162306a36Sopenharmony_ci struct cdnsp_port *active_port; 146262306a36Sopenharmony_ci u16 test_mode; 146362306a36Sopenharmony_ci}; 146462306a36Sopenharmony_ci 146562306a36Sopenharmony_ci/* 146662306a36Sopenharmony_ci * Registers should always be accessed with double word or quad word accesses. 146762306a36Sopenharmony_ci * 146862306a36Sopenharmony_ci * Registers with 64-bit address pointers should be written to with 146962306a36Sopenharmony_ci * dword accesses by writing the low dword first (ptr[0]), then the high dword 147062306a36Sopenharmony_ci * (ptr[1]) second. controller implementations that do not support 64-bit 147162306a36Sopenharmony_ci * address pointers will ignore the high dword, and write order is irrelevant. 147262306a36Sopenharmony_ci */ 147362306a36Sopenharmony_cistatic inline u64 cdnsp_read_64(__le64 __iomem *regs) 147462306a36Sopenharmony_ci{ 147562306a36Sopenharmony_ci return lo_hi_readq(regs); 147662306a36Sopenharmony_ci} 147762306a36Sopenharmony_ci 147862306a36Sopenharmony_cistatic inline void cdnsp_write_64(const u64 val, __le64 __iomem *regs) 147962306a36Sopenharmony_ci{ 148062306a36Sopenharmony_ci lo_hi_writeq(val, regs); 148162306a36Sopenharmony_ci} 148262306a36Sopenharmony_ci 148362306a36Sopenharmony_ci/* CDNSP memory management functions. */ 148462306a36Sopenharmony_civoid cdnsp_mem_cleanup(struct cdnsp_device *pdev); 148562306a36Sopenharmony_ciint cdnsp_mem_init(struct cdnsp_device *pdev); 148662306a36Sopenharmony_ciint cdnsp_setup_addressable_priv_dev(struct cdnsp_device *pdev); 148762306a36Sopenharmony_civoid cdnsp_copy_ep0_dequeue_into_input_ctx(struct cdnsp_device *pdev); 148862306a36Sopenharmony_civoid cdnsp_endpoint_zero(struct cdnsp_device *pdev, struct cdnsp_ep *ep); 148962306a36Sopenharmony_ciint cdnsp_endpoint_init(struct cdnsp_device *pdev, 149062306a36Sopenharmony_ci struct cdnsp_ep *pep, 149162306a36Sopenharmony_ci gfp_t mem_flags); 149262306a36Sopenharmony_ciint cdnsp_ring_expansion(struct cdnsp_device *pdev, 149362306a36Sopenharmony_ci struct cdnsp_ring *ring, 149462306a36Sopenharmony_ci unsigned int num_trbs, gfp_t flags); 149562306a36Sopenharmony_cistruct cdnsp_ring *cdnsp_dma_to_transfer_ring(struct cdnsp_ep *ep, u64 address); 149662306a36Sopenharmony_ciint cdnsp_alloc_stream_info(struct cdnsp_device *pdev, 149762306a36Sopenharmony_ci struct cdnsp_ep *pep, 149862306a36Sopenharmony_ci unsigned int num_stream_ctxs, 149962306a36Sopenharmony_ci unsigned int num_streams); 150062306a36Sopenharmony_ciint cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep); 150162306a36Sopenharmony_civoid cdnsp_free_endpoint_rings(struct cdnsp_device *pdev, struct cdnsp_ep *pep); 150262306a36Sopenharmony_ci 150362306a36Sopenharmony_ci/* Device controller glue. */ 150462306a36Sopenharmony_ciint cdnsp_find_next_ext_cap(void __iomem *base, u32 start, int id); 150562306a36Sopenharmony_ciint cdnsp_halt(struct cdnsp_device *pdev); 150662306a36Sopenharmony_civoid cdnsp_died(struct cdnsp_device *pdev); 150762306a36Sopenharmony_ciint cdnsp_reset(struct cdnsp_device *pdev); 150862306a36Sopenharmony_ciirqreturn_t cdnsp_irq_handler(int irq, void *priv); 150962306a36Sopenharmony_ciint cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup); 151062306a36Sopenharmony_civoid cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *usbsssp_data, 151162306a36Sopenharmony_ci struct usb_request *req, int enable); 151262306a36Sopenharmony_ciirqreturn_t cdnsp_thread_irq_handler(int irq, void *data); 151362306a36Sopenharmony_ci 151462306a36Sopenharmony_ci/* Ring, segment, TRB, and TD functions. */ 151562306a36Sopenharmony_cidma_addr_t cdnsp_trb_virt_to_dma(struct cdnsp_segment *seg, 151662306a36Sopenharmony_ci union cdnsp_trb *trb); 151762306a36Sopenharmony_cibool cdnsp_last_trb_on_seg(struct cdnsp_segment *seg, union cdnsp_trb *trb); 151862306a36Sopenharmony_cibool cdnsp_last_trb_on_ring(struct cdnsp_ring *ring, 151962306a36Sopenharmony_ci struct cdnsp_segment *seg, 152062306a36Sopenharmony_ci union cdnsp_trb *trb); 152162306a36Sopenharmony_ciint cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev); 152262306a36Sopenharmony_civoid cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, 152362306a36Sopenharmony_ci union cdnsp_trb *event_ring_deq, 152462306a36Sopenharmony_ci u8 clear_ehb); 152562306a36Sopenharmony_civoid cdnsp_initialize_ring_info(struct cdnsp_ring *ring); 152662306a36Sopenharmony_civoid cdnsp_ring_cmd_db(struct cdnsp_device *pdev); 152762306a36Sopenharmony_civoid cdnsp_queue_slot_control(struct cdnsp_device *pdev, u32 trb_type); 152862306a36Sopenharmony_civoid cdnsp_queue_address_device(struct cdnsp_device *pdev, 152962306a36Sopenharmony_ci dma_addr_t in_ctx_ptr, 153062306a36Sopenharmony_ci enum cdnsp_setup_dev setup); 153162306a36Sopenharmony_civoid cdnsp_queue_stop_endpoint(struct cdnsp_device *pdev, 153262306a36Sopenharmony_ci unsigned int ep_index); 153362306a36Sopenharmony_ciint cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq); 153462306a36Sopenharmony_ciint cdnsp_queue_bulk_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq); 153562306a36Sopenharmony_ciint cdnsp_queue_isoc_tx(struct cdnsp_device *pdev, 153662306a36Sopenharmony_ci struct cdnsp_request *preq); 153762306a36Sopenharmony_civoid cdnsp_queue_configure_endpoint(struct cdnsp_device *pdev, 153862306a36Sopenharmony_ci dma_addr_t in_ctx_ptr); 153962306a36Sopenharmony_civoid cdnsp_queue_reset_ep(struct cdnsp_device *pdev, unsigned int ep_index); 154062306a36Sopenharmony_civoid cdnsp_queue_halt_endpoint(struct cdnsp_device *pdev, 154162306a36Sopenharmony_ci unsigned int ep_index); 154262306a36Sopenharmony_civoid cdnsp_queue_flush_endpoint(struct cdnsp_device *pdev, 154362306a36Sopenharmony_ci unsigned int ep_index); 154462306a36Sopenharmony_civoid cdnsp_force_header_wakeup(struct cdnsp_device *pdev, int intf_num); 154562306a36Sopenharmony_civoid cdnsp_queue_reset_device(struct cdnsp_device *pdev); 154662306a36Sopenharmony_civoid cdnsp_queue_new_dequeue_state(struct cdnsp_device *pdev, 154762306a36Sopenharmony_ci struct cdnsp_ep *pep, 154862306a36Sopenharmony_ci struct cdnsp_dequeue_state *deq_state); 154962306a36Sopenharmony_civoid cdnsp_ring_doorbell_for_active_rings(struct cdnsp_device *pdev, 155062306a36Sopenharmony_ci struct cdnsp_ep *pep); 155162306a36Sopenharmony_civoid cdnsp_inc_deq(struct cdnsp_device *pdev, struct cdnsp_ring *ring); 155262306a36Sopenharmony_civoid cdnsp_set_link_state(struct cdnsp_device *pdev, 155362306a36Sopenharmony_ci __le32 __iomem *port_regs, u32 link_state); 155462306a36Sopenharmony_ciu32 cdnsp_port_state_to_neutral(u32 state); 155562306a36Sopenharmony_ci 155662306a36Sopenharmony_ci/* CDNSP device controller contexts. */ 155762306a36Sopenharmony_ciint cdnsp_enable_slot(struct cdnsp_device *pdev); 155862306a36Sopenharmony_ciint cdnsp_disable_slot(struct cdnsp_device *pdev); 155962306a36Sopenharmony_cistruct cdnsp_input_control_ctx 156062306a36Sopenharmony_ci *cdnsp_get_input_control_ctx(struct cdnsp_container_ctx *ctx); 156162306a36Sopenharmony_cistruct cdnsp_slot_ctx *cdnsp_get_slot_ctx(struct cdnsp_container_ctx *ctx); 156262306a36Sopenharmony_cistruct cdnsp_ep_ctx *cdnsp_get_ep_ctx(struct cdnsp_container_ctx *ctx, 156362306a36Sopenharmony_ci unsigned int ep_index); 156462306a36Sopenharmony_ci/* CDNSP gadget interface. */ 156562306a36Sopenharmony_civoid cdnsp_suspend_gadget(struct cdnsp_device *pdev); 156662306a36Sopenharmony_civoid cdnsp_resume_gadget(struct cdnsp_device *pdev); 156762306a36Sopenharmony_civoid cdnsp_disconnect_gadget(struct cdnsp_device *pdev); 156862306a36Sopenharmony_civoid cdnsp_gadget_giveback(struct cdnsp_ep *pep, struct cdnsp_request *preq, 156962306a36Sopenharmony_ci int status); 157062306a36Sopenharmony_ciint cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq); 157162306a36Sopenharmony_ciint cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq); 157262306a36Sopenharmony_ciunsigned int cdnsp_port_speed(unsigned int port_status); 157362306a36Sopenharmony_civoid cdnsp_irq_reset(struct cdnsp_device *pdev); 157462306a36Sopenharmony_ciint cdnsp_halt_endpoint(struct cdnsp_device *pdev, 157562306a36Sopenharmony_ci struct cdnsp_ep *pep, int value); 157662306a36Sopenharmony_ciint cdnsp_cmd_stop_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep); 157762306a36Sopenharmony_ciint cdnsp_cmd_flush_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep); 157862306a36Sopenharmony_civoid cdnsp_setup_analyze(struct cdnsp_device *pdev); 157962306a36Sopenharmony_ciint cdnsp_status_stage(struct cdnsp_device *pdev); 158062306a36Sopenharmony_ciint cdnsp_reset_device(struct cdnsp_device *pdev); 158162306a36Sopenharmony_ci 158262306a36Sopenharmony_ci/** 158362306a36Sopenharmony_ci * next_request - gets the next request on the given list 158462306a36Sopenharmony_ci * @list: the request list to operate on 158562306a36Sopenharmony_ci * 158662306a36Sopenharmony_ci * Caller should take care of locking. This function return NULL or the first 158762306a36Sopenharmony_ci * request available on list. 158862306a36Sopenharmony_ci */ 158962306a36Sopenharmony_cistatic inline struct cdnsp_request *next_request(struct list_head *list) 159062306a36Sopenharmony_ci{ 159162306a36Sopenharmony_ci return list_first_entry_or_null(list, struct cdnsp_request, list); 159262306a36Sopenharmony_ci} 159362306a36Sopenharmony_ci 159462306a36Sopenharmony_ci#define to_cdnsp_ep(ep) (container_of(ep, struct cdnsp_ep, endpoint)) 159562306a36Sopenharmony_ci#define gadget_to_cdnsp(g) (container_of(g, struct cdnsp_device, gadget)) 159662306a36Sopenharmony_ci#define request_to_cdnsp_request(r) (container_of(r, struct cdnsp_request, \ 159762306a36Sopenharmony_ci request)) 159862306a36Sopenharmony_ci#define to_cdnsp_request(r) (container_of(r, struct cdnsp_request, request)) 159962306a36Sopenharmony_ciint cdnsp_remove_request(struct cdnsp_device *pdev, struct cdnsp_request *preq, 160062306a36Sopenharmony_ci struct cdnsp_ep *pep); 160162306a36Sopenharmony_ci 160262306a36Sopenharmony_ci#endif /* __LINUX_CDNSP_GADGET_H */ 1603