Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64e8de58 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'ti-cpts-update-and-fixes'

Grygorii Strashko says:

====================
net: ethernet: ti: cpts: update and fixes

It is preparation series intended to clean up and optimize TI CPTS driver to
facilitate further integration with other TI's SoCs like Keystone 2.

Changes in v5:
- fixed copy paste error in cpts_release
- reworked cc.mult/shift and cc_mult initialization

Changes in v4:
- fixed build error in patch
  "net: ethernet: ti: cpts: clean up event list if event pool is empty"
- rebased on top of net-next

Changes in v3:
- patches reordered: fixes and small updates moved first
- added comments in code about cpts->cc_mult
- conversation range (maxsec) limited to 10sec

Changes in v2:
- patch "net: ethernet: ti: cpts: rework initialization/deinitialization"
  was split on 4 patches
- applied comments from Richard Cochran
- dropped patch
  "net: ethernet: ti: cpts: add return value to tx and rx timestamp funcitons"
- new patches added:
  "net: ethernet: ti: cpts: drop excessive writes to CTRL and INT_EN regs"
  and "clocksource: export the clocks_calc_mult_shift to use by timestamp code"

Links on prev versions:
v4: https://lkml.org/lkml/2016/12/6/496
v3: https://www.spinics.net/lists/devicetree/msg153474.html
v2: http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1282034.html
v1: http://www.spinics.net/lists/linux-omap/msg131925.html


====================

Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents d3243aef 20138cf9
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ Required properties:
- slaves		: Specifies number for slaves
- active_slave		: Specifies the slave to use for time stamping,
			  ethtool and SIOCGMIIPHY
- cpts_clock_mult	: Numerator to convert input clock ticks into nanoseconds
- cpts_clock_shift	: Denominator to convert input clock ticks into nanoseconds

Optional properties:
- ti,hwmods		: Must be "cpgmac0"
@@ -35,7 +33,11 @@ Optional properties:
			  For example in dra72x-evm, pcf gpio has to be
			  driven low so that cpsw slave 0 and phy data
			  lines are connected via mux.

- cpts_clock_mult	: Numerator to convert input clock ticks into nanoseconds
- cpts_clock_shift	: Denominator to convert input clock ticks into nanoseconds
			  Mult and shift will be calculated basing on CPTS
			  rftclk frequency if both cpts_clock_shift and
			  cpts_clock_mult properties are not provided.

Slave Properties:
Required properties:
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ config TI_CPSW
	  will be called cpsw.

config TI_CPTS
	bool "TI Common Platform Time Sync (CPTS) Support"
	tristate "TI Common Platform Time Sync (CPTS) Support"
	depends on TI_CPSW
	select PTP_1588_CLOCK
	---help---
+2 −1
Original line number Diff line number Diff line
@@ -12,8 +12,9 @@ obj-$(CONFIG_TI_DAVINCI_MDIO) += davinci_mdio.o
obj-$(CONFIG_TI_DAVINCI_CPDMA) += davinci_cpdma.o
obj-$(CONFIG_TI_CPSW_PHY_SEL) += cpsw-phy-sel.o
obj-$(CONFIG_TI_CPSW_ALE) += cpsw_ale.o
obj-$(CONFIG_TI_CPTS) += cpts.o
obj-$(CONFIG_TI_CPSW) += ti_cpsw.o
ti_cpsw-y := cpsw.o cpts.o
ti_cpsw-y := cpsw.o

obj-$(CONFIG_TI_KEYSTONE_NETCP) += keystone_netcp.o
keystone_netcp-y := netcp_core.o
+43 −41
Original line number Diff line number Diff line
@@ -1487,9 +1487,7 @@ static int cpsw_ndo_open(struct net_device *ndev)
		if (ret < 0)
			goto err_cleanup;

		if (cpts_register(cpsw->dev, cpsw->cpts,
				  cpsw->data.cpts_clock_mult,
				  cpsw->data.cpts_clock_shift))
		if (cpts_register(cpsw->cpts))
			dev_err(priv->dev, "error registering cpts device\n");

	}
@@ -1562,7 +1560,7 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
	}

	if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
				cpsw->cpts->tx_enable)
	    cpts_is_tx_enabled(cpsw->cpts))
		skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;

	skb_tx_timestamp(skb);
@@ -1594,14 +1592,15 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
	return NETDEV_TX_BUSY;
}

#ifdef CONFIG_TI_CPTS
#if IS_ENABLED(CONFIG_TI_CPTS)

