[PATCH net-next v6 2/2] net: thunderx: add timestamping support
From: Sunil GouthamThis adds timestamping support for both receive and transmit paths. On the receive side no filters are supported i.e either all pkts will get a timestamp appended infront of the packet or none. On the transmit side HW doesn't support timestamp insertion but only generates a separate CQE with transmitted packet's timestamp. Also HW supports only one packet at a time for timestamping on the transmit side. Signed-off-by: Sunil Goutham Signed-off-by: Aleksey Makarov Acked-by: Philippe Ombredanne --- drivers/net/ethernet/cavium/Kconfig| 1 + drivers/net/ethernet/cavium/thunder/nic.h | 36 + drivers/net/ethernet/cavium/thunder/nic_main.c | 56 ++- drivers/net/ethernet/cavium/thunder/nic_reg.h | 1 + .../net/ethernet/cavium/thunder/nicvf_ethtool.c| 29 +++- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 169 - drivers/net/ethernet/cavium/thunder/nicvf_queues.c | 26 drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 29 drivers/net/ethernet/cavium/thunder/thunder_bgx.h | 4 + 9 files changed, 345 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/cavium/Kconfig b/drivers/net/ethernet/cavium/Kconfig index 96586c0b4490..043e3c11c42b 100644 --- a/drivers/net/ethernet/cavium/Kconfig +++ b/drivers/net/ethernet/cavium/Kconfig @@ -27,6 +27,7 @@ config THUNDER_NIC_PF config THUNDER_NIC_VF tristate "Thunder Virtual function driver" + imply CAVIUM_PTP depends on 64BIT ---help--- This driver supports Thunder's NIC virtual function diff --git a/drivers/net/ethernet/cavium/thunder/nic.h b/drivers/net/ethernet/cavium/thunder/nic.h index 4a02e618e318..4cacce5d2b16 100644 --- a/drivers/net/ethernet/cavium/thunder/nic.h +++ b/drivers/net/ethernet/cavium/thunder/nic.h @@ -263,6 +263,8 @@ struct nicvf_drv_stats { struct u64_stats_sync syncp; }; +struct cavium_ptp; + struct nicvf { struct nicvf*pnicvf; struct net_device *netdev; @@ -312,6 +314,33 @@ struct nicvf { struct tasklet_struct qs_err_task; struct work_struct reset_task; + /* PTP timestamp */ + struct cavium_ptp *ptp_clock; + /* Inbound timestamping is on */ + boolhw_rx_tstamp; + /* When the packet that requires timestamping is sent, hardware inserts +* two entries to the completion queue. First is the regular +* CQE_TYPE_SEND entry that signals that the packet was sent. +* The second is CQE_TYPE_SEND_PTP that contains the actual timestamp +* for that packet. +* `ptp_skb` is initialized in the handler for the CQE_TYPE_SEND +* entry and is used and zeroed in the handler for the CQE_TYPE_SEND_PTP +* entry. +* So `ptp_skb` is used to hold the pointer to the packet between +* the calls to CQE_TYPE_SEND and CQE_TYPE_SEND_PTP handlers. +*/ + struct sk_buff *ptp_skb; + /* `tx_ptp_skbs` is set when the hardware is sending a packet that +* requires timestamping. Cavium hardware can not process more than one +* such packet at once so this is set each time the driver submits +* a packet that requires timestamping to the send queue and clears +* each time it receives the entry on the completion queue saying +* that such packet was sent. +* So `tx_ptp_skbs` prevents driver from submitting more than one +* packet that requires timestamping to the hardware for transmitting. +*/ + atomic_ttx_ptp_skbs; + /* Interrupt coalescing settings */ u32 cq_coalesce_usecs; u32 msg_enable; @@ -371,6 +400,7 @@ struct nicvf { #defineNIC_MBOX_MSG_LOOPBACK 0x16/* Set interface in loopback */ #defineNIC_MBOX_MSG_RESET_STAT_COUNTER 0x17/* Reset statistics counters */ #defineNIC_MBOX_MSG_PFC0x18/* Pause frame control */ +#defineNIC_MBOX_MSG_PTP_CFG0x19/* HW packet timestamp */ #defineNIC_MBOX_MSG_CFG_DONE 0xF0/* VF configuration done */ #defineNIC_MBOX_MSG_SHUTDOWN 0xF1/* VF is being shutdown */ @@ -521,6 +551,11 @@ struct pfc { u8fc_tx; }; +struct set_ptp { + u8msg; + bool enable; +}; + /* 128 bit shared memory between PF and each VF */ union nic_mbx { struct { u8 msg; } msg; @@ -540,6 +575,7 @@ union nic_mbx { struct set_loopback lbk; struct reset_stat_cfg reset_stat; struct pfc pfc; + struct set_ptp ptp; }; #define NIC_NODE_ID_MASK 0x03 diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c
[PATCH net-next v6 2/2] net: thunderx: add timestamping support
From: Sunil Goutham This adds timestamping support for both receive and transmit paths. On the receive side no filters are supported i.e either all pkts will get a timestamp appended infront of the packet or none. On the transmit side HW doesn't support timestamp insertion but only generates a separate CQE with transmitted packet's timestamp. Also HW supports only one packet at a time for timestamping on the transmit side. Signed-off-by: Sunil Goutham Signed-off-by: Aleksey Makarov Acked-by: Philippe Ombredanne --- drivers/net/ethernet/cavium/Kconfig| 1 + drivers/net/ethernet/cavium/thunder/nic.h | 36 + drivers/net/ethernet/cavium/thunder/nic_main.c | 56 ++- drivers/net/ethernet/cavium/thunder/nic_reg.h | 1 + .../net/ethernet/cavium/thunder/nicvf_ethtool.c| 29 +++- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 169 - drivers/net/ethernet/cavium/thunder/nicvf_queues.c | 26 drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 29 drivers/net/ethernet/cavium/thunder/thunder_bgx.h | 4 + 9 files changed, 345 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/cavium/Kconfig b/drivers/net/ethernet/cavium/Kconfig index 96586c0b4490..043e3c11c42b 100644 --- a/drivers/net/ethernet/cavium/Kconfig +++ b/drivers/net/ethernet/cavium/Kconfig @@ -27,6 +27,7 @@ config THUNDER_NIC_PF config THUNDER_NIC_VF tristate "Thunder Virtual function driver" + imply CAVIUM_PTP depends on 64BIT ---help--- This driver supports Thunder's NIC virtual function diff --git a/drivers/net/ethernet/cavium/thunder/nic.h b/drivers/net/ethernet/cavium/thunder/nic.h index 4a02e618e318..4cacce5d2b16 100644 --- a/drivers/net/ethernet/cavium/thunder/nic.h +++ b/drivers/net/ethernet/cavium/thunder/nic.h @@ -263,6 +263,8 @@ struct nicvf_drv_stats { struct u64_stats_sync syncp; }; +struct cavium_ptp; + struct nicvf { struct nicvf*pnicvf; struct net_device *netdev; @@ -312,6 +314,33 @@ struct nicvf { struct tasklet_struct qs_err_task; struct work_struct reset_task; + /* PTP timestamp */ + struct cavium_ptp *ptp_clock; + /* Inbound timestamping is on */ + boolhw_rx_tstamp; + /* When the packet that requires timestamping is sent, hardware inserts +* two entries to the completion queue. First is the regular +* CQE_TYPE_SEND entry that signals that the packet was sent. +* The second is CQE_TYPE_SEND_PTP that contains the actual timestamp +* for that packet. +* `ptp_skb` is initialized in the handler for the CQE_TYPE_SEND +* entry and is used and zeroed in the handler for the CQE_TYPE_SEND_PTP +* entry. +* So `ptp_skb` is used to hold the pointer to the packet between +* the calls to CQE_TYPE_SEND and CQE_TYPE_SEND_PTP handlers. +*/ + struct sk_buff *ptp_skb; + /* `tx_ptp_skbs` is set when the hardware is sending a packet that +* requires timestamping. Cavium hardware can not process more than one +* such packet at once so this is set each time the driver submits +* a packet that requires timestamping to the send queue and clears +* each time it receives the entry on the completion queue saying +* that such packet was sent. +* So `tx_ptp_skbs` prevents driver from submitting more than one +* packet that requires timestamping to the hardware for transmitting. +*/ + atomic_ttx_ptp_skbs; + /* Interrupt coalescing settings */ u32 cq_coalesce_usecs; u32 msg_enable; @@ -371,6 +400,7 @@ struct nicvf { #defineNIC_MBOX_MSG_LOOPBACK 0x16/* Set interface in loopback */ #defineNIC_MBOX_MSG_RESET_STAT_COUNTER 0x17/* Reset statistics counters */ #defineNIC_MBOX_MSG_PFC0x18/* Pause frame control */ +#defineNIC_MBOX_MSG_PTP_CFG0x19/* HW packet timestamp */ #defineNIC_MBOX_MSG_CFG_DONE 0xF0/* VF configuration done */ #defineNIC_MBOX_MSG_SHUTDOWN 0xF1/* VF is being shutdown */ @@ -521,6 +551,11 @@ struct pfc { u8fc_tx; }; +struct set_ptp { + u8msg; + bool enable; +}; + /* 128 bit shared memory between PF and each VF */ union nic_mbx { struct { u8 msg; } msg; @@ -540,6 +575,7 @@ union nic_mbx { struct set_loopback lbk; struct reset_stat_cfg reset_stat; struct pfc pfc; + struct set_ptp ptp; }; #define NIC_NODE_ID_MASK 0x03 diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c b/drivers/net/ethernet/cavium/thunder/nic_main.c index 8f1dd55b3e08..8325577d7442 100644 ---