add enhancement into the existing reset flow
Subsystems (4)
v2 cover add enhancement into the existing reset flow
From: Sean Wang <[email protected]>
Current driver only resets DMA used by descriptor rings which can't guarantee it can recover all various kinds of fatal errors, so the patch
1) tries to reset the underlying hardware resource from scratch on Mediatek SoC required for ethernet running.
2) refactors code in order to the reusability of existing code.
3) considers handling for race condition between the reset flow and callbacks registered into core driver called about hardware accessing.
4) introduces power domain usage to hardware setup which leads to have cleanly and completely restore to the state as the initial.
Changes since v1:
- fix the build error with module built causing undefined symbol for pinctrl_bind_pins, so using pinctrl_select_state instead accomplishes the pin mux setup during the reset process.
Sean Wang (7):
net: ethernet: mediatek: refactoring mtk_hw_init to be reused
net: ethernet: mediatek: add mtk_hw_deinit call as the opposite to
mtk_hw_init call
net: ethernet: mediatek: cleanup error path inside mtk_hw_init
net: ethernet: mediatek: add controlling power domain the ethernet
belongs to
net: ethernet: mediatek: add the whole ethernet reset into the reset
process
net: ethernet: mediatek: add more resets for internal ethernet circuit
block
net: ethernet: mediatek: avoid race condition during the reset process
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 226 +++++++++++++++++++++------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 15 +- 2 files changed, 186 insertions(+), 55 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/7 net: ethernet: mediatek: refactoring mtk_hw_init to be reused
From: Sean Wang <[email protected]>
the existing mtk_hw_init includes hardware and software initialization inside so that it is slightly hard to reuse them for the process of the reset recovery, so some splitting is made here for keeping hardware initializing relevant thing and the else such as IRQ registration and MDIO initialization what are all about to the interface of core driver moved to the other proper place because they have no needs to register IRQ and re-initialize structure again during the reset process.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 62 ++++++++++++++++------------- 1 file changed, 34 insertions(+), 28 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +34 -28
@@ -1415,7 +1415,12 @@ static int mtk_stop(struct net_device *dev)static int __init mtk_hw_init (struct mtk_eth *eth) { -int err, i; +int i; + +clk_prepare_enable (eth->clks[MTK_CLK_ETHIF ]); +clk_prepare_enable (eth->clks[MTK_CLK_ESW ]); +clk_prepare_enable (eth->clks[MTK_CLK_GP1 ]); +clk_prepare_enable (eth->clks[MTK_CLK_GP2 ]);/* reset the frame engine */ reset_control_assert (eth->rstc);
@@ -1441,19 +1446,6 @@ static int __init mtk_hw_init(struct mtk_eth *eth)/* Enable RX VLan Offloading */ mtk_w32 (eth,1 ,MTK_CDMP_EG_CTRL ); - err =devm_request_irq (eth->dev, eth->irq[1 ], mtk_handle_irq_tx,0 , -dev_name (eth->dev), eth); -if (err) -return err; - err =devm_request_irq (eth->dev, eth->irq[2 ], mtk_handle_irq_rx,0 , -dev_name (eth->dev), eth); -if (err) -return err; - - err =mtk_mdio_init (eth); -if (err) -return err; -/* disable delay and normal interrupt */ mtk_w32 (eth,0 ,MTK_QDMA_DELAY_INT );mtk_w32 (eth,0 ,MTK_PDMA_DELAY_INT );
@@ -1783,16 +1775,7 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) eth->netdev[id]->features |=MTK_HW_FEATURES ; eth->netdev[id]->ethtool_ops = &mtk_ethtool_ops; - err =register_netdev (eth->netdev[id]); -if (err) { -dev_err (eth->dev,"error bringing up device\n" ); - goto free_netdev; - } eth->netdev[id]->irq = eth->irq[0 ]; -netif_info (eth, probe, eth->netdev[id], -"mediatek frame engine at 0x%08lx, irq %d\n" , - eth->netdev[id]->base_addr, eth->irq[0 ]); -return 0 ; free_netdev:
@@ -1862,11 +1845,6 @@ static int mtk_probe(struct platform_device *pdev) } } -clk_prepare_enable (eth->clks[MTK_CLK_ETHIF ]); -clk_prepare_enable (eth->clks[MTK_CLK_ESW ]); -clk_prepare_enable (eth->clks[MTK_CLK_GP1 ]); -clk_prepare_enable (eth->clks[MTK_CLK_GP2 ]); - eth->msg_enable =netif_msg_init (mtk_msg_level,MTK_DEFAULT_MSG_ENABLE );INIT_WORK (ð->pending_work, mtk_pending_work);
@@ -1887,6 +1865,34 @@ static int mtk_probe(struct platform_device *pdev) goto err_free_dev; } + err =devm_request_irq (eth->dev, eth->irq[1 ], mtk_handle_irq_tx,0 , +dev_name (eth->dev), eth); +if (err) + goto err_free_dev; + + err =devm_request_irq (eth->dev, eth->irq[2 ], mtk_handle_irq_rx,0 , +dev_name (eth->dev), eth); +if (err) + goto err_free_dev; + + err =mtk_mdio_init (eth); +if (err) + goto err_free_dev; + +for (i =0 ; i <MTK_MAX_DEVS ; i++) { +if (!eth->netdev[i]) +continue ; + + err =register_netdev (eth->netdev[i]); +if (err) { +dev_err (eth->dev,"error bringing up device\n" ); + goto err_free_dev; + }else +netif_info (eth, probe, eth->netdev[i], +"mediatek frame engine at 0x%08lx, irq %d\n" , + eth->netdev[i]->base_addr, eth->irq[0 ]); + } +/* we run 2 devices on the same DMA ring so we need a dummy device * for NAPI to work */
Signature · 1 line
1.9.1
PATCH v2 2/7 net: ethernet: mediatek: add mtk_hw_deinit call as the opposite to mtk_hw_init call
In reply to [email protected]From: Sean Wang <[email protected]>
grouping things related to the deinitialization of what mtk_hw_init call does that help to be reused by the reset process and the error path handling.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +11 -4
@@ -1477,6 +1477,16 @@ static int __init mtk_hw_init(struct mtk_eth *eth)return 0 ; } +static int mtk_hw_deinit (struct mtk_eth *eth) +{ +clk_disable_unprepare (eth->clks[MTK_CLK_GP2 ]); +clk_disable_unprepare (eth->clks[MTK_CLK_GP1 ]); +clk_disable_unprepare (eth->clks[MTK_CLK_ESW ]); +clk_disable_unprepare (eth->clks[MTK_CLK_ETHIF ]); + +return 0 ; +} +static int __init mtk_init (struct net_device *dev) {struct mtk_mac *mac =netdev_priv (dev);
@@ -1923,10 +1933,7 @@ static int mtk_remove(struct platform_device *pdev)mtk_stop (eth->netdev[i]); } -clk_disable_unprepare (eth->clks[MTK_CLK_ETHIF ]); -clk_disable_unprepare (eth->clks[MTK_CLK_ESW ]); -clk_disable_unprepare (eth->clks[MTK_CLK_GP1 ]); -clk_disable_unprepare (eth->clks[MTK_CLK_GP2 ]); +mtk_hw_deinit (eth);netif_napi_del (ð->tx_napi);netif_napi_del (ð->rx_napi);
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1473866001-9805-1-git-send-email-sean.wang-NuS5LvNUpcJWk0Htik3J/[email protected]
PATCH v2 3/7 net: ethernet: mediatek: cleanup error path inside mtk_hw_init
From: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/[email protected]>
This cleans up the error path inside mtk_hw_init call, causing it able to exit appropriately when something fails and also includes refactoring mtk_cleanup call to make the partial logic reusable on the error path.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 34 ++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +29 -5
@@ -1564,17 +1564,36 @@ static void mtk_pending_work(struct work_struct *work)rtnl_unlock (); } -static int mtk_cleanup (struct mtk_eth *eth) +static int mtk_free_dev (struct mtk_eth *eth) {int i;for (i =0 ; i <MTK_MAC_COUNT ; i++) {if (!eth->netdev[i])continue ; +free_netdev (eth->netdev[i]); + } + +return 0 ; +} +static int mtk_unreg_dev (struct mtk_eth *eth) +{ +int i; + +for (i =0 ; i <MTK_MAC_COUNT ; i++) { +if (!eth->netdev[i]) +continue ;unregister_netdev (eth->netdev[i]); -free_netdev (eth->netdev[i]); } + +return 0 ; +} + +static int mtk_cleanup (struct mtk_eth *eth) +{ +mtk_unreg_dev (eth); +mtk_free_dev (eth);cancel_work_sync (ð->pending_work);return 0 ;
@@ -1872,7 +1891,7 @@ static int mtk_probe(struct platform_device *pdev) err =mtk_add_mac (eth, mac_np);if (err) - goto err_free_dev; + goto err_deinit_hw; } err = devm_request_irq(eth->dev, eth->irq[1], mtk_handle_irq_tx, 0,
@@ -1896,7 +1915,7 @@ static int mtk_probe(struct platform_device *pdev) err =register_netdev (eth->netdev[i]);if (err) {dev_err (eth->dev,"error bringing up device\n" ); - goto err_free_dev; + goto err_deinit_mdio; }else netif_info(eth, probe, eth->netdev[i], "mediatek frame engine at 0x%08lx, irq %d\n",
@@ -1916,8 +1935,13 @@ static int mtk_probe(struct platform_device *pdev)return 0 ; +err_deinit_mdio: +mtk_mdio_cleanup (eth); err_free_dev: -mtk_cleanup (eth); +mtk_free_dev (eth); +err_deinit_hw: +mtk_hw_deinit (eth); +return err; }
Signature · 1 line
1.9.1
From: <sean.wang-NuS5LvNUpcJWk0Htik3J/[email protected]>
Date: Wed, 14 Sep 2016 23:13:14 +0800
Quoted 13 lines
From: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/[email protected]>
Current driver only resets DMA used by descriptor rings which can't guarantee it can recover all various kinds of fatal errors, so the patch
1) tries to reset the underlying hardware resource from scratch on Mediatek SoC required for ethernet running.
2) refactors code in order to the reusability of existing code.
3) considers handling for race condition between the reset flow and callbacks registered into core driver called about hardware accessing.
4) introduces power domain usage to hardware setup which leads to have cleanly and completely restore to the state as the initial.
Quoted 4 lines
Changes since v1:
- fix the build error with module built causing undefined symbol forpinctrl_bind_pins, so usingpinctrl_select_stateinstead accomplishes the pin mux setup during the reset process.
Series applied, thanks.
PATCH v2 4/7 net: ethernet: mediatek: add controlling power domain the ethernet belongs to
In reply to [email protected]From: Sean Wang <[email protected]>
introduce power domain control which the digital circuit of the ethernet belongs to inside the flow of hardware initialization and deinitialization which helps the entire ethernet hardware block could restart cleanly and completely as being back to the initial state when the whole machine reboot.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +7 -0
@@ -18,6 +18,7 @@#include <linux/mfd/syscon.h> #include <linux/regmap.h> #include <linux/clk.h> +#include <linux/pm_runtime.h> #include <linux/if_vlan.h> #include <linux/reset.h> #include <linux/tcp.h>
@@ -1417,6 +1418,9 @@ static int __init mtk_hw_init(struct mtk_eth *eth) {int i; +pm_runtime_enable (eth->dev); +pm_runtime_get_sync (eth->dev); +clk_prepare_enable (eth->clks[MTK_CLK_ETHIF ]);clk_prepare_enable (eth->clks[MTK_CLK_ESW ]);clk_prepare_enable (eth->clks[MTK_CLK_GP1 ]);
@@ -1484,6 +1488,9 @@ static int mtk_hw_deinit(struct mtk_eth *eth)clk_disable_unprepare (eth->clks[MTK_CLK_ESW ]);clk_disable_unprepare (eth->clks[MTK_CLK_ETHIF ]); +pm_runtime_put_sync (eth->dev); +pm_runtime_disable (eth->dev); +return 0 ; }
Signature · 1 line
1.9.1
PATCH v2 5/7 net: ethernet: mediatek: add the whole ethernet reset into the reset process
In reply to [email protected]From: Sean Wang <[email protected]>
1) original driver only resets DMA used by descriptor rings which can't guarantee it can recover all various kinds of fatal errors, so the patch tries to reset the underlying hardware resource from scratch on Mediatek SoC required for ethernet running, including power, pin mux control, clock and internal circuits on the ethernet in order to restore into the initial state which the rebooted machine gives.
2) add state variable inside structure mtk_eth to help distinguish mtk_hw_init is called between the initialization during boot time or re-initialization during the reset process.
3) add ge_mode variable inside structure mtk_mac for restoring the interface mode of the current setup for the target MAC.
4) remove __init attribute from mtk_hw_init definition
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 51 ++++++++++++++++++++++++----- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 8 +++++ 2 files changed, 51 insertions(+), 8 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +43 -8
@@ -231,7 +231,7 @@ static int mtk_phy_connect(struct mtk_mac *mac) {struct mtk_eth *eth = mac->hw;struct device_node *np; -u32 val, ge_mode; +u32 val; np =of_parse_phandle (mac->of_node,"phy-handle" ,0 );if (!np &&of_phy_is_fixed_link (mac->of_node))
@@ -245,18 +245,18 @@ static int mtk_phy_connect(struct mtk_mac *mac)case PHY_INTERFACE_MODE_RGMII_RXID :case PHY_INTERFACE_MODE_RGMII_ID :case PHY_INTERFACE_MODE_RGMII : - ge_mode =0 ; + mac->ge_mode =0 ;break ;case PHY_INTERFACE_MODE_MII : - ge_mode =1 ; + mac->ge_mode =1 ;break ;case PHY_INTERFACE_MODE_REVMII : - ge_mode =2 ; + mac->ge_mode =2 ;break ;case PHY_INTERFACE_MODE_RMII :if (!mac->id) goto err_phy; - ge_mode =3 ; + mac->ge_mode =3 ;break ;default : goto err_phy;
@@ -265,7 +265,7 @@ static int mtk_phy_connect(struct mtk_mac *mac)/* put the gmac into the right mode */ regmap_read (eth->ethsys,ETHSYS_SYSCFG0 , &val); val &= ~SYSCFG0_GE_MODE (SYSCFG0_GE_MASK , mac->id); - val |=SYSCFG0_GE_MODE (ge_mode, mac->id); + val |=SYSCFG0_GE_MODE (mac->ge_mode, mac->id);regmap_write (eth->ethsys,ETHSYS_SYSCFG0 , val);mtk_phy_connect_node (eth, mac, np);
@@ -1414,9 +1414,12 @@ static int mtk_stop(struct net_device *dev)return 0 ; } -static int __init mtk_hw_init (struct mtk_eth *eth) +static int mtk_hw_init (struct mtk_eth *eth) { -int i; +int i, val; + +if (test_and_set_bit (MTK_HW_INIT , ð->state)) +return 0 ;pm_runtime_enable (eth->dev);pm_runtime_get_sync (eth->dev);
@@ -1432,6 +1435,15 @@ static int __init mtk_hw_init(struct mtk_eth *eth)reset_control_deassert (eth->rstc);usleep_range (10 ,20 ); +regmap_read (eth->ethsys,ETHSYS_SYSCFG0 , &val); +for (i =0 ; i <MTK_MAC_COUNT ; i++) { +if (!eth->mac[i]) +continue ; + val &= ~SYSCFG0_GE_MODE (SYSCFG0_GE_MASK , eth->mac[i]->id); + val |=SYSCFG0_GE_MODE (eth->mac[i]->ge_mode, eth->mac[i]->id); + } +regmap_write (eth->ethsys,ETHSYS_SYSCFG0 , val); +/* Set GE2 driving and slew rate */ regmap_write (eth->pctl,GPIO_DRV_SEL10 ,0xa00 );
@@ -1483,6 +1495,9 @@ static int __init mtk_hw_init(struct mtk_eth *eth)static int mtk_hw_deinit (struct mtk_eth *eth) { +if (!test_and_clear_bit (MTK_HW_INIT , ð->state)) +return 0 ; +clk_disable_unprepare (eth->clks[MTK_CLK_GP2 ]);clk_disable_unprepare (eth->clks[MTK_CLK_GP1 ]);clk_disable_unprepare (eth->clks[MTK_CLK_ESW ]);
@@ -1557,6 +1572,26 @@ static void mtk_pending_work(struct work_struct *work)__set_bit (i, &restart); } +/* restart underlying hardware such as power, clock, pin mux +* and the connected phy +*/ +mtk_hw_deinit (eth); + +if (eth->dev->pins) +pinctrl_select_state (eth->dev->pins->p, + eth->dev->pins->default_state); +mtk_hw_init (eth); + +for (i =0 ; i <MTK_MAC_COUNT ; i++) { +if (!eth->mac[i] || +of_phy_is_fixed_link (eth->mac[i]->of_node)) +continue ; + err =phy_init_hw (eth->mac[i]->phy_dev); +if (err) +dev_err (eth->dev,"%s: PHY init failed.\n" , + eth->netdev[i]->name); + } +/* restart DMA and enable IRQs */ for (i =0 ; i <MTK_MAC_COUNT ; i++) {if (!test_bit (i, &restart))
drivers/net/ethernet/mediatek/mtk_eth_soc.h +8 -0
@@ -330,6 +330,10 @@ enum mtk_clks_map { MTK_CLK_MAX }; +enum mtk_dev_state { +MTK_HW_INIT +}; +/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at * by the TX descriptor s * @skb: The SKB pointer of the packet being sent
@@ -413,6 +417,7 @@ struct mtk_rx_ring {* @clks: clock array for all clocks required * @mii_bus: If there is a bus we need to create an instance for it * @pending_work: The workqueue used to reset the dma ring +* @state Initialization and runtime state of the device. */ struct mtk_eth {
@@ -441,11 +446,13 @@ struct mtk_eth {struct mii_bus *mii_bus;struct work_struct pending_work; +unsigned long state; };/* struct mtk_mac - the structure that holds the info about the MACs of the * SoC * @id: The number of the MAC +* @ge_mode: Interface mode kept for setup restoring * @of_node: Our devicetree node * @hw: Backpointer to our main datastruture * @hw_stats: Packet statistics counter
@@ -453,6 +460,7 @@ struct mtk_eth {*/ struct mtk_mac {int id; +int ge_mode;struct device_node *of_node;struct mtk_eth *hw;struct mtk_hw_stats *hw_stats;
Signature · 1 line
1.9.1
PATCH v2 6/7 net: ethernet: mediatek: add more resets for internal ethernet circuit block
In reply to [email protected]From: Sean Wang <[email protected]>
struct mtk_eth has already contained struct regmap ethsys pointer to the address range of the internal circuit reset, so we reuse it to reset more internal blocks on ethernet hardware such as packet processing engine (PPE) and frame engine (FE) instead of rstc which deals with FE only.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 27 +++++++++++++++------------ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 6 +++++- 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +15 -12
@@ -1414,6 +1414,19 @@ static int mtk_stop(struct net_device *dev)return 0 ; } +static void ethsys_reset (struct mtk_eth *eth,u32 reset_bits) +{ +regmap_update_bits (eth->ethsys,ETHSYS_RSTCTRL , + reset_bits, + reset_bits); + +usleep_range (1000 ,1100 ); +regmap_update_bits (eth->ethsys,ETHSYS_RSTCTRL , + reset_bits, + ~reset_bits); +mdelay (10 ); +} +static int mtk_hw_init (struct mtk_eth *eth) {int i, val;
@@ -1428,12 +1441,8 @@ static int mtk_hw_init(struct mtk_eth *eth)clk_prepare_enable (eth->clks[MTK_CLK_ESW ]);clk_prepare_enable (eth->clks[MTK_CLK_GP1 ]);clk_prepare_enable (eth->clks[MTK_CLK_GP2 ]); - -/* reset the frame engine */ -reset_control_assert (eth->rstc); -usleep_range (10 ,20 ); -reset_control_deassert (eth->rstc); -usleep_range (10 ,20 ); +ethsys_reset (eth,RSTCTRL_FE ); +ethsys_reset (eth,RSTCTRL_PPE );regmap_read (eth->ethsys,ETHSYS_SYSCFG0 , &val);for (i =0 ; i <MTK_MAC_COUNT ; i++) {
@@ -1893,12 +1902,6 @@ static int mtk_probe(struct platform_device *pdev)return PTR_ERR (eth->pctl); } - eth->rstc =devm_reset_control_get (&pdev->dev,"eth" ); -if (IS_ERR (eth->rstc)) { -dev_err (&pdev->dev,"no eth reset found\n" ); -return PTR_ERR (eth->rstc); - } -for (i =0 ; i <3 ; i++) { eth->irq[i] =platform_get_irq (pdev, i);if (eth->irq[i] <0 ) {
drivers/net/ethernet/mediatek/mtk_eth_soc.h +5 -1
@@ -266,6 +266,11 @@#define SYSCFG0_GE_MASK 0x3#define SYSCFG0_GE_MODE (x, y) (x << (12 + (y * 2))) +/*ethernet reset control register*/ +#define ETHSYS_RSTCTRL 0x34 +#define RSTCTRL_FE BIT(6) +#define RSTCTRL_PPE BIT(31) +struct mtk_rx_dma {unsigned int rxd1;unsigned int rxd2;
@@ -423,7 +428,6 @@ struct mtk_rx_ring {struct mtk_eth {struct device *dev;void __iomem *base; -struct reset_control *rstc;spinlock_t page_lock;spinlock_t irq_lock;struct net_device dummy_dev;
Signature · 1 line
1.9.1
PATCH v2 7/7 net: ethernet: mediatek: avoid race condition during the reset process
In reply to [email protected]From: Sean Wang <[email protected]>
add the protection of the race condition between
the reset process and hardware access happening
on the related callbacks.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 36 +++++++++++++++++++++++++++++ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +36 -0
@@ -145,6 +145,9 @@ static void mtk_phy_link_adjust(struct net_device *dev)MAC_MCR_RX_EN |MAC_MCR_BACKOFF_EN |MAC_MCR_BACKPR_EN ; +if (unlikely (test_bit (MTK_RESETTING , &mac->hw->state))) +return ; +switch (mac->phy_dev->speed) {case SPEED_1000 : mcr |=MAC_MCR_SPEED_1000 ;
@@ -370,6 +373,9 @@ static int mtk_set_mac_address(struct net_device *dev, void *p)if (ret)return ret; +if (unlikely (test_bit (MTK_RESETTING , &mac->hw->state))) +return -EBUSY ; +spin_lock_bh (&mac->hw->page_lock);mtk_w32 (mac->hw, (macaddr[0 ] <<8 ) | macaddr[1 ],MTK_GDMA_MAC_ADRH (mac->id));
@@ -770,6 +776,9 @@ static int mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)*/ spin_lock (ð->page_lock); +if (unlikely (test_bit (MTK_RESETTING , ð->state))) + goto drop; + tx_num =mtk_cal_txd_req (skb);if (unlikely (atomic_read (&ring->free_count) <= tx_num)) {mtk_stop_queue (eth);
@@ -842,6 +851,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, netdev = eth->netdev[mac]; +if (unlikely (test_bit (MTK_RESETTING , ð->state))) + goto release_desc; +/* alloc new buffer */ new_data =napi_alloc_frag (ring->frag_size);if (unlikely (!new_data)) {
@@ -1573,6 +1585,12 @@ static void mtk_pending_work(struct work_struct *work)rtnl_lock (); +dev_dbg (eth->dev,"[%s][%d] reset\n" , __func__, __LINE__); + +while (test_and_set_bit_lock (MTK_RESETTING , ð->state)) +cpu_relax (); + +dev_dbg (eth->dev,"[%s][%d] mtk_stop starts\n" , __func__, __LINE__);/* stop all devices to make sure that dma is properly shut down */ for (i =0 ; i <MTK_MAC_COUNT ; i++) {if (!eth->netdev[i])
@@ -1580,6 +1598,7 @@ static void mtk_pending_work(struct work_struct *work)mtk_stop (eth->netdev[i]);__set_bit (i, &restart); } +dev_dbg (eth->dev,"[%s][%d] mtk_stop ends\n" , __func__, __LINE__);/* restart underlying hardware such as power, clock, pin mux * and the connected phy
@@ -1612,6 +1631,11 @@ static void mtk_pending_work(struct work_struct *work)dev_close (eth->netdev[i]); } } + +dev_dbg (eth->dev,"[%s][%d] reset done\n" , __func__, __LINE__); + +clear_bit_unlock (MTK_RESETTING , ð->state); +rtnl_unlock (); }
@@ -1656,6 +1680,9 @@ static int mtk_get_settings(struct net_device *dev,struct mtk_mac *mac =netdev_priv (dev);int err; +if (unlikely (test_bit (MTK_RESETTING , &mac->hw->state))) +return -EBUSY ; + err =phy_read_status (mac->phy_dev);if (err)return -ENODEV ;
@@ -1706,6 +1733,9 @@ static int mtk_nway_reset(struct net_device *dev) {struct mtk_mac *mac =netdev_priv (dev); +if (unlikely (test_bit (MTK_RESETTING , &mac->hw->state))) +return -EBUSY ; +return genphy_restart_aneg (mac->phy_dev); }
@@ -1714,6 +1744,9 @@ static u32 mtk_get_link(struct net_device *dev)struct mtk_mac *mac =netdev_priv (dev);int err; +if (unlikely (test_bit (MTK_RESETTING , &mac->hw->state))) +return -EBUSY ; + err =genphy_update_link (mac->phy_dev);if (err)return ethtool_op_get_link (dev);
@@ -1754,6 +1787,9 @@ static void mtk_get_ethtool_stats(struct net_device *dev,unsigned int start;int i; +if (unlikely (test_bit (MTK_RESETTING , &mac->hw->state))) +return ; +if (netif_running (dev) &&netif_device_present (dev)) {if (spin_trylock (&hwstats->stats_lock)) {mtk_stats_update_mac (mac);
drivers/net/ethernet/mediatek/mtk_eth_soc.h +2 -1
@@ -336,7 +336,8 @@ enum mtk_clks_map { };enum mtk_dev_state { -MTK_HW_INIT +MTK_HW_INIT , +MTK_RESETTING };/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at
Signature · 1 line
1.9.1