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