net: dsa: mv88e6xxx: Abstract HW timestamp setup
authorAndrew Lunn <andrew@lunn.ch>
Wed, 18 Jul 2018 20:38:23 +0000 (22:38 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Jul 2018 22:05:38 +0000 (15:05 -0700)
The 6165 family does not have per port PTP control registers. Also, it
places the timestamp data in different registers. Abstract the current
implementation of 6352 compatible PTP devices so that 6165 can be
added.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx/chip.h
drivers/net/dsa/mv88e6xxx/hwtstamp.c
drivers/net/dsa/mv88e6xxx/hwtstamp.h
drivers/net/dsa/mv88e6xxx/ptp.c

index e12a489c22d46eec9f3b3ce357cac51373bf895e..2cc4deb110d6c04df210177c54338960c01fe620 100644 (file)
@@ -497,7 +497,12 @@ struct mv88e6xxx_ptp_ops {
        int (*ptp_verify)(struct ptp_clock_info *ptp, unsigned int pin,
                          enum ptp_pin_function func, unsigned int chan);
        void (*event_work)(struct work_struct *ugly);
+       int (*port_enable)(struct mv88e6xxx_chip *chip, int port);
+       int (*port_disable)(struct mv88e6xxx_chip *chip, int port);
        int n_ext_ts;
+       int arr0_sts_reg;
+       int arr1_sts_reg;
+       int dep_sts_reg;
 };
 
 #define STATS_TYPE_PORT                BIT(0)
index a036c490b7ce0662f0c29f8fe0e6609344639455..1378c9d102a1861eb4be9c193452f48c02ec583b 100644 (file)
@@ -92,10 +92,9 @@ int mv88e6xxx_get_ts_info(struct dsa_switch *ds, int port,
 static int mv88e6xxx_set_hwtstamp_config(struct mv88e6xxx_chip *chip, int port,
                                         struct hwtstamp_config *config)
 {
+       const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
        struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
        bool tstamp_enable = false;
-       u16 port_config0;
-       int err;
 
        /* Prevent the TX/RX paths from trying to interact with the
         * timestamp hardware while we reconfigure it.
@@ -141,24 +140,16 @@ static int mv88e6xxx_set_hwtstamp_config(struct mv88e6xxx_chip *chip, int port,
                return -ERANGE;
        }
 
+       mutex_lock(&chip->reg_lock);
        if (tstamp_enable) {
-               /* Disable transportSpecific value matching, so that packets
-                * with either 1588 (0) and 802.1AS (1) will be timestamped.
-                */
-               port_config0 = MV88E6XXX_PORT_PTP_CFG0_DISABLE_TSPEC_MATCH;
+               if (ptp_ops->port_enable)
+                       ptp_ops->port_enable(chip, port);
        } else {
-               /* Disable PTP. This disables both RX and TX timestamping. */
-               port_config0 = MV88E6XXX_PORT_PTP_CFG0_DISABLE_PTP;
+               if (ptp_ops->port_disable)
+                       ptp_ops->port_disable(chip, port);
        }
-
-       mutex_lock(&chip->reg_lock);
-       err = mv88e6xxx_port_ptp_write(chip, port, MV88E6XXX_PORT_PTP_CFG0,
-                                      port_config0);
        mutex_unlock(&chip->reg_lock);
 
-       if (err < 0)
-               return err;
-
        /* Once hardware has been configured, enable timestamp checks
         * in the RX/TX paths.
         */
@@ -338,17 +329,18 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
 static void mv88e6xxx_rxtstamp_work(struct mv88e6xxx_chip *chip,
                                    struct mv88e6xxx_port_hwtstamp *ps)
 {
+       const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
        struct sk_buff *skb;
 
        skb = skb_dequeue(&ps->rx_queue);
 
        if (skb)
-               mv88e6xxx_get_rxts(chip, ps, skb, MV88E6XXX_PORT_PTP_ARR0_STS,
+               mv88e6xxx_get_rxts(chip, ps, skb, ptp_ops->arr0_sts_reg,
                                   &ps->rx_queue);
 
        skb = skb_dequeue(&ps->rx_queue2);
        if (skb)
-               mv88e6xxx_get_rxts(chip, ps, skb, MV88E6XXX_PORT_PTP_ARR1_STS,
+               mv88e6xxx_get_rxts(chip, ps, skb, ptp_ops->arr1_sts_reg,
                                   &ps->rx_queue2);
 }
 
@@ -389,6 +381,7 @@ bool mv88e6xxx_port_rxtstamp(struct dsa_switch *ds, int port,
 static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,
                                   struct mv88e6xxx_port_hwtstamp *ps)
 {
+       const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
        struct skb_shared_hwtstamps shhwtstamps;
        u16 departure_block[4], status;
        struct sk_buff *tmp_skb;
@@ -401,7 +394,7 @@ static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,
 
        mutex_lock(&chip->reg_lock);
        err = mv88e6xxx_port_ptp_read(chip, ps->port_id,
-                                     MV88E6XXX_PORT_PTP_DEP_STS,
+                                     ptp_ops->dep_sts_reg,
                                      departure_block,
                                      ARRAY_SIZE(departure_block));
        mutex_unlock(&chip->reg_lock);
@@ -425,8 +418,7 @@ static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,
 
        /* We have the timestamp; go ahead and clear valid now */
        mutex_lock(&chip->reg_lock);
-       mv88e6xxx_port_ptp_write(chip, ps->port_id,
-                                MV88E6XXX_PORT_PTP_DEP_STS, 0);
+       mv88e6xxx_port_ptp_write(chip, ps->port_id, ptp_ops->dep_sts_reg, 0);
        mutex_unlock(&chip->reg_lock);
 
        status = departure_block[0] & MV88E6XXX_PTP_TS_STATUS_MASK;
@@ -522,8 +514,21 @@ bool mv88e6xxx_port_txtstamp(struct dsa_switch *ds, int port,
        return true;
 }
 
+int mv88e6352_hwtstamp_port_disable(struct mv88e6xxx_chip *chip, int port)
+{
+       return mv88e6xxx_port_ptp_write(chip, port, MV88E6XXX_PORT_PTP_CFG0,
+                                       MV88E6XXX_PORT_PTP_CFG0_DISABLE_PTP);
+}
+
+int mv88e6352_hwtstamp_port_enable(struct mv88e6xxx_chip *chip, int port)
+{
+       return mv88e6xxx_port_ptp_write(chip, port, MV88E6XXX_PORT_PTP_CFG0,
+                                       MV88E6XXX_PORT_PTP_CFG0_DISABLE_TSPEC_MATCH);
+}
+
 static int mv88e6xxx_hwtstamp_port_setup(struct mv88e6xxx_chip *chip, int port)
 {
+       const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
        struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
 
        ps->port_id = port;
@@ -531,8 +536,10 @@ static int mv88e6xxx_hwtstamp_port_setup(struct mv88e6xxx_chip *chip, int port)
        skb_queue_head_init(&ps->rx_queue);
        skb_queue_head_init(&ps->rx_queue2);
 
-       return mv88e6xxx_port_ptp_write(chip, port, MV88E6XXX_PORT_PTP_CFG0,
-                                       MV88E6XXX_PORT_PTP_CFG0_DISABLE_PTP);
+       if (ptp_ops->port_disable)
+               return ptp_ops->port_disable(chip, port);
+
+       return 0;
 }
 
 int mv88e6xxx_hwtstamp_setup(struct mv88e6xxx_chip *chip)
index bc71c9212a0813adbe0519a9a0a27ab812bfe08a..3e601051f7c0dd70062c8cd52fbbdb98f232e664 100644 (file)
@@ -123,6 +123,8 @@ int mv88e6xxx_get_ts_info(struct dsa_switch *ds, int port,
 
 int mv88e6xxx_hwtstamp_setup(struct mv88e6xxx_chip *chip);
 void mv88e6xxx_hwtstamp_free(struct mv88e6xxx_chip *chip);
+int mv88e6352_hwtstamp_port_enable(struct mv88e6xxx_chip *chip, int port);
+int mv88e6352_hwtstamp_port_disable(struct mv88e6xxx_chip *chip, int port);
 
 #else /* !CONFIG_NET_DSA_MV88E6XXX_PTP */
 
index 485f5676fefb5acd00fac2978036fb2899044757..4963167b9e835a0a266cdd549aa802cdc5041a82 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "chip.h"
 #include "global2.h"
+#include "hwtstamp.h"
 #include "ptp.h"
 
 /* Raw timestamps are in units of 8-ns clock periods. */
@@ -318,7 +319,12 @@ const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {
        .ptp_enable = mv88e6352_ptp_enable,
        .ptp_verify = mv88e6352_ptp_verify,
        .event_work = mv88e6352_tai_event_work,
+       .port_enable = mv88e6352_hwtstamp_port_enable,
+       .port_disable = mv88e6352_hwtstamp_port_disable,
        .n_ext_ts = 1,
+       .arr0_sts_reg = MV88E6XXX_PORT_PTP_ARR0_STS,
+       .arr1_sts_reg = MV88E6XXX_PORT_PTP_ARR1_STS,
+       .dep_sts_reg = MV88E6XXX_PORT_PTP_DEP_STS,
 };
 
 const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops = {