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>
42 #include <asm/pgtable.h>
44 #include <asm/uaccess.h>
53 #define W32(_p, _m, _v) out_be32(&(_p)->_m, (_v))
54 #define R32(_p, _m) in_be32(&(_p)->_m)
55 #define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
56 #define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
58 #define W16(_p, _m, _v) out_be16(&(_p)->_m, (_v))
59 #define R16(_p, _m) in_be16(&(_p)->_m)
60 #define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
61 #define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
63 #define W8(_p, _m, _v) out_8(&(_p)->_m, (_v))
64 #define R8(_p, _m) in_8(&(_p)->_m)
65 #define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
66 #define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
70 #define FCC_MAX_MULTICAST_ADDRS 64
72 #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
73 #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
76 #define MAX_CR_CMD_LOOPS 10000
126 #define FCC_NAPI_RX_EVENT_MSK (FCC_ENET_RXF | FCC_ENET_RXB)
127 #define FCC_RX_EVENT (FCC_ENET_RXF)
128 #define FCC_TX_EVENT (FCC_ENET_TXB)
129 #define FCC_ERR_EVENT_MSK (FCC_ENET_TXE)
135 if (do_pd_setup(fep) != 0)
172 static void cleanup_data(
struct net_device *dev)
177 static void set_promiscuous_mode(
struct net_device *dev)
182 S32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
185 static void set_multicast_start(
struct net_device *dev)
190 W32(ep, fen_gaddrh, 0);
191 W32(ep, fen_gaddrl, 0);
198 u16 taddrh, taddrm, taddrl;
200 taddrh = ((
u16)mac[5] << 8) | mac[4];
201 taddrm = ((
u16)mac[3] << 8) | mac[2];
202 taddrl = ((
u16)mac[1] << 8) | mac[0];
204 W16(ep, fen_taddrh, taddrh);
205 W16(ep, fen_taddrm, taddrm);
206 W16(ep, fen_taddrl, taddrl);
210 static void set_multicast_finish(
struct net_device *dev)
217 C32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
223 W32(ep, fen_gaddrh, 0xffffffff);
224 W32(ep, fen_gaddrl, 0xffffffff);
228 fep->
fcc.gaddrh =
R32(ep, fen_gaddrh);
229 fep->
fcc.gaddrl =
R32(ep, fen_gaddrl);
232 static void set_multicast_list(
struct net_device *dev)
237 set_multicast_start(dev);
239 set_multicast_one(dev, ha->
addr);
240 set_multicast_finish(dev);
242 set_promiscuous_mode(dev);
253 u16 paddrh, paddrm, paddrl;
254 const unsigned char *
mac;
257 C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
260 for (i = 0; i <
sizeof(*ep); i++)
265 tx_bd_base_phys = rx_bd_base_phys +
sizeof(
cbd_t) * fpi->
rx_ring;
268 W32(ep, fen_genfcc.fcc_rbase, rx_bd_base_phys);
269 W32(ep, fen_genfcc.fcc_tbase, tx_bd_base_phys);
293 W32(ep, fen_genfcc.fcc_rbptr, 0);
294 W32(ep, fen_genfcc.fcc_tbptr, 0);
295 W32(ep, fen_genfcc.fcc_rcrc, 0);
296 W32(ep, fen_genfcc.fcc_tcrc, 0);
297 W16(ep, fen_genfcc.fcc_res1, 0);
298 W32(ep, fen_genfcc.fcc_res2, 0);
301 W32(ep, fen_camptr, 0);
304 W32(ep, fen_cmask, 0xdebb20e3);
305 W32(ep, fen_cpres, 0xffffffff);
307 W32(ep, fen_crcec, 0);
308 W32(ep, fen_alec, 0);
309 W32(ep, fen_disfc, 0);
310 W16(ep, fen_retlim, 15);
311 W16(ep, fen_pper, 0);
314 W32(ep, fen_gaddrh, fep->
fcc.gaddrh);
315 W32(ep, fen_gaddrl, fep->
fcc.gaddrh);
318 W32(ep, fen_iaddrh, 0);
319 W32(ep, fen_iaddrl, 0);
322 W16(ep, fen_tfcstat, 0);
323 W16(ep, fen_tfclen, 0);
324 W32(ep, fen_tfcptr, 0);
331 paddrh = ((
u16)mac[5] << 8) | mac[4];
332 paddrm = ((
u16)mac[3] << 8) | mac[2];
333 paddrl = ((
u16)mac[1] << 8) | mac[0];
335 W16(ep, fen_paddrh, paddrh);
336 W16(ep, fen_paddrm, paddrm);
337 W16(ep, fen_paddrl, paddrl);
339 W16(ep, fen_taddrh, 0);
340 W16(ep, fen_taddrm, 0);
341 W16(ep, fen_taddrl, 0);
343 W16(ep, fen_maxd1, 1520);
344 W16(ep, fen_maxd2, 1520);
347 W32(ep, fen_octc, 0);
348 W32(ep, fen_colc, 0);
349 W32(ep, fen_broc, 0);
350 W32(ep, fen_mulc, 0);
351 W32(ep, fen_uspc, 0);
352 W32(ep, fen_frgc, 0);
353 W32(ep, fen_ospc, 0);
354 W32(ep, fen_jbrc, 0);
355 W32(ep, fen_p64c, 0);
356 W32(ep, fen_p65c, 0);
357 W32(ep, fen_p128c, 0);
358 W32(ep, fen_p256c, 0);
359 W32(ep, fen_p512c, 0);
360 W32(ep, fen_p1024c, 0);
362 W16(ep, fen_rfthr, 0);
363 W16(ep, fen_rfcnt, 0);
364 W16(ep, fen_cftype, 0);
370 if (fep->
phydev->speed == 100)
371 C8(fcccp, fcc_gfemr, 0x20);
373 S8(fcccp, fcc_gfemr, 0x20);
379 W16(fccp, fcc_fcce, 0xffff);
382 W16(fccp, fcc_fccm, FCC_ENET_TXE | FCC_ENET_RXF | FCC_ENET_TXB);
385 W32(fccp, fcc_gfmr, FCC_GFMR_TCI | FCC_GFMR_MODE_ENET);
388 W16(fccp, fcc_fdsr, 0xd555);
390 W32(fccp, fcc_fpsmr, FCC_PSMR_ENCRC);
393 S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
397 S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
399 C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
402 set_multicast_list(dev);
404 S32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
413 C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
416 W16(fccp, fcc_fcce, 0xffff);
419 W16(fccp, fcc_fccm, 0);
424 static void napi_clear_rx_event(
struct net_device *dev)
432 static void napi_enable_rx(
struct net_device *dev)
440 static void napi_disable_rx(
struct net_device *dev)
448 static void rx_bd_done(
struct net_device *dev)
453 static void tx_kickstart(
struct net_device *dev)
458 S16(fccp, fcc_ftodr, 0x8000);
466 return (
u32)
R16(fccp, fcc_fcce);
469 static void clear_int_events(
struct net_device *dev,
u32 int_events)
474 W16(fccp, fcc_fcce, int_events & 0xffff);
481 dev_warn(fep->
dev,
"FS_ENET ERROR(s) 0x%x\n", int_events);
484 static int get_regs(
struct net_device *dev,
void *
p,
int *sizep)
488 if (*sizep <
sizeof(fcc_t) +
sizeof(fcc_enet_t) + 1)
492 p = (
char *)p +
sizeof(fcc_t);
495 p = (
char *)p +
sizeof(fcc_enet_t);
501 static int get_regs_len(
struct net_device *dev)
503 return sizeof(fcc_t) +
sizeof(fcc_enet_t) + 1;
517 static void tx_restart(
struct net_device *dev)
535 prev_bd = (recheck_bd == fep->
tx_bd_base) ? last_tx_bd : recheck_bd - 1;
541 recheck_bd = prev_bd;
544 prev_bd = (prev_bd == fep->
tx_bd_base) ? last_tx_bd : prev_bd - 1;
547 if (recheck_bd == curr_tbptr)
551 W32(ep, fen_genfcc.fcc_tbptr,
556 C32(fccp, fcc_gfmr, FCC_GFMR_ENT);
558 S32(fccp, fcc_gfmr, FCC_GFMR_ENT);