mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	lan743x: lan743x: Add PTP support
PTP support includes:
    Ingress, and egress timestamping.
    One step timestamping available.
    PTP clock support.
    Periodic output support.
Signed-off-by: Bryan Whitehead <Bryan.Whitehead@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
			
			
This commit is contained in:
		
							parent
							
								
									217e502b89
								
							
						
					
					
						commit
						07624df1c9
					
				
					 6 changed files with 1443 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -6,4 +6,4 @@ obj-$(CONFIG_ENC28J60) += enc28j60.o
 | 
			
		|||
obj-$(CONFIG_ENCX24J600) += encx24j600.o encx24j600-regmap.o
 | 
			
		||||
obj-$(CONFIG_LAN743X) += lan743x.o
 | 
			
		||||
 | 
			
		||||
lan743x-objs := lan743x_main.o lan743x_ethtool.o
 | 
			
		||||
lan743x-objs := lan743x_main.o lan743x_ethtool.o lan743x_ptp.o
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
#include <linux/netdevice.h>
 | 
			
		||||
#include "lan743x_main.h"
 | 
			
		||||
#include "lan743x_ethtool.h"
 | 
			
		||||
#include <linux/net_tstamp.h>
 | 
			
		||||
#include <linux/pci.h>
 | 
			
		||||
