forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/drivers/usb/host/xhci.h
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+/* SPDX-License-Identifier: GPL-2.0 */
22
33 /*
44 * xHCI host controller driver
....@@ -17,10 +17,14 @@
1717 #include <linux/kernel.h>
1818 #include <linux/usb/hcd.h>
1919 #include <linux/io-64-nonatomic-lo-hi.h>
20
+#include <linux/android_kabi.h>
2021
2122 /* Code sharing between pci-quirks and xhci hcd */
2223 #include "xhci-ext-caps.h"
2324 #include "pci-quirks.h"
25
+
26
+/* max buffer size for trace and debug messages */
27
+#define XHCI_MSG_MAX 500
2428
2529 /* xHCI PCI Configuration Registers */
2630 #define XHCI_SBRN_OFFSET (0x60)
....@@ -225,6 +229,9 @@
225229 /* bit 14 Extended TBC Enable, changes Isoc TRB fields to support larger TBC */
226230 #define CMD_ETE (1 << 14)
227231 /* bits 15:31 are reserved (and should be preserved on writes). */
232
+
233
+#define XHCI_RESET_LONG_USEC (10 * 1000 * 1000)
234
+#define XHCI_RESET_SHORT_USEC (250 * 1000)
228235
229236 /* IMAN - Interrupt Management Register */
230237 #define IMAN_IE (1 << 1)
....@@ -809,6 +816,9 @@
809816 struct completion *completion;
810817 union xhci_trb *command_trb;
811818 struct list_head cmd_list;
819
+
820
+ ANDROID_KABI_RESERVE(1);
821
+ ANDROID_KABI_RESERVE(2);
812822 };
813823
814824 /* drop context bitmasks */
....@@ -918,6 +928,8 @@
918928 #define SS_BW_RESERVED 10
919929
920930 struct xhci_virt_ep {
931
+ struct xhci_virt_device *vdev; /* parent */
932
+ unsigned int ep_index;
921933 struct xhci_ring *ring;
922934 /* Related to endpoints that are configured to use stream IDs only */
923935 struct xhci_stream_info *stream_info;
....@@ -936,6 +948,8 @@
936948 #define EP_GETTING_NO_STREAMS (1 << 5)
937949 #define EP_HARD_CLEAR_TOGGLE (1 << 6)
938950 #define EP_SOFT_CLEAR_TOGGLE (1 << 7)
951
+/* usb_hub_clear_tt_buffer is in progress */
952
+#define EP_CLEARING_TT (1 << 8)
939953 /* ---- Related to URB cancellation ---- */
940954 struct list_head cancelled_td_list;
941955 /* Watchdog timer for stop endpoint command to cancel URBs */
....@@ -994,6 +1008,7 @@
9941008 #define EP_CTX_PER_DEV 31
9951009
9961010 struct xhci_virt_device {
1011
+ int slot_id;
9971012 struct usb_device *udev;
9981013 /*
9991014 * Commands to the hardware are passed an "input context" that
....@@ -1313,6 +1328,8 @@
13131328 #define TRB_IOC (1<<5)
13141329 /* The buffer pointer contains immediate data */
13151330 #define TRB_IDT (1<<6)
1331
+/* TDs smaller than this might use IDT */
1332
+#define TRB_IDT_MAX_SIZE 8
13161333
13171334 /* Block Event Interrupt */
13181335 #define TRB_BEI (1<<9)
....@@ -1408,7 +1425,7 @@
14081425 /* MFINDEX Wrap Event - microframe counter wrapped */
14091426 #define TRB_MFINDEX_WRAP 39
14101427 /* TRB IDs 40-47 reserved, 48-63 is vendor-defined */
1411
-
1428
+#define TRB_VENDOR_DEFINED_LOW 48
14121429 /* Nec vendor-specific command completion event. */
14131430 #define TRB_NEC_CMD_COMP 48
14141431 /* Get NEC firmware revision. */
....@@ -1509,15 +1526,12 @@
15091526 #define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
15101527 #define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE))
15111528 /* TRB buffer pointers can't cross 64KB boundaries */
1512
-#ifdef CONFIG_ARCH_ROCKCHIP
1513
-#define TRB_MAX_BUFF_SHIFT 12
1514
-#else
15151529 #define TRB_MAX_BUFF_SHIFT 16
1516
-#endif
15171530 #define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
15181531 /* How much data is left before the 64KB boundary? */
15191532 #define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \
15201533 (addr & (TRB_MAX_BUFF_SIZE - 1)))
1534
+#define MAX_SOFT_RETRY 3
15211535
15221536 struct xhci_segment {
15231537 union xhci_trb *trbs;
....@@ -1529,18 +1543,31 @@
15291543 void *bounce_buf;
15301544 unsigned int bounce_offs;
15311545 unsigned int bounce_len;
1546
+
1547
+ ANDROID_KABI_RESERVE(1);
1548
+};
1549
+
1550
+enum xhci_cancelled_td_status {
1551
+ TD_DIRTY = 0,
1552
+ TD_HALTED,
1553
+ TD_CLEARING_CACHE,
1554
+ TD_CLEARED,
15321555 };
15331556
15341557 struct xhci_td {
15351558 struct list_head td_list;
15361559 struct list_head cancelled_td_list;
1560
+ int status;
1561
+ enum xhci_cancelled_td_status cancel_status;
15371562 struct urb *urb;
15381563 struct xhci_segment *start_seg;
15391564 union xhci_trb *first_trb;
15401565 union xhci_trb *last_trb;
1566
+ struct xhci_segment *last_trb_seg;
15411567 struct xhci_segment *bounce_seg;
15421568 /* actual_length of the URB has already been set */
15431569 bool urb_length_set;
1570
+ unsigned int num_trbs;
15441571 };
15451572
15461573 /* xHCI command default timeout value */
....@@ -1550,13 +1577,6 @@
15501577 struct xhci_cd {
15511578 struct xhci_command *command;
15521579 union xhci_trb *cmd_trb;
1553
-};
1554
-
1555
-struct xhci_dequeue_state {
1556
- struct xhci_segment *new_deq_seg;
1557
- union xhci_trb *new_deq_ptr;
1558
- int new_cycle_state;
1559
- unsigned int stream_id;
15601580 };
15611581
15621582 enum xhci_ring_type {
....@@ -1605,6 +1625,7 @@
16051625 * if we own the TRB (if we are the consumer). See section 4.9.1.
16061626 */
16071627 u32 cycle_state;
1628
+ unsigned int err_count;
16081629 unsigned int stream_id;
16091630 unsigned int num_segs;
16101631 unsigned int num_trbs_free;
....@@ -1613,6 +1634,9 @@
16131634 enum xhci_ring_type type;
16141635 bool last_td_was_short;
16151636 struct radix_tree_root *trb_address_map;
1637
+
1638
+ ANDROID_KABI_RESERVE(1);
1639
+ ANDROID_KABI_RESERVE(2);
16161640 };
16171641
16181642 struct xhci_erst_entry {
....@@ -1630,6 +1654,8 @@
16301654 dma_addr_t erst_dma_addr;
16311655 /* Num entries the ERST can contain */
16321656 unsigned int erst_size;
1657
+
1658
+ ANDROID_KABI_RESERVE(1);
16331659 };
16341660
16351661 struct xhci_scratchpad {
....@@ -1641,7 +1667,7 @@
16411667 struct urb_priv {
16421668 int num_tds;
16431669 int num_tds_done;
1644
- struct xhci_td td[0];
1670
+ struct xhci_td td[];
16451671 };
16461672
16471673 /*
....@@ -1693,6 +1719,7 @@
16931719 /* Which ports are waiting on RExit to U0 transition. */
16941720 unsigned long rexit_ports;
16951721 struct completion rexit_done[USB_MAXCHILDREN];
1722
+ struct completion u3exit_done[USB_MAXCHILDREN];
16961723 };
16971724
16981725
....@@ -1701,15 +1728,6 @@
17011728 * Intel Lynx Point LP xHCI host.
17021729 */
17031730 #define XHCI_MAX_REXIT_TIMEOUT_MS 20
1704
-
1705
-static inline unsigned int hcd_index(struct usb_hcd *hcd)
1706
-{
1707
- if (hcd->speed >= HCD_USB3)
1708
- return 0;
1709
- else
1710
- return 1;
1711
-}
1712
-
17131731 struct xhci_port_cap {
17141732 u32 *psi; /* array of protocol speed ID entries */
17151733 u8 psi_count;
....@@ -1730,6 +1748,8 @@
17301748 struct xhci_port **ports;
17311749 unsigned int num_ports;
17321750 struct usb_hcd *hcd;
1751
+ /* keep track of bus suspend info */
1752
+ struct xhci_bus_state bus_state;
17331753 /* supported prococol extended capabiliy values */
17341754 u8 maj_rev;
17351755 u8 min_rev;
....@@ -1746,10 +1766,6 @@
17461766 struct xhci_doorbell_array __iomem *dba;
17471767 /* Our HCD's current interrupter register set */
17481768 struct xhci_intr_reg __iomem *ir_set;
1749
- /* secondary interrupter */
1750
- struct xhci_intr_reg __iomem **sec_ir_set;
1751
-
1752
- int core_id;
17531769
17541770 /* Cached register copies of read-only HC data */
17551771 __u32 hcs_params1;
....@@ -1779,6 +1795,8 @@
17791795 /* optional clocks */
17801796 struct clk *clk;
17811797 struct clk *reg_clk;
1798
+ /* optional reset controller */
1799
+ struct reset_control *reset;
17821800 /* data structures */
17831801 struct xhci_device_context_array *dcbaa;
17841802 struct xhci_ring *cmd_ring;
....@@ -1793,11 +1811,6 @@
17931811 struct xhci_command *current_cmd;
17941812 struct xhci_ring *event_ring;
17951813 struct xhci_erst erst;
1796
-
1797
- /* secondary event ring and erst */
1798
- struct xhci_ring **sec_event_ring;
1799
- struct xhci_erst *sec_erst;
1800
-
18011814 /* Scratchpad */
18021815 struct xhci_scratchpad *scratchpad;
18031816 /* Store LPM test failed devices' information */
....@@ -1884,24 +1897,24 @@
18841897 #define XHCI_SUSPEND_DELAY BIT_ULL(30)
18851898 #define XHCI_INTEL_USB_ROLE_SW BIT_ULL(31)
18861899 #define XHCI_ZERO_64B_REGS BIT_ULL(32)
1900
+#define XHCI_DEFAULT_PM_RUNTIME_ALLOW BIT_ULL(33)
18871901 #define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(34)
18881902 #define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35)
1889
-#define XHCI_TRB_ENT_QUIRK BIT_ULL(36)
1890
-#define XHCI_DIS_AUTOSUSPEND BIT_ULL(37)
1903
+#define XHCI_RENESAS_FW_QUIRK BIT_ULL(36)
1904
+#define XHCI_SKIP_PHY_INIT BIT_ULL(37)
18911905 #define XHCI_DISABLE_SPARSE BIT_ULL(38)
1892
-#define XHCI_WARM_RESET_ON_SUSPEND BIT_ULL(39)
1893
-#define XHCI_U2_BROKEN_SUSPEND BIT_ULL(40)
1894
-#define XHCI_SKIP_PHY_INIT BIT_ULL(41)
1906
+#define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39)
1907
+#define XHCI_NO_SOFT_RETRY BIT_ULL(40)
1908
+#define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42)
1909
+#define XHCI_SUSPEND_RESUME_CLKS BIT_ULL(43)
1910
+#define XHCI_RESET_TO_DEFAULT BIT_ULL(44)
1911
+#define XHCI_U2_BROKEN_SUSPEND BIT_ULL(45)
18951912
18961913 unsigned int num_active_eps;
18971914 unsigned int limit_active_eps;
1898
- /* There are two roothubs to keep track of bus suspend info for */
1899
- struct xhci_bus_state bus_state[2];
19001915 struct xhci_port *hw_ports;
19011916 struct xhci_hub usb2_rhub;
19021917 struct xhci_hub usb3_rhub;
1903
- /* support xHCI 0.96 spec USB2 software LPM */
1904
- unsigned sw_lpm_support:1;
19051918 /* support xHCI 1.0 spec USB2 hardware LPM */
19061919 unsigned hw_lpm_support:1;
19071920 /* Broken Suspend flag for SNPS Suspend resume issue */
....@@ -1924,8 +1937,16 @@
19241937 struct list_head regset_list;
19251938
19261939 void *dbc;
1940
+
1941
+ /* Used for bug 194461020 */
1942
+ ANDROID_KABI_USE(1, struct xhci_vendor_ops *vendor_ops);
1943
+
1944
+ ANDROID_KABI_RESERVE(2);
1945
+ ANDROID_KABI_RESERVE(3);
1946
+ ANDROID_KABI_RESERVE(4);
1947
+
19271948 /* platform-specific data -- must come last */
1928
- unsigned long priv[0] __aligned(sizeof(s64));
1949
+ unsigned long priv[] __aligned(sizeof(s64));
19291950 };
19301951
19311952 /* Platform specific overrides to generic XHCI hc_driver ops */
....@@ -1933,6 +1954,15 @@
19331954 size_t extra_priv_size;
19341955 int (*reset)(struct usb_hcd *hcd);
19351956 int (*start)(struct usb_hcd *hcd);
1957
+ int (*add_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1958
+ struct usb_host_endpoint *ep);
1959
+ int (*drop_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1960
+ struct usb_host_endpoint *ep);
1961
+ int (*check_bandwidth)(struct usb_hcd *, struct usb_device *);
1962
+ void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
1963
+ int (*address_device)(struct usb_hcd *hcd, struct usb_device *udev);
1964
+ int (*bus_suspend)(struct usb_hcd *hcd);
1965
+ int (*bus_resume)(struct usb_hcd *hcd);
19361966 };
19371967
19381968 #define XHCI_CFC_DELAY 10
....@@ -2037,6 +2067,8 @@
20372067 struct xhci_ring *evt_ring,
20382068 struct xhci_erst *erst,
20392069 gfp_t flags);
2070
+void xhci_initialize_ring_info(struct xhci_ring *ring,
2071
+ unsigned int cycle_state);
20402072 void xhci_free_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
20412073 void xhci_free_endpoint_ring(struct xhci_hcd *xhci,
20422074 struct xhci_virt_device *virt_dev,
....@@ -2057,10 +2089,6 @@
20572089 struct xhci_ring *xhci_dma_to_transfer_ring(
20582090 struct xhci_virt_ep *ep,
20592091 u64 address);
2060
-struct xhci_ring *xhci_stream_id_to_ring(
2061
- struct xhci_virt_device *dev,
2062
- unsigned int ep_index,
2063
- unsigned int stream_id);
20642092 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
20652093 bool allocate_completion, gfp_t mem_flags);
20662094 struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci,
....@@ -2072,21 +2100,26 @@
20722100 int type, gfp_t flags);
20732101 void xhci_free_container_ctx(struct xhci_hcd *xhci,
20742102 struct xhci_container_ctx *ctx);
2075
-int xhci_sec_event_ring_setup(struct usb_hcd *hcd, unsigned int intr_num);
2076
-int xhci_sec_event_ring_cleanup(struct usb_hcd *hcd, unsigned int intr_num);
20772103
20782104 /* xHCI host controller glue */
20792105 typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
2080
-int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec);
2106
+int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us);
20812107 void xhci_quiesce(struct xhci_hcd *xhci);
20822108 int xhci_halt(struct xhci_hcd *xhci);
20832109 int xhci_start(struct xhci_hcd *xhci);
2084
-int xhci_reset(struct xhci_hcd *xhci);
2110
+int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us);
20852111 int xhci_run(struct usb_hcd *hcd);
20862112 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
20872113 void xhci_shutdown(struct usb_hcd *hcd);
20882114 void xhci_init_driver(struct hc_driver *drv,
20892115 const struct xhci_driver_overrides *over);
2116
+int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2117
+ struct usb_host_endpoint *ep);
2118
+int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2119
+ struct usb_host_endpoint *ep);
2120
+int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
2121
+void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
2122
+int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
20902123 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id);
20912124 int xhci_ext_cap_init(struct xhci_hcd *xhci);
20922125
....@@ -2134,20 +2167,17 @@
21342167 enum xhci_ep_reset_type reset_type);
21352168 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd,
21362169 u32 slot_id);
2137
-void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
2138
- unsigned int slot_id, unsigned int ep_index,
2139
- unsigned int stream_id, struct xhci_td *cur_td,
2140
- struct xhci_dequeue_state *state);
2141
-void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
2142
- unsigned int slot_id, unsigned int ep_index,
2143
- struct xhci_dequeue_state *deq_state);
2144
-void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int ep_index,
2145
- unsigned int stream_id, struct xhci_td *td);
2170
+void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int slot_id,
2171
+ unsigned int ep_index, unsigned int stream_id,
2172
+ struct xhci_td *td);
21462173 void xhci_stop_endpoint_command_watchdog(struct timer_list *t);
21472174 void xhci_handle_command_timeout(struct work_struct *work);
21482175
21492176 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
21502177 unsigned int ep_index, unsigned int stream_id);
2178
+void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci,
2179
+ unsigned int slot_id,
2180
+ unsigned int ep_index);
21512181 void xhci_cleanup_command_queue(struct xhci_hcd *xhci);
21522182 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring);
21532183 unsigned int count_trbs(u64 addr, u64 len);
....@@ -2197,6 +2227,70 @@
21972227 urb->stream_id);
21982228 }
21992229
2230
+/**
2231
+ * struct xhci_vendor_ops - function callbacks for vendor specific operations
2232
+ * @vendor_init: called for vendor init process
2233
+ * @vendor_cleanup: called for vendor cleanup process
2234
+ * @is_usb_offload_enabled: called to check if usb offload enabled
2235
+ * @queue_irq_work: called to queue vendor specific irq work
2236
+ * @alloc_dcbaa: called when allocating vendor specific dcbaa
2237
+ * @free_dcbaa: called to free vendor specific dcbaa
2238
+ * @alloc_transfer_ring: called when remote transfer ring allocation is required
2239
+ * @free_transfer_ring: called to free vendor specific transfer ring
2240
+ * @sync_dev_ctx: called when synchronization for device context is required
2241
+ * @alloc_container_ctx: called when allocating vendor specific container context
2242
+ * @free_container_ctx: called to free vendor specific container context
2243
+ */
2244
+struct xhci_vendor_ops {
2245
+ int (*vendor_init)(struct xhci_hcd *xhci);
2246
+ void (*vendor_cleanup)(struct xhci_hcd *xhci);
2247
+ bool (*is_usb_offload_enabled)(struct xhci_hcd *xhci,
2248
+ struct xhci_virt_device *vdev,
2249
+ unsigned int ep_index);
2250
+ irqreturn_t (*queue_irq_work)(struct xhci_hcd *xhci);
2251
+
2252
+ struct xhci_device_context_array *(*alloc_dcbaa)(struct xhci_hcd *xhci,
2253
+ gfp_t flags);
2254
+ void (*free_dcbaa)(struct xhci_hcd *xhci);
2255
+
2256
+ struct xhci_ring *(*alloc_transfer_ring)(struct xhci_hcd *xhci,
2257
+ u32 endpoint_type, enum xhci_ring_type ring_type,
2258
+ unsigned int max_packet, gfp_t mem_flags);
2259
+ void (*free_transfer_ring)(struct xhci_hcd *xhci,
2260
+ struct xhci_virt_device *virt_dev, unsigned int ep_index);
2261
+ int (*sync_dev_ctx)(struct xhci_hcd *xhci, unsigned int slot_id);
2262
+ bool (*usb_offload_skip_urb)(struct xhci_hcd *xhci, struct urb *urb);
2263
+ void (*alloc_container_ctx)(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
2264
+ int type, gfp_t flags);
2265
+ void (*free_container_ctx)(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
2266
+};
2267
+
2268
+struct xhci_vendor_ops *xhci_vendor_get_ops(struct xhci_hcd *xhci);
2269
+
2270
+int xhci_vendor_sync_dev_ctx(struct xhci_hcd *xhci, unsigned int slot_id);
2271
+bool xhci_vendor_usb_offload_skip_urb(struct xhci_hcd *xhci, struct urb *urb);
2272
+void xhci_vendor_free_transfer_ring(struct xhci_hcd *xhci,
2273
+ struct xhci_virt_device *virt_dev, unsigned int ep_index);
2274
+bool xhci_vendor_is_usb_offload_enabled(struct xhci_hcd *xhci,
2275
+ struct xhci_virt_device *virt_dev, unsigned int ep_index);
2276
+
2277
+/*
2278
+ * TODO: As per spec Isochronous IDT transmissions are supported. We bypass
2279
+ * them anyways as we where unable to find a device that matches the
2280
+ * constraints.
2281
+ */
2282
+static inline bool xhci_urb_suitable_for_idt(struct urb *urb)
2283
+{
2284
+ if (!usb_endpoint_xfer_isoc(&urb->ep->desc) && usb_urb_dir_out(urb) &&
2285
+ usb_endpoint_maxp(&urb->ep->desc) >= TRB_IDT_MAX_SIZE &&
2286
+ urb->transfer_buffer_length <= TRB_IDT_MAX_SIZE &&
2287
+ !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) &&
2288
+ !urb->num_sgs)
2289
+ return true;
2290
+
2291
+ return false;
2292
+}
2293
+
22002294 static inline char *xhci_slot_state_string(u32 state)
22012295 {
22022296 switch (state) {
....@@ -2213,15 +2307,14 @@
22132307 }
22142308 }
22152309
2216
-static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2217
- u32 field3)
2310
+static inline const char *xhci_decode_trb(char *str, size_t size,
2311
+ u32 field0, u32 field1, u32 field2, u32 field3)
22182312 {
2219
- static char str[256];
22202313 int type = TRB_FIELD_TO_TYPE(field3);
22212314
22222315 switch (type) {
22232316 case TRB_LINK:
2224
- sprintf(str,
2317
+ snprintf(str, size,
22252318 "LINK %08x%08x intr %d type '%s' flags %c:%c:%c:%c",
22262319 field1, field0, GET_INTR_TARGET(field2),
22272320 xhci_trb_type_string(type),
....@@ -2238,7 +2331,7 @@
22382331 case TRB_HC_EVENT:
22392332 case TRB_DEV_NOTE:
22402333 case TRB_MFINDEX_WRAP:
2241
- sprintf(str,
2334
+ snprintf(str, size,
22422335 "TRB %08x%08x status '%s' len %d slot %d ep %d type '%s' flags %c:%c",
22432336 field1, field0,
22442337 xhci_trb_comp_code_string(GET_COMP_CODE(field2)),
....@@ -2251,7 +2344,8 @@
22512344
22522345 break;
22532346 case TRB_SETUP:
2254
- sprintf(str, "bRequestType %02x bRequest %02x wValue %02x%02x wIndex %02x%02x wLength %d length %d TD size %d intr %d type '%s' flags %c:%c:%c",
2347
+ snprintf(str, size,
2348
+ "bRequestType %02x bRequest %02x wValue %02x%02x wIndex %02x%02x wLength %d length %d TD size %d intr %d type '%s' flags %c:%c:%c",
22552349 field0 & 0xff,
22562350 (field0 & 0xff00) >> 8,
22572351 (field0 & 0xff000000) >> 24,
....@@ -2268,7 +2362,8 @@
22682362 field3 & TRB_CYCLE ? 'C' : 'c');
22692363 break;
22702364 case TRB_DATA:
2271
- sprintf(str, "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c",
2365
+ snprintf(str, size,
2366
+ "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c",
22722367 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
22732368 GET_INTR_TARGET(field2),
22742369 xhci_trb_type_string(type),
....@@ -2281,7 +2376,8 @@
22812376 field3 & TRB_CYCLE ? 'C' : 'c');
22822377 break;
22832378 case TRB_STATUS:
2284
- sprintf(str, "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c",
2379
+ snprintf(str, size,
2380
+ "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c",
22852381 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
22862382 GET_INTR_TARGET(field2),
22872383 xhci_trb_type_string(type),
....@@ -2294,7 +2390,7 @@
22942390 case TRB_ISOC:
22952391 case TRB_EVENT_DATA:
22962392 case TRB_TR_NOOP:
2297
- sprintf(str,
2393
+ snprintf(str, size,
22982394 "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c:%c",
22992395 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
23002396 GET_INTR_TARGET(field2),
....@@ -2311,21 +2407,21 @@
23112407
23122408 case TRB_CMD_NOOP:
23132409 case TRB_ENABLE_SLOT:
2314
- sprintf(str,
2410
+ snprintf(str, size,
23152411 "%s: flags %c",
23162412 xhci_trb_type_string(type),
23172413 field3 & TRB_CYCLE ? 'C' : 'c');
23182414 break;
23192415 case TRB_DISABLE_SLOT:
23202416 case TRB_NEG_BANDWIDTH:
2321
- sprintf(str,
2417
+ snprintf(str, size,
23222418 "%s: slot %d flags %c",
23232419 xhci_trb_type_string(type),
23242420 TRB_TO_SLOT_ID(field3),
23252421 field3 & TRB_CYCLE ? 'C' : 'c');
23262422 break;
23272423 case TRB_ADDR_DEV:
2328
- sprintf(str,
2424
+ snprintf(str, size,
23292425 "%s: ctx %08x%08x slot %d flags %c:%c",
23302426 xhci_trb_type_string(type),
23312427 field1, field0,
....@@ -2334,7 +2430,7 @@
23342430 field3 & TRB_CYCLE ? 'C' : 'c');
23352431 break;
23362432 case TRB_CONFIG_EP:
2337
- sprintf(str,
2433
+ snprintf(str, size,
23382434 "%s: ctx %08x%08x slot %d flags %c:%c",
23392435 xhci_trb_type_string(type),
23402436 field1, field0,
....@@ -2343,7 +2439,7 @@
23432439 field3 & TRB_CYCLE ? 'C' : 'c');
23442440 break;
23452441 case TRB_EVAL_CONTEXT:
2346
- sprintf(str,
2442
+ snprintf(str, size,
23472443 "%s: ctx %08x%08x slot %d flags %c",
23482444 xhci_trb_type_string(type),
23492445 field1, field0,
....@@ -2351,17 +2447,18 @@
23512447 field3 & TRB_CYCLE ? 'C' : 'c');
23522448 break;
23532449 case TRB_RESET_EP:
2354
- sprintf(str,
2355
- "%s: ctx %08x%08x slot %d ep %d flags %c",
2450
+ snprintf(str, size,
2451
+ "%s: ctx %08x%08x slot %d ep %d flags %c:%c",
23562452 xhci_trb_type_string(type),
23572453 field1, field0,
23582454 TRB_TO_SLOT_ID(field3),
23592455 /* Macro decrements 1, maybe it shouldn't?!? */
23602456 TRB_TO_EP_INDEX(field3) + 1,
2457
+ field3 & TRB_TSP ? 'T' : 't',
23612458 field3 & TRB_CYCLE ? 'C' : 'c');
23622459 break;
23632460 case TRB_STOP_RING:
2364
- sprintf(str,
2461
+ snprintf(str, size,
23652462 "%s: slot %d sp %d ep %d flags %c",
23662463 xhci_trb_type_string(type),
23672464 TRB_TO_SLOT_ID(field3),
....@@ -2371,7 +2468,7 @@
23712468 field3 & TRB_CYCLE ? 'C' : 'c');
23722469 break;
23732470 case TRB_SET_DEQ:
2374
- sprintf(str,
2471
+ snprintf(str, size,
23752472 "%s: deq %08x%08x stream %d slot %d ep %d flags %c",
23762473 xhci_trb_type_string(type),
23772474 field1, field0,
....@@ -2382,14 +2479,14 @@
23822479 field3 & TRB_CYCLE ? 'C' : 'c');
23832480 break;
23842481 case TRB_RESET_DEV:
2385
- sprintf(str,
2482
+ snprintf(str, size,
23862483 "%s: slot %d flags %c",
23872484 xhci_trb_type_string(type),
23882485 TRB_TO_SLOT_ID(field3),
23892486 field3 & TRB_CYCLE ? 'C' : 'c');
23902487 break;
23912488 case TRB_FORCE_EVENT:
2392
- sprintf(str,
2489
+ snprintf(str, size,
23932490 "%s: event %08x%08x vf intr %d vf id %d flags %c",
23942491 xhci_trb_type_string(type),
23952492 field1, field0,
....@@ -2398,14 +2495,14 @@
23982495 field3 & TRB_CYCLE ? 'C' : 'c');
23992496 break;
24002497 case TRB_SET_LT:
2401
- sprintf(str,
2498
+ snprintf(str, size,
24022499 "%s: belt %d flags %c",
24032500 xhci_trb_type_string(type),
24042501 TRB_TO_BELT(field3),
24052502 field3 & TRB_CYCLE ? 'C' : 'c');
24062503 break;
24072504 case TRB_GET_BW:
2408
- sprintf(str,
2505
+ snprintf(str, size,
24092506 "%s: ctx %08x%08x slot %d speed %d flags %c",
24102507 xhci_trb_type_string(type),
24112508 field1, field0,
....@@ -2414,7 +2511,7 @@
24142511 field3 & TRB_CYCLE ? 'C' : 'c');
24152512 break;
24162513 case TRB_FORCE_HEADER:
2417
- sprintf(str,
2514
+ snprintf(str, size,
24182515 "%s: info %08x%08x%08x pkt type %d roothub port %d flags %c",
24192516 xhci_trb_type_string(type),
24202517 field2, field1, field0 & 0xffffffe0,
....@@ -2423,7 +2520,7 @@
24232520 field3 & TRB_CYCLE ? 'C' : 'c');
24242521 break;
24252522 default:
2426
- sprintf(str,
2523
+ snprintf(str, size,
24272524 "type '%s' -> raw %08x %08x %08x %08x",
24282525 xhci_trb_type_string(type),
24292526 field0, field1, field2, field3);
....@@ -2432,10 +2529,39 @@
24322529 return str;
24332530 }
24342531
2435
-static inline const char *xhci_decode_slot_context(u32 info, u32 info2,
2436
- u32 tt_info, u32 state)
2532
+static inline const char *xhci_decode_ctrl_ctx(char *str,
2533
+ unsigned long drop, unsigned long add)
24372534 {
2438
- static char str[1024];
2535
+ unsigned int bit;
2536
+ int ret = 0;
2537
+
2538
+ str[0] = '\0';
2539
+
2540
+ if (drop) {
2541
+ ret = sprintf(str, "Drop:");
2542
+ for_each_set_bit(bit, &drop, 32)
2543
+ ret += sprintf(str + ret, " %d%s",
2544
+ bit / 2,
2545
+ bit % 2 ? "in":"out");
2546
+ ret += sprintf(str + ret, ", ");
2547
+ }
2548
+
2549
+ if (add) {
2550
+ ret += sprintf(str + ret, "Add:%s%s",
2551
+ (add & SLOT_FLAG) ? " slot":"",
2552
+ (add & EP0_FLAG) ? " ep0":"");
2553
+ add &= ~(SLOT_FLAG | EP0_FLAG);
2554
+ for_each_set_bit(bit, &add, 32)
2555
+ ret += sprintf(str + ret, " %d%s",
2556
+ bit / 2,
2557
+ bit % 2 ? "in":"out");
2558
+ }
2559
+ return str;
2560
+}
2561
+
2562
+static inline const char *xhci_decode_slot_context(char *str,
2563
+ u32 info, u32 info2, u32 tt_info, u32 state)
2564
+{
24392565 u32 speed;
24402566 u32 hub;
24412567 u32 mtt;
....@@ -2519,9 +2645,8 @@
25192645 return "Unknown";
25202646 }
25212647
2522
-static inline const char *xhci_decode_portsc(u32 portsc)
2648
+static inline const char *xhci_decode_portsc(char *str, u32 portsc)
25232649 {
2524
- static char str[256];
25252650 int ret;
25262651
25272652 ret = sprintf(str, "%s %s %s Link:%s PortSpeed:%d ",
....@@ -2561,6 +2686,65 @@
25612686 ret += sprintf(str + ret, "WDE ");
25622687 if (portsc & PORT_WKOC_E)
25632688 ret += sprintf(str + ret, "WOE ");
2689
+
2690
+ return str;
2691
+}
2692
+
2693
+static inline const char *xhci_decode_usbsts(char *str, u32 usbsts)
2694
+{
2695
+ int ret = 0;
2696
+
2697
+ ret = sprintf(str, " 0x%08x", usbsts);
2698
+
2699
+ if (usbsts == ~(u32)0)
2700
+ return str;
2701
+
2702
+ if (usbsts & STS_HALT)
2703
+ ret += sprintf(str + ret, " HCHalted");
2704
+ if (usbsts & STS_FATAL)
2705
+ ret += sprintf(str + ret, " HSE");
2706
+ if (usbsts & STS_EINT)
2707
+ ret += sprintf(str + ret, " EINT");
2708
+ if (usbsts & STS_PORT)
2709
+ ret += sprintf(str + ret, " PCD");
2710
+ if (usbsts & STS_SAVE)
2711
+ ret += sprintf(str + ret, " SSS");
2712
+ if (usbsts & STS_RESTORE)
2713
+ ret += sprintf(str + ret, " RSS");
2714
+ if (usbsts & STS_SRE)
2715
+ ret += sprintf(str + ret, " SRE");
2716
+ if (usbsts & STS_CNR)
2717
+ ret += sprintf(str + ret, " CNR");
2718
+ if (usbsts & STS_HCE)
2719
+ ret += sprintf(str + ret, " HCE");
2720
+
2721
+ return str;
2722
+}
2723
+
2724
+static inline const char *xhci_decode_doorbell(char *str, u32 slot, u32 doorbell)
2725
+{
2726
+ u8 ep;
2727
+ u16 stream;
2728
+ int ret;
2729
+
2730
+ ep = (doorbell & 0xff);
2731
+ stream = doorbell >> 16;
2732
+
2733
+ if (slot == 0) {
2734
+ sprintf(str, "Command Ring %d", doorbell);
2735
+ return str;
2736
+ }
2737
+ ret = sprintf(str, "Slot %d ", slot);
2738
+ if (ep > 0 && ep < 32)
2739
+ ret = sprintf(str + ret, "ep%d%s",
2740
+ ep / 2,
2741
+ ep % 2 ? "in" : "out");
2742
+ else if (ep == 0 || ep < 248)
2743
+ ret = sprintf(str + ret, "Reserved %d", ep);
2744
+ else
2745
+ ret = sprintf(str + ret, "Vendor Defined %d", ep);
2746
+ if (stream)
2747
+ ret = sprintf(str + ret, " Stream %d", stream);
25642748
25652749 return str;
25662750 }
....@@ -2605,10 +2789,9 @@
26052789 }
26062790 }
26072791
2608
-static inline const char *xhci_decode_ep_context(u32 info, u32 info2, u64 deq,
2609
- u32 tx_info)
2792
+static inline const char *xhci_decode_ep_context(char *str, u32 info,
2793
+ u32 info2, u64 deq, u32 tx_info)
26102794 {
2611
- static char str[1024];
26122795 int ret;
26132796
26142797 u32 esit;