Skip to content

Commit 3a79215

Browse files
steen-hegelund-mchpdavem330
authored andcommitted
net: microchip: sparx5: Add VCAP rule debugFS support for the VCAP API
This add support to show all rules in a VCAP instance. The information shown is: - rule id - address range - size - chain id - keyset name, subword size, register span - actionset name, subword size, register span - counter value - sticky bit (one bit width counter) Signed-off-by: Steen Hegelund <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d4134d4 commit 3a79215

File tree

3 files changed

+141
-4
lines changed

3 files changed

+141
-4
lines changed

drivers/net/ethernet/microchip/vcap/vcap_api.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ int vcap_api_check(struct vcap_control *ctrl)
502502
return 0;
503503
}
504504

505-
static void vcap_erase_cache(struct vcap_rule_internal *ri)
505+
void vcap_erase_cache(struct vcap_rule_internal *ri)
506506
{
507507
ri->vctrl->ops->cache_erase(ri->admin);
508508
}
@@ -578,7 +578,7 @@ int vcap_lookup_rule_by_cookie(struct vcap_control *vctrl, u64 cookie)
578578
EXPORT_SYMBOL_GPL(vcap_lookup_rule_by_cookie);
579579

580580
/* Make a shallow copy of the rule without the fields */
581-
static struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri)
581+
struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri)
582582
{
583583
struct vcap_rule_internal *duprule;
584584

@@ -782,9 +782,16 @@ const char *vcap_keyfield_name(struct vcap_control *vctrl,
782782
}
783783
EXPORT_SYMBOL_GPL(vcap_keyfield_name);
784784

785+
/* map actionset id to a string with the actionset name */
786+
const char *vcap_actionset_name(struct vcap_control *vctrl,
787+
enum vcap_actionfield_set actionset)
788+
{
789+
return vctrl->stats->actionfield_set_names[actionset];
790+
}
791+
785792
/* map action field id to a string with the action name */
786-
static const char *vcap_actionfield_name(struct vcap_control *vctrl,
787-
enum vcap_action_field action)
793+
const char *vcap_actionfield_name(struct vcap_control *vctrl,
794+
enum vcap_action_field action)
788795
{
789796
return vctrl->stats->actionfield_names[action];
790797
}

drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,106 @@ static int vcap_addr_keyset(struct vcap_control *vctrl,
234234
admin->cache.maskstream, false, 0);
235235
}
236236

237+
static int vcap_read_rule(struct vcap_rule_internal *ri)
238+
{
239+
struct vcap_admin *admin = ri->admin;
240+
int sw_idx, ent_idx = 0, act_idx = 0;
241+
u32 addr = ri->addr;
242+
243+
if (!ri->size || !ri->keyset_sw_regs || !ri->actionset_sw_regs) {
244+
pr_err("%s:%d: rule is empty\n", __func__, __LINE__);
245+
return -EINVAL;
246+
}
247+
vcap_erase_cache(ri);
248+
/* Use the values in the streams to read the VCAP cache */
249+
for (sw_idx = 0; sw_idx < ri->size; sw_idx++, addr++) {
250+
ri->vctrl->ops->update(ri->ndev, admin, VCAP_CMD_READ,
251+
VCAP_SEL_ALL, addr);
252+
ri->vctrl->ops->cache_read(ri->ndev, admin,
253+
VCAP_SEL_ENTRY, ent_idx,
254+
ri->keyset_sw_regs);
255+
ri->vctrl->ops->cache_read(ri->ndev, admin,
256+
VCAP_SEL_ACTION, act_idx,
257+
ri->actionset_sw_regs);
258+
if (sw_idx == 0)
259+
ri->vctrl->ops->cache_read(ri->ndev, admin,
260+
VCAP_SEL_COUNTER,
261+
ri->counter_id, 0);
262+
ent_idx += ri->keyset_sw_regs;
263+
act_idx += ri->actionset_sw_regs;
264+
}
265+
return 0;
266+
}
267+
268+
static void vcap_show_admin_rule(struct vcap_control *vctrl,
269+
struct vcap_admin *admin,
270+
struct vcap_output_print *out,
271+
struct vcap_rule_internal *ri)
272+
{
273+
ri->counter.value = admin->cache.counter;
274+
ri->counter.sticky = admin->cache.sticky;
275+
out->prf(out->dst,
276+
"rule: %u, addr: [%d,%d], X%d, ctr[%d]: %d, hit: %d\n",
277+
ri->data.id, ri->addr, ri->addr + ri->size - 1, ri->size,
278+
ri->counter_id, ri->counter.value, ri->counter.sticky);
279+
out->prf(out->dst, " chain_id: %d\n", ri->data.vcap_chain_id);
280+
out->prf(out->dst, " user: %d\n", ri->data.user);
281+
out->prf(out->dst, " priority: %d\n", ri->data.priority);
282+
out->prf(out->dst, " keyset: %s\n",
283+
vcap_keyset_name(vctrl, ri->data.keyset));
284+
out->prf(out->dst, " actionset: %s\n",
285+
vcap_actionset_name(vctrl, ri->data.actionset));
286+
}
287+
288+
static void vcap_show_admin_info(struct vcap_control *vctrl,
289+
struct vcap_admin *admin,
290+
struct vcap_output_print *out)
291+
{
292+
const struct vcap_info *vcap = &vctrl->vcaps[admin->vtype];
293+
294+
out->prf(out->dst, "name: %s\n", vcap->name);
295+
out->prf(out->dst, "rows: %d\n", vcap->rows);
296+
out->prf(out->dst, "sw_count: %d\n", vcap->sw_count);
297+
out->prf(out->dst, "sw_width: %d\n", vcap->sw_width);
298+
out->prf(out->dst, "sticky_width: %d\n", vcap->sticky_width);
299+
out->prf(out->dst, "act_width: %d\n", vcap->act_width);
300+
out->prf(out->dst, "default_cnt: %d\n", vcap->default_cnt);
301+
out->prf(out->dst, "require_cnt_dis: %d\n", vcap->require_cnt_dis);
302+
out->prf(out->dst, "version: %d\n", vcap->version);
303+
out->prf(out->dst, "vtype: %d\n", admin->vtype);
304+
out->prf(out->dst, "vinst: %d\n", admin->vinst);
305+
out->prf(out->dst, "first_cid: %d\n", admin->first_cid);
306+
out->prf(out->dst, "last_cid: %d\n", admin->last_cid);
307+
out->prf(out->dst, "lookups: %d\n", admin->lookups);
308+
out->prf(out->dst, "first_valid_addr: %d\n", admin->first_valid_addr);
309+
out->prf(out->dst, "last_valid_addr: %d\n", admin->last_valid_addr);
310+
out->prf(out->dst, "last_used_addr: %d\n", admin->last_used_addr);
311+
}
312+
313+
static int vcap_show_admin(struct vcap_control *vctrl,
314+
struct vcap_admin *admin,
315+
struct vcap_output_print *out)
316+
{
317+
struct vcap_rule_internal *elem, *ri;
318+
int ret = 0;
319+
320+
vcap_show_admin_info(vctrl, admin, out);
321+
list_for_each_entry(elem, &admin->rules, list) {
322+
ri = vcap_dup_rule(elem);
323+
if (IS_ERR(ri))
324+
goto free_rule;
325+
/* Read data from VCAP */
326+
ret = vcap_read_rule(ri);
327+
if (ret)
328+
goto free_rule;
329+
out->prf(out->dst, "\n");
330+
vcap_show_admin_rule(vctrl, admin, out, ri);
331+
free_rule:
332+
vcap_free_rule((struct vcap_rule *)ri);
333+
}
334+
return ret;
335+
}
336+
237337
static int vcap_show_admin_raw(struct vcap_control *vctrl,
238338
struct vcap_admin *admin,
239339
struct vcap_output_print *out)
@@ -313,6 +413,19 @@ void vcap_port_debugfs(struct device *dev, struct dentry *parent,
313413
}
314414
EXPORT_SYMBOL_GPL(vcap_port_debugfs);
315415

