Skip to contentSkip to conversation

cxgb4: Add PTP Hardware Clock (PHC) support

PATCH In review Atul Gupta 3 participants 6 messages Jul 4, 2017 – Jul 10, 2017

Subsystems (3)
lore
Share & tools
lore

Atul Gupta

author
#0 lore raw

cover cxgb4: Add PTP Hardware Clock (PHC) support

V4:
Splitting the patch again
V3:
Releasing lock in the exit paths
V2:
Splitting the patch

Atul Gupta (3):
cxgb4: time stamping interface for PTP
cxgb4: Add PTP Hardware Clock (PHC) support
cxgb4: Support for get_ts_info ethtool method

 drivers/net/ethernet/chelsio/cxgb4/Makefile        |   2 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h         |   9 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c |  19 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c    |  82 +++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c     | 475 +++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.h     |  74 ++++
 drivers/net/ethernet/chelsio/cxgb4/sge.c           | 173 +++++++-
 drivers/net/ethernet/chelsio/cxgb4/t4_msg.h        |  28 ++
 drivers/net/ethernet/chelsio/cxgb4/t4_regs.h       |   2 +
 drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h      |  50 +++
 10 files changed, 900 insertions(+), 14 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.h
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/3 cxgb4: time stamping interface for PTP

Supports hardware and software time stamping via the Linux SO_TIMESTAMPING socket option.

---
 drivers/net/ethernet/chelsio/cxgb4/Makefile     |   2 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h      |   9 ++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c |  76 +++++++++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c  | 194 ++++++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.h  |  74 +++++++++
 drivers/net/ethernet/chelsio/cxgb4/sge.c        | 173 ++++++++++++++++++++-
 drivers/net/ethernet/chelsio/cxgb4/t4_msg.h     |  28 ++++
 drivers/net/ethernet/chelsio/cxgb4/t4_regs.h    |   2 +
 drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h   |  50 ++++++
 9 files changed, 595 insertions(+), 13 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.h
drivers/net/ethernet/chelsio/cxgb4/Makefile +1 -1
index c6b71f6..8172127 100644
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_CHELSIO_T4) += cxgb4.o
 
-cxgb4-objs := cxgb4_main.o l2t.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o cxgb4_uld.o sched.o cxgb4_filter.o cxgb4_tc_u32.o
+cxgb4-objs := cxgb4_main.o l2t.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o cxgb4_uld.o sched.o cxgb4_filter.o cxgb4_tc_u32.o cxgb4_ptp.o
 cxgb4-$(CONFIG_CHELSIO_T4_DCB) +=  cxgb4_dcb.o
 cxgb4-$(CONFIG_CHELSIO_T4_FCOE) +=  cxgb4_fcoe.o
 cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +9 -0
index 451c138..dd6e5a3 100644
@@ -48,6 +48,8 @@
 #include <linux/vmalloc.h>
 #include <linux/etherdevice.h>
 #include <linux/net_tstamp.h>
+#include <linux/ptp_clock_kernel.h>
+#include <linux/ptp_classify.h>
 #include <asm/io.h>
 #include "t4_chip_type.h"
 #include "cxgb4_uld.h"
@@ -510,6 +512,7 @@ struct port_info {
 #endif /* CONFIG_CHELSIO_T4_FCOE */
 	bool rxtstamp;  /* Enable TS */
 	struct hwtstamp_config tstamp_config;
+	bool ptp_enable;
 	struct sched_table *sched_tbl;
 };
 
