starfire.c 62 KB

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