Skip to content

Commit a0d2f20

Browse files
Sergei Shtylyovdavem330
authored andcommitted
Renesas Ethernet AVB PTP clock driver
Ethernet AVB device includes the gPTP timer, so we can implement a PTP clock driver. We're doing that in a separate file, with the main Ethernet driver calling the PTP driver's [de]initialization and interrupt handler functions. Unfortunately, the clock seems tightly coupled with the AVB-DMAC, so when that one leaves the operation mode, we have to unregister the PTP clock... :-( Based on the original patches by Masaru Nagai. Signed-off-by: Masaru Nagai <[email protected]> Signed-off-by: Sergei Shtylyov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c156633 commit a0d2f20

File tree

4 files changed

+414
-5
lines changed

4 files changed

+414
-5
lines changed

drivers/net/ethernet/renesas/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
#
44

55
obj-$(CONFIG_SH_ETH) += sh_eth.o
6+
7+
ravb-objs := ravb_main.o ravb_ptp.o
8+
69
obj-$(CONFIG_RAVB) += ravb.o

drivers/net/ethernet/renesas/ravb.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <linux/mdio-bitbang.h>
2121
#include <linux/netdevice.h>
2222
#include <linux/phy.h>
23+
#include <linux/platform_device.h>
24+
#include <linux/ptp_clock_kernel.h>
2325

2426
#define BE_TX_RING_SIZE 64 /* TX ring size for Best Effort */
2527
#define BE_RX_RING_SIZE 1024 /* RX ring size for Best Effort */
@@ -744,6 +746,23 @@ struct ravb_tstamp_skb {
744746
u16 tag;
745747
};
746748

749+
struct ravb_ptp_perout {
750+
u32 target;
751+
u32 period;
752+
};
753+
754+
#define N_EXT_TS 1
755+
#define N_PER_OUT 1
756+
757+
struct ravb_ptp {
758+
struct ptp_clock *clock;
759+
struct ptp_clock_info info;
760+
u32 default_addend;
761+
u32 current_addend;
762+
int extts[N_EXT_TS];
763+
struct ravb_ptp_perout perout[N_PER_OUT];
764+
};
765+
747766
struct ravb_private {
748767
struct net_device *ndev;
749768
struct platform_device *pdev;
@@ -768,6 +787,7 @@ struct ravb_private {
768787
u32 tstamp_rx_ctrl;
769788
struct list_head ts_skb_list;
770789
u32 ts_skb_tag;
790+
struct ravb_ptp ptp;
771791
spinlock_t lock; /* Register access lock */
772792
u32 cur_rx[NUM_RX_QUEUE]; /* Consumer ring indices */
773793
u32 dirty_rx[NUM_RX_QUEUE]; /* Producer ring indices */
@@ -803,4 +823,10 @@ static inline void ravb_write(struct net_device *ndev, u32 data,
803823
iowrite32(data, priv->addr + reg);
804824
}
805825

826+
int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value);
827+
828+
irqreturn_t ravb_ptp_interrupt(struct net_device *ndev);
829+
void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev);
830+
void ravb_ptp_stop(struct net_device *ndev);
831+
806832
#endif /* #ifndef __RAVB_H__ */

drivers/net/ethernet/renesas/ravb.c renamed to drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <linux/of_irq.h>
2929
#include <linux/of_mdio.h>
3030
#include <linux/of_net.h>
31-
#include <linux/platform_device.h>
3231
#include <linux/pm_runtime.h>
3332
#include <linux/slab.h>
3433
#include <linux/spinlock.h>
@@ -41,8 +40,7 @@
4140
NETIF_MSG_RX_ERR | \
4241
NETIF_MSG_TX_ERR)
4342

44-
static int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask,
45-
u32 value)
43+
int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value)
4644
{
4745
int i;
4846

@@ -763,6 +761,9 @@ static irqreturn_t ravb_interrupt(int irq, void *dev_id)
763761
result = IRQ_HANDLED;
764762
}
765763

