@@ -226,18 +226,85 @@ static const struct file_operations rvu_dbg_##name##_fops = { \
226
226
227
227
static void print_nix_qsize (struct seq_file * filp , struct rvu_pfvf * pfvf );
228
228
229
+ static void get_lf_str_list (struct rvu_block block , int pcifunc ,
230
+ char * lfs )
231
+ {
232
+ int lf = 0 , seq = 0 , len = 0 , prev_lf = block .lf .max ;
233
+
234
+ for_each_set_bit (lf , block .lf .bmap , block .lf .max ) {
235
+ if (lf >= block .lf .max )
236
+ break ;
237
+
238
+ if (block .fn_map [lf ] != pcifunc )
239
+ continue ;
240
+
241
+ if (lf == prev_lf + 1 ) {
242
+ prev_lf = lf ;
243
+ seq = 1 ;
244
+ continue ;
245
+ }
246
+
247
+ if (seq )
248
+ len += sprintf (lfs + len , "-%d,%d" , prev_lf , lf );
249
+ else
250
+ len += (len ? sprintf (lfs + len , ",%d" , lf ) :
251
+ sprintf (lfs + len , "%d" , lf ));
252
+
253
+ prev_lf = lf ;
254
+ seq = 0 ;
255
+ }
256
+
257
+ if (seq )
258
+ len += sprintf (lfs + len , "-%d" , prev_lf );
259
+
260
+ lfs [len ] = '\0' ;
261
+ }
262
+
263
+ static int get_max_column_width (struct rvu * rvu )
264
+ {
265
+ int index , pf , vf , lf_str_size = 12 , buf_size = 256 ;
266
+ struct rvu_block block ;
267
+ u16 pcifunc ;
268
+ char * buf ;
269
+
270
+ buf = kzalloc (buf_size , GFP_KERNEL );
271
+ if (!buf )
272
+ return - ENOMEM ;
273
+
274
+ for (pf = 0 ; pf < rvu -> hw -> total_pfs ; pf ++ ) {
275
+ for (vf = 0 ; vf <= rvu -> hw -> total_vfs ; vf ++ ) {
276
+ pcifunc = pf << 10 | vf ;
277
+ if (!pcifunc )
278
+ continue ;
279
+
280
+ for (index = 0 ; index < BLK_COUNT ; index ++ ) {
281
+ block = rvu -> hw -> block [index ];
282
+ if (!strlen (block .name ))
283
+ continue ;
284
+
285
+ get_lf_str_list (block , pcifunc , buf );
286
+ if (lf_str_size <= strlen (buf ))
287
+ lf_str_size = strlen (buf ) + 1 ;
288
+ }
289
+ }
290
+ }
291
+
292
+ kfree (buf );
293
+ return lf_str_size ;
294
+ }
295
+
229
296
/* Dumps current provisioning status of all RVU block LFs */
230
297
static ssize_t rvu_dbg_rsrc_attach_status (struct file * filp ,
231
298
char __user * buffer ,
232
299
size_t count , loff_t * ppos )
233
300
{
234
- int index , off = 0 , flag = 0 , go_back = 0 , len = 0 ;
301
+ int index , off = 0 , flag = 0 , len = 0 , i = 0 ;
235
302
struct rvu * rvu = filp -> private_data ;
236
- int lf , pf , vf , pcifunc ;
303
+ int bytes_not_copied = 0 ;
237
304
struct rvu_block block ;
238
- int bytes_not_copied ;
239
- int lf_str_size = 12 ;
305
+ int pf , vf , pcifunc ;
240
306
int buf_size = 2048 ;
307
+ int lf_str_size ;
241
308
char * lfs ;
242
309
char * buf ;
243
310
@@ -249,6 +316,9 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
249
316
if (!buf )
250
317
return - ENOSPC ;
251
318
319
+ /* Get the maximum width of a column */
320
+ lf_str_size = get_max_column_width (rvu );
321
+
252
322
lfs = kzalloc (lf_str_size , GFP_KERNEL );
253
323
if (!lfs ) {
254
324
kfree (buf );
@@ -262,65 +332,69 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
262
332
"%-*s" , lf_str_size ,
263
333
rvu -> hw -> block [index ].name );
264
334
}
335
+
265
336
off += scnprintf (& buf [off ], buf_size - 1 - off , "\n" );
337
+ bytes_not_copied = copy_to_user (buffer + (i * off ), buf , off );
338
+ if (bytes_not_copied )
339
+ goto out ;
340
+
341
+ i ++ ;
342
+ * ppos += off ;
266
343
for (pf = 0 ; pf < rvu -> hw -> total_pfs ; pf ++ ) {
267
344
for (vf = 0 ; vf <= rvu -> hw -> total_vfs ; vf ++ ) {
345
+ off = 0 ;
346
+ flag = 0 ;
268
347
pcifunc = pf << 10 | vf ;
269
348
if (!pcifunc )
270
349
continue ;
271
350
272
351
if (vf ) {
273
352
sprintf (lfs , "PF%d:VF%d" , pf , vf - 1 );
274
- go_back = scnprintf (& buf [off ],
275
- buf_size - 1 - off ,
276
- "%-*s" , lf_str_size , lfs );
353
+ off = scnprintf (& buf [off ],
354
+ buf_size - 1 - off ,
355
+ "%-*s" , lf_str_size , lfs );
277
356
} else {
278
357
sprintf (lfs , "PF%d" , pf );
279
- go_back = scnprintf (& buf [off ],
280
- buf_size - 1 - off ,
281
- "%-*s" , lf_str_size , lfs );
358
+ off = scnprintf (& buf [off ],
359
+ buf_size - 1 - off ,
360
+ "%-*s" , lf_str_size , lfs );
282
361
}
283
362
284
- off += go_back ;
285
- for (index = 0 ; index < BLKTYPE_MAX ; index ++ ) {
363
+ for (index = 0 ; index < BLK_COUNT ; index ++ ) {
286
364
block = rvu -> hw -> block [index ];
287
365
if (!strlen (block .name ))
288
366
continue ;
289
367
len = 0 ;
290
368
lfs [len ] = '\0' ;
291
- for (lf = 0 ; lf < block .lf .max ; lf ++ ) {
292
- if (block .fn_map [lf ] != pcifunc )
293
- continue ;
369
+ get_lf_str_list (block , pcifunc , lfs );
370
+ if (strlen (lfs ))
294
371
flag = 1 ;
295
- len += sprintf (& lfs [len ], "%d," , lf );
296
- }
297
372
298
- if (flag )
299
- len -- ;
300
- lfs [len ] = '\0' ;
301
373
off += scnprintf (& buf [off ], buf_size - 1 - off ,
302
374
"%-*s" , lf_str_size , lfs );
303
- if (!strlen (lfs ))
304
- go_back += lf_str_size ;
305
375
}
306
- if (!flag )
307
- off -= go_back ;
308
- else
309
- flag = 0 ;
310
- off -- ;
311
- off += scnprintf (& buf [off ], buf_size - 1 - off , "\n" );
376
+ if (flag ) {
377
+ off += scnprintf (& buf [off ],
378
+ buf_size - 1 - off , "\n" );
379
+ bytes_not_copied = copy_to_user (buffer +
380
+ (i * off ),
381
+ buf , off );
382
+ if (bytes_not_copied )
383
+ goto out ;
384
+
385
+ i ++ ;
386
+ * ppos += off ;
387
+ }
312
388
}
313
389
}
314
390
315
- bytes_not_copied = copy_to_user ( buffer , buf , off );
391
+ out :
316
392
kfree (lfs );
317
393
kfree (buf );
318
-
319
394
if (bytes_not_copied )
320
395
return - EFAULT ;
321
396
322
- * ppos = off ;
323
- return off ;
397
+ return * ppos ;
324
398
}
325
399
326
400
RVU_DEBUG_FOPS (rsrc_status , rsrc_attach_status , NULL );
@@ -504,7 +578,7 @@ static ssize_t rvu_dbg_qsize_write(struct file *filp,
504
578
if (cmd_buf )
505
579
ret = - EINVAL ;
506
580
507
- if (!strncmp (subtoken , "help" , 4 ) || ret < 0 ) {
581
+ if (ret < 0 || !strncmp (subtoken , "help" , 4 )) {
508
582
dev_info (rvu -> dev , "Use echo <%s-lf > qsize\n" , blk_string );
509
583
goto qsize_write_done ;
510
584
}
@@ -1719,6 +1793,10 @@ static int rvu_dbg_nix_band_prof_ctx_display(struct seq_file *m, void *unused)
1719
1793
u16 pcifunc ;
1720
1794
char * str ;
1721
1795
1796
+ /* Ingress policers do not exist on all platforms */
1797
+ if (!nix_hw -> ipolicer )
1798
+ return 0 ;
1799
+
1722
1800
for (layer = 0 ; layer < BAND_PROF_NUM_LAYERS ; layer ++ ) {
1723
1801
if (layer == BAND_PROF_INVAL_LAYER )
1724
1802
continue ;
@@ -1768,6 +1846,10 @@ static int rvu_dbg_nix_band_prof_rsrc_display(struct seq_file *m, void *unused)
1768
1846
int layer ;
1769
1847
char * str ;
1770
1848
1849
+ /* Ingress policers do not exist on all platforms */
1850
+ if (!nix_hw -> ipolicer )
1851
+ return 0 ;
1852
+
1771
1853
seq_puts (m , "\nBandwidth profile resource free count\n" );
1772
1854
seq_puts (m , "=====================================\n" );
1773
1855
for (layer = 0 ; layer < BAND_PROF_NUM_LAYERS ; layer ++ ) {
0 commit comments