22
22
#include "xhci-ext-caps.h"
23
23
#include "pci-quirks.h"
24
24
25
+ /* max buffer size for trace and debug messages */
26
+ #define XHCI_MSG_MAX 500
27
+
25
28
/* xHCI PCI Configuration Registers */
26
29
#define XHCI_SBRN_OFFSET (0x60)
27
30
@@ -2235,15 +2238,14 @@ static inline char *xhci_slot_state_string(u32 state)
2235
2238
}
2236
2239
}
2237
2240
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 )
2240
2243
{
2241
- static char str [256 ];
2242
2244
int type = TRB_FIELD_TO_TYPE (field3 );
2243
2245
2244
2246
switch (type ) {
2245
2247
case TRB_LINK :
2246
- sprintf (str ,
2248
+ snprintf (str , size ,
2247
2249
"LINK %08x%08x intr %d type '%s' flags %c:%c:%c:%c" ,
2248
2250
field1 , field0 , GET_INTR_TARGET (field2 ),
2249
2251
xhci_trb_type_string (type ),
@@ -2260,7 +2262,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2260
2262
case TRB_HC_EVENT :
2261
2263
case TRB_DEV_NOTE :
2262
2264
case TRB_MFINDEX_WRAP :
2263
- sprintf (str ,
2265
+ snprintf (str , size ,
2264
2266
"TRB %08x%08x status '%s' len %d slot %d ep %d type '%s' flags %c:%c" ,
2265
2267
field1 , field0 ,
2266
2268
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,
2273
2275
2274
2276
break ;
2275
2277
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" ,
2277
2280
field0 & 0xff ,
2278
2281
(field0 & 0xff00 ) >> 8 ,
2279
2282
(field0 & 0xff000000 ) >> 24 ,
@@ -2290,7 +2293,8 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2290
2293
field3 & TRB_CYCLE ? 'C' : 'c' );
2291
2294
break ;
2292
2295
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" ,
2294
2298
field1 , field0 , TRB_LEN (field2 ), GET_TD_SIZE (field2 ),
2295
2299
GET_INTR_TARGET (field2 ),
2296
2300
xhci_trb_type_string (type ),
@@ -2303,7 +2307,8 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2303
2307
field3 & TRB_CYCLE ? 'C' : 'c' );
2304
2308
break ;
2305
2309
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" ,
2307
2312
field1 , field0 , TRB_LEN (field2 ), GET_TD_SIZE (field2 ),
2308
2313
GET_INTR_TARGET (field2 ),
2309
2314
xhci_trb_type_string (type ),
@@ -2316,7 +2321,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2316
2321
case TRB_ISOC :
2317
2322
case TRB_EVENT_DATA :
2318
2323
case TRB_TR_NOOP :
2319
- sprintf (str ,
2324
+ snprintf (str , size ,
2320
2325
"Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c:%c" ,
2321
2326
field1 , field0 , TRB_LEN (field2 ), GET_TD_SIZE (field2 ),
2322
2327
GET_INTR_TARGET (field2 ),
@@ -2333,21 +2338,21 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2333
2338
2334
2339
case TRB_CMD_NOOP :
2335
2340
case TRB_ENABLE_SLOT :
2336
- sprintf (str ,
2341
+ snprintf (str , size ,
2337
2342
"%s: flags %c" ,
2338
2343
xhci_trb_type_string (type ),
2339
2344
field3 & TRB_CYCLE ? 'C' : 'c' );
2340
2345
break ;
2341
2346
case TRB_DISABLE_SLOT :
2342
2347
case TRB_NEG_BANDWIDTH :
2343
- sprintf (str ,
2348
+ snprintf (str , size ,
2344
2349
"%s: slot %d flags %c" ,
2345
2350
xhci_trb_type_string (type ),
2346
2351
TRB_TO_SLOT_ID (field3 ),
2347
2352
field3 & TRB_CYCLE ? 'C' : 'c' );
2348
2353
break ;
2349
2354
case TRB_ADDR_DEV :
2350
- sprintf (str ,
2355
+ snprintf (str , size ,
2351
2356
"%s: ctx %08x%08x slot %d flags %c:%c" ,
2352
2357
xhci_trb_type_string (type ),
2353
2358
field1 , field0 ,
@@ -2356,7 +2361,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2356
2361
field3 & TRB_CYCLE ? 'C' : 'c' );
2357
2362
break ;
2358
2363
case TRB_CONFIG_EP :
2359
- sprintf (str ,
2364
+ snprintf (str , size ,
2360
2365
"%s: ctx %08x%08x slot %d flags %c:%c" ,
2361
2366
xhci_trb_type_string (type ),
2362
2367
field1 , field0 ,
@@ -2365,15 +2370,15 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2365
2370
field3 & TRB_CYCLE ? 'C' : 'c' );
2366
2371
break ;
2367
2372
case TRB_EVAL_CONTEXT :
2368
- sprintf (str ,
2373
+ snprintf (str , size ,
2369
2374
"%s: ctx %08x%08x slot %d flags %c" ,
2370
2375
xhci_trb_type_string (type ),
2371
2376
field1 , field0 ,
2372
2377
TRB_TO_SLOT_ID (field3 ),
2373
2378
field3 & TRB_CYCLE ? 'C' : 'c' );
2374
2379
break ;
2375
2380
case TRB_RESET_EP :
2376
- sprintf (str ,
2381
+ snprintf (str , size ,
2377
2382
"%s: ctx %08x%08x slot %d ep %d flags %c:%c" ,
2378
2383
xhci_trb_type_string (type ),
2379
2384
field1 , field0 ,
@@ -2394,7 +2399,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2394
2399
field3 & TRB_CYCLE ? 'C' : 'c' );
2395
2400
break ;
2396
2401
case TRB_SET_DEQ :
2397
- sprintf (str ,
2402
+ snprintf (str , size ,
2398
2403
"%s: deq %08x%08x stream %d slot %d ep %d flags %c" ,
2399
2404
xhci_trb_type_string (type ),
2400
2405
field1 , field0 ,
@@ -2405,14 +2410,14 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2405
2410
field3 & TRB_CYCLE ? 'C' : 'c' );
2406
2411
break ;
2407
2412
case TRB_RESET_DEV :
2408
- sprintf (str ,
2413
+ snprintf (str , size ,
2409
2414
"%s: slot %d flags %c" ,
2410
2415
xhci_trb_type_string (type ),
2411
2416
TRB_TO_SLOT_ID (field3 ),
2412
2417
field3 & TRB_CYCLE ? 'C' : 'c' );
2413
2418
break ;
2414
2419
case TRB_FORCE_EVENT :
2415
- sprintf (str ,
2420
+ snprintf (str , size ,
2416
2421
"%s: event %08x%08x vf intr %d vf id %d flags %c" ,
2417
2422
xhci_trb_type_string (type ),
2418
2423
field1 , field0 ,
@@ -2421,14 +2426,14 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2421
2426
field3 & TRB_CYCLE ? 'C' : 'c' );
2422
2427
break ;
2423
2428
case TRB_SET_LT :
2424
- sprintf (str ,
2429
+ snprintf (str , size ,
2425
2430
"%s: belt %d flags %c" ,
2426
2431
xhci_trb_type_string (type ),
2427
2432
TRB_TO_BELT (field3 ),
2428
2433
field3 & TRB_CYCLE ? 'C' : 'c' );
2429
2434
break ;
2430
2435
case TRB_GET_BW :
2431
- sprintf (str ,
2436
+ snprintf (str , size ,
2432
2437
"%s: ctx %08x%08x slot %d speed %d flags %c" ,
2433
2438
xhci_trb_type_string (type ),
2434
2439
field1 , field0 ,
@@ -2437,7 +2442,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2437
2442
field3 & TRB_CYCLE ? 'C' : 'c' );
2438
2443
break ;
2439
2444
case TRB_FORCE_HEADER :
2440
- sprintf (str ,
2445
+ snprintf (str , size ,
2441
2446
"%s: info %08x%08x%08x pkt type %d roothub port %d flags %c" ,
2442
2447
xhci_trb_type_string (type ),
2443
2448
field2 , field1 , field0 & 0xffffffe0 ,
@@ -2446,7 +2451,7 @@ static inline const char *xhci_decode_trb(u32 field0, u32 field1, u32 field2,
2446
2451
field3 & TRB_CYCLE ? 'C' : 'c' );
2447
2452
break ;
2448
2453
default :
2449
- sprintf (str ,
2454
+ snprintf (str , size ,
2450
2455
"type '%s' -> raw %08x %08x %08x %08x" ,
2451
2456
xhci_trb_type_string (type ),
2452
2457
field0 , field1 , field2 , field3 );
@@ -2571,9 +2576,8 @@ static inline const char *xhci_portsc_link_state_string(u32 portsc)
2571
2576
return "Unknown" ;
2572
2577
}
2573
2578
2574
- static inline const char * xhci_decode_portsc (u32 portsc )
2579
+ static inline const char * xhci_decode_portsc (char * str , u32 portsc )
2575
2580
{
2576
- static char str [256 ];
2577
2581
int ret ;
2578
2582
2579
2583
ret = sprintf (str , "%s %s %s Link:%s PortSpeed:%d " ,
0 commit comments