Skip to content

Commit ea97cae

Browse files
committed
Merge branch 'gianfar'
Claudiu Manoil says: ==================== gianfar: ARM port driver updates (1/2) This is the first round of driver portability fixes and clean-up with the main purpose to make gianfar portable on ARM, for the ARM based SoC that integrates the eTSEC ethernet controller - "ls1021a". The patches primarily address compile time errors, when compiling gianfar on ARM. They replace PPC specific functions and macros with architecture independent ones, solve arch specific header inclusions, guard code that relates to PPC only, and even address some simple endianess issues (see MAC address setup patch). The patches addressing the bulk of remaining endianess issues, like handling DMA fields (BD and FCB), will follow with the second round. ==================== Reviewed-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 59f35b8 + d55398b commit ea97cae

3 files changed

Lines changed: 102 additions & 53 deletions

File tree

‎drivers/net/ethernet/freescale/fsl_pq_mdio.c‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#include <linux/of_device.h>
2929

3030
#include <asm/io.h>
31+
#if IS_ENABLED(CONFIG_UCC_GETH)
3132
#include <asm/ucc.h> /* for ucc_set_qe_mux_mii_mng() */
33+
#endif
3234

3335
#include "gianfar.h"
3436

@@ -102,19 +104,22 @@ static int fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
102104
{
103105
struct fsl_pq_mdio_priv *priv = bus->priv;
104106
struct fsl_pq_mii __iomem *regs = priv->regs;
105-
u32 status;
107+
unsigned int timeout;
106108

107109
/* Set the PHY address and the register address we want to write */
108-
out_be32(&regs->miimadd, (mii_id << 8) | regnum);
110+
iowrite32be((mii_id << 8) | regnum, &regs->miimadd);
109111

110112
/* Write out the value we want */
111-
out_be32(&regs->miimcon, value);
113+
iowrite32be(value, &regs->miimcon);
112114

113115
/* Wait for the transaction to finish */
114-
status = spin_event_timeout(!(in_be32(&regs->miimind) & MIIMIND_BUSY),
115-
MII_TIMEOUT, 0);
116+
timeout = MII_TIMEOUT;
117+
while ((ioread32be(&regs->miimind) & MIIMIND_BUSY) && timeout) {
118+
cpu_relax();
119+
timeout--;
120+
}
116121

117-
return status ? 0 : -ETIMEDOUT;
122+
return timeout ? 0 : -ETIMEDOUT;
118123
}
119124

120125
/*
@@ -131,25 +136,29 @@ static int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
131136
{
132137
struct fsl_pq_mdio_priv *priv = bus->priv;
133138
struct fsl_pq_mii __iomem *regs = priv->regs;
134-
u32 status;
139+
unsigned int timeout;
135140
u16 value;
136141

137142
/* Set the PHY address and the register address we want to read */
138-
out_be32(&regs->miimadd, (mii_id << 8) | regnum);
143+
iowrite32be((mii_id << 8) | regnum, &regs->miimadd);
139144

140145
/* Clear miimcom, and then initiate a read */
141-
out_be32(&regs->miimcom, 0);
142-
out_be32(&regs->miimcom, MII_READ_COMMAND);
146+
iowrite32be(0, &regs->miimcom);
147+
iowrite32be(MII_READ_COMMAND, &regs->miimcom);
143148

144149
/* Wait for the transaction to finish, normally less than 100us */
145-
status = spin_event_timeout(!(in_be32(&regs->miimind) &
146-
(MIIMIND_NOTVALID | MIIMIND_BUSY)),
147-
MII_TIMEOUT, 0);
148-
if (!status)
150+
timeout = MII_TIMEOUT;
151+
while ((ioread32be(&regs->miimind) &
152+
(MIIMIND_NOTVALID | MIIMIND_BUSY)) && timeout) {
153+
cpu_relax();
154+
timeout--;
155+
}
156+
157+
if (!timeout)
149158
return -ETIMEDOUT;
150159

151160
/* Grab the value of the register from miimstat */
152-
value = in_be32(&regs->miimstat);
161+
value = ioread32be(&regs->miimstat);
153162

