Lines Matching refs:priv
85 spi_read_buf(struct enc28j60_net *priv, int len, u8 *data) in spi_read_buf() argument
87 struct device *dev = &priv->spi->dev; in spi_read_buf()
88 u8 *rx_buf = priv->spi_transfer_buf + 4; in spi_read_buf()
89 u8 *tx_buf = priv->spi_transfer_buf; in spi_read_buf()
107 ret = spi_sync(priv->spi, &msg); in spi_read_buf()
112 if (ret && netif_msg_drv(priv)) in spi_read_buf()
122 static int spi_write_buf(struct enc28j60_net *priv, int len, const u8 *data) in spi_write_buf() argument
124 struct device *dev = &priv->spi->dev; in spi_write_buf()
130 priv->spi_transfer_buf[0] = ENC28J60_WRITE_BUF_MEM; in spi_write_buf()
131 memcpy(&priv->spi_transfer_buf[1], data, len); in spi_write_buf()
132 ret = spi_write(priv->spi, priv->spi_transfer_buf, len + 1); in spi_write_buf()
133 if (ret && netif_msg_drv(priv)) in spi_write_buf()
143 static u8 spi_read_op(struct enc28j60_net *priv, u8 op, u8 addr) in spi_read_op() argument
145 struct device *dev = &priv->spi->dev; in spi_read_op()
157 ret = spi_write_then_read(priv->spi, tx_buf, 1, rx_buf, slen); in spi_read_op()
170 static int spi_write_op(struct enc28j60_net *priv, u8 op, u8 addr, u8 val) in spi_write_op() argument
172 struct device *dev = &priv->spi->dev; in spi_write_op()
175 priv->spi_transfer_buf[0] = op | (addr & ADDR_MASK); in spi_write_op()
176 priv->spi_transfer_buf[1] = val; in spi_write_op()
177 ret = spi_write(priv->spi, priv->spi_transfer_buf, 2); in spi_write_op()
178 if (ret && netif_msg_drv(priv)) in spi_write_op()
184 static void enc28j60_soft_reset(struct enc28j60_net *priv) in enc28j60_soft_reset() argument
186 spi_write_op(priv, ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET); in enc28j60_soft_reset()
195 static void enc28j60_set_bank(struct enc28j60_net *priv, u8 addr) in enc28j60_set_bank() argument
206 if ((b & ECON1_BSEL0) != (priv->bank & ECON1_BSEL0)) { in enc28j60_set_bank()
208 spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1, in enc28j60_set_bank()
211 spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1, in enc28j60_set_bank()
214 if ((b & ECON1_BSEL1) != (priv->bank & ECON1_BSEL1)) { in enc28j60_set_bank()
216 spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1, in enc28j60_set_bank()
219 spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1, in enc28j60_set_bank()
222 priv->bank = b; in enc28j60_set_bank()
239 static void nolock_reg_bfset(struct enc28j60_net *priv, u8 addr, u8 mask) in nolock_reg_bfset() argument
241 enc28j60_set_bank(priv, addr); in nolock_reg_bfset()
242 spi_write_op(priv, ENC28J60_BIT_FIELD_SET, addr, mask); in nolock_reg_bfset()
245 static void locked_reg_bfset(struct enc28j60_net *priv, u8 addr, u8 mask) in locked_reg_bfset() argument
247 mutex_lock(&priv->lock); in locked_reg_bfset()
248 nolock_reg_bfset(priv, addr, mask); in locked_reg_bfset()
249 mutex_unlock(&priv->lock); in locked_reg_bfset()
255 static void nolock_reg_bfclr(struct enc28j60_net *priv, u8 addr, u8 mask) in nolock_reg_bfclr() argument
257 enc28j60_set_bank(priv, addr); in nolock_reg_bfclr()
258 spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, addr, mask); in nolock_reg_bfclr()
261 static void locked_reg_bfclr(struct enc28j60_net *priv, u8 addr, u8 mask) in locked_reg_bfclr() argument
263 mutex_lock(&priv->lock); in locked_reg_bfclr()
264 nolock_reg_bfclr(priv, addr, mask); in locked_reg_bfclr()
265 mutex_unlock(&priv->lock); in locked_reg_bfclr()
271 static int nolock_regb_read(struct enc28j60_net *priv, u8 address) in nolock_regb_read() argument
273 enc28j60_set_bank(priv, address); in nolock_regb_read()
274 return spi_read_op(priv, ENC28J60_READ_CTRL_REG, address); in nolock_regb_read()
277 static int locked_regb_read(struct enc28j60_net *priv, u8 address) in locked_regb_read() argument
281 mutex_lock(&priv->lock); in locked_regb_read()
282 ret = nolock_regb_read(priv, address); in locked_regb_read()
283 mutex_unlock(&priv->lock); in locked_regb_read()
291 static int nolock_regw_read(struct enc28j60_net *priv, u8 address) in nolock_regw_read() argument
295 enc28j60_set_bank(priv, address); in nolock_regw_read()
296 rl = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address); in nolock_regw_read()
297 rh = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address + 1); in nolock_regw_read()
302 static int locked_regw_read(struct enc28j60_net *priv, u8 address) in locked_regw_read() argument
306 mutex_lock(&priv->lock); in locked_regw_read()
307 ret = nolock_regw_read(priv, address); in locked_regw_read()
308 mutex_unlock(&priv->lock); in locked_regw_read()
316 static void nolock_regb_write(struct enc28j60_net *priv, u8 address, u8 data) in nolock_regb_write() argument
318 enc28j60_set_bank(priv, address); in nolock_regb_write()
319 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, data); in nolock_regb_write()
322 static void locked_regb_write(struct enc28j60_net *priv, u8 address, u8 data) in locked_regb_write() argument
324 mutex_lock(&priv->lock); in locked_regb_write()
325 nolock_regb_write(priv, address, data); in locked_regb_write()
326 mutex_unlock(&priv->lock); in locked_regb_write()
332 static void nolock_regw_write(struct enc28j60_net *priv, u8 address, u16 data) in nolock_regw_write() argument
334 enc28j60_set_bank(priv, address); in nolock_regw_write()
335 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, (u8) data); in nolock_regw_write()
336 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address + 1, in nolock_regw_write()
340 static void locked_regw_write(struct enc28j60_net *priv, u8 address, u16 data) in locked_regw_write() argument
342 mutex_lock(&priv->lock); in locked_regw_write()
343 nolock_regw_write(priv, address, data); in locked_regw_write()
344 mutex_unlock(&priv->lock); in locked_regw_write()
351 static void enc28j60_mem_read(struct enc28j60_net *priv, u16 addr, int len, in enc28j60_mem_read() argument
354 mutex_lock(&priv->lock); in enc28j60_mem_read()
355 nolock_regw_write(priv, ERDPTL, addr); in enc28j60_mem_read()
357 if (netif_msg_drv(priv)) { in enc28j60_mem_read()
358 struct device *dev = &priv->spi->dev; in enc28j60_mem_read()
361 reg = nolock_regw_read(priv, ERDPTL); in enc28j60_mem_read()
368 spi_read_buf(priv, len, data); in enc28j60_mem_read()
369 mutex_unlock(&priv->lock); in enc28j60_mem_read()
376 enc28j60_packet_write(struct enc28j60_net *priv, int len, const u8 *data) in enc28j60_packet_write() argument
378 struct device *dev = &priv->spi->dev; in enc28j60_packet_write()
380 mutex_lock(&priv->lock); in enc28j60_packet_write()
382 nolock_regw_write(priv, EWRPTL, TXSTART_INIT); in enc28j60_packet_write()
384 if (netif_msg_drv(priv)) { in enc28j60_packet_write()
386 reg = nolock_regw_read(priv, EWRPTL); in enc28j60_packet_write()
394 nolock_regw_write(priv, ETXNDL, TXSTART_INIT + len); in enc28j60_packet_write()
396 spi_write_op(priv, ENC28J60_WRITE_BUF_MEM, 0, 0x00); in enc28j60_packet_write()
397 if (netif_msg_hw(priv)) in enc28j60_packet_write()
400 __func__, nolock_regw_read(priv, EWRPTL)); in enc28j60_packet_write()
402 spi_write_buf(priv, len, data); in enc28j60_packet_write()
403 if (netif_msg_hw(priv)) in enc28j60_packet_write()
406 __func__, nolock_regw_read(priv, EWRPTL), len); in enc28j60_packet_write()
407 mutex_unlock(&priv->lock); in enc28j60_packet_write()
410 static int poll_ready(struct enc28j60_net *priv, u8 reg, u8 mask, u8 val) in poll_ready() argument
412 struct device *dev = &priv->spi->dev; in poll_ready()
416 while ((nolock_regb_read(priv, reg) & mask) != val) { in poll_ready()
418 if (netif_msg_drv(priv)) in poll_ready()
430 static int wait_phy_ready(struct enc28j60_net *priv) in wait_phy_ready() argument
432 return poll_ready(priv, MISTAT, MISTAT_BUSY, 0) ? 0 : 1; in wait_phy_ready()
439 static u16 enc28j60_phy_read(struct enc28j60_net *priv, u8 address) in enc28j60_phy_read() argument
443 mutex_lock(&priv->lock); in enc28j60_phy_read()
445 nolock_regb_write(priv, MIREGADR, address); in enc28j60_phy_read()
447 nolock_regb_write(priv, MICMD, MICMD_MIIRD); in enc28j60_phy_read()
449 wait_phy_ready(priv); in enc28j60_phy_read()
451 nolock_regb_write(priv, MICMD, 0x00); in enc28j60_phy_read()
453 ret = nolock_regw_read(priv, MIRDL); in enc28j60_phy_read()
454 mutex_unlock(&priv->lock); in enc28j60_phy_read()
459 static int enc28j60_phy_write(struct enc28j60_net *priv, u8 address, u16 data) in enc28j60_phy_write() argument
463 mutex_lock(&priv->lock); in enc28j60_phy_write()
465 nolock_regb_write(priv, MIREGADR, address); in enc28j60_phy_write()
467 nolock_regw_write(priv, MIWRL, data); in enc28j60_phy_write()
469 ret = wait_phy_ready(priv); in enc28j60_phy_write()
470 mutex_unlock(&priv->lock); in enc28j60_phy_write()
481 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_set_hw_macaddr() local
482 struct device *dev = &priv->spi->dev; in enc28j60_set_hw_macaddr()
484 mutex_lock(&priv->lock); in enc28j60_set_hw_macaddr()
485 if (!priv->hw_enable) { in enc28j60_set_hw_macaddr()
486 if (netif_msg_drv(priv)) in enc28j60_set_hw_macaddr()
490 nolock_regb_write(priv, MAADR5, ndev->dev_addr[0]); in enc28j60_set_hw_macaddr()
491 nolock_regb_write(priv, MAADR4, ndev->dev_addr[1]); in enc28j60_set_hw_macaddr()
492 nolock_regb_write(priv, MAADR3, ndev->dev_addr[2]); in enc28j60_set_hw_macaddr()
493 nolock_regb_write(priv, MAADR2, ndev->dev_addr[3]); in enc28j60_set_hw_macaddr()
494 nolock_regb_write(priv, MAADR1, ndev->dev_addr[4]); in enc28j60_set_hw_macaddr()
495 nolock_regb_write(priv, MAADR0, ndev->dev_addr[5]); in enc28j60_set_hw_macaddr()
498 if (netif_msg_drv(priv)) in enc28j60_set_hw_macaddr()
504 mutex_unlock(&priv->lock); in enc28j60_set_hw_macaddr()
527 static void enc28j60_dump_regs(struct enc28j60_net *priv, const char *msg) in enc28j60_dump_regs() argument
529 struct device *dev = &priv->spi->dev; in enc28j60_dump_regs()
531 mutex_lock(&priv->lock); in enc28j60_dump_regs()
544 msg, nolock_regb_read(priv, EREVID), in enc28j60_dump_regs()
545 nolock_regb_read(priv, ECON1), nolock_regb_read(priv, ECON2), in enc28j60_dump_regs()
546 nolock_regb_read(priv, ESTAT), nolock_regb_read(priv, EIR), in enc28j60_dump_regs()
547 nolock_regb_read(priv, EIE), nolock_regb_read(priv, MACON1), in enc28j60_dump_regs()
548 nolock_regb_read(priv, MACON3), nolock_regb_read(priv, MACON4), in enc28j60_dump_regs()
549 nolock_regw_read(priv, ERXSTL), nolock_regw_read(priv, ERXNDL), in enc28j60_dump_regs()
550 nolock_regw_read(priv, ERXWRPTL), in enc28j60_dump_regs()
551 nolock_regw_read(priv, ERXRDPTL), in enc28j60_dump_regs()
552 nolock_regb_read(priv, ERXFCON), in enc28j60_dump_regs()
553 nolock_regb_read(priv, EPKTCNT), in enc28j60_dump_regs()
554 nolock_regw_read(priv, MAMXFLL), nolock_regw_read(priv, ETXSTL), in enc28j60_dump_regs()
555 nolock_regw_read(priv, ETXNDL), in enc28j60_dump_regs()
556 nolock_regb_read(priv, MACLCON1), in enc28j60_dump_regs()
557 nolock_regb_read(priv, MACLCON2), in enc28j60_dump_regs()
558 nolock_regb_read(priv, MAPHSUP)); in enc28j60_dump_regs()
559 mutex_unlock(&priv->lock); in enc28j60_dump_regs()
588 static void nolock_rxfifo_init(struct enc28j60_net *priv, u16 start, u16 end) in nolock_rxfifo_init() argument
590 struct device *dev = &priv->spi->dev; in nolock_rxfifo_init()
594 if (netif_msg_drv(priv)) in nolock_rxfifo_init()
600 priv->next_pk_ptr = start; in nolock_rxfifo_init()
601 nolock_regw_write(priv, ERXSTL, start); in nolock_rxfifo_init()
602 erxrdpt = erxrdpt_workaround(priv->next_pk_ptr, start, end); in nolock_rxfifo_init()
603 nolock_regw_write(priv, ERXRDPTL, erxrdpt); in nolock_rxfifo_init()
604 nolock_regw_write(priv, ERXNDL, end); in nolock_rxfifo_init()
607 static void nolock_txfifo_init(struct enc28j60_net *priv, u16 start, u16 end) in nolock_txfifo_init() argument
609 struct device *dev = &priv->spi->dev; in nolock_txfifo_init()
612 if (netif_msg_drv(priv)) in nolock_txfifo_init()
618 nolock_regw_write(priv, ETXSTL, start); in nolock_txfifo_init()
619 nolock_regw_write(priv, ETXNDL, end); in nolock_txfifo_init()
627 static void enc28j60_lowpower(struct enc28j60_net *priv, bool is_low) in enc28j60_lowpower() argument
629 struct device *dev = &priv->spi->dev; in enc28j60_lowpower()
631 if (netif_msg_drv(priv)) in enc28j60_lowpower()
634 mutex_lock(&priv->lock); in enc28j60_lowpower()
636 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN); in enc28j60_lowpower()
637 poll_ready(priv, ESTAT, ESTAT_RXBUSY, 0); in enc28j60_lowpower()
638 poll_ready(priv, ECON1, ECON1_TXRTS, 0); in enc28j60_lowpower()
640 nolock_reg_bfset(priv, ECON2, ECON2_PWRSV); in enc28j60_lowpower()
642 nolock_reg_bfclr(priv, ECON2, ECON2_PWRSV); in enc28j60_lowpower()
643 poll_ready(priv, ESTAT, ESTAT_CLKRDY, ESTAT_CLKRDY); in enc28j60_lowpower()
646 mutex_unlock(&priv->lock); in enc28j60_lowpower()
649 static int enc28j60_hw_init(struct enc28j60_net *priv) in enc28j60_hw_init() argument
651 struct device *dev = &priv->spi->dev; in enc28j60_hw_init()
654 if (netif_msg_drv(priv)) in enc28j60_hw_init()
656 priv->full_duplex ? "FullDuplex" : "HalfDuplex"); in enc28j60_hw_init()
658 mutex_lock(&priv->lock); in enc28j60_hw_init()
660 enc28j60_soft_reset(priv); in enc28j60_hw_init()
662 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, ECON1, 0x00); in enc28j60_hw_init()
663 priv->bank = 0; in enc28j60_hw_init()
664 priv->hw_enable = false; in enc28j60_hw_init()
665 priv->tx_retry_count = 0; in enc28j60_hw_init()
666 priv->max_pk_counter = 0; in enc28j60_hw_init()
667 priv->rxfilter = RXFILTER_NORMAL; in enc28j60_hw_init()
669 nolock_regb_write(priv, ECON2, ECON2_AUTOINC | ECON2_VRPS); in enc28j60_hw_init()
671 nolock_rxfifo_init(priv, RXSTART_INIT, RXEND_INIT); in enc28j60_hw_init()
672 nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT); in enc28j60_hw_init()
673 mutex_unlock(&priv->lock); in enc28j60_hw_init()
680 reg = locked_regb_read(priv, EREVID); in enc28j60_hw_init()
681 if (netif_msg_drv(priv)) in enc28j60_hw_init()
684 if (netif_msg_drv(priv)) in enc28j60_hw_init()
691 locked_regb_write(priv, ERXFCON, in enc28j60_hw_init()
695 locked_regb_write(priv, MACON1, in enc28j60_hw_init()
698 if (priv->full_duplex) { in enc28j60_hw_init()
699 locked_regb_write(priv, MACON3, in enc28j60_hw_init()
703 locked_regb_write(priv, MAIPGL, 0x12); in enc28j60_hw_init()
705 locked_regb_write(priv, MABBIPG, 0x15); in enc28j60_hw_init()
707 locked_regb_write(priv, MACON3, in enc28j60_hw_init()
710 locked_regb_write(priv, MACON4, 1 << 6); /* DEFER bit */ in enc28j60_hw_init()
712 locked_regw_write(priv, MAIPGL, 0x0C12); in enc28j60_hw_init()
714 locked_regb_write(priv, MABBIPG, 0x12); in enc28j60_hw_init()
721 locked_regw_write(priv, MAMXFLL, MAX_FRAMELEN); in enc28j60_hw_init()
724 if (!enc28j60_phy_write(priv, PHLCON, ENC28J60_LAMPS_MODE)) in enc28j60_hw_init()
727 if (priv->full_duplex) { in enc28j60_hw_init()
728 if (!enc28j60_phy_write(priv, PHCON1, PHCON1_PDPXMD)) in enc28j60_hw_init()
730 if (!enc28j60_phy_write(priv, PHCON2, 0x00)) in enc28j60_hw_init()
733 if (!enc28j60_phy_write(priv, PHCON1, 0x00)) in enc28j60_hw_init()
735 if (!enc28j60_phy_write(priv, PHCON2, PHCON2_HDLDIS)) in enc28j60_hw_init()
738 if (netif_msg_hw(priv)) in enc28j60_hw_init()
739 enc28j60_dump_regs(priv, "Hw initialized."); in enc28j60_hw_init()
744 static void enc28j60_hw_enable(struct enc28j60_net *priv) in enc28j60_hw_enable() argument
746 struct device *dev = &priv->spi->dev; in enc28j60_hw_enable()
749 if (netif_msg_hw(priv)) in enc28j60_hw_enable()
753 enc28j60_phy_write(priv, PHIE, PHIE_PGEIE | PHIE_PLNKIE); in enc28j60_hw_enable()
755 mutex_lock(&priv->lock); in enc28j60_hw_enable()
756 nolock_reg_bfclr(priv, EIR, EIR_DMAIF | EIR_LINKIF | in enc28j60_hw_enable()
758 nolock_regb_write(priv, EIE, EIE_INTIE | EIE_PKTIE | EIE_LINKIE | in enc28j60_hw_enable()
762 nolock_reg_bfset(priv, ECON1, ECON1_RXEN); in enc28j60_hw_enable()
763 priv->hw_enable = true; in enc28j60_hw_enable()
764 mutex_unlock(&priv->lock); in enc28j60_hw_enable()
767 static void enc28j60_hw_disable(struct enc28j60_net *priv) in enc28j60_hw_disable() argument
769 mutex_lock(&priv->lock); in enc28j60_hw_disable()
771 nolock_regb_write(priv, EIE, 0x00); in enc28j60_hw_disable()
772 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN); in enc28j60_hw_disable()
773 priv->hw_enable = false; in enc28j60_hw_disable()
774 mutex_unlock(&priv->lock); in enc28j60_hw_disable()
780 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_setlink() local
783 if (!priv->hw_enable) { in enc28j60_setlink()
788 priv->full_duplex = (duplex == DUPLEX_FULL); in enc28j60_setlink()
790 if (netif_msg_link(priv)) in enc28j60_setlink()
795 if (netif_msg_link(priv)) in enc28j60_setlink()
805 static void enc28j60_read_tsv(struct enc28j60_net *priv, u8 tsv[TSV_SIZE]) in enc28j60_read_tsv() argument
807 struct device *dev = &priv->spi->dev; in enc28j60_read_tsv()
810 endptr = locked_regw_read(priv, ETXNDL); in enc28j60_read_tsv()
811 if (netif_msg_hw(priv)) in enc28j60_read_tsv()
814 enc28j60_mem_read(priv, endptr + 1, TSV_SIZE, tsv); in enc28j60_read_tsv()
817 static void enc28j60_dump_tsv(struct enc28j60_net *priv, const char *msg, in enc28j60_dump_tsv() argument
820 struct device *dev = &priv->spi->dev; in enc28j60_dump_tsv()
863 static void enc28j60_dump_rsv(struct enc28j60_net *priv, const char *msg, in enc28j60_dump_rsv() argument
866 struct device *dev = &priv->spi->dev; in enc28j60_dump_rsv()
905 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_hw_rx() local
906 struct device *dev = &priv->spi->dev; in enc28j60_hw_rx()
912 if (netif_msg_rx_status(priv)) in enc28j60_hw_rx()
914 priv->next_pk_ptr); in enc28j60_hw_rx()
916 if (unlikely(priv->next_pk_ptr > RXEND_INIT)) { in enc28j60_hw_rx()
917 if (netif_msg_rx_err(priv)) in enc28j60_hw_rx()
919 __func__, priv->next_pk_ptr); in enc28j60_hw_rx()
921 mutex_lock(&priv->lock); in enc28j60_hw_rx()
922 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN); in enc28j60_hw_rx()
923 nolock_reg_bfset(priv, ECON1, ECON1_RXRST); in enc28j60_hw_rx()
924 nolock_reg_bfclr(priv, ECON1, ECON1_RXRST); in enc28j60_hw_rx()
925 nolock_rxfifo_init(priv, RXSTART_INIT, RXEND_INIT); in enc28j60_hw_rx()
926 nolock_reg_bfclr(priv, EIR, EIR_RXERIF); in enc28j60_hw_rx()
927 nolock_reg_bfset(priv, ECON1, ECON1_RXEN); in enc28j60_hw_rx()
928 mutex_unlock(&priv->lock); in enc28j60_hw_rx()
933 enc28j60_mem_read(priv, priv->next_pk_ptr, sizeof(rsv), rsv); in enc28j60_hw_rx()
947 if (netif_msg_rx_status(priv)) in enc28j60_hw_rx()
948 enc28j60_dump_rsv(priv, __func__, next_packet, len, rxstat); in enc28j60_hw_rx()
951 if (netif_msg_rx_err(priv)) in enc28j60_hw_rx()
963 if (netif_msg_rx_err(priv)) in enc28j60_hw_rx()
969 enc28j60_mem_read(priv, in enc28j60_hw_rx()
970 rx_packet_start(priv->next_pk_ptr), in enc28j60_hw_rx()
972 if (netif_msg_pktdata(priv)) in enc28j60_hw_rx()
987 if (netif_msg_hw(priv)) in enc28j60_hw_rx()
991 mutex_lock(&priv->lock); in enc28j60_hw_rx()
992 nolock_regw_write(priv, ERXRDPTL, erxrdpt); in enc28j60_hw_rx()
994 if (netif_msg_drv(priv)) { in enc28j60_hw_rx()
996 reg = nolock_regw_read(priv, ERXRDPTL); in enc28j60_hw_rx()
1003 priv->next_pk_ptr = next_packet; in enc28j60_hw_rx()
1005 nolock_reg_bfset(priv, ECON2, ECON2_PKTDEC); in enc28j60_hw_rx()
1006 mutex_unlock(&priv->lock); in enc28j60_hw_rx()
1012 static int enc28j60_get_free_rxfifo(struct enc28j60_net *priv) in enc28j60_get_free_rxfifo() argument
1014 struct net_device *ndev = priv->netdev; in enc28j60_get_free_rxfifo()
1018 mutex_lock(&priv->lock); in enc28j60_get_free_rxfifo()
1019 epkcnt = nolock_regb_read(priv, EPKTCNT); in enc28j60_get_free_rxfifo()
1023 erxst = nolock_regw_read(priv, ERXSTL); in enc28j60_get_free_rxfifo()
1024 erxnd = nolock_regw_read(priv, ERXNDL); in enc28j60_get_free_rxfifo()
1025 erxwr = nolock_regw_read(priv, ERXWRPTL); in enc28j60_get_free_rxfifo()
1026 erxrd = nolock_regw_read(priv, ERXRDPTL); in enc28j60_get_free_rxfifo()
1035 mutex_unlock(&priv->lock); in enc28j60_get_free_rxfifo()
1036 if (netif_msg_rx_status(priv)) in enc28j60_get_free_rxfifo()
1047 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_check_link_status() local
1048 struct device *dev = &priv->spi->dev; in enc28j60_check_link_status()
1052 reg = enc28j60_phy_read(priv, PHSTAT2); in enc28j60_check_link_status()
1053 if (netif_msg_hw(priv)) in enc28j60_check_link_status()
1056 enc28j60_phy_read(priv, PHSTAT1), reg); in enc28j60_check_link_status()
1061 if (netif_msg_ifup(priv)) in enc28j60_check_link_status()
1065 if (netif_msg_ifdown(priv)) in enc28j60_check_link_status()
1073 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_tx_clear() local
1080 if (priv->tx_skb) { in enc28j60_tx_clear()
1082 ndev->stats.tx_bytes += priv->tx_skb->len; in enc28j60_tx_clear()
1083 dev_kfree_skb(priv->tx_skb); in enc28j60_tx_clear()
1084 priv->tx_skb = NULL; in enc28j60_tx_clear()
1086 locked_reg_bfclr(priv, ECON1, ECON1_TXRTS); in enc28j60_tx_clear()
1100 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_rx_interrupt() local
1103 pk_counter = locked_regb_read(priv, EPKTCNT); in enc28j60_rx_interrupt()
1104 if (pk_counter && netif_msg_intr(priv)) in enc28j60_rx_interrupt()
1107 if (pk_counter > priv->max_pk_counter) { in enc28j60_rx_interrupt()
1109 priv->max_pk_counter = pk_counter; in enc28j60_rx_interrupt()
1110 if (netif_msg_rx_status(priv) && priv->max_pk_counter > 1) in enc28j60_rx_interrupt()
1112 priv->max_pk_counter); in enc28j60_rx_interrupt()
1123 struct enc28j60_net *priv = in enc28j60_irq_work_handler() local
1125 struct net_device *ndev = priv->netdev; in enc28j60_irq_work_handler()
1129 locked_reg_bfclr(priv, EIE, EIE_INTIE); in enc28j60_irq_work_handler()
1133 intflags = locked_regb_read(priv, EIR); in enc28j60_irq_work_handler()
1137 if (netif_msg_intr(priv)) in enc28j60_irq_work_handler()
1140 locked_reg_bfclr(priv, EIR, EIR_DMAIF); in enc28j60_irq_work_handler()
1145 if (netif_msg_intr(priv)) in enc28j60_irq_work_handler()
1150 enc28j60_phy_read(priv, PHIR); in enc28j60_irq_work_handler()
1157 if (netif_msg_intr(priv)) in enc28j60_irq_work_handler()
1160 priv->tx_retry_count = 0; in enc28j60_irq_work_handler()
1161 if (locked_regb_read(priv, ESTAT) & ESTAT_TXABRT) { in enc28j60_irq_work_handler()
1162 if (netif_msg_tx_err(priv)) in enc28j60_irq_work_handler()
1166 if (netif_msg_tx_done(priv)) { in enc28j60_irq_work_handler()
1168 enc28j60_read_tsv(priv, tsv); in enc28j60_irq_work_handler()
1169 enc28j60_dump_tsv(priv, "Tx Done", tsv); in enc28j60_irq_work_handler()
1172 locked_reg_bfclr(priv, EIR, EIR_TXIF); in enc28j60_irq_work_handler()
1179 if (netif_msg_intr(priv)) in enc28j60_irq_work_handler()
1182 locked_reg_bfclr(priv, ECON1, ECON1_TXRTS); in enc28j60_irq_work_handler()
1183 enc28j60_read_tsv(priv, tsv); in enc28j60_irq_work_handler()
1184 if (netif_msg_tx_err(priv)) in enc28j60_irq_work_handler()
1185 enc28j60_dump_tsv(priv, "Tx Error", tsv); in enc28j60_irq_work_handler()
1187 mutex_lock(&priv->lock); in enc28j60_irq_work_handler()
1188 nolock_reg_bfset(priv, ECON1, ECON1_TXRST); in enc28j60_irq_work_handler()
1189 nolock_reg_bfclr(priv, ECON1, ECON1_TXRST); in enc28j60_irq_work_handler()
1190 nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT); in enc28j60_irq_work_handler()
1191 mutex_unlock(&priv->lock); in enc28j60_irq_work_handler()
1194 if (netif_msg_tx_err(priv)) in enc28j60_irq_work_handler()
1197 priv->tx_retry_count); in enc28j60_irq_work_handler()
1198 if (priv->tx_retry_count++ < MAX_TX_RETRYCOUNT) in enc28j60_irq_work_handler()
1199 locked_reg_bfset(priv, ECON1, in enc28j60_irq_work_handler()
1205 locked_reg_bfclr(priv, EIR, EIR_TXERIF | EIR_TXIF); in enc28j60_irq_work_handler()
1210 if (netif_msg_intr(priv)) in enc28j60_irq_work_handler()
1214 if (enc28j60_get_free_rxfifo(priv) <= 0) { in enc28j60_irq_work_handler()
1215 if (netif_msg_rx_err(priv)) in enc28j60_irq_work_handler()
1219 locked_reg_bfclr(priv, EIR, EIR_RXERIF); in enc28j60_irq_work_handler()
1227 locked_reg_bfset(priv, EIE, EIE_INTIE); in enc28j60_irq_work_handler()
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 = dev_id; in enc28j60_irq() local
1323 schedule_work(&priv->irq_work); in enc28j60_irq()
1330 struct enc28j60_net *priv = netdev_priv(ndev); in enc28j60_tx_timeout() local
1332 if (netif_msg_timer(priv)) in enc28j60_tx_timeout()
1337 schedule_work(&priv->restart_work); in enc28j60_tx_timeout()
1350 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_net_open() local
1353 if (netif_msg_ifup(priv)) in enc28j60_net_open()
1358 enc28j60_lowpower(priv, false); in enc28j60_net_open()
1359 enc28j60_hw_disable(priv); in enc28j60_net_open()
1360 if (!enc28j60_hw_init(priv)) { in enc28j60_net_open()
1361 if (netif_msg_ifup(priv)) in enc28j60_net_open()
1368 enc28j60_hw_enable(priv); in enc28j60_net_open()
1382 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_net_close() local
1384 enc28j60_hw_disable(priv); in enc28j60_net_close()
1385 enc28j60_lowpower(priv, true); in enc28j60_net_close()
1399 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_set_multicast_list() local
1400 int oldfilter = priv->rxfilter; in enc28j60_set_multicast_list()
1403 if (netif_msg_link(priv)) in enc28j60_set_multicast_list()
1405 priv->rxfilter = RXFILTER_PROMISC; in enc28j60_set_multicast_list()
1407 if (netif_msg_link(priv)) in enc28j60_set_multicast_list()
1410 priv->rxfilter = RXFILTER_MULTI; in enc28j60_set_multicast_list()
1412 if (netif_msg_link(priv)) in enc28j60_set_multicast_list()
1414 priv->rxfilter = RXFILTER_NORMAL; in enc28j60_set_multicast_list()
1417 if (oldfilter != priv->rxfilter) in enc28j60_set_multicast_list()
1418 schedule_work(&priv->setrx_work); in enc28j60_set_multicast_list()
1423 struct enc28j60_net *priv = in enc28j60_setrx_work_handler() local
1425 struct device *dev = &priv->spi->dev; in enc28j60_setrx_work_handler()
1427 if (priv->rxfilter == RXFILTER_PROMISC) { in enc28j60_setrx_work_handler()
1428 if (netif_msg_drv(priv)) in enc28j60_setrx_work_handler()
1430 locked_regb_write(priv, ERXFCON, 0x00); in enc28j60_setrx_work_handler()
1431 } else if (priv->rxfilter == RXFILTER_MULTI) { in enc28j60_setrx_work_handler()
1432 if (netif_msg_drv(priv)) in enc28j60_setrx_work_handler()
1434 locked_regb_write(priv, ERXFCON, in enc28j60_setrx_work_handler()
1438 if (netif_msg_drv(priv)) in enc28j60_setrx_work_handler()
1440 locked_regb_write(priv, ERXFCON, in enc28j60_setrx_work_handler()
1448 struct enc28j60_net *priv = in enc28j60_restart_work_handler() local
1450 struct net_device *ndev = priv->netdev; in enc28j60_restart_work_handler()
1480 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_get_link_ksettings() local
1488 cmd->base.duplex = priv->full_duplex ? DUPLEX_FULL : DUPLEX_HALF; in enc28j60_get_link_ksettings()
1505 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_get_msglevel() local
1506 return priv->msg_enable; in enc28j60_get_msglevel()
1511 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_set_msglevel() local
1512 priv->msg_enable = val; in enc28j60_set_msglevel()
1525 struct enc28j60_net *priv = netdev_priv(dev); in enc28j60_chipset_init() local
1527 return enc28j60_hw_init(priv); in enc28j60_chipset_init()
1544 struct enc28j60_net *priv; in enc28j60_probe() local
1555 priv = netdev_priv(dev); in enc28j60_probe()
1557 priv->netdev = dev; /* priv to netdev reference */ in enc28j60_probe()
1558 priv->spi = spi; /* priv to spi reference */ in enc28j60_probe()
1559 priv->msg_enable = netif_msg_init(debug.msg_enable, ENC28J60_MSG_DEFAULT); in enc28j60_probe()
1560 mutex_init(&priv->lock); in enc28j60_probe()
1561 INIT_WORK(&priv->tx_work, enc28j60_tx_work_handler); in enc28j60_probe()
1562 INIT_WORK(&priv->setrx_work, enc28j60_setrx_work_handler); in enc28j60_probe()
1563 INIT_WORK(&priv->irq_work, enc28j60_irq_work_handler); in enc28j60_probe()
1564 INIT_WORK(&priv->restart_work, enc28j60_restart_work_handler); in enc28j60_probe()
1565 spi_set_drvdata(spi, priv); /* spi to priv reference */ in enc28j60_probe()
1569 if (netif_msg_probe(priv)) in enc28j60_probe()
1584 ret = request_irq(spi->irq, enc28j60_irq, 0, DRV_NAME, priv); in enc28j60_probe()
1586 if (netif_msg_probe(priv)) in enc28j60_probe()
1598 enc28j60_lowpower(priv, true); in enc28j60_probe()
1602 if (netif_msg_probe(priv)) in enc28j60_probe()
1611 free_irq(spi->irq, priv); in enc28j60_probe()
1620 struct enc28j60_net *priv = spi_get_drvdata(spi); in enc28j60_remove() local
1622 unregister_netdev(priv->netdev); in enc28j60_remove()
1623 free_irq(spi->irq, priv); in enc28j60_remove()
1624 free_netdev(priv->netdev); in enc28j60_remove()