Creation of Cybook 2416 (actually Gen4) repository
This commit is contained in:
20
drivers/net/fs_enet/Kconfig
Normal file
20
drivers/net/fs_enet/Kconfig
Normal file
@@ -0,0 +1,20 @@
|
||||
config FS_ENET
|
||||
tristate "Freescale Ethernet Driver"
|
||||
depends on NET_ETHERNET && (CPM1 || CPM2)
|
||||
select MII
|
||||
|
||||
config FS_ENET_HAS_SCC
|
||||
bool "Chip has an SCC usable for ethernet"
|
||||
depends on FS_ENET && (CPM1 || CPM2)
|
||||
default y
|
||||
|
||||
config FS_ENET_HAS_FCC
|
||||
bool "Chip has an FCC usable for ethernet"
|
||||
depends on FS_ENET && CPM2
|
||||
default y
|
||||
|
||||
config FS_ENET_HAS_FEC
|
||||
bool "Chip has an FEC usable for ethernet"
|
||||
depends on FS_ENET && CPM1
|
||||
default y
|
||||
|
||||
10
drivers/net/fs_enet/Makefile
Normal file
10
drivers/net/fs_enet/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Makefile for the Freescale Ethernet controllers
|
||||
#
|
||||
|
||||
obj-$(CONFIG_FS_ENET) += fs_enet.o
|
||||
|
||||
obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o mii-fec.o
|
||||
obj-$(CONFIG_CPM2) += mac-fcc.o mii-bitbang.o
|
||||
|
||||
fs_enet-objs := fs_enet-main.o
|
||||
42
drivers/net/fs_enet/fec.h
Normal file
42
drivers/net/fs_enet/fec.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef FS_ENET_FEC_H
|
||||
#define FS_ENET_FEC_H
|
||||
|
||||
/* CRC polynomium used by the FEC for the multicast group filtering */
|
||||
#define FEC_CRC_POLY 0x04C11DB7
|
||||
|
||||
#define FEC_MAX_MULTICAST_ADDRS 64
|
||||
|
||||
/* Interrupt events/masks.
|
||||
*/
|
||||
#define FEC_ENET_HBERR 0x80000000U /* Heartbeat error */
|
||||
#define FEC_ENET_BABR 0x40000000U /* Babbling receiver */
|
||||
#define FEC_ENET_BABT 0x20000000U /* Babbling transmitter */
|
||||
#define FEC_ENET_GRA 0x10000000U /* Graceful stop complete */
|
||||
#define FEC_ENET_TXF 0x08000000U /* Full frame transmitted */
|
||||
#define FEC_ENET_TXB 0x04000000U /* A buffer was transmitted */
|
||||
#define FEC_ENET_RXF 0x02000000U /* Full frame received */
|
||||
#define FEC_ENET_RXB 0x01000000U /* A buffer was received */
|
||||
#define FEC_ENET_MII 0x00800000U /* MII interrupt */
|
||||
#define FEC_ENET_EBERR 0x00400000U /* SDMA bus error */
|
||||
|
||||
#define FEC_ECNTRL_PINMUX 0x00000004
|
||||
#define FEC_ECNTRL_ETHER_EN 0x00000002
|
||||
#define FEC_ECNTRL_RESET 0x00000001
|
||||
|
||||
#define FEC_RCNTRL_BC_REJ 0x00000010
|
||||
#define FEC_RCNTRL_PROM 0x00000008
|
||||
#define FEC_RCNTRL_MII_MODE 0x00000004
|
||||
#define FEC_RCNTRL_DRT 0x00000002
|
||||
#define FEC_RCNTRL_LOOP 0x00000001
|
||||
|
||||
#define FEC_TCNTRL_FDEN 0x00000004
|
||||
#define FEC_TCNTRL_HBC 0x00000002
|
||||
#define FEC_TCNTRL_GTS 0x00000001
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Delay to wait for FEC reset command to complete (in us)
|
||||
*/
|
||||
#define FEC_RESET_DELAY 50
|
||||
#endif
|
||||
1281
drivers/net/fs_enet/fs_enet-main.c
Normal file
1281
drivers/net/fs_enet/fs_enet-main.c
Normal file
File diff suppressed because it is too large
Load Diff
254
drivers/net/fs_enet/fs_enet.h
Normal file
254
drivers/net/fs_enet/fs_enet.h
Normal file
@@ -0,0 +1,254 @@
|
||||
#ifndef FS_ENET_H
|
||||
#define FS_ENET_H
|
||||
|
||||
#include <linux/mii.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/phy.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
|
||||
#include <linux/fs_enet_pd.h>
|
||||
#include <asm/fs_pd.h>
|
||||
|
||||
#ifdef CONFIG_CPM1
|
||||
#include <asm/commproc.h>
|
||||
|
||||
struct fec_info {
|
||||
fec_t* fecp;
|
||||
u32 mii_speed;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CPM2
|
||||
#include <asm/cpm2.h>
|
||||
#endif
|
||||
|
||||
/* This is used to operate with pins.
|
||||
Note that the actual port size may
|
||||
be different; cpm(s) handle it OK */
|
||||
struct bb_info {
|
||||
u8 mdio_dat_msk;
|
||||
u8 mdio_dir_msk;
|
||||
u8 *mdio_dir;
|
||||
u8 *mdio_dat;
|
||||
u8 mdc_msk;
|
||||
u8 *mdc_dat;
|
||||
int delay;
|
||||
};
|
||||
|
||||
/* hw driver ops */
|
||||
struct fs_ops {
|
||||
int (*setup_data)(struct net_device *dev);
|
||||
int (*allocate_bd)(struct net_device *dev);
|
||||
void (*free_bd)(struct net_device *dev);
|
||||
void (*cleanup_data)(struct net_device *dev);
|
||||
void (*set_multicast_list)(struct net_device *dev);
|
||||
void (*adjust_link)(struct net_device *dev);
|
||||
void (*restart)(struct net_device *dev);
|
||||
void (*stop)(struct net_device *dev);
|
||||
void (*pre_request_irq)(struct net_device *dev, int irq);
|
||||
void (*post_free_irq)(struct net_device *dev, int irq);
|
||||
void (*napi_clear_rx_event)(struct net_device *dev);
|
||||
void (*napi_enable_rx)(struct net_device *dev);
|
||||
void (*napi_disable_rx)(struct net_device *dev);
|
||||
void (*rx_bd_done)(struct net_device *dev);
|
||||
void (*tx_kickstart)(struct net_device *dev);
|
||||
u32 (*get_int_events)(struct net_device *dev);
|
||||
void (*clear_int_events)(struct net_device *dev, u32 int_events);
|
||||
void (*ev_error)(struct net_device *dev, u32 int_events);
|
||||
int (*get_regs)(struct net_device *dev, void *p, int *sizep);
|
||||
int (*get_regs_len)(struct net_device *dev);
|
||||
void (*tx_restart)(struct net_device *dev);
|
||||
};
|
||||
|
||||
struct phy_info {
|
||||
unsigned int id;
|
||||
const char *name;
|
||||
void (*startup) (struct net_device * dev);
|
||||
void (*shutdown) (struct net_device * dev);
|
||||
void (*ack_int) (struct net_device * dev);
|
||||
};
|
||||
|
||||
/* The FEC stores dest/src/type, data, and checksum for receive packets.
|
||||
*/
|
||||
#define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */
|
||||
#define MIN_MTU 46 /* this is data size */
|
||||
#define CRC_LEN 4
|
||||
|
||||
#define PKT_MAXBUF_SIZE (MAX_MTU+ETH_HLEN+CRC_LEN)
|
||||
#define PKT_MINBUF_SIZE (MIN_MTU+ETH_HLEN+CRC_LEN)
|
||||
|
||||
/* Must be a multiple of 32 (to cover both FEC & FCC) */
|
||||
#define PKT_MAXBLR_SIZE ((PKT_MAXBUF_SIZE + 31) & ~31)
|
||||
/* This is needed so that invalidate_xxx wont invalidate too much */
|
||||
#define ENET_RX_FRSIZE L1_CACHE_ALIGN(PKT_MAXBUF_SIZE)
|
||||
|
||||
struct fs_enet_mii_bus {
|
||||
struct list_head list;
|
||||
spinlock_t mii_lock;
|
||||
const struct fs_mii_bus_info *bus_info;
|
||||
int refs;
|
||||
u32 usage_map;
|
||||
|
||||
int (*mii_read)(struct fs_enet_mii_bus *bus,
|
||||
int phy_id, int location);
|
||||
|
||||
void (*mii_write)(struct fs_enet_mii_bus *bus,
|
||||
int phy_id, int location, int value);
|
||||
|
||||
union {
|
||||
struct {
|
||||
unsigned int mii_speed;
|
||||
void *fecp;
|
||||
} fec;
|
||||
|
||||
struct {
|
||||
/* note that the actual port size may */
|
||||
/* be different; cpm(s) handle it OK */
|
||||
u8 mdio_msk;
|
||||
u8 *mdio_dir;
|
||||
u8 *mdio_dat;
|
||||
u8 mdc_msk;
|
||||
u8 *mdc_dir;
|
||||
u8 *mdc_dat;
|
||||
} bitbang;
|
||||
|
||||
struct {
|
||||
u16 lpa;
|
||||
} fixed;
|
||||
};
|
||||
};
|
||||
|
||||
struct fs_enet_private {
|
||||
struct device *dev; /* pointer back to the device (must be initialized first) */
|
||||
spinlock_t lock; /* during all ops except TX pckt processing */
|
||||
spinlock_t tx_lock; /* during fs_start_xmit and fs_tx */
|
||||
const struct fs_platform_info *fpi;
|
||||
const struct fs_ops *ops;
|
||||
int rx_ring, tx_ring;
|
||||
dma_addr_t ring_mem_addr;
|
||||
void *ring_base;
|
||||
struct sk_buff **rx_skbuff;
|
||||
struct sk_buff **tx_skbuff;
|
||||
cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
|
||||
cbd_t *tx_bd_base;
|
||||
cbd_t *dirty_tx; /* ring entries to be free()ed. */
|
||||
cbd_t *cur_rx;
|
||||
cbd_t *cur_tx;
|
||||
int tx_free;
|
||||
struct net_device_stats stats;
|
||||
struct timer_list phy_timer_list;
|
||||
const struct phy_info *phy;
|
||||
u32 msg_enable;
|
||||
struct mii_if_info mii_if;
|
||||
unsigned int last_mii_status;
|
||||
struct fs_enet_mii_bus *mii_bus;
|
||||
int interrupt;
|
||||
|
||||
struct phy_device *phydev;
|
||||
int oldduplex, oldspeed, oldlink; /* current settings */
|
||||
|
||||
/* event masks */
|
||||
u32 ev_napi_rx; /* mask of NAPI rx events */
|
||||
u32 ev_rx; /* rx event mask */
|
||||
u32 ev_tx; /* tx event mask */
|
||||
u32 ev_err; /* error event mask */
|
||||
|
||||
u16 bd_rx_empty; /* mask of BD rx empty */
|
||||
u16 bd_rx_err; /* mask of BD rx errors */
|
||||
|
||||
union {
|
||||
struct {
|
||||
int idx; /* FEC1 = 0, FEC2 = 1 */
|
||||
void *fecp; /* hw registers */
|
||||
u32 hthi, htlo; /* state for multicast */
|
||||
} fec;
|
||||
|
||||
struct {
|
||||
int idx; /* FCC1-3 = 0-2 */
|
||||
void *fccp; /* hw registers */
|
||||
void *ep; /* parameter ram */
|
||||
void *fcccp; /* hw registers cont. */
|
||||
void *mem; /* FCC DPRAM */
|
||||
u32 gaddrh, gaddrl; /* group address */
|
||||
} fcc;
|
||||
|
||||
struct {
|
||||
int idx; /* FEC1 = 0, FEC2 = 1 */
|
||||
void *sccp; /* hw registers */
|
||||
void *ep; /* parameter ram */
|
||||
u32 hthi, htlo; /* state for multicast */
|
||||
} scc;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
int fs_enet_mdio_bb_init(void);
|
||||
int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
|
||||
int fs_enet_mdio_fec_init(void);
|
||||
|
||||
void fs_init_bds(struct net_device *dev);
|
||||
void fs_cleanup_bds(struct net_device *dev);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define DRV_MODULE_NAME "fs_enet"
|
||||
#define PFX DRV_MODULE_NAME ": "
|
||||
#define DRV_MODULE_VERSION "1.0"
|
||||
#define DRV_MODULE_RELDATE "Aug 8, 2005"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int fs_enet_platform_init(void);
|
||||
void fs_enet_platform_cleanup(void);
|
||||
|
||||
/***************************************************************************/
|
||||
/* buffer descriptor access macros */
|
||||
|
||||
/* access macros */
|
||||
#if defined(CONFIG_CPM1)
|
||||
/* for a a CPM1 __raw_xxx's are sufficient */
|
||||
#define __cbd_out32(addr, x) __raw_writel(x, addr)
|
||||
#define __cbd_out16(addr, x) __raw_writew(x, addr)
|
||||
#define __cbd_in32(addr) __raw_readl(addr)
|
||||
#define __cbd_in16(addr) __raw_readw(addr)
|
||||
#else
|
||||
/* for others play it safe */
|
||||
#define __cbd_out32(addr, x) out_be32(addr, x)
|
||||
#define __cbd_out16(addr, x) out_be16(addr, x)
|
||||
#define __cbd_in32(addr) in_be32(addr)
|
||||
#define __cbd_in16(addr) in_be16(addr)
|
||||
#endif
|
||||
|
||||
/* write */
|
||||
#define CBDW_SC(_cbd, _sc) __cbd_out16(&(_cbd)->cbd_sc, (_sc))
|
||||
#define CBDW_DATLEN(_cbd, _datlen) __cbd_out16(&(_cbd)->cbd_datlen, (_datlen))
|
||||
#define CBDW_BUFADDR(_cbd, _bufaddr) __cbd_out32(&(_cbd)->cbd_bufaddr, (_bufaddr))
|
||||
|
||||
/* read */
|
||||
#define CBDR_SC(_cbd) __cbd_in16(&(_cbd)->cbd_sc)
|
||||
#define CBDR_DATLEN(_cbd) __cbd_in16(&(_cbd)->cbd_datlen)
|
||||
#define CBDR_BUFADDR(_cbd) __cbd_in32(&(_cbd)->cbd_bufaddr)
|
||||
|
||||
/* set bits */
|
||||
#define CBDS_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) | (_sc))
|
||||
|
||||
/* clear bits */
|
||||
#define CBDC_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) & ~(_sc))
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
extern const struct fs_ops fs_fec_ops;
|
||||
extern const struct fs_ops fs_fcc_ops;
|
||||
extern const struct fs_ops fs_scc_ops;
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
/* handy pointer to the immap */
|
||||
extern void *fs_enet_immap;
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
#endif
|
||||
591
drivers/net/fs_enet/mac-fcc.c
Normal file
591
drivers/net/fs_enet/mac-fcc.c
Normal file
@@ -0,0 +1,591 @@
|
||||
/*
|
||||
* FCC driver for Motorola MPC82xx (PQ2).
|
||||
*
|
||||
* Copyright (c) 2003 Intracom S.A.
|
||||
* by Pantelis Antoniou <panto@intracom.gr>
|
||||
*
|
||||
* 2005 (c) MontaVista Software, Inc.
|
||||
* Vitaly Bordug <vbordug@ru.mvista.com>
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public License
|
||||
* version 2. This program is licensed "as is" without any warranty of any
|
||||
* kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/ptrace.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/mii.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/phy.h>
|
||||
|
||||
#include <asm/immap_cpm2.h>
|
||||
#include <asm/mpc8260.h>
|
||||
#include <asm/cpm2.h>
|
||||
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/irq.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "fs_enet.h"
|
||||
|
||||
/*************************************************/
|
||||
|
||||
/* FCC access macros */
|
||||
|
||||
#define __fcc_out32(addr, x) out_be32((unsigned *)addr, x)
|
||||
#define __fcc_out16(addr, x) out_be16((unsigned short *)addr, x)
|
||||
#define __fcc_out8(addr, x) out_8((unsigned char *)addr, x)
|
||||
#define __fcc_in32(addr) in_be32((unsigned *)addr)
|
||||
#define __fcc_in16(addr) in_be16((unsigned short *)addr)
|
||||
#define __fcc_in8(addr) in_8((unsigned char *)addr)
|
||||
|
||||
/* parameter space */
|
||||
|
||||
/* write, read, set bits, clear bits */
|
||||
#define W32(_p, _m, _v) __fcc_out32(&(_p)->_m, (_v))
|
||||
#define R32(_p, _m) __fcc_in32(&(_p)->_m)
|
||||
#define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
|
||||
#define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
|
||||
|
||||
#define W16(_p, _m, _v) __fcc_out16(&(_p)->_m, (_v))
|
||||
#define R16(_p, _m) __fcc_in16(&(_p)->_m)
|
||||
#define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
|
||||
#define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
|
||||
|
||||
#define W8(_p, _m, _v) __fcc_out8(&(_p)->_m, (_v))
|
||||
#define R8(_p, _m) __fcc_in8(&(_p)->_m)
|
||||
#define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
|
||||
#define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
|
||||
|
||||
/*************************************************/
|
||||
|
||||
#define FCC_MAX_MULTICAST_ADDRS 64
|
||||
|
||||
#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
|
||||
#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
|
||||
#define mk_mii_end 0
|
||||
|
||||
#define MAX_CR_CMD_LOOPS 10000
|
||||
|
||||
static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 mcn, u32 op)
|
||||
{
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
cpm2_map_t *immap = fs_enet_immap;
|
||||
cpm_cpm2_t *cpmp = &immap->im_cpm;
|
||||
u32 v;
|
||||
int i;
|
||||
|
||||
/* Currently I don't know what feature call will look like. But
|
||||
I guess there'd be something like do_cpm_cmd() which will require page & sblock */
|
||||
v = mk_cr_cmd(fpi->cp_page, fpi->cp_block, mcn, op);
|
||||
W32(cpmp, cp_cpcr, v | CPM_CR_FLG);
|
||||
for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
|
||||
if ((R32(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
|
||||
break;
|
||||
|
||||
if (i >= MAX_CR_CMD_LOOPS) {
|
||||
printk(KERN_ERR "%s(): Not able to issue CPM command\n",
|
||||
__FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_pd_setup(struct fs_enet_private *fep)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(fep->dev);
|
||||
struct resource *r;
|
||||
|
||||
/* Fill out IRQ field */
|
||||
fep->interrupt = platform_get_irq(pdev, 0);
|
||||
if (fep->interrupt < 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Attach the memory for the FCC Parameter RAM */
|
||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram");
|
||||
fep->fcc.ep = (void *)ioremap(r->start, r->end - r->start + 1);
|
||||
if (fep->fcc.ep == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs");
|
||||
fep->fcc.fccp = (void *)ioremap(r->start, r->end - r->start + 1);
|
||||
if (fep->fcc.fccp == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
if (fep->fpi->fcc_regs_c) {
|
||||
|
||||
fep->fcc.fcccp = (void *)fep->fpi->fcc_regs_c;
|
||||
} else {
|
||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
||||
"fcc_regs_c");
|
||||
fep->fcc.fcccp = (void *)ioremap(r->start,
|
||||
r->end - r->start + 1);
|
||||
}
|
||||
|
||||
if (fep->fcc.fcccp == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
fep->fcc.mem = (void *)fep->fpi->mem_offset;
|
||||
if (fep->fcc.mem == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FCC_NAPI_RX_EVENT_MSK (FCC_ENET_RXF | FCC_ENET_RXB)
|
||||
#define FCC_RX_EVENT (FCC_ENET_RXF)
|
||||
#define FCC_TX_EVENT (FCC_ENET_TXB)
|
||||
#define FCC_ERR_EVENT_MSK (FCC_ENET_TXE | FCC_ENET_BSY)
|
||||
|
||||
static int setup_data(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
fep->fcc.idx = fs_get_fcc_index(fpi->fs_no);
|
||||
if ((unsigned int)fep->fcc.idx >= 3) /* max 3 FCCs */
|
||||
return -EINVAL;
|
||||
|
||||
if (do_pd_setup(fep) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
fep->ev_napi_rx = FCC_NAPI_RX_EVENT_MSK;
|
||||
fep->ev_rx = FCC_RX_EVENT;
|
||||
fep->ev_tx = FCC_TX_EVENT;
|
||||
fep->ev_err = FCC_ERR_EVENT_MSK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int allocate_bd(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
fep->ring_base = dma_alloc_coherent(fep->dev,
|
||||
(fpi->tx_ring + fpi->rx_ring) *
|
||||
sizeof(cbd_t), &fep->ring_mem_addr,
|
||||
GFP_KERNEL);
|
||||
if (fep->ring_base == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_bd(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
if (fep->ring_base)
|
||||
dma_free_coherent(fep->dev,
|
||||
(fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t),
|
||||
fep->ring_base, fep->ring_mem_addr);
|
||||
}
|
||||
|
||||
static void cleanup_data(struct net_device *dev)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void set_promiscuous_mode(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
S32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
|
||||
}
|
||||
|
||||
static void set_multicast_start(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_enet_t *ep = fep->fcc.ep;
|
||||
|
||||
W32(ep, fen_gaddrh, 0);
|
||||
W32(ep, fen_gaddrl, 0);
|
||||
}
|
||||
|
||||
static void set_multicast_one(struct net_device *dev, const u8 *mac)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_enet_t *ep = fep->fcc.ep;
|
||||
u16 taddrh, taddrm, taddrl;
|
||||
|
||||
taddrh = ((u16)mac[5] << 8) | mac[4];
|
||||
taddrm = ((u16)mac[3] << 8) | mac[2];
|
||||
taddrl = ((u16)mac[1] << 8) | mac[0];
|
||||
|
||||
W16(ep, fen_taddrh, taddrh);
|
||||
W16(ep, fen_taddrm, taddrm);
|
||||
W16(ep, fen_taddrl, taddrl);
|
||||
fcc_cr_cmd(fep, 0x0C, CPM_CR_SET_GADDR);
|
||||
}
|
||||
|
||||
static void set_multicast_finish(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
fcc_enet_t *ep = fep->fcc.ep;
|
||||
|
||||
/* clear promiscuous always */
|
||||
C32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
|
||||
|
||||
/* if all multi or too many multicasts; just enable all */
|
||||
if ((dev->flags & IFF_ALLMULTI) != 0 ||
|
||||
dev->mc_count > FCC_MAX_MULTICAST_ADDRS) {
|
||||
|
||||
W32(ep, fen_gaddrh, 0xffffffff);
|
||||
W32(ep, fen_gaddrl, 0xffffffff);
|
||||
}
|
||||
|
||||
/* read back */
|
||||
fep->fcc.gaddrh = R32(ep, fen_gaddrh);
|
||||
fep->fcc.gaddrl = R32(ep, fen_gaddrl);
|
||||
}
|
||||
|
||||
static void set_multicast_list(struct net_device *dev)
|
||||
{
|
||||
struct dev_mc_list *pmc;
|
||||
|
||||
if ((dev->flags & IFF_PROMISC) == 0) {
|
||||
set_multicast_start(dev);
|
||||
for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
|
||||
set_multicast_one(dev, pmc->dmi_addr);
|
||||
set_multicast_finish(dev);
|
||||
} else
|
||||
set_promiscuous_mode(dev);
|
||||
}
|
||||
|
||||
static void restart(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
fcc_c_t *fcccp = fep->fcc.fcccp;
|
||||
fcc_enet_t *ep = fep->fcc.ep;
|
||||
dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
|
||||
u16 paddrh, paddrm, paddrl;
|
||||
u16 mem_addr;
|
||||
const unsigned char *mac;
|
||||
int i;
|
||||
|
||||
C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
|
||||
|
||||
/* clear everything (slow & steady does it) */
|
||||
for (i = 0; i < sizeof(*ep); i++)
|
||||
__fcc_out8((char *)ep + i, 0);
|
||||
|
||||
/* get physical address */
|
||||
rx_bd_base_phys = fep->ring_mem_addr;
|
||||
tx_bd_base_phys = rx_bd_base_phys + sizeof(cbd_t) * fpi->rx_ring;
|
||||
|
||||
/* point to bds */
|
||||
W32(ep, fen_genfcc.fcc_rbase, rx_bd_base_phys);
|
||||
W32(ep, fen_genfcc.fcc_tbase, tx_bd_base_phys);
|
||||
|
||||
/* Set maximum bytes per receive buffer.
|
||||
* It must be a multiple of 32.
|
||||
*/
|
||||
W16(ep, fen_genfcc.fcc_mrblr, PKT_MAXBLR_SIZE);
|
||||
|
||||
W32(ep, fen_genfcc.fcc_rstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
|
||||
W32(ep, fen_genfcc.fcc_tstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
|
||||
|
||||
/* Allocate space in the reserved FCC area of DPRAM for the
|
||||
* internal buffers. No one uses this space (yet), so we
|
||||
* can do this. Later, we will add resource management for
|
||||
* this area.
|
||||
*/
|
||||
|
||||
mem_addr = (u32) fep->fcc.mem; /* de-fixup dpram offset */
|
||||
|
||||
W16(ep, fen_genfcc.fcc_riptr, (mem_addr & 0xffff));
|
||||
W16(ep, fen_genfcc.fcc_tiptr, ((mem_addr + 32) & 0xffff));
|
||||
W16(ep, fen_padptr, mem_addr + 64);
|
||||
|
||||
/* fill with special symbol... */
|
||||
memset(fep->fcc.mem + fpi->dpram_offset + 64, 0x88, 32);
|
||||
|
||||
W32(ep, fen_genfcc.fcc_rbptr, 0);
|
||||
W32(ep, fen_genfcc.fcc_tbptr, 0);
|
||||
W32(ep, fen_genfcc.fcc_rcrc, 0);
|
||||
W32(ep, fen_genfcc.fcc_tcrc, 0);
|
||||
W16(ep, fen_genfcc.fcc_res1, 0);
|
||||
W32(ep, fen_genfcc.fcc_res2, 0);
|
||||
|
||||
/* no CAM */
|
||||
W32(ep, fen_camptr, 0);
|
||||
|
||||
/* Set CRC preset and mask */
|
||||
W32(ep, fen_cmask, 0xdebb20e3);
|
||||
W32(ep, fen_cpres, 0xffffffff);
|
||||
|
||||
W32(ep, fen_crcec, 0); /* CRC Error counter */
|
||||
W32(ep, fen_alec, 0); /* alignment error counter */
|
||||
W32(ep, fen_disfc, 0); /* discard frame counter */
|
||||
W16(ep, fen_retlim, 15); /* Retry limit threshold */
|
||||
W16(ep, fen_pper, 0); /* Normal persistence */
|
||||
|
||||
/* set group address */
|
||||
W32(ep, fen_gaddrh, fep->fcc.gaddrh);
|
||||
W32(ep, fen_gaddrl, fep->fcc.gaddrh);
|
||||
|
||||
/* Clear hash filter tables */
|
||||
W32(ep, fen_iaddrh, 0);
|
||||
W32(ep, fen_iaddrl, 0);
|
||||
|
||||
/* Clear the Out-of-sequence TxBD */
|
||||
W16(ep, fen_tfcstat, 0);
|
||||
W16(ep, fen_tfclen, 0);
|
||||
W32(ep, fen_tfcptr, 0);
|
||||
|
||||
W16(ep, fen_mflr, PKT_MAXBUF_SIZE); /* maximum frame length register */
|
||||
W16(ep, fen_minflr, PKT_MINBUF_SIZE); /* minimum frame length register */
|
||||
|
||||
/* set address */
|
||||
mac = dev->dev_addr;
|
||||
paddrh = ((u16)mac[5] << 8) | mac[4];
|
||||
paddrm = ((u16)mac[3] << 8) | mac[2];
|
||||
paddrl = ((u16)mac[1] << 8) | mac[0];
|
||||
|
||||
W16(ep, fen_paddrh, paddrh);
|
||||
W16(ep, fen_paddrm, paddrm);
|
||||
W16(ep, fen_paddrl, paddrl);
|
||||
|
||||
W16(ep, fen_taddrh, 0);
|
||||
W16(ep, fen_taddrm, 0);
|
||||
W16(ep, fen_taddrl, 0);
|
||||
|
||||
W16(ep, fen_maxd1, 1520); /* maximum DMA1 length */
|
||||
W16(ep, fen_maxd2, 1520); /* maximum DMA2 length */
|
||||
|
||||
/* Clear stat counters, in case we ever enable RMON */
|
||||
W32(ep, fen_octc, 0);
|
||||
W32(ep, fen_colc, 0);
|
||||
W32(ep, fen_broc, 0);
|
||||
W32(ep, fen_mulc, 0);
|
||||
W32(ep, fen_uspc, 0);
|
||||
W32(ep, fen_frgc, 0);
|
||||
W32(ep, fen_ospc, 0);
|
||||
W32(ep, fen_jbrc, 0);
|
||||
W32(ep, fen_p64c, 0);
|
||||
W32(ep, fen_p65c, 0);
|
||||
W32(ep, fen_p128c, 0);
|
||||
W32(ep, fen_p256c, 0);
|
||||
W32(ep, fen_p512c, 0);
|
||||
W32(ep, fen_p1024c, 0);
|
||||
|
||||
W16(ep, fen_rfthr, 0); /* Suggested by manual */
|
||||
W16(ep, fen_rfcnt, 0);
|
||||
W16(ep, fen_cftype, 0);
|
||||
|
||||
fs_init_bds(dev);
|
||||
|
||||
/* adjust to speed (for RMII mode) */
|
||||
if (fpi->use_rmii) {
|
||||
if (fep->phydev->speed == 100)
|
||||
C8(fcccp, fcc_gfemr, 0x20);
|
||||
else
|
||||
S8(fcccp, fcc_gfemr, 0x20);
|
||||
}
|
||||
|
||||
fcc_cr_cmd(fep, 0x0c, CPM_CR_INIT_TRX);
|
||||
|
||||
/* clear events */
|
||||
W16(fccp, fcc_fcce, 0xffff);
|
||||
|
||||
/* Enable interrupts we wish to service */
|
||||
W16(fccp, fcc_fccm, FCC_ENET_TXE | FCC_ENET_RXF | FCC_ENET_TXB);
|
||||
|
||||
/* Set GFMR to enable Ethernet operating mode */
|
||||
W32(fccp, fcc_gfmr, FCC_GFMR_TCI | FCC_GFMR_MODE_ENET);
|
||||
|
||||
/* set sync/delimiters */
|
||||
W16(fccp, fcc_fdsr, 0xd555);
|
||||
|
||||
W32(fccp, fcc_fpsmr, FCC_PSMR_ENCRC);
|
||||
|
||||
if (fpi->use_rmii)
|
||||
S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
|
||||
|
||||
/* adjust to duplex mode */
|
||||
if (fep->phydev->duplex)
|
||||
S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
|
||||
else
|
||||
C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
|
||||
|
||||
S32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
|
||||
}
|
||||
|
||||
static void stop(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
/* stop ethernet */
|
||||
C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
|
||||
|
||||
/* clear events */
|
||||
W16(fccp, fcc_fcce, 0xffff);
|
||||
|
||||
/* clear interrupt mask */
|
||||
W16(fccp, fcc_fccm, 0);
|
||||
|
||||
fs_cleanup_bds(dev);
|
||||
}
|
||||
|
||||
static void pre_request_irq(struct net_device *dev, int irq)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void post_free_irq(struct net_device *dev, int irq)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void napi_clear_rx_event(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
W16(fccp, fcc_fcce, FCC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void napi_enable_rx(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
S16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void napi_disable_rx(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
C16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void rx_bd_done(struct net_device *dev)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void tx_kickstart(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
S32(fccp, fcc_ftodr, 0x80);
|
||||
}
|
||||
|
||||
static u32 get_int_events(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
return (u32)R16(fccp, fcc_fcce);
|
||||
}
|
||||
|
||||
static void clear_int_events(struct net_device *dev, u32 int_events)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
W16(fccp, fcc_fcce, int_events & 0xffff);
|
||||
}
|
||||
|
||||
static void ev_error(struct net_device *dev, u32 int_events)
|
||||
{
|
||||
printk(KERN_WARNING DRV_MODULE_NAME
|
||||
": %s FS_ENET ERROR(s) 0x%x\n", dev->name, int_events);
|
||||
}
|
||||
|
||||
int get_regs(struct net_device *dev, void *p, int *sizep)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
|
||||
if (*sizep < sizeof(fcc_t) + sizeof(fcc_c_t) + sizeof(fcc_enet_t))
|
||||
return -EINVAL;
|
||||
|
||||
memcpy_fromio(p, fep->fcc.fccp, sizeof(fcc_t));
|
||||
p = (char *)p + sizeof(fcc_t);
|
||||
|
||||
memcpy_fromio(p, fep->fcc.fcccp, sizeof(fcc_c_t));
|
||||
p = (char *)p + sizeof(fcc_c_t);
|
||||
|
||||
memcpy_fromio(p, fep->fcc.ep, sizeof(fcc_enet_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_regs_len(struct net_device *dev)
|
||||
{
|
||||
return sizeof(fcc_t) + sizeof(fcc_c_t) + sizeof(fcc_enet_t);
|
||||
}
|
||||
|
||||
/* Some transmit errors cause the transmitter to shut
|
||||
* down. We now issue a restart transmit. Since the
|
||||
* errors close the BD and update the pointers, the restart
|
||||
* _should_ pick up without having to reset any of our
|
||||
* pointers either. Also, To workaround 8260 device erratum
|
||||
* CPM37, we must disable and then re-enable the transmitter
|
||||
* following a Late Collision, Underrun, or Retry Limit error.
|
||||
*/
|
||||
void tx_restart(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fcc_t *fccp = fep->fcc.fccp;
|
||||
|
||||
C32(fccp, fcc_gfmr, FCC_GFMR_ENT);
|
||||
udelay(10);
|
||||
S32(fccp, fcc_gfmr, FCC_GFMR_ENT);
|
||||
|
||||
fcc_cr_cmd(fep, 0x0C, CPM_CR_RESTART_TX);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
const struct fs_ops fs_fcc_ops = {
|
||||
.setup_data = setup_data,
|
||||
.cleanup_data = cleanup_data,
|
||||
.set_multicast_list = set_multicast_list,
|
||||
.restart = restart,
|
||||
.stop = stop,
|
||||
.pre_request_irq = pre_request_irq,
|
||||
.post_free_irq = post_free_irq,
|
||||
.napi_clear_rx_event = napi_clear_rx_event,
|
||||
.napi_enable_rx = napi_enable_rx,
|
||||
.napi_disable_rx = napi_disable_rx,
|
||||
.rx_bd_done = rx_bd_done,
|
||||
.tx_kickstart = tx_kickstart,
|
||||
.get_int_events = get_int_events,
|
||||
.clear_int_events = clear_int_events,
|
||||
.ev_error = ev_error,
|
||||
.get_regs = get_regs,
|
||||
.get_regs_len = get_regs_len,
|
||||
.tx_restart = tx_restart,
|
||||
.allocate_bd = allocate_bd,
|
||||
.free_bd = free_bd,
|
||||
};
|
||||
553
drivers/net/fs_enet/mac-fec.c
Normal file
553
drivers/net/fs_enet/mac-fec.c
Normal file
@@ -0,0 +1,553 @@
|
||||
/*
|
||||
* Freescale Ethernet controllers
|
||||
*
|
||||
* Copyright (c) 2005 Intracom S.A.
|
||||
* by Pantelis Antoniou <panto@intracom.gr>
|
||||
*
|
||||
* 2005 (c) MontaVista Software, Inc.
|
||||
* Vitaly Bordug <vbordug@ru.mvista.com>
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public License
|
||||
* version 2. This program is licensed "as is" without any warranty of any
|
||||
* kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/ptrace.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/mii.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include <asm/irq.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#ifdef CONFIG_8xx
|
||||
#include <asm/8xx_immap.h>
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/mpc8xx.h>
|
||||
#include <asm/commproc.h>
|
||||
#endif
|
||||
|
||||
#include "fs_enet.h"
|
||||
#include "fec.h"
|
||||
|
||||
/*************************************************/
|
||||
|
||||
#if defined(CONFIG_CPM1)
|
||||
/* for a CPM1 __raw_xxx's are sufficient */
|
||||
#define __fs_out32(addr, x) __raw_writel(x, addr)
|
||||
#define __fs_out16(addr, x) __raw_writew(x, addr)
|
||||
#define __fs_in32(addr) __raw_readl(addr)
|
||||
#define __fs_in16(addr) __raw_readw(addr)
|
||||
#else
|
||||
/* for others play it safe */
|
||||
#define __fs_out32(addr, x) out_be32(addr, x)
|
||||
#define __fs_out16(addr, x) out_be16(addr, x)
|
||||
#define __fs_in32(addr) in_be32(addr)
|
||||
#define __fs_in16(addr) in_be16(addr)
|
||||
#endif
|
||||
|
||||
/* write */
|
||||
#define FW(_fecp, _reg, _v) __fs_out32(&(_fecp)->fec_ ## _reg, (_v))
|
||||
|
||||
/* read */
|
||||
#define FR(_fecp, _reg) __fs_in32(&(_fecp)->fec_ ## _reg)
|
||||
|
||||
/* set bits */
|
||||
#define FS(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) | (_v))
|
||||
|
||||
/* clear bits */
|
||||
#define FC(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) & ~(_v))
|
||||
|
||||
/*
|
||||
* Delay to wait for FEC reset command to complete (in us)
|
||||
*/
|
||||
#define FEC_RESET_DELAY 50
|
||||
|
||||
static int whack_reset(fec_t * fecp)
|
||||
{
|
||||
int i;
|
||||
|
||||
FW(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
|
||||
for (i = 0; i < FEC_RESET_DELAY; i++) {
|
||||
if ((FR(fecp, ecntrl) & FEC_ECNTRL_RESET) == 0)
|
||||
return 0; /* OK */
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int do_pd_setup(struct fs_enet_private *fep)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(fep->dev);
|
||||
struct resource *r;
|
||||
|
||||
/* Fill out IRQ field */
|
||||
fep->interrupt = platform_get_irq_byname(pdev,"interrupt");
|
||||
if (fep->interrupt < 0)
|
||||
return -EINVAL;
|
||||
|
||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
|
||||
fep->fec.fecp = ioremap(r->start, r->end - r->start + 1);
|
||||
|
||||
if(fep->fec.fecp == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#define FEC_NAPI_RX_EVENT_MSK (FEC_ENET_RXF | FEC_ENET_RXB)
|
||||
#define FEC_RX_EVENT (FEC_ENET_RXF)
|
||||
#define FEC_TX_EVENT (FEC_ENET_TXF)
|
||||
#define FEC_ERR_EVENT_MSK (FEC_ENET_HBERR | FEC_ENET_BABR | \
|
||||
FEC_ENET_BABT | FEC_ENET_EBERR)
|
||||
|
||||
static int setup_data(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
|
||||
if (do_pd_setup(fep) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
fep->fec.hthi = 0;
|
||||
fep->fec.htlo = 0;
|
||||
|
||||
fep->ev_napi_rx = FEC_NAPI_RX_EVENT_MSK;
|
||||
fep->ev_rx = FEC_RX_EVENT;
|
||||
fep->ev_tx = FEC_TX_EVENT;
|
||||
fep->ev_err = FEC_ERR_EVENT_MSK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int allocate_bd(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
fep->ring_base = dma_alloc_coherent(fep->dev,
|
||||
(fpi->tx_ring + fpi->rx_ring) *
|
||||
sizeof(cbd_t), &fep->ring_mem_addr,
|
||||
GFP_KERNEL);
|
||||
if (fep->ring_base == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_bd(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
if(fep->ring_base)
|
||||
dma_free_coherent(fep->dev, (fpi->tx_ring + fpi->rx_ring)
|
||||
* sizeof(cbd_t),
|
||||
fep->ring_base,
|
||||
fep->ring_mem_addr);
|
||||
}
|
||||
|
||||
static void cleanup_data(struct net_device *dev)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void set_promiscuous_mode(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
FS(fecp, r_cntrl, FEC_RCNTRL_PROM);
|
||||
}
|
||||
|
||||
static void set_multicast_start(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
|
||||
fep->fec.hthi = 0;
|
||||
fep->fec.htlo = 0;
|
||||
}
|
||||
|
||||
static void set_multicast_one(struct net_device *dev, const u8 *mac)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
int temp, hash_index, i, j;
|
||||
u32 crc, csrVal;
|
||||
u8 byte, msb;
|
||||
|
||||
crc = 0xffffffff;
|
||||
for (i = 0; i < 6; i++) {
|
||||
byte = mac[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
msb = crc >> 31;
|
||||
crc <<= 1;
|
||||
if (msb ^ (byte & 0x1))
|
||||
crc ^= FEC_CRC_POLY;
|
||||
byte >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
temp = (crc & 0x3f) >> 1;
|
||||
hash_index = ((temp & 0x01) << 4) |
|
||||
((temp & 0x02) << 2) |
|
||||
((temp & 0x04)) |
|
||||
((temp & 0x08) >> 2) |
|
||||
((temp & 0x10) >> 4);
|
||||
csrVal = 1 << hash_index;
|
||||
if (crc & 1)
|
||||
fep->fec.hthi |= csrVal;
|
||||
else
|
||||
fep->fec.htlo |= csrVal;
|
||||
}
|
||||
|
||||
static void set_multicast_finish(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
/* if all multi or too many multicasts; just enable all */
|
||||
if ((dev->flags & IFF_ALLMULTI) != 0 ||
|
||||
dev->mc_count > FEC_MAX_MULTICAST_ADDRS) {
|
||||
fep->fec.hthi = 0xffffffffU;
|
||||
fep->fec.htlo = 0xffffffffU;
|
||||
}
|
||||
|
||||
FC(fecp, r_cntrl, FEC_RCNTRL_PROM);
|
||||
FW(fecp, hash_table_high, fep->fec.hthi);
|
||||
FW(fecp, hash_table_low, fep->fec.htlo);
|
||||
}
|
||||
|
||||
static void set_multicast_list(struct net_device *dev)
|
||||
{
|
||||
struct dev_mc_list *pmc;
|
||||
|
||||
if ((dev->flags & IFF_PROMISC) == 0) {
|
||||
set_multicast_start(dev);
|
||||
for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
|
||||
set_multicast_one(dev, pmc->dmi_addr);
|
||||
set_multicast_finish(dev);
|
||||
} else
|
||||
set_promiscuous_mode(dev);
|
||||
}
|
||||
|
||||
static void restart(struct net_device *dev)
|
||||
{
|
||||
#ifdef CONFIG_DUET
|
||||
immap_t *immap = fs_enet_immap;
|
||||
u32 cptr;
|
||||
#endif
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
|
||||
int r;
|
||||
u32 addrhi, addrlo;
|
||||
|
||||
struct mii_bus* mii = fep->phydev->bus;
|
||||
struct fec_info* fec_inf = mii->priv;
|
||||
|
||||
r = whack_reset(fep->fec.fecp);
|
||||
if (r != 0)
|
||||
printk(KERN_ERR DRV_MODULE_NAME
|
||||
": %s FEC Reset FAILED!\n", dev->name);
|
||||
/*
|
||||
* Set station address.
|
||||
*/
|
||||
addrhi = ((u32) dev->dev_addr[0] << 24) |
|
||||
((u32) dev->dev_addr[1] << 16) |
|
||||
((u32) dev->dev_addr[2] << 8) |
|
||||
(u32) dev->dev_addr[3];
|
||||
addrlo = ((u32) dev->dev_addr[4] << 24) |
|
||||
((u32) dev->dev_addr[5] << 16);
|
||||
FW(fecp, addr_low, addrhi);
|
||||
FW(fecp, addr_high, addrlo);
|
||||
|
||||
/*
|
||||
* Reset all multicast.
|
||||
*/
|
||||
FW(fecp, hash_table_high, fep->fec.hthi);
|
||||
FW(fecp, hash_table_low, fep->fec.htlo);
|
||||
|
||||
/*
|
||||
* Set maximum receive buffer size.
|
||||
*/
|
||||
FW(fecp, r_buff_size, PKT_MAXBLR_SIZE);
|
||||
FW(fecp, r_hash, PKT_MAXBUF_SIZE);
|
||||
|
||||
/* get physical address */
|
||||
rx_bd_base_phys = fep->ring_mem_addr;
|
||||
tx_bd_base_phys = rx_bd_base_phys + sizeof(cbd_t) * fpi->rx_ring;
|
||||
|
||||
/*
|
||||
* Set receive and transmit descriptor base.
|
||||
*/
|
||||
FW(fecp, r_des_start, rx_bd_base_phys);
|
||||
FW(fecp, x_des_start, tx_bd_base_phys);
|
||||
|
||||
fs_init_bds(dev);
|
||||
|
||||
/*
|
||||
* Enable big endian and don't care about SDMA FC.
|
||||
*/
|
||||
FW(fecp, fun_code, 0x78000000);
|
||||
|
||||
/*
|
||||
* Set MII speed.
|
||||
*/
|
||||
FW(fecp, mii_speed, fec_inf->mii_speed);
|
||||
|
||||
/*
|
||||
* Clear any outstanding interrupt.
|
||||
*/
|
||||
FW(fecp, ievent, 0xffc0);
|
||||
#ifndef CONFIG_PPC_MERGE
|
||||
FW(fecp, ivec, (fep->interrupt / 2) << 29);
|
||||
#else
|
||||
FW(fecp, ivec, (virq_to_hw(fep->interrupt) / 2) << 29);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* adjust to speed (only for DUET & RMII)
|
||||
*/
|
||||
#ifdef CONFIG_DUET
|
||||
if (fpi->use_rmii) {
|
||||
cptr = in_be32(&immap->im_cpm.cp_cptr);
|
||||
switch (fs_get_fec_index(fpi->fs_no)) {
|
||||
case 0:
|
||||
cptr |= 0x100;
|
||||
if (fep->speed == 10)
|
||||
cptr |= 0x0000010;
|
||||
else if (fep->speed == 100)
|
||||
cptr &= ~0x0000010;
|
||||
break;
|
||||
case 1:
|
||||
cptr |= 0x80;
|
||||
if (fep->speed == 10)
|
||||
cptr |= 0x0000008;
|
||||
else if (fep->speed == 100)
|
||||
cptr &= ~0x0000008;
|
||||
break;
|
||||
default:
|
||||
BUG(); /* should never happen */
|
||||
break;
|
||||
}
|
||||
out_be32(&immap->im_cpm.cp_cptr, cptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
FW(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
|
||||
/*
|
||||
* adjust to duplex mode
|
||||
*/
|
||||
if (fep->phydev->duplex) {
|
||||
FC(fecp, r_cntrl, FEC_RCNTRL_DRT);
|
||||
FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
|
||||
} else {
|
||||
FS(fecp, r_cntrl, FEC_RCNTRL_DRT);
|
||||
FC(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD disable */
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable interrupts we wish to service.
|
||||
*/
|
||||
FW(fecp, imask, FEC_ENET_TXF | FEC_ENET_TXB |
|
||||
FEC_ENET_RXF | FEC_ENET_RXB);
|
||||
|
||||
/*
|
||||
* And last, enable the transmit and receive processing.
|
||||
*/
|
||||
FW(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
|
||||
FW(fecp, r_des_active, 0x01000000);
|
||||
}
|
||||
|
||||
static void stop(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
struct fec_info* feci= fep->phydev->bus->priv;
|
||||
|
||||
int i;
|
||||
|
||||
if ((FR(fecp, ecntrl) & FEC_ECNTRL_ETHER_EN) == 0)
|
||||
return; /* already down */
|
||||
|
||||
FW(fecp, x_cntrl, 0x01); /* Graceful transmit stop */
|
||||
for (i = 0; ((FR(fecp, ievent) & 0x10000000) == 0) &&
|
||||
i < FEC_RESET_DELAY; i++)
|
||||
udelay(1);
|
||||
|
||||
if (i == FEC_RESET_DELAY)
|
||||
printk(KERN_WARNING DRV_MODULE_NAME
|
||||
": %s FEC timeout on graceful transmit stop\n",
|
||||
dev->name);
|
||||
/*
|
||||
* Disable FEC. Let only MII interrupts.
|
||||
*/
|
||||
FW(fecp, imask, 0);
|
||||
FC(fecp, ecntrl, FEC_ECNTRL_ETHER_EN);
|
||||
|
||||
fs_cleanup_bds(dev);
|
||||
|
||||
/* shut down FEC1? that's where the mii bus is */
|
||||
if (fpi->has_phy) {
|
||||
FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
|
||||
FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
|
||||
FW(fecp, ievent, FEC_ENET_MII);
|
||||
FW(fecp, mii_speed, feci->mii_speed);
|
||||
}
|
||||
}
|
||||
|
||||
static void pre_request_irq(struct net_device *dev, int irq)
|
||||
{
|
||||
#ifndef CONFIG_PPC_MERGE
|
||||
immap_t *immap = fs_enet_immap;
|
||||
u32 siel;
|
||||
|
||||
/* SIU interrupt */
|
||||
if (irq >= SIU_IRQ0 && irq < SIU_LEVEL7) {
|
||||
|
||||
siel = in_be32(&immap->im_siu_conf.sc_siel);
|
||||
if ((irq & 1) == 0)
|
||||
siel |= (0x80000000 >> irq);
|
||||
else
|
||||
siel &= ~(0x80000000 >> (irq & ~1));
|
||||
out_be32(&immap->im_siu_conf.sc_siel, siel);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void post_free_irq(struct net_device *dev, int irq)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void napi_clear_rx_event(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
FW(fecp, ievent, FEC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void napi_enable_rx(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
FS(fecp, imask, FEC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void napi_disable_rx(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
FC(fecp, imask, FEC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void rx_bd_done(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
FW(fecp, r_des_active, 0x01000000);
|
||||
}
|
||||
|
||||
static void tx_kickstart(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
FW(fecp, x_des_active, 0x01000000);
|
||||
}
|
||||
|
||||
static u32 get_int_events(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
return FR(fecp, ievent) & FR(fecp, imask);
|
||||
}
|
||||
|
||||
static void clear_int_events(struct net_device *dev, u32 int_events)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
fec_t *fecp = fep->fec.fecp;
|
||||
|
||||
FW(fecp, ievent, int_events);
|
||||
}
|
||||
|
||||
static void ev_error(struct net_device *dev, u32 int_events)
|
||||
{
|
||||
printk(KERN_WARNING DRV_MODULE_NAME
|
||||
": %s FEC ERROR(s) 0x%x\n", dev->name, int_events);
|
||||
}
|
||||
|
||||
int get_regs(struct net_device *dev, void *p, int *sizep)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
|
||||
if (*sizep < sizeof(fec_t))
|
||||
return -EINVAL;
|
||||
|
||||
memcpy_fromio(p, fep->fec.fecp, sizeof(fec_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_regs_len(struct net_device *dev)
|
||||
{
|
||||
return sizeof(fec_t);
|
||||
}
|
||||
|
||||
void tx_restart(struct net_device *dev)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
const struct fs_ops fs_fec_ops = {
|
||||
.setup_data = setup_data,
|
||||
.cleanup_data = cleanup_data,
|
||||
.set_multicast_list = set_multicast_list,
|
||||
.restart = restart,
|
||||
.stop = stop,
|
||||
.pre_request_irq = pre_request_irq,
|
||||
.post_free_irq = post_free_irq,
|
||||
.napi_clear_rx_event = napi_clear_rx_event,
|
||||
.napi_enable_rx = napi_enable_rx,
|
||||
.napi_disable_rx = napi_disable_rx,
|
||||
.rx_bd_done = rx_bd_done,
|
||||
.tx_kickstart = tx_kickstart,
|
||||
.get_int_events = get_int_events,
|
||||
.clear_int_events = clear_int_events,
|
||||
.ev_error = ev_error,
|
||||
.get_regs = get_regs,
|
||||
.get_regs_len = get_regs_len,
|
||||
.tx_restart = tx_restart,
|
||||
.allocate_bd = allocate_bd,
|
||||
.free_bd = free_bd,
|
||||
};
|
||||
|
||||
529
drivers/net/fs_enet/mac-scc.c
Normal file
529
drivers/net/fs_enet/mac-scc.c
Normal file
@@ -0,0 +1,529 @@
|
||||
/*
|
||||
* Ethernet on Serial Communications Controller (SCC) driver for Motorola MPC8xx and MPC82xx.
|
||||
*
|
||||
* Copyright (c) 2003 Intracom S.A.
|
||||
* by Pantelis Antoniou <panto@intracom.gr>
|
||||
*
|
||||
* 2005 (c) MontaVista Software, Inc.
|
||||
* Vitaly Bordug <vbordug@ru.mvista.com>
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public License
|
||||
* version 2. This program is licensed "as is" without any warranty of any
|
||||
* kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/ptrace.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/mii.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include <asm/irq.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#ifdef CONFIG_8xx
|
||||
#include <asm/8xx_immap.h>
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/mpc8xx.h>
|
||||
#include <asm/commproc.h>
|
||||
#endif
|
||||
|
||||
#include "fs_enet.h"
|
||||
|
||||
/*************************************************/
|
||||
|
||||
#if defined(CONFIG_CPM1)
|
||||
/* for a 8xx __raw_xxx's are sufficient */
|
||||
#define __fs_out32(addr, x) __raw_writel(x, addr)
|
||||
#define __fs_out16(addr, x) __raw_writew(x, addr)
|
||||
#define __fs_out8(addr, x) __raw_writeb(x, addr)
|
||||
#define __fs_in32(addr) __raw_readl(addr)
|
||||
#define __fs_in16(addr) __raw_readw(addr)
|
||||
#define __fs_in8(addr) __raw_readb(addr)
|
||||
#else
|
||||
/* for others play it safe */
|
||||
#define __fs_out32(addr, x) out_be32(addr, x)
|
||||
#define __fs_out16(addr, x) out_be16(addr, x)
|
||||
#define __fs_in32(addr) in_be32(addr)
|
||||
#define __fs_in16(addr) in_be16(addr)
|
||||
#endif
|
||||
|
||||
/* write, read, set bits, clear bits */
|
||||
#define W32(_p, _m, _v) __fs_out32(&(_p)->_m, (_v))
|
||||
#define R32(_p, _m) __fs_in32(&(_p)->_m)
|
||||
#define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
|
||||
#define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
|
||||
|
||||
#define W16(_p, _m, _v) __fs_out16(&(_p)->_m, (_v))
|
||||
#define R16(_p, _m) __fs_in16(&(_p)->_m)
|
||||
#define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
|
||||
#define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
|
||||
|
||||
#define W8(_p, _m, _v) __fs_out8(&(_p)->_m, (_v))
|
||||
#define R8(_p, _m) __fs_in8(&(_p)->_m)
|
||||
#define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
|
||||
#define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
|
||||
|
||||
#define SCC_MAX_MULTICAST_ADDRS 64
|
||||
|
||||
/*
|
||||
* Delay to wait for SCC reset command to complete (in us)
|
||||
*/
|
||||
#define SCC_RESET_DELAY 50
|
||||
#define MAX_CR_CMD_LOOPS 10000
|
||||
|
||||
static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
|
||||
{
|
||||
cpm8xx_t *cpmp = &((immap_t *)fs_enet_immap)->im_cpm;
|
||||
u32 v, ch;
|
||||
int i = 0;
|
||||
|
||||
ch = fep->scc.idx << 2;
|
||||
v = mk_cr_cmd(ch, op);
|
||||
W16(cpmp, cp_cpcr, v | CPM_CR_FLG);
|
||||
for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
|
||||
if ((R16(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
|
||||
break;
|
||||
|
||||
if (i >= MAX_CR_CMD_LOOPS) {
|
||||
printk(KERN_ERR "%s(): Not able to issue CPM command\n",
|
||||
__FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_pd_setup(struct fs_enet_private *fep)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(fep->dev);
|
||||
struct resource *r;
|
||||
|
||||
/* Fill out IRQ field */
|
||||
fep->interrupt = platform_get_irq_byname(pdev, "interrupt");
|
||||
if (fep->interrupt < 0)
|
||||
return -EINVAL;
|
||||
|
||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
|
||||
fep->scc.sccp = ioremap(r->start, r->end - r->start + 1);
|
||||
|
||||
if (fep->scc.sccp == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram");
|
||||
fep->scc.ep = ioremap(r->start, r->end - r->start + 1);
|
||||
|
||||
if (fep->scc.ep == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SCC_NAPI_RX_EVENT_MSK (SCCE_ENET_RXF | SCCE_ENET_RXB)
|
||||
#define SCC_RX_EVENT (SCCE_ENET_RXF)
|
||||
#define SCC_TX_EVENT (SCCE_ENET_TXB)
|
||||
#define SCC_ERR_EVENT_MSK (SCCE_ENET_TXE | SCCE_ENET_BSY)
|
||||
|
||||
static int setup_data(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
fep->scc.idx = fs_get_scc_index(fpi->fs_no);
|
||||
if ((unsigned int)fep->fcc.idx > 4) /* max 4 SCCs */
|
||||
return -EINVAL;
|
||||
|
||||
do_pd_setup(fep);
|
||||
|
||||
fep->scc.hthi = 0;
|
||||
fep->scc.htlo = 0;
|
||||
|
||||
fep->ev_napi_rx = SCC_NAPI_RX_EVENT_MSK;
|
||||
fep->ev_rx = SCC_RX_EVENT;
|
||||
fep->ev_tx = SCC_TX_EVENT;
|
||||
fep->ev_err = SCC_ERR_EVENT_MSK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int allocate_bd(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
|
||||
fep->ring_mem_addr = cpm_dpalloc((fpi->tx_ring + fpi->rx_ring) *
|
||||
sizeof(cbd_t), 8);
|
||||
if (IS_DPERR(fep->ring_mem_addr))
|
||||
return -ENOMEM;
|
||||
|
||||
fep->ring_base = cpm_dpram_addr(fep->ring_mem_addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_bd(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
|
||||
if (fep->ring_base)
|
||||
cpm_dpfree(fep->ring_mem_addr);
|
||||
}
|
||||
|
||||
static void cleanup_data(struct net_device *dev)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void set_promiscuous_mode(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
|
||||
S16(sccp, scc_psmr, SCC_PSMR_PRO);
|
||||
}
|
||||
|
||||
static void set_multicast_start(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_enet_t *ep = fep->scc.ep;
|
||||
|
||||
W16(ep, sen_gaddr1, 0);
|
||||
W16(ep, sen_gaddr2, 0);
|
||||
W16(ep, sen_gaddr3, 0);
|
||||
W16(ep, sen_gaddr4, 0);
|
||||
}
|
||||
|
||||
static void set_multicast_one(struct net_device *dev, const u8 * mac)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_enet_t *ep = fep->scc.ep;
|
||||
u16 taddrh, taddrm, taddrl;
|
||||
|
||||
taddrh = ((u16) mac[5] << 8) | mac[4];
|
||||
taddrm = ((u16) mac[3] << 8) | mac[2];
|
||||
taddrl = ((u16) mac[1] << 8) | mac[0];
|
||||
|
||||
W16(ep, sen_taddrh, taddrh);
|
||||
W16(ep, sen_taddrm, taddrm);
|
||||
W16(ep, sen_taddrl, taddrl);
|
||||
scc_cr_cmd(fep, CPM_CR_SET_GADDR);
|
||||
}
|
||||
|
||||
static void set_multicast_finish(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
scc_enet_t *ep = fep->scc.ep;
|
||||
|
||||
/* clear promiscuous always */
|
||||
C16(sccp, scc_psmr, SCC_PSMR_PRO);
|
||||
|
||||
/* if all multi or too many multicasts; just enable all */
|
||||
if ((dev->flags & IFF_ALLMULTI) != 0 ||
|
||||
dev->mc_count > SCC_MAX_MULTICAST_ADDRS) {
|
||||
|
||||
W16(ep, sen_gaddr1, 0xffff);
|
||||
W16(ep, sen_gaddr2, 0xffff);
|
||||
W16(ep, sen_gaddr3, 0xffff);
|
||||
W16(ep, sen_gaddr4, 0xffff);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_multicast_list(struct net_device *dev)
|
||||
{
|
||||
struct dev_mc_list *pmc;
|
||||
|
||||
if ((dev->flags & IFF_PROMISC) == 0) {
|
||||
set_multicast_start(dev);
|
||||
for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
|
||||
set_multicast_one(dev, pmc->dmi_addr);
|
||||
set_multicast_finish(dev);
|
||||
} else
|
||||
set_promiscuous_mode(dev);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called to start or restart the FEC during a link
|
||||
* change. This only happens when switching between half and full
|
||||
* duplex.
|
||||
*/
|
||||
static void restart(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
scc_enet_t *ep = fep->scc.ep;
|
||||
const struct fs_platform_info *fpi = fep->fpi;
|
||||
u16 paddrh, paddrm, paddrl;
|
||||
const unsigned char *mac;
|
||||
int i;
|
||||
|
||||
C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
|
||||
|
||||
/* clear everything (slow & steady does it) */
|
||||
for (i = 0; i < sizeof(*ep); i++)
|
||||
__fs_out8((char *)ep + i, 0);
|
||||
|
||||
/* point to bds */
|
||||
W16(ep, sen_genscc.scc_rbase, fep->ring_mem_addr);
|
||||
W16(ep, sen_genscc.scc_tbase,
|
||||
fep->ring_mem_addr + sizeof(cbd_t) * fpi->rx_ring);
|
||||
|
||||
/* Initialize function code registers for big-endian.
|
||||
*/
|
||||
W8(ep, sen_genscc.scc_rfcr, SCC_EB);
|
||||
W8(ep, sen_genscc.scc_tfcr, SCC_EB);
|
||||
|
||||
/* Set maximum bytes per receive buffer.
|
||||
* This appears to be an Ethernet frame size, not the buffer
|
||||
* fragment size. It must be a multiple of four.
|
||||
*/
|
||||
W16(ep, sen_genscc.scc_mrblr, 0x5f0);
|
||||
|
||||
/* Set CRC preset and mask.
|
||||
*/
|
||||
W32(ep, sen_cpres, 0xffffffff);
|
||||
W32(ep, sen_cmask, 0xdebb20e3);
|
||||
|
||||
W32(ep, sen_crcec, 0); /* CRC Error counter */
|
||||
W32(ep, sen_alec, 0); /* alignment error counter */
|
||||
W32(ep, sen_disfc, 0); /* discard frame counter */
|
||||
|
||||
W16(ep, sen_pads, 0x8888); /* Tx short frame pad character */
|
||||
W16(ep, sen_retlim, 15); /* Retry limit threshold */
|
||||
|
||||
W16(ep, sen_maxflr, 0x5ee); /* maximum frame length register */
|
||||
|
||||
W16(ep, sen_minflr, PKT_MINBUF_SIZE); /* minimum frame length register */
|
||||
|
||||
W16(ep, sen_maxd1, 0x000005f0); /* maximum DMA1 length */
|
||||
W16(ep, sen_maxd2, 0x000005f0); /* maximum DMA2 length */
|
||||
|
||||
/* Clear hash tables.
|
||||
*/
|
||||
W16(ep, sen_gaddr1, 0);
|
||||
W16(ep, sen_gaddr2, 0);
|
||||
W16(ep, sen_gaddr3, 0);
|
||||
W16(ep, sen_gaddr4, 0);
|
||||
W16(ep, sen_iaddr1, 0);
|
||||
W16(ep, sen_iaddr2, 0);
|
||||
W16(ep, sen_iaddr3, 0);
|
||||
W16(ep, sen_iaddr4, 0);
|
||||
|
||||
/* set address
|
||||
*/
|
||||
mac = dev->dev_addr;
|
||||
paddrh = ((u16) mac[5] << 8) | mac[4];
|
||||
paddrm = ((u16) mac[3] << 8) | mac[2];
|
||||
paddrl = ((u16) mac[1] << 8) | mac[0];
|
||||
|
||||
W16(ep, sen_paddrh, paddrh);
|
||||
W16(ep, sen_paddrm, paddrm);
|
||||
W16(ep, sen_paddrl, paddrl);
|
||||
|
||||
W16(ep, sen_pper, 0);
|
||||
W16(ep, sen_taddrl, 0);
|
||||
W16(ep, sen_taddrm, 0);
|
||||
W16(ep, sen_taddrh, 0);
|
||||
|
||||
fs_init_bds(dev);
|
||||
|
||||
scc_cr_cmd(fep, CPM_CR_INIT_TRX);
|
||||
|
||||
W16(sccp, scc_scce, 0xffff);
|
||||
|
||||
/* Enable interrupts we wish to service.
|
||||
*/
|
||||
W16(sccp, scc_sccm, SCCE_ENET_TXE | SCCE_ENET_RXF | SCCE_ENET_TXB);
|
||||
|
||||
/* Set GSMR_H to enable all normal operating modes.
|
||||
* Set GSMR_L to enable Ethernet to MC68160.
|
||||
*/
|
||||
W32(sccp, scc_gsmrh, 0);
|
||||
W32(sccp, scc_gsmrl,
|
||||
SCC_GSMRL_TCI | SCC_GSMRL_TPL_48 | SCC_GSMRL_TPP_10 |
|
||||
SCC_GSMRL_MODE_ENET);
|
||||
|
||||
/* Set sync/delimiters.
|
||||
*/
|
||||
W16(sccp, scc_dsr, 0xd555);
|
||||
|
||||
/* Set processing mode. Use Ethernet CRC, catch broadcast, and
|
||||
* start frame search 22 bit times after RENA.
|
||||
*/
|
||||
W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22);
|
||||
|
||||
/* Set full duplex mode if needed */
|
||||
if (fep->phydev->duplex)
|
||||
S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE);
|
||||
|
||||
S32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
|
||||
}
|
||||
|
||||
static void stop(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
int i;
|
||||
|
||||
for (i = 0; (R16(sccp, scc_sccm) == 0) && i < SCC_RESET_DELAY; i++)
|
||||
udelay(1);
|
||||
|
||||
if (i == SCC_RESET_DELAY)
|
||||
printk(KERN_WARNING DRV_MODULE_NAME
|
||||
": %s SCC timeout on graceful transmit stop\n",
|
||||
dev->name);
|
||||
|
||||
W16(sccp, scc_sccm, 0);
|
||||
C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
|
||||
|
||||
fs_cleanup_bds(dev);
|
||||
}
|
||||
|
||||
static void pre_request_irq(struct net_device *dev, int irq)
|
||||
{
|
||||
#ifndef CONFIG_PPC_MERGE
|
||||
immap_t *immap = fs_enet_immap;
|
||||
u32 siel;
|
||||
|
||||
/* SIU interrupt */
|
||||
if (irq >= SIU_IRQ0 && irq < SIU_LEVEL7) {
|
||||
|
||||
siel = in_be32(&immap->im_siu_conf.sc_siel);
|
||||
if ((irq & 1) == 0)
|
||||
siel |= (0x80000000 >> irq);
|
||||
else
|
||||
siel &= ~(0x80000000 >> (irq & ~1));
|
||||
out_be32(&immap->im_siu_conf.sc_siel, siel);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void post_free_irq(struct net_device *dev, int irq)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void napi_clear_rx_event(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
|
||||
W16(sccp, scc_scce, SCC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void napi_enable_rx(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
|
||||
S16(sccp, scc_sccm, SCC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void napi_disable_rx(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
|
||||
C16(sccp, scc_sccm, SCC_NAPI_RX_EVENT_MSK);
|
||||
}
|
||||
|
||||
static void rx_bd_done(struct net_device *dev)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void tx_kickstart(struct net_device *dev)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static u32 get_int_events(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
|
||||
return (u32) R16(sccp, scc_scce);
|
||||
}
|
||||
|
||||
static void clear_int_events(struct net_device *dev, u32 int_events)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
scc_t *sccp = fep->scc.sccp;
|
||||
|
||||
W16(sccp, scc_scce, int_events & 0xffff);
|
||||
}
|
||||
|
||||
static void ev_error(struct net_device *dev, u32 int_events)
|
||||
{
|
||||
printk(KERN_WARNING DRV_MODULE_NAME
|
||||
": %s SCC ERROR(s) 0x%x\n", dev->name, int_events);
|
||||
}
|
||||
|
||||
static int get_regs(struct net_device *dev, void *p, int *sizep)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
|
||||
if (*sizep < sizeof(scc_t) + sizeof(scc_enet_t))
|
||||
return -EINVAL;
|
||||
|
||||
memcpy_fromio(p, fep->scc.sccp, sizeof(scc_t));
|
||||
p = (char *)p + sizeof(scc_t);
|
||||
|
||||
memcpy_fromio(p, fep->scc.ep, sizeof(scc_enet_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_regs_len(struct net_device *dev)
|
||||
{
|
||||
return sizeof(scc_t) + sizeof(scc_enet_t);
|
||||
}
|
||||
|
||||
static void tx_restart(struct net_device *dev)
|
||||
{
|
||||
struct fs_enet_private *fep = netdev_priv(dev);
|
||||
|
||||
scc_cr_cmd(fep, CPM_CR_RESTART_TX);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
const struct fs_ops fs_scc_ops = {
|
||||
.setup_data = setup_data,
|
||||
.cleanup_data = cleanup_data,
|
||||
.set_multicast_list = set_multicast_list,
|
||||
.restart = restart,
|
||||
.stop = stop,
|
||||
.pre_request_irq = pre_request_irq,
|
||||
.post_free_irq = post_free_irq,
|
||||
.napi_clear_rx_event = napi_clear_rx_event,
|
||||
.napi_enable_rx = napi_enable_rx,
|
||||
.napi_disable_rx = napi_disable_rx,
|
||||
.rx_bd_done = rx_bd_done,
|
||||
.tx_kickstart = tx_kickstart,
|
||||
.get_int_events = get_int_events,
|
||||
.clear_int_events = clear_int_events,
|
||||
.ev_error = ev_error,
|
||||
.get_regs = get_regs,
|
||||
.get_regs_len = get_regs_len,
|
||||
.tx_restart = tx_restart,
|
||||
.allocate_bd = allocate_bd,
|
||||
.free_bd = free_bd,
|
||||
};
|
||||
407
drivers/net/fs_enet/mii-bitbang.c
Normal file
407
drivers/net/fs_enet/mii-bitbang.c
Normal file
@@ -0,0 +1,407 @@
|
||||
/*
|
||||
* Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
|
||||
*
|
||||
* Copyright (c) 2003 Intracom S.A.
|
||||
* by Pantelis Antoniou <panto@intracom.gr>
|
||||
*
|
||||
* 2005 (c) MontaVista Software, Inc.
|
||||
* Vitaly Bordug <vbordug@ru.mvista.com>
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public License
|
||||
* version 2. This program is licensed "as is" without any warranty of any
|
||||
* kind, whether express or implied.
|
||||
*/
|
||||
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/ptrace.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/mii.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/irq.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "fs_enet.h"
|
||||
|
||||
static int bitbang_prep_bit(u8 **datp, u8 *mskp,
|
||||
struct fs_mii_bit *mii_bit)
|
||||
{
|
||||
void *dat;
|
||||
int adv;
|
||||
u8 msk;
|
||||
|
||||
dat = (void*) mii_bit->offset;
|
||||
|
||||
adv = mii_bit->bit >> 3;
|
||||
dat = (char *)dat + adv;
|
||||
|
||||
msk = 1 << (7 - (mii_bit->bit & 7));
|
||||
|
||||
*datp = dat;
|
||||
*mskp = msk;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void bb_set(u8 *p, u8 m)
|
||||
{
|
||||
out_8(p, in_8(p) | m);
|
||||
}
|
||||
|
||||
static inline void bb_clr(u8 *p, u8 m)
|
||||
{
|
||||
out_8(p, in_8(p) & ~m);
|
||||
}
|
||||
|
||||
static inline int bb_read(u8 *p, u8 m)
|
||||
{
|
||||
return (in_8(p) & m) != 0;
|
||||
}
|
||||
|
||||
static inline void mdio_active(struct bb_info *bitbang)
|
||||
{
|
||||
bb_set(bitbang->mdio_dir, bitbang->mdio_dir_msk);
|
||||
}
|
||||
|
||||
static inline void mdio_tristate(struct bb_info *bitbang )
|
||||
{
|
||||
bb_clr(bitbang->mdio_dir, bitbang->mdio_dir_msk);
|
||||
}
|
||||
|
||||
static inline int mdio_read(struct bb_info *bitbang )
|
||||
{
|
||||
return bb_read(bitbang->mdio_dat, bitbang->mdio_dat_msk);
|
||||
}
|
||||
|
||||
static inline void mdio(struct bb_info *bitbang , int what)
|
||||
{
|
||||
if (what)
|
||||
bb_set(bitbang->mdio_dat, bitbang->mdio_dat_msk);
|
||||
else
|
||||
bb_clr(bitbang->mdio_dat, bitbang->mdio_dat_msk);
|
||||
}
|
||||
|
||||
static inline void mdc(struct bb_info *bitbang , int what)
|
||||
{
|
||||
if (what)
|
||||
bb_set(bitbang->mdc_dat, bitbang->mdc_msk);
|
||||
else
|
||||
bb_clr(bitbang->mdc_dat, bitbang->mdc_msk);
|
||||
}
|
||||
|
||||
static inline void mii_delay(struct bb_info *bitbang )
|
||||
{
|
||||
udelay(bitbang->delay);
|
||||
}
|
||||
|
||||
/* Utility to send the preamble, address, and register (common to read and write). */
|
||||
static void bitbang_pre(struct bb_info *bitbang , int read, u8 addr, u8 reg)
|
||||
{
|
||||
int j;
|
||||
|
||||
/*
|
||||
* Send a 32 bit preamble ('1's) with an extra '1' bit for good measure.
|
||||
* The IEEE spec says this is a PHY optional requirement. The AMD
|
||||
* 79C874 requires one after power up and one after a MII communications
|
||||
* error. This means that we are doing more preambles than we need,
|
||||
* but it is safer and will be much more robust.
|
||||
*/
|
||||
|
||||
mdio_active(bitbang);
|
||||
mdio(bitbang, 1);
|
||||
for (j = 0; j < 32; j++) {
|
||||
mdc(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
}
|
||||
|
||||
/* send the start bit (01) and the read opcode (10) or write (10) */
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, read);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, !read);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
|
||||
/* send the PHY address */
|
||||
for (j = 0; j < 5; j++) {
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, (addr & 0x10) != 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
addr <<= 1;
|
||||
}
|
||||
|
||||
/* send the register address */
|
||||
for (j = 0; j < 5; j++) {
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, (reg & 0x10) != 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
reg <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int fs_enet_mii_bb_read(struct mii_bus *bus , int phy_id, int location)
|
||||
{
|
||||
u16 rdreg;
|
||||
int ret, j;
|
||||
u8 addr = phy_id & 0xff;
|
||||
u8 reg = location & 0xff;
|
||||
struct bb_info* bitbang = bus->priv;
|
||||
|
||||
bitbang_pre(bitbang, 1, addr, reg);
|
||||
|
||||
/* tri-state our MDIO I/O pin so we can read */
|
||||
mdc(bitbang, 0);
|
||||
mdio_tristate(bitbang);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
|
||||
/* check the turnaround bit: the PHY should be driving it to zero */
|
||||
if (mdio_read(bitbang) != 0) {
|
||||
/* PHY didn't drive TA low */
|
||||
for (j = 0; j < 32; j++) {
|
||||
mdc(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
}
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
mdc(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
|
||||
/* read 16 bits of register data, MSB first */
|
||||
rdreg = 0;
|
||||
for (j = 0; j < 16; j++) {
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
rdreg <<= 1;
|
||||
rdreg |= mdio_read(bitbang);
|
||||
mdc(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
}
|
||||
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
|
||||
ret = rdreg;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fs_enet_mii_bb_write(struct mii_bus *bus, int phy_id, int location, u16 val)
|
||||
{
|
||||
int j;
|
||||
struct bb_info* bitbang = bus->priv;
|
||||
|
||||
u8 addr = phy_id & 0xff;
|
||||
u8 reg = location & 0xff;
|
||||
u16 value = val & 0xffff;
|
||||
|
||||
bitbang_pre(bitbang, 0, addr, reg);
|
||||
|
||||
/* send the turnaround (10) */
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
|
||||
/* write 16 bits of register data, MSB first */
|
||||
for (j = 0; j < 16; j++) {
|
||||
mdc(bitbang, 0);
|
||||
mdio(bitbang, (value & 0x8000) != 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
value <<= 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tri-state the MDIO line.
|
||||
*/
|
||||
mdio_tristate(bitbang);
|
||||
mdc(bitbang, 0);
|
||||
mii_delay(bitbang);
|
||||
mdc(bitbang, 1);
|
||||
mii_delay(bitbang);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fs_enet_mii_bb_reset(struct mii_bus *bus)
|
||||
{
|
||||
/*nothing here - dunno how to reset it*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fs_mii_bitbang_init(struct bb_info *bitbang, struct fs_mii_bb_platform_info* fmpi)
|
||||
{
|
||||
int r;
|
||||
|
||||
bitbang->delay = fmpi->delay;
|
||||
|
||||
r = bitbang_prep_bit(&bitbang->mdio_dir,
|
||||
&bitbang->mdio_dir_msk,
|
||||
&fmpi->mdio_dir);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
r = bitbang_prep_bit(&bitbang->mdio_dat,
|
||||
&bitbang->mdio_dat_msk,
|
||||
&fmpi->mdio_dat);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
r = bitbang_prep_bit(&bitbang->mdc_dat,
|
||||
&bitbang->mdc_msk,
|
||||
&fmpi->mdc_dat);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int __devinit fs_enet_mdio_probe(struct device *dev)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(dev);
|
||||
struct fs_mii_bb_platform_info *pdata;
|
||||
struct mii_bus *new_bus;
|
||||
struct bb_info *bitbang;
|
||||
int err = 0;
|
||||
|
||||
if (NULL == dev)
|
||||
return -EINVAL;
|
||||
|
||||
new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
|
||||
|
||||
if (NULL == new_bus)
|
||||
return -ENOMEM;
|
||||
|
||||
bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
|
||||
|
||||
if (NULL == bitbang)
|
||||
return -ENOMEM;
|
||||
|
||||
new_bus->name = "BB MII Bus",
|
||||
new_bus->read = &fs_enet_mii_bb_read,
|
||||
new_bus->write = &fs_enet_mii_bb_write,
|
||||
new_bus->reset = &fs_enet_mii_bb_reset,
|
||||
new_bus->id = pdev->id;
|
||||
|
||||
new_bus->phy_mask = ~0x9;
|
||||
pdata = (struct fs_mii_bb_platform_info *)pdev->dev.platform_data;
|
||||
|
||||
if (NULL == pdata) {
|
||||
printk(KERN_ERR "gfar mdio %d: Missing platform data!\n", pdev->id);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/*set up workspace*/
|
||||
fs_mii_bitbang_init(bitbang, pdata);
|
||||
|
||||
new_bus->priv = bitbang;
|
||||
|
||||
new_bus->irq = pdata->irq;
|
||||
|
||||
new_bus->dev = dev;
|
||||
dev_set_drvdata(dev, new_bus);
|
||||
|
||||
err = mdiobus_register(new_bus);
|
||||
|
||||
if (0 != err) {
|
||||
printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
|
||||
new_bus->name);
|
||||
goto bus_register_fail;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
bus_register_fail:
|
||||
kfree(bitbang);
|
||||
kfree(new_bus);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int fs_enet_mdio_remove(struct device *dev)
|
||||
{
|
||||
struct mii_bus *bus = dev_get_drvdata(dev);
|
||||
|
||||
mdiobus_unregister(bus);
|
||||
|
||||
dev_set_drvdata(dev, NULL);
|
||||
|
||||
iounmap((void *) (&bus->priv));
|
||||
bus->priv = NULL;
|
||||
kfree(bus);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct device_driver fs_enet_bb_mdio_driver = {
|
||||
.name = "fsl-bb-mdio",
|
||||
.bus = &platform_bus_type,
|
||||
.probe = fs_enet_mdio_probe,
|
||||
.remove = fs_enet_mdio_remove,
|
||||
};
|
||||
|
||||
int fs_enet_mdio_bb_init(void)
|
||||
{
|
||||
return driver_register(&fs_enet_bb_mdio_driver);
|
||||
}
|
||||
|
||||
void fs_enet_mdio_bb_exit(void)
|
||||
{
|
||||
driver_unregister(&fs_enet_bb_mdio_driver);
|
||||
}
|
||||
|
||||
240
drivers/net/fs_enet/mii-fec.c
Normal file
240
drivers/net/fs_enet/mii-fec.c
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
|
||||
*
|
||||
* Copyright (c) 2003 Intracom S.A.
|
||||
* by Pantelis Antoniou <panto@intracom.gr>
|
||||
*
|
||||
* 2005 (c) MontaVista Software, Inc.
|
||||
* Vitaly Bordug <vbordug@ru.mvista.com>
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public License
|
||||
* version 2. This program is licensed "as is" without any warranty of any
|
||||
* kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/ptrace.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/mii.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/irq.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "fs_enet.h"
|
||||
#include "fec.h"
|
||||
|
||||
/* Make MII read/write commands for the FEC.
|
||||
*/
|
||||
#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
|
||||
#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
|
||||
#define mk_mii_end 0
|
||||
|
||||
#define FEC_MII_LOOPS 10000
|
||||
|
||||
static int match_has_phy (struct device *dev, void* data)
|
||||
{
|
||||
struct platform_device* pdev = container_of(dev, struct platform_device, dev);
|
||||
struct fs_platform_info* fpi;
|
||||
if(strcmp(pdev->name, (char*)data))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fpi = pdev->dev.platform_data;
|
||||
if((fpi)&&(fpi->has_phy))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fs_mii_fec_init(struct fec_info* fec, struct fs_mii_fec_platform_info *fmpi)
|
||||
{
|
||||
struct resource *r;
|
||||
fec_t *fecp;
|
||||
char* name = "fsl-cpm-fec";
|
||||
|
||||
/* we need fec in order to be useful */
|
||||
struct platform_device *fec_pdev =
|
||||
container_of(bus_find_device(&platform_bus_type, NULL, name, match_has_phy),
|
||||
struct platform_device, dev);
|
||||
|
||||
if(fec_pdev == NULL) {
|
||||
printk(KERN_ERR"Unable to find PHY for %s", name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
r = platform_get_resource_byname(fec_pdev, IORESOURCE_MEM, "regs");
|
||||
|
||||
fec->fecp = fecp = (fec_t*)ioremap(r->start,sizeof(fec_t));
|
||||
fec->mii_speed = fmpi->mii_speed;
|
||||
|
||||
setbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
|
||||
setbits32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
|
||||
out_be32(&fecp->fec_ievent, FEC_ENET_MII);
|
||||
out_be32(&fecp->fec_mii_speed, fec->mii_speed);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fs_enet_fec_mii_read(struct mii_bus *bus , int phy_id, int location)
|
||||
{
|
||||
struct fec_info* fec = bus->priv;
|
||||
fec_t *fecp = fec->fecp;
|
||||
int i, ret = -1;
|
||||
|
||||
if ((in_be32(&fecp->fec_r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
|
||||
BUG();
|
||||
|
||||
/* Add PHY address to register command. */
|
||||
out_be32(&fecp->fec_mii_data, (phy_id << 23) | mk_mii_read(location));
|
||||
|
||||
for (i = 0; i < FEC_MII_LOOPS; i++)
|
||||
if ((in_be32(&fecp->fec_ievent) & FEC_ENET_MII) != 0)
|
||||
break;
|
||||
|
||||
if (i < FEC_MII_LOOPS) {
|
||||
out_be32(&fecp->fec_ievent, FEC_ENET_MII);
|
||||
ret = in_be32(&fecp->fec_mii_data) & 0xffff;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static int fs_enet_fec_mii_write(struct mii_bus *bus, int phy_id, int location, u16 val)
|
||||
{
|
||||
struct fec_info* fec = bus->priv;
|
||||
fec_t *fecp = fec->fecp;
|
||||
int i;
|
||||
|
||||
/* this must never happen */
|
||||
if ((in_be32(&fecp->fec_r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
|
||||
BUG();
|
||||
|
||||
/* Add PHY address to register command. */
|
||||
out_be32(&fecp->fec_mii_data, (phy_id << 23) | mk_mii_write(location, val));
|
||||
|
||||
for (i = 0; i < FEC_MII_LOOPS; i++)
|
||||
if ((in_be32(&fecp->fec_ievent) & FEC_ENET_MII) != 0)
|
||||
break;
|
||||
|
||||
if (i < FEC_MII_LOOPS)
|
||||
out_be32(&fecp->fec_ievent, FEC_ENET_MII);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int fs_enet_fec_mii_reset(struct mii_bus *bus)
|
||||
{
|
||||
/* nothing here - for now */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __devinit fs_enet_fec_mdio_probe(struct device *dev)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(dev);
|
||||
struct fs_mii_fec_platform_info *pdata;
|
||||
struct mii_bus *new_bus;
|
||||
struct fec_info *fec;
|
||||
int err = 0;
|
||||
if (NULL == dev)
|
||||
return -EINVAL;
|
||||
new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
|
||||
|
||||
if (NULL == new_bus)
|
||||
return -ENOMEM;
|
||||
|
||||
fec = kzalloc(sizeof(struct fec_info), GFP_KERNEL);
|
||||
|
||||
if (NULL == fec)
|
||||
return -ENOMEM;
|
||||
|
||||
new_bus->name = "FEC MII Bus",
|
||||
new_bus->read = &fs_enet_fec_mii_read,
|
||||
new_bus->write = &fs_enet_fec_mii_write,
|
||||
new_bus->reset = &fs_enet_fec_mii_reset,
|
||||
new_bus->id = pdev->id;
|
||||
|
||||
pdata = (struct fs_mii_fec_platform_info *)pdev->dev.platform_data;
|
||||
|
||||
if (NULL == pdata) {
|
||||
printk(KERN_ERR "fs_enet FEC mdio %d: Missing platform data!\n", pdev->id);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/*set up workspace*/
|
||||
|
||||
fs_mii_fec_init(fec, pdata);
|
||||
new_bus->priv = fec;
|
||||
|
||||
new_bus->irq = pdata->irq;
|
||||
|
||||
new_bus->dev = dev;
|
||||
dev_set_drvdata(dev, new_bus);
|
||||
|
||||
err = mdiobus_register(new_bus);
|
||||
|
||||
if (0 != err) {
|
||||
printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
|
||||
new_bus->name);
|
||||
goto bus_register_fail;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
bus_register_fail:
|
||||
kfree(new_bus);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int fs_enet_fec_mdio_remove(struct device *dev)
|
||||
{
|
||||
struct mii_bus *bus = dev_get_drvdata(dev);
|
||||
|
||||
mdiobus_unregister(bus);
|
||||
|
||||
dev_set_drvdata(dev, NULL);
|
||||
kfree(bus->priv);
|
||||
|
||||
bus->priv = NULL;
|
||||
kfree(bus);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct device_driver fs_enet_fec_mdio_driver = {
|
||||
.name = "fsl-cpm-fec-mdio",
|
||||
.bus = &platform_bus_type,
|
||||
.probe = fs_enet_fec_mdio_probe,
|
||||
.remove = fs_enet_fec_mdio_remove,
|
||||
};
|
||||
|
||||
int fs_enet_mdio_fec_init(void)
|
||||
{
|
||||
return driver_register(&fs_enet_fec_mdio_driver);
|
||||
}
|
||||
|
||||
void fs_enet_mdio_fec_exit(void)
|
||||
{
|
||||
driver_unregister(&fs_enet_fec_mdio_driver);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user