154163
dev_dbg(&bus->dev, "read %04x from address %x/%x\n", value, mii_id, regnum);
155164
return value;
@@ -160,23 +169,26 @@ static int fsl_pq_mdio_reset(struct mii_bus *bus)
160169
{
161170
struct fsl_pq_mdio_priv *priv = bus->priv;
162171
struct fsl_pq_mii __iomem *regs = priv->regs;
163-
u32 status;
172+
unsigned int timeout;
164173

165174
mutex_lock(&bus->mdio_lock);
166175

167176
/* Reset the management interface */
168-
out_be32(&regs->miimcfg, MIIMCFG_RESET);
177+
iowrite32be(MIIMCFG_RESET, &regs->miimcfg);
169178

170179
/* Setup the MII Mgmt clock speed */
171-
out_be32(&regs->miimcfg, MIIMCFG_INIT_VALUE);
180+
iowrite32be(MIIMCFG_INIT_VALUE, &regs->miimcfg);
172181

173182
/* Wait until the bus is free */
174-
status = spin_event_timeout(!(in_be32(&regs->miimind) & MIIMIND_BUSY),
175-
MII_TIMEOUT, 0);
183+
timeout = MII_TIMEOUT;
184+
while ((ioread32be(&regs->miimind) & MIIMIND_BUSY) && timeout) {
185+
cpu_relax();
186+
timeout--;
187+
}
176188

177189
mutex_unlock(&bus->mdio_lock);
178190

179-
if (!status) {
191+
if (!timeout) {
180192
dev_err(&bus->dev, "timeout waiting for MII bus\n");
181193
return -EBUSY;
182194
}
@@ -433,7 +445,7 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev)
433445

434446
tbipa = data->get_tbipa(priv->map);
435447

436-
out_be32(tbipa, be32_to_cpup(prop));
448+
iowrite32be(be32_to_cpup(prop), tbipa);
437449
}
438450
}
439451

‎drivers/net/ethernet/freescale/gianfar.c‎

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@
8888
#include <linux/net_tstamp.h>
8989

9090
#include <asm/io.h>
91+
#ifdef CONFIG_PPC
9192
#include <asm/reg.h>
9293
#include <asm/mpc85xx.h>
94+
#endif
9395
#include <asm/irq.h>
9496
#include <asm/uaccess.h>
9597
#include <linux/module.h>
@@ -100,6 +102,8 @@
100102
#include <linux/phy_fixed.h>
101103
#include <linux/of.h>
102104
#include <linux/of_net.h>
105+
#include <linux/of_address.h>
106+
#include <linux/of_irq.h>
103107

104108
#include "gianfar.h"
105109

@@ -161,7 +165,7 @@ static void gfar_init_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp,
161165
if (bdp == rx_queue->rx_bd_base + rx_queue->rx_ring_size - 1)
162166
lstatus |= BD_LFLAG(RXBD_WRAP);
163167

164-
eieio();
168+
gfar_wmb();
165169

166170
bdp->lstatus = lstatus;
167171
}
@@ -1061,6 +1065,7 @@ static void gfar_init_filer_table(struct gfar_private *priv)
10611065
}
10621066
}
10631067

1068+
#ifdef CONFIG_PPC
10641069
static void __gfar_detect_errata_83xx(struct gfar_private *priv)
10651070
{
10661071
unsigned int pvr = mfspr(SPRN_PVR);
@@ -1093,6 +1098,7 @@ static void __gfar_detect_errata_85xx(struct gfar_private *priv)
10931098
((SVR_SOC_VER(svr) == SVR_P2010) && (SVR_REV(svr) < 0x20)))
10941099
priv->errata |= GFAR_ERRATA_76; /* aka eTSEC 20 */
10951100
}
1101+
#endif
10961102

