Skip to content

Commit

Permalink
Merge branch 'IXP46x-PTP-Timer'
Browse files Browse the repository at this point in the history
Linus Walleij says:

====================
IXP46x PTP Timer clean-up and DT

ChangeLog v2->v3:

- Dropped the patch enabling compile tests: we are still dependent
  on some machine-specific headers. The plan is to get rid of this
  after device tree conversion. We include one of the compile testing
  fixes anyway, because it is nice to have fixed.

- Rebased on the latest net-next
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Aug 30, 2021
2 parents 27c7794 + e9e5062 commit 724812d
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 77 deletions.
54 changes: 54 additions & 0 deletions Documentation/devicetree/bindings/net/intel,ixp46x-ptp-timer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
# Copyright 2018 Linaro Ltd.
%YAML 1.2
---
$id: "http://devicetree.org/schemas/net/intel,ixp46x-ptp-timer.yaml#"
$schema: "http://devicetree.org/meta-schemas/core.yaml#"

title: Intel IXP46x PTP Timer (TSYNC)

maintainers:
- Linus Walleij <linus.walleij@linaro.org>

description: |
The Intel IXP46x PTP timer is known in the manual as IEEE1588 Hardware
Assist and Time Synchronization Hardware Assist TSYNC provides a PTP
timer. It exists in the Intel IXP45x and IXP46x XScale SoCs.
properties:
compatible:
const: intel,ixp46x-ptp-timer

reg:
maxItems: 1

interrupts:
items:
- description: Interrupt to trigger master mode snapshot from the
PRP timer, usually a GPIO interrupt.
- description: Interrupt to trigger slave mode snapshot from the
PRP timer, usually a GPIO interrupt.

interrupt-names:
items:
- const: master
- const: slave

required:
- compatible
- reg
- interrupts
- interrupt-names

additionalProperties: false

examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
ptp-timer@c8010000 {
compatible = "intel,ixp46x-ptp-timer";
reg = <0xc8010000 0x1000>;
interrupt-parent = <&gpio0>;
interrupts = <8 IRQ_TYPE_EDGE_FALLING>, <7 IRQ_TYPE_EDGE_FALLING>;
interrupt-names = "master", "slave";
};
14 changes: 14 additions & 0 deletions arch/arm/mach-ixp4xx/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,23 @@ static struct platform_device ixp46x_i2c_controller = {
.resource = ixp46x_i2c_resources
};

static struct resource ixp46x_ptp_resources[] = {
DEFINE_RES_MEM(IXP4XX_TIMESYNC_BASE_PHYS, SZ_4K),
DEFINE_RES_IRQ_NAMED(IRQ_IXP4XX_GPIO8, "master"),
DEFINE_RES_IRQ_NAMED(IRQ_IXP4XX_GPIO7, "slave"),
};

static struct platform_device ixp46x_ptp = {
.name = "ptp-ixp46x",
.id = -1,
.resource = ixp46x_ptp_resources,
.num_resources = ARRAY_SIZE(ixp46x_ptp_resources),
};

static struct platform_device *ixp46x_devices[] __initdata = {
&ixp46x_hwrandom_device,
&ixp46x_i2c_controller,
&ixp46x_ptp,
};

unsigned long ixp4xx_exp_bus_size;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ethernet/xscale/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ config IXP4XX_ETH
on IXP4xx processor.

config PTP_1588_CLOCK_IXP46X
tristate "Intel IXP46x as PTP clock"
bool "Intel IXP46x as PTP clock"
depends on IXP4XX_ETH
depends on PTP_1588_CLOCK
depends on PTP_1588_CLOCK=y || PTP_1588_CLOCK=IXP4XX_ETH
default y
help
This driver adds support for using the IXP46X as a PTP
Expand Down
6 changes: 5 additions & 1 deletion drivers/net/ethernet/xscale/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
# Makefile for the Intel XScale IXP device drivers.
#

# Keep this link order to avoid deferred probing
ifdef CONFIG_PTP_1588_CLOCK_IXP46X
obj-$(CONFIG_IXP4XX_ETH) += ptp_ixp46x.o
endif

obj-$(CONFIG_IXP4XX_ETH) += ixp4xx_eth.o
obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o
13 changes: 11 additions & 2 deletions drivers/net/ethernet/xscale/ixp46x_ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ struct ixp46x_ts_regs {
#define TX_SNAPSHOT_LOCKED (1<<0)
#define RX_SNAPSHOT_LOCKED (1<<1)

/* The ptp_ixp46x module will set this variable */
extern int ixp46x_phc_index;
#if IS_ENABLED(CONFIG_PTP_1588_CLOCK_IXP46X)
int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index);
#else
static inline int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index)
{
*regs = NULL;
*phc_index = -1;

return -ENODEV;
}
#endif

