21142.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. drivers/net/ethernet/dec/tulip/21142.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. DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller
  8. Hardware Reference Manual" is currently available at :
  9. http://developer.intel.com/design/network/manuals/278074.htm
  10. Please submit bugs to http://bugzilla.kernel.org/ .
  11. */
  12. #include <linux/delay.h>
  13. #include "tulip.h"
  14. static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
  15. u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
  16. static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
  17. /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
  18. of available transceivers. */
  19. void t21142_media_task(struct work_struct *work)
  20. {
  21. struct tulip_private *tp =
  22. container_of(work, struct tulip_private, media_work);
  23. struct net_device *dev = tp->dev;
  24. void __iomem *ioaddr = tp->base_addr;
  25. int csr12 = ioread32(ioaddr + CSR12);
  26. int next_tick = 60*HZ;
  27. int new_csr6 = 0;
  28. int csr14 = ioread32(ioaddr + CSR14);
  29. /* CSR12[LS10,LS100] are not reliable during autonegotiation */
  30. if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
  31. csr12 |= 6;
  32. if (tulip_debug > 2)
  33. dev_info(&dev->dev, "21143 negotiation status %08x, %s\n",
  34. csr12, medianame[dev->if_port]);
  35. if (tulip_media_cap[dev->if_port] & MediaIsMII) {
  36. if (tulip_check_duplex(dev) < 0) {
  37. netif_carrier_off(dev);
  38. next_tick = 3*HZ;
  39. } else {
  40. netif_carrier_on(dev);
  41. next_tick = 60*HZ;
  42. }
  43. } else if (tp->nwayset) {
  44. /* Don't screw up a negotiated session! */
  45. if (tulip_debug > 1)
  46. dev_info(&dev->dev,
  47. "Using NWay-set %s media, csr12 %08x\n",
  48. medianame[dev->if_port], csr12);
  49. } else if (tp->medialock) {
  50. ;
  51. } else if (dev->if_port == 3) {
  52. if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
  53. if (tulip_debug > 1)
  54. dev_info(&dev->dev,
  55. "No 21143 100baseTx link beat, %08x, trying NWay\n",
  56. csr12);
  57. t21142_start_nway(dev);
  58. next_tick = 3*HZ;
  59. }
  60. } else if ((csr12 & 0x7000) != 0x5000) {
  61. /* Negotiation failed. Search media types. */
  62. if (tulip_debug > 1)
  63. dev_info(&dev->dev,
  64. "21143 negotiation failed, status %08x\n",
  65. csr12);
  66. if (!(csr12 & 4)) { /* 10mbps link beat good. */
  67. new_csr6 = 0x82420000;
  68. dev->if_port = 0;
  69. iowrite32(0, ioaddr + CSR13);
  70. iowrite32(0x0003FFFF, ioaddr + CSR14);
  71. iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15);
  72. iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13);
  73. } else {
  74. /* Select 100mbps port to check for link beat. */
  75. new_csr6 = 0x83860000;
  76. dev->if_port = 3;
  77. iowrite32(0, ioaddr + CSR13);
  78. iowrite32(0x0003FFFF, ioaddr + CSR14);
  79. iowrite16(8, ioaddr + CSR15);
  80. iowrite32(1, ioaddr + CSR13);
  81. }
  82. if (tulip_debug > 1)
  83. dev_info(&dev->dev, "Testing new 21143 media %s\n",
  84. medianame[dev->if_port]);
  85. if (new_csr6 != (tp->csr6 & ~0x00D5)) {
  86. tp->csr6 &= 0x00D5;
  87. tp->csr6 |= new_csr6;
  88. iowrite32(0x0301, ioaddr + CSR12);
  89. tulip_restart_rxtx(tp);
  90. }
  91. next_tick = 3*HZ;
  92. }
  93. /* mod_timer synchronizes us with potential add_timer calls
  94. * from interrupts.
  95. */
  96. mod_timer(&tp->timer, RUN_AT(next_tick));
  97. }
  98. void t21142_start_nway(struct net_device *dev)
  99. {
  100. struct tulip_private *tp = netdev_priv(dev);
  101. void __iomem *ioaddr = tp->base_addr;
  102. int csr14 = ((tp->sym_advertise & 0x0780) << 9) |
  103. ((tp->sym_advertise & 0x0020) << 1) | 0xffbf;
  104. dev->if_port = 0;
  105. tp->nway = tp->mediasense = 1;
  106. tp->nwayset = tp->lpar = 0;
  107. if (tulip_debug > 1)
  108. netdev_dbg(dev, "Restarting 21143 autonegotiation, csr14=%08x\n",
  109. csr14);
  110. iowrite32(0x0001, ioaddr + CSR13);
  111. udelay(100);
  112. iowrite32(csr14, ioaddr + CSR14);
  113. tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
  114. iowrite32(tp->csr6, ioaddr + CSR6);
  115. if (tp->mtable && tp->mtable->csr15dir) {
  116. iowrite32(tp->mtable->csr15dir, ioaddr + CSR15);
  117. iowrite32(tp->mtable->csr15val, ioaddr + CSR15);
  118. } else
  119. iowrite16(0x0008, ioaddr + CSR15);
  120. iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */
  121. }
  122. void t21142_lnk_change(struct net_device *dev, int csr5)
  123. {
  124. struct tulip_private *tp = netdev_priv(dev);
  125. void __iomem *ioaddr = tp->base_addr;
  126. int csr12 = ioread32(ioaddr + CSR12);
  127. int csr14 = ioread32(ioaddr + CSR14);
  128. /* CSR12[LS10,LS100] are not reliable during autonegotiation */
  129. if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
  130. csr12 |= 6;
  131. if (tulip_debug > 1)
  132. dev_info(&dev->dev,
  133. "21143 link status interrupt %08x, CSR5 %x, %08x\n",
  134. csr12, csr5, csr14);
  135. /* If NWay finished and we have a negotiated partner capability. */
  136. if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
  137. int setup_done = 0;
  138. int negotiated = tp->sym_advertise & (csr12 >> 16);
  139. tp->lpar = csr12 >> 16;
  140. tp->nwayset = 1;
  141. /* If partner cannot negotiate, it is 10Mbps Half Duplex */
  142. if (!(csr12 & 0x8000)) dev->if_port = 0;
  143. else if (negotiated & 0x0100) dev->if_port = 5;
  144. else if (negotiated & 0x0080) dev->if_port = 3;
  145. else if (negotiated & 0x0040) dev->if_port = 4;
  146. else if (negotiated & 0x0020) dev->if_port = 0;
  147. else {
  148. tp->nwayset = 0;
  149. if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
  150. dev->if_port = 3;
  151. }
  152. tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
  153. if (tulip_debug > 1) {
  154. if (tp->nwayset)
  155. dev_info(&dev->dev,
  156. "Switching to %s based on link negotiation %04x & %04x = %04x\n",
  157. medianame[dev->if_port],
  158. tp->sym_advertise, tp->lpar,
  159. negotiated);
  160. else
  161. dev_info(&dev->dev,
  162. "Autonegotiation failed, using %s, link beat status %04x\n",
  163. medianame[dev->if_port], csr12);
  164. }
  165. if (tp->mtable) {
  166. int i;
  167. for (i = 0; i < tp->mtable->leafcount; i++)
  168. if (tp->mtable->mleaf[i].media == dev->if_port) {
  169. int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
  170. tp->cur_index = i;
  171. tulip_select_media(dev, startup);
  172. setup_done = 1;
  173. break;
  174. }
  175. }
  176. if ( ! setup_done) {
  177. tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
  178. if (tp->full_duplex)
  179. tp->csr6 |= 0x0200;
  180. iowrite32(1, ioaddr + CSR13);
  181. }
  182. #if 0 /* Restart shouldn't be needed. */
  183. iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
  184. if (tulip_debug > 2)
  185. netdev_dbg(dev, " Restarting Tx and Rx, CSR5 is %08x\n",
  186. ioread32(ioaddr + CSR5));
  187. #endif
  188. tulip_start_rxtx(tp);
  189. if (tulip_debug > 2)
  190. netdev_dbg(dev, " Setting CSR6 %08x/%x CSR12 %08x\n",
  191. tp->csr6, ioread32(ioaddr + CSR6),
  192. ioread32(ioaddr + CSR12));
  193. } else if ((tp->nwayset && (csr5 & 0x08000000) &&
  194. (dev->if_port == 3 || dev->if_port == 5) &&
  195. (csr12 & 2) == 2) ||
  196. (tp->nway && (csr5 & (TPLnkFail)))) {
  197. /* Link blew? Maybe restart NWay. */
  198. del_timer_sync(&tp->timer);
  199. t21142_start_nway(dev);
  200. tp->timer.expires = RUN_AT(3*HZ);
  201. add_timer(&tp->timer);
  202. } else if (dev->if_port == 3 || dev->if_port == 5) {
  203. if (tulip_debug > 1)
  204. dev_info(&dev->dev, "21143 %s link beat %s\n",
  205. medianame[dev->if_port],
  206. (csr12 & 2) ? "failed" : "good");
  207. if ((csr12 & 2) && ! tp->medialock) {
  208. del_timer_sync(&tp->timer);
  209. t21142_start_nway(dev);
  210. tp->timer.expires = RUN_AT(3*HZ);
  211. add_timer(&tp->timer);
  212. } else if (dev->if_port == 5)
  213. iowrite32(csr14 & ~0x080, ioaddr + CSR14);
  214. } else if (dev->if_port == 0 || dev->if_port == 4) {
  215. if ((csr12 & 4) == 0)
  216. dev_info(&dev->dev, "21143 10baseT link beat good\n");
  217. } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
  218. if (tulip_debug)
  219. dev_info(&dev->dev, "21143 10mbps sensed media\n");
  220. dev->if_port = 0;
  221. } else if (tp->nwayset) {
  222. if (tulip_debug)
  223. dev_info(&dev->dev, "21143 using NWay-set %s, csr6 %08x\n",
  224. medianame[dev->if_port], tp->csr6);
  225. } else { /* 100mbps link beat good. */
  226. if (tulip_debug)
  227. dev_info(&dev->dev, "21143 100baseTx sensed media\n");
  228. dev->if_port = 3;
  229. tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
  230. iowrite32(0x0003FF7F, ioaddr + CSR14);
  231. iowrite32(0x0301, ioaddr + CSR12);
  232. tulip_restart_rxtx(tp);
  233. }
  234. }