Skip to content

Commit 6642777

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: Change the PTP command access pattern
The PTP command register contains enable bits for: - Putting the 64-bit PTPCLKVAL register in add/subtract or write mode - Taking timestamps off of the corrected vs free-running clock - Starting/stopping the TTEthernet scheduling - Starting/stopping PPS output - Resetting the switch When a command needs to be issued (e.g. "change the PTPCLKVAL from write mode to add/subtract mode"), one cannot simply write to the command register setting the PTPCLKADD bit to 1, because that would zeroize the other settings. One also cannot do a read-modify-write (that would be too easy for this hardware) because not all bits of the command register are readable over SPI. So this leaves us with the only option of keeping the value of the PTP command register in the driver, and operating on that. Actually there are 2 types of PTP operations now: - Operations that modify the cached PTP command. These operate on ptp_data->cmd as a pointer. - Operations that apply all previously cached PTP settings, but don't otherwise cache what they did themselves. The sja1105_ptp_reset function is such an example. It copies the ptp_data->cmd on stack before modifying and writing it to SPI. This practically means that struct sja1105_ptp_cmd is no longer an implementation detail, since it needs to be stored in full into struct sja1105_ptp_data, and hence in struct sja1105_private. So the (*ptp_cmd) function prototype can change and take struct sja1105_ptp_cmd as second argument now. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a9d6ed7 commit 6642777

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

drivers/net/dsa/sja1105/sja1105.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ struct sja1105_info {
7272
const struct sja1105_dynamic_table_ops *dyn_ops;
7373
const struct sja1105_table_ops *static_ops;
7474
const struct sja1105_regs *regs;
75-
int (*ptp_cmd)(const struct dsa_switch *ds, const void *data);
75+
int (*ptp_cmd)(const struct dsa_switch *ds,
76+
const struct sja1105_ptp_cmd *cmd);
7677
int (*reset_cmd)(const void *ctx, const void *data);
7778
int (*setup_rgmii_delay)(const void *ctx, int port);
7879
/* Prototypes from include/net/dsa.h */

drivers/net/dsa/sja1105/sja1105_ptp.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@
5959
#define ptp_data_to_sja1105(d) \
6060
container_of((d), struct sja1105_private, ptp_data)
6161

62-
struct sja1105_ptp_cmd {
63-
u64 resptp; /* reset */
64-
};
65-
6662
static int sja1105_init_avb_params(struct sja1105_private *priv,
6763
bool on)
6864
{
@@ -212,10 +208,10 @@ int sja1105_get_ts_info(struct dsa_switch *ds, int port,
212208
return 0;
213209
}
214210

215-
int sja1105et_ptp_cmd(const struct dsa_switch *ds, const void *data)
211+
int sja1105et_ptp_cmd(const struct dsa_switch *ds,
212+
const struct sja1105_ptp_cmd *cmd)
216213
{
217214
const struct sja1105_private *priv = ds->priv;
218-
const struct sja1105_ptp_cmd *cmd = data;
219215
const struct sja1105_regs *regs = priv->info->regs;
220216
const int size = SJA1105_SIZE_PTP_CMD;
221217
u8 buf[SJA1105_SIZE_PTP_CMD] = {0};
@@ -229,10 +225,10 @@ int sja1105et_ptp_cmd(const struct dsa_switch *ds, const void *data)
229225
SJA1105_SIZE_PTP_CMD);
230226
}
231227

232-
int sja1105pqrs_ptp_cmd(const struct dsa_switch *ds, const void *data)
228+
int sja1105pqrs_ptp_cmd(const struct dsa_switch *ds,
229+
const struct sja1105_ptp_cmd *cmd)
233230
{
234231
const struct sja1105_private *priv = ds->priv;
235-
const struct sja1105_ptp_cmd *cmd = data;
236232
const struct sja1105_regs *regs = priv->info->regs;
237233
const int size = SJA1105_SIZE_PTP_CMD;
238234
u8 buf[SJA1105_SIZE_PTP_CMD] = {0};
@@ -422,7 +418,7 @@ int sja1105_ptp_reset(struct dsa_switch *ds)
422418
{
423419
struct sja1105_private *priv = ds->priv;
424420
struct sja1105_ptp_data *ptp_data = &priv->ptp_data;
425-
struct sja1105_ptp_cmd cmd = {0};
421+
struct sja1105_ptp_cmd cmd = ptp_data->cmd;
426422
int rc;
427423

428424
mutex_lock(&ptp_data->lock);

drivers/net/dsa/sja1105/sja1105_ptp.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66

77
#if IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP)
88

9+
struct sja1105_ptp_cmd {
10+
u64 resptp; /* reset */
11+
};
12+
913
struct sja1105_ptp_data {
1014
struct ptp_clock_info caps;
1115
struct ptp_clock *clock;
16+
struct sja1105_ptp_cmd cmd;
1217
/* The cycle counter translates the PTP timestamps (based on
1318
* a free-running counter) into a software time domain.
1419
*/
@@ -23,9 +28,11 @@ int sja1105_ptp_clock_register(struct dsa_switch *ds);
2328

2429
void sja1105_ptp_clock_unregister(struct dsa_switch *ds);
2530

26-
int sja1105et_ptp_cmd(const struct dsa_switch *ds, const void *data);
31+
int sja1105et_ptp_cmd(const struct dsa_switch *ds,
32+
const struct sja1105_ptp_cmd *cmd);
2733

28-
int sja1105pqrs_ptp_cmd(const struct dsa_switch *ds, const void *data);
34+
int sja1105pqrs_ptp_cmd(const struct dsa_switch *ds,
35+
const struct sja1105_ptp_cmd *cmd);
2936

3037
int sja1105_get_ts_info(struct dsa_switch *ds, int port,
3138
struct ethtool_ts_info *ts);
@@ -47,6 +54,8 @@ int sja1105_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr);
4754

4855
#else
4956

57+
struct sja1105_ptp_cmd;
58+
5059
/* Structures cannot be empty in C. Bah!
5160
* Keep the mutex as the only element, which is a bit more difficult to
5261
* refactor out of sja1105_main.c anyway.

0 commit comments

Comments
 (0)