starfire.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101
  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 <asm/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 "/*(DEBLOBBED)*/"
  142. #define FIRMWARE_TX "/*(DEBLOBBED)*/"
  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. /*(DEBLOBBED)*/
  152. module_param(max_interrupt_work, int, 0);
  153. module_param(mtu, int, 0);
  154. module_param(debug, int, 0);
  155. module_param(rx_copybreak, int, 0);
  156. module_param(intr_latency, int, 0);
  157. module_param(small_frames, int, 0);
  158. module_param(enable_hw_cksum, int, 0);
  159. MODULE_PARM_DESC(max_interrupt_work, "Maximum events handled per interrupt");
  160. MODULE_PARM_DESC(mtu, "MTU (all boards)");
  161. MODULE_PARM_DESC(debug, "Debug level (0-6)");
  162. MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
  163. MODULE_PARM_DESC(intr_latency, "Maximum interrupt latency, in microseconds");
  164. MODULE_PARM_DESC(small_frames, "Maximum size of receive frames that bypass interrupt latency (0,64,128,256,512)");
  165. MODULE_PARM_DESC(enable_hw_cksum, "Enable/disable hardware cksum support (0/1)");
  166. /*
  167. Theory of Operation
  168. I. Board Compatibility
  169. This driver is for the Adaptec 6915 "Starfire" 64 bit PCI Ethernet adapter.
  170. II. Board-specific settings
  171. III. Driver operation
  172. IIIa. Ring buffers
  173. The Starfire hardware uses multiple fixed-size descriptor queues/rings. The
  174. ring sizes are set fixed by the hardware, but may optionally be wrapped
  175. earlier by the END bit in the descriptor.
  176. This driver uses that hardware queue size for the Rx ring, where a large
  177. number of entries has no ill effect beyond increases the potential backlog.
  178. The Tx ring is wrapped with the END bit, since a large hardware Tx queue
  179. disables the queue layer priority ordering and we have no mechanism to
  180. utilize the hardware two-level priority queue. When modifying the
  181. RX/TX_RING_SIZE pay close attention to page sizes and the ring-empty warning
  182. levels.
  183. IIIb/c. Transmit/Receive Structure
  184. See the Adaptec manual for the many possible structures, and options for
  185. each structure. There are far too many to document all of them here.
  186. For transmit this driver uses type 0/1 transmit descriptors (depending
  187. on the 32/64 bitness of the architecture), and relies on automatic
  188. minimum-length padding. It does not use the completion queue
  189. consumer index, but instead checks for non-zero status entries.
  190. For receive this driver uses type 2/3 receive descriptors. The driver
  191. allocates full frame size skbuffs for the Rx ring buffers, so all frames
  192. should fit in a single descriptor. The driver does not use the completion
  193. queue consumer index, but instead checks for non-zero status entries.
  194. When an incoming frame is less than RX_COPYBREAK bytes long, a fresh skbuff
  195. is allocated and the frame is copied to the new skbuff. When the incoming
  196. frame is larger, the skbuff is passed directly up the protocol stack.
  197. Buffers consumed this way are replaced by newly allocated skbuffs in a later
  198. phase of receive.
  199. A notable aspect of operation is that unaligned buffers are not permitted by
  200. the Starfire hardware. Thus the IP header at offset 14 in an ethernet frame
  201. isn't longword aligned, which may cause problems on some machine
  202. e.g. Alphas and IA64. For these architectures, the driver is forced to copy
  203. the frame into a new skbuff unconditionally. Copied frames are put into the
  204. skbuff at an offset of "+2", thus 16-byte aligning the IP header.
  205. IIId. Synchronization
  206. The driver runs as two independent, single-threaded flows of control. One
  207. is the send-packet routine, which enforces single-threaded use by the
  208. dev->tbusy flag. The other thread is the interrupt handler, which is single
  209. threaded by the hardware and interrupt handling software.
  210. The send packet thread has partial control over the Tx ring and the netif_queue
  211. status. If the number of free Tx slots in the ring falls below a certain number
  212. (currently hardcoded to 4), it signals the upper layer to stop the queue.
  213. The interrupt handler has exclusive control over the Rx ring and records stats
  214. from the Tx ring. After reaping the stats, it marks the Tx queue entry as
  215. empty by incrementing the dirty_tx mark. Iff the netif_queue is stopped and the
  216. number of free Tx slow is above the threshold, it signals the upper layer to
  217. restart the queue.
  218. IV. Notes
  219. IVb. References
  220. The Adaptec Starfire manuals, available only from Adaptec.
  221. http://www.scyld.com/expert/100mbps.html
  222. http://www.scyld.com/expert/NWay.html
  223. IVc. Errata
  224. - StopOnPerr is broken, don't enable
  225. - Hardware ethernet padding exposes random data, perform software padding
  226. instead (unverified -- works correctly for all the hardware I have)
  227. */
  228. enum chip_capability_flags {CanHaveMII=1, };
  229. enum chipset {
  230. CH_6915 = 0,
  231. };
  232. static const struct pci_device_id starfire_pci_tbl[] = {
  233. { PCI_VDEVICE(ADAPTEC, 0x6915), CH_6915 },
  234. { 0, }
  235. };
  236. MODULE_DEVICE_TABLE(pci, starfire_pci_tbl);
  237. /* A chip capabilities table, matching the CH_xxx entries in xxx_pci_tbl[] above. */
  238. static const struct chip_info {
  239. const char *name;
  240. int drv_flags;
  241. } netdrv_tbl[] = {
  242. { "Adaptec Starfire 6915", CanHaveMII },
  243. };
  244. /* Offsets to the device registers.
  245. Unlike software-only systems, device drivers interact with complex hardware.
  246. It's not useful to define symbolic names for every register bit in the
  247. device. The name can only partially document the semantics and make
  248. the driver longer and more difficult to read.
  249. In general, only the important configuration values or bits changed
  250. multiple times should be defined symbolically.
  251. */
  252. enum register_offsets {
  253. PCIDeviceConfig=0x50040, GenCtrl=0x50070, IntrTimerCtrl=0x50074,
  254. IntrClear=0x50080, IntrStatus=0x50084, IntrEnable=0x50088,
  255. MIICtrl=0x52000, TxStationAddr=0x50120, EEPROMCtrl=0x51000,
  256. GPIOCtrl=0x5008C, TxDescCtrl=0x50090,
  257. TxRingPtr=0x50098, HiPriTxRingPtr=0x50094, /* Low and High priority. */
  258. TxRingHiAddr=0x5009C, /* 64 bit address extension. */
  259. TxProducerIdx=0x500A0, TxConsumerIdx=0x500A4,
  260. TxThreshold=0x500B0,
  261. CompletionHiAddr=0x500B4, TxCompletionAddr=0x500B8,
  262. RxCompletionAddr=0x500BC, RxCompletionQ2Addr=0x500C0,
  263. CompletionQConsumerIdx=0x500C4, RxDMACtrl=0x500D0,
  264. RxDescQCtrl=0x500D4, RxDescQHiAddr=0x500DC, RxDescQAddr=0x500E0,
  265. RxDescQIdx=0x500E8, RxDMAStatus=0x500F0, RxFilterMode=0x500F4,
  266. TxMode=0x55000, VlanType=0x55064,
  267. PerfFilterTable=0x56000, HashTable=0x56100,
  268. TxGfpMem=0x58000, RxGfpMem=0x5a000,
  269. };
  270. /*
  271. * Bits in the interrupt status/mask registers.
  272. * Warning: setting Intr[Ab]NormalSummary in the IntrEnable register
  273. * enables all the interrupt sources that are or'ed into those status bits.
  274. */
  275. enum intr_status_bits {
  276. IntrLinkChange=0xf0000000, IntrStatsMax=0x08000000,
  277. IntrAbnormalSummary=0x02000000, IntrGeneralTimer=0x01000000,
  278. IntrSoftware=0x800000, IntrRxComplQ1Low=0x400000,
  279. IntrTxComplQLow=0x200000, IntrPCI=0x100000,
  280. IntrDMAErr=0x080000, IntrTxDataLow=0x040000,
  281. IntrRxComplQ2Low=0x020000, IntrRxDescQ1Low=0x010000,
  282. IntrNormalSummary=0x8000, IntrTxDone=0x4000,
  283. IntrTxDMADone=0x2000, IntrTxEmpty=0x1000,
  284. IntrEarlyRxQ2=0x0800, IntrEarlyRxQ1=0x0400,
  285. IntrRxQ2Done=0x0200, IntrRxQ1Done=0x0100,
  286. IntrRxGFPDead=0x80, IntrRxDescQ2Low=0x40,
  287. IntrNoTxCsum=0x20, IntrTxBadID=0x10,
  288. IntrHiPriTxBadID=0x08, IntrRxGfp=0x04,
  289. IntrTxGfp=0x02, IntrPCIPad=0x01,
  290. /* not quite bits */
  291. IntrRxDone=IntrRxQ2Done | IntrRxQ1Done,
  292. IntrRxEmpty=IntrRxDescQ1Low | IntrRxDescQ2Low,
  293. IntrNormalMask=0xff00, IntrAbnormalMask=0x3ff00fe,
  294. };
  295. /* Bits in the RxFilterMode register. */
  296. enum rx_mode_bits {
  297. AcceptBroadcast=0x04, AcceptAllMulticast=0x02, AcceptAll=0x01,
  298. AcceptMulticast=0x10, PerfectFilter=0x40, HashFilter=0x30,
  299. PerfectFilterVlan=0x80, MinVLANPrio=0xE000, VlanMode=0x0200,
  300. WakeupOnGFP=0x0800,
  301. };
  302. /* Bits in the TxMode register */
  303. enum tx_mode_bits {
  304. MiiSoftReset=0x8000, MIILoopback=0x4000,
  305. TxFlowEnable=0x0800, RxFlowEnable=0x0400,
  306. PadEnable=0x04, FullDuplex=0x02, HugeFrame=0x01,
  307. };
  308. /* Bits in the TxDescCtrl register. */
  309. enum tx_ctrl_bits {
  310. TxDescSpaceUnlim=0x00, TxDescSpace32=0x10, TxDescSpace64=0x20,
  311. TxDescSpace128=0x30, TxDescSpace256=0x40,
  312. TxDescType0=0x00, TxDescType1=0x01, TxDescType2=0x02,
  313. TxDescType3=0x03, TxDescType4=0x04,
  314. TxNoDMACompletion=0x08,
  315. TxDescQAddr64bit=0x80, TxDescQAddr32bit=0,
  316. TxHiPriFIFOThreshShift=24, TxPadLenShift=16,
  317. TxDMABurstSizeShift=8,
  318. };
  319. /* Bits in the RxDescQCtrl register. */
  320. enum rx_ctrl_bits {
  321. RxBufferLenShift=16, RxMinDescrThreshShift=0,
  322. RxPrefetchMode=0x8000, RxVariableQ=0x2000,
  323. Rx2048QEntries=0x4000, Rx256QEntries=0,
  324. RxDescAddr64bit=0x1000, RxDescAddr32bit=0,
  325. RxDescQAddr64bit=0x0100, RxDescQAddr32bit=0,
  326. RxDescSpace4=0x000, RxDescSpace8=0x100,
  327. RxDescSpace16=0x200, RxDescSpace32=0x300,
  328. RxDescSpace64=0x400, RxDescSpace128=0x500,
  329. RxConsumerWrEn=0x80,
  330. };
  331. /* Bits in the RxDMACtrl register. */
  332. enum rx_dmactrl_bits {
  333. RxReportBadFrames=0x80000000, RxDMAShortFrames=0x40000000,
  334. RxDMABadFrames=0x20000000, RxDMACrcErrorFrames=0x10000000,
  335. RxDMAControlFrame=0x08000000, RxDMAPauseFrame=0x04000000,
  336. RxChecksumIgnore=0, RxChecksumRejectTCPUDP=0x02000000,
  337. RxChecksumRejectTCPOnly=0x01000000,
  338. RxCompletionQ2Enable=0x800000,
  339. RxDMAQ2Disable=0, RxDMAQ2FPOnly=0x100000,
  340. RxDMAQ2SmallPkt=0x200000, RxDMAQ2HighPrio=0x300000,
  341. RxDMAQ2NonIP=0x400000,
  342. RxUseBackupQueue=0x080000, RxDMACRC=0x040000,
  343. RxEarlyIntThreshShift=12, RxHighPrioThreshShift=8,
  344. RxBurstSizeShift=0,
  345. };
  346. /* Bits in the RxCompletionAddr register */
  347. enum rx_compl_bits {
  348. RxComplQAddr64bit=0x80, RxComplQAddr32bit=0,
  349. RxComplProducerWrEn=0x40,
  350. RxComplType0=0x00, RxComplType1=0x10,
  351. RxComplType2=0x20, RxComplType3=0x30,
  352. RxComplThreshShift=0,
  353. };
  354. /* Bits in the TxCompletionAddr register */
  355. enum tx_compl_bits {
  356. TxComplQAddr64bit=0x80, TxComplQAddr32bit=0,
  357. TxComplProducerWrEn=0x40,
  358. TxComplIntrStatus=0x20,
  359. CommonQueueMode=0x10,
  360. TxComplThreshShift=0,
  361. };
  362. /* Bits in the GenCtrl register */
  363. enum gen_ctrl_bits {
  364. RxEnable=0x05, TxEnable=0x0a,
  365. RxGFPEnable=0x10, TxGFPEnable=0x20,
  366. };
  367. /* Bits in the IntrTimerCtrl register */
  368. enum intr_ctrl_bits {
  369. Timer10X=0x800, EnableIntrMasking=0x60, SmallFrameBypass=0x100,
  370. SmallFrame64=0, SmallFrame128=0x200, SmallFrame256=0x400, SmallFrame512=0x600,
  371. IntrLatencyMask=0x1f,
  372. };
  373. /* The Rx and Tx buffer descriptors. */
  374. struct starfire_rx_desc {
  375. netdrv_addr_t rxaddr;
  376. };
  377. enum rx_desc_bits {
  378. RxDescValid=1, RxDescEndRing=2,
  379. };
  380. /* Completion queue entry. */
  381. struct short_rx_done_desc {
  382. __le32 status; /* Low 16 bits is length. */
  383. };
  384. struct basic_rx_done_desc {
  385. __le32 status; /* Low 16 bits is length. */
  386. __le16 vlanid;
  387. __le16 status2;
  388. };
  389. struct csum_rx_done_desc {
  390. __le32 status; /* Low 16 bits is length. */
  391. __le16 csum; /* Partial checksum */
  392. __le16 status2;
  393. };
  394. struct full_rx_done_desc {
  395. __le32 status; /* Low 16 bits is length. */
  396. __le16 status3;
  397. __le16 status2;
  398. __le16 vlanid;
  399. __le16 csum; /* partial checksum */
  400. __le32 timestamp;
  401. };
  402. /* XXX: this is ugly and I'm not sure it's worth the trouble -Ion */
  403. #ifdef VLAN_SUPPORT
  404. typedef struct full_rx_done_desc rx_done_desc;
  405. #define RxComplType RxComplType3
  406. #else /* not VLAN_SUPPORT */
  407. typedef struct csum_rx_done_desc rx_done_desc;
  408. #define RxComplType RxComplType2
  409. #endif /* not VLAN_SUPPORT */
  410. enum rx_done_bits {
  411. RxOK=0x20000000, RxFIFOErr=0x10000000, RxBufQ2=0x08000000,
  412. };
  413. /* Type 1 Tx descriptor. */
  414. struct starfire_tx_desc_1 {
  415. __le32 status; /* Upper bits are status, lower 16 length. */
  416. __le32 addr;
  417. };
  418. /* Type 2 Tx descriptor. */
  419. struct starfire_tx_desc_2 {
  420. __le32 status; /* Upper bits are status, lower 16 length. */
  421. __le32 reserved;
  422. __le64 addr;
  423. };
  424. #ifdef ADDR_64BITS
  425. typedef struct starfire_tx_desc_2 starfire_tx_desc;
  426. #define TX_DESC_TYPE TxDescType2
  427. #else /* not ADDR_64BITS */
  428. typedef struct starfire_tx_desc_1 starfire_tx_desc;
  429. #define TX_DESC_TYPE TxDescType1
  430. #endif /* not ADDR_64BITS */
  431. #define TX_DESC_SPACING TxDescSpaceUnlim
  432. enum tx_desc_bits {
  433. TxDescID=0xB0000000,
  434. TxCRCEn=0x01000000, TxDescIntr=0x08000000,
  435. TxRingWrap=0x04000000, TxCalTCP=0x02000000,
  436. };
  437. struct tx_done_desc {
  438. __le32 status; /* timestamp, index. */
  439. #if 0
  440. __le32 intrstatus; /* interrupt status */
  441. #endif
  442. };
  443. struct rx_ring_info {
  444. struct sk_buff *skb;
  445. dma_addr_t mapping;
  446. };
  447. struct tx_ring_info {
  448. struct sk_buff *skb;
  449. dma_addr_t mapping;
  450. unsigned int used_slots;
  451. };
  452. #define PHY_CNT 2
  453. struct netdev_private {
  454. /* Descriptor rings first for alignment. */
  455. struct starfire_rx_desc *rx_ring;
  456. starfire_tx_desc *tx_ring;
  457. dma_addr_t rx_ring_dma;
  458. dma_addr_t tx_ring_dma;
  459. /* The addresses of rx/tx-in-place skbuffs. */
  460. struct rx_ring_info rx_info[RX_RING_SIZE];
  461. struct tx_ring_info tx_info[TX_RING_SIZE];
  462. /* Pointers to completion queues (full pages). */
  463. rx_done_desc *rx_done_q;
  464. dma_addr_t rx_done_q_dma;
  465. unsigned int rx_done;
  466. struct tx_done_desc *tx_done_q;
  467. dma_addr_t tx_done_q_dma;
  468. unsigned int tx_done;
  469. struct napi_struct napi;
  470. struct net_device *dev;
  471. struct pci_dev *pci_dev;
  472. #ifdef VLAN_SUPPORT
  473. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  474. #endif
  475. void *queue_mem;
  476. dma_addr_t queue_mem_dma;
  477. size_t queue_mem_size;
  478. /* Frequently used values: keep some adjacent for cache effect. */
  479. spinlock_t lock;
  480. unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */
  481. unsigned int cur_tx, dirty_tx, reap_tx;
  482. unsigned int rx_buf_sz; /* Based on MTU+slack. */
  483. /* These values keep track of the transceiver/media in use. */
  484. int speed100; /* Set if speed == 100MBit. */
  485. u32 tx_mode;
  486. u32 intr_timer_ctrl;
  487. u8 tx_threshold;
  488. /* MII transceiver section. */
  489. struct mii_if_info mii_if; /* MII lib hooks/info */
  490. int phy_cnt; /* MII device addresses. */
  491. unsigned char phys[PHY_CNT]; /* MII device addresses. */
  492. void __iomem *base;
  493. };
  494. static int mdio_read(struct net_device *dev, int phy_id, int location);
  495. static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
  496. static int netdev_open(struct net_device *dev);
  497. static void check_duplex(struct net_device *dev);
  498. static void tx_timeout(struct net_device *dev);
  499. static void init_ring(struct net_device *dev);
  500. static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev);
  501. static irqreturn_t intr_handler(int irq, void *dev_instance);
  502. static void netdev_error(struct net_device *dev, int intr_status);
  503. static int __netdev_rx(struct net_device *dev, int *quota);
  504. static int netdev_poll(struct napi_struct *napi, int budget);
  505. static void refill_rx_ring(struct net_device *dev);
  506. static void netdev_error(struct net_device *dev, int intr_status);
  507. static void set_rx_mode(struct net_device *dev);
  508. static struct net_device_stats *get_stats(struct net_device *dev);
  509. static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  510. static int netdev_close(struct net_device *dev);
  511. static void netdev_media_change(struct net_device *dev);
  512. static const struct ethtool_ops ethtool_ops;
  513. #ifdef VLAN_SUPPORT
  514. static int netdev_vlan_rx_add_vid(struct net_device *dev,
  515. __be16 proto, u16 vid)
  516. {
  517. struct netdev_private *np = netdev_priv(dev);
  518. spin_lock(&np->lock);
  519. if (debug > 1)
  520. printk("%s: Adding vlanid %d to vlan filter\n", dev->name, vid);
  521. set_bit(vid, np->active_vlans);
  522. set_rx_mode(dev);
  523. spin_unlock(&np->lock);
  524. return 0;
  525. }
  526. static int netdev_vlan_rx_kill_vid(struct net_device *dev,
  527. __be16 proto, u16 vid)
  528. {
  529. struct netdev_private *np = netdev_priv(dev);
  530. spin_lock(&np->lock);
  531. if (debug > 1)
  532. printk("%s: removing vlanid %d from vlan filter\n", dev->name, vid);
  533. clear_bit(vid, np->active_vlans);
  534. set_rx_mode(dev);
  535. spin_unlock(&np->lock);
  536. return 0;
  537. }
  538. #endif /* VLAN_SUPPORT */
  539. static const struct net_device_ops netdev_ops = {
  540. .ndo_open = netdev_open,
  541. .ndo_stop = netdev_close,
  542. .ndo_start_xmit = start_tx,
  543. .ndo_tx_timeout = tx_timeout,
  544. .ndo_get_stats = get_stats,
  545. .ndo_set_rx_mode = set_rx_mode,
  546. .ndo_do_ioctl = netdev_ioctl,
  547. .ndo_change_mtu = eth_change_mtu,
  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. mdelay(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 = reject_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 = reject_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_kfree_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_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1614. {
  1615. struct netdev_private *np = netdev_priv(dev);
  1616. spin_lock_irq(&np->lock);
  1617. mii_ethtool_gset(&np->mii_if, ecmd);
  1618. spin_unlock_irq(&np->lock);
  1619. return 0;
  1620. }
  1621. static int set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1622. {
  1623. struct netdev_private *np = netdev_priv(dev);
  1624. int res;
  1625. spin_lock_irq(&np->lock);
  1626. res = mii_ethtool_sset(&np->mii_if, ecmd);
  1627. spin_unlock_irq(&np->lock);
  1628. check_duplex(dev);
  1629. return res;
  1630. }
  1631. static int nway_reset(struct net_device *dev)
  1632. {
  1633. struct netdev_private *np = netdev_priv(dev);
  1634. return mii_nway_restart(&np->mii_if);
  1635. }
  1636. static u32 get_link(struct net_device *dev)
  1637. {
  1638. struct netdev_private *np = netdev_priv(dev);
  1639. return mii_link_ok(&np->mii_if);
  1640. }
  1641. static u32 get_msglevel(struct net_device *dev)
  1642. {
  1643. return debug;
  1644. }
  1645. static void set_msglevel(struct net_device *dev, u32 val)
  1646. {
  1647. debug = val;
  1648. }
  1649. static const struct ethtool_ops ethtool_ops = {
  1650. .begin = check_if_running,
  1651. .get_drvinfo = get_drvinfo,
  1652. .get_settings = get_settings,
  1653. .set_settings = set_settings,
  1654. .nway_reset = nway_reset,
  1655. .get_link = get_link,
  1656. .get_msglevel = get_msglevel,
  1657. .set_msglevel = set_msglevel,
  1658. };
  1659. static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1660. {
  1661. struct netdev_private *np = netdev_priv(dev);
  1662. struct mii_ioctl_data *data = if_mii(rq);
  1663. int rc;
  1664. if (!netif_running(dev))
  1665. return -EINVAL;
  1666. spin_lock_irq(&np->lock);
  1667. rc = generic_mii_ioctl(&np->mii_if, data, cmd, NULL);
  1668. spin_unlock_irq(&np->lock);
  1669. if ((cmd == SIOCSMIIREG) && (data->phy_id == np->phys[0]))
  1670. check_duplex(dev);
  1671. return rc;
  1672. }
  1673. static int netdev_close(struct net_device *dev)
  1674. {
  1675. struct netdev_private *np = netdev_priv(dev);
  1676. void __iomem *ioaddr = np->base;
  1677. int i;
  1678. netif_stop_queue(dev);
  1679. napi_disable(&np->napi);
  1680. if (debug > 1) {
  1681. printk(KERN_DEBUG "%s: Shutting down ethercard, Intr status %#8.8x.\n",
  1682. dev->name, (int) readl(ioaddr + IntrStatus));
  1683. printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d, Rx %d / %d.\n",
  1684. dev->name, np->cur_tx, np->dirty_tx,
  1685. np->cur_rx, np->dirty_rx);
  1686. }
  1687. /* Disable interrupts by clearing the interrupt mask. */
  1688. writel(0, ioaddr + IntrEnable);
  1689. /* Stop the chip's Tx and Rx processes. */
  1690. writel(0, ioaddr + GenCtrl);
  1691. readl(ioaddr + GenCtrl);
  1692. if (debug > 5) {
  1693. printk(KERN_DEBUG" Tx ring at %#llx:\n",
  1694. (long long) np->tx_ring_dma);
  1695. for (i = 0; i < 8 /* TX_RING_SIZE is huge! */; i++)
  1696. printk(KERN_DEBUG " #%d desc. %#8.8x %#llx -> %#8.8x.\n",
  1697. i, le32_to_cpu(np->tx_ring[i].status),
  1698. (long long) dma_to_cpu(np->tx_ring[i].addr),
  1699. le32_to_cpu(np->tx_done_q[i].status));
  1700. printk(KERN_DEBUG " Rx ring at %#llx -> %p:\n",
  1701. (long long) np->rx_ring_dma, np->rx_done_q);
  1702. if (np->rx_done_q)
  1703. for (i = 0; i < 8 /* RX_RING_SIZE */; i++) {
  1704. printk(KERN_DEBUG " #%d desc. %#llx -> %#8.8x\n",
  1705. i, (long long) dma_to_cpu(np->rx_ring[i].rxaddr), le32_to_cpu(np->rx_done_q[i].status));
  1706. }
  1707. }
  1708. free_irq(np->pci_dev->irq, dev);
  1709. /* Free all the skbuffs in the Rx queue. */
  1710. for (i = 0; i < RX_RING_SIZE; i++) {
  1711. np->rx_ring[i].rxaddr = cpu_to_dma(0xBADF00D0); /* An invalid address. */
  1712. if (np->rx_info[i].skb != NULL) {
  1713. pci_unmap_single(np->pci_dev, np->rx_info[i].mapping, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1714. dev_kfree_skb(np->rx_info[i].skb);
  1715. }
  1716. np->rx_info[i].skb = NULL;
  1717. np->rx_info[i].mapping = 0;
  1718. }
  1719. for (i = 0; i < TX_RING_SIZE; i++) {
  1720. struct sk_buff *skb = np->tx_info[i].skb;
  1721. if (skb == NULL)
  1722. continue;
  1723. pci_unmap_single(np->pci_dev,
  1724. np->tx_info[i].mapping,
  1725. skb_first_frag_len(skb), PCI_DMA_TODEVICE);
  1726. np->tx_info[i].mapping = 0;
  1727. dev_kfree_skb(skb);
  1728. np->tx_info[i].skb = NULL;
  1729. }
  1730. return 0;
  1731. }
  1732. #ifdef CONFIG_PM
  1733. static int starfire_suspend(struct pci_dev *pdev, pm_message_t state)
  1734. {
  1735. struct net_device *dev = pci_get_drvdata(pdev);
  1736. if (netif_running(dev)) {
  1737. netif_device_detach(dev);
  1738. netdev_close(dev);
  1739. }
  1740. pci_save_state(pdev);
  1741. pci_set_power_state(pdev, pci_choose_state(pdev,state));
  1742. return 0;
  1743. }
  1744. static int starfire_resume(struct pci_dev *pdev)
  1745. {
  1746. struct net_device *dev = pci_get_drvdata(pdev);
  1747. pci_set_power_state(pdev, PCI_D0);
  1748. pci_restore_state(pdev);
  1749. if (netif_running(dev)) {
  1750. netdev_open(dev);
  1751. netif_device_attach(dev);
  1752. }
  1753. return 0;
  1754. }
  1755. #endif /* CONFIG_PM */
  1756. static void starfire_remove_one(struct pci_dev *pdev)
  1757. {
  1758. struct net_device *dev = pci_get_drvdata(pdev);
  1759. struct netdev_private *np = netdev_priv(dev);
  1760. BUG_ON(!dev);
  1761. unregister_netdev(dev);
  1762. if (np->queue_mem)
  1763. pci_free_consistent(pdev, np->queue_mem_size, np->queue_mem, np->queue_mem_dma);
  1764. /* XXX: add wakeup code -- requires firmware for MagicPacket */
  1765. pci_set_power_state(pdev, PCI_D3hot); /* go to sleep in D3 mode */
  1766. pci_disable_device(pdev);
  1767. iounmap(np->base);
  1768. pci_release_regions(pdev);
  1769. free_netdev(dev); /* Will also free np!! */
  1770. }
  1771. static struct pci_driver starfire_driver = {
  1772. .name = DRV_NAME,
  1773. .probe = starfire_init_one,
  1774. .remove = starfire_remove_one,
  1775. #ifdef CONFIG_PM
  1776. .suspend = starfire_suspend,
  1777. .resume = starfire_resume,
  1778. #endif /* CONFIG_PM */
  1779. .id_table = starfire_pci_tbl,
  1780. };
  1781. static int __init starfire_init (void)
  1782. {
  1783. /* when a module, this is printed whether or not devices are found in probe */
  1784. #ifdef MODULE
  1785. printk(version);
  1786. printk(KERN_INFO DRV_NAME ": polling (NAPI) enabled\n");
  1787. #endif
  1788. BUILD_BUG_ON(sizeof(dma_addr_t) != sizeof(netdrv_addr_t));
  1789. return pci_register_driver(&starfire_driver);
  1790. }
  1791. static void __exit starfire_cleanup (void)
  1792. {
  1793. pci_unregister_driver (&starfire_driver);
  1794. }
  1795. module_init(starfire_init);
  1796. module_exit(starfire_cleanup);
  1797. /*
  1798. * Local variables:
  1799. * c-basic-offset: 8
  1800. * tab-width: 8
  1801. * End:
  1802. */