764+
if (iss & ISS_CGIS)
765+
result = ravb_ptp_interrupt(ndev);
766+
766767
mmiowb();
767768
spin_unlock(&priv->lock);
768769
return result;
@@ -1103,6 +1104,8 @@ static int ravb_set_ringparam(struct net_device *ndev,
11031104

11041105
if (netif_running(ndev)) {
11051106
netif_device_detach(ndev);
1107+
/* Stop PTP Clock driver */
1108+
ravb_ptp_stop(ndev);
11061109
/* Wait for DMA stopping */
11071110
error = ravb_stop_dma(ndev);
11081111
if (error) {
@@ -1132,6 +1135,9 @@ static int ravb_set_ringparam(struct net_device *ndev,
11321135

11331136
ravb_emac_init(ndev);
11341137

1138+
/* Initialise PTP Clock driver */
1139+
ravb_ptp_init(ndev, priv->pdev);
1140+
11351141
netif_device_attach(ndev);
11361142
}
11371143

@@ -1141,6 +1147,8 @@ static int ravb_set_ringparam(struct net_device *ndev,
11411147
static int ravb_get_ts_info(struct net_device *ndev,
11421148
struct ethtool_ts_info *info)
11431149
{
1150+
struct ravb_private *priv = netdev_priv(ndev);
1151+
11441152
info->so_timestamping =
11451153
SOF_TIMESTAMPING_TX_SOFTWARE |
11461154
SOF_TIMESTAMPING_RX_SOFTWARE |
@@ -1153,7 +1161,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
11531161
(1 << HWTSTAMP_FILTER_NONE) |
11541162
(1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
11551163
(1 << HWTSTAMP_FILTER_ALL);
1156-
info->phc_index = -1;
1164+
info->phc_index = ptp_clock_index(priv->ptp.clock);
11571165

11581166
return 0;
11591167
}
@@ -1195,15 +1203,21 @@ static int ravb_open(struct net_device *ndev)
11951203
goto out_free_irq;
11961204
ravb_emac_init(ndev);
11971205

1206+
/* Initialise PTP Clock driver */
1207+
ravb_ptp_init(ndev, priv->pdev);
1208+
11981209
netif_tx_start_all_queues(ndev);
11991210

12001211
/* PHY control start */
12011212
error = ravb_phy_start(ndev);
12021213
if (error)
1203-
goto out_free_irq;
1214+
goto out_ptp_stop;
12041215

12051216
return 0;
12061217

1218+
out_ptp_stop:
1219+
/* Stop PTP Clock driver */
1220+
ravb_ptp_stop(ndev);
12071221
out_free_irq:
12081222
free_irq(ndev->irq, ndev);
12091223
out_napi_off:
@@ -1235,6 +1249,9 @@ static void ravb_tx_timeout_work(struct work_struct *work)
12351249

12361250
netif_tx_stop_all_queues(ndev);
12371251

1252+
/* Stop PTP Clock driver */
1253+
ravb_ptp_stop(ndev);
1254+
12381255
/* Wait for DMA stopping */
12391256
ravb_stop_dma(ndev);
12401257

@@ -1245,6 +1262,9 @@ static void ravb_tx_timeout_work(struct work_struct *work)
12451262
ravb_dmac_init(ndev);
12461263
ravb_emac_init(ndev);
12471264

1265+
/* Initialise PTP Clock driver */
1266+
ravb_ptp_init(ndev, priv->pdev);
1267+
12481268
netif_tx_start_all_queues(ndev);
12491269
}
12501270

@@ -1409,6 +1429,9 @@ static int ravb_close(struct net_device *ndev)
14091429
ravb_write(ndev, 0, RIC2);
14101430
ravb_write(ndev, 0, TIC);
14111431

1432+
/* Stop PTP Clock driver */
1433+
ravb_ptp_stop(ndev);
1434+
14121435
/* Set the config mode to stop the AVB-DMAC's processes */
14131436
if (ravb_stop_dma(ndev) < 0)
14141437
netdev_err(ndev,

0 commit comments

Comments
 (0)