15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/string.h>
19 #include <linux/ptrace.h>
20 #include <linux/errno.h>
25 #include <linux/netdevice.h>
29 #include <linux/mii.h>
30 #include <linux/ethtool.h>
31 #include <linux/bitops.h>
38 #include <asm/uaccess.h>
42 #include <asm/pgtable.h>
52 #if defined(CONFIG_CPM1)
54 #define __fs_out32(addr, x) __raw_writel(x, addr)
55 #define __fs_out16(addr, x) __raw_writew(x, addr)
56 #define __fs_in32(addr) __raw_readl(addr)
57 #define __fs_in16(addr) __raw_readw(addr)
60 #define __fs_out32(addr, x) out_be32(addr, x)
61 #define __fs_out16(addr, x) out_be16(addr, x)
62 #define __fs_in32(addr) in_be32(addr)
63 #define __fs_in16(addr) in_be16(addr)
67 #define FW(_fecp, _reg, _v) __fs_out32(&(_fecp)->fec_ ## _reg, (_v))
70 #define FR(_fecp, _reg) __fs_in32(&(_fecp)->fec_ ## _reg)
73 #define FS(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) | (_v))
76 #define FC(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) & ~(_v))
81 #define FEC_RESET_DELAY 50
83 static int whack_reset(
struct fec __iomem *fecp)
112 #define FEC_NAPI_RX_EVENT_MSK (FEC_ENET_RXF | FEC_ENET_RXB)
113 #define FEC_RX_EVENT (FEC_ENET_RXF)
114 #define FEC_TX_EVENT (FEC_ENET_TXF)
115 #define FEC_ERR_EVENT_MSK (FEC_ENET_HBERR | FEC_ENET_BABR | \
116 FEC_ENET_BABT | FEC_ENET_EBERR)
122 if (do_pd_setup(fep) != 0)
163 static void cleanup_data(
struct net_device *dev)
168 static void set_promiscuous_mode(
struct net_device *dev)
176 static void set_multicast_start(
struct net_device *dev)
187 int temp, hash_index,
i,
j;
192 for (i = 0; i < 6; i++) {
194 for (j = 0; j < 8; j++) {
197 if (msb ^ (byte & 0x1))
203 temp = (crc & 0x3f) >> 1;
204 hash_index = ((temp & 0x01) << 4) |
205 ((temp & 0x02) << 2) |
207 ((temp & 0x08) >> 2) |
208 ((temp & 0x10) >> 4);
209 csrVal = 1 << hash_index;
211 fep->
fec.hthi |= csrVal;
213 fep->
fec.htlo |= csrVal;
216 static void set_multicast_finish(
struct net_device *dev)
224 fep->
fec.hthi = 0xffffffff
U;
225 fep->
fec.htlo = 0xffffffff
U;
229 FW(fecp, grp_hash_table_high, fep->
fec.hthi);
230 FW(fecp, grp_hash_table_low, fep->
fec.htlo);
233 static void set_multicast_list(
struct net_device *dev)
238 set_multicast_start(dev);
240 set_multicast_one(dev, ha->
addr);
241 set_multicast_finish(dev);
243 set_promiscuous_mode(dev);
256 struct fec_info* fec_inf = mii->
priv;
258 r = whack_reset(fep->
fec.fecp);
264 addrhi = ((
u32) dev->dev_addr[0] << 24) |
265 ((
u32) dev->dev_addr[1] << 16) |
266 ((
u32) dev->dev_addr[2] << 8) |
267 (
u32) dev->dev_addr[3];
268 addrlo = ((
u32) dev->dev_addr[4] << 24) |
269 ((
u32) dev->dev_addr[5] << 16);
276 FW(fecp, grp_hash_table_high, fep->
fec.hthi);
277 FW(fecp, grp_hash_table_low, fep->
fec.htlo);
283 #ifdef CONFIG_FS_ENET_MPC5121_FEC
291 tx_bd_base_phys = rx_bd_base_phys +
sizeof(
cbd_t) * fpi->
rx_ring;
296 FW(fecp, r_des_start, rx_bd_base_phys);
297 FW(fecp, x_des_start, tx_bd_base_phys);
304 #ifdef CONFIG_FS_ENET_MPC5121_FEC
307 FW(fecp, fun_code, 0x78000000);
313 FW(fecp, mii_speed, fec_inf->mii_speed);
318 FW(fecp, ievent, 0xffc0);
319 #ifndef CONFIG_FS_ENET_MPC5121_FEC
334 if (fep->
phydev->duplex) {
352 FW(fecp, r_des_active, 0x01000000);
361 struct fec_info* feci= fep->
phydev->bus->priv;
368 FW(fecp, x_cntrl, 0x01);
369 for (i = 0; ((
FR(fecp, ievent) & 0x10000000) == 0) &&
373 if (i == FEC_RESET_DELAY)
374 dev_warn(fep->
dev,
"FEC timeout on graceful transmit stop\n");
379 FC(fecp, ecntrl, FEC_ECNTRL_ETHER_EN);
390 FW(fecp, mii_speed, feci->mii_speed);
394 static void napi_clear_rx_event(
struct net_device *dev)
402 static void napi_enable_rx(
struct net_device *dev)
410 static void napi_disable_rx(
struct net_device *dev)
418 static void rx_bd_done(
struct net_device *dev)
423 FW(fecp, r_des_active, 0x01000000);
426 static void tx_kickstart(
struct net_device *dev)
431 FW(fecp, x_des_active, 0x01000000);
439 return FR(fecp, ievent) &
FR(fecp, imask);
442 static void clear_int_events(
struct net_device *dev,
u32 int_events)
447 FW(fecp, ievent, int_events);
454 dev_warn(fep->
dev,
"FEC ERROR(s) 0x%x\n", int_events);
457 static int get_regs(
struct net_device *dev,
void *
p,
int *sizep)
461 if (*sizep <
sizeof(
struct fec))
469 static int get_regs_len(
struct net_device *dev)
471 return sizeof(
struct fec);
474 static void tx_restart(
struct net_device *dev)