static void cpsw_hwtstamp_v1(struct cpsw_common *cpsw)
{
	struct cpsw_slave *slave = &cpsw->slaves[cpsw->data.active_slave];
	u32 ts_en, seq_id;

	if (!cpsw->cpts->tx_enable && !cpsw->cpts->rx_enable) {
	if (!cpts_is_tx_enabled(cpsw->cpts) &&
	    !cpts_is_rx_enabled(cpsw->cpts)) {
		slave_write(slave, 0, CPSW1_TS_CTL);
		return;
	}
@@ -1609,10 +1608,10 @@ static void cpsw_hwtstamp_v1(struct cpsw_common *cpsw)
	seq_id = (30 << CPSW_V1_SEQ_ID_OFS_SHIFT) | ETH_P_1588;
	ts_en = EVENT_MSG_BITS << CPSW_V1_MSG_TYPE_OFS;

	if (cpsw->cpts->tx_enable)
	if (cpts_is_tx_enabled(cpsw->cpts))
		ts_en |= CPSW_V1_TS_TX_EN;

	if (cpsw->cpts->rx_enable)
	if (cpts_is_rx_enabled(cpsw->cpts))
		ts_en |= CPSW_V1_TS_RX_EN;

	slave_write(slave, ts_en, CPSW1_TS_CTL);
@@ -1635,20 +1634,20 @@ static void cpsw_hwtstamp_v2(struct cpsw_priv *priv)
	case CPSW_VERSION_2:
		ctrl &= ~CTRL_V2_ALL_TS_MASK;

		if (cpsw->cpts->tx_enable)
		if (cpts_is_tx_enabled(cpsw->cpts))
			ctrl |= CTRL_V2_TX_TS_BITS;

		if (cpsw->cpts->rx_enable)
		if (cpts_is_rx_enabled(cpsw->cpts))
			ctrl |= CTRL_V2_RX_TS_BITS;
		break;
	case CPSW_VERSION_3:
	default:
		ctrl &= ~CTRL_V3_ALL_TS_MASK;

		if (cpsw->cpts->tx_enable)
		if (cpts_is_tx_enabled(cpsw->cpts))
			ctrl |= CTRL_V3_TX_TS_BITS;

		if (cpsw->cpts->rx_enable)
		if (cpts_is_rx_enabled(cpsw->cpts))
			ctrl |= CTRL_V3_RX_TS_BITS;
		break;
	}
@@ -1684,7 +1683,7 @@ static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)

	switch (cfg.rx_filter) {
	case HWTSTAMP_FILTER_NONE:
		cpts->rx_enable = 0;
		cpts_rx_enable(cpts, 0);
		break;
	case HWTSTAMP_FILTER_ALL:
	case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
@@ -1700,14 +1699,14 @@ static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
	case HWTSTAMP_FILTER_PTP_V2_EVENT:
	case HWTSTAMP_FILTER_PTP_V2_SYNC:
	case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
		cpts->rx_enable = 1;
		cpts_rx_enable(cpts, 1);
		cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
		break;
	default:
		return -ERANGE;
	}

	cpts->tx_enable = cfg.tx_type == HWTSTAMP_TX_ON;
	cpts_tx_enable(cpts, cfg.tx_type == HWTSTAMP_TX_ON);

	switch (cpsw->version) {
	case CPSW_VERSION_1:
@@ -1736,13 +1735,23 @@ static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
		return -EOPNOTSUPP;

	cfg.flags = 0;
	cfg.tx_type = cpts->tx_enable ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
	cfg.rx_filter = (cpts->rx_enable ?
	cfg.tx_type = cpts_is_tx_enabled(cpts) ?
		      HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
	cfg.rx_filter = (cpts_is_rx_enabled(cpts) ?
			 HWTSTAMP_FILTER_PTP_V2_EVENT : HWTSTAMP_FILTER_NONE);

	return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
}
#else
static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
{
	return -EOPNOTSUPP;
}

static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
{
	return -EOPNOTSUPP;
}
#endif /*CONFIG_TI_CPTS*/

static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
@@ -1755,12 +1764,10 @@ static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
		return -EINVAL;

	switch (cmd) {
#ifdef CONFIG_TI_CPTS
	case SIOCSHWTSTAMP:
		return cpsw_hwtstamp_set(dev, req);
	case SIOCGHWTSTAMP:
		return cpsw_hwtstamp_get(dev, req);
#endif
	}

	if (!cpsw->slaves[slave_no].phy)
@@ -2100,10 +2107,10 @@ static void cpsw_set_msglevel(struct net_device *ndev, u32 value)
	priv->msg_enable = value;
}

#if IS_ENABLED(CONFIG_TI_CPTS)
static int cpsw_get_ts_info(struct net_device *ndev,
			    struct ethtool_ts_info *info)
{
#ifdef CONFIG_TI_CPTS
	struct cpsw_common *cpsw = ndev_to_cpsw(ndev);

