acenic.c 86 KB

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