tulip.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  1. /* -*- Mode:C; c-basic-offset:4; -*- */
  2. /*
  3. Tulip and clone Etherboot Driver
  4. By Marty Connor (mdc@thinguin.org)
  5. Copyright (C) 2001 Entity Cyber, Inc.
  6. This software may be used and distributed according to the terms
  7. of the GNU Public License, incorporated herein by reference.
  8. As of April 2001 this driver should support most tulip cards that
  9. the Linux tulip driver supports because Donald Becker's Linux media
  10. detection code is now included.
  11. Based on Ken Yap's Tulip Etherboot Driver and Donald Becker's
  12. Linux Tulip Driver. Supports N-Way speed auto-configuration on
  13. MX98715, MX98715A and MX98725. Support inexpensive PCI 10/100 cards
  14. based on the Macronix MX987x5 chip, such as the SOHOware Fast
  15. model SFA110A, and the LinkSYS model LNE100TX. The NetGear
  16. model FA310X, based on the LC82C168 chip is supported.
  17. The TRENDnet TE100-PCIA NIC which uses a genuine Intel 21143-PD
  18. chipset is supported. Also, Davicom DM9102's.
  19. Documentation and source code used:
  20. Source for Etherboot driver at
  21. http://etherboot.sourceforge.net/
  22. MX98715A Data Sheet and MX98715A Application Note
  23. on http://www.macronix.com/ (PDF format files)
  24. Source for Linux tulip driver at
  25. http://cesdis.gsfc.nasa.gov/linux/drivers/tulip.html
  26. Adapted by Ken Yap from
  27. FreeBSD netboot DEC 21143 driver
  28. Author: David Sharp
  29. date: Nov/98
  30. Some code fragments were taken from verious places, Ken Yap's
  31. etherboot, FreeBSD's if_de.c, and various Linux related files.
  32. DEC's manuals for the 21143 and SROM format were very helpful.
  33. The Linux de driver development page has a number of links to
  34. useful related information. Have a look at:
  35. ftp://cesdis.gsfc.nasa.gov/pub/linux/drivers/tulip-devel.html
  36. */
  37. /*********************************************************************/
  38. /* Revision History */
  39. /*********************************************************************/
  40. /*
  41. 11 Apr 2001 mdc [patch to etherboot 4.7.24]
  42. Major rewrite to include Linux tulip driver media detection
  43. code. This driver should support a lot more cards now.
  44. 16 Jul 2000 mdc 0.75b11
  45. Added support for ADMtek 0985 Centaur-P, a "Comet" tulip clone
  46. which is used on the LinkSYS LNE100TX v4.x cards. We already
  47. support LNE100TX v2.0 cards, which use a different controller.
  48. 04 Jul 2000 jam ?
  49. Added test of status after receiving a packet from the card.
  50. Also uncommented the tulip_disable routine. Stray packets
  51. seemed to be causing problems.
  52. 27 Apr 2000 njl ?
  53. 29 Feb 2000 mdc 0.75b7
  54. Increased reset delay to 3 seconds because Macronix cards seem to
  55. need more reset time before card comes back to a usable state.
  56. 26 Feb 2000 mdc 0.75b6
  57. Added a 1 second delay after initializing the transmitter because
  58. some cards seem to need the time or they drop the first packet
  59. transmitted.
  60. 23 Feb 2000 mdc 0.75b5
  61. removed udelay code and used currticks() for more reliable delay
  62. code in reset pause and sanity timeouts. Added function prototypes
  63. and TX debugging code.
  64. 21 Feb 2000 mdc patch to Etherboot 4.4.3
  65. Incorporated patches from Bob Edwards and Paul Mackerras of
  66. Linuxcare's OZLabs to deal with inefficiencies in tulip_transmit
  67. and udelay. We now wait for packet transmission to complete
  68. (or sanity timeout).
  69. 04 Feb 2000 Robert.Edwards@anu.edu.au patch to Etherboot 4.4.2
  70. patch to tulip.c that implements the automatic selection of the MII
  71. interface on cards using the Intel/DEC 21143 reference design, in
  72. particular, the TRENDnet TE100-PCIA NIC which uses a genuine Intel
  73. 21143-PD chipset.
  74. 11 Jan 2000 mdc 0.75b4
  75. Added support for NetGear FA310TX card based on the LC82C168
  76. chip. This should also support Lite-On LC82C168 boards.
  77. Added simple MII support. Re-arranged code to better modularize
  78. initializations.
  79. 04 Dec 1999 mdc 0.75b3
  80. Added preliminary support for LNE100TX PCI cards. Should work for
  81. PNIC2 cards. No MII support, but single interface (RJ45) tulip
  82. cards seem to not care.
  83. 03 Dec 1999 mdc 0.75b2
  84. Renamed from mx987x5 to tulip, merged in original tulip init code
  85. from tulip.c to support other tulip compatible cards.
  86. 02 Dec 1999 mdc 0.75b1
  87. Released Beta MX987x5 Driver for code review and testing to netboot
  88. and thinguin mailing lists.
  89. */
  90. /*********************************************************************/
  91. /* Declarations */
  92. /*********************************************************************/
  93. #include "etherboot.h"
  94. #include "nic.h"
  95. #include "pci.h"
  96. #include "cards.h"
  97. /* User settable parameters */
  98. #undef TULIP_DEBUG
  99. #undef TULIP_DEBUG_WHERE
  100. static int tulip_debug = 2; /* 1 normal messages, 0 quiet .. 7 verbose. */
  101. #define TX_TIME_OUT 2*TICKS_PER_SEC
  102. typedef unsigned char u8;
  103. typedef signed char s8;
  104. typedef unsigned short u16;
  105. typedef signed short s16;
  106. typedef unsigned int u32;
  107. typedef signed int s32;
  108. /* helpful macros if on a big_endian machine for changing byte order.
  109. not strictly needed on Intel */
  110. #define le16_to_cpu(val) (val)
  111. #define cpu_to_le32(val) (val)
  112. #define get_unaligned(ptr) (*(ptr))
  113. #define put_unaligned(val, ptr) ((void)( *(ptr) = (val) ))
  114. #define get_u16(ptr) (*(u16 *)(ptr))
  115. #define virt_to_bus(x) ((unsigned long)x)
  116. #define virt_to_le32desc(addr) virt_to_bus(addr)
  117. #define TULIP_IOTYPE PCI_USES_MASTER | PCI_USES_IO | PCI_ADDR0
  118. #define TULIP_SIZE 0x80
  119. /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
  120. to support a pre-NWay full-duplex signaling mechanism using short frames.
  121. No one knows what it should be, but if left at its default value some
  122. 10base2(!) packets trigger a full-duplex-request interrupt. */
  123. #define FULL_DUPLEX_MAGIC 0x6969
  124. static const int csr0 = 0x01A00000 | 0x8000;
  125. /* The possible media types that can be set in options[] are: */
  126. #define MEDIA_MASK 31
  127. static const char * const medianame[32] = {
  128. "10baseT", "10base2", "AUI", "100baseTx",
  129. "10baseT-FDX", "100baseTx-FDX", "100baseT4", "100baseFx",
  130. "100baseFx-FDX", "MII 10baseT", "MII 10baseT-FDX", "MII",
  131. "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FDX", "MII 100baseT4",
  132. "MII 100baseFx-HDX", "MII 100baseFx-FDX", "Home-PNA 1Mbps", "Invalid-19",
  133. };
  134. /* This much match tulip_tbl[]! Note 21142 == 21143. */
  135. enum tulip_chips {
  136. DC21040=0, DC21041=1, DC21140=2, DC21142=3, DC21143=3,
  137. LC82C168, MX98713, MX98715, MX98725, AX88141, AX88140, PNIC2, COMET,
  138. COMPEX9881, I21145, XIRCOM
  139. };
  140. enum pci_id_flags_bits {
  141. /* Set PCI command register bits before calling probe1(). */
  142. PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
  143. /* Read and map the single following PCI BAR. */
  144. PCI_ADDR0=0<<4, PCI_ADDR1=1<<4, PCI_ADDR2=2<<4, PCI_ADDR3=3<<4,
  145. PCI_ADDR_64BITS=0x100, PCI_NO_ACPI_WAKE=0x200, PCI_NO_MIN_LATENCY=0x400,
  146. PCI_UNUSED_IRQ=0x800,
  147. };
  148. struct pci_id_info {
  149. char *name;
  150. struct match_info {
  151. u32 pci, pci_mask, subsystem, subsystem_mask;
  152. u32 revision, revision_mask; /* Only 8 bits. */
  153. } id;
  154. enum pci_id_flags_bits pci_flags;
  155. int io_size; /* Needed for I/O region check or ioremap(). */
  156. int drv_flags; /* Driver use, intended as capability flags. */
  157. };
  158. static struct pci_id_info pci_id_tbl[] = {
  159. { "Digital DC21040 Tulip", { 0x00021011, 0xffffffff, 0, 0, 0, 0 },
  160. TULIP_IOTYPE, 0x80, DC21040 },
  161. { "Digital DC21041 Tulip", { 0x00141011, 0xffffffff, 0, 0, 0, 0 },
  162. TULIP_IOTYPE, 0x80, DC21041 },
  163. { "Digital DS21140A Tulip", { 0x00091011, 0xffffffff, 0,0, 0x20,0xf0 },
  164. TULIP_IOTYPE, 0x80, DC21140 },
  165. { "Digital DS21140 Tulip", { 0x00091011, 0xffffffff, 0, 0, 0, 0 },
  166. TULIP_IOTYPE, 0x80, DC21140 },
  167. { "Digital DS21143 Tulip", { 0x00191011, 0xffffffff, 0,0, 65,0xff },
  168. TULIP_IOTYPE, TULIP_SIZE, DC21142 },
  169. { "Digital DS21142 Tulip", { 0x00191011, 0xffffffff, 0, 0, 0, 0 },
  170. TULIP_IOTYPE, TULIP_SIZE, DC21142 },
  171. { "Kingston KNE110tx (PNIC)", { 0x000211AD, 0xffffffff, 0xf0022646, 0xffffffff, 0, 0 },
  172. TULIP_IOTYPE, 256, LC82C168 },
  173. { "Lite-On 82c168 PNIC", { 0x000211AD, 0xffffffff, 0, 0, 0, 0 },
  174. TULIP_IOTYPE, 256, LC82C168 },
  175. { "Macronix 98713 PMAC", { 0x051210d9, 0xffffffff, 0, 0, 0, 0 },
  176. TULIP_IOTYPE, 256, MX98713 },
  177. { "Macronix 98715 PMAC", { 0x053110d9, 0xffffffff, 0, 0, 0, 0 },
  178. TULIP_IOTYPE, 256, MX98715 },
  179. { "Macronix 98725 PMAC", { 0x053110d9, 0xffffffff, 0, 0, 0, 0 },
  180. TULIP_IOTYPE, 256, MX98725 },
  181. { "ASIX AX88141", { 0x1400125B, 0xffffffff, 0,0, 0x10, 0xf0 },
  182. TULIP_IOTYPE, 128, AX88141 },
  183. { "ASIX AX88140", { 0x1400125B, 0xffffffff, 0, 0, 0, 0 },
  184. TULIP_IOTYPE, 128, AX88140 },
  185. { "Lite-On LC82C115 PNIC-II", { 0xc11511AD, 0xffffffff, 0, 0, 0, 0 },
  186. TULIP_IOTYPE, 256, PNIC2 },
  187. { "ADMtek AN981 Comet", { 0x09811317, 0xffffffff, 0, 0, 0, 0 },
  188. TULIP_IOTYPE, 256, COMET },
  189. { "ADMtek Centaur-P", { 0x09851317, 0xffffffff, 0, 0, 0, 0 },
  190. TULIP_IOTYPE, 256, COMET },
  191. { "ADMtek Centaur-C", { 0x19851317, 0xffffffff, 0, 0, 0, 0 },
  192. TULIP_IOTYPE, 256, COMET },
  193. { "Compex RL100-TX", { 0x988111F6, 0xffffffff, 0, 0, 0, 0 },
  194. TULIP_IOTYPE, 128, COMPEX9881 },
  195. { "Intel 21145 Tulip", { 0x00398086, 0xffffffff, 0, 0, 0, 0 },
  196. TULIP_IOTYPE, 128, I21145 },
  197. { "Xircom Tulip clone", { 0x0003115d, 0xffffffff, 0, 0, 0, 0 },
  198. TULIP_IOTYPE, 128, XIRCOM },
  199. { "Davicom DM9102", { 0x91021282, 0xffffffff, 0, 0, 0, 0 },
  200. TULIP_IOTYPE, 0x80, DC21140 },
  201. { "Davicom DM9100", { 0x91001282, 0xffffffff, 0, 0, 0, 0 },
  202. TULIP_IOTYPE, 0x80, DC21140 },
  203. { "Macronix mxic-98715 (EN1217)", { 0x12171113, 0xffffffff, 0, 0, 0, 0 },
  204. TULIP_IOTYPE, 256, MX98715 },
  205. { 0, { 0, 0, 0, 0, 0, 0 }, 0, 0, 0 },
  206. };
  207. enum tbl_flag {
  208. HAS_MII=1, HAS_MEDIA_TABLE=2, CSR12_IN_SROM=4, ALWAYS_CHECK_MII=8,
  209. HAS_PWRDWN=0x10, MC_HASH_ONLY=0x20, /* Hash-only multicast filter. */
  210. HAS_PNICNWAY=0x80, HAS_NWAY=0x40, /* Uses internal NWay xcvr. */
  211. HAS_INTR_MITIGATION=0x100, IS_ASIX=0x200, HAS_8023X=0x400,
  212. };
  213. /* Note: this table must match enum tulip_chips above. */
  214. static struct tulip_chip_table {
  215. char *chip_name;
  216. int flags;
  217. } tulip_tbl[] = {
  218. { "Digital DC21040 Tulip", 0},
  219. { "Digital DC21041 Tulip", HAS_MEDIA_TABLE | HAS_NWAY },
  220. { "Digital DS21140 Tulip", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM },
  221. { "Digital DS21143 Tulip", HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII
  222. | HAS_PWRDWN | HAS_NWAY | HAS_INTR_MITIGATION },
  223. { "Lite-On 82c168 PNIC", HAS_MII | HAS_PNICNWAY },
  224. { "Macronix 98713 PMAC", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM },
  225. { "Macronix 98715 PMAC", HAS_MEDIA_TABLE },
  226. { "Macronix 98725 PMAC", HAS_MEDIA_TABLE },
  227. { "ASIX AX88140", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM
  228. | MC_HASH_ONLY | IS_ASIX },
  229. { "ASIX AX88141", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | MC_HASH_ONLY
  230. | IS_ASIX },
  231. { "Lite-On PNIC-II", HAS_MII | HAS_NWAY | HAS_8023X },
  232. { "ADMtek Comet", MC_HASH_ONLY },
  233. { "Compex 9881 PMAC", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM },
  234. { "Intel DS21145 Tulip", HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII
  235. | HAS_PWRDWN | HAS_NWAY },
  236. { "Xircom tulip work-alike", HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII
  237. | HAS_PWRDWN | HAS_NWAY },
  238. { 0, 0 },
  239. };
  240. /* A full-duplex map for media types. */
  241. enum MediaIs {
  242. MediaIsFD = 1, MediaAlwaysFD=2, MediaIsMII=4, MediaIsFx=8,
  243. MediaIs100=16};
  244. static const char media_cap[32] =
  245. {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20, 20,31,0,0, };
  246. static u8 t21040_csr13[] = {2,0x0C,8,4, 4,0,0,0, 0,0,0,0, 4,0,0,0};
  247. /* 21041 transceiver register settings: 10-T, 10-2, AUI, 10-T, 10T-FD */
  248. static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
  249. static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
  250. static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
  251. static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
  252. static u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
  253. static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
  254. /* Offsets to the Command and Status Registers, "CSRs". All accesses
  255. must be longword instructions and quadword aligned. */
  256. enum tulip_offsets {
  257. CSR0=0, CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
  258. CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
  259. CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78, CSR16=0x80, CSR20=0xA0
  260. };
  261. /* The bits in the CSR5 status registers, mostly interrupt sources. */
  262. enum status_bits {
  263. TimerInt=0x800, TPLnkFail=0x1000, TPLnkPass=0x10,
  264. NormalIntr=0x10000, AbnormalIntr=0x8000,
  265. RxJabber=0x200, RxDied=0x100, RxNoBuf=0x80, RxIntr=0x40,
  266. TxFIFOUnderflow=0x20, TxJabber=0x08, TxNoBuf=0x04, TxDied=0x02, TxIntr=0x01,
  267. };
  268. enum desc_status_bits {
  269. DescOwnded=0x80000000, RxDescFatalErr=0x8000, RxWholePkt=0x0300,
  270. };
  271. struct medialeaf {
  272. u8 type;
  273. u8 media;
  274. unsigned char *leafdata;
  275. };
  276. struct mediatable {
  277. u16 defaultmedia;
  278. u8 leafcount, csr12dir; /* General purpose pin directions. */
  279. unsigned has_mii:1, has_nonmii:1, has_reset:6;
  280. u32 csr15dir, csr15val; /* 21143 NWay setting. */
  281. struct medialeaf mleaf[0];
  282. };
  283. struct mediainfo {
  284. struct mediainfo *next;
  285. int info_type;
  286. int index;
  287. unsigned char *info;
  288. };
  289. /* EEPROM Address width definitions */
  290. #define EEPROM_ADDRLEN 6
  291. #define EEPROM_SIZE 128 /* 2 << EEPROM_ADDRLEN */
  292. /* The EEPROM commands include the alway-set leading bit. */
  293. #define EE_WRITE_CMD (5 << addr_len)
  294. #define EE_READ_CMD (6 << addr_len)
  295. #define EE_ERASE_CMD (7 << addr_len)
  296. /* EEPROM_Ctrl bits. */
  297. #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
  298. #define EE_CS 0x01 /* EEPROM chip select. */
  299. #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
  300. #define EE_WRITE_0 0x01
  301. #define EE_WRITE_1 0x05
  302. #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
  303. #define EE_ENB (0x4800 | EE_CS)
  304. /* Delay between EEPROM clock transitions. Even at 33Mhz current PCI
  305. implementations don't overrun the EEPROM clock. We add a bus
  306. turn-around to insure that this remains true. */
  307. #define eeprom_delay() inl(ee_addr)
  308. /* Size of transmit and receive buffers */
  309. #define BUFLEN 1536
  310. /* Ring-wrap flag in length field, use for last ring entry.
  311. 0x01000000 means chain on buffer2 address,
  312. 0x02000000 means use the ring start address in CSR2/3.
  313. Note: Some work-alike chips do not function correctly in chained mode.
  314. The ASIX chip works only in chained mode.
  315. Thus we indicate ring mode, but always write the 'next' field for
  316. chained mode as well. */
  317. #define DESC_RING_WRAP 0x02000000
  318. /* transmit and receive descriptor format */
  319. struct tulip_rx_desc {
  320. volatile u32 status;
  321. u32 length;
  322. u32 buffer1, buffer2;
  323. };
  324. struct tulip_tx_desc {
  325. volatile u32 status;
  326. u32 length;
  327. u32 buffer1, buffer2;
  328. };
  329. /*********************************************************************/
  330. /* Global Storage */
  331. /*********************************************************************/
  332. static u32 ioaddr;
  333. /* Note: transmit and receive buffers must be longword aligned and
  334. longword divisable */
  335. #define TX_RING_SIZE 2
  336. static struct tulip_tx_desc tx_ring[TX_RING_SIZE] __attribute__ ((aligned(4)));
  337. #ifdef USE_LOWMEM_BUFFER
  338. #define txb ((char *)0x10000 - BUFLEN)
  339. #else
  340. static unsigned char txb[BUFLEN] __attribute__ ((aligned(4)));
  341. #endif
  342. #define RX_RING_SIZE 4
  343. static struct tulip_rx_desc rx_ring[RX_RING_SIZE] __attribute__ ((aligned(4)));
  344. #ifdef USE_LOWMEM_BUFFER
  345. #define rxb ((char *)0x10000 - RX_RING_SIZE * BUFLEN - BUFLEN)
  346. #else
  347. static unsigned char rxb[RX_RING_SIZE * BUFLEN] __attribute__ ((aligned(4)));
  348. #endif
  349. static struct tulip_private {
  350. int cur_rx;
  351. int chip_id; /* index into tulip_tbl[] */
  352. int pci_id_idx; /* index into pci_id_tbl[] */
  353. int revision;
  354. int flags;
  355. unsigned short vendor_id; /* PCI card vendor code */
  356. unsigned short dev_id; /* PCI card device code */
  357. unsigned char ehdr[ETH_HLEN]; /* buffer for ethernet header */
  358. const char *nic_name;
  359. unsigned int csr0, csr6; /* Current CSR0, CSR6 settings. */
  360. unsigned int if_port;
  361. unsigned int full_duplex; /* Full-duplex operation requested. */
  362. unsigned int full_duplex_lock;
  363. unsigned int medialock; /* Do not sense media type. */
  364. unsigned int mediasense; /* Media sensing in progress. */
  365. unsigned int nway, nwayset; /* 21143 internal NWay. */
  366. unsigned int default_port;
  367. unsigned char eeprom[EEPROM_SIZE]; /* Serial EEPROM contents. */
  368. u8 media_table_storage[(sizeof(struct mediatable) + 32*sizeof(struct medialeaf))];
  369. u16 sym_advertise, mii_advertise; /* NWay to-advertise. */
  370. struct mediatable *mtable;
  371. u16 lpar; /* 21143 Link partner ability. */
  372. u16 advertising[4]; /* MII advertise, from SROM table. */
  373. signed char phys[4], mii_cnt; /* MII device addresses. */
  374. int cur_index; /* Current media index. */
  375. int saved_if_port;
  376. } tpx;
  377. static struct tulip_private *tp;
  378. /* Known cards that have old-style EEPROMs.
  379. Writing this table is described at
  380. http://cesdis.gsfc.nasa.gov/linux/drivers/tulip-drivers/tulip-media.html */
  381. static struct fixups {
  382. char *name;
  383. unsigned char addr0, addr1, addr2;
  384. u16 newtable[32]; /* Max length below. */
  385. } eeprom_fixups[] = {
  386. {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
  387. 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
  388. {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x041f,
  389. 0x0000, 0x009E, /* 10baseT */
  390. 0x0004, 0x009E, /* 10baseT-FD */
  391. 0x0903, 0x006D, /* 100baseTx */
  392. 0x0905, 0x006D, /* 100baseTx-FD */ }},
  393. {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x063f,
  394. 0x0107, 0x8021, /* 100baseFx */
  395. 0x0108, 0x8021, /* 100baseFx-FD */
  396. 0x0100, 0x009E, /* 10baseT */
  397. 0x0104, 0x009E, /* 10baseT-FD */
  398. 0x0103, 0x006D, /* 100baseTx */
  399. 0x0105, 0x006D, /* 100baseTx-FD */ }},
  400. {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0513,
  401. 0x1001, 0x009E, /* 10base2, CSR12 0x10*/
  402. 0x0000, 0x009E, /* 10baseT */
  403. 0x0004, 0x009E, /* 10baseT-FD */
  404. 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */
  405. 0x0305, 0x006D, /* 100baseTx-FD CSR12 0x03 */}},
  406. {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x051F,
  407. 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */
  408. 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */
  409. 0x0B04, 0x009E, /* 10baseT-FD,CSR12 0x0B */
  410. 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */
  411. 0x1B05, 0x006D, /* 100baseTx-FD CSR12 0x1B */
  412. }},
  413. {0, 0, 0, 0, {}}};
  414. static const char * block_name[] = {"21140 non-MII", "21140 MII PHY",
  415. "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"};
  416. /*********************************************************************/
  417. /* Function Prototypes */
  418. /*********************************************************************/
  419. static int mdio_read(struct nic *nic, int phy_id, int location);
  420. static void mdio_write(struct nic *nic, int phy_id, int location, int value);
  421. static int read_eeprom(unsigned long ioaddr, int location, int addr_len);
  422. static void parse_eeprom(struct nic *nic);
  423. struct nic *tulip_probe(struct nic *nic, unsigned short *io_addrs,
  424. struct pci_device *pci);
  425. static void tulip_init_ring(struct nic *nic);
  426. static void tulip_reset(struct nic *nic);
  427. static void tulip_transmit(struct nic *nic, const char *d, unsigned int t,
  428. unsigned int s, const char *p);
  429. static int tulip_poll(struct nic *nic);
  430. static void tulip_disable(struct nic *nic);
  431. static void nway_start(struct nic *nic);
  432. static void pnic_do_nway(struct nic *nic);
  433. static void select_media(struct nic *nic, int startup);
  434. static void init_media(struct nic *nic);
  435. static void start_link(struct nic *nic);
  436. static int tulip_check_duplex(struct nic *nic);
  437. static void tulip_wait(unsigned int nticks);
  438. #ifdef TULIP_DEBUG_WHERE
  439. static void whereami(const char *str);
  440. #endif
  441. #ifdef TULIP_DEBUG
  442. static void tulip_more(void);
  443. #endif
  444. /*********************************************************************/
  445. /* Utility Routines */
  446. /*********************************************************************/
  447. #ifdef TULIP_DEBUG_WHERE
  448. static void whereami (const char *str)
  449. {
  450. printf("%s: %s\n", tp->nic_name, str);
  451. /* sleep(2); */
  452. }
  453. #endif
  454. #ifdef TULIP_DEBUG
  455. static void tulip_more(void)
  456. {
  457. printf("\n\n-- more --");
  458. while (!iskey())
  459. /* wait */;
  460. getchar();
  461. printf("\n\n");
  462. }
  463. #endif /* TULIP_DEBUG */
  464. static void tulip_wait(unsigned int nticks)
  465. {
  466. unsigned int to = currticks() + nticks;
  467. while (currticks() < to)
  468. /* wait */ ;
  469. }
  470. /*********************************************************************/
  471. /* Media Descriptor Code */
  472. /*********************************************************************/
  473. /* MII transceiver control section.
  474. Read and write the MII registers using software-generated serial
  475. MDIO protocol. See the MII specifications or DP83840A data sheet
  476. for details. */
  477. /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
  478. met by back-to-back PCI I/O cycles, but we insert a delay to avoid
  479. "overclocking" issues or future 66Mhz PCI. */
  480. #define mdio_delay() inl(mdio_addr)
  481. /* Read and write the MII registers using software-generated serial
  482. MDIO protocol. It is just different enough from the EEPROM protocol
  483. to not share code. The maxium data clock rate is 2.5 Mhz. */
  484. #define MDIO_SHIFT_CLK 0x10000
  485. #define MDIO_DATA_WRITE0 0x00000
  486. #define MDIO_DATA_WRITE1 0x20000
  487. #define MDIO_ENB 0x00000 /* Ignore the 0x02000 databook setting. */
  488. #define MDIO_ENB_IN 0x40000
  489. #define MDIO_DATA_READ 0x80000
  490. /* MII transceiver control section.
  491. Read and write the MII registers using software-generated serial
  492. MDIO protocol. See the MII specifications or DP83840A data sheet
  493. for details. */
  494. int mdio_read(struct nic *nic, int phy_id, int location)
  495. {
  496. int i;
  497. int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
  498. int retval = 0;
  499. long mdio_addr = ioaddr + CSR9;
  500. #ifdef TULIP_DEBUG_WHERE
  501. whereami("mdio_read\n");
  502. #endif
  503. if (tp->chip_id == LC82C168) {
  504. int i = 1000;
  505. outl(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0);
  506. inl(ioaddr + 0xA0);
  507. inl(ioaddr + 0xA0);
  508. while (--i > 0)
  509. if ( ! ((retval = inl(ioaddr + 0xA0)) & 0x80000000))
  510. return retval & 0xffff;
  511. return 0xffff;
  512. }
  513. if (tp->chip_id == COMET) {
  514. if (phy_id == 1) {
  515. if (location < 7)
  516. return inl(ioaddr + 0xB4 + (location<<2));
  517. else if (location == 17)
  518. return inl(ioaddr + 0xD0);
  519. else if (location >= 29 && location <= 31)
  520. return inl(ioaddr + 0xD4 + ((location-29)<<2));
  521. }
  522. return 0xffff;
  523. }
  524. /* Establish sync by sending at least 32 logic ones. */
  525. for (i = 32; i >= 0; i--) {
  526. outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
  527. mdio_delay();
  528. outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
  529. mdio_delay();
  530. }
  531. /* Shift the read command bits out. */
  532. for (i = 15; i >= 0; i--) {
  533. int dataval = (read_cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
  534. outl(MDIO_ENB | dataval, mdio_addr);
  535. mdio_delay();
  536. outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
  537. mdio_delay();
  538. }
  539. /* Read the two transition, 16 data, and wire-idle bits. */
  540. for (i = 19; i > 0; i--) {
  541. outl(MDIO_ENB_IN, mdio_addr);
  542. mdio_delay();
  543. retval = (retval << 1) | ((inl(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
  544. outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
  545. mdio_delay();
  546. }
  547. return (retval>>1) & 0xffff;
  548. }
  549. void mdio_write(struct nic *nic, int phy_id, int location, int value)
  550. {
  551. int i;
  552. int cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
  553. long mdio_addr = ioaddr + CSR9;
  554. #ifdef TULIP_DEBUG_WHERE
  555. whereami("mdio_write\n");
  556. #endif
  557. if (tp->chip_id == LC82C168) {
  558. int i = 1000;
  559. outl(cmd, ioaddr + 0xA0);
  560. do
  561. if ( ! (inl(ioaddr + 0xA0) & 0x80000000))
  562. break;
  563. while (--i > 0);
  564. return;
  565. }
  566. if (tp->chip_id == COMET) {
  567. if (phy_id != 1)
  568. return;
  569. if (location < 7)
  570. outl(value, ioaddr + 0xB4 + (location<<2));
  571. else if (location == 17)
  572. outl(value, ioaddr + 0xD0);
  573. else if (location >= 29 && location <= 31)
  574. outl(value, ioaddr + 0xD4 + ((location-29)<<2));
  575. return;
  576. }
  577. /* Establish sync by sending 32 logic ones. */
  578. for (i = 32; i >= 0; i--) {
  579. outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
  580. mdio_delay();
  581. outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
  582. mdio_delay();
  583. }
  584. /* Shift the command bits out. */
  585. for (i = 31; i >= 0; i--) {
  586. int dataval = (cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
  587. outl(MDIO_ENB | dataval, mdio_addr);
  588. mdio_delay();
  589. outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
  590. mdio_delay();
  591. }
  592. /* Clear out extra bits. */
  593. for (i = 2; i > 0; i--) {
  594. outl(MDIO_ENB_IN, mdio_addr);
  595. mdio_delay();
  596. outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
  597. mdio_delay();
  598. }
  599. }
  600. /*********************************************************************/
  601. /* EEPROM Reading Code */
  602. /*********************************************************************/
  603. /* EEPROM routines adapted from the Linux Tulip Code */
  604. /* Reading a serial EEPROM is a "bit" grungy, but we work our way
  605. through:->.
  606. */
  607. static int read_eeprom(unsigned long ioaddr, int location, int addr_len)
  608. {
  609. int i;
  610. unsigned short retval = 0;
  611. long ee_addr = ioaddr + CSR9;
  612. int read_cmd = location | EE_READ_CMD;
  613. #ifdef TULIP_DEBUG_WHERE
  614. whereami("read_eeprom\n");
  615. #endif
  616. outl(EE_ENB & ~EE_CS, ee_addr);
  617. outl(EE_ENB, ee_addr);
  618. /* Shift the read command bits out. */
  619. for (i = 4 + addr_len; i >= 0; i--) {
  620. short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
  621. outl(EE_ENB | dataval, ee_addr);
  622. eeprom_delay();
  623. outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
  624. eeprom_delay();
  625. }
  626. outl(EE_ENB, ee_addr);
  627. for (i = 16; i > 0; i--) {
  628. outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
  629. eeprom_delay();
  630. retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
  631. outl(EE_ENB, ee_addr);
  632. eeprom_delay();
  633. }
  634. /* Terminate the EEPROM access. */
  635. outl(EE_ENB & ~EE_CS, ee_addr);
  636. return retval;
  637. }
  638. /*********************************************************************/
  639. /* EEPROM Parsing Code */
  640. /*********************************************************************/
  641. static void parse_eeprom(struct nic *nic)
  642. {
  643. unsigned char *p, *ee_data = tp->eeprom;
  644. int new_advertise = 0;
  645. int i;
  646. #ifdef TULIP_DEBUG_WHERE
  647. whereami("parse_eeprom\n");
  648. #endif
  649. tp->mtable = 0;
  650. /* Detect an old-style (SA only) EEPROM layout:
  651. memcmp(ee_data, ee_data+16, 8). */
  652. for (i = 0; i < 8; i ++)
  653. if (ee_data[i] != ee_data[16+i])
  654. break;
  655. if (i >= 8) {
  656. /* Do a fix-up based on the vendor half of the station address. */
  657. for (i = 0; eeprom_fixups[i].name; i++) {
  658. if (nic->node_addr[0] == eeprom_fixups[i].addr0
  659. && nic->node_addr[1] == eeprom_fixups[i].addr1
  660. && nic->node_addr[2] == eeprom_fixups[i].addr2) {
  661. if (nic->node_addr[2] == 0xE8 && ee_data[0x1a] == 0x55)
  662. i++; /* An Accton EN1207, not an outlaw Maxtech. */
  663. memcpy(ee_data + 26, eeprom_fixups[i].newtable,
  664. sizeof(eeprom_fixups[i].newtable));
  665. #ifdef TULIP_DEBUG
  666. printf("%s: Old format EEPROM on '%s' board.\n%s: Using substitute media control info.\n",
  667. tp->nic_name, eeprom_fixups[i].name, tp->nic_name);
  668. #endif
  669. break;
  670. }
  671. }
  672. if (eeprom_fixups[i].name == NULL) { /* No fixup found. */
  673. #ifdef TULIP_DEBUG
  674. printf("%s: Old style EEPROM with no media selection information.\n",
  675. tp->nic_name);
  676. #endif
  677. return;
  678. }
  679. }
  680. if (ee_data[19] > 1) {
  681. #ifdef TULIP_DEBUG
  682. printf("%s: Multiport cards (%d ports) may not work correctly.\n",
  683. tp->nic_name, ee_data[19]);
  684. #endif
  685. }
  686. p = (void *)ee_data + ee_data[27];
  687. if (ee_data[27] == 0) { /* No valid media table. */
  688. #ifdef TULIP_DEBUG
  689. if (tulip_debug > 1) {
  690. printf("%s: No Valid Media Table. ee_data[27] = %hhX\n",
  691. tp->nic_name, ee_data[27]);
  692. }
  693. #endif
  694. } else if (tp->chip_id == DC21041) {
  695. int media = get_u16(p);
  696. int count = p[2];
  697. p += 3;
  698. printf("%s: 21041 Media table, default media %hX (%s).\n",
  699. tp->nic_name, media,
  700. media & 0x0800 ? "Autosense" : medianame[media & 15]);
  701. for (i = 0; i < count; i++) {
  702. unsigned char media_block = *p++;
  703. int media_code = media_block & MEDIA_MASK;
  704. if (media_block & 0x40)
  705. p += 6;
  706. switch(media_code) {
  707. case 0: new_advertise |= 0x0020; break;
  708. case 4: new_advertise |= 0x0040; break;
  709. }
  710. printf("%s: 21041 media #%d, %s.\n",
  711. tp->nic_name, media_code, medianame[media_code]);
  712. }
  713. } else {
  714. unsigned char csr12dir = 0;
  715. int count;
  716. struct mediatable *mtable;
  717. u16 media = get_u16(p);
  718. p += 2;
  719. if (tp->flags & CSR12_IN_SROM)
  720. csr12dir = *p++;
  721. count = *p++;
  722. tp->mtable = mtable = (struct mediatable *)&tp->media_table_storage[0];
  723. mtable->defaultmedia = media;
  724. mtable->leafcount = count;
  725. mtable->csr12dir = csr12dir;
  726. mtable->has_nonmii = mtable->has_mii = mtable->has_reset = 0;
  727. mtable->csr15dir = mtable->csr15val = 0;
  728. printf("%s: EEPROM default media type %s.\n", tp->nic_name,
  729. media & 0x0800 ? "Autosense" : medianame[media & MEDIA_MASK]);
  730. for (i = 0; i < count; i++) {
  731. struct medialeaf *leaf = &mtable->mleaf[i];
  732. if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */
  733. leaf->type = 0;
  734. leaf->media = p[0] & 0x3f;
  735. leaf->leafdata = p;
  736. if ((p[2] & 0x61) == 0x01) /* Bogus, but Znyx boards do it. */
  737. mtable->has_mii = 1;
  738. p += 4;
  739. } else {
  740. switch(leaf->type = p[1]) {
  741. case 5:
  742. mtable->has_reset = i;
  743. leaf->media = p[2] & 0x0f;
  744. break;
  745. case 1: case 3:
  746. mtable->has_mii = 1;
  747. leaf->media = 11;
  748. break;
  749. case 2:
  750. if ((p[2] & 0x3f) == 0) {
  751. u32 base15 = (p[2] & 0x40) ? get_u16(p + 7) : 0x0008;
  752. u16 *p1 = (u16 *)(p + (p[2] & 0x40 ? 9 : 3));
  753. mtable->csr15dir = (get_unaligned(p1 + 0)<<16) + base15;
  754. mtable->csr15val = (get_unaligned(p1 + 1)<<16) + base15;
  755. }
  756. /* Fall through. */
  757. case 0: case 4:
  758. mtable->has_nonmii = 1;
  759. leaf->media = p[2] & MEDIA_MASK;
  760. switch (leaf->media) {
  761. case 0: new_advertise |= 0x0020; break;
  762. case 4: new_advertise |= 0x0040; break;
  763. case 3: new_advertise |= 0x0080; break;
  764. case 5: new_advertise |= 0x0100; break;
  765. case 6: new_advertise |= 0x0200; break;
  766. }
  767. break;
  768. default:
  769. leaf->media = 19;
  770. }
  771. leaf->leafdata = p + 2;
  772. p += (p[0] & 0x3f) + 1;
  773. }
  774. #ifdef TULIP_DEBUG
  775. if (tulip_debug > 1 && leaf->media == 11) {
  776. unsigned char *bp = leaf->leafdata;
  777. printf("%s: MII interface PHY %d, setup/reset sequences %d/%d long, capabilities %hhX %hhX.\n",
  778. tp->nic_name, bp[0], bp[1], bp[2 + bp[1]*2],
  779. bp[5 + bp[2 + bp[1]*2]*2], bp[4 + bp[2 + bp[1]*2]*2]);
  780. }
  781. #endif
  782. printf("%s: Index #%d - Media %s (#%d) described "
  783. "by a %s (%d) block.\n",
  784. tp->nic_name, i, medianame[leaf->media], leaf->media,
  785. leaf->type < 6 ? block_name[leaf->type] : "UNKNOWN",
  786. leaf->type);
  787. }
  788. if (new_advertise)
  789. tp->sym_advertise = new_advertise;
  790. }
  791. }
  792. /*********************************************************************/
  793. /* tulip_init_ring - setup the tx and rx descriptors */
  794. /*********************************************************************/
  795. static void tulip_init_ring(struct nic *nic)
  796. {
  797. int i;
  798. #ifdef TULIP_DEBUG_WHERE
  799. whereami("tulip_init_ring\n");
  800. #endif
  801. tp->cur_rx = 0;
  802. for (i = 0; i < RX_RING_SIZE; i++) {
  803. rx_ring[i].status = cpu_to_le32(0x80000000);
  804. rx_ring[i].length = cpu_to_le32(BUFLEN);
  805. rx_ring[i].buffer1 = virt_to_le32desc(&rxb[i * BUFLEN]);
  806. rx_ring[i].buffer2 = virt_to_le32desc(&rx_ring[i+1]);
  807. }
  808. /* Mark the last entry as wrapping the ring. */
  809. rx_ring[i-1].length = cpu_to_le32(DESC_RING_WRAP | BUFLEN);
  810. rx_ring[i-1].buffer2 = virt_to_le32desc(&rx_ring[0]);
  811. /* We only use 1 transmit buffer, but we use 2 descriptors so
  812. transmit engines have somewhere to point to if they feel the need */
  813. tx_ring[0].status = 0x00000000;
  814. tx_ring[0].buffer1 = virt_to_le32desc(&txb[0]);
  815. tx_ring[0].buffer2 = virt_to_le32desc(&tx_ring[1]);
  816. /* this descriptor should never get used, since it will never be owned
  817. by the machine (status will always == 0) */
  818. tx_ring[1].status = 0x00000000;
  819. tx_ring[1].buffer1 = virt_to_le32desc(&txb[0]);
  820. tx_ring[1].buffer2 = virt_to_le32desc(&tx_ring[0]);
  821. /* Mark the last entry as wrapping the ring, though this should never happen */
  822. tx_ring[1].length = cpu_to_le32(DESC_RING_WRAP | BUFLEN);
  823. }
  824. /*********************************************************************/
  825. /* eth_reset - Reset adapter */
  826. /*********************************************************************/
  827. static void tulip_reset(struct nic *nic)
  828. {
  829. int i;
  830. unsigned long to;
  831. u32 addr_low, addr_high;
  832. #ifdef TULIP_DEBUG_WHERE
  833. whereami("tulip_reset\n");
  834. #endif
  835. /* Stop Tx and RX */
  836. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  837. /* On some chip revs we must set the MII/SYM port before the reset!? */
  838. if (tp->mii_cnt || (tp->mtable && tp->mtable->has_mii)) {
  839. outl(0x814C0000, ioaddr + CSR6);
  840. }
  841. /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
  842. outl(0x00000001, ioaddr + CSR0);
  843. tulip_wait(1);
  844. /* turn off reset and set cache align=16lword, burst=unlimit */
  845. outl(tp->csr0, ioaddr + CSR0);
  846. /* Wait the specified 50 PCI cycles after a reset */
  847. tulip_wait(1);
  848. /* set up transmit and receive descriptors */
  849. tulip_init_ring(nic);
  850. if (tp->chip_id == PNIC2) {
  851. u32 addr_high = (nic->node_addr[1]<<8) + (nic->node_addr[0]<<0);
  852. /* This address setting does not appear to impact chip operation?? */
  853. outl((nic->node_addr[5]<<8) + nic->node_addr[4] +
  854. (nic->node_addr[3]<<24) + (nic->node_addr[2]<<16),
  855. ioaddr + 0xB0);
  856. outl(addr_high + (addr_high<<16), ioaddr + 0xB8);
  857. }
  858. /* MC_HASH_ONLY boards don't support setup packets */
  859. if (tp->flags & MC_HASH_ONLY) {
  860. u32 addr_low = cpu_to_le32(get_unaligned((u32 *)nic->node_addr));
  861. u32 addr_high = cpu_to_le32(get_unaligned((u16 *)(nic->node_addr+4)));
  862. /* clear multicast hash filters and setup MAC address filters */
  863. if (tp->flags & IS_ASIX) {
  864. outl(0, ioaddr + CSR13);
  865. outl(addr_low, ioaddr + CSR14);
  866. outl(1, ioaddr + CSR13);
  867. outl(addr_high, ioaddr + CSR14);
  868. outl(2, ioaddr + CSR13);
  869. outl(0, ioaddr + CSR14);
  870. outl(3, ioaddr + CSR13);
  871. outl(0, ioaddr + CSR14);
  872. } else if (tp->chip_id == COMET) {
  873. outl(addr_low, ioaddr + 0xA4);
  874. outl(addr_high, ioaddr + 0xA8);
  875. outl(0, ioaddr + 0xAC);
  876. outl(0, ioaddr + 0xB0);
  877. }
  878. } else {
  879. /* for other boards we send a setup packet to initialize
  880. the filters */
  881. u32 tx_flags = 0x08000000 | 192;
  882. /* construct perfect filter frame with mac address as first match
  883. and broadcast address for all others */
  884. for (i=0; i<192; i++)
  885. txb[i] = 0xFF;
  886. txb[0] = nic->node_addr[0];
  887. txb[1] = nic->node_addr[1];
  888. txb[4] = nic->node_addr[2];
  889. txb[5] = nic->node_addr[3];
  890. txb[8] = nic->node_addr[4];
  891. txb[9] = nic->node_addr[5];
  892. tx_ring[0].length = cpu_to_le32(tx_flags);
  893. tx_ring[0].buffer1 = virt_to_le32desc(&txb[0]);
  894. tx_ring[0].status = cpu_to_le32(0x80000000);
  895. }
  896. /* Point to rx and tx descriptors */
  897. outl((unsigned long)&rx_ring[0], ioaddr + CSR3);
  898. outl((unsigned long)&tx_ring[0], ioaddr + CSR4);
  899. init_media(nic);
  900. /* set the chip's operating mode (but don't turn on xmit and recv yet) */
  901. outl((tp->csr6 & ~0x00002002), ioaddr + CSR6);
  902. /* send setup packet for cards that support it */
  903. if (!(tp->flags & MC_HASH_ONLY)) {
  904. /* enable transmit wait for completion */
  905. outl(tp->csr6 | 0x00002000, ioaddr + CSR6);
  906. /* immediate transmit demand */
  907. outl(0, ioaddr + CSR1);
  908. to = currticks() + TX_TIME_OUT;
  909. while ((tx_ring[0].status & 0x80000000) && (currticks() < to))
  910. /* wait */ ;
  911. if (currticks() >= to) {
  912. printf ("%s: TX Setup Timeout.\n", tp->nic_name);
  913. }
  914. }
  915. if (tp->chip_id == LC82C168)
  916. tulip_check_duplex(nic);
  917. /* enable transmit and receive */
  918. outl(tp->csr6 | 0x00002002, ioaddr + CSR6);
  919. }
  920. /*********************************************************************/
  921. /* eth_transmit - Transmit a frame */
  922. /*********************************************************************/
  923. static void tulip_transmit(struct nic *nic, const char *d, unsigned int t,
  924. unsigned int s, const char *p)
  925. {
  926. u16 nstype;
  927. u32 to;
  928. u32 csr6 = inl(ioaddr + CSR6);
  929. #ifdef TULIP_DEBUG_WHERE
  930. whereami("tulip_transmit\n");
  931. #endif
  932. /* Disable Tx */
  933. outl(csr6 & ~0x00002000, ioaddr + CSR6);
  934. memcpy(txb, d, ETH_ALEN);
  935. memcpy(txb + ETH_ALEN, nic->node_addr, ETH_ALEN);
  936. nstype = htons((u16) t);
  937. memcpy(txb + 2 * ETH_ALEN, (u8 *)&nstype, 2);
  938. memcpy(txb + ETH_HLEN, p, s);
  939. s += ETH_HLEN;
  940. s &= 0x0FFF;
  941. /* pad to minimum packet size */
  942. while (s < ETH_ZLEN)
  943. txb[s++] = '\0';
  944. #ifdef TULIP_DEBUG
  945. if (tulip_debug > 1)
  946. printf("%s: sending %d bytes ethtype %hX\n", tp->nic_name, s, t);
  947. #endif
  948. /* setup the transmit descriptor */
  949. /* 0x60000000 = no interrupt on completion */
  950. tx_ring[0].length = cpu_to_le32(0x60000000 | s);
  951. tx_ring[0].status = cpu_to_le32(0x80000000);
  952. /* Point to transmit descriptor */
  953. outl((u32)&tx_ring[0], ioaddr + CSR4);
  954. /* Enable Tx */
  955. outl(csr6 | 0x00002000, ioaddr + CSR6);
  956. /* immediate transmit demand */
  957. outl(0, ioaddr + CSR1);
  958. to = currticks() + TX_TIME_OUT;
  959. while ((tx_ring[0].status & 0x80000000) && (currticks() < to))
  960. /* wait */ ;
  961. if (currticks() >= to) {
  962. printf ("TX Timeout!\n");
  963. }
  964. /* Disable Tx */
  965. outl(csr6 & ~0x00002000, ioaddr + CSR6);
  966. }
  967. /*********************************************************************/
  968. /* eth_poll - Wait for a frame */
  969. /*********************************************************************/
  970. static int tulip_poll(struct nic *nic)
  971. {
  972. #ifdef TULIP_DEBUG_WHERE
  973. whereami("tulip_poll\n");
  974. #endif
  975. /* no packet waiting. packet still owned by NIC */
  976. if (rx_ring[tp->cur_rx].status & 0x80000000)
  977. return 0;
  978. #ifdef TULIP_DEBUG_WHERE
  979. whereami("tulip_poll got one\n");
  980. #endif
  981. nic->packetlen = (rx_ring[tp->cur_rx].status & 0x3FFF0000) >> 16;
  982. /* if we get a corrupted packet. throw it away and move on */
  983. if (rx_ring[tp->cur_rx].status & 0x00008000) {
  984. /* return the descriptor and buffer to receive ring */
  985. rx_ring[tp->cur_rx].status = 0x80000000;
  986. tp->cur_rx = (++tp->cur_rx) % RX_RING_SIZE;
  987. return 0;
  988. }
  989. /* copy packet to working buffer */
  990. memcpy(nic->packet, rxb + tp->cur_rx * BUFLEN, nic->packetlen);
  991. /* return the descriptor and buffer to receive ring */
  992. rx_ring[tp->cur_rx].status = 0x80000000;
  993. tp->cur_rx = (++tp->cur_rx) % RX_RING_SIZE;
  994. return 1;
  995. }
  996. /*********************************************************************/
  997. /* eth_disable - Disable the interface */
  998. /*********************************************************************/
  999. static void tulip_disable(struct nic *nic)
  1000. {
  1001. #ifdef TULIP_DEBUG_WHERE
  1002. whereami("tulip_disable\n");
  1003. #endif
  1004. /* disable interrupts */
  1005. outl(0x00000000, ioaddr + CSR7);
  1006. /* Stop the chip's Tx and Rx processes. */
  1007. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  1008. /* Clear the missed-packet counter. */
  1009. (volatile unsigned long)inl(ioaddr + CSR8);
  1010. }
  1011. /*********************************************************************/
  1012. /* eth_probe - Look for an adapter */
  1013. /*********************************************************************/
  1014. struct nic *tulip_probe(struct nic *nic, unsigned short *io_addrs,
  1015. struct pci_device *pci)
  1016. {
  1017. u32 i, l1, l2;
  1018. u8 chip_rev;
  1019. u8 ee_data[EEPROM_SIZE];
  1020. unsigned short sum;
  1021. int chip_idx;
  1022. static unsigned char last_phys_addr[ETH_ALEN] = {0x00, 'L', 'i', 'n', 'u', 'x'};
  1023. if (io_addrs == 0 || *io_addrs == 0)
  1024. return 0;
  1025. ioaddr = *io_addrs;
  1026. /* point to private storage */
  1027. tp = &tpx;
  1028. tp->vendor_id = pci->vendor;
  1029. tp->dev_id = pci->dev_id;
  1030. tp->nic_name = pci->name;
  1031. tp->if_port = 0;
  1032. tp->default_port = 0;
  1033. adjust_pci_device(pci);
  1034. /* disable interrupts */
  1035. outl(0x00000000, ioaddr + CSR7);
  1036. /* Stop the chip's Tx and Rx processes. */
  1037. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  1038. /* Clear the missed-packet counter. */
  1039. (volatile unsigned long)inl(ioaddr + CSR8);
  1040. printf("\n"); /* so we start on a fresh line */
  1041. #ifdef TULIP_DEBUG_WHERE
  1042. whereami("tulip_probe\n");
  1043. #endif
  1044. #ifdef TULIP_DEBUG
  1045. if (tulip_debug > 1)
  1046. printf ("%s: Looking for Tulip Chip: Vendor=%hX Device=%hX\n", tp->nic_name,
  1047. tp->vendor_id, tp->dev_id);
  1048. #endif
  1049. /* Figure out which chip we're dealing with */
  1050. i = 0;
  1051. chip_idx = -1;
  1052. while (pci_id_tbl[i].name) {
  1053. if ( (((u32) tp->dev_id << 16) | tp->vendor_id) ==
  1054. (pci_id_tbl[i].id.pci & pci_id_tbl[i].id.pci_mask) ) {
  1055. chip_idx = pci_id_tbl[i].drv_flags;
  1056. break;
  1057. }
  1058. i++;
  1059. }
  1060. if (chip_idx == -1) {
  1061. printf ("%s: Unknown Tulip Chip: Vendor=%hX Device=%hX\n", tp->nic_name,
  1062. tp->vendor_id, tp->dev_id);
  1063. return 0;
  1064. }
  1065. tp->pci_id_idx = i;
  1066. tp->flags = tulip_tbl[chip_idx].flags;
  1067. #ifdef TULIP_DEBUG
  1068. if (tulip_debug > 1) {
  1069. printf ("%s: tp->pci_id_idx == %d, name == %s\n", tp->nic_name,
  1070. tp->pci_id_idx, pci_id_tbl[tp->pci_id_idx].name);
  1071. printf ("%s: chip_idx == %d, name == %s\n", tp->nic_name, chip_idx,
  1072. tulip_tbl[chip_idx].chip_name);
  1073. }
  1074. #endif
  1075. /* Bring the 21041/21143 out of sleep mode.
  1076. Caution: Snooze mode does not work with some boards! */
  1077. if (tp->flags & HAS_PWRDWN)
  1078. pcibios_write_config_dword(pci->bus, pci->devfn, 0x40, 0x00000000);
  1079. if (inl(ioaddr + CSR5) == 0xFFFFFFFF) {
  1080. printf("%s: The Tulip chip at %X is not functioning.\n",
  1081. tp->nic_name, ioaddr);
  1082. return 0;
  1083. }
  1084. pcibios_read_config_byte(pci->bus, pci->devfn, PCI_REVISION, &chip_rev);
  1085. printf("%s: [chip: %s] rev %d at %hX\n", tp->nic_name,
  1086. tulip_tbl[chip_idx].chip_name, chip_rev, ioaddr);
  1087. printf("%s: Vendor=%hX Device=%hX", tp->nic_name, tp->vendor_id, tp->dev_id);
  1088. if (chip_idx == DC21041 && inl(ioaddr + CSR9) & 0x8000) {
  1089. printf(" 21040 compatible mode.");
  1090. chip_idx = DC21040;
  1091. }
  1092. printf("\n");
  1093. /* The SROM/EEPROM interface varies dramatically. */
  1094. sum = 0;
  1095. if (chip_idx == DC21040) {
  1096. outl(0, ioaddr + CSR9); /* Reset the pointer with a dummy write. */
  1097. for (i = 0; i < ETH_ALEN; i++) {
  1098. int value, boguscnt = 100000;
  1099. do
  1100. value = inl(ioaddr + CSR9);
  1101. while (value < 0 && --boguscnt > 0);
  1102. nic->node_addr[i] = value;
  1103. sum += value & 0xff;
  1104. }
  1105. } else if (chip_idx == LC82C168) {
  1106. for (i = 0; i < 3; i++) {
  1107. int value, boguscnt = 100000;
  1108. outl(0x600 | i, ioaddr + 0x98);
  1109. do
  1110. value = inl(ioaddr + CSR9);
  1111. while (value < 0 && --boguscnt > 0);
  1112. put_unaligned(le16_to_cpu(value), ((u16*)nic->node_addr) + i);
  1113. sum += value & 0xffff;
  1114. }
  1115. } else if (chip_idx == COMET) {
  1116. /* No need to read the EEPROM. */
  1117. put_unaligned(inl(ioaddr + 0xA4), (u32 *)nic->node_addr);
  1118. put_unaligned(inl(ioaddr + 0xA8), (u16 *)(nic->node_addr + 4));
  1119. for (i = 0; i < ETH_ALEN; i ++)
  1120. sum += nic->node_addr[i];
  1121. } else {
  1122. /* A serial EEPROM interface, we read now and sort it out later. */
  1123. int sa_offset = 0;
  1124. int ee_addr_size = read_eeprom(ioaddr, 0xff, 8) & 0x40000 ? 8 : 6;
  1125. for (i = 0; i < sizeof(ee_data)/2; i++)
  1126. ((u16 *)ee_data)[i] =
  1127. le16_to_cpu(read_eeprom(ioaddr, i, ee_addr_size));
  1128. /* DEC now has a specification (see Notes) but early board makers
  1129. just put the address in the first EEPROM locations. */
  1130. /* This does memcmp(eedata, eedata+16, 8) */
  1131. for (i = 0; i < 8; i ++)
  1132. if (ee_data[i] != ee_data[16+i])
  1133. sa_offset = 20;
  1134. if (ee_data[0] == 0xff && ee_data[1] == 0xff && ee_data[2] == 0) {
  1135. sa_offset = 2; /* Grrr, damn Matrox boards. */
  1136. }
  1137. for (i = 0; i < ETH_ALEN; i ++) {
  1138. nic->node_addr[i] = ee_data[i + sa_offset];
  1139. sum += ee_data[i + sa_offset];
  1140. }
  1141. }
  1142. /* Lite-On boards have the address byte-swapped. */
  1143. if ((nic->node_addr[0] == 0xA0 || nic->node_addr[0] == 0xC0)
  1144. && nic->node_addr[1] == 0x00)
  1145. for (i = 0; i < ETH_ALEN; i+=2) {
  1146. char tmp = nic->node_addr[i];
  1147. nic->node_addr[i] = nic->node_addr[i+1];
  1148. nic->node_addr[i+1] = tmp;
  1149. }
  1150. if (sum == 0 || sum == ETH_ALEN*0xff) {
  1151. printf("%s: EEPROM not present!\n", tp->nic_name);
  1152. for (i = 0; i < ETH_ALEN-1; i++)
  1153. nic->node_addr[i] = last_phys_addr[i];
  1154. nic->node_addr[i] = last_phys_addr[i] + 1;
  1155. }
  1156. for (i = 0; i < ETH_ALEN; i++)
  1157. last_phys_addr[i] = nic->node_addr[i];
  1158. printf("%s: %! at ioaddr %hX\n", tp->nic_name, nic->node_addr, ioaddr);
  1159. tp->chip_id = chip_idx;
  1160. tp->revision = chip_rev;
  1161. tp->csr0 = csr0;
  1162. /* BugFixes: The 21143-TD hangs with PCI Write-and-Invalidate cycles.
  1163. And the ASIX must have a burst limit or horrible things happen. */
  1164. if (chip_idx == DC21143 && chip_rev == 65)
  1165. tp->csr0 &= ~0x01000000;
  1166. else if (tp->flags & IS_ASIX)
  1167. tp->csr0 |= 0x2000;
  1168. if (media_cap[tp->default_port] & MediaIsMII) {
  1169. u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
  1170. tp->mii_advertise = media2advert[tp->default_port - 9];
  1171. tp->mii_advertise |= (tp->flags & HAS_8023X); /* Matching bits! */
  1172. }
  1173. /* This is logically part of the probe routine, but too complex
  1174. to write inline. */
  1175. if (tp->flags & HAS_MEDIA_TABLE) {
  1176. memcpy(tp->eeprom, ee_data, sizeof(tp->eeprom));
  1177. parse_eeprom(nic);
  1178. }
  1179. start_link(nic);
  1180. /* reset the device and make ready for tx and rx of packets */
  1181. tulip_reset(nic);
  1182. nic->reset = tulip_reset;
  1183. nic->poll = tulip_poll;
  1184. nic->transmit = tulip_transmit;
  1185. nic->disable = tulip_disable;
  1186. /* give the board a chance to reset before returning */
  1187. tulip_wait(4*TICKS_PER_SEC);
  1188. return nic;
  1189. }
  1190. static void start_link(struct nic *nic)
  1191. {
  1192. int i;
  1193. #ifdef TULIP_DEBUG_WHERE
  1194. whereami("start_link\n");
  1195. #endif
  1196. if ((tp->flags & ALWAYS_CHECK_MII) ||
  1197. (tp->mtable && tp->mtable->has_mii) ||
  1198. ( ! tp->mtable && (tp->flags & HAS_MII))) {
  1199. unsigned int phy, phy_idx;
  1200. if (tp->mtable && tp->mtable->has_mii) {
  1201. for (i = 0; i < tp->mtable->leafcount; i++)
  1202. if (tp->mtable->mleaf[i].media == 11) {
  1203. tp->cur_index = i;
  1204. tp->saved_if_port = tp->if_port;
  1205. select_media(nic, 2);
  1206. tp->if_port = tp->saved_if_port;
  1207. break;
  1208. }
  1209. }
  1210. /* Find the connected MII xcvrs. */
  1211. for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys);
  1212. phy++) {
  1213. int mii_status = mdio_read(nic, phy, 1);
  1214. if ((mii_status & 0x8301) == 0x8001 ||
  1215. ((mii_status & 0x8000) == 0 && (mii_status & 0x7800) != 0)) {
  1216. int mii_reg0 = mdio_read(nic, phy, 0);
  1217. int mii_advert = mdio_read(nic, phy, 4);
  1218. int to_advert;
  1219. if (tp->mii_advertise)
  1220. to_advert = tp->mii_advertise;
  1221. else if (tp->advertising[phy_idx])
  1222. to_advert = tp->advertising[phy_idx];
  1223. else /* Leave unchanged. */
  1224. tp->mii_advertise = to_advert = mii_advert;
  1225. tp->phys[phy_idx++] = phy;
  1226. printf("%s: MII transceiver %d config %hX status %hX advertising %hX.\n",
  1227. tp->nic_name, phy, mii_reg0, mii_status, mii_advert);
  1228. /* Fixup for DLink with miswired PHY. */
  1229. if (mii_advert != to_advert) {
  1230. printf("%s: Advertising %hX on PHY %d previously advertising %hX.\n",
  1231. tp->nic_name, to_advert, phy, mii_advert);
  1232. mdio_write(nic, phy, 4, to_advert);
  1233. }
  1234. /* Enable autonegotiation: some boards default to off. */
  1235. mdio_write(nic, phy, 0, mii_reg0 |
  1236. (tp->full_duplex ? 0x1100 : 0x1000) |
  1237. (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0));
  1238. }
  1239. }
  1240. tp->mii_cnt = phy_idx;
  1241. if (tp->mtable && tp->mtable->has_mii && phy_idx == 0) {
  1242. printf("%s: ***WARNING***: No MII transceiver found!\n",
  1243. tp->nic_name);
  1244. tp->phys[0] = 1;
  1245. }
  1246. }
  1247. /* Reset the xcvr interface and turn on heartbeat. */
  1248. switch (tp->chip_id) {
  1249. case DC21040:
  1250. outl(0x00000000, ioaddr + CSR13);
  1251. outl(0x00000004, ioaddr + CSR13);
  1252. break;
  1253. case DC21041:
  1254. /* This is nway_start(). */
  1255. if (tp->sym_advertise == 0)
  1256. tp->sym_advertise = 0x0061;
  1257. outl(0x00000000, ioaddr + CSR13);
  1258. outl(0xFFFFFFFF, ioaddr + CSR14);
  1259. outl(0x00000008, ioaddr + CSR15); /* Listen on AUI also. */
  1260. outl(inl(ioaddr + CSR6) | 0x0200, ioaddr + CSR6);
  1261. outl(0x0000EF01, ioaddr + CSR13);
  1262. break;
  1263. case DC21140: default:
  1264. if (tp->mtable)
  1265. outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12);
  1266. break;
  1267. case DC21142:
  1268. case PNIC2:
  1269. if (tp->mii_cnt || media_cap[tp->if_port] & MediaIsMII) {
  1270. outl(0x82020000, ioaddr + CSR6);
  1271. outl(0x0000, ioaddr + CSR13);
  1272. outl(0x0000, ioaddr + CSR14);
  1273. outl(0x820E0000, ioaddr + CSR6);
  1274. } else
  1275. nway_start(nic);
  1276. break;
  1277. case LC82C168:
  1278. if ( ! tp->mii_cnt) {
  1279. tp->nway = 1;
  1280. tp->nwayset = 0;
  1281. outl(0x00420000, ioaddr + CSR6);
  1282. outl(0x30, ioaddr + CSR12);
  1283. outl(0x0001F078, ioaddr + 0xB8);
  1284. outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */
  1285. }
  1286. break;
  1287. case MX98713: case COMPEX9881:
  1288. outl(0x00000000, ioaddr + CSR6);
  1289. outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */
  1290. outl(0x00000001, ioaddr + CSR13);
  1291. break;
  1292. case MX98715: case MX98725:
  1293. outl(0x01a80000, ioaddr + CSR6);
  1294. outl(0xFFFFFFFF, ioaddr + CSR14);
  1295. outl(0x00001000, ioaddr + CSR12);
  1296. break;
  1297. case COMET:
  1298. /* No initialization necessary. */
  1299. break;
  1300. }
  1301. }
  1302. static void nway_start(struct nic *nic)
  1303. {
  1304. int csr14 = ((tp->sym_advertise & 0x0780) << 9) |
  1305. ((tp->sym_advertise&0x0020)<<1) | 0xffbf;
  1306. #ifdef TULIP_DEBUG_WHERE
  1307. whereami("nway_start\n");
  1308. #endif
  1309. tp->if_port = 0;
  1310. tp->nway = tp->mediasense = 1;
  1311. tp->nwayset = tp->lpar = 0;
  1312. if (tp->chip_id == PNIC2) {
  1313. tp->csr6 = 0x01000000 | (tp->sym_advertise & 0x0040 ? 0x0200 : 0);
  1314. return;
  1315. }
  1316. #ifdef TULIP_DEBUG
  1317. if (tulip_debug > 1)
  1318. printf("%s: Restarting internal NWay autonegotiation, %X.\n",
  1319. tp->nic_name, csr14);
  1320. #endif
  1321. outl(0x0001, ioaddr + CSR13);
  1322. outl(csr14, ioaddr + CSR14);
  1323. tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? 0x0200 : 0);
  1324. outl(tp->csr6, ioaddr + CSR6);
  1325. if (tp->mtable && tp->mtable->csr15dir) {
  1326. outl(tp->mtable->csr15dir, ioaddr + CSR15);
  1327. outl(tp->mtable->csr15val, ioaddr + CSR15);
  1328. } else if (tp->chip_id != PNIC2)
  1329. outw(0x0008, ioaddr + CSR15);
  1330. if (tp->chip_id == DC21041) /* Trigger NWAY. */
  1331. outl(0xEF01, ioaddr + CSR12);
  1332. else
  1333. outl(0x1301, ioaddr + CSR12);
  1334. }
  1335. static void init_media(struct nic *nic)
  1336. {
  1337. int i;
  1338. #ifdef TULIP_DEBUG_WHERE
  1339. whereami("init_media\n");
  1340. #endif
  1341. tp->saved_if_port = tp->if_port;
  1342. if (tp->if_port == 0)
  1343. tp->if_port = tp->default_port;
  1344. /* Allow selecting a default media. */
  1345. i = 0;
  1346. if (tp->mtable == NULL)
  1347. goto media_picked;
  1348. if (tp->if_port) {
  1349. int looking_for = media_cap[tp->if_port] & MediaIsMII ? 11 :
  1350. (tp->if_port == 12 ? 0 : tp->if_port);
  1351. for (i = 0; i < tp->mtable->leafcount; i++)
  1352. if (tp->mtable->mleaf[i].media == looking_for) {
  1353. printf("%s: Using user-specified media %s.\n",
  1354. tp->nic_name, medianame[tp->if_port]);
  1355. goto media_picked;
  1356. }
  1357. }
  1358. if ((tp->mtable->defaultmedia & 0x0800) == 0) {
  1359. int looking_for = tp->mtable->defaultmedia & 15;
  1360. for (i = 0; i < tp->mtable->leafcount; i++)
  1361. if (tp->mtable->mleaf[i].media == looking_for) {
  1362. printf("%s: Using EEPROM-set media %s.\n",
  1363. tp->nic_name, medianame[looking_for]);
  1364. goto media_picked;
  1365. }
  1366. }
  1367. /* Start sensing first non-full-duplex media. */
  1368. for (i = tp->mtable->leafcount - 1;
  1369. (media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
  1370. ;
  1371. media_picked:
  1372. tp->csr6 = 0;
  1373. tp->cur_index = i;
  1374. tp->nwayset = 0;
  1375. if (tp->if_port) {
  1376. if (tp->chip_id == DC21143 && media_cap[tp->if_port] & MediaIsMII) {
  1377. /* We must reset the media CSRs when we force-select MII mode. */
  1378. outl(0x0000, ioaddr + CSR13);
  1379. outl(0x0000, ioaddr + CSR14);
  1380. outl(0x0008, ioaddr + CSR15);
  1381. }
  1382. select_media(nic, 1);
  1383. return;
  1384. }
  1385. switch(tp->chip_id) {
  1386. case DC21041:
  1387. /* tp->nway = 1;*/
  1388. nway_start(nic);
  1389. break;
  1390. case DC21142:
  1391. if (tp->mii_cnt) {
  1392. select_media(nic, 1);
  1393. #ifdef TULIP_DEBUG
  1394. if (tulip_debug > 1)
  1395. printf("%s: Using MII transceiver %d, status %hX.\n",
  1396. tp->nic_name, tp->phys[0], mdio_read(nic, tp->phys[0], 1));
  1397. #endif
  1398. outl(0x82020000, ioaddr + CSR6);
  1399. tp->csr6 = 0x820E0000;
  1400. tp->if_port = 11;
  1401. outl(0x0000, ioaddr + CSR13);
  1402. outl(0x0000, ioaddr + CSR14);
  1403. } else
  1404. nway_start(nic);
  1405. break;
  1406. case PNIC2:
  1407. nway_start(nic);
  1408. break;
  1409. case LC82C168:
  1410. if (tp->mii_cnt) {
  1411. tp->if_port = 11;
  1412. tp->csr6 = 0x814C0000 | (tp->full_duplex ? 0x0200 : 0);
  1413. outl(0x0001, ioaddr + CSR15);
  1414. } else if (inl(ioaddr + CSR5) & TPLnkPass)
  1415. pnic_do_nway(nic);
  1416. else {
  1417. /* Start with 10mbps to do autonegotiation. */
  1418. outl(0x32, ioaddr + CSR12);
  1419. tp->csr6 = 0x00420000;
  1420. outl(0x0001B078, ioaddr + 0xB8);
  1421. outl(0x0201B078, ioaddr + 0xB8);
  1422. }
  1423. break;
  1424. case MX98713: case COMPEX9881:
  1425. tp->if_port = 0;
  1426. tp->csr6 = 0x01880000 | (tp->full_duplex ? 0x0200 : 0);
  1427. outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
  1428. break;
  1429. case MX98715: case MX98725:
  1430. /* Provided by BOLO, Macronix - 12/10/1998. */
  1431. tp->if_port = 0;
  1432. tp->csr6 = 0x01a80200;
  1433. outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
  1434. outl(0x11000 | inw(ioaddr + 0xa0), ioaddr + 0xa0);
  1435. break;
  1436. case COMET:
  1437. tp->if_port = 0;
  1438. tp->csr6 = 0x00040000;
  1439. break;
  1440. case AX88140: case AX88141:
  1441. tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100;
  1442. break;
  1443. default:
  1444. select_media(nic, 1);
  1445. }
  1446. }
  1447. static void pnic_do_nway(struct nic *nic)
  1448. {
  1449. u32 phy_reg = inl(ioaddr + 0xB8);
  1450. u32 new_csr6 = tp->csr6 & ~0x40C40200;
  1451. #ifdef TULIP_DEBUG_WHERE
  1452. whereami("pnic_do_nway\n");
  1453. #endif
  1454. if (phy_reg & 0x78000000) { /* Ignore baseT4 */
  1455. if (phy_reg & 0x20000000) tp->if_port = 5;
  1456. else if (phy_reg & 0x40000000) tp->if_port = 3;
  1457. else if (phy_reg & 0x10000000) tp->if_port = 4;
  1458. else if (phy_reg & 0x08000000) tp->if_port = 0;
  1459. tp->nwayset = 1;
  1460. new_csr6 = (tp->if_port & 1) ? 0x01860000 : 0x00420000;
  1461. outl(0x32 | (tp->if_port & 1), ioaddr + CSR12);
  1462. if (tp->if_port & 1)
  1463. outl(0x1F868, ioaddr + 0xB8);
  1464. if (phy_reg & 0x30000000) {
  1465. tp->full_duplex = 1;
  1466. new_csr6 |= 0x00000200;
  1467. }
  1468. #ifdef TULIP_DEBUG
  1469. if (tulip_debug > 1)
  1470. printf("%s: PNIC autonegotiated status %X, %s.\n",
  1471. tp->nic_name, phy_reg, medianame[tp->if_port]);
  1472. #endif
  1473. if (tp->csr6 != new_csr6) {
  1474. tp->csr6 = new_csr6;
  1475. outl(tp->csr6 | 0x0002, ioaddr + CSR6); /* Restart Tx */
  1476. outl(tp->csr6 | 0x2002, ioaddr + CSR6);
  1477. }
  1478. }
  1479. }
  1480. /* Set up the transceiver control registers for the selected media type. */
  1481. static void select_media(struct nic *nic, int startup)
  1482. {
  1483. struct mediatable *mtable = tp->mtable;
  1484. u32 new_csr6;
  1485. int i;
  1486. #ifdef TULIP_DEBUG_WHERE
  1487. whereami("select_media\n");
  1488. #endif
  1489. if (mtable) {
  1490. struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index];
  1491. unsigned char *p = mleaf->leafdata;
  1492. switch (mleaf->type) {
  1493. case 0: /* 21140 non-MII xcvr. */
  1494. #ifdef TULIP_DEBUG
  1495. if (tulip_debug > 1)
  1496. printf("%s: Using a 21140 non-MII transceiver"
  1497. " with control setting %hhX.\n",
  1498. tp->nic_name, p[1]);
  1499. #endif
  1500. tp->if_port = p[0];
  1501. if (startup)
  1502. outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
  1503. outl(p[1], ioaddr + CSR12);
  1504. new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);
  1505. break;
  1506. case 2: case 4: {
  1507. u16 setup[5];
  1508. u32 csr13val, csr14val, csr15dir, csr15val;
  1509. for (i = 0; i < 5; i++)
  1510. setup[i] = get_u16(&p[i*2 + 1]);
  1511. tp->if_port = p[0] & 15;
  1512. if (media_cap[tp->if_port] & MediaAlwaysFD)
  1513. tp->full_duplex = 1;
  1514. if (startup && mtable->has_reset) {
  1515. struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset];
  1516. unsigned char *rst = rleaf->leafdata;
  1517. #ifdef TULIP_DEBUG
  1518. if (tulip_debug > 1)
  1519. printf("%s: Resetting the transceiver.\n",
  1520. tp->nic_name);
  1521. #endif
  1522. for (i = 0; i < rst[0]; i++)
  1523. outl(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15);
  1524. }
  1525. #ifdef TULIP_DEBUG
  1526. if (tulip_debug > 1)
  1527. printf("%s: 21143 non-MII %s transceiver control "
  1528. "%hX/%hX.\n",
  1529. tp->nic_name, medianame[tp->if_port], setup[0], setup[1]);
  1530. #endif
  1531. if (p[0] & 0x40) { /* SIA (CSR13-15) setup values are provided. */
  1532. csr13val = setup[0];
  1533. csr14val = setup[1];
  1534. csr15dir = (setup[3]<<16) | setup[2];
  1535. csr15val = (setup[4]<<16) | setup[2];
  1536. outl(0, ioaddr + CSR13);
  1537. outl(csr14val, ioaddr + CSR14);
  1538. outl(csr15dir, ioaddr + CSR15); /* Direction */
  1539. outl(csr15val, ioaddr + CSR15); /* Data */
  1540. outl(csr13val, ioaddr + CSR13);
  1541. } else {
  1542. csr13val = 1;
  1543. csr14val = 0x0003FF7F;
  1544. csr15dir = (setup[0]<<16) | 0x0008;
  1545. csr15val = (setup[1]<<16) | 0x0008;
  1546. if (tp->if_port <= 4)
  1547. csr14val = t21142_csr14[tp->if_port];
  1548. if (startup) {
  1549. outl(0, ioaddr + CSR13);
  1550. outl(csr14val, ioaddr + CSR14);
  1551. }
  1552. outl(csr15dir, ioaddr + CSR15); /* Direction */
  1553. outl(csr15val, ioaddr + CSR15); /* Data */
  1554. if (startup) outl(csr13val, ioaddr + CSR13);
  1555. }
  1556. #ifdef TULIP_DEBUG
  1557. if (tulip_debug > 1)
  1558. printf("%s: Setting CSR15 to %X/%X.\n",
  1559. tp->nic_name, csr15dir, csr15val);
  1560. #endif
  1561. if (mleaf->type == 4)
  1562. new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18);
  1563. else
  1564. new_csr6 = 0x82420000;
  1565. break;
  1566. }
  1567. case 1: case 3: {
  1568. int phy_num = p[0];
  1569. int init_length = p[1];
  1570. u16 *misc_info;
  1571. tp->if_port = 11;
  1572. new_csr6 = 0x020E0000;
  1573. if (mleaf->type == 3) { /* 21142 */
  1574. u16 *init_sequence = (u16*)(p+2);
  1575. u16 *reset_sequence = &((u16*)(p+3))[init_length];
  1576. int reset_length = p[2 + init_length*2];
  1577. misc_info = reset_sequence + reset_length;
  1578. if (startup)
  1579. for (i = 0; i < reset_length; i++)
  1580. outl(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);
  1581. for (i = 0; i < init_length; i++)
  1582. outl(get_u16(&init_sequence[i]) << 16, ioaddr + CSR15);
  1583. } else {
  1584. u8 *init_sequence = p + 2;
  1585. u8 *reset_sequence = p + 3 + init_length;
  1586. int reset_length = p[2 + init_length];
  1587. misc_info = (u16*)(reset_sequence + reset_length);
  1588. if (startup) {
  1589. outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
  1590. for (i = 0; i < reset_length; i++)
  1591. outl(reset_sequence[i], ioaddr + CSR12);
  1592. }
  1593. for (i = 0; i < init_length; i++)
  1594. outl(init_sequence[i], ioaddr + CSR12);
  1595. }
  1596. tp->advertising[phy_num] = get_u16(&misc_info[1]) | 1;
  1597. if (startup < 2) {
  1598. if (tp->mii_advertise == 0)
  1599. tp->mii_advertise = tp->advertising[phy_num];
  1600. #ifdef TULIP_DEBUG
  1601. if (tulip_debug > 1)
  1602. printf("%s: Advertising %hX on MII %d.\n",
  1603. tp->nic_name, tp->mii_advertise, tp->phys[phy_num]);
  1604. #endif
  1605. mdio_write(nic, tp->phys[phy_num], 4, tp->mii_advertise);
  1606. }
  1607. break;
  1608. }
  1609. default:
  1610. printf("%s: Invalid media table selection %d.\n",
  1611. tp->nic_name, mleaf->type);
  1612. new_csr6 = 0x020E0000;
  1613. }
  1614. #ifdef TULIP_DEBUG
  1615. if (tulip_debug > 1)
  1616. printf("%s: Using media type %s, CSR12 is %hhX.\n",
  1617. tp->nic_name, medianame[tp->if_port],
  1618. inl(ioaddr + CSR12) & 0xff);
  1619. #endif
  1620. } else if (tp->chip_id == DC21041) {
  1621. int port = tp->if_port <= 4 ? tp->if_port : 0;
  1622. #ifdef TULIP_DEBUG
  1623. if (tulip_debug > 1)
  1624. printf("%s: 21041 using media %s, CSR12 is %hX.\n",
  1625. tp->nic_name, medianame[port == 3 ? 12: port],
  1626. inl(ioaddr + CSR12));
  1627. #endif
  1628. outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
  1629. outl(t21041_csr14[port], ioaddr + CSR14);
  1630. outl(t21041_csr15[port], ioaddr + CSR15);
  1631. outl(t21041_csr13[port], ioaddr + CSR13);
  1632. new_csr6 = 0x80020000;
  1633. } else if (tp->chip_id == LC82C168) {
  1634. if (startup && ! tp->medialock)
  1635. tp->if_port = tp->mii_cnt ? 11 : 0;
  1636. #ifdef TULIP_DEBUG
  1637. if (tulip_debug > 1)
  1638. printf("%s: PNIC PHY status is %hX, media %s.\n",
  1639. tp->nic_name, inl(ioaddr + 0xB8), medianame[tp->if_port]);
  1640. #endif
  1641. if (tp->mii_cnt) {
  1642. new_csr6 = 0x810C0000;
  1643. outl(0x0001, ioaddr + CSR15);
  1644. outl(0x0201B07A, ioaddr + 0xB8);
  1645. } else if (startup) {
  1646. /* Start with 10mbps to do autonegotiation. */
  1647. outl(0x32, ioaddr + CSR12);
  1648. new_csr6 = 0x00420000;
  1649. outl(0x0001B078, ioaddr + 0xB8);
  1650. outl(0x0201B078, ioaddr + 0xB8);
  1651. } else if (tp->if_port == 3 || tp->if_port == 5) {
  1652. outl(0x33, ioaddr + CSR12);
  1653. new_csr6 = 0x01860000;
  1654. /* Trigger autonegotiation. */
  1655. outl(startup ? 0x0201F868 : 0x0001F868, ioaddr + 0xB8);
  1656. } else {
  1657. outl(0x32, ioaddr + CSR12);
  1658. new_csr6 = 0x00420000;
  1659. outl(0x1F078, ioaddr + 0xB8);
  1660. }
  1661. } else if (tp->chip_id == DC21040) { /* 21040 */
  1662. /* Turn on the xcvr interface. */
  1663. int csr12 = inl(ioaddr + CSR12);
  1664. #ifdef TULIP_DEBUG
  1665. if (tulip_debug > 1)
  1666. printf("%s: 21040 media type is %s, CSR12 is %hhX.\n",
  1667. tp->nic_name, medianame[tp->if_port], csr12);
  1668. #endif
  1669. if (media_cap[tp->if_port] & MediaAlwaysFD)
  1670. tp->full_duplex = 1;
  1671. new_csr6 = 0x20000;
  1672. /* Set the full duplux match frame. */
  1673. outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11);
  1674. outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
  1675. if (t21040_csr13[tp->if_port] & 8) {
  1676. outl(0x0705, ioaddr + CSR14);
  1677. outl(0x0006, ioaddr + CSR15);
  1678. } else {
  1679. outl(0xffff, ioaddr + CSR14);
  1680. outl(0x0000, ioaddr + CSR15);
  1681. }
  1682. outl(0x8f01 | t21040_csr13[tp->if_port], ioaddr + CSR13);
  1683. } else { /* Unknown chip type with no media table. */
  1684. if (tp->default_port == 0)
  1685. tp->if_port = tp->mii_cnt ? 11 : 3;
  1686. if (media_cap[tp->if_port] & MediaIsMII) {
  1687. new_csr6 = 0x020E0000;
  1688. } else if (media_cap[tp->if_port] & MediaIsFx) {
  1689. new_csr6 = 0x028600000;
  1690. } else
  1691. new_csr6 = 0x038600000;
  1692. #ifdef TULIP_DEBUG
  1693. if (tulip_debug > 1)
  1694. printf("%s: No media description table, assuming "
  1695. "%s transceiver, CSR12 %hhX.\n",
  1696. tp->nic_name, medianame[tp->if_port],
  1697. inl(ioaddr + CSR12));
  1698. #endif
  1699. }
  1700. tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);
  1701. return;
  1702. }
  1703. /*
  1704. Check the MII negotiated duplex and change the CSR6 setting if
  1705. required.
  1706. Return 0 if everything is OK.
  1707. Return < 0 if the transceiver is missing or has no link beat.
  1708. */
  1709. static int tulip_check_duplex(struct nic *nic)
  1710. {
  1711. unsigned int bmsr, lpa, negotiated, new_csr6;
  1712. bmsr = mdio_read(nic, tp->phys[0], 1);
  1713. lpa = mdio_read(nic, tp->phys[0], 5);
  1714. #ifdef TULIP_DEBUG
  1715. if (tulip_debug > 1)
  1716. printf("%s: MII status %#x, Link partner report "
  1717. "%#x.\n", tp->nic_name, bmsr, lpa);
  1718. #endif
  1719. if (bmsr == 0xffff)
  1720. return -2;
  1721. if ((bmsr & 4) == 0) {
  1722. int new_bmsr = mdio_read(nic, tp->phys[0], 1);
  1723. if ((new_bmsr & 4) == 0) {
  1724. #ifdef TULIP_DEBUG
  1725. if (tulip_debug > 1)
  1726. printf("%s: No link beat on the MII interface,"
  1727. " status %#x.\n", tp->nic_name,
  1728. new_bmsr);
  1729. #endif
  1730. return -1;
  1731. }
  1732. }
  1733. tp->full_duplex = lpa & 0x140;
  1734. new_csr6 = tp->csr6;
  1735. negotiated = lpa & tp->advertising[0];
  1736. if(negotiated & 0x380) new_csr6 &= ~0x400000;
  1737. else new_csr6 |= 0x400000;
  1738. if (tp->full_duplex) new_csr6 |= 0x200;
  1739. else new_csr6 &= ~0x200;
  1740. if (new_csr6 != tp->csr6) {
  1741. tp->csr6 = new_csr6;
  1742. #ifdef TULIP_DEBUG
  1743. if (tulip_debug > 0)
  1744. printf("%s: Setting %s-duplex based on MII"
  1745. "#%d link partner capability of %#x.\n",
  1746. tp->nic_name,
  1747. tp->full_duplex ? "full" : "half",
  1748. tp->phys[0], lpa);
  1749. #endif
  1750. return 1;
  1751. }
  1752. return 0;
  1753. }