starfire.c 63 KB

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