forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
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,26 @@
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_ZHAOXIN_TRB_FETCH BIT_ULL(45)
1912
+#define XHCI_ZHAOXIN_HOST BIT_ULL(46)
1913
+#define XHCI_U2_BROKEN_SUSPEND BIT_ULL(47)
18951914
18961915 unsigned int num_active_eps;
18971916 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];
19001917 struct xhci_port *hw_ports;
19011918 struct xhci_hub usb2_rhub;
19021919 struct xhci_hub usb3_rhub;
1903
- /* support xHCI 0.96 spec USB2 software LPM */
1904
- unsigned sw_lpm_support:1;
19051920 /* support xHCI 1.0 spec USB2 hardware LPM */
19061921 unsigned hw_lpm_support:1;
19071922 /* Broken Suspend flag for SNPS Suspend resume issue */
....@@ -1924,8 +1939,16 @@
19241939 struct list_head regset_list;
19251940
19261941 void *dbc;
1942
+
1943
+ /* Used for bug 194461020 */
1944
+ ANDROID_KABI_USE(1, struct xhci_vendor_ops *vendor_ops);
1945
+
1946
+ ANDROID_KABI_RESERVE(2);
1947
+ ANDROID_KABI_RESERVE(3);
1948
+ ANDROID_KABI_RESERVE(4);
1949
+
19271950 /* platform-specific data -- must come last */
1928
- unsigned long priv[0] __aligned(sizeof(s64));
1951
+ unsigned long priv[] __aligned(sizeof(s64));
19291952 };
19301953
19311954 /* Platform specific overrides to generic XHCI hc_driver ops */
....@@ -1933,6 +1956,15 @@
19331956 size_t extra_priv_size;
19341957 int (*reset)(struct usb_hcd *hcd);
19351958 int (*start)(struct usb_hcd *hcd);
1959
+ int (*add_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1960
+ struct usb_host_endpoint *ep);
1961
+ int (*drop_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1962
+ struct usb_host_endpoint *ep);
1963
+ int (*check_bandwidth)(struct usb_hcd *, struct usb_device *);
1964
+ void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
1965
+ int (*address_device)(struct usb_hcd *hcd, struct usb_device *udev);
1966
+ int (*bus_suspend)(struct usb_hcd *hcd);
1967
+ int (*bus_resume)(struct usb_hcd *hcd);
19361968 };
19371969
19381970 #define XHCI_CFC_DELAY 10
....@@ -2037,6 +2069,8 @@
20372069 struct xhci_ring *evt_ring,
20382070 struct xhci_erst *erst,
20392071 gfp_t flags);
2072
+void xhci_initialize_ring_info(struct xhci_ring *ring,
2073
+ unsigned int cycle_state);
20402074 void xhci_free_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
20412075 void xhci_free_endpoint_ring(struct xhci_hcd *xhci,
20422076 struct xhci_virt_device *virt_dev,
....@@ -2057,10 +2091,6 @@
20572091 struct xhci_ring *xhci_dma_to_transfer_ring(
20582092 struct xhci_virt_ep *ep,
20592093 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);
20642094 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
20652095 bool allocate_completion, gfp_t mem_flags);
20662096 struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci,
....@@ -2072,21 +2102,26 @@
20722102 int type, gfp_t flags);
20732103 void xhci_free_container_ctx(struct xhci_hcd *xhci,
20742104 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);
20772105
20782106 /* xHCI host controller glue */
20792107 typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
2080
-int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec);
2108
+int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us);
20812109 void xhci_quiesce(struct xhci_hcd *xhci);
20822110 int xhci_halt(struct xhci_hcd *xhci);
20832111 int xhci_start(struct xhci_hcd *xhci);
2084
-int xhci_reset(struct xhci_hcd *xhci);
2112
+int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us);
20852113 int xhci_run(struct usb_hcd *hcd);
20862114 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
20872115 void xhci_shutdown(struct usb_hcd *hcd);
20882116 void xhci_init_driver(struct hc_driver *drv,
20892117 const struct xhci_driver_overrides *over);
2118
+int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2119
+ struct usb_host_endpoint *ep);
2120
+int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2121
+ struct usb_host_endpoint *ep);
2122
+int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
2123
+void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
2124
+int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
20902125 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id);
20912126 int xhci_ext_cap_init(struct xhci_hcd *xhci);
20922127
....@@ -2134,20 +2169,17 @@
21342169 enum xhci_ep_reset_type reset_type);
21352170 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd,
21362171 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);
2172
+void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int slot_id,
2173
+ unsigned int ep_index, unsigned int stream_id,
2174
+ struct xhci_td *td);
21462175 void xhci_stop_endpoint_command_watchdog(struct timer_list *t);
21472176 void xhci_handle_command_timeout(struct work_struct *work);
21482177
21492178 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
21502179 unsigned int ep_index, unsigned int stream_id);
2180
+void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci,
2181
+ unsigned int slot_id,
2182
+ unsigned int ep_index);
21512183 void xhci_cleanup_command_queue(struct xhci_hcd *xhci);
21522184 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring);
21532185 unsigned int count_trbs(u64 addr, u64 len);
....@@ -2197,6 +2229,70 @@
21972229 urb->stream_id);
21982230 }
21992231
2232
+/**
2233
+ * struct xhci_vendor_ops - function callbacks for vendor specific operations
2234
+ * @vendor_init: called for vendor init process
2235
+ * @vendor_cleanup: called for vendor cleanup process
2236
+ * @is_usb_offload_enabled: called to check if usb offload enabled
2237
+ * @queue_irq_work: called to queue vendor specific irq work
2238
+ * @alloc_dcbaa: called when allocating vendor specific dcbaa
2239
+ * @free_dcbaa: called to free vendor specific dcbaa
2240
+ * @alloc_transfer_ring: called when remote transfer ring allocation is required
2241
+ * @free_transfer_ring: called to free vendor specific transfer ring
2242
+ * @sync_dev_ctx: called when synchronization for device context is required
2243
+ * @alloc_container_ctx: called when allocating vendor specific container context
2244
+ * @free_container_ctx: called to free vendor specific container context
2245
+ */
2246
+struct xhci_vendor_ops {
2247
+ int (*vendor_init)(struct xhci_hcd *xhci);
2248
+ void (*vendor_cleanup)(struct xhci_hcd *xhci);
2249
+ bool (*is_usb_offload_enabled)(struct xhci_hcd *xhci,
2250
+ struct xhci_virt_device *vdev,
2251
+ unsigned int ep_index);
2252
+ irqreturn_t (*queue_irq_work)(struct xhci_hcd *xhci);
2253
+
2254
+ struct xhci_device_context_array *(*alloc_dcbaa)(struct xhci_hcd *xhci,
2255
+ gfp_t flags);
2256
+ void (*free_dcbaa)(struct xhci_hcd *xhci);
2257
+
2258
+ struct xhci_ring *(*alloc_transfer_ring)(struct xhci_hcd *xhci,
2259
+ u32 endpoint_type, enum xhci_ring_type ring_type,
2260
+ unsigned int max_packet, gfp_t mem_flags);
2261
+ void (*free_transfer_ring)(struct xhci_hcd *xhci,
2262
+ struct xhci_virt_device *virt_dev, unsigned int ep_index);
2263
+ int (*sync_dev_ctx)(struct xhci_hcd *xhci, unsigned int slot_id);
2264
+ bool (*usb_offload_skip_urb)(struct xhci_hcd *xhci, struct urb *urb);
2265
+ void (*alloc_container_ctx)(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
2266
+ int type, gfp_t flags);
2267
+ void (*free_container_ctx)(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
2268
+};
2269
+
2270
+struct xhci_vendor_ops *xhci_vendor_get_ops(struct xhci_hcd *xhci);
2271
+
2272
+int xhci_vendor_sync_dev_ctx(struct xhci_hcd *xhci, unsigned int slot_id);
2273
+bool xhci_vendor_usb_offload_skip_urb(struct xhci_hcd *xhci, struct urb *urb);
2274
+void xhci_vendor_free_transfer_ring(struct xhci_hcd *xhci,
2275
+ struct xhci_virt_device *virt_dev, unsigned int ep_index);
2276
+bool xhci_vendor_is_usb_offload_enabled(struct xhci_hcd *xhci,
2277
+ struct xhci_virt_device *virt_dev, unsigned int ep_index);
2278
+
2279
+/*
2280
+ * TODO: As per spec Isochronous IDT transmissions are supported. We bypass
2281
+ * them anyways as we where unable to find a device that matches the
2282
+ * constraints.
2283
+ */
2284
+static inline bool xhci_urb_suitable_for_idt(struct urb *urb)
2285
+{
2286
+ if (!usb_endpoint_xfer_isoc(&urb->ep->desc) && usb_urb_dir_out(urb) &&
2287
+ usb_endpoint_maxp(&urb->ep->desc) >= TRB_IDT_MAX_SIZE &&
2288
+ urb->transfer_buffer_length <= TRB_IDT_MAX_SIZE &&
2289
+ !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) &&
2290
+ !urb->num_sgs)
2291
+ return true;
2292
+
2293
+ return false;
2294
+}
2295
+
22002296 static inline char *xhci_slot_state_string(u32 state)
22012297 {
22022298 switch (state) {
....@@ -2213,15 +2309,14 @@
22132309 }
22142310 }
22152311
2216
-static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2217
- u32 field3)
2312
+static inline const char *xhci_decode_trb(char *str, size_t size,
2313
+ u32 field0, u32 field1, u32 field2, u32 field3)
22182314 {
2219
- static char str[256];
22202315 int type = TRB_FIELD_TO_TYPE(field3);
22212316
22222317 switch (type) {
22232318 case TRB_LINK:
2224
- sprintf(str,
2319
+ snprintf(str, size,
22252320 "LINK %08x%08x intr %d type '%s' flags %c:%c:%c:%c",
22262321 field1, field0, GET_INTR_TARGET(field2),
22272322 xhci_trb_type_string(type),
....@@ -2238,7 +2333,7 @@
22382333 case TRB_HC_EVENT:
22392334 case TRB_DEV_NOTE:
22402335 case TRB_MFINDEX_WRAP:
2241
- sprintf(str,
2336
+ snprintf(str, size,
22422337 "TRB %08x%08x status '%s' len %d slot %d ep %d type '%s' flags %c:%c",
22432338 field1, field0,
22442339 xhci_trb_comp_code_string(GET_COMP_CODE(field2)),
....@@ -2251,7 +2346,8 @@
22512346
22522347 break;
22532348 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",
2349
+ snprintf(str, size,
2350
+ "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",
22552351 field0 & 0xff,
22562352 (field0 & 0xff00) >> 8,
22572353 (field0 & 0xff000000) >> 24,
....@@ -2268,7 +2364,8 @@
22682364 field3 & TRB_CYCLE ? 'C' : 'c');
22692365 break;
22702366 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",
2367
+ snprintf(str, size,
2368
+ "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c",
22722369 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
22732370 GET_INTR_TARGET(field2),
22742371 xhci_trb_type_string(type),
....@@ -2281,7 +2378,8 @@
22812378 field3 & TRB_CYCLE ? 'C' : 'c');
22822379 break;
22832380 case TRB_STATUS:
2284
- sprintf(str, "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c",
2381
+ snprintf(str, size,
2382
+ "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c",
22852383 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
22862384 GET_INTR_TARGET(field2),
22872385 xhci_trb_type_string(type),
....@@ -2294,7 +2392,7 @@
22942392 case TRB_ISOC:
22952393 case TRB_EVENT_DATA:
22962394 case TRB_TR_NOOP:
2297
- sprintf(str,
2395
+ snprintf(str, size,
22982396 "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c:%c",
22992397 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
23002398 GET_INTR_TARGET(field2),
....@@ -2311,21 +2409,21 @@
23112409
23122410 case TRB_CMD_NOOP:
23132411 case TRB_ENABLE_SLOT:
2314
- sprintf(str,
2412
+ snprintf(str, size,
23152413 "%s: flags %c",
23162414 xhci_trb_type_string(type),
23172415 field3 & TRB_CYCLE ? 'C' : 'c');
23182416 break;
23192417 case TRB_DISABLE_SLOT:
23202418 case TRB_NEG_BANDWIDTH:
2321
- sprintf(str,
2419
+ snprintf(str, size,
23222420 "%s: slot %d flags %c",
23232421 xhci_trb_type_string(type),
23242422 TRB_TO_SLOT_ID(field3),
23252423 field3 & TRB_CYCLE ? 'C' : 'c');
23262424 break;
23272425 case TRB_ADDR_DEV:
2328
- sprintf(str,
2426
+ snprintf(str, size,
23292427 "%s: ctx %08x%08x slot %d flags %c:%c",
23302428 xhci_trb_type_string(type),
23312429 field1, field0,
....@@ -2334,7 +2432,7 @@
23342432 field3 & TRB_CYCLE ? 'C' : 'c');
23352433 break;
23362434 case TRB_CONFIG_EP:
2337
- sprintf(str,
2435
+ snprintf(str, size,
23382436 "%s: ctx %08x%08x slot %d flags %c:%c",
23392437 xhci_trb_type_string(type),
23402438 field1, field0,
....@@ -2343,7 +2441,7 @@
23432441 field3 & TRB_CYCLE ? 'C' : 'c');
23442442 break;
23452443 case TRB_EVAL_CONTEXT:
2346
- sprintf(str,
2444
+ snprintf(str, size,
23472445 "%s: ctx %08x%08x slot %d flags %c",
23482446 xhci_trb_type_string(type),
23492447 field1, field0,
....@@ -2351,17 +2449,18 @@
23512449 field3 & TRB_CYCLE ? 'C' : 'c');
23522450 break;
23532451 case TRB_RESET_EP:
2354
- sprintf(str,
2355
- "%s: ctx %08x%08x slot %d ep %d flags %c",
2452
+ snprintf(str, size,
2453
+ "%s: ctx %08x%08x slot %d ep %d flags %c:%c",
23562454 xhci_trb_type_string(type),
23572455 field1, field0,
23582456 TRB_TO_SLOT_ID(field3),
23592457 /* Macro decrements 1, maybe it shouldn't?!? */
23602458 TRB_TO_EP_INDEX(field3) + 1,
2459
+ field3 & TRB_TSP ? 'T' : 't',
23612460 field3 & TRB_CYCLE ? 'C' : 'c');
23622461 break;
23632462 case TRB_STOP_RING:
2364
- sprintf(str,
2463
+ snprintf(str, size,
23652464 "%s: slot %d sp %d ep %d flags %c",
23662465 xhci_trb_type_string(type),
23672466 TRB_TO_SLOT_ID(field3),
....@@ -2371,7 +2470,7 @@
23712470 field3 & TRB_CYCLE ? 'C' : 'c');
23722471 break;
23732472 case TRB_SET_DEQ:
2374
- sprintf(str,
2473
+ snprintf(str, size,
23752474 "%s: deq %08x%08x stream %d slot %d ep %d flags %c",
23762475 xhci_trb_type_string(type),
23772476 field1, field0,
....@@ -2382,14 +2481,14 @@
23822481 field3 & TRB_CYCLE ? 'C' : 'c');
23832482 break;
23842483 case TRB_RESET_DEV:
2385
- sprintf(str,
2484
+ snprintf(str, size,
23862485 "%s: slot %d flags %c",
23872486 xhci_trb_type_string(type),
23882487 TRB_TO_SLOT_ID(field3),
23892488 field3 & TRB_CYCLE ? 'C' : 'c');
23902489 break;
23912490 case TRB_FORCE_EVENT:
2392
- sprintf(str,
2491
+ snprintf(str, size,
23932492 "%s: event %08x%08x vf intr %d vf id %d flags %c",
23942493 xhci_trb_type_string(type),
23952494 field1, field0,
....@@ -2398,14 +2497,14 @@
23982497 field3 & TRB_CYCLE ? 'C' : 'c');
23992498 break;
24002499 case TRB_SET_LT:
2401
- sprintf(str,
2500
+ snprintf(str, size,
24022501 "%s: belt %d flags %c",
24032502 xhci_trb_type_string(type),
24042503 TRB_TO_BELT(field3),
24052504 field3 & TRB_CYCLE ? 'C' : 'c');
24062505 break;
24072506 case TRB_GET_BW:
2408
- sprintf(str,
2507
+ snprintf(str, size,
24092508 "%s: ctx %08x%08x slot %d speed %d flags %c",
24102509 xhci_trb_type_string(type),
24112510 field1, field0,
....@@ -2414,7 +2513,7 @@
24142513 field3 & TRB_CYCLE ? 'C' : 'c');
24152514 break;
24162515 case TRB_FORCE_HEADER:
2417
- sprintf(str,
2516
+ snprintf(str, size,
24182517 "%s: info %08x%08x%08x pkt type %d roothub port %d flags %c",
24192518 xhci_trb_type_string(type),
24202519 field2, field1, field0 & 0xffffffe0,
....@@ -2423,7 +2522,7 @@
24232522 field3 & TRB_CYCLE ? 'C' : 'c');
24242523 break;
24252524 default:
2426
- sprintf(str,
2525
+ snprintf(str, size,
24272526 "type '%s' -> raw %08x %08x %08x %08x",
24282527 xhci_trb_type_string(type),
24292528 field0, field1, field2, field3);
....@@ -2432,10 +2531,39 @@
24322531 return str;
24332532 }
24342533
2435
-static inline const char *xhci_decode_slot_context(u32 info, u32 info2,
2436
- u32 tt_info, u32 state)
2534
+static inline const char *xhci_decode_ctrl_ctx(char *str,
2535
+ unsigned long drop, unsigned long add)
24372536 {
2438
- static char str[1024];
2537
+ unsigned int bit;
2538
+ int ret = 0;
2539
+
2540
+ str[0] = '\0';
2541
+
2542
+ if (drop) {
2543
+ ret = sprintf(str, "Drop:");
2544
+ for_each_set_bit(bit, &drop, 32)
2545
+ ret += sprintf(str + ret, " %d%s",
2546
+ bit / 2,
2547
+ bit % 2 ? "in":"out");
2548
+ ret += sprintf(str + ret, ", ");
2549
+ }
2550
+
2551
+ if (add) {
2552
+ ret += sprintf(str + ret, "Add:%s%s",
2553
+ (add & SLOT_FLAG) ? " slot":"",
2554
+ (add & EP0_FLAG) ? " ep0":"");
2555
+ add &= ~(SLOT_FLAG | EP0_FLAG);
2556
+ for_each_set_bit(bit, &add, 32)
2557
+ ret += sprintf(str + ret, " %d%s",
2558
+ bit / 2,
2559
+ bit % 2 ? "in":"out");
2560
+ }
2561
+ return str;
2562
+}
2563
+
2564
+static inline const char *xhci_decode_slot_context(char *str,
2565
+ u32 info, u32 info2, u32 tt_info, u32 state)
2566
+{
24392567 u32 speed;
24402568 u32 hub;
24412569 u32 mtt;
....@@ -2519,9 +2647,8 @@
25192647 return "Unknown";
25202648 }
25212649
2522
-static inline const char *xhci_decode_portsc(u32 portsc)
2650
+static inline const char *xhci_decode_portsc(char *str, u32 portsc)
25232651 {
2524
- static char str[256];
25252652 int ret;
25262653
25272654 ret = sprintf(str, "%s %s %s Link:%s PortSpeed:%d ",
....@@ -2561,6 +2688,65 @@
25612688 ret += sprintf(str + ret, "WDE ");
25622689 if (portsc & PORT_WKOC_E)
25632690 ret += sprintf(str + ret, "WOE ");
2691
+
2692
+ return str;
2693
+}
2694
+
2695
+static inline const char *xhci_decode_usbsts(char *str, u32 usbsts)
2696
+{
2697
+ int ret = 0;
2698
+
2699
+ ret = sprintf(str, " 0x%08x", usbsts);
2700
+
2701
+ if (usbsts == ~(u32)0)
2702
+ return str;
2703
+
2704
+ if (usbsts & STS_HALT)
2705
+ ret += sprintf(str + ret, " HCHalted");
2706
+ if (usbsts & STS_FATAL)
2707
+ ret += sprintf(str + ret, " HSE");
2708
+ if (usbsts & STS_EINT)
2709
+ ret += sprintf(str + ret, " EINT");
2710
+ if (usbsts & STS_PORT)
2711
+ ret += sprintf(str + ret, " PCD");
2712
+ if (usbsts & STS_SAVE)
2713
+ ret += sprintf(str + ret, " SSS");
2714
+ if (usbsts & STS_RESTORE)
2715
+ ret += sprintf(str + ret, " RSS");
2716
+ if (usbsts & STS_SRE)
2717
+ ret += sprintf(str + ret, " SRE");
2718
+ if (usbsts & STS_CNR)
2719
+ ret += sprintf(str + ret, " CNR");
2720
+ if (usbsts & STS_HCE)
2721
+ ret += sprintf(str + ret, " HCE");
2722
+
2723
+ return str;
2724
+}
2725
+
2726
+static inline const char *xhci_decode_doorbell(char *str, u32 slot, u32 doorbell)
2727
+{
2728
+ u8 ep;
2729
+ u16 stream;
2730
+ int ret;
2731
+
2732
+ ep = (doorbell & 0xff);
2733
+ stream = doorbell >> 16;
2734
+
2735
+ if (slot == 0) {
2736
+ sprintf(str, "Command Ring %d", doorbell);
2737
+ return str;
2738
+ }
2739
+ ret = sprintf(str, "Slot %d ", slot);
2740
+ if (ep > 0 && ep < 32)
2741
+ ret = sprintf(str + ret, "ep%d%s",
2742
+ ep / 2,
2743
+ ep % 2 ? "in" : "out");
2744
+ else if (ep == 0 || ep < 248)
2745
+ ret = sprintf(str + ret, "Reserved %d", ep);
2746
+ else
2747
+ ret = sprintf(str + ret, "Vendor Defined %d", ep);
2748
+ if (stream)
2749
+ ret = sprintf(str + ret, " Stream %d", stream);
25642750
25652751 return str;
25662752 }
....@@ -2605,10 +2791,9 @@
26052791 }
26062792 }
26072793
2608
-static inline const char *xhci_decode_ep_context(u32 info, u32 info2, u64 deq,
2609
- u32 tx_info)
2794
+static inline const char *xhci_decode_ep_context(char *str, u32 info,
2795
+ u32 info2, u64 deq, u32 tx_info)
26102796 {
2611
- static char str[1024];
26122797 int ret;
26132798
26142799 u32 esit;