416+
/* Show the full VCAP instance data (rules with all fields) */
417+
static int vcap_debugfs_show(struct seq_file *m, void *unused)
418+
{
419+
struct vcap_admin_debugfs_info *info = m->private;
420+
struct vcap_output_print out = {
421+
.prf = (void *)seq_printf,
422+
.dst = m,
423+
};
424+
425+
return vcap_show_admin(info->vctrl, info->admin, &out);
426+
}
427+
DEFINE_SHOW_ATTRIBUTE(vcap_debugfs);
428+
316429
/* Show the raw VCAP instance data (rules with address info) */
317430
static int vcap_raw_debugfs_show(struct seq_file *m, void *unused)
318431
{
@@ -347,6 +460,9 @@ struct dentry *vcap_debugfs(struct device *dev, struct dentry *parent,
347460
info->admin = admin;
348461
debugfs_create_file(name, 0444, dir, info,
349462
&vcap_raw_debugfs_fops);
463+
sprintf(name, "%s_%d", vctrl->vcaps[admin->vtype].name,
464+
admin->vinst);
465+
debugfs_create_file(name, 0444, dir, info, &vcap_debugfs_fops);
350466
}
351467
return dir;
352468
}

drivers/net/ethernet/microchip/vcap/vcap_api_private.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ struct vcap_stream_iter {
4343

4444
/* Check that the control has a valid set of callbacks */
4545
int vcap_api_check(struct vcap_control *ctrl);
46+
/* Make a shallow copy of the rule without the fields */
47+
struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri);
48+
/* Erase the VCAP cache area used or encoding and decoding */
49+
void vcap_erase_cache(struct vcap_rule_internal *ri);
4650

4751
/* Iterator functionality */
4852

@@ -70,4 +74,14 @@ vcap_keyfield_typegroup(struct vcap_control *vctrl,
7074
const struct vcap_field *vcap_keyfields(struct vcap_control *vctrl,
7175
enum vcap_type vt,
7276
enum vcap_keyfield_set keyset);
77+
78+
/* Actionset and actionfield functionality */
79+
80+
/* Map actionset id to a string with the actionset name */
81+
const char *vcap_actionset_name(struct vcap_control *vctrl,
82+
enum vcap_actionfield_set actionset);
83+
/* Map key field id to a string with the key name */
84+
const char *vcap_actionfield_name(struct vcap_control *vctrl,
85+
enum vcap_action_field action);
86+
7387
#endif /* __VCAP_API_PRIVATE__ */

0 commit comments

Comments
 (0)