Commit 9055a2f5 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by David S. Miller
Browse files

ixp4xx_eth: make ptp support a platform driver



After the recent ixp4xx cleanups, the ptp driver has gained a
build failure in some configurations:

drivers/net/ethernet/xscale/ptp_ixp46x.c: In function 'ptp_ixp_init':
drivers/net/ethernet/xscale/ptp_ixp46x.c:290:51: error: 'IXP4XX_TIMESYNC_BASE_VIRT' undeclared (first use in this function)

Avoid the last bit of hardcoded constants from platform headers
by turning the ptp driver bit into a platform driver and passing
the IRQ and MMIO address as resources.

This is a bit tricky:

- The interface between the two drivers is now the new
  ixp46x_ptp_find() function, replacing the global
  ixp46x_phc_index variable. The call is done as late
  as possible, in hwtstamp_set(), to ensure that the
  ptp device is fully probed.

- As the ptp driver is now called by the network driver, the
  link dependency is reversed, which in turn requires a small
  Makefile hack

- The GPIO number is still left hardcoded. This is clearly not
  great, but it can be addressed later. Note that commit 98ac0cc2
  ("ARM: ixp4xx: Convert to MULTI_IRQ_HANDLER") changed the
  IRQ number to something meaningless. Passing the correct IRQ
  in a resource fixes this.

- When the PTP driver is disabled, ethtool .get_ts_info()
  now correctly lists only software timestamping regardless
  of the hardware.

Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
[Fix a missing include]
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 27c77943
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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
+5 −1
Original line number Diff line number Diff line
@@ -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
+11 −2
Original line number Diff line number Diff line
@@ -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
+19 −9
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ 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;
@@ -295,7 +297,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);

@@ -340,7 +342,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.
@@ -375,6 +377,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)))
@@ -383,8 +386,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;
@@ -988,25 +995,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);
@@ -1481,6 +1490,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);
Loading