acenic.c 86 KB

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