@@ -705,6 +708,7 @@ struct sge_uld_txq_info {
 
 struct sge {
 	struct sge_eth_txq ethtxq[MAX_ETH_QSETS];
+	struct sge_eth_txq ptptxq;
 	struct sge_ctrl_txq ctrlq[MAX_CTRL_QUEUES];
 
 	struct sge_eth_rxq ethrxq[MAX_ETH_QSETS];
@@ -869,6 +873,11 @@ struct adapter {
 			 * used for all 4 filters.
 			 */
 
+	struct ptp_clock *ptp_clock;
+	struct ptp_clock_info ptp_clock_info;
+	struct sk_buff *ptp_tx_skb;
+	/* ptp lock */
+	spinlock_t ptp_lock;
 	spinlock_t stats_lock;
 	spinlock_t win0_lock ____cacheline_aligned_in_smp;
 
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +70 -6

112 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c new file +194 -0

194 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.h new file +74 -0

74 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/sge.c +167 -6

276 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/t4_msg.h +28 -0
index 8098c93..b0ff78d 100644
@@ -92,6 +92,7 @@ enum {
 	CPL_RDMA_TERMINATE    = 0xA2,
 	CPL_RDMA_WRITE        = 0xA4,
 	CPL_SGE_EGR_UPDATE    = 0xA5,
+	CPL_RX_MPS_PKT        = 0xAF,
 
 	CPL_TRACE_PKT         = 0xB0,
 	CPL_ISCSI_DATA	      = 0xB2,
@@ -807,6 +808,10 @@ struct cpl_tx_pkt {
 #define TXPKT_INS_OVLAN_V(x) ((x) << TXPKT_INS_OVLAN_S)
 #define TXPKT_INS_OVLAN_F    TXPKT_INS_OVLAN_V(1U)
 
+#define TXPKT_TSTAMP_S    23
+#define TXPKT_TSTAMP_V(x) ((x) << TXPKT_TSTAMP_S)
+#define TXPKT_TSTAMP_F    TXPKT_TSTAMP_V(1ULL)
+
 #define TXPKT_OPCODE_S    24
 #define TXPKT_OPCODE_V(x) ((x) << TXPKT_OPCODE_S)
 
@@ -1875,4 +1880,27 @@ struct cpl_rx_phys_dsgl {
 	(((x) >> CPL_RX_PHYS_DSGL_NOOFSGENTR_S) & \
 	 CPL_RX_PHYS_DSGL_NOOFSGENTR_M)
 
+struct cpl_rx_mps_pkt {
+	__be32 op_to_r1_hi;
+	__be32 r1_lo_length;
+};
+
+#define CPL_RX_MPS_PKT_OP_S     24
+#define CPL_RX_MPS_PKT_OP_M     0xff
+#define CPL_RX_MPS_PKT_OP_V(x)  ((x) << CPL_RX_MPS_PKT_OP_S)
+#define CPL_RX_MPS_PKT_OP_G(x)  \
+	(((x) >> CPL_RX_MPS_PKT_OP_S) & CPL_RX_MPS_PKT_OP_M)
+
+#define CPL_RX_MPS_PKT_TYPE_S           20
+#define CPL_RX_MPS_PKT_TYPE_M           0xf
+#define CPL_RX_MPS_PKT_TYPE_V(x)        ((x) << CPL_RX_MPS_PKT_TYPE_S)
+#define CPL_RX_MPS_PKT_TYPE_G(x)        \
+	(((x) >> CPL_RX_MPS_PKT_TYPE_S) & CPL_RX_MPS_PKT_TYPE_M)
+
+enum {
+	X_CPL_RX_MPS_PKT_TYPE_PAUSE = 1 << 0,
+	X_CPL_RX_MPS_PKT_TYPE_PPP   = 1 << 1,
+	X_CPL_RX_MPS_PKT_TYPE_QFC   = 1 << 2,
+	X_CPL_RX_MPS_PKT_TYPE_PTP   = 1 << 3
+};
 #endif  /* __T4_MSG_H */
drivers/net/ethernet/chelsio/cxgb4/t4_regs.h +2 -0
index 3884336..dac9083 100644
@@ -1799,6 +1799,8 @@
 #define MPS_PORT_STAT_RX_PORT_LESS_64B_H 0x614
 #define MAC_PORT_MAGIC_MACID_LO 0x824
 #define MAC_PORT_MAGIC_MACID_HI 0x828
+#define MAC_PORT_TX_TS_VAL_LO   0x928
+#define MAC_PORT_TX_TS_VAL_HI   0x92c
 
 #define MAC_PORT_EPIO_DATA0_A 0x8c0
 #define MAC_PORT_EPIO_DATA1_A 0x8c4
drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h +50 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 2/3 cxgb4: Add PTP Hardware Clock (PHC) support

In reply to Atul Gupta

Add PTP IEEE-1588 support and make it accessible via PHC subsystem. The functionality is enabled for T5/T6 adapters. Driver interfaces with Firmware to program and adjust the clock offset.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c |   6 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c  | 281 ++++++++++++++++++++++++
 2 files changed, 287 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +6 -0
index 584aa60..86f92e3 100644
@@ -5202,6 +5202,9 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		mutex_unlock(&uld_mutex);
 	}
 
+	if (!is_t4(adapter->params.chip))
+		cxgb4_ptp_init(adapter);
+
 	print_adapter_info(adapter);
 	setup_fw_sge_queues(adapter);
 	return 0;
@@ -5311,6 +5314,9 @@ static void remove_one(struct pci_dev *pdev)
 
 		debugfs_remove_recursive(adapter->debugfs_root);
 
+		if (!is_t4(adapter->params.chip))
+			cxgb4_ptp_stop(adapter);
+
 		/* If we allocated filters, free up state associated with any
 		 * valid filters ...
 		 */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c +281 -0

284 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#4 lore raw

PATCH 3/3 cxgb4: Support for get_ts_info ethtool method

In reply to Atul Gupta
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +18 -1
index e9bab72..26eb00a 100644
@@ -1113,14 +1113,31 @@ static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
 
 static int get_ts_info(struct net_device *dev, struct ethtool_ts_info *ts_info)
 {
+	struct port_info *pi = netdev_priv(dev);
+	struct  adapter *adapter = pi->adapter;
+
 	ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
 				   SOF_TIMESTAMPING_RX_SOFTWARE |
 				   SOF_TIMESTAMPING_SOFTWARE;
 
 	ts_info->so_timestamping |= SOF_TIMESTAMPING_RX_HARDWARE |
+				    SOF_TIMESTAMPING_TX_HARDWARE |
 				    SOF_TIMESTAMPING_RAW_HARDWARE;
 
-	ts_info->phc_index = -1;
+	ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) |
+			    (1 << HWTSTAMP_TX_ON);
+
+	ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
+			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
+			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
+			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
+			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
+			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
+
+	if (adapter->ptp_clock)
+		ts_info->phc_index = ptp_clock_index(adapter->ptp_clock);
+	else
+		ts_info->phc_index = -1;
 
 	return 0;
 }
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Atul Gupta
Quoted 14 lines · Atul Gupta
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c +14 -0
+/**
+ * cxgb4_ptp_init - initialize PTP for devices which support it
+ * @adapter: board private structure
+ *
+ * This function performs the required steps for enabling PTP support.
+ */
+void cxgb4_ptp_init(struct adapter *adapter)
+{
+	struct timespec64 now;
+	 /* no need to create a clock device if we already have one */
+	if (!IS_ERR_OR_NULL(adapter->ptp_clock))
+		return;
+
+	adapter->ptp_tx_skb = NULL;

drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c int cxgb4_ptp_redirect_rx_packet(struct adapter *adapter, struct port_info *pi) · line 448

Quoted 10 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c +10 -0
+	adapter->ptp_clock_info = cxgb4_ptp_clock_info;
+	spin_lock_init(&adapter->ptp_lock);
+
+	adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info,
+						&adapter->pdev->dev);
+	if (!adapter->ptp_clock) {
+		dev_err(adapter->pdev_dev,
+			"PTP %s Clock registration has failed\n", __func__);
+		return;
+	}

This is wrong. To quote the header file:

/**
* ptp_clock_register() - register a PTP hardware clock driver *
* @info: Structure describing the new clock.
* @parent: Pointer to the parent device of the new clock. *
* Returns a valid pointer on success or PTR_ERR on failure. If PHC
* support is missing at the configuration level, this function
* returns NULL, and drivers are expected to gracefully handle that
* case separately.
*/

As this has already been merged, please submit a patch to properly handle both PTR_ERR and NULL.

Thanks,
Richard