#include <linux/phy.h>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -542,6 +543,31 @@ static int lan743x_ethtool_set_rxfh(struct net_device *netdev,
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int lan743x_ethtool_get_ts_info(struct net_device *netdev,
 | 
			
		||||
				       struct ethtool_ts_info *ts_info)
 | 
			
		||||
{
 | 
			
		||||
	struct lan743x_adapter *adapter = netdev_priv(netdev);
 | 
			
		||||
 | 
			
		||||
	ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
 | 
			
		||||
				   SOF_TIMESTAMPING_RX_SOFTWARE |
 | 
			
		||||
				   SOF_TIMESTAMPING_SOFTWARE |
 | 
			
		||||
				   SOF_TIMESTAMPING_TX_HARDWARE |
 | 
			
		||||
				   SOF_TIMESTAMPING_RX_HARDWARE |
 | 
			
		||||
				   SOF_TIMESTAMPING_RAW_HARDWARE;
 | 
			
		||||
 | 
			
		||||
	if (adapter->ptp.ptp_clock)
 | 
			
		||||
		ts_info->phc_index = ptp_clock_index(adapter->ptp.ptp_clock);
 | 
			
		||||
	else
 | 
			
		||||
		ts_info->phc_index = -1;
 | 
			
		||||
 | 
			
		||||
	ts_info->tx_types = BIT(HWTSTAMP_TX_OFF) |
 | 
			
		||||
			    BIT(HWTSTAMP_TX_ON) |
 | 
			
		||||
			    BIT(HWTSTAMP_TX_ONESTEP_SYNC);
 | 
			
		||||
	ts_info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
 | 
			
		||||
			      BIT(HWTSTAMP_FILTER_ALL);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int lan743x_ethtool_get_eee(struct net_device *netdev,
 | 
			
		||||
				   struct ethtool_eee *eee)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -685,6 +711,7 @@ const struct ethtool_ops lan743x_ethtool_ops = {
 | 
			
		|||
	.get_rxfh_indir_size = lan743x_ethtool_get_rxfh_indir_size,
 | 
			
		||||
	.get_rxfh = lan743x_ethtool_get_rxfh,
 | 
			
		||||
	.set_rxfh = lan743x_ethtool_set_rxfh,
 | 
			
		||||
	.get_ts_info = lan743x_ethtool_get_ts_info,
 | 
			
		||||
	.get_eee = lan743x_ethtool_get_eee,
 | 
			
		||||
	.set_eee = lan743x_ethtool_set_eee,
 | 
			
		||||
	.get_link_ksettings = phy_ethtool_get_link_ksettings,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -267,6 +267,10 @@ static void lan743x_intr_shared_isr(void *context, u32 int_sts, u32 flags)
 | 
			
		|||
			lan743x_intr_software_isr(adapter);
 | 
			
		||||
			int_sts &= ~INT_BIT_SW_GP_;
 | 
			
		||||
		}
 | 
			
		||||
		if (int_sts & INT_BIT_1588_) {
 | 
			
		||||
			lan743x_ptp_isr(adapter);
 | 
			
		||||
			int_sts &= ~INT_BIT_1588_;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (int_sts)
 | 
			
		||||
		lan743x_csr_write(adapter, INT_EN_CLR, int_sts);
 | 
			
		||||
| 
						 | 
				
			
			@ -976,6 +980,7 @@ static void lan743x_phy_link_status_change(struct net_device *netdev)
 | 
			
		|||
					       ksettings.base.duplex,
 | 
			
		||||
					       local_advertisement,
 | 
			
		||||
					       remote_advertisement);
 | 
			
		||||
		lan743x_ptp_update_latency(adapter, ksettings.base.speed);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1226,6 +1231,7 @@ static void lan743x_tx_release_desc(struct lan743x_tx *tx,
 | 
			
		|||
	struct lan743x_tx_buffer_info *buffer_info = NULL;
 | 
			
		||||
	struct lan743x_tx_descriptor *descriptor = NULL;
 | 
			
		||||
	u32 descriptor_type = 0;
 | 
			
		||||
	bool ignore_sync;
 | 
			
		||||
 | 
			
		||||
	descriptor = &tx->ring_cpu_ptr[descriptor_index];
 | 
			
		||||
	buffer_info = &tx->buffer_info[descriptor_index];
 | 
			
		||||
| 
						 | 
				
			
			@ -1256,11 +1262,27 @@ static void lan743x_tx_release_desc(struct lan743x_tx *tx,
 | 
			
		|||
		buffer_info->dma_ptr = 0;
 | 
			
		||||
		buffer_info->buffer_length = 0;
 | 
			
		||||
	}
 | 
			
		||||
	if (buffer_info->skb) {
 | 
			
		||||
	if (!buffer_info->skb)
 | 
			
		||||
		goto clear_active;
 | 
			
		||||
 | 
			
		||||
	if (!(buffer_info->flags & TX_BUFFER_INFO_FLAG_TIMESTAMP_REQUESTED)) {
 | 
			
		||||
		dev_kfree_skb(buffer_info->skb);
 | 
			
		||||
		buffer_info->skb = NULL;
 | 
			
		||||
		goto clear_skb;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (cleanup) {
 | 
			
		||||
		lan743x_ptp_unrequest_tx_timestamp(tx->adapter);
 | 
			
		||||
		dev_kfree_skb(buffer_info->skb);
 | 
			
		||||
	} else {
 | 
			
		||||
		ignore_sync = (buffer_info->flags &
 | 
			
		||||
			       TX_BUFFER_INFO_FLAG_IGNORE_SYNC) != 0;
 | 
			
		||||
		lan743x_ptp_tx_timestamp_skb(tx->adapter,
 | 
			
		||||
					     buffer_info->skb, ignore_sync);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
clear_skb:
 | 
			
		||||
	buffer_info->skb = NULL;
 | 
			
		||||
 | 
			
		||||
clear_active:
 | 
			
		||||
	buffer_info->flags &= ~TX_BUFFER_INFO_FLAG_ACTIVE;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1321,10 +1343,25 @@ static int lan743x_tx_get_avail_desc(struct lan743x_tx *tx)
 | 
			
		|||
		return last_head - last_tail - 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void lan743x_tx_set_timestamping_mode(struct lan743x_tx *tx,
 | 
			
		||||
				      bool enable_timestamping,
 | 
			
		||||
				      bool enable_onestep_sync)
 | 
			
		||||
{
 | 
			
		||||
	if (enable_timestamping)
 | 
			
		||||
		tx->ts_flags |= TX_TS_FLAG_TIMESTAMPING_ENABLED;
 | 
			
		||||
	else
 | 
			
		||||
		tx->ts_flags &= ~TX_TS_FLAG_TIMESTAMPING_ENABLED;
 | 
			
		||||
	if (enable_onestep_sync)
 | 
			
		||||
		tx->ts_flags |= TX_TS_FLAG_ONE_STEP_SYNC;
 | 
			
		||||
	else
 | 
			
		||||
		tx->ts_flags &= ~TX_TS_FLAG_ONE_STEP_SYNC;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int lan743x_tx_frame_start(struct lan743x_tx *tx,
 | 
			
		||||
				  unsigned char *first_buffer,
 | 
			
		||||
				  unsigned int first_buffer_length,
 | 
			
		||||
				  unsigned int frame_length,
 | 
			
		||||
				  bool time_stamp,
 | 
			
		||||
				  bool check_sum)
 | 
			
		||||
{
 | 
			
		||||
	/* called only from within lan743x_tx_xmit_frame.
 | 
			
		||||
| 
						 | 
				
			
			@ -1362,6 +1399,8 @@ static int lan743x_tx_frame_start(struct lan743x_tx *tx,
 | 
			
		|||
		TX_DESC_DATA0_DTYPE_DATA_ |
 | 
			
		||||
		TX_DESC_DATA0_FS_ |
 | 
			
		||||
		TX_DESC_DATA0_FCS_;
 | 
			
		||||
	if (time_stamp)
 | 
			
		||||
		tx->frame_data0 |= TX_DESC_DATA0_TSE_;
 | 
			
		||||
 | 
			
		||||
	if (check_sum)
 | 
			
		||||
		tx->frame_data0 |= TX_DESC_DATA0_ICE_ |
 | 
			
		||||
| 
						 | 
				
			
			@ -1475,6 +1514,7 @@ static int lan743x_tx_frame_add_fragment(struct lan743x_tx *tx,
 | 
			
		|||
 | 
			
		||||
static void lan743x_tx_frame_end(struct lan743x_tx *tx,
 | 
			
		||||
				 struct sk_buff *skb,
 | 
			
		||||
				 bool time_stamp,
 | 
			
		||||
				 bool ignore_sync)
 | 
			
		||||
{
 | 
			
		||||
	/* called only from within lan743x_tx_xmit_frame
 | 
			
		||||
| 
						 | 
				
			
			@ -1492,6 +1532,8 @@ static void lan743x_tx_frame_end(struct lan743x_tx *tx,
 | 
			
		|||
	tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail];
 | 
			
		||||
	buffer_info = &tx->buffer_info[tx->frame_tail];
 | 
			
		||||
	buffer_info->skb = skb;
 | 
			
		||||
	if (time_stamp)
 | 
			
		||||
		buffer_info->flags |= TX_BUFFER_INFO_FLAG_TIMESTAMP_REQUESTED;
 | 
			
		||||
	if (ignore_sync)
 | 
			
		||||
		buffer_info->flags |= TX_BUFFER_INFO_FLAG_IGNORE_SYNC;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1520,6 +1562,7 @@ static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx,
 | 
			
		|||
	unsigned int frame_length = 0;
 | 
			
		||||
	unsigned int head_length = 0;
 | 
			
		||||
	unsigned long irq_flags = 0;
 | 
			
		||||
	bool do_timestamp = false;
 | 
			
		||||
	bool ignore_sync = false;
 | 
			
		||||
	int nr_frags = 0;
 | 
			
		||||
	bool gso = false;
 | 
			
		||||
| 
						 | 
				
			
			@ -1541,6 +1584,14 @@ static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	/* space available, transmit skb  */
 | 
			
		||||
	if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
 | 
			
		||||
	    (tx->ts_flags & TX_TS_FLAG_TIMESTAMPING_ENABLED) &&
 | 
			
		||||
	    (lan743x_ptp_request_tx_timestamp(tx->adapter))) {
 | 
			
		||||
		skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
 | 
			
		||||
		do_timestamp = true;
 | 
			
		||||
		if (tx->ts_flags & TX_TS_FLAG_ONE_STEP_SYNC)
 | 
			
		||||
			ignore_sync = true;
 | 
			
		||||
	}
 | 
			
		||||
	head_length = skb_headlen(skb);
 | 
			
		||||
	frame_length = skb_pagelen(skb);
 | 
			
		||||
	nr_frags = skb_shinfo(skb)->nr_frags;
 | 
			
		||||
| 
						 | 
				
			
			@ -1554,6 +1605,7 @@ static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx,
 | 
			
		|||
	if (lan743x_tx_frame_start(tx,
 | 
			
		||||
				   skb->data, head_length,
 | 
			
		||||
				   start_frame_length,
 | 
			
		||||
				   do_timestamp,
 | 
			
		||||
				   skb->ip_summed == CHECKSUM_PARTIAL)) {
 | 
			
		||||
		dev_kfree_skb(skb);
 | 
			
		||||
		goto unlock;
 | 
			
		||||
| 
						 | 
				
			
			@ -1581,7 +1633,7 @@ static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
finish:
 | 
			
		||||
	lan743x_tx_frame_end(tx, skb, ignore_sync);
 | 
			
		||||
	lan743x_tx_frame_end(tx, skb, do_timestamp, ignore_sync);
 | 
			
		||||
 | 
			
		||||
unlock:
 | 
			
		||||
	spin_unlock_irqrestore(&tx->ring_lock, irq_flags);
 | 
			
		||||
| 
						 | 
				
			
			@ -2410,6 +2462,8 @@ static int lan743x_netdev_close(struct net_device *netdev)
 | 
			
		|||
	for (index = 0; index < LAN743X_USED_RX_CHANNELS; index++)
 | 
			
		||||
		lan743x_rx_close(&adapter->rx[index]);
 | 
			
		||||
 | 
			
		||||
	lan743x_ptp_close(adapter);
 | 
			
		||||
 | 
			
		||||
	lan743x_phy_close(adapter);
 | 
			
		||||
 | 
			
		||||
	lan743x_mac_close(adapter);
 | 
			
		||||
| 
						 | 
				
			
			@ -2437,6 +2491,10 @@ static int lan743x_netdev_open(struct net_device *netdev)
 | 
			
		|||
	if (ret)
 | 
			
		||||
		goto close_mac;
 | 
			
		||||
 | 
			
		||||
	ret = lan743x_ptp_open(adapter);
 | 
			
		||||
	if (ret)
 | 
			
		||||
		goto close_phy;
 | 
			
		||||
 | 
			
		||||
	lan743x_rfe_open(adapter);
 | 
			
		||||
 | 
			
		||||
	for (index = 0; index < LAN743X_USED_RX_CHANNELS; index++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2456,6 +2514,9 @@ static int lan743x_netdev_open(struct net_device *netdev)
 | 
			
		|||
		if (adapter->rx[index].ring_cpu_ptr)
 | 
			
		||||
			lan743x_rx_close(&adapter->rx[index]);
 | 
			
		||||
	}
 | 
			
		||||
	lan743x_ptp_close(adapter);
 | 
			
		||||
 | 
			
		||||
close_phy:
 | 
			
		||||
	lan743x_phy_close(adapter);
 | 
			
		||||
 | 
			
		||||
close_mac:
 | 
			
		||||
| 
						 | 
				
			
			@ -2483,6 +2544,8 @@ static int lan743x_netdev_ioctl(struct net_device *netdev,
 | 
			
		|||
{
 | 
			
		||||
	if (!netif_running(netdev))
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
	if (cmd == SIOCSHWTSTAMP)
 | 
			
		||||
		return lan743x_ptp_ioctl(netdev, ifr, cmd);
 | 
			
		||||
	return phy_mii_ioctl(netdev->phydev, ifr, cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2607,6 +2670,11 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter,
 | 
			
		|||
	adapter->intr.irq = adapter->pdev->irq;
 | 
			
		||||
	lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF);
 | 
			
		||||
	mutex_init(&adapter->dp_lock);
 | 
			
		||||
 | 
			
		||||
	ret = lan743x_gpio_init(adapter);
 | 
			
		||||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	ret = lan743x_mac_init(adapter);
 | 
			
		||||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -2615,6 +2683,10 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter,
 | 
			
		|||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	ret = lan743x_ptp_init(adapter);
 | 
			
		||||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	lan743x_rfe_update_mac_address(adapter);
 | 
			
		||||
 | 
			
		||||
	ret = lan743x_dmac_init(adapter);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,12 +4,17 @@
 | 
			
		|||
#ifndef _LAN743X_H
 | 
			
		||||
#define _LAN743X_H
 | 
			
		||||
 | 
			
		||||
#include "lan743x_ptp.h"
 | 
			
		||||
 | 
			
		||||
#define DRIVER_AUTHOR   "Bryan Whitehead <Bryan.Whitehead@microchip.com>"
 | 
			
		||||
#define DRIVER_DESC "LAN743x PCIe Gigabit Ethernet Driver"
 | 
			
		||||
#define DRIVER_NAME "lan743x"
 | 
			
		||||
 | 
			
		||||
/* Register Definitions */
 | 
			
		||||
#define ID_REV				(0x00)
 | 
			
		||||
#define ID_REV_ID_MASK_			(0xFFFF0000)
 | 
			
		||||
#define ID_REV_ID_LAN7430_		(0x74300000)
 | 
			
		||||
#define ID_REV_ID_LAN7431_		(0x74310000)
 | 
			
		||||
#define ID_REV_IS_VALID_CHIP_ID_(id_rev)	\
 | 
			
		||||
	(((id_rev) & 0xFFF00000) == 0x74300000)
 | 
			
		||||
#define ID_REV_CHIP_REV_MASK_		(0x0000FFFF)
 | 
			
		||||
| 
						 | 
				
			
			@ -62,6 +67,21 @@
 | 
			
		|||
 | 
			
		||||
#define E2P_DATA			(0x044)
 | 
			
		||||
 | 
			
		||||
#define GPIO_CFG0			(0x050)
 | 
			
		||||
#define GPIO_CFG0_GPIO_DIR_BIT_(bit)	BIT(16 + (bit))
 | 
			
		||||
#define GPIO_CFG0_GPIO_DATA_BIT_(bit)	BIT(0 + (bit))
 | 
			
		||||
 | 
			
		||||
#define GPIO_CFG1			(0x054)
 | 
			
		||||
#define GPIO_CFG1_GPIOEN_BIT_(bit)	BIT(16 + (bit))
 | 
			
		||||
#define GPIO_CFG1_GPIOBUF_BIT_(bit)	BIT(0 + (bit))
 | 
			
		||||
 | 
			
		||||
#define GPIO_CFG2			(0x058)
 | 
			
		||||
#define GPIO_CFG2_1588_POL_BIT_(bit)	BIT(0 + (bit))
 | 
			
		||||
 | 
			
		||||
#define GPIO_CFG3			(0x05C)
 | 
			
		||||
#define GPIO_CFG3_1588_CH_SEL_BIT_(bit)	BIT(16 + (bit))
 | 
			
		||||
#define GPIO_CFG3_1588_OE_BIT_(bit)	BIT(0 + (bit))
 | 
			
		||||
 | 
			
		||||
#define FCT_RX_CTL			(0xAC)
 | 
			
		||||
#define FCT_RX_CTL_EN_(channel)		BIT(28 + (channel))
 | 
			
		||||
#define FCT_RX_CTL_DIS_(channel)	BIT(24 + (channel))
 | 
			
		||||
| 
						 | 
				
			
			@ -193,7 +213,8 @@
 | 
			
		|||
#define INT_BIT_DMA_TX_(channel)	BIT(16 + (channel))
 | 
			
		||||
#define INT_BIT_ALL_TX_			(0x000F0000)
 | 
			
		||||
#define INT_BIT_SW_GP_			BIT(9)
 | 
			
		||||
#define INT_BIT_ALL_OTHER_		(0x00000280)
 | 
			
		||||
#define INT_BIT_1588_			BIT(7)
 | 
			
		||||
#define INT_BIT_ALL_OTHER_		(INT_BIT_SW_GP_ | INT_BIT_1588_)
 | 
			
		||||
#define INT_BIT_MAS_			BIT(0)
 | 
			
		||||
 | 
			
		||||
#define INT_SET				(0x784)
 | 
			
		||||
| 
						 | 
				
			
			@ -234,6 +255,71 @@
 | 
			
		|||
#define INT_MOD_CFG6			(0x7D8)
 | 
			
		||||
#define INT_MOD_CFG7			(0x7DC)
 | 
			
		||||
 | 
			
		||||
#define PTP_CMD_CTL					(0x0A00)
 | 
			
		||||
#define PTP_CMD_CTL_PTP_CLK_STP_NSEC_			BIT(6)
 | 
			
		||||
#define PTP_CMD_CTL_PTP_CLOCK_STEP_SEC_			BIT(5)
 | 
			
		||||
#define PTP_CMD_CTL_PTP_CLOCK_LOAD_			BIT(4)
 | 
			
		||||
#define PTP_CMD_CTL_PTP_CLOCK_READ_			BIT(3)
 | 
			
		||||
#define PTP_CMD_CTL_PTP_ENABLE_				BIT(2)
 | 
			
		||||
#define PTP_CMD_CTL_PTP_DISABLE_			BIT(1)
 | 
			
		||||
#define PTP_CMD_CTL_PTP_RESET_				BIT(0)
 | 
			
		||||
#define PTP_GENERAL_CONFIG				(0x0A04)
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_X_MASK_(channel) \
 | 
			
		||||
	(0x7 << (1 + ((channel) << 2)))
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_100NS_	(0)
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_10US_	(1)
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_100US_	(2)
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_1MS_	(3)
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_10MS_	(4)
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_200MS_	(5)
 | 
			
		||||
#define PTP_GENERAL_CONFIG_CLOCK_EVENT_X_SET_(channel, value) \
 | 
			
		||||
	(((value) & 0x7) << (1 + ((channel) << 2)))
 | 
			
		||||
#define PTP_GENERAL_CONFIG_RELOAD_ADD_X_(channel)	(BIT((channel) << 2))
 | 
			
		||||
 | 
			
		||||
#define PTP_INT_STS				(0x0A08)
 | 
			
		||||
#define PTP_INT_EN_SET				(0x0A0C)
 | 
			
		||||
#define PTP_INT_EN_CLR				(0x0A10)
 | 
			
		||||
#define PTP_INT_BIT_TX_SWTS_ERR_		BIT(13)
 | 
			
		||||
#define PTP_INT_BIT_TX_TS_			BIT(12)
 | 
			
		||||
#define PTP_INT_BIT_TIMER_B_			BIT(1)
 | 
			
		||||
#define PTP_INT_BIT_TIMER_A_			BIT(0)
 | 
			
		||||
 | 
			
		||||
#define PTP_CLOCK_SEC				(0x0A14)
 | 
			
		||||
#define PTP_CLOCK_NS				(0x0A18)
 | 
			
		||||
#define PTP_CLOCK_SUBNS				(0x0A1C)
 | 
			
		||||
#define PTP_CLOCK_RATE_ADJ			(0x0A20)
 | 
			
		||||
#define PTP_CLOCK_RATE_ADJ_DIR_			BIT(31)
 | 
			
		||||
#define PTP_CLOCK_STEP_ADJ			(0x0A2C)
 | 
			
		||||
#define PTP_CLOCK_STEP_ADJ_DIR_			BIT(31)
 | 
			
		||||
#define PTP_CLOCK_STEP_ADJ_VALUE_MASK_		(0x3FFFFFFF)
 | 
			
		||||
#define PTP_CLOCK_TARGET_SEC_X(channel)		(0x0A30 + ((channel) << 4))
 | 
			
		||||
#define PTP_CLOCK_TARGET_NS_X(channel)		(0x0A34 + ((channel) << 4))
 | 
			
		||||
#define PTP_CLOCK_TARGET_RELOAD_SEC_X(channel)	(0x0A38 + ((channel) << 4))
 | 
			
		||||
#define PTP_CLOCK_TARGET_RELOAD_NS_X(channel)	(0x0A3C + ((channel) << 4))
 | 
			
		||||
#define PTP_LATENCY				(0x0A5C)
 | 
			
		||||
#define PTP_LATENCY_TX_SET_(tx_latency)		(((u32)(tx_latency)) << 16)
 | 
			
		||||
#define PTP_LATENCY_RX_SET_(rx_latency)		\
 | 
			
		||||
	(((u32)(rx_latency)) & 0x0000FFFF)
 | 
			
		||||
#define PTP_CAP_INFO				(0x0A60)
 | 
			
		||||
#define PTP_CAP_INFO_TX_TS_CNT_GET_(reg_val)	(((reg_val) & 0x00000070) >> 4)
 | 
			
		||||
 | 
			
		||||
#define PTP_TX_MOD				(0x0AA4)
 | 
			
		||||
#define PTP_TX_MOD_TX_PTP_SYNC_TS_INSERT_	(0x10000000)
 | 
			
		||||
 | 
			
		||||
#define PTP_TX_MOD2				(0x0AA8)
 | 
			
		||||
#define PTP_TX_MOD2_TX_PTP_CLR_UDPV4_CHKSUM_	(0x00000001)
 | 
			
		||||
 | 
			
		||||
#define PTP_TX_EGRESS_SEC			(0x0AAC)
 | 
			
		||||
#define PTP_TX_EGRESS_NS			(0x0AB0)
 | 
			
		||||
#define PTP_TX_EGRESS_NS_CAPTURE_CAUSE_MASK_	(0xC0000000)
 | 
			
		||||
#define PTP_TX_EGRESS_NS_CAPTURE_CAUSE_AUTO_	(0x00000000)
 | 
			
		||||
#define PTP_TX_EGRESS_NS_CAPTURE_CAUSE_SW_	(0x40000000)
 | 
			
		||||
#define PTP_TX_EGRESS_NS_TS_NS_MASK_		(0x3FFFFFFF)
 | 
			
		||||
 | 
			
		||||
#define PTP_TX_MSG_HEADER			(0x0AB4)
 | 
			
		||||
#define PTP_TX_MSG_HEADER_MSG_TYPE_		(0x000F0000)
 | 
			
		||||
#define PTP_TX_MSG_HEADER_MSG_TYPE_SYNC_	(0x00000000)
 | 
			
		||||
 | 
			
		||||
#define DMAC_CFG				(0xC00)
 | 
			
		||||
#define DMAC_CFG_COAL_EN_			BIT(16)
 | 
			
		||||
#define DMAC_CFG_CH_ARB_SEL_RX_HIGH_		(0x00000000)
 | 
			
		||||
| 
						 | 
				
			
			@ -542,8 +628,12 @@ struct lan743x_tx_buffer_info;
 | 
			
		|||
 | 
			
		||||
#define TX_FRAME_FLAG_IN_PROGRESS	BIT(0)
 | 
			
		||||
 | 
			
		||||
#define TX_TS_FLAG_TIMESTAMPING_ENABLED	BIT(0)
 | 
			
		||||
#define TX_TS_FLAG_ONE_STEP_SYNC	BIT(1)
 | 
			
		||||
 | 
			
		||||
struct lan743x_tx {
 | 
			
		||||
	struct lan743x_adapter *adapter;
 | 
			
		||||
	u32	ts_flags;
 | 
			
		||||
	u32	vector_flags;
 | 
			
		||||
	int	channel_number;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -570,6 +660,10 @@ struct lan743x_tx {
 | 
			
		|||
	struct sk_buff *overflow_skb;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void lan743x_tx_set_timestamping_mode(struct lan743x_tx *tx,
 | 
			
		||||
				      bool enable_timestamping,
 | 
			
		||||
				      bool enable_onestep_sync);
 | 
			
		||||
 | 
			
		||||
/* RX */
 | 
			
		||||
struct lan743x_rx_descriptor;
 | 
			
		||||
struct lan743x_rx_buffer_info;
 | 
			
		||||
| 
						 | 
				
			
			@ -610,6 +704,9 @@ struct lan743x_adapter {
 | 
			
		|||
	/* lock, used to prevent concurrent access to data port */
 | 
			
		||||
	struct mutex		dp_lock;
 | 
			
		||||
 | 
			
		||||
	struct lan743x_gpio	gpio;
 | 
			
		||||
	struct lan743x_ptp	ptp;
 | 
			
		||||
 | 
			
		||||
	u8			mac_address[ETH_ALEN];
 | 
			
		||||
 | 
			
		||||
	struct lan743x_phy      phy;
 | 
			
		||||
| 
						 | 
				
			
			@ -660,6 +757,7 @@ struct lan743x_adapter {
 | 
			
		|||
#define TX_DESC_DATA0_IPE_			(0x00200000)
 | 
			
		||||
#define TX_DESC_DATA0_TPE_			(0x00100000)
 | 
			
		||||
#define TX_DESC_DATA0_FCS_			(0x00020000)
 | 
			
		||||
#define TX_DESC_DATA0_TSE_			(0x00010000)
 | 
			
		||||
#define TX_DESC_DATA0_BUF_LENGTH_MASK_		(0x0000FFFF)
 | 
			
		||||
#define TX_DESC_DATA0_EXT_LSO_			(0x00200000)
 | 
			
		||||
#define TX_DESC_DATA0_EXT_PAY_LENGTH_MASK_	(0x000FFFFF)
 | 
			
		||||
| 
						 | 
				
			
			@ -673,6 +771,7 @@ struct lan743x_tx_descriptor {
 | 
			
		|||
} __aligned(DEFAULT_DMA_DESCRIPTOR_SPACING);
 | 
			
		||||
 | 
			
		||||
#define TX_BUFFER_INFO_FLAG_ACTIVE		BIT(0)
 | 
			
		||||
#define TX_BUFFER_INFO_FLAG_TIMESTAMP_REQUESTED	BIT(1)
 | 
			
		||||
#define TX_BUFFER_INFO_FLAG_IGNORE_SYNC		BIT(2)
 | 
			
		||||
#define TX_BUFFER_INFO_FLAG_SKB_FRAGMENT	BIT(3)
 | 
			
		||||
struct lan743x_tx_buffer_info {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1164
									
								
								drivers/net/ethernet/microchip/lan743x_ptp.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1164
									
								
								drivers/net/ethernet/microchip/lan743x_ptp.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										76
									
								
								drivers/net/ethernet/microchip/lan743x_ptp.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								drivers/net/ethernet/microchip/lan743x_ptp.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,76 @@
 | 
			
		|||
/* SPDX-License-Identifier: GPL-2.0+ */
 | 
			
		||||
/* Copyright (C) 2018 Microchip Technology Inc. */
 | 
			
		||||
 | 
			
		||||
#ifndef _LAN743X_PTP_H
 | 
			
		||||
#define _LAN743X_PTP_H
 | 
			
		||||
 | 
			
		||||
#include "linux/ptp_clock_kernel.h"
 | 
			
		||||
#include "linux/netdevice.h"
 | 
			
		||||
 | 
			
		||||
struct lan743x_adapter;
 | 
			
		||||
 | 
			
		||||
/* GPIO */
 | 
			
		||||
struct lan743x_gpio {
 | 
			
		||||
	/* gpio_lock: used to prevent concurrent access to gpio settings */
 | 
			
		||||
	spinlock_t gpio_lock;
 | 
			
		||||
 | 
			
		||||
	int used_bits;
 | 
			
		||||
	int output_bits;
 | 
			
		||||
	int ptp_bits;
 | 
			
		||||
	u32 gpio_cfg0;
 | 
			
		||||
	u32 gpio_cfg1;
 | 
			
		||||
	u32 gpio_cfg2;
 | 
			
		||||
	u32 gpio_cfg3;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int lan743x_gpio_init(struct lan743x_adapter *adapter);
 | 
			
		||||
 | 
			
		||||
void lan743x_ptp_isr(void *context);
 | 
			
		||||
bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter);
 | 
			
		||||
void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter);
 | 
			
		||||
void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter,
 | 
			
		||||
				  struct sk_buff *skb, bool ignore_sync);
 | 
			
		||||
int lan743x_ptp_init(struct lan743x_adapter *adapter);
 | 
			
		||||
int lan743x_ptp_open(struct lan743x_adapter *adapter);
 | 
			
		||||
void lan743x_ptp_close(struct lan743x_adapter *adapter);
 | 
			
		||||
void lan743x_ptp_update_latency(struct lan743x_adapter *adapter,
 | 
			
		||||
				u32 link_speed);
 | 
			
		||||
 | 
			
		||||
int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
 | 
			
		||||
 | 
			
		||||
#define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4)
 | 
			
		||||
 | 
			
		||||
#define PTP_FLAG_PTP_CLOCK_REGISTERED	BIT(1)
 | 
			
		||||
#define PTP_FLAG_ISR_ENABLED			BIT(2)
 | 
			
		||||
 | 
			
		||||
struct lan743x_ptp {
 | 
			
		||||
	int flags;
 | 
			
		||||
 | 
			
		||||
	/* command_lock: used to prevent concurrent ptp commands */
 | 
			
		||||
	struct mutex	command_lock;
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_PTP_1588_CLOCK
 | 
			
		||||
	struct ptp_clock *ptp_clock;
 | 
			
		||||
	struct ptp_clock_info ptp_clock_info;
 | 
			
		||||
	struct ptp_pin_desc pin_config[1];
 | 
			
		||||
#endif /* CONFIG_PTP_1588_CLOCK */
 | 
			
		||||
 | 
			
		||||
#define LAN743X_PTP_NUMBER_OF_EVENT_CHANNELS (2)
 | 
			
		||||
	unsigned long used_event_ch;
 | 
			
		||||
 | 
			
		||||
	int perout_event_ch;
 | 
			
		||||
	int perout_gpio_bit;
 | 
			
		||||
 | 
			
		||||
	/* tx_ts_lock: used to prevent concurrent access to timestamp arrays */
 | 
			
		||||
	spinlock_t	tx_ts_lock;
 | 
			
		||||
	int pending_tx_timestamps;
 | 
			
		||||
	struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
 | 
			
		||||
	unsigned int	tx_ts_ignore_sync_queue;
 | 
			
		||||
	int tx_ts_skb_queue_size;
 | 
			
		||||
	u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
 | 
			
		||||
	u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
 | 
			
		||||
	u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
 | 
			
		||||
	int tx_ts_queue_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif /* _LAN743X_PTP_H */
 | 
			
		||||
		Loading…
	
		Reference in a new issue