defxx.c 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853
  1. /*
  2. * File Name:
  3. * defxx.c
  4. *
  5. * Copyright Information:
  6. * Copyright Digital Equipment Corporation 1996.
  7. *
  8. * This software may be used and distributed according to the terms of
  9. * the GNU General Public License, incorporated herein by reference.
  10. *
  11. * Abstract:
  12. * A Linux device driver supporting the Digital Equipment Corporation
  13. * FDDI TURBOchannel, EISA and PCI controller families. Supported
  14. * adapters include:
  15. *
  16. * DEC FDDIcontroller/TURBOchannel (DEFTA)
  17. * DEC FDDIcontroller/EISA (DEFEA)
  18. * DEC FDDIcontroller/PCI (DEFPA)
  19. *
  20. * The original author:
  21. * LVS Lawrence V. Stefani <lstefani@yahoo.com>
  22. *
  23. * Maintainers:
  24. * macro Maciej W. Rozycki <macro@linux-mips.org>
  25. *
  26. * Credits:
  27. * I'd like to thank Patricia Cross for helping me get started with
  28. * Linux, David Davies for a lot of help upgrading and configuring
  29. * my development system and for answering many OS and driver
  30. * development questions, and Alan Cox for recommendations and
  31. * integration help on getting FDDI support into Linux. LVS
  32. *
  33. * Driver Architecture:
  34. * The driver architecture is largely based on previous driver work
  35. * for other operating systems. The upper edge interface and
  36. * functions were largely taken from existing Linux device drivers
  37. * such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C
  38. * driver.
  39. *
  40. * Adapter Probe -
  41. * The driver scans for supported EISA adapters by reading the
  42. * SLOT ID register for each EISA slot and making a match
  43. * against the expected value.
  44. *
  45. * Bus-Specific Initialization -
  46. * This driver currently supports both EISA and PCI controller
  47. * families. While the custom DMA chip and FDDI logic is similar
  48. * or identical, the bus logic is very different. After
  49. * initialization, the only bus-specific differences is in how the
  50. * driver enables and disables interrupts. Other than that, the
  51. * run-time critical code behaves the same on both families.
  52. * It's important to note that both adapter families are configured
  53. * to I/O map, rather than memory map, the adapter registers.
  54. *
  55. * Driver Open/Close -
  56. * In the driver open routine, the driver ISR (interrupt service
  57. * routine) is registered and the adapter is brought to an
  58. * operational state. In the driver close routine, the opposite
  59. * occurs; the driver ISR is deregistered and the adapter is
  60. * brought to a safe, but closed state. Users may use consecutive
  61. * commands to bring the adapter up and down as in the following
  62. * example:
  63. * ifconfig fddi0 up
  64. * ifconfig fddi0 down
  65. * ifconfig fddi0 up
  66. *
  67. * Driver Shutdown -
  68. * Apparently, there is no shutdown or halt routine support under
  69. * Linux. This routine would be called during "reboot" or
  70. * "shutdown" to allow the driver to place the adapter in a safe
  71. * state before a warm reboot occurs. To be really safe, the user
  72. * should close the adapter before shutdown (eg. ifconfig fddi0 down)
  73. * to ensure that the adapter DMA engine is taken off-line. However,
  74. * the current driver code anticipates this problem and always issues
  75. * a soft reset of the adapter at the beginning of driver initialization.
  76. * A future driver enhancement in this area may occur in 2.1.X where
  77. * Alan indicated that a shutdown handler may be implemented.
  78. *
  79. * Interrupt Service Routine -
  80. * The driver supports shared interrupts, so the ISR is registered for
  81. * each board with the appropriate flag and the pointer to that board's
  82. * device structure. This provides the context during interrupt
  83. * processing to support shared interrupts and multiple boards.
  84. *
  85. * Interrupt enabling/disabling can occur at many levels. At the host
  86. * end, you can disable system interrupts, or disable interrupts at the
  87. * PIC (on Intel systems). Across the bus, both EISA and PCI adapters
  88. * have a bus-logic chip interrupt enable/disable as well as a DMA
  89. * controller interrupt enable/disable.
  90. *
  91. * The driver currently enables and disables adapter interrupts at the
  92. * bus-logic chip and assumes that Linux will take care of clearing or
  93. * acknowledging any host-based interrupt chips.
  94. *
  95. * Control Functions -
  96. * Control functions are those used to support functions such as adding
  97. * or deleting multicast addresses, enabling or disabling packet
  98. * reception filters, or other custom/proprietary commands. Presently,
  99. * the driver supports the "get statistics", "set multicast list", and
  100. * "set mac address" functions defined by Linux. A list of possible
  101. * enhancements include:
  102. *
  103. * - Custom ioctl interface for executing port interface commands
  104. * - Custom ioctl interface for adding unicast addresses to
  105. * adapter CAM (to support bridge functions).
  106. * - Custom ioctl interface for supporting firmware upgrades.
  107. *
  108. * Hardware (port interface) Support Routines -
  109. * The driver function names that start with "dfx_hw_" represent
  110. * low-level port interface routines that are called frequently. They
  111. * include issuing a DMA or port control command to the adapter,
  112. * resetting the adapter, or reading the adapter state. Since the
  113. * driver initialization and run-time code must make calls into the
  114. * port interface, these routines were written to be as generic and
  115. * usable as possible.
  116. *
  117. * Receive Path -
  118. * The adapter DMA engine supports a 256 entry receive descriptor block
  119. * of which up to 255 entries can be used at any given time. The
  120. * architecture is a standard producer, consumer, completion model in
  121. * which the driver "produces" receive buffers to the adapter, the
  122. * adapter "consumes" the receive buffers by DMAing incoming packet data,
  123. * and the driver "completes" the receive buffers by servicing the
  124. * incoming packet, then "produces" a new buffer and starts the cycle
  125. * again. Receive buffers can be fragmented in up to 16 fragments
  126. * (descriptor entries). For simplicity, this driver posts
  127. * single-fragment receive buffers of 4608 bytes, then allocates a
  128. * sk_buff, copies the data, then reposts the buffer. To reduce CPU
  129. * utilization, a better approach would be to pass up the receive
  130. * buffer (no extra copy) then allocate and post a replacement buffer.
  131. * This is a performance enhancement that should be looked into at
  132. * some point.
  133. *
  134. * Transmit Path -
  135. * Like the receive path, the adapter DMA engine supports a 256 entry
  136. * transmit descriptor block of which up to 255 entries can be used at
  137. * any given time. Transmit buffers can be fragmented in up to 255
  138. * fragments (descriptor entries). This driver always posts one
  139. * fragment per transmit packet request.
  140. *
  141. * The fragment contains the entire packet from FC to end of data.
  142. * Before posting the buffer to the adapter, the driver sets a three-byte
  143. * packet request header (PRH) which is required by the Motorola MAC chip
  144. * used on the adapters. The PRH tells the MAC the type of token to
  145. * receive/send, whether or not to generate and append the CRC, whether
  146. * synchronous or asynchronous framing is used, etc. Since the PRH
  147. * definition is not necessarily consistent across all FDDI chipsets,
  148. * the driver, rather than the common FDDI packet handler routines,
  149. * sets these bytes.
  150. *
  151. * To reduce the amount of descriptor fetches needed per transmit request,
  152. * the driver takes advantage of the fact that there are at least three
  153. * bytes available before the skb->data field on the outgoing transmit
  154. * request. This is guaranteed by having fddi_setup() in net_init.c set
  155. * dev->hard_header_len to 24 bytes. 21 bytes accounts for the largest
  156. * header in an 802.2 SNAP frame. The other 3 bytes are the extra "pad"
  157. * bytes which we'll use to store the PRH.
  158. *
  159. * There's a subtle advantage to adding these pad bytes to the
  160. * hard_header_len, it ensures that the data portion of the packet for
  161. * an 802.2 SNAP frame is longword aligned. Other FDDI driver
  162. * implementations may not need the extra padding and can start copying
  163. * or DMAing directly from the FC byte which starts at skb->data. Should
  164. * another driver implementation need ADDITIONAL padding, the net_init.c
  165. * module should be updated and dev->hard_header_len should be increased.
  166. * NOTE: To maintain the alignment on the data portion of the packet,
  167. * dev->hard_header_len should always be evenly divisible by 4 and at
  168. * least 24 bytes in size.
  169. *
  170. * Modification History:
  171. * Date Name Description
  172. * 16-Aug-96 LVS Created.
  173. * 20-Aug-96 LVS Updated dfx_probe so that version information
  174. * string is only displayed if 1 or more cards are
  175. * found. Changed dfx_rcv_queue_process to copy
  176. * 3 NULL bytes before FC to ensure that data is
  177. * longword aligned in receive buffer.
  178. * 09-Sep-96 LVS Updated dfx_ctl_set_multicast_list to enable
  179. * LLC group promiscuous mode if multicast list
  180. * is too large. LLC individual/group promiscuous
  181. * mode is now disabled if IFF_PROMISC flag not set.
  182. * dfx_xmt_queue_pkt no longer checks for NULL skb
  183. * on Alan Cox recommendation. Added node address
  184. * override support.
  185. * 12-Sep-96 LVS Reset current address to factory address during
  186. * device open. Updated transmit path to post a
  187. * single fragment which includes PRH->end of data.
  188. * Mar 2000 AC Did various cleanups for 2.3.x
  189. * Jun 2000 jgarzik PCI and resource alloc cleanups
  190. * Jul 2000 tjeerd Much cleanup and some bug fixes
  191. * Sep 2000 tjeerd Fix leak on unload, cosmetic code cleanup
  192. * Feb 2001 Skb allocation fixes
  193. * Feb 2001 davej PCI enable cleanups.
  194. * 04 Aug 2003 macro Converted to the DMA API.
  195. * 14 Aug 2004 macro Fix device names reported.
  196. * 14 Jun 2005 macro Use irqreturn_t.
  197. * 23 Oct 2006 macro Big-endian host support.
  198. * 14 Dec 2006 macro TURBOchannel support.
  199. * 01 Jul 2014 macro Fixes for DMA on 64-bit hosts.
  200. */
  201. /* Include files */
  202. #include <linux/bitops.h>
  203. #include <linux/compiler.h>
  204. #include <linux/delay.h>
  205. #include <linux/dma-mapping.h>
  206. #include <linux/eisa.h>
  207. #include <linux/errno.h>
  208. #include <linux/fddidevice.h>
  209. #include <linux/interrupt.h>
  210. #include <linux/ioport.h>
  211. #include <linux/kernel.h>
  212. #include <linux/module.h>
  213. #include <linux/netdevice.h>
  214. #include <linux/pci.h>
  215. #include <linux/skbuff.h>
  216. #include <linux/slab.h>
  217. #include <linux/string.h>
  218. #include <linux/tc.h>
  219. #include <asm/byteorder.h>
  220. #include <asm/io.h>
  221. #include "defxx.h"
  222. /* Version information string should be updated prior to each new release! */
  223. #define DRV_NAME "defxx"
  224. #define DRV_VERSION "v1.11"
  225. #define DRV_RELDATE "2014/07/01"
  226. static char version[] =
  227. DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
  228. " Lawrence V. Stefani and others\n";
  229. #define DYNAMIC_BUFFERS 1
  230. #define SKBUFF_RX_COPYBREAK 200
  231. /*
  232. * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
  233. * alignment for compatibility with old EISA boards.
  234. */
  235. #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
  236. #ifdef CONFIG_EISA
  237. #define DFX_BUS_EISA(dev) (dev->bus == &eisa_bus_type)
  238. #else
  239. #define DFX_BUS_EISA(dev) 0
  240. #endif
  241. #ifdef CONFIG_TC
  242. #define DFX_BUS_TC(dev) (dev->bus == &tc_bus_type)
  243. #else
  244. #define DFX_BUS_TC(dev) 0
  245. #endif
  246. #ifdef CONFIG_DEFXX_MMIO
  247. #define DFX_MMIO 1
  248. #else
  249. #define DFX_MMIO 0
  250. #endif
  251. /* Define module-wide (static) routines */
  252. static void dfx_bus_init(struct net_device *dev);
  253. static void dfx_bus_uninit(struct net_device *dev);
  254. static void dfx_bus_config_check(DFX_board_t *bp);
  255. static int dfx_driver_init(struct net_device *dev,
  256. const char *print_name,
  257. resource_size_t bar_start);
  258. static int dfx_adap_init(DFX_board_t *bp, int get_buffers);
  259. static int dfx_open(struct net_device *dev);
  260. static int dfx_close(struct net_device *dev);
  261. static void dfx_int_pr_halt_id(DFX_board_t *bp);
  262. static void dfx_int_type_0_process(DFX_board_t *bp);
  263. static void dfx_int_common(struct net_device *dev);
  264. static irqreturn_t dfx_interrupt(int irq, void *dev_id);
  265. static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
  266. static void dfx_ctl_set_multicast_list(struct net_device *dev);
  267. static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
  268. static int dfx_ctl_update_cam(DFX_board_t *bp);
  269. static int dfx_ctl_update_filters(DFX_board_t *bp);
  270. static int dfx_hw_dma_cmd_req(DFX_board_t *bp);
  271. static int dfx_hw_port_ctrl_req(DFX_board_t *bp, PI_UINT32 command, PI_UINT32 data_a, PI_UINT32 data_b, PI_UINT32 *host_data);
  272. static void dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
  273. static int dfx_hw_adap_state_rd(DFX_board_t *bp);
  274. static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
  275. static int dfx_rcv_init(DFX_board_t *bp, int get_buffers);
  276. static void dfx_rcv_queue_process(DFX_board_t *bp);
  277. #ifdef DYNAMIC_BUFFERS
  278. static void dfx_rcv_flush(DFX_board_t *bp);
  279. #else
  280. static inline void dfx_rcv_flush(DFX_board_t *bp) {}
  281. #endif
  282. static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
  283. struct net_device *dev);
  284. static int dfx_xmt_done(DFX_board_t *bp);
  285. static void dfx_xmt_flush(DFX_board_t *bp);
  286. /* Define module-wide (static) variables */
  287. static struct pci_driver dfx_pci_driver;
  288. static struct eisa_driver dfx_eisa_driver;
  289. static struct tc_driver dfx_tc_driver;
  290. /*
  291. * =======================
  292. * = dfx_port_write_long =
  293. * = dfx_port_read_long =
  294. * =======================
  295. *
  296. * Overview:
  297. * Routines for reading and writing values from/to adapter
  298. *
  299. * Returns:
  300. * None
  301. *
  302. * Arguments:
  303. * bp - pointer to board information
  304. * offset - register offset from base I/O address
  305. * data - for dfx_port_write_long, this is a value to write;
  306. * for dfx_port_read_long, this is a pointer to store
  307. * the read value
  308. *
  309. * Functional Description:
  310. * These routines perform the correct operation to read or write
  311. * the adapter register.
  312. *
  313. * EISA port block base addresses are based on the slot number in which the
  314. * controller is installed. For example, if the EISA controller is installed
  315. * in slot 4, the port block base address is 0x4000. If the controller is
  316. * installed in slot 2, the port block base address is 0x2000, and so on.
  317. * This port block can be used to access PDQ, ESIC, and DEFEA on-board
  318. * registers using the register offsets defined in DEFXX.H.
  319. *
  320. * PCI port block base addresses are assigned by the PCI BIOS or system
  321. * firmware. There is one 128 byte port block which can be accessed. It
  322. * allows for I/O mapping of both PDQ and PFI registers using the register
  323. * offsets defined in DEFXX.H.
  324. *
  325. * Return Codes:
  326. * None
  327. *
  328. * Assumptions:
  329. * bp->base is a valid base I/O address for this adapter.
  330. * offset is a valid register offset for this adapter.
  331. *
  332. * Side Effects:
  333. * Rather than produce macros for these functions, these routines
  334. * are defined using "inline" to ensure that the compiler will
  335. * generate inline code and not waste a procedure call and return.
  336. * This provides all the benefits of macros, but with the
  337. * advantage of strict data type checking.
  338. */
  339. static inline void dfx_writel(DFX_board_t *bp, int offset, u32 data)
  340. {
  341. writel(data, bp->base.mem + offset);
  342. mb();
  343. }
  344. static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
  345. {
  346. outl(data, bp->base.port + offset);
  347. }
  348. static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
  349. {
  350. struct device __maybe_unused *bdev = bp->bus_dev;
  351. int dfx_bus_tc = DFX_BUS_TC(bdev);
  352. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  353. if (dfx_use_mmio)
  354. dfx_writel(bp, offset, data);
  355. else
  356. dfx_outl(bp, offset, data);
  357. }
  358. static inline void dfx_readl(DFX_board_t *bp, int offset, u32 *data)
  359. {
  360. mb();
  361. *data = readl(bp->base.mem + offset);
  362. }
  363. static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
  364. {
  365. *data = inl(bp->base.port + offset);
  366. }
  367. static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
  368. {
  369. struct device __maybe_unused *bdev = bp->bus_dev;
  370. int dfx_bus_tc = DFX_BUS_TC(bdev);
  371. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  372. if (dfx_use_mmio)
  373. dfx_readl(bp, offset, data);
  374. else
  375. dfx_inl(bp, offset, data);
  376. }
  377. /*
  378. * ================
  379. * = dfx_get_bars =
  380. * ================
  381. *
  382. * Overview:
  383. * Retrieves the address ranges used to access control and status
  384. * registers.
  385. *
  386. * Returns:
  387. * None
  388. *
  389. * Arguments:
  390. * bdev - pointer to device information
  391. * bar_start - pointer to store the start addresses
  392. * bar_len - pointer to store the lengths of the areas
  393. *
  394. * Assumptions:
  395. * I am sure there are some.
  396. *
  397. * Side Effects:
  398. * None
  399. */
  400. static void dfx_get_bars(struct device *bdev,
  401. resource_size_t *bar_start, resource_size_t *bar_len)
  402. {
  403. int dfx_bus_pci = dev_is_pci(bdev);
  404. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  405. int dfx_bus_tc = DFX_BUS_TC(bdev);
  406. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  407. if (dfx_bus_pci) {
  408. int num = dfx_use_mmio ? 0 : 1;
  409. bar_start[0] = pci_resource_start(to_pci_dev(bdev), num);
  410. bar_len[0] = pci_resource_len(to_pci_dev(bdev), num);
  411. bar_start[2] = bar_start[1] = 0;
  412. bar_len[2] = bar_len[1] = 0;
  413. }
  414. if (dfx_bus_eisa) {
  415. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  416. resource_size_t bar_lo;
  417. resource_size_t bar_hi;
  418. if (dfx_use_mmio) {
  419. bar_lo = inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_2);
  420. bar_lo <<= 8;
  421. bar_lo |= inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_1);
  422. bar_lo <<= 8;
  423. bar_lo |= inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_0);
  424. bar_lo <<= 8;
  425. bar_start[0] = bar_lo;
  426. bar_hi = inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_2);
  427. bar_hi <<= 8;
  428. bar_hi |= inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_1);
  429. bar_hi <<= 8;
  430. bar_hi |= inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_0);
  431. bar_hi <<= 8;
  432. bar_len[0] = ((bar_hi - bar_lo) | PI_MEM_ADD_MASK_M) +
  433. 1;
  434. } else {
  435. bar_start[0] = base_addr;
  436. bar_len[0] = PI_ESIC_K_CSR_IO_LEN;
  437. }
  438. bar_start[1] = base_addr + PI_DEFEA_K_BURST_HOLDOFF;
  439. bar_len[1] = PI_ESIC_K_BURST_HOLDOFF_LEN;
  440. bar_start[2] = base_addr + PI_ESIC_K_ESIC_CSR;
  441. bar_len[2] = PI_ESIC_K_ESIC_CSR_LEN;
  442. }
  443. if (dfx_bus_tc) {
  444. bar_start[0] = to_tc_dev(bdev)->resource.start +
  445. PI_TC_K_CSR_OFFSET;
  446. bar_len[0] = PI_TC_K_CSR_LEN;
  447. bar_start[2] = bar_start[1] = 0;
  448. bar_len[2] = bar_len[1] = 0;
  449. }
  450. }
  451. static const struct net_device_ops dfx_netdev_ops = {
  452. .ndo_open = dfx_open,
  453. .ndo_stop = dfx_close,
  454. .ndo_start_xmit = dfx_xmt_queue_pkt,
  455. .ndo_get_stats = dfx_ctl_get_stats,
  456. .ndo_set_rx_mode = dfx_ctl_set_multicast_list,
  457. .ndo_set_mac_address = dfx_ctl_set_mac_address,
  458. };
  459. /*
  460. * ================
  461. * = dfx_register =
  462. * ================
  463. *
  464. * Overview:
  465. * Initializes a supported FDDI controller
  466. *
  467. * Returns:
  468. * Condition code
  469. *
  470. * Arguments:
  471. * bdev - pointer to device information
  472. *
  473. * Functional Description:
  474. *
  475. * Return Codes:
  476. * 0 - This device (fddi0, fddi1, etc) configured successfully
  477. * -EBUSY - Failed to get resources, or dfx_driver_init failed.
  478. *
  479. * Assumptions:
  480. * It compiles so it should work :-( (PCI cards do :-)
  481. *
  482. * Side Effects:
  483. * Device structures for FDDI adapters (fddi0, fddi1, etc) are
  484. * initialized and the board resources are read and stored in
  485. * the device structure.
  486. */
  487. static int dfx_register(struct device *bdev)
  488. {
  489. static int version_disp;
  490. int dfx_bus_pci = dev_is_pci(bdev);
  491. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  492. int dfx_bus_tc = DFX_BUS_TC(bdev);
  493. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  494. const char *print_name = dev_name(bdev);
  495. struct net_device *dev;
  496. DFX_board_t *bp; /* board pointer */
  497. resource_size_t bar_start[3]; /* pointers to ports */
  498. resource_size_t bar_len[3]; /* resource length */
  499. int alloc_size; /* total buffer size used */
  500. struct resource *region;
  501. int err = 0;
  502. if (!version_disp) { /* display version info if adapter is found */
  503. version_disp = 1; /* set display flag to TRUE so that */
  504. printk(version); /* we only display this string ONCE */
  505. }
  506. dev = alloc_fddidev(sizeof(*bp));
  507. if (!dev) {
  508. printk(KERN_ERR "%s: Unable to allocate fddidev, aborting\n",
  509. print_name);
  510. return -ENOMEM;
  511. }
  512. /* Enable PCI device. */
  513. if (dfx_bus_pci) {
  514. err = pci_enable_device(to_pci_dev(bdev));
  515. if (err) {
  516. pr_err("%s: Cannot enable PCI device, aborting\n",
  517. print_name);
  518. goto err_out;
  519. }
  520. }
  521. SET_NETDEV_DEV(dev, bdev);
  522. bp = netdev_priv(dev);
  523. bp->bus_dev = bdev;
  524. dev_set_drvdata(bdev, dev);
  525. dfx_get_bars(bdev, bar_start, bar_len);
  526. if (dfx_bus_eisa && dfx_use_mmio && bar_start[0] == 0) {
  527. pr_err("%s: Cannot use MMIO, no address set, aborting\n",
  528. print_name);
  529. pr_err("%s: Run ECU and set adapter's MMIO location\n",
  530. print_name);
  531. pr_err("%s: Or recompile driver with \"CONFIG_DEFXX_MMIO=n\""
  532. "\n", print_name);
  533. err = -ENXIO;
  534. goto err_out;
  535. }
  536. if (dfx_use_mmio)
  537. region = request_mem_region(bar_start[0], bar_len[0],
  538. print_name);
  539. else
  540. region = request_region(bar_start[0], bar_len[0], print_name);
  541. if (!region) {
  542. pr_err("%s: Cannot reserve %s resource 0x%lx @ 0x%lx, "
  543. "aborting\n", dfx_use_mmio ? "MMIO" : "I/O", print_name,
  544. (long)bar_len[0], (long)bar_start[0]);
  545. err = -EBUSY;
  546. goto err_out_disable;
  547. }
  548. if (bar_start[1] != 0) {
  549. region = request_region(bar_start[1], bar_len[1], print_name);
  550. if (!region) {
  551. pr_err("%s: Cannot reserve I/O resource "
  552. "0x%lx @ 0x%lx, aborting\n", print_name,
  553. (long)bar_len[1], (long)bar_start[1]);
  554. err = -EBUSY;
  555. goto err_out_csr_region;
  556. }
  557. }
  558. if (bar_start[2] != 0) {
  559. region = request_region(bar_start[2], bar_len[2], print_name);
  560. if (!region) {
  561. pr_err("%s: Cannot reserve I/O resource "
  562. "0x%lx @ 0x%lx, aborting\n", print_name,
  563. (long)bar_len[2], (long)bar_start[2]);
  564. err = -EBUSY;
  565. goto err_out_bh_region;
  566. }
  567. }
  568. /* Set up I/O base address. */
  569. if (dfx_use_mmio) {
  570. bp->base.mem = ioremap_nocache(bar_start[0], bar_len[0]);
  571. if (!bp->base.mem) {
  572. printk(KERN_ERR "%s: Cannot map MMIO\n", print_name);
  573. err = -ENOMEM;
  574. goto err_out_esic_region;
  575. }
  576. } else {
  577. bp->base.port = bar_start[0];
  578. dev->base_addr = bar_start[0];
  579. }
  580. /* Initialize new device structure */
  581. dev->netdev_ops = &dfx_netdev_ops;
  582. if (dfx_bus_pci)
  583. pci_set_master(to_pci_dev(bdev));
  584. if (dfx_driver_init(dev, print_name, bar_start[0]) != DFX_K_SUCCESS) {
  585. err = -ENODEV;
  586. goto err_out_unmap;
  587. }
  588. err = register_netdev(dev);
  589. if (err)
  590. goto err_out_kfree;
  591. printk("%s: registered as %s\n", print_name, dev->name);
  592. return 0;
  593. err_out_kfree:
  594. alloc_size = sizeof(PI_DESCR_BLOCK) +
  595. PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  596. #ifndef DYNAMIC_BUFFERS
  597. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  598. #endif
  599. sizeof(PI_CONSUMER_BLOCK) +
  600. (PI_ALIGN_K_DESC_BLK - 1);
  601. if (bp->kmalloced)
  602. dma_free_coherent(bdev, alloc_size,
  603. bp->kmalloced, bp->kmalloced_dma);
  604. err_out_unmap:
  605. if (dfx_use_mmio)
  606. iounmap(bp->base.mem);
  607. err_out_esic_region:
  608. if (bar_start[2] != 0)
  609. release_region(bar_start[2], bar_len[2]);
  610. err_out_bh_region:
  611. if (bar_start[1] != 0)
  612. release_region(bar_start[1], bar_len[1]);
  613. err_out_csr_region:
  614. if (dfx_use_mmio)
  615. release_mem_region(bar_start[0], bar_len[0]);
  616. else
  617. release_region(bar_start[0], bar_len[0]);
  618. err_out_disable:
  619. if (dfx_bus_pci)
  620. pci_disable_device(to_pci_dev(bdev));
  621. err_out:
  622. free_netdev(dev);
  623. return err;
  624. }
  625. /*
  626. * ================
  627. * = dfx_bus_init =
  628. * ================
  629. *
  630. * Overview:
  631. * Initializes the bus-specific controller logic.
  632. *
  633. * Returns:
  634. * None
  635. *
  636. * Arguments:
  637. * dev - pointer to device information
  638. *
  639. * Functional Description:
  640. * Determine and save adapter IRQ in device table,
  641. * then perform bus-specific logic initialization.
  642. *
  643. * Return Codes:
  644. * None
  645. *
  646. * Assumptions:
  647. * bp->base has already been set with the proper
  648. * base I/O address for this device.
  649. *
  650. * Side Effects:
  651. * Interrupts are enabled at the adapter bus-specific logic.
  652. * Note: Interrupts at the DMA engine (PDQ chip) are not
  653. * enabled yet.
  654. */
  655. static void dfx_bus_init(struct net_device *dev)
  656. {
  657. DFX_board_t *bp = netdev_priv(dev);
  658. struct device *bdev = bp->bus_dev;
  659. int dfx_bus_pci = dev_is_pci(bdev);
  660. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  661. int dfx_bus_tc = DFX_BUS_TC(bdev);
  662. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  663. u8 val;
  664. DBG_printk("In dfx_bus_init...\n");
  665. /* Initialize a pointer back to the net_device struct */
  666. bp->dev = dev;
  667. /* Initialize adapter based on bus type */
  668. if (dfx_bus_tc)
  669. dev->irq = to_tc_dev(bdev)->interrupt;
  670. if (dfx_bus_eisa) {
  671. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  672. /* Disable the board before fiddling with the decoders. */
  673. outb(0, base_addr + PI_ESIC_K_SLOT_CNTRL);
  674. /* Get the interrupt level from the ESIC chip. */
  675. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  676. val &= PI_CONFIG_STAT_0_M_IRQ;
  677. val >>= PI_CONFIG_STAT_0_V_IRQ;
  678. switch (val) {
  679. case PI_CONFIG_STAT_0_IRQ_K_9:
  680. dev->irq = 9;
  681. break;
  682. case PI_CONFIG_STAT_0_IRQ_K_10:
  683. dev->irq = 10;
  684. break;
  685. case PI_CONFIG_STAT_0_IRQ_K_11:
  686. dev->irq = 11;
  687. break;
  688. case PI_CONFIG_STAT_0_IRQ_K_15:
  689. dev->irq = 15;
  690. break;
  691. }
  692. /*
  693. * Enable memory decoding (MEMCS1) and/or port decoding
  694. * (IOCS1/IOCS0) as appropriate in Function Control
  695. * Register. MEMCS1 or IOCS0 is used for PDQ registers,
  696. * taking 16 32-bit words, while IOCS1 is used for the
  697. * Burst Holdoff register, taking a single 32-bit word
  698. * only. We use the slot-specific I/O range as per the
  699. * ESIC spec, that is set bits 15:12 in the mask registers
  700. * to mask them out.
  701. */
  702. /* Set the decode range of the board. */
  703. val = 0;
  704. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_0_1);
  705. val = PI_DEFEA_K_CSR_IO;
  706. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_0_0);
  707. val = PI_IO_CMP_M_SLOT;
  708. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_0_1);
  709. val = (PI_ESIC_K_CSR_IO_LEN - 1) & ~3;
  710. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_0_0);
  711. val = 0;
  712. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_1_1);
  713. val = PI_DEFEA_K_BURST_HOLDOFF;
  714. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_1_0);
  715. val = PI_IO_CMP_M_SLOT;
  716. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_1_1);
  717. val = (PI_ESIC_K_BURST_HOLDOFF_LEN - 1) & ~3;
  718. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_1_0);
  719. /* Enable the decoders. */
  720. val = PI_FUNCTION_CNTRL_M_IOCS1;
  721. if (dfx_use_mmio)
  722. val |= PI_FUNCTION_CNTRL_M_MEMCS1;
  723. else
  724. val |= PI_FUNCTION_CNTRL_M_IOCS0;
  725. outb(val, base_addr + PI_ESIC_K_FUNCTION_CNTRL);
  726. /*
  727. * Enable access to the rest of the module
  728. * (including PDQ and packet memory).
  729. */
  730. val = PI_SLOT_CNTRL_M_ENB;
  731. outb(val, base_addr + PI_ESIC_K_SLOT_CNTRL);
  732. /*
  733. * Map PDQ registers into memory or port space. This is
  734. * done with a bit in the Burst Holdoff register.
  735. */
  736. val = inb(base_addr + PI_DEFEA_K_BURST_HOLDOFF);
  737. if (dfx_use_mmio)
  738. val |= PI_BURST_HOLDOFF_M_MEM_MAP;
  739. else
  740. val &= ~PI_BURST_HOLDOFF_M_MEM_MAP;
  741. outb(val, base_addr + PI_DEFEA_K_BURST_HOLDOFF);
  742. /* Enable interrupts at EISA bus interface chip (ESIC) */
  743. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  744. val |= PI_CONFIG_STAT_0_M_INT_ENB;
  745. outb(val, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  746. }
  747. if (dfx_bus_pci) {
  748. struct pci_dev *pdev = to_pci_dev(bdev);
  749. /* Get the interrupt level from the PCI Configuration Table */
  750. dev->irq = pdev->irq;
  751. /* Check Latency Timer and set if less than minimal */
  752. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
  753. if (val < PFI_K_LAT_TIMER_MIN) {
  754. val = PFI_K_LAT_TIMER_DEF;
  755. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
  756. }
  757. /* Enable interrupts at PCI bus interface chip (PFI) */
  758. val = PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB;
  759. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, val);
  760. }
  761. }
  762. /*
  763. * ==================
  764. * = dfx_bus_uninit =
  765. * ==================
  766. *
  767. * Overview:
  768. * Uninitializes the bus-specific controller logic.
  769. *
  770. * Returns:
  771. * None
  772. *
  773. * Arguments:
  774. * dev - pointer to device information
  775. *
  776. * Functional Description:
  777. * Perform bus-specific logic uninitialization.
  778. *
  779. * Return Codes:
  780. * None
  781. *
  782. * Assumptions:
  783. * bp->base has already been set with the proper
  784. * base I/O address for this device.
  785. *
  786. * Side Effects:
  787. * Interrupts are disabled at the adapter bus-specific logic.
  788. */
  789. static void dfx_bus_uninit(struct net_device *dev)
  790. {
  791. DFX_board_t *bp = netdev_priv(dev);
  792. struct device *bdev = bp->bus_dev;
  793. int dfx_bus_pci = dev_is_pci(bdev);
  794. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  795. u8 val;
  796. DBG_printk("In dfx_bus_uninit...\n");
  797. /* Uninitialize adapter based on bus type */
  798. if (dfx_bus_eisa) {
  799. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  800. /* Disable interrupts at EISA bus interface chip (ESIC) */
  801. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  802. val &= ~PI_CONFIG_STAT_0_M_INT_ENB;
  803. outb(val, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  804. /* Disable the board. */
  805. outb(0, base_addr + PI_ESIC_K_SLOT_CNTRL);
  806. /* Disable memory and port decoders. */
  807. outb(0, base_addr + PI_ESIC_K_FUNCTION_CNTRL);
  808. }
  809. if (dfx_bus_pci) {
  810. /* Disable interrupts at PCI bus interface chip (PFI) */
  811. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 0);
  812. }
  813. }
  814. /*
  815. * ========================
  816. * = dfx_bus_config_check =
  817. * ========================
  818. *
  819. * Overview:
  820. * Checks the configuration (burst size, full-duplex, etc.) If any parameters
  821. * are illegal, then this routine will set new defaults.
  822. *
  823. * Returns:
  824. * None
  825. *
  826. * Arguments:
  827. * bp - pointer to board information
  828. *
  829. * Functional Description:
  830. * For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
  831. * PDQ, and all FDDI PCI controllers, all values are legal.
  832. *
  833. * Return Codes:
  834. * None
  835. *
  836. * Assumptions:
  837. * dfx_adap_init has NOT been called yet so burst size and other items have
  838. * not been set.
  839. *
  840. * Side Effects:
  841. * None
  842. */
  843. static void dfx_bus_config_check(DFX_board_t *bp)
  844. {
  845. struct device __maybe_unused *bdev = bp->bus_dev;
  846. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  847. int status; /* return code from adapter port control call */
  848. u32 host_data; /* LW data returned from port control call */
  849. DBG_printk("In dfx_bus_config_check...\n");
  850. /* Configuration check only valid for EISA adapter */
  851. if (dfx_bus_eisa) {
  852. /*
  853. * First check if revision 2 EISA controller. Rev. 1 cards used
  854. * PDQ revision B, so no workaround needed in this case. Rev. 3
  855. * cards used PDQ revision E, so no workaround needed in this
  856. * case, either. Only Rev. 2 cards used either Rev. D or E
  857. * chips, so we must verify the chip revision on Rev. 2 cards.
  858. */
  859. if (to_eisa_device(bdev)->id.driver_data == DEFEA_PROD_ID_2) {
  860. /*
  861. * Revision 2 FDDI EISA controller found,
  862. * so let's check PDQ revision of adapter.
  863. */
  864. status = dfx_hw_port_ctrl_req(bp,
  865. PI_PCTRL_M_SUB_CMD,
  866. PI_SUB_CMD_K_PDQ_REV_GET,
  867. 0,
  868. &host_data);
  869. if ((status != DFX_K_SUCCESS) || (host_data == 2))
  870. {
  871. /*
  872. * Either we couldn't determine the PDQ revision, or
  873. * we determined that it is at revision D. In either case,
  874. * we need to implement the workaround.
  875. */
  876. /* Ensure that the burst size is set to 8 longwords or less */
  877. switch (bp->burst_size)
  878. {
  879. case PI_PDATA_B_DMA_BURST_SIZE_32:
  880. case PI_PDATA_B_DMA_BURST_SIZE_16:
  881. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
  882. break;
  883. default:
  884. break;
  885. }
  886. /* Ensure that full-duplex mode is not enabled */
  887. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  888. }
  889. }
  890. }
  891. }
  892. /*
  893. * ===================
  894. * = dfx_driver_init =
  895. * ===================
  896. *
  897. * Overview:
  898. * Initializes remaining adapter board structure information
  899. * and makes sure adapter is in a safe state prior to dfx_open().
  900. *
  901. * Returns:
  902. * Condition code
  903. *
  904. * Arguments:
  905. * dev - pointer to device information
  906. * print_name - printable device name
  907. *
  908. * Functional Description:
  909. * This function allocates additional resources such as the host memory
  910. * blocks needed by the adapter (eg. descriptor and consumer blocks).
  911. * Remaining bus initialization steps are also completed. The adapter
  912. * is also reset so that it is in the DMA_UNAVAILABLE state. The OS
  913. * must call dfx_open() to open the adapter and bring it on-line.
  914. *
  915. * Return Codes:
  916. * DFX_K_SUCCESS - initialization succeeded
  917. * DFX_K_FAILURE - initialization failed - could not allocate memory
  918. * or read adapter MAC address
  919. *
  920. * Assumptions:
  921. * Memory allocated from pci_alloc_consistent() call is physically
  922. * contiguous, locked memory.
  923. *
  924. * Side Effects:
  925. * Adapter is reset and should be in DMA_UNAVAILABLE state before
  926. * returning from this routine.
  927. */
  928. static int dfx_driver_init(struct net_device *dev, const char *print_name,
  929. resource_size_t bar_start)
  930. {
  931. DFX_board_t *bp = netdev_priv(dev);
  932. struct device *bdev = bp->bus_dev;
  933. int dfx_bus_pci = dev_is_pci(bdev);
  934. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  935. int dfx_bus_tc = DFX_BUS_TC(bdev);
  936. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  937. int alloc_size; /* total buffer size needed */
  938. char *top_v, *curr_v; /* virtual addrs into memory block */
  939. dma_addr_t top_p, curr_p; /* physical addrs into memory block */
  940. u32 data; /* host data register value */
  941. __le32 le32;
  942. char *board_name = NULL;
  943. DBG_printk("In dfx_driver_init...\n");
  944. /* Initialize bus-specific hardware registers */
  945. dfx_bus_init(dev);
  946. /*
  947. * Initialize default values for configurable parameters
  948. *
  949. * Note: All of these parameters are ones that a user may
  950. * want to customize. It'd be nice to break these
  951. * out into Space.c or someplace else that's more
  952. * accessible/understandable than this file.
  953. */
  954. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  955. bp->req_ttrt = 8 * 12500; /* 8ms in 80 nanosec units */
  956. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_DEF;
  957. bp->rcv_bufs_to_post = RCV_BUFS_DEF;
  958. /*
  959. * Ensure that HW configuration is OK
  960. *
  961. * Note: Depending on the hardware revision, we may need to modify
  962. * some of the configurable parameters to workaround hardware
  963. * limitations. We'll perform this configuration check AFTER
  964. * setting the parameters to their default values.
  965. */
  966. dfx_bus_config_check(bp);
  967. /* Disable PDQ interrupts first */
  968. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  969. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  970. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  971. /* Read the factory MAC address from the adapter then save it */
  972. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_LO, 0,
  973. &data) != DFX_K_SUCCESS) {
  974. printk("%s: Could not read adapter factory MAC address!\n",
  975. print_name);
  976. return DFX_K_FAILURE;
  977. }
  978. le32 = cpu_to_le32(data);
  979. memcpy(&bp->factory_mac_addr[0], &le32, sizeof(u32));
  980. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_HI, 0,
  981. &data) != DFX_K_SUCCESS) {
  982. printk("%s: Could not read adapter factory MAC address!\n",
  983. print_name);
  984. return DFX_K_FAILURE;
  985. }
  986. le32 = cpu_to_le32(data);
  987. memcpy(&bp->factory_mac_addr[4], &le32, sizeof(u16));
  988. /*
  989. * Set current address to factory address
  990. *
  991. * Note: Node address override support is handled through
  992. * dfx_ctl_set_mac_address.
  993. */
  994. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  995. if (dfx_bus_tc)
  996. board_name = "DEFTA";
  997. if (dfx_bus_eisa)
  998. board_name = "DEFEA";
  999. if (dfx_bus_pci)
  1000. board_name = "DEFPA";
  1001. pr_info("%s: %s at %s addr = 0x%llx, IRQ = %d, Hardware addr = %pMF\n",
  1002. print_name, board_name, dfx_use_mmio ? "MMIO" : "I/O",
  1003. (long long)bar_start, dev->irq, dev->dev_addr);
  1004. /*
  1005. * Get memory for descriptor block, consumer block, and other buffers
  1006. * that need to be DMA read or written to by the adapter.
  1007. */
  1008. alloc_size = sizeof(PI_DESCR_BLOCK) +
  1009. PI_CMD_REQ_K_SIZE_MAX +
  1010. PI_CMD_RSP_K_SIZE_MAX +
  1011. #ifndef DYNAMIC_BUFFERS
  1012. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  1013. #endif
  1014. sizeof(PI_CONSUMER_BLOCK) +
  1015. (PI_ALIGN_K_DESC_BLK - 1);
  1016. bp->kmalloced = top_v = dma_zalloc_coherent(bp->bus_dev, alloc_size,
  1017. &bp->kmalloced_dma,
  1018. GFP_ATOMIC);
  1019. if (top_v == NULL)
  1020. return DFX_K_FAILURE;
  1021. top_p = bp->kmalloced_dma; /* get physical address of buffer */
  1022. /*
  1023. * To guarantee the 8K alignment required for the descriptor block, 8K - 1
  1024. * plus the amount of memory needed was allocated. The physical address
  1025. * is now 8K aligned. By carving up the memory in a specific order,
  1026. * we'll guarantee the alignment requirements for all other structures.
  1027. *
  1028. * Note: If the assumptions change regarding the non-paged, non-cached,
  1029. * physically contiguous nature of the memory block or the address
  1030. * alignments, then we'll need to implement a different algorithm
  1031. * for allocating the needed memory.
  1032. */
  1033. curr_p = ALIGN(top_p, PI_ALIGN_K_DESC_BLK);
  1034. curr_v = top_v + (curr_p - top_p);
  1035. /* Reserve space for descriptor block */
  1036. bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
  1037. bp->descr_block_phys = curr_p;
  1038. curr_v += sizeof(PI_DESCR_BLOCK);
  1039. curr_p += sizeof(PI_DESCR_BLOCK);
  1040. /* Reserve space for command request buffer */
  1041. bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
  1042. bp->cmd_req_phys = curr_p;
  1043. curr_v += PI_CMD_REQ_K_SIZE_MAX;
  1044. curr_p += PI_CMD_REQ_K_SIZE_MAX;
  1045. /* Reserve space for command response buffer */
  1046. bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
  1047. bp->cmd_rsp_phys = curr_p;
  1048. curr_v += PI_CMD_RSP_K_SIZE_MAX;
  1049. curr_p += PI_CMD_RSP_K_SIZE_MAX;
  1050. /* Reserve space for the LLC host receive queue buffers */
  1051. bp->rcv_block_virt = curr_v;
  1052. bp->rcv_block_phys = curr_p;
  1053. #ifndef DYNAMIC_BUFFERS
  1054. curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  1055. curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  1056. #endif
  1057. /* Reserve space for the consumer block */
  1058. bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
  1059. bp->cons_block_phys = curr_p;
  1060. /* Display virtual and physical addresses if debug driver */
  1061. DBG_printk("%s: Descriptor block virt = %p, phys = %pad\n",
  1062. print_name, bp->descr_block_virt, &bp->descr_block_phys);
  1063. DBG_printk("%s: Command Request buffer virt = %p, phys = %pad\n",
  1064. print_name, bp->cmd_req_virt, &bp->cmd_req_phys);
  1065. DBG_printk("%s: Command Response buffer virt = %p, phys = %pad\n",
  1066. print_name, bp->cmd_rsp_virt, &bp->cmd_rsp_phys);
  1067. DBG_printk("%s: Receive buffer block virt = %p, phys = %pad\n",
  1068. print_name, bp->rcv_block_virt, &bp->rcv_block_phys);
  1069. DBG_printk("%s: Consumer block virt = %p, phys = %pad\n",
  1070. print_name, bp->cons_block_virt, &bp->cons_block_phys);
  1071. return DFX_K_SUCCESS;
  1072. }
  1073. /*
  1074. * =================
  1075. * = dfx_adap_init =
  1076. * =================
  1077. *
  1078. * Overview:
  1079. * Brings the adapter to the link avail/link unavailable state.
  1080. *
  1081. * Returns:
  1082. * Condition code
  1083. *
  1084. * Arguments:
  1085. * bp - pointer to board information
  1086. * get_buffers - non-zero if buffers to be allocated
  1087. *
  1088. * Functional Description:
  1089. * Issues the low-level firmware/hardware calls necessary to bring
  1090. * the adapter up, or to properly reset and restore adapter during
  1091. * run-time.
  1092. *
  1093. * Return Codes:
  1094. * DFX_K_SUCCESS - Adapter brought up successfully
  1095. * DFX_K_FAILURE - Adapter initialization failed
  1096. *
  1097. * Assumptions:
  1098. * bp->reset_type should be set to a valid reset type value before
  1099. * calling this routine.
  1100. *
  1101. * Side Effects:
  1102. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1103. * upon a successful return of this routine.
  1104. */
  1105. static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
  1106. {
  1107. DBG_printk("In dfx_adap_init...\n");
  1108. /* Disable PDQ interrupts first */
  1109. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1110. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1111. if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
  1112. {
  1113. printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
  1114. return DFX_K_FAILURE;
  1115. }
  1116. /*
  1117. * When the PDQ is reset, some false Type 0 interrupts may be pending,
  1118. * so we'll acknowledge all Type 0 interrupts now before continuing.
  1119. */
  1120. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
  1121. /*
  1122. * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
  1123. *
  1124. * Note: We only need to clear host copies of these registers. The PDQ reset
  1125. * takes care of the on-board register values.
  1126. */
  1127. bp->cmd_req_reg.lword = 0;
  1128. bp->cmd_rsp_reg.lword = 0;
  1129. bp->rcv_xmt_reg.lword = 0;
  1130. /* Clear consumer block before going to DMA_AVAILABLE state */
  1131. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1132. /* Initialize the DMA Burst Size */
  1133. if (dfx_hw_port_ctrl_req(bp,
  1134. PI_PCTRL_M_SUB_CMD,
  1135. PI_SUB_CMD_K_BURST_SIZE_SET,
  1136. bp->burst_size,
  1137. NULL) != DFX_K_SUCCESS)
  1138. {
  1139. printk("%s: Could not set adapter burst size!\n", bp->dev->name);
  1140. return DFX_K_FAILURE;
  1141. }
  1142. /*
  1143. * Set base address of Consumer Block
  1144. *
  1145. * Assumption: 32-bit physical address of consumer block is 64 byte
  1146. * aligned. That is, bits 0-5 of the address must be zero.
  1147. */
  1148. if (dfx_hw_port_ctrl_req(bp,
  1149. PI_PCTRL_M_CONS_BLOCK,
  1150. bp->cons_block_phys,
  1151. 0,
  1152. NULL) != DFX_K_SUCCESS)
  1153. {
  1154. printk("%s: Could not set consumer block address!\n", bp->dev->name);
  1155. return DFX_K_FAILURE;
  1156. }
  1157. /*
  1158. * Set the base address of Descriptor Block and bring adapter
  1159. * to DMA_AVAILABLE state.
  1160. *
  1161. * Note: We also set the literal and data swapping requirements
  1162. * in this command.
  1163. *
  1164. * Assumption: 32-bit physical address of descriptor block
  1165. * is 8Kbyte aligned.
  1166. */
  1167. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_INIT,
  1168. (u32)(bp->descr_block_phys |
  1169. PI_PDATA_A_INIT_M_BSWAP_INIT),
  1170. 0, NULL) != DFX_K_SUCCESS) {
  1171. printk("%s: Could not set descriptor block address!\n",
  1172. bp->dev->name);
  1173. return DFX_K_FAILURE;
  1174. }
  1175. /* Set transmit flush timeout value */
  1176. bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
  1177. bp->cmd_req_virt->char_set.item[0].item_code = PI_ITEM_K_FLUSH_TIME;
  1178. bp->cmd_req_virt->char_set.item[0].value = 3; /* 3 seconds */
  1179. bp->cmd_req_virt->char_set.item[0].item_index = 0;
  1180. bp->cmd_req_virt->char_set.item[1].item_code = PI_ITEM_K_EOL;
  1181. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1182. {
  1183. printk("%s: DMA command request failed!\n", bp->dev->name);
  1184. return DFX_K_FAILURE;
  1185. }
  1186. /* Set the initial values for eFDXEnable and MACTReq MIB objects */
  1187. bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
  1188. bp->cmd_req_virt->snmp_set.item[0].item_code = PI_ITEM_K_FDX_ENB_DIS;
  1189. bp->cmd_req_virt->snmp_set.item[0].value = bp->full_duplex_enb;
  1190. bp->cmd_req_virt->snmp_set.item[0].item_index = 0;
  1191. bp->cmd_req_virt->snmp_set.item[1].item_code = PI_ITEM_K_MAC_T_REQ;
  1192. bp->cmd_req_virt->snmp_set.item[1].value = bp->req_ttrt;
  1193. bp->cmd_req_virt->snmp_set.item[1].item_index = 0;
  1194. bp->cmd_req_virt->snmp_set.item[2].item_code = PI_ITEM_K_EOL;
  1195. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1196. {
  1197. printk("%s: DMA command request failed!\n", bp->dev->name);
  1198. return DFX_K_FAILURE;
  1199. }
  1200. /* Initialize adapter CAM */
  1201. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  1202. {
  1203. printk("%s: Adapter CAM update failed!\n", bp->dev->name);
  1204. return DFX_K_FAILURE;
  1205. }
  1206. /* Initialize adapter filters */
  1207. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  1208. {
  1209. printk("%s: Adapter filters update failed!\n", bp->dev->name);
  1210. return DFX_K_FAILURE;
  1211. }
  1212. /*
  1213. * Remove any existing dynamic buffers (i.e. if the adapter is being
  1214. * reinitialized)
  1215. */
  1216. if (get_buffers)
  1217. dfx_rcv_flush(bp);
  1218. /* Initialize receive descriptor block and produce buffers */
  1219. if (dfx_rcv_init(bp, get_buffers))
  1220. {
  1221. printk("%s: Receive buffer allocation failed\n", bp->dev->name);
  1222. if (get_buffers)
  1223. dfx_rcv_flush(bp);
  1224. return DFX_K_FAILURE;
  1225. }
  1226. /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
  1227. bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
  1228. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1229. {
  1230. printk("%s: Start command failed\n", bp->dev->name);
  1231. if (get_buffers)
  1232. dfx_rcv_flush(bp);
  1233. return DFX_K_FAILURE;
  1234. }
  1235. /* Initialization succeeded, reenable PDQ interrupts */
  1236. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
  1237. return DFX_K_SUCCESS;
  1238. }
  1239. /*
  1240. * ============
  1241. * = dfx_open =
  1242. * ============
  1243. *
  1244. * Overview:
  1245. * Opens the adapter
  1246. *
  1247. * Returns:
  1248. * Condition code
  1249. *
  1250. * Arguments:
  1251. * dev - pointer to device information
  1252. *
  1253. * Functional Description:
  1254. * This function brings the adapter to an operational state.
  1255. *
  1256. * Return Codes:
  1257. * 0 - Adapter was successfully opened
  1258. * -EAGAIN - Could not register IRQ or adapter initialization failed
  1259. *
  1260. * Assumptions:
  1261. * This routine should only be called for a device that was
  1262. * initialized successfully.
  1263. *
  1264. * Side Effects:
  1265. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1266. * if the open is successful.
  1267. */
  1268. static int dfx_open(struct net_device *dev)
  1269. {
  1270. DFX_board_t *bp = netdev_priv(dev);
  1271. int ret;
  1272. DBG_printk("In dfx_open...\n");
  1273. /* Register IRQ - support shared interrupts by passing device ptr */
  1274. ret = request_irq(dev->irq, dfx_interrupt, IRQF_SHARED, dev->name,
  1275. dev);
  1276. if (ret) {
  1277. printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
  1278. return ret;
  1279. }
  1280. /*
  1281. * Set current address to factory MAC address
  1282. *
  1283. * Note: We've already done this step in dfx_driver_init.
  1284. * However, it's possible that a user has set a node
  1285. * address override, then closed and reopened the
  1286. * adapter. Unless we reset the device address field
  1287. * now, we'll continue to use the existing modified
  1288. * address.
  1289. */
  1290. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  1291. /* Clear local unicast/multicast address tables and counts */
  1292. memset(bp->uc_table, 0, sizeof(bp->uc_table));
  1293. memset(bp->mc_table, 0, sizeof(bp->mc_table));
  1294. bp->uc_count = 0;
  1295. bp->mc_count = 0;
  1296. /* Disable promiscuous filter settings */
  1297. bp->ind_group_prom = PI_FSTATE_K_BLOCK;
  1298. bp->group_prom = PI_FSTATE_K_BLOCK;
  1299. spin_lock_init(&bp->lock);
  1300. /* Reset and initialize adapter */
  1301. bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST; /* skip self-test */
  1302. if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
  1303. {
  1304. printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
  1305. free_irq(dev->irq, dev);
  1306. return -EAGAIN;
  1307. }
  1308. /* Set device structure info */
  1309. netif_start_queue(dev);
  1310. return 0;
  1311. }
  1312. /*
  1313. * =============
  1314. * = dfx_close =
  1315. * =============
  1316. *
  1317. * Overview:
  1318. * Closes the device/module.
  1319. *
  1320. * Returns:
  1321. * Condition code
  1322. *
  1323. * Arguments:
  1324. * dev - pointer to device information
  1325. *
  1326. * Functional Description:
  1327. * This routine closes the adapter and brings it to a safe state.
  1328. * The interrupt service routine is deregistered with the OS.
  1329. * The adapter can be opened again with another call to dfx_open().
  1330. *
  1331. * Return Codes:
  1332. * Always return 0.
  1333. *
  1334. * Assumptions:
  1335. * No further requests for this adapter are made after this routine is
  1336. * called. dfx_open() can be called to reset and reinitialize the
  1337. * adapter.
  1338. *
  1339. * Side Effects:
  1340. * Adapter should be in DMA_UNAVAILABLE state upon completion of this
  1341. * routine.
  1342. */
  1343. static int dfx_close(struct net_device *dev)
  1344. {
  1345. DFX_board_t *bp = netdev_priv(dev);
  1346. DBG_printk("In dfx_close...\n");
  1347. /* Disable PDQ interrupts first */
  1348. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1349. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1350. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  1351. /*
  1352. * Flush any pending transmit buffers
  1353. *
  1354. * Note: It's important that we flush the transmit buffers
  1355. * BEFORE we clear our copy of the Type 2 register.
  1356. * Otherwise, we'll have no idea how many buffers
  1357. * we need to free.
  1358. */
  1359. dfx_xmt_flush(bp);
  1360. /*
  1361. * Clear Type 1 and Type 2 registers after adapter reset
  1362. *
  1363. * Note: Even though we're closing the adapter, it's
  1364. * possible that an interrupt will occur after
  1365. * dfx_close is called. Without some assurance to
  1366. * the contrary we want to make sure that we don't
  1367. * process receive and transmit LLC frames and update
  1368. * the Type 2 register with bad information.
  1369. */
  1370. bp->cmd_req_reg.lword = 0;
  1371. bp->cmd_rsp_reg.lword = 0;
  1372. bp->rcv_xmt_reg.lword = 0;
  1373. /* Clear consumer block for the same reason given above */
  1374. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1375. /* Release all dynamically allocate skb in the receive ring. */
  1376. dfx_rcv_flush(bp);
  1377. /* Clear device structure flags */
  1378. netif_stop_queue(dev);
  1379. /* Deregister (free) IRQ */
  1380. free_irq(dev->irq, dev);
  1381. return 0;
  1382. }
  1383. /*
  1384. * ======================
  1385. * = dfx_int_pr_halt_id =
  1386. * ======================
  1387. *
  1388. * Overview:
  1389. * Displays halt id's in string form.
  1390. *
  1391. * Returns:
  1392. * None
  1393. *
  1394. * Arguments:
  1395. * bp - pointer to board information
  1396. *
  1397. * Functional Description:
  1398. * Determine current halt id and display appropriate string.
  1399. *
  1400. * Return Codes:
  1401. * None
  1402. *
  1403. * Assumptions:
  1404. * None
  1405. *
  1406. * Side Effects:
  1407. * None
  1408. */
  1409. static void dfx_int_pr_halt_id(DFX_board_t *bp)
  1410. {
  1411. PI_UINT32 port_status; /* PDQ port status register value */
  1412. PI_UINT32 halt_id; /* PDQ port status halt ID */
  1413. /* Read the latest port status */
  1414. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  1415. /* Display halt state transition information */
  1416. halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
  1417. switch (halt_id)
  1418. {
  1419. case PI_HALT_ID_K_SELFTEST_TIMEOUT:
  1420. printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
  1421. break;
  1422. case PI_HALT_ID_K_PARITY_ERROR:
  1423. printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
  1424. break;
  1425. case PI_HALT_ID_K_HOST_DIR_HALT:
  1426. printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
  1427. break;
  1428. case PI_HALT_ID_K_SW_FAULT:
  1429. printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
  1430. break;
  1431. case PI_HALT_ID_K_HW_FAULT:
  1432. printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
  1433. break;
  1434. case PI_HALT_ID_K_PC_TRACE:
  1435. printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp->dev->name);
  1436. break;
  1437. case PI_HALT_ID_K_DMA_ERROR:
  1438. printk("%s: Halt ID: Adapter DMA Error\n", bp->dev->name);
  1439. break;
  1440. case PI_HALT_ID_K_IMAGE_CRC_ERROR:
  1441. printk("%s: Halt ID: Firmware Image CRC Error\n", bp->dev->name);
  1442. break;
  1443. case PI_HALT_ID_K_BUS_EXCEPTION:
  1444. printk("%s: Halt ID: 68000 Bus Exception\n", bp->dev->name);
  1445. break;
  1446. default:
  1447. printk("%s: Halt ID: Unknown (code = %X)\n", bp->dev->name, halt_id);
  1448. break;
  1449. }
  1450. }
  1451. /*
  1452. * ==========================
  1453. * = dfx_int_type_0_process =
  1454. * ==========================
  1455. *
  1456. * Overview:
  1457. * Processes Type 0 interrupts.
  1458. *
  1459. * Returns:
  1460. * None
  1461. *
  1462. * Arguments:
  1463. * bp - pointer to board information
  1464. *
  1465. * Functional Description:
  1466. * Processes all enabled Type 0 interrupts. If the reason for the interrupt
  1467. * is a serious fault on the adapter, then an error message is displayed
  1468. * and the adapter is reset.
  1469. *
  1470. * One tricky potential timing window is the rapid succession of "link avail"
  1471. * "link unavail" state change interrupts. The acknowledgement of the Type 0
  1472. * interrupt must be done before reading the state from the Port Status
  1473. * register. This is true because a state change could occur after reading
  1474. * the data, but before acknowledging the interrupt. If this state change
  1475. * does happen, it would be lost because the driver is using the old state,
  1476. * and it will never know about the new state because it subsequently
  1477. * acknowledges the state change interrupt.
  1478. *
  1479. * INCORRECT CORRECT
  1480. * read type 0 int reasons read type 0 int reasons
  1481. * read adapter state ack type 0 interrupts
  1482. * ack type 0 interrupts read adapter state
  1483. * ... process interrupt ... ... process interrupt ...
  1484. *
  1485. * Return Codes:
  1486. * None
  1487. *
  1488. * Assumptions:
  1489. * None
  1490. *
  1491. * Side Effects:
  1492. * An adapter reset may occur if the adapter has any Type 0 error interrupts
  1493. * or if the port status indicates that the adapter is halted. The driver
  1494. * is responsible for reinitializing the adapter with the current CAM
  1495. * contents and adapter filter settings.
  1496. */
  1497. static void dfx_int_type_0_process(DFX_board_t *bp)
  1498. {
  1499. PI_UINT32 type_0_status; /* Host Interrupt Type 0 register */
  1500. PI_UINT32 state; /* current adap state (from port status) */
  1501. /*
  1502. * Read host interrupt Type 0 register to determine which Type 0
  1503. * interrupts are pending. Immediately write it back out to clear
  1504. * those interrupts.
  1505. */
  1506. dfx_port_read_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, &type_0_status);
  1507. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, type_0_status);
  1508. /* Check for Type 0 error interrupts */
  1509. if (type_0_status & (PI_TYPE_0_STAT_M_NXM |
  1510. PI_TYPE_0_STAT_M_PM_PAR_ERR |
  1511. PI_TYPE_0_STAT_M_BUS_PAR_ERR))
  1512. {
  1513. /* Check for Non-Existent Memory error */
  1514. if (type_0_status & PI_TYPE_0_STAT_M_NXM)
  1515. printk("%s: Non-Existent Memory Access Error\n", bp->dev->name);
  1516. /* Check for Packet Memory Parity error */
  1517. if (type_0_status & PI_TYPE_0_STAT_M_PM_PAR_ERR)
  1518. printk("%s: Packet Memory Parity Error\n", bp->dev->name);
  1519. /* Check for Host Bus Parity error */
  1520. if (type_0_status & PI_TYPE_0_STAT_M_BUS_PAR_ERR)
  1521. printk("%s: Host Bus Parity Error\n", bp->dev->name);
  1522. /* Reset adapter and bring it back on-line */
  1523. bp->link_available = PI_K_FALSE; /* link is no longer available */
  1524. bp->reset_type = 0; /* rerun on-board diagnostics */
  1525. printk("%s: Resetting adapter...\n", bp->dev->name);
  1526. if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
  1527. {
  1528. printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
  1529. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1530. return;
  1531. }
  1532. printk("%s: Adapter reset successful!\n", bp->dev->name);
  1533. return;
  1534. }
  1535. /* Check for transmit flush interrupt */
  1536. if (type_0_status & PI_TYPE_0_STAT_M_XMT_FLUSH)
  1537. {
  1538. /* Flush any pending xmt's and acknowledge the flush interrupt */
  1539. bp->link_available = PI_K_FALSE; /* link is no longer available */
  1540. dfx_xmt_flush(bp); /* flush any outstanding packets */
  1541. (void) dfx_hw_port_ctrl_req(bp,
  1542. PI_PCTRL_M_XMT_DATA_FLUSH_DONE,
  1543. 0,
  1544. 0,
  1545. NULL);
  1546. }
  1547. /* Check for adapter state change */
  1548. if (type_0_status & PI_TYPE_0_STAT_M_STATE_CHANGE)
  1549. {
  1550. /* Get latest adapter state */
  1551. state = dfx_hw_adap_state_rd(bp); /* get adapter state */
  1552. if (state == PI_STATE_K_HALTED)
  1553. {
  1554. /*
  1555. * Adapter has transitioned to HALTED state, try to reset
  1556. * adapter to bring it back on-line. If reset fails,
  1557. * leave the adapter in the broken state.
  1558. */
  1559. printk("%s: Controller has transitioned to HALTED state!\n", bp->dev->name);
  1560. dfx_int_pr_halt_id(bp); /* display halt id as string */
  1561. /* Reset adapter and bring it back on-line */
  1562. bp->link_available = PI_K_FALSE; /* link is no longer available */
  1563. bp->reset_type = 0; /* rerun on-board diagnostics */
  1564. printk("%s: Resetting adapter...\n", bp->dev->name);
  1565. if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
  1566. {
  1567. printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
  1568. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1569. return;
  1570. }
  1571. printk("%s: Adapter reset successful!\n", bp->dev->name);
  1572. }
  1573. else if (state == PI_STATE_K_LINK_AVAIL)
  1574. {
  1575. bp->link_available = PI_K_TRUE; /* set link available flag */
  1576. }
  1577. }
  1578. }
  1579. /*
  1580. * ==================
  1581. * = dfx_int_common =
  1582. * ==================
  1583. *
  1584. * Overview:
  1585. * Interrupt service routine (ISR)
  1586. *
  1587. * Returns:
  1588. * None
  1589. *
  1590. * Arguments:
  1591. * bp - pointer to board information
  1592. *
  1593. * Functional Description:
  1594. * This is the ISR which processes incoming adapter interrupts.
  1595. *
  1596. * Return Codes:
  1597. * None
  1598. *
  1599. * Assumptions:
  1600. * This routine assumes PDQ interrupts have not been disabled.
  1601. * When interrupts are disabled at the PDQ, the Port Status register
  1602. * is automatically cleared. This routine uses the Port Status
  1603. * register value to determine whether a Type 0 interrupt occurred,
  1604. * so it's important that adapter interrupts are not normally
  1605. * enabled/disabled at the PDQ.
  1606. *
  1607. * It's vital that this routine is NOT reentered for the
  1608. * same board and that the OS is not in another section of
  1609. * code (eg. dfx_xmt_queue_pkt) for the same board on a
  1610. * different thread.
  1611. *
  1612. * Side Effects:
  1613. * Pending interrupts are serviced. Depending on the type of
  1614. * interrupt, acknowledging and clearing the interrupt at the
  1615. * PDQ involves writing a register to clear the interrupt bit
  1616. * or updating completion indices.
  1617. */
  1618. static void dfx_int_common(struct net_device *dev)
  1619. {
  1620. DFX_board_t *bp = netdev_priv(dev);
  1621. PI_UINT32 port_status; /* Port Status register */
  1622. /* Process xmt interrupts - frequent case, so always call this routine */
  1623. if(dfx_xmt_done(bp)) /* free consumed xmt packets */
  1624. netif_wake_queue(dev);
  1625. /* Process rcv interrupts - frequent case, so always call this routine */
  1626. dfx_rcv_queue_process(bp); /* service received LLC frames */
  1627. /*
  1628. * Transmit and receive producer and completion indices are updated on the
  1629. * adapter by writing to the Type 2 Producer register. Since the frequent
  1630. * case is that we'll be processing either LLC transmit or receive buffers,
  1631. * we'll optimize I/O writes by doing a single register write here.
  1632. */
  1633. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  1634. /* Read PDQ Port Status register to find out which interrupts need processing */
  1635. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  1636. /* Process Type 0 interrupts (if any) - infrequent, so only call when needed */
  1637. if (port_status & PI_PSTATUS_M_TYPE_0_PENDING)
  1638. dfx_int_type_0_process(bp); /* process Type 0 interrupts */
  1639. }
  1640. /*
  1641. * =================
  1642. * = dfx_interrupt =
  1643. * =================
  1644. *
  1645. * Overview:
  1646. * Interrupt processing routine
  1647. *
  1648. * Returns:
  1649. * Whether a valid interrupt was seen.
  1650. *
  1651. * Arguments:
  1652. * irq - interrupt vector
  1653. * dev_id - pointer to device information
  1654. *
  1655. * Functional Description:
  1656. * This routine calls the interrupt processing routine for this adapter. It
  1657. * disables and reenables adapter interrupts, as appropriate. We can support
  1658. * shared interrupts since the incoming dev_id pointer provides our device
  1659. * structure context.
  1660. *
  1661. * Return Codes:
  1662. * IRQ_HANDLED - an IRQ was handled.
  1663. * IRQ_NONE - no IRQ was handled.
  1664. *
  1665. * Assumptions:
  1666. * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
  1667. * on Intel-based systems) is done by the operating system outside this
  1668. * routine.
  1669. *
  1670. * System interrupts are enabled through this call.
  1671. *
  1672. * Side Effects:
  1673. * Interrupts are disabled, then reenabled at the adapter.
  1674. */
  1675. static irqreturn_t dfx_interrupt(int irq, void *dev_id)
  1676. {
  1677. struct net_device *dev = dev_id;
  1678. DFX_board_t *bp = netdev_priv(dev);
  1679. struct device *bdev = bp->bus_dev;
  1680. int dfx_bus_pci = dev_is_pci(bdev);
  1681. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  1682. int dfx_bus_tc = DFX_BUS_TC(bdev);
  1683. /* Service adapter interrupts */
  1684. if (dfx_bus_pci) {
  1685. u32 status;
  1686. dfx_port_read_long(bp, PFI_K_REG_STATUS, &status);
  1687. if (!(status & PFI_STATUS_M_PDQ_INT))
  1688. return IRQ_NONE;
  1689. spin_lock(&bp->lock);
  1690. /* Disable PDQ-PFI interrupts at PFI */
  1691. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
  1692. PFI_MODE_M_DMA_ENB);
  1693. /* Call interrupt service routine for this adapter */
  1694. dfx_int_common(dev);
  1695. /* Clear PDQ interrupt status bit and reenable interrupts */
  1696. dfx_port_write_long(bp, PFI_K_REG_STATUS,
  1697. PFI_STATUS_M_PDQ_INT);
  1698. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
  1699. (PFI_MODE_M_PDQ_INT_ENB |
  1700. PFI_MODE_M_DMA_ENB));
  1701. spin_unlock(&bp->lock);
  1702. }
  1703. if (dfx_bus_eisa) {
  1704. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  1705. u8 status;
  1706. status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  1707. if (!(status & PI_CONFIG_STAT_0_M_PEND))
  1708. return IRQ_NONE;
  1709. spin_lock(&bp->lock);
  1710. /* Disable interrupts at the ESIC */
  1711. status &= ~PI_CONFIG_STAT_0_M_INT_ENB;
  1712. outb(status, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  1713. /* Call interrupt service routine for this adapter */
  1714. dfx_int_common(dev);
  1715. /* Reenable interrupts at the ESIC */
  1716. status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  1717. status |= PI_CONFIG_STAT_0_M_INT_ENB;
  1718. outb(status, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  1719. spin_unlock(&bp->lock);
  1720. }
  1721. if (dfx_bus_tc) {
  1722. u32 status;
  1723. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &status);
  1724. if (!(status & (PI_PSTATUS_M_RCV_DATA_PENDING |
  1725. PI_PSTATUS_M_XMT_DATA_PENDING |
  1726. PI_PSTATUS_M_SMT_HOST_PENDING |
  1727. PI_PSTATUS_M_UNSOL_PENDING |
  1728. PI_PSTATUS_M_CMD_RSP_PENDING |
  1729. PI_PSTATUS_M_CMD_REQ_PENDING |
  1730. PI_PSTATUS_M_TYPE_0_PENDING)))
  1731. return IRQ_NONE;
  1732. spin_lock(&bp->lock);
  1733. /* Call interrupt service routine for this adapter */
  1734. dfx_int_common(dev);
  1735. spin_unlock(&bp->lock);
  1736. }
  1737. return IRQ_HANDLED;
  1738. }
  1739. /*
  1740. * =====================
  1741. * = dfx_ctl_get_stats =
  1742. * =====================
  1743. *
  1744. * Overview:
  1745. * Get statistics for FDDI adapter
  1746. *
  1747. * Returns:
  1748. * Pointer to FDDI statistics structure
  1749. *
  1750. * Arguments:
  1751. * dev - pointer to device information
  1752. *
  1753. * Functional Description:
  1754. * Gets current MIB objects from adapter, then
  1755. * returns FDDI statistics structure as defined
  1756. * in if_fddi.h.
  1757. *
  1758. * Note: Since the FDDI statistics structure is
  1759. * still new and the device structure doesn't
  1760. * have an FDDI-specific get statistics handler,
  1761. * we'll return the FDDI statistics structure as
  1762. * a pointer to an Ethernet statistics structure.
  1763. * That way, at least the first part of the statistics
  1764. * structure can be decoded properly, and it allows
  1765. * "smart" applications to perform a second cast to
  1766. * decode the FDDI-specific statistics.
  1767. *
  1768. * We'll have to pay attention to this routine as the
  1769. * device structure becomes more mature and LAN media
  1770. * independent.
  1771. *
  1772. * Return Codes:
  1773. * None
  1774. *
  1775. * Assumptions:
  1776. * None
  1777. *
  1778. * Side Effects:
  1779. * None
  1780. */
  1781. static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev)
  1782. {
  1783. DFX_board_t *bp = netdev_priv(dev);
  1784. /* Fill the bp->stats structure with driver-maintained counters */
  1785. bp->stats.gen.rx_packets = bp->rcv_total_frames;
  1786. bp->stats.gen.tx_packets = bp->xmt_total_frames;
  1787. bp->stats.gen.rx_bytes = bp->rcv_total_bytes;
  1788. bp->stats.gen.tx_bytes = bp->xmt_total_bytes;
  1789. bp->stats.gen.rx_errors = bp->rcv_crc_errors +
  1790. bp->rcv_frame_status_errors +
  1791. bp->rcv_length_errors;
  1792. bp->stats.gen.tx_errors = bp->xmt_length_errors;
  1793. bp->stats.gen.rx_dropped = bp->rcv_discards;
  1794. bp->stats.gen.tx_dropped = bp->xmt_discards;
  1795. bp->stats.gen.multicast = bp->rcv_multicast_frames;
  1796. bp->stats.gen.collisions = 0; /* always zero (0) for FDDI */
  1797. /* Get FDDI SMT MIB objects */
  1798. bp->cmd_req_virt->cmd_type = PI_CMD_K_SMT_MIB_GET;
  1799. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1800. return (struct net_device_stats *)&bp->stats;
  1801. /* Fill the bp->stats structure with the SMT MIB object values */
  1802. memcpy(bp->stats.smt_station_id, &bp->cmd_rsp_virt->smt_mib_get.smt_station_id, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_station_id));
  1803. bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
  1804. bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
  1805. bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
  1806. memcpy(bp->stats.smt_user_data, &bp->cmd_rsp_virt->smt_mib_get.smt_user_data, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_user_data));
  1807. bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
  1808. bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
  1809. bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
  1810. bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
  1811. bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
  1812. bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
  1813. bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
  1814. bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
  1815. bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
  1816. bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
  1817. bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
  1818. bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
  1819. bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
  1820. bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
  1821. bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
  1822. bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
  1823. bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
  1824. bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
  1825. bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
  1826. bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
  1827. bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
  1828. bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
  1829. bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
  1830. bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
  1831. memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
  1832. memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
  1833. memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
  1834. memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
  1835. bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
  1836. bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
  1837. bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
  1838. memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
  1839. bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
  1840. bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
  1841. bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
  1842. bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
  1843. bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
  1844. bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
  1845. bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
  1846. bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
  1847. bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
  1848. bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
  1849. bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
  1850. bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
  1851. bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
  1852. bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
  1853. bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
  1854. bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
  1855. memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
  1856. bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
  1857. bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
  1858. bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
  1859. bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
  1860. bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
  1861. bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
  1862. bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
  1863. bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
  1864. bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
  1865. bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
  1866. memcpy(&bp->stats.port_requested_paths[0*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
  1867. memcpy(&bp->stats.port_requested_paths[1*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
  1868. bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
  1869. bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
  1870. bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
  1871. bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
  1872. bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
  1873. bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
  1874. bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
  1875. bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
  1876. bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
  1877. bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
  1878. bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
  1879. bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
  1880. bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
  1881. bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
  1882. bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
  1883. bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
  1884. bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
  1885. bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
  1886. bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
  1887. bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
  1888. bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
  1889. bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
  1890. bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
  1891. bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
  1892. bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
  1893. bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
  1894. /* Get FDDI counters */
  1895. bp->cmd_req_virt->cmd_type = PI_CMD_K_CNTRS_GET;
  1896. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1897. return (struct net_device_stats *)&bp->stats;
  1898. /* Fill the bp->stats structure with the FDDI counter values */
  1899. bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
  1900. bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
  1901. bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
  1902. bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
  1903. bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
  1904. bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
  1905. bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
  1906. bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
  1907. bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
  1908. bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
  1909. bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
  1910. return (struct net_device_stats *)&bp->stats;
  1911. }
  1912. /*
  1913. * ==============================
  1914. * = dfx_ctl_set_multicast_list =
  1915. * ==============================
  1916. *
  1917. * Overview:
  1918. * Enable/Disable LLC frame promiscuous mode reception
  1919. * on the adapter and/or update multicast address table.
  1920. *
  1921. * Returns:
  1922. * None
  1923. *
  1924. * Arguments:
  1925. * dev - pointer to device information
  1926. *
  1927. * Functional Description:
  1928. * This routine follows a fairly simple algorithm for setting the
  1929. * adapter filters and CAM:
  1930. *
  1931. * if IFF_PROMISC flag is set
  1932. * enable LLC individual/group promiscuous mode
  1933. * else
  1934. * disable LLC individual/group promiscuous mode
  1935. * if number of incoming multicast addresses >
  1936. * (CAM max size - number of unicast addresses in CAM)
  1937. * enable LLC group promiscuous mode
  1938. * set driver-maintained multicast address count to zero
  1939. * else
  1940. * disable LLC group promiscuous mode
  1941. * set driver-maintained multicast address count to incoming count
  1942. * update adapter CAM
  1943. * update adapter filters
  1944. *
  1945. * Return Codes:
  1946. * None
  1947. *
  1948. * Assumptions:
  1949. * Multicast addresses are presented in canonical (LSB) format.
  1950. *
  1951. * Side Effects:
  1952. * On-board adapter CAM and filters are updated.
  1953. */
  1954. static void dfx_ctl_set_multicast_list(struct net_device *dev)
  1955. {
  1956. DFX_board_t *bp = netdev_priv(dev);
  1957. int i; /* used as index in for loop */
  1958. struct netdev_hw_addr *ha;
  1959. /* Enable LLC frame promiscuous mode, if necessary */
  1960. if (dev->flags & IFF_PROMISC)
  1961. bp->ind_group_prom = PI_FSTATE_K_PASS; /* Enable LLC ind/group prom mode */
  1962. /* Else, update multicast address table */
  1963. else
  1964. {
  1965. bp->ind_group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC ind/group prom mode */
  1966. /*
  1967. * Check whether incoming multicast address count exceeds table size
  1968. *
  1969. * Note: The adapters utilize an on-board 64 entry CAM for
  1970. * supporting perfect filtering of multicast packets
  1971. * and bridge functions when adding unicast addresses.
  1972. * There is no hash function available. To support
  1973. * additional multicast addresses, the all multicast
  1974. * filter (LLC group promiscuous mode) must be enabled.
  1975. *
  1976. * The firmware reserves two CAM entries for SMT-related
  1977. * multicast addresses, which leaves 62 entries available.
  1978. * The following code ensures that we're not being asked
  1979. * to add more than 62 addresses to the CAM. If we are,
  1980. * the driver will enable the all multicast filter.
  1981. * Should the number of multicast addresses drop below
  1982. * the high water mark, the filter will be disabled and
  1983. * perfect filtering will be used.
  1984. */
  1985. if (netdev_mc_count(dev) > (PI_CMD_ADDR_FILTER_K_SIZE - bp->uc_count))
  1986. {
  1987. bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
  1988. bp->mc_count = 0; /* Don't add mc addrs to CAM */
  1989. }
  1990. else
  1991. {
  1992. bp->group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC group prom mode */
  1993. bp->mc_count = netdev_mc_count(dev); /* Add mc addrs to CAM */
  1994. }
  1995. /* Copy addresses to multicast address table, then update adapter CAM */
  1996. i = 0;
  1997. netdev_for_each_mc_addr(ha, dev)
  1998. memcpy(&bp->mc_table[i++ * FDDI_K_ALEN],
  1999. ha->addr, FDDI_K_ALEN);
  2000. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  2001. {
  2002. DBG_printk("%s: Could not update multicast address table!\n", dev->name);
  2003. }
  2004. else
  2005. {
  2006. DBG_printk("%s: Multicast address table updated! Added %d addresses.\n", dev->name, bp->mc_count);
  2007. }
  2008. }
  2009. /* Update adapter filters */
  2010. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  2011. {
  2012. DBG_printk("%s: Could not update adapter filters!\n", dev->name);
  2013. }
  2014. else
  2015. {
  2016. DBG_printk("%s: Adapter filters updated!\n", dev->name);
  2017. }
  2018. }
  2019. /*
  2020. * ===========================
  2021. * = dfx_ctl_set_mac_address =
  2022. * ===========================
  2023. *
  2024. * Overview:
  2025. * Add node address override (unicast address) to adapter
  2026. * CAM and update dev_addr field in device table.
  2027. *
  2028. * Returns:
  2029. * None
  2030. *
  2031. * Arguments:
  2032. * dev - pointer to device information
  2033. * addr - pointer to sockaddr structure containing unicast address to add
  2034. *
  2035. * Functional Description:
  2036. * The adapter supports node address overrides by adding one or more
  2037. * unicast addresses to the adapter CAM. This is similar to adding
  2038. * multicast addresses. In this routine we'll update the driver and
  2039. * device structures with the new address, then update the adapter CAM
  2040. * to ensure that the adapter will copy and strip frames destined and
  2041. * sourced by that address.
  2042. *
  2043. * Return Codes:
  2044. * Always returns zero.
  2045. *
  2046. * Assumptions:
  2047. * The address pointed to by addr->sa_data is a valid unicast
  2048. * address and is presented in canonical (LSB) format.
  2049. *
  2050. * Side Effects:
  2051. * On-board adapter CAM is updated. On-board adapter filters
  2052. * may be updated.
  2053. */
  2054. static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)
  2055. {
  2056. struct sockaddr *p_sockaddr = (struct sockaddr *)addr;
  2057. DFX_board_t *bp = netdev_priv(dev);
  2058. /* Copy unicast address to driver-maintained structs and update count */
  2059. memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN); /* update device struct */
  2060. memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN); /* update driver struct */
  2061. bp->uc_count = 1;
  2062. /*
  2063. * Verify we're not exceeding the CAM size by adding unicast address
  2064. *
  2065. * Note: It's possible that before entering this routine we've
  2066. * already filled the CAM with 62 multicast addresses.
  2067. * Since we need to place the node address override into
  2068. * the CAM, we have to check to see that we're not
  2069. * exceeding the CAM size. If we are, we have to enable
  2070. * the LLC group (multicast) promiscuous mode filter as
  2071. * in dfx_ctl_set_multicast_list.
  2072. */
  2073. if ((bp->uc_count + bp->mc_count) > PI_CMD_ADDR_FILTER_K_SIZE)
  2074. {
  2075. bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
  2076. bp->mc_count = 0; /* Don't add mc addrs to CAM */
  2077. /* Update adapter filters */
  2078. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  2079. {
  2080. DBG_printk("%s: Could not update adapter filters!\n", dev->name);
  2081. }
  2082. else
  2083. {
  2084. DBG_printk("%s: Adapter filters updated!\n", dev->name);
  2085. }
  2086. }
  2087. /* Update adapter CAM with new unicast address */
  2088. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  2089. {
  2090. DBG_printk("%s: Could not set new MAC address!\n", dev->name);
  2091. }
  2092. else
  2093. {
  2094. DBG_printk("%s: Adapter CAM updated with new MAC address\n", dev->name);
  2095. }
  2096. return 0; /* always return zero */
  2097. }
  2098. /*
  2099. * ======================
  2100. * = dfx_ctl_update_cam =
  2101. * ======================
  2102. *
  2103. * Overview:
  2104. * Procedure to update adapter CAM (Content Addressable Memory)
  2105. * with desired unicast and multicast address entries.
  2106. *
  2107. * Returns:
  2108. * Condition code
  2109. *
  2110. * Arguments:
  2111. * bp - pointer to board information
  2112. *
  2113. * Functional Description:
  2114. * Updates adapter CAM with current contents of board structure
  2115. * unicast and multicast address tables. Since there are only 62
  2116. * free entries in CAM, this routine ensures that the command
  2117. * request buffer is not overrun.
  2118. *
  2119. * Return Codes:
  2120. * DFX_K_SUCCESS - Request succeeded
  2121. * DFX_K_FAILURE - Request failed
  2122. *
  2123. * Assumptions:
  2124. * All addresses being added (unicast and multicast) are in canonical
  2125. * order.
  2126. *
  2127. * Side Effects:
  2128. * On-board adapter CAM is updated.
  2129. */
  2130. static int dfx_ctl_update_cam(DFX_board_t *bp)
  2131. {
  2132. int i; /* used as index */
  2133. PI_LAN_ADDR *p_addr; /* pointer to CAM entry */
  2134. /*
  2135. * Fill in command request information
  2136. *
  2137. * Note: Even though both the unicast and multicast address
  2138. * table entries are stored as contiguous 6 byte entries,
  2139. * the firmware address filter set command expects each
  2140. * entry to be two longwords (8 bytes total). We must be
  2141. * careful to only copy the six bytes of each unicast and
  2142. * multicast table entry into each command entry. This
  2143. * is also why we must first clear the entire command
  2144. * request buffer.
  2145. */
  2146. memset(bp->cmd_req_virt, 0, PI_CMD_REQ_K_SIZE_MAX); /* first clear buffer */
  2147. bp->cmd_req_virt->cmd_type = PI_CMD_K_ADDR_FILTER_SET;
  2148. p_addr = &bp->cmd_req_virt->addr_filter_set.entry[0];
  2149. /* Now add unicast addresses to command request buffer, if any */
  2150. for (i=0; i < (int)bp->uc_count; i++)
  2151. {
  2152. if (i < PI_CMD_ADDR_FILTER_K_SIZE)
  2153. {
  2154. memcpy(p_addr, &bp->uc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
  2155. p_addr++; /* point to next command entry */
  2156. }
  2157. }
  2158. /* Now add multicast addresses to command request buffer, if any */
  2159. for (i=0; i < (int)bp->mc_count; i++)
  2160. {
  2161. if ((i + bp->uc_count) < PI_CMD_ADDR_FILTER_K_SIZE)
  2162. {
  2163. memcpy(p_addr, &bp->mc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
  2164. p_addr++; /* point to next command entry */
  2165. }
  2166. }
  2167. /* Issue command to update adapter CAM, then return */
  2168. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  2169. return DFX_K_FAILURE;
  2170. return DFX_K_SUCCESS;
  2171. }
  2172. /*
  2173. * ==========================
  2174. * = dfx_ctl_update_filters =
  2175. * ==========================
  2176. *
  2177. * Overview:
  2178. * Procedure to update adapter filters with desired
  2179. * filter settings.
  2180. *
  2181. * Returns:
  2182. * Condition code
  2183. *
  2184. * Arguments:
  2185. * bp - pointer to board information
  2186. *
  2187. * Functional Description:
  2188. * Enables or disables filter using current filter settings.
  2189. *
  2190. * Return Codes:
  2191. * DFX_K_SUCCESS - Request succeeded.
  2192. * DFX_K_FAILURE - Request failed.
  2193. *
  2194. * Assumptions:
  2195. * We must always pass up packets destined to the broadcast
  2196. * address (FF-FF-FF-FF-FF-FF), so we'll always keep the
  2197. * broadcast filter enabled.
  2198. *
  2199. * Side Effects:
  2200. * On-board adapter filters are updated.
  2201. */
  2202. static int dfx_ctl_update_filters(DFX_board_t *bp)
  2203. {
  2204. int i = 0; /* used as index */
  2205. /* Fill in command request information */
  2206. bp->cmd_req_virt->cmd_type = PI_CMD_K_FILTERS_SET;
  2207. /* Initialize Broadcast filter - * ALWAYS ENABLED * */
  2208. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_BROADCAST;
  2209. bp->cmd_req_virt->filter_set.item[i++].value = PI_FSTATE_K_PASS;
  2210. /* Initialize LLC Individual/Group Promiscuous filter */
  2211. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_IND_GROUP_PROM;
  2212. bp->cmd_req_virt->filter_set.item[i++].value = bp->ind_group_prom;
  2213. /* Initialize LLC Group Promiscuous filter */
  2214. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_GROUP_PROM;
  2215. bp->cmd_req_virt->filter_set.item[i++].value = bp->group_prom;
  2216. /* Terminate the item code list */
  2217. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_EOL;
  2218. /* Issue command to update adapter filters, then return */
  2219. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  2220. return DFX_K_FAILURE;
  2221. return DFX_K_SUCCESS;
  2222. }
  2223. /*
  2224. * ======================
  2225. * = dfx_hw_dma_cmd_req =
  2226. * ======================
  2227. *
  2228. * Overview:
  2229. * Sends PDQ DMA command to adapter firmware
  2230. *
  2231. * Returns:
  2232. * Condition code
  2233. *
  2234. * Arguments:
  2235. * bp - pointer to board information
  2236. *
  2237. * Functional Description:
  2238. * The command request and response buffers are posted to the adapter in the manner
  2239. * described in the PDQ Port Specification:
  2240. *
  2241. * 1. Command Response Buffer is posted to adapter.
  2242. * 2. Command Request Buffer is posted to adapter.
  2243. * 3. Command Request consumer index is polled until it indicates that request
  2244. * buffer has been DMA'd to adapter.
  2245. * 4. Command Response consumer index is polled until it indicates that response
  2246. * buffer has been DMA'd from adapter.
  2247. *
  2248. * This ordering ensures that a response buffer is already available for the firmware
  2249. * to use once it's done processing the request buffer.
  2250. *
  2251. * Return Codes:
  2252. * DFX_K_SUCCESS - DMA command succeeded
  2253. * DFX_K_OUTSTATE - Adapter is NOT in proper state
  2254. * DFX_K_HW_TIMEOUT - DMA command timed out
  2255. *
  2256. * Assumptions:
  2257. * Command request buffer has already been filled with desired DMA command.
  2258. *
  2259. * Side Effects:
  2260. * None
  2261. */
  2262. static int dfx_hw_dma_cmd_req(DFX_board_t *bp)
  2263. {
  2264. int status; /* adapter status */
  2265. int timeout_cnt; /* used in for loops */
  2266. /* Make sure the adapter is in a state that we can issue the DMA command in */
  2267. status = dfx_hw_adap_state_rd(bp);
  2268. if ((status == PI_STATE_K_RESET) ||
  2269. (status == PI_STATE_K_HALTED) ||
  2270. (status == PI_STATE_K_DMA_UNAVAIL) ||
  2271. (status == PI_STATE_K_UPGRADE))
  2272. return DFX_K_OUTSTATE;
  2273. /* Put response buffer on the command response queue */
  2274. bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  2275. ((PI_CMD_RSP_K_SIZE_MAX / PI_ALIGN_K_CMD_RSP_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  2276. bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_1 = bp->cmd_rsp_phys;
  2277. /* Bump (and wrap) the producer index and write out to register */
  2278. bp->cmd_rsp_reg.index.prod += 1;
  2279. bp->cmd_rsp_reg.index.prod &= PI_CMD_RSP_K_NUM_ENTRIES-1;
  2280. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
  2281. /* Put request buffer on the command request queue */
  2282. bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_0 = (u32) (PI_XMT_DESCR_M_SOP |
  2283. PI_XMT_DESCR_M_EOP | (PI_CMD_REQ_K_SIZE_MAX << PI_XMT_DESCR_V_SEG_LEN));
  2284. bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_1 = bp->cmd_req_phys;
  2285. /* Bump (and wrap) the producer index and write out to register */
  2286. bp->cmd_req_reg.index.prod += 1;
  2287. bp->cmd_req_reg.index.prod &= PI_CMD_REQ_K_NUM_ENTRIES-1;
  2288. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
  2289. /*
  2290. * Here we wait for the command request consumer index to be equal
  2291. * to the producer, indicating that the adapter has DMAed the request.
  2292. */
  2293. for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
  2294. {
  2295. if (bp->cmd_req_reg.index.prod == (u8)(bp->cons_block_virt->cmd_req))
  2296. break;
  2297. udelay(100); /* wait for 100 microseconds */
  2298. }
  2299. if (timeout_cnt == 0)
  2300. return DFX_K_HW_TIMEOUT;
  2301. /* Bump (and wrap) the completion index and write out to register */
  2302. bp->cmd_req_reg.index.comp += 1;
  2303. bp->cmd_req_reg.index.comp &= PI_CMD_REQ_K_NUM_ENTRIES-1;
  2304. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
  2305. /*
  2306. * Here we wait for the command response consumer index to be equal
  2307. * to the producer, indicating that the adapter has DMAed the response.
  2308. */
  2309. for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
  2310. {
  2311. if (bp->cmd_rsp_reg.index.prod == (u8)(bp->cons_block_virt->cmd_rsp))
  2312. break;
  2313. udelay(100); /* wait for 100 microseconds */
  2314. }
  2315. if (timeout_cnt == 0)
  2316. return DFX_K_HW_TIMEOUT;
  2317. /* Bump (and wrap) the completion index and write out to register */
  2318. bp->cmd_rsp_reg.index.comp += 1;
  2319. bp->cmd_rsp_reg.index.comp &= PI_CMD_RSP_K_NUM_ENTRIES-1;
  2320. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
  2321. return DFX_K_SUCCESS;
  2322. }
  2323. /*
  2324. * ========================
  2325. * = dfx_hw_port_ctrl_req =
  2326. * ========================
  2327. *
  2328. * Overview:
  2329. * Sends PDQ port control command to adapter firmware
  2330. *
  2331. * Returns:
  2332. * Host data register value in host_data if ptr is not NULL
  2333. *
  2334. * Arguments:
  2335. * bp - pointer to board information
  2336. * command - port control command
  2337. * data_a - port data A register value
  2338. * data_b - port data B register value
  2339. * host_data - ptr to host data register value
  2340. *
  2341. * Functional Description:
  2342. * Send generic port control command to adapter by writing
  2343. * to various PDQ port registers, then polling for completion.
  2344. *
  2345. * Return Codes:
  2346. * DFX_K_SUCCESS - port control command succeeded
  2347. * DFX_K_HW_TIMEOUT - port control command timed out
  2348. *
  2349. * Assumptions:
  2350. * None
  2351. *
  2352. * Side Effects:
  2353. * None
  2354. */
  2355. static int dfx_hw_port_ctrl_req(
  2356. DFX_board_t *bp,
  2357. PI_UINT32 command,
  2358. PI_UINT32 data_a,
  2359. PI_UINT32 data_b,
  2360. PI_UINT32 *host_data
  2361. )
  2362. {
  2363. PI_UINT32 port_cmd; /* Port Control command register value */
  2364. int timeout_cnt; /* used in for loops */
  2365. /* Set Command Error bit in command longword */
  2366. port_cmd = (PI_UINT32) (command | PI_PCTRL_M_CMD_ERROR);
  2367. /* Issue port command to the adapter */
  2368. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, data_a);
  2369. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_B, data_b);
  2370. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_CTRL, port_cmd);
  2371. /* Now wait for command to complete */
  2372. if (command == PI_PCTRL_M_BLAST_FLASH)
  2373. timeout_cnt = 600000; /* set command timeout count to 60 seconds */
  2374. else
  2375. timeout_cnt = 20000; /* set command timeout count to 2 seconds */
  2376. for (; timeout_cnt > 0; timeout_cnt--)
  2377. {
  2378. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_CTRL, &port_cmd);
  2379. if (!(port_cmd & PI_PCTRL_M_CMD_ERROR))
  2380. break;
  2381. udelay(100); /* wait for 100 microseconds */
  2382. }
  2383. if (timeout_cnt == 0)
  2384. return DFX_K_HW_TIMEOUT;
  2385. /*
  2386. * If the address of host_data is non-zero, assume caller has supplied a
  2387. * non NULL pointer, and return the contents of the HOST_DATA register in
  2388. * it.
  2389. */
  2390. if (host_data != NULL)
  2391. dfx_port_read_long(bp, PI_PDQ_K_REG_HOST_DATA, host_data);
  2392. return DFX_K_SUCCESS;
  2393. }
  2394. /*
  2395. * =====================
  2396. * = dfx_hw_adap_reset =
  2397. * =====================
  2398. *
  2399. * Overview:
  2400. * Resets adapter
  2401. *
  2402. * Returns:
  2403. * None
  2404. *
  2405. * Arguments:
  2406. * bp - pointer to board information
  2407. * type - type of reset to perform
  2408. *
  2409. * Functional Description:
  2410. * Issue soft reset to adapter by writing to PDQ Port Reset
  2411. * register. Use incoming reset type to tell adapter what
  2412. * kind of reset operation to perform.
  2413. *
  2414. * Return Codes:
  2415. * None
  2416. *
  2417. * Assumptions:
  2418. * This routine merely issues a soft reset to the adapter.
  2419. * It is expected that after this routine returns, the caller
  2420. * will appropriately poll the Port Status register for the
  2421. * adapter to enter the proper state.
  2422. *
  2423. * Side Effects:
  2424. * Internal adapter registers are cleared.
  2425. */
  2426. static void dfx_hw_adap_reset(
  2427. DFX_board_t *bp,
  2428. PI_UINT32 type
  2429. )
  2430. {
  2431. /* Set Reset type and assert reset */
  2432. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, type); /* tell adapter type of reset */
  2433. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, PI_RESET_M_ASSERT_RESET);
  2434. /* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */
  2435. udelay(20);
  2436. /* Deassert reset */
  2437. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, 0);
  2438. }
  2439. /*
  2440. * ========================
  2441. * = dfx_hw_adap_state_rd =
  2442. * ========================
  2443. *
  2444. * Overview:
  2445. * Returns current adapter state
  2446. *
  2447. * Returns:
  2448. * Adapter state per PDQ Port Specification
  2449. *
  2450. * Arguments:
  2451. * bp - pointer to board information
  2452. *
  2453. * Functional Description:
  2454. * Reads PDQ Port Status register and returns adapter state.
  2455. *
  2456. * Return Codes:
  2457. * None
  2458. *
  2459. * Assumptions:
  2460. * None
  2461. *
  2462. * Side Effects:
  2463. * None
  2464. */
  2465. static int dfx_hw_adap_state_rd(DFX_board_t *bp)
  2466. {
  2467. PI_UINT32 port_status; /* Port Status register value */
  2468. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  2469. return (port_status & PI_PSTATUS_M_STATE) >> PI_PSTATUS_V_STATE;
  2470. }
  2471. /*
  2472. * =====================
  2473. * = dfx_hw_dma_uninit =
  2474. * =====================
  2475. *
  2476. * Overview:
  2477. * Brings adapter to DMA_UNAVAILABLE state
  2478. *
  2479. * Returns:
  2480. * Condition code
  2481. *
  2482. * Arguments:
  2483. * bp - pointer to board information
  2484. * type - type of reset to perform
  2485. *
  2486. * Functional Description:
  2487. * Bring adapter to DMA_UNAVAILABLE state by performing the following:
  2488. * 1. Set reset type bit in Port Data A Register then reset adapter.
  2489. * 2. Check that adapter is in DMA_UNAVAILABLE state.
  2490. *
  2491. * Return Codes:
  2492. * DFX_K_SUCCESS - adapter is in DMA_UNAVAILABLE state
  2493. * DFX_K_HW_TIMEOUT - adapter did not reset properly
  2494. *
  2495. * Assumptions:
  2496. * None
  2497. *
  2498. * Side Effects:
  2499. * Internal adapter registers are cleared.
  2500. */
  2501. static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type)
  2502. {
  2503. int timeout_cnt; /* used in for loops */
  2504. /* Set reset type bit and reset adapter */
  2505. dfx_hw_adap_reset(bp, type);
  2506. /* Now wait for adapter to enter DMA_UNAVAILABLE state */
  2507. for (timeout_cnt = 100000; timeout_cnt > 0; timeout_cnt--)
  2508. {
  2509. if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_DMA_UNAVAIL)
  2510. break;
  2511. udelay(100); /* wait for 100 microseconds */
  2512. }
  2513. if (timeout_cnt == 0)
  2514. return DFX_K_HW_TIMEOUT;
  2515. return DFX_K_SUCCESS;
  2516. }
  2517. /*
  2518. * Align an sk_buff to a boundary power of 2
  2519. *
  2520. */
  2521. #ifdef DYNAMIC_BUFFERS
  2522. static void my_skb_align(struct sk_buff *skb, int n)
  2523. {
  2524. unsigned long x = (unsigned long)skb->data;
  2525. unsigned long v;
  2526. v = ALIGN(x, n); /* Where we want to be */
  2527. skb_reserve(skb, v - x);
  2528. }
  2529. #endif
  2530. /*
  2531. * ================
  2532. * = dfx_rcv_init =
  2533. * ================
  2534. *
  2535. * Overview:
  2536. * Produces buffers to adapter LLC Host receive descriptor block
  2537. *
  2538. * Returns:
  2539. * None
  2540. *
  2541. * Arguments:
  2542. * bp - pointer to board information
  2543. * get_buffers - non-zero if buffers to be allocated
  2544. *
  2545. * Functional Description:
  2546. * This routine can be called during dfx_adap_init() or during an adapter
  2547. * reset. It initializes the descriptor block and produces all allocated
  2548. * LLC Host queue receive buffers.
  2549. *
  2550. * Return Codes:
  2551. * Return 0 on success or -ENOMEM if buffer allocation failed (when using
  2552. * dynamic buffer allocation). If the buffer allocation failed, the
  2553. * already allocated buffers will not be released and the caller should do
  2554. * this.
  2555. *
  2556. * Assumptions:
  2557. * The PDQ has been reset and the adapter and driver maintained Type 2
  2558. * register indices are cleared.
  2559. *
  2560. * Side Effects:
  2561. * Receive buffers are posted to the adapter LLC queue and the adapter
  2562. * is notified.
  2563. */
  2564. static int dfx_rcv_init(DFX_board_t *bp, int get_buffers)
  2565. {
  2566. int i, j; /* used in for loop */
  2567. /*
  2568. * Since each receive buffer is a single fragment of same length, initialize
  2569. * first longword in each receive descriptor for entire LLC Host descriptor
  2570. * block. Also initialize second longword in each receive descriptor with
  2571. * physical address of receive buffer. We'll always allocate receive
  2572. * buffers in powers of 2 so that we can easily fill the 256 entry descriptor
  2573. * block and produce new receive buffers by simply updating the receive
  2574. * producer index.
  2575. *
  2576. * Assumptions:
  2577. * To support all shipping versions of PDQ, the receive buffer size
  2578. * must be mod 128 in length and the physical address must be 128 byte
  2579. * aligned. In other words, bits 0-6 of the length and address must
  2580. * be zero for the following descriptor field entries to be correct on
  2581. * all PDQ-based boards. We guaranteed both requirements during
  2582. * driver initialization when we allocated memory for the receive buffers.
  2583. */
  2584. if (get_buffers) {
  2585. #ifdef DYNAMIC_BUFFERS
  2586. for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
  2587. for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  2588. {
  2589. struct sk_buff *newskb;
  2590. dma_addr_t dma_addr;
  2591. newskb = __netdev_alloc_skb(bp->dev, NEW_SKB_SIZE,
  2592. GFP_NOIO);
  2593. if (!newskb)
  2594. return -ENOMEM;
  2595. /*
  2596. * align to 128 bytes for compatibility with
  2597. * the old EISA boards.
  2598. */
  2599. my_skb_align(newskb, 128);
  2600. dma_addr = dma_map_single(bp->bus_dev,
  2601. newskb->data,
  2602. PI_RCV_DATA_K_SIZE_MAX,
  2603. DMA_FROM_DEVICE);
  2604. if (dma_mapping_error(bp->bus_dev, dma_addr)) {
  2605. dev_kfree_skb(newskb);
  2606. return -ENOMEM;
  2607. }
  2608. bp->descr_block_virt->rcv_data[i + j].long_0 =
  2609. (u32)(PI_RCV_DESCR_M_SOP |
  2610. ((PI_RCV_DATA_K_SIZE_MAX /
  2611. PI_ALIGN_K_RCV_DATA_BUFF) <<
  2612. PI_RCV_DESCR_V_SEG_LEN));
  2613. bp->descr_block_virt->rcv_data[i + j].long_1 =
  2614. (u32)dma_addr;
  2615. /*
  2616. * p_rcv_buff_va is only used inside the
  2617. * kernel so we put the skb pointer here.
  2618. */
  2619. bp->p_rcv_buff_va[i+j] = (char *) newskb;
  2620. }
  2621. #else
  2622. for (i=0; i < (int)(bp->rcv_bufs_to_post); i++)
  2623. for (j=0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  2624. {
  2625. bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  2626. ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  2627. bp->descr_block_virt->rcv_data[i+j].long_1 = (u32) (bp->rcv_block_phys + (i * PI_RCV_DATA_K_SIZE_MAX));
  2628. bp->p_rcv_buff_va[i+j] = (bp->rcv_block_virt + (i * PI_RCV_DATA_K_SIZE_MAX));
  2629. }
  2630. #endif
  2631. }
  2632. /* Update receive producer and Type 2 register */
  2633. bp->rcv_xmt_reg.index.rcv_prod = bp->rcv_bufs_to_post;
  2634. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  2635. return 0;
  2636. }
  2637. /*
  2638. * =========================
  2639. * = dfx_rcv_queue_process =
  2640. * =========================
  2641. *
  2642. * Overview:
  2643. * Process received LLC frames.
  2644. *
  2645. * Returns:
  2646. * None
  2647. *
  2648. * Arguments:
  2649. * bp - pointer to board information
  2650. *
  2651. * Functional Description:
  2652. * Received LLC frames are processed until there are no more consumed frames.
  2653. * Once all frames are processed, the receive buffers are returned to the
  2654. * adapter. Note that this algorithm fixes the length of time that can be spent
  2655. * in this routine, because there are a fixed number of receive buffers to
  2656. * process and buffers are not produced until this routine exits and returns
  2657. * to the ISR.
  2658. *
  2659. * Return Codes:
  2660. * None
  2661. *
  2662. * Assumptions:
  2663. * None
  2664. *
  2665. * Side Effects:
  2666. * None
  2667. */
  2668. static void dfx_rcv_queue_process(
  2669. DFX_board_t *bp
  2670. )
  2671. {
  2672. PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
  2673. char *p_buff; /* ptr to start of packet receive buffer (FMC descriptor) */
  2674. u32 descr, pkt_len; /* FMC descriptor field and packet length */
  2675. struct sk_buff *skb = NULL; /* pointer to a sk_buff to hold incoming packet data */
  2676. /* Service all consumed LLC receive frames */
  2677. p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
  2678. while (bp->rcv_xmt_reg.index.rcv_comp != p_type_2_cons->index.rcv_cons)
  2679. {
  2680. /* Process any errors */
  2681. dma_addr_t dma_addr;
  2682. int entry;
  2683. entry = bp->rcv_xmt_reg.index.rcv_comp;
  2684. #ifdef DYNAMIC_BUFFERS
  2685. p_buff = (char *) (((struct sk_buff *)bp->p_rcv_buff_va[entry])->data);
  2686. #else
  2687. p_buff = bp->p_rcv_buff_va[entry];
  2688. #endif
  2689. dma_addr = bp->descr_block_virt->rcv_data[entry].long_1;
  2690. dma_sync_single_for_cpu(bp->bus_dev,
  2691. dma_addr + RCV_BUFF_K_DESCR,
  2692. sizeof(u32),
  2693. DMA_FROM_DEVICE);
  2694. memcpy(&descr, p_buff + RCV_BUFF_K_DESCR, sizeof(u32));
  2695. if (descr & PI_FMC_DESCR_M_RCC_FLUSH)
  2696. {
  2697. if (descr & PI_FMC_DESCR_M_RCC_CRC)
  2698. bp->rcv_crc_errors++;
  2699. else
  2700. bp->rcv_frame_status_errors++;
  2701. }
  2702. else
  2703. {
  2704. int rx_in_place = 0;
  2705. /* The frame was received without errors - verify packet length */
  2706. pkt_len = (u32)((descr & PI_FMC_DESCR_M_LEN) >> PI_FMC_DESCR_V_LEN);
  2707. pkt_len -= 4; /* subtract 4 byte CRC */
  2708. if (!IN_RANGE(pkt_len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
  2709. bp->rcv_length_errors++;
  2710. else{
  2711. #ifdef DYNAMIC_BUFFERS
  2712. struct sk_buff *newskb = NULL;
  2713. if (pkt_len > SKBUFF_RX_COPYBREAK) {
  2714. dma_addr_t new_dma_addr;
  2715. newskb = netdev_alloc_skb(bp->dev,
  2716. NEW_SKB_SIZE);
  2717. if (newskb){
  2718. my_skb_align(newskb, 128);
  2719. new_dma_addr = dma_map_single(
  2720. bp->bus_dev,
  2721. newskb->data,
  2722. PI_RCV_DATA_K_SIZE_MAX,
  2723. DMA_FROM_DEVICE);
  2724. if (dma_mapping_error(
  2725. bp->bus_dev,
  2726. new_dma_addr)) {
  2727. dev_kfree_skb(newskb);
  2728. newskb = NULL;
  2729. }
  2730. }
  2731. if (newskb) {
  2732. rx_in_place = 1;
  2733. skb = (struct sk_buff *)bp->p_rcv_buff_va[entry];
  2734. dma_unmap_single(bp->bus_dev,
  2735. dma_addr,
  2736. PI_RCV_DATA_K_SIZE_MAX,
  2737. DMA_FROM_DEVICE);
  2738. skb_reserve(skb, RCV_BUFF_K_PADDING);
  2739. bp->p_rcv_buff_va[entry] = (char *)newskb;
  2740. bp->descr_block_virt->rcv_data[entry].long_1 = (u32)new_dma_addr;
  2741. }
  2742. }
  2743. if (!newskb)
  2744. #endif
  2745. /* Alloc new buffer to pass up,
  2746. * add room for PRH. */
  2747. skb = netdev_alloc_skb(bp->dev,
  2748. pkt_len + 3);
  2749. if (skb == NULL)
  2750. {
  2751. printk("%s: Could not allocate receive buffer. Dropping packet.\n", bp->dev->name);
  2752. bp->rcv_discards++;
  2753. break;
  2754. }
  2755. else {
  2756. if (!rx_in_place) {
  2757. /* Receive buffer allocated, pass receive packet up */
  2758. dma_sync_single_for_cpu(
  2759. bp->bus_dev,
  2760. dma_addr +
  2761. RCV_BUFF_K_PADDING,
  2762. pkt_len + 3,
  2763. DMA_FROM_DEVICE);
  2764. skb_copy_to_linear_data(skb,
  2765. p_buff + RCV_BUFF_K_PADDING,
  2766. pkt_len + 3);
  2767. }
  2768. skb_reserve(skb,3); /* adjust data field so that it points to FC byte */
  2769. skb_put(skb, pkt_len); /* pass up packet length, NOT including CRC */
  2770. skb->protocol = fddi_type_trans(skb, bp->dev);
  2771. bp->rcv_total_bytes += skb->len;
  2772. netif_rx(skb);
  2773. /* Update the rcv counters */
  2774. bp->rcv_total_frames++;
  2775. if (*(p_buff + RCV_BUFF_K_DA) & 0x01)
  2776. bp->rcv_multicast_frames++;
  2777. }
  2778. }
  2779. }
  2780. /*
  2781. * Advance the producer (for recycling) and advance the completion
  2782. * (for servicing received frames). Note that it is okay to
  2783. * advance the producer without checking that it passes the
  2784. * completion index because they are both advanced at the same
  2785. * rate.
  2786. */
  2787. bp->rcv_xmt_reg.index.rcv_prod += 1;
  2788. bp->rcv_xmt_reg.index.rcv_comp += 1;
  2789. }
  2790. }
  2791. /*
  2792. * =====================
  2793. * = dfx_xmt_queue_pkt =
  2794. * =====================
  2795. *
  2796. * Overview:
  2797. * Queues packets for transmission
  2798. *
  2799. * Returns:
  2800. * Condition code
  2801. *
  2802. * Arguments:
  2803. * skb - pointer to sk_buff to queue for transmission
  2804. * dev - pointer to device information
  2805. *
  2806. * Functional Description:
  2807. * Here we assume that an incoming skb transmit request
  2808. * is contained in a single physically contiguous buffer
  2809. * in which the virtual address of the start of packet
  2810. * (skb->data) can be converted to a physical address
  2811. * by using pci_map_single().
  2812. *
  2813. * Since the adapter architecture requires a three byte
  2814. * packet request header to prepend the start of packet,
  2815. * we'll write the three byte field immediately prior to
  2816. * the FC byte. This assumption is valid because we've
  2817. * ensured that dev->hard_header_len includes three pad
  2818. * bytes. By posting a single fragment to the adapter,
  2819. * we'll reduce the number of descriptor fetches and
  2820. * bus traffic needed to send the request.
  2821. *
  2822. * Also, we can't free the skb until after it's been DMA'd
  2823. * out by the adapter, so we'll queue it in the driver and
  2824. * return it in dfx_xmt_done.
  2825. *
  2826. * Return Codes:
  2827. * 0 - driver queued packet, link is unavailable, or skbuff was bad
  2828. * 1 - caller should requeue the sk_buff for later transmission
  2829. *
  2830. * Assumptions:
  2831. * First and foremost, we assume the incoming skb pointer
  2832. * is NOT NULL and is pointing to a valid sk_buff structure.
  2833. *
  2834. * The outgoing packet is complete, starting with the
  2835. * frame control byte including the last byte of data,
  2836. * but NOT including the 4 byte CRC. We'll let the
  2837. * adapter hardware generate and append the CRC.
  2838. *
  2839. * The entire packet is stored in one physically
  2840. * contiguous buffer which is not cached and whose
  2841. * 32-bit physical address can be determined.
  2842. *
  2843. * It's vital that this routine is NOT reentered for the
  2844. * same board and that the OS is not in another section of
  2845. * code (eg. dfx_int_common) for the same board on a
  2846. * different thread.
  2847. *
  2848. * Side Effects:
  2849. * None
  2850. */
  2851. static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
  2852. struct net_device *dev)
  2853. {
  2854. DFX_board_t *bp = netdev_priv(dev);
  2855. u8 prod; /* local transmit producer index */
  2856. PI_XMT_DESCR *p_xmt_descr; /* ptr to transmit descriptor block entry */
  2857. XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
  2858. dma_addr_t dma_addr;
  2859. unsigned long flags;
  2860. netif_stop_queue(dev);
  2861. /*
  2862. * Verify that incoming transmit request is OK
  2863. *
  2864. * Note: The packet size check is consistent with other
  2865. * Linux device drivers, although the correct packet
  2866. * size should be verified before calling the
  2867. * transmit routine.
  2868. */
  2869. if (!IN_RANGE(skb->len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
  2870. {
  2871. printk("%s: Invalid packet length - %u bytes\n",
  2872. dev->name, skb->len);
  2873. bp->xmt_length_errors++; /* bump error counter */
  2874. netif_wake_queue(dev);
  2875. dev_kfree_skb(skb);
  2876. return NETDEV_TX_OK; /* return "success" */
  2877. }
  2878. /*
  2879. * See if adapter link is available, if not, free buffer
  2880. *
  2881. * Note: If the link isn't available, free buffer and return 0
  2882. * rather than tell the upper layer to requeue the packet.
  2883. * The methodology here is that by the time the link
  2884. * becomes available, the packet to be sent will be
  2885. * fairly stale. By simply dropping the packet, the
  2886. * higher layer protocols will eventually time out
  2887. * waiting for response packets which it won't receive.
  2888. */
  2889. if (bp->link_available == PI_K_FALSE)
  2890. {
  2891. if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_LINK_AVAIL) /* is link really available? */
  2892. bp->link_available = PI_K_TRUE; /* if so, set flag and continue */
  2893. else
  2894. {
  2895. bp->xmt_discards++; /* bump error counter */
  2896. dev_kfree_skb(skb); /* free sk_buff now */
  2897. netif_wake_queue(dev);
  2898. return NETDEV_TX_OK; /* return "success" */
  2899. }
  2900. }
  2901. /* Write the three PRH bytes immediately before the FC byte */
  2902. skb_push(skb, 3);
  2903. skb->data[0] = DFX_PRH0_BYTE; /* these byte values are defined */
  2904. skb->data[1] = DFX_PRH1_BYTE; /* in the Motorola FDDI MAC chip */
  2905. skb->data[2] = DFX_PRH2_BYTE; /* specification */
  2906. dma_addr = dma_map_single(bp->bus_dev, skb->data, skb->len,
  2907. DMA_TO_DEVICE);
  2908. if (dma_mapping_error(bp->bus_dev, dma_addr)) {
  2909. skb_pull(skb, 3);
  2910. return NETDEV_TX_BUSY;
  2911. }
  2912. spin_lock_irqsave(&bp->lock, flags);
  2913. /* Get the current producer and the next free xmt data descriptor */
  2914. prod = bp->rcv_xmt_reg.index.xmt_prod;
  2915. p_xmt_descr = &(bp->descr_block_virt->xmt_data[prod]);
  2916. /*
  2917. * Get pointer to auxiliary queue entry to contain information
  2918. * for this packet.
  2919. *
  2920. * Note: The current xmt producer index will become the
  2921. * current xmt completion index when we complete this
  2922. * packet later on. So, we'll get the pointer to the
  2923. * next auxiliary queue entry now before we bump the
  2924. * producer index.
  2925. */
  2926. p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[prod++]); /* also bump producer index */
  2927. /*
  2928. * Write the descriptor with buffer info and bump producer
  2929. *
  2930. * Note: Since we need to start DMA from the packet request
  2931. * header, we'll add 3 bytes to the DMA buffer length,
  2932. * and we'll determine the physical address of the
  2933. * buffer from the PRH, not skb->data.
  2934. *
  2935. * Assumptions:
  2936. * 1. Packet starts with the frame control (FC) byte
  2937. * at skb->data.
  2938. * 2. The 4-byte CRC is not appended to the buffer or
  2939. * included in the length.
  2940. * 3. Packet length (skb->len) is from FC to end of
  2941. * data, inclusive.
  2942. * 4. The packet length does not exceed the maximum
  2943. * FDDI LLC frame length of 4491 bytes.
  2944. * 5. The entire packet is contained in a physically
  2945. * contiguous, non-cached, locked memory space
  2946. * comprised of a single buffer pointed to by
  2947. * skb->data.
  2948. * 6. The physical address of the start of packet
  2949. * can be determined from the virtual address
  2950. * by using pci_map_single() and is only 32-bits
  2951. * wide.
  2952. */
  2953. p_xmt_descr->long_0 = (u32) (PI_XMT_DESCR_M_SOP | PI_XMT_DESCR_M_EOP | ((skb->len) << PI_XMT_DESCR_V_SEG_LEN));
  2954. p_xmt_descr->long_1 = (u32)dma_addr;
  2955. /*
  2956. * Verify that descriptor is actually available
  2957. *
  2958. * Note: If descriptor isn't available, return 1 which tells
  2959. * the upper layer to requeue the packet for later
  2960. * transmission.
  2961. *
  2962. * We need to ensure that the producer never reaches the
  2963. * completion, except to indicate that the queue is empty.
  2964. */
  2965. if (prod == bp->rcv_xmt_reg.index.xmt_comp)
  2966. {
  2967. skb_pull(skb,3);
  2968. spin_unlock_irqrestore(&bp->lock, flags);
  2969. return NETDEV_TX_BUSY; /* requeue packet for later */
  2970. }
  2971. /*
  2972. * Save info for this packet for xmt done indication routine
  2973. *
  2974. * Normally, we'd save the producer index in the p_xmt_drv_descr
  2975. * structure so that we'd have it handy when we complete this
  2976. * packet later (in dfx_xmt_done). However, since the current
  2977. * transmit architecture guarantees a single fragment for the
  2978. * entire packet, we can simply bump the completion index by
  2979. * one (1) for each completed packet.
  2980. *
  2981. * Note: If this assumption changes and we're presented with
  2982. * an inconsistent number of transmit fragments for packet
  2983. * data, we'll need to modify this code to save the current
  2984. * transmit producer index.
  2985. */
  2986. p_xmt_drv_descr->p_skb = skb;
  2987. /* Update Type 2 register */
  2988. bp->rcv_xmt_reg.index.xmt_prod = prod;
  2989. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  2990. spin_unlock_irqrestore(&bp->lock, flags);
  2991. netif_wake_queue(dev);
  2992. return NETDEV_TX_OK; /* packet queued to adapter */
  2993. }
  2994. /*
  2995. * ================
  2996. * = dfx_xmt_done =
  2997. * ================
  2998. *
  2999. * Overview:
  3000. * Processes all frames that have been transmitted.
  3001. *
  3002. * Returns:
  3003. * None
  3004. *
  3005. * Arguments:
  3006. * bp - pointer to board information
  3007. *
  3008. * Functional Description:
  3009. * For all consumed transmit descriptors that have not
  3010. * yet been completed, we'll free the skb we were holding
  3011. * onto using dev_kfree_skb and bump the appropriate
  3012. * counters.
  3013. *
  3014. * Return Codes:
  3015. * None
  3016. *
  3017. * Assumptions:
  3018. * The Type 2 register is not updated in this routine. It is
  3019. * assumed that it will be updated in the ISR when dfx_xmt_done
  3020. * returns.
  3021. *
  3022. * Side Effects:
  3023. * None
  3024. */
  3025. static int dfx_xmt_done(DFX_board_t *bp)
  3026. {
  3027. XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
  3028. PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
  3029. u8 comp; /* local transmit completion index */
  3030. int freed = 0; /* buffers freed */
  3031. /* Service all consumed transmit frames */
  3032. p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
  3033. while (bp->rcv_xmt_reg.index.xmt_comp != p_type_2_cons->index.xmt_cons)
  3034. {
  3035. /* Get pointer to the transmit driver descriptor block information */
  3036. p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
  3037. /* Increment transmit counters */
  3038. bp->xmt_total_frames++;
  3039. bp->xmt_total_bytes += p_xmt_drv_descr->p_skb->len;
  3040. /* Return skb to operating system */
  3041. comp = bp->rcv_xmt_reg.index.xmt_comp;
  3042. dma_unmap_single(bp->bus_dev,
  3043. bp->descr_block_virt->xmt_data[comp].long_1,
  3044. p_xmt_drv_descr->p_skb->len,
  3045. DMA_TO_DEVICE);
  3046. dev_kfree_skb_irq(p_xmt_drv_descr->p_skb);
  3047. /*
  3048. * Move to start of next packet by updating completion index
  3049. *
  3050. * Here we assume that a transmit packet request is always
  3051. * serviced by posting one fragment. We can therefore
  3052. * simplify the completion code by incrementing the
  3053. * completion index by one. This code will need to be
  3054. * modified if this assumption changes. See comments
  3055. * in dfx_xmt_queue_pkt for more details.
  3056. */
  3057. bp->rcv_xmt_reg.index.xmt_comp += 1;
  3058. freed++;
  3059. }
  3060. return freed;
  3061. }
  3062. /*
  3063. * =================
  3064. * = dfx_rcv_flush =
  3065. * =================
  3066. *
  3067. * Overview:
  3068. * Remove all skb's in the receive ring.
  3069. *
  3070. * Returns:
  3071. * None
  3072. *
  3073. * Arguments:
  3074. * bp - pointer to board information
  3075. *
  3076. * Functional Description:
  3077. * Free's all the dynamically allocated skb's that are
  3078. * currently attached to the device receive ring. This
  3079. * function is typically only used when the device is
  3080. * initialized or reinitialized.
  3081. *
  3082. * Return Codes:
  3083. * None
  3084. *
  3085. * Side Effects:
  3086. * None
  3087. */
  3088. #ifdef DYNAMIC_BUFFERS
  3089. static void dfx_rcv_flush( DFX_board_t *bp )
  3090. {
  3091. int i, j;
  3092. for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
  3093. for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  3094. {
  3095. struct sk_buff *skb;
  3096. skb = (struct sk_buff *)bp->p_rcv_buff_va[i+j];
  3097. if (skb) {
  3098. dma_unmap_single(bp->bus_dev,
  3099. bp->descr_block_virt->rcv_data[i+j].long_1,
  3100. PI_RCV_DATA_K_SIZE_MAX,
  3101. DMA_FROM_DEVICE);
  3102. dev_kfree_skb(skb);
  3103. }
  3104. bp->p_rcv_buff_va[i+j] = NULL;
  3105. }
  3106. }
  3107. #endif /* DYNAMIC_BUFFERS */
  3108. /*
  3109. * =================
  3110. * = dfx_xmt_flush =
  3111. * =================
  3112. *
  3113. * Overview:
  3114. * Processes all frames whether they've been transmitted
  3115. * or not.
  3116. *
  3117. * Returns:
  3118. * None
  3119. *
  3120. * Arguments:
  3121. * bp - pointer to board information
  3122. *
  3123. * Functional Description:
  3124. * For all produced transmit descriptors that have not
  3125. * yet been completed, we'll free the skb we were holding
  3126. * onto using dev_kfree_skb and bump the appropriate
  3127. * counters. Of course, it's possible that some of
  3128. * these transmit requests actually did go out, but we
  3129. * won't make that distinction here. Finally, we'll
  3130. * update the consumer index to match the producer.
  3131. *
  3132. * Return Codes:
  3133. * None
  3134. *
  3135. * Assumptions:
  3136. * This routine does NOT update the Type 2 register. It
  3137. * is assumed that this routine is being called during a
  3138. * transmit flush interrupt, or a shutdown or close routine.
  3139. *
  3140. * Side Effects:
  3141. * None
  3142. */
  3143. static void dfx_xmt_flush( DFX_board_t *bp )
  3144. {
  3145. u32 prod_cons; /* rcv/xmt consumer block longword */
  3146. XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
  3147. u8 comp; /* local transmit completion index */
  3148. /* Flush all outstanding transmit frames */
  3149. while (bp->rcv_xmt_reg.index.xmt_comp != bp->rcv_xmt_reg.index.xmt_prod)
  3150. {
  3151. /* Get pointer to the transmit driver descriptor block information */
  3152. p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
  3153. /* Return skb to operating system */
  3154. comp = bp->rcv_xmt_reg.index.xmt_comp;
  3155. dma_unmap_single(bp->bus_dev,
  3156. bp->descr_block_virt->xmt_data[comp].long_1,
  3157. p_xmt_drv_descr->p_skb->len,
  3158. DMA_TO_DEVICE);
  3159. dev_kfree_skb(p_xmt_drv_descr->p_skb);
  3160. /* Increment transmit error counter */
  3161. bp->xmt_discards++;
  3162. /*
  3163. * Move to start of next packet by updating completion index
  3164. *
  3165. * Here we assume that a transmit packet request is always
  3166. * serviced by posting one fragment. We can therefore
  3167. * simplify the completion code by incrementing the
  3168. * completion index by one. This code will need to be
  3169. * modified if this assumption changes. See comments
  3170. * in dfx_xmt_queue_pkt for more details.
  3171. */
  3172. bp->rcv_xmt_reg.index.xmt_comp += 1;
  3173. }
  3174. /* Update the transmit consumer index in the consumer block */
  3175. prod_cons = (u32)(bp->cons_block_virt->xmt_rcv_data & ~PI_CONS_M_XMT_INDEX);
  3176. prod_cons |= (u32)(bp->rcv_xmt_reg.index.xmt_prod << PI_CONS_V_XMT_INDEX);
  3177. bp->cons_block_virt->xmt_rcv_data = prod_cons;
  3178. }
  3179. /*
  3180. * ==================
  3181. * = dfx_unregister =
  3182. * ==================
  3183. *
  3184. * Overview:
  3185. * Shuts down an FDDI controller
  3186. *
  3187. * Returns:
  3188. * Condition code
  3189. *
  3190. * Arguments:
  3191. * bdev - pointer to device information
  3192. *
  3193. * Functional Description:
  3194. *
  3195. * Return Codes:
  3196. * None
  3197. *
  3198. * Assumptions:
  3199. * It compiles so it should work :-( (PCI cards do :-)
  3200. *
  3201. * Side Effects:
  3202. * Device structures for FDDI adapters (fddi0, fddi1, etc) are
  3203. * freed.
  3204. */
  3205. static void dfx_unregister(struct device *bdev)
  3206. {
  3207. struct net_device *dev = dev_get_drvdata(bdev);
  3208. DFX_board_t *bp = netdev_priv(dev);
  3209. int dfx_bus_pci = dev_is_pci(bdev);
  3210. int dfx_bus_tc = DFX_BUS_TC(bdev);
  3211. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  3212. resource_size_t bar_start[3]; /* pointers to ports */
  3213. resource_size_t bar_len[3]; /* resource lengths */
  3214. int alloc_size; /* total buffer size used */
  3215. unregister_netdev(dev);
  3216. alloc_size = sizeof(PI_DESCR_BLOCK) +
  3217. PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  3218. #ifndef DYNAMIC_BUFFERS
  3219. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  3220. #endif
  3221. sizeof(PI_CONSUMER_BLOCK) +
  3222. (PI_ALIGN_K_DESC_BLK - 1);
  3223. if (bp->kmalloced)
  3224. dma_free_coherent(bdev, alloc_size,
  3225. bp->kmalloced, bp->kmalloced_dma);
  3226. dfx_bus_uninit(dev);
  3227. dfx_get_bars(bdev, bar_start, bar_len);
  3228. if (bar_start[2] != 0)
  3229. release_region(bar_start[2], bar_len[2]);
  3230. if (bar_start[1] != 0)
  3231. release_region(bar_start[1], bar_len[1]);
  3232. if (dfx_use_mmio) {
  3233. iounmap(bp->base.mem);
  3234. release_mem_region(bar_start[0], bar_len[0]);
  3235. } else
  3236. release_region(bar_start[0], bar_len[0]);
  3237. if (dfx_bus_pci)
  3238. pci_disable_device(to_pci_dev(bdev));
  3239. free_netdev(dev);
  3240. }
  3241. static int __maybe_unused dfx_dev_register(struct device *);
  3242. static int __maybe_unused dfx_dev_unregister(struct device *);
  3243. #ifdef CONFIG_PCI
  3244. static int dfx_pci_register(struct pci_dev *, const struct pci_device_id *);
  3245. static void dfx_pci_unregister(struct pci_dev *);
  3246. static const struct pci_device_id dfx_pci_table[] = {
  3247. { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_FDDI) },
  3248. { }
  3249. };
  3250. MODULE_DEVICE_TABLE(pci, dfx_pci_table);
  3251. static struct pci_driver dfx_pci_driver = {
  3252. .name = "defxx",
  3253. .id_table = dfx_pci_table,
  3254. .probe = dfx_pci_register,
  3255. .remove = dfx_pci_unregister,
  3256. };
  3257. static int dfx_pci_register(struct pci_dev *pdev,
  3258. const struct pci_device_id *ent)
  3259. {
  3260. return dfx_register(&pdev->dev);
  3261. }
  3262. static void dfx_pci_unregister(struct pci_dev *pdev)
  3263. {
  3264. dfx_unregister(&pdev->dev);
  3265. }
  3266. #endif /* CONFIG_PCI */
  3267. #ifdef CONFIG_EISA
  3268. static struct eisa_device_id dfx_eisa_table[] = {
  3269. { "DEC3001", DEFEA_PROD_ID_1 },
  3270. { "DEC3002", DEFEA_PROD_ID_2 },
  3271. { "DEC3003", DEFEA_PROD_ID_3 },
  3272. { "DEC3004", DEFEA_PROD_ID_4 },
  3273. { }
  3274. };
  3275. MODULE_DEVICE_TABLE(eisa, dfx_eisa_table);
  3276. static struct eisa_driver dfx_eisa_driver = {
  3277. .id_table = dfx_eisa_table,
  3278. .driver = {
  3279. .name = "defxx",
  3280. .bus = &eisa_bus_type,
  3281. .probe = dfx_dev_register,
  3282. .remove = dfx_dev_unregister,
  3283. },
  3284. };
  3285. #endif /* CONFIG_EISA */
  3286. #ifdef CONFIG_TC
  3287. static struct tc_device_id const dfx_tc_table[] = {
  3288. { "DEC ", "PMAF-FA " },
  3289. { "DEC ", "PMAF-FD " },
  3290. { "DEC ", "PMAF-FS " },
  3291. { "DEC ", "PMAF-FU " },
  3292. { }
  3293. };
  3294. MODULE_DEVICE_TABLE(tc, dfx_tc_table);
  3295. static struct tc_driver dfx_tc_driver = {
  3296. .id_table = dfx_tc_table,
  3297. .driver = {
  3298. .name = "defxx",
  3299. .bus = &tc_bus_type,
  3300. .probe = dfx_dev_register,
  3301. .remove = dfx_dev_unregister,
  3302. },
  3303. };
  3304. #endif /* CONFIG_TC */
  3305. static int __maybe_unused dfx_dev_register(struct device *dev)
  3306. {
  3307. int status;
  3308. status = dfx_register(dev);
  3309. if (!status)
  3310. get_device(dev);
  3311. return status;
  3312. }
  3313. static int __maybe_unused dfx_dev_unregister(struct device *dev)
  3314. {
  3315. put_device(dev);
  3316. dfx_unregister(dev);
  3317. return 0;
  3318. }
  3319. static int dfx_init(void)
  3320. {
  3321. int status;
  3322. status = pci_register_driver(&dfx_pci_driver);
  3323. if (!status)
  3324. status = eisa_driver_register(&dfx_eisa_driver);
  3325. if (!status)
  3326. status = tc_register_driver(&dfx_tc_driver);
  3327. return status;
  3328. }
  3329. static void dfx_cleanup(void)
  3330. {
  3331. tc_unregister_driver(&dfx_tc_driver);
  3332. eisa_driver_unregister(&dfx_eisa_driver);
  3333. pci_unregister_driver(&dfx_pci_driver);
  3334. }
  3335. module_init(dfx_init);
  3336. module_exit(dfx_cleanup);
  3337. MODULE_AUTHOR("Lawrence V. Stefani");
  3338. MODULE_DESCRIPTION("DEC FDDIcontroller TC/EISA/PCI (DEFTA/DEFEA/DEFPA) driver "
  3339. DRV_VERSION " " DRV_RELDATE);
  3340. MODULE_LICENSE("GPL");