public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli•us>
To: netdev@vger•kernel.org
Cc: davem@davemloft•net, arkadis@mellanox•com, idosch@mellanox•com,
	mlxsw@mellanox•com, jhs@mojatatu•com, ivecera@redhat•com,
	roopa@cumulusnetworks•com, f.fainelli@gmail•com,
	vivien.didelot@savoirfairelinux•com, john.fastabend@gmail•com,
	andrew@lunn•ch
Subject: [patch net-next RFC 8/8] mlxsw: spectrum: Add Support for erif table entries access
Date: Thu, 16 Feb 2017 16:22:44 +0100	[thread overview]
Message-ID: <1487258564-3775-9-git-send-email-jiri@resnulli.us> (raw)
In-Reply-To: <1487258564-3775-1-git-send-email-jiri@resnulli.us>

From: Arkadi Sharshevsky <arkadis@mellanox•com>

Implement dpipe's table ops for erif table which provide:
1. Getting the entries in the table with the associate values.
	- match on "mlxsw_meta:erif_index"
	- action on "mlxsw_meta:forwared_out"
2. Synchronize the hardware in case of enabling/disabling counters which
   mean removing erif counters from all interfaces.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox•com>
Signed-off-by: Jiri Pirko <jiri@mellanox•com>
---
 .../net/ethernet/mellanox/mlxsw/spectrum_dpipe.c   | 167 ++++++++++++++++++++-
 1 file changed, 166 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
index 41e8e33..a7eebee 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
@@ -100,7 +100,172 @@ static struct devlink_dpipe_hfield mlxsw_sp_dpipe_actions_erif[] = {
 	},
 };
 