#endif
35 changes: 22 additions & 13 deletions drivers/net/ethernet/xscale/ixp4xx_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <linux/module.h>
#include <linux/soc/ixp4xx/npe.h>
#include <linux/soc/ixp4xx/qmgr.h>
#include <mach/hardware.h>
#include <linux/soc/ixp4xx/cpu.h>

#include "ixp46x_ts.h"
Expand Down Expand Up @@ -169,13 +168,15 @@ struct eth_regs {

struct port {
struct eth_regs __iomem *regs;
struct ixp46x_ts_regs __iomem *timesync_regs;
int phc_index;
struct npe *npe;
struct net_device *netdev;
struct napi_struct napi;
struct eth_plat_info *plat;
buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
struct desc *desc_tab; /* coherent */
u32 desc_tab_phys;
dma_addr_t desc_tab_phys;
int id; /* logical port ID */
int speed, duplex;
u8 firmware[4];
Expand Down Expand Up @@ -295,7 +296,7 @@ static void ixp_rx_timestamp(struct port *port, struct sk_buff *skb)

ch = PORT2CHANNEL(port);

regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
regs = port->timesync_regs;

val = __raw_readl(&regs->channel[ch].ch_event);

Expand Down Expand Up @@ -340,7 +341,7 @@ static void ixp_tx_timestamp(struct port *port, struct sk_buff *skb)

ch = PORT2CHANNEL(port);

regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
regs = port->timesync_regs;

/*
* This really stinks, but we have to poll for the Tx time stamp.
Expand Down Expand Up @@ -375,6 +376,7 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
struct hwtstamp_config cfg;
struct ixp46x_ts_regs *regs;
struct port *port = netdev_priv(netdev);
int ret;
int ch;

if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
Expand All @@ -383,8 +385,12 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
if (cfg.flags) /* reserved for future extensions */
return -EINVAL;

ret = ixp46x_ptp_find(&port->timesync_regs, &port->phc_index);
if (ret)
return ret;

ch = PORT2CHANNEL(port);
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
regs = port->timesync_regs;

if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
return -ERANGE;
Expand Down Expand Up @@ -850,14 +856,14 @@ static int eth_xmit(struct sk_buff *skb, struct net_device *dev)
bytes = len;
mem = skb->data;
#else
offset = (int)skb->data & 3; /* keep 32-bit alignment */
offset = (uintptr_t)skb->data & 3; /* keep 32-bit alignment */
bytes = ALIGN(offset + len, 4);
if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
dev_kfree_skb(skb);
dev->stats.tx_dropped++;
return NETDEV_TX_OK;
}
memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
memcpy_swab32(mem, (u32 *)((uintptr_t)skb->data & ~3), bytes / 4);
#endif

phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
Expand Down Expand Up @@ -988,25 +994,27 @@ static void ixp4xx_get_drvinfo(struct net_device *dev,
strlcpy(info->bus_info, "internal", sizeof(info->bus_info));
}

int ixp46x_phc_index = -1;
EXPORT_SYMBOL_GPL(ixp46x_phc_index);

static int ixp4xx_get_ts_info(struct net_device *dev,
struct ethtool_ts_info *info)
{
if (!cpu_is_ixp46x()) {
struct port *port = netdev_priv(dev);

if (port->phc_index < 0)
ixp46x_ptp_find(&port->timesync_regs, &port->phc_index);

info->phc_index = port->phc_index;

if (info->phc_index < 0) {
info->so_timestamping =
SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE;
info->phc_index = -1;
return 0;
}
info->so_timestamping =
SOF_TIMESTAMPING_TX_HARDWARE |
SOF_TIMESTAMPING_RX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE;
info->phc_index = ixp46x_phc_index;
info->tx_types =
(1 << HWTSTAMP_TX_OFF) |
(1 << HWTSTAMP_TX_ON);
Expand Down Expand Up @@ -1481,6 +1489,7 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
port = netdev_priv(ndev);
port->netdev = ndev;
port->id = plat->npe;
port->phc_index = -1;

/* Get the port resource and remap */
port->regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
Expand Down
Loading

0 comments on commit 724812d

Please sign in to comment.