Skip to content

Commit c2594d8

Browse files
AndreiPistidavem330
authored andcommitted
macb: Common code to enable ptp support for MACB/GEM
This patch does the following: - MACB/GEM-PTP interface - registers and bitfields for TSU - capability flags to enable PTP per platform basis Signed-off-by: Andrei Pistirica <[email protected]> Acked-by: Nicolas Ferre <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 54c30f6 commit c2594d8

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

drivers/net/ethernet/cadence/macb.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,9 @@ static int macb_open(struct net_device *dev)
20852085

20862086
netif_tx_start_all_queues(dev);
20872087

2088+
if (bp->ptp_info)
2089+
bp->ptp_info->ptp_init(dev);
2090+
20882091
return 0;
20892092
}
20902093

@@ -2106,6 +2109,9 @@ static int macb_close(struct net_device *dev)
21062109

21072110
macb_free_consistent(bp);
21082111

2112+
if (bp->ptp_info)
2113+
bp->ptp_info->ptp_remove(dev);
2114+
21092115
return 0;
21102116
}
21112117

@@ -2379,6 +2385,17 @@ static int macb_set_ringparam(struct net_device *netdev,
23792385
return 0;
23802386
}
23812387

2388+
static int macb_get_ts_info(struct net_device *netdev,
2389+
struct ethtool_ts_info *info)
2390+
{
2391+
struct macb *bp = netdev_priv(netdev);
2392+
2393+
if (bp->ptp_info)
2394+
return bp->ptp_info->get_ts_info(netdev, info);
2395+
2396+
return ethtool_op_get_ts_info(netdev, info);
2397+
}
2398+
23822399
static const struct ethtool_ops macb_ethtool_ops = {
23832400
.get_regs_len = macb_get_regs_len,
23842401
.get_regs = macb_get_regs,
@@ -2396,7 +2413,7 @@ static const struct ethtool_ops gem_ethtool_ops = {
23962413
.get_regs_len = macb_get_regs_len,
23972414
.get_regs = macb_get_regs,
23982415
.get_link = ethtool_op_get_link,
2399-
.get_ts_info = ethtool_op_get_ts_info,
2416+
.get_ts_info = macb_get_ts_info,
24002417
.get_ethtool_stats = gem_get_ethtool_stats,
24012418
.get_strings = gem_get_ethtool_strings,
24022419
.get_sset_count = gem_get_sset_count,
@@ -2409,14 +2426,25 @@ static const struct ethtool_ops gem_ethtool_ops = {
24092426
static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
24102427
{
24112428
struct phy_device *phydev = dev->phydev;
2429+
struct macb *bp = netdev_priv(dev);
24122430

24132431
if (!netif_running(dev))
24142432
return -EINVAL;
24152433

24162434
if (!phydev)
24172435
return -ENODEV;
24182436

2419-
return phy_mii_ioctl(phydev, rq, cmd);
2437+
if (!bp->ptp_info)
2438+
return phy_mii_ioctl(phydev, rq, cmd);
2439+
2440+
switch (cmd) {
2441+
case SIOCSHWTSTAMP:
2442+
return bp->ptp_info->set_hwtst(dev, rq, cmd);
2443+
case SIOCGHWTSTAMP:
2444+
return bp->ptp_info->get_hwtst(dev, rq);
2445+
default:
2446+
return phy_mii_ioctl(phydev, rq, cmd);
2447+
}
24202448
}
24212449

24222450
static int macb_set_features(struct net_device *netdev,

drivers/net/ethernet/cadence/macb.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@
131131
#define GEM_RXIPCCNT 0x01a8 /* IP header Checksum Error Counter */
132132
#define GEM_RXTCPCCNT 0x01ac /* TCP Checksum Error Counter */
133133
#define GEM_RXUDPCCNT 0x01b0 /* UDP Checksum Error Counter */
134+
#define GEM_TISUBN 0x01bc /* 1588 Timer Increment Sub-ns */
135+
#define GEM_TSH 0x01c0 /* 1588 Timer Seconds High */
136+
#define GEM_TSL 0x01d0 /* 1588 Timer Seconds Low */
137+
#define GEM_TN 0x01d4 /* 1588 Timer Nanoseconds */
138+
#define GEM_TA 0x01d8 /* 1588 Timer Adjust */
139+
#define GEM_TI 0x01dc /* 1588 Timer Increment */
140+
#define GEM_EFTSL 0x01e0 /* PTP Event Frame Tx Seconds Low */
141+
#define GEM_EFTN 0x01e4 /* PTP Event Frame Tx Nanoseconds */
142+
#define GEM_EFRSL 0x01e8 /* PTP Event Frame Rx Seconds Low */
143+
#define GEM_EFRN 0x01ec /* PTP Event Frame Rx Nanoseconds */
144+
#define GEM_PEFTSL 0x01f0 /* PTP Peer Event Frame Tx Secs Low */
145+
#define GEM_PEFTN 0x01f4 /* PTP Peer Event Frame Tx Ns */
146+
#define GEM_PEFRSL 0x01f8 /* PTP Peer Event Frame Rx Sec Low */
147+
#define GEM_PEFRN 0x01fc /* PTP Peer Event Frame Rx Ns */
134148
#define GEM_DCFG1 0x0280 /* Design Config 1 */
135149
#define GEM_DCFG2 0x0284 /* Design Config 2 */
136150
#define GEM_DCFG3 0x0288 /* Design Config 3 */
@@ -174,6 +188,7 @@
174188
#define MACB_NCR_TPF_SIZE 1
175189
#define MACB_TZQ_OFFSET 12 /* Transmit zero quantum pause frame */
176190
#define MACB_TZQ_SIZE 1
191+
#define MACB_SRTSM_OFFSET 15
177192

178193
/* Bitfields in NCFGR */
179194
#define MACB_SPD_OFFSET 0 /* Speed */
@@ -319,6 +334,32 @@
319334
#define MACB_PTZ_SIZE 1
320335
#define MACB_WOL_OFFSET 14 /* Enable wake-on-lan interrupt */
321336
#define MACB_WOL_SIZE 1
337+
#define MACB_DRQFR_OFFSET 18 /* PTP Delay Request Frame Received */
338+
#define MACB_DRQFR_SIZE 1
339+
#define MACB_SFR_OFFSET 19 /* PTP Sync Frame Received */
340+
#define MACB_SFR_SIZE 1
341+
#define MACB_DRQFT_OFFSET 20 /* PTP Delay Request Frame Transmitted */
342+
#define MACB_DRQFT_SIZE 1
343+
#define MACB_SFT_OFFSET 21 /* PTP Sync Frame Transmitted */
344+
#define MACB_SFT_SIZE 1
345+
#define MACB_PDRQFR_OFFSET 22 /* PDelay Request Frame Received */
346+
#define MACB_PDRQFR_SIZE 1
347+
#define MACB_PDRSFR_OFFSET 23 /* PDelay Response Frame Received */
348+
#define MACB_PDRSFR_SIZE 1
349+
#define MACB_PDRQFT_OFFSET 24 /* PDelay Request Frame Transmitted */
350+
#define MACB_PDRQFT_SIZE 1
351+
#define MACB_PDRSFT_OFFSET 25 /* PDelay Response Frame Transmitted */
352+
#define MACB_PDRSFT_SIZE 1
353+
#define MACB_SRI_OFFSET 26 /* TSU Seconds Register Increment */
354+
#define MACB_SRI_SIZE 1
355+
356+
/* Timer increment fields */
357+
#define MACB_TI_CNS_OFFSET 0
358+
#define MACB_TI_CNS_SIZE 8
359+
#define MACB_TI_ACNS_OFFSET 8
360+
#define MACB_TI_ACNS_SIZE 8
361+
#define MACB_TI_NIT_OFFSET 16
362+
#define MACB_TI_NIT_SIZE 8
322363

323364
/* Bitfields in MAN */
324365
#define MACB_DATA_OFFSET 0 /* data */
@@ -386,6 +427,17 @@
386427
#define GEM_PBUF_LSO_OFFSET 27
387428
#define GEM_PBUF_LSO_SIZE 1
388429

430+
/* Bitfields in TISUBN */
431+
#define GEM_SUBNSINCR_OFFSET 0
432+
#define GEM_SUBNSINCR_SIZE 16
433+
434+
/* Bitfields in TI */
435+
#define GEM_NSINCR_OFFSET 0
436+
#define GEM_NSINCR_SIZE 8
437+
438+
/* Bitfields in ADJ */
439+
#define GEM_ADDSUB_OFFSET 31
440+
#define GEM_ADDSUB_SIZE 1
389441
/* Constants for CLK */
390442
#define MACB_CLK_DIV8 0
391443
#define MACB_CLK_DIV16 1
@@ -413,6 +465,7 @@
413465
#define MACB_CAPS_NO_GIGABIT_HALF 0x00000008
414466
#define MACB_CAPS_USRIO_DISABLED 0x00000010
415467
#define MACB_CAPS_JUMBO 0x00000020
468+
#define MACB_CAPS_GEM_HAS_PTP 0x00000040
416469
#define MACB_CAPS_FIFO_MODE 0x10000000
417470
#define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000
418471
#define MACB_CAPS_SG_DISABLED 0x40000000
@@ -782,6 +835,20 @@ struct macb_or_gem_ops {
782835
int (*mog_rx)(struct macb *bp, int budget);
783836
};
784837

838+
/* MACB-PTP interface: adapt to platform needs. */
839+
struct macb_ptp_info {
840+
void (*ptp_init)(struct net_device *ndev);
841+
void (*ptp_remove)(struct net_device *ndev);
842+
s32 (*get_ptp_max_adj)(void);
843+
unsigned int (*get_tsu_rate)(struct macb *bp);
844+
int (*get_ts_info)(struct net_device *dev,
845+
struct ethtool_ts_info *info);
846+
int (*get_hwtst)(struct net_device *netdev,
847+
struct ifreq *ifr);
848+
int (*set_hwtst)(struct net_device *netdev,
849+
struct ifreq *ifr, int cmd);
850+
};
851+
785852
struct macb_config {
786853
u32 caps;
787854
unsigned int dma_burst_length;
@@ -874,11 +941,18 @@ struct macb {
874941
unsigned int jumbo_max_len;
875942

876943
u32 wol;
944+
945+
struct macb_ptp_info *ptp_info; /* macb-ptp interface */
877946
};
878947

879948
static inline bool macb_is_gem(struct macb *bp)
880949
{
881950
return !!(bp->caps & MACB_CAPS_MACB_IS_GEM);
882951
}
883952

953+
static inline bool gem_has_ptp(struct macb *bp)
954+
{
955+
return !!(bp->caps & MACB_CAPS_GEM_HAS_PTP);
956+
}
957+
884958
#endif /* _MACB_H */

0 commit comments

Comments
 (0)