acenic.c 85 KB

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