Commit 9a9f8d1e authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

mlxsw: spectrum_span: Do no expose mirroring agents to entire driver

The struct holding the different mirroring agents is currently allocated
as part of the main driver struct. This is unlike other driver modules.

Allocate the memory required to store the different mirroring agents as
part of the initialization of the mirroring module.
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6c5a688e
...@@ -168,12 +168,8 @@ struct mlxsw_sp { ...@@ -168,12 +168,8 @@ struct mlxsw_sp {
struct notifier_block netdevice_nb; struct notifier_block netdevice_nb;
struct mlxsw_sp_ptp_clock *clock; struct mlxsw_sp_ptp_clock *clock;
struct mlxsw_sp_ptp_state *ptp_state; struct mlxsw_sp_ptp_state *ptp_state;
struct mlxsw_sp_counter_pool *counter_pool; struct mlxsw_sp_counter_pool *counter_pool;
struct { struct mlxsw_sp_span *span;
struct mlxsw_sp_span_entry *entries;
int entries_count;
} span;
const struct mlxsw_fw_rev *req_rev; const struct mlxsw_fw_rev *req_rev;
const char *fw_filename; const char *fw_filename;
const struct mlxsw_sp_kvdl_ops *kvdl_ops; const struct mlxsw_sp_kvdl_ops *kvdl_ops;
......
...@@ -14,14 +14,19 @@ ...@@ -14,14 +14,19 @@
#include "spectrum_span.h" #include "spectrum_span.h"
#include "spectrum_switchdev.h" #include "spectrum_switchdev.h"
struct mlxsw_sp_span {
struct mlxsw_sp_span_entry *entries;
int entries_count;
};
static u64 mlxsw_sp_span_occ_get(void *priv) static u64 mlxsw_sp_span_occ_get(void *priv)
{ {
const struct mlxsw_sp *mlxsw_sp = priv; const struct mlxsw_sp *mlxsw_sp = priv;
u64 occ = 0; u64 occ = 0;
int i; int i;
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
if (mlxsw_sp->span.entries[i].ref_count) if (mlxsw_sp->span->entries[i].ref_count)
occ++; occ++;
} }
...@@ -31,21 +36,29 @@ static u64 mlxsw_sp_span_occ_get(void *priv) ...@@ -31,21 +36,29 @@ static u64 mlxsw_sp_span_occ_get(void *priv)
int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp) int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp)
{ {
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
int i; struct mlxsw_sp_span *span;
int i, err;
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_SPAN)) if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_SPAN))
return -EIO; return -EIO;
mlxsw_sp->span.entries_count = MLXSW_CORE_RES_GET(mlxsw_sp->core, span = kzalloc(sizeof(*span), GFP_KERNEL);
MAX_SPAN); if (!span)
mlxsw_sp->span.entries = kcalloc(mlxsw_sp->span.entries_count,
sizeof(struct mlxsw_sp_span_entry),
GFP_KERNEL);
if (!mlxsw_sp->span.entries)
return -ENOMEM; return -ENOMEM;
mlxsw_sp->span = span;
mlxsw_sp->span->entries_count = MLXSW_CORE_RES_GET(mlxsw_sp->core,
MAX_SPAN);
mlxsw_sp->span->entries = kcalloc(mlxsw_sp->span->entries_count,
sizeof(struct mlxsw_sp_span_entry),
GFP_KERNEL);
if (!mlxsw_sp->span->entries) {
err = -ENOMEM;
goto err_alloc_span_entries;
}
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i]; struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span->entries[i];
INIT_LIST_HEAD(&curr->bound_ports_list); INIT_LIST_HEAD(&curr->bound_ports_list);
curr->id = i; curr->id = i;
...@@ -55,6 +68,10 @@ int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp) ...@@ -55,6 +68,10 @@ int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp)
mlxsw_sp_span_occ_get, mlxsw_sp); mlxsw_sp_span_occ_get, mlxsw_sp);
return 0; return 0;
err_alloc_span_entries:
kfree(span);
return err;
} }
void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp) void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp)
...@@ -64,12 +81,13 @@ void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp) ...@@ -64,12 +81,13 @@ void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp)
devlink_resource_occ_get_unregister(devlink, MLXSW_SP_RESOURCE_SPAN); devlink_resource_occ_get_unregister(devlink, MLXSW_SP_RESOURCE_SPAN);
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i]; struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span->entries[i];
WARN_ON_ONCE(!list_empty(&curr->bound_ports_list)); WARN_ON_ONCE(!list_empty(&curr->bound_ports_list));
} }
kfree(mlxsw_sp->span.entries); kfree(mlxsw_sp->span->entries);
kfree(mlxsw_sp->span);
} }
static int static int
...@@ -645,9 +663,9 @@ mlxsw_sp_span_entry_create(struct mlxsw_sp *mlxsw_sp, ...@@ -645,9 +663,9 @@ mlxsw_sp_span_entry_create(struct mlxsw_sp *mlxsw_sp,
int i; int i;
/* find a free entry to use */ /* find a free entry to use */
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
if (!mlxsw_sp->span.entries[i].ref_count) { if (!mlxsw_sp->span->entries[i].ref_count) {
span_entry = &mlxsw_sp->span.entries[i]; span_entry = &mlxsw_sp->span->entries[i];
break; break;
} }
} }
...@@ -673,8 +691,8 @@ mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp, ...@@ -673,8 +691,8 @@ mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
{ {
int i; int i;
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i]; struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span->entries[i];
if (curr->ref_count && curr->to_dev == to_dev) if (curr->ref_count && curr->to_dev == to_dev)
return curr; return curr;
...@@ -694,8 +712,8 @@ mlxsw_sp_span_entry_find_by_id(struct mlxsw_sp *mlxsw_sp, int span_id) ...@@ -694,8 +712,8 @@ mlxsw_sp_span_entry_find_by_id(struct mlxsw_sp *mlxsw_sp, int span_id)
{ {
int i; int i;
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i]; struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span->entries[i];
if (curr->ref_count && curr->id == span_id) if (curr->ref_count && curr->id == span_id)
return curr; return curr;
...@@ -736,8 +754,8 @@ static bool mlxsw_sp_span_is_egress_mirror(struct mlxsw_sp_port *port) ...@@ -736,8 +754,8 @@ static bool mlxsw_sp_span_is_egress_mirror(struct mlxsw_sp_port *port)
struct mlxsw_sp_span_inspected_port *p; struct mlxsw_sp_span_inspected_port *p;
int i; int i;
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i]; struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span->entries[i];
list_for_each_entry(p, &curr->bound_ports_list, list) list_for_each_entry(p, &curr->bound_ports_list, list)
if (p->local_port == port->local_port && if (p->local_port == port->local_port &&
...@@ -842,9 +860,9 @@ mlxsw_sp_span_inspected_port_add(struct mlxsw_sp_port *port, ...@@ -842,9 +860,9 @@ mlxsw_sp_span_inspected_port_add(struct mlxsw_sp_port *port,
* so if a binding is requested, check for conflicts. * so if a binding is requested, check for conflicts.
*/ */
if (bind) if (bind)
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
struct mlxsw_sp_span_entry *curr = struct mlxsw_sp_span_entry *curr =
&mlxsw_sp->span.entries[i]; &mlxsw_sp->span->entries[i];
if (mlxsw_sp_span_entry_bound_port_find(curr, type, if (mlxsw_sp_span_entry_bound_port_find(curr, type,
port, bind)) port, bind))
...@@ -994,8 +1012,8 @@ void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp) ...@@ -994,8 +1012,8 @@ void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp)
int err; int err;
ASSERT_RTNL(); ASSERT_RTNL();
for (i = 0; i < mlxsw_sp->span.entries_count; i++) { for (i = 0; i < mlxsw_sp->span->entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i]; struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span->entries[i];
struct mlxsw_sp_span_parms sparms = {NULL}; struct mlxsw_sp_span_parms sparms = {NULL};
if (!curr->ref_count) if (!curr->ref_count)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment