Skip to content

Commit 6df76e0

Browse files
committed
drivers: eth: mcux: Allow gPTP over VLAN
If VLAN is enabled for specific PTP interface, then manipulate the ethernet header properly in this case. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 452d00d commit 6df76e0

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

drivers/ethernet/eth_mcux.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,21 +367,46 @@ static void eth_mcux_delayed_phy_work(struct k_work *item)
367367
static enet_ptp_time_data_t ptp_rx_buffer[CONFIG_ETH_MCUX_PTP_RX_BUFFERS];
368368
static enet_ptp_time_data_t ptp_tx_buffer[CONFIG_ETH_MCUX_PTP_TX_BUFFERS];
369369

370-
static bool eth_get_ptp_data(struct net_pkt *pkt,
370+
static bool eth_get_ptp_data(struct net_if *iface, struct net_pkt *pkt,
371371
enet_ptp_time_data_t *ptpTsData)
372372
{
373373
struct gptp_hdr *hdr;
374374

375-
if (ntohs(NET_ETH_HDR(pkt)->type) != NET_ETH_PTYPE_PTP) {
376-
return false;
375+
#if defined(CONFIG_NET_VLAN)
376+
struct net_eth_vlan_hdr *hdr_vlan;
377+
struct ethernet_context *eth_ctx;
378+
bool vlan_enabled = false;
379+
380+
eth_ctx = net_if_l2_data(iface);
381+
if (net_eth_is_vlan_enabled(eth_ctx, iface)) {
382+
hdr_vlan = (struct net_eth_vlan_hdr *)NET_ETH_HDR(pkt);
383+
vlan_enabled = true;
384+
385+
if (ntohs(hdr_vlan->type) != NET_ETH_PTYPE_PTP) {
386+
return false;
387+
}
388+
} else
389+
#endif
390+
{
391+
if (ntohs(NET_ETH_HDR(pkt)->type) != NET_ETH_PTYPE_PTP) {
392+
return false;
393+
}
377394
}
378395

379396
if (ptpTsData) {
380397

381398
/* Cannot use GPTP_HDR as net_pkt fields are not all filled */
382399

383-
hdr = (struct gptp_hdr *)((u8_t *)net_pkt_ll(pkt)
384-
+ sizeof(struct net_eth_hdr));
400+
#if defined(CONFIG_NET_VLAN)
401+
if (vlan_enabled) {
402+
hdr = (struct gptp_hdr *)((u8_t *)net_pkt_ll(pkt)
403+
+ sizeof(struct net_eth_vlan_hdr));
404+
} else
405+
#endif
406+
{
407+
hdr = (struct gptp_hdr *)((u8_t *)net_pkt_ll(pkt)
408+
+ sizeof(struct net_eth_hdr));
409+
}
385410

386411
ptpTsData->version = hdr->ptp_version;
387412
memcpy(ptpTsData->sourcePortId, &hdr->port_id,
@@ -465,7 +490,7 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
465490
total_len);
466491

467492
#if defined(CONFIG_NET_PKT_TIMESTAMP)
468-
timestamped_frame = eth_get_ptp_data(pkt, NULL);
493+
timestamped_frame = eth_get_ptp_data(iface, pkt, NULL);
469494
if (timestamped_frame) {
470495
if (!status) {
471496
ts_tx_pkt[ts_tx_wr] = net_pkt_ref(pkt);
@@ -621,7 +646,8 @@ static void eth_rx(struct device *iface)
621646
#endif
622647

623648
#if defined(CONFIG_NET_PKT_TIMESTAMP)
624-
if (eth_get_ptp_data(pkt, &ptpTimeData) &&
649+
if (eth_get_ptp_data(get_iface(context, vlan_tag), pkt,
650+
&ptpTimeData) &&
625651
(ENET_GetRxFrameTime(&context->enet_handle,
626652
&ptpTimeData) == kStatus_Success)) {
627653
pkt->timestamp.nanosecond = ptpTimeData.timeStamp.nanosecond;
@@ -648,7 +674,7 @@ static inline void ts_register_tx_event(struct eth_context *context)
648674

649675
pkt = ts_tx_pkt[ts_tx_rd];
650676
if (pkt && pkt->ref > 0) {
651-
if (eth_get_ptp_data(pkt, &timeData)) {
677+
if (eth_get_ptp_data(net_pkt_iface(pkt), pkt, &timeData)) {
652678
int status;
653679

654680
status = ENET_GetTxFrameTime(&context->enet_handle,

0 commit comments

Comments
 (0)