2222#include "xhci-ext-caps.h"
2323#include "pci-quirks.h"
2424
25+ /* max buffer size for trace and debug messages */
26+ #define XHCI_MSG_MAX 500
27+
2528/* xHCI PCI Configuration Registers */
2629#define XHCI_SBRN_OFFSET (0x60)
2730
@@ -2235,15 +2238,14 @@ static inline char *xhci_slot_state_string(u32 state)
22352238 }
22362239}
22372240
2238- static inline const char * xhci_decode_trb (u32 field0 , u32 field1 , u32 field2 ,
2239- u32 field3 )
2241+ static inline const char * xhci_decode_trb (char * str , size_t size ,
2242+ u32 field0 , u32 field1 , u32 field2 , u32 field3 )
22402243{
2241- static char str [256 ];
22422244 int type = TRB_FIELD_TO_TYPE (field3 );
22432245
22442246 switch (type ) {
22452247 case TRB_LINK :
2246- sprintf (str ,
2248+ snprintf (str , size ,
22472249 "LINK %08x%08x intr %d type '%s' flags %c:%c:%c:%c" ,
22482250 field1 , field0 , GET_INTR_TARGET (field2 ),
22492251 xhci_trb_type_string (type ),
@@ -2260,7 +2262,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
22602262 case TRB_HC_EVENT :
22612263 case TRB_DEV_NOTE :
22622264 case TRB_MFINDEX_WRAP :
2263- sprintf (str ,
2265+ snprintf (str , size ,
22642266 "TRB %08x%08x status '%s' len %d slot %d ep %d type '%s' flags %c:%c" ,
22652267 field1 , field0 ,
22662268 xhci_trb_comp_code_string (GET_COMP_CODE (field2 )),
@@ -2273,7 +2275,8 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
22732275
22742276 break ;
22752277 case TRB_SETUP :
2276- 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" ,
2278+ snprintf (str , size ,
2279+ "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" ,
22772280 field0 & 0xff ,
22782281 (field0 & 0xff00 ) >> 8 ,
22792282 (field0 & 0xff000000 ) >> 24 ,
@@ -2290,7 +2293,8 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
22902293 field3 & TRB_CYCLE ? 'C' : 'c' );
22912294 break ;
22922295 case TRB_DATA :
2293- sprintf (str , "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c" ,
2296+ snprintf (str , size ,
2297+ "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c" ,
22942298 field1 , field0 , TRB_LEN (field2 ), GET_TD_SIZE (field2 ),
22952299 GET_INTR_TARGET (field2 ),
22962300 xhci_trb_type_string (type ),
@@ -2303,7 +2307,8 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
23032307 field3 & TRB_CYCLE ? 'C' : 'c' );
23042308 break ;
23052309 case TRB_STATUS :
2306- sprintf (str , "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c" ,
2310+ snprintf (str , size ,
2311+ "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c" ,
23072312 field1 , field0 , TRB_LEN (field2 ), GET_TD_SIZE (field2 ),
23082313 GET_INTR_TARGET (field2 ),
23092314 xhci_trb_type_string (type ),
@@ -2316,7 +2321,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
23162321 case TRB_ISOC :
23172322 case TRB_EVENT_DATA :
23182323 case TRB_TR_NOOP :
2319- sprintf (str ,
2324+ snprintf (str , size ,
23202325 "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c:%c" ,
23212326 field1 , field0 , TRB_LEN (field2 ), GET_TD_SIZE (field2 ),
23222327 GET_INTR_TARGET (field2 ),
@@ -2333,21 +2338,21 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
23332338
23342339 case TRB_CMD_NOOP :
23352340 case TRB_ENABLE_SLOT :
2336- sprintf (str ,
2341+ snprintf (str , size ,
23372342 "%s: flags %c" ,
23382343 xhci_trb_type_string (type ),
23392344 field3 & TRB_CYCLE ? 'C' : 'c' );
23402345 break ;
23412346 case TRB_DISABLE_SLOT :
23422347 case TRB_NEG_BANDWIDTH :
2343- sprintf (str ,
2348+ snprintf (str , size ,
23442349 "%s: slot %d flags %c" ,
23452350 xhci_trb_type_string (type ),
23462351 TRB_TO_SLOT_ID (field3 ),
23472352 field3 & TRB_CYCLE ? 'C' : 'c' );
23482353 break ;
23492354 case TRB_ADDR_DEV :
2350- sprintf (str ,
2355+ snprintf (str , size ,
23512356 "%s: ctx %08x%08x slot %d flags %c:%c" ,
23522357 xhci_trb_type_string (type ),
23532358 field1 , field0 ,
@@ -2356,7 +2361,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
23562361 field3 & TRB_CYCLE ? 'C' : 'c' );
23572362 break ;
23582363 case TRB_CONFIG_EP :
2359- sprintf (str ,
2364+ snprintf (str , size ,
23602365 "%s: ctx %08x%08x slot %d flags %c:%c" ,
23612366 xhci_trb_type_string (type ),
23622367 field1 , field0 ,
@@ -2365,15 +2370,15 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
23652370 field3 & TRB_CYCLE ? 'C' : 'c' );
23662371 break ;
23672372 case TRB_EVAL_CONTEXT :
2368- sprintf (str ,
2373+ snprintf (str , size ,
23692374 "%s: ctx %08x%08x slot %d flags %c" ,
23702375 xhci_trb_type_string (type ),
23712376 field1 , field0 ,
23722377 TRB_TO_SLOT_ID (field3 ),
23732378 field3 & TRB_CYCLE ? 'C' : 'c' );
23742379 break ;
23752380 case TRB_RESET_EP :
2376- sprintf (str ,
2381+ snprintf (str , size ,
23772382 "%s: ctx %08x%08x slot %d ep %d flags %c:%c" ,
23782383 xhci_trb_type_string (type ),
23792384 field1 , field0 ,
@@ -2394,7 +2399,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
23942399 field3 & TRB_CYCLE ? 'C' : 'c' );
23952400 break ;
23962401 case TRB_SET_DEQ :
2397- sprintf (str ,
2402+ snprintf (str , size ,
23982403 "%s: deq %08x%08x stream %d slot %d ep %d flags %c" ,
23992404 xhci_trb_type_string (type ),
24002405 field1 , field0 ,
@@ -2405,14 +2410,14 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
24052410 field3 & TRB_CYCLE ? 'C' : 'c' );
24062411 break ;
24072412 case TRB_RESET_DEV :
2408- sprintf (str ,
2413+ snprintf (str , size ,
24092414 "%s: slot %d flags %c" ,
24102415 xhci_trb_type_string (type ),
24112416 TRB_TO_SLOT_ID (field3 ),
24122417 field3 & TRB_CYCLE ? 'C' : 'c' );
24132418 break ;
24142419 case TRB_FORCE_EVENT :
2415- sprintf (str ,
2420+ snprintf (str , size ,
24162421 "%s: event %08x%08x vf intr %d vf id %d flags %c" ,
24172422 xhci_trb_type_string (type ),
24182423 field1 , field0 ,
@@ -2421,14 +2426,14 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
24212426 field3 & TRB_CYCLE ? 'C' : 'c' );
24222427 break ;
24232428 case TRB_SET_LT :
2424- sprintf (str ,
2429+ snprintf (str , size ,
24252430 "%s: belt %d flags %c" ,
24262431 xhci_trb_type_string (type ),
24272432 TRB_TO_BELT (field3 ),
24282433 field3 & TRB_CYCLE ? 'C' : 'c' );
24292434 break ;
24302435 case TRB_GET_BW :
2431- sprintf (str ,
2436+ snprintf (str , size ,
24322437 "%s: ctx %08x%08x slot %d speed %d flags %c" ,
24332438 xhci_trb_type_string (type ),
24342439 field1 , field0 ,
@@ -2437,7 +2442,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
24372442 field3 & TRB_CYCLE ? 'C' : 'c' );
24382443 break ;
24392444 case TRB_FORCE_HEADER :
2440- sprintf (str ,
2445+ snprintf (str , size ,
24412446 "%s: info %08x%08x%08x pkt type %d roothub port %d flags %c" ,
24422447 xhci_trb_type_string (type ),
24432448 field2 , field1 , field0 & 0xffffffe0 ,
@@ -2446,7 +2451,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
24462451 field3 & TRB_CYCLE ? 'C' : 'c' );
24472452 break ;
24482453 default :
2449- sprintf (str ,
2454+ snprintf (str , size ,
24502455 "type '%s' -> raw %08x %08x %08x %08x" ,
24512456 xhci_trb_type_string (type ),
24522457 field0 , field1 , field2 , field3 );
@@ -2571,9 +2576,8 @@ static inline const char *xhci_portsc_link_state_string(u32 portsc)
25712576 return "Unknown" ;
25722577}
25732578
2574- static inline const char * xhci_decode_portsc (u32 portsc )
2579+ static inline const char * xhci_decode_portsc (char * str , u32 portsc )
25752580{
2576- static char str [256 ];
25772581 int ret ;
25782582
25792583 ret = sprintf (str , "%s %s %s Link:%s PortSpeed:%d " ,
0 commit comments