Skip to content

Commit a9dbe40

Browse files
dwmw2davem330
authored andcommitted
8139cp: set ring address after enabling C+ mode
This fixes (for me) a regression introduced by commit b01af45 ("8139cp: set ring address before enabling receiver"). That commit configured the descriptor ring addresses earlier in the initialisation sequence, in order to avoid the possibility of triggering stray DMA before the correct address had been set up. Unfortunately, it seems that the hardware will scribble garbage into the TxRingAddr registers when we enable "plus mode" Tx in the CpCmd register. Observed on a Traverse Geos router board. To deal with this, while not reintroducing the problem which led to the original commit, we augment cp_start_hw() to write to the CpCmd register *first*, then set the descriptor ring addresses, and then finally to enable Rx and Tx in the original 8139 Cmd register. The datasheet actually indicates that we should enable Tx/Rx in the Cmd register *before* configuring the descriptor addresses, but that would appear to re-introduce the problem that the offending commit b01af45 was trying to solve. And this variant appears to work fine on real hardware. Signed-off-by: David Woodhouse <[email protected]> Cc: [email protected] [3.5+] Signed-off-by: David S. Miller <[email protected]>
1 parent 071e3ef commit a9dbe40

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

drivers/net/ethernet/realtek/8139cp.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,35 @@ static void cp_reset_hw (struct cp_private *cp)
957957

958958
static inline void cp_start_hw (struct cp_private *cp)
959959
{
960+
dma_addr_t ring_dma;
961+
960962
cpw16(CpCmd, cp->cpcmd);
963+
964+
/*
965+
* These (at least TxRingAddr) need to be configured after the
966+
* corresponding bits in CpCmd are enabled. Datasheet v1.6 §6.33
967+
* (C+ Command Register) recommends that these and more be configured
968+
* *after* the [RT]xEnable bits in CpCmd are set. And on some hardware
969+
* it's been observed that the TxRingAddr is actually reset to garbage
970+
* when C+ mode Tx is enabled in CpCmd.
971+
*/
972+
cpw32_f(HiTxRingAddr, 0);
973+
cpw32_f(HiTxRingAddr + 4, 0);
974+
975+
ring_dma = cp->ring_dma;
976+
cpw32_f(RxRingAddr, ring_dma & 0xffffffff);
977+
cpw32_f(RxRingAddr + 4, (ring_dma >> 16) >> 16);
978+
979+
ring_dma += sizeof(struct cp_desc) * CP_RX_RING_SIZE;
980+
cpw32_f(TxRingAddr, ring_dma & 0xffffffff);
981+
cpw32_f(TxRingAddr + 4, (ring_dma >> 16) >> 16);
982+
983+
/*
984+
* Strictly speaking, the datasheet says this should be enabled
985+
* *before* setting the descriptor addresses. But what, then, would
986+
* prevent it from doing DMA to random unconfigured addresses?
987+
* This variant appears to work fine.
988+
*/
961989
cpw8(Cmd, RxOn | TxOn);
962990
}
963991

@@ -969,7 +997,6 @@ static void cp_enable_irq(struct cp_private *cp)
969997
static void cp_init_hw (struct cp_private *cp)
970998
{
971999
struct net_device *dev = cp->dev;
972-
dma_addr_t ring_dma;
9731000

9741001
cp_reset_hw(cp);
9751002

@@ -979,17 +1006,6 @@ static void cp_init_hw (struct cp_private *cp)
9791006
cpw32_f (MAC0 + 0, le32_to_cpu (*(__le32 *) (dev->dev_addr + 0)));
9801007
cpw32_f (MAC0 + 4, le32_to_cpu (*(__le32 *) (dev->dev_addr + 4)));
9811008

982-
cpw32_f(HiTxRingAddr, 0);
983-
cpw32_f(HiTxRingAddr + 4, 0);
984-
985-
ring_dma = cp->ring_dma;
986-
cpw32_f(RxRingAddr, ring_dma & 0xffffffff);
987-
cpw32_f(RxRingAddr + 4, (ring_dma >> 16) >> 16);
988-
989-
ring_dma += sizeof(struct cp_desc) * CP_RX_RING_SIZE;
990-
cpw32_f(TxRingAddr, ring_dma & 0xffffffff);
991-
cpw32_f(TxRingAddr + 4, (ring_dma >> 16) >> 16);
992-
9931009
cp_start_hw(cp);
9941010
cpw8(TxThresh, 0x06); /* XXX convert magic num to a constant */
9951011

0 commit comments

Comments
 (0)