acenic.c 86 KB

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