starfire.c 63 KB

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