acenic.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189
  1. /*
  2. * acenic.c: Linux driver for the Alteon AceNIC Gigabit Ethernet card
  3. * and other Tigon based cards.
  4. *
  5. * Copyright 1998-2002 by Jes Sorensen, <jes@trained-monkey.org>.
  6. *
  7. * Thanks to Alteon and 3Com for providing hardware and documentation
  8. * enabling me to write this driver.
  9. *
  10. * A mailing list for discussing the use of this driver has been
  11. * setup, please subscribe to the lists if you have any questions
  12. * about the driver. Send mail to linux-acenic-help@sunsite.auc.dk to
  13. * see how to subscribe.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * Additional credits:
  21. * Pete Wyckoff <wyckoff@ca.sandia.gov>: Initial Linux/Alpha and trace
  22. * dump support. The trace dump support has not been
  23. * integrated yet however.
  24. * Troy Benjegerdes: Big Endian (PPC) patches.
  25. * Nate Stahl: Better out of memory handling and stats support.
  26. * Aman Singla: Nasty race between interrupt handler and tx code dealing
  27. * with 'testing the tx_ret_csm and setting tx_full'
  28. * David S. Miller <davem@redhat.com>: conversion to new PCI dma mapping
  29. * infrastructure and Sparc support
  30. * Pierrick Pinasseau (CERN): For lending me an Ultra 5 to test the
  31. * driver under Linux/Sparc64
  32. * Matt Domsch <Matt_Domsch@dell.com>: Detect Alteon 1000baseT cards
  33. * ETHTOOL_GDRVINFO support
  34. * Chip Salzenberg <chip@valinux.com>: Fix race condition between tx
  35. * handler and close() cleanup.
  36. * Ken Aaker <kdaaker@rchland.vnet.ibm.com>: Correct check for whether
  37. * memory mapped IO is enabled to
  38. * make the driver work on RS/6000.
  39. * Takayoshi Kouchi <kouchi@hpc.bs1.fc.nec.co.jp>: Identifying problem
  40. * where the driver would disable
  41. * bus master mode if it had to disable
  42. * write and invalidate.
  43. * Stephen Hack <stephen_hack@hp.com>: Fixed ace_set_mac_addr for little
  44. * endian systems.
  45. * Val Henson <vhenson@esscom.com>: Reset Jumbo skb producer and
  46. * rx producer index when
  47. * flushing the Jumbo ring.
  48. * Hans Grobler <grobh@sun.ac.za>: Memory leak fixes in the
  49. * driver init path.
  50. * Grant Grundler <grundler@cup.hp.com>: PCI write posting fixes.
  51. */
  52. #include <linux/module.h>
  53. #include <linux/moduleparam.h>
  54. #include <linux/types.h>
  55. #include <linux/errno.h>
  56. #include <linux/ioport.h>
  57. #include <linux/pci.h>
  58. #include <linux/dma-mapping.h>
  59. #include <linux/kernel.h>
  60. #include <linux/netdevice.h>
  61. #include <linux/etherdevice.h>
  62. #include <linux/skbuff.h>
  63. #include <linux/delay.h>
  64. #include <linux/mm.h>
  65. #include <linux/highmem.h>
  66. #include <linux/sockios.h>
  67. #include <linux/firmware.h>
  68. #include <linux/slab.h>
  69. #include <linux/prefetch.h>
  70. #include <linux/if_vlan.h>
  71. #ifdef SIOCETHTOOL
  72. #include <linux/ethtool.h>
  73. #endif
  74. #include <net/sock.h>
  75. #include <net/ip.h>
  76. #include <asm/io.h>
  77. #include <asm/irq.h>
  78. #include <asm/byteorder.h>
  79. #include <linux/uaccess.h>
  80. #define DRV_NAME "acenic"
  81. #undef INDEX_DEBUG
  82. #ifdef CONFIG_ACENIC_OMIT_TIGON_I
  83. #define ACE_IS_TIGON_I(ap) 0
  84. #define ACE_TX_RING_ENTRIES(ap) MAX_TX_RING_ENTRIES
  85. #else
  86. #define ACE_IS_TIGON_I(ap) (ap->version == 1)
  87. #define ACE_TX_RING_ENTRIES(ap) ap->tx_ring_entries
  88. #endif
  89. #ifndef PCI_VENDOR_ID_ALTEON
  90. #define PCI_VENDOR_ID_ALTEON 0x12ae
  91. #endif
  92. #ifndef PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE
  93. #define PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE 0x0001
  94. #define PCI_DEVICE_ID_ALTEON_ACENIC_COPPER 0x0002
  95. #endif
  96. #ifndef PCI_DEVICE_ID_3COM_3C985
  97. #define PCI_DEVICE_ID_3COM_3C985 0x0001
  98. #endif
  99. #ifndef PCI_VENDOR_ID_NETGEAR
  100. #define PCI_VENDOR_ID_NETGEAR 0x1385
  101. #define PCI_DEVICE_ID_NETGEAR_GA620 0x620a
  102. #endif
  103. #ifndef PCI_DEVICE_ID_NETGEAR_GA620T
  104. #define PCI_DEVICE_ID_NETGEAR_GA620T 0x630a
  105. #endif
  106. /*
  107. * Farallon used the DEC vendor ID by mistake and they seem not
  108. * to care - stinky!
  109. */
  110. #ifndef PCI_DEVICE_ID_FARALLON_PN9000SX
  111. #define PCI_DEVICE_ID_FARALLON_PN9000SX 0x1a
  112. #endif
  113. #ifndef PCI_DEVICE_ID_FARALLON_PN9100T
  114. #define PCI_DEVICE_ID_FARALLON_PN9100T 0xfa
  115. #endif
  116. #ifndef PCI_VENDOR_ID_SGI
  117. #define PCI_VENDOR_ID_SGI 0x10a9
  118. #endif
  119. #ifndef PCI_DEVICE_ID_SGI_ACENIC
  120. #define PCI_DEVICE_ID_SGI_ACENIC 0x0009
  121. #endif
  122. static const struct pci_device_id acenic_pci_tbl[] = {
  123. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE,
  124. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  125. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_COPPER,
  126. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  127. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C985,
  128. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  129. { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620,
  130. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  131. { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620T,
  132. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  133. /*
  134. * Farallon used the DEC vendor ID on their cards incorrectly,
  135. * then later Alteon's ID.
  136. */
  137. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_FARALLON_PN9000SX,
  138. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  139. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_FARALLON_PN9100T,
  140. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  141. { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_ACENIC,
  142. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  143. { }
  144. };
  145. MODULE_DEVICE_TABLE(pci, acenic_pci_tbl);
  146. #define ace_sync_irq(irq) synchronize_irq(irq)
  147. #ifndef offset_in_page
  148. #define offset_in_page(ptr) ((unsigned long)(ptr) & ~PAGE_MASK)
  149. #endif
  150. #define ACE_MAX_MOD_PARMS 8
  151. #define BOARD_IDX_STATIC 0
  152. #define BOARD_IDX_OVERFLOW -1
  153. #include "acenic.h"
  154. /*
  155. * These must be defined before the firmware is included.
  156. */
  157. #define MAX_TEXT_LEN 96*1024
  158. #define MAX_RODATA_LEN 8*1024
  159. #define MAX_DATA_LEN 2*1024
  160. #ifndef tigon2FwReleaseLocal
  161. #define tigon2FwReleaseLocal 0
  162. #endif
  163. /*
  164. * This driver currently supports Tigon I and Tigon II based cards
  165. * including the Alteon AceNIC, the 3Com 3C985[B] and NetGear
  166. * GA620. The driver should also work on the SGI, DEC and Farallon
  167. * versions of the card, however I have not been able to test that
  168. * myself.
  169. *
  170. * This card is really neat, it supports receive hardware checksumming
  171. * and jumbo frames (up to 9000 bytes) and does a lot of work in the
  172. * firmware. Also the programming interface is quite neat, except for
  173. * the parts dealing with the i2c eeprom on the card ;-)
  174. *
  175. * Using jumbo frames:
  176. *
  177. * To enable jumbo frames, simply specify an mtu between 1500 and 9000
  178. * bytes to ifconfig. Jumbo frames can be enabled or disabled at any time
  179. * by running `ifconfig eth<X> mtu <MTU>' with <X> being the Ethernet
  180. * interface number and <MTU> being the MTU value.
  181. *
  182. * Module parameters:
  183. *
  184. * When compiled as a loadable module, the driver allows for a number
  185. * of module parameters to be specified. The driver supports the
  186. * following module parameters:
  187. *
  188. * trace=<val> - Firmware trace level. This requires special traced
  189. * firmware to replace the firmware supplied with
  190. * the driver - for debugging purposes only.
  191. *
  192. * link=<val> - Link state. Normally you want to use the default link
  193. * parameters set by the driver. This can be used to
  194. * override these in case your switch doesn't negotiate
  195. * the link properly. Valid values are:
  196. * 0x0001 - Force half duplex link.
  197. * 0x0002 - Do not negotiate line speed with the other end.
  198. * 0x0010 - 10Mbit/sec link.
  199. * 0x0020 - 100Mbit/sec link.
  200. * 0x0040 - 1000Mbit/sec link.
  201. * 0x0100 - Do not negotiate flow control.
  202. * 0x0200 - Enable RX flow control Y
  203. * 0x0400 - Enable TX flow control Y (Tigon II NICs only).
  204. * Default value is 0x0270, ie. enable link+flow
  205. * control negotiation. Negotiating the highest
  206. * possible link speed with RX flow control enabled.
  207. *
  208. * When disabling link speed negotiation, only one link
  209. * speed is allowed to be specified!
  210. *
  211. * tx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
  212. * to wait for more packets to arive before
  213. * interrupting the host, from the time the first
  214. * packet arrives.
  215. *
  216. * rx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
  217. * to wait for more packets to arive in the transmit ring,
  218. * before interrupting the host, after transmitting the
  219. * first packet in the ring.
  220. *
  221. * max_tx_desc=<val> - maximum number of transmit descriptors
  222. * (packets) transmitted before interrupting the host.
  223. *
  224. * max_rx_desc=<val> - maximum number of receive descriptors
  225. * (packets) received before interrupting the host.
  226. *
  227. * tx_ratio=<val> - 7 bit value (0 - 63) specifying the split in 64th
  228. * increments of the NIC's on board memory to be used for
  229. * transmit and receive buffers. For the 1MB NIC app. 800KB
  230. * is available, on the 1/2MB NIC app. 300KB is available.
  231. * 68KB will always be available as a minimum for both
  232. * directions. The default value is a 50/50 split.
  233. * dis_pci_mem_inval=<val> - disable PCI memory write and invalidate
  234. * operations, default (1) is to always disable this as
  235. * that is what Alteon does on NT. I have not been able
  236. * to measure any real performance differences with
  237. * this on my systems. Set <val>=0 if you want to
  238. * enable these operations.
  239. *
  240. * If you use more than one NIC, specify the parameters for the
  241. * individual NICs with a comma, ie. trace=0,0x00001fff,0 you want to
  242. * run tracing on NIC #2 but not on NIC #1 and #3.
  243. *
  244. * TODO:
  245. *
  246. * - Proper multicast support.
  247. * - NIC dump support.
  248. * - More tuning parameters.
  249. *
  250. * The mini ring is not used under Linux and I am not sure it makes sense
  251. * to actually use it.
  252. *
  253. * New interrupt handler strategy:
  254. *
  255. * The old interrupt handler worked using the traditional method of
  256. * replacing an skbuff with a new one when a packet arrives. However
  257. * the rx rings do not need to contain a static number of buffer
  258. * descriptors, thus it makes sense to move the memory allocation out
  259. * of the main interrupt handler and do it in a bottom half handler
  260. * and only allocate new buffers when the number of buffers in the
  261. * ring is below a certain threshold. In order to avoid starving the
  262. * NIC under heavy load it is however necessary to force allocation
  263. * when hitting a minimum threshold. The strategy for alloction is as
  264. * follows:
  265. *
  266. * RX_LOW_BUF_THRES - allocate buffers in the bottom half
  267. * RX_PANIC_LOW_THRES - we are very low on buffers, allocate
  268. * the buffers in the interrupt handler
  269. * RX_RING_THRES - maximum number of buffers in the rx ring
  270. * RX_MINI_THRES - maximum number of buffers in the mini ring
  271. * RX_JUMBO_THRES - maximum number of buffers in the jumbo ring
  272. *
  273. * One advantagous side effect of this allocation approach is that the
  274. * entire rx processing can be done without holding any spin lock
  275. * since the rx rings and registers are totally independent of the tx
  276. * ring and its registers. This of course includes the kmalloc's of
  277. * new skb's. Thus start_xmit can run in parallel with rx processing
  278. * and the memory allocation on SMP systems.
  279. *
  280. * Note that running the skb reallocation in a bottom half opens up
  281. * another can of races which needs to be handled properly. In
  282. * particular it can happen that the interrupt handler tries to run
  283. * the reallocation while the bottom half is either running on another
  284. * CPU or was interrupted on the same CPU. To get around this the
  285. * driver uses bitops to prevent the reallocation routines from being
  286. * reentered.
  287. *
  288. * TX handling can also be done without holding any spin lock, wheee
  289. * this is fun! since tx_ret_csm is only written to by the interrupt
  290. * handler. The case to be aware of is when shutting down the device
  291. * and cleaning up where it is necessary to make sure that
  292. * start_xmit() is not running while this is happening. Well DaveM
  293. * informs me that this case is already protected against ... bye bye
  294. * Mr. Spin Lock, it was nice to know you.
  295. *
  296. * TX interrupts are now partly disabled so the NIC will only generate
  297. * TX interrupts for the number of coal ticks, not for the number of
  298. * TX packets in the queue. This should reduce the number of TX only,
  299. * ie. when no RX processing is done, interrupts seen.
  300. */
  301. /*
  302. * Threshold values for RX buffer allocation - the low water marks for
  303. * when to start refilling the rings are set to 75% of the ring
  304. * sizes. It seems to make sense to refill the rings entirely from the
  305. * intrrupt handler once it gets below the panic threshold, that way
  306. * we don't risk that the refilling is moved to another CPU when the
  307. * one running the interrupt handler just got the slab code hot in its
  308. * cache.
  309. */
  310. #define RX_RING_SIZE 72
  311. #define RX_MINI_SIZE 64
  312. #define RX_JUMBO_SIZE 48
  313. #define RX_PANIC_STD_THRES 16
  314. #define RX_PANIC_STD_REFILL (3*RX_PANIC_STD_THRES)/2
  315. #define RX_LOW_STD_THRES (3*RX_RING_SIZE)/4
  316. #define RX_PANIC_MINI_THRES 12
  317. #define RX_PANIC_MINI_REFILL (3*RX_PANIC_MINI_THRES)/2
  318. #define RX_LOW_MINI_THRES (3*RX_MINI_SIZE)/4
  319. #define RX_PANIC_JUMBO_THRES 6
  320. #define RX_PANIC_JUMBO_REFILL (3*RX_PANIC_JUMBO_THRES)/2
  321. #define RX_LOW_JUMBO_THRES (3*RX_JUMBO_SIZE)/4
  322. /*
  323. * Size of the mini ring entries, basically these just should be big
  324. * enough to take TCP ACKs
  325. */
  326. #define ACE_MINI_SIZE 100
  327. #define ACE_MINI_BUFSIZE ACE_MINI_SIZE
  328. #define ACE_STD_BUFSIZE (ACE_STD_MTU + ETH_HLEN + 4)
  329. #define ACE_JUMBO_BUFSIZE (ACE_JUMBO_MTU + ETH_HLEN + 4)
  330. /*
  331. * There seems to be a magic difference in the effect between 995 and 996
  332. * but little difference between 900 and 995 ... no idea why.
  333. *
  334. * There is now a default set of tuning parameters which is set, depending
  335. * on whether or not the user enables Jumbo frames. It's assumed that if
  336. * Jumbo frames are enabled, the user wants optimal tuning for that case.
  337. */
  338. #define DEF_TX_COAL 400 /* 996 */
  339. #define DEF_TX_MAX_DESC 60 /* was 40 */
  340. #define DEF_RX_COAL 120 /* 1000 */
  341. #define DEF_RX_MAX_DESC 25
  342. #define DEF_TX_RATIO 21 /* 24 */
  343. #define DEF_JUMBO_TX_COAL 20
  344. #define DEF_JUMBO_TX_MAX_DESC 60
  345. #define DEF_JUMBO_RX_COAL 30
  346. #define DEF_JUMBO_RX_MAX_DESC 6
  347. #define DEF_JUMBO_TX_RATIO 21
  348. #if tigon2FwReleaseLocal < 20001118
  349. /*
  350. * Standard firmware and early modifications duplicate
  351. * IRQ load without this flag (coal timer is never reset).
  352. * Note that with this flag tx_coal should be less than
  353. * time to xmit full tx ring.
  354. * 400usec is not so bad for tx ring size of 128.
  355. */
  356. #define TX_COAL_INTS_ONLY 1 /* worth it */
  357. #else
  358. /*
  359. * With modified firmware, this is not necessary, but still useful.
  360. */
  361. #define TX_COAL_INTS_ONLY 1
  362. #endif
  363. #define DEF_TRACE 0
  364. #define DEF_STAT (2 * TICKS_PER_SEC)
  365. static int link_state[ACE_MAX_MOD_PARMS];
  366. static int trace[ACE_MAX_MOD_PARMS];
  367. static int tx_coal_tick[ACE_MAX_MOD_PARMS];
  368. static int rx_coal_tick[ACE_MAX_MOD_PARMS];
  369. static int max_tx_desc[ACE_MAX_MOD_PARMS];
  370. static int max_rx_desc[ACE_MAX_MOD_PARMS];
  371. static int tx_ratio[ACE_MAX_MOD_PARMS];
  372. static int dis_pci_mem_inval[ACE_MAX_MOD_PARMS] = {1, 1, 1, 1, 1, 1, 1, 1};
  373. MODULE_AUTHOR("Jes Sorensen <jes@trained-monkey.org>");
  374. MODULE_LICENSE("GPL");
  375. MODULE_DESCRIPTION("AceNIC/3C985/GA620 Gigabit Ethernet driver");
  376. #ifndef CONFIG_ACENIC_OMIT_TIGON_I
  377. MODULE_FIRMWARE("acenic/tg1.bin");
  378. #endif
  379. MODULE_FIRMWARE("acenic/tg2.bin");
  380. module_param_array_named(link, link_state, int, NULL, 0);
  381. module_param_array(trace, int, NULL, 0);
  382. module_param_array(tx_coal_tick, int, NULL, 0);
  383. module_param_array(max_tx_desc, int, NULL, 0);
  384. module_param_array(rx_coal_tick, int, NULL, 0);
  385. module_param_array(max_rx_desc, int, NULL, 0);
  386. module_param_array(tx_ratio, int, NULL, 0);
  387. MODULE_PARM_DESC(link, "AceNIC/3C985/NetGear link state");
  388. MODULE_PARM_DESC(trace, "AceNIC/3C985/NetGear firmware trace level");
  389. MODULE_PARM_DESC(tx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first tx descriptor arrives");
  390. MODULE_PARM_DESC(max_tx_desc, "AceNIC/3C985/GA620 max number of transmit descriptors to wait");
  391. MODULE_PARM_DESC(rx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first rx descriptor arrives");
  392. MODULE_PARM_DESC(max_rx_desc, "AceNIC/3C985/GA620 max number of receive descriptors to wait");
  393. MODULE_PARM_DESC(tx_ratio, "AceNIC/3C985/GA620 ratio of NIC memory used for TX/RX descriptors (range 0-63)");
  394. static const char version[] =
  395. "acenic.c: v0.92 08/05/2002 Jes Sorensen, linux-acenic@SunSITE.dk\n"
  396. " http://home.cern.ch/~jes/gige/acenic.html\n";
  397. static int ace_get_link_ksettings(struct net_device *,
  398. struct ethtool_link_ksettings *);
  399. static int ace_set_link_ksettings(struct net_device *,
  400. const struct ethtool_link_ksettings *);
  401. static void ace_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
  402. static const struct ethtool_ops ace_ethtool_ops = {
  403. .get_drvinfo = ace_get_drvinfo,
  404. .get_link_ksettings = ace_get_link_ksettings,
  405. .set_link_ksettings = ace_set_link_ksettings,
  406. };
  407. static void ace_watchdog(struct net_device *dev);
  408. static const struct net_device_ops ace_netdev_ops = {
  409. .ndo_open = ace_open,
  410. .ndo_stop = ace_close,
  411. .ndo_tx_timeout = ace_watchdog,
  412. .ndo_get_stats = ace_get_stats,
  413. .ndo_start_xmit = ace_start_xmit,
  414. .ndo_set_rx_mode = ace_set_multicast_list,
  415. .ndo_validate_addr = eth_validate_addr,
  416. .ndo_set_mac_address = ace_set_mac_addr,
  417. .ndo_change_mtu = ace_change_mtu,
  418. };
  419. static int acenic_probe_one(struct pci_dev *pdev,
  420. const struct pci_device_id *id)
  421. {
  422. struct net_device *dev;
  423. struct ace_private *ap;
  424. static int boards_found;
  425. dev = alloc_etherdev(sizeof(struct ace_private));
  426. if (dev == NULL)
  427. return -ENOMEM;
  428. SET_NETDEV_DEV(dev, &pdev->dev);
  429. ap = netdev_priv(dev);
  430. ap->pdev = pdev;
  431. ap->name = pci_name(pdev);
  432. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  433. dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
  434. dev->watchdog_timeo = 5*HZ;
  435. dev->min_mtu = 0;
  436. dev->max_mtu = ACE_JUMBO_MTU;
  437. dev->netdev_ops = &ace_netdev_ops;
  438. dev->ethtool_ops = &ace_ethtool_ops;
  439. /* we only display this string ONCE */
  440. if (!boards_found)
  441. printk(version);
  442. if (pci_enable_device(pdev))
  443. goto fail_free_netdev;
  444. /*
  445. * Enable master mode before we start playing with the
  446. * pci_command word since pci_set_master() will modify
  447. * it.
  448. */
  449. pci_set_master(pdev);
  450. pci_read_config_word(pdev, PCI_COMMAND, &ap->pci_command);
  451. /* OpenFirmware on Mac's does not set this - DOH.. */
  452. if (!(ap->pci_command & PCI_COMMAND_MEMORY)) {
  453. printk(KERN_INFO "%s: Enabling PCI Memory Mapped "
  454. "access - was not enabled by BIOS/Firmware\n",
  455. ap->name);
  456. ap->pci_command = ap->pci_command | PCI_COMMAND_MEMORY;
  457. pci_write_config_word(ap->pdev, PCI_COMMAND,
  458. ap->pci_command);
  459. wmb();
  460. }
  461. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &ap->pci_latency);
  462. if (ap->pci_latency <= 0x40) {
  463. ap->pci_latency = 0x40;
  464. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, ap->pci_latency);
  465. }
  466. /*
  467. * Remap the regs into kernel space - this is abuse of
  468. * dev->base_addr since it was means for I/O port
  469. * addresses but who gives a damn.
  470. */
  471. dev->base_addr = pci_resource_start(pdev, 0);
  472. ap->regs = ioremap(dev->base_addr, 0x4000);
  473. if (!ap->regs) {
  474. printk(KERN_ERR "%s: Unable to map I/O register, "
  475. "AceNIC %i will be disabled.\n",
  476. ap->name, boards_found);
  477. goto fail_free_netdev;
  478. }
  479. switch(pdev->vendor) {
  480. case PCI_VENDOR_ID_ALTEON:
  481. if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T) {
  482. printk(KERN_INFO "%s: Farallon PN9100-T ",
  483. ap->name);
  484. } else {
  485. printk(KERN_INFO "%s: Alteon AceNIC ",
  486. ap->name);
  487. }
  488. break;
  489. case PCI_VENDOR_ID_3COM:
  490. printk(KERN_INFO "%s: 3Com 3C985 ", ap->name);
  491. break;
  492. case PCI_VENDOR_ID_NETGEAR:
  493. printk(KERN_INFO "%s: NetGear GA620 ", ap->name);
  494. break;
  495. case PCI_VENDOR_ID_DEC:
  496. if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9000SX) {
  497. printk(KERN_INFO "%s: Farallon PN9000-SX ",
  498. ap->name);
  499. break;
  500. }
  501. /* Fall through */
  502. case PCI_VENDOR_ID_SGI:
  503. printk(KERN_INFO "%s: SGI AceNIC ", ap->name);
  504. break;
  505. default:
  506. printk(KERN_INFO "%s: Unknown AceNIC ", ap->name);
  507. break;
  508. }
  509. printk("Gigabit Ethernet at 0x%08lx, ", dev->base_addr);
  510. printk("irq %d\n", pdev->irq);
  511. #ifdef CONFIG_ACENIC_OMIT_TIGON_I
  512. if ((readl(&ap->regs->HostCtrl) >> 28) == 4) {
  513. printk(KERN_ERR "%s: Driver compiled without Tigon I"
  514. " support - NIC disabled\n", dev->name);
  515. goto fail_uninit;
  516. }
  517. #endif
  518. if (ace_allocate_descriptors(dev))
  519. goto fail_free_netdev;
  520. #ifdef MODULE
  521. if (boards_found >= ACE_MAX_MOD_PARMS)
  522. ap->board_idx = BOARD_IDX_OVERFLOW;
  523. else
  524. ap->board_idx = boards_found;
  525. #else
  526. ap->board_idx = BOARD_IDX_STATIC;
  527. #endif
  528. if (ace_init(dev))
  529. goto fail_free_netdev;
  530. if (register_netdev(dev)) {
  531. printk(KERN_ERR "acenic: device registration failed\n");
  532. goto fail_uninit;
  533. }
  534. ap->name = dev->name;
  535. if (ap->pci_using_dac)
  536. dev->features |= NETIF_F_HIGHDMA;
  537. pci_set_drvdata(pdev, dev);
  538. boards_found++;
  539. return 0;
  540. fail_uninit:
  541. ace_init_cleanup(dev);
  542. fail_free_netdev:
  543. free_netdev(dev);
  544. return -ENODEV;
  545. }
  546. static void acenic_remove_one(struct pci_dev *pdev)
  547. {
  548. struct net_device *dev = pci_get_drvdata(pdev);
  549. struct ace_private *ap = netdev_priv(dev);
  550. struct ace_regs __iomem *regs = ap->regs;
  551. short i;
  552. unregister_netdev(dev);
  553. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  554. if (ap->version >= 2)
  555. writel(readl(&regs->CpuBCtrl) | CPU_HALT, &regs->CpuBCtrl);
  556. /*
  557. * This clears any pending interrupts
  558. */
  559. writel(1, &regs->Mb0Lo);
  560. readl(&regs->CpuCtrl); /* flush */
  561. /*
  562. * Make sure no other CPUs are processing interrupts
  563. * on the card before the buffers are being released.
  564. * Otherwise one might experience some `interesting'
  565. * effects.
  566. *
  567. * Then release the RX buffers - jumbo buffers were
  568. * already released in ace_close().
  569. */
  570. ace_sync_irq(dev->irq);
  571. for (i = 0; i < RX_STD_RING_ENTRIES; i++) {
  572. struct sk_buff *skb = ap->skb->rx_std_skbuff[i].skb;
  573. if (skb) {
  574. struct ring_info *ringp;
  575. dma_addr_t mapping;
  576. ringp = &ap->skb->rx_std_skbuff[i];
  577. mapping = dma_unmap_addr(ringp, mapping);
  578. pci_unmap_page(ap->pdev, mapping,
  579. ACE_STD_BUFSIZE,
  580. PCI_DMA_FROMDEVICE);
  581. ap->rx_std_ring[i].size = 0;
  582. ap->skb->rx_std_skbuff[i].skb = NULL;
  583. dev_kfree_skb(skb);
  584. }
  585. }
  586. if (ap->version >= 2) {
  587. for (i = 0; i < RX_MINI_RING_ENTRIES; i++) {
  588. struct sk_buff *skb = ap->skb->rx_mini_skbuff[i].skb;
  589. if (skb) {
  590. struct ring_info *ringp;
  591. dma_addr_t mapping;
  592. ringp = &ap->skb->rx_mini_skbuff[i];
  593. mapping = dma_unmap_addr(ringp,mapping);
  594. pci_unmap_page(ap->pdev, mapping,
  595. ACE_MINI_BUFSIZE,
  596. PCI_DMA_FROMDEVICE);
  597. ap->rx_mini_ring[i].size = 0;
  598. ap->skb->rx_mini_skbuff[i].skb = NULL;
  599. dev_kfree_skb(skb);
  600. }
  601. }
  602. }
  603. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
  604. struct sk_buff *skb = ap->skb->rx_jumbo_skbuff[i].skb;
  605. if (skb) {
  606. struct ring_info *ringp;
  607. dma_addr_t mapping;
  608. ringp = &ap->skb->rx_jumbo_skbuff[i];
  609. mapping = dma_unmap_addr(ringp, mapping);
  610. pci_unmap_page(ap->pdev, mapping,
  611. ACE_JUMBO_BUFSIZE,
  612. PCI_DMA_FROMDEVICE);
  613. ap->rx_jumbo_ring[i].size = 0;
  614. ap->skb->rx_jumbo_skbuff[i].skb = NULL;
  615. dev_kfree_skb(skb);
  616. }
  617. }
  618. ace_init_cleanup(dev);
  619. free_netdev(dev);
  620. }
  621. static struct pci_driver acenic_pci_driver = {
  622. .name = "acenic",
  623. .id_table = acenic_pci_tbl,
  624. .probe = acenic_probe_one,
  625. .remove = acenic_remove_one,
  626. };
  627. static void ace_free_descriptors(struct net_device *dev)
  628. {
  629. struct ace_private *ap = netdev_priv(dev);
  630. int size;
  631. if (ap->rx_std_ring != NULL) {
  632. size = (sizeof(struct rx_desc) *
  633. (RX_STD_RING_ENTRIES +
  634. RX_JUMBO_RING_ENTRIES +
  635. RX_MINI_RING_ENTRIES +
  636. RX_RETURN_RING_ENTRIES));
  637. pci_free_consistent(ap->pdev, size, ap->rx_std_ring,
  638. ap->rx_ring_base_dma);
  639. ap->rx_std_ring = NULL;
  640. ap->rx_jumbo_ring = NULL;
  641. ap->rx_mini_ring = NULL;
  642. ap->rx_return_ring = NULL;
  643. }
  644. if (ap->evt_ring != NULL) {
  645. size = (sizeof(struct event) * EVT_RING_ENTRIES);
  646. pci_free_consistent(ap->pdev, size, ap->evt_ring,
  647. ap->evt_ring_dma);
  648. ap->evt_ring = NULL;
  649. }
  650. if (ap->tx_ring != NULL && !ACE_IS_TIGON_I(ap)) {
  651. size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
  652. pci_free_consistent(ap->pdev, size, ap->tx_ring,
  653. ap->tx_ring_dma);
  654. }
  655. ap->tx_ring = NULL;
  656. if (ap->evt_prd != NULL) {
  657. pci_free_consistent(ap->pdev, sizeof(u32),
  658. (void *)ap->evt_prd, ap->evt_prd_dma);
  659. ap->evt_prd = NULL;
  660. }
  661. if (ap->rx_ret_prd != NULL) {
  662. pci_free_consistent(ap->pdev, sizeof(u32),
  663. (void *)ap->rx_ret_prd,
  664. ap->rx_ret_prd_dma);
  665. ap->rx_ret_prd = NULL;
  666. }
  667. if (ap->tx_csm != NULL) {
  668. pci_free_consistent(ap->pdev, sizeof(u32),
  669. (void *)ap->tx_csm, ap->tx_csm_dma);
  670. ap->tx_csm = NULL;
  671. }
  672. }
  673. static int ace_allocate_descriptors(struct net_device *dev)
  674. {
  675. struct ace_private *ap = netdev_priv(dev);
  676. int size;
  677. size = (sizeof(struct rx_desc) *
  678. (RX_STD_RING_ENTRIES +
  679. RX_JUMBO_RING_ENTRIES +
  680. RX_MINI_RING_ENTRIES +
  681. RX_RETURN_RING_ENTRIES));
  682. ap->rx_std_ring = pci_alloc_consistent(ap->pdev, size,
  683. &ap->rx_ring_base_dma);
  684. if (ap->rx_std_ring == NULL)
  685. goto fail;
  686. ap->rx_jumbo_ring = ap->rx_std_ring + RX_STD_RING_ENTRIES;
  687. ap->rx_mini_ring = ap->rx_jumbo_ring + RX_JUMBO_RING_ENTRIES;
  688. ap->rx_return_ring = ap->rx_mini_ring + RX_MINI_RING_ENTRIES;
  689. size = (sizeof(struct event) * EVT_RING_ENTRIES);
  690. ap->evt_ring = pci_alloc_consistent(ap->pdev, size, &ap->evt_ring_dma);
  691. if (ap->evt_ring == NULL)
  692. goto fail;
  693. /*
  694. * Only allocate a host TX ring for the Tigon II, the Tigon I
  695. * has to use PCI registers for this ;-(
  696. */
  697. if (!ACE_IS_TIGON_I(ap)) {
  698. size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
  699. ap->tx_ring = pci_alloc_consistent(ap->pdev, size,
  700. &ap->tx_ring_dma);
  701. if (ap->tx_ring == NULL)
  702. goto fail;
  703. }
  704. ap->evt_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
  705. &ap->evt_prd_dma);
  706. if (ap->evt_prd == NULL)
  707. goto fail;
  708. ap->rx_ret_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
  709. &ap->rx_ret_prd_dma);
  710. if (ap->rx_ret_prd == NULL)
  711. goto fail;
  712. ap->tx_csm = pci_alloc_consistent(ap->pdev, sizeof(u32),
  713. &ap->tx_csm_dma);
  714. if (ap->tx_csm == NULL)
  715. goto fail;
  716. return 0;
  717. fail:
  718. /* Clean up. */
  719. ace_init_cleanup(dev);
  720. return 1;
  721. }
  722. /*
  723. * Generic cleanup handling data allocated during init. Used when the
  724. * module is unloaded or if an error occurs during initialization
  725. */
  726. static void ace_init_cleanup(struct net_device *dev)
  727. {
  728. struct ace_private *ap;
  729. ap = netdev_priv(dev);
  730. ace_free_descriptors(dev);
  731. if (ap->info)
  732. pci_free_consistent(ap->pdev, sizeof(struct ace_info),
  733. ap->info, ap->info_dma);
  734. kfree(ap->skb);
  735. kfree(ap->trace_buf);
  736. if (dev->irq)
  737. free_irq(dev->irq, dev);
  738. iounmap(ap->regs);
  739. }
  740. /*
  741. * Commands are considered to be slow.
  742. */
  743. static inline void ace_issue_cmd(struct ace_regs __iomem *regs, struct cmd *cmd)
  744. {
  745. u32 idx;
  746. idx = readl(&regs->CmdPrd);
  747. writel(*(u32 *)(cmd), &regs->CmdRng[idx]);
  748. idx = (idx + 1) % CMD_RING_ENTRIES;
  749. writel(idx, &regs->CmdPrd);
  750. }
  751. static int ace_init(struct net_device *dev)
  752. {
  753. struct ace_private *ap;
  754. struct ace_regs __iomem *regs;
  755. struct ace_info *info = NULL;
  756. struct pci_dev *pdev;
  757. unsigned long myjif;
  758. u64 tmp_ptr;
  759. u32 tig_ver, mac1, mac2, tmp, pci_state;
  760. int board_idx, ecode = 0;
  761. short i;
  762. unsigned char cache_size;
  763. ap = netdev_priv(dev);
  764. regs = ap->regs;
  765. board_idx = ap->board_idx;
  766. /*
  767. * aman@sgi.com - its useful to do a NIC reset here to
  768. * address the `Firmware not running' problem subsequent
  769. * to any crashes involving the NIC
  770. */
  771. writel(HW_RESET | (HW_RESET << 24), &regs->HostCtrl);
  772. readl(&regs->HostCtrl); /* PCI write posting */
  773. udelay(5);
  774. /*
  775. * Don't access any other registers before this point!
  776. */
  777. #ifdef __BIG_ENDIAN
  778. /*
  779. * This will most likely need BYTE_SWAP once we switch
  780. * to using __raw_writel()
  781. */
  782. writel((WORD_SWAP | CLR_INT | ((WORD_SWAP | CLR_INT) << 24)),
  783. &regs->HostCtrl);
  784. #else
  785. writel((CLR_INT | WORD_SWAP | ((CLR_INT | WORD_SWAP) << 24)),
  786. &regs->HostCtrl);
  787. #endif
  788. readl(&regs->HostCtrl); /* PCI write posting */
  789. /*
  790. * Stop the NIC CPU and clear pending interrupts
  791. */
  792. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  793. readl(&regs->CpuCtrl); /* PCI write posting */
  794. writel(0, &regs->Mb0Lo);
  795. tig_ver = readl(&regs->HostCtrl) >> 28;
  796. switch(tig_ver){
  797. #ifndef CONFIG_ACENIC_OMIT_TIGON_I
  798. case 4:
  799. case 5:
  800. printk(KERN_INFO " Tigon I (Rev. %i), Firmware: %i.%i.%i, ",
  801. tig_ver, ap->firmware_major, ap->firmware_minor,
  802. ap->firmware_fix);
  803. writel(0, &regs->LocalCtrl);
  804. ap->version = 1;
  805. ap->tx_ring_entries = TIGON_I_TX_RING_ENTRIES;
  806. break;
  807. #endif
  808. case 6:
  809. printk(KERN_INFO " Tigon II (Rev. %i), Firmware: %i.%i.%i, ",
  810. tig_ver, ap->firmware_major, ap->firmware_minor,
  811. ap->firmware_fix);
  812. writel(readl(&regs->CpuBCtrl) | CPU_HALT, &regs->CpuBCtrl);
  813. readl(&regs->CpuBCtrl); /* PCI write posting */
  814. /*
  815. * The SRAM bank size does _not_ indicate the amount
  816. * of memory on the card, it controls the _bank_ size!
  817. * Ie. a 1MB AceNIC will have two banks of 512KB.
  818. */
  819. writel(SRAM_BANK_512K, &regs->LocalCtrl);
  820. writel(SYNC_SRAM_TIMING, &regs->MiscCfg);
  821. ap->version = 2;
  822. ap->tx_ring_entries = MAX_TX_RING_ENTRIES;
  823. break;
  824. default:
  825. printk(KERN_WARNING " Unsupported Tigon version detected "
  826. "(%i)\n", tig_ver);
  827. ecode = -ENODEV;
  828. goto init_error;
  829. }
  830. /*
  831. * ModeStat _must_ be set after the SRAM settings as this change
  832. * seems to corrupt the ModeStat and possible other registers.
  833. * The SRAM settings survive resets and setting it to the same
  834. * value a second time works as well. This is what caused the
  835. * `Firmware not running' problem on the Tigon II.
  836. */
  837. #ifdef __BIG_ENDIAN
  838. writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL | ACE_BYTE_SWAP_BD |
  839. ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, &regs->ModeStat);
  840. #else
  841. writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL |
  842. ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, &regs->ModeStat);
  843. #endif
  844. readl(&regs->ModeStat); /* PCI write posting */
  845. mac1 = 0;
  846. for(i = 0; i < 4; i++) {
  847. int t;
  848. mac1 = mac1 << 8;
  849. t = read_eeprom_byte(dev, 0x8c+i);
  850. if (t < 0) {
  851. ecode = -EIO;
  852. goto init_error;
  853. } else
  854. mac1 |= (t & 0xff);
  855. }
  856. mac2 = 0;
  857. for(i = 4; i < 8; i++) {
  858. int t;
  859. mac2 = mac2 << 8;
  860. t = read_eeprom_byte(dev, 0x8c+i);
  861. if (t < 0) {
  862. ecode = -EIO;
  863. goto init_error;
  864. } else
  865. mac2 |= (t & 0xff);
  866. }
  867. writel(mac1, &regs->MacAddrHi);
  868. writel(mac2, &regs->MacAddrLo);
  869. dev->dev_addr[0] = (mac1 >> 8) & 0xff;
  870. dev->dev_addr[1] = mac1 & 0xff;
  871. dev->dev_addr[2] = (mac2 >> 24) & 0xff;
  872. dev->dev_addr[3] = (mac2 >> 16) & 0xff;
  873. dev->dev_addr[4] = (mac2 >> 8) & 0xff;
  874. dev->dev_addr[5] = mac2 & 0xff;
  875. printk("MAC: %pM\n", dev->dev_addr);
  876. /*
  877. * Looks like this is necessary to deal with on all architectures,
  878. * even this %$#%$# N440BX Intel based thing doesn't get it right.
  879. * Ie. having two NICs in the machine, one will have the cache
  880. * line set at boot time, the other will not.
  881. */
  882. pdev = ap->pdev;
  883. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_size);
  884. cache_size <<= 2;
  885. if (cache_size != SMP_CACHE_BYTES) {
  886. printk(KERN_INFO " PCI cache line size set incorrectly "
  887. "(%i bytes) by BIOS/FW, ", cache_size);
  888. if (cache_size > SMP_CACHE_BYTES)
  889. printk("expecting %i\n", SMP_CACHE_BYTES);
  890. else {
  891. printk("correcting to %i\n", SMP_CACHE_BYTES);
  892. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  893. SMP_CACHE_BYTES >> 2);
  894. }
  895. }
  896. pci_state = readl(&regs->PciState);
  897. printk(KERN_INFO " PCI bus width: %i bits, speed: %iMHz, "
  898. "latency: %i clks\n",
  899. (pci_state & PCI_32BIT) ? 32 : 64,
  900. (pci_state & PCI_66MHZ) ? 66 : 33,
  901. ap->pci_latency);
  902. /*
  903. * Set the max DMA transfer size. Seems that for most systems
  904. * the performance is better when no MAX parameter is
  905. * set. However for systems enabling PCI write and invalidate,
  906. * DMA writes must be set to the L1 cache line size to get
  907. * optimal performance.
  908. *
  909. * The default is now to turn the PCI write and invalidate off
  910. * - that is what Alteon does for NT.
  911. */
  912. tmp = READ_CMD_MEM | WRITE_CMD_MEM;
  913. if (ap->version >= 2) {
  914. tmp |= (MEM_READ_MULTIPLE | (pci_state & PCI_66MHZ));
  915. /*
  916. * Tuning parameters only supported for 8 cards
  917. */
  918. if (board_idx == BOARD_IDX_OVERFLOW ||
  919. dis_pci_mem_inval[board_idx]) {
  920. if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
  921. ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
  922. pci_write_config_word(pdev, PCI_COMMAND,
  923. ap->pci_command);
  924. printk(KERN_INFO " Disabling PCI memory "
  925. "write and invalidate\n");
  926. }
  927. } else if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
  928. printk(KERN_INFO " PCI memory write & invalidate "
  929. "enabled by BIOS, enabling counter measures\n");
  930. switch(SMP_CACHE_BYTES) {
  931. case 16:
  932. tmp |= DMA_WRITE_MAX_16;
  933. break;
  934. case 32:
  935. tmp |= DMA_WRITE_MAX_32;
  936. break;
  937. case 64:
  938. tmp |= DMA_WRITE_MAX_64;
  939. break;
  940. case 128:
  941. tmp |= DMA_WRITE_MAX_128;
  942. break;
  943. default:
  944. printk(KERN_INFO " Cache line size %i not "
  945. "supported, PCI write and invalidate "
  946. "disabled\n", SMP_CACHE_BYTES);
  947. ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
  948. pci_write_config_word(pdev, PCI_COMMAND,
  949. ap->pci_command);
  950. }
  951. }
  952. }
  953. #ifdef __sparc__
  954. /*
  955. * On this platform, we know what the best dma settings
  956. * are. We use 64-byte maximum bursts, because if we
  957. * burst larger than the cache line size (or even cross
  958. * a 64byte boundary in a single burst) the UltraSparc
  959. * PCI controller will disconnect at 64-byte multiples.
  960. *
  961. * Read-multiple will be properly enabled above, and when
  962. * set will give the PCI controller proper hints about
  963. * prefetching.
  964. */
  965. tmp &= ~DMA_READ_WRITE_MASK;
  966. tmp |= DMA_READ_MAX_64;
  967. tmp |= DMA_WRITE_MAX_64;
  968. #endif
  969. #ifdef __alpha__
  970. tmp &= ~DMA_READ_WRITE_MASK;
  971. tmp |= DMA_READ_MAX_128;
  972. /*
  973. * All the docs say MUST NOT. Well, I did.
  974. * Nothing terrible happens, if we load wrong size.
  975. * Bit w&i still works better!
  976. */
  977. tmp |= DMA_WRITE_MAX_128;
  978. #endif
  979. writel(tmp, &regs->PciState);
  980. #if 0
  981. /*
  982. * The Host PCI bus controller driver has to set FBB.
  983. * If all devices on that PCI bus support FBB, then the controller
  984. * can enable FBB support in the Host PCI Bus controller (or on
  985. * the PCI-PCI bridge if that applies).
  986. * -ggg
  987. */
  988. /*
  989. * I have received reports from people having problems when this
  990. * bit is enabled.
  991. */
  992. if (!(ap->pci_command & PCI_COMMAND_FAST_BACK)) {
  993. printk(KERN_INFO " Enabling PCI Fast Back to Back\n");
  994. ap->pci_command |= PCI_COMMAND_FAST_BACK;
  995. pci_write_config_word(pdev, PCI_COMMAND, ap->pci_command);
  996. }
  997. #endif
  998. /*
  999. * Configure DMA attributes.
  1000. */
  1001. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  1002. ap->pci_using_dac = 1;
  1003. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  1004. ap->pci_using_dac = 0;
  1005. } else {
  1006. ecode = -ENODEV;
  1007. goto init_error;
  1008. }
  1009. /*
  1010. * Initialize the generic info block and the command+event rings
  1011. * and the control blocks for the transmit and receive rings
  1012. * as they need to be setup once and for all.
  1013. */
  1014. if (!(info = pci_alloc_consistent(ap->pdev, sizeof(struct ace_info),
  1015. &ap->info_dma))) {
  1016. ecode = -EAGAIN;
  1017. goto init_error;
  1018. }
  1019. ap->info = info;
  1020. /*
  1021. * Get the memory for the skb rings.
  1022. */
  1023. if (!(ap->skb = kmalloc(sizeof(struct ace_skb), GFP_KERNEL))) {
  1024. ecode = -EAGAIN;
  1025. goto init_error;
  1026. }
  1027. ecode = request_irq(pdev->irq, ace_interrupt, IRQF_SHARED,
  1028. DRV_NAME, dev);
  1029. if (ecode) {
  1030. printk(KERN_WARNING "%s: Requested IRQ %d is busy\n",
  1031. DRV_NAME, pdev->irq);
  1032. goto init_error;
  1033. } else
  1034. dev->irq = pdev->irq;
  1035. #ifdef INDEX_DEBUG
  1036. spin_lock_init(&ap->debug_lock);
  1037. ap->last_tx = ACE_TX_RING_ENTRIES(ap) - 1;
  1038. ap->last_std_rx = 0;
  1039. ap->last_mini_rx = 0;
  1040. #endif
  1041. memset(ap->info, 0, sizeof(struct ace_info));
  1042. memset(ap->skb, 0, sizeof(struct ace_skb));
  1043. ecode = ace_load_firmware(dev);
  1044. if (ecode)
  1045. goto init_error;
  1046. ap->fw_running = 0;
  1047. tmp_ptr = ap->info_dma;
  1048. writel(tmp_ptr >> 32, &regs->InfoPtrHi);
  1049. writel(tmp_ptr & 0xffffffff, &regs->InfoPtrLo);
  1050. memset(ap->evt_ring, 0, EVT_RING_ENTRIES * sizeof(struct event));
  1051. set_aceaddr(&info->evt_ctrl.rngptr, ap->evt_ring_dma);
  1052. info->evt_ctrl.flags = 0;
  1053. *(ap->evt_prd) = 0;
  1054. wmb();
  1055. set_aceaddr(&info->evt_prd_ptr, ap->evt_prd_dma);
  1056. writel(0, &regs->EvtCsm);
  1057. set_aceaddr(&info->cmd_ctrl.rngptr, 0x100);
  1058. info->cmd_ctrl.flags = 0;
  1059. info->cmd_ctrl.max_len = 0;
  1060. for (i = 0; i < CMD_RING_ENTRIES; i++)
  1061. writel(0, &regs->CmdRng[i]);
  1062. writel(0, &regs->CmdPrd);
  1063. writel(0, &regs->CmdCsm);
  1064. tmp_ptr = ap->info_dma;
  1065. tmp_ptr += (unsigned long) &(((struct ace_info *)0)->s.stats);
  1066. set_aceaddr(&info->stats2_ptr, (dma_addr_t) tmp_ptr);
  1067. set_aceaddr(&info->rx_std_ctrl.rngptr, ap->rx_ring_base_dma);
  1068. info->rx_std_ctrl.max_len = ACE_STD_BUFSIZE;
  1069. info->rx_std_ctrl.flags =
  1070. RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | RCB_FLG_VLAN_ASSIST;
  1071. memset(ap->rx_std_ring, 0,
  1072. RX_STD_RING_ENTRIES * sizeof(struct rx_desc));
  1073. for (i = 0; i < RX_STD_RING_ENTRIES; i++)
  1074. ap->rx_std_ring[i].flags = BD_FLG_TCP_UDP_SUM;
  1075. ap->rx_std_skbprd = 0;
  1076. atomic_set(&ap->cur_rx_bufs, 0);
  1077. set_aceaddr(&info->rx_jumbo_ctrl.rngptr,
  1078. (ap->rx_ring_base_dma +
  1079. (sizeof(struct rx_desc) * RX_STD_RING_ENTRIES)));
  1080. info->rx_jumbo_ctrl.max_len = 0;
  1081. info->rx_jumbo_ctrl.flags =
  1082. RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | RCB_FLG_VLAN_ASSIST;
  1083. memset(ap->rx_jumbo_ring, 0,
  1084. RX_JUMBO_RING_ENTRIES * sizeof(struct rx_desc));
  1085. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++)
  1086. ap->rx_jumbo_ring[i].flags = BD_FLG_TCP_UDP_SUM | BD_FLG_JUMBO;
  1087. ap->rx_jumbo_skbprd = 0;
  1088. atomic_set(&ap->cur_jumbo_bufs, 0);
  1089. memset(ap->rx_mini_ring, 0,
  1090. RX_MINI_RING_ENTRIES * sizeof(struct rx_desc));
  1091. if (ap->version >= 2) {
  1092. set_aceaddr(&info->rx_mini_ctrl.rngptr,
  1093. (ap->rx_ring_base_dma +
  1094. (sizeof(struct rx_desc) *
  1095. (RX_STD_RING_ENTRIES +
  1096. RX_JUMBO_RING_ENTRIES))));
  1097. info->rx_mini_ctrl.max_len = ACE_MINI_SIZE;
  1098. info->rx_mini_ctrl.flags =
  1099. RCB_FLG_TCP_UDP_SUM|RCB_FLG_NO_PSEUDO_HDR|RCB_FLG_VLAN_ASSIST;
  1100. for (i = 0; i < RX_MINI_RING_ENTRIES; i++)
  1101. ap->rx_mini_ring[i].flags =
  1102. BD_FLG_TCP_UDP_SUM | BD_FLG_MINI;
  1103. } else {
  1104. set_aceaddr(&info->rx_mini_ctrl.rngptr, 0);
  1105. info->rx_mini_ctrl.flags = RCB_FLG_RNG_DISABLE;
  1106. info->rx_mini_ctrl.max_len = 0;
  1107. }
  1108. ap->rx_mini_skbprd = 0;
  1109. atomic_set(&ap->cur_mini_bufs, 0);
  1110. set_aceaddr(&info->rx_return_ctrl.rngptr,
  1111. (ap->rx_ring_base_dma +
  1112. (sizeof(struct rx_desc) *
  1113. (RX_STD_RING_ENTRIES +
  1114. RX_JUMBO_RING_ENTRIES +
  1115. RX_MINI_RING_ENTRIES))));
  1116. info->rx_return_ctrl.flags = 0;
  1117. info->rx_return_ctrl.max_len = RX_RETURN_RING_ENTRIES;
  1118. memset(ap->rx_return_ring, 0,
  1119. RX_RETURN_RING_ENTRIES * sizeof(struct rx_desc));
  1120. set_aceaddr(&info->rx_ret_prd_ptr, ap->rx_ret_prd_dma);
  1121. *(ap->rx_ret_prd) = 0;
  1122. writel(TX_RING_BASE, &regs->WinBase);
  1123. if (ACE_IS_TIGON_I(ap)) {
  1124. ap->tx_ring = (__force struct tx_desc *) regs->Window;
  1125. for (i = 0; i < (TIGON_I_TX_RING_ENTRIES
  1126. * sizeof(struct tx_desc)) / sizeof(u32); i++)
  1127. writel(0, (__force void __iomem *)ap->tx_ring + i * 4);
  1128. set_aceaddr(&info->tx_ctrl.rngptr, TX_RING_BASE);
  1129. } else {
  1130. memset(ap->tx_ring, 0,
  1131. MAX_TX_RING_ENTRIES * sizeof(struct tx_desc));
  1132. set_aceaddr(&info->tx_ctrl.rngptr, ap->tx_ring_dma);
  1133. }
  1134. info->tx_ctrl.max_len = ACE_TX_RING_ENTRIES(ap);
  1135. tmp = RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | RCB_FLG_VLAN_ASSIST;
  1136. /*
  1137. * The Tigon I does not like having the TX ring in host memory ;-(
  1138. */
  1139. if (!ACE_IS_TIGON_I(ap))
  1140. tmp |= RCB_FLG_TX_HOST_RING;
  1141. #if TX_COAL_INTS_ONLY
  1142. tmp |= RCB_FLG_COAL_INT_ONLY;
  1143. #endif
  1144. info->tx_ctrl.flags = tmp;
  1145. set_aceaddr(&info->tx_csm_ptr, ap->tx_csm_dma);
  1146. /*
  1147. * Potential item for tuning parameter
  1148. */
  1149. #if 0 /* NO */
  1150. writel(DMA_THRESH_16W, &regs->DmaReadCfg);
  1151. writel(DMA_THRESH_16W, &regs->DmaWriteCfg);
  1152. #else
  1153. writel(DMA_THRESH_8W, &regs->DmaReadCfg);
  1154. writel(DMA_THRESH_8W, &regs->DmaWriteCfg);
  1155. #endif
  1156. writel(0, &regs->MaskInt);
  1157. writel(1, &regs->IfIdx);
  1158. #if 0
  1159. /*
  1160. * McKinley boxes do not like us fiddling with AssistState
  1161. * this early
  1162. */
  1163. writel(1, &regs->AssistState);
  1164. #endif
  1165. writel(DEF_STAT, &regs->TuneStatTicks);
  1166. writel(DEF_TRACE, &regs->TuneTrace);
  1167. ace_set_rxtx_parms(dev, 0);
  1168. if (board_idx == BOARD_IDX_OVERFLOW) {
  1169. printk(KERN_WARNING "%s: more than %i NICs detected, "
  1170. "ignoring module parameters!\n",
  1171. ap->name, ACE_MAX_MOD_PARMS);
  1172. } else if (board_idx >= 0) {
  1173. if (tx_coal_tick[board_idx])
  1174. writel(tx_coal_tick[board_idx],
  1175. &regs->TuneTxCoalTicks);
  1176. if (max_tx_desc[board_idx])
  1177. writel(max_tx_desc[board_idx], &regs->TuneMaxTxDesc);
  1178. if (rx_coal_tick[board_idx])
  1179. writel(rx_coal_tick[board_idx],
  1180. &regs->TuneRxCoalTicks);
  1181. if (max_rx_desc[board_idx])
  1182. writel(max_rx_desc[board_idx], &regs->TuneMaxRxDesc);
  1183. if (trace[board_idx])
  1184. writel(trace[board_idx], &regs->TuneTrace);
  1185. if ((tx_ratio[board_idx] > 0) && (tx_ratio[board_idx] < 64))
  1186. writel(tx_ratio[board_idx], &regs->TxBufRat);
  1187. }
  1188. /*
  1189. * Default link parameters
  1190. */
  1191. tmp = LNK_ENABLE | LNK_FULL_DUPLEX | LNK_1000MB | LNK_100MB |
  1192. LNK_10MB | LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL | LNK_NEGOTIATE;
  1193. if(ap->version >= 2)
  1194. tmp |= LNK_TX_FLOW_CTL_Y;
  1195. /*
  1196. * Override link default parameters
  1197. */
  1198. if ((board_idx >= 0) && link_state[board_idx]) {
  1199. int option = link_state[board_idx];
  1200. tmp = LNK_ENABLE;
  1201. if (option & 0x01) {
  1202. printk(KERN_INFO "%s: Setting half duplex link\n",
  1203. ap->name);
  1204. tmp &= ~LNK_FULL_DUPLEX;
  1205. }
  1206. if (option & 0x02)
  1207. tmp &= ~LNK_NEGOTIATE;
  1208. if (option & 0x10)
  1209. tmp |= LNK_10MB;
  1210. if (option & 0x20)
  1211. tmp |= LNK_100MB;
  1212. if (option & 0x40)
  1213. tmp |= LNK_1000MB;
  1214. if ((option & 0x70) == 0) {
  1215. printk(KERN_WARNING "%s: No media speed specified, "
  1216. "forcing auto negotiation\n", ap->name);
  1217. tmp |= LNK_NEGOTIATE | LNK_1000MB |
  1218. LNK_100MB | LNK_10MB;
  1219. }
  1220. if ((option & 0x100) == 0)
  1221. tmp |= LNK_NEG_FCTL;
  1222. else
  1223. printk(KERN_INFO "%s: Disabling flow control "
  1224. "negotiation\n", ap->name);
  1225. if (option & 0x200)
  1226. tmp |= LNK_RX_FLOW_CTL_Y;
  1227. if ((option & 0x400) && (ap->version >= 2)) {
  1228. printk(KERN_INFO "%s: Enabling TX flow control\n",
  1229. ap->name);
  1230. tmp |= LNK_TX_FLOW_CTL_Y;
  1231. }
  1232. }
  1233. ap->link = tmp;
  1234. writel(tmp, &regs->TuneLink);
  1235. if (ap->version >= 2)
  1236. writel(tmp, &regs->TuneFastLink);
  1237. writel(ap->firmware_start, &regs->Pc);
  1238. writel(0, &regs->Mb0Lo);
  1239. /*
  1240. * Set tx_csm before we start receiving interrupts, otherwise
  1241. * the interrupt handler might think it is supposed to process
  1242. * tx ints before we are up and running, which may cause a null
  1243. * pointer access in the int handler.
  1244. */
  1245. ap->cur_rx = 0;
  1246. ap->tx_prd = *(ap->tx_csm) = ap->tx_ret_csm = 0;
  1247. wmb();
  1248. ace_set_txprd(regs, ap, 0);
  1249. writel(0, &regs->RxRetCsm);
  1250. /*
  1251. * Enable DMA engine now.
  1252. * If we do this sooner, Mckinley box pukes.
  1253. * I assume it's because Tigon II DMA engine wants to check
  1254. * *something* even before the CPU is started.
  1255. */
  1256. writel(1, &regs->AssistState); /* enable DMA */
  1257. /*
  1258. * Start the NIC CPU
  1259. */
  1260. writel(readl(&regs->CpuCtrl) & ~(CPU_HALT|CPU_TRACE), &regs->CpuCtrl);
  1261. readl(&regs->CpuCtrl);
  1262. /*
  1263. * Wait for the firmware to spin up - max 3 seconds.
  1264. */
  1265. myjif = jiffies + 3 * HZ;
  1266. while (time_before(jiffies, myjif) && !ap->fw_running)
  1267. cpu_relax();
  1268. if (!ap->fw_running) {
  1269. printk(KERN_ERR "%s: Firmware NOT running!\n", ap->name);
  1270. ace_dump_trace(ap);
  1271. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  1272. readl(&regs->CpuCtrl);
  1273. /* aman@sgi.com - account for badly behaving firmware/NIC:
  1274. * - have observed that the NIC may continue to generate
  1275. * interrupts for some reason; attempt to stop it - halt
  1276. * second CPU for Tigon II cards, and also clear Mb0
  1277. * - if we're a module, we'll fail to load if this was
  1278. * the only GbE card in the system => if the kernel does
  1279. * see an interrupt from the NIC, code to handle it is
  1280. * gone and OOps! - so free_irq also
  1281. */
  1282. if (ap->version >= 2)
  1283. writel(readl(&regs->CpuBCtrl) | CPU_HALT,
  1284. &regs->CpuBCtrl);
  1285. writel(0, &regs->Mb0Lo);
  1286. readl(&regs->Mb0Lo);
  1287. ecode = -EBUSY;
  1288. goto init_error;
  1289. }
  1290. /*
  1291. * We load the ring here as there seem to be no way to tell the
  1292. * firmware to wipe the ring without re-initializing it.
  1293. */
  1294. if (!test_and_set_bit(0, &ap->std_refill_busy))
  1295. ace_load_std_rx_ring(dev, RX_RING_SIZE);
  1296. else
  1297. printk(KERN_ERR "%s: Someone is busy refilling the RX ring\n",
  1298. ap->name);
  1299. if (ap->version >= 2) {
  1300. if (!test_and_set_bit(0, &ap->mini_refill_busy))
  1301. ace_load_mini_rx_ring(dev, RX_MINI_SIZE);
  1302. else
  1303. printk(KERN_ERR "%s: Someone is busy refilling "
  1304. "the RX mini ring\n", ap->name);
  1305. }
  1306. return 0;
  1307. init_error:
  1308. ace_init_cleanup(dev);
  1309. return ecode;
  1310. }
  1311. static void ace_set_rxtx_parms(struct net_device *dev, int jumbo)
  1312. {
  1313. struct ace_private *ap = netdev_priv(dev);
  1314. struct ace_regs __iomem *regs = ap->regs;
  1315. int board_idx = ap->board_idx;
  1316. if (board_idx >= 0) {
  1317. if (!jumbo) {
  1318. if (!tx_coal_tick[board_idx])
  1319. writel(DEF_TX_COAL, &regs->TuneTxCoalTicks);
  1320. if (!max_tx_desc[board_idx])
  1321. writel(DEF_TX_MAX_DESC, &regs->TuneMaxTxDesc);
  1322. if (!rx_coal_tick[board_idx])
  1323. writel(DEF_RX_COAL, &regs->TuneRxCoalTicks);
  1324. if (!max_rx_desc[board_idx])
  1325. writel(DEF_RX_MAX_DESC, &regs->TuneMaxRxDesc);
  1326. if (!tx_ratio[board_idx])
  1327. writel(DEF_TX_RATIO, &regs->TxBufRat);
  1328. } else {
  1329. if (!tx_coal_tick[board_idx])
  1330. writel(DEF_JUMBO_TX_COAL,
  1331. &regs->TuneTxCoalTicks);
  1332. if (!max_tx_desc[board_idx])
  1333. writel(DEF_JUMBO_TX_MAX_DESC,
  1334. &regs->TuneMaxTxDesc);
  1335. if (!rx_coal_tick[board_idx])
  1336. writel(DEF_JUMBO_RX_COAL,
  1337. &regs->TuneRxCoalTicks);
  1338. if (!max_rx_desc[board_idx])
  1339. writel(DEF_JUMBO_RX_MAX_DESC,
  1340. &regs->TuneMaxRxDesc);
  1341. if (!tx_ratio[board_idx])
  1342. writel(DEF_JUMBO_TX_RATIO, &regs->TxBufRat);
  1343. }
  1344. }
  1345. }
  1346. static void ace_watchdog(struct net_device *data)
  1347. {
  1348. struct net_device *dev = data;
  1349. struct ace_private *ap = netdev_priv(dev);
  1350. struct ace_regs __iomem *regs = ap->regs;
  1351. /*
  1352. * We haven't received a stats update event for more than 2.5
  1353. * seconds and there is data in the transmit queue, thus we
  1354. * assume the card is stuck.
  1355. */
  1356. if (*ap->tx_csm != ap->tx_ret_csm) {
  1357. printk(KERN_WARNING "%s: Transmitter is stuck, %08x\n",
  1358. dev->name, (unsigned int)readl(&regs->HostCtrl));
  1359. /* This can happen due to ieee flow control. */
  1360. } else {
  1361. printk(KERN_DEBUG "%s: BUG... transmitter died. Kicking it.\n",
  1362. dev->name);
  1363. #if 0
  1364. netif_wake_queue(dev);
  1365. #endif
  1366. }
  1367. }
  1368. static void ace_tasklet(unsigned long arg)
  1369. {
  1370. struct net_device *dev = (struct net_device *) arg;
  1371. struct ace_private *ap = netdev_priv(dev);
  1372. int cur_size;
  1373. cur_size = atomic_read(&ap->cur_rx_bufs);
  1374. if ((cur_size < RX_LOW_STD_THRES) &&
  1375. !test_and_set_bit(0, &ap->std_refill_busy)) {
  1376. #ifdef DEBUG
  1377. printk("refilling buffers (current %i)\n", cur_size);
  1378. #endif
  1379. ace_load_std_rx_ring(dev, RX_RING_SIZE - cur_size);
  1380. }
  1381. if (ap->version >= 2) {
  1382. cur_size = atomic_read(&ap->cur_mini_bufs);
  1383. if ((cur_size < RX_LOW_MINI_THRES) &&
  1384. !test_and_set_bit(0, &ap->mini_refill_busy)) {
  1385. #ifdef DEBUG
  1386. printk("refilling mini buffers (current %i)\n",
  1387. cur_size);
  1388. #endif
  1389. ace_load_mini_rx_ring(dev, RX_MINI_SIZE - cur_size);
  1390. }
  1391. }
  1392. cur_size = atomic_read(&ap->cur_jumbo_bufs);
  1393. if (ap->jumbo && (cur_size < RX_LOW_JUMBO_THRES) &&
  1394. !test_and_set_bit(0, &ap->jumbo_refill_busy)) {
  1395. #ifdef DEBUG
  1396. printk("refilling jumbo buffers (current %i)\n", cur_size);
  1397. #endif
  1398. ace_load_jumbo_rx_ring(dev, RX_JUMBO_SIZE - cur_size);
  1399. }
  1400. ap->tasklet_pending = 0;
  1401. }
  1402. /*
  1403. * Copy the contents of the NIC's trace buffer to kernel memory.
  1404. */
  1405. static void ace_dump_trace(struct ace_private *ap)
  1406. {
  1407. #if 0
  1408. if (!ap->trace_buf)
  1409. if (!(ap->trace_buf = kmalloc(ACE_TRACE_SIZE, GFP_KERNEL)))
  1410. return;
  1411. #endif
  1412. }
  1413. /*
  1414. * Load the standard rx ring.
  1415. *
  1416. * Loading rings is safe without holding the spin lock since this is
  1417. * done only before the device is enabled, thus no interrupts are
  1418. * generated and by the interrupt handler/tasklet handler.
  1419. */
  1420. static void ace_load_std_rx_ring(struct net_device *dev, int nr_bufs)
  1421. {
  1422. struct ace_private *ap = netdev_priv(dev);
  1423. struct ace_regs __iomem *regs = ap->regs;
  1424. short i, idx;
  1425. prefetchw(&ap->cur_rx_bufs);
  1426. idx = ap->rx_std_skbprd;
  1427. for (i = 0; i < nr_bufs; i++) {
  1428. struct sk_buff *skb;
  1429. struct rx_desc *rd;
  1430. dma_addr_t mapping;
  1431. skb = netdev_alloc_skb_ip_align(dev, ACE_STD_BUFSIZE);
  1432. if (!skb)
  1433. break;
  1434. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1435. offset_in_page(skb->data),
  1436. ACE_STD_BUFSIZE,
  1437. PCI_DMA_FROMDEVICE);
  1438. ap->skb->rx_std_skbuff[idx].skb = skb;
  1439. dma_unmap_addr_set(&ap->skb->rx_std_skbuff[idx],
  1440. mapping, mapping);
  1441. rd = &ap->rx_std_ring[idx];
  1442. set_aceaddr(&rd->addr, mapping);
  1443. rd->size = ACE_STD_BUFSIZE;
  1444. rd->idx = idx;
  1445. idx = (idx + 1) % RX_STD_RING_ENTRIES;
  1446. }
  1447. if (!i)
  1448. goto error_out;
  1449. atomic_add(i, &ap->cur_rx_bufs);
  1450. ap->rx_std_skbprd = idx;
  1451. if (ACE_IS_TIGON_I(ap)) {
  1452. struct cmd cmd;
  1453. cmd.evt = C_SET_RX_PRD_IDX;
  1454. cmd.code = 0;
  1455. cmd.idx = ap->rx_std_skbprd;
  1456. ace_issue_cmd(regs, &cmd);
  1457. } else {
  1458. writel(idx, &regs->RxStdPrd);
  1459. wmb();
  1460. }
  1461. out:
  1462. clear_bit(0, &ap->std_refill_busy);
  1463. return;
  1464. error_out:
  1465. printk(KERN_INFO "Out of memory when allocating "
  1466. "standard receive buffers\n");
  1467. goto out;
  1468. }
  1469. static void ace_load_mini_rx_ring(struct net_device *dev, int nr_bufs)
  1470. {
  1471. struct ace_private *ap = netdev_priv(dev);
  1472. struct ace_regs __iomem *regs = ap->regs;
  1473. short i, idx;
  1474. prefetchw(&ap->cur_mini_bufs);
  1475. idx = ap->rx_mini_skbprd;
  1476. for (i = 0; i < nr_bufs; i++) {
  1477. struct sk_buff *skb;
  1478. struct rx_desc *rd;
  1479. dma_addr_t mapping;
  1480. skb = netdev_alloc_skb_ip_align(dev, ACE_MINI_BUFSIZE);
  1481. if (!skb)
  1482. break;
  1483. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1484. offset_in_page(skb->data),
  1485. ACE_MINI_BUFSIZE,
  1486. PCI_DMA_FROMDEVICE);
  1487. ap->skb->rx_mini_skbuff[idx].skb = skb;
  1488. dma_unmap_addr_set(&ap->skb->rx_mini_skbuff[idx],
  1489. mapping, mapping);
  1490. rd = &ap->rx_mini_ring[idx];
  1491. set_aceaddr(&rd->addr, mapping);
  1492. rd->size = ACE_MINI_BUFSIZE;
  1493. rd->idx = idx;
  1494. idx = (idx + 1) % RX_MINI_RING_ENTRIES;
  1495. }
  1496. if (!i)
  1497. goto error_out;
  1498. atomic_add(i, &ap->cur_mini_bufs);
  1499. ap->rx_mini_skbprd = idx;
  1500. writel(idx, &regs->RxMiniPrd);
  1501. wmb();
  1502. out:
  1503. clear_bit(0, &ap->mini_refill_busy);
  1504. return;
  1505. error_out:
  1506. printk(KERN_INFO "Out of memory when allocating "
  1507. "mini receive buffers\n");
  1508. goto out;
  1509. }
  1510. /*
  1511. * Load the jumbo rx ring, this may happen at any time if the MTU
  1512. * is changed to a value > 1500.
  1513. */
  1514. static void ace_load_jumbo_rx_ring(struct net_device *dev, int nr_bufs)
  1515. {
  1516. struct ace_private *ap = netdev_priv(dev);
  1517. struct ace_regs __iomem *regs = ap->regs;
  1518. short i, idx;
  1519. idx = ap->rx_jumbo_skbprd;
  1520. for (i = 0; i < nr_bufs; i++) {
  1521. struct sk_buff *skb;
  1522. struct rx_desc *rd;
  1523. dma_addr_t mapping;
  1524. skb = netdev_alloc_skb_ip_align(dev, ACE_JUMBO_BUFSIZE);
  1525. if (!skb)
  1526. break;
  1527. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1528. offset_in_page(skb->data),
  1529. ACE_JUMBO_BUFSIZE,
  1530. PCI_DMA_FROMDEVICE);
  1531. ap->skb->rx_jumbo_skbuff[idx].skb = skb;
  1532. dma_unmap_addr_set(&ap->skb->rx_jumbo_skbuff[idx],
  1533. mapping, mapping);
  1534. rd = &ap->rx_jumbo_ring[idx];
  1535. set_aceaddr(&rd->addr, mapping);
  1536. rd->size = ACE_JUMBO_BUFSIZE;
  1537. rd->idx = idx;
  1538. idx = (idx + 1) % RX_JUMBO_RING_ENTRIES;
  1539. }
  1540. if (!i)
  1541. goto error_out;
  1542. atomic_add(i, &ap->cur_jumbo_bufs);
  1543. ap->rx_jumbo_skbprd = idx;
  1544. if (ACE_IS_TIGON_I(ap)) {
  1545. struct cmd cmd;
  1546. cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
  1547. cmd.code = 0;
  1548. cmd.idx = ap->rx_jumbo_skbprd;
  1549. ace_issue_cmd(regs, &cmd);
  1550. } else {
  1551. writel(idx, &regs->RxJumboPrd);
  1552. wmb();
  1553. }
  1554. out:
  1555. clear_bit(0, &ap->jumbo_refill_busy);
  1556. return;
  1557. error_out:
  1558. if (net_ratelimit())
  1559. printk(KERN_INFO "Out of memory when allocating "
  1560. "jumbo receive buffers\n");
  1561. goto out;
  1562. }
  1563. /*
  1564. * All events are considered to be slow (RX/TX ints do not generate
  1565. * events) and are handled here, outside the main interrupt handler,
  1566. * to reduce the size of the handler.
  1567. */
  1568. static u32 ace_handle_event(struct net_device *dev, u32 evtcsm, u32 evtprd)
  1569. {
  1570. struct ace_private *ap;
  1571. ap = netdev_priv(dev);
  1572. while (evtcsm != evtprd) {
  1573. switch (ap->evt_ring[evtcsm].evt) {
  1574. case E_FW_RUNNING:
  1575. printk(KERN_INFO "%s: Firmware up and running\n",
  1576. ap->name);
  1577. ap->fw_running = 1;
  1578. wmb();
  1579. break;
  1580. case E_STATS_UPDATED:
  1581. break;
  1582. case E_LNK_STATE:
  1583. {
  1584. u16 code = ap->evt_ring[evtcsm].code;
  1585. switch (code) {
  1586. case E_C_LINK_UP:
  1587. {
  1588. u32 state = readl(&ap->regs->GigLnkState);
  1589. printk(KERN_WARNING "%s: Optical link UP "
  1590. "(%s Duplex, Flow Control: %s%s)\n",
  1591. ap->name,
  1592. state & LNK_FULL_DUPLEX ? "Full":"Half",
  1593. state & LNK_TX_FLOW_CTL_Y ? "TX " : "",
  1594. state & LNK_RX_FLOW_CTL_Y ? "RX" : "");
  1595. break;
  1596. }
  1597. case E_C_LINK_DOWN:
  1598. printk(KERN_WARNING "%s: Optical link DOWN\n",
  1599. ap->name);
  1600. break;
  1601. case E_C_LINK_10_100:
  1602. printk(KERN_WARNING "%s: 10/100BaseT link "
  1603. "UP\n", ap->name);
  1604. break;
  1605. default:
  1606. printk(KERN_ERR "%s: Unknown optical link "
  1607. "state %02x\n", ap->name, code);
  1608. }
  1609. break;
  1610. }
  1611. case E_ERROR:
  1612. switch(ap->evt_ring[evtcsm].code) {
  1613. case E_C_ERR_INVAL_CMD:
  1614. printk(KERN_ERR "%s: invalid command error\n",
  1615. ap->name);
  1616. break;
  1617. case E_C_ERR_UNIMP_CMD:
  1618. printk(KERN_ERR "%s: unimplemented command "
  1619. "error\n", ap->name);
  1620. break;
  1621. case E_C_ERR_BAD_CFG:
  1622. printk(KERN_ERR "%s: bad config error\n",
  1623. ap->name);
  1624. break;
  1625. default:
  1626. printk(KERN_ERR "%s: unknown error %02x\n",
  1627. ap->name, ap->evt_ring[evtcsm].code);
  1628. }
  1629. break;
  1630. case E_RESET_JUMBO_RNG:
  1631. {
  1632. int i;
  1633. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
  1634. if (ap->skb->rx_jumbo_skbuff[i].skb) {
  1635. ap->rx_jumbo_ring[i].size = 0;
  1636. set_aceaddr(&ap->rx_jumbo_ring[i].addr, 0);
  1637. dev_kfree_skb(ap->skb->rx_jumbo_skbuff[i].skb);
  1638. ap->skb->rx_jumbo_skbuff[i].skb = NULL;
  1639. }
  1640. }
  1641. if (ACE_IS_TIGON_I(ap)) {
  1642. struct cmd cmd;
  1643. cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
  1644. cmd.code = 0;
  1645. cmd.idx = 0;
  1646. ace_issue_cmd(ap->regs, &cmd);
  1647. } else {
  1648. writel(0, &((ap->regs)->RxJumboPrd));
  1649. wmb();
  1650. }
  1651. ap->jumbo = 0;
  1652. ap->rx_jumbo_skbprd = 0;
  1653. printk(KERN_INFO "%s: Jumbo ring flushed\n",
  1654. ap->name);
  1655. clear_bit(0, &ap->jumbo_refill_busy);
  1656. break;
  1657. }
  1658. default:
  1659. printk(KERN_ERR "%s: Unhandled event 0x%02x\n",
  1660. ap->name, ap->evt_ring[evtcsm].evt);
  1661. }
  1662. evtcsm = (evtcsm + 1) % EVT_RING_ENTRIES;
  1663. }
  1664. return evtcsm;
  1665. }
  1666. static void ace_rx_int(struct net_device *dev, u32 rxretprd, u32 rxretcsm)
  1667. {
  1668. struct ace_private *ap = netdev_priv(dev);
  1669. u32 idx;
  1670. int mini_count = 0, std_count = 0;
  1671. idx = rxretcsm;
  1672. prefetchw(&ap->cur_rx_bufs);
  1673. prefetchw(&ap->cur_mini_bufs);
  1674. while (idx != rxretprd) {
  1675. struct ring_info *rip;
  1676. struct sk_buff *skb;
  1677. struct rx_desc *retdesc;
  1678. u32 skbidx;
  1679. int bd_flags, desc_type, mapsize;
  1680. u16 csum;
  1681. /* make sure the rx descriptor isn't read before rxretprd */
  1682. if (idx == rxretcsm)
  1683. rmb();
  1684. retdesc = &ap->rx_return_ring[idx];
  1685. skbidx = retdesc->idx;
  1686. bd_flags = retdesc->flags;
  1687. desc_type = bd_flags & (BD_FLG_JUMBO | BD_FLG_MINI);
  1688. switch(desc_type) {
  1689. /*
  1690. * Normal frames do not have any flags set
  1691. *
  1692. * Mini and normal frames arrive frequently,
  1693. * so use a local counter to avoid doing
  1694. * atomic operations for each packet arriving.
  1695. */
  1696. case 0:
  1697. rip = &ap->skb->rx_std_skbuff[skbidx];
  1698. mapsize = ACE_STD_BUFSIZE;
  1699. std_count++;
  1700. break;
  1701. case BD_FLG_JUMBO:
  1702. rip = &ap->skb->rx_jumbo_skbuff[skbidx];
  1703. mapsize = ACE_JUMBO_BUFSIZE;
  1704. atomic_dec(&ap->cur_jumbo_bufs);
  1705. break;
  1706. case BD_FLG_MINI:
  1707. rip = &ap->skb->rx_mini_skbuff[skbidx];
  1708. mapsize = ACE_MINI_BUFSIZE;
  1709. mini_count++;
  1710. break;
  1711. default:
  1712. printk(KERN_INFO "%s: unknown frame type (0x%02x) "
  1713. "returned by NIC\n", dev->name,
  1714. retdesc->flags);
  1715. goto error;
  1716. }
  1717. skb = rip->skb;
  1718. rip->skb = NULL;
  1719. pci_unmap_page(ap->pdev,
  1720. dma_unmap_addr(rip, mapping),
  1721. mapsize,
  1722. PCI_DMA_FROMDEVICE);
  1723. skb_put(skb, retdesc->size);
  1724. /*
  1725. * Fly baby, fly!
  1726. */
  1727. csum = retdesc->tcp_udp_csum;
  1728. skb->protocol = eth_type_trans(skb, dev);
  1729. /*
  1730. * Instead of forcing the poor tigon mips cpu to calculate
  1731. * pseudo hdr checksum, we do this ourselves.
  1732. */
  1733. if (bd_flags & BD_FLG_TCP_UDP_SUM) {
  1734. skb->csum = htons(csum);
  1735. skb->ip_summed = CHECKSUM_COMPLETE;
  1736. } else {
  1737. skb_checksum_none_assert(skb);
  1738. }
  1739. /* send it up */
  1740. if ((bd_flags & BD_FLG_VLAN_TAG))
  1741. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), retdesc->vlan);
  1742. netif_rx(skb);
  1743. dev->stats.rx_packets++;
  1744. dev->stats.rx_bytes += retdesc->size;
  1745. idx = (idx + 1) % RX_RETURN_RING_ENTRIES;
  1746. }
  1747. atomic_sub(std_count, &ap->cur_rx_bufs);
  1748. if (!ACE_IS_TIGON_I(ap))
  1749. atomic_sub(mini_count, &ap->cur_mini_bufs);
  1750. out:
  1751. /*
  1752. * According to the documentation RxRetCsm is obsolete with
  1753. * the 12.3.x Firmware - my Tigon I NICs seem to disagree!
  1754. */
  1755. if (ACE_IS_TIGON_I(ap)) {
  1756. writel(idx, &ap->regs->RxRetCsm);
  1757. }
  1758. ap->cur_rx = idx;
  1759. return;
  1760. error:
  1761. idx = rxretprd;
  1762. goto out;
  1763. }
  1764. static inline void ace_tx_int(struct net_device *dev,
  1765. u32 txcsm, u32 idx)
  1766. {
  1767. struct ace_private *ap = netdev_priv(dev);
  1768. do {
  1769. struct sk_buff *skb;
  1770. struct tx_ring_info *info;
  1771. info = ap->skb->tx_skbuff + idx;
  1772. skb = info->skb;
  1773. if (dma_unmap_len(info, maplen)) {
  1774. pci_unmap_page(ap->pdev, dma_unmap_addr(info, mapping),
  1775. dma_unmap_len(info, maplen),
  1776. PCI_DMA_TODEVICE);
  1777. dma_unmap_len_set(info, maplen, 0);
  1778. }
  1779. if (skb) {
  1780. dev->stats.tx_packets++;
  1781. dev->stats.tx_bytes += skb->len;
  1782. dev_kfree_skb_irq(skb);
  1783. info->skb = NULL;
  1784. }
  1785. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  1786. } while (idx != txcsm);
  1787. if (netif_queue_stopped(dev))
  1788. netif_wake_queue(dev);
  1789. wmb();
  1790. ap->tx_ret_csm = txcsm;
  1791. /* So... tx_ret_csm is advanced _after_ check for device wakeup.
  1792. *
  1793. * We could try to make it before. In this case we would get
  1794. * the following race condition: hard_start_xmit on other cpu
  1795. * enters after we advanced tx_ret_csm and fills space,
  1796. * which we have just freed, so that we make illegal device wakeup.
  1797. * There is no good way to workaround this (at entry
  1798. * to ace_start_xmit detects this condition and prevents
  1799. * ring corruption, but it is not a good workaround.)
  1800. *
  1801. * When tx_ret_csm is advanced after, we wake up device _only_
  1802. * if we really have some space in ring (though the core doing
  1803. * hard_start_xmit can see full ring for some period and has to
  1804. * synchronize.) Superb.
  1805. * BUT! We get another subtle race condition. hard_start_xmit
  1806. * may think that ring is full between wakeup and advancing
  1807. * tx_ret_csm and will stop device instantly! It is not so bad.
  1808. * We are guaranteed that there is something in ring, so that
  1809. * the next irq will resume transmission. To speedup this we could
  1810. * mark descriptor, which closes ring with BD_FLG_COAL_NOW
  1811. * (see ace_start_xmit).
  1812. *
  1813. * Well, this dilemma exists in all lock-free devices.
  1814. * We, following scheme used in drivers by Donald Becker,
  1815. * select the least dangerous.
  1816. * --ANK
  1817. */
  1818. }
  1819. static irqreturn_t ace_interrupt(int irq, void *dev_id)
  1820. {
  1821. struct net_device *dev = (struct net_device *)dev_id;
  1822. struct ace_private *ap = netdev_priv(dev);
  1823. struct ace_regs __iomem *regs = ap->regs;
  1824. u32 idx;
  1825. u32 txcsm, rxretcsm, rxretprd;
  1826. u32 evtcsm, evtprd;
  1827. /*
  1828. * In case of PCI shared interrupts or spurious interrupts,
  1829. * we want to make sure it is actually our interrupt before
  1830. * spending any time in here.
  1831. */
  1832. if (!(readl(&regs->HostCtrl) & IN_INT))
  1833. return IRQ_NONE;
  1834. /*
  1835. * ACK intr now. Otherwise we will lose updates to rx_ret_prd,
  1836. * which happened _after_ rxretprd = *ap->rx_ret_prd; but before
  1837. * writel(0, &regs->Mb0Lo).
  1838. *
  1839. * "IRQ avoidance" recommended in docs applies to IRQs served
  1840. * threads and it is wrong even for that case.
  1841. */
  1842. writel(0, &regs->Mb0Lo);
  1843. readl(&regs->Mb0Lo);
  1844. /*
  1845. * There is no conflict between transmit handling in
  1846. * start_xmit and receive processing, thus there is no reason
  1847. * to take a spin lock for RX handling. Wait until we start
  1848. * working on the other stuff - hey we don't need a spin lock
  1849. * anymore.
  1850. */
  1851. rxretprd = *ap->rx_ret_prd;
  1852. rxretcsm = ap->cur_rx;
  1853. if (rxretprd != rxretcsm)
  1854. ace_rx_int(dev, rxretprd, rxretcsm);
  1855. txcsm = *ap->tx_csm;
  1856. idx = ap->tx_ret_csm;
  1857. if (txcsm != idx) {
  1858. /*
  1859. * If each skb takes only one descriptor this check degenerates
  1860. * to identity, because new space has just been opened.
  1861. * But if skbs are fragmented we must check that this index
  1862. * update releases enough of space, otherwise we just
  1863. * wait for device to make more work.
  1864. */
  1865. if (!tx_ring_full(ap, txcsm, ap->tx_prd))
  1866. ace_tx_int(dev, txcsm, idx);
  1867. }
  1868. evtcsm = readl(&regs->EvtCsm);
  1869. evtprd = *ap->evt_prd;
  1870. if (evtcsm != evtprd) {
  1871. evtcsm = ace_handle_event(dev, evtcsm, evtprd);
  1872. writel(evtcsm, &regs->EvtCsm);
  1873. }
  1874. /*
  1875. * This has to go last in the interrupt handler and run with
  1876. * the spin lock released ... what lock?
  1877. */
  1878. if (netif_running(dev)) {
  1879. int cur_size;
  1880. int run_tasklet = 0;
  1881. cur_size = atomic_read(&ap->cur_rx_bufs);
  1882. if (cur_size < RX_LOW_STD_THRES) {
  1883. if ((cur_size < RX_PANIC_STD_THRES) &&
  1884. !test_and_set_bit(0, &ap->std_refill_busy)) {
  1885. #ifdef DEBUG
  1886. printk("low on std buffers %i\n", cur_size);
  1887. #endif
  1888. ace_load_std_rx_ring(dev,
  1889. RX_RING_SIZE - cur_size);
  1890. } else
  1891. run_tasklet = 1;
  1892. }
  1893. if (!ACE_IS_TIGON_I(ap)) {
  1894. cur_size = atomic_read(&ap->cur_mini_bufs);
  1895. if (cur_size < RX_LOW_MINI_THRES) {
  1896. if ((cur_size < RX_PANIC_MINI_THRES) &&
  1897. !test_and_set_bit(0,
  1898. &ap->mini_refill_busy)) {
  1899. #ifdef DEBUG
  1900. printk("low on mini buffers %i\n",
  1901. cur_size);
  1902. #endif
  1903. ace_load_mini_rx_ring(dev,
  1904. RX_MINI_SIZE - cur_size);
  1905. } else
  1906. run_tasklet = 1;
  1907. }
  1908. }
  1909. if (ap->jumbo) {
  1910. cur_size = atomic_read(&ap->cur_jumbo_bufs);
  1911. if (cur_size < RX_LOW_JUMBO_THRES) {
  1912. if ((cur_size < RX_PANIC_JUMBO_THRES) &&
  1913. !test_and_set_bit(0,
  1914. &ap->jumbo_refill_busy)){
  1915. #ifdef DEBUG
  1916. printk("low on jumbo buffers %i\n",
  1917. cur_size);
  1918. #endif
  1919. ace_load_jumbo_rx_ring(dev,
  1920. RX_JUMBO_SIZE - cur_size);
  1921. } else
  1922. run_tasklet = 1;
  1923. }
  1924. }
  1925. if (run_tasklet && !ap->tasklet_pending) {
  1926. ap->tasklet_pending = 1;
  1927. tasklet_schedule(&ap->ace_tasklet);
  1928. }
  1929. }
  1930. return IRQ_HANDLED;
  1931. }
  1932. static int ace_open(struct net_device *dev)
  1933. {
  1934. struct ace_private *ap = netdev_priv(dev);
  1935. struct ace_regs __iomem *regs = ap->regs;
  1936. struct cmd cmd;
  1937. if (!(ap->fw_running)) {
  1938. printk(KERN_WARNING "%s: Firmware not running!\n", dev->name);
  1939. return -EBUSY;
  1940. }
  1941. writel(dev->mtu + ETH_HLEN + 4, &regs->IfMtu);
  1942. cmd.evt = C_CLEAR_STATS;
  1943. cmd.code = 0;
  1944. cmd.idx = 0;
  1945. ace_issue_cmd(regs, &cmd);
  1946. cmd.evt = C_HOST_STATE;
  1947. cmd.code = C_C_STACK_UP;
  1948. cmd.idx = 0;
  1949. ace_issue_cmd(regs, &cmd);
  1950. if (ap->jumbo &&
  1951. !test_and_set_bit(0, &ap->jumbo_refill_busy))
  1952. ace_load_jumbo_rx_ring(dev, RX_JUMBO_SIZE);
  1953. if (dev->flags & IFF_PROMISC) {
  1954. cmd.evt = C_SET_PROMISC_MODE;
  1955. cmd.code = C_C_PROMISC_ENABLE;
  1956. cmd.idx = 0;
  1957. ace_issue_cmd(regs, &cmd);
  1958. ap->promisc = 1;
  1959. }else
  1960. ap->promisc = 0;
  1961. ap->mcast_all = 0;
  1962. #if 0
  1963. cmd.evt = C_LNK_NEGOTIATION;
  1964. cmd.code = 0;
  1965. cmd.idx = 0;
  1966. ace_issue_cmd(regs, &cmd);
  1967. #endif
  1968. netif_start_queue(dev);
  1969. /*
  1970. * Setup the bottom half rx ring refill handler
  1971. */
  1972. tasklet_init(&ap->ace_tasklet, ace_tasklet, (unsigned long)dev);
  1973. return 0;
  1974. }
  1975. static int ace_close(struct net_device *dev)
  1976. {
  1977. struct ace_private *ap = netdev_priv(dev);
  1978. struct ace_regs __iomem *regs = ap->regs;
  1979. struct cmd cmd;
  1980. unsigned long flags;
  1981. short i;
  1982. /*
  1983. * Without (or before) releasing irq and stopping hardware, this
  1984. * is an absolute non-sense, by the way. It will be reset instantly
  1985. * by the first irq.
  1986. */
  1987. netif_stop_queue(dev);
  1988. if (ap->promisc) {
  1989. cmd.evt = C_SET_PROMISC_MODE;
  1990. cmd.code = C_C_PROMISC_DISABLE;
  1991. cmd.idx = 0;
  1992. ace_issue_cmd(regs, &cmd);
  1993. ap->promisc = 0;
  1994. }
  1995. cmd.evt = C_HOST_STATE;
  1996. cmd.code = C_C_STACK_DOWN;
  1997. cmd.idx = 0;
  1998. ace_issue_cmd(regs, &cmd);
  1999. tasklet_kill(&ap->ace_tasklet);
  2000. /*
  2001. * Make sure one CPU is not processing packets while
  2002. * buffers are being released by another.
  2003. */
  2004. local_irq_save(flags);
  2005. ace_mask_irq(dev);
  2006. for (i = 0; i < ACE_TX_RING_ENTRIES(ap); i++) {
  2007. struct sk_buff *skb;
  2008. struct tx_ring_info *info;
  2009. info = ap->skb->tx_skbuff + i;
  2010. skb = info->skb;
  2011. if (dma_unmap_len(info, maplen)) {
  2012. if (ACE_IS_TIGON_I(ap)) {
  2013. /* NB: TIGON_1 is special, tx_ring is in io space */
  2014. struct tx_desc __iomem *tx;
  2015. tx = (__force struct tx_desc __iomem *) &ap->tx_ring[i];
  2016. writel(0, &tx->addr.addrhi);
  2017. writel(0, &tx->addr.addrlo);
  2018. writel(0, &tx->flagsize);
  2019. } else
  2020. memset(ap->tx_ring + i, 0,
  2021. sizeof(struct tx_desc));
  2022. pci_unmap_page(ap->pdev, dma_unmap_addr(info, mapping),
  2023. dma_unmap_len(info, maplen),
  2024. PCI_DMA_TODEVICE);
  2025. dma_unmap_len_set(info, maplen, 0);
  2026. }
  2027. if (skb) {
  2028. dev_kfree_skb(skb);
  2029. info->skb = NULL;
  2030. }
  2031. }
  2032. if (ap->jumbo) {
  2033. cmd.evt = C_RESET_JUMBO_RNG;
  2034. cmd.code = 0;
  2035. cmd.idx = 0;
  2036. ace_issue_cmd(regs, &cmd);
  2037. }
  2038. ace_unmask_irq(dev);
  2039. local_irq_restore(flags);
  2040. return 0;
  2041. }
  2042. static inline dma_addr_t
  2043. ace_map_tx_skb(struct ace_private *ap, struct sk_buff *skb,
  2044. struct sk_buff *tail, u32 idx)
  2045. {
  2046. dma_addr_t mapping;
  2047. struct tx_ring_info *info;
  2048. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  2049. offset_in_page(skb->data),
  2050. skb->len, PCI_DMA_TODEVICE);
  2051. info = ap->skb->tx_skbuff + idx;
  2052. info->skb = tail;
  2053. dma_unmap_addr_set(info, mapping, mapping);
  2054. dma_unmap_len_set(info, maplen, skb->len);
  2055. return mapping;
  2056. }
  2057. static inline void
  2058. ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr,
  2059. u32 flagsize, u32 vlan_tag)
  2060. {
  2061. #if !USE_TX_COAL_NOW
  2062. flagsize &= ~BD_FLG_COAL_NOW;
  2063. #endif
  2064. if (ACE_IS_TIGON_I(ap)) {
  2065. struct tx_desc __iomem *io = (__force struct tx_desc __iomem *) desc;
  2066. writel(addr >> 32, &io->addr.addrhi);
  2067. writel(addr & 0xffffffff, &io->addr.addrlo);
  2068. writel(flagsize, &io->flagsize);
  2069. writel(vlan_tag, &io->vlanres);
  2070. } else {
  2071. desc->addr.addrhi = addr >> 32;
  2072. desc->addr.addrlo = addr;
  2073. desc->flagsize = flagsize;
  2074. desc->vlanres = vlan_tag;
  2075. }
  2076. }
  2077. static netdev_tx_t ace_start_xmit(struct sk_buff *skb,
  2078. struct net_device *dev)
  2079. {
  2080. struct ace_private *ap = netdev_priv(dev);
  2081. struct ace_regs __iomem *regs = ap->regs;
  2082. struct tx_desc *desc;
  2083. u32 idx, flagsize;
  2084. unsigned long maxjiff = jiffies + 3*HZ;
  2085. restart:
  2086. idx = ap->tx_prd;
  2087. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2088. goto overflow;
  2089. if (!skb_shinfo(skb)->nr_frags) {
  2090. dma_addr_t mapping;
  2091. u32 vlan_tag = 0;
  2092. mapping = ace_map_tx_skb(ap, skb, skb, idx);
  2093. flagsize = (skb->len << 16) | (BD_FLG_END);
  2094. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2095. flagsize |= BD_FLG_TCP_UDP_SUM;
  2096. if (skb_vlan_tag_present(skb)) {
  2097. flagsize |= BD_FLG_VLAN_TAG;
  2098. vlan_tag = skb_vlan_tag_get(skb);
  2099. }
  2100. desc = ap->tx_ring + idx;
  2101. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2102. /* Look at ace_tx_int for explanations. */
  2103. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2104. flagsize |= BD_FLG_COAL_NOW;
  2105. ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
  2106. } else {
  2107. dma_addr_t mapping;
  2108. u32 vlan_tag = 0;
  2109. int i, len = 0;
  2110. mapping = ace_map_tx_skb(ap, skb, NULL, idx);
  2111. flagsize = (skb_headlen(skb) << 16);
  2112. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2113. flagsize |= BD_FLG_TCP_UDP_SUM;
  2114. if (skb_vlan_tag_present(skb)) {
  2115. flagsize |= BD_FLG_VLAN_TAG;
  2116. vlan_tag = skb_vlan_tag_get(skb);
  2117. }
  2118. ace_load_tx_bd(ap, ap->tx_ring + idx, mapping, flagsize, vlan_tag);
  2119. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2120. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2121. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2122. struct tx_ring_info *info;
  2123. len += skb_frag_size(frag);
  2124. info = ap->skb->tx_skbuff + idx;
  2125. desc = ap->tx_ring + idx;
  2126. mapping = skb_frag_dma_map(&ap->pdev->dev, frag, 0,
  2127. skb_frag_size(frag),
  2128. DMA_TO_DEVICE);
  2129. flagsize = skb_frag_size(frag) << 16;
  2130. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2131. flagsize |= BD_FLG_TCP_UDP_SUM;
  2132. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2133. if (i == skb_shinfo(skb)->nr_frags - 1) {
  2134. flagsize |= BD_FLG_END;
  2135. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2136. flagsize |= BD_FLG_COAL_NOW;
  2137. /*
  2138. * Only the last fragment frees
  2139. * the skb!
  2140. */
  2141. info->skb = skb;
  2142. } else {
  2143. info->skb = NULL;
  2144. }
  2145. dma_unmap_addr_set(info, mapping, mapping);
  2146. dma_unmap_len_set(info, maplen, skb_frag_size(frag));
  2147. ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
  2148. }
  2149. }
  2150. wmb();
  2151. ap->tx_prd = idx;
  2152. ace_set_txprd(regs, ap, idx);
  2153. if (flagsize & BD_FLG_COAL_NOW) {
  2154. netif_stop_queue(dev);
  2155. /*
  2156. * A TX-descriptor producer (an IRQ) might have gotten
  2157. * between, making the ring free again. Since xmit is
  2158. * serialized, this is the only situation we have to
  2159. * re-test.
  2160. */
  2161. if (!tx_ring_full(ap, ap->tx_ret_csm, idx))
  2162. netif_wake_queue(dev);
  2163. }
  2164. return NETDEV_TX_OK;
  2165. overflow:
  2166. /*
  2167. * This race condition is unavoidable with lock-free drivers.
  2168. * We wake up the queue _before_ tx_prd is advanced, so that we can
  2169. * enter hard_start_xmit too early, while tx ring still looks closed.
  2170. * This happens ~1-4 times per 100000 packets, so that we can allow
  2171. * to loop syncing to other CPU. Probably, we need an additional
  2172. * wmb() in ace_tx_intr as well.
  2173. *
  2174. * Note that this race is relieved by reserving one more entry
  2175. * in tx ring than it is necessary (see original non-SG driver).
  2176. * However, with SG we need to reserve 2*MAX_SKB_FRAGS+1, which
  2177. * is already overkill.
  2178. *
  2179. * Alternative is to return with 1 not throttling queue. In this
  2180. * case loop becomes longer, no more useful effects.
  2181. */
  2182. if (time_before(jiffies, maxjiff)) {
  2183. barrier();
  2184. cpu_relax();
  2185. goto restart;
  2186. }
  2187. /* The ring is stuck full. */
  2188. printk(KERN_WARNING "%s: Transmit ring stuck full\n", dev->name);
  2189. return NETDEV_TX_BUSY;
  2190. }
  2191. static int ace_change_mtu(struct net_device *dev, int new_mtu)
  2192. {
  2193. struct ace_private *ap = netdev_priv(dev);
  2194. struct ace_regs __iomem *regs = ap->regs;
  2195. writel(new_mtu + ETH_HLEN + 4, &regs->IfMtu);
  2196. dev->mtu = new_mtu;
  2197. if (new_mtu > ACE_STD_MTU) {
  2198. if (!(ap->jumbo)) {
  2199. printk(KERN_INFO "%s: Enabling Jumbo frame "
  2200. "support\n", dev->name);
  2201. ap->jumbo = 1;
  2202. if (!test_and_set_bit(0, &ap->jumbo_refill_busy))
  2203. ace_load_jumbo_rx_ring(dev, RX_JUMBO_SIZE);
  2204. ace_set_rxtx_parms(dev, 1);
  2205. }
  2206. } else {
  2207. while (test_and_set_bit(0, &ap->jumbo_refill_busy));
  2208. ace_sync_irq(dev->irq);
  2209. ace_set_rxtx_parms(dev, 0);
  2210. if (ap->jumbo) {
  2211. struct cmd cmd;
  2212. cmd.evt = C_RESET_JUMBO_RNG;
  2213. cmd.code = 0;
  2214. cmd.idx = 0;
  2215. ace_issue_cmd(regs, &cmd);
  2216. }
  2217. }
  2218. return 0;
  2219. }
  2220. static int ace_get_link_ksettings(struct net_device *dev,
  2221. struct ethtool_link_ksettings *cmd)
  2222. {
  2223. struct ace_private *ap = netdev_priv(dev);
  2224. struct ace_regs __iomem *regs = ap->regs;
  2225. u32 link;
  2226. u32 supported;
  2227. memset(cmd, 0, sizeof(struct ethtool_link_ksettings));
  2228. supported = (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
  2229. SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
  2230. SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full |
  2231. SUPPORTED_Autoneg | SUPPORTED_FIBRE);
  2232. cmd->base.port = PORT_FIBRE;
  2233. link = readl(&regs->GigLnkState);
  2234. if (link & LNK_1000MB) {
  2235. cmd->base.speed = SPEED_1000;
  2236. } else {
  2237. link = readl(&regs->FastLnkState);
  2238. if (link & LNK_100MB)
  2239. cmd->base.speed = SPEED_100;
  2240. else if (link & LNK_10MB)
  2241. cmd->base.speed = SPEED_10;
  2242. else
  2243. cmd->base.speed = 0;
  2244. }
  2245. if (link & LNK_FULL_DUPLEX)
  2246. cmd->base.duplex = DUPLEX_FULL;
  2247. else
  2248. cmd->base.duplex = DUPLEX_HALF;
  2249. if (link & LNK_NEGOTIATE)
  2250. cmd->base.autoneg = AUTONEG_ENABLE;
  2251. else
  2252. cmd->base.autoneg = AUTONEG_DISABLE;
  2253. #if 0
  2254. /*
  2255. * Current struct ethtool_cmd is insufficient
  2256. */
  2257. ecmd->trace = readl(&regs->TuneTrace);
  2258. ecmd->txcoal = readl(&regs->TuneTxCoalTicks);
  2259. ecmd->rxcoal = readl(&regs->TuneRxCoalTicks);
  2260. #endif
  2261. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  2262. supported);
  2263. return 0;
  2264. }
  2265. static int ace_set_link_ksettings(struct net_device *dev,
  2266. const struct ethtool_link_ksettings *cmd)
  2267. {
  2268. struct ace_private *ap = netdev_priv(dev);
  2269. struct ace_regs __iomem *regs = ap->regs;
  2270. u32 link, speed;
  2271. link = readl(&regs->GigLnkState);
  2272. if (link & LNK_1000MB)
  2273. speed = SPEED_1000;
  2274. else {
  2275. link = readl(&regs->FastLnkState);
  2276. if (link & LNK_100MB)
  2277. speed = SPEED_100;
  2278. else if (link & LNK_10MB)
  2279. speed = SPEED_10;
  2280. else
  2281. speed = SPEED_100;
  2282. }
  2283. link = LNK_ENABLE | LNK_1000MB | LNK_100MB | LNK_10MB |
  2284. LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL;
  2285. if (!ACE_IS_TIGON_I(ap))
  2286. link |= LNK_TX_FLOW_CTL_Y;
  2287. if (cmd->base.autoneg == AUTONEG_ENABLE)
  2288. link |= LNK_NEGOTIATE;
  2289. if (cmd->base.speed != speed) {
  2290. link &= ~(LNK_1000MB | LNK_100MB | LNK_10MB);
  2291. switch (cmd->base.speed) {
  2292. case SPEED_1000:
  2293. link |= LNK_1000MB;
  2294. break;
  2295. case SPEED_100:
  2296. link |= LNK_100MB;
  2297. break;
  2298. case SPEED_10:
  2299. link |= LNK_10MB;
  2300. break;
  2301. }
  2302. }
  2303. if (cmd->base.duplex == DUPLEX_FULL)
  2304. link |= LNK_FULL_DUPLEX;
  2305. if (link != ap->link) {
  2306. struct cmd cmd;
  2307. printk(KERN_INFO "%s: Renegotiating link state\n",
  2308. dev->name);
  2309. ap->link = link;
  2310. writel(link, &regs->TuneLink);
  2311. if (!ACE_IS_TIGON_I(ap))
  2312. writel(link, &regs->TuneFastLink);
  2313. wmb();
  2314. cmd.evt = C_LNK_NEGOTIATION;
  2315. cmd.code = 0;
  2316. cmd.idx = 0;
  2317. ace_issue_cmd(regs, &cmd);
  2318. }
  2319. return 0;
  2320. }
  2321. static void ace_get_drvinfo(struct net_device *dev,
  2322. struct ethtool_drvinfo *info)
  2323. {
  2324. struct ace_private *ap = netdev_priv(dev);
  2325. strlcpy(info->driver, "acenic", sizeof(info->driver));
  2326. snprintf(info->version, sizeof(info->version), "%i.%i.%i",
  2327. ap->firmware_major, ap->firmware_minor,
  2328. ap->firmware_fix);
  2329. if (ap->pdev)
  2330. strlcpy(info->bus_info, pci_name(ap->pdev),
  2331. sizeof(info->bus_info));
  2332. }
  2333. /*
  2334. * Set the hardware MAC address.
  2335. */
  2336. static int ace_set_mac_addr(struct net_device *dev, void *p)
  2337. {
  2338. struct ace_private *ap = netdev_priv(dev);
  2339. struct ace_regs __iomem *regs = ap->regs;
  2340. struct sockaddr *addr=p;
  2341. u8 *da;
  2342. struct cmd cmd;
  2343. if(netif_running(dev))
  2344. return -EBUSY;
  2345. memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
  2346. da = (u8 *)dev->dev_addr;
  2347. writel(da[0] << 8 | da[1], &regs->MacAddrHi);
  2348. writel((da[2] << 24) | (da[3] << 16) | (da[4] << 8) | da[5],
  2349. &regs->MacAddrLo);
  2350. cmd.evt = C_SET_MAC_ADDR;
  2351. cmd.code = 0;
  2352. cmd.idx = 0;
  2353. ace_issue_cmd(regs, &cmd);
  2354. return 0;
  2355. }
  2356. static void ace_set_multicast_list(struct net_device *dev)
  2357. {
  2358. struct ace_private *ap = netdev_priv(dev);
  2359. struct ace_regs __iomem *regs = ap->regs;
  2360. struct cmd cmd;
  2361. if ((dev->flags & IFF_ALLMULTI) && !(ap->mcast_all)) {
  2362. cmd.evt = C_SET_MULTICAST_MODE;
  2363. cmd.code = C_C_MCAST_ENABLE;
  2364. cmd.idx = 0;
  2365. ace_issue_cmd(regs, &cmd);
  2366. ap->mcast_all = 1;
  2367. } else if (ap->mcast_all) {
  2368. cmd.evt = C_SET_MULTICAST_MODE;
  2369. cmd.code = C_C_MCAST_DISABLE;
  2370. cmd.idx = 0;
  2371. ace_issue_cmd(regs, &cmd);
  2372. ap->mcast_all = 0;
  2373. }
  2374. if ((dev->flags & IFF_PROMISC) && !(ap->promisc)) {
  2375. cmd.evt = C_SET_PROMISC_MODE;
  2376. cmd.code = C_C_PROMISC_ENABLE;
  2377. cmd.idx = 0;
  2378. ace_issue_cmd(regs, &cmd);
  2379. ap->promisc = 1;
  2380. }else if (!(dev->flags & IFF_PROMISC) && (ap->promisc)) {
  2381. cmd.evt = C_SET_PROMISC_MODE;
  2382. cmd.code = C_C_PROMISC_DISABLE;
  2383. cmd.idx = 0;
  2384. ace_issue_cmd(regs, &cmd);
  2385. ap->promisc = 0;
  2386. }
  2387. /*
  2388. * For the time being multicast relies on the upper layers
  2389. * filtering it properly. The Firmware does not allow one to
  2390. * set the entire multicast list at a time and keeping track of
  2391. * it here is going to be messy.
  2392. */
  2393. if (!netdev_mc_empty(dev) && !ap->mcast_all) {
  2394. cmd.evt = C_SET_MULTICAST_MODE;
  2395. cmd.code = C_C_MCAST_ENABLE;
  2396. cmd.idx = 0;
  2397. ace_issue_cmd(regs, &cmd);
  2398. }else if (!ap->mcast_all) {
  2399. cmd.evt = C_SET_MULTICAST_MODE;
  2400. cmd.code = C_C_MCAST_DISABLE;
  2401. cmd.idx = 0;
  2402. ace_issue_cmd(regs, &cmd);
  2403. }
  2404. }
  2405. static struct net_device_stats *ace_get_stats(struct net_device *dev)
  2406. {
  2407. struct ace_private *ap = netdev_priv(dev);
  2408. struct ace_mac_stats __iomem *mac_stats =
  2409. (struct ace_mac_stats __iomem *)ap->regs->Stats;
  2410. dev->stats.rx_missed_errors = readl(&mac_stats->drop_space);
  2411. dev->stats.multicast = readl(&mac_stats->kept_mc);
  2412. dev->stats.collisions = readl(&mac_stats->coll);
  2413. return &dev->stats;
  2414. }
  2415. static void ace_copy(struct ace_regs __iomem *regs, const __be32 *src,
  2416. u32 dest, int size)
  2417. {
  2418. void __iomem *tdest;
  2419. short tsize, i;
  2420. if (size <= 0)
  2421. return;
  2422. while (size > 0) {
  2423. tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
  2424. min_t(u32, size, ACE_WINDOW_SIZE));
  2425. tdest = (void __iomem *) &regs->Window +
  2426. (dest & (ACE_WINDOW_SIZE - 1));
  2427. writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
  2428. for (i = 0; i < (tsize / 4); i++) {
  2429. /* Firmware is big-endian */
  2430. writel(be32_to_cpup(src), tdest);
  2431. src++;
  2432. tdest += 4;
  2433. dest += 4;
  2434. size -= 4;
  2435. }
  2436. }
  2437. }
  2438. static void ace_clear(struct ace_regs __iomem *regs, u32 dest, int size)
  2439. {
  2440. void __iomem *tdest;
  2441. short tsize = 0, i;
  2442. if (size <= 0)
  2443. return;
  2444. while (size > 0) {
  2445. tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
  2446. min_t(u32, size, ACE_WINDOW_SIZE));
  2447. tdest = (void __iomem *) &regs->Window +
  2448. (dest & (ACE_WINDOW_SIZE - 1));
  2449. writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
  2450. for (i = 0; i < (tsize / 4); i++) {
  2451. writel(0, tdest + i*4);
  2452. }
  2453. dest += tsize;
  2454. size -= tsize;
  2455. }
  2456. }
  2457. /*
  2458. * Download the firmware into the SRAM on the NIC
  2459. *
  2460. * This operation requires the NIC to be halted and is performed with
  2461. * interrupts disabled and with the spinlock hold.
  2462. */
  2463. static int ace_load_firmware(struct net_device *dev)
  2464. {
  2465. const struct firmware *fw;
  2466. const char *fw_name = "acenic/tg2.bin";
  2467. struct ace_private *ap = netdev_priv(dev);
  2468. struct ace_regs __iomem *regs = ap->regs;
  2469. const __be32 *fw_data;
  2470. u32 load_addr;
  2471. int ret;
  2472. if (!(readl(&regs->CpuCtrl) & CPU_HALTED)) {
  2473. printk(KERN_ERR "%s: trying to download firmware while the "
  2474. "CPU is running!\n", ap->name);
  2475. return -EFAULT;
  2476. }
  2477. if (ACE_IS_TIGON_I(ap))
  2478. fw_name = "acenic/tg1.bin";
  2479. ret = request_firmware(&fw, fw_name, &ap->pdev->dev);
  2480. if (ret)
  2481. return ret;
  2482. fw_data = (void *)fw->data;
  2483. /* Firmware blob starts with version numbers, followed by
  2484. load and start address. Remainder is the blob to be loaded
  2485. contiguously from load address. We don't bother to represent
  2486. the BSS/SBSS sections any more, since we were clearing the
  2487. whole thing anyway. */
  2488. ap->firmware_major = fw->data[0];
  2489. ap->firmware_minor = fw->data[1];
  2490. ap->firmware_fix = fw->data[2];
  2491. ap->firmware_start = be32_to_cpu(fw_data[1]);
  2492. if (ap->firmware_start < 0x4000 || ap->firmware_start >= 0x80000) {
  2493. printk(KERN_ERR "%s: bogus load address %08x in \"%s\"\n",
  2494. ap->name, ap->firmware_start, fw_name);
  2495. ret = -EINVAL;
  2496. goto out;
  2497. }
  2498. load_addr = be32_to_cpu(fw_data[2]);
  2499. if (load_addr < 0x4000 || load_addr >= 0x80000) {
  2500. printk(KERN_ERR "%s: bogus load address %08x in \"%s\"\n",
  2501. ap->name, load_addr, fw_name);
  2502. ret = -EINVAL;
  2503. goto out;
  2504. }
  2505. /*
  2506. * Do not try to clear more than 512KiB or we end up seeing
  2507. * funny things on NICs with only 512KiB SRAM
  2508. */
  2509. ace_clear(regs, 0x2000, 0x80000-0x2000);
  2510. ace_copy(regs, &fw_data[3], load_addr, fw->size-12);
  2511. out:
  2512. release_firmware(fw);
  2513. return ret;
  2514. }
  2515. /*
  2516. * The eeprom on the AceNIC is an Atmel i2c EEPROM.
  2517. *
  2518. * Accessing the EEPROM is `interesting' to say the least - don't read
  2519. * this code right after dinner.
  2520. *
  2521. * This is all about black magic and bit-banging the device .... I
  2522. * wonder in what hospital they have put the guy who designed the i2c
  2523. * specs.
  2524. *
  2525. * Oh yes, this is only the beginning!
  2526. *
  2527. * Thanks to Stevarino Webinski for helping tracking down the bugs in the
  2528. * code i2c readout code by beta testing all my hacks.
  2529. */
  2530. static void eeprom_start(struct ace_regs __iomem *regs)
  2531. {
  2532. u32 local;
  2533. readl(&regs->LocalCtrl);
  2534. udelay(ACE_SHORT_DELAY);
  2535. local = readl(&regs->LocalCtrl);
  2536. local |= EEPROM_DATA_OUT | EEPROM_WRITE_ENABLE;
  2537. writel(local, &regs->LocalCtrl);
  2538. readl(&regs->LocalCtrl);
  2539. mb();
  2540. udelay(ACE_SHORT_DELAY);
  2541. local |= EEPROM_CLK_OUT;
  2542. writel(local, &regs->LocalCtrl);
  2543. readl(&regs->LocalCtrl);
  2544. mb();
  2545. udelay(ACE_SHORT_DELAY);
  2546. local &= ~EEPROM_DATA_OUT;
  2547. writel(local, &regs->LocalCtrl);
  2548. readl(&regs->LocalCtrl);
  2549. mb();
  2550. udelay(ACE_SHORT_DELAY);
  2551. local &= ~EEPROM_CLK_OUT;
  2552. writel(local, &regs->LocalCtrl);
  2553. readl(&regs->LocalCtrl);
  2554. mb();
  2555. }
  2556. static void eeprom_prep(struct ace_regs __iomem *regs, u8 magic)
  2557. {
  2558. short i;
  2559. u32 local;
  2560. udelay(ACE_SHORT_DELAY);
  2561. local = readl(&regs->LocalCtrl);
  2562. local &= ~EEPROM_DATA_OUT;
  2563. local |= EEPROM_WRITE_ENABLE;
  2564. writel(local, &regs->LocalCtrl);
  2565. readl(&regs->LocalCtrl);
  2566. mb();
  2567. for (i = 0; i < 8; i++, magic <<= 1) {
  2568. udelay(ACE_SHORT_DELAY);
  2569. if (magic & 0x80)
  2570. local |= EEPROM_DATA_OUT;
  2571. else
  2572. local &= ~EEPROM_DATA_OUT;
  2573. writel(local, &regs->LocalCtrl);
  2574. readl(&regs->LocalCtrl);
  2575. mb();
  2576. udelay(ACE_SHORT_DELAY);
  2577. local |= EEPROM_CLK_OUT;
  2578. writel(local, &regs->LocalCtrl);
  2579. readl(&regs->LocalCtrl);
  2580. mb();
  2581. udelay(ACE_SHORT_DELAY);
  2582. local &= ~(EEPROM_CLK_OUT | EEPROM_DATA_OUT);
  2583. writel(local, &regs->LocalCtrl);
  2584. readl(&regs->LocalCtrl);
  2585. mb();
  2586. }
  2587. }
  2588. static int eeprom_check_ack(struct ace_regs __iomem *regs)
  2589. {
  2590. int state;
  2591. u32 local;
  2592. local = readl(&regs->LocalCtrl);
  2593. local &= ~EEPROM_WRITE_ENABLE;
  2594. writel(local, &regs->LocalCtrl);
  2595. readl(&regs->LocalCtrl);
  2596. mb();
  2597. udelay(ACE_LONG_DELAY);
  2598. local |= EEPROM_CLK_OUT;
  2599. writel(local, &regs->LocalCtrl);
  2600. readl(&regs->LocalCtrl);
  2601. mb();
  2602. udelay(ACE_SHORT_DELAY);
  2603. /* sample data in middle of high clk */
  2604. state = (readl(&regs->LocalCtrl) & EEPROM_DATA_IN) != 0;
  2605. udelay(ACE_SHORT_DELAY);
  2606. mb();
  2607. writel(readl(&regs->LocalCtrl) & ~EEPROM_CLK_OUT, &regs->LocalCtrl);
  2608. readl(&regs->LocalCtrl);
  2609. mb();
  2610. return state;
  2611. }
  2612. static void eeprom_stop(struct ace_regs __iomem *regs)
  2613. {
  2614. u32 local;
  2615. udelay(ACE_SHORT_DELAY);
  2616. local = readl(&regs->LocalCtrl);
  2617. local |= EEPROM_WRITE_ENABLE;
  2618. writel(local, &regs->LocalCtrl);
  2619. readl(&regs->LocalCtrl);
  2620. mb();
  2621. udelay(ACE_SHORT_DELAY);
  2622. local &= ~EEPROM_DATA_OUT;
  2623. writel(local, &regs->LocalCtrl);
  2624. readl(&regs->LocalCtrl);
  2625. mb();
  2626. udelay(ACE_SHORT_DELAY);
  2627. local |= EEPROM_CLK_OUT;
  2628. writel(local, &regs->LocalCtrl);
  2629. readl(&regs->LocalCtrl);
  2630. mb();
  2631. udelay(ACE_SHORT_DELAY);
  2632. local |= EEPROM_DATA_OUT;
  2633. writel(local, &regs->LocalCtrl);
  2634. readl(&regs->LocalCtrl);
  2635. mb();
  2636. udelay(ACE_LONG_DELAY);
  2637. local &= ~EEPROM_CLK_OUT;
  2638. writel(local, &regs->LocalCtrl);
  2639. mb();
  2640. }
  2641. /*
  2642. * Read a whole byte from the EEPROM.
  2643. */
  2644. static int read_eeprom_byte(struct net_device *dev, unsigned long offset)
  2645. {
  2646. struct ace_private *ap = netdev_priv(dev);
  2647. struct ace_regs __iomem *regs = ap->regs;
  2648. unsigned long flags;
  2649. u32 local;
  2650. int result = 0;
  2651. short i;
  2652. /*
  2653. * Don't take interrupts on this CPU will bit banging
  2654. * the %#%#@$ I2C device
  2655. */
  2656. local_irq_save(flags);
  2657. eeprom_start(regs);
  2658. eeprom_prep(regs, EEPROM_WRITE_SELECT);
  2659. if (eeprom_check_ack(regs)) {
  2660. local_irq_restore(flags);
  2661. printk(KERN_ERR "%s: Unable to sync eeprom\n", ap->name);
  2662. result = -EIO;
  2663. goto eeprom_read_error;
  2664. }
  2665. eeprom_prep(regs, (offset >> 8) & 0xff);
  2666. if (eeprom_check_ack(regs)) {
  2667. local_irq_restore(flags);
  2668. printk(KERN_ERR "%s: Unable to set address byte 0\n",
  2669. ap->name);
  2670. result = -EIO;
  2671. goto eeprom_read_error;
  2672. }
  2673. eeprom_prep(regs, offset & 0xff);
  2674. if (eeprom_check_ack(regs)) {
  2675. local_irq_restore(flags);
  2676. printk(KERN_ERR "%s: Unable to set address byte 1\n",
  2677. ap->name);
  2678. result = -EIO;
  2679. goto eeprom_read_error;
  2680. }
  2681. eeprom_start(regs);
  2682. eeprom_prep(regs, EEPROM_READ_SELECT);
  2683. if (eeprom_check_ack(regs)) {
  2684. local_irq_restore(flags);
  2685. printk(KERN_ERR "%s: Unable to set READ_SELECT\n",
  2686. ap->name);
  2687. result = -EIO;
  2688. goto eeprom_read_error;
  2689. }
  2690. for (i = 0; i < 8; i++) {
  2691. local = readl(&regs->LocalCtrl);
  2692. local &= ~EEPROM_WRITE_ENABLE;
  2693. writel(local, &regs->LocalCtrl);
  2694. readl(&regs->LocalCtrl);
  2695. udelay(ACE_LONG_DELAY);
  2696. mb();
  2697. local |= EEPROM_CLK_OUT;
  2698. writel(local, &regs->LocalCtrl);
  2699. readl(&regs->LocalCtrl);
  2700. mb();
  2701. udelay(ACE_SHORT_DELAY);
  2702. /* sample data mid high clk */
  2703. result = (result << 1) |
  2704. ((readl(&regs->LocalCtrl) & EEPROM_DATA_IN) != 0);
  2705. udelay(ACE_SHORT_DELAY);
  2706. mb();
  2707. local = readl(&regs->LocalCtrl);
  2708. local &= ~EEPROM_CLK_OUT;
  2709. writel(local, &regs->LocalCtrl);
  2710. readl(&regs->LocalCtrl);
  2711. udelay(ACE_SHORT_DELAY);
  2712. mb();
  2713. if (i == 7) {
  2714. local |= EEPROM_WRITE_ENABLE;
  2715. writel(local, &regs->LocalCtrl);
  2716. readl(&regs->LocalCtrl);
  2717. mb();
  2718. udelay(ACE_SHORT_DELAY);
  2719. }
  2720. }
  2721. local |= EEPROM_DATA_OUT;
  2722. writel(local, &regs->LocalCtrl);
  2723. readl(&regs->LocalCtrl);
  2724. mb();
  2725. udelay(ACE_SHORT_DELAY);
  2726. writel(readl(&regs->LocalCtrl) | EEPROM_CLK_OUT, &regs->LocalCtrl);
  2727. readl(&regs->LocalCtrl);
  2728. udelay(ACE_LONG_DELAY);
  2729. writel(readl(&regs->LocalCtrl) & ~EEPROM_CLK_OUT, &regs->LocalCtrl);
  2730. readl(&regs->LocalCtrl);
  2731. mb();
  2732. udelay(ACE_SHORT_DELAY);
  2733. eeprom_stop(regs);
  2734. local_irq_restore(flags);
  2735. out:
  2736. return result;
  2737. eeprom_read_error:
  2738. printk(KERN_ERR "%s: Unable to read eeprom byte 0x%02lx\n",
  2739. ap->name, offset);
  2740. goto out;
  2741. }
  2742. module_pci_driver(acenic_pci_driver);