starfire.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156
  1. /* starfire.c: Linux device driver for the Adaptec Starfire network adapter. */
  2. /*
  3. Written 1998-2000 by Donald Becker.
  4. Current maintainer is Ion Badulescu <ionut ta badula tod org>. Please
  5. send all bug reports to me, and not to Donald Becker, as this code
  6. has been heavily modified from Donald's original version.
  7. This software may be used and distributed according to the terms of
  8. the GNU General Public License (GPL), incorporated herein by reference.
  9. Drivers based on or derived from this code fall under the GPL and must
  10. retain the authorship, copyright and license notice. This file is not
  11. a complete program and may only be used when the entire operating
  12. system is licensed under the GPL.
  13. The information below comes from Donald Becker's original driver:
  14. The author may be reached as becker@scyld.com, or C/O
  15. Scyld Computing Corporation
  16. 410 Severn Ave., Suite 210
  17. Annapolis MD 21403
  18. Support and updates available at
  19. http://www.scyld.com/network/starfire.html
  20. -----------------------------------------------------------
  21. Linux kernel-specific changes:
  22. LK1.1.1 (jgarzik):
  23. - Use PCI driver interface
  24. - Fix MOD_xxx races
  25. - softnet fixups
  26. LK1.1.2 (jgarzik):
  27. - Merge Becker version 0.15
  28. LK1.1.3 (Andrew Morton)
  29. - Timer cleanups
  30. LK1.1.4 (jgarzik):
  31. - Merge Becker version 1.03
  32. LK1.2.1 (Ion Badulescu <ionut@cs.columbia.edu>)
  33. - Support hardware Rx/Tx checksumming
  34. - Use the GFP firmware taken from Adaptec's Netware driver
  35. LK1.2.2 (Ion Badulescu)
  36. - Backported to 2.2.x
  37. LK1.2.3 (Ion Badulescu)
  38. - Fix the flaky mdio interface
  39. - More compat clean-ups
  40. LK1.2.4 (Ion Badulescu)
  41. - More 2.2.x initialization fixes
  42. LK1.2.5 (Ion Badulescu)
  43. - Several fixes from Manfred Spraul
  44. LK1.2.6 (Ion Badulescu)
  45. - Fixed ifup/ifdown/ifup problem in 2.4.x
  46. LK1.2.7 (Ion Badulescu)
  47. - Removed unused code
  48. - Made more functions static and __init
  49. LK1.2.8 (Ion Badulescu)
  50. - Quell bogus error messages, inform about the Tx threshold
  51. - Removed #ifdef CONFIG_PCI, this driver is PCI only
  52. LK1.2.9 (Ion Badulescu)
  53. - Merged Jeff Garzik's changes from 2.4.4-pre5
  54. - Added 2.2.x compatibility stuff required by the above changes
  55. LK1.2.9a (Ion Badulescu)
  56. - More updates from Jeff Garzik
  57. LK1.3.0 (Ion Badulescu)
  58. - Merged zerocopy support
  59. LK1.3.1 (Ion Badulescu)
  60. - Added ethtool support
  61. - Added GPIO (media change) interrupt support
  62. LK1.3.2 (Ion Badulescu)
  63. - Fixed 2.2.x compatibility issues introduced in 1.3.1
  64. - Fixed ethtool ioctl returning uninitialized memory
  65. LK1.3.3 (Ion Badulescu)
  66. - Initialize the TxMode register properly
  67. - Don't dereference dev->priv after freeing it
  68. LK1.3.4 (Ion Badulescu)
  69. - Fixed initialization timing problems
  70. - Fixed interrupt mask definitions
  71. LK1.3.5 (jgarzik)
  72. - ethtool NWAY_RST, GLINK, [GS]MSGLVL support
  73. LK1.3.6:
  74. - Sparc64 support and fixes (Ion Badulescu)
  75. - Better stats and error handling (Ion Badulescu)
  76. - Use new pci_set_mwi() PCI API function (jgarzik)
  77. LK1.3.7 (Ion Badulescu)
  78. - minimal implementation of tx_timeout()
  79. - correctly shutdown the Rx/Tx engines in netdev_close()
  80. - added calls to netif_carrier_on/off
  81. (patch from Stefan Rompf <srompf@isg.de>)
  82. - VLAN support
  83. LK1.3.8 (Ion Badulescu)
  84. - adjust DMA burst size on sparc64
  85. - 64-bit support
  86. - reworked zerocopy support for 64-bit buffers
  87. - working and usable interrupt mitigation/latency
  88. - reduced Tx interrupt frequency for lower interrupt overhead
  89. LK1.3.9 (Ion Badulescu)
  90. - bugfix for mcast filter
  91. - enable the right kind of Tx interrupts (TxDMADone, not TxDone)
  92. LK1.4.0 (Ion Badulescu)
  93. - NAPI support
  94. LK1.4.1 (Ion Badulescu)
  95. - flush PCI posting buffers after disabling Rx interrupts
  96. - put the chip to a D3 slumber on driver unload
  97. - added config option to enable/disable NAPI
  98. LK1.4.2 (Ion Badulescu)
  99. - finally added firmware (GPL'ed by Adaptec)
  100. - removed compatibility code for 2.2.x
  101. TODO: - fix forced speed/duplexing code (broken a long time ago, when
  102. somebody converted the driver to use the generic MII code)
  103. - fix VLAN support
  104. */
  105. #define DRV_NAME "starfire"
  106. #define DRV_VERSION "1.03+LK1.4.2"
  107. #define DRV_RELDATE "January 19, 2005"
  108. #include <linux/config.h>
  109. #include <linux/version.h>
  110. #include <linux/module.h>
  111. #include <linux/kernel.h>
  112. #include <linux/pci.h>
  113. #include <linux/netdevice.h>
  114. #include <linux/etherdevice.h>
  115. #include <linux/init.h>
  116. #include <linux/delay.h>
  117. #include <linux/crc32.h>
  118. #include <linux/ethtool.h>
  119. #include <linux/mii.h>
  120. #include <linux/if_vlan.h>
  121. #include <asm/processor.h> /* Processor type for cache alignment. */
  122. #include <asm/uaccess.h>
  123. #include <asm/io.h>
  124. #include "starfire_firmware.h"
  125. /*
  126. * The current frame processor firmware fails to checksum a fragment
  127. * of length 1. If and when this is fixed, the #define below can be removed.
  128. */
  129. #define HAS_BROKEN_FIRMWARE
  130. /*
  131. * Define this if using the driver with the zero-copy patch
  132. */
  133. #define ZEROCOPY
  134. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  135. #define VLAN_SUPPORT
  136. #endif
  137. #ifndef CONFIG_ADAPTEC_STARFIRE_NAPI
  138. #undef HAVE_NETDEV_POLL
  139. #endif
  140. /* The user-configurable values.
  141. These may be modified when a driver module is loaded.*/
  142. /* Used for tuning interrupt latency vs. overhead. */
  143. static int intr_latency;
  144. static int small_frames;
  145. static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */
  146. static int max_interrupt_work = 20;
  147. static int mtu;
  148. /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
  149. The Starfire has a 512 element hash table based on the Ethernet CRC. */
  150. static int multicast_filter_limit = 512;
  151. /* Whether to do TCP/UDP checksums in hardware */
  152. static int enable_hw_cksum = 1;
  153. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
  154. /*
  155. * Set the copy breakpoint for the copy-only-tiny-frames scheme.
  156. * Setting to > 1518 effectively disables this feature.
  157. *
  158. * NOTE:
  159. * The ia64 doesn't allow for unaligned loads even of integers being
  160. * misaligned on a 2 byte boundary. Thus always force copying of
  161. * packets as the starfire doesn't allow for misaligned DMAs ;-(
  162. * 23/10/2000 - Jes
  163. *
  164. * The Alpha and the Sparc don't like unaligned loads, either. On Sparc64,
  165. * at least, having unaligned frames leads to a rather serious performance
  166. * penalty. -Ion
  167. */
  168. #if defined(__ia64__) || defined(__alpha__) || defined(__sparc__)
  169. static int rx_copybreak = PKT_BUF_SZ;
  170. #else
  171. static int rx_copybreak /* = 0 */;
  172. #endif
  173. /* PCI DMA burst size -- on sparc64 we want to force it to 64 bytes, on the others the default of 128 is fine. */
  174. #ifdef __sparc__
  175. #define DMA_BURST_SIZE 64
  176. #else
  177. #define DMA_BURST_SIZE 128
  178. #endif
  179. /* Used to pass the media type, etc.
  180. Both 'options[]' and 'full_duplex[]' exist for driver interoperability.
  181. The media type is usually passed in 'options[]'.
  182. These variables are deprecated, use ethtool instead. -Ion
  183. */
  184. #define MAX_UNITS 8 /* More are supported, limit only on options */
  185. static int options[MAX_UNITS] = {0, };
  186. static int full_duplex[MAX_UNITS] = {0, };
  187. /* Operational parameters that are set at compile time. */
  188. /* The "native" ring sizes are either 256 or 2048.
  189. However in some modes a descriptor may be marked to wrap the ring earlier.
  190. */
  191. #define RX_RING_SIZE 256
  192. #define TX_RING_SIZE 32
  193. /* The completion queues are fixed at 1024 entries i.e. 4K or 8KB. */
  194. #define DONE_Q_SIZE 1024
  195. /* All queues must be aligned on a 256-byte boundary */
  196. #define QUEUE_ALIGN 256
  197. #if RX_RING_SIZE > 256
  198. #define RX_Q_ENTRIES Rx2048QEntries
  199. #else
  200. #define RX_Q_ENTRIES Rx256QEntries
  201. #endif
  202. /* Operational parameters that usually are not changed. */
  203. /* Time in jiffies before concluding the transmitter is hung. */
  204. #define TX_TIMEOUT (2 * HZ)
  205. /*
  206. * This SUCKS.
  207. * We need a much better method to determine if dma_addr_t is 64-bit.
  208. */
  209. #if (defined(__i386__) && defined(CONFIG_HIGHMEM) && (LINUX_VERSION_CODE > 0x20500 || defined(CONFIG_HIGHMEM64G))) || defined(__x86_64__) || defined (__ia64__) || defined(__mips64__) || (defined(__mips__) && defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR))
  210. /* 64-bit dma_addr_t */
  211. #define ADDR_64BITS /* This chip uses 64 bit addresses. */
  212. #define cpu_to_dma(x) cpu_to_le64(x)
  213. #define dma_to_cpu(x) le64_to_cpu(x)
  214. #define RX_DESC_Q_ADDR_SIZE RxDescQAddr64bit
  215. #define TX_DESC_Q_ADDR_SIZE TxDescQAddr64bit
  216. #define RX_COMPL_Q_ADDR_SIZE RxComplQAddr64bit
  217. #define TX_COMPL_Q_ADDR_SIZE TxComplQAddr64bit
  218. #define RX_DESC_ADDR_SIZE RxDescAddr64bit
  219. #else /* 32-bit dma_addr_t */
  220. #define cpu_to_dma(x) cpu_to_le32(x)
  221. #define dma_to_cpu(x) le32_to_cpu(x)
  222. #define RX_DESC_Q_ADDR_SIZE RxDescQAddr32bit
  223. #define TX_DESC_Q_ADDR_SIZE TxDescQAddr32bit
  224. #define RX_COMPL_Q_ADDR_SIZE RxComplQAddr32bit
  225. #define TX_COMPL_Q_ADDR_SIZE TxComplQAddr32bit
  226. #define RX_DESC_ADDR_SIZE RxDescAddr32bit
  227. #endif
  228. #define skb_first_frag_len(skb) skb_headlen(skb)
  229. #define skb_num_frags(skb) (skb_shinfo(skb)->nr_frags + 1)
  230. #ifdef HAVE_NETDEV_POLL
  231. #define init_poll(dev) \
  232. do { \
  233. dev->poll = &netdev_poll; \
  234. dev->weight = max_interrupt_work; \
  235. } while (0)
  236. #define netdev_rx(dev, ioaddr) \
  237. do { \
  238. u32 intr_enable; \
  239. if (netif_rx_schedule_prep(dev)) { \
  240. __netif_rx_schedule(dev); \
  241. intr_enable = readl(ioaddr + IntrEnable); \
  242. intr_enable &= ~(IntrRxDone | IntrRxEmpty); \
  243. writel(intr_enable, ioaddr + IntrEnable); \
  244. readl(ioaddr + IntrEnable); /* flush PCI posting buffers */ \
  245. } else { \
  246. /* Paranoia check */ \
  247. intr_enable = readl(ioaddr + IntrEnable); \
  248. if (intr_enable & (IntrRxDone | IntrRxEmpty)) { \
  249. printk(KERN_INFO "%s: interrupt while in polling mode!\n", dev->name); \
  250. intr_enable &= ~(IntrRxDone | IntrRxEmpty); \
  251. writel(intr_enable, ioaddr + IntrEnable); \
  252. } \
  253. } \
  254. } while (0)
  255. #define netdev_receive_skb(skb) netif_receive_skb(skb)
  256. #define vlan_netdev_receive_skb(skb, vlgrp, vlid) vlan_hwaccel_receive_skb(skb, vlgrp, vlid)
  257. static int netdev_poll(struct net_device *dev, int *budget);
  258. #else /* not HAVE_NETDEV_POLL */
  259. #define init_poll(dev)
  260. #define netdev_receive_skb(skb) netif_rx(skb)
  261. #define vlan_netdev_receive_skb(skb, vlgrp, vlid) vlan_hwaccel_rx(skb, vlgrp, vlid)
  262. #define netdev_rx(dev, ioaddr) \
  263. do { \
  264. int quota = np->dirty_rx + RX_RING_SIZE - np->cur_rx; \
  265. __netdev_rx(dev, &quota);\
  266. } while (0)
  267. #endif /* not HAVE_NETDEV_POLL */
  268. /* end of compatibility code */
  269. /* These identify the driver base version and may not be removed. */
  270. static char version[] __devinitdata =
  271. KERN_INFO "starfire.c:v1.03 7/26/2000 Written by Donald Becker <becker@scyld.com>\n"
  272. KERN_INFO " (unofficial 2.2/2.4 kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n";
  273. MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
  274. MODULE_DESCRIPTION("Adaptec Starfire Ethernet driver");
  275. MODULE_LICENSE("GPL");
  276. MODULE_VERSION(DRV_VERSION);
  277. module_param(max_interrupt_work, int, 0);
  278. module_param(mtu, int, 0);
  279. module_param(debug, int, 0);
  280. module_param(rx_copybreak, int, 0);
  281. module_param(intr_latency, int, 0);
  282. module_param(small_frames, int, 0);
  283. module_param_array(options, int, NULL, 0);
  284. module_param_array(full_duplex, int, NULL, 0);
  285. module_param(enable_hw_cksum, int, 0);
  286. MODULE_PARM_DESC(max_interrupt_work, "Maximum events handled per interrupt");
  287. MODULE_PARM_DESC(mtu, "MTU (all boards)");
  288. MODULE_PARM_DESC(debug, "Debug level (0-6)");
  289. MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
  290. MODULE_PARM_DESC(intr_latency, "Maximum interrupt latency, in microseconds");
  291. MODULE_PARM_DESC(small_frames, "Maximum size of receive frames that bypass interrupt latency (0,64,128,256,512)");
  292. MODULE_PARM_DESC(options, "Deprecated: Bits 0-3: media type, bit 17: full duplex");
  293. MODULE_PARM_DESC(full_duplex, "Deprecated: Forced full-duplex setting (0/1)");
  294. MODULE_PARM_DESC(enable_hw_cksum, "Enable/disable hardware cksum support (0/1)");
  295. /*
  296. Theory of Operation
  297. I. Board Compatibility
  298. This driver is for the Adaptec 6915 "Starfire" 64 bit PCI Ethernet adapter.
  299. II. Board-specific settings
  300. III. Driver operation
  301. IIIa. Ring buffers
  302. The Starfire hardware uses multiple fixed-size descriptor queues/rings. The
  303. ring sizes are set fixed by the hardware, but may optionally be wrapped
  304. earlier by the END bit in the descriptor.
  305. This driver uses that hardware queue size for the Rx ring, where a large
  306. number of entries has no ill effect beyond increases the potential backlog.
  307. The Tx ring is wrapped with the END bit, since a large hardware Tx queue
  308. disables the queue layer priority ordering and we have no mechanism to
  309. utilize the hardware two-level priority queue. When modifying the
  310. RX/TX_RING_SIZE pay close attention to page sizes and the ring-empty warning
  311. levels.
  312. IIIb/c. Transmit/Receive Structure
  313. See the Adaptec manual for the many possible structures, and options for
  314. each structure. There are far too many to document all of them here.
  315. For transmit this driver uses type 0/1 transmit descriptors (depending
  316. on the 32/64 bitness of the architecture), and relies on automatic
  317. minimum-length padding. It does not use the completion queue
  318. consumer index, but instead checks for non-zero status entries.
  319. For receive this driver uses type 2/3 receive descriptors. The driver
  320. allocates full frame size skbuffs for the Rx ring buffers, so all frames
  321. should fit in a single descriptor. The driver does not use the completion
  322. queue consumer index, but instead checks for non-zero status entries.
  323. When an incoming frame is less than RX_COPYBREAK bytes long, a fresh skbuff
  324. is allocated and the frame is copied to the new skbuff. When the incoming
  325. frame is larger, the skbuff is passed directly up the protocol stack.
  326. Buffers consumed this way are replaced by newly allocated skbuffs in a later
  327. phase of receive.
  328. A notable aspect of operation is that unaligned buffers are not permitted by
  329. the Starfire hardware. Thus the IP header at offset 14 in an ethernet frame
  330. isn't longword aligned, which may cause problems on some machine
  331. e.g. Alphas and IA64. For these architectures, the driver is forced to copy
  332. the frame into a new skbuff unconditionally. Copied frames are put into the
  333. skbuff at an offset of "+2", thus 16-byte aligning the IP header.
  334. IIId. Synchronization
  335. The driver runs as two independent, single-threaded flows of control. One
  336. is the send-packet routine, which enforces single-threaded use by the
  337. dev->tbusy flag. The other thread is the interrupt handler, which is single
  338. threaded by the hardware and interrupt handling software.
  339. The send packet thread has partial control over the Tx ring and the netif_queue
  340. status. If the number of free Tx slots in the ring falls below a certain number
  341. (currently hardcoded to 4), it signals the upper layer to stop the queue.
  342. The interrupt handler has exclusive control over the Rx ring and records stats
  343. from the Tx ring. After reaping the stats, it marks the Tx queue entry as
  344. empty by incrementing the dirty_tx mark. Iff the netif_queue is stopped and the
  345. number of free Tx slow is above the threshold, it signals the upper layer to
  346. restart the queue.
  347. IV. Notes
  348. IVb. References
  349. The Adaptec Starfire manuals, available only from Adaptec.
  350. http://www.scyld.com/expert/100mbps.html
  351. http://www.scyld.com/expert/NWay.html
  352. IVc. Errata
  353. - StopOnPerr is broken, don't enable
  354. - Hardware ethernet padding exposes random data, perform software padding
  355. instead (unverified -- works correctly for all the hardware I have)
  356. */
  357. enum chip_capability_flags {CanHaveMII=1, };
  358. enum chipset {
  359. CH_6915 = 0,
  360. };
  361. static struct pci_device_id starfire_pci_tbl[] = {
  362. { 0x9004, 0x6915, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_6915 },
  363. { 0, }
  364. };
  365. MODULE_DEVICE_TABLE(pci, starfire_pci_tbl);
  366. /* A chip capabilities table, matching the CH_xxx entries in xxx_pci_tbl[] above. */
  367. static struct chip_info {
  368. const char *name;
  369. int drv_flags;
  370. } netdrv_tbl[] __devinitdata = {
  371. { "Adaptec Starfire 6915", CanHaveMII },
  372. };
  373. /* Offsets to the device registers.
  374. Unlike software-only systems, device drivers interact with complex hardware.
  375. It's not useful to define symbolic names for every register bit in the
  376. device. The name can only partially document the semantics and make
  377. the driver longer and more difficult to read.
  378. In general, only the important configuration values or bits changed
  379. multiple times should be defined symbolically.
  380. */
  381. enum register_offsets {
  382. PCIDeviceConfig=0x50040, GenCtrl=0x50070, IntrTimerCtrl=0x50074,
  383. IntrClear=0x50080, IntrStatus=0x50084, IntrEnable=0x50088,
  384. MIICtrl=0x52000, TxStationAddr=0x50120, EEPROMCtrl=0x51000,
  385. GPIOCtrl=0x5008C, TxDescCtrl=0x50090,
  386. TxRingPtr=0x50098, HiPriTxRingPtr=0x50094, /* Low and High priority. */
  387. TxRingHiAddr=0x5009C, /* 64 bit address extension. */
  388. TxProducerIdx=0x500A0, TxConsumerIdx=0x500A4,
  389. TxThreshold=0x500B0,
  390. CompletionHiAddr=0x500B4, TxCompletionAddr=0x500B8,
  391. RxCompletionAddr=0x500BC, RxCompletionQ2Addr=0x500C0,
  392. CompletionQConsumerIdx=0x500C4, RxDMACtrl=0x500D0,
  393. RxDescQCtrl=0x500D4, RxDescQHiAddr=0x500DC, RxDescQAddr=0x500E0,
  394. RxDescQIdx=0x500E8, RxDMAStatus=0x500F0, RxFilterMode=0x500F4,
  395. TxMode=0x55000, VlanType=0x55064,
  396. PerfFilterTable=0x56000, HashTable=0x56100,
  397. TxGfpMem=0x58000, RxGfpMem=0x5a000,
  398. };
  399. /*
  400. * Bits in the interrupt status/mask registers.
  401. * Warning: setting Intr[Ab]NormalSummary in the IntrEnable register
  402. * enables all the interrupt sources that are or'ed into those status bits.
  403. */
  404. enum intr_status_bits {
  405. IntrLinkChange=0xf0000000, IntrStatsMax=0x08000000,
  406. IntrAbnormalSummary=0x02000000, IntrGeneralTimer=0x01000000,
  407. IntrSoftware=0x800000, IntrRxComplQ1Low=0x400000,
  408. IntrTxComplQLow=0x200000, IntrPCI=0x100000,
  409. IntrDMAErr=0x080000, IntrTxDataLow=0x040000,
  410. IntrRxComplQ2Low=0x020000, IntrRxDescQ1Low=0x010000,
  411. IntrNormalSummary=0x8000, IntrTxDone=0x4000,
  412. IntrTxDMADone=0x2000, IntrTxEmpty=0x1000,
  413. IntrEarlyRxQ2=0x0800, IntrEarlyRxQ1=0x0400,
  414. IntrRxQ2Done=0x0200, IntrRxQ1Done=0x0100,
  415. IntrRxGFPDead=0x80, IntrRxDescQ2Low=0x40,
  416. IntrNoTxCsum=0x20, IntrTxBadID=0x10,
  417. IntrHiPriTxBadID=0x08, IntrRxGfp=0x04,
  418. IntrTxGfp=0x02, IntrPCIPad=0x01,
  419. /* not quite bits */
  420. IntrRxDone=IntrRxQ2Done | IntrRxQ1Done,
  421. IntrRxEmpty=IntrRxDescQ1Low | IntrRxDescQ2Low,
  422. IntrNormalMask=0xff00, IntrAbnormalMask=0x3ff00fe,
  423. };
  424. /* Bits in the RxFilterMode register. */
  425. enum rx_mode_bits {
  426. AcceptBroadcast=0x04, AcceptAllMulticast=0x02, AcceptAll=0x01,
  427. AcceptMulticast=0x10, PerfectFilter=0x40, HashFilter=0x30,
  428. PerfectFilterVlan=0x80, MinVLANPrio=0xE000, VlanMode=0x0200,
  429. WakeupOnGFP=0x0800,
  430. };
  431. /* Bits in the TxMode register */
  432. enum tx_mode_bits {
  433. MiiSoftReset=0x8000, MIILoopback=0x4000,
  434. TxFlowEnable=0x0800, RxFlowEnable=0x0400,
  435. PadEnable=0x04, FullDuplex=0x02, HugeFrame=0x01,
  436. };
  437. /* Bits in the TxDescCtrl register. */
  438. enum tx_ctrl_bits {
  439. TxDescSpaceUnlim=0x00, TxDescSpace32=0x10, TxDescSpace64=0x20,
  440. TxDescSpace128=0x30, TxDescSpace256=0x40,
  441. TxDescType0=0x00, TxDescType1=0x01, TxDescType2=0x02,
  442. TxDescType3=0x03, TxDescType4=0x04,
  443. TxNoDMACompletion=0x08,
  444. TxDescQAddr64bit=0x80, TxDescQAddr32bit=0,
  445. TxHiPriFIFOThreshShift=24, TxPadLenShift=16,
  446. TxDMABurstSizeShift=8,
  447. };
  448. /* Bits in the RxDescQCtrl register. */
  449. enum rx_ctrl_bits {
  450. RxBufferLenShift=16, RxMinDescrThreshShift=0,
  451. RxPrefetchMode=0x8000, RxVariableQ=0x2000,
  452. Rx2048QEntries=0x4000, Rx256QEntries=0,
  453. RxDescAddr64bit=0x1000, RxDescAddr32bit=0,
  454. RxDescQAddr64bit=0x0100, RxDescQAddr32bit=0,
  455. RxDescSpace4=0x000, RxDescSpace8=0x100,
  456. RxDescSpace16=0x200, RxDescSpace32=0x300,
  457. RxDescSpace64=0x400, RxDescSpace128=0x500,
  458. RxConsumerWrEn=0x80,
  459. };
  460. /* Bits in the RxDMACtrl register. */
  461. enum rx_dmactrl_bits {
  462. RxReportBadFrames=0x80000000, RxDMAShortFrames=0x40000000,
  463. RxDMABadFrames=0x20000000, RxDMACrcErrorFrames=0x10000000,
  464. RxDMAControlFrame=0x08000000, RxDMAPauseFrame=0x04000000,
  465. RxChecksumIgnore=0, RxChecksumRejectTCPUDP=0x02000000,
  466. RxChecksumRejectTCPOnly=0x01000000,
  467. RxCompletionQ2Enable=0x800000,
  468. RxDMAQ2Disable=0, RxDMAQ2FPOnly=0x100000,
  469. RxDMAQ2SmallPkt=0x200000, RxDMAQ2HighPrio=0x300000,
  470. RxDMAQ2NonIP=0x400000,
  471. RxUseBackupQueue=0x080000, RxDMACRC=0x040000,
  472. RxEarlyIntThreshShift=12, RxHighPrioThreshShift=8,
  473. RxBurstSizeShift=0,
  474. };
  475. /* Bits in the RxCompletionAddr register */
  476. enum rx_compl_bits {
  477. RxComplQAddr64bit=0x80, RxComplQAddr32bit=0,
  478. RxComplProducerWrEn=0x40,
  479. RxComplType0=0x00, RxComplType1=0x10,
  480. RxComplType2=0x20, RxComplType3=0x30,
  481. RxComplThreshShift=0,
  482. };
  483. /* Bits in the TxCompletionAddr register */
  484. enum tx_compl_bits {
  485. TxComplQAddr64bit=0x80, TxComplQAddr32bit=0,
  486. TxComplProducerWrEn=0x40,
  487. TxComplIntrStatus=0x20,
  488. CommonQueueMode=0x10,
  489. TxComplThreshShift=0,
  490. };
  491. /* Bits in the GenCtrl register */
  492. enum gen_ctrl_bits {
  493. RxEnable=0x05, TxEnable=0x0a,
  494. RxGFPEnable=0x10, TxGFPEnable=0x20,
  495. };
  496. /* Bits in the IntrTimerCtrl register */
  497. enum intr_ctrl_bits {
  498. Timer10X=0x800, EnableIntrMasking=0x60, SmallFrameBypass=0x100,
  499. SmallFrame64=0, SmallFrame128=0x200, SmallFrame256=0x400, SmallFrame512=0x600,
  500. IntrLatencyMask=0x1f,
  501. };
  502. /* The Rx and Tx buffer descriptors. */
  503. struct starfire_rx_desc {
  504. dma_addr_t rxaddr;
  505. };
  506. enum rx_desc_bits {
  507. RxDescValid=1, RxDescEndRing=2,
  508. };
  509. /* Completion queue entry. */
  510. struct short_rx_done_desc {
  511. u32 status; /* Low 16 bits is length. */
  512. };
  513. struct basic_rx_done_desc {
  514. u32 status; /* Low 16 bits is length. */
  515. u16 vlanid;
  516. u16 status2;
  517. };
  518. struct csum_rx_done_desc {
  519. u32 status; /* Low 16 bits is length. */
  520. u16 csum; /* Partial checksum */
  521. u16 status2;
  522. };
  523. struct full_rx_done_desc {
  524. u32 status; /* Low 16 bits is length. */
  525. u16 status3;
  526. u16 status2;
  527. u16 vlanid;
  528. u16 csum; /* partial checksum */
  529. u32 timestamp;
  530. };
  531. /* XXX: this is ugly and I'm not sure it's worth the trouble -Ion */
  532. #ifdef VLAN_SUPPORT
  533. typedef struct full_rx_done_desc rx_done_desc;
  534. #define RxComplType RxComplType3
  535. #else /* not VLAN_SUPPORT */
  536. typedef struct csum_rx_done_desc rx_done_desc;
  537. #define RxComplType RxComplType2
  538. #endif /* not VLAN_SUPPORT */
  539. enum rx_done_bits {
  540. RxOK=0x20000000, RxFIFOErr=0x10000000, RxBufQ2=0x08000000,
  541. };
  542. /* Type 1 Tx descriptor. */
  543. struct starfire_tx_desc_1 {
  544. u32 status; /* Upper bits are status, lower 16 length. */
  545. u32 addr;
  546. };
  547. /* Type 2 Tx descriptor. */
  548. struct starfire_tx_desc_2 {
  549. u32 status; /* Upper bits are status, lower 16 length. */
  550. u32 reserved;
  551. u64 addr;
  552. };
  553. #ifdef ADDR_64BITS
  554. typedef struct starfire_tx_desc_2 starfire_tx_desc;
  555. #define TX_DESC_TYPE TxDescType2
  556. #else /* not ADDR_64BITS */
  557. typedef struct starfire_tx_desc_1 starfire_tx_desc;
  558. #define TX_DESC_TYPE TxDescType1
  559. #endif /* not ADDR_64BITS */
  560. #define TX_DESC_SPACING TxDescSpaceUnlim
  561. enum tx_desc_bits {
  562. TxDescID=0xB0000000,
  563. TxCRCEn=0x01000000, TxDescIntr=0x08000000,
  564. TxRingWrap=0x04000000, TxCalTCP=0x02000000,
  565. };
  566. struct tx_done_desc {
  567. u32 status; /* timestamp, index. */
  568. #if 0
  569. u32 intrstatus; /* interrupt status */
  570. #endif
  571. };
  572. struct rx_ring_info {
  573. struct sk_buff *skb;
  574. dma_addr_t mapping;
  575. };
  576. struct tx_ring_info {
  577. struct sk_buff *skb;
  578. dma_addr_t mapping;
  579. unsigned int used_slots;
  580. };
  581. #define PHY_CNT 2
  582. struct netdev_private {
  583. /* Descriptor rings first for alignment. */
  584. struct starfire_rx_desc *rx_ring;
  585. starfire_tx_desc *tx_ring;
  586. dma_addr_t rx_ring_dma;
  587. dma_addr_t tx_ring_dma;
  588. /* The addresses of rx/tx-in-place skbuffs. */
  589. struct rx_ring_info rx_info[RX_RING_SIZE];
  590. struct tx_ring_info tx_info[TX_RING_SIZE];
  591. /* Pointers to completion queues (full pages). */
  592. rx_done_desc *rx_done_q;
  593. dma_addr_t rx_done_q_dma;
  594. unsigned int rx_done;
  595. struct tx_done_desc *tx_done_q;
  596. dma_addr_t tx_done_q_dma;
  597. unsigned int tx_done;
  598. struct net_device_stats stats;
  599. struct pci_dev *pci_dev;
  600. #ifdef VLAN_SUPPORT
  601. struct vlan_group *vlgrp;
  602. #endif
  603. void *queue_mem;
  604. dma_addr_t queue_mem_dma;
  605. size_t queue_mem_size;
  606. /* Frequently used values: keep some adjacent for cache effect. */
  607. spinlock_t lock;
  608. unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */
  609. unsigned int cur_tx, dirty_tx, reap_tx;
  610. unsigned int rx_buf_sz; /* Based on MTU+slack. */
  611. /* These values keep track of the transceiver/media in use. */
  612. int speed100; /* Set if speed == 100MBit. */
  613. u32 tx_mode;
  614. u32 intr_timer_ctrl;
  615. u8 tx_threshold;
  616. /* MII transceiver section. */
  617. struct mii_if_info mii_if; /* MII lib hooks/info */
  618. int phy_cnt; /* MII device addresses. */
  619. unsigned char phys[PHY_CNT]; /* MII device addresses. */
  620. void __iomem *base;
  621. };
  622. static int mdio_read(struct net_device *dev, int phy_id, int location);
  623. static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
  624. static int netdev_open(struct net_device *dev);
  625. static void check_duplex(struct net_device *dev);
  626. static void tx_timeout(struct net_device *dev);
  627. static void init_ring(struct net_device *dev);
  628. static int start_tx(struct sk_buff *skb, struct net_device *dev);
  629. static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
  630. static void netdev_error(struct net_device *dev, int intr_status);
  631. static int __netdev_rx(struct net_device *dev, int *quota);
  632. static void refill_rx_ring(struct net_device *dev);
  633. static void netdev_error(struct net_device *dev, int intr_status);
  634. static void set_rx_mode(struct net_device *dev);
  635. static struct net_device_stats *get_stats(struct net_device *dev);
  636. static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  637. static int netdev_close(struct net_device *dev);
  638. static void netdev_media_change(struct net_device *dev);
  639. static struct ethtool_ops ethtool_ops;
  640. #ifdef VLAN_SUPPORT
  641. static void netdev_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  642. {
  643. struct netdev_private *np = netdev_priv(dev);
  644. spin_lock(&np->lock);
  645. if (debug > 2)
  646. printk("%s: Setting vlgrp to %p\n", dev->name, grp);
  647. np->vlgrp = grp;
  648. set_rx_mode(dev);
  649. spin_unlock(&np->lock);
  650. }
  651. static void netdev_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
  652. {
  653. struct netdev_private *np = netdev_priv(dev);
  654. spin_lock(&np->lock);
  655. if (debug > 1)
  656. printk("%s: Adding vlanid %d to vlan filter\n", dev->name, vid);
  657. set_rx_mode(dev);
  658. spin_unlock(&np->lock);
  659. }
  660. static void netdev_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  661. {
  662. struct netdev_private *np = netdev_priv(dev);
  663. spin_lock(&np->lock);
  664. if (debug > 1)
  665. printk("%s: removing vlanid %d from vlan filter\n", dev->name, vid);
  666. if (np->vlgrp)
  667. np->vlgrp->vlan_devices[vid] = NULL;
  668. set_rx_mode(dev);
  669. spin_unlock(&np->lock);
  670. }
  671. #endif /* VLAN_SUPPORT */
  672. static int __devinit starfire_init_one(struct pci_dev *pdev,
  673. const struct pci_device_id *ent)
  674. {
  675. struct netdev_private *np;
  676. int i, irq, option, chip_idx = ent->driver_data;
  677. struct net_device *dev;
  678. static int card_idx = -1;
  679. long ioaddr;
  680. void __iomem *base;
  681. int drv_flags, io_size;
  682. int boguscnt;
  683. /* when built into the kernel, we only print version if device is found */
  684. #ifndef MODULE
  685. static int printed_version;
  686. if (!printed_version++)
  687. printk(version);
  688. #endif
  689. card_idx++;
  690. if (pci_enable_device (pdev))
  691. return -EIO;
  692. ioaddr = pci_resource_start(pdev, 0);
  693. io_size = pci_resource_len(pdev, 0);
  694. if (!ioaddr || ((pci_resource_flags(pdev, 0) & IORESOURCE_MEM) == 0)) {
  695. printk(KERN_ERR DRV_NAME " %d: no PCI MEM resources, aborting\n", card_idx);
  696. return -ENODEV;
  697. }
  698. dev = alloc_etherdev(sizeof(*np));
  699. if (!dev) {
  700. printk(KERN_ERR DRV_NAME " %d: cannot alloc etherdev, aborting\n", card_idx);
  701. return -ENOMEM;
  702. }
  703. SET_MODULE_OWNER(dev);
  704. SET_NETDEV_DEV(dev, &pdev->dev);
  705. irq = pdev->irq;
  706. if (pci_request_regions (pdev, DRV_NAME)) {
  707. printk(KERN_ERR DRV_NAME " %d: cannot reserve PCI resources, aborting\n", card_idx);
  708. goto err_out_free_netdev;
  709. }
  710. /* ioremap is borken in Linux-2.2.x/sparc64 */
  711. base = ioremap(ioaddr, io_size);
  712. if (!base) {
  713. printk(KERN_ERR DRV_NAME " %d: cannot remap %#x @ %#lx, aborting\n",
  714. card_idx, io_size, ioaddr);
  715. goto err_out_free_res;
  716. }
  717. pci_set_master(pdev);
  718. /* enable MWI -- it vastly improves Rx performance on sparc64 */
  719. pci_set_mwi(pdev);
  720. #ifdef ZEROCOPY
  721. /* Starfire can do TCP/UDP checksumming */
  722. if (enable_hw_cksum)
  723. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  724. #endif /* ZEROCOPY */
  725. #ifdef VLAN_SUPPORT
  726. dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
  727. dev->vlan_rx_register = netdev_vlan_rx_register;
  728. dev->vlan_rx_add_vid = netdev_vlan_rx_add_vid;
  729. dev->vlan_rx_kill_vid = netdev_vlan_rx_kill_vid;
  730. #endif /* VLAN_RX_KILL_VID */
  731. #ifdef ADDR_64BITS
  732. dev->features |= NETIF_F_HIGHDMA;
  733. #endif /* ADDR_64BITS */
  734. /* Serial EEPROM reads are hidden by the hardware. */
  735. for (i = 0; i < 6; i++)
  736. dev->dev_addr[i] = readb(base + EEPROMCtrl + 20 - i);
  737. #if ! defined(final_version) /* Dump the EEPROM contents during development. */
  738. if (debug > 4)
  739. for (i = 0; i < 0x20; i++)
  740. printk("%2.2x%s",
  741. (unsigned int)readb(base + EEPROMCtrl + i),
  742. i % 16 != 15 ? " " : "\n");
  743. #endif
  744. /* Issue soft reset */
  745. writel(MiiSoftReset, base + TxMode);
  746. udelay(1000);
  747. writel(0, base + TxMode);
  748. /* Reset the chip to erase previous misconfiguration. */
  749. writel(1, base + PCIDeviceConfig);
  750. boguscnt = 1000;
  751. while (--boguscnt > 0) {
  752. udelay(10);
  753. if ((readl(base + PCIDeviceConfig) & 1) == 0)
  754. break;
  755. }
  756. if (boguscnt == 0)
  757. printk("%s: chipset reset never completed!\n", dev->name);
  758. /* wait a little longer */
  759. udelay(1000);
  760. dev->base_addr = (unsigned long)base;
  761. dev->irq = irq;
  762. np = netdev_priv(dev);
  763. np->base = base;
  764. spin_lock_init(&np->lock);
  765. pci_set_drvdata(pdev, dev);
  766. np->pci_dev = pdev;
  767. np->mii_if.dev = dev;
  768. np->mii_if.mdio_read = mdio_read;
  769. np->mii_if.mdio_write = mdio_write;
  770. np->mii_if.phy_id_mask = 0x1f;
  771. np->mii_if.reg_num_mask = 0x1f;
  772. drv_flags = netdrv_tbl[chip_idx].drv_flags;
  773. option = card_idx < MAX_UNITS ? options[card_idx] : 0;
  774. if (dev->mem_start)
  775. option = dev->mem_start;
  776. /* The lower four bits are the media type. */
  777. if (option & 0x200)
  778. np->mii_if.full_duplex = 1;
  779. if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0)
  780. np->mii_if.full_duplex = 1;
  781. if (np->mii_if.full_duplex)
  782. np->mii_if.force_media = 1;
  783. else
  784. np->mii_if.force_media = 0;
  785. np->speed100 = 1;
  786. /* timer resolution is 128 * 0.8us */
  787. np->intr_timer_ctrl = (((intr_latency * 10) / 1024) & IntrLatencyMask) |
  788. Timer10X | EnableIntrMasking;
  789. if (small_frames > 0) {
  790. np->intr_timer_ctrl |= SmallFrameBypass;
  791. switch (small_frames) {
  792. case 1 ... 64:
  793. np->intr_timer_ctrl |= SmallFrame64;
  794. break;
  795. case 65 ... 128:
  796. np->intr_timer_ctrl |= SmallFrame128;
  797. break;
  798. case 129 ... 256:
  799. np->intr_timer_ctrl |= SmallFrame256;
  800. break;
  801. default:
  802. np->intr_timer_ctrl |= SmallFrame512;
  803. if (small_frames > 512)
  804. printk("Adjusting small_frames down to 512\n");
  805. break;
  806. }
  807. }
  808. /* The chip-specific entries in the device structure. */
  809. dev->open = &netdev_open;
  810. dev->hard_start_xmit = &start_tx;
  811. dev->tx_timeout = tx_timeout;
  812. dev->watchdog_timeo = TX_TIMEOUT;
  813. init_poll(dev);
  814. dev->stop = &netdev_close;
  815. dev->get_stats = &get_stats;
  816. dev->set_multicast_list = &set_rx_mode;
  817. dev->do_ioctl = &netdev_ioctl;
  818. SET_ETHTOOL_OPS(dev, &ethtool_ops);
  819. if (mtu)
  820. dev->mtu = mtu;
  821. if (register_netdev(dev))
  822. goto err_out_cleardev;
  823. printk(KERN_INFO "%s: %s at %p, ",
  824. dev->name, netdrv_tbl[chip_idx].name, base);
  825. for (i = 0; i < 5; i++)
  826. printk("%2.2x:", dev->dev_addr[i]);
  827. printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
  828. if (drv_flags & CanHaveMII) {
  829. int phy, phy_idx = 0;
  830. int mii_status;
  831. for (phy = 0; phy < 32 && phy_idx < PHY_CNT; phy++) {
  832. mdio_write(dev, phy, MII_BMCR, BMCR_RESET);
  833. mdelay(100);
  834. boguscnt = 1000;
  835. while (--boguscnt > 0)
  836. if ((mdio_read(dev, phy, MII_BMCR) & BMCR_RESET) == 0)
  837. break;
  838. if (boguscnt == 0) {
  839. printk("%s: PHY#%d reset never completed!\n", dev->name, phy);
  840. continue;
  841. }
  842. mii_status = mdio_read(dev, phy, MII_BMSR);
  843. if (mii_status != 0) {
  844. np->phys[phy_idx++] = phy;
  845. np->mii_if.advertising = mdio_read(dev, phy, MII_ADVERTISE);
  846. printk(KERN_INFO "%s: MII PHY found at address %d, status "
  847. "%#4.4x advertising %#4.4x.\n",
  848. dev->name, phy, mii_status, np->mii_if.advertising);
  849. /* there can be only one PHY on-board */
  850. break;
  851. }
  852. }
  853. np->phy_cnt = phy_idx;
  854. if (np->phy_cnt > 0)
  855. np->mii_if.phy_id = np->phys[0];
  856. else
  857. memset(&np->mii_if, 0, sizeof(np->mii_if));
  858. }
  859. printk(KERN_INFO "%s: scatter-gather and hardware TCP cksumming %s.\n",
  860. dev->name, enable_hw_cksum ? "enabled" : "disabled");
  861. return 0;
  862. err_out_cleardev:
  863. pci_set_drvdata(pdev, NULL);
  864. iounmap(base);
  865. err_out_free_res:
  866. pci_release_regions (pdev);
  867. err_out_free_netdev:
  868. free_netdev(dev);
  869. return -ENODEV;
  870. }
  871. /* Read the MII Management Data I/O (MDIO) interfaces. */
  872. static int mdio_read(struct net_device *dev, int phy_id, int location)
  873. {
  874. struct netdev_private *np = netdev_priv(dev);
  875. void __iomem *mdio_addr = np->base + MIICtrl + (phy_id<<7) + (location<<2);
  876. int result, boguscnt=1000;
  877. /* ??? Should we add a busy-wait here? */
  878. do
  879. result = readl(mdio_addr);
  880. while ((result & 0xC0000000) != 0x80000000 && --boguscnt > 0);
  881. if (boguscnt == 0)
  882. return 0;
  883. if ((result & 0xffff) == 0xffff)
  884. return 0;
  885. return result & 0xffff;
  886. }
  887. static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
  888. {
  889. struct netdev_private *np = netdev_priv(dev);
  890. void __iomem *mdio_addr = np->base + MIICtrl + (phy_id<<7) + (location<<2);
  891. writel(value, mdio_addr);
  892. /* The busy-wait will occur before a read. */
  893. }
  894. static int netdev_open(struct net_device *dev)
  895. {
  896. struct netdev_private *np = netdev_priv(dev);
  897. void __iomem *ioaddr = np->base;
  898. int i, retval;
  899. size_t tx_done_q_size, rx_done_q_size, tx_ring_size, rx_ring_size;
  900. /* Do we ever need to reset the chip??? */
  901. retval = request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev);
  902. if (retval)
  903. return retval;
  904. /* Disable the Rx and Tx, and reset the chip. */
  905. writel(0, ioaddr + GenCtrl);
  906. writel(1, ioaddr + PCIDeviceConfig);
  907. if (debug > 1)
  908. printk(KERN_DEBUG "%s: netdev_open() irq %d.\n",
  909. dev->name, dev->irq);
  910. /* Allocate the various queues. */
  911. if (np->queue_mem == 0) {
  912. tx_done_q_size = ((sizeof(struct tx_done_desc) * DONE_Q_SIZE + QUEUE_ALIGN - 1) / QUEUE_ALIGN) * QUEUE_ALIGN;
  913. rx_done_q_size = ((sizeof(rx_done_desc) * DONE_Q_SIZE + QUEUE_ALIGN - 1) / QUEUE_ALIGN) * QUEUE_ALIGN;
  914. tx_ring_size = ((sizeof(starfire_tx_desc) * TX_RING_SIZE + QUEUE_ALIGN - 1) / QUEUE_ALIGN) * QUEUE_ALIGN;
  915. rx_ring_size = sizeof(struct starfire_rx_desc) * RX_RING_SIZE;
  916. np->queue_mem_size = tx_done_q_size + rx_done_q_size + tx_ring_size + rx_ring_size;
  917. np->queue_mem = pci_alloc_consistent(np->pci_dev, np->queue_mem_size, &np->queue_mem_dma);
  918. if (np->queue_mem == 0)
  919. return -ENOMEM;
  920. np->tx_done_q = np->queue_mem;
  921. np->tx_done_q_dma = np->queue_mem_dma;
  922. np->rx_done_q = (void *) np->tx_done_q + tx_done_q_size;
  923. np->rx_done_q_dma = np->tx_done_q_dma + tx_done_q_size;
  924. np->tx_ring = (void *) np->rx_done_q + rx_done_q_size;
  925. np->tx_ring_dma = np->rx_done_q_dma + rx_done_q_size;
  926. np->rx_ring = (void *) np->tx_ring + tx_ring_size;
  927. np->rx_ring_dma = np->tx_ring_dma + tx_ring_size;
  928. }
  929. /* Start with no carrier, it gets adjusted later */
  930. netif_carrier_off(dev);
  931. init_ring(dev);
  932. /* Set the size of the Rx buffers. */
  933. writel((np->rx_buf_sz << RxBufferLenShift) |
  934. (0 << RxMinDescrThreshShift) |
  935. RxPrefetchMode | RxVariableQ |
  936. RX_Q_ENTRIES |
  937. RX_DESC_Q_ADDR_SIZE | RX_DESC_ADDR_SIZE |
  938. RxDescSpace4,
  939. ioaddr + RxDescQCtrl);
  940. /* Set up the Rx DMA controller. */
  941. writel(RxChecksumIgnore |
  942. (0 << RxEarlyIntThreshShift) |
  943. (6 << RxHighPrioThreshShift) |
  944. ((DMA_BURST_SIZE / 32) << RxBurstSizeShift),
  945. ioaddr + RxDMACtrl);
  946. /* Set Tx descriptor */
  947. writel((2 << TxHiPriFIFOThreshShift) |
  948. (0 << TxPadLenShift) |
  949. ((DMA_BURST_SIZE / 32) << TxDMABurstSizeShift) |
  950. TX_DESC_Q_ADDR_SIZE |
  951. TX_DESC_SPACING | TX_DESC_TYPE,
  952. ioaddr + TxDescCtrl);
  953. writel( (np->queue_mem_dma >> 16) >> 16, ioaddr + RxDescQHiAddr);
  954. writel( (np->queue_mem_dma >> 16) >> 16, ioaddr + TxRingHiAddr);
  955. writel( (np->queue_mem_dma >> 16) >> 16, ioaddr + CompletionHiAddr);
  956. writel(np->rx_ring_dma, ioaddr + RxDescQAddr);
  957. writel(np->tx_ring_dma, ioaddr + TxRingPtr);
  958. writel(np->tx_done_q_dma, ioaddr + TxCompletionAddr);
  959. writel(np->rx_done_q_dma |
  960. RxComplType |
  961. (0 << RxComplThreshShift),
  962. ioaddr + RxCompletionAddr);
  963. if (debug > 1)
  964. printk(KERN_DEBUG "%s: Filling in the station address.\n", dev->name);
  965. /* Fill both the Tx SA register and the Rx perfect filter. */
  966. for (i = 0; i < 6; i++)
  967. writeb(dev->dev_addr[i], ioaddr + TxStationAddr + 5 - i);
  968. /* The first entry is special because it bypasses the VLAN filter.
  969. Don't use it. */
  970. writew(0, ioaddr + PerfFilterTable);
  971. writew(0, ioaddr + PerfFilterTable + 4);
  972. writew(0, ioaddr + PerfFilterTable + 8);
  973. for (i = 1; i < 16; i++) {
  974. u16 *eaddrs = (u16 *)dev->dev_addr;
  975. void __iomem *setup_frm = ioaddr + PerfFilterTable + i * 16;
  976. writew(cpu_to_be16(eaddrs[2]), setup_frm); setup_frm += 4;
  977. writew(cpu_to_be16(eaddrs[1]), setup_frm); setup_frm += 4;
  978. writew(cpu_to_be16(eaddrs[0]), setup_frm); setup_frm += 8;
  979. }
  980. /* Initialize other registers. */
  981. /* Configure the PCI bus bursts and FIFO thresholds. */
  982. np->tx_mode = TxFlowEnable|RxFlowEnable|PadEnable; /* modified when link is up. */
  983. writel(MiiSoftReset | np->tx_mode, ioaddr + TxMode);
  984. udelay(1000);
  985. writel(np->tx_mode, ioaddr + TxMode);
  986. np->tx_threshold = 4;
  987. writel(np->tx_threshold, ioaddr + TxThreshold);
  988. writel(np->intr_timer_ctrl, ioaddr + IntrTimerCtrl);
  989. netif_start_queue(dev);
  990. if (debug > 1)
  991. printk(KERN_DEBUG "%s: Setting the Rx and Tx modes.\n", dev->name);
  992. set_rx_mode(dev);
  993. np->mii_if.advertising = mdio_read(dev, np->phys[0], MII_ADVERTISE);
  994. check_duplex(dev);
  995. /* Enable GPIO interrupts on link change */
  996. writel(0x0f00ff00, ioaddr + GPIOCtrl);
  997. /* Set the interrupt mask */
  998. writel(IntrRxDone | IntrRxEmpty | IntrDMAErr |
  999. IntrTxDMADone | IntrStatsMax | IntrLinkChange |
  1000. IntrRxGFPDead | IntrNoTxCsum | IntrTxBadID,
  1001. ioaddr + IntrEnable);
  1002. /* Enable PCI interrupts. */
  1003. writel(0x00800000 | readl(ioaddr + PCIDeviceConfig),
  1004. ioaddr + PCIDeviceConfig);
  1005. #ifdef VLAN_SUPPORT
  1006. /* Set VLAN type to 802.1q */
  1007. writel(ETH_P_8021Q, ioaddr + VlanType);
  1008. #endif /* VLAN_SUPPORT */
  1009. /* Load Rx/Tx firmware into the frame processors */
  1010. for (i = 0; i < FIRMWARE_RX_SIZE * 2; i++)
  1011. writel(firmware_rx[i], ioaddr + RxGfpMem + i * 4);
  1012. for (i = 0; i < FIRMWARE_TX_SIZE * 2; i++)
  1013. writel(firmware_tx[i], ioaddr + TxGfpMem + i * 4);
  1014. if (enable_hw_cksum)
  1015. /* Enable the Rx and Tx units, and the Rx/Tx frame processors. */
  1016. writel(TxEnable|TxGFPEnable|RxEnable|RxGFPEnable, ioaddr + GenCtrl);
  1017. else
  1018. /* Enable the Rx and Tx units only. */
  1019. writel(TxEnable|RxEnable, ioaddr + GenCtrl);
  1020. if (debug > 1)
  1021. printk(KERN_DEBUG "%s: Done netdev_open().\n",
  1022. dev->name);
  1023. return 0;
  1024. }
  1025. static void check_duplex(struct net_device *dev)
  1026. {
  1027. struct netdev_private *np = netdev_priv(dev);
  1028. u16 reg0;
  1029. int silly_count = 1000;
  1030. mdio_write(dev, np->phys[0], MII_ADVERTISE, np->mii_if.advertising);
  1031. mdio_write(dev, np->phys[0], MII_BMCR, BMCR_RESET);
  1032. udelay(500);
  1033. while (--silly_count && mdio_read(dev, np->phys[0], MII_BMCR) & BMCR_RESET)
  1034. /* do nothing */;
  1035. if (!silly_count) {
  1036. printk("%s: MII reset failed!\n", dev->name);
  1037. return;
  1038. }
  1039. reg0 = mdio_read(dev, np->phys[0], MII_BMCR);
  1040. if (!np->mii_if.force_media) {
  1041. reg0 |= BMCR_ANENABLE | BMCR_ANRESTART;
  1042. } else {
  1043. reg0 &= ~(BMCR_ANENABLE | BMCR_ANRESTART);
  1044. if (np->speed100)
  1045. reg0 |= BMCR_SPEED100;
  1046. if (np->mii_if.full_duplex)
  1047. reg0 |= BMCR_FULLDPLX;
  1048. printk(KERN_DEBUG "%s: Link forced to %sMbit %s-duplex\n",
  1049. dev->name,
  1050. np->speed100 ? "100" : "10",
  1051. np->mii_if.full_duplex ? "full" : "half");
  1052. }
  1053. mdio_write(dev, np->phys[0], MII_BMCR, reg0);
  1054. }
  1055. static void tx_timeout(struct net_device *dev)
  1056. {
  1057. struct netdev_private *np = netdev_priv(dev);
  1058. void __iomem *ioaddr = np->base;
  1059. int old_debug;
  1060. printk(KERN_WARNING "%s: Transmit timed out, status %#8.8x, "
  1061. "resetting...\n", dev->name, (int) readl(ioaddr + IntrStatus));
  1062. /* Perhaps we should reinitialize the hardware here. */
  1063. /*
  1064. * Stop and restart the interface.
  1065. * Cheat and increase the debug level temporarily.
  1066. */
  1067. old_debug = debug;
  1068. debug = 2;
  1069. netdev_close(dev);
  1070. netdev_open(dev);
  1071. debug = old_debug;
  1072. /* Trigger an immediate transmit demand. */
  1073. dev->trans_start = jiffies;
  1074. np->stats.tx_errors++;
  1075. netif_wake_queue(dev);
  1076. }
  1077. /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  1078. static void init_ring(struct net_device *dev)
  1079. {
  1080. struct netdev_private *np = netdev_priv(dev);
  1081. int i;
  1082. np->cur_rx = np->cur_tx = np->reap_tx = 0;
  1083. np->dirty_rx = np->dirty_tx = np->rx_done = np->tx_done = 0;
  1084. np->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
  1085. /* Fill in the Rx buffers. Handle allocation failure gracefully. */
  1086. for (i = 0; i < RX_RING_SIZE; i++) {
  1087. struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
  1088. np->rx_info[i].skb = skb;
  1089. if (skb == NULL)
  1090. break;
  1091. np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1092. skb->dev = dev; /* Mark as being used by this device. */
  1093. /* Grrr, we cannot offset to correctly align the IP header. */
  1094. np->rx_ring[i].rxaddr = cpu_to_dma(np->rx_info[i].mapping | RxDescValid);
  1095. }
  1096. writew(i - 1, np->base + RxDescQIdx);
  1097. np->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
  1098. /* Clear the remainder of the Rx buffer ring. */
  1099. for ( ; i < RX_RING_SIZE; i++) {
  1100. np->rx_ring[i].rxaddr = 0;
  1101. np->rx_info[i].skb = NULL;
  1102. np->rx_info[i].mapping = 0;
  1103. }
  1104. /* Mark the last entry as wrapping the ring. */
  1105. np->rx_ring[RX_RING_SIZE - 1].rxaddr |= cpu_to_dma(RxDescEndRing);
  1106. /* Clear the completion rings. */
  1107. for (i = 0; i < DONE_Q_SIZE; i++) {
  1108. np->rx_done_q[i].status = 0;
  1109. np->tx_done_q[i].status = 0;
  1110. }
  1111. for (i = 0; i < TX_RING_SIZE; i++)
  1112. memset(&np->tx_info[i], 0, sizeof(np->tx_info[i]));
  1113. return;
  1114. }
  1115. static int start_tx(struct sk_buff *skb, struct net_device *dev)
  1116. {
  1117. struct netdev_private *np = netdev_priv(dev);
  1118. unsigned int entry;
  1119. u32 status;
  1120. int i;
  1121. /*
  1122. * be cautious here, wrapping the queue has weird semantics
  1123. * and we may not have enough slots even when it seems we do.
  1124. */
  1125. if ((np->cur_tx - np->dirty_tx) + skb_num_frags(skb) * 2 > TX_RING_SIZE) {
  1126. netif_stop_queue(dev);
  1127. return 1;
  1128. }
  1129. #if defined(ZEROCOPY) && defined(HAS_BROKEN_FIRMWARE)
  1130. {
  1131. int has_bad_length = 0;
  1132. if (skb_first_frag_len(skb) == 1)
  1133. has_bad_length = 1;
  1134. else {
  1135. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  1136. if (skb_shinfo(skb)->frags[i].size == 1) {
  1137. has_bad_length = 1;
  1138. break;
  1139. }
  1140. }
  1141. if (has_bad_length)
  1142. skb_checksum_help(skb, 0);
  1143. }
  1144. #endif /* ZEROCOPY && HAS_BROKEN_FIRMWARE */
  1145. entry = np->cur_tx % TX_RING_SIZE;
  1146. for (i = 0; i < skb_num_frags(skb); i++) {
  1147. int wrap_ring = 0;
  1148. status = TxDescID;
  1149. if (i == 0) {
  1150. np->tx_info[entry].skb = skb;
  1151. status |= TxCRCEn;
  1152. if (entry >= TX_RING_SIZE - skb_num_frags(skb)) {
  1153. status |= TxRingWrap;
  1154. wrap_ring = 1;
  1155. }
  1156. if (np->reap_tx) {
  1157. status |= TxDescIntr;
  1158. np->reap_tx = 0;
  1159. }
  1160. if (skb->ip_summed == CHECKSUM_HW) {
  1161. status |= TxCalTCP;
  1162. np->stats.tx_compressed++;
  1163. }
  1164. status |= skb_first_frag_len(skb) | (skb_num_frags(skb) << 16);
  1165. np->tx_info[entry].mapping =
  1166. pci_map_single(np->pci_dev, skb->data, skb_first_frag_len(skb), PCI_DMA_TODEVICE);
  1167. } else {
  1168. skb_frag_t *this_frag = &skb_shinfo(skb)->frags[i - 1];
  1169. status |= this_frag->size;
  1170. np->tx_info[entry].mapping =
  1171. pci_map_single(np->pci_dev, page_address(this_frag->page) + this_frag->page_offset, this_frag->size, PCI_DMA_TODEVICE);
  1172. }
  1173. np->tx_ring[entry].addr = cpu_to_dma(np->tx_info[entry].mapping);
  1174. np->tx_ring[entry].status = cpu_to_le32(status);
  1175. if (debug > 3)
  1176. printk(KERN_DEBUG "%s: Tx #%d/#%d slot %d status %#8.8x.\n",
  1177. dev->name, np->cur_tx, np->dirty_tx,
  1178. entry, status);
  1179. if (wrap_ring) {
  1180. np->tx_info[entry].used_slots = TX_RING_SIZE - entry;
  1181. np->cur_tx += np->tx_info[entry].used_slots;
  1182. entry = 0;
  1183. } else {
  1184. np->tx_info[entry].used_slots = 1;
  1185. np->cur_tx += np->tx_info[entry].used_slots;
  1186. entry++;
  1187. }
  1188. /* scavenge the tx descriptors twice per TX_RING_SIZE */
  1189. if (np->cur_tx % (TX_RING_SIZE / 2) == 0)
  1190. np->reap_tx = 1;
  1191. }
  1192. /* Non-x86: explicitly flush descriptor cache lines here. */
  1193. /* Ensure all descriptors are written back before the transmit is
  1194. initiated. - Jes */
  1195. wmb();
  1196. /* Update the producer index. */
  1197. writel(entry * (sizeof(starfire_tx_desc) / 8), np->base + TxProducerIdx);
  1198. /* 4 is arbitrary, but should be ok */
  1199. if ((np->cur_tx - np->dirty_tx) + 4 > TX_RING_SIZE)
  1200. netif_stop_queue(dev);
  1201. dev->trans_start = jiffies;
  1202. return 0;
  1203. }
  1204. /* The interrupt handler does all of the Rx thread work and cleans up
  1205. after the Tx thread. */
  1206. static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs)
  1207. {
  1208. struct net_device *dev = dev_instance;
  1209. struct netdev_private *np = netdev_priv(dev);
  1210. void __iomem *ioaddr = np->base;
  1211. int boguscnt = max_interrupt_work;
  1212. int consumer;
  1213. int tx_status;
  1214. int handled = 0;
  1215. do {
  1216. u32 intr_status = readl(ioaddr + IntrClear);
  1217. if (debug > 4)
  1218. printk(KERN_DEBUG "%s: Interrupt status %#8.8x.\n",
  1219. dev->name, intr_status);
  1220. if (intr_status == 0 || intr_status == (u32) -1)
  1221. break;
  1222. handled = 1;
  1223. if (intr_status & (IntrRxDone | IntrRxEmpty))
  1224. netdev_rx(dev, ioaddr);
  1225. /* Scavenge the skbuff list based on the Tx-done queue.
  1226. There are redundant checks here that may be cleaned up
  1227. after the driver has proven to be reliable. */
  1228. consumer = readl(ioaddr + TxConsumerIdx);
  1229. if (debug > 3)
  1230. printk(KERN_DEBUG "%s: Tx Consumer index is %d.\n",
  1231. dev->name, consumer);
  1232. while ((tx_status = le32_to_cpu(np->tx_done_q[np->tx_done].status)) != 0) {
  1233. if (debug > 3)
  1234. printk(KERN_DEBUG "%s: Tx completion #%d entry %d is %#8.8x.\n",
  1235. dev->name, np->dirty_tx, np->tx_done, tx_status);
  1236. if ((tx_status & 0xe0000000) == 0xa0000000) {
  1237. np->stats.tx_packets++;
  1238. } else if ((tx_status & 0xe0000000) == 0x80000000) {
  1239. u16 entry = (tx_status & 0x7fff) / sizeof(starfire_tx_desc);
  1240. struct sk_buff *skb = np->tx_info[entry].skb;
  1241. np->tx_info[entry].skb = NULL;
  1242. pci_unmap_single(np->pci_dev,
  1243. np->tx_info[entry].mapping,
  1244. skb_first_frag_len(skb),
  1245. PCI_DMA_TODEVICE);
  1246. np->tx_info[entry].mapping = 0;
  1247. np->dirty_tx += np->tx_info[entry].used_slots;
  1248. entry = (entry + np->tx_info[entry].used_slots) % TX_RING_SIZE;
  1249. {
  1250. int i;
  1251. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1252. pci_unmap_single(np->pci_dev,
  1253. np->tx_info[entry].mapping,
  1254. skb_shinfo(skb)->frags[i].size,
  1255. PCI_DMA_TODEVICE);
  1256. np->dirty_tx++;
  1257. entry++;
  1258. }
  1259. }
  1260. dev_kfree_skb_irq(skb);
  1261. }
  1262. np->tx_done_q[np->tx_done].status = 0;
  1263. np->tx_done = (np->tx_done + 1) % DONE_Q_SIZE;
  1264. }
  1265. writew(np->tx_done, ioaddr + CompletionQConsumerIdx + 2);
  1266. if (netif_queue_stopped(dev) &&
  1267. (np->cur_tx - np->dirty_tx + 4 < TX_RING_SIZE)) {
  1268. /* The ring is no longer full, wake the queue. */
  1269. netif_wake_queue(dev);
  1270. }
  1271. /* Stats overflow */
  1272. if (intr_status & IntrStatsMax)
  1273. get_stats(dev);
  1274. /* Media change interrupt. */
  1275. if (intr_status & IntrLinkChange)
  1276. netdev_media_change(dev);
  1277. /* Abnormal error summary/uncommon events handlers. */
  1278. if (intr_status & IntrAbnormalSummary)
  1279. netdev_error(dev, intr_status);
  1280. if (--boguscnt < 0) {
  1281. if (debug > 1)
  1282. printk(KERN_WARNING "%s: Too much work at interrupt, "
  1283. "status=%#8.8x.\n",
  1284. dev->name, intr_status);
  1285. break;
  1286. }
  1287. } while (1);
  1288. if (debug > 4)
  1289. printk(KERN_DEBUG "%s: exiting interrupt, status=%#8.8x.\n",
  1290. dev->name, (int) readl(ioaddr + IntrStatus));
  1291. return IRQ_RETVAL(handled);
  1292. }
  1293. /* This routine is logically part of the interrupt/poll handler, but separated
  1294. for clarity, code sharing between NAPI/non-NAPI, and better register allocation. */
  1295. static int __netdev_rx(struct net_device *dev, int *quota)
  1296. {
  1297. struct netdev_private *np = netdev_priv(dev);
  1298. u32 desc_status;
  1299. int retcode = 0;
  1300. /* If EOP is set on the next entry, it's a new packet. Send it up. */
  1301. while ((desc_status = le32_to_cpu(np->rx_done_q[np->rx_done].status)) != 0) {
  1302. struct sk_buff *skb;
  1303. u16 pkt_len;
  1304. int entry;
  1305. rx_done_desc *desc = &np->rx_done_q[np->rx_done];
  1306. if (debug > 4)
  1307. printk(KERN_DEBUG " netdev_rx() status of %d was %#8.8x.\n", np->rx_done, desc_status);
  1308. if (!(desc_status & RxOK)) {
  1309. /* There was an error. */
  1310. if (debug > 2)
  1311. printk(KERN_DEBUG " netdev_rx() Rx error was %#8.8x.\n", desc_status);
  1312. np->stats.rx_errors++;
  1313. if (desc_status & RxFIFOErr)
  1314. np->stats.rx_fifo_errors++;
  1315. goto next_rx;
  1316. }
  1317. if (*quota <= 0) { /* out of rx quota */
  1318. retcode = 1;
  1319. goto out;
  1320. }
  1321. (*quota)--;
  1322. pkt_len = desc_status; /* Implicitly Truncate */
  1323. entry = (desc_status >> 16) & 0x7ff;
  1324. if (debug > 4)
  1325. printk(KERN_DEBUG " netdev_rx() normal Rx pkt length %d, quota %d.\n", pkt_len, *quota);
  1326. /* Check if the packet is long enough to accept without copying
  1327. to a minimally-sized skbuff. */
  1328. if (pkt_len < rx_copybreak
  1329. && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
  1330. skb->dev = dev;
  1331. skb_reserve(skb, 2); /* 16 byte align the IP header */
  1332. pci_dma_sync_single_for_cpu(np->pci_dev,
  1333. np->rx_info[entry].mapping,
  1334. pkt_len, PCI_DMA_FROMDEVICE);
  1335. eth_copy_and_sum(skb, np->rx_info[entry].skb->data, pkt_len, 0);
  1336. pci_dma_sync_single_for_device(np->pci_dev,
  1337. np->rx_info[entry].mapping,
  1338. pkt_len, PCI_DMA_FROMDEVICE);
  1339. skb_put(skb, pkt_len);
  1340. } else {
  1341. pci_unmap_single(np->pci_dev, np->rx_info[entry].mapping, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1342. skb = np->rx_info[entry].skb;
  1343. skb_put(skb, pkt_len);
  1344. np->rx_info[entry].skb = NULL;
  1345. np->rx_info[entry].mapping = 0;
  1346. }
  1347. #ifndef final_version /* Remove after testing. */
  1348. /* You will want this info for the initial debug. */
  1349. if (debug > 5)
  1350. printk(KERN_DEBUG " Rx data %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:"
  1351. "%2.2x %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x %2.2x%2.2x.\n",
  1352. skb->data[0], skb->data[1], skb->data[2], skb->data[3],
  1353. skb->data[4], skb->data[5], skb->data[6], skb->data[7],
  1354. skb->data[8], skb->data[9], skb->data[10],
  1355. skb->data[11], skb->data[12], skb->data[13]);
  1356. #endif
  1357. skb->protocol = eth_type_trans(skb, dev);
  1358. #ifdef VLAN_SUPPORT
  1359. if (debug > 4)
  1360. printk(KERN_DEBUG " netdev_rx() status2 of %d was %#4.4x.\n", np->rx_done, le16_to_cpu(desc->status2));
  1361. #endif
  1362. if (le16_to_cpu(desc->status2) & 0x0100) {
  1363. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1364. np->stats.rx_compressed++;
  1365. }
  1366. /*
  1367. * This feature doesn't seem to be working, at least
  1368. * with the two firmware versions I have. If the GFP sees
  1369. * an IP fragment, it either ignores it completely, or reports
  1370. * "bad checksum" on it.
  1371. *
  1372. * Maybe I missed something -- corrections are welcome.
  1373. * Until then, the printk stays. :-) -Ion
  1374. */
  1375. else if (le16_to_cpu(desc->status2) & 0x0040) {
  1376. skb->ip_summed = CHECKSUM_HW;
  1377. skb->csum = le16_to_cpu(desc->csum);
  1378. printk(KERN_DEBUG "%s: checksum_hw, status2 = %#x\n", dev->name, le16_to_cpu(desc->status2));
  1379. }
  1380. #ifdef VLAN_SUPPORT
  1381. if (np->vlgrp && le16_to_cpu(desc->status2) & 0x0200) {
  1382. if (debug > 4)
  1383. printk(KERN_DEBUG " netdev_rx() vlanid = %d\n", le16_to_cpu(desc->vlanid));
  1384. /* vlan_netdev_receive_skb() expects a packet with the VLAN tag stripped out */
  1385. vlan_netdev_receive_skb(skb, np->vlgrp, le16_to_cpu(desc->vlanid) & VLAN_VID_MASK);
  1386. } else
  1387. #endif /* VLAN_SUPPORT */
  1388. netdev_receive_skb(skb);
  1389. dev->last_rx = jiffies;
  1390. np->stats.rx_packets++;
  1391. next_rx:
  1392. np->cur_rx++;
  1393. desc->status = 0;
  1394. np->rx_done = (np->rx_done + 1) % DONE_Q_SIZE;
  1395. }
  1396. writew(np->rx_done, np->base + CompletionQConsumerIdx);
  1397. out:
  1398. refill_rx_ring(dev);
  1399. if (debug > 5)
  1400. printk(KERN_DEBUG " exiting netdev_rx(): %d, status of %d was %#8.8x.\n",
  1401. retcode, np->rx_done, desc_status);
  1402. return retcode;
  1403. }
  1404. #ifdef HAVE_NETDEV_POLL
  1405. static int netdev_poll(struct net_device *dev, int *budget)
  1406. {
  1407. u32 intr_status;
  1408. struct netdev_private *np = netdev_priv(dev);
  1409. void __iomem *ioaddr = np->base;
  1410. int retcode = 0, quota = dev->quota;
  1411. do {
  1412. writel(IntrRxDone | IntrRxEmpty, ioaddr + IntrClear);
  1413. retcode = __netdev_rx(dev, &quota);
  1414. *budget -= (dev->quota - quota);
  1415. dev->quota = quota;
  1416. if (retcode)
  1417. goto out;
  1418. intr_status = readl(ioaddr + IntrStatus);
  1419. } while (intr_status & (IntrRxDone | IntrRxEmpty));
  1420. netif_rx_complete(dev);
  1421. intr_status = readl(ioaddr + IntrEnable);
  1422. intr_status |= IntrRxDone | IntrRxEmpty;
  1423. writel(intr_status, ioaddr + IntrEnable);
  1424. out:
  1425. if (debug > 5)
  1426. printk(KERN_DEBUG " exiting netdev_poll(): %d.\n", retcode);
  1427. /* Restart Rx engine if stopped. */
  1428. return retcode;
  1429. }
  1430. #endif /* HAVE_NETDEV_POLL */
  1431. static void refill_rx_ring(struct net_device *dev)
  1432. {
  1433. struct netdev_private *np = netdev_priv(dev);
  1434. struct sk_buff *skb;
  1435. int entry = -1;
  1436. /* Refill the Rx ring buffers. */
  1437. for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) {
  1438. entry = np->dirty_rx % RX_RING_SIZE;
  1439. if (np->rx_info[entry].skb == NULL) {
  1440. skb = dev_alloc_skb(np->rx_buf_sz);
  1441. np->rx_info[entry].skb = skb;
  1442. if (skb == NULL)
  1443. break; /* Better luck next round. */
  1444. np->rx_info[entry].mapping =
  1445. pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1446. skb->dev = dev; /* Mark as being used by this device. */
  1447. np->rx_ring[entry].rxaddr =
  1448. cpu_to_dma(np->rx_info[entry].mapping | RxDescValid);
  1449. }
  1450. if (entry == RX_RING_SIZE - 1)
  1451. np->rx_ring[entry].rxaddr |= cpu_to_dma(RxDescEndRing);
  1452. }
  1453. if (entry >= 0)
  1454. writew(entry, np->base + RxDescQIdx);
  1455. }
  1456. static void netdev_media_change(struct net_device *dev)
  1457. {
  1458. struct netdev_private *np = netdev_priv(dev);
  1459. void __iomem *ioaddr = np->base;
  1460. u16 reg0, reg1, reg4, reg5;
  1461. u32 new_tx_mode;
  1462. u32 new_intr_timer_ctrl;
  1463. /* reset status first */
  1464. mdio_read(dev, np->phys[0], MII_BMCR);
  1465. mdio_read(dev, np->phys[0], MII_BMSR);
  1466. reg0 = mdio_read(dev, np->phys[0], MII_BMCR);
  1467. reg1 = mdio_read(dev, np->phys[0], MII_BMSR);
  1468. if (reg1 & BMSR_LSTATUS) {
  1469. /* link is up */
  1470. if (reg0 & BMCR_ANENABLE) {
  1471. /* autonegotiation is enabled */
  1472. reg4 = mdio_read(dev, np->phys[0], MII_ADVERTISE);
  1473. reg5 = mdio_read(dev, np->phys[0], MII_LPA);
  1474. if (reg4 & ADVERTISE_100FULL && reg5 & LPA_100FULL) {
  1475. np->speed100 = 1;
  1476. np->mii_if.full_duplex = 1;
  1477. } else if (reg4 & ADVERTISE_100HALF && reg5 & LPA_100HALF) {
  1478. np->speed100 = 1;
  1479. np->mii_if.full_duplex = 0;
  1480. } else if (reg4 & ADVERTISE_10FULL && reg5 & LPA_10FULL) {
  1481. np->speed100 = 0;
  1482. np->mii_if.full_duplex = 1;
  1483. } else {
  1484. np->speed100 = 0;
  1485. np->mii_if.full_duplex = 0;
  1486. }
  1487. } else {
  1488. /* autonegotiation is disabled */
  1489. if (reg0 & BMCR_SPEED100)
  1490. np->speed100 = 1;
  1491. else
  1492. np->speed100 = 0;
  1493. if (reg0 & BMCR_FULLDPLX)
  1494. np->mii_if.full_duplex = 1;
  1495. else
  1496. np->mii_if.full_duplex = 0;
  1497. }
  1498. netif_carrier_on(dev);
  1499. printk(KERN_DEBUG "%s: Link is up, running at %sMbit %s-duplex\n",
  1500. dev->name,
  1501. np->speed100 ? "100" : "10",
  1502. np->mii_if.full_duplex ? "full" : "half");
  1503. new_tx_mode = np->tx_mode & ~FullDuplex; /* duplex setting */
  1504. if (np->mii_if.full_duplex)
  1505. new_tx_mode |= FullDuplex;
  1506. if (np->tx_mode != new_tx_mode) {
  1507. np->tx_mode = new_tx_mode;
  1508. writel(np->tx_mode | MiiSoftReset, ioaddr + TxMode);
  1509. udelay(1000);
  1510. writel(np->tx_mode, ioaddr + TxMode);
  1511. }
  1512. new_intr_timer_ctrl = np->intr_timer_ctrl & ~Timer10X;
  1513. if (np->speed100)
  1514. new_intr_timer_ctrl |= Timer10X;
  1515. if (np->intr_timer_ctrl != new_intr_timer_ctrl) {
  1516. np->intr_timer_ctrl = new_intr_timer_ctrl;
  1517. writel(new_intr_timer_ctrl, ioaddr + IntrTimerCtrl);
  1518. }
  1519. } else {
  1520. netif_carrier_off(dev);
  1521. printk(KERN_DEBUG "%s: Link is down\n", dev->name);
  1522. }
  1523. }
  1524. static void netdev_error(struct net_device *dev, int intr_status)
  1525. {
  1526. struct netdev_private *np = netdev_priv(dev);
  1527. /* Came close to underrunning the Tx FIFO, increase threshold. */
  1528. if (intr_status & IntrTxDataLow) {
  1529. if (np->tx_threshold <= PKT_BUF_SZ / 16) {
  1530. writel(++np->tx_threshold, np->base + TxThreshold);
  1531. printk(KERN_NOTICE "%s: PCI bus congestion, increasing Tx FIFO threshold to %d bytes\n",
  1532. dev->name, np->tx_threshold * 16);
  1533. } else
  1534. printk(KERN_WARNING "%s: PCI Tx underflow -- adapter is probably malfunctioning\n", dev->name);
  1535. }
  1536. if (intr_status & IntrRxGFPDead) {
  1537. np->stats.rx_fifo_errors++;
  1538. np->stats.rx_errors++;
  1539. }
  1540. if (intr_status & (IntrNoTxCsum | IntrDMAErr)) {
  1541. np->stats.tx_fifo_errors++;
  1542. np->stats.tx_errors++;
  1543. }
  1544. if ((intr_status & ~(IntrNormalMask | IntrAbnormalSummary | IntrLinkChange | IntrStatsMax | IntrTxDataLow | IntrRxGFPDead | IntrNoTxCsum | IntrPCIPad)) && debug)
  1545. printk(KERN_ERR "%s: Something Wicked happened! %#8.8x.\n",
  1546. dev->name, intr_status);
  1547. }
  1548. static struct net_device_stats *get_stats(struct net_device *dev)
  1549. {
  1550. struct netdev_private *np = netdev_priv(dev);
  1551. void __iomem *ioaddr = np->base;
  1552. /* This adapter architecture needs no SMP locks. */
  1553. np->stats.tx_bytes = readl(ioaddr + 0x57010);
  1554. np->stats.rx_bytes = readl(ioaddr + 0x57044);
  1555. np->stats.tx_packets = readl(ioaddr + 0x57000);
  1556. np->stats.tx_aborted_errors =
  1557. readl(ioaddr + 0x57024) + readl(ioaddr + 0x57028);
  1558. np->stats.tx_window_errors = readl(ioaddr + 0x57018);
  1559. np->stats.collisions =
  1560. readl(ioaddr + 0x57004) + readl(ioaddr + 0x57008);
  1561. /* The chip only need report frame silently dropped. */
  1562. np->stats.rx_dropped += readw(ioaddr + RxDMAStatus);
  1563. writew(0, ioaddr + RxDMAStatus);
  1564. np->stats.rx_crc_errors = readl(ioaddr + 0x5703C);
  1565. np->stats.rx_frame_errors = readl(ioaddr + 0x57040);
  1566. np->stats.rx_length_errors = readl(ioaddr + 0x57058);
  1567. np->stats.rx_missed_errors = readl(ioaddr + 0x5707C);
  1568. return &np->stats;
  1569. }
  1570. static void set_rx_mode(struct net_device *dev)
  1571. {
  1572. struct netdev_private *np = netdev_priv(dev);
  1573. void __iomem *ioaddr = np->base;
  1574. u32 rx_mode = MinVLANPrio;
  1575. struct dev_mc_list *mclist;
  1576. int i;
  1577. #ifdef VLAN_SUPPORT
  1578. rx_mode |= VlanMode;
  1579. if (np->vlgrp) {
  1580. int vlan_count = 0;
  1581. void __iomem *filter_addr = ioaddr + HashTable + 8;
  1582. for (i = 0; i < VLAN_VID_MASK; i++) {
  1583. if (np->vlgrp->vlan_devices[i]) {
  1584. if (vlan_count >= 32)
  1585. break;
  1586. writew(cpu_to_be16(i), filter_addr);
  1587. filter_addr += 16;
  1588. vlan_count++;
  1589. }
  1590. }
  1591. if (i == VLAN_VID_MASK) {
  1592. rx_mode |= PerfectFilterVlan;
  1593. while (vlan_count < 32) {
  1594. writew(0, filter_addr);
  1595. filter_addr += 16;
  1596. vlan_count++;
  1597. }
  1598. }
  1599. }
  1600. #endif /* VLAN_SUPPORT */
  1601. if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
  1602. rx_mode |= AcceptAll;
  1603. } else if ((dev->mc_count > multicast_filter_limit)
  1604. || (dev->flags & IFF_ALLMULTI)) {
  1605. /* Too many to match, or accept all multicasts. */
  1606. rx_mode |= AcceptBroadcast|AcceptAllMulticast|PerfectFilter;
  1607. } else if (dev->mc_count <= 14) {
  1608. /* Use the 16 element perfect filter, skip first two entries. */
  1609. void __iomem *filter_addr = ioaddr + PerfFilterTable + 2 * 16;
  1610. u16 *eaddrs;
  1611. for (i = 2, mclist = dev->mc_list; mclist && i < dev->mc_count + 2;
  1612. i++, mclist = mclist->next) {
  1613. eaddrs = (u16 *)mclist->dmi_addr;
  1614. writew(cpu_to_be16(eaddrs[2]), filter_addr); filter_addr += 4;
  1615. writew(cpu_to_be16(eaddrs[1]), filter_addr); filter_addr += 4;
  1616. writew(cpu_to_be16(eaddrs[0]), filter_addr); filter_addr += 8;
  1617. }
  1618. eaddrs = (u16 *)dev->dev_addr;
  1619. while (i++ < 16) {
  1620. writew(cpu_to_be16(eaddrs[0]), filter_addr); filter_addr += 4;
  1621. writew(cpu_to_be16(eaddrs[1]), filter_addr); filter_addr += 4;
  1622. writew(cpu_to_be16(eaddrs[2]), filter_addr); filter_addr += 8;
  1623. }
  1624. rx_mode |= AcceptBroadcast|PerfectFilter;
  1625. } else {
  1626. /* Must use a multicast hash table. */
  1627. void __iomem *filter_addr;
  1628. u16 *eaddrs;
  1629. u16 mc_filter[32] __attribute__ ((aligned(sizeof(long)))); /* Multicast hash filter */
  1630. memset(mc_filter, 0, sizeof(mc_filter));
  1631. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1632. i++, mclist = mclist->next) {
  1633. /* The chip uses the upper 9 CRC bits
  1634. as index into the hash table */
  1635. int bit_nr = ether_crc_le(ETH_ALEN, mclist->dmi_addr) >> 23;
  1636. __u32 *fptr = (__u32 *) &mc_filter[(bit_nr >> 4) & ~1];
  1637. *fptr |= cpu_to_le32(1 << (bit_nr & 31));
  1638. }
  1639. /* Clear the perfect filter list, skip first two entries. */
  1640. filter_addr = ioaddr + PerfFilterTable + 2 * 16;
  1641. eaddrs = (u16 *)dev->dev_addr;
  1642. for (i = 2; i < 16; i++) {
  1643. writew(cpu_to_be16(eaddrs[0]), filter_addr); filter_addr += 4;
  1644. writew(cpu_to_be16(eaddrs[1]), filter_addr); filter_addr += 4;
  1645. writew(cpu_to_be16(eaddrs[2]), filter_addr); filter_addr += 8;
  1646. }
  1647. for (filter_addr = ioaddr + HashTable, i = 0; i < 32; filter_addr+= 16, i++)
  1648. writew(mc_filter[i], filter_addr);
  1649. rx_mode |= AcceptBroadcast|PerfectFilter|HashFilter;
  1650. }
  1651. writel(rx_mode, ioaddr + RxFilterMode);
  1652. }
  1653. static int check_if_running(struct net_device *dev)
  1654. {
  1655. if (!netif_running(dev))
  1656. return -EINVAL;
  1657. return 0;
  1658. }
  1659. static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1660. {
  1661. struct netdev_private *np = netdev_priv(dev);
  1662. strcpy(info->driver, DRV_NAME);
  1663. strcpy(info->version, DRV_VERSION);
  1664. strcpy(info->bus_info, pci_name(np->pci_dev));
  1665. }
  1666. static int get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1667. {
  1668. struct netdev_private *np = netdev_priv(dev);
  1669. spin_lock_irq(&np->lock);
  1670. mii_ethtool_gset(&np->mii_if, ecmd);
  1671. spin_unlock_irq(&np->lock);
  1672. return 0;
  1673. }
  1674. static int set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1675. {
  1676. struct netdev_private *np = netdev_priv(dev);
  1677. int res;
  1678. spin_lock_irq(&np->lock);
  1679. res = mii_ethtool_sset(&np->mii_if, ecmd);
  1680. spin_unlock_irq(&np->lock);
  1681. check_duplex(dev);
  1682. return res;
  1683. }
  1684. static int nway_reset(struct net_device *dev)
  1685. {
  1686. struct netdev_private *np = netdev_priv(dev);
  1687. return mii_nway_restart(&np->mii_if);
  1688. }
  1689. static u32 get_link(struct net_device *dev)
  1690. {
  1691. struct netdev_private *np = netdev_priv(dev);
  1692. return mii_link_ok(&np->mii_if);
  1693. }
  1694. static u32 get_msglevel(struct net_device *dev)
  1695. {
  1696. return debug;
  1697. }
  1698. static void set_msglevel(struct net_device *dev, u32 val)
  1699. {
  1700. debug = val;
  1701. }
  1702. static struct ethtool_ops ethtool_ops = {
  1703. .begin = check_if_running,
  1704. .get_drvinfo = get_drvinfo,
  1705. .get_settings = get_settings,
  1706. .set_settings = set_settings,
  1707. .nway_reset = nway_reset,
  1708. .get_link = get_link,
  1709. .get_msglevel = get_msglevel,
  1710. .set_msglevel = set_msglevel,
  1711. };
  1712. static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1713. {
  1714. struct netdev_private *np = netdev_priv(dev);
  1715. struct mii_ioctl_data *data = if_mii(rq);
  1716. int rc;
  1717. if (!netif_running(dev))
  1718. return -EINVAL;
  1719. spin_lock_irq(&np->lock);
  1720. rc = generic_mii_ioctl(&np->mii_if, data, cmd, NULL);
  1721. spin_unlock_irq(&np->lock);
  1722. if ((cmd == SIOCSMIIREG) && (data->phy_id == np->phys[0]))
  1723. check_duplex(dev);
  1724. return rc;
  1725. }
  1726. static int netdev_close(struct net_device *dev)
  1727. {
  1728. struct netdev_private *np = netdev_priv(dev);
  1729. void __iomem *ioaddr = np->base;
  1730. int i;
  1731. netif_stop_queue(dev);
  1732. if (debug > 1) {
  1733. printk(KERN_DEBUG "%s: Shutting down ethercard, Intr status %#8.8x.\n",
  1734. dev->name, (int) readl(ioaddr + IntrStatus));
  1735. printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d, Rx %d / %d.\n",
  1736. dev->name, np->cur_tx, np->dirty_tx,
  1737. np->cur_rx, np->dirty_rx);
  1738. }
  1739. /* Disable interrupts by clearing the interrupt mask. */
  1740. writel(0, ioaddr + IntrEnable);
  1741. /* Stop the chip's Tx and Rx processes. */
  1742. writel(0, ioaddr + GenCtrl);
  1743. readl(ioaddr + GenCtrl);
  1744. if (debug > 5) {
  1745. printk(KERN_DEBUG" Tx ring at %#llx:\n",
  1746. (long long) np->tx_ring_dma);
  1747. for (i = 0; i < 8 /* TX_RING_SIZE is huge! */; i++)
  1748. printk(KERN_DEBUG " #%d desc. %#8.8x %#llx -> %#8.8x.\n",
  1749. i, le32_to_cpu(np->tx_ring[i].status),
  1750. (long long) dma_to_cpu(np->tx_ring[i].addr),
  1751. le32_to_cpu(np->tx_done_q[i].status));
  1752. printk(KERN_DEBUG " Rx ring at %#llx -> %p:\n",
  1753. (long long) np->rx_ring_dma, np->rx_done_q);
  1754. if (np->rx_done_q)
  1755. for (i = 0; i < 8 /* RX_RING_SIZE */; i++) {
  1756. printk(KERN_DEBUG " #%d desc. %#llx -> %#8.8x\n",
  1757. i, (long long) dma_to_cpu(np->rx_ring[i].rxaddr), le32_to_cpu(np->rx_done_q[i].status));
  1758. }
  1759. }
  1760. free_irq(dev->irq, dev);
  1761. /* Free all the skbuffs in the Rx queue. */
  1762. for (i = 0; i < RX_RING_SIZE; i++) {
  1763. np->rx_ring[i].rxaddr = cpu_to_dma(0xBADF00D0); /* An invalid address. */
  1764. if (np->rx_info[i].skb != NULL) {
  1765. pci_unmap_single(np->pci_dev, np->rx_info[i].mapping, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1766. dev_kfree_skb(np->rx_info[i].skb);
  1767. }
  1768. np->rx_info[i].skb = NULL;
  1769. np->rx_info[i].mapping = 0;
  1770. }
  1771. for (i = 0; i < TX_RING_SIZE; i++) {
  1772. struct sk_buff *skb = np->tx_info[i].skb;
  1773. if (skb == NULL)
  1774. continue;
  1775. pci_unmap_single(np->pci_dev,
  1776. np->tx_info[i].mapping,
  1777. skb_first_frag_len(skb), PCI_DMA_TODEVICE);
  1778. np->tx_info[i].mapping = 0;
  1779. dev_kfree_skb(skb);
  1780. np->tx_info[i].skb = NULL;
  1781. }
  1782. return 0;
  1783. }
  1784. static void __devexit starfire_remove_one (struct pci_dev *pdev)
  1785. {
  1786. struct net_device *dev = pci_get_drvdata(pdev);
  1787. struct netdev_private *np = netdev_priv(dev);
  1788. if (!dev)
  1789. BUG();
  1790. unregister_netdev(dev);
  1791. if (np->queue_mem)
  1792. pci_free_consistent(pdev, np->queue_mem_size, np->queue_mem, np->queue_mem_dma);
  1793. /* XXX: add wakeup code -- requires firmware for MagicPacket */
  1794. pci_set_power_state(pdev, PCI_D3hot); /* go to sleep in D3 mode */
  1795. pci_disable_device(pdev);
  1796. iounmap(np->base);
  1797. pci_release_regions(pdev);
  1798. pci_set_drvdata(pdev, NULL);
  1799. free_netdev(dev); /* Will also free np!! */
  1800. }
  1801. static struct pci_driver starfire_driver = {
  1802. .name = DRV_NAME,
  1803. .probe = starfire_init_one,
  1804. .remove = __devexit_p(starfire_remove_one),
  1805. .id_table = starfire_pci_tbl,
  1806. };
  1807. static int __init starfire_init (void)
  1808. {
  1809. /* when a module, this is printed whether or not devices are found in probe */
  1810. #ifdef MODULE
  1811. printk(version);
  1812. #ifdef HAVE_NETDEV_POLL
  1813. printk(KERN_INFO DRV_NAME ": polling (NAPI) enabled\n");
  1814. #else
  1815. printk(KERN_INFO DRV_NAME ": polling (NAPI) disabled\n");
  1816. #endif
  1817. #endif
  1818. #ifndef ADDR_64BITS
  1819. /* we can do this test only at run-time... sigh */
  1820. if (sizeof(dma_addr_t) == sizeof(u64)) {
  1821. printk("This driver has not been ported to this 64-bit architecture yet\n");
  1822. return -ENODEV;
  1823. }
  1824. #endif /* not ADDR_64BITS */
  1825. return pci_module_init (&starfire_driver);
  1826. }
  1827. static void __exit starfire_cleanup (void)
  1828. {
  1829. pci_unregister_driver (&starfire_driver);
  1830. }
  1831. module_init(starfire_init);
  1832. module_exit(starfire_cleanup);
  1833. /*
  1834. * Local variables:
  1835. * c-basic-offset: 8
  1836. * tab-width: 8
  1837. * End:
  1838. */