pnic.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. drivers/net/ethernet/dec/tulip/pnic.c
  3. Copyright 2000,2001 The Linux Kernel Team
  4. Written/copyright 1994-2001 by Donald Becker.
  5. This software may be used and distributed according to the terms
  6. of the GNU General Public License, incorporated herein by reference.
  7. Please submit bugs to http://bugzilla.kernel.org/ .
  8. */
  9. #include <linux/interrupt.h>
  10. #include <linux/kernel.h>
  11. #include <linux/jiffies.h>
  12. #include "tulip.h"
  13. void pnic_do_nway(struct net_device *dev)
  14. {
  15. struct tulip_private *tp = netdev_priv(dev);
  16. void __iomem *ioaddr = tp->base_addr;
  17. u32 phy_reg = ioread32(ioaddr + 0xB8);
  18. u32 new_csr6 = tp->csr6 & ~0x40C40200;
  19. if (phy_reg & 0x78000000) { /* Ignore baseT4 */
  20. if (phy_reg & 0x20000000) dev->if_port = 5;
  21. else if (phy_reg & 0x40000000) dev->if_port = 3;
  22. else if (phy_reg & 0x10000000) dev->if_port = 4;
  23. else if (phy_reg & 0x08000000) dev->if_port = 0;
  24. tp->nwayset = 1;
  25. new_csr6 = (dev->if_port & 1) ? 0x01860000 : 0x00420000;
  26. iowrite32(0x32 | (dev->if_port & 1), ioaddr + CSR12);
  27. if (dev->if_port & 1)
  28. iowrite32(0x1F868, ioaddr + 0xB8);
  29. if (phy_reg & 0x30000000) {
  30. tp->full_duplex = 1;
  31. new_csr6 |= 0x00000200;
  32. }
  33. if (tulip_debug > 1)
  34. netdev_dbg(dev, "PNIC autonegotiated status %08x, %s\n",
  35. phy_reg, medianame[dev->if_port]);
  36. if (tp->csr6 != new_csr6) {
  37. tp->csr6 = new_csr6;
  38. /* Restart Tx */
  39. tulip_restart_rxtx(tp);
  40. netif_trans_update(dev);
  41. }
  42. }
  43. }
  44. void pnic_lnk_change(struct net_device *dev, int csr5)
  45. {
  46. struct tulip_private *tp = netdev_priv(dev);
  47. void __iomem *ioaddr = tp->base_addr;
  48. int phy_reg = ioread32(ioaddr + 0xB8);
  49. if (tulip_debug > 1)
  50. netdev_dbg(dev, "PNIC link changed state %08x, CSR5 %08x\n",
  51. phy_reg, csr5);
  52. if (ioread32(ioaddr + CSR5) & TPLnkFail) {
  53. iowrite32((ioread32(ioaddr + CSR7) & ~TPLnkFail) | TPLnkPass, ioaddr + CSR7);
  54. /* If we use an external MII, then we mustn't use the
  55. * internal negotiation.
  56. */
  57. if (tulip_media_cap[dev->if_port] & MediaIsMII)
  58. return;
  59. if (! tp->nwayset || time_after(jiffies, dev_trans_start(dev) + 1*HZ)) {
  60. tp->csr6 = 0x00420000 | (tp->csr6 & 0x0000fdff);
  61. iowrite32(tp->csr6, ioaddr + CSR6);
  62. iowrite32(0x30, ioaddr + CSR12);
  63. iowrite32(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */
  64. netif_trans_update(dev);
  65. }
  66. } else if (ioread32(ioaddr + CSR5) & TPLnkPass) {
  67. if (tulip_media_cap[dev->if_port] & MediaIsMII) {
  68. spin_lock(&tp->lock);
  69. tulip_check_duplex(dev);
  70. spin_unlock(&tp->lock);
  71. } else {
  72. pnic_do_nway(dev);
  73. }
  74. iowrite32((ioread32(ioaddr + CSR7) & ~TPLnkPass) | TPLnkFail, ioaddr + CSR7);
  75. }
  76. }
  77. void pnic_timer(struct timer_list *t)
  78. {
  79. struct tulip_private *tp = from_timer(tp, t, timer);
  80. struct net_device *dev = tp->dev;
  81. void __iomem *ioaddr = tp->base_addr;
  82. int next_tick = 60*HZ;
  83. if(!ioread32(ioaddr + CSR7)) {
  84. /* the timer was called due to a work overflow
  85. * in the interrupt handler. Skip the connection
  86. * checks, the nic is definitively speaking with
  87. * his link partner.
  88. */
  89. goto too_good_connection;
  90. }
  91. if (tulip_media_cap[dev->if_port] & MediaIsMII) {
  92. spin_lock_irq(&tp->lock);
  93. if (tulip_check_duplex(dev) > 0)
  94. next_tick = 3*HZ;
  95. spin_unlock_irq(&tp->lock);
  96. } else {
  97. int csr12 = ioread32(ioaddr + CSR12);
  98. int new_csr6 = tp->csr6 & ~0x40C40200;
  99. int phy_reg = ioread32(ioaddr + 0xB8);
  100. int csr5 = ioread32(ioaddr + CSR5);
  101. if (tulip_debug > 1)
  102. netdev_dbg(dev, "PNIC timer PHY status %08x, %s CSR5 %08x\n",
  103. phy_reg, medianame[dev->if_port], csr5);
  104. if (phy_reg & 0x04000000) { /* Remote link fault */
  105. iowrite32(0x0201F078, ioaddr + 0xB8);
  106. next_tick = 1*HZ;
  107. tp->nwayset = 0;
  108. } else if (phy_reg & 0x78000000) { /* Ignore baseT4 */
  109. pnic_do_nway(dev);
  110. next_tick = 60*HZ;
  111. } else if (csr5 & TPLnkFail) { /* 100baseTx link beat */
  112. if (tulip_debug > 1)
  113. netdev_dbg(dev, "%s link beat failed, CSR12 %04x, CSR5 %08x, PHY %03x\n",
  114. medianame[dev->if_port],
  115. csr12,
  116. ioread32(ioaddr + CSR5),
  117. ioread32(ioaddr + 0xB8));
  118. next_tick = 3*HZ;
  119. if (tp->medialock) {
  120. } else if (tp->nwayset && (dev->if_port & 1)) {
  121. next_tick = 1*HZ;
  122. } else if (dev->if_port == 0) {
  123. dev->if_port = 3;
  124. iowrite32(0x33, ioaddr + CSR12);
  125. new_csr6 = 0x01860000;
  126. iowrite32(0x1F868, ioaddr + 0xB8);
  127. } else {
  128. dev->if_port = 0;
  129. iowrite32(0x32, ioaddr + CSR12);
  130. new_csr6 = 0x00420000;
  131. iowrite32(0x1F078, ioaddr + 0xB8);
  132. }
  133. if (tp->csr6 != new_csr6) {
  134. tp->csr6 = new_csr6;
  135. /* Restart Tx */
  136. tulip_restart_rxtx(tp);
  137. netif_trans_update(dev);
  138. if (tulip_debug > 1)
  139. dev_info(&dev->dev,
  140. "Changing PNIC configuration to %s %s-duplex, CSR6 %08x\n",
  141. medianame[dev->if_port],
  142. tp->full_duplex ? "full" : "half",
  143. new_csr6);
  144. }
  145. }
  146. }
  147. too_good_connection:
  148. mod_timer(&tp->timer, RUN_AT(next_tick));
  149. if(!ioread32(ioaddr + CSR7)) {
  150. if (tulip_debug > 1)
  151. dev_info(&dev->dev, "sw timer wakeup\n");
  152. disable_irq(dev->irq);
  153. tulip_refill_rx(dev);
  154. enable_irq(dev->irq);
  155. iowrite32(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
  156. }
  157. }