acenic.c 86 KB

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