pnic2.c 12 KB

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