3c59x.c 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379
  1. /* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. */
  2. /*
  3. Written 1996-1999 by Donald Becker.
  4. This software may be used and distributed according to the terms
  5. of the GNU General Public License, incorporated herein by reference.
  6. This driver is for the 3Com "Vortex" and "Boomerang" series ethercards.
  7. Members of the series include Fast EtherLink 3c590/3c592/3c595/3c597
  8. and the EtherLink XL 3c900 and 3c905 cards.
  9. Problem reports and questions should be directed to
  10. vortex@scyld.com
  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. */
  16. /*
  17. * FIXME: This driver _could_ support MTU changing, but doesn't. See Don's hamachi.c implementation
  18. * as well as other drivers
  19. *
  20. * NOTE: If you make 'vortex_debug' a constant (#define vortex_debug 0) the driver shrinks by 2k
  21. * due to dead code elimination. There will be some performance benefits from this due to
  22. * elimination of all the tests and reduced cache footprint.
  23. */
  24. #define DRV_NAME "3c59x"
  25. /* A few values that may be tweaked. */
  26. /* Keep the ring sizes a power of two for efficiency. */
  27. #define TX_RING_SIZE 16
  28. #define RX_RING_SIZE 32
  29. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
  30. /* "Knobs" that adjust features and parameters. */
  31. /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
  32. Setting to > 1512 effectively disables this feature. */
  33. #ifndef __arm__
  34. static int rx_copybreak = 200;
  35. #else
  36. /* ARM systems perform better by disregarding the bus-master
  37. transfer capability of these cards. -- rmk */
  38. static int rx_copybreak = 1513;
  39. #endif
  40. /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
  41. static const int mtu = 1500;
  42. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  43. static int max_interrupt_work = 32;
  44. /* Tx timeout interval (millisecs) */
  45. static int watchdog = 5000;
  46. /* Allow aggregation of Tx interrupts. Saves CPU load at the cost
  47. * of possible Tx stalls if the system is blocking interrupts
  48. * somewhere else. Undefine this to disable.
  49. */
  50. #define tx_interrupt_mitigation 1
  51. /* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */
  52. #define vortex_debug debug
  53. #ifdef VORTEX_DEBUG
  54. static int vortex_debug = VORTEX_DEBUG;
  55. #else
  56. static int vortex_debug = 1;
  57. #endif
  58. #include <linux/module.h>
  59. #include <linux/kernel.h>
  60. #include <linux/string.h>
  61. #include <linux/timer.h>
  62. #include <linux/errno.h>
  63. #include <linux/in.h>
  64. #include <linux/ioport.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/pci.h>
  67. #include <linux/mii.h>
  68. #include <linux/init.h>
  69. #include <linux/netdevice.h>
  70. #include <linux/etherdevice.h>
  71. #include <linux/skbuff.h>
  72. #include <linux/ethtool.h>
  73. #include <linux/highmem.h>
  74. #include <linux/eisa.h>
  75. #include <linux/bitops.h>
  76. #include <linux/jiffies.h>
  77. #include <linux/gfp.h>
  78. #include <asm/irq.h> /* For nr_irqs only. */
  79. #include <asm/io.h>
  80. #include <asm/uaccess.h>
  81. /* Kernel compatibility defines, some common to David Hinds' PCMCIA package.
  82. This is only in the support-all-kernels source code. */
  83. #define RUN_AT(x) (jiffies + (x))
  84. #include <linux/delay.h>
  85. static const char version[] =
  86. DRV_NAME ": Donald Becker and others.\n";
  87. MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
  88. MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver ");
  89. MODULE_LICENSE("GPL");
  90. /* Operational parameter that usually are not changed. */
  91. /* The Vortex size is twice that of the original EtherLinkIII series: the
  92. runtime register window, window 1, is now always mapped in.
  93. The Boomerang size is twice as large as the Vortex -- it has additional
  94. bus master control registers. */
  95. #define VORTEX_TOTAL_SIZE 0x20
  96. #define BOOMERANG_TOTAL_SIZE 0x40
  97. /* Set iff a MII transceiver on any interface requires mdio preamble.
  98. This only set with the original DP83840 on older 3c905 boards, so the extra
  99. code size of a per-interface flag is not worthwhile. */
  100. static char mii_preamble_required;
  101. #define PFX DRV_NAME ": "
  102. /*
  103. Theory of Operation
  104. I. Board Compatibility
  105. This device driver is designed for the 3Com FastEtherLink and FastEtherLink
  106. XL, 3Com's PCI to 10/100baseT adapters. It also works with the 10Mbs
  107. versions of the FastEtherLink cards. The supported product IDs are
  108. 3c590, 3c592, 3c595, 3c597, 3c900, 3c905
  109. The related ISA 3c515 is supported with a separate driver, 3c515.c, included
  110. with the kernel source or available from
  111. cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.html
  112. II. Board-specific settings
  113. PCI bus devices are configured by the system at boot time, so no jumpers
  114. need to be set on the board. The system BIOS should be set to assign the
  115. PCI INTA signal to an otherwise unused system IRQ line.
  116. The EEPROM settings for media type and forced-full-duplex are observed.
  117. The EEPROM media type should be left at the default "autoselect" unless using
  118. 10base2 or AUI connections which cannot be reliably detected.
  119. III. Driver operation
  120. The 3c59x series use an interface that's very similar to the previous 3c5x9
  121. series. The primary interface is two programmed-I/O FIFOs, with an
  122. alternate single-contiguous-region bus-master transfer (see next).
  123. The 3c900 "Boomerang" series uses a full-bus-master interface with separate
  124. lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
  125. DEC Tulip and Intel Speedo3. The first chip version retains a compatible
  126. programmed-I/O interface that has been removed in 'B' and subsequent board
  127. revisions.
  128. One extension that is advertised in a very large font is that the adapters
  129. are capable of being bus masters. On the Vortex chip this capability was
  130. only for a single contiguous region making it far less useful than the full
  131. bus master capability. There is a significant performance impact of taking
  132. an extra interrupt or polling for the completion of each transfer, as well
  133. as difficulty sharing the single transfer engine between the transmit and
  134. receive threads. Using DMA transfers is a win only with large blocks or
  135. with the flawed versions of the Intel Orion motherboard PCI controller.
  136. The Boomerang chip's full-bus-master interface is useful, and has the
  137. currently-unused advantages over other similar chips that queued transmit
  138. packets may be reordered and receive buffer groups are associated with a
  139. single frame.
  140. With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.
  141. Rather than a fixed intermediate receive buffer, this scheme allocates
  142. full-sized skbuffs as receive buffers. The value RX_COPYBREAK is used as
  143. the copying breakpoint: it is chosen to trade-off the memory wasted by
  144. passing the full-sized skbuff to the queue layer for all frames vs. the
  145. copying cost of copying a frame to a correctly-sized skbuff.
  146. IIIC. Synchronization
  147. The driver runs as two independent, single-threaded flows of control. One
  148. is the send-packet routine, which enforces single-threaded use by the
  149. dev->tbusy flag. The other thread is the interrupt handler, which is single
  150. threaded by the hardware and other software.
  151. IV. Notes
  152. Thanks to Cameron Spitzer and Terry Murphy of 3Com for providing development
  153. 3c590, 3c595, and 3c900 boards.
  154. The name "Vortex" is the internal 3Com project name for the PCI ASIC, and
  155. the EISA version is called "Demon". According to Terry these names come
  156. from rides at the local amusement park.
  157. The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes!
  158. This driver only supports ethernet packets because of the skbuff allocation
  159. limit of 4K.
  160. */
  161. /* This table drives the PCI probe routines. It's mostly boilerplate in all
  162. of the drivers, and will likely be provided by some future kernel.
  163. */
  164. enum pci_flags_bit {
  165. PCI_USES_MASTER=4,
  166. };
  167. enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8,
  168. EEPROM_8BIT=0x10, /* AKPM: Uses 0x230 as the base bitmaps for EEPROM reads */
  169. HAS_PWR_CTRL=0x20, HAS_MII=0x40, HAS_NWAY=0x80, HAS_CB_FNS=0x100,
  170. INVERT_MII_PWR=0x200, INVERT_LED_PWR=0x400, MAX_COLLISION_RESET=0x800,
  171. EEPROM_OFFSET=0x1000, HAS_HWCKSM=0x2000, WNO_XCVR_PWR=0x4000,
  172. EXTRA_PREAMBLE=0x8000, EEPROM_RESET=0x10000, };
  173. enum vortex_chips {
  174. CH_3C590 = 0,
  175. CH_3C592,
  176. CH_3C597,
  177. CH_3C595_1,
  178. CH_3C595_2,
  179. CH_3C595_3,
  180. CH_3C900_1,
  181. CH_3C900_2,
  182. CH_3C900_3,
  183. CH_3C900_4,
  184. CH_3C900_5,
  185. CH_3C900B_FL,
  186. CH_3C905_1,
  187. CH_3C905_2,
  188. CH_3C905B_TX,
  189. CH_3C905B_1,
  190. CH_3C905B_2,
  191. CH_3C905B_FX,
  192. CH_3C905C,
  193. CH_3C9202,
  194. CH_3C980,
  195. CH_3C9805,
  196. CH_3CSOHO100_TX,
  197. CH_3C555,
  198. CH_3C556,
  199. CH_3C556B,
  200. CH_3C575,
  201. CH_3C575_1,
  202. CH_3CCFE575,
  203. CH_3CCFE575CT,
  204. CH_3CCFE656,
  205. CH_3CCFEM656,
  206. CH_3CCFEM656_1,
  207. CH_3C450,
  208. CH_3C920,
  209. CH_3C982A,
  210. CH_3C982B,
  211. CH_905BT4,
  212. CH_920B_EMB_WNM,
  213. };
  214. /* note: this array directly indexed by above enums, and MUST
  215. * be kept in sync with both the enums above, and the PCI device
  216. * table below
  217. */
  218. static struct vortex_chip_info {
  219. const char *name;
  220. int flags;
  221. int drv_flags;
  222. int io_size;
  223. } vortex_info_tbl[] = {
  224. {"3c590 Vortex 10Mbps",
  225. PCI_USES_MASTER, IS_VORTEX, 32, },
  226. {"3c592 EISA 10Mbps Demon/Vortex", /* AKPM: from Don's 3c59x_cb.c 0.49H */
  227. PCI_USES_MASTER, IS_VORTEX, 32, },
  228. {"3c597 EISA Fast Demon/Vortex", /* AKPM: from Don's 3c59x_cb.c 0.49H */
  229. PCI_USES_MASTER, IS_VORTEX, 32, },
  230. {"3c595 Vortex 100baseTx",
  231. PCI_USES_MASTER, IS_VORTEX, 32, },
  232. {"3c595 Vortex 100baseT4",
  233. PCI_USES_MASTER, IS_VORTEX, 32, },
  234. {"3c595 Vortex 100base-MII",
  235. PCI_USES_MASTER, IS_VORTEX, 32, },
  236. {"3c900 Boomerang 10baseT",
  237. PCI_USES_MASTER, IS_BOOMERANG|EEPROM_RESET, 64, },
  238. {"3c900 Boomerang 10Mbps Combo",
  239. PCI_USES_MASTER, IS_BOOMERANG|EEPROM_RESET, 64, },
  240. {"3c900 Cyclone 10Mbps TPO", /* AKPM: from Don's 0.99M */
  241. PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  242. {"3c900 Cyclone 10Mbps Combo",
  243. PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  244. {"3c900 Cyclone 10Mbps TPC", /* AKPM: from Don's 0.99M */
  245. PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  246. {"3c900B-FL Cyclone 10base-FL",
  247. PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  248. {"3c905 Boomerang 100baseTx",
  249. PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_RESET, 64, },
  250. {"3c905 Boomerang 100baseT4",
  251. PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_RESET, 64, },
  252. {"3C905B-TX Fast Etherlink XL PCI",
  253. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  254. {"3c905B Cyclone 100baseTx",
  255. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  256. {"3c905B Cyclone 10/100/BNC",
  257. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
  258. {"3c905B-FX Cyclone 100baseFx",
  259. PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  260. {"3c905C Tornado",
  261. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  262. {"3c920B-EMB-WNM (ATI Radeon 9100 IGP)",
  263. PCI_USES_MASTER, IS_TORNADO|HAS_MII|HAS_HWCKSM, 128, },
  264. {"3c980 Cyclone",
  265. PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  266. {"3c980C Python-T",
  267. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
  268. {"3cSOHO100-TX Hurricane",
  269. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  270. {"3c555 Laptop Hurricane",
  271. PCI_USES_MASTER, IS_CYCLONE|EEPROM_8BIT|HAS_HWCKSM, 128, },
  272. {"3c556 Laptop Tornado",
  273. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_8BIT|HAS_CB_FNS|INVERT_MII_PWR|
  274. HAS_HWCKSM, 128, },
  275. {"3c556B Laptop Hurricane",
  276. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_OFFSET|HAS_CB_FNS|INVERT_MII_PWR|
  277. WNO_XCVR_PWR|HAS_HWCKSM, 128, },
  278. {"3c575 [Megahertz] 10/100 LAN CardBus",
  279. PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
  280. {"3c575 Boomerang CardBus",
  281. PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
  282. {"3CCFE575BT Cyclone CardBus",
  283. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|
  284. INVERT_LED_PWR|HAS_HWCKSM, 128, },
  285. {"3CCFE575CT Tornado CardBus",
  286. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  287. MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
  288. {"3CCFE656 Cyclone CardBus",
  289. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  290. INVERT_LED_PWR|HAS_HWCKSM, 128, },
  291. {"3CCFEM656B Cyclone+Winmodem CardBus",
  292. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  293. INVERT_LED_PWR|HAS_HWCKSM, 128, },
  294. {"3CXFEM656C Tornado+Winmodem CardBus", /* From pcmcia-cs-3.1.5 */
  295. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  296. MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
  297. {"3c450 HomePNA Tornado", /* AKPM: from Don's 0.99Q */
  298. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
  299. {"3c920 Tornado",
  300. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
  301. {"3c982 Hydra Dual Port A",
  302. PCI_USES_MASTER, IS_TORNADO|HAS_HWCKSM|HAS_NWAY, 128, },
  303. {"3c982 Hydra Dual Port B",
  304. PCI_USES_MASTER, IS_TORNADO|HAS_HWCKSM|HAS_NWAY, 128, },
  305. {"3c905B-T4",
  306. PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  307. {"3c920B-EMB-WNM Tornado",
  308. PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
  309. {NULL,}, /* NULL terminated list. */
  310. };
  311. static const struct pci_device_id vortex_pci_tbl[] = {
  312. { 0x10B7, 0x5900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C590 },
  313. { 0x10B7, 0x5920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C592 },
  314. { 0x10B7, 0x5970, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C597 },
  315. { 0x10B7, 0x5950, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_1 },
  316. { 0x10B7, 0x5951, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_2 },
  317. { 0x10B7, 0x5952, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_3 },
  318. { 0x10B7, 0x9000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_1 },
  319. { 0x10B7, 0x9001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_2 },
  320. { 0x10B7, 0x9004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_3 },
  321. { 0x10B7, 0x9005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_4 },
  322. { 0x10B7, 0x9006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_5 },
  323. { 0x10B7, 0x900A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900B_FL },
  324. { 0x10B7, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_1 },
  325. { 0x10B7, 0x9051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_2 },
  326. { 0x10B7, 0x9054, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_TX },
  327. { 0x10B7, 0x9055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_1 },
  328. { 0x10B7, 0x9058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_2 },
  329. { 0x10B7, 0x905A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_FX },
  330. { 0x10B7, 0x9200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905C },
  331. { 0x10B7, 0x9202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9202 },
  332. { 0x10B7, 0x9800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C980 },
  333. { 0x10B7, 0x9805, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9805 },
  334. { 0x10B7, 0x7646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CSOHO100_TX },
  335. { 0x10B7, 0x5055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C555 },
  336. { 0x10B7, 0x6055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556 },
  337. { 0x10B7, 0x6056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556B },
  338. { 0x10B7, 0x5b57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575 },
  339. { 0x10B7, 0x5057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575_1 },
  340. { 0x10B7, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575 },
  341. { 0x10B7, 0x5257, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575CT },
  342. { 0x10B7, 0x6560, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE656 },
  343. { 0x10B7, 0x6562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656 },
  344. { 0x10B7, 0x6564, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656_1 },
  345. { 0x10B7, 0x4500, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C450 },
  346. { 0x10B7, 0x9201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C920 },
  347. { 0x10B7, 0x1201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C982A },
  348. { 0x10B7, 0x1202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C982B },
  349. { 0x10B7, 0x9056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_905BT4 },
  350. { 0x10B7, 0x9210, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_920B_EMB_WNM },
  351. {0,} /* 0 terminated list. */
  352. };
  353. MODULE_DEVICE_TABLE(pci, vortex_pci_tbl);
  354. /* Operational definitions.
  355. These are not used by other compilation units and thus are not
  356. exported in a ".h" file.
  357. First the windows. There are eight register windows, with the command
  358. and status registers available in each.
  359. */
  360. #define EL3_CMD 0x0e
  361. #define EL3_STATUS 0x0e
  362. /* The top five bits written to EL3_CMD are a command, the lower
  363. 11 bits are the parameter, if applicable.
  364. Note that 11 parameters bits was fine for ethernet, but the new chip
  365. can handle FDDI length frames (~4500 octets) and now parameters count
  366. 32-bit 'Dwords' rather than octets. */
  367. enum vortex_cmd {
  368. TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
  369. RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
  370. UpStall = 6<<11, UpUnstall = (6<<11)+1,
  371. DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
  372. RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
  373. FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
  374. SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
  375. SetTxThreshold = 18<<11, SetTxStart = 19<<11,
  376. StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
  377. StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11,};
  378. /* The SetRxFilter command accepts the following classes: */
  379. enum RxFilter {
  380. RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
  381. /* Bits in the general status register. */
  382. enum vortex_status {
  383. IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004,
  384. TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
  385. IntReq = 0x0040, StatsFull = 0x0080,
  386. DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
  387. DMAInProgress = 1<<11, /* DMA controller is still busy.*/
  388. CmdInProgress = 1<<12, /* EL3_CMD is still busy.*/
  389. };
  390. /* Register window 1 offsets, the window used in normal operation.
  391. On the Vortex this window is always mapped at offsets 0x10-0x1f. */
  392. enum Window1 {
  393. TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
  394. RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
  395. TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
  396. };
  397. enum Window0 {
  398. Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */
  399. Wn0EepromData = 12, /* Window 0: EEPROM results register. */
  400. IntrStatus=0x0E, /* Valid in all windows. */
  401. };
  402. enum Win0_EEPROM_bits {
  403. EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
  404. EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
  405. EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
  406. };
  407. /* EEPROM locations. */
  408. enum eeprom_offset {
  409. PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
  410. EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
  411. NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
  412. DriverTune=13, Checksum=15};
  413. enum Window2 { /* Window 2. */
  414. Wn2_ResetOptions=12,
  415. };
  416. enum Window3 { /* Window 3: MAC/config bits. */
  417. Wn3_Config=0, Wn3_MaxPktSize=4, Wn3_MAC_Ctrl=6, Wn3_Options=8,
  418. };
  419. #define BFEXT(value, offset, bitcount) \
  420. ((((unsigned long)(value)) >> (offset)) & ((1 << (bitcount)) - 1))
  421. #define BFINS(lhs, rhs, offset, bitcount) \
  422. (((lhs) & ~((((1 << (bitcount)) - 1)) << (offset))) | \
  423. (((rhs) & ((1 << (bitcount)) - 1)) << (offset)))
  424. #define RAM_SIZE(v) BFEXT(v, 0, 3)
  425. #define RAM_WIDTH(v) BFEXT(v, 3, 1)
  426. #define RAM_SPEED(v) BFEXT(v, 4, 2)
  427. #define ROM_SIZE(v) BFEXT(v, 6, 2)
  428. #define RAM_SPLIT(v) BFEXT(v, 16, 2)
  429. #define XCVR(v) BFEXT(v, 20, 4)
  430. #define AUTOSELECT(v) BFEXT(v, 24, 1)
  431. enum Window4 { /* Window 4: Xcvr/media bits. */
  432. Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
  433. };
  434. enum Win4_Media_bits {
  435. Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */
  436. Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */
  437. Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
  438. Media_LnkBeat = 0x0800,
  439. };
  440. enum Window7 { /* Window 7: Bus Master control. */
  441. Wn7_MasterAddr = 0, Wn7_VlanEtherType=4, Wn7_MasterLen = 6,
  442. Wn7_MasterStatus = 12,
  443. };
  444. /* Boomerang bus master control registers. */
  445. enum MasterCtrl {
  446. PktStatus = 0x20, DownListPtr = 0x24, FragAddr = 0x28, FragLen = 0x2c,
  447. TxFreeThreshold = 0x2f, UpPktStatus = 0x30, UpListPtr = 0x38,
  448. };
  449. /* The Rx and Tx descriptor lists.
  450. Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
  451. alignment contraint on tx_ring[] and rx_ring[]. */
  452. #define LAST_FRAG 0x80000000 /* Last Addr/Len pair in descriptor. */
  453. #define DN_COMPLETE 0x00010000 /* This packet has been downloaded */
  454. struct boom_rx_desc {
  455. __le32 next; /* Last entry points to 0. */
  456. __le32 status;
  457. __le32 addr; /* Up to 63 addr/len pairs possible. */
  458. __le32 length; /* Set LAST_FRAG to indicate last pair. */
  459. };
  460. /* Values for the Rx status entry. */
  461. enum rx_desc_status {
  462. RxDComplete=0x00008000, RxDError=0x4000,
  463. /* See boomerang_rx() for actual error bits */
  464. IPChksumErr=1<<25, TCPChksumErr=1<<26, UDPChksumErr=1<<27,
  465. IPChksumValid=1<<29, TCPChksumValid=1<<30, UDPChksumValid=1<<31,
  466. };
  467. #ifdef MAX_SKB_FRAGS
  468. #define DO_ZEROCOPY 1
  469. #else
  470. #define DO_ZEROCOPY 0
  471. #endif
  472. struct boom_tx_desc {
  473. __le32 next; /* Last entry points to 0. */
  474. __le32 status; /* bits 0:12 length, others see below. */
  475. #if DO_ZEROCOPY
  476. struct {
  477. __le32 addr;
  478. __le32 length;
  479. } frag[1+MAX_SKB_FRAGS];
  480. #else
  481. __le32 addr;
  482. __le32 length;
  483. #endif
  484. };
  485. /* Values for the Tx status entry. */
  486. enum tx_desc_status {
  487. CRCDisable=0x2000, TxDComplete=0x8000,
  488. AddIPChksum=0x02000000, AddTCPChksum=0x04000000, AddUDPChksum=0x08000000,
  489. TxIntrUploaded=0x80000000, /* IRQ when in FIFO, but maybe not sent. */
  490. };
  491. /* Chip features we care about in vp->capabilities, read from the EEPROM. */
  492. enum ChipCaps { CapBusMaster=0x20, CapPwrMgmt=0x2000 };
  493. struct vortex_extra_stats {
  494. unsigned long tx_deferred;
  495. unsigned long tx_max_collisions;
  496. unsigned long tx_multiple_collisions;
  497. unsigned long tx_single_collisions;
  498. unsigned long rx_bad_ssd;
  499. };
  500. struct vortex_private {
  501. /* The Rx and Tx rings should be quad-word-aligned. */
  502. struct boom_rx_desc* rx_ring;
  503. struct boom_tx_desc* tx_ring;
  504. dma_addr_t rx_ring_dma;
  505. dma_addr_t tx_ring_dma;
  506. /* The addresses of transmit- and receive-in-place skbuffs. */
  507. struct sk_buff* rx_skbuff[RX_RING_SIZE];
  508. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  509. unsigned int cur_rx, cur_tx; /* The next free ring entry */
  510. unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
  511. struct vortex_extra_stats xstats; /* NIC-specific extra stats */
  512. struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
  513. dma_addr_t tx_skb_dma; /* Allocated DMA address for bus master ctrl DMA. */
  514. /* PCI configuration space information. */
  515. struct device *gendev;
  516. void __iomem *ioaddr; /* IO address space */
  517. void __iomem *cb_fn_base; /* CardBus function status addr space. */
  518. /* Some values here only for performance evaluation and path-coverage */
  519. int rx_nocopy, rx_copy, queued_packet, rx_csumhits;
  520. int card_idx;
  521. /* The remainder are related to chip state, mostly media selection. */
  522. struct timer_list timer; /* Media selection timer. */
  523. struct timer_list rx_oom_timer; /* Rx skb allocation retry timer */
  524. int options; /* User-settable misc. driver options. */
  525. unsigned int media_override:4, /* Passed-in media type. */
  526. default_media:4, /* Read from the EEPROM/Wn3_Config. */
  527. full_duplex:1, autoselect:1,
  528. bus_master:1, /* Vortex can only do a fragment bus-m. */
  529. full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang */
  530. flow_ctrl:1, /* Use 802.3x flow control (PAUSE only) */
  531. partner_flow_ctrl:1, /* Partner supports flow control */
  532. has_nway:1,
  533. enable_wol:1, /* Wake-on-LAN is enabled */
  534. pm_state_valid:1, /* pci_dev->saved_config_space has sane contents */
  535. open:1,
  536. medialock:1,
  537. large_frames:1, /* accept large frames */
  538. handling_irq:1; /* private in_irq indicator */
  539. /* {get|set}_wol operations are already serialized by rtnl.
  540. * no additional locking is required for the enable_wol and acpi_set_WOL()
  541. */
  542. int drv_flags;
  543. u16 status_enable;
  544. u16 intr_enable;
  545. u16 available_media; /* From Wn3_Options. */
  546. u16 capabilities, info1, info2; /* Various, from EEPROM. */
  547. u16 advertising; /* NWay media advertisement */
  548. unsigned char phys[2]; /* MII device addresses. */
  549. u16 deferred; /* Resend these interrupts when we
  550. * bale from the ISR */
  551. u16 io_size; /* Size of PCI region (for release_region) */
  552. /* Serialises access to hardware other than MII and variables below.
  553. * The lock hierarchy is rtnl_lock > {lock, mii_lock} > window_lock. */
  554. spinlock_t lock;
  555. spinlock_t mii_lock; /* Serialises access to MII */
  556. struct mii_if_info mii; /* MII lib hooks/info */
  557. spinlock_t window_lock; /* Serialises access to windowed regs */
  558. int window; /* Register window */
  559. };
  560. static void window_set(struct vortex_private *vp, int window)
  561. {
  562. if (window != vp->window) {
  563. iowrite16(SelectWindow + window, vp->ioaddr + EL3_CMD);
  564. vp->window = window;
  565. }
  566. }
  567. #define DEFINE_WINDOW_IO(size) \
  568. static u ## size \
  569. window_read ## size(struct vortex_private *vp, int window, int addr) \
  570. { \
  571. unsigned long flags; \
  572. u ## size ret; \
  573. spin_lock_irqsave(&vp->window_lock, flags); \
  574. window_set(vp, window); \
  575. ret = ioread ## size(vp->ioaddr + addr); \
  576. spin_unlock_irqrestore(&vp->window_lock, flags); \
  577. return ret; \
  578. } \
  579. static void \
  580. window_write ## size(struct vortex_private *vp, u ## size value, \
  581. int window, int addr) \
  582. { \
  583. unsigned long flags; \
  584. spin_lock_irqsave(&vp->window_lock, flags); \
  585. window_set(vp, window); \
  586. iowrite ## size(value, vp->ioaddr + addr); \
  587. spin_unlock_irqrestore(&vp->window_lock, flags); \
  588. }
  589. DEFINE_WINDOW_IO(8)
  590. DEFINE_WINDOW_IO(16)
  591. DEFINE_WINDOW_IO(32)
  592. #ifdef CONFIG_PCI
  593. #define DEVICE_PCI(dev) ((dev_is_pci(dev)) ? to_pci_dev((dev)) : NULL)
  594. #else
  595. #define DEVICE_PCI(dev) NULL
  596. #endif
  597. #define VORTEX_PCI(vp) \
  598. ((struct pci_dev *) (((vp)->gendev) ? DEVICE_PCI((vp)->gendev) : NULL))
  599. #ifdef CONFIG_EISA
  600. #define DEVICE_EISA(dev) (((dev)->bus == &eisa_bus_type) ? to_eisa_device((dev)) : NULL)
  601. #else
  602. #define DEVICE_EISA(dev) NULL
  603. #endif
  604. #define VORTEX_EISA(vp) \
  605. ((struct eisa_device *) (((vp)->gendev) ? DEVICE_EISA((vp)->gendev) : NULL))
  606. /* The action to take with a media selection timer tick.
  607. Note that we deviate from the 3Com order by checking 10base2 before AUI.
  608. */
  609. enum xcvr_types {
  610. XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
  611. XCVR_100baseFx, XCVR_MII=6, XCVR_NWAY=8, XCVR_ExtMII=9, XCVR_Default=10,
  612. };
  613. static const struct media_table {
  614. char *name;
  615. unsigned int media_bits:16, /* Bits to set in Wn4_Media register. */
  616. mask:8, /* The transceiver-present bit in Wn3_Config.*/
  617. next:8; /* The media type to try next. */
  618. int wait; /* Time before we check media status. */
  619. } media_tbl[] = {
  620. { "10baseT", Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
  621. { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
  622. { "undefined", 0, 0x80, XCVR_10baseT, 10000},
  623. { "10base2", 0, 0x10, XCVR_AUI, (1*HZ)/10},
  624. { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
  625. { "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14*HZ)/10},
  626. { "MII", 0, 0x41, XCVR_10baseT, 3*HZ },
  627. { "undefined", 0, 0x01, XCVR_10baseT, 10000},
  628. { "Autonegotiate", 0, 0x41, XCVR_10baseT, 3*HZ},
  629. { "MII-External", 0, 0x41, XCVR_10baseT, 3*HZ },
  630. { "Default", 0, 0xFF, XCVR_10baseT, 10000},
  631. };
  632. static struct {
  633. const char str[ETH_GSTRING_LEN];
  634. } ethtool_stats_keys[] = {
  635. { "tx_deferred" },
  636. { "tx_max_collisions" },
  637. { "tx_multiple_collisions" },
  638. { "tx_single_collisions" },
  639. { "rx_bad_ssd" },
  640. };
  641. /* number of ETHTOOL_GSTATS u64's */
  642. #define VORTEX_NUM_STATS 5
  643. static int vortex_probe1(struct device *gendev, void __iomem *ioaddr, int irq,
  644. int chip_idx, int card_idx);
  645. static int vortex_up(struct net_device *dev);
  646. static void vortex_down(struct net_device *dev, int final);
  647. static int vortex_open(struct net_device *dev);
  648. static void mdio_sync(struct vortex_private *vp, int bits);
  649. static int mdio_read(struct net_device *dev, int phy_id, int location);
  650. static void mdio_write(struct net_device *vp, int phy_id, int location, int value);
  651. static void vortex_timer(unsigned long arg);
  652. static void rx_oom_timer(unsigned long arg);
  653. static netdev_tx_t vortex_start_xmit(struct sk_buff *skb,
  654. struct net_device *dev);
  655. static netdev_tx_t boomerang_start_xmit(struct sk_buff *skb,
  656. struct net_device *dev);
  657. static int vortex_rx(struct net_device *dev);
  658. static int boomerang_rx(struct net_device *dev);
  659. static irqreturn_t vortex_interrupt(int irq, void *dev_id);
  660. static irqreturn_t boomerang_interrupt(int irq, void *dev_id);
  661. static int vortex_close(struct net_device *dev);
  662. static void dump_tx_ring(struct net_device *dev);
  663. static void update_stats(void __iomem *ioaddr, struct net_device *dev);
  664. static struct net_device_stats *vortex_get_stats(struct net_device *dev);
  665. static void set_rx_mode(struct net_device *dev);
  666. #ifdef CONFIG_PCI
  667. static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  668. #endif
  669. static void vortex_tx_timeout(struct net_device *dev);
  670. static void acpi_set_WOL(struct net_device *dev);
  671. static const struct ethtool_ops vortex_ethtool_ops;
  672. static void set_8021q_mode(struct net_device *dev, int enable);
  673. /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
  674. /* Option count limit only -- unlimited interfaces are supported. */
  675. #define MAX_UNITS 8
  676. static int options[MAX_UNITS] = { [0 ... MAX_UNITS-1] = -1 };
  677. static int full_duplex[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  678. static int hw_checksums[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  679. static int flow_ctrl[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  680. static int enable_wol[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  681. static int use_mmio[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  682. static int global_options = -1;
  683. static int global_full_duplex = -1;
  684. static int global_enable_wol = -1;
  685. static int global_use_mmio = -1;
  686. /* Variables to work-around the Compaq PCI BIOS32 problem. */
  687. static int compaq_ioaddr, compaq_irq, compaq_device_id = 0x5900;
  688. static struct net_device *compaq_net_device;
  689. static int vortex_cards_found;
  690. module_param(debug, int, 0);
  691. module_param(global_options, int, 0);
  692. module_param_array(options, int, NULL, 0);
  693. module_param(global_full_duplex, int, 0);
  694. module_param_array(full_duplex, int, NULL, 0);
  695. module_param_array(hw_checksums, int, NULL, 0);
  696. module_param_array(flow_ctrl, int, NULL, 0);
  697. module_param(global_enable_wol, int, 0);
  698. module_param_array(enable_wol, int, NULL, 0);
  699. module_param(rx_copybreak, int, 0);
  700. module_param(max_interrupt_work, int, 0);
  701. module_param(compaq_ioaddr, int, 0);
  702. module_param(compaq_irq, int, 0);
  703. module_param(compaq_device_id, int, 0);
  704. module_param(watchdog, int, 0);
  705. module_param(global_use_mmio, int, 0);
  706. module_param_array(use_mmio, int, NULL, 0);
  707. MODULE_PARM_DESC(debug, "3c59x debug level (0-6)");
  708. MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex");
  709. MODULE_PARM_DESC(global_options, "3c59x: same as options, but applies to all NICs if options is unset");
  710. MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)");
  711. MODULE_PARM_DESC(global_full_duplex, "3c59x: same as full_duplex, but applies to all NICs if full_duplex is unset");
  712. MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)");
  713. MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)");
  714. MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)");
  715. MODULE_PARM_DESC(global_enable_wol, "3c59x: same as enable_wol, but applies to all NICs if enable_wol is unset");
  716. MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames");
  717. MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt");
  718. MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)");
  719. MODULE_PARM_DESC(compaq_irq, "3c59x PCI IRQ number (Compaq BIOS problem workaround)");
  720. MODULE_PARM_DESC(compaq_device_id, "3c59x PCI device ID (Compaq BIOS problem workaround)");
  721. MODULE_PARM_DESC(watchdog, "3c59x transmit timeout in milliseconds");
  722. MODULE_PARM_DESC(global_use_mmio, "3c59x: same as use_mmio, but applies to all NICs if options is unset");
  723. MODULE_PARM_DESC(use_mmio, "3c59x: use memory-mapped PCI I/O resource (0-1)");
  724. #ifdef CONFIG_NET_POLL_CONTROLLER
  725. static void poll_vortex(struct net_device *dev)
  726. {
  727. struct vortex_private *vp = netdev_priv(dev);
  728. unsigned long flags;
  729. local_irq_save(flags);
  730. (vp->full_bus_master_rx ? boomerang_interrupt:vortex_interrupt)(dev->irq,dev);
  731. local_irq_restore(flags);
  732. }
  733. #endif
  734. #ifdef CONFIG_PM
  735. static int vortex_suspend(struct device *dev)
  736. {
  737. struct pci_dev *pdev = to_pci_dev(dev);
  738. struct net_device *ndev = pci_get_drvdata(pdev);
  739. if (!ndev || !netif_running(ndev))
  740. return 0;
  741. netif_device_detach(ndev);
  742. vortex_down(ndev, 1);
  743. return 0;
  744. }
  745. static int vortex_resume(struct device *dev)
  746. {
  747. struct pci_dev *pdev = to_pci_dev(dev);
  748. struct net_device *ndev = pci_get_drvdata(pdev);
  749. int err;
  750. if (!ndev || !netif_running(ndev))
  751. return 0;
  752. err = vortex_up(ndev);
  753. if (err)
  754. return err;
  755. netif_device_attach(ndev);
  756. return 0;
  757. }
  758. static const struct dev_pm_ops vortex_pm_ops = {
  759. .suspend = vortex_suspend,
  760. .resume = vortex_resume,
  761. .freeze = vortex_suspend,
  762. .thaw = vortex_resume,
  763. .poweroff = vortex_suspend,
  764. .restore = vortex_resume,
  765. };
  766. #define VORTEX_PM_OPS (&vortex_pm_ops)
  767. #else /* !CONFIG_PM */
  768. #define VORTEX_PM_OPS NULL
  769. #endif /* !CONFIG_PM */
  770. #ifdef CONFIG_EISA
  771. static struct eisa_device_id vortex_eisa_ids[] = {
  772. { "TCM5920", CH_3C592 },
  773. { "TCM5970", CH_3C597 },
  774. { "" }
  775. };
  776. MODULE_DEVICE_TABLE(eisa, vortex_eisa_ids);
  777. static int vortex_eisa_probe(struct device *device)
  778. {
  779. void __iomem *ioaddr;
  780. struct eisa_device *edev;
  781. edev = to_eisa_device(device);
  782. if (!request_region(edev->base_addr, VORTEX_TOTAL_SIZE, DRV_NAME))
  783. return -EBUSY;
  784. ioaddr = ioport_map(edev->base_addr, VORTEX_TOTAL_SIZE);
  785. if (vortex_probe1(device, ioaddr, ioread16(ioaddr + 0xC88) >> 12,
  786. edev->id.driver_data, vortex_cards_found)) {
  787. release_region(edev->base_addr, VORTEX_TOTAL_SIZE);
  788. return -ENODEV;
  789. }
  790. vortex_cards_found++;
  791. return 0;
  792. }
  793. static int vortex_eisa_remove(struct device *device)
  794. {
  795. struct eisa_device *edev;
  796. struct net_device *dev;
  797. struct vortex_private *vp;
  798. void __iomem *ioaddr;
  799. edev = to_eisa_device(device);
  800. dev = eisa_get_drvdata(edev);
  801. if (!dev) {
  802. pr_err("vortex_eisa_remove called for Compaq device!\n");
  803. BUG();
  804. }
  805. vp = netdev_priv(dev);
  806. ioaddr = vp->ioaddr;
  807. unregister_netdev(dev);
  808. iowrite16(TotalReset|0x14, ioaddr + EL3_CMD);
  809. release_region(edev->base_addr, VORTEX_TOTAL_SIZE);
  810. free_netdev(dev);
  811. return 0;
  812. }
  813. static struct eisa_driver vortex_eisa_driver = {
  814. .id_table = vortex_eisa_ids,
  815. .driver = {
  816. .name = "3c59x",
  817. .probe = vortex_eisa_probe,
  818. .remove = vortex_eisa_remove
  819. }
  820. };
  821. #endif /* CONFIG_EISA */
  822. /* returns count found (>= 0), or negative on error */
  823. static int __init vortex_eisa_init(void)
  824. {
  825. int eisa_found = 0;
  826. int orig_cards_found = vortex_cards_found;
  827. #ifdef CONFIG_EISA
  828. int err;
  829. err = eisa_driver_register (&vortex_eisa_driver);
  830. if (!err) {
  831. /*
  832. * Because of the way EISA bus is probed, we cannot assume
  833. * any device have been found when we exit from
  834. * eisa_driver_register (the bus root driver may not be
  835. * initialized yet). So we blindly assume something was
  836. * found, and let the sysfs magic happened...
  837. */
  838. eisa_found = 1;
  839. }
  840. #endif
  841. /* Special code to work-around the Compaq PCI BIOS32 problem. */
  842. if (compaq_ioaddr) {
  843. vortex_probe1(NULL, ioport_map(compaq_ioaddr, VORTEX_TOTAL_SIZE),
  844. compaq_irq, compaq_device_id, vortex_cards_found++);
  845. }
  846. return vortex_cards_found - orig_cards_found + eisa_found;
  847. }
  848. /* returns count (>= 0), or negative on error */
  849. static int vortex_init_one(struct pci_dev *pdev,
  850. const struct pci_device_id *ent)
  851. {
  852. int rc, unit, pci_bar;
  853. struct vortex_chip_info *vci;
  854. void __iomem *ioaddr;
  855. /* wake up and enable device */
  856. rc = pci_enable_device(pdev);
  857. if (rc < 0)
  858. goto out;
  859. rc = pci_request_regions(pdev, DRV_NAME);
  860. if (rc < 0)
  861. goto out_disable;
  862. unit = vortex_cards_found;
  863. if (global_use_mmio < 0 && (unit >= MAX_UNITS || use_mmio[unit] < 0)) {
  864. /* Determine the default if the user didn't override us */
  865. vci = &vortex_info_tbl[ent->driver_data];
  866. pci_bar = vci->drv_flags & (IS_CYCLONE | IS_TORNADO) ? 1 : 0;
  867. } else if (unit < MAX_UNITS && use_mmio[unit] >= 0)
  868. pci_bar = use_mmio[unit] ? 1 : 0;
  869. else
  870. pci_bar = global_use_mmio ? 1 : 0;
  871. ioaddr = pci_iomap(pdev, pci_bar, 0);
  872. if (!ioaddr) /* If mapping fails, fall-back to BAR 0... */
  873. ioaddr = pci_iomap(pdev, 0, 0);
  874. if (!ioaddr) {
  875. rc = -ENOMEM;
  876. goto out_release;
  877. }
  878. rc = vortex_probe1(&pdev->dev, ioaddr, pdev->irq,
  879. ent->driver_data, unit);
  880. if (rc < 0)
  881. goto out_iounmap;
  882. vortex_cards_found++;
  883. goto out;
  884. out_iounmap:
  885. pci_iounmap(pdev, ioaddr);
  886. out_release:
  887. pci_release_regions(pdev);
  888. out_disable:
  889. pci_disable_device(pdev);
  890. out:
  891. return rc;
  892. }
  893. static const struct net_device_ops boomrang_netdev_ops = {
  894. .ndo_open = vortex_open,
  895. .ndo_stop = vortex_close,
  896. .ndo_start_xmit = boomerang_start_xmit,
  897. .ndo_tx_timeout = vortex_tx_timeout,
  898. .ndo_get_stats = vortex_get_stats,
  899. #ifdef CONFIG_PCI
  900. .ndo_do_ioctl = vortex_ioctl,
  901. #endif
  902. .ndo_set_rx_mode = set_rx_mode,
  903. .ndo_change_mtu = eth_change_mtu,
  904. .ndo_set_mac_address = eth_mac_addr,
  905. .ndo_validate_addr = eth_validate_addr,
  906. #ifdef CONFIG_NET_POLL_CONTROLLER
  907. .ndo_poll_controller = poll_vortex,
  908. #endif
  909. };
  910. static const struct net_device_ops vortex_netdev_ops = {
  911. .ndo_open = vortex_open,
  912. .ndo_stop = vortex_close,
  913. .ndo_start_xmit = vortex_start_xmit,
  914. .ndo_tx_timeout = vortex_tx_timeout,
  915. .ndo_get_stats = vortex_get_stats,
  916. #ifdef CONFIG_PCI
  917. .ndo_do_ioctl = vortex_ioctl,
  918. #endif
  919. .ndo_set_rx_mode = set_rx_mode,
  920. .ndo_change_mtu = eth_change_mtu,
  921. .ndo_set_mac_address = eth_mac_addr,
  922. .ndo_validate_addr = eth_validate_addr,
  923. #ifdef CONFIG_NET_POLL_CONTROLLER
  924. .ndo_poll_controller = poll_vortex,
  925. #endif
  926. };
  927. /*
  928. * Start up the PCI/EISA device which is described by *gendev.
  929. * Return 0 on success.
  930. *
  931. * NOTE: pdev can be NULL, for the case of a Compaq device
  932. */
  933. static int vortex_probe1(struct device *gendev, void __iomem *ioaddr, int irq,
  934. int chip_idx, int card_idx)
  935. {
  936. struct vortex_private *vp;
  937. int option;
  938. unsigned int eeprom[0x40], checksum = 0; /* EEPROM contents */
  939. int i, step;
  940. struct net_device *dev;
  941. static int printed_version;
  942. int retval, print_info;
  943. struct vortex_chip_info * const vci = &vortex_info_tbl[chip_idx];
  944. const char *print_name = "3c59x";
  945. struct pci_dev *pdev = NULL;
  946. struct eisa_device *edev = NULL;
  947. if (!printed_version) {
  948. pr_info("%s", version);
  949. printed_version = 1;
  950. }
  951. if (gendev) {
  952. if ((pdev = DEVICE_PCI(gendev))) {
  953. print_name = pci_name(pdev);
  954. }
  955. if ((edev = DEVICE_EISA(gendev))) {
  956. print_name = dev_name(&edev->dev);
  957. }
  958. }
  959. dev = alloc_etherdev(sizeof(*vp));
  960. retval = -ENOMEM;
  961. if (!dev)
  962. goto out;
  963. SET_NETDEV_DEV(dev, gendev);
  964. vp = netdev_priv(dev);
  965. option = global_options;
  966. /* The lower four bits are the media type. */
  967. if (dev->mem_start) {
  968. /*
  969. * The 'options' param is passed in as the third arg to the
  970. * LILO 'ether=' argument for non-modular use
  971. */
  972. option = dev->mem_start;
  973. }
  974. else if (card_idx < MAX_UNITS) {
  975. if (options[card_idx] >= 0)
  976. option = options[card_idx];
  977. }
  978. if (option > 0) {
  979. if (option & 0x8000)
  980. vortex_debug = 7;
  981. if (option & 0x4000)
  982. vortex_debug = 2;
  983. if (option & 0x0400)
  984. vp->enable_wol = 1;
  985. }
  986. print_info = (vortex_debug > 1);
  987. if (print_info)
  988. pr_info("See Documentation/networking/vortex.txt\n");
  989. pr_info("%s: 3Com %s %s at %p.\n",
  990. print_name,
  991. pdev ? "PCI" : "EISA",
  992. vci->name,
  993. ioaddr);
  994. dev->base_addr = (unsigned long)ioaddr;
  995. dev->irq = irq;
  996. dev->mtu = mtu;
  997. vp->ioaddr = ioaddr;
  998. vp->large_frames = mtu > 1500;
  999. vp->drv_flags = vci->drv_flags;
  1000. vp->has_nway = (vci->drv_flags & HAS_NWAY) ? 1 : 0;
  1001. vp->io_size = vci->io_size;
  1002. vp->card_idx = card_idx;
  1003. vp->window = -1;
  1004. /* module list only for Compaq device */
  1005. if (gendev == NULL) {
  1006. compaq_net_device = dev;
  1007. }
  1008. /* PCI-only startup logic */
  1009. if (pdev) {
  1010. /* enable bus-mastering if necessary */
  1011. if (vci->flags & PCI_USES_MASTER)
  1012. pci_set_master(pdev);
  1013. if (vci->drv_flags & IS_VORTEX) {
  1014. u8 pci_latency;
  1015. u8 new_latency = 248;
  1016. /* Check the PCI latency value. On the 3c590 series the latency timer
  1017. must be set to the maximum value to avoid data corruption that occurs
  1018. when the timer expires during a transfer. This bug exists the Vortex
  1019. chip only. */
  1020. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
  1021. if (pci_latency < new_latency) {
  1022. pr_info("%s: Overriding PCI latency timer (CFLT) setting of %d, new value is %d.\n",
  1023. print_name, pci_latency, new_latency);
  1024. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, new_latency);
  1025. }
  1026. }
  1027. }
  1028. spin_lock_init(&vp->lock);
  1029. spin_lock_init(&vp->mii_lock);
  1030. spin_lock_init(&vp->window_lock);
  1031. vp->gendev = gendev;
  1032. vp->mii.dev = dev;
  1033. vp->mii.mdio_read = mdio_read;
  1034. vp->mii.mdio_write = mdio_write;
  1035. vp->mii.phy_id_mask = 0x1f;
  1036. vp->mii.reg_num_mask = 0x1f;
  1037. /* Makes sure rings are at least 16 byte aligned. */
  1038. vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
  1039. + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
  1040. &vp->rx_ring_dma);
  1041. retval = -ENOMEM;
  1042. if (!vp->rx_ring)
  1043. goto free_device;
  1044. vp->tx_ring = (struct boom_tx_desc *)(vp->rx_ring + RX_RING_SIZE);
  1045. vp->tx_ring_dma = vp->rx_ring_dma + sizeof(struct boom_rx_desc) * RX_RING_SIZE;
  1046. /* if we are a PCI driver, we store info in pdev->driver_data
  1047. * instead of a module list */
  1048. if (pdev)
  1049. pci_set_drvdata(pdev, dev);
  1050. if (edev)
  1051. eisa_set_drvdata(edev, dev);
  1052. vp->media_override = 7;
  1053. if (option >= 0) {
  1054. vp->media_override = ((option & 7) == 2) ? 0 : option & 15;
  1055. if (vp->media_override != 7)
  1056. vp->medialock = 1;
  1057. vp->full_duplex = (option & 0x200) ? 1 : 0;
  1058. vp->bus_master = (option & 16) ? 1 : 0;
  1059. }
  1060. if (global_full_duplex > 0)
  1061. vp->full_duplex = 1;
  1062. if (global_enable_wol > 0)
  1063. vp->enable_wol = 1;
  1064. if (card_idx < MAX_UNITS) {
  1065. if (full_duplex[card_idx] > 0)
  1066. vp->full_duplex = 1;
  1067. if (flow_ctrl[card_idx] > 0)
  1068. vp->flow_ctrl = 1;
  1069. if (enable_wol[card_idx] > 0)
  1070. vp->enable_wol = 1;
  1071. }
  1072. vp->mii.force_media = vp->full_duplex;
  1073. vp->options = option;
  1074. /* Read the station address from the EEPROM. */
  1075. {
  1076. int base;
  1077. if (vci->drv_flags & EEPROM_8BIT)
  1078. base = 0x230;
  1079. else if (vci->drv_flags & EEPROM_OFFSET)
  1080. base = EEPROM_Read + 0x30;
  1081. else
  1082. base = EEPROM_Read;
  1083. for (i = 0; i < 0x40; i++) {
  1084. int timer;
  1085. window_write16(vp, base + i, 0, Wn0EepromCmd);
  1086. /* Pause for at least 162 us. for the read to take place. */
  1087. for (timer = 10; timer >= 0; timer--) {
  1088. udelay(162);
  1089. if ((window_read16(vp, 0, Wn0EepromCmd) &
  1090. 0x8000) == 0)
  1091. break;
  1092. }
  1093. eeprom[i] = window_read16(vp, 0, Wn0EepromData);
  1094. }
  1095. }
  1096. for (i = 0; i < 0x18; i++)
  1097. checksum ^= eeprom[i];
  1098. checksum = (checksum ^ (checksum >> 8)) & 0xff;
  1099. if (checksum != 0x00) { /* Grrr, needless incompatible change 3Com. */
  1100. while (i < 0x21)
  1101. checksum ^= eeprom[i++];
  1102. checksum = (checksum ^ (checksum >> 8)) & 0xff;
  1103. }
  1104. if ((checksum != 0x00) && !(vci->drv_flags & IS_TORNADO))
  1105. pr_cont(" ***INVALID CHECKSUM %4.4x*** ", checksum);
  1106. for (i = 0; i < 3; i++)
  1107. ((__be16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
  1108. if (print_info)
  1109. pr_cont(" %pM", dev->dev_addr);
  1110. /* Unfortunately an all zero eeprom passes the checksum and this
  1111. gets found in the wild in failure cases. Crypto is hard 8) */
  1112. if (!is_valid_ether_addr(dev->dev_addr)) {
  1113. retval = -EINVAL;
  1114. pr_err("*** EEPROM MAC address is invalid.\n");
  1115. goto free_ring; /* With every pack */
  1116. }
  1117. for (i = 0; i < 6; i++)
  1118. window_write8(vp, dev->dev_addr[i], 2, i);
  1119. if (print_info)
  1120. pr_cont(", IRQ %d\n", dev->irq);
  1121. /* Tell them about an invalid IRQ. */
  1122. if (dev->irq <= 0 || dev->irq >= nr_irqs)
  1123. pr_warn(" *** Warning: IRQ %d is unlikely to work! ***\n",
  1124. dev->irq);
  1125. step = (window_read8(vp, 4, Wn4_NetDiag) & 0x1e) >> 1;
  1126. if (print_info) {
  1127. pr_info(" product code %02x%02x rev %02x.%d date %02d-%02d-%02d\n",
  1128. eeprom[6]&0xff, eeprom[6]>>8, eeprom[0x14],
  1129. step, (eeprom[4]>>5) & 15, eeprom[4] & 31, eeprom[4]>>9);
  1130. }
  1131. if (pdev && vci->drv_flags & HAS_CB_FNS) {
  1132. unsigned short n;
  1133. vp->cb_fn_base = pci_iomap(pdev, 2, 0);
  1134. if (!vp->cb_fn_base) {
  1135. retval = -ENOMEM;
  1136. goto free_ring;
  1137. }
  1138. if (print_info) {
  1139. pr_info("%s: CardBus functions mapped %16.16llx->%p\n",
  1140. print_name,
  1141. (unsigned long long)pci_resource_start(pdev, 2),
  1142. vp->cb_fn_base);
  1143. }
  1144. n = window_read16(vp, 2, Wn2_ResetOptions) & ~0x4010;
  1145. if (vp->drv_flags & INVERT_LED_PWR)
  1146. n |= 0x10;
  1147. if (vp->drv_flags & INVERT_MII_PWR)
  1148. n |= 0x4000;
  1149. window_write16(vp, n, 2, Wn2_ResetOptions);
  1150. if (vp->drv_flags & WNO_XCVR_PWR) {
  1151. window_write16(vp, 0x0800, 0, 0);
  1152. }
  1153. }
  1154. /* Extract our information from the EEPROM data. */
  1155. vp->info1 = eeprom[13];
  1156. vp->info2 = eeprom[15];
  1157. vp->capabilities = eeprom[16];
  1158. if (vp->info1 & 0x8000) {
  1159. vp->full_duplex = 1;
  1160. if (print_info)
  1161. pr_info("Full duplex capable\n");
  1162. }
  1163. {
  1164. static const char * const ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
  1165. unsigned int config;
  1166. vp->available_media = window_read16(vp, 3, Wn3_Options);
  1167. if ((vp->available_media & 0xff) == 0) /* Broken 3c916 */
  1168. vp->available_media = 0x40;
  1169. config = window_read32(vp, 3, Wn3_Config);
  1170. if (print_info) {
  1171. pr_debug(" Internal config register is %4.4x, transceivers %#x.\n",
  1172. config, window_read16(vp, 3, Wn3_Options));
  1173. pr_info(" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
  1174. 8 << RAM_SIZE(config),
  1175. RAM_WIDTH(config) ? "word" : "byte",
  1176. ram_split[RAM_SPLIT(config)],
  1177. AUTOSELECT(config) ? "autoselect/" : "",
  1178. XCVR(config) > XCVR_ExtMII ? "<invalid transceiver>" :
  1179. media_tbl[XCVR(config)].name);
  1180. }
  1181. vp->default_media = XCVR(config);
  1182. if (vp->default_media == XCVR_NWAY)
  1183. vp->has_nway = 1;
  1184. vp->autoselect = AUTOSELECT(config);
  1185. }
  1186. if (vp->media_override != 7) {
  1187. pr_info("%s: Media override to transceiver type %d (%s).\n",
  1188. print_name, vp->media_override,
  1189. media_tbl[vp->media_override].name);
  1190. dev->if_port = vp->media_override;
  1191. } else
  1192. dev->if_port = vp->default_media;
  1193. if ((vp->available_media & 0x40) || (vci->drv_flags & HAS_NWAY) ||
  1194. dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
  1195. int phy, phy_idx = 0;
  1196. mii_preamble_required++;
  1197. if (vp->drv_flags & EXTRA_PREAMBLE)
  1198. mii_preamble_required++;
  1199. mdio_sync(vp, 32);
  1200. mdio_read(dev, 24, MII_BMSR);
  1201. for (phy = 0; phy < 32 && phy_idx < 1; phy++) {
  1202. int mii_status, phyx;
  1203. /*
  1204. * For the 3c905CX we look at index 24 first, because it bogusly
  1205. * reports an external PHY at all indices
  1206. */
  1207. if (phy == 0)
  1208. phyx = 24;
  1209. else if (phy <= 24)
  1210. phyx = phy - 1;
  1211. else
  1212. phyx = phy;
  1213. mii_status = mdio_read(dev, phyx, MII_BMSR);
  1214. if (mii_status && mii_status != 0xffff) {
  1215. vp->phys[phy_idx++] = phyx;
  1216. if (print_info) {
  1217. pr_info(" MII transceiver found at address %d, status %4x.\n",
  1218. phyx, mii_status);
  1219. }
  1220. if ((mii_status & 0x0040) == 0)
  1221. mii_preamble_required++;
  1222. }
  1223. }
  1224. mii_preamble_required--;
  1225. if (phy_idx == 0) {
  1226. pr_warn(" ***WARNING*** No MII transceivers found!\n");
  1227. vp->phys[0] = 24;
  1228. } else {
  1229. vp->advertising = mdio_read(dev, vp->phys[0], MII_ADVERTISE);
  1230. if (vp->full_duplex) {
  1231. /* Only advertise the FD media types. */
  1232. vp->advertising &= ~0x02A0;
  1233. mdio_write(dev, vp->phys[0], 4, vp->advertising);
  1234. }
  1235. }
  1236. vp->mii.phy_id = vp->phys[0];
  1237. }
  1238. if (vp->capabilities & CapBusMaster) {
  1239. vp->full_bus_master_tx = 1;
  1240. if (print_info) {
  1241. pr_info(" Enabling bus-master transmits and %s receives.\n",
  1242. (vp->info2 & 1) ? "early" : "whole-frame" );
  1243. }
  1244. vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;
  1245. vp->bus_master = 0; /* AKPM: vortex only */
  1246. }
  1247. /* The 3c59x-specific entries in the device structure. */
  1248. if (vp->full_bus_master_tx) {
  1249. dev->netdev_ops = &boomrang_netdev_ops;
  1250. /* Actually, it still should work with iommu. */
  1251. if (card_idx < MAX_UNITS &&
  1252. ((hw_checksums[card_idx] == -1 && (vp->drv_flags & HAS_HWCKSM)) ||
  1253. hw_checksums[card_idx] == 1)) {
  1254. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  1255. }
  1256. } else
  1257. dev->netdev_ops = &vortex_netdev_ops;
  1258. if (print_info) {
  1259. pr_info("%s: scatter/gather %sabled. h/w checksums %sabled\n",
  1260. print_name,
  1261. (dev->features & NETIF_F_SG) ? "en":"dis",
  1262. (dev->features & NETIF_F_IP_CSUM) ? "en":"dis");
  1263. }
  1264. dev->ethtool_ops = &vortex_ethtool_ops;
  1265. dev->watchdog_timeo = (watchdog * HZ) / 1000;
  1266. if (pdev) {
  1267. vp->pm_state_valid = 1;
  1268. pci_save_state(pdev);
  1269. acpi_set_WOL(dev);
  1270. }
  1271. retval = register_netdev(dev);
  1272. if (retval == 0)
  1273. return 0;
  1274. free_ring:
  1275. pci_free_consistent(pdev,
  1276. sizeof(struct boom_rx_desc) * RX_RING_SIZE
  1277. + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
  1278. vp->rx_ring,
  1279. vp->rx_ring_dma);
  1280. free_device:
  1281. free_netdev(dev);
  1282. pr_err(PFX "vortex_probe1 fails. Returns %d\n", retval);
  1283. out:
  1284. return retval;
  1285. }
  1286. static void
  1287. issue_and_wait(struct net_device *dev, int cmd)
  1288. {
  1289. struct vortex_private *vp = netdev_priv(dev);
  1290. void __iomem *ioaddr = vp->ioaddr;
  1291. int i;
  1292. iowrite16(cmd, ioaddr + EL3_CMD);
  1293. for (i = 0; i < 2000; i++) {
  1294. if (!(ioread16(ioaddr + EL3_STATUS) & CmdInProgress))
  1295. return;
  1296. }
  1297. /* OK, that didn't work. Do it the slow way. One second */
  1298. for (i = 0; i < 100000; i++) {
  1299. if (!(ioread16(ioaddr + EL3_STATUS) & CmdInProgress)) {
  1300. if (vortex_debug > 1)
  1301. pr_info("%s: command 0x%04x took %d usecs\n",
  1302. dev->name, cmd, i * 10);
  1303. return;
  1304. }
  1305. udelay(10);
  1306. }
  1307. pr_err("%s: command 0x%04x did not complete! Status=0x%x\n",
  1308. dev->name, cmd, ioread16(ioaddr + EL3_STATUS));
  1309. }
  1310. static void
  1311. vortex_set_duplex(struct net_device *dev)
  1312. {
  1313. struct vortex_private *vp = netdev_priv(dev);
  1314. pr_info("%s: setting %s-duplex.\n",
  1315. dev->name, (vp->full_duplex) ? "full" : "half");
  1316. /* Set the full-duplex bit. */
  1317. window_write16(vp,
  1318. ((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
  1319. (vp->large_frames ? 0x40 : 0) |
  1320. ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ?
  1321. 0x100 : 0),
  1322. 3, Wn3_MAC_Ctrl);
  1323. }
  1324. static void vortex_check_media(struct net_device *dev, unsigned int init)
  1325. {
  1326. struct vortex_private *vp = netdev_priv(dev);
  1327. unsigned int ok_to_print = 0;
  1328. if (vortex_debug > 3)
  1329. ok_to_print = 1;
  1330. if (mii_check_media(&vp->mii, ok_to_print, init)) {
  1331. vp->full_duplex = vp->mii.full_duplex;
  1332. vortex_set_duplex(dev);
  1333. } else if (init) {
  1334. vortex_set_duplex(dev);
  1335. }
  1336. }
  1337. static int
  1338. vortex_up(struct net_device *dev)
  1339. {
  1340. struct vortex_private *vp = netdev_priv(dev);
  1341. void __iomem *ioaddr = vp->ioaddr;
  1342. unsigned int config;
  1343. int i, mii_reg1, mii_reg5, err = 0;
  1344. if (VORTEX_PCI(vp)) {
  1345. pci_set_power_state(VORTEX_PCI(vp), PCI_D0); /* Go active */
  1346. if (vp->pm_state_valid)
  1347. pci_restore_state(VORTEX_PCI(vp));
  1348. err = pci_enable_device(VORTEX_PCI(vp));
  1349. if (err) {
  1350. pr_warn("%s: Could not enable device\n", dev->name);
  1351. goto err_out;
  1352. }
  1353. }
  1354. /* Before initializing select the active media port. */
  1355. config = window_read32(vp, 3, Wn3_Config);
  1356. if (vp->media_override != 7) {
  1357. pr_info("%s: Media override to transceiver %d (%s).\n",
  1358. dev->name, vp->media_override,
  1359. media_tbl[vp->media_override].name);
  1360. dev->if_port = vp->media_override;
  1361. } else if (vp->autoselect) {
  1362. if (vp->has_nway) {
  1363. if (vortex_debug > 1)
  1364. pr_info("%s: using NWAY device table, not %d\n",
  1365. dev->name, dev->if_port);
  1366. dev->if_port = XCVR_NWAY;
  1367. } else {
  1368. /* Find first available media type, starting with 100baseTx. */
  1369. dev->if_port = XCVR_100baseTx;
  1370. while (! (vp->available_media & media_tbl[dev->if_port].mask))
  1371. dev->if_port = media_tbl[dev->if_port].next;
  1372. if (vortex_debug > 1)
  1373. pr_info("%s: first available media type: %s\n",
  1374. dev->name, media_tbl[dev->if_port].name);
  1375. }
  1376. } else {
  1377. dev->if_port = vp->default_media;
  1378. if (vortex_debug > 1)
  1379. pr_info("%s: using default media %s\n",
  1380. dev->name, media_tbl[dev->if_port].name);
  1381. }
  1382. setup_timer(&vp->timer, vortex_timer, (unsigned long)dev);
  1383. mod_timer(&vp->timer, RUN_AT(media_tbl[dev->if_port].wait));
  1384. setup_timer(&vp->rx_oom_timer, rx_oom_timer, (unsigned long)dev);
  1385. if (vortex_debug > 1)
  1386. pr_debug("%s: Initial media type %s.\n",
  1387. dev->name, media_tbl[dev->if_port].name);
  1388. vp->full_duplex = vp->mii.force_media;
  1389. config = BFINS(config, dev->if_port, 20, 4);
  1390. if (vortex_debug > 6)
  1391. pr_debug("vortex_up(): writing 0x%x to InternalConfig\n", config);
  1392. window_write32(vp, config, 3, Wn3_Config);
  1393. if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
  1394. mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
  1395. mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
  1396. vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
  1397. vp->mii.full_duplex = vp->full_duplex;
  1398. vortex_check_media(dev, 1);
  1399. }
  1400. else
  1401. vortex_set_duplex(dev);
  1402. issue_and_wait(dev, TxReset);
  1403. /*
  1404. * Don't reset the PHY - that upsets autonegotiation during DHCP operations.
  1405. */
  1406. issue_and_wait(dev, RxReset|0x04);
  1407. iowrite16(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
  1408. if (vortex_debug > 1) {
  1409. pr_debug("%s: vortex_up() irq %d media status %4.4x.\n",
  1410. dev->name, dev->irq, window_read16(vp, 4, Wn4_Media));
  1411. }
  1412. /* Set the station address and mask in window 2 each time opened. */
  1413. for (i = 0; i < 6; i++)
  1414. window_write8(vp, dev->dev_addr[i], 2, i);
  1415. for (; i < 12; i+=2)
  1416. window_write16(vp, 0, 2, i);
  1417. if (vp->cb_fn_base) {
  1418. unsigned short n = window_read16(vp, 2, Wn2_ResetOptions) & ~0x4010;
  1419. if (vp->drv_flags & INVERT_LED_PWR)
  1420. n |= 0x10;
  1421. if (vp->drv_flags & INVERT_MII_PWR)
  1422. n |= 0x4000;
  1423. window_write16(vp, n, 2, Wn2_ResetOptions);
  1424. }
  1425. if (dev->if_port == XCVR_10base2)
  1426. /* Start the thinnet transceiver. We should really wait 50ms...*/
  1427. iowrite16(StartCoax, ioaddr + EL3_CMD);
  1428. if (dev->if_port != XCVR_NWAY) {
  1429. window_write16(vp,
  1430. (window_read16(vp, 4, Wn4_Media) &
  1431. ~(Media_10TP|Media_SQE)) |
  1432. media_tbl[dev->if_port].media_bits,
  1433. 4, Wn4_Media);
  1434. }
  1435. /* Switch to the stats window, and clear all stats by reading. */
  1436. iowrite16(StatsDisable, ioaddr + EL3_CMD);
  1437. for (i = 0; i < 10; i++)
  1438. window_read8(vp, 6, i);
  1439. window_read16(vp, 6, 10);
  1440. window_read16(vp, 6, 12);
  1441. /* New: On the Vortex we must also clear the BadSSD counter. */
  1442. window_read8(vp, 4, 12);
  1443. /* ..and on the Boomerang we enable the extra statistics bits. */
  1444. window_write16(vp, 0x0040, 4, Wn4_NetDiag);
  1445. if (vp->full_bus_master_rx) { /* Boomerang bus master. */
  1446. vp->cur_rx = vp->dirty_rx = 0;
  1447. /* Initialize the RxEarly register as recommended. */
  1448. iowrite16(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
  1449. iowrite32(0x0020, ioaddr + PktStatus);
  1450. iowrite32(vp->rx_ring_dma, ioaddr + UpListPtr);
  1451. }
  1452. if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
  1453. vp->cur_tx = vp->dirty_tx = 0;
  1454. if (vp->drv_flags & IS_BOOMERANG)
  1455. iowrite8(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
  1456. /* Clear the Rx, Tx rings. */
  1457. for (i = 0; i < RX_RING_SIZE; i++) /* AKPM: this is done in vortex_open, too */
  1458. vp->rx_ring[i].status = 0;
  1459. for (i = 0; i < TX_RING_SIZE; i++)
  1460. vp->tx_skbuff[i] = NULL;
  1461. iowrite32(0, ioaddr + DownListPtr);
  1462. }
  1463. /* Set receiver mode: presumably accept b-case and phys addr only. */
  1464. set_rx_mode(dev);
  1465. /* enable 802.1q tagged frames */
  1466. set_8021q_mode(dev, 1);
  1467. iowrite16(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
  1468. iowrite16(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
  1469. iowrite16(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
  1470. /* Allow status bits to be seen. */
  1471. vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
  1472. (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
  1473. (vp->full_bus_master_rx ? UpComplete : RxComplete) |
  1474. (vp->bus_master ? DMADone : 0);
  1475. vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable |
  1476. (vp->full_bus_master_rx ? 0 : RxComplete) |
  1477. StatsFull | HostError | TxComplete | IntReq
  1478. | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
  1479. iowrite16(vp->status_enable, ioaddr + EL3_CMD);
  1480. /* Ack all pending events, and set active indicator mask. */
  1481. iowrite16(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
  1482. ioaddr + EL3_CMD);
  1483. iowrite16(vp->intr_enable, ioaddr + EL3_CMD);
  1484. if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
  1485. iowrite32(0x8000, vp->cb_fn_base + 4);
  1486. netif_start_queue (dev);
  1487. netdev_reset_queue(dev);
  1488. err_out:
  1489. return err;
  1490. }
  1491. static int
  1492. vortex_open(struct net_device *dev)
  1493. {
  1494. struct vortex_private *vp = netdev_priv(dev);
  1495. int i;
  1496. int retval;
  1497. /* Use the now-standard shared IRQ implementation. */
  1498. if ((retval = request_irq(dev->irq, vp->full_bus_master_rx ?
  1499. boomerang_interrupt : vortex_interrupt, IRQF_SHARED, dev->name, dev))) {
  1500. pr_err("%s: Could not reserve IRQ %d\n", dev->name, dev->irq);
  1501. goto err;
  1502. }
  1503. if (vp->full_bus_master_rx) { /* Boomerang bus master. */
  1504. if (vortex_debug > 2)
  1505. pr_debug("%s: Filling in the Rx ring.\n", dev->name);
  1506. for (i = 0; i < RX_RING_SIZE; i++) {
  1507. struct sk_buff *skb;
  1508. vp->rx_ring[i].next = cpu_to_le32(vp->rx_ring_dma + sizeof(struct boom_rx_desc) * (i+1));
  1509. vp->rx_ring[i].status = 0; /* Clear complete bit. */
  1510. vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);
  1511. skb = __netdev_alloc_skb(dev, PKT_BUF_SZ + NET_IP_ALIGN,
  1512. GFP_KERNEL);
  1513. vp->rx_skbuff[i] = skb;
  1514. if (skb == NULL)
  1515. break; /* Bad news! */
  1516. skb_reserve(skb, NET_IP_ALIGN); /* Align IP on 16 byte boundaries */
  1517. vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
  1518. }
  1519. if (i != RX_RING_SIZE) {
  1520. pr_emerg("%s: no memory for rx ring\n", dev->name);
  1521. retval = -ENOMEM;
  1522. goto err_free_skb;
  1523. }
  1524. /* Wrap the ring. */
  1525. vp->rx_ring[i-1].next = cpu_to_le32(vp->rx_ring_dma);
  1526. }
  1527. retval = vortex_up(dev);
  1528. if (!retval)
  1529. goto out;
  1530. err_free_skb:
  1531. for (i = 0; i < RX_RING_SIZE; i++) {
  1532. if (vp->rx_skbuff[i]) {
  1533. dev_kfree_skb(vp->rx_skbuff[i]);
  1534. vp->rx_skbuff[i] = NULL;
  1535. }
  1536. }
  1537. free_irq(dev->irq, dev);
  1538. err:
  1539. if (vortex_debug > 1)
  1540. pr_err("%s: vortex_open() fails: returning %d\n", dev->name, retval);
  1541. out:
  1542. return retval;
  1543. }
  1544. static void
  1545. vortex_timer(unsigned long data)
  1546. {
  1547. struct net_device *dev = (struct net_device *)data;
  1548. struct vortex_private *vp = netdev_priv(dev);
  1549. void __iomem *ioaddr = vp->ioaddr;
  1550. int next_tick = 60*HZ;
  1551. int ok = 0;
  1552. int media_status;
  1553. if (vortex_debug > 2) {
  1554. pr_debug("%s: Media selection timer tick happened, %s.\n",
  1555. dev->name, media_tbl[dev->if_port].name);
  1556. pr_debug("dev->watchdog_timeo=%d\n", dev->watchdog_timeo);
  1557. }
  1558. media_status = window_read16(vp, 4, Wn4_Media);
  1559. switch (dev->if_port) {
  1560. case XCVR_10baseT: case XCVR_100baseTx: case XCVR_100baseFx:
  1561. if (media_status & Media_LnkBeat) {
  1562. netif_carrier_on(dev);
  1563. ok = 1;
  1564. if (vortex_debug > 1)
  1565. pr_debug("%s: Media %s has link beat, %x.\n",
  1566. dev->name, media_tbl[dev->if_port].name, media_status);
  1567. } else {
  1568. netif_carrier_off(dev);
  1569. if (vortex_debug > 1) {
  1570. pr_debug("%s: Media %s has no link beat, %x.\n",
  1571. dev->name, media_tbl[dev->if_port].name, media_status);
  1572. }
  1573. }
  1574. break;
  1575. case XCVR_MII: case XCVR_NWAY:
  1576. {
  1577. ok = 1;
  1578. vortex_check_media(dev, 0);
  1579. }
  1580. break;
  1581. default: /* Other media types handled by Tx timeouts. */
  1582. if (vortex_debug > 1)
  1583. pr_debug("%s: Media %s has no indication, %x.\n",
  1584. dev->name, media_tbl[dev->if_port].name, media_status);
  1585. ok = 1;
  1586. }
  1587. if (dev->flags & IFF_SLAVE || !netif_carrier_ok(dev))
  1588. next_tick = 5*HZ;
  1589. if (vp->medialock)
  1590. goto leave_media_alone;
  1591. if (!ok) {
  1592. unsigned int config;
  1593. spin_lock_irq(&vp->lock);
  1594. do {
  1595. dev->if_port = media_tbl[dev->if_port].next;
  1596. } while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
  1597. if (dev->if_port == XCVR_Default) { /* Go back to default. */
  1598. dev->if_port = vp->default_media;
  1599. if (vortex_debug > 1)
  1600. pr_debug("%s: Media selection failing, using default %s port.\n",
  1601. dev->name, media_tbl[dev->if_port].name);
  1602. } else {
  1603. if (vortex_debug > 1)
  1604. pr_debug("%s: Media selection failed, now trying %s port.\n",
  1605. dev->name, media_tbl[dev->if_port].name);
  1606. next_tick = media_tbl[dev->if_port].wait;
  1607. }
  1608. window_write16(vp,
  1609. (media_status & ~(Media_10TP|Media_SQE)) |
  1610. media_tbl[dev->if_port].media_bits,
  1611. 4, Wn4_Media);
  1612. config = window_read32(vp, 3, Wn3_Config);
  1613. config = BFINS(config, dev->if_port, 20, 4);
  1614. window_write32(vp, config, 3, Wn3_Config);
  1615. iowrite16(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
  1616. ioaddr + EL3_CMD);
  1617. if (vortex_debug > 1)
  1618. pr_debug("wrote 0x%08x to Wn3_Config\n", config);
  1619. /* AKPM: FIXME: Should reset Rx & Tx here. P60 of 3c90xc.pdf */
  1620. spin_unlock_irq(&vp->lock);
  1621. }
  1622. leave_media_alone:
  1623. if (vortex_debug > 2)
  1624. pr_debug("%s: Media selection timer finished, %s.\n",
  1625. dev->name, media_tbl[dev->if_port].name);
  1626. mod_timer(&vp->timer, RUN_AT(next_tick));
  1627. if (vp->deferred)
  1628. iowrite16(FakeIntr, ioaddr + EL3_CMD);
  1629. }
  1630. static void vortex_tx_timeout(struct net_device *dev)
  1631. {
  1632. struct vortex_private *vp = netdev_priv(dev);
  1633. void __iomem *ioaddr = vp->ioaddr;
  1634. pr_err("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
  1635. dev->name, ioread8(ioaddr + TxStatus),
  1636. ioread16(ioaddr + EL3_STATUS));
  1637. pr_err(" diagnostics: net %04x media %04x dma %08x fifo %04x\n",
  1638. window_read16(vp, 4, Wn4_NetDiag),
  1639. window_read16(vp, 4, Wn4_Media),
  1640. ioread32(ioaddr + PktStatus),
  1641. window_read16(vp, 4, Wn4_FIFODiag));
  1642. /* Slight code bloat to be user friendly. */
  1643. if ((ioread8(ioaddr + TxStatus) & 0x88) == 0x88)
  1644. pr_err("%s: Transmitter encountered 16 collisions --"
  1645. " network cable problem?\n", dev->name);
  1646. if (ioread16(ioaddr + EL3_STATUS) & IntLatch) {
  1647. pr_err("%s: Interrupt posted but not delivered --"
  1648. " IRQ blocked by another device?\n", dev->name);
  1649. /* Bad idea here.. but we might as well handle a few events. */
  1650. {
  1651. /*
  1652. * Block interrupts because vortex_interrupt does a bare spin_lock()
  1653. */
  1654. unsigned long flags;
  1655. local_irq_save(flags);
  1656. if (vp->full_bus_master_tx)
  1657. boomerang_interrupt(dev->irq, dev);
  1658. else
  1659. vortex_interrupt(dev->irq, dev);
  1660. local_irq_restore(flags);
  1661. }
  1662. }
  1663. if (vortex_debug > 0)
  1664. dump_tx_ring(dev);
  1665. issue_and_wait(dev, TxReset);
  1666. dev->stats.tx_errors++;
  1667. if (vp->full_bus_master_tx) {
  1668. pr_debug("%s: Resetting the Tx ring pointer.\n", dev->name);
  1669. if (vp->cur_tx - vp->dirty_tx > 0 && ioread32(ioaddr + DownListPtr) == 0)
  1670. iowrite32(vp->tx_ring_dma + (vp->dirty_tx % TX_RING_SIZE) * sizeof(struct boom_tx_desc),
  1671. ioaddr + DownListPtr);
  1672. if (vp->cur_tx - vp->dirty_tx < TX_RING_SIZE) {
  1673. netif_wake_queue (dev);
  1674. netdev_reset_queue (dev);
  1675. }
  1676. if (vp->drv_flags & IS_BOOMERANG)
  1677. iowrite8(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
  1678. iowrite16(DownUnstall, ioaddr + EL3_CMD);
  1679. } else {
  1680. dev->stats.tx_dropped++;
  1681. netif_wake_queue(dev);
  1682. netdev_reset_queue(dev);
  1683. }
  1684. /* Issue Tx Enable */
  1685. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1686. netif_trans_update(dev); /* prevent tx timeout */
  1687. }
  1688. /*
  1689. * Handle uncommon interrupt sources. This is a separate routine to minimize
  1690. * the cache impact.
  1691. */
  1692. static void
  1693. vortex_error(struct net_device *dev, int status)
  1694. {
  1695. struct vortex_private *vp = netdev_priv(dev);
  1696. void __iomem *ioaddr = vp->ioaddr;
  1697. int do_tx_reset = 0, reset_mask = 0;
  1698. unsigned char tx_status = 0;
  1699. if (vortex_debug > 2) {
  1700. pr_err("%s: vortex_error(), status=0x%x\n", dev->name, status);
  1701. }
  1702. if (status & TxComplete) { /* Really "TxError" for us. */
  1703. tx_status = ioread8(ioaddr + TxStatus);
  1704. /* Presumably a tx-timeout. We must merely re-enable. */
  1705. if (vortex_debug > 2 ||
  1706. (tx_status != 0x88 && vortex_debug > 0)) {
  1707. pr_err("%s: Transmit error, Tx status register %2.2x.\n",
  1708. dev->name, tx_status);
  1709. if (tx_status == 0x82) {
  1710. pr_err("Probably a duplex mismatch. See "
  1711. "Documentation/networking/vortex.txt\n");
  1712. }
  1713. dump_tx_ring(dev);
  1714. }
  1715. if (tx_status & 0x14) dev->stats.tx_fifo_errors++;
  1716. if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
  1717. if (tx_status & 0x08) vp->xstats.tx_max_collisions++;
  1718. iowrite8(0, ioaddr + TxStatus);
  1719. if (tx_status & 0x30) { /* txJabber or txUnderrun */
  1720. do_tx_reset = 1;
  1721. } else if ((tx_status & 0x08) && (vp->drv_flags & MAX_COLLISION_RESET)) { /* maxCollisions */
  1722. do_tx_reset = 1;
  1723. reset_mask = 0x0108; /* Reset interface logic, but not download logic */
  1724. } else { /* Merely re-enable the transmitter. */
  1725. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1726. }
  1727. }
  1728. if (status & RxEarly) /* Rx early is unused. */
  1729. iowrite16(AckIntr | RxEarly, ioaddr + EL3_CMD);
  1730. if (status & StatsFull) { /* Empty statistics. */
  1731. static int DoneDidThat;
  1732. if (vortex_debug > 4)
  1733. pr_debug("%s: Updating stats.\n", dev->name);
  1734. update_stats(ioaddr, dev);
  1735. /* HACK: Disable statistics as an interrupt source. */
  1736. /* This occurs when we have the wrong media type! */
  1737. if (DoneDidThat == 0 &&
  1738. ioread16(ioaddr + EL3_STATUS) & StatsFull) {
  1739. pr_warn("%s: Updating statistics failed, disabling stats as an interrupt source\n",
  1740. dev->name);
  1741. iowrite16(SetIntrEnb |
  1742. (window_read16(vp, 5, 10) & ~StatsFull),
  1743. ioaddr + EL3_CMD);
  1744. vp->intr_enable &= ~StatsFull;
  1745. DoneDidThat++;
  1746. }
  1747. }
  1748. if (status & IntReq) { /* Restore all interrupt sources. */
  1749. iowrite16(vp->status_enable, ioaddr + EL3_CMD);
  1750. iowrite16(vp->intr_enable, ioaddr + EL3_CMD);
  1751. }
  1752. if (status & HostError) {
  1753. u16 fifo_diag;
  1754. fifo_diag = window_read16(vp, 4, Wn4_FIFODiag);
  1755. pr_err("%s: Host error, FIFO diagnostic register %4.4x.\n",
  1756. dev->name, fifo_diag);
  1757. /* Adapter failure requires Tx/Rx reset and reinit. */
  1758. if (vp->full_bus_master_tx) {
  1759. int bus_status = ioread32(ioaddr + PktStatus);
  1760. /* 0x80000000 PCI master abort. */
  1761. /* 0x40000000 PCI target abort. */
  1762. if (vortex_debug)
  1763. pr_err("%s: PCI bus error, bus status %8.8x\n", dev->name, bus_status);
  1764. /* In this case, blow the card away */
  1765. /* Must not enter D3 or we can't legally issue the reset! */
  1766. vortex_down(dev, 0);
  1767. issue_and_wait(dev, TotalReset | 0xff);
  1768. vortex_up(dev); /* AKPM: bug. vortex_up() assumes that the rx ring is full. It may not be. */
  1769. } else if (fifo_diag & 0x0400)
  1770. do_tx_reset = 1;
  1771. if (fifo_diag & 0x3000) {
  1772. /* Reset Rx fifo and upload logic */
  1773. issue_and_wait(dev, RxReset|0x07);
  1774. /* Set the Rx filter to the current state. */
  1775. set_rx_mode(dev);
  1776. /* enable 802.1q VLAN tagged frames */
  1777. set_8021q_mode(dev, 1);
  1778. iowrite16(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
  1779. iowrite16(AckIntr | HostError, ioaddr + EL3_CMD);
  1780. }
  1781. }
  1782. if (do_tx_reset) {
  1783. issue_and_wait(dev, TxReset|reset_mask);
  1784. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1785. if (!vp->full_bus_master_tx)
  1786. netif_wake_queue(dev);
  1787. }
  1788. }
  1789. static netdev_tx_t
  1790. vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1791. {
  1792. struct vortex_private *vp = netdev_priv(dev);
  1793. void __iomem *ioaddr = vp->ioaddr;
  1794. int skblen = skb->len;
  1795. /* Put out the doubleword header... */
  1796. iowrite32(skb->len, ioaddr + TX_FIFO);
  1797. if (vp->bus_master) {
  1798. /* Set the bus-master controller to transfer the packet. */
  1799. int len = (skb->len + 3) & ~3;
  1800. vp->tx_skb_dma = pci_map_single(VORTEX_PCI(vp), skb->data, len,
  1801. PCI_DMA_TODEVICE);
  1802. spin_lock_irq(&vp->window_lock);
  1803. window_set(vp, 7);
  1804. iowrite32(vp->tx_skb_dma, ioaddr + Wn7_MasterAddr);
  1805. iowrite16(len, ioaddr + Wn7_MasterLen);
  1806. spin_unlock_irq(&vp->window_lock);
  1807. vp->tx_skb = skb;
  1808. skb_tx_timestamp(skb);
  1809. iowrite16(StartDMADown, ioaddr + EL3_CMD);
  1810. /* netif_wake_queue() will be called at the DMADone interrupt. */
  1811. } else {
  1812. /* ... and the packet rounded to a doubleword. */
  1813. skb_tx_timestamp(skb);
  1814. iowrite32_rep(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
  1815. dev_consume_skb_any (skb);
  1816. if (ioread16(ioaddr + TxFree) > 1536) {
  1817. netif_start_queue (dev); /* AKPM: redundant? */
  1818. } else {
  1819. /* Interrupt us when the FIFO has room for max-sized packet. */
  1820. netif_stop_queue(dev);
  1821. iowrite16(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
  1822. }
  1823. }
  1824. netdev_sent_queue(dev, skblen);
  1825. /* Clear the Tx status stack. */
  1826. {
  1827. int tx_status;
  1828. int i = 32;
  1829. while (--i > 0 && (tx_status = ioread8(ioaddr + TxStatus)) > 0) {
  1830. if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */
  1831. if (vortex_debug > 2)
  1832. pr_debug("%s: Tx error, status %2.2x.\n",
  1833. dev->name, tx_status);
  1834. if (tx_status & 0x04) dev->stats.tx_fifo_errors++;
  1835. if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
  1836. if (tx_status & 0x30) {
  1837. issue_and_wait(dev, TxReset);
  1838. }
  1839. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1840. }
  1841. iowrite8(0x00, ioaddr + TxStatus); /* Pop the status stack. */
  1842. }
  1843. }
  1844. return NETDEV_TX_OK;
  1845. }
  1846. static netdev_tx_t
  1847. boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1848. {
  1849. struct vortex_private *vp = netdev_priv(dev);
  1850. void __iomem *ioaddr = vp->ioaddr;
  1851. /* Calculate the next Tx descriptor entry. */
  1852. int entry = vp->cur_tx % TX_RING_SIZE;
  1853. int skblen = skb->len;
  1854. struct boom_tx_desc *prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
  1855. unsigned long flags;
  1856. dma_addr_t dma_addr;
  1857. if (vortex_debug > 6) {
  1858. pr_debug("boomerang_start_xmit()\n");
  1859. pr_debug("%s: Trying to send a packet, Tx index %d.\n",
  1860. dev->name, vp->cur_tx);
  1861. }
  1862. /*
  1863. * We can't allow a recursion from our interrupt handler back into the
  1864. * tx routine, as they take the same spin lock, and that causes
  1865. * deadlock. Just return NETDEV_TX_BUSY and let the stack try again in
  1866. * a bit
  1867. */
  1868. if (vp->handling_irq)
  1869. return NETDEV_TX_BUSY;
  1870. if (vp->cur_tx - vp->dirty_tx >= TX_RING_SIZE) {
  1871. if (vortex_debug > 0)
  1872. pr_warn("%s: BUG! Tx Ring full, refusing to send buffer\n",
  1873. dev->name);
  1874. netif_stop_queue(dev);
  1875. return NETDEV_TX_BUSY;
  1876. }
  1877. vp->tx_skbuff[entry] = skb;
  1878. vp->tx_ring[entry].next = 0;
  1879. #if DO_ZEROCOPY
  1880. if (skb->ip_summed != CHECKSUM_PARTIAL)
  1881. vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
  1882. else
  1883. vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded | AddTCPChksum | AddUDPChksum);
  1884. if (!skb_shinfo(skb)->nr_frags) {
  1885. dma_addr = pci_map_single(VORTEX_PCI(vp), skb->data, skb->len,
  1886. PCI_DMA_TODEVICE);
  1887. if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr))
  1888. goto out_dma_err;
  1889. vp->tx_ring[entry].frag[0].addr = cpu_to_le32(dma_addr);
  1890. vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb->len | LAST_FRAG);
  1891. } else {
  1892. int i;
  1893. dma_addr = pci_map_single(VORTEX_PCI(vp), skb->data,
  1894. skb_headlen(skb), PCI_DMA_TODEVICE);
  1895. if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr))
  1896. goto out_dma_err;
  1897. vp->tx_ring[entry].frag[0].addr = cpu_to_le32(dma_addr);
  1898. vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb_headlen(skb));
  1899. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1900. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1901. dma_addr = skb_frag_dma_map(&VORTEX_PCI(vp)->dev, frag,
  1902. 0,
  1903. frag->size,
  1904. DMA_TO_DEVICE);
  1905. if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr)) {
  1906. for(i = i-1; i >= 0; i--)
  1907. dma_unmap_page(&VORTEX_PCI(vp)->dev,
  1908. le32_to_cpu(vp->tx_ring[entry].frag[i+1].addr),
  1909. le32_to_cpu(vp->tx_ring[entry].frag[i+1].length),
  1910. DMA_TO_DEVICE);
  1911. pci_unmap_single(VORTEX_PCI(vp),
  1912. le32_to_cpu(vp->tx_ring[entry].frag[0].addr),
  1913. le32_to_cpu(vp->tx_ring[entry].frag[0].length),
  1914. PCI_DMA_TODEVICE);
  1915. goto out_dma_err;
  1916. }
  1917. vp->tx_ring[entry].frag[i+1].addr =
  1918. cpu_to_le32(dma_addr);
  1919. if (i == skb_shinfo(skb)->nr_frags-1)
  1920. vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(skb_frag_size(frag)|LAST_FRAG);
  1921. else
  1922. vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(skb_frag_size(frag));
  1923. }
  1924. }
  1925. #else
  1926. dma_addr = pci_map_single(VORTEX_PCI(vp), skb->data, skb->len, PCI_DMA_TODEVICE);
  1927. if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr))
  1928. goto out_dma_err;
  1929. vp->tx_ring[entry].addr = cpu_to_le32(dma_addr);
  1930. vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
  1931. vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
  1932. #endif
  1933. spin_lock_irqsave(&vp->lock, flags);
  1934. /* Wait for the stall to complete. */
  1935. issue_and_wait(dev, DownStall);
  1936. prev_entry->next = cpu_to_le32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc));
  1937. if (ioread32(ioaddr + DownListPtr) == 0) {
  1938. iowrite32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc), ioaddr + DownListPtr);
  1939. vp->queued_packet++;
  1940. }
  1941. vp->cur_tx++;
  1942. netdev_sent_queue(dev, skblen);
  1943. if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1) {
  1944. netif_stop_queue (dev);
  1945. } else { /* Clear previous interrupt enable. */
  1946. #if defined(tx_interrupt_mitigation)
  1947. /* Dubious. If in boomeang_interrupt "faster" cyclone ifdef
  1948. * were selected, this would corrupt DN_COMPLETE. No?
  1949. */
  1950. prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
  1951. #endif
  1952. }
  1953. skb_tx_timestamp(skb);
  1954. iowrite16(DownUnstall, ioaddr + EL3_CMD);
  1955. spin_unlock_irqrestore(&vp->lock, flags);
  1956. out:
  1957. return NETDEV_TX_OK;
  1958. out_dma_err:
  1959. dev_err(&VORTEX_PCI(vp)->dev, "Error mapping dma buffer\n");
  1960. goto out;
  1961. }
  1962. /* The interrupt handler does all of the Rx thread work and cleans up
  1963. after the Tx thread. */
  1964. /*
  1965. * This is the ISR for the vortex series chips.
  1966. * full_bus_master_tx == 0 && full_bus_master_rx == 0
  1967. */
  1968. static irqreturn_t
  1969. vortex_interrupt(int irq, void *dev_id)
  1970. {
  1971. struct net_device *dev = dev_id;
  1972. struct vortex_private *vp = netdev_priv(dev);
  1973. void __iomem *ioaddr;
  1974. int status;
  1975. int work_done = max_interrupt_work;
  1976. int handled = 0;
  1977. unsigned int bytes_compl = 0, pkts_compl = 0;
  1978. ioaddr = vp->ioaddr;
  1979. spin_lock(&vp->lock);
  1980. status = ioread16(ioaddr + EL3_STATUS);
  1981. if (vortex_debug > 6)
  1982. pr_debug("vortex_interrupt(). status=0x%4x\n", status);
  1983. if ((status & IntLatch) == 0)
  1984. goto handler_exit; /* No interrupt: shared IRQs cause this */
  1985. handled = 1;
  1986. if (status & IntReq) {
  1987. status |= vp->deferred;
  1988. vp->deferred = 0;
  1989. }
  1990. if (status == 0xffff) /* h/w no longer present (hotplug)? */
  1991. goto handler_exit;
  1992. if (vortex_debug > 4)
  1993. pr_debug("%s: interrupt, status %4.4x, latency %d ticks.\n",
  1994. dev->name, status, ioread8(ioaddr + Timer));
  1995. spin_lock(&vp->window_lock);
  1996. window_set(vp, 7);
  1997. do {
  1998. if (vortex_debug > 5)
  1999. pr_debug("%s: In interrupt loop, status %4.4x.\n",
  2000. dev->name, status);
  2001. if (status & RxComplete)
  2002. vortex_rx(dev);
  2003. if (status & TxAvailable) {
  2004. if (vortex_debug > 5)
  2005. pr_debug(" TX room bit was handled.\n");
  2006. /* There's room in the FIFO for a full-sized packet. */
  2007. iowrite16(AckIntr | TxAvailable, ioaddr + EL3_CMD);
  2008. netif_wake_queue (dev);
  2009. }
  2010. if (status & DMADone) {
  2011. if (ioread16(ioaddr + Wn7_MasterStatus) & 0x1000) {
  2012. iowrite16(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
  2013. pci_unmap_single(VORTEX_PCI(vp), vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE);
  2014. pkts_compl++;
  2015. bytes_compl += vp->tx_skb->len;
  2016. dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */
  2017. if (ioread16(ioaddr + TxFree) > 1536) {
  2018. /*
  2019. * AKPM: FIXME: I don't think we need this. If the queue was stopped due to
  2020. * insufficient FIFO room, the TxAvailable test will succeed and call
  2021. * netif_wake_queue()
  2022. */
  2023. netif_wake_queue(dev);
  2024. } else { /* Interrupt when FIFO has room for max-sized packet. */
  2025. iowrite16(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
  2026. netif_stop_queue(dev);
  2027. }
  2028. }
  2029. }
  2030. /* Check for all uncommon interrupts at once. */
  2031. if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
  2032. if (status == 0xffff)
  2033. break;
  2034. if (status & RxEarly)
  2035. vortex_rx(dev);
  2036. spin_unlock(&vp->window_lock);
  2037. vortex_error(dev, status);
  2038. spin_lock(&vp->window_lock);
  2039. window_set(vp, 7);
  2040. }
  2041. if (--work_done < 0) {
  2042. pr_warn("%s: Too much work in interrupt, status %4.4x\n",
  2043. dev->name, status);
  2044. /* Disable all pending interrupts. */
  2045. do {
  2046. vp->deferred |= status;
  2047. iowrite16(SetStatusEnb | (~vp->deferred & vp->status_enable),
  2048. ioaddr + EL3_CMD);
  2049. iowrite16(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
  2050. } while ((status = ioread16(ioaddr + EL3_CMD)) & IntLatch);
  2051. /* The timer will reenable interrupts. */
  2052. mod_timer(&vp->timer, jiffies + 1*HZ);
  2053. break;
  2054. }
  2055. /* Acknowledge the IRQ. */
  2056. iowrite16(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
  2057. } while ((status = ioread16(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
  2058. netdev_completed_queue(dev, pkts_compl, bytes_compl);
  2059. spin_unlock(&vp->window_lock);
  2060. if (vortex_debug > 4)
  2061. pr_debug("%s: exiting interrupt, status %4.4x.\n",
  2062. dev->name, status);
  2063. handler_exit:
  2064. spin_unlock(&vp->lock);
  2065. return IRQ_RETVAL(handled);
  2066. }
  2067. /*
  2068. * This is the ISR for the boomerang series chips.
  2069. * full_bus_master_tx == 1 && full_bus_master_rx == 1
  2070. */
  2071. static irqreturn_t
  2072. boomerang_interrupt(int irq, void *dev_id)
  2073. {
  2074. struct net_device *dev = dev_id;
  2075. struct vortex_private *vp = netdev_priv(dev);
  2076. void __iomem *ioaddr;
  2077. int status;
  2078. int work_done = max_interrupt_work;
  2079. int handled = 0;
  2080. unsigned int bytes_compl = 0, pkts_compl = 0;
  2081. ioaddr = vp->ioaddr;
  2082. /*
  2083. * It seems dopey to put the spinlock this early, but we could race against vortex_tx_timeout
  2084. * and boomerang_start_xmit
  2085. */
  2086. spin_lock(&vp->lock);
  2087. vp->handling_irq = 1;
  2088. status = ioread16(ioaddr + EL3_STATUS);
  2089. if (vortex_debug > 6)
  2090. pr_debug("boomerang_interrupt. status=0x%4x\n", status);
  2091. if ((status & IntLatch) == 0)
  2092. goto handler_exit; /* No interrupt: shared IRQs can cause this */
  2093. handled = 1;
  2094. if (status == 0xffff) { /* h/w no longer present (hotplug)? */
  2095. if (vortex_debug > 1)
  2096. pr_debug("boomerang_interrupt(1): status = 0xffff\n");
  2097. goto handler_exit;
  2098. }
  2099. if (status & IntReq) {
  2100. status |= vp->deferred;
  2101. vp->deferred = 0;
  2102. }
  2103. if (vortex_debug > 4)
  2104. pr_debug("%s: interrupt, status %4.4x, latency %d ticks.\n",
  2105. dev->name, status, ioread8(ioaddr + Timer));
  2106. do {
  2107. if (vortex_debug > 5)
  2108. pr_debug("%s: In interrupt loop, status %4.4x.\n",
  2109. dev->name, status);
  2110. if (status & UpComplete) {
  2111. iowrite16(AckIntr | UpComplete, ioaddr + EL3_CMD);
  2112. if (vortex_debug > 5)
  2113. pr_debug("boomerang_interrupt->boomerang_rx\n");
  2114. boomerang_rx(dev);
  2115. }
  2116. if (status & DownComplete) {
  2117. unsigned int dirty_tx = vp->dirty_tx;
  2118. iowrite16(AckIntr | DownComplete, ioaddr + EL3_CMD);
  2119. while (vp->cur_tx - dirty_tx > 0) {
  2120. int entry = dirty_tx % TX_RING_SIZE;
  2121. #if 1 /* AKPM: the latter is faster, but cyclone-only */
  2122. if (ioread32(ioaddr + DownListPtr) ==
  2123. vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc))
  2124. break; /* It still hasn't been processed. */
  2125. #else
  2126. if ((vp->tx_ring[entry].status & DN_COMPLETE) == 0)
  2127. break; /* It still hasn't been processed. */
  2128. #endif
  2129. if (vp->tx_skbuff[entry]) {
  2130. struct sk_buff *skb = vp->tx_skbuff[entry];
  2131. #if DO_ZEROCOPY
  2132. int i;
  2133. pci_unmap_single(VORTEX_PCI(vp),
  2134. le32_to_cpu(vp->tx_ring[entry].frag[0].addr),
  2135. le32_to_cpu(vp->tx_ring[entry].frag[0].length)&0xFFF,
  2136. PCI_DMA_TODEVICE);
  2137. for (i=1; i<=skb_shinfo(skb)->nr_frags; i++)
  2138. pci_unmap_page(VORTEX_PCI(vp),
  2139. le32_to_cpu(vp->tx_ring[entry].frag[i].addr),
  2140. le32_to_cpu(vp->tx_ring[entry].frag[i].length)&0xFFF,
  2141. PCI_DMA_TODEVICE);
  2142. #else
  2143. pci_unmap_single(VORTEX_PCI(vp),
  2144. le32_to_cpu(vp->tx_ring[entry].addr), skb->len, PCI_DMA_TODEVICE);
  2145. #endif
  2146. pkts_compl++;
  2147. bytes_compl += skb->len;
  2148. dev_kfree_skb_irq(skb);
  2149. vp->tx_skbuff[entry] = NULL;
  2150. } else {
  2151. pr_debug("boomerang_interrupt: no skb!\n");
  2152. }
  2153. /* dev->stats.tx_packets++; Counted below. */
  2154. dirty_tx++;
  2155. }
  2156. vp->dirty_tx = dirty_tx;
  2157. if (vp->cur_tx - dirty_tx <= TX_RING_SIZE - 1) {
  2158. if (vortex_debug > 6)
  2159. pr_debug("boomerang_interrupt: wake queue\n");
  2160. netif_wake_queue (dev);
  2161. }
  2162. }
  2163. /* Check for all uncommon interrupts at once. */
  2164. if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq))
  2165. vortex_error(dev, status);
  2166. if (--work_done < 0) {
  2167. pr_warn("%s: Too much work in interrupt, status %4.4x\n",
  2168. dev->name, status);
  2169. /* Disable all pending interrupts. */
  2170. do {
  2171. vp->deferred |= status;
  2172. iowrite16(SetStatusEnb | (~vp->deferred & vp->status_enable),
  2173. ioaddr + EL3_CMD);
  2174. iowrite16(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
  2175. } while ((status = ioread16(ioaddr + EL3_CMD)) & IntLatch);
  2176. /* The timer will reenable interrupts. */
  2177. mod_timer(&vp->timer, jiffies + 1*HZ);
  2178. break;
  2179. }
  2180. /* Acknowledge the IRQ. */
  2181. iowrite16(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
  2182. if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
  2183. iowrite32(0x8000, vp->cb_fn_base + 4);
  2184. } while ((status = ioread16(ioaddr + EL3_STATUS)) & IntLatch);
  2185. netdev_completed_queue(dev, pkts_compl, bytes_compl);
  2186. if (vortex_debug > 4)
  2187. pr_debug("%s: exiting interrupt, status %4.4x.\n",
  2188. dev->name, status);
  2189. handler_exit:
  2190. vp->handling_irq = 0;
  2191. spin_unlock(&vp->lock);
  2192. return IRQ_RETVAL(handled);
  2193. }
  2194. static int vortex_rx(struct net_device *dev)
  2195. {
  2196. struct vortex_private *vp = netdev_priv(dev);
  2197. void __iomem *ioaddr = vp->ioaddr;
  2198. int i;
  2199. short rx_status;
  2200. if (vortex_debug > 5)
  2201. pr_debug("vortex_rx(): status %4.4x, rx_status %4.4x.\n",
  2202. ioread16(ioaddr+EL3_STATUS), ioread16(ioaddr+RxStatus));
  2203. while ((rx_status = ioread16(ioaddr + RxStatus)) > 0) {
  2204. if (rx_status & 0x4000) { /* Error, update stats. */
  2205. unsigned char rx_error = ioread8(ioaddr + RxErrors);
  2206. if (vortex_debug > 2)
  2207. pr_debug(" Rx error: status %2.2x.\n", rx_error);
  2208. dev->stats.rx_errors++;
  2209. if (rx_error & 0x01) dev->stats.rx_over_errors++;
  2210. if (rx_error & 0x02) dev->stats.rx_length_errors++;
  2211. if (rx_error & 0x04) dev->stats.rx_frame_errors++;
  2212. if (rx_error & 0x08) dev->stats.rx_crc_errors++;
  2213. if (rx_error & 0x10) dev->stats.rx_length_errors++;
  2214. } else {
  2215. /* The packet length: up to 4.5K!. */
  2216. int pkt_len = rx_status & 0x1fff;
  2217. struct sk_buff *skb;
  2218. skb = netdev_alloc_skb(dev, pkt_len + 5);
  2219. if (vortex_debug > 4)
  2220. pr_debug("Receiving packet size %d status %4.4x.\n",
  2221. pkt_len, rx_status);
  2222. if (skb != NULL) {
  2223. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  2224. /* 'skb_put()' points to the start of sk_buff data area. */
  2225. if (vp->bus_master &&
  2226. ! (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)) {
  2227. dma_addr_t dma = pci_map_single(VORTEX_PCI(vp), skb_put(skb, pkt_len),
  2228. pkt_len, PCI_DMA_FROMDEVICE);
  2229. iowrite32(dma, ioaddr + Wn7_MasterAddr);
  2230. iowrite16((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
  2231. iowrite16(StartDMAUp, ioaddr + EL3_CMD);
  2232. while (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)
  2233. ;
  2234. pci_unmap_single(VORTEX_PCI(vp), dma, pkt_len, PCI_DMA_FROMDEVICE);
  2235. } else {
  2236. ioread32_rep(ioaddr + RX_FIFO,
  2237. skb_put(skb, pkt_len),
  2238. (pkt_len + 3) >> 2);
  2239. }
  2240. iowrite16(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
  2241. skb->protocol = eth_type_trans(skb, dev);
  2242. netif_rx(skb);
  2243. dev->stats.rx_packets++;
  2244. /* Wait a limited time to go to next packet. */
  2245. for (i = 200; i >= 0; i--)
  2246. if ( ! (ioread16(ioaddr + EL3_STATUS) & CmdInProgress))
  2247. break;
  2248. continue;
  2249. } else if (vortex_debug > 0)
  2250. pr_notice("%s: No memory to allocate a sk_buff of size %d.\n",
  2251. dev->name, pkt_len);
  2252. dev->stats.rx_dropped++;
  2253. }
  2254. issue_and_wait(dev, RxDiscard);
  2255. }
  2256. return 0;
  2257. }
  2258. static int
  2259. boomerang_rx(struct net_device *dev)
  2260. {
  2261. struct vortex_private *vp = netdev_priv(dev);
  2262. int entry = vp->cur_rx % RX_RING_SIZE;
  2263. void __iomem *ioaddr = vp->ioaddr;
  2264. int rx_status;
  2265. int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
  2266. if (vortex_debug > 5)
  2267. pr_debug("boomerang_rx(): status %4.4x\n", ioread16(ioaddr+EL3_STATUS));
  2268. while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
  2269. if (--rx_work_limit < 0)
  2270. break;
  2271. if (rx_status & RxDError) { /* Error, update stats. */
  2272. unsigned char rx_error = rx_status >> 16;
  2273. if (vortex_debug > 2)
  2274. pr_debug(" Rx error: status %2.2x.\n", rx_error);
  2275. dev->stats.rx_errors++;
  2276. if (rx_error & 0x01) dev->stats.rx_over_errors++;
  2277. if (rx_error & 0x02) dev->stats.rx_length_errors++;
  2278. if (rx_error & 0x04) dev->stats.rx_frame_errors++;
  2279. if (rx_error & 0x08) dev->stats.rx_crc_errors++;
  2280. if (rx_error & 0x10) dev->stats.rx_length_errors++;
  2281. } else {
  2282. /* The packet length: up to 4.5K!. */
  2283. int pkt_len = rx_status & 0x1fff;
  2284. struct sk_buff *skb;
  2285. dma_addr_t dma = le32_to_cpu(vp->rx_ring[entry].addr);
  2286. if (vortex_debug > 4)
  2287. pr_debug("Receiving packet size %d status %4.4x.\n",
  2288. pkt_len, rx_status);
  2289. /* Check if the packet is long enough to just accept without
  2290. copying to a properly sized skbuff. */
  2291. if (pkt_len < rx_copybreak &&
  2292. (skb = netdev_alloc_skb(dev, pkt_len + 2)) != NULL) {
  2293. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  2294. pci_dma_sync_single_for_cpu(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2295. /* 'skb_put()' points to the start of sk_buff data area. */
  2296. memcpy(skb_put(skb, pkt_len),
  2297. vp->rx_skbuff[entry]->data,
  2298. pkt_len);
  2299. pci_dma_sync_single_for_device(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2300. vp->rx_copy++;
  2301. } else {
  2302. /* Pass up the skbuff already on the Rx ring. */
  2303. skb = vp->rx_skbuff[entry];
  2304. vp->rx_skbuff[entry] = NULL;
  2305. skb_put(skb, pkt_len);
  2306. pci_unmap_single(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2307. vp->rx_nocopy++;
  2308. }
  2309. skb->protocol = eth_type_trans(skb, dev);
  2310. { /* Use hardware checksum info. */
  2311. int csum_bits = rx_status & 0xee000000;
  2312. if (csum_bits &&
  2313. (csum_bits == (IPChksumValid | TCPChksumValid) ||
  2314. csum_bits == (IPChksumValid | UDPChksumValid))) {
  2315. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2316. vp->rx_csumhits++;
  2317. }
  2318. }
  2319. netif_rx(skb);
  2320. dev->stats.rx_packets++;
  2321. }
  2322. entry = (++vp->cur_rx) % RX_RING_SIZE;
  2323. }
  2324. /* Refill the Rx ring buffers. */
  2325. for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
  2326. struct sk_buff *skb;
  2327. entry = vp->dirty_rx % RX_RING_SIZE;
  2328. if (vp->rx_skbuff[entry] == NULL) {
  2329. skb = netdev_alloc_skb_ip_align(dev, PKT_BUF_SZ);
  2330. if (skb == NULL) {
  2331. static unsigned long last_jif;
  2332. if (time_after(jiffies, last_jif + 10 * HZ)) {
  2333. pr_warn("%s: memory shortage\n",
  2334. dev->name);
  2335. last_jif = jiffies;
  2336. }
  2337. if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)
  2338. mod_timer(&vp->rx_oom_timer, RUN_AT(HZ * 1));
  2339. break; /* Bad news! */
  2340. }
  2341. vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
  2342. vp->rx_skbuff[entry] = skb;
  2343. }
  2344. vp->rx_ring[entry].status = 0; /* Clear complete bit. */
  2345. iowrite16(UpUnstall, ioaddr + EL3_CMD);
  2346. }
  2347. return 0;
  2348. }
  2349. /*
  2350. * If we've hit a total OOM refilling the Rx ring we poll once a second
  2351. * for some memory. Otherwise there is no way to restart the rx process.
  2352. */
  2353. static void
  2354. rx_oom_timer(unsigned long arg)
  2355. {
  2356. struct net_device *dev = (struct net_device *)arg;
  2357. struct vortex_private *vp = netdev_priv(dev);
  2358. spin_lock_irq(&vp->lock);
  2359. if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE) /* This test is redundant, but makes me feel good */
  2360. boomerang_rx(dev);
  2361. if (vortex_debug > 1) {
  2362. pr_debug("%s: rx_oom_timer %s\n", dev->name,
  2363. ((vp->cur_rx - vp->dirty_rx) != RX_RING_SIZE) ? "succeeded" : "retrying");
  2364. }
  2365. spin_unlock_irq(&vp->lock);
  2366. }
  2367. static void
  2368. vortex_down(struct net_device *dev, int final_down)
  2369. {
  2370. struct vortex_private *vp = netdev_priv(dev);
  2371. void __iomem *ioaddr = vp->ioaddr;
  2372. netdev_reset_queue(dev);
  2373. netif_stop_queue(dev);
  2374. del_timer_sync(&vp->rx_oom_timer);
  2375. del_timer_sync(&vp->timer);
  2376. /* Turn off statistics ASAP. We update dev->stats below. */
  2377. iowrite16(StatsDisable, ioaddr + EL3_CMD);
  2378. /* Disable the receiver and transmitter. */
  2379. iowrite16(RxDisable, ioaddr + EL3_CMD);
  2380. iowrite16(TxDisable, ioaddr + EL3_CMD);
  2381. /* Disable receiving 802.1q tagged frames */
  2382. set_8021q_mode(dev, 0);
  2383. if (dev->if_port == XCVR_10base2)
  2384. /* Turn off thinnet power. Green! */
  2385. iowrite16(StopCoax, ioaddr + EL3_CMD);
  2386. iowrite16(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
  2387. update_stats(ioaddr, dev);
  2388. if (vp->full_bus_master_rx)
  2389. iowrite32(0, ioaddr + UpListPtr);
  2390. if (vp->full_bus_master_tx)
  2391. iowrite32(0, ioaddr + DownListPtr);
  2392. if (final_down && VORTEX_PCI(vp)) {
  2393. vp->pm_state_valid = 1;
  2394. pci_save_state(VORTEX_PCI(vp));
  2395. acpi_set_WOL(dev);
  2396. }
  2397. }
  2398. static int
  2399. vortex_close(struct net_device *dev)
  2400. {
  2401. struct vortex_private *vp = netdev_priv(dev);
  2402. void __iomem *ioaddr = vp->ioaddr;
  2403. int i;
  2404. if (netif_device_present(dev))
  2405. vortex_down(dev, 1);
  2406. if (vortex_debug > 1) {
  2407. pr_debug("%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
  2408. dev->name, ioread16(ioaddr + EL3_STATUS), ioread8(ioaddr + TxStatus));
  2409. pr_debug("%s: vortex close stats: rx_nocopy %d rx_copy %d"
  2410. " tx_queued %d Rx pre-checksummed %d.\n",
  2411. dev->name, vp->rx_nocopy, vp->rx_copy, vp->queued_packet, vp->rx_csumhits);
  2412. }
  2413. #if DO_ZEROCOPY
  2414. if (vp->rx_csumhits &&
  2415. (vp->drv_flags & HAS_HWCKSM) == 0 &&
  2416. (vp->card_idx >= MAX_UNITS || hw_checksums[vp->card_idx] == -1)) {
  2417. pr_warn("%s supports hardware checksums, and we're not using them!\n",
  2418. dev->name);
  2419. }
  2420. #endif
  2421. free_irq(dev->irq, dev);
  2422. if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
  2423. for (i = 0; i < RX_RING_SIZE; i++)
  2424. if (vp->rx_skbuff[i]) {
  2425. pci_unmap_single( VORTEX_PCI(vp), le32_to_cpu(vp->rx_ring[i].addr),
  2426. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2427. dev_kfree_skb(vp->rx_skbuff[i]);
  2428. vp->rx_skbuff[i] = NULL;
  2429. }
  2430. }
  2431. if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
  2432. for (i = 0; i < TX_RING_SIZE; i++) {
  2433. if (vp->tx_skbuff[i]) {
  2434. struct sk_buff *skb = vp->tx_skbuff[i];
  2435. #if DO_ZEROCOPY
  2436. int k;
  2437. for (k=0; k<=skb_shinfo(skb)->nr_frags; k++)
  2438. pci_unmap_single(VORTEX_PCI(vp),
  2439. le32_to_cpu(vp->tx_ring[i].frag[k].addr),
  2440. le32_to_cpu(vp->tx_ring[i].frag[k].length)&0xFFF,
  2441. PCI_DMA_TODEVICE);
  2442. #else
  2443. pci_unmap_single(VORTEX_PCI(vp), le32_to_cpu(vp->tx_ring[i].addr), skb->len, PCI_DMA_TODEVICE);
  2444. #endif
  2445. dev_kfree_skb(skb);
  2446. vp->tx_skbuff[i] = NULL;
  2447. }
  2448. }
  2449. }
  2450. return 0;
  2451. }
  2452. static void
  2453. dump_tx_ring(struct net_device *dev)
  2454. {
  2455. if (vortex_debug > 0) {
  2456. struct vortex_private *vp = netdev_priv(dev);
  2457. void __iomem *ioaddr = vp->ioaddr;
  2458. if (vp->full_bus_master_tx) {
  2459. int i;
  2460. int stalled = ioread32(ioaddr + PktStatus) & 0x04; /* Possible racy. But it's only debug stuff */
  2461. pr_err(" Flags; bus-master %d, dirty %d(%d) current %d(%d)\n",
  2462. vp->full_bus_master_tx,
  2463. vp->dirty_tx, vp->dirty_tx % TX_RING_SIZE,
  2464. vp->cur_tx, vp->cur_tx % TX_RING_SIZE);
  2465. pr_err(" Transmit list %8.8x vs. %p.\n",
  2466. ioread32(ioaddr + DownListPtr),
  2467. &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
  2468. issue_and_wait(dev, DownStall);
  2469. for (i = 0; i < TX_RING_SIZE; i++) {
  2470. unsigned int length;
  2471. #if DO_ZEROCOPY
  2472. length = le32_to_cpu(vp->tx_ring[i].frag[0].length);
  2473. #else
  2474. length = le32_to_cpu(vp->tx_ring[i].length);
  2475. #endif
  2476. pr_err(" %d: @%p length %8.8x status %8.8x\n",
  2477. i, &vp->tx_ring[i], length,
  2478. le32_to_cpu(vp->tx_ring[i].status));
  2479. }
  2480. if (!stalled)
  2481. iowrite16(DownUnstall, ioaddr + EL3_CMD);
  2482. }
  2483. }
  2484. }
  2485. static struct net_device_stats *vortex_get_stats(struct net_device *dev)
  2486. {
  2487. struct vortex_private *vp = netdev_priv(dev);
  2488. void __iomem *ioaddr = vp->ioaddr;
  2489. unsigned long flags;
  2490. if (netif_device_present(dev)) { /* AKPM: Used to be netif_running */
  2491. spin_lock_irqsave (&vp->lock, flags);
  2492. update_stats(ioaddr, dev);
  2493. spin_unlock_irqrestore (&vp->lock, flags);
  2494. }
  2495. return &dev->stats;
  2496. }
  2497. /* Update statistics.
  2498. Unlike with the EL3 we need not worry about interrupts changing
  2499. the window setting from underneath us, but we must still guard
  2500. against a race condition with a StatsUpdate interrupt updating the
  2501. table. This is done by checking that the ASM (!) code generated uses
  2502. atomic updates with '+='.
  2503. */
  2504. static void update_stats(void __iomem *ioaddr, struct net_device *dev)
  2505. {
  2506. struct vortex_private *vp = netdev_priv(dev);
  2507. /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
  2508. /* Switch to the stats window, and read everything. */
  2509. dev->stats.tx_carrier_errors += window_read8(vp, 6, 0);
  2510. dev->stats.tx_heartbeat_errors += window_read8(vp, 6, 1);
  2511. dev->stats.tx_window_errors += window_read8(vp, 6, 4);
  2512. dev->stats.rx_fifo_errors += window_read8(vp, 6, 5);
  2513. dev->stats.tx_packets += window_read8(vp, 6, 6);
  2514. dev->stats.tx_packets += (window_read8(vp, 6, 9) &
  2515. 0x30) << 4;
  2516. /* Rx packets */ window_read8(vp, 6, 7); /* Must read to clear */
  2517. /* Don't bother with register 9, an extension of registers 6&7.
  2518. If we do use the 6&7 values the atomic update assumption above
  2519. is invalid. */
  2520. dev->stats.rx_bytes += window_read16(vp, 6, 10);
  2521. dev->stats.tx_bytes += window_read16(vp, 6, 12);
  2522. /* Extra stats for get_ethtool_stats() */
  2523. vp->xstats.tx_multiple_collisions += window_read8(vp, 6, 2);
  2524. vp->xstats.tx_single_collisions += window_read8(vp, 6, 3);
  2525. vp->xstats.tx_deferred += window_read8(vp, 6, 8);
  2526. vp->xstats.rx_bad_ssd += window_read8(vp, 4, 12);
  2527. dev->stats.collisions = vp->xstats.tx_multiple_collisions
  2528. + vp->xstats.tx_single_collisions
  2529. + vp->xstats.tx_max_collisions;
  2530. {
  2531. u8 up = window_read8(vp, 4, 13);
  2532. dev->stats.rx_bytes += (up & 0x0f) << 16;
  2533. dev->stats.tx_bytes += (up & 0xf0) << 12;
  2534. }
  2535. }
  2536. static int vortex_nway_reset(struct net_device *dev)
  2537. {
  2538. struct vortex_private *vp = netdev_priv(dev);
  2539. return mii_nway_restart(&vp->mii);
  2540. }
  2541. static int vortex_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2542. {
  2543. struct vortex_private *vp = netdev_priv(dev);
  2544. return mii_ethtool_gset(&vp->mii, cmd);
  2545. }
  2546. static int vortex_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2547. {
  2548. struct vortex_private *vp = netdev_priv(dev);
  2549. return mii_ethtool_sset(&vp->mii, cmd);
  2550. }
  2551. static u32 vortex_get_msglevel(struct net_device *dev)
  2552. {
  2553. return vortex_debug;
  2554. }
  2555. static void vortex_set_msglevel(struct net_device *dev, u32 dbg)
  2556. {
  2557. vortex_debug = dbg;
  2558. }
  2559. static int vortex_get_sset_count(struct net_device *dev, int sset)
  2560. {
  2561. switch (sset) {
  2562. case ETH_SS_STATS:
  2563. return VORTEX_NUM_STATS;
  2564. default:
  2565. return -EOPNOTSUPP;
  2566. }
  2567. }
  2568. static void vortex_get_ethtool_stats(struct net_device *dev,
  2569. struct ethtool_stats *stats, u64 *data)
  2570. {
  2571. struct vortex_private *vp = netdev_priv(dev);
  2572. void __iomem *ioaddr = vp->ioaddr;
  2573. unsigned long flags;
  2574. spin_lock_irqsave(&vp->lock, flags);
  2575. update_stats(ioaddr, dev);
  2576. spin_unlock_irqrestore(&vp->lock, flags);
  2577. data[0] = vp->xstats.tx_deferred;
  2578. data[1] = vp->xstats.tx_max_collisions;
  2579. data[2] = vp->xstats.tx_multiple_collisions;
  2580. data[3] = vp->xstats.tx_single_collisions;
  2581. data[4] = vp->xstats.rx_bad_ssd;
  2582. }
  2583. static void vortex_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  2584. {
  2585. switch (stringset) {
  2586. case ETH_SS_STATS:
  2587. memcpy(data, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  2588. break;
  2589. default:
  2590. WARN_ON(1);
  2591. break;
  2592. }
  2593. }
  2594. static void vortex_get_drvinfo(struct net_device *dev,
  2595. struct ethtool_drvinfo *info)
  2596. {
  2597. struct vortex_private *vp = netdev_priv(dev);
  2598. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  2599. if (VORTEX_PCI(vp)) {
  2600. strlcpy(info->bus_info, pci_name(VORTEX_PCI(vp)),
  2601. sizeof(info->bus_info));
  2602. } else {
  2603. if (VORTEX_EISA(vp))
  2604. strlcpy(info->bus_info, dev_name(vp->gendev),
  2605. sizeof(info->bus_info));
  2606. else
  2607. snprintf(info->bus_info, sizeof(info->bus_info),
  2608. "EISA 0x%lx %d", dev->base_addr, dev->irq);
  2609. }
  2610. }
  2611. static void vortex_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  2612. {
  2613. struct vortex_private *vp = netdev_priv(dev);
  2614. if (!VORTEX_PCI(vp))
  2615. return;
  2616. wol->supported = WAKE_MAGIC;
  2617. wol->wolopts = 0;
  2618. if (vp->enable_wol)
  2619. wol->wolopts |= WAKE_MAGIC;
  2620. }
  2621. static int vortex_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  2622. {
  2623. struct vortex_private *vp = netdev_priv(dev);
  2624. if (!VORTEX_PCI(vp))
  2625. return -EOPNOTSUPP;
  2626. if (wol->wolopts & ~WAKE_MAGIC)
  2627. return -EINVAL;
  2628. if (wol->wolopts & WAKE_MAGIC)
  2629. vp->enable_wol = 1;
  2630. else
  2631. vp->enable_wol = 0;
  2632. acpi_set_WOL(dev);
  2633. return 0;
  2634. }
  2635. static const struct ethtool_ops vortex_ethtool_ops = {
  2636. .get_drvinfo = vortex_get_drvinfo,
  2637. .get_strings = vortex_get_strings,
  2638. .get_msglevel = vortex_get_msglevel,
  2639. .set_msglevel = vortex_set_msglevel,
  2640. .get_ethtool_stats = vortex_get_ethtool_stats,
  2641. .get_sset_count = vortex_get_sset_count,
  2642. .get_settings = vortex_get_settings,
  2643. .set_settings = vortex_set_settings,
  2644. .get_link = ethtool_op_get_link,
  2645. .nway_reset = vortex_nway_reset,
  2646. .get_wol = vortex_get_wol,
  2647. .set_wol = vortex_set_wol,
  2648. .get_ts_info = ethtool_op_get_ts_info,
  2649. };
  2650. #ifdef CONFIG_PCI
  2651. /*
  2652. * Must power the device up to do MDIO operations
  2653. */
  2654. static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2655. {
  2656. int err;
  2657. struct vortex_private *vp = netdev_priv(dev);
  2658. pci_power_t state = 0;
  2659. if(VORTEX_PCI(vp))
  2660. state = VORTEX_PCI(vp)->current_state;
  2661. /* The kernel core really should have pci_get_power_state() */
  2662. if(state != 0)
  2663. pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
  2664. err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
  2665. if(state != 0)
  2666. pci_set_power_state(VORTEX_PCI(vp), state);
  2667. return err;
  2668. }
  2669. #endif
  2670. /* Pre-Cyclone chips have no documented multicast filter, so the only
  2671. multicast setting is to receive all multicast frames. At least
  2672. the chip has a very clean way to set the mode, unlike many others. */
  2673. static void set_rx_mode(struct net_device *dev)
  2674. {
  2675. struct vortex_private *vp = netdev_priv(dev);
  2676. void __iomem *ioaddr = vp->ioaddr;
  2677. int new_mode;
  2678. if (dev->flags & IFF_PROMISC) {
  2679. if (vortex_debug > 3)
  2680. pr_notice("%s: Setting promiscuous mode.\n", dev->name);
  2681. new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
  2682. } else if (!netdev_mc_empty(dev) || dev->flags & IFF_ALLMULTI) {
  2683. new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
  2684. } else
  2685. new_mode = SetRxFilter | RxStation | RxBroadcast;
  2686. iowrite16(new_mode, ioaddr + EL3_CMD);
  2687. }
  2688. #if IS_ENABLED(CONFIG_VLAN_8021Q)
  2689. /* Setup the card so that it can receive frames with an 802.1q VLAN tag.
  2690. Note that this must be done after each RxReset due to some backwards
  2691. compatibility logic in the Cyclone and Tornado ASICs */
  2692. /* The Ethernet Type used for 802.1q tagged frames */
  2693. #define VLAN_ETHER_TYPE 0x8100
  2694. static void set_8021q_mode(struct net_device *dev, int enable)
  2695. {
  2696. struct vortex_private *vp = netdev_priv(dev);
  2697. int mac_ctrl;
  2698. if ((vp->drv_flags&IS_CYCLONE) || (vp->drv_flags&IS_TORNADO)) {
  2699. /* cyclone and tornado chipsets can recognize 802.1q
  2700. * tagged frames and treat them correctly */
  2701. int max_pkt_size = dev->mtu+14; /* MTU+Ethernet header */
  2702. if (enable)
  2703. max_pkt_size += 4; /* 802.1Q VLAN tag */
  2704. window_write16(vp, max_pkt_size, 3, Wn3_MaxPktSize);
  2705. /* set VlanEtherType to let the hardware checksumming
  2706. treat tagged frames correctly */
  2707. window_write16(vp, VLAN_ETHER_TYPE, 7, Wn7_VlanEtherType);
  2708. } else {
  2709. /* on older cards we have to enable large frames */
  2710. vp->large_frames = dev->mtu > 1500 || enable;
  2711. mac_ctrl = window_read16(vp, 3, Wn3_MAC_Ctrl);
  2712. if (vp->large_frames)
  2713. mac_ctrl |= 0x40;
  2714. else
  2715. mac_ctrl &= ~0x40;
  2716. window_write16(vp, mac_ctrl, 3, Wn3_MAC_Ctrl);
  2717. }
  2718. }
  2719. #else
  2720. static void set_8021q_mode(struct net_device *dev, int enable)
  2721. {
  2722. }
  2723. #endif
  2724. /* MII transceiver control section.
  2725. Read and write the MII registers using software-generated serial
  2726. MDIO protocol. See the MII specifications or DP83840A data sheet
  2727. for details. */
  2728. /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
  2729. met by back-to-back PCI I/O cycles, but we insert a delay to avoid
  2730. "overclocking" issues. */
  2731. static void mdio_delay(struct vortex_private *vp)
  2732. {
  2733. window_read32(vp, 4, Wn4_PhysicalMgmt);
  2734. }
  2735. #define MDIO_SHIFT_CLK 0x01
  2736. #define MDIO_DIR_WRITE 0x04
  2737. #define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
  2738. #define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
  2739. #define MDIO_DATA_READ 0x02
  2740. #define MDIO_ENB_IN 0x00
  2741. /* Generate the preamble required for initial synchronization and
  2742. a few older transceivers. */
  2743. static void mdio_sync(struct vortex_private *vp, int bits)
  2744. {
  2745. /* Establish sync by sending at least 32 logic ones. */
  2746. while (-- bits >= 0) {
  2747. window_write16(vp, MDIO_DATA_WRITE1, 4, Wn4_PhysicalMgmt);
  2748. mdio_delay(vp);
  2749. window_write16(vp, MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK,
  2750. 4, Wn4_PhysicalMgmt);
  2751. mdio_delay(vp);
  2752. }
  2753. }
  2754. static int mdio_read(struct net_device *dev, int phy_id, int location)
  2755. {
  2756. int i;
  2757. struct vortex_private *vp = netdev_priv(dev);
  2758. int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
  2759. unsigned int retval = 0;
  2760. spin_lock_bh(&vp->mii_lock);
  2761. if (mii_preamble_required)
  2762. mdio_sync(vp, 32);
  2763. /* Shift the read command bits out. */
  2764. for (i = 14; i >= 0; i--) {
  2765. int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  2766. window_write16(vp, dataval, 4, Wn4_PhysicalMgmt);
  2767. mdio_delay(vp);
  2768. window_write16(vp, dataval | MDIO_SHIFT_CLK,
  2769. 4, Wn4_PhysicalMgmt);
  2770. mdio_delay(vp);
  2771. }
  2772. /* Read the two transition, 16 data, and wire-idle bits. */
  2773. for (i = 19; i > 0; i--) {
  2774. window_write16(vp, MDIO_ENB_IN, 4, Wn4_PhysicalMgmt);
  2775. mdio_delay(vp);
  2776. retval = (retval << 1) |
  2777. ((window_read16(vp, 4, Wn4_PhysicalMgmt) &
  2778. MDIO_DATA_READ) ? 1 : 0);
  2779. window_write16(vp, MDIO_ENB_IN | MDIO_SHIFT_CLK,
  2780. 4, Wn4_PhysicalMgmt);
  2781. mdio_delay(vp);
  2782. }
  2783. spin_unlock_bh(&vp->mii_lock);
  2784. return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
  2785. }
  2786. static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
  2787. {
  2788. struct vortex_private *vp = netdev_priv(dev);
  2789. int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
  2790. int i;
  2791. spin_lock_bh(&vp->mii_lock);
  2792. if (mii_preamble_required)
  2793. mdio_sync(vp, 32);
  2794. /* Shift the command bits out. */
  2795. for (i = 31; i >= 0; i--) {
  2796. int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  2797. window_write16(vp, dataval, 4, Wn4_PhysicalMgmt);
  2798. mdio_delay(vp);
  2799. window_write16(vp, dataval | MDIO_SHIFT_CLK,
  2800. 4, Wn4_PhysicalMgmt);
  2801. mdio_delay(vp);
  2802. }
  2803. /* Leave the interface idle. */
  2804. for (i = 1; i >= 0; i--) {
  2805. window_write16(vp, MDIO_ENB_IN, 4, Wn4_PhysicalMgmt);
  2806. mdio_delay(vp);
  2807. window_write16(vp, MDIO_ENB_IN | MDIO_SHIFT_CLK,
  2808. 4, Wn4_PhysicalMgmt);
  2809. mdio_delay(vp);
  2810. }
  2811. spin_unlock_bh(&vp->mii_lock);
  2812. }
  2813. /* ACPI: Advanced Configuration and Power Interface. */
  2814. /* Set Wake-On-LAN mode and put the board into D3 (power-down) state. */
  2815. static void acpi_set_WOL(struct net_device *dev)
  2816. {
  2817. struct vortex_private *vp = netdev_priv(dev);
  2818. void __iomem *ioaddr = vp->ioaddr;
  2819. device_set_wakeup_enable(vp->gendev, vp->enable_wol);
  2820. if (vp->enable_wol) {
  2821. /* Power up on: 1==Downloaded Filter, 2==Magic Packets, 4==Link Status. */
  2822. window_write16(vp, 2, 7, 0x0c);
  2823. /* The RxFilter must accept the WOL frames. */
  2824. iowrite16(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
  2825. iowrite16(RxEnable, ioaddr + EL3_CMD);
  2826. if (pci_enable_wake(VORTEX_PCI(vp), PCI_D3hot, 1)) {
  2827. pr_info("%s: WOL not supported.\n", pci_name(VORTEX_PCI(vp)));
  2828. vp->enable_wol = 0;
  2829. return;
  2830. }
  2831. if (VORTEX_PCI(vp)->current_state < PCI_D3hot)
  2832. return;
  2833. /* Change the power state to D3; RxEnable doesn't take effect. */
  2834. pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot);
  2835. }
  2836. }
  2837. static void vortex_remove_one(struct pci_dev *pdev)
  2838. {
  2839. struct net_device *dev = pci_get_drvdata(pdev);
  2840. struct vortex_private *vp;
  2841. if (!dev) {
  2842. pr_err("vortex_remove_one called for Compaq device!\n");
  2843. BUG();
  2844. }
  2845. vp = netdev_priv(dev);
  2846. if (vp->cb_fn_base)
  2847. pci_iounmap(pdev, vp->cb_fn_base);
  2848. unregister_netdev(dev);
  2849. pci_set_power_state(pdev, PCI_D0); /* Go active */
  2850. if (vp->pm_state_valid)
  2851. pci_restore_state(pdev);
  2852. pci_disable_device(pdev);
  2853. /* Should really use issue_and_wait() here */
  2854. iowrite16(TotalReset | ((vp->drv_flags & EEPROM_RESET) ? 0x04 : 0x14),
  2855. vp->ioaddr + EL3_CMD);
  2856. pci_iounmap(pdev, vp->ioaddr);
  2857. pci_free_consistent(pdev,
  2858. sizeof(struct boom_rx_desc) * RX_RING_SIZE
  2859. + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
  2860. vp->rx_ring,
  2861. vp->rx_ring_dma);
  2862. pci_release_regions(pdev);
  2863. free_netdev(dev);
  2864. }
  2865. static struct pci_driver vortex_driver = {
  2866. .name = "3c59x",
  2867. .probe = vortex_init_one,
  2868. .remove = vortex_remove_one,
  2869. .id_table = vortex_pci_tbl,
  2870. .driver.pm = VORTEX_PM_OPS,
  2871. };
  2872. static int vortex_have_pci;
  2873. static int vortex_have_eisa;
  2874. static int __init vortex_init(void)
  2875. {
  2876. int pci_rc, eisa_rc;
  2877. pci_rc = pci_register_driver(&vortex_driver);
  2878. eisa_rc = vortex_eisa_init();
  2879. if (pci_rc == 0)
  2880. vortex_have_pci = 1;
  2881. if (eisa_rc > 0)
  2882. vortex_have_eisa = 1;
  2883. return (vortex_have_pci + vortex_have_eisa) ? 0 : -ENODEV;
  2884. }
  2885. static void __exit vortex_eisa_cleanup(void)
  2886. {
  2887. void __iomem *ioaddr;
  2888. #ifdef CONFIG_EISA
  2889. /* Take care of the EISA devices */
  2890. eisa_driver_unregister(&vortex_eisa_driver);
  2891. #endif
  2892. if (compaq_net_device) {
  2893. ioaddr = ioport_map(compaq_net_device->base_addr,
  2894. VORTEX_TOTAL_SIZE);
  2895. unregister_netdev(compaq_net_device);
  2896. iowrite16(TotalReset, ioaddr + EL3_CMD);
  2897. release_region(compaq_net_device->base_addr,
  2898. VORTEX_TOTAL_SIZE);
  2899. free_netdev(compaq_net_device);
  2900. }
  2901. }
  2902. static void __exit vortex_cleanup(void)
  2903. {
  2904. if (vortex_have_pci)
  2905. pci_unregister_driver(&vortex_driver);
  2906. if (vortex_have_eisa)
  2907. vortex_eisa_cleanup();
  2908. }
  2909. module_init(vortex_init);
  2910. module_exit(vortex_cleanup);