Skip to content

Commit 9039cd4

Browse files
claudiubezneadavem330
authored andcommitted
net: ravb: Wait for operating mode to be applied
CSR.OPS bits specify the current operating mode and (according to documentation) they are updated by HW when the operating mode change request is processed. To comply with this check CSR.OPS before proceeding. Commit introduces ravb_set_opmode() that does all the necessities for setting the operating mode (set CCC.OPC (and CCC.GAC, CCC.CSEL, if any) and wait for CSR.OPS) and call it where needed. This should comply with all the HW manuals requirements as different manual variants specify that different modes need to be checked in CSR.OPS when setting CCC.OPC. If gPTP active in config mode is supported and it needs to be enabled, the CCC.GAC and CCC.CSEL needs to be configured along with CCC.OPC in the same write access. For this, ravb_set_opmode() allows passing GAC and CSEL as part of opmode and the function updates accordingly CCC register. Fixes: c156633 ("Renesas Ethernet AVB driver proper") Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent eaac6a2 commit 9039cd4

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,27 @@ int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value)
6666
return -ETIMEDOUT;
6767
}
6868

69-
static int ravb_config(struct net_device *ndev)
69+
static int ravb_set_opmode(struct net_device *ndev, u32 opmode)
7070
{
71+
u32 csr_ops = 1U << (opmode & CCC_OPC);
72+
u32 ccc_mask = CCC_OPC;
7173
int error;
7274

73-
/* Set config mode */
74-
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
75-
/* Check if the operating mode is changed to the config mode */
76-
error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
77-
if (error)
78-
netdev_err(ndev, "failed to switch device to config mode\n");
75+
/* If gPTP active in config mode is supported it needs to be configured
76+
* along with CSEL and operating mode in the same access. This is a
77+
* hardware limitation.
78+
*/
79+
if (opmode & CCC_GAC)
80+
ccc_mask |= CCC_GAC | CCC_CSEL;
81+
82+
/* Set operating mode */
83+
ravb_modify(ndev, CCC, ccc_mask, opmode);
84+
/* Check if the operating mode is changed to the requested one */
85+
error = ravb_wait(ndev, CSR, CSR_OPS, csr_ops);
86+
if (error) {
87+
netdev_err(ndev, "failed to switch device to requested mode (%u)\n",
88+
opmode & CCC_OPC);
89+
}
7990

8091
return error;
8192
}
@@ -673,7 +684,7 @@ static int ravb_dmac_init(struct net_device *ndev)
673684
int error;
674685

675686
/* Set CONFIG mode */
676-
error = ravb_config(ndev);
687+
error = ravb_set_opmode(ndev, CCC_OPC_CONFIG);
677688
if (error)
678689
return error;
679690

@@ -682,9 +693,7 @@ static int ravb_dmac_init(struct net_device *ndev)
682693
return error;
683694

684695
/* Setting the control will start the AVB-DMAC process. */
685-
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
686-
687-
return 0;
696+
return ravb_set_opmode(ndev, CCC_OPC_OPERATION);
688697
}
689698

690699
static void ravb_get_tx_tstamp(struct net_device *ndev)
@@ -1046,7 +1055,7 @@ static int ravb_stop_dma(struct net_device *ndev)
10461055
return error;
10471056

10481057
/* Stop AVB-DMAC process */
1049-
return ravb_config(ndev);
1058+
return ravb_set_opmode(ndev, CCC_OPC_CONFIG);
10501059
}
10511060

10521061
/* E-MAC interrupt handler */
@@ -2560,21 +2569,25 @@ static int ravb_set_gti(struct net_device *ndev)
25602569
return 0;
25612570
}
25622571

2563-
static void ravb_set_config_mode(struct net_device *ndev)
2572+
static int ravb_set_config_mode(struct net_device *ndev)
25642573
{
25652574
struct ravb_private *priv = netdev_priv(ndev);
25662575
const struct ravb_hw_info *info = priv->info;
2576+
int error;
25672577

25682578
if (info->gptp) {
2569-
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
2579+
error = ravb_set_opmode(ndev, CCC_OPC_CONFIG);
2580+
if (error)
2581+
return error;
25702582
/* Set CSEL value */
25712583
ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB);
25722584
} else if (info->ccc_gac) {
2573-
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG |
2574-
CCC_GAC | CCC_CSEL_HPB);
2585+
error = ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB);
25752586
} else {
2576-
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
2587+
error = ravb_set_opmode(ndev, CCC_OPC_CONFIG);
25772588
}
2589+
2590+
return error;
25782591
}
25792592

25802593
/* Set tx and rx clock internal delay modes */
@@ -2794,7 +2807,9 @@ static int ravb_probe(struct platform_device *pdev)
27942807
ndev->ethtool_ops = &ravb_ethtool_ops;
27952808

27962809
/* Set AVB config mode */
2797-
ravb_set_config_mode(ndev);
2810+
error = ravb_set_config_mode(ndev);
2811+
if (error)
2812+
goto out_disable_gptp_clk;
27982813

27992814
if (info->gptp || info->ccc_gac) {
28002815
/* Set GTI value */
@@ -2917,8 +2932,7 @@ static void ravb_remove(struct platform_device *pdev)
29172932
dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
29182933
priv->desc_bat_dma);
29192934

2920-
/* Set reset mode */
2921-
ravb_write(ndev, CCC_OPC_RESET, CCC);
2935+
ravb_set_opmode(ndev, CCC_OPC_RESET);
29222936

29232937
clk_disable_unprepare(priv->gptp_clk);
29242938
clk_disable_unprepare(priv->refclk);
@@ -3000,16 +3014,21 @@ static int __maybe_unused ravb_resume(struct device *dev)
30003014
int ret = 0;
30013015

30023016
/* If WoL is enabled set reset mode to rearm the WoL logic */
3003-
if (priv->wol_enabled)
3004-
ravb_write(ndev, CCC_OPC_RESET, CCC);
3017+
if (priv->wol_enabled) {
3018+
ret = ravb_set_opmode(ndev, CCC_OPC_RESET);
3019+
if (ret)
3020+
return ret;
3021+
}
30053022

30063023
/* All register have been reset to default values.
30073024
* Restore all registers which where setup at probe time and
30083025
* reopen device if it was running before system suspended.
30093026
*/
30103027

30113028
/* Set AVB config mode */
3012-
ravb_set_config_mode(ndev);
3029+
ret = ravb_set_config_mode(ndev);
3030+
if (ret)
3031+
return ret;
30133032

30143033
if (info->gptp || info->ccc_gac) {
30153034
/* Set GTI value */

0 commit comments

Comments
 (0)