Commit 41603d78 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: sja1105: Make the PTP command read-write

The PTPSTRTSCH and PTPSTOPSCH bits are actually readable and indicate
whether the time-aware scheduler is running or not. We will be using
that for monitoring the scheduler in the next patch, so refactor the PTP
command API in order to allow that.
Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 72c99609
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
*/ */
#define SJA1105_AGEING_TIME_MS(ms) ((ms) / 10) #define SJA1105_AGEING_TIME_MS(ms) ((ms) / 10)
typedef enum {
SPI_READ = 0,
SPI_WRITE = 1,
} sja1105_spi_rw_mode_t;
#include "sja1105_tas.h" #include "sja1105_tas.h"
#include "sja1105_ptp.h" #include "sja1105_ptp.h"
...@@ -71,8 +76,6 @@ struct sja1105_info { ...@@ -71,8 +76,6 @@ struct sja1105_info {
const struct sja1105_dynamic_table_ops *dyn_ops; const struct sja1105_dynamic_table_ops *dyn_ops;
const struct sja1105_table_ops *static_ops; const struct sja1105_table_ops *static_ops;
const struct sja1105_regs *regs; const struct sja1105_regs *regs;
int (*ptp_cmd)(const struct dsa_switch *ds,
const struct sja1105_ptp_cmd *cmd);
int (*reset_cmd)(const void *ctx, const void *data); int (*reset_cmd)(const void *ctx, const void *data);
int (*setup_rgmii_delay)(const void *ctx, int port); int (*setup_rgmii_delay)(const void *ctx, int port);
/* Prototypes from include/net/dsa.h */ /* Prototypes from include/net/dsa.h */
...@@ -80,6 +83,8 @@ struct sja1105_info { ...@@ -80,6 +83,8 @@ struct sja1105_info {
const unsigned char *addr, u16 vid); const unsigned char *addr, u16 vid);
int (*fdb_del_cmd)(struct dsa_switch *ds, int port, int (*fdb_del_cmd)(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid); const unsigned char *addr, u16 vid);
void (*ptp_cmd_packing)(u8 *buf, struct sja1105_ptp_cmd *cmd,
enum packing_op op);
const char *name; const char *name;
}; };
...@@ -109,11 +114,6 @@ struct sja1105_spi_message { ...@@ -109,11 +114,6 @@ struct sja1105_spi_message {
u64 address; u64 address;
}; };
typedef enum {
SPI_READ = 0,
SPI_WRITE = 1,
} sja1105_spi_rw_mode_t;
/* From sja1105_main.c */ /* From sja1105_main.c */
enum sja1105_reset_reason { enum sja1105_reset_reason {
SJA1105_VLAN_FILTERING = 0, SJA1105_VLAN_FILTERING = 0,
......
...@@ -193,42 +193,50 @@ int sja1105_get_ts_info(struct dsa_switch *ds, int port, ...@@ -193,42 +193,50 @@ int sja1105_get_ts_info(struct dsa_switch *ds, int port,
return 0; return 0;
} }
int sja1105et_ptp_cmd(const struct dsa_switch *ds, void sja1105et_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd,
const struct sja1105_ptp_cmd *cmd) enum packing_op op)
{ {
const struct sja1105_private *priv = ds->priv;
const struct sja1105_regs *regs = priv->info->regs;
const int size = SJA1105_SIZE_PTP_CMD; const int size = SJA1105_SIZE_PTP_CMD;
u8 buf[SJA1105_SIZE_PTP_CMD] = {0};
/* No need to keep this as part of the structure */ /* No need to keep this as part of the structure */
u64 valid = 1; u64 valid = 1;
sja1105_pack(buf, &valid, 31, 31, size); sja1105_packing(buf, &valid, 31, 31, size, op);
sja1105_pack(buf, &cmd->resptp, 2, 2, size); sja1105_packing(buf, &cmd->resptp, 2, 2, size, op);
sja1105_pack(buf, &cmd->corrclk4ts, 1, 1, size); sja1105_packing(buf, &cmd->corrclk4ts, 1, 1, size, op);
sja1105_pack(buf, &cmd->ptpclkadd, 0, 0, size); sja1105_packing(buf, &cmd->ptpclkadd, 0, 0, size, op);
return sja1105_xfer_buf(priv, SPI_WRITE, regs->ptp_control, buf,
SJA1105_SIZE_PTP_CMD);
} }
int sja1105pqrs_ptp_cmd(const struct dsa_switch *ds, void sja1105pqrs_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd,
const struct sja1105_ptp_cmd *cmd) enum packing_op op)
{ {
const struct sja1105_private *priv = ds->priv;
const struct sja1105_regs *regs = priv->info->regs;
const int size = SJA1105_SIZE_PTP_CMD; const int size = SJA1105_SIZE_PTP_CMD;
u8 buf[SJA1105_SIZE_PTP_CMD] = {0};
/* No need to keep this as part of the structure */ /* No need to keep this as part of the structure */
u64 valid = 1; u64 valid = 1;
sja1105_pack(buf, &valid, 31, 31, size); sja1105_packing(buf, &valid, 31, 31, size, op);
sja1105_pack(buf, &cmd->resptp, 3, 3, size); sja1105_packing(buf, &cmd->resptp, 3, 3, size, op);
sja1105_pack(buf, &cmd->corrclk4ts, 2, 2, size); sja1105_packing(buf, &cmd->corrclk4ts, 2, 2, size, op);
sja1105_pack(buf, &cmd->ptpclkadd, 0, 0, size); sja1105_packing(buf, &cmd->ptpclkadd, 0, 0, size, op);
}
static int sja1105_ptp_commit(struct sja1105_private *priv,
struct sja1105_ptp_cmd *cmd,
sja1105_spi_rw_mode_t rw)
{
const struct sja1105_regs *regs = priv->info->regs;
u8 buf[SJA1105_SIZE_PTP_CMD] = {0};
int rc;
if (rw == SPI_WRITE)
priv->info->ptp_cmd_packing(buf, cmd, PACK);
return sja1105_xfer_buf(priv, SPI_WRITE, regs->ptp_control, buf, rc = sja1105_xfer_buf(priv, SPI_WRITE, regs->ptp_control, buf,
SJA1105_SIZE_PTP_CMD); SJA1105_SIZE_PTP_CMD);
if (rw == SPI_READ)
priv->info->ptp_cmd_packing(buf, cmd, UNPACK);
return rc;
} }
/* The switch returns partial timestamps (24 bits for SJA1105 E/T, which wrap /* The switch returns partial timestamps (24 bits for SJA1105 E/T, which wrap
...@@ -438,8 +446,9 @@ static int sja1105_ptp_reset(struct dsa_switch *ds) ...@@ -438,8 +446,9 @@ static int sja1105_ptp_reset(struct dsa_switch *ds)
mutex_lock(&ptp_data->lock); mutex_lock(&ptp_data->lock);
cmd.resptp = 1; cmd.resptp = 1;
dev_dbg(ds->dev, "Resetting PTP clock\n"); dev_dbg(ds->dev, "Resetting PTP clock\n");
rc = priv->info->ptp_cmd(ds, &cmd); rc = sja1105_ptp_commit(priv, &cmd, SPI_WRITE);
mutex_unlock(&ptp_data->lock); mutex_unlock(&ptp_data->lock);
...@@ -495,7 +504,7 @@ static int sja1105_ptp_mode_set(struct sja1105_private *priv, ...@@ -495,7 +504,7 @@ static int sja1105_ptp_mode_set(struct sja1105_private *priv,
ptp_data->cmd.ptpclkadd = mode; ptp_data->cmd.ptpclkadd = mode;
return priv->info->ptp_cmd(priv->ds, &ptp_data->cmd); return sja1105_ptp_commit(priv, &ptp_data->cmd, SPI_WRITE);
} }
/* Write to PTPCLKVAL while PTPCLKADD is 0 */ /* Write to PTPCLKVAL while PTPCLKADD is 0 */
......
...@@ -39,11 +39,11 @@ int sja1105_ptp_clock_register(struct dsa_switch *ds); ...@@ -39,11 +39,11 @@ int sja1105_ptp_clock_register(struct dsa_switch *ds);
void sja1105_ptp_clock_unregister(struct dsa_switch *ds); void sja1105_ptp_clock_unregister(struct dsa_switch *ds);
int sja1105et_ptp_cmd(const struct dsa_switch *ds, void sja1105et_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd,
const struct sja1105_ptp_cmd *cmd); enum packing_op op);
int sja1105pqrs_ptp_cmd(const struct dsa_switch *ds, void sja1105pqrs_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd,
const struct sja1105_ptp_cmd *cmd); enum packing_op op);
int sja1105_get_ts_info(struct dsa_switch *ds, int port, int sja1105_get_ts_info(struct dsa_switch *ds, int port,
struct ethtool_ts_info *ts); struct ethtool_ts_info *ts);
...@@ -110,9 +110,9 @@ static inline int __sja1105_ptp_adjtime(struct dsa_switch *ds, s64 delta) ...@@ -110,9 +110,9 @@ static inline int __sja1105_ptp_adjtime(struct dsa_switch *ds, s64 delta)
return 0; return 0;
} }
#define sja1105et_ptp_cmd NULL #define sja1105et_ptp_cmd_packing NULL
#define sja1105pqrs_ptp_cmd NULL #define sja1105pqrs_ptp_cmd_packing NULL
#define sja1105_get_ts_info NULL #define sja1105_get_ts_info NULL
......
...@@ -584,7 +584,7 @@ struct sja1105_info sja1105e_info = { ...@@ -584,7 +584,7 @@ struct sja1105_info sja1105e_info = {
.reset_cmd = sja1105et_reset_cmd, .reset_cmd = sja1105et_reset_cmd,
.fdb_add_cmd = sja1105et_fdb_add, .fdb_add_cmd = sja1105et_fdb_add,
.fdb_del_cmd = sja1105et_fdb_del, .fdb_del_cmd = sja1105et_fdb_del,
.ptp_cmd = sja1105et_ptp_cmd, .ptp_cmd_packing = sja1105et_ptp_cmd_packing,
.regs = &sja1105et_regs, .regs = &sja1105et_regs,
.name = "SJA1105E", .name = "SJA1105E",
}; };
...@@ -598,7 +598,7 @@ struct sja1105_info sja1105t_info = { ...@@ -598,7 +598,7 @@ struct sja1105_info sja1105t_info = {
.reset_cmd = sja1105et_reset_cmd, .reset_cmd = sja1105et_reset_cmd,
.fdb_add_cmd = sja1105et_fdb_add, .fdb_add_cmd = sja1105et_fdb_add,
.fdb_del_cmd = sja1105et_fdb_del, .fdb_del_cmd = sja1105et_fdb_del,
.ptp_cmd = sja1105et_ptp_cmd, .ptp_cmd_packing = sja1105et_ptp_cmd_packing,
.regs = &sja1105et_regs, .regs = &sja1105et_regs,
.name = "SJA1105T", .name = "SJA1105T",
}; };
...@@ -613,7 +613,7 @@ struct sja1105_info sja1105p_info = { ...@@ -613,7 +613,7 @@ struct sja1105_info sja1105p_info = {
.reset_cmd = sja1105pqrs_reset_cmd, .reset_cmd = sja1105pqrs_reset_cmd,
.fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_add_cmd = sja1105pqrs_fdb_add,
.fdb_del_cmd = sja1105pqrs_fdb_del, .fdb_del_cmd = sja1105pqrs_fdb_del,
.ptp_cmd = sja1105pqrs_ptp_cmd, .ptp_cmd_packing = sja1105pqrs_ptp_cmd_packing,
.regs = &sja1105pqrs_regs, .regs = &sja1105pqrs_regs,
.name = "SJA1105P", .name = "SJA1105P",
}; };
...@@ -628,7 +628,7 @@ struct sja1105_info sja1105q_info = { ...@@ -628,7 +628,7 @@ struct sja1105_info sja1105q_info = {
.reset_cmd = sja1105pqrs_reset_cmd, .reset_cmd = sja1105pqrs_reset_cmd,
.fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_add_cmd = sja1105pqrs_fdb_add,
.fdb_del_cmd = sja1105pqrs_fdb_del, .fdb_del_cmd = sja1105pqrs_fdb_del,
.ptp_cmd = sja1105pqrs_ptp_cmd, .ptp_cmd_packing = sja1105pqrs_ptp_cmd_packing,
.regs = &sja1105pqrs_regs, .regs = &sja1105pqrs_regs,
.name = "SJA1105Q", .name = "SJA1105Q",
}; };
...@@ -643,7 +643,7 @@ struct sja1105_info sja1105r_info = { ...@@ -643,7 +643,7 @@ struct sja1105_info sja1105r_info = {
.reset_cmd = sja1105pqrs_reset_cmd, .reset_cmd = sja1105pqrs_reset_cmd,
.fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_add_cmd = sja1105pqrs_fdb_add,
.fdb_del_cmd = sja1105pqrs_fdb_del, .fdb_del_cmd = sja1105pqrs_fdb_del,
.ptp_cmd = sja1105pqrs_ptp_cmd, .ptp_cmd_packing = sja1105pqrs_ptp_cmd_packing,
.regs = &sja1105pqrs_regs, .regs = &sja1105pqrs_regs,
.name = "SJA1105R", .name = "SJA1105R",
}; };
...@@ -659,6 +659,6 @@ struct sja1105_info sja1105s_info = { ...@@ -659,6 +659,6 @@ struct sja1105_info sja1105s_info = {
.reset_cmd = sja1105pqrs_reset_cmd, .reset_cmd = sja1105pqrs_reset_cmd,
.fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_add_cmd = sja1105pqrs_fdb_add,
.fdb_del_cmd = sja1105pqrs_fdb_del, .fdb_del_cmd = sja1105pqrs_fdb_del,
.ptp_cmd = sja1105pqrs_ptp_cmd, .ptp_cmd_packing = sja1105pqrs_ptp_cmd_packing,
.name = "SJA1105S", .name = "SJA1105S",
}; };
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