pnic2.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*
  2. drivers/net/tulip/pnic2.c
  3. Copyright 2000,2001 The Linux Kernel Team
  4. Written/copyright 1994-2001 by Donald Becker.
  5. Modified to hep support PNIC_II by Kevin B. Hendricks
  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.
  10. Please submit bugs to http://bugzilla.kernel.org/ .
  11. */
  12. /* Understanding the PNIC_II - everything is this file is based
  13. * on the PNIC_II_PDF datasheet which is sorely lacking in detail
  14. *
  15. * As I understand things, here are the registers and bits that
  16. * explain the masks and constants used in this file that are
  17. * either different from the 21142/3 or important for basic operation.
  18. *
  19. *
  20. * CSR 6 (mask = 0xfe3bd1fd of bits not to change)
  21. * -----
  22. * Bit 24 - SCR
  23. * Bit 23 - PCS
  24. * Bit 22 - TTM (Trasmit Threshold Mode)
  25. * Bit 18 - Port Select
  26. * Bit 13 - Start - 1, Stop - 0 Transmissions
  27. * Bit 11:10 - Loop Back Operation Mode
  28. * Bit 9 - Full Duplex mode (Advertise 10BaseT-FD is CSR14<7> is set)
  29. * Bit 1 - Start - 1, Stop - 0 Receive
  30. *
  31. *
  32. * CSR 14 (mask = 0xfff0ee39 of bits not to change)
  33. * ------
  34. * Bit 19 - PAUSE-Pause
  35. * Bit 18 - Advertise T4
  36. * Bit 17 - Advertise 100baseTx-FD
  37. * Bit 16 - Advertise 100baseTx-HD
  38. * Bit 12 - LTE - Link Test Enable
  39. * Bit 7 - ANE - Auto Negotiate Enable
  40. * Bit 6 - HDE - Advertise 10baseT-HD
  41. * Bit 2 - Reset to Power down - kept as 1 for normal operation
  42. * Bit 1 - Loop Back enable for 10baseT MCC
  43. *
  44. *
  45. * CSR 12
  46. * ------
  47. * Bit 25 - Partner can do T4
  48. * Bit 24 - Partner can do 100baseTx-FD
  49. * Bit 23 - Partner can do 100baseTx-HD
  50. * Bit 22 - Partner can do 10baseT-FD
  51. * Bit 21 - Partner can do 10baseT-HD
  52. * Bit 15 - LPN is 1 if all above bits are valid other wise 0
  53. * Bit 14:12 - autonegotiation state (write 001 to start autonegotiate)
  54. * Bit 3 - Autopolarity state
  55. * Bit 2 - LS10B - link state of 10baseT 0 - good, 1 - failed
  56. * Bit 1 - LS100B - link state of 100baseT 0 - good, 1 - failed
  57. *
  58. *
  59. * Data Port Selection Info
  60. *-------------------------
  61. *
  62. * CSR14<7> CSR6<18> CSR6<22> CSR6<23> CSR6<24> MODE/PORT
  63. * 1 0 0 (X) 0 (X) 1 NWAY
  64. * 0 0 1 0 (X) 0 10baseT
  65. * 0 1 0 1 1 (X) 100baseT
  66. *
  67. *
  68. */
  69. #include "tulip.h"
  70. #include <linux/delay.h>
  71. void pnic2_timer(unsigned long data)
  72. {
  73. struct net_device *dev = (struct net_device *)data;
  74. struct tulip_private *tp = netdev_priv(dev);
  75. void __iomem *ioaddr = tp->base_addr;
  76. int next_tick = 60*HZ;
  77. if (tulip_debug > 3)
  78. dev_info(&dev->dev, "PNIC2 negotiation status %08x\n",
  79. ioread32(ioaddr + CSR12));
  80. if (next_tick) {
  81. mod_timer(&tp->timer, RUN_AT(next_tick));
  82. }
  83. }
  84. void pnic2_start_nway(struct net_device *dev)
  85. {
  86. struct tulip_private *tp = netdev_priv(dev);
  87. void __iomem *ioaddr = tp->base_addr;
  88. int csr14;
  89. int csr12;
  90. /* set up what to advertise during the negotiation */
  91. /* load in csr14 and mask off bits not to touch
  92. * comment at top of file explains mask value
  93. */
  94. csr14 = (ioread32(ioaddr + CSR14) & 0xfff0ee39);
  95. /* bit 17 - advetise 100baseTx-FD */
  96. if (tp->sym_advertise & 0x0100) csr14 |= 0x00020000;
  97. /* bit 16 - advertise 100baseTx-HD */
  98. if (tp->sym_advertise & 0x0080) csr14 |= 0x00010000;
  99. /* bit 6 - advertise 10baseT-HD */
  100. if (tp->sym_advertise & 0x0020) csr14 |= 0x00000040;
  101. /* Now set bit 12 Link Test Enable, Bit 7 Autonegotiation Enable
  102. * and bit 0 Don't PowerDown 10baseT
  103. */
  104. csr14 |= 0x00001184;
  105. if (tulip_debug > 1)
  106. netdev_dbg(dev, "Restarting PNIC2 autonegotiation, csr14=%08x\n",
  107. csr14);
  108. /* tell pnic2_lnk_change we are doing an nway negotiation */
  109. dev->if_port = 0;
  110. tp->nway = tp->mediasense = 1;
  111. tp->nwayset = tp->lpar = 0;
  112. /* now we have to set up csr6 for NWAY state */
  113. tp->csr6 = ioread32(ioaddr + CSR6);
  114. if (tulip_debug > 1)
  115. netdev_dbg(dev, "On Entry to Nway, csr6=%08x\n", tp->csr6);
  116. /* mask off any bits not to touch
  117. * comment at top of file explains mask value
  118. */
  119. tp->csr6 = tp->csr6 & 0xfe3bd1fd;
  120. /* don't forget that bit 9 is also used for advertising */
  121. /* advertise 10baseT-FD for the negotiation (bit 9) */
  122. if (tp->sym_advertise & 0x0040) tp->csr6 |= 0x00000200;
  123. /* set bit 24 for nway negotiation mode ...
  124. * see Data Port Selection comment at top of file
  125. * and "Stop" - reset both Transmit (bit 13) and Receive (bit 1)
  126. */
  127. tp->csr6 |= 0x01000000;
  128. iowrite32(csr14, ioaddr + CSR14);
  129. iowrite32(tp->csr6, ioaddr + CSR6);
  130. udelay(100);
  131. /* all set up so now force the negotiation to begin */
  132. /* read in current values and mask off all but the
  133. * Autonegotiation bits 14:12. Writing a 001 to those bits
  134. * should start the autonegotiation
  135. */
  136. csr12 = (ioread32(ioaddr + CSR12) & 0xffff8fff);
  137. csr12 |= 0x1000;
  138. iowrite32(csr12, ioaddr + CSR12);
  139. }
  140. void pnic2_lnk_change(struct net_device *dev, int csr5)
  141. {
  142. struct tulip_private *tp = netdev_priv(dev);
  143. void __iomem *ioaddr = tp->base_addr;
  144. int csr14;
  145. /* read the staus register to find out what is up */
  146. int csr12 = ioread32(ioaddr + CSR12);
  147. if (tulip_debug > 1)
  148. dev_info(&dev->dev,
  149. "PNIC2 link status interrupt %08x, CSR5 %x, %08x\n",
  150. csr12, csr5, ioread32(ioaddr + CSR14));
  151. /* If NWay finished and we have a negotiated partner capability.
  152. * check bits 14:12 for bit pattern 101 - all is good
  153. */
  154. if (tp->nway && !tp->nwayset) {
  155. /* we did an auto negotiation */
  156. if ((csr12 & 0x7000) == 0x5000) {
  157. /* negotiation ended successfully */
  158. /* get the link partners reply and mask out all but
  159. * bits 24-21 which show the partners capabilities
  160. * and match those to what we advertised
  161. *
  162. * then begin to interpret the results of the negotiation.
  163. * Always go in this order : (we are ignoring T4 for now)
  164. * 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD
  165. */
  166. int negotiated = ((csr12 >> 16) & 0x01E0) & tp->sym_advertise;
  167. tp->lpar = (csr12 >> 16);
  168. tp->nwayset = 1;
  169. if (negotiated & 0x0100) dev->if_port = 5;
  170. else if (negotiated & 0x0080) dev->if_port = 3;
  171. else if (negotiated & 0x0040) dev->if_port = 4;
  172. else if (negotiated & 0x0020) dev->if_port = 0;
  173. else {
  174. if (tulip_debug > 1)
  175. dev_info(&dev->dev,
  176. "funny autonegotiate result csr12 %08x advertising %04x\n",
  177. csr12, tp->sym_advertise);
  178. tp->nwayset = 0;
  179. /* so check if 100baseTx link state is okay */
  180. if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
  181. dev->if_port = 3;
  182. }
  183. /* now record the duplex that was negotiated */
  184. tp->full_duplex = 0;
  185. if ((dev->if_port == 4) || (dev->if_port == 5))
  186. tp->full_duplex = 1;
  187. if (tulip_debug > 1) {
  188. if (tp->nwayset)
  189. dev_info(&dev->dev,
  190. "Switching to %s based on link negotiation %04x & %04x = %04x\n",
  191. medianame[dev->if_port],
  192. tp->sym_advertise, tp->lpar,
  193. negotiated);
  194. }
  195. /* remember to turn off bit 7 - autonegotiate
  196. * enable so we can properly end nway mode and
  197. * set duplex (ie. use csr6<9> again)
  198. */
  199. csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f);
  200. iowrite32(csr14,ioaddr + CSR14);
  201. /* now set the data port and operating mode
  202. * (see the Data Port Selection comments at
  203. * the top of the file
  204. */
  205. /* get current csr6 and mask off bits not to touch */
  206. /* see comment at top of file */
  207. tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd);
  208. /* so if using if_port 3 or 5 then select the 100baseT
  209. * port else select the 10baseT port.
  210. * See the Data Port Selection table at the top
  211. * of the file which was taken from the PNIC_II.PDF
  212. * datasheet
  213. */
  214. if (dev->if_port & 1) tp->csr6 |= 0x01840000;
  215. else tp->csr6 |= 0x00400000;
  216. /* now set the full duplex bit appropriately */
  217. if (tp->full_duplex) tp->csr6 |= 0x00000200;
  218. iowrite32(1, ioaddr + CSR13);
  219. if (tulip_debug > 2)
  220. netdev_dbg(dev, "Setting CSR6 %08x/%x CSR12 %08x\n",
  221. tp->csr6,
  222. ioread32(ioaddr + CSR6),
  223. ioread32(ioaddr + CSR12));
  224. /* now the following actually writes out the
  225. * new csr6 values
  226. */
  227. tulip_start_rxtx(tp);
  228. return;
  229. } else {
  230. dev_info(&dev->dev,
  231. "Autonegotiation failed, using %s, link beat status %04x\n",
  232. medianame[dev->if_port], csr12);
  233. /* remember to turn off bit 7 - autonegotiate
  234. * enable so we don't forget
  235. */
  236. csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f);
  237. iowrite32(csr14,ioaddr + CSR14);
  238. /* what should we do when autonegotiate fails?
  239. * should we try again or default to baseline
  240. * case. I just don't know.
  241. *
  242. * for now default to some baseline case
  243. */
  244. dev->if_port = 0;
  245. tp->nway = 0;
  246. tp->nwayset = 1;
  247. /* set to 10baseTx-HD - see Data Port Selection
  248. * comment given at the top of the file
  249. */
  250. tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd);
  251. tp->csr6 |= 0x00400000;
  252. tulip_restart_rxtx(tp);
  253. return;
  254. }
  255. }
  256. if ((tp->nwayset && (csr5 & 0x08000000) &&
  257. (dev->if_port == 3 || dev->if_port == 5) &&
  258. (csr12 & 2) == 2) || (tp->nway && (csr5 & (TPLnkFail)))) {
  259. /* Link blew? Maybe restart NWay. */
  260. if (tulip_debug > 2)
  261. netdev_dbg(dev, "Ugh! Link blew?\n");
  262. del_timer_sync(&tp->timer);
  263. pnic2_start_nway(dev);
  264. tp->timer.expires = RUN_AT(3*HZ);
  265. add_timer(&tp->timer);
  266. return;
  267. }
  268. if (dev->if_port == 3 || dev->if_port == 5) {
  269. /* we are at 100mb and a potential link change occurred */
  270. if (tulip_debug > 1)
  271. dev_info(&dev->dev, "PNIC2 %s link beat %s\n",
  272. medianame[dev->if_port],
  273. (csr12 & 2) ? "failed" : "good");
  274. /* check 100 link beat */
  275. tp->nway = 0;
  276. tp->nwayset = 1;
  277. /* if failed then try doing an nway to get in sync */
  278. if ((csr12 & 2) && ! tp->medialock) {
  279. del_timer_sync(&tp->timer);
  280. pnic2_start_nway(dev);
  281. tp->timer.expires = RUN_AT(3*HZ);
  282. add_timer(&tp->timer);
  283. }
  284. return;
  285. }
  286. if (dev->if_port == 0 || dev->if_port == 4) {
  287. /* we are at 10mb and a potential link change occurred */
  288. if (tulip_debug > 1)
  289. dev_info(&dev->dev, "PNIC2 %s link beat %s\n",
  290. medianame[dev->if_port],
  291. (csr12 & 4) ? "failed" : "good");
  292. tp->nway = 0;
  293. tp->nwayset = 1;
  294. /* if failed, try doing an nway to get in sync */
  295. if ((csr12 & 4) && ! tp->medialock) {
  296. del_timer_sync(&tp->timer);
  297. pnic2_start_nway(dev);
  298. tp->timer.expires = RUN_AT(3*HZ);
  299. add_timer(&tp->timer);
  300. }
  301. return;
  302. }
  303. if (tulip_debug > 1)
  304. dev_info(&dev->dev, "PNIC2 Link Change Default?\n");
  305. /* if all else fails default to trying 10baseT-HD */
  306. dev->if_port = 0;
  307. /* make sure autonegotiate enable is off */
  308. csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f);
  309. iowrite32(csr14,ioaddr + CSR14);
  310. /* set to 10baseTx-HD - see Data Port Selection
  311. * comment given at the top of the file
  312. */
  313. tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd);
  314. tp->csr6 |= 0x00400000;
  315. tulip_restart_rxtx(tp);
  316. }