acenic.c 86 KB

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