hamachi.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  1. /* hamachi.c: A Packet Engines GNIC-II Gigabit Ethernet driver for Linux. */
  2. /*
  3. Written 1998-2000 by Donald Becker.
  4. Updates 2000 by Keith Underwood.
  5. This software may be used and distributed according to the terms of
  6. the GNU General Public License (GPL), incorporated herein by reference.
  7. Drivers based on or derived from this code fall under the GPL and must
  8. retain the authorship, copyright and license notice. This file is not
  9. a complete program and may only be used when the entire operating
  10. system is licensed under the GPL.
  11. The author may be reached as becker@scyld.com, or C/O
  12. Scyld Computing Corporation
  13. 410 Severn Ave., Suite 210
  14. Annapolis MD 21403
  15. This driver is for the Packet Engines GNIC-II PCI Gigabit Ethernet
  16. adapter.
  17. Support and updates available at
  18. http://www.scyld.com/network/hamachi.html
  19. [link no longer provides useful info -jgarzik]
  20. or
  21. http://www.parl.clemson.edu/~keithu/hamachi.html
  22. */
  23. #define DRV_NAME "hamachi"
  24. #define DRV_VERSION "2.1"
  25. #define DRV_RELDATE "Sept 11, 2006"
  26. /* A few user-configurable values. */
  27. static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */
  28. #define final_version
  29. #define hamachi_debug debug
  30. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  31. static int max_interrupt_work = 40;
  32. static int mtu;
  33. /* Default values selected by testing on a dual processor PIII-450 */
  34. /* These six interrupt control parameters may be set directly when loading the
  35. * module, or through the rx_params and tx_params variables
  36. */
  37. static int max_rx_latency = 0x11;
  38. static int max_rx_gap = 0x05;
  39. static int min_rx_pkt = 0x18;
  40. static int max_tx_latency = 0x00;
  41. static int max_tx_gap = 0x00;
  42. static int min_tx_pkt = 0x30;
  43. /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
  44. -Setting to > 1518 causes all frames to be copied
  45. -Setting to 0 disables copies
  46. */
  47. static int rx_copybreak;
  48. /* An override for the hardware detection of bus width.
  49. Set to 1 to force 32 bit PCI bus detection. Set to 4 to force 64 bit.
  50. Add 2 to disable parity detection.
  51. */
  52. static int force32;
  53. /* Used to pass the media type, etc.
  54. These exist for driver interoperability.
  55. No media types are currently defined.
  56. - The lower 4 bits are reserved for the media type.
  57. - The next three bits may be set to one of the following:
  58. 0x00000000 : Autodetect PCI bus
  59. 0x00000010 : Force 32 bit PCI bus
  60. 0x00000020 : Disable parity detection
  61. 0x00000040 : Force 64 bit PCI bus
  62. Default is autodetect
  63. - The next bit can be used to force half-duplex. This is a bad
  64. idea since no known implementations implement half-duplex, and,
  65. in general, half-duplex for gigabit ethernet is a bad idea.
  66. 0x00000080 : Force half-duplex
  67. Default is full-duplex.
  68. - In the original driver, the ninth bit could be used to force
  69. full-duplex. Maintain that for compatibility
  70. 0x00000200 : Force full-duplex
  71. */
  72. #define MAX_UNITS 8 /* More are supported, limit only on options */
  73. static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
  74. static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
  75. /* The Hamachi chipset supports 3 parameters each for Rx and Tx
  76. * interruput management. Parameters will be loaded as specified into
  77. * the TxIntControl and RxIntControl registers.
  78. *
  79. * The registers are arranged as follows:
  80. * 23 - 16 15 - 8 7 - 0
  81. * _________________________________
  82. * | min_pkt | max_gap | max_latency |
  83. * ---------------------------------
  84. * min_pkt : The minimum number of packets processed between
  85. * interrupts.
  86. * max_gap : The maximum inter-packet gap in units of 8.192 us
  87. * max_latency : The absolute time between interrupts in units of 8.192 us
  88. *
  89. */
  90. static int rx_params[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
  91. static int tx_params[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
  92. /* Operational parameters that are set at compile time. */
  93. /* Keep the ring sizes a power of two for compile efficiency.
  94. The compiler will convert <unsigned>'%'<2^N> into a bit mask.
  95. Making the Tx ring too large decreases the effectiveness of channel
  96. bonding and packet priority.
  97. There are no ill effects from too-large receive rings, except for
  98. excessive memory usage */
  99. /* Empirically it appears that the Tx ring needs to be a little bigger
  100. for these Gbit adapters or you get into an overrun condition really
  101. easily. Also, things appear to work a bit better in back-to-back
  102. configurations if the Rx ring is 8 times the size of the Tx ring
  103. */
  104. #define TX_RING_SIZE 64
  105. #define RX_RING_SIZE 512
  106. #define TX_TOTAL_SIZE TX_RING_SIZE*sizeof(struct hamachi_desc)
  107. #define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct hamachi_desc)
  108. /*
  109. * Enable netdev_ioctl. Added interrupt coalescing parameter adjustment.
  110. * 2/19/99 Pete Wyckoff <wyckoff@ca.sandia.gov>
  111. */
  112. /* play with 64-bit addrlen; seems to be a teensy bit slower --pw */
  113. /* #define ADDRLEN 64 */
  114. /*
  115. * RX_CHECKSUM turns on card-generated receive checksum generation for
  116. * TCP and UDP packets. Otherwise the upper layers do the calculation.
  117. * TX_CHECKSUM won't do anything too useful, even if it works. There's no
  118. * easy mechanism by which to tell the TCP/UDP stack that it need not
  119. * generate checksums for this device. But if somebody can find a way
  120. * to get that to work, most of the card work is in here already.
  121. * 3/10/1999 Pete Wyckoff <wyckoff@ca.sandia.gov>
  122. */
  123. #undef TX_CHECKSUM
  124. #define RX_CHECKSUM
  125. /* Operational parameters that usually are not changed. */
  126. /* Time in jiffies before concluding the transmitter is hung. */
  127. #define TX_TIMEOUT (5*HZ)
  128. #include <linux/module.h>
  129. #include <linux/kernel.h>
  130. #include <linux/string.h>
  131. #include <linux/timer.h>
  132. #include <linux/time.h>
  133. #include <linux/errno.h>
  134. #include <linux/ioport.h>
  135. #include <linux/slab.h>
  136. #include <linux/interrupt.h>
  137. #include <linux/pci.h>
  138. #include <linux/init.h>
  139. #include <linux/ethtool.h>
  140. #include <linux/mii.h>
  141. #include <linux/netdevice.h>
  142. #include <linux/etherdevice.h>
  143. #include <linux/skbuff.h>
  144. #include <linux/ip.h>
  145. #include <linux/delay.h>
  146. #include <linux/bitops.h>
  147. #include <asm/uaccess.h>
  148. #include <asm/processor.h> /* Processor type for cache alignment. */
  149. #include <asm/io.h>
  150. #include <asm/unaligned.h>
  151. #include <asm/cache.h>
  152. static char version[] __devinitdata =
  153. KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Written by Donald Becker\n"
  154. KERN_INFO " Some modifications by Eric kasten <kasten@nscl.msu.edu>\n"
  155. KERN_INFO " Further modifications by Keith Underwood <keithu@parl.clemson.edu>\n";
  156. /* IP_MF appears to be only defined in <netinet/ip.h>, however,
  157. we need it for hardware checksumming support. FYI... some of
  158. the definitions in <netinet/ip.h> conflict/duplicate those in
  159. other linux headers causing many compiler warnings.
  160. */
  161. #ifndef IP_MF
  162. #define IP_MF 0x2000 /* IP more frags from <netinet/ip.h> */
  163. #endif
  164. /* Define IP_OFFSET to be IPOPT_OFFSET */
  165. #ifndef IP_OFFSET
  166. #ifdef IPOPT_OFFSET
  167. #define IP_OFFSET IPOPT_OFFSET
  168. #else
  169. #define IP_OFFSET 2
  170. #endif
  171. #endif
  172. #define RUN_AT(x) (jiffies + (x))
  173. #ifndef ADDRLEN
  174. #define ADDRLEN 32
  175. #endif
  176. /* Condensed bus+endian portability operations. */
  177. #if ADDRLEN == 64
  178. #define cpu_to_leXX(addr) cpu_to_le64(addr)
  179. #else
  180. #define cpu_to_leXX(addr) cpu_to_le32(addr)
  181. #endif
  182. /*
  183. Theory of Operation
  184. I. Board Compatibility
  185. This device driver is designed for the Packet Engines "Hamachi"
  186. Gigabit Ethernet chip. The only PCA currently supported is the GNIC-II 64-bit
  187. 66Mhz PCI card.
  188. II. Board-specific settings
  189. No jumpers exist on the board. The chip supports software correction of
  190. various motherboard wiring errors, however this driver does not support
  191. that feature.
  192. III. Driver operation
  193. IIIa. Ring buffers
  194. The Hamachi uses a typical descriptor based bus-master architecture.
  195. The descriptor list is similar to that used by the Digital Tulip.
  196. This driver uses two statically allocated fixed-size descriptor lists
  197. formed into rings by a branch from the final descriptor to the beginning of
  198. the list. The ring sizes are set at compile time by RX/TX_RING_SIZE.
  199. This driver uses a zero-copy receive and transmit scheme similar my other
  200. network drivers.
  201. The driver allocates full frame size skbuffs for the Rx ring buffers at
  202. open() time and passes the skb->data field to the Hamachi as receive data
  203. buffers. When an incoming frame is less than RX_COPYBREAK bytes long,
  204. a fresh skbuff is allocated and the frame is copied to the new skbuff.
  205. When the incoming frame is larger, the skbuff is passed directly up the
  206. protocol stack and replaced by a newly allocated skbuff.
  207. The RX_COPYBREAK value is chosen to trade-off the memory wasted by
  208. using a full-sized skbuff for small frames vs. the copying costs of larger
  209. frames. Gigabit cards are typically used on generously configured machines
  210. and the underfilled buffers have negligible impact compared to the benefit of
  211. a single allocation size, so the default value of zero results in never
  212. copying packets.
  213. IIIb/c. Transmit/Receive Structure
  214. The Rx and Tx descriptor structure are straight-forward, with no historical
  215. baggage that must be explained. Unlike the awkward DBDMA structure, there
  216. are no unused fields or option bits that had only one allowable setting.
  217. Two details should be noted about the descriptors: The chip supports both 32
  218. bit and 64 bit address structures, and the length field is overwritten on
  219. the receive descriptors. The descriptor length is set in the control word
  220. for each channel. The development driver uses 32 bit addresses only, however
  221. 64 bit addresses may be enabled for 64 bit architectures e.g. the Alpha.
  222. IIId. Synchronization
  223. This driver is very similar to my other network drivers.
  224. The driver runs as two independent, single-threaded flows of control. One
  225. is the send-packet routine, which enforces single-threaded use by the
  226. dev->tbusy flag. The other thread is the interrupt handler, which is single
  227. threaded by the hardware and other software.
  228. The send packet thread has partial control over the Tx ring and 'dev->tbusy'
  229. flag. It sets the tbusy flag whenever it's queuing a Tx packet. If the next
  230. queue slot is empty, it clears the tbusy flag when finished otherwise it sets
  231. the 'hmp->tx_full' flag.
  232. The interrupt handler has exclusive control over the Rx ring and records stats
  233. from the Tx ring. After reaping the stats, it marks the Tx queue entry as
  234. empty by incrementing the dirty_tx mark. Iff the 'hmp->tx_full' flag is set, it
  235. clears both the tx_full and tbusy flags.
  236. IV. Notes
  237. Thanks to Kim Stearns of Packet Engines for providing a pair of GNIC-II boards.
  238. IVb. References
  239. Hamachi Engineering Design Specification, 5/15/97
  240. (Note: This version was marked "Confidential".)
  241. IVc. Errata
  242. None noted.
  243. V. Recent Changes
  244. 01/15/1999 EPK Enlargement of the TX and RX ring sizes. This appears
  245. to help avoid some stall conditions -- this needs further research.
  246. 01/15/1999 EPK Creation of the hamachi_tx function. This function cleans
  247. the Tx ring and is called from hamachi_start_xmit (this used to be
  248. called from hamachi_interrupt but it tends to delay execution of the
  249. interrupt handler and thus reduce bandwidth by reducing the latency
  250. between hamachi_rx()'s). Notably, some modification has been made so
  251. that the cleaning loop checks only to make sure that the DescOwn bit
  252. isn't set in the status flag since the card is not required
  253. to set the entire flag to zero after processing.
  254. 01/15/1999 EPK In the hamachi_start_tx function, the Tx ring full flag is
  255. checked before attempting to add a buffer to the ring. If the ring is full
  256. an attempt is made to free any dirty buffers and thus find space for
  257. the new buffer or the function returns non-zero which should case the
  258. scheduler to reschedule the buffer later.
  259. 01/15/1999 EPK Some adjustments were made to the chip initialization.
  260. End-to-end flow control should now be fully active and the interrupt
  261. algorithm vars have been changed. These could probably use further tuning.
  262. 01/15/1999 EPK Added the max_{rx,tx}_latency options. These are used to
  263. set the rx and tx latencies for the Hamachi interrupts. If you're having
  264. problems with network stalls, try setting these to higher values.
  265. Valid values are 0x00 through 0xff.
  266. 01/15/1999 EPK In general, the overall bandwidth has increased and
  267. latencies are better (sometimes by a factor of 2). Stalls are rare at
  268. this point, however there still appears to be a bug somewhere between the
  269. hardware and driver. TCP checksum errors under load also appear to be
  270. eliminated at this point.
  271. 01/18/1999 EPK Ensured that the DescEndRing bit was being set on both the
  272. Rx and Tx rings. This appears to have been affecting whether a particular
  273. peer-to-peer connection would hang under high load. I believe the Rx
  274. rings was typically getting set correctly, but the Tx ring wasn't getting
  275. the DescEndRing bit set during initialization. ??? Does this mean the
  276. hamachi card is using the DescEndRing in processing even if a particular
  277. slot isn't in use -- hypothetically, the card might be searching the
  278. entire Tx ring for slots with the DescOwn bit set and then processing
  279. them. If the DescEndRing bit isn't set, then it might just wander off
  280. through memory until it hits a chunk of data with that bit set
  281. and then looping back.
  282. 02/09/1999 EPK Added Michel Mueller's TxDMA Interrupt and Tx-timeout
  283. problem (TxCmd and RxCmd need only to be set when idle or stopped.
  284. 02/09/1999 EPK Added code to check/reset dev->tbusy in hamachi_interrupt.
  285. (Michel Mueller pointed out the ``permanently busy'' potential
  286. problem here).
  287. 02/22/1999 EPK Added Pete Wyckoff's ioctl to control the Tx/Rx latencies.
  288. 02/23/1999 EPK Verified that the interrupt status field bits for Tx were
  289. incorrectly defined and corrected (as per Michel Mueller).
  290. 02/23/1999 EPK Corrected the Tx full check to check that at least 4 slots
  291. were available before reseting the tbusy and tx_full flags
  292. (as per Michel Mueller).
  293. 03/11/1999 EPK Added Pete Wyckoff's hardware checksumming support.
  294. 12/31/1999 KDU Cleaned up assorted things and added Don's code to force
  295. 32 bit.
  296. 02/20/2000 KDU Some of the control was just plain odd. Cleaned up the
  297. hamachi_start_xmit() and hamachi_interrupt() code. There is still some
  298. re-structuring I would like to do.
  299. 03/01/2000 KDU Experimenting with a WIDE range of interrupt mitigation
  300. parameters on a dual P3-450 setup yielded the new default interrupt
  301. mitigation parameters. Tx should interrupt VERY infrequently due to
  302. Eric's scheme. Rx should be more often...
  303. 03/13/2000 KDU Added a patch to make the Rx Checksum code interact
  304. nicely with non-linux machines.
  305. 03/13/2000 KDU Experimented with some of the configuration values:
  306. -It seems that enabling PCI performance commands for descriptors
  307. (changing RxDMACtrl and TxDMACtrl lower nibble from 5 to D) has minimal
  308. performance impact for any of my tests. (ttcp, netpipe, netperf) I will
  309. leave them that way until I hear further feedback.
  310. -Increasing the PCI_LATENCY_TIMER to 130
  311. (2 + (burst size of 128 * (0 wait states + 1))) seems to slightly
  312. degrade performance. Leaving default at 64 pending further information.
  313. 03/14/2000 KDU Further tuning:
  314. -adjusted boguscnt in hamachi_rx() to depend on interrupt
  315. mitigation parameters chosen.
  316. -Selected a set of interrupt parameters based on some extensive testing.
  317. These may change with more testing.
  318. TO DO:
  319. -Consider borrowing from the acenic driver code to check PCI_COMMAND for
  320. PCI_COMMAND_INVALIDATE. Set maximum burst size to cache line size in
  321. that case.
  322. -fix the reset procedure. It doesn't quite work.
  323. */
  324. /* A few values that may be tweaked. */
  325. /* Size of each temporary Rx buffer, calculated as:
  326. * 1518 bytes (ethernet packet) + 2 bytes (to get 8 byte alignment for
  327. * the card) + 8 bytes of status info + 8 bytes for the Rx Checksum +
  328. * 2 more because we use skb_reserve.
  329. */
  330. #define PKT_BUF_SZ 1538
  331. /* For now, this is going to be set to the maximum size of an ethernet
  332. * packet. Eventually, we may want to make it a variable that is
  333. * related to the MTU
  334. */
  335. #define MAX_FRAME_SIZE 1518
  336. /* The rest of these values should never change. */
  337. static void hamachi_timer(unsigned long data);
  338. enum capability_flags {CanHaveMII=1, };
  339. static const struct chip_info {
  340. u16 vendor_id, device_id, device_id_mask, pad;
  341. const char *name;
  342. void (*media_timer)(unsigned long data);
  343. int flags;
  344. } chip_tbl[] = {
  345. {0x1318, 0x0911, 0xffff, 0, "Hamachi GNIC-II", hamachi_timer, 0},
  346. {0,},
  347. };
  348. /* Offsets to the Hamachi registers. Various sizes. */
  349. enum hamachi_offsets {
  350. TxDMACtrl=0x00, TxCmd=0x04, TxStatus=0x06, TxPtr=0x08, TxCurPtr=0x10,
  351. RxDMACtrl=0x20, RxCmd=0x24, RxStatus=0x26, RxPtr=0x28, RxCurPtr=0x30,
  352. PCIClkMeas=0x060, MiscStatus=0x066, ChipRev=0x68, ChipReset=0x06B,
  353. LEDCtrl=0x06C, VirtualJumpers=0x06D, GPIO=0x6E,
  354. TxChecksum=0x074, RxChecksum=0x076,
  355. TxIntrCtrl=0x078, RxIntrCtrl=0x07C,
  356. InterruptEnable=0x080, InterruptClear=0x084, IntrStatus=0x088,
  357. EventStatus=0x08C,
  358. MACCnfg=0x0A0, FrameGap0=0x0A2, FrameGap1=0x0A4,
  359. /* See enum MII_offsets below. */
  360. MACCnfg2=0x0B0, RxDepth=0x0B8, FlowCtrl=0x0BC, MaxFrameSize=0x0CE,
  361. AddrMode=0x0D0, StationAddr=0x0D2,
  362. /* Gigabit AutoNegotiation. */
  363. ANCtrl=0x0E0, ANStatus=0x0E2, ANXchngCtrl=0x0E4, ANAdvertise=0x0E8,
  364. ANLinkPartnerAbility=0x0EA,
  365. EECmdStatus=0x0F0, EEData=0x0F1, EEAddr=0x0F2,
  366. FIFOcfg=0x0F8,
  367. };
  368. /* Offsets to the MII-mode registers. */
  369. enum MII_offsets {
  370. MII_Cmd=0xA6, MII_Addr=0xA8, MII_Wr_Data=0xAA, MII_Rd_Data=0xAC,
  371. MII_Status=0xAE,
  372. };
  373. /* Bits in the interrupt status/mask registers. */
  374. enum intr_status_bits {
  375. IntrRxDone=0x01, IntrRxPCIFault=0x02, IntrRxPCIErr=0x04,
  376. IntrTxDone=0x100, IntrTxPCIFault=0x200, IntrTxPCIErr=0x400,
  377. LinkChange=0x10000, NegotiationChange=0x20000, StatsMax=0x40000, };
  378. /* The Hamachi Rx and Tx buffer descriptors. */
  379. struct hamachi_desc {
  380. u32 status_n_length;
  381. #if ADDRLEN == 64
  382. u32 pad;
  383. u64 addr;
  384. #else
  385. u32 addr;
  386. #endif
  387. };
  388. /* Bits in hamachi_desc.status_n_length */
  389. enum desc_status_bits {
  390. DescOwn=0x80000000, DescEndPacket=0x40000000, DescEndRing=0x20000000,
  391. DescIntr=0x10000000,
  392. };
  393. #define PRIV_ALIGN 15 /* Required alignment mask */
  394. #define MII_CNT 4
  395. struct hamachi_private {
  396. /* Descriptor rings first for alignment. Tx requires a second descriptor
  397. for status. */
  398. struct hamachi_desc *rx_ring;
  399. struct hamachi_desc *tx_ring;
  400. struct sk_buff* rx_skbuff[RX_RING_SIZE];
  401. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  402. dma_addr_t tx_ring_dma;
  403. dma_addr_t rx_ring_dma;
  404. struct net_device_stats stats;
  405. struct timer_list timer; /* Media selection timer. */
  406. /* Frequently used and paired value: keep adjacent for cache effect. */
  407. spinlock_t lock;
  408. int chip_id;
  409. unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */
  410. unsigned int cur_tx, dirty_tx;
  411. unsigned int rx_buf_sz; /* Based on MTU+slack. */
  412. unsigned int tx_full:1; /* The Tx queue is full. */
  413. unsigned int duplex_lock:1;
  414. unsigned int default_port:4; /* Last dev->if_port value. */
  415. /* MII transceiver section. */
  416. int mii_cnt; /* MII device addresses. */
  417. struct mii_if_info mii_if; /* MII lib hooks/info */
  418. unsigned char phys[MII_CNT]; /* MII device addresses, only first one used. */
  419. u32 rx_int_var, tx_int_var; /* interrupt control variables */
  420. u32 option; /* Hold on to a copy of the options */
  421. struct pci_dev *pci_dev;
  422. void __iomem *base;
  423. };
  424. MODULE_AUTHOR("Donald Becker <becker@scyld.com>, Eric Kasten <kasten@nscl.msu.edu>, Keith Underwood <keithu@parl.clemson.edu>");
  425. MODULE_DESCRIPTION("Packet Engines 'Hamachi' GNIC-II Gigabit Ethernet driver");
  426. MODULE_LICENSE("GPL");
  427. module_param(max_interrupt_work, int, 0);
  428. module_param(mtu, int, 0);
  429. module_param(debug, int, 0);
  430. module_param(min_rx_pkt, int, 0);
  431. module_param(max_rx_gap, int, 0);
  432. module_param(max_rx_latency, int, 0);
  433. module_param(min_tx_pkt, int, 0);
  434. module_param(max_tx_gap, int, 0);
  435. module_param(max_tx_latency, int, 0);
  436. module_param(rx_copybreak, int, 0);
  437. module_param_array(rx_params, int, NULL, 0);
  438. module_param_array(tx_params, int, NULL, 0);
  439. module_param_array(options, int, NULL, 0);
  440. module_param_array(full_duplex, int, NULL, 0);
  441. module_param(force32, int, 0);
  442. MODULE_PARM_DESC(max_interrupt_work, "GNIC-II maximum events handled per interrupt");
  443. MODULE_PARM_DESC(mtu, "GNIC-II MTU (all boards)");
  444. MODULE_PARM_DESC(debug, "GNIC-II debug level (0-7)");
  445. MODULE_PARM_DESC(min_rx_pkt, "GNIC-II minimum Rx packets processed between interrupts");
  446. MODULE_PARM_DESC(max_rx_gap, "GNIC-II maximum Rx inter-packet gap in 8.192 microsecond units");
  447. MODULE_PARM_DESC(max_rx_latency, "GNIC-II time between Rx interrupts in 8.192 microsecond units");
  448. MODULE_PARM_DESC(min_tx_pkt, "GNIC-II minimum Tx packets processed between interrupts");
  449. MODULE_PARM_DESC(max_tx_gap, "GNIC-II maximum Tx inter-packet gap in 8.192 microsecond units");
  450. MODULE_PARM_DESC(max_tx_latency, "GNIC-II time between Tx interrupts in 8.192 microsecond units");
  451. MODULE_PARM_DESC(rx_copybreak, "GNIC-II copy breakpoint for copy-only-tiny-frames");
  452. MODULE_PARM_DESC(rx_params, "GNIC-II min_rx_pkt+max_rx_gap+max_rx_latency");
  453. MODULE_PARM_DESC(tx_params, "GNIC-II min_tx_pkt+max_tx_gap+max_tx_latency");
  454. MODULE_PARM_DESC(options, "GNIC-II Bits 0-3: media type, bits 4-6: as force32, bit 7: half duplex, bit 9 full duplex");
  455. MODULE_PARM_DESC(full_duplex, "GNIC-II full duplex setting(s) (1)");
  456. MODULE_PARM_DESC(force32, "GNIC-II: Bit 0: 32 bit PCI, bit 1: disable parity, bit 2: 64 bit PCI (all boards)");
  457. static int read_eeprom(void __iomem *ioaddr, int location);
  458. static int mdio_read(struct net_device *dev, int phy_id, int location);
  459. static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
  460. static int hamachi_open(struct net_device *dev);
  461. static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  462. static void hamachi_timer(unsigned long data);
  463. static void hamachi_tx_timeout(struct net_device *dev);
  464. static void hamachi_init_ring(struct net_device *dev);
  465. static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev);
  466. static irqreturn_t hamachi_interrupt(int irq, void *dev_instance);
  467. static int hamachi_rx(struct net_device *dev);
  468. static inline int hamachi_tx(struct net_device *dev);
  469. static void hamachi_error(struct net_device *dev, int intr_status);
  470. static int hamachi_close(struct net_device *dev);
  471. static struct net_device_stats *hamachi_get_stats(struct net_device *dev);
  472. static void set_rx_mode(struct net_device *dev);
  473. static const struct ethtool_ops ethtool_ops;
  474. static const struct ethtool_ops ethtool_ops_no_mii;
  475. static int __devinit hamachi_init_one (struct pci_dev *pdev,
  476. const struct pci_device_id *ent)
  477. {
  478. struct hamachi_private *hmp;
  479. int option, i, rx_int_var, tx_int_var, boguscnt;
  480. int chip_id = ent->driver_data;
  481. int irq;
  482. void __iomem *ioaddr;
  483. unsigned long base;
  484. static int card_idx;
  485. struct net_device *dev;
  486. void *ring_space;
  487. dma_addr_t ring_dma;
  488. int ret = -ENOMEM;
  489. /* when built into the kernel, we only print version if device is found */
  490. #ifndef MODULE
  491. static int printed_version;
  492. if (!printed_version++)
  493. printk(version);
  494. #endif
  495. if (pci_enable_device(pdev)) {
  496. ret = -EIO;
  497. goto err_out;
  498. }
  499. base = pci_resource_start(pdev, 0);
  500. #ifdef __alpha__ /* Really "64 bit addrs" */
  501. base |= (pci_resource_start(pdev, 1) << 32);
  502. #endif
  503. pci_set_master(pdev);
  504. i = pci_request_regions(pdev, DRV_NAME);
  505. if (i)
  506. return i;
  507. irq = pdev->irq;
  508. ioaddr = ioremap(base, 0x400);
  509. if (!ioaddr)
  510. goto err_out_release;
  511. dev = alloc_etherdev(sizeof(struct hamachi_private));
  512. if (!dev)
  513. goto err_out_iounmap;
  514. SET_MODULE_OWNER(dev);
  515. SET_NETDEV_DEV(dev, &pdev->dev);
  516. #ifdef TX_CHECKSUM
  517. printk("check that skbcopy in ip_queue_xmit isn't happening\n");
  518. dev->hard_header_len += 8; /* for cksum tag */
  519. #endif
  520. for (i = 0; i < 6; i++)
  521. dev->dev_addr[i] = 1 ? read_eeprom(ioaddr, 4 + i)
  522. : readb(ioaddr + StationAddr + i);
  523. #if ! defined(final_version)
  524. if (hamachi_debug > 4)
  525. for (i = 0; i < 0x10; i++)
  526. printk("%2.2x%s",
  527. read_eeprom(ioaddr, i), i % 16 != 15 ? " " : "\n");
  528. #endif
  529. hmp = netdev_priv(dev);
  530. spin_lock_init(&hmp->lock);
  531. hmp->mii_if.dev = dev;
  532. hmp->mii_if.mdio_read = mdio_read;
  533. hmp->mii_if.mdio_write = mdio_write;
  534. hmp->mii_if.phy_id_mask = 0x1f;
  535. hmp->mii_if.reg_num_mask = 0x1f;
  536. ring_space = pci_alloc_consistent(pdev, TX_TOTAL_SIZE, &ring_dma);
  537. if (!ring_space)
  538. goto err_out_cleardev;
  539. hmp->tx_ring = (struct hamachi_desc *)ring_space;
  540. hmp->tx_ring_dma = ring_dma;
  541. ring_space = pci_alloc_consistent(pdev, RX_TOTAL_SIZE, &ring_dma);
  542. if (!ring_space)
  543. goto err_out_unmap_tx;
  544. hmp->rx_ring = (struct hamachi_desc *)ring_space;
  545. hmp->rx_ring_dma = ring_dma;
  546. /* Check for options being passed in */
  547. option = card_idx < MAX_UNITS ? options[card_idx] : 0;
  548. if (dev->mem_start)
  549. option = dev->mem_start;
  550. /* If the bus size is misidentified, do the following. */
  551. force32 = force32 ? force32 :
  552. ((option >= 0) ? ((option & 0x00000070) >> 4) : 0 );
  553. if (force32)
  554. writeb(force32, ioaddr + VirtualJumpers);
  555. /* Hmmm, do we really need to reset the chip???. */
  556. writeb(0x01, ioaddr + ChipReset);
  557. /* After a reset, the clock speed measurement of the PCI bus will not
  558. * be valid for a moment. Wait for a little while until it is. If
  559. * it takes more than 10ms, forget it.
  560. */
  561. udelay(10);
  562. i = readb(ioaddr + PCIClkMeas);
  563. for (boguscnt = 0; (!(i & 0x080)) && boguscnt < 1000; boguscnt++){
  564. udelay(10);
  565. i = readb(ioaddr + PCIClkMeas);
  566. }
  567. hmp->base = ioaddr;
  568. dev->base_addr = (unsigned long)ioaddr;
  569. dev->irq = irq;
  570. pci_set_drvdata(pdev, dev);
  571. hmp->chip_id = chip_id;
  572. hmp->pci_dev = pdev;
  573. /* The lower four bits are the media type. */
  574. if (option > 0) {
  575. hmp->option = option;
  576. if (option & 0x200)
  577. hmp->mii_if.full_duplex = 1;
  578. else if (option & 0x080)
  579. hmp->mii_if.full_duplex = 0;
  580. hmp->default_port = option & 15;
  581. if (hmp->default_port)
  582. hmp->mii_if.force_media = 1;
  583. }
  584. if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0)
  585. hmp->mii_if.full_duplex = 1;
  586. /* lock the duplex mode if someone specified a value */
  587. if (hmp->mii_if.full_duplex || (option & 0x080))
  588. hmp->duplex_lock = 1;
  589. /* Set interrupt tuning parameters */
  590. max_rx_latency = max_rx_latency & 0x00ff;
  591. max_rx_gap = max_rx_gap & 0x00ff;
  592. min_rx_pkt = min_rx_pkt & 0x00ff;
  593. max_tx_latency = max_tx_latency & 0x00ff;
  594. max_tx_gap = max_tx_gap & 0x00ff;
  595. min_tx_pkt = min_tx_pkt & 0x00ff;
  596. rx_int_var = card_idx < MAX_UNITS ? rx_params[card_idx] : -1;
  597. tx_int_var = card_idx < MAX_UNITS ? tx_params[card_idx] : -1;
  598. hmp->rx_int_var = rx_int_var >= 0 ? rx_int_var :
  599. (min_rx_pkt << 16 | max_rx_gap << 8 | max_rx_latency);
  600. hmp->tx_int_var = tx_int_var >= 0 ? tx_int_var :
  601. (min_tx_pkt << 16 | max_tx_gap << 8 | max_tx_latency);
  602. /* The Hamachi-specific entries in the device structure. */
  603. dev->open = &hamachi_open;
  604. dev->hard_start_xmit = &hamachi_start_xmit;
  605. dev->stop = &hamachi_close;
  606. dev->get_stats = &hamachi_get_stats;
  607. dev->set_multicast_list = &set_rx_mode;
  608. dev->do_ioctl = &netdev_ioctl;
  609. if (chip_tbl[hmp->chip_id].flags & CanHaveMII)
  610. SET_ETHTOOL_OPS(dev, &ethtool_ops);
  611. else
  612. SET_ETHTOOL_OPS(dev, &ethtool_ops_no_mii);
  613. dev->tx_timeout = &hamachi_tx_timeout;
  614. dev->watchdog_timeo = TX_TIMEOUT;
  615. if (mtu)
  616. dev->mtu = mtu;
  617. i = register_netdev(dev);
  618. if (i) {
  619. ret = i;
  620. goto err_out_unmap_rx;
  621. }
  622. printk(KERN_INFO "%s: %s type %x at %p, ",
  623. dev->name, chip_tbl[chip_id].name, readl(ioaddr + ChipRev),
  624. ioaddr);
  625. for (i = 0; i < 5; i++)
  626. printk("%2.2x:", dev->dev_addr[i]);
  627. printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
  628. i = readb(ioaddr + PCIClkMeas);
  629. printk(KERN_INFO "%s: %d-bit %d Mhz PCI bus (%d), Virtual Jumpers "
  630. "%2.2x, LPA %4.4x.\n",
  631. dev->name, readw(ioaddr + MiscStatus) & 1 ? 64 : 32,
  632. i ? 2000/(i&0x7f) : 0, i&0x7f, (int)readb(ioaddr + VirtualJumpers),
  633. readw(ioaddr + ANLinkPartnerAbility));
  634. if (chip_tbl[hmp->chip_id].flags & CanHaveMII) {
  635. int phy, phy_idx = 0;
  636. for (phy = 0; phy < 32 && phy_idx < MII_CNT; phy++) {
  637. int mii_status = mdio_read(dev, phy, MII_BMSR);
  638. if (mii_status != 0xffff &&
  639. mii_status != 0x0000) {
  640. hmp->phys[phy_idx++] = phy;
  641. hmp->mii_if.advertising = mdio_read(dev, phy, MII_ADVERTISE);
  642. printk(KERN_INFO "%s: MII PHY found at address %d, status "
  643. "0x%4.4x advertising %4.4x.\n",
  644. dev->name, phy, mii_status, hmp->mii_if.advertising);
  645. }
  646. }
  647. hmp->mii_cnt = phy_idx;
  648. if (hmp->mii_cnt > 0)
  649. hmp->mii_if.phy_id = hmp->phys[0];
  650. else
  651. memset(&hmp->mii_if, 0, sizeof(hmp->mii_if));
  652. }
  653. /* Configure gigabit autonegotiation. */
  654. writew(0x0400, ioaddr + ANXchngCtrl); /* Enable legacy links. */
  655. writew(0x08e0, ioaddr + ANAdvertise); /* Set our advertise word. */
  656. writew(0x1000, ioaddr + ANCtrl); /* Enable negotiation */
  657. card_idx++;
  658. return 0;
  659. err_out_unmap_rx:
  660. pci_free_consistent(pdev, RX_TOTAL_SIZE, hmp->rx_ring,
  661. hmp->rx_ring_dma);
  662. err_out_unmap_tx:
  663. pci_free_consistent(pdev, TX_TOTAL_SIZE, hmp->tx_ring,
  664. hmp->tx_ring_dma);
  665. err_out_cleardev:
  666. free_netdev (dev);
  667. err_out_iounmap:
  668. iounmap(ioaddr);
  669. err_out_release:
  670. pci_release_regions(pdev);
  671. err_out:
  672. return ret;
  673. }
  674. static int __devinit read_eeprom(void __iomem *ioaddr, int location)
  675. {
  676. int bogus_cnt = 1000;
  677. /* We should check busy first - per docs -KDU */
  678. while ((readb(ioaddr + EECmdStatus) & 0x40) && --bogus_cnt > 0);
  679. writew(location, ioaddr + EEAddr);
  680. writeb(0x02, ioaddr + EECmdStatus);
  681. bogus_cnt = 1000;
  682. while ((readb(ioaddr + EECmdStatus) & 0x40) && --bogus_cnt > 0);
  683. if (hamachi_debug > 5)
  684. printk(" EEPROM status is %2.2x after %d ticks.\n",
  685. (int)readb(ioaddr + EECmdStatus), 1000- bogus_cnt);
  686. return readb(ioaddr + EEData);
  687. }
  688. /* MII Managemen Data I/O accesses.
  689. These routines assume the MDIO controller is idle, and do not exit until
  690. the command is finished. */
  691. static int mdio_read(struct net_device *dev, int phy_id, int location)
  692. {
  693. struct hamachi_private *hmp = netdev_priv(dev);
  694. void __iomem *ioaddr = hmp->base;
  695. int i;
  696. /* We should check busy first - per docs -KDU */
  697. for (i = 10000; i >= 0; i--)
  698. if ((readw(ioaddr + MII_Status) & 1) == 0)
  699. break;
  700. writew((phy_id<<8) + location, ioaddr + MII_Addr);
  701. writew(0x0001, ioaddr + MII_Cmd);
  702. for (i = 10000; i >= 0; i--)
  703. if ((readw(ioaddr + MII_Status) & 1) == 0)
  704. break;
  705. return readw(ioaddr + MII_Rd_Data);
  706. }
  707. static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
  708. {
  709. struct hamachi_private *hmp = netdev_priv(dev);
  710. void __iomem *ioaddr = hmp->base;
  711. int i;
  712. /* We should check busy first - per docs -KDU */
  713. for (i = 10000; i >= 0; i--)
  714. if ((readw(ioaddr + MII_Status) & 1) == 0)
  715. break;
  716. writew((phy_id<<8) + location, ioaddr + MII_Addr);
  717. writew(value, ioaddr + MII_Wr_Data);
  718. /* Wait for the command to finish. */
  719. for (i = 10000; i >= 0; i--)
  720. if ((readw(ioaddr + MII_Status) & 1) == 0)
  721. break;
  722. return;
  723. }
  724. static int hamachi_open(struct net_device *dev)
  725. {
  726. struct hamachi_private *hmp = netdev_priv(dev);
  727. void __iomem *ioaddr = hmp->base;
  728. int i;
  729. u32 rx_int_var, tx_int_var;
  730. u16 fifo_info;
  731. i = request_irq(dev->irq, &hamachi_interrupt, IRQF_SHARED, dev->name, dev);
  732. if (i)
  733. return i;
  734. if (hamachi_debug > 1)
  735. printk(KERN_DEBUG "%s: hamachi_open() irq %d.\n",
  736. dev->name, dev->irq);
  737. hamachi_init_ring(dev);
  738. #if ADDRLEN == 64
  739. /* writellll anyone ? */
  740. writel(cpu_to_le64(hmp->rx_ring_dma), ioaddr + RxPtr);
  741. writel(cpu_to_le64(hmp->rx_ring_dma) >> 32, ioaddr + RxPtr + 4);
  742. writel(cpu_to_le64(hmp->tx_ring_dma), ioaddr + TxPtr);
  743. writel(cpu_to_le64(hmp->tx_ring_dma) >> 32, ioaddr + TxPtr + 4);
  744. #else
  745. writel(cpu_to_le32(hmp->rx_ring_dma), ioaddr + RxPtr);
  746. writel(cpu_to_le32(hmp->tx_ring_dma), ioaddr + TxPtr);
  747. #endif
  748. /* TODO: It would make sense to organize this as words since the card
  749. * documentation does. -KDU
  750. */
  751. for (i = 0; i < 6; i++)
  752. writeb(dev->dev_addr[i], ioaddr + StationAddr + i);
  753. /* Initialize other registers: with so many this eventually this will
  754. converted to an offset/value list. */
  755. /* Configure the FIFO */
  756. fifo_info = (readw(ioaddr + GPIO) & 0x00C0) >> 6;
  757. switch (fifo_info){
  758. case 0 :
  759. /* No FIFO */
  760. writew(0x0000, ioaddr + FIFOcfg);
  761. break;
  762. case 1 :
  763. /* Configure the FIFO for 512K external, 16K used for Tx. */
  764. writew(0x0028, ioaddr + FIFOcfg);
  765. break;
  766. case 2 :
  767. /* Configure the FIFO for 1024 external, 32K used for Tx. */
  768. writew(0x004C, ioaddr + FIFOcfg);
  769. break;
  770. case 3 :
  771. /* Configure the FIFO for 2048 external, 32K used for Tx. */
  772. writew(0x006C, ioaddr + FIFOcfg);
  773. break;
  774. default :
  775. printk(KERN_WARNING "%s: Unsupported external memory config!\n",
  776. dev->name);
  777. /* Default to no FIFO */
  778. writew(0x0000, ioaddr + FIFOcfg);
  779. break;
  780. }
  781. if (dev->if_port == 0)
  782. dev->if_port = hmp->default_port;
  783. /* Setting the Rx mode will start the Rx process. */
  784. /* If someone didn't choose a duplex, default to full-duplex */
  785. if (hmp->duplex_lock != 1)
  786. hmp->mii_if.full_duplex = 1;
  787. /* always 1, takes no more time to do it */
  788. writew(0x0001, ioaddr + RxChecksum);
  789. #ifdef TX_CHECKSUM
  790. writew(0x0001, ioaddr + TxChecksum);
  791. #else
  792. writew(0x0000, ioaddr + TxChecksum);
  793. #endif
  794. writew(0x8000, ioaddr + MACCnfg); /* Soft reset the MAC */
  795. writew(0x215F, ioaddr + MACCnfg);
  796. writew(0x000C, ioaddr + FrameGap0);
  797. /* WHAT?!?!? Why isn't this documented somewhere? -KDU */
  798. writew(0x1018, ioaddr + FrameGap1);
  799. /* Why do we enable receives/transmits here? -KDU */
  800. writew(0x0780, ioaddr + MACCnfg2); /* Upper 16 bits control LEDs. */
  801. /* Enable automatic generation of flow control frames, period 0xffff. */
  802. writel(0x0030FFFF, ioaddr + FlowCtrl);
  803. writew(MAX_FRAME_SIZE, ioaddr + MaxFrameSize); /* dev->mtu+14 ??? */
  804. /* Enable legacy links. */
  805. writew(0x0400, ioaddr + ANXchngCtrl); /* Enable legacy links. */
  806. /* Initial Link LED to blinking red. */
  807. writeb(0x03, ioaddr + LEDCtrl);
  808. /* Configure interrupt mitigation. This has a great effect on
  809. performance, so systems tuning should start here!. */
  810. rx_int_var = hmp->rx_int_var;
  811. tx_int_var = hmp->tx_int_var;
  812. if (hamachi_debug > 1) {
  813. printk("max_tx_latency: %d, max_tx_gap: %d, min_tx_pkt: %d\n",
  814. tx_int_var & 0x00ff, (tx_int_var & 0x00ff00) >> 8,
  815. (tx_int_var & 0x00ff0000) >> 16);
  816. printk("max_rx_latency: %d, max_rx_gap: %d, min_rx_pkt: %d\n",
  817. rx_int_var & 0x00ff, (rx_int_var & 0x00ff00) >> 8,
  818. (rx_int_var & 0x00ff0000) >> 16);
  819. printk("rx_int_var: %x, tx_int_var: %x\n", rx_int_var, tx_int_var);
  820. }
  821. writel(tx_int_var, ioaddr + TxIntrCtrl);
  822. writel(rx_int_var, ioaddr + RxIntrCtrl);
  823. set_rx_mode(dev);
  824. netif_start_queue(dev);
  825. /* Enable interrupts by setting the interrupt mask. */
  826. writel(0x80878787, ioaddr + InterruptEnable);
  827. writew(0x0000, ioaddr + EventStatus); /* Clear non-interrupting events */
  828. /* Configure and start the DMA channels. */
  829. /* Burst sizes are in the low three bits: size = 4<<(val&7) */
  830. #if ADDRLEN == 64
  831. writew(0x005D, ioaddr + RxDMACtrl); /* 128 dword bursts */
  832. writew(0x005D, ioaddr + TxDMACtrl);
  833. #else
  834. writew(0x001D, ioaddr + RxDMACtrl);
  835. writew(0x001D, ioaddr + TxDMACtrl);
  836. #endif
  837. writew(0x0001, ioaddr + RxCmd);
  838. if (hamachi_debug > 2) {
  839. printk(KERN_DEBUG "%s: Done hamachi_open(), status: Rx %x Tx %x.\n",
  840. dev->name, readw(ioaddr + RxStatus), readw(ioaddr + TxStatus));
  841. }
  842. /* Set the timer to check for link beat. */
  843. init_timer(&hmp->timer);
  844. hmp->timer.expires = RUN_AT((24*HZ)/10); /* 2.4 sec. */
  845. hmp->timer.data = (unsigned long)dev;
  846. hmp->timer.function = &hamachi_timer; /* timer handler */
  847. add_timer(&hmp->timer);
  848. return 0;
  849. }
  850. static inline int hamachi_tx(struct net_device *dev)
  851. {
  852. struct hamachi_private *hmp = netdev_priv(dev);
  853. /* Update the dirty pointer until we find an entry that is
  854. still owned by the card */
  855. for (; hmp->cur_tx - hmp->dirty_tx > 0; hmp->dirty_tx++) {
  856. int entry = hmp->dirty_tx % TX_RING_SIZE;
  857. struct sk_buff *skb;
  858. if (hmp->tx_ring[entry].status_n_length & cpu_to_le32(DescOwn))
  859. break;
  860. /* Free the original skb. */
  861. skb = hmp->tx_skbuff[entry];
  862. if (skb != 0) {
  863. pci_unmap_single(hmp->pci_dev,
  864. hmp->tx_ring[entry].addr, skb->len,
  865. PCI_DMA_TODEVICE);
  866. dev_kfree_skb(skb);
  867. hmp->tx_skbuff[entry] = NULL;
  868. }
  869. hmp->tx_ring[entry].status_n_length = 0;
  870. if (entry >= TX_RING_SIZE-1)
  871. hmp->tx_ring[TX_RING_SIZE-1].status_n_length |=
  872. cpu_to_le32(DescEndRing);
  873. hmp->stats.tx_packets++;
  874. }
  875. return 0;
  876. }
  877. static void hamachi_timer(unsigned long data)
  878. {
  879. struct net_device *dev = (struct net_device *)data;
  880. struct hamachi_private *hmp = netdev_priv(dev);
  881. void __iomem *ioaddr = hmp->base;
  882. int next_tick = 10*HZ;
  883. if (hamachi_debug > 2) {
  884. printk(KERN_INFO "%s: Hamachi Autonegotiation status %4.4x, LPA "
  885. "%4.4x.\n", dev->name, readw(ioaddr + ANStatus),
  886. readw(ioaddr + ANLinkPartnerAbility));
  887. printk(KERN_INFO "%s: Autonegotiation regs %4.4x %4.4x %4.4x "
  888. "%4.4x %4.4x %4.4x.\n", dev->name,
  889. readw(ioaddr + 0x0e0),
  890. readw(ioaddr + 0x0e2),
  891. readw(ioaddr + 0x0e4),
  892. readw(ioaddr + 0x0e6),
  893. readw(ioaddr + 0x0e8),
  894. readw(ioaddr + 0x0eA));
  895. }
  896. /* We could do something here... nah. */
  897. hmp->timer.expires = RUN_AT(next_tick);
  898. add_timer(&hmp->timer);
  899. }
  900. static void hamachi_tx_timeout(struct net_device *dev)
  901. {
  902. int i;
  903. struct hamachi_private *hmp = netdev_priv(dev);
  904. void __iomem *ioaddr = hmp->base;
  905. printk(KERN_WARNING "%s: Hamachi transmit timed out, status %8.8x,"
  906. " resetting...\n", dev->name, (int)readw(ioaddr + TxStatus));
  907. {
  908. int i;
  909. printk(KERN_DEBUG " Rx ring %p: ", hmp->rx_ring);
  910. for (i = 0; i < RX_RING_SIZE; i++)
  911. printk(" %8.8x", (unsigned int)hmp->rx_ring[i].status_n_length);
  912. printk("\n"KERN_DEBUG" Tx ring %p: ", hmp->tx_ring);
  913. for (i = 0; i < TX_RING_SIZE; i++)
  914. printk(" %4.4x", hmp->tx_ring[i].status_n_length);
  915. printk("\n");
  916. }
  917. /* Reinit the hardware and make sure the Rx and Tx processes
  918. are up and running.
  919. */
  920. dev->if_port = 0;
  921. /* The right way to do Reset. -KDU
  922. * -Clear OWN bit in all Rx/Tx descriptors
  923. * -Wait 50 uS for channels to go idle
  924. * -Turn off MAC receiver
  925. * -Issue Reset
  926. */
  927. for (i = 0; i < RX_RING_SIZE; i++)
  928. hmp->rx_ring[i].status_n_length &= cpu_to_le32(~DescOwn);
  929. /* Presume that all packets in the Tx queue are gone if we have to
  930. * re-init the hardware.
  931. */
  932. for (i = 0; i < TX_RING_SIZE; i++){
  933. struct sk_buff *skb;
  934. if (i >= TX_RING_SIZE - 1)
  935. hmp->tx_ring[i].status_n_length = cpu_to_le32(
  936. DescEndRing |
  937. (hmp->tx_ring[i].status_n_length & 0x0000FFFF));
  938. else
  939. hmp->tx_ring[i].status_n_length &= 0x0000ffff;
  940. skb = hmp->tx_skbuff[i];
  941. if (skb){
  942. pci_unmap_single(hmp->pci_dev, hmp->tx_ring[i].addr,
  943. skb->len, PCI_DMA_TODEVICE);
  944. dev_kfree_skb(skb);
  945. hmp->tx_skbuff[i] = NULL;
  946. }
  947. }
  948. udelay(60); /* Sleep 60 us just for safety sake */
  949. writew(0x0002, ioaddr + RxCmd); /* STOP Rx */
  950. writeb(0x01, ioaddr + ChipReset); /* Reinit the hardware */
  951. hmp->tx_full = 0;
  952. hmp->cur_rx = hmp->cur_tx = 0;
  953. hmp->dirty_rx = hmp->dirty_tx = 0;
  954. /* Rx packets are also presumed lost; however, we need to make sure a
  955. * ring of buffers is in tact. -KDU
  956. */
  957. for (i = 0; i < RX_RING_SIZE; i++){
  958. struct sk_buff *skb = hmp->rx_skbuff[i];
  959. if (skb){
  960. pci_unmap_single(hmp->pci_dev, hmp->rx_ring[i].addr,
  961. hmp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  962. dev_kfree_skb(skb);
  963. hmp->rx_skbuff[i] = NULL;
  964. }
  965. }
  966. /* Fill in the Rx buffers. Handle allocation failure gracefully. */
  967. for (i = 0; i < RX_RING_SIZE; i++) {
  968. struct sk_buff *skb = dev_alloc_skb(hmp->rx_buf_sz);
  969. hmp->rx_skbuff[i] = skb;
  970. if (skb == NULL)
  971. break;
  972. skb->dev = dev; /* Mark as being used by this device. */
  973. skb_reserve(skb, 2); /* 16 byte align the IP header. */
  974. hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
  975. skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
  976. hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn |
  977. DescEndPacket | DescIntr | (hmp->rx_buf_sz - 2));
  978. }
  979. hmp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
  980. /* Mark the last entry as wrapping the ring. */
  981. hmp->rx_ring[RX_RING_SIZE-1].status_n_length |= cpu_to_le32(DescEndRing);
  982. /* Trigger an immediate transmit demand. */
  983. dev->trans_start = jiffies;
  984. hmp->stats.tx_errors++;
  985. /* Restart the chip's Tx/Rx processes . */
  986. writew(0x0002, ioaddr + TxCmd); /* STOP Tx */
  987. writew(0x0001, ioaddr + TxCmd); /* START Tx */
  988. writew(0x0001, ioaddr + RxCmd); /* START Rx */
  989. netif_wake_queue(dev);
  990. }
  991. /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  992. static void hamachi_init_ring(struct net_device *dev)
  993. {
  994. struct hamachi_private *hmp = netdev_priv(dev);
  995. int i;
  996. hmp->tx_full = 0;
  997. hmp->cur_rx = hmp->cur_tx = 0;
  998. hmp->dirty_rx = hmp->dirty_tx = 0;
  999. #if 0
  1000. /* This is wrong. I'm not sure what the original plan was, but this
  1001. * is wrong. An MTU of 1 gets you a buffer of 1536, while an MTU
  1002. * of 1501 gets a buffer of 1533? -KDU
  1003. */
  1004. hmp->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
  1005. #endif
  1006. /* My attempt at a reasonable correction */
  1007. /* +26 gets the maximum ethernet encapsulation, +7 & ~7 because the
  1008. * card needs room to do 8 byte alignment, +2 so we can reserve
  1009. * the first 2 bytes, and +16 gets room for the status word from the
  1010. * card. -KDU
  1011. */
  1012. hmp->rx_buf_sz = (dev->mtu <= 1492 ? PKT_BUF_SZ :
  1013. (((dev->mtu+26+7) & ~7) + 2 + 16));
  1014. /* Initialize all Rx descriptors. */
  1015. for (i = 0; i < RX_RING_SIZE; i++) {
  1016. hmp->rx_ring[i].status_n_length = 0;
  1017. hmp->rx_skbuff[i] = NULL;
  1018. }
  1019. /* Fill in the Rx buffers. Handle allocation failure gracefully. */
  1020. for (i = 0; i < RX_RING_SIZE; i++) {
  1021. struct sk_buff *skb = dev_alloc_skb(hmp->rx_buf_sz);
  1022. hmp->rx_skbuff[i] = skb;
  1023. if (skb == NULL)
  1024. break;
  1025. skb->dev = dev; /* Mark as being used by this device. */
  1026. skb_reserve(skb, 2); /* 16 byte align the IP header. */
  1027. hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
  1028. skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
  1029. /* -2 because it doesn't REALLY have that first 2 bytes -KDU */
  1030. hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn |
  1031. DescEndPacket | DescIntr | (hmp->rx_buf_sz -2));
  1032. }
  1033. hmp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
  1034. hmp->rx_ring[RX_RING_SIZE-1].status_n_length |= cpu_to_le32(DescEndRing);
  1035. for (i = 0; i < TX_RING_SIZE; i++) {
  1036. hmp->tx_skbuff[i] = NULL;
  1037. hmp->tx_ring[i].status_n_length = 0;
  1038. }
  1039. /* Mark the last entry of the ring */
  1040. hmp->tx_ring[TX_RING_SIZE-1].status_n_length |= cpu_to_le32(DescEndRing);
  1041. return;
  1042. }
  1043. #ifdef TX_CHECKSUM
  1044. #define csum_add(it, val) \
  1045. do { \
  1046. it += (u16) (val); \
  1047. if (it & 0xffff0000) { \
  1048. it &= 0xffff; \
  1049. ++it; \
  1050. } \
  1051. } while (0)
  1052. /* printk("add %04x --> %04x\n", val, it); \ */
  1053. /* uh->len already network format, do not swap */
  1054. #define pseudo_csum_udp(sum,ih,uh) do { \
  1055. sum = 0; \
  1056. csum_add(sum, (ih)->saddr >> 16); \
  1057. csum_add(sum, (ih)->saddr & 0xffff); \
  1058. csum_add(sum, (ih)->daddr >> 16); \
  1059. csum_add(sum, (ih)->daddr & 0xffff); \
  1060. csum_add(sum, __constant_htons(IPPROTO_UDP)); \
  1061. csum_add(sum, (uh)->len); \
  1062. } while (0)
  1063. /* swap len */
  1064. #define pseudo_csum_tcp(sum,ih,len) do { \
  1065. sum = 0; \
  1066. csum_add(sum, (ih)->saddr >> 16); \
  1067. csum_add(sum, (ih)->saddr & 0xffff); \
  1068. csum_add(sum, (ih)->daddr >> 16); \
  1069. csum_add(sum, (ih)->daddr & 0xffff); \
  1070. csum_add(sum, __constant_htons(IPPROTO_TCP)); \
  1071. csum_add(sum, htons(len)); \
  1072. } while (0)
  1073. #endif
  1074. static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1075. {
  1076. struct hamachi_private *hmp = netdev_priv(dev);
  1077. unsigned entry;
  1078. u16 status;
  1079. /* Ok, now make sure that the queue has space before trying to
  1080. add another skbuff. if we return non-zero the scheduler
  1081. should interpret this as a queue full and requeue the buffer
  1082. for later.
  1083. */
  1084. if (hmp->tx_full) {
  1085. /* We should NEVER reach this point -KDU */
  1086. printk(KERN_WARNING "%s: Hamachi transmit queue full at slot %d.\n",dev->name, hmp->cur_tx);
  1087. /* Wake the potentially-idle transmit channel. */
  1088. /* If we don't need to read status, DON'T -KDU */
  1089. status=readw(hmp->base + TxStatus);
  1090. if( !(status & 0x0001) || (status & 0x0002))
  1091. writew(0x0001, hmp->base + TxCmd);
  1092. return 1;
  1093. }
  1094. /* Caution: the write order is important here, set the field
  1095. with the "ownership" bits last. */
  1096. /* Calculate the next Tx descriptor entry. */
  1097. entry = hmp->cur_tx % TX_RING_SIZE;
  1098. hmp->tx_skbuff[entry] = skb;
  1099. #ifdef TX_CHECKSUM
  1100. {
  1101. /* tack on checksum tag */
  1102. u32 tagval = 0;
  1103. struct ethhdr *eh = (struct ethhdr *)skb->data;
  1104. if (eh->h_proto == __constant_htons(ETH_P_IP)) {
  1105. struct iphdr *ih = (struct iphdr *)((char *)eh + ETH_HLEN);
  1106. if (ih->protocol == IPPROTO_UDP) {
  1107. struct udphdr *uh
  1108. = (struct udphdr *)((char *)ih + ih->ihl*4);
  1109. u32 offset = ((unsigned char *)uh + 6) - skb->data;
  1110. u32 pseudo;
  1111. pseudo_csum_udp(pseudo, ih, uh);
  1112. pseudo = htons(pseudo);
  1113. printk("udp cksum was %04x, sending pseudo %04x\n",
  1114. uh->check, pseudo);
  1115. uh->check = 0; /* zero out uh->check before card calc */
  1116. /*
  1117. * start at 14 (skip ethhdr), store at offset (uh->check),
  1118. * use pseudo value given.
  1119. */
  1120. tagval = (14 << 24) | (offset << 16) | pseudo;
  1121. } else if (ih->protocol == IPPROTO_TCP) {
  1122. printk("tcp, no auto cksum\n");
  1123. }
  1124. }
  1125. *(u32 *)skb_push(skb, 8) = tagval;
  1126. }
  1127. #endif
  1128. hmp->tx_ring[entry].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
  1129. skb->data, skb->len, PCI_DMA_TODEVICE));
  1130. /* Hmmmm, could probably put a DescIntr on these, but the way
  1131. the driver is currently coded makes Tx interrupts unnecessary
  1132. since the clearing of the Tx ring is handled by the start_xmit
  1133. routine. This organization helps mitigate the interrupts a
  1134. bit and probably renders the max_tx_latency param useless.
  1135. Update: Putting a DescIntr bit on all of the descriptors and
  1136. mitigating interrupt frequency with the tx_min_pkt parameter. -KDU
  1137. */
  1138. if (entry >= TX_RING_SIZE-1) /* Wrap ring */
  1139. hmp->tx_ring[entry].status_n_length = cpu_to_le32(DescOwn |
  1140. DescEndPacket | DescEndRing | DescIntr | skb->len);
  1141. else
  1142. hmp->tx_ring[entry].status_n_length = cpu_to_le32(DescOwn |
  1143. DescEndPacket | DescIntr | skb->len);
  1144. hmp->cur_tx++;
  1145. /* Non-x86 Todo: explicitly flush cache lines here. */
  1146. /* Wake the potentially-idle transmit channel. */
  1147. /* If we don't need to read status, DON'T -KDU */
  1148. status=readw(hmp->base + TxStatus);
  1149. if( !(status & 0x0001) || (status & 0x0002))
  1150. writew(0x0001, hmp->base + TxCmd);
  1151. /* Immediately before returning, let's clear as many entries as we can. */
  1152. hamachi_tx(dev);
  1153. /* We should kick the bottom half here, since we are not accepting
  1154. * interrupts with every packet. i.e. realize that Gigabit ethernet
  1155. * can transmit faster than ordinary machines can load packets;
  1156. * hence, any packet that got put off because we were in the transmit
  1157. * routine should IMMEDIATELY get a chance to be re-queued. -KDU
  1158. */
  1159. if ((hmp->cur_tx - hmp->dirty_tx) < (TX_RING_SIZE - 4))
  1160. netif_wake_queue(dev); /* Typical path */
  1161. else {
  1162. hmp->tx_full = 1;
  1163. netif_stop_queue(dev);
  1164. }
  1165. dev->trans_start = jiffies;
  1166. if (hamachi_debug > 4) {
  1167. printk(KERN_DEBUG "%s: Hamachi transmit frame #%d queued in slot %d.\n",
  1168. dev->name, hmp->cur_tx, entry);
  1169. }
  1170. return 0;
  1171. }
  1172. /* The interrupt handler does all of the Rx thread work and cleans up
  1173. after the Tx thread. */
  1174. static irqreturn_t hamachi_interrupt(int irq, void *dev_instance)
  1175. {
  1176. struct net_device *dev = dev_instance;
  1177. struct hamachi_private *hmp = netdev_priv(dev);
  1178. void __iomem *ioaddr = hmp->base;
  1179. long boguscnt = max_interrupt_work;
  1180. int handled = 0;
  1181. #ifndef final_version /* Can never occur. */
  1182. if (dev == NULL) {
  1183. printk (KERN_ERR "hamachi_interrupt(): irq %d for unknown device.\n", irq);
  1184. return IRQ_NONE;
  1185. }
  1186. #endif
  1187. spin_lock(&hmp->lock);
  1188. do {
  1189. u32 intr_status = readl(ioaddr + InterruptClear);
  1190. if (hamachi_debug > 4)
  1191. printk(KERN_DEBUG "%s: Hamachi interrupt, status %4.4x.\n",
  1192. dev->name, intr_status);
  1193. if (intr_status == 0)
  1194. break;
  1195. handled = 1;
  1196. if (intr_status & IntrRxDone)
  1197. hamachi_rx(dev);
  1198. if (intr_status & IntrTxDone){
  1199. /* This code should RARELY need to execute. After all, this is
  1200. * a gigabit link, it should consume packets as fast as we put
  1201. * them in AND we clear the Tx ring in hamachi_start_xmit().
  1202. */
  1203. if (hmp->tx_full){
  1204. for (; hmp->cur_tx - hmp->dirty_tx > 0; hmp->dirty_tx++){
  1205. int entry = hmp->dirty_tx % TX_RING_SIZE;
  1206. struct sk_buff *skb;
  1207. if (hmp->tx_ring[entry].status_n_length & cpu_to_le32(DescOwn))
  1208. break;
  1209. skb = hmp->tx_skbuff[entry];
  1210. /* Free the original skb. */
  1211. if (skb){
  1212. pci_unmap_single(hmp->pci_dev,
  1213. hmp->tx_ring[entry].addr,
  1214. skb->len,
  1215. PCI_DMA_TODEVICE);
  1216. dev_kfree_skb_irq(skb);
  1217. hmp->tx_skbuff[entry] = NULL;
  1218. }
  1219. hmp->tx_ring[entry].status_n_length = 0;
  1220. if (entry >= TX_RING_SIZE-1)
  1221. hmp->tx_ring[TX_RING_SIZE-1].status_n_length |=
  1222. cpu_to_le32(DescEndRing);
  1223. hmp->stats.tx_packets++;
  1224. }
  1225. if (hmp->cur_tx - hmp->dirty_tx < TX_RING_SIZE - 4){
  1226. /* The ring is no longer full */
  1227. hmp->tx_full = 0;
  1228. netif_wake_queue(dev);
  1229. }
  1230. } else {
  1231. netif_wake_queue(dev);
  1232. }
  1233. }
  1234. /* Abnormal error summary/uncommon events handlers. */
  1235. if (intr_status &
  1236. (IntrTxPCIFault | IntrTxPCIErr | IntrRxPCIFault | IntrRxPCIErr |
  1237. LinkChange | NegotiationChange | StatsMax))
  1238. hamachi_error(dev, intr_status);
  1239. if (--boguscnt < 0) {
  1240. printk(KERN_WARNING "%s: Too much work at interrupt, status=0x%4.4x.\n",
  1241. dev->name, intr_status);
  1242. break;
  1243. }
  1244. } while (1);
  1245. if (hamachi_debug > 3)
  1246. printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n",
  1247. dev->name, readl(ioaddr + IntrStatus));
  1248. #ifndef final_version
  1249. /* Code that should never be run! Perhaps remove after testing.. */
  1250. {
  1251. static int stopit = 10;
  1252. if (dev->start == 0 && --stopit < 0) {
  1253. printk(KERN_ERR "%s: Emergency stop, looping startup interrupt.\n",
  1254. dev->name);
  1255. free_irq(irq, dev);
  1256. }
  1257. }
  1258. #endif
  1259. spin_unlock(&hmp->lock);
  1260. return IRQ_RETVAL(handled);
  1261. }
  1262. /* This routine is logically part of the interrupt handler, but separated
  1263. for clarity and better register allocation. */
  1264. static int hamachi_rx(struct net_device *dev)
  1265. {
  1266. struct hamachi_private *hmp = netdev_priv(dev);
  1267. int entry = hmp->cur_rx % RX_RING_SIZE;
  1268. int boguscnt = (hmp->dirty_rx + RX_RING_SIZE) - hmp->cur_rx;
  1269. if (hamachi_debug > 4) {
  1270. printk(KERN_DEBUG " In hamachi_rx(), entry %d status %4.4x.\n",
  1271. entry, hmp->rx_ring[entry].status_n_length);
  1272. }
  1273. /* If EOP is set on the next entry, it's a new packet. Send it up. */
  1274. while (1) {
  1275. struct hamachi_desc *desc = &(hmp->rx_ring[entry]);
  1276. u32 desc_status = le32_to_cpu(desc->status_n_length);
  1277. u16 data_size = desc_status; /* Implicit truncate */
  1278. u8 *buf_addr;
  1279. s32 frame_status;
  1280. if (desc_status & DescOwn)
  1281. break;
  1282. pci_dma_sync_single_for_cpu(hmp->pci_dev,
  1283. desc->addr,
  1284. hmp->rx_buf_sz,
  1285. PCI_DMA_FROMDEVICE);
  1286. buf_addr = (u8 *) hmp->rx_skbuff[entry]->data;
  1287. frame_status = le32_to_cpu(get_unaligned((s32*)&(buf_addr[data_size - 12])));
  1288. if (hamachi_debug > 4)
  1289. printk(KERN_DEBUG " hamachi_rx() status was %8.8x.\n",
  1290. frame_status);
  1291. if (--boguscnt < 0)
  1292. break;
  1293. if ( ! (desc_status & DescEndPacket)) {
  1294. printk(KERN_WARNING "%s: Oversized Ethernet frame spanned "
  1295. "multiple buffers, entry %#x length %d status %4.4x!\n",
  1296. dev->name, hmp->cur_rx, data_size, desc_status);
  1297. printk(KERN_WARNING "%s: Oversized Ethernet frame %p vs %p.\n",
  1298. dev->name, desc, &hmp->rx_ring[hmp->cur_rx % RX_RING_SIZE]);
  1299. printk(KERN_WARNING "%s: Oversized Ethernet frame -- next status %x/%x last status %x.\n",
  1300. dev->name,
  1301. hmp->rx_ring[(hmp->cur_rx+1) % RX_RING_SIZE].status_n_length & 0xffff0000,
  1302. hmp->rx_ring[(hmp->cur_rx+1) % RX_RING_SIZE].status_n_length & 0x0000ffff,
  1303. hmp->rx_ring[(hmp->cur_rx-1) % RX_RING_SIZE].status_n_length);
  1304. hmp->stats.rx_length_errors++;
  1305. } /* else Omit for prototype errata??? */
  1306. if (frame_status & 0x00380000) {
  1307. /* There was an error. */
  1308. if (hamachi_debug > 2)
  1309. printk(KERN_DEBUG " hamachi_rx() Rx error was %8.8x.\n",
  1310. frame_status);
  1311. hmp->stats.rx_errors++;
  1312. if (frame_status & 0x00600000) hmp->stats.rx_length_errors++;
  1313. if (frame_status & 0x00080000) hmp->stats.rx_frame_errors++;
  1314. if (frame_status & 0x00100000) hmp->stats.rx_crc_errors++;
  1315. if (frame_status < 0) hmp->stats.rx_dropped++;
  1316. } else {
  1317. struct sk_buff *skb;
  1318. /* Omit CRC */
  1319. u16 pkt_len = (frame_status & 0x07ff) - 4;
  1320. #ifdef RX_CHECKSUM
  1321. u32 pfck = *(u32 *) &buf_addr[data_size - 8];
  1322. #endif
  1323. #ifndef final_version
  1324. if (hamachi_debug > 4)
  1325. printk(KERN_DEBUG " hamachi_rx() normal Rx pkt length %d"
  1326. " of %d, bogus_cnt %d.\n",
  1327. pkt_len, data_size, boguscnt);
  1328. if (hamachi_debug > 5)
  1329. printk(KERN_DEBUG"%s: rx status %8.8x %8.8x %8.8x %8.8x %8.8x.\n",
  1330. dev->name,
  1331. *(s32*)&(buf_addr[data_size - 20]),
  1332. *(s32*)&(buf_addr[data_size - 16]),
  1333. *(s32*)&(buf_addr[data_size - 12]),
  1334. *(s32*)&(buf_addr[data_size - 8]),
  1335. *(s32*)&(buf_addr[data_size - 4]));
  1336. #endif
  1337. /* Check if the packet is long enough to accept without copying
  1338. to a minimally-sized skbuff. */
  1339. if (pkt_len < rx_copybreak
  1340. && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
  1341. #ifdef RX_CHECKSUM
  1342. printk(KERN_ERR "%s: rx_copybreak non-zero "
  1343. "not good with RX_CHECKSUM\n", dev->name);
  1344. #endif
  1345. skb->dev = dev;
  1346. skb_reserve(skb, 2); /* 16 byte align the IP header */
  1347. pci_dma_sync_single_for_cpu(hmp->pci_dev,
  1348. hmp->rx_ring[entry].addr,
  1349. hmp->rx_buf_sz,
  1350. PCI_DMA_FROMDEVICE);
  1351. /* Call copy + cksum if available. */
  1352. #if 1 || USE_IP_COPYSUM
  1353. eth_copy_and_sum(skb,
  1354. hmp->rx_skbuff[entry]->data, pkt_len, 0);
  1355. skb_put(skb, pkt_len);
  1356. #else
  1357. memcpy(skb_put(skb, pkt_len), hmp->rx_ring_dma
  1358. + entry*sizeof(*desc), pkt_len);
  1359. #endif
  1360. pci_dma_sync_single_for_device(hmp->pci_dev,
  1361. hmp->rx_ring[entry].addr,
  1362. hmp->rx_buf_sz,
  1363. PCI_DMA_FROMDEVICE);
  1364. } else {
  1365. pci_unmap_single(hmp->pci_dev,
  1366. hmp->rx_ring[entry].addr,
  1367. hmp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1368. skb_put(skb = hmp->rx_skbuff[entry], pkt_len);
  1369. hmp->rx_skbuff[entry] = NULL;
  1370. }
  1371. skb->protocol = eth_type_trans(skb, dev);
  1372. #ifdef RX_CHECKSUM
  1373. /* TCP or UDP on ipv4, DIX encoding */
  1374. if (pfck>>24 == 0x91 || pfck>>24 == 0x51) {
  1375. struct iphdr *ih = (struct iphdr *) skb->data;
  1376. /* Check that IP packet is at least 46 bytes, otherwise,
  1377. * there may be pad bytes included in the hardware checksum.
  1378. * This wouldn't happen if everyone padded with 0.
  1379. */
  1380. if (ntohs(ih->tot_len) >= 46){
  1381. /* don't worry about frags */
  1382. if (!(ih->frag_off & __constant_htons(IP_MF|IP_OFFSET))) {
  1383. u32 inv = *(u32 *) &buf_addr[data_size - 16];
  1384. u32 *p = (u32 *) &buf_addr[data_size - 20];
  1385. register u32 crc, p_r, p_r1;
  1386. if (inv & 4) {
  1387. inv &= ~4;
  1388. --p;
  1389. }
  1390. p_r = *p;
  1391. p_r1 = *(p-1);
  1392. switch (inv) {
  1393. case 0:
  1394. crc = (p_r & 0xffff) + (p_r >> 16);
  1395. break;
  1396. case 1:
  1397. crc = (p_r >> 16) + (p_r & 0xffff)
  1398. + (p_r1 >> 16 & 0xff00);
  1399. break;
  1400. case 2:
  1401. crc = p_r + (p_r1 >> 16);
  1402. break;
  1403. case 3:
  1404. crc = p_r + (p_r1 & 0xff00) + (p_r1 >> 16);
  1405. break;
  1406. default: /*NOTREACHED*/ crc = 0;
  1407. }
  1408. if (crc & 0xffff0000) {
  1409. crc &= 0xffff;
  1410. ++crc;
  1411. }
  1412. /* tcp/udp will add in pseudo */
  1413. skb->csum = ntohs(pfck & 0xffff);
  1414. if (skb->csum > crc)
  1415. skb->csum -= crc;
  1416. else
  1417. skb->csum += (~crc & 0xffff);
  1418. /*
  1419. * could do the pseudo myself and return
  1420. * CHECKSUM_UNNECESSARY
  1421. */
  1422. skb->ip_summed = CHECKSUM_COMPLETE;
  1423. }
  1424. }
  1425. }
  1426. #endif /* RX_CHECKSUM */
  1427. netif_rx(skb);
  1428. dev->last_rx = jiffies;
  1429. hmp->stats.rx_packets++;
  1430. }
  1431. entry = (++hmp->cur_rx) % RX_RING_SIZE;
  1432. }
  1433. /* Refill the Rx ring buffers. */
  1434. for (; hmp->cur_rx - hmp->dirty_rx > 0; hmp->dirty_rx++) {
  1435. struct hamachi_desc *desc;
  1436. entry = hmp->dirty_rx % RX_RING_SIZE;
  1437. desc = &(hmp->rx_ring[entry]);
  1438. if (hmp->rx_skbuff[entry] == NULL) {
  1439. struct sk_buff *skb = dev_alloc_skb(hmp->rx_buf_sz);
  1440. hmp->rx_skbuff[entry] = skb;
  1441. if (skb == NULL)
  1442. break; /* Better luck next round. */
  1443. skb->dev = dev; /* Mark as being used by this device. */
  1444. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  1445. desc->addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
  1446. skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
  1447. }
  1448. desc->status_n_length = cpu_to_le32(hmp->rx_buf_sz);
  1449. if (entry >= RX_RING_SIZE-1)
  1450. desc->status_n_length |= cpu_to_le32(DescOwn |
  1451. DescEndPacket | DescEndRing | DescIntr);
  1452. else
  1453. desc->status_n_length |= cpu_to_le32(DescOwn |
  1454. DescEndPacket | DescIntr);
  1455. }
  1456. /* Restart Rx engine if stopped. */
  1457. /* If we don't need to check status, don't. -KDU */
  1458. if (readw(hmp->base + RxStatus) & 0x0002)
  1459. writew(0x0001, hmp->base + RxCmd);
  1460. return 0;
  1461. }
  1462. /* This is more properly named "uncommon interrupt events", as it covers more
  1463. than just errors. */
  1464. static void hamachi_error(struct net_device *dev, int intr_status)
  1465. {
  1466. struct hamachi_private *hmp = netdev_priv(dev);
  1467. void __iomem *ioaddr = hmp->base;
  1468. if (intr_status & (LinkChange|NegotiationChange)) {
  1469. if (hamachi_debug > 1)
  1470. printk(KERN_INFO "%s: Link changed: AutoNegotiation Ctrl"
  1471. " %4.4x, Status %4.4x %4.4x Intr status %4.4x.\n",
  1472. dev->name, readw(ioaddr + 0x0E0), readw(ioaddr + 0x0E2),
  1473. readw(ioaddr + ANLinkPartnerAbility),
  1474. readl(ioaddr + IntrStatus));
  1475. if (readw(ioaddr + ANStatus) & 0x20)
  1476. writeb(0x01, ioaddr + LEDCtrl);
  1477. else
  1478. writeb(0x03, ioaddr + LEDCtrl);
  1479. }
  1480. if (intr_status & StatsMax) {
  1481. hamachi_get_stats(dev);
  1482. /* Read the overflow bits to clear. */
  1483. readl(ioaddr + 0x370);
  1484. readl(ioaddr + 0x3F0);
  1485. }
  1486. if ((intr_status & ~(LinkChange|StatsMax|NegotiationChange|IntrRxDone|IntrTxDone))
  1487. && hamachi_debug)
  1488. printk(KERN_ERR "%s: Something Wicked happened! %4.4x.\n",
  1489. dev->name, intr_status);
  1490. /* Hmmmmm, it's not clear how to recover from PCI faults. */
  1491. if (intr_status & (IntrTxPCIErr | IntrTxPCIFault))
  1492. hmp->stats.tx_fifo_errors++;
  1493. if (intr_status & (IntrRxPCIErr | IntrRxPCIFault))
  1494. hmp->stats.rx_fifo_errors++;
  1495. }
  1496. static int hamachi_close(struct net_device *dev)
  1497. {
  1498. struct hamachi_private *hmp = netdev_priv(dev);
  1499. void __iomem *ioaddr = hmp->base;
  1500. struct sk_buff *skb;
  1501. int i;
  1502. netif_stop_queue(dev);
  1503. if (hamachi_debug > 1) {
  1504. printk(KERN_DEBUG "%s: Shutting down ethercard, status was Tx %4.4x Rx %4.4x Int %2.2x.\n",
  1505. dev->name, readw(ioaddr + TxStatus),
  1506. readw(ioaddr + RxStatus), readl(ioaddr + IntrStatus));
  1507. printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d, Rx %d / %d.\n",
  1508. dev->name, hmp->cur_tx, hmp->dirty_tx, hmp->cur_rx, hmp->dirty_rx);
  1509. }
  1510. /* Disable interrupts by clearing the interrupt mask. */
  1511. writel(0x0000, ioaddr + InterruptEnable);
  1512. /* Stop the chip's Tx and Rx processes. */
  1513. writel(2, ioaddr + RxCmd);
  1514. writew(2, ioaddr + TxCmd);
  1515. #ifdef __i386__
  1516. if (hamachi_debug > 2) {
  1517. printk("\n"KERN_DEBUG" Tx ring at %8.8x:\n",
  1518. (int)hmp->tx_ring_dma);
  1519. for (i = 0; i < TX_RING_SIZE; i++)
  1520. printk(" %c #%d desc. %8.8x %8.8x.\n",
  1521. readl(ioaddr + TxCurPtr) == (long)&hmp->tx_ring[i] ? '>' : ' ',
  1522. i, hmp->tx_ring[i].status_n_length, hmp->tx_ring[i].addr);
  1523. printk("\n"KERN_DEBUG " Rx ring %8.8x:\n",
  1524. (int)hmp->rx_ring_dma);
  1525. for (i = 0; i < RX_RING_SIZE; i++) {
  1526. printk(KERN_DEBUG " %c #%d desc. %4.4x %8.8x\n",
  1527. readl(ioaddr + RxCurPtr) == (long)&hmp->rx_ring[i] ? '>' : ' ',
  1528. i, hmp->rx_ring[i].status_n_length, hmp->rx_ring[i].addr);
  1529. if (hamachi_debug > 6) {
  1530. if (*(u8*)hmp->rx_skbuff[i]->data != 0x69) {
  1531. u16 *addr = (u16 *)
  1532. hmp->rx_skbuff[i]->data;
  1533. int j;
  1534. for (j = 0; j < 0x50; j++)
  1535. printk(" %4.4x", addr[j]);
  1536. printk("\n");
  1537. }
  1538. }
  1539. }
  1540. }
  1541. #endif /* __i386__ debugging only */
  1542. free_irq(dev->irq, dev);
  1543. del_timer_sync(&hmp->timer);
  1544. /* Free all the skbuffs in the Rx queue. */
  1545. for (i = 0; i < RX_RING_SIZE; i++) {
  1546. skb = hmp->rx_skbuff[i];
  1547. hmp->rx_ring[i].status_n_length = 0;
  1548. hmp->rx_ring[i].addr = 0xBADF00D0; /* An invalid address. */
  1549. if (skb) {
  1550. pci_unmap_single(hmp->pci_dev,
  1551. hmp->rx_ring[i].addr, hmp->rx_buf_sz,
  1552. PCI_DMA_FROMDEVICE);
  1553. dev_kfree_skb(skb);
  1554. hmp->rx_skbuff[i] = NULL;
  1555. }
  1556. }
  1557. for (i = 0; i < TX_RING_SIZE; i++) {
  1558. skb = hmp->tx_skbuff[i];
  1559. if (skb) {
  1560. pci_unmap_single(hmp->pci_dev,
  1561. hmp->tx_ring[i].addr, skb->len,
  1562. PCI_DMA_TODEVICE);
  1563. dev_kfree_skb(skb);
  1564. hmp->tx_skbuff[i] = NULL;
  1565. }
  1566. }
  1567. writeb(0x00, ioaddr + LEDCtrl);
  1568. return 0;
  1569. }
  1570. static struct net_device_stats *hamachi_get_stats(struct net_device *dev)
  1571. {
  1572. struct hamachi_private *hmp = netdev_priv(dev);
  1573. void __iomem *ioaddr = hmp->base;
  1574. /* We should lock this segment of code for SMP eventually, although
  1575. the vulnerability window is very small and statistics are
  1576. non-critical. */
  1577. /* Ok, what goes here? This appears to be stuck at 21 packets
  1578. according to ifconfig. It does get incremented in hamachi_tx(),
  1579. so I think I'll comment it out here and see if better things
  1580. happen.
  1581. */
  1582. /* hmp->stats.tx_packets = readl(ioaddr + 0x000); */
  1583. hmp->stats.rx_bytes = readl(ioaddr + 0x330); /* Total Uni+Brd+Multi */
  1584. hmp->stats.tx_bytes = readl(ioaddr + 0x3B0); /* Total Uni+Brd+Multi */
  1585. hmp->stats.multicast = readl(ioaddr + 0x320); /* Multicast Rx */
  1586. hmp->stats.rx_length_errors = readl(ioaddr + 0x368); /* Over+Undersized */
  1587. hmp->stats.rx_over_errors = readl(ioaddr + 0x35C); /* Jabber */
  1588. hmp->stats.rx_crc_errors = readl(ioaddr + 0x360); /* Jabber */
  1589. hmp->stats.rx_frame_errors = readl(ioaddr + 0x364); /* Symbol Errs */
  1590. hmp->stats.rx_missed_errors = readl(ioaddr + 0x36C); /* Dropped */
  1591. return &hmp->stats;
  1592. }
  1593. static void set_rx_mode(struct net_device *dev)
  1594. {
  1595. struct hamachi_private *hmp = netdev_priv(dev);
  1596. void __iomem *ioaddr = hmp->base;
  1597. if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
  1598. writew(0x000F, ioaddr + AddrMode);
  1599. } else if ((dev->mc_count > 63) || (dev->flags & IFF_ALLMULTI)) {
  1600. /* Too many to match, or accept all multicasts. */
  1601. writew(0x000B, ioaddr + AddrMode);
  1602. } else if (dev->mc_count > 0) { /* Must use the CAM filter. */
  1603. struct dev_mc_list *mclist;
  1604. int i;
  1605. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1606. i++, mclist = mclist->next) {
  1607. writel(*(u32*)(mclist->dmi_addr), ioaddr + 0x100 + i*8);
  1608. writel(0x20000 | (*(u16*)&mclist->dmi_addr[4]),
  1609. ioaddr + 0x104 + i*8);
  1610. }
  1611. /* Clear remaining entries. */
  1612. for (; i < 64; i++)
  1613. writel(0, ioaddr + 0x104 + i*8);
  1614. writew(0x0003, ioaddr + AddrMode);
  1615. } else { /* Normal, unicast/broadcast-only mode. */
  1616. writew(0x0001, ioaddr + AddrMode);
  1617. }
  1618. }
  1619. static int check_if_running(struct net_device *dev)
  1620. {
  1621. if (!netif_running(dev))
  1622. return -EINVAL;
  1623. return 0;
  1624. }
  1625. static void hamachi_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1626. {
  1627. struct hamachi_private *np = netdev_priv(dev);
  1628. strcpy(info->driver, DRV_NAME);
  1629. strcpy(info->version, DRV_VERSION);
  1630. strcpy(info->bus_info, pci_name(np->pci_dev));
  1631. }
  1632. static int hamachi_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1633. {
  1634. struct hamachi_private *np = netdev_priv(dev);
  1635. spin_lock_irq(&np->lock);
  1636. mii_ethtool_gset(&np->mii_if, ecmd);
  1637. spin_unlock_irq(&np->lock);
  1638. return 0;
  1639. }
  1640. static int hamachi_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1641. {
  1642. struct hamachi_private *np = netdev_priv(dev);
  1643. int res;
  1644. spin_lock_irq(&np->lock);
  1645. res = mii_ethtool_sset(&np->mii_if, ecmd);
  1646. spin_unlock_irq(&np->lock);
  1647. return res;
  1648. }
  1649. static int hamachi_nway_reset(struct net_device *dev)
  1650. {
  1651. struct hamachi_private *np = netdev_priv(dev);
  1652. return mii_nway_restart(&np->mii_if);
  1653. }
  1654. static u32 hamachi_get_link(struct net_device *dev)
  1655. {
  1656. struct hamachi_private *np = netdev_priv(dev);
  1657. return mii_link_ok(&np->mii_if);
  1658. }
  1659. static const struct ethtool_ops ethtool_ops = {
  1660. .begin = check_if_running,
  1661. .get_drvinfo = hamachi_get_drvinfo,
  1662. .get_settings = hamachi_get_settings,
  1663. .set_settings = hamachi_set_settings,
  1664. .nway_reset = hamachi_nway_reset,
  1665. .get_link = hamachi_get_link,
  1666. };
  1667. static const struct ethtool_ops ethtool_ops_no_mii = {
  1668. .begin = check_if_running,
  1669. .get_drvinfo = hamachi_get_drvinfo,
  1670. };
  1671. static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1672. {
  1673. struct hamachi_private *np = netdev_priv(dev);
  1674. struct mii_ioctl_data *data = if_mii(rq);
  1675. int rc;
  1676. if (!netif_running(dev))
  1677. return -EINVAL;
  1678. if (cmd == (SIOCDEVPRIVATE+3)) { /* set rx,tx intr params */
  1679. u32 *d = (u32 *)&rq->ifr_ifru;
  1680. /* Should add this check here or an ordinary user can do nasty
  1681. * things. -KDU
  1682. *
  1683. * TODO: Shut down the Rx and Tx engines while doing this.
  1684. */
  1685. if (!capable(CAP_NET_ADMIN))
  1686. return -EPERM;
  1687. writel(d[0], np->base + TxIntrCtrl);
  1688. writel(d[1], np->base + RxIntrCtrl);
  1689. printk(KERN_NOTICE "%s: tx %08x, rx %08x intr\n", dev->name,
  1690. (u32) readl(np->base + TxIntrCtrl),
  1691. (u32) readl(np->base + RxIntrCtrl));
  1692. rc = 0;
  1693. }
  1694. else {
  1695. spin_lock_irq(&np->lock);
  1696. rc = generic_mii_ioctl(&np->mii_if, data, cmd, NULL);
  1697. spin_unlock_irq(&np->lock);
  1698. }
  1699. return rc;
  1700. }
  1701. static void __devexit hamachi_remove_one (struct pci_dev *pdev)
  1702. {
  1703. struct net_device *dev = pci_get_drvdata(pdev);
  1704. if (dev) {
  1705. struct hamachi_private *hmp = netdev_priv(dev);
  1706. pci_free_consistent(pdev, RX_TOTAL_SIZE, hmp->rx_ring,
  1707. hmp->rx_ring_dma);
  1708. pci_free_consistent(pdev, TX_TOTAL_SIZE, hmp->tx_ring,
  1709. hmp->tx_ring_dma);
  1710. unregister_netdev(dev);
  1711. iounmap(hmp->base);
  1712. free_netdev(dev);
  1713. pci_release_regions(pdev);
  1714. pci_set_drvdata(pdev, NULL);
  1715. }
  1716. }
  1717. static struct pci_device_id hamachi_pci_tbl[] = {
  1718. { 0x1318, 0x0911, PCI_ANY_ID, PCI_ANY_ID, },
  1719. { 0, }
  1720. };
  1721. MODULE_DEVICE_TABLE(pci, hamachi_pci_tbl);
  1722. static struct pci_driver hamachi_driver = {
  1723. .name = DRV_NAME,
  1724. .id_table = hamachi_pci_tbl,
  1725. .probe = hamachi_init_one,
  1726. .remove = __devexit_p(hamachi_remove_one),
  1727. };
  1728. static int __init hamachi_init (void)
  1729. {
  1730. /* when a module, this is printed whether or not devices are found in probe */
  1731. #ifdef MODULE
  1732. printk(version);
  1733. #endif
  1734. return pci_register_driver(&hamachi_driver);
  1735. }
  1736. static void __exit hamachi_exit (void)
  1737. {
  1738. pci_unregister_driver(&hamachi_driver);
  1739. }
  1740. module_init(hamachi_init);
  1741. module_exit(hamachi_exit);