1// SPDX-License-Identifier: GPL-2.0 2/* 3 * xhci-dbc.h - xHCI debug capability early driver 4 * 5 * Copyright (C) 2016 Intel Corporation 6 * 7 * Author: Lu Baolu <baolu.lu@linux.intel.com> 8 */ 9 10#ifndef __LINUX_XHCI_DBC_H 11#define __LINUX_XHCI_DBC_H 12 13#include <linux/types.h> 14#include <linux/usb/ch9.h> 15 16/* 17 * xHCI Debug Capability Register interfaces: 18 */ 19struct xdbc_regs { 20 __le32 capability; 21 __le32 doorbell; 22 __le32 ersts; /* Event Ring Segment Table Size*/ 23 __le32 __reserved_0; /* 0c~0f reserved bits */ 24 __le64 erstba; /* Event Ring Segment Table Base Address */ 25 __le64 erdp; /* Event Ring Dequeue Pointer */ 26 __le32 control; 27 __le32 status; 28 __le32 portsc; /* Port status and control */ 29 __le32 __reserved_1; /* 2b~28 reserved bits */ 30 __le64 dccp; /* Debug Capability Context Pointer */ 31 __le32 devinfo1; /* Device Descriptor Info Register 1 */ 32 __le32 devinfo2; /* Device Descriptor Info Register 2 */ 33}; 34 35#define DEBUG_MAX_BURST(p) (((p) >> 16) & 0xff) 36 37#define CTRL_DBC_RUN BIT(0) 38#define CTRL_PORT_ENABLE BIT(1) 39#define CTRL_HALT_OUT_TR BIT(2) 40#define CTRL_HALT_IN_TR BIT(3) 41#define CTRL_DBC_RUN_CHANGE BIT(4) 42#define CTRL_DBC_ENABLE BIT(31) 43 44#define DCST_DEBUG_PORT(p) (((p) >> 24) & 0xff) 45 46#define PORTSC_CONN_STATUS BIT(0) 47#define PORTSC_CONN_CHANGE BIT(17) 48#define PORTSC_RESET_CHANGE BIT(21) 49#define PORTSC_LINK_CHANGE BIT(22) 50#define PORTSC_CONFIG_CHANGE BIT(23) 51 52/* 53 * xHCI Debug Capability data structures: 54 */ 55struct xdbc_trb { 56 __le32 field[4]; 57}; 58 59struct xdbc_erst_entry { 60 __le64 seg_addr; 61 __le32 seg_size; 62 __le32 __reserved_0; 63}; 64 65struct xdbc_info_context { 66 __le64 string0; 67 __le64 manufacturer; 68 __le64 product; 69 __le64 serial; 70 __le32 length; 71 __le32 __reserved_0[7]; 72}; 73 74struct xdbc_ep_context { 75 __le32 ep_info1; 76 __le32 ep_info2; 77 __le64 deq; 78 __le32 tx_info; 79 __le32 __reserved_0[11]; 80}; 81 82struct xdbc_context { 83 struct xdbc_info_context info; 84 struct xdbc_ep_context out; 85 struct xdbc_ep_context in; 86}; 87 88#define XDBC_INFO_CONTEXT_SIZE 48 89#define XDBC_MAX_STRING_LENGTH 64 90#define XDBC_STRING_MANUFACTURER "Linux Foundation" 91#define XDBC_STRING_PRODUCT "Linux USB GDB Target" 92#define XDBC_STRING_SERIAL "0001" 93 94struct xdbc_strings { 95 char string0[XDBC_MAX_STRING_LENGTH]; 96 char manufacturer[XDBC_MAX_STRING_LENGTH]; 97 char product[XDBC_MAX_STRING_LENGTH]; 98 char serial[XDBC_MAX_STRING_LENGTH]; 99}; 100 101#define XDBC_PROTOCOL 1 /* GNU Remote Debug Command Set */ 102#define XDBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */ 103#define XDBC_PRODUCT_ID 0x0011 /* __le16 idProduct; device 0011 */ 104#define XDBC_DEVICE_REV 0x0010 /* 0.10 */ 105 106/* 107 * xHCI Debug Capability software state structures: 108 */ 109struct xdbc_segment { 110 struct xdbc_trb *trbs; 111 dma_addr_t dma; 112}; 113 114#define XDBC_TRBS_PER_SEGMENT 256 115 116struct xdbc_ring { 117 struct xdbc_segment *segment; 118 struct xdbc_trb *enqueue; 119 struct xdbc_trb *dequeue; 120 u32 cycle_state; 121}; 122 123#define XDBC_EPID_OUT 2 124#define XDBC_EPID_IN 3 125 126struct xdbc_state { 127 u16 vendor; 128 u16 device; 129 u32 bus; 130 u32 dev; 131 u32 func; 132 void __iomem *xhci_base; 133 u64 xhci_start; 134 size_t xhci_length; 135 int port_number; 136 137 /* DbC register base */ 138 struct xdbc_regs __iomem *xdbc_reg; 139 140 /* DbC table page */ 141 dma_addr_t table_dma; 142 void *table_base; 143 144 /* event ring segment table */ 145 dma_addr_t erst_dma; 146 size_t erst_size; 147 void *erst_base; 148 149 /* event ring segments */ 150 struct xdbc_ring evt_ring; 151 struct xdbc_segment evt_seg; 152 153 /* debug capability contexts */ 154 dma_addr_t dbcc_dma; 155 size_t dbcc_size; 156 void *dbcc_base; 157 158 /* descriptor strings */ 159 dma_addr_t string_dma; 160 size_t string_size; 161 void *string_base; 162 163 /* bulk OUT endpoint */ 164 struct xdbc_ring out_ring; 165 struct xdbc_segment out_seg; 166 void *out_buf; 167 dma_addr_t out_dma; 168 169 /* bulk IN endpoint */ 170 struct xdbc_ring in_ring; 171 struct xdbc_segment in_seg; 172 void *in_buf; 173 dma_addr_t in_dma; 174 175 u32 flags; 176 177 /* spinlock for early_xdbc_write() reentrancy */ 178 raw_spinlock_t lock; 179}; 180 181#define XDBC_PCI_MAX_BUSES 256 182#define XDBC_PCI_MAX_DEVICES 32 183#define XDBC_PCI_MAX_FUNCTION 8 184 185#define XDBC_TABLE_ENTRY_SIZE 64 186#define XDBC_ERST_ENTRY_NUM 1 187#define XDBC_DBCC_ENTRY_NUM 3 188#define XDBC_STRING_ENTRY_NUM 4 189 190/* Bits definitions for xdbc_state.flags: */ 191#define XDBC_FLAGS_INITIALIZED BIT(0) 192#define XDBC_FLAGS_IN_STALL BIT(1) 193#define XDBC_FLAGS_OUT_STALL BIT(2) 194#define XDBC_FLAGS_IN_PROCESS BIT(3) 195#define XDBC_FLAGS_OUT_PROCESS BIT(4) 196#define XDBC_FLAGS_CONFIGURED BIT(5) 197 198#define XDBC_MAX_PACKET 1024 199 200/* Door bell target: */ 201#define OUT_EP_DOORBELL 0 202#define IN_EP_DOORBELL 1 203#define DOOR_BELL_TARGET(p) (((p) & 0xff) << 8) 204 205#define xdbc_read64(regs) xhci_read_64(NULL, (regs)) 206#define xdbc_write64(val, regs) xhci_write_64(NULL, (val), (regs)) 207 208#endif /* __LINUX_XHCI_DBC_H */ 209