acenic.c 85 KB

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