Skip to content

Commit e77bcdd

Browse files
Rakesh Babudavem330
authored andcommitted
octeontx2-af: Display all enabled PF VF rsrc_alloc entries.
Currently, we are using a fixed buffer size of length 2048 to display rsrc_alloc output. As a result a maximum of 2048 characters of rsrc_alloc output is displayed, which may lead sometimes to display only partial output. This patch fixes this dependency on max limit of buffer size and displays all PF VF entries. Each column of the debugfs entry "rsrc_alloc" uses a fixed width of 12 characters to print the list of LFs of each block for a PF/VF. If the length of list of LFs of a block exceeds this fixed width then the list gets truncated and displays only a part of the list. This patch fixes this by using the maximum possible length of list of LFs among all blocks of all PFs and VFs entries as the width size. Fixes: f788409 ("octeontx2-af: Formatting debugfs entry rsrc_alloc.") Fixes: 23205e6 ("octeontx2-af: Dump current resource provisioning status") Signed-off-by: Rakesh Babu <[email protected]> Signed-off-by: Nithin Dabilpuram <[email protected]> Signed-off-by: Sunil Kovvuri Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cc45b96 commit e77bcdd

File tree

1 file changed

+106
-32
lines changed

1 file changed

+106
-32
lines changed

drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c

Lines changed: 106 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,85 @@ static const struct file_operations rvu_dbg_##name##_fops = { \
226226

227227
static void print_nix_qsize(struct seq_file *filp, struct rvu_pfvf *pfvf);
228228

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+
229296
/* Dumps current provisioning status of all RVU block LFs */
230297
static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
231298
char __user *buffer,
232299
size_t count, loff_t *ppos)
233300
{
234-
int index, off = 0, flag = 0, go_back = 0, len = 0;
301+
int index, off = 0, flag = 0, len = 0, i = 0;
235302
struct rvu *rvu = filp->private_data;
236-
int lf, pf, vf, pcifunc;
303+
int bytes_not_copied = 0;
237304
struct rvu_block block;
238-
int bytes_not_copied;
239-
int lf_str_size = 12;
305+
int pf, vf, pcifunc;
240306
int buf_size = 2048;
307+
int lf_str_size;
241308
char *lfs;
242309
char *buf;
243310

@@ -249,6 +316,9 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
249316
if (!buf)
250317
return -ENOSPC;
251318

319+
/* Get the maximum width of a column */
320+
lf_str_size = get_max_column_width(rvu);
321+
252322
lfs = kzalloc(lf_str_size, GFP_KERNEL);
253323
if (!lfs) {
254324
kfree(buf);
@@ -262,65 +332,69 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
262332
"%-*s", lf_str_size,
263333
rvu->hw->block[index].name);
264334
}
335+
265336
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;
266343
for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
267344
for (vf = 0; vf <= rvu->hw->total_vfs; vf++) {
345+
off = 0;
346+
flag = 0;
268347
pcifunc = pf << 10 | vf;
269348
if (!pcifunc)
270349
continue;
271350

272351
if (vf) {
273352
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);
277356
} else {
278357
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);
282361
}
283362

284-
off += go_back;
285-
for (index = 0; index < BLKTYPE_MAX; index++) {
363+
for (index = 0; index < BLK_COUNT; index++) {
286364
block = rvu->hw->block[index];
287365
if (!strlen(block.name))
288366
continue;
289367
len = 0;
290368
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))
294371
flag = 1;
295-
len += sprintf(&lfs[len], "%d,", lf);
296-
}
297372

298-
if (flag)
299-
len--;
300-
lfs[len] = '\0';
301373
off += scnprintf(&buf[off], buf_size - 1 - off,
302374
"%-*s", lf_str_size, lfs);
303-
if (!strlen(lfs))
304-
go_back += lf_str_size;
305375
}
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+
}
312388
}
313389
}
314390

315-
bytes_not_copied = copy_to_user(buffer, buf, off);
391+
out:
316392
kfree(lfs);
317393
kfree(buf);
318-
319394
if (bytes_not_copied)
320395
return -EFAULT;
321396

322-
*ppos = off;
323-
return off;
397+
return *ppos;
324398
}
325399

326400
RVU_DEBUG_FOPS(rsrc_status, rsrc_attach_status, NULL);

0 commit comments

Comments
 (0)