Lines Matching refs:priv
84 spi_read_buf(struct enc28j60_net *priv, int len, u8 *data) in spi_read_buf() argument
86 struct device *dev = &priv->spi->dev; in spi_read_buf()
87 u8 *rx_buf = priv->spi_transfer_buf + 4; in spi_read_buf()
88 u8 *tx_buf = priv->spi_transfer_buf; in spi_read_buf()
106 ret = spi_sync(priv->spi, &msg); in spi_read_buf()
111 if (ret && netif_msg_drv(priv)) in spi_read_buf()
121 static int spi_write_buf(struct enc28j60_net *priv, int len, const u8 *data) in spi_write_buf() argument
123 struct device *dev = &priv->spi->dev; in spi_write_buf()
129 priv->spi_transfer_buf[0] = ENC28J60_WRITE_BUF_MEM; in spi_write_buf()
130 memcpy(&priv->spi_transfer_buf[1], data, len); in spi_write_buf()
131 ret = spi_write(priv->spi, priv->spi_transfer_buf, len + 1); in spi_write_buf()
132 if (ret && netif_msg_drv(priv)) in spi_write_buf()
142 static u8 spi_read_op(struct enc28j60_net *priv, u8 op, u8 addr) in spi_read_op() argument
144 struct device *dev = &priv->spi->dev; in spi_read_op()
156 ret = spi_write_then_read(priv->spi, tx_buf, 1, rx_buf, slen); in spi_read_op()
169 static int spi_write_op(struct enc28j60_net *priv, u8 op, u8 addr, u8 val) in spi_write_op() argument
171 struct device *dev = &priv->spi->dev; in spi_write_op()
174 priv->spi_transfer_buf[0] = op | (addr & ADDR_MASK); in spi_write_op()
175 priv->spi_transfer_buf[1] = val; in spi_write_op()
176 ret = spi_write(priv->spi, priv->spi_transfer_buf, 2); in spi_write_op()
177 if (ret && netif_msg_drv(priv)) in spi_write_op()
183 static void enc28j60_soft_reset(struct enc28j60_net *priv) in enc28j60_soft_reset() argument
185 spi_write_op(priv, ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET); in enc28j60_soft_reset()
194 static void enc28j60_set_bank(struct enc28j60_net *priv, u8 addr) in enc28j60_set_bank() argument
205 if ((b & ECON1_BSEL0) != (priv->bank & ECON1_BSEL0)) { in enc28j60_set_bank()
207 spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1, in enc28j60_set_bank()
210 spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1, in enc28j60_set_bank()
213 if ((b & ECON1_BSEL1) != (priv->bank & ECON1_BSEL1)) { in enc28j60_set_bank()
215 spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1, in enc28j60_set_bank()
218 spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1, in enc28j60_set_bank()
221 priv->bank = b; in enc28j60_set_bank()
238 static void nolock_reg_bfset(struct enc28j60_net *priv, u8 addr, u8 mask) in nolock_reg_bfset() argument
240 enc28j60_set_bank(priv, addr); in nolock_reg_bfset()
241 spi_write_op(priv, ENC28J60_BIT_FIELD_SET, addr, mask); in nolock_reg_bfset()
244 static void locked_reg_bfset(struct enc28j60_net *priv, u8 addr, u8 mask) in locked_reg_bfset() argument
246 mutex_lock(&priv->lock); in locked_reg_bfset()
247 nolock_reg_bfset(priv, addr, mask); in locked_reg_bfset()
248 mutex_unlock(&priv->lock); in locked_reg_bfset()
254 static void nolock_reg_bfclr(struct enc28j60_net *priv, u8 addr, u8 mask) in nolock_reg_bfclr() argument
256 enc28j60_set_bank(priv, addr); in nolock_reg_bfclr()
257 spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, addr, mask); in nolock_reg_bfclr()
260 static void locked_reg_bfclr(struct enc28j60_net *priv, u8 addr, u8 mask) in locked_reg_bfclr() argument
262 mutex_lock(&priv->lock); in locked_reg_bfclr()
263 nolock_reg_bfclr(priv, addr, mask); in locked_reg_bfclr()
264 mutex_unlock(&priv->lock); in locked_reg_bfclr()
270 static int nolock_regb_read(struct enc28j60_net *priv, u8 address) in nolock_regb_read() argument
272 enc28j60_set_bank(priv, address); in nolock_regb_read()
273 return spi_read_op(priv, ENC28J60_READ_CTRL_REG, address); in nolock_regb_read()
276 static int locked_regb_read(struct enc28j60_net *priv, u8 address) in locked_regb_read() argument
280 mutex_lock(&priv->lock); in locked_regb_read()
281 ret = nolock_regb_read(priv, address); in locked_regb_read()
282 mutex_unlock(&priv->lock); in locked_regb_read()
290 static int nolock_regw_read(struct enc28j60_net *priv, u8 address) in nolock_regw_read() argument
294 enc28j60_set_bank(priv, address); in nolock_regw_read()
295 rl = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address); in nolock_regw_read()
296 rh = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address + 1); in nolock_regw_read()
301 static int locked_regw_read(struct enc28j60_net *priv, u8 address) in locked_regw_read() argument
305 mutex_lock(&priv->lock); in locked_regw_read()
306 ret = nolock_regw_read(priv, address); in locked_regw_read()
307 mutex_unlock(&priv->lock); in locked_regw_read()
315 static void nolock_regb_write(struct enc28j60_net *priv, u8 address, u8 data) in nolock_regb_write() argument
317 enc28j60_set_bank(priv, address); in nolock_regb_write()
318 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, data); in nolock_regb_write()
321 static void locked_regb_write(struct enc28j60_net *priv, u8 address, u8 data) in locked_regb_write() argument
323 mutex_lock(&priv->lock); in locked_regb_write()
324 nolock_regb_write(priv, address, data); in locked_regb_write()
325 mutex_unlock(&priv->lock); in locked_regb_write()
331 static void nolock_regw_write(struct enc28j60_net *priv, u8 address, u16 data) in nolock_regw_write() argument
333 enc28j60_set_bank(priv, address); in nolock_regw_write()
334 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, (u8) data); in nolock_regw_write()
335 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address + 1, in nolock_regw_write()
339 static void locked_regw_write(struct enc28j60_net *priv, u8 address, u16 data) in locked_regw_write() argument
341 mutex_lock(&priv->lock); in locked_regw_write()
342 nolock_regw_write(priv, address, data); in locked_regw_write()
343 mutex_unlock(&priv->lock); in locked_regw_write()
350 static void enc28j60_mem_read(struct enc28j60_net *priv, u16 addr, int len, in enc28j60_mem_read() argument
353 mutex_lock(&priv->lock); in enc28j60_mem_read()
354 nolock_regw_write(priv, ERDPTL, addr); in enc28j60_mem_read()
356 if (netif_msg_drv(priv)) { in enc28j60_mem_read()
357 struct device *dev = &priv->spi->dev; in enc28j60_mem_read()
360 reg = nolock_regw_read(priv, ERDPTL); in enc28j60_mem_read()
367 spi_read_buf(priv, len, data); in enc28j60_mem_read()
368 mutex_unlock(&priv->lock); in enc28j60_mem_read()
375 enc28j60_packet_write(struct enc28j60_net *priv, int len, const u8 *data) in enc28j60_packet_write() argument
377 struct device *dev = &priv->spi->dev; in enc28j60_packet_write()
379 mutex_lock(&priv->lock); in enc28j60_packet_write()
381 nolock_regw_write(priv, EWRPTL, TXSTART_INIT); in enc28j60_packet_write()
383 if (netif_msg_drv(priv)) { in enc28j60_packet_write()
385 reg = nolock_regw_read(priv, EWRPTL); in enc28j60_packet_write()
393 nolock_regw_write(priv, ETXNDL, TXSTART_INIT + len); in enc28j60_packet_write()
395 spi_write_op(priv, ENC28J60_WRITE_BUF_MEM, 0, 0x00); in enc28j60_packet_write()
396 if (netif_msg_hw(priv)) in enc28j60_packet_write()
399 __func__, nolock_regw_read(priv, EWRPTL)); in enc28j60_packet_write()
401 spi_write_buf(priv, len, data); in enc28j60_packet_write()
402 if (netif_msg_hw(priv)) in enc28j60_packet_write()
405 __func__, nolock_regw_read(priv, EWRPTL), len); in enc28j60_packet_write()
406 mutex_unlock(&priv->lock); in enc28j60_packet_write()
409 static int poll_ready(struct enc28j60_net *priv, u8 reg, u8 mask, u8 val) in poll_ready() argument
411 struct device *dev = &priv->spi->dev; in poll_ready()
415 while ((nolock_regb_read(priv, reg) & mask) != val) { in poll_ready()
417 if (netif_msg_drv(priv)) in poll_ready()
429 static int wait_phy_ready(struct enc28j60_net *priv) in wait_phy_ready() argument
431 return poll_ready(priv, MISTAT, MISTAT_BUSY, 0) ? 0 : 1; in wait_phy_ready()
438 static u16 enc28j60_phy_read(struct enc28j60_net *priv, u8 address) in enc28j60_phy_read() argument
442 mutex_lock(&priv->lock); in enc28j60_phy_read()
444 nolock_regb_write(priv, MIREGADR, address); in enc28j60_phy_read()
446 nolock_regb_write(priv, MICMD, MICMD_MIIRD); in enc28j60_phy_read()
448 wait_phy_ready(priv); in enc28j60_phy_read()
450 nolock_regb_write(priv, MICMD, 0x00); in enc28j60_phy_read()
452 ret = nolock_regw_read(priv, MIRDL); in enc28j60_phy_read()
453 mutex_unlock(&priv->lock); in enc28j60_phy_read()
458 static int enc28j60_phy_write(struct enc28j60_net *priv, u8 address, u16 data) in enc28j60_phy_write() argument
462 mutex_lock(&priv->lock); in enc28j60_phy_write()
464 nolock_regb_write(priv, MIREGADR, address); in enc28j60_phy_write()
466 nolock_regw_write(priv, MIWRL, data); in enc28j60_phy_write()
468 ret = wait_phy_ready(priv); in enc28j60_phy_write()
469 mutex_unlock(&priv->lock); in enc28j60_phy_write()
480 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_set_hw_macaddr() local
481 struct device *dev = &priv->spi->dev; in enc28j60_set_hw_macaddr()
483 mutex_lock(&priv->lock); in enc28j60_set_hw_macaddr()
484 if (!priv->hw_enable) { in enc28j60_set_hw_macaddr()
485 if (netif_msg_drv(priv)) in enc28j60_set_hw_macaddr()
489 nolock_regb_write(priv, MAADR5, ndev->dev_addr[0]); in enc28j60_set_hw_macaddr()
490 nolock_regb_write(priv, MAADR4, ndev->dev_addr[1]); in enc28j60_set_hw_macaddr()
491 nolock_regb_write(priv, MAADR3, ndev->dev_addr[2]); in enc28j60_set_hw_macaddr()
492 nolock_regb_write(priv, MAADR2, ndev->dev_addr[3]); in enc28j60_set_hw_macaddr()
493 nolock_regb_write(priv, MAADR1, ndev->dev_addr[4]); in enc28j60_set_hw_macaddr()
494 nolock_regb_write(priv, MAADR0, ndev->dev_addr[5]); in enc28j60_set_hw_macaddr()
497 if (netif_msg_drv(priv)) in enc28j60_set_hw_macaddr()
503 mutex_unlock(&priv->lock); in enc28j60_set_hw_macaddr()
526 static void enc28j60_dump_regs(struct enc28j60_net *priv, const char *msg) in enc28j60_dump_regs() argument
528 struct device *dev = &priv->spi->dev; in enc28j60_dump_regs()
530 mutex_lock(&priv->lock); in enc28j60_dump_regs()
543 msg, nolock_regb_read(priv, EREVID), in enc28j60_dump_regs()
544 nolock_regb_read(priv, ECON1), nolock_regb_read(priv, ECON2), in enc28j60_dump_regs()
545 nolock_regb_read(priv, ESTAT), nolock_regb_read(priv, EIR), in enc28j60_dump_regs()
546 nolock_regb_read(priv, EIE), nolock_regb_read(priv, MACON1), in enc28j60_dump_regs()
547 nolock_regb_read(priv, MACON3), nolock_regb_read(priv, MACON4), in enc28j60_dump_regs()
548 nolock_regw_read(priv, ERXSTL), nolock_regw_read(priv, ERXNDL), in enc28j60_dump_regs()
549 nolock_regw_read(priv, ERXWRPTL), in enc28j60_dump_regs()
550 nolock_regw_read(priv, ERXRDPTL), in enc28j60_dump_regs()
551 nolock_regb_read(priv, ERXFCON), in enc28j60_dump_regs()
552 nolock_regb_read(priv, EPKTCNT), in enc28j60_dump_regs()
553 nolock_regw_read(priv, MAMXFLL), nolock_regw_read(priv, ETXSTL), in enc28j60_dump_regs()
554 nolock_regw_read(priv, ETXNDL), in enc28j60_dump_regs()
555 nolock_regb_read(priv, MACLCON1), in enc28j60_dump_regs()
556 nolock_regb_read(priv, MACLCON2), in enc28j60_dump_regs()
557 nolock_regb_read(priv, MAPHSUP)); in enc28j60_dump_regs()
558 mutex_unlock(&priv->lock); in enc28j60_dump_regs()
587 static void nolock_rxfifo_init(struct enc28j60_net *priv, u16 start, u16 end) in nolock_rxfifo_init() argument
589 struct device *dev = &priv->spi->dev; in nolock_rxfifo_init()
593 if (netif_msg_drv(priv)) in nolock_rxfifo_init()
599 priv->next_pk_ptr = start; in nolock_rxfifo_init()
600 nolock_regw_write(priv, ERXSTL, start); in nolock_rxfifo_init()
601 erxrdpt = erxrdpt_workaround(priv->next_pk_ptr, start, end); in nolock_rxfifo_init()
602 nolock_regw_write(priv, ERXRDPTL, erxrdpt); in nolock_rxfifo_init()
603 nolock_regw_write(priv, ERXNDL, end); in nolock_rxfifo_init()
606 static void nolock_txfifo_init(struct enc28j60_net *priv, u16 start, u16 end) in nolock_txfifo_init() argument
608 struct device *dev = &priv->spi->dev; in nolock_txfifo_init()
611 if (netif_msg_drv(priv)) in nolock_txfifo_init()
617 nolock_regw_write(priv, ETXSTL, start); in nolock_txfifo_init()
618 nolock_regw_write(priv, ETXNDL, end); in nolock_txfifo_init()
626 static void enc28j60_lowpower(struct enc28j60_net *priv, bool is_low) in enc28j60_lowpower() argument
628 struct device *dev = &priv->spi->dev; in enc28j60_lowpower()
630 if (netif_msg_drv(priv)) in enc28j60_lowpower()
633 mutex_lock(&priv->lock); in enc28j60_lowpower()
635 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN); in enc28j60_lowpower()
636 poll_ready(priv, ESTAT, ESTAT_RXBUSY, 0); in enc28j60_lowpower()
637 poll_ready(priv, ECON1, ECON1_TXRTS, 0); in enc28j60_lowpower()
639 nolock_reg_bfset(priv, ECON2, ECON2_PWRSV); in enc28j60_lowpower()
641 nolock_reg_bfclr(priv, ECON2, ECON2_PWRSV); in enc28j60_lowpower()
642 poll_ready(priv, ESTAT, ESTAT_CLKRDY, ESTAT_CLKRDY); in enc28j60_lowpower()
645 mutex_unlock(&priv->lock); in enc28j60_lowpower()
648 static int enc28j60_hw_init(struct enc28j60_net *priv) in enc28j60_hw_init() argument
650 struct device *dev = &priv->spi->dev; in enc28j60_hw_init()
653 if (netif_msg_drv(priv)) in enc28j60_hw_init()
655 priv->full_duplex ? "FullDuplex" : "HalfDuplex"); in enc28j60_hw_init()
657 mutex_lock(&priv->lock); in enc28j60_hw_init()
659 enc28j60_soft_reset(priv); in enc28j60_hw_init()
661 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, ECON1, 0x00); in enc28j60_hw_init()
662 priv->bank = 0; in enc28j60_hw_init()
663 priv->hw_enable = false; in enc28j60_hw_init()
664 priv->tx_retry_count = 0; in enc28j60_hw_init()
665 priv->max_pk_counter = 0; in enc28j60_hw_init()
666 priv->rxfilter = RXFILTER_NORMAL; in enc28j60_hw_init()
668 nolock_regb_write(priv, ECON2, ECON2_AUTOINC | ECON2_VRPS); in enc28j60_hw_init()
670 nolock_rxfifo_init(priv, RXSTART_INIT, RXEND_INIT); in enc28j60_hw_init()
671 nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT); in enc28j60_hw_init()
672 mutex_unlock(&priv->lock); in enc28j60_hw_init()
679 reg = locked_regb_read(priv, EREVID); in enc28j60_hw_init()
680 if (netif_msg_drv(priv)) in enc28j60_hw_init()
683 if (netif_msg_drv(priv)) in enc28j60_hw_init()
690 locked_regb_write(priv, ERXFCON, in enc28j60_hw_init()
694 locked_regb_write(priv, MACON1, in enc28j60_hw_init()
697 if (priv->full_duplex) { in enc28j60_hw_init()
698 locked_regb_write(priv, MACON3, in enc28j60_hw_init()
702 locked_regb_write(priv, MAIPGL, 0x12); in enc28j60_hw_init()
704 locked_regb_write(priv, MABBIPG, 0x15); in enc28j60_hw_init()
706 locked_regb_write(priv, MACON3, in enc28j60_hw_init()
709 locked_regb_write(priv, MACON4, 1 << 6); /* DEFER bit */ in enc28j60_hw_init()
711 locked_regw_write(priv, MAIPGL, 0x0C12); in enc28j60_hw_init()
713 locked_regb_write(priv, MABBIPG, 0x12); in enc28j60_hw_init()
720 locked_regw_write(priv, MAMXFLL, MAX_FRAMELEN); in enc28j60_hw_init()
723 if (!enc28j60_phy_write(priv, PHLCON, ENC28J60_LAMPS_MODE)) in enc28j60_hw_init()
726 if (priv->full_duplex) { in enc28j60_hw_init()
727 if (!enc28j60_phy_write(priv, PHCON1, PHCON1_PDPXMD)) in enc28j60_hw_init()
729 if (!enc28j60_phy_write(priv, PHCON2, 0x00)) in enc28j60_hw_init()
732 if (!enc28j60_phy_write(priv, PHCON1, 0x00)) in enc28j60_hw_init()
734 if (!enc28j60_phy_write(priv, PHCON2, PHCON2_HDLDIS)) in enc28j60_hw_init()
737 if (netif_msg_hw(priv)) in enc28j60_hw_init()
738 enc28j60_dump_regs(priv, "Hw initialized."); in enc28j60_hw_init()
743 static void enc28j60_hw_enable(struct enc28j60_net *priv) in enc28j60_hw_enable() argument
745 struct device *dev = &priv->spi->dev; in enc28j60_hw_enable()
748 if (netif_msg_hw(priv)) in enc28j60_hw_enable()
752 enc28j60_phy_write(priv, PHIE, PHIE_PGEIE | PHIE_PLNKIE); in enc28j60_hw_enable()
754 mutex_lock(&priv->lock); in enc28j60_hw_enable()
755 nolock_reg_bfclr(priv, EIR, EIR_DMAIF | EIR_LINKIF | in enc28j60_hw_enable()
757 nolock_regb_write(priv, EIE, EIE_INTIE | EIE_PKTIE | EIE_LINKIE | in enc28j60_hw_enable()
761 nolock_reg_bfset(priv, ECON1, ECON1_RXEN); in enc28j60_hw_enable()
762 priv->hw_enable = true; in enc28j60_hw_enable()
763 mutex_unlock(&priv->lock); in enc28j60_hw_enable()
766 static void enc28j60_hw_disable(struct enc28j60_net *priv) in enc28j60_hw_disable() argument
768 mutex_lock(&priv->lock); in enc28j60_hw_disable()
770 nolock_regb_write(priv, EIE, 0x00); in enc28j60_hw_disable()
771 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN); in enc28j60_hw_disable()
772 priv->hw_enable = false; in enc28j60_hw_disable()
773 mutex_unlock(&priv->lock); in enc28j60_hw_disable()
779 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_setlink() local
782 if (!priv->hw_enable) { in enc28j60_setlink()
787 priv->full_duplex = (duplex == DUPLEX_FULL); in enc28j60_setlink()
789 if (netif_msg_link(priv)) in enc28j60_setlink()
794 if (netif_msg_link(priv)) in enc28j60_setlink()
804 static void enc28j60_read_tsv(struct enc28j60_net *priv, u8 tsv[TSV_SIZE]) in enc28j60_read_tsv() argument
806 struct device *dev = &priv->spi->dev; in enc28j60_read_tsv()
809 endptr = locked_regw_read(priv, ETXNDL); in enc28j60_read_tsv()
810 if (netif_msg_hw(priv)) in enc28j60_read_tsv()
813 enc28j60_mem_read(priv, endptr + 1, TSV_SIZE, tsv); in enc28j60_read_tsv()
816 static void enc28j60_dump_tsv(struct enc28j60_net *priv, const char *msg, in enc28j60_dump_tsv() argument
819 struct device *dev = &priv->spi->dev; in enc28j60_dump_tsv()
862 static void enc28j60_dump_rsv(struct enc28j60_net *priv, const char *msg, in enc28j60_dump_rsv() argument
865 struct device *dev = &priv->spi->dev; in enc28j60_dump_rsv()
904 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_hw_rx() local
905 struct device *dev = &priv->spi->dev; in enc28j60_hw_rx()
911 if (netif_msg_rx_status(priv)) in enc28j60_hw_rx()
913 priv->next_pk_ptr); in enc28j60_hw_rx()
915 if (unlikely(priv->next_pk_ptr > RXEND_INIT)) { in enc28j60_hw_rx()
916 if (netif_msg_rx_err(priv)) in enc28j60_hw_rx()
918 __func__, priv->next_pk_ptr); in enc28j60_hw_rx()
920 mutex_lock(&priv->lock); in enc28j60_hw_rx()
921 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN); in enc28j60_hw_rx()
922 nolock_reg_bfset(priv, ECON1, ECON1_RXRST); in enc28j60_hw_rx()
923 nolock_reg_bfclr(priv, ECON1, ECON1_RXRST); in enc28j60_hw_rx()
924 nolock_rxfifo_init(priv, RXSTART_INIT, RXEND_INIT); in enc28j60_hw_rx()
925 nolock_reg_bfclr(priv, EIR, EIR_RXERIF); in enc28j60_hw_rx()
926 nolock_reg_bfset(priv, ECON1, ECON1_RXEN); in enc28j60_hw_rx()
927 mutex_unlock(&priv->lock); in enc28j60_hw_rx()
932 enc28j60_mem_read(priv, priv->next_pk_ptr, sizeof(rsv), rsv); in enc28j60_hw_rx()
946 if (netif_msg_rx_status(priv)) in enc28j60_hw_rx()
947 enc28j60_dump_rsv(priv, __func__, next_packet, len, rxstat); in enc28j60_hw_rx()
950 if (netif_msg_rx_err(priv)) in enc28j60_hw_rx()
962 if (netif_msg_rx_err(priv)) in enc28j60_hw_rx()
968 enc28j60_mem_read(priv, in enc28j60_hw_rx()
969 rx_packet_start(priv->next_pk_ptr), in enc28j60_hw_rx()
971 if (netif_msg_pktdata(priv)) in enc28j60_hw_rx()
986 if (netif_msg_hw(priv)) in enc28j60_hw_rx()
990 mutex_lock(&priv->lock); in enc28j60_hw_rx()
991 nolock_regw_write(priv, ERXRDPTL, erxrdpt); in enc28j60_hw_rx()
993 if (netif_msg_drv(priv)) { in enc28j60_hw_rx()
995 reg = nolock_regw_read(priv, ERXRDPTL); in enc28j60_hw_rx()
1002 priv->next_pk_ptr = next_packet; in enc28j60_hw_rx()
1004 nolock_reg_bfset(priv, ECON2, ECON2_PKTDEC); in enc28j60_hw_rx()
1005 mutex_unlock(&priv->lock); in enc28j60_hw_rx()
1011 static int enc28j60_get_free_rxfifo(struct enc28j60_net *priv) in enc28j60_get_free_rxfifo() argument
1013 struct net_device *ndev = priv->netdev; in enc28j60_get_free_rxfifo()
1017 mutex_lock(&priv->lock); in enc28j60_get_free_rxfifo()
1018 epkcnt = nolock_regb_read(priv, EPKTCNT); in enc28j60_get_free_rxfifo()
1022 erxst = nolock_regw_read(priv, ERXSTL); in enc28j60_get_free_rxfifo()
1023 erxnd = nolock_regw_read(priv, ERXNDL); in enc28j60_get_free_rxfifo()
1024 erxwr = nolock_regw_read(priv, ERXWRPTL); in enc28j60_get_free_rxfifo()
1025 erxrd = nolock_regw_read(priv, ERXRDPTL); in enc28j60_get_free_rxfifo()
1034 mutex_unlock(&priv->lock); in enc28j60_get_free_rxfifo()
1035 if (netif_msg_rx_status(priv)) in enc28j60_get_free_rxfifo()
1046 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_check_link_status() local
1047 struct device *dev = &priv->spi->dev; in enc28j60_check_link_status()
1051 reg = enc28j60_phy_read(priv, PHSTAT2); in enc28j60_check_link_status()
1052 if (netif_msg_hw(priv)) in enc28j60_check_link_status()
1055 enc28j60_phy_read(priv, PHSTAT1), reg); in enc28j60_check_link_status()
1060 if (netif_msg_ifup(priv)) in enc28j60_check_link_status()
1064 if (netif_msg_ifdown(priv)) in enc28j60_check_link_status()
1072 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_tx_clear() local
1079 if (priv->tx_skb) { in enc28j60_tx_clear()
1081 ndev->stats.tx_bytes += priv->tx_skb->len; in enc28j60_tx_clear()
1082 dev_kfree_skb(priv->tx_skb); in enc28j60_tx_clear()
1083 priv->tx_skb = NULL; in enc28j60_tx_clear()
1085 locked_reg_bfclr(priv, ECON1, ECON1_TXRTS); in enc28j60_tx_clear()
1099 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_rx_interrupt() local
1102 pk_counter = locked_regb_read(priv, EPKTCNT); in enc28j60_rx_interrupt()
1103 if (pk_counter && netif_msg_intr(priv)) in enc28j60_rx_interrupt()
1106 if (pk_counter > priv->max_pk_counter) { in enc28j60_rx_interrupt()
1108 priv->max_pk_counter = pk_counter; in enc28j60_rx_interrupt()
1109 if (netif_msg_rx_status(priv) && priv->max_pk_counter > 1) in enc28j60_rx_interrupt()
1111 priv->max_pk_counter); in enc28j60_rx_interrupt()
1122 struct enc28j60_net *priv = dev_id; in enc28j60_irq() local
1123 struct net_device *ndev = priv->netdev; in enc28j60_irq()
1127 locked_reg_bfclr(priv, EIE, EIE_INTIE); in enc28j60_irq()
1131 intflags = locked_regb_read(priv, EIR); in enc28j60_irq()
1135 if (netif_msg_intr(priv)) in enc28j60_irq()
1138 locked_reg_bfclr(priv, EIR, EIR_DMAIF); in enc28j60_irq()
1143 if (netif_msg_intr(priv)) in enc28j60_irq()
1148 enc28j60_phy_read(priv, PHIR); in enc28j60_irq()
1155 if (netif_msg_intr(priv)) in enc28j60_irq()
1158 priv->tx_retry_count = 0; in enc28j60_irq()
1159 if (locked_regb_read(priv, ESTAT) & ESTAT_TXABRT) { in enc28j60_irq()
1160 if (netif_msg_tx_err(priv)) in enc28j60_irq()
1164 if (netif_msg_tx_done(priv)) { in enc28j60_irq()
1166 enc28j60_read_tsv(priv, tsv); in enc28j60_irq()
1167 enc28j60_dump_tsv(priv, "Tx Done", tsv); in enc28j60_irq()
1170 locked_reg_bfclr(priv, EIR, EIR_TXIF); in enc28j60_irq()
1177 if (netif_msg_intr(priv)) in enc28j60_irq()
1180 locked_reg_bfclr(priv, ECON1, ECON1_TXRTS); in enc28j60_irq()
1181 enc28j60_read_tsv(priv, tsv); in enc28j60_irq()
1182 if (netif_msg_tx_err(priv)) in enc28j60_irq()
1183 enc28j60_dump_tsv(priv, "Tx Error", tsv); in enc28j60_irq()
1185 mutex_lock(&priv->lock); in enc28j60_irq()
1186 nolock_reg_bfset(priv, ECON1, ECON1_TXRST); in enc28j60_irq()
1187 nolock_reg_bfclr(priv, ECON1, ECON1_TXRST); in enc28j60_irq()
1188 nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT); in enc28j60_irq()
1189 mutex_unlock(&priv->lock); in enc28j60_irq()
1192 if (netif_msg_tx_err(priv)) in enc28j60_irq()
1195 priv->tx_retry_count); in enc28j60_irq()
1196 if (priv->tx_retry_count++ < MAX_TX_RETRYCOUNT) in enc28j60_irq()
1197 locked_reg_bfset(priv, ECON1, in enc28j60_irq()
1203 locked_reg_bfclr(priv, EIR, EIR_TXERIF | EIR_TXIF); in enc28j60_irq()
1208 if (netif_msg_intr(priv)) in enc28j60_irq()
1212 if (enc28j60_get_free_rxfifo(priv) <= 0) { in enc28j60_irq()
1213 if (netif_msg_rx_err(priv)) in enc28j60_irq()
1217 locked_reg_bfclr(priv, EIR, EIR_RXERIF); in enc28j60_irq()
1225 locked_reg_bfset(priv, EIE, EIE_INTIE); in enc28j60_irq()
1235 static void enc28j60_hw_tx(struct enc28j60_net *priv) in enc28j60_hw_tx() argument
1237 struct net_device *ndev = priv->netdev; in enc28j60_hw_tx()
1239 BUG_ON(!priv->tx_skb); in enc28j60_hw_tx()
1241 if (netif_msg_tx_queued(priv)) in enc28j60_hw_tx()
1243 priv->tx_skb->len); in enc28j60_hw_tx()
1245 if (netif_msg_pktdata(priv)) in enc28j60_hw_tx()
1247 priv->tx_skb->len, priv->tx_skb->data); in enc28j60_hw_tx()
1248 enc28j60_packet_write(priv, priv->tx_skb->len, priv->tx_skb->data); in enc28j60_hw_tx()
1252 if (netif_msg_drv(priv)) { in enc28j60_hw_tx()
1253 struct device *dev = &priv->spi->dev; in enc28j60_hw_tx()
1258 test_len = priv->tx_skb->len; in enc28j60_hw_tx()
1263 enc28j60_mem_read(priv, TXSTART_INIT + 1, test_len, test_buf); in enc28j60_hw_tx()
1266 if (priv->tx_skb->data[k] != test_buf[k]) { in enc28j60_hw_tx()
1269 k, priv->tx_skb->data[k], test_buf[k]); in enc28j60_hw_tx()
1278 locked_reg_bfset(priv, ECON1, ECON1_TXRTS); in enc28j60_hw_tx()
1284 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_send_packet() local
1297 priv->tx_skb = skb; in enc28j60_send_packet()
1298 schedule_work(&priv->tx_work); in enc28j60_send_packet()
1305 struct enc28j60_net *priv = in enc28j60_tx_work_handler() local
1309 enc28j60_hw_tx(priv); in enc28j60_tx_work_handler()
1314 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_tx_timeout() local
1316 if (netif_msg_timer(priv)) in enc28j60_tx_timeout()
1321 schedule_work(&priv->restart_work); in enc28j60_tx_timeout()
1334 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_net_open() local
1337 if (netif_msg_ifup(priv)) in enc28j60_net_open()
1342 enc28j60_lowpower(priv, false); in enc28j60_net_open()
1343 enc28j60_hw_disable(priv); in enc28j60_net_open()
1344 if (!enc28j60_hw_init(priv)) { in enc28j60_net_open()
1345 if (netif_msg_ifup(priv)) in enc28j60_net_open()
1352 enc28j60_hw_enable(priv); in enc28j60_net_open()
1366 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_net_close() local
1368 enc28j60_hw_disable(priv); in enc28j60_net_close()
1369 enc28j60_lowpower(priv, true); in enc28j60_net_close()
1383 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_set_multicast_list() local
1384 int oldfilter = priv->rxfilter; in enc28j60_set_multicast_list()
1387 if (netif_msg_link(priv)) in enc28j60_set_multicast_list()
1389 priv->rxfilter = RXFILTER_PROMISC; in enc28j60_set_multicast_list()
1391 if (netif_msg_link(priv)) in enc28j60_set_multicast_list()
1394 priv->rxfilter = RXFILTER_MULTI; in enc28j60_set_multicast_list()
1396 if (netif_msg_link(priv)) in enc28j60_set_multicast_list()
1398 priv->rxfilter = RXFILTER_NORMAL; in enc28j60_set_multicast_list()
1401 if (oldfilter != priv->rxfilter) in enc28j60_set_multicast_list()
1402 schedule_work(&priv->setrx_work); in enc28j60_set_multicast_list()
1407 struct enc28j60_net *priv = in enc28j60_setrx_work_handler() local
1409 struct device *dev = &priv->spi->dev; in enc28j60_setrx_work_handler()
1411 if (priv->rxfilter == RXFILTER_PROMISC) { in enc28j60_setrx_work_handler()
1412 if (netif_msg_drv(priv)) in enc28j60_setrx_work_handler()
1414 locked_regb_write(priv, ERXFCON, 0x00); in enc28j60_setrx_work_handler()
1415 } else if (priv->rxfilter == RXFILTER_MULTI) { in enc28j60_setrx_work_handler()
1416 if (netif_msg_drv(priv)) in enc28j60_setrx_work_handler()
1418 locked_regb_write(priv, ERXFCON, in enc28j60_setrx_work_handler()
1422 if (netif_msg_drv(priv)) in enc28j60_setrx_work_handler()
1424 locked_regb_write(priv, ERXFCON, in enc28j60_setrx_work_handler()
1432 struct enc28j60_net *priv = in enc28j60_restart_work_handler() local
1434 struct net_device *ndev = priv->netdev; in enc28j60_restart_work_handler()
1464 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_get_link_ksettings() local
1472 cmd->base.duplex = priv->full_duplex ? DUPLEX_FULL : DUPLEX_HALF; in enc28j60_get_link_ksettings()
1489 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_get_msglevel() local
1490 return priv->msg_enable; in enc28j60_get_msglevel()
1495 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_set_msglevel() local
1496 priv->msg_enable = val; in enc28j60_set_msglevel()
1509 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_chipset_init() local
1511 return enc28j60_hw_init(priv); in enc28j60_chipset_init()
1527 struct enc28j60_net *priv; in enc28j60_probe() local
1538 priv = netdev_priv(dev); in enc28j60_probe()
1540 priv->netdev = dev; /* priv to netdev reference */ in enc28j60_probe()
1541 priv->spi = spi; /* priv to spi reference */ in enc28j60_probe()
1542 priv->msg_enable = netif_msg_init(debug.msg_enable, ENC28J60_MSG_DEFAULT); in enc28j60_probe()
1543 mutex_init(&priv->lock); in enc28j60_probe()
1544 INIT_WORK(&priv->tx_work, enc28j60_tx_work_handler); in enc28j60_probe()
1545 INIT_WORK(&priv->setrx_work, enc28j60_setrx_work_handler); in enc28j60_probe()
1546 INIT_WORK(&priv->restart_work, enc28j60_restart_work_handler); in enc28j60_probe()
1547 spi_set_drvdata(spi, priv); /* spi to priv reference */ in enc28j60_probe()
1551 if (netif_msg_probe(priv)) in enc28j60_probe()
1565 DRV_NAME, priv); in enc28j60_probe()
1567 if (netif_msg_probe(priv)) in enc28j60_probe()
1579 enc28j60_lowpower(priv, true); in enc28j60_probe()
1583 if (netif_msg_probe(priv)) in enc28j60_probe()
1592 free_irq(spi->irq, priv); in enc28j60_probe()
1601 struct enc28j60_net *priv = spi_get_drvdata(spi); in enc28j60_remove() local
1603 unregister_netdev(priv->netdev); in enc28j60_remove()
1604 free_irq(spi->irq, priv); in enc28j60_remove()
1605 free_netdev(priv->netdev); in enc28j60_remove()