Skip to content

Commit c6fe0ad

Browse files
bstreiffdavem330
authored andcommitted
net: dsa: mv88e6xxx: add rx/tx timestamping support
This patch implements RX/TX timestamping support. The Marvell PTP hardware supports RX timestamping individual message types, but for simplicity we only support the EVENT receive filter since few if any clients bother with the more specific filter types. checkpatch and reverse Christmas tree changes by Andrew Lunn. Re-factor duplicated code paths and avoid IfOk anti-pattern, use the common ptp worker thread from the class layer and time stamp UDP/IPv4 frames as well as Layer-2 frame by Richard Cochran. Signed-off-by: Brandon Streiff <[email protected]> Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: Richard Cochran <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 90af105 commit c6fe0ad

File tree

7 files changed

+788
-4
lines changed

7 files changed

+788
-4
lines changed

drivers/net/dsa/mv88e6xxx/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mv88e6xxx-objs += global1_vtu.o
77
mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_GLOBAL2) += global2.o
88
mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_GLOBAL2) += global2_avb.o
99
mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_GLOBAL2) += global2_scratch.o
10+
mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_PTP) += hwtstamp.o
1011
mv88e6xxx-objs += phy.o
1112
mv88e6xxx-objs += port.o
1213
mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_PTP) += ptp.o

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "chip.h"
3737
#include "global1.h"
3838
#include "global2.h"
39+
#include "hwtstamp.h"
3940
#include "phy.h"
4041
#include "port.h"
4142
#include "ptp.h"
@@ -2093,11 +2094,15 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
20932094
if (err)
20942095
goto unlock;
20952096

2096-
/* Setup PTP Hardware Clock */
2097+
/* Setup PTP Hardware Clock and timestamping */
20972098
if (chip->info->ptp_support) {
20982099
err = mv88e6xxx_ptp_setup(chip);
20992100
if (err)
21002101
goto unlock;
2102+
2103+
err = mv88e6xxx_hwtstamp_setup(chip);
2104+
if (err)
2105+
goto unlock;
21012106
}
21022107

21032108
unlock:
@@ -3932,6 +3937,11 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
39323937
.port_mdb_del = mv88e6xxx_port_mdb_del,
39333938
.crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
39343939
.crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
3940+
.port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
3941+
.port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
3942+
.port_txtstamp = mv88e6xxx_port_txtstamp,
3943+
.port_rxtstamp = mv88e6xxx_port_rxtstamp,
3944+
.get_ts_info = mv88e6xxx_get_ts_info,
39353945
};
39363946

39373947
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
@@ -4074,8 +4084,10 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev)
40744084
struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
40754085
struct mv88e6xxx_chip *chip = ds->priv;
40764086

4077-
if (chip->info->ptp_support)
4087+
if (chip->info->ptp_support) {
4088+
mv88e6xxx_hwtstamp_free(chip);
40784089
mv88e6xxx_ptp_free(chip);
4090+
}
40794091

40804092
mv88e6xxx_phy_destroy(chip);
40814093
mv88e6xxx_unregister_switch(chip);

drivers/net/dsa/mv88e6xxx/chip.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,32 @@ struct mv88e6xxx_irq {
164164
unsigned int nirqs;
165165
};
166166

167+
/* state flags for mv88e6xxx_port_hwtstamp::state */
168+
enum {
169+
MV88E6XXX_HWTSTAMP_ENABLED,
170+
MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS,
171+
};
172+
173+
struct mv88e6xxx_port_hwtstamp {
174+
/* Port index */
175+
int port_id;
176+
177+
/* Timestamping state */
178+
unsigned long state;
179+
180+
/* Resources for receive timestamping */
181+
struct sk_buff_head rx_queue;
182+
struct sk_buff_head rx_queue2;
183+
184+
/* Resources for transmit timestamping */
185+
unsigned long tx_tstamp_start;
186+
struct sk_buff *tx_skb;
187+
u16 tx_seq_id;
188+
189+
/* Current timestamp configuration */
190+
struct hwtstamp_config tstamp_config;
191+
};
192+
167193
struct mv88e6xxx_chip {
168194
const struct mv88e6xxx_info *info;
169195

@@ -236,6 +262,9 @@ struct mv88e6xxx_chip {
236262
struct ptp_pin_desc pin_config[MV88E6XXX_MAX_GPIO];
237263
u16 trig_config;
238264
u16 evcap_config;
265+
266+
/* Per-port timestamping resources. */
267+
struct mv88e6xxx_port_hwtstamp port_hwtstamp[DSA_MAX_PORTS];
239268
};
240269

241270
struct mv88e6xxx_bus_ops {

0 commit comments

Comments
 (0)