Lines Matching +full:bd +full:- +full:address

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2007-2008 Avionic Design Development GmbH
6 * Copyright (C) 2008-2009 Avionic Design GmbH
7 * Thierry Reding <thierry.reding@avionic-design.de>
49 #define MODER_BRO (1 << 3) /* broadcast address */
50 #define MODER_IAM (1 << 4) /* individual address mode */
54 #define MODER_NBO (1 << 8) /* no back-off */
106 /* MII address register */
168 * struct ethoc - driver-private device structure
192 * struct ethoc_bd - buffer descriptor
194 * @addr: physical memory address
203 return priv->iobase + offset; in ethoc_reg()
217 struct ethoc_bd *bd) in ethoc_read_bd() argument
220 bd->stat = ethoc_read(priv, offset + 0); in ethoc_read_bd()
221 bd->addr = ethoc_read(priv, offset + 4); in ethoc_read_bd()
225 const struct ethoc_bd *bd) in ethoc_write_bd() argument
228 ethoc_write(priv, offset + 0, bd->stat); in ethoc_write_bd()
229 ethoc_write(priv, offset + 4, bd->addr); in ethoc_write_bd()
261 struct ethoc_bd bd; in ethoc_init_ring() local
262 phys_addr_t addr = priv->packet_phys; in ethoc_init_ring()
265 priv->cur_tx = 0; in ethoc_init_ring()
266 priv->dty_tx = 0; in ethoc_init_ring()
267 priv->cur_rx = 0; in ethoc_init_ring()
270 bd.stat = TX_BD_IRQ | TX_BD_CRC; in ethoc_init_ring()
271 bd.addr = 0; in ethoc_init_ring()
273 for (i = 0; i < priv->num_tx; i++) { in ethoc_init_ring()
275 bd.addr = addr; in ethoc_init_ring()
278 if (i == priv->num_tx - 1) in ethoc_init_ring()
279 bd.stat |= TX_BD_WRAP; in ethoc_init_ring()
281 ethoc_write_bd(priv, i, &bd); in ethoc_init_ring()
284 bd.stat = RX_BD_EMPTY | RX_BD_IRQ; in ethoc_init_ring()
286 for (i = 0; i < priv->num_rx; i++) { in ethoc_init_ring()
288 bd.addr = addr; in ethoc_init_ring()
291 bd.addr = virt_to_phys(net_rx_packets[i]); in ethoc_init_ring()
293 if (i == priv->num_rx - 1) in ethoc_init_ring()
294 bd.stat |= RX_BD_WRAP; in ethoc_init_ring()
298 ethoc_write_bd(priv, priv->num_tx + i, &bd); in ethoc_init_ring()
319 /* set full-duplex mode */ in ethoc_reset()
334 priv->num_tx = 1; in ethoc_init_common()
335 priv->num_rx = PKTBUFSRX; in ethoc_init_common()
336 ethoc_write(priv, TX_BD_NUM, priv->num_tx); in ethoc_init_common()
341 ret = phy_startup(priv->phydev); in ethoc_init_common()
344 priv->phydev->dev->name); in ethoc_init_common()
355 phy_shutdown(priv->phydev); in ethoc_stop_common()
359 static int ethoc_update_rx_stats(struct ethoc_bd *bd) in ethoc_update_rx_stats() argument
363 if (bd->stat & RX_BD_TL) { in ethoc_update_rx_stats()
368 if (bd->stat & RX_BD_SF) { in ethoc_update_rx_stats()
373 if (bd->stat & RX_BD_DN) in ethoc_update_rx_stats()
376 if (bd->stat & RX_BD_CRC) { in ethoc_update_rx_stats()
381 if (bd->stat & RX_BD_OR) { in ethoc_update_rx_stats()
386 if (bd->stat & RX_BD_LC) { in ethoc_update_rx_stats()
396 struct ethoc_bd bd; in ethoc_rx_common() local
397 u32 i = priv->cur_rx % priv->num_rx; in ethoc_rx_common()
398 u32 entry = priv->num_tx + i; in ethoc_rx_common()
400 ethoc_read_bd(priv, entry, &bd); in ethoc_rx_common()
401 if (bd.stat & RX_BD_EMPTY) in ethoc_rx_common()
402 return -EAGAIN; in ethoc_rx_common()
405 __func__, priv->cur_rx, bd.stat); in ethoc_rx_common()
406 if (ethoc_update_rx_stats(&bd) == 0) { in ethoc_rx_common()
407 int size = bd.stat >> 16; in ethoc_rx_common()
409 size -= 4; /* strip the CRC */ in ethoc_rx_common()
410 if (priv->packet) in ethoc_rx_common()
411 *packetp = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_rx_common()
436 static int ethoc_update_tx_stats(struct ethoc_bd *bd) in ethoc_update_tx_stats() argument
438 if (bd->stat & TX_BD_LC) in ethoc_update_tx_stats()
441 if (bd->stat & TX_BD_RL) in ethoc_update_tx_stats()
444 if (bd->stat & TX_BD_UR) in ethoc_update_tx_stats()
447 if (bd->stat & TX_BD_CS) in ethoc_update_tx_stats()
455 u32 entry = priv->dty_tx % priv->num_tx; in ethoc_tx()
456 struct ethoc_bd bd; in ethoc_tx() local
458 ethoc_read_bd(priv, entry, &bd); in ethoc_tx()
459 if ((bd.stat & TX_BD_READY) == 0) in ethoc_tx()
460 (void)ethoc_update_tx_stats(&bd); in ethoc_tx()
465 struct ethoc_bd bd; in ethoc_send_common() local
470 entry = priv->cur_tx % priv->num_tx; in ethoc_send_common()
471 ethoc_read_bd(priv, entry, &bd); in ethoc_send_common()
473 bd.stat |= TX_BD_PAD; in ethoc_send_common()
475 bd.stat &= ~TX_BD_PAD; in ethoc_send_common()
477 if (priv->packet) { in ethoc_send_common()
478 void *p = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_send_common()
483 bd.addr = virt_to_phys(packet); in ethoc_send_common()
486 bd.stat &= ~(TX_BD_STATS | TX_BD_LEN_MASK); in ethoc_send_common()
487 bd.stat |= TX_BD_LEN(length); in ethoc_send_common()
488 ethoc_write_bd(priv, entry, &bd); in ethoc_send_common()
491 bd.stat |= TX_BD_READY; in ethoc_send_common()
492 ethoc_write_bd(priv, entry, &bd); in ethoc_send_common()
508 return -1; in ethoc_send_common()
518 struct ethoc_bd bd; in ethoc_free_pkt_common() local
519 u32 i = priv->cur_rx % priv->num_rx; in ethoc_free_pkt_common()
520 u32 entry = priv->num_tx + i; in ethoc_free_pkt_common()
523 ethoc_read_bd(priv, entry, &bd); in ethoc_free_pkt_common()
525 if (priv->packet) in ethoc_free_pkt_common()
526 src = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_free_pkt_common()
532 bd.stat &= ~RX_BD_STATS; in ethoc_free_pkt_common()
533 bd.stat |= RX_BD_EMPTY; in ethoc_free_pkt_common()
534 ethoc_write_bd(priv, entry, &bd); in ethoc_free_pkt_common()
535 priv->cur_rx++; in ethoc_free_pkt_common()
544 struct ethoc *priv = bus->priv; in ethoc_mdio_read()
566 struct ethoc *priv = bus->priv; in ethoc_mdio_write()
590 return -ENOMEM; in ethoc_mdio_init()
593 bus->read = ethoc_mdio_read; in ethoc_mdio_init()
594 bus->write = ethoc_mdio_write; in ethoc_mdio_init()
595 snprintf(bus->name, sizeof(bus->name), "%s", name); in ethoc_mdio_init()
596 bus->priv = priv; in ethoc_mdio_init()
602 priv->bus = miiphy_get_dev_by_name(name); in ethoc_mdio_init()
615 phydev = phy_find_by_mask(priv->bus, mask, PHY_INTERFACE_MODE_MII); in ethoc_phy_init()
617 return -ENODEV; in ethoc_phy_init()
621 phydev->supported &= PHY_BASIC_FEATURES; in ethoc_phy_init()
622 phydev->advertising = phydev->supported; in ethoc_phy_init()
624 priv->phydev = phydev; in ethoc_phy_init()
650 u8 *mac = pdata->eth_pdata.enetaddr; in ethoc_write_hwaddr()
671 return -EAGAIN; in ethoc_recv()
691 pdata->eth_pdata.iobase = devfdt_get_addr(dev); in ethoc_ofdata_to_platdata()
694 pdata->packet_base = addr; in ethoc_ofdata_to_platdata()
703 priv->iobase = ioremap(pdata->eth_pdata.iobase, ETHOC_IOSIZE); in ethoc_probe()
704 if (pdata->packet_base) { in ethoc_probe()
705 priv->packet_phys = pdata->packet_base; in ethoc_probe()
706 priv->packet = ioremap(pdata->packet_base, in ethoc_probe()
710 ethoc_mdio_init(dev->name, priv); in ethoc_probe()
721 free(priv->phydev); in ethoc_remove()
722 mdio_unregister(priv->bus); in ethoc_remove()
723 mdio_free(priv->bus); in ethoc_remove()
725 iounmap(priv->iobase); in ethoc_remove()
757 static int ethoc_init(struct eth_device *dev, bd_t *bd) in ethoc_init() argument
759 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_init()
766 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_write_hwaddr()
767 u8 *mac = dev->enetaddr; in ethoc_write_hwaddr()
774 return ethoc_send_common(dev->priv, packet, length); in ethoc_send()
779 ethoc_disable_rx_and_tx(dev->priv); in ethoc_halt()
784 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_recv()
818 dev->priv = priv; in ethoc_initialize()
819 dev->iobase = base_addr; in ethoc_initialize()
820 dev->init = ethoc_init; in ethoc_initialize()
821 dev->halt = ethoc_halt; in ethoc_initialize()
822 dev->send = ethoc_send; in ethoc_initialize()
823 dev->recv = ethoc_recv; in ethoc_initialize()
824 dev->write_hwaddr = ethoc_write_hwaddr; in ethoc_initialize()
825 sprintf(dev->name, "%s-%hu", "ETHOC", dev_num); in ethoc_initialize()
826 priv->iobase = ioremap(dev->iobase, ETHOC_IOSIZE); in ethoc_initialize()
830 ethoc_mdio_init(dev->name, priv); in ethoc_initialize()