acenic.c 86 KB

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