1b790b554SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2b790b554SNishad Kamdar /* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com>
3317ab5b8SVladimir Oltean */
4317ab5b8SVladimir Oltean #ifndef _SJA1105_TAS_H
5317ab5b8SVladimir Oltean #define _SJA1105_TAS_H
6317ab5b8SVladimir Oltean
7317ab5b8SVladimir Oltean #include <net/pkt_sched.h>
8317ab5b8SVladimir Oltean
9834f8933SVladimir Oltean #define SJA1105_TAS_MAX_DELTA BIT(18)
10834f8933SVladimir Oltean
11834f8933SVladimir Oltean struct sja1105_private;
12834f8933SVladimir Oltean
13317ab5b8SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA_SJA1105_TAS)
14317ab5b8SVladimir Oltean
1586db36a3SVladimir Oltean enum sja1105_tas_state {
1686db36a3SVladimir Oltean SJA1105_TAS_STATE_DISABLED,
1786db36a3SVladimir Oltean SJA1105_TAS_STATE_ENABLED_NOT_RUNNING,
1886db36a3SVladimir Oltean SJA1105_TAS_STATE_RUNNING,
1986db36a3SVladimir Oltean };
2086db36a3SVladimir Oltean
2186db36a3SVladimir Oltean enum sja1105_ptp_op {
2286db36a3SVladimir Oltean SJA1105_PTP_NONE,
2386db36a3SVladimir Oltean SJA1105_PTP_CLOCKSTEP,
2486db36a3SVladimir Oltean SJA1105_PTP_ADJUSTFREQ,
2586db36a3SVladimir Oltean };
2686db36a3SVladimir Oltean
27834f8933SVladimir Oltean struct sja1105_gate_entry {
28834f8933SVladimir Oltean struct list_head list;
29834f8933SVladimir Oltean struct sja1105_rule *rule;
30834f8933SVladimir Oltean s64 interval;
31834f8933SVladimir Oltean u8 gate_state;
32834f8933SVladimir Oltean };
33834f8933SVladimir Oltean
34834f8933SVladimir Oltean struct sja1105_gating_config {
35834f8933SVladimir Oltean u64 cycle_time;
36834f8933SVladimir Oltean s64 base_time;
37834f8933SVladimir Oltean int num_entries;
38834f8933SVladimir Oltean struct list_head entries;
39834f8933SVladimir Oltean };
40834f8933SVladimir Oltean
41317ab5b8SVladimir Oltean struct sja1105_tas_data {
42*82760d7fSVladimir Oltean struct tc_taprio_qopt_offload *offload[SJA1105_MAX_NUM_PORTS];
43834f8933SVladimir Oltean struct sja1105_gating_config gating_cfg;
4486db36a3SVladimir Oltean enum sja1105_tas_state state;
4586db36a3SVladimir Oltean enum sja1105_ptp_op last_op;
4686db36a3SVladimir Oltean struct work_struct tas_work;
4786db36a3SVladimir Oltean s64 earliest_base_time;
4886db36a3SVladimir Oltean s64 oper_base_time;
4986db36a3SVladimir Oltean u64 max_cycle_time;
5086db36a3SVladimir Oltean bool enabled;
51317ab5b8SVladimir Oltean };
52317ab5b8SVladimir Oltean
53317ab5b8SVladimir Oltean int sja1105_setup_tc_taprio(struct dsa_switch *ds, int port,
54317ab5b8SVladimir Oltean struct tc_taprio_qopt_offload *admin);
55317ab5b8SVladimir Oltean
56317ab5b8SVladimir Oltean void sja1105_tas_setup(struct dsa_switch *ds);
57317ab5b8SVladimir Oltean
58317ab5b8SVladimir Oltean void sja1105_tas_teardown(struct dsa_switch *ds);
59317ab5b8SVladimir Oltean
6086db36a3SVladimir Oltean void sja1105_tas_clockstep(struct dsa_switch *ds);
6186db36a3SVladimir Oltean
6286db36a3SVladimir Oltean void sja1105_tas_adjfreq(struct dsa_switch *ds);
6386db36a3SVladimir Oltean
64834f8933SVladimir Oltean bool sja1105_gating_check_conflicts(struct sja1105_private *priv, int port,
65834f8933SVladimir Oltean struct netlink_ext_ack *extack);
66834f8933SVladimir Oltean
67834f8933SVladimir Oltean int sja1105_init_scheduling(struct sja1105_private *priv);
68834f8933SVladimir Oltean
69317ab5b8SVladimir Oltean #else
70317ab5b8SVladimir Oltean
71317ab5b8SVladimir Oltean /* C doesn't allow empty structures, bah! */
72317ab5b8SVladimir Oltean struct sja1105_tas_data {
73317ab5b8SVladimir Oltean u8 dummy;
74317ab5b8SVladimir Oltean };
75317ab5b8SVladimir Oltean
sja1105_setup_tc_taprio(struct dsa_switch * ds,int port,struct tc_taprio_qopt_offload * admin)76317ab5b8SVladimir Oltean static inline int sja1105_setup_tc_taprio(struct dsa_switch *ds, int port,
77317ab5b8SVladimir Oltean struct tc_taprio_qopt_offload *admin)
78317ab5b8SVladimir Oltean {
79317ab5b8SVladimir Oltean return -EOPNOTSUPP;
80317ab5b8SVladimir Oltean }
81317ab5b8SVladimir Oltean
sja1105_tas_setup(struct dsa_switch * ds)82317ab5b8SVladimir Oltean static inline void sja1105_tas_setup(struct dsa_switch *ds) { }
83317ab5b8SVladimir Oltean
sja1105_tas_teardown(struct dsa_switch * ds)84317ab5b8SVladimir Oltean static inline void sja1105_tas_teardown(struct dsa_switch *ds) { }
85317ab5b8SVladimir Oltean
sja1105_tas_clockstep(struct dsa_switch * ds)8686db36a3SVladimir Oltean static inline void sja1105_tas_clockstep(struct dsa_switch *ds) { }
8786db36a3SVladimir Oltean
sja1105_tas_adjfreq(struct dsa_switch * ds)8886db36a3SVladimir Oltean static inline void sja1105_tas_adjfreq(struct dsa_switch *ds) { }
8986db36a3SVladimir Oltean
90834f8933SVladimir Oltean static inline bool
sja1105_gating_check_conflicts(struct dsa_switch * ds,int port,struct netlink_ext_ack * extack)91834f8933SVladimir Oltean sja1105_gating_check_conflicts(struct dsa_switch *ds, int port,
92834f8933SVladimir Oltean struct netlink_ext_ack *extack)
93834f8933SVladimir Oltean {
94834f8933SVladimir Oltean return true;
95834f8933SVladimir Oltean }
96834f8933SVladimir Oltean
sja1105_init_scheduling(struct sja1105_private * priv)97834f8933SVladimir Oltean static inline int sja1105_init_scheduling(struct sja1105_private *priv)
98834f8933SVladimir Oltean {
99834f8933SVladimir Oltean return 0;
100834f8933SVladimir Oltean }
101834f8933SVladimir Oltean
102317ab5b8SVladimir Oltean #endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_TAS) */
103317ab5b8SVladimir Oltean
104317ab5b8SVladimir Oltean #endif /* _SJA1105_TAS_H */
105