acenic.c 86 KB

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