starfire.c 63 KB

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