tulip_core.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006
  1. /* tulip_core.c: A DEC 21x4x-family ethernet driver for Linux.
  2. Copyright 2000,2001 The Linux Kernel Team
  3. Written/copyright 1994-2001 by Donald Becker.
  4. This software may be used and distributed according to the terms
  5. of the GNU General Public License, incorporated herein by reference.
  6. Please submit bugs to http://bugzilla.kernel.org/ .
  7. */
  8. #define pr_fmt(fmt) "tulip: " fmt
  9. #define DRV_NAME "tulip"
  10. #ifdef CONFIG_TULIP_NAPI
  11. #define DRV_VERSION "1.1.15-NAPI" /* Keep at least for test */
  12. #else
  13. #define DRV_VERSION "1.1.15"
  14. #endif
  15. #define DRV_RELDATE "Feb 27, 2007"
  16. #include <linux/module.h>
  17. #include <linux/pci.h>
  18. #include <linux/slab.h>
  19. #include "tulip.h"
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/delay.h>
  24. #include <linux/mii.h>
  25. #include <linux/crc32.h>
  26. #include <asm/unaligned.h>
  27. #include <asm/uaccess.h>
  28. #ifdef CONFIG_SPARC
  29. #include <asm/prom.h>
  30. #endif
  31. static char version[] =
  32. "Linux Tulip driver version " DRV_VERSION " (" DRV_RELDATE ")\n";
  33. /* A few user-configurable values. */
  34. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  35. static unsigned int max_interrupt_work = 25;
  36. #define MAX_UNITS 8
  37. /* Used to pass the full-duplex flag, etc. */
  38. static int full_duplex[MAX_UNITS];
  39. static int options[MAX_UNITS];
  40. static int mtu[MAX_UNITS]; /* Jumbo MTU for interfaces. */
  41. /* The possible media types that can be set in options[] are: */
  42. const char * const medianame[32] = {
  43. "10baseT", "10base2", "AUI", "100baseTx",
  44. "10baseT-FDX", "100baseTx-FDX", "100baseT4", "100baseFx",
  45. "100baseFx-FDX", "MII 10baseT", "MII 10baseT-FDX", "MII",
  46. "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FDX", "MII 100baseT4",
  47. "MII 100baseFx-HDX", "MII 100baseFx-FDX", "Home-PNA 1Mbps", "Invalid-19",
  48. "","","","", "","","","", "","","","Transceiver reset",
  49. };
  50. /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
  51. #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) || \
  52. defined(CONFIG_SPARC) || defined(__ia64__) || \
  53. defined(__sh__) || defined(__mips__)
  54. static int rx_copybreak = 1518;
  55. #else
  56. static int rx_copybreak = 100;
  57. #endif
  58. /*
  59. Set the bus performance register.
  60. Typical: Set 16 longword cache alignment, no burst limit.
  61. Cache alignment bits 15:14 Burst length 13:8
  62. 0000 No alignment 0x00000000 unlimited 0800 8 longwords
  63. 4000 8 longwords 0100 1 longword 1000 16 longwords
  64. 8000 16 longwords 0200 2 longwords 2000 32 longwords
  65. C000 32 longwords 0400 4 longwords
  66. Warning: many older 486 systems are broken and require setting 0x00A04800
  67. 8 longword cache alignment, 8 longword burst.
  68. ToDo: Non-Intel setting could be better.
  69. */
  70. #if defined(__alpha__) || defined(__ia64__)
  71. static int csr0 = 0x01A00000 | 0xE000;
  72. #elif defined(__i386__) || defined(__powerpc__) || defined(__x86_64__)
  73. static int csr0 = 0x01A00000 | 0x8000;
  74. #elif defined(CONFIG_SPARC) || defined(__hppa__)
  75. /* The UltraSparc PCI controllers will disconnect at every 64-byte
  76. * crossing anyways so it makes no sense to tell Tulip to burst
  77. * any more than that.
  78. */
  79. static int csr0 = 0x01A00000 | 0x9000;
  80. #elif defined(__arm__) || defined(__sh__)
  81. static int csr0 = 0x01A00000 | 0x4800;
  82. #elif defined(__mips__)
  83. static int csr0 = 0x00200000 | 0x4000;
  84. #else
  85. static int csr0;
  86. #endif
  87. /* Operational parameters that usually are not changed. */
  88. /* Time in jiffies before concluding the transmitter is hung. */
  89. #define TX_TIMEOUT (4*HZ)
  90. MODULE_AUTHOR("The Linux Kernel Team");
  91. MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver");
  92. MODULE_LICENSE("GPL");
  93. MODULE_VERSION(DRV_VERSION);
  94. module_param(tulip_debug, int, 0);
  95. module_param(max_interrupt_work, int, 0);
  96. module_param(rx_copybreak, int, 0);
  97. module_param(csr0, int, 0);
  98. module_param_array(options, int, NULL, 0);
  99. module_param_array(full_duplex, int, NULL, 0);
  100. #ifdef TULIP_DEBUG
  101. int tulip_debug = TULIP_DEBUG;
  102. #else
  103. int tulip_debug = 1;
  104. #endif
  105. static void tulip_timer(unsigned long data)
  106. {
  107. struct net_device *dev = (struct net_device *)data;
  108. struct tulip_private *tp = netdev_priv(dev);
  109. if (netif_running(dev))
  110. schedule_work(&tp->media_work);
  111. }
  112. /*
  113. * This table use during operation for capabilities and media timer.
  114. *
  115. * It is indexed via the values in 'enum chips'
  116. */
  117. struct tulip_chip_table tulip_tbl[] = {
  118. { }, /* placeholder for array, slot unused currently */
  119. { }, /* placeholder for array, slot unused currently */
  120. /* DC21140 */
  121. { "Digital DS21140 Tulip", 128, 0x0001ebef,
  122. HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | HAS_PCI_MWI, tulip_timer,
  123. tulip_media_task },
  124. /* DC21142, DC21143 */
  125. { "Digital DS21142/43 Tulip", 128, 0x0801fbff,
  126. HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_ACPI | HAS_NWAY
  127. | HAS_INTR_MITIGATION | HAS_PCI_MWI, tulip_timer, t21142_media_task },
  128. /* LC82C168 */
  129. { "Lite-On 82c168 PNIC", 256, 0x0001fbef,
  130. HAS_MII | HAS_PNICNWAY, pnic_timer, },
  131. /* MX98713 */
  132. { "Macronix 98713 PMAC", 128, 0x0001ebef,
  133. HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer, },
  134. /* MX98715 */
  135. { "Macronix 98715 PMAC", 256, 0x0001ebef,
  136. HAS_MEDIA_TABLE, mxic_timer, },
  137. /* MX98725 */
  138. { "Macronix 98725 PMAC", 256, 0x0001ebef,
  139. HAS_MEDIA_TABLE, mxic_timer, },
  140. /* AX88140 */
  141. { "ASIX AX88140", 128, 0x0001fbff,
  142. HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | MC_HASH_ONLY
  143. | IS_ASIX, tulip_timer, tulip_media_task },
  144. /* PNIC2 */
  145. { "Lite-On PNIC-II", 256, 0x0801fbff,
  146. HAS_MII | HAS_NWAY | HAS_8023X | HAS_PCI_MWI, pnic2_timer, },
  147. /* COMET */
  148. { "ADMtek Comet", 256, 0x0001abef,
  149. HAS_MII | MC_HASH_ONLY | COMET_MAC_ADDR, comet_timer, },
  150. /* COMPEX9881 */
  151. { "Compex 9881 PMAC", 128, 0x0001ebef,
  152. HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer, },
  153. /* I21145 */
  154. { "Intel DS21145 Tulip", 128, 0x0801fbff,
  155. HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_ACPI
  156. | HAS_NWAY | HAS_PCI_MWI, tulip_timer, tulip_media_task },
  157. /* DM910X */
  158. #ifdef CONFIG_TULIP_DM910X
  159. { "Davicom DM9102/DM9102A", 128, 0x0001ebef,
  160. HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | HAS_ACPI,
  161. tulip_timer, tulip_media_task },
  162. #else
  163. { NULL },
  164. #endif
  165. /* RS7112 */
  166. { "Conexant LANfinity", 256, 0x0001ebef,
  167. HAS_MII | HAS_ACPI, tulip_timer, tulip_media_task },
  168. };
  169. static const struct pci_device_id tulip_pci_tbl[] = {
  170. { 0x1011, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21140 },
  171. { 0x1011, 0x0019, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21143 },
  172. { 0x11AD, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, LC82C168 },
  173. { 0x10d9, 0x0512, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98713 },
  174. { 0x10d9, 0x0531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98715 },
  175. /* { 0x10d9, 0x0531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98725 },*/
  176. { 0x125B, 0x1400, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AX88140 },
  177. { 0x11AD, 0xc115, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PNIC2 },
  178. { 0x1317, 0x0981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  179. { 0x1317, 0x0985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  180. { 0x1317, 0x1985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  181. { 0x1317, 0x9511, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  182. { 0x13D1, 0xAB02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  183. { 0x13D1, 0xAB03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  184. { 0x13D1, 0xAB08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  185. { 0x104A, 0x0981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  186. { 0x104A, 0x2774, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  187. { 0x1259, 0xa120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  188. { 0x11F6, 0x9881, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMPEX9881 },
  189. { 0x8086, 0x0039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, I21145 },
  190. #ifdef CONFIG_TULIP_DM910X
  191. { 0x1282, 0x9100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DM910X },
  192. { 0x1282, 0x9102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DM910X },
  193. #endif
  194. { 0x1113, 0x1216, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  195. { 0x1113, 0x1217, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98715 },
  196. { 0x1113, 0x9511, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  197. { 0x1186, 0x1541, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  198. { 0x1186, 0x1561, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  199. { 0x1186, 0x1591, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  200. { 0x14f1, 0x1803, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CONEXANT },
  201. { 0x1626, 0x8410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  202. { 0x1737, 0xAB09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  203. { 0x1737, 0xAB08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  204. { 0x17B3, 0xAB08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  205. { 0x10b7, 0x9300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* 3Com 3CSOHO100B-TX */
  206. { 0x14ea, 0xab08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* Planex FNW-3602-TX */
  207. { 0x1414, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* Microsoft MN-120 */
  208. { 0x1414, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
  209. { } /* terminate list */
  210. };
  211. MODULE_DEVICE_TABLE(pci, tulip_pci_tbl);
  212. /* A full-duplex map for media types. */
  213. const char tulip_media_cap[32] =
  214. {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20, 28,31,0,0, };
  215. static void tulip_tx_timeout(struct net_device *dev);
  216. static void tulip_init_ring(struct net_device *dev);
  217. static void tulip_free_ring(struct net_device *dev);
  218. static netdev_tx_t tulip_start_xmit(struct sk_buff *skb,
  219. struct net_device *dev);
  220. static int tulip_open(struct net_device *dev);
  221. static int tulip_close(struct net_device *dev);
  222. static void tulip_up(struct net_device *dev);
  223. static void tulip_down(struct net_device *dev);
  224. static struct net_device_stats *tulip_get_stats(struct net_device *dev);
  225. static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  226. static void set_rx_mode(struct net_device *dev);
  227. static void tulip_set_wolopts(struct pci_dev *pdev, u32 wolopts);
  228. #ifdef CONFIG_NET_POLL_CONTROLLER
  229. static void poll_tulip(struct net_device *dev);
  230. #endif
  231. static void tulip_set_power_state (struct tulip_private *tp,
  232. int sleep, int snooze)
  233. {
  234. if (tp->flags & HAS_ACPI) {
  235. u32 tmp, newtmp;
  236. pci_read_config_dword (tp->pdev, CFDD, &tmp);
  237. newtmp = tmp & ~(CFDD_Sleep | CFDD_Snooze);
  238. if (sleep)
  239. newtmp |= CFDD_Sleep;
  240. else if (snooze)
  241. newtmp |= CFDD_Snooze;
  242. if (tmp != newtmp)
  243. pci_write_config_dword (tp->pdev, CFDD, newtmp);
  244. }
  245. }
  246. static void tulip_up(struct net_device *dev)
  247. {
  248. struct tulip_private *tp = netdev_priv(dev);
  249. void __iomem *ioaddr = tp->base_addr;
  250. int next_tick = 3*HZ;
  251. u32 reg;
  252. int i;
  253. #ifdef CONFIG_TULIP_NAPI
  254. napi_enable(&tp->napi);
  255. #endif
  256. /* Wake the chip from sleep/snooze mode. */
  257. tulip_set_power_state (tp, 0, 0);
  258. /* Disable all WOL events */
  259. pci_enable_wake(tp->pdev, PCI_D3hot, 0);
  260. pci_enable_wake(tp->pdev, PCI_D3cold, 0);
  261. tulip_set_wolopts(tp->pdev, 0);
  262. /* On some chip revs we must set the MII/SYM port before the reset!? */
  263. if (tp->mii_cnt || (tp->mtable && tp->mtable->has_mii))
  264. iowrite32(0x00040000, ioaddr + CSR6);
  265. /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
  266. iowrite32(0x00000001, ioaddr + CSR0);
  267. pci_read_config_dword(tp->pdev, PCI_COMMAND, &reg); /* flush write */
  268. udelay(100);
  269. /* Deassert reset.
  270. Wait the specified 50 PCI cycles after a reset by initializing
  271. Tx and Rx queues and the address filter list. */
  272. iowrite32(tp->csr0, ioaddr + CSR0);
  273. pci_read_config_dword(tp->pdev, PCI_COMMAND, &reg); /* flush write */
  274. udelay(100);
  275. if (tulip_debug > 1)
  276. netdev_dbg(dev, "tulip_up(), irq==%d\n", tp->pdev->irq);
  277. iowrite32(tp->rx_ring_dma, ioaddr + CSR3);
  278. iowrite32(tp->tx_ring_dma, ioaddr + CSR4);
  279. tp->cur_rx = tp->cur_tx = 0;
  280. tp->dirty_rx = tp->dirty_tx = 0;
  281. if (tp->flags & MC_HASH_ONLY) {
  282. u32 addr_low = get_unaligned_le32(dev->dev_addr);
  283. u32 addr_high = get_unaligned_le16(dev->dev_addr + 4);
  284. if (tp->chip_id == AX88140) {
  285. iowrite32(0, ioaddr + CSR13);
  286. iowrite32(addr_low, ioaddr + CSR14);
  287. iowrite32(1, ioaddr + CSR13);
  288. iowrite32(addr_high, ioaddr + CSR14);
  289. } else if (tp->flags & COMET_MAC_ADDR) {
  290. iowrite32(addr_low, ioaddr + 0xA4);
  291. iowrite32(addr_high, ioaddr + 0xA8);
  292. iowrite32(0, ioaddr + CSR27);
  293. iowrite32(0, ioaddr + CSR28);
  294. }
  295. } else {
  296. /* This is set_rx_mode(), but without starting the transmitter. */
  297. u16 *eaddrs = (u16 *)dev->dev_addr;
  298. u16 *setup_frm = &tp->setup_frame[15*6];
  299. dma_addr_t mapping;
  300. /* 21140 bug: you must add the broadcast address. */
  301. memset(tp->setup_frame, 0xff, sizeof(tp->setup_frame));
  302. /* Fill the final entry of the table with our physical address. */
  303. *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
  304. *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
  305. *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
  306. mapping = pci_map_single(tp->pdev, tp->setup_frame,
  307. sizeof(tp->setup_frame),
  308. PCI_DMA_TODEVICE);
  309. tp->tx_buffers[tp->cur_tx].skb = NULL;
  310. tp->tx_buffers[tp->cur_tx].mapping = mapping;
  311. /* Put the setup frame on the Tx list. */
  312. tp->tx_ring[tp->cur_tx].length = cpu_to_le32(0x08000000 | 192);
  313. tp->tx_ring[tp->cur_tx].buffer1 = cpu_to_le32(mapping);
  314. tp->tx_ring[tp->cur_tx].status = cpu_to_le32(DescOwned);
  315. tp->cur_tx++;
  316. }
  317. tp->saved_if_port = dev->if_port;
  318. if (dev->if_port == 0)
  319. dev->if_port = tp->default_port;
  320. /* Allow selecting a default media. */
  321. i = 0;
  322. if (tp->mtable == NULL)
  323. goto media_picked;
  324. if (dev->if_port) {
  325. int looking_for = tulip_media_cap[dev->if_port] & MediaIsMII ? 11 :
  326. (dev->if_port == 12 ? 0 : dev->if_port);
  327. for (i = 0; i < tp->mtable->leafcount; i++)
  328. if (tp->mtable->mleaf[i].media == looking_for) {
  329. dev_info(&dev->dev,
  330. "Using user-specified media %s\n",
  331. medianame[dev->if_port]);
  332. goto media_picked;
  333. }
  334. }
  335. if ((tp->mtable->defaultmedia & 0x0800) == 0) {
  336. int looking_for = tp->mtable->defaultmedia & MEDIA_MASK;
  337. for (i = 0; i < tp->mtable->leafcount; i++)
  338. if (tp->mtable->mleaf[i].media == looking_for) {
  339. dev_info(&dev->dev,
  340. "Using EEPROM-set media %s\n",
  341. medianame[looking_for]);
  342. goto media_picked;
  343. }
  344. }
  345. /* Start sensing first non-full-duplex media. */
  346. for (i = tp->mtable->leafcount - 1;
  347. (tulip_media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
  348. ;
  349. media_picked:
  350. tp->csr6 = 0;
  351. tp->cur_index = i;
  352. tp->nwayset = 0;
  353. if (dev->if_port) {
  354. if (tp->chip_id == DC21143 &&
  355. (tulip_media_cap[dev->if_port] & MediaIsMII)) {
  356. /* We must reset the media CSRs when we force-select MII mode. */
  357. iowrite32(0x0000, ioaddr + CSR13);
  358. iowrite32(0x0000, ioaddr + CSR14);
  359. iowrite32(0x0008, ioaddr + CSR15);
  360. }
  361. tulip_select_media(dev, 1);
  362. } else if (tp->chip_id == DC21142) {
  363. if (tp->mii_cnt) {
  364. tulip_select_media(dev, 1);
  365. if (tulip_debug > 1)
  366. dev_info(&dev->dev,
  367. "Using MII transceiver %d, status %04x\n",
  368. tp->phys[0],
  369. tulip_mdio_read(dev, tp->phys[0], 1));
  370. iowrite32(csr6_mask_defstate, ioaddr + CSR6);
  371. tp->csr6 = csr6_mask_hdcap;
  372. dev->if_port = 11;
  373. iowrite32(0x0000, ioaddr + CSR13);
  374. iowrite32(0x0000, ioaddr + CSR14);
  375. } else
  376. t21142_start_nway(dev);
  377. } else if (tp->chip_id == PNIC2) {
  378. /* for initial startup advertise 10/100 Full and Half */
  379. tp->sym_advertise = 0x01E0;
  380. /* enable autonegotiate end interrupt */
  381. iowrite32(ioread32(ioaddr+CSR5)| 0x00008010, ioaddr + CSR5);
  382. iowrite32(ioread32(ioaddr+CSR7)| 0x00008010, ioaddr + CSR7);
  383. pnic2_start_nway(dev);
  384. } else if (tp->chip_id == LC82C168 && ! tp->medialock) {
  385. if (tp->mii_cnt) {
  386. dev->if_port = 11;
  387. tp->csr6 = 0x814C0000 | (tp->full_duplex ? 0x0200 : 0);
  388. iowrite32(0x0001, ioaddr + CSR15);
  389. } else if (ioread32(ioaddr + CSR5) & TPLnkPass)
  390. pnic_do_nway(dev);
  391. else {
  392. /* Start with 10mbps to do autonegotiation. */
  393. iowrite32(0x32, ioaddr + CSR12);
  394. tp->csr6 = 0x00420000;
  395. iowrite32(0x0001B078, ioaddr + 0xB8);
  396. iowrite32(0x0201B078, ioaddr + 0xB8);
  397. next_tick = 1*HZ;
  398. }
  399. } else if ((tp->chip_id == MX98713 || tp->chip_id == COMPEX9881) &&
  400. ! tp->medialock) {
  401. dev->if_port = 0;
  402. tp->csr6 = 0x01880000 | (tp->full_duplex ? 0x0200 : 0);
  403. iowrite32(0x0f370000 | ioread16(ioaddr + 0x80), ioaddr + 0x80);
  404. } else if (tp->chip_id == MX98715 || tp->chip_id == MX98725) {
  405. /* Provided by BOLO, Macronix - 12/10/1998. */
  406. dev->if_port = 0;
  407. tp->csr6 = 0x01a80200;
  408. iowrite32(0x0f370000 | ioread16(ioaddr + 0x80), ioaddr + 0x80);
  409. iowrite32(0x11000 | ioread16(ioaddr + 0xa0), ioaddr + 0xa0);
  410. } else if (tp->chip_id == COMET || tp->chip_id == CONEXANT) {
  411. /* Enable automatic Tx underrun recovery. */
  412. iowrite32(ioread32(ioaddr + 0x88) | 1, ioaddr + 0x88);
  413. dev->if_port = tp->mii_cnt ? 11 : 0;
  414. tp->csr6 = 0x00040000;
  415. } else if (tp->chip_id == AX88140) {
  416. tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100;
  417. } else
  418. tulip_select_media(dev, 1);
  419. /* Start the chip's Tx to process setup frame. */
  420. tulip_stop_rxtx(tp);
  421. barrier();
  422. udelay(5);
  423. iowrite32(tp->csr6 | TxOn, ioaddr + CSR6);
  424. /* Enable interrupts by setting the interrupt mask. */
  425. iowrite32(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR5);
  426. iowrite32(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
  427. tulip_start_rxtx(tp);
  428. iowrite32(0, ioaddr + CSR2); /* Rx poll demand */
  429. if (tulip_debug > 2) {
  430. netdev_dbg(dev, "Done tulip_up(), CSR0 %08x, CSR5 %08x CSR6 %08x\n",
  431. ioread32(ioaddr + CSR0),
  432. ioread32(ioaddr + CSR5),
  433. ioread32(ioaddr + CSR6));
  434. }
  435. /* Set the timer to switch to check for link beat and perhaps switch
  436. to an alternate media type. */
  437. tp->timer.expires = RUN_AT(next_tick);
  438. add_timer(&tp->timer);
  439. #ifdef CONFIG_TULIP_NAPI
  440. init_timer(&tp->oom_timer);
  441. tp->oom_timer.data = (unsigned long)dev;
  442. tp->oom_timer.function = oom_timer;
  443. #endif
  444. }
  445. static int
  446. tulip_open(struct net_device *dev)
  447. {
  448. struct tulip_private *tp = netdev_priv(dev);
  449. int retval;
  450. tulip_init_ring (dev);
  451. retval = request_irq(tp->pdev->irq, tulip_interrupt, IRQF_SHARED,
  452. dev->name, dev);
  453. if (retval)
  454. goto free_ring;
  455. tulip_up (dev);
  456. netif_start_queue (dev);
  457. return 0;
  458. free_ring:
  459. tulip_free_ring (dev);
  460. return retval;
  461. }
  462. static void tulip_tx_timeout(struct net_device *dev)
  463. {
  464. struct tulip_private *tp = netdev_priv(dev);
  465. void __iomem *ioaddr = tp->base_addr;
  466. unsigned long flags;
  467. spin_lock_irqsave (&tp->lock, flags);
  468. if (tulip_media_cap[dev->if_port] & MediaIsMII) {
  469. /* Do nothing -- the media monitor should handle this. */
  470. if (tulip_debug > 1)
  471. dev_warn(&dev->dev,
  472. "Transmit timeout using MII device\n");
  473. } else if (tp->chip_id == DC21140 || tp->chip_id == DC21142 ||
  474. tp->chip_id == MX98713 || tp->chip_id == COMPEX9881 ||
  475. tp->chip_id == DM910X) {
  476. dev_warn(&dev->dev,
  477. "21140 transmit timed out, status %08x, SIA %08x %08x %08x %08x, resetting...\n",
  478. ioread32(ioaddr + CSR5), ioread32(ioaddr + CSR12),
  479. ioread32(ioaddr + CSR13), ioread32(ioaddr + CSR14),
  480. ioread32(ioaddr + CSR15));
  481. tp->timeout_recovery = 1;
  482. schedule_work(&tp->media_work);
  483. goto out_unlock;
  484. } else if (tp->chip_id == PNIC2) {
  485. dev_warn(&dev->dev,
  486. "PNIC2 transmit timed out, status %08x, CSR6/7 %08x / %08x CSR12 %08x, resetting...\n",
  487. (int)ioread32(ioaddr + CSR5),
  488. (int)ioread32(ioaddr + CSR6),
  489. (int)ioread32(ioaddr + CSR7),
  490. (int)ioread32(ioaddr + CSR12));
  491. } else {
  492. dev_warn(&dev->dev,
  493. "Transmit timed out, status %08x, CSR12 %08x, resetting...\n",
  494. ioread32(ioaddr + CSR5), ioread32(ioaddr + CSR12));
  495. dev->if_port = 0;
  496. }
  497. #if defined(way_too_many_messages)
  498. if (tulip_debug > 3) {
  499. int i;
  500. for (i = 0; i < RX_RING_SIZE; i++) {
  501. u8 *buf = (u8 *)(tp->rx_ring[i].buffer1);
  502. int j;
  503. printk(KERN_DEBUG
  504. "%2d: %08x %08x %08x %08x %02x %02x %02x\n",
  505. i,
  506. (unsigned int)tp->rx_ring[i].status,
  507. (unsigned int)tp->rx_ring[i].length,
  508. (unsigned int)tp->rx_ring[i].buffer1,
  509. (unsigned int)tp->rx_ring[i].buffer2,
  510. buf[0], buf[1], buf[2]);
  511. for (j = 0; ((j < 1600) && buf[j] != 0xee); j++)
  512. if (j < 100)
  513. pr_cont(" %02x", buf[j]);
  514. pr_cont(" j=%d\n", j);
  515. }
  516. printk(KERN_DEBUG " Rx ring %p: ", tp->rx_ring);
  517. for (i = 0; i < RX_RING_SIZE; i++)
  518. pr_cont(" %08x", (unsigned int)tp->rx_ring[i].status);
  519. printk(KERN_DEBUG " Tx ring %p: ", tp->tx_ring);
  520. for (i = 0; i < TX_RING_SIZE; i++)
  521. pr_cont(" %08x", (unsigned int)tp->tx_ring[i].status);
  522. pr_cont("\n");
  523. }
  524. #endif
  525. tulip_tx_timeout_complete(tp, ioaddr);
  526. out_unlock:
  527. spin_unlock_irqrestore (&tp->lock, flags);
  528. dev->trans_start = jiffies; /* prevent tx timeout */
  529. netif_wake_queue (dev);
  530. }
  531. /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  532. static void tulip_init_ring(struct net_device *dev)
  533. {
  534. struct tulip_private *tp = netdev_priv(dev);
  535. int i;
  536. tp->susp_rx = 0;
  537. tp->ttimer = 0;
  538. tp->nir = 0;
  539. for (i = 0; i < RX_RING_SIZE; i++) {
  540. tp->rx_ring[i].status = 0x00000000;
  541. tp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ);
  542. tp->rx_ring[i].buffer2 = cpu_to_le32(tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * (i + 1));
  543. tp->rx_buffers[i].skb = NULL;
  544. tp->rx_buffers[i].mapping = 0;
  545. }
  546. /* Mark the last entry as wrapping the ring. */
  547. tp->rx_ring[i-1].length = cpu_to_le32(PKT_BUF_SZ | DESC_RING_WRAP);
  548. tp->rx_ring[i-1].buffer2 = cpu_to_le32(tp->rx_ring_dma);
  549. for (i = 0; i < RX_RING_SIZE; i++) {
  550. dma_addr_t mapping;
  551. /* Note the receive buffer must be longword aligned.
  552. netdev_alloc_skb() provides 16 byte alignment. But do *not*
  553. use skb_reserve() to align the IP header! */
  554. struct sk_buff *skb = netdev_alloc_skb(dev, PKT_BUF_SZ);
  555. tp->rx_buffers[i].skb = skb;
  556. if (skb == NULL)
  557. break;
  558. mapping = pci_map_single(tp->pdev, skb->data,
  559. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  560. tp->rx_buffers[i].mapping = mapping;
  561. tp->rx_ring[i].status = cpu_to_le32(DescOwned); /* Owned by Tulip chip */
  562. tp->rx_ring[i].buffer1 = cpu_to_le32(mapping);
  563. }
  564. tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
  565. /* The Tx buffer descriptor is filled in as needed, but we
  566. do need to clear the ownership bit. */
  567. for (i = 0; i < TX_RING_SIZE; i++) {
  568. tp->tx_buffers[i].skb = NULL;
  569. tp->tx_buffers[i].mapping = 0;
  570. tp->tx_ring[i].status = 0x00000000;
  571. tp->tx_ring[i].buffer2 = cpu_to_le32(tp->tx_ring_dma + sizeof(struct tulip_tx_desc) * (i + 1));
  572. }
  573. tp->tx_ring[i-1].buffer2 = cpu_to_le32(tp->tx_ring_dma);
  574. }
  575. static netdev_tx_t
  576. tulip_start_xmit(struct sk_buff *skb, struct net_device *dev)
  577. {
  578. struct tulip_private *tp = netdev_priv(dev);
  579. int entry;
  580. u32 flag;
  581. dma_addr_t mapping;
  582. unsigned long flags;
  583. spin_lock_irqsave(&tp->lock, flags);
  584. /* Calculate the next Tx descriptor entry. */
  585. entry = tp->cur_tx % TX_RING_SIZE;
  586. tp->tx_buffers[entry].skb = skb;
  587. mapping = pci_map_single(tp->pdev, skb->data,
  588. skb->len, PCI_DMA_TODEVICE);
  589. tp->tx_buffers[entry].mapping = mapping;
  590. tp->tx_ring[entry].buffer1 = cpu_to_le32(mapping);
  591. if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */
  592. flag = 0x60000000; /* No interrupt */
  593. } else if (tp->cur_tx - tp->dirty_tx == TX_RING_SIZE/2) {
  594. flag = 0xe0000000; /* Tx-done intr. */
  595. } else if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE - 2) {
  596. flag = 0x60000000; /* No Tx-done intr. */
  597. } else { /* Leave room for set_rx_mode() to fill entries. */
  598. flag = 0xe0000000; /* Tx-done intr. */
  599. netif_stop_queue(dev);
  600. }
  601. if (entry == TX_RING_SIZE-1)
  602. flag = 0xe0000000 | DESC_RING_WRAP;
  603. tp->tx_ring[entry].length = cpu_to_le32(skb->len | flag);
  604. /* if we were using Transmit Automatic Polling, we would need a
  605. * wmb() here. */
  606. tp->tx_ring[entry].status = cpu_to_le32(DescOwned);
  607. wmb();
  608. tp->cur_tx++;
  609. /* Trigger an immediate transmit demand. */
  610. iowrite32(0, tp->base_addr + CSR1);
  611. spin_unlock_irqrestore(&tp->lock, flags);
  612. return NETDEV_TX_OK;
  613. }
  614. static void tulip_clean_tx_ring(struct tulip_private *tp)
  615. {
  616. unsigned int dirty_tx;
  617. for (dirty_tx = tp->dirty_tx ; tp->cur_tx - dirty_tx > 0;
  618. dirty_tx++) {
  619. int entry = dirty_tx % TX_RING_SIZE;
  620. int status = le32_to_cpu(tp->tx_ring[entry].status);
  621. if (status < 0) {
  622. tp->dev->stats.tx_errors++; /* It wasn't Txed */
  623. tp->tx_ring[entry].status = 0;
  624. }
  625. /* Check for Tx filter setup frames. */
  626. if (tp->tx_buffers[entry].skb == NULL) {
  627. /* test because dummy frames not mapped */
  628. if (tp->tx_buffers[entry].mapping)
  629. pci_unmap_single(tp->pdev,
  630. tp->tx_buffers[entry].mapping,
  631. sizeof(tp->setup_frame),
  632. PCI_DMA_TODEVICE);
  633. continue;
  634. }
  635. pci_unmap_single(tp->pdev, tp->tx_buffers[entry].mapping,
  636. tp->tx_buffers[entry].skb->len,
  637. PCI_DMA_TODEVICE);
  638. /* Free the original skb. */
  639. dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
  640. tp->tx_buffers[entry].skb = NULL;
  641. tp->tx_buffers[entry].mapping = 0;
  642. }
  643. }
  644. static void tulip_down (struct net_device *dev)
  645. {
  646. struct tulip_private *tp = netdev_priv(dev);
  647. void __iomem *ioaddr = tp->base_addr;
  648. unsigned long flags;
  649. cancel_work_sync(&tp->media_work);
  650. #ifdef CONFIG_TULIP_NAPI
  651. napi_disable(&tp->napi);
  652. #endif
  653. del_timer_sync (&tp->timer);
  654. #ifdef CONFIG_TULIP_NAPI
  655. del_timer_sync (&tp->oom_timer);
  656. #endif
  657. spin_lock_irqsave (&tp->lock, flags);
  658. /* Disable interrupts by clearing the interrupt mask. */
  659. iowrite32 (0x00000000, ioaddr + CSR7);
  660. /* Stop the Tx and Rx processes. */
  661. tulip_stop_rxtx(tp);
  662. /* prepare receive buffers */
  663. tulip_refill_rx(dev);
  664. /* release any unconsumed transmit buffers */
  665. tulip_clean_tx_ring(tp);
  666. if (ioread32(ioaddr + CSR6) != 0xffffffff)
  667. dev->stats.rx_missed_errors += ioread32(ioaddr + CSR8) & 0xffff;
  668. spin_unlock_irqrestore (&tp->lock, flags);
  669. init_timer(&tp->timer);
  670. tp->timer.data = (unsigned long)dev;
  671. tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
  672. dev->if_port = tp->saved_if_port;
  673. /* Leave the driver in snooze, not sleep, mode. */
  674. tulip_set_power_state (tp, 0, 1);
  675. }
  676. static void tulip_free_ring (struct net_device *dev)
  677. {
  678. struct tulip_private *tp = netdev_priv(dev);
  679. int i;
  680. /* Free all the skbuffs in the Rx queue. */
  681. for (i = 0; i < RX_RING_SIZE; i++) {
  682. struct sk_buff *skb = tp->rx_buffers[i].skb;
  683. dma_addr_t mapping = tp->rx_buffers[i].mapping;
  684. tp->rx_buffers[i].skb = NULL;
  685. tp->rx_buffers[i].mapping = 0;
  686. tp->rx_ring[i].status = 0; /* Not owned by Tulip chip. */
  687. tp->rx_ring[i].length = 0;
  688. /* An invalid address. */
  689. tp->rx_ring[i].buffer1 = cpu_to_le32(0xBADF00D0);
  690. if (skb) {
  691. pci_unmap_single(tp->pdev, mapping, PKT_BUF_SZ,
  692. PCI_DMA_FROMDEVICE);
  693. dev_kfree_skb (skb);
  694. }
  695. }
  696. for (i = 0; i < TX_RING_SIZE; i++) {
  697. struct sk_buff *skb = tp->tx_buffers[i].skb;
  698. if (skb != NULL) {
  699. pci_unmap_single(tp->pdev, tp->tx_buffers[i].mapping,
  700. skb->len, PCI_DMA_TODEVICE);
  701. dev_kfree_skb (skb);
  702. }
  703. tp->tx_buffers[i].skb = NULL;
  704. tp->tx_buffers[i].mapping = 0;
  705. }
  706. }
  707. static int tulip_close (struct net_device *dev)
  708. {
  709. struct tulip_private *tp = netdev_priv(dev);
  710. void __iomem *ioaddr = tp->base_addr;
  711. netif_stop_queue (dev);
  712. tulip_down (dev);
  713. if (tulip_debug > 1)
  714. netdev_dbg(dev, "Shutting down ethercard, status was %02x\n",
  715. ioread32 (ioaddr + CSR5));
  716. free_irq (tp->pdev->irq, dev);
  717. tulip_free_ring (dev);
  718. return 0;
  719. }
  720. static struct net_device_stats *tulip_get_stats(struct net_device *dev)
  721. {
  722. struct tulip_private *tp = netdev_priv(dev);
  723. void __iomem *ioaddr = tp->base_addr;
  724. if (netif_running(dev)) {
  725. unsigned long flags;
  726. spin_lock_irqsave (&tp->lock, flags);
  727. dev->stats.rx_missed_errors += ioread32(ioaddr + CSR8) & 0xffff;
  728. spin_unlock_irqrestore(&tp->lock, flags);
  729. }
  730. return &dev->stats;
  731. }
  732. static void tulip_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  733. {
  734. struct tulip_private *np = netdev_priv(dev);
  735. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  736. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  737. strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
  738. }
  739. static int tulip_ethtool_set_wol(struct net_device *dev,
  740. struct ethtool_wolinfo *wolinfo)
  741. {
  742. struct tulip_private *tp = netdev_priv(dev);
  743. if (wolinfo->wolopts & (~tp->wolinfo.supported))
  744. return -EOPNOTSUPP;
  745. tp->wolinfo.wolopts = wolinfo->wolopts;
  746. device_set_wakeup_enable(&tp->pdev->dev, tp->wolinfo.wolopts);
  747. return 0;
  748. }
  749. static void tulip_ethtool_get_wol(struct net_device *dev,
  750. struct ethtool_wolinfo *wolinfo)
  751. {
  752. struct tulip_private *tp = netdev_priv(dev);
  753. wolinfo->supported = tp->wolinfo.supported;
  754. wolinfo->wolopts = tp->wolinfo.wolopts;
  755. return;
  756. }
  757. static const struct ethtool_ops ops = {
  758. .get_drvinfo = tulip_get_drvinfo,
  759. .set_wol = tulip_ethtool_set_wol,
  760. .get_wol = tulip_ethtool_get_wol,
  761. };
  762. /* Provide ioctl() calls to examine the MII xcvr state. */
  763. static int private_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
  764. {
  765. struct tulip_private *tp = netdev_priv(dev);
  766. void __iomem *ioaddr = tp->base_addr;
  767. struct mii_ioctl_data *data = if_mii(rq);
  768. const unsigned int phy_idx = 0;
  769. int phy = tp->phys[phy_idx] & 0x1f;
  770. unsigned int regnum = data->reg_num;
  771. switch (cmd) {
  772. case SIOCGMIIPHY: /* Get address of MII PHY in use. */
  773. if (tp->mii_cnt)
  774. data->phy_id = phy;
  775. else if (tp->flags & HAS_NWAY)
  776. data->phy_id = 32;
  777. else if (tp->chip_id == COMET)
  778. data->phy_id = 1;
  779. else
  780. return -ENODEV;
  781. case SIOCGMIIREG: /* Read MII PHY register. */
  782. if (data->phy_id == 32 && (tp->flags & HAS_NWAY)) {
  783. int csr12 = ioread32 (ioaddr + CSR12);
  784. int csr14 = ioread32 (ioaddr + CSR14);
  785. switch (regnum) {
  786. case 0:
  787. if (((csr14<<5) & 0x1000) ||
  788. (dev->if_port == 5 && tp->nwayset))
  789. data->val_out = 0x1000;
  790. else
  791. data->val_out = (tulip_media_cap[dev->if_port]&MediaIs100 ? 0x2000 : 0)
  792. | (tulip_media_cap[dev->if_port]&MediaIsFD ? 0x0100 : 0);
  793. break;
  794. case 1:
  795. data->val_out =
  796. 0x1848 +
  797. ((csr12&0x7000) == 0x5000 ? 0x20 : 0) +
  798. ((csr12&0x06) == 6 ? 0 : 4);
  799. data->val_out |= 0x6048;
  800. break;
  801. case 4:
  802. /* Advertised value, bogus 10baseTx-FD value from CSR6. */
  803. data->val_out =
  804. ((ioread32(ioaddr + CSR6) >> 3) & 0x0040) +
  805. ((csr14 >> 1) & 0x20) + 1;
  806. data->val_out |= ((csr14 >> 9) & 0x03C0);
  807. break;
  808. case 5: data->val_out = tp->lpar; break;
  809. default: data->val_out = 0; break;
  810. }
  811. } else {
  812. data->val_out = tulip_mdio_read (dev, data->phy_id & 0x1f, regnum);
  813. }
  814. return 0;
  815. case SIOCSMIIREG: /* Write MII PHY register. */
  816. if (regnum & ~0x1f)
  817. return -EINVAL;
  818. if (data->phy_id == phy) {
  819. u16 value = data->val_in;
  820. switch (regnum) {
  821. case 0: /* Check for autonegotiation on or reset. */
  822. tp->full_duplex_lock = (value & 0x9000) ? 0 : 1;
  823. if (tp->full_duplex_lock)
  824. tp->full_duplex = (value & 0x0100) ? 1 : 0;
  825. break;
  826. case 4:
  827. tp->advertising[phy_idx] =
  828. tp->mii_advertise = data->val_in;
  829. break;
  830. }
  831. }
  832. if (data->phy_id == 32 && (tp->flags & HAS_NWAY)) {
  833. u16 value = data->val_in;
  834. if (regnum == 0) {
  835. if ((value & 0x1200) == 0x1200) {
  836. if (tp->chip_id == PNIC2) {
  837. pnic2_start_nway (dev);
  838. } else {
  839. t21142_start_nway (dev);
  840. }
  841. }
  842. } else if (regnum == 4)
  843. tp->sym_advertise = value;
  844. } else {
  845. tulip_mdio_write (dev, data->phy_id & 0x1f, regnum, data->val_in);
  846. }
  847. return 0;
  848. default:
  849. return -EOPNOTSUPP;
  850. }
  851. return -EOPNOTSUPP;
  852. }
  853. /* Set or clear the multicast filter for this adaptor.
  854. Note that we only use exclusion around actually queueing the
  855. new frame, not around filling tp->setup_frame. This is non-deterministic
  856. when re-entered but still correct. */
  857. static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)
  858. {
  859. struct tulip_private *tp = netdev_priv(dev);
  860. u16 hash_table[32];
  861. struct netdev_hw_addr *ha;
  862. int i;
  863. u16 *eaddrs;
  864. memset(hash_table, 0, sizeof(hash_table));
  865. __set_bit_le(255, hash_table); /* Broadcast entry */
  866. /* This should work on big-endian machines as well. */
  867. netdev_for_each_mc_addr(ha, dev) {
  868. int index = ether_crc_le(ETH_ALEN, ha->addr) & 0x1ff;
  869. __set_bit_le(index, hash_table);
  870. }
  871. for (i = 0; i < 32; i++) {
  872. *setup_frm++ = hash_table[i];
  873. *setup_frm++ = hash_table[i];
  874. }
  875. setup_frm = &tp->setup_frame[13*6];
  876. /* Fill the final entry with our physical address. */
  877. eaddrs = (u16 *)dev->dev_addr;
  878. *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
  879. *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
  880. *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
  881. }
  882. static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev)
  883. {
  884. struct tulip_private *tp = netdev_priv(dev);
  885. struct netdev_hw_addr *ha;
  886. u16 *eaddrs;
  887. /* We have <= 14 addresses so we can use the wonderful
  888. 16 address perfect filtering of the Tulip. */
  889. netdev_for_each_mc_addr(ha, dev) {
  890. eaddrs = (u16 *) ha->addr;
  891. *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
  892. *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
  893. *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
  894. }
  895. /* Fill the unused entries with the broadcast address. */
  896. memset(setup_frm, 0xff, (15 - netdev_mc_count(dev)) * 12);
  897. setup_frm = &tp->setup_frame[15*6];
  898. /* Fill the final entry with our physical address. */
  899. eaddrs = (u16 *)dev->dev_addr;
  900. *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
  901. *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
  902. *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
  903. }
  904. static void set_rx_mode(struct net_device *dev)
  905. {
  906. struct tulip_private *tp = netdev_priv(dev);
  907. void __iomem *ioaddr = tp->base_addr;
  908. int csr6;
  909. csr6 = ioread32(ioaddr + CSR6) & ~0x00D5;
  910. tp->csr6 &= ~0x00D5;
  911. if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
  912. tp->csr6 |= AcceptAllMulticast | AcceptAllPhys;
  913. csr6 |= AcceptAllMulticast | AcceptAllPhys;
  914. } else if ((netdev_mc_count(dev) > 1000) ||
  915. (dev->flags & IFF_ALLMULTI)) {
  916. /* Too many to filter well -- accept all multicasts. */
  917. tp->csr6 |= AcceptAllMulticast;
  918. csr6 |= AcceptAllMulticast;
  919. } else if (tp->flags & MC_HASH_ONLY) {
  920. /* Some work-alikes have only a 64-entry hash filter table. */
  921. /* Should verify correctness on big-endian/__powerpc__ */
  922. struct netdev_hw_addr *ha;
  923. if (netdev_mc_count(dev) > 64) {
  924. /* Arbitrary non-effective limit. */
  925. tp->csr6 |= AcceptAllMulticast;
  926. csr6 |= AcceptAllMulticast;
  927. } else {
  928. u32 mc_filter[2] = {0, 0}; /* Multicast hash filter */
  929. int filterbit;
  930. netdev_for_each_mc_addr(ha, dev) {
  931. if (tp->flags & COMET_MAC_ADDR)
  932. filterbit = ether_crc_le(ETH_ALEN,
  933. ha->addr);
  934. else
  935. filterbit = ether_crc(ETH_ALEN,
  936. ha->addr) >> 26;
  937. filterbit &= 0x3f;
  938. mc_filter[filterbit >> 5] |= 1 << (filterbit & 31);
  939. if (tulip_debug > 2)
  940. dev_info(&dev->dev,
  941. "Added filter for %pM %08x bit %d\n",
  942. ha->addr,
  943. ether_crc(ETH_ALEN, ha->addr),
  944. filterbit);
  945. }
  946. if (mc_filter[0] == tp->mc_filter[0] &&
  947. mc_filter[1] == tp->mc_filter[1])
  948. ; /* No change. */
  949. else if (tp->flags & IS_ASIX) {
  950. iowrite32(2, ioaddr + CSR13);
  951. iowrite32(mc_filter[0], ioaddr + CSR14);
  952. iowrite32(3, ioaddr + CSR13);
  953. iowrite32(mc_filter[1], ioaddr + CSR14);
  954. } else if (tp->flags & COMET_MAC_ADDR) {
  955. iowrite32(mc_filter[0], ioaddr + CSR27);
  956. iowrite32(mc_filter[1], ioaddr + CSR28);
  957. }
  958. tp->mc_filter[0] = mc_filter[0];
  959. tp->mc_filter[1] = mc_filter[1];
  960. }
  961. } else {
  962. unsigned long flags;
  963. u32 tx_flags = 0x08000000 | 192;
  964. /* Note that only the low-address shortword of setup_frame is valid!
  965. The values are doubled for big-endian architectures. */
  966. if (netdev_mc_count(dev) > 14) {
  967. /* Must use a multicast hash table. */
  968. build_setup_frame_hash(tp->setup_frame, dev);
  969. tx_flags = 0x08400000 | 192;
  970. } else {
  971. build_setup_frame_perfect(tp->setup_frame, dev);
  972. }
  973. spin_lock_irqsave(&tp->lock, flags);
  974. if (tp->cur_tx - tp->dirty_tx > TX_RING_SIZE - 2) {
  975. /* Same setup recently queued, we need not add it. */
  976. } else {
  977. unsigned int entry;
  978. int dummy = -1;
  979. /* Now add this frame to the Tx list. */
  980. entry = tp->cur_tx++ % TX_RING_SIZE;
  981. if (entry != 0) {
  982. /* Avoid a chip errata by prefixing a dummy entry. */
  983. tp->tx_buffers[entry].skb = NULL;
  984. tp->tx_buffers[entry].mapping = 0;
  985. tp->tx_ring[entry].length =
  986. (entry == TX_RING_SIZE-1) ? cpu_to_le32(DESC_RING_WRAP) : 0;
  987. tp->tx_ring[entry].buffer1 = 0;
  988. /* Must set DescOwned later to avoid race with chip */
  989. dummy = entry;
  990. entry = tp->cur_tx++ % TX_RING_SIZE;
  991. }
  992. tp->tx_buffers[entry].skb = NULL;
  993. tp->tx_buffers[entry].mapping =
  994. pci_map_single(tp->pdev, tp->setup_frame,
  995. sizeof(tp->setup_frame),
  996. PCI_DMA_TODEVICE);
  997. /* Put the setup frame on the Tx list. */
  998. if (entry == TX_RING_SIZE-1)
  999. tx_flags |= DESC_RING_WRAP; /* Wrap ring. */
  1000. tp->tx_ring[entry].length = cpu_to_le32(tx_flags);
  1001. tp->tx_ring[entry].buffer1 =
  1002. cpu_to_le32(tp->tx_buffers[entry].mapping);
  1003. tp->tx_ring[entry].status = cpu_to_le32(DescOwned);
  1004. if (dummy >= 0)
  1005. tp->tx_ring[dummy].status = cpu_to_le32(DescOwned);
  1006. if (tp->cur_tx - tp->dirty_tx >= TX_RING_SIZE - 2)
  1007. netif_stop_queue(dev);
  1008. /* Trigger an immediate transmit demand. */
  1009. iowrite32(0, ioaddr + CSR1);
  1010. }
  1011. spin_unlock_irqrestore(&tp->lock, flags);
  1012. }
  1013. iowrite32(csr6, ioaddr + CSR6);
  1014. }
  1015. #ifdef CONFIG_TULIP_MWI
  1016. static void tulip_mwi_config(struct pci_dev *pdev, struct net_device *dev)
  1017. {
  1018. struct tulip_private *tp = netdev_priv(dev);
  1019. u8 cache;
  1020. u16 pci_command;
  1021. u32 csr0;
  1022. if (tulip_debug > 3)
  1023. netdev_dbg(dev, "tulip_mwi_config()\n");
  1024. tp->csr0 = csr0 = 0;
  1025. /* if we have any cache line size at all, we can do MRM and MWI */
  1026. csr0 |= MRM | MWI;
  1027. /* Enable MWI in the standard PCI command bit.
  1028. * Check for the case where MWI is desired but not available
  1029. */
  1030. pci_try_set_mwi(pdev);
  1031. /* read result from hardware (in case bit refused to enable) */
  1032. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  1033. if ((csr0 & MWI) && (!(pci_command & PCI_COMMAND_INVALIDATE)))
  1034. csr0 &= ~MWI;
  1035. /* if cache line size hardwired to zero, no MWI */
  1036. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache);
  1037. if ((csr0 & MWI) && (cache == 0)) {
  1038. csr0 &= ~MWI;
  1039. pci_clear_mwi(pdev);
  1040. }
  1041. /* assign per-cacheline-size cache alignment and
  1042. * burst length values
  1043. */
  1044. switch (cache) {
  1045. case 8:
  1046. csr0 |= MRL | (1 << CALShift) | (16 << BurstLenShift);
  1047. break;
  1048. case 16:
  1049. csr0 |= MRL | (2 << CALShift) | (16 << BurstLenShift);
  1050. break;
  1051. case 32:
  1052. csr0 |= MRL | (3 << CALShift) | (32 << BurstLenShift);
  1053. break;
  1054. default:
  1055. cache = 0;
  1056. break;
  1057. }
  1058. /* if we have a good cache line size, we by now have a good
  1059. * csr0, so save it and exit
  1060. */
  1061. if (cache)
  1062. goto out;
  1063. /* we don't have a good csr0 or cache line size, disable MWI */
  1064. if (csr0 & MWI) {
  1065. pci_clear_mwi(pdev);
  1066. csr0 &= ~MWI;
  1067. }
  1068. /* sane defaults for burst length and cache alignment
  1069. * originally from de4x5 driver
  1070. */
  1071. csr0 |= (8 << BurstLenShift) | (1 << CALShift);
  1072. out:
  1073. tp->csr0 = csr0;
  1074. if (tulip_debug > 2)
  1075. netdev_dbg(dev, "MWI config cacheline=%d, csr0=%08x\n",
  1076. cache, csr0);
  1077. }
  1078. #endif
  1079. /*
  1080. * Chips that have the MRM/reserved bit quirk and the burst quirk. That
  1081. * is the DM910X and the on chip ULi devices
  1082. */
  1083. static int tulip_uli_dm_quirk(struct pci_dev *pdev)
  1084. {
  1085. if (pdev->vendor == 0x1282 && pdev->device == 0x9102)
  1086. return 1;
  1087. return 0;
  1088. }
  1089. static const struct net_device_ops tulip_netdev_ops = {
  1090. .ndo_open = tulip_open,
  1091. .ndo_start_xmit = tulip_start_xmit,
  1092. .ndo_tx_timeout = tulip_tx_timeout,
  1093. .ndo_stop = tulip_close,
  1094. .ndo_get_stats = tulip_get_stats,
  1095. .ndo_do_ioctl = private_ioctl,
  1096. .ndo_set_rx_mode = set_rx_mode,
  1097. .ndo_change_mtu = eth_change_mtu,
  1098. .ndo_set_mac_address = eth_mac_addr,
  1099. .ndo_validate_addr = eth_validate_addr,
  1100. #ifdef CONFIG_NET_POLL_CONTROLLER
  1101. .ndo_poll_controller = poll_tulip,
  1102. #endif
  1103. };
  1104. const struct pci_device_id early_486_chipsets[] = {
  1105. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82424) },
  1106. { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496) },
  1107. { },
  1108. };
  1109. static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  1110. {
  1111. struct tulip_private *tp;
  1112. /* See note below on the multiport cards. */
  1113. static unsigned char last_phys_addr[ETH_ALEN] = {
  1114. 0x00, 'L', 'i', 'n', 'u', 'x'
  1115. };
  1116. static int last_irq;
  1117. static int multiport_cnt; /* For four-port boards w/one EEPROM */
  1118. int i, irq;
  1119. unsigned short sum;
  1120. unsigned char *ee_data;
  1121. struct net_device *dev;
  1122. void __iomem *ioaddr;
  1123. static int board_idx = -1;
  1124. int chip_idx = ent->driver_data;
  1125. const char *chip_name = tulip_tbl[chip_idx].chip_name;
  1126. unsigned int eeprom_missing = 0;
  1127. unsigned int force_csr0 = 0;
  1128. #ifndef MODULE
  1129. if (tulip_debug > 0)
  1130. printk_once(KERN_INFO "%s", version);
  1131. #endif
  1132. board_idx++;
  1133. /*
  1134. * Lan media wire a tulip chip to a wan interface. Needs a very
  1135. * different driver (lmc driver)
  1136. */
  1137. if (pdev->subsystem_vendor == PCI_VENDOR_ID_LMC) {
  1138. pr_err("skipping LMC card\n");
  1139. return -ENODEV;
  1140. } else if (pdev->subsystem_vendor == PCI_VENDOR_ID_SBE &&
  1141. (pdev->subsystem_device == PCI_SUBDEVICE_ID_SBE_T3E3 ||
  1142. pdev->subsystem_device == PCI_SUBDEVICE_ID_SBE_2T3E3_P0 ||
  1143. pdev->subsystem_device == PCI_SUBDEVICE_ID_SBE_2T3E3_P1)) {
  1144. pr_err("skipping SBE T3E3 port\n");
  1145. return -ENODEV;
  1146. }
  1147. /*
  1148. * DM910x chips should be handled by the dmfe driver, except
  1149. * on-board chips on SPARC systems. Also, early DM9100s need
  1150. * software CRC which only the dmfe driver supports.
  1151. */
  1152. #ifdef CONFIG_TULIP_DM910X
  1153. if (chip_idx == DM910X) {
  1154. struct device_node *dp;
  1155. if (pdev->vendor == 0x1282 && pdev->device == 0x9100 &&
  1156. pdev->revision < 0x30) {
  1157. pr_info("skipping early DM9100 with Crc bug (use dmfe)\n");
  1158. return -ENODEV;
  1159. }
  1160. dp = pci_device_to_OF_node(pdev);
  1161. if (!(dp && of_get_property(dp, "local-mac-address", NULL))) {
  1162. pr_info("skipping DM910x expansion card (use dmfe)\n");
  1163. return -ENODEV;
  1164. }
  1165. }
  1166. #endif
  1167. /*
  1168. * Looks for early PCI chipsets where people report hangs
  1169. * without the workarounds being on.
  1170. */
  1171. /* 1. Intel Saturn. Switch to 8 long words burst, 8 long word cache
  1172. aligned. Aries might need this too. The Saturn errata are not
  1173. pretty reading but thankfully it's an old 486 chipset.
  1174. 2. The dreaded SiS496 486 chipset. Same workaround as Intel
  1175. Saturn.
  1176. */
  1177. if (pci_dev_present(early_486_chipsets)) {
  1178. csr0 = MRL | MRM | (8 << BurstLenShift) | (1 << CALShift);
  1179. force_csr0 = 1;
  1180. }
  1181. /* bugfix: the ASIX must have a burst limit or horrible things happen. */
  1182. if (chip_idx == AX88140) {
  1183. if ((csr0 & 0x3f00) == 0)
  1184. csr0 |= 0x2000;
  1185. }
  1186. /* PNIC doesn't have MWI/MRL/MRM... */
  1187. if (chip_idx == LC82C168)
  1188. csr0 &= ~0xfff10000; /* zero reserved bits 31:20, 16 */
  1189. /* DM9102A has troubles with MRM & clear reserved bits 24:22, 20, 16, 7:1 */
  1190. if (tulip_uli_dm_quirk(pdev)) {
  1191. csr0 &= ~0x01f100ff;
  1192. #if defined(CONFIG_SPARC)
  1193. csr0 = (csr0 & ~0xff00) | 0xe000;
  1194. #endif
  1195. }
  1196. /*
  1197. * And back to business
  1198. */
  1199. i = pci_enable_device(pdev);
  1200. if (i) {
  1201. pr_err("Cannot enable tulip board #%d, aborting\n", board_idx);
  1202. return i;
  1203. }
  1204. irq = pdev->irq;
  1205. /* alloc_etherdev ensures aligned and zeroed private structures */
  1206. dev = alloc_etherdev (sizeof (*tp));
  1207. if (!dev)
  1208. return -ENOMEM;
  1209. SET_NETDEV_DEV(dev, &pdev->dev);
  1210. if (pci_resource_len (pdev, 0) < tulip_tbl[chip_idx].io_size) {
  1211. pr_err("%s: I/O region (0x%llx@0x%llx) too small, aborting\n",
  1212. pci_name(pdev),
  1213. (unsigned long long)pci_resource_len (pdev, 0),
  1214. (unsigned long long)pci_resource_start (pdev, 0));
  1215. goto err_out_free_netdev;
  1216. }
  1217. /* grab all resources from both PIO and MMIO regions, as we
  1218. * don't want anyone else messing around with our hardware */
  1219. if (pci_request_regions (pdev, DRV_NAME))
  1220. goto err_out_free_netdev;
  1221. ioaddr = pci_iomap(pdev, TULIP_BAR, tulip_tbl[chip_idx].io_size);
  1222. if (!ioaddr)
  1223. goto err_out_free_res;
  1224. /*
  1225. * initialize private data structure 'tp'
  1226. * it is zeroed and aligned in alloc_etherdev
  1227. */
  1228. tp = netdev_priv(dev);
  1229. tp->dev = dev;
  1230. tp->rx_ring = pci_alloc_consistent(pdev,
  1231. sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
  1232. sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
  1233. &tp->rx_ring_dma);
  1234. if (!tp->rx_ring)
  1235. goto err_out_mtable;
  1236. tp->tx_ring = (struct tulip_tx_desc *)(tp->rx_ring + RX_RING_SIZE);
  1237. tp->tx_ring_dma = tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * RX_RING_SIZE;
  1238. tp->chip_id = chip_idx;
  1239. tp->flags = tulip_tbl[chip_idx].flags;
  1240. tp->wolinfo.supported = 0;
  1241. tp->wolinfo.wolopts = 0;
  1242. /* COMET: Enable power management only for AN983B */
  1243. if (chip_idx == COMET ) {
  1244. u32 sig;
  1245. pci_read_config_dword (pdev, 0x80, &sig);
  1246. if (sig == 0x09811317) {
  1247. tp->flags |= COMET_PM;
  1248. tp->wolinfo.supported = WAKE_PHY | WAKE_MAGIC;
  1249. pr_info("%s: Enabled WOL support for AN983B\n",
  1250. __func__);
  1251. }
  1252. }
  1253. tp->pdev = pdev;
  1254. tp->base_addr = ioaddr;
  1255. tp->revision = pdev->revision;
  1256. tp->csr0 = csr0;
  1257. spin_lock_init(&tp->lock);
  1258. spin_lock_init(&tp->mii_lock);
  1259. init_timer(&tp->timer);
  1260. tp->timer.data = (unsigned long)dev;
  1261. tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
  1262. INIT_WORK(&tp->media_work, tulip_tbl[tp->chip_id].media_task);
  1263. #ifdef CONFIG_TULIP_MWI
  1264. if (!force_csr0 && (tp->flags & HAS_PCI_MWI))
  1265. tulip_mwi_config (pdev, dev);
  1266. #endif
  1267. /* Stop the chip's Tx and Rx processes. */
  1268. tulip_stop_rxtx(tp);
  1269. pci_set_master(pdev);
  1270. #ifdef CONFIG_GSC
  1271. if (pdev->subsystem_vendor == PCI_VENDOR_ID_HP) {
  1272. switch (pdev->subsystem_device) {
  1273. default:
  1274. break;
  1275. case 0x1061:
  1276. case 0x1062:
  1277. case 0x1063:
  1278. case 0x1098:
  1279. case 0x1099:
  1280. case 0x10EE:
  1281. tp->flags |= HAS_SWAPPED_SEEPROM | NEEDS_FAKE_MEDIA_TABLE;
  1282. chip_name = "GSC DS21140 Tulip";
  1283. }
  1284. }
  1285. #endif
  1286. /* Clear the missed-packet counter. */
  1287. ioread32(ioaddr + CSR8);
  1288. /* The station address ROM is read byte serially. The register must
  1289. be polled, waiting for the value to be read bit serially from the
  1290. EEPROM.
  1291. */
  1292. ee_data = tp->eeprom;
  1293. memset(ee_data, 0, sizeof(tp->eeprom));
  1294. sum = 0;
  1295. if (chip_idx == LC82C168) {
  1296. for (i = 0; i < 3; i++) {
  1297. int value, boguscnt = 100000;
  1298. iowrite32(0x600 | i, ioaddr + 0x98);
  1299. do {
  1300. value = ioread32(ioaddr + CSR9);
  1301. } while (value < 0 && --boguscnt > 0);
  1302. put_unaligned_le16(value, ((__le16 *)dev->dev_addr) + i);
  1303. sum += value & 0xffff;
  1304. }
  1305. } else if (chip_idx == COMET) {
  1306. /* No need to read the EEPROM. */
  1307. put_unaligned_le32(ioread32(ioaddr + 0xA4), dev->dev_addr);
  1308. put_unaligned_le16(ioread32(ioaddr + 0xA8), dev->dev_addr + 4);
  1309. for (i = 0; i < 6; i ++)
  1310. sum += dev->dev_addr[i];
  1311. } else {
  1312. /* A serial EEPROM interface, we read now and sort it out later. */
  1313. int sa_offset = 0;
  1314. int ee_addr_size = tulip_read_eeprom(dev, 0xff, 8) & 0x40000 ? 8 : 6;
  1315. int ee_max_addr = ((1 << ee_addr_size) - 1) * sizeof(u16);
  1316. if (ee_max_addr > sizeof(tp->eeprom))
  1317. ee_max_addr = sizeof(tp->eeprom);
  1318. for (i = 0; i < ee_max_addr ; i += sizeof(u16)) {
  1319. u16 data = tulip_read_eeprom(dev, i/2, ee_addr_size);
  1320. ee_data[i] = data & 0xff;
  1321. ee_data[i + 1] = data >> 8;
  1322. }
  1323. /* DEC now has a specification (see Notes) but early board makers
  1324. just put the address in the first EEPROM locations. */
  1325. /* This does memcmp(ee_data, ee_data+16, 8) */
  1326. for (i = 0; i < 8; i ++)
  1327. if (ee_data[i] != ee_data[16+i])
  1328. sa_offset = 20;
  1329. if (chip_idx == CONEXANT) {
  1330. /* Check that the tuple type and length is correct. */
  1331. if (ee_data[0x198] == 0x04 && ee_data[0x199] == 6)
  1332. sa_offset = 0x19A;
  1333. } else if (ee_data[0] == 0xff && ee_data[1] == 0xff &&
  1334. ee_data[2] == 0) {
  1335. sa_offset = 2; /* Grrr, damn Matrox boards. */
  1336. multiport_cnt = 4;
  1337. }
  1338. #ifdef CONFIG_MIPS_COBALT
  1339. if ((pdev->bus->number == 0) &&
  1340. ((PCI_SLOT(pdev->devfn) == 7) ||
  1341. (PCI_SLOT(pdev->devfn) == 12))) {
  1342. /* Cobalt MAC address in first EEPROM locations. */
  1343. sa_offset = 0;
  1344. /* Ensure our media table fixup get's applied */
  1345. memcpy(ee_data + 16, ee_data, 8);
  1346. }
  1347. #endif
  1348. #ifdef CONFIG_GSC
  1349. /* Check to see if we have a broken srom */
  1350. if (ee_data[0] == 0x61 && ee_data[1] == 0x10) {
  1351. /* pci_vendor_id and subsystem_id are swapped */
  1352. ee_data[0] = ee_data[2];
  1353. ee_data[1] = ee_data[3];
  1354. ee_data[2] = 0x61;
  1355. ee_data[3] = 0x10;
  1356. /* HSC-PCI boards need to be byte-swaped and shifted
  1357. * up 1 word. This shift needs to happen at the end
  1358. * of the MAC first because of the 2 byte overlap.
  1359. */
  1360. for (i = 4; i >= 0; i -= 2) {
  1361. ee_data[17 + i + 3] = ee_data[17 + i];
  1362. ee_data[16 + i + 5] = ee_data[16 + i];
  1363. }
  1364. }
  1365. #endif
  1366. for (i = 0; i < 6; i ++) {
  1367. dev->dev_addr[i] = ee_data[i + sa_offset];
  1368. sum += ee_data[i + sa_offset];
  1369. }
  1370. }
  1371. /* Lite-On boards have the address byte-swapped. */
  1372. if ((dev->dev_addr[0] == 0xA0 ||
  1373. dev->dev_addr[0] == 0xC0 ||
  1374. dev->dev_addr[0] == 0x02) &&
  1375. dev->dev_addr[1] == 0x00)
  1376. for (i = 0; i < 6; i+=2) {
  1377. char tmp = dev->dev_addr[i];
  1378. dev->dev_addr[i] = dev->dev_addr[i+1];
  1379. dev->dev_addr[i+1] = tmp;
  1380. }
  1381. /* On the Zynx 315 Etherarray and other multiport boards only the
  1382. first Tulip has an EEPROM.
  1383. On Sparc systems the mac address is held in the OBP property
  1384. "local-mac-address".
  1385. The addresses of the subsequent ports are derived from the first.
  1386. Many PCI BIOSes also incorrectly report the IRQ line, so we correct
  1387. that here as well. */
  1388. if (sum == 0 || sum == 6*0xff) {
  1389. #if defined(CONFIG_SPARC)
  1390. struct device_node *dp = pci_device_to_OF_node(pdev);
  1391. const unsigned char *addr;
  1392. int len;
  1393. #endif
  1394. eeprom_missing = 1;
  1395. for (i = 0; i < 5; i++)
  1396. dev->dev_addr[i] = last_phys_addr[i];
  1397. dev->dev_addr[i] = last_phys_addr[i] + 1;
  1398. #if defined(CONFIG_SPARC)
  1399. addr = of_get_property(dp, "local-mac-address", &len);
  1400. if (addr && len == ETH_ALEN)
  1401. memcpy(dev->dev_addr, addr, ETH_ALEN);
  1402. #endif
  1403. #if defined(__i386__) || defined(__x86_64__) /* Patch up x86 BIOS bug. */
  1404. if (last_irq)
  1405. irq = last_irq;
  1406. #endif
  1407. }
  1408. for (i = 0; i < 6; i++)
  1409. last_phys_addr[i] = dev->dev_addr[i];
  1410. last_irq = irq;
  1411. /* The lower four bits are the media type. */
  1412. if (board_idx >= 0 && board_idx < MAX_UNITS) {
  1413. if (options[board_idx] & MEDIA_MASK)
  1414. tp->default_port = options[board_idx] & MEDIA_MASK;
  1415. if ((options[board_idx] & FullDuplex) || full_duplex[board_idx] > 0)
  1416. tp->full_duplex = 1;
  1417. if (mtu[board_idx] > 0)
  1418. dev->mtu = mtu[board_idx];
  1419. }
  1420. if (dev->mem_start & MEDIA_MASK)
  1421. tp->default_port = dev->mem_start & MEDIA_MASK;
  1422. if (tp->default_port) {
  1423. pr_info(DRV_NAME "%d: Transceiver selection forced to %s\n",
  1424. board_idx, medianame[tp->default_port & MEDIA_MASK]);
  1425. tp->medialock = 1;
  1426. if (tulip_media_cap[tp->default_port] & MediaAlwaysFD)
  1427. tp->full_duplex = 1;
  1428. }
  1429. if (tp->full_duplex)
  1430. tp->full_duplex_lock = 1;
  1431. if (tulip_media_cap[tp->default_port] & MediaIsMII) {
  1432. static const u16 media2advert[] = {
  1433. 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200
  1434. };
  1435. tp->mii_advertise = media2advert[tp->default_port - 9];
  1436. tp->mii_advertise |= (tp->flags & HAS_8023X); /* Matching bits! */
  1437. }
  1438. if (tp->flags & HAS_MEDIA_TABLE) {
  1439. sprintf(dev->name, DRV_NAME "%d", board_idx); /* hack */
  1440. tulip_parse_eeprom(dev);
  1441. strcpy(dev->name, "eth%d"); /* un-hack */
  1442. }
  1443. if ((tp->flags & ALWAYS_CHECK_MII) ||
  1444. (tp->mtable && tp->mtable->has_mii) ||
  1445. ( ! tp->mtable && (tp->flags & HAS_MII))) {
  1446. if (tp->mtable && tp->mtable->has_mii) {
  1447. for (i = 0; i < tp->mtable->leafcount; i++)
  1448. if (tp->mtable->mleaf[i].media == 11) {
  1449. tp->cur_index = i;
  1450. tp->saved_if_port = dev->if_port;
  1451. tulip_select_media(dev, 2);
  1452. dev->if_port = tp->saved_if_port;
  1453. break;
  1454. }
  1455. }
  1456. /* Find the connected MII xcvrs.
  1457. Doing this in open() would allow detecting external xcvrs
  1458. later, but takes much time. */
  1459. tulip_find_mii (dev, board_idx);
  1460. }
  1461. /* The Tulip-specific entries in the device structure. */
  1462. dev->netdev_ops = &tulip_netdev_ops;
  1463. dev->watchdog_timeo = TX_TIMEOUT;
  1464. #ifdef CONFIG_TULIP_NAPI
  1465. netif_napi_add(dev, &tp->napi, tulip_poll, 16);
  1466. #endif
  1467. dev->ethtool_ops = &ops;
  1468. if (register_netdev(dev))
  1469. goto err_out_free_ring;
  1470. pci_set_drvdata(pdev, dev);
  1471. dev_info(&dev->dev,
  1472. #ifdef CONFIG_TULIP_MMIO
  1473. "%s rev %d at MMIO %#llx,%s %pM, IRQ %d\n",
  1474. #else
  1475. "%s rev %d at Port %#llx,%s %pM, IRQ %d\n",
  1476. #endif
  1477. chip_name, pdev->revision,
  1478. (unsigned long long)pci_resource_start(pdev, TULIP_BAR),
  1479. eeprom_missing ? " EEPROM not present," : "",
  1480. dev->dev_addr, irq);
  1481. if (tp->chip_id == PNIC2)
  1482. tp->link_change = pnic2_lnk_change;
  1483. else if (tp->flags & HAS_NWAY)
  1484. tp->link_change = t21142_lnk_change;
  1485. else if (tp->flags & HAS_PNICNWAY)
  1486. tp->link_change = pnic_lnk_change;
  1487. /* Reset the xcvr interface and turn on heartbeat. */
  1488. switch (chip_idx) {
  1489. case DC21140:
  1490. case DM910X:
  1491. default:
  1492. if (tp->mtable)
  1493. iowrite32(tp->mtable->csr12dir | 0x100, ioaddr + CSR12);
  1494. break;
  1495. case DC21142:
  1496. if (tp->mii_cnt || tulip_media_cap[dev->if_port] & MediaIsMII) {
  1497. iowrite32(csr6_mask_defstate, ioaddr + CSR6);
  1498. iowrite32(0x0000, ioaddr + CSR13);
  1499. iowrite32(0x0000, ioaddr + CSR14);
  1500. iowrite32(csr6_mask_hdcap, ioaddr + CSR6);
  1501. } else
  1502. t21142_start_nway(dev);
  1503. break;
  1504. case PNIC2:
  1505. /* just do a reset for sanity sake */
  1506. iowrite32(0x0000, ioaddr + CSR13);
  1507. iowrite32(0x0000, ioaddr + CSR14);
  1508. break;
  1509. case LC82C168:
  1510. if ( ! tp->mii_cnt) {
  1511. tp->nway = 1;
  1512. tp->nwayset = 0;
  1513. iowrite32(csr6_ttm | csr6_ca, ioaddr + CSR6);
  1514. iowrite32(0x30, ioaddr + CSR12);
  1515. iowrite32(0x0001F078, ioaddr + CSR6);
  1516. iowrite32(0x0201F078, ioaddr + CSR6); /* Turn on autonegotiation. */
  1517. }
  1518. break;
  1519. case MX98713:
  1520. case COMPEX9881:
  1521. iowrite32(0x00000000, ioaddr + CSR6);
  1522. iowrite32(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */
  1523. iowrite32(0x00000001, ioaddr + CSR13);
  1524. break;
  1525. case MX98715:
  1526. case MX98725:
  1527. iowrite32(0x01a80000, ioaddr + CSR6);
  1528. iowrite32(0xFFFFFFFF, ioaddr + CSR14);
  1529. iowrite32(0x00001000, ioaddr + CSR12);
  1530. break;
  1531. case COMET:
  1532. /* No initialization necessary. */
  1533. break;
  1534. }
  1535. /* put the chip in snooze mode until opened */
  1536. tulip_set_power_state (tp, 0, 1);
  1537. return 0;
  1538. err_out_free_ring:
  1539. pci_free_consistent (pdev,
  1540. sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
  1541. sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
  1542. tp->rx_ring, tp->rx_ring_dma);
  1543. err_out_mtable:
  1544. kfree (tp->mtable);
  1545. pci_iounmap(pdev, ioaddr);
  1546. err_out_free_res:
  1547. pci_release_regions (pdev);
  1548. err_out_free_netdev:
  1549. free_netdev (dev);
  1550. return -ENODEV;
  1551. }
  1552. /* set the registers according to the given wolopts */
  1553. static void tulip_set_wolopts (struct pci_dev *pdev, u32 wolopts)
  1554. {
  1555. struct net_device *dev = pci_get_drvdata(pdev);
  1556. struct tulip_private *tp = netdev_priv(dev);
  1557. void __iomem *ioaddr = tp->base_addr;
  1558. if (tp->flags & COMET_PM) {
  1559. unsigned int tmp;
  1560. tmp = ioread32(ioaddr + CSR18);
  1561. tmp &= ~(comet_csr18_pmes_sticky | comet_csr18_apm_mode | comet_csr18_d3a);
  1562. tmp |= comet_csr18_pm_mode;
  1563. iowrite32(tmp, ioaddr + CSR18);
  1564. /* Set the Wake-up Control/Status Register to the given WOL options*/
  1565. tmp = ioread32(ioaddr + CSR13);
  1566. tmp &= ~(comet_csr13_linkoffe | comet_csr13_linkone | comet_csr13_wfre | comet_csr13_lsce | comet_csr13_mpre);
  1567. if (wolopts & WAKE_MAGIC)
  1568. tmp |= comet_csr13_mpre;
  1569. if (wolopts & WAKE_PHY)
  1570. tmp |= comet_csr13_linkoffe | comet_csr13_linkone | comet_csr13_lsce;
  1571. /* Clear the event flags */
  1572. tmp |= comet_csr13_wfr | comet_csr13_mpr | comet_csr13_lsc;
  1573. iowrite32(tmp, ioaddr + CSR13);
  1574. }
  1575. }
  1576. #ifdef CONFIG_PM
  1577. static int tulip_suspend (struct pci_dev *pdev, pm_message_t state)
  1578. {
  1579. pci_power_t pstate;
  1580. struct net_device *dev = pci_get_drvdata(pdev);
  1581. struct tulip_private *tp = netdev_priv(dev);
  1582. if (!dev)
  1583. return -EINVAL;
  1584. if (!netif_running(dev))
  1585. goto save_state;
  1586. tulip_down(dev);
  1587. netif_device_detach(dev);
  1588. /* FIXME: it needlessly adds an error path. */
  1589. free_irq(tp->pdev->irq, dev);
  1590. save_state:
  1591. pci_save_state(pdev);
  1592. pci_disable_device(pdev);
  1593. pstate = pci_choose_state(pdev, state);
  1594. if (state.event == PM_EVENT_SUSPEND && pstate != PCI_D0) {
  1595. int rc;
  1596. tulip_set_wolopts(pdev, tp->wolinfo.wolopts);
  1597. rc = pci_enable_wake(pdev, pstate, tp->wolinfo.wolopts);
  1598. if (rc)
  1599. pr_err("pci_enable_wake failed (%d)\n", rc);
  1600. }
  1601. pci_set_power_state(pdev, pstate);
  1602. return 0;
  1603. }
  1604. static int tulip_resume(struct pci_dev *pdev)
  1605. {
  1606. struct net_device *dev = pci_get_drvdata(pdev);
  1607. struct tulip_private *tp = netdev_priv(dev);
  1608. void __iomem *ioaddr = tp->base_addr;
  1609. int retval;
  1610. unsigned int tmp;
  1611. if (!dev)
  1612. return -EINVAL;
  1613. pci_set_power_state(pdev, PCI_D0);
  1614. pci_restore_state(pdev);
  1615. if (!netif_running(dev))
  1616. return 0;
  1617. if ((retval = pci_enable_device(pdev))) {
  1618. pr_err("pci_enable_device failed in resume\n");
  1619. return retval;
  1620. }
  1621. retval = request_irq(pdev->irq, tulip_interrupt, IRQF_SHARED,
  1622. dev->name, dev);
  1623. if (retval) {
  1624. pr_err("request_irq failed in resume\n");
  1625. return retval;
  1626. }
  1627. if (tp->flags & COMET_PM) {
  1628. pci_enable_wake(pdev, PCI_D3hot, 0);
  1629. pci_enable_wake(pdev, PCI_D3cold, 0);
  1630. /* Clear the PMES flag */
  1631. tmp = ioread32(ioaddr + CSR20);
  1632. tmp |= comet_csr20_pmes;
  1633. iowrite32(tmp, ioaddr + CSR20);
  1634. /* Disable all wake-up events */
  1635. tulip_set_wolopts(pdev, 0);
  1636. }
  1637. netif_device_attach(dev);
  1638. if (netif_running(dev))
  1639. tulip_up(dev);
  1640. return 0;
  1641. }
  1642. #endif /* CONFIG_PM */
  1643. static void tulip_remove_one(struct pci_dev *pdev)
  1644. {
  1645. struct net_device *dev = pci_get_drvdata (pdev);
  1646. struct tulip_private *tp;
  1647. if (!dev)
  1648. return;
  1649. tp = netdev_priv(dev);
  1650. unregister_netdev(dev);
  1651. pci_free_consistent (pdev,
  1652. sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
  1653. sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
  1654. tp->rx_ring, tp->rx_ring_dma);
  1655. kfree (tp->mtable);
  1656. pci_iounmap(pdev, tp->base_addr);
  1657. free_netdev (dev);
  1658. pci_release_regions (pdev);
  1659. pci_disable_device(pdev);
  1660. /* pci_power_off (pdev, -1); */
  1661. }
  1662. #ifdef CONFIG_NET_POLL_CONTROLLER
  1663. /*
  1664. * Polling 'interrupt' - used by things like netconsole to send skbs
  1665. * without having to re-enable interrupts. It's not called while
  1666. * the interrupt routine is executing.
  1667. */
  1668. static void poll_tulip (struct net_device *dev)
  1669. {
  1670. struct tulip_private *tp = netdev_priv(dev);
  1671. const int irq = tp->pdev->irq;
  1672. /* disable_irq here is not very nice, but with the lockless
  1673. interrupt handler we have no other choice. */
  1674. disable_irq(irq);
  1675. tulip_interrupt (irq, dev);
  1676. enable_irq(irq);
  1677. }
  1678. #endif
  1679. static struct pci_driver tulip_driver = {
  1680. .name = DRV_NAME,
  1681. .id_table = tulip_pci_tbl,
  1682. .probe = tulip_init_one,
  1683. .remove = tulip_remove_one,
  1684. #ifdef CONFIG_PM
  1685. .suspend = tulip_suspend,
  1686. .resume = tulip_resume,
  1687. #endif /* CONFIG_PM */
  1688. };
  1689. static int __init tulip_init (void)
  1690. {
  1691. #ifdef MODULE
  1692. pr_info("%s", version);
  1693. #endif
  1694. if (!csr0) {
  1695. pr_warn("tulip: unknown CPU architecture, using default csr0\n");
  1696. /* default to 8 longword cache line alignment */
  1697. csr0 = 0x00A00000 | 0x4800;
  1698. }
  1699. /* copy module parms into globals */
  1700. tulip_rx_copybreak = rx_copybreak;
  1701. tulip_max_interrupt_work = max_interrupt_work;
  1702. /* probe for and init boards */
  1703. return pci_register_driver(&tulip_driver);
  1704. }
  1705. static void __exit tulip_cleanup (void)
  1706. {
  1707. pci_unregister_driver (&tulip_driver);
  1708. }
  1709. module_init(tulip_init);
  1710. module_exit(tulip_cleanup);