pnic.c 5.2 KB

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