📄 mac-fcc.c
字号:
/* * 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/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>#ifdef CONFIG_PPC_CPM_NEW_BINDING#include <asm/of_device.h>#endif#include "fs_enet.h"/*************************************************//* FCC access macros *//* write, read, set bits, clear bits */#define W32(_p, _m, _v) out_be32(&(_p)->_m, (_v))#define R32(_p, _m) in_be32(&(_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) out_be16(&(_p)->_m, (_v))#define R16(_p, _m) in_be16(&(_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) out_8(&(_p)->_m, (_v))#define R8(_p, _m) in_8(&(_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 10000static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op){ const struct fs_platform_info *fpi = fep->fpi; int i; W32(cpmp, cp_cpcr, fpi->cp_command | op | CPM_CR_FLG); for (i = 0; i < MAX_CR_CMD_LOOPS; i++) if ((R32(cpmp, cp_cpcr) & CPM_CR_FLG) == 0) return 0; printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__); return 1;}static int do_pd_setup(struct fs_enet_private *fep){#ifdef CONFIG_PPC_CPM_NEW_BINDING struct of_device *ofdev = to_of_device(fep->dev); struct fs_platform_info *fpi = fep->fpi; int ret = -EINVAL; fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL); if (fep->interrupt == NO_IRQ) goto out; fep->fcc.fccp = of_iomap(ofdev->node, 0); if (!fep->fcc.fccp) goto out; fep->fcc.ep = of_iomap(ofdev->node, 1); if (!fep->fcc.ep) goto out_fccp; fep->fcc.fcccp = of_iomap(ofdev->node, 2); if (!fep->fcc.fcccp) goto out_ep; fep->fcc.mem = (void __iomem *)cpm2_immr; fpi->dpram_offset = cpm_dpalloc(128, 8); if (IS_ERR_VALUE(fpi->dpram_offset)) { ret = fpi->dpram_offset; goto out_fcccp; } return 0;out_fcccp: iounmap(fep->fcc.fcccp);out_ep: iounmap(fep->fcc.ep);out_fccp: iounmap(fep->fcc.fccp);out: return ret;#else 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 = 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 = 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 __iomem *)fep->fpi->fcc_regs_c; } else { r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs_c"); fep->fcc.fcccp = ioremap(r->start, r->end - r->start + 1); } if (fep->fcc.fcccp == NULL) return -EINVAL; fep->fcc.mem = (void __iomem *)fep->fpi->mem_offset; if (fep->fcc.mem == NULL) return -EINVAL; return 0;#endif}#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);#ifndef CONFIG_PPC_CPM_NEW_BINDING struct fs_platform_info *fpi = fep->fpi; fpi->cp_command = (fpi->cp_page << 26) | (fpi->cp_block << 21) | (12 << 6); fep->fcc.idx = fs_get_fcc_index(fpi->fs_no); if ((unsigned int)fep->fcc.idx >= 3) /* max 3 FCCs */ return -EINVAL;#endif 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 = (void __iomem __force *)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), (void __force *)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 __iomem *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 __iomem *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 __iomem *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, CPM_CR_SET_GADDR);}static void set_multicast_finish(struct net_device *dev){ struct fs_enet_private *fep = netdev_priv(dev); fcc_t __iomem *fccp = fep->fcc.fccp; fcc_enet_t __iomem *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 __iomem *fccp = fep->fcc.fccp; fcc_c_t __iomem *fcccp = fep->fcc.fcccp; fcc_enet_t __iomem *ep = fep->fcc.ep; dma_addr_t rx_bd_base_phys, tx_bd_base_phys; u16 paddrh, paddrm, paddrl;#ifndef CONFIG_PPC_CPM_NEW_BINDING
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -