acenic.c 85 KB

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