Lines Matching refs:priv

202 static inline u32 *ethoc_reg(struct ethoc *priv, size_t offset)  in ethoc_reg()  argument
204 return priv->iobase + offset; in ethoc_reg()
207 static inline u32 ethoc_read(struct ethoc *priv, size_t offset) in ethoc_read() argument
209 return readl(ethoc_reg(priv, offset)); in ethoc_read()
212 static inline void ethoc_write(struct ethoc *priv, size_t offset, u32 data) in ethoc_write() argument
214 writel(data, ethoc_reg(priv, offset)); in ethoc_write()
217 static inline void ethoc_read_bd(struct ethoc *priv, int index, 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()
225 static inline void ethoc_write_bd(struct ethoc *priv, int index, 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()
233 static int ethoc_write_hwaddr_common(struct ethoc *priv, u8 *mac) in ethoc_write_hwaddr_common() argument
235 ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) | in ethoc_write_hwaddr_common()
237 ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0)); in ethoc_write_hwaddr_common()
241 static inline void ethoc_ack_irq(struct ethoc *priv, u32 mask) in ethoc_ack_irq() argument
243 ethoc_write(priv, INT_SOURCE, mask); in ethoc_ack_irq()
246 static inline void ethoc_enable_rx_and_tx(struct ethoc *priv) in ethoc_enable_rx_and_tx() argument
248 u32 mode = ethoc_read(priv, MODER); in ethoc_enable_rx_and_tx()
250 ethoc_write(priv, MODER, mode); in ethoc_enable_rx_and_tx()
253 static inline void ethoc_disable_rx_and_tx(struct ethoc *priv) in ethoc_disable_rx_and_tx() argument
255 u32 mode = ethoc_read(priv, MODER); in ethoc_disable_rx_and_tx()
257 ethoc_write(priv, MODER, mode); in ethoc_disable_rx_and_tx()
260 static int ethoc_init_ring(struct ethoc *priv) in ethoc_init_ring() argument
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()
274 for (i = 0; i < priv->num_tx; i++) { in ethoc_init_ring()
279 if (i == priv->num_tx - 1) in ethoc_init_ring()
282 ethoc_write_bd(priv, i, &bd); in ethoc_init_ring()
287 for (i = 0; i < priv->num_rx; i++) { in ethoc_init_ring()
294 if (i == priv->num_rx - 1) in ethoc_init_ring()
299 ethoc_write_bd(priv, priv->num_tx + i, &bd); in ethoc_init_ring()
305 static int ethoc_reset(struct ethoc *priv) in ethoc_reset() argument
311 ethoc_disable_rx_and_tx(priv); in ethoc_reset()
316 mode = ethoc_read(priv, MODER); in ethoc_reset()
318 ethoc_write(priv, MODER, mode); in ethoc_reset()
321 mode = ethoc_read(priv, MODER); in ethoc_reset()
323 ethoc_write(priv, MODER, mode); in ethoc_reset()
324 ethoc_write(priv, IPGT, 0x15); in ethoc_reset()
326 ethoc_ack_irq(priv, INT_MASK_ALL); in ethoc_reset()
327 ethoc_enable_rx_and_tx(priv); in ethoc_reset()
331 static int ethoc_init_common(struct ethoc *priv) in ethoc_init_common() argument
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()
338 ethoc_init_ring(priv); in ethoc_init_common()
339 ethoc_reset(priv); in ethoc_init_common()
342 ret = phy_startup(priv->phydev); in ethoc_init_common()
345 priv->phydev->dev->name); in ethoc_init_common()
352 static void ethoc_stop_common(struct ethoc *priv) in ethoc_stop_common() argument
354 ethoc_disable_rx_and_tx(priv); in ethoc_stop_common()
356 phy_shutdown(priv->phydev); in ethoc_stop_common()
395 static int ethoc_rx_common(struct ethoc *priv, uchar **packetp) in ethoc_rx_common() argument
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()
406 __func__, priv->cur_rx, bd.stat); in ethoc_rx_common()
411 if (priv->packet) in ethoc_rx_common()
412 *packetp = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_rx_common()
421 static int ethoc_is_new_packet_received(struct ethoc *priv) in ethoc_is_new_packet_received() argument
425 pending = ethoc_read(priv, INT_SOURCE); in ethoc_is_new_packet_received()
426 ethoc_ack_irq(priv, pending); in ethoc_is_new_packet_received()
454 static void ethoc_tx(struct ethoc *priv) in ethoc_tx() argument
456 u32 entry = priv->dty_tx % priv->num_tx; in ethoc_tx()
459 ethoc_read_bd(priv, entry, &bd); in ethoc_tx()
464 static int ethoc_send_common(struct ethoc *priv, void *packet, int length) in ethoc_send_common() argument
471 entry = priv->cur_tx % priv->num_tx; in ethoc_send_common()
472 ethoc_read_bd(priv, entry, &bd); in ethoc_send_common()
478 if (priv->packet) { in ethoc_send_common()
479 void *p = priv->packet + entry * PKTSIZE_ALIGN; in ethoc_send_common()
489 ethoc_write_bd(priv, entry, &bd); in ethoc_send_common()
493 ethoc_write_bd(priv, entry, &bd); in ethoc_send_common()
498 pending = ethoc_read(priv, INT_SOURCE); in ethoc_send_common()
499 ethoc_ack_irq(priv, pending & ~INT_MASK_RX); in ethoc_send_common()
504 ethoc_tx(priv); in ethoc_send_common()
517 static int ethoc_free_pkt_common(struct ethoc *priv) in ethoc_free_pkt_common() argument
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()
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() local
548 ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(addr, reg)); in ethoc_mdio_read()
549 ethoc_write(priv, MIICOMMAND, MIICOMMAND_READ); in ethoc_mdio_read()
551 rc = wait_for_bit_le32(ethoc_reg(priv, MIISTATUS), in ethoc_mdio_read()
555 u32 data = ethoc_read(priv, MIIRX_DATA); in ethoc_mdio_read()
558 ethoc_write(priv, MIICOMMAND, 0); in ethoc_mdio_read()
567 struct ethoc *priv = bus->priv; in ethoc_mdio_write() local
570 ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(addr, reg)); in ethoc_mdio_write()
571 ethoc_write(priv, MIITX_DATA, val); in ethoc_mdio_write()
572 ethoc_write(priv, MIICOMMAND, MIICOMMAND_WRITE); in ethoc_mdio_write()
574 rc = wait_for_bit_le32(ethoc_reg(priv, MIISTATUS), in ethoc_mdio_write()
579 ethoc_write(priv, MIICOMMAND, 0); in ethoc_mdio_write()
584 static int ethoc_mdio_init(const char *name, struct ethoc *priv) in ethoc_mdio_init() argument
597 bus->priv = priv; in ethoc_mdio_init()
603 priv->bus = miiphy_get_dev_by_name(name); in ethoc_mdio_init()
607 static int ethoc_phy_init(struct ethoc *priv, void *dev) in ethoc_phy_init() argument
616 phydev = phy_find_by_mask(priv->bus, mask, PHY_INTERFACE_MODE_MII); in ethoc_phy_init()
625 priv->phydev = phydev; in ethoc_phy_init()
633 static inline int ethoc_mdio_init(const char *name, struct ethoc *priv) in ethoc_mdio_init() argument
638 static inline int ethoc_phy_init(struct ethoc *priv, void *dev) in ethoc_phy_init() argument
650 struct ethoc *priv = dev_get_priv(dev); in ethoc_write_hwaddr() local
653 return ethoc_write_hwaddr_common(priv, mac); in ethoc_write_hwaddr()
668 struct ethoc *priv = dev_get_priv(dev); in ethoc_recv() local
671 if (!ethoc_is_new_packet_received(priv)) in ethoc_recv()
674 return ethoc_rx_common(priv, packetp); in ethoc_recv()
702 struct ethoc *priv = dev_get_priv(dev); in ethoc_probe() local
704 priv->iobase = ioremap(pdata->eth_pdata.iobase, ETHOC_IOSIZE); 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()
712 ethoc_phy_init(priv, dev); in ethoc_probe()
719 struct ethoc *priv = dev_get_priv(dev); in ethoc_remove() local
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()
760 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_init() local
762 return ethoc_init_common(priv); in ethoc_init()
767 struct ethoc *priv = (struct ethoc *)dev->priv; in ethoc_write_hwaddr() local
770 return ethoc_write_hwaddr_common(priv, mac); 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() local
788 if (!ethoc_is_new_packet_received(priv)) in ethoc_recv()
793 int size = ethoc_rx_common(priv, &packetp); in ethoc_recv()
799 ethoc_free_pkt_common(priv); in ethoc_recv()
806 struct ethoc *priv; in ethoc_initialize() local
809 priv = malloc(sizeof(*priv)); in ethoc_initialize()
810 if (!priv) in ethoc_initialize()
814 free(priv); in ethoc_initialize()
819 dev->priv = priv; in ethoc_initialize()
827 priv->iobase = ioremap(dev->iobase, ETHOC_IOSIZE); in ethoc_initialize()
831 ethoc_mdio_init(dev->name, priv); in ethoc_initialize()
832 ethoc_phy_init(priv, dev); in ethoc_initialize()