-static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {};
+static void mlxsw_sp_erif_entry_clear(struct devlink_dpipe_entry *entry)
+{
+	struct devlink_dpipe_hfield_val *val;
+	unsigned int val_count, val_index;
+
+	val = entry->actions;
+	val_count = entry->actions_count;
+	for (val_index = 0; val_index < val_count; val_index++) {
+		kfree(val[val_index].value);
+		kfree(val[val_index].mask);
+	}
+
+	val = entry->matches;
+	val_count = entry->matches_count;
+	for (val_index = 0; val_index < val_count; val_index++) {
+		kfree(val[val_index].value);
+		kfree(val[val_index].mask);
+	}
+}
+
+static int mlxsw_sp_erif_entry_get(struct mlxsw_sp *mlxsw_sp,
+				   struct devlink_dpipe_entry *entry,
+				   struct mlxsw_sp_rif *r,
+				   bool counters_enabled)
+{
+	u32 *action_value;
+	u32 *rif_value;
+	u64 cnt;
+	int err;
+
+	/* Set Match RIF index */
+	rif_value = entry->matches->value;
+	*rif_value = r->rif;
+	entry->matches->mapping_value = r->dev->ifindex;
+
+	/* Set Action Forwarding */
+	action_value = entry->actions->value;
+	*action_value = 1;
+
+	entry->counter_valid = false;
+	entry->counter = 0;
+	if (!counters_enabled)
+		return 0;
+
+	entry->index = r->rif;
+	err = mlxsw_sp_rif_counter_value_get(mlxsw_sp, r,
+					     MLXSW_SP_RIF_COUNTER_EGRESS,
+					     &cnt);
+	if (!err) {
+		entry->counter = cnt;
+		entry->counter_valid = true;
+	}
+	return 0;
+}
+
+static int mlxsw_sp_erif_entry_prepare(struct devlink_dpipe_entry *entry,
+				       struct devlink_dpipe_hfield_val *match,
+				       struct devlink_dpipe_hfield_val *action)
+{
+	entry->matches = match;
+	entry->matches_count = 1;
+
+	entry->actions = action;
+	entry->actions_count = 1;
+
+	match->hfield = mlxsw_sp_dpipe_matches_erif;
+	match->value_size = sizeof(u32);
+	match->value = kmalloc(match->value_size, GFP_KERNEL);
+	if (!match->value)
+		return -ENOMEM;
+
+	action->hfield = &mlxsw_sp_dpipe_actions_erif[MLXSW_SP_DPIPE_TABLE_ERIF_ACTION_FOWARD];
+	action->value_size = sizeof(u32);
+	action->value = kmalloc(action->value_size, GFP_KERNEL);
+	if (!action->value)
+		goto err_action_alloc;
+	return 0;
+
+err_action_alloc:
+	kfree(match->value);
+	return -ENOMEM;
+}
+
+static int mlxsw_sp_table_erif_entries_dump(void *priv, bool counters_enabled,
+					    struct devlink_dpipe_dump_ctx *
+					    dump_ctx)
+{
+	struct devlink_dpipe_hfield_val match = {0}, action = {0};
+	struct devlink_dpipe_entry entry = {0};
+	struct mlxsw_sp *mlxsw_sp = priv;
+	unsigned int rif_count;
+	int i, j;
+	int err;
+
+	err = mlxsw_sp_erif_entry_prepare(&entry, &match, &action);
+	if (err)
+		return err;
+
+	rif_count = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
+	rtnl_lock();
+	i = 0;
+start_again:
+	err = devlink_dpipe_entry_prepare_ctx(dump_ctx);
+	if (err)
+		return err;
+	j = 0;
+	for (; i < rif_count; i++) {
+		if (!mlxsw_sp->rifs[i])
+			continue;
+		err = mlxsw_sp_erif_entry_get(mlxsw_sp, &entry,
+					      mlxsw_sp->rifs[i],
+					      counters_enabled);
+		if (err)
+			goto err_entry_get;
+		err = devlink_dpipe_entry_append_ctx(dump_ctx, &entry);
+		if (err) {
+			if (err == -EMSGSIZE) {
+				if (!j)
+					goto err_entry_append;
+				break;
+			}
+			goto err_entry_append;
+		}
+		j++;
+	}
+
+	devlink_dpipe_entry_close_ctx(dump_ctx);
+	if (i != rif_count)
+		goto start_again;
+	rtnl_unlock();
+
+	mlxsw_sp_erif_entry_clear(&entry);
+	return 0;
+err_entry_append:
+err_entry_get:
+	rtnl_unlock();
+	mlxsw_sp_erif_entry_clear(&entry);
+	return err;
+}
+
+static int mlxsw_sp_table_erif_counter_update(void *priv, bool enable)
+{
+	struct mlxsw_sp *mlxsw_sp = priv;
+	int i;
+
+	rtnl_lock();
+	for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); i++) {
+		if (!mlxsw_sp->rifs[i])
+			continue;
+		if (enable)
+			mlxsw_sp_rif_counter_alloc(mlxsw_sp,
+						   mlxsw_sp->rifs[i],
+						   MLXSW_SP_RIF_COUNTER_EGRESS);
+		else
+			mlxsw_sp_rif_counter_free(mlxsw_sp,
+						  mlxsw_sp->rifs[i],
+						  MLXSW_SP_RIF_COUNTER_EGRESS);
+	}
+	rtnl_unlock();
+	return 0;
+}
+
+static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
+	.entries_dump = mlxsw_sp_table_erif_entries_dump,
+	.counter_set_update = mlxsw_sp_table_erif_counter_update,
+};
 
 int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp)
 {
-- 
2.7.4

  parent reply	other threads:[~2017-02-16 15:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-16 15:22 [patch net-next RFC 0/8] Add support for pipeline debug (dpipe) Jiri Pirko
2017-02-16 15:22 ` [patch net-next RFC 1/8] devlink: Support " Jiri Pirko
2017-02-16 15:57   ` John Fastabend
2017-02-17  8:49   ` Simon Horman
2017-02-18  7:38     ` Jiri Pirko
2017-02-20  8:27       ` Simon Horman
2017-02-16 15:22 ` [patch net-next RFC 2/8] mlxsw: spectrum: Add support for flow counter allocator Jiri Pirko
2017-02-16 15:22 ` [patch net-next RFC 3/8] mlxsw: reg: Add counter fields to RITR register Jiri Pirko
2017-02-16 15:22 ` [patch net-next RFC 4/8] mlxsw: spectrum: Add placeholder for dpipe Jiri Pirko
2017-02-16 15:22 ` [patch net-next RFC 5/8] mlxsw: spectrum: Add definition for egress rif table Jiri Pirko
2017-02-16 15:22 ` [patch net-next RFC 6/8] mlxsw: reg: Add Router Interface Counter Register Jiri Pirko
2017-02-16 15:22 ` [patch net-next RFC 7/8] mlxsw: spectrum: Support for counters on router interfaces Jiri Pirko
2017-02-16 15:22 ` Jiri Pirko [this message]
2017-02-16 15:51 ` [patch net-next RFC 0/8] Add support for pipeline debug (dpipe) John Fastabend
2017-02-16 16:26   ` Jiri Pirko
2017-02-16 16:11 ` Andrew Lunn
2017-02-16 16:20   ` Jiri Pirko
2017-02-16 16:40     ` Andrew Lunn
2017-02-16 16:48       ` Jiri Pirko
2017-02-16 21:20         ` arkadis
2017-02-16 17:04 ` Andrew Lunn
2017-02-16 18:40   ` Jiri Pirko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1487258564-3775-9-git-send-email-jiri@resnulli.us \
    --to=jiri@resnulli$(echo .)us \
    --cc=andrew@lunn$(echo .)ch \
    --cc=arkadis@mellanox$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=f.fainelli@gmail$(echo .)com \
    --cc=idosch@mellanox$(echo .)com \
    --cc=ivecera@redhat$(echo .)com \
    --cc=jhs@mojatatu$(echo .)com \
    --cc=john.fastabend@gmail$(echo .)com \
    --cc=mlxsw@mellanox$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=roopa@cumulusnetworks$(echo .)com \
    --cc=vivien.didelot@savoirfairelinux$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox