Commit e8fea346 authored by Amit Cohen's avatar Amit Cohen Committed by David S. Miller

mlxsw: spectrum_ptp: Use 'struct mlxsw_sp_ptp_state' per ASIC

Currently, there is one shared structure that holds the required
structures and details for PTP. Most of the existing fields are relevant
only for Spectrum-1 (hash table, lock for hash table, delayed work, and
more). Rename the structure to be specific for Spectrum-1 and align the
existing code. Add a common structure which includes
'struct mlxsw_sp *mlxsw_sp' and will be returned from ptp_init()
operation, as the definition is shared between all ASICs' operations.
Signed-off-by: default avatarAmit Cohen <amcohen@nvidia.com>
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 94683229
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
struct mlxsw_sp_ptp_state { struct mlxsw_sp_ptp_state {
struct mlxsw_sp *mlxsw_sp; struct mlxsw_sp *mlxsw_sp;
};
struct mlxsw_sp1_ptp_state {
struct mlxsw_sp_ptp_state common;
struct rhltable unmatched_ht; struct rhltable unmatched_ht;
spinlock_t unmatched_lock; /* protects the HT */ spinlock_t unmatched_lock; /* protects the HT */
struct delayed_work ht_gc_dw; struct delayed_work ht_gc_dw;
...@@ -70,6 +74,13 @@ struct mlxsw_sp_ptp_clock { ...@@ -70,6 +74,13 @@ struct mlxsw_sp_ptp_clock {
struct delayed_work overflow_work; struct delayed_work overflow_work;
}; };
static struct mlxsw_sp1_ptp_state *
mlxsw_sp1_ptp_state(struct mlxsw_sp *mlxsw_sp)
{
return container_of(mlxsw_sp->ptp_state, struct mlxsw_sp1_ptp_state,
common);
}
static u64 __mlxsw_sp1_ptp_read_frc(struct mlxsw_sp_ptp_clock *clock, static u64 __mlxsw_sp1_ptp_read_frc(struct mlxsw_sp_ptp_clock *clock,
struct ptp_system_timestamp *sts) struct ptp_system_timestamp *sts)
{ {
...@@ -347,7 +358,7 @@ mlxsw_sp1_ptp_unmatched_save(struct mlxsw_sp *mlxsw_sp, ...@@ -347,7 +358,7 @@ mlxsw_sp1_ptp_unmatched_save(struct mlxsw_sp *mlxsw_sp,
u64 timestamp) u64 timestamp)
{ {
int cycles = MLXSW_SP1_PTP_HT_GC_TIMEOUT / MLXSW_SP1_PTP_HT_GC_INTERVAL; int cycles = MLXSW_SP1_PTP_HT_GC_TIMEOUT / MLXSW_SP1_PTP_HT_GC_INTERVAL;
struct mlxsw_sp_ptp_state *ptp_state = mlxsw_sp->ptp_state; struct mlxsw_sp1_ptp_state *ptp_state = mlxsw_sp1_ptp_state(mlxsw_sp);
struct mlxsw_sp1_ptp_unmatched *unmatched; struct mlxsw_sp1_ptp_unmatched *unmatched;
int err; int err;
...@@ -358,7 +369,7 @@ mlxsw_sp1_ptp_unmatched_save(struct mlxsw_sp *mlxsw_sp, ...@@ -358,7 +369,7 @@ mlxsw_sp1_ptp_unmatched_save(struct mlxsw_sp *mlxsw_sp,
unmatched->key = key; unmatched->key = key;
unmatched->skb = skb; unmatched->skb = skb;
unmatched->timestamp = timestamp; unmatched->timestamp = timestamp;
unmatched->gc_cycle = mlxsw_sp->ptp_state->gc_cycle + cycles; unmatched->gc_cycle = ptp_state->gc_cycle + cycles;
err = rhltable_insert(&ptp_state->unmatched_ht, &unmatched->ht_node, err = rhltable_insert(&ptp_state->unmatched_ht, &unmatched->ht_node,
mlxsw_sp1_ptp_unmatched_ht_params); mlxsw_sp1_ptp_unmatched_ht_params);
...@@ -372,11 +383,12 @@ static struct mlxsw_sp1_ptp_unmatched * ...@@ -372,11 +383,12 @@ static struct mlxsw_sp1_ptp_unmatched *
mlxsw_sp1_ptp_unmatched_lookup(struct mlxsw_sp *mlxsw_sp, mlxsw_sp1_ptp_unmatched_lookup(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp1_ptp_key key, int *p_length) struct mlxsw_sp1_ptp_key key, int *p_length)
{ {
struct mlxsw_sp1_ptp_state *ptp_state = mlxsw_sp1_ptp_state(mlxsw_sp);
struct mlxsw_sp1_ptp_unmatched *unmatched, *last = NULL; struct mlxsw_sp1_ptp_unmatched *unmatched, *last = NULL;
struct rhlist_head *tmp, *list; struct rhlist_head *tmp, *list;
int length = 0; int length = 0;
list = rhltable_lookup(&mlxsw_sp->ptp_state->unmatched_ht, &key, list = rhltable_lookup(&ptp_state->unmatched_ht, &key,
mlxsw_sp1_ptp_unmatched_ht_params); mlxsw_sp1_ptp_unmatched_ht_params);
rhl_for_each_entry_rcu(unmatched, tmp, list, ht_node) { rhl_for_each_entry_rcu(unmatched, tmp, list, ht_node) {
last = unmatched; last = unmatched;
...@@ -391,7 +403,9 @@ static int ...@@ -391,7 +403,9 @@ static int
mlxsw_sp1_ptp_unmatched_remove(struct mlxsw_sp *mlxsw_sp, mlxsw_sp1_ptp_unmatched_remove(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp1_ptp_unmatched *unmatched) struct mlxsw_sp1_ptp_unmatched *unmatched)
{ {
return rhltable_remove(&mlxsw_sp->ptp_state->unmatched_ht, struct mlxsw_sp1_ptp_state *ptp_state = mlxsw_sp1_ptp_state(mlxsw_sp);
return rhltable_remove(&ptp_state->unmatched_ht,
&unmatched->ht_node, &unmatched->ht_node,
mlxsw_sp1_ptp_unmatched_ht_params); mlxsw_sp1_ptp_unmatched_ht_params);
} }
...@@ -480,13 +494,14 @@ static void mlxsw_sp1_ptp_got_piece(struct mlxsw_sp *mlxsw_sp, ...@@ -480,13 +494,14 @@ static void mlxsw_sp1_ptp_got_piece(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp1_ptp_key key, struct mlxsw_sp1_ptp_key key,
struct sk_buff *skb, u64 timestamp) struct sk_buff *skb, u64 timestamp)
{ {
struct mlxsw_sp1_ptp_state *ptp_state = mlxsw_sp1_ptp_state(mlxsw_sp);
struct mlxsw_sp1_ptp_unmatched *unmatched; struct mlxsw_sp1_ptp_unmatched *unmatched;
int length; int length;
int err; int err;
rcu_read_lock(); rcu_read_lock();
spin_lock(&mlxsw_sp->ptp_state->unmatched_lock); spin_lock(&ptp_state->unmatched_lock);
unmatched = mlxsw_sp1_ptp_unmatched_lookup(mlxsw_sp, key, &length); unmatched = mlxsw_sp1_ptp_unmatched_lookup(mlxsw_sp, key, &length);
if (skb && unmatched && unmatched->timestamp) { if (skb && unmatched && unmatched->timestamp) {
...@@ -514,7 +529,7 @@ static void mlxsw_sp1_ptp_got_piece(struct mlxsw_sp *mlxsw_sp, ...@@ -514,7 +529,7 @@ static void mlxsw_sp1_ptp_got_piece(struct mlxsw_sp *mlxsw_sp,
WARN_ON_ONCE(err); WARN_ON_ONCE(err);
} }
spin_unlock(&mlxsw_sp->ptp_state->unmatched_lock); spin_unlock(&ptp_state->unmatched_lock);
if (unmatched) if (unmatched)
mlxsw_sp1_ptp_unmatched_finish(mlxsw_sp, unmatched); mlxsw_sp1_ptp_unmatched_finish(mlxsw_sp, unmatched);
...@@ -610,9 +625,10 @@ void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp, ...@@ -610,9 +625,10 @@ void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
} }
static void static void
mlxsw_sp1_ptp_ht_gc_collect(struct mlxsw_sp_ptp_state *ptp_state, mlxsw_sp1_ptp_ht_gc_collect(struct mlxsw_sp1_ptp_state *ptp_state,
struct mlxsw_sp1_ptp_unmatched *unmatched) struct mlxsw_sp1_ptp_unmatched *unmatched)
{ {
struct mlxsw_sp *mlxsw_sp = ptp_state->common.mlxsw_sp;
struct mlxsw_sp_ptp_port_dir_stats *stats; struct mlxsw_sp_ptp_port_dir_stats *stats;
struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_port *mlxsw_sp_port;
int err; int err;
...@@ -635,7 +651,7 @@ mlxsw_sp1_ptp_ht_gc_collect(struct mlxsw_sp_ptp_state *ptp_state, ...@@ -635,7 +651,7 @@ mlxsw_sp1_ptp_ht_gc_collect(struct mlxsw_sp_ptp_state *ptp_state,
/* The packet was matched with timestamp during the walk. */ /* The packet was matched with timestamp during the walk. */
goto out; goto out;
mlxsw_sp_port = ptp_state->mlxsw_sp->ports[unmatched->key.local_port]; mlxsw_sp_port = mlxsw_sp->ports[unmatched->key.local_port];
if (mlxsw_sp_port) { if (mlxsw_sp_port) {
stats = unmatched->key.ingress ? stats = unmatched->key.ingress ?
&mlxsw_sp_port->ptp.stats.rx_gcd : &mlxsw_sp_port->ptp.stats.rx_gcd :
...@@ -652,7 +668,7 @@ mlxsw_sp1_ptp_ht_gc_collect(struct mlxsw_sp_ptp_state *ptp_state, ...@@ -652,7 +668,7 @@ mlxsw_sp1_ptp_ht_gc_collect(struct mlxsw_sp_ptp_state *ptp_state,
* netif_receive_skb(), in process context, is seen elsewhere in the * netif_receive_skb(), in process context, is seen elsewhere in the
* kernel, notably in pktgen. * kernel, notably in pktgen.
*/ */
mlxsw_sp1_ptp_unmatched_finish(ptp_state->mlxsw_sp, unmatched); mlxsw_sp1_ptp_unmatched_finish(mlxsw_sp, unmatched);
out: out:
local_bh_enable(); local_bh_enable();
...@@ -662,12 +678,12 @@ static void mlxsw_sp1_ptp_ht_gc(struct work_struct *work) ...@@ -662,12 +678,12 @@ static void mlxsw_sp1_ptp_ht_gc(struct work_struct *work)
{ {
struct delayed_work *dwork = to_delayed_work(work); struct delayed_work *dwork = to_delayed_work(work);
struct mlxsw_sp1_ptp_unmatched *unmatched; struct mlxsw_sp1_ptp_unmatched *unmatched;
struct mlxsw_sp_ptp_state *ptp_state; struct mlxsw_sp1_ptp_state *ptp_state;
struct rhashtable_iter iter; struct rhashtable_iter iter;
u32 gc_cycle; u32 gc_cycle;
void *obj; void *obj;
ptp_state = container_of(dwork, struct mlxsw_sp_ptp_state, ht_gc_dw); ptp_state = container_of(dwork, struct mlxsw_sp1_ptp_state, ht_gc_dw);
gc_cycle = ptp_state->gc_cycle++; gc_cycle = ptp_state->gc_cycle++;
rhltable_walk_enter(&ptp_state->unmatched_ht, &iter); rhltable_walk_enter(&ptp_state->unmatched_ht, &iter);
...@@ -808,7 +824,7 @@ static int mlxsw_sp1_ptp_shaper_params_set(struct mlxsw_sp *mlxsw_sp) ...@@ -808,7 +824,7 @@ static int mlxsw_sp1_ptp_shaper_params_set(struct mlxsw_sp *mlxsw_sp)
struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp) struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
{ {
struct mlxsw_sp_ptp_state *ptp_state; struct mlxsw_sp1_ptp_state *ptp_state;
u16 message_type; u16 message_type;
int err; int err;
...@@ -819,7 +835,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp) ...@@ -819,7 +835,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
ptp_state = kzalloc(sizeof(*ptp_state), GFP_KERNEL); ptp_state = kzalloc(sizeof(*ptp_state), GFP_KERNEL);
if (!ptp_state) if (!ptp_state)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
ptp_state->mlxsw_sp = mlxsw_sp; ptp_state->common.mlxsw_sp = mlxsw_sp;
spin_lock_init(&ptp_state->unmatched_lock); spin_lock_init(&ptp_state->unmatched_lock);
...@@ -852,7 +868,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp) ...@@ -852,7 +868,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
INIT_DELAYED_WORK(&ptp_state->ht_gc_dw, mlxsw_sp1_ptp_ht_gc); INIT_DELAYED_WORK(&ptp_state->ht_gc_dw, mlxsw_sp1_ptp_ht_gc);
mlxsw_core_schedule_dw(&ptp_state->ht_gc_dw, mlxsw_core_schedule_dw(&ptp_state->ht_gc_dw,
MLXSW_SP1_PTP_HT_GC_INTERVAL); MLXSW_SP1_PTP_HT_GC_INTERVAL);
return ptp_state; return &ptp_state->common;
err_fifo_clr: err_fifo_clr:
mlxsw_sp_ptp_mtptpt_set(mlxsw_sp, MLXSW_REG_MTPTPT_TRAP_ID_PTP1, 0); mlxsw_sp_ptp_mtptpt_set(mlxsw_sp, MLXSW_REG_MTPTPT_TRAP_ID_PTP1, 0);
...@@ -865,9 +881,12 @@ struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp) ...@@ -865,9 +881,12 @@ struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
return ERR_PTR(err); return ERR_PTR(err);
} }
void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state) void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state_common)
{ {
struct mlxsw_sp *mlxsw_sp = ptp_state->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = ptp_state_common->mlxsw_sp;
struct mlxsw_sp1_ptp_state *ptp_state;
ptp_state = mlxsw_sp1_ptp_state(mlxsw_sp);
cancel_delayed_work_sync(&ptp_state->ht_gc_dw); cancel_delayed_work_sync(&ptp_state->ht_gc_dw);
mlxsw_sp1_ptp_mtpppc_set(mlxsw_sp, 0, 0); mlxsw_sp1_ptp_mtpppc_set(mlxsw_sp, 0, 0);
......
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