	info->so_timestamping =
@@ -2120,7 +2127,12 @@ static int cpsw_get_ts_info(struct net_device *ndev,
	info->rx_filters =
		(1 << HWTSTAMP_FILTER_NONE) |
		(1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
	return 0;
}
#else
static int cpsw_get_ts_info(struct net_device *ndev,
			    struct ethtool_ts_info *info)
{
	info->so_timestamping =
		SOF_TIMESTAMPING_TX_SOFTWARE |
		SOF_TIMESTAMPING_RX_SOFTWARE |
@@ -2128,9 +2140,9 @@ static int cpsw_get_ts_info(struct net_device *ndev,
	info->phc_index = -1;
	info->tx_types = 0;
	info->rx_filters = 0;
#endif
	return 0;
}
#endif

static int cpsw_get_link_ksettings(struct net_device *ndev,
				   struct ethtool_link_ksettings *ecmd)
@@ -2512,18 +2524,6 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
	}
	data->active_slave = prop;

	if (of_property_read_u32(node, "cpts_clock_mult", &prop)) {
		dev_err(&pdev->dev, "Missing cpts_clock_mult property in the DT.\n");
		return -EINVAL;
	}
	data->cpts_clock_mult = prop;

	if (of_property_read_u32(node, "cpts_clock_shift", &prop)) {
		dev_err(&pdev->dev, "Missing cpts_clock_shift property in the DT.\n");
		return -EINVAL;
	}
	data->cpts_clock_shift = prop;

	data->slave_data = devm_kzalloc(&pdev->dev, data->slaves
					* sizeof(struct cpsw_slave_data),
					GFP_KERNEL);
@@ -2782,6 +2782,7 @@ static int cpsw_probe(struct platform_device *pdev)
	struct cpdma_params		dma_params;
	struct cpsw_ale_params		ale_params;
	void __iomem			*ss_regs;
	void __iomem			*cpts_regs;
	struct resource			*res, *ss_res;
	const struct of_device_id	*of_id;
	struct gpio_descs		*mode;
@@ -2809,12 +2810,6 @@ static int cpsw_probe(struct platform_device *pdev)
	priv->dev  = &ndev->dev;
	priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
	cpsw->rx_packet_max = max(rx_packet_max, 128);
	cpsw->cpts = devm_kzalloc(&pdev->dev, sizeof(struct cpts), GFP_KERNEL);
	if (!cpsw->cpts) {
		dev_err(&pdev->dev, "error allocating cpts\n");
		ret = -ENOMEM;
		goto clean_ndev_ret;
	}

	mode = devm_gpiod_get_array_optional(&pdev->dev, "mode", GPIOD_OUT_LOW);
	if (IS_ERR(mode)) {
@@ -2902,7 +2897,7 @@ static int cpsw_probe(struct platform_device *pdev)
	switch (cpsw->version) {
	case CPSW_VERSION_1:
		cpsw->host_port_regs = ss_regs + CPSW1_HOST_PORT_OFFSET;
		cpsw->cpts->reg      = ss_regs + CPSW1_CPTS_OFFSET;
		cpts_regs		= ss_regs + CPSW1_CPTS_OFFSET;
		cpsw->hw_stats	     = ss_regs + CPSW1_HW_STATS;
		dma_params.dmaregs   = ss_regs + CPSW1_CPDMA_OFFSET;
		dma_params.txhdp     = ss_regs + CPSW1_STATERAM_OFFSET;
@@ -2916,7 +2911,7 @@ static int cpsw_probe(struct platform_device *pdev)
	case CPSW_VERSION_3:
	case CPSW_VERSION_4:
		cpsw->host_port_regs = ss_regs + CPSW2_HOST_PORT_OFFSET;
		cpsw->cpts->reg      = ss_regs + CPSW2_CPTS_OFFSET;
		cpts_regs		= ss_regs + CPSW2_CPTS_OFFSET;
		cpsw->hw_stats	     = ss_regs + CPSW2_HW_STATS;
		dma_params.dmaregs   = ss_regs + CPSW2_CPDMA_OFFSET;
		dma_params.txhdp     = ss_regs + CPSW2_STATERAM_OFFSET;
@@ -2983,6 +2978,12 @@ static int cpsw_probe(struct platform_device *pdev)
		goto clean_dma_ret;
	}

	cpsw->cpts = cpts_create(cpsw->dev, cpts_regs, cpsw->dev->of_node);
	if (IS_ERR(cpsw->cpts)) {
		ret = PTR_ERR(cpsw->cpts);
		goto clean_ale_ret;
	}

	ndev->irq = platform_get_irq(pdev, 1);
	if (ndev->irq < 0) {
		dev_err(priv->dev, "error getting irq resource\n");
@@ -3098,6 +3099,7 @@ static int cpsw_remove(struct platform_device *pdev)
		unregister_netdev(cpsw->slaves[1].ndev);
	unregister_netdev(ndev);

	cpts_release(cpsw->cpts);
	cpsw_ale_destroy(cpsw->ale);
	cpdma_ctlr_destroy(cpsw->dma);
	cpsw_remove_dt(pdev);
+0 −2
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@ struct cpsw_platform_data {
	u32	channels;	/* number of cpdma channels (symmetric) */
	u32	slaves;		/* number of slave cpgmac ports */
	u32	active_slave; /* time stamping, ethtool and SIOCGMIIPHY slave */
	u32	cpts_clock_mult;  /* convert input clock ticks to nanoseconds */
	u32	cpts_clock_shift; /* convert input clock ticks to nanoseconds */
	u32	ale_entries;	/* ale table size */
	u32	bd_ram_size;  /*buffer descriptor ram size */
	u32	mac_control;	/* Mac control register */
Loading