10971103
static void gfar_detect_errata(struct gfar_private *priv)
10981104
{
@@ -1101,10 +1107,12 @@ static void gfar_detect_errata(struct gfar_private *priv)
11011107
/* no plans to fix */
11021108
priv->errata |= GFAR_ERRATA_A002;
11031109

1110+
#ifdef CONFIG_PPC
11041111
if (pvr_version_is(PVR_VER_E500V1) || pvr_version_is(PVR_VER_E500V2))
11051112
__gfar_detect_errata_85xx(priv);
11061113
else /* non-mpc85xx parts, i.e. e300 core based */
11071114
__gfar_detect_errata_83xx(priv);
1115+
#endif
11081116

11091117
if (priv->errata)
11101118
dev_info(dev, "enabled errata workarounds, flags: 0x%x\n",
@@ -1754,26 +1762,32 @@ static void gfar_halt_nodisable(struct gfar_private *priv)
17541762
{
17551763
struct gfar __iomem *regs = priv->gfargrp[0].regs;
17561764
u32 tempval;
1765+
unsigned int timeout;
1766+
int stopped;
17571767

17581768
gfar_ints_disable(priv);
17591769

1770+
if (gfar_is_dma_stopped(priv))
1771+
return;
1772+
17601773
/* Stop the DMA, and wait for it to stop */
17611774
tempval = gfar_read(&regs->dmactrl);
1762-
if ((tempval & (DMACTRL_GRS | DMACTRL_GTS)) !=
1763-
(DMACTRL_GRS | DMACTRL_GTS)) {
1764-
int ret;
1765-
1766-
tempval |= (DMACTRL_GRS | DMACTRL_GTS);
1767-
gfar_write(&regs->dmactrl, tempval);
1775+
tempval |= (DMACTRL_GRS | DMACTRL_GTS);
1776+
gfar_write(&regs->dmactrl, tempval);
17681777

1769-
do {
1770-
ret = spin_event_timeout(((gfar_read(&regs->ievent) &
1771-
(IEVENT_GRSC | IEVENT_GTSC)) ==
1772-
(IEVENT_GRSC | IEVENT_GTSC)), 1000000, 0);
1773-
if (!ret && !(gfar_read(&regs->ievent) & IEVENT_GRSC))
1774-
ret = __gfar_is_rx_idle(priv);
1775-
} while (!ret);
1778+
retry:
1779+
timeout = 1000;
1780+
while (!(stopped = gfar_is_dma_stopped(priv)) && timeout) {
1781+
cpu_relax();
1782+
timeout--;
17761783
}
1784+
1785+
if (!timeout)
1786+
stopped = gfar_is_dma_stopped(priv);
1787+
1788+
if (!stopped && !gfar_is_rx_dma_stopped(priv) &&
1789+
!__gfar_is_rx_idle(priv))
1790+
goto retry;
17771791
}
17781792

17791793
/* Halt the receive and transmit queues */
@@ -2357,18 +2371,11 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
23572371
*/
23582372
spin_lock_irqsave(&tx_queue->txlock, flags);
23592373

2360-
/* The powerpc-specific eieio() is used, as wmb() has too strong
2361-
* semantics (it requires synchronization between cacheable and
2362-
* uncacheable mappings, which eieio doesn't provide and which we
2363-
* don't need), thus requiring a more expensive sync instruction. At
2364-
* some point, the set of architecture-independent barrier functions
2365-
* should be expanded to include weaker barriers.
2366-
*/
2367-
eieio();
2374+
gfar_wmb();
23682375

23692376
txbdp_start->lstatus = lstatus;
23702377

2371-
eieio(); /* force lstatus write before tx_skbuff */
2378+
gfar_wmb(); /* force lstatus write before tx_skbuff */
23722379

23732380
tx_queue->tx_skbuff[tx_queue->skb_curtx] = skb;
23742381

@@ -3240,22 +3247,21 @@ static void gfar_set_mac_for_addr(struct net_device *dev, int num,
32403247
{
32413248
struct gfar_private *priv = netdev_priv(dev);
32423249
struct gfar __iomem *regs = priv->gfargrp[0].regs;
3243-
int idx;
3244-
char tmpbuf[ETH_ALEN];
32453250
u32 tempval;
32463251
u32 __iomem *macptr = &regs->macstnaddr1;
32473252

32483253
macptr += num*2;
32493254

3250-
/* Now copy it into the mac registers backwards, cuz
3251-
* little endian is silly
3255+
/* For a station address of 0x12345678ABCD in transmission
3256+
* order (BE), MACnADDR1 is set to 0xCDAB7856 and
3257+
* MACnADDR2 is set to 0x34120000.
32523258
*/
3253-
for (idx = 0; idx < ETH_ALEN; idx++)
3254-
tmpbuf[ETH_ALEN - 1 - idx] = addr[idx];
3259+
tempval = (addr[5] << 24) | (addr[4] << 16) |
3260+
(addr[3] << 8) | addr[2];
32553261

3256-
gfar_write(macptr, *((u32 *) (tmpbuf)));
3262+
gfar_write(macptr, tempval);
32573263

3258-
tempval = *((u32 *) (tmpbuf + 4));
3264+
tempval = (addr[1] << 24) | (addr[0] << 16);
32593265

32603266
gfar_write(macptr+1, tempval);
32613267
}

‎drivers/net/ethernet/freescale/gianfar.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,37 @@ static inline void gfar_write_isrg(struct gfar_private *priv)
12261226
}
12271227
}
12281228

1229+
static inline int gfar_is_dma_stopped(struct gfar_private *priv)
1230+
{
1231+
struct gfar __iomem *regs = priv->gfargrp[0].regs;
1232+
1233+
return ((gfar_read(&regs->ievent) & (IEVENT_GRSC | IEVENT_GTSC)) ==
1234+
(IEVENT_GRSC | IEVENT_GTSC));
1235+
}
1236+
1237+
static inline int gfar_is_rx_dma_stopped(struct gfar_private *priv)
1238+
{
1239+
struct gfar __iomem *regs = priv->gfargrp[0].regs;
1240+
1241+
return gfar_read(&regs->ievent) & IEVENT_GRSC;
1242+
}
1243+
1244+
static inline void gfar_wmb(void)
1245+
{
1246+
#if defined(CONFIG_PPC)
1247+
/* The powerpc-specific eieio() is used, as wmb() has too strong
1248+
* semantics (it requires synchronization between cacheable and
1249+
* uncacheable mappings, which eieio() doesn't provide and which we
1250+
* don't need), thus requiring a more expensive sync instruction. At
1251+
* some point, the set of architecture-independent barrier functions
1252+
* should be expanded to include weaker barriers.
1253+
*/
1254+
eieio();
1255+
#else
1256+
wmb(); /* order write acesses for BD (or FCB) fields */
1257+
#endif
1258+
}
1259+
12291260
irqreturn_t gfar_receive(int irq, void *dev_id);
12301261
int startup_gfar(struct net_device *dev);
12311262
void stop_gfar(struct net_device *dev);

0 commit comments

Comments
 (0)