Lines Matching +full:rx +full:- +full:ctrl

1 // SPDX-License-Identifier: GPL-2.0+
6 * Dante Su <dantesu@faraday-tech.com>
15 #include <asm/dma-mapping.h>
34 * Its DMA engine has a weird restriction that its Rx DMA engine
35 * accepts only 16-bits aligned address, 32-bits aligned is not
42 * 4 bytes aligned: O.K (-> u-boot ZeroCopy is possible)
43 * (2) Rx DMA Buffer Address:
70 struct ftmac110_chip *chip = dev->priv; in mdio_read()
71 struct ftmac110_regs *regs = chip->regs; in mdio_read()
79 writel(tmp, &regs->phycr); in mdio_read()
82 tmp = readl(&regs->phycr); in mdio_read()
99 struct ftmac110_chip *chip = dev->priv; in mdio_write()
100 struct ftmac110_regs *regs = chip->regs; in mdio_write()
107 writel(phydata, &regs->phydr); in mdio_write()
108 writel(tmp, &regs->phycr); in mdio_write()
111 if (readl(&regs->phycr) & PHYCR_WRITE) in mdio_write()
116 if (readl(&regs->phycr) & PHYCR_WRITE) in mdio_write()
125 struct ftmac110_chip *chip = dev->priv; in ftmac110_phyqry()
135 chip->phy_addr = pa; in ftmac110_phyqry()
143 /* 2. wait until link-up & auto-negotiation complete */ in ftmac110_phyqry()
144 chip->lnkup = 0; in ftmac110_phyqry()
145 bmcr = mdio_read(dev, chip->phy_addr, MII_BMCR); in ftmac110_phyqry()
148 bmsr = mdio_read(dev, chip->phy_addr, MII_BMSR); in ftmac110_phyqry()
149 chip->lnkup = (bmsr & BMSR_LSTATUS) ? 1 : 0; in ftmac110_phyqry()
150 if (!chip->lnkup) in ftmac110_phyqry()
155 if (!chip->lnkup) { in ftmac110_phyqry()
166 tmp = mdio_read(dev, chip->phy_addr, MII_ADVERTISE); in ftmac110_phyqry()
167 tmp &= mdio_read(dev, chip->phy_addr, MII_LPA); in ftmac110_phyqry()
168 if (tmp & LPA_100FULL) /* 100Mbps full-duplex */ in ftmac110_phyqry()
170 else if (tmp & LPA_100HALF) /* 100Mbps half-duplex */ in ftmac110_phyqry()
172 else if (tmp & LPA_10FULL) /* 10Mbps full-duplex */ in ftmac110_phyqry()
174 else if (tmp & LPA_10HALF) /* 10Mbps half-duplex */ in ftmac110_phyqry()
196 struct ftmac110_chip *chip = dev->priv; in ftmac110_reset()
197 struct ftmac110_regs *regs = chip->regs; in ftmac110_reset()
200 writel(MACCR_RESET, &regs->maccr); in ftmac110_reset()
202 if (readl(&regs->maccr) & MACCR_RESET) in ftmac110_reset()
206 if (readl(&regs->maccr) & MACCR_RESET) { in ftmac110_reset()
208 return -ENXIO; in ftmac110_reset()
211 /* 1-1. Init tx ring */ in ftmac110_reset()
214 chip->txd[i].ctrl &= cpu_to_le64(FTMAC110_TXD_CLRMASK); in ftmac110_reset()
216 chip->txd_idx = 0; in ftmac110_reset()
218 /* 1-2. Init rx ring */ in ftmac110_reset()
221 chip->rxd[i].ctrl &= cpu_to_le64(FTMAC110_RXD_CLRMASK); in ftmac110_reset()
222 chip->rxd[i].ctrl |= cpu_to_le64(FTMAC110_RXD_OWNER); in ftmac110_reset()
224 chip->rxd_idx = 0; in ftmac110_reset()
230 chip->maccr = maccr | MACCR_CRCAPD | MACCR_RXALL | MACCR_RXRUNT in ftmac110_reset()
234 a = dev->enetaddr; in ftmac110_reset()
235 writel(a[1] | (a[0] << 8), &regs->mac[0]); in ftmac110_reset()
237 | (a[2] << 24), &regs->mac[1]); in ftmac110_reset()
240 writel(chip->rxd_dma, &regs->rxba); in ftmac110_reset()
241 writel(chip->txd_dma, &regs->txba); in ftmac110_reset()
242 /* interrupt at each tx/rx */ in ftmac110_reset()
243 writel(ITC_DEFAULT, &regs->itc); in ftmac110_reset()
244 /* no tx pool, rx poll = 1 normal cycle */ in ftmac110_reset()
245 writel(APTC_DEFAULT, &regs->aptc); in ftmac110_reset()
246 /* rx threshold = [6/8 fifo, 2/8 fifo] */ in ftmac110_reset()
247 writel(DBLAC_DEFAULT, &regs->dblac); in ftmac110_reset()
249 chip->imr = 0; in ftmac110_reset()
250 writel(ISR_ALL, &regs->isr); in ftmac110_reset()
251 writel(chip->imr, &regs->imr); in ftmac110_reset()
253 writel(chip->maccr, &regs->maccr); in ftmac110_reset()
263 return -1; in ftmac110_probe()
270 struct ftmac110_chip *chip = dev->priv; in ftmac110_halt()
271 struct ftmac110_regs *regs = chip->regs; in ftmac110_halt()
273 writel(0, &regs->imr); in ftmac110_halt()
274 writel(0, &regs->maccr); in ftmac110_halt()
281 struct ftmac110_chip *chip = dev->priv; in ftmac110_send()
282 struct ftmac110_regs *regs = chip->regs; in ftmac110_send()
284 uint64_t ctrl; in ftmac110_send() local
286 if (!chip->lnkup) in ftmac110_send()
296 txd = &chip->txd[chip->txd_idx]; in ftmac110_send()
297 ctrl = le64_to_cpu(txd->ctrl); in ftmac110_send()
298 if (ctrl & FTMAC110_TXD_OWNER) { in ftmac110_send()
299 /* kick-off Tx DMA */ in ftmac110_send()
300 writel(0xffffffff, &regs->txpd); in ftmac110_send()
305 memcpy(txd->vbuf, (void *)pkt, len); in ftmac110_send()
306 dma_map_single(txd->vbuf, len, DMA_TO_DEVICE); in ftmac110_send()
309 ctrl &= FTMAC110_TXD_CLRMASK; in ftmac110_send()
311 ctrl |= FTMAC110_TXD_LEN(len) | FTMAC110_TXD_FTS | FTMAC110_TXD_LTS; in ftmac110_send()
313 ctrl |= FTMAC110_TXD_OWNER; in ftmac110_send()
315 txd->ctrl = cpu_to_le64(ctrl); in ftmac110_send()
317 /* kick-off Tx DMA */ in ftmac110_send()
318 writel(0xffffffff, &regs->txpd); in ftmac110_send()
320 chip->txd_idx = (chip->txd_idx + 1) % CFG_TXDES_NUM; in ftmac110_send()
327 struct ftmac110_chip *chip = dev->priv; in ftmac110_recv()
330 uint64_t ctrl; in ftmac110_recv() local
333 if (!chip->lnkup) in ftmac110_recv()
337 rxd = &chip->rxd[chip->rxd_idx]; in ftmac110_recv()
338 ctrl = le64_to_cpu(rxd->ctrl); in ftmac110_recv()
339 if (ctrl & FTMAC110_RXD_OWNER) in ftmac110_recv()
342 len = (uint32_t)FTMAC110_RXD_LEN(ctrl); in ftmac110_recv()
343 buf = rxd->vbuf; in ftmac110_recv()
345 if (ctrl & FTMAC110_RXD_ERRMASK) { in ftmac110_recv()
346 printf("ftmac110: rx error\n"); in ftmac110_recv()
354 ctrl &= FTMAC110_RXD_CLRMASK; in ftmac110_recv()
355 ctrl |= FTMAC110_RXD_OWNER; in ftmac110_recv()
356 rxd->ctrl |= cpu_to_le64(ctrl); in ftmac110_recv()
358 chip->rxd_idx = (chip->rxd_idx + 1) % CFG_RXDES_NUM; in ftmac110_recv()
373 dev = eth_get_dev_by_name(bus->name); in ftmac110_mdio_read()
375 printf("%s: no such device\n", bus->name); in ftmac110_mdio_read()
376 ret = -1; in ftmac110_mdio_read()
392 dev = eth_get_dev_by_name(bus->name); in ftmac110_mdio_write()
394 printf("%s: no such device\n", bus->name); in ftmac110_mdio_write()
395 ret = -1; in ftmac110_mdio_write()
414 return -1; in ftmac110_initialize()
419 sprintf(dev->name, "FTMAC110#%d", card_nr); in ftmac110_initialize()
421 dev->iobase = CONFIG_FTMAC110_BASE; in ftmac110_initialize()
422 chip->regs = (void __iomem *)dev->iobase; in ftmac110_initialize()
423 dev->priv = chip; in ftmac110_initialize()
424 dev->init = ftmac110_probe; in ftmac110_initialize()
425 dev->halt = ftmac110_halt; in ftmac110_initialize()
426 dev->send = ftmac110_send; in ftmac110_initialize()
427 dev->recv = ftmac110_recv; in ftmac110_initialize()
430 chip->txd = dma_alloc_coherent( in ftmac110_initialize()
431 sizeof(struct ftmac110_desc) * CFG_TXDES_NUM, &chip->txd_dma); in ftmac110_initialize()
432 if (!chip->txd) in ftmac110_initialize()
434 memset(chip->txd, 0, in ftmac110_initialize()
441 chip->txd[i].vbuf = va; in ftmac110_initialize()
442 chip->txd[i].pbuf = cpu_to_le32(virt_to_phys(va)); in ftmac110_initialize()
443 chip->txd[i].ctrl = 0; /* owned by SW */ in ftmac110_initialize()
445 chip->txd[i - 1].ctrl |= cpu_to_le64(FTMAC110_TXD_END); in ftmac110_initialize()
446 chip->txd_idx = 0; in ftmac110_initialize()
448 /* allocate rx descriptors (it must be 16 bytes aligned) */ in ftmac110_initialize()
449 chip->rxd = dma_alloc_coherent( in ftmac110_initialize()
450 sizeof(struct ftmac110_desc) * CFG_RXDES_NUM, &chip->rxd_dma); in ftmac110_initialize()
451 if (!chip->rxd) in ftmac110_initialize()
453 memset((void *)chip->rxd, 0, in ftmac110_initialize()
462 chip->rxd[i].vbuf = va; in ftmac110_initialize()
463 chip->rxd[i].pbuf = cpu_to_le32(virt_to_phys(va)); in ftmac110_initialize()
464 chip->rxd[i].ctrl = cpu_to_le64(FTMAC110_RXD_OWNER in ftmac110_initialize()
467 chip->rxd[i - 1].ctrl |= cpu_to_le64(FTMAC110_RXD_END); in ftmac110_initialize()
468 chip->rxd_idx = 0; in ftmac110_initialize()
476 return -ENOMEM; in ftmac110_initialize()
477 strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN); in ftmac110_initialize()
478 mdiodev->read = ftmac110_mdio_read; in ftmac110_initialize()
479 mdiodev->write = ftmac110_mdio_write; in ftmac110_initialize()