Commit ff43da86 authored by Frank Li's avatar Frank Li Committed by David S. Miller

NET: FEC: dynamtic check DMA desc buff type

MX6 and mx28 support enhanced DMA descriptor buff to support 1588
ptp. But MX25, MX3x, MX5x can't support enhanced DMA descriptor buff.
Check fec type and choose correct DMA descriptor buff type.

Remove static config CONFIG_FEC_PTP.
ptp function will be auto detected.
Signed-off-by: default avatarFrank Li <Frank.Li@freescale.com>
Acked-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 579e1d81
...@@ -26,6 +26,7 @@ config FEC ...@@ -26,6 +26,7 @@ config FEC
ARCH_MXC || SOC_IMX28) ARCH_MXC || SOC_IMX28)
default ARCH_MXC || SOC_IMX28 if ARM default ARCH_MXC || SOC_IMX28 if ARM
select PHYLIB select PHYLIB
select PTP_1588_CLOCK
---help--- ---help---
Say Y here if you want to use the built-in 10/100 Fast ethernet Say Y here if you want to use the built-in 10/100 Fast ethernet
controller on some Motorola ColdFire and Freescale i.MX processors. controller on some Motorola ColdFire and Freescale i.MX processors.
...@@ -92,12 +93,4 @@ config GIANFAR ...@@ -92,12 +93,4 @@ config GIANFAR
This driver supports the Gigabit TSEC on the MPC83xx, MPC85xx, This driver supports the Gigabit TSEC on the MPC83xx, MPC85xx,
and MPC86xx family of chips, and the FEC on the 8540. and MPC86xx family of chips, and the FEC on the 8540.
config FEC_PTP
bool "PTP Hardware Clock (PHC)"
depends on FEC && ARCH_MXC && !SOC_IMX25 && !SOC_IMX27 && !SOC_IMX35 && !SOC_IMX5
select PTP_1588_CLOCK
--help---
Say Y here if you want to use PTP Hardware Clock (PHC) in the
driver. Only the basic clock operations have been implemented.
endif # NET_VENDOR_FREESCALE endif # NET_VENDOR_FREESCALE
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
# Makefile for the Freescale network device drivers. # Makefile for the Freescale network device drivers.
# #
obj-$(CONFIG_FEC) += fec.o obj-$(CONFIG_FEC) += fec.o fec_ptp.o
obj-$(CONFIG_FEC_PTP) += fec_ptp.o
obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o
ifeq ($(CONFIG_FEC_MPC52xx_MDIO),y) ifeq ($(CONFIG_FEC_MPC52xx_MDIO),y)
obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx_phy.o obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx_phy.o
......
...@@ -76,6 +76,8 @@ ...@@ -76,6 +76,8 @@
#define FEC_QUIRK_USE_GASKET (1 << 2) #define FEC_QUIRK_USE_GASKET (1 << 2)
/* Controller has GBIT support */ /* Controller has GBIT support */
#define FEC_QUIRK_HAS_GBIT (1 << 3) #define FEC_QUIRK_HAS_GBIT (1 << 3)
/* Controller has extend desc buffer */
#define FEC_QUIRK_HAS_BUFDESC_EX (1 << 4)
static struct platform_device_id fec_devtype[] = { static struct platform_device_id fec_devtype[] = {
{ {
...@@ -93,7 +95,8 @@ static struct platform_device_id fec_devtype[] = { ...@@ -93,7 +95,8 @@ static struct platform_device_id fec_devtype[] = {
.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME, .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME,
}, { }, {
.name = "imx6q-fec", .name = "imx6q-fec",
.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT, .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
FEC_QUIRK_HAS_BUFDESC_EX,
}, { }, {
/* sentinel */ /* sentinel */
} }
...@@ -140,7 +143,7 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address"); ...@@ -140,7 +143,7 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
#endif #endif
#endif /* CONFIG_M5272 */ #endif /* CONFIG_M5272 */
#if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE) #if (((RX_RING_SIZE + TX_RING_SIZE) * 32) > PAGE_SIZE)
#error "FEC: descriptor ring size constants too large" #error "FEC: descriptor ring size constants too large"
#endif #endif
...@@ -192,6 +195,24 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address"); ...@@ -192,6 +195,24 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
static int mii_cnt; static int mii_cnt;
static struct bufdesc *fec_enet_get_nextdesc(struct bufdesc *bdp, int is_ex)
{
struct bufdesc_ex *ex = (struct bufdesc_ex *)bdp;
if (is_ex)
return (struct bufdesc *)(ex + 1);
else
return bdp + 1;
}
static struct bufdesc *fec_enet_get_prevdesc(struct bufdesc *bdp, int is_ex)
{
struct bufdesc_ex *ex = (struct bufdesc_ex *)bdp;
if (is_ex)
return (struct bufdesc *)(ex - 1);
else
return bdp - 1;
}
static void *swap_buffer(void *bufaddr, int len) static void *swap_buffer(void *bufaddr, int len)
{ {
int i; int i;
...@@ -248,7 +269,11 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -248,7 +269,11 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
*/ */
if (((unsigned long) bufaddr) & FEC_ALIGNMENT) { if (((unsigned long) bufaddr) & FEC_ALIGNMENT) {
unsigned int index; unsigned int index;
index = bdp - fep->tx_bd_base; if (fep->bufdesc_ex)
index = (struct bufdesc_ex *)bdp -
(struct bufdesc_ex *)fep->tx_bd_base;
else
index = bdp - fep->tx_bd_base;
memcpy(fep->tx_bounce[index], skb->data, skb->len); memcpy(fep->tx_bounce[index], skb->data, skb->len);
bufaddr = fep->tx_bounce[index]; bufaddr = fep->tx_bounce[index];
} }
...@@ -280,17 +305,19 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -280,17 +305,19 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
| BD_ENET_TX_LAST | BD_ENET_TX_TC); | BD_ENET_TX_LAST | BD_ENET_TX_TC);
bdp->cbd_sc = status; bdp->cbd_sc = status;
#ifdef CONFIG_FEC_PTP if (fep->bufdesc_ex) {
bdp->cbd_bdu = 0;
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
ebdp->cbd_bdu = 0;
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
fep->hwts_tx_en)) { fep->hwts_tx_en)) {
bdp->cbd_esc = (BD_ENET_TX_TS | BD_ENET_TX_INT); ebdp->cbd_esc = (BD_ENET_TX_TS | BD_ENET_TX_INT);
skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
} else { } else {
bdp->cbd_esc = BD_ENET_TX_INT; ebdp->cbd_esc = BD_ENET_TX_INT;
}
} }
#endif
/* Trigger transmission start */ /* Trigger transmission start */
writel(0, fep->hwp + FEC_X_DES_ACTIVE); writel(0, fep->hwp + FEC_X_DES_ACTIVE);
...@@ -298,7 +325,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -298,7 +325,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
if (status & BD_ENET_TX_WRAP) if (status & BD_ENET_TX_WRAP)
bdp = fep->tx_bd_base; bdp = fep->tx_bd_base;
else else
bdp++; bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
if (bdp == fep->dirty_tx) { if (bdp == fep->dirty_tx) {
fep->tx_full = 1; fep->tx_full = 1;
...@@ -359,8 +386,12 @@ fec_restart(struct net_device *ndev, int duplex) ...@@ -359,8 +386,12 @@ fec_restart(struct net_device *ndev, int duplex)
/* Set receive and transmit descriptor base. */ /* Set receive and transmit descriptor base. */
writel(fep->bd_dma, fep->hwp + FEC_R_DES_START); writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE, if (fep->bufdesc_ex)
fep->hwp + FEC_X_DES_START); writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc_ex)
* RX_RING_SIZE, fep->hwp + FEC_X_DES_START);
else
writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc)
* RX_RING_SIZE, fep->hwp + FEC_X_DES_START);
fep->dirty_tx = fep->cur_tx = fep->tx_bd_base; fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
fep->cur_rx = fep->rx_bd_base; fep->cur_rx = fep->rx_bd_base;
...@@ -448,17 +479,16 @@ fec_restart(struct net_device *ndev, int duplex) ...@@ -448,17 +479,16 @@ fec_restart(struct net_device *ndev, int duplex)
writel(1 << 8, fep->hwp + FEC_X_WMRK); writel(1 << 8, fep->hwp + FEC_X_WMRK);
} }
#ifdef CONFIG_FEC_PTP if (fep->bufdesc_ex)
ecntl |= (1 << 4); ecntl |= (1 << 4);
#endif
/* And last, enable the transmit and receive processing */ /* And last, enable the transmit and receive processing */
writel(ecntl, fep->hwp + FEC_ECNTRL); writel(ecntl, fep->hwp + FEC_ECNTRL);
writel(0, fep->hwp + FEC_R_DES_ACTIVE); writel(0, fep->hwp + FEC_R_DES_ACTIVE);
#ifdef CONFIG_FEC_PTP if (fep->bufdesc_ex)
fec_ptp_start_cyclecounter(ndev); fec_ptp_start_cyclecounter(ndev);
#endif
/* Enable interrupts we wish to service */ /* Enable interrupts we wish to service */
writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
} }
...@@ -544,19 +574,20 @@ fec_enet_tx(struct net_device *ndev) ...@@ -544,19 +574,20 @@ fec_enet_tx(struct net_device *ndev)
ndev->stats.tx_packets++; ndev->stats.tx_packets++;
} }
#ifdef CONFIG_FEC_PTP if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) &&
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { fep->bufdesc_ex) {
struct skb_shared_hwtstamps shhwtstamps; struct skb_shared_hwtstamps shhwtstamps;
unsigned long flags; unsigned long flags;
struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
memset(&shhwtstamps, 0, sizeof(shhwtstamps)); memset(&shhwtstamps, 0, sizeof(shhwtstamps));
spin_lock_irqsave(&fep->tmreg_lock, flags); spin_lock_irqsave(&fep->tmreg_lock, flags);
shhwtstamps.hwtstamp = ns_to_ktime( shhwtstamps.hwtstamp = ns_to_ktime(
timecounter_cyc2time(&fep->tc, bdp->ts)); timecounter_cyc2time(&fep->tc, ebdp->ts));
spin_unlock_irqrestore(&fep->tmreg_lock, flags); spin_unlock_irqrestore(&fep->tmreg_lock, flags);
skb_tstamp_tx(skb, &shhwtstamps); skb_tstamp_tx(skb, &shhwtstamps);
} }
#endif
if (status & BD_ENET_TX_READY) if (status & BD_ENET_TX_READY)
printk("HEY! Enet xmit interrupt and TX_READY.\n"); printk("HEY! Enet xmit interrupt and TX_READY.\n");
...@@ -575,7 +606,7 @@ fec_enet_tx(struct net_device *ndev) ...@@ -575,7 +606,7 @@ fec_enet_tx(struct net_device *ndev)
if (status & BD_ENET_TX_WRAP) if (status & BD_ENET_TX_WRAP)
bdp = fep->tx_bd_base; bdp = fep->tx_bd_base;
else else
bdp++; bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
/* Since we have freed up a buffer, the ring is no longer full /* Since we have freed up a buffer, the ring is no longer full
*/ */
...@@ -683,21 +714,23 @@ fec_enet_rx(struct net_device *ndev) ...@@ -683,21 +714,23 @@ fec_enet_rx(struct net_device *ndev)
skb_put(skb, pkt_len - 4); /* Make room */ skb_put(skb, pkt_len - 4); /* Make room */
skb_copy_to_linear_data(skb, data, pkt_len - 4); skb_copy_to_linear_data(skb, data, pkt_len - 4);
skb->protocol = eth_type_trans(skb, ndev); skb->protocol = eth_type_trans(skb, ndev);
#ifdef CONFIG_FEC_PTP
/* Get receive timestamp from the skb */ /* Get receive timestamp from the skb */
if (fep->hwts_rx_en) { if (fep->hwts_rx_en && fep->bufdesc_ex) {
struct skb_shared_hwtstamps *shhwtstamps = struct skb_shared_hwtstamps *shhwtstamps =
skb_hwtstamps(skb); skb_hwtstamps(skb);
unsigned long flags; unsigned long flags;
struct bufdesc_ex *ebdp =
(struct bufdesc_ex *)bdp;
memset(shhwtstamps, 0, sizeof(*shhwtstamps)); memset(shhwtstamps, 0, sizeof(*shhwtstamps));
spin_lock_irqsave(&fep->tmreg_lock, flags); spin_lock_irqsave(&fep->tmreg_lock, flags);
shhwtstamps->hwtstamp = ns_to_ktime( shhwtstamps->hwtstamp = ns_to_ktime(
timecounter_cyc2time(&fep->tc, bdp->ts)); timecounter_cyc2time(&fep->tc, ebdp->ts));
spin_unlock_irqrestore(&fep->tmreg_lock, flags); spin_unlock_irqrestore(&fep->tmreg_lock, flags);
} }
#endif
if (!skb_defer_rx_timestamp(skb)) if (!skb_defer_rx_timestamp(skb))
netif_rx(skb); netif_rx(skb);
} }
...@@ -712,17 +745,19 @@ fec_enet_rx(struct net_device *ndev) ...@@ -712,17 +745,19 @@ fec_enet_rx(struct net_device *ndev)
status |= BD_ENET_RX_EMPTY; status |= BD_ENET_RX_EMPTY;
bdp->cbd_sc = status; bdp->cbd_sc = status;
#ifdef CONFIG_FEC_PTP if (fep->bufdesc_ex) {
bdp->cbd_esc = BD_ENET_RX_INT; struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
bdp->cbd_prot = 0;
bdp->cbd_bdu = 0; ebdp->cbd_esc = BD_ENET_RX_INT;
#endif ebdp->cbd_prot = 0;
ebdp->cbd_bdu = 0;
}
/* Update BD pointer to next entry */ /* Update BD pointer to next entry */
if (status & BD_ENET_RX_WRAP) if (status & BD_ENET_RX_WRAP)
bdp = fep->rx_bd_base; bdp = fep->rx_bd_base;
else else
bdp++; bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
/* Doing this here will keep the FEC running while we process /* Doing this here will keep the FEC running while we process
* incoming frames. On a heavily loaded network, we should be * incoming frames. On a heavily loaded network, we should be
* able to keep up at the expense of system resources. * able to keep up at the expense of system resources.
...@@ -1157,10 +1192,9 @@ static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) ...@@ -1157,10 +1192,9 @@ static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
if (!phydev) if (!phydev)
return -ENODEV; return -ENODEV;
#ifdef CONFIG_FEC_PTP if (cmd == SIOCSHWTSTAMP && fep->bufdesc_ex)
if (cmd == SIOCSHWTSTAMP)
return fec_ptp_ioctl(ndev, rq, cmd); return fec_ptp_ioctl(ndev, rq, cmd);
#endif
return phy_mii_ioctl(phydev, rq, cmd); return phy_mii_ioctl(phydev, rq, cmd);
} }
...@@ -1180,7 +1214,7 @@ static void fec_enet_free_buffers(struct net_device *ndev) ...@@ -1180,7 +1214,7 @@ static void fec_enet_free_buffers(struct net_device *ndev)
FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
if (skb) if (skb)
dev_kfree_skb(skb); dev_kfree_skb(skb);
bdp++; bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
} }
bdp = fep->tx_bd_base; bdp = fep->tx_bd_base;
...@@ -1207,14 +1241,17 @@ static int fec_enet_alloc_buffers(struct net_device *ndev) ...@@ -1207,14 +1241,17 @@ static int fec_enet_alloc_buffers(struct net_device *ndev)
bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data, bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data,
FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
bdp->cbd_sc = BD_ENET_RX_EMPTY; bdp->cbd_sc = BD_ENET_RX_EMPTY;
#ifdef CONFIG_FEC_PTP
bdp->cbd_esc = BD_ENET_RX_INT; if (fep->bufdesc_ex) {
#endif struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
bdp++; ebdp->cbd_esc = BD_ENET_RX_INT;
}
bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
} }
/* Set the last buffer to wrap. */ /* Set the last buffer to wrap. */
bdp--; bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
bdp->cbd_sc |= BD_SC_WRAP; bdp->cbd_sc |= BD_SC_WRAP;
bdp = fep->tx_bd_base; bdp = fep->tx_bd_base;
...@@ -1224,14 +1261,16 @@ static int fec_enet_alloc_buffers(struct net_device *ndev) ...@@ -1224,14 +1261,16 @@ static int fec_enet_alloc_buffers(struct net_device *ndev)
bdp->cbd_sc = 0; bdp->cbd_sc = 0;
bdp->cbd_bufaddr = 0; bdp->cbd_bufaddr = 0;
#ifdef CONFIG_FEC_PTP if (fep->bufdesc_ex) {
bdp->cbd_esc = BD_ENET_RX_INT; struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
#endif ebdp->cbd_esc = BD_ENET_RX_INT;
bdp++; }
bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
} }
/* Set the last buffer to wrap. */ /* Set the last buffer to wrap. */
bdp--; bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
bdp->cbd_sc |= BD_SC_WRAP; bdp->cbd_sc |= BD_SC_WRAP;
return 0; return 0;
...@@ -1444,7 +1483,11 @@ static int fec_enet_init(struct net_device *ndev) ...@@ -1444,7 +1483,11 @@ static int fec_enet_init(struct net_device *ndev)
/* Set receive and transmit descriptor base. */ /* Set receive and transmit descriptor base. */
fep->rx_bd_base = cbd_base; fep->rx_bd_base = cbd_base;
fep->tx_bd_base = cbd_base + RX_RING_SIZE; if (fep->bufdesc_ex)
fep->tx_bd_base = (struct bufdesc *)
(((struct bufdesc_ex *)cbd_base) + RX_RING_SIZE);
else
fep->tx_bd_base = cbd_base + RX_RING_SIZE;
/* The FEC Ethernet specific entries in the device structure */ /* The FEC Ethernet specific entries in the device structure */
ndev->watchdog_timeo = TX_TIMEOUT; ndev->watchdog_timeo = TX_TIMEOUT;
...@@ -1457,11 +1500,11 @@ static int fec_enet_init(struct net_device *ndev) ...@@ -1457,11 +1500,11 @@ static int fec_enet_init(struct net_device *ndev)
/* Initialize the BD for every fragment in the page. */ /* Initialize the BD for every fragment in the page. */
bdp->cbd_sc = 0; bdp->cbd_sc = 0;
bdp++; bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
} }
/* Set the last buffer to wrap */ /* Set the last buffer to wrap */
bdp--; bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
bdp->cbd_sc |= BD_SC_WRAP; bdp->cbd_sc |= BD_SC_WRAP;
/* ...and the same for transmit */ /* ...and the same for transmit */
...@@ -1471,11 +1514,11 @@ static int fec_enet_init(struct net_device *ndev) ...@@ -1471,11 +1514,11 @@ static int fec_enet_init(struct net_device *ndev)
/* Initialize the BD for every fragment in the page. */ /* Initialize the BD for every fragment in the page. */
bdp->cbd_sc = 0; bdp->cbd_sc = 0;
bdp->cbd_bufaddr = 0; bdp->cbd_bufaddr = 0;
bdp++; bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
} }
/* Set the last buffer to wrap */ /* Set the last buffer to wrap */
bdp--; bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
bdp->cbd_sc |= BD_SC_WRAP; bdp->cbd_sc |= BD_SC_WRAP;
fec_restart(ndev, 0); fec_restart(ndev, 0);
...@@ -1574,6 +1617,8 @@ fec_probe(struct platform_device *pdev) ...@@ -1574,6 +1617,8 @@ fec_probe(struct platform_device *pdev)
fep->pdev = pdev; fep->pdev = pdev;
fep->dev_id = dev_id++; fep->dev_id = dev_id++;
fep->bufdesc_ex = 0;
if (!fep->hwp) { if (!fep->hwp) {
ret = -ENOMEM; ret = -ENOMEM;
goto failed_ioremap; goto failed_ioremap;
...@@ -1628,19 +1673,19 @@ fec_probe(struct platform_device *pdev) ...@@ -1628,19 +1673,19 @@ fec_probe(struct platform_device *pdev)
goto failed_clk; goto failed_clk;
} }
#ifdef CONFIG_FEC_PTP
fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp"); fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp");
fep->bufdesc_ex =
pdev->id_entry->driver_data & FEC_QUIRK_HAS_BUFDESC_EX;
if (IS_ERR(fep->clk_ptp)) { if (IS_ERR(fep->clk_ptp)) {
ret = PTR_ERR(fep->clk_ptp); ret = PTR_ERR(fep->clk_ptp);
goto failed_clk; fep->bufdesc_ex = 0;
} }
#endif
clk_prepare_enable(fep->clk_ahb); clk_prepare_enable(fep->clk_ahb);
clk_prepare_enable(fep->clk_ipg); clk_prepare_enable(fep->clk_ipg);
#ifdef CONFIG_FEC_PTP if (!IS_ERR(fep->clk_ptp))
clk_prepare_enable(fep->clk_ptp); clk_prepare_enable(fep->clk_ptp);
#endif
reg_phy = devm_regulator_get(&pdev->dev, "phy"); reg_phy = devm_regulator_get(&pdev->dev, "phy");
if (!IS_ERR(reg_phy)) { if (!IS_ERR(reg_phy)) {
ret = regulator_enable(reg_phy); ret = regulator_enable(reg_phy);
...@@ -1668,9 +1713,8 @@ fec_probe(struct platform_device *pdev) ...@@ -1668,9 +1713,8 @@ fec_probe(struct platform_device *pdev)
if (ret) if (ret)
goto failed_register; goto failed_register;
#ifdef CONFIG_FEC_PTP if (fep->bufdesc_ex)
fec_ptp_init(ndev, pdev); fec_ptp_init(ndev, pdev);
#endif
return 0; return 0;
...@@ -1681,9 +1725,8 @@ fec_probe(struct platform_device *pdev) ...@@ -1681,9 +1725,8 @@ fec_probe(struct platform_device *pdev)
failed_regulator: failed_regulator:
clk_disable_unprepare(fep->clk_ahb); clk_disable_unprepare(fep->clk_ahb);
clk_disable_unprepare(fep->clk_ipg); clk_disable_unprepare(fep->clk_ipg);
#ifdef CONFIG_FEC_PTP if (!IS_ERR(fep->clk_ptp))
clk_disable_unprepare(fep->clk_ptp); clk_disable_unprepare(fep->clk_ptp);
#endif
failed_pin: failed_pin:
failed_clk: failed_clk:
for (i = 0; i < FEC_IRQ_NUM; i++) { for (i = 0; i < FEC_IRQ_NUM; i++) {
...@@ -1716,12 +1759,10 @@ fec_drv_remove(struct platform_device *pdev) ...@@ -1716,12 +1759,10 @@ fec_drv_remove(struct platform_device *pdev)
if (irq > 0) if (irq > 0)
free_irq(irq, ndev); free_irq(irq, ndev);
} }
#ifdef CONFIG_FEC_PTP
del_timer_sync(&fep->time_keep); del_timer_sync(&fep->time_keep);
clk_disable_unprepare(fep->clk_ptp); clk_disable_unprepare(fep->clk_ptp);
if (fep->ptp_clock) if (fep->ptp_clock)
ptp_clock_unregister(fep->ptp_clock); ptp_clock_unregister(fep->ptp_clock);
#endif
clk_disable_unprepare(fep->clk_ahb); clk_disable_unprepare(fep->clk_ahb);
clk_disable_unprepare(fep->clk_ipg); clk_disable_unprepare(fep->clk_ipg);
iounmap(fep->hwp); iounmap(fep->hwp);
......
...@@ -13,11 +13,9 @@ ...@@ -13,11 +13,9 @@
#define FEC_H #define FEC_H
/****************************************************************************/ /****************************************************************************/
#ifdef CONFIG_FEC_PTP
#include <linux/clocksource.h> #include <linux/clocksource.h>
#include <linux/net_tstamp.h> #include <linux/net_tstamp.h>
#include <linux/ptp_clock_kernel.h> #include <linux/ptp_clock_kernel.h>
#endif
#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \ #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
defined(CONFIG_M520x) || defined(CONFIG_M532x) || \ defined(CONFIG_M520x) || defined(CONFIG_M532x) || \
...@@ -94,14 +92,17 @@ struct bufdesc { ...@@ -94,14 +92,17 @@ struct bufdesc {
unsigned short cbd_datlen; /* Data length */ unsigned short cbd_datlen; /* Data length */
unsigned short cbd_sc; /* Control and status info */ unsigned short cbd_sc; /* Control and status info */
unsigned long cbd_bufaddr; /* Buffer address */ unsigned long cbd_bufaddr; /* Buffer address */
#ifdef CONFIG_FEC_PTP };
struct bufdesc_ex {
struct bufdesc desc;
unsigned long cbd_esc; unsigned long cbd_esc;
unsigned long cbd_prot; unsigned long cbd_prot;
unsigned long cbd_bdu; unsigned long cbd_bdu;
unsigned long ts; unsigned long ts;
unsigned short res0[4]; unsigned short res0[4];
#endif
}; };
#else #else
struct bufdesc { struct bufdesc {
unsigned short cbd_sc; /* Control and status info */ unsigned short cbd_sc; /* Control and status info */
...@@ -203,9 +204,7 @@ struct fec_enet_private { ...@@ -203,9 +204,7 @@ struct fec_enet_private {
struct clk *clk_ipg; struct clk *clk_ipg;
struct clk *clk_ahb; struct clk *clk_ahb;
#ifdef CONFIG_FEC_PTP
struct clk *clk_ptp; struct clk *clk_ptp;
#endif
/* The saved address of a sent-in-place packet/buffer, for skfree(). */ /* The saved address of a sent-in-place packet/buffer, for skfree(). */
unsigned char *tx_bounce[TX_RING_SIZE]; unsigned char *tx_bounce[TX_RING_SIZE];
...@@ -243,8 +242,8 @@ struct fec_enet_private { ...@@ -243,8 +242,8 @@ struct fec_enet_private {
int full_duplex; int full_duplex;
struct completion mdio_done; struct completion mdio_done;
int irq[FEC_IRQ_NUM]; int irq[FEC_IRQ_NUM];
int bufdesc_ex;
#ifdef CONFIG_FEC_PTP
struct ptp_clock *ptp_clock; struct ptp_clock *ptp_clock;
struct ptp_clock_info ptp_caps; struct ptp_clock_info ptp_caps;
unsigned long last_overflow_check; unsigned long last_overflow_check;
...@@ -257,15 +256,12 @@ struct fec_enet_private { ...@@ -257,15 +256,12 @@ struct fec_enet_private {
int hwts_rx_en; int hwts_rx_en;
int hwts_tx_en; int hwts_tx_en;
struct timer_list time_keep; struct timer_list time_keep;
#endif
}; };
#ifdef CONFIG_FEC_PTP
void fec_ptp_init(struct net_device *ndev, struct platform_device *pdev); void fec_ptp_init(struct net_device *ndev, struct platform_device *pdev);
void fec_ptp_start_cyclecounter(struct net_device *ndev); void fec_ptp_start_cyclecounter(struct net_device *ndev);
int fec_ptp_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd); int fec_ptp_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd);
#endif
/****************************************************************************/ /****************************************************************************/
#endif /* FEC_H */ #endif /* FEC_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment