Skip to content

Commit 45d0fcb

Browse files
vladimirolteanPaolo Abeni
authored andcommitted
net: mscc: ocelot: don't keep PTP configuration of all ports in single structure
In a future change, the driver will need to determine whether PTP RX timestamping is enabled on a port (including whether traps were set up on that port in particular) and that is currently not possible. The driver supports different RX filters (L2, L4) and kinds of TX timestamping (one-step, two-step) on its ports, but it saves all configuration in a single struct hwtstamp_config that is global to the switch. So, the latest timestamping configuration on one port (including a request to disable timestamping) affects what gets reported for all ports, even though the configuration itself is still individual to each port. The port timestamping configurations are only coupled because of the common structure, so replace the hwtstamp_config with a mask of trapped protocols saved per port. We also have the ptp_cmd to distinguish between one-step and two-step PTP timestamping, so with those 2 bits of information we can fully reconstruct a descriptive struct hwtstamp_config for each port, during the SIOCGHWTSTAMP ioctl. Fixes: 4e3b046 ("net: mscc: PTP Hardware Clock (PHC) support") Fixes: 96ca08c ("net: mscc: ocelot: set up traps for PTP packets") Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 4fd44b8 commit 45d0fcb

File tree

3 files changed

+48
-24
lines changed

3 files changed

+48
-24
lines changed

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,6 @@ int ocelot_init(struct ocelot *ocelot)
29252925
}
29262926
}
29272927

2928-
mutex_init(&ocelot->ptp_lock);
29292928
mutex_init(&ocelot->mact_lock);
29302929
mutex_init(&ocelot->fwd_domain_lock);
29312930
mutex_init(&ocelot->tas_lock);

drivers/net/ethernet/mscc/ocelot_ptp.c

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,12 @@ static int ocelot_ipv6_ptp_trap_del(struct ocelot *ocelot, int port)
439439
static int ocelot_setup_ptp_traps(struct ocelot *ocelot, int port,
440440
bool l2, bool l4)
441441
{
442+
struct ocelot_port *ocelot_port = ocelot->ports[port];
442443
int err;
443444

445+
ocelot_port->trap_proto &= ~(OCELOT_PROTO_PTP_L2 |
446+
OCELOT_PROTO_PTP_L4);
447+
444448
if (l2)
445449
err = ocelot_l2_ptp_trap_add(ocelot, port);
446450
else
@@ -464,6 +468,11 @@ static int ocelot_setup_ptp_traps(struct ocelot *ocelot, int port,
464468
if (err)
465469
return err;
466470

471+
if (l2)
472+
ocelot_port->trap_proto |= OCELOT_PROTO_PTP_L2;
473+
if (l4)
474+
ocelot_port->trap_proto |= OCELOT_PROTO_PTP_L4;
475+
467476
return 0;
468477

469478
err_ipv6:
@@ -474,10 +483,38 @@ static int ocelot_setup_ptp_traps(struct ocelot *ocelot, int port,
474483
return err;
475484
}
476485

486+
static int ocelot_traps_to_ptp_rx_filter(unsigned int proto)
487+
{
488+
if ((proto & OCELOT_PROTO_PTP_L2) && (proto & OCELOT_PROTO_PTP_L4))
489+
return HWTSTAMP_FILTER_PTP_V2_EVENT;
490+
else if (proto & OCELOT_PROTO_PTP_L2)
491+
return HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
492+
else if (proto & OCELOT_PROTO_PTP_L4)
493+
return HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
494+
495+
return HWTSTAMP_FILTER_NONE;
496+
}
497+
477498
int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr)
478499
{
479-
return copy_to_user(ifr->ifr_data, &ocelot->hwtstamp_config,
480-
sizeof(ocelot->hwtstamp_config)) ? -EFAULT : 0;
500+
struct ocelot_port *ocelot_port = ocelot->ports[port];
501+
struct hwtstamp_config cfg = {};
502+
503+
switch (ocelot_port->ptp_cmd) {
504+
case IFH_REW_OP_TWO_STEP_PTP:
505+
cfg.tx_type = HWTSTAMP_TX_ON;
506+
break;
507+
case IFH_REW_OP_ORIGIN_PTP:
508+
cfg.tx_type = HWTSTAMP_TX_ONESTEP_SYNC;
509+
break;
510+
default:
511+
cfg.tx_type = HWTSTAMP_TX_OFF;
512+
break;
513+
}
514+
515+
cfg.rx_filter = ocelot_traps_to_ptp_rx_filter(ocelot_port->trap_proto);
516+
517+
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
481518
}
482519
EXPORT_SYMBOL(ocelot_hwstamp_get);
483520

@@ -509,8 +546,6 @@ int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr)
509546
return -ERANGE;
510547
}
511548

512-
mutex_lock(&ocelot->ptp_lock);
513-
514549
switch (cfg.rx_filter) {
515550
case HWTSTAMP_FILTER_NONE:
516551
break;
@@ -531,28 +566,14 @@ int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr)
531566
l4 = true;
532567
break;
533568
default:
534-
mutex_unlock(&ocelot->ptp_lock);
535569
return -ERANGE;
536570
}
537571

538572
err = ocelot_setup_ptp_traps(ocelot, port, l2, l4);
539-
if (err) {
540-
mutex_unlock(&ocelot->ptp_lock);
573+
if (err)
541574
return err;
542-
}
543-
544-
if (l2 && l4)
545-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
546-
else if (l2)
547-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
548-
else if (l4)
549-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
550-
else
551-
cfg.rx_filter = HWTSTAMP_FILTER_NONE;
552575

553-
/* Commit back the result & save it */
554-
memcpy(&ocelot->hwtstamp_config, &cfg, sizeof(cfg));
555-
mutex_unlock(&ocelot->ptp_lock);
576+
cfg.rx_filter = ocelot_traps_to_ptp_rx_filter(ocelot_port->trap_proto);
556577

557578
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
558579
}

include/soc/mscc/ocelot.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,11 @@ enum macaccess_entry_type {
730730
ENTRYTYPE_MACv6,
731731
};
732732

733+
enum ocelot_proto {
734+
OCELOT_PROTO_PTP_L2 = BIT(0),
735+
OCELOT_PROTO_PTP_L4 = BIT(1),
736+
};
737+
733738
#define OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION BIT(0)
734739
#define OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP BIT(1)
735740

@@ -775,6 +780,8 @@ struct ocelot_port {
775780
unsigned int ptp_skbs_in_flight;
776781
struct sk_buff_head tx_skbs;
777782

783+
unsigned int trap_proto;
784+
778785
u16 mrp_ring_id;
779786

780787
u8 ptp_cmd;
@@ -868,12 +875,9 @@ struct ocelot {
868875
u8 mm_supported:1;
869876
struct ptp_clock *ptp_clock;
870877
struct ptp_clock_info ptp_info;
871-
struct hwtstamp_config hwtstamp_config;
872878
unsigned int ptp_skbs_in_flight;
873879
/* Protects the 2-step TX timestamp ID logic */
874880
spinlock_t ts_id_lock;
875-
/* Protects the PTP interface state */
876-
struct mutex ptp_lock;
877881
/* Protects the PTP clock */
878882
spinlock_t ptp_clock_lock;
879883
struct ptp_pin_desc ptp_pins[OCELOT_PTP_PINS_NUM];

0 commit comments

Comments
 (0)