net: ethernet: ti: am65-cpsw: Fix set channel operation
Subsystems (2)
v3 cover net: ethernet: ti: am65-cpsw: Fix set channel operation
Hi,
This contains a critical bug fix for the recently merged suspend/resume support [1] that broke set channel operation. (ethtool -L eth0 tx <n>)
As there were 2 dependent patches on top of the offending commit [1] first revert them and then apply them back after the correct fix.
[1] fd23df72f2be ("net: ethernet: ti: am65-cpsw: Add suspend/resume support")
cheers,
-roger
Changelog:
v3:
- revert offending commit before applying the updated patch.
- drop optimization patch to be sent separately.
v2:
- Fix build warning
drivers/net/ethernet/ti/am65-cpsw-nuss.c:562:13: warning: variable 'tmo' set but not used [-Wunused-but-set-variable]
Roger Quadros (6):
Revert "net: ethernet: ti: am65-cpsw: Fix hardware switch mode on
suspend/resume"
Revert "net: ethernet: ti: am65-cpsw: retain PORT_VLAN_REG after
suspend/resume"
Revert "net: ethernet: ti: am65-cpsw: Add suspend/resume support"
net: ethernet: ti: am65-cpsw: Add suspend/resume support
net: ethernet: ti: am65-cpsw: retain PORT_VLAN_REG after
suspend/resume
net: ethernet: ti: am65-cpsw: Fix hardware switch mode on
suspend/resume
drivers/net/ethernet/ti/am65-cpsw-nuss.c | 165 ++++++++++++----------- 1 file changed, 89 insertions(+), 76 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/6 Revert "net: ethernet: ti: am65-cpsw: Fix hardware switch mode on suspend/resume"
This reverts commit 1af3cb3702d02167926a2bd18580cecb2d64fd94.
This is to make it easier to revert the offending commit fd23df72f2be ("net: ethernet: ti: am65-cpsw: Add suspend/resume support")
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 ------- drivers/net/ethernet/ti/am65-cpsw-nuss.h | 2 -- 2 files changed, 9 deletions(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +0 -7
@@ -2714,7 +2714,6 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)struct clk *clk;u64 id_temp;int ret, i; -int ale_entries; common =devm_kzalloc (dev,sizeof (struct am65_cpsw_common ),GFP_KERNEL );if (!common)
@@ -2809,10 +2808,6 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev) goto err_of_clear; } - ale_entries = common->ale->params.ale_entries; - common->ale_context =devm_kzalloc (dev, - ale_entries *ALE_ENTRY_WORDS *sizeof (u32), -GFP_KERNEL ); ret =am65_cpsw_init_cpts (common);if (ret) goto err_of_clear;
@@ -2883,7 +2878,6 @@ static int am65_cpsw_nuss_suspend(struct device *dev)int i, ret;struct am65_cpsw_host *host_p =am65_common_get_host (common); -cpsw_ale_dump (common->ale, common->ale_context); host_p->vid_context =readl (host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );for (i =0 ; i < common->port_num; i++) { port = &common->ports[i];
@@ -2942,7 +2936,6 @@ static int am65_cpsw_nuss_resume(struct device *dev) }writel (host_p->vid_context, host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); -cpsw_ale_restore (common->ale, common->ale_context);return 0 ; }
drivers/net/ethernet/ti/am65-cpsw-nuss.h +0 -2
@@ -149,8 +149,6 @@ struct am65_cpsw_common {struct net_device *hw_bridge_dev;struct notifier_block am65_cpsw_netdevice_nb;unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN ]; -/* only for suspend/resume context restore */ -u32 *ale_context; };struct am65_cpsw_ndev_stats {
Signature · 1 line
2.17.1
PATCH v3 3/6 Revert "net: ethernet: ti: am65-cpsw: Add suspend/resume support"
In reply to Roger QuadrosThis reverts commit fd23df72f2be317d38d9fde0a8996b8e7454fd2a.
This commit broke set channel operation. Revert this and implement it with a different approach in a separate patch.
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 221 ++++++----------------- 1 file changed, 55 insertions(+), 166 deletions(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +55 -166
@@ -24,7 +24,6 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/regmap.h> -#include <linux/rtnetlink.h> #include <linux/mfd/syscon.h> #include <linux/sys_soc.h> #include <linux/dma/ti-cppi5.h>
@@ -133,11 +132,6 @@ NETIF_MSG_IFUP | NETIF_MSG_PROBE | NETIF_MSG_IFDOWN | \ NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) -static int am65_cpsw_nuss_init_tx_chns (struct am65_cpsw_common *common); -static int am65_cpsw_nuss_init_rx_chns (struct am65_cpsw_common *common); -static void am65_cpsw_nuss_free_tx_chns (struct am65_cpsw_common *common); -static void am65_cpsw_nuss_free_rx_chns (struct am65_cpsw_common *common); -static void am65_cpsw_port_set_sl_mac (struct am65_cpsw_port *slave,const u8 *dev_addr) {
@@ -379,20 +373,6 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)if (common->usage_count)return 0 ; -/* init tx/rx channels */ - ret =am65_cpsw_nuss_init_tx_chns (common); -if (ret) { -dev_err (common->dev,"init_tx_chns failed\n" ); -return ret; - } - - ret =am65_cpsw_nuss_init_rx_chns (common); -if (ret) { -dev_err (common->dev,"init_rx_chns failed\n" ); -am65_cpsw_nuss_free_tx_chns (common); -return ret; - } -/* Control register */ writel(AM65_CPSW_CTL_P0_ENABLE | AM65_CPSW_CTL_P0_TX_CRC_REMOVE | AM65_CPSW_CTL_VLAN_AWARE | AM65_CPSW_CTL_P0_RX_PAD,
@@ -421,7 +401,6 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)/* disable priority elevation */ writel (0 , common->cpsw_base +AM65_CPSW_REG_PTYPE ); -cpsw_ale_control_set (common->ale,0 ,ALE_CLEAR ,1 );cpsw_ale_start (common->ale);/* limit to one RX flow only */
@@ -453,8 +432,7 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common) GFP_KERNEL);if (!skb) {dev_err (common->dev,"cannot allocate skb\n" ); - ret = -ENOMEM ; - goto err; +return -ENOMEM ; } ret =am65_cpsw_nuss_rx_push (common, skb);
@@ -463,7 +441,7 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)"cannot submit skb to channel rx, error %d\n" , ret);kfree_skb (skb); - goto err; +return ret; }kmemleak_not_leak (skb); }
@@ -472,7 +450,7 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)for (i =0 ; i < common->tx_ch_num; i++) { ret =k3_udma_glue_enable_tx_chn (common->tx_chns[i].tx_chn);if (ret) - goto err; +return ret;napi_enable (&common->tx_chns[i].napi_tx); }
@@ -484,12 +462,6 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)dev_dbg (common->dev,"cpsw_nuss started\n" );return 0 ; - -err: -am65_cpsw_nuss_free_tx_chns (common); -am65_cpsw_nuss_free_rx_chns (common); - -return ret; }static void am65_cpsw_nuss_tx_cleanup (void *data,dma_addr_t desc_dma);
@@ -543,9 +515,6 @@ static int am65_cpsw_nuss_common_stop(struct am65_cpsw_common *common)writel (0 , common->cpsw_base +AM65_CPSW_REG_CTL );writel (0 , common->cpsw_base +AM65_CPSW_REG_STAT_PORT_EN ); -am65_cpsw_nuss_free_tx_chns (common); -am65_cpsw_nuss_free_rx_chns (common); -dev_dbg (common->dev,"cpsw_nuss stopped\n" );return 0 ; }
@@ -586,29 +555,11 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)struct am65_cpsw_common *common =am65_ndev_to_common (ndev);struct am65_cpsw_port *port =am65_ndev_to_port (ndev);int ret, i; -u32 reg; -int tmo; ret =pm_runtime_resume_and_get (common->dev);if (ret <0 )return ret; -/* Idle MAC port */ -cpsw_sl_ctl_set (port->slave.mac_sl,CPSW_SL_CTL_CMD_IDLE ); - - tmo =cpsw_sl_wait_for_idle (port->slave.mac_sl,100 ); -dev_info (common->dev,"down msc_sl %08x tmo %d\n" , -cpsw_sl_reg_read (port->slave.mac_sl,CPSW_SL_MACSTATUS ), tmo); - -cpsw_sl_ctl_reset (port->slave.mac_sl); - -/* soft reset MAC */ -cpsw_sl_reg_write (port->slave.mac_sl,CPSW_SL_SOFT_RESET ,1 ); -mdelay (1 ); - reg =cpsw_sl_reg_read (port->slave.mac_sl,CPSW_SL_SOFT_RESET ); -if (reg) -dev_info (common->dev,"mac reset not yet done\n" ); -/* Notify the stack of the actual queue counts. */ ret =netif_set_real_num_tx_queues (ndev, common->tx_ch_num);if (ret) {
@@ -1539,9 +1490,9 @@ static void am65_cpsw_nuss_slave_disable_unused(struct am65_cpsw_port *port)cpsw_sl_ctl_reset (port->slave.mac_sl); } -static void am65_cpsw_nuss_free_tx_chns (struct am65_cpsw_common *common) +static void am65_cpsw_nuss_free_tx_chns (void *data) { -struct device *dev = common->dev; +struct am65_cpsw_common *common = data;int i;for (i =0 ; i < common->tx_ch_num; i++) {
@@ -1553,11 +1504,7 @@ static void am65_cpsw_nuss_free_tx_chns(struct am65_cpsw_common *common)if (!IS_ERR_OR_NULL (tx_chn->tx_chn))k3_udma_glue_release_tx_chn (tx_chn->tx_chn); -/* Don't clear tx_chn memory as we need to preserve -* data between suspend/resume -*/ -if (!(tx_chn->irq <0 )) -devm_free_irq (dev, tx_chn->irq, tx_chn); +memset (tx_chn,0 ,sizeof (*tx_chn)); } }
@@ -1566,10 +1513,12 @@ void am65_cpsw_nuss_remove_tx_chns(struct am65_cpsw_common *common)struct device *dev = common->dev;int i; +devm_remove_action (dev, am65_cpsw_nuss_free_tx_chns, common); +for (i =0 ; i < common->tx_ch_num; i++) {struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; -if (!(tx_chn->irq <0 )) +if (tx_chn->irq)devm_free_irq (dev, tx_chn->irq, tx_chn);netif_napi_del (&tx_chn->napi_tx);
@@ -1639,7 +1588,7 @@ static int am65_cpsw_nuss_init_tx_chns(struct am65_cpsw_common *common) } tx_chn->irq =k3_udma_glue_tx_get_irq (tx_chn->tx_chn); -if (tx_chn->irq <0 ) { +if (tx_chn->irq <=0 ) {dev_err (dev,"Failed to get tx dma irq %d\n" , tx_chn->irq); goto err;
@@ -1648,36 +1597,25 @@ static int am65_cpsw_nuss_init_tx_chns(struct am65_cpsw_common *common)snprintf (tx_chn->tx_chn_name,sizeof (tx_chn->tx_chn_name),"%s-tx%d" ,dev_name (dev), tx_chn->id); - - ret =devm_request_irq (dev, tx_chn->irq, - am65_cpsw_nuss_tx_irq, -IRQF_TRIGGER_HIGH , - tx_chn->tx_chn_name, tx_chn); -if (ret) { -dev_err (dev,"failure requesting tx%u irq %u, %d\n" , - tx_chn->id, tx_chn->irq, ret); - tx_chn->irq = -EINVAL ; - goto err; - } } -return 0 ; - err: -am65_cpsw_nuss_free_tx_chns (common); + i =devm_add_action (dev, am65_cpsw_nuss_free_tx_chns, common); +if (i) { +dev_err (dev,"Failed to add free_tx_chns action %d\n" , i); +return i; + }return ret; } -static void am65_cpsw_nuss_free_rx_chns (struct am65_cpsw_common *common) +static void am65_cpsw_nuss_free_rx_chns (void *data) { +struct am65_cpsw_common *common = data;struct am65_cpsw_rx_chn *rx_chn; rx_chn = &common->rx_chns; -if (!(rx_chn->irq <0 )) -devm_free_irq (common->dev, rx_chn->irq, common); -if (!IS_ERR_OR_NULL (rx_chn->desc_pool))k3_cppi_desc_pool_destroy (rx_chn->desc_pool);
@@ -1700,7 +1638,7 @@ static int am65_cpsw_nuss_init_rx_chns(struct am65_cpsw_common *common) rx_cfg.swdata_size =AM65_CPSW_NAV_SW_DATA_SIZE ; rx_cfg.flow_id_num =AM65_CPSW_MAX_RX_FLOWS ; - rx_cfg.flow_id_base =-1 ; + rx_cfg.flow_id_base = common->rx_flow_id_base;/* init all flows */ rx_chn->dev = dev;
@@ -1772,20 +1710,12 @@ static int am65_cpsw_nuss_init_rx_chns(struct am65_cpsw_common *common) } } - ret =devm_request_irq (dev, rx_chn->irq, - am65_cpsw_nuss_rx_irq, -IRQF_TRIGGER_HIGH ,dev_name (dev), common); -if (ret) { -dev_err (dev,"failure requesting rx irq %u, %d\n" , - rx_chn->irq, ret); - rx_chn->irq = -EINVAL ; - goto err; - } - -return 0 ; - err: -am65_cpsw_nuss_free_rx_chns (common); + i =devm_add_action (dev, am65_cpsw_nuss_free_rx_chns, common); +if (i) { +dev_err (dev,"Failed to add free_rx_chns action %d\n" , i); +return i; + }return ret; }
@@ -2051,7 +1981,6 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx) port->slave.phylink_config.dev = &port->ndev->dev; port->slave.phylink_config.type =PHYLINK_NETDEV ; port->slave.phylink_config.mac_capabilities =MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000FD ; - port->slave.phylink_config.mac_managed_pm = true;/* MAC does PM */ if (phy_interface_mode_is_rgmii (port->slave.phy_if)) {phy_interface_set_rgmii (port->slave.phylink_config.supported_interfaces);
@@ -2113,16 +2042,28 @@ static int am65_cpsw_nuss_init_ndevs(struct am65_cpsw_common *common)static int am65_cpsw_nuss_ndev_add_tx_napi (struct am65_cpsw_common *common) { -int i; +struct device *dev = common->dev; +int i, ret =0 ;for (i =0 ; i < common->tx_ch_num; i++) {struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i];netif_napi_add_tx (common->dma_ndev, &tx_chn->napi_tx, am65_cpsw_nuss_tx_poll); + + ret =devm_request_irq (dev, tx_chn->irq, + am65_cpsw_nuss_tx_irq, +IRQF_TRIGGER_HIGH , + tx_chn->tx_chn_name, tx_chn); +if (ret) { +dev_err (dev,"failure requesting tx%u irq %u, %d\n" , + tx_chn->id, tx_chn->irq, ret); + goto err; + } } -return 0 ; +err: +return ret; }static void am65_cpsw_nuss_cleanup_ndev (struct am65_cpsw_common *common)
@@ -2591,6 +2532,15 @@ static int am65_cpsw_nuss_register_ndevs(struct am65_cpsw_common *common)if (ret)return ret; + ret =devm_request_irq (dev, common->rx_chns.irq, + am65_cpsw_nuss_rx_irq, +IRQF_TRIGGER_HIGH ,dev_name (dev), common); +if (ret) { +dev_err (dev,"failure requesting rx irq %u, %d\n" , + common->rx_chns.irq, ret); +return ret; + } + ret =am65_cpsw_nuss_register_devlink (common);if (ret)return ret;
@@ -2744,6 +2694,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)if (common->port_num <1 || common->port_num >AM65_CPSW_MAX_PORTS )return -ENOENT ; + common->rx_flow_id_base =-1 ;init_completion (&common->tdown_complete); common->tx_ch_num =1 ; common->pf_p0_rx_ptype_rrobin = false;
@@ -2785,6 +2736,14 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)am65_cpsw_nuss_get_ver (common); +/* init tx channels */ + ret =am65_cpsw_nuss_init_tx_chns (common); +if (ret) + goto err_of_clear; + ret =am65_cpsw_nuss_init_rx_chns (common); +if (ret) + goto err_of_clear; + ret =am65_cpsw_nuss_init_host_p (common);if (ret) goto err_of_clear;
@@ -2869,80 +2828,10 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev)return 0 ; } -#ifdef CONFIG_PM_SLEEP -static int am65_cpsw_nuss_suspend (struct device *dev) -{ -struct am65_cpsw_common *common =dev_get_drvdata (dev); -struct am65_cpsw_port *port; -struct net_device *ndev; -int i, ret; - -for (i =0 ; i < common->port_num; i++) { - port = &common->ports[i]; - ndev = port->ndev; - -if (!ndev) -continue ; - -netif_device_detach (ndev); -if (netif_running (ndev)) { -rtnl_lock (); - ret =am65_cpsw_nuss_ndo_slave_stop (ndev); -rtnl_unlock (); -if (ret <0 ) { -netdev_err (ndev,"failed to stop: %d" , ret); -return ret; - } - } - } - -am65_cpts_suspend (common->cpts); - -return 0 ; -} - -static int am65_cpsw_nuss_resume (struct device *dev) -{ -struct am65_cpsw_common *common =dev_get_drvdata (dev); -struct am65_cpsw_port *port; -struct net_device *ndev; -int i, ret; - -am65_cpts_resume (common->cpts); - -for (i =0 ; i < common->port_num; i++) { - port = &common->ports[i]; - ndev = port->ndev; - -if (!ndev) -continue ; - -if (netif_running (ndev)) { -rtnl_lock (); - ret =am65_cpsw_nuss_ndo_slave_open (ndev); -rtnl_unlock (); -if (ret <0 ) { -netdev_err (ndev,"failed to start: %d" , ret); -return ret; - } - } - -netif_device_attach (ndev); - } - -return 0 ; -} -#endif /* CONFIG_PM_SLEEP */ - -static const struct dev_pm_ops am65_cpsw_nuss_dev_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (am65_cpsw_nuss_suspend, am65_cpsw_nuss_resume) -}; -static struct platform_driver am65_cpsw_nuss_driver = { .driver = { .name =AM65_CPSW_DRV_NAME , .of_match_table = am65_cpsw_nuss_of_mtable, - .pm = &am65_cpsw_nuss_dev_pm_ops, }, .probe = am65_cpsw_nuss_probe, .remove = am65_cpsw_nuss_remove,
Signature · 1 line
2.17.1
PATCH v3 2/6 Revert "net: ethernet: ti: am65-cpsw: retain PORT_VLAN_REG after suspend/resume"
In reply to Roger QuadrosThis reverts commit 643cf0e3ab5ccee37b3c53c018bd476c45c4b70e.
This is to make it easier to revert the offending commit fd23df72f2be ("net: ethernet: ti: am65-cpsw: Add suspend/resume support")
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 ------- drivers/net/ethernet/ti/am65-cpsw-nuss.h | 4 ---- 2 files changed, 11 deletions(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +0 -7
@@ -2876,9 +2876,7 @@ static int am65_cpsw_nuss_suspend(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; -struct am65_cpsw_host *host_p =am65_common_get_host (common); - host_p->vid_context =readl (host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );for (i =0 ; i < common->port_num; i++) { port = &common->ports[i]; ndev = port->ndev;
@@ -2886,7 +2884,6 @@ static int am65_cpsw_nuss_suspend(struct device *dev)if (!ndev)continue ; - port->vid_context =readl (port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );netif_device_detach (ndev);if (netif_running (ndev)) {rtnl_lock ();
@@ -2910,7 +2907,6 @@ static int am65_cpsw_nuss_resume(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; -struct am65_cpsw_host *host_p =am65_common_get_host (common);am65_cpts_resume (common->cpts);
@@ -2932,11 +2928,8 @@ static int am65_cpsw_nuss_resume(struct device *dev) }netif_device_attach (ndev); -writel (port->vid_context, port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); } -writel (host_p->vid_context, host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); -return 0 ; }#endif /* CONFIG_PM_SLEEP */
drivers/net/ethernet/ti/am65-cpsw-nuss.h +0 -4
@@ -55,16 +55,12 @@ struct am65_cpsw_port {bool rx_ts_enabled;struct am65_cpsw_qos qos;struct devlink_port devlink_port; -/* Only for suspend resume context */ -u32 vid_context; };struct am65_cpsw_host {struct am65_cpsw_common *common;void __iomem *port_base;void __iomem *stat_base; -/* Only for suspend resume context */ -u32 vid_context; };struct am65_cpsw_tx_chn {
Signature · 1 line
2.17.1
PATCH v3 4/6 net: ethernet: ti: am65-cpsw: Add suspend/resume support
In reply to Roger QuadrosAdd PM handlers for System suspend/resume.
As DMA driver doesn't yet support suspend/resume we free up the DMA channels at suspend and acquire and initialize them at resume.
In this revised approach we do not free the TX/RX IRQs at am65_cpsw_nuss_common_stop() as it causes problems. We will now free them only on .suspend() as we need to release the DMA channels (as DMA looses context) and re-acquiring them on .resume() may not necessarily give us the same IRQs.
To make this easier:
- introduce am65_cpsw_nuss_remove_rx_chns() which is similar to am65_cpsw_nuss_remove_tx_chns(). These will be invoked in pm.suspend() to release the DMA channels and free up the IRQs.
- move napi_add() and request_irq() calls to am65_cpsw_nuss_init_rx/tx_chns() so we can invoke them in pm.resume() to acquire the DMA channels and IRQs.
As CPTS looses contect during suspend/resume, invoke the necessary CPTS suspend/resume helpers.
ALE_CLEAR command is issued in cpsw_ale_start() so no need to issue it before the call to cpsw_ale_start().
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 170 ++++++++++++++++++++--- 1 file changed, 147 insertions(+), 23 deletions(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +147 -23
@@ -24,6 +24,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/regmap.h> +#include <linux/rtnetlink.h> #include <linux/mfd/syscon.h> #include <linux/sys_soc.h> #include <linux/dma/ti-cppi5.h>
@@ -132,6 +133,8 @@ NETIF_MSG_IFUP | NETIF_MSG_PROBE | NETIF_MSG_IFDOWN | \ NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) +static int am65_cpsw_nuss_ndev_add_tx_napi (struct am65_cpsw_common *common); +static void am65_cpsw_port_set_sl_mac (struct am65_cpsw_port *slave,const u8 *dev_addr) {
@@ -555,11 +558,24 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)struct am65_cpsw_common *common =am65_ndev_to_common (ndev);struct am65_cpsw_port *port =am65_ndev_to_port (ndev);int ret, i; +u32 reg; ret =pm_runtime_resume_and_get (common->dev);if (ret <0 )return ret; +/* Idle MAC port */ +cpsw_sl_ctl_set (port->slave.mac_sl,CPSW_SL_CTL_CMD_IDLE ); +cpsw_sl_wait_for_idle (port->slave.mac_sl,100 ); +cpsw_sl_ctl_reset (port->slave.mac_sl); + +/* soft reset MAC */ +cpsw_sl_reg_write (port->slave.mac_sl,CPSW_SL_SOFT_RESET ,1 ); +mdelay (1 ); + reg =cpsw_sl_reg_read (port->slave.mac_sl,CPSW_SL_SOFT_RESET ); +if (reg) +dev_info (common->dev,"mac reset not yet done\n" ); +/* Notify the stack of the actual queue counts. */ ret =netif_set_real_num_tx_queues (ndev, common->tx_ch_num);if (ret) {
@@ -1599,6 +1615,12 @@ static int am65_cpsw_nuss_init_tx_chns(struct am65_cpsw_common *common) dev_name(dev), tx_chn->id); } + ret =am65_cpsw_nuss_ndev_add_tx_napi (common); +if (ret) { +dev_err (dev,"Failed to add tx NAPI %d\n" , ret); + goto err; + } + err: i =devm_add_action (dev, am65_cpsw_nuss_free_tx_chns, common);if (i) {
@@ -1623,6 +1645,29 @@ static void am65_cpsw_nuss_free_rx_chns(void *data)k3_udma_glue_release_rx_chn (rx_chn->rx_chn); } +static void am65_cpsw_nuss_remove_rx_chns (void *data) +{ +struct am65_cpsw_common *common = data; +struct am65_cpsw_rx_chn *rx_chn; +struct device *dev = common->dev; + + rx_chn = &common->rx_chns; +devm_remove_action (dev, am65_cpsw_nuss_free_rx_chns, common); + +if (!(rx_chn->irq <0 )) +devm_free_irq (dev, rx_chn->irq, common); + +netif_napi_del (&common->napi_rx); + +if (!IS_ERR_OR_NULL (rx_chn->desc_pool)) +k3_cppi_desc_pool_destroy (rx_chn->desc_pool); + +if (!IS_ERR_OR_NULL (rx_chn->rx_chn)) +k3_udma_glue_release_rx_chn (rx_chn->rx_chn); + + common->rx_flow_id_base =-1 ; +} +static int am65_cpsw_nuss_init_rx_chns (struct am65_cpsw_common *common) {struct am65_cpsw_rx_chn *rx_chn = &common->rx_chns;
@@ -1710,6 +1755,18 @@ static int am65_cpsw_nuss_init_rx_chns(struct am65_cpsw_common *common) } } +netif_napi_add (common->dma_ndev, &common->napi_rx, + am65_cpsw_nuss_rx_poll); + + ret =devm_request_irq (dev, rx_chn->irq, + am65_cpsw_nuss_rx_irq, +IRQF_TRIGGER_HIGH ,dev_name (dev), common); +if (ret) { +dev_err (dev,"failure requesting rx irq %u, %d\n" , + rx_chn->irq, ret); + goto err; + } + err: i =devm_add_action (dev, am65_cpsw_nuss_free_rx_chns, common);if (i) {
@@ -1981,6 +2038,7 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx) port->slave.phylink_config.dev = &port->ndev->dev; port->slave.phylink_config.type =PHYLINK_NETDEV ; port->slave.phylink_config.mac_capabilities =MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000FD ; + port->slave.phylink_config.mac_managed_pm = true;/* MAC does PM */ if (phy_interface_mode_is_rgmii (port->slave.phy_if)) {phy_interface_set_rgmii (port->slave.phylink_config.supported_interfaces);
@@ -2034,9 +2092,6 @@ static int am65_cpsw_nuss_init_ndevs(struct am65_cpsw_common *common)return ret; } -netif_napi_add (common->dma_ndev, &common->napi_rx, - am65_cpsw_nuss_rx_poll); -return ret; }
@@ -2528,18 +2583,13 @@ static int am65_cpsw_nuss_register_ndevs(struct am65_cpsw_common *common)struct am65_cpsw_port *port;int ret =0 , i; - ret =am65_cpsw_nuss_ndev_add_tx_napi (common); +/* init tx channels */ + ret =am65_cpsw_nuss_init_tx_chns (common);if (ret)return ret; - - ret =devm_request_irq (dev, common->rx_chns.irq, - am65_cpsw_nuss_rx_irq, -IRQF_TRIGGER_HIGH ,dev_name (dev), common); -if (ret) { -dev_err (dev,"failure requesting rx irq %u, %d\n" , - common->rx_chns.irq, ret); + ret =am65_cpsw_nuss_init_rx_chns (common); +if (ret)return ret; - } ret =am65_cpsw_nuss_register_devlink (common);if (ret)
@@ -2584,10 +2634,8 @@ int am65_cpsw_nuss_update_tx_chns(struct am65_cpsw_common *common, int num_tx) common->tx_ch_num = num_tx; ret =am65_cpsw_nuss_init_tx_chns (common); -if (ret) -return ret; -return am65_cpsw_nuss_ndev_add_tx_napi (common); +return ret; }struct am65_cpsw_soc_pdata {
@@ -2736,14 +2784,6 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)am65_cpsw_nuss_get_ver (common); -/* init tx channels */ - ret =am65_cpsw_nuss_init_tx_chns (common); -if (ret) - goto err_of_clear; - ret =am65_cpsw_nuss_init_rx_chns (common); -if (ret) - goto err_of_clear; - ret =am65_cpsw_nuss_init_host_p (common);if (ret) goto err_of_clear;
@@ -2828,10 +2868,94 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev)return 0 ; } +#ifdef CONFIG_PM_SLEEP +static int am65_cpsw_nuss_suspend (struct device *dev) +{ +struct am65_cpsw_common *common =dev_get_drvdata (dev); +struct am65_cpsw_port *port; +struct net_device *ndev; +int i, ret; + +for (i =0 ; i < common->port_num; i++) { + port = &common->ports[i]; + ndev = port->ndev; + +if (!ndev) +continue ; + +netif_device_detach (ndev); +if (netif_running (ndev)) { +rtnl_lock (); + ret =am65_cpsw_nuss_ndo_slave_stop (ndev); +rtnl_unlock (); +if (ret <0 ) { +netdev_err (ndev,"failed to stop: %d" , ret); +return ret; + } + } + } + +am65_cpts_suspend (common->cpts); + +am65_cpsw_nuss_remove_rx_chns (common); +am65_cpsw_nuss_remove_tx_chns (common); + +return 0 ; +} + +static int am65_cpsw_nuss_resume (struct device *dev) +{ +struct am65_cpsw_common *common =dev_get_drvdata (dev); +struct am65_cpsw_port *port; +struct net_device *ndev; +int i, ret; + + ret =am65_cpsw_nuss_init_tx_chns (common); +if (ret) +return ret; + ret =am65_cpsw_nuss_init_rx_chns (common); +if (ret) +return ret; + +/* If RX IRQ was disabled before suspend, keep it disabled */ +if (common->rx_irq_disabled) +disable_irq (common->rx_chns.irq); + +am65_cpts_resume (common->cpts); + +for (i =0 ; i < common->port_num; i++) { + port = &common->ports[i]; + ndev = port->ndev; + +if (!ndev) +continue ; + +if (netif_running (ndev)) { +rtnl_lock (); + ret =am65_cpsw_nuss_ndo_slave_open (ndev); +rtnl_unlock (); +if (ret <0 ) { +netdev_err (ndev,"failed to start: %d" , ret); +return ret; + } + } + +netif_device_attach (ndev); + } + +return 0 ; +} +#endif /* CONFIG_PM_SLEEP */ + +static const struct dev_pm_ops am65_cpsw_nuss_dev_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (am65_cpsw_nuss_suspend, am65_cpsw_nuss_resume) +}; +static struct platform_driver am65_cpsw_nuss_driver = { .driver = { .name =AM65_CPSW_DRV_NAME , .of_match_table = am65_cpsw_nuss_of_mtable, + .pm = &am65_cpsw_nuss_dev_pm_ops, }, .probe = am65_cpsw_nuss_probe, .remove = am65_cpsw_nuss_remove,
Signature · 1 line
2.17.1
PATCH v3 5/6 net: ethernet: ti: am65-cpsw: retain PORT_VLAN_REG after suspend/resume
In reply to Roger QuadrosDuring suspend resume the context of PORT_VLAN_REG is lost so save it during suspend and restore it during resume for host port and slave ports.
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.h | 4 ++++ 2 files changed, 11 insertions(+)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +7 -0
@@ -2875,7 +2875,9 @@ static int am65_cpsw_nuss_suspend(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common); + host_p->vid_context =readl (host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );for (i =0 ; i < common->port_num; i++) { port = &common->ports[i]; ndev = port->ndev;
@@ -2883,6 +2885,7 @@ static int am65_cpsw_nuss_suspend(struct device *dev)if (!ndev)continue ; + port->vid_context =readl (port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );netif_device_detach (ndev);if (netif_running (ndev)) {rtnl_lock ();
@@ -2909,6 +2912,7 @@ static int am65_cpsw_nuss_resume(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common); ret =am65_cpsw_nuss_init_tx_chns (common);if (ret)
@@ -2941,8 +2945,11 @@ static int am65_cpsw_nuss_resume(struct device *dev) }netif_device_attach (ndev); +writel (port->vid_context, port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); } +writel (host_p->vid_context, host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); +return 0 ; }#endif /* CONFIG_PM_SLEEP */
drivers/net/ethernet/ti/am65-cpsw-nuss.h +4 -0
@@ -55,12 +55,16 @@ struct am65_cpsw_port {bool rx_ts_enabled;struct am65_cpsw_qos qos;struct devlink_port devlink_port; +/* Only for suspend resume context */ +u32 vid_context; };struct am65_cpsw_host {struct am65_cpsw_common *common;void __iomem *port_base;void __iomem *stat_base; +/* Only for suspend resume context */ +u32 vid_context; };struct am65_cpsw_tx_chn {
Signature · 1 line
2.17.1
PATCH v3 6/6 net: ethernet: ti: am65-cpsw: Fix hardware switch mode on suspend/resume
In reply to Roger QuadrosOn low power during system suspend the ALE table context is lost. Save the ALE context before suspend and restore it after resume.
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.h | 2 ++ 2 files changed, 9 insertions(+)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +7 -0
@@ -2712,6 +2712,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)struct clk *clk;u64 id_temp;int ret, i; +int ale_entries; common =devm_kzalloc (dev,sizeof (struct am65_cpsw_common ),GFP_KERNEL );if (!common)
@@ -2807,6 +2808,10 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev) goto err_of_clear; } + ale_entries = common->ale->params.ale_entries; + common->ale_context =devm_kzalloc (dev, + ale_entries *ALE_ENTRY_WORDS *sizeof (u32), +GFP_KERNEL ); ret =am65_cpsw_init_cpts (common);if (ret) goto err_of_clear;
@@ -2877,6 +2882,7 @@ static int am65_cpsw_nuss_suspend(struct device *dev)int i, ret;struct am65_cpsw_host *host_p =am65_common_get_host (common); +cpsw_ale_dump (common->ale, common->ale_context); host_p->vid_context =readl (host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );for (i =0 ; i < common->port_num; i++) { port = &common->ports[i];
@@ -2949,6 +2955,7 @@ static int am65_cpsw_nuss_resume(struct device *dev) }writel (host_p->vid_context, host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); +cpsw_ale_restore (common->ale, common->ale_context);return 0 ; }
drivers/net/ethernet/ti/am65-cpsw-nuss.h +2 -0
@@ -149,6 +149,8 @@ struct am65_cpsw_common {struct net_device *hw_bridge_dev;struct notifier_block am65_cpsw_netdevice_nb;unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN ]; +/* only for suspend/resume context restore */ +u32 *ale_context; };struct am65_cpsw_ndev_stats {
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 4/6] net: ethernet: ti: am65-cpsw: Add suspend/resume support
In reply to Roger Quadrosdrivers/net/ethernet/ti/am65-cpsw-nuss.c line 137
Quoted 2 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +2
-0+static int am65_cpsw_nuss_ndev_add_tx_napi (struct am65_cpsw_common *common); +
Please move the code around so you don't need this. Ideally as a patch which only does the move. It is then trivial to review.
Quoted 14 lines
static void am65_cpsw_port_set_sl_mac(struct
am65_cpsw_port*slave,drivers/net/ethernet/ti/am65-cpsw-nuss.c +2
-0const u8 *dev_addr) {@@ -555,11 +558,24 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)struct am65_cpsw_common *common =am65_ndev_to_common (ndev);struct am65_cpsw_port *port =am65_ndev_to_port (ndev);int ret, i; +u32 reg; ret =pm_runtime_resume_and_get (common->dev);if (ret <0 )return ret; +/* Idle MAC port */
drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev) · line 577
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +10
-0+cpsw_sl_ctl_set (port->slave.mac_sl,CPSW_SL_CTL_CMD_IDLE ); +cpsw_sl_wait_for_idle (port->slave.mac_sl,100 ); +cpsw_sl_ctl_reset (port->slave.mac_sl); + +/* soft reset MAC */ +cpsw_sl_reg_write (port->slave.mac_sl,CPSW_SL_SOFT_RESET ,1 ); +mdelay (1 ); + reg =cpsw_sl_reg_read (port->slave.mac_sl,CPSW_SL_SOFT_RESET ); +if (reg) +dev_info (common->dev,"mac reset not yet done\n" );
Should that be dev_info()? dev_dbg()
Andrew
Re: [PATCH v3 net-next 4/6] net: ethernet: ti: am65-cpsw: Add suspend/resume support
Quoted 5 lines · Andrew Lunn
drivers/net/ethernet/ti/am65-cpsw-nuss.c line 137
Quoted 2 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +2
-0+static int am65_cpsw_nuss_ndev_add_tx_napi (struct am65_cpsw_common *common); +Please move the code around so you don't need this. Ideally as a patch which only does the move. It is then trivial to review.
OK.
Quoted 14 lines
Quoted 14 lines
static void am65_cpsw_port_set_sl_mac(struct
am65_cpsw_port*slave,drivers/net/ethernet/ti/am65-cpsw-nuss.c +1
-0const u8 *dev_addr) {@@ -555,11 +558,24 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)struct am65_cpsw_common *common =am65_ndev_to_common (ndev);struct am65_cpsw_port *port =am65_ndev_to_port (ndev);int ret, i; +u32 reg; ret =pm_runtime_resume_and_get (common->dev);if (ret <0 )return ret;
Quoted 13 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev) · line 577
Quoted 11 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +11
-0+/* Idle MAC port */ +cpsw_sl_ctl_set (port->slave.mac_sl,CPSW_SL_CTL_CMD_IDLE ); +cpsw_sl_wait_for_idle (port->slave.mac_sl,100 ); +cpsw_sl_ctl_reset (port->slave.mac_sl); + +/* soft reset MAC */ +cpsw_sl_reg_write (port->slave.mac_sl,CPSW_SL_SOFT_RESET ,1 ); +mdelay (1 ); + reg =cpsw_sl_reg_read (port->slave.mac_sl,CPSW_SL_SOFT_RESET ); +if (reg) +dev_info (common->dev,"mac reset not yet done\n" );Should that be
dev_info()?dev_dbg()
Do you think we should error out here as this might indicate some hardware malfunction and it is unlikely to work?
In that case dev_err() seems more appropriate?
Quoted 2 lines
Andrew
cheers,
-roger
Re: [PATCH v3 net-next 5/6] net: ethernet: ti: am65-cpsw: retain PORT_VLAN_REG after suspend/resume
In reply to Roger QuadrosQuoted 16 lines · Roger Quadros
During suspend resume the context of
PORT_VLAN_REGis lost so save it during suspend and restore it during resume for host port and slave ports.Signed-off-by Roger Quadros <[email protected]>Signed-off-by David S. Miller <[email protected]>--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.h | 4 ++++ 2 files changed, 11 insertions(+)drivers/net/ethernet/ti/am65-cpsw-nuss.c +0
-0
drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_nuss_suspend(struct device *dev) · line 2878
Quoted 4 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +1
-0@@ -2875,7 +2875,9 @@ static int am65_cpsw_nuss_suspend(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common);
Nit: I see that retrieving host pointer depends on getting the common pointer first from dev_get_drvdata(dev) so pure RCT is not possible to maintain here but nonetheless I would move this line just below the common pointer:
struct am65_cpsw_common *common = dev_get_drvdata(dev); struct am65_cpsw_host *host = am65_common_get_host(common); struct am65_cpsw_port *port; struct net_device *ndev; int i, ret;
Also I think plain 'host' for variable name is just fine, no need for _p suffix to indicate it is a pointer. in that case you should go with common_p etc.
Quoted 57 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +6
-0+ host_p->vid_context =readl (host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );for (i =0 ; i < common->port_num; i++) { port = &common->ports[i]; ndev = port->ndev;@@ -2883,6 +2885,7 @@ static int am65_cpsw_nuss_suspend(struct device *dev)if (!ndev)continue ; + port->vid_context =readl (port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );netif_device_detach (ndev);if (netif_running (ndev)) {rtnl_lock ();@@ -2909,6 +2912,7 @@ static int am65_cpsw_nuss_resume(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common); ret =am65_cpsw_nuss_init_tx_chns (common);if (ret)@@ -2941,8 +2945,11 @@ static int am65_cpsw_nuss_resume(struct device *dev) }netif_device_attach (ndev); +writel (port->vid_context, port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); } +writel (host_p->vid_context, host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); +return 0 ; }#endif /* CONFIG_PM_SLEEP */ drivers/net/ethernet/ti/am65-cpsw-nuss.h +4
-0@@ -55,12 +55,16 @@ struct am65_cpsw_port {bool rx_ts_enabled;struct am65_cpsw_qos qos;struct devlink_port devlink_port; +/* Only for suspend resume context */ +u32 vid_context; };struct am65_cpsw_host {struct am65_cpsw_common *common;void __iomem *port_base;void __iomem *stat_base; +/* Only for suspend resume context */ +u32 vid_context; };struct am65_cpsw_tx_chn {Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 5/6] net: ethernet: ti: am65-cpsw: retain PORT_VLAN_REG after suspend/resume
Quoted 27 lines · Maciej Fijalkowski
Quoted 16 lines · Roger Quadros
During suspend resume the context of
PORT_VLAN_REGis lost so save it during suspend and restore it during resume for host port and slave ports.Signed-off-by Roger Quadros <[email protected]>Signed-off-by David S. Miller <[email protected]>--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.h | 4 ++++ 2 files changed, 11 insertions(+)drivers/net/ethernet/ti/am65-cpsw-nuss.c +0
-0drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_nuss_suspend(struct device *dev) · line 2878
Quoted 4 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +1
-0@@ -2875,7 +2875,9 @@ static int am65_cpsw_nuss_suspend(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common);Nit: I see that retrieving host pointer depends on getting the common pointer first from
dev_get_drvdata(dev)so pure RCT is not possible to maintain here but nonetheless I would move this line just below the common pointer:
Quoted 5 lines
struct am65_cpsw_common *common = dev_get_drvdata(dev); struct am65_cpsw_host *host = am65_common_get_host(common); struct am65_cpsw_port *port; struct net_device *ndev; int i, ret;
OK.
Quoted 4 lines
Also I think plain 'host' for variable name is just fine, no need for _p suffix to indicate it is a pointer. in that case you should go with
common_petc.
host_p is the naming convention used throughout the driver. Do think it is a good idea to change it at this one place?
Quoted 54 lines
Quoted 54 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +6
-0+ host_p->vid_context =readl (host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );for (i =0 ; i < common->port_num; i++) { port = &common->ports[i]; ndev = port->ndev;@@ -2883,6 +2885,7 @@ static int am65_cpsw_nuss_suspend(struct device *dev)if (!ndev)continue ; + port->vid_context =readl (port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );netif_device_detach (ndev);if (netif_running (ndev)) {rtnl_lock ();@@ -2909,6 +2912,7 @@ static int am65_cpsw_nuss_resume(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common); ret =am65_cpsw_nuss_init_tx_chns (common);if (ret)@@ -2941,8 +2945,11 @@ static int am65_cpsw_nuss_resume(struct device *dev) }netif_device_attach (ndev); +writel (port->vid_context, port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); } +writel (host_p->vid_context, host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); +return 0 ; }#endif /* CONFIG_PM_SLEEP */ drivers/net/ethernet/ti/am65-cpsw-nuss.h +4
-0@@ -55,12 +55,16 @@ struct am65_cpsw_port {bool rx_ts_enabled;struct am65_cpsw_qos qos;struct devlink_port devlink_port; +/* Only for suspend resume context */ +u32 vid_context; };struct am65_cpsw_host {struct am65_cpsw_common *common;void __iomem *port_base;void __iomem *stat_base; +/* Only for suspend resume context */ +u32 vid_context; };
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.h +0
-0struct am65_cpsw_tx_chn {Signature · 1 line
2.17.1
--
cheers,
-roger
Re: [PATCH v3 net-next 5/6] net: ethernet: ti: am65-cpsw: retain PORT_VLAN_REG after suspend/resume
Quoted 37 lines · Roger Quadros
Quoted 27 lines · Maciej Fijalkowski
Quoted 16 lines · Roger Quadros
During suspend resume the context of
PORT_VLAN_REGis lost so save it during suspend and restore it during resume for host port and slave ports.Signed-off-by Roger Quadros <[email protected]>Signed-off-by David S. Miller <[email protected]>--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.h | 4 ++++ 2 files changed, 11 insertions(+)drivers/net/ethernet/ti/am65-cpsw-nuss.c +0
-0drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_nuss_suspend(struct device *dev) · line 2878
Quoted 4 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +1
-0@@ -2875,7 +2875,9 @@ static int am65_cpsw_nuss_suspend(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common);Nit: I see that retrieving host pointer depends on getting the common pointer first from
dev_get_drvdata(dev)so pure RCT is not possible to maintain here but nonetheless I would move this line just below the common pointer:Quoted 5 lines
struct am65_cpsw_common *common = dev_get_drvdata(dev); struct am65_cpsw_host *host = am65_common_get_host(common); struct am65_cpsw_port *port; struct net_device *ndev; int i, ret;OK.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
Also I think plain 'host' for variable name is just fine, no need for _p suffix to indicate it is a pointer. in that case you should go with
common_petc.
host_pis the naming convention used throughout the driver. Do think it is a good idea to change it at this one place?
No, maybe think of a refactor throughout whole codebase, changing it in a single place would be odd.
Quoted 63 lines
Quoted 55 lines
Quoted 55 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +6
-0+ host_p->vid_context =readl (host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );for (i =0 ; i < common->port_num; i++) { port = &common->ports[i]; ndev = port->ndev;@@ -2883,6 +2885,7 @@ static int am65_cpsw_nuss_suspend(struct device *dev)if (!ndev)continue ; + port->vid_context =readl (port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET );netif_device_detach (ndev);if (netif_running (ndev)) {rtnl_lock ();@@ -2909,6 +2912,7 @@ static int am65_cpsw_nuss_resume(struct device *dev)struct am65_cpsw_port *port;struct net_device *ndev;int i, ret; +struct am65_cpsw_host *host_p =am65_common_get_host (common); ret =am65_cpsw_nuss_init_tx_chns (common);if (ret)@@ -2941,8 +2945,11 @@ static int am65_cpsw_nuss_resume(struct device *dev) }netif_device_attach (ndev); +writel (port->vid_context, port->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); } +writel (host_p->vid_context, host_p->port_base +AM65_CPSW_PORT_VLAN_REG_OFFSET ); +return 0 ; }#endif /* CONFIG_PM_SLEEP */ drivers/net/ethernet/ti/am65-cpsw-nuss.h +4
-0@@ -55,12 +55,16 @@ struct am65_cpsw_port {bool rx_ts_enabled;struct am65_cpsw_qos qos;struct devlink_port devlink_port; +/* Only for suspend resume context */ +u32 vid_context; };struct am65_cpsw_host {struct am65_cpsw_common *common;void __iomem *port_base;void __iomem *stat_base; +/* Only for suspend resume context */ +u32 vid_context; };Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.h +0
-0struct am65_cpsw_tx_chn {Signature · 1 line
2.17.1--
cheers,
-roger