X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=drivers%2Fnet%2Ffec_mxc.c;h=74d36f479ec9b59301cb2002c94e783986c0e564;hb=1bcabd79215ece91ee8f79e768c4886efae182ba;hp=f16b2990d7ce4c56c6a45983cd7c5775bcbe670c;hpb=5619295995e3262bb5770e8b5e945ffdc5442145;p=oweals%2Fu-boot.git diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index f16b2990d7..74d36f479e 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -284,7 +285,7 @@ static int fec_tx_task_disable(struct fec_priv *fec) static void fec_rbd_init(struct fec_priv *fec, int count, int dsize) { uint32_t size; - uint8_t *data; + ulong data; int i; /* @@ -293,9 +294,9 @@ static void fec_rbd_init(struct fec_priv *fec, int count, int dsize) */ size = roundup(dsize, ARCH_DMA_MINALIGN); for (i = 0; i < count; i++) { - data = (uint8_t *)fec->rbd_base[i].data_pointer; - memset(data, 0, dsize); - flush_dcache_range((uint32_t)data, (uint32_t)data + size); + data = fec->rbd_base[i].data_pointer; + memset((void *)data, 0, dsize); + flush_dcache_range(data, data + size); fec->rbd_base[i].status = FEC_RBD_EMPTY; fec->rbd_base[i].data_length = 0; @@ -305,8 +306,8 @@ static void fec_rbd_init(struct fec_priv *fec, int count, int dsize) fec->rbd_base[i - 1].status = FEC_RBD_WRAP | FEC_RBD_EMPTY; fec->rbd_index = 0; - flush_dcache_range((unsigned)fec->rbd_base, - (unsigned)fec->rbd_base + size); + flush_dcache_range((ulong)fec->rbd_base, + (ulong)fec->rbd_base + size); } /** @@ -323,7 +324,7 @@ static void fec_rbd_init(struct fec_priv *fec, int count, int dsize) */ static void fec_tbd_init(struct fec_priv *fec) { - unsigned addr = (unsigned)fec->tbd_base; + ulong addr = (ulong)fec->tbd_base; unsigned size = roundup(2 * sizeof(struct fec_bd), ARCH_DMA_MINALIGN); @@ -423,7 +424,7 @@ static int fec_open(struct eth_device *edev) struct fec_priv *fec = (struct fec_priv *)edev->priv; #endif int speed; - uint32_t addr, size; + ulong addr, size; int i; debug("fec_open: fec_open(dev)\n"); @@ -439,7 +440,7 @@ static int fec_open(struct eth_device *edev) /* Flush the descriptors into RAM */ size = roundup(FEC_RBD_NUM * sizeof(struct fec_bd), ARCH_DMA_MINALIGN); - addr = (uint32_t)fec->rbd_base; + addr = (ulong)fec->rbd_base; flush_dcache_range(addr, addr + size); #ifdef FEC_QUIRK_ENET_MAC @@ -533,8 +534,9 @@ static int fec_init(struct eth_device *dev, bd_t *bd) #else struct fec_priv *fec = (struct fec_priv *)dev->priv; #endif - uint32_t mib_ptr = (uint32_t)&fec->eth->rmon_t_drop; - int i; + u8 *mib_ptr = (uint8_t *)&fec->eth->rmon_t_drop; + u8 *i; + ulong addr; /* Initialize MAC address */ #ifdef CONFIG_DM_ETH @@ -562,8 +564,8 @@ static int fec_init(struct eth_device *dev, bd_t *bd) writel(0x00000000, &fec->eth->gaddr1); writel(0x00000000, &fec->eth->gaddr2); - /* Do not access reserved register for i.MX6UL */ - if (!is_mx6ul() && !is_mx6ull()) { + /* Do not access reserved register */ + if (!is_mx6ul() && !is_mx6ull() && !is_mx8m()) { /* clear MIB RAM */ for (i = mib_ptr; i <= mib_ptr + 0xfc; i += 4) writel(0, i); @@ -574,8 +576,12 @@ static int fec_init(struct eth_device *dev, bd_t *bd) /* size and address of each buffer */ writel(FEC_MAX_PKT_SIZE, &fec->eth->emrbr); - writel((uint32_t)fec->tbd_base, &fec->eth->etdsr); - writel((uint32_t)fec->rbd_base, &fec->eth->erdsr); + + addr = (ulong)fec->tbd_base; + writel((uint32_t)addr, &fec->eth->etdsr); + + addr = (ulong)fec->rbd_base; + writel((uint32_t)addr, &fec->eth->erdsr); #ifndef CONFIG_PHYLIB if (fec->xcv_type != SEVENWIRE) @@ -640,8 +646,8 @@ static int fec_send(struct eth_device *dev, void *packet, int length) #endif { unsigned int status; - uint32_t size, end; - uint32_t addr; + u32 size; + ulong addr, end; int timeout = FEC_XFER_TIMEOUT; int ret = 0; @@ -672,13 +678,13 @@ static int fec_send(struct eth_device *dev, void *packet, int length) swap_packet((uint32_t *)packet, length); #endif - addr = (uint32_t)packet; + addr = (ulong)packet; end = roundup(addr + length, ARCH_DMA_MINALIGN); addr &= ~(ARCH_DMA_MINALIGN - 1); flush_dcache_range(addr, end); writew(length, &fec->tbd_base[fec->tbd_index].data_length); - writel(addr, &fec->tbd_base[fec->tbd_index].data_pointer); + writel((uint32_t)addr, &fec->tbd_base[fec->tbd_index].data_pointer); /* * update BD's status now @@ -698,7 +704,7 @@ static int fec_send(struct eth_device *dev, void *packet, int length) * can start DMA. */ size = roundup(2 * sizeof(struct fec_bd), ARCH_DMA_MINALIGN); - addr = (uint32_t)fec->tbd_base; + addr = (ulong)fec->tbd_base; flush_dcache_range(addr, addr + size); /* @@ -799,9 +805,18 @@ static int fec_recv(struct eth_device *dev) unsigned long ievent; int frame_length, len = 0; uint16_t bd_status; - uint32_t addr, size, end; + ulong addr, size, end; int i; + +#ifdef CONFIG_DM_ETH + *packetp = memalign(ARCH_DMA_MINALIGN, FEC_MAX_PKT_SIZE); + if (*packetp == 0) { + printf("%s: error allocating packetp\n", __func__); + return -ENOMEM; + } +#else ALLOC_CACHE_ALIGN_BUFFER(uchar, buff, FEC_MAX_PKT_SIZE); +#endif /* Check if any critical events have happened */ ievent = readl(&fec->eth->ievent); @@ -854,7 +869,7 @@ static int fec_recv(struct eth_device *dev) * the descriptor. The solution is to mark the whole cache line when all * descriptors in the cache line are processed. */ - addr = (uint32_t)rbd; + addr = (ulong)rbd; addr &= ~(ARCH_DMA_MINALIGN - 1); size = roundup(sizeof(struct fec_bd), ARCH_DMA_MINALIGN); invalidate_dcache_range(addr, addr + size); @@ -877,13 +892,18 @@ static int fec_recv(struct eth_device *dev) #ifdef CONFIG_FEC_MXC_SWAP_PACKET swap_packet((uint32_t *)addr, frame_length); #endif + +#ifdef CONFIG_DM_ETH + memcpy(*packetp, (char *)addr, frame_length); +#else memcpy(buff, (char *)addr, frame_length); net_process_received_packet(buff, frame_length); +#endif len = frame_length; } else { if (bd_status & FEC_RBD_ERR) - printf("error frame: 0x%08x 0x%08x\n", - addr, bd_status); + debug("error frame: 0x%08lx 0x%08x\n", + addr, bd_status); } /* @@ -895,7 +915,7 @@ static int fec_recv(struct eth_device *dev) size = RXDESC_PER_CACHELINE - 1; if ((fec->rbd_index & size) == size) { i = fec->rbd_index - size; - addr = (uint32_t)&fec->rbd_base[i]; + addr = (ulong)&fec->rbd_base[i]; for (; i <= fec->rbd_index ; i++) { fec_rbd_clean(i == (FEC_RBD_NUM - 1), &fec->rbd_base[i]); @@ -922,6 +942,7 @@ static int fec_alloc_descs(struct fec_priv *fec) unsigned int size; int i; uint8_t *data; + ulong addr; /* Allocate TX descriptors. */ size = roundup(2 * sizeof(struct fec_bd), ARCH_DMA_MINALIGN); @@ -950,11 +971,12 @@ static int fec_alloc_descs(struct fec_priv *fec) memset(data, 0, size); - fec->rbd_base[i].data_pointer = (uint32_t)data; + addr = (ulong)data; + fec->rbd_base[i].data_pointer = (uint32_t)addr; fec->rbd_base[i].status = FEC_RBD_EMPTY; fec->rbd_base[i].data_length = 0; /* Flush the buffer to memory. */ - flush_dcache_range((uint32_t)data, (uint32_t)data + size); + flush_dcache_range(addr, addr + size); } /* Mark the last RBD to close the ring. */ @@ -966,8 +988,10 @@ static int fec_alloc_descs(struct fec_priv *fec) return 0; err_ring: - for (; i >= 0; i--) - free((void *)fec->rbd_base[i].data_pointer); + for (; i >= 0; i--) { + addr = fec->rbd_base[i].data_pointer; + free((void *)addr); + } free(fec->rbd_base); err_rx: free(fec->tbd_base); @@ -978,25 +1002,19 @@ err_tx: static void fec_free_descs(struct fec_priv *fec) { int i; + ulong addr; - for (i = 0; i < FEC_RBD_NUM; i++) - free((void *)fec->rbd_base[i].data_pointer); + for (i = 0; i < FEC_RBD_NUM; i++) { + addr = fec->rbd_base[i].data_pointer; + free((void *)addr); + } free(fec->rbd_base); free(fec->tbd_base); } -#ifdef CONFIG_DM_ETH -struct mii_dev *fec_get_miibus(struct udevice *dev, int dev_id) -#else -struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id) -#endif +struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id) { -#ifdef CONFIG_DM_ETH - struct fec_priv *priv = dev_get_priv(dev); - struct ethernet_regs *eth = priv->eth; -#else struct ethernet_regs *eth = (struct ethernet_regs *)base_addr; -#endif struct mii_dev *bus; int ret; @@ -1065,7 +1083,7 @@ static int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr, edev->halt = fec_halt; edev->write_hwaddr = fec_set_hwaddr; - fec->eth = (struct ethernet_regs *)base_addr; + fec->eth = (struct ethernet_regs *)(ulong)base_addr; fec->bd = bd; fec->xcv_type = CONFIG_FEC_XCV_TYPE; @@ -1189,10 +1207,19 @@ static int fecmxc_read_rom_hwaddr(struct udevice *dev) return fec_get_hwaddr(priv->dev_id, pdata->enetaddr); } +static int fecmxc_free_pkt(struct udevice *dev, uchar *packet, int length) +{ + if (packet) + free(packet); + + return 0; +} + static const struct eth_ops fecmxc_ops = { .start = fecmxc_init, .send = fecmxc_send, .recv = fecmxc_recv, + .free_pkt = fecmxc_free_pkt, .stop = fecmxc_halt, .write_hwaddr = fecmxc_set_hwaddr, .read_rom_hwaddr = fecmxc_read_rom_hwaddr, @@ -1247,7 +1274,7 @@ static int fecmxc_probe(struct udevice *dev) fec_reg_setup(priv); priv->dev_id = (dev_id == -1) ? 0 : dev_id; - bus = fec_get_miibus(dev, dev_id); + bus = fec_get_miibus((ulong)priv->eth, dev_id); if (!bus) { ret = -ENOMEM; goto err_mii;