tlan.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304
  1. /*******************************************************************************
  2. *
  3. * Linux ThunderLAN Driver
  4. *
  5. * tlan.c
  6. * by James Banks
  7. *
  8. * (C) 1997-1998 Caldera, Inc.
  9. * (C) 1998 James Banks
  10. * (C) 1999-2001 Torben Mathiasen
  11. * (C) 2002 Samuel Chessman
  12. *
  13. * This software may be used and distributed according to the terms
  14. * of the GNU General Public License, incorporated herein by reference.
  15. *
  16. ** This file is best viewed/edited with columns>=132.
  17. *
  18. ** Useful (if not required) reading:
  19. *
  20. * Texas Instruments, ThunderLAN Programmer's Guide,
  21. * TI Literature Number SPWU013A
  22. * available in PDF format from www.ti.com
  23. * Level One, LXT901 and LXT970 Data Sheets
  24. * available in PDF format from www.level1.com
  25. * National Semiconductor, DP83840A Data Sheet
  26. * available in PDF format from www.national.com
  27. * Microchip Technology, 24C01A/02A/04A Data Sheet
  28. * available in PDF format from www.microchip.com
  29. *
  30. * Change History
  31. *
  32. * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses
  33. * new PCI BIOS interface.
  34. * Alan Cox <alan@redhat.com>: Fixed the out of memory
  35. * handling.
  36. *
  37. * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer!
  38. *
  39. * v1.1 Dec 20, 1999 - Removed linux version checking
  40. * Patch from Tigran Aivazian.
  41. * - v1.1 includes Alan's SMP updates.
  42. * - We still have problems on SMP though,
  43. * but I'm looking into that.
  44. *
  45. * v1.2 Jan 02, 2000 - Hopefully fixed the SMP deadlock.
  46. * - Removed dependency of HZ being 100.
  47. * - We now allow higher priority timers to
  48. * overwrite timers like TLAN_TIMER_ACTIVITY
  49. * Patch from John Cagle <john.cagle@compaq.com>.
  50. * - Fixed a few compiler warnings.
  51. *
  52. * v1.3 Feb 04, 2000 - Fixed the remaining HZ issues.
  53. * - Removed call to pci_present().
  54. * - Removed SA_INTERRUPT flag from irq handler.
  55. * - Added __init and __initdata to reduce resisdent
  56. * code size.
  57. * - Driver now uses module_init/module_exit.
  58. * - Rewrote init_module and tlan_probe to
  59. * share a lot more code. We now use tlan_probe
  60. * with builtin and module driver.
  61. * - Driver ported to new net API.
  62. * - tlan.txt has been reworked to reflect current
  63. * driver (almost)
  64. * - Other minor stuff
  65. *
  66. * v1.4 Feb 10, 2000 - Updated with more changes required after Dave's
  67. * network cleanup in 2.3.43pre7 (Tigran & myself)
  68. * - Minor stuff.
  69. *
  70. * v1.5 March 22, 2000 - Fixed another timer bug that would hang the driver
  71. * if no cable/link were present.
  72. * - Cosmetic changes.
  73. * - TODO: Port completely to new PCI/DMA API
  74. * Auto-Neg fallback.
  75. *
  76. * v1.6 April 04, 2000 - Fixed driver support for kernel-parameters. Haven't
  77. * tested it though, as the kernel support is currently
  78. * broken (2.3.99p4p3).
  79. * - Updated tlan.txt accordingly.
  80. * - Adjusted minimum/maximum frame length.
  81. * - There is now a TLAN website up at
  82. * http://tlan.kernel.dk
  83. *
  84. * v1.7 April 07, 2000 - Started to implement custom ioctls. Driver now
  85. * reports PHY information when used with Donald
  86. * Beckers userspace MII diagnostics utility.
  87. *
  88. * v1.8 April 23, 2000 - Fixed support for forced speed/duplex settings.
  89. * - Added link information to Auto-Neg and forced
  90. * modes. When NIC operates with auto-neg the driver
  91. * will report Link speed & duplex modes as well as
  92. * link partner abilities. When forced link is used,
  93. * the driver will report status of the established
  94. * link.
  95. * Please read tlan.txt for additional information.
  96. * - Removed call to check_region(), and used
  97. * return value of request_region() instead.
  98. *
  99. * v1.8a May 28, 2000 - Minor updates.
  100. *
  101. * v1.9 July 25, 2000 - Fixed a few remaining Full-Duplex issues.
  102. * - Updated with timer fixes from Andrew Morton.
  103. * - Fixed module race in TLan_Open.
  104. * - Added routine to monitor PHY status.
  105. * - Added activity led support for Proliant devices.
  106. *
  107. * v1.10 Aug 30, 2000 - Added support for EISA based tlan controllers
  108. * like the Compaq NetFlex3/E.
  109. * - Rewrote tlan_probe to better handle multiple
  110. * bus probes. Probing and device setup is now
  111. * done through TLan_Probe and TLan_init_one. Actual
  112. * hardware probe is done with kernel API and
  113. * TLan_EisaProbe.
  114. * - Adjusted debug information for probing.
  115. * - Fixed bug that would cause general debug information
  116. * to be printed after driver removal.
  117. * - Added transmit timeout handling.
  118. * - Fixed OOM return values in tlan_probe.
  119. * - Fixed possible mem leak in tlan_exit
  120. * (now tlan_remove_one).
  121. * - Fixed timer bug in TLan_phyMonitor.
  122. * - This driver version is alpha quality, please
  123. * send me any bug issues you may encounter.
  124. *
  125. * v1.11 Aug 31, 2000 - Do not try to register irq 0 if no irq line was
  126. * set for EISA cards.
  127. * - Added support for NetFlex3/E with nibble-rate
  128. * 10Base-T PHY. This is untestet as I haven't got
  129. * one of these cards.
  130. * - Fixed timer being added twice.
  131. * - Disabled PhyMonitoring by default as this is
  132. * work in progress. Define MONITOR to enable it.
  133. * - Now we don't display link info with PHYs that
  134. * doesn't support it (level1).
  135. * - Incresed tx_timeout beacuse of auto-neg.
  136. * - Adjusted timers for forced speeds.
  137. *
  138. * v1.12 Oct 12, 2000 - Minor fixes (memleak, init, etc.)
  139. *
  140. * v1.13 Nov 28, 2000 - Stop flooding console with auto-neg issues
  141. * when link can't be established.
  142. * - Added the bbuf option as a kernel parameter.
  143. * - Fixed ioaddr probe bug.
  144. * - Fixed stupid deadlock with MII interrupts.
  145. * - Added support for speed/duplex selection with
  146. * multiple nics.
  147. * - Added partly fix for TX Channel lockup with
  148. * TLAN v1.0 silicon. This needs to be investigated
  149. * further.
  150. *
  151. * v1.14 Dec 16, 2000 - Added support for servicing multiple frames per.
  152. * interrupt. Thanks goes to
  153. * Adam Keys <adam@ti.com>
  154. * Denis Beaudoin <dbeaudoin@ti.com>
  155. * for providing the patch.
  156. * - Fixed auto-neg output when using multiple
  157. * adapters.
  158. * - Converted to use new taskq interface.
  159. *
  160. * v1.14a Jan 6, 2001 - Minor adjustments (spinlocks, etc.)
  161. *
  162. * Samuel Chessman <chessman@tux.org> New Maintainer!
  163. *
  164. * v1.15 Apr 4, 2002 - Correct operation when aui=1 to be
  165. * 10T half duplex no loopback
  166. * Thanks to Gunnar Eikman
  167. *******************************************************************************/
  168. #include <linux/module.h>
  169. #include <linux/init.h>
  170. #include <linux/ioport.h>
  171. #include <linux/eisa.h>
  172. #include <linux/pci.h>
  173. #include <linux/netdevice.h>
  174. #include <linux/etherdevice.h>
  175. #include <linux/delay.h>
  176. #include <linux/spinlock.h>
  177. #include <linux/workqueue.h>
  178. #include <linux/mii.h>
  179. #include "tlan.h"
  180. typedef u32 (TLanIntVectorFunc)( struct net_device *, u16 );
  181. /* For removing EISA devices */
  182. static struct net_device *TLan_Eisa_Devices;
  183. static int TLanDevicesInstalled;
  184. /* Set speed, duplex and aui settings */
  185. static int aui[MAX_TLAN_BOARDS];
  186. static int duplex[MAX_TLAN_BOARDS];
  187. static int speed[MAX_TLAN_BOARDS];
  188. static int boards_found;
  189. MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
  190. MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
  191. MODULE_LICENSE("GPL");
  192. /* Define this to enable Link beat monitoring */
  193. #undef MONITOR
  194. /* Turn on debugging. See Documentation/networking/tlan.txt for details */
  195. static int debug;
  196. static int bbuf;
  197. static u8 *TLanPadBuffer;
  198. static dma_addr_t TLanPadBufferDMA;
  199. static char TLanSignature[] = "TLAN";
  200. static const char tlan_banner[] = "ThunderLAN driver v1.15\n";
  201. static int tlan_have_pci;
  202. static int tlan_have_eisa;
  203. static const char *media[] = {
  204. "10BaseT-HD ", "10BaseT-FD ","100baseTx-HD ",
  205. "100baseTx-FD", "100baseT4", NULL
  206. };
  207. static struct board {
  208. const char *deviceLabel;
  209. u32 flags;
  210. u16 addrOfs;
  211. } board_info[] = {
  212. { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  213. { "Compaq Netelligent 10/100 TX PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  214. { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
  215. { "Compaq NetFlex-3/P", TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
  216. { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
  217. { "Compaq Netelligent Integrated 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  218. { "Compaq Netelligent Dual 10/100 TX PCI UTP", TLAN_ADAPTER_NONE, 0x83 },
  219. { "Compaq Netelligent 10/100 TX Embedded UTP", TLAN_ADAPTER_NONE, 0x83 },
  220. { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
  221. { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xF8 },
  222. { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xF8 },
  223. { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  224. { "Compaq Netelligent 10 T/2 PCI UTP/Coax", TLAN_ADAPTER_NONE, 0x83 },
  225. { "Compaq NetFlex-3/E", TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
  226. TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
  227. { "Compaq NetFlex-3/E", TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
  228. };
  229. static struct pci_device_id tlan_pci_tbl[] = {
  230. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
  231. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  232. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
  233. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  234. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
  235. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  236. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
  237. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  238. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
  239. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
  240. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
  241. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
  242. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
  243. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
  244. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
  245. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
  246. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
  247. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
  248. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
  249. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
  250. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
  251. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
  252. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
  253. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
  254. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
  255. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
  256. { 0,}
  257. };
  258. MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
  259. static void TLan_EisaProbe( void );
  260. static void TLan_Eisa_Cleanup( void );
  261. static int TLan_Init( struct net_device * );
  262. static int TLan_Open( struct net_device *dev );
  263. static int TLan_StartTx( struct sk_buff *, struct net_device *);
  264. static irqreturn_t TLan_HandleInterrupt( int, void *, struct pt_regs *);
  265. static int TLan_Close( struct net_device *);
  266. static struct net_device_stats *TLan_GetStats( struct net_device *);
  267. static void TLan_SetMulticastList( struct net_device *);
  268. static int TLan_ioctl( struct net_device *dev, struct ifreq *rq, int cmd);
  269. static int TLan_probe1( struct pci_dev *pdev, long ioaddr, int irq, int rev, const struct pci_device_id *ent);
  270. static void TLan_tx_timeout( struct net_device *dev);
  271. static int tlan_init_one( struct pci_dev *pdev, const struct pci_device_id *ent);
  272. static u32 TLan_HandleInvalid( struct net_device *, u16 );
  273. static u32 TLan_HandleTxEOF( struct net_device *, u16 );
  274. static u32 TLan_HandleStatOverflow( struct net_device *, u16 );
  275. static u32 TLan_HandleRxEOF( struct net_device *, u16 );
  276. static u32 TLan_HandleDummy( struct net_device *, u16 );
  277. static u32 TLan_HandleTxEOC( struct net_device *, u16 );
  278. static u32 TLan_HandleStatusCheck( struct net_device *, u16 );
  279. static u32 TLan_HandleRxEOC( struct net_device *, u16 );
  280. static void TLan_Timer( unsigned long );
  281. static void TLan_ResetLists( struct net_device * );
  282. static void TLan_FreeLists( struct net_device * );
  283. static void TLan_PrintDio( u16 );
  284. static void TLan_PrintList( TLanList *, char *, int );
  285. static void TLan_ReadAndClearStats( struct net_device *, int );
  286. static void TLan_ResetAdapter( struct net_device * );
  287. static void TLan_FinishReset( struct net_device * );
  288. static void TLan_SetMac( struct net_device *, int areg, char *mac );
  289. static void TLan_PhyPrint( struct net_device * );
  290. static void TLan_PhyDetect( struct net_device * );
  291. static void TLan_PhyPowerDown( struct net_device * );
  292. static void TLan_PhyPowerUp( struct net_device * );
  293. static void TLan_PhyReset( struct net_device * );
  294. static void TLan_PhyStartLink( struct net_device * );
  295. static void TLan_PhyFinishAutoNeg( struct net_device * );
  296. #ifdef MONITOR
  297. static void TLan_PhyMonitor( struct net_device * );
  298. #endif
  299. /*
  300. static int TLan_PhyNop( struct net_device * );
  301. static int TLan_PhyInternalCheck( struct net_device * );
  302. static int TLan_PhyInternalService( struct net_device * );
  303. static int TLan_PhyDp83840aCheck( struct net_device * );
  304. */
  305. static int TLan_MiiReadReg( struct net_device *, u16, u16, u16 * );
  306. static void TLan_MiiSendData( u16, u32, unsigned );
  307. static void TLan_MiiSync( u16 );
  308. static void TLan_MiiWriteReg( struct net_device *, u16, u16, u16 );
  309. static void TLan_EeSendStart( u16 );
  310. static int TLan_EeSendByte( u16, u8, int );
  311. static void TLan_EeReceiveByte( u16, u8 *, int );
  312. static int TLan_EeReadByte( struct net_device *, u8, u8 * );
  313. static void
  314. TLan_StoreSKB( struct tlan_list_tag *tag, struct sk_buff *skb)
  315. {
  316. unsigned long addr = (unsigned long)skb;
  317. tag->buffer[9].address = (u32)addr;
  318. addr >>= 31; /* >>= 32 is undefined for 32bit arch, stupid C */
  319. addr >>= 1;
  320. tag->buffer[8].address = (u32)addr;
  321. }
  322. static struct sk_buff *
  323. TLan_GetSKB( struct tlan_list_tag *tag)
  324. {
  325. unsigned long addr = tag->buffer[8].address;
  326. addr <<= 31;
  327. addr <<= 1;
  328. addr |= tag->buffer[9].address;
  329. return (struct sk_buff *) addr;
  330. }
  331. static TLanIntVectorFunc *TLanIntVector[TLAN_INT_NUMBER_OF_INTS] = {
  332. TLan_HandleInvalid,
  333. TLan_HandleTxEOF,
  334. TLan_HandleStatOverflow,
  335. TLan_HandleRxEOF,
  336. TLan_HandleDummy,
  337. TLan_HandleTxEOC,
  338. TLan_HandleStatusCheck,
  339. TLan_HandleRxEOC
  340. };
  341. static inline void
  342. TLan_SetTimer( struct net_device *dev, u32 ticks, u32 type )
  343. {
  344. TLanPrivateInfo *priv = netdev_priv(dev);
  345. unsigned long flags = 0;
  346. if (!in_irq())
  347. spin_lock_irqsave(&priv->lock, flags);
  348. if ( priv->timer.function != NULL &&
  349. priv->timerType != TLAN_TIMER_ACTIVITY ) {
  350. if (!in_irq())
  351. spin_unlock_irqrestore(&priv->lock, flags);
  352. return;
  353. }
  354. priv->timer.function = &TLan_Timer;
  355. if (!in_irq())
  356. spin_unlock_irqrestore(&priv->lock, flags);
  357. priv->timer.data = (unsigned long) dev;
  358. priv->timerSetAt = jiffies;
  359. priv->timerType = type;
  360. mod_timer(&priv->timer, jiffies + ticks);
  361. } /* TLan_SetTimer */
  362. /*****************************************************************************
  363. ******************************************************************************
  364. ThunderLAN Driver Primary Functions
  365. These functions are more or less common to all Linux network drivers.
  366. ******************************************************************************
  367. *****************************************************************************/
  368. /***************************************************************
  369. * tlan_remove_one
  370. *
  371. * Returns:
  372. * Nothing
  373. * Parms:
  374. * None
  375. *
  376. * Goes through the TLanDevices list and frees the device
  377. * structs and memory associated with each device (lists
  378. * and buffers). It also ureserves the IO port regions
  379. * associated with this device.
  380. *
  381. **************************************************************/
  382. static void __devexit tlan_remove_one( struct pci_dev *pdev)
  383. {
  384. struct net_device *dev = pci_get_drvdata( pdev );
  385. TLanPrivateInfo *priv = netdev_priv(dev);
  386. unregister_netdev( dev );
  387. if ( priv->dmaStorage ) {
  388. pci_free_consistent(priv->pciDev, priv->dmaSize, priv->dmaStorage, priv->dmaStorageDMA );
  389. }
  390. #ifdef CONFIG_PCI
  391. pci_release_regions(pdev);
  392. #endif
  393. free_netdev( dev );
  394. pci_set_drvdata( pdev, NULL );
  395. }
  396. static struct pci_driver tlan_driver = {
  397. .name = "tlan",
  398. .id_table = tlan_pci_tbl,
  399. .probe = tlan_init_one,
  400. .remove = __devexit_p(tlan_remove_one),
  401. };
  402. static int __init tlan_probe(void)
  403. {
  404. static int pad_allocated;
  405. printk(KERN_INFO "%s", tlan_banner);
  406. TLanPadBuffer = (u8 *) pci_alloc_consistent(NULL, TLAN_MIN_FRAME_SIZE, &TLanPadBufferDMA);
  407. if (TLanPadBuffer == NULL) {
  408. printk(KERN_ERR "TLAN: Could not allocate memory for pad buffer.\n");
  409. return -ENOMEM;
  410. }
  411. memset(TLanPadBuffer, 0, TLAN_MIN_FRAME_SIZE);
  412. pad_allocated = 1;
  413. TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
  414. /* Use new style PCI probing. Now the kernel will
  415. do most of this for us */
  416. pci_register_driver(&tlan_driver);
  417. TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
  418. TLan_EisaProbe();
  419. printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n",
  420. TLanDevicesInstalled, TLanDevicesInstalled == 1 ? "" : "s",
  421. tlan_have_pci, tlan_have_eisa);
  422. if (TLanDevicesInstalled == 0) {
  423. pci_unregister_driver(&tlan_driver);
  424. pci_free_consistent(NULL, TLAN_MIN_FRAME_SIZE, TLanPadBuffer, TLanPadBufferDMA);
  425. return -ENODEV;
  426. }
  427. return 0;
  428. }
  429. static int __devinit tlan_init_one( struct pci_dev *pdev,
  430. const struct pci_device_id *ent)
  431. {
  432. return TLan_probe1( pdev, -1, -1, 0, ent);
  433. }
  434. /*
  435. ***************************************************************
  436. * tlan_probe1
  437. *
  438. * Returns:
  439. * 0 on success, error code on error
  440. * Parms:
  441. * none
  442. *
  443. * The name is lower case to fit in with all the rest of
  444. * the netcard_probe names. This function looks for
  445. * another TLan based adapter, setting it up with the
  446. * allocated device struct if one is found.
  447. * tlan_probe has been ported to the new net API and
  448. * now allocates its own device structure. This function
  449. * is also used by modules.
  450. *
  451. **************************************************************/
  452. static int __devinit TLan_probe1(struct pci_dev *pdev,
  453. long ioaddr, int irq, int rev, const struct pci_device_id *ent )
  454. {
  455. struct net_device *dev;
  456. TLanPrivateInfo *priv;
  457. u8 pci_rev;
  458. u16 device_id;
  459. int reg, rc = -ENODEV;
  460. if (pdev) {
  461. rc = pci_enable_device(pdev);
  462. if (rc)
  463. return rc;
  464. rc = pci_request_regions(pdev, TLanSignature);
  465. if (rc) {
  466. printk(KERN_ERR "TLAN: Could not reserve IO regions\n");
  467. goto err_out;
  468. }
  469. }
  470. dev = alloc_etherdev(sizeof(TLanPrivateInfo));
  471. if (dev == NULL) {
  472. printk(KERN_ERR "TLAN: Could not allocate memory for device.\n");
  473. rc = -ENOMEM;
  474. goto err_out_regions;
  475. }
  476. SET_MODULE_OWNER(dev);
  477. SET_NETDEV_DEV(dev, &pdev->dev);
  478. priv = netdev_priv(dev);
  479. priv->pciDev = pdev;
  480. /* Is this a PCI device? */
  481. if (pdev) {
  482. u32 pci_io_base = 0;
  483. priv->adapter = &board_info[ent->driver_data];
  484. rc = pci_set_dma_mask(pdev, 0xFFFFFFFF);
  485. if (rc) {
  486. printk(KERN_ERR "TLAN: No suitable PCI mapping available.\n");
  487. goto err_out_free_dev;
  488. }
  489. pci_read_config_byte ( pdev, PCI_REVISION_ID, &pci_rev);
  490. for ( reg= 0; reg <= 5; reg ++ ) {
  491. if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
  492. pci_io_base = pci_resource_start(pdev, reg);
  493. TLAN_DBG( TLAN_DEBUG_GNRL, "IO mapping is available at %x.\n",
  494. pci_io_base);
  495. break;
  496. }
  497. }
  498. if (!pci_io_base) {
  499. printk(KERN_ERR "TLAN: No IO mappings available\n");
  500. rc = -EIO;
  501. goto err_out_free_dev;
  502. }
  503. dev->base_addr = pci_io_base;
  504. dev->irq = pdev->irq;
  505. priv->adapterRev = pci_rev;
  506. pci_set_master(pdev);
  507. pci_set_drvdata(pdev, dev);
  508. } else { /* EISA card */
  509. /* This is a hack. We need to know which board structure
  510. * is suited for this adapter */
  511. device_id = inw(ioaddr + EISA_ID2);
  512. priv->is_eisa = 1;
  513. if (device_id == 0x20F1) {
  514. priv->adapter = &board_info[13]; /* NetFlex-3/E */
  515. priv->adapterRev = 23; /* TLAN 2.3 */
  516. } else {
  517. priv->adapter = &board_info[14];
  518. priv->adapterRev = 10; /* TLAN 1.0 */
  519. }
  520. dev->base_addr = ioaddr;
  521. dev->irq = irq;
  522. }
  523. /* Kernel parameters */
  524. if (dev->mem_start) {
  525. priv->aui = dev->mem_start & 0x01;
  526. priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0 : (dev->mem_start & 0x06) >> 1;
  527. priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0 : (dev->mem_start & 0x18) >> 3;
  528. if (priv->speed == 0x1) {
  529. priv->speed = TLAN_SPEED_10;
  530. } else if (priv->speed == 0x2) {
  531. priv->speed = TLAN_SPEED_100;
  532. }
  533. debug = priv->debug = dev->mem_end;
  534. } else {
  535. priv->aui = aui[boards_found];
  536. priv->speed = speed[boards_found];
  537. priv->duplex = duplex[boards_found];
  538. priv->debug = debug;
  539. }
  540. /* This will be used when we get an adapter error from
  541. * within our irq handler */
  542. INIT_WORK(&priv->tlan_tqueue, (void *)(void*)TLan_tx_timeout, dev);
  543. spin_lock_init(&priv->lock);
  544. rc = TLan_Init(dev);
  545. if (rc) {
  546. printk(KERN_ERR "TLAN: Could not set up device.\n");
  547. goto err_out_free_dev;
  548. }
  549. rc = register_netdev(dev);
  550. if (rc) {
  551. printk(KERN_ERR "TLAN: Could not register device.\n");
  552. goto err_out_uninit;
  553. }
  554. TLanDevicesInstalled++;
  555. boards_found++;
  556. /* pdev is NULL if this is an EISA device */
  557. if (pdev)
  558. tlan_have_pci++;
  559. else {
  560. priv->nextDevice = TLan_Eisa_Devices;
  561. TLan_Eisa_Devices = dev;
  562. tlan_have_eisa++;
  563. }
  564. printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
  565. dev->name,
  566. (int) dev->irq,
  567. (int) dev->base_addr,
  568. priv->adapter->deviceLabel,
  569. priv->adapterRev);
  570. return 0;
  571. err_out_uninit:
  572. pci_free_consistent(priv->pciDev, priv->dmaSize, priv->dmaStorage,
  573. priv->dmaStorageDMA );
  574. err_out_free_dev:
  575. free_netdev(dev);
  576. err_out_regions:
  577. #ifdef CONFIG_PCI
  578. if (pdev)
  579. pci_release_regions(pdev);
  580. #endif
  581. err_out:
  582. if (pdev)
  583. pci_disable_device(pdev);
  584. return rc;
  585. }
  586. static void TLan_Eisa_Cleanup(void)
  587. {
  588. struct net_device *dev;
  589. TLanPrivateInfo *priv;
  590. while( tlan_have_eisa ) {
  591. dev = TLan_Eisa_Devices;
  592. priv = netdev_priv(dev);
  593. if (priv->dmaStorage) {
  594. pci_free_consistent(priv->pciDev, priv->dmaSize, priv->dmaStorage, priv->dmaStorageDMA );
  595. }
  596. release_region( dev->base_addr, 0x10);
  597. unregister_netdev( dev );
  598. TLan_Eisa_Devices = priv->nextDevice;
  599. free_netdev( dev );
  600. tlan_have_eisa--;
  601. }
  602. }
  603. static void __exit tlan_exit(void)
  604. {
  605. pci_unregister_driver(&tlan_driver);
  606. if (tlan_have_eisa)
  607. TLan_Eisa_Cleanup();
  608. pci_free_consistent(NULL, TLAN_MIN_FRAME_SIZE, TLanPadBuffer, TLanPadBufferDMA);
  609. }
  610. /* Module loading/unloading */
  611. module_init(tlan_probe);
  612. module_exit(tlan_exit);
  613. /**************************************************************
  614. * TLan_EisaProbe
  615. *
  616. * Returns: 0 on success, 1 otherwise
  617. *
  618. * Parms: None
  619. *
  620. *
  621. * This functions probes for EISA devices and calls
  622. * TLan_probe1 when one is found.
  623. *
  624. *************************************************************/
  625. static void __init TLan_EisaProbe (void)
  626. {
  627. long ioaddr;
  628. int rc = -ENODEV;
  629. int irq;
  630. u16 device_id;
  631. if (!EISA_bus) {
  632. TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
  633. return;
  634. }
  635. /* Loop through all slots of the EISA bus */
  636. for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
  637. TLAN_DBG(TLAN_DEBUG_PROBE,"EISA_ID 0x%4x: 0x%4x\n", (int) ioaddr + 0xC80, inw(ioaddr + EISA_ID));
  638. TLAN_DBG(TLAN_DEBUG_PROBE,"EISA_ID 0x%4x: 0x%4x\n", (int) ioaddr + 0xC82, inw(ioaddr + EISA_ID2));
  639. TLAN_DBG(TLAN_DEBUG_PROBE, "Probing for EISA adapter at IO: 0x%4x : ",
  640. (int) ioaddr);
  641. if (request_region(ioaddr, 0x10, TLanSignature) == NULL)
  642. goto out;
  643. if (inw(ioaddr + EISA_ID) != 0x110E) {
  644. release_region(ioaddr, 0x10);
  645. goto out;
  646. }
  647. device_id = inw(ioaddr + EISA_ID2);
  648. if (device_id != 0x20F1 && device_id != 0x40F1) {
  649. release_region (ioaddr, 0x10);
  650. goto out;
  651. }
  652. if (inb(ioaddr + EISA_CR) != 0x1) { /* Check if adapter is enabled */
  653. release_region (ioaddr, 0x10);
  654. goto out2;
  655. }
  656. if (debug == 0x10)
  657. printk("Found one\n");
  658. /* Get irq from board */
  659. switch (inb(ioaddr + 0xCC0)) {
  660. case(0x10):
  661. irq=5;
  662. break;
  663. case(0x20):
  664. irq=9;
  665. break;
  666. case(0x40):
  667. irq=10;
  668. break;
  669. case(0x80):
  670. irq=11;
  671. break;
  672. default:
  673. goto out;
  674. }
  675. /* Setup the newly found eisa adapter */
  676. rc = TLan_probe1( NULL, ioaddr, irq,
  677. 12, NULL);
  678. continue;
  679. out:
  680. if (debug == 0x10)
  681. printk("None found\n");
  682. continue;
  683. out2: if (debug == 0x10)
  684. printk("Card found but it is not enabled, skipping\n");
  685. continue;
  686. }
  687. } /* TLan_EisaProbe */
  688. #ifdef CONFIG_NET_POLL_CONTROLLER
  689. static void TLan_Poll(struct net_device *dev)
  690. {
  691. disable_irq(dev->irq);
  692. TLan_HandleInterrupt(dev->irq, dev, NULL);
  693. enable_irq(dev->irq);
  694. }
  695. #endif
  696. /***************************************************************
  697. * TLan_Init
  698. *
  699. * Returns:
  700. * 0 on success, error code otherwise.
  701. * Parms:
  702. * dev The structure of the device to be
  703. * init'ed.
  704. *
  705. * This function completes the initialization of the
  706. * device structure and driver. It reserves the IO
  707. * addresses, allocates memory for the lists and bounce
  708. * buffers, retrieves the MAC address from the eeprom
  709. * and assignes the device's methods.
  710. *
  711. **************************************************************/
  712. static int TLan_Init( struct net_device *dev )
  713. {
  714. int dma_size;
  715. int err;
  716. int i;
  717. TLanPrivateInfo *priv;
  718. priv = netdev_priv(dev);
  719. if ( bbuf ) {
  720. dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
  721. * ( sizeof(TLanList) + TLAN_MAX_FRAME_SIZE );
  722. } else {
  723. dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
  724. * ( sizeof(TLanList) );
  725. }
  726. priv->dmaStorage = pci_alloc_consistent(priv->pciDev, dma_size, &priv->dmaStorageDMA);
  727. priv->dmaSize = dma_size;
  728. if ( priv->dmaStorage == NULL ) {
  729. printk(KERN_ERR "TLAN: Could not allocate lists and buffers for %s.\n",
  730. dev->name );
  731. return -ENOMEM;
  732. }
  733. memset( priv->dmaStorage, 0, dma_size );
  734. priv->rxList = (TLanList *)
  735. ( ( ( (u32) priv->dmaStorage ) + 7 ) & 0xFFFFFFF8 );
  736. priv->rxListDMA = ( ( ( (u32) priv->dmaStorageDMA ) + 7 ) & 0xFFFFFFF8 );
  737. priv->txList = priv->rxList + TLAN_NUM_RX_LISTS;
  738. priv->txListDMA = priv->rxListDMA + sizeof(TLanList) * TLAN_NUM_RX_LISTS;
  739. if ( bbuf ) {
  740. priv->rxBuffer = (u8 *) ( priv->txList + TLAN_NUM_TX_LISTS );
  741. priv->rxBufferDMA =priv->txListDMA + sizeof(TLanList) * TLAN_NUM_TX_LISTS;
  742. priv->txBuffer = priv->rxBuffer + ( TLAN_NUM_RX_LISTS * TLAN_MAX_FRAME_SIZE );
  743. priv->txBufferDMA = priv->rxBufferDMA + ( TLAN_NUM_RX_LISTS * TLAN_MAX_FRAME_SIZE );
  744. }
  745. err = 0;
  746. for ( i = 0; i < 6 ; i++ )
  747. err |= TLan_EeReadByte( dev,
  748. (u8) priv->adapter->addrOfs + i,
  749. (u8 *) &dev->dev_addr[i] );
  750. if ( err ) {
  751. printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n",
  752. dev->name,
  753. err );
  754. }
  755. dev->addr_len = 6;
  756. netif_carrier_off(dev);
  757. /* Device methods */
  758. dev->open = &TLan_Open;
  759. dev->hard_start_xmit = &TLan_StartTx;
  760. dev->stop = &TLan_Close;
  761. dev->get_stats = &TLan_GetStats;
  762. dev->set_multicast_list = &TLan_SetMulticastList;
  763. dev->do_ioctl = &TLan_ioctl;
  764. #ifdef CONFIG_NET_POLL_CONTROLLER
  765. dev->poll_controller = &TLan_Poll;
  766. #endif
  767. dev->tx_timeout = &TLan_tx_timeout;
  768. dev->watchdog_timeo = TX_TIMEOUT;
  769. return 0;
  770. } /* TLan_Init */
  771. /***************************************************************
  772. * TLan_Open
  773. *
  774. * Returns:
  775. * 0 on success, error code otherwise.
  776. * Parms:
  777. * dev Structure of device to be opened.
  778. *
  779. * This routine puts the driver and TLAN adapter in a
  780. * state where it is ready to send and receive packets.
  781. * It allocates the IRQ, resets and brings the adapter
  782. * out of reset, and allows interrupts. It also delays
  783. * the startup for autonegotiation or sends a Rx GO
  784. * command to the adapter, as appropriate.
  785. *
  786. **************************************************************/
  787. static int TLan_Open( struct net_device *dev )
  788. {
  789. TLanPrivateInfo *priv = netdev_priv(dev);
  790. int err;
  791. priv->tlanRev = TLan_DioRead8( dev->base_addr, TLAN_DEF_REVISION );
  792. err = request_irq( dev->irq, TLan_HandleInterrupt, SA_SHIRQ, TLanSignature, dev );
  793. if ( err ) {
  794. printk(KERN_ERR "TLAN: Cannot open %s because IRQ %d is already in use.\n", dev->name, dev->irq );
  795. return err;
  796. }
  797. init_timer(&priv->timer);
  798. netif_start_queue(dev);
  799. /* NOTE: It might not be necessary to read the stats before a
  800. reset if you don't care what the values are.
  801. */
  802. TLan_ResetLists( dev );
  803. TLan_ReadAndClearStats( dev, TLAN_IGNORE );
  804. TLan_ResetAdapter( dev );
  805. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n", dev->name, priv->tlanRev );
  806. return 0;
  807. } /* TLan_Open */
  808. /**************************************************************
  809. * TLan_ioctl
  810. *
  811. * Returns:
  812. * 0 on success, error code otherwise
  813. * Params:
  814. * dev structure of device to receive ioctl.
  815. *
  816. * rq ifreq structure to hold userspace data.
  817. *
  818. * cmd ioctl command.
  819. *
  820. *
  821. *************************************************************/
  822. static int TLan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  823. {
  824. TLanPrivateInfo *priv = netdev_priv(dev);
  825. struct mii_ioctl_data *data = if_mii(rq);
  826. u32 phy = priv->phy[priv->phyNum];
  827. if (!priv->phyOnline)
  828. return -EAGAIN;
  829. switch(cmd) {
  830. case SIOCGMIIPHY: /* Get address of MII PHY in use. */
  831. data->phy_id = phy;
  832. case SIOCGMIIREG: /* Read MII PHY register. */
  833. TLan_MiiReadReg(dev, data->phy_id & 0x1f, data->reg_num & 0x1f, &data->val_out);
  834. return 0;
  835. case SIOCSMIIREG: /* Write MII PHY register. */
  836. if (!capable(CAP_NET_ADMIN))
  837. return -EPERM;
  838. TLan_MiiWriteReg(dev, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
  839. return 0;
  840. default:
  841. return -EOPNOTSUPP;
  842. }
  843. } /* tlan_ioctl */
  844. /***************************************************************
  845. * TLan_tx_timeout
  846. *
  847. * Returns: nothing
  848. *
  849. * Params:
  850. * dev structure of device which timed out
  851. * during transmit.
  852. *
  853. **************************************************************/
  854. static void TLan_tx_timeout(struct net_device *dev)
  855. {
  856. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
  857. /* Ok so we timed out, lets see what we can do about it...*/
  858. TLan_FreeLists( dev );
  859. TLan_ResetLists( dev );
  860. TLan_ReadAndClearStats( dev, TLAN_IGNORE );
  861. TLan_ResetAdapter( dev );
  862. dev->trans_start = jiffies;
  863. netif_wake_queue( dev );
  864. }
  865. /***************************************************************
  866. * TLan_StartTx
  867. *
  868. * Returns:
  869. * 0 on success, non-zero on failure.
  870. * Parms:
  871. * skb A pointer to the sk_buff containing the
  872. * frame to be sent.
  873. * dev The device to send the data on.
  874. *
  875. * This function adds a frame to the Tx list to be sent
  876. * ASAP. First it verifies that the adapter is ready and
  877. * there is room in the queue. Then it sets up the next
  878. * available list, copies the frame to the corresponding
  879. * buffer. If the adapter Tx channel is idle, it gives
  880. * the adapter a Tx Go command on the list, otherwise it
  881. * sets the forward address of the previous list to point
  882. * to this one. Then it frees the sk_buff.
  883. *
  884. **************************************************************/
  885. static int TLan_StartTx( struct sk_buff *skb, struct net_device *dev )
  886. {
  887. TLanPrivateInfo *priv = netdev_priv(dev);
  888. TLanList *tail_list;
  889. dma_addr_t tail_list_phys;
  890. u8 *tail_buffer;
  891. int pad;
  892. unsigned long flags;
  893. if ( ! priv->phyOnline ) {
  894. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n", dev->name );
  895. dev_kfree_skb_any(skb);
  896. return 0;
  897. }
  898. tail_list = priv->txList + priv->txTail;
  899. tail_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txTail;
  900. if ( tail_list->cStat != TLAN_CSTAT_UNUSED ) {
  901. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s is busy (Head=%d Tail=%d)\n", dev->name, priv->txHead, priv->txTail );
  902. netif_stop_queue(dev);
  903. priv->txBusyCount++;
  904. return 1;
  905. }
  906. tail_list->forward = 0;
  907. if ( bbuf ) {
  908. tail_buffer = priv->txBuffer + ( priv->txTail * TLAN_MAX_FRAME_SIZE );
  909. memcpy( tail_buffer, skb->data, skb->len );
  910. } else {
  911. tail_list->buffer[0].address = pci_map_single(priv->pciDev, skb->data, skb->len, PCI_DMA_TODEVICE);
  912. TLan_StoreSKB(tail_list, skb);
  913. }
  914. pad = TLAN_MIN_FRAME_SIZE - skb->len;
  915. if ( pad > 0 ) {
  916. tail_list->frameSize = (u16) skb->len + pad;
  917. tail_list->buffer[0].count = (u32) skb->len;
  918. tail_list->buffer[1].count = TLAN_LAST_BUFFER | (u32) pad;
  919. tail_list->buffer[1].address = TLanPadBufferDMA;
  920. } else {
  921. tail_list->frameSize = (u16) skb->len;
  922. tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) skb->len;
  923. tail_list->buffer[1].count = 0;
  924. tail_list->buffer[1].address = 0;
  925. }
  926. spin_lock_irqsave(&priv->lock, flags);
  927. tail_list->cStat = TLAN_CSTAT_READY;
  928. if ( ! priv->txInProgress ) {
  929. priv->txInProgress = 1;
  930. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Starting TX on buffer %d\n", priv->txTail );
  931. outl( tail_list_phys, dev->base_addr + TLAN_CH_PARM );
  932. outl( TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD );
  933. } else {
  934. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Adding buffer %d to TX channel\n", priv->txTail );
  935. if ( priv->txTail == 0 ) {
  936. ( priv->txList + ( TLAN_NUM_TX_LISTS - 1 ) )->forward = tail_list_phys;
  937. } else {
  938. ( priv->txList + ( priv->txTail - 1 ) )->forward = tail_list_phys;
  939. }
  940. }
  941. spin_unlock_irqrestore(&priv->lock, flags);
  942. CIRC_INC( priv->txTail, TLAN_NUM_TX_LISTS );
  943. if ( bbuf )
  944. dev_kfree_skb_any(skb);
  945. dev->trans_start = jiffies;
  946. return 0;
  947. } /* TLan_StartTx */
  948. /***************************************************************
  949. * TLan_HandleInterrupt
  950. *
  951. * Returns:
  952. * Nothing
  953. * Parms:
  954. * irq The line on which the interrupt
  955. * occurred.
  956. * dev_id A pointer to the device assigned to
  957. * this irq line.
  958. * regs ???
  959. *
  960. * This function handles an interrupt generated by its
  961. * assigned TLAN adapter. The function deactivates
  962. * interrupts on its adapter, records the type of
  963. * interrupt, executes the appropriate subhandler, and
  964. * acknowdges the interrupt to the adapter (thus
  965. * re-enabling adapter interrupts.
  966. *
  967. **************************************************************/
  968. static irqreturn_t TLan_HandleInterrupt(int irq, void *dev_id, struct pt_regs *regs)
  969. {
  970. u32 ack;
  971. struct net_device *dev;
  972. u32 host_cmd;
  973. u16 host_int;
  974. int type;
  975. TLanPrivateInfo *priv;
  976. dev = dev_id;
  977. priv = netdev_priv(dev);
  978. spin_lock(&priv->lock);
  979. host_int = inw( dev->base_addr + TLAN_HOST_INT );
  980. outw( host_int, dev->base_addr + TLAN_HOST_INT );
  981. type = ( host_int & TLAN_HI_IT_MASK ) >> 2;
  982. ack = TLanIntVector[type]( dev, host_int );
  983. if ( ack ) {
  984. host_cmd = TLAN_HC_ACK | ack | ( type << 18 );
  985. outl( host_cmd, dev->base_addr + TLAN_HOST_CMD );
  986. }
  987. spin_unlock(&priv->lock);
  988. return IRQ_HANDLED;
  989. } /* TLan_HandleInterrupts */
  990. /***************************************************************
  991. * TLan_Close
  992. *
  993. * Returns:
  994. * An error code.
  995. * Parms:
  996. * dev The device structure of the device to
  997. * close.
  998. *
  999. * This function shuts down the adapter. It records any
  1000. * stats, puts the adapter into reset state, deactivates
  1001. * its time as needed, and frees the irq it is using.
  1002. *
  1003. **************************************************************/
  1004. static int TLan_Close(struct net_device *dev)
  1005. {
  1006. TLanPrivateInfo *priv = netdev_priv(dev);
  1007. netif_stop_queue(dev);
  1008. priv->neg_be_verbose = 0;
  1009. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1010. outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
  1011. if ( priv->timer.function != NULL ) {
  1012. del_timer_sync( &priv->timer );
  1013. priv->timer.function = NULL;
  1014. }
  1015. free_irq( dev->irq, dev );
  1016. TLan_FreeLists( dev );
  1017. TLAN_DBG( TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name );
  1018. return 0;
  1019. } /* TLan_Close */
  1020. /***************************************************************
  1021. * TLan_GetStats
  1022. *
  1023. * Returns:
  1024. * A pointer to the device's statistics structure.
  1025. * Parms:
  1026. * dev The device structure to return the
  1027. * stats for.
  1028. *
  1029. * This function updates the devices statistics by reading
  1030. * the TLAN chip's onboard registers. Then it returns the
  1031. * address of the statistics structure.
  1032. *
  1033. **************************************************************/
  1034. static struct net_device_stats *TLan_GetStats( struct net_device *dev )
  1035. {
  1036. TLanPrivateInfo *priv = netdev_priv(dev);
  1037. int i;
  1038. /* Should only read stats if open ? */
  1039. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1040. TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name, priv->rxEocCount );
  1041. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name, priv->txBusyCount );
  1042. if ( debug & TLAN_DEBUG_GNRL ) {
  1043. TLan_PrintDio( dev->base_addr );
  1044. TLan_PhyPrint( dev );
  1045. }
  1046. if ( debug & TLAN_DEBUG_LIST ) {
  1047. for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ )
  1048. TLan_PrintList( priv->rxList + i, "RX", i );
  1049. for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ )
  1050. TLan_PrintList( priv->txList + i, "TX", i );
  1051. }
  1052. return ( &( (TLanPrivateInfo *) netdev_priv(dev) )->stats );
  1053. } /* TLan_GetStats */
  1054. /***************************************************************
  1055. * TLan_SetMulticastList
  1056. *
  1057. * Returns:
  1058. * Nothing
  1059. * Parms:
  1060. * dev The device structure to set the
  1061. * multicast list for.
  1062. *
  1063. * This function sets the TLAN adaptor to various receive
  1064. * modes. If the IFF_PROMISC flag is set, promiscuous
  1065. * mode is acitviated. Otherwise, promiscuous mode is
  1066. * turned off. If the IFF_ALLMULTI flag is set, then
  1067. * the hash table is set to receive all group addresses.
  1068. * Otherwise, the first three multicast addresses are
  1069. * stored in AREG_1-3, and the rest are selected via the
  1070. * hash table, as necessary.
  1071. *
  1072. **************************************************************/
  1073. static void TLan_SetMulticastList( struct net_device *dev )
  1074. {
  1075. struct dev_mc_list *dmi = dev->mc_list;
  1076. u32 hash1 = 0;
  1077. u32 hash2 = 0;
  1078. int i;
  1079. u32 offset;
  1080. u8 tmp;
  1081. if ( dev->flags & IFF_PROMISC ) {
  1082. tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
  1083. TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF );
  1084. } else {
  1085. tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
  1086. TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF );
  1087. if ( dev->flags & IFF_ALLMULTI ) {
  1088. for ( i = 0; i < 3; i++ )
  1089. TLan_SetMac( dev, i + 1, NULL );
  1090. TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, 0xFFFFFFFF );
  1091. TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, 0xFFFFFFFF );
  1092. } else {
  1093. for ( i = 0; i < dev->mc_count; i++ ) {
  1094. if ( i < 3 ) {
  1095. TLan_SetMac( dev, i + 1, (char *) &dmi->dmi_addr );
  1096. } else {
  1097. offset = TLan_HashFunc( (u8 *) &dmi->dmi_addr );
  1098. if ( offset < 32 )
  1099. hash1 |= ( 1 << offset );
  1100. else
  1101. hash2 |= ( 1 << ( offset - 32 ) );
  1102. }
  1103. dmi = dmi->next;
  1104. }
  1105. for ( ; i < 3; i++ )
  1106. TLan_SetMac( dev, i + 1, NULL );
  1107. TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, hash1 );
  1108. TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, hash2 );
  1109. }
  1110. }
  1111. } /* TLan_SetMulticastList */
  1112. /*****************************************************************************
  1113. ******************************************************************************
  1114. ThunderLAN Driver Interrupt Vectors and Table
  1115. Please see Chap. 4, "Interrupt Handling" of the "ThunderLAN
  1116. Programmer's Guide" for more informations on handling interrupts
  1117. generated by TLAN based adapters.
  1118. ******************************************************************************
  1119. *****************************************************************************/
  1120. /***************************************************************
  1121. * TLan_HandleInvalid
  1122. *
  1123. * Returns:
  1124. * 0
  1125. * Parms:
  1126. * dev Device assigned the IRQ that was
  1127. * raised.
  1128. * host_int The contents of the HOST_INT
  1129. * port.
  1130. *
  1131. * This function handles invalid interrupts. This should
  1132. * never happen unless some other adapter is trying to use
  1133. * the IRQ line assigned to the device.
  1134. *
  1135. **************************************************************/
  1136. u32 TLan_HandleInvalid( struct net_device *dev, u16 host_int )
  1137. {
  1138. /* printk( "TLAN: Invalid interrupt on %s.\n", dev->name ); */
  1139. return 0;
  1140. } /* TLan_HandleInvalid */
  1141. /***************************************************************
  1142. * TLan_HandleTxEOF
  1143. *
  1144. * Returns:
  1145. * 1
  1146. * Parms:
  1147. * dev Device assigned the IRQ that was
  1148. * raised.
  1149. * host_int The contents of the HOST_INT
  1150. * port.
  1151. *
  1152. * This function handles Tx EOF interrupts which are raised
  1153. * by the adapter when it has completed sending the
  1154. * contents of a buffer. If detemines which list/buffer
  1155. * was completed and resets it. If the buffer was the last
  1156. * in the channel (EOC), then the function checks to see if
  1157. * another buffer is ready to send, and if so, sends a Tx
  1158. * Go command. Finally, the driver activates/continues the
  1159. * activity LED.
  1160. *
  1161. **************************************************************/
  1162. u32 TLan_HandleTxEOF( struct net_device *dev, u16 host_int )
  1163. {
  1164. TLanPrivateInfo *priv = netdev_priv(dev);
  1165. int eoc = 0;
  1166. TLanList *head_list;
  1167. dma_addr_t head_list_phys;
  1168. u32 ack = 0;
  1169. u16 tmpCStat;
  1170. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n", priv->txHead, priv->txTail );
  1171. head_list = priv->txList + priv->txHead;
  1172. while (((tmpCStat = head_list->cStat ) & TLAN_CSTAT_FRM_CMP) && (ack < 255)) {
  1173. ack++;
  1174. if ( ! bbuf ) {
  1175. struct sk_buff *skb = TLan_GetSKB(head_list);
  1176. pci_unmap_single(priv->pciDev, head_list->buffer[0].address, skb->len, PCI_DMA_TODEVICE);
  1177. dev_kfree_skb_any(skb);
  1178. head_list->buffer[8].address = 0;
  1179. head_list->buffer[9].address = 0;
  1180. }
  1181. if ( tmpCStat & TLAN_CSTAT_EOC )
  1182. eoc = 1;
  1183. priv->stats.tx_bytes += head_list->frameSize;
  1184. head_list->cStat = TLAN_CSTAT_UNUSED;
  1185. netif_start_queue(dev);
  1186. CIRC_INC( priv->txHead, TLAN_NUM_TX_LISTS );
  1187. head_list = priv->txList + priv->txHead;
  1188. }
  1189. if (!ack)
  1190. printk(KERN_INFO "TLAN: Received interrupt for uncompleted TX frame.\n");
  1191. if ( eoc ) {
  1192. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Handling TX EOC (Head=%d Tail=%d)\n", priv->txHead, priv->txTail );
  1193. head_list = priv->txList + priv->txHead;
  1194. head_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txHead;
  1195. if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
  1196. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1197. ack |= TLAN_HC_GO;
  1198. } else {
  1199. priv->txInProgress = 0;
  1200. }
  1201. }
  1202. if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
  1203. TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
  1204. if ( priv->timer.function == NULL ) {
  1205. priv->timer.function = &TLan_Timer;
  1206. priv->timer.data = (unsigned long) dev;
  1207. priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
  1208. priv->timerSetAt = jiffies;
  1209. priv->timerType = TLAN_TIMER_ACTIVITY;
  1210. add_timer(&priv->timer);
  1211. } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
  1212. priv->timerSetAt = jiffies;
  1213. }
  1214. }
  1215. return ack;
  1216. } /* TLan_HandleTxEOF */
  1217. /***************************************************************
  1218. * TLan_HandleStatOverflow
  1219. *
  1220. * Returns:
  1221. * 1
  1222. * Parms:
  1223. * dev Device assigned the IRQ that was
  1224. * raised.
  1225. * host_int The contents of the HOST_INT
  1226. * port.
  1227. *
  1228. * This function handles the Statistics Overflow interrupt
  1229. * which means that one or more of the TLAN statistics
  1230. * registers has reached 1/2 capacity and needs to be read.
  1231. *
  1232. **************************************************************/
  1233. u32 TLan_HandleStatOverflow( struct net_device *dev, u16 host_int )
  1234. {
  1235. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1236. return 1;
  1237. } /* TLan_HandleStatOverflow */
  1238. /***************************************************************
  1239. * TLan_HandleRxEOF
  1240. *
  1241. * Returns:
  1242. * 1
  1243. * Parms:
  1244. * dev Device assigned the IRQ that was
  1245. * raised.
  1246. * host_int The contents of the HOST_INT
  1247. * port.
  1248. *
  1249. * This function handles the Rx EOF interrupt which
  1250. * indicates a frame has been received by the adapter from
  1251. * the net and the frame has been transferred to memory.
  1252. * The function determines the bounce buffer the frame has
  1253. * been loaded into, creates a new sk_buff big enough to
  1254. * hold the frame, and sends it to protocol stack. It
  1255. * then resets the used buffer and appends it to the end
  1256. * of the list. If the frame was the last in the Rx
  1257. * channel (EOC), the function restarts the receive channel
  1258. * by sending an Rx Go command to the adapter. Then it
  1259. * activates/continues the activity LED.
  1260. *
  1261. **************************************************************/
  1262. u32 TLan_HandleRxEOF( struct net_device *dev, u16 host_int )
  1263. {
  1264. TLanPrivateInfo *priv = netdev_priv(dev);
  1265. u32 ack = 0;
  1266. int eoc = 0;
  1267. u8 *head_buffer;
  1268. TLanList *head_list;
  1269. struct sk_buff *skb;
  1270. TLanList *tail_list;
  1271. void *t;
  1272. u32 frameSize;
  1273. u16 tmpCStat;
  1274. dma_addr_t head_list_phys;
  1275. TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: Handling RX EOF (Head=%d Tail=%d)\n", priv->rxHead, priv->rxTail );
  1276. head_list = priv->rxList + priv->rxHead;
  1277. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1278. while (((tmpCStat = head_list->cStat) & TLAN_CSTAT_FRM_CMP) && (ack < 255)) {
  1279. frameSize = head_list->frameSize;
  1280. ack++;
  1281. if (tmpCStat & TLAN_CSTAT_EOC)
  1282. eoc = 1;
  1283. if (bbuf) {
  1284. skb = dev_alloc_skb(frameSize + 7);
  1285. if (skb == NULL)
  1286. printk(KERN_INFO "TLAN: Couldn't allocate memory for received data.\n");
  1287. else {
  1288. head_buffer = priv->rxBuffer + (priv->rxHead * TLAN_MAX_FRAME_SIZE);
  1289. skb->dev = dev;
  1290. skb_reserve(skb, 2);
  1291. t = (void *) skb_put(skb, frameSize);
  1292. priv->stats.rx_bytes += head_list->frameSize;
  1293. memcpy( t, head_buffer, frameSize );
  1294. skb->protocol = eth_type_trans( skb, dev );
  1295. netif_rx( skb );
  1296. }
  1297. } else {
  1298. struct sk_buff *new_skb;
  1299. /*
  1300. * I changed the algorithm here. What we now do
  1301. * is allocate the new frame. If this fails we
  1302. * simply recycle the frame.
  1303. */
  1304. new_skb = dev_alloc_skb( TLAN_MAX_FRAME_SIZE + 7 );
  1305. if ( new_skb != NULL ) {
  1306. skb = TLan_GetSKB(head_list);
  1307. pci_unmap_single(priv->pciDev, head_list->buffer[0].address, TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
  1308. skb_trim( skb, frameSize );
  1309. priv->stats.rx_bytes += frameSize;
  1310. skb->protocol = eth_type_trans( skb, dev );
  1311. netif_rx( skb );
  1312. new_skb->dev = dev;
  1313. skb_reserve( new_skb, 2 );
  1314. t = (void *) skb_put( new_skb, TLAN_MAX_FRAME_SIZE );
  1315. head_list->buffer[0].address = pci_map_single(priv->pciDev, new_skb->data, TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
  1316. head_list->buffer[8].address = (u32) t;
  1317. TLan_StoreSKB(head_list, new_skb);
  1318. } else
  1319. printk(KERN_WARNING "TLAN: Couldn't allocate memory for received data.\n" );
  1320. }
  1321. head_list->forward = 0;
  1322. head_list->cStat = 0;
  1323. tail_list = priv->rxList + priv->rxTail;
  1324. tail_list->forward = head_list_phys;
  1325. CIRC_INC( priv->rxHead, TLAN_NUM_RX_LISTS );
  1326. CIRC_INC( priv->rxTail, TLAN_NUM_RX_LISTS );
  1327. head_list = priv->rxList + priv->rxHead;
  1328. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1329. }
  1330. if (!ack)
  1331. printk(KERN_INFO "TLAN: Received interrupt for uncompleted RX frame.\n");
  1332. if ( eoc ) {
  1333. TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: Handling RX EOC (Head=%d Tail=%d)\n", priv->rxHead, priv->rxTail );
  1334. head_list = priv->rxList + priv->rxHead;
  1335. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1336. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1337. ack |= TLAN_HC_GO | TLAN_HC_RT;
  1338. priv->rxEocCount++;
  1339. }
  1340. if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
  1341. TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
  1342. if ( priv->timer.function == NULL ) {
  1343. priv->timer.function = &TLan_Timer;
  1344. priv->timer.data = (unsigned long) dev;
  1345. priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
  1346. priv->timerSetAt = jiffies;
  1347. priv->timerType = TLAN_TIMER_ACTIVITY;
  1348. add_timer(&priv->timer);
  1349. } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
  1350. priv->timerSetAt = jiffies;
  1351. }
  1352. }
  1353. dev->last_rx = jiffies;
  1354. return ack;
  1355. } /* TLan_HandleRxEOF */
  1356. /***************************************************************
  1357. * TLan_HandleDummy
  1358. *
  1359. * Returns:
  1360. * 1
  1361. * Parms:
  1362. * dev Device assigned the IRQ that was
  1363. * raised.
  1364. * host_int The contents of the HOST_INT
  1365. * port.
  1366. *
  1367. * This function handles the Dummy interrupt, which is
  1368. * raised whenever a test interrupt is generated by setting
  1369. * the Req_Int bit of HOST_CMD to 1.
  1370. *
  1371. **************************************************************/
  1372. u32 TLan_HandleDummy( struct net_device *dev, u16 host_int )
  1373. {
  1374. printk( "TLAN: Test interrupt on %s.\n", dev->name );
  1375. return 1;
  1376. } /* TLan_HandleDummy */
  1377. /***************************************************************
  1378. * TLan_HandleTxEOC
  1379. *
  1380. * Returns:
  1381. * 1
  1382. * Parms:
  1383. * dev Device assigned the IRQ that was
  1384. * raised.
  1385. * host_int The contents of the HOST_INT
  1386. * port.
  1387. *
  1388. * This driver is structured to determine EOC occurrences by
  1389. * reading the CSTAT member of the list structure. Tx EOC
  1390. * interrupts are disabled via the DIO INTDIS register.
  1391. * However, TLAN chips before revision 3.0 didn't have this
  1392. * functionality, so process EOC events if this is the
  1393. * case.
  1394. *
  1395. **************************************************************/
  1396. u32 TLan_HandleTxEOC( struct net_device *dev, u16 host_int )
  1397. {
  1398. TLanPrivateInfo *priv = netdev_priv(dev);
  1399. TLanList *head_list;
  1400. dma_addr_t head_list_phys;
  1401. u32 ack = 1;
  1402. host_int = 0;
  1403. if ( priv->tlanRev < 0x30 ) {
  1404. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Handling TX EOC (Head=%d Tail=%d) -- IRQ\n", priv->txHead, priv->txTail );
  1405. head_list = priv->txList + priv->txHead;
  1406. head_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txHead;
  1407. if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
  1408. netif_stop_queue(dev);
  1409. outl( head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1410. ack |= TLAN_HC_GO;
  1411. } else {
  1412. priv->txInProgress = 0;
  1413. }
  1414. }
  1415. return ack;
  1416. } /* TLan_HandleTxEOC */
  1417. /***************************************************************
  1418. * TLan_HandleStatusCheck
  1419. *
  1420. * Returns:
  1421. * 0 if Adapter check, 1 if Network Status check.
  1422. * Parms:
  1423. * dev Device assigned the IRQ that was
  1424. * raised.
  1425. * host_int The contents of the HOST_INT
  1426. * port.
  1427. *
  1428. * This function handles Adapter Check/Network Status
  1429. * interrupts generated by the adapter. It checks the
  1430. * vector in the HOST_INT register to determine if it is
  1431. * an Adapter Check interrupt. If so, it resets the
  1432. * adapter. Otherwise it clears the status registers
  1433. * and services the PHY.
  1434. *
  1435. **************************************************************/
  1436. u32 TLan_HandleStatusCheck( struct net_device *dev, u16 host_int )
  1437. {
  1438. TLanPrivateInfo *priv = netdev_priv(dev);
  1439. u32 ack;
  1440. u32 error;
  1441. u8 net_sts;
  1442. u32 phy;
  1443. u16 tlphy_ctl;
  1444. u16 tlphy_sts;
  1445. ack = 1;
  1446. if ( host_int & TLAN_HI_IV_MASK ) {
  1447. netif_stop_queue( dev );
  1448. error = inl( dev->base_addr + TLAN_CH_PARM );
  1449. printk( "TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error );
  1450. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1451. outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
  1452. schedule_work(&priv->tlan_tqueue);
  1453. netif_wake_queue(dev);
  1454. ack = 0;
  1455. } else {
  1456. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name );
  1457. phy = priv->phy[priv->phyNum];
  1458. net_sts = TLan_DioRead8( dev->base_addr, TLAN_NET_STS );
  1459. if ( net_sts ) {
  1460. TLan_DioWrite8( dev->base_addr, TLAN_NET_STS, net_sts );
  1461. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n", dev->name, (unsigned) net_sts );
  1462. }
  1463. if ( ( net_sts & TLAN_NET_STS_MIRQ ) && ( priv->phyNum == 0 ) ) {
  1464. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_STS, &tlphy_sts );
  1465. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
  1466. if ( ! ( tlphy_sts & TLAN_TS_POLOK ) && ! ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
  1467. tlphy_ctl |= TLAN_TC_SWAPOL;
  1468. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
  1469. } else if ( ( tlphy_sts & TLAN_TS_POLOK ) && ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
  1470. tlphy_ctl &= ~TLAN_TC_SWAPOL;
  1471. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
  1472. }
  1473. if (debug) {
  1474. TLan_PhyPrint( dev );
  1475. }
  1476. }
  1477. }
  1478. return ack;
  1479. } /* TLan_HandleStatusCheck */
  1480. /***************************************************************
  1481. * TLan_HandleRxEOC
  1482. *
  1483. * Returns:
  1484. * 1
  1485. * Parms:
  1486. * dev Device assigned the IRQ that was
  1487. * raised.
  1488. * host_int The contents of the HOST_INT
  1489. * port.
  1490. *
  1491. * This driver is structured to determine EOC occurrences by
  1492. * reading the CSTAT member of the list structure. Rx EOC
  1493. * interrupts are disabled via the DIO INTDIS register.
  1494. * However, TLAN chips before revision 3.0 didn't have this
  1495. * CSTAT member or a INTDIS register, so if this chip is
  1496. * pre-3.0, process EOC interrupts normally.
  1497. *
  1498. **************************************************************/
  1499. u32 TLan_HandleRxEOC( struct net_device *dev, u16 host_int )
  1500. {
  1501. TLanPrivateInfo *priv = netdev_priv(dev);
  1502. dma_addr_t head_list_phys;
  1503. u32 ack = 1;
  1504. if ( priv->tlanRev < 0x30 ) {
  1505. TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: Handling RX EOC (Head=%d Tail=%d) -- IRQ\n", priv->rxHead, priv->rxTail );
  1506. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1507. outl( head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1508. ack |= TLAN_HC_GO | TLAN_HC_RT;
  1509. priv->rxEocCount++;
  1510. }
  1511. return ack;
  1512. } /* TLan_HandleRxEOC */
  1513. /*****************************************************************************
  1514. ******************************************************************************
  1515. ThunderLAN Driver Timer Function
  1516. ******************************************************************************
  1517. *****************************************************************************/
  1518. /***************************************************************
  1519. * TLan_Timer
  1520. *
  1521. * Returns:
  1522. * Nothing
  1523. * Parms:
  1524. * data A value given to add timer when
  1525. * add_timer was called.
  1526. *
  1527. * This function handles timed functionality for the
  1528. * TLAN driver. The two current timer uses are for
  1529. * delaying for autonegotionation and driving the ACT LED.
  1530. * - Autonegotiation requires being allowed about
  1531. * 2 1/2 seconds before attempting to transmit a
  1532. * packet. It would be a very bad thing to hang
  1533. * the kernel this long, so the driver doesn't
  1534. * allow transmission 'til after this time, for
  1535. * certain PHYs. It would be much nicer if all
  1536. * PHYs were interrupt-capable like the internal
  1537. * PHY.
  1538. * - The ACT LED, which shows adapter activity, is
  1539. * driven by the driver, and so must be left on
  1540. * for a short period to power up the LED so it
  1541. * can be seen. This delay can be changed by
  1542. * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
  1543. * if desired. 100 ms produces a slightly
  1544. * sluggish response.
  1545. *
  1546. **************************************************************/
  1547. void TLan_Timer( unsigned long data )
  1548. {
  1549. struct net_device *dev = (struct net_device *) data;
  1550. TLanPrivateInfo *priv = netdev_priv(dev);
  1551. u32 elapsed;
  1552. unsigned long flags = 0;
  1553. priv->timer.function = NULL;
  1554. switch ( priv->timerType ) {
  1555. #ifdef MONITOR
  1556. case TLAN_TIMER_LINK_BEAT:
  1557. TLan_PhyMonitor( dev );
  1558. break;
  1559. #endif
  1560. case TLAN_TIMER_PHY_PDOWN:
  1561. TLan_PhyPowerDown( dev );
  1562. break;
  1563. case TLAN_TIMER_PHY_PUP:
  1564. TLan_PhyPowerUp( dev );
  1565. break;
  1566. case TLAN_TIMER_PHY_RESET:
  1567. TLan_PhyReset( dev );
  1568. break;
  1569. case TLAN_TIMER_PHY_START_LINK:
  1570. TLan_PhyStartLink( dev );
  1571. break;
  1572. case TLAN_TIMER_PHY_FINISH_AN:
  1573. TLan_PhyFinishAutoNeg( dev );
  1574. break;
  1575. case TLAN_TIMER_FINISH_RESET:
  1576. TLan_FinishReset( dev );
  1577. break;
  1578. case TLAN_TIMER_ACTIVITY:
  1579. spin_lock_irqsave(&priv->lock, flags);
  1580. if ( priv->timer.function == NULL ) {
  1581. elapsed = jiffies - priv->timerSetAt;
  1582. if ( elapsed >= TLAN_TIMER_ACT_DELAY ) {
  1583. TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
  1584. } else {
  1585. priv->timer.function = &TLan_Timer;
  1586. priv->timer.expires = priv->timerSetAt + TLAN_TIMER_ACT_DELAY;
  1587. spin_unlock_irqrestore(&priv->lock, flags);
  1588. add_timer( &priv->timer );
  1589. break;
  1590. }
  1591. }
  1592. spin_unlock_irqrestore(&priv->lock, flags);
  1593. break;
  1594. default:
  1595. break;
  1596. }
  1597. } /* TLan_Timer */
  1598. /*****************************************************************************
  1599. ******************************************************************************
  1600. ThunderLAN Driver Adapter Related Routines
  1601. ******************************************************************************
  1602. *****************************************************************************/
  1603. /***************************************************************
  1604. * TLan_ResetLists
  1605. *
  1606. * Returns:
  1607. * Nothing
  1608. * Parms:
  1609. * dev The device structure with the list
  1610. * stuctures to be reset.
  1611. *
  1612. * This routine sets the variables associated with managing
  1613. * the TLAN lists to their initial values.
  1614. *
  1615. **************************************************************/
  1616. void TLan_ResetLists( struct net_device *dev )
  1617. {
  1618. TLanPrivateInfo *priv = netdev_priv(dev);
  1619. int i;
  1620. TLanList *list;
  1621. dma_addr_t list_phys;
  1622. struct sk_buff *skb;
  1623. void *t = NULL;
  1624. priv->txHead = 0;
  1625. priv->txTail = 0;
  1626. for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
  1627. list = priv->txList + i;
  1628. list->cStat = TLAN_CSTAT_UNUSED;
  1629. if ( bbuf ) {
  1630. list->buffer[0].address = priv->txBufferDMA + ( i * TLAN_MAX_FRAME_SIZE );
  1631. } else {
  1632. list->buffer[0].address = 0;
  1633. }
  1634. list->buffer[2].count = 0;
  1635. list->buffer[2].address = 0;
  1636. list->buffer[8].address = 0;
  1637. list->buffer[9].address = 0;
  1638. }
  1639. priv->rxHead = 0;
  1640. priv->rxTail = TLAN_NUM_RX_LISTS - 1;
  1641. for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
  1642. list = priv->rxList + i;
  1643. list_phys = priv->rxListDMA + sizeof(TLanList) * i;
  1644. list->cStat = TLAN_CSTAT_READY;
  1645. list->frameSize = TLAN_MAX_FRAME_SIZE;
  1646. list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
  1647. if ( bbuf ) {
  1648. list->buffer[0].address = priv->rxBufferDMA + ( i * TLAN_MAX_FRAME_SIZE );
  1649. } else {
  1650. skb = dev_alloc_skb( TLAN_MAX_FRAME_SIZE + 7 );
  1651. if ( skb == NULL ) {
  1652. printk( "TLAN: Couldn't allocate memory for received data.\n" );
  1653. /* If this ever happened it would be a problem */
  1654. } else {
  1655. skb->dev = dev;
  1656. skb_reserve( skb, 2 );
  1657. t = (void *) skb_put( skb, TLAN_MAX_FRAME_SIZE );
  1658. }
  1659. list->buffer[0].address = pci_map_single(priv->pciDev, t, TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
  1660. list->buffer[8].address = (u32) t;
  1661. TLan_StoreSKB(list, skb);
  1662. }
  1663. list->buffer[1].count = 0;
  1664. list->buffer[1].address = 0;
  1665. if ( i < TLAN_NUM_RX_LISTS - 1 )
  1666. list->forward = list_phys + sizeof(TLanList);
  1667. else
  1668. list->forward = 0;
  1669. }
  1670. } /* TLan_ResetLists */
  1671. void TLan_FreeLists( struct net_device *dev )
  1672. {
  1673. TLanPrivateInfo *priv = netdev_priv(dev);
  1674. int i;
  1675. TLanList *list;
  1676. struct sk_buff *skb;
  1677. if ( ! bbuf ) {
  1678. for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
  1679. list = priv->txList + i;
  1680. skb = TLan_GetSKB(list);
  1681. if ( skb ) {
  1682. pci_unmap_single(priv->pciDev, list->buffer[0].address, skb->len, PCI_DMA_TODEVICE);
  1683. dev_kfree_skb_any( skb );
  1684. list->buffer[8].address = 0;
  1685. list->buffer[9].address = 0;
  1686. }
  1687. }
  1688. for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
  1689. list = priv->rxList + i;
  1690. skb = TLan_GetSKB(list);
  1691. if ( skb ) {
  1692. pci_unmap_single(priv->pciDev, list->buffer[0].address, TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
  1693. dev_kfree_skb_any( skb );
  1694. list->buffer[8].address = 0;
  1695. list->buffer[9].address = 0;
  1696. }
  1697. }
  1698. }
  1699. } /* TLan_FreeLists */
  1700. /***************************************************************
  1701. * TLan_PrintDio
  1702. *
  1703. * Returns:
  1704. * Nothing
  1705. * Parms:
  1706. * io_base Base IO port of the device of
  1707. * which to print DIO registers.
  1708. *
  1709. * This function prints out all the internal (DIO)
  1710. * registers of a TLAN chip.
  1711. *
  1712. **************************************************************/
  1713. void TLan_PrintDio( u16 io_base )
  1714. {
  1715. u32 data0, data1;
  1716. int i;
  1717. printk( "TLAN: Contents of internal registers for io base 0x%04hx.\n", io_base );
  1718. printk( "TLAN: Off. +0 +4\n" );
  1719. for ( i = 0; i < 0x4C; i+= 8 ) {
  1720. data0 = TLan_DioRead32( io_base, i );
  1721. data1 = TLan_DioRead32( io_base, i + 0x4 );
  1722. printk( "TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1 );
  1723. }
  1724. } /* TLan_PrintDio */
  1725. /***************************************************************
  1726. * TLan_PrintList
  1727. *
  1728. * Returns:
  1729. * Nothing
  1730. * Parms:
  1731. * list A pointer to the TLanList structure to
  1732. * be printed.
  1733. * type A string to designate type of list,
  1734. * "Rx" or "Tx".
  1735. * num The index of the list.
  1736. *
  1737. * This function prints out the contents of the list
  1738. * pointed to by the list parameter.
  1739. *
  1740. **************************************************************/
  1741. void TLan_PrintList( TLanList *list, char *type, int num)
  1742. {
  1743. int i;
  1744. printk( "TLAN: %s List %d at 0x%08x\n", type, num, (u32) list );
  1745. printk( "TLAN: Forward = 0x%08x\n", list->forward );
  1746. printk( "TLAN: CSTAT = 0x%04hx\n", list->cStat );
  1747. printk( "TLAN: Frame Size = 0x%04hx\n", list->frameSize );
  1748. /* for ( i = 0; i < 10; i++ ) { */
  1749. for ( i = 0; i < 2; i++ ) {
  1750. printk( "TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n", i, list->buffer[i].count, list->buffer[i].address );
  1751. }
  1752. } /* TLan_PrintList */
  1753. /***************************************************************
  1754. * TLan_ReadAndClearStats
  1755. *
  1756. * Returns:
  1757. * Nothing
  1758. * Parms:
  1759. * dev Pointer to device structure of adapter
  1760. * to which to read stats.
  1761. * record Flag indicating whether to add
  1762. *
  1763. * This functions reads all the internal status registers
  1764. * of the TLAN chip, which clears them as a side effect.
  1765. * It then either adds the values to the device's status
  1766. * struct, or discards them, depending on whether record
  1767. * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
  1768. *
  1769. **************************************************************/
  1770. void TLan_ReadAndClearStats( struct net_device *dev, int record )
  1771. {
  1772. TLanPrivateInfo *priv = netdev_priv(dev);
  1773. u32 tx_good, tx_under;
  1774. u32 rx_good, rx_over;
  1775. u32 def_tx, crc, code;
  1776. u32 multi_col, single_col;
  1777. u32 excess_col, late_col, loss;
  1778. outw( TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1779. tx_good = inb( dev->base_addr + TLAN_DIO_DATA );
  1780. tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1781. tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
  1782. tx_under = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
  1783. outw( TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1784. rx_good = inb( dev->base_addr + TLAN_DIO_DATA );
  1785. rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1786. rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
  1787. rx_over = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
  1788. outw( TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR );
  1789. def_tx = inb( dev->base_addr + TLAN_DIO_DATA );
  1790. def_tx += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1791. crc = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
  1792. code = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
  1793. outw( TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1794. multi_col = inb( dev->base_addr + TLAN_DIO_DATA );
  1795. multi_col += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1796. single_col = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
  1797. single_col += inb( dev->base_addr + TLAN_DIO_DATA + 3 ) << 8;
  1798. outw( TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1799. excess_col = inb( dev->base_addr + TLAN_DIO_DATA );
  1800. late_col = inb( dev->base_addr + TLAN_DIO_DATA + 1 );
  1801. loss = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
  1802. if ( record ) {
  1803. priv->stats.rx_packets += rx_good;
  1804. priv->stats.rx_errors += rx_over + crc + code;
  1805. priv->stats.tx_packets += tx_good;
  1806. priv->stats.tx_errors += tx_under + loss;
  1807. priv->stats.collisions += multi_col + single_col + excess_col + late_col;
  1808. priv->stats.rx_over_errors += rx_over;
  1809. priv->stats.rx_crc_errors += crc;
  1810. priv->stats.rx_frame_errors += code;
  1811. priv->stats.tx_aborted_errors += tx_under;
  1812. priv->stats.tx_carrier_errors += loss;
  1813. }
  1814. } /* TLan_ReadAndClearStats */
  1815. /***************************************************************
  1816. * TLan_Reset
  1817. *
  1818. * Returns:
  1819. * 0
  1820. * Parms:
  1821. * dev Pointer to device structure of adapter
  1822. * to be reset.
  1823. *
  1824. * This function resets the adapter and it's physical
  1825. * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
  1826. * Programmer's Guide" for details. The routine tries to
  1827. * implement what is detailed there, though adjustments
  1828. * have been made.
  1829. *
  1830. **************************************************************/
  1831. void
  1832. TLan_ResetAdapter( struct net_device *dev )
  1833. {
  1834. TLanPrivateInfo *priv = netdev_priv(dev);
  1835. int i;
  1836. u32 addr;
  1837. u32 data;
  1838. u8 data8;
  1839. priv->tlanFullDuplex = FALSE;
  1840. priv->phyOnline=0;
  1841. netif_carrier_off(dev);
  1842. /* 1. Assert reset bit. */
  1843. data = inl(dev->base_addr + TLAN_HOST_CMD);
  1844. data |= TLAN_HC_AD_RST;
  1845. outl(data, dev->base_addr + TLAN_HOST_CMD);
  1846. udelay(1000);
  1847. /* 2. Turn off interrupts. ( Probably isn't necessary ) */
  1848. data = inl(dev->base_addr + TLAN_HOST_CMD);
  1849. data |= TLAN_HC_INT_OFF;
  1850. outl(data, dev->base_addr + TLAN_HOST_CMD);
  1851. /* 3. Clear AREGs and HASHs. */
  1852. for ( i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4 ) {
  1853. TLan_DioWrite32( dev->base_addr, (u16) i, 0 );
  1854. }
  1855. /* 4. Setup NetConfig register. */
  1856. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  1857. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
  1858. /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
  1859. outl( TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD );
  1860. outl( TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD );
  1861. /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
  1862. outw( TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR );
  1863. addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  1864. TLan_SetBit( TLAN_NET_SIO_NMRST, addr );
  1865. /* 7. Setup the remaining registers. */
  1866. if ( priv->tlanRev >= 0x30 ) {
  1867. data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
  1868. TLan_DioWrite8( dev->base_addr, TLAN_INT_DIS, data8 );
  1869. }
  1870. TLan_PhyDetect( dev );
  1871. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
  1872. if ( priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY ) {
  1873. data |= TLAN_NET_CFG_BIT;
  1874. if ( priv->aui == 1 ) {
  1875. TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x0a );
  1876. } else if ( priv->duplex == TLAN_DUPLEX_FULL ) {
  1877. TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x00 );
  1878. priv->tlanFullDuplex = TRUE;
  1879. } else {
  1880. TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x08 );
  1881. }
  1882. }
  1883. if ( priv->phyNum == 0 ) {
  1884. data |= TLAN_NET_CFG_PHY_EN;
  1885. }
  1886. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
  1887. if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
  1888. TLan_FinishReset( dev );
  1889. } else {
  1890. TLan_PhyPowerDown( dev );
  1891. }
  1892. } /* TLan_ResetAdapter */
  1893. void
  1894. TLan_FinishReset( struct net_device *dev )
  1895. {
  1896. TLanPrivateInfo *priv = netdev_priv(dev);
  1897. u8 data;
  1898. u32 phy;
  1899. u8 sio;
  1900. u16 status;
  1901. u16 partner;
  1902. u16 tlphy_ctl;
  1903. u16 tlphy_par;
  1904. u16 tlphy_id1, tlphy_id2;
  1905. int i;
  1906. phy = priv->phy[priv->phyNum];
  1907. data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
  1908. if ( priv->tlanFullDuplex ) {
  1909. data |= TLAN_NET_CMD_DUPLEX;
  1910. }
  1911. TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, data );
  1912. data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
  1913. if ( priv->phyNum == 0 ) {
  1914. data |= TLAN_NET_MASK_MASK7;
  1915. }
  1916. TLan_DioWrite8( dev->base_addr, TLAN_NET_MASK, data );
  1917. TLan_DioWrite16( dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7 );
  1918. TLan_MiiReadReg( dev, phy, MII_GEN_ID_HI, &tlphy_id1 );
  1919. TLan_MiiReadReg( dev, phy, MII_GEN_ID_LO, &tlphy_id2 );
  1920. if ( ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) || ( priv->aui ) ) {
  1921. status = MII_GS_LINK;
  1922. printk( "TLAN: %s: Link forced.\n", dev->name );
  1923. } else {
  1924. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  1925. udelay( 1000 );
  1926. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  1927. if ( (status & MII_GS_LINK) && /* We only support link info on Nat.Sem. PHY's */
  1928. (tlphy_id1 == NAT_SEM_ID1) &&
  1929. (tlphy_id2 == NAT_SEM_ID2) ) {
  1930. TLan_MiiReadReg( dev, phy, MII_AN_LPA, &partner );
  1931. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_PAR, &tlphy_par );
  1932. printk( "TLAN: %s: Link active with ", dev->name );
  1933. if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
  1934. printk( "forced 10%sMbps %s-Duplex\n",
  1935. tlphy_par & TLAN_PHY_SPEED_100 ? "" : "0",
  1936. tlphy_par & TLAN_PHY_DUPLEX_FULL ? "Full" : "Half");
  1937. } else {
  1938. printk( "AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
  1939. tlphy_par & TLAN_PHY_SPEED_100 ? "" : "0",
  1940. tlphy_par & TLAN_PHY_DUPLEX_FULL ? "Full" : "Half");
  1941. printk("TLAN: Partner capability: ");
  1942. for (i = 5; i <= 10; i++)
  1943. if (partner & (1<<i))
  1944. printk("%s",media[i-5]);
  1945. printk("\n");
  1946. }
  1947. TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
  1948. #ifdef MONITOR
  1949. /* We have link beat..for now anyway */
  1950. priv->link = 1;
  1951. /*Enabling link beat monitoring */
  1952. TLan_SetTimer( dev, (10*HZ), TLAN_TIMER_LINK_BEAT );
  1953. #endif
  1954. } else if (status & MII_GS_LINK) {
  1955. printk( "TLAN: %s: Link active\n", dev->name );
  1956. TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
  1957. }
  1958. }
  1959. if ( priv->phyNum == 0 ) {
  1960. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
  1961. tlphy_ctl |= TLAN_TC_INTEN;
  1962. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl );
  1963. sio = TLan_DioRead8( dev->base_addr, TLAN_NET_SIO );
  1964. sio |= TLAN_NET_SIO_MINTEN;
  1965. TLan_DioWrite8( dev->base_addr, TLAN_NET_SIO, sio );
  1966. }
  1967. if ( status & MII_GS_LINK ) {
  1968. TLan_SetMac( dev, 0, dev->dev_addr );
  1969. priv->phyOnline = 1;
  1970. outb( ( TLAN_HC_INT_ON >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
  1971. if ( debug >= 1 && debug != TLAN_DEBUG_PROBE ) {
  1972. outb( ( TLAN_HC_REQ_INT >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
  1973. }
  1974. outl( priv->rxListDMA, dev->base_addr + TLAN_CH_PARM );
  1975. outl( TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD );
  1976. netif_carrier_on(dev);
  1977. } else {
  1978. printk( "TLAN: %s: Link inactive, will retry in 10 secs...\n", dev->name );
  1979. TLan_SetTimer( dev, (10*HZ), TLAN_TIMER_FINISH_RESET );
  1980. return;
  1981. }
  1982. } /* TLan_FinishReset */
  1983. /***************************************************************
  1984. * TLan_SetMac
  1985. *
  1986. * Returns:
  1987. * Nothing
  1988. * Parms:
  1989. * dev Pointer to device structure of adapter
  1990. * on which to change the AREG.
  1991. * areg The AREG to set the address in (0 - 3).
  1992. * mac A pointer to an array of chars. Each
  1993. * element stores one byte of the address.
  1994. * IE, it isn't in ascii.
  1995. *
  1996. * This function transfers a MAC address to one of the
  1997. * TLAN AREGs (address registers). The TLAN chip locks
  1998. * the register on writing to offset 0 and unlocks the
  1999. * register after writing to offset 5. If NULL is passed
  2000. * in mac, then the AREG is filled with 0's.
  2001. *
  2002. **************************************************************/
  2003. void TLan_SetMac( struct net_device *dev, int areg, char *mac )
  2004. {
  2005. int i;
  2006. areg *= 6;
  2007. if ( mac != NULL ) {
  2008. for ( i = 0; i < 6; i++ )
  2009. TLan_DioWrite8( dev->base_addr, TLAN_AREG_0 + areg + i, mac[i] );
  2010. } else {
  2011. for ( i = 0; i < 6; i++ )
  2012. TLan_DioWrite8( dev->base_addr, TLAN_AREG_0 + areg + i, 0 );
  2013. }
  2014. } /* TLan_SetMac */
  2015. /*****************************************************************************
  2016. ******************************************************************************
  2017. ThunderLAN Driver PHY Layer Routines
  2018. ******************************************************************************
  2019. *****************************************************************************/
  2020. /*********************************************************************
  2021. * TLan_PhyPrint
  2022. *
  2023. * Returns:
  2024. * Nothing
  2025. * Parms:
  2026. * dev A pointer to the device structure of the
  2027. * TLAN device having the PHYs to be detailed.
  2028. *
  2029. * This function prints the registers a PHY (aka transceiver).
  2030. *
  2031. ********************************************************************/
  2032. void TLan_PhyPrint( struct net_device *dev )
  2033. {
  2034. TLanPrivateInfo *priv = netdev_priv(dev);
  2035. u16 i, data0, data1, data2, data3, phy;
  2036. phy = priv->phy[priv->phyNum];
  2037. if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
  2038. printk( "TLAN: Device %s, Unmanaged PHY.\n", dev->name );
  2039. } else if ( phy <= TLAN_PHY_MAX_ADDR ) {
  2040. printk( "TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy );
  2041. printk( "TLAN: Off. +0 +1 +2 +3 \n" );
  2042. for ( i = 0; i < 0x20; i+= 4 ) {
  2043. printk( "TLAN: 0x%02x", i );
  2044. TLan_MiiReadReg( dev, phy, i, &data0 );
  2045. printk( " 0x%04hx", data0 );
  2046. TLan_MiiReadReg( dev, phy, i + 1, &data1 );
  2047. printk( " 0x%04hx", data1 );
  2048. TLan_MiiReadReg( dev, phy, i + 2, &data2 );
  2049. printk( " 0x%04hx", data2 );
  2050. TLan_MiiReadReg( dev, phy, i + 3, &data3 );
  2051. printk( " 0x%04hx\n", data3 );
  2052. }
  2053. } else {
  2054. printk( "TLAN: Device %s, Invalid PHY.\n", dev->name );
  2055. }
  2056. } /* TLan_PhyPrint */
  2057. /*********************************************************************
  2058. * TLan_PhyDetect
  2059. *
  2060. * Returns:
  2061. * Nothing
  2062. * Parms:
  2063. * dev A pointer to the device structure of the adapter
  2064. * for which the PHY needs determined.
  2065. *
  2066. * So far I've found that adapters which have external PHYs
  2067. * may also use the internal PHY for part of the functionality.
  2068. * (eg, AUI/Thinnet). This function finds out if this TLAN
  2069. * chip has an internal PHY, and then finds the first external
  2070. * PHY (starting from address 0) if it exists).
  2071. *
  2072. ********************************************************************/
  2073. void TLan_PhyDetect( struct net_device *dev )
  2074. {
  2075. TLanPrivateInfo *priv = netdev_priv(dev);
  2076. u16 control;
  2077. u16 hi;
  2078. u16 lo;
  2079. u32 phy;
  2080. if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
  2081. priv->phyNum = 0xFFFF;
  2082. return;
  2083. }
  2084. TLan_MiiReadReg( dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi );
  2085. if ( hi != 0xFFFF ) {
  2086. priv->phy[0] = TLAN_PHY_MAX_ADDR;
  2087. } else {
  2088. priv->phy[0] = TLAN_PHY_NONE;
  2089. }
  2090. priv->phy[1] = TLAN_PHY_NONE;
  2091. for ( phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++ ) {
  2092. TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &control );
  2093. TLan_MiiReadReg( dev, phy, MII_GEN_ID_HI, &hi );
  2094. TLan_MiiReadReg( dev, phy, MII_GEN_ID_LO, &lo );
  2095. if ( ( control != 0xFFFF ) || ( hi != 0xFFFF ) || ( lo != 0xFFFF ) ) {
  2096. TLAN_DBG( TLAN_DEBUG_GNRL, "PHY found at %02x %04x %04x %04x\n", phy, control, hi, lo );
  2097. if ( ( priv->phy[1] == TLAN_PHY_NONE ) && ( phy != TLAN_PHY_MAX_ADDR ) ) {
  2098. priv->phy[1] = phy;
  2099. }
  2100. }
  2101. }
  2102. if ( priv->phy[1] != TLAN_PHY_NONE ) {
  2103. priv->phyNum = 1;
  2104. } else if ( priv->phy[0] != TLAN_PHY_NONE ) {
  2105. priv->phyNum = 0;
  2106. } else {
  2107. printk( "TLAN: Cannot initialize device, no PHY was found!\n" );
  2108. }
  2109. } /* TLan_PhyDetect */
  2110. void TLan_PhyPowerDown( struct net_device *dev )
  2111. {
  2112. TLanPrivateInfo *priv = netdev_priv(dev);
  2113. u16 value;
  2114. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name );
  2115. value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
  2116. TLan_MiiSync( dev->base_addr );
  2117. TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
  2118. if ( ( priv->phyNum == 0 ) && ( priv->phy[1] != TLAN_PHY_NONE ) && ( ! ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) ) ) {
  2119. TLan_MiiSync( dev->base_addr );
  2120. TLan_MiiWriteReg( dev, priv->phy[1], MII_GEN_CTL, value );
  2121. }
  2122. /* Wait for 50 ms and powerup
  2123. * This is abitrary. It is intended to make sure the
  2124. * transceiver settles.
  2125. */
  2126. TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_PUP );
  2127. } /* TLan_PhyPowerDown */
  2128. void TLan_PhyPowerUp( struct net_device *dev )
  2129. {
  2130. TLanPrivateInfo *priv = netdev_priv(dev);
  2131. u16 value;
  2132. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name );
  2133. TLan_MiiSync( dev->base_addr );
  2134. value = MII_GC_LOOPBK;
  2135. TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
  2136. TLan_MiiSync(dev->base_addr);
  2137. /* Wait for 500 ms and reset the
  2138. * transceiver. The TLAN docs say both 50 ms and
  2139. * 500 ms, so do the longer, just in case.
  2140. */
  2141. TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET );
  2142. } /* TLan_PhyPowerUp */
  2143. void TLan_PhyReset( struct net_device *dev )
  2144. {
  2145. TLanPrivateInfo *priv = netdev_priv(dev);
  2146. u16 phy;
  2147. u16 value;
  2148. phy = priv->phy[priv->phyNum];
  2149. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name );
  2150. TLan_MiiSync( dev->base_addr );
  2151. value = MII_GC_LOOPBK | MII_GC_RESET;
  2152. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, value );
  2153. TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
  2154. while ( value & MII_GC_RESET ) {
  2155. TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
  2156. }
  2157. /* Wait for 500 ms and initialize.
  2158. * I don't remember why I wait this long.
  2159. * I've changed this to 50ms, as it seems long enough.
  2160. */
  2161. TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_START_LINK );
  2162. } /* TLan_PhyReset */
  2163. void TLan_PhyStartLink( struct net_device *dev )
  2164. {
  2165. TLanPrivateInfo *priv = netdev_priv(dev);
  2166. u16 ability;
  2167. u16 control;
  2168. u16 data;
  2169. u16 phy;
  2170. u16 status;
  2171. u16 tctl;
  2172. phy = priv->phy[priv->phyNum];
  2173. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name );
  2174. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  2175. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &ability );
  2176. if ( ( status & MII_GS_AUTONEG ) &&
  2177. ( ! priv->aui ) ) {
  2178. ability = status >> 11;
  2179. if ( priv->speed == TLAN_SPEED_10 &&
  2180. priv->duplex == TLAN_DUPLEX_HALF) {
  2181. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x0000);
  2182. } else if ( priv->speed == TLAN_SPEED_10 &&
  2183. priv->duplex == TLAN_DUPLEX_FULL) {
  2184. priv->tlanFullDuplex = TRUE;
  2185. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x0100);
  2186. } else if ( priv->speed == TLAN_SPEED_100 &&
  2187. priv->duplex == TLAN_DUPLEX_HALF) {
  2188. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x2000);
  2189. } else if ( priv->speed == TLAN_SPEED_100 &&
  2190. priv->duplex == TLAN_DUPLEX_FULL) {
  2191. priv->tlanFullDuplex = TRUE;
  2192. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x2100);
  2193. } else {
  2194. /* Set Auto-Neg advertisement */
  2195. TLan_MiiWriteReg( dev, phy, MII_AN_ADV, (ability << 5) | 1);
  2196. /* Enablee Auto-Neg */
  2197. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1000 );
  2198. /* Restart Auto-Neg */
  2199. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1200 );
  2200. /* Wait for 4 sec for autonegotiation
  2201. * to complete. The max spec time is less than this
  2202. * but the card need additional time to start AN.
  2203. * .5 sec should be plenty extra.
  2204. */
  2205. printk( "TLAN: %s: Starting autonegotiation.\n", dev->name );
  2206. TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN );
  2207. return;
  2208. }
  2209. }
  2210. if ( ( priv->aui ) && ( priv->phyNum != 0 ) ) {
  2211. priv->phyNum = 0;
  2212. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  2213. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
  2214. TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN );
  2215. return;
  2216. } else if ( priv->phyNum == 0 ) {
  2217. control = 0;
  2218. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tctl );
  2219. if ( priv->aui ) {
  2220. tctl |= TLAN_TC_AUISEL;
  2221. } else {
  2222. tctl &= ~TLAN_TC_AUISEL;
  2223. if ( priv->duplex == TLAN_DUPLEX_FULL ) {
  2224. control |= MII_GC_DUPLEX;
  2225. priv->tlanFullDuplex = TRUE;
  2226. }
  2227. if ( priv->speed == TLAN_SPEED_100 ) {
  2228. control |= MII_GC_SPEEDSEL;
  2229. }
  2230. }
  2231. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, control );
  2232. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tctl );
  2233. }
  2234. /* Wait for 2 sec to give the transceiver time
  2235. * to establish link.
  2236. */
  2237. TLan_SetTimer( dev, (4*HZ), TLAN_TIMER_FINISH_RESET );
  2238. } /* TLan_PhyStartLink */
  2239. void TLan_PhyFinishAutoNeg( struct net_device *dev )
  2240. {
  2241. TLanPrivateInfo *priv = netdev_priv(dev);
  2242. u16 an_adv;
  2243. u16 an_lpa;
  2244. u16 data;
  2245. u16 mode;
  2246. u16 phy;
  2247. u16 status;
  2248. phy = priv->phy[priv->phyNum];
  2249. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  2250. udelay( 1000 );
  2251. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  2252. if ( ! ( status & MII_GS_AUTOCMPLT ) ) {
  2253. /* Wait for 8 sec to give the process
  2254. * more time. Perhaps we should fail after a while.
  2255. */
  2256. if (!priv->neg_be_verbose++) {
  2257. printk(KERN_INFO "TLAN: Giving autonegotiation more time.\n");
  2258. printk(KERN_INFO "TLAN: Please check that your adapter has\n");
  2259. printk(KERN_INFO "TLAN: been properly connected to a HUB or Switch.\n");
  2260. printk(KERN_INFO "TLAN: Trying to establish link in the background...\n");
  2261. }
  2262. TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN );
  2263. return;
  2264. }
  2265. printk( "TLAN: %s: Autonegotiation complete.\n", dev->name );
  2266. TLan_MiiReadReg( dev, phy, MII_AN_ADV, &an_adv );
  2267. TLan_MiiReadReg( dev, phy, MII_AN_LPA, &an_lpa );
  2268. mode = an_adv & an_lpa & 0x03E0;
  2269. if ( mode & 0x0100 ) {
  2270. priv->tlanFullDuplex = TRUE;
  2271. } else if ( ! ( mode & 0x0080 ) && ( mode & 0x0040 ) ) {
  2272. priv->tlanFullDuplex = TRUE;
  2273. }
  2274. if ( ( ! ( mode & 0x0180 ) ) && ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) && ( priv->phyNum != 0 ) ) {
  2275. priv->phyNum = 0;
  2276. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  2277. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
  2278. TLan_SetTimer( dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN );
  2279. return;
  2280. }
  2281. if ( priv->phyNum == 0 ) {
  2282. if ( ( priv->duplex == TLAN_DUPLEX_FULL ) || ( an_adv & an_lpa & 0x0040 ) ) {
  2283. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, MII_GC_AUTOENB | MII_GC_DUPLEX );
  2284. printk( "TLAN: Starting internal PHY with FULL-DUPLEX\n" );
  2285. } else {
  2286. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, MII_GC_AUTOENB );
  2287. printk( "TLAN: Starting internal PHY with HALF-DUPLEX\n" );
  2288. }
  2289. }
  2290. /* Wait for 100 ms. No reason in partiticular.
  2291. */
  2292. TLan_SetTimer( dev, (HZ/10), TLAN_TIMER_FINISH_RESET );
  2293. } /* TLan_PhyFinishAutoNeg */
  2294. #ifdef MONITOR
  2295. /*********************************************************************
  2296. *
  2297. * TLan_phyMonitor
  2298. *
  2299. * Returns:
  2300. * None
  2301. *
  2302. * Params:
  2303. * dev The device structure of this device.
  2304. *
  2305. *
  2306. * This function monitors PHY condition by reading the status
  2307. * register via the MII bus. This can be used to give info
  2308. * about link changes (up/down), and possible switch to alternate
  2309. * media.
  2310. *
  2311. * ******************************************************************/
  2312. void TLan_PhyMonitor( struct net_device *dev )
  2313. {
  2314. TLanPrivateInfo *priv = netdev_priv(dev);
  2315. u16 phy;
  2316. u16 phy_status;
  2317. phy = priv->phy[priv->phyNum];
  2318. /* Get PHY status register */
  2319. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &phy_status );
  2320. /* Check if link has been lost */
  2321. if (!(phy_status & MII_GS_LINK)) {
  2322. if (priv->link) {
  2323. priv->link = 0;
  2324. printk(KERN_DEBUG "TLAN: %s has lost link\n", dev->name);
  2325. dev->flags &= ~IFF_RUNNING;
  2326. TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT );
  2327. return;
  2328. }
  2329. }
  2330. /* Link restablished? */
  2331. if ((phy_status & MII_GS_LINK) && !priv->link) {
  2332. priv->link = 1;
  2333. printk(KERN_DEBUG "TLAN: %s has reestablished link\n", dev->name);
  2334. dev->flags |= IFF_RUNNING;
  2335. }
  2336. /* Setup a new monitor */
  2337. TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT );
  2338. }
  2339. #endif /* MONITOR */
  2340. /*****************************************************************************
  2341. ******************************************************************************
  2342. ThunderLAN Driver MII Routines
  2343. These routines are based on the information in Chap. 2 of the
  2344. "ThunderLAN Programmer's Guide", pp. 15-24.
  2345. ******************************************************************************
  2346. *****************************************************************************/
  2347. /***************************************************************
  2348. * TLan_MiiReadReg
  2349. *
  2350. * Returns:
  2351. * 0 if ack received ok
  2352. * 1 otherwise.
  2353. *
  2354. * Parms:
  2355. * dev The device structure containing
  2356. * The io address and interrupt count
  2357. * for this device.
  2358. * phy The address of the PHY to be queried.
  2359. * reg The register whose contents are to be
  2360. * retreived.
  2361. * val A pointer to a variable to store the
  2362. * retrieved value.
  2363. *
  2364. * This function uses the TLAN's MII bus to retreive the contents
  2365. * of a given register on a PHY. It sends the appropriate info
  2366. * and then reads the 16-bit register value from the MII bus via
  2367. * the TLAN SIO register.
  2368. *
  2369. **************************************************************/
  2370. int TLan_MiiReadReg( struct net_device *dev, u16 phy, u16 reg, u16 *val )
  2371. {
  2372. u8 nack;
  2373. u16 sio, tmp;
  2374. u32 i;
  2375. int err;
  2376. int minten;
  2377. TLanPrivateInfo *priv = netdev_priv(dev);
  2378. unsigned long flags = 0;
  2379. err = FALSE;
  2380. outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
  2381. sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  2382. if (!in_irq())
  2383. spin_lock_irqsave(&priv->lock, flags);
  2384. TLan_MiiSync(dev->base_addr);
  2385. minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
  2386. if ( minten )
  2387. TLan_ClearBit(TLAN_NET_SIO_MINTEN, sio);
  2388. TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
  2389. TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Read ( 10b ) */
  2390. TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
  2391. TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
  2392. TLan_ClearBit(TLAN_NET_SIO_MTXEN, sio); /* Change direction */
  2393. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Clock Idle bit */
  2394. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2395. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Wait 300ns */
  2396. nack = TLan_GetBit(TLAN_NET_SIO_MDATA, sio); /* Check for ACK */
  2397. TLan_SetBit(TLAN_NET_SIO_MCLK, sio); /* Finish ACK */
  2398. if (nack) { /* No ACK, so fake it */
  2399. for (i = 0; i < 16; i++) {
  2400. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  2401. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2402. }
  2403. tmp = 0xffff;
  2404. err = TRUE;
  2405. } else { /* ACK, so read data */
  2406. for (tmp = 0, i = 0x8000; i; i >>= 1) {
  2407. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  2408. if (TLan_GetBit(TLAN_NET_SIO_MDATA, sio))
  2409. tmp |= i;
  2410. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2411. }
  2412. }
  2413. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
  2414. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2415. if ( minten )
  2416. TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
  2417. *val = tmp;
  2418. if (!in_irq())
  2419. spin_unlock_irqrestore(&priv->lock, flags);
  2420. return err;
  2421. } /* TLan_MiiReadReg */
  2422. /***************************************************************
  2423. * TLan_MiiSendData
  2424. *
  2425. * Returns:
  2426. * Nothing
  2427. * Parms:
  2428. * base_port The base IO port of the adapter in
  2429. * question.
  2430. * dev The address of the PHY to be queried.
  2431. * data The value to be placed on the MII bus.
  2432. * num_bits The number of bits in data that are to
  2433. * be placed on the MII bus.
  2434. *
  2435. * This function sends on sequence of bits on the MII
  2436. * configuration bus.
  2437. *
  2438. **************************************************************/
  2439. void TLan_MiiSendData( u16 base_port, u32 data, unsigned num_bits )
  2440. {
  2441. u16 sio;
  2442. u32 i;
  2443. if ( num_bits == 0 )
  2444. return;
  2445. outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
  2446. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  2447. TLan_SetBit( TLAN_NET_SIO_MTXEN, sio );
  2448. for ( i = ( 0x1 << ( num_bits - 1 ) ); i; i >>= 1 ) {
  2449. TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
  2450. (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
  2451. if ( data & i )
  2452. TLan_SetBit( TLAN_NET_SIO_MDATA, sio );
  2453. else
  2454. TLan_ClearBit( TLAN_NET_SIO_MDATA, sio );
  2455. TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
  2456. (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
  2457. }
  2458. } /* TLan_MiiSendData */
  2459. /***************************************************************
  2460. * TLan_MiiSync
  2461. *
  2462. * Returns:
  2463. * Nothing
  2464. * Parms:
  2465. * base_port The base IO port of the adapter in
  2466. * question.
  2467. *
  2468. * This functions syncs all PHYs in terms of the MII configuration
  2469. * bus.
  2470. *
  2471. **************************************************************/
  2472. void TLan_MiiSync( u16 base_port )
  2473. {
  2474. int i;
  2475. u16 sio;
  2476. outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
  2477. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  2478. TLan_ClearBit( TLAN_NET_SIO_MTXEN, sio );
  2479. for ( i = 0; i < 32; i++ ) {
  2480. TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
  2481. TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
  2482. }
  2483. } /* TLan_MiiSync */
  2484. /***************************************************************
  2485. * TLan_MiiWriteReg
  2486. *
  2487. * Returns:
  2488. * Nothing
  2489. * Parms:
  2490. * dev The device structure for the device
  2491. * to write to.
  2492. * phy The address of the PHY to be written to.
  2493. * reg The register whose contents are to be
  2494. * written.
  2495. * val The value to be written to the register.
  2496. *
  2497. * This function uses the TLAN's MII bus to write the contents of a
  2498. * given register on a PHY. It sends the appropriate info and then
  2499. * writes the 16-bit register value from the MII configuration bus
  2500. * via the TLAN SIO register.
  2501. *
  2502. **************************************************************/
  2503. void TLan_MiiWriteReg( struct net_device *dev, u16 phy, u16 reg, u16 val )
  2504. {
  2505. u16 sio;
  2506. int minten;
  2507. unsigned long flags = 0;
  2508. TLanPrivateInfo *priv = netdev_priv(dev);
  2509. outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
  2510. sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  2511. if (!in_irq())
  2512. spin_lock_irqsave(&priv->lock, flags);
  2513. TLan_MiiSync( dev->base_addr );
  2514. minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
  2515. if ( minten )
  2516. TLan_ClearBit( TLAN_NET_SIO_MINTEN, sio );
  2517. TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
  2518. TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Write ( 01b ) */
  2519. TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
  2520. TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
  2521. TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Send ACK */
  2522. TLan_MiiSendData( dev->base_addr, val, 16 ); /* Send Data */
  2523. TLan_ClearBit( TLAN_NET_SIO_MCLK, sio ); /* Idle cycle */
  2524. TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
  2525. if ( minten )
  2526. TLan_SetBit( TLAN_NET_SIO_MINTEN, sio );
  2527. if (!in_irq())
  2528. spin_unlock_irqrestore(&priv->lock, flags);
  2529. } /* TLan_MiiWriteReg */
  2530. /*****************************************************************************
  2531. ******************************************************************************
  2532. ThunderLAN Driver Eeprom routines
  2533. The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
  2534. EEPROM. These functions are based on information in Microchip's
  2535. data sheet. I don't know how well this functions will work with
  2536. other EEPROMs.
  2537. ******************************************************************************
  2538. *****************************************************************************/
  2539. /***************************************************************
  2540. * TLan_EeSendStart
  2541. *
  2542. * Returns:
  2543. * Nothing
  2544. * Parms:
  2545. * io_base The IO port base address for the
  2546. * TLAN device with the EEPROM to
  2547. * use.
  2548. *
  2549. * This function sends a start cycle to an EEPROM attached
  2550. * to a TLAN chip.
  2551. *
  2552. **************************************************************/
  2553. void TLan_EeSendStart( u16 io_base )
  2554. {
  2555. u16 sio;
  2556. outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
  2557. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2558. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2559. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2560. TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
  2561. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
  2562. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2563. } /* TLan_EeSendStart */
  2564. /***************************************************************
  2565. * TLan_EeSendByte
  2566. *
  2567. * Returns:
  2568. * If the correct ack was received, 0, otherwise 1
  2569. * Parms: io_base The IO port base address for the
  2570. * TLAN device with the EEPROM to
  2571. * use.
  2572. * data The 8 bits of information to
  2573. * send to the EEPROM.
  2574. * stop If TLAN_EEPROM_STOP is passed, a
  2575. * stop cycle is sent after the
  2576. * byte is sent after the ack is
  2577. * read.
  2578. *
  2579. * This function sends a byte on the serial EEPROM line,
  2580. * driving the clock to send each bit. The function then
  2581. * reverses transmission direction and reads an acknowledge
  2582. * bit.
  2583. *
  2584. **************************************************************/
  2585. int TLan_EeSendByte( u16 io_base, u8 data, int stop )
  2586. {
  2587. int err;
  2588. u8 place;
  2589. u16 sio;
  2590. outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
  2591. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2592. /* Assume clock is low, tx is enabled; */
  2593. for ( place = 0x80; place != 0; place >>= 1 ) {
  2594. if ( place & data )
  2595. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2596. else
  2597. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
  2598. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2599. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2600. }
  2601. TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
  2602. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2603. err = TLan_GetBit( TLAN_NET_SIO_EDATA, sio );
  2604. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2605. TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
  2606. if ( ( ! err ) && stop ) {
  2607. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* STOP, raise data while clock is high */
  2608. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2609. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2610. }
  2611. return ( err );
  2612. } /* TLan_EeSendByte */
  2613. /***************************************************************
  2614. * TLan_EeReceiveByte
  2615. *
  2616. * Returns:
  2617. * Nothing
  2618. * Parms:
  2619. * io_base The IO port base address for the
  2620. * TLAN device with the EEPROM to
  2621. * use.
  2622. * data An address to a char to hold the
  2623. * data sent from the EEPROM.
  2624. * stop If TLAN_EEPROM_STOP is passed, a
  2625. * stop cycle is sent after the
  2626. * byte is received, and no ack is
  2627. * sent.
  2628. *
  2629. * This function receives 8 bits of data from the EEPROM
  2630. * over the serial link. It then sends and ack bit, or no
  2631. * ack and a stop bit. This function is used to retrieve
  2632. * data after the address of a byte in the EEPROM has been
  2633. * sent.
  2634. *
  2635. **************************************************************/
  2636. void TLan_EeReceiveByte( u16 io_base, u8 *data, int stop )
  2637. {
  2638. u8 place;
  2639. u16 sio;
  2640. outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
  2641. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2642. *data = 0;
  2643. /* Assume clock is low, tx is enabled; */
  2644. TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
  2645. for ( place = 0x80; place; place >>= 1 ) {
  2646. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2647. if ( TLan_GetBit( TLAN_NET_SIO_EDATA, sio ) )
  2648. *data |= place;
  2649. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2650. }
  2651. TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
  2652. if ( ! stop ) {
  2653. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* Ack = 0 */
  2654. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2655. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2656. } else {
  2657. TLan_SetBit( TLAN_NET_SIO_EDATA, sio ); /* No ack = 1 (?) */
  2658. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2659. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2660. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* STOP, raise data while clock is high */
  2661. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2662. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2663. }
  2664. } /* TLan_EeReceiveByte */
  2665. /***************************************************************
  2666. * TLan_EeReadByte
  2667. *
  2668. * Returns:
  2669. * No error = 0, else, the stage at which the error
  2670. * occurred.
  2671. * Parms:
  2672. * io_base The IO port base address for the
  2673. * TLAN device with the EEPROM to
  2674. * use.
  2675. * ee_addr The address of the byte in the
  2676. * EEPROM whose contents are to be
  2677. * retrieved.
  2678. * data An address to a char to hold the
  2679. * data obtained from the EEPROM.
  2680. *
  2681. * This function reads a byte of information from an byte
  2682. * cell in the EEPROM.
  2683. *
  2684. **************************************************************/
  2685. int TLan_EeReadByte( struct net_device *dev, u8 ee_addr, u8 *data )
  2686. {
  2687. int err;
  2688. TLanPrivateInfo *priv = netdev_priv(dev);
  2689. unsigned long flags = 0;
  2690. int ret=0;
  2691. spin_lock_irqsave(&priv->lock, flags);
  2692. TLan_EeSendStart( dev->base_addr );
  2693. err = TLan_EeSendByte( dev->base_addr, 0xA0, TLAN_EEPROM_ACK );
  2694. if (err)
  2695. {
  2696. ret=1;
  2697. goto fail;
  2698. }
  2699. err = TLan_EeSendByte( dev->base_addr, ee_addr, TLAN_EEPROM_ACK );
  2700. if (err)
  2701. {
  2702. ret=2;
  2703. goto fail;
  2704. }
  2705. TLan_EeSendStart( dev->base_addr );
  2706. err = TLan_EeSendByte( dev->base_addr, 0xA1, TLAN_EEPROM_ACK );
  2707. if (err)
  2708. {
  2709. ret=3;
  2710. goto fail;
  2711. }
  2712. TLan_EeReceiveByte( dev->base_addr, data, TLAN_EEPROM_STOP );
  2713. fail:
  2714. spin_unlock_irqrestore(&priv->lock, flags);
  2715. return ret;
  2716. } /* TLan_EeReadByte */