Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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