aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNimrod Andy <B38611@freescale.com>2014-08-21 05:09:38 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-22 13:45:56 -0400
commit91c0d987a9788dcc5fe26baafd73bf9242b68900 (patch)
tree82ccf2f5b675f2a65a362772b8875817d15ce13a
parent08f1a1b9d1a9902498f7c4bd93b14899dda18708 (diff)
net: fec: ptp: avoid register access when ipg clock is disabled
The current kernel hang on i.MX6SX with rootfs mount from MMC. The root cause is that ptp uses a periodic timer to access enet register even if ipg clock is disabled. FEC ptp driver start one period timer to read 1588 counter register in the ptp init function that is called after FEC driver is probed. To save power, after FEC probe finish, FEC driver disable all clocks including ipg clock that is needed for register access. i.MX5x, i.MX6q/dl/sl FEC register access don't cause system hang when ipg clock is disabled, just return zero value. But for i.MX6sx SOC, it cause system hang. To avoid the issue, we need to check ptp clock status before ptp timer count access. Signed-off-by: Fugang Duan <B38611@freescale.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/freescale/fec.h5
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c18
-rw-r--r--drivers/net/ethernet/freescale/fec_ptp.c33
3 files changed, 41 insertions, 15 deletions
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 9f7fa644a397..ee41d98b44b6 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -275,6 +275,9 @@ struct fec_enet_private {
275 struct clk *clk_enet_out; 275 struct clk *clk_enet_out;
276 struct clk *clk_ptp; 276 struct clk *clk_ptp;
277 277
278 bool ptp_clk_on;
279 struct mutex ptp_clk_mutex;
280
278 /* The saved address of a sent-in-place packet/buffer, for skfree(). */ 281 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
279 unsigned char *tx_bounce[TX_RING_SIZE]; 282 unsigned char *tx_bounce[TX_RING_SIZE];
280 struct sk_buff *tx_skbuff[TX_RING_SIZE]; 283 struct sk_buff *tx_skbuff[TX_RING_SIZE];
@@ -335,7 +338,7 @@ struct fec_enet_private {
335 u32 cycle_speed; 338 u32 cycle_speed;
336 int hwts_rx_en; 339 int hwts_rx_en;
337 int hwts_tx_en; 340 int hwts_tx_en;
338 struct timer_list time_keep; 341 struct delayed_work time_keep;
339 struct regulator *reg_phy; 342 struct regulator *reg_phy;
340}; 343};
341 344
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 4f87dffcb9b2..89355a719625 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1611,17 +1611,27 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
1611 goto failed_clk_enet_out; 1611 goto failed_clk_enet_out;
1612 } 1612 }
1613 if (fep->clk_ptp) { 1613 if (fep->clk_ptp) {
1614 mutex_lock(&fep->ptp_clk_mutex);
1614 ret = clk_prepare_enable(fep->clk_ptp); 1615 ret = clk_prepare_enable(fep->clk_ptp);
1615 if (ret) 1616 if (ret) {
1617 mutex_unlock(&fep->ptp_clk_mutex);
1616 goto failed_clk_ptp; 1618 goto failed_clk_ptp;
1619 } else {
1620 fep->ptp_clk_on = true;
1621 }
1622 mutex_unlock(&fep->ptp_clk_mutex);
1617 } 1623 }
1618 } else { 1624 } else {
1619 clk_disable_unprepare(fep->clk_ahb); 1625 clk_disable_unprepare(fep->clk_ahb);
1620 clk_disable_unprepare(fep->clk_ipg); 1626 clk_disable_unprepare(fep->clk_ipg);
1621 if (fep->clk_enet_out) 1627 if (fep->clk_enet_out)
1622 clk_disable_unprepare(fep->clk_enet_out); 1628 clk_disable_unprepare(fep->clk_enet_out);
1623 if (fep->clk_ptp) 1629 if (fep->clk_ptp) {
1630 mutex_lock(&fep->ptp_clk_mutex);
1624 clk_disable_unprepare(fep->clk_ptp); 1631 clk_disable_unprepare(fep->clk_ptp);
1632 fep->ptp_clk_on = false;
1633 mutex_unlock(&fep->ptp_clk_mutex);
1634 }
1625 } 1635 }
1626 1636
1627 return 0; 1637 return 0;
@@ -2625,6 +2635,8 @@ fec_probe(struct platform_device *pdev)
2625 if (IS_ERR(fep->clk_enet_out)) 2635 if (IS_ERR(fep->clk_enet_out))
2626 fep->clk_enet_out = NULL; 2636 fep->clk_enet_out = NULL;
2627 2637
2638 fep->ptp_clk_on = false;
2639 mutex_init(&fep->ptp_clk_mutex);
2628 fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp"); 2640 fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp");
2629 fep->bufdesc_ex = 2641 fep->bufdesc_ex =
2630 pdev->id_entry->driver_data & FEC_QUIRK_HAS_BUFDESC_EX; 2642 pdev->id_entry->driver_data & FEC_QUIRK_HAS_BUFDESC_EX;
@@ -2715,10 +2727,10 @@ fec_drv_remove(struct platform_device *pdev)
2715 struct net_device *ndev = platform_get_drvdata(pdev); 2727 struct net_device *ndev = platform_get_drvdata(pdev);
2716 struct fec_enet_private *fep = netdev_priv(ndev); 2728 struct fec_enet_private *fep = netdev_priv(ndev);
2717 2729
2730 cancel_delayed_work_sync(&fep->time_keep);
2718 cancel_work_sync(&fep->tx_timeout_work); 2731 cancel_work_sync(&fep->tx_timeout_work);
2719 unregister_netdev(ndev); 2732 unregister_netdev(ndev);
2720 fec_enet_mii_remove(fep); 2733 fec_enet_mii_remove(fep);
2721 del_timer_sync(&fep->time_keep);
2722 if (fep->reg_phy) 2734 if (fep->reg_phy)
2723 regulator_disable(fep->reg_phy); 2735 regulator_disable(fep->reg_phy);
2724 if (fep->ptp_clock) 2736 if (fep->ptp_clock)
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 82386b29914a..cca3617a2321 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -245,12 +245,20 @@ static int fec_ptp_settime(struct ptp_clock_info *ptp,
245 u64 ns; 245 u64 ns;
246 unsigned long flags; 246 unsigned long flags;
247 247
248 mutex_lock(&fep->ptp_clk_mutex);
249 /* Check the ptp clock */
250 if (!fep->ptp_clk_on) {
251 mutex_unlock(&fep->ptp_clk_mutex);
252 return -EINVAL;
253 }
254
248 ns = ts->tv_sec * 1000000000ULL; 255 ns = ts->tv_sec * 1000000000ULL;
249 ns += ts->tv_nsec; 256 ns += ts->tv_nsec;
250 257
251 spin_lock_irqsave(&fep->tmreg_lock, flags); 258 spin_lock_irqsave(&fep->tmreg_lock, flags);
252 timecounter_init(&fep->tc, &fep->cc, ns); 259 timecounter_init(&fep->tc, &fep->cc, ns);
253 spin_unlock_irqrestore(&fep->tmreg_lock, flags); 260 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
261 mutex_unlock(&fep->ptp_clk_mutex);
254 return 0; 262 return 0;
255} 263}
256 264
@@ -338,17 +346,22 @@ int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr)
338 * fec_time_keep - call timecounter_read every second to avoid timer overrun 346 * fec_time_keep - call timecounter_read every second to avoid timer overrun
339 * because ENET just support 32bit counter, will timeout in 4s 347 * because ENET just support 32bit counter, will timeout in 4s
340 */ 348 */
341static void fec_time_keep(unsigned long _data) 349static void fec_time_keep(struct work_struct *work)
342{ 350{
343 struct fec_enet_private *fep = (struct fec_enet_private *)_data; 351 struct delayed_work *dwork = to_delayed_work(work);
352 struct fec_enet_private *fep = container_of(dwork, struct fec_enet_private, time_keep);
344 u64 ns; 353 u64 ns;
345 unsigned long flags; 354 unsigned long flags;
346 355
347 spin_lock_irqsave(&fep->tmreg_lock, flags); 356 mutex_lock(&fep->ptp_clk_mutex);
348 ns = timecounter_read(&fep->tc); 357 if (fep->ptp_clk_on) {
349 spin_unlock_irqrestore(&fep->tmreg_lock, flags); 358 spin_lock_irqsave(&fep->tmreg_lock, flags);
359 ns = timecounter_read(&fep->tc);
360 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
361 }
362 mutex_unlock(&fep->ptp_clk_mutex);
350 363
351 mod_timer(&fep->time_keep, jiffies + HZ); 364 schedule_delayed_work(&fep->time_keep, HZ);
352} 365}
353 366
354/** 367/**
@@ -386,15 +399,13 @@ void fec_ptp_init(struct platform_device *pdev)
386 399
387 fec_ptp_start_cyclecounter(ndev); 400 fec_ptp_start_cyclecounter(ndev);
388 401
389 init_timer(&fep->time_keep); 402 INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep);
390 fep->time_keep.data = (unsigned long)fep;
391 fep->time_keep.function = fec_time_keep;
392 fep->time_keep.expires = jiffies + HZ;
393 add_timer(&fep->time_keep);
394 403
395 fep->ptp_clock = ptp_clock_register(&fep->ptp_caps, &pdev->dev); 404 fep->ptp_clock = ptp_clock_register(&fep->ptp_caps, &pdev->dev);
396 if (IS_ERR(fep->ptp_clock)) { 405 if (IS_ERR(fep->ptp_clock)) {
397 fep->ptp_clock = NULL; 406 fep->ptp_clock = NULL;
398 pr_err("ptp_clock_register failed\n"); 407 pr_err("ptp_clock_register failed\n");
399 } 408 }
409
410 schedule_delayed_work(&fep->time_keep, HZ);
400} 411}