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

4  * Copyright (C) 2007-2008 Avionic Design Development GmbH
5 * Copyright (C) 2008-2009 Avionic Design GmbH
6 * Thierry Reding <thierry.reding@avionic-design.de>
10 * SPDX-License-Identifier: GPL-2.0
55 #define MODER_NBO (1 << 8) /* no back-off */
169 * struct ethoc - driver-private device structure
193 * struct ethoc_bd - buffer descriptor
204 return priv->iobase + offset; in ethoc_reg()
218 struct ethoc_bd *bd) in ethoc_read_bd() argument
221 bd->stat = ethoc_read(priv, offset + 0); in ethoc_read_bd()
222 bd->addr = ethoc_read(priv, offset + 4); in ethoc_read_bd()
226 const struct ethoc_bd *bd) in ethoc_write_bd() argument
229 ethoc_write(priv, offset + 0, bd->stat); in ethoc_write_bd()
230 ethoc_write(priv, offset + 4, bd->addr); in ethoc_write_bd()
262 struct ethoc_bd bd; in ethoc_init_ring() local
263 phys_addr_t addr = priv->packet_phys; in ethoc_init_ring()
266 priv->cur_tx = 0; in ethoc_init_ring()
267 priv->dty_tx = 0; in ethoc_init_ring()
268 priv->cur_rx = 0; in ethoc_init_ring()
271 bd.stat = TX_BD_IRQ | TX_BD_CRC; in ethoc_init_ring()
272 bd.addr = 0; in ethoc_init_ring()
274 for (i = 0; i < priv->num_tx; i++) { in ethoc_init_ring()
276 bd.addr = addr; in ethoc_init_ring()
279 if (i == priv->num_tx - 1) in ethoc_init_ring()
280 bd.stat |= TX_BD_WRAP; in ethoc_init_ring()
282 ethoc_write_bd(priv, i, &bd); in ethoc_init_ring()
285 bd.stat = RX_BD_EMPTY | RX_BD_IRQ; in ethoc_init_ring()
287 for (i = 0; i < priv->num_rx; i++) { in ethoc_init_ring()
289 bd.addr = addr; in ethoc_init_ring()
292 bd.addr = virt_to_phys(net_rx_packets[i]); in ethoc_init_ring()
294 if (i == priv->num_rx - 1) in ethoc_init_ring()
295 bd.stat |= RX_BD_WRAP; in ethoc_init_ring()
299 ethoc_write_bd(priv, priv->num_tx + i, &bd); in ethoc_init_ring()
320 /* set full-duplex mode */ in ethoc_reset()
335 priv->num_tx = 1; in ethoc_init_common()
336 priv->num_rx = PKTBUFSRX; in ethoc_init_common()
337 ethoc_write(priv, TX_BD_NUM, priv->num_tx); in ethoc_init_common()
342 ret = phy_startup(priv->phydev); in ethoc_init_common()
345 priv->phydev->dev->name); in ethoc_init_common()
356 phy_shutdown(priv->phydev); in ethoc_stop_common()
360 static int ethoc_update_rx_stats(struct ethoc_bd *bd) in ethoc_update_rx_stats() argument
364 if (bd->stat & RX_BD_TL) { in ethoc_update_rx_stats()
369 if (bd->stat & RX_BD_SF) { in ethoc_update_rx_stats()
374 if (bd->stat & RX_BD_DN) in ethoc_update_rx_stats()
377 if (bd->stat & RX_BD_CRC) { in ethoc_update_rx_stats()
382 if (bd->stat & RX_BD_OR) { in ethoc_update_rx_stats()
387 if (bd->stat & RX_BD_LC) { in ethoc_update_rx_stats()
397 struct ethoc_bd bd; in ethoc_rx_common() local
398 u32 i = priv->cur_rx % priv->num_rx; in ethoc_rx_common()
399 u32 entry = priv->num_tx + i; in ethoc_rx_common()
401 ethoc_read_bd(priv, entry, &bd); in ethoc_rx_common()
402 if (bd.stat & RX_BD_EMPTY) in ethoc_rx_common()
403 return -EAGAIN; in ethoc_rx_common()
406 __func__, priv->cur_rx, bd.stat); in ethoc_rx_common()
407 if (ethoc_update_rx_stats(&bd) == 0) { in ethoc_rx_common()
408 int size = bd.stat >> 16; in ethoc_rx_common()
410 size -= 4; /* strip the CRC */ in ethoc_rx_common()
411 if (priv->packet) in ethoc_rx_common()
412 *packetp = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_rx_common()
437 static int ethoc_update_tx_stats(struct ethoc_bd *bd) in ethoc_update_tx_stats() argument
439 if (bd->stat & TX_BD_LC) in ethoc_update_tx_stats()
442 if (bd->stat & TX_BD_RL) in ethoc_update_tx_stats()
445 if (bd->stat & TX_BD_UR) in ethoc_update_tx_stats()
448 if (bd->stat & TX_BD_CS) in ethoc_update_tx_stats()
456 u32 entry = priv->dty_tx % priv->num_tx; in ethoc_tx()
457 struct ethoc_bd bd; in ethoc_tx() local
459 ethoc_read_bd(priv, entry, &bd); in ethoc_tx()
460 if ((bd.stat & TX_BD_READY) == 0) in ethoc_tx()
461 (void)ethoc_update_tx_stats(&bd); in ethoc_tx()
466 struct ethoc_bd bd; in ethoc_send_common() local
471 entry = priv->cur_tx % priv->num_tx; in ethoc_send_common()
472 ethoc_read_bd(priv, entry, &bd); in ethoc_send_common()
474 bd.stat |= TX_BD_PAD; in ethoc_send_common()
476 bd.stat &= ~TX_BD_PAD; in ethoc_send_common()
478 if (priv->packet) { in ethoc_send_common()
479 void *p = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_send_common()
484 bd.addr = virt_to_phys(packet); in ethoc_send_common()
487 bd.stat &= ~(TX_BD_STATS | TX_BD_LEN_MASK); in ethoc_send_common()
488 bd.stat |= TX_BD_LEN(length); in ethoc_send_common()
489 ethoc_write_bd(priv, entry, &bd); in ethoc_send_common()
492 bd.stat |= TX_BD_READY; in ethoc_send_common()
493 ethoc_write_bd(priv, entry, &bd); in ethoc_send_common()
509 return -1; in ethoc_send_common()
519 struct ethoc_bd bd; in ethoc_free_pkt_common() local
520 u32 i = priv->cur_rx % priv->num_rx; in ethoc_free_pkt_common()
521 u32 entry = priv->num_tx + i; in ethoc_free_pkt_common()
524 ethoc_read_bd(priv, entry, &bd); in ethoc_free_pkt_common()
526 if (priv->packet) in ethoc_free_pkt_common()
527 src = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_free_pkt_common()
533 bd.stat &= ~RX_BD_STATS; in ethoc_free_pkt_common()
534 bd.stat |= RX_BD_EMPTY; in ethoc_free_pkt_common()
535 ethoc_write_bd(priv, entry, &bd); in ethoc_free_pkt_common()
536 priv->cur_rx++; in ethoc_free_pkt_common()
545 struct ethoc *priv = bus->priv; in ethoc_mdio_read()
567 struct ethoc *priv = bus->priv; in ethoc_mdio_write()
591 return -ENOMEM; in ethoc_mdio_init()
594 bus->read = ethoc_mdio_read; in ethoc_mdio_init()
595 bus->write = ethoc_mdio_write; in ethoc_mdio_init()
596 snprintf(bus->name, sizeof(bus->name), "%s", name); in ethoc_mdio_init()
597 bus->priv = priv; in ethoc_mdio_init()
603 priv->bus = miiphy_get_dev_by_name(name); in ethoc_mdio_init()
616 phydev = phy_find_by_mask(priv->bus, mask, PHY_INTERFACE_MODE_MII); in ethoc_phy_init()
618 return -ENODEV; in ethoc_phy_init()
622 phydev->supported &= PHY_BASIC_FEATURES; in ethoc_phy_init()
623 phydev->advertising = phydev->supported; in ethoc_phy_init()
625 priv->phydev = phydev; in ethoc_phy_init()
651 u8 *mac = pdata->eth_pdata.enetaddr; in ethoc_write_hwaddr()
672 return -EAGAIN; in ethoc_recv()
692 pdata->eth_pdata.iobase = devfdt_get_addr(dev); in ethoc_ofdata_to_platdata()
695 pdata->packet_base = addr; in ethoc_ofdata_to_platdata()
704 priv->iobase = ioremap(pdata->eth_pdata.iobase, ETHOC_IOSIZE); in ethoc_probe()
705 if (pdata->packet_base) { in ethoc_probe()
706 priv->packet_phys = pdata->packet_base; in ethoc_probe()
707 priv->packet = ioremap(pdata->packet_base, in ethoc_probe()
711 ethoc_mdio_init(dev->name, priv); in ethoc_probe()
722 free(priv->phydev); in ethoc_remove()
723 mdio_unregister(priv->bus); in ethoc_remove()
724 mdio_free(priv->bus); in ethoc_remove()
726 iounmap(priv->iobase); in ethoc_remove()
758 static int ethoc_init(struct eth_device *dev, bd_t *bd) in ethoc_init() argument
760 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_init()
767 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_write_hwaddr()
768 u8 *mac = dev->enetaddr; in ethoc_write_hwaddr()
775 return ethoc_send_common(dev->priv, packet, length); in ethoc_send()
780 ethoc_disable_rx_and_tx(dev->priv); in ethoc_halt()
785 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_recv()
819 dev->priv = priv; in ethoc_initialize()
820 dev->iobase = base_addr; in ethoc_initialize()
821 dev->init = ethoc_init; in ethoc_initialize()
822 dev->halt = ethoc_halt; in ethoc_initialize()
823 dev->send = ethoc_send; in ethoc_initialize()
824 dev->recv = ethoc_recv; in ethoc_initialize()
825 dev->write_hwaddr = ethoc_write_hwaddr; in ethoc_initialize()
826 sprintf(dev->name, "%s-%hu", "ETHOC", dev_num); in ethoc_initialize()
827 priv->iobase = ioremap(dev->iobase, ETHOC_IOSIZE); in ethoc_initialize()
831 ethoc_mdio_init(dev->name, priv); in ethoc_initialize()