Skip to content

Commit 1620652

Browse files
Jon Masondavem330
authored andcommitted
net: ethernet: bgmac: init sequence bug
Fix a bug in the 'bgmac' driver init sequence that blind writes for init sequence where it should preserve most bits other than the ones it is deliberately manipulating. The code now checks to see if the adapter needs to be brought out of reset (where as before it was doing an IDM write to bring it out of reset regardless of whether it was in reset or not). Also, removed unnecessary usleeps (as there is already a read present to flush the IDM writes). Signed-off-by: Zac Schroff <[email protected]> Signed-off-by: Jon Mason <[email protected]> Fixes: f6a95a2 ("net: ethernet: bgmac: Add platform device support") Signed-off-by: David S. Miller <[email protected]>
1 parent 2ddbcea commit 1620652

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

drivers/net/ethernet/broadcom/bgmac-platform.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ static void platform_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
5151

5252
static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
5353
{
54-
if ((bgmac_idm_read(bgmac, BCMA_IOCTL) &
55-
(BCMA_IOCTL_CLK | BCMA_IOCTL_FGC)) != BCMA_IOCTL_CLK)
54+
if ((bgmac_idm_read(bgmac, BCMA_IOCTL) & BGMAC_CLK_EN) != BGMAC_CLK_EN)
5655
return false;
5756
if (bgmac_idm_read(bgmac, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
5857
return false;
@@ -61,15 +60,25 @@ static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
6160

6261
static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
6362
{
64-
bgmac_idm_write(bgmac, BCMA_IOCTL,
65-
(BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
66-
bgmac_idm_read(bgmac, BCMA_IOCTL);
63+
u32 val;
6764

68-
bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
69-
bgmac_idm_read(bgmac, BCMA_RESET_CTL);
70-
udelay(1);
65+
/* The Reset Control register only contains a single bit to show if the
66+
* controller is currently in reset. Do a sanity check here, just in
67+
* case the bootloader happened to leave the device in reset.
68+
*/
69+
val = bgmac_idm_read(bgmac, BCMA_RESET_CTL);
70+
if (val) {
71+
bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
72+
bgmac_idm_read(bgmac, BCMA_RESET_CTL);
73+
udelay(1);
74+
}
7175

72-
bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
76+
val = bgmac_idm_read(bgmac, BCMA_IOCTL);
77+
/* Some bits of BCMA_IOCTL set by HW/ATF and should not change */
78+
val |= flags & ~(BGMAC_AWCACHE | BGMAC_ARCACHE | BGMAC_AWUSER |
79+
BGMAC_ARUSER);
80+
val |= BGMAC_CLK_EN;
81+
bgmac_idm_write(bgmac, BCMA_IOCTL, val);
7382
bgmac_idm_read(bgmac, BCMA_IOCTL);
7483
udelay(1);
7584
}

drivers/net/ethernet/broadcom/bgmac.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,22 @@
213213
/* BCMA GMAC core specific IO Control (BCMA_IOCTL) flags */
214214
#define BGMAC_BCMA_IOCTL_SW_CLKEN 0x00000004 /* PHY Clock Enable */
215215
#define BGMAC_BCMA_IOCTL_SW_RESET 0x00000008 /* PHY Reset */
216+
/* The IOCTL values appear to be different in NS, NSP, and NS2, and do not match
217+
* the values directly above
218+
*/
219+
#define BGMAC_CLK_EN BIT(0)
220+
#define BGMAC_RESERVED_0 BIT(1)
221+
#define BGMAC_SOURCE_SYNC_MODE_EN BIT(2)
222+
#define BGMAC_DEST_SYNC_MODE_EN BIT(3)
223+
#define BGMAC_TX_CLK_OUT_INVERT_EN BIT(4)
224+
#define BGMAC_DIRECT_GMII_MODE BIT(5)
225+
#define BGMAC_CLK_250_SEL BIT(6)
226+
#define BGMAC_AWCACHE (0xf << 7)
227+
#define BGMAC_RESERVED_1 (0x1f << 11)
228+
#define BGMAC_ARCACHE (0xf << 16)
229+
#define BGMAC_AWUSER (0x3f << 20)
230+
#define BGMAC_ARUSER (0x3f << 26)
231+
#define BGMAC_RESERVED BIT(31)
216232

217233
/* BCMA GMAC core specific IO status (BCMA_IOST) flags */
218234
#define BGMAC_BCMA_IOST_ATTACHED 0x00000800

0 commit comments